@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.
- package/build/engine/useXRStore.d.ts +4 -12
- package/build/engine/useXRStore.d.ts.map +1 -1
- package/build/fiducial/FiducialAnchor.d.ts.map +1 -1
- package/build/fiducial/FiducialSession.d.ts +1 -4
- package/build/fiducial/FiducialSession.d.ts.map +1 -1
- package/build/fiducial/fiducialBackend.d.ts +9 -1
- package/build/fiducial/fiducialBackend.d.ts.map +1 -1
- package/build/fiducial/index.d.ts +2 -1
- package/build/fiducial/index.d.ts.map +1 -1
- package/build/fiducial/useFiducialBackend.d.ts +14 -0
- package/build/fiducial/useFiducialBackend.d.ts.map +1 -0
- package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
- package/build/geolocation/GeolocationSession.d.ts +1 -4
- package/build/geolocation/GeolocationSession.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts +40 -1
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/geolocation/index.d.ts +2 -1
- package/build/geolocation/index.d.ts.map +1 -1
- package/build/geolocation/useGeolocationBackend.d.ts +14 -0
- package/build/geolocation/useGeolocationBackend.d.ts.map +1 -0
- package/build/immersive/ImmersiveSession.d.ts.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +378 -398
- package/build/lib/types/engine/backend/Backend.interface.d.ts +20 -4
- package/build/lib/types/engine/backend/Backend.interface.d.ts.map +1 -1
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts +4 -4
- package/build/lib/types/engine/backend/BackendInitArgs.interface.d.ts.map +1 -1
- package/build/lib/types/engine/backend/index.d.ts +2 -1
- package/build/lib/types/engine/backend/index.d.ts.map +1 -1
- package/build/lib/types/engine/index.d.ts +2 -2
- package/build/lib/types/engine/index.d.ts.map +1 -1
- package/package.json +17 -19
- package/build/lib/types/engine/context/ContextValue.interface.d.ts +0 -16
- package/build/lib/types/engine/context/ContextValue.interface.d.ts.map +0 -1
- package/build/lib/types/engine/context/index.d.ts +0 -2
- package/build/lib/types/engine/context/index.d.ts.map +0 -1
- package/build/lib/types/index.d.ts +0 -3
- package/build/lib/types/index.d.ts.map +0 -1
- package/build/lib/util/immersive/fromWebXRSessionMode.d.ts +0 -7
- package/build/lib/util/immersive/fromWebXRSessionMode.d.ts.map +0 -1
- package/build/lib/util/immersive/index.d.ts +0 -4
- package/build/lib/util/immersive/index.d.ts.map +0 -1
- package/build/lib/util/immersive/isImmersiveModeSupported.d.ts +0 -7
- package/build/lib/util/immersive/isImmersiveModeSupported.d.ts.map +0 -1
- package/build/lib/util/immersive/toWebXRSessionMode.d.ts +0 -7
- package/build/lib/util/immersive/toWebXRSessionMode.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -1,513 +1,493 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFrame as
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { ArMarkerControls as
|
|
5
|
-
import { Group as
|
|
6
|
-
import
|
|
7
|
-
import { createXRStore as
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
},
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
29
|
+
return y.useDebugValue(t), t;
|
|
26
30
|
}
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
return Object.assign(
|
|
30
|
-
},
|
|
31
|
-
const
|
|
32
|
-
return r.subscribe = ((
|
|
33
|
-
let
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const b =
|
|
41
|
-
|
|
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
|
-
},
|
|
47
|
+
}, u?.fireImmediately && a(l, l);
|
|
44
48
|
}
|
|
45
|
-
return
|
|
46
|
-
}), e
|
|
47
|
-
},
|
|
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
|
|
50
|
-
),
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
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 [
|
|
55
|
-
if (!r.has(
|
|
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
|
-
},
|
|
59
|
-
const
|
|
60
|
-
let
|
|
61
|
-
for (; !
|
|
62
|
-
if (!Object.is(
|
|
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
|
-
|
|
68
|
+
c = t.next(), s = r.next();
|
|
65
69
|
}
|
|
66
|
-
return !!
|
|
70
|
+
return !!c.done && !!s.done;
|
|
67
71
|
};
|
|
68
|
-
function
|
|
69
|
-
return Object.is(
|
|
70
|
-
{ entries: () => Object.entries(
|
|
71
|
-
{ entries: () => Object.entries(
|
|
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
|
|
75
|
-
const
|
|
76
|
-
return (
|
|
77
|
-
const r =
|
|
78
|
-
return
|
|
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
|
|
82
|
-
|
|
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 (
|
|
92
|
+
registerBackend: async (t, r) => {
|
|
94
93
|
try {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
99
|
+
await t.init({
|
|
106
100
|
scene: r.scene,
|
|
107
101
|
camera: r.camera,
|
|
108
102
|
renderer: r.renderer
|
|
109
|
-
}),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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: (
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
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
|
-
|
|
123
|
-
} catch (
|
|
124
|
-
console.error("[XRStore] Error disposing backend:",
|
|
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: (
|
|
133
|
-
|
|
123
|
+
setVideo: (t) => {
|
|
124
|
+
n({ video: t });
|
|
134
125
|
},
|
|
135
|
-
updateBackends: (
|
|
136
|
-
const { backends: r } =
|
|
137
|
-
r.
|
|
126
|
+
updateBackends: (t) => {
|
|
127
|
+
const { backends: r } = e();
|
|
128
|
+
for (const c of r.values())
|
|
138
129
|
try {
|
|
139
|
-
|
|
140
|
-
} catch (
|
|
141
|
-
console.error("[XRStore] Backend update error:",
|
|
130
|
+
c.update?.(t);
|
|
131
|
+
} catch (s) {
|
|
132
|
+
console.error("[XRStore] Backend update error:", s);
|
|
142
133
|
}
|
|
143
|
-
});
|
|
144
134
|
},
|
|
145
|
-
setImmersiveStore: (
|
|
146
|
-
|
|
135
|
+
setImmersiveStore: (t) => {
|
|
136
|
+
n({ immersiveStore: t });
|
|
147
137
|
}
|
|
148
138
|
}))
|
|
149
|
-
),
|
|
150
|
-
|
|
139
|
+
), ne = () => M.getState(), pe = M.subscribe, I = (n) => M(
|
|
140
|
+
te((t) => {
|
|
151
141
|
const r = {
|
|
152
|
-
...
|
|
153
|
-
isImmersive:
|
|
154
|
-
immersive:
|
|
142
|
+
...t,
|
|
143
|
+
isImmersive: t.backends.has(p.IMMERSIVE),
|
|
144
|
+
immersive: t.immersiveStore || null
|
|
155
145
|
};
|
|
156
|
-
return
|
|
146
|
+
return n ? n(r) : r;
|
|
157
147
|
})
|
|
158
|
-
),
|
|
159
|
-
const { updateBackends:
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
}),
|
|
163
|
-
},
|
|
164
|
-
patternUrl:
|
|
165
|
-
barcodeValue:
|
|
166
|
-
params:
|
|
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:
|
|
169
|
-
children:
|
|
158
|
+
onMarkerLost: c,
|
|
159
|
+
children: s
|
|
170
160
|
}) => {
|
|
171
|
-
const
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
177
|
-
if (!
|
|
178
|
-
|
|
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 (!
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
|
196
|
-
type:
|
|
197
|
-
patternUrl:
|
|
198
|
-
barcodeValue:
|
|
199
|
-
...
|
|
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
|
-
|
|
202
|
-
} catch (
|
|
203
|
-
console.error("Failed to initialize fiducial
|
|
193
|
+
f.current = h, i.current = !0;
|
|
194
|
+
} catch (d) {
|
|
195
|
+
console.error("Failed to initialize fiducial anchor:", d);
|
|
204
196
|
}
|
|
205
197
|
})(), () => {
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
typeof
|
|
198
|
+
l = !0;
|
|
199
|
+
const d = f.current;
|
|
200
|
+
typeof d?.dispose == "function" && d.dispose(), i.current = !1;
|
|
209
201
|
};
|
|
210
|
-
}, [
|
|
211
|
-
const
|
|
212
|
-
if (!
|
|
213
|
-
|
|
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
|
|
217
|
-
|
|
218
|
-
}), /* @__PURE__ */
|
|
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:
|
|
213
|
+
ref: A,
|
|
222
214
|
visible: !1,
|
|
223
|
-
children:
|
|
215
|
+
children: s
|
|
224
216
|
}
|
|
225
217
|
);
|
|
226
|
-
},
|
|
227
|
-
const { scene:
|
|
228
|
-
return
|
|
229
|
-
if (
|
|
230
|
-
let
|
|
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
|
|
234
|
-
if (
|
|
235
|
-
await
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
232
|
+
i = !0, a.current && (A(a.current), a.current = null);
|
|
245
233
|
};
|
|
246
|
-
}, [
|
|
247
|
-
}
|
|
248
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
260
|
-
clearTimeout(
|
|
261
|
-
const
|
|
262
|
-
|
|
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
|
|
266
|
-
cameraParametersUrl:
|
|
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:
|
|
269
|
-
patternRatio:
|
|
270
|
-
matrixCodeType:
|
|
255
|
+
detectionMode: n?.detectionMode ?? "mono",
|
|
256
|
+
patternRatio: n?.patternRatio ?? 0.5,
|
|
257
|
+
matrixCodeType: n?.matrixCodeType ?? "3x3"
|
|
271
258
|
};
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
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((
|
|
279
|
-
const
|
|
280
|
-
|
|
265
|
+
await new Promise((i, f) => {
|
|
266
|
+
const l = setTimeout(() => {
|
|
267
|
+
f(new Error("AR context initialization timeout"));
|
|
281
268
|
}, 1e4);
|
|
282
|
-
|
|
283
|
-
clearTimeout(
|
|
269
|
+
t?.init(() => {
|
|
270
|
+
clearTimeout(l);
|
|
284
271
|
try {
|
|
285
|
-
o
|
|
286
|
-
|
|
287
|
-
|
|
272
|
+
const o = t?.getProjectionMatrix();
|
|
273
|
+
o && s.projectionMatrix.copy(o), u(), i();
|
|
274
|
+
} catch (o) {
|
|
275
|
+
f(o);
|
|
288
276
|
}
|
|
289
277
|
});
|
|
290
|
-
}),
|
|
278
|
+
}), window.addEventListener("resize", u), c = u;
|
|
291
279
|
},
|
|
292
280
|
update() {
|
|
293
|
-
|
|
294
|
-
if (!(!o || !a) && o.ready !== !1 && o.domElement)
|
|
281
|
+
if (!(!e || !t) && !(!e.ready || !e.domElement))
|
|
295
282
|
try {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
295
|
+
e = null, t = null, r = null;
|
|
309
296
|
},
|
|
310
|
-
getInternal() {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
};
|
|
315
|
-
}
|
|
297
|
+
getInternal: () => ({
|
|
298
|
+
arSource: e,
|
|
299
|
+
arContext: t
|
|
300
|
+
})
|
|
316
301
|
};
|
|
317
|
-
},
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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:
|
|
325
|
-
onGpsUpdate:
|
|
326
|
-
children:
|
|
307
|
+
onAttach: c,
|
|
308
|
+
onGpsUpdate: s,
|
|
309
|
+
children: A
|
|
327
310
|
}) => {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
}, [
|
|
331
|
-
(
|
|
332
|
-
|
|
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
|
-
[
|
|
317
|
+
[s]
|
|
335
318
|
);
|
|
336
|
-
return
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
397
|
-
|
|
335
|
+
f,
|
|
336
|
+
n,
|
|
398
337
|
e,
|
|
399
338
|
t,
|
|
400
|
-
n,
|
|
401
339
|
l,
|
|
402
|
-
|
|
403
|
-
]),
|
|
404
|
-
!r || !
|
|
405
|
-
}),
|
|
406
|
-
},
|
|
407
|
-
options:
|
|
408
|
-
children:
|
|
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:
|
|
411
|
-
return
|
|
412
|
-
if (
|
|
413
|
-
let
|
|
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
|
|
417
|
-
if (
|
|
418
|
-
await
|
|
419
|
-
|
|
420
|
-
|
|
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
|
-
|
|
361
|
+
i = !0, a.current && (A(a.current), a.current = null);
|
|
428
362
|
};
|
|
429
|
-
}, [
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
let
|
|
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
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
442
|
-
|
|
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
|
-
),
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
-
|
|
425
|
+
E(), window.addEventListener("resize", E), c = E;
|
|
469
426
|
},
|
|
470
427
|
update() {
|
|
471
|
-
|
|
428
|
+
r?.update?.();
|
|
472
429
|
},
|
|
473
430
|
dispose() {
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
-
},
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
}, [
|
|
476
|
+
}, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
|
|
500
477
|
};
|
|
501
478
|
export {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
ye as
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
};
|