@webspatial/core-sdk 1.3.0 → 1.5.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/dist/index.d.ts CHANGED
@@ -47,8 +47,6 @@ declare abstract class SpatialMaterial extends SpatialObject {
47
47
  }
48
48
 
49
49
  declare enum SpatialWebMsgType {
50
- cubeInfo = "cubeInfo",
51
- transform = "transform",
52
50
  modelloaded = "modelloaded",
53
51
  modelloadfailed = "modelloadfailed",
54
52
  spatialtap = "spatialtap",
@@ -64,25 +62,6 @@ declare enum SpatialWebMsgType {
64
62
  interface ObjectDestroyMsg {
65
63
  type: SpatialWebMsgType.objectdestroy;
66
64
  }
67
- interface CubeInfoMsg {
68
- type: SpatialWebMsgType.cubeInfo;
69
- origin: Vec3;
70
- size: Size3D;
71
- }
72
- interface CubeInfoMsg {
73
- type: SpatialWebMsgType.cubeInfo;
74
- origin: Vec3;
75
- size: Size3D;
76
- }
77
- interface TransformMsg {
78
- type: SpatialWebMsgType.transform;
79
- detail: {
80
- column0: [number, number, number];
81
- column1: [number, number, number];
82
- column2: [number, number, number];
83
- column3: [number, number, number];
84
- };
85
- }
86
65
  interface SpatialTapMsg {
87
66
  type: SpatialWebMsgType.spatialtap;
88
67
  detail: SpatialTapEventDetail;
@@ -144,7 +123,7 @@ declare abstract class SpatializedElement extends SpatialObject {
144
123
  * Gets the current cube information for this element.
145
124
  * @returns The current CubeInfo or undefined if not set
146
125
  */
147
- get cubeInfo(): CubeInfo$1 | undefined;
126
+ get cubeInfo(): CubeInfo | undefined;
148
127
  /**
149
128
  * The current transformation matrix of this element.
150
129
  */
@@ -169,7 +148,7 @@ declare abstract class SpatializedElement extends SpatialObject {
169
148
  * Handles various spatial events like transforms, gestures, and interactions.
170
149
  * @param data The event data received from the WebSpatial system
171
150
  */
172
- protected onReceiveEvent(data: CubeInfoMsg | TransformMsg | SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
151
+ protected onReceiveEvent(data: SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
173
152
  private _onSpatialTap?;
174
153
  set onSpatialTap(value: (event: SpatialTapEvent) => void | undefined);
175
154
  private _onSpatialDragStart?;
@@ -195,8 +174,12 @@ declare abstract class SpatializedElement extends SpatialObject {
195
174
 
196
175
  declare class SpatializedDynamic3DElement extends SpatializedElement {
197
176
  children: SpatialEntityOrReality[];
177
+ events: Record<string, (data: any) => void>;
198
178
  constructor(id: string);
199
179
  addEntity(entity: SpatialEntity): Promise<CommandResult>;
180
+ addEvent(type: SpatialEntityEventType, callback: (data: any) => void): void;
181
+ removeEvent(eventName: SpatialEntityEventType): void;
182
+ dispatchEvent(evt: CustomEvent): void;
200
183
  updateProperties(properties: Partial<SpatializedElementProperties>): Promise<CommandResult>;
201
184
  }
202
185
 
@@ -264,6 +247,11 @@ interface SpatializedElementProperties {
264
247
  enableRotateEndGesture: boolean;
265
248
  enableMagnifyGesture: boolean;
266
249
  enableMagnifyEndGesture: boolean;
250
+ /**
251
+ * Optional world-space axis for spatial rotate gesture. Omitted or zero vector
252
+ * means unconstrained rotation (platform default).
253
+ */
254
+ rotateConstrainedToAxis?: Vec3;
267
255
  }
268
256
  interface Spatialized2DElementProperties extends SpatializedElementProperties {
269
257
  scrollPageEnabled: boolean;
@@ -291,6 +279,7 @@ interface SpatialSceneCreationOptions$1 {
291
279
  worldAlignment?: WorldAlignmentType;
292
280
  baseplateVisibility?: BaseplateVisibilityType;
293
281
  }
282
+ type SpatialEntityEventType = 'spatialtap' | 'spatialdragstart' | 'spatialdrag' | 'spatialdragend' | 'spatialrotate' | 'spatialrotateend' | 'spatialmagnify' | 'spatialmagnifyend';
294
283
  declare const BaseplateVisibilityValues: readonly ["automatic", "visible", "hidden"];
295
284
  type BaseplateVisibilityType = (typeof BaseplateVisibilityValues)[number];
296
285
  declare function isValidBaseplateVisibilityType(type: string): Boolean;
@@ -313,7 +302,6 @@ interface SpatialEntityProperties {
313
302
  rotation: Vec3;
314
303
  scale: Vec3;
315
304
  }
316
- type SpatialEntityEventType = 'spatialtap';
317
305
  type SpatialGeometryType = 'BoxGeometry' | 'PlaneGeometry' | 'SphereGeometry' | 'CylinderGeometry' | 'ConeGeometry';
318
306
  interface SpatialBoxGeometryOptions {
319
307
  width?: number;
@@ -383,7 +371,7 @@ interface Size {
383
371
  interface Size3D extends Size {
384
372
  depth: number;
385
373
  }
386
- declare class CubeInfo$1 {
374
+ declare class CubeInfo {
387
375
  size: Size3D;
388
376
  origin: Vec3;
389
377
  constructor(size: Size3D, origin: Vec3);
@@ -439,6 +427,7 @@ interface AttachmentEntityOptions {
439
427
  width: number;
440
428
  height: number;
441
429
  };
430
+ ownerViewId: string;
442
431
  }
443
432
  interface AttachmentEntityUpdateOptions {
444
433
  position?: [number, number, number];
@@ -461,8 +450,12 @@ declare class SpatialEntity extends SpatialObject {
461
450
  events: Record<string, (data: any) => void>;
462
451
  children: SpatialEntity[];
463
452
  parent: SpatialEntityOrReality | null;
453
+ private _enableInput;
454
+ get enableInput(): boolean;
455
+ set enableInput(value: boolean);
464
456
  constructor(id: string, userData?: SpatialEntityUserData | undefined);
465
457
  addComponent(component: SpatialComponent): Promise<CommandResult>;
458
+ removeComponent(component: SpatialComponent): Promise<CommandResult>;
466
459
  setPosition(position: Vec3): Promise<CommandResult>;
467
460
  setRotation(rotation: Vec3): Promise<CommandResult>;
468
461
  setScale(scale: Vec3): Promise<CommandResult>;
@@ -485,6 +478,7 @@ declare class SpatialModelEntity extends SpatialEntity {
485
478
  options?: SpatialModelEntityCreationOptions | undefined;
486
479
  userData?: SpatialEntityUserData | undefined;
487
480
  constructor(id: string, options?: SpatialModelEntityCreationOptions | undefined, userData?: SpatialEntityUserData | undefined);
481
+ setMaterials(materials: SpatialMaterial[]): Promise<CommandResult>;
488
482
  }
489
483
 
490
484
  declare class ModelComponent extends SpatialComponent {
@@ -577,6 +571,7 @@ declare class SpatialScene extends SpatialObject {
577
571
  * @returns The singleton SpatialScene instance
578
572
  */
579
573
  static getInstance(): SpatialScene;
574
+ convertCoordinate(position: Vec3, fromId: string, toId: string): Promise<Vec3>;
580
575
  /**
581
576
  * Updates the properties of the spatial scene.
582
577
  * This can include background settings, lighting, and other scene-wide properties.
@@ -819,6 +814,7 @@ declare class SpatialSession {
819
814
  * This is the main entry point for the WebSpatial SDK, providing access to spatial capabilities.
820
815
  */
821
816
  declare class Spatial {
817
+ private wsAppShellVersionFromUA;
822
818
  /**
823
819
  * Requests a spatial session object from the browser.
824
820
  * This is the primary method to initialize spatial functionality.
@@ -832,6 +828,7 @@ declare class Spatial {
832
828
  * @returns True if running in a spatial web environment, false otherwise
833
829
  */
834
830
  runInSpatialWeb(): boolean;
831
+ getShellVersionFromUA(): string | null;
835
832
  /** @deprecated
836
833
  * Checks if WebSpatial is supported in the current environment.
837
834
  * Verifies compatibility between native and client versions.
@@ -852,6 +849,53 @@ declare class Spatial {
852
849
  getClientVersion(): string;
853
850
  }
854
851
 
852
+ type PhysicalMetricsValueShape = {
853
+ meterToPtUnscaled: number;
854
+ meterToPtScaled: number;
855
+ };
856
+ type WorldScalingCompensation = 'unscaled' | 'scaled';
857
+ type ConvertOption = {
858
+ worldScalingCompensation: WorldScalingCompensation;
859
+ };
860
+ /**
861
+ * Converts scene points (pt) to physical meters (m).
862
+ *
863
+ * @param point Points value to convert.
864
+ * @param options Optional conversion options to select world scaling compensation.
865
+ * @returns Physical length in meters.
866
+ */
867
+ declare function pointToPhysical(point: number, options?: ConvertOption): number;
868
+ /**
869
+ * Converts physical meters (m) to scene points (pt).
870
+ *
871
+ * @param physical Physical length in meters to convert.
872
+ * @param options Optional conversion options to select world scaling compensation.
873
+ * @returns Points length in the scene.
874
+ */
875
+ declare function physicalToPoint(physical: number, options?: ConvertOption): number;
876
+ /**
877
+ * Returns the current physical metrics used for conversions.
878
+ *
879
+ * @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.
880
+ */
881
+ declare function getValue(): PhysicalMetricsValueShape;
882
+ /**
883
+ * Subscribes to physical metrics changes.
884
+ *
885
+ * @param cb Callback invoked when metrics update is detected.
886
+ * @returns Unsubscribe function to remove the listener.
887
+ */
888
+ declare function subscribe(cb: () => void): () => void;
889
+
890
+ type physicalMetrics_PhysicalMetricsValueShape = PhysicalMetricsValueShape;
891
+ declare const physicalMetrics_getValue: typeof getValue;
892
+ declare const physicalMetrics_physicalToPoint: typeof physicalToPoint;
893
+ declare const physicalMetrics_pointToPhysical: typeof pointToPhysical;
894
+ declare const physicalMetrics_subscribe: typeof subscribe;
895
+ declare namespace physicalMetrics {
896
+ export { type physicalMetrics_PhysicalMetricsValueShape as PhysicalMetricsValueShape, physicalMetrics_getValue as getValue, physicalMetrics_physicalToPoint as physicalToPoint, physicalMetrics_pointToPhysical as pointToPhysical, physicalMetrics_subscribe as subscribe };
897
+ }
898
+
855
899
  declare global {
856
900
  declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
857
901
 
@@ -874,6 +918,11 @@ declare global {
874
918
  webkit: any
875
919
  webspatialBridge: any
876
920
 
921
+ // Project Pico OS browser injects this global object to provide internal capabilities.
922
+ webSpatial?: {
923
+ genToken?: () => string
924
+ }
925
+
877
926
  // Will be removed in favor of __WebSpatialData
878
927
  WebSpatailNativeVersion: string
879
928
 
@@ -882,19 +931,19 @@ declare global {
882
931
  'natvie-version'?: string
883
932
  'react-sdk-version'?: string
884
933
  'core-sdk-version'?: string
934
+ physicalMetrics?: PhysicalMetricsValueShape
885
935
  }
886
936
 
887
- innerDepth: number
888
- outerDepth: number
937
+ xrInnerDepth: number
938
+ xrOuterDepth: number
889
939
  }
890
940
 
891
941
  interface HTMLElement {
892
- offsetBack: number
893
- clientDepth: number
894
- getBoundingClientCube: () => CubeInfo | undefined
942
+ xrOffsetBack: number
943
+ xrClientDepth: number
895
944
  }
896
945
  }
897
946
 
898
947
  declare const isSSREnv: () => boolean;
899
948
 
900
- export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo$1 as CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, type Point3D, type Quaternion, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEndEventDetail, type SpatialDragEvent, type SpatialDragEventDetail, type SpatialDragStartEvent, type SpatialDragStartEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEndEventDetail, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEndEventDetail, type SpatialRotateEvent, type SpatialRotateEventDetail, SpatialScene, type SpatialSceneCreationOptions$1 as SpatialSceneCreationOptions, type SpatialSceneProperties, SpatialSceneState$1 as SpatialSceneState, type SpatialSceneType$1 as SpatialSceneType, SpatialSceneValues, SpatialSession, SpatialSphereGeometry, type SpatialSphereGeometryOptions, type SpatialTapEvent, type SpatialTapEventDetail, SpatialUnlitMaterial, type SpatialUnlitMaterialOptions, Spatialized2DElement, type Spatialized2DElementProperties, SpatializedDynamic3DElement, SpatializedElement, type SpatializedElementProperties, SpatializedElementType, SpatializedStatic3DElement, type SpatializedStatic3DElementProperties, type Vec3, type WorldAlignmentType, WorldAlignmentValues, type WorldScalingType, WorldScalingValues, createAttachmentEntity, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
949
+ export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, physicalMetrics as PhysicalMetrics, type Point3D, type Quaternion, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEndEventDetail, type SpatialDragEvent, type SpatialDragEventDetail, type SpatialDragStartEvent, type SpatialDragStartEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEndEventDetail, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEndEventDetail, type SpatialRotateEvent, type SpatialRotateEventDetail, SpatialScene, type SpatialSceneCreationOptions$1 as SpatialSceneCreationOptions, type SpatialSceneProperties, SpatialSceneState$1 as SpatialSceneState, type SpatialSceneType$1 as SpatialSceneType, SpatialSceneValues, SpatialSession, SpatialSphereGeometry, type SpatialSphereGeometryOptions, type SpatialTapEvent, type SpatialTapEventDetail, SpatialUnlitMaterial, type SpatialUnlitMaterialOptions, Spatialized2DElement, type Spatialized2DElementProperties, SpatializedDynamic3DElement, SpatializedElement, type SpatializedElementProperties, SpatializedElementType, SpatializedStatic3DElement, type SpatializedStatic3DElementProperties, type Vec3, type WorldAlignmentType, WorldAlignmentValues, type WorldScalingType, WorldScalingValues, createAttachmentEntity, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };