@webspatial/core-sdk 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/dist/iife/index.d.ts +7 -0
- package/dist/iife/index.global.js +4 -4
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +62 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +33 -0
- package/src/platform-adapter/index.ts +2 -2
- package/src/platform-adapter/{xr/XRPlatform.ts → pico-os/PicoOSPlatform.ts} +5 -7
- package/src/reality/entity/SpatialEntity.ts +4 -0
- package/src/reality/entity/SpatialModelEntity.ts +6 -0
- package/src/scene-polyfill.ts +12 -0
- package/src/types/global.d.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @webspatial/core-sdk
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3b304a1: Introduces runtime reactivity to our 3D API. Previously, entities were mostly static after instantiation. We can now dynamically update material properties, modify geometry in-place, and apply material overrides to model entities on the fly.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- c7b240c: Project Swan renamed to Pico OS
|
|
12
|
+
|
|
3
13
|
## 1.4.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -217,4 +227,4 @@
|
|
|
217
227
|
|
|
218
228
|
### Patch Changes
|
|
219
229
|
|
|
220
|
-
- 456d15f: change ModelDragEvent to SpatialModelDragEvent in coresdk
|
|
230
|
+
- 456d15f: change ModelDragEvent to SpatialModelDragEvent in coresdk
|
package/dist/iife/index.d.ts
CHANGED
|
@@ -455,6 +455,7 @@ declare class SpatialEntity extends SpatialObject {
|
|
|
455
455
|
set enableInput(value: boolean);
|
|
456
456
|
constructor(id: string, userData?: SpatialEntityUserData | undefined);
|
|
457
457
|
addComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
458
|
+
removeComponent(component: SpatialComponent): Promise<CommandResult>;
|
|
458
459
|
setPosition(position: Vec3): Promise<CommandResult>;
|
|
459
460
|
setRotation(rotation: Vec3): Promise<CommandResult>;
|
|
460
461
|
setScale(scale: Vec3): Promise<CommandResult>;
|
|
@@ -477,6 +478,7 @@ declare class SpatialModelEntity extends SpatialEntity {
|
|
|
477
478
|
options?: SpatialModelEntityCreationOptions | undefined;
|
|
478
479
|
userData?: SpatialEntityUserData | undefined;
|
|
479
480
|
constructor(id: string, options?: SpatialModelEntityCreationOptions | undefined, userData?: SpatialEntityUserData | undefined);
|
|
481
|
+
setMaterials(materials: SpatialMaterial[]): Promise<CommandResult>;
|
|
480
482
|
}
|
|
481
483
|
|
|
482
484
|
declare class ModelComponent extends SpatialComponent {
|
|
@@ -916,6 +918,11 @@ declare global {
|
|
|
916
918
|
webkit: any
|
|
917
919
|
webspatialBridge: any
|
|
918
920
|
|
|
921
|
+
// Project Pico OS browser injects this global object to provide internal capabilities.
|
|
922
|
+
webSpatial?: {
|
|
923
|
+
genToken?: () => string
|
|
924
|
+
}
|
|
925
|
+
|
|
919
926
|
// Will be removed in favor of __WebSpatialData
|
|
920
927
|
WebSpatailNativeVersion: string
|
|
921
928
|
|
|
@@ -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.
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.5.0"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
|
-
"use strict";var webspatialCore=(()=>{var
|
|
8
|
+
"use strict";var webspatialCore=(()=>{var jt=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var ti=Object.prototype.hasOwnProperty;var h=(i,t)=>()=>(i&&(t=i(i=0)),t);var R=(i,t)=>{for(var e in t)jt(i,e,{get:t[e],enumerable:!0})},ei=(i,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ye(t))!ti.call(i,n)&&n!==e&&jt(i,n,{get:()=>t[n],enumerable:!(r=Ze(t,n))||r.enumerable});return i};var V=i=>ei(jt({},"__esModule",{value:!0}),i);var ii,G,kt=h(()=>{"use strict";ii=typeof window>"u",G=()=>ii});var Z,ue=h(()=>{"use strict";Z=class{callJSB(t,e){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocol(t,e,r,n){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocolSync(t,e,r,n,a){return{success:!0,data:void 0,errorCode:void 0,errorMessage:void 0}}}});function m(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function g(i,t=""){return{success:!1,data:void 0,errorCode:i,errorMessage:t}}var _=h(()=>{"use strict"});var ye={};R(ye,{PuppeteerPlatform:()=>Jt});var Jt,Se=h(()=>{"use strict";_();console.log("PuppeteerPlatform");Jt=class{iframeRegistry=new Map;constructor(){}callJSB(t,e){return new Promise(r=>{try{if(window.__handleJSBMessage)try{console.log(` core-sdk Puppeteer Platform: callJSB: ${t}::${e}`);let n=window.__handleJSBMessage(`${t}::${e}`);console.log(` core-sdk Puppeteer Platform callJSB result: ${n}`),r(m(n))}catch{r(g("500","JSB execution error"))}else r(m("ok"))}catch(n){console.error(`PuppeteerPlatform cmd Error: ${t}, msg: ${e} error: ${n}`),r(g("500","Internal error"))}})}createSpatializedElementSync(t,e){try{console.log(`[Puppeteer Platform] Creating spatialized element sync with id: ${t}, url: ${e}`);let r=window;if(r.__handleJSBMessage){let n={id:t,url:e};r.__handleJSBMessage(`CreateSpatialized2DElement::${JSON.stringify(n)}`)}}catch(r){console.error("Error creating spatialized element sync:",r)}}callWebSpatialProtocol(t,e,r,n){return console.log(`PuppeteerPlatform: Calling webspatial protocol: webspatial://${t}${e?`?${e}`:""}`),new Promise(a=>{try{let o=`webspatial://${t}${e?`?${e}`:""}`,{spatialId:s,iframe:p,windowProxy:y}=this.createIframeWindow(o,r,n);t==="createSpatialized2DElement"&&this.createSpatializedElementSync(s,o),console.log(`[Puppeteer Platform] iframe created with spatialId: ${s}`),this.iframeRegistry.set(s,p),a(m({windowProxy:y,id:s}))}catch(o){console.error("Error calling webspatial protocol:",o),a(g("500","Failed to call webspatial protocol"))}})}callWebSpatialProtocolSync(t,e,r,n){try{let a=`webspatial://${t}${e?`?${e}`:""}`;console.log(`Calling webspatial protocol sync: ${a}`);let{spatialId:o,iframe:s,windowProxy:p}=this.createIframeWindow(a,r,n);return t==="createSpatialized2DElement"&&this.createSpatializedElementSync(o,a),this.iframeRegistry.set(o,s),m({windowProxy:p,id:o})}catch(a){return console.error("Error calling webspatial protocol sync:",a),g("500","Failed to call webspatial protocol sync")}}createIframeWindow(t,e,r){let n=document.createElement("iframe");n.style.border="none",n.style.display="none",n.style.width="100%",n.style.height="100%";let a=this.generateUUID();n.spatialId=a,n.id=`spatial-iframe-${a}`;let o=this.parseFeatures(r||"");o.width&&(n.style.width=o.width),o.height&&(n.style.height=o.height),o.left&&(n.style.left=o.left,n.style.position="absolute"),o.top&&(n.style.top=o.top,n.style.position="absolute"),document.body.appendChild(n);let s=this.createEnhancedWindowProxy(n,t,a);return n.src="about:blank",console.log(`PuppeteerPlatform created iframe window with spatialId: ${a}, URL: ${t}`),this.initializeIframeContent(n,t,a),{spatialId:a,iframe:n,windowProxy:s}}createEnhancedWindowProxy(t,e,r){return{location:{href:e,toString:()=>e,reload:()=>{t.contentWindow&&t.contentWindow.location.reload()}},navigator:{userAgent:`Mozilla/5.0 (WebKit) SpatialId/${r}`},close:()=>{console.log(`Closing iframe with spatialId: ${r}`),t.remove(),this.iframeRegistry.delete(r)},document:t.contentDocument||{},contentWindow:t.contentWindow||{},postMessage:(n,a)=>{t.contentWindow&&t.contentWindow.postMessage(n,a||"*")},addEventListener:(n,a)=>{t.contentWindow&&t.contentWindow.addEventListener(n,a)},removeEventListener:(n,a)=>{t.contentWindow&&t.contentWindow.removeEventListener(n,a)},executeScript:n=>{if(t.contentWindow)try{return t.contentWindow.eval(n)}catch(a){return console.error(`Error executing script in iframe ${r}:`,a),null}return null},getIframe:()=>t,getSpatialId:()=>r}}initializeIframeContent(t,e,r){try{t.onload=()=>{try{let n=`
|
|
9
9
|
// inject communication script
|
|
10
10
|
window.webSpatialId = '${r}';
|
|
11
11
|
window.SpatialId = '${r}';
|
|
@@ -70,6 +70,6 @@
|
|
|
70
70
|
<script>${n}</script>
|
|
71
71
|
</body>
|
|
72
72
|
</html>
|
|
73
|
-
`),a.close())}catch(n){console.error("Error initializing iframe content:",n)}}}catch(n){console.error("Error setting up iframe:",n)}}parseFeatures(t){let e={};return t.split(",").forEach(n=>{let[a,o]=n.split("=").map(s=>s.trim());a&&o&&(e[a]=o)}),e}sendMessageToIframe(t,e){let r=this.iframeRegistry.get(t);return r&&r.contentWindow?(r.contentWindow.postMessage(e,window.location.origin),!0):!1}getAllActiveIframes(){let t=[];return this.iframeRegistry.forEach((e,r)=>{t.push({spatialId:r,iframe:e})}),t}dispose(){this.iframeRegistry.forEach((t,e)=>{console.log(`Disposing iframe with spatialId: ${e}`),t.remove()}),this.iframeRegistry.clear()}generateUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16).toUpperCase()})}}});var c,w=h(()=>{"use strict";c=class i{static eventReceiver={};static init(){window.__SpatialWebEvent=({id:t,data:e})=>{i.eventReceiver[t]?.(e)}}static addEventReceiver(t,e){i.eventReceiver[t]=e}static removeEventReceiver(t){delete i.eventReceiver[t]}}});var ue={};R(ue,{XRPlatform:()=>kt});function me(){return jt=(jt+1)%ti,`rId_${jt}`}var jt,ti,kt,ye=h(()=>{"use strict";_();w();jt=0,ti=1e5;kt=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=me();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}});let o=window.webspatialBridge.postMessage(a,t,e);if(o!==""){c.removeEventReceiver(a);let s=JSON.parse(o);if(s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}}}catch(a){console.error(`XRPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(S(o,s))}})}async callWebSpatialProtocol(t,e,r,n){return new Promise((a,o)=>{let s=me();try{let p=null;c.addEventReceiver(s,y=>{console.log("createdId",s,y.spatialId),a(m({windowProxy:p,id:y.spatialId})),c.removeEventReceiver(s)}),p=this.openWindow(t,e,r,n).windowProxy,p?.open(`about:blank?rid=${s}`,"_self")}catch(p){console.error(`open window error: ${p}`);let{code:y,message:Lt}=p;c.removeEventReceiver(s),a(S(y,Lt))}})}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${t}?${e||""}`,r,n)}}}});var Se={};R(Se,{AndroidPlatform:()=>Ht});function ii(){return Nt=(Nt+1)%ei,`rId_${Nt}`}var Jt,Nt,ei,Ht,ge=h(()=>{"use strict";_();g();w();Jt=0,Nt=0,ei=1e5;Ht=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=ii();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}});let o=window.webspatialBridge.postMessage(a,t,e);if(o!==""){c.removeEventReceiver(a);let s=JSON.parse(o);if(s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(S(p,y))}}}catch(a){console.error(`AndroidPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(S(o,s))}})}async callWebSpatialProtocol(t,e,r,n){await new Promise(p=>setTimeout(p,16*Jt)),Jt++;let a=await new U().execute();for(;!a.data.can;)await new Promise(p=>setTimeout(p,16)),a=await new U().execute();let{windowProxy:o}=this.openWindow(t,e,r,n);for(;!o?.open;)await new Promise(p=>setTimeout(p,16));for(o?.open("about:blank","_self");!o?.__SpatialId;)await new Promise(p=>setTimeout(p,16));let s=o?.__SpatialId;return Jt--,Promise.resolve(m({windowProxy:o,id:s}))}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${t}?${e||""}`,r,n)}}}});var fe={};R(fe,{VisionOSPlatform:()=>qt});var qt,he=h(()=>{"use strict";_();qt=class{async callJSB(t,e){try{let r=await window.webkit.messageHandlers.bridge.postMessage(`${t}::${e}`);return m(r)}catch(r){let{code:n,message:a}=JSON.parse(r.message);return S(n,a)}}callWebSpatialProtocol(t,e,r,n){let{spatialId:a,windowProxy:o}=this.openWindow(t,e,r,n);return Promise.resolve(m({windowProxy:o,id:a}))}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){let a=window.open(`webspatial://${t}?${e||""}`,r,n);return{spatialId:a?.navigator.userAgent?.match(/\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi)?.[0],windowProxy:a}}}});function ri(i){let t=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function ni(i,t){if(!i)return!1;for(let e=0;e<3;e+=1){let r=i[e]-t[e];if(r>0)return!0;if(r<0)return!1}return!1}function Ee(){if(G())return new K;let i=window.navigator.userAgent,t=ri(i);if(window.navigator.userAgent.includes("Puppeteer")){let e=(de(),V(ce)).PuppeteerPlatform;return new e}else if(i.includes("PicoWebApp")&&ni(t,[0,0,1])){let e=(ye(),V(ue)).XRPlatform;return new e}else if(i.includes("Android")||i.includes("Linux")){let e=(ge(),V(Se)).AndroidPlatform;return new e}else{let e=(he(),V(fe)).VisionOSPlatform;return new e}}var be=h(()=>{"use strict";$t();le()});function Z(i,t){return i===""?0:i.endsWith("%")?t*parseFloat(i)/100:parseFloat(i)}function xe(i){let t=parseFloat(i.getPropertyValue("width")),e=i.getPropertyValue("border-top-left-radius"),r=i.getPropertyValue("border-top-right-radius"),n=i.getPropertyValue("border-bottom-left-radius"),a=i.getPropertyValue("border-bottom-right-radius");return{topLeading:Z(e,t),bottomLeading:Z(n,t),topTrailing:Z(r,t),bottomTrailing:Z(a,t)}}function we(i,t,e){let{x:r,y:n,z:a}=i,{x:o,y:s,z:p}=t,{x:y,y:Lt,z:qe}=e,M=new DOMMatrix;return M=M.translate(r,n,a),M=M.rotate(o,s,p),M=M.scale(y,Lt,qe),M}var Xt=h(()=>{"use strict"});var Qt,l,Y,tt,et,it,rt,nt,v,at,ot,st,pt,lt,ct,dt,mt,ut,yt,St,gt,ft,ht,Et,bt,D,xt,wt,vt,Pt,Mt,Dt,U,L,Tt,Rt,Ct,Ot,It,g=h(()=>{"use strict";be();Xt();Qt=Ee(),l=class{commandType="";async execute(){let t=this.getParams(),e=t?JSON.stringify(t):"";return Qt.callJSB(this.commandType,e)}},Y=class extends l{constructor(e,r){super();this.entity=e;this.properties=r}commandType="UpdateEntityProperties";getParams(){let e=we(this.properties.position??this.entity.position,this.properties.rotation??this.entity.rotation,this.properties.scale??this.entity.scale).toFloat64Array();return{entityId:this.entity.id,transform:e}}},tt=class extends l{constructor(e,r,n){super();this.entity=e;this.type=r;this.isEnable=n}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}},et=class extends l{properties;commandType="UpdateSpatialSceneProperties";constructor(t){super(),this.properties=t}getParams(){return this.properties}},it=class extends l{config;commandType="UpdateSceneConfig";constructor(t){super(),this.config=t}getParams(){return{config:this.config}}},rt=class extends l{constructor(e){super();this.id=e}commandType="FocusScene";getParams(){return{id:this.id}}},nt=class extends l{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},v=class extends l{constructor(e){super();this.spatialObject=e}getParams(){let e=this.getExtraParams();return{id:this.spatialObject.id,...e}}},at=class extends v{properties;commandType="UpdateSpatialized2DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},ot=class extends v{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},st=class extends v{properties;commandType="UpdateUnlitMaterialProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},pt=class extends v{matrix;commandType="UpdateSpatializedElementTransform";constructor(t,e){super(t),this.matrix=e}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},lt=class extends v{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},ct=class extends v{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(t,e){super(t),this.spatializedElement=e}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},dt=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(t){super(),this.spatializedElement=t}getParams(){return{spatializedElementId:this.spatializedElement.id}}},mt=class extends l{constructor(e){super();this.modelURL=e;this.modelURL=e}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},ut=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},yt=class extends l{constructor(e){super();this.name=e}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},St=class extends l{constructor(e){super();this.options=e}getParams(){let e=this.options.mesh.id,r=this.options.materials.map(n=>n.id);return{geometryId:e,materialIds:r}}commandType="CreateModelComponent"},gt=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ft=class extends l{constructor(e){super();this.options=e}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},ht=class extends l{constructor(e,r={}){super();this.type=e;this.options=r}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},Et=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateUnlitMaterial"},bt=class extends l{constructor(e,r){super();this.entity=e;this.comp=r}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},D=class extends l{constructor(e,r){super();this.childId=e;this.parentId=r}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},xt=class extends l{constructor(e,r,n){super();this.fromEntityId=e;this.toEntityId=r;this.fromPosition=n}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},wt=class extends l{constructor(e,r){super();this.fromEntityId=e;this.position=r}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},vt=class extends l{constructor(e,r){super();this.entityId=e;this.position=r}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},Pt=class extends l{constructor(e,r,n){super();this.position=e;this.fromId=r;this.toId=n}getParams(){return{position:this.position,fromId:this.fromId,toId:this.toId}}commandType="ConvertCoordinate"},Mt=class extends l{constructor(e=""){super();this.id=e}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Dt=class extends l{constructor(e){super();this.id=e}commandType="Destroy";getParams(){return{id:this.id}}},U=class extends l{constructor(e=""){super();this.id=e}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},L=class extends l{target;features;async execute(){let t=this.getQuery();return Qt.callWebSpatialProtocol(this.commandType,t,this.target,this.features)}executeSync(){let t=this.getQuery();return Qt.callWebSpatialProtocolSync(this.commandType,t,this.target,this.features)}getQuery(){let t,e=this.getParams();return e&&(t=Object.keys(e).map(r=>{let n=e[r],a=typeof n=="object"?JSON.stringify(n):n;return`${r}=${encodeURIComponent(a)}`}).join("&")),t}},Tt=class extends L{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Rt=class extends L{constructor(e,r,n,a){super();this.url=e;this.config=r;this.target=n;this.features=a}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}},Ct=class extends L{constructor(e){super();this.options=e}commandType="createAttachment";getParams(){return{}}},Ot=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="InitializeAttachment";getParams(){return{id:this.attachmentId,parentEntityId:this.options.parentEntityId,position:this.options.position??[0,0,0],size:this.options.size,ownerViewId:this.options.ownerViewId}}},It=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}}});var xi={};R(xi,{Attachment:()=>At,BaseplateVisibilityValues:()=>Pe,CubeInfo:()=>Zt,ModelComponent:()=>F,PhysicalMetrics:()=>pe,Spatial:()=>A,SpatialBoxGeometry:()=>N,SpatialComponent:()=>$,SpatialConeGeometry:()=>Q,SpatialCylinderGeometry:()=>q,SpatialEntity:()=>T,SpatialGeometry:()=>f,SpatialMaterial:()=>j,SpatialModelAsset:()=>J,SpatialModelEntity:()=>B,SpatialObject:()=>d,SpatialPlaneGeometry:()=>X,SpatialScene:()=>x,SpatialSceneState:()=>re,SpatialSceneValues:()=>Te,SpatialSession:()=>W,SpatialSphereGeometry:()=>H,SpatialUnlitMaterial:()=>k,Spatialized2DElement:()=>C,SpatializedDynamic3DElement:()=>I,SpatializedElement:()=>E,SpatializedElementType:()=>ve,SpatializedStatic3DElement:()=>O,WorldAlignmentValues:()=>De,WorldScalingValues:()=>Me,createAttachmentEntity:()=>oe,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>Yt,isValidSceneUnit:()=>zt,isValidSpatialSceneType:()=>ie,isValidWorldAlignmentType:()=>ee,isValidWorldScalingType:()=>te});g();var d=class{constructor(t){this.id=t}name;isDestroyed=!1;async inspect(){let t=await new Mt(this.id).execute();if(t.success)return t.data;throw new Error(t.errorMessage)}async destroy(){if(this.isDestroyed)return;let t=await new Dt(this.id).execute();if(t.success)return this.onDestroy(),this.isDestroyed=!0,t.data;if(this.isDestroyed)return;throw new Error(t.errorMessage)}onDestroy(){}};g();g();g();var Kt,x=class i extends d{static getInstance(){return Kt||(Kt=new i("")),Kt}async convertCoordinate(t,e,r){try{return(await new Pt(t,e,r).execute())?.data??t}catch(n){throw console.warn("SpatialScene.convertCoordinate error:",n),n}}async updateSpatialProperties(t){return new et(t).execute()}async addSpatializedElement(t){return new dt(t).execute()}async updateSceneCreationConfig(t){return new it(t).execute()}async getState(){return(await new nt().execute()).data.name}};var ve=(r=>(r[r.Spatialized2DElement=0]="Spatialized2DElement",r[r.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",r[r.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",r))(ve||{}),Pe=["automatic","visible","hidden"];function Yt(i){return Pe.includes(i)}var Me=["automatic","dynamic"];function te(i){return Me.includes(i)}var De=["adaptive","automatic","gravityAligned"];function ee(i){return De.includes(i)}var Te=["window","volume"];function ie(i){return Te.includes(i)}function zt(i){if(typeof i=="number")return i>=0;if(typeof i=="string"){if(i.endsWith("px"))return isNaN(Number(i.slice(0,-2)))?!1:Number(i.slice(0,-2))>=0;if(i.endsWith("m"))return isNaN(Number(i.slice(0,-1)))?!1:Number(i.slice(0,-1))>=0}return!1}var re=(a=>(a.idle="idle",a.pending="pending",a.willVisible="willVisible",a.visible="visible",a.fail="fail",a))(re||{}),Zt=class{constructor(t,e){this.size=t;this.origin=e;this.size=t,this.origin=e}get x(){return this.origin.x}get y(){return this.origin.y}get z(){return this.origin.z}get width(){return this.size.width}get height(){return this.size.height}get depth(){return this.size.depth}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get back(){return this.z}get front(){return this.z+this.depth}};var ai={defaultSize:{width:1280,height:720}},oi={defaultSize:{width:.94,height:.94,depth:.94}},si="webspatial://",Wt=class i{originalOpen;static instance;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(t){this.originalOpen=t.open.bind(t),t.open=this.open}configMap={};getConfig(t){if(!(t===void 0||!this.configMap[t]))return this.configMap[t]}ensureAbsoluteUrl(t){if(!t||/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t))return t;if(t.startsWith("//"))return`${window.location.protocol}${t}`;try{return new URL(t,document.baseURI).toString()}catch{return t}}open=(t,e,r)=>{if(t?.startsWith(si))return this.originalOpen(t,e,r);if(t=this.ensureAbsoluteUrl(t),e==="_self"||e==="_parent"||e==="_top")return this.originalOpen(t,e,r);let n=e?this.getConfig(e):void 0,o=new Rt(t,n,e,r).executeSync(),s=o.data?.id;return s&&new rt(s).execute(),o.data?.windowProxy};initScene(t,e,r){let n=r?.type??"window",a=ae(n),o=e({...a}),[s,p]=Ie(o,n);p.length>0&&console.warn(`initScene ${t} with errors: ${p.join(", ")}`),this.configMap[t]={...s,type:n}}};function Re(i){return i/1360}function Ce(i){return i*1360}function Oe(i,t,e){if(typeof i=="number")return e==="px"&&t==="px"||e==="m"&&t==="m"?i:e==="px"&&t==="m"?Re(i):e==="m"&&t==="px"?Ce(i):i;if(t==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return Re(Number(i.slice(0,-2)));throw new Error("formatToNumber: invalid str")}else if(t==="px"){if(i.endsWith("px"))return Number(i.slice(0,-2));if(i.endsWith("m"))return Ce(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function Ie(i,t){let e=ae(t),r=[],n=t==="window";if(ie(t)||r.push("sceneType"),i.defaultSize){let a=["width","height","depth"];for(let o of a)o in i.defaultSize&&(zt(i.defaultSize[o])?i.defaultSize[o]=Oe(i.defaultSize[o],n?"px":"m",n?"px":"m"):(i.defaultSize[o]=e.defaultSize[o],r.push(`defaultSize.${o}`)))}if(i.resizability){let a=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of a)o in i.resizability&&(zt(i.resizability[o])?i.resizability[o]=Oe(i.resizability[o],"px",n?"px":"m"):(i.resizability[o]=void 0,r.push(`resizability.${o}`)))}return i.worldScaling&&(te(i.worldScaling)||(i.worldScaling="automatic",r.push("worldScaling"))),i.worldAlignment&&(ee(i.worldAlignment)||(i.worldAlignment="automatic",r.push("worldAlignment"))),i.baseplateVisibility&&(Yt(i.baseplateVisibility)||(i.baseplateVisibility="automatic",r.push("baseplateVisibility"))),[i,r]}function ze(i,t,e){return Wt.getInstance().initScene(i,t,e)}function pi(i){Wt.getInstance().init(i)}function ne(i){i.document.onclick=function(t){let e=t.target,r=!1;for(;!r;){if(e&&e.tagName=="A")return!li(t);if(e&&e.parentElement)e=e.parentElement;else break}}}function li(i){let t=i.target;if(t.tagName==="A"){let e=t,r=e.target,n=e.href;if(r&&r!=="_self")return i.preventDefault(),window.open(n,r),!0}}function ae(i){return i==="window"?ai:oi}async function ci(){if(!window.opener||await x.getInstance().getState()!=="pending")return;function t(e){document.readyState==="interactive"||document.readyState==="complete"?e():document.addEventListener("DOMContentLoaded",e)}t(async()=>{let e=ae(window.xrCurrentSceneType??"window"),r=e;if(typeof window.xrCurrentSceneDefaults=="function")try{r=await window.xrCurrentSceneDefaults?.(e)}catch(s){console.error(s)}await new Promise((s,p)=>{setTimeout(()=>{s(null)},1e3)});let n=window.xrCurrentSceneType??"window",[a,o]=Ie(r,n);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await x.getInstance().updateSceneCreationConfig({...a,type:n})})}function We(){pi(window),ne(window),ci()}g();g();g();w();function u(i,t){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:t})}var E=class extends d{constructor(e){super(e);this.id=e;c.addEventReceiver(e,this.onReceiveEvent.bind(this))}async updateTransform(e){return new pt(this,e).execute()}_cubeInfo;get cubeInfo(){return this._cubeInfo}_transform;_transformInv;get transform(){return this._transform}get transformInv(){return this._transformInv}onReceiveEvent(e){let{type:r}=e;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",e.detail);this._onSpatialTap?.(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",e.detail);this._onSpatialDragStart?.(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",e.detail);this._onSpatialDrag?.(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",e.detail);this._onSpatialDragEnd?.(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",e.detail);this._onSpatialRotate?.(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",e.detail);this._onSpatialRotateEnd?.(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",e.detail);this._onSpatialMagnify?.(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",e.detail);this._onSpatialMagnifyEnd?.(n)}}_onSpatialTap;set onSpatialTap(e){this._onSpatialTap=e,this.updateProperties({enableTapGesture:e!==void 0})}_onSpatialDragStart;set onSpatialDragStart(e){this._onSpatialDragStart=e,this.updateProperties({enableDragStartGesture:this._onSpatialDragStart!==void 0})}_onSpatialDrag;set onSpatialDrag(e){this._onSpatialDrag=e,this.updateProperties({enableDragGesture:this._onSpatialDrag!==void 0})}_onSpatialDragEnd;set onSpatialDragEnd(e){this._onSpatialDragEnd=e,this.updateProperties({enableDragEndGesture:e!==void 0})}_onSpatialRotate;set onSpatialRotate(e){this._onSpatialRotate=e,this.updateProperties({enableRotateGesture:this._onSpatialRotate!==void 0})}_onSpatialRotateEnd;set onSpatialRotateEnd(e){this._onSpatialRotateEnd=e,this.updateProperties({enableRotateEndGesture:e!==void 0})}_onSpatialMagnify;set onSpatialMagnify(e){this._onSpatialMagnify=e,this.updateProperties({enableMagnifyGesture:e!==void 0})}_onSpatialMagnifyEnd;set onSpatialMagnifyEnd(e){this._onSpatialMagnifyEnd=e,this.updateProperties({enableMagnifyEndGesture:e!==void 0})}onDestroy(){c.removeEventReceiver(this.id)}};var C=class extends E{constructor(e,r){super(e);this.windowProxy=r;ne(r)}async updateProperties(e){return new at(this,e).execute()}async addSpatializedElement(e){return new ct(this,e).execute()}};g();var O=class extends E{constructor(t,e){super(t),this.modelURL=e}_readyResolve;modelURL;createReadyPromise(){return this._readyResolve?.(!1),new Promise(t=>{this._readyResolve=t})}ready=this.createReadyPromise();async updateProperties(t){return t.modelURL!==void 0&&this.modelURL!==t.modelURL&&(this.modelURL=t.modelURL,this.ready=this.createReadyPromise()),new lt(this,t).execute()}onReceiveEvent(t){t.type==="modelloaded"?(this._onLoadCallback?.(),this._readyResolve?.(!0)):t.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):super.onReceiveEvent(t)}_onLoadCallback;set onLoadCallback(t){this._onLoadCallback=t}_onLoadFailureCallback;set onLoadFailureCallback(t){this._onLoadFailureCallback=t}updateModelTransform(t){let e=Array.from(t.toFloat64Array());this.updateProperties({modelTransform:e})}};g();var I=class extends E{children=[];events={};constructor(t){super(t)}async addEntity(t){let e=new D(t.id,this.id).execute();return this.children.push(t),t.parent=this,e}addEvent(t,e){this.events[t]=e}removeEvent(t){this.events[t]&&delete this.events[t]}dispatchEvent(t){this.events[t.type]?.(t)}async updateProperties(t){return new ot(this,t).execute()}};async function Ae(){let i=await new Tt().execute();if(i.success){let{id:t,windowProxy:e}=i.data;return e.document.head.innerHTML=`<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
74
|
-
<base href="${document.baseURI}">`,new C(t,e)}else throw new Error("createSpatialized2DElement failed")}async function Ve(i){let t=await new mt(i).execute();if(t.success){let{id:e}=t.data;return new O(e,i)}else throw new Error("createSpatializedStatic3DElement failed")}async function Ge(){let i=await new ut().execute();if(i.success){let{id:t}=i.data;return new I(t)}else throw new Error("createSpatializedDynamic3DElement failed")}g();var At=class extends d{constructor(e,r,n){super(e);this.windowProxy=r;this.options=n}getContainer(){return this.windowProxy.document.body}getWindowProxy(){return this.windowProxy}async update(e){if(!this.isDestroyed)return e.position&&(this.options.position=e.position),e.size&&(this.options.size=e.size),new It(this.id,e).execute()}};async function oe(i){let t=await new Ct(i).execute();if(!t.success)throw new Error("createAttachmentEntity failed: "+t?.errorMessage);let{id:e,windowProxy:r}=t.data;return await new Ot(e,i).execute(),new At(e,r,i)}g();g();g();w();var T=class extends d{constructor(e,r){super(e);this.userData=r;c.addEventReceiver(e,this.onReceiveEvent)}position={x:0,y:0,z:0};rotation={x:0,y:0,z:0};scale={x:1,y:1,z:1};events={};children=[];parent=null;_enableInput=!1;get enableInput(){return this._enableInput}set enableInput(e){this._enableInput!==e&&(this._enableInput=e,this.updateEntityEvent("spatialtap",e).catch(r=>{console.error("enableInput updateEntityEvent failed","spatialtap",r),this._enableInput===e&&(this._enableInput=!e)}))}async addComponent(e){return new bt(this,e).execute()}async setPosition(e){return this.updateTransform({position:e})}async setRotation(e){return this.updateTransform({rotation:e})}async setScale(e){return this.updateTransform({scale:e})}async addEntity(e){let r=await new D(e.id,this.id).execute();return this.children.push(e),e.parent=this,r}async removeFromParent(){let e=await new D(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(r=>r.id!==this.id),this.parent=null),e}async updateTransform(e){return this.position=e.position??this.position,this.rotation=e.rotation??this.rotation,this.scale=e.scale??this.scale,new Y(this,e).execute()}async addEvent(e,r){if(this.events[e])this.events[e]=r;else try{await this.updateEntityEvent(e,!0),this.events[e]=r}catch{console.error("addEvent failed",e)}}async removeEvent(e){if(this.events[e]){delete this.events[e];try{await this.updateEntityEvent(e,!1)}catch{console.error("removeEvent failed",e)}}}async updateEntityEvent(e,r){return new tt(this,e,r).execute()}onReceiveEvent=e=>{let{type:r}=e;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",e.detail);this.dispatchEvent(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",e.detail);this.dispatchEvent(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",e.detail);this.dispatchEvent(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",e.detail);this.dispatchEvent(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",e.detail);this.dispatchEvent(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",e.detail);this.dispatchEvent(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",e.detail);this.dispatchEvent(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",e.detail);this.dispatchEvent(n)}};dispatchEvent(e){e.__origin||Object.defineProperty(e,"__origin",{value:this,enumerable:!1}),this.events[e.type]?.(e),e.bubbles&&!e.cancelBubble&&this.parent&&this.parent.dispatchEvent(e)}onDestroy(){c.removeEventReceiver(this.id),this.children.forEach(e=>{e.parent=null}),this.children=[],this.parent&&(this.parent.children=this.parent.children.filter(e=>e.id!==this.id),this.parent=null)}async convertFromEntityToEntity(e,r,n){return new xt(e,r,n).execute()}async convertFromEntityToScene(e,r){return new wt(e,r).execute()}async convertFromSceneToEntity(e,r){return new vt(e,r).execute()}};var B=class extends T{constructor(e,r,n){super(e,n);this.id=e;this.options=r;this.userData=n}};w();var $=class extends d{constructor(t){super(t),c.addEventReceiver(t,this.onReceiveEvent)}onReceiveEvent=t=>{let{type:e}=t;e==="objectdestroy"&&(this.isDestroyed=!0)}};var F=class extends ${constructor(e,r){super(e);this.options=r}};g();var j=class extends d{constructor(e,r){super(e);this.id=e;this.type=r;this.type=r}};var k=class extends j{constructor(e,r){super(e,"unlit");this.id=e;this.options=r}updateProperties(e){return new st(this,e).execute()}};var J=class extends d{constructor(e,r){super(e);this.id=e;this.options=r}};async function _e(i){let t=await new yt(i?.name).execute();if(t.success){let{id:e}=t.data;return new T(e,i)}else throw new Error("createSpatialEntity failed:"+t?.errorMessage)}async function z(i,t){let e=await new ht(i.type,t).execute();if(e.success){let{id:r}=e.data;return new i(r,t)}else throw new Error("createSpatialGeometry failed:"+e?.errorMessage)}async function Ue(i){let t=await new Et(i).execute();if(t.success){let{id:e}=t.data;return new k(e,i)}else throw new Error("createSpatialUnlitMaterial failed:"+t?.errorMessage)}async function Le(i){let t=await new St(i).execute();if(t.success){let{id:e}=t.data;return new F(e,i)}else throw new Error("createModelComponent failed:"+t?.errorMessage)}async function Be(i,t){let e=await new gt(i).execute();if(e.success){let{id:r}=e.data;return new B(r,i,t)}else throw new Error("createSpatialModelEntity failed:"+e?.errorMessage)}async function $e(i){let t=await new ft(i).execute();if(t.success){let{id:e}=t.data;return new J(e,i)}else throw new Error("createModelAsset failed:"+t?.errorMessage)}var f=class extends d{constructor(e,r){super(e);this.id=e;this.options=r}static type};var N=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="BoxGeometry"};var H=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="SphereGeometry"};var q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="CylinderGeometry"};var X=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="PlaneGeometry"};var Q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="ConeGeometry"};var W=class{getSpatialScene(){return x.getInstance()}createSpatialized2DElement(){return Ae()}createSpatializedStatic3DElement(t){return Ve(t)}initScene=ze;createSpatializedDynamic3DElement(){return Ge()}createEntity(t){return _e(t)}createBoxGeometry(t={}){return z(N,t)}createPlaneGeometry(t={}){return z(X,t)}createSphereGeometry(t={}){return z(H,t)}createConeGeometry(t){return z(Q,t)}createCylinderGeometry(t){return z(q,t)}createModelComponent(t){return Le(t)}createUnlitMaterial(t){return Ue(t)}createModelAsset(t){return $e(t)}createSpatialModelEntity(t,e){return Be(t,e)}createAttachmentEntity(t){return oe(t)}};w();var A=class{wsAppShellVersionFromUA;requestSession(){return this.runInSpatialWeb()?(c.init(),new W):null}runInSpatialWeb(){return navigator.userAgent.indexOf("WebSpatial/")>0}getShellVersionFromUA(){if(this.wsAppShellVersionFromUA!==void 0)return this.wsAppShellVersionFromUA;if(typeof navigator>"u"||typeof navigator.userAgent!="string")return this.wsAppShellVersionFromUA=null,null;let t=navigator.userAgent.match(/WSAppShell\/(\d+(?:\.\d+){2}(?:[-+][0-9A-Za-z.-]+)*)/);return this.wsAppShellVersionFromUA=t?t[1]:"1.3.0",this.wsAppShellVersionFromUA}isSupported(){return!0}getNativeVersion(){return window.__WebSpatialData&&window.__WebSpatialData.getNativeVersion?window.__WebSpatialData.getNativeVersion():window.WebSpatailNativeVersion==="WS_SHELL_VERSION"?this.getClientVersion():window.WebSpatailNativeVersion}getClientVersion(){return"1.4.0"}};var pe={};R(pe,{getValue:()=>ui,physicalToPoint:()=>mi,pointToPhysical:()=>di,subscribe:()=>yi});w();var b={meterToPtUnscaled:1360,meterToPtScaled:1360};function Fe(i){return i?.worldScalingCompensation??"scaled"}function di(i,t){return se(),Fe(t)==="unscaled"?i/b.meterToPtUnscaled:i/b.meterToPtScaled}function mi(i,t){return se(),Fe(t)==="unscaled"?i*b.meterToPtUnscaled:i*b.meterToPtScaled}function se(){if(typeof window>"u")return;let i=window.__webspatialsdk__?.physicalMetrics;if(!i)return;let t={meterToPtScaled:i.meterToPtScaled??b.meterToPtScaled,meterToPtUnscaled:i.meterToPtUnscaled??b.meterToPtUnscaled};(t.meterToPtScaled!==b.meterToPtScaled||t.meterToPtUnscaled!==b.meterToPtUnscaled)&&(b=t)}function ui(){return se(),b}function yi(i){if(typeof window>"u")return()=>{};let t=()=>{i()};return c.addEventReceiver("window",t),()=>{c.removeEventReceiver("window")}}$t();Xt();var je=new A,Ut,Vt={backgroundMaterial:"--xr-background-material"},ke="";function Gt(i){i!==ke&&(Ut?.getSpatialScene()?.updateSpatialProperties({material:i}),ke=i)}function Si(){let t=getComputedStyle(document.documentElement).getPropertyValue(Vt.backgroundMaterial);Gt(t||"none")}var P={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function Je(){let i=getComputedStyle(document.documentElement),t=xe(i);gi(t)}function gi(i){(P.topLeading!==i.topLeading||P.bottomLeading!==i.bottomLeading||P.topTrailing!==i.topTrailing||P.bottomTrailing!==i.bottomTrailing)&&(Ut?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),P.topLeading=i.topLeading,P.bottomLeading=i.bottomLeading,P.topTrailing=i.topTrailing,P.bottomTrailing=i.bottomTrailing)}function fi(i){Ut?.getSpatialScene().updateSpatialProperties({opacity:i})}function Ne(){let i=getComputedStyle(document.documentElement),t=parseFloat(i.getPropertyValue("opacity"));fi(t)}function hi(){let i=document.documentElement.style,t=new Proxy(i,{set:function(e,r,n){let a=Reflect.set(e,r,n);return r===Vt.backgroundMaterial&&Gt(n),(r==="border-radius"||r==="borderRadius"||r==="border-top-left-radius"||r==="borderTopLeftRadius"||r==="border-top-right-radius"||r==="borderTopRightRadius"||r==="border-bottom-left-radius"||r==="borderBottomLeftRadius"||r==="border-bottom-right-radius"||r==="borderBottomRightRadius")&&Je(),r==="opacity"&&Ne(),a},get:function(e,r){return typeof e[r]=="function"?function(...n){if(r==="setProperty"){let[a,o]=n;a===Vt.backgroundMaterial&&Gt(o)}else if(r==="removeProperty"){let[a]=n;a===Vt.backgroundMaterial&&Gt("none")}return e[r](...n)}:Reflect.get(e,r)}});Object.defineProperty(document.documentElement,"style",{get:function(){return t}})}function Ei(){new MutationObserver(_t).observe(document.head,{childList:!0,subtree:!0})}function _t(){Si(),Je(),Ne()}function bi(){new MutationObserver(t=>{t.forEach(e=>{e.type==="attributes"&&e.attributeName&&_t()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function He(){je.runInSpatialWeb()&&(Ut=await je.requestSession(),document.readyState==="complete"?_t():window.addEventListener("load",()=>{_t()}),hi(),Ei(),bi())}!G()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(We(),He());return V(xi);})();
|
|
73
|
+
`),a.close())}catch(n){console.error("Error initializing iframe content:",n)}}}catch(n){console.error("Error setting up iframe:",n)}}parseFeatures(t){let e={};return t.split(",").forEach(n=>{let[a,o]=n.split("=").map(s=>s.trim());a&&o&&(e[a]=o)}),e}sendMessageToIframe(t,e){let r=this.iframeRegistry.get(t);return r&&r.contentWindow?(r.contentWindow.postMessage(e,window.location.origin),!0):!1}getAllActiveIframes(){let t=[];return this.iframeRegistry.forEach((e,r)=>{t.push({spatialId:r,iframe:e})}),t}dispose(){this.iframeRegistry.forEach((t,e)=>{console.log(`Disposing iframe with spatialId: ${e}`),t.remove()}),this.iframeRegistry.clear()}generateUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16).toUpperCase()})}}});var c,v=h(()=>{"use strict";c=class i{static eventReceiver={};static init(){window.__SpatialWebEvent=({id:t,data:e})=>{i.eventReceiver[t]?.(e)}}static addEventReceiver(t,e){i.eventReceiver[t]=e}static removeEventReceiver(t){delete i.eventReceiver[t]}}});var fe={};R(fe,{PicoOSPlatform:()=>Ht});function ge(){return Nt=(Nt+1)%ri,`rId_${Nt}`}var Nt,ri,Ht,he=h(()=>{"use strict";_();v();Nt=0,ri=1e5;Ht=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=ge();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(g(p,y))}});let o=window.webspatialBridge.postMessage(a,t,e);if(o!==""){c.removeEventReceiver(a);let s=JSON.parse(o);if(s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(g(p,y))}}}catch(a){console.error(`SwanPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(g(o,s))}})}async callWebSpatialProtocol(t,e,r,n){return new Promise((a,o)=>{let s=ge();try{let p=null;c.addEventReceiver(s,y=>{a(m({windowProxy:p,id:y.spatialId})),c.removeEventReceiver(s)}),p=this.openWindow(t,"rid="+s,r,n).windowProxy}catch(p){let{code:y,message:X}=p;c.removeEventReceiver(s),a(g(y,X))}})}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${t}?${e||""}`,r,n)}}}});var Ee={};R(Ee,{AndroidPlatform:()=>Kt});function ai(){return Qt=(Qt+1)%ni,`rId_${Qt}`}var qt,Qt,ni,Kt,be=h(()=>{"use strict";_();S();v();qt=0,Qt=0,ni=1e5;Kt=class{async callJSB(t,e){return new Promise((r,n)=>{try{let a=ai();c.addEventReceiver(a,s=>{if(c.removeEventReceiver(a),s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(g(p,y))}});let o=window.webspatialBridge.postMessage(a,t,e);if(o!==""){c.removeEventReceiver(a);let s=JSON.parse(o);if(s.success)r(m(s.data));else{let{code:p,message:y}=s.data;r(g(p,y))}}}catch(a){console.error(`AndroidPlatform cmd: ${t}, msg: ${e} error: ${a}`);let{code:o,message:s}=a;r(g(o,s))}})}async callWebSpatialProtocol(t,e,r,n){await new Promise(p=>setTimeout(p,16*qt)),qt++;let a=await new U().execute();for(;!a.data.can;)await new Promise(p=>setTimeout(p,16)),a=await new U().execute();let{windowProxy:o}=this.openWindow(t,e,r,n);for(;!o?.open;)await new Promise(p=>setTimeout(p,16));for(o?.open("about:blank","_self");!o?.__SpatialId;)await new Promise(p=>setTimeout(p,16));let s=o?.__SpatialId;return qt--,Promise.resolve(m({windowProxy:o,id:s}))}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){return{spatialId:"",windowProxy:window.open(`webspatial://${t}?${e||""}`,r,n)}}}});var xe={};R(xe,{VisionOSPlatform:()=>Xt});var Xt,we=h(()=>{"use strict";_();Xt=class{async callJSB(t,e){try{let r=await window.webkit.messageHandlers.bridge.postMessage(`${t}::${e}`);return m(r)}catch(r){let{code:n,message:a}=JSON.parse(r.message);return g(n,a)}}callWebSpatialProtocol(t,e,r,n){let{spatialId:a,windowProxy:o}=this.openWindow(t,e,r,n);return Promise.resolve(m({windowProxy:o,id:a}))}callWebSpatialProtocolSync(t,e,r,n){let{spatialId:a="",windowProxy:o}=this.openWindow(t,e,r,n);return m({windowProxy:o,id:a})}openWindow(t,e,r,n){let a=window.open(`webspatial://${t}?${e||""}`,r,n);return{spatialId:a?.navigator.userAgent?.match(/\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi)?.[0],windowProxy:a}}}});function oi(i){let t=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function si(i,t){if(!i)return!1;for(let e=0;e<3;e+=1){let r=i[e]-t[e];if(r>0)return!0;if(r<0)return!1}return!1}function ve(){if(G())return new Z;let i=window.navigator.userAgent,t=oi(i);if(window.navigator.userAgent.includes("Puppeteer")){let e=(Se(),V(ye)).PuppeteerPlatform;return new e}else if(i.includes("PicoWebApp")&&si(t,[0,0,1])){let e=(he(),V(fe)).PicoOSPlatform;return new e}else if(i.includes("Android")||i.includes("Linux")){let e=(be(),V(Ee)).AndroidPlatform;return new e}else{let e=(we(),V(xe)).VisionOSPlatform;return new e}}var Pe=h(()=>{"use strict";kt();ue()});function Y(i,t){return i===""?0:i.endsWith("%")?t*parseFloat(i)/100:parseFloat(i)}function Me(i){let t=parseFloat(i.getPropertyValue("width")),e=i.getPropertyValue("border-top-left-radius"),r=i.getPropertyValue("border-top-right-radius"),n=i.getPropertyValue("border-bottom-left-radius"),a=i.getPropertyValue("border-bottom-right-radius");return{topLeading:Y(e,t),bottomLeading:Y(n,t),topTrailing:Y(r,t),bottomTrailing:Y(a,t)}}function Te(i,t,e){let{x:r,y:n,z:a}=i,{x:o,y:s,z:p}=t,{x:y,y:X,z:Ft}=e,E=new DOMMatrix;return E=E.translate(r,n,a),E=E.rotate(o,s,p),E=E.scale(y,X,Ft),E}var Zt=h(()=>{"use strict"});var Yt,l,tt,et,it,rt,nt,at,P,ot,st,pt,lt,ct,dt,mt,ut,yt,St,gt,ft,ht,Et,bt,xt,wt,vt,T,Pt,Mt,Tt,Dt,Rt,Ct,U,L,Ot,It,zt,Wt,At,S=h(()=>{"use strict";Pe();Zt();Yt=ve(),l=class{commandType="";async execute(){let t=this.getParams(),e=t?JSON.stringify(t):"";return Yt.callJSB(this.commandType,e)}},tt=class extends l{constructor(e,r){super();this.entity=e;this.properties=r}commandType="UpdateEntityProperties";getParams(){let e=Te(this.properties.position??this.entity.position,this.properties.rotation??this.entity.rotation,this.properties.scale??this.entity.scale).toFloat64Array();return{entityId:this.entity.id,transform:e}}},et=class extends l{constructor(e,r,n){super();this.entity=e;this.type=r;this.isEnable=n}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}},it=class extends l{properties;commandType="UpdateSpatialSceneProperties";constructor(t){super(),this.properties=t}getParams(){return this.properties}},rt=class extends l{config;commandType="UpdateSceneConfig";constructor(t){super(),this.config=t}getParams(){return{config:this.config}}},nt=class extends l{constructor(e){super();this.id=e}commandType="FocusScene";getParams(){return{id:this.id}}},at=class extends l{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},P=class extends l{constructor(e){super();this.spatialObject=e}getParams(){let e=this.getExtraParams();return{id:this.spatialObject.id,...e}}},ot=class extends P{properties;commandType="UpdateSpatialized2DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},st=class extends P{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},pt=class extends P{properties;commandType="UpdateUnlitMaterialProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},lt=class extends P{matrix;commandType="UpdateSpatializedElementTransform";constructor(t,e){super(t),this.matrix=e}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},ct=class extends P{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(t,e){super(t),this.properties=e}getExtraParams(){return this.properties}},dt=class extends P{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(t,e){super(t),this.spatializedElement=e}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},mt=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(t){super(),this.spatializedElement=t}getParams(){return{spatializedElementId:this.spatializedElement.id}}},ut=class extends l{constructor(e){super();this.modelURL=e;this.modelURL=e}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},yt=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},St=class extends l{constructor(e){super();this.name=e}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},gt=class extends l{constructor(e){super();this.options=e}getParams(){let e=this.options.mesh.id,r=this.options.materials.map(n=>n.id);return{geometryId:e,materialIds:r}}commandType="CreateModelComponent"},ft=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ht=class extends l{constructor(e){super();this.options=e}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},Et=class extends l{constructor(e,r={}){super();this.type=e;this.options=r}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},bt=class extends l{constructor(e){super();this.options=e}getParams(){return this.options}commandType="CreateUnlitMaterial"},xt=class extends l{constructor(e,r){super();this.entity=e;this.comp=r}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},wt=class extends l{constructor(e,r){super();this.entity=e;this.comp=r}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="RemoveComponentFromEntity"},vt=class extends l{constructor(e,r){super();this.entityId=e;this.materials=r}getParams(){return{entityId:this.entityId,materialIds:this.materials.map(e=>e.id)}}commandType="SetMaterialsOnEntity"},T=class extends l{constructor(e,r){super();this.childId=e;this.parentId=r}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},Pt=class extends l{constructor(e,r,n){super();this.fromEntityId=e;this.toEntityId=r;this.fromPosition=n}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},Mt=class extends l{constructor(e,r){super();this.fromEntityId=e;this.position=r}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},Tt=class extends l{constructor(e,r){super();this.entityId=e;this.position=r}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},Dt=class extends l{constructor(e,r,n){super();this.position=e;this.fromId=r;this.toId=n}getParams(){return{position:this.position,fromId:this.fromId,toId:this.toId}}commandType="ConvertCoordinate"},Rt=class extends l{constructor(e=""){super();this.id=e}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Ct=class extends l{constructor(e){super();this.id=e}commandType="Destroy";getParams(){return{id:this.id}}},U=class extends l{constructor(e=""){super();this.id=e}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},L=class extends l{target;features;async execute(){let t=this.getQuery();return Yt.callWebSpatialProtocol(this.commandType,t,this.target,this.features)}executeSync(){let t=this.getQuery();return Yt.callWebSpatialProtocolSync(this.commandType,t,this.target,this.features)}getQuery(){let t,e=this.getParams();return e&&(t=Object.keys(e).map(r=>{let n=e[r],a=typeof n=="object"?JSON.stringify(n):n;return`${r}=${encodeURIComponent(a)}`}).join("&")),t}},Ot=class extends L{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},It=class extends L{constructor(e,r,n,a){super();this.url=e;this.config=r;this.target=n;this.features=a}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}},zt=class extends L{constructor(e){super();this.options=e}commandType="createAttachment";getParams(){return{}}},Wt=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="InitializeAttachment";getParams(){return{id:this.attachmentId,parentEntityId:this.options.parentEntityId,position:this.options.position??[0,0,0],size:this.options.size,ownerViewId:this.options.ownerViewId}}},At=class extends l{constructor(e,r){super();this.attachmentId=e;this.options=r}commandType="UpdateAttachmentEntity";getParams(){return{id:this.attachmentId,...this.options}}}});var Pi={};R(Pi,{Attachment:()=>_t,BaseplateVisibilityValues:()=>Re,CubeInfo:()=>ee,ModelComponent:()=>F,PhysicalMetrics:()=>de,Spatial:()=>A,SpatialBoxGeometry:()=>N,SpatialComponent:()=>$,SpatialConeGeometry:()=>K,SpatialCylinderGeometry:()=>q,SpatialEntity:()=>D,SpatialGeometry:()=>f,SpatialMaterial:()=>j,SpatialModelAsset:()=>J,SpatialModelEntity:()=>B,SpatialObject:()=>d,SpatialPlaneGeometry:()=>Q,SpatialScene:()=>w,SpatialSceneState:()=>oe,SpatialSceneValues:()=>Ie,SpatialSession:()=>W,SpatialSphereGeometry:()=>H,SpatialUnlitMaterial:()=>k,Spatialized2DElement:()=>C,SpatializedDynamic3DElement:()=>I,SpatializedElement:()=>b,SpatializedElementType:()=>De,SpatializedStatic3DElement:()=>O,WorldAlignmentValues:()=>Oe,WorldScalingValues:()=>Ce,createAttachmentEntity:()=>le,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>ie,isValidSceneUnit:()=>Vt,isValidSpatialSceneType:()=>ae,isValidWorldAlignmentType:()=>ne,isValidWorldScalingType:()=>re});S();var d=class{constructor(t){this.id=t}name;isDestroyed=!1;async inspect(){let t=await new Rt(this.id).execute();if(t.success)return t.data;throw new Error(t.errorMessage)}async destroy(){if(this.isDestroyed)return;let t=await new Ct(this.id).execute();if(t.success)return this.onDestroy(),this.isDestroyed=!0,t.data;if(this.isDestroyed)return;throw new Error(t.errorMessage)}onDestroy(){}};S();S();S();var te,w=class i extends d{static getInstance(){return te||(te=new i("")),te}async convertCoordinate(t,e,r){try{return(await new Dt(t,e,r).execute())?.data??t}catch(n){throw console.warn("SpatialScene.convertCoordinate error:",n),n}}async updateSpatialProperties(t){return new it(t).execute()}async addSpatializedElement(t){return new mt(t).execute()}async updateSceneCreationConfig(t){return new rt(t).execute()}async getState(){return(await new at().execute()).data.name}};var De=(r=>(r[r.Spatialized2DElement=0]="Spatialized2DElement",r[r.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",r[r.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",r))(De||{}),Re=["automatic","visible","hidden"];function ie(i){return Re.includes(i)}var Ce=["automatic","dynamic"];function re(i){return Ce.includes(i)}var Oe=["adaptive","automatic","gravityAligned"];function ne(i){return Oe.includes(i)}var Ie=["window","volume"];function ae(i){return Ie.includes(i)}function Vt(i){if(typeof i=="number")return i>=0;if(typeof i=="string"){if(i.endsWith("px"))return isNaN(Number(i.slice(0,-2)))?!1:Number(i.slice(0,-2))>=0;if(i.endsWith("m"))return isNaN(Number(i.slice(0,-1)))?!1:Number(i.slice(0,-1))>=0}return!1}var oe=(a=>(a.idle="idle",a.pending="pending",a.willVisible="willVisible",a.visible="visible",a.fail="fail",a))(oe||{}),ee=class{constructor(t,e){this.size=t;this.origin=e;this.size=t,this.origin=e}get x(){return this.origin.x}get y(){return this.origin.y}get z(){return this.origin.z}get width(){return this.size.width}get height(){return this.size.height}get depth(){return this.size.depth}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get back(){return this.z}get front(){return this.z+this.depth}};var pi={defaultSize:{width:1280,height:720}},li={defaultSize:{width:.94,height:.94,depth:.94}},ci="webspatial://",Gt=class i{originalOpen;static instance;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(t){this.originalOpen=t.open.bind(t),t.open=this.open}configMap={};getConfig(t){if(!(t===void 0||!this.configMap[t]))return this.configMap[t]}ensureAbsoluteUrl(t){if(!t||/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t))return t;if(t.startsWith("//"))return`${window.location.protocol}${t}`;try{return new URL(t,document.baseURI).toString()}catch{return t}}open=(t,e,r)=>{if(t?.startsWith(ci)){if(t.includes("createSpatialized2DElement")){let p=window.webSpatial?.genToken?.();if(p){let y=window.location.host,Ft=`${window.location.protocol}//${y}/${p}/?command=createSpatialized2DElement`,E=new URL(t).searchParams.get("rid"),me=new URL(Ft);return E&&me.searchParams.set("rid",E),this.originalOpen(me.toString(),e,r)}}return this.originalOpen(t,e,r)}if(t=this.ensureAbsoluteUrl(t),e==="_self"||e==="_parent"||e==="_top")return this.originalOpen(t,e,r);let n=e?this.getConfig(e):void 0,o=new It(t,n,e,r).executeSync(),s=o.data?.id;return s&&new nt(s).execute(),o.data?.windowProxy};initScene(t,e,r){let n=r?.type??"window",a=pe(n),o=e({...a}),[s,p]=Ve(o,n);p.length>0&&console.warn(`initScene ${t} with errors: ${p.join(", ")}`),this.configMap[t]={...s,type:n}}};function ze(i){return i/1360}function We(i){return i*1360}function Ae(i,t,e){if(typeof i=="number")return e==="px"&&t==="px"||e==="m"&&t==="m"?i:e==="px"&&t==="m"?ze(i):e==="m"&&t==="px"?We(i):i;if(t==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return ze(Number(i.slice(0,-2)));throw new Error("formatToNumber: invalid str")}else if(t==="px"){if(i.endsWith("px"))return Number(i.slice(0,-2));if(i.endsWith("m"))return We(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function Ve(i,t){let e=pe(t),r=[],n=t==="window";if(ae(t)||r.push("sceneType"),i.defaultSize){let a=["width","height","depth"];for(let o of a)o in i.defaultSize&&(Vt(i.defaultSize[o])?i.defaultSize[o]=Ae(i.defaultSize[o],n?"px":"m",n?"px":"m"):(i.defaultSize[o]=e.defaultSize[o],r.push(`defaultSize.${o}`)))}if(i.resizability){let a=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of a)o in i.resizability&&(Vt(i.resizability[o])?i.resizability[o]=Ae(i.resizability[o],"px",n?"px":"m"):(i.resizability[o]=void 0,r.push(`resizability.${o}`)))}return i.worldScaling&&(re(i.worldScaling)||(i.worldScaling="automatic",r.push("worldScaling"))),i.worldAlignment&&(ne(i.worldAlignment)||(i.worldAlignment="automatic",r.push("worldAlignment"))),i.baseplateVisibility&&(ie(i.baseplateVisibility)||(i.baseplateVisibility="automatic",r.push("baseplateVisibility"))),[i,r]}function Ge(i,t,e){return Gt.getInstance().initScene(i,t,e)}function di(i){Gt.getInstance().init(i)}function se(i){i.document.onclick=function(t){let e=t.target,r=!1;for(;!r;){if(e&&e.tagName=="A")return!mi(t);if(e&&e.parentElement)e=e.parentElement;else break}}}function mi(i){let t=i.target;if(t.tagName==="A"){let e=t,r=e.target,n=e.href;if(r&&r!=="_self")return i.preventDefault(),window.open(n,r),!0}}function pe(i){return i==="window"?pi:li}async function ui(){if(!window.opener||await w.getInstance().getState()!=="pending")return;function t(e){document.readyState==="interactive"||document.readyState==="complete"?e():document.addEventListener("DOMContentLoaded",e)}t(async()=>{let e=pe(window.xrCurrentSceneType??"window"),r=e;if(typeof window.xrCurrentSceneDefaults=="function")try{r=await window.xrCurrentSceneDefaults?.(e)}catch(s){console.error(s)}await new Promise((s,p)=>{setTimeout(()=>{s(null)},1e3)});let n=window.xrCurrentSceneType??"window",[a,o]=Ve(r,n);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await w.getInstance().updateSceneCreationConfig({...a,type:n})})}function _e(){di(window),se(window),ui()}S();S();S();v();function u(i,t){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:t})}var b=class extends d{constructor(e){super(e);this.id=e;c.addEventReceiver(e,this.onReceiveEvent.bind(this))}async updateTransform(e){return new lt(this,e).execute()}_cubeInfo;get cubeInfo(){return this._cubeInfo}_transform;_transformInv;get transform(){return this._transform}get transformInv(){return this._transformInv}onReceiveEvent(e){let{type:r}=e;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",e.detail);this._onSpatialTap?.(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",e.detail);this._onSpatialDragStart?.(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",e.detail);this._onSpatialDrag?.(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",e.detail);this._onSpatialDragEnd?.(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",e.detail);this._onSpatialRotate?.(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",e.detail);this._onSpatialRotateEnd?.(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",e.detail);this._onSpatialMagnify?.(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",e.detail);this._onSpatialMagnifyEnd?.(n)}}_onSpatialTap;set onSpatialTap(e){this._onSpatialTap=e,this.updateProperties({enableTapGesture:e!==void 0})}_onSpatialDragStart;set onSpatialDragStart(e){this._onSpatialDragStart=e,this.updateProperties({enableDragStartGesture:this._onSpatialDragStart!==void 0})}_onSpatialDrag;set onSpatialDrag(e){this._onSpatialDrag=e,this.updateProperties({enableDragGesture:this._onSpatialDrag!==void 0})}_onSpatialDragEnd;set onSpatialDragEnd(e){this._onSpatialDragEnd=e,this.updateProperties({enableDragEndGesture:e!==void 0})}_onSpatialRotate;set onSpatialRotate(e){this._onSpatialRotate=e,this.updateProperties({enableRotateGesture:this._onSpatialRotate!==void 0})}_onSpatialRotateEnd;set onSpatialRotateEnd(e){this._onSpatialRotateEnd=e,this.updateProperties({enableRotateEndGesture:e!==void 0})}_onSpatialMagnify;set onSpatialMagnify(e){this._onSpatialMagnify=e,this.updateProperties({enableMagnifyGesture:e!==void 0})}_onSpatialMagnifyEnd;set onSpatialMagnifyEnd(e){this._onSpatialMagnifyEnd=e,this.updateProperties({enableMagnifyEndGesture:e!==void 0})}onDestroy(){c.removeEventReceiver(this.id)}};var C=class extends b{constructor(e,r){super(e);this.windowProxy=r;se(r)}async updateProperties(e){return new ot(this,e).execute()}async addSpatializedElement(e){return new dt(this,e).execute()}};S();var O=class extends b{constructor(t,e){super(t),this.modelURL=e}_readyResolve;modelURL;createReadyPromise(){return this._readyResolve?.(!1),new Promise(t=>{this._readyResolve=t})}ready=this.createReadyPromise();async updateProperties(t){return t.modelURL!==void 0&&this.modelURL!==t.modelURL&&(this.modelURL=t.modelURL,this.ready=this.createReadyPromise()),new ct(this,t).execute()}onReceiveEvent(t){t.type==="modelloaded"?(this._onLoadCallback?.(),this._readyResolve?.(!0)):t.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):super.onReceiveEvent(t)}_onLoadCallback;set onLoadCallback(t){this._onLoadCallback=t}_onLoadFailureCallback;set onLoadFailureCallback(t){this._onLoadFailureCallback=t}updateModelTransform(t){let e=Array.from(t.toFloat64Array());this.updateProperties({modelTransform:e})}};S();var I=class extends b{children=[];events={};constructor(t){super(t)}async addEntity(t){let e=new T(t.id,this.id).execute();return this.children.push(t),t.parent=this,e}addEvent(t,e){this.events[t]=e}removeEvent(t){this.events[t]&&delete this.events[t]}dispatchEvent(t){this.events[t.type]?.(t)}async updateProperties(t){return new st(this,t).execute()}};async function Ue(){let i=await new Ot().execute();if(i.success){let{id:t,windowProxy:e}=i.data;return e.document.head.innerHTML=`<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
74
|
+
<base href="${document.baseURI}">`,new C(t,e)}else throw new Error("createSpatialized2DElement failed")}async function Le(i){let t=await new ut(i).execute();if(t.success){let{id:e}=t.data;return new O(e,i)}else throw new Error("createSpatializedStatic3DElement failed")}async function Be(){let i=await new yt().execute();if(i.success){let{id:t}=i.data;return new I(t)}else throw new Error("createSpatializedDynamic3DElement failed")}S();var _t=class extends d{constructor(e,r,n){super(e);this.windowProxy=r;this.options=n}getContainer(){return this.windowProxy.document.body}getWindowProxy(){return this.windowProxy}async update(e){if(!this.isDestroyed)return e.position&&(this.options.position=e.position),e.size&&(this.options.size=e.size),new At(this.id,e).execute()}};async function le(i){let t=await new zt(i).execute();if(!t.success)throw new Error("createAttachmentEntity failed: "+t?.errorMessage);let{id:e,windowProxy:r}=t.data;return await new Wt(e,i).execute(),new _t(e,r,i)}S();S();S();v();var D=class extends d{constructor(e,r){super(e);this.userData=r;c.addEventReceiver(e,this.onReceiveEvent)}position={x:0,y:0,z:0};rotation={x:0,y:0,z:0};scale={x:1,y:1,z:1};events={};children=[];parent=null;_enableInput=!1;get enableInput(){return this._enableInput}set enableInput(e){this._enableInput!==e&&(this._enableInput=e,this.updateEntityEvent("spatialtap",e).catch(r=>{console.error("enableInput updateEntityEvent failed","spatialtap",r),this._enableInput===e&&(this._enableInput=!e)}))}async addComponent(e){return new xt(this,e).execute()}async removeComponent(e){return new wt(this,e).execute()}async setPosition(e){return this.updateTransform({position:e})}async setRotation(e){return this.updateTransform({rotation:e})}async setScale(e){return this.updateTransform({scale:e})}async addEntity(e){let r=await new T(e.id,this.id).execute();return this.children.push(e),e.parent=this,r}async removeFromParent(){let e=await new T(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(r=>r.id!==this.id),this.parent=null),e}async updateTransform(e){return this.position=e.position??this.position,this.rotation=e.rotation??this.rotation,this.scale=e.scale??this.scale,new tt(this,e).execute()}async addEvent(e,r){if(this.events[e])this.events[e]=r;else try{await this.updateEntityEvent(e,!0),this.events[e]=r}catch{console.error("addEvent failed",e)}}async removeEvent(e){if(this.events[e]){delete this.events[e];try{await this.updateEntityEvent(e,!1)}catch{console.error("removeEvent failed",e)}}}async updateEntityEvent(e,r){return new et(this,e,r).execute()}onReceiveEvent=e=>{let{type:r}=e;if(r==="objectdestroy")this.isDestroyed=!0;else if(r==="spatialtap"){let n=u("spatialtap",e.detail);this.dispatchEvent(n)}else if(r==="spatialdragstart"){let n=u("spatialdragstart",e.detail);this.dispatchEvent(n)}else if(r==="spatialdrag"){let n=u("spatialdrag",e.detail);this.dispatchEvent(n)}else if(r==="spatialdragend"){let n=u("spatialdragend",e.detail);this.dispatchEvent(n)}else if(r==="spatialrotate"){let n=u("spatialrotate",e.detail);this.dispatchEvent(n)}else if(r==="spatialrotateend"){let n=u("spatialrotateend",e.detail);this.dispatchEvent(n)}else if(r==="spatialmagnify"){let n=u("spatialmagnify",e.detail);this.dispatchEvent(n)}else if(r==="spatialmagnifyend"){let n=u("spatialmagnifyend",e.detail);this.dispatchEvent(n)}};dispatchEvent(e){e.__origin||Object.defineProperty(e,"__origin",{value:this,enumerable:!1}),this.events[e.type]?.(e),e.bubbles&&!e.cancelBubble&&this.parent&&this.parent.dispatchEvent(e)}onDestroy(){c.removeEventReceiver(this.id),this.children.forEach(e=>{e.parent=null}),this.children=[],this.parent&&(this.parent.children=this.parent.children.filter(e=>e.id!==this.id),this.parent=null)}async convertFromEntityToEntity(e,r,n){return new Pt(e,r,n).execute()}async convertFromEntityToScene(e,r){return new Mt(e,r).execute()}async convertFromSceneToEntity(e,r){return new Tt(e,r).execute()}};S();var B=class extends D{constructor(e,r,n){super(e,n);this.id=e;this.options=r;this.userData=n}async setMaterials(e){return new vt(this.id,e).execute()}};v();var $=class extends d{constructor(t){super(t),c.addEventReceiver(t,this.onReceiveEvent)}onReceiveEvent=t=>{let{type:e}=t;e==="objectdestroy"&&(this.isDestroyed=!0)}};var F=class extends ${constructor(e,r){super(e);this.options=r}};S();var j=class extends d{constructor(e,r){super(e);this.id=e;this.type=r;this.type=r}};var k=class extends j{constructor(e,r){super(e,"unlit");this.id=e;this.options=r}updateProperties(e){return new pt(this,e).execute()}};var J=class extends d{constructor(e,r){super(e);this.id=e;this.options=r}};async function $e(i){let t=await new St(i?.name).execute();if(t.success){let{id:e}=t.data;return new D(e,i)}else throw new Error("createSpatialEntity failed:"+t?.errorMessage)}async function z(i,t){let e=await new Et(i.type,t).execute();if(e.success){let{id:r}=e.data;return new i(r,t)}else throw new Error("createSpatialGeometry failed:"+e?.errorMessage)}async function Fe(i){let t=await new bt(i).execute();if(t.success){let{id:e}=t.data;return new k(e,i)}else throw new Error("createSpatialUnlitMaterial failed:"+t?.errorMessage)}async function je(i){let t=await new gt(i).execute();if(t.success){let{id:e}=t.data;return new F(e,i)}else throw new Error("createModelComponent failed:"+t?.errorMessage)}async function ke(i,t){let e=await new ft(i).execute();if(e.success){let{id:r}=e.data;return new B(r,i,t)}else throw new Error("createSpatialModelEntity failed:"+e?.errorMessage)}async function Je(i){let t=await new ht(i).execute();if(t.success){let{id:e}=t.data;return new J(e,i)}else throw new Error("createModelAsset failed:"+t?.errorMessage)}var f=class extends d{constructor(e,r){super(e);this.id=e;this.options=r}static type};var N=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="BoxGeometry"};var H=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="SphereGeometry"};var q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="CylinderGeometry"};var Q=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="PlaneGeometry"};var K=class extends f{constructor(e,r){super(e,r);this.id=e;this.options=r}static type="ConeGeometry"};var W=class{getSpatialScene(){return w.getInstance()}createSpatialized2DElement(){return Ue()}createSpatializedStatic3DElement(t){return Le(t)}initScene=Ge;createSpatializedDynamic3DElement(){return Be()}createEntity(t){return $e(t)}createBoxGeometry(t={}){return z(N,t)}createPlaneGeometry(t={}){return z(Q,t)}createSphereGeometry(t={}){return z(H,t)}createConeGeometry(t){return z(K,t)}createCylinderGeometry(t){return z(q,t)}createModelComponent(t){return je(t)}createUnlitMaterial(t){return Fe(t)}createModelAsset(t){return Je(t)}createSpatialModelEntity(t,e){return ke(t,e)}createAttachmentEntity(t){return le(t)}};v();var A=class{wsAppShellVersionFromUA;requestSession(){return this.runInSpatialWeb()?(c.init(),new W):null}runInSpatialWeb(){return navigator.userAgent.indexOf("WebSpatial/")>0}getShellVersionFromUA(){if(this.wsAppShellVersionFromUA!==void 0)return this.wsAppShellVersionFromUA;if(typeof navigator>"u"||typeof navigator.userAgent!="string")return this.wsAppShellVersionFromUA=null,null;let t=navigator.userAgent.match(/WSAppShell\/(\d+(?:\.\d+){2}(?:[-+][0-9A-Za-z.-]+)*)/);return this.wsAppShellVersionFromUA=t?t[1]:"1.3.0",this.wsAppShellVersionFromUA}isSupported(){return!0}getNativeVersion(){return window.__WebSpatialData&&window.__WebSpatialData.getNativeVersion?window.__WebSpatialData.getNativeVersion():window.WebSpatailNativeVersion==="WS_SHELL_VERSION"?this.getClientVersion():window.WebSpatailNativeVersion}getClientVersion(){return"1.5.0"}};var de={};R(de,{getValue:()=>gi,physicalToPoint:()=>Si,pointToPhysical:()=>yi,subscribe:()=>fi});v();var x={meterToPtUnscaled:1360,meterToPtScaled:1360};function Ne(i){return i?.worldScalingCompensation??"scaled"}function yi(i,t){return ce(),Ne(t)==="unscaled"?i/x.meterToPtUnscaled:i/x.meterToPtScaled}function Si(i,t){return ce(),Ne(t)==="unscaled"?i*x.meterToPtUnscaled:i*x.meterToPtScaled}function ce(){if(typeof window>"u")return;let i=window.__webspatialsdk__?.physicalMetrics;if(!i)return;let t={meterToPtScaled:i.meterToPtScaled??x.meterToPtScaled,meterToPtUnscaled:i.meterToPtUnscaled??x.meterToPtUnscaled};(t.meterToPtScaled!==x.meterToPtScaled||t.meterToPtUnscaled!==x.meterToPtUnscaled)&&(x=t)}function gi(){return ce(),x}function fi(i){if(typeof window>"u")return()=>{};let t=()=>{i()};return c.addEventReceiver("window",t),()=>{c.removeEventReceiver("window")}}kt();Zt();var He=new A,$t,Ut={backgroundMaterial:"--xr-background-material"},qe="";function Lt(i){i!==qe&&($t?.getSpatialScene()?.updateSpatialProperties({material:i}),qe=i)}function hi(){let t=getComputedStyle(document.documentElement).getPropertyValue(Ut.backgroundMaterial);Lt(t||"none")}var M={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function Qe(){let i=getComputedStyle(document.documentElement),t=Me(i);Ei(t)}function Ei(i){(M.topLeading!==i.topLeading||M.bottomLeading!==i.bottomLeading||M.topTrailing!==i.topTrailing||M.bottomTrailing!==i.bottomTrailing)&&($t?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),M.topLeading=i.topLeading,M.bottomLeading=i.bottomLeading,M.topTrailing=i.topTrailing,M.bottomTrailing=i.bottomTrailing)}function bi(i){$t?.getSpatialScene().updateSpatialProperties({opacity:i})}function Ke(){let i=getComputedStyle(document.documentElement),t=parseFloat(i.getPropertyValue("opacity"));bi(t)}function xi(){let i=document.documentElement.style,t=new Proxy(i,{set:function(e,r,n){let a=Reflect.set(e,r,n);return r===Ut.backgroundMaterial&&Lt(n),(r==="border-radius"||r==="borderRadius"||r==="border-top-left-radius"||r==="borderTopLeftRadius"||r==="border-top-right-radius"||r==="borderTopRightRadius"||r==="border-bottom-left-radius"||r==="borderBottomLeftRadius"||r==="border-bottom-right-radius"||r==="borderBottomRightRadius")&&Qe(),r==="opacity"&&Ke(),a},get:function(e,r){return typeof e[r]=="function"?function(...n){if(r==="setProperty"){let[a,o]=n;a===Ut.backgroundMaterial&&Lt(o)}else if(r==="removeProperty"){let[a]=n;a===Ut.backgroundMaterial&&Lt("none")}return e[r](...n)}:Reflect.get(e,r)}});Object.defineProperty(document.documentElement,"style",{get:function(){return t}})}function wi(){new MutationObserver(Bt).observe(document.head,{childList:!0,subtree:!0})}function Bt(){hi(),Qe(),Ke()}function vi(){new MutationObserver(t=>{t.forEach(e=>{e.type==="attributes"&&e.attributeName&&Bt()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function Xe(){He.runInSpatialWeb()&&($t=await He.requestSession(),document.readyState==="complete"?Bt():window.addEventListener("load",()=>{Bt()}),xi(),wi(),vi())}!G()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(_e(),Xe());return V(Pi);})();
|
|
75
75
|
//# sourceMappingURL=index.global.js.map
|