@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
@@ -0,0 +1,338 @@
1
+ import { jsx as G } from "react/jsx-runtime";
2
+ import { createPortal as x, useThree as U, useFrame as q } from "@react-three/fiber";
3
+ import { useState as y, useMemo as z, useEffect as B, useCallback as F, useRef as W } from "react";
4
+ import { Group as D, Vector3 as V, DoubleSide as Y, BackSide as $, FrontSide as Q, Shape as ee, Path as te, ShapeGeometry as ne } from "three";
5
+ import { Line2 as oe } from "three/addons/lines/Line2.js";
6
+ import { LineGeometry as re } from "three/addons/lines/LineGeometry.js";
7
+ import { LineMaterial as se } from "three/addons/lines/LineMaterial.js";
8
+ import { u as X, B as j } from "./useXRStore-eThHhTNv.js";
9
+ import { LocationBased as ce, Webcam as ie, DeviceOrientationControls as ae } from "locar";
10
+ const le = {
11
+ isPending: !0,
12
+ isSuccess: !1,
13
+ locar: null,
14
+ webcam: null,
15
+ deviceOrientation: null,
16
+ scene: null,
17
+ camera: null,
18
+ lastPosition: null,
19
+ registerAnchor: () => {
20
+ },
21
+ unregisterAnchor: () => {
22
+ },
23
+ getAnchor: () => {
24
+ }
25
+ }, N = () => {
26
+ const e = X((a) => a.backends).get(j.GEOLOCATION);
27
+ return e ? {
28
+ ...e.getInternal(),
29
+ isPending: !1,
30
+ isSuccess: !0
31
+ } : le;
32
+ }, Se = ({
33
+ coordinates: o,
34
+ color: e = "#ff0000",
35
+ isDashed: a = !1,
36
+ dashSize: l = 3,
37
+ gapSize: h = 1,
38
+ lineWidth: d = 1
39
+ }) => {
40
+ const r = N(), [t] = y(() => new D()), u = z(() => Math.random().toString(36).slice(2, 11), []), [s, g] = y(null);
41
+ return B(() => {
42
+ if (!r.isSuccess || o.length < 2) return;
43
+ const [m, n, c = 0] = o[0], L = (p) => {
44
+ const [S, b, i = 0] = o[0], [A, E] = p.lonLatToWorldCoords(
45
+ S,
46
+ b
47
+ ), w = o.map(([M, f, v = 0]) => {
48
+ const [P, T] = p.lonLatToWorldCoords(M, f);
49
+ return new V(P - A, v - i, T - E);
50
+ }), k = new re().setFromPoints(w), O = new se({
51
+ color: e,
52
+ dashSize: l,
53
+ gapSize: h,
54
+ dashed: a,
55
+ worldUnits: !0,
56
+ linewidth: d
57
+ }), C = new oe(k, O);
58
+ a && C.computeLineDistances(), g(C);
59
+ };
60
+ return r.registerAnchor(u, {
61
+ anchor: t,
62
+ isAttached: !1,
63
+ latitude: n,
64
+ longitude: m,
65
+ altitude: c,
66
+ onAttach: L
67
+ }), () => {
68
+ r.unregisterAnchor(u);
69
+ };
70
+ }, [
71
+ r.isSuccess,
72
+ r.registerAnchor,
73
+ r.unregisterAnchor,
74
+ u,
75
+ t,
76
+ o,
77
+ e,
78
+ a,
79
+ l,
80
+ h,
81
+ d
82
+ ]), x(
83
+ /* @__PURE__ */ G("group", { children: s && /* @__PURE__ */ G("primitive", { object: s }) }),
84
+ t
85
+ );
86
+ }, be = ({
87
+ latitude: o,
88
+ longitude: e,
89
+ altitude: a = 0,
90
+ isBillboard: l = !0,
91
+ onAttach: h,
92
+ onGpsUpdate: d,
93
+ children: r
94
+ }) => {
95
+ const t = N(), { camera: u } = U(), [s] = y(() => new D()), g = z(() => Math.random().toString(36).slice(2, 11), []), m = F(() => {
96
+ h?.();
97
+ }, [h]), n = F(
98
+ (c, L) => {
99
+ d?.(c, L);
100
+ },
101
+ [d]
102
+ );
103
+ return B(() => {
104
+ if (t.isSuccess)
105
+ return t.registerAnchor(g, {
106
+ anchor: s,
107
+ isAttached: !1,
108
+ latitude: o,
109
+ longitude: e,
110
+ altitude: a,
111
+ onAttach: m,
112
+ onGpsUpdate: n
113
+ }), () => {
114
+ t.unregisterAnchor(g);
115
+ };
116
+ }, [
117
+ t.isSuccess,
118
+ t.registerAnchor,
119
+ t.unregisterAnchor,
120
+ s,
121
+ g,
122
+ o,
123
+ e,
124
+ a,
125
+ m,
126
+ n
127
+ ]), q(() => {
128
+ !l || !u || !t.isSuccess || !t.getAnchor(g)?.isAttached || s.lookAt(u.position);
129
+ }), x(/* @__PURE__ */ G("group", { children: r }), s);
130
+ }, ke = ({
131
+ options: o = {},
132
+ children: e
133
+ }) => {
134
+ const { scene: a, camera: l, gl: h } = U(), { registerBackend: d, unregisterBackend: r } = X(), t = W(null), u = W(o);
135
+ return u.current = o, B(() => {
136
+ if (t.current) return;
137
+ let s = !1;
138
+ return (async () => {
139
+ try {
140
+ const m = de(u.current);
141
+ if (s) return;
142
+ await d(m, { scene: a, camera: l, renderer: h }), t.current = m;
143
+ } catch (m) {
144
+ console.error("[GeolocationSession] Failed to initialize:", m);
145
+ }
146
+ })(), () => {
147
+ s = !0, t.current && (r(t.current), t.current = null);
148
+ };
149
+ }, [a, l, h, d, r]), e;
150
+ }, ue = {
151
+ front: Q,
152
+ back: $,
153
+ double: Y
154
+ }, Ge = ({
155
+ coordinates: o,
156
+ holes: e,
157
+ color: a = "#ff0000",
158
+ opacity: l = 1,
159
+ isWireframe: h = !1,
160
+ side: d = "double"
161
+ }) => {
162
+ const r = N(), [t] = y(() => new D()), u = z(() => Math.random().toString(36).slice(2, 11), []), [s, g] = y(null);
163
+ return B(() => {
164
+ if (!r.isSuccess || o.length < 3) return;
165
+ const [m, n, c = 0] = o[0], L = (p) => {
166
+ const [S, b, i = 0] = o[0], [A, E] = p.lonLatToWorldCoords(
167
+ S,
168
+ b
169
+ ), w = [];
170
+ for (const [f, v, P = 0] of o) {
171
+ const [T, I] = p.lonLatToWorldCoords(f, v);
172
+ w.push({
173
+ x: T - A,
174
+ z: I - E,
175
+ elev: P - i
176
+ });
177
+ }
178
+ const k = new ee();
179
+ k.moveTo(w[0].x, w[0].z);
180
+ for (let f = 1; f < w.length; f++)
181
+ k.lineTo(w[f].x, w[f].z);
182
+ if (k.closePath(), e && e.length > 0)
183
+ for (const f of e) {
184
+ if (f.length < 3) continue;
185
+ const v = new te(), [P, T] = f[0], [I, H] = p.lonLatToWorldCoords(
186
+ P,
187
+ T
188
+ );
189
+ v.moveTo(I - A, H - E);
190
+ for (let R = 1; R < f.length; R++) {
191
+ const [Z, J] = f[R], [K, _] = p.lonLatToWorldCoords(Z, J);
192
+ v.lineTo(K - A, _ - E);
193
+ }
194
+ v.closePath(), k.holes.push(v);
195
+ }
196
+ const O = new ne(k), M = w.reduce((f, v) => f + v.elev, 0) / w.length;
197
+ O.rotateX(-Math.PI / 2), g({ geometry: O, avgElevation: M });
198
+ };
199
+ return r.registerAnchor(u, {
200
+ anchor: t,
201
+ isAttached: !1,
202
+ latitude: n,
203
+ longitude: m,
204
+ altitude: c,
205
+ onAttach: L
206
+ }), () => {
207
+ r.unregisterAnchor(u);
208
+ };
209
+ }, [
210
+ r.isSuccess,
211
+ r.registerAnchor,
212
+ r.unregisterAnchor,
213
+ u,
214
+ t,
215
+ o,
216
+ e
217
+ ]), x(
218
+ /* @__PURE__ */ G("group", { children: s && /* @__PURE__ */ G("group", { position: [0, s.avgElevation, 0], children: /* @__PURE__ */ G("mesh", { geometry: s.geometry, children: /* @__PURE__ */ G(
219
+ "meshBasicMaterial",
220
+ {
221
+ color: a,
222
+ opacity: l,
223
+ transparent: l < 1,
224
+ wireframe: h,
225
+ side: ue[d]
226
+ }
227
+ ) }) }) }),
228
+ t
229
+ );
230
+ }, de = (o) => {
231
+ let e = null, a = null, l = null, h, d = null, r = null, t = null, u = null;
232
+ const s = /* @__PURE__ */ new Map();
233
+ let g = null;
234
+ const m = (n) => {
235
+ if (!(!e || n.isAttached))
236
+ try {
237
+ e.add(n.anchor, n.longitude, n.latitude, n.altitude), n.isAttached = !0, n.onAttach?.(e);
238
+ } catch (c) {
239
+ console.error("❌ Failed to attach anchor:", c);
240
+ }
241
+ };
242
+ return {
243
+ type: j.GEOLOCATION,
244
+ async init(n) {
245
+ const { camera: c, renderer: L, scene: p } = n;
246
+ if (!p)
247
+ throw new Error(
248
+ "[geolocationBackend] A THREE.Scene is required for location-based AR"
249
+ );
250
+ r = c, t = L, u = p, e = new ce(p, c), a = new ie(
251
+ o?.webcamConstraints ?? {
252
+ video: { facingMode: "environment" }
253
+ // TODO remove `as any` once fixed upstream (LocAR.js)
254
+ }
255
+ ), d = (i) => {
256
+ g = i.position;
257
+ for (const A of s.values())
258
+ A.isAttached || m(A), A.onGpsUpdate?.(i.position, i.distMoved);
259
+ o?.onGpsUpdate?.(i.position, i.distMoved);
260
+ }, e.on("gpsupdate", d), a.on("webcamstarted", (i) => {
261
+ p.background = i.texture;
262
+ }), a.on("webcamerror", (i) => {
263
+ console.error("[geolocationBackend] webcam error:", i);
264
+ }), l = new ae(c), l.on("deviceorientationgranted", (i) => {
265
+ i.target?.connect?.();
266
+ }), l.on("deviceorientationerror", (i) => {
267
+ console.error("[geolocationBackend] Device orientation error:", i);
268
+ }), l.init?.(), e.on("gpserror", (i) => {
269
+ console.error("[geolocationBackend] gps error:", i);
270
+ }), e.startGps(), typeof o?.fakeLat == "number" && typeof o?.fakeLon == "number" && e.fakeGps(o.fakeLon, o.fakeLat);
271
+ const S = e.getLastKnownLocation();
272
+ S !== null && (g = {
273
+ coords: {
274
+ longitude: S.longitude,
275
+ latitude: S.latitude,
276
+ accuracy: 0,
277
+ altitude: null,
278
+ altitudeAccuracy: null,
279
+ heading: null,
280
+ speed: null,
281
+ toJSON: () => S
282
+ },
283
+ timestamp: Date.now(),
284
+ toJSON: () => S
285
+ });
286
+ const b = () => {
287
+ if (!t || !r) return;
288
+ const i = window.innerWidth, A = window.innerHeight;
289
+ t.setSize(i, A, !1), r.aspect = i / A, r.updateProjectionMatrix?.();
290
+ };
291
+ b(), window.addEventListener("resize", b), h = b;
292
+ },
293
+ update() {
294
+ l?.update?.();
295
+ },
296
+ dispose() {
297
+ e && d && e.off("gpsupdate", d), e?.stopGps?.(), a?.stop?.(), l?.dispose?.(), h && (window.removeEventListener("resize", h), h = void 0);
298
+ for (const n of s.values())
299
+ if (n.isAttached)
300
+ try {
301
+ n.anchor.removeFromParent();
302
+ } catch (c) {
303
+ console.error("⚠️ Error removing anchor:", c);
304
+ }
305
+ s.clear(), e = null, a = null, l = null, r = null, t = null, u = null, d = null, g = null;
306
+ },
307
+ getInternal: () => ({
308
+ locar: e,
309
+ webcam: a,
310
+ deviceOrientation: l,
311
+ scene: u,
312
+ camera: r,
313
+ lastPosition: g,
314
+ registerAnchor: (n, c) => {
315
+ s.set(n, c), g !== null && !c.isAttached && (m(c), c.onGpsUpdate?.(g, 0));
316
+ },
317
+ unregisterAnchor: (n) => {
318
+ const c = s.get(n);
319
+ if (c?.isAttached)
320
+ try {
321
+ c.anchor.removeFromParent();
322
+ } catch (L) {
323
+ console.error(`⚠️ Error removing anchor ${n}:`, L);
324
+ }
325
+ s.delete(n);
326
+ },
327
+ getAnchor: (n) => s.get(n)
328
+ })
329
+ };
330
+ };
331
+ export {
332
+ Se as G,
333
+ be as a,
334
+ ke as b,
335
+ Ge as c,
336
+ de as d,
337
+ N as u
338
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./ImmersiveSession-BiX-Du0K.cjs");exports.ImmersiveSession=e.ImmersiveSession;
@@ -0,0 +1,2 @@
1
+ export * from './immersive/index'
2
+ export {}
@@ -0,0 +1,4 @@
1
+ import { I as m } from "./ImmersiveSession-CJRYdHjb.js";
2
+ export {
3
+ m as ImmersiveSession
4
+ };
package/build/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),R=require("@react-three/fiber"),v=require("react/jsx-runtime"),P=require("@ar-js-org/ar.js/three.js/build/ar-threex"),I=require("three"),re=require("three/addons/lines/Line2.js"),oe=require("three/addons/lines/LineGeometry.js"),se=require("three/addons/lines/LineMaterial.js"),N=require("locar"),U=require("@react-three/xr");var X=typeof document<"u"?document.currentScript:null;const b={FIDUCIAL:"fiducial",GEOLOCATION:"geolocation",IMMERSIVE:"immersive"},W=t=>{let e;const n=new Set,r=(s,f)=>{const u=typeof s=="function"?s(e):s;if(!Object.is(u,e)){const c=e;e=f??(typeof u!="object"||u===null)?u:Object.assign({},e,u),n.forEach(A=>A(e,c))}},i=()=>e,o={setState:r,getState:i,getInitialState:()=>d,subscribe:s=>(n.add(s),()=>n.delete(s))},d=e=t(r,i,o);return o},ce=(t=>t?W(t):W),ie=t=>t;function ae(t,e=ie){const n=m.useSyncExternalStore(t.subscribe,m.useCallback(()=>e(t.getState()),[t,e]),m.useCallback(()=>e(t.getInitialState()),[t,e]));return m.useDebugValue(n),n}const le=t=>{const e=ce(t),n=r=>ae(e,r);return Object.assign(n,e),n},ue=(t=>le),de=t=>(e,n,r)=>{const i=r.subscribe;return r.subscribe=((l,o,d)=>{let s=l;if(o){const f=d?.equalityFn||Object.is;let u=l(r.getState());s=c=>{const A=l(c);if(!f(u,A)){const h=u;o(u=A,h)}},d?.fireImmediately&&o(u,u)}return i(s)}),t(e,n,r)},Ae=de,_=t=>Symbol.iterator in t,H=t=>"entries"in t,K=(t,e)=>{const n=t instanceof Map?t:new Map(t.entries()),r=e instanceof Map?e:new Map(e.entries());if(n.size!==r.size)return!1;for(const[i,a]of n)if(!r.has(i)||!Object.is(a,r.get(i)))return!1;return!0},fe=(t,e)=>{const n=t[Symbol.iterator](),r=e[Symbol.iterator]();let i=n.next(),a=r.next();for(;!i.done&&!a.done;){if(!Object.is(i.value,a.value))return!1;i=n.next(),a=r.next()}return!!i.done&&!!a.done};function me(t,e){return Object.is(t,e)?!0:typeof t!="object"||t===null||typeof e!="object"||e===null||Object.getPrototypeOf(t)!==Object.getPrototypeOf(e)?!1:_(t)&&_(e)?H(t)&&H(e)?K(t,e):fe(t,e):K({entries:()=>Object.entries(t)},{entries:()=>Object.entries(e)})}function ge(t){const e=m.useRef(void 0);return n=>{const r=t(n);return me(e.current,r)?e.current:e.current=r}}const q=ue()(Ae((t,e)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(n,r)=>{try{const i=e(),a=new Set(i.backends.keys()),l=a.has(b.FIDUCIAL)||n.type===b.FIDUCIAL,o=a.has(b.GEOLOCATION)||n.type===b.GEOLOCATION;if(l&&o){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.";throw console.error(d),new Error(d)}await n.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),t(d=>{const s=new Map(d.backends);return s.set(n.type,n),{backends:s}})}catch(i){throw console.error("[XRStore] Failed to register backend:",i),i}},unregisterBackend:n=>{t(r=>{const i=new Map(r.backends);i.delete(n.type);try{n.dispose?.()}catch(a){console.error("[XRStore] Error disposing backend:",a)}return{backends:i}})},setVideo:n=>{t({video:n})},updateBackends:n=>{const{backends:r}=e();for(const i of r.values())try{i.update?.(n)}catch(a){console.error("[XRStore] Backend update error:",a)}},setImmersiveStore:n=>{t({immersiveStore:n})}}))),V=()=>q.getState(),he=q.subscribe,C=t=>q(ge(n=>{const r={...n,isImmersive:n.backends.has(b.IMMERSIVE),immersive:n.immersiveStore||null};return t?t(r):r})),Se=({children:t})=>{const{updateBackends:e}=C();return R.useFrame((n,r)=>{e(r)}),t},pe={isPending:!0,isSuccess:!1,arSource:null,arContext:null},Y=()=>{const e=C(n=>n.backends).get(b.FIDUCIAL);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:pe},be=({patternUrl:t,barcodeValue:e,params:n,onMarkerFound:r,onMarkerLost:i,children:a})=>{const l=m.useRef(null),o=Y(),d=m.useRef(!1),s=m.useRef(!1),f=m.useRef(null);return m.useEffect(()=>{if(!o.isSuccess)return;let u=!1;return(()=>{try{const{arContext:A}=o,h=l.current;if(!A||!h||u)return;if(h.visible=!1,s.current=!1,!A.arController){requestAnimationFrame(()=>{if(!l.current||u||!o.arContext?.arController)return;const y=new P.ArMarkerControls(o.arContext,l.current,{type:t?"pattern":e?"barcode":"unknown",patternUrl:t,barcodeValue:e,...n});f.current=y,s.current=!0});return}const p=new P.ArMarkerControls(A,h,{type:t?"pattern":e?"barcode":"unknown",patternUrl:t,barcodeValue:e,...n});f.current=p,s.current=!0}catch(A){console.error("Failed to initialize fiducial anchor:",A)}})(),()=>{u=!0;const A=f.current;typeof A?.dispose=="function"&&A.dispose(),s.current=!1}},[o.isSuccess,o.arContext,t,e,n,o]),R.useFrame(()=>{const u=l.current;if(!u||!s.current){u&&(u.visible=!1);return}const c=u.visible;c&&!d.current?(d.current=!0,r?.()):!c&&d.current&&(d.current=!1,i?.())}),v.jsx("group",{ref:l,visible:!1,children:a})},we=({options:t={},children:e})=>{const{scene:n,camera:r,gl:i}=R.useThree(),{registerBackend:a,unregisterBackend:l}=C(),o=m.useRef(null),d=m.useRef(t);return d.current=t,m.useEffect(()=>{if(o.current)return;let s=!1;return(async()=>{try{const u=Q(d.current);if(s)return;await a(u,{scene:n,camera:r,renderer:i}),o.current=u}catch(u){console.error("[FiducialSession] Failed to initialize:",u)}})(),()=>{s=!0,o.current&&(l(o.current),o.current=null)}},[n,r,i,a,l]),e},Q=t=>{let e=null,n=null,r=null,i;return{type:b.FIDUCIAL,async init({camera:a,renderer:l}){e=new P.ArToolkitSource({sourceType:t?.sourceType??"webcam"}),await new Promise((s,f)=>{const u=setTimeout(()=>{f(new Error("AR source initialization timeout"))},1e4);e?.init(()=>{clearTimeout(u);const c=e?.domElement;c&&(c.style.position="fixed",c.style.top="0",c.style.left="0",c.style.width="100vw",c.style.height="100vh",c.style.objectFit="cover",c.style.zIndex="-1",c.style.pointerEvents="none"),s()})});const o={cameraParametersUrl:t?.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:X&&X.tagName.toUpperCase()==="SCRIPT"&&X.src||new URL("index.cjs",document.baseURI).href).toString(),detectionMode:t?.detectionMode??"mono",patternRatio:t?.patternRatio??.5,matrixCodeType:t?.matrixCodeType??"3x3"};n=new P.ArToolkitContext(o),r=a;const d=()=>{e?.onResizeElement();const s=window.innerWidth,f=window.innerHeight;l.setSize(s,f,!1),e?.copyElementSizeTo(l.domElement),n?.arController&&e?.copyElementSizeTo(n.arController.canvas)};await new Promise((s,f)=>{const u=setTimeout(()=>{f(new Error("AR context initialization timeout"))},1e4);n?.init(()=>{clearTimeout(u);try{const c=n?.getProjectionMatrix();c&&a.projectionMatrix.copy(c),d(),s()}catch(c){f(c)}})}),window.addEventListener("resize",d),i=d},update(){if(!(!e||!n)&&!(!e.ready||!e.domElement))try{n.update(e.domElement);const a=n.getProjectionMatrix?.();r&&a&&r.projectionMatrix.copy(a)}catch(a){console.warn("AR.js update error:",a)}},dispose(){if(i&&(window.removeEventListener("resize",i),i=void 0),n&&typeof n.dispose=="function"&&n.dispose(),e?.domElement){const a=e.domElement.parentNode;a&&a.removeChild(e.domElement)}e=null,n=null,r=null},getInternal:()=>({arSource:e,arContext:n})}},ye={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>{}},G=()=>{const e=C(n=>n.backends).get(b.GEOLOCATION);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:ye},ke=({coordinates:t,color:e="#ff0000",isDashed:n=!1,dashSize:r=3,gapSize:i=1,lineWidth:a=1})=>{const l=G(),[o]=m.useState(()=>new I.Group),d=m.useMemo(()=>Math.random().toString(36).slice(2,11),[]),[s,f]=m.useState(null);return m.useEffect(()=>{if(!l.isSuccess||t.length<2)return;const[u,c,A=0]=t[0],h=p=>{const[y,L,g=0]=t[0],[w,M]=p.lonLatToWorldCoords(y,L),k=t.map(([z,S,E=0])=>{const[T,j]=p.lonLatToWorldCoords(z,S);return new I.Vector3(T-w,E-g,j-M)}),x=new oe.LineGeometry().setFromPoints(k),O=new se.LineMaterial({color:e,dashSize:r,gapSize:i,dashed:n,worldUnits:!0,linewidth:a}),F=new re.Line2(x,O);n&&F.computeLineDistances(),f(F)};return l.registerAnchor(d,{anchor:o,isAttached:!1,latitude:c,longitude:u,altitude:A,onAttach:h}),()=>{l.unregisterAnchor(d)}},[l.isSuccess,l.registerAnchor,l.unregisterAnchor,d,o,t,e,n,r,i,a]),R.createPortal(v.jsx("group",{children:s&&v.jsx("primitive",{object:s})}),o)},Ee=({latitude:t,longitude:e,altitude:n=0,isBillboard:r=!0,onAttach:i,onGpsUpdate:a,children:l})=>{const o=G(),{camera:d}=R.useThree(),[s]=m.useState(()=>new I.Group),f=m.useMemo(()=>Math.random().toString(36).slice(2,11),[]),u=m.useCallback(()=>{i?.()},[i]),c=m.useCallback((A,h)=>{a?.(A,h)},[a]);return m.useEffect(()=>{if(o.isSuccess)return o.registerAnchor(f,{anchor:s,isAttached:!1,latitude:t,longitude:e,altitude:n,onAttach:u,onGpsUpdate:c}),()=>{o.unregisterAnchor(f)}},[o.isSuccess,o.registerAnchor,o.unregisterAnchor,s,f,t,e,n,u,c]),R.useFrame(()=>{!r||!d||!o.isSuccess||!o.getAnchor(f)?.isAttached||s.lookAt(d.position)}),R.createPortal(v.jsx("group",{children:l}),s)},Ie=({options:t={},children:e})=>{const{scene:n,camera:r,gl:i}=R.useThree(),{registerBackend:a,unregisterBackend:l}=C(),o=m.useRef(null),d=m.useRef(t);return d.current=t,m.useEffect(()=>{if(o.current)return;let s=!1;return(async()=>{try{const u=J(d.current);if(s)return;await a(u,{scene:n,camera:r,renderer:i}),o.current=u}catch(u){console.error("[GeolocationSession] Failed to initialize:",u)}})(),()=>{s=!0,o.current&&(l(o.current),o.current=null)}},[n,r,i,a,l]),e},ve={front:I.FrontSide,back:I.BackSide,double:I.DoubleSide},Re=({coordinates:t,holes:e,color:n="#ff0000",opacity:r=1,isWireframe:i=!1,side:a="double"})=>{const l=G(),[o]=m.useState(()=>new I.Group),d=m.useMemo(()=>Math.random().toString(36).slice(2,11),[]),[s,f]=m.useState(null);return m.useEffect(()=>{if(!l.isSuccess||t.length<3)return;const[u,c,A=0]=t[0],h=p=>{const[y,L,g=0]=t[0],[w,M]=p.lonLatToWorldCoords(y,L),k=[];for(const[S,E,T=0]of t){const[j,B]=p.lonLatToWorldCoords(S,E);k.push({x:j-w,z:B-M,elev:T-g})}const x=new I.Shape;x.moveTo(k[0].x,k[0].z);for(let S=1;S<k.length;S++)x.lineTo(k[S].x,k[S].z);if(x.closePath(),e&&e.length>0)for(const S of e){if(S.length<3)continue;const E=new I.Path,[T,j]=S[0],[B,Z]=p.lonLatToWorldCoords(T,j);E.moveTo(B-w,Z-M);for(let D=1;D<S.length;D++){const[$,ee]=S[D],[te,ne]=p.lonLatToWorldCoords($,ee);E.lineTo(te-w,ne-M)}E.closePath(),x.holes.push(E)}const O=new I.ShapeGeometry(x),z=k.reduce((S,E)=>S+E.elev,0)/k.length;O.rotateX(-Math.PI/2),f({geometry:O,avgElevation:z})};return l.registerAnchor(d,{anchor:o,isAttached:!1,latitude:c,longitude:u,altitude:A,onAttach:h}),()=>{l.unregisterAnchor(d)}},[l.isSuccess,l.registerAnchor,l.unregisterAnchor,d,o,t,e]),R.createPortal(v.jsx("group",{children:s&&v.jsx("group",{position:[0,s.avgElevation,0],children:v.jsx("mesh",{geometry:s.geometry,children:v.jsx("meshBasicMaterial",{color:n,opacity:r,transparent:r<1,wireframe:i,side:ve[a]})})})}),o)},J=t=>{let e=null,n=null,r=null,i,a=null,l=null,o=null,d=null;const s=new Map;let f=null;const u=c=>{if(!(!e||c.isAttached))try{e.add(c.anchor,c.longitude,c.latitude,c.altitude),c.isAttached=!0,c.onAttach?.(e)}catch(A){console.error("❌ Failed to attach anchor:",A)}};return{type:b.GEOLOCATION,async init(c){const{camera:A,renderer:h,scene:p}=c;if(!p)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");l=A,o=h,d=p,e=new N.LocationBased(p,A),n=new N.Webcam(t?.webcamConstraints??{video:{facingMode:"environment"}}),a=g=>{f=g.position;for(const w of s.values())w.isAttached||u(w),w.onGpsUpdate?.(g.position,g.distMoved);t?.onGpsUpdate?.(g.position,g.distMoved)},e.on("gpsupdate",a),n.on("webcamstarted",g=>{p.background=g.texture}),n.on("webcamerror",g=>{console.error("[geolocationBackend] webcam error:",g)}),r=new N.DeviceOrientationControls(A),r.on("deviceorientationgranted",g=>{g.target?.connect?.()}),r.on("deviceorientationerror",g=>{console.error("[geolocationBackend] Device orientation error:",g)}),r.init?.(),e.on("gpserror",g=>{console.error("[geolocationBackend] gps error:",g)}),e.startGps(),typeof t?.fakeLat=="number"&&typeof t?.fakeLon=="number"&&e.fakeGps(t.fakeLon,t.fakeLat);const y=e.getLastKnownLocation();y!==null&&(f={coords:{longitude:y.longitude,latitude:y.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>y},timestamp:Date.now(),toJSON:()=>y});const L=()=>{if(!o||!l)return;const g=window.innerWidth,w=window.innerHeight;o.setSize(g,w,!1),l.aspect=g/w,l.updateProjectionMatrix?.()};L(),window.addEventListener("resize",L),i=L},update(){r?.update?.()},dispose(){e&&a&&e.off("gpsupdate",a),e?.stopGps?.(),n?.stop?.(),r?.dispose?.(),i&&(window.removeEventListener("resize",i),i=void 0);for(const c of s.values())if(c.isAttached)try{c.anchor.removeFromParent()}catch(A){console.error("⚠️ Error removing anchor:",A)}s.clear(),e=null,n=null,r=null,l=null,o=null,d=null,a=null,f=null},getInternal:()=>({locar:e,webcam:n,deviceOrientation:r,scene:d,camera:l,lastPosition:f,registerAnchor:(c,A)=>{s.set(c,A),f!==null&&!A.isAttached&&(u(A),A.onGpsUpdate?.(f,0))},unregisterAnchor:c=>{const A=s.get(c);if(A?.isAttached)try{A.anchor.removeFromParent()}catch(h){console.error(`⚠️ Error removing anchor ${c}:`,h)}s.delete(c)},getAnchor:c=>s.get(c)})}},Le=()=>({type:b.IMMERSIVE,init:()=>{},getInternal:()=>null}),xe=({children:t})=>{const e=m.useMemo(()=>U.createXRStore(),[]);return m.useEffect(()=>{const n=V(),r=Le();return n.backends.set(b.IMMERSIVE,r),n.setImmersiveStore(e),()=>{n.backends.delete(b.IMMERSIVE),n.setImmersiveStore(null)}},[e]),v.jsx(U.XR,{store:e,children:t})};exports.BACKEND_TYPES=b;exports.FiducialAnchor=be;exports.FiducialSession=we;exports.GeoLine=ke;exports.GeoPolygon=Re;exports.GeolocationAnchor=Ee;exports.GeolocationSession=Ie;exports.ImmersiveSession=xe;exports.XR=Se;exports.createFiducialBackend=Q;exports.createGeolocationBackend=J;exports.getXRStore=V;exports.subscribeToXRStore=he;exports.useFiducialBackend=Y;exports.useGeolocationBackend=G;exports.useXRStore=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./useXRStore-emhiLtDT.cjs"),s=require("@react-three/fiber"),c=require("./fiducialBackend-Cr8mdwro.cjs"),e=require("./geolocationBackend-BkS2-zqx.cjs"),t=require("./ImmersiveSession-BiX-Du0K.cjs"),i=require("./WorldAnchor-gszXX9H2.cjs"),u=({children:n})=>{const{updateBackends:r}=o.useXRStore();return s.useFrame((d,a)=>{r(a)}),n};exports.BACKEND_TYPES=o.BACKEND_TYPES;exports.getXRStore=o.getXRStore;exports.subscribeToXRStore=o.subscribeToXRStore;exports.useXRStore=o.useXRStore;exports.FiducialAnchor=c.FiducialAnchor;exports.FiducialSession=c.FiducialSession;exports.createFiducialBackend=c.createFiducialBackend;exports.useFiducialBackend=c.useFiducialBackend;exports.GeoLine=e.GeoLine;exports.GeoPolygon=e.GeoPolygon;exports.GeolocationAnchor=e.GeolocationAnchor;exports.GeolocationSession=e.GeolocationSession;exports.createGeolocationBackend=e.createGeolocationBackend;exports.useGeolocationBackend=e.useGeolocationBackend;exports.ImmersiveSession=t.ImmersiveSession;exports.MagicSession=i.MagicSession;exports.WorldAnchor=i.WorldAnchor;exports.createMagicBackend=i.createMagicBackend;exports.XR=u;
package/build/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './fiducial';
4
4
  export * from './geolocation';
5
5
  export * from './immersive';
6
6
  export { BACKEND_TYPES } from './lib/types/engine';
7
+ export * from './magic';
7
8
  export type { Backend, BackendType, } from './lib/types/engine';
8
9
  export type { ImmersiveMode } from './lib/types/immersive';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,UAAU,EACV,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,YAAY,EACV,OAAO,EACP,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,OAAO,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,UAAU,EACV,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,cAAc,SAAS,CAAC;AAExB,YAAY,EACV,OAAO,EACP,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG3D,OAAO,oBAAoB,CAAC"}