@webspatial/core-sdk 1.5.0 → 1.6.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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # @webspatial/core-sdk
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f1b28eb: Model add play(), pause(), and paused for playback controls
8
+ - 0f743a1: Model add <source> element support for multi-format fallback
9
+ - 19a0daf: manifest support new xr_spatial_scene API
10
+ - 5d72631: Add autoplay attribute to <Model>
11
+
12
+ When a 3D model contains an embedded animation, developers can opt into automatic playback via a simple boolean attribute. When autoplay is set, the model's first available animation begins playing as soon as the model has successfully loaded.
13
+
14
+ - 19a0daf: update initScene callback input pre to be previous return value.
15
+ - 005480c: Model add duration and playbackRate for animation control
16
+ - d9a0418: Add loop attribute to <Model>
17
+
18
+ When loop is set, the animation automatically seeks back to the start upon reaching the end.
19
+
20
+ ### Patch Changes
21
+
22
+ - afb6c35: fix spatialDiv create issue. API change for token access.
23
+ - ee7c68f: Fix Spatial UA detection and align no-runtime fallback behavior
24
+ - 3d62c5d: Pico OS: when `webSpatial.genToken()` is present, rewrite `window.open` for **`createSpatialized2DElement`** and **`createAttachment`** to the token URL form (`command=` + optional `rid`). Other `webspatial://` URLs are left unchanged.
25
+
3
26
  ## 1.5.0
4
27
 
5
28
  ### Minor Changes
@@ -57,6 +57,7 @@ declare enum SpatialWebMsgType {
57
57
  spatialrotateend = "spatialrotateend",
58
58
  spatialmagnify = "spatialmagnify",
59
59
  spatialmagnifyend = "spatialmagnifyend",
60
+ animationstatechange = "animationstatechange",
60
61
  objectdestroy = "objectdestroy"
61
62
  }
62
63
  interface ObjectDestroyMsg {
@@ -86,6 +87,23 @@ interface SpatialRotateEndMsg {
86
87
  type: SpatialWebMsgType.spatialrotateend;
87
88
  detail: SpatialRotateEventDetail;
88
89
  }
90
+ interface ModelLoadSuccess {
91
+ type: SpatialWebMsgType.modelloaded;
92
+ detail?: {
93
+ src: string;
94
+ };
95
+ }
96
+ interface ModelLoadFailure {
97
+ type: SpatialWebMsgType.modelloadfailed;
98
+ }
99
+ interface AnimationStateChangeDetail {
100
+ paused: boolean;
101
+ duration: number;
102
+ }
103
+ interface AnimationStateChangeMsg {
104
+ type: SpatialWebMsgType.animationstatechange;
105
+ detail: AnimationStateChangeDetail;
106
+ }
89
107
 
90
108
  /**
91
109
  * Abstract base class for all spatialized elements in the WebSpatial environment.
@@ -148,7 +166,7 @@ declare abstract class SpatializedElement extends SpatialObject {
148
166
  * Handles various spatial events like transforms, gestures, and interactions.
149
167
  * @param data The event data received from the WebSpatial system
150
168
  */
151
- protected onReceiveEvent(data: SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
169
+ protected onReceiveEvent(data: ReceiveEventData): void;
152
170
  private _onSpatialTap?;
153
171
  set onSpatialTap(value: (event: SpatialTapEvent) => void | undefined);
154
172
  private _onSpatialDragStart?;
@@ -171,6 +189,7 @@ declare abstract class SpatializedElement extends SpatialObject {
171
189
  */
172
190
  onDestroy(): void;
173
191
  }
192
+ type ReceiveEventData = SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg;
174
193
 
175
194
  declare class SpatializedDynamic3DElement extends SpatializedElement {
176
195
  children: SpatialEntityOrReality[];
@@ -259,9 +278,18 @@ interface Spatialized2DElementProperties extends SpatializedElementProperties {
259
278
  material: BackgroundMaterialType;
260
279
  scrollEdgeInsetsMarginRight: number;
261
280
  }
281
+ interface ModelSource {
282
+ src: string;
283
+ type?: string;
284
+ }
262
285
  interface SpatializedStatic3DElementProperties extends SpatializedElementProperties {
263
286
  modelURL: string;
287
+ sources?: ModelSource[];
264
288
  modelTransform?: number[];
289
+ autoplay?: boolean;
290
+ loop?: boolean;
291
+ animationPaused?: boolean;
292
+ playbackRate?: number;
265
293
  }
266
294
  interface SpatialSceneCreationOptions$1 {
267
295
  defaultSize?: {
@@ -436,6 +464,56 @@ interface AttachmentEntityUpdateOptions {
436
464
  height: number;
437
465
  };
438
466
  }
467
+ type SceneUnitPx = `${number}px`;
468
+ type SceneUnitM = `${number}m`;
469
+ type SceneUnit = number | SceneUnitPx | SceneUnitM;
470
+ interface XRSceneSize {
471
+ width: SceneUnit;
472
+ height: SceneUnit;
473
+ depth?: SceneUnit;
474
+ }
475
+ interface XRSceneResizability {
476
+ minWidth?: SceneUnit;
477
+ minHeight?: SceneUnit;
478
+ maxWidth?: SceneUnit;
479
+ maxHeight?: SceneUnit;
480
+ }
481
+ interface XRMainSceneConfig extends XRSpatialSceneDefaults {
482
+ type?: SpatialSceneType$1;
483
+ }
484
+ interface XRSpatialSceneDefaults {
485
+ default_size?: XRSceneSize;
486
+ resizability?: XRSceneResizability;
487
+ worldScaling?: WorldScalingType;
488
+ worldAlignment?: WorldAlignmentType;
489
+ baseplateVisibility?: BaseplateVisibilityType;
490
+ }
491
+ interface XRSpatialSceneOverrides {
492
+ window_scene?: XRSpatialSceneDefaults;
493
+ volume_scene?: XRSpatialSceneDefaults;
494
+ }
495
+ interface XRSpatialSceneConfig extends XRSpatialSceneDefaults {
496
+ overrides?: XRSpatialSceneOverrides;
497
+ }
498
+ interface XRPrdConfig {
499
+ xr_main_scene?: XRMainSceneConfig;
500
+ xr_spatial_scene?: XRSpatialSceneConfig;
501
+ }
502
+ interface PWAManifest extends XRPrdConfig {
503
+ name?: string;
504
+ short_name?: string;
505
+ start_url?: string;
506
+ display?: string;
507
+ icons?: Array<{
508
+ src: string;
509
+ sizes?: string;
510
+ type?: string;
511
+ purpose?: string;
512
+ }>;
513
+ id?: string;
514
+ scope?: string;
515
+ [key: string]: any;
516
+ }
439
517
 
440
518
  declare class SpatialComponent extends SpatialObject {
441
519
  constructor(id: string);
@@ -544,10 +622,6 @@ declare class Attachment extends SpatialObject {
544
622
  }
545
623
  declare function createAttachmentEntity(options: AttachmentEntityOptions): Promise<Attachment>;
546
624
 
547
- declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
548
- type: SpatialSceneType$1;
549
- }): void;
550
-
551
625
  type SpatialSceneCreationOptionsInternal = SpatialSceneCreationOptions$1 & {
552
626
  type: SpatialSceneType$1;
553
627
  };
@@ -559,6 +633,10 @@ declare enum SpatialSceneState {
559
633
  fail = "fail"
560
634
  }
561
635
 
636
+ declare function initScene(name: string, callback: (pre: SpatialSceneCreationOptions$1) => SpatialSceneCreationOptions$1, options?: {
637
+ type: SpatialSceneType$1;
638
+ }): void;
639
+
562
640
  /**
563
641
  * Represents the spatial scene that contains all spatialized elements.
564
642
  * This class follows the singleton pattern - only one instance exists per application.
@@ -641,8 +719,9 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
641
719
  * Registers the element to receive spatial events.
642
720
  * @param id Unique identifier for this element
643
721
  * @param modelURL URL of the 3D model
722
+ * @param sources Optional fallback model sources
644
723
  */
645
- constructor(id: string, modelURL: string);
724
+ constructor(id: string, modelURL?: string, sources?: ModelSource[]);
646
725
  /**
647
726
  * Promise resolver for the ready state.
648
727
  * Used to resolve the ready promise when the model is loaded.
@@ -652,7 +731,16 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
652
731
  * Caches the last model URL to detect changes.
653
732
  * Used to reset the ready promise when the model URL changes.
654
733
  */
655
- private modelURL;
734
+ private modelURL?;
735
+ /**
736
+ * Caches the last sources array to detect changes.
737
+ */
738
+ private sources?;
739
+ /**
740
+ * The model URL that was successfully loaded by the native runtime.
741
+ */
742
+ private _currentSrc;
743
+ get currentSrc(): string;
656
744
  /**
657
745
  * Creates a new promise for tracking the ready state of the model.
658
746
  * @returns Promise that resolves when the model is loaded (true) or fails to load (false)
@@ -670,14 +758,74 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
670
758
  * @returns Promise resolving when the update is complete
671
759
  */
672
760
  updateProperties(properties: Partial<SpatializedStatic3DElementProperties>): Promise<CommandResult>;
761
+ /**
762
+ * Total animation duration in seconds, synced from native.
763
+ */
764
+ private _duration;
765
+ /**
766
+ * Returns the total animation duration in seconds.
767
+ */
768
+ get duration(): number;
769
+ /**
770
+ * Playback speed multiplier.
771
+ */
772
+ private _playbackRate;
773
+ /**
774
+ * Returns the current playback rate.
775
+ */
776
+ get playbackRate(): number;
777
+ /**
778
+ * Sets the playback rate and sends it to native.
779
+ */
780
+ set playbackRate(value: number);
781
+ /**
782
+ * Whether the animation is currently paused.
783
+ */
784
+ private _paused;
785
+ /**
786
+ * Returns whether the animation is currently paused.
787
+ */
788
+ get paused(): boolean;
789
+ /**
790
+ * Callback for animation state changes.
791
+ */
792
+ private _onAnimationStateChangeCallback?;
793
+ /**
794
+ * Sets the callback for animation state changes.
795
+ */
796
+ set onAnimationStateChangeCallback(callback: undefined | ((detail: AnimationStateChangeDetail) => void));
797
+ /**
798
+ * Starts or resumes animation playback.
799
+ * @returns Promise resolving when the command is sent
800
+ */
801
+ play(): Promise<void>;
802
+ /**
803
+ * Pauses animation playback.
804
+ * @returns Promise resolving when the command is sent
805
+ */
806
+ pause(): Promise<void>;
673
807
  /**
674
808
  * Processes events received from the WebSpatial environment.
675
809
  * Handles model loading events in addition to base spatial events.
676
810
  * @param data The event data received from the WebSpatial system
677
811
  */
678
- onReceiveEvent(data: {
679
- type: SpatialWebMsgType;
680
- }): void;
812
+ onReceiveEvent(data: Static3DReceiveEventData): void;
813
+ /**
814
+ * Whether the model should automatically play its first animation on load.
815
+ */
816
+ private _autoplay;
817
+ /**
818
+ * Returns whether autoplay is enabled for this element.
819
+ */
820
+ get autoplay(): boolean;
821
+ /**
822
+ * Whether the model animation should loop continuously.
823
+ */
824
+ private _loop;
825
+ /**
826
+ * Returns whether loop is enabled for this element.
827
+ */
828
+ get loop(): boolean;
681
829
  /**
682
830
  * Callback function for successful model loading.
683
831
  */
@@ -698,6 +846,7 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
698
846
  set onLoadFailureCallback(callback: undefined | (() => void));
699
847
  updateModelTransform(transform: DOMMatrixReadOnly): void;
700
848
  }
849
+ type Static3DReceiveEventData = ModelLoadSuccess | ModelLoadFailure | ReceiveEventData | AnimationStateChangeMsg;
701
850
 
702
851
  /**
703
852
  * Session used to establish a connection to the spatial renderer of the system.
@@ -723,7 +872,7 @@ declare class SpatialSession {
723
872
  * @param modelURL Optional URL to the 3D model to load
724
873
  * @returns Promise resolving to a new SpatializedStatic3DElement instance
725
874
  */
726
- createSpatializedStatic3DElement(modelURL: string): Promise<SpatializedStatic3DElement>;
875
+ createSpatializedStatic3DElement(modelURL?: string, sources?: ModelSource[]): Promise<SpatializedStatic3DElement>;
727
876
  /**
728
877
  * Initializes the spatial scene with custom configuration.
729
878
  * This is a reference to the initScene function from scene-polyfill.
@@ -922,6 +1071,9 @@ declare global {
922
1071
  webSpatial?: {
923
1072
  genToken?: () => string
924
1073
  }
1074
+ __webspatialShell__?: {
1075
+ genToken?: () => string
1076
+ }
925
1077
 
926
1078
  // Will be removed in favor of __WebSpatialData
927
1079
  WebSpatailNativeVersion: string
@@ -946,4 +1098,4 @@ declare global {
946
1098
 
947
1099
  declare const isSSREnv: () => boolean;
948
1100
 
949
- export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, physicalMetrics as PhysicalMetrics, type Point3D, type Quaternion, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEndEventDetail, type SpatialDragEvent, type SpatialDragEventDetail, type SpatialDragStartEvent, type SpatialDragStartEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEndEventDetail, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEndEventDetail, type SpatialRotateEvent, type SpatialRotateEventDetail, SpatialScene, type SpatialSceneCreationOptions$1 as SpatialSceneCreationOptions, type SpatialSceneProperties, SpatialSceneState$1 as SpatialSceneState, type SpatialSceneType$1 as SpatialSceneType, SpatialSceneValues, SpatialSession, SpatialSphereGeometry, type SpatialSphereGeometryOptions, type SpatialTapEvent, type SpatialTapEventDetail, SpatialUnlitMaterial, type SpatialUnlitMaterialOptions, Spatialized2DElement, type Spatialized2DElementProperties, SpatializedDynamic3DElement, SpatializedElement, type SpatializedElementProperties, SpatializedElementType, SpatializedStatic3DElement, type SpatializedStatic3DElementProperties, type Vec3, type WorldAlignmentType, WorldAlignmentValues, type WorldScalingType, WorldScalingValues, createAttachmentEntity, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
1101
+ export { Attachment, type AttachmentEntityOptions, type AttachmentEntityUpdateOptions, type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, type ModelSource, type PWAManifest, physicalMetrics as PhysicalMetrics, type Point3D, type Quaternion, type SceneUnit, type SceneUnitM, type SceneUnitPx, 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, type XRMainSceneConfig, type XRPrdConfig, type XRSceneResizability, type XRSceneSize, type XRSpatialSceneConfig, type XRSpatialSceneDefaults, type XRSpatialSceneOverrides, createAttachmentEntity, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
@@ -2,13 +2,13 @@
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.0"
5
+ window.__webspatialsdk__['core-sdk-version'] = "1.6.0"
6
6
  })()
7
7
 
8
- "use strict";var webspatialCore=(()=>{var jt=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var ti=Object.prototype.hasOwnProperty;var h=(i,t)=>()=>(i&&(t=i(i=0)),t);var R=(i,t)=>{for(var e in t)jt(i,e,{get:t[e],enumerable:!0})},ei=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ye(t))!ti.call(i,n)&&n!==e&&jt(i,n,{get:()=>t[n],enumerable:!(r=Ze(t,n))||r.enumerable});return i};var V=i=>ei(jt({},"__esModule",{value:!0}),i);var ii,G,kt=h(()=>{"use strict";ii=typeof window>"u",G=()=>ii});var Z,ue=h(()=>{"use strict";Z=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 g(i,t=""){return{success:!1,data:void 0,errorCode:i,errorMessage:t}}var _=h(()=>{"use strict"});var ye={};R(ye,{PuppeteerPlatform:()=>Jt});var Jt,Se=h(()=>{"use strict";_();console.log("PuppeteerPlatform");Jt=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(g("500","JSB execution error"))}else r(m("ok"))}catch(n){console.error(`PuppeteerPlatform cmd Error: ${t}, msg: ${e} error: ${n}`),r(g("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(g("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),g("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=`
8
+ "use strict";var webspatialCore=(()=>{var qt=Object.defineProperty;var li=Object.getOwnPropertyDescriptor;var pi=Object.getOwnPropertyNames;var ci=Object.prototype.hasOwnProperty;var x=(i,e)=>()=>(i&&(e=i(i=0)),e);var O=(i,e)=>{for(var t in e)qt(i,t,{get:e[t],enumerable:!0})},di=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of pi(e))!ci.call(i,a)&&a!==t&&qt(i,a,{get:()=>e[a],enumerable:!(n=li(e,a))||n.enumerable});return i};var k=i=>di(qt({},"__esModule",{value:!0}),i);var mi,B,Qt=x(()=>{"use strict";mi=typeof window>"u",B=()=>mi});var rt,be=x(()=>{"use strict";rt=class{callJSB(e,t){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocol(e,t,n,a){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocolSync(e,t,n,a,r){return{success:!0,data:void 0,errorCode:void 0,errorMessage:void 0}}}});function u(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function f(i,e=""){return{success:!1,data:void 0,errorCode:i,errorMessage:e}}var $=x(()=>{"use strict"});var xe={};O(xe,{PuppeteerPlatform:()=>Kt});var Kt,Ee=x(()=>{"use strict";$();console.log("PuppeteerPlatform");Kt=class{iframeRegistry=new Map;constructor(){}callJSB(e,t){return new Promise(n=>{try{if(window.__handleJSBMessage)try{console.log(` core-sdk Puppeteer Platform: callJSB: ${e}::${t}`);let a=window.__handleJSBMessage(`${e}::${t}`);console.log(` core-sdk Puppeteer Platform callJSB result: ${a}`),n(u(a))}catch{n(f("500","JSB execution error"))}else n(u("ok"))}catch(a){console.error(`PuppeteerPlatform cmd Error: ${e}, msg: ${t} error: ${a}`),n(f("500","Internal error"))}})}createSpatializedElementSync(e,t){try{console.log(`[Puppeteer Platform] Creating spatialized element sync with id: ${e}, url: ${t}`);let n=window;if(n.__handleJSBMessage){let a={id:e,url:t};n.__handleJSBMessage(`CreateSpatialized2DElement::${JSON.stringify(a)}`)}}catch(n){console.error("Error creating spatialized element sync:",n)}}callWebSpatialProtocol(e,t,n,a){return console.log(`PuppeteerPlatform: Calling webspatial protocol: webspatial://${e}${t?`?${t}`:""}`),new Promise(r=>{try{let o=`webspatial://${e}${t?`?${t}`:""}`,{spatialId:s,iframe:l,windowProxy:d}=this.createIframeWindow(o,n,a);e==="createSpatialized2DElement"&&this.createSpatializedElementSync(s,o),console.log(`[Puppeteer Platform] iframe created with spatialId: ${s}`),this.iframeRegistry.set(s,l),r(u({windowProxy:d,id:s}))}catch(o){console.error("Error calling webspatial protocol:",o),r(f("500","Failed to call webspatial protocol"))}})}callWebSpatialProtocolSync(e,t,n,a){try{let r=`webspatial://${e}${t?`?${t}`:""}`;console.log(`Calling webspatial protocol sync: ${r}`);let{spatialId:o,iframe:s,windowProxy:l}=this.createIframeWindow(r,n,a);return e==="createSpatialized2DElement"&&this.createSpatializedElementSync(o,r),this.iframeRegistry.set(o,s),u({windowProxy:l,id:o})}catch(r){return console.error("Error calling webspatial protocol sync:",r),f("500","Failed to call webspatial protocol sync")}}createIframeWindow(e,t,n){let a=document.createElement("iframe");a.style.border="none",a.style.display="none",a.style.width="100%",a.style.height="100%";let r=this.generateUUID();a.spatialId=r,a.id=`spatial-iframe-${r}`;let o=this.parseFeatures(n||"");o.width&&(a.style.width=o.width),o.height&&(a.style.height=o.height),o.left&&(a.style.left=o.left,a.style.position="absolute"),o.top&&(a.style.top=o.top,a.style.position="absolute"),document.body.appendChild(a);let s=this.createEnhancedWindowProxy(a,e,r);return a.src="about:blank",console.log(`PuppeteerPlatform created iframe window with spatialId: ${r}, URL: ${e}`),this.initializeIframeContent(a,e,r),{spatialId:r,iframe:a,windowProxy:s}}createEnhancedWindowProxy(e,t,n){return{location:{href:t,toString:()=>t,reload:()=>{e.contentWindow&&e.contentWindow.location.reload()}},navigator:{userAgent:`Mozilla/5.0 (WebKit) SpatialId/${n}`},close:()=>{console.log(`Closing iframe with spatialId: ${n}`),e.remove(),this.iframeRegistry.delete(n)},document:e.contentDocument||{},contentWindow:e.contentWindow||{},postMessage:(a,r)=>{e.contentWindow&&e.contentWindow.postMessage(a,r||"*")},addEventListener:(a,r)=>{e.contentWindow&&e.contentWindow.addEventListener(a,r)},removeEventListener:(a,r)=>{e.contentWindow&&e.contentWindow.removeEventListener(a,r)},executeScript:a=>{if(e.contentWindow)try{return e.contentWindow.eval(a)}catch(r){return console.error(`Error executing script in iframe ${n}:`,r),null}return null},getIframe:()=>e,getSpatialId:()=>n}}initializeIframeContent(e,t,n){try{e.onload=()=>{try{let a=`
9
9
  // inject communication script
10
- window.webSpatialId = '${r}';
11
- window.SpatialId = '${r}';
10
+ window.webSpatialId = '${n}';
11
+ window.SpatialId = '${n}';
12
12
 
13
13
  // override window.open to support webspatial protocol
14
14
  const originalOpen = window.open;
@@ -37,8 +37,8 @@
37
37
  // send loaded message
38
38
  window.parent.postMessage({
39
39
  type: 'iframe_loaded',
40
- spatialId: '${r}',
41
- url: '${e}'
40
+ spatialId: '${n}',
41
+ url: '${t}'
42
42
  }, '${window.location.origin}');
43
43
 
44
44
  // set message handler
@@ -52,11 +52,11 @@
52
52
  // add command handling logic here
53
53
  }
54
54
  });
55
- `,a=t.contentDocument;a&&(a.open(),a.write(`
55
+ `,r=e.contentDocument;r&&(r.open(),r.write(`
56
56
  <!DOCTYPE html>
57
57
  <html>
58
58
  <head>
59
- <title>Spatial Iframe - ${r}</title>
59
+ <title>Spatial Iframe - ${n}</title>
60
60
  <meta charset="UTF-8">
61
61
  <style>
62
62
  body {
@@ -67,9 +67,9 @@
67
67
  </style>
68
68
  </head>
69
69
  <body>
70
- <script>${n}</script>
70
+ <script>${a}</script>
71
71
  </body>
72
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,v=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 fe={};R(fe,{PicoOSPlatform:()=>Ht});function ge(){return Nt=(Nt+1)%ri,`rId_${Nt}`}var Nt,ri,Ht,he=h(()=>{"use strict";_();v();Nt=0,ri=1e5;Ht=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=ge();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(g(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(g(p,y))}}}catch(a){console.error(`SwanPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(g(o,s))}})}async callWebSpatialProtocol(t,e,r,n){return new Promise((a,o)=>{let s=ge();try{let p=null;c.addEventReceiver(s,y=>{a(m({windowProxy:p,id:y.spatialId})),c.removeEventReceiver(s)}),p=this.openWindow(t,"rid="+s,r,n).windowProxy}catch(p){let{code:y,message:X}=p;c.removeEventReceiver(s),a(g(y,X))}})}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 Ee={};R(Ee,{AndroidPlatform:()=>Kt});function ai(){return Qt=(Qt+1)%ni,`rId_${Qt}`}var qt,Qt,ni,Kt,be=h(()=>{"use strict";_();S();v();qt=0,Qt=0,ni=1e5;Kt=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=ai();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(g(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(g(p,y))}}}catch(a){console.error(`AndroidPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(g(o,s))}})}async callWebSpatialProtocol(t,e,r,n){await new Promise(p=>setTimeout(p,16*qt)),qt++;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 qt--,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 xe={};R(xe,{VisionOSPlatform:()=>Xt});var Xt,we=h(()=>{"use strict";_();Xt=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 g(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 oi(i){let t=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function si(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 ve(){if(G())return new Z;let i=window.navigator.userAgent,t=oi(i);if(window.navigator.userAgent.includes("Puppeteer")){let e=(Se(),V(ye)).PuppeteerPlatform;return new e}else if(i.includes("PicoWebApp")&&si(t,[0,0,1])){let e=(he(),V(fe)).PicoOSPlatform;return new e}else if(i.includes("Android")||i.includes("Linux")){let e=(be(),V(Ee)).AndroidPlatform;return new e}else{let e=(we(),V(xe)).VisionOSPlatform;return new e}}var Pe=h(()=>{"use strict";kt();ue()});function Y(i,t){return i===""?0:i.endsWith("%")?t*parseFloat(i)/100:parseFloat(i)}function Me(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:Y(e,t),bottomLeading:Y(n,t),topTrailing:Y(r,t),bottomTrailing:Y(a,t)}}function Te(i,t,e){let{x:r,y:n,z:a}=i,{x:o,y:s,z:p}=t,{x:y,y:X,z:Ft}=e,E=new DOMMatrix;return E=E.translate(r,n,a),E=E.rotate(o,s,p),E=E.scale(y,X,Ft),E}var Zt=h(()=>{"use strict"});var Yt,l,tt,et,it,rt,nt,at,P,ot,st,pt,lt,ct,dt,mt,ut,yt,St,gt,ft,ht,Et,bt,xt,wt,vt,T,Pt,Mt,Tt,Dt,Rt,Ct,U,L,Ot,It,zt,Wt,At,S=h(()=>{"use strict";Pe();Zt();Yt=ve(),l=class{commandType="";async execute(){let t=this.getParams(),e=t?JSON.stringify(t):"";return Yt.callJSB(this.commandType,e)}},tt=class extends l{constructor(e,r){super();this.entity=e;this.properties=r}commandType="UpdateEntityProperties";getParams(){let e=Te(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}}},et=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}}},it=class extends l{properties;commandType="UpdateSpatialSceneProperties";constructor(t){super(),this.properties=t}getParams(){return this.properties}},rt=class extends l{config;commandType="UpdateSceneConfig";constructor(t){super(),this.config=t}getParams(){return{config:this.config}}},nt=class extends l{constructor(e){super();this.id=e}commandType="FocusScene";getParams(){return{id:this.id}}},at=class extends l{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},P=class extends l{constructor(e){super();this.spatialObject=e}getParams(){let e=this.getExtraParams();return{id:this.spatialObject.id,...e}}},ot=class extends P{properties;commandType="UpdateSpatialized2DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},st=class extends P{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},pt=class extends P{properties;commandType="UpdateUnlitMaterialProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},lt=class extends P{matrix;commandType="UpdateSpatializedElementTransform";constructor(t,e){super(t),this.matrix=e}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},ct=class extends P{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},dt=class extends P{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(t,e){super(t),this.spatializedElement=e}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},mt=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(t){super(),this.spatializedElement=t}getParams(){return{spatializedElementId:this.spatializedElement.id}}},ut=class extends l{constructor(e){super();this.modelURL=e;this.modelURL=e}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},yt=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},St=class extends l{constructor(e){super();this.name=e}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},gt=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"},ft=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ht=class extends l{constructor(e){super();this.options=e}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},Et=class extends l{constructor(e,r={}){super();this.type=e;this.options=r}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},bt=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateUnlitMaterial"},xt=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"},wt=class extends l{constructor(e,r){super();this.entity=e;this.comp=r}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="RemoveComponentFromEntity"},vt=class extends l{constructor(e,r){super();this.entityId=e;this.materials=r}getParams(){return{entityId:this.entityId,materialIds:this.materials.map(e=>e.id)}}commandType="SetMaterialsOnEntity"},T=class extends l{constructor(e,r){super();this.childId=e;this.parentId=r}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},Pt=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"},Mt=class extends l{constructor(e,r){super();this.fromEntityId=e;this.position=r}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},Tt=class extends l{constructor(e,r){super();this.entityId=e;this.position=r}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},Dt=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"},Rt=class extends l{constructor(e=""){super();this.id=e}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Ct=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 Yt.callWebSpatialProtocol(this.commandType,t,this.target,this.features)}executeSync(){let t=this.getQuery();return Yt.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}},Ot=class extends L{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},It=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}}},zt=class extends L{constructor(e){super();this.options=e}commandType="createAttachment";getParams(){return{}}},Wt=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}}},At=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}}});var Pi={};R(Pi,{Attachment:()=>_t,BaseplateVisibilityValues:()=>Re,CubeInfo:()=>ee,ModelComponent:()=>F,PhysicalMetrics:()=>de,Spatial:()=>A,SpatialBoxGeometry:()=>N,SpatialComponent:()=>$,SpatialConeGeometry:()=>K,SpatialCylinderGeometry:()=>q,SpatialEntity:()=>D,SpatialGeometry:()=>f,SpatialMaterial:()=>j,SpatialModelAsset:()=>J,SpatialModelEntity:()=>B,SpatialObject:()=>d,SpatialPlaneGeometry:()=>Q,SpatialScene:()=>w,SpatialSceneState:()=>oe,SpatialSceneValues:()=>Ie,SpatialSession:()=>W,SpatialSphereGeometry:()=>H,SpatialUnlitMaterial:()=>k,Spatialized2DElement:()=>C,SpatializedDynamic3DElement:()=>I,SpatializedElement:()=>b,SpatializedElementType:()=>De,SpatializedStatic3DElement:()=>O,WorldAlignmentValues:()=>Oe,WorldScalingValues:()=>Ce,createAttachmentEntity:()=>le,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>ie,isValidSceneUnit:()=>Vt,isValidSpatialSceneType:()=>ae,isValidWorldAlignmentType:()=>ne,isValidWorldScalingType:()=>re});S();var d=class{constructor(t){this.id=t}name;isDestroyed=!1;async inspect(){let t=await new Rt(this.id).execute();if(t.success)return t.data;throw new Error(t.errorMessage)}async destroy(){if(this.isDestroyed)return;let t=await new Ct(this.id).execute();if(t.success)return this.onDestroy(),this.isDestroyed=!0,t.data;if(this.isDestroyed)return;throw new Error(t.errorMessage)}onDestroy(){}};S();S();S();var te,w=class i extends d{static getInstance(){return te||(te=new i("")),te}async convertCoordinate(t,e,r){try{return(await new Dt(t,e,r).execute())?.data??t}catch(n){throw console.warn("SpatialScene.convertCoordinate error:",n),n}}async updateSpatialProperties(t){return new it(t).execute()}async addSpatializedElement(t){return new mt(t).execute()}async updateSceneCreationConfig(t){return new rt(t).execute()}async getState(){return(await new at().execute()).data.name}};var De=(r=>(r[r.Spatialized2DElement=0]="Spatialized2DElement",r[r.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",r[r.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",r))(De||{}),Re=["automatic","visible","hidden"];function ie(i){return Re.includes(i)}var Ce=["automatic","dynamic"];function re(i){return Ce.includes(i)}var Oe=["adaptive","automatic","gravityAligned"];function ne(i){return Oe.includes(i)}var Ie=["window","volume"];function ae(i){return Ie.includes(i)}function Vt(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 oe=(a=>(a.idle="idle",a.pending="pending",a.willVisible="willVisible",a.visible="visible",a.fail="fail",a))(oe||{}),ee=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 pi={defaultSize:{width:1280,height:720}},li={defaultSize:{width:.94,height:.94,depth:.94}},ci="webspatial://",Gt=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(ci)){if(t.includes("createSpatialized2DElement")){let p=window.webSpatial?.genToken?.();if(p){let y=window.location.host,Ft=`${window.location.protocol}//${y}/${p}/?command=createSpatialized2DElement`,E=new URL(t).searchParams.get("rid"),me=new URL(Ft);return E&&me.searchParams.set("rid",E),this.originalOpen(me.toString(),e,r)}}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 It(t,n,e,r).executeSync(),s=o.data?.id;return s&&new nt(s).execute(),o.data?.windowProxy};initScene(t,e,r){let n=r?.type??"window",a=pe(n),o=e({...a}),[s,p]=Ve(o,n);p.length>0&&console.warn(`initScene ${t} with errors: ${p.join(", ")}`),this.configMap[t]={...s,type:n}}};function ze(i){return i/1360}function We(i){return i*1360}function Ae(i,t,e){if(typeof i=="number")return e==="px"&&t==="px"||e==="m"&&t==="m"?i:e==="px"&&t==="m"?ze(i):e==="m"&&t==="px"?We(i):i;if(t==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return ze(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 We(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function Ve(i,t){let e=pe(t),r=[],n=t==="window";if(ae(t)||r.push("sceneType"),i.defaultSize){let a=["width","height","depth"];for(let o of a)o in i.defaultSize&&(Vt(i.defaultSize[o])?i.defaultSize[o]=Ae(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&&(Vt(i.resizability[o])?i.resizability[o]=Ae(i.resizability[o],"px",n?"px":"m"):(i.resizability[o]=void 0,r.push(`resizability.${o}`)))}return i.worldScaling&&(re(i.worldScaling)||(i.worldScaling="automatic",r.push("worldScaling"))),i.worldAlignment&&(ne(i.worldAlignment)||(i.worldAlignment="automatic",r.push("worldAlignment"))),i.baseplateVisibility&&(ie(i.baseplateVisibility)||(i.baseplateVisibility="automatic",r.push("baseplateVisibility"))),[i,r]}function Ge(i,t,e){return Gt.getInstance().initScene(i,t,e)}function di(i){Gt.getInstance().init(i)}function se(i){i.document.onclick=function(t){let e=t.target,r=!1;for(;!r;){if(e&&e.tagName=="A")return!mi(t);if(e&&e.parentElement)e=e.parentElement;else break}}}function mi(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 pe(i){return i==="window"?pi:li}async function ui(){if(!window.opener||await w.getInstance().getState()!=="pending")return;function t(e){document.readyState==="interactive"||document.readyState==="complete"?e():document.addEventListener("DOMContentLoaded",e)}t(async()=>{let e=pe(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]=Ve(r,n);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await w.getInstance().updateSceneCreationConfig({...a,type:n})})}function _e(){di(window),se(window),ui()}S();S();S();v();function u(i,t){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:t})}var b=class extends d{constructor(e){super(e);this.id=e;c.addEventReceiver(e,this.onReceiveEvent.bind(this))}async updateTransform(e){return new lt(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 b{constructor(e,r){super(e);this.windowProxy=r;se(r)}async updateProperties(e){return new ot(this,e).execute()}async addSpatializedElement(e){return new dt(this,e).execute()}};S();var O=class extends b{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 ct(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})}};S();var I=class extends b{children=[];events={};constructor(t){super(t)}async addEntity(t){let e=new T(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 st(this,t).execute()}};async function Ue(){let i=await new Ot().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 Le(i){let t=await new ut(i).execute();if(t.success){let{id:e}=t.data;return new O(e,i)}else throw new Error("createSpatializedStatic3DElement failed")}async function Be(){let i=await new yt().execute();if(i.success){let{id:t}=i.data;return new I(t)}else throw new Error("createSpatializedDynamic3DElement failed")}S();var _t=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 At(this.id,e).execute()}};async function le(i){let t=await new zt(i).execute();if(!t.success)throw new Error("createAttachmentEntity failed: "+t?.errorMessage);let{id:e,windowProxy:r}=t.data;return await new Wt(e,i).execute(),new _t(e,r,i)}S();S();S();v();var D=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 xt(this,e).execute()}async removeComponent(e){return new wt(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 T(e.id,this.id).execute();return this.children.push(e),e.parent=this,r}async removeFromParent(){let e=await new T(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 tt(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 et(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 Pt(e,r,n).execute()}async convertFromEntityToScene(e,r){return new Mt(e,r).execute()}async convertFromSceneToEntity(e,r){return new Tt(e,r).execute()}};S();var B=class extends D{constructor(e,r,n){super(e,n);this.id=e;this.options=r;this.userData=n}async setMaterials(e){return new vt(this.id,e).execute()}};v();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}};S();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 pt(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 St(i?.name).execute();if(t.success){let{id:e}=t.data;return new D(e,i)}else throw new Error("createSpatialEntity failed:"+t?.errorMessage)}async function z(i,t){let e=await new Et(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 Fe(i){let t=await new bt(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 je(i){let t=await new gt(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 ke(i,t){let e=await new ft(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 Je(i){let t=await new ht(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 Q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="PlaneGeometry"};var K=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="ConeGeometry"};var W=class{getSpatialScene(){return w.getInstance()}createSpatialized2DElement(){return Ue()}createSpatializedStatic3DElement(t){return Le(t)}initScene=Ge;createSpatializedDynamic3DElement(){return Be()}createEntity(t){return $e(t)}createBoxGeometry(t={}){return z(N,t)}createPlaneGeometry(t={}){return z(Q,t)}createSphereGeometry(t={}){return z(H,t)}createConeGeometry(t){return z(K,t)}createCylinderGeometry(t){return z(q,t)}createModelComponent(t){return je(t)}createUnlitMaterial(t){return Fe(t)}createModelAsset(t){return Je(t)}createSpatialModelEntity(t,e){return ke(t,e)}createAttachmentEntity(t){return le(t)}};v();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.5.0"}};var de={};R(de,{getValue:()=>gi,physicalToPoint:()=>Si,pointToPhysical:()=>yi,subscribe:()=>fi});v();var x={meterToPtUnscaled:1360,meterToPtScaled:1360};function Ne(i){return i?.worldScalingCompensation??"scaled"}function yi(i,t){return ce(),Ne(t)==="unscaled"?i/x.meterToPtUnscaled:i/x.meterToPtScaled}function Si(i,t){return ce(),Ne(t)==="unscaled"?i*x.meterToPtUnscaled:i*x.meterToPtScaled}function ce(){if(typeof window>"u")return;let i=window.__webspatialsdk__?.physicalMetrics;if(!i)return;let t={meterToPtScaled:i.meterToPtScaled??x.meterToPtScaled,meterToPtUnscaled:i.meterToPtUnscaled??x.meterToPtUnscaled};(t.meterToPtScaled!==x.meterToPtScaled||t.meterToPtUnscaled!==x.meterToPtUnscaled)&&(x=t)}function gi(){return ce(),x}function fi(i){if(typeof window>"u")return()=>{};let t=()=>{i()};return c.addEventReceiver("window",t),()=>{c.removeEventReceiver("window")}}kt();Zt();var He=new A,$t,Ut={backgroundMaterial:"--xr-background-material"},qe="";function Lt(i){i!==qe&&($t?.getSpatialScene()?.updateSpatialProperties({material:i}),qe=i)}function hi(){let t=getComputedStyle(document.documentElement).getPropertyValue(Ut.backgroundMaterial);Lt(t||"none")}var M={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function Qe(){let i=getComputedStyle(document.documentElement),t=Me(i);Ei(t)}function Ei(i){(M.topLeading!==i.topLeading||M.bottomLeading!==i.bottomLeading||M.topTrailing!==i.topTrailing||M.bottomTrailing!==i.bottomTrailing)&&($t?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),M.topLeading=i.topLeading,M.bottomLeading=i.bottomLeading,M.topTrailing=i.topTrailing,M.bottomTrailing=i.bottomTrailing)}function bi(i){$t?.getSpatialScene().updateSpatialProperties({opacity:i})}function Ke(){let i=getComputedStyle(document.documentElement),t=parseFloat(i.getPropertyValue("opacity"));bi(t)}function xi(){let i=document.documentElement.style,t=new Proxy(i,{set:function(e,r,n){let a=Reflect.set(e,r,n);return r===Ut.backgroundMaterial&&Lt(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")&&Qe(),r==="opacity"&&Ke(),a},get:function(e,r){return typeof e[r]=="function"?function(...n){if(r==="setProperty"){let[a,o]=n;a===Ut.backgroundMaterial&&Lt(o)}else if(r==="removeProperty"){let[a]=n;a===Ut.backgroundMaterial&&Lt("none")}return e[r](...n)}:Reflect.get(e,r)}});Object.defineProperty(document.documentElement,"style",{get:function(){return t}})}function wi(){new MutationObserver(Bt).observe(document.head,{childList:!0,subtree:!0})}function Bt(){hi(),Qe(),Ke()}function vi(){new MutationObserver(t=>{t.forEach(e=>{e.type==="attributes"&&e.attributeName&&Bt()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function Xe(){He.runInSpatialWeb()&&($t=await He.requestSession(),document.readyState==="complete"?Bt():window.addEventListener("load",()=>{Bt()}),xi(),wi(),vi())}!G()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(_e(),Xe());return V(Pi);})();
73
+ `),r.close())}catch(a){console.error("Error initializing iframe content:",a)}}}catch(a){console.error("Error setting up iframe:",a)}}parseFeatures(e){let t={};return e.split(",").forEach(a=>{let[r,o]=a.split("=").map(s=>s.trim());r&&o&&(t[r]=o)}),t}sendMessageToIframe(e,t){let n=this.iframeRegistry.get(e);return n&&n.contentWindow?(n.contentWindow.postMessage(t,window.location.origin),!0):!1}getAllActiveIframes(){let e=[];return this.iframeRegistry.forEach((t,n)=>{e.push({spatialId:n,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=x(()=>{"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 ve={};O(ve,{PicoOSPlatform:()=>Yt});function we(){return Zt=(Zt+1)%ui,`rId_${Zt}`}var Zt,ui,Yt,Pe=x(()=>{"use strict";$();P();Zt=0,ui=1e5;Yt=class{async callJSB(e,t){return new Promise((n,a)=>{try{let r=we();c.addEventReceiver(r,s=>{if(c.removeEventReceiver(r),s.success)n(u(s.data));else{let{code:l,message:d}=s.data;n(f(l,d))}});let o=window.webspatialBridge.postMessage(r,e,t);if(o!==""){c.removeEventReceiver(r);let s=JSON.parse(o);if(s.success)n(u(s.data));else{let{code:l,message:d}=s.data;n(f(l,d))}}}catch(r){console.error(`SwanPlatform cmd: ${e}, msg: ${t} error: ${r}`);let{code:o,message:s}=r;n(f(o,s))}})}async callWebSpatialProtocol(e,t,n,a){return new Promise((r,o)=>{let s=we();try{let l=null;c.addEventReceiver(s,d=>{r(u({windowProxy:l,id:d.spatialId})),c.removeEventReceiver(s)}),l=this.openWindow(e,"rid="+s,n,a).windowProxy}catch(l){let{code:d,message:h}=l;c.removeEventReceiver(s),r(f(d,h))}})}callWebSpatialProtocolSync(e,t,n,a){let{spatialId:r="",windowProxy:o}=this.openWindow(e,t,n,a);return u({windowProxy:o,id:r})}openWindow(e,t,n,a){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,n,a)}}}});var Me={};O(Me,{AndroidPlatform:()=>ie});function Si(){return ee=(ee+1)%yi,`rId_${ee}`}var te,ee,yi,ie,Re=x(()=>{"use strict";$();S();P();te=0,ee=0,yi=1e5;ie=class{async callJSB(e,t){return new Promise((n,a)=>{try{let r=Si();c.addEventReceiver(r,s=>{if(c.removeEventReceiver(r),s.success)n(u(s.data));else{let{code:l,message:d}=s.data;n(f(l,d))}});let o=window.webspatialBridge.postMessage(r,e,t);if(o!==""){c.removeEventReceiver(r);let s=JSON.parse(o);if(s.success)n(u(s.data));else{let{code:l,message:d}=s.data;n(f(l,d))}}}catch(r){console.error(`AndroidPlatform cmd: ${e}, msg: ${t} error: ${r}`);let{code:o,message:s}=r;n(f(o,s))}})}async callWebSpatialProtocol(e,t,n,a){await new Promise(l=>setTimeout(l,16*te)),te++;let r=await new F().execute();for(;!r.data.can;)await new Promise(l=>setTimeout(l,16)),r=await new F().execute();let{windowProxy:o}=this.openWindow(e,t,n,a);for(;!o?.open;)await new Promise(l=>setTimeout(l,16));for(o?.open("about:blank","_self");!o?.__SpatialId;)await new Promise(l=>setTimeout(l,16));let s=o?.__SpatialId;return te--,Promise.resolve(u({windowProxy:o,id:s}))}callWebSpatialProtocolSync(e,t,n,a){let{spatialId:r="",windowProxy:o}=this.openWindow(e,t,n,a);return u({windowProxy:o,id:r})}openWindow(e,t,n,a){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,n,a)}}}});var Ce={};O(Ce,{VisionOSPlatform:()=>ne});var ne,De=x(()=>{"use strict";$();ne=class{async callJSB(e,t){try{let n=await window.webkit.messageHandlers.bridge.postMessage(`${e}::${t}`);return u(n)}catch(n){let{code:a,message:r}=JSON.parse(n.message);return f(a,r)}}callWebSpatialProtocol(e,t,n,a){let{spatialId:r,windowProxy:o}=this.openWindow(e,t,n,a);return Promise.resolve(u({windowProxy:o,id:r}))}callWebSpatialProtocolSync(e,t,n,a){let{spatialId:r="",windowProxy:o}=this.openWindow(e,t,n,a);return u({windowProxy:o,id:r})}openWindow(e,t,n,a){let r=window.open(`webspatial://${e}?${t||""}`,n,a);return{spatialId:r?.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:r}}}});function fi(i){let e=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:null}function gi(i,e){if(!i)return!1;for(let t=0;t<3;t+=1){let n=i[t]-e[t];if(n>0)return!0;if(n<0)return!1}return!1}function Te(){if(B())return new rt;let i=window.navigator.userAgent,e=fi(i);if(window.navigator.userAgent.includes("Puppeteer")){let t=(Ee(),k(xe)).PuppeteerPlatform;return new t}else if(i.includes("PicoWebApp")&&gi(e,[0,0,1])){let t=(Pe(),k(ve)).PicoOSPlatform;return new t}else if(i.includes("Android")||i.includes("Linux")){let t=(Re(),k(Me)).AndroidPlatform;return new t}else{let t=(De(),k(Ce)).VisionOSPlatform;return new t}}var Oe=x(()=>{"use strict";Qt();be()});function ot(i,e){return i===""?0:i.endsWith("%")?e*parseFloat(i)/100:parseFloat(i)}function ze(i){let e=parseFloat(i.getPropertyValue("width")),t=i.getPropertyValue("border-top-left-radius"),n=i.getPropertyValue("border-top-right-radius"),a=i.getPropertyValue("border-bottom-left-radius"),r=i.getPropertyValue("border-bottom-right-radius");return{topLeading:ot(t,e),bottomLeading:ot(a,e),topTrailing:ot(n,e),bottomTrailing:ot(r,e)}}function Ae(i,e,t){let{x:n,y:a,z:r}=i,{x:o,y:s,z:l}=e,{x:d,y:h,z:G}=t,b=new DOMMatrix;return b=b.translate(n,a,r),b=b.rotate(o,s,l),b=b.scale(d,h,G),b}function M(i){let e=globalThis.structuredClone;if(typeof e=="function")try{return e(i)}catch{}return JSON.parse(JSON.stringify(i))}var st=x(()=>{"use strict"});var ae,p,lt,pt,ct,dt,mt,ut,R,yt,St,ft,gt,ht,bt,xt,Et,wt,vt,Pt,Mt,Rt,Ct,Dt,Tt,Ot,zt,D,At,It,Wt,_t,Vt,Ut,F,j,Gt,Lt,kt,Bt,$t,S=x(()=>{"use strict";Oe();st();ae=Te(),p=class{commandType="";async execute(){let e=this.getParams(),t=e?JSON.stringify(e):"";return ae.callJSB(this.commandType,t)}},lt=class extends p{constructor(t,n){super();this.entity=t;this.properties=n}commandType="UpdateEntityProperties";getParams(){let t=Ae(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}}},pt=class extends p{constructor(t,n,a){super();this.entity=t;this.type=n;this.isEnable=a}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}},ct=class extends p{properties;commandType="UpdateSpatialSceneProperties";constructor(e){super(),this.properties=e}getParams(){return this.properties}},dt=class extends p{config;commandType="UpdateSceneConfig";constructor(e){super(),this.config=e}getParams(){return{config:this.config}}},mt=class extends p{constructor(t){super();this.id=t}commandType="FocusScene";getParams(){return{id:this.id}}},ut=class extends p{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},R=class extends p{constructor(t){super();this.spatialObject=t}getParams(){let t=this.getExtraParams();return{id:this.spatialObject.id,...t}}},yt=class extends R{properties;commandType="UpdateSpatialized2DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},St=class extends R{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},ft=class extends R{properties;commandType="UpdateUnlitMaterialProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},gt=class extends R{matrix;commandType="UpdateSpatializedElementTransform";constructor(e,t){super(e),this.matrix=t}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},ht=class extends R{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},bt=class extends R{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(e,t){super(e),this.spatializedElement=t}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},xt=class extends p{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(e){super(),this.spatializedElement=e}getParams(){return{spatializedElementId:this.spatializedElement.id}}},Et=class extends p{constructor(t,n){super();this.modelURL=t;this.sources=n;this.modelURL=t,this.sources=n}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL,sources:this.sources}}},wt=class extends p{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},vt=class extends p{constructor(t){super();this.name=t}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},Pt=class extends p{constructor(t){super();this.options=t}getParams(){let t=this.options.mesh.id,n=this.options.materials.map(a=>a.id);return{geometryId:t,materialIds:n}}commandType="CreateModelComponent"},Mt=class extends p{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateSpatialModelEntity"},Rt=class extends p{constructor(t){super();this.options=t}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},Ct=class extends p{constructor(t,n={}){super();this.type=t;this.options=n}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},Dt=class extends p{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateUnlitMaterial"},Tt=class extends p{constructor(t,n){super();this.entity=t;this.comp=n}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},Ot=class extends p{constructor(t,n){super();this.entity=t;this.comp=n}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="RemoveComponentFromEntity"},zt=class extends p{constructor(t,n){super();this.entityId=t;this.materials=n}getParams(){return{entityId:this.entityId,materialIds:this.materials.map(t=>t.id)}}commandType="SetMaterialsOnEntity"},D=class extends p{constructor(t,n){super();this.childId=t;this.parentId=n}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},At=class extends p{constructor(t,n,a){super();this.fromEntityId=t;this.toEntityId=n;this.fromPosition=a}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},It=class extends p{constructor(t,n){super();this.fromEntityId=t;this.position=n}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},Wt=class extends p{constructor(t,n){super();this.entityId=t;this.position=n}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},_t=class extends p{constructor(t,n,a){super();this.position=t;this.fromId=n;this.toId=a}getParams(){return{position:this.position,fromId:this.fromId,toId:this.toId}}commandType="ConvertCoordinate"},Vt=class extends p{constructor(t=""){super();this.id=t}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Ut=class extends p{constructor(t){super();this.id=t}commandType="Destroy";getParams(){return{id:this.id}}},F=class extends p{constructor(t=""){super();this.id=t}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},j=class extends p{target;features;async execute(){let e=this.getQuery();return ae.callWebSpatialProtocol(this.commandType,e,this.target,this.features)}executeSync(){let e=this.getQuery();return ae.callWebSpatialProtocolSync(this.commandType,e,this.target,this.features)}getQuery(){let e,t=this.getParams();return t&&(e=Object.keys(t).map(n=>{let a=t[n],r=typeof a=="object"?JSON.stringify(a):a;return`${n}=${encodeURIComponent(r)}`}).join("&")),e}},Gt=class extends j{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Lt=class extends j{constructor(t,n,a,r){super();this.url=t;this.config=n;this.target=a;this.features=r}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}},kt=class extends j{constructor(t){super();this.options=t}commandType="createAttachment";getParams(){return{}}},Bt=class extends p{constructor(t,n){super();this.attachmentId=t;this.options=n}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}}},$t=class extends p{constructor(t,n){super();this.attachmentId=t;this.options=n}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}}});var zi={};O(zi,{Attachment:()=>Ft,BaseplateVisibilityValues:()=>We,CubeInfo:()=>oe,ModelComponent:()=>Q,PhysicalMetrics:()=>Se,Spatial:()=>U,SpatialBoxGeometry:()=>tt,SpatialComponent:()=>q,SpatialConeGeometry:()=>at,SpatialCylinderGeometry:()=>it,SpatialEntity:()=>T,SpatialGeometry:()=>g,SpatialMaterial:()=>K,SpatialModelAsset:()=>Y,SpatialModelEntity:()=>X,SpatialObject:()=>m,SpatialPlaneGeometry:()=>nt,SpatialScene:()=>v,SpatialSceneState:()=>de,SpatialSceneValues:()=>Ue,SpatialSession:()=>V,SpatialSphereGeometry:()=>et,SpatialUnlitMaterial:()=>Z,Spatialized2DElement:()=>A,SpatializedDynamic3DElement:()=>W,SpatializedElement:()=>w,SpatializedElementType:()=>Ie,SpatializedStatic3DElement:()=>I,WorldAlignmentValues:()=>Ve,WorldScalingValues:()=>_e,createAttachmentEntity:()=>he,isSSREnv:()=>B,isValidBaseplateVisibilityType:()=>se,isValidSceneUnit:()=>z,isValidSpatialSceneType:()=>ce,isValidWorldAlignmentType:()=>pe,isValidWorldScalingType:()=>le});S();var m=class{constructor(e){this.id=e}name;isDestroyed=!1;async inspect(){let e=await new Vt(this.id).execute();if(e.success)return e.data;throw new Error(e.errorMessage)}async destroy(){if(this.isDestroyed)return;let e=await new Ut(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();S();var re,v=class i extends m{static getInstance(){return re||(re=new i("")),re}async convertCoordinate(e,t,n){try{return(await new _t(e,t,n).execute())?.data??e}catch(a){throw console.warn("SpatialScene.convertCoordinate error:",a),a}}async updateSpatialProperties(e){return new ct(e).execute()}async addSpatializedElement(e){return new xt(e).execute()}async updateSceneCreationConfig(e){return new dt(e).execute()}async getState(){return(await new ut().execute()).data.name}};var Ie=(n=>(n[n.Spatialized2DElement=0]="Spatialized2DElement",n[n.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",n[n.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",n))(Ie||{}),We=["automatic","visible","hidden"];function se(i){return We.includes(i)}var _e=["automatic","dynamic"];function le(i){return _e.includes(i)}var Ve=["adaptive","automatic","gravityAligned"];function pe(i){return Ve.includes(i)}var Ue=["window","volume"];function ce(i){return Ue.includes(i)}function z(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 de=(r=>(r.idle="idle",r.pending="pending",r.willVisible="willVisible",r.visible="visible",r.fail="fail",r))(de||{}),oe=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}};st();var Se={};O(Se,{getValue:()=>hi,physicalToPoint:()=>ue,pointToPhysical:()=>me,subscribe:()=>bi});P();var E={meterToPtUnscaled:1360,meterToPtScaled:1360};function Ge(i){return i?.worldScalingCompensation??"scaled"}function me(i,e){return ye(),Ge(e)==="unscaled"?i/E.meterToPtUnscaled:i/E.meterToPtScaled}function ue(i,e){return ye(),Ge(e)==="unscaled"?i*E.meterToPtUnscaled:i*E.meterToPtScaled}function ye(){if(typeof window>"u")return;let i=window.__webspatialsdk__?.physicalMetrics;if(!i)return;let e={meterToPtScaled:i.meterToPtScaled??E.meterToPtScaled,meterToPtUnscaled:i.meterToPtUnscaled??E.meterToPtUnscaled};(e.meterToPtScaled!==E.meterToPtScaled||e.meterToPtUnscaled!==E.meterToPtUnscaled)&&(E=e)}function hi(){return ye(),E}function bi(i){if(typeof window>"u")return()=>{};let e=()=>{i()};return c.addEventReceiver("window",e),()=>{c.removeEventReceiver("window")}}var Fe={defaultSize:{width:1280,height:720}},je={defaultSize:{width:"0.94m",height:"0.94m",depth:"0.94m"}},Je={...Fe},Ne={...je},xi="webspatial://";function J(i,e){if(!e)return{...i||{}};let t={...i||{}};for(let n of Object.keys(e)){let a=t[n],r=e[n];r&&typeof r=="object"&&!Array.isArray(r)&&a&&typeof a=="object"&&!Array.isArray(a)?t[n]=J(a,r):t[n]=r}return t}function Le(i){let e={...i||{}},t=i.defaultSize!==void 0?i.defaultSize:i.default_size;return t!==void 0&&(e.defaultSize=t),"default_size"in e&&delete e.default_size,e}var H=class i{originalOpen;static instance;manifestReady=null;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(e){this.manifestReady=this.setupManifest(),this.originalOpen=e.open.bind(e),e.open=this.open}configMap={};callbackReturnMap={};getConfig(e){if(!(e===void 0||!this.configMap[e]))return this.configMap[e]}waitManifest(){return this.manifestReady??Promise.resolve()}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}}async setupManifest(){let e=await this.getPWAManifest();try{let t=e?.xr_spatial_scene;if(!t||typeof t!="object")return;let{overrides:n,...a}=t,r=J(a,n?.window_scene),o=J(a,n?.volume_scene),s=Le(r),l=Le(o);s&&Object.keys(s).length>0&&(Je=s),l&&Object.keys(l).length>0&&(Ne=l)}catch(t){console.warn("SceneManager.setupManifest failed; using built-in defaults.",t?.message||t)}}open=(e,t,n)=>{if(e?.startsWith(xi)){if(e.includes("createSpatialized2DElement")||e.includes("createAttachment")){let l=(window.webSpatial||window.__webspatialShell__)?.genToken?.();if(l){let d=e.includes("createAttachment")?"createAttachment":"createSpatialized2DElement",h=window.location.host,b=`${window.location.protocol}//${h}/${l}/?command=${d}`,L=new URL(e).searchParams.get("rid"),Xt=new URL(b);return L&&Xt.searchParams.set("rid",L),this.originalOpen(Xt.toString(),t,n)}}return this.originalOpen(e,t,n)}if(e=this.ensureAbsoluteUrl(e),t==="_self"||t==="_parent"||t==="_top")return this.originalOpen(e,t,n);let a=t?this.getConfig(t):void 0;if(a===void 0){let l=M(N("window")),[d]=fe(l,"window");a={...d,type:"window"}}let o=new Lt(e,a,t,n).executeSync(),s=o.data?.id;return s&&new mt(s).execute(),o.data?.windowProxy};initScene(e,t,n){let a=n?.type??"window",r=N(a),o=this.callbackReturnMap[e]??M(r),s=t(o),l=Ei(M(s)),d=M(l),h=M(N(a)),G=J(h,d),[b,L]=fe(G,a);L.length>0&&console.warn(`initScene ${e} with errors: ${L.join(", ")}`),this.callbackReturnMap[e]=l,this.configMap[e]={...b,type:a}}async getPWAManifest(e){let t=e;if(!t){let n=document.querySelector('link[rel="manifest"]');t=n?.getAttribute("href")||n?.href}if(t&&(t=this.ensureAbsoluteUrl(t),!!t)){if(t.startsWith("data:"))try{let n=t.indexOf(",");if(n<0)return;let a=t.slice(5,n),r=t.slice(n+1),s=/;base64/i.test(a)?atob(r):decodeURIComponent(r);return JSON.parse(s)}catch{return}try{let n=await fetch(t,{credentials:"same-origin"});if(!n.ok)throw new Error(String(n.status));try{return await n.json()}catch{let a=await n.text();return JSON.parse(a)}}catch{try{let n=await fetch(t);if(!n.ok)return;try{return await n.json()}catch{let a=await n.text();return JSON.parse(a)}}catch{return}}}}};function Ei(i){if(i?.defaultSize){let e=["width","height","depth"];for(let t of e)t in i.defaultSize&&!z(i.defaultSize[t])&&delete i.defaultSize[t]}if(i?.resizability){let e=["minWidth","minHeight","maxWidth","maxHeight"];for(let t of e)t in i.resizability&&!z(i.resizability[t])&&delete i.resizability[t]}return i}function ke(i){return me(i)}function Be(i){return ue(i)}function $e(i,e,t){if(typeof i=="number")return t==="px"&&e==="px"||t==="m"&&e==="m"?i:t==="px"&&e==="m"?ke(i):t==="m"&&e==="px"?Be(i):i;if(e==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return ke(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 Be(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function fe(i,e){let t=N(e),n=[],a=e==="window";if(ce(e)||n.push("sceneType"),i.defaultSize){let r=["width","height","depth"];for(let o of r)o in i.defaultSize&&(z(i.defaultSize[o])?i.defaultSize[o]=$e(i.defaultSize[o],a?"px":"m","px"):(delete i.defaultSize[o],n.push(`defaultSize.${o}`)))}if(i.resizability){let r=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of r)o in i.resizability&&(z(i.resizability[o])?i.resizability[o]=$e(i.resizability[o],"px","px"):(delete i.resizability[o],n.push(`resizability.${o}`)))}return i.worldScaling&&(le(i.worldScaling)||(i.worldScaling="automatic",n.push("worldScaling"))),i.worldAlignment&&(pe(i.worldAlignment)||(i.worldAlignment="automatic",n.push("worldAlignment"))),i.baseplateVisibility&&(se(i.baseplateVisibility)||(i.baseplateVisibility="automatic",n.push("baseplateVisibility"))),[i,n]}function He(i,e,t){return H.getInstance().initScene(i,e,t)}function wi(i){H.getInstance().init(i)}function ge(i){i.document.onclick=function(e){let t=e.target,n=!1;for(;!n;){if(t&&t.tagName=="A")return!vi(e);if(t&&t.parentElement)t=t.parentElement;else break}}}function vi(i){let e=i.target;if(e.tagName==="A"){let t=e,n=t.target,a=t.href;if(n&&n!=="_self")return i.preventDefault(),window.open(a,n),!0}}function N(i){return i==="window"?Je||Fe:Ne||je}async function Pi(){if(!window.opener||await v.getInstance().getState()!=="pending")return;function e(t){document.readyState==="interactive"||document.readyState==="complete"?t():document.addEventListener("DOMContentLoaded",t)}e(async()=>{await H.getInstance().waitManifest();let t=window.xrCurrentSceneType??"window",n=N(t),a=M(n),r=a;if(typeof window.xrCurrentSceneDefaults=="function")try{r=await window.xrCurrentSceneDefaults?.(a)}catch(h){console.error(h)}await new Promise((h,G)=>{setTimeout(()=>{h(null)},1e3)});let o=J(M(n),r),[s,l]=fe(o,t);l.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${l.join(", ")}`);let d={...s,type:t};await v.getInstance().updateSceneCreationConfig(d)})}function Xe(){wi(window),ge(window),Pi()}S();S();S();P();function y(i,e){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:e})}var w=class extends m{constructor(t){super(t);this.id=t;c.addEventReceiver(t,this.onReceiveEvent.bind(this))}async updateTransform(t){return new gt(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:n}=t;if(n==="objectdestroy")this.isDestroyed=!0;else if(n==="spatialtap"){let a=y("spatialtap",t.detail);this._onSpatialTap?.(a)}else if(n==="spatialdragstart"){let a=y("spatialdragstart",t.detail);this._onSpatialDragStart?.(a)}else if(n==="spatialdrag"){let a=y("spatialdrag",t.detail);this._onSpatialDrag?.(a)}else if(n==="spatialdragend"){let a=y("spatialdragend",t.detail);this._onSpatialDragEnd?.(a)}else if(n==="spatialrotate"){let a=y("spatialrotate",t.detail);this._onSpatialRotate?.(a)}else if(n==="spatialrotateend"){let a=y("spatialrotateend",t.detail);this._onSpatialRotateEnd?.(a)}else if(n==="spatialmagnify"){let a=y("spatialmagnify",t.detail);this._onSpatialMagnify?.(a)}else if(n==="spatialmagnifyend"){let a=y("spatialmagnifyend",t.detail);this._onSpatialMagnifyEnd?.(a)}}_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 A=class extends w{constructor(t,n){super(t);this.windowProxy=n;ge(n)}async updateProperties(t){return new yt(this,t).execute()}async addSpatializedElement(t){return new bt(this,t).execute()}};S();var I=class extends w{constructor(e,t,n){super(e),this.modelURL=t,this.sources=n}_readyResolve;modelURL;sources;_currentSrc="";get currentSrc(){return this._currentSrc}createReadyPromise(){return this._readyResolve?.(!1),new Promise(e=>{this._readyResolve=e})}ready=this.createReadyPromise();async updateProperties(e){let t=!1;if(e.modelURL!==void 0&&this.modelURL!==e.modelURL&&(this.modelURL=e.modelURL,t=!0),e.sources!==void 0){let n=JSON.stringify(this.sources),a=JSON.stringify(e.sources);n!==a&&(this.sources=e.sources,t=!0)}return t&&(this.ready=this.createReadyPromise()),e.autoplay!==void 0&&(this._autoplay=e.autoplay),e.loop!==void 0&&(this._loop=e.loop),e.playbackRate!==void 0&&(this._playbackRate=e.playbackRate),new ht(this,e).execute()}_duration=0;get duration(){return this._duration}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this.updateProperties({playbackRate:e})}_paused=!0;get paused(){return this._paused}_onAnimationStateChangeCallback;set onAnimationStateChangeCallback(e){this._onAnimationStateChangeCallback=e}async play(){this._paused=!1,await this.updateProperties({animationPaused:!1})}async pause(){this._paused=!0,await this.updateProperties({animationPaused:!0})}onReceiveEvent(e){e.type==="modelloaded"?(this._currentSrc=e.detail?.src??this.modelURL??"",this._onLoadCallback?.(),this._readyResolve?.(!0)):e.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):e.type==="animationstatechange"?(this._paused=e.detail.paused,this._duration=e.detail.duration,this._onAnimationStateChangeCallback?.(e.detail)):super.onReceiveEvent(e)}_autoplay=!1;get autoplay(){return this._autoplay}_loop=!1;get loop(){return this._loop}_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 W=class extends w{children=[];events={};constructor(e){super(e)}async addEntity(e){let t=new D(e.id,this.id).execute();return this.children.push(e),e.parent=this,t}addEvent(e,t){this.events[e]=t}removeEvent(e){this.events[e]&&delete this.events[e]}dispatchEvent(e){this.events[e.type]?.(e)}async updateProperties(e){return new St(this,e).execute()}};async function qe(){let i=await new Gt().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 A(e,t)}else throw new Error("createSpatialized2DElement failed")}async function Qe(i,e){let t=await new Et(i,e).execute();if(t.success){let{id:n}=t.data;return new I(n,i,e)}else throw new Error("createSpatializedStatic3DElement failed")}async function Ke(){let i=await new wt().execute();if(i.success){let{id:e}=i.data;return new W(e)}else throw new Error("createSpatializedDynamic3DElement failed")}S();var Ft=class extends m{constructor(t,n,a){super(t);this.windowProxy=n;this.options=a}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 $t(this.id,t).execute()}};async function he(i){let e=await new kt(i).execute();if(!e.success)throw new Error("createAttachmentEntity failed: "+e?.errorMessage);let{id:t,windowProxy:n}=e.data;return await new Bt(t,i).execute(),new Ft(t,n,i)}S();S();S();P();var T=class extends m{constructor(t,n){super(t);this.userData=n;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;_enableInput=!1;get enableInput(){return this._enableInput}set enableInput(t){this._enableInput!==t&&(this._enableInput=t,this.updateEntityEvent("spatialtap",t).catch(n=>{console.error("enableInput updateEntityEvent failed","spatialtap",n),this._enableInput===t&&(this._enableInput=!t)}))}async addComponent(t){return new Tt(this,t).execute()}async removeComponent(t){return new Ot(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 n=await new D(t.id,this.id).execute();return this.children.push(t),t.parent=this,n}async removeFromParent(){let t=await new D(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(n=>n.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 lt(this,t).execute()}async addEvent(t,n){if(this.events[t])this.events[t]=n;else try{await this.updateEntityEvent(t,!0),this.events[t]=n}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,n){return new pt(this,t,n).execute()}onReceiveEvent=t=>{let{type:n}=t;if(n==="objectdestroy")this.isDestroyed=!0;else if(n==="spatialtap"){let a=y("spatialtap",t.detail);this.dispatchEvent(a)}else if(n==="spatialdragstart"){let a=y("spatialdragstart",t.detail);this.dispatchEvent(a)}else if(n==="spatialdrag"){let a=y("spatialdrag",t.detail);this.dispatchEvent(a)}else if(n==="spatialdragend"){let a=y("spatialdragend",t.detail);this.dispatchEvent(a)}else if(n==="spatialrotate"){let a=y("spatialrotate",t.detail);this.dispatchEvent(a)}else if(n==="spatialrotateend"){let a=y("spatialrotateend",t.detail);this.dispatchEvent(a)}else if(n==="spatialmagnify"){let a=y("spatialmagnify",t.detail);this.dispatchEvent(a)}else if(n==="spatialmagnifyend"){let a=y("spatialmagnifyend",t.detail);this.dispatchEvent(a)}};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.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,n,a){return new At(t,n,a).execute()}async convertFromEntityToScene(t,n){return new It(t,n).execute()}async convertFromSceneToEntity(t,n){return new Wt(t,n).execute()}};S();var X=class extends T{constructor(t,n,a){super(t,a);this.id=t;this.options=n;this.userData=a}async setMaterials(t){return new zt(this.id,t).execute()}};P();var q=class extends m{constructor(e){super(e),c.addEventReceiver(e,this.onReceiveEvent)}onReceiveEvent=e=>{let{type:t}=e;t==="objectdestroy"&&(this.isDestroyed=!0)}};var Q=class extends q{constructor(t,n){super(t);this.options=n}};S();var K=class extends m{constructor(t,n){super(t);this.id=t;this.type=n;this.type=n}};var Z=class extends K{constructor(t,n){super(t,"unlit");this.id=t;this.options=n}updateProperties(t){return new ft(this,t).execute()}};var Y=class extends m{constructor(t,n){super(t);this.id=t;this.options=n}};async function Ze(i){let e=await new vt(i?.name).execute();if(e.success){let{id:t}=e.data;return new T(t,i)}else throw new Error("createSpatialEntity failed:"+e?.errorMessage)}async function _(i,e){let t=await new Ct(i.type,e).execute();if(t.success){let{id:n}=t.data;return new i(n,e)}else throw new Error("createSpatialGeometry failed:"+t?.errorMessage)}async function Ye(i){let e=await new Dt(i).execute();if(e.success){let{id:t}=e.data;return new Z(t,i)}else throw new Error("createSpatialUnlitMaterial failed:"+e?.errorMessage)}async function ti(i){let e=await new Pt(i).execute();if(e.success){let{id:t}=e.data;return new Q(t,i)}else throw new Error("createModelComponent failed:"+e?.errorMessage)}async function ei(i,e){let t=await new Mt(i).execute();if(t.success){let{id:n}=t.data;return new X(n,i,e)}else throw new Error("createSpatialModelEntity failed:"+t?.errorMessage)}async function ii(i){let e=await new Rt(i).execute();if(e.success){let{id:t}=e.data;return new Y(t,i)}else throw new Error("createModelAsset failed:"+e?.errorMessage)}var g=class extends m{constructor(t,n){super(t);this.id=t;this.options=n}static type};var tt=class extends g{constructor(t,n){super(t,n);this.id=t;this.options=n}static type="BoxGeometry"};var et=class extends g{constructor(t,n){super(t,n);this.id=t;this.options=n}static type="SphereGeometry"};var it=class extends g{constructor(t,n){super(t,n);this.id=t;this.options=n}static type="CylinderGeometry"};var nt=class extends g{constructor(t,n){super(t,n);this.id=t;this.options=n}static type="PlaneGeometry"};var at=class extends g{constructor(t,n){super(t,n);this.id=t;this.options=n}static type="ConeGeometry"};var V=class{getSpatialScene(){return v.getInstance()}createSpatialized2DElement(){return qe()}createSpatializedStatic3DElement(e,t){return Qe(e,t)}initScene=He;createSpatializedDynamic3DElement(){return Ke()}createEntity(e){return Ze(e)}createBoxGeometry(e={}){return _(tt,e)}createPlaneGeometry(e={}){return _(nt,e)}createSphereGeometry(e={}){return _(et,e)}createConeGeometry(e){return _(at,e)}createCylinderGeometry(e){return _(it,e)}createModelComponent(e){return ti(e)}createUnlitMaterial(e){return Ye(e)}createModelAsset(e){return ii(e)}createSpatialModelEntity(e,t){return ei(e,t)}createAttachmentEntity(e){return he(e)}};P();var U=class{wsAppShellVersionFromUA;requestSession(){return this.runInSpatialWeb()?(c.init(),new V):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 e=navigator.userAgent.match(/WSAppShell\/(\d+(?:\.\d+){2}(?:[-+][0-9A-Za-z.-]+)*)/);return this.wsAppShellVersionFromUA=e?e[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.6.0"}};Qt();st();var ni=new U,Ht,jt={backgroundMaterial:"--xr-background-material"},ai="";function Jt(i){i!==ai&&(Ht?.getSpatialScene()?.updateSpatialProperties({material:i}),ai=i)}function Mi(){let e=getComputedStyle(document.documentElement).getPropertyValue(jt.backgroundMaterial);Jt(e||"none")}var C={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function ri(){let i=getComputedStyle(document.documentElement),e=ze(i);Ri(e)}function Ri(i){(C.topLeading!==i.topLeading||C.bottomLeading!==i.bottomLeading||C.topTrailing!==i.topTrailing||C.bottomTrailing!==i.bottomTrailing)&&(Ht?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),C.topLeading=i.topLeading,C.bottomLeading=i.bottomLeading,C.topTrailing=i.topTrailing,C.bottomTrailing=i.bottomTrailing)}function Ci(i){Ht?.getSpatialScene().updateSpatialProperties({opacity:i})}function oi(){let i=getComputedStyle(document.documentElement),e=parseFloat(i.getPropertyValue("opacity"));Ci(e)}function Di(){let i=document.documentElement.style,e=new Proxy(i,{set:function(t,n,a){let r=Reflect.set(t,n,a);return n===jt.backgroundMaterial&&Jt(a),(n==="border-radius"||n==="borderRadius"||n==="border-top-left-radius"||n==="borderTopLeftRadius"||n==="border-top-right-radius"||n==="borderTopRightRadius"||n==="border-bottom-left-radius"||n==="borderBottomLeftRadius"||n==="border-bottom-right-radius"||n==="borderBottomRightRadius")&&ri(),n==="opacity"&&oi(),r},get:function(t,n){return typeof t[n]=="function"?function(...a){if(n==="setProperty"){let[r,o]=a;r===jt.backgroundMaterial&&Jt(o)}else if(n==="removeProperty"){let[r]=a;r===jt.backgroundMaterial&&Jt("none")}return t[n](...a)}:Reflect.get(t,n)}});Object.defineProperty(document.documentElement,"style",{get:function(){return e}})}function Ti(){new MutationObserver(Nt).observe(document.head,{childList:!0,subtree:!0})}function Nt(){Mi(),ri(),oi()}function Oi(){new MutationObserver(e=>{e.forEach(t=>{t.type==="attributes"&&t.attributeName&&Nt()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function si(){ni.runInSpatialWeb()&&(Ht=await ni.requestSession(),document.readyState==="complete"?Nt():window.addEventListener("load",()=>{Nt()}),Di(),Ti(),Oi())}!B()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(Xe(),si());return k(zi);})();
75
75
  //# sourceMappingURL=index.global.js.map