@webspatial/core-sdk 1.0.4 → 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.
Files changed (82) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +112 -81
  3. package/dist/iife/index.d.ts +683 -561
  4. package/dist/iife/index.global.js +3 -4
  5. package/dist/iife/index.global.js.map +1 -1
  6. package/dist/index.d.ts +683 -561
  7. package/dist/index.js +2193 -1291
  8. package/dist/index.js.map +1 -1
  9. package/package.json +7 -4
  10. package/src/JSBCommand.ts +631 -0
  11. package/src/Spatial.ts +68 -0
  12. package/src/SpatialObject.ts +46 -0
  13. package/src/SpatialScene.ts +75 -0
  14. package/src/SpatialSession.ts +187 -0
  15. package/src/SpatialWebEvent.ts +23 -0
  16. package/src/SpatialWebEventCreator.ts +12 -0
  17. package/src/Spatialized2DElement.ts +51 -0
  18. package/src/SpatializedDynamic3DElement.ts +30 -0
  19. package/src/SpatializedElement.ts +331 -0
  20. package/src/SpatializedElementCreator.ts +45 -0
  21. package/src/SpatializedStatic3DElement.ts +111 -0
  22. package/src/WebMsgCommand.ts +88 -0
  23. package/src/index.ts +23 -1
  24. package/src/platform-adapter/CommandResultUtils.ts +22 -0
  25. package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
  26. package/src/platform-adapter/index.ts +21 -0
  27. package/src/platform-adapter/interface.ts +36 -0
  28. package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
  29. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
  30. package/src/reality/component/ModelComponent.ts +11 -0
  31. package/src/reality/component/SpatialComponent.ts +17 -0
  32. package/src/reality/component/index.ts +2 -0
  33. package/src/reality/entity/SpatialEntity.ts +259 -0
  34. package/src/reality/entity/SpatialModelEntity.ts +15 -0
  35. package/src/reality/entity/index.ts +2 -0
  36. package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
  37. package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
  38. package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
  39. package/src/reality/geometry/SpatialGeometry.ts +12 -0
  40. package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
  41. package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
  42. package/src/reality/geometry/index.ts +6 -0
  43. package/src/reality/index.ts +5 -0
  44. package/src/reality/material/SpatialMaterial.ts +14 -0
  45. package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
  46. package/src/reality/material/index.ts +2 -0
  47. package/src/reality/realityCreator.ts +94 -0
  48. package/src/reality/resource/SpatialModelAsset.ts +11 -0
  49. package/src/reality/resource/index.ts +1 -0
  50. package/src/scene-polyfill.test.ts +376 -0
  51. package/src/scene-polyfill.ts +379 -0
  52. package/src/spatial-window-polyfill.ts +182 -0
  53. package/src/ssr-polyfill.ts +3 -0
  54. package/src/types/global.d.ts +33 -1
  55. package/src/types/internal.ts +13 -0
  56. package/src/types/types.ts +380 -0
  57. package/src/utils.ts +61 -0
  58. package/tsconfig.json +1 -1
  59. package/vitest.config.ts +8 -0
  60. package/src/core/Spatial.ts +0 -50
  61. package/src/core/SpatialEntity.ts +0 -147
  62. package/src/core/SpatialHelper.ts +0 -230
  63. package/src/core/SpatialObject.ts +0 -26
  64. package/src/core/SpatialSession.ts +0 -457
  65. package/src/core/SpatialTransform.ts +0 -26
  66. package/src/core/SpatialWindowContainer.ts +0 -59
  67. package/src/core/component/EventSpatialComponent.ts +0 -32
  68. package/src/core/component/SpatialComponent.ts +0 -26
  69. package/src/core/component/SpatialInputComponent.ts +0 -24
  70. package/src/core/component/SpatialModel3DComponent.ts +0 -223
  71. package/src/core/component/SpatialModelComponent.ts +0 -39
  72. package/src/core/component/SpatialViewComponent.ts +0 -32
  73. package/src/core/component/SpatialWindowComponent.ts +0 -177
  74. package/src/core/component/index.ts +0 -14
  75. package/src/core/index.ts +0 -10
  76. package/src/core/private/WebSpatial.ts +0 -383
  77. package/src/core/private/remote-command/RemoteCommand.ts +0 -15
  78. package/src/core/private/remote-command/index.ts +0 -1
  79. package/src/core/resource/SpatialMeshResource.ts +0 -6
  80. package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
  81. package/src/core/resource/index.ts +0 -2
  82. package/src/core/types.ts +0 -32
package/dist/index.js CHANGED
@@ -2,1521 +2,2423 @@
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.4"
5
+ window.__webspatialsdk__['core-sdk-version'] = "1.1.0"
6
6
  })()
7
7
 
8
-
9
- // src/core/private/remote-command/RemoteCommand.ts
10
- var RemoteCommand = class _RemoteCommand {
11
- static requestCounter = 0;
12
- command;
13
- data;
14
- requestID;
15
- constructor(cmd, data) {
16
- this.command = cmd;
17
- this.data = data;
18
- this.requestID = ++_RemoteCommand.requestCounter;
19
- }
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __esm = (fn, res) => function __init() {
13
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
20
14
  };
21
-
22
- // src/core/private/WebSpatial.ts
23
- var WindowContainer = class {
24
- id = "";
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
25
18
  };
26
- var WebSpatialResource = class {
27
- id = "";
28
- windowContainerId = "";
29
- data = {};
30
- receiveEvent() {
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
24
  }
25
+ return to;
32
26
  };
33
- var WebSpatial = class _WebSpatial {
34
- static eventPromises = {};
35
- static transactionStarted = false;
36
- static transactionCommands = Array();
37
- // store event receivers
38
- static eventReceivers = {};
39
- static registerEventReceiver(resourceId, callback) {
40
- this.eventReceivers[resourceId] = callback;
41
- }
42
- static unregisterEventReceiver(resourceId) {
43
- delete this.eventReceivers[resourceId];
44
- }
45
- static init() {
46
- window.__SpatialWebEvent = (e) => {
47
- if (e.resourceId) {
48
- var callback = _WebSpatial.eventReceivers[e.resourceId];
49
- callback(e.data);
50
- } else {
51
- var p = _WebSpatial.eventPromises[e.requestID];
52
- if (p) {
53
- if (e.success) {
54
- p.res(e);
55
- } else {
56
- p.rej(e);
57
- }
58
- }
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/ssr-polyfill.ts
30
+ var isSSR, isSSREnv;
31
+ var init_ssr_polyfill = __esm({
32
+ "src/ssr-polyfill.ts"() {
33
+ "use strict";
34
+ isSSR = typeof window === "undefined";
35
+ isSSREnv = () => isSSR;
36
+ }
37
+ });
38
+
39
+ // src/platform-adapter/ssr/SSRPlatform.ts
40
+ var SSRPlatform;
41
+ var init_SSRPlatform = __esm({
42
+ "src/platform-adapter/ssr/SSRPlatform.ts"() {
43
+ "use strict";
44
+ SSRPlatform = class {
45
+ callJSB(cmd, msg) {
46
+ return Promise.resolve({
47
+ success: true,
48
+ data: void 0,
49
+ errorCode: void 0,
50
+ errorMessage: void 0
51
+ });
52
+ }
53
+ callWebSpatialProtocol(schema, query, target, features) {
54
+ return Promise.resolve({
55
+ success: true,
56
+ data: void 0,
57
+ errorCode: void 0,
58
+ errorMessage: void 0
59
+ });
60
+ }
61
+ callWebSpatialProtocolSync(schema, query, target, features, resultCallback) {
62
+ return {
63
+ success: true,
64
+ data: void 0,
65
+ errorCode: void 0,
66
+ errorMessage: void 0
67
+ };
59
68
  }
60
69
  };
61
70
  }
62
- static startTransaction() {
63
- _WebSpatial.transactionStarted = true;
64
- _WebSpatial.transactionCommands = [];
65
- }
66
- static async sendTransaction() {
67
- _WebSpatial.transactionStarted = false;
68
- var cmd = new RemoteCommand("multiCommand", {
69
- commandList: _WebSpatial.transactionCommands
70
- });
71
- var result = await new Promise((res, rej) => {
72
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
73
- _WebSpatial.sendCommand(cmd);
74
- });
75
- return result;
76
- }
77
- static getBackend() {
78
- if (window.webkit) {
79
- return "AVP";
80
- } else {
81
- return "UNKNOWN";
82
- }
83
- }
84
- static async sendCommand(cmd) {
85
- if (window.__WebSpatialUnloaded) {
86
- return;
87
- }
88
- if (_WebSpatial.transactionStarted) {
89
- _WebSpatial.transactionCommands.push(cmd);
90
- return;
91
- }
92
- var msg = JSON.stringify(cmd);
93
- if (_WebSpatial.getBackend() == "AVP") {
94
- window.webkit.messageHandlers.bridge.postMessage(msg);
95
- return;
96
- } else {
97
- window.__WebSpatialData.androidNativeMessage(msg);
98
- return;
99
- }
71
+ });
72
+
73
+ // src/platform-adapter/CommandResultUtils.ts
74
+ function CommandResultSuccess(data) {
75
+ return {
76
+ success: true,
77
+ data,
78
+ errorCode: "",
79
+ errorMessage: ""
80
+ };
81
+ }
82
+ function CommandResultFailure(errorCode, errorMessage = "") {
83
+ return {
84
+ success: false,
85
+ data: void 0,
86
+ errorCode,
87
+ errorMessage
88
+ };
89
+ }
90
+ var init_CommandResultUtils = __esm({
91
+ "src/platform-adapter/CommandResultUtils.ts"() {
92
+ "use strict";
100
93
  }
101
- static getImmersiveWindowContainer() {
102
- var wg = new WindowContainer();
103
- wg.id = "Immersive";
104
- return wg;
105
- }
106
- static getCurrentWindowContainer() {
107
- var wg = new WindowContainer();
108
- wg.id = "current";
109
- return wg;
110
- }
111
- static getCurrentWebPanel() {
112
- var wg = new WebSpatialResource();
113
- wg.id = "current";
114
- wg.windowContainerId = _WebSpatial.getCurrentWindowContainer().id;
115
- return wg;
116
- }
117
- static async createScene(style = "Plain", cfg) {
118
- const { window: newWindow, ...sceneData } = cfg.sceneData;
119
- const jsbSceneData = {
120
- ...sceneData,
121
- windowID: newWindow._webSpatialID,
122
- windowContainerID: newWindow._webSpatialGroupID
94
+ });
95
+
96
+ // src/SpatialWebEvent.ts
97
+ var SpatialWebEvent;
98
+ var init_SpatialWebEvent = __esm({
99
+ "src/SpatialWebEvent.ts"() {
100
+ "use strict";
101
+ SpatialWebEvent = class _SpatialWebEvent {
102
+ static eventReceiver = {};
103
+ static init() {
104
+ window.__SpatialWebEvent = ({ id, data }) => {
105
+ _SpatialWebEvent.eventReceiver[id]?.(data);
106
+ };
107
+ }
108
+ static addEventReceiver(id, callback) {
109
+ _SpatialWebEvent.eventReceiver[id] = callback;
110
+ }
111
+ static removeEventReceiver(id) {
112
+ delete _SpatialWebEvent.eventReceiver[id];
113
+ }
123
114
  };
124
- var cmd = new RemoteCommand("createScene", {
125
- windowStyle: style,
126
- sceneData: jsbSceneData,
127
- windowContainerID: window._webSpatialParentGroupID
128
- // parent WindowContainerID
129
- });
130
- try {
131
- await new Promise((res, rej) => {
132
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
133
- _WebSpatial.sendCommand(cmd);
134
- });
135
- return true;
136
- } catch (error) {
137
- return false;
138
- }
139
- }
140
- static async createWindowContainer(style = "Plain", windowContainer, parentWebView) {
141
- var cmd = new RemoteCommand("createWindowContainer", {
142
- windowStyle: style,
143
- windowContainerID: windowContainer ? windowContainer.id : void 0,
144
- resourceID: parentWebView ? parentWebView.id : void 0
145
- });
146
- var result = await new Promise((res2, rej) => {
147
- _WebSpatial.eventPromises[cmd.requestID] = { res: res2, rej };
148
- _WebSpatial.sendCommand(cmd);
149
- });
150
- var res = new WindowContainer();
151
- res.id = result.data.createdID;
152
- return res;
153
- }
154
- static async destroyResource(resource) {
155
- const data = {};
156
- var cmd = new RemoteCommand("destroyResource", {
157
- windowContainerID: resource.windowContainerId,
158
- resourceID: resource.id
159
- });
160
- _WebSpatial.sendCommand(cmd);
161
115
  }
162
- static async ping(msg) {
163
- var cmd = new RemoteCommand("ping", {
164
- windowContainerID: this.getCurrentWindowContainer().id,
165
- resourceID: this.getCurrentWebPanel().id,
166
- message: msg
167
- });
168
- if (_WebSpatial.transactionStarted) {
169
- _WebSpatial.sendCommand(cmd);
170
- return null;
171
- } else {
172
- var result = await new Promise((res, rej) => {
173
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
174
- _WebSpatial.sendCommand(cmd);
175
- });
176
- return result;
177
- }
116
+ });
117
+
118
+ // src/platform-adapter/android/AndroidPlatform.ts
119
+ var AndroidPlatform_exports = {};
120
+ __export(AndroidPlatform_exports, {
121
+ AndroidPlatform: () => AndroidPlatform
122
+ });
123
+ function nextRequestId() {
124
+ requestId = (requestId + 1) % MAX_ID;
125
+ return `rId_${requestId}`;
126
+ }
127
+ var creatingElementCount, requestId, MAX_ID, AndroidPlatform;
128
+ var init_AndroidPlatform = __esm({
129
+ "src/platform-adapter/android/AndroidPlatform.ts"() {
130
+ "use strict";
131
+ init_CommandResultUtils();
132
+ init_JSBCommand();
133
+ init_SpatialWebEvent();
134
+ creatingElementCount = 0;
135
+ requestId = 0;
136
+ MAX_ID = 1e5;
137
+ AndroidPlatform = class {
138
+ async callJSB(cmd, msg) {
139
+ return new Promise((resolve, reject) => {
140
+ try {
141
+ const rId = nextRequestId();
142
+ SpatialWebEvent.addEventReceiver(rId, (result) => {
143
+ SpatialWebEvent.removeEventReceiver(rId);
144
+ if (result.success) {
145
+ resolve(CommandResultSuccess(result.data));
146
+ } else {
147
+ const { code, message } = result.data;
148
+ resolve(CommandResultFailure(code, message));
149
+ }
150
+ });
151
+ const ans = window.webspatialBridge.postMessage(rId, cmd, msg);
152
+ if (ans !== "") {
153
+ SpatialWebEvent.removeEventReceiver(rId);
154
+ const result = JSON.parse(ans);
155
+ if (result.success) {
156
+ resolve(CommandResultSuccess(result.data));
157
+ } else {
158
+ const { code, message } = result.data;
159
+ resolve(CommandResultFailure(code, message));
160
+ }
161
+ }
162
+ } catch (error) {
163
+ console.error(
164
+ `AndroidPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`
165
+ );
166
+ const { code, message } = error;
167
+ resolve(CommandResultFailure(code, message));
168
+ }
169
+ });
170
+ }
171
+ async callWebSpatialProtocol(command, query, target, features) {
172
+ await new Promise((resolve) => setTimeout(resolve, 16 * creatingElementCount));
173
+ creatingElementCount++;
174
+ let canCreate = await new CheckWebViewCanCreateCommand().execute();
175
+ while (!canCreate.data.can) {
176
+ await new Promise((resolve) => setTimeout(resolve, 16));
177
+ canCreate = await new CheckWebViewCanCreateCommand().execute();
178
+ }
179
+ const { windowProxy } = this.openWindow(command, query, target, features);
180
+ while (!windowProxy?.open) {
181
+ await new Promise((resolve) => setTimeout(resolve, 16));
182
+ }
183
+ windowProxy?.open("about:blank", "_self");
184
+ while (!windowProxy?.__SpatialId) {
185
+ await new Promise((resolve) => setTimeout(resolve, 16));
186
+ }
187
+ let spatialId = windowProxy?.__SpatialId;
188
+ creatingElementCount--;
189
+ return Promise.resolve(
190
+ CommandResultSuccess({ windowProxy, id: spatialId })
191
+ );
192
+ }
193
+ callWebSpatialProtocolSync(command, query, target, features) {
194
+ const { spatialId: id = "", windowProxy } = this.openWindow(
195
+ command,
196
+ query,
197
+ target,
198
+ features
199
+ );
200
+ return CommandResultSuccess({ windowProxy, id });
201
+ }
202
+ openWindow(command, query, target, features) {
203
+ const windowProxy = window.open(
204
+ `webspatial://${command}?${query || ""}`,
205
+ target,
206
+ features
207
+ );
208
+ return { spatialId: "", windowProxy };
209
+ }
210
+ };
178
211
  }
179
- static async getStats() {
180
- var cmd = new RemoteCommand("getStats", {
181
- windowContainerID: this.getCurrentWindowContainer().id,
182
- resourceID: this.getCurrentWebPanel().id
183
- });
184
- var result = await new Promise((res, rej) => {
185
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
186
- _WebSpatial.sendCommand(cmd);
187
- });
188
- return result.data;
212
+ });
213
+
214
+ // src/platform-adapter/vision-os/VisionOSPlatform.ts
215
+ var VisionOSPlatform_exports = {};
216
+ __export(VisionOSPlatform_exports, {
217
+ VisionOSPlatform: () => VisionOSPlatform
218
+ });
219
+ var VisionOSPlatform;
220
+ var init_VisionOSPlatform = __esm({
221
+ "src/platform-adapter/vision-os/VisionOSPlatform.ts"() {
222
+ "use strict";
223
+ init_CommandResultUtils();
224
+ VisionOSPlatform = class {
225
+ async callJSB(cmd, msg) {
226
+ try {
227
+ const result = await window.webkit.messageHandlers.bridge.postMessage(
228
+ `${cmd}::${msg}`
229
+ );
230
+ return CommandResultSuccess(result);
231
+ } catch (error) {
232
+ const { code, message } = JSON.parse(error.message);
233
+ return CommandResultFailure(code, message);
234
+ }
235
+ }
236
+ callWebSpatialProtocol(command, query, target, features) {
237
+ const { spatialId: id, windowProxy } = this.openWindow(
238
+ command,
239
+ query,
240
+ target,
241
+ features
242
+ );
243
+ return Promise.resolve(
244
+ CommandResultSuccess({ windowProxy, id })
245
+ );
246
+ }
247
+ callWebSpatialProtocolSync(command, query, target, features) {
248
+ const { spatialId: id = "", windowProxy } = this.openWindow(
249
+ command,
250
+ query,
251
+ target,
252
+ features
253
+ );
254
+ return CommandResultSuccess({ windowProxy, id });
255
+ }
256
+ openWindow(command, query, target, features) {
257
+ const windowProxy = window.open(
258
+ `webspatial://${command}?${query || ""}`,
259
+ target,
260
+ features
261
+ );
262
+ const ua = windowProxy?.navigator.userAgent;
263
+ const spatialId = ua?.match(
264
+ /\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi
265
+ )?.[0];
266
+ return { spatialId, windowProxy };
267
+ }
268
+ };
189
269
  }
190
- static async inspect(spatialObjectId) {
191
- var cmd = new RemoteCommand("inspect", {
192
- resourceID: spatialObjectId
193
- });
194
- var result = await new Promise((res, rej) => {
195
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
196
- _WebSpatial.sendCommand(cmd);
197
- });
198
- return result.data;
270
+ });
271
+
272
+ // src/platform-adapter/index.ts
273
+ function createPlatform() {
274
+ if (isSSREnv()) {
275
+ return new SSRPlatform();
276
+ }
277
+ if (window.navigator.userAgent.includes("Android") || window.navigator.userAgent.includes("Linux")) {
278
+ const AndroidPlatform2 = (init_AndroidPlatform(), __toCommonJS(AndroidPlatform_exports)).AndroidPlatform;
279
+ return new AndroidPlatform2();
280
+ } else {
281
+ const VisionOSPlatform2 = (init_VisionOSPlatform(), __toCommonJS(VisionOSPlatform_exports)).VisionOSPlatform;
282
+ return new VisionOSPlatform2();
199
283
  }
200
- static async inspectRootWindowContainer() {
201
- return this.inspect("root");
284
+ }
285
+ var init_platform_adapter = __esm({
286
+ "src/platform-adapter/index.ts"() {
287
+ "use strict";
288
+ init_ssr_polyfill();
289
+ init_SSRPlatform();
202
290
  }
203
- static async setComponent(entity, resource) {
204
- var cmd = new RemoteCommand("setComponent", {
205
- windowContainerID: entity.windowContainerId,
206
- resourceID: resource.id,
207
- entityID: entity.id
208
- });
209
- _WebSpatial.sendCommand(cmd);
291
+ });
292
+
293
+ // src/utils.ts
294
+ function parseBorderRadius(borderProperty, width) {
295
+ if (borderProperty === "") {
296
+ return 0;
210
297
  }
211
- static async removeComponent(entity, resource) {
212
- var cmd = new RemoteCommand("removeComponent", {
213
- windowContainerID: entity.windowContainerId,
214
- resourceID: resource.id,
215
- entityID: entity.id
216
- });
217
- _WebSpatial.sendCommand(cmd);
218
- }
219
- // windowContainer is the group the resource will be tied to (if not provided it will use the current window grou)
220
- // parentWebView is the SpatialWebView that the resource will be tied to (if not provided, resource will continue to exist even if this page is unloaded)
221
- static async createResource(type, windowContainer, parentWebView, params = {}) {
222
- var cmd = new RemoteCommand("createResource", {
223
- windowContainerID: windowContainer ? windowContainer.id : void 0,
224
- resourceID: parentWebView ? parentWebView.id : void 0,
225
- type,
226
- params
227
- });
228
- var result = await new Promise((res2, rej) => {
229
- _WebSpatial.eventPromises[cmd.requestID] = { res: res2, rej };
230
- _WebSpatial.sendCommand(cmd);
231
- });
232
- var res = new WebSpatialResource();
233
- res.id = result.data.createdID;
234
- res.windowContainerId = cmd.data.windowContainerID;
235
- return res;
236
- }
237
- static async updateWindowContainer(wg, data) {
238
- var cmd = new RemoteCommand("updateWindowContainer", {
239
- windowContainerID: wg.id,
240
- update: data
241
- });
242
- var result = await new Promise((res, rej) => {
243
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
244
- _WebSpatial.sendCommand(cmd);
245
- });
246
- return result;
298
+ if (borderProperty.endsWith("%")) {
299
+ return width * parseFloat(borderProperty) / 100;
247
300
  }
248
- static async updateResource(resource, data = null) {
249
- var cmd = new RemoteCommand("updateResource", {
250
- windowContainerID: resource.windowContainerId,
251
- resourceID: resource.id,
252
- update: data || resource.data
253
- });
254
- var result = await new Promise((res, rej) => {
255
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
256
- _WebSpatial.sendCommand(cmd);
257
- });
258
- return result;
301
+ return parseFloat(borderProperty);
302
+ }
303
+ function parseCornerRadius(computedStyle) {
304
+ const width = parseFloat(computedStyle.getPropertyValue("width"));
305
+ const topLeftPropertyValue = computedStyle.getPropertyValue(
306
+ "border-top-left-radius"
307
+ );
308
+ const topRightPropertyValue = computedStyle.getPropertyValue(
309
+ "border-top-right-radius"
310
+ );
311
+ const bottomLeftPropertyValue = computedStyle.getPropertyValue(
312
+ "border-bottom-left-radius"
313
+ );
314
+ const bottomRightPropertyValue = computedStyle.getPropertyValue(
315
+ "border-bottom-right-radius"
316
+ );
317
+ const cornerRadius = {
318
+ topLeading: parseBorderRadius(topLeftPropertyValue, width),
319
+ bottomLeading: parseBorderRadius(bottomLeftPropertyValue, width),
320
+ topTrailing: parseBorderRadius(topRightPropertyValue, width),
321
+ bottomTrailing: parseBorderRadius(bottomRightPropertyValue, width)
322
+ };
323
+ return cornerRadius;
324
+ }
325
+ function composeSRT(position, rotation, scale) {
326
+ const { x: px, y: py, z: pz } = position;
327
+ const { x: rx, y: ry, z: rz } = rotation;
328
+ const { x: sx, y: sy, z: sz } = scale;
329
+ let m = new DOMMatrix();
330
+ m = m.translate(px, py, pz);
331
+ m = m.rotate(rx, ry, rz);
332
+ m = m.scale(sx, sy, sz);
333
+ return m;
334
+ }
335
+ var init_utils = __esm({
336
+ "src/utils.ts"() {
337
+ "use strict";
259
338
  }
260
- static async setLoading(method, style) {
261
- var cmd = new RemoteCommand("setLoading", {
262
- windowContainerID: window._webSpatialParentGroupID,
263
- // parent WindowContainerID
264
- loading: {
265
- method,
266
- style
339
+ });
340
+
341
+ // src/JSBCommand.ts
342
+ 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;
343
+ var init_JSBCommand = __esm({
344
+ "src/JSBCommand.ts"() {
345
+ "use strict";
346
+ init_platform_adapter();
347
+ init_utils();
348
+ platform = createPlatform();
349
+ JSBCommand = class {
350
+ commandType = "";
351
+ async execute() {
352
+ const param = this.getParams();
353
+ const msg = param ? JSON.stringify(param) : "";
354
+ return platform.callJSB(this.commandType, msg);
355
+ }
356
+ };
357
+ UpdateEntityPropertiesCommand = class extends JSBCommand {
358
+ constructor(entity, properties) {
359
+ super();
360
+ this.entity = entity;
361
+ this.properties = properties;
362
+ }
363
+ commandType = "UpdateEntityProperties";
364
+ getParams() {
365
+ const transform = composeSRT(
366
+ this.properties.position ?? this.entity.position,
367
+ this.properties.rotation ?? this.entity.rotation,
368
+ this.properties.scale ?? this.entity.scale
369
+ ).toFloat64Array();
370
+ return {
371
+ entityId: this.entity.id,
372
+ transform
373
+ };
374
+ }
375
+ };
376
+ UpdateEntityEventCommand = class extends JSBCommand {
377
+ constructor(entity, type, isEnable) {
378
+ super();
379
+ this.entity = entity;
380
+ this.type = type;
381
+ this.isEnable = isEnable;
382
+ }
383
+ commandType = "UpdateEntityEvent";
384
+ getParams() {
385
+ return {
386
+ type: this.type,
387
+ entityId: this.entity.id,
388
+ isEnable: this.isEnable
389
+ };
390
+ }
391
+ };
392
+ UpdateSpatialSceneProperties = class extends JSBCommand {
393
+ properties;
394
+ commandType = "UpdateSpatialSceneProperties";
395
+ constructor(properties) {
396
+ super();
397
+ this.properties = properties;
398
+ }
399
+ getParams() {
400
+ return this.properties;
401
+ }
402
+ };
403
+ UpdateSceneConfig = class extends JSBCommand {
404
+ config;
405
+ commandType = "UpdateSceneConfig";
406
+ constructor(config) {
407
+ super();
408
+ this.config = config;
409
+ }
410
+ getParams() {
411
+ return { config: this.config };
412
+ }
413
+ };
414
+ FocusScene = class extends JSBCommand {
415
+ constructor(id) {
416
+ super();
417
+ this.id = id;
418
+ }
419
+ commandType = "FocusScene";
420
+ getParams() {
421
+ return { id: this.id };
422
+ }
423
+ };
424
+ GetSpatialSceneState = class extends JSBCommand {
425
+ commandType = "GetSpatialSceneState";
426
+ constructor() {
427
+ super();
428
+ }
429
+ getParams() {
430
+ return {};
431
+ }
432
+ };
433
+ SpatializedElementCommand = class extends JSBCommand {
434
+ constructor(spatialObject) {
435
+ super();
436
+ this.spatialObject = spatialObject;
437
+ }
438
+ getParams() {
439
+ const extraParams = this.getExtraParams();
440
+ return { id: this.spatialObject.id, ...extraParams };
441
+ }
442
+ };
443
+ UpdateSpatialized2DElementProperties = class extends SpatializedElementCommand {
444
+ properties;
445
+ commandType = "UpdateSpatialized2DElementProperties";
446
+ constructor(spatialObject, properties) {
447
+ super(spatialObject);
448
+ this.properties = properties;
449
+ }
450
+ getExtraParams() {
451
+ return this.properties;
452
+ }
453
+ };
454
+ UpdateSpatializedDynamic3DElementProperties = class extends SpatializedElementCommand {
455
+ properties;
456
+ commandType = "UpdateSpatializedDynamic3DElementProperties";
457
+ constructor(spatialObject, properties) {
458
+ super(spatialObject);
459
+ this.properties = properties;
460
+ }
461
+ getExtraParams() {
462
+ return {
463
+ id: this.spatialObject.id,
464
+ ...this.properties
465
+ };
466
+ }
467
+ };
468
+ UpdateUnlitMaterialProperties = class extends SpatializedElementCommand {
469
+ properties;
470
+ commandType = "UpdateUnlitMaterialProperties";
471
+ constructor(spatialObject, properties) {
472
+ super(spatialObject);
473
+ this.properties = properties;
474
+ }
475
+ getExtraParams() {
476
+ return this.properties;
477
+ }
478
+ };
479
+ UpdateSpatializedElementTransform = class extends SpatializedElementCommand {
480
+ matrix;
481
+ commandType = "UpdateSpatializedElementTransform";
482
+ constructor(spatialObject, matrix) {
483
+ super(spatialObject);
484
+ this.matrix = matrix;
485
+ }
486
+ getExtraParams() {
487
+ return { matrix: Array.from(this.matrix.toFloat64Array()) };
488
+ }
489
+ };
490
+ UpdateSpatializedStatic3DElementProperties = class extends SpatializedElementCommand {
491
+ properties;
492
+ commandType = "UpdateSpatializedStatic3DElementProperties";
493
+ constructor(spatialObject, properties) {
494
+ super(spatialObject);
495
+ this.properties = properties;
496
+ }
497
+ getExtraParams() {
498
+ return this.properties;
499
+ }
500
+ };
501
+ AddSpatializedElementToSpatialized2DElement = class extends SpatializedElementCommand {
502
+ commandType = "AddSpatializedElementToSpatialized2DElement";
503
+ spatializedElement;
504
+ constructor(spatialObject, spatializedElement) {
505
+ super(spatialObject);
506
+ this.spatializedElement = spatializedElement;
507
+ }
508
+ getExtraParams() {
509
+ return { spatializedElementId: this.spatializedElement.id };
510
+ }
511
+ };
512
+ AddSpatializedElementToSpatialScene = class extends JSBCommand {
513
+ commandType = "AddSpatializedElementToSpatialScene";
514
+ spatializedElement;
515
+ constructor(spatializedElement) {
516
+ super();
517
+ this.spatializedElement = spatializedElement;
518
+ }
519
+ getParams() {
520
+ return {
521
+ spatializedElementId: this.spatializedElement.id
522
+ };
523
+ }
524
+ };
525
+ CreateSpatializedStatic3DElementCommand = class extends JSBCommand {
526
+ constructor(modelURL) {
527
+ super();
528
+ this.modelURL = modelURL;
529
+ this.modelURL = modelURL;
530
+ }
531
+ commandType = "CreateSpatializedStatic3DElement";
532
+ getParams() {
533
+ return { modelURL: this.modelURL };
534
+ }
535
+ };
536
+ CreateSpatializedDynamic3DElementCommand = class extends JSBCommand {
537
+ getParams() {
538
+ return { test: true };
539
+ }
540
+ commandType = "CreateSpatializedDynamic3DElement";
541
+ };
542
+ CreateSpatialEntityCommand = class extends JSBCommand {
543
+ constructor(name) {
544
+ super();
545
+ this.name = name;
546
+ }
547
+ getParams() {
548
+ return { name: this.name };
549
+ }
550
+ commandType = "CreateSpatialEntity";
551
+ };
552
+ CreateModelComponentCommand = class extends JSBCommand {
553
+ constructor(options) {
554
+ super();
555
+ this.options = options;
556
+ }
557
+ getParams() {
558
+ let geometryId = this.options.mesh.id;
559
+ let materialIds = this.options.materials.map((material) => material.id);
560
+ return { geometryId, materialIds };
561
+ }
562
+ commandType = "CreateModelComponent";
563
+ };
564
+ CreateSpatialModelEntityCommand = class extends JSBCommand {
565
+ constructor(options) {
566
+ super();
567
+ this.options = options;
568
+ }
569
+ getParams() {
570
+ return this.options;
571
+ }
572
+ commandType = "CreateSpatialModelEntity";
573
+ };
574
+ CreateModelAssetCommand = class extends JSBCommand {
575
+ constructor(options) {
576
+ super();
577
+ this.options = options;
578
+ }
579
+ getParams() {
580
+ return { url: this.options.url };
581
+ }
582
+ commandType = "CreateModelAsset";
583
+ };
584
+ CreateSpatialGeometryCommand = class extends JSBCommand {
585
+ constructor(type, options = {}) {
586
+ super();
587
+ this.type = type;
588
+ this.options = options;
589
+ }
590
+ getParams() {
591
+ return { type: this.type, ...this.options };
592
+ }
593
+ commandType = "CreateGeometry";
594
+ };
595
+ CreateSpatialUnlitMaterialCommand = class extends JSBCommand {
596
+ constructor(options) {
597
+ super();
598
+ this.options = options;
599
+ }
600
+ getParams() {
601
+ return this.options;
602
+ }
603
+ commandType = "CreateUnlitMaterial";
604
+ };
605
+ AddComponentToEntityCommand = class extends JSBCommand {
606
+ constructor(entity, comp) {
607
+ super();
608
+ this.entity = entity;
609
+ this.comp = comp;
610
+ }
611
+ getParams() {
612
+ return {
613
+ entityId: this.entity.id,
614
+ componentId: this.comp.id
615
+ };
616
+ }
617
+ commandType = "AddComponentToEntity";
618
+ };
619
+ SetParentForEntityCommand = class extends JSBCommand {
620
+ // childId, parentId
621
+ constructor(childId, parentId) {
622
+ super();
623
+ this.childId = childId;
624
+ this.parentId = parentId;
625
+ }
626
+ getParams() {
627
+ return {
628
+ childId: this.childId,
629
+ parentId: this.parentId
630
+ };
631
+ }
632
+ commandType = "SetParentToEntity";
633
+ };
634
+ ConvertFromEntityToEntityCommand = class extends JSBCommand {
635
+ constructor(fromEntityId, toEntityId, fromPosition) {
636
+ super();
637
+ this.fromEntityId = fromEntityId;
638
+ this.toEntityId = toEntityId;
639
+ this.fromPosition = fromPosition;
640
+ }
641
+ getParams() {
642
+ return {
643
+ fromEntityId: this.fromEntityId,
644
+ toEntityId: this.toEntityId,
645
+ position: this.fromPosition
646
+ };
647
+ }
648
+ commandType = "ConvertFromEntityToEntity";
649
+ };
650
+ ConvertFromEntityToSceneCommand = class extends JSBCommand {
651
+ constructor(fromEntityId, position) {
652
+ super();
653
+ this.fromEntityId = fromEntityId;
654
+ this.position = position;
655
+ }
656
+ getParams() {
657
+ return {
658
+ fromEntityId: this.fromEntityId,
659
+ position: this.position
660
+ };
661
+ }
662
+ commandType = "ConvertFromEntityToScene";
663
+ };
664
+ ConvertFromSceneToEntityCommand = class extends JSBCommand {
665
+ // let entityId: String
666
+ // let position:Vec3
667
+ constructor(entityId, position) {
668
+ super();
669
+ this.entityId = entityId;
670
+ this.position = position;
671
+ }
672
+ getParams() {
673
+ return {
674
+ entityId: this.entityId,
675
+ position: this.position
676
+ };
677
+ }
678
+ commandType = "ConvertFromSceneToEntity";
679
+ };
680
+ InspectCommand = class extends JSBCommand {
681
+ constructor(id = "") {
682
+ super();
683
+ this.id = id;
684
+ }
685
+ commandType = "Inspect";
686
+ getParams() {
687
+ return this.id ? { id: this.id } : { id: "" };
688
+ }
689
+ };
690
+ DestroyCommand = class extends JSBCommand {
691
+ constructor(id) {
692
+ super();
693
+ this.id = id;
694
+ }
695
+ commandType = "Destroy";
696
+ getParams() {
697
+ return { id: this.id };
698
+ }
699
+ };
700
+ CheckWebViewCanCreateCommand = class extends JSBCommand {
701
+ constructor(id = "") {
702
+ super();
703
+ this.id = id;
704
+ }
705
+ commandType = "CheckWebViewCanCreate";
706
+ getParams() {
707
+ return { id: this.id };
708
+ }
709
+ };
710
+ WebSpatialProtocolCommand = class extends JSBCommand {
711
+ target;
712
+ features;
713
+ async execute() {
714
+ const query = this.getQuery();
715
+ return platform.callWebSpatialProtocol(
716
+ this.commandType,
717
+ query,
718
+ this.target,
719
+ this.features
720
+ );
721
+ }
722
+ executeSync() {
723
+ const query = this.getQuery();
724
+ return platform.callWebSpatialProtocolSync(
725
+ this.commandType,
726
+ query,
727
+ this.target,
728
+ this.features
729
+ );
730
+ }
731
+ getQuery() {
732
+ let query = void 0;
733
+ const params = this.getParams();
734
+ if (params) {
735
+ query = Object.keys(params).map((key) => {
736
+ const value = params[key];
737
+ const finalValue = typeof value === "object" ? JSON.stringify(value) : value;
738
+ return `${key}=${encodeURIComponent(finalValue)}`;
739
+ }).join("&");
740
+ }
741
+ return query;
742
+ }
743
+ };
744
+ createSpatialized2DElementCommand = class extends WebSpatialProtocolCommand {
745
+ commandType = "createSpatialized2DElement";
746
+ constructor() {
747
+ super();
748
+ }
749
+ getParams() {
750
+ return {};
751
+ }
752
+ };
753
+ createSpatialSceneCommand = class extends WebSpatialProtocolCommand {
754
+ constructor(url, config, target, features) {
755
+ super();
756
+ this.url = url;
757
+ this.config = config;
758
+ this.target = target;
759
+ this.features = features;
760
+ }
761
+ commandType = "createSpatialScene";
762
+ getParams() {
763
+ return {
764
+ url: this.url,
765
+ config: this.config
766
+ };
267
767
  }
268
- });
269
- var result = await new Promise((res, rej) => {
270
- _WebSpatial.eventPromises[cmd.requestID] = { res, rej };
271
- _WebSpatial.sendCommand(cmd);
272
- });
273
- return result;
274
- }
275
- static async openImmersiveSpace() {
276
- var cmd = new RemoteCommand("openImmersiveSpace");
277
- await _WebSpatial.sendCommand(cmd);
278
- }
279
- static async dismissImmersiveSpace() {
280
- var cmd = new RemoteCommand("dismissImmersiveSpace");
281
- await _WebSpatial.sendCommand(cmd);
282
- }
283
- static onFrame(fn) {
284
- var dt = 0;
285
- var loop = async () => {
286
- var curTime = window.performance.now();
287
- await fn(curTime);
288
- var updateTime = window.performance.now() - curTime;
289
- setTimeout(
290
- () => {
291
- loop();
292
- },
293
- Math.max(1e3 / 60 - updateTime, 0)
294
- );
295
768
  };
296
- loop();
297
769
  }
298
- };
299
- WebSpatial.init();
770
+ });
300
771
 
301
- // src/core/SpatialObject.ts
772
+ // src/SpatialObject.ts
773
+ init_JSBCommand();
302
774
  var SpatialObject = class {
303
775
  /** @hidden */
304
- constructor(_resource) {
305
- this._resource = _resource;
776
+ constructor(id) {
777
+ this.id = id;
778
+ }
779
+ name;
780
+ isDestroyed = false;
781
+ async inspect() {
782
+ const ret = await new InspectCommand(this.id).execute();
783
+ if (ret.success) {
784
+ return ret.data;
785
+ }
786
+ throw new Error(ret.errorMessage);
306
787
  }
307
- /**
308
- * Marks resource to be released (it should no longer be used)
309
- */
310
788
  async destroy() {
311
- await WebSpatial.destroyResource(this._resource);
312
- await this.onDestroy();
789
+ if (this.isDestroyed) {
790
+ return;
791
+ }
792
+ const ret = await new DestroyCommand(this.id).execute();
793
+ if (ret.success) {
794
+ this.onDestroy();
795
+ this.isDestroyed = true;
796
+ return ret.data;
797
+ } else if (this.isDestroyed) {
798
+ return;
799
+ }
800
+ throw new Error(ret.errorMessage);
313
801
  }
314
- name = "";
315
- async onDestroy() {
802
+ // override this method to do some cleanup
803
+ onDestroy() {
316
804
  }
317
805
  };
318
806
 
319
- // src/core/SpatialTransform.ts
320
- var Vec3 = class {
321
- constructor(x = 0, y = 0, z = 0) {
322
- this.x = x;
323
- this.y = y;
324
- this.z = z;
325
- }
326
- };
327
- var Vec4 = class {
328
- constructor(x = 0, y = 0, z = 0, w = 1) {
329
- this.x = x;
330
- this.y = y;
331
- this.z = z;
332
- this.w = w;
333
- }
334
- };
335
- var SpatialTransform = class {
336
- position = new Vec3(0, 0, 0);
337
- /** Quaternion value for x,y,z,w */
338
- orientation = new Vec4(0, 0, 0, 1);
339
- scale = new Vec3(1, 1, 1);
340
- };
807
+ // src/scene-polyfill.ts
808
+ init_JSBCommand();
341
809
 
342
- // src/core/SpatialEntity.ts
343
- var SpatialEntity = class extends SpatialObject {
344
- /**
345
- * Transform corresponding to the entity
346
- * note: updateTransform must be called for transform to be synced to rendering
347
- */
348
- transform = new SpatialTransform();
349
- /** @hidden */
350
- _destroyed = false;
351
- /** @hidden */
352
- get _entity() {
353
- return this._resource;
810
+ // src/SpatialScene.ts
811
+ init_JSBCommand();
812
+ var instance;
813
+ var SpatialScene = class _SpatialScene extends SpatialObject {
814
+ /**
815
+ * Gets the singleton instance of the SpatialScene.
816
+ * Creates a new instance if one doesn't exist yet.
817
+ * @returns The singleton SpatialScene instance
818
+ */
819
+ static getInstance() {
820
+ if (!instance) {
821
+ instance = new _SpatialScene("");
822
+ }
823
+ return instance;
354
824
  }
355
825
  /**
356
- * Syncs the transform with the renderer, must be called to observe updates
826
+ * Updates the properties of the spatial scene.
827
+ * This can include background settings, lighting, and other scene-wide properties.
828
+ * @param properties Partial set of properties to update
829
+ * @returns Promise resolving when the update is complete
357
830
  */
358
- async updateTransform() {
359
- await WebSpatial.updateResource(this._entity, this.transform);
831
+ async updateSpatialProperties(properties) {
832
+ return new UpdateSpatialSceneProperties(properties).execute();
360
833
  }
361
834
  /**
362
- * Syncs the zIndex with the renderer
835
+ * Adds a spatialized element to the scene.
836
+ * This makes the element visible and interactive in the spatial environment.
837
+ * @param element The SpatializedElement to add to the scene
838
+ * @returns Promise resolving when the element is added
363
839
  */
364
- async updateZIndex(zIndex) {
365
- await WebSpatial.updateResource(this._entity, { zIndex });
840
+ async addSpatializedElement(element) {
841
+ return new AddSpatializedElementToSpatialScene(element).execute();
366
842
  }
367
- components = /* @__PURE__ */ new Map();
368
843
  /**
369
- * Attaches a component to the entity to be displayed
370
- * [TODO] review pass by value vs ref and ownership model for this
844
+ * Updates the scene creation configuration.
845
+ * This allows changing scene parameters after initial creation.
846
+ * @param config The new scene creation configuration
847
+ * @returns Promise resolving when the update is complete
371
848
  */
372
- async setComponent(component) {
373
- await WebSpatial.setComponent(this._entity, component._resource);
374
- this.components.set(component.constructor, component);
849
+ async updateSceneCreationConfig(config) {
850
+ return new UpdateSceneConfig(config).execute();
375
851
  }
376
852
  /**
377
- * Removes a component from the entity
853
+ * Gets the current state of the spatial scene.
854
+ * This includes information about active elements and scene configuration.
855
+ * @returns Promise resolving to the current SpatialSceneState
378
856
  */
379
- async removeComponent(type) {
380
- var c = this.getComponent(type);
381
- if (c != void 0) {
382
- await WebSpatial.removeComponent(this._entity, c._resource);
383
- this.components.delete(c.constructor);
857
+ async getState() {
858
+ return (await new GetSpatialSceneState().execute()).data.name;
859
+ }
860
+ };
861
+
862
+ // src/types/types.ts
863
+ var SpatializedElementType = /* @__PURE__ */ ((SpatializedElementType2) => {
864
+ SpatializedElementType2[SpatializedElementType2["Spatialized2DElement"] = 0] = "Spatialized2DElement";
865
+ SpatializedElementType2[SpatializedElementType2["SpatializedStatic3DElement"] = 1] = "SpatializedStatic3DElement";
866
+ SpatializedElementType2[SpatializedElementType2["SpatializedDynamic3DElement"] = 2] = "SpatializedDynamic3DElement";
867
+ return SpatializedElementType2;
868
+ })(SpatializedElementType || {});
869
+ var BaseplateVisibilityValues = [
870
+ "automatic",
871
+ "visible",
872
+ "hidden"
873
+ ];
874
+ function isValidBaseplateVisibilityType(type) {
875
+ return BaseplateVisibilityValues.includes(type);
876
+ }
877
+ var WorldScalingValues = ["automatic", "dynamic"];
878
+ function isValidWorldScalingType(type) {
879
+ return WorldScalingValues.includes(type);
880
+ }
881
+ var WorldAlignmentValues = [
882
+ "adaptive",
883
+ "automatic",
884
+ "gravityAligned"
885
+ ];
886
+ function isValidWorldAlignmentType(type) {
887
+ return WorldAlignmentValues.includes(type);
888
+ }
889
+ var SpatialSceneValues = ["window", "volume"];
890
+ function isValidSpatialSceneType(type) {
891
+ return SpatialSceneValues.includes(type);
892
+ }
893
+ function isValidSceneUnit(val) {
894
+ if (typeof val === "number") {
895
+ return val >= 0;
896
+ }
897
+ if (typeof val === "string") {
898
+ if (val.endsWith("px")) {
899
+ if (isNaN(Number(val.slice(0, -2)))) {
900
+ return false;
901
+ }
902
+ return Number(val.slice(0, -2)) >= 0;
903
+ }
904
+ if (val.endsWith("m")) {
905
+ if (isNaN(Number(val.slice(0, -1)))) {
906
+ return false;
907
+ }
908
+ return Number(val.slice(0, -1)) >= 0;
384
909
  }
385
910
  }
386
- /**
387
- * Gets a component from the entity
388
- */
389
- getComponent(type) {
390
- return this.components.get(type);
911
+ return false;
912
+ }
913
+ var SpatialSceneState = /* @__PURE__ */ ((SpatialSceneState2) => {
914
+ SpatialSceneState2["idle"] = "idle";
915
+ SpatialSceneState2["pending"] = "pending";
916
+ SpatialSceneState2["willVisible"] = "willVisible";
917
+ SpatialSceneState2["visible"] = "visible";
918
+ SpatialSceneState2["fail"] = "fail";
919
+ return SpatialSceneState2;
920
+ })(SpatialSceneState || {});
921
+ var CubeInfo = class {
922
+ constructor(size, origin) {
923
+ this.size = size;
924
+ this.origin = origin;
925
+ this.size = size;
926
+ this.origin = origin;
391
927
  }
392
- /**
393
- * @hidden
394
- * Sets the window container that this entity should be rendered by (this does not effect resource ownership)
395
- * @param wg the window container that should render this entity
396
- */
397
- async _setParentWindowContainer(wg) {
398
- await WebSpatial.updateResource(this._entity, {
399
- setParentWindowContainerID: wg._wg.id
400
- });
928
+ get x() {
929
+ return this.origin.x;
401
930
  }
402
- /**
403
- * Sets a parent entity, if that entity or its parents are attached to a window container, this entity will be displayed
404
- * @param e parent entity or null to remove current parent
405
- */
406
- async setParent(e) {
407
- await WebSpatial.updateResource(this._entity, {
408
- setParent: e ? e._entity.id : ""
409
- });
931
+ get y() {
932
+ return this.origin.y;
410
933
  }
411
- /**
412
- * Sets the coordinate space of this entity (Default: App)
413
- * "App" = game engine style coordinates in meters
414
- * "Dom" = Windowing coordinates in dom units (eg. 0,0,0 is top left of window)
415
- * "Root" = Coordinate space is ignored and content is displayed and updated as window container's root object, window containers can only have one root entity
416
- * [TODO] review this api
417
- * @param space coordinate space mode
418
- */
419
- async setCoordinateSpace(space) {
420
- await WebSpatial.updateResource(this._entity, { setCoordinateSpace: space });
934
+ get z() {
935
+ return this.origin.z;
421
936
  }
422
- /**
423
- * Query the 3d boudning box of the entity
424
- * @returns The bounding box of the entity
425
- */
426
- async getBoundingBox() {
427
- var res = await WebSpatial.updateResource(this._entity, {
428
- getBoundingBox: true
429
- });
430
- return res.data;
937
+ get width() {
938
+ return this.size.width;
431
939
  }
432
- /**
433
- * Sets if the entity should be visible (default: True)
434
- * @param visible
435
- */
436
- async setVisible(visible) {
437
- await WebSpatial.updateResource(this._entity, { visible });
940
+ get height() {
941
+ return this.size.height;
438
942
  }
439
- /**
440
- * Removes a reference to the entity by the renderer and this object should no longer be used. [TODO] Attached components will not be destroyed
441
- */
442
- async destroy() {
443
- this._destroyed = true;
444
- await WebSpatial.destroyResource(this._entity);
943
+ get depth() {
944
+ return this.size.depth;
445
945
  }
446
- /**
447
- * Check if destroy has been called
448
- */
449
- isDestroyed() {
450
- return this._destroyed;
946
+ get left() {
947
+ return this.x;
451
948
  }
452
- // Set Entity name. Currently for debugging only.
453
- /** @hidden */
454
- async _setName(name) {
455
- this.name = name;
456
- return WebSpatial.updateResource(this._entity, { name });
949
+ get top() {
950
+ return this.y;
951
+ }
952
+ get right() {
953
+ return this.x + this.width;
954
+ }
955
+ get bottom() {
956
+ return this.y + this.height;
957
+ }
958
+ get back() {
959
+ return this.z;
960
+ }
961
+ get front() {
962
+ return this.z + this.depth;
457
963
  }
458
964
  };
459
965
 
460
- // src/core/component/SpatialComponent.ts
461
- var SpatialComponent = class extends SpatialObject {
462
- /**
463
- * Gets the entity this component is attached to
464
- * @returns entity or null
465
- */
466
- async getEntity() {
467
- let reqResp = await WebSpatial.updateResource(
468
- WebSpatial.getCurrentWebPanel(),
469
- { getEntityID: "" }
470
- );
471
- if (reqResp.data.parentID === "") {
472
- return new Promise((res2, rej) => {
473
- res2(null);
474
- });
475
- } else {
476
- var res = new WebSpatialResource();
477
- res.id = reqResp.data.parentID;
478
- return new SpatialEntity(res);
479
- }
966
+ // src/scene-polyfill.ts
967
+ var defaultSceneConfig = {
968
+ defaultSize: {
969
+ width: 1280,
970
+ height: 720
480
971
  }
481
972
  };
482
-
483
- // src/core/SpatialWindowContainer.ts
484
- var SpatialWindowContainer = class {
485
- /** @hidden */
486
- constructor(_wg) {
487
- this._wg = _wg;
973
+ var defaultSceneConfigVolume = {
974
+ defaultSize: {
975
+ width: 0.94,
976
+ height: 0.94,
977
+ depth: 0.94
488
978
  }
489
- /**
490
- * @hidden
491
- * Sets sets the open configuration for opening new window containers
492
- * @param options style options
493
- */
494
- async _setOpenSettings(options) {
495
- await WebSpatial.updateWindowContainer(this._wg, {
496
- nextOpenSettings: options
497
- });
979
+ };
980
+ var INTERNAL_SCHEMA_PREFIX = "webspatial://";
981
+ var SceneManager = class _SceneManager {
982
+ originalOpen;
983
+ static instance;
984
+ static getInstance() {
985
+ if (!_SceneManager.instance) {
986
+ _SceneManager.instance = new _SceneManager();
987
+ }
988
+ return _SceneManager.instance;
989
+ }
990
+ init(window2) {
991
+ this.originalOpen = window2.open.bind(window2);
992
+ window2.open = this.open;
993
+ }
994
+ configMap = {};
995
+ // name=>config
996
+ getConfig(name) {
997
+ if (name === void 0 || !this.configMap[name]) return void 0;
998
+ return this.configMap[name];
999
+ }
1000
+ // Ensure URL is absolute; only convert when a relative path is provided
1001
+ // - Keep external and special schemes untouched (http, https, data, blob, about, file, mailto, etc.)
1002
+ // - Handle protocol-relative URLs (//example.com/path)
1003
+ // - Resolve relative paths against document.baseURI (respects <base href>)
1004
+ ensureAbsoluteUrl(raw) {
1005
+ if (!raw) return raw;
1006
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(raw)) {
1007
+ return raw;
1008
+ }
1009
+ if (raw.startsWith("//")) {
1010
+ return `${window.location.protocol}${raw}`;
1011
+ }
1012
+ try {
1013
+ return new URL(raw, document.baseURI).toString();
1014
+ } catch {
1015
+ return raw;
1016
+ }
498
1017
  }
499
- /**
500
- * Retrieves the root entity of the windowContainer
501
- * @returns the root entity of the windowContainer if one exists
502
- */
503
- async getRootEntity() {
504
- let reqResp = await WebSpatial.updateWindowContainer(this._wg, {
505
- getRootEntityID: ""
506
- });
507
- if (reqResp.data.rootEntId === "") {
508
- return null;
1018
+ open = (url, target, features) => {
1019
+ if (url?.startsWith(INTERNAL_SCHEMA_PREFIX)) {
1020
+ return this.originalOpen(url, target, features);
1021
+ }
1022
+ url = this.ensureAbsoluteUrl(url);
1023
+ if (target === "_self" || target === "_parent" || target === "_top") {
1024
+ const newWindow = this.originalOpen(url, target, features);
1025
+ return newWindow;
1026
+ }
1027
+ const cfg = target ? this.getConfig(target) : void 0;
1028
+ const cmd = new createSpatialSceneCommand(url, cfg, target, features);
1029
+ const result = cmd.executeSync();
1030
+ if (typeof target === "string" && this.configMap[target]) {
1031
+ delete this.configMap[target];
1032
+ }
1033
+ const id = result.data?.id;
1034
+ if (id) {
1035
+ let focusCmd = new FocusScene(id);
1036
+ focusCmd.execute();
1037
+ }
1038
+ return result.data?.windowProxy;
1039
+ };
1040
+ initScene(name, callback, options) {
1041
+ const sceneType = options?.type ?? "window";
1042
+ const defaultConfig = getSceneDefaultConfig(sceneType);
1043
+ const rawReturnVal = callback({ ...defaultConfig });
1044
+ const [formattedConfig, errors] = formatSceneConfig(rawReturnVal, sceneType);
1045
+ if (errors.length > 0) {
1046
+ console.warn(`initScene ${name} with errors: ${errors.join(", ")}`);
1047
+ }
1048
+ this.configMap[name] = {
1049
+ ...formattedConfig,
1050
+ type: sceneType
1051
+ };
1052
+ }
1053
+ };
1054
+ function pxToMeter(px) {
1055
+ return px / 1360;
1056
+ }
1057
+ function meterToPx(meter) {
1058
+ return meter * 1360;
1059
+ }
1060
+ function formatToNumber(str, targetUnit, defaultUnit) {
1061
+ if (typeof str === "number") {
1062
+ if (defaultUnit === "px" && targetUnit === "px" || defaultUnit === "m" && targetUnit === "m") {
1063
+ return str;
1064
+ }
1065
+ if (defaultUnit === "px" && targetUnit === "m") {
1066
+ return pxToMeter(str);
1067
+ } else if (defaultUnit === "m" && targetUnit === "px") {
1068
+ return meterToPx(str);
1069
+ }
1070
+ return str;
1071
+ }
1072
+ if (targetUnit === "m") {
1073
+ if (str.endsWith("m")) {
1074
+ return Number(str.slice(0, -1));
1075
+ } else if (str.endsWith("px")) {
1076
+ return pxToMeter(Number(str.slice(0, -2)));
1077
+ } else {
1078
+ throw new Error("formatToNumber: invalid str");
1079
+ }
1080
+ } else if (targetUnit === "px") {
1081
+ if (str.endsWith("px")) {
1082
+ return Number(str.slice(0, -2));
1083
+ } else if (str.endsWith("m")) {
1084
+ return meterToPx(Number(str.slice(0, -1)));
509
1085
  } else {
510
- var res = new WebSpatialResource();
511
- res.id = reqResp.data.rootEntId;
512
- return new SpatialEntity(res);
1086
+ throw new Error("formatToNumber: invalid str");
513
1087
  }
1088
+ } else {
1089
+ throw new Error("formatToNumber: invalid targetUnit");
514
1090
  }
515
- /*
516
- * Sets the root entity that this windowContainer will display (this does not effect resource ownership)
517
- * @param entity to display
518
- */
519
- async setRootEntity(entity) {
520
- await entity._setParentWindowContainer(this);
1091
+ }
1092
+ function formatSceneConfig(config, sceneType) {
1093
+ const defaultSceneConfig2 = getSceneDefaultConfig(sceneType);
1094
+ const errors = [];
1095
+ const isWindow = sceneType === "window";
1096
+ if (!isValidSpatialSceneType(sceneType)) {
1097
+ errors.push(`sceneType`);
1098
+ }
1099
+ if (config.defaultSize) {
1100
+ const iterKeys = ["width", "height", "depth"];
1101
+ for (let k of iterKeys) {
1102
+ if (!(k in config.defaultSize)) continue;
1103
+ if (isValidSceneUnit(config.defaultSize[k])) {
1104
+ ;
1105
+ config.defaultSize[k] = formatToNumber(
1106
+ config.defaultSize[k],
1107
+ isWindow ? "px" : "m",
1108
+ isWindow ? "px" : "m"
1109
+ );
1110
+ } else {
1111
+ ;
1112
+ config.defaultSize[k] = defaultSceneConfig2.defaultSize[k];
1113
+ errors.push(`defaultSize.${k}`);
1114
+ }
1115
+ }
521
1116
  }
522
- async close() {
523
- await WebSpatial.updateWindowContainer(this._wg, {
524
- close: true
525
- });
1117
+ if (config.resizability) {
1118
+ const iterKeys = ["minWidth", "minHeight", "maxWidth", "maxHeight"];
1119
+ for (let k of iterKeys) {
1120
+ if (!(k in config.resizability)) continue;
1121
+ if (isValidSceneUnit(config.resizability[k])) {
1122
+ ;
1123
+ config.resizability[k] = formatToNumber(
1124
+ config.resizability[k],
1125
+ "px",
1126
+ isWindow ? "px" : "m"
1127
+ );
1128
+ } else {
1129
+ ;
1130
+ config.resizability[k] = void 0;
1131
+ errors.push(`resizability.${k}`);
1132
+ }
1133
+ }
526
1134
  }
527
- };
528
-
529
- // src/core/resource/SpatialMeshResource.ts
530
- var SpatialMeshResource = class extends SpatialObject {
531
- };
532
-
533
- // src/core/resource/SpatialPhysicallyBasedMaterialResource.ts
534
- var SpatialPhysicallyBasedMaterialResource = class extends SpatialObject {
535
- /**
536
- * Base color of the material containing rgba between 0 and 1
537
- */
538
- baseColor = { r: 0, g: 0.7, b: 0.7, a: 1 };
539
- /**
540
- * PBR metalic value between 0 and 1
541
- */
542
- metallic = { value: 0.5 };
543
- /**
544
- * PBR roughness value between 0 and 1
545
- */
546
- roughness = { value: 0.5 };
547
- _modelComponentAttachedTo = {};
548
- _addToComponent(c) {
549
- this._modelComponentAttachedTo[c._resource.id] = c;
1135
+ if (config.worldScaling) {
1136
+ if (!isValidWorldScalingType(config.worldScaling)) {
1137
+ config.worldScaling = "automatic";
1138
+ errors.push("worldScaling");
1139
+ }
550
1140
  }
551
- /**
552
- * Syncs state of color, metallic, roupghness to the renderer
553
- */
554
- async update() {
555
- await WebSpatial.updateResource(this._resource, {
556
- baseColor: this.baseColor,
557
- metallic: this.metallic,
558
- roughness: this.roughness
559
- });
560
- for (var key in this._modelComponentAttachedTo) {
561
- await this._modelComponentAttachedTo[key]._syncMaterials();
1141
+ if (config.worldAlignment) {
1142
+ if (!isValidWorldAlignmentType(config.worldAlignment)) {
1143
+ config.worldAlignment = "automatic";
1144
+ errors.push("worldAlignment");
562
1145
  }
563
1146
  }
564
- };
565
-
566
- // src/core/SpatialSession.ts
567
- function _parseParentResources(options) {
568
- var parentWindowContainer = null;
569
- if (options?.windowContainer !== null) {
570
- parentWindowContainer = options?.windowContainer ? options?.windowContainer._wg : WebSpatial.getCurrentWindowContainer();
1147
+ if (config.baseplateVisibility) {
1148
+ if (!isValidBaseplateVisibilityType(config.baseplateVisibility)) {
1149
+ config.baseplateVisibility = "automatic";
1150
+ errors.push("baseplateVisibility");
1151
+ }
571
1152
  }
572
- var parentWindow = null;
573
- if (options?.windowComponent !== null) {
574
- parentWindow = options?.windowComponent ? options?.windowComponent._resource : WebSpatial.getCurrentWebPanel();
1153
+ return [config, errors];
1154
+ }
1155
+ function initScene(name, callback, options) {
1156
+ return SceneManager.getInstance().initScene(name, callback, options);
1157
+ }
1158
+ function hijackWindowOpen(window2) {
1159
+ SceneManager.getInstance().init(window2);
1160
+ }
1161
+ function hijackWindowATag(openedWindow) {
1162
+ openedWindow.document.onclick = function(e) {
1163
+ let element = e.target;
1164
+ let found = false;
1165
+ while (!found) {
1166
+ if (element && element.tagName == "A") {
1167
+ if (handleATag(e)) {
1168
+ return false;
1169
+ }
1170
+ return true;
1171
+ }
1172
+ if (element && element.parentElement) {
1173
+ element = element.parentElement;
1174
+ } else {
1175
+ break;
1176
+ }
1177
+ }
1178
+ };
1179
+ }
1180
+ function handleATag(event) {
1181
+ const targetElement = event.target;
1182
+ if (targetElement.tagName === "A") {
1183
+ const link = targetElement;
1184
+ const target = link.target;
1185
+ const url = link.href;
1186
+ if (target && target !== "_self") {
1187
+ event.preventDefault();
1188
+ window.open(url, target);
1189
+ return true;
1190
+ }
575
1191
  }
576
- return [parentWindowContainer, parentWindow];
577
1192
  }
578
- var SpatialSession = class _SpatialSession {
579
- /** @hidden */
580
- _engineUpdateListeners = Array();
581
- /** @hidden */
582
- _frameLoopStarted = false;
583
- /**
584
- * Add event listener callback to be called each frame
585
- * @param callback callback to be called each update
586
- */
587
- addOnEngineUpdateEventListener(callback) {
588
- this._engineUpdateListeners.push(callback);
589
- if (!this._frameLoopStarted) {
590
- this._frameLoopStarted = true;
591
- WebSpatial.onFrame(async (time) => {
592
- await Promise.all(
593
- this._engineUpdateListeners.map((cb) => {
594
- return cb(time);
595
- })
596
- );
597
- });
1193
+ function getSceneDefaultConfig(sceneType) {
1194
+ return sceneType === "window" ? defaultSceneConfig : defaultSceneConfigVolume;
1195
+ }
1196
+ async function injectScenePolyfill() {
1197
+ if (!window.opener) return;
1198
+ const state = await SpatialScene.getInstance().getState();
1199
+ if (state !== "pending" /* pending */) return;
1200
+ function onContentLoaded(callback) {
1201
+ if (document.readyState === "interactive" || document.readyState === "complete") {
1202
+ callback();
1203
+ } else {
1204
+ document.addEventListener("DOMContentLoaded", callback);
598
1205
  }
599
1206
  }
1207
+ onContentLoaded(async () => {
1208
+ let provideDefaultSceneConfig = getSceneDefaultConfig(
1209
+ window.xrCurrentSceneType ?? "window"
1210
+ );
1211
+ let cfg = provideDefaultSceneConfig;
1212
+ if (typeof window.xrCurrentSceneDefaults === "function") {
1213
+ try {
1214
+ cfg = await window.xrCurrentSceneDefaults?.(provideDefaultSceneConfig);
1215
+ } catch (error) {
1216
+ console.error(error);
1217
+ }
1218
+ }
1219
+ await new Promise((resolve, reject) => {
1220
+ setTimeout(() => {
1221
+ resolve(null);
1222
+ }, 1e3);
1223
+ });
1224
+ const sceneType = window.xrCurrentSceneType ?? "window";
1225
+ const [formattedConfig, errors] = formatSceneConfig(cfg, sceneType);
1226
+ if (errors.length > 0) {
1227
+ console.warn(
1228
+ `window.xrCurrentSceneDefaults with errors: ${errors.join(", ")}`
1229
+ );
1230
+ }
1231
+ await SpatialScene.getInstance().updateSceneCreationConfig({
1232
+ ...formattedConfig,
1233
+ type: sceneType
1234
+ });
1235
+ });
1236
+ }
1237
+ function injectSceneHook() {
1238
+ hijackWindowOpen(window);
1239
+ hijackWindowATag(window);
1240
+ injectScenePolyfill();
1241
+ }
1242
+
1243
+ // src/SpatializedElementCreator.ts
1244
+ init_JSBCommand();
1245
+
1246
+ // src/Spatialized2DElement.ts
1247
+ init_JSBCommand();
1248
+
1249
+ // src/SpatializedElement.ts
1250
+ init_JSBCommand();
1251
+ init_SpatialWebEvent();
1252
+
1253
+ // src/SpatialWebEventCreator.ts
1254
+ function createSpatialEvent(type, detail) {
1255
+ return new CustomEvent(type, {
1256
+ bubbles: true,
1257
+ cancelable: false,
1258
+ detail
1259
+ });
1260
+ }
1261
+
1262
+ // src/SpatializedElement.ts
1263
+ var SpatializedElement = class extends SpatialObject {
600
1264
  /**
601
- * Creates a Entity
602
- * @returns Entity
1265
+ * Creates a new spatialized element with the specified ID.
1266
+ * Registers the element to receive spatial events.
1267
+ * @param id Unique identifier for this element
603
1268
  */
604
- async createEntity(options) {
605
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
606
- let entity = await WebSpatial.createResource(
607
- "Entity",
608
- parentWindowContainer,
609
- parentWindow
610
- );
611
- return new SpatialEntity(entity);
1269
+ constructor(id) {
1270
+ super(id);
1271
+ this.id = id;
1272
+ SpatialWebEvent.addEventReceiver(id, this.onReceiveEvent.bind(this));
612
1273
  }
613
1274
  /**
614
- * Creates a WindowComponent
615
- * [TODO] should creation of components be moved to entity? and these made private?
616
- * @returns WindowComponent
1275
+ * Updates the transformation matrix of this element in 3D space.
1276
+ * This affects the position, rotation, and scale of the element.
1277
+ * @param matrix The new transformation matrix
1278
+ * @returns Promise resolving when the transform is updated
617
1279
  */
618
- async createWindowComponent(options) {
619
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
620
- let entity = await WebSpatial.createResource(
621
- "SpatialWebView",
622
- parentWindowContainer,
623
- parentWindow
624
- );
625
- return new SpatialWindowComponent(entity);
1280
+ async updateTransform(matrix) {
1281
+ return new UpdateSpatializedElementTransform(this, matrix).execute();
626
1282
  }
627
1283
  /**
628
- * Creates a ViewComponent used to display 3D content within the entity
629
- * @returns SpatialViewComponent
1284
+ * Information about the element's bounding cube.
1285
+ * Used for spatial calculations and hit testing.
630
1286
  */
631
- async createViewComponent(options) {
632
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
633
- let entity = await WebSpatial.createResource(
634
- "SpatialView",
635
- parentWindowContainer,
636
- parentWindow
637
- );
638
- return new SpatialViewComponent(entity);
639
- }
1287
+ _cubeInfo;
640
1288
  /**
641
- * Creates a ModelComponent used to display geometry + material of a 3D model
642
- * @returns ModelComponent
1289
+ * Gets the current cube information for this element.
1290
+ * @returns The current CubeInfo or undefined if not set
643
1291
  */
644
- async createModelComponent(options) {
645
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
646
- var opts = void 0;
647
- if (options) {
648
- opts = { modelURL: options.url };
649
- }
650
- let entity = await WebSpatial.createResource(
651
- "ModelComponent",
652
- parentWindowContainer,
653
- parentWindow,
654
- opts
655
- );
656
- return new SpatialModelComponent(entity);
1292
+ get cubeInfo() {
1293
+ return this._cubeInfo;
657
1294
  }
658
1295
  /**
659
- * Creates a Model3DComponent
660
- * @returns Model3DComponent
1296
+ * The current transformation matrix of this element.
661
1297
  */
662
- async createModel3DComponent(options) {
663
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
664
- var opts = void 0;
665
- if (options) {
666
- opts = { modelURL: options.url };
667
- }
668
- let entity = await WebSpatial.createResource(
669
- "Model3DComponent",
670
- parentWindowContainer,
671
- parentWindow,
672
- opts
673
- );
674
- return new SpatialModel3DComponent(entity);
675
- }
1298
+ _transform;
676
1299
  /**
677
- * Creates a InputComponent
678
- * [Experimental] Creates a InputComponent used to handle click and drag events of the entity containing a model
679
- * @returns InputComponent
1300
+ * The inverse of the current transformation matrix.
1301
+ * Used for converting world coordinates to local coordinates.
680
1302
  */
681
- async createInputComponent(options) {
682
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
683
- let entity = await WebSpatial.createResource(
684
- "InputComponent",
685
- parentWindowContainer,
686
- parentWindow
687
- );
688
- return new SpatialInputComponent(entity);
1303
+ _transformInv;
1304
+ /**
1305
+ * Gets the current transformation matrix.
1306
+ * @returns The current transformation matrix or undefined if not set
1307
+ */
1308
+ get transform() {
1309
+ return this._transform;
689
1310
  }
690
1311
  /**
691
- * Creates a MeshResource containing geometry data
692
- * @returns MeshResource
1312
+ * Gets the inverse of the current transformation matrix.
1313
+ * @returns The inverse transformation matrix or undefined if not set
693
1314
  */
694
- async createMeshResource(options) {
695
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
696
- let entity = await WebSpatial.createResource(
697
- "MeshResource",
698
- parentWindowContainer,
699
- parentWindow,
700
- options
701
- );
702
- return new SpatialMeshResource(entity);
1315
+ get transformInv() {
1316
+ return this._transformInv;
703
1317
  }
704
1318
  /**
705
- * Creates a PhysicallyBasedMaterial containing PBR material data
706
- * @returns PhysicallyBasedMaterial
1319
+ * Processes events received from the WebSpatial environment.
1320
+ * Handles various spatial events like transforms, gestures, and interactions.
1321
+ * @param data The event data received from the WebSpatial system
707
1322
  */
708
- async createPhysicallyBasedMaterialResource(options) {
709
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
710
- let entity = await WebSpatial.createResource(
711
- "PhysicallyBasedMaterial",
712
- parentWindowContainer,
713
- parentWindow,
714
- options
715
- );
716
- return new SpatialPhysicallyBasedMaterialResource(entity);
1323
+ onReceiveEvent(data) {
1324
+ const { type } = data;
1325
+ if (type === "objectdestroy" /* objectdestroy */) {
1326
+ this.isDestroyed = true;
1327
+ } else if (type === "cubeInfo" /* cubeInfo */) {
1328
+ const cubeInfoMsg = data;
1329
+ this._cubeInfo = new CubeInfo(cubeInfoMsg.size, cubeInfoMsg.origin);
1330
+ } else if (type === "transform" /* transform */) {
1331
+ this._transform = new DOMMatrix([
1332
+ data.detail.column0[0],
1333
+ data.detail.column0[1],
1334
+ data.detail.column0[2],
1335
+ 0,
1336
+ data.detail.column1[0],
1337
+ data.detail.column1[1],
1338
+ data.detail.column1[2],
1339
+ 0,
1340
+ data.detail.column2[0],
1341
+ data.detail.column2[1],
1342
+ data.detail.column2[2],
1343
+ 0,
1344
+ data.detail.column3[0],
1345
+ data.detail.column3[1],
1346
+ data.detail.column3[2],
1347
+ 1
1348
+ ]);
1349
+ this._transformInv = this._transform.inverse();
1350
+ } else if (type === "spatialtap" /* spatialtap */) {
1351
+ const event = createSpatialEvent(
1352
+ "spatialtap" /* spatialtap */,
1353
+ data.detail
1354
+ );
1355
+ this._onSpatialTap?.(event);
1356
+ } else if (type === "spatialdrag" /* spatialdrag */) {
1357
+ if (!this._isDragging) {
1358
+ const dragStartEvent = createSpatialEvent(
1359
+ "spatialdragstart" /* spatialdragstart */,
1360
+ data.detail
1361
+ );
1362
+ this._onSpatialDragStart?.(dragStartEvent);
1363
+ }
1364
+ this._isDragging = true;
1365
+ const event = createSpatialEvent(
1366
+ "spatialdrag" /* spatialdrag */,
1367
+ data.detail
1368
+ );
1369
+ this._onSpatialDrag?.(event);
1370
+ } else if (type === "spatialdragend" /* spatialdragend */) {
1371
+ this._isDragging = false;
1372
+ const event = createSpatialEvent(
1373
+ "spatialdragend" /* spatialdragend */,
1374
+ data.detail
1375
+ );
1376
+ this._onSpatialDragEnd?.(event);
1377
+ } else if (type === "spatialrotate" /* spatialrotate */) {
1378
+ if (!this._isRotating) {
1379
+ const rotationStartEvent = createSpatialEvent(
1380
+ "spatialrotatestart" /* spatialrotatestart */,
1381
+ data.detail
1382
+ );
1383
+ this._onSpatialRotateStart?.(rotationStartEvent);
1384
+ }
1385
+ this._isRotating = true;
1386
+ const event = createSpatialEvent(
1387
+ "spatialrotate" /* spatialrotate */,
1388
+ data.detail
1389
+ );
1390
+ this._onSpatialRotate?.(event);
1391
+ } else if (type === "spatialrotateend" /* spatialrotateend */) {
1392
+ this._isRotating = false;
1393
+ const event = createSpatialEvent(
1394
+ "spatialrotateend" /* spatialrotateend */,
1395
+ data.detail
1396
+ );
1397
+ this._onSpatialRotateEnd?.(event);
1398
+ } else if (type === "spatialmagnify" /* spatialmagnify */) {
1399
+ if (!this._isMagnify) {
1400
+ const magnifyStartEvent = createSpatialEvent(
1401
+ "spatialmagnifystart" /* spatialmagnifystart */,
1402
+ data.detail
1403
+ );
1404
+ this._onSpatialMagnifyStart?.(magnifyStartEvent);
1405
+ }
1406
+ this._isMagnify = true;
1407
+ const event = createSpatialEvent(
1408
+ "spatialmagnify" /* spatialmagnify */,
1409
+ data.detail
1410
+ );
1411
+ this._onSpatialMagnify?.(event);
1412
+ } else if (type === "spatialmagnifyend" /* spatialmagnifyend */) {
1413
+ this._isMagnify = false;
1414
+ const event = createSpatialEvent(
1415
+ "spatialmagnifyend" /* spatialmagnifyend */,
1416
+ data.detail
1417
+ );
1418
+ this._onSpatialMagnifyEnd?.(event);
1419
+ }
1420
+ }
1421
+ _onSpatialTap;
1422
+ set onSpatialTap(value) {
1423
+ this._onSpatialTap = value;
1424
+ this.updateProperties({
1425
+ enableTapGesture: value !== void 0
1426
+ });
1427
+ }
1428
+ _isDragging = false;
1429
+ _onSpatialDragStart;
1430
+ set onSpatialDragStart(value) {
1431
+ this._onSpatialDragStart = value;
1432
+ this.updateProperties({
1433
+ enableDragStartGesture: this._onSpatialDragStart !== void 0
1434
+ });
1435
+ }
1436
+ _onSpatialDrag;
1437
+ set onSpatialDrag(value) {
1438
+ this._onSpatialDrag = value;
1439
+ this.updateProperties({
1440
+ enableDragGesture: this._onSpatialDrag !== void 0
1441
+ });
1442
+ }
1443
+ _onSpatialDragEnd;
1444
+ set onSpatialDragEnd(value) {
1445
+ this._onSpatialDragEnd = value;
1446
+ this.updateProperties({
1447
+ enableDragEndGesture: value !== void 0
1448
+ });
1449
+ }
1450
+ _isRotating = false;
1451
+ _onSpatialRotateStart;
1452
+ set onSpatialRotateStart(value) {
1453
+ this._onSpatialRotateStart = value;
1454
+ this.updateProperties({
1455
+ enableRotateStartGesture: this._onSpatialRotateStart !== void 0
1456
+ });
1457
+ }
1458
+ _onSpatialRotate;
1459
+ set onSpatialRotate(value) {
1460
+ this._onSpatialRotate = value;
1461
+ this.updateProperties({
1462
+ enableRotateGesture: this._onSpatialRotate !== void 0
1463
+ });
1464
+ }
1465
+ _onSpatialRotateEnd;
1466
+ set onSpatialRotateEnd(value) {
1467
+ this._onSpatialRotateEnd = value;
1468
+ this.updateProperties({
1469
+ enableRotateEndGesture: value !== void 0
1470
+ });
1471
+ }
1472
+ _isMagnify = false;
1473
+ _onSpatialMagnifyStart;
1474
+ set onSpatialMagnifyStart(value) {
1475
+ this._onSpatialMagnifyStart = value;
1476
+ this.updateProperties({
1477
+ enableMagnifyStartGesture: value !== void 0
1478
+ });
1479
+ }
1480
+ _onSpatialMagnify;
1481
+ set onSpatialMagnify(value) {
1482
+ this._onSpatialMagnify = value;
1483
+ this.updateProperties({
1484
+ enableMagnifyGesture: value !== void 0
1485
+ });
717
1486
  }
718
- /**
719
- * Creates a WindowContainer
720
- * @returns SpatialWindowContainer
721
- * */
722
- async createWindowContainer(options) {
723
- var style = options?.style ? options?.style : "Plain";
724
- var [parentWindowContainer, parentWindow] = _parseParentResources(options);
725
- return new SpatialWindowContainer(
726
- await WebSpatial.createWindowContainer(
727
- style,
728
- parentWindowContainer,
729
- parentWindow
730
- )
731
- );
1487
+ _onSpatialMagnifyEnd;
1488
+ set onSpatialMagnifyEnd(value) {
1489
+ this._onSpatialMagnifyEnd = value;
1490
+ this.updateProperties({
1491
+ enableMagnifyEndGesture: value !== void 0
1492
+ });
732
1493
  }
733
1494
  /**
734
- * Creates a Scene to display content within an anchored area managed by the OS
735
- * @hidden
736
- * @param {WindowStyle} [style='Plain'] - The style of the Scene container to be created with. Defaults to 'Plain'.
737
- * @param {Object} [cfg={}] - Configuration object for the Scene.
738
- * @returns Boolean
1495
+ * Cleans up resources when this element is destroyed.
1496
+ * Removes event receivers to prevent memory leaks.
739
1497
  */
740
- async _createScene(style = "Plain", cfg) {
741
- return await WebSpatial.createScene(style, cfg);
1498
+ onDestroy() {
1499
+ SpatialWebEvent.removeEventReceiver(this.id);
742
1500
  }
1501
+ };
1502
+
1503
+ // src/Spatialized2DElement.ts
1504
+ var Spatialized2DElement = class extends SpatializedElement {
743
1505
  /**
744
- * Retrieves the window for this page
745
- * @returns the window component corresponding to the js running on this page
746
- * [TODO] discuss implications of this not being async
1506
+ * Creates a new spatialized 2D element.
1507
+ * @param id Unique identifier for this element
1508
+ * @param windowProxy Reference to the window object containing the 2D content
747
1509
  */
748
- getCurrentWindowComponent() {
749
- return new SpatialWindowComponent(WebSpatial.getCurrentWebPanel());
1510
+ constructor(id, windowProxy) {
1511
+ super(id);
1512
+ this.windowProxy = windowProxy;
1513
+ hijackWindowATag(windowProxy);
750
1514
  }
751
1515
  /**
752
- * Retrieves the parent window for this page or null if this is the root page
753
- * @returns the window component or null
1516
+ * Updates the properties of this 2D element.
1517
+ * This can include size, position, background, and other visual properties.
1518
+ * @param properties Partial set of properties to update
1519
+ * @returns Promise resolving when the update is complete
754
1520
  */
755
- async getParentWindowComponent() {
756
- let parentResp = await WebSpatial.updateResource(
757
- WebSpatial.getCurrentWebPanel(),
758
- { getParentID: "" }
759
- );
760
- if (parentResp.data.parentID === "") {
761
- return new Promise((res2, rej) => {
762
- res2(null);
763
- });
764
- } else {
765
- var res = new WebSpatialResource();
766
- res.id = parentResp.data.parentID;
767
- return new SpatialWindowComponent(res);
768
- }
1521
+ async updateProperties(properties) {
1522
+ return new UpdateSpatialized2DElementProperties(this, properties).execute();
769
1523
  }
770
1524
  /**
771
- * Logs a message to the native apps console
772
- * @param msg mesage to log
1525
+ * Adds a child spatialized element to this 2D element.
1526
+ * This allows for creating hierarchical structures of spatial elements.
1527
+ * @param element The child element to add
1528
+ * @returns Promise resolving when the element is added
773
1529
  */
774
- async log(...msg) {
775
- await WebSpatial.sendCommand(
776
- new RemoteCommand("log", {
777
- logString: msg.map((x) => {
778
- return JSON.stringify(x);
779
- })
780
- })
781
- );
1530
+ async addSpatializedElement(element) {
1531
+ return new AddSpatializedElementToSpatialized2DElement(
1532
+ this,
1533
+ element
1534
+ ).execute();
782
1535
  }
1536
+ };
1537
+
1538
+ // src/SpatializedStatic3DElement.ts
1539
+ init_JSBCommand();
1540
+ var SpatializedStatic3DElement = class extends SpatializedElement {
783
1541
  /**
784
- * @hidden
785
- * Debugging only, used to ping the native renderer
1542
+ * Promise resolver for the ready state.
1543
+ * Used to resolve the ready promise when the model is loaded.
786
1544
  */
787
- async _ping(msg) {
788
- return await WebSpatial.ping(msg);
789
- }
1545
+ _readyResolve;
790
1546
  /**
791
- * @hidden
792
- * Debugging to get internal state from native code
793
- * @returns stats from native code. Objects tracks number of native objects that were created but not yet explicitly destroyed. RefObjects tracks bjects that still have references. After an object is destroyed, we should be cleaning up all of the native references. Expect objects.count == refObjects.count , if not, there is likely a leak.
1547
+ * Caches the last model URL to detect changes.
1548
+ * Used to reset the ready promise when the model URL changes.
794
1549
  */
795
- async _getStats() {
796
- return await WebSpatial.getStats();
797
- }
1550
+ modelURL = "";
798
1551
  /**
799
- * @hidden
1552
+ * Creates a new promise for tracking the ready state of the model.
1553
+ * @returns Promise that resolves when the model is loaded (true) or fails to load (false)
800
1554
  */
801
- async _inspect(spatialObjectId = WebSpatial.getCurrentWebPanel().id) {
802
- return WebSpatial.inspect(spatialObjectId);
1555
+ createReadyPromise() {
1556
+ return new Promise((resolve) => {
1557
+ this._readyResolve = resolve;
1558
+ });
803
1559
  }
804
1560
  /**
805
- * @hidden
1561
+ * Promise that resolves when the model is loaded.
1562
+ * Resolves to true on successful load, false on failure.
806
1563
  */
807
- async _inspectRootWindowContainer() {
808
- return WebSpatial.inspectRootWindowContainer();
809
- }
810
- /** Opens the immersive space */
811
- async openImmersiveSpace() {
812
- return await WebSpatial.openImmersiveSpace();
813
- }
814
- /** Closes the immersive space */
815
- async dismissImmersiveSpace() {
816
- return await WebSpatial.dismissImmersiveSpace();
817
- }
818
- static _immersiveWindowContainer = null;
1564
+ ready = this.createReadyPromise();
819
1565
  /**
820
- * Retreives the window container corresponding to the Immersive space
821
- * @returns the immersive window container
1566
+ * Updates the properties of this static 3D element.
1567
+ * Handles special case for modelURL changes by resetting the ready promise.
1568
+ * @param properties Partial set of properties to update
1569
+ * @returns Promise resolving when the update is complete
822
1570
  */
823
- async getImmersiveWindowContainer() {
824
- if (_SpatialSession._immersiveWindowContainer) {
825
- return _SpatialSession._immersiveWindowContainer;
1571
+ async updateProperties(properties) {
1572
+ if (properties.modelURL !== void 0) {
1573
+ if (this.modelURL !== properties.modelURL) {
1574
+ this.modelURL = properties.modelURL;
1575
+ this.ready = this.createReadyPromise();
1576
+ }
1577
+ }
1578
+ return new UpdateSpatializedStatic3DElementProperties(
1579
+ this,
1580
+ properties
1581
+ ).execute();
1582
+ }
1583
+ /**
1584
+ * Processes events received from the WebSpatial environment.
1585
+ * Handles model loading events in addition to base spatial events.
1586
+ * @param data The event data received from the WebSpatial system
1587
+ */
1588
+ onReceiveEvent(data) {
1589
+ if (data.type === "modelloaded" /* modelloaded */) {
1590
+ this._onLoadCallback?.();
1591
+ this._readyResolve?.(true);
1592
+ } else if (data.type === "modelloadfailed" /* modelloadfailed */) {
1593
+ this._onLoadFailureCallback?.();
1594
+ this._readyResolve?.(false);
826
1595
  } else {
827
- _SpatialSession._immersiveWindowContainer = new SpatialWindowContainer(
828
- WebSpatial.getImmersiveWindowContainer()
829
- );
830
- return _SpatialSession._immersiveWindowContainer;
1596
+ super.onReceiveEvent(data);
831
1597
  }
832
1598
  }
833
- // Retreives the window container that is the parent to this spatial web page
834
- static _currentWindowContainer = null;
835
1599
  /**
836
- * Gets the current window container for the window
837
- * [TODO] discuss what happens if it doesnt yet have a window container
838
- * @returns the current window container for the window
1600
+ * Callback function for successful model loading.
839
1601
  */
840
- getCurrentWindowContainer() {
841
- if (_SpatialSession._currentWindowContainer) {
842
- return _SpatialSession._currentWindowContainer;
843
- } else {
844
- _SpatialSession._currentWindowContainer = new SpatialWindowContainer(
845
- WebSpatial.getCurrentWindowContainer()
846
- );
847
- return _SpatialSession._currentWindowContainer;
848
- }
849
- }
1602
+ _onLoadCallback;
850
1603
  /**
851
- * Start a transaction that queues up commands to submit them all at once to reduce ipc overhead
852
- * @param fn function to be run, within this function, promises will not resolve
853
- * @returns promise for the entire transaction completion
1604
+ * Sets the callback function for successful model loading.
1605
+ * @param callback Function to call when the model is loaded successfully
854
1606
  */
855
- transaction(fn) {
856
- WebSpatial.startTransaction();
857
- fn();
858
- return WebSpatial.sendTransaction();
1607
+ set onLoadCallback(callback) {
1608
+ this._onLoadCallback = callback;
859
1609
  }
860
1610
  /**
861
- * Creates a window context object that is compatable with SpatialWindowComponent's setFromWindow API
862
- * @returns window context
1611
+ * Callback function for model loading failure.
863
1612
  */
864
- async createWindowContext() {
865
- let openedWindow = window.open("webspatial://createWindowContext");
866
- if (WebSpatial.getBackend() != "AVP") {
867
- var counter = 0;
868
- while (openedWindow.window.testAPI == null) {
869
- if (counter > 15) {
870
- openedWindow?.close();
871
- openedWindow = window.open("about:blank");
872
- counter = 0;
873
- this.log("unexpected error when trying to open new window, retrying.");
874
- }
875
- var locName = "about:blank?x" + counter;
876
- openedWindow.location.href = locName;
877
- counter++;
878
- await new Promise((resolve) => setTimeout(resolve, 10));
879
- }
880
- ;
881
- openedWindow._webSpatialID = openedWindow.window.testAPI.getWindowID();
882
- } else {
883
- while (openedWindow.window._webSpatialID == void 0) {
884
- await new Promise((resolve) => setTimeout(resolve, 10));
885
- }
886
- }
887
- openedWindow.document.head.innerHTML = `<meta name="viewport" content="width=device-width, initial-scale=1">
888
- <base href="${document.baseURI}">
889
- `;
890
- return openedWindow;
1613
+ _onLoadFailureCallback;
1614
+ /**
1615
+ * Sets the callback function for model loading failure.
1616
+ * @param callback Function to call when the model fails to load
1617
+ */
1618
+ set onLoadFailureCallback(callback) {
1619
+ this._onLoadFailureCallback = callback;
891
1620
  }
892
- // Get Entity by id. Currently for debugging only.
893
- /** @hidden */
894
- async _getEntity(id) {
895
- const entityInfo = await WebSpatial.inspect(id);
896
- const [_, x, y, z] = entityInfo.position.match(/(\d+\.?\d*)/g);
897
- const [__, sx, sy, sz] = entityInfo.scale.match(/(\d+\.?\d*)/g);
898
- var res = new WebSpatialResource();
899
- res.id = id;
900
- res.windowContainerId = WebSpatial.getCurrentWindowContainer().id;
901
- const entity = new SpatialEntity(res);
902
- entity.transform.position.x = parseFloat(x);
903
- entity.transform.position.y = parseFloat(y);
904
- entity.transform.position.z = parseFloat(z);
905
- entity.transform.scale.x = parseFloat(sx);
906
- entity.transform.scale.y = parseFloat(sy);
907
- entity.transform.scale.z = parseFloat(sz);
908
- return entity;
909
- }
910
- // set loading view.
911
- /** @hidden */
912
- async setLoading(method, style) {
913
- return WebSpatial.setLoading(method, style);
1621
+ updateModelTransform(transform) {
1622
+ const modelTransform = Array.from(transform.toFloat64Array());
1623
+ this.updateProperties({ modelTransform });
914
1624
  }
915
1625
  };
916
1626
 
917
- // src/core/Spatial.ts
918
- var Spatial = class {
919
- /**
920
- * Requests a session object from the browser
921
- * @returns The session or null if not availible in the current browser
922
- * [TODO] discuss implications of this not being async
923
- */
924
- requestSession() {
925
- if (this.isSupported() && this.getNativeVersion() === this.getClientVersion()) {
926
- return new SpatialSession();
927
- } else {
928
- return null;
929
- }
1627
+ // src/SpatializedDynamic3DElement.ts
1628
+ init_JSBCommand();
1629
+ var SpatializedDynamic3DElement = class extends SpatializedElement {
1630
+ children = [];
1631
+ constructor(id) {
1632
+ super(id);
1633
+ }
1634
+ async addEntity(entity) {
1635
+ const ans = new SetParentForEntityCommand(entity.id, this.id).execute();
1636
+ this.children.push(entity);
1637
+ entity.parent = this;
1638
+ return ans;
1639
+ }
1640
+ async updateProperties(properties) {
1641
+ return new UpdateSpatializedDynamic3DElementProperties(
1642
+ this,
1643
+ properties
1644
+ ).execute();
930
1645
  }
931
- /**
932
- * @returns true if web spatial is supported by this webpage
933
- */
934
- isSupported() {
935
- return this.getNativeVersion() === this.getClientVersion();
1646
+ };
1647
+
1648
+ // src/SpatializedElementCreator.ts
1649
+ async function createSpatialized2DElement() {
1650
+ const result = await new createSpatialized2DElementCommand().execute();
1651
+ if (!result.success) {
1652
+ throw new Error("createSpatialized2DElement failed");
1653
+ } else {
1654
+ const { id, windowProxy } = result.data;
1655
+ windowProxy.document.head.innerHTML = `<meta name="viewport" content="width=device-width, initial-scale=1">
1656
+ <base href="${document.baseURI}">`;
1657
+ return new Spatialized2DElement(id, windowProxy);
936
1658
  }
937
- /**
938
- * Gets the native version, format is "x.x.x"
939
- * @returns native version string
940
- */
941
- getNativeVersion() {
942
- if (window.__WebSpatialData && window.__WebSpatialData.getNativeVersion) {
943
- return window.__WebSpatialData.getNativeVersion();
944
- }
945
- return window.WebSpatailNativeVersion === "PACKAGE_VERSION" ? this.getClientVersion() : window.WebSpatailNativeVersion;
1659
+ }
1660
+ async function createSpatializedStatic3DElement(modelURL) {
1661
+ const result = await new CreateSpatializedStatic3DElementCommand(
1662
+ modelURL
1663
+ ).execute();
1664
+ if (!result.success) {
1665
+ throw new Error("createSpatializedStatic3DElement failed");
1666
+ } else {
1667
+ const { id } = result.data;
1668
+ return new SpatializedStatic3DElement(id);
946
1669
  }
947
- /**
948
- * Gets the client version, format is "x.x.x"
949
- * @returns client version string
950
- */
951
- getClientVersion() {
952
- return "1.0.4";
1670
+ }
1671
+ async function createSpatializedDynamic3DElement() {
1672
+ const result = await new CreateSpatializedDynamic3DElementCommand().execute();
1673
+ if (!result.success) {
1674
+ throw new Error("createSpatializedDynamic3DElement failed");
1675
+ } else {
1676
+ const { id } = result.data;
1677
+ return new SpatializedDynamic3DElement(id);
953
1678
  }
954
- };
1679
+ }
1680
+
1681
+ // src/reality/realityCreator.ts
1682
+ init_JSBCommand();
955
1683
 
956
- // src/core/SpatialHelper.ts
957
- var SpatialHelper = class _SpatialHelper {
958
- constructor(session) {
959
- this.session = session;
960
- }
961
- static _instance = null;
962
- static get instance() {
963
- if (this._instance) {
964
- return this._instance;
1684
+ // src/reality/entity/SpatialEntity.ts
1685
+ init_JSBCommand();
1686
+ init_JSBCommand();
1687
+ init_SpatialWebEvent();
1688
+ var SpatialEntity = class _SpatialEntity extends SpatialObject {
1689
+ constructor(id, userData) {
1690
+ super(id);
1691
+ this.userData = userData;
1692
+ SpatialWebEvent.addEventReceiver(id, this.onReceiveEvent);
1693
+ }
1694
+ position = { x: 0, y: 0, z: 0 };
1695
+ rotation = { x: 0, y: 0, z: 0 };
1696
+ scale = { x: 1, y: 1, z: 1 };
1697
+ events = {};
1698
+ children = [];
1699
+ parent = null;
1700
+ async addComponent(component) {
1701
+ return new AddComponentToEntityCommand(this, component).execute();
1702
+ }
1703
+ async setPosition(position) {
1704
+ return this.updateTransform({ position });
1705
+ }
1706
+ async setRotation(rotation) {
1707
+ return this.updateTransform({ rotation });
1708
+ }
1709
+ async setScale(scale) {
1710
+ return this.updateTransform({ scale });
1711
+ }
1712
+ async addEntity(ent) {
1713
+ const ans = await new SetParentForEntityCommand(ent.id, this.id).execute();
1714
+ this.children.push(ent);
1715
+ ent.parent = this;
1716
+ return ans;
1717
+ }
1718
+ async removeFromParent() {
1719
+ const ans = await new SetParentForEntityCommand(
1720
+ this.id,
1721
+ void 0
1722
+ ).execute();
1723
+ if (this.parent) {
1724
+ this.parent.children = this.parent.children.filter(
1725
+ (child) => child.id !== this.id
1726
+ );
1727
+ this.parent = null;
1728
+ }
1729
+ return ans;
1730
+ }
1731
+ async updateTransform(properties) {
1732
+ this.position = properties.position ?? this.position;
1733
+ this.rotation = properties.rotation ?? this.rotation;
1734
+ this.scale = properties.scale ?? this.scale;
1735
+ return new UpdateEntityPropertiesCommand(this, properties).execute();
1736
+ }
1737
+ async addEvent(type, callback) {
1738
+ if (this.events[type]) {
1739
+ this.events[type] = callback;
965
1740
  } else {
966
- let spatial = new Spatial();
967
- if (spatial.isSupported()) {
968
- let session = spatial.requestSession();
969
- if (session) {
970
- this._instance = new _SpatialHelper(session);
971
- return this._instance;
972
- }
1741
+ try {
1742
+ await this.updateEntityEvent(type, true);
1743
+ this.events[type] = callback;
1744
+ } catch (error) {
1745
+ console.error("addEvent failed", type);
973
1746
  }
974
1747
  }
975
- return null;
976
- }
977
- shape = {
978
- createShapeEntity: async (shape = "box") => {
979
- var box = await this.session.createMeshResource({ shape });
980
- var mat = await this.session.createPhysicallyBasedMaterialResource();
981
- await mat.update();
982
- var customModel = await this.session.createModelComponent();
983
- customModel.setMaterials([mat]);
984
- customModel.setMesh(box);
985
- var boxEntity = await this.session.createEntity();
986
- await boxEntity.setComponent(customModel);
987
- boxEntity.transform.position.z = 0;
988
- boxEntity.transform.scale = new Vec3(0.5, 0.5, 0.5);
989
- await boxEntity.updateTransform();
990
- return boxEntity;
991
- },
992
- createModelEntity: async (url) => {
993
- var customModel = await this.session.createModelComponent({ url });
994
- var boxEntity = await this.session.createEntity();
995
- await boxEntity.setComponent(customModel);
996
- await boxEntity.updateTransform();
997
- return boxEntity;
998
- },
999
- wrapInBoundingBoxEntity: async (entityToWrap) => {
1000
- var bb = await entityToWrap.getBoundingBox();
1001
- var targetSize = 1;
1002
- var scale = targetSize / Math.max(bb.extents.x, bb.extents.y, bb.extents.z);
1003
- entityToWrap.transform.scale.x = scale;
1004
- entityToWrap.transform.scale.y = scale;
1005
- entityToWrap.transform.scale.z = scale;
1006
- entityToWrap.transform.position.x = -bb.center.x * scale;
1007
- entityToWrap.transform.position.y = -bb.center.y * scale;
1008
- entityToWrap.transform.position.z = -bb.center.z * scale;
1009
- await entityToWrap.updateTransform();
1010
- var boudningEntity = await _SpatialHelper.instance?.session.createEntity();
1011
- await entityToWrap.setParent(boudningEntity);
1012
- return boudningEntity;
1748
+ }
1749
+ async removeEvent(eventName) {
1750
+ if (this.events[eventName]) {
1751
+ delete this.events[eventName];
1752
+ try {
1753
+ await this.updateEntityEvent(eventName, false);
1754
+ } catch (error) {
1755
+ console.error("removeEvent failed", eventName);
1756
+ }
1013
1757
  }
1014
- };
1015
- navigation = {
1016
- openPanel: async (url, options) => {
1017
- if (options?.resolution) {
1018
- await this.session.getCurrentWindowContainer()._setOpenSettings({ resolution: options.resolution });
1019
- }
1020
- var wg = await this.session.createWindowContainer({
1021
- style: "Plain",
1022
- windowComponent: null,
1023
- windowContainer: null
1024
- });
1025
- var ent = await this.session.createEntity({
1026
- windowComponent: null,
1027
- windowContainer: wg
1028
- });
1029
- var i = await this.session.createWindowComponent({
1030
- windowComponent: null,
1031
- windowContainer: wg
1032
- });
1033
- await i.loadURL(url);
1034
- await ent.setCoordinateSpace("Root");
1035
- await ent.setComponent(i);
1036
- await wg.setRootEntity(ent);
1037
- await this.session.getCurrentWindowContainer()._setOpenSettings({ resolution: { width: 900, height: 700 } });
1038
- return {
1039
- windowContainer: wg
1040
- };
1041
- },
1042
- openVolume: async (url, options) => {
1043
- var wg = await this.session.createWindowContainer({
1044
- style: "Volumetric",
1045
- windowComponent: null,
1046
- windowContainer: null
1047
- });
1048
- var rootEnt = await this.session.createEntity({
1049
- windowComponent: null,
1050
- windowContainer: wg
1051
- });
1052
- await rootEnt.setComponent(
1053
- await this.session.createViewComponent({
1054
- windowComponent: null,
1055
- windowContainer: wg
1056
- })
1758
+ }
1759
+ async updateEntityEvent(eventName, isEnable) {
1760
+ return new UpdateEntityEventCommand(this, eventName, isEnable).execute();
1761
+ }
1762
+ onReceiveEvent = (data) => {
1763
+ const { type } = data;
1764
+ if (type === "objectdestroy" /* objectdestroy */) {
1765
+ this.isDestroyed = true;
1766
+ } else if (type === "spatialtap" /* spatialtap */) {
1767
+ const evt = createSpatialEvent(
1768
+ "spatialtap" /* spatialtap */,
1769
+ data.detail
1057
1770
  );
1058
- await rootEnt.setCoordinateSpace("Root");
1059
- await wg.setRootEntity(rootEnt);
1060
- var ent = await this.session.createEntity({
1061
- windowComponent: null,
1062
- windowContainer: wg
1063
- });
1064
- var i = await this.session.createWindowComponent({
1065
- windowComponent: null,
1066
- windowContainer: wg
1067
- });
1068
- await i.loadURL(url);
1069
- if (options?.resolution) {
1070
- await i.setResolution(
1071
- options.resolution.width,
1072
- options.resolution.height
1073
- );
1074
- } else {
1075
- await i.setResolution(1e3, 1e3);
1076
- }
1077
- ent.transform.position.z = -0.49;
1078
- await ent.updateTransform();
1079
- await ent.setCoordinateSpace("App");
1080
- await ent.setComponent(i);
1081
- await ent.setParent(rootEnt);
1771
+ this.dispatchEvent(evt);
1772
+ } else if (type === "spatialdragstart" /* spatialdragstart */) {
1773
+ const evt = createSpatialEvent(
1774
+ "spatialdragstart" /* spatialdragstart */,
1775
+ data.detail
1776
+ );
1777
+ this.dispatchEvent(evt);
1778
+ } else if (type === "spatialdrag" /* spatialdrag */) {
1779
+ const evt = createSpatialEvent(
1780
+ "spatialdrag" /* spatialdrag */,
1781
+ data.detail
1782
+ );
1783
+ this.dispatchEvent(evt);
1784
+ } else if (type === "spatialdragend" /* spatialdragend */) {
1785
+ const evt = createSpatialEvent(
1786
+ "spatialdragend" /* spatialdragend */,
1787
+ data.detail
1788
+ );
1789
+ this.dispatchEvent(evt);
1790
+ } else if (type === "spatialrotatestart" /* spatialrotatestart */) {
1791
+ const evt = createSpatialEvent(
1792
+ "spatialrotatestart" /* spatialrotatestart */,
1793
+ data.detail
1794
+ );
1795
+ this.dispatchEvent(evt);
1796
+ } else if (type === "spatialrotate" /* spatialrotate */) {
1797
+ const evt = createSpatialEvent(
1798
+ "spatialrotate" /* spatialrotate */,
1799
+ data.detail
1800
+ );
1801
+ this.dispatchEvent(evt);
1802
+ } else if (type === "spatialrotateend" /* spatialrotateend */) {
1803
+ const evt = createSpatialEvent(
1804
+ "spatialrotateend" /* spatialrotateend */,
1805
+ data.detail
1806
+ );
1807
+ this.dispatchEvent(evt);
1808
+ } else if (type === "spatialmagnifystart" /* spatialmagnifystart */) {
1809
+ const evt = createSpatialEvent(
1810
+ "spatialmagnifystart" /* spatialmagnifystart */,
1811
+ data.detail
1812
+ );
1813
+ this.dispatchEvent(evt);
1814
+ } else if (type === "spatialmagnify" /* spatialmagnify */) {
1815
+ const evt = createSpatialEvent(
1816
+ "spatialmagnify" /* spatialmagnify */,
1817
+ data.detail
1818
+ );
1819
+ this.dispatchEvent(evt);
1820
+ } else if (type === "spatialmagnifyend" /* spatialmagnifyend */) {
1821
+ const evt = createSpatialEvent(
1822
+ "spatialmagnifyend" /* spatialmagnifyend */,
1823
+ data.detail
1824
+ );
1825
+ this.dispatchEvent(evt);
1082
1826
  }
1083
1827
  };
1084
- dom = {
1085
- attachSpatialView: async (divOnPage) => {
1086
- var viewEnt = await this.session.createEntity();
1087
- await viewEnt.setCoordinateSpace("Dom");
1088
- await viewEnt.setComponent(await this.session.createViewComponent());
1089
- var wc = await this.session.getCurrentWindowComponent();
1090
- var ent = await wc.getEntity();
1091
- await viewEnt.setParent(ent);
1092
- var update = () => {
1093
- var rect = divOnPage.getBoundingClientRect();
1094
- viewEnt.transform.position.x = rect.x + rect.width / 2;
1095
- viewEnt.transform.position.y = rect.y + rect.height / 2 + window.scrollY;
1096
- viewEnt.updateTransform();
1097
- viewEnt.getComponent(SpatialViewComponent).setResolution(rect.width, rect.height);
1098
- };
1099
- var mo = new MutationObserver(update);
1100
- mo.observe(divOnPage, { attributes: true });
1101
- var ro = new ResizeObserver(update);
1102
- ro.observe(divOnPage);
1103
- const addRemoveObserver = new MutationObserver((mutations) => {
1104
- mutations.forEach((mutation) => {
1105
- mutation.removedNodes.forEach((node) => {
1106
- if (node instanceof HTMLElement) {
1107
- update();
1108
- }
1109
- });
1110
- mutation.addedNodes.forEach((node) => {
1111
- if (node instanceof HTMLElement) {
1112
- update();
1113
- }
1114
- });
1115
- });
1116
- });
1117
- addRemoveObserver.observe(document.body, {
1118
- childList: true,
1119
- subtree: true
1120
- });
1121
- update();
1122
- return {
1123
- entity: viewEnt
1124
- };
1828
+ dispatchEvent(evt) {
1829
+ if (!evt.__origin) {
1830
+ Object.defineProperty(evt, "__origin", { value: this, enumerable: false });
1125
1831
  }
1126
- };
1127
- setBackgroundStyle = async (style, backgroundColor = "#00000000") => {
1128
- document.documentElement.style.backgroundColor = backgroundColor;
1129
- await this.session.getCurrentWindowComponent().setStyle(style);
1130
- };
1131
- };
1132
-
1133
- // src/core/component/SpatialWindowComponent.ts
1134
- var SpatialWindowComponent = class extends SpatialComponent {
1135
- /**
1136
- * Loads a url page in the window
1137
- * @param url url to load
1138
- */
1139
- async loadURL(url) {
1140
- await WebSpatial.updateResource(this._resource, { url });
1141
- }
1142
- async setFromWindow(window2) {
1143
- if (window2._webSpatialID) {
1144
- await WebSpatial.updateResource(this._resource, {
1145
- windowID: window2._webSpatialID
1146
- });
1147
- } else {
1148
- await console.warn(
1149
- "failed to call setFromWindow, window provided is not valid"
1150
- );
1832
+ this.events[evt.type]?.(evt);
1833
+ if (evt.bubbles && !evt.cancelBubble) {
1834
+ if (this.parent && this.parent instanceof _SpatialEntity) {
1835
+ this.parent.dispatchEvent(evt);
1836
+ }
1151
1837
  }
1152
1838
  }
1153
- /**
1154
- * Sets the resolution of the window, the resulting dimensions when rendered will be equal to 1/1360 units
1155
- * eg. if the resolution is set to 1360x1360 it will be a 1x1 plane
1156
- * See 1360 in spatialViewUI.swift for how this ratio works
1157
- * @param width width in pixels
1158
- * @param height height in pixels
1159
- */
1160
- async setResolution(width, height) {
1161
- await WebSpatial.updateResource(this._resource, {
1162
- resolution: { x: width, y: height }
1839
+ onDestroy() {
1840
+ SpatialWebEvent.removeEventReceiver(this.id);
1841
+ this.children.forEach((child) => {
1842
+ child.parent = null;
1163
1843
  });
1844
+ this.children = [];
1845
+ if (this.parent) {
1846
+ this.parent.children = this.parent.children.filter(
1847
+ (child) => child.id !== this.id
1848
+ );
1849
+ this.parent = null;
1850
+ }
1164
1851
  }
1165
- /**
1166
- * [Experimental] Sets the anchor which the entity this is attached to will rotate around
1167
- * @param rotationAnchor
1168
- */
1169
- async setRotationAnchor(rotationAnchor) {
1170
- await WebSpatial.updateResource(this._resource, {
1171
- rotationAnchor
1172
- });
1852
+ // onUpdate(properties: SpatialEntityProperties) {
1853
+ // this.position = properties.position
1854
+ // this.rotation = properties.rotation
1855
+ // this.scale = properties.scale
1856
+ // }
1857
+ async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
1858
+ return new ConvertFromEntityToEntityCommand(
1859
+ fromEntityId,
1860
+ toEntityId,
1861
+ position
1862
+ ).execute();
1173
1863
  }
1174
- /**
1175
- * [Experimental] Sets the opacity of the window after apply material
1176
- * @param opacity
1177
- */
1178
- async setOpacity(opacity) {
1179
- await WebSpatial.updateResource(this._resource, {
1180
- opacity
1181
- });
1864
+ async convertFromEntityToScene(fromEntityId, position) {
1865
+ return new ConvertFromEntityToSceneCommand(fromEntityId, position).execute();
1182
1866
  }
1183
- /**
1184
- * Sets the style that should be applied to the window
1185
- * @param options style options
1186
- */
1187
- async setStyle(styleParam) {
1188
- const currentWindowComponent = SpatialHelper.instance?.session.getCurrentWindowComponent();
1189
- const isSettingSelfStyle = currentWindowComponent?._resource.id == this._resource.id;
1190
- const { material, cornerRadius } = styleParam;
1191
- const options = {};
1192
- if (material?.type) {
1193
- options.backgroundMaterial = material.type;
1194
- }
1195
- if (cornerRadius !== void 0) {
1196
- if (typeof cornerRadius === "number") {
1197
- options.cornerRadius = {
1198
- topLeading: cornerRadius,
1199
- bottomLeading: cornerRadius,
1200
- topTrailing: cornerRadius,
1201
- bottomTrailing: cornerRadius
1202
- };
1203
- } else {
1204
- options.cornerRadius = { ...cornerRadius };
1205
- }
1206
- }
1207
- if (isSettingSelfStyle && document && document.readyState == "loading") {
1208
- var encoded = encodeURIComponent(JSON.stringify(options));
1209
- const a = document.createElement(`a`);
1210
- a.href = "forcestyle://mystyle.css?style=" + encoded;
1211
- document.body.appendChild(a);
1212
- a.click();
1213
- a.remove();
1214
- } else {
1215
- await WebSpatial.updateResource(this._resource, { style: options });
1216
- }
1867
+ async convertFromSceneToEntity(entityId, position) {
1868
+ return new ConvertFromSceneToEntityCommand(entityId, position).execute();
1217
1869
  }
1218
- /**
1219
- * Modifies the amount the spatial window can be scrolled
1220
- * Should only be used internally
1221
- * See https://developer.apple.com/documentation/uikit/1624475-uiedgeinsetsmake?language=objc
1222
- * @param insets margin to modify scroll distances by
1223
- */
1224
- async setScrollEdgeInsets(insets) {
1225
- await WebSpatial.updateResource(this._resource, {
1226
- setScrollEdgeInsets: insets
1227
- });
1870
+ };
1871
+
1872
+ // src/reality/entity/SpatialModelEntity.ts
1873
+ var SpatialModelEntity = class extends SpatialEntity {
1874
+ constructor(id, options, userData) {
1875
+ super(id, userData);
1876
+ this.id = id;
1877
+ this.options = options;
1878
+ this.userData = userData;
1228
1879
  }
1229
- /**
1230
- * Enable/Disable scrolling in the window (defaults to enabled), if disabled, scrolling will be applied to the root page
1231
- * @param enabled value to set
1232
- */
1233
- async setScrollEnabled(enabled) {
1234
- await WebSpatial.updateResource(this._resource, { scrollEnabled: enabled });
1880
+ };
1881
+
1882
+ // src/reality/component/SpatialComponent.ts
1883
+ init_SpatialWebEvent();
1884
+ var SpatialComponent = class extends SpatialObject {
1885
+ constructor(id) {
1886
+ super(id);
1887
+ SpatialWebEvent.addEventReceiver(id, this.onReceiveEvent);
1888
+ }
1889
+ onReceiveEvent = (data) => {
1890
+ const { type } = data;
1891
+ if (type === "objectdestroy" /* objectdestroy */) {
1892
+ this.isDestroyed = true;
1893
+ }
1894
+ };
1895
+ };
1896
+
1897
+ // src/reality/component/ModelComponent.ts
1898
+ var ModelComponent = class extends SpatialComponent {
1899
+ constructor(id, options) {
1900
+ super(id);
1901
+ this.options = options;
1235
1902
  }
1236
- /**
1237
- * Defaults to false. If set to true, scrolling the parent page will also scroll this window with it like other dom elements
1238
- * @param scrollWithParent value to set
1239
- */
1240
- async setScrollWithParent(scrollWithParent) {
1241
- await WebSpatial.updateResource(this._resource, {
1242
- scrollWithParent
1243
- });
1903
+ };
1904
+
1905
+ // src/reality/material/SpatialUnlitMaterial.ts
1906
+ init_JSBCommand();
1907
+
1908
+ // src/reality/material/SpatialMaterial.ts
1909
+ var SpatialMaterial = class extends SpatialObject {
1910
+ constructor(id, type) {
1911
+ super(id);
1912
+ this.id = id;
1913
+ this.type = type;
1914
+ this.type = type;
1244
1915
  }
1245
1916
  };
1246
1917
 
1247
- // src/core/component/EventSpatialComponent.ts
1248
- var EventSpatialComponent = class extends SpatialComponent {
1249
- // Class implementation goes here
1250
- constructor(_resource) {
1251
- super(_resource);
1252
- WebSpatial.registerEventReceiver(_resource.id, (data) => {
1253
- this.onRecvEvent(data);
1254
- });
1918
+ // src/reality/material/SpatialUnlitMaterial.ts
1919
+ var SpatialUnlitMaterial = class extends SpatialMaterial {
1920
+ constructor(id, options) {
1921
+ super(id, "unlit");
1922
+ this.id = id;
1923
+ this.options = options;
1255
1924
  }
1256
- async onDestroy() {
1257
- WebSpatial.unregisterEventReceiver(this._resource.id);
1925
+ updateProperties(properties) {
1926
+ return new UpdateUnlitMaterialProperties(this, properties).execute();
1258
1927
  }
1259
1928
  };
1260
1929
 
1261
- // src/core/component/SpatialInputComponent.ts
1262
- var SpatialInputComponent = class extends EventSpatialComponent {
1263
- onRecvEvent(data) {
1264
- this.onTranslate(data);
1930
+ // src/reality/resource/SpatialModelAsset.ts
1931
+ var SpatialModelAsset = class extends SpatialObject {
1932
+ constructor(id, options) {
1933
+ super(id);
1934
+ this.id = id;
1935
+ this.options = options;
1265
1936
  }
1266
- /**
1267
- * Callback fired when a translate event occurs
1268
- * @param data translate event data
1269
- */
1270
- onTranslate(data) {
1937
+ };
1938
+
1939
+ // src/reality/realityCreator.ts
1940
+ async function createSpatialEntity(userData) {
1941
+ const result = await new CreateSpatialEntityCommand(userData?.name).execute();
1942
+ if (!result.success) {
1943
+ throw new Error("createSpatialEntity failed:" + result?.errorMessage);
1944
+ } else {
1945
+ const { id } = result.data;
1946
+ return new SpatialEntity(id, userData);
1271
1947
  }
1948
+ }
1949
+ async function createSpatialGeometry(ctor, options) {
1950
+ const result = await new CreateSpatialGeometryCommand(
1951
+ ctor.type,
1952
+ options
1953
+ ).execute();
1954
+ if (!result.success) {
1955
+ throw new Error("createSpatialGeometry failed:" + result?.errorMessage);
1956
+ } else {
1957
+ const { id } = result.data;
1958
+ return new ctor(id, options);
1959
+ }
1960
+ }
1961
+ async function createSpatialUnlitMaterial(options) {
1962
+ const result = await new CreateSpatialUnlitMaterialCommand(options).execute();
1963
+ if (!result.success) {
1964
+ throw new Error("createSpatialUnlitMaterial failed:" + result?.errorMessage);
1965
+ } else {
1966
+ const { id } = result.data;
1967
+ return new SpatialUnlitMaterial(id, options);
1968
+ }
1969
+ }
1970
+ async function createModelComponent(options) {
1971
+ const result = await new CreateModelComponentCommand(options).execute();
1972
+ if (!result.success) {
1973
+ throw new Error("createModelComponent failed:" + result?.errorMessage);
1974
+ } else {
1975
+ const { id } = result.data;
1976
+ return new ModelComponent(id, options);
1977
+ }
1978
+ }
1979
+ async function createSpatialModelEntity(options, userData) {
1980
+ const result = await new CreateSpatialModelEntityCommand(options).execute();
1981
+ if (!result.success) {
1982
+ throw new Error("createSpatialModelEntity failed:" + result?.errorMessage);
1983
+ } else {
1984
+ const { id } = result.data;
1985
+ return new SpatialModelEntity(id, options, userData);
1986
+ }
1987
+ }
1988
+ async function createModelAsset(options) {
1989
+ const result = await new CreateModelAssetCommand(options).execute();
1990
+ if (!result.success) {
1991
+ throw new Error("createModelAsset failed:" + result?.errorMessage);
1992
+ } else {
1993
+ const { id } = result.data;
1994
+ return new SpatialModelAsset(id, options);
1995
+ }
1996
+ }
1997
+
1998
+ // src/reality/geometry/SpatialGeometry.ts
1999
+ var SpatialGeometry = class extends SpatialObject {
2000
+ constructor(id, options) {
2001
+ super(id);
2002
+ this.id = id;
2003
+ this.options = options;
2004
+ }
2005
+ static type;
2006
+ };
2007
+
2008
+ // src/reality/geometry/SpatialBoxGeometry.ts
2009
+ var SpatialBoxGeometry = class extends SpatialGeometry {
2010
+ constructor(id, options) {
2011
+ super(id, options);
2012
+ this.id = id;
2013
+ this.options = options;
2014
+ }
2015
+ static type = "BoxGeometry";
2016
+ };
2017
+
2018
+ // src/reality/geometry/SpatialSphereGeometry.ts
2019
+ var SpatialSphereGeometry = class extends SpatialGeometry {
2020
+ constructor(id, options) {
2021
+ super(id, options);
2022
+ this.id = id;
2023
+ this.options = options;
2024
+ }
2025
+ static type = "SphereGeometry";
1272
2026
  };
1273
2027
 
1274
- // src/core/component/SpatialModelComponent.ts
1275
- var SpatialModelComponent = class extends SpatialComponent {
1276
- cachedMaterials = new Array();
2028
+ // src/reality/geometry/SpatialCylinderGeometry.ts
2029
+ var SpatialCylinderGeometry = class extends SpatialGeometry {
2030
+ constructor(id, options) {
2031
+ super(id, options);
2032
+ this.id = id;
2033
+ this.options = options;
2034
+ }
2035
+ static type = "CylinderGeometry";
2036
+ };
2037
+
2038
+ // src/reality/geometry/SpatialPlaneGeometry.ts
2039
+ var SpatialPlaneGeometry = class extends SpatialGeometry {
2040
+ constructor(id, options) {
2041
+ super(id, options);
2042
+ this.id = id;
2043
+ this.options = options;
2044
+ }
2045
+ static type = "PlaneGeometry";
2046
+ };
2047
+
2048
+ // src/reality/geometry/SpatialConeGeometry.ts
2049
+ var SpatialConeGeometry = class extends SpatialGeometry {
2050
+ constructor(id, options) {
2051
+ super(id, options);
2052
+ this.id = id;
2053
+ this.options = options;
2054
+ }
2055
+ static type = "ConeGeometry";
2056
+ };
2057
+
2058
+ // src/SpatialSession.ts
2059
+ var SpatialSession = class {
1277
2060
  /**
1278
- * Sets the mesh to be displayed by the component
1279
- * @param mesh mesh to set
2061
+ * Gets the singleton instance of the spatial scene.
2062
+ * The spatial scene is the root container for all spatial elements.
2063
+ * @returns The SpatialScene singleton instance
1280
2064
  */
1281
- async setMesh(mesh) {
1282
- await WebSpatial.updateResource(this._resource, {
1283
- meshResource: mesh._resource.id
1284
- });
2065
+ getSpatialScene() {
2066
+ return SpatialScene.getInstance();
1285
2067
  }
1286
2068
  /**
1287
- * Sets the materials that should be applied to the mesh
1288
- * @param materials array of materials to set
2069
+ * Creates a new 2D element that can be spatialized in the 3D environment.
2070
+ * 2D elements represent HTML content that can be positioned in 3D space.
2071
+ * @returns Promise resolving to a new Spatialized2DElement instance
1289
2072
  */
1290
- async setMaterials(materials) {
1291
- this.cachedMaterials = materials;
1292
- await WebSpatial.updateResource(this._resource, {
1293
- materials: materials.map((m) => {
1294
- m._addToComponent(this);
1295
- return m._resource.id;
1296
- })
1297
- });
2073
+ createSpatialized2DElement() {
2074
+ return createSpatialized2DElement();
1298
2075
  }
1299
- /** @hidden */
1300
- async _syncMaterials() {
1301
- await this.setMaterials(this.cachedMaterials);
1302
- }
1303
- };
1304
-
1305
- // src/core/component/SpatialViewComponent.ts
1306
- var SpatialViewComponent = class extends SpatialComponent {
1307
2076
  /**
1308
- * Sets the resolution of the spatial view in dom pixels
2077
+ * Creates a new static 3D element with an optional model URL.
2078
+ * Static 3D elements represent pre-built 3D models that can be loaded from a URL.
2079
+ * @param modelURL Optional URL to the 3D model to load
2080
+ * @returns Promise resolving to a new SpatializedStatic3DElement instance
1309
2081
  */
1310
- async setResolution(width, height) {
1311
- await WebSpatial.updateResource(this._resource, {
1312
- resolution: { x: width, y: height }
1313
- });
2082
+ createSpatializedStatic3DElement(modelURL = "") {
2083
+ return createSpatializedStatic3DElement(modelURL);
1314
2084
  }
1315
2085
  /**
1316
- * Sets if content of the spatialView should be within a portal
1317
- * If true, volume will be behind the page, if false, it will be in front of the page
2086
+ * Initializes the spatial scene with custom configuration.
2087
+ * This is a reference to the initScene function from scene-polyfill.
1318
2088
  */
1319
- async setIsPortal(isPortal) {
1320
- await WebSpatial.updateResource(this._resource, {
1321
- isPortal
1322
- });
1323
- }
1324
- };
1325
-
1326
- // src/core/component/SpatialModel3DComponent.ts
1327
- var SpatialModel3DComponent = class extends EventSpatialComponent {
1328
- onRecvEvent(data) {
1329
- const { eventType, value, error } = data;
1330
- switch (eventType) {
1331
- case "phase":
1332
- if (value === "success") {
1333
- this.onSuccess?.();
1334
- } else {
1335
- this.onFailure?.(error);
1336
- }
1337
- break;
1338
- case "dragstart":
1339
- this._onDragStart?.(value);
1340
- break;
1341
- case "dragend":
1342
- this._onDragEnd?.(value);
1343
- break;
1344
- case "drag":
1345
- this._onDrag?.(value);
1346
- break;
1347
- case "tap":
1348
- this._onTap?.();
1349
- break;
1350
- case "doubletap":
1351
- this._onDoubleTap?.();
1352
- break;
1353
- case "longpress":
1354
- this._onLongPress?.();
1355
- break;
1356
- default:
1357
- break;
1358
- }
2089
+ initScene = initScene;
2090
+ /**
2091
+ * Creates a new dynamic 3D element that can be manipulated at runtime.
2092
+ * Dynamic 3D elements allow for programmatic creation and modification of 3D content.
2093
+ * @returns Promise resolving to a new SpatializedDynamic3DElement instance
2094
+ */
2095
+ createSpatializedDynamic3DElement() {
2096
+ return createSpatializedDynamic3DElement();
1359
2097
  }
1360
2098
  /**
1361
- * Sets the resolution of the spatial view in dom pixels
2099
+ * Creates a new spatial entity with an optional name.
2100
+ * Entities are the basic building blocks for creating custom 3D content.
2101
+ * @param name Optional name for the entity
2102
+ * @returns Promise resolving to a new SpatialEntity instance
1362
2103
  */
1363
- async setResolution(width, height) {
1364
- await WebSpatial.updateResource(this._resource, {
1365
- resolution: { x: width, y: height }
1366
- });
2104
+ createEntity(userData) {
2105
+ return createSpatialEntity(userData);
1367
2106
  }
1368
- async setRotationAnchor(rotationAnchor) {
1369
- await WebSpatial.updateResource(this._resource, {
1370
- rotationAnchor
1371
- });
2107
+ /**
2108
+ * Creates a box geometry with optional configuration.
2109
+ * @param options Configuration options for the box geometry
2110
+ * @returns Promise resolving to a new SpatialBoxGeometry instance
2111
+ */
2112
+ createBoxGeometry(options = {}) {
2113
+ return createSpatialGeometry(SpatialBoxGeometry, options);
1372
2114
  }
1373
2115
  /**
1374
- * Sets the opacity of the model
1375
- * @param opacity
2116
+ * Creates a plane geometry with optional configuration.
2117
+ * @param options Configuration options for the plane geometry
2118
+ * @returns Promise resolving to a new SpatialPlaneGeometry instance
1376
2119
  */
1377
- async setOpacity(opacity) {
1378
- await WebSpatial.updateResource(this._resource, {
1379
- opacity
1380
- });
2120
+ createPlaneGeometry(options = {}) {
2121
+ return createSpatialGeometry(SpatialPlaneGeometry, options);
1381
2122
  }
1382
2123
  /**
1383
- * Sets how the model fill the rect
1384
- * @param contentMode
2124
+ * Creates a sphere geometry with optional configuration.
2125
+ * @param options Configuration options for the sphere geometry
2126
+ * @returns Promise resolving to a new SpatialSphereGeometry instance
1385
2127
  */
1386
- async setContentMode(contentMode) {
1387
- await WebSpatial.updateResource(this._resource, {
1388
- contentMode
1389
- });
2128
+ createSphereGeometry(options = {}) {
2129
+ return createSpatialGeometry(SpatialSphereGeometry, options);
1390
2130
  }
1391
2131
  /**
1392
- * Constrains this model dimensions to the specified aspect ratio.
1393
- * with a value of 0, the model will use the original aspect ratio.
1394
- *
1395
- * @param aspectRatio number
2132
+ * Creates a cone geometry with the specified configuration.
2133
+ * @param options Configuration options for the cone geometry
2134
+ * @returns Promise resolving to a new SpatialConeGeometry instance
1396
2135
  */
1397
- async setAspectRatio(aspectRatio) {
1398
- await WebSpatial.updateResource(this._resource, {
1399
- aspectRatio
1400
- });
2136
+ createConeGeometry(options) {
2137
+ return createSpatialGeometry(SpatialConeGeometry, options);
1401
2138
  }
1402
2139
  /**
1403
- * Defaults to false. If set to true, scrolling the parent page will also scroll this window with it like other dom elements
1404
- * @param scrollWithParent value to set
2140
+ * Creates a cylinder geometry with the specified configuration.
2141
+ * @param options Configuration options for the cylinder geometry
2142
+ * @returns Promise resolving to a new SpatialCylinderGeometry instance
1405
2143
  */
1406
- async setScrollWithParent(scrollWithParent) {
1407
- await WebSpatial.updateResource(this._resource, {
1408
- scrollWithParent
1409
- });
2144
+ createCylinderGeometry(options) {
2145
+ return createSpatialGeometry(SpatialCylinderGeometry, options);
1410
2146
  }
1411
2147
  /**
1412
- * Sets whether the model appear in original size or fit the rect
1413
- * @param resizable
2148
+ * Creates a model component with the specified configuration.
2149
+ * Model components are used to add 3D model rendering capabilities to entities.
2150
+ * @param options Configuration options for the model component
2151
+ * @returns Promise resolving to a new ModelComponent instance
1414
2152
  */
1415
- async setResizable(resizable) {
1416
- await WebSpatial.updateResource(this._resource, {
1417
- resizable
1418
- });
2153
+ createModelComponent(options) {
2154
+ return createModelComponent(options);
1419
2155
  }
1420
2156
  /**
1421
- * Callback fired when model load success
2157
+ * Creates an unlit material with the specified configuration.
2158
+ * Unlit materials don't respond to lighting in the scene.
2159
+ * @param options Configuration options for the unlit material
2160
+ * @returns Promise resolving to a new SpatialUnlitMaterial instance
1422
2161
  */
1423
- onSuccess;
2162
+ createUnlitMaterial(options) {
2163
+ return createSpatialUnlitMaterial(options);
2164
+ }
1424
2165
  /**
1425
- * Callback fired when model load failure
1426
- * @param errorReason
2166
+ * Creates a model asset with the specified configuration.
2167
+ * Model assets represent 3D model resources that can be used by entities.
2168
+ * @param options Configuration options for the model asset
2169
+ * @returns Promise resolving to a new SpatialModelAsset instance
1427
2170
  */
1428
- onFailure;
2171
+ createModelAsset(options) {
2172
+ return createModelAsset(options);
2173
+ }
1429
2174
  /**
1430
- * Callback fired when model was dragged at the beginning
1431
- * @param dragEvent
2175
+ * Creates a spatial model entity with the specified configuration.
2176
+ * This is a convenience method for creating an entity with a model component.
2177
+ * @param options Configuration options for the spatial model entity
2178
+ * @returns Promise resolving to a new SpatialModelEntity instance
1432
2179
  */
1433
- _onDragStart;
1434
- set onDragStart(callback) {
1435
- if (this._onDragStart !== callback) {
1436
- this._onDragStart = callback;
1437
- WebSpatial.updateResource(this._resource, {
1438
- enableDragEvent: this.enableDragEvent
1439
- });
1440
- }
2180
+ createSpatialModelEntity(options, userData) {
2181
+ return createSpatialModelEntity(options, userData);
1441
2182
  }
2183
+ };
2184
+
2185
+ // src/Spatial.ts
2186
+ init_SpatialWebEvent();
2187
+ var Spatial = class {
1442
2188
  /**
1443
- * Callback fired when model was dragged
1444
- * @param dragEvent
2189
+ * Requests a spatial session object from the browser.
2190
+ * This is the primary method to initialize spatial functionality.
2191
+ * @returns The SpatialSession instance or null if not available in the current browser
2192
+ * [TODO] discuss implications of this not being async
1445
2193
  */
1446
- _onDrag;
1447
- set onDrag(callback) {
1448
- if (this._onDrag !== callback) {
1449
- this._onDrag = callback;
1450
- WebSpatial.updateResource(this._resource, {
1451
- enableDragEvent: this.enableDragEvent
1452
- });
2194
+ requestSession() {
2195
+ if (this.runInSpatialWeb()) {
2196
+ SpatialWebEvent.init();
2197
+ return new SpatialSession();
2198
+ } else {
2199
+ return null;
1453
2200
  }
1454
2201
  }
1455
2202
  /**
1456
- * Callback fired when model was dragged at the ending
1457
- * @param dragEvent
2203
+ * Checks if the current page is running in a spatial web environment.
2204
+ * This method detects if the application is running in a WebSpatial-compatible browser.
2205
+ * @returns True if running in a spatial web environment, false otherwise
1458
2206
  */
1459
- _onDragEnd;
1460
- set onDragEnd(callback) {
1461
- if (this._onDragEnd !== callback) {
1462
- this._onDragEnd = callback;
1463
- WebSpatial.updateResource(this._resource, {
1464
- enableDragEvent: this.enableDragEvent
1465
- });
2207
+ runInSpatialWeb() {
2208
+ if (navigator.userAgent.indexOf("WebSpatial/") > 0) {
2209
+ return true;
1466
2210
  }
2211
+ return false;
1467
2212
  }
1468
- get enableDragEvent() {
1469
- return void 0 !== this._onDrag || void 0 !== this._onDragStart || void 0 !== this._onDragEnd;
2213
+ /** @deprecated
2214
+ * Checks if WebSpatial is supported in the current environment.
2215
+ * Verifies compatibility between native and client versions.
2216
+ * @returns True if web spatial is supported by this webpage
2217
+ */
2218
+ isSupported() {
2219
+ return true;
1470
2220
  }
1471
- /**
1472
- * Callback fired when model was tapped
2221
+ /** @deprecated
2222
+ * Gets the native WebSpatial version from the browser environment.
2223
+ * The version format follows semantic versioning (x.x.x).
2224
+ * @returns Native version string in format "x.x.x"
1473
2225
  */
1474
- _onTap;
1475
- set onTap(callback) {
1476
- if (this._onTap !== callback) {
1477
- this._onTap = callback;
1478
- WebSpatial.updateResource(this._resource, {
1479
- enableTapEvent: void 0 !== callback
1480
- });
2226
+ getNativeVersion() {
2227
+ if (window.__WebSpatialData && window.__WebSpatialData.getNativeVersion) {
2228
+ return window.__WebSpatialData.getNativeVersion();
1481
2229
  }
2230
+ return window.WebSpatailNativeVersion === "PACKAGE_VERSION" ? this.getClientVersion() : window.WebSpatailNativeVersion;
1482
2231
  }
1483
- /** Callback fired when model was double tapped */
1484
- _onDoubleTap;
1485
- set onDoubleTap(callback) {
1486
- if (this._onDoubleTap !== callback) {
1487
- this._onDoubleTap = callback;
1488
- WebSpatial.updateResource(this._resource, {
1489
- enableDoubleTapEvent: void 0 !== callback
1490
- });
1491
- }
2232
+ /** @deprecated
2233
+ * Gets the client SDK version.
2234
+ * The version format follows semantic versioning (x.x.x).
2235
+ * @returns Client SDK version string in format "x.x.x"
2236
+ */
2237
+ getClientVersion() {
2238
+ return "1.1.0";
1492
2239
  }
1493
- /** Callback fired when model was long pressed */
1494
- _onLongPress;
1495
- set onLongPress(callback) {
1496
- if (this._onLongPress !== callback) {
1497
- this._onLongPress = callback;
1498
- WebSpatial.updateResource(this._resource, {
1499
- enableLongPressEvent: void 0 !== callback
1500
- });
1501
- }
2240
+ };
2241
+
2242
+ // src/index.ts
2243
+ init_ssr_polyfill();
2244
+
2245
+ // src/spatial-window-polyfill.ts
2246
+ init_utils();
2247
+ var spatial = new Spatial();
2248
+ var session = void 0;
2249
+ var SpatialGlobalCustomVars = {
2250
+ backgroundMaterial: "--xr-background-material"
2251
+ };
2252
+ var htmlBackgroundMaterial = "";
2253
+ function setCurrentWindowStyle(backgroundMaterial) {
2254
+ if (backgroundMaterial !== htmlBackgroundMaterial) {
2255
+ session?.getSpatialScene()?.updateSpatialProperties({
2256
+ material: backgroundMaterial
2257
+ });
2258
+ htmlBackgroundMaterial = backgroundMaterial;
1502
2259
  }
2260
+ }
2261
+ function checkHtmlBackgroundMaterial() {
2262
+ const computedStyle = getComputedStyle(document.documentElement);
2263
+ const backgroundMaterial = computedStyle.getPropertyValue(
2264
+ SpatialGlobalCustomVars.backgroundMaterial
2265
+ );
2266
+ setCurrentWindowStyle(backgroundMaterial || "none");
2267
+ }
2268
+ var htmlCornerRadius = {
2269
+ topLeading: 0,
2270
+ bottomLeading: 0,
2271
+ topTrailing: 0,
2272
+ bottomTrailing: 0
1503
2273
  };
2274
+ function checkCornerRadius() {
2275
+ const computedStyle = getComputedStyle(document.documentElement);
2276
+ const cornerRadius = parseCornerRadius(computedStyle);
2277
+ setCornerRadius(cornerRadius);
2278
+ }
2279
+ function setCornerRadius(cornerRadius) {
2280
+ if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
2281
+ session?.getSpatialScene()?.updateSpatialProperties({
2282
+ cornerRadius
2283
+ });
2284
+ htmlCornerRadius.topLeading = cornerRadius.topLeading;
2285
+ htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
2286
+ htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
2287
+ htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
2288
+ }
2289
+ }
2290
+ function setOpacity(opacity) {
2291
+ session?.getSpatialScene().updateSpatialProperties({
2292
+ opacity
2293
+ });
2294
+ }
2295
+ function checkOpacity() {
2296
+ const computedStyle = getComputedStyle(document.documentElement);
2297
+ const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
2298
+ setOpacity(opacity);
2299
+ }
2300
+ function hijackDocumentElementStyle() {
2301
+ const rawDocumentStyle = document.documentElement.style;
2302
+ const styleProxy = new Proxy(rawDocumentStyle, {
2303
+ set: function(target, key, value) {
2304
+ const ret = Reflect.set(target, key, value);
2305
+ if (key === SpatialGlobalCustomVars.backgroundMaterial) {
2306
+ setCurrentWindowStyle(value);
2307
+ }
2308
+ if (key === "border-radius" || key === "borderRadius" || key === "border-top-left-radius" || key === "borderTopLeftRadius" || key === "border-top-right-radius" || key === "borderTopRightRadius" || key === "border-bottom-left-radius" || key === "borderBottomLeftRadius" || key === "border-bottom-right-radius" || key === "borderBottomRightRadius") {
2309
+ checkCornerRadius();
2310
+ }
2311
+ if (key === "opacity") {
2312
+ checkOpacity();
2313
+ }
2314
+ return ret;
2315
+ },
2316
+ get: function(target, prop) {
2317
+ if (typeof target[prop] === "function") {
2318
+ return function(...args) {
2319
+ if (prop === "setProperty") {
2320
+ const [property, value] = args;
2321
+ if (property === SpatialGlobalCustomVars.backgroundMaterial) {
2322
+ setCurrentWindowStyle(value);
2323
+ }
2324
+ } else if (prop === "removeProperty") {
2325
+ const [property] = args;
2326
+ if (property === SpatialGlobalCustomVars.backgroundMaterial) {
2327
+ setCurrentWindowStyle("none");
2328
+ }
2329
+ }
2330
+ return target[prop](
2331
+ ...args
2332
+ );
2333
+ };
2334
+ }
2335
+ return Reflect.get(target, prop);
2336
+ }
2337
+ });
2338
+ Object.defineProperty(document.documentElement, "style", {
2339
+ get: function() {
2340
+ return styleProxy;
2341
+ }
2342
+ });
2343
+ }
2344
+ function monitorExternalStyleChange() {
2345
+ const headObserver = new MutationObserver(checkCSSProperties);
2346
+ headObserver.observe(document.head, { childList: true, subtree: true });
2347
+ }
2348
+ function checkCSSProperties() {
2349
+ checkHtmlBackgroundMaterial();
2350
+ checkCornerRadius();
2351
+ checkOpacity();
2352
+ }
2353
+ function monitorHTMLAttributeChange() {
2354
+ const observer = new MutationObserver((mutations) => {
2355
+ mutations.forEach((mutation) => {
2356
+ if (mutation.type === "attributes" && mutation.attributeName) {
2357
+ checkCSSProperties();
2358
+ }
2359
+ });
2360
+ });
2361
+ observer.observe(document.documentElement, {
2362
+ attributes: true,
2363
+ attributeFilter: ["style", "class"]
2364
+ });
2365
+ }
2366
+ async function spatialWindowPolyfill() {
2367
+ if (!spatial.runInSpatialWeb()) {
2368
+ return;
2369
+ }
2370
+ session = await spatial.requestSession();
2371
+ if (document.readyState === "complete") {
2372
+ checkCSSProperties();
2373
+ } else {
2374
+ window.addEventListener("load", () => {
2375
+ checkCSSProperties();
2376
+ });
2377
+ }
2378
+ hijackDocumentElementStyle();
2379
+ monitorExternalStyleChange();
2380
+ monitorHTMLAttributeChange();
2381
+ }
2382
+
2383
+ // src/index.ts
2384
+ if (!isSSREnv() && navigator.userAgent.indexOf("WebSpatial/") > 0) {
2385
+ injectSceneHook();
2386
+ spatialWindowPolyfill();
2387
+ }
1504
2388
  export {
2389
+ BaseplateVisibilityValues,
2390
+ CubeInfo,
2391
+ ModelComponent,
1505
2392
  Spatial,
2393
+ SpatialBoxGeometry,
1506
2394
  SpatialComponent,
2395
+ SpatialConeGeometry,
2396
+ SpatialCylinderGeometry,
1507
2397
  SpatialEntity,
1508
- SpatialHelper,
1509
- SpatialInputComponent,
1510
- SpatialMeshResource,
1511
- SpatialModel3DComponent,
1512
- SpatialModelComponent,
1513
- SpatialPhysicallyBasedMaterialResource,
2398
+ SpatialGeometry,
2399
+ SpatialMaterial,
2400
+ SpatialModelAsset,
2401
+ SpatialModelEntity,
2402
+ SpatialObject,
2403
+ SpatialPlaneGeometry,
2404
+ SpatialScene,
2405
+ SpatialSceneState,
2406
+ SpatialSceneValues,
1514
2407
  SpatialSession,
1515
- SpatialTransform,
1516
- SpatialViewComponent,
1517
- SpatialWindowComponent,
1518
- SpatialWindowContainer,
1519
- Vec3,
1520
- Vec4
2408
+ SpatialSphereGeometry,
2409
+ SpatialUnlitMaterial,
2410
+ Spatialized2DElement,
2411
+ SpatializedDynamic3DElement,
2412
+ SpatializedElement,
2413
+ SpatializedElementType,
2414
+ SpatializedStatic3DElement,
2415
+ WorldAlignmentValues,
2416
+ WorldScalingValues,
2417
+ isSSREnv,
2418
+ isValidBaseplateVisibilityType,
2419
+ isValidSceneUnit,
2420
+ isValidSpatialSceneType,
2421
+ isValidWorldAlignmentType,
2422
+ isValidWorldScalingType
1521
2423
  };
1522
2424
  //# sourceMappingURL=index.js.map