@webspatial/core-sdk 1.0.5 → 1.1.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 +6 -0
- package/dist/iife/index.global.js +3 -3
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/platform-adapter/android/AndroidPlatform.ts +2 -2
- package/src/reality/entity/SpatialEntity.ts +4 -0
- package/src/scene-polyfill.ts +25 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +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.1.0"
|
|
6
6
|
})()
|
|
7
7
|
|
|
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
|
|
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})},_e=(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=>_e(zt({},"__esModule",{value:!0}),i);var Ve,I,_t=f(()=>{"use strict";Ve=typeof window>"u",I=()=>Ve});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 P(i,e=""){return{success:!1,data:void 0,errorCode:i,errorMessage:e}}var Vt=f(()=>{"use strict"});var m,M=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)%We,`rId_${At}`}var Wt,At,We,Lt,Zt=f(()=>{"use strict";Vt();u();M();Wt=0,At=0,We=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:G}=p.data;a(P(c,G))}});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:G}=p.data;a(P(c,G))}}}catch(n){console.error(`AndroidPlatform cmd: ${e}, msg: ${t} error: ${n}`);let{code:o,message:p}=n;a(P(o,p))}})}async callWebSpatialProtocol(e,t,a,r){await new Promise(c=>setTimeout(c,16*Wt)),Wt++;let n=await new _().execute();for(;!n.data.can;)await new Promise(c=>setTimeout(c,16)),n=await new _().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 Wt--,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 Yt={};Gt(Yt,{VisionOSPlatform:()=>Ut});var Ut,te=f(()=>{"use strict";Vt();Ut=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 P(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=(Zt(),It(Xt)).AndroidPlatform;return new i}else{let i=(te(),It(Yt)).VisionOSPlatform;return new i}}var ie=f(()=>{"use strict";_t();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:G,y:Ce,z:Oe}=t,x=new DOMMatrix;return x=x.translate(a,r,n),x=x.rotate(o,p,c),x=x.scale(G,Ce,Oe),x}var Bt=f(()=>{"use strict"});var jt,s,K,Q,X,Z,Y,tt,E,et,it,at,rt,nt,ot,st,pt,lt,ct,dt,mt,ut,yt,St,ft,v,gt,ht,Et,bt,xt,_,vt,wt,Pt,u=f(()=>{"use strict";ie();Bt();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}},Z=class extends s{config;commandType="UpdateSceneConfig";constructor(e){super(),this.config=e}getParams(){return{config:this.config}}},Y=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"},v=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}}},_=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:()=>V,ModelComponent:()=>L,Spatial:()=>z,SpatialBoxGeometry:()=>F,SpatialComponent:()=>A,SpatialConeGeometry:()=>J,SpatialCylinderGeometry:()=>N,SpatialEntity:()=>w,SpatialGeometry:()=>y,SpatialMaterial:()=>U,SpatialModelAsset:()=>j,SpatialModelEntity:()=>W,SpatialObject:()=>d,SpatialPlaneGeometry:()=>$,SpatialScene:()=>h,SpatialSceneState:()=>Ht,SpatialSceneValues:()=>le,SpatialSession:()=>O,SpatialSphereGeometry:()=>k,SpatialUnlitMaterial:()=>B,Spatialized2DElement:()=>D,SpatializedDynamic3DElement:()=>T,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 Z(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||{}),V=class{constructor(e,t){this.size=e;this.origin=t;this.size=e,this.origin=t}get x(){return this.origin.x}get y(){return this.origin.y}get z(){return this.origin.z}get width(){return this.size.width}get height(){return this.size.height}get depth(){return this.size.depth}get left(){return this.x}get top(){return this.y}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get back(){return this.z}get front(){return this.z+this.depth}};var Le={defaultSize:{width:1280,height:720}},Ue={defaultSize:{width:.94,height:.94,depth:.94}},Be="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]}ensureAbsoluteUrl(e){if(!e||/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e))return e;if(e.startsWith("//"))return`${window.location.protocol}${e}`;try{return new URL(e,document.baseURI).toString()}catch{return e}}open=(e,t,a)=>{if(e?.startsWith(Be))return this.originalOpen(e,t,a);if(e=this.ensureAbsoluteUrl(e),t==="_self"||t==="_parent"||t==="_top")return this.originalOpen(e,t,a);let r=t?this.getConfig(t):void 0,o=new Pt(e,r,t,a).executeSync();typeof t=="string"&&this.configMap[t]&&delete this.configMap[t];let p=o.data?.id;return p&&new Y(p).execute(),o.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:Ue}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();M();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 V(r.size,r.origin)}else if(a==="transform")this._transform=new DOMMatrix([t.detail.column0[0],t.detail.column0[1],t.detail.column0[2],0,t.detail.column1[0],t.detail.column1[1],t.detail.column1[2],0,t.detail.column2[0],t.detail.column2[1],t.detail.column2[2],0,t.detail.column3[0],t.detail.column3[1],t.detail.column3[2],1]),this._transformInv=this._transform.inverse();else if(a==="spatialtap"){let r=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 D=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 T=class extends S{children=[];constructor(e){super(e)}async addEntity(e){let t=new v(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 D(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 T(e)}else throw new Error("createSpatializedDynamic3DElement failed")}u();u();u();M();var w=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 v(t.id,this.id).execute();return this.children.push(t),t.parent=this,a}async removeFromParent(){let t=await new v(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){t.__origin||Object.defineProperty(t,"__origin",{value:this,enumerable:!1}),this.events[t.type]?.(t),t.bubbles&&!t.cancelBubble&&this.parent&&this.parent instanceof i&&this.parent.dispatchEvent(t)}onDestroy(){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 W=class extends w{constructor(t,a,r){super(t,r);this.id=t;this.options=a;this.userData=r}};M();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 U=class extends d{constructor(t,a){super(t);this.id=t;this.type=a;this.type=a}};var B=class extends U{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 w(t,i)}else throw new Error("createSpatialEntity failed:"+e?.errorMessage)}async function C(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 B(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 W(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 O=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 C(F,e)}createPlaneGeometry(e={}){return C($,e)}createSphereGeometry(e={}){return C(k,e)}createConeGeometry(e){return C(J,e)}createCylinderGeometry(e){return C(N,e)}createModelComponent(e){return xe(e)}createUnlitMaterial(e){return be(e)}createModelAsset(e){return we(e)}createSpatialModelEntity(e,t){return ve(e,t)}};M();var z=class{requestSession(){return this.runInSpatialWeb()?(m.init(),new O):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.1.0"}};_t();Bt();var Pe=new z,Ot,Rt={backgroundMaterial:"--xr-background-material"},Me="";function Tt(i){i!==Me&&(Ot?.getSpatialScene()?.updateSpatialProperties({material:i}),Me=i)}function Ne(){let e=getComputedStyle(document.documentElement).getPropertyValue(Rt.backgroundMaterial);Tt(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 Re(){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===Rt.backgroundMaterial&&Tt(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"&&Re(),n},get:function(t,a){return typeof t[a]=="function"?function(...r){if(a==="setProperty"){let[n,o]=r;n===Rt.backgroundMaterial&&Tt(o)}else if(a==="removeProperty"){let[n]=r;n===Rt.backgroundMaterial&&Tt("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(),Re()}function Ke(){new MutationObserver(e=>{e.forEach(t=>{t.type==="attributes"&&t.attributeName&&Ct()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function Te(){Pe.runInSpatialWeb()&&(Ot=await Pe.requestSession(),document.readyState==="complete"?Ct():window.addEventListener("load",()=>{Ct()}),He(),qe(),Ke())}!I()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(Se(),Te());return It(Qe);})();
|
|
10
10
|
//# sourceMappingURL=index.global.js.map
|