@omnidotdev/rdk 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ export interface GeoLineProps {
2
+ /** Array of coordinates forming the line. GeoJSON-style: [lon, lat, elevation?] */
3
+ coordinates: Array<[number, number, number?]>;
4
+ /**
5
+ * Line color.
6
+ * @default "#ff0000"
7
+ */
8
+ color?: string;
9
+ /**
10
+ * Whether line is dashed.
11
+ * @default false
12
+ */
13
+ isDashed?: boolean;
14
+ /**
15
+ * Dash size (requires isDashed=true).
16
+ * @default 3
17
+ */
18
+ dashSize?: number;
19
+ /**
20
+ * Line width (in world units).
21
+ * @default 1
22
+ */
23
+ lineWidth?: number;
24
+ /**
25
+ * Gap size (requires isDashed=true).
26
+ * @default 1
27
+ */
28
+ gapSize?: number;
29
+ }
30
+ /**
31
+ * Geolocation line component for rendering lines in AR space. Useful for e.g. roads, paths, and routes.
32
+ * Accepts an array of lon/lat coordinates in GeoJSON-style format.
33
+ */
34
+ declare const GeoLine: ({ coordinates, color, isDashed, dashSize, gapSize, lineWidth, }: GeoLineProps) => import("react").JSX.Element;
35
+ export default GeoLine;
36
+ //# sourceMappingURL=GeoLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeoLine.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeoLine.tsx"],"names":[],"mappings":"AAWA,MAAM,WAAW,YAAY;IAC3B,mFAAmF;IACnF,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9C;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,QAAA,MAAM,OAAO,GAAI,iEAOd,YAAY,gCAyEd,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,35 @@
1
+ export interface GeoPolygonProps {
2
+ /** Outer ring coordinates. GeoJSON-style: [lon, lat, elevation?] */
3
+ coordinates: Array<[number, number, number?]>;
4
+ /**
5
+ * Optional inner rings (holes).
6
+ */
7
+ holes?: Array<Array<[number, number, number?]>>;
8
+ /**
9
+ * Fill color.
10
+ * @default "#ff0000"
11
+ */
12
+ color?: string;
13
+ /**
14
+ * Fill opacity (0-1).
15
+ * @default 1
16
+ */
17
+ opacity?: number;
18
+ /**
19
+ * Whether to render as wireframe.
20
+ * @default false
21
+ */
22
+ isWireframe?: boolean;
23
+ /**
24
+ * Side to render: front, back, or double.
25
+ * @default "double"
26
+ */
27
+ side?: "front" | "back" | "double";
28
+ }
29
+ /**
30
+ * Geolocation polygon component for rendering filled areas in AR space.
31
+ * Accepts an array of lon/lat coordinates in GeoJSON-style format.
32
+ */
33
+ declare const GeoPolygon: ({ coordinates, holes, color, opacity, isWireframe, side, }: GeoPolygonProps) => import("react").JSX.Element;
34
+ export default GeoPolygon;
35
+ //# sourceMappingURL=GeoPolygon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GeoPolygon.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeoPolygon.tsx"],"names":[],"mappings":"AAiBA,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9C;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;CACpC;AAQD;;;GAGG;AACH,QAAA,MAAM,UAAU,GAAI,4DAOjB,eAAe,gCA6HjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -17,7 +17,8 @@ export interface AnchorEntry {
17
17
  latitude: number;
18
18
  longitude: number;
19
19
  altitude: number;
20
- onAttach?: () => void;
20
+ /** Called once attached to LocAR scene. Receives locar instance for coordinate conversion. */
21
+ onAttach?: (locar: LocAR) => void;
21
22
  onGpsUpdate?: (position: GeolocationPosition, distMoved: number) => void;
22
23
  }
23
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,aAAa,IAAI,KAAK,EACtB,MAAM,EACP,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAiB,MAAM,OAAO,CAAC;AAEjE;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iBAAiB,EAAE,yBAAyB,GAAG,IAAI,CAAC;IACpD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+BAA+B;IAC/B,YAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACzC,2CAA2C;IAC3C,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACzD,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,iCAAiC;IACjC,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,iEAAiE;IACjE,SAAS,EAAE,OAAO,CAAC;IACnB,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;IAC3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9E;AAED;;GAEG;AACH,QAAA,MAAM,wBAAwB,GAC5B,UAAU,yBAAyB,KAClC,OAAO,CAAC,mBAAmB,CA+N7B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
1
+ {"version":3,"file":"geolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/geolocationBackend.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,aAAa,IAAI,KAAK,EACtB,MAAM,EACP,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAiB,MAAM,OAAO,CAAC;AAEjE;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1E;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,iBAAiB,EAAE,yBAAyB,GAAG,IAAI,CAAC;IACpD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+BAA+B;IAC/B,YAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACzC,2CAA2C;IAC3C,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACzD,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,iCAAiC;IACjC,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAC;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,iEAAiE;IACjE,SAAS,EAAE,OAAO,CAAC;IACnB,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,CAAC;IAC3C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9E;AAED;;GAEG;AACH,QAAA,MAAM,wBAAwB,GAC5B,UAAU,yBAAyB,KAClC,OAAO,CAAC,mBAAmB,CA+N7B,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
@@ -1,8 +1,12 @@
1
+ export { default as GeoLine } from './GeoLine';
1
2
  export { default as GeolocationAnchor } from './GeolocationAnchor';
2
3
  export { default as GeolocationSession } from './GeolocationSession';
4
+ export { default as GeoPolygon } from './GeoPolygon';
3
5
  export { default as createGeolocationBackend } from './geolocationBackend';
4
6
  export { default as useGeolocationBackend } from './useGeolocationBackend';
7
+ export type { GeoLineProps } from './GeoLine';
5
8
  export type { GeolocationAnchorProps } from './GeolocationAnchor';
6
9
  export type { GeolocationSessionProps } from './GeolocationSession';
10
+ export type { GeoPolygonProps } from './GeoPolygon';
7
11
  export type { AnchorEntry, GeolocationBackendState, GeolocationInternal, GeolocationSessionOptions, GpsUpdateEvent, } from './geolocationBackend';
8
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geolocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE3E,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,YAAY,EACV,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,yBAAyB,EACzB,cAAc,GACf,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geolocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAE3E,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,YAAY,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EACV,WAAW,EACX,uBAAuB,EACvB,mBAAmB,EACnB,yBAAyB,EACzB,cAAc,GACf,MAAM,sBAAsB,CAAC"}
package/build/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),h=require("@react-three/fiber"),v=require("react/jsx-runtime"),I=require("@ar-js-org/ar.js/three.js/build/ar-threex"),N=require("three"),R=require("locar"),x=require("@react-three/xr");var C=typeof document<"u"?document.currentScript:null;const p={FIDUCIAL:"fiducial",GEOLOCATION:"geolocation",IMMERSIVE:"immersive"},M=n=>{let e;const t=new Set,r=(a,f)=>{const l=typeof a=="function"?a(e):a;if(!Object.is(l,e)){const o=e;e=f??(typeof l!="object"||l===null)?l:Object.assign({},e,l),t.forEach(d=>d(e,o))}},c=()=>e,s={setState:r,getState:c,getInitialState:()=>u,subscribe:a=>(t.add(a),()=>t.delete(a))},u=e=n(r,c,s);return s},D=(n=>n?M(n):M),U=n=>n;function q(n,e=U){const t=m.useSyncExternalStore(n.subscribe,m.useCallback(()=>e(n.getState()),[n,e]),m.useCallback(()=>e(n.getInitialState()),[n,e]));return m.useDebugValue(t),t}const X=n=>{const e=D(n),t=r=>q(e,r);return Object.assign(t,e),t},H=(n=>X),W=n=>(e,t,r)=>{const c=r.subscribe;return r.subscribe=((A,s,u)=>{let a=A;if(s){const f=u?.equalityFn||Object.is;let l=A(r.getState());a=o=>{const d=A(o);if(!f(l,d)){const b=l;s(l=d,b)}},u?.fireImmediately&&s(l,l)}return c(a)}),n(e,t,r)},_=W,T=n=>Symbol.iterator in n,F=n=>"entries"in n,j=(n,e)=>{const t=n instanceof Map?n:new Map(n.entries()),r=e instanceof Map?e:new Map(e.entries());if(t.size!==r.size)return!1;for(const[c,i]of t)if(!r.has(c)||!Object.is(i,r.get(c)))return!1;return!0},K=(n,e)=>{const t=n[Symbol.iterator](),r=e[Symbol.iterator]();let c=t.next(),i=r.next();for(;!c.done&&!i.done;){if(!Object.is(c.value,i.value))return!1;c=t.next(),i=r.next()}return!!c.done&&!!i.done};function V(n,e){return Object.is(n,e)?!0:typeof n!="object"||n===null||typeof e!="object"||e===null||Object.getPrototypeOf(n)!==Object.getPrototypeOf(e)?!1:T(n)&&T(e)?F(n)&&F(e)?j(n,e):K(n,e):j({entries:()=>Object.entries(n)},{entries:()=>Object.entries(e)})}function Y(n){const e=m.useRef(void 0);return t=>{const r=n(t);return V(e.current,r)?e.current:e.current=r}}const O=H()(_((n,e)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(t,r)=>{try{const c=e(),i=new Set(c.backends.keys()),A=i.has(p.FIDUCIAL)||t.type===p.FIDUCIAL,s=i.has(p.GEOLOCATION)||t.type===p.GEOLOCATION;if(A&&s){const u="❌ [RDK] INCOMPATIBLE SESSIONS: fiducial and geolocation backends cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.";throw console.error(u),new Error(u)}await t.init({scene:r.scene,camera:r.camera,renderer:r.renderer}),n(u=>{const a=new Map(u.backends);return a.set(t.type,t),{backends:a}})}catch(c){throw console.error("[XRStore] Failed to register backend:",c),c}},unregisterBackend:t=>{n(r=>{const c=new Map(r.backends);c.delete(t.type);try{t.dispose?.()}catch(i){console.error("[XRStore] Error disposing backend:",i)}return{backends:c}})},setVideo:t=>{n({video:t})},updateBackends:t=>{const{backends:r}=e();for(const c of r.values())try{c.update?.(t)}catch(i){console.error("[XRStore] Backend update error:",i)}},setImmersiveStore:t=>{n({immersiveStore:t})}}))),L=()=>O.getState(),Q=O.subscribe,k=n=>O(Y(t=>{const r={...t,isImmersive:t.backends.has(p.IMMERSIVE),immersive:t.immersiveStore||null};return n?n(r):r})),J=({children:n})=>{const{updateBackends:e}=k();return h.useFrame((t,r)=>{e(r)}),n},$={isPending:!0,isSuccess:!1,arSource:null,arContext:null},B=()=>{const e=k(t=>t.backends).get(p.FIDUCIAL);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:$},Z=({patternUrl:n,barcodeValue:e,params:t,onMarkerFound:r,onMarkerLost:c,children:i})=>{const A=m.useRef(null),s=B(),u=m.useRef(!1),a=m.useRef(!1),f=m.useRef(null);return m.useEffect(()=>{if(!s.isSuccess)return;let l=!1;return(()=>{try{const{arContext:d}=s,b=A.current;if(!d||!b||l)return;if(b.visible=!1,a.current=!1,!d.arController){requestAnimationFrame(()=>{if(!A.current||l||!s.arContext?.arController)return;const g=new I.ArMarkerControls(s.arContext,A.current,{type:n?"pattern":e?"barcode":"unknown",patternUrl:n,barcodeValue:e,...t});f.current=g,a.current=!0});return}const w=new I.ArMarkerControls(d,b,{type:n?"pattern":e?"barcode":"unknown",patternUrl:n,barcodeValue:e,...t});f.current=w,a.current=!0}catch(d){console.error("Failed to initialize fiducial anchor:",d)}})(),()=>{l=!0;const d=f.current;typeof d?.dispose=="function"&&d.dispose(),a.current=!1}},[s.isSuccess,s.arContext,n,e,t,s]),h.useFrame(()=>{const l=A.current;if(!l||!a.current){l&&(l.visible=!1);return}const o=l.visible;o&&!u.current?(u.current=!0,r?.()):!o&&u.current&&(u.current=!1,c?.())}),v.jsx("group",{ref:A,visible:!1,children:i})},ee=({options:n={},children:e})=>{const{scene:t,camera:r,gl:c}=h.useThree(),{registerBackend:i,unregisterBackend:A}=k(),s=m.useRef(null),u=m.useRef(n);return u.current=n,m.useEffect(()=>{if(s.current)return;let a=!1;return(async()=>{try{const l=G(u.current);if(a)return;await i(l,{scene:t,camera:r,renderer:c}),s.current=l}catch(l){console.error("[FiducialSession] Failed to initialize:",l)}})(),()=>{a=!0,s.current&&(A(s.current),s.current=null)}},[t,r,c,i,A]),e},G=n=>{let e=null,t=null,r=null,c;return{type:p.FIDUCIAL,async init({camera:i,renderer:A}){e=new I.ArToolkitSource({sourceType:n?.sourceType??"webcam"}),await new Promise((a,f)=>{const l=setTimeout(()=>{f(new Error("AR source initialization timeout"))},1e4);e?.init(()=>{clearTimeout(l);const o=e?.domElement;o&&(o.style.position="fixed",o.style.top="0",o.style.left="0",o.style.width="100vw",o.style.height="100vh",o.style.objectFit="cover",o.style.zIndex="-1",o.style.pointerEvents="none"),a()})});const s={cameraParametersUrl:n?.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:C&&C.tagName.toUpperCase()==="SCRIPT"&&C.src||new URL("index.cjs",document.baseURI).href).toString(),detectionMode:n?.detectionMode??"mono",patternRatio:n?.patternRatio??.5,matrixCodeType:n?.matrixCodeType??"3x3"};t=new I.ArToolkitContext(s),r=i;const u=()=>{e?.onResizeElement();const a=window.innerWidth,f=window.innerHeight;A.setSize(a,f,!1),e?.copyElementSizeTo(A.domElement),t?.arController&&e?.copyElementSizeTo(t.arController.canvas)};await new Promise((a,f)=>{const l=setTimeout(()=>{f(new Error("AR context initialization timeout"))},1e4);t?.init(()=>{clearTimeout(l);try{const o=t?.getProjectionMatrix();o&&i.projectionMatrix.copy(o),u(),a()}catch(o){f(o)}})}),window.addEventListener("resize",u),c=u},update(){if(!(!e||!t)&&!(!e.ready||!e.domElement))try{t.update(e.domElement);const i=t.getProjectionMatrix?.();r&&i&&r.projectionMatrix.copy(i)}catch(i){console.warn("AR.js update error:",i)}},dispose(){if(c&&(window.removeEventListener("resize",c),c=void 0),t&&typeof t.dispose=="function"&&t.dispose(),e?.domElement){const i=e.domElement.parentNode;i&&i.removeChild(e.domElement)}e=null,t=null,r=null},getInternal:()=>({arSource:e,arContext:t})}},te={isPending:!0,isSuccess:!1,locar:null,webcam:null,deviceOrientation:null,scene:null,camera:null,lastPosition:null,registerAnchor:()=>{},unregisterAnchor:()=>{},getAnchor:()=>{}},P=()=>{const e=k(t=>t.backends).get(p.GEOLOCATION);return e?{...e.getInternal(),isPending:!1,isSuccess:!0}:te},ne=({latitude:n,longitude:e,altitude:t=0,isBillboard:r=!0,onAttach:c,onGpsUpdate:i,children:A})=>{const s=P(),{camera:u}=h.useThree(),[a]=m.useState(()=>new N.Group),f=m.useMemo(()=>Math.random().toString(36).slice(2,11),[]),l=m.useCallback(()=>{c?.()},[c]),o=m.useCallback((d,b)=>{i?.(d,b)},[i]);return m.useEffect(()=>{if(s.isSuccess)return s.registerAnchor(f,{anchor:a,isAttached:!1,latitude:n,longitude:e,altitude:t,onAttach:l,onGpsUpdate:o}),()=>{s.unregisterAnchor(f)}},[s.isSuccess,s.registerAnchor,s.unregisterAnchor,a,f,n,e,t,l,o]),h.useFrame(()=>{!r||!u||!s.isSuccess||!s.getAnchor(f)?.isAttached||a.lookAt(u.position)}),h.createPortal(v.jsx("group",{children:A}),a)},re=({options:n={},children:e})=>{const{scene:t,camera:r,gl:c}=h.useThree(),{registerBackend:i,unregisterBackend:A}=k(),s=m.useRef(null),u=m.useRef(n);return u.current=n,m.useEffect(()=>{if(s.current)return;let a=!1;return(async()=>{try{const l=z(u.current);if(a)return;await i(l,{scene:t,camera:r,renderer:c}),s.current=l}catch(l){console.error("[GeolocationSession] Failed to initialize:",l)}})(),()=>{a=!0,s.current&&(A(s.current),s.current=null)}},[t,r,c,i,A]),e},z=n=>{let e=null,t=null,r=null,c,i=null,A=null,s=null,u=null;const a=new Map;let f=null;const l=o=>{if(!(!e||o.isAttached))try{e.add(o.anchor,o.longitude,o.latitude,o.altitude),o.isAttached=!0,o.onAttach?.()}catch(d){console.error("❌ Failed to attach anchor:",d)}};return{type:p.GEOLOCATION,async init(o){const{camera:d,renderer:b,scene:w}=o;if(!w)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");A=d,s=b,u=w,e=new R.LocationBased(w,d),t=new R.Webcam(n?.webcamConstraints??{video:{facingMode:"environment"}}),i=S=>{f=S.position;for(const y of a.values())y.isAttached||l(y),y.onGpsUpdate?.(S.position,S.distMoved);n?.onGpsUpdate?.(S.position,S.distMoved)},e.on("gpsupdate",i),t.on("webcamstarted",S=>{w.background=S.texture}),t.on("webcamerror",S=>{console.error("[geolocationBackend] webcam error:",S)}),r=new R.DeviceOrientationControls(d),r.on("deviceorientationgranted",S=>{S.target?.connect?.()}),r.on("deviceorientationerror",S=>{console.error("[geolocationBackend] Device orientation error:",S)}),r.init?.(),e.on("gpserror",S=>{console.error("[geolocationBackend] gps error:",S)}),e.startGps(),typeof n?.fakeLat=="number"&&typeof n?.fakeLon=="number"&&e.fakeGps(n.fakeLon,n.fakeLat);const g=e.getLastKnownLocation();g!==null&&(f={coords:{longitude:g.longitude,latitude:g.latitude,accuracy:0,altitude:null,altitudeAccuracy:null,heading:null,speed:null,toJSON:()=>g},timestamp:Date.now(),toJSON:()=>g});const E=()=>{if(!s||!A)return;const S=window.innerWidth,y=window.innerHeight;s.setSize(S,y,!1),A.aspect=S/y,A.updateProjectionMatrix?.()};E(),window.addEventListener("resize",E),c=E},update(){r?.update?.()},dispose(){e&&i&&e.off("gpsupdate",i),e?.stopGps?.(),t?.stop?.(),r?.dispose?.(),c&&(window.removeEventListener("resize",c),c=void 0);for(const o of a.values())if(o.isAttached)try{o.anchor.removeFromParent()}catch(d){console.error("⚠️ Error removing anchor:",d)}a.clear(),e=null,t=null,r=null,A=null,s=null,u=null,i=null,f=null},getInternal:()=>({locar:e,webcam:t,deviceOrientation:r,scene:u,camera:A,lastPosition:f,registerAnchor:(o,d)=>{a.set(o,d),f!==null&&!d.isAttached&&(l(d),d.onGpsUpdate?.(f,0))},unregisterAnchor:o=>{const d=a.get(o);if(d?.isAttached)try{d.anchor.removeFromParent()}catch(b){console.error(`⚠️ Error removing anchor ${o}:`,b)}a.delete(o)},getAnchor:o=>a.get(o)})}},oe=()=>({type:p.IMMERSIVE,init:()=>{},getInternal:()=>null}),se=({children:n})=>{const e=m.useMemo(()=>x.createXRStore(),[]);return m.useEffect(()=>{const t=L(),r=oe();return t.backends.set(p.IMMERSIVE,r),t.setImmersiveStore(e),()=>{t.backends.delete(p.IMMERSIVE),t.setImmersiveStore(null)}},[e]),v.jsx(x.XR,{store:e,children:n})};exports.BACKEND_TYPES=p;exports.FiducialAnchor=Z;exports.FiducialSession=ee;exports.GeolocationAnchor=ne;exports.GeolocationSession=re;exports.ImmersiveSession=se;exports.XR=J;exports.createFiducialBackend=G;exports.createGeolocationBackend=z;exports.getXRStore=L;exports.subscribeToXRStore=Q;exports.useFiducialBackend=B;exports.useGeolocationBackend=P;exports.useXRStore=k;
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;
package/build/index.js CHANGED
@@ -1,324 +1,327 @@
1
- import y, { useRef as b, useEffect as k, useState as P, useMemo as F, useCallback as M } from "react";
2
- import { useFrame as R, useThree as v, createPortal as G } from "@react-three/fiber";
3
- import { jsx as C } from "react/jsx-runtime";
4
- import { ArMarkerControls as x, ArToolkitSource as B, ArToolkitContext as N } from "@ar-js-org/ar.js/three.js/build/ar-threex";
5
- import { Group as D } from "three";
6
- import { LocationBased as U, Webcam as X, DeviceOrientationControls as H } from "locar";
7
- import { createXRStore as W, XR as q } from "@react-three/xr";
8
- const p = {
1
+ import O, { useRef as E, useEffect as C, useState as T, useMemo as j, useCallback as V } from "react";
2
+ import { useFrame as N, useThree as X, createPortal as U } from "@react-three/fiber";
3
+ import { jsx as I } from "react/jsx-runtime";
4
+ import { ArMarkerControls as K, ArToolkitSource as re, ArToolkitContext as oe } from "@ar-js-org/ar.js/three.js/build/ar-threex";
5
+ import { Group as W, Vector3 as se, DoubleSide as ie, BackSide as ce, FrontSide as ae, Shape as le, Path as ue, ShapeGeometry as de } from "three";
6
+ import { Line2 as Ae } from "three/addons/lines/Line2.js";
7
+ import { LineGeometry as fe } from "three/addons/lines/LineGeometry.js";
8
+ import { LineMaterial as me } from "three/addons/lines/LineMaterial.js";
9
+ import { LocationBased as ge, Webcam as he, DeviceOrientationControls as pe } from "locar";
10
+ import { createXRStore as Se, XR as be } from "@react-three/xr";
11
+ const b = {
9
12
  FIDUCIAL: "fiducial",
10
13
  GEOLOCATION: "geolocation",
11
14
  IMMERSIVE: "immersive"
12
- }, L = (n) => {
15
+ }, _ = (t) => {
13
16
  let e;
14
- const t = /* @__PURE__ */ new Set(), r = (a, f) => {
15
- const l = typeof a == "function" ? a(e) : a;
16
- if (!Object.is(l, e)) {
17
- const o = e;
18
- e = f ?? (typeof l != "object" || l === null) ? l : Object.assign({}, e, l), t.forEach((d) => d(e, o));
17
+ const n = /* @__PURE__ */ new Set(), r = (s, f) => {
18
+ const u = typeof s == "function" ? s(e) : s;
19
+ if (!Object.is(u, e)) {
20
+ const i = e;
21
+ e = f ?? (typeof u != "object" || u === null) ? u : Object.assign({}, e, u), n.forEach((A) => A(e, i));
19
22
  }
20
- }, c = () => e, s = { setState: r, getState: c, getInitialState: () => u, subscribe: (a) => (t.add(a), () => t.delete(a)) }, u = e = n(r, c, s);
21
- return s;
22
- }, K = ((n) => n ? L(n) : L), V = (n) => n;
23
- function Q(n, e = V) {
24
- const t = y.useSyncExternalStore(
25
- n.subscribe,
26
- y.useCallback(() => e(n.getState()), [n, e]),
27
- y.useCallback(() => e(n.getInitialState()), [n, e])
23
+ }, c = () => e, o = { setState: r, getState: c, getInitialState: () => d, subscribe: (s) => (n.add(s), () => n.delete(s)) }, d = e = t(r, c, o);
24
+ return o;
25
+ }, we = ((t) => t ? _(t) : _), ye = (t) => t;
26
+ function ke(t, e = ye) {
27
+ const n = O.useSyncExternalStore(
28
+ t.subscribe,
29
+ O.useCallback(() => e(t.getState()), [t, e]),
30
+ O.useCallback(() => e(t.getInitialState()), [t, e])
28
31
  );
29
- return y.useDebugValue(t), t;
32
+ return O.useDebugValue(n), n;
30
33
  }
31
- const Y = (n) => {
32
- const e = K(n), t = (r) => Q(e, r);
33
- return Object.assign(t, e), t;
34
- }, _ = ((n) => Y), J = (n) => (e, t, r) => {
34
+ const Ie = (t) => {
35
+ const e = we(t), n = (r) => ke(e, r);
36
+ return Object.assign(n, e), n;
37
+ }, Ee = ((t) => Ie), ve = (t) => (e, n, r) => {
35
38
  const c = r.subscribe;
36
- return r.subscribe = ((A, s, u) => {
37
- let a = A;
38
- if (s) {
39
- const f = u?.equalityFn || Object.is;
40
- let l = A(r.getState());
41
- a = (o) => {
42
- const d = A(o);
43
- if (!f(l, d)) {
44
- const S = l;
45
- s(l = d, S);
39
+ return r.subscribe = ((l, o, d) => {
40
+ let s = l;
41
+ if (o) {
42
+ const f = d?.equalityFn || Object.is;
43
+ let u = l(r.getState());
44
+ s = (i) => {
45
+ const A = l(i);
46
+ if (!f(u, A)) {
47
+ const g = u;
48
+ o(u = A, g);
46
49
  }
47
- }, u?.fireImmediately && s(l, l);
50
+ }, d?.fireImmediately && o(u, u);
48
51
  }
49
- return c(a);
50
- }), n(e, t, r);
51
- }, $ = J, T = (n) => Symbol.iterator in n, j = (n) => (
52
+ return c(s);
53
+ }), t(e, n, r);
54
+ }, Le = ve, Q = (t) => Symbol.iterator in t, Y = (t) => (
52
55
  // HACK: avoid checking entries type
53
- "entries" in n
54
- ), z = (n, e) => {
55
- const t = n instanceof Map ? n : new Map(n.entries()), r = e instanceof Map ? e : new Map(e.entries());
56
- if (t.size !== r.size)
56
+ "entries" in t
57
+ ), J = (t, e) => {
58
+ const n = t instanceof Map ? t : new Map(t.entries()), r = e instanceof Map ? e : new Map(e.entries());
59
+ if (n.size !== r.size)
57
60
  return !1;
58
- for (const [c, i] of t)
59
- if (!r.has(c) || !Object.is(i, r.get(c)))
61
+ for (const [c, a] of n)
62
+ if (!r.has(c) || !Object.is(a, r.get(c)))
60
63
  return !1;
61
64
  return !0;
62
- }, Z = (n, e) => {
63
- const t = n[Symbol.iterator](), r = e[Symbol.iterator]();
64
- let c = t.next(), i = r.next();
65
- for (; !c.done && !i.done; ) {
66
- if (!Object.is(c.value, i.value))
65
+ }, Ce = (t, e) => {
66
+ const n = t[Symbol.iterator](), r = e[Symbol.iterator]();
67
+ let c = n.next(), a = r.next();
68
+ for (; !c.done && !a.done; ) {
69
+ if (!Object.is(c.value, a.value))
67
70
  return !1;
68
- c = t.next(), i = r.next();
71
+ c = n.next(), a = r.next();
69
72
  }
70
- return !!c.done && !!i.done;
73
+ return !!c.done && !!a.done;
71
74
  };
72
- function ee(n, e) {
73
- return Object.is(n, e) ? !0 : typeof n != "object" || n === null || typeof e != "object" || e === null || Object.getPrototypeOf(n) !== Object.getPrototypeOf(e) ? !1 : T(n) && T(e) ? j(n) && j(e) ? z(n, e) : Z(n, e) : z(
74
- { entries: () => Object.entries(n) },
75
+ function Re(t, e) {
76
+ return Object.is(t, e) ? !0 : typeof t != "object" || t === null || typeof e != "object" || e === null || Object.getPrototypeOf(t) !== Object.getPrototypeOf(e) ? !1 : Q(t) && Q(e) ? Y(t) && Y(e) ? J(t, e) : Ce(t, e) : J(
77
+ { entries: () => Object.entries(t) },
75
78
  { entries: () => Object.entries(e) }
76
79
  );
77
80
  }
78
- function te(n) {
79
- const e = y.useRef(void 0);
80
- return (t) => {
81
- const r = n(t);
82
- return ee(e.current, r) ? e.current : e.current = r;
81
+ function Me(t) {
82
+ const e = O.useRef(void 0);
83
+ return (n) => {
84
+ const r = t(n);
85
+ return Re(e.current, r) ? e.current : e.current = r;
83
86
  };
84
87
  }
85
- const O = _()(
86
- $((n, e) => ({
88
+ const H = Ee()(
89
+ Le((t, e) => ({
87
90
  // initial state
88
91
  video: null,
89
92
  backends: /* @__PURE__ */ new Map(),
90
93
  immersiveStore: null,
91
94
  // actions
92
- registerBackend: async (t, r) => {
95
+ registerBackend: async (n, r) => {
93
96
  try {
94
- const c = e(), i = new Set(c.backends.keys()), A = i.has(p.FIDUCIAL) || t.type === p.FIDUCIAL, s = i.has(p.GEOLOCATION) || t.type === p.GEOLOCATION;
95
- if (A && s) {
96
- const u = "❌ [RDK] INCOMPATIBLE SESSIONS: fiducial and geolocation backends cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.";
97
- throw console.error(u), new Error(u);
97
+ const c = e(), a = new Set(c.backends.keys()), l = a.has(b.FIDUCIAL) || n.type === b.FIDUCIAL, o = a.has(b.GEOLOCATION) || n.type === b.GEOLOCATION;
98
+ if (l && o) {
99
+ const d = "❌ [RDK] INCOMPATIBLE SESSIONS: fiducial and geolocation backends cannot be used together due to camera/video conflicts between AR.js and LocAR.js libraries. Use only one session type per app.";
100
+ throw console.error(d), new Error(d);
98
101
  }
99
- await t.init({
102
+ await n.init({
100
103
  scene: r.scene,
101
104
  camera: r.camera,
102
105
  renderer: r.renderer
103
- }), n((u) => {
104
- const a = new Map(u.backends);
105
- return a.set(t.type, t), { backends: a };
106
+ }), t((d) => {
107
+ const s = new Map(d.backends);
108
+ return s.set(n.type, n), { backends: s };
106
109
  });
107
110
  } catch (c) {
108
111
  throw console.error("[XRStore] Failed to register backend:", c), c;
109
112
  }
110
113
  },
111
- unregisterBackend: (t) => {
112
- n((r) => {
114
+ unregisterBackend: (n) => {
115
+ t((r) => {
113
116
  const c = new Map(r.backends);
114
- c.delete(t.type);
117
+ c.delete(n.type);
115
118
  try {
116
- t.dispose?.();
117
- } catch (i) {
118
- console.error("[XRStore] Error disposing backend:", i);
119
+ n.dispose?.();
120
+ } catch (a) {
121
+ console.error("[XRStore] Error disposing backend:", a);
119
122
  }
120
123
  return { backends: c };
121
124
  });
122
125
  },
123
- setVideo: (t) => {
124
- n({ video: t });
126
+ setVideo: (n) => {
127
+ t({ video: n });
125
128
  },
126
- updateBackends: (t) => {
129
+ updateBackends: (n) => {
127
130
  const { backends: r } = e();
128
131
  for (const c of r.values())
129
132
  try {
130
- c.update?.(t);
131
- } catch (i) {
132
- console.error("[XRStore] Backend update error:", i);
133
+ c.update?.(n);
134
+ } catch (a) {
135
+ console.error("[XRStore] Backend update error:", a);
133
136
  }
134
137
  },
135
- setImmersiveStore: (t) => {
136
- n({ immersiveStore: t });
138
+ setImmersiveStore: (n) => {
139
+ t({ immersiveStore: n });
137
140
  }
138
141
  }))
139
- ), ne = () => O.getState(), be = O.subscribe, I = (n) => O(
140
- te((t) => {
142
+ ), xe = () => H.getState(), _e = H.subscribe, P = (t) => H(
143
+ Me((n) => {
141
144
  const r = {
142
- ...t,
143
- isImmersive: t.backends.has(p.IMMERSIVE),
144
- immersive: t.immersiveStore || null
145
+ ...n,
146
+ isImmersive: n.backends.has(b.IMMERSIVE),
147
+ immersive: n.immersiveStore || null
145
148
  };
146
- return n ? n(r) : r;
149
+ return t ? t(r) : r;
147
150
  })
148
- ), ge = ({ children: n }) => {
149
- const { updateBackends: e } = I();
150
- return R((t, r) => {
151
+ ), Qe = ({ children: t }) => {
152
+ const { updateBackends: e } = P();
153
+ return N((n, r) => {
151
154
  e(r);
152
- }), n;
153
- }, re = {
155
+ }), t;
156
+ }, Oe = {
154
157
  isPending: !0,
155
158
  isSuccess: !1,
156
159
  arSource: null,
157
160
  arContext: null
158
- }, oe = () => {
159
- const e = I((t) => t.backends).get(p.FIDUCIAL);
161
+ }, Te = () => {
162
+ const e = P((n) => n.backends).get(b.FIDUCIAL);
160
163
  return e ? {
161
164
  ...e.getInternal(),
162
165
  isPending: !1,
163
166
  isSuccess: !0
164
- } : re;
165
- }, he = ({
166
- patternUrl: n,
167
+ } : Oe;
168
+ }, Ye = ({
169
+ patternUrl: t,
167
170
  barcodeValue: e,
168
- params: t,
171
+ params: n,
169
172
  onMarkerFound: r,
170
173
  onMarkerLost: c,
171
- children: i
174
+ children: a
172
175
  }) => {
173
- const A = b(null), s = oe(), u = b(!1), a = b(!1), f = b(null);
174
- return k(() => {
175
- if (!s.isSuccess) return;
176
- let l = !1;
176
+ const l = E(null), o = Te(), d = E(!1), s = E(!1), f = E(null);
177
+ return C(() => {
178
+ if (!o.isSuccess) return;
179
+ let u = !1;
177
180
  return (() => {
178
181
  try {
179
- const { arContext: d } = s, S = A.current;
180
- if (!d || !S || l) return;
181
- if (S.visible = !1, a.current = !1, !d.arController) {
182
+ const { arContext: A } = o, g = l.current;
183
+ if (!A || !g || u) return;
184
+ if (g.visible = !1, s.current = !1, !A.arController) {
182
185
  requestAnimationFrame(() => {
183
- if (!A.current || l || !s.arContext?.arController)
186
+ if (!l.current || u || !o.arContext?.arController)
184
187
  return;
185
- const g = new x(
186
- s.arContext,
187
- A.current,
188
+ const w = new K(
189
+ o.arContext,
190
+ l.current,
188
191
  {
189
- type: n ? "pattern" : e ? "barcode" : "unknown",
190
- patternUrl: n,
192
+ type: t ? "pattern" : e ? "barcode" : "unknown",
193
+ patternUrl: t,
191
194
  barcodeValue: e,
192
- ...t
195
+ ...n
193
196
  }
194
197
  );
195
- f.current = g, a.current = !0;
198
+ f.current = w, s.current = !0;
196
199
  });
197
200
  return;
198
201
  }
199
- const h = new x(d, S, {
200
- type: n ? "pattern" : e ? "barcode" : "unknown",
201
- patternUrl: n,
202
+ const p = new K(A, g, {
203
+ type: t ? "pattern" : e ? "barcode" : "unknown",
204
+ patternUrl: t,
202
205
  barcodeValue: e,
203
- ...t
206
+ ...n
204
207
  });
205
- f.current = h, a.current = !0;
206
- } catch (d) {
207
- console.error("Failed to initialize fiducial anchor:", d);
208
+ f.current = p, s.current = !0;
209
+ } catch (A) {
210
+ console.error("Failed to initialize fiducial anchor:", A);
208
211
  }
209
212
  })(), () => {
210
- l = !0;
211
- const d = f.current;
212
- typeof d?.dispose == "function" && d.dispose(), a.current = !1;
213
+ u = !0;
214
+ const A = f.current;
215
+ typeof A?.dispose == "function" && A.dispose(), s.current = !1;
213
216
  };
214
217
  }, [
215
- s.isSuccess,
216
- s.arContext,
217
- n,
218
- e,
218
+ o.isSuccess,
219
+ o.arContext,
219
220
  t,
220
- s
221
- ]), R(() => {
222
- const l = A.current;
223
- if (!l || !a.current) {
224
- l && (l.visible = !1);
221
+ e,
222
+ n,
223
+ o
224
+ ]), N(() => {
225
+ const u = l.current;
226
+ if (!u || !s.current) {
227
+ u && (u.visible = !1);
225
228
  return;
226
229
  }
227
- const o = l.visible;
228
- o && !u.current ? (u.current = !0, r?.()) : !o && u.current && (u.current = !1, c?.());
229
- }), /* @__PURE__ */ C(
230
+ const i = u.visible;
231
+ i && !d.current ? (d.current = !0, r?.()) : !i && d.current && (d.current = !1, c?.());
232
+ }), /* @__PURE__ */ I(
230
233
  "group",
231
234
  {
232
- ref: A,
235
+ ref: l,
233
236
  visible: !1,
234
- children: i
237
+ children: a
235
238
  }
236
239
  );
237
- }, we = ({ options: n = {}, children: e }) => {
238
- const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
239
- return u.current = n, k(() => {
240
- if (s.current) return;
241
- let a = !1;
240
+ }, Je = ({ options: t = {}, children: e }) => {
241
+ const { scene: n, camera: r, gl: c } = X(), { registerBackend: a, unregisterBackend: l } = P(), o = E(null), d = E(t);
242
+ return d.current = t, C(() => {
243
+ if (o.current) return;
244
+ let s = !1;
242
245
  return (async () => {
243
246
  try {
244
- const l = se(u.current);
245
- if (a) return;
246
- await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
247
- } catch (l) {
248
- console.error("[FiducialSession] Failed to initialize:", l);
247
+ const u = Pe(d.current);
248
+ if (s) return;
249
+ await a(u, { scene: n, camera: r, renderer: c }), o.current = u;
250
+ } catch (u) {
251
+ console.error("[FiducialSession] Failed to initialize:", u);
249
252
  }
250
253
  })(), () => {
251
- a = !0, s.current && (A(s.current), s.current = null);
254
+ s = !0, o.current && (l(o.current), o.current = null);
252
255
  };
253
- }, [t, r, c, i, A]), e;
254
- }, se = (n) => {
255
- let e = null, t = null, r = null, c;
256
+ }, [n, r, c, a, l]), e;
257
+ }, Pe = (t) => {
258
+ let e = null, n = null, r = null, c;
256
259
  return {
257
- type: p.FIDUCIAL,
258
- async init({ camera: i, renderer: A }) {
259
- e = new B({
260
- sourceType: n?.sourceType ?? "webcam"
261
- }), await new Promise((a, f) => {
262
- const l = setTimeout(() => {
260
+ type: b.FIDUCIAL,
261
+ async init({ camera: a, renderer: l }) {
262
+ e = new re({
263
+ sourceType: t?.sourceType ?? "webcam"
264
+ }), await new Promise((s, f) => {
265
+ const u = setTimeout(() => {
263
266
  f(new Error("AR source initialization timeout"));
264
267
  }, 1e4);
265
268
  e?.init(() => {
266
- clearTimeout(l);
267
- const o = e?.domElement;
268
- o && (o.style.position = "fixed", o.style.top = "0", o.style.left = "0", o.style.width = "100vw", o.style.height = "100vh", o.style.objectFit = "cover", o.style.zIndex = "-1", o.style.pointerEvents = "none"), a();
269
+ clearTimeout(u);
270
+ const i = e?.domElement;
271
+ i && (i.style.position = "fixed", i.style.top = "0", i.style.left = "0", i.style.width = "100vw", i.style.height = "100vh", i.style.objectFit = "cover", i.style.zIndex = "-1", i.style.pointerEvents = "none"), s();
269
272
  });
270
273
  });
271
- const s = {
272
- cameraParametersUrl: n?.cameraParametersUrl ?? // default to internal camera parameters
274
+ const o = {
275
+ cameraParametersUrl: t?.cameraParametersUrl ?? // default to internal camera parameters
273
276
  new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
274
- detectionMode: n?.detectionMode ?? "mono",
275
- patternRatio: n?.patternRatio ?? 0.5,
276
- matrixCodeType: n?.matrixCodeType ?? "3x3"
277
+ detectionMode: t?.detectionMode ?? "mono",
278
+ patternRatio: t?.patternRatio ?? 0.5,
279
+ matrixCodeType: t?.matrixCodeType ?? "3x3"
277
280
  };
278
- t = new N(s), r = i;
279
- const u = () => {
281
+ n = new oe(o), r = a;
282
+ const d = () => {
280
283
  e?.onResizeElement();
281
- const a = window.innerWidth, f = window.innerHeight;
282
- A.setSize(a, f, !1), e?.copyElementSizeTo(A.domElement), t?.arController && e?.copyElementSizeTo(t.arController.canvas);
284
+ const s = window.innerWidth, f = window.innerHeight;
285
+ l.setSize(s, f, !1), e?.copyElementSizeTo(l.domElement), n?.arController && e?.copyElementSizeTo(n.arController.canvas);
283
286
  };
284
- await new Promise((a, f) => {
285
- const l = setTimeout(() => {
287
+ await new Promise((s, f) => {
288
+ const u = setTimeout(() => {
286
289
  f(new Error("AR context initialization timeout"));
287
290
  }, 1e4);
288
- t?.init(() => {
289
- clearTimeout(l);
291
+ n?.init(() => {
292
+ clearTimeout(u);
290
293
  try {
291
- const o = t?.getProjectionMatrix();
292
- o && i.projectionMatrix.copy(o), u(), a();
293
- } catch (o) {
294
- f(o);
294
+ const i = n?.getProjectionMatrix();
295
+ i && a.projectionMatrix.copy(i), d(), s();
296
+ } catch (i) {
297
+ f(i);
295
298
  }
296
299
  });
297
- }), window.addEventListener("resize", u), c = u;
300
+ }), window.addEventListener("resize", d), c = d;
298
301
  },
299
302
  update() {
300
- if (!(!e || !t) && !(!e.ready || !e.domElement))
303
+ if (!(!e || !n) && !(!e.ready || !e.domElement))
301
304
  try {
302
- t.update(e.domElement);
303
- const i = t.getProjectionMatrix?.();
304
- r && i && r.projectionMatrix.copy(i);
305
- } catch (i) {
306
- console.warn("AR.js update error:", i);
305
+ n.update(e.domElement);
306
+ const a = n.getProjectionMatrix?.();
307
+ r && a && r.projectionMatrix.copy(a);
308
+ } catch (a) {
309
+ console.warn("AR.js update error:", a);
307
310
  }
308
311
  },
309
312
  dispose() {
310
- if (c && (window.removeEventListener("resize", c), c = void 0), t && typeof t.dispose == "function" && t.dispose(), e?.domElement) {
311
- const i = e.domElement.parentNode;
312
- i && i.removeChild(e.domElement);
313
+ if (c && (window.removeEventListener("resize", c), c = void 0), n && typeof n.dispose == "function" && n.dispose(), e?.domElement) {
314
+ const a = e.domElement.parentNode;
315
+ a && a.removeChild(e.domElement);
313
316
  }
314
- e = null, t = null, r = null;
317
+ e = null, n = null, r = null;
315
318
  },
316
319
  getInternal: () => ({
317
320
  arSource: e,
318
- arContext: t
321
+ arContext: n
319
322
  })
320
323
  };
321
- }, ce = {
324
+ }, ze = {
322
325
  isPending: !0,
323
326
  isSuccess: !1,
324
327
  locar: null,
@@ -333,204 +336,340 @@ const O = _()(
333
336
  },
334
337
  getAnchor: () => {
335
338
  }
336
- }, ie = () => {
337
- const e = I((t) => t.backends).get(p.GEOLOCATION);
339
+ }, q = () => {
340
+ const e = P((n) => n.backends).get(b.GEOLOCATION);
338
341
  return e ? {
339
342
  ...e.getInternal(),
340
343
  isPending: !1,
341
344
  isSuccess: !0
342
- } : ce;
343
- }, ye = ({
344
- latitude: n,
345
+ } : ze;
346
+ }, Ze = ({
347
+ coordinates: t,
348
+ color: e = "#ff0000",
349
+ isDashed: n = !1,
350
+ dashSize: r = 3,
351
+ gapSize: c = 1,
352
+ lineWidth: a = 1
353
+ }) => {
354
+ const l = q(), [o] = T(() => new W()), d = j(() => Math.random().toString(36).slice(2, 11), []), [s, f] = T(null);
355
+ return C(() => {
356
+ if (!l.isSuccess || t.length < 2) return;
357
+ const [u, i, A = 0] = t[0], g = (p) => {
358
+ const [w, v, m = 0] = t[0], [S, R] = p.lonLatToWorldCoords(
359
+ w,
360
+ v
361
+ ), y = t.map(([F, h, k = 0]) => {
362
+ const [M, x] = p.lonLatToWorldCoords(F, h);
363
+ return new se(M - S, k - m, x - R);
364
+ }), L = new fe().setFromPoints(y), z = new me({
365
+ color: e,
366
+ dashSize: r,
367
+ gapSize: c,
368
+ dashed: n,
369
+ worldUnits: !0,
370
+ linewidth: a
371
+ }), G = new Ae(L, z);
372
+ n && G.computeLineDistances(), f(G);
373
+ };
374
+ return l.registerAnchor(d, {
375
+ anchor: o,
376
+ isAttached: !1,
377
+ latitude: i,
378
+ longitude: u,
379
+ altitude: A,
380
+ onAttach: g
381
+ }), () => {
382
+ l.unregisterAnchor(d);
383
+ };
384
+ }, [
385
+ l.isSuccess,
386
+ l.registerAnchor,
387
+ l.unregisterAnchor,
388
+ d,
389
+ o,
390
+ t,
391
+ e,
392
+ n,
393
+ r,
394
+ c,
395
+ a
396
+ ]), U(
397
+ /* @__PURE__ */ I("group", { children: s && /* @__PURE__ */ I("primitive", { object: s }) }),
398
+ o
399
+ );
400
+ }, $e = ({
401
+ latitude: t,
345
402
  longitude: e,
346
- altitude: t = 0,
403
+ altitude: n = 0,
347
404
  isBillboard: r = !0,
348
405
  onAttach: c,
349
- onGpsUpdate: i,
350
- children: A
406
+ onGpsUpdate: a,
407
+ children: l
351
408
  }) => {
352
- const s = ie(), { camera: u } = v(), [a] = P(() => new D()), f = F(() => Math.random().toString(36).slice(2, 11), []), l = M(() => {
409
+ const o = q(), { camera: d } = X(), [s] = T(() => new W()), f = j(() => Math.random().toString(36).slice(2, 11), []), u = V(() => {
353
410
  c?.();
354
- }, [c]), o = M(
355
- (d, S) => {
356
- i?.(d, S);
411
+ }, [c]), i = V(
412
+ (A, g) => {
413
+ a?.(A, g);
357
414
  },
358
- [i]
415
+ [a]
359
416
  );
360
- return k(() => {
361
- if (s.isSuccess)
362
- return s.registerAnchor(f, {
363
- anchor: a,
417
+ return C(() => {
418
+ if (o.isSuccess)
419
+ return o.registerAnchor(f, {
420
+ anchor: s,
364
421
  isAttached: !1,
365
- latitude: n,
422
+ latitude: t,
366
423
  longitude: e,
367
- altitude: t,
368
- onAttach: l,
369
- onGpsUpdate: o
424
+ altitude: n,
425
+ onAttach: u,
426
+ onGpsUpdate: i
370
427
  }), () => {
371
- s.unregisterAnchor(f);
428
+ o.unregisterAnchor(f);
372
429
  };
373
430
  }, [
374
- s.isSuccess,
375
- s.registerAnchor,
376
- s.unregisterAnchor,
377
- a,
431
+ o.isSuccess,
432
+ o.registerAnchor,
433
+ o.unregisterAnchor,
434
+ s,
378
435
  f,
379
- n,
380
- e,
381
436
  t,
382
- l,
383
- o
384
- ]), R(() => {
385
- !r || !u || !s.isSuccess || !s.getAnchor(f)?.isAttached || a.lookAt(u.position);
386
- }), G(/* @__PURE__ */ C("group", { children: A }), a);
387
- }, ke = ({
388
- options: n = {},
437
+ e,
438
+ n,
439
+ u,
440
+ i
441
+ ]), N(() => {
442
+ !r || !d || !o.isSuccess || !o.getAnchor(f)?.isAttached || s.lookAt(d.position);
443
+ }), U(/* @__PURE__ */ I("group", { children: l }), s);
444
+ }, et = ({
445
+ options: t = {},
389
446
  children: e
390
447
  }) => {
391
- const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
392
- return u.current = n, k(() => {
393
- if (s.current) return;
394
- let a = !1;
448
+ const { scene: n, camera: r, gl: c } = X(), { registerBackend: a, unregisterBackend: l } = P(), o = E(null), d = E(t);
449
+ return d.current = t, C(() => {
450
+ if (o.current) return;
451
+ let s = !1;
395
452
  return (async () => {
396
453
  try {
397
- const l = ae(u.current);
398
- if (a) return;
399
- await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
400
- } catch (l) {
401
- console.error("[GeolocationSession] Failed to initialize:", l);
454
+ const u = Ge(d.current);
455
+ if (s) return;
456
+ await a(u, { scene: n, camera: r, renderer: c }), o.current = u;
457
+ } catch (u) {
458
+ console.error("[GeolocationSession] Failed to initialize:", u);
402
459
  }
403
460
  })(), () => {
404
- a = !0, s.current && (A(s.current), s.current = null);
461
+ s = !0, o.current && (l(o.current), o.current = null);
405
462
  };
406
- }, [t, r, c, i, A]), e;
407
- }, ae = (n) => {
408
- let e = null, t = null, r = null, c, i = null, A = null, s = null, u = null;
409
- const a = /* @__PURE__ */ new Map();
463
+ }, [n, r, c, a, l]), e;
464
+ }, je = {
465
+ front: ae,
466
+ back: ce,
467
+ double: ie
468
+ }, tt = ({
469
+ coordinates: t,
470
+ holes: e,
471
+ color: n = "#ff0000",
472
+ opacity: r = 1,
473
+ isWireframe: c = !1,
474
+ side: a = "double"
475
+ }) => {
476
+ const l = q(), [o] = T(() => new W()), d = j(() => Math.random().toString(36).slice(2, 11), []), [s, f] = T(null);
477
+ return C(() => {
478
+ if (!l.isSuccess || t.length < 3) return;
479
+ const [u, i, A = 0] = t[0], g = (p) => {
480
+ const [w, v, m = 0] = t[0], [S, R] = p.lonLatToWorldCoords(
481
+ w,
482
+ v
483
+ ), y = [];
484
+ for (const [h, k, M = 0] of t) {
485
+ const [x, B] = p.lonLatToWorldCoords(h, k);
486
+ y.push({
487
+ x: x - S,
488
+ z: B - R,
489
+ elev: M - m
490
+ });
491
+ }
492
+ const L = new le();
493
+ L.moveTo(y[0].x, y[0].z);
494
+ for (let h = 1; h < y.length; h++)
495
+ L.lineTo(y[h].x, y[h].z);
496
+ if (L.closePath(), e && e.length > 0)
497
+ for (const h of e) {
498
+ if (h.length < 3) continue;
499
+ const k = new ue(), [M, x] = h[0], [B, Z] = p.lonLatToWorldCoords(
500
+ M,
501
+ x
502
+ );
503
+ k.moveTo(B - S, Z - R);
504
+ for (let D = 1; D < h.length; D++) {
505
+ const [$, ee] = h[D], [te, ne] = p.lonLatToWorldCoords($, ee);
506
+ k.lineTo(te - S, ne - R);
507
+ }
508
+ k.closePath(), L.holes.push(k);
509
+ }
510
+ const z = new de(L), F = y.reduce((h, k) => h + k.elev, 0) / y.length;
511
+ z.rotateX(-Math.PI / 2), f({ geometry: z, avgElevation: F });
512
+ };
513
+ return l.registerAnchor(d, {
514
+ anchor: o,
515
+ isAttached: !1,
516
+ latitude: i,
517
+ longitude: u,
518
+ altitude: A,
519
+ onAttach: g
520
+ }), () => {
521
+ l.unregisterAnchor(d);
522
+ };
523
+ }, [
524
+ l.isSuccess,
525
+ l.registerAnchor,
526
+ l.unregisterAnchor,
527
+ d,
528
+ o,
529
+ t,
530
+ e
531
+ ]), U(
532
+ /* @__PURE__ */ I("group", { children: s && /* @__PURE__ */ I("group", { position: [0, s.avgElevation, 0], children: /* @__PURE__ */ I("mesh", { geometry: s.geometry, children: /* @__PURE__ */ I(
533
+ "meshBasicMaterial",
534
+ {
535
+ color: n,
536
+ opacity: r,
537
+ transparent: r < 1,
538
+ wireframe: c,
539
+ side: je[a]
540
+ }
541
+ ) }) }) }),
542
+ o
543
+ );
544
+ }, Ge = (t) => {
545
+ let e = null, n = null, r = null, c, a = null, l = null, o = null, d = null;
546
+ const s = /* @__PURE__ */ new Map();
410
547
  let f = null;
411
- const l = (o) => {
412
- if (!(!e || o.isAttached))
548
+ const u = (i) => {
549
+ if (!(!e || i.isAttached))
413
550
  try {
414
- e.add(o.anchor, o.longitude, o.latitude, o.altitude), o.isAttached = !0, o.onAttach?.();
415
- } catch (d) {
416
- console.error("❌ Failed to attach anchor:", d);
551
+ e.add(i.anchor, i.longitude, i.latitude, i.altitude), i.isAttached = !0, i.onAttach?.(e);
552
+ } catch (A) {
553
+ console.error("❌ Failed to attach anchor:", A);
417
554
  }
418
555
  };
419
556
  return {
420
- type: p.GEOLOCATION,
421
- async init(o) {
422
- const { camera: d, renderer: S, scene: h } = o;
423
- if (!h)
557
+ type: b.GEOLOCATION,
558
+ async init(i) {
559
+ const { camera: A, renderer: g, scene: p } = i;
560
+ if (!p)
424
561
  throw new Error(
425
562
  "[geolocationBackend] A THREE.Scene is required for location-based AR"
426
563
  );
427
- A = d, s = S, u = h, e = new U(h, d), t = new X(
428
- n?.webcamConstraints ?? {
564
+ l = A, o = g, d = p, e = new ge(p, A), n = new he(
565
+ t?.webcamConstraints ?? {
429
566
  video: { facingMode: "environment" }
430
567
  // TODO remove `as any` once fixed upstream (LocAR.js)
431
568
  }
432
- ), i = (m) => {
569
+ ), a = (m) => {
433
570
  f = m.position;
434
- for (const w of a.values())
435
- w.isAttached || l(w), w.onGpsUpdate?.(m.position, m.distMoved);
436
- n?.onGpsUpdate?.(m.position, m.distMoved);
437
- }, e.on("gpsupdate", i), t.on("webcamstarted", (m) => {
438
- h.background = m.texture;
439
- }), t.on("webcamerror", (m) => {
571
+ for (const S of s.values())
572
+ S.isAttached || u(S), S.onGpsUpdate?.(m.position, m.distMoved);
573
+ t?.onGpsUpdate?.(m.position, m.distMoved);
574
+ }, e.on("gpsupdate", a), n.on("webcamstarted", (m) => {
575
+ p.background = m.texture;
576
+ }), n.on("webcamerror", (m) => {
440
577
  console.error("[geolocationBackend] webcam error:", m);
441
- }), r = new H(d), r.on("deviceorientationgranted", (m) => {
578
+ }), r = new pe(A), r.on("deviceorientationgranted", (m) => {
442
579
  m.target?.connect?.();
443
580
  }), r.on("deviceorientationerror", (m) => {
444
581
  console.error("[geolocationBackend] Device orientation error:", m);
445
582
  }), r.init?.(), e.on("gpserror", (m) => {
446
583
  console.error("[geolocationBackend] gps error:", m);
447
- }), e.startGps(), typeof n?.fakeLat == "number" && typeof n?.fakeLon == "number" && e.fakeGps(n.fakeLon, n.fakeLat);
448
- const g = e.getLastKnownLocation();
449
- g !== null && (f = {
584
+ }), e.startGps(), typeof t?.fakeLat == "number" && typeof t?.fakeLon == "number" && e.fakeGps(t.fakeLon, t.fakeLat);
585
+ const w = e.getLastKnownLocation();
586
+ w !== null && (f = {
450
587
  coords: {
451
- longitude: g.longitude,
452
- latitude: g.latitude,
588
+ longitude: w.longitude,
589
+ latitude: w.latitude,
453
590
  accuracy: 0,
454
591
  altitude: null,
455
592
  altitudeAccuracy: null,
456
593
  heading: null,
457
594
  speed: null,
458
- toJSON: () => g
595
+ toJSON: () => w
459
596
  },
460
597
  timestamp: Date.now(),
461
- toJSON: () => g
598
+ toJSON: () => w
462
599
  });
463
- const E = () => {
464
- if (!s || !A) return;
465
- const m = window.innerWidth, w = window.innerHeight;
466
- s.setSize(m, w, !1), A.aspect = m / w, A.updateProjectionMatrix?.();
600
+ const v = () => {
601
+ if (!o || !l) return;
602
+ const m = window.innerWidth, S = window.innerHeight;
603
+ o.setSize(m, S, !1), l.aspect = m / S, l.updateProjectionMatrix?.();
467
604
  };
468
- E(), window.addEventListener("resize", E), c = E;
605
+ v(), window.addEventListener("resize", v), c = v;
469
606
  },
470
607
  update() {
471
608
  r?.update?.();
472
609
  },
473
610
  dispose() {
474
- e && i && e.off("gpsupdate", i), e?.stopGps?.(), t?.stop?.(), r?.dispose?.(), c && (window.removeEventListener("resize", c), c = void 0);
475
- for (const o of a.values())
476
- if (o.isAttached)
611
+ e && a && e.off("gpsupdate", a), e?.stopGps?.(), n?.stop?.(), r?.dispose?.(), c && (window.removeEventListener("resize", c), c = void 0);
612
+ for (const i of s.values())
613
+ if (i.isAttached)
477
614
  try {
478
- o.anchor.removeFromParent();
479
- } catch (d) {
480
- console.error("⚠️ Error removing anchor:", d);
615
+ i.anchor.removeFromParent();
616
+ } catch (A) {
617
+ console.error("⚠️ Error removing anchor:", A);
481
618
  }
482
- a.clear(), e = null, t = null, r = null, A = null, s = null, u = null, i = null, f = null;
619
+ s.clear(), e = null, n = null, r = null, l = null, o = null, d = null, a = null, f = null;
483
620
  },
484
621
  getInternal: () => ({
485
622
  locar: e,
486
- webcam: t,
623
+ webcam: n,
487
624
  deviceOrientation: r,
488
- scene: u,
489
- camera: A,
625
+ scene: d,
626
+ camera: l,
490
627
  lastPosition: f,
491
- registerAnchor: (o, d) => {
492
- a.set(o, d), f !== null && !d.isAttached && (l(d), d.onGpsUpdate?.(f, 0));
628
+ registerAnchor: (i, A) => {
629
+ s.set(i, A), f !== null && !A.isAttached && (u(A), A.onGpsUpdate?.(f, 0));
493
630
  },
494
- unregisterAnchor: (o) => {
495
- const d = a.get(o);
496
- if (d?.isAttached)
631
+ unregisterAnchor: (i) => {
632
+ const A = s.get(i);
633
+ if (A?.isAttached)
497
634
  try {
498
- d.anchor.removeFromParent();
499
- } catch (S) {
500
- console.error(`⚠️ Error removing anchor ${o}:`, S);
635
+ A.anchor.removeFromParent();
636
+ } catch (g) {
637
+ console.error(`⚠️ Error removing anchor ${i}:`, g);
501
638
  }
502
- a.delete(o);
639
+ s.delete(i);
503
640
  },
504
- getAnchor: (o) => a.get(o)
641
+ getAnchor: (i) => s.get(i)
505
642
  })
506
643
  };
507
- }, le = () => ({
508
- type: p.IMMERSIVE,
644
+ }, Fe = () => ({
645
+ type: b.IMMERSIVE,
509
646
  init: () => {
510
647
  },
511
648
  getInternal: () => null
512
- }), Ie = ({ children: n }) => {
513
- const e = F(() => W(), []);
514
- return k(() => {
515
- const t = ne(), r = le();
516
- return t.backends.set(p.IMMERSIVE, r), t.setImmersiveStore(e), () => {
517
- t.backends.delete(p.IMMERSIVE), t.setImmersiveStore(null);
649
+ }), nt = ({ children: t }) => {
650
+ const e = j(() => Se(), []);
651
+ return C(() => {
652
+ const n = xe(), r = Fe();
653
+ return n.backends.set(b.IMMERSIVE, r), n.setImmersiveStore(e), () => {
654
+ n.backends.delete(b.IMMERSIVE), n.setImmersiveStore(null);
518
655
  };
519
- }, [e]), /* @__PURE__ */ C(q, { store: e, children: n });
656
+ }, [e]), /* @__PURE__ */ I(be, { store: e, children: t });
520
657
  };
521
658
  export {
522
- p as BACKEND_TYPES,
523
- he as FiducialAnchor,
524
- we as FiducialSession,
525
- ye as GeolocationAnchor,
526
- ke as GeolocationSession,
527
- Ie as ImmersiveSession,
528
- ge as XR,
529
- se as createFiducialBackend,
530
- ae as createGeolocationBackend,
531
- ne as getXRStore,
532
- be as subscribeToXRStore,
533
- oe as useFiducialBackend,
534
- ie as useGeolocationBackend,
535
- I as useXRStore
659
+ b as BACKEND_TYPES,
660
+ Ye as FiducialAnchor,
661
+ Je as FiducialSession,
662
+ Ze as GeoLine,
663
+ tt as GeoPolygon,
664
+ $e as GeolocationAnchor,
665
+ et as GeolocationSession,
666
+ nt as ImmersiveSession,
667
+ Qe as XR,
668
+ Pe as createFiducialBackend,
669
+ Ge as createGeolocationBackend,
670
+ xe as getXRStore,
671
+ _e as subscribeToXRStore,
672
+ Te as useFiducialBackend,
673
+ q as useGeolocationBackend,
674
+ P as useXRStore
536
675
  };
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.7.0",
4
+ "version": "0.8.0",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "build/index.js",