@webspatial/core-sdk 1.2.1 → 1.4.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/CHANGELOG.md +69 -1
- package/dist/iife/index.d.ts +115 -32
- package/dist/iife/index.global.js +68 -3
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +115 -32
- package/dist/index.js +603 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +65 -0
- package/src/Spatial.ts +22 -1
- package/src/SpatialScene.ts +20 -0
- package/src/SpatialSession.ts +15 -1
- package/src/SpatializedDynamic3DElement.ts +19 -0
- package/src/SpatializedElement.ts +0 -29
- package/src/SpatializedElementCreator.ts +1 -1
- package/src/SpatializedStatic3DElement.test.ts +125 -0
- package/src/SpatializedStatic3DElement.ts +14 -1
- package/src/WebMsgCommand.ts +0 -26
- package/src/index.ts +2 -0
- package/src/jsbcommand.coverage.test.ts +0 -43
- package/src/physicalMetrics.test.ts +110 -0
- package/src/physicalMetrics.ts +101 -0
- package/src/platform-adapter/index.ts +5 -1
- package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +470 -0
- package/src/reality/Attachment.ts +47 -0
- package/src/reality/entity/SpatialEntity.ts +45 -24
- package/src/reality/index.ts +1 -0
- package/src/types/global.d.ts +7 -5
- package/src/types/types.ts +29 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# @webspatial/core-sdk
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 945856b: add enableInput for Entity
|
|
8
|
+
move reality events definition from specific Entity to top-level Reality
|
|
9
|
+
- 56e98c8: rename innerDepth to xrInnerDepth and outerDepth to xrOuterDepth
|
|
10
|
+
- 0def1ef: Remove deprecated spatial measurement APIs: getBoundingClientRect, getBoundingClientCube, toSceneSpatial, toLocalSpace and their internal message types (CubeInfoMsg, TransformMsg)
|
|
11
|
+
- 58e1f69: Attachment init flow and lifecycle cleanup.
|
|
12
|
+
|
|
13
|
+
- **Core**
|
|
14
|
+
- Split attachment creation into `CreateAttachmentEntityCommand` (window/engine) and `InitializeAttachmentCommand` (send id, parent, position, size over JSB so native initializes after window exists).
|
|
15
|
+
- `createAttachmentEntity()` now runs both; native receives full options via init command.
|
|
16
|
+
- **React**
|
|
17
|
+
- `AttachmentEntity`: inline head-style sync via `MutationObserver` on `document.head`; direct cleanup on unmount (no StrictMode-only logic).
|
|
18
|
+
- `useEntity`: forwards all entity event handlers (tap, drag, rotate, magnify) to `useEntityEvent`.
|
|
19
|
+
- `useSpatializedElement`: ref-based cleanup so elements are destroyed correctly on unmount.
|
|
20
|
+
- Removed React 18 StrictMode–specific deferred cleanup from Reality, useEntity, AttachmentEntity, useSpatializedElement.
|
|
21
|
+
- **visionOS**
|
|
22
|
+
- Attachment manager and JSB handling updated for init command and consolidated window creation.
|
|
23
|
+
|
|
24
|
+
- 087fa12: react-sdk:support convertCoordinate
|
|
25
|
+
- 98fd429: react-sdk support pointToPhysical,physicalToPoint API from useMetrics() hook
|
|
26
|
+
- 8f8c50a: Spatial rotate axis constraint for spatialized elements.
|
|
27
|
+
|
|
28
|
+
- **Core**
|
|
29
|
+
- `SpatializedElementProperties` adds optional `rotateConstrainedToAxis` (Vec3) on partial updates to native.
|
|
30
|
+
- **React**
|
|
31
|
+
- `spatialEventOptions={{ constrainedToAxis: Vec3 | [number, number, number] }}` on spatialized containers and JSX intrinsics (`enable-xr`); omit or `[0,0,0]` means unconstrained.
|
|
32
|
+
- `PortalSpatializedContainer` syncs axis via `updateProperties`; `Model` / degraded paths strip `spatialEventOptions` from DOM.
|
|
33
|
+
- **visionOS**
|
|
34
|
+
- `RotateGesture3D(constrainedToAxis:)` when axis is non-zero; world-space axis, normalized on native.
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 8c50a0f: chore:update spatialEntityEventtype
|
|
39
|
+
- dabb15f: Update UA injection logic in VisionOS and add WSAppShell version number
|
|
40
|
+
- 2f2a3a8: Model ready promise triggers rejection when URL is changed midway
|
|
41
|
+
- 931f236: rename offsetBack to xrOffsetBack for naming consistency
|
|
42
|
+
|
|
43
|
+
## 1.3.0
|
|
44
|
+
|
|
45
|
+
### Minor Changes
|
|
46
|
+
|
|
47
|
+
- 93fe590: Add attachments support across React, Core SDK, and visionOS runtime, plus navigation guard and demo.
|
|
48
|
+
|
|
49
|
+
- React API
|
|
50
|
+
- New <AttachmentAsset name="..."> to declare attachment UI outside <SceneGraph>.
|
|
51
|
+
- New <AttachmentEntity attachment="..." position size /> to place the declared UI in 3D under a parent entity.
|
|
52
|
+
- Attachment content is rendered via createPortal so it shares React state with the main app.
|
|
53
|
+
- Core SDK
|
|
54
|
+
- Attachment types and SpatialSession.createAttachmentEntity(...).
|
|
55
|
+
- Create/update/destroy commands: webspatial://createAttachment, UpdateAttachmentEntity, DestroyCommand.
|
|
56
|
+
- Attachment wrapper with getContainer(), update(), destroy().
|
|
57
|
+
- visionOS (AVP runtime)
|
|
58
|
+
- Native AttachmentManager with a child WKWebView per attachment.
|
|
59
|
+
- SpatialScene intercepts webspatial://createAttachment, handles update/destroy, and cleans up on reload/destroy.
|
|
60
|
+
- SpatializedDynamic3DView renders attachments via RealityView(..., attachments:) and parents them under the correct SpatialEntity.
|
|
61
|
+
- Navigation fix
|
|
62
|
+
- Prevent internal webspatial:// URLs from being forwarded to UIApplication.shared.open(...).
|
|
63
|
+
- Test page
|
|
64
|
+
- /reality/attachments demo page: hide/show, animation (attachments follow parent), shared React state.
|
|
65
|
+
- Notes
|
|
66
|
+
- Attachments are 2D UI surfaces only (no nested <Reality> / 3D APIs inside attachments).
|
|
67
|
+
- No billboard/camera-facing policy in this PR.
|
|
68
|
+
|
|
69
|
+
- 1405681: Require URL for SpatializedStatic3DElement
|
|
70
|
+
|
|
3
71
|
## 1.2.1
|
|
4
72
|
|
|
5
73
|
## 1.2.0
|
|
@@ -149,4 +217,4 @@
|
|
|
149
217
|
|
|
150
218
|
### Patch Changes
|
|
151
219
|
|
|
152
|
-
- 456d15f: change ModelDragEvent to SpatialModelDragEvent in coresdk
|
|
220
|
+
- 456d15f: change ModelDragEvent to SpatialModelDragEvent in coresdk
|
package/dist/iife/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
|
|
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:
|
|
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
|
|
374
|
+
declare class CubeInfo {
|
|
387
375
|
size: Size3D;
|
|
388
376
|
origin: Vec3;
|
|
389
377
|
constructor(size: Size3D, origin: Vec3);
|
|
@@ -402,10 +390,12 @@ declare class CubeInfo$1 {
|
|
|
402
390
|
}
|
|
403
391
|
interface SpatialTapEventDetail {
|
|
404
392
|
location3D: Point3D;
|
|
393
|
+
globalLocation3D?: Point3D;
|
|
405
394
|
}
|
|
406
395
|
type SpatialTapEvent = CustomEvent<SpatialTapEventDetail>;
|
|
407
396
|
interface SpatialDragStartEventDetail {
|
|
408
397
|
startLocation3D: Point3D;
|
|
398
|
+
globalLocation3D?: Point3D;
|
|
409
399
|
}
|
|
410
400
|
interface SpatialDragEventDetail {
|
|
411
401
|
translation3D: Vec3;
|
|
@@ -430,6 +420,22 @@ interface SpatialMagnifyEndEventDetail {
|
|
|
430
420
|
type SpatialMagnifyEvent = CustomEvent<SpatialMagnifyEventDetail>;
|
|
431
421
|
type SpatialMagnifyEndEvent = CustomEvent<SpatialMagnifyEndEventDetail>;
|
|
432
422
|
type SpatialEntityOrReality = SpatialEntity | SpatializedDynamic3DElement;
|
|
423
|
+
interface AttachmentEntityOptions {
|
|
424
|
+
parentEntityId: string;
|
|
425
|
+
position?: [number, number, number];
|
|
426
|
+
size: {
|
|
427
|
+
width: number;
|
|
428
|
+
height: number;
|
|
429
|
+
};
|
|
430
|
+
ownerViewId: string;
|
|
431
|
+
}
|
|
432
|
+
interface AttachmentEntityUpdateOptions {
|
|
433
|
+
position?: [number, number, number];
|
|
434
|
+
size?: {
|
|
435
|
+
width: number;
|
|
436
|
+
height: number;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
433
439
|
|
|
434
440
|
declare class SpatialComponent extends SpatialObject {
|
|
435
441
|
constructor(id: string);
|
|
@@ -444,6 +450,9 @@ declare class SpatialEntity extends SpatialObject {
|
|
|
444
450
|
events: Record<string, (data: any) => void>;
|
|
445
451
|
children: SpatialEntity[];
|
|
446
452
|
parent: SpatialEntityOrReality | null;
|
|
453
|
+
private _enableInput;
|
|
454
|
+
get enableInput(): boolean;
|
|
455
|
+
set enableInput(value: boolean);
|
|
447
456
|
constructor(id: string, userData?: SpatialEntityUserData | undefined);
|
|
448
457
|
addComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
449
458
|
setPosition(position: Vec3): Promise<CommandResult>;
|
|
@@ -523,6 +532,16 @@ declare class SpatialModelAsset extends SpatialObject {
|
|
|
523
532
|
constructor(id: string, options: ModelAssetOptions);
|
|
524
533
|
}
|
|
525
534
|
|
|
535
|
+
declare class Attachment extends SpatialObject {
|
|
536
|
+
private readonly windowProxy;
|
|
537
|
+
private options;
|
|
538
|
+
constructor(id: string, windowProxy: WindowProxy, options: AttachmentEntityOptions);
|
|
539
|
+
getContainer(): HTMLElement;
|
|
540
|
+
getWindowProxy(): WindowProxy;
|
|
541
|
+
update(options: AttachmentEntityUpdateOptions): Promise<CommandResult | undefined>;
|
|
542
|
+
}
|
|
543
|
+
declare function createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
544
|
+
|
|
526
545
|
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
527
546
|
type: SpatialSceneType$1;
|
|
528
547
|
}): void;
|
|
@@ -550,6 +569,7 @@ declare class SpatialScene extends SpatialObject {
|
|
|
550
569
|
* @returns The singleton SpatialScene instance
|
|
551
570
|
*/
|
|
552
571
|
static getInstance(): SpatialScene;
|
|
572
|
+
convertCoordinate(position: Vec3, fromId: string, toId: string): Promise<Vec3>;
|
|
553
573
|
/**
|
|
554
574
|
* Updates the properties of the spatial scene.
|
|
555
575
|
* This can include background settings, lighting, and other scene-wide properties.
|
|
@@ -614,6 +634,13 @@ declare class Spatialized2DElement extends SpatializedElement {
|
|
|
614
634
|
* and provides events for load success and failure.
|
|
615
635
|
*/
|
|
616
636
|
declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
637
|
+
/**
|
|
638
|
+
* Creates a new spatialized static 3D element with the specified ID and URL.
|
|
639
|
+
* Registers the element to receive spatial events.
|
|
640
|
+
* @param id Unique identifier for this element
|
|
641
|
+
* @param modelURL URL of the 3D model
|
|
642
|
+
*/
|
|
643
|
+
constructor(id: string, modelURL: string);
|
|
617
644
|
/**
|
|
618
645
|
* Promise resolver for the ready state.
|
|
619
646
|
* Used to resolve the ready promise when the model is loaded.
|
|
@@ -694,7 +721,7 @@ declare class SpatialSession {
|
|
|
694
721
|
* @param modelURL Optional URL to the 3D model to load
|
|
695
722
|
* @returns Promise resolving to a new SpatializedStatic3DElement instance
|
|
696
723
|
*/
|
|
697
|
-
createSpatializedStatic3DElement(modelURL
|
|
724
|
+
createSpatializedStatic3DElement(modelURL: string): Promise<SpatializedStatic3DElement>;
|
|
698
725
|
/**
|
|
699
726
|
* Initializes the spatial scene with custom configuration.
|
|
700
727
|
* This is a reference to the initScene function from scene-polyfill.
|
|
@@ -771,6 +798,13 @@ declare class SpatialSession {
|
|
|
771
798
|
* @returns Promise resolving to a new SpatialModelEntity instance
|
|
772
799
|
*/
|
|
773
800
|
createSpatialModelEntity(options: SpatialModelEntityCreationOptions, userData?: SpatialEntityUserData): Promise<SpatialModelEntity>;
|
|
801
|
+
/**
|
|
802
|
+
* Creates an attachment entity that renders 2D HTML content as a child
|
|
803
|
+
* of a 3D entity in the scene graph.
|
|
804
|
+
* @param options Configuration options including parent entity ID, position, and size
|
|
805
|
+
* @returns Promise resolving to a new Attachment instance
|
|
806
|
+
*/
|
|
807
|
+
createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
774
808
|
}
|
|
775
809
|
|
|
776
810
|
/**
|
|
@@ -778,6 +812,7 @@ declare class SpatialSession {
|
|
|
778
812
|
* This is the main entry point for the WebSpatial SDK, providing access to spatial capabilities.
|
|
779
813
|
*/
|
|
780
814
|
declare class Spatial {
|
|
815
|
+
private wsAppShellVersionFromUA;
|
|
781
816
|
/**
|
|
782
817
|
* Requests a spatial session object from the browser.
|
|
783
818
|
* This is the primary method to initialize spatial functionality.
|
|
@@ -791,6 +826,7 @@ declare class Spatial {
|
|
|
791
826
|
* @returns True if running in a spatial web environment, false otherwise
|
|
792
827
|
*/
|
|
793
828
|
runInSpatialWeb(): boolean;
|
|
829
|
+
getShellVersionFromUA(): string | null;
|
|
794
830
|
/** @deprecated
|
|
795
831
|
* Checks if WebSpatial is supported in the current environment.
|
|
796
832
|
* Verifies compatibility between native and client versions.
|
|
@@ -811,6 +847,53 @@ declare class Spatial {
|
|
|
811
847
|
getClientVersion(): string;
|
|
812
848
|
}
|
|
813
849
|
|
|
850
|
+
type PhysicalMetricsValueShape = {
|
|
851
|
+
meterToPtUnscaled: number;
|
|
852
|
+
meterToPtScaled: number;
|
|
853
|
+
};
|
|
854
|
+
type WorldScalingCompensation = 'unscaled' | 'scaled';
|
|
855
|
+
type ConvertOption = {
|
|
856
|
+
worldScalingCompensation: WorldScalingCompensation;
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* Converts scene points (pt) to physical meters (m).
|
|
860
|
+
*
|
|
861
|
+
* @param point Points value to convert.
|
|
862
|
+
* @param options Optional conversion options to select world scaling compensation.
|
|
863
|
+
* @returns Physical length in meters.
|
|
864
|
+
*/
|
|
865
|
+
declare function pointToPhysical(point: number, options?: ConvertOption): number;
|
|
866
|
+
/**
|
|
867
|
+
* Converts physical meters (m) to scene points (pt).
|
|
868
|
+
*
|
|
869
|
+
* @param physical Physical length in meters to convert.
|
|
870
|
+
* @param options Optional conversion options to select world scaling compensation.
|
|
871
|
+
* @returns Points length in the scene.
|
|
872
|
+
*/
|
|
873
|
+
declare function physicalToPoint(physical: number, options?: ConvertOption): number;
|
|
874
|
+
/**
|
|
875
|
+
* Returns the current physical metrics used for conversions.
|
|
876
|
+
*
|
|
877
|
+
* @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.
|
|
878
|
+
*/
|
|
879
|
+
declare function getValue(): PhysicalMetricsValueShape;
|
|
880
|
+
/**
|
|
881
|
+
* Subscribes to physical metrics changes.
|
|
882
|
+
*
|
|
883
|
+
* @param cb Callback invoked when metrics update is detected.
|
|
884
|
+
* @returns Unsubscribe function to remove the listener.
|
|
885
|
+
*/
|
|
886
|
+
declare function subscribe(cb: () => void): () => void;
|
|
887
|
+
|
|
888
|
+
type physicalMetrics_PhysicalMetricsValueShape = PhysicalMetricsValueShape;
|
|
889
|
+
declare const physicalMetrics_getValue: typeof getValue;
|
|
890
|
+
declare const physicalMetrics_physicalToPoint: typeof physicalToPoint;
|
|
891
|
+
declare const physicalMetrics_pointToPhysical: typeof pointToPhysical;
|
|
892
|
+
declare const physicalMetrics_subscribe: typeof subscribe;
|
|
893
|
+
declare namespace physicalMetrics {
|
|
894
|
+
export { type physicalMetrics_PhysicalMetricsValueShape as PhysicalMetricsValueShape, physicalMetrics_getValue as getValue, physicalMetrics_physicalToPoint as physicalToPoint, physicalMetrics_pointToPhysical as pointToPhysical, physicalMetrics_subscribe as subscribe };
|
|
895
|
+
}
|
|
896
|
+
|
|
814
897
|
declare global {
|
|
815
898
|
declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
|
|
816
899
|
|
|
@@ -841,19 +924,19 @@ declare global {
|
|
|
841
924
|
'natvie-version'?: string
|
|
842
925
|
'react-sdk-version'?: string
|
|
843
926
|
'core-sdk-version'?: string
|
|
927
|
+
physicalMetrics?: PhysicalMetricsValueShape
|
|
844
928
|
}
|
|
845
929
|
|
|
846
|
-
|
|
847
|
-
|
|
930
|
+
xrInnerDepth: number
|
|
931
|
+
xrOuterDepth: number
|
|
848
932
|
}
|
|
849
933
|
|
|
850
934
|
interface HTMLElement {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
getBoundingClientCube: () => CubeInfo | undefined
|
|
935
|
+
xrOffsetBack: number
|
|
936
|
+
xrClientDepth: number
|
|
854
937
|
}
|
|
855
938
|
}
|
|
856
939
|
|
|
857
940
|
declare const isSSREnv: () => boolean;
|
|
858
941
|
|
|
859
|
-
export { type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo
|
|
942
|
+
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 };
|
|
@@ -2,9 +2,74 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['core-sdk-version'] = "1.
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.4.0"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
|
-
"use strict";var webspatialCore=(()=>{var Vt=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Be=Object.prototype.hasOwnProperty;var h=(i,e)=>()=>(i&&(e=i(i=0)),e);var q=(i,e)=>{for(var t in e)Vt(i,t,{get:e[t],enumerable:!0})},Le=(i,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of _e(e))!Be.call(i,r)&&r!==t&&Vt(i,r,{get:()=>e[r],enumerable:!(a=Ae(e,r))||a.enumerable});return i};var H=i=>Le(Vt({},"__esModule",{value:!0}),i);var Ue,G,At=h(()=>{"use strict";Ue=typeof window>"u",G=()=>Ue});var X,Yt=h(()=>{"use strict";X=class{callJSB(e,t){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocol(e,t,a,r){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocolSync(e,t,a,r,n){return{success:!0,data:void 0,errorCode:void 0,errorMessage:void 0}}}});function y(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function g(i,e=""){return{success:!1,data:void 0,errorCode:i,errorMessage:e}}var Q=h(()=>{"use strict"});var c,P=h(()=>{"use strict";c=class i{static eventReceiver={};static init(){window.__SpatialWebEvent=({id:e,data:t})=>{i.eventReceiver[e]?.(t)}}static addEventReceiver(e,t){i.eventReceiver[e]=t}static removeEventReceiver(e){delete i.eventReceiver[e]}}});var ee={};q(ee,{XRPlatform:()=>Bt});function te(){return _t=(_t+1)%je,`rId_${_t}`}var _t,je,Bt,ie=h(()=>{"use strict";Q();P();_t=0,je=1e5;Bt=class{async callJSB(e,t){return new Promise((a,r)=>{try{let n=te();c.addEventReceiver(n,s=>{if(c.removeEventReceiver(n),s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}});let o=window.webspatialBridge.postMessage(n,e,t);if(o!==""){c.removeEventReceiver(n);let s=JSON.parse(o);if(s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}}}catch(n){console.error(`XRPlatform cmd: ${e}, msg: ${t} error: ${n}`);let{code:o,message:s}=n;a(g(o,s))}})}async callWebSpatialProtocol(e,t,a,r){return new Promise((n,o)=>{let s=te();try{let p=null;c.addEventReceiver(s,u=>{console.log("createdId",s,u.spatialId),n(y({windowProxy:p,id:u.spatialId})),c.removeEventReceiver(s)}),p=this.openWindow(e,t,a,r).windowProxy,p?.open(`about:blank?rid=${s}`,"_self")}catch(p){console.error(`open window error: ${p}`);let{code:u,message:Wt}=p;c.removeEventReceiver(s),n(g(u,Wt))}})}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return y({windowProxy:o,id:n})}openWindow(e,t,a,r){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,a,r)}}}});var ae={};q(ae,{AndroidPlatform:()=>jt});function Fe(){return Ut=(Ut+1)%ke,`rId_${Ut}`}var Lt,Ut,ke,jt,re=h(()=>{"use strict";Q();S();P();Lt=0,Ut=0,ke=1e5;jt=class{async callJSB(e,t){return new Promise((a,r)=>{try{let n=Fe();c.addEventReceiver(n,s=>{if(c.removeEventReceiver(n),s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}});let o=window.webspatialBridge.postMessage(n,e,t);if(o!==""){c.removeEventReceiver(n);let s=JSON.parse(o);if(s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}}}catch(n){console.error(`AndroidPlatform cmd: ${e}, msg: ${t} error: ${n}`);let{code:o,message:s}=n;a(g(o,s))}})}async callWebSpatialProtocol(e,t,a,r){await new Promise(p=>setTimeout(p,16*Lt)),Lt++;let n=await new W().execute();for(;!n.data.can;)await new Promise(p=>setTimeout(p,16)),n=await new W().execute();let{windowProxy:o}=this.openWindow(e,t,a,r);for(;!o?.open;)await new Promise(p=>setTimeout(p,16));for(o?.open("about:blank","_self");!o?.__SpatialId;)await new Promise(p=>setTimeout(p,16));let s=o?.__SpatialId;return Lt--,Promise.resolve(y({windowProxy:o,id:s}))}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return y({windowProxy:o,id:n})}openWindow(e,t,a,r){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,a,r)}}}});var ne={};q(ne,{VisionOSPlatform:()=>kt});var kt,oe=h(()=>{"use strict";Q();kt=class{async callJSB(e,t){try{let a=await window.webkit.messageHandlers.bridge.postMessage(`${e}::${t}`);return y(a)}catch(a){let{code:r,message:n}=JSON.parse(a.message);return g(r,n)}}callWebSpatialProtocol(e,t,a,r){let{spatialId:n,windowProxy:o}=this.openWindow(e,t,a,r);return Promise.resolve(y({windowProxy:o,id:n}))}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return y({windowProxy:o,id:n})}openWindow(e,t,a,r){let n=window.open(`webspatial://${e}?${t||""}`,a,r);return{spatialId:n?.navigator.userAgent?.match(/\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi)?.[0],windowProxy:n}}}});function Ne(i){let e=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:null}function $e(i,e){if(!i)return!1;for(let t=0;t<3;t+=1){let a=i[t]-e[t];if(a>0)return!0;if(a<0)return!1}return!1}function se(){if(G())return new X;let i=window.navigator.userAgent,e=Ne(i);if(i.includes("PicoWebApp")&&$e(e,[0,0,1])){let t=(ie(),H(ee)).XRPlatform;return new t}else if(i.includes("Android")||i.includes("Linux")){let t=(re(),H(ae)).AndroidPlatform;return new t}else{let t=(oe(),H(ne)).VisionOSPlatform;return new t}}var pe=h(()=>{"use strict";At();Yt()});function K(i,e){return i===""?0:i.endsWith("%")?e*parseFloat(i)/100:parseFloat(i)}function le(i){let e=parseFloat(i.getPropertyValue("width")),t=i.getPropertyValue("border-top-left-radius"),a=i.getPropertyValue("border-top-right-radius"),r=i.getPropertyValue("border-bottom-left-radius"),n=i.getPropertyValue("border-bottom-right-radius");return{topLeading:K(t,e),bottomLeading:K(r,e),topTrailing:K(a,e),bottomTrailing:K(n,e)}}function ce(i,e,t){let{x:a,y:r,z:n}=i,{x:o,y:s,z:p}=e,{x:u,y:Wt,z:Ve}=t,w=new DOMMatrix;return w=w.translate(a,r,n),w=w.rotate(o,s,p),w=w.scale(u,Wt,Ve),w}var Ft=h(()=>{"use strict"});var Nt,l,Z,Y,tt,et,it,at,x,rt,nt,ot,st,pt,lt,ct,dt,mt,ut,yt,St,ft,gt,ht,Et,M,bt,xt,vt,wt,Pt,W,Mt,Dt,Rt,S=h(()=>{"use strict";pe();Ft();Nt=se(),l=class{commandType="";async execute(){let e=this.getParams(),t=e?JSON.stringify(e):"";return Nt.callJSB(this.commandType,t)}},Z=class extends l{constructor(t,a){super();this.entity=t;this.properties=a}commandType="UpdateEntityProperties";getParams(){let t=ce(this.properties.position??this.entity.position,this.properties.rotation??this.entity.rotation,this.properties.scale??this.entity.scale).toFloat64Array();return{entityId:this.entity.id,transform:t}}},Y=class extends l{constructor(t,a,r){super();this.entity=t;this.type=a;this.isEnable=r}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}},tt=class extends l{properties;commandType="UpdateSpatialSceneProperties";constructor(e){super(),this.properties=e}getParams(){return this.properties}},et=class extends l{config;commandType="UpdateSceneConfig";constructor(e){super(),this.config=e}getParams(){return{config:this.config}}},it=class extends l{constructor(t){super();this.id=t}commandType="FocusScene";getParams(){return{id:this.id}}},at=class extends l{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},x=class extends l{constructor(t){super();this.spatialObject=t}getParams(){let t=this.getExtraParams();return{id:this.spatialObject.id,...t}}},rt=class extends x{properties;commandType="UpdateSpatialized2DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},nt=class extends x{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},ot=class extends x{properties;commandType="UpdateUnlitMaterialProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},st=class extends x{matrix;commandType="UpdateSpatializedElementTransform";constructor(e,t){super(e),this.matrix=t}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},pt=class extends x{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},lt=class extends x{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(e,t){super(e),this.spatializedElement=t}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},ct=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(e){super(),this.spatializedElement=e}getParams(){return{spatializedElementId:this.spatializedElement.id}}},dt=class extends l{constructor(t){super();this.modelURL=t;this.modelURL=t}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},mt=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},ut=class extends l{constructor(t){super();this.name=t}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},yt=class extends l{constructor(t){super();this.options=t}getParams(){let t=this.options.mesh.id,a=this.options.materials.map(r=>r.id);return{geometryId:t,materialIds:a}}commandType="CreateModelComponent"},St=class extends l{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ft=class extends l{constructor(t){super();this.options=t}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},gt=class extends l{constructor(t,a={}){super();this.type=t;this.options=a}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},ht=class extends l{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateUnlitMaterial"},Et=class extends l{constructor(t,a){super();this.entity=t;this.comp=a}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},M=class extends l{constructor(t,a){super();this.childId=t;this.parentId=a}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},bt=class extends l{constructor(t,a,r){super();this.fromEntityId=t;this.toEntityId=a;this.fromPosition=r}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},xt=class extends l{constructor(t,a){super();this.fromEntityId=t;this.position=a}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},vt=class extends l{constructor(t,a){super();this.entityId=t;this.position=a}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},wt=class extends l{constructor(t=""){super();this.id=t}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Pt=class extends l{constructor(t){super();this.id=t}commandType="Destroy";getParams(){return{id:this.id}}},W=class extends l{constructor(t=""){super();this.id=t}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},Mt=class extends l{target;features;async execute(){let e=this.getQuery();return Nt.callWebSpatialProtocol(this.commandType,e,this.target,this.features)}executeSync(){let e=this.getQuery();return Nt.callWebSpatialProtocolSync(this.commandType,e,this.target,this.features)}getQuery(){let e,t=this.getParams();return t&&(e=Object.keys(t).map(a=>{let r=t[a],n=typeof r=="object"?JSON.stringify(r):r;return`${a}=${encodeURIComponent(n)}`}).join("&")),e}},Dt=class extends Mt{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Rt=class extends Mt{constructor(t,a,r,n){super();this.url=t;this.config=a;this.target=r;this.features=n}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}}});var ri={};q(ri,{BaseplateVisibilityValues:()=>me,CubeInfo:()=>V,ModelComponent:()=>B,Spatial:()=>I,SpatialBoxGeometry:()=>k,SpatialComponent:()=>_,SpatialConeGeometry:()=>J,SpatialCylinderGeometry:()=>N,SpatialEntity:()=>D,SpatialGeometry:()=>f,SpatialMaterial:()=>L,SpatialModelAsset:()=>j,SpatialModelEntity:()=>A,SpatialObject:()=>d,SpatialPlaneGeometry:()=>$,SpatialScene:()=>b,SpatialSceneState:()=>Qt,SpatialSceneValues:()=>Se,SpatialSession:()=>z,SpatialSphereGeometry:()=>F,SpatialUnlitMaterial:()=>U,Spatialized2DElement:()=>R,SpatializedDynamic3DElement:()=>C,SpatializedElement:()=>E,SpatializedElementType:()=>de,SpatializedStatic3DElement:()=>T,WorldAlignmentValues:()=>ye,WorldScalingValues:()=>ue,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>Jt,isValidSceneUnit:()=>Tt,isValidSpatialSceneType:()=>Xt,isValidWorldAlignmentType:()=>Ht,isValidWorldScalingType:()=>qt});S();var d=class{constructor(e){this.id=e}name;isDestroyed=!1;async inspect(){let e=await new wt(this.id).execute();if(e.success)return e.data;throw new Error(e.errorMessage)}async destroy(){if(this.isDestroyed)return;let e=await new Pt(this.id).execute();if(e.success)return this.onDestroy(),this.isDestroyed=!0,e.data;if(this.isDestroyed)return;throw new Error(e.errorMessage)}onDestroy(){}};S();S();var $t,b=class i extends d{static getInstance(){return $t||($t=new i("")),$t}async updateSpatialProperties(e){return new tt(e).execute()}async addSpatializedElement(e){return new ct(e).execute()}async updateSceneCreationConfig(e){return new et(e).execute()}async getState(){return(await new at().execute()).data.name}};var de=(a=>(a[a.Spatialized2DElement=0]="Spatialized2DElement",a[a.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",a[a.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",a))(de||{}),me=["automatic","visible","hidden"];function Jt(i){return me.includes(i)}var ue=["automatic","dynamic"];function qt(i){return ue.includes(i)}var ye=["adaptive","automatic","gravityAligned"];function Ht(i){return ye.includes(i)}var Se=["window","volume"];function Xt(i){return Se.includes(i)}function Tt(i){if(typeof i=="number")return i>=0;if(typeof i=="string"){if(i.endsWith("px"))return isNaN(Number(i.slice(0,-2)))?!1:Number(i.slice(0,-2))>=0;if(i.endsWith("m"))return isNaN(Number(i.slice(0,-1)))?!1:Number(i.slice(0,-1))>=0}return!1}var Qt=(n=>(n.idle="idle",n.pending="pending",n.willVisible="willVisible",n.visible="visible",n.fail="fail",n))(Qt||{}),V=class{constructor(e,t){this.size=e;this.origin=t;this.size=e,this.origin=t}get x(){return this.origin.x}get y(){return this.origin.y}get z(){return this.origin.z}get width(){return this.size.width}get height(){return this.size.height}get depth(){return this.size.depth}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get back(){return this.z}get front(){return this.z+this.depth}};var Je={defaultSize:{width:1280,height:720}},qe={defaultSize:{width:.94,height:.94,depth:.94}},He="webspatial://",Ct=class i{originalOpen;static instance;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(e){this.originalOpen=e.open.bind(e),e.open=this.open}configMap={};getConfig(e){if(!(e===void 0||!this.configMap[e]))return this.configMap[e]}ensureAbsoluteUrl(e){if(!e||/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e))return e;if(e.startsWith("//"))return`${window.location.protocol}${e}`;try{return new URL(e,document.baseURI).toString()}catch{return e}}open=(e,t,a)=>{if(e?.startsWith(He))return this.originalOpen(e,t,a);if(e=this.ensureAbsoluteUrl(e),t==="_self"||t==="_parent"||t==="_top")return this.originalOpen(e,t,a);let r=t?this.getConfig(t):void 0,o=new Rt(e,r,t,a).executeSync(),s=o.data?.id;return s&&new it(s).execute(),o.data?.windowProxy};initScene(e,t,a){let r=a?.type??"window",n=Zt(r),o=t({...n}),[s,p]=Ee(o,r);p.length>0&&console.warn(`initScene ${e} with errors: ${p.join(", ")}`),this.configMap[e]={...s,type:r}}};function fe(i){return i/1360}function ge(i){return i*1360}function he(i,e,t){if(typeof i=="number")return t==="px"&&e==="px"||t==="m"&&e==="m"?i:t==="px"&&e==="m"?fe(i):t==="m"&&e==="px"?ge(i):i;if(e==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return fe(Number(i.slice(0,-2)));throw new Error("formatToNumber: invalid str")}else if(e==="px"){if(i.endsWith("px"))return Number(i.slice(0,-2));if(i.endsWith("m"))return ge(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function Ee(i,e){let t=Zt(e),a=[],r=e==="window";if(Xt(e)||a.push("sceneType"),i.defaultSize){let n=["width","height","depth"];for(let o of n)o in i.defaultSize&&(Tt(i.defaultSize[o])?i.defaultSize[o]=he(i.defaultSize[o],r?"px":"m",r?"px":"m"):(i.defaultSize[o]=t.defaultSize[o],a.push(`defaultSize.${o}`)))}if(i.resizability){let n=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of n)o in i.resizability&&(Tt(i.resizability[o])?i.resizability[o]=he(i.resizability[o],"px",r?"px":"m"):(i.resizability[o]=void 0,a.push(`resizability.${o}`)))}return i.worldScaling&&(qt(i.worldScaling)||(i.worldScaling="automatic",a.push("worldScaling"))),i.worldAlignment&&(Ht(i.worldAlignment)||(i.worldAlignment="automatic",a.push("worldAlignment"))),i.baseplateVisibility&&(Jt(i.baseplateVisibility)||(i.baseplateVisibility="automatic",a.push("baseplateVisibility"))),[i,a]}function be(i,e,t){return Ct.getInstance().initScene(i,e,t)}function Xe(i){Ct.getInstance().init(i)}function Kt(i){i.document.onclick=function(e){let t=e.target,a=!1;for(;!a;){if(t&&t.tagName=="A")return!Qe(e);if(t&&t.parentElement)t=t.parentElement;else break}}}function Qe(i){let e=i.target;if(e.tagName==="A"){let t=e,a=t.target,r=t.href;if(a&&a!=="_self")return i.preventDefault(),window.open(r,a),!0}}function Zt(i){return i==="window"?Je:qe}async function Ke(){if(!window.opener||await b.getInstance().getState()!=="pending")return;function e(t){document.readyState==="interactive"||document.readyState==="complete"?t():document.addEventListener("DOMContentLoaded",t)}e(async()=>{let t=Zt(window.xrCurrentSceneType??"window"),a=t;if(typeof window.xrCurrentSceneDefaults=="function")try{a=await window.xrCurrentSceneDefaults?.(t)}catch(s){console.error(s)}await new Promise((s,p)=>{setTimeout(()=>{s(null)},1e3)});let r=window.xrCurrentSceneType??"window",[n,o]=Ee(a,r);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await b.getInstance().updateSceneCreationConfig({...n,type:r})})}function xe(){Xe(window),Kt(window),Ke()}S();S();S();P();function m(i,e){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:e})}var E=class extends d{constructor(t){super(t);this.id=t;c.addEventReceiver(t,this.onReceiveEvent.bind(this))}async updateTransform(t){return new st(this,t).execute()}_cubeInfo;get cubeInfo(){return this._cubeInfo}_transform;_transformInv;get transform(){return this._transform}get transformInv(){return this._transformInv}onReceiveEvent(t){let{type:a}=t;if(a==="objectdestroy")this.isDestroyed=!0;else if(a==="cubeInfo"){let r=t;this._cubeInfo=new V(r.size,r.origin)}else if(a==="transform")this._transform=new DOMMatrix([t.detail.column0[0],t.detail.column0[1],t.detail.column0[2],0,t.detail.column1[0],t.detail.column1[1],t.detail.column1[2],0,t.detail.column2[0],t.detail.column2[1],t.detail.column2[2],0,t.detail.column3[0],t.detail.column3[1],t.detail.column3[2],1]),this._transformInv=this._transform.inverse();else if(a==="spatialtap"){let r=m("spatialtap",t.detail);this._onSpatialTap?.(r)}else if(a==="spatialdragstart"){let r=m("spatialdragstart",t.detail);this._onSpatialDragStart?.(r)}else if(a==="spatialdrag"){let r=m("spatialdrag",t.detail);this._onSpatialDrag?.(r)}else if(a==="spatialdragend"){let r=m("spatialdragend",t.detail);this._onSpatialDragEnd?.(r)}else if(a==="spatialrotate"){let r=m("spatialrotate",t.detail);this._onSpatialRotate?.(r)}else if(a==="spatialrotateend"){let r=m("spatialrotateend",t.detail);this._onSpatialRotateEnd?.(r)}else if(a==="spatialmagnify"){let r=m("spatialmagnify",t.detail);this._onSpatialMagnify?.(r)}else if(a==="spatialmagnifyend"){let r=m("spatialmagnifyend",t.detail);this._onSpatialMagnifyEnd?.(r)}}_onSpatialTap;set onSpatialTap(t){this._onSpatialTap=t,this.updateProperties({enableTapGesture:t!==void 0})}_onSpatialDragStart;set onSpatialDragStart(t){this._onSpatialDragStart=t,this.updateProperties({enableDragStartGesture:this._onSpatialDragStart!==void 0})}_onSpatialDrag;set onSpatialDrag(t){this._onSpatialDrag=t,this.updateProperties({enableDragGesture:this._onSpatialDrag!==void 0})}_onSpatialDragEnd;set onSpatialDragEnd(t){this._onSpatialDragEnd=t,this.updateProperties({enableDragEndGesture:t!==void 0})}_onSpatialRotate;set onSpatialRotate(t){this._onSpatialRotate=t,this.updateProperties({enableRotateGesture:this._onSpatialRotate!==void 0})}_onSpatialRotateEnd;set onSpatialRotateEnd(t){this._onSpatialRotateEnd=t,this.updateProperties({enableRotateEndGesture:t!==void 0})}_onSpatialMagnify;set onSpatialMagnify(t){this._onSpatialMagnify=t,this.updateProperties({enableMagnifyGesture:t!==void 0})}_onSpatialMagnifyEnd;set onSpatialMagnifyEnd(t){this._onSpatialMagnifyEnd=t,this.updateProperties({enableMagnifyEndGesture:t!==void 0})}onDestroy(){c.removeEventReceiver(this.id)}};var R=class extends E{constructor(t,a){super(t);this.windowProxy=a;Kt(a)}async updateProperties(t){return new rt(this,t).execute()}async addSpatializedElement(t){return new lt(this,t).execute()}};S();var T=class extends E{_readyResolve;modelURL="";createReadyPromise(){return new Promise(e=>{this._readyResolve=e})}ready=this.createReadyPromise();async updateProperties(e){return e.modelURL!==void 0&&this.modelURL!==e.modelURL&&(this.modelURL=e.modelURL,this.ready=this.createReadyPromise()),new pt(this,e).execute()}onReceiveEvent(e){e.type==="modelloaded"?(this._onLoadCallback?.(),this._readyResolve?.(!0)):e.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):super.onReceiveEvent(e)}_onLoadCallback;set onLoadCallback(e){this._onLoadCallback=e}_onLoadFailureCallback;set onLoadFailureCallback(e){this._onLoadFailureCallback=e}updateModelTransform(e){let t=Array.from(e.toFloat64Array());this.updateProperties({modelTransform:t})}};S();var C=class extends E{children=[];constructor(e){super(e)}async addEntity(e){let t=new M(e.id,this.id).execute();return this.children.push(e),e.parent=this,t}async updateProperties(e){return new nt(this,e).execute()}};async function ve(){let i=await new Dt().execute();if(i.success){let{id:e,windowProxy:t}=i.data;return t.document.head.innerHTML=`<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
-
|
|
8
|
+
"use strict";var webspatialCore=(()=>{var Bt=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var h=(i,t)=>()=>(i&&(t=i(i=0)),t);var R=(i,t)=>{for(var e in t)Bt(i,e,{get:t[e],enumerable:!0})},Ze=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Qe(t))!Ke.call(i,n)&&n!==e&&Bt(i,n,{get:()=>t[n],enumerable:!(r=Xe(t,n))||r.enumerable});return i};var V=i=>Ze(Bt({},"__esModule",{value:!0}),i);var Ye,G,$t=h(()=>{"use strict";Ye=typeof window>"u",G=()=>Ye});var K,le=h(()=>{"use strict";K=class{callJSB(t,e){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocol(t,e,r,n){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocolSync(t,e,r,n,a){return{success:!0,data:void 0,errorCode:void 0,errorMessage:void 0}}}});function m(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function S(i,t=""){return{success:!1,data:void 0,errorCode:i,errorMessage:t}}var _=h(()=>{"use strict"});var ce={};R(ce,{PuppeteerPlatform:()=>Ft});var Ft,de=h(()=>{"use strict";_();console.log("PuppeteerPlatform");Ft=class{iframeRegistry=new Map;constructor(){}callJSB(t,e){return new Promise(r=>{try{if(window.__handleJSBMessage)try{console.log(` core-sdk Puppeteer Platform: callJSB: ${t}::${e}`);let n=window.__handleJSBMessage(`${t}::${e}`);console.log(` core-sdk Puppeteer Platform callJSB result: ${n}`),r(m(n))}catch{r(S("500","JSB execution error"))}else r(m("ok"))}catch(n){console.error(`PuppeteerPlatform cmd Error: ${t}, msg: ${e} error: ${n}`),r(S("500","Internal error"))}})}createSpatializedElementSync(t,e){try{console.log(`[Puppeteer Platform] Creating spatialized element sync with id: ${t}, url: ${e}`);let r=window;if(r.__handleJSBMessage){let n={id:t,url:e};r.__handleJSBMessage(`CreateSpatialized2DElement::${JSON.stringify(n)}`)}}catch(r){console.error("Error creating spatialized element sync:",r)}}callWebSpatialProtocol(t,e,r,n){return console.log(`PuppeteerPlatform: Calling webspatial protocol: webspatial://${t}${e?`?${e}`:""}`),new Promise(a=>{try{let o=`webspatial://${t}${e?`?${e}`:""}`,{spatialId:s,iframe:p,windowProxy:y}=this.createIframeWindow(o,r,n);t==="createSpatialized2DElement"&&this.createSpatializedElementSync(s,o),console.log(`[Puppeteer Platform] iframe created with spatialId: ${s}`),this.iframeRegistry.set(s,p),a(m({windowProxy:y,id:s}))}catch(o){console.error("Error calling webspatial protocol:",o),a(S("500","Failed to call webspatial protocol"))}})}callWebSpatialProtocolSync(t,e,r,n){try{let a=`webspatial://${t}${e?`?${e}`:""}`;console.log(`Calling webspatial protocol sync: ${a}`);let{spatialId:o,iframe:s,windowProxy:p}=this.createIframeWindow(a,r,n);return t==="createSpatialized2DElement"&&this.createSpatializedElementSync(o,a),this.iframeRegistry.set(o,s),m({windowProxy:p,id:o})}catch(a){return console.error("Error calling webspatial protocol sync:",a),S("500","Failed to call webspatial protocol sync")}}createIframeWindow(t,e,r){let n=document.createElement("iframe");n.style.border="none",n.style.display="none",n.style.width="100%",n.style.height="100%";let a=this.generateUUID();n.spatialId=a,n.id=`spatial-iframe-${a}`;let o=this.parseFeatures(r||"");o.width&&(n.style.width=o.width),o.height&&(n.style.height=o.height),o.left&&(n.style.left=o.left,n.style.position="absolute"),o.top&&(n.style.top=o.top,n.style.position="absolute"),document.body.appendChild(n);let s=this.createEnhancedWindowProxy(n,t,a);return n.src="about:blank",console.log(`PuppeteerPlatform created iframe window with spatialId: ${a}, URL: ${t}`),this.initializeIframeContent(n,t,a),{spatialId:a,iframe:n,windowProxy:s}}createEnhancedWindowProxy(t,e,r){return{location:{href:e,toString:()=>e,reload:()=>{t.contentWindow&&t.contentWindow.location.reload()}},navigator:{userAgent:`Mozilla/5.0 (WebKit) SpatialId/${r}`},close:()=>{console.log(`Closing iframe with spatialId: ${r}`),t.remove(),this.iframeRegistry.delete(r)},document:t.contentDocument||{},contentWindow:t.contentWindow||{},postMessage:(n,a)=>{t.contentWindow&&t.contentWindow.postMessage(n,a||"*")},addEventListener:(n,a)=>{t.contentWindow&&t.contentWindow.addEventListener(n,a)},removeEventListener:(n,a)=>{t.contentWindow&&t.contentWindow.removeEventListener(n,a)},executeScript:n=>{if(t.contentWindow)try{return t.contentWindow.eval(n)}catch(a){return console.error(`Error executing script in iframe ${r}:`,a),null}return null},getIframe:()=>t,getSpatialId:()=>r}}initializeIframeContent(t,e,r){try{t.onload=()=>{try{let n=`
|
|
9
|
+
// inject communication script
|
|
10
|
+
window.webSpatialId = '${r}';
|
|
11
|
+
window.SpatialId = '${r}';
|
|
12
|
+
|
|
13
|
+
// override window.open to support webspatial protocol
|
|
14
|
+
const originalOpen = window.open;
|
|
15
|
+
window.open = function(url, target, features) {
|
|
16
|
+
if (url && url.startsWith('webspatial://')) {
|
|
17
|
+
// handle webspatial protocol through windowProxy
|
|
18
|
+
const windowProxy = new Proxy({}, {
|
|
19
|
+
get: function(target, prop) {
|
|
20
|
+
if (prop === 'toString') {
|
|
21
|
+
return function() { return url; };
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return windowProxy;
|
|
27
|
+
}
|
|
28
|
+
return originalOpen.call(window, url, target, features);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// set navigator.userAgent to identify webspatial environment
|
|
32
|
+
Object.defineProperty(navigator, 'userAgent', {
|
|
33
|
+
value: 'WebSpatial/1.0 ' + navigator.userAgent,
|
|
34
|
+
configurable: true
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// send loaded message
|
|
38
|
+
window.parent.postMessage({
|
|
39
|
+
type: 'iframe_loaded',
|
|
40
|
+
spatialId: '${r}',
|
|
41
|
+
url: '${e}'
|
|
42
|
+
}, '${window.location.origin}');
|
|
43
|
+
|
|
44
|
+
// set message handler
|
|
45
|
+
window.addEventListener('message', (event) => {
|
|
46
|
+
if (event.origin !== window.parent.location.origin) return;
|
|
47
|
+
|
|
48
|
+
const data = event.data;
|
|
49
|
+
if (data && data.type === 'webspatial_command') {
|
|
50
|
+
// handle command from parent window
|
|
51
|
+
console.log('Received command in iframe from parent:', data.command);
|
|
52
|
+
// add command handling logic here
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
`,a=t.contentDocument;a&&(a.open(),a.write(`
|
|
56
|
+
<!DOCTYPE html>
|
|
57
|
+
<html>
|
|
58
|
+
<head>
|
|
59
|
+
<title>Spatial Iframe - ${r}</title>
|
|
60
|
+
<meta charset="UTF-8">
|
|
61
|
+
<style>
|
|
62
|
+
body {
|
|
63
|
+
margin: 0;
|
|
64
|
+
padding: 0;
|
|
65
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
66
|
+
}
|
|
67
|
+
</style>
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
<script>${n}</script>
|
|
71
|
+
</body>
|
|
72
|
+
</html>
|
|
73
|
+
`),a.close())}catch(n){console.error("Error initializing iframe content:",n)}}}catch(n){console.error("Error setting up iframe:",n)}}parseFeatures(t){let e={};return t.split(",").forEach(n=>{let[a,o]=n.split("=").map(s=>s.trim());a&&o&&(e[a]=o)}),e}sendMessageToIframe(t,e){let r=this.iframeRegistry.get(t);return r&&r.contentWindow?(r.contentWindow.postMessage(e,window.location.origin),!0):!1}getAllActiveIframes(){let t=[];return this.iframeRegistry.forEach((e,r)=>{t.push({spatialId:r,iframe:e})}),t}dispose(){this.iframeRegistry.forEach((t,e)=>{console.log(`Disposing iframe with spatialId: ${e}`),t.remove()}),this.iframeRegistry.clear()}generateUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16).toUpperCase()})}}});var c,w=h(()=>{"use strict";c=class i{static eventReceiver={};static init(){window.__SpatialWebEvent=({id:t,data:e})=>{i.eventReceiver[t]?.(e)}}static addEventReceiver(t,e){i.eventReceiver[t]=e}static removeEventReceiver(t){delete i.eventReceiver[t]}}});var ue={};R(ue,{XRPlatform:()=>kt});function me(){return jt=(jt+1)%ti,`rId_${jt}`}var jt,ti,kt,ye=h(()=>{"use strict";_();w();jt=0,ti=1e5;kt=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=me();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}});let o=window.webspatialBridge.postMessage(a,t,e);if(o!==""){c.removeEventReceiver(a);let s=JSON.parse(o);if(s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}}}catch(a){console.error(`XRPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(S(o,s))}})}async callWebSpatialProtocol(t,e,r,n){return new Promise((a,o)=>{let s=me();try{let p=null;c.addEventReceiver(s,y=>{console.log("createdId",s,y.spatialId),a(m({windowProxy:p,id:y.spatialId})),c.removeEventReceiver(s)}),p=this.openWindow(t,e,r,n).windowProxy,p?.open(`about:blank?rid=${s}`,"_self")}catch(p){console.error(`open window error: ${p}`);let{code:y,message:Lt}=p;c.removeEventReceiver(s),a(S(y,Lt))}})}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${t}?${e||""}`,r,n)}}}});var Se={};R(Se,{AndroidPlatform:()=>Ht});function ii(){return Nt=(Nt+1)%ei,`rId_${Nt}`}var Jt,Nt,ei,Ht,ge=h(()=>{"use strict";_();g();w();Jt=0,Nt=0,ei=1e5;Ht=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=ii();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}});let o=window.webspatialBridge.postMessage(a,t,e);if(o!==""){c.removeEventReceiver(a);let s=JSON.parse(o);if(s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}}}catch(a){console.error(`AndroidPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(S(o,s))}})}async callWebSpatialProtocol(t,e,r,n){await new Promise(p=>setTimeout(p,16*Jt)),Jt++;let a=await new U().execute();for(;!a.data.can;)await new Promise(p=>setTimeout(p,16)),a=await new U().execute();let{windowProxy:o}=this.openWindow(t,e,r,n);for(;!o?.open;)await new Promise(p=>setTimeout(p,16));for(o?.open("about:blank","_self");!o?.__SpatialId;)await new Promise(p=>setTimeout(p,16));let s=o?.__SpatialId;return Jt--,Promise.resolve(m({windowProxy:o,id:s}))}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${t}?${e||""}`,r,n)}}}});var fe={};R(fe,{VisionOSPlatform:()=>qt});var qt,he=h(()=>{"use strict";_();qt=class{async callJSB(t,e){try{let r=await window.webkit.messageHandlers.bridge.postMessage(`${t}::${e}`);return m(r)}catch(r){let{code:n,message:a}=JSON.parse(r.message);return S(n,a)}}callWebSpatialProtocol(t,e,r,n){let{spatialId:a,windowProxy:o}=this.openWindow(t,e,r,n);return Promise.resolve(m({windowProxy:o,id:a}))}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){let a=window.open(`webspatial://${t}?${e||""}`,r,n);return{spatialId:a?.navigator.userAgent?.match(/\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi)?.[0],windowProxy:a}}}});function ri(i){let t=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function ni(i,t){if(!i)return!1;for(let e=0;e<3;e+=1){let r=i[e]-t[e];if(r>0)return!0;if(r<0)return!1}return!1}function Ee(){if(G())return new K;let i=window.navigator.userAgent,t=ri(i);if(window.navigator.userAgent.includes("Puppeteer")){let e=(de(),V(ce)).PuppeteerPlatform;return new e}else if(i.includes("PicoWebApp")&&ni(t,[0,0,1])){let e=(ye(),V(ue)).XRPlatform;return new e}else if(i.includes("Android")||i.includes("Linux")){let e=(ge(),V(Se)).AndroidPlatform;return new e}else{let e=(he(),V(fe)).VisionOSPlatform;return new e}}var be=h(()=>{"use strict";$t();le()});function Z(i,t){return i===""?0:i.endsWith("%")?t*parseFloat(i)/100:parseFloat(i)}function xe(i){let t=parseFloat(i.getPropertyValue("width")),e=i.getPropertyValue("border-top-left-radius"),r=i.getPropertyValue("border-top-right-radius"),n=i.getPropertyValue("border-bottom-left-radius"),a=i.getPropertyValue("border-bottom-right-radius");return{topLeading:Z(e,t),bottomLeading:Z(n,t),topTrailing:Z(r,t),bottomTrailing:Z(a,t)}}function we(i,t,e){let{x:r,y:n,z:a}=i,{x:o,y:s,z:p}=t,{x:y,y:Lt,z:qe}=e,M=new DOMMatrix;return M=M.translate(r,n,a),M=M.rotate(o,s,p),M=M.scale(y,Lt,qe),M}var Xt=h(()=>{"use strict"});var Qt,l,Y,tt,et,it,rt,nt,v,at,ot,st,pt,lt,ct,dt,mt,ut,yt,St,gt,ft,ht,Et,bt,D,xt,wt,vt,Pt,Mt,Dt,U,L,Tt,Rt,Ct,Ot,It,g=h(()=>{"use strict";be();Xt();Qt=Ee(),l=class{commandType="";async execute(){let t=this.getParams(),e=t?JSON.stringify(t):"";return Qt.callJSB(this.commandType,e)}},Y=class extends l{constructor(e,r){super();this.entity=e;this.properties=r}commandType="UpdateEntityProperties";getParams(){let e=we(this.properties.position??this.entity.position,this.properties.rotation??this.entity.rotation,this.properties.scale??this.entity.scale).toFloat64Array();return{entityId:this.entity.id,transform:e}}},tt=class extends l{constructor(e,r,n){super();this.entity=e;this.type=r;this.isEnable=n}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}},et=class extends l{properties;commandType="UpdateSpatialSceneProperties";constructor(t){super(),this.properties=t}getParams(){return this.properties}},it=class extends l{config;commandType="UpdateSceneConfig";constructor(t){super(),this.config=t}getParams(){return{config:this.config}}},rt=class extends l{constructor(e){super();this.id=e}commandType="FocusScene";getParams(){return{id:this.id}}},nt=class extends l{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},v=class extends l{constructor(e){super();this.spatialObject=e}getParams(){let e=this.getExtraParams();return{id:this.spatialObject.id,...e}}},at=class extends v{properties;commandType="UpdateSpatialized2DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},ot=class extends v{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},st=class extends v{properties;commandType="UpdateUnlitMaterialProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},pt=class extends v{matrix;commandType="UpdateSpatializedElementTransform";constructor(t,e){super(t),this.matrix=e}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},lt=class extends v{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},ct=class extends v{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(t,e){super(t),this.spatializedElement=e}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},dt=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(t){super(),this.spatializedElement=t}getParams(){return{spatializedElementId:this.spatializedElement.id}}},mt=class extends l{constructor(e){super();this.modelURL=e;this.modelURL=e}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},ut=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},yt=class extends l{constructor(e){super();this.name=e}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},St=class extends l{constructor(e){super();this.options=e}getParams(){let e=this.options.mesh.id,r=this.options.materials.map(n=>n.id);return{geometryId:e,materialIds:r}}commandType="CreateModelComponent"},gt=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ft=class extends l{constructor(e){super();this.options=e}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},ht=class extends l{constructor(e,r={}){super();this.type=e;this.options=r}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},Et=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateUnlitMaterial"},bt=class extends l{constructor(e,r){super();this.entity=e;this.comp=r}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},D=class extends l{constructor(e,r){super();this.childId=e;this.parentId=r}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},xt=class extends l{constructor(e,r,n){super();this.fromEntityId=e;this.toEntityId=r;this.fromPosition=n}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},wt=class extends l{constructor(e,r){super();this.fromEntityId=e;this.position=r}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},vt=class extends l{constructor(e,r){super();this.entityId=e;this.position=r}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},Pt=class extends l{constructor(e,r,n){super();this.position=e;this.fromId=r;this.toId=n}getParams(){return{position:this.position,fromId:this.fromId,toId:this.toId}}commandType="ConvertCoordinate"},Mt=class extends l{constructor(e=""){super();this.id=e}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Dt=class extends l{constructor(e){super();this.id=e}commandType="Destroy";getParams(){return{id:this.id}}},U=class extends l{constructor(e=""){super();this.id=e}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},L=class extends l{target;features;async execute(){let t=this.getQuery();return Qt.callWebSpatialProtocol(this.commandType,t,this.target,this.features)}executeSync(){let t=this.getQuery();return Qt.callWebSpatialProtocolSync(this.commandType,t,this.target,this.features)}getQuery(){let t,e=this.getParams();return e&&(t=Object.keys(e).map(r=>{let n=e[r],a=typeof n=="object"?JSON.stringify(n):n;return`${r}=${encodeURIComponent(a)}`}).join("&")),t}},Tt=class extends L{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Rt=class extends L{constructor(e,r,n,a){super();this.url=e;this.config=r;this.target=n;this.features=a}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}},Ct=class extends L{constructor(e){super();this.options=e}commandType="createAttachment";getParams(){return{}}},Ot=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="InitializeAttachment";getParams(){return{id:this.attachmentId,parentEntityId:this.options.parentEntityId,position:this.options.position??[0,0,0],size:this.options.size,ownerViewId:this.options.ownerViewId}}},It=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}}});var xi={};R(xi,{Attachment:()=>At,BaseplateVisibilityValues:()=>Pe,CubeInfo:()=>Zt,ModelComponent:()=>F,PhysicalMetrics:()=>pe,Spatial:()=>A,SpatialBoxGeometry:()=>N,SpatialComponent:()=>$,SpatialConeGeometry:()=>Q,SpatialCylinderGeometry:()=>q,SpatialEntity:()=>T,SpatialGeometry:()=>f,SpatialMaterial:()=>j,SpatialModelAsset:()=>J,SpatialModelEntity:()=>B,SpatialObject:()=>d,SpatialPlaneGeometry:()=>X,SpatialScene:()=>x,SpatialSceneState:()=>re,SpatialSceneValues:()=>Te,SpatialSession:()=>W,SpatialSphereGeometry:()=>H,SpatialUnlitMaterial:()=>k,Spatialized2DElement:()=>C,SpatializedDynamic3DElement:()=>I,SpatializedElement:()=>E,SpatializedElementType:()=>ve,SpatializedStatic3DElement:()=>O,WorldAlignmentValues:()=>De,WorldScalingValues:()=>Me,createAttachmentEntity:()=>oe,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>Yt,isValidSceneUnit:()=>zt,isValidSpatialSceneType:()=>ie,isValidWorldAlignmentType:()=>ee,isValidWorldScalingType:()=>te});g();var d=class{constructor(t){this.id=t}name;isDestroyed=!1;async inspect(){let t=await new Mt(this.id).execute();if(t.success)return t.data;throw new Error(t.errorMessage)}async destroy(){if(this.isDestroyed)return;let t=await new Dt(this.id).execute();if(t.success)return this.onDestroy(),this.isDestroyed=!0,t.data;if(this.isDestroyed)return;throw new Error(t.errorMessage)}onDestroy(){}};g();g();g();var Kt,x=class i extends d{static getInstance(){return Kt||(Kt=new i("")),Kt}async convertCoordinate(t,e,r){try{return(await new Pt(t,e,r).execute())?.data??t}catch(n){throw console.warn("SpatialScene.convertCoordinate error:",n),n}}async updateSpatialProperties(t){return new et(t).execute()}async addSpatializedElement(t){return new dt(t).execute()}async updateSceneCreationConfig(t){return new it(t).execute()}async getState(){return(await new nt().execute()).data.name}};var ve=(r=>(r[r.Spatialized2DElement=0]="Spatialized2DElement",r[r.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",r[r.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",r))(ve||{}),Pe=["automatic","visible","hidden"];function Yt(i){return Pe.includes(i)}var Me=["automatic","dynamic"];function te(i){return Me.includes(i)}var De=["adaptive","automatic","gravityAligned"];function ee(i){return De.includes(i)}var Te=["window","volume"];function ie(i){return Te.includes(i)}function zt(i){if(typeof i=="number")return i>=0;if(typeof i=="string"){if(i.endsWith("px"))return isNaN(Number(i.slice(0,-2)))?!1:Number(i.slice(0,-2))>=0;if(i.endsWith("m"))return isNaN(Number(i.slice(0,-1)))?!1:Number(i.slice(0,-1))>=0}return!1}var re=(a=>(a.idle="idle",a.pending="pending",a.willVisible="willVisible",a.visible="visible",a.fail="fail",a))(re||{}),Zt=class{constructor(t,e){this.size=t;this.origin=e;this.size=t,this.origin=e}get x(){return this.origin.x}get y(){return this.origin.y}get z(){return this.origin.z}get width(){return this.size.width}get height(){return this.size.height}get depth(){return this.size.depth}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get back(){return this.z}get front(){return this.z+this.depth}};var ai={defaultSize:{width:1280,height:720}},oi={defaultSize:{width:.94,height:.94,depth:.94}},si="webspatial://",Wt=class i{originalOpen;static instance;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(t){this.originalOpen=t.open.bind(t),t.open=this.open}configMap={};getConfig(t){if(!(t===void 0||!this.configMap[t]))return this.configMap[t]}ensureAbsoluteUrl(t){if(!t||/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t))return t;if(t.startsWith("//"))return`${window.location.protocol}${t}`;try{return new URL(t,document.baseURI).toString()}catch{return t}}open=(t,e,r)=>{if(t?.startsWith(si))return this.originalOpen(t,e,r);if(t=this.ensureAbsoluteUrl(t),e==="_self"||e==="_parent"||e==="_top")return this.originalOpen(t,e,r);let n=e?this.getConfig(e):void 0,o=new Rt(t,n,e,r).executeSync(),s=o.data?.id;return s&&new rt(s).execute(),o.data?.windowProxy};initScene(t,e,r){let n=r?.type??"window",a=ae(n),o=e({...a}),[s,p]=Ie(o,n);p.length>0&&console.warn(`initScene ${t} with errors: ${p.join(", ")}`),this.configMap[t]={...s,type:n}}};function Re(i){return i/1360}function Ce(i){return i*1360}function Oe(i,t,e){if(typeof i=="number")return e==="px"&&t==="px"||e==="m"&&t==="m"?i:e==="px"&&t==="m"?Re(i):e==="m"&&t==="px"?Ce(i):i;if(t==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return Re(Number(i.slice(0,-2)));throw new Error("formatToNumber: invalid str")}else if(t==="px"){if(i.endsWith("px"))return Number(i.slice(0,-2));if(i.endsWith("m"))return Ce(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function Ie(i,t){let e=ae(t),r=[],n=t==="window";if(ie(t)||r.push("sceneType"),i.defaultSize){let a=["width","height","depth"];for(let o of a)o in i.defaultSize&&(zt(i.defaultSize[o])?i.defaultSize[o]=Oe(i.defaultSize[o],n?"px":"m",n?"px":"m"):(i.defaultSize[o]=e.defaultSize[o],r.push(`defaultSize.${o}`)))}if(i.resizability){let a=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of a)o in i.resizability&&(zt(i.resizability[o])?i.resizability[o]=Oe(i.resizability[o],"px",n?"px":"m"):(i.resizability[o]=void 0,r.push(`resizability.${o}`)))}return i.worldScaling&&(te(i.worldScaling)||(i.worldScaling="automatic",r.push("worldScaling"))),i.worldAlignment&&(ee(i.worldAlignment)||(i.worldAlignment="automatic",r.push("worldAlignment"))),i.baseplateVisibility&&(Yt(i.baseplateVisibility)||(i.baseplateVisibility="automatic",r.push("baseplateVisibility"))),[i,r]}function ze(i,t,e){return Wt.getInstance().initScene(i,t,e)}function pi(i){Wt.getInstance().init(i)}function ne(i){i.document.onclick=function(t){let e=t.target,r=!1;for(;!r;){if(e&&e.tagName=="A")return!li(t);if(e&&e.parentElement)e=e.parentElement;else break}}}function li(i){let t=i.target;if(t.tagName==="A"){let e=t,r=e.target,n=e.href;if(r&&r!=="_self")return i.preventDefault(),window.open(n,r),!0}}function ae(i){return i==="window"?ai:oi}async function ci(){if(!window.opener||await x.getInstance().getState()!=="pending")return;function t(e){document.readyState==="interactive"||document.readyState==="complete"?e():document.addEventListener("DOMContentLoaded",e)}t(async()=>{let e=ae(window.xrCurrentSceneType??"window"),r=e;if(typeof window.xrCurrentSceneDefaults=="function")try{r=await window.xrCurrentSceneDefaults?.(e)}catch(s){console.error(s)}await new Promise((s,p)=>{setTimeout(()=>{s(null)},1e3)});let n=window.xrCurrentSceneType??"window",[a,o]=Ie(r,n);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await x.getInstance().updateSceneCreationConfig({...a,type:n})})}function We(){pi(window),ne(window),ci()}g();g();g();w();function u(i,t){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:t})}var E=class extends d{constructor(e){super(e);this.id=e;c.addEventReceiver(e,this.onReceiveEvent.bind(this))}async updateTransform(e){return new pt(this,e).execute()}_cubeInfo;get cubeInfo(){return this._cubeInfo}_transform;_transformInv;get transform(){return this._transform}get transformInv(){return this._transformInv}onReceiveEvent(e){let{type:r}=e;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",e.detail);this._onSpatialTap?.(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",e.detail);this._onSpatialDragStart?.(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",e.detail);this._onSpatialDrag?.(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",e.detail);this._onSpatialDragEnd?.(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",e.detail);this._onSpatialRotate?.(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",e.detail);this._onSpatialRotateEnd?.(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",e.detail);this._onSpatialMagnify?.(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",e.detail);this._onSpatialMagnifyEnd?.(n)}}_onSpatialTap;set onSpatialTap(e){this._onSpatialTap=e,this.updateProperties({enableTapGesture:e!==void 0})}_onSpatialDragStart;set onSpatialDragStart(e){this._onSpatialDragStart=e,this.updateProperties({enableDragStartGesture:this._onSpatialDragStart!==void 0})}_onSpatialDrag;set onSpatialDrag(e){this._onSpatialDrag=e,this.updateProperties({enableDragGesture:this._onSpatialDrag!==void 0})}_onSpatialDragEnd;set onSpatialDragEnd(e){this._onSpatialDragEnd=e,this.updateProperties({enableDragEndGesture:e!==void 0})}_onSpatialRotate;set onSpatialRotate(e){this._onSpatialRotate=e,this.updateProperties({enableRotateGesture:this._onSpatialRotate!==void 0})}_onSpatialRotateEnd;set onSpatialRotateEnd(e){this._onSpatialRotateEnd=e,this.updateProperties({enableRotateEndGesture:e!==void 0})}_onSpatialMagnify;set onSpatialMagnify(e){this._onSpatialMagnify=e,this.updateProperties({enableMagnifyGesture:e!==void 0})}_onSpatialMagnifyEnd;set onSpatialMagnifyEnd(e){this._onSpatialMagnifyEnd=e,this.updateProperties({enableMagnifyEndGesture:e!==void 0})}onDestroy(){c.removeEventReceiver(this.id)}};var C=class extends E{constructor(e,r){super(e);this.windowProxy=r;ne(r)}async updateProperties(e){return new at(this,e).execute()}async addSpatializedElement(e){return new ct(this,e).execute()}};g();var O=class extends E{constructor(t,e){super(t),this.modelURL=e}_readyResolve;modelURL;createReadyPromise(){return this._readyResolve?.(!1),new Promise(t=>{this._readyResolve=t})}ready=this.createReadyPromise();async updateProperties(t){return t.modelURL!==void 0&&this.modelURL!==t.modelURL&&(this.modelURL=t.modelURL,this.ready=this.createReadyPromise()),new lt(this,t).execute()}onReceiveEvent(t){t.type==="modelloaded"?(this._onLoadCallback?.(),this._readyResolve?.(!0)):t.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):super.onReceiveEvent(t)}_onLoadCallback;set onLoadCallback(t){this._onLoadCallback=t}_onLoadFailureCallback;set onLoadFailureCallback(t){this._onLoadFailureCallback=t}updateModelTransform(t){let e=Array.from(t.toFloat64Array());this.updateProperties({modelTransform:e})}};g();var I=class extends E{children=[];events={};constructor(t){super(t)}async addEntity(t){let e=new D(t.id,this.id).execute();return this.children.push(t),t.parent=this,e}addEvent(t,e){this.events[t]=e}removeEvent(t){this.events[t]&&delete this.events[t]}dispatchEvent(t){this.events[t.type]?.(t)}async updateProperties(t){return new ot(this,t).execute()}};async function Ae(){let i=await new Tt().execute();if(i.success){let{id:t,windowProxy:e}=i.data;return e.document.head.innerHTML=`<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
74
|
+
<base href="${document.baseURI}">`,new C(t,e)}else throw new Error("createSpatialized2DElement failed")}async function Ve(i){let t=await new mt(i).execute();if(t.success){let{id:e}=t.data;return new O(e,i)}else throw new Error("createSpatializedStatic3DElement failed")}async function Ge(){let i=await new ut().execute();if(i.success){let{id:t}=i.data;return new I(t)}else throw new Error("createSpatializedDynamic3DElement failed")}g();var At=class extends d{constructor(e,r,n){super(e);this.windowProxy=r;this.options=n}getContainer(){return this.windowProxy.document.body}getWindowProxy(){return this.windowProxy}async update(e){if(!this.isDestroyed)return e.position&&(this.options.position=e.position),e.size&&(this.options.size=e.size),new It(this.id,e).execute()}};async function oe(i){let t=await new Ct(i).execute();if(!t.success)throw new Error("createAttachmentEntity failed: "+t?.errorMessage);let{id:e,windowProxy:r}=t.data;return await new Ot(e,i).execute(),new At(e,r,i)}g();g();g();w();var T=class extends d{constructor(e,r){super(e);this.userData=r;c.addEventReceiver(e,this.onReceiveEvent)}position={x:0,y:0,z:0};rotation={x:0,y:0,z:0};scale={x:1,y:1,z:1};events={};children=[];parent=null;_enableInput=!1;get enableInput(){return this._enableInput}set enableInput(e){this._enableInput!==e&&(this._enableInput=e,this.updateEntityEvent("spatialtap",e).catch(r=>{console.error("enableInput updateEntityEvent failed","spatialtap",r),this._enableInput===e&&(this._enableInput=!e)}))}async addComponent(e){return new bt(this,e).execute()}async setPosition(e){return this.updateTransform({position:e})}async setRotation(e){return this.updateTransform({rotation:e})}async setScale(e){return this.updateTransform({scale:e})}async addEntity(e){let r=await new D(e.id,this.id).execute();return this.children.push(e),e.parent=this,r}async removeFromParent(){let e=await new D(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(r=>r.id!==this.id),this.parent=null),e}async updateTransform(e){return this.position=e.position??this.position,this.rotation=e.rotation??this.rotation,this.scale=e.scale??this.scale,new Y(this,e).execute()}async addEvent(e,r){if(this.events[e])this.events[e]=r;else try{await this.updateEntityEvent(e,!0),this.events[e]=r}catch{console.error("addEvent failed",e)}}async removeEvent(e){if(this.events[e]){delete this.events[e];try{await this.updateEntityEvent(e,!1)}catch{console.error("removeEvent failed",e)}}}async updateEntityEvent(e,r){return new tt(this,e,r).execute()}onReceiveEvent=e=>{let{type:r}=e;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",e.detail);this.dispatchEvent(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",e.detail);this.dispatchEvent(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",e.detail);this.dispatchEvent(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",e.detail);this.dispatchEvent(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",e.detail);this.dispatchEvent(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",e.detail);this.dispatchEvent(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",e.detail);this.dispatchEvent(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",e.detail);this.dispatchEvent(n)}};dispatchEvent(e){e.__origin||Object.defineProperty(e,"__origin",{value:this,enumerable:!1}),this.events[e.type]?.(e),e.bubbles&&!e.cancelBubble&&this.parent&&this.parent.dispatchEvent(e)}onDestroy(){c.removeEventReceiver(this.id),this.children.forEach(e=>{e.parent=null}),this.children=[],this.parent&&(this.parent.children=this.parent.children.filter(e=>e.id!==this.id),this.parent=null)}async convertFromEntityToEntity(e,r,n){return new xt(e,r,n).execute()}async convertFromEntityToScene(e,r){return new wt(e,r).execute()}async convertFromSceneToEntity(e,r){return new vt(e,r).execute()}};var B=class extends T{constructor(e,r,n){super(e,n);this.id=e;this.options=r;this.userData=n}};w();var $=class extends d{constructor(t){super(t),c.addEventReceiver(t,this.onReceiveEvent)}onReceiveEvent=t=>{let{type:e}=t;e==="objectdestroy"&&(this.isDestroyed=!0)}};var F=class extends ${constructor(e,r){super(e);this.options=r}};g();var j=class extends d{constructor(e,r){super(e);this.id=e;this.type=r;this.type=r}};var k=class extends j{constructor(e,r){super(e,"unlit");this.id=e;this.options=r}updateProperties(e){return new st(this,e).execute()}};var J=class extends d{constructor(e,r){super(e);this.id=e;this.options=r}};async function _e(i){let t=await new yt(i?.name).execute();if(t.success){let{id:e}=t.data;return new T(e,i)}else throw new Error("createSpatialEntity failed:"+t?.errorMessage)}async function z(i,t){let e=await new ht(i.type,t).execute();if(e.success){let{id:r}=e.data;return new i(r,t)}else throw new Error("createSpatialGeometry failed:"+e?.errorMessage)}async function Ue(i){let t=await new Et(i).execute();if(t.success){let{id:e}=t.data;return new k(e,i)}else throw new Error("createSpatialUnlitMaterial failed:"+t?.errorMessage)}async function Le(i){let t=await new St(i).execute();if(t.success){let{id:e}=t.data;return new F(e,i)}else throw new Error("createModelComponent failed:"+t?.errorMessage)}async function Be(i,t){let e=await new gt(i).execute();if(e.success){let{id:r}=e.data;return new B(r,i,t)}else throw new Error("createSpatialModelEntity failed:"+e?.errorMessage)}async function $e(i){let t=await new ft(i).execute();if(t.success){let{id:e}=t.data;return new J(e,i)}else throw new Error("createModelAsset failed:"+t?.errorMessage)}var f=class extends d{constructor(e,r){super(e);this.id=e;this.options=r}static type};var N=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="BoxGeometry"};var H=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="SphereGeometry"};var q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="CylinderGeometry"};var X=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="PlaneGeometry"};var Q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="ConeGeometry"};var W=class{getSpatialScene(){return x.getInstance()}createSpatialized2DElement(){return Ae()}createSpatializedStatic3DElement(t){return Ve(t)}initScene=ze;createSpatializedDynamic3DElement(){return Ge()}createEntity(t){return _e(t)}createBoxGeometry(t={}){return z(N,t)}createPlaneGeometry(t={}){return z(X,t)}createSphereGeometry(t={}){return z(H,t)}createConeGeometry(t){return z(Q,t)}createCylinderGeometry(t){return z(q,t)}createModelComponent(t){return Le(t)}createUnlitMaterial(t){return Ue(t)}createModelAsset(t){return $e(t)}createSpatialModelEntity(t,e){return Be(t,e)}createAttachmentEntity(t){return oe(t)}};w();var A=class{wsAppShellVersionFromUA;requestSession(){return this.runInSpatialWeb()?(c.init(),new W):null}runInSpatialWeb(){return navigator.userAgent.indexOf("WebSpatial/")>0}getShellVersionFromUA(){if(this.wsAppShellVersionFromUA!==void 0)return this.wsAppShellVersionFromUA;if(typeof navigator>"u"||typeof navigator.userAgent!="string")return this.wsAppShellVersionFromUA=null,null;let t=navigator.userAgent.match(/WSAppShell\/(\d+(?:\.\d+){2}(?:[-+][0-9A-Za-z.-]+)*)/);return this.wsAppShellVersionFromUA=t?t[1]:"1.3.0",this.wsAppShellVersionFromUA}isSupported(){return!0}getNativeVersion(){return window.__WebSpatialData&&window.__WebSpatialData.getNativeVersion?window.__WebSpatialData.getNativeVersion():window.WebSpatailNativeVersion==="WS_SHELL_VERSION"?this.getClientVersion():window.WebSpatailNativeVersion}getClientVersion(){return"1.4.0"}};var pe={};R(pe,{getValue:()=>ui,physicalToPoint:()=>mi,pointToPhysical:()=>di,subscribe:()=>yi});w();var b={meterToPtUnscaled:1360,meterToPtScaled:1360};function Fe(i){return i?.worldScalingCompensation??"scaled"}function di(i,t){return se(),Fe(t)==="unscaled"?i/b.meterToPtUnscaled:i/b.meterToPtScaled}function mi(i,t){return se(),Fe(t)==="unscaled"?i*b.meterToPtUnscaled:i*b.meterToPtScaled}function se(){if(typeof window>"u")return;let i=window.__webspatialsdk__?.physicalMetrics;if(!i)return;let t={meterToPtScaled:i.meterToPtScaled??b.meterToPtScaled,meterToPtUnscaled:i.meterToPtUnscaled??b.meterToPtUnscaled};(t.meterToPtScaled!==b.meterToPtScaled||t.meterToPtUnscaled!==b.meterToPtUnscaled)&&(b=t)}function ui(){return se(),b}function yi(i){if(typeof window>"u")return()=>{};let t=()=>{i()};return c.addEventReceiver("window",t),()=>{c.removeEventReceiver("window")}}$t();Xt();var je=new A,Ut,Vt={backgroundMaterial:"--xr-background-material"},ke="";function Gt(i){i!==ke&&(Ut?.getSpatialScene()?.updateSpatialProperties({material:i}),ke=i)}function Si(){let t=getComputedStyle(document.documentElement).getPropertyValue(Vt.backgroundMaterial);Gt(t||"none")}var P={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function Je(){let i=getComputedStyle(document.documentElement),t=xe(i);gi(t)}function gi(i){(P.topLeading!==i.topLeading||P.bottomLeading!==i.bottomLeading||P.topTrailing!==i.topTrailing||P.bottomTrailing!==i.bottomTrailing)&&(Ut?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),P.topLeading=i.topLeading,P.bottomLeading=i.bottomLeading,P.topTrailing=i.topTrailing,P.bottomTrailing=i.bottomTrailing)}function fi(i){Ut?.getSpatialScene().updateSpatialProperties({opacity:i})}function Ne(){let i=getComputedStyle(document.documentElement),t=parseFloat(i.getPropertyValue("opacity"));fi(t)}function hi(){let i=document.documentElement.style,t=new Proxy(i,{set:function(e,r,n){let a=Reflect.set(e,r,n);return r===Vt.backgroundMaterial&&Gt(n),(r==="border-radius"||r==="borderRadius"||r==="border-top-left-radius"||r==="borderTopLeftRadius"||r==="border-top-right-radius"||r==="borderTopRightRadius"||r==="border-bottom-left-radius"||r==="borderBottomLeftRadius"||r==="border-bottom-right-radius"||r==="borderBottomRightRadius")&&Je(),r==="opacity"&&Ne(),a},get:function(e,r){return typeof e[r]=="function"?function(...n){if(r==="setProperty"){let[a,o]=n;a===Vt.backgroundMaterial&&Gt(o)}else if(r==="removeProperty"){let[a]=n;a===Vt.backgroundMaterial&&Gt("none")}return e[r](...n)}:Reflect.get(e,r)}});Object.defineProperty(document.documentElement,"style",{get:function(){return t}})}function Ei(){new MutationObserver(_t).observe(document.head,{childList:!0,subtree:!0})}function _t(){Si(),Je(),Ne()}function bi(){new MutationObserver(t=>{t.forEach(e=>{e.type==="attributes"&&e.attributeName&&_t()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function He(){je.runInSpatialWeb()&&(Ut=await je.requestSession(),document.readyState==="complete"?_t():window.addEventListener("load",()=>{_t()}),hi(),Ei(),bi())}!G()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(We(),He());return V(xi);})();
|
|
10
75
|
//# sourceMappingURL=index.global.js.map
|