@webspatial/core-sdk 1.2.0 → 1.3.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 +30 -0
- package/dist/iife/index.d.ts +43 -2
- package/dist/iife/index.global.js +68 -3
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +43 -2
- package/dist/index.js +451 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +32 -0
- package/src/SpatialSession.ts +15 -1
- package/src/SpatializedElementCreator.ts +1 -1
- package/src/SpatializedStatic3DElement.ts +12 -1
- package/src/platform-adapter/index.ts +5 -1
- package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +470 -0
- package/src/reality/Attachment.ts +45 -0
- package/src/reality/index.ts +1 -0
- package/src/types/types.ts +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @webspatial/core-sdk
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 93fe590: Add attachments support across React, Core SDK, and visionOS runtime, plus navigation guard and demo.
|
|
8
|
+
|
|
9
|
+
- React API
|
|
10
|
+
- New <AttachmentAsset name="..."> to declare attachment UI outside <SceneGraph>.
|
|
11
|
+
- New <AttachmentEntity attachment="..." position size /> to place the declared UI in 3D under a parent entity.
|
|
12
|
+
- Attachment content is rendered via createPortal so it shares React state with the main app.
|
|
13
|
+
- Core SDK
|
|
14
|
+
- Attachment types and SpatialSession.createAttachmentEntity(...).
|
|
15
|
+
- Create/update/destroy commands: webspatial://createAttachment, UpdateAttachmentEntity, DestroyCommand.
|
|
16
|
+
- Attachment wrapper with getContainer(), update(), destroy().
|
|
17
|
+
- visionOS (AVP runtime)
|
|
18
|
+
- Native AttachmentManager with a child WKWebView per attachment.
|
|
19
|
+
- SpatialScene intercepts webspatial://createAttachment, handles update/destroy, and cleans up on reload/destroy.
|
|
20
|
+
- SpatializedDynamic3DView renders attachments via RealityView(..., attachments:) and parents them under the correct SpatialEntity.
|
|
21
|
+
- Navigation fix
|
|
22
|
+
- Prevent internal webspatial:// URLs from being forwarded to UIApplication.shared.open(...).
|
|
23
|
+
- Test page
|
|
24
|
+
- /reality/attachments demo page: hide/show, animation (attachments follow parent), shared React state.
|
|
25
|
+
- Notes
|
|
26
|
+
- Attachments are 2D UI surfaces only (no nested <Reality> / 3D APIs inside attachments).
|
|
27
|
+
- No billboard/camera-facing policy in this PR.
|
|
28
|
+
|
|
29
|
+
- 1405681: Require URL for SpatializedStatic3DElement
|
|
30
|
+
|
|
31
|
+
## 1.2.1
|
|
32
|
+
|
|
3
33
|
## 1.2.0
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/iife/index.d.ts
CHANGED
|
@@ -402,10 +402,12 @@ declare class CubeInfo$1 {
|
|
|
402
402
|
}
|
|
403
403
|
interface SpatialTapEventDetail {
|
|
404
404
|
location3D: Point3D;
|
|
405
|
+
globalLocation3D?: Point3D;
|
|
405
406
|
}
|
|
406
407
|
type SpatialTapEvent = CustomEvent<SpatialTapEventDetail>;
|
|
407
408
|
interface SpatialDragStartEventDetail {
|
|
408
409
|
startLocation3D: Point3D;
|
|
410
|
+
globalLocation3D?: Point3D;
|
|
409
411
|
}
|
|
410
412
|
interface SpatialDragEventDetail {
|
|
411
413
|
translation3D: Vec3;
|
|
@@ -430,6 +432,21 @@ interface SpatialMagnifyEndEventDetail {
|
|
|
430
432
|
type SpatialMagnifyEvent = CustomEvent<SpatialMagnifyEventDetail>;
|
|
431
433
|
type SpatialMagnifyEndEvent = CustomEvent<SpatialMagnifyEndEventDetail>;
|
|
432
434
|
type SpatialEntityOrReality = SpatialEntity | SpatializedDynamic3DElement;
|
|
435
|
+
interface AttachmentEntityOptions {
|
|
436
|
+
parentEntityId: string;
|
|
437
|
+
position?: [number, number, number];
|
|
438
|
+
size: {
|
|
439
|
+
width: number;
|
|
440
|
+
height: number;
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
interface AttachmentEntityUpdateOptions {
|
|
444
|
+
position?: [number, number, number];
|
|
445
|
+
size?: {
|
|
446
|
+
width: number;
|
|
447
|
+
height: number;
|
|
448
|
+
};
|
|
449
|
+
}
|
|
433
450
|
|
|
434
451
|
declare class SpatialComponent extends SpatialObject {
|
|
435
452
|
constructor(id: string);
|
|
@@ -523,6 +540,16 @@ declare class SpatialModelAsset extends SpatialObject {
|
|
|
523
540
|
constructor(id: string, options: ModelAssetOptions);
|
|
524
541
|
}
|
|
525
542
|
|
|
543
|
+
declare class Attachment extends SpatialObject {
|
|
544
|
+
private readonly windowProxy;
|
|
545
|
+
private options;
|
|
546
|
+
constructor(id: string, windowProxy: WindowProxy, options: AttachmentEntityOptions);
|
|
547
|
+
getContainer(): HTMLElement;
|
|
548
|
+
getWindowProxy(): WindowProxy;
|
|
549
|
+
update(options: AttachmentEntityUpdateOptions): Promise<CommandResult | undefined>;
|
|
550
|
+
}
|
|
551
|
+
declare function createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
552
|
+
|
|
526
553
|
declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
|
|
527
554
|
type: SpatialSceneType$1;
|
|
528
555
|
}): void;
|
|
@@ -614,6 +641,13 @@ declare class Spatialized2DElement extends SpatializedElement {
|
|
|
614
641
|
* and provides events for load success and failure.
|
|
615
642
|
*/
|
|
616
643
|
declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
644
|
+
/**
|
|
645
|
+
* Creates a new spatialized static 3D element with the specified ID and URL.
|
|
646
|
+
* Registers the element to receive spatial events.
|
|
647
|
+
* @param id Unique identifier for this element
|
|
648
|
+
* @param modelURL URL of the 3D model
|
|
649
|
+
*/
|
|
650
|
+
constructor(id: string, modelURL: string);
|
|
617
651
|
/**
|
|
618
652
|
* Promise resolver for the ready state.
|
|
619
653
|
* Used to resolve the ready promise when the model is loaded.
|
|
@@ -694,7 +728,7 @@ declare class SpatialSession {
|
|
|
694
728
|
* @param modelURL Optional URL to the 3D model to load
|
|
695
729
|
* @returns Promise resolving to a new SpatializedStatic3DElement instance
|
|
696
730
|
*/
|
|
697
|
-
createSpatializedStatic3DElement(modelURL
|
|
731
|
+
createSpatializedStatic3DElement(modelURL: string): Promise<SpatializedStatic3DElement>;
|
|
698
732
|
/**
|
|
699
733
|
* Initializes the spatial scene with custom configuration.
|
|
700
734
|
* This is a reference to the initScene function from scene-polyfill.
|
|
@@ -771,6 +805,13 @@ declare class SpatialSession {
|
|
|
771
805
|
* @returns Promise resolving to a new SpatialModelEntity instance
|
|
772
806
|
*/
|
|
773
807
|
createSpatialModelEntity(options: SpatialModelEntityCreationOptions, userData?: SpatialEntityUserData): Promise<SpatialModelEntity>;
|
|
808
|
+
/**
|
|
809
|
+
* Creates an attachment entity that renders 2D HTML content as a child
|
|
810
|
+
* of a 3D entity in the scene graph.
|
|
811
|
+
* @param options Configuration options including parent entity ID, position, and size
|
|
812
|
+
* @returns Promise resolving to a new Attachment instance
|
|
813
|
+
*/
|
|
814
|
+
createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
|
|
774
815
|
}
|
|
775
816
|
|
|
776
817
|
/**
|
|
@@ -856,4 +897,4 @@ declare global {
|
|
|
856
897
|
|
|
857
898
|
declare const isSSREnv: () => boolean;
|
|
858
899
|
|
|
859
|
-
export { 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, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
|
|
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 };
|
|
@@ -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.3.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 Lt=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var h=(i,e)=>()=>(i&&(e=i(i=0)),e);var W=(i,e)=>{for(var t in e)Lt(i,t,{get:e[t],enumerable:!0})},Ne=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ke(e))!Je.call(i,n)&&n!==t&&Lt(i,n,{get:()=>e[n],enumerable:!(r=Fe(e,n))||r.enumerable});return i};var A=i=>Ne(Lt({},"__esModule",{value:!0}),i);var He,G,Bt=h(()=>{"use strict";He=typeof window>"u",G=()=>He});var Q,ne=h(()=>{"use strict";Q=class{callJSB(e,t){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocol(e,t,r,n){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocolSync(e,t,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,e=""){return{success:!1,data:void 0,errorCode:i,errorMessage:e}}var V=h(()=>{"use strict"});var ae={};W(ae,{PuppeteerPlatform:()=>$t});var $t,oe=h(()=>{"use strict";V();console.log("PuppeteerPlatform");$t=class{iframeRegistry=new Map;constructor(){}callJSB(e,t){return new Promise(r=>{try{if(window.__handleJSBMessage)try{console.log(` core-sdk Puppeteer Platform: callJSB: ${e}::${t}`);let n=window.__handleJSBMessage(`${e}::${t}`);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: ${e}, msg: ${t} error: ${n}`),r(S("500","Internal error"))}})}createSpatializedElementSync(e,t){try{console.log(`[Puppeteer Platform] Creating spatialized element sync with id: ${e}, url: ${t}`);let r=window;if(r.__handleJSBMessage){let n={id:e,url:t};r.__handleJSBMessage(`CreateSpatialized2DElement::${JSON.stringify(n)}`)}}catch(r){console.error("Error creating spatialized element sync:",r)}}callWebSpatialProtocol(e,t,r,n){return console.log(`PuppeteerPlatform: Calling webspatial protocol: webspatial://${e}${t?`?${t}`:""}`),new Promise(a=>{try{let o=`webspatial://${e}${t?`?${t}`:""}`,{spatialId:s,iframe:p,windowProxy:y}=this.createIframeWindow(o,r,n);e==="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(e,t,r,n){try{let a=`webspatial://${e}${t?`?${t}`:""}`;console.log(`Calling webspatial protocol sync: ${a}`);let{spatialId:o,iframe:s,windowProxy:p}=this.createIframeWindow(a,r,n);return e==="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(e,t,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,e,a);return n.src="about:blank",console.log(`PuppeteerPlatform created iframe window with spatialId: ${a}, URL: ${e}`),this.initializeIframeContent(n,e,a),{spatialId:a,iframe:n,windowProxy:s}}createEnhancedWindowProxy(e,t,r){return{location:{href:t,toString:()=>t,reload:()=>{e.contentWindow&&e.contentWindow.location.reload()}},navigator:{userAgent:`Mozilla/5.0 (WebKit) SpatialId/${r}`},close:()=>{console.log(`Closing iframe with spatialId: ${r}`),e.remove(),this.iframeRegistry.delete(r)},document:e.contentDocument||{},contentWindow:e.contentWindow||{},postMessage:(n,a)=>{e.contentWindow&&e.contentWindow.postMessage(n,a||"*")},addEventListener:(n,a)=>{e.contentWindow&&e.contentWindow.addEventListener(n,a)},removeEventListener:(n,a)=>{e.contentWindow&&e.contentWindow.removeEventListener(n,a)},executeScript:n=>{if(e.contentWindow)try{return e.contentWindow.eval(n)}catch(a){return console.error(`Error executing script in iframe ${r}:`,a),null}return null},getIframe:()=>e,getSpatialId:()=>r}}initializeIframeContent(e,t,r){try{e.onload=()=>{try{let n=`
|
|
9
|
+
// \u6CE8\u5165\u901A\u4FE1\u811A\u672C
|
|
10
|
+
window.webSpatialId = '${r}';
|
|
11
|
+
window.SpatialId = '${r}';
|
|
12
|
+
|
|
13
|
+
// \u91CD\u5199window.open\u4EE5\u652F\u6301webspatial\u534F\u8BAE
|
|
14
|
+
const originalOpen = window.open;
|
|
15
|
+
window.open = function(url, target, features) {
|
|
16
|
+
if (url && url.startsWith('webspatial://')) {
|
|
17
|
+
// \u901A\u8FC7windowProxy\u5904\u7406webspatial\u534F\u8BAE
|
|
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
|
+
// \u8BBE\u7F6Enavigator.userAgent\u4EE5\u8BC6\u522Bwebspatial\u73AF\u5883
|
|
32
|
+
Object.defineProperty(navigator, 'userAgent', {
|
|
33
|
+
value: 'WebSpatial/1.0 ' + navigator.userAgent,
|
|
34
|
+
configurable: true
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// \u53D1\u9001\u52A0\u8F7D\u5B8C\u6210\u6D88\u606F
|
|
38
|
+
window.parent.postMessage({
|
|
39
|
+
type: 'iframe_loaded',
|
|
40
|
+
spatialId: '${r}',
|
|
41
|
+
url: '${t}'
|
|
42
|
+
}, '${window.location.origin}');
|
|
43
|
+
|
|
44
|
+
// \u8BBE\u7F6E\u6D88\u606F\u5904\u7406\u5668
|
|
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
|
+
// \u5904\u7406\u6765\u81EA\u7236\u7A97\u53E3\u7684\u547D\u4EE4
|
|
51
|
+
console.log('Received command in iframe from parent:', data.command);
|
|
52
|
+
// \u8FD9\u91CC\u53EF\u4EE5\u6DFB\u52A0\u547D\u4EE4\u5904\u7406\u903B\u8F91
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
`,a=e.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(e){let t={};return e.split(",").forEach(n=>{let[a,o]=n.split("=").map(s=>s.trim());a&&o&&(t[a]=o)}),t}sendMessageToIframe(e,t){let r=this.iframeRegistry.get(e);return r&&r.contentWindow?(r.contentWindow.postMessage(t,window.location.origin),!0):!1}getAllActiveIframes(){let e=[];return this.iframeRegistry.forEach((t,r)=>{e.push({spatialId:r,iframe:t})}),e}dispose(){this.iframeRegistry.forEach((e,t)=>{console.log(`Disposing iframe with spatialId: ${t}`),e.remove()}),this.iframeRegistry.clear()}generateUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16).toUpperCase()})}}});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 pe={};W(pe,{XRPlatform:()=>jt});function se(){return Ut=(Ut+1)%qe,`rId_${Ut}`}var Ut,qe,jt,le=h(()=>{"use strict";V();P();Ut=0,qe=1e5;jt=class{async callJSB(e,t){return new Promise((r,n)=>{try{let a=se();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,e,t);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: ${e}, msg: ${t} error: ${a}`);let{code:o,message:s}=a;r(S(o,s))}})}async callWebSpatialProtocol(e,t,r,n){return new Promise((a,o)=>{let s=se();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(e,t,r,n).windowProxy,p?.open(`about:blank?rid=${s}`,"_self")}catch(p){console.error(`open window error: ${p}`);let{code:y,message:_t}=p;c.removeEventReceiver(s),a(S(y,_t))}})}callWebSpatialProtocolSync(e,t,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(e,t,r,n);return m({windowProxy:o,id:a})}openWindow(e,t,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,r,n)}}}});var ce={};W(ce,{AndroidPlatform:()=>Jt});function Ke(){return kt=(kt+1)%Xe,`rId_${kt}`}var Ft,kt,Xe,Jt,de=h(()=>{"use strict";V();g();P();Ft=0,kt=0,Xe=1e5;Jt=class{async callJSB(e,t){return new Promise((r,n)=>{try{let a=Ke();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,e,t);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: ${e}, msg: ${t} error: ${a}`);let{code:o,message:s}=a;r(S(o,s))}})}async callWebSpatialProtocol(e,t,r,n){await new Promise(p=>setTimeout(p,16*Ft)),Ft++;let a=await new _().execute();for(;!a.data.can;)await new Promise(p=>setTimeout(p,16)),a=await new _().execute();let{windowProxy:o}=this.openWindow(e,t,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 Ft--,Promise.resolve(m({windowProxy:o,id:s}))}callWebSpatialProtocolSync(e,t,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(e,t,r,n);return m({windowProxy:o,id:a})}openWindow(e,t,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,r,n)}}}});var me={};W(me,{VisionOSPlatform:()=>Nt});var Nt,ue=h(()=>{"use strict";V();Nt=class{async callJSB(e,t){try{let r=await window.webkit.messageHandlers.bridge.postMessage(`${e}::${t}`);return m(r)}catch(r){let{code:n,message:a}=JSON.parse(r.message);return S(n,a)}}callWebSpatialProtocol(e,t,r,n){let{spatialId:a,windowProxy:o}=this.openWindow(e,t,r,n);return Promise.resolve(m({windowProxy:o,id:a}))}callWebSpatialProtocolSync(e,t,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(e,t,r,n);return m({windowProxy:o,id:a})}openWindow(e,t,r,n){let a=window.open(`webspatial://${e}?${t||""}`,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 Qe(i){let e=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:null}function Ye(i,e){if(!i)return!1;for(let t=0;t<3;t+=1){let r=i[t]-e[t];if(r>0)return!0;if(r<0)return!1}return!1}function ye(){if(G())return new Q;let i=window.navigator.userAgent,e=Qe(i);if(window.navigator.userAgent.includes("Puppeteer")){let t=(oe(),A(ae)).PuppeteerPlatform;return new t}else if(i.includes("PicoWebApp")&&Ye(e,[0,0,1])){let t=(le(),A(pe)).XRPlatform;return new t}else if(i.includes("Android")||i.includes("Linux")){let t=(de(),A(ce)).AndroidPlatform;return new t}else{let t=(ue(),A(me)).VisionOSPlatform;return new t}}var Se=h(()=>{"use strict";Bt();ne()});function Y(i,e){return i===""?0:i.endsWith("%")?e*parseFloat(i)/100:parseFloat(i)}function ge(i){let e=parseFloat(i.getPropertyValue("width")),t=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:Y(t,e),bottomLeading:Y(n,e),topTrailing:Y(r,e),bottomTrailing:Y(a,e)}}function fe(i,e,t){let{x:r,y:n,z:a}=i,{x:o,y:s,z:p}=e,{x:y,y:_t,z:je}=t,v=new DOMMatrix;return v=v.translate(r,n,a),v=v.rotate(o,s,p),v=v.scale(y,_t,je),v}var Ht=h(()=>{"use strict"});var qt,l,Z,tt,et,it,rt,nt,x,at,ot,st,pt,lt,ct,dt,mt,ut,yt,St,gt,ft,ht,Et,bt,M,xt,wt,vt,Pt,Mt,_,L,Dt,Rt,Ct,Tt,g=h(()=>{"use strict";Se();Ht();qt=ye(),l=class{commandType="";async execute(){let e=this.getParams(),t=e?JSON.stringify(e):"";return qt.callJSB(this.commandType,t)}},Z=class extends l{constructor(t,r){super();this.entity=t;this.properties=r}commandType="UpdateEntityProperties";getParams(){let t=fe(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}}},tt=class extends l{constructor(t,r,n){super();this.entity=t;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(e){super(),this.properties=e}getParams(){return this.properties}},it=class extends l{config;commandType="UpdateSceneConfig";constructor(e){super(),this.config=e}getParams(){return{config:this.config}}},rt=class extends l{constructor(t){super();this.id=t}commandType="FocusScene";getParams(){return{id:this.id}}},nt=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}}},at=class extends x{properties;commandType="UpdateSpatialized2DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},ot=class extends x{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},st=class extends x{properties;commandType="UpdateUnlitMaterialProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},pt=class extends x{matrix;commandType="UpdateSpatializedElementTransform";constructor(e,t){super(e),this.matrix=t}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},lt=class extends x{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},ct=class extends x{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(e,t){super(e),this.spatializedElement=t}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},dt=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(e){super(),this.spatializedElement=e}getParams(){return{spatializedElementId:this.spatializedElement.id}}},mt=class extends l{constructor(t){super();this.modelURL=t;this.modelURL=t}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},ut=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},yt=class extends l{constructor(t){super();this.name=t}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},St=class extends l{constructor(t){super();this.options=t}getParams(){let t=this.options.mesh.id,r=this.options.materials.map(n=>n.id);return{geometryId:t,materialIds:r}}commandType="CreateModelComponent"},gt=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"},ht=class extends l{constructor(t,r={}){super();this.type=t;this.options=r}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},Et=class extends l{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateUnlitMaterial"},bt=class extends l{constructor(t,r){super();this.entity=t;this.comp=r}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},M=class extends l{constructor(t,r){super();this.childId=t;this.parentId=r}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},xt=class extends l{constructor(t,r,n){super();this.fromEntityId=t;this.toEntityId=r;this.fromPosition=n}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},wt=class extends l{constructor(t,r){super();this.fromEntityId=t;this.position=r}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},vt=class extends l{constructor(t,r){super();this.entityId=t;this.position=r}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},Pt=class extends l{constructor(t=""){super();this.id=t}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Mt=class extends l{constructor(t){super();this.id=t}commandType="Destroy";getParams(){return{id:this.id}}},_=class extends l{constructor(t=""){super();this.id=t}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},L=class extends l{target;features;async execute(){let e=this.getQuery();return qt.callWebSpatialProtocol(this.commandType,e,this.target,this.features)}executeSync(){let e=this.getQuery();return qt.callWebSpatialProtocolSync(this.commandType,e,this.target,this.features)}getQuery(){let e,t=this.getParams();return t&&(e=Object.keys(t).map(r=>{let n=t[r],a=typeof n=="object"?JSON.stringify(n):n;return`${r}=${encodeURIComponent(a)}`}).join("&")),e}},Dt=class extends L{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Rt=class extends L{constructor(t,r,n,a){super();this.url=t;this.config=r;this.target=n;this.features=a}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}},Ct=class extends L{constructor(t){super();this.options=t}commandType="createAttachment";getParams(){return{parentEntityId:this.options.parentEntityId,position:this.options.position??[0,0,0],size:this.options.size}}},Tt=class extends l{constructor(t,r){super();this.attachmentId=t;this.options=r}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}}});var di={};W(di,{Attachment:()=>It,BaseplateVisibilityValues:()=>Ee,CubeInfo:()=>B,ModelComponent:()=>j,Spatial:()=>I,SpatialBoxGeometry:()=>N,SpatialComponent:()=>U,SpatialConeGeometry:()=>K,SpatialCylinderGeometry:()=>q,SpatialEntity:()=>D,SpatialGeometry:()=>f,SpatialMaterial:()=>F,SpatialModelAsset:()=>J,SpatialModelEntity:()=>$,SpatialObject:()=>d,SpatialPlaneGeometry:()=>X,SpatialScene:()=>b,SpatialSceneState:()=>te,SpatialSceneValues:()=>we,SpatialSession:()=>z,SpatialSphereGeometry:()=>H,SpatialUnlitMaterial:()=>k,Spatialized2DElement:()=>R,SpatializedDynamic3DElement:()=>T,SpatializedElement:()=>E,SpatializedElementType:()=>he,SpatializedStatic3DElement:()=>C,WorldAlignmentValues:()=>xe,WorldScalingValues:()=>be,createAttachmentEntity:()=>re,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>Kt,isValidSceneUnit:()=>Ot,isValidSpatialSceneType:()=>Zt,isValidWorldAlignmentType:()=>Yt,isValidWorldScalingType:()=>Qt});g();var d=class{constructor(e){this.id=e}name;isDestroyed=!1;async inspect(){let e=await new Pt(this.id).execute();if(e.success)return e.data;throw new Error(e.errorMessage)}async destroy(){if(this.isDestroyed)return;let e=await new Mt(this.id).execute();if(e.success)return this.onDestroy(),this.isDestroyed=!0,e.data;if(this.isDestroyed)return;throw new Error(e.errorMessage)}onDestroy(){}};g();g();var Xt,b=class i extends d{static getInstance(){return Xt||(Xt=new i("")),Xt}async updateSpatialProperties(e){return new et(e).execute()}async addSpatializedElement(e){return new dt(e).execute()}async updateSceneCreationConfig(e){return new it(e).execute()}async getState(){return(await new nt().execute()).data.name}};var he=(r=>(r[r.Spatialized2DElement=0]="Spatialized2DElement",r[r.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",r[r.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",r))(he||{}),Ee=["automatic","visible","hidden"];function Kt(i){return Ee.includes(i)}var be=["automatic","dynamic"];function Qt(i){return be.includes(i)}var xe=["adaptive","automatic","gravityAligned"];function Yt(i){return xe.includes(i)}var we=["window","volume"];function Zt(i){return we.includes(i)}function Ot(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 te=(a=>(a.idle="idle",a.pending="pending",a.willVisible="willVisible",a.visible="visible",a.fail="fail",a))(te||{}),B=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 Ze={defaultSize:{width:1280,height:720}},ti={defaultSize:{width:.94,height:.94,depth:.94}},ei="webspatial://",zt=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,r)=>{if(e?.startsWith(ei))return this.originalOpen(e,t,r);if(e=this.ensureAbsoluteUrl(e),t==="_self"||t==="_parent"||t==="_top")return this.originalOpen(e,t,r);let n=t?this.getConfig(t):void 0,o=new Rt(e,n,t,r).executeSync(),s=o.data?.id;return s&&new rt(s).execute(),o.data?.windowProxy};initScene(e,t,r){let n=r?.type??"window",a=ie(n),o=t({...a}),[s,p]=De(o,n);p.length>0&&console.warn(`initScene ${e} with errors: ${p.join(", ")}`),this.configMap[e]={...s,type:n}}};function ve(i){return i/1360}function Pe(i){return i*1360}function Me(i,e,t){if(typeof i=="number")return t==="px"&&e==="px"||t==="m"&&e==="m"?i:t==="px"&&e==="m"?ve(i):t==="m"&&e==="px"?Pe(i):i;if(e==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return ve(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 Pe(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function De(i,e){let t=ie(e),r=[],n=e==="window";if(Zt(e)||r.push("sceneType"),i.defaultSize){let a=["width","height","depth"];for(let o of a)o in i.defaultSize&&(Ot(i.defaultSize[o])?i.defaultSize[o]=Me(i.defaultSize[o],n?"px":"m",n?"px":"m"):(i.defaultSize[o]=t.defaultSize[o],r.push(`defaultSize.${o}`)))}if(i.resizability){let a=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of a)o in i.resizability&&(Ot(i.resizability[o])?i.resizability[o]=Me(i.resizability[o],"px",n?"px":"m"):(i.resizability[o]=void 0,r.push(`resizability.${o}`)))}return i.worldScaling&&(Qt(i.worldScaling)||(i.worldScaling="automatic",r.push("worldScaling"))),i.worldAlignment&&(Yt(i.worldAlignment)||(i.worldAlignment="automatic",r.push("worldAlignment"))),i.baseplateVisibility&&(Kt(i.baseplateVisibility)||(i.baseplateVisibility="automatic",r.push("baseplateVisibility"))),[i,r]}function Re(i,e,t){return zt.getInstance().initScene(i,e,t)}function ii(i){zt.getInstance().init(i)}function ee(i){i.document.onclick=function(e){let t=e.target,r=!1;for(;!r;){if(t&&t.tagName=="A")return!ri(e);if(t&&t.parentElement)t=t.parentElement;else break}}}function ri(i){let e=i.target;if(e.tagName==="A"){let t=e,r=t.target,n=t.href;if(r&&r!=="_self")return i.preventDefault(),window.open(n,r),!0}}function ie(i){return i==="window"?Ze:ti}async function ni(){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=ie(window.xrCurrentSceneType??"window"),r=t;if(typeof window.xrCurrentSceneDefaults=="function")try{r=await window.xrCurrentSceneDefaults?.(t)}catch(s){console.error(s)}await new Promise((s,p)=>{setTimeout(()=>{s(null)},1e3)});let n=window.xrCurrentSceneType??"window",[a,o]=De(r,n);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await b.getInstance().updateSceneCreationConfig({...a,type:n})})}function Ce(){ii(window),ee(window),ni()}g();g();g();P();function u(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 pt(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:r}=t;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="cubeInfo"){let n=t;this._cubeInfo=new B(n.size,n.origin)}else if(r==="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(r==="spatialtap"){let n=u("spatialtap",t.detail);this._onSpatialTap?.(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",t.detail);this._onSpatialDragStart?.(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",t.detail);this._onSpatialDrag?.(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",t.detail);this._onSpatialDragEnd?.(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",t.detail);this._onSpatialRotate?.(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",t.detail);this._onSpatialRotateEnd?.(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",t.detail);this._onSpatialMagnify?.(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",t.detail);this._onSpatialMagnifyEnd?.(n)}}_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,r){super(t);this.windowProxy=r;ee(r)}async updateProperties(t){return new at(this,t).execute()}async addSpatializedElement(t){return new ct(this,t).execute()}};g();var C=class extends E{constructor(e,t){super(e),this.modelURL=t}_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 lt(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})}};g();var T=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 ot(this,e).execute()}};async function Te(){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">
|
|
74
|
+
<base href="${document.baseURI}">`,new R(e,t)}else throw new Error("createSpatialized2DElement failed")}async function Oe(i){let e=await new mt(i).execute();if(e.success){let{id:t}=e.data;return new C(t,i)}else throw new Error("createSpatializedStatic3DElement failed")}async function ze(){let i=await new ut().execute();if(i.success){let{id:e}=i.data;return new T(e)}else throw new Error("createSpatializedDynamic3DElement failed")}g();var It=class extends d{constructor(t,r,n){super(t);this.windowProxy=r;this.options=n}getContainer(){return this.windowProxy.document.body}getWindowProxy(){return this.windowProxy}async update(t){if(!this.isDestroyed)return t.position&&(this.options.position=t.position),t.size&&(this.options.size=t.size),new Tt(this.id,t).execute()}};async function re(i){let e=await new Ct(i).execute();if(!e.success)throw new Error("createAttachmentEntity failed: "+e?.errorMessage);let{id:t,windowProxy:r}=e.data;return new It(t,r,i)}g();g();g();P();var D=class i extends d{constructor(t,r){super(t);this.userData=r;c.addEventReceiver(t,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;async addComponent(t){return new bt(this,t).execute()}async setPosition(t){return this.updateTransform({position:t})}async setRotation(t){return this.updateTransform({rotation:t})}async setScale(t){return this.updateTransform({scale:t})}async addEntity(t){let r=await new M(t.id,this.id).execute();return this.children.push(t),t.parent=this,r}async removeFromParent(){let t=await new M(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(r=>r.id!==this.id),this.parent=null),t}async updateTransform(t){return this.position=t.position??this.position,this.rotation=t.rotation??this.rotation,this.scale=t.scale??this.scale,new Z(this,t).execute()}async addEvent(t,r){if(this.events[t])this.events[t]=r;else try{await this.updateEntityEvent(t,!0),this.events[t]=r}catch{console.error("addEvent failed",t)}}async removeEvent(t){if(this.events[t]){delete this.events[t];try{await this.updateEntityEvent(t,!1)}catch{console.error("removeEvent failed",t)}}}async updateEntityEvent(t,r){return new tt(this,t,r).execute()}onReceiveEvent=t=>{let{type:r}=t;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",t.detail);this.dispatchEvent(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",t.detail);this.dispatchEvent(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",t.detail);this.dispatchEvent(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",t.detail);this.dispatchEvent(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",t.detail);this.dispatchEvent(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",t.detail);this.dispatchEvent(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",t.detail);this.dispatchEvent(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",t.detail);this.dispatchEvent(n)}};dispatchEvent(t){t.__origin||Object.defineProperty(t,"__origin",{value:this,enumerable:!1}),this.events[t.type]?.(t),t.bubbles&&!t.cancelBubble&&this.parent&&this.parent instanceof i&&this.parent.dispatchEvent(t)}onDestroy(){c.removeEventReceiver(this.id),this.children.forEach(t=>{t.parent=null}),this.children=[],this.parent&&(this.parent.children=this.parent.children.filter(t=>t.id!==this.id),this.parent=null)}async convertFromEntityToEntity(t,r,n){return new xt(t,r,n).execute()}async convertFromEntityToScene(t,r){return new wt(t,r).execute()}async convertFromSceneToEntity(t,r){return new vt(t,r).execute()}};var $=class extends D{constructor(t,r,n){super(t,n);this.id=t;this.options=r;this.userData=n}};P();var U=class extends d{constructor(e){super(e),c.addEventReceiver(e,this.onReceiveEvent)}onReceiveEvent=e=>{let{type:t}=e;t==="objectdestroy"&&(this.isDestroyed=!0)}};var j=class extends U{constructor(t,r){super(t);this.options=r}};g();var F=class extends d{constructor(t,r){super(t);this.id=t;this.type=r;this.type=r}};var k=class extends F{constructor(t,r){super(t,"unlit");this.id=t;this.options=r}updateProperties(t){return new st(this,t).execute()}};var J=class extends d{constructor(t,r){super(t);this.id=t;this.options=r}};async function Ie(i){let e=await new yt(i?.name).execute();if(e.success){let{id:t}=e.data;return new D(t,i)}else throw new Error("createSpatialEntity failed:"+e?.errorMessage)}async function O(i,e){let t=await new ht(i.type,e).execute();if(t.success){let{id:r}=t.data;return new i(r,e)}else throw new Error("createSpatialGeometry failed:"+t?.errorMessage)}async function We(i){let e=await new Et(i).execute();if(e.success){let{id:t}=e.data;return new k(t,i)}else throw new Error("createSpatialUnlitMaterial failed:"+e?.errorMessage)}async function Ae(i){let e=await new St(i).execute();if(e.success){let{id:t}=e.data;return new j(t,i)}else throw new Error("createModelComponent failed:"+e?.errorMessage)}async function Ge(i,e){let t=await new gt(i).execute();if(t.success){let{id:r}=t.data;return new $(r,i,e)}else throw new Error("createSpatialModelEntity failed:"+t?.errorMessage)}async function Ve(i){let e=await new ft(i).execute();if(e.success){let{id:t}=e.data;return new J(t,i)}else throw new Error("createModelAsset failed:"+e?.errorMessage)}var f=class extends d{constructor(t,r){super(t);this.id=t;this.options=r}static type};var N=class extends f{constructor(t,r){super(t,r);this.id=t;this.options=r}static type="BoxGeometry"};var H=class extends f{constructor(t,r){super(t,r);this.id=t;this.options=r}static type="SphereGeometry"};var q=class extends f{constructor(t,r){super(t,r);this.id=t;this.options=r}static type="CylinderGeometry"};var X=class extends f{constructor(t,r){super(t,r);this.id=t;this.options=r}static type="PlaneGeometry"};var K=class extends f{constructor(t,r){super(t,r);this.id=t;this.options=r}static type="ConeGeometry"};var z=class{getSpatialScene(){return b.getInstance()}createSpatialized2DElement(){return Te()}createSpatializedStatic3DElement(e){return Oe(e)}initScene=Re;createSpatializedDynamic3DElement(){return ze()}createEntity(e){return Ie(e)}createBoxGeometry(e={}){return O(N,e)}createPlaneGeometry(e={}){return O(X,e)}createSphereGeometry(e={}){return O(H,e)}createConeGeometry(e){return O(K,e)}createCylinderGeometry(e){return O(q,e)}createModelComponent(e){return Ae(e)}createUnlitMaterial(e){return We(e)}createModelAsset(e){return Ve(e)}createSpatialModelEntity(e,t){return Ge(e,t)}createAttachmentEntity(e){return re(e)}};P();var I=class{requestSession(){return this.runInSpatialWeb()?(c.init(),new z):null}runInSpatialWeb(){return navigator.userAgent.indexOf("WebSpatial/")>0}isSupported(){return!0}getNativeVersion(){return window.__WebSpatialData&&window.__WebSpatialData.getNativeVersion?window.__WebSpatialData.getNativeVersion():window.WebSpatailNativeVersion==="PACKAGE_VERSION"?this.getClientVersion():window.WebSpatailNativeVersion}getClientVersion(){return"1.3.0"}};Bt();Ht();var _e=new I,Vt,Wt={backgroundMaterial:"--xr-background-material"},Le="";function At(i){i!==Le&&(Vt?.getSpatialScene()?.updateSpatialProperties({material:i}),Le=i)}function ai(){let e=getComputedStyle(document.documentElement).getPropertyValue(Wt.backgroundMaterial);At(e||"none")}var w={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function Be(){let i=getComputedStyle(document.documentElement),e=ge(i);oi(e)}function oi(i){(w.topLeading!==i.topLeading||w.bottomLeading!==i.bottomLeading||w.topTrailing!==i.topTrailing||w.bottomTrailing!==i.bottomTrailing)&&(Vt?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),w.topLeading=i.topLeading,w.bottomLeading=i.bottomLeading,w.topTrailing=i.topTrailing,w.bottomTrailing=i.bottomTrailing)}function si(i){Vt?.getSpatialScene().updateSpatialProperties({opacity:i})}function $e(){let i=getComputedStyle(document.documentElement),e=parseFloat(i.getPropertyValue("opacity"));si(e)}function pi(){let i=document.documentElement.style,e=new Proxy(i,{set:function(t,r,n){let a=Reflect.set(t,r,n);return r===Wt.backgroundMaterial&&At(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")&&Be(),r==="opacity"&&$e(),a},get:function(t,r){return typeof t[r]=="function"?function(...n){if(r==="setProperty"){let[a,o]=n;a===Wt.backgroundMaterial&&At(o)}else if(r==="removeProperty"){let[a]=n;a===Wt.backgroundMaterial&&At("none")}return t[r](...n)}:Reflect.get(t,r)}});Object.defineProperty(document.documentElement,"style",{get:function(){return e}})}function li(){new MutationObserver(Gt).observe(document.head,{childList:!0,subtree:!0})}function Gt(){ai(),Be(),$e()}function ci(){new MutationObserver(e=>{e.forEach(t=>{t.type==="attributes"&&t.attributeName&&Gt()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function Ue(){_e.runInSpatialWeb()&&(Vt=await _e.requestSession(),document.readyState==="complete"?Gt():window.addEventListener("load",()=>{Gt()}),pi(),li(),ci())}!G()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(Ce(),Ue());return A(di);})();
|
|
10
75
|
//# sourceMappingURL=index.global.js.map
|