@webspatial/core-sdk 1.2.0 → 1.2.1
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 +2 -0
- package/dist/iife/index.global.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
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.2.
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.2.1"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
8
|
"use strict";var webspatialCore=(()=>{var Vt=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Be=Object.prototype.hasOwnProperty;var h=(i,e)=>()=>(i&&(e=i(i=0)),e);var q=(i,e)=>{for(var t in e)Vt(i,t,{get:e[t],enumerable:!0})},Le=(i,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of _e(e))!Be.call(i,r)&&r!==t&&Vt(i,r,{get:()=>e[r],enumerable:!(a=Ae(e,r))||a.enumerable});return i};var H=i=>Le(Vt({},"__esModule",{value:!0}),i);var Ue,G,At=h(()=>{"use strict";Ue=typeof window>"u",G=()=>Ue});var X,Yt=h(()=>{"use strict";X=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 y(i){return{success:!0,data:i,errorCode:"",errorMessage:""}}function g(i,e=""){return{success:!1,data:void 0,errorCode:i,errorMessage:e}}var Q=h(()=>{"use strict"});var c,P=h(()=>{"use strict";c=class i{static eventReceiver={};static init(){window.__SpatialWebEvent=({id:e,data:t})=>{i.eventReceiver[e]?.(t)}}static addEventReceiver(e,t){i.eventReceiver[e]=t}static removeEventReceiver(e){delete i.eventReceiver[e]}}});var ee={};q(ee,{XRPlatform:()=>Bt});function te(){return _t=(_t+1)%je,`rId_${_t}`}var _t,je,Bt,ie=h(()=>{"use strict";Q();P();_t=0,je=1e5;Bt=class{async callJSB(e,t){return new Promise((a,r)=>{try{let n=te();c.addEventReceiver(n,s=>{if(c.removeEventReceiver(n),s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}});let o=window.webspatialBridge.postMessage(n,e,t);if(o!==""){c.removeEventReceiver(n);let s=JSON.parse(o);if(s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}}}catch(n){console.error(`XRPlatform cmd: ${e}, msg: ${t} error: ${n}`);let{code:o,message:s}=n;a(g(o,s))}})}async callWebSpatialProtocol(e,t,a,r){return new Promise((n,o)=>{let s=te();try{let p=null;c.addEventReceiver(s,u=>{console.log("createdId",s,u.spatialId),n(y({windowProxy:p,id:u.spatialId})),c.removeEventReceiver(s)}),p=this.openWindow(e,t,a,r).windowProxy,p?.open(`about:blank?rid=${s}`,"_self")}catch(p){console.error(`open window error: ${p}`);let{code:u,message:Wt}=p;c.removeEventReceiver(s),n(g(u,Wt))}})}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return y({windowProxy:o,id:n})}openWindow(e,t,a,r){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,a,r)}}}});var ae={};q(ae,{AndroidPlatform:()=>jt});function Fe(){return Ut=(Ut+1)%ke,`rId_${Ut}`}var Lt,Ut,ke,jt,re=h(()=>{"use strict";Q();S();P();Lt=0,Ut=0,ke=1e5;jt=class{async callJSB(e,t){return new Promise((a,r)=>{try{let n=Fe();c.addEventReceiver(n,s=>{if(c.removeEventReceiver(n),s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}});let o=window.webspatialBridge.postMessage(n,e,t);if(o!==""){c.removeEventReceiver(n);let s=JSON.parse(o);if(s.success)a(y(s.data));else{let{code:p,message:u}=s.data;a(g(p,u))}}}catch(n){console.error(`AndroidPlatform cmd: ${e}, msg: ${t} error: ${n}`);let{code:o,message:s}=n;a(g(o,s))}})}async callWebSpatialProtocol(e,t,a,r){await new Promise(p=>setTimeout(p,16*Lt)),Lt++;let n=await new W().execute();for(;!n.data.can;)await new Promise(p=>setTimeout(p,16)),n=await new W().execute();let{windowProxy:o}=this.openWindow(e,t,a,r);for(;!o?.open;)await new Promise(p=>setTimeout(p,16));for(o?.open("about:blank","_self");!o?.__SpatialId;)await new Promise(p=>setTimeout(p,16));let s=o?.__SpatialId;return Lt--,Promise.resolve(y({windowProxy:o,id:s}))}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return y({windowProxy:o,id:n})}openWindow(e,t,a,r){return{spatialId:"",windowProxy:window.open(`webspatial://${e}?${t||""}`,a,r)}}}});var ne={};q(ne,{VisionOSPlatform:()=>kt});var kt,oe=h(()=>{"use strict";Q();kt=class{async callJSB(e,t){try{let a=await window.webkit.messageHandlers.bridge.postMessage(`${e}::${t}`);return y(a)}catch(a){let{code:r,message:n}=JSON.parse(a.message);return g(r,n)}}callWebSpatialProtocol(e,t,a,r){let{spatialId:n,windowProxy:o}=this.openWindow(e,t,a,r);return Promise.resolve(y({windowProxy:o,id:n}))}callWebSpatialProtocolSync(e,t,a,r){let{spatialId:n="",windowProxy:o}=this.openWindow(e,t,a,r);return y({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 Ne(i){let e=i.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);return e?[Number(e[1]),Number(e[2]),Number(e[3])]:null}function $e(i,e){if(!i)return!1;for(let t=0;t<3;t+=1){let a=i[t]-e[t];if(a>0)return!0;if(a<0)return!1}return!1}function se(){if(G())return new X;let i=window.navigator.userAgent,e=Ne(i);if(i.includes("PicoWebApp")&&$e(e,[0,0,1])){let t=(ie(),H(ee)).XRPlatform;return new t}else if(i.includes("Android")||i.includes("Linux")){let t=(re(),H(ae)).AndroidPlatform;return new t}else{let t=(oe(),H(ne)).VisionOSPlatform;return new t}}var pe=h(()=>{"use strict";At();Yt()});function K(i,e){return i===""?0:i.endsWith("%")?e*parseFloat(i)/100:parseFloat(i)}function le(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:K(t,e),bottomLeading:K(r,e),topTrailing:K(a,e),bottomTrailing:K(n,e)}}function ce(i,e,t){let{x:a,y:r,z:n}=i,{x:o,y:s,z:p}=e,{x:u,y:Wt,z:Ve}=t,w=new DOMMatrix;return w=w.translate(a,r,n),w=w.rotate(o,s,p),w=w.scale(u,Wt,Ve),w}var Ft=h(()=>{"use strict"});var Nt,l,Z,Y,tt,et,it,at,x,rt,nt,ot,st,pt,lt,ct,dt,mt,ut,yt,St,ft,gt,ht,Et,M,bt,xt,vt,wt,Pt,W,Mt,Dt,Rt,S=h(()=>{"use strict";pe();Ft();Nt=se(),l=class{commandType="";async execute(){let e=this.getParams(),t=e?JSON.stringify(e):"";return Nt.callJSB(this.commandType,t)}},Z=class extends l{constructor(t,a){super();this.entity=t;this.properties=a}commandType="UpdateEntityProperties";getParams(){let t=ce(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}}},Y=class extends l{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}}},tt=class extends l{properties;commandType="UpdateSpatialSceneProperties";constructor(e){super(),this.properties=e}getParams(){return this.properties}},et=class extends l{config;commandType="UpdateSceneConfig";constructor(e){super(),this.config=e}getParams(){return{config:this.config}}},it=class extends l{constructor(t){super();this.id=t}commandType="FocusScene";getParams(){return{id:this.id}}},at=class extends l{commandType="GetSpatialSceneState";constructor(){super()}getParams(){return{}}},x=class extends l{constructor(t){super();this.spatialObject=t}getParams(){let t=this.getExtraParams();return{id:this.spatialObject.id,...t}}},rt=class extends x{properties;commandType="UpdateSpatialized2DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},nt=class extends x{properties;commandType="UpdateSpatializedDynamic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return{id:this.spatialObject.id,...this.properties}}},ot=class extends x{properties;commandType="UpdateUnlitMaterialProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},st=class extends x{matrix;commandType="UpdateSpatializedElementTransform";constructor(e,t){super(e),this.matrix=t}getExtraParams(){return{matrix:Array.from(this.matrix.toFloat64Array())}}},pt=class extends x{properties;commandType="UpdateSpatializedStatic3DElementProperties";constructor(e,t){super(e),this.properties=t}getExtraParams(){return this.properties}},lt=class extends x{commandType="AddSpatializedElementToSpatialized2DElement";spatializedElement;constructor(e,t){super(e),this.spatializedElement=t}getExtraParams(){return{spatializedElementId:this.spatializedElement.id}}},ct=class extends l{commandType="AddSpatializedElementToSpatialScene";spatializedElement;constructor(e){super(),this.spatializedElement=e}getParams(){return{spatializedElementId:this.spatializedElement.id}}},dt=class extends l{constructor(t){super();this.modelURL=t;this.modelURL=t}commandType="CreateSpatializedStatic3DElement";getParams(){return{modelURL:this.modelURL}}},mt=class extends l{getParams(){return{test:!0}}commandType="CreateSpatializedDynamic3DElement"},ut=class extends l{constructor(t){super();this.name=t}getParams(){return{name:this.name}}commandType="CreateSpatialEntity"},yt=class extends l{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"},St=class extends l{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateSpatialModelEntity"},ft=class extends l{constructor(t){super();this.options=t}getParams(){return{url:this.options.url}}commandType="CreateModelAsset"},gt=class extends l{constructor(t,a={}){super();this.type=t;this.options=a}getParams(){return{type:this.type,...this.options}}commandType="CreateGeometry"},ht=class extends l{constructor(t){super();this.options=t}getParams(){return this.options}commandType="CreateUnlitMaterial"},Et=class extends l{constructor(t,a){super();this.entity=t;this.comp=a}getParams(){return{entityId:this.entity.id,componentId:this.comp.id}}commandType="AddComponentToEntity"},M=class extends l{constructor(t,a){super();this.childId=t;this.parentId=a}getParams(){return{childId:this.childId,parentId:this.parentId}}commandType="SetParentToEntity"},bt=class extends l{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"},xt=class extends l{constructor(t,a){super();this.fromEntityId=t;this.position=a}getParams(){return{fromEntityId:this.fromEntityId,position:this.position}}commandType="ConvertFromEntityToScene"},vt=class extends l{constructor(t,a){super();this.entityId=t;this.position=a}getParams(){return{entityId:this.entityId,position:this.position}}commandType="ConvertFromSceneToEntity"},wt=class extends l{constructor(t=""){super();this.id=t}commandType="Inspect";getParams(){return this.id?{id:this.id}:{id:""}}},Pt=class extends l{constructor(t){super();this.id=t}commandType="Destroy";getParams(){return{id:this.id}}},W=class extends l{constructor(t=""){super();this.id=t}commandType="CheckWebViewCanCreate";getParams(){return{id:this.id}}},Mt=class extends l{target;features;async execute(){let e=this.getQuery();return Nt.callWebSpatialProtocol(this.commandType,e,this.target,this.features)}executeSync(){let e=this.getQuery();return Nt.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}},Dt=class extends Mt{commandType="createSpatialized2DElement";constructor(){super()}getParams(){return{}}},Rt=class extends Mt{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 ri={};q(ri,{BaseplateVisibilityValues:()=>me,CubeInfo:()=>V,ModelComponent:()=>B,Spatial:()=>I,SpatialBoxGeometry:()=>k,SpatialComponent:()=>_,SpatialConeGeometry:()=>J,SpatialCylinderGeometry:()=>N,SpatialEntity:()=>D,SpatialGeometry:()=>f,SpatialMaterial:()=>L,SpatialModelAsset:()=>j,SpatialModelEntity:()=>A,SpatialObject:()=>d,SpatialPlaneGeometry:()=>$,SpatialScene:()=>b,SpatialSceneState:()=>Qt,SpatialSceneValues:()=>Se,SpatialSession:()=>z,SpatialSphereGeometry:()=>F,SpatialUnlitMaterial:()=>U,Spatialized2DElement:()=>R,SpatializedDynamic3DElement:()=>C,SpatializedElement:()=>E,SpatializedElementType:()=>de,SpatializedStatic3DElement:()=>T,WorldAlignmentValues:()=>ye,WorldScalingValues:()=>ue,isSSREnv:()=>G,isValidBaseplateVisibilityType:()=>Jt,isValidSceneUnit:()=>Tt,isValidSpatialSceneType:()=>Xt,isValidWorldAlignmentType:()=>Ht,isValidWorldScalingType:()=>qt});S();var d=class{constructor(e){this.id=e}name;isDestroyed=!1;async inspect(){let e=await new wt(this.id).execute();if(e.success)return e.data;throw new Error(e.errorMessage)}async destroy(){if(this.isDestroyed)return;let e=await new Pt(this.id).execute();if(e.success)return this.onDestroy(),this.isDestroyed=!0,e.data;if(this.isDestroyed)return;throw new Error(e.errorMessage)}onDestroy(){}};S();S();var $t,b=class i extends d{static getInstance(){return $t||($t=new i("")),$t}async updateSpatialProperties(e){return new tt(e).execute()}async addSpatializedElement(e){return new ct(e).execute()}async updateSceneCreationConfig(e){return new et(e).execute()}async getState(){return(await new at().execute()).data.name}};var de=(a=>(a[a.Spatialized2DElement=0]="Spatialized2DElement",a[a.SpatializedStatic3DElement=1]="SpatializedStatic3DElement",a[a.SpatializedDynamic3DElement=2]="SpatializedDynamic3DElement",a))(de||{}),me=["automatic","visible","hidden"];function Jt(i){return me.includes(i)}var ue=["automatic","dynamic"];function qt(i){return ue.includes(i)}var ye=["adaptive","automatic","gravityAligned"];function Ht(i){return ye.includes(i)}var Se=["window","volume"];function Xt(i){return Se.includes(i)}function Tt(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 Qt=(n=>(n.idle="idle",n.pending="pending",n.willVisible="willVisible",n.visible="visible",n.fail="fail",n))(Qt||{}),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 Je={defaultSize:{width:1280,height:720}},qe={defaultSize:{width:.94,height:.94,depth:.94}},He="webspatial://",Ct=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(He))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 Rt(e,r,t,a).executeSync(),s=o.data?.id;return s&&new it(s).execute(),o.data?.windowProxy};initScene(e,t,a){let r=a?.type??"window",n=Zt(r),o=t({...n}),[s,p]=Ee(o,r);p.length>0&&console.warn(`initScene ${e} with errors: ${p.join(", ")}`),this.configMap[e]={...s,type:r}}};function fe(i){return i/1360}function ge(i){return i*1360}function he(i,e,t){if(typeof i=="number")return t==="px"&&e==="px"||t==="m"&&e==="m"?i:t==="px"&&e==="m"?fe(i):t==="m"&&e==="px"?ge(i):i;if(e==="m"){if(i.endsWith("m"))return Number(i.slice(0,-1));if(i.endsWith("px"))return fe(Number(i.slice(0,-2)));throw new Error("formatToNumber: invalid str")}else if(e==="px"){if(i.endsWith("px"))return Number(i.slice(0,-2));if(i.endsWith("m"))return ge(Number(i.slice(0,-1)));throw new Error("formatToNumber: invalid str")}else throw new Error("formatToNumber: invalid targetUnit")}function Ee(i,e){let t=Zt(e),a=[],r=e==="window";if(Xt(e)||a.push("sceneType"),i.defaultSize){let n=["width","height","depth"];for(let o of n)o in i.defaultSize&&(Tt(i.defaultSize[o])?i.defaultSize[o]=he(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&&(Tt(i.resizability[o])?i.resizability[o]=he(i.resizability[o],"px",r?"px":"m"):(i.resizability[o]=void 0,a.push(`resizability.${o}`)))}return i.worldScaling&&(qt(i.worldScaling)||(i.worldScaling="automatic",a.push("worldScaling"))),i.worldAlignment&&(Ht(i.worldAlignment)||(i.worldAlignment="automatic",a.push("worldAlignment"))),i.baseplateVisibility&&(Jt(i.baseplateVisibility)||(i.baseplateVisibility="automatic",a.push("baseplateVisibility"))),[i,a]}function be(i,e,t){return Ct.getInstance().initScene(i,e,t)}function Xe(i){Ct.getInstance().init(i)}function Kt(i){i.document.onclick=function(e){let t=e.target,a=!1;for(;!a;){if(t&&t.tagName=="A")return!Qe(e);if(t&&t.parentElement)t=t.parentElement;else break}}}function Qe(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 Zt(i){return i==="window"?Je:qe}async function Ke(){if(!window.opener||await b.getInstance().getState()!=="pending")return;function e(t){document.readyState==="interactive"||document.readyState==="complete"?t():document.addEventListener("DOMContentLoaded",t)}e(async()=>{let t=Zt(window.xrCurrentSceneType??"window"),a=t;if(typeof window.xrCurrentSceneDefaults=="function")try{a=await window.xrCurrentSceneDefaults?.(t)}catch(s){console.error(s)}await new Promise((s,p)=>{setTimeout(()=>{s(null)},1e3)});let r=window.xrCurrentSceneType??"window",[n,o]=Ee(a,r);o.length>0&&console.warn(`window.xrCurrentSceneDefaults with errors: ${o.join(", ")}`),await b.getInstance().updateSceneCreationConfig({...n,type:r})})}function xe(){Xe(window),Kt(window),Ke()}S();S();S();P();function m(i,e){return new CustomEvent(i,{bubbles:!0,cancelable:!1,detail:e})}var E=class extends d{constructor(t){super(t);this.id=t;c.addEventReceiver(t,this.onReceiveEvent.bind(this))}async updateTransform(t){return new st(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=m("spatialtap",t.detail);this._onSpatialTap?.(r)}else if(a==="spatialdragstart"){let r=m("spatialdragstart",t.detail);this._onSpatialDragStart?.(r)}else if(a==="spatialdrag"){let r=m("spatialdrag",t.detail);this._onSpatialDrag?.(r)}else if(a==="spatialdragend"){let r=m("spatialdragend",t.detail);this._onSpatialDragEnd?.(r)}else if(a==="spatialrotate"){let r=m("spatialrotate",t.detail);this._onSpatialRotate?.(r)}else if(a==="spatialrotateend"){let r=m("spatialrotateend",t.detail);this._onSpatialRotateEnd?.(r)}else if(a==="spatialmagnify"){let r=m("spatialmagnify",t.detail);this._onSpatialMagnify?.(r)}else if(a==="spatialmagnifyend"){let r=m("spatialmagnifyend",t.detail);this._onSpatialMagnifyEnd?.(r)}}_onSpatialTap;set onSpatialTap(t){this._onSpatialTap=t,this.updateProperties({enableTapGesture:t!==void 0})}_onSpatialDragStart;set onSpatialDragStart(t){this._onSpatialDragStart=t,this.updateProperties({enableDragStartGesture:this._onSpatialDragStart!==void 0})}_onSpatialDrag;set onSpatialDrag(t){this._onSpatialDrag=t,this.updateProperties({enableDragGesture:this._onSpatialDrag!==void 0})}_onSpatialDragEnd;set onSpatialDragEnd(t){this._onSpatialDragEnd=t,this.updateProperties({enableDragEndGesture:t!==void 0})}_onSpatialRotate;set onSpatialRotate(t){this._onSpatialRotate=t,this.updateProperties({enableRotateGesture:this._onSpatialRotate!==void 0})}_onSpatialRotateEnd;set onSpatialRotateEnd(t){this._onSpatialRotateEnd=t,this.updateProperties({enableRotateEndGesture:t!==void 0})}_onSpatialMagnify;set onSpatialMagnify(t){this._onSpatialMagnify=t,this.updateProperties({enableMagnifyGesture:t!==void 0})}_onSpatialMagnifyEnd;set onSpatialMagnifyEnd(t){this._onSpatialMagnifyEnd=t,this.updateProperties({enableMagnifyEndGesture:t!==void 0})}onDestroy(){c.removeEventReceiver(this.id)}};var R=class extends E{constructor(t,a){super(t);this.windowProxy=a;Kt(a)}async updateProperties(t){return new rt(this,t).execute()}async addSpatializedElement(t){return new lt(this,t).execute()}};S();var T=class extends E{_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 pt(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})}};S();var C=class extends E{children=[];constructor(e){super(e)}async addEntity(e){let t=new M(e.id,this.id).execute();return this.children.push(e),e.parent=this,t}async updateProperties(e){return new nt(this,e).execute()}};async function ve(){let i=await new Dt().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 R(e,t)}else throw new Error("createSpatialized2DElement failed")}async function we(i){let e=await new dt(i).execute();if(e.success){let{id:t}=e.data;return new T(t)}else throw new Error("createSpatializedStatic3DElement failed")}async function Pe(){let i=await new mt().execute();if(i.success){let{id:e}=i.data;return new C(e)}else throw new Error("createSpatializedDynamic3DElement failed")}S();S();S();P();var D=class i extends d{constructor(t,a){super(t);this.userData=a;c.addEventReceiver(t,this.onReceiveEvent)}position={x:0,y:0,z:0};rotation={x:0,y:0,z:0};scale={x:1,y:1,z:1};events={};children=[];parent=null;async addComponent(t){return new Et(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 M(t.id,this.id).execute();return this.children.push(t),t.parent=this,a}async removeFromParent(){let t=await new M(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 Z(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 Y(this,t,a).execute()}onReceiveEvent=t=>{let{type:a}=t;if(a==="objectdestroy")this.isDestroyed=!0;else if(a==="spatialtap"){let r=m("spatialtap",t.detail);this.dispatchEvent(r)}else if(a==="spatialdragstart"){let r=m("spatialdragstart",t.detail);this.dispatchEvent(r)}else if(a==="spatialdrag"){let r=m("spatialdrag",t.detail);this.dispatchEvent(r)}else if(a==="spatialdragend"){let r=m("spatialdragend",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotate"){let r=m("spatialrotate",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotateend"){let r=m("spatialrotateend",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnify"){let r=m("spatialmagnify",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnifyend"){let r=m("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(){c.removeEventReceiver(this.id),this.children.forEach(t=>{t.parent=null}),this.children=[],this.parent&&(this.parent.children=this.parent.children.filter(t=>t.id!==this.id),this.parent=null)}async convertFromEntityToEntity(t,a,r){return new bt(t,a,r).execute()}async convertFromEntityToScene(t,a){return new xt(t,a).execute()}async convertFromSceneToEntity(t,a){return new vt(t,a).execute()}};var A=class extends D{constructor(t,a,r){super(t,r);this.id=t;this.options=a;this.userData=r}};P();var _=class extends d{constructor(e){super(e),c.addEventReceiver(e,this.onReceiveEvent)}onReceiveEvent=e=>{let{type:t}=e;t==="objectdestroy"&&(this.isDestroyed=!0)}};var B=class extends _{constructor(t,a){super(t);this.options=a}};S();var L=class extends d{constructor(t,a){super(t);this.id=t;this.type=a;this.type=a}};var U=class extends L{constructor(t,a){super(t,"unlit");this.id=t;this.options=a}updateProperties(t){return new ot(this,t).execute()}};var j=class extends d{constructor(t,a){super(t);this.id=t;this.options=a}};async function Me(i){let e=await new ut(i?.name).execute();if(e.success){let{id:t}=e.data;return new D(t,i)}else throw new Error("createSpatialEntity failed:"+e?.errorMessage)}async function O(i,e){let t=await new gt(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 De(i){let e=await new ht(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 Re(i){let e=await new yt(i).execute();if(e.success){let{id:t}=e.data;return new B(t,i)}else throw new Error("createModelComponent failed:"+e?.errorMessage)}async function Te(i,e){let t=await new St(i).execute();if(t.success){let{id:a}=t.data;return new A(a,i,e)}else throw new Error("createSpatialModelEntity failed:"+t?.errorMessage)}async function Ce(i){let e=await new ft(i).execute();if(e.success){let{id:t}=e.data;return new j(t,i)}else throw new Error("createModelAsset failed:"+e?.errorMessage)}var f=class extends d{constructor(t,a){super(t);this.id=t;this.options=a}static type};var k=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="BoxGeometry"};var F=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="SphereGeometry"};var N=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="CylinderGeometry"};var $=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="PlaneGeometry"};var J=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="ConeGeometry"};var z=class{getSpatialScene(){return b.getInstance()}createSpatialized2DElement(){return ve()}createSpatializedStatic3DElement(e=""){return we(e)}initScene=be;createSpatializedDynamic3DElement(){return Pe()}createEntity(e){return Me(e)}createBoxGeometry(e={}){return O(k,e)}createPlaneGeometry(e={}){return O($,e)}createSphereGeometry(e={}){return O(F,e)}createConeGeometry(e){return O(J,e)}createCylinderGeometry(e){return O(N,e)}createModelComponent(e){return Re(e)}createUnlitMaterial(e){return De(e)}createModelAsset(e){return Ce(e)}createSpatialModelEntity(e,t){return Te(e,t)}};P();var I=class{requestSession(){return this.runInSpatialWeb()?(c.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.2.
|
|
9
|
+
<base href="${document.baseURI}">`,new R(e,t)}else throw new Error("createSpatialized2DElement failed")}async function we(i){let e=await new dt(i).execute();if(e.success){let{id:t}=e.data;return new T(t)}else throw new Error("createSpatializedStatic3DElement failed")}async function Pe(){let i=await new mt().execute();if(i.success){let{id:e}=i.data;return new C(e)}else throw new Error("createSpatializedDynamic3DElement failed")}S();S();S();P();var D=class i extends d{constructor(t,a){super(t);this.userData=a;c.addEventReceiver(t,this.onReceiveEvent)}position={x:0,y:0,z:0};rotation={x:0,y:0,z:0};scale={x:1,y:1,z:1};events={};children=[];parent=null;async addComponent(t){return new Et(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 M(t.id,this.id).execute();return this.children.push(t),t.parent=this,a}async removeFromParent(){let t=await new M(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 Z(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 Y(this,t,a).execute()}onReceiveEvent=t=>{let{type:a}=t;if(a==="objectdestroy")this.isDestroyed=!0;else if(a==="spatialtap"){let r=m("spatialtap",t.detail);this.dispatchEvent(r)}else if(a==="spatialdragstart"){let r=m("spatialdragstart",t.detail);this.dispatchEvent(r)}else if(a==="spatialdrag"){let r=m("spatialdrag",t.detail);this.dispatchEvent(r)}else if(a==="spatialdragend"){let r=m("spatialdragend",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotate"){let r=m("spatialrotate",t.detail);this.dispatchEvent(r)}else if(a==="spatialrotateend"){let r=m("spatialrotateend",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnify"){let r=m("spatialmagnify",t.detail);this.dispatchEvent(r)}else if(a==="spatialmagnifyend"){let r=m("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(){c.removeEventReceiver(this.id),this.children.forEach(t=>{t.parent=null}),this.children=[],this.parent&&(this.parent.children=this.parent.children.filter(t=>t.id!==this.id),this.parent=null)}async convertFromEntityToEntity(t,a,r){return new bt(t,a,r).execute()}async convertFromEntityToScene(t,a){return new xt(t,a).execute()}async convertFromSceneToEntity(t,a){return new vt(t,a).execute()}};var A=class extends D{constructor(t,a,r){super(t,r);this.id=t;this.options=a;this.userData=r}};P();var _=class extends d{constructor(e){super(e),c.addEventReceiver(e,this.onReceiveEvent)}onReceiveEvent=e=>{let{type:t}=e;t==="objectdestroy"&&(this.isDestroyed=!0)}};var B=class extends _{constructor(t,a){super(t);this.options=a}};S();var L=class extends d{constructor(t,a){super(t);this.id=t;this.type=a;this.type=a}};var U=class extends L{constructor(t,a){super(t,"unlit");this.id=t;this.options=a}updateProperties(t){return new ot(this,t).execute()}};var j=class extends d{constructor(t,a){super(t);this.id=t;this.options=a}};async function Me(i){let e=await new ut(i?.name).execute();if(e.success){let{id:t}=e.data;return new D(t,i)}else throw new Error("createSpatialEntity failed:"+e?.errorMessage)}async function O(i,e){let t=await new gt(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 De(i){let e=await new ht(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 Re(i){let e=await new yt(i).execute();if(e.success){let{id:t}=e.data;return new B(t,i)}else throw new Error("createModelComponent failed:"+e?.errorMessage)}async function Te(i,e){let t=await new St(i).execute();if(t.success){let{id:a}=t.data;return new A(a,i,e)}else throw new Error("createSpatialModelEntity failed:"+t?.errorMessage)}async function Ce(i){let e=await new ft(i).execute();if(e.success){let{id:t}=e.data;return new j(t,i)}else throw new Error("createModelAsset failed:"+e?.errorMessage)}var f=class extends d{constructor(t,a){super(t);this.id=t;this.options=a}static type};var k=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="BoxGeometry"};var F=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="SphereGeometry"};var N=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="CylinderGeometry"};var $=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="PlaneGeometry"};var J=class extends f{constructor(t,a){super(t,a);this.id=t;this.options=a}static type="ConeGeometry"};var z=class{getSpatialScene(){return b.getInstance()}createSpatialized2DElement(){return ve()}createSpatializedStatic3DElement(e=""){return we(e)}initScene=be;createSpatializedDynamic3DElement(){return Pe()}createEntity(e){return Me(e)}createBoxGeometry(e={}){return O(k,e)}createPlaneGeometry(e={}){return O($,e)}createSphereGeometry(e={}){return O(F,e)}createConeGeometry(e){return O(J,e)}createCylinderGeometry(e){return O(N,e)}createModelComponent(e){return Re(e)}createUnlitMaterial(e){return De(e)}createModelAsset(e){return Ce(e)}createSpatialModelEntity(e,t){return Te(e,t)}};P();var I=class{requestSession(){return this.runInSpatialWeb()?(c.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.2.1"}};At();Ft();var Oe=new I,Gt,Ot={backgroundMaterial:"--xr-background-material"},ze="";function zt(i){i!==ze&&(Gt?.getSpatialScene()?.updateSpatialProperties({material:i}),ze=i)}function Ze(){let e=getComputedStyle(document.documentElement).getPropertyValue(Ot.backgroundMaterial);zt(e||"none")}var v={topLeading:0,bottomLeading:0,topTrailing:0,bottomTrailing:0};function Ie(){let i=getComputedStyle(document.documentElement),e=le(i);Ye(e)}function Ye(i){(v.topLeading!==i.topLeading||v.bottomLeading!==i.bottomLeading||v.topTrailing!==i.topTrailing||v.bottomTrailing!==i.bottomTrailing)&&(Gt?.getSpatialScene()?.updateSpatialProperties({cornerRadius:i}),v.topLeading=i.topLeading,v.bottomLeading=i.bottomLeading,v.topTrailing=i.topTrailing,v.bottomTrailing=i.bottomTrailing)}function ti(i){Gt?.getSpatialScene().updateSpatialProperties({opacity:i})}function Ge(){let i=getComputedStyle(document.documentElement),e=parseFloat(i.getPropertyValue("opacity"));ti(e)}function ei(){let i=document.documentElement.style,e=new Proxy(i,{set:function(t,a,r){let n=Reflect.set(t,a,r);return a===Ot.backgroundMaterial&&zt(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")&&Ie(),a==="opacity"&&Ge(),n},get:function(t,a){return typeof t[a]=="function"?function(...r){if(a==="setProperty"){let[n,o]=r;n===Ot.backgroundMaterial&&zt(o)}else if(a==="removeProperty"){let[n]=r;n===Ot.backgroundMaterial&&zt("none")}return t[a](...r)}:Reflect.get(t,a)}});Object.defineProperty(document.documentElement,"style",{get:function(){return e}})}function ii(){new MutationObserver(It).observe(document.head,{childList:!0,subtree:!0})}function It(){Ze(),Ie(),Ge()}function ai(){new MutationObserver(e=>{e.forEach(t=>{t.type==="attributes"&&t.attributeName&&It()})}).observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]})}async function We(){Oe.runInSpatialWeb()&&(Gt=await Oe.requestSession(),document.readyState==="complete"?It():window.addEventListener("load",()=>{It()}),ei(),ii(),ai())}!G()&&navigator.userAgent.indexOf("WebSpatial/")>0&&(xe(),We());return H(ri);})();
|
|
10
10
|
//# sourceMappingURL=index.global.js.map
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['core-sdk-version'] = "1.2.
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.2.1"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
@@ -2312,7 +2312,7 @@ var Spatial = class {
|
|
|
2312
2312
|
* @returns Client SDK version string in format "x.x.x"
|
|
2313
2313
|
*/
|
|
2314
2314
|
getClientVersion() {
|
|
2315
|
-
return "1.2.
|
|
2315
|
+
return "1.2.1";
|
|
2316
2316
|
}
|
|
2317
2317
|
};
|
|
2318
2318
|
|