@omnidotdev/rdk 0.8.0 → 0.9.1

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 (41) hide show
  1. package/build/fiducial-CqsG94R9.js +163 -0
  2. package/build/fiducial-dapuWTXg.cjs +1 -0
  3. package/build/fiducial.cjs +1 -0
  4. package/build/fiducial.d.ts +2 -0
  5. package/build/fiducial.js +3 -0
  6. package/build/geolocation/GeoLine.d.ts.map +1 -1
  7. package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
  8. package/build/geolocation/geolocationBackend.d.ts.map +1 -1
  9. package/build/geolocation-U_vaIjuk.js +288 -0
  10. package/build/geolocation-uko8RwgK.cjs +1 -0
  11. package/build/geolocation.cjs +1 -0
  12. package/build/geolocation.d.ts +2 -0
  13. package/build/geolocation.js +3 -0
  14. package/build/immersive/ImmersiveSession.d.ts.map +1 -1
  15. package/build/immersive-8m33PLug.cjs +1 -0
  16. package/build/immersive-Dp2-ZCRC.js +23 -0
  17. package/build/immersive.cjs +1 -0
  18. package/build/immersive.d.ts +2 -0
  19. package/build/immersive.js +3 -0
  20. package/build/index.cjs +1 -1
  21. package/build/index.d.ts +1 -0
  22. package/build/index.d.ts.map +1 -1
  23. package/build/index.js +14 -674
  24. package/build/lib/types/engine/backend/Backend.interface.d.ts +1 -0
  25. package/build/lib/types/engine/backend/Backend.interface.d.ts.map +1 -1
  26. package/build/magic/MagicSession.d.ts +14 -0
  27. package/build/magic/MagicSession.d.ts.map +1 -0
  28. package/build/magic/WorldAnchor.d.ts +21 -0
  29. package/build/magic/WorldAnchor.d.ts.map +1 -0
  30. package/build/magic/index.d.ts +7 -0
  31. package/build/magic/index.d.ts.map +1 -0
  32. package/build/magic/magicBackend.d.ts +57 -0
  33. package/build/magic/magicBackend.d.ts.map +1 -0
  34. package/build/magic-DAQdGGEO.js +148 -0
  35. package/build/magic-DznuBYgG.cjs +1 -0
  36. package/build/magic.cjs +1 -0
  37. package/build/magic.d.ts +2 -0
  38. package/build/magic.js +3 -0
  39. package/build/useXRStore-7Gy83DEg.cjs +1 -0
  40. package/build/useXRStore-B3-MaaCu.js +131 -0
  41. package/package.json +31 -8
@@ -0,0 +1,14 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { MagicSessionOptions } from './magicBackend';
3
+ export interface MagicSessionProps extends PropsWithChildren {
4
+ /** Magic window session options. */
5
+ options?: MagicSessionOptions;
6
+ }
7
+ /**
8
+ * Manage the magic window AR backend.
9
+ * Registers with the XR session provider and provides device orientation
10
+ * tracking with camera passthrough capabilities.
11
+ */
12
+ declare const MagicSession: ({ options, children }: MagicSessionProps) => import('react').ReactNode;
13
+ export default MagicSession;
14
+ //# sourceMappingURL=MagicSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MagicSession.d.ts","sourceRoot":"","sources":["../../src/magic/MagicSession.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,oCAAoC;IACpC,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B;AAED;;;;GAIG;AACH,QAAA,MAAM,YAAY,GAAI,uBAA4B,iBAAiB,8BA4ClE,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export interface WorldAnchorProps extends PropsWithChildren {
3
+ /** Position offset relative to the initial orientation. */
4
+ position?: [number, number, number];
5
+ /** Rotation offset in radians. */
6
+ rotation?: [number, number, number];
7
+ /** Scale factor. */
8
+ scale?: number | [number, number, number];
9
+ /**
10
+ * Whether the anchor should face the camera every frame.
11
+ * @default false
12
+ */
13
+ isBillboard?: boolean;
14
+ }
15
+ /**
16
+ * World anchor that positions children relative to the device's initial orientation.
17
+ * Uses the magic window backend's orientation data for world-space positioning.
18
+ */
19
+ declare const WorldAnchor: ({ position, rotation, scale, isBillboard, children, }: WorldAnchorProps) => import("react/jsx-runtime").JSX.Element;
20
+ export default WorldAnchor;
21
+ //# sourceMappingURL=WorldAnchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorldAnchor.d.ts","sourceRoot":"","sources":["../../src/magic/WorldAnchor.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAI/C,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,kCAAkC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;GAGG;AACH,QAAA,MAAM,WAAW,GAAI,uDAMlB,gBAAgB,4CA0ClB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { default as MagicSession } from './MagicSession';
2
+ export { default as createMagicBackend } from './magicBackend';
3
+ export { default as WorldAnchor } from './WorldAnchor';
4
+ export type { MagicSessionProps } from './MagicSession';
5
+ export type { MagicInternal, MagicSessionOptions, } from './magicBackend';
6
+ export type { WorldAnchorProps } from './WorldAnchor';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/magic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AAEvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,YAAY,EACV,aAAa,EACb,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { Backend } from 'lib/types/engine';
2
+ import * as THREE from "three";
3
+ /**
4
+ * Internal state exposed by the magic window backend.
5
+ */
6
+ export interface MagicInternal {
7
+ videoElement: HTMLVideoElement | null;
8
+ videoTexture: THREE.VideoTexture | null;
9
+ stream: MediaStream | null;
10
+ orientationEnabled: boolean;
11
+ orientationPermissionGranted: boolean;
12
+ worldAnchoringEnabled: boolean;
13
+ currentOrientation: {
14
+ alpha: number;
15
+ beta: number;
16
+ gamma: number;
17
+ };
18
+ initialOrientation: {
19
+ alpha: number;
20
+ beta: number;
21
+ gamma: number;
22
+ };
23
+ hasInitialOrientation: boolean;
24
+ /** Request device orientation permission (must be called from user gesture on iOS) */
25
+ requestOrientationPermission: () => Promise<boolean>;
26
+ }
27
+ /**
28
+ * Options for the magic window backend.
29
+ */
30
+ export interface MagicSessionOptions {
31
+ /** Whether to enable device orientation tracking. */
32
+ enableOrientation?: boolean;
33
+ /** Whether to enable world anchoring (orientation-based positioning). */
34
+ enableWorldAnchoring?: boolean;
35
+ /**
36
+ * Smoothing factor for orientation interpolation (0-1).
37
+ * Lower values produce smoother but more delayed movement.
38
+ * @default 0.15
39
+ */
40
+ smoothingFactor?: number;
41
+ /**
42
+ * Dead zone threshold in degrees.
43
+ * Orientation changes smaller than this value are ignored to prevent jitter.
44
+ * @default 0.5
45
+ */
46
+ deadZone?: number;
47
+ /** Custom webcam constraints. */
48
+ webcamConstraints?: MediaStreamConstraints;
49
+ }
50
+ /**
51
+ * Create a magic window AR backend.
52
+ * Provides device orientation tracking and camera passthrough without
53
+ * requiring WebXR, using standard browser APIs (DeviceOrientation + getUserMedia).
54
+ */
55
+ declare const createMagicBackend: (options?: MagicSessionOptions) => Backend<MagicInternal>;
56
+ export default createMagicBackend;
57
+ //# sourceMappingURL=magicBackend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"magicBackend.d.ts","sourceRoot":"","sources":["../../src/magic/magicBackend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACtC,YAAY,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IACxC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,4BAA4B,EAAE,OAAO,CAAC;IACtC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,kBAAkB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,kBAAkB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,qBAAqB,EAAE,OAAO,CAAC;IAC/B,sFAAsF;IACtF,4BAA4B,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yEAAyE;IACzE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;CAC5C;AAMD;;;;GAIG;AACH,QAAA,MAAM,kBAAkB,GACtB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,aAAa,CA2avB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,148 @@
1
+ import { i as e, r as t } from "./useXRStore-B3-MaaCu.js";
2
+ import { useEffect as n, useRef as r } from "react";
3
+ import { useFrame as i, useThree as a } from "@react-three/fiber";
4
+ import { jsx as o } from "react/jsx-runtime";
5
+ import * as s from "three";
6
+ //#region src/magic/magicBackend.ts
7
+ var c = .15, l = .5, u = (t) => {
8
+ let n = null, r = null, i = null, a, o = t?.enableOrientation ?? !0, u = !1, d = t?.enableWorldAnchoring ?? !0, f = null, p = null, m = t?.smoothingFactor ?? c, h = t?.deadZone ?? l, g = {
9
+ alpha: 0,
10
+ beta: 0,
11
+ gamma: 0
12
+ }, _ = {
13
+ alpha: 0,
14
+ beta: 0,
15
+ gamma: 0
16
+ }, v = {
17
+ alpha: 0,
18
+ beta: 0,
19
+ gamma: 0
20
+ }, y = !1, b = null, x = null, S = null, C = new s.Quaternion(), w = new s.Quaternion(), T = new s.Euler(), E = new s.Quaternion(), D = new s.Quaternion(-Math.sqrt(.5), 0, 0, Math.sqrt(.5)), O = new s.Vector3(0, 0, 1), k = new s.Quaternion(), A = new s.Quaternion(), j = (e, t, n, r) => {
21
+ let i = (screen.orientation?.angle ?? 0) * Math.PI / 180;
22
+ T.set(n, t, -r, "YXZ"), e.setFromEuler(T), e.multiply(D), e.multiply(E.setFromAxisAngle(O, -i));
23
+ }, M = (e, t) => {
24
+ let n = (t - e) % 360 + 360;
25
+ return n = (n + 180) % 360 - 180, n;
26
+ }, N = (e, t, n = !1) => Math.abs(n ? M(e, t) : t - e) < h ? e : t, P = (e, t, n) => e + (t - e) * n, F = (e, t, n) => ((e + M(e, t) * n) % 360 + 360) % 360, I = async () => {
27
+ let e = DeviceOrientationEvent;
28
+ if (typeof e.requestPermission == "function") try {
29
+ return await e.requestPermission() === "granted" ? (u = !0, !0) : (console.warn("[MagicBackend] Device orientation permission denied"), !1);
30
+ } catch (e) {
31
+ return console.error("[MagicBackend] Error requesting orientation permission:", e), !1;
32
+ }
33
+ return u = !0, !0;
34
+ }, L = () => {
35
+ f = (e) => {
36
+ if (g.alpha = e.alpha ?? 0, g.beta = e.beta ?? 0, g.gamma = e.gamma ?? 0, !y && (g.alpha !== 0 || g.beta !== 0 || g.gamma !== 0)) {
37
+ v.alpha = g.alpha, v.beta = g.beta, v.gamma = g.gamma;
38
+ let { degToRad: e } = s.MathUtils;
39
+ j(k, e(g.alpha), e(g.beta), e(g.gamma)), A.copy(k).invert(), y = !0;
40
+ }
41
+ }, window.addEventListener("deviceorientation", f, !0);
42
+ }, R = async (e, a) => {
43
+ let o = t?.webcamConstraints ?? { video: { facingMode: "environment" } };
44
+ try {
45
+ i = await navigator.mediaDevices.getUserMedia(o);
46
+ } catch (e) {
47
+ throw console.error("[MagicBackend] Failed to access camera:", e), e;
48
+ }
49
+ n = document.createElement("video"), n.srcObject = i, n.setAttribute("playsinline", ""), n.setAttribute("autoplay", ""), n.muted = !0, n.style.position = "fixed", n.style.top = "0", n.style.left = "0", n.style.width = "100vw", n.style.height = "100vh", n.style.objectFit = "cover", n.style.zIndex = "-1", n.style.pointerEvents = "none", document.body.appendChild(n), await n.play(), r = new s.VideoTexture(n), r.minFilter = s.LinearFilter, r.magFilter = s.LinearFilter, r.colorSpace = s.SRGBColorSpace, e.background = r, a.setClearColor(0, 0);
50
+ };
51
+ return {
52
+ type: e.MAGIC,
53
+ async init({ scene: e, camera: t, renderer: n }) {
54
+ if (b = t, x = n, S = e, await R(e, n), o) if (await I()) L();
55
+ else {
56
+ let e = async () => {
57
+ document.removeEventListener("click", e), document.removeEventListener("touchend", e), p = null, await I() && L();
58
+ };
59
+ p = e, document.addEventListener("click", e), document.addEventListener("touchend", e);
60
+ }
61
+ let r = () => {
62
+ if (!x || !b) return;
63
+ let e = window.innerWidth, t = window.innerHeight;
64
+ x.setSize(e, t, !1), b.aspect = e / t, b.updateProjectionMatrix?.();
65
+ };
66
+ r(), window.addEventListener("resize", r), a = r;
67
+ },
68
+ update() {
69
+ if (!o || !u) return;
70
+ let e = N(_.alpha, g.alpha, !0), t = N(_.beta, g.beta), n = N(_.gamma, g.gamma);
71
+ if (_.alpha = F(_.alpha, e, m), _.beta = P(_.beta, t, m), _.gamma = P(_.gamma, n, m), d && b && y) {
72
+ let { degToRad: e } = s.MathUtils;
73
+ j(C, e(g.alpha), e(g.beta), e(g.gamma)), w.copy(A).multiply(C), b.quaternion.slerp(w, m);
74
+ }
75
+ r && (r.needsUpdate = !0);
76
+ },
77
+ dispose() {
78
+ if (f &&= (window.removeEventListener("deviceorientation", f), null), p &&= (document.removeEventListener("click", p), document.removeEventListener("touchend", p), null), a &&= (window.removeEventListener("resize", a), void 0), i) {
79
+ for (let e of i.getTracks()) e.stop();
80
+ i = null;
81
+ }
82
+ n &&= (n.pause(), n.srcObject = null, n.parentNode?.removeChild(n), null), r &&= (r.dispose(), null), S && (S.background = null), b = null, x = null, S = null, o = !1, u = !1, d = !1, y = !1, _.alpha = 0, _.beta = 0, _.gamma = 0, g.alpha = 0, g.beta = 0, g.gamma = 0, v.alpha = 0, v.beta = 0, v.gamma = 0, k.identity(), A.identity();
83
+ },
84
+ getInternal: () => ({
85
+ videoElement: n,
86
+ videoTexture: r,
87
+ stream: i,
88
+ orientationEnabled: o,
89
+ orientationPermissionGranted: u,
90
+ worldAnchoringEnabled: d,
91
+ currentOrientation: { ..._ },
92
+ initialOrientation: { ...v },
93
+ hasInitialOrientation: y,
94
+ requestOrientationPermission: async () => {
95
+ let e = await I();
96
+ return e && !f && L(), e;
97
+ }
98
+ })
99
+ };
100
+ }, d = ({ options: e = {}, children: i }) => {
101
+ let { scene: o, camera: s, gl: c } = a(), { registerBackend: l, unregisterBackend: d } = t(), f = r(null), p = r(e);
102
+ return p.current = e, n(() => {
103
+ if (f.current) return;
104
+ let e = !1;
105
+ return (async () => {
106
+ try {
107
+ let t = u(p.current);
108
+ if (e) return;
109
+ await l(t, {
110
+ scene: o,
111
+ camera: s,
112
+ renderer: c
113
+ }), f.current = t;
114
+ } catch (e) {
115
+ console.error("[MagicSession] Failed to initialize:", e);
116
+ }
117
+ })(), () => {
118
+ e = !0, f.current &&= (d(f.current), null);
119
+ };
120
+ }, [
121
+ o,
122
+ s,
123
+ c,
124
+ l,
125
+ d
126
+ ]), i;
127
+ }, f = ({ position: n = [
128
+ 0,
129
+ 0,
130
+ -2
131
+ ], rotation: a = [
132
+ 0,
133
+ 0,
134
+ 0
135
+ ], scale: s = 1, isBillboard: c = !1, children: l }) => {
136
+ let u = r(null), d = t((e) => e.backends);
137
+ return i(({ camera: t }) => {
138
+ let r = u.current;
139
+ if (!r) return;
140
+ let i = d.get(e.MAGIC);
141
+ i && i.getInternal().hasInitialOrientation && (r.position.set(n[0], n[1], n[2]), r.rotation.set(a[0], a[1], a[2]), typeof s == "number" ? r.scale.setScalar(s) : r.scale.set(s[0], s[1], s[2]), c && r.lookAt(t.position));
142
+ }), /* @__PURE__ */ o("group", {
143
+ ref: u,
144
+ children: l
145
+ });
146
+ };
147
+ //#endregion
148
+ export { d as n, u as r, f as t };
@@ -0,0 +1 @@
1
+ const e=require(`./useXRStore-7Gy83DEg.cjs`);let t=require(`react`),n=require(`@react-three/fiber`),r=require(`react/jsx-runtime`),i=require(`three`);i=e.a(i);var a=.15,o=.5,s=t=>{let n=null,r=null,s=null,c,l=t?.enableOrientation??!0,u=!1,d=t?.enableWorldAnchoring??!0,f=null,p=null,m=t?.smoothingFactor??a,h=t?.deadZone??o,g={alpha:0,beta:0,gamma:0},_={alpha:0,beta:0,gamma:0},v={alpha:0,beta:0,gamma:0},y=!1,b=null,x=null,S=null,C=new i.Quaternion,w=new i.Quaternion,T=new i.Euler,E=new i.Quaternion,D=new i.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),O=new i.Vector3(0,0,1),k=new i.Quaternion,A=new i.Quaternion,j=(e,t,n,r)=>{let i=(screen.orientation?.angle??0)*Math.PI/180;T.set(n,t,-r,`YXZ`),e.setFromEuler(T),e.multiply(D),e.multiply(E.setFromAxisAngle(O,-i))},M=(e,t)=>{let n=(t-e)%360+360;return n=(n+180)%360-180,n},N=(e,t,n=!1)=>Math.abs(n?M(e,t):t-e)<h?e:t,P=(e,t,n)=>e+(t-e)*n,F=(e,t,n)=>((e+M(e,t)*n)%360+360)%360,I=async()=>{let e=DeviceOrientationEvent;if(typeof e.requestPermission==`function`)try{return await e.requestPermission()===`granted`?(u=!0,!0):(console.warn(`[MagicBackend] Device orientation permission denied`),!1)}catch(e){return console.error(`[MagicBackend] Error requesting orientation permission:`,e),!1}return u=!0,!0},L=()=>{f=e=>{if(g.alpha=e.alpha??0,g.beta=e.beta??0,g.gamma=e.gamma??0,!y&&(g.alpha!==0||g.beta!==0||g.gamma!==0)){v.alpha=g.alpha,v.beta=g.beta,v.gamma=g.gamma;let{degToRad:e}=i.MathUtils;j(k,e(g.alpha),e(g.beta),e(g.gamma)),A.copy(k).invert(),y=!0}},window.addEventListener(`deviceorientation`,f,!0)},R=async(e,a)=>{let o=t?.webcamConstraints??{video:{facingMode:`environment`}};try{s=await navigator.mediaDevices.getUserMedia(o)}catch(e){throw console.error(`[MagicBackend] Failed to access camera:`,e),e}n=document.createElement(`video`),n.srcObject=s,n.setAttribute(`playsinline`,``),n.setAttribute(`autoplay`,``),n.muted=!0,n.style.position=`fixed`,n.style.top=`0`,n.style.left=`0`,n.style.width=`100vw`,n.style.height=`100vh`,n.style.objectFit=`cover`,n.style.zIndex=`-1`,n.style.pointerEvents=`none`,document.body.appendChild(n),await n.play(),r=new i.VideoTexture(n),r.minFilter=i.LinearFilter,r.magFilter=i.LinearFilter,r.colorSpace=i.SRGBColorSpace,e.background=r,a.setClearColor(0,0)};return{type:e.i.MAGIC,async init({scene:e,camera:t,renderer:n}){if(b=t,x=n,S=e,await R(e,n),l)if(await I())L();else{let e=async()=>{document.removeEventListener(`click`,e),document.removeEventListener(`touchend`,e),p=null,await I()&&L()};p=e,document.addEventListener(`click`,e),document.addEventListener(`touchend`,e)}let r=()=>{if(!x||!b)return;let e=window.innerWidth,t=window.innerHeight;x.setSize(e,t,!1),b.aspect=e/t,b.updateProjectionMatrix?.()};r(),window.addEventListener(`resize`,r),c=r},update(){if(!l||!u)return;let e=N(_.alpha,g.alpha,!0),t=N(_.beta,g.beta),n=N(_.gamma,g.gamma);if(_.alpha=F(_.alpha,e,m),_.beta=P(_.beta,t,m),_.gamma=P(_.gamma,n,m),d&&b&&y){let{degToRad:e}=i.MathUtils;j(C,e(g.alpha),e(g.beta),e(g.gamma)),w.copy(A).multiply(C),b.quaternion.slerp(w,m)}r&&(r.needsUpdate=!0)},dispose(){if(f&&=(window.removeEventListener(`deviceorientation`,f),null),p&&=(document.removeEventListener(`click`,p),document.removeEventListener(`touchend`,p),null),c&&=(window.removeEventListener(`resize`,c),void 0),s){for(let e of s.getTracks())e.stop();s=null}n&&=(n.pause(),n.srcObject=null,n.parentNode?.removeChild(n),null),r&&=(r.dispose(),null),S&&(S.background=null),b=null,x=null,S=null,l=!1,u=!1,d=!1,y=!1,_.alpha=0,_.beta=0,_.gamma=0,g.alpha=0,g.beta=0,g.gamma=0,v.alpha=0,v.beta=0,v.gamma=0,k.identity(),A.identity()},getInternal:()=>({videoElement:n,videoTexture:r,stream:s,orientationEnabled:l,orientationPermissionGranted:u,worldAnchoringEnabled:d,currentOrientation:{..._},initialOrientation:{...v},hasInitialOrientation:y,requestOrientationPermission:async()=>{let e=await I();return e&&!f&&L(),e}})}},c=({options:r={},children:i})=>{let{scene:a,camera:o,gl:c}=(0,n.useThree)(),{registerBackend:l,unregisterBackend:u}=e.r(),d=(0,t.useRef)(null),f=(0,t.useRef)(r);return f.current=r,(0,t.useEffect)(()=>{if(d.current)return;let e=!1;return(async()=>{try{let t=s(f.current);if(e)return;await l(t,{scene:a,camera:o,renderer:c}),d.current=t}catch(e){console.error(`[MagicSession] Failed to initialize:`,e)}})(),()=>{e=!0,d.current&&=(u(d.current),null)}},[a,o,c,l,u]),i},l=({position:i=[0,0,-2],rotation:a=[0,0,0],scale:o=1,isBillboard:s=!1,children:c})=>{let l=(0,t.useRef)(null),u=e.r(e=>e.backends);return(0,n.useFrame)(({camera:t})=>{let n=l.current;if(!n)return;let r=u.get(e.i.MAGIC);r&&r.getInternal().hasInitialOrientation&&(n.position.set(i[0],i[1],i[2]),n.rotation.set(a[0],a[1],a[2]),typeof o==`number`?n.scale.setScalar(o):n.scale.set(o[0],o[1],o[2]),s&&n.lookAt(t.position))}),(0,r.jsx)(`group`,{ref:l,children:c})};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./useXRStore-7Gy83DEg.cjs`);const e=require(`./magic-DznuBYgG.cjs`);exports.MagicSession=e.n,exports.WorldAnchor=e.t,exports.createMagicBackend=e.r;
@@ -0,0 +1,2 @@
1
+ export * from './magic/index'
2
+ export {}
package/build/magic.js ADDED
@@ -0,0 +1,3 @@
1
+ import "./useXRStore-B3-MaaCu.js";
2
+ import { n as e, r as t, t as n } from "./magic-DAQdGGEO.js";
3
+ export { e as MagicSession, n as WorldAnchor, t as createMagicBackend };
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`react`);c=s(c);var l={FIDUCIAL:`fiducial`,GEOLOCATION:`geolocation`,IMMERSIVE:`immersive`,MAGIC:`magic`},u=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},d=(e=>e?u(e):u),f=e=>e;function p(e,t=f){let n=c.default.useSyncExternalStore(e.subscribe,c.default.useCallback(()=>t(e.getState()),[e,t]),c.default.useCallback(()=>t(e.getInitialState()),[e,t]));return c.default.useDebugValue(n),n}var m=e=>{let t=d(e),n=e=>p(t,e);return Object.assign(n,t),n},h=(e=>e?m(e):m),g=e=>(t,n,r)=>{let i=r.subscribe;return r.subscribe=((e,t,n)=>{let a=e;if(t){let i=n?.equalityFn||Object.is,o=e(r.getState());a=n=>{let r=e(n);if(!i(o,r)){let e=o;t(o=r,e)}},n?.fireImmediately&&t(o,o)}return i(a)}),e(t,n,r)},_=e=>Symbol.iterator in e,v=e=>`entries`in e,y=(e,t)=>{let n=e instanceof Map?e:new Map(e.entries()),r=t instanceof Map?t:new Map(t.entries());if(n.size!==r.size)return!1;for(let[e,t]of n)if(!r.has(e)||!Object.is(t,r.get(e)))return!1;return!0},b=(e,t)=>{let n=e[Symbol.iterator](),r=t[Symbol.iterator](),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 x(e,t){return Object.is(e,t)?!0:typeof e!=`object`||!e||typeof t!=`object`||!t||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:_(e)&&_(t)?v(e)&&v(t)?y(e,t):b(e,t):y({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function S(e){let t=c.default.useRef(void 0);return n=>{let r=e(n);return x(t.current,r)?t.current:t.current=r}}var C=h()(g((e,t)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(n,r)=>{try{let i=t(),a=new Set(i.backends.keys()),o=a.has(l.FIDUCIAL)||n.type===l.FIDUCIAL,s=a.has(l.GEOLOCATION)||n.type===l.GEOLOCATION;if(o&&s){let e=`❌ [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(e),Error(e)}await n.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),e(e=>{let t=new Map(e.backends);return t.set(n.type,n),{backends:t}})}catch(e){throw console.error(`[XRStore] Failed to register backend:`,e),e}},unregisterBackend:t=>{e(e=>{let n=new Map(e.backends);n.delete(t.type);try{t.dispose?.()}catch(e){console.error(`[XRStore] Error disposing backend:`,e)}return{backends:n}})},setVideo:t=>{e({video:t})},updateBackends:e=>{let{backends:n}=t();for(let t of n.values())try{t.update?.(e)}catch(e){console.error(`[XRStore] Backend update error:`,e)}},setImmersiveStore:t=>{e({immersiveStore:t})}}))),w=()=>C.getState(),T=C.subscribe,E=e=>C(S(t=>{let n={...t,isImmersive:t.backends.has(l.IMMERSIVE),immersive:t.immersiveStore||null};return e?e(n):n}));Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return w}});
@@ -0,0 +1,131 @@
1
+ import e from "react";
2
+ //#region src/lib/types/engine/backend/Backend.interface.ts
3
+ var t = {
4
+ FIDUCIAL: "fiducial",
5
+ GEOLOCATION: "geolocation",
6
+ IMMERSIVE: "immersive",
7
+ MAGIC: "magic"
8
+ }, n = (e) => {
9
+ let t, n = /* @__PURE__ */ new Set(), r = (e, r) => {
10
+ let i = typeof e == "function" ? e(t) : e;
11
+ if (!Object.is(i, t)) {
12
+ let e = t;
13
+ t = r ?? (typeof i != "object" || !i) ? i : Object.assign({}, t, i), n.forEach((n) => n(t, e));
14
+ }
15
+ }, i = () => t, a = {
16
+ setState: r,
17
+ getState: i,
18
+ getInitialState: () => o,
19
+ subscribe: (e) => (n.add(e), () => n.delete(e))
20
+ }, o = t = e(r, i, a);
21
+ return a;
22
+ }, r = ((e) => e ? n(e) : n), i = (e) => e;
23
+ function a(t, n = i) {
24
+ let r = e.useSyncExternalStore(t.subscribe, e.useCallback(() => n(t.getState()), [t, n]), e.useCallback(() => n(t.getInitialState()), [t, n]));
25
+ return e.useDebugValue(r), r;
26
+ }
27
+ var o = (e) => {
28
+ let t = r(e), n = (e) => a(t, e);
29
+ return Object.assign(n, t), n;
30
+ }, s = ((e) => e ? o(e) : o), c = (e) => (t, n, r) => {
31
+ let i = r.subscribe;
32
+ return r.subscribe = ((e, t, n) => {
33
+ let a = e;
34
+ if (t) {
35
+ let i = n?.equalityFn || Object.is, o = e(r.getState());
36
+ a = (n) => {
37
+ let r = e(n);
38
+ if (!i(o, r)) {
39
+ let e = o;
40
+ t(o = r, e);
41
+ }
42
+ }, n?.fireImmediately && t(o, o);
43
+ }
44
+ return i(a);
45
+ }), e(t, n, r);
46
+ }, l = (e) => Symbol.iterator in e, u = (e) => "entries" in e, d = (e, t) => {
47
+ let n = e instanceof Map ? e : new Map(e.entries()), r = t instanceof Map ? t : new Map(t.entries());
48
+ if (n.size !== r.size) return !1;
49
+ for (let [e, t] of n) if (!r.has(e) || !Object.is(t, r.get(e))) return !1;
50
+ return !0;
51
+ }, f = (e, t) => {
52
+ let n = e[Symbol.iterator](), r = t[Symbol.iterator](), i = n.next(), a = r.next();
53
+ for (; !i.done && !a.done;) {
54
+ if (!Object.is(i.value, a.value)) return !1;
55
+ i = n.next(), a = r.next();
56
+ }
57
+ return !!i.done && !!a.done;
58
+ };
59
+ function p(e, t) {
60
+ return Object.is(e, t) ? !0 : typeof e != "object" || !e || typeof t != "object" || !t || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) ? !1 : l(e) && l(t) ? u(e) && u(t) ? d(e, t) : f(e, t) : d({ entries: () => Object.entries(e) }, { entries: () => Object.entries(t) });
61
+ }
62
+ //#endregion
63
+ //#region ../../node_modules/.bun/zustand@5.0.9+3efc971a6f010947/node_modules/zustand/esm/react/shallow.mjs
64
+ function m(t) {
65
+ let n = e.useRef(void 0);
66
+ return (e) => {
67
+ let r = t(e);
68
+ return p(n.current, r) ? n.current : n.current = r;
69
+ };
70
+ }
71
+ //#endregion
72
+ //#region src/engine/useXRStore.ts
73
+ var h = s()(c((e, n) => ({
74
+ video: null,
75
+ backends: /* @__PURE__ */ new Map(),
76
+ immersiveStore: null,
77
+ registerBackend: async (r, i) => {
78
+ try {
79
+ let a = n(), o = new Set(a.backends.keys()), s = o.has(t.FIDUCIAL) || r.type === t.FIDUCIAL, c = o.has(t.GEOLOCATION) || r.type === t.GEOLOCATION;
80
+ if (s && c) {
81
+ let e = "❌ [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.";
82
+ throw console.error(e), Error(e);
83
+ }
84
+ await r.init({
85
+ scene: i.scene,
86
+ camera: i.camera,
87
+ renderer: i.renderer
88
+ }), e((e) => {
89
+ let t = new Map(e.backends);
90
+ return t.set(r.type, r), { backends: t };
91
+ });
92
+ } catch (e) {
93
+ throw console.error("[XRStore] Failed to register backend:", e), e;
94
+ }
95
+ },
96
+ unregisterBackend: (t) => {
97
+ e((e) => {
98
+ let n = new Map(e.backends);
99
+ n.delete(t.type);
100
+ try {
101
+ t.dispose?.();
102
+ } catch (e) {
103
+ console.error("[XRStore] Error disposing backend:", e);
104
+ }
105
+ return { backends: n };
106
+ });
107
+ },
108
+ setVideo: (t) => {
109
+ e({ video: t });
110
+ },
111
+ updateBackends: (e) => {
112
+ let { backends: t } = n();
113
+ for (let n of t.values()) try {
114
+ n.update?.(e);
115
+ } catch (e) {
116
+ console.error("[XRStore] Backend update error:", e);
117
+ }
118
+ },
119
+ setImmersiveStore: (t) => {
120
+ e({ immersiveStore: t });
121
+ }
122
+ }))), g = () => h.getState(), _ = h.subscribe, v = (e) => h(m((n) => {
123
+ let r = {
124
+ ...n,
125
+ isImmersive: n.backends.has(t.IMMERSIVE),
126
+ immersive: n.immersiveStore || null
127
+ };
128
+ return e ? e(r) : r;
129
+ }));
130
+ //#endregion
131
+ export { t as i, _ as n, v as r, g as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@omnidotdev/rdk",
3
- "description": "AR.js with react-three-fiber",
4
- "version": "0.8.0",
3
+ "description": "Reality Development Kit, a unified React-first XR engine",
4
+ "version": "0.9.1",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "build/index.js",
@@ -15,6 +15,9 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/omnidotdev/rdk/issues"
17
17
  },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
18
21
  "files": [
19
22
  "build/"
20
23
  ],
@@ -31,6 +34,26 @@
31
34
  "types": "./build/index.d.ts",
32
35
  "import": "./build/index.js",
33
36
  "require": "./build/index.cjs"
37
+ },
38
+ "./fiducial": {
39
+ "types": "./build/fiducial.d.ts",
40
+ "import": "./build/fiducial.js",
41
+ "require": "./build/fiducial.cjs"
42
+ },
43
+ "./geolocation": {
44
+ "types": "./build/geolocation.d.ts",
45
+ "import": "./build/geolocation.js",
46
+ "require": "./build/geolocation.cjs"
47
+ },
48
+ "./immersive": {
49
+ "types": "./build/immersive.d.ts",
50
+ "import": "./build/immersive.js",
51
+ "require": "./build/immersive.cjs"
52
+ },
53
+ "./magic": {
54
+ "types": "./build/magic.d.ts",
55
+ "import": "./build/magic.js",
56
+ "require": "./build/magic.cjs"
34
57
  }
35
58
  },
36
59
  "scripts": {
@@ -50,7 +73,7 @@
50
73
  "locar": "^0.1.8",
51
74
  "react": "^19.2.0",
52
75
  "react-dom": "^19.2.0",
53
- "three": "^0.182.0"
76
+ "three": "^0.183.0"
54
77
  },
55
78
  "peerDependenciesMeta": {
56
79
  "@ar-js-org/ar.js": {
@@ -65,21 +88,21 @@
65
88
  },
66
89
  "devDependencies": {
67
90
  "@ar-js-org/ar.js": "^3.4.7",
68
- "@biomejs/biome": "^2.3.11",
91
+ "@biomejs/biome": "^2.4.8",
69
92
  "@react-three/fiber": "^9.5.0",
70
93
  "@testing-library/jest-dom": "^6.9.1",
71
94
  "@testing-library/react": "^16.3.1",
72
95
  "@types/node": "^25.0.3",
73
96
  "@types/react": "^19.2.7",
74
97
  "@types/react-dom": "^19.2.3",
75
- "@types/three": "^0.182.0",
76
- "jsdom": "^27.4.0",
98
+ "@types/three": "^0.183.0",
99
+ "jsdom": "^29.0.0",
77
100
  "locar": "^0.1.8",
78
101
  "react": "^19.2.3",
79
102
  "react-dom": "^19.2.3",
80
- "three": "^0.182.0",
103
+ "three": "^0.183.0",
81
104
  "typescript": "^5.9.3",
82
- "vite": "^7.3.0",
105
+ "vite": "^8.0.0",
83
106
  "vite-plugin-dts": "^4.5.4",
84
107
  "vite-tsconfig-paths": "^6.0.3",
85
108
  "vitest": "^4.0.16"