@webspatial/core-sdk 1.0.3 → 1.0.5
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 +4 -0
- package/README.md +112 -81
- package/dist/iife/index.d.ts +683 -561
- package/dist/iife/index.global.js +3 -4
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +683 -561
- package/dist/index.js +2175 -1291
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/src/JSBCommand.ts +631 -0
- package/src/Spatial.ts +68 -0
- package/src/SpatialObject.ts +46 -0
- package/src/SpatialScene.ts +75 -0
- package/src/SpatialSession.ts +187 -0
- package/src/SpatialWebEvent.ts +23 -0
- package/src/SpatialWebEventCreator.ts +12 -0
- package/src/Spatialized2DElement.ts +51 -0
- package/src/SpatializedDynamic3DElement.ts +30 -0
- package/src/SpatializedElement.ts +331 -0
- package/src/SpatializedElementCreator.ts +45 -0
- package/src/SpatializedStatic3DElement.ts +111 -0
- package/src/WebMsgCommand.ts +88 -0
- package/src/index.ts +23 -1
- package/src/platform-adapter/CommandResultUtils.ts +22 -0
- package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
- package/src/platform-adapter/index.ts +21 -0
- package/src/platform-adapter/interface.ts +36 -0
- package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
- package/src/reality/component/ModelComponent.ts +11 -0
- package/src/reality/component/SpatialComponent.ts +17 -0
- package/src/reality/component/index.ts +2 -0
- package/src/reality/entity/SpatialEntity.ts +255 -0
- package/src/reality/entity/SpatialModelEntity.ts +15 -0
- package/src/reality/entity/index.ts +2 -0
- package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
- package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
- package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
- package/src/reality/geometry/SpatialGeometry.ts +12 -0
- package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
- package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
- package/src/reality/geometry/index.ts +6 -0
- package/src/reality/index.ts +5 -0
- package/src/reality/material/SpatialMaterial.ts +14 -0
- package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
- package/src/reality/material/index.ts +2 -0
- package/src/reality/realityCreator.ts +94 -0
- package/src/reality/resource/SpatialModelAsset.ts +11 -0
- package/src/reality/resource/index.ts +1 -0
- package/src/scene-polyfill.test.ts +376 -0
- package/src/scene-polyfill.ts +359 -0
- package/src/spatial-window-polyfill.ts +182 -0
- package/src/ssr-polyfill.ts +3 -0
- package/src/types/global.d.ts +33 -1
- package/src/types/internal.ts +13 -0
- package/src/types/types.ts +380 -0
- package/src/utils.ts +61 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +8 -0
- package/src/core/Spatial.ts +0 -50
- package/src/core/SpatialEntity.ts +0 -147
- package/src/core/SpatialHelper.ts +0 -230
- package/src/core/SpatialObject.ts +0 -26
- package/src/core/SpatialSession.ts +0 -457
- package/src/core/SpatialTransform.ts +0 -26
- package/src/core/SpatialWindowContainer.ts +0 -59
- package/src/core/component/EventSpatialComponent.ts +0 -32
- package/src/core/component/SpatialComponent.ts +0 -26
- package/src/core/component/SpatialInputComponent.ts +0 -24
- package/src/core/component/SpatialModel3DComponent.ts +0 -223
- package/src/core/component/SpatialModelComponent.ts +0 -39
- package/src/core/component/SpatialViewComponent.ts +0 -32
- package/src/core/component/SpatialWindowComponent.ts +0 -177
- package/src/core/component/index.ts +0 -14
- package/src/core/index.ts +0 -10
- package/src/core/private/WebSpatial.ts +0 -383
- package/src/core/private/remote-command/RemoteCommand.ts +0 -15
- package/src/core/private/remote-command/index.ts +0 -1
- package/src/core/resource/SpatialMeshResource.ts +0 -6
- package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
- package/src/core/resource/index.ts +0 -2
- package/src/core/types.ts +0 -32
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['core-sdk-version'] = "1.0.
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.0.5"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
|
-
"use strict";var webspatialCore=(()=>{var B=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var j=(i,e)=>{for(var t in e)B(i,t,{get:e[t],enumerable:!0})},q=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of N(e))!k.call(i,r)&&r!==t&&B(i,r,{get:()=>e[r],enumerable:!(n=A(e,r))||n.enumerable});return i};var z=i=>q(B({},"__esModule",{value:!0}),i);var F={};j(F,{Spatial:()=>P,SpatialComponent:()=>l,SpatialEntity:()=>w,SpatialHelper:()=>M,SpatialInputComponent:()=>I,SpatialMeshResource:()=>W,SpatialModel3DComponent:()=>x,SpatialModelComponent:()=>E,SpatialPhysicallyBasedMaterialResource:()=>D,SpatialSession:()=>_,SpatialTransform:()=>R,SpatialViewComponent:()=>S,SpatialWindowComponent:()=>h,SpatialWindowContainer:()=>g,Vec3:()=>v,Vec4:()=>V});var d=class i{static requestCounter=0;command;data;requestID;constructor(e,t){this.command=e,this.data=t,this.requestID=++i.requestCounter}};var L=class{id=""},m=class{id="";windowContainerId="";data={};receiveEvent(){}},a=class i{static eventPromises={};static transactionStarted=!1;static transactionCommands=Array();static eventReceivers={};static registerEventReceiver(e,t){this.eventReceivers[e]=t}static unregisterEventReceiver(e){delete this.eventReceivers[e]}static init(){window.__SpatialWebEvent=e=>{if(e.resourceId){var t=i.eventReceivers[e.resourceId];t(e.data)}else{var n=i.eventPromises[e.requestID];n&&(e.success?n.res(e):n.rej(e))}}}static startTransaction(){i.transactionStarted=!0,i.transactionCommands=[]}static async sendTransaction(){i.transactionStarted=!1;var e=new d("multiCommand",{commandList:i.transactionCommands}),t=await new Promise((n,r)=>{i.eventPromises[e.requestID]={res:n,rej:r},i.sendCommand(e)});return t}static getBackend(){return window.webkit?"AVP":"UNKNOWN"}static async sendCommand(e){if(!window.__WebSpatialUnloaded){if(i.transactionStarted){i.transactionCommands.push(e);return}var t=JSON.stringify(e);if(i.getBackend()=="AVP"){window.webkit.messageHandlers.bridge.postMessage(t);return}else{window.__WebSpatialData.androidNativeMessage(t);return}}}static getImmersiveWindowContainer(){var e=new L;return e.id="Immersive",e}static getCurrentWindowContainer(){var e=new L;return e.id="current",e}static getCurrentWebPanel(){var e=new m;return e.id="current",e.windowContainerId=i.getCurrentWindowContainer().id,e}static async createScene(e="Plain",t){let{window:n,...r}=t.sceneData,o={...r,windowID:n._webSpatialID,windowContainerID:n._webSpatialGroupID};var s=new d("createScene",{windowStyle:e,sceneData:o,windowContainerID:window._webSpatialParentGroupID});try{return await new Promise((c,u)=>{i.eventPromises[s.requestID]={res:c,rej:u},i.sendCommand(s)}),!0}catch{return!1}}static async createWindowContainer(e="Plain",t,n){var r=new d("createWindowContainer",{windowStyle:e,windowContainerID:t?t.id:void 0,resourceID:n?n.id:void 0}),o=await new Promise((c,u)=>{i.eventPromises[r.requestID]={res:c,rej:u},i.sendCommand(r)}),s=new L;return s.id=o.data.createdID,s}static async destroyResource(e){let t={};var n=new d("destroyResource",{windowContainerID:e.windowContainerId,resourceID:e.id});i.sendCommand(n)}static async ping(e){var t=new d("ping",{windowContainerID:this.getCurrentWindowContainer().id,resourceID:this.getCurrentWebPanel().id,message:e});if(i.transactionStarted)return i.sendCommand(t),null;var n=await new Promise((r,o)=>{i.eventPromises[t.requestID]={res:r,rej:o},i.sendCommand(t)});return n}static async getStats(){var e=new d("getStats",{windowContainerID:this.getCurrentWindowContainer().id,resourceID:this.getCurrentWebPanel().id}),t=await new Promise((n,r)=>{i.eventPromises[e.requestID]={res:n,rej:r},i.sendCommand(e)});return t.data}static async inspect(e){var t=new d("inspect",{resourceID:e}),n=await new Promise((r,o)=>{i.eventPromises[t.requestID]={res:r,rej:o},i.sendCommand(t)});return n.data}static async inspectRootWindowContainer(){return this.inspect("root")}static async setComponent(e,t){var n=new d("setComponent",{windowContainerID:e.windowContainerId,resourceID:t.id,entityID:e.id});i.sendCommand(n)}static async removeComponent(e,t){var n=new d("removeComponent",{windowContainerID:e.windowContainerId,resourceID:t.id,entityID:e.id});i.sendCommand(n)}static async createResource(e,t,n,r={}){var o=new d("createResource",{windowContainerID:t?t.id:void 0,resourceID:n?n.id:void 0,type:e,params:r}),s=await new Promise((u,p)=>{i.eventPromises[o.requestID]={res:u,rej:p},i.sendCommand(o)}),c=new m;return c.id=s.data.createdID,c.windowContainerId=o.data.windowContainerID,c}static async updateWindowContainer(e,t){var n=new d("updateWindowContainer",{windowContainerID:e.id,update:t}),r=await new Promise((o,s)=>{i.eventPromises[n.requestID]={res:o,rej:s},i.sendCommand(n)});return r}static async updateResource(e,t=null){var n=new d("updateResource",{windowContainerID:e.windowContainerId,resourceID:e.id,update:t||e.data}),r=await new Promise((o,s)=>{i.eventPromises[n.requestID]={res:o,rej:s},i.sendCommand(n)});return r}static async setLoading(e,t){var n=new d("setLoading",{windowContainerID:window._webSpatialParentGroupID,loading:{method:e,style:t}}),r=await new Promise((o,s)=>{i.eventPromises[n.requestID]={res:o,rej:s},i.sendCommand(n)});return r}static async openImmersiveSpace(){var e=new d("openImmersiveSpace");await i.sendCommand(e)}static async dismissImmersiveSpace(){var e=new d("dismissImmersiveSpace");await i.sendCommand(e)}static onFrame(e){var t=0,n=async()=>{var r=window.performance.now();await e(r);var o=window.performance.now()-r;setTimeout(()=>{n()},Math.max(1e3/60-o,0))};n()}};a.init();var y=class{constructor(e){this._resource=e}async destroy(){await a.destroyResource(this._resource),await this.onDestroy()}name="";async onDestroy(){}};var v=class{constructor(e=0,t=0,n=0){this.x=e;this.y=t;this.z=n}},V=class{constructor(e=0,t=0,n=0,r=1){this.x=e;this.y=t;this.z=n;this.w=r}},R=class{position=new v(0,0,0);orientation=new V(0,0,0,1);scale=new v(1,1,1)};var w=class extends y{transform=new R;_destroyed=!1;get _entity(){return this._resource}async updateTransform(){await a.updateResource(this._entity,this.transform)}async updateZIndex(e){await a.updateResource(this._entity,{zIndex:e})}components=new Map;async setComponent(e){await a.setComponent(this._entity,e._resource),this.components.set(e.constructor,e)}async removeComponent(e){var t=this.getComponent(e);t!=null&&(await a.removeComponent(this._entity,t._resource),this.components.delete(t.constructor))}getComponent(e){return this.components.get(e)}async _setParentWindowContainer(e){await a.updateResource(this._entity,{setParentWindowContainerID:e._wg.id})}async setParent(e){await a.updateResource(this._entity,{setParent:e?e._entity.id:""})}async setCoordinateSpace(e){await a.updateResource(this._entity,{setCoordinateSpace:e})}async getBoundingBox(){var e=await a.updateResource(this._entity,{getBoundingBox:!0});return e.data}async setVisible(e){await a.updateResource(this._entity,{visible:e})}async destroy(){this._destroyed=!0,await a.destroyResource(this._entity)}isDestroyed(){return this._destroyed}async _setName(e){return this.name=e,a.updateResource(this._entity,{name:e})}};var l=class extends y{async getEntity(){let e=await a.updateResource(a.getCurrentWebPanel(),{getEntityID:""});if(e.data.parentID==="")return new Promise((n,r)=>{n(null)});var t=new m;return t.id=e.data.parentID,new w(t)}};var g=class{constructor(e){this._wg=e}async _setOpenSettings(e){await a.updateWindowContainer(this._wg,{nextOpenSettings:e})}async getRootEntity(){let e=await a.updateWindowContainer(this._wg,{getRootEntityID:""});if(e.data.rootEntId==="")return null;var t=new m;return t.id=e.data.rootEntId,new w(t)}async setRootEntity(e){await e._setParentWindowContainer(this)}async close(){await a.updateWindowContainer(this._wg,{close:!0})}};var W=class extends y{};var D=class extends y{baseColor={r:0,g:.7,b:.7,a:1};metallic={value:.5};roughness={value:.5};_modelComponentAttachedTo={};_addToComponent(e){this._modelComponentAttachedTo[e._resource.id]=e}async update(){await a.updateResource(this._resource,{baseColor:this.baseColor,metallic:this.metallic,roughness:this.roughness});for(var e in this._modelComponentAttachedTo)await this._modelComponentAttachedTo[e]._syncMaterials()}};function C(i){var e=null;i?.windowContainer!==null&&(e=i?.windowContainer?i?.windowContainer._wg:a.getCurrentWindowContainer());var t=null;return i?.windowComponent!==null&&(t=i?.windowComponent?i?.windowComponent._resource:a.getCurrentWebPanel()),[e,t]}var _=class i{_engineUpdateListeners=Array();_frameLoopStarted=!1;addOnEngineUpdateEventListener(e){this._engineUpdateListeners.push(e),this._frameLoopStarted||(this._frameLoopStarted=!0,a.onFrame(async t=>{await Promise.all(this._engineUpdateListeners.map(n=>n(t)))}))}async createEntity(e){var[t,n]=C(e);let r=await a.createResource("Entity",t,n);return new w(r)}async createWindowComponent(e){var[t,n]=C(e);let r=await a.createResource("SpatialWebView",t,n);return new h(r)}async createViewComponent(e){var[t,n]=C(e);let r=await a.createResource("SpatialView",t,n);return new S(r)}async createModelComponent(e){var[t,n]=C(e),r=void 0;e&&(r={modelURL:e.url});let o=await a.createResource("ModelComponent",t,n,r);return new E(o)}async createModel3DComponent(e){var[t,n]=C(e),r=void 0;e&&(r={modelURL:e.url});let o=await a.createResource("Model3DComponent",t,n,r);return new x(o)}async createInputComponent(e){var[t,n]=C(e);let r=await a.createResource("InputComponent",t,n);return new I(r)}async createMeshResource(e){var[t,n]=C(e);let r=await a.createResource("MeshResource",t,n,e);return new W(r)}async createPhysicallyBasedMaterialResource(e){var[t,n]=C(e);let r=await a.createResource("PhysicallyBasedMaterial",t,n,e);return new D(r)}async createWindowContainer(e){var t=e?.style?e?.style:"Plain",[n,r]=C(e);return new g(await a.createWindowContainer(t,n,r))}async _createScene(e="Plain",t){return await a.createScene(e,t)}getCurrentWindowComponent(){return new h(a.getCurrentWebPanel())}async getParentWindowComponent(){let e=await a.updateResource(a.getCurrentWebPanel(),{getParentID:""});if(e.data.parentID==="")return new Promise((n,r)=>{n(null)});var t=new m;return t.id=e.data.parentID,new h(t)}async log(...e){await a.sendCommand(new d("log",{logString:e.map(t=>JSON.stringify(t))}))}async _ping(e){return await a.ping(e)}async _getStats(){return await a.getStats()}async _inspect(e=a.getCurrentWebPanel().id){return a.inspect(e)}async _inspectRootWindowContainer(){return a.inspectRootWindowContainer()}async openImmersiveSpace(){return await a.openImmersiveSpace()}async dismissImmersiveSpace(){return await a.dismissImmersiveSpace()}static _immersiveWindowContainer=null;async getImmersiveWindowContainer(){return i._immersiveWindowContainer||(i._immersiveWindowContainer=new g(a.getImmersiveWindowContainer())),i._immersiveWindowContainer}static _currentWindowContainer=null;getCurrentWindowContainer(){return i._currentWindowContainer||(i._currentWindowContainer=new g(a.getCurrentWindowContainer())),i._currentWindowContainer}transaction(e){return a.startTransaction(),e(),a.sendTransaction()}async createWindowContext(){let e=window.open("webspatial://createWindowContext");if(a.getBackend()!="AVP"){for(var t=0;e.window.testAPI==null;){t>15&&(e?.close(),e=window.open("about:blank"),t=0,this.log("unexpected error when trying to open new window, retrying."));var n="about:blank?x"+t;e.location.href=n,t++,await new Promise(r=>setTimeout(r,10))}e._webSpatialID=e.window.testAPI.getWindowID()}else for(;e.window._webSpatialID==null;)await new Promise(r=>setTimeout(r,10));return e.document.head.innerHTML=`<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
-
<base href="${document.baseURI}">
|
|
10
|
-
`,e}async _getEntity(e){let t=await a.inspect(e),[n,r,o,s]=t.position.match(/(\d+\.?\d*)/g),[c,u,p,O]=t.scale.match(/(\d+\.?\d*)/g);var b=new m;b.id=e,b.windowContainerId=a.getCurrentWindowContainer().id;let f=new w(b);return f.transform.position.x=parseFloat(r),f.transform.position.y=parseFloat(o),f.transform.position.z=parseFloat(s),f.transform.scale.x=parseFloat(u),f.transform.scale.y=parseFloat(p),f.transform.scale.z=parseFloat(O),f}async setLoading(e,t){return a.setLoading(e,t)}};var P=class{requestSession(){return this.isSupported()&&this.getNativeVersion()===this.getClientVersion()?new _:null}isSupported(){return this.getNativeVersion()===this.getClientVersion()}getNativeVersion(){return window.__WebSpatialData&&window.__WebSpatialData.getNativeVersion?window.__WebSpatialData.getNativeVersion():window.WebSpatailNativeVersion==="PACKAGE_VERSION"?this.getClientVersion():window.WebSpatailNativeVersion}getClientVersion(){return"1.0.3"}};var M=class i{constructor(e){this.session=e}static _instance=null;static get instance(){if(this._instance)return this._instance;{let e=new P;if(e.isSupported()){let t=e.requestSession();if(t)return this._instance=new i(t),this._instance}}return null}shape={createShapeEntity:async(e="box")=>{var t=await this.session.createMeshResource({shape:e}),n=await this.session.createPhysicallyBasedMaterialResource();await n.update();var r=await this.session.createModelComponent();r.setMaterials([n]),r.setMesh(t);var o=await this.session.createEntity();return await o.setComponent(r),o.transform.position.z=0,o.transform.scale=new v(.5,.5,.5),await o.updateTransform(),o},createModelEntity:async e=>{var t=await this.session.createModelComponent({url:e}),n=await this.session.createEntity();return await n.setComponent(t),await n.updateTransform(),n},wrapInBoundingBoxEntity:async e=>{var t=await e.getBoundingBox(),n=1,r=n/Math.max(t.extents.x,t.extents.y,t.extents.z);e.transform.scale.x=r,e.transform.scale.y=r,e.transform.scale.z=r,e.transform.position.x=-t.center.x*r,e.transform.position.y=-t.center.y*r,e.transform.position.z=-t.center.z*r,await e.updateTransform();var o=await i.instance?.session.createEntity();return await e.setParent(o),o}};navigation={openPanel:async(e,t)=>{t?.resolution&&await this.session.getCurrentWindowContainer()._setOpenSettings({resolution:t.resolution});var n=await this.session.createWindowContainer({style:"Plain",windowComponent:null,windowContainer:null}),r=await this.session.createEntity({windowComponent:null,windowContainer:n}),o=await this.session.createWindowComponent({windowComponent:null,windowContainer:n});return await o.loadURL(e),await r.setCoordinateSpace("Root"),await r.setComponent(o),await n.setRootEntity(r),await this.session.getCurrentWindowContainer()._setOpenSettings({resolution:{width:900,height:700}}),{windowContainer:n}},openVolume:async(e,t)=>{var n=await this.session.createWindowContainer({style:"Volumetric",windowComponent:null,windowContainer:null}),r=await this.session.createEntity({windowComponent:null,windowContainer:n});await r.setComponent(await this.session.createViewComponent({windowComponent:null,windowContainer:n})),await r.setCoordinateSpace("Root"),await n.setRootEntity(r);var o=await this.session.createEntity({windowComponent:null,windowContainer:n}),s=await this.session.createWindowComponent({windowComponent:null,windowContainer:n});await s.loadURL(e),t?.resolution?await s.setResolution(t.resolution.width,t.resolution.height):await s.setResolution(1e3,1e3),o.transform.position.z=-.49,await o.updateTransform(),await o.setCoordinateSpace("App"),await o.setComponent(s),await o.setParent(r)}};dom={attachSpatialView:async e=>{var t=await this.session.createEntity();await t.setCoordinateSpace("Dom"),await t.setComponent(await this.session.createViewComponent());var n=await this.session.getCurrentWindowComponent(),r=await n.getEntity();await t.setParent(r);var o=()=>{var p=e.getBoundingClientRect();t.transform.position.x=p.x+p.width/2,t.transform.position.y=p.y+p.height/2+window.scrollY,t.updateTransform(),t.getComponent(S).setResolution(p.width,p.height)},s=new MutationObserver(o);s.observe(e,{attributes:!0});var c=new ResizeObserver(o);return c.observe(e),new MutationObserver(p=>{p.forEach(O=>{O.removedNodes.forEach(b=>{b instanceof HTMLElement&&o()}),O.addedNodes.forEach(b=>{b instanceof HTMLElement&&o()})})}).observe(document.body,{childList:!0,subtree:!0}),o(),{entity:t}}};setBackgroundStyle=async(e,t="#00000000")=>{document.documentElement.style.backgroundColor=t,await this.session.getCurrentWindowComponent().setStyle(e)}};var h=class extends l{async loadURL(e){await a.updateResource(this._resource,{url:e})}async setFromWindow(e){e._webSpatialID?await a.updateResource(this._resource,{windowID:e._webSpatialID}):await console.warn("failed to call setFromWindow, window provided is not valid")}async setResolution(e,t){await a.updateResource(this._resource,{resolution:{x:e,y:t}})}async setRotationAnchor(e){await a.updateResource(this._resource,{rotationAnchor:e})}async setOpacity(e){await a.updateResource(this._resource,{opacity:e})}async setStyle(e){let n=M.instance?.session.getCurrentWindowComponent()?._resource.id==this._resource.id,{material:r,cornerRadius:o}=e,s={};if(r?.type&&(s.backgroundMaterial=r.type),o!==void 0&&(typeof o=="number"?s.cornerRadius={topLeading:o,bottomLeading:o,topTrailing:o,bottomTrailing:o}:s.cornerRadius={...o}),n&&document&&document.readyState=="loading"){var c=encodeURIComponent(JSON.stringify(s));let u=document.createElement("a");u.href="forcestyle://mystyle.css?style="+c,document.body.appendChild(u),u.click(),u.remove()}else await a.updateResource(this._resource,{style:s})}async setScrollEdgeInsets(e){await a.updateResource(this._resource,{setScrollEdgeInsets:e})}async setScrollEnabled(e){await a.updateResource(this._resource,{scrollEnabled:e})}async setScrollWithParent(e){await a.updateResource(this._resource,{scrollWithParent:e})}};var T=class extends l{constructor(e){super(e),a.registerEventReceiver(e.id,t=>{this.onRecvEvent(t)})}async onDestroy(){a.unregisterEventReceiver(this._resource.id)}};var I=class extends T{onRecvEvent(e){this.onTranslate(e)}onTranslate(e){}};var E=class extends l{cachedMaterials=new Array;async setMesh(e){await a.updateResource(this._resource,{meshResource:e._resource.id})}async setMaterials(e){this.cachedMaterials=e,await a.updateResource(this._resource,{materials:e.map(t=>(t._addToComponent(this),t._resource.id))})}async _syncMaterials(){await this.setMaterials(this.cachedMaterials)}};var S=class extends l{async setResolution(e,t){await a.updateResource(this._resource,{resolution:{x:e,y:t}})}async setIsPortal(e){await a.updateResource(this._resource,{isPortal:e})}};var x=class extends T{onRecvEvent(e){let{eventType:t,value:n,error:r}=e;switch(t){case"phase":n==="success"?this.onSuccess?.():this.onFailure?.(r);break;case"dragstart":this._onDragStart?.(n);break;case"dragend":this._onDragEnd?.(n);break;case"drag":this._onDrag?.(n);break;case"tap":this._onTap?.();break;case"doubletap":this._onDoubleTap?.();break;case"longpress":this._onLongPress?.();break;default:break}}async setResolution(e,t){await a.updateResource(this._resource,{resolution:{x:e,y:t}})}async setRotationAnchor(e){await a.updateResource(this._resource,{rotationAnchor:e})}async setOpacity(e){await a.updateResource(this._resource,{opacity:e})}async setContentMode(e){await a.updateResource(this._resource,{contentMode:e})}async setAspectRatio(e){await a.updateResource(this._resource,{aspectRatio:e})}async setScrollWithParent(e){await a.updateResource(this._resource,{scrollWithParent:e})}async setResizable(e){await a.updateResource(this._resource,{resizable:e})}onSuccess;onFailure;_onDragStart;set onDragStart(e){this._onDragStart!==e&&(this._onDragStart=e,a.updateResource(this._resource,{enableDragEvent:this.enableDragEvent}))}_onDrag;set onDrag(e){this._onDrag!==e&&(this._onDrag=e,a.updateResource(this._resource,{enableDragEvent:this.enableDragEvent}))}_onDragEnd;set onDragEnd(e){this._onDragEnd!==e&&(this._onDragEnd=e,a.updateResource(this._resource,{enableDragEvent:this.enableDragEvent}))}get enableDragEvent(){return this._onDrag!==void 0||this._onDragStart!==void 0||this._onDragEnd!==void 0}_onTap;set onTap(e){this._onTap!==e&&(this._onTap=e,a.updateResource(this._resource,{enableTapEvent:e!==void 0}))}_onDoubleTap;set onDoubleTap(e){this._onDoubleTap!==e&&(this._onDoubleTap=e,a.updateResource(this._resource,{enableDoubleTapEvent:e!==void 0}))}_onLongPress;set onLongPress(e){this._onLongPress!==e&&(this._onLongPress=e,a.updateResource(this._resource,{enableLongPressEvent:e!==void 0}))}};return z(F);})();
|
|
8
|
+
"use strict";var webspatialCore=(()=>{var zt=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var f=(i,e)=>()=>(i&&(e=i(i=0)),e);var Gt=(i,e)=>{for(var t in e)zt(i,t,{get:e[t],enumerable:!0})},Ve=(i,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ge(e))!Ie.call(i,r)&&r!==t&&zt(i,r,{get:()=>e[r],enumerable:!(a=ze(e,r))||a.enumerable});return i};var It=i=>Ve(zt({},"__esModule",{value:!0}),i);var We,I,Vt=f(()=>{"use strict";We=typeof window>"u",I=()=>We});var H,Qt=f(()=>{"use strict";H=class{callJSB(e,t){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocol(e,t,a,r){return Promise.resolve({success:!0,data:void 0,errorCode:void 0,errorMessage:void 0})}callWebSpatialProtocolSync(e,t,a,r,n){return{success:!0,data:void 0,errorCode:void 0,errorMessage:void 0}}}});function g(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function M(i,e=""){return{success:!1,data:void 0,errorCode:i,errorMessage:e}}var Wt=f(()=>{"use strict"});var m,D=f(()=>{"use strict";m=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 Xt={};Gt(Xt,{AndroidPlatform:()=>Lt});function Ae(){return At=(At+1)%_e,`rId_${At}`}var _t,At,_e,Lt,Yt=f(()=>{"use strict";Wt();u();D();_t=0,At=0,_e=1e5;Lt=class{async callJSB(e,t){return new Promise((a,r)=>{try{let n=Ae();m.addEventReceiver(n,p=>{if(m.removeEventReceiver(n),p.success)a(g(p.data));else{let{code:c,message:x}=p.data;a(M(c,x))}});let o=window.webspatialBridge.postMessage(n,e,t);if(o!==""){m.removeEventReceiver(n);let p=JSON.parse(o);if(p.success)a(g(p.data));else{let{code:c,message:x}=p.data;a(M(c,x))}}}catch(n){console.error(`AndroidPlatform cmd: ${e}, msg: ${t} error: ${n}`);let{code:o,message:p}=n;a(M(o,p))}})}async callWebSpatialProtocol(e,t,a,r){await new Promise(c=>setTimeout(c,16*_t)),_t++;let n=await new V().execute();for(;!n.data.can;)await new Promise(c=>setTimeout(c,16)),n=await new V().execute();let{windowProxy:o}=this.openWindow(e,t,a,r);for(;!o?.open;)await new Promise(c=>setTimeout(c,16));for(o?.open("about:blank","_self");!o?.SpatialId;)await new Promise(c=>setTimeout(c,16));let p=o?.SpatialId;return _t--,Promise.resolve(g({windowProxy:o,id:p}))}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return g({windowProxy:o,id:n})}openWindow(e,t,a,r){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,a,r)}}}});var Zt={};Gt(Zt,{VisionOSPlatform:()=>Bt});var Bt,te=f(()=>{"use strict";Wt();Bt=class{async callJSB(e,t){try{let a=await window.webkit.messageHandlers.bridge.postMessage(`${e}::${t}`);return g(a)}catch(a){let{code:r,message:n}=JSON.parse(a.message);return M(r,n)}}callWebSpatialProtocol(e,t,a,r){let{spatialId:n,windowProxy:o}=this.openWindow(e,t,a,r);return Promise.resolve(g({windowProxy:o,id:n}))}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return g({windowProxy:o,id:n})}openWindow(e,t,a,r){let n=window.open(`webspatial://${e}?${t||""}`,a,r);return{spatialId:n?.navigator.userAgent?.match(/\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi)?.[0],windowProxy:n}}}});function ee(){if(I())return new H;if(window.navigator.userAgent.includes("Android")||window.navigator.userAgent.includes("Linux")){let i=(Yt(),It(Xt)).AndroidPlatform;return new i}else{let i=(te(),It(Zt)).VisionOSPlatform;return new i}}var ie=f(()=>{"use strict";Vt();Qt()});function q(i,e){return i===""?0:i.endsWith("%")?e*parseFloat(i)/100:parseFloat(i)}function ae(i){let e=parseFloat(i.getPropertyValue("width")),t=i.getPropertyValue("border-top-left-radius"),a=i.getPropertyValue("border-top-right-radius"),r=i.getPropertyValue("border-bottom-left-radius"),n=i.getPropertyValue("border-bottom-right-radius");return{topLeading:q(t,e),bottomLeading:q(r,e),topTrailing:q(a,e),bottomTrailing:q(n,e)}}function re(i,e,t){let{x:a,y:r,z:n}=i,{x:o,y:p,z:c}=e,{x,y:Ce,z:Oe}=t,v=new DOMMatrix;return v=v.translate(a,r,n),v=v.rotate(o,p,c),v=v.scale(x,Ce,Oe),v}var Ut=f(()=>{"use strict"});var jt,s,K,Q,X,Y,Z,tt,E,et,it,at,rt,nt,ot,st,pt,lt,ct,dt,mt,ut,yt,St,ft,w,gt,ht,Et,bt,xt,V,vt,wt,Pt,u=f(()=>{"use strict";ie();Ut();jt=ee(),s=class{commandType="";async execute(){let e=this.getParams(),t=e?JSON.stringify(e):"";return jt.callJSB(this.commandType,t)}},K=class extends s{constructor(t,a){super();this.entity=t;this.properties=a}commandType="UpdateEntityProperties";getParams(){let t=re(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}}},Q=class extends s{constructor(t,a,r){super();this.entity=t;this.type=a;this.isEnable=r}commandType="UpdateEntityEvent";getParams(){return{type:this.type,entityId:this.entity.id,isEnable:this.isEnable}}},X=class extends s{properties;commandType="UpdateSpatialSceneProperties";constructor(e){super(),this.properties=e}getParams(){return this.properties}},Y=class extends s{config;commandType="UpdateSceneConfig";constructor(e){super(),this.config=e}getParams(){return{config:this.config}}},Z=class extends s{constructor(t){super();this.id=t}commandType="FocusScene";getParams(){return{id:this.id}}},tt=class extends s{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},E=class extends s{constructor(t){super();this.spatialObject=t}getParams(){let t=this.getExtraParams();return{id:this.spatialObject.id,...t}}},et=class extends E{properties;commandType="UpdateSpatialized2DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},it=class extends E{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},at=class extends E{properties;commandType="UpdateUnlitMaterialProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},rt=class extends E{matrix;commandType="UpdateSpatializedElementTransform";constructor(e,t){super(e),this.matrix=t}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},nt=class extends E{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},ot=class extends E{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(e,t){super(e),this.spatializedElement=t}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},st=class extends s{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(e){super(),this.spatializedElement=e}getParams(){return{spatializedElementId:this.spatializedElement.id}}},pt=class extends s{constructor(t){super();this.modelURL=t;this.modelURL=t}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},lt=class extends s{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},ct=class extends s{constructor(t){super();this.name=t}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},dt=class extends s{constructor(t){super();this.options=t}getParams(){let t=this.options.mesh.id,a=this.options.materials.map(r=>r.id);return{geometryId:t,materialIds:a}}commandType="CreateModelComponent"},mt=class extends s{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ut=class extends s{constructor(t){super();this.options=t}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},yt=class extends s{constructor(t,a={}){super();this.type=t;this.options=a}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},St=class extends s{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateUnlitMaterial"},ft=class extends s{constructor(t,a){super();this.entity=t;this.comp=a}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},w=class extends s{constructor(t,a){super();this.childId=t;this.parentId=a}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},gt=class extends s{constructor(t,a,r){super();this.fromEntityId=t;this.toEntityId=a;this.fromPosition=r}getParams(){return{fromEntityId:this.fromEntityId,toEntityId:this.toEntityId,position:this.fromPosition}}commandType="ConvertFromEntityToEntity"},ht=class extends s{constructor(t,a){super();this.fromEntityId=t;this.position=a}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},Et=class extends s{constructor(t,a){super();this.entityId=t;this.position=a}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},bt=class extends s{constructor(t=""){super();this.id=t}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},xt=class extends s{constructor(t){super();this.id=t}commandType="Destroy";getParams(){return{id:this.id}}},V=class extends s{constructor(t=""){super();this.id=t}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},vt=class extends s{target;features;async execute(){let e=this.getQuery();return jt.callWebSpatialProtocol(this.commandType,e,this.target,this.features)}executeSync(){let e=this.getQuery();return jt.callWebSpatialProtocolSync(this.commandType,e,this.target,this.features)}getQuery(){let e,t=this.getParams();return t&&(e=Object.keys(t).map(a=>{let r=t[a],n=typeof r=="object"?JSON.stringify(r):r;return`${a}=${encodeURIComponent(n)}`}).join("&")),e}},wt=class extends vt{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Pt=class extends vt{constructor(t,a,r,n){super();this.url=t;this.config=a;this.target=r;this.features=n}commandType="createSpatialScene";getParams(){return{url:this.url,config:this.config}}}});var Qe={};Gt(Qe,{BaseplateVisibilityValues:()=>oe,CubeInfo:()=>W,ModelComponent:()=>L,Spatial:()=>G,SpatialBoxGeometry:()=>F,SpatialComponent:()=>A,SpatialConeGeometry:()=>J,SpatialCylinderGeometry:()=>N,SpatialEntity:()=>P,SpatialGeometry:()=>y,SpatialMaterial:()=>B,SpatialModelAsset:()=>j,SpatialModelEntity:()=>_,SpatialObject:()=>d,SpatialPlaneGeometry:()=>$,SpatialScene:()=>h,SpatialSceneState:()=>Ht,SpatialSceneValues:()=>le,SpatialSession:()=>z,SpatialSphereGeometry:()=>k,SpatialUnlitMaterial:()=>U,Spatialized2DElement:()=>T,SpatializedDynamic3DElement:()=>C,SpatializedElement:()=>S,SpatializedElementType:()=>ne,SpatializedStatic3DElement:()=>R,WorldAlignmentValues:()=>pe,WorldScalingValues:()=>se,isSSREnv:()=>I,isValidBaseplateVisibilityType:()=>kt,isValidSceneUnit:()=>Mt,isValidSpatialSceneType:()=>Jt,isValidWorldAlignmentType:()=>$t,isValidWorldScalingType:()=>Nt});u();var d=class{constructor(e){this.id=e}name;isDestroyed=!1;async inspect(){let e=await new bt(this.id).execute();if(e.success)return e.data;throw new Error(e.errorMessage)}async destroy(){if(this.isDestroyed)return;let e=await new xt(this.id).execute();if(e.success)return this.onDestroy(),this.isDestroyed=!0,e.data;if(this.isDestroyed)return;throw new Error(e.errorMessage)}onDestroy(){}};u();u();var Ft,h=class i extends d{static getInstance(){return Ft||(Ft=new i("")),Ft}async updateSpatialProperties(e){return new X(e).execute()}async addSpatializedElement(e){return new st(e).execute()}async updateSceneCreationConfig(e){return new Y(e).execute()}async getState(){return(await new tt().execute()).data.name}};var ne=(a=>(a[a.Spatialized2DElement=0]="Spatialized2DElement",a[a.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",a[a.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",a))(ne||{}),oe=["automatic","visible","hidden"];function kt(i){return oe.includes(i)}var se=["automatic","dynamic"];function Nt(i){return se.includes(i)}var pe=["adaptive","automatic","gravityAligned"];function $t(i){return pe.includes(i)}var le=["window","volume"];function Jt(i){return le.includes(i)}function Mt(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 Ht=(n=>(n.idle="idle",n.pending="pending",n.willVisible="willVisible",n.visible="visible",n.fail="fail",n))(Ht||{}),W=class{constructor(e,t){this.size=e;this.origin=t;this.size=e,this.origin=t}get x(){return this.origin.x}get y(){return this.origin.y}get z(){return this.origin.z}get width(){return this.size.width}get height(){return this.size.height}get depth(){return this.size.depth}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get back(){return this.z}get front(){return this.z+this.depth}};var Le={defaultSize:{width:1280,height:720}},Be={defaultSize:{width:.94,height:.94,depth:.94}},Ue="webspatial://",Dt=class i{originalOpen;static instance;static getInstance(){return i.instance||(i.instance=new i),i.instance}init(e){this.originalOpen=e.open.bind(e),e.open=this.open}configMap={};getConfig(e){if(!(e===void 0||!this.configMap[e]))return this.configMap[e]}open=(e,t,a)=>{if(e?.startsWith(Ue))return this.originalOpen(e,t,a);let r=`${window.location.protocol}//${window.location.host}`;if(e?.startsWith(r)||(e=r+e),t==="_self"||t==="_parent"||t==="_top")return this.originalOpen(e,t,a);let n=t?this.getConfig(t):void 0,p=new Pt(e,n,t,a).executeSync();typeof t=="string"&&this.configMap[t]&&delete this.configMap[t];let c=p.data?.id;return c&&new Z(c).execute(),p.data?.windowProxy};initScene(e,t,a){let r=a?.type??"window",n=Kt(r),o=t({...n}),[p,c]=ue(o,r);c.length>0&&console.warn(`initScene ${e} with errors: ${c.join(", ")}`),this.configMap[e]={...p,type:r}}};function ce(i){return i/1360}function de(i){return i*1360}function me(i,e,t){if(typeof i=="number")return t==="px"&&e==="px"||t==="m"&&e==="m"?i:t==="px"&&e==="m"?ce(i):t==="m"&&e==="px"?de(i):i;if(e==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return ce(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 de(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function ue(i,e){let t=Kt(e),a=[],r=e==="window";if(Jt(e)||a.push("sceneType"),i.defaultSize){let n=["width","height","depth"];for(let o of n)o in i.defaultSize&&(Mt(i.defaultSize[o])?i.defaultSize[o]=me(i.defaultSize[o],r?"px":"m",r?"px":"m"):(i.defaultSize[o]=t.defaultSize[o],a.push(`defaultSize.${o}`)))}if(i.resizability){let n=["minWidth","minHeight","maxWidth","maxHeight"];for(let o of n)o in i.resizability&&(Mt(i.resizability[o])?i.resizability[o]=me(i.resizability[o],"px",r?"px":"m"):(i.resizability[o]=void 0,a.push(`resizability.${o}`)))}return i.worldScaling&&(Nt(i.worldScaling)||(i.worldScaling="automatic",a.push("worldScaling"))),i.worldAlignment&&($t(i.worldAlignment)||(i.worldAlignment="automatic",a.push("worldAlignment"))),i.baseplateVisibility&&(kt(i.baseplateVisibility)||(i.baseplateVisibility="automatic",a.push("baseplateVisibility"))),[i,a]}function ye(i,e,t){return Dt.getInstance().initScene(i,e,t)}function je(i){Dt.getInstance().init(i)}function qt(i){i.document.onclick=function(e){let t=e.target,a=!1;for(;!a;){if(t&&t.tagName=="A")return!Fe(e);if(t&&t.parentElement)t=t.parentElement;else break}}}function Fe(i){let e=i.target;if(e.tagName==="A"){let t=e,a=t.target,r=t.href;if(a&&a!=="_self")return i.preventDefault(),window.open(r,a),!0}}function Kt(i){return i==="window"?Le:Be}async function ke(){if(!window.opener||await h.getInstance().getState()!=="pending")return;function e(t){document.readyState==="interactive"||document.readyState==="complete"?t():document.addEventListener("DOMContentLoaded",t)}e(async()=>{let t=Kt(window.xrCurrentSceneType??"window"),a=t;if(typeof window.xrCurrentSceneDefaults=="function")try{a=await window.xrCurrentSceneDefaults?.(t)}catch(p){console.error(p)}await new Promise((p,c)=>{setTimeout(()=>{p(null)},1e3)});let r=window.xrCurrentSceneType??"window",[n,o]=ue(a,r);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await h.getInstance().updateSceneCreationConfig({...n,type:r})})}function Se(){je(window),qt(window),ke()}u();u();u();D();function l(i,e){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:e})}var S=class extends d{constructor(t){super(t);this.id=t;m.addEventReceiver(t,this.onReceiveEvent.bind(this))}async updateTransform(t){return new rt(this,t).execute()}_cubeInfo;get cubeInfo(){return this._cubeInfo}_transform;_transformInv;get transform(){return this._transform}get transformInv(){return this._transformInv}onReceiveEvent(t){let{type:a}=t;if(a==="objectdestroy")this.isDestroyed=!0;else if(a==="cubeInfo"){let r=t;this._cubeInfo=new W(r.size,r.origin)}else if(a==="transform")this._transform=new DOMMatrix([t.detail.column0[0],t.detail.column0[1],t.detail.column0[2],0,t.detail.column1[0],t.detail.column1[1],t.detail.column1[2],0,t.detail.column2[0],t.detail.column2[1],t.detail.column2[2],0,t.detail.column3[0],t.detail.column3[1],t.detail.column3[2],1]),this._transformInv=this._transform.inverse();else if(a==="spatialtap"){let r=l("spatialtap",t.detail);this._onSpatialTap?.(r)}else if(a==="spatialdrag"){if(!this._isDragging){let n=l("spatialdragstart",t.detail);this._onSpatialDragStart?.(n)}this._isDragging=!0;let r=l("spatialdrag",t.detail);this._onSpatialDrag?.(r)}else if(a==="spatialdragend"){this._isDragging=!1;let r=l("spatialdragend",t.detail);this._onSpatialDragEnd?.(r)}else if(a==="spatialrotate"){if(!this._isRotating){let n=l("spatialrotatestart",t.detail);this._onSpatialRotateStart?.(n)}this._isRotating=!0;let r=l("spatialrotate",t.detail);this._onSpatialRotate?.(r)}else if(a==="spatialrotateend"){this._isRotating=!1;let r=l("spatialrotateend",t.detail);this._onSpatialRotateEnd?.(r)}else if(a==="spatialmagnify"){if(!this._isMagnify){let n=l("spatialmagnifystart",t.detail);this._onSpatialMagnifyStart?.(n)}this._isMagnify=!0;let r=l("spatialmagnify",t.detail);this._onSpatialMagnify?.(r)}else if(a==="spatialmagnifyend"){this._isMagnify=!1;let r=l("spatialmagnifyend",t.detail);this._onSpatialMagnifyEnd?.(r)}}_onSpatialTap;set onSpatialTap(t){this._onSpatialTap=t,this.updateProperties({enableTapGesture:t!==void 0})}_isDragging=!1;_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})}_isRotating=!1;_onSpatialRotateStart;set onSpatialRotateStart(t){this._onSpatialRotateStart=t,this.updateProperties({enableRotateStartGesture:this._onSpatialRotateStart!==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})}_isMagnify=!1;_onSpatialMagnifyStart;set onSpatialMagnifyStart(t){this._onSpatialMagnifyStart=t,this.updateProperties({enableMagnifyStartGesture: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(){m.removeEventReceiver(this.id)}};var T=class extends S{constructor(t,a){super(t);this.windowProxy=a;qt(a)}async updateProperties(t){return new et(this,t).execute()}async addSpatializedElement(t){return new ot(this,t).execute()}};u();var R=class extends S{_readyResolve;modelURL="";createReadyPromise(){return new Promise(e=>{this._readyResolve=e})}ready=this.createReadyPromise();async updateProperties(e){return e.modelURL!==void 0&&this.modelURL!==e.modelURL&&(this.modelURL=e.modelURL,this.ready=this.createReadyPromise()),new nt(this,e).execute()}onReceiveEvent(e){e.type==="modelloaded"?(this._onLoadCallback?.(),this._readyResolve?.(!0)):e.type==="modelloadfailed"?(this._onLoadFailureCallback?.(),this._readyResolve?.(!1)):super.onReceiveEvent(e)}_onLoadCallback;set onLoadCallback(e){this._onLoadCallback=e}_onLoadFailureCallback;set onLoadFailureCallback(e){this._onLoadFailureCallback=e}updateModelTransform(e){let t=Array.from(e.toFloat64Array());this.updateProperties({modelTransform:t})}};u();var C=class extends S{children=[];constructor(e){super(e)}async addEntity(e){let t=new w(e.id,this.id).execute();return this.children.push(e),e.parent=this,t}async updateProperties(e){return new it(this,e).execute()}};async function fe(){let i=await new wt().execute();if(i.success){let{id:e,windowProxy:t}=i.data;return t.document.head.innerHTML=`<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<base href="${document.baseURI}">`,new T(e,t)}else throw new Error("createSpatialized2DElement failed")}async function ge(i){let e=await new pt(i).execute();if(e.success){let{id:t}=e.data;return new R(t)}else throw new Error("createSpatializedStatic3DElement failed")}async function he(){let i=await new lt().execute();if(i.success){let{id:e}=i.data;return new C(e)}else throw new Error("createSpatializedDynamic3DElement failed")}u();u();u();D();var P=class i extends d{constructor(t,a){super(t);this.userData=a;m.addEventReceiver(t,this.onReceiveEvent)}position={x:0,y:0,z:0};rotation={x:0,y:0,z:0};scale={x:1,y:1,z:1};events={};children=[];parent=null;async addComponent(t){return new ft(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 a=await new w(t.id,this.id).execute();return this.children.push(t),t.parent=this,a}async removeFromParent(){let t=await new w(this.id,void 0).execute();return this.parent&&(this.parent.children=this.parent.children.filter(a=>a.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 K(this,t).execute()}async addEvent(t,a){if(this.events[t])this.events[t]=a;else try{await this.updateEntityEvent(t,!0),this.events[t]=a}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,a){return new Q(this,t,a).execute()}onReceiveEvent=t=>{let{type:a}=t;if(a==="objectdestroy")this.isDestroyed=!0;else if(a==="spatialtap"){let r=l("spatialtap",t.detail);this.dispatchEvent(r)}else if(a==="spatialdragstart"){let r=l("spatialdragstart",t.detail);this.dispatchEvent(r)}else if(a==="spatialdrag"){let r=l("spatialdrag",t.detail);this.dispatchEvent(r)}else if(a==="spatialdragend"){let r=l("spatialdragend",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotatestart"){let r=l("spatialrotatestart",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotate"){let r=l("spatialrotate",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotateend"){let r=l("spatialrotateend",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnifystart"){let r=l("spatialmagnifystart",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnify"){let r=l("spatialmagnify",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnifyend"){let r=l("spatialmagnifyend",t.detail);this.dispatchEvent(r)}};dispatchEvent(t){this.events[t.type]?.(t),t.bubbles&&!t.cancelBubble&&this.parent&&this.parent instanceof i&&this.parent.dispatchEvent(t)}onDestroy(){m.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,a,r){return new gt(t,a,r).execute()}async convertFromEntityToScene(t,a){return new ht(t,a).execute()}async convertFromSceneToEntity(t,a){return new Et(t,a).execute()}};var _=class extends P{constructor(t,a,r){super(t,r);this.id=t;this.options=a;this.userData=r}};D();var A=class extends d{constructor(e){super(e),m.addEventReceiver(e,this.onReceiveEvent)}onReceiveEvent=e=>{let{type:t}=e;t==="objectdestroy"&&(this.isDestroyed=!0)}};var L=class extends A{constructor(t,a){super(t);this.options=a}};u();var B=class extends d{constructor(t,a){super(t);this.id=t;this.type=a;this.type=a}};var U=class extends B{constructor(t,a){super(t,"unlit");this.id=t;this.options=a}updateProperties(t){return new at(this,t).execute()}};var j=class extends d{constructor(t,a){super(t);this.id=t;this.options=a}};async function Ee(i){let e=await new ct(i?.name).execute();if(e.success){let{id:t}=e.data;return new P(t,i)}else throw new Error("createSpatialEntity failed:"+e?.errorMessage)}async function O(i,e){let t=await new yt(i.type,e).execute();if(t.success){let{id:a}=t.data;return new i(a,e)}else throw new Error("createSpatialGeometry failed:"+t?.errorMessage)}async function be(i){let e=await new St(i).execute();if(e.success){let{id:t}=e.data;return new U(t,i)}else throw new Error("createSpatialUnlitMaterial failed:"+e?.errorMessage)}async function xe(i){let e=await new dt(i).execute();if(e.success){let{id:t}=e.data;return new L(t,i)}else throw new Error("createModelComponent failed:"+e?.errorMessage)}async function ve(i,e){let t=await new mt(i).execute();if(t.success){let{id:a}=t.data;return new _(a,i,e)}else throw new Error("createSpatialModelEntity failed:"+t?.errorMessage)}async function we(i){let e=await new ut(i).execute();if(e.success){let{id:t}=e.data;return new j(t,i)}else throw new Error("createModelAsset failed:"+e?.errorMessage)}var y=class extends d{constructor(t,a){super(t);this.id=t;this.options=a}static type};var F=class extends y{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="BoxGeometry"};var k=class extends y{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="SphereGeometry"};var N=class extends y{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="CylinderGeometry"};var $=class extends y{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="PlaneGeometry"};var J=class extends y{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="ConeGeometry"};var z=class{getSpatialScene(){return h.getInstance()}createSpatialized2DElement(){return fe()}createSpatializedStatic3DElement(e=""){return ge(e)}initScene=ye;createSpatializedDynamic3DElement(){return he()}createEntity(e){return Ee(e)}createBoxGeometry(e={}){return O(F,e)}createPlaneGeometry(e={}){return O($,e)}createSphereGeometry(e={}){return O(k,e)}createConeGeometry(e){return O(J,e)}createCylinderGeometry(e){return O(N,e)}createModelComponent(e){return xe(e)}createUnlitMaterial(e){return be(e)}createModelAsset(e){return we(e)}createSpatialModelEntity(e,t){return ve(e,t)}};D();var G=class{requestSession(){return this.runInSpatialWeb()?(m.init(),new z):null}runInSpatialWeb(){return navigator.userAgent.indexOf("WebSpatial/")>0}isSupported(){return!0}getNativeVersion(){return window.__WebSpatialData&&window.__WebSpatialData.getNativeVersion?window.__WebSpatialData.getNativeVersion():window.WebSpatailNativeVersion==="PACKAGE_VERSION"?this.getClientVersion():window.WebSpatailNativeVersion}getClientVersion(){return"1.0.5"}};Vt();Ut();var Pe=new G,Ot,Tt={backgroundMaterial:"--xr-background-material"},Me="";function Rt(i){i!==Me&&(Ot?.getSpatialScene()?.updateSpatialProperties({material:i}),Me=i)}function Ne(){let e=getComputedStyle(document.documentElement).getPropertyValue(Tt.backgroundMaterial);Rt(e||"none")}var b={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function De(){let i=getComputedStyle(document.documentElement),e=ae(i);$e(e)}function $e(i){(b.topLeading!==i.topLeading||b.bottomLeading!==i.bottomLeading||b.topTrailing!==i.topTrailing||b.bottomTrailing!==i.bottomTrailing)&&(Ot?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),b.topLeading=i.topLeading,b.bottomLeading=i.bottomLeading,b.topTrailing=i.topTrailing,b.bottomTrailing=i.bottomTrailing)}function Je(i){Ot?.getSpatialScene().updateSpatialProperties({opacity:i})}function Te(){let i=getComputedStyle(document.documentElement),e=parseFloat(i.getPropertyValue("opacity"));Je(e)}function He(){let i=document.documentElement.style,e=new Proxy(i,{set:function(t,a,r){let n=Reflect.set(t,a,r);return a===Tt.backgroundMaterial&&Rt(r),(a==="border-radius"||a==="borderRadius"||a==="border-top-left-radius"||a==="borderTopLeftRadius"||a==="border-top-right-radius"||a==="borderTopRightRadius"||a==="border-bottom-left-radius"||a==="borderBottomLeftRadius"||a==="border-bottom-right-radius"||a==="borderBottomRightRadius")&&De(),a==="opacity"&&Te(),n},get:function(t,a){return typeof t[a]=="function"?function(...r){if(a==="setProperty"){let[n,o]=r;n===Tt.backgroundMaterial&&Rt(o)}else if(a==="removeProperty"){let[n]=r;n===Tt.backgroundMaterial&&Rt("none")}return t[a](...r)}:Reflect.get(t,a)}});Object.defineProperty(document.documentElement,"style",{get:function(){return e}})}function qe(){new MutationObserver(Ct).observe(document.head,{childList:!0,subtree:!0})}function Ct(){Ne(),De(),Te()}function Ke(){new MutationObserver(e=>{e.forEach(t=>{t.type==="attributes"&&t.attributeName&&Ct()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function Re(){Pe.runInSpatialWeb()&&(Ot=await Pe.requestSession(),document.readyState==="complete"?Ct():window.addEventListener("load",()=>{Ct()}),He(),qe(),Ke())}!I()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(Se(),Re());return It(Qe);})();
|
|
11
10
|
//# sourceMappingURL=index.global.js.map
|