@omnidotdev/rdk 0.5.0 → 0.5.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.
- package/build/engine/useXRStore.d.ts.map +1 -1
- package/build/fiducial/FiducialSession.d.ts.map +1 -1
- package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
- package/build/geolocation/GeolocationSession.d.ts.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.js +313 -268
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useXRStore.d.ts","sourceRoot":"","sources":["../../src/engine/useXRStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useXRStore.d.ts","sourceRoot":"","sources":["../../src/engine/useXRStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE1D,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE/E,UAAU,gBAAgB;IACxB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,8CAA8C;IAC9C,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,uDAAuD;IACvD,YAAY,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;IACjC,6CAA6C;IAC7C,cAAc,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC3C;AAED,UAAU,kBAAkB;IAC1B,+CAA+C;IAC/C,eAAe,EAAE,CACf,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,aAAa,CAAA;KAAE,EACpE,WAAW,CAAC,EAAE,aAAa,KACxB,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,iDAAiD;IACjD,iBAAiB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3E,gCAAgC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAC;IACnD,yDAAyD;IACzD,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,oCAAoC;IACpC,iBAAiB,EAAE,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;CAC9D;AAED,KAAK,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAEzD,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACrC,CAAC;AA+FF,eAAO,MAAM,UAAU,mBAAkC,CAAC;AAC1D,eAAO,MAAM,kBAAkB;;;;;;CAA2B,CAAC;AAE3D;;GAEG;AACH,QAAA,MAAM,UAAU,GAAI,CAAC,GAAG,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,KAc5C,CACpB,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiducialSession.d.ts","sourceRoot":"","sources":["../../src/fiducial/FiducialSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,gCAAgC;IAChC,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe;4BAAgC,oBAAoB;;
|
|
1
|
+
{"version":3,"file":"FiducialSession.d.ts","sourceRoot":"","sources":["../../src/fiducial/FiducialSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,gCAAgC;IAChC,OAAO,CAAC,EAAE,sBAAsB,CAAC;CAClC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe;4BAAgC,oBAAoB;;CAgDxE,CAAC;AAKF,eAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeolocationAnchor.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationAnchor.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AA8BtE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,yBAAyB,EAAE,aAAa,CAAC,EACpD,iBAAiB;IACnB,wFAAwF;IACxF,QAAQ,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,QAAA,MAAM,iBAAiB,GAAI,2GAQxB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"GeolocationAnchor.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationAnchor.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AA8BtE,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,yBAAyB,EAAE,aAAa,CAAC,EACpD,iBAAiB;IACnB,wFAAwF;IACxF,QAAQ,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,QAAA,MAAM,iBAAiB,GAAI,2GAQxB,sBAAsB,gCAiNxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeolocationSession.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,mCAAmC;IACnC,OAAO,CAAC,EAAE,yBAAyB,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB;6BAGrB,uBAAuB;;
|
|
1
|
+
{"version":3,"file":"GeolocationSession.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationSession.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,mCAAmC;IACnC,OAAO,CAAC,EAAE,yBAAyB,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB;6BAGrB,uBAAuB;;CAgDzB,CAAC;AAKF,eAAe,kBAAkB,CAAC"}
|
package/build/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),v=require("@react-three/fiber"),L=require("react/jsx-runtime"),O=require("@ar-js-org/ar.js/three.js/build/ar-threex"),N=require("three"),H=require("locar"),G=require("@react-three/xr");var B=typeof document<"u"?document.currentScript:null;function W(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const F=W(H),j=e=>{let t;const n=new Set,o=(a,l)=>{const d=typeof a=="function"?a(t):a;if(!Object.is(d,t)){const c=t;t=l??(typeof d!="object"||d===null)?d:Object.assign({},t,d),n.forEach(m=>m(t,c))}},A=()=>t,r={setState:o,getState:A,getInitialState:()=>u,subscribe:a=>(n.add(a),()=>n.delete(a))},u=t=e(o,A,r);return r},Q=(e=>e?j(e):j),V=e=>e;function Y(e,t=V){const n=f.useSyncExternalStore(e.subscribe,f.useCallback(()=>t(e.getState()),[e,t]),f.useCallback(()=>t(e.getInitialState()),[e,t]));return f.useDebugValue(n),n}const K=e=>{const t=Q(e),n=o=>Y(t,o);return Object.assign(n,t),n},$=(e=>K),J=e=>(t,n,o)=>{const A=o.subscribe;return o.subscribe=((i,r,u)=>{let a=i;if(r){const l=u?.equalityFn||Object.is;let d=i(o.getState());a=c=>{const m=i(c);if(!l(d,m)){const g=d;r(d=m,g)}},u?.fireImmediately&&r(d,d)}return A(a)}),e(t,n,o)},Z=J,p={FIDUCIAL:"FiducialSession",GEOLOCATION:"GeolocationSession",IMMERSIVE:"ImmersiveSession"},M=$()(Z((e,t)=>({video:null,backends:[],sessionTypes:new Set,immersiveStore:null,registerBackend:async(n,o,A)=>{try{if(A){const s=t(),i=new Set([...s.sessionTypes,A]),r=i.has(p.FIDUCIAL),u=i.has(p.GEOLOCATION);if(r&&u){const a=`❌ [RDK] INCOMPATIBLE SESSIONS: ${p.FIDUCIAL} and ${p.GEOLOCATION} 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(a),new Error(a)}e(()=>({sessionTypes:i}))}await n.init({scene:o.scene,camera:o.camera,renderer:o.renderer}),e(s=>({backends:[...s.backends,n]}))}catch(s){throw console.error("[XRStore] Failed to register backend:",s),s}},unregisterBackend:(n,o)=>{e(A=>{const s=new Set(A.sessionTypes);o&&s.delete(o);const i=A.backends.filter(r=>r!==n);try{n.dispose?.()}catch(r){console.error("[XRStore] Error disposing backend:",r)}return{backends:i,sessionTypes:s}})},setVideo:n=>{e({video:n})},updateBackends:n=>{const{backends:o}=t();o.forEach(A=>{try{A.update?.(n)}catch(s){console.error("[XRStore] Backend update error:",s)}})},setImmersiveStore:n=>{e({immersiveStore:n})}}))),P=()=>M.getState(),ee=M.subscribe,E=e=>{const t=M(),n={...t,isImmersive:t.sessionTypes.has(p.IMMERSIVE),immersive:t.immersiveStore||null};return e?e(n):n},te=({children:e})=>{const{updateBackends:t}=E();return v.useFrame((n,o)=>{t(o)}),e},ne=({patternUrl:e,barcodeValue:t,params:n,onMarkerFound:o,onMarkerLost:A,children:s})=>{const i=f.useRef(null),r=E(d=>d.backends),u=f.useRef(!1),a=f.useRef(!1),l=f.useRef(null);return f.useEffect(()=>{let d=!1;return(async()=>{try{const m=r.find(w=>w.getInternal?.()?.arContext);if(!m||d)return;const k=m.getInternal?.()?.arContext,y=i.current;if(!k||!y)return;if(y.visible=!1,a.current=!1,!k.arController){requestAnimationFrame(()=>{if(!i.current||d)return;const b=m.getInternal?.()?.arContext;if(!b?.arController)return;const h=new O.ArMarkerControls(b,i.current,{type:e?"pattern":t?"barcode":"unknown",patternUrl:e,barcodeValue:t,...n});l.current=h,a.current=!0});return}const I=new O.ArMarkerControls(k,y,{type:e?"pattern":t?"barcode":"unknown",patternUrl:e,barcodeValue:t,...n});l.current=I,a.current=!0}catch(m){console.error("Failed to initialize fiducial backend:",m)}})(),()=>{d=!0;const m=l.current;typeof m?.dispose=="function"&&m.dispose(),a.current=!1}},[r,e,t,n]),v.useFrame(()=>{const d=i.current;if(!d||!a.current){d&&(d.visible=!1);return}const c=d.visible;c&&!u.current?(u.current=!0,o?.()):!c&&u.current&&(u.current=!1,A?.())}),L.jsx("group",{ref:i,visible:!1,children:s})},U=({options:e={},children:t})=>{const{scene:n,camera:o,gl:A}=v.useThree(),{registerBackend:s,unregisterBackend:i}=E(),r=f.useRef(null);return f.useEffect(()=>{if(r.current)return;let u=!1;return(async()=>{try{const l=q(e);if(u)return;await s(l,{scene:n,camera:o,renderer:A},p.FIDUCIAL),r.current=l}catch(l){console.error("[FiducialSession] Failed to initialize:",l)}})(),()=>{u=!0,r.current&&(i(r.current,p.FIDUCIAL),r.current=null)}},[n,o,A,s,i,e]),t};U.sessionType="FiducialSession";const q=e=>{let t,n,o;return{async init({camera:s,renderer:i}){t=new O.ArToolkitSource({sourceType:e.sourceType??"webcam"}),await new Promise((a,l)=>{const d=setTimeout(()=>{l(new Error("AR source initialization timeout"))},1e4);t.init(()=>{clearTimeout(d);const c=t.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"),a()})});const r={cameraParametersUrl:e.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:B&&B.tagName.toUpperCase()==="SCRIPT"&&B.src||new URL("index.cjs",document.baseURI).href).toString(),detectionMode:e.detectionMode??"mono",patternRatio:e.patternRatio??.5,matrixCodeType:e.matrixCodeType??"3x3"};n=new O.ArToolkitContext(r);const u=()=>{t.onResizeElement();const a=window.innerWidth,l=window.innerHeight;i.setSize(a,l,!1),t.copyElementSizeTo(i.domElement),n?.arController&&t.copyElementSizeTo(n.arController.canvas)};await new Promise((a,l)=>{const d=setTimeout(()=>{l(new Error("AR context initialization timeout"))},1e4);n.init(()=>{clearTimeout(d);try{s.projectionMatrix.copy(n.getProjectionMatrix()),u(),a()}catch(c){l(c)}})}),this._arSource=t,this._arContext=n,this._camera=s,window.addEventListener("resize",u),o=u},update(){const s=this._arSource,i=this._arContext,r=this._camera;if(!(!s||!i)&&s.ready!==!1&&s.domElement)try{i.update(s.domElement),r&&i.getProjectionMatrix&&r.projectionMatrix.copy(i.getProjectionMatrix())}catch(u){console.warn("AR.js update error:",u)}},dispose(){o&&(window.removeEventListener("resize",o),o=void 0);const s=this._arSource,i=this._arContext;if(i&&typeof i.dispose=="function"&&i.dispose(),s?.domElement){const r=s.domElement.parentNode;r&&r.removeChild(s.domElement)}this._arSource=void 0,this._arContext=void 0},getInternal(){return{arSource:this._arSource,arContext:this._arContext}}}},R=new Map;let z=!1,x=null,C=null;const re=({latitude:e,longitude:t,altitude:n=0,isBillboard:o=!0,onAttach:A,onGpsUpdate:s,children:i})=>{const r=E(g=>g.backends),{camera:u}=v.useThree(),[a]=f.useState(()=>new N.Group),[l]=f.useState(()=>Math.random().toString(36).slice(2,11)),d=f.useRef(!1),c=f.useCallback(()=>{A?.()},[A]),m=f.useCallback((g,k)=>{s?.(g,k)},[s]);return f.useEffect(()=>{let g=!1;return(async()=>{try{const y=r.find(S=>S.getInternal?.()?.locar);if(!y||g)return;const w=y.getInternal?.()?.locar;if(!w)return;const b=S=>{try{w.add(S.anchor,S.longitude,S.latitude,S.altitude),S.isAttached=!0,S.onAttach?.()}catch(T){console.error("❌ Failed to attach anchor:",T)}},h={anchor:a,isAttached:!1,latitude:e,longitude:t,altitude:n||0,onAttach:c,onGpsUpdate:m};R.set(l,h),z||(C=({position:S,distMoved:T})=>{x=S,R.forEach(_=>{_.isAttached||b(_),_.onGpsUpdate?.(S,T)})},x!==null&&!h.isAttached&&b(h),w.on?.("gpsupdate",C),z=!0),x!==null&&(h.isAttached||b(h),h.onGpsUpdate?.(x,0)),d.current=!1}catch(y){console.error("Failed to initialize geolocation backend:",y)}})(),()=>{if(g=!0,R.get(l)?.isAttached)try{const b=r.find(h=>h.getInternal?.()?.locar)?.getInternal?.()?.locar;typeof b?.remove=="function"?b.remove(a):a.removeFromParent()}catch(I){console.error(`⚠️ Error removing anchor ${l}:`,I)}R.delete(l),R.size===0&&C&&(r.find(h=>h.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate",C),C=null,z=!1)}},[r,a,l,e,t,n,c,m]),v.useFrame(()=>{!o||!u||!R.get(l)?.isAttached||a.lookAt(u.position)}),v.createPortal(L.jsx("group",{children:i}),a)},X=({options:e={},children:t})=>{const{scene:n,camera:o,gl:A}=v.useThree(),{registerBackend:s,unregisterBackend:i}=E(),r=f.useRef(null);return f.useEffect(()=>{if(r.current)return;let u=!1;return(async()=>{try{const l=D(e);if(u)return;await s(l,{scene:n,camera:o,renderer:A},p.GEOLOCATION),r.current=l}catch(l){console.error("[GeolocationSession] Failed to initialize:",l)}})(),()=>{u=!0,r.current&&(i(r.current,p.GEOLOCATION),r.current=null)}},[n,o,A,s,i,e]),t};X.sessionType="GeolocationSession";const D=e=>{let t,n,o,A,s=null,i=null;return{async init(r){const{camera:u,renderer:a,scene:l}=r;if(!l)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");s=u,i=a,t=new F.LocationBased(l,u),n=new F.Webcam(e.webcamConstraints??{video:{facingMode:"environment"}},null),t.on("gpsupdate",c=>{e.onGpsUpdate?.(c.position,c.distMoved)}),n.on("webcamstarted",c=>{l.background=c.texture}),n.on("webcamerror",c=>{console.error("[geolocationBackend] webcam error:",c)}),o=new F.DeviceOrientationControls(u),o.on("deviceorientationgranted",c=>{c.target?.connect?.()}),o.on("deviceorientationerror",c=>{console.error("[geolocationBackend] Device orientation error:",c)}),o.init?.(),t.on("gpserror",c=>{console.error("[geolocationBackend] gps error:",c)}),t.startGps(),typeof e.fakeLat=="number"&&typeof e.fakeLon=="number"&&t.fakeGps(e.fakeLon,e.fakeLat);const d=()=>{if(!i||!s)return;const c=window.innerWidth,m=window.innerHeight;i.setSize(c,m,!1),s.aspect=c/m,s.updateProjectionMatrix?.()};d(),window.addEventListener("resize",d),A=d,this._locar=t,this._webcam=n,this._deviceOrientation=o,this._scene=l,this._camera=u},update(){this._deviceOrientation?.update?.()},dispose(){const r=this._locar,u=this._webcam,a=this._deviceOrientation;e?.onGpsUpdate&&r?.off("gpsupdate",e.onGpsUpdate),r?.stopGps?.(),u?.stop?.(),a?.dispose?.(),A&&(window.removeEventListener("resize",A),A=void 0),this._locar=null,this._webcam=null,this._deviceOrientation=null,this._scene=null,this._camera=null},getInternal(){return{locar:this._locar,webcam:this._webcam,deviceOrientation:this._deviceOrientation,scene:this._scene,camera:this._camera}}}},oe=({children:e})=>{const t=f.useMemo(()=>G.createXRStore(),[]);return f.useEffect(()=>{const n=P();return n.sessionTypes.add(p.IMMERSIVE),n.setImmersiveStore(t),()=>{n.sessionTypes.delete(p.IMMERSIVE),n.setImmersiveStore(null)}},[t]),L.jsx(G.XR,{store:t,children:e})};exports.FiducialAnchor=ne;exports.FiducialSession=U;exports.GeolocationAnchor=re;exports.GeolocationSession=X;exports.ImmersiveSession=oe;exports.XR=te;exports.createFiducialBackend=q;exports.createGeolocationBackend=D;exports.getXRStore=P;exports.subscribeToXRStore=ee;exports.useXRStore=E;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react"),k=require("@react-three/fiber"),F=require("react/jsx-runtime"),T=require("@ar-js-org/ar.js/three.js/build/ar-threex"),Q=require("three"),V=require("locar"),G=require("@react-three/xr");var j=typeof document<"u"?document.currentScript:null;function Y(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const M=Y(V),B=e=>{let t;const n=new Set,r=(c,f)=>{const i=typeof c=="function"?c(t):c;if(!Object.is(i,t)){const l=t;t=f??(typeof i!="object"||i===null)?i:Object.assign({},t,i),n.forEach(m=>m(t,l))}},u=()=>t,s={setState:r,getState:u,getInitialState:()=>d,subscribe:c=>(n.add(c),()=>n.delete(c))},d=t=e(r,u,s);return s},$=(e=>e?B(e):B),J=e=>e;function Z(e,t=J){const n=A.useSyncExternalStore(e.subscribe,A.useCallback(()=>t(e.getState()),[e,t]),A.useCallback(()=>t(e.getInitialState()),[e,t]));return A.useDebugValue(n),n}const ee=e=>{const t=$(e),n=r=>Z(t,r);return Object.assign(n,t),n},te=(e=>ee),ne=e=>(t,n,r)=>{const u=r.subscribe;return r.subscribe=((a,s,d)=>{let c=a;if(s){const f=d?.equalityFn||Object.is;let i=a(r.getState());c=l=>{const m=a(l);if(!f(i,m)){const g=i;s(i=m,g)}},d?.fireImmediately&&s(i,i)}return u(c)}),e(t,n,r)},re=ne,P=e=>Symbol.iterator in e,U=e=>"entries"in e,q=(e,t)=>{const 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(const[u,o]of n)if(!r.has(u)||!Object.is(o,r.get(u)))return!1;return!0},oe=(e,t)=>{const n=e[Symbol.iterator](),r=t[Symbol.iterator]();let u=n.next(),o=r.next();for(;!u.done&&!o.done;){if(!Object.is(u.value,o.value))return!1;u=n.next(),o=r.next()}return!!u.done&&!!o.done};function se(e,t){return Object.is(e,t)?!0:typeof e!="object"||e===null||typeof t!="object"||t===null||Object.getPrototypeOf(e)!==Object.getPrototypeOf(t)?!1:P(e)&&P(t)?U(e)&&U(t)?q(e,t):oe(e,t):q({entries:()=>Object.entries(e)},{entries:()=>Object.entries(t)})}function ie(e){const t=A.useRef(void 0);return n=>{const r=e(n);return se(t.current,r)?t.current:t.current=r}}const h={FIDUCIAL:"FiducialSession",GEOLOCATION:"GeolocationSession",IMMERSIVE:"ImmersiveSession"},L=te()(re((e,t)=>({video:null,backends:[],sessionTypes:new Set,immersiveStore:null,registerBackend:async(n,r,u)=>{try{if(u){const o=t(),a=new Set([...o.sessionTypes,u]),s=a.has(h.FIDUCIAL),d=a.has(h.GEOLOCATION);if(s&&d){const c=`❌ [RDK] INCOMPATIBLE SESSIONS: ${h.FIDUCIAL} and ${h.GEOLOCATION} 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(c),new Error(c)}e(()=>({sessionTypes:a}))}await n.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),e(o=>({backends:[...o.backends,n]}))}catch(o){throw console.error("[XRStore] Failed to register backend:",o),o}},unregisterBackend:(n,r)=>{e(u=>{const o=new Set(u.sessionTypes);r&&o.delete(r);const a=u.backends.filter(s=>s!==n);try{n.dispose?.()}catch(s){console.error("[XRStore] Error disposing backend:",s)}return{backends:a,sessionTypes:o}})},setVideo:n=>{e({video:n})},updateBackends:n=>{const{backends:r}=t();r.forEach(u=>{try{u.update?.(n)}catch(o){console.error("[XRStore] Backend update error:",o)}})},setImmersiveStore:n=>{e({immersiveStore:n})}}))),D=()=>L.getState(),ce=L.subscribe,v=e=>L(ie(n=>{const r={...n,isImmersive:n.sessionTypes.has(h.IMMERSIVE),immersive:n.immersiveStore||null};return e?e(r):r})),ae=({children:e})=>{const{updateBackends:t}=v();return k.useFrame((n,r)=>{t(r)}),e},le=({patternUrl:e,barcodeValue:t,params:n,onMarkerFound:r,onMarkerLost:u,children:o})=>{const a=A.useRef(null),s=v(i=>i.backends),d=A.useRef(!1),c=A.useRef(!1),f=A.useRef(null);return A.useEffect(()=>{let i=!1;return(async()=>{try{const m=s.find(w=>w.getInternal?.()?.arContext);if(!m||i)return;const I=m.getInternal?.()?.arContext,y=a.current;if(!I||!y)return;if(y.visible=!1,c.current=!1,!I.arController){requestAnimationFrame(()=>{if(!a.current||i)return;const p=m.getInternal?.()?.arContext;if(!p?.arController)return;const b=new T.ArMarkerControls(p,a.current,{type:e?"pattern":t?"barcode":"unknown",patternUrl:e,barcodeValue:t,...n});f.current=b,c.current=!0});return}const R=new T.ArMarkerControls(I,y,{type:e?"pattern":t?"barcode":"unknown",patternUrl:e,barcodeValue:t,...n});f.current=R,c.current=!0}catch(m){console.error("Failed to initialize fiducial backend:",m)}})(),()=>{i=!0;const m=f.current;typeof m?.dispose=="function"&&m.dispose(),c.current=!1}},[s,e,t,n]),k.useFrame(()=>{const i=a.current;if(!i||!c.current){i&&(i.visible=!1);return}const l=i.visible;l&&!d.current?(d.current=!0,r?.()):!l&&d.current&&(d.current=!1,u?.())}),F.jsx("group",{ref:a,visible:!1,children:o})},X=({options:e={},children:t})=>{const{scene:n,camera:r,gl:u}=k.useThree(),{registerBackend:o,unregisterBackend:a}=v(),s=A.useRef(null),d=A.useRef(e);return d.current=e,A.useEffect(()=>{if(s.current)return;let c=!1;return(async()=>{try{const i=N(d.current);if(c)return;await o(i,{scene:n,camera:r,renderer:u},h.FIDUCIAL),s.current=i}catch(i){console.error("[FiducialSession] Failed to initialize:",i)}})(),()=>{c=!0,s.current&&(a(s.current,h.FIDUCIAL),s.current=null)}},[n,r,u,o,a]),t};X.sessionType="FiducialSession";const N=e=>{let t,n,r;return{async init({camera:o,renderer:a}){t=new T.ArToolkitSource({sourceType:e.sourceType??"webcam"}),await new Promise((c,f)=>{const i=setTimeout(()=>{f(new Error("AR source initialization timeout"))},1e4);t.init(()=>{clearTimeout(i);const l=t.domElement;l&&(l.style.position="fixed",l.style.top="0",l.style.left="0",l.style.width="100vw",l.style.height="100vh",l.style.objectFit="cover",l.style.zIndex="-1",l.style.pointerEvents="none"),c()})});const s={cameraParametersUrl:e.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:j&&j.tagName.toUpperCase()==="SCRIPT"&&j.src||new URL("index.cjs",document.baseURI).href).toString(),detectionMode:e.detectionMode??"mono",patternRatio:e.patternRatio??.5,matrixCodeType:e.matrixCodeType??"3x3"};n=new T.ArToolkitContext(s);const d=()=>{t.onResizeElement();const c=window.innerWidth,f=window.innerHeight;a.setSize(c,f,!1),t.copyElementSizeTo(a.domElement),n?.arController&&t.copyElementSizeTo(n.arController.canvas)};await new Promise((c,f)=>{const i=setTimeout(()=>{f(new Error("AR context initialization timeout"))},1e4);n.init(()=>{clearTimeout(i);try{o.projectionMatrix.copy(n.getProjectionMatrix()),d(),c()}catch(l){f(l)}})}),this._arSource=t,this._arContext=n,this._camera=o,window.addEventListener("resize",d),r=d},update(){const o=this._arSource,a=this._arContext,s=this._camera;if(!(!o||!a)&&o.ready!==!1&&o.domElement)try{a.update(o.domElement),s&&a.getProjectionMatrix&&s.projectionMatrix.copy(a.getProjectionMatrix())}catch(d){console.warn("AR.js update error:",d)}},dispose(){r&&(window.removeEventListener("resize",r),r=void 0);const o=this._arSource,a=this._arContext;if(a&&typeof a.dispose=="function"&&a.dispose(),o?.domElement){const s=o.domElement.parentNode;s&&s.removeChild(o.domElement)}this._arSource=void 0,this._arContext=void 0},getInternal(){return{arSource:this._arSource,arContext:this._arContext}}}},E=new Map;let z=!1,C=null,x=null;const ue=({latitude:e,longitude:t,altitude:n=0,isBillboard:r=!0,onAttach:u,onGpsUpdate:o,children:a})=>{const s=v(g=>g.backends),{camera:d}=k.useThree(),[c]=A.useState(()=>new Q.Group),[f]=A.useState(()=>Math.random().toString(36).slice(2,11)),i=A.useRef(!1),l=A.useCallback(()=>{u?.()},[u]),m=A.useCallback((g,I)=>{o?.(g,I)},[o]);return A.useEffect(()=>{let g=!1;return(async()=>{try{const y=s.find(S=>S.getInternal?.()?.locar);if(!y||g)return;const w=y.getInternal?.()?.locar;if(!w)return;const p=S=>{try{w.add(S.anchor,S.longitude,S.latitude,S.altitude),S.isAttached=!0,S.onAttach?.()}catch(O){console.error("❌ Failed to attach anchor:",O)}},b={anchor:c,isAttached:!1,latitude:e,longitude:t,altitude:n||0,onAttach:l,onGpsUpdate:m};if(E.set(f,b),!z){x=({position:O,distMoved:K})=>{C=O,E.forEach(_=>{_.isAttached||p(_),_.onGpsUpdate?.(O,K)})};const S=w.getLastKnownLocation();S!==null&&(C={coords:S,timestamp:Date.now(),toJSON:()=>S}),C!==null&&!b.isAttached&&p(b),w.on?.("gpsupdate",x),z=!0}C!==null&&(b.isAttached||p(b),b.onGpsUpdate?.(C,0)),i.current=!1}catch(y){console.error("Failed to initialize geolocation backend:",y)}})(),()=>{if(g=!0,E.get(f)?.isAttached)try{const p=s.find(b=>b.getInternal?.()?.locar)?.getInternal?.()?.locar;typeof p?.remove=="function"?p.remove(c):c.removeFromParent()}catch(R){console.error(`⚠️ Error removing anchor ${f}:`,R)}E.delete(f),E.size===0&&x&&(s.find(b=>b.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate",x),x=null,z=!1)}},[s,c,f,e,t,n,l,m]),k.useFrame(()=>{!r||!d||!E.get(f)?.isAttached||c.lookAt(d.position)}),k.createPortal(F.jsx("group",{children:a}),c)},H=({options:e={},children:t})=>{const{scene:n,camera:r,gl:u}=k.useThree(),{registerBackend:o,unregisterBackend:a}=v(),s=A.useRef(null),d=A.useRef(e);return d.current=e,A.useEffect(()=>{if(s.current)return;let c=!1;return(async()=>{try{const i=W(d.current);if(c)return;await o(i,{scene:n,camera:r,renderer:u},h.GEOLOCATION),s.current=i}catch(i){console.error("[GeolocationSession] Failed to initialize:",i)}})(),()=>{c=!0,s.current&&(a(s.current,h.GEOLOCATION),s.current=null)}},[n,r,u,o,a]),t};H.sessionType="GeolocationSession";const W=e=>{let t,n,r,u,o=null,a=null;return{async init(s){const{camera:d,renderer:c,scene:f}=s;if(!f)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");o=d,a=c,t=new M.LocationBased(f,d),n=new M.Webcam(e.webcamConstraints??{video:{facingMode:"environment"}},null),t.on("gpsupdate",l=>{e.onGpsUpdate?.(l.position,l.distMoved)}),n.on("webcamstarted",l=>{f.background=l.texture}),n.on("webcamerror",l=>{console.error("[geolocationBackend] webcam error:",l)}),r=new M.DeviceOrientationControls(d),r.on("deviceorientationgranted",l=>{l.target?.connect?.()}),r.on("deviceorientationerror",l=>{console.error("[geolocationBackend] Device orientation error:",l)}),r.init?.(),t.on("gpserror",l=>{console.error("[geolocationBackend] gps error:",l)}),t.startGps(),typeof e.fakeLat=="number"&&typeof e.fakeLon=="number"&&t.fakeGps(e.fakeLon,e.fakeLat);const i=()=>{if(!a||!o)return;const l=window.innerWidth,m=window.innerHeight;a.setSize(l,m,!1),o.aspect=l/m,o.updateProjectionMatrix?.()};i(),window.addEventListener("resize",i),u=i,this._locar=t,this._webcam=n,this._deviceOrientation=r,this._scene=f,this._camera=d},update(){this._deviceOrientation?.update?.()},dispose(){const s=this._locar,d=this._webcam,c=this._deviceOrientation;e?.onGpsUpdate&&s?.off("gpsupdate",e.onGpsUpdate),s?.stopGps?.(),d?.stop?.(),c?.dispose?.(),u&&(window.removeEventListener("resize",u),u=void 0),this._locar=null,this._webcam=null,this._deviceOrientation=null,this._scene=null,this._camera=null},getInternal(){return{locar:this._locar,webcam:this._webcam,deviceOrientation:this._deviceOrientation,scene:this._scene,camera:this._camera}}}},de=({children:e})=>{const t=A.useMemo(()=>G.createXRStore(),[]);return A.useEffect(()=>{const n=D();return n.sessionTypes.add(h.IMMERSIVE),n.setImmersiveStore(t),()=>{n.sessionTypes.delete(h.IMMERSIVE),n.setImmersiveStore(null)}},[t]),F.jsx(G.XR,{store:t,children:e})};exports.FiducialAnchor=le;exports.FiducialSession=X;exports.GeolocationAnchor=ue;exports.GeolocationSession=H;exports.ImmersiveSession=de;exports.XR=ae;exports.createFiducialBackend=N;exports.createGeolocationBackend=W;exports.getXRStore=D;exports.subscribeToXRStore=ce;exports.useXRStore=v;
|
package/build/index.js
CHANGED
|
@@ -1,97 +1,131 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFrame as
|
|
3
|
-
import { jsx as
|
|
4
|
-
import { ArMarkerControls as D, ArToolkitSource as
|
|
5
|
-
import { Group as
|
|
6
|
-
import * as
|
|
7
|
-
import { createXRStore as
|
|
8
|
-
const
|
|
1
|
+
import O, { useRef as y, useEffect as x, useState as B, useCallback as P, useMemo as q } from "react";
|
|
2
|
+
import { useFrame as L, useThree as j, createPortal as K } from "@react-three/fiber";
|
|
3
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
4
|
+
import { ArMarkerControls as D, ArToolkitSource as Q, ArToolkitContext as V } from "@ar-js-org/ar.js/three.js/build/ar-threex";
|
|
5
|
+
import { Group as Y } from "three";
|
|
6
|
+
import * as z from "locar";
|
|
7
|
+
import { createXRStore as $, XR as J } from "@react-three/xr";
|
|
8
|
+
const N = (e) => {
|
|
9
9
|
let t;
|
|
10
|
-
const n = /* @__PURE__ */ new Set(),
|
|
11
|
-
const
|
|
12
|
-
if (!Object.is(
|
|
13
|
-
const
|
|
14
|
-
t =
|
|
10
|
+
const n = /* @__PURE__ */ new Set(), r = (c, A) => {
|
|
11
|
+
const s = typeof c == "function" ? c(t) : c;
|
|
12
|
+
if (!Object.is(s, t)) {
|
|
13
|
+
const l = t;
|
|
14
|
+
t = A ?? (typeof s != "object" || s === null) ? s : Object.assign({}, t, s), n.forEach((f) => f(t, l));
|
|
15
15
|
}
|
|
16
|
-
},
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
function
|
|
20
|
-
const n =
|
|
16
|
+
}, u = () => t, i = { setState: r, getState: u, getInitialState: () => d, subscribe: (c) => (n.add(c), () => n.delete(c)) }, d = t = e(r, u, i);
|
|
17
|
+
return i;
|
|
18
|
+
}, Z = ((e) => e ? N(e) : N), ee = (e) => e;
|
|
19
|
+
function te(e, t = ee) {
|
|
20
|
+
const n = O.useSyncExternalStore(
|
|
21
21
|
e.subscribe,
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
O.useCallback(() => t(e.getState()), [e, t]),
|
|
23
|
+
O.useCallback(() => t(e.getInitialState()), [e, t])
|
|
24
24
|
);
|
|
25
|
-
return
|
|
25
|
+
return O.useDebugValue(n), n;
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
const t =
|
|
27
|
+
const ne = (e) => {
|
|
28
|
+
const t = Z(e), n = (r) => te(t, r);
|
|
29
29
|
return Object.assign(n, t), n;
|
|
30
|
-
},
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
let
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
-
const f =
|
|
39
|
-
if (!
|
|
40
|
-
const
|
|
41
|
-
|
|
30
|
+
}, re = ((e) => ne), oe = (e) => (t, n, r) => {
|
|
31
|
+
const u = r.subscribe;
|
|
32
|
+
return r.subscribe = ((a, i, d) => {
|
|
33
|
+
let c = a;
|
|
34
|
+
if (i) {
|
|
35
|
+
const A = d?.equalityFn || Object.is;
|
|
36
|
+
let s = a(r.getState());
|
|
37
|
+
c = (l) => {
|
|
38
|
+
const f = a(l);
|
|
39
|
+
if (!A(s, f)) {
|
|
40
|
+
const b = s;
|
|
41
|
+
i(s = f, b);
|
|
42
42
|
}
|
|
43
|
-
},
|
|
43
|
+
}, d?.fireImmediately && i(s, s);
|
|
44
44
|
}
|
|
45
|
-
return
|
|
46
|
-
}), e(t, n,
|
|
47
|
-
},
|
|
45
|
+
return u(c);
|
|
46
|
+
}), e(t, n, r);
|
|
47
|
+
}, ie = oe, U = (e) => Symbol.iterator in e, X = (e) => (
|
|
48
|
+
// HACK: avoid checking entries type
|
|
49
|
+
"entries" in e
|
|
50
|
+
), H = (e, t) => {
|
|
51
|
+
const n = e instanceof Map ? e : new Map(e.entries()), r = t instanceof Map ? t : new Map(t.entries());
|
|
52
|
+
if (n.size !== r.size)
|
|
53
|
+
return !1;
|
|
54
|
+
for (const [u, o] of n)
|
|
55
|
+
if (!r.has(u) || !Object.is(o, r.get(u)))
|
|
56
|
+
return !1;
|
|
57
|
+
return !0;
|
|
58
|
+
}, se = (e, t) => {
|
|
59
|
+
const n = e[Symbol.iterator](), r = t[Symbol.iterator]();
|
|
60
|
+
let u = n.next(), o = r.next();
|
|
61
|
+
for (; !u.done && !o.done; ) {
|
|
62
|
+
if (!Object.is(u.value, o.value))
|
|
63
|
+
return !1;
|
|
64
|
+
u = n.next(), o = r.next();
|
|
65
|
+
}
|
|
66
|
+
return !!u.done && !!o.done;
|
|
67
|
+
};
|
|
68
|
+
function ce(e, t) {
|
|
69
|
+
return Object.is(e, t) ? !0 : typeof e != "object" || e === null || typeof t != "object" || t === null || Object.getPrototypeOf(e) !== Object.getPrototypeOf(t) ? !1 : U(e) && U(t) ? X(e) && X(t) ? H(e, t) : se(e, t) : H(
|
|
70
|
+
{ entries: () => Object.entries(e) },
|
|
71
|
+
{ entries: () => Object.entries(t) }
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function ae(e) {
|
|
75
|
+
const t = O.useRef(void 0);
|
|
76
|
+
return (n) => {
|
|
77
|
+
const r = e(n);
|
|
78
|
+
return ce(t.current, r) ? t.current : t.current = r;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const h = {
|
|
48
82
|
FIDUCIAL: "FiducialSession",
|
|
49
83
|
GEOLOCATION: "GeolocationSession",
|
|
50
84
|
IMMERSIVE: "ImmersiveSession"
|
|
51
|
-
}, G =
|
|
52
|
-
|
|
85
|
+
}, G = re()(
|
|
86
|
+
ie((e, t) => ({
|
|
53
87
|
// initial state
|
|
54
88
|
video: null,
|
|
55
89
|
backends: [],
|
|
56
90
|
sessionTypes: /* @__PURE__ */ new Set(),
|
|
57
91
|
immersiveStore: null,
|
|
58
92
|
// actions
|
|
59
|
-
registerBackend: async (n,
|
|
93
|
+
registerBackend: async (n, r, u) => {
|
|
60
94
|
try {
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
throw console.error(
|
|
95
|
+
if (u) {
|
|
96
|
+
const o = t(), a = /* @__PURE__ */ new Set([...o.sessionTypes, u]), i = a.has(h.FIDUCIAL), d = a.has(h.GEOLOCATION);
|
|
97
|
+
if (i && d) {
|
|
98
|
+
const c = `❌ [RDK] INCOMPATIBLE SESSIONS: ${h.FIDUCIAL} and ${h.GEOLOCATION} cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.`;
|
|
99
|
+
throw console.error(c), new Error(c);
|
|
66
100
|
}
|
|
67
101
|
e(() => ({
|
|
68
|
-
sessionTypes:
|
|
102
|
+
sessionTypes: a
|
|
69
103
|
}));
|
|
70
104
|
}
|
|
71
105
|
await n.init({
|
|
72
|
-
scene:
|
|
73
|
-
camera:
|
|
74
|
-
renderer:
|
|
75
|
-
}), e((
|
|
76
|
-
backends: [...
|
|
106
|
+
scene: r.scene,
|
|
107
|
+
camera: r.camera,
|
|
108
|
+
renderer: r.renderer
|
|
109
|
+
}), e((o) => ({
|
|
110
|
+
backends: [...o.backends, n]
|
|
77
111
|
}));
|
|
78
|
-
} catch (
|
|
79
|
-
throw console.error("[XRStore] Failed to register backend:",
|
|
112
|
+
} catch (o) {
|
|
113
|
+
throw console.error("[XRStore] Failed to register backend:", o), o;
|
|
80
114
|
}
|
|
81
115
|
},
|
|
82
|
-
unregisterBackend: (n,
|
|
83
|
-
e((
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const
|
|
116
|
+
unregisterBackend: (n, r) => {
|
|
117
|
+
e((u) => {
|
|
118
|
+
const o = new Set(u.sessionTypes);
|
|
119
|
+
r && o.delete(r);
|
|
120
|
+
const a = u.backends.filter((i) => i !== n);
|
|
87
121
|
try {
|
|
88
122
|
n.dispose?.();
|
|
89
|
-
} catch (
|
|
90
|
-
console.error("[XRStore] Error disposing backend:",
|
|
123
|
+
} catch (i) {
|
|
124
|
+
console.error("[XRStore] Error disposing backend:", i);
|
|
91
125
|
}
|
|
92
126
|
return {
|
|
93
|
-
backends:
|
|
94
|
-
sessionTypes:
|
|
127
|
+
backends: a,
|
|
128
|
+
sessionTypes: o
|
|
95
129
|
};
|
|
96
130
|
});
|
|
97
131
|
},
|
|
@@ -99,12 +133,12 @@ const J = (e) => {
|
|
|
99
133
|
e({ video: n });
|
|
100
134
|
},
|
|
101
135
|
updateBackends: (n) => {
|
|
102
|
-
const { backends:
|
|
103
|
-
|
|
136
|
+
const { backends: r } = t();
|
|
137
|
+
r.forEach((u) => {
|
|
104
138
|
try {
|
|
105
|
-
|
|
106
|
-
} catch (
|
|
107
|
-
console.error("[XRStore] Backend update error:",
|
|
139
|
+
u.update?.(n);
|
|
140
|
+
} catch (o) {
|
|
141
|
+
console.error("[XRStore] Backend update error:", o);
|
|
108
142
|
}
|
|
109
143
|
});
|
|
110
144
|
},
|
|
@@ -112,162 +146,164 @@ const J = (e) => {
|
|
|
112
146
|
e({ immersiveStore: n });
|
|
113
147
|
}
|
|
114
148
|
}))
|
|
115
|
-
),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
149
|
+
), le = () => G.getState(), we = G.subscribe, T = (e) => G(
|
|
150
|
+
ae((n) => {
|
|
151
|
+
const r = {
|
|
152
|
+
...n,
|
|
153
|
+
isImmersive: n.sessionTypes.has(h.IMMERSIVE),
|
|
154
|
+
immersive: n.immersiveStore || null
|
|
155
|
+
};
|
|
156
|
+
return e ? e(r) : r;
|
|
157
|
+
})
|
|
158
|
+
), ye = ({ children: e }) => {
|
|
159
|
+
const { updateBackends: t } = T();
|
|
160
|
+
return L((n, r) => {
|
|
161
|
+
t(r);
|
|
126
162
|
}), e;
|
|
127
|
-
},
|
|
163
|
+
}, Ie = ({
|
|
128
164
|
patternUrl: e,
|
|
129
165
|
barcodeValue: t,
|
|
130
166
|
params: n,
|
|
131
|
-
onMarkerFound:
|
|
132
|
-
onMarkerLost:
|
|
133
|
-
children:
|
|
167
|
+
onMarkerFound: r,
|
|
168
|
+
onMarkerLost: u,
|
|
169
|
+
children: o
|
|
134
170
|
}) => {
|
|
135
|
-
const
|
|
136
|
-
return
|
|
137
|
-
let
|
|
171
|
+
const a = y(null), i = T((s) => s.backends), d = y(!1), c = y(!1), A = y(null);
|
|
172
|
+
return x(() => {
|
|
173
|
+
let s = !1;
|
|
138
174
|
return (async () => {
|
|
139
175
|
try {
|
|
140
|
-
const f =
|
|
141
|
-
if (!f ||
|
|
142
|
-
const
|
|
143
|
-
if (!
|
|
144
|
-
if (
|
|
176
|
+
const f = i.find((w) => w.getInternal?.()?.arContext);
|
|
177
|
+
if (!f || s) return;
|
|
178
|
+
const I = f.getInternal?.()?.arContext, g = a.current;
|
|
179
|
+
if (!I || !g) return;
|
|
180
|
+
if (g.visible = !1, c.current = !1, !I.arController) {
|
|
145
181
|
requestAnimationFrame(() => {
|
|
146
|
-
if (!
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
149
|
-
const
|
|
182
|
+
if (!a.current || s) return;
|
|
183
|
+
const S = f.getInternal?.()?.arContext;
|
|
184
|
+
if (!S?.arController) return;
|
|
185
|
+
const p = new D(S, a.current, {
|
|
150
186
|
type: e ? "pattern" : t ? "barcode" : "unknown",
|
|
151
187
|
patternUrl: e,
|
|
152
188
|
barcodeValue: t,
|
|
153
189
|
...n
|
|
154
190
|
});
|
|
155
|
-
|
|
191
|
+
A.current = p, c.current = !0;
|
|
156
192
|
});
|
|
157
193
|
return;
|
|
158
194
|
}
|
|
159
|
-
const
|
|
195
|
+
const k = new D(I, g, {
|
|
160
196
|
type: e ? "pattern" : t ? "barcode" : "unknown",
|
|
161
197
|
patternUrl: e,
|
|
162
198
|
barcodeValue: t,
|
|
163
199
|
...n
|
|
164
200
|
});
|
|
165
|
-
|
|
201
|
+
A.current = k, c.current = !0;
|
|
166
202
|
} catch (f) {
|
|
167
203
|
console.error("Failed to initialize fiducial backend:", f);
|
|
168
204
|
}
|
|
169
205
|
})(), () => {
|
|
170
|
-
|
|
171
|
-
const f =
|
|
172
|
-
typeof f?.dispose == "function" && f.dispose(),
|
|
206
|
+
s = !0;
|
|
207
|
+
const f = A.current;
|
|
208
|
+
typeof f?.dispose == "function" && f.dispose(), c.current = !1;
|
|
173
209
|
};
|
|
174
|
-
}, [
|
|
175
|
-
const
|
|
176
|
-
if (!
|
|
177
|
-
|
|
210
|
+
}, [i, e, t, n]), L(() => {
|
|
211
|
+
const s = a.current;
|
|
212
|
+
if (!s || !c.current) {
|
|
213
|
+
s && (s.visible = !1);
|
|
178
214
|
return;
|
|
179
215
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
}), /* @__PURE__ */
|
|
216
|
+
const l = s.visible;
|
|
217
|
+
l && !d.current ? (d.current = !0, r?.()) : !l && d.current && (d.current = !1, u?.());
|
|
218
|
+
}), /* @__PURE__ */ F(
|
|
183
219
|
"group",
|
|
184
220
|
{
|
|
185
|
-
ref:
|
|
221
|
+
ref: a,
|
|
186
222
|
visible: !1,
|
|
187
|
-
children:
|
|
223
|
+
children: o
|
|
188
224
|
}
|
|
189
225
|
);
|
|
190
|
-
},
|
|
191
|
-
const { scene: n, camera:
|
|
192
|
-
return
|
|
193
|
-
if (
|
|
194
|
-
let
|
|
226
|
+
}, ue = ({ options: e = {}, children: t }) => {
|
|
227
|
+
const { scene: n, camera: r, gl: u } = j(), { registerBackend: o, unregisterBackend: a } = T(), i = y(null), d = y(e);
|
|
228
|
+
return d.current = e, x(() => {
|
|
229
|
+
if (i.current) return;
|
|
230
|
+
let c = !1;
|
|
195
231
|
return (async () => {
|
|
196
232
|
try {
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
199
|
-
await
|
|
200
|
-
|
|
201
|
-
{ scene: n, camera:
|
|
202
|
-
|
|
203
|
-
),
|
|
204
|
-
} catch (
|
|
205
|
-
console.error("[FiducialSession] Failed to initialize:",
|
|
233
|
+
const s = de(d.current);
|
|
234
|
+
if (c) return;
|
|
235
|
+
await o(
|
|
236
|
+
s,
|
|
237
|
+
{ scene: n, camera: r, renderer: u },
|
|
238
|
+
h.FIDUCIAL
|
|
239
|
+
), i.current = s;
|
|
240
|
+
} catch (s) {
|
|
241
|
+
console.error("[FiducialSession] Failed to initialize:", s);
|
|
206
242
|
}
|
|
207
243
|
})(), () => {
|
|
208
|
-
|
|
244
|
+
c = !0, i.current && (a(i.current, h.FIDUCIAL), i.current = null);
|
|
209
245
|
};
|
|
210
|
-
}, [n,
|
|
246
|
+
}, [n, r, u, o, a]), t;
|
|
211
247
|
};
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
let t, n,
|
|
248
|
+
ue.sessionType = "FiducialSession";
|
|
249
|
+
const de = (e) => {
|
|
250
|
+
let t, n, r;
|
|
215
251
|
return {
|
|
216
|
-
async init({ camera:
|
|
217
|
-
t = new
|
|
252
|
+
async init({ camera: o, renderer: a }) {
|
|
253
|
+
t = new Q({
|
|
218
254
|
sourceType: e.sourceType ?? "webcam"
|
|
219
|
-
}), await new Promise((
|
|
220
|
-
const
|
|
221
|
-
|
|
255
|
+
}), await new Promise((c, A) => {
|
|
256
|
+
const s = setTimeout(() => {
|
|
257
|
+
A(new Error("AR source initialization timeout"));
|
|
222
258
|
}, 1e4);
|
|
223
259
|
t.init(() => {
|
|
224
|
-
clearTimeout(
|
|
225
|
-
const
|
|
226
|
-
|
|
260
|
+
clearTimeout(s);
|
|
261
|
+
const l = t.domElement;
|
|
262
|
+
l && (l.style.position = "fixed", l.style.top = "0", l.style.left = "0", l.style.width = "100vw", l.style.height = "100vh", l.style.objectFit = "cover", l.style.zIndex = "-1", l.style.pointerEvents = "none"), c();
|
|
227
263
|
});
|
|
228
264
|
});
|
|
229
|
-
const
|
|
265
|
+
const i = {
|
|
230
266
|
cameraParametersUrl: e.cameraParametersUrl ?? // default to internal camera parameters
|
|
231
267
|
new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
|
|
232
268
|
detectionMode: e.detectionMode ?? "mono",
|
|
233
269
|
patternRatio: e.patternRatio ?? 0.5,
|
|
234
270
|
matrixCodeType: e.matrixCodeType ?? "3x3"
|
|
235
271
|
};
|
|
236
|
-
n = new
|
|
237
|
-
const
|
|
272
|
+
n = new V(i);
|
|
273
|
+
const d = () => {
|
|
238
274
|
t.onResizeElement();
|
|
239
|
-
const
|
|
240
|
-
|
|
275
|
+
const c = window.innerWidth, A = window.innerHeight;
|
|
276
|
+
a.setSize(c, A, !1), t.copyElementSizeTo(a.domElement), n?.arController && t.copyElementSizeTo(n.arController.canvas);
|
|
241
277
|
};
|
|
242
|
-
await new Promise((
|
|
243
|
-
const
|
|
244
|
-
|
|
278
|
+
await new Promise((c, A) => {
|
|
279
|
+
const s = setTimeout(() => {
|
|
280
|
+
A(new Error("AR context initialization timeout"));
|
|
245
281
|
}, 1e4);
|
|
246
282
|
n.init(() => {
|
|
247
|
-
clearTimeout(
|
|
283
|
+
clearTimeout(s);
|
|
248
284
|
try {
|
|
249
|
-
|
|
250
|
-
} catch (
|
|
251
|
-
l
|
|
285
|
+
o.projectionMatrix.copy(n.getProjectionMatrix()), d(), c();
|
|
286
|
+
} catch (l) {
|
|
287
|
+
A(l);
|
|
252
288
|
}
|
|
253
289
|
});
|
|
254
|
-
}), this._arSource = t, this._arContext = n, this._camera =
|
|
290
|
+
}), this._arSource = t, this._arContext = n, this._camera = o, window.addEventListener("resize", d), r = d;
|
|
255
291
|
},
|
|
256
292
|
update() {
|
|
257
|
-
const
|
|
258
|
-
if (!(!
|
|
293
|
+
const o = this._arSource, a = this._arContext, i = this._camera;
|
|
294
|
+
if (!(!o || !a) && o.ready !== !1 && o.domElement)
|
|
259
295
|
try {
|
|
260
|
-
|
|
261
|
-
} catch (
|
|
262
|
-
console.warn("AR.js update error:",
|
|
296
|
+
a.update(o.domElement), i && a.getProjectionMatrix && i.projectionMatrix.copy(a.getProjectionMatrix());
|
|
297
|
+
} catch (d) {
|
|
298
|
+
console.warn("AR.js update error:", d);
|
|
263
299
|
}
|
|
264
300
|
},
|
|
265
301
|
dispose() {
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
const
|
|
270
|
-
|
|
302
|
+
r && (window.removeEventListener("resize", r), r = void 0);
|
|
303
|
+
const o = this._arSource, a = this._arContext;
|
|
304
|
+
if (a && typeof a.dispose == "function" && a.dispose(), o?.domElement) {
|
|
305
|
+
const i = o.domElement.parentNode;
|
|
306
|
+
i && i.removeChild(o.domElement);
|
|
271
307
|
}
|
|
272
308
|
this._arSource = void 0, this._arContext = void 0;
|
|
273
309
|
},
|
|
@@ -278,34 +314,34 @@ const oe = (e) => {
|
|
|
278
314
|
};
|
|
279
315
|
}
|
|
280
316
|
};
|
|
281
|
-
},
|
|
282
|
-
let
|
|
283
|
-
const
|
|
317
|
+
}, E = /* @__PURE__ */ new Map();
|
|
318
|
+
let M = !1, R = null, C = null;
|
|
319
|
+
const ke = ({
|
|
284
320
|
latitude: e,
|
|
285
321
|
longitude: t,
|
|
286
322
|
altitude: n = 0,
|
|
287
|
-
isBillboard:
|
|
288
|
-
onAttach:
|
|
289
|
-
onGpsUpdate:
|
|
290
|
-
children:
|
|
323
|
+
isBillboard: r = !0,
|
|
324
|
+
onAttach: u,
|
|
325
|
+
onGpsUpdate: o,
|
|
326
|
+
children: a
|
|
291
327
|
}) => {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
}, [
|
|
295
|
-
(
|
|
296
|
-
|
|
328
|
+
const i = T((b) => b.backends), { camera: d } = j(), [c] = B(() => new Y()), [A] = B(() => Math.random().toString(36).slice(2, 11)), s = y(!1), l = P(() => {
|
|
329
|
+
u?.();
|
|
330
|
+
}, [u]), f = P(
|
|
331
|
+
(b, I) => {
|
|
332
|
+
o?.(b, I);
|
|
297
333
|
},
|
|
298
|
-
[
|
|
334
|
+
[o]
|
|
299
335
|
);
|
|
300
|
-
return
|
|
301
|
-
let
|
|
336
|
+
return x(() => {
|
|
337
|
+
let b = !1;
|
|
302
338
|
return (async () => {
|
|
303
339
|
try {
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
306
|
-
const w =
|
|
340
|
+
const g = i.find((m) => m.getInternal?.()?.locar);
|
|
341
|
+
if (!g || b) return;
|
|
342
|
+
const w = g.getInternal?.()?.locar;
|
|
307
343
|
if (!w) return;
|
|
308
|
-
const
|
|
344
|
+
const S = (m) => {
|
|
309
345
|
try {
|
|
310
346
|
w.add(
|
|
311
347
|
m.anchor,
|
|
@@ -313,87 +349,96 @@ const he = ({
|
|
|
313
349
|
m.latitude,
|
|
314
350
|
m.altitude
|
|
315
351
|
), m.isAttached = !0, m.onAttach?.();
|
|
316
|
-
} catch (
|
|
317
|
-
console.error("❌ Failed to attach anchor:",
|
|
352
|
+
} catch (v) {
|
|
353
|
+
console.error("❌ Failed to attach anchor:", v);
|
|
318
354
|
}
|
|
319
|
-
},
|
|
320
|
-
anchor:
|
|
355
|
+
}, p = {
|
|
356
|
+
anchor: c,
|
|
321
357
|
isAttached: !1,
|
|
322
358
|
latitude: e,
|
|
323
359
|
longitude: t,
|
|
324
360
|
altitude: n || 0,
|
|
325
|
-
onAttach:
|
|
361
|
+
onAttach: l,
|
|
326
362
|
onGpsUpdate: f
|
|
327
363
|
};
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
364
|
+
if (E.set(A, p), !M) {
|
|
365
|
+
C = ({
|
|
366
|
+
position: v,
|
|
367
|
+
distMoved: W
|
|
368
|
+
}) => {
|
|
369
|
+
R = v, E.forEach((_) => {
|
|
370
|
+
_.isAttached || S(_), _.onGpsUpdate?.(v, W);
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
const m = w.getLastKnownLocation();
|
|
374
|
+
m !== null && (R = {
|
|
375
|
+
coords: m,
|
|
376
|
+
timestamp: Date.now(),
|
|
377
|
+
toJSON: () => m
|
|
378
|
+
}), R !== null && !p.isAttached && S(p), w.on?.("gpsupdate", C), M = !0;
|
|
379
|
+
}
|
|
380
|
+
R !== null && (p.isAttached || S(p), p.onGpsUpdate?.(R, 0)), s.current = !1;
|
|
381
|
+
} catch (g) {
|
|
382
|
+
console.error("Failed to initialize geolocation backend:", g);
|
|
338
383
|
}
|
|
339
384
|
})(), () => {
|
|
340
|
-
if (
|
|
385
|
+
if (b = !0, E.get(A)?.isAttached)
|
|
341
386
|
try {
|
|
342
|
-
const
|
|
343
|
-
typeof
|
|
344
|
-
} catch (
|
|
345
|
-
console.error(`⚠️ Error removing anchor ${
|
|
387
|
+
const S = i.find((p) => p.getInternal?.()?.locar)?.getInternal?.()?.locar;
|
|
388
|
+
typeof S?.remove == "function" ? S.remove(c) : c.removeFromParent();
|
|
389
|
+
} catch (k) {
|
|
390
|
+
console.error(`⚠️ Error removing anchor ${A}:`, k);
|
|
346
391
|
}
|
|
347
|
-
|
|
392
|
+
E.delete(A), E.size === 0 && C && (i.find((p) => p.getInternal?.()?.locar)?.getInternal?.()?.locar?.off?.("gpsupdate", C), C = null, M = !1);
|
|
348
393
|
};
|
|
349
394
|
}, [
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
395
|
+
i,
|
|
396
|
+
c,
|
|
397
|
+
A,
|
|
353
398
|
e,
|
|
354
399
|
t,
|
|
355
400
|
n,
|
|
356
|
-
|
|
401
|
+
l,
|
|
357
402
|
f
|
|
358
|
-
]),
|
|
359
|
-
!
|
|
360
|
-
}),
|
|
361
|
-
},
|
|
403
|
+
]), L(() => {
|
|
404
|
+
!r || !d || !E.get(A)?.isAttached || c.lookAt(d.position);
|
|
405
|
+
}), K(/* @__PURE__ */ F("group", { children: a }), c);
|
|
406
|
+
}, Ae = ({
|
|
362
407
|
options: e = {},
|
|
363
408
|
children: t
|
|
364
409
|
}) => {
|
|
365
|
-
const { scene: n, camera:
|
|
366
|
-
return
|
|
367
|
-
if (
|
|
368
|
-
let
|
|
410
|
+
const { scene: n, camera: r, gl: u } = j(), { registerBackend: o, unregisterBackend: a } = T(), i = y(null), d = y(e);
|
|
411
|
+
return d.current = e, x(() => {
|
|
412
|
+
if (i.current) return;
|
|
413
|
+
let c = !1;
|
|
369
414
|
return (async () => {
|
|
370
415
|
try {
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
await
|
|
374
|
-
|
|
375
|
-
{ scene: n, camera:
|
|
376
|
-
|
|
377
|
-
),
|
|
378
|
-
} catch (
|
|
379
|
-
console.error("[GeolocationSession] Failed to initialize:",
|
|
416
|
+
const s = fe(d.current);
|
|
417
|
+
if (c) return;
|
|
418
|
+
await o(
|
|
419
|
+
s,
|
|
420
|
+
{ scene: n, camera: r, renderer: u },
|
|
421
|
+
h.GEOLOCATION
|
|
422
|
+
), i.current = s;
|
|
423
|
+
} catch (s) {
|
|
424
|
+
console.error("[GeolocationSession] Failed to initialize:", s);
|
|
380
425
|
}
|
|
381
426
|
})(), () => {
|
|
382
|
-
|
|
427
|
+
c = !0, i.current && (a(i.current, h.GEOLOCATION), i.current = null);
|
|
383
428
|
};
|
|
384
|
-
}, [n,
|
|
429
|
+
}, [n, r, u, o, a]), t;
|
|
385
430
|
};
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
let t, n,
|
|
431
|
+
Ae.sessionType = "GeolocationSession";
|
|
432
|
+
const fe = (e) => {
|
|
433
|
+
let t, n, r, u, o = null, a = null;
|
|
389
434
|
return {
|
|
390
|
-
async init(
|
|
391
|
-
const { camera:
|
|
392
|
-
if (!
|
|
435
|
+
async init(i) {
|
|
436
|
+
const { camera: d, renderer: c, scene: A } = i;
|
|
437
|
+
if (!A)
|
|
393
438
|
throw new Error(
|
|
394
439
|
"[geolocationBackend] A THREE.Scene is required for location-based AR"
|
|
395
440
|
);
|
|
396
|
-
|
|
441
|
+
o = d, a = c, t = new z.LocationBased(A, d), n = new z.Webcam(
|
|
397
442
|
e.webcamConstraints ?? {
|
|
398
443
|
video: { facingMode: "environment" }
|
|
399
444
|
},
|
|
@@ -401,33 +446,33 @@ const se = (e) => {
|
|
|
401
446
|
), t.on(
|
|
402
447
|
"gpsupdate",
|
|
403
448
|
// TODO remove explicit type annotation once LocAR.js converted to TS (https://github.com/AR-js-org/locar.js/pull/27#issuecomment-3487422995)
|
|
404
|
-
(
|
|
405
|
-
e.onGpsUpdate?.(
|
|
449
|
+
(l) => {
|
|
450
|
+
e.onGpsUpdate?.(l.position, l.distMoved);
|
|
406
451
|
}
|
|
407
|
-
), n.on("webcamstarted", (
|
|
408
|
-
|
|
409
|
-
}), n.on("webcamerror", (
|
|
410
|
-
console.error("[geolocationBackend] webcam error:",
|
|
411
|
-
}),
|
|
412
|
-
|
|
413
|
-
}),
|
|
414
|
-
console.error("[geolocationBackend] Device orientation error:",
|
|
415
|
-
}),
|
|
416
|
-
console.error("[geolocationBackend] gps error:",
|
|
452
|
+
), n.on("webcamstarted", (l) => {
|
|
453
|
+
A.background = l.texture;
|
|
454
|
+
}), n.on("webcamerror", (l) => {
|
|
455
|
+
console.error("[geolocationBackend] webcam error:", l);
|
|
456
|
+
}), r = new z.DeviceOrientationControls(d), r.on("deviceorientationgranted", (l) => {
|
|
457
|
+
l.target?.connect?.();
|
|
458
|
+
}), r.on("deviceorientationerror", (l) => {
|
|
459
|
+
console.error("[geolocationBackend] Device orientation error:", l);
|
|
460
|
+
}), r.init?.(), t.on("gpserror", (l) => {
|
|
461
|
+
console.error("[geolocationBackend] gps error:", l);
|
|
417
462
|
}), t.startGps(), typeof e.fakeLat == "number" && typeof e.fakeLon == "number" && t.fakeGps(e.fakeLon, e.fakeLat);
|
|
418
|
-
const
|
|
419
|
-
if (!
|
|
420
|
-
const
|
|
421
|
-
|
|
463
|
+
const s = () => {
|
|
464
|
+
if (!a || !o) return;
|
|
465
|
+
const l = window.innerWidth, f = window.innerHeight;
|
|
466
|
+
a.setSize(l, f, !1), o.aspect = l / f, o.updateProjectionMatrix?.();
|
|
422
467
|
};
|
|
423
|
-
|
|
468
|
+
s(), window.addEventListener("resize", s), u = s, this._locar = t, this._webcam = n, this._deviceOrientation = r, this._scene = A, this._camera = d;
|
|
424
469
|
},
|
|
425
470
|
update() {
|
|
426
471
|
this._deviceOrientation?.update?.();
|
|
427
472
|
},
|
|
428
473
|
dispose() {
|
|
429
|
-
const
|
|
430
|
-
e?.onGpsUpdate &&
|
|
474
|
+
const i = this._locar, d = this._webcam, c = this._deviceOrientation;
|
|
475
|
+
e?.onGpsUpdate && i?.off("gpsupdate", e.onGpsUpdate), i?.stopGps?.(), d?.stop?.(), c?.dispose?.(), u && (window.removeEventListener("resize", u), u = void 0), this._locar = null, this._webcam = null, this._deviceOrientation = null, this._scene = null, this._camera = null;
|
|
431
476
|
},
|
|
432
477
|
getInternal() {
|
|
433
478
|
return {
|
|
@@ -444,25 +489,25 @@ const se = (e) => {
|
|
|
444
489
|
};
|
|
445
490
|
}
|
|
446
491
|
};
|
|
447
|
-
},
|
|
448
|
-
const t =
|
|
449
|
-
return
|
|
450
|
-
const n =
|
|
451
|
-
return n.sessionTypes.add(
|
|
452
|
-
n.sessionTypes.delete(
|
|
492
|
+
}, Ee = ({ children: e }) => {
|
|
493
|
+
const t = q(() => $(), []);
|
|
494
|
+
return x(() => {
|
|
495
|
+
const n = le();
|
|
496
|
+
return n.sessionTypes.add(h.IMMERSIVE), n.setImmersiveStore(t), () => {
|
|
497
|
+
n.sessionTypes.delete(h.IMMERSIVE), n.setImmersiveStore(null);
|
|
453
498
|
};
|
|
454
|
-
}, [t]), /* @__PURE__ */
|
|
499
|
+
}, [t]), /* @__PURE__ */ F(J, { store: t, children: e });
|
|
455
500
|
};
|
|
456
501
|
export {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
502
|
+
Ie as FiducialAnchor,
|
|
503
|
+
ue as FiducialSession,
|
|
504
|
+
ke as GeolocationAnchor,
|
|
505
|
+
Ae as GeolocationSession,
|
|
506
|
+
Ee as ImmersiveSession,
|
|
507
|
+
ye as XR,
|
|
508
|
+
de as createFiducialBackend,
|
|
509
|
+
fe as createGeolocationBackend,
|
|
510
|
+
le as getXRStore,
|
|
511
|
+
we as subscribeToXRStore,
|
|
512
|
+
T as useXRStore
|
|
468
513
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnidotdev/rdk",
|
|
3
3
|
"description": "AR.js with react-three-fiber",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@ar-js-org/ar.js": "^3.4.7",
|
|
68
68
|
"@biomejs/biome": "^2.3.8",
|
|
69
|
-
"@react-three/fiber": "^9.4.
|
|
69
|
+
"@react-three/fiber": "^9.4.2",
|
|
70
70
|
"@testing-library/jest-dom": "^6.9.1",
|
|
71
71
|
"@testing-library/react": "^16.3.0",
|
|
72
72
|
"@types/node": "^24.10.1",
|
|
@@ -75,18 +75,18 @@
|
|
|
75
75
|
"@types/three": "^0.181.0",
|
|
76
76
|
"@types/webxr": "^0.5.24",
|
|
77
77
|
"jsdom": "^27.2.0",
|
|
78
|
-
"locar": "^0.1.
|
|
78
|
+
"locar": "^0.1.6",
|
|
79
79
|
"react": "^19.2.0",
|
|
80
80
|
"react-dom": "^19.2.0",
|
|
81
81
|
"three": "^0.181.2",
|
|
82
82
|
"typescript": "^5.9.3",
|
|
83
|
-
"vite": "^7.2.
|
|
83
|
+
"vite": "^7.2.6",
|
|
84
84
|
"vite-plugin-dts": "^4.5.4",
|
|
85
85
|
"vite-tsconfig-paths": "^5.1.4",
|
|
86
|
-
"vitest": "^4.0.
|
|
86
|
+
"vitest": "^4.0.15"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"ts-pattern": "^5.9.0",
|
|
90
|
-
"zustand": "^5.0.
|
|
90
|
+
"zustand": "^5.0.9"
|
|
91
91
|
}
|
|
92
92
|
}
|