@omnidotdev/rdk 0.6.0 → 0.8.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/index.js CHANGED
@@ -1,493 +1,675 @@
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 = {
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 = {
9
12
  FIDUCIAL: "fiducial",
10
13
  GEOLOCATION: "geolocation",
11
14
  IMMERSIVE: "immersive"
12
- }, L = (n) => {
15
+ }, _ = (t) => {
13
16
  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));
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));
19
22
  }
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])
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])
28
31
  );
29
- return y.useDebugValue(t), t;
32
+ return O.useDebugValue(n), n;
30
33
  }
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) => {
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) => {
35
38
  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);
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);
46
49
  }
47
- }, u?.fireImmediately && a(l, l);
50
+ }, d?.fireImmediately && o(u, u);
48
51
  }
49
- return c(i);
50
- }), n(e, t, r);
51
- }, Z = $, j = (n) => Symbol.iterator in n, z = (n) => (
52
+ return c(s);
53
+ }), t(e, n, r);
54
+ }, Le = ve, Q = (t) => Symbol.iterator in t, Y = (t) => (
52
55
  // HACK: avoid checking entries type
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)
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)
57
60
  return !1;
58
- for (const [c, s] of t)
59
- if (!r.has(c) || !Object.is(s, r.get(c)))
61
+ for (const [c, a] of n)
62
+ if (!r.has(c) || !Object.is(a, r.get(c)))
60
63
  return !1;
61
64
  return !0;
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))
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))
67
70
  return !1;
68
- c = t.next(), s = r.next();
71
+ c = n.next(), a = r.next();
69
72
  }
70
- return !!c.done && !!s.done;
73
+ return !!c.done && !!a.done;
71
74
  };
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
+ 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) },
75
78
  { entries: () => Object.entries(e) }
76
79
  );
77
80
  }
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;
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;
83
86
  };
84
87
  }
85
- const M = J()(
86
- Z((n, e) => ({
88
+ const H = Ee()(
89
+ Le((t, e) => ({
87
90
  // initial state
88
91
  video: null,
89
92
  backends: /* @__PURE__ */ new Map(),
90
93
  immersiveStore: null,
91
94
  // actions
92
- registerBackend: async (t, r) => {
95
+ registerBackend: async (n, r) => {
93
96
  try {
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);
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);
98
101
  }
99
- await t.init({
102
+ await n.init({
100
103
  scene: r.scene,
101
104
  camera: r.camera,
102
105
  renderer: r.renderer
103
- }), n((u) => {
104
- const i = new Map(u.backends);
105
- return i.set(t.type, t), { backends: i };
106
+ }), t((d) => {
107
+ const s = new Map(d.backends);
108
+ return s.set(n.type, n), { backends: s };
106
109
  });
107
110
  } catch (c) {
108
111
  throw console.error("[XRStore] Failed to register backend:", c), c;
109
112
  }
110
113
  },
111
- unregisterBackend: (t) => {
112
- n((r) => {
114
+ unregisterBackend: (n) => {
115
+ t((r) => {
113
116
  const c = new Map(r.backends);
114
- c.delete(t.type);
117
+ c.delete(n.type);
115
118
  try {
116
- t.dispose?.();
117
- } catch (s) {
118
- console.error("[XRStore] Error disposing backend:", s);
119
+ n.dispose?.();
120
+ } catch (a) {
121
+ console.error("[XRStore] Error disposing backend:", a);
119
122
  }
120
123
  return { backends: c };
121
124
  });
122
125
  },
123
- setVideo: (t) => {
124
- n({ video: t });
126
+ setVideo: (n) => {
127
+ t({ video: n });
125
128
  },
126
- updateBackends: (t) => {
129
+ updateBackends: (n) => {
127
130
  const { backends: r } = e();
128
131
  for (const c of r.values())
129
132
  try {
130
- c.update?.(t);
131
- } catch (s) {
132
- console.error("[XRStore] Backend update error:", s);
133
+ c.update?.(n);
134
+ } catch (a) {
135
+ console.error("[XRStore] Backend update error:", a);
133
136
  }
134
137
  },
135
- setImmersiveStore: (t) => {
136
- n({ immersiveStore: t });
138
+ setImmersiveStore: (n) => {
139
+ t({ immersiveStore: n });
137
140
  }
138
141
  }))
139
- ), ne = () => M.getState(), pe = M.subscribe, I = (n) => M(
140
- te((t) => {
142
+ ), xe = () => H.getState(), _e = H.subscribe, P = (t) => H(
143
+ Me((n) => {
141
144
  const r = {
142
- ...t,
143
- isImmersive: t.backends.has(p.IMMERSIVE),
144
- immersive: t.immersiveStore || null
145
+ ...n,
146
+ isImmersive: n.backends.has(b.IMMERSIVE),
147
+ immersive: n.immersiveStore || null
145
148
  };
146
- return n ? n(r) : r;
149
+ return t ? t(r) : r;
147
150
  })
148
- ), be = ({ children: n }) => {
149
- const { updateBackends: e } = I();
150
- return R((t, r) => {
151
+ ), Qe = ({ children: t }) => {
152
+ const { updateBackends: e } = P();
153
+ return N((n, r) => {
151
154
  e(r);
152
- }), n;
153
- }, re = () => I((t) => t.backends).get(p.FIDUCIAL)?.getInternal() ?? null, Se = ({
154
- patternUrl: n,
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,
155
170
  barcodeValue: e,
156
- params: t,
171
+ params: n,
157
172
  onMarkerFound: r,
158
173
  onMarkerLost: c,
159
- children: s
174
+ children: a
160
175
  }) => {
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;
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;
165
180
  return (() => {
166
181
  try {
167
- const { arContext: d } = a, b = A.current;
168
- if (!d || !b || l) return;
169
- if (b.visible = !1, i.current = !1, !d.arController) {
182
+ const { arContext: A } = o, g = l.current;
183
+ if (!A || !g || u) return;
184
+ if (g.visible = !1, s.current = !1, !A.arController) {
170
185
  requestAnimationFrame(() => {
171
- if (!A.current || l || !a.arContext?.arController)
186
+ if (!l.current || u || !o.arContext?.arController)
172
187
  return;
173
- const g = new x(
174
- a.arContext,
175
- A.current,
188
+ const w = new K(
189
+ o.arContext,
190
+ l.current,
176
191
  {
177
- type: n ? "pattern" : e ? "barcode" : "unknown",
178
- patternUrl: n,
192
+ type: t ? "pattern" : e ? "barcode" : "unknown",
193
+ patternUrl: t,
179
194
  barcodeValue: e,
180
- ...t
195
+ ...n
181
196
  }
182
197
  );
183
- f.current = g, i.current = !0;
198
+ f.current = w, s.current = !0;
184
199
  });
185
200
  return;
186
201
  }
187
- const h = new x(d, b, {
188
- type: n ? "pattern" : e ? "barcode" : "unknown",
189
- patternUrl: n,
202
+ const p = new K(A, g, {
203
+ type: t ? "pattern" : e ? "barcode" : "unknown",
204
+ patternUrl: t,
190
205
  barcodeValue: e,
191
- ...t
206
+ ...n
192
207
  });
193
- f.current = h, i.current = !0;
194
- } catch (d) {
195
- console.error("Failed to initialize fiducial anchor:", d);
208
+ f.current = p, s.current = !0;
209
+ } catch (A) {
210
+ console.error("Failed to initialize fiducial anchor:", A);
196
211
  }
197
212
  })(), () => {
198
- l = !0;
199
- const d = f.current;
200
- typeof d?.dispose == "function" && d.dispose(), i.current = !1;
213
+ u = !0;
214
+ const A = f.current;
215
+ typeof A?.dispose == "function" && A.dispose(), s.current = !1;
201
216
  };
202
- }, [a, n, e, t]), R(() => {
203
- const l = A.current;
204
- if (!l || !i.current) {
205
- l && (l.visible = !1);
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);
206
228
  return;
207
229
  }
208
- const o = l.visible;
209
- o && !u.current ? (u.current = !0, r?.()) : !o && u.current && (u.current = !1, c?.());
210
- }), /* @__PURE__ */ C(
230
+ const i = u.visible;
231
+ i && !d.current ? (d.current = !0, r?.()) : !i && d.current && (d.current = !1, c?.());
232
+ }), /* @__PURE__ */ I(
211
233
  "group",
212
234
  {
213
- ref: A,
235
+ ref: l,
214
236
  visible: !1,
215
- children: s
237
+ children: a
216
238
  }
217
239
  );
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;
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;
223
245
  return (async () => {
224
246
  try {
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);
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);
230
252
  }
231
253
  })(), () => {
232
- i = !0, a.current && (A(a.current), a.current = null);
254
+ s = !0, o.current && (l(o.current), o.current = null);
233
255
  };
234
- }, [t, r, c, s, A]), e;
235
- }, oe = (n) => {
236
- let e = null, t = null, r = null, c;
256
+ }, [n, r, c, a, l]), e;
257
+ }, Pe = (t) => {
258
+ let e = null, n = null, r = null, c;
237
259
  return {
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(() => {
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(() => {
244
266
  f(new Error("AR source initialization timeout"));
245
267
  }, 1e4);
246
268
  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();
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();
250
272
  });
251
273
  });
252
- const a = {
253
- cameraParametersUrl: n?.cameraParametersUrl ?? // default to internal camera parameters
274
+ const o = {
275
+ cameraParametersUrl: t?.cameraParametersUrl ?? // default to internal camera parameters
254
276
  new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
255
- detectionMode: n?.detectionMode ?? "mono",
256
- patternRatio: n?.patternRatio ?? 0.5,
257
- matrixCodeType: n?.matrixCodeType ?? "3x3"
277
+ detectionMode: t?.detectionMode ?? "mono",
278
+ patternRatio: t?.patternRatio ?? 0.5,
279
+ matrixCodeType: t?.matrixCodeType ?? "3x3"
258
280
  };
259
- t = new D(a), r = s;
260
- const u = () => {
281
+ n = new oe(o), r = a;
282
+ const d = () => {
261
283
  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);
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);
264
286
  };
265
- await new Promise((i, f) => {
266
- const l = setTimeout(() => {
287
+ await new Promise((s, f) => {
288
+ const u = setTimeout(() => {
267
289
  f(new Error("AR context initialization timeout"));
268
290
  }, 1e4);
269
- t?.init(() => {
270
- clearTimeout(l);
291
+ n?.init(() => {
292
+ clearTimeout(u);
271
293
  try {
272
- const o = t?.getProjectionMatrix();
273
- o && s.projectionMatrix.copy(o), u(), i();
274
- } catch (o) {
275
- f(o);
294
+ const i = n?.getProjectionMatrix();
295
+ i && a.projectionMatrix.copy(i), d(), s();
296
+ } catch (i) {
297
+ f(i);
276
298
  }
277
299
  });
278
- }), window.addEventListener("resize", u), c = u;
300
+ }), window.addEventListener("resize", d), c = d;
279
301
  },
280
302
  update() {
281
- if (!(!e || !t) && !(!e.ready || !e.domElement))
303
+ if (!(!e || !n) && !(!e.ready || !e.domElement))
282
304
  try {
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);
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);
288
310
  }
289
311
  },
290
312
  dispose() {
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);
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);
294
316
  }
295
- e = null, t = null, r = null;
317
+ e = null, n = null, r = null;
296
318
  },
297
319
  getInternal: () => ({
298
320
  arSource: e,
299
- arContext: t
321
+ arContext: n
300
322
  })
301
323
  };
302
- }, ce = () => I((t) => t.backends).get(p.GEOLOCATION)?.getInternal() ?? null, he = ({
303
- latitude: n,
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,
304
402
  longitude: e,
305
- altitude: t = 0,
403
+ altitude: n = 0,
306
404
  isBillboard: r = !0,
307
405
  onAttach: c,
308
- onGpsUpdate: s,
309
- children: A
406
+ onGpsUpdate: a,
407
+ children: l
310
408
  }) => {
311
- const a = ce(), { camera: u } = v(), [i] = B(() => new N()), f = T(() => Math.random().toString(36).slice(2, 11), []), l = O(() => {
409
+ const o = q(), { camera: d } = X(), [s] = T(() => new W()), f = j(() => Math.random().toString(36).slice(2, 11), []), u = V(() => {
312
410
  c?.();
313
- }, [c]), o = O(
314
- (d, b) => {
315
- s?.(d, b);
411
+ }, [c]), i = V(
412
+ (A, g) => {
413
+ a?.(A, g);
316
414
  },
317
- [s]
415
+ [a]
318
416
  );
319
- return k(() => {
320
- if (a)
321
- return a.registerAnchor(f, {
322
- anchor: i,
417
+ return C(() => {
418
+ if (o.isSuccess)
419
+ return o.registerAnchor(f, {
420
+ anchor: s,
323
421
  isAttached: !1,
324
- latitude: n,
422
+ latitude: t,
325
423
  longitude: e,
326
- altitude: t,
327
- onAttach: l,
328
- onGpsUpdate: o
424
+ altitude: n,
425
+ onAttach: u,
426
+ onGpsUpdate: i
329
427
  }), () => {
330
- a.unregisterAnchor(f);
428
+ o.unregisterAnchor(f);
331
429
  };
332
430
  }, [
333
- a,
334
- i,
431
+ o.isSuccess,
432
+ o.registerAnchor,
433
+ o.unregisterAnchor,
434
+ s,
335
435
  f,
336
- n,
337
- e,
338
436
  t,
339
- l,
340
- o
341
- ]), R(() => {
342
- !r || !u || !a || !a.getAnchor(f)?.isAttached || i.lookAt(u.position);
343
- }), G(/* @__PURE__ */ C("group", { children: A }), i);
344
- }, we = ({
345
- options: n = {},
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 = {},
346
446
  children: e
347
447
  }) => {
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;
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;
352
452
  return (async () => {
353
453
  try {
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);
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);
359
459
  }
360
460
  })(), () => {
361
- i = !0, a.current && (A(a.current), a.current = null);
461
+ s = !0, o.current && (l(o.current), o.current = null);
362
462
  };
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();
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();
367
547
  let f = null;
368
- const l = (o) => {
369
- if (!(!e || o.isAttached))
548
+ const u = (i) => {
549
+ if (!(!e || i.isAttached))
370
550
  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);
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);
374
554
  }
375
555
  };
376
556
  return {
377
- type: p.GEOLOCATION,
378
- async init(o) {
379
- const { camera: d, renderer: b, scene: h } = o;
380
- if (!h)
557
+ type: b.GEOLOCATION,
558
+ async init(i) {
559
+ const { camera: A, renderer: g, scene: p } = i;
560
+ if (!p)
381
561
  throw new Error(
382
562
  "[geolocationBackend] A THREE.Scene is required for location-based AR"
383
563
  );
384
- A = d, a = b, u = h, e = new X(h, d), t = new U(
385
- n?.webcamConstraints ?? {
564
+ l = A, o = g, d = p, e = new ge(p, A), n = new he(
565
+ t?.webcamConstraints ?? {
386
566
  video: { facingMode: "environment" }
387
567
  // TODO remove `as any` once fixed upstream (LocAR.js)
388
568
  }
389
- ), s = (m) => {
569
+ ), a = (m) => {
390
570
  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) => {
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) => {
397
577
  console.error("[geolocationBackend] webcam error:", m);
398
- }), r = new H(d), r.on("deviceorientationgranted", (m) => {
578
+ }), r = new pe(A), r.on("deviceorientationgranted", (m) => {
399
579
  m.target?.connect?.();
400
580
  }), r.on("deviceorientationerror", (m) => {
401
581
  console.error("[geolocationBackend] Device orientation error:", m);
402
582
  }), r.init?.(), e.on("gpserror", (m) => {
403
583
  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 = {
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 = {
407
587
  coords: {
408
- longitude: g.longitude,
409
- latitude: g.latitude,
588
+ longitude: w.longitude,
589
+ latitude: w.latitude,
410
590
  accuracy: 0,
411
591
  altitude: null,
412
592
  altitudeAccuracy: null,
413
593
  heading: null,
414
594
  speed: null,
415
- toJSON: () => g
595
+ toJSON: () => w
416
596
  },
417
597
  timestamp: Date.now(),
418
- toJSON: () => g
598
+ toJSON: () => w
419
599
  });
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?.();
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?.();
424
604
  };
425
- E(), window.addEventListener("resize", E), c = E;
605
+ v(), window.addEventListener("resize", v), c = v;
426
606
  },
427
607
  update() {
428
608
  r?.update?.();
429
609
  },
430
610
  dispose() {
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)
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)
434
614
  try {
435
- o.anchor.removeFromParent();
436
- } catch (d) {
437
- console.error("⚠️ Error removing anchor:", d);
615
+ i.anchor.removeFromParent();
616
+ } catch (A) {
617
+ console.error("⚠️ Error removing anchor:", A);
438
618
  }
439
- i.clear(), e = null, t = null, r = null, A = null, a = null, u = null, s = null, f = null;
619
+ s.clear(), e = null, n = null, r = null, l = null, o = null, d = null, a = null, f = null;
440
620
  },
441
621
  getInternal: () => ({
442
622
  locar: e,
443
- webcam: t,
623
+ webcam: n,
444
624
  deviceOrientation: r,
445
- scene: u,
446
- camera: A,
625
+ scene: d,
626
+ camera: l,
447
627
  lastPosition: f,
448
- registerAnchor: (o, d) => {
449
- i.set(o, d), f !== null && !d.isAttached && (l(d), d.onGpsUpdate?.(f, 0));
628
+ registerAnchor: (i, A) => {
629
+ s.set(i, A), f !== null && !A.isAttached && (u(A), A.onGpsUpdate?.(f, 0));
450
630
  },
451
- unregisterAnchor: (o) => {
452
- const d = i.get(o);
453
- if (d?.isAttached)
631
+ unregisterAnchor: (i) => {
632
+ const A = s.get(i);
633
+ if (A?.isAttached)
454
634
  try {
455
- d.anchor.removeFromParent();
456
- } catch (b) {
457
- console.error(`⚠️ Error removing anchor ${o}:`, b);
635
+ A.anchor.removeFromParent();
636
+ } catch (g) {
637
+ console.error(`⚠️ Error removing anchor ${i}:`, g);
458
638
  }
459
- i.delete(o);
639
+ s.delete(i);
460
640
  },
461
- getAnchor: (o) => i.get(o)
641
+ getAnchor: (i) => s.get(i)
462
642
  })
463
643
  };
464
- }, ie = () => ({
465
- type: p.IMMERSIVE,
644
+ }, Fe = () => ({
645
+ type: b.IMMERSIVE,
466
646
  init: () => {
467
647
  },
468
648
  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);
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);
475
655
  };
476
- }, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
656
+ }, [e]), /* @__PURE__ */ I(be, { store: e, children: t });
477
657
  };
478
658
  export {
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
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
493
675
  };