@webspatial/core-sdk 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.3.0"
5
+ window.__webspatialsdk__['core-sdk-version'] = "1.5.0"
6
6
  })()
7
7
 
8
8
  var __defProp = Object.defineProperty;
@@ -105,7 +105,7 @@ var init_PuppeteerPlatform = __esm({
105
105
  init_CommandResultUtils();
106
106
  console.log("PuppeteerPlatform");
107
107
  PuppeteerPlatform = class {
108
- // 存储iframe实例
108
+ // store iframe instance
109
109
  iframeRegistry = /* @__PURE__ */ new Map();
110
110
  constructor() {
111
111
  }
@@ -135,7 +135,7 @@ var init_PuppeteerPlatform = __esm({
135
135
  });
136
136
  }
137
137
  /**
138
- * 同步创建Spatialized2DElementPuppeteer Runner
138
+ * Synchronously create Spatialized2DElement to Puppeteer Runner
139
139
  */
140
140
  createSpatializedElementSync(spatialId, webspatialUrl) {
141
141
  try {
@@ -207,7 +207,7 @@ var init_PuppeteerPlatform = __esm({
207
207
  }
208
208
  }
209
209
  /**
210
- * 创建基于iframe的窗口
210
+ * Synchronously create iframe-based window
211
211
  */
212
212
  createIframeWindow(url, target, features) {
213
213
  const iframe = document.createElement("iframe");
@@ -243,11 +243,11 @@ var init_PuppeteerPlatform = __esm({
243
243
  return { spatialId, iframe, windowProxy };
244
244
  }
245
245
  /**
246
- * 创建增强的windowProxy对象
246
+ * create enhanced windowProxy object
247
247
  */
248
248
  createEnhancedWindowProxy(iframe, url, spatialId) {
249
249
  return {
250
- // 基本属性
250
+ // basic properties
251
251
  location: {
252
252
  href: url,
253
253
  toString: () => url,
@@ -260,22 +260,22 @@ var init_PuppeteerPlatform = __esm({
260
260
  navigator: {
261
261
  userAgent: `Mozilla/5.0 (WebKit) SpatialId/${spatialId}`
262
262
  },
263
- // 方法
263
+ // methods
264
264
  close: () => {
265
265
  console.log(`Closing iframe with spatialId: ${spatialId}`);
266
266
  iframe.remove();
267
267
  this.iframeRegistry.delete(spatialId);
268
268
  },
269
- // 文档访问
269
+ // document access
270
270
  document: iframe.contentDocument || {},
271
271
  contentWindow: iframe.contentWindow || {},
272
- // 添加消息通信方法
272
+ // add message communication method
273
273
  postMessage: (message, targetOrigin) => {
274
274
  if (iframe.contentWindow) {
275
275
  iframe.contentWindow.postMessage(message, targetOrigin || "*");
276
276
  }
277
277
  },
278
- // 添加事件监听方法
278
+ // add event listener method
279
279
  addEventListener: (type, listener) => {
280
280
  if (iframe.contentWindow) {
281
281
  iframe.contentWindow.addEventListener(type, listener);
@@ -286,7 +286,7 @@ var init_PuppeteerPlatform = __esm({
286
286
  iframe.contentWindow.removeEventListener(type, listener);
287
287
  }
288
288
  },
289
- // 执行JavaScript
289
+ // execute JavaScript
290
290
  executeScript: (code) => {
291
291
  if (iframe.contentWindow) {
292
292
  try {
@@ -302,29 +302,29 @@ var init_PuppeteerPlatform = __esm({
302
302
  }
303
303
  return null;
304
304
  },
305
- // 获取iframe引用
305
+ // get iframe reference
306
306
  getIframe: () => iframe,
307
- // 获取spatialId
307
+ // get spatialId
308
308
  getSpatialId: () => spatialId
309
309
  };
310
310
  }
311
311
  /**
312
- * 初始化iframe内容
312
+ * initialize iframe content
313
313
  */
314
314
  initializeIframeContent(iframe, url, spatialId) {
315
315
  try {
316
316
  iframe.onload = () => {
317
317
  try {
318
318
  const iframeContent = `
319
- // \u6CE8\u5165\u901A\u4FE1\u811A\u672C
319
+ // inject communication script
320
320
  window.webSpatialId = '${spatialId}';
321
321
  window.SpatialId = '${spatialId}';
322
322
 
323
- // \u91CD\u5199window.open\u4EE5\u652F\u6301webspatial\u534F\u8BAE
323
+ // override window.open to support webspatial protocol
324
324
  const originalOpen = window.open;
325
325
  window.open = function(url, target, features) {
326
326
  if (url && url.startsWith('webspatial://')) {
327
- // \u901A\u8FC7windowProxy\u5904\u7406webspatial\u534F\u8BAE
327
+ // handle webspatial protocol through windowProxy
328
328
  const windowProxy = new Proxy({}, {
329
329
  get: function(target, prop) {
330
330
  if (prop === 'toString') {
@@ -338,28 +338,28 @@ var init_PuppeteerPlatform = __esm({
338
338
  return originalOpen.call(window, url, target, features);
339
339
  };
340
340
 
341
- // \u8BBE\u7F6Enavigator.userAgent\u4EE5\u8BC6\u522Bwebspatial\u73AF\u5883
341
+ // set navigator.userAgent to identify webspatial environment
342
342
  Object.defineProperty(navigator, 'userAgent', {
343
343
  value: 'WebSpatial/1.0 ' + navigator.userAgent,
344
344
  configurable: true
345
345
  });
346
346
 
347
- // \u53D1\u9001\u52A0\u8F7D\u5B8C\u6210\u6D88\u606F
347
+ // send loaded message
348
348
  window.parent.postMessage({
349
349
  type: 'iframe_loaded',
350
350
  spatialId: '${spatialId}',
351
351
  url: '${url}'
352
352
  }, '${window.location.origin}');
353
353
 
354
- // \u8BBE\u7F6E\u6D88\u606F\u5904\u7406\u5668
354
+ // set message handler
355
355
  window.addEventListener('message', (event) => {
356
356
  if (event.origin !== window.parent.location.origin) return;
357
357
 
358
358
  const data = event.data;
359
359
  if (data && data.type === 'webspatial_command') {
360
- // \u5904\u7406\u6765\u81EA\u7236\u7A97\u53E3\u7684\u547D\u4EE4
360
+ // handle command from parent window
361
361
  console.log('Received command in iframe from parent:', data.command);
362
- // \u8FD9\u91CC\u53EF\u4EE5\u6DFB\u52A0\u547D\u4EE4\u5904\u7406\u903B\u8F91
362
+ // add command handling logic here
363
363
  }
364
364
  });
365
365
  `;
@@ -396,7 +396,7 @@ var init_PuppeteerPlatform = __esm({
396
396
  }
397
397
  }
398
398
  /**
399
- * 解析features字符串为对象
399
+ * parse features string to object
400
400
  */
401
401
  parseFeatures(features) {
402
402
  const result = {};
@@ -410,7 +410,7 @@ var init_PuppeteerPlatform = __esm({
410
410
  return result;
411
411
  }
412
412
  /**
413
- * 发送消息到指定spatialId的iframe
413
+ * send message to iframe with specified spatialId
414
414
  */
415
415
  sendMessageToIframe(spatialId, message) {
416
416
  const iframe = this.iframeRegistry.get(spatialId);
@@ -421,7 +421,7 @@ var init_PuppeteerPlatform = __esm({
421
421
  return false;
422
422
  }
423
423
  /**
424
- * 获取所有活跃的iframe
424
+ * get all active iframes
425
425
  */
426
426
  getAllActiveIframes() {
427
427
  const result = [];
@@ -431,7 +431,7 @@ var init_PuppeteerPlatform = __esm({
431
431
  return result;
432
432
  }
433
433
  /**
434
- * 清理资源
434
+ * dispose all active iframes
435
435
  */
436
436
  dispose() {
437
437
  this.iframeRegistry.forEach((iframe, spatialId) => {
@@ -440,7 +440,7 @@ var init_PuppeteerPlatform = __esm({
440
440
  });
441
441
  this.iframeRegistry.clear();
442
442
  }
443
- // 生成UUID函数
443
+ // generate UUID function
444
444
  generateUUID() {
445
445
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
446
446
  /[xy]/g,
@@ -477,24 +477,24 @@ var init_SpatialWebEvent = __esm({
477
477
  }
478
478
  });
479
479
 
480
- // src/platform-adapter/xr/XRPlatform.ts
481
- var XRPlatform_exports = {};
482
- __export(XRPlatform_exports, {
483
- XRPlatform: () => XRPlatform
480
+ // src/platform-adapter/pico-os/PicoOSPlatform.ts
481
+ var PicoOSPlatform_exports = {};
482
+ __export(PicoOSPlatform_exports, {
483
+ PicoOSPlatform: () => PicoOSPlatform
484
484
  });
485
485
  function nextRequestId() {
486
486
  requestId = (requestId + 1) % MAX_ID;
487
487
  return `rId_${requestId}`;
488
488
  }
489
- var requestId, MAX_ID, XRPlatform;
490
- var init_XRPlatform = __esm({
491
- "src/platform-adapter/xr/XRPlatform.ts"() {
489
+ var requestId, MAX_ID, PicoOSPlatform;
490
+ var init_PicoOSPlatform = __esm({
491
+ "src/platform-adapter/pico-os/PicoOSPlatform.ts"() {
492
492
  "use strict";
493
493
  init_CommandResultUtils();
494
494
  init_SpatialWebEvent();
495
495
  requestId = 0;
496
496
  MAX_ID = 1e5;
497
- XRPlatform = class {
497
+ PicoOSPlatform = class {
498
498
  async callJSB(cmd, msg) {
499
499
  return new Promise((resolve, reject) => {
500
500
  try {
@@ -520,7 +520,7 @@ var init_XRPlatform = __esm({
520
520
  }
521
521
  }
522
522
  } catch (error) {
523
- console.error(`XRPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
523
+ console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
524
524
  const { code, message } = error;
525
525
  resolve(CommandResultFailure(code, message));
526
526
  }
@@ -534,7 +534,6 @@ var init_XRPlatform = __esm({
534
534
  SpatialWebEvent.addEventReceiver(
535
535
  createdId,
536
536
  (result) => {
537
- console.log("createdId", createdId, result.spatialId);
538
537
  resolve(
539
538
  CommandResultSuccess({
540
539
  windowProxy,
@@ -546,13 +545,11 @@ var init_XRPlatform = __esm({
546
545
  );
547
546
  windowProxy = this.openWindow(
548
547
  command,
549
- query,
548
+ "rid=" + createdId,
550
549
  target,
551
550
  features
552
551
  ).windowProxy;
553
- windowProxy?.open(`about:blank?rid=${createdId}`, "_self");
554
552
  } catch (error) {
555
- console.error(`open window error: ${error}`);
556
553
  const { code, message } = error;
557
554
  SpatialWebEvent.removeEventReceiver(createdId);
558
555
  resolve(CommandResultFailure(code, message));
@@ -767,8 +764,8 @@ function createPlatform() {
767
764
  const PuppeteerPlatform2 = (init_PuppeteerPlatform(), __toCommonJS(PuppeteerPlatform_exports)).PuppeteerPlatform;
768
765
  return new PuppeteerPlatform2();
769
766
  } else if (userAgent.includes("PicoWebApp") && isVersionGreater(webSpatialVersion, [0, 0, 1])) {
770
- const XRPlatform2 = (init_XRPlatform(), __toCommonJS(XRPlatform_exports)).XRPlatform;
771
- return new XRPlatform2();
767
+ const PicoOSPlatform2 = (init_PicoOSPlatform(), __toCommonJS(PicoOSPlatform_exports)).PicoOSPlatform;
768
+ return new PicoOSPlatform2();
772
769
  } else if (userAgent.includes("Android") || userAgent.includes("Linux")) {
773
770
  const AndroidPlatform2 = (init_AndroidPlatform(), __toCommonJS(AndroidPlatform_exports)).AndroidPlatform;
774
771
  return new AndroidPlatform2();
@@ -834,7 +831,7 @@ var init_utils = __esm({
834
831
  });
835
832
 
836
833
  // src/JSBCommand.ts
837
- var platform, JSBCommand, UpdateEntityPropertiesCommand, UpdateEntityEventCommand, UpdateSpatialSceneProperties, UpdateSceneConfig, FocusScene, GetSpatialSceneState, SpatializedElementCommand, UpdateSpatialized2DElementProperties, UpdateSpatializedDynamic3DElementProperties, UpdateUnlitMaterialProperties, UpdateSpatializedElementTransform, UpdateSpatializedStatic3DElementProperties, AddSpatializedElementToSpatialized2DElement, AddSpatializedElementToSpatialScene, CreateSpatializedStatic3DElementCommand, CreateSpatializedDynamic3DElementCommand, CreateSpatialEntityCommand, CreateModelComponentCommand, CreateSpatialModelEntityCommand, CreateModelAssetCommand, CreateSpatialGeometryCommand, CreateSpatialUnlitMaterialCommand, AddComponentToEntityCommand, SetParentForEntityCommand, ConvertFromEntityToEntityCommand, ConvertFromEntityToSceneCommand, ConvertFromSceneToEntityCommand, InspectCommand, DestroyCommand, CheckWebViewCanCreateCommand, WebSpatialProtocolCommand, createSpatialized2DElementCommand, createSpatialSceneCommand, CreateAttachmentEntityCommand, UpdateAttachmentEntityCommand;
834
+ var platform, JSBCommand, UpdateEntityPropertiesCommand, UpdateEntityEventCommand, UpdateSpatialSceneProperties, UpdateSceneConfig, FocusScene, GetSpatialSceneState, SpatializedElementCommand, UpdateSpatialized2DElementProperties, UpdateSpatializedDynamic3DElementProperties, UpdateUnlitMaterialProperties, UpdateSpatializedElementTransform, UpdateSpatializedStatic3DElementProperties, AddSpatializedElementToSpatialized2DElement, AddSpatializedElementToSpatialScene, CreateSpatializedStatic3DElementCommand, CreateSpatializedDynamic3DElementCommand, CreateSpatialEntityCommand, CreateModelComponentCommand, CreateSpatialModelEntityCommand, CreateModelAssetCommand, CreateSpatialGeometryCommand, CreateSpatialUnlitMaterialCommand, AddComponentToEntityCommand, RemoveComponentFromEntityCommand, SetMaterialsOnEntityCommand, SetParentForEntityCommand, ConvertFromEntityToEntityCommand, ConvertFromEntityToSceneCommand, ConvertFromSceneToEntityCommand, ConvertCoordinateCommand, InspectCommand, DestroyCommand, CheckWebViewCanCreateCommand, WebSpatialProtocolCommand, createSpatialized2DElementCommand, createSpatialSceneCommand, CreateAttachmentEntityCommand, InitializeAttachmentCommand, UpdateAttachmentEntityCommand;
838
835
  var init_JSBCommand = __esm({
839
836
  "src/JSBCommand.ts"() {
840
837
  "use strict";
@@ -1111,6 +1108,34 @@ var init_JSBCommand = __esm({
1111
1108
  }
1112
1109
  commandType = "AddComponentToEntity";
1113
1110
  };
1111
+ RemoveComponentFromEntityCommand = class extends JSBCommand {
1112
+ constructor(entity, comp) {
1113
+ super();
1114
+ this.entity = entity;
1115
+ this.comp = comp;
1116
+ }
1117
+ getParams() {
1118
+ return {
1119
+ entityId: this.entity.id,
1120
+ componentId: this.comp.id
1121
+ };
1122
+ }
1123
+ commandType = "RemoveComponentFromEntity";
1124
+ };
1125
+ SetMaterialsOnEntityCommand = class extends JSBCommand {
1126
+ constructor(entityId, materials) {
1127
+ super();
1128
+ this.entityId = entityId;
1129
+ this.materials = materials;
1130
+ }
1131
+ getParams() {
1132
+ return {
1133
+ entityId: this.entityId,
1134
+ materialIds: this.materials.map((m) => m.id)
1135
+ };
1136
+ }
1137
+ commandType = "SetMaterialsOnEntity";
1138
+ };
1114
1139
  SetParentForEntityCommand = class extends JSBCommand {
1115
1140
  // childId, parentId
1116
1141
  constructor(childId, parentId) {
@@ -1172,6 +1197,22 @@ var init_JSBCommand = __esm({
1172
1197
  }
1173
1198
  commandType = "ConvertFromSceneToEntity";
1174
1199
  };
1200
+ ConvertCoordinateCommand = class extends JSBCommand {
1201
+ constructor(position, fromId, toId) {
1202
+ super();
1203
+ this.position = position;
1204
+ this.fromId = fromId;
1205
+ this.toId = toId;
1206
+ }
1207
+ getParams() {
1208
+ return {
1209
+ position: this.position,
1210
+ fromId: this.fromId,
1211
+ toId: this.toId
1212
+ };
1213
+ }
1214
+ commandType = "ConvertCoordinate";
1215
+ };
1175
1216
  InspectCommand = class extends JSBCommand {
1176
1217
  constructor(id = "") {
1177
1218
  super();
@@ -1267,11 +1308,24 @@ var init_JSBCommand = __esm({
1267
1308
  this.options = options;
1268
1309
  }
1269
1310
  commandType = "createAttachment";
1311
+ getParams() {
1312
+ return {};
1313
+ }
1314
+ };
1315
+ InitializeAttachmentCommand = class extends JSBCommand {
1316
+ constructor(attachmentId, options) {
1317
+ super();
1318
+ this.attachmentId = attachmentId;
1319
+ this.options = options;
1320
+ }
1321
+ commandType = "InitializeAttachment";
1270
1322
  getParams() {
1271
1323
  return {
1324
+ id: this.attachmentId,
1272
1325
  parentEntityId: this.options.parentEntityId,
1273
1326
  position: this.options.position ?? [0, 0, 0],
1274
- size: this.options.size
1327
+ size: this.options.size,
1328
+ ownerViewId: this.options.ownerViewId
1275
1329
  };
1276
1330
  }
1277
1331
  };
@@ -1332,6 +1386,7 @@ init_JSBCommand();
1332
1386
 
1333
1387
  // src/SpatialScene.ts
1334
1388
  init_JSBCommand();
1389
+ init_JSBCommand();
1335
1390
  var instance;
1336
1391
  var SpatialScene = class _SpatialScene extends SpatialObject {
1337
1392
  /**
@@ -1345,6 +1400,19 @@ var SpatialScene = class _SpatialScene extends SpatialObject {
1345
1400
  }
1346
1401
  return instance;
1347
1402
  }
1403
+ async convertCoordinate(position, fromId, toId) {
1404
+ try {
1405
+ const ret = await new ConvertCoordinateCommand(
1406
+ position,
1407
+ fromId,
1408
+ toId
1409
+ ).execute();
1410
+ return ret?.data ?? position;
1411
+ } catch (error) {
1412
+ console.warn("SpatialScene.convertCoordinate error:", error);
1413
+ throw error;
1414
+ }
1415
+ }
1348
1416
  /**
1349
1417
  * Updates the properties of the spatial scene.
1350
1418
  * This can include background settings, lighting, and other scene-wide properties.
@@ -1540,6 +1608,18 @@ var SceneManager = class _SceneManager {
1540
1608
  }
1541
1609
  open = (url, target, features) => {
1542
1610
  if (url?.startsWith(INTERNAL_SCHEMA_PREFIX)) {
1611
+ if (url.includes("createSpatialized2DElement")) {
1612
+ const token = window.webSpatial?.genToken?.();
1613
+ if (token) {
1614
+ const host = window.location.host;
1615
+ const protocol = window.location.protocol;
1616
+ const finalURL = `${protocol}//${host}/${token}/?command=createSpatialized2DElement`;
1617
+ const rid = new URL(url).searchParams.get("rid");
1618
+ const final = new URL(finalURL);
1619
+ if (rid) final.searchParams.set("rid", rid);
1620
+ return this.originalOpen(final.toString(), target, features);
1621
+ }
1622
+ }
1543
1623
  return this.originalOpen(url, target, features);
1544
1624
  }
1545
1625
  url = this.ensureAbsoluteUrl(url);
@@ -1844,29 +1924,6 @@ var SpatializedElement = class extends SpatialObject {
1844
1924
  const { type } = data;
1845
1925
  if (type === "objectdestroy" /* objectdestroy */) {
1846
1926
  this.isDestroyed = true;
1847
- } else if (type === "cubeInfo" /* cubeInfo */) {
1848
- const cubeInfoMsg = data;
1849
- this._cubeInfo = new CubeInfo(cubeInfoMsg.size, cubeInfoMsg.origin);
1850
- } else if (type === "transform" /* transform */) {
1851
- this._transform = new DOMMatrix([
1852
- data.detail.column0[0],
1853
- data.detail.column0[1],
1854
- data.detail.column0[2],
1855
- 0,
1856
- data.detail.column1[0],
1857
- data.detail.column1[1],
1858
- data.detail.column1[2],
1859
- 0,
1860
- data.detail.column2[0],
1861
- data.detail.column2[1],
1862
- data.detail.column2[2],
1863
- 0,
1864
- data.detail.column3[0],
1865
- data.detail.column3[1],
1866
- data.detail.column3[2],
1867
- 1
1868
- ]);
1869
- this._transformInv = this._transform.inverse();
1870
1927
  } else if (type === "spatialtap" /* spatialtap */) {
1871
1928
  const event = createSpatialEvent(
1872
1929
  "spatialtap" /* spatialtap */,
@@ -2045,6 +2102,7 @@ var SpatializedStatic3DElement = class extends SpatializedElement {
2045
2102
  * @returns Promise that resolves when the model is loaded (true) or fails to load (false)
2046
2103
  */
2047
2104
  createReadyPromise() {
2105
+ this._readyResolve?.(false);
2048
2106
  return new Promise((resolve) => {
2049
2107
  this._readyResolve = resolve;
2050
2108
  });
@@ -2120,6 +2178,7 @@ var SpatializedStatic3DElement = class extends SpatializedElement {
2120
2178
  init_JSBCommand();
2121
2179
  var SpatializedDynamic3DElement = class extends SpatializedElement {
2122
2180
  children = [];
2181
+ events = {};
2123
2182
  constructor(id) {
2124
2183
  super(id);
2125
2184
  }
@@ -2129,6 +2188,17 @@ var SpatializedDynamic3DElement = class extends SpatializedElement {
2129
2188
  entity.parent = this;
2130
2189
  return ans;
2131
2190
  }
2191
+ addEvent(type, callback) {
2192
+ this.events[type] = callback;
2193
+ }
2194
+ removeEvent(eventName) {
2195
+ if (this.events[eventName]) {
2196
+ delete this.events[eventName];
2197
+ }
2198
+ }
2199
+ dispatchEvent(evt) {
2200
+ this.events[evt.type]?.(evt);
2201
+ }
2132
2202
  async updateProperties(properties) {
2133
2203
  return new UpdateSpatializedDynamic3DElementProperties(
2134
2204
  this,
@@ -2197,6 +2267,7 @@ async function createAttachmentEntity(options) {
2197
2267
  throw new Error("createAttachmentEntity failed: " + result?.errorMessage);
2198
2268
  }
2199
2269
  const { id, windowProxy } = result.data;
2270
+ await new InitializeAttachmentCommand(id, options).execute();
2200
2271
  return new Attachment(id, windowProxy, options);
2201
2272
  }
2202
2273
 
@@ -2207,7 +2278,7 @@ init_JSBCommand();
2207
2278
  init_JSBCommand();
2208
2279
  init_JSBCommand();
2209
2280
  init_SpatialWebEvent();
2210
- var SpatialEntity = class _SpatialEntity extends SpatialObject {
2281
+ var SpatialEntity = class extends SpatialObject {
2211
2282
  constructor(id, userData) {
2212
2283
  super(id);
2213
2284
  this.userData = userData;
@@ -2219,9 +2290,26 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
2219
2290
  events = {};
2220
2291
  children = [];
2221
2292
  parent = null;
2293
+ _enableInput = false;
2294
+ get enableInput() {
2295
+ return this._enableInput;
2296
+ }
2297
+ set enableInput(value) {
2298
+ if (this._enableInput === value) return;
2299
+ this._enableInput = value;
2300
+ void this.updateEntityEvent("spatialtap", value).catch((err) => {
2301
+ console.error("enableInput updateEntityEvent failed", "spatialtap", err);
2302
+ if (this._enableInput === value) {
2303
+ this._enableInput = !value;
2304
+ }
2305
+ });
2306
+ }
2222
2307
  async addComponent(component) {
2223
2308
  return new AddComponentToEntityCommand(this, component).execute();
2224
2309
  }
2310
+ async removeComponent(component) {
2311
+ return new RemoveComponentFromEntityCommand(this, component).execute();
2312
+ }
2225
2313
  async setPosition(position) {
2226
2314
  return this.updateTransform({ position });
2227
2315
  }
@@ -2286,10 +2374,7 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
2286
2374
  if (type === "objectdestroy" /* objectdestroy */) {
2287
2375
  this.isDestroyed = true;
2288
2376
  } else if (type === "spatialtap" /* spatialtap */) {
2289
- const evt = createSpatialEvent(
2290
- "spatialtap" /* spatialtap */,
2291
- data.detail
2292
- );
2377
+ const evt = createSpatialEvent("spatialtap" /* spatialtap */, data.detail);
2293
2378
  this.dispatchEvent(evt);
2294
2379
  } else if (type === "spatialdragstart" /* spatialdragstart */) {
2295
2380
  const evt = createSpatialEvent(
@@ -2298,10 +2383,7 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
2298
2383
  );
2299
2384
  this.dispatchEvent(evt);
2300
2385
  } else if (type === "spatialdrag" /* spatialdrag */) {
2301
- const evt = createSpatialEvent(
2302
- "spatialdrag" /* spatialdrag */,
2303
- data.detail
2304
- );
2386
+ const evt = createSpatialEvent("spatialdrag" /* spatialdrag */, data.detail);
2305
2387
  this.dispatchEvent(evt);
2306
2388
  } else if (type === "spatialdragend" /* spatialdragend */) {
2307
2389
  const evt = createSpatialEvent(
@@ -2341,7 +2423,7 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
2341
2423
  }
2342
2424
  this.events[evt.type]?.(evt);
2343
2425
  if (evt.bubbles && !evt.cancelBubble) {
2344
- if (this.parent && this.parent instanceof _SpatialEntity) {
2426
+ if (this.parent) {
2345
2427
  this.parent.dispatchEvent(evt);
2346
2428
  }
2347
2429
  }
@@ -2380,6 +2462,7 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
2380
2462
  };
2381
2463
 
2382
2464
  // src/reality/entity/SpatialModelEntity.ts
2465
+ init_JSBCommand();
2383
2466
  var SpatialModelEntity = class extends SpatialEntity {
2384
2467
  constructor(id, options, userData) {
2385
2468
  super(id, userData);
@@ -2387,6 +2470,9 @@ var SpatialModelEntity = class extends SpatialEntity {
2387
2470
  this.options = options;
2388
2471
  this.userData = userData;
2389
2472
  }
2473
+ async setMaterials(materials) {
2474
+ return new SetMaterialsOnEntityCommand(this.id, materials).execute();
2475
+ }
2390
2476
  };
2391
2477
 
2392
2478
  // src/reality/component/SpatialComponent.ts
@@ -2704,6 +2790,7 @@ var SpatialSession = class {
2704
2790
  // src/Spatial.ts
2705
2791
  init_SpatialWebEvent();
2706
2792
  var Spatial = class {
2793
+ wsAppShellVersionFromUA;
2707
2794
  /**
2708
2795
  * Requests a spatial session object from the browser.
2709
2796
  * This is the primary method to initialize spatial functionality.
@@ -2729,6 +2816,20 @@ var Spatial = class {
2729
2816
  }
2730
2817
  return false;
2731
2818
  }
2819
+ getShellVersionFromUA() {
2820
+ if (this.wsAppShellVersionFromUA !== void 0) {
2821
+ return this.wsAppShellVersionFromUA;
2822
+ }
2823
+ if (typeof navigator === "undefined" || typeof navigator.userAgent !== "string") {
2824
+ this.wsAppShellVersionFromUA = null;
2825
+ return null;
2826
+ }
2827
+ const match = navigator.userAgent.match(
2828
+ /WSAppShell\/(\d+(?:\.\d+){2}(?:[-+][0-9A-Za-z.-]+)*)/
2829
+ );
2830
+ this.wsAppShellVersionFromUA = match ? match[1] : "1.3.0";
2831
+ return this.wsAppShellVersionFromUA;
2832
+ }
2732
2833
  /** @deprecated
2733
2834
  * Checks if WebSpatial is supported in the current environment.
2734
2835
  * Verifies compatibility between native and client versions.
@@ -2746,7 +2847,7 @@ var Spatial = class {
2746
2847
  if (window.__WebSpatialData && window.__WebSpatialData.getNativeVersion) {
2747
2848
  return window.__WebSpatialData.getNativeVersion();
2748
2849
  }
2749
- return window.WebSpatailNativeVersion === "PACKAGE_VERSION" ? this.getClientVersion() : window.WebSpatailNativeVersion;
2850
+ return window.WebSpatailNativeVersion === "WS_SHELL_VERSION" ? this.getClientVersion() : window.WebSpatailNativeVersion;
2750
2851
  }
2751
2852
  /** @deprecated
2752
2853
  * Gets the client SDK version.
@@ -2754,10 +2855,70 @@ var Spatial = class {
2754
2855
  * @returns Client SDK version string in format "x.x.x"
2755
2856
  */
2756
2857
  getClientVersion() {
2757
- return "1.3.0";
2858
+ return "1.5.0";
2758
2859
  }
2759
2860
  };
2760
2861
 
2862
+ // src/physicalMetrics.ts
2863
+ var physicalMetrics_exports = {};
2864
+ __export(physicalMetrics_exports, {
2865
+ getValue: () => getValue,
2866
+ physicalToPoint: () => physicalToPoint,
2867
+ pointToPhysical: () => pointToPhysical,
2868
+ subscribe: () => subscribe
2869
+ });
2870
+ init_SpatialWebEvent();
2871
+ var snapshot = {
2872
+ meterToPtUnscaled: 1360,
2873
+ meterToPtScaled: 1360
2874
+ };
2875
+ function getWorldScalingCompensation(options) {
2876
+ return options?.worldScalingCompensation ?? "scaled";
2877
+ }
2878
+ function pointToPhysical(point, options) {
2879
+ updateValue();
2880
+ const compensation = getWorldScalingCompensation(options);
2881
+ if (compensation === "unscaled") {
2882
+ return point / snapshot.meterToPtUnscaled;
2883
+ }
2884
+ return point / snapshot.meterToPtScaled;
2885
+ }
2886
+ function physicalToPoint(physical, options) {
2887
+ updateValue();
2888
+ const compensation = getWorldScalingCompensation(options);
2889
+ if (compensation === "unscaled") {
2890
+ return physical * snapshot.meterToPtUnscaled;
2891
+ }
2892
+ return physical * snapshot.meterToPtScaled;
2893
+ }
2894
+ function updateValue() {
2895
+ if (typeof window === "undefined") return;
2896
+ const src = window.__webspatialsdk__?.physicalMetrics;
2897
+ if (!src) return;
2898
+ const next = {
2899
+ meterToPtScaled: src.meterToPtScaled ?? snapshot.meterToPtScaled,
2900
+ meterToPtUnscaled: src.meterToPtUnscaled ?? snapshot.meterToPtUnscaled
2901
+ };
2902
+ if (next.meterToPtScaled !== snapshot.meterToPtScaled || next.meterToPtUnscaled !== snapshot.meterToPtUnscaled) {
2903
+ snapshot = next;
2904
+ }
2905
+ }
2906
+ function getValue() {
2907
+ updateValue();
2908
+ return snapshot;
2909
+ }
2910
+ function subscribe(cb) {
2911
+ if (typeof window === "undefined") return () => {
2912
+ };
2913
+ const handler = () => {
2914
+ cb();
2915
+ };
2916
+ SpatialWebEvent.addEventReceiver("window", handler);
2917
+ return () => {
2918
+ SpatialWebEvent.removeEventReceiver("window");
2919
+ };
2920
+ }
2921
+
2761
2922
  // src/index.ts
2762
2923
  init_ssr_polyfill();
2763
2924
 
@@ -2909,6 +3070,7 @@ export {
2909
3070
  BaseplateVisibilityValues,
2910
3071
  CubeInfo,
2911
3072
  ModelComponent,
3073
+ physicalMetrics_exports as PhysicalMetrics,
2912
3074
  Spatial,
2913
3075
  SpatialBoxGeometry,
2914
3076
  SpatialComponent,