@omnidotdev/rdk 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/fiducial/FiducialAnchor.d.ts.map +1 -1
- package/build/fiducial/fiducialBackend.d.ts +9 -0
- package/build/fiducial/fiducialBackend.d.ts.map +1 -1
- package/build/fiducial/index.d.ts +1 -1
- package/build/fiducial/index.d.ts.map +1 -1
- package/build/fiducial/useFiducialBackend.d.ts +8 -5
- package/build/fiducial/useFiducialBackend.d.ts.map +1 -1
- package/build/geolocation/GeolocationAnchor.d.ts.map +1 -1
- package/build/geolocation/geolocationBackend.d.ts +9 -0
- package/build/geolocation/geolocationBackend.d.ts.map +1 -1
- package/build/geolocation/index.d.ts +1 -1
- package/build/geolocation/index.d.ts.map +1 -1
- package/build/geolocation/useGeolocationBackend.d.ts +8 -5
- package/build/geolocation/useGeolocationBackend.d.ts.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.js +182 -139
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiducialAnchor.d.ts","sourceRoot":"","sources":["../../src/fiducial/FiducialAnchor.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D,mBAAmB;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;GAEG;AACH,QAAA,MAAM,cAAc,GAAI,8EAOrB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"FiducialAnchor.d.ts","sourceRoot":"","sources":["../../src/fiducial/FiducialAnchor.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D,mBAAmB;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;GAEG;AACH,QAAA,MAAM,cAAc,GAAI,8EAOrB,mBAAmB,4CA4HrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -7,6 +7,15 @@ export interface FiducialInternal {
|
|
|
7
7
|
arSource: ArToolkitSource | null;
|
|
8
8
|
arContext: ArToolkitContext | null;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* State returned by fiducial backend hook.
|
|
12
|
+
*/
|
|
13
|
+
export interface FiducialBackendState extends FiducialInternal {
|
|
14
|
+
/** Whether the backend is still initializing (not yet ready). */
|
|
15
|
+
isPending: boolean;
|
|
16
|
+
/** Whether the backend is initialized and ready to use. */
|
|
17
|
+
isSuccess: boolean;
|
|
18
|
+
}
|
|
10
19
|
export interface FiducialSessionOptions {
|
|
11
20
|
/** Input source type. */
|
|
12
21
|
sourceType?: "webcam" | "image" | "video";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fiducialBackend.d.ts","sourceRoot":"","sources":["../../src/fiducial/fiducialBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,2CAA2C,CAAC;AAInD,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC,yBAAyB;IACzB,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IAC1C,6BAA6B;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB;IACtB,aAAa,CAAC,EAAE,OAAO,GAAG,kBAAkB,GAAG,MAAM,GAAG,iBAAiB,CAAC;IAC1E,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,cAAc,CAAC,EACX,KAAK,GACL,eAAe,GACf,cAAc,GACd,KAAK,GACL,gBAAgB,GAChB,gBAAgB,CAAC;CACtB;AAED;;GAEG;AACH,QAAA,MAAM,qBAAqB,GACzB,UAAU,sBAAsB,KAC/B,OAAO,CAAC,gBAAgB,CA+I1B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"fiducialBackend.d.ts","sourceRoot":"","sources":["../../src/fiducial/fiducialBackend.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,2CAA2C,CAAC;AAInD,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,iEAAiE;IACjE,SAAS,EAAE,OAAO,CAAC;IACnB,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,yBAAyB;IACzB,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IAC1C,6BAA6B;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB;IACtB,aAAa,CAAC,EAAE,OAAO,GAAG,kBAAkB,GAAG,MAAM,GAAG,iBAAiB,CAAC;IAC1E,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,cAAc,CAAC,EACX,KAAK,GACL,eAAe,GACf,cAAc,GACd,KAAK,GACL,gBAAgB,GAChB,gBAAgB,CAAC;CACtB;AAED;;GAEG;AACH,QAAA,MAAM,qBAAqB,GACzB,UAAU,sBAAsB,KAC/B,OAAO,CAAC,gBAAgB,CA+I1B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -4,5 +4,5 @@ export { default as createFiducialBackend } from './fiducialBackend';
|
|
|
4
4
|
export { default as useFiducialBackend } from './useFiducialBackend';
|
|
5
5
|
export type { FiducialAnchorProps } from './FiducialAnchor';
|
|
6
6
|
export type { FiducialSessionProps } from './FiducialSession';
|
|
7
|
-
export type { FiducialInternal, FiducialSessionOptions, } from './fiducialBackend';
|
|
7
|
+
export type { FiducialBackendState, FiducialInternal, FiducialSessionOptions, } from './fiducialBackend';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fiducial/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAErE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EACV,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fiducial/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAErE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FiducialBackendState } from './fiducialBackend';
|
|
2
2
|
/**
|
|
3
3
|
* Access the fiducial backend internals.
|
|
4
|
-
* @returns fiducial backend
|
|
4
|
+
* @returns fiducial backend state. `isSuccess` can be checked to verify readiness.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```tsx
|
|
8
|
-
* const
|
|
9
|
-
*
|
|
8
|
+
* const { arContext, isSuccess } = useFiducialBackend();
|
|
9
|
+
*
|
|
10
|
+
* if (isSuccess && arContext) {
|
|
11
|
+
* // use `arContext`
|
|
12
|
+
* }
|
|
10
13
|
* ```
|
|
11
14
|
*/
|
|
12
|
-
declare const useFiducialBackend: () =>
|
|
15
|
+
declare const useFiducialBackend: () => FiducialBackendState;
|
|
13
16
|
export default useFiducialBackend;
|
|
14
17
|
//# sourceMappingURL=useFiducialBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFiducialBackend.d.ts","sourceRoot":"","sources":["../../src/fiducial/useFiducialBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useFiducialBackend.d.ts","sourceRoot":"","sources":["../../src/fiducial/useFiducialBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAoB,MAAM,mBAAmB,CAAC;AAYhF;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,kBAAkB,QAAO,oBAc9B,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeolocationAnchor.d.ts","sourceRoot":"","sources":["../../src/geolocation/GeolocationAnchor.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,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":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,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,gCA4DxB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -38,6 +38,15 @@ export interface GeolocationInternal {
|
|
|
38
38
|
/** Get an anchor entry by ID. */
|
|
39
39
|
getAnchor: (id: string) => AnchorEntry | undefined;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* State returned by geolocation backend hook.
|
|
43
|
+
*/
|
|
44
|
+
export interface GeolocationBackendState extends GeolocationInternal {
|
|
45
|
+
/** Whether the backend is still initializing (not yet ready). */
|
|
46
|
+
isPending: boolean;
|
|
47
|
+
/** Whether the backend is initialized and ready to use. */
|
|
48
|
+
isSuccess: boolean;
|
|
49
|
+
}
|
|
41
50
|
/**
|
|
42
51
|
* Options for the geolocation backend.
|
|
43
52
|
*/
|
|
@@ -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,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,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"}
|
|
@@ -4,5 +4,5 @@ export { default as createGeolocationBackend } from './geolocationBackend';
|
|
|
4
4
|
export { default as useGeolocationBackend } from './useGeolocationBackend';
|
|
5
5
|
export type { GeolocationAnchorProps } from './GeolocationAnchor';
|
|
6
6
|
export type { GeolocationSessionProps } from './GeolocationSession';
|
|
7
|
-
export type { AnchorEntry, GeolocationInternal, GeolocationSessionOptions, GpsUpdateEvent, } from './geolocationBackend';
|
|
7
|
+
export type { AnchorEntry, GeolocationBackendState, GeolocationInternal, GeolocationSessionOptions, GpsUpdateEvent, } from './geolocationBackend';
|
|
8
8
|
//# 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,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,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,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeolocationBackendState } from './geolocationBackend';
|
|
2
2
|
/**
|
|
3
3
|
* Access the geolocation backend internals.
|
|
4
|
-
* @returns geolocation backend
|
|
4
|
+
* @returns geolocation backend state. `isSuccess` can be checked to verify readiness.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```tsx
|
|
8
|
-
* const
|
|
9
|
-
*
|
|
8
|
+
* const { locar, isSuccess } = useGeolocationBackend();
|
|
9
|
+
*
|
|
10
|
+
* if (isSuccess && locar) {
|
|
11
|
+
* const worldCoords = locar.lonLatToWorldCoords(lon, lat);
|
|
12
|
+
* }
|
|
10
13
|
* ```
|
|
11
14
|
*/
|
|
12
|
-
declare const useGeolocationBackend: () =>
|
|
15
|
+
declare const useGeolocationBackend: () => GeolocationBackendState;
|
|
13
16
|
export default useGeolocationBackend;
|
|
14
17
|
//# sourceMappingURL=useGeolocationBackend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGeolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/useGeolocationBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useGeolocationBackend.d.ts","sourceRoot":"","sources":["../../src/geolocation/useGeolocationBackend.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,sBAAsB,CAAC;AAmB9B;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,qBAAqB,QAAO,uBAcjC,CAAC;AAEF,eAAe,qBAAqB,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"),C=require("react/jsx-runtime"),I=require("@ar-js-org/ar.js/three.js/build/ar-threex"),q=require("three"),E=require("locar"),x=require("@react-three/xr");var v=typeof document<"u"?document.currentScript:null;const p={FIDUCIAL:"fiducial",GEOLOCATION:"geolocation",IMMERSIVE:"immersive"},O=n=>{let e;const t=new Set,r=(i,f)=>{const l=typeof i=="function"?i(e):i;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,a={setState:r,getState:c,getInitialState:()=>u,subscribe:i=>(t.add(i),()=>t.delete(i))},u=e=n(r,c,a);return a},D=(n=>n?O(n):O),N=n=>n;function U(n,e=N){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=>U(e,r);return Object.assign(t,e),t},H=(n=>X),W=n=>(e,t,r)=>{const c=r.subscribe;return r.subscribe=((A,a,u)=>{let i=A;if(a){const f=u?.equalityFn||Object.is;let l=A(r.getState());i=o=>{const d=A(o);if(!f(l,d)){const S=l;a(l=d,S)}},u?.fireImmediately&&a(l,l)}return c(i)}),n(e,t,r)},K=W,T=n=>Symbol.iterator in n,j=n=>"entries"in n,F=(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,s]of t)if(!r.has(c)||!Object.is(s,r.get(c)))return!1;return!0},V=(n,e)=>{const t=n[Symbol.iterator](),r=e[Symbol.iterator]();let c=t.next(),s=r.next();for(;!c.done&&!s.done;){if(!Object.is(c.value,s.value))return!1;c=t.next(),s=r.next()}return!!c.done&&!!s.done};function Y(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)?j(n)&&j(e)?F(n,e):V(n,e):F({entries:()=>Object.entries(n)},{entries:()=>Object.entries(e)})}function Q(n){const e=m.useRef(void 0);return t=>{const r=n(t);return Y(e.current,r)?e.current:e.current=r}}const M=H()(K((n,e)=>({video:null,backends:new Map,immersiveStore:null,registerBackend:async(t,r)=>{try{const c=e(),s=new Set(c.backends.keys()),A=s.has(p.FIDUCIAL)||t.type===p.FIDUCIAL,a=s.has(p.GEOLOCATION)||t.type===p.GEOLOCATION;if(A&&a){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 i=new Map(u.backends);return i.set(t.type,t),{backends:i}})}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(s){console.error("[XRStore] Error disposing backend:",s)}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(s){console.error("[XRStore] Backend update error:",s)}},setImmersiveStore:t=>{n({immersiveStore:t})}}))),L=()=>M.getState(),_=M.subscribe,y=n=>M(Q(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}=y();return h.useFrame((t,r)=>{e(r)}),n},B=()=>y(t=>t.backends).get(p.FIDUCIAL)?.getInternal()??null,$=({patternUrl:n,barcodeValue:e,params:t,onMarkerFound:r,onMarkerLost:c,children:s})=>{const A=m.useRef(null),a=B(),u=m.useRef(!1),i=m.useRef(!1),f=m.useRef(null);return m.useEffect(()=>{if(!a)return;let l=!1;return(()=>{try{const{arContext:d}=a,S=A.current;if(!d||!S||l)return;if(S.visible=!1,i.current=!1,!d.arController){requestAnimationFrame(()=>{if(!A.current||l||!a.arContext?.arController)return;const g=new I.ArMarkerControls(a.arContext,A.current,{type:n?"pattern":e?"barcode":"unknown",patternUrl:n,barcodeValue:e,...t});f.current=g,i.current=!0});return}const w=new I.ArMarkerControls(d,S,{type:n?"pattern":e?"barcode":"unknown",patternUrl:n,barcodeValue:e,...t});f.current=w,i.current=!0}catch(d){console.error("Failed to initialize fiducial anchor:",d)}})(),()=>{l=!0;const d=f.current;typeof d?.dispose=="function"&&d.dispose(),i.current=!1}},[a,n,e,t]),h.useFrame(()=>{const l=A.current;if(!l||!i.current){l&&(l.visible=!1);return}const o=l.visible;o&&!u.current?(u.current=!0,r?.()):!o&&u.current&&(u.current=!1,c?.())}),C.jsx("group",{ref:A,visible:!1,children:s})},Z=({options:n={},children:e})=>{const{scene:t,camera:r,gl:c}=h.useThree(),{registerBackend:s,unregisterBackend:A}=y(),a=m.useRef(null),u=m.useRef(n);return u.current=n,m.useEffect(()=>{if(a.current)return;let i=!1;return(async()=>{try{const l=z(u.current);if(i)return;await s(l,{scene:t,camera:r,renderer:c}),a.current=l}catch(l){console.error("[FiducialSession] Failed to initialize:",l)}})(),()=>{i=!0,a.current&&(A(a.current),a.current=null)}},[t,r,c,s,A]),e},z=n=>{let e=null,t=null,r=null,c;return{type:p.FIDUCIAL,async init({camera:s,renderer:A}){e=new I.ArToolkitSource({sourceType:n?.sourceType??"webcam"}),await new Promise((i,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"),i()})});const a={cameraParametersUrl:n?.cameraParametersUrl??new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=",typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.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(a),r=s;const u=()=>{e?.onResizeElement();const i=window.innerWidth,f=window.innerHeight;A.setSize(i,f,!1),e?.copyElementSizeTo(A.domElement),t?.arController&&e?.copyElementSizeTo(t.arController.canvas)};await new Promise((i,f)=>{const l=setTimeout(()=>{f(new Error("AR context initialization timeout"))},1e4);t?.init(()=>{clearTimeout(l);try{const o=t?.getProjectionMatrix();o&&s.projectionMatrix.copy(o),u(),i()}catch(o){f(o)}})}),window.addEventListener("resize",u),c=u},update(){if(!(!e||!t)&&!(!e.ready||!e.domElement))try{t.update(e.domElement);const s=t.getProjectionMatrix?.();r&&s&&r.projectionMatrix.copy(s)}catch(s){console.warn("AR.js update error:",s)}},dispose(){if(c&&(window.removeEventListener("resize",c),c=void 0),t&&typeof t.dispose=="function"&&t.dispose(),e?.domElement){const s=e.domElement.parentNode;s&&s.removeChild(e.domElement)}e=null,t=null,r=null},getInternal:()=>({arSource:e,arContext:t})}},G=()=>y(t=>t.backends).get(p.GEOLOCATION)?.getInternal()??null,ee=({latitude:n,longitude:e,altitude:t=0,isBillboard:r=!0,onAttach:c,onGpsUpdate:s,children:A})=>{const a=G(),{camera:u}=h.useThree(),[i]=m.useState(()=>new q.Group),f=m.useMemo(()=>Math.random().toString(36).slice(2,11),[]),l=m.useCallback(()=>{c?.()},[c]),o=m.useCallback((d,S)=>{s?.(d,S)},[s]);return m.useEffect(()=>{if(a)return a.registerAnchor(f,{anchor:i,isAttached:!1,latitude:n,longitude:e,altitude:t,onAttach:l,onGpsUpdate:o}),()=>{a.unregisterAnchor(f)}},[a,i,f,n,e,t,l,o]),h.useFrame(()=>{!r||!u||!a||!a.getAnchor(f)?.isAttached||i.lookAt(u.position)}),h.createPortal(C.jsx("group",{children:A}),i)},te=({options:n={},children:e})=>{const{scene:t,camera:r,gl:c}=h.useThree(),{registerBackend:s,unregisterBackend:A}=y(),a=m.useRef(null),u=m.useRef(n);return u.current=n,m.useEffect(()=>{if(a.current)return;let i=!1;return(async()=>{try{const l=P(u.current);if(i)return;await s(l,{scene:t,camera:r,renderer:c}),a.current=l}catch(l){console.error("[GeolocationSession] Failed to initialize:",l)}})(),()=>{i=!0,a.current&&(A(a.current),a.current=null)}},[t,r,c,s,A]),e},P=n=>{let e=null,t=null,r=null,c,s=null,A=null,a=null,u=null;const i=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:S,scene:w}=o;if(!w)throw new Error("[geolocationBackend] A THREE.Scene is required for location-based AR");A=d,a=S,u=w,e=new E.LocationBased(w,d),t=new E.Webcam(n?.webcamConstraints??{video:{facingMode:"environment"}}),s=b=>{f=b.position;for(const k of i.values())k.isAttached||l(k),k.onGpsUpdate?.(b.position,b.distMoved);n?.onGpsUpdate?.(b.position,b.distMoved)},e.on("gpsupdate",s),t.on("webcamstarted",b=>{w.background=b.texture}),t.on("webcamerror",b=>{console.error("[geolocationBackend] webcam error:",b)}),r=new E.DeviceOrientationControls(d),r.on("deviceorientationgranted",b=>{b.target?.connect?.()}),r.on("deviceorientationerror",b=>{console.error("[geolocationBackend] Device orientation error:",b)}),r.init?.(),e.on("gpserror",b=>{console.error("[geolocationBackend] gps error:",b)}),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 R=()=>{if(!a||!A)return;const b=window.innerWidth,k=window.innerHeight;a.setSize(b,k,!1),A.aspect=b/k,A.updateProjectionMatrix?.()};R(),window.addEventListener("resize",R),c=R},update(){r?.update?.()},dispose(){e&&s&&e.off("gpsupdate",s),e?.stopGps?.(),t?.stop?.(),r?.dispose?.(),c&&(window.removeEventListener("resize",c),c=void 0);for(const o of i.values())if(o.isAttached)try{o.anchor.removeFromParent()}catch(d){console.error("⚠️ Error removing anchor:",d)}i.clear(),e=null,t=null,r=null,A=null,a=null,u=null,s=null,f=null},getInternal:()=>({locar:e,webcam:t,deviceOrientation:r,scene:u,camera:A,lastPosition:f,registerAnchor:(o,d)=>{i.set(o,d),f!==null&&!d.isAttached&&(l(d),d.onGpsUpdate?.(f,0))},unregisterAnchor:o=>{const d=i.get(o);if(d?.isAttached)try{d.anchor.removeFromParent()}catch(S){console.error(`⚠️ Error removing anchor ${o}:`,S)}i.delete(o)},getAnchor:o=>i.get(o)})}},ne=()=>({type:p.IMMERSIVE,init:()=>{},getInternal:()=>null}),re=({children:n})=>{const e=m.useMemo(()=>x.createXRStore(),[]);return m.useEffect(()=>{const t=L(),r=ne();return t.backends.set(p.IMMERSIVE,r),t.setImmersiveStore(e),()=>{t.backends.delete(p.IMMERSIVE),t.setImmersiveStore(null)}},[e]),C.jsx(x.XR,{store:e,children:n})};exports.BACKEND_TYPES=p;exports.FiducialAnchor=$;exports.FiducialSession=Z;exports.GeolocationAnchor=ee;exports.GeolocationSession=te;exports.ImmersiveSession=re;exports.XR=J;exports.createFiducialBackend=z;exports.createGeolocationBackend=P;exports.getXRStore=L;exports.subscribeToXRStore=_;exports.useFiducialBackend=B;exports.useGeolocationBackend=G;exports.useXRStore=y;
|
|
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;
|
package/build/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import y, { useRef as
|
|
1
|
+
import y, { useRef as b, useEffect as k, useState as P, useMemo as F, useCallback as M } from "react";
|
|
2
2
|
import { useFrame as R, useThree as v, createPortal as G } from "@react-three/fiber";
|
|
3
3
|
import { jsx as C } from "react/jsx-runtime";
|
|
4
|
-
import { ArMarkerControls as x, ArToolkitSource as
|
|
5
|
-
import { Group as
|
|
6
|
-
import { LocationBased as
|
|
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
7
|
import { createXRStore as W, XR as q } from "@react-three/xr";
|
|
8
8
|
const p = {
|
|
9
9
|
FIDUCIAL: "fiducial",
|
|
@@ -11,14 +11,14 @@ const p = {
|
|
|
11
11
|
IMMERSIVE: "immersive"
|
|
12
12
|
}, L = (n) => {
|
|
13
13
|
let e;
|
|
14
|
-
const t = /* @__PURE__ */ new Set(), r = (
|
|
15
|
-
const l = typeof
|
|
14
|
+
const t = /* @__PURE__ */ new Set(), r = (a, f) => {
|
|
15
|
+
const l = typeof a == "function" ? a(e) : a;
|
|
16
16
|
if (!Object.is(l, e)) {
|
|
17
17
|
const o = e;
|
|
18
18
|
e = f ?? (typeof l != "object" || l === null) ? l : Object.assign({}, e, l), t.forEach((d) => d(e, o));
|
|
19
19
|
}
|
|
20
|
-
}, c = () => e,
|
|
21
|
-
return
|
|
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
22
|
}, K = ((n) => n ? L(n) : L), V = (n) => n;
|
|
23
23
|
function Q(n, e = V) {
|
|
24
24
|
const t = y.useSyncExternalStore(
|
|
@@ -31,46 +31,46 @@ function Q(n, e = V) {
|
|
|
31
31
|
const Y = (n) => {
|
|
32
32
|
const e = K(n), t = (r) => Q(e, r);
|
|
33
33
|
return Object.assign(t, e), t;
|
|
34
|
-
},
|
|
34
|
+
}, _ = ((n) => Y), J = (n) => (e, t, r) => {
|
|
35
35
|
const c = r.subscribe;
|
|
36
|
-
return r.subscribe = ((A,
|
|
37
|
-
let
|
|
38
|
-
if (
|
|
36
|
+
return r.subscribe = ((A, s, u) => {
|
|
37
|
+
let a = A;
|
|
38
|
+
if (s) {
|
|
39
39
|
const f = u?.equalityFn || Object.is;
|
|
40
40
|
let l = A(r.getState());
|
|
41
|
-
|
|
41
|
+
a = (o) => {
|
|
42
42
|
const d = A(o);
|
|
43
43
|
if (!f(l, d)) {
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const S = l;
|
|
45
|
+
s(l = d, S);
|
|
46
46
|
}
|
|
47
|
-
}, u?.fireImmediately &&
|
|
47
|
+
}, u?.fireImmediately && s(l, l);
|
|
48
48
|
}
|
|
49
|
-
return c(
|
|
49
|
+
return c(a);
|
|
50
50
|
}), n(e, t, r);
|
|
51
|
-
},
|
|
51
|
+
}, $ = J, T = (n) => Symbol.iterator in n, j = (n) => (
|
|
52
52
|
// HACK: avoid checking entries type
|
|
53
53
|
"entries" in n
|
|
54
|
-
),
|
|
54
|
+
), z = (n, e) => {
|
|
55
55
|
const t = n instanceof Map ? n : new Map(n.entries()), r = e instanceof Map ? e : new Map(e.entries());
|
|
56
56
|
if (t.size !== r.size)
|
|
57
57
|
return !1;
|
|
58
|
-
for (const [c,
|
|
59
|
-
if (!r.has(c) || !Object.is(
|
|
58
|
+
for (const [c, i] of t)
|
|
59
|
+
if (!r.has(c) || !Object.is(i, r.get(c)))
|
|
60
60
|
return !1;
|
|
61
61
|
return !0;
|
|
62
|
-
},
|
|
62
|
+
}, Z = (n, e) => {
|
|
63
63
|
const t = n[Symbol.iterator](), r = e[Symbol.iterator]();
|
|
64
|
-
let c = t.next(),
|
|
65
|
-
for (; !c.done && !
|
|
66
|
-
if (!Object.is(c.value,
|
|
64
|
+
let c = t.next(), i = r.next();
|
|
65
|
+
for (; !c.done && !i.done; ) {
|
|
66
|
+
if (!Object.is(c.value, i.value))
|
|
67
67
|
return !1;
|
|
68
|
-
c = t.next(),
|
|
68
|
+
c = t.next(), i = r.next();
|
|
69
69
|
}
|
|
70
|
-
return !!c.done && !!
|
|
70
|
+
return !!c.done && !!i.done;
|
|
71
71
|
};
|
|
72
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 :
|
|
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
74
|
{ entries: () => Object.entries(n) },
|
|
75
75
|
{ entries: () => Object.entries(e) }
|
|
76
76
|
);
|
|
@@ -82,8 +82,8 @@ function te(n) {
|
|
|
82
82
|
return ee(e.current, r) ? e.current : e.current = r;
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
85
|
+
const O = _()(
|
|
86
|
+
$((n, e) => ({
|
|
87
87
|
// initial state
|
|
88
88
|
video: null,
|
|
89
89
|
backends: /* @__PURE__ */ new Map(),
|
|
@@ -91,8 +91,8 @@ const M = J()(
|
|
|
91
91
|
// actions
|
|
92
92
|
registerBackend: async (t, r) => {
|
|
93
93
|
try {
|
|
94
|
-
const c = e(),
|
|
95
|
-
if (A &&
|
|
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
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
97
|
throw console.error(u), new Error(u);
|
|
98
98
|
}
|
|
@@ -101,8 +101,8 @@ const M = J()(
|
|
|
101
101
|
camera: r.camera,
|
|
102
102
|
renderer: r.renderer
|
|
103
103
|
}), n((u) => {
|
|
104
|
-
const
|
|
105
|
-
return
|
|
104
|
+
const a = new Map(u.backends);
|
|
105
|
+
return a.set(t.type, t), { backends: a };
|
|
106
106
|
});
|
|
107
107
|
} catch (c) {
|
|
108
108
|
throw console.error("[XRStore] Failed to register backend:", c), c;
|
|
@@ -114,8 +114,8 @@ const M = J()(
|
|
|
114
114
|
c.delete(t.type);
|
|
115
115
|
try {
|
|
116
116
|
t.dispose?.();
|
|
117
|
-
} catch (
|
|
118
|
-
console.error("[XRStore] Error disposing backend:",
|
|
117
|
+
} catch (i) {
|
|
118
|
+
console.error("[XRStore] Error disposing backend:", i);
|
|
119
119
|
}
|
|
120
120
|
return { backends: c };
|
|
121
121
|
});
|
|
@@ -128,15 +128,15 @@ const M = J()(
|
|
|
128
128
|
for (const c of r.values())
|
|
129
129
|
try {
|
|
130
130
|
c.update?.(t);
|
|
131
|
-
} catch (
|
|
132
|
-
console.error("[XRStore] Backend update error:",
|
|
131
|
+
} catch (i) {
|
|
132
|
+
console.error("[XRStore] Backend update error:", i);
|
|
133
133
|
}
|
|
134
134
|
},
|
|
135
135
|
setImmersiveStore: (t) => {
|
|
136
136
|
n({ immersiveStore: t });
|
|
137
137
|
}
|
|
138
138
|
}))
|
|
139
|
-
), ne = () =>
|
|
139
|
+
), ne = () => O.getState(), be = O.subscribe, I = (n) => O(
|
|
140
140
|
te((t) => {
|
|
141
141
|
const r = {
|
|
142
142
|
...t,
|
|
@@ -145,33 +145,45 @@ const M = J()(
|
|
|
145
145
|
};
|
|
146
146
|
return n ? n(r) : r;
|
|
147
147
|
})
|
|
148
|
-
),
|
|
148
|
+
), ge = ({ children: n }) => {
|
|
149
149
|
const { updateBackends: e } = I();
|
|
150
150
|
return R((t, r) => {
|
|
151
151
|
e(r);
|
|
152
152
|
}), n;
|
|
153
|
-
}, re =
|
|
153
|
+
}, re = {
|
|
154
|
+
isPending: !0,
|
|
155
|
+
isSuccess: !1,
|
|
156
|
+
arSource: null,
|
|
157
|
+
arContext: null
|
|
158
|
+
}, oe = () => {
|
|
159
|
+
const e = I((t) => t.backends).get(p.FIDUCIAL);
|
|
160
|
+
return e ? {
|
|
161
|
+
...e.getInternal(),
|
|
162
|
+
isPending: !1,
|
|
163
|
+
isSuccess: !0
|
|
164
|
+
} : re;
|
|
165
|
+
}, he = ({
|
|
154
166
|
patternUrl: n,
|
|
155
167
|
barcodeValue: e,
|
|
156
168
|
params: t,
|
|
157
169
|
onMarkerFound: r,
|
|
158
170
|
onMarkerLost: c,
|
|
159
|
-
children:
|
|
171
|
+
children: i
|
|
160
172
|
}) => {
|
|
161
|
-
const A =
|
|
173
|
+
const A = b(null), s = oe(), u = b(!1), a = b(!1), f = b(null);
|
|
162
174
|
return k(() => {
|
|
163
|
-
if (!
|
|
175
|
+
if (!s.isSuccess) return;
|
|
164
176
|
let l = !1;
|
|
165
177
|
return (() => {
|
|
166
178
|
try {
|
|
167
|
-
const { arContext: d } =
|
|
168
|
-
if (!d || !
|
|
169
|
-
if (
|
|
179
|
+
const { arContext: d } = s, S = A.current;
|
|
180
|
+
if (!d || !S || l) return;
|
|
181
|
+
if (S.visible = !1, a.current = !1, !d.arController) {
|
|
170
182
|
requestAnimationFrame(() => {
|
|
171
|
-
if (!A.current || l || !
|
|
183
|
+
if (!A.current || l || !s.arContext?.arController)
|
|
172
184
|
return;
|
|
173
185
|
const g = new x(
|
|
174
|
-
|
|
186
|
+
s.arContext,
|
|
175
187
|
A.current,
|
|
176
188
|
{
|
|
177
189
|
type: n ? "pattern" : e ? "barcode" : "unknown",
|
|
@@ -180,28 +192,35 @@ const M = J()(
|
|
|
180
192
|
...t
|
|
181
193
|
}
|
|
182
194
|
);
|
|
183
|
-
f.current = g,
|
|
195
|
+
f.current = g, a.current = !0;
|
|
184
196
|
});
|
|
185
197
|
return;
|
|
186
198
|
}
|
|
187
|
-
const h = new x(d,
|
|
199
|
+
const h = new x(d, S, {
|
|
188
200
|
type: n ? "pattern" : e ? "barcode" : "unknown",
|
|
189
201
|
patternUrl: n,
|
|
190
202
|
barcodeValue: e,
|
|
191
203
|
...t
|
|
192
204
|
});
|
|
193
|
-
f.current = h,
|
|
205
|
+
f.current = h, a.current = !0;
|
|
194
206
|
} catch (d) {
|
|
195
207
|
console.error("Failed to initialize fiducial anchor:", d);
|
|
196
208
|
}
|
|
197
209
|
})(), () => {
|
|
198
210
|
l = !0;
|
|
199
211
|
const d = f.current;
|
|
200
|
-
typeof d?.dispose == "function" && d.dispose(),
|
|
212
|
+
typeof d?.dispose == "function" && d.dispose(), a.current = !1;
|
|
201
213
|
};
|
|
202
|
-
}, [
|
|
214
|
+
}, [
|
|
215
|
+
s.isSuccess,
|
|
216
|
+
s.arContext,
|
|
217
|
+
n,
|
|
218
|
+
e,
|
|
219
|
+
t,
|
|
220
|
+
s
|
|
221
|
+
]), R(() => {
|
|
203
222
|
const l = A.current;
|
|
204
|
-
if (!l || !
|
|
223
|
+
if (!l || !a.current) {
|
|
205
224
|
l && (l.visible = !1);
|
|
206
225
|
return;
|
|
207
226
|
}
|
|
@@ -212,57 +231,57 @@ const M = J()(
|
|
|
212
231
|
{
|
|
213
232
|
ref: A,
|
|
214
233
|
visible: !1,
|
|
215
|
-
children:
|
|
234
|
+
children: i
|
|
216
235
|
}
|
|
217
236
|
);
|
|
218
|
-
},
|
|
219
|
-
const { scene: t, camera: r, gl: c } = v(), { registerBackend:
|
|
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);
|
|
220
239
|
return u.current = n, k(() => {
|
|
221
|
-
if (
|
|
222
|
-
let
|
|
240
|
+
if (s.current) return;
|
|
241
|
+
let a = !1;
|
|
223
242
|
return (async () => {
|
|
224
243
|
try {
|
|
225
|
-
const l =
|
|
226
|
-
if (
|
|
227
|
-
await
|
|
244
|
+
const l = se(u.current);
|
|
245
|
+
if (a) return;
|
|
246
|
+
await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
|
|
228
247
|
} catch (l) {
|
|
229
248
|
console.error("[FiducialSession] Failed to initialize:", l);
|
|
230
249
|
}
|
|
231
250
|
})(), () => {
|
|
232
|
-
|
|
251
|
+
a = !0, s.current && (A(s.current), s.current = null);
|
|
233
252
|
};
|
|
234
|
-
}, [t, r, c,
|
|
235
|
-
},
|
|
253
|
+
}, [t, r, c, i, A]), e;
|
|
254
|
+
}, se = (n) => {
|
|
236
255
|
let e = null, t = null, r = null, c;
|
|
237
256
|
return {
|
|
238
257
|
type: p.FIDUCIAL,
|
|
239
|
-
async init({ camera:
|
|
240
|
-
e = new
|
|
258
|
+
async init({ camera: i, renderer: A }) {
|
|
259
|
+
e = new B({
|
|
241
260
|
sourceType: n?.sourceType ?? "webcam"
|
|
242
|
-
}), await new Promise((
|
|
261
|
+
}), await new Promise((a, f) => {
|
|
243
262
|
const l = setTimeout(() => {
|
|
244
263
|
f(new Error("AR source initialization timeout"));
|
|
245
264
|
}, 1e4);
|
|
246
265
|
e?.init(() => {
|
|
247
266
|
clearTimeout(l);
|
|
248
267
|
const o = e?.domElement;
|
|
249
|
-
o && (o.style.position = "fixed", o.style.top = "0", o.style.left = "0", o.style.width = "100vw", o.style.height = "100vh", o.style.objectFit = "cover", o.style.zIndex = "-1", o.style.pointerEvents = "none"),
|
|
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();
|
|
250
269
|
});
|
|
251
270
|
});
|
|
252
|
-
const
|
|
271
|
+
const s = {
|
|
253
272
|
cameraParametersUrl: n?.cameraParametersUrl ?? // default to internal camera parameters
|
|
254
273
|
new URL("data:application/octet-stream;base64,AAACgAAAAeBAgwrsW6bUSwAAAAAAAAAAQHQ3KqAAAAAAAAAAAAAAAAAAAAAAAAAAQIL0K3dHyf9AbbNowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/wAAAAAAAAAAAAAAAAAAA/uWNa4AAAAL+3lTLAAAAAv17YFWAAAAA/VYLXIAAAAECCe0YgAAAAQIJlMOAAAABAdDcqoAAAAEBts2jAAAAAP+8OmzqkDy4=", import.meta.url).toString(),
|
|
255
274
|
detectionMode: n?.detectionMode ?? "mono",
|
|
256
275
|
patternRatio: n?.patternRatio ?? 0.5,
|
|
257
276
|
matrixCodeType: n?.matrixCodeType ?? "3x3"
|
|
258
277
|
};
|
|
259
|
-
t = new
|
|
278
|
+
t = new N(s), r = i;
|
|
260
279
|
const u = () => {
|
|
261
280
|
e?.onResizeElement();
|
|
262
|
-
const
|
|
263
|
-
A.setSize(
|
|
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);
|
|
264
283
|
};
|
|
265
|
-
await new Promise((
|
|
284
|
+
await new Promise((a, f) => {
|
|
266
285
|
const l = setTimeout(() => {
|
|
267
286
|
f(new Error("AR context initialization timeout"));
|
|
268
287
|
}, 1e4);
|
|
@@ -270,7 +289,7 @@ const M = J()(
|
|
|
270
289
|
clearTimeout(l);
|
|
271
290
|
try {
|
|
272
291
|
const o = t?.getProjectionMatrix();
|
|
273
|
-
o &&
|
|
292
|
+
o && i.projectionMatrix.copy(o), u(), a();
|
|
274
293
|
} catch (o) {
|
|
275
294
|
f(o);
|
|
276
295
|
}
|
|
@@ -281,16 +300,16 @@ const M = J()(
|
|
|
281
300
|
if (!(!e || !t) && !(!e.ready || !e.domElement))
|
|
282
301
|
try {
|
|
283
302
|
t.update(e.domElement);
|
|
284
|
-
const
|
|
285
|
-
r &&
|
|
286
|
-
} catch (
|
|
287
|
-
console.warn("AR.js update error:",
|
|
303
|
+
const i = t.getProjectionMatrix?.();
|
|
304
|
+
r && i && r.projectionMatrix.copy(i);
|
|
305
|
+
} catch (i) {
|
|
306
|
+
console.warn("AR.js update error:", i);
|
|
288
307
|
}
|
|
289
308
|
},
|
|
290
309
|
dispose() {
|
|
291
310
|
if (c && (window.removeEventListener("resize", c), c = void 0), t && typeof t.dispose == "function" && t.dispose(), e?.domElement) {
|
|
292
|
-
const
|
|
293
|
-
|
|
311
|
+
const i = e.domElement.parentNode;
|
|
312
|
+
i && i.removeChild(e.domElement);
|
|
294
313
|
}
|
|
295
314
|
e = null, t = null, r = null;
|
|
296
315
|
},
|
|
@@ -299,27 +318,49 @@ const M = J()(
|
|
|
299
318
|
arContext: t
|
|
300
319
|
})
|
|
301
320
|
};
|
|
302
|
-
}, ce =
|
|
321
|
+
}, ce = {
|
|
322
|
+
isPending: !0,
|
|
323
|
+
isSuccess: !1,
|
|
324
|
+
locar: null,
|
|
325
|
+
webcam: null,
|
|
326
|
+
deviceOrientation: null,
|
|
327
|
+
scene: null,
|
|
328
|
+
camera: null,
|
|
329
|
+
lastPosition: null,
|
|
330
|
+
registerAnchor: () => {
|
|
331
|
+
},
|
|
332
|
+
unregisterAnchor: () => {
|
|
333
|
+
},
|
|
334
|
+
getAnchor: () => {
|
|
335
|
+
}
|
|
336
|
+
}, ie = () => {
|
|
337
|
+
const e = I((t) => t.backends).get(p.GEOLOCATION);
|
|
338
|
+
return e ? {
|
|
339
|
+
...e.getInternal(),
|
|
340
|
+
isPending: !1,
|
|
341
|
+
isSuccess: !0
|
|
342
|
+
} : ce;
|
|
343
|
+
}, ye = ({
|
|
303
344
|
latitude: n,
|
|
304
345
|
longitude: e,
|
|
305
346
|
altitude: t = 0,
|
|
306
347
|
isBillboard: r = !0,
|
|
307
348
|
onAttach: c,
|
|
308
|
-
onGpsUpdate:
|
|
349
|
+
onGpsUpdate: i,
|
|
309
350
|
children: A
|
|
310
351
|
}) => {
|
|
311
|
-
const
|
|
352
|
+
const s = ie(), { camera: u } = v(), [a] = P(() => new D()), f = F(() => Math.random().toString(36).slice(2, 11), []), l = M(() => {
|
|
312
353
|
c?.();
|
|
313
|
-
}, [c]), o =
|
|
314
|
-
(d,
|
|
315
|
-
|
|
354
|
+
}, [c]), o = M(
|
|
355
|
+
(d, S) => {
|
|
356
|
+
i?.(d, S);
|
|
316
357
|
},
|
|
317
|
-
[
|
|
358
|
+
[i]
|
|
318
359
|
);
|
|
319
360
|
return k(() => {
|
|
320
|
-
if (
|
|
321
|
-
return
|
|
322
|
-
anchor:
|
|
361
|
+
if (s.isSuccess)
|
|
362
|
+
return s.registerAnchor(f, {
|
|
363
|
+
anchor: a,
|
|
323
364
|
isAttached: !1,
|
|
324
365
|
latitude: n,
|
|
325
366
|
longitude: e,
|
|
@@ -327,11 +368,13 @@ const M = J()(
|
|
|
327
368
|
onAttach: l,
|
|
328
369
|
onGpsUpdate: o
|
|
329
370
|
}), () => {
|
|
330
|
-
|
|
371
|
+
s.unregisterAnchor(f);
|
|
331
372
|
};
|
|
332
373
|
}, [
|
|
374
|
+
s.isSuccess,
|
|
375
|
+
s.registerAnchor,
|
|
376
|
+
s.unregisterAnchor,
|
|
333
377
|
a,
|
|
334
|
-
i,
|
|
335
378
|
f,
|
|
336
379
|
n,
|
|
337
380
|
e,
|
|
@@ -339,31 +382,31 @@ const M = J()(
|
|
|
339
382
|
l,
|
|
340
383
|
o
|
|
341
384
|
]), R(() => {
|
|
342
|
-
!r || !u || !
|
|
343
|
-
}), G(/* @__PURE__ */ C("group", { children: A }),
|
|
344
|
-
},
|
|
385
|
+
!r || !u || !s.isSuccess || !s.getAnchor(f)?.isAttached || a.lookAt(u.position);
|
|
386
|
+
}), G(/* @__PURE__ */ C("group", { children: A }), a);
|
|
387
|
+
}, ke = ({
|
|
345
388
|
options: n = {},
|
|
346
389
|
children: e
|
|
347
390
|
}) => {
|
|
348
|
-
const { scene: t, camera: r, gl: c } = v(), { registerBackend:
|
|
391
|
+
const { scene: t, camera: r, gl: c } = v(), { registerBackend: i, unregisterBackend: A } = I(), s = b(null), u = b(n);
|
|
349
392
|
return u.current = n, k(() => {
|
|
350
|
-
if (
|
|
351
|
-
let
|
|
393
|
+
if (s.current) return;
|
|
394
|
+
let a = !1;
|
|
352
395
|
return (async () => {
|
|
353
396
|
try {
|
|
354
|
-
const l =
|
|
355
|
-
if (
|
|
356
|
-
await
|
|
397
|
+
const l = ae(u.current);
|
|
398
|
+
if (a) return;
|
|
399
|
+
await i(l, { scene: t, camera: r, renderer: c }), s.current = l;
|
|
357
400
|
} catch (l) {
|
|
358
401
|
console.error("[GeolocationSession] Failed to initialize:", l);
|
|
359
402
|
}
|
|
360
403
|
})(), () => {
|
|
361
|
-
|
|
404
|
+
a = !0, s.current && (A(s.current), s.current = null);
|
|
362
405
|
};
|
|
363
|
-
}, [t, r, c,
|
|
364
|
-
},
|
|
365
|
-
let e = null, t = null, r = null, c,
|
|
366
|
-
const
|
|
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();
|
|
367
410
|
let f = null;
|
|
368
411
|
const l = (o) => {
|
|
369
412
|
if (!(!e || o.isAttached))
|
|
@@ -376,22 +419,22 @@ const M = J()(
|
|
|
376
419
|
return {
|
|
377
420
|
type: p.GEOLOCATION,
|
|
378
421
|
async init(o) {
|
|
379
|
-
const { camera: d, renderer:
|
|
422
|
+
const { camera: d, renderer: S, scene: h } = o;
|
|
380
423
|
if (!h)
|
|
381
424
|
throw new Error(
|
|
382
425
|
"[geolocationBackend] A THREE.Scene is required for location-based AR"
|
|
383
426
|
);
|
|
384
|
-
A = d,
|
|
427
|
+
A = d, s = S, u = h, e = new U(h, d), t = new X(
|
|
385
428
|
n?.webcamConstraints ?? {
|
|
386
429
|
video: { facingMode: "environment" }
|
|
387
430
|
// TODO remove `as any` once fixed upstream (LocAR.js)
|
|
388
431
|
}
|
|
389
|
-
),
|
|
432
|
+
), i = (m) => {
|
|
390
433
|
f = m.position;
|
|
391
|
-
for (const w of
|
|
434
|
+
for (const w of a.values())
|
|
392
435
|
w.isAttached || l(w), w.onGpsUpdate?.(m.position, m.distMoved);
|
|
393
436
|
n?.onGpsUpdate?.(m.position, m.distMoved);
|
|
394
|
-
}, e.on("gpsupdate",
|
|
437
|
+
}, e.on("gpsupdate", i), t.on("webcamstarted", (m) => {
|
|
395
438
|
h.background = m.texture;
|
|
396
439
|
}), t.on("webcamerror", (m) => {
|
|
397
440
|
console.error("[geolocationBackend] webcam error:", m);
|
|
@@ -418,9 +461,9 @@ const M = J()(
|
|
|
418
461
|
toJSON: () => g
|
|
419
462
|
});
|
|
420
463
|
const E = () => {
|
|
421
|
-
if (!
|
|
464
|
+
if (!s || !A) return;
|
|
422
465
|
const m = window.innerWidth, w = window.innerHeight;
|
|
423
|
-
|
|
466
|
+
s.setSize(m, w, !1), A.aspect = m / w, A.updateProjectionMatrix?.();
|
|
424
467
|
};
|
|
425
468
|
E(), window.addEventListener("resize", E), c = E;
|
|
426
469
|
},
|
|
@@ -428,15 +471,15 @@ const M = J()(
|
|
|
428
471
|
r?.update?.();
|
|
429
472
|
},
|
|
430
473
|
dispose() {
|
|
431
|
-
e &&
|
|
432
|
-
for (const o of
|
|
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())
|
|
433
476
|
if (o.isAttached)
|
|
434
477
|
try {
|
|
435
478
|
o.anchor.removeFromParent();
|
|
436
479
|
} catch (d) {
|
|
437
480
|
console.error("⚠️ Error removing anchor:", d);
|
|
438
481
|
}
|
|
439
|
-
|
|
482
|
+
a.clear(), e = null, t = null, r = null, A = null, s = null, u = null, i = null, f = null;
|
|
440
483
|
},
|
|
441
484
|
getInternal: () => ({
|
|
442
485
|
locar: e,
|
|
@@ -446,30 +489,30 @@ const M = J()(
|
|
|
446
489
|
camera: A,
|
|
447
490
|
lastPosition: f,
|
|
448
491
|
registerAnchor: (o, d) => {
|
|
449
|
-
|
|
492
|
+
a.set(o, d), f !== null && !d.isAttached && (l(d), d.onGpsUpdate?.(f, 0));
|
|
450
493
|
},
|
|
451
494
|
unregisterAnchor: (o) => {
|
|
452
|
-
const d =
|
|
495
|
+
const d = a.get(o);
|
|
453
496
|
if (d?.isAttached)
|
|
454
497
|
try {
|
|
455
498
|
d.anchor.removeFromParent();
|
|
456
|
-
} catch (
|
|
457
|
-
console.error(`⚠️ Error removing anchor ${o}:`,
|
|
499
|
+
} catch (S) {
|
|
500
|
+
console.error(`⚠️ Error removing anchor ${o}:`, S);
|
|
458
501
|
}
|
|
459
|
-
|
|
502
|
+
a.delete(o);
|
|
460
503
|
},
|
|
461
|
-
getAnchor: (o) =>
|
|
504
|
+
getAnchor: (o) => a.get(o)
|
|
462
505
|
})
|
|
463
506
|
};
|
|
464
|
-
},
|
|
507
|
+
}, le = () => ({
|
|
465
508
|
type: p.IMMERSIVE,
|
|
466
509
|
init: () => {
|
|
467
510
|
},
|
|
468
511
|
getInternal: () => null
|
|
469
|
-
}),
|
|
470
|
-
const e =
|
|
512
|
+
}), Ie = ({ children: n }) => {
|
|
513
|
+
const e = F(() => W(), []);
|
|
471
514
|
return k(() => {
|
|
472
|
-
const t = ne(), r =
|
|
515
|
+
const t = ne(), r = le();
|
|
473
516
|
return t.backends.set(p.IMMERSIVE, r), t.setImmersiveStore(e), () => {
|
|
474
517
|
t.backends.delete(p.IMMERSIVE), t.setImmersiveStore(null);
|
|
475
518
|
};
|
|
@@ -477,17 +520,17 @@ const M = J()(
|
|
|
477
520
|
};
|
|
478
521
|
export {
|
|
479
522
|
p as BACKEND_TYPES,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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,
|
|
488
531
|
ne as getXRStore,
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
532
|
+
be as subscribeToXRStore,
|
|
533
|
+
oe as useFiducialBackend,
|
|
534
|
+
ie as useGeolocationBackend,
|
|
492
535
|
I as useXRStore
|
|
493
536
|
};
|
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.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@ar-js-org/ar.js": "^3.4.7",
|
|
48
48
|
"@react-three/fiber": "^9.5.0",
|
|
49
|
-
"@react-three/xr": "^6.6.
|
|
49
|
+
"@react-three/xr": "^6.6.29",
|
|
50
50
|
"locar": "^0.1.8",
|
|
51
51
|
"react": "^19.2.0",
|
|
52
52
|
"react-dom": "^19.2.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@ar-js-org/ar.js": "^3.4.7",
|
|
68
|
-
"@biomejs/biome": "^2.3.
|
|
68
|
+
"@biomejs/biome": "^2.3.11",
|
|
69
69
|
"@react-three/fiber": "^9.5.0",
|
|
70
70
|
"@testing-library/jest-dom": "^6.9.1",
|
|
71
71
|
"@testing-library/react": "^16.3.1",
|