@omnidotdev/rdk 0.8.0 → 0.9.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 (37) hide show
  1. package/build/ImmersiveSession-BiX-Du0K.cjs +1 -0
  2. package/build/ImmersiveSession-CJRYdHjb.js +21 -0
  3. package/build/WorldAnchor-gszXX9H2.cjs +1 -0
  4. package/build/WorldAnchor-ur1RjMrN.js +167 -0
  5. package/build/fiducial.cjs +1 -0
  6. package/build/fiducial.d.ts +2 -0
  7. package/build/fiducial.js +7 -0
  8. package/build/fiducialBackend-Cr8mdwro.cjs +1 -0
  9. package/build/fiducialBackend-Vj5N1epW.js +180 -0
  10. package/build/geolocation.cjs +1 -0
  11. package/build/geolocation.d.ts +2 -0
  12. package/build/geolocation.js +9 -0
  13. package/build/geolocationBackend-BkS2-zqx.cjs +1 -0
  14. package/build/geolocationBackend-BxwE8Vcl.js +338 -0
  15. package/build/immersive.cjs +1 -0
  16. package/build/immersive.d.ts +2 -0
  17. package/build/immersive.js +4 -0
  18. package/build/index.cjs +1 -1
  19. package/build/index.d.ts +1 -0
  20. package/build/index.d.ts.map +1 -1
  21. package/build/index.js +31 -672
  22. package/build/lib/types/engine/backend/Backend.interface.d.ts +1 -0
  23. package/build/lib/types/engine/backend/Backend.interface.d.ts.map +1 -1
  24. package/build/magic/MagicSession.d.ts +14 -0
  25. package/build/magic/MagicSession.d.ts.map +1 -0
  26. package/build/magic/WorldAnchor.d.ts +21 -0
  27. package/build/magic/WorldAnchor.d.ts.map +1 -0
  28. package/build/magic/index.d.ts +7 -0
  29. package/build/magic/index.d.ts.map +1 -0
  30. package/build/magic/magicBackend.d.ts +57 -0
  31. package/build/magic/magicBackend.d.ts.map +1 -0
  32. package/build/magic.cjs +1 -0
  33. package/build/magic.d.ts +2 -0
  34. package/build/magic.js +6 -0
  35. package/build/useXRStore-eThHhTNv.js +149 -0
  36. package/build/useXRStore-emhiLtDT.cjs +1 -0
  37. package/package.json +24 -4
package/build/index.js CHANGED
@@ -1,675 +1,34 @@
1
- import O, { useRef as E, useEffect as C, useState as T, useMemo as j, useCallback as V } from "react";
2
- import { useFrame as N, useThree as X, createPortal as U } from "@react-three/fiber";
3
- import { jsx as I } from "react/jsx-runtime";
4
- import { ArMarkerControls as K, ArToolkitSource as re, ArToolkitContext as oe } from "@ar-js-org/ar.js/three.js/build/ar-threex";
5
- import { Group as W, Vector3 as se, DoubleSide as ie, BackSide as ce, FrontSide as ae, Shape as le, Path as ue, ShapeGeometry as de } from "three";
6
- import { Line2 as Ae } from "three/addons/lines/Line2.js";
7
- import { LineGeometry as fe } from "three/addons/lines/LineGeometry.js";
8
- import { LineMaterial as me } from "three/addons/lines/LineMaterial.js";
9
- import { LocationBased as ge, Webcam as he, DeviceOrientationControls as pe } from "locar";
10
- import { createXRStore as Se, XR as be } from "@react-three/xr";
11
- const b = {
12
- FIDUCIAL: "fiducial",
13
- GEOLOCATION: "geolocation",
14
- IMMERSIVE: "immersive"
15
- }, _ = (t) => {
16
- let e;
17
- const n = /* @__PURE__ */ new Set(), r = (s, f) => {
18
- const u = typeof s == "function" ? s(e) : s;
19
- if (!Object.is(u, e)) {
20
- const i = e;
21
- e = f ?? (typeof u != "object" || u === null) ? u : Object.assign({}, e, u), n.forEach((A) => A(e, i));
22
- }
23
- }, c = () => e, o = { setState: r, getState: c, getInitialState: () => d, subscribe: (s) => (n.add(s), () => n.delete(s)) }, d = e = t(r, c, o);
24
- return o;
25
- }, we = ((t) => t ? _(t) : _), ye = (t) => t;
26
- function ke(t, e = ye) {
27
- const n = O.useSyncExternalStore(
28
- t.subscribe,
29
- O.useCallback(() => e(t.getState()), [t, e]),
30
- O.useCallback(() => e(t.getInitialState()), [t, e])
31
- );
32
- return O.useDebugValue(n), n;
33
- }
34
- const Ie = (t) => {
35
- const e = we(t), n = (r) => ke(e, r);
36
- return Object.assign(n, e), n;
37
- }, Ee = ((t) => Ie), ve = (t) => (e, n, r) => {
38
- const c = r.subscribe;
39
- return r.subscribe = ((l, o, d) => {
40
- let s = l;
41
- if (o) {
42
- const f = d?.equalityFn || Object.is;
43
- let u = l(r.getState());
44
- s = (i) => {
45
- const A = l(i);
46
- if (!f(u, A)) {
47
- const g = u;
48
- o(u = A, g);
49
- }
50
- }, d?.fireImmediately && o(u, u);
51
- }
52
- return c(s);
53
- }), t(e, n, r);
54
- }, Le = ve, Q = (t) => Symbol.iterator in t, Y = (t) => (
55
- // HACK: avoid checking entries type
56
- "entries" in t
57
- ), J = (t, e) => {
58
- const n = t instanceof Map ? t : new Map(t.entries()), r = e instanceof Map ? e : new Map(e.entries());
59
- if (n.size !== r.size)
60
- return !1;
61
- for (const [c, a] of n)
62
- if (!r.has(c) || !Object.is(a, r.get(c)))
63
- return !1;
64
- return !0;
65
- }, Ce = (t, e) => {
66
- const n = t[Symbol.iterator](), r = e[Symbol.iterator]();
67
- let c = n.next(), a = r.next();
68
- for (; !c.done && !a.done; ) {
69
- if (!Object.is(c.value, a.value))
70
- return !1;
71
- c = n.next(), a = r.next();
72
- }
73
- return !!c.done && !!a.done;
74
- };
75
- function Re(t, e) {
76
- return Object.is(t, e) ? !0 : typeof t != "object" || t === null || typeof e != "object" || e === null || Object.getPrototypeOf(t) !== Object.getPrototypeOf(e) ? !1 : Q(t) && Q(e) ? Y(t) && Y(e) ? J(t, e) : Ce(t, e) : J(
77
- { entries: () => Object.entries(t) },
78
- { entries: () => Object.entries(e) }
79
- );
80
- }
81
- function Me(t) {
82
- const e = O.useRef(void 0);
83
- return (n) => {
84
- const r = t(n);
85
- return Re(e.current, r) ? e.current : e.current = r;
86
- };
87
- }
88
- const H = Ee()(
89
- Le((t, e) => ({
90
- // initial state
91
- video: null,
92
- backends: /* @__PURE__ */ new Map(),
93
- immersiveStore: null,
94
- // actions
95
- registerBackend: async (n, r) => {
96
- try {
97
- const c = e(), a = new Set(c.backends.keys()), l = a.has(b.FIDUCIAL) || n.type === b.FIDUCIAL, o = a.has(b.GEOLOCATION) || n.type === b.GEOLOCATION;
98
- if (l && o) {
99
- const d = "❌ [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.";
100
- throw console.error(d), new Error(d);
101
- }
102
- await n.init({
103
- scene: r.scene,
104
- camera: r.camera,
105
- renderer: r.renderer
106
- }), t((d) => {
107
- const s = new Map(d.backends);
108
- return s.set(n.type, n), { backends: s };
109
- });
110
- } catch (c) {
111
- throw console.error("[XRStore] Failed to register backend:", c), c;
112
- }
113
- },
114
- unregisterBackend: (n) => {
115
- t((r) => {
116
- const c = new Map(r.backends);
117
- c.delete(n.type);
118
- try {
119
- n.dispose?.();
120
- } catch (a) {
121
- console.error("[XRStore] Error disposing backend:", a);
122
- }
123
- return { backends: c };
124
- });
125
- },
126
- setVideo: (n) => {
127
- t({ video: n });
128
- },
129
- updateBackends: (n) => {
130
- const { backends: r } = e();
131
- for (const c of r.values())
132
- try {
133
- c.update?.(n);
134
- } catch (a) {
135
- console.error("[XRStore] Backend update error:", a);
136
- }
137
- },
138
- setImmersiveStore: (n) => {
139
- t({ immersiveStore: n });
140
- }
141
- }))
142
- ), xe = () => H.getState(), _e = H.subscribe, P = (t) => H(
143
- Me((n) => {
144
- const r = {
145
- ...n,
146
- isImmersive: n.backends.has(b.IMMERSIVE),
147
- immersive: n.immersiveStore || null
148
- };
149
- return t ? t(r) : r;
150
- })
151
- ), Qe = ({ children: t }) => {
152
- const { updateBackends: e } = P();
153
- return N((n, r) => {
154
- e(r);
155
- }), t;
156
- }, Oe = {
157
- isPending: !0,
158
- isSuccess: !1,
159
- arSource: null,
160
- arContext: null
161
- }, Te = () => {
162
- const e = P((n) => n.backends).get(b.FIDUCIAL);
163
- return e ? {
164
- ...e.getInternal(),
165
- isPending: !1,
166
- isSuccess: !0
167
- } : Oe;
168
- }, Ye = ({
169
- patternUrl: t,
170
- barcodeValue: e,
171
- params: n,
172
- onMarkerFound: r,
173
- onMarkerLost: c,
174
- children: a
175
- }) => {
176
- const l = E(null), o = Te(), d = E(!1), s = E(!1), f = E(null);
177
- return C(() => {
178
- if (!o.isSuccess) return;
179
- let u = !1;
180
- return (() => {
181
- try {
182
- const { arContext: A } = o, g = l.current;
183
- if (!A || !g || u) return;
184
- if (g.visible = !1, s.current = !1, !A.arController) {
185
- requestAnimationFrame(() => {
186
- if (!l.current || u || !o.arContext?.arController)
187
- return;
188
- const w = new K(
189
- o.arContext,
190
- l.current,
191
- {
192
- type: t ? "pattern" : e ? "barcode" : "unknown",
193
- patternUrl: t,
194
- barcodeValue: e,
195
- ...n
196
- }
197
- );
198
- f.current = w, s.current = !0;
199
- });
200
- return;
201
- }
202
- const p = new K(A, g, {
203
- type: t ? "pattern" : e ? "barcode" : "unknown",
204
- patternUrl: t,
205
- barcodeValue: e,
206
- ...n
207
- });
208
- f.current = p, s.current = !0;
209
- } catch (A) {
210
- console.error("Failed to initialize fiducial anchor:", A);
211
- }
212
- })(), () => {
213
- u = !0;
214
- const A = f.current;
215
- typeof A?.dispose == "function" && A.dispose(), s.current = !1;
216
- };
217
- }, [
218
- o.isSuccess,
219
- o.arContext,
220
- t,
221
- e,
222
- n,
223
- o
224
- ]), N(() => {
225
- const u = l.current;
226
- if (!u || !s.current) {
227
- u && (u.visible = !1);
228
- return;
229
- }
230
- const i = u.visible;
231
- i && !d.current ? (d.current = !0, r?.()) : !i && d.current && (d.current = !1, c?.());
232
- }), /* @__PURE__ */ I(
233
- "group",
234
- {
235
- ref: l,
236
- visible: !1,
237
- children: a
238
- }
239
- );
240
- }, Je = ({ options: t = {}, children: e }) => {
241
- const { scene: n, camera: r, gl: c } = X(), { registerBackend: a, unregisterBackend: l } = P(), o = E(null), d = E(t);
242
- return d.current = t, C(() => {
243
- if (o.current) return;
244
- let s = !1;
245
- return (async () => {
246
- try {
247
- const u = Pe(d.current);
248
- if (s) return;
249
- await a(u, { scene: n, camera: r, renderer: c }), o.current = u;
250
- } catch (u) {
251
- console.error("[FiducialSession] Failed to initialize:", u);
252
- }
253
- })(), () => {
254
- s = !0, o.current && (l(o.current), o.current = null);
255
- };
256
- }, [n, r, c, a, l]), e;
257
- }, Pe = (t) => {
258
- let e = null, n = null, r = null, c;
259
- return {
260
- type: b.FIDUCIAL,
261
- async init({ camera: a, renderer: l }) {
262
- e = new re({
263
- sourceType: t?.sourceType ?? "webcam"
264
- }), await new Promise((s, f) => {
265
- const u = setTimeout(() => {
266
- f(new Error("AR source initialization timeout"));
267
- }, 1e4);
268
- e?.init(() => {
269
- clearTimeout(u);
270
- const i = e?.domElement;
271
- i && (i.style.position = "fixed", i.style.top = "0", i.style.left = "0", i.style.width = "100vw", i.style.height = "100vh", i.style.objectFit = "cover", i.style.zIndex = "-1", i.style.pointerEvents = "none"), s();
272
- });
273
- });
274
- const o = {
275
- cameraParametersUrl: t?.cameraParametersUrl ?? // default to internal camera parameters
276
- new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
277
- detectionMode: t?.detectionMode ?? "mono",
278
- patternRatio: t?.patternRatio ?? 0.5,
279
- matrixCodeType: t?.matrixCodeType ?? "3x3"
280
- };
281
- n = new oe(o), r = a;
282
- const d = () => {
283
- e?.onResizeElement();
284
- const s = window.innerWidth, f = window.innerHeight;
285
- l.setSize(s, f, !1), e?.copyElementSizeTo(l.domElement), n?.arController && e?.copyElementSizeTo(n.arController.canvas);
286
- };
287
- await new Promise((s, f) => {
288
- const u = setTimeout(() => {
289
- f(new Error("AR context initialization timeout"));
290
- }, 1e4);
291
- n?.init(() => {
292
- clearTimeout(u);
293
- try {
294
- const i = n?.getProjectionMatrix();
295
- i && a.projectionMatrix.copy(i), d(), s();
296
- } catch (i) {
297
- f(i);
298
- }
299
- });
300
- }), window.addEventListener("resize", d), c = d;
301
- },
302
- update() {
303
- if (!(!e || !n) && !(!e.ready || !e.domElement))
304
- try {
305
- n.update(e.domElement);
306
- const a = n.getProjectionMatrix?.();
307
- r && a && r.projectionMatrix.copy(a);
308
- } catch (a) {
309
- console.warn("AR.js update error:", a);
310
- }
311
- },
312
- dispose() {
313
- if (c && (window.removeEventListener("resize", c), c = void 0), n && typeof n.dispose == "function" && n.dispose(), e?.domElement) {
314
- const a = e.domElement.parentNode;
315
- a && a.removeChild(e.domElement);
316
- }
317
- e = null, n = null, r = null;
318
- },
319
- getInternal: () => ({
320
- arSource: e,
321
- arContext: n
322
- })
323
- };
324
- }, ze = {
325
- isPending: !0,
326
- isSuccess: !1,
327
- locar: null,
328
- webcam: null,
329
- deviceOrientation: null,
330
- scene: null,
331
- camera: null,
332
- lastPosition: null,
333
- registerAnchor: () => {
334
- },
335
- unregisterAnchor: () => {
336
- },
337
- getAnchor: () => {
338
- }
339
- }, q = () => {
340
- const e = P((n) => n.backends).get(b.GEOLOCATION);
341
- return e ? {
342
- ...e.getInternal(),
343
- isPending: !1,
344
- isSuccess: !0
345
- } : ze;
346
- }, Ze = ({
347
- coordinates: t,
348
- color: e = "#ff0000",
349
- isDashed: n = !1,
350
- dashSize: r = 3,
351
- gapSize: c = 1,
352
- lineWidth: a = 1
353
- }) => {
354
- const l = q(), [o] = T(() => new W()), d = j(() => Math.random().toString(36).slice(2, 11), []), [s, f] = T(null);
355
- return C(() => {
356
- if (!l.isSuccess || t.length < 2) return;
357
- const [u, i, A = 0] = t[0], g = (p) => {
358
- const [w, v, m = 0] = t[0], [S, R] = p.lonLatToWorldCoords(
359
- w,
360
- v
361
- ), y = t.map(([F, h, k = 0]) => {
362
- const [M, x] = p.lonLatToWorldCoords(F, h);
363
- return new se(M - S, k - m, x - R);
364
- }), L = new fe().setFromPoints(y), z = new me({
365
- color: e,
366
- dashSize: r,
367
- gapSize: c,
368
- dashed: n,
369
- worldUnits: !0,
370
- linewidth: a
371
- }), G = new Ae(L, z);
372
- n && G.computeLineDistances(), f(G);
373
- };
374
- return l.registerAnchor(d, {
375
- anchor: o,
376
- isAttached: !1,
377
- latitude: i,
378
- longitude: u,
379
- altitude: A,
380
- onAttach: g
381
- }), () => {
382
- l.unregisterAnchor(d);
383
- };
384
- }, [
385
- l.isSuccess,
386
- l.registerAnchor,
387
- l.unregisterAnchor,
388
- d,
389
- o,
390
- t,
391
- e,
392
- n,
393
- r,
394
- c,
395
- a
396
- ]), U(
397
- /* @__PURE__ */ I("group", { children: s && /* @__PURE__ */ I("primitive", { object: s }) }),
398
- o
399
- );
400
- }, $e = ({
401
- latitude: t,
402
- longitude: e,
403
- altitude: n = 0,
404
- isBillboard: r = !0,
405
- onAttach: c,
406
- onGpsUpdate: a,
407
- children: l
408
- }) => {
409
- const o = q(), { camera: d } = X(), [s] = T(() => new W()), f = j(() => Math.random().toString(36).slice(2, 11), []), u = V(() => {
410
- c?.();
411
- }, [c]), i = V(
412
- (A, g) => {
413
- a?.(A, g);
414
- },
415
- [a]
416
- );
417
- return C(() => {
418
- if (o.isSuccess)
419
- return o.registerAnchor(f, {
420
- anchor: s,
421
- isAttached: !1,
422
- latitude: t,
423
- longitude: e,
424
- altitude: n,
425
- onAttach: u,
426
- onGpsUpdate: i
427
- }), () => {
428
- o.unregisterAnchor(f);
429
- };
430
- }, [
431
- o.isSuccess,
432
- o.registerAnchor,
433
- o.unregisterAnchor,
434
- s,
435
- f,
436
- t,
437
- e,
438
- n,
439
- u,
440
- i
441
- ]), N(() => {
442
- !r || !d || !o.isSuccess || !o.getAnchor(f)?.isAttached || s.lookAt(d.position);
443
- }), U(/* @__PURE__ */ I("group", { children: l }), s);
444
- }, et = ({
445
- options: t = {},
446
- children: e
447
- }) => {
448
- const { scene: n, camera: r, gl: c } = X(), { registerBackend: a, unregisterBackend: l } = P(), o = E(null), d = E(t);
449
- return d.current = t, C(() => {
450
- if (o.current) return;
451
- let s = !1;
452
- return (async () => {
453
- try {
454
- const u = Ge(d.current);
455
- if (s) return;
456
- await a(u, { scene: n, camera: r, renderer: c }), o.current = u;
457
- } catch (u) {
458
- console.error("[GeolocationSession] Failed to initialize:", u);
459
- }
460
- })(), () => {
461
- s = !0, o.current && (l(o.current), o.current = null);
462
- };
463
- }, [n, r, c, a, l]), e;
464
- }, je = {
465
- front: ae,
466
- back: ce,
467
- double: ie
468
- }, tt = ({
469
- coordinates: t,
470
- holes: e,
471
- color: n = "#ff0000",
472
- opacity: r = 1,
473
- isWireframe: c = !1,
474
- side: a = "double"
475
- }) => {
476
- const l = q(), [o] = T(() => new W()), d = j(() => Math.random().toString(36).slice(2, 11), []), [s, f] = T(null);
477
- return C(() => {
478
- if (!l.isSuccess || t.length < 3) return;
479
- const [u, i, A = 0] = t[0], g = (p) => {
480
- const [w, v, m = 0] = t[0], [S, R] = p.lonLatToWorldCoords(
481
- w,
482
- v
483
- ), y = [];
484
- for (const [h, k, M = 0] of t) {
485
- const [x, B] = p.lonLatToWorldCoords(h, k);
486
- y.push({
487
- x: x - S,
488
- z: B - R,
489
- elev: M - m
490
- });
491
- }
492
- const L = new le();
493
- L.moveTo(y[0].x, y[0].z);
494
- for (let h = 1; h < y.length; h++)
495
- L.lineTo(y[h].x, y[h].z);
496
- if (L.closePath(), e && e.length > 0)
497
- for (const h of e) {
498
- if (h.length < 3) continue;
499
- const k = new ue(), [M, x] = h[0], [B, Z] = p.lonLatToWorldCoords(
500
- M,
501
- x
502
- );
503
- k.moveTo(B - S, Z - R);
504
- for (let D = 1; D < h.length; D++) {
505
- const [$, ee] = h[D], [te, ne] = p.lonLatToWorldCoords($, ee);
506
- k.lineTo(te - S, ne - R);
507
- }
508
- k.closePath(), L.holes.push(k);
509
- }
510
- const z = new de(L), F = y.reduce((h, k) => h + k.elev, 0) / y.length;
511
- z.rotateX(-Math.PI / 2), f({ geometry: z, avgElevation: F });
512
- };
513
- return l.registerAnchor(d, {
514
- anchor: o,
515
- isAttached: !1,
516
- latitude: i,
517
- longitude: u,
518
- altitude: A,
519
- onAttach: g
520
- }), () => {
521
- l.unregisterAnchor(d);
522
- };
523
- }, [
524
- l.isSuccess,
525
- l.registerAnchor,
526
- l.unregisterAnchor,
527
- d,
528
- o,
529
- t,
530
- e
531
- ]), U(
532
- /* @__PURE__ */ I("group", { children: s && /* @__PURE__ */ I("group", { position: [0, s.avgElevation, 0], children: /* @__PURE__ */ I("mesh", { geometry: s.geometry, children: /* @__PURE__ */ I(
533
- "meshBasicMaterial",
534
- {
535
- color: n,
536
- opacity: r,
537
- transparent: r < 1,
538
- wireframe: c,
539
- side: je[a]
540
- }
541
- ) }) }) }),
542
- o
543
- );
544
- }, Ge = (t) => {
545
- let e = null, n = null, r = null, c, a = null, l = null, o = null, d = null;
546
- const s = /* @__PURE__ */ new Map();
547
- let f = null;
548
- const u = (i) => {
549
- if (!(!e || i.isAttached))
550
- try {
551
- e.add(i.anchor, i.longitude, i.latitude, i.altitude), i.isAttached = !0, i.onAttach?.(e);
552
- } catch (A) {
553
- console.error("❌ Failed to attach anchor:", A);
554
- }
555
- };
556
- return {
557
- type: b.GEOLOCATION,
558
- async init(i) {
559
- const { camera: A, renderer: g, scene: p } = i;
560
- if (!p)
561
- throw new Error(
562
- "[geolocationBackend] A THREE.Scene is required for location-based AR"
563
- );
564
- l = A, o = g, d = p, e = new ge(p, A), n = new he(
565
- t?.webcamConstraints ?? {
566
- video: { facingMode: "environment" }
567
- // TODO remove `as any` once fixed upstream (LocAR.js)
568
- }
569
- ), a = (m) => {
570
- f = m.position;
571
- for (const S of s.values())
572
- S.isAttached || u(S), S.onGpsUpdate?.(m.position, m.distMoved);
573
- t?.onGpsUpdate?.(m.position, m.distMoved);
574
- }, e.on("gpsupdate", a), n.on("webcamstarted", (m) => {
575
- p.background = m.texture;
576
- }), n.on("webcamerror", (m) => {
577
- console.error("[geolocationBackend] webcam error:", m);
578
- }), r = new pe(A), r.on("deviceorientationgranted", (m) => {
579
- m.target?.connect?.();
580
- }), r.on("deviceorientationerror", (m) => {
581
- console.error("[geolocationBackend] Device orientation error:", m);
582
- }), r.init?.(), e.on("gpserror", (m) => {
583
- console.error("[geolocationBackend] gps error:", m);
584
- }), e.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && e.fakeGps(t.fakeLon, t.fakeLat);
585
- const w = e.getLastKnownLocation();
586
- w !== null && (f = {
587
- coords: {
588
- longitude: w.longitude,
589
- latitude: w.latitude,
590
- accuracy: 0,
591
- altitude: null,
592
- altitudeAccuracy: null,
593
- heading: null,
594
- speed: null,
595
- toJSON: () => w
596
- },
597
- timestamp: Date.now(),
598
- toJSON: () => w
599
- });
600
- const v = () => {
601
- if (!o || !l) return;
602
- const m = window.innerWidth, S = window.innerHeight;
603
- o.setSize(m, S, !1), l.aspect = m / S, l.updateProjectionMatrix?.();
604
- };
605
- v(), window.addEventListener("resize", v), c = v;
606
- },
607
- update() {
608
- r?.update?.();
609
- },
610
- dispose() {
611
- e && a && e.off("gpsupdate", a), e?.stopGps?.(), n?.stop?.(), r?.dispose?.(), c && (window.removeEventListener("resize", c), c = void 0);
612
- for (const i of s.values())
613
- if (i.isAttached)
614
- try {
615
- i.anchor.removeFromParent();
616
- } catch (A) {
617
- console.error("⚠️ Error removing anchor:", A);
618
- }
619
- s.clear(), e = null, n = null, r = null, l = null, o = null, d = null, a = null, f = null;
620
- },
621
- getInternal: () => ({
622
- locar: e,
623
- webcam: n,
624
- deviceOrientation: r,
625
- scene: d,
626
- camera: l,
627
- lastPosition: f,
628
- registerAnchor: (i, A) => {
629
- s.set(i, A), f !== null && !A.isAttached && (u(A), A.onGpsUpdate?.(f, 0));
630
- },
631
- unregisterAnchor: (i) => {
632
- const A = s.get(i);
633
- if (A?.isAttached)
634
- try {
635
- A.anchor.removeFromParent();
636
- } catch (g) {
637
- console.error(`⚠️ Error removing anchor ${i}:`, g);
638
- }
639
- s.delete(i);
640
- },
641
- getAnchor: (i) => s.get(i)
642
- })
643
- };
644
- }, Fe = () => ({
645
- type: b.IMMERSIVE,
646
- init: () => {
647
- },
648
- getInternal: () => null
649
- }), nt = ({ children: t }) => {
650
- const e = j(() => Se(), []);
651
- return C(() => {
652
- const n = xe(), r = Fe();
653
- return n.backends.set(b.IMMERSIVE, r), n.setImmersiveStore(e), () => {
654
- n.backends.delete(b.IMMERSIVE), n.setImmersiveStore(null);
655
- };
656
- }, [e]), /* @__PURE__ */ I(be, { store: e, children: t });
1
+ import { u as s } from "./useXRStore-eThHhTNv.js";
2
+ import { B as m, g as l, s as p } from "./useXRStore-eThHhTNv.js";
3
+ import { useFrame as r } from "@react-three/fiber";
4
+ import { F as S, a as f, c as G, u as k } from "./fiducialBackend-Vj5N1epW.js";
5
+ import { G as F, c as g, a as A, b as R, d as X, u as b } from "./geolocationBackend-BxwE8Vcl.js";
6
+ import { I as M } from "./ImmersiveSession-CJRYdHjb.js";
7
+ import { M as I, W as P, c as T } from "./WorldAnchor-ur1RjMrN.js";
8
+ const n = ({ children: o }) => {
9
+ const { updateBackends: e } = s();
10
+ return r((c, a) => {
11
+ e(a);
12
+ }), o;
657
13
  };
658
14
  export {
659
- b as BACKEND_TYPES,
660
- Ye as FiducialAnchor,
661
- Je as FiducialSession,
662
- Ze as GeoLine,
663
- tt as GeoPolygon,
664
- $e as GeolocationAnchor,
665
- et as GeolocationSession,
666
- nt as ImmersiveSession,
667
- Qe as XR,
668
- Pe as createFiducialBackend,
669
- Ge as createGeolocationBackend,
670
- xe as getXRStore,
671
- _e as subscribeToXRStore,
672
- Te as useFiducialBackend,
673
- q as useGeolocationBackend,
674
- P as useXRStore
15
+ m as BACKEND_TYPES,
16
+ S as FiducialAnchor,
17
+ f as FiducialSession,
18
+ F as GeoLine,
19
+ g as GeoPolygon,
20
+ A as GeolocationAnchor,
21
+ R as GeolocationSession,
22
+ M as ImmersiveSession,
23
+ I as MagicSession,
24
+ P as WorldAnchor,
25
+ n as XR,
26
+ G as createFiducialBackend,
27
+ X as createGeolocationBackend,
28
+ T as createMagicBackend,
29
+ l as getXRStore,
30
+ p as subscribeToXRStore,
31
+ k as useFiducialBackend,
32
+ b as useGeolocationBackend,
33
+ s as useXRStore
675
34
  };
@@ -6,6 +6,7 @@ export declare const BACKEND_TYPES: {
6
6
  readonly FIDUCIAL: "fiducial";
7
7
  readonly GEOLOCATION: "geolocation";
8
8
  readonly IMMERSIVE: "immersive";
9
+ readonly MAGIC: "magic";
9
10
  };
10
11
  /**
11
12
  * Backend type discriminator.