@webspatial/core-sdk 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/iife/index.d.ts +386 -236
  3. package/dist/iife/index.global.js +7 -7
  4. package/dist/iife/index.global.js.map +1 -1
  5. package/dist/index.d.ts +386 -236
  6. package/dist/index.js +1479 -1226
  7. package/dist/index.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/JSBCommand.ts +30 -100
  10. package/src/Spatial.ts +0 -21
  11. package/src/SpatialScene.ts +1 -5
  12. package/src/SpatialSession.ts +17 -3
  13. package/src/SpatializedDynamic3DElement.ts +0 -1
  14. package/src/SpatializedElementCreator.ts +6 -4
  15. package/src/SpatializedStatic3DElement.test.ts +99 -0
  16. package/src/SpatializedStatic3DElement.ts +99 -1
  17. package/src/WebMsgCommand.ts +10 -0
  18. package/src/coverage-boost.test.ts +38 -119
  19. package/src/index.ts +3 -1
  20. package/src/jsbcommand.coverage.test.ts +19 -48
  21. package/src/platform-adapter/CommandResultUtils.ts +2 -2
  22. package/src/platform-adapter/createPlatformSync.ts +34 -0
  23. package/src/platform-adapter/index.ts +5 -51
  24. package/src/platform-adapter/interface.ts +35 -23
  25. package/src/platform-adapter/pico-os/PicoOSPlatform.ts +84 -52
  26. package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +37 -11
  27. package/src/platform-adapter/spatialSceneQuery.ts +17 -0
  28. package/src/platform-adapter/ssr/SSRPlatform.ts +24 -15
  29. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +55 -24
  30. package/src/platform-runtime.ts +13 -0
  31. package/src/reality/Attachment.ts +2 -2
  32. package/src/reality/entity/SpatialEntity.ts +0 -2
  33. package/src/reality/realityCreator.ts +15 -1
  34. package/src/reality/resource/SpatialTextureResource.ts +16 -0
  35. package/src/reality/resource/index.ts +1 -0
  36. package/src/runtime/WebSpatialRuntimeError.ts +16 -0
  37. package/src/runtime/capability-data.ts +113 -0
  38. package/src/runtime/contract-review.test.ts +44 -0
  39. package/src/runtime/index.ts +28 -0
  40. package/src/runtime/jsbAdapterPlatform.test.ts +36 -0
  41. package/src/runtime/jsbAdapterPlatform.ts +51 -0
  42. package/src/runtime/keys.ts +129 -0
  43. package/src/runtime/semver.ts +33 -0
  44. package/src/runtime/supports.test.ts +207 -0
  45. package/src/runtime/supports.ts +110 -0
  46. package/src/runtime/types.ts +11 -0
  47. package/src/runtime/userAgent.ts +64 -0
  48. package/src/scene-polyfill.manifest.test.ts +7 -5
  49. package/src/scene-polyfill.test.ts +60 -0
  50. package/src/scene-polyfill.ts +23 -22
  51. package/src/spatial-host.ts +25 -0
  52. package/src/types/{global.d.ts → global.ts} +10 -5
  53. package/src/types/types.ts +9 -0
  54. package/src/platform-adapter/android/AndroidPlatform.ts +0 -133
@@ -2,10 +2,10 @@
2
2
  (function(){
3
3
  if(typeof window === 'undefined') return;
4
4
  if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
5
- window.__webspatialsdk__['core-sdk-version'] = "1.6.0"
5
+ window.__webspatialsdk__['core-sdk-version'] = "1.7.0"
6
6
  })()
7
7
 
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=`
8
+ "use strict";var webspatialCore=(()=>{var te=Object.defineProperty;var xi=Object.getOwnPropertyDescriptor;var wi=Object.getOwnPropertyNames;var vi=Object.prototype.hasOwnProperty;var Te=(i,t)=>{for(var e in t)te(i,e,{get:t[e],enumerable:!0})},Pi=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of wi(t))!vi.call(i,r)&&r!==e&&te(i,r,{get:()=>t[r],enumerable:!(n=xi(t,r))||n.enumerable});return i};var Ri=i=>Pi(te({},"__esModule",{value:!0}),i);var rn={};Te(rn,{Attachment:()=>Ht,BaseplateVisibilityValues:()=>Le,CAPABILITY_TABLE:()=>Xt,COMPONENT_KEYS:()=>he,CSS_KEYS:()=>be,CubeInfo:()=>ae,DOM_DEPTH_KEYS:()=>Pe,ELEMENT_DOM_DEPTH_KEYS:()=>we,GESTURE_KEYS:()=>Ee,JS_SCENE_KEYS:()=>xe,ModelComponent:()=>J,PhysicalMetrics:()=>fe,SUB_TOKENS_BY_NAME:()=>nt,Spatial:()=>L,SpatialBoxGeometry:()=>Q,SpatialComponent:()=>j,SpatialConeGeometry:()=>et,SpatialCylinderGeometry:()=>Z,SpatialEntity:()=>M,SpatialGeometry:()=>f,SpatialMaterial:()=>H,SpatialModelAsset:()=>X,SpatialModelEntity:()=>$,SpatialObject:()=>c,SpatialPlaneGeometry:()=>tt,SpatialScene:()=>x,SpatialSceneState:()=>ce,SpatialSceneValues:()=>Ne,SpatialSession:()=>V,SpatialSphereGeometry:()=>q,SpatialTextureResource:()=>Y,SpatialUnlitMaterial:()=>K,Spatialized2DElement:()=>A,SpatializedDynamic3DElement:()=>z,SpatializedElement:()=>h,SpatializedElementType:()=>Ve,SpatializedStatic3DElement:()=>I,TOP_LEVEL_KEYS:()=>it,VISIONOS_DEBUG_SHELL_VERSION_PLACEHOLDER:()=>Re,WINDOW_DOM_DEPTH_KEYS:()=>ve,WebSpatialRuntimeError:()=>Kt,WorldAlignmentValues:()=>Ge,WorldScalingValues:()=>Ue,compareSemver:()=>U,computeRuntimeFromUserAgent:()=>C,createAttachmentEntity:()=>ge,getRuntime:()=>Me,isSSREnv:()=>N,isValidBaseplateVisibilityType:()=>oe,isValidSceneUnit:()=>_,isValidSpatialSceneType:()=>le,isValidWorldAlignmentType:()=>pe,isValidWorldScalingType:()=>se,parseSemverOrNull:()=>rt,parseShellToken:()=>at,resetRuntimeCacheForTests:()=>fi,resolveJsbAdapterPlatform:()=>ot,supports:()=>yi});function at(i){let t=/\bWSAppShell\/([\w.-]+)/i.exec(i);if(t?.[1])return{version:t[1],source:"wsapp"};let e=/\bPicoWebApp\/([\w.-]+)/i.exec(i);return e?.[1]?{version:e[1],source:"picoapp"}:{version:null,source:null}}function Mi(i){return/\bPicoWebApp\//i.test(i)||/\bPicoBrowser\b/i.test(i)}function Ti(i){return/Mac OS X/i.test(i)}function C(i){if(i===void 0||i==="")return{type:null,shellVersion:null};if(i.includes("Puppeteer")){let{version:n}=at(i);return{type:"puppeteer",shellVersion:n}}let{version:t,source:e}=at(i);return t?e==="picoapp"||Mi(i)?{type:"picoos",shellVersion:t}:e==="wsapp"?Ti(i)?{type:"visionos",shellVersion:t}:{type:null,shellVersion:t}:{type:null,shellVersion:t}:{type:null,shellVersion:null}}function Oi(i){let t=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function Ci(i,t){if(!i)return!1;for(let e=0;e<3;e+=1){let n=i[e]-t[e];if(n>0)return!0;if(n<0)return!1}return!1}function ot(i){if(C(i).type==="puppeteer")return"puppeteer";let e=Oi(i);return i.includes("PicoWebApp")&&Ci(e,[0,0,1])?"picoos":"visionos"}var Di=typeof window>"u",N=()=>Di;function m(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function S(i,t=""){return{success:!1,data:void 0,errorCode:i,errorMessage:t}}function D(i,t){let e={url:i,config:t};return Object.keys(e).map(n=>{let r=e[n],a=typeof r=="object"?JSON.stringify(r):r;return`${n}=${encodeURIComponent(a)}`}).join("&")}var l=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 ee=0,_i=1e5,Oe="E_PICO_JSB",Ai="Pico JSB execution failed";function Ce(){return ee=(ee+1)%_i,`rId_${ee}`}var st=class{async callJSB(t,e){return new Promise(n=>{try{let r=Ce();l.addEventReceiver(r,o=>{l.removeEventReceiver(r),n(this.toCommandResult(o))});let a=window.webspatialBridge.postMessage(r,t,e);a!==""&&(l.removeEventReceiver(r),n(this.parseBridgeResponse(a)))}catch(r){console.error(`SwanPlatform cmd: ${t}, msg: ${e} error: ${r}`);let{code:a,message:o}=this.parseJSBError(r);n(S(a,o))}})}openSpatialSceneSync(t,e,n,r){let a=D(t,e),{spatialId:o="",windowProxy:s}=this.openWindow("createSpatialScene",a,n,r);return m({windowProxy:s,id:o})}createNativeSpatialDiv(){return this.waitForRidProtocolAsync("createSpatialized2DElement")}createNativeAttachment(t){return this.waitForRidProtocolAsync("createAttachment")}waitForRidProtocolAsync(t){return new Promise(e=>{let n=Ce();try{let r=null;l.addEventReceiver(n,a=>{e(m({windowProxy:r,id:a.spatialId})),l.removeEventReceiver(n)}),r=this.openWindow(t,"rid="+n).windowProxy}catch(r){let{code:a,message:o}=this.parseJSBError(r);l.removeEventReceiver(n),e(S(a,o))}})}openWindow(t,e,n,r){let a=e?`webspatial://${t}?${e}`:`webspatial://${t}`;return{spatialId:"",windowProxy:window.open(a,n,r)}}parseBridgeResponse(t){try{let e=JSON.parse(t);return this.toCommandResult(e)}catch{return S(Oe,"Invalid Pico JSB response payload")}}toCommandResult(t){if(t.success)return m(t.data);let{code:e,message:n}=this.parseJSBError(t.data);return S(e,n)}parseJSBError(t){return{code:t?.code??Oe,message:t?.message??(typeof t=="string"?t:Ai)}}};var pt=class{iframeRegistry=new Map;constructor(){}callJSB(t,e){return new Promise(n=>{try{if(window.__handleJSBMessage)try{console.log(` core-sdk Puppeteer Platform: callJSB: ${t}::${e}`);let r=window.__handleJSBMessage(`${t}::${e}`);console.log(` core-sdk Puppeteer Platform callJSB result: ${r}`),n(m(r))}catch{n(S("500","JSB execution error"))}else n(m("ok"))}catch(r){console.error(`PuppeteerPlatform cmd Error: ${t}, msg: ${e} error: ${r}`),n(S("500","Internal error"))}})}createSpatializedElementSync(t,e){try{console.log(`[Puppeteer Platform] Creating spatialized element sync with id: ${t}, url: ${e}`);let n=window;if(n.__handleJSBMessage){let r={id:t,url:e};n.__handleJSBMessage(`CreateSpatialized2DElement::${JSON.stringify(r)}`)}}catch(n){console.error("Error creating spatialized element sync:",n)}}openSpatialSceneSync(t,e,n,r){let a=D(t,e);return this.runProtocolSync("createSpatialScene",a,n,r)}createNativeSpatialDiv(){return this.runProtocolAsync("createSpatialized2DElement","",void 0,void 0)}createNativeAttachment(t){return this.runProtocolAsync("createAttachment","",void 0,void 0)}runProtocolAsync(t,e,n,r){return console.log(`PuppeteerPlatform: Calling webspatial protocol: webspatial://${t}${e?`?${e}`:""}`),new Promise(a=>{try{let o=`webspatial://${t}${e?`?${e}`:""}`,{spatialId:s,iframe:d,windowProxy:b}=this.createIframeWindow(o,n,r);t==="createSpatialized2DElement"&&this.createSpatializedElementSync(s,o),console.log(`[Puppeteer Platform] iframe created with spatialId: ${s}`),this.iframeRegistry.set(s,d),a(m({windowProxy:b,id:s}))}catch(o){console.error("Error calling webspatial protocol:",o),a(S("500","Failed to call webspatial protocol"))}})}runProtocolSync(t,e,n,r){try{let a=`webspatial://${t}${e?`?${e}`:""}`;console.log(`Calling webspatial protocol sync: ${a}`);let{spatialId:o,iframe:s,windowProxy:d}=this.createIframeWindow(a,n,r);return t==="createSpatialized2DElement"&&this.createSpatializedElementSync(o,a),this.iframeRegistry.set(o,s),m({windowProxy:d,id:o})}catch(a){return console.error("Error calling webspatial protocol sync:",a),S("500","Failed to call webspatial protocol sync")}}createIframeWindow(t,e,n){let r=document.createElement("iframe");r.style.border="none",r.style.display="none",r.style.width="100%",r.style.height="100%";let a=this.generateUUID();r.spatialId=a,r.id=`spatial-iframe-${a}`;let o=this.parseFeatures(n||"");o.width&&(r.style.width=o.width),o.height&&(r.style.height=o.height),o.left&&(r.style.left=o.left,r.style.position="absolute"),o.top&&(r.style.top=o.top,r.style.position="absolute"),document.body.appendChild(r);let s=this.createEnhancedWindowProxy(r,t,a);return r.src="about:blank",console.log(`PuppeteerPlatform created iframe window with spatialId: ${a}, URL: ${t}`),this.initializeIframeContent(r,t,a),{spatialId:a,iframe:r,windowProxy:s}}createEnhancedWindowProxy(t,e,n){return{location:{href:e,toString:()=>e,reload:()=>{t.contentWindow&&t.contentWindow.location.reload()}},navigator:{userAgent:`Mozilla/5.0 (WebKit) SpatialId/${n}`},close:()=>{console.log(`Closing iframe with spatialId: ${n}`),t.remove(),this.iframeRegistry.delete(n)},document:t.contentDocument||{},contentWindow:t.contentWindow||{},postMessage:(r,a)=>{t.contentWindow&&t.contentWindow.postMessage(r,a||"*")},addEventListener:(r,a)=>{t.contentWindow&&t.contentWindow.addEventListener(r,a)},removeEventListener:(r,a)=>{t.contentWindow&&t.contentWindow.removeEventListener(r,a)},executeScript:r=>{if(t.contentWindow)try{return t.contentWindow.eval(r)}catch(a){return console.error(`Error executing script in iframe ${n}:`,a),null}return null},getIframe:()=>t,getSpatialId:()=>n}}initializeIframeContent(t,e,n){try{t.onload=()=>{try{let r=`
9
9
  // inject communication script
10
10
  window.webSpatialId = '${n}';
11
11
  window.SpatialId = '${n}';
@@ -38,7 +38,7 @@
38
38
  window.parent.postMessage({
39
39
  type: 'iframe_loaded',
40
40
  spatialId: '${n}',
41
- url: '${t}'
41
+ url: '${e}'
42
42
  }, '${window.location.origin}');
43
43
 
44
44
  // set message handler
@@ -52,7 +52,7 @@
52
52
  // add command handling logic here
53
53
  }
54
54
  });
55
- `,r=e.contentDocument;r&&(r.open(),r.write(`
55
+ `,a=t.contentDocument;a&&(a.open(),a.write(`
56
56
  <!DOCTYPE html>
57
57
  <html>
58
58
  <head>
@@ -67,9 +67,9 @@
67
67
  </style>
68
68
  </head>
69
69
  <body>
70
- <script>${a}</script>
70
+ <script>${r}</script>
71
71
  </body>
72
72
  </html>
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);})();
73
+ `),a.close())}catch(r){console.error("Error initializing iframe content:",r)}}}catch(r){console.error("Error setting up iframe:",r)}}parseFeatures(t){let e={};return t.split(",").forEach(r=>{let[a,o]=r.split("=").map(s=>s.trim());a&&o&&(e[a]=o)}),e}sendMessageToIframe(t,e){let n=this.iframeRegistry.get(t);return n&&n.contentWindow?(n.contentWindow.postMessage(e,window.location.origin),!0):!1}getAllActiveIframes(){let t=[];return this.iframeRegistry.forEach((e,n)=>{t.push({spatialId:n,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 lt=class{callJSB(t,e){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}openSpatialSceneSync(t,e,n,r){return{success:!0,data:void 0,errorCode:void 0,errorMessage:void 0}}createNativeSpatialDiv(){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}createNativeAttachment(t){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}};var Ii=/\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi,ct=class{async callJSB(t,e){try{let n=await window.webkit.messageHandlers.bridge.postMessage(`${t}::${e}`);return m(n)}catch(n){let{code:r,message:a}=this.parseJSBError(n);return S(r,a)}}openSpatialSceneSync(t,e,n,r){let a=D(t,e),{spatialId:o="",windowProxy:s}=this.openWindow("createSpatialScene",a,n,r);return m({windowProxy:s,id:o})}createNativeSpatialDiv(){return this.openProtocolAsync("createSpatialized2DElement")}createNativeAttachment(t){return this.openProtocolAsync("createAttachment")}async openProtocolAsync(t){let{spatialId:e="",windowProxy:n}=this.openWindow(t,"",void 0,void 0);return m({windowProxy:n,id:e})}openWindow(t,e,n,r){let a=window.open(`webspatial://${t}?${e||""}`,n,r);return{spatialId:a?.navigator.userAgent?.match(Ii)?.[0],windowProxy:a}}parseJSBError(t){try{let e=JSON.parse(t.message??"");return{code:e.code??"E_VISIONOS_JSB",message:e.message??"VisionOS JSB execution failed"}}catch{return{code:"E_VISIONOS_JSB",message:t?.message??"VisionOS JSB execution failed"}}}};function zi(i){throw new Error("Unhandled jsb adapter platform kind")}function ie(){if(N())return new lt;let i=window.navigator.userAgent,t=ot(i);switch(t){case"puppeteer":return new pt;case"picoos":return new st;case"visionos":return new ct;default:return zi(t)}}var De;function ne(){return De??=ie(),De}async function B(){return ne()}function dt(i,t){return i===""?0:i.endsWith("%")?t*parseFloat(i)/100:parseFloat(i)}function _e(i){let t=parseFloat(i.getPropertyValue("width")),e=i.getPropertyValue("border-top-left-radius"),n=i.getPropertyValue("border-top-right-radius"),r=i.getPropertyValue("border-bottom-left-radius"),a=i.getPropertyValue("border-bottom-right-radius");return{topLeading:dt(e,t),bottomLeading:dt(r,t),topTrailing:dt(n,t),bottomTrailing:dt(a,t)}}function Ae(i,t,e){let{x:n,y:r,z:a}=i,{x:o,y:s,z:d}=t,{x:b,y:w,z:O}=e,y=new DOMMatrix;return y=y.translate(n,r,a),y=y.rotate(o,s,d),y=y.scale(b,w,O),y}function v(i){let t=globalThis.structuredClone;if(typeof t=="function")try{return t(i)}catch{}return JSON.parse(JSON.stringify(i))}var p=class{commandType="";async execute(){let t=this.getParams(),e=t?JSON.stringify(t):"";return(await B()).callJSB(this.commandType,e)}},ut=class extends p{constructor(e,n){super();this.entity=e;this.properties=n}commandType="UpdateEntityProperties";getParams(){let e=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:e}}},mt=class extends p{constructor(e,n,r){super();this.entity=e;this.type=n;this.isEnable=r}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}};var ft=class extends p{properties;commandType="UpdateSpatialSceneProperties";constructor(t){super(),this.properties=t}getParams(){return this.properties}},yt=class extends p{config;commandType="UpdateSceneConfig";constructor(t){super(),this.config=t}getParams(){return{config:this.config}}},St=class extends p{constructor(e){super();this.id=e}commandType="FocusScene";getParams(){return{id:this.id}}},gt=class extends p{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},E=class extends p{constructor(e){super();this.spatialObject=e}getParams(){let e=this.getExtraParams();return{id:this.spatialObject.id,...e}}},ht=class extends E{properties;commandType="UpdateSpatialized2DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},bt=class extends E{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},Et=class extends E{properties;commandType="UpdateUnlitMaterialProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},xt=class extends E{matrix;commandType="UpdateSpatializedElementTransform";constructor(t,e){super(t),this.matrix=e}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},wt=class extends E{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},vt=class extends E{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(t,e){super(t),this.spatializedElement=e}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},Pt=class extends p{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(t){super(),this.spatializedElement=t}getParams(){return{spatializedElementId:this.spatializedElement.id}}},Rt=class extends p{constructor(e,n,r="eager"){super();this.modelURL=e;this.sources=n;this.loading=r;this.modelURL=e,this.sources=n,this.loading=r}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL,sources:this.sources,loading:this.loading}}},Mt=class extends p{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},Tt=class extends p{constructor(e){super();this.name=e}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},Ot=class extends p{constructor(e){super();this.options=e}getParams(){let e=this.options.mesh.id,n=this.options.materials.map(r=>r.id);return{geometryId:e,materialIds:n}}commandType="CreateModelComponent"},Ct=class extends p{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateSpatialModelEntity"},Dt=class extends p{constructor(e){super();this.options=e}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},_t=class extends p{constructor(e,n={}){super();this.type=e;this.options=n}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},At=class extends p{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateUnlitMaterial"},It=class extends p{constructor(e,n){super();this.entity=e;this.comp=n}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},zt=class extends p{constructor(e,n){super();this.entity=e;this.comp=n}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="RemoveComponentFromEntity"},Wt=class extends p{constructor(e,n){super();this.entityId=e;this.materials=n}getParams(){return{entityId:this.entityId,materialIds:this.materials.map(e=>e.id)}}commandType="SetMaterialsOnEntity"};var R=class extends p{constructor(e,n){super();this.childId=e;this.parentId=n}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},Vt=class extends p{constructor(e,n,r){super();this.fromEntityId=e;this.toEntityId=n;this.fromPosition=r}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},Lt=class extends p{constructor(e,n){super();this.fromEntityId=e;this.position=n}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},Ut=class extends p{constructor(e,n){super();this.entityId=e;this.position=n}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},Gt=class extends p{constructor(e,n,r){super();this.position=e;this.fromId=n;this.toId=r}getParams(){return{position:this.position,fromId:this.fromId,toId:this.toId}}commandType="ConvertCoordinate"},Nt=class extends p{constructor(e){super();this.url=e}getParams(){return{url:this.url}}commandType="CreateTexture"},Bt=class extends E{properties;commandType="UpdateTextureProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},kt=class extends p{constructor(e=""){super();this.id=e}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Ft=class extends p{constructor(e){super();this.id=e}commandType="Destroy";getParams(){return{id:this.id}}};var $t=class extends p{constructor(e,n){super();this.attachmentId=e;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}}},jt=class extends p{constructor(e,n){super();this.attachmentId=e;this.options=n}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}};var c=class{constructor(t){this.id=t}name;isDestroyed=!1;async inspect(){let t=await new kt(this.id).execute();if(t.success)return t.data;throw new Error(t.errorMessage)}async destroy(){if(this.isDestroyed)return;let t=await new Ft(this.id).execute();if(t.success)return this.onDestroy(),this.isDestroyed=!0,t.data;if(this.isDestroyed)return;throw new Error(t.errorMessage)}onDestroy(){}};async function Ie(){return(await B()).createNativeSpatialDiv()}async function ze(i){return(await B()).createNativeAttachment(i)}function We(i,t,e,n){return ne().openSpatialSceneSync(i,t,e,n)}var re,x=class i extends c{static getInstance(){return re||(re=new i("")),re}async convertCoordinate(t,e,n){try{return(await new Gt(t,e,n).execute())?.data??t}catch(r){throw console.warn("SpatialScene.convertCoordinate error:",r),r}}async updateSpatialProperties(t){return new ft(t).execute()}async addSpatializedElement(t){return new Pt(t).execute()}async updateSceneCreationConfig(t){return new yt(t).execute()}async getState(){return(await new gt().execute()).data.name}};var Ve=(n=>(n[n.Spatialized2DElement=0]="Spatialized2DElement",n[n.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",n[n.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",n))(Ve||{}),Le=["automatic","visible","hidden"];function oe(i){return Le.includes(i)}var Ue=["automatic","dynamic"];function se(i){return Ue.includes(i)}var Ge=["adaptive","automatic","gravityAligned"];function pe(i){return Ge.includes(i)}var Ne=["window","volume"];function le(i){return Ne.includes(i)}function _(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 ce=(a=>(a.idle="idle",a.pending="pending",a.willVisible="willVisible",a.visible="visible",a.fail="fail",a))(ce||{}),ae=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 fe={};Te(fe,{getValue:()=>Wi,physicalToPoint:()=>ue,pointToPhysical:()=>de,subscribe:()=>Vi});var g={meterToPtUnscaled:1360,meterToPtScaled:1360};function Be(i){return i?.worldScalingCompensation??"scaled"}function de(i,t){return me(),Be(t)==="unscaled"?i/g.meterToPtUnscaled:i/g.meterToPtScaled}function ue(i,t){return me(),Be(t)==="unscaled"?i*g.meterToPtUnscaled:i*g.meterToPtScaled}function me(){if(typeof window>"u")return;let i=window.__webspatialsdk__?.physicalMetrics;if(!i)return;let t={meterToPtScaled:i.meterToPtScaled??g.meterToPtScaled,meterToPtUnscaled:i.meterToPtUnscaled??g.meterToPtUnscaled};(t.meterToPtScaled!==g.meterToPtScaled||t.meterToPtUnscaled!==g.meterToPtUnscaled)&&(g=t)}function Wi(){return me(),g}function Vi(i){if(typeof window>"u")return()=>{};let t=()=>{i()};return l.addEventReceiver("window",t),()=>{l.removeEventReceiver("window")}}var Je={defaultSize:{width:1280,height:720}},He={defaultSize:{width:"0.94m",height:"0.94m",depth:"0.94m"}},Ke={...Je},Xe={...He},Li="webspatial://";function k(i,t){if(!t)return{...i||{}};let e={...i||{}};for(let n of Object.keys(t)){let r=e[n],a=t[n];a&&typeof a=="object"&&!Array.isArray(a)&&r&&typeof r=="object"&&!Array.isArray(r)?e[n]=k(r,a):e[n]=a}return e}function ke(i){let t={...i||{}},e=i.defaultSize!==void 0?i.defaultSize:i.default_size;return e!==void 0&&(t.defaultSize=e),"default_size"in t&&delete t.default_size,t}var F=class i{originalOpen;static instance;manifestReady=null;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(t){this.manifestReady=this.setupManifest(),this.originalOpen=t.open.bind(t),t.open=this.open}configMap={};callbackReturnMap={};getConfig(t){if(!(t===void 0||!this.configMap[t]))return this.configMap[t]}waitManifest(){return this.manifestReady??Promise.resolve()}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}}async setupManifest(){let t=await this.getPWAManifest();try{let e=t?.xr_spatial_scene;if(!e||typeof e!="object")return;let{overrides:n,...r}=e,a=k(r,n?.window_scene),o=k(r,n?.volume_scene),s=ke(a),d=ke(o);s&&Object.keys(s).length>0&&(Ke=s),d&&Object.keys(d).length>0&&(Xe=d)}catch(e){console.warn("SceneManager.setupManifest failed; using built-in defaults.",e?.message||e)}}open=(t,e,n)=>{if(t?.startsWith(Li)){if(t.includes("createSpatialized2DElement")||t.includes("createAttachment")){let s=(window.webSpatial||window.__webspatialShell__)?.genToken?.();if(s){let d=t.includes("createAttachment")?"createAttachment":"createSpatialized2DElement",b=window.location.host,O=`${window.location.protocol}//${b}/${s}/?command=${d}`,y=new URL(t).searchParams.get("rid"),G=new URL(O);return y&&G.searchParams.set("rid",y),this.originalOpen(G.toString(),e,n)}}return this.originalOpen(t,e,n)}if(t=this.ensureAbsoluteUrl(t),e==="_self"||e==="_parent"||e==="_top")return this.originalOpen(t,e,n);let r=e?this.getConfig(e):void 0;if(r===void 0){let s=v(Jt("window")),[d]=ye(s,"window");r={...d,type:"window"}}let a=We(t,r,e,n),o=a.data?.id;return o&&new St(o).execute(),a.data?.windowProxy};initScene(t,e,n){let r=n?.type??"window",a=Jt(r),o=this.callbackReturnMap[t]??v(a),s=e(o),d=Ui(v(s)),b=v(d),w=v(Jt(r)),O=k(w,b),[y,G]=ye(O,r);G.length>0&&console.warn(`initScene ${t} with errors: ${G.join(", ")}`),this.callbackReturnMap[t]=d,this.configMap[t]={...y,type:r}}async getPWAManifest(t){let e=t;if(!e){let n=document.querySelector('link[rel="manifest"]');e=n?.getAttribute("href")||n?.href}if(e&&(e=this.ensureAbsoluteUrl(e),!!e)){if(e.startsWith("data:"))try{let n=e.indexOf(",");if(n<0)return;let r=e.slice(5,n),a=e.slice(n+1),s=/;base64/i.test(r)?atob(a):decodeURIComponent(a);return JSON.parse(s)}catch{return}try{let n=await fetch(e,{credentials:"same-origin"});if(!n.ok)throw new Error(String(n.status));try{return await n.json()}catch{let r=await n.text();return JSON.parse(r)}}catch{try{let n=await fetch(e);if(!n.ok)return;try{return await n.json()}catch{let r=await n.text();return JSON.parse(r)}}catch{return}}}}};function Ui(i){if(i?.defaultSize){let t=["width","height","depth"];for(let e of t)e in i.defaultSize&&!_(i.defaultSize[e])&&delete i.defaultSize[e]}if(i?.resizability){let t=["minWidth","minHeight","maxWidth","maxHeight"];for(let e of t)e in i.resizability&&!_(i.resizability[e])&&delete i.resizability[e]}return i}function Fe(i){return de(i)}function $e(i){return ue(i)}function je(i,t,e){if(typeof i=="number")return e==="px"&&t==="px"||e==="m"&&t==="m"?i:e==="px"&&t==="m"?Fe(i):e==="m"&&t==="px"?$e(i):i;if(t==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return Fe(Number(i.slice(0,-2)));throw new Error("formatToNumber: invalid str")}else if(t==="px"){if(i.endsWith("px"))return Number(i.slice(0,-2));if(i.endsWith("m"))return $e(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function ye(i,t){let e=[],n=t==="window";if(le(t)||e.push("sceneType"),i.defaultSize){let r=["width","height","depth"];for(let a of r)a in i.defaultSize&&(_(i.defaultSize[a])?i.defaultSize[a]=je(i.defaultSize[a],n?"px":"m","px"):(delete i.defaultSize[a],e.push(`defaultSize.${a}`)))}if(i.resizability){let r=["minWidth","minHeight","maxWidth","maxHeight"];for(let a of r)a in i.resizability&&(_(i.resizability[a])?i.resizability[a]=je(i.resizability[a],"px","px"):(delete i.resizability[a],e.push(`resizability.${a}`)))}return i.worldScaling&&(se(i.worldScaling)||(i.worldScaling="automatic",e.push("worldScaling"))),i.worldAlignment&&(pe(i.worldAlignment)||(i.worldAlignment="automatic",e.push("worldAlignment"))),i.baseplateVisibility&&(oe(i.baseplateVisibility)||(i.baseplateVisibility="automatic",e.push("baseplateVisibility"))),[i,e]}function Ye(i,t,e){return F.getInstance().initScene(i,t,e)}function Gi(i){F.getInstance().init(i)}function Se(i){i.document.onclick=function(t){let e=t.target;for(;e;){if(e.tagName=="A")return!Ni(t,e);if(e.parentElement)e=e.parentElement;else break}}}function Ni(i,t){if(i.defaultPrevented)return!1;let e=t.target,n=t.href;if(e&&e!=="_self")return i.preventDefault(),window.open(n,e),!0}function Jt(i){return i==="window"?Ke||Je:Xe||He}async function Bi(){if(!window.opener||await x.getInstance().getState()!=="pending")return;function t(e){document.readyState==="interactive"||document.readyState==="complete"?e():document.addEventListener("DOMContentLoaded",e)}t(async()=>{await F.getInstance().waitManifest();let e=window.xrCurrentSceneType??"window",n=Jt(e),r=v(n),a=r;if(typeof window.xrCurrentSceneDefaults=="function")try{a=await window.xrCurrentSceneDefaults?.(r)}catch(w){console.error(w)}await new Promise((w,O)=>{setTimeout(()=>{w(null)},1e3)});let o=k(v(n),a),[s,d]=ye(o,e);d.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${d.join(", ")}`);let b={...s,type:e};await x.getInstance().updateSceneCreationConfig(b)})}function Qe(){Gi(window),Se(window),Bi()}function u(i,t){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:t})}var h=class extends c{constructor(e){super(e);this.id=e;l.addEventReceiver(e,this.onReceiveEvent.bind(this))}async updateTransform(e){return new xt(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:n}=e;if(n==="objectdestroy")this.isDestroyed=!0;else if(n==="spatialtap"){let r=u("spatialtap",e.detail);this._onSpatialTap?.(r)}else if(n==="spatialdragstart"){let r=u("spatialdragstart",e.detail);this._onSpatialDragStart?.(r)}else if(n==="spatialdrag"){let r=u("spatialdrag",e.detail);this._onSpatialDrag?.(r)}else if(n==="spatialdragend"){let r=u("spatialdragend",e.detail);this._onSpatialDragEnd?.(r)}else if(n==="spatialrotate"){let r=u("spatialrotate",e.detail);this._onSpatialRotate?.(r)}else if(n==="spatialrotateend"){let r=u("spatialrotateend",e.detail);this._onSpatialRotateEnd?.(r)}else if(n==="spatialmagnify"){let r=u("spatialmagnify",e.detail);this._onSpatialMagnify?.(r)}else if(n==="spatialmagnifyend"){let r=u("spatialmagnifyend",e.detail);this._onSpatialMagnifyEnd?.(r)}}_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(){l.removeEventReceiver(this.id)}};var A=class extends h{constructor(e,n){super(e);this.windowProxy=n;Se(n)}async updateProperties(e){return new ht(this,e).execute()}async addSpatializedElement(e){return new vt(this,e).execute()}};var I=class extends h{constructor(t,e,n,r="eager"){super(t),this.modelURL=e,this.sources=n,this._loading=r}_readyResolve;modelURL;get modelUrl(){return this.modelURL}sources;_currentSrc="";get currentSrc(){return this._currentSrc}createReadyPromise(){return this._readyResolve?.(!1),new Promise(t=>{this._readyResolve=t})}ready=this.createReadyPromise();async updateProperties(t){let e=!1;if(t.modelURL!==void 0&&this.modelURL!==t.modelURL&&(this.modelURL=t.modelURL,e=!0),t.sources!==void 0){let n=JSON.stringify(this.sources),r=JSON.stringify(t.sources);n!==r&&(this.sources=t.sources,e=!0)}return e&&(this.ready=this.createReadyPromise()),t.autoplay!==void 0&&(this._autoplay=t.autoplay),t.loop!==void 0&&(this._loop=t.loop),t.playbackRate!==void 0&&(this._paused||(this._currentTime=this.currentTime,this._anchorTimestamp=Date.now()),this._playbackRate=t.playbackRate),t.currentTime!==void 0&&(this._currentTime=t.currentTime,this._anchorTimestamp=Date.now()),t.loading!==void 0&&(this._loading=t.loading),new wt(this,t).execute()}_duration=0;get duration(){return this._duration}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(t){this.updateProperties({playbackRate:t})}_currentTime=0;_anchorTimestamp=0;clampTime(t){return!Number.isFinite(t)||t<0?0:t>this._duration?this.loop&&this.duration>0?t%this._duration:this.duration:t}get currentTime(){if(this._paused)return this._currentTime;let t=(Date.now()-this._anchorTimestamp)/1e3;return this.clampTime(this._currentTime+t*this._playbackRate)}set currentTime(t){let e=Number.isNaN(t)?0:ki(t,0,this.duration);this.updateProperties({currentTime:e})}_paused=!0;get paused(){return this._paused}_onAnimationStateChangeCallback;set onAnimationStateChangeCallback(t){this._onAnimationStateChangeCallback=t}async play(){this._paused&&(this._anchorTimestamp=Date.now()),this._paused=!1,await this.updateProperties({animationPaused:!1})}async pause(){this._paused||(this._currentTime=this.currentTime,this._anchorTimestamp=Date.now()),this._paused=!0,await this.updateProperties({animationPaused:!0})}onReceiveEvent(t){t.type==="modelloaded"?(this._currentSrc=t.detail?.src??this.modelURL??"",this._onLoadCallback?.(),this._readyResolve?.(!0)):t.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):t.type==="animationstatechange"?(this._paused=t.detail.paused,this._duration=t.detail.duration,this._currentTime=t.detail.currentTime??0,this._anchorTimestamp=t.detail.timestamp??Date.now(),this._onAnimationStateChangeCallback?.(t.detail)):super.onReceiveEvent(t)}_autoplay=!1;get autoplay(){return this._autoplay}_loading="eager";get loading(){return this._loading}_loop=!1;get loop(){return this._loop}_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})}};function ki(i,t,e){return i<=t?t:i>=e?e:i}var z=class extends h{children=[];events={};constructor(t){super(t)}async addEntity(t){let e=new R(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 bt(this,t).execute()}};async function qe(){let i=await Ie();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 A(t,e)}else throw new Error("createSpatialized2DElement failed")}async function Ze(i,t,e="eager"){let n=await new Rt(i,t,e).execute();if(n.success){let{id:r}=n.data;return new I(r,i,t,e)}else throw new Error("createSpatializedStatic3DElement failed")}async function ti(){let i=await new Mt().execute();if(i.success){let{id:t}=i.data;return new z(t)}else throw new Error("createSpatializedDynamic3DElement failed")}var Ht=class extends c{constructor(e,n,r){super(e);this.windowProxy=n;this.options=r}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 jt(this.id,e).execute()}};async function ge(i){let t=await ze(i);if(!t.success)throw new Error("createAttachmentEntity failed: "+t?.errorMessage);let{id:e,windowProxy:n}=t.data;return await new $t(e,i).execute(),new Ht(e,n,i)}var M=class extends c{constructor(e,n){super(e);this.userData=n;l.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(n=>{console.error("enableInput updateEntityEvent failed","spatialtap",n),this._enableInput===e&&(this._enableInput=!e)}))}async addComponent(e){return new It(this,e).execute()}async removeComponent(e){return new zt(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 n=await new R(e.id,this.id).execute();return this.children.push(e),e.parent=this,n}async removeFromParent(){let e=await new R(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(n=>n.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 ut(this,e).execute()}async addEvent(e,n){if(this.events[e])this.events[e]=n;else try{await this.updateEntityEvent(e,!0),this.events[e]=n}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,n){return new mt(this,e,n).execute()}onReceiveEvent=e=>{let{type:n}=e;if(n==="objectdestroy")this.isDestroyed=!0;else if(n==="spatialtap"){let r=u("spatialtap",e.detail);this.dispatchEvent(r)}else if(n==="spatialdragstart"){let r=u("spatialdragstart",e.detail);this.dispatchEvent(r)}else if(n==="spatialdrag"){let r=u("spatialdrag",e.detail);this.dispatchEvent(r)}else if(n==="spatialdragend"){let r=u("spatialdragend",e.detail);this.dispatchEvent(r)}else if(n==="spatialrotate"){let r=u("spatialrotate",e.detail);this.dispatchEvent(r)}else if(n==="spatialrotateend"){let r=u("spatialrotateend",e.detail);this.dispatchEvent(r)}else if(n==="spatialmagnify"){let r=u("spatialmagnify",e.detail);this.dispatchEvent(r)}else if(n==="spatialmagnifyend"){let r=u("spatialmagnifyend",e.detail);this.dispatchEvent(r)}};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(){l.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,n,r){return new Vt(e,n,r).execute()}async convertFromEntityToScene(e,n){return new Lt(e,n).execute()}async convertFromSceneToEntity(e,n){return new Ut(e,n).execute()}};var $=class extends M{constructor(e,n,r){super(e,r);this.id=e;this.options=n;this.userData=r}async setMaterials(e){return new Wt(this.id,e).execute()}};var j=class extends c{constructor(t){super(t),l.addEventReceiver(t,this.onReceiveEvent)}onReceiveEvent=t=>{let{type:e}=t;e==="objectdestroy"&&(this.isDestroyed=!0)}};var J=class extends j{constructor(e,n){super(e);this.options=n}};var H=class extends c{constructor(e,n){super(e);this.id=e;this.type=n;this.type=n}};var K=class extends H{constructor(e,n){super(e,"unlit");this.id=e;this.options=n}updateProperties(e){return new Et(this,e).execute()}};var X=class extends c{constructor(e,n){super(e);this.id=e;this.options=n}};var Y=class extends c{constructor(e,n){super(e);this.id=e;this.options=n}updateProperties(e){return new Bt(this,e).execute()}};async function ei(i){let t=await new Tt(i?.name).execute();if(t.success){let{id:e}=t.data;return new M(e,i)}else throw new Error("createSpatialEntity failed:"+t?.errorMessage)}async function W(i,t){let e=await new _t(i.type,t).execute();if(e.success){let{id:n}=e.data;return new i(n,t)}else throw new Error("createSpatialGeometry failed:"+e?.errorMessage)}async function ii(i){let t=await new At(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 ni(i){let t=await new Ot(i).execute();if(t.success){let{id:e}=t.data;return new J(e,i)}else throw new Error("createModelComponent failed:"+t?.errorMessage)}async function ri(i,t){let e=await new Ct(i).execute();if(e.success){let{id:n}=e.data;return new $(n,i,t)}else throw new Error("createSpatialModelEntity failed:"+e?.errorMessage)}async function ai(i){let t=await new Dt(i).execute();if(t.success){let{id:e}=t.data;return new X(e,i)}else throw new Error("createModelAsset failed:"+t?.errorMessage)}async function oi(i){let t=await new Nt(i.url).execute();if(t.success){let{id:e}=t.data;return new Y(e,i)}else throw new Error("createSpatialTexture failed:"+t?.errorMessage)}var f=class extends c{constructor(e,n){super(e);this.id=e;this.options=n}static type};var Q=class extends f{constructor(e,n){super(e,n);this.id=e;this.options=n}static type="BoxGeometry"};var q=class extends f{constructor(e,n){super(e,n);this.id=e;this.options=n}static type="SphereGeometry"};var Z=class extends f{constructor(e,n){super(e,n);this.id=e;this.options=n}static type="CylinderGeometry"};var tt=class extends f{constructor(e,n){super(e,n);this.id=e;this.options=n}static type="PlaneGeometry"};var et=class extends f{constructor(e,n){super(e,n);this.id=e;this.options=n}static type="ConeGeometry"};var V=class{getSpatialScene(){return x.getInstance()}createSpatialized2DElement(){return qe()}createSpatializedStatic3DElement(t,e,n="eager"){return Ze(t,e,n)}initScene=Ye;createSpatializedDynamic3DElement(){return ti()}createEntity(t){return ei(t)}createBoxGeometry(t={}){return W(Q,t)}createPlaneGeometry(t={}){return W(tt,t)}createSphereGeometry(t={}){return W(q,t)}createConeGeometry(t){return W(et,t)}createCylinderGeometry(t){return W(Z,t)}createModelComponent(t){return ni(t)}createUnlitMaterial(t){return ii(t)}createTexture(t){return oi(t)}createModelAsset(t){return ai(t)}createSpatialModelEntity(t,e){return ri(t,e)}createAttachmentEntity(t){return ge(t)}};var L=class{requestSession(){return this.runInSpatialWeb()?(l.init(),new V):null}runInSpatialWeb(){return navigator.userAgent.indexOf("WebSpatial/")>=0}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.7.0"}};var Kt=class extends Error{capability;constructor(t,e){super(e??`Capability "${t}" is not supported in this WebSpatial runtime`),this.name="WebSpatialRuntimeError",this.capability=t}};var he=["Model","Reality","Entity","BoxEntity","SphereEntity","ConeEntity","CylinderEntity","PlaneEntity","SceneGraph","ModelAsset","ModelEntity","UnlitMaterial","Material","AttachmentAsset","AttachmentEntity"],be=["-xr-background-material","-xr-back","-xr-depth","-xr-transform"],Ee=["SpatialTapEvent","SpatialDragStartEvent","SpatialDragEvent","SpatialDragEndEvent","SpatialRotateEvent","SpatialRotateEndEvent","SpatialMagnifyEvent","SpatialMagnifyEndEvent"],xe=["useMetrics","convertCoordinate","initScene","WindowScene","VolumeScene"],we=["xrClientDepth","xrOffsetBack"],ve=["xrInnerDepth","xrOuterDepth"],Pe=[...we,...ve],it=[...he,...be,...Ee,...xe,...Pe],Fi={Box:"BoxEntity",Sphere:"SphereEntity",Cone:"ConeEntity",Cylinder:"CylinderEntity",Plane:"PlaneEntity",World:"SceneGraph"};function si(i){return Fi[i]??i}var nt={Material:["unlit"],WindowScene:["defaultSize","resizability"],VolumeScene:["defaultSize","resizability","worldScaling","worldAlignment","baseplateVisibility"],SpatialRotateEvent:["constrainedToAxis"],Model:["autoplay","loop","stagemode","poster","loading","source","ready","currentSrc","entityTransform","paused","duration","playbackRate","play","pause","currentTime"]};function pi(i){return it.includes(i)}function li(i,t){let e=nt[i];return e!==void 0&&e.includes(t)}function ci(){let i={};for(let t of it)i[t]=!0;for(let[t,e]of Object.entries(nt))for(let n of e)i[`${t}:${n}`]=!0;return i}function di(){let i=ci(),t=["autoplay","loop","stagemode","poster","loading","source","paused","duration","playbackRate","play","pause","currentTime"];for(let e of t)i[`Model:${e}`]=!1;return i["SpatialRotateEvent:constrainedToAxis"]=!0,i}function ui(){let i=ci();for(let t of["stagemode","poster","loading","currentTime"])i[`Model:${t}`]=!1;return i["SpatialRotateEvent:constrainedToAxis"]=!0,i}function $i(){let i=di();return i.xrInnerDepth=!1,i.xrOuterDepth=!1,i}function ji(){let i=ui();return i.xrInnerDepth=!1,i.xrOuterDepth=!1,i}function Ji(){return{version:"1.5.0",flags:di()}}function Hi(){return{version:"1.6.0",flags:ui()}}function Ki(){return{version:"0.1.1",flags:$i()}}function Xi(){return{version:"0.1.2",flags:ji()}}var Xt={visionos:[Ji(),Hi()],picoos:[Ki(),Xi()]};function U(i,t){let e=mi(i),n=mi(t);if(!e||!n)return String(i).localeCompare(String(t));let r=Math.max(e.length,n.length);for(let a=0;a<r;a++){let o=e[a]??0,s=n[a]??0;if(o!==s)return o-s}return 0}function mi(i){let t=/^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/.exec(i.trim());if(!t)return null;let e=Number(t[1]),n=t[2]!==void 0?Number(t[2]):0,r=t[3]!==void 0?Number(t[3]):0;return[e,n,r].some(a=>Number.isNaN(a))?null:[e,n,r]}function rt(i){let t=/^(\d+(?:\.\d+){0,2})/.exec(i.trim());return t?t[1]:null}var Re="WS_SHELL_VERSION",T;function fi(){T=void 0}function Me(){return T!==void 0?T:typeof navigator>"u"?(T={type:null,shellVersion:null},T):(T=C(navigator.userAgent),T)}function Yi(i,t){let e=rt(t);if(!e)return null;let n=Xt[i];if(!n.length)return null;let r=[...n].sort((s,d)=>U(s.version,d.version)),a=r[0].version;if(U(e,a)<0)return null;let o=null;for(let s of r)if(U(s.version,e)<=0)o=s;else break;return o}function yi(i,t){if(typeof i!="string")return!1;let e=si(i);if(!pi(e))return!1;let n=t===void 0?[]:Array.isArray(t)?[...t]:[];if(n.some(s=>typeof s!="string"))return!1;for(let s of n)if(!li(e,s))return!1;let r=Me();if(r.type==="puppeteer")return!0;if(r.type===null||r.shellVersion===null)return!1;if(r.type==="visionos"&&r.shellVersion===Re)return!0;let a=rt(r.shellVersion);if(!a||r.type!=="visionos"&&r.type!=="picoos")return!1;let o=Yi(r.type,a);return o?n.length===0?o.flags[e]===!0:o.flags[e]!==!0?!1:n.every(s=>o.flags[`${e}:${s}`]===!0):!1}var Si=new L,Zt,Yt={backgroundMaterial:"--xr-background-material"},gi="";function Qt(i){i!==gi&&(Zt?.getSpatialScene()?.updateSpatialProperties({material:i}),gi=i)}function Qi(){let t=getComputedStyle(document.documentElement).getPropertyValue(Yt.backgroundMaterial);Qt(t||"none")}var P={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function hi(){let i=getComputedStyle(document.documentElement),t=_e(i);qi(t)}function qi(i){(P.topLeading!==i.topLeading||P.bottomLeading!==i.bottomLeading||P.topTrailing!==i.topTrailing||P.bottomTrailing!==i.bottomTrailing)&&(Zt?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),P.topLeading=i.topLeading,P.bottomLeading=i.bottomLeading,P.topTrailing=i.topTrailing,P.bottomTrailing=i.bottomTrailing)}function Zi(i){Zt?.getSpatialScene().updateSpatialProperties({opacity:i})}function bi(){let i=getComputedStyle(document.documentElement),t=parseFloat(i.getPropertyValue("opacity"));Zi(t)}function tn(){let i=document.documentElement.style,t=new Proxy(i,{set:function(e,n,r){let a=Reflect.set(e,n,r);return n===Yt.backgroundMaterial&&Qt(r),(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")&&hi(),n==="opacity"&&bi(),a},get:function(e,n){return typeof e[n]=="function"?function(...r){if(n==="setProperty"){let[a,o]=r;a===Yt.backgroundMaterial&&Qt(o)}else if(n==="removeProperty"){let[a]=r;a===Yt.backgroundMaterial&&Qt("none")}return e[n](...r)}:Reflect.get(e,n)}});Object.defineProperty(document.documentElement,"style",{get:function(){return t}})}function en(){new MutationObserver(qt).observe(document.head,{childList:!0,subtree:!0})}function qt(){Qi(),hi(),bi()}function nn(){new MutationObserver(t=>{t.forEach(e=>{e.type==="attributes"&&e.attributeName&&qt()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function Ei(){Si.runInSpatialWeb()&&(Zt=await Si.requestSession(),document.readyState==="complete"?qt():window.addEventListener("load",()=>{qt()}),tn(),en(),nn())}!N()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(Qe(),Ei());return Ri(rn);})();
75
75
  //# sourceMappingURL=index.global.js.map