@webspatial/core-sdk 1.6.1 → 2.0.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 (320) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +10 -0
  3. package/dist/JSBCommand.d.ts +398 -0
  4. package/dist/JSBCommand.js +668 -0
  5. package/dist/JSBCommand.js.map +1 -0
  6. package/dist/Spatial.d.ts +63 -0
  7. package/dist/Spatial.js +60 -0
  8. package/dist/Spatial.js.map +1 -0
  9. package/dist/SpatialObject.d.ts +19 -0
  10. package/dist/SpatialObject.js +44 -0
  11. package/dist/SpatialObject.js.map +1 -0
  12. package/dist/SpatialScene.d.ts +51 -0
  13. package/dist/SpatialScene.js +74 -0
  14. package/dist/SpatialScene.js.map +1 -0
  15. package/dist/SpatialSession.d.ts +143 -0
  16. package/dist/SpatialSession.js +173 -0
  17. package/dist/SpatialSession.js.map +1 -0
  18. package/dist/SpatialWebEvent.d.ts +8 -0
  19. package/dist/SpatialWebEvent.js +18 -0
  20. package/dist/SpatialWebEvent.js.map +1 -0
  21. package/dist/SpatialWebEventCreator.d.ts +11 -0
  22. package/dist/SpatialWebEventCreator.js +11 -0
  23. package/dist/SpatialWebEventCreator.js.map +1 -0
  24. package/dist/Spatialized2DElement.d.ts +42 -0
  25. package/dist/Spatialized2DElement.js +47 -0
  26. package/dist/Spatialized2DElement.js.map +1 -0
  27. package/dist/SpatializedDynamic3DElement.d.ts +7 -0
  28. package/dist/SpatializedDynamic3DElement.js +43 -0
  29. package/dist/SpatializedDynamic3DElement.js.map +1 -0
  30. package/dist/SpatializedElement.d.ts +7 -0
  31. package/dist/SpatializedElement.js +206 -0
  32. package/dist/SpatializedElement.js.map +1 -0
  33. package/dist/SpatializedElementCreator.d.ts +15 -0
  34. package/dist/SpatializedElementCreator.js +47 -0
  35. package/dist/SpatializedElementCreator.js.map +1 -0
  36. package/dist/SpatializedStatic3DElement.d.ts +195 -0
  37. package/dist/SpatializedStatic3DElement.js +327 -0
  38. package/dist/SpatializedStatic3DElement.js.map +1 -0
  39. package/dist/WebMsgCommand.d.ts +7 -0
  40. package/dist/WebMsgCommand.js +23 -0
  41. package/dist/WebMsgCommand.js.map +1 -0
  42. package/dist/index.d.ts +35 -1101
  43. package/dist/index.js +21 -3393
  44. package/dist/index.js.map +1 -1
  45. package/dist/install-polyfills.d.ts +2 -0
  46. package/dist/install-polyfills.js +13 -0
  47. package/dist/install-polyfills.js.map +1 -0
  48. package/dist/isSSREnv.d.ts +3 -0
  49. package/dist/isSSREnv.js +6 -0
  50. package/dist/isSSREnv.js.map +1 -0
  51. package/dist/motion/AnimationObject.d.ts +7 -0
  52. package/dist/motion/AnimationObject.js +140 -0
  53. package/dist/motion/AnimationObject.js.map +1 -0
  54. package/dist/motion/compute/index.d.ts +10 -0
  55. package/dist/motion/compute/index.js +19 -0
  56. package/dist/motion/compute/index.js.map +1 -0
  57. package/dist/motion/compute/motionPropertyValues.d.ts +19 -0
  58. package/dist/motion/compute/motionPropertyValues.js +50 -0
  59. package/dist/motion/compute/motionPropertyValues.js.map +1 -0
  60. package/dist/motion/compute/normalize.d.ts +31 -0
  61. package/dist/motion/compute/normalize.js +201 -0
  62. package/dist/motion/compute/normalize.js.map +1 -0
  63. package/dist/motion/compute/validate.d.ts +22 -0
  64. package/dist/motion/compute/validate.js +103 -0
  65. package/dist/motion/compute/validate.js.map +1 -0
  66. package/dist/motion/index.d.ts +8 -0
  67. package/dist/motion/index.js +6 -0
  68. package/dist/motion/index.js.map +1 -0
  69. package/dist/motion/native/serializeMotionTimeline.d.ts +12 -0
  70. package/dist/motion/native/serializeMotionTimeline.js +21 -0
  71. package/dist/motion/native/serializeMotionTimeline.js.map +1 -0
  72. package/dist/physicalMetrics-W5uZ5xKb.d.ts +48 -0
  73. package/dist/physicalMetrics.d.ts +1 -0
  74. package/dist/physicalMetrics.js +58 -0
  75. package/dist/physicalMetrics.js.map +1 -0
  76. package/dist/platform-adapter/CommandResultUtils.d.ts +12 -0
  77. package/dist/platform-adapter/CommandResultUtils.js +21 -0
  78. package/dist/platform-adapter/CommandResultUtils.js.map +1 -0
  79. package/dist/platform-adapter/createPlatformSync.d.ts +16 -0
  80. package/dist/platform-adapter/createPlatformSync.js +30 -0
  81. package/dist/platform-adapter/createPlatformSync.js.map +1 -0
  82. package/dist/platform-adapter/index.d.ts +12 -0
  83. package/dist/platform-adapter/index.js +10 -0
  84. package/dist/platform-adapter/index.js.map +1 -0
  85. package/dist/platform-adapter/interface.d.ts +7 -0
  86. package/dist/platform-adapter/interface.js +1 -0
  87. package/dist/platform-adapter/interface.js.map +1 -0
  88. package/dist/platform-adapter/pico-os/PicoOSPlatform.d.ts +25 -0
  89. package/dist/platform-adapter/pico-os/PicoOSPlatform.js +168 -0
  90. package/dist/platform-adapter/pico-os/PicoOSPlatform.js.map +1 -0
  91. package/dist/platform-adapter/puppeteer/PuppeteerPlatform.d.ts +66 -0
  92. package/dist/platform-adapter/puppeteer/PuppeteerPlatform.js +372 -0
  93. package/dist/platform-adapter/puppeteer/PuppeteerPlatform.js.map +1 -0
  94. package/dist/platform-adapter/spatialRequestMetadata.d.ts +6 -0
  95. package/dist/platform-adapter/spatialRequestMetadata.js +39 -0
  96. package/dist/platform-adapter/spatialRequestMetadata.js.map +1 -0
  97. package/dist/platform-adapter/spatialSceneQuery.d.ts +12 -0
  98. package/dist/platform-adapter/spatialSceneQuery.js +12 -0
  99. package/dist/platform-adapter/spatialSceneQuery.js.map +1 -0
  100. package/dist/platform-adapter/vision-os/VisionOSPlatform.d.ts +19 -0
  101. package/dist/platform-adapter/vision-os/VisionOSPlatform.js +77 -0
  102. package/dist/platform-adapter/vision-os/VisionOSPlatform.js.map +1 -0
  103. package/dist/platform-runtime.d.ts +12 -0
  104. package/dist/platform-runtime.js +14 -0
  105. package/dist/platform-runtime.js.map +1 -0
  106. package/dist/reality/Attachment.d.ts +19 -0
  107. package/dist/reality/Attachment.js +39 -0
  108. package/dist/reality/Attachment.js.map +1 -0
  109. package/dist/reality/component/ModelComponent.d.ts +14 -0
  110. package/dist/reality/component/ModelComponent.js +11 -0
  111. package/dist/reality/component/ModelComponent.js.map +1 -0
  112. package/dist/reality/component/SpatialComponent.d.ts +8 -0
  113. package/dist/reality/component/SpatialComponent.js +19 -0
  114. package/dist/reality/component/SpatialComponent.js.map +1 -0
  115. package/dist/reality/component/index.d.ts +8 -0
  116. package/dist/reality/component/index.js +3 -0
  117. package/dist/reality/component/index.js.map +1 -0
  118. package/dist/reality/entity/SpatialEntity.d.ts +7 -0
  119. package/dist/reality/entity/SpatialEntity.js +291 -0
  120. package/dist/reality/entity/SpatialEntity.js.map +1 -0
  121. package/dist/reality/entity/SpatialModelEntity.d.ts +17 -0
  122. package/dist/reality/entity/SpatialModelEntity.js +17 -0
  123. package/dist/reality/entity/SpatialModelEntity.js.map +1 -0
  124. package/dist/reality/entity/index.d.ts +8 -0
  125. package/dist/reality/entity/index.js +3 -0
  126. package/dist/reality/entity/index.js.map +1 -0
  127. package/dist/reality/geometry/SpatialBoxGeometry.d.ts +16 -0
  128. package/dist/reality/geometry/SpatialBoxGeometry.js +13 -0
  129. package/dist/reality/geometry/SpatialBoxGeometry.js.map +1 -0
  130. package/dist/reality/geometry/SpatialConeGeometry.d.ts +16 -0
  131. package/dist/reality/geometry/SpatialConeGeometry.js +13 -0
  132. package/dist/reality/geometry/SpatialConeGeometry.js.map +1 -0
  133. package/dist/reality/geometry/SpatialCylinderGeometry.d.ts +16 -0
  134. package/dist/reality/geometry/SpatialCylinderGeometry.js +13 -0
  135. package/dist/reality/geometry/SpatialCylinderGeometry.js.map +1 -0
  136. package/dist/reality/geometry/SpatialGeometry.d.ts +7 -0
  137. package/dist/reality/geometry/SpatialGeometry.js +13 -0
  138. package/dist/reality/geometry/SpatialGeometry.js.map +1 -0
  139. package/dist/reality/geometry/SpatialPlaneGeometry.d.ts +16 -0
  140. package/dist/reality/geometry/SpatialPlaneGeometry.js +13 -0
  141. package/dist/reality/geometry/SpatialPlaneGeometry.js.map +1 -0
  142. package/dist/reality/geometry/SpatialSphereGeometry.d.ts +16 -0
  143. package/dist/reality/geometry/SpatialSphereGeometry.js +13 -0
  144. package/dist/reality/geometry/SpatialSphereGeometry.js.map +1 -0
  145. package/dist/reality/geometry/index.d.ts +12 -0
  146. package/dist/reality/geometry/index.js +7 -0
  147. package/dist/reality/geometry/index.js.map +1 -0
  148. package/dist/reality/index.d.ts +18 -0
  149. package/dist/reality/index.js +7 -0
  150. package/dist/reality/index.js.map +1 -0
  151. package/dist/reality/material/SpatialMaterial.d.ts +7 -0
  152. package/dist/reality/material/SpatialMaterial.js +13 -0
  153. package/dist/reality/material/SpatialMaterial.js.map +1 -0
  154. package/dist/reality/material/SpatialUnlitMaterial.d.ts +16 -0
  155. package/dist/reality/material/SpatialUnlitMaterial.js +16 -0
  156. package/dist/reality/material/SpatialUnlitMaterial.js.map +1 -0
  157. package/dist/reality/material/index.d.ts +8 -0
  158. package/dist/reality/material/index.js +3 -0
  159. package/dist/reality/material/index.js.map +1 -0
  160. package/dist/reality/realityCreator.d.ts +22 -0
  161. package/dist/reality/realityCreator.js +89 -0
  162. package/dist/reality/realityCreator.js.map +1 -0
  163. package/dist/reality/resource/SpatialModelAsset.d.ts +15 -0
  164. package/dist/reality/resource/SpatialModelAsset.js +12 -0
  165. package/dist/reality/resource/SpatialModelAsset.js.map +1 -0
  166. package/dist/reality/resource/SpatialTextureResource.d.ts +16 -0
  167. package/dist/reality/resource/SpatialTextureResource.js +16 -0
  168. package/dist/reality/resource/SpatialTextureResource.js.map +1 -0
  169. package/dist/reality/resource/index.d.ts +9 -0
  170. package/dist/reality/resource/index.js +3 -0
  171. package/dist/reality/resource/index.js.map +1 -0
  172. package/dist/runtime/WebSpatialRuntimeError.d.ts +10 -0
  173. package/dist/runtime/WebSpatialRuntimeError.js +14 -0
  174. package/dist/runtime/WebSpatialRuntimeError.js.map +1 -0
  175. package/dist/runtime/capability-data.d.ts +12 -0
  176. package/dist/runtime/capability-data.js +134 -0
  177. package/dist/runtime/capability-data.js.map +1 -0
  178. package/dist/runtime/index.d.ts +8 -0
  179. package/dist/runtime/index.js +27 -0
  180. package/dist/runtime/index.js.map +1 -0
  181. package/dist/runtime/jsbAdapterPlatform.d.ts +9 -0
  182. package/dist/runtime/jsbAdapterPlatform.js +38 -0
  183. package/dist/runtime/jsbAdapterPlatform.js.map +1 -0
  184. package/dist/runtime/keys.d.ts +34 -0
  185. package/dist/runtime/keys.js +122 -0
  186. package/dist/runtime/keys.js.map +1 -0
  187. package/dist/runtime/semver.d.ts +8 -0
  188. package/dist/runtime/semver.js +32 -0
  189. package/dist/runtime/semver.js.map +1 -0
  190. package/dist/runtime/supports.d.ts +22 -0
  191. package/dist/runtime/supports.js +78 -0
  192. package/dist/runtime/supports.js.map +1 -0
  193. package/dist/runtime/types.d.ts +12 -0
  194. package/dist/runtime/types.js +1 -0
  195. package/dist/runtime/types.js.map +1 -0
  196. package/dist/runtime/userAgent.d.ts +20 -0
  197. package/dist/runtime/userAgent.js +41 -0
  198. package/dist/runtime/userAgent.js.map +1 -0
  199. package/dist/scene-polyfill.d.ts +18 -0
  200. package/dist/scene-polyfill.js +480 -0
  201. package/dist/scene-polyfill.js.map +1 -0
  202. package/dist/spatial-host.d.ts +13 -0
  203. package/dist/spatial-host.js +18 -0
  204. package/dist/spatial-host.js.map +1 -0
  205. package/dist/spatial-window-polyfill.d.ts +3 -0
  206. package/dist/spatial-window-polyfill.js +155 -0
  207. package/dist/spatial-window-polyfill.js.map +1 -0
  208. package/dist/spatializedElementMotion-_0XWPQCE.d.ts +1009 -0
  209. package/dist/types/animation.d.ts +7 -0
  210. package/dist/types/animation.js +1 -0
  211. package/dist/types/animation.js.map +1 -0
  212. package/dist/types/global.d.ts +38 -0
  213. package/dist/types/global.js +1 -0
  214. package/dist/types/global.js.map +1 -0
  215. package/dist/types/internal.d.ts +7 -0
  216. package/dist/types/internal.js +12 -0
  217. package/dist/types/internal.js.map +1 -0
  218. package/dist/types/motion/index.d.ts +7 -0
  219. package/dist/types/motion/index.js +3 -0
  220. package/dist/types/motion/index.js.map +1 -0
  221. package/dist/types/motion/spatializedElementMotion.d.ts +7 -0
  222. package/dist/types/motion/spatializedElementMotion.js +1 -0
  223. package/dist/types/motion/spatializedElementMotion.js.map +1 -0
  224. package/dist/types/motion/spatializedMotion.d.ts +7 -0
  225. package/dist/types/motion/spatializedMotion.js +16 -0
  226. package/dist/types/motion/spatializedMotion.js.map +1 -0
  227. package/dist/types/motion/spatializedPlayback.d.ts +11 -0
  228. package/dist/types/motion/spatializedPlayback.js +1 -0
  229. package/dist/types/motion/spatializedPlayback.js.map +1 -0
  230. package/dist/types/motion/spatializedVisual.d.ts +35 -0
  231. package/dist/types/motion/spatializedVisual.js +1 -0
  232. package/dist/types/motion/spatializedVisual.js.map +1 -0
  233. package/dist/types/types.d.ts +7 -0
  234. package/dist/types/types.js +117 -0
  235. package/dist/types/types.js.map +1 -0
  236. package/dist/utils.d.ts +44 -0
  237. package/dist/utils.js +86 -0
  238. package/dist/utils.js.map +1 -0
  239. package/package.json +20 -4
  240. package/src/JSBCommand.ts +148 -91
  241. package/src/Spatial.ts +0 -21
  242. package/src/SpatialObject.ts +10 -0
  243. package/src/SpatialScene.ts +1 -5
  244. package/src/SpatialSession.ts +17 -3
  245. package/src/Spatialized2DElement.ts +5 -0
  246. package/src/SpatializedDynamic3DElement.ts +5 -1
  247. package/src/SpatializedElement.ts +29 -0
  248. package/src/SpatializedElementCreator.ts +6 -4
  249. package/src/SpatializedStatic3DElement.test.ts +99 -0
  250. package/src/SpatializedStatic3DElement.ts +141 -4
  251. package/src/WebMsgCommand.ts +50 -0
  252. package/src/coverage-boost.test.ts +258 -316
  253. package/src/index.ts +28 -12
  254. package/src/install-polyfills.ts +38 -0
  255. package/src/jsbcommand.coverage.test.ts +42 -48
  256. package/src/motion/AnimationObject.test.ts +421 -0
  257. package/src/motion/AnimationObject.ts +208 -0
  258. package/src/motion/compute/index.ts +10 -0
  259. package/src/motion/compute/motionPropertyValues.test.ts +55 -0
  260. package/src/motion/compute/motionPropertyValues.ts +70 -0
  261. package/src/motion/compute/normalize.test.ts +99 -0
  262. package/src/motion/compute/normalize.ts +289 -0
  263. package/src/motion/compute/validate.test.ts +229 -0
  264. package/src/motion/compute/validate.ts +156 -0
  265. package/src/motion/index.ts +2 -0
  266. package/src/motion/native/serializeMotionTimeline.test.ts +61 -0
  267. package/src/motion/native/serializeMotionTimeline.ts +27 -0
  268. package/src/platform-adapter/CommandResultUtils.ts +2 -2
  269. package/src/platform-adapter/createPlatformSync.ts +36 -0
  270. package/src/platform-adapter/index.ts +5 -51
  271. package/src/platform-adapter/interface.ts +35 -23
  272. package/src/platform-adapter/pico-os/PicoOSPlatform.ts +156 -59
  273. package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +37 -11
  274. package/src/platform-adapter/spatialRequestMetadata.test.ts +175 -0
  275. package/src/platform-adapter/spatialRequestMetadata.ts +48 -0
  276. package/src/platform-adapter/spatialSceneQuery.ts +17 -0
  277. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +60 -24
  278. package/src/platform-runtime.ts +13 -0
  279. package/src/reality/Attachment.ts +2 -2
  280. package/src/reality/entity/SpatialEntity.ts +127 -2
  281. package/src/reality/realityCreator.ts +15 -1
  282. package/src/reality/resource/SpatialTextureResource.ts +16 -0
  283. package/src/reality/resource/index.ts +1 -0
  284. package/src/runtime/WebSpatialRuntimeError.ts +16 -0
  285. package/src/runtime/capability-data.ts +213 -0
  286. package/src/runtime/contract-review.test.ts +44 -0
  287. package/src/runtime/index.ts +17 -0
  288. package/src/runtime/jsbAdapterPlatform.test.ts +36 -0
  289. package/src/runtime/jsbAdapterPlatform.ts +51 -0
  290. package/src/runtime/keys.ts +140 -0
  291. package/src/runtime/semver.ts +33 -0
  292. package/src/runtime/supports.test.ts +346 -0
  293. package/src/runtime/supports.ts +112 -0
  294. package/src/runtime/types.ts +11 -0
  295. package/src/runtime/useAnimation.capability.test.ts +275 -0
  296. package/src/runtime/userAgent.ts +64 -0
  297. package/src/scene-polyfill.manifest.test.ts +312 -9
  298. package/src/scene-polyfill.request-metadata.test.ts +39 -0
  299. package/src/scene-polyfill.test.ts +33 -94
  300. package/src/scene-polyfill.ts +125 -92
  301. package/src/spatial-host.ts +25 -0
  302. package/src/spatial-window-polyfill.ts +18 -2
  303. package/src/transform-roundtrip.test.ts +90 -0
  304. package/src/types/animation.ts +224 -0
  305. package/src/types/{global.d.ts → global.ts} +10 -12
  306. package/src/types/motion/index.ts +10 -0
  307. package/src/types/motion/spatializedElementMotion.ts +49 -0
  308. package/src/types/motion/spatializedMotion.ts +147 -0
  309. package/src/types/motion/spatializedPlayback.ts +17 -0
  310. package/src/types/motion/spatializedVisual.ts +24 -0
  311. package/src/types/types.ts +12 -0
  312. package/src/utils.ts +54 -0
  313. package/tsup.config.ts +61 -36
  314. package/vitest.config.ts +5 -1
  315. package/dist/iife/index.d.ts +0 -1101
  316. package/dist/iife/index.global.js +0 -75
  317. package/dist/iife/index.global.js.map +0 -1
  318. package/src/platform-adapter/android/AndroidPlatform.ts +0 -133
  319. package/src/platform-adapter/ssr/SSRPlatform.ts +0 -43
  320. /package/src/{ssr-polyfill.ts → isSSREnv.ts} +0 -0
@@ -80,15 +80,17 @@ describe('utils', () => {
80
80
  { x: 2, y: 3, z: 4 },
81
81
  )
82
82
 
83
+ // Use toMatchObject because happy-dom returns a real DOMPoint (which
84
+ // includes a `w` property) rather than a plain {x,y,z} object.
83
85
  const origin = m.transformPoint({ x: 0, y: 0, z: 0 })
84
- expect(origin).toEqual({
86
+ expect(origin).toMatchObject({
85
87
  x: 10,
86
88
  y: 20,
87
89
  z: 30,
88
90
  })
89
91
 
90
92
  const p = m.transformPoint({ x: 1, y: 1, z: 1 })
91
- expect(p).toEqual({ x: 12, y: 23, z: 34 })
93
+ expect(p).toMatchObject({ x: 12, y: 23, z: 34 })
92
94
  })
93
95
  })
94
96
 
@@ -171,20 +173,24 @@ describe('SpatialObject', () => {
171
173
  it('inspect returns data when command succeeds', async () => {
172
174
  vi.doMock('./JSBCommand', () => {
173
175
  return {
174
- InspectCommand: vi.fn().mockImplementation(() => ({
175
- execute: vi.fn().mockResolvedValue({
176
- success: true,
177
- data: { a: 1 },
178
- errorMessage: '',
179
- }),
180
- })),
181
- DestroyCommand: vi.fn().mockImplementation(() => ({
182
- execute: vi.fn().mockResolvedValue({
183
- success: true,
184
- data: undefined,
185
- errorMessage: '',
186
- }),
187
- })),
176
+ InspectCommand: vi.fn().mockImplementation(function () {
177
+ return {
178
+ execute: vi.fn().mockResolvedValue({
179
+ success: true,
180
+ data: { a: 1 },
181
+ errorMessage: '',
182
+ }),
183
+ }
184
+ }),
185
+ DestroyCommand: vi.fn().mockImplementation(function () {
186
+ return {
187
+ execute: vi.fn().mockResolvedValue({
188
+ success: true,
189
+ data: undefined,
190
+ errorMessage: '',
191
+ }),
192
+ }
193
+ }),
188
194
  }
189
195
  })
190
196
 
@@ -196,20 +202,24 @@ describe('SpatialObject', () => {
196
202
  it('inspect throws when command fails', async () => {
197
203
  vi.doMock('./JSBCommand', () => {
198
204
  return {
199
- InspectCommand: vi.fn().mockImplementation(() => ({
200
- execute: vi.fn().mockResolvedValue({
201
- success: false,
202
- data: undefined,
203
- errorMessage: 'nope',
204
- }),
205
- })),
206
- DestroyCommand: vi.fn().mockImplementation(() => ({
207
- execute: vi.fn().mockResolvedValue({
208
- success: true,
209
- data: undefined,
210
- errorMessage: '',
211
- }),
212
- })),
205
+ InspectCommand: vi.fn().mockImplementation(function () {
206
+ return {
207
+ execute: vi.fn().mockResolvedValue({
208
+ success: false,
209
+ data: undefined,
210
+ errorMessage: 'nope',
211
+ }),
212
+ }
213
+ }),
214
+ DestroyCommand: vi.fn().mockImplementation(function () {
215
+ return {
216
+ execute: vi.fn().mockResolvedValue({
217
+ success: true,
218
+ data: undefined,
219
+ errorMessage: '',
220
+ }),
221
+ }
222
+ }),
213
223
  }
214
224
  })
215
225
 
@@ -222,20 +232,24 @@ describe('SpatialObject', () => {
222
232
  const onDestroy = vi.fn()
223
233
  vi.doMock('./JSBCommand', () => {
224
234
  return {
225
- InspectCommand: vi.fn().mockImplementation(() => ({
226
- execute: vi.fn().mockResolvedValue({
227
- success: true,
228
- data: undefined,
229
- errorMessage: '',
230
- }),
231
- })),
232
- DestroyCommand: vi.fn().mockImplementation(() => ({
233
- execute: vi.fn().mockResolvedValue({
234
- success: true,
235
- data: { ok: true },
236
- errorMessage: '',
237
- }),
238
- })),
235
+ InspectCommand: vi.fn().mockImplementation(function () {
236
+ return {
237
+ execute: vi.fn().mockResolvedValue({
238
+ success: true,
239
+ data: undefined,
240
+ errorMessage: '',
241
+ }),
242
+ }
243
+ }),
244
+ DestroyCommand: vi.fn().mockImplementation(function () {
245
+ return {
246
+ execute: vi.fn().mockResolvedValue({
247
+ success: true,
248
+ data: { ok: true },
249
+ errorMessage: '',
250
+ }),
251
+ }
252
+ }),
239
253
  }
240
254
  })
241
255
 
@@ -253,6 +267,45 @@ describe('SpatialObject', () => {
253
267
  await expect(obj.destroy()).resolves.toBeUndefined()
254
268
  expect(onDestroy).toHaveBeenCalledTimes(1)
255
269
  })
270
+
271
+ it('treats missing native spatial objects as already destroyed', async () => {
272
+ const onDestroy = vi.fn()
273
+ vi.doMock('./JSBCommand', () => {
274
+ return {
275
+ InspectCommand: vi.fn().mockImplementation(function () {
276
+ return {
277
+ execute: vi.fn().mockResolvedValue({
278
+ success: true,
279
+ data: undefined,
280
+ errorMessage: '',
281
+ }),
282
+ }
283
+ }),
284
+ DestroyCommand: vi.fn().mockImplementation(function () {
285
+ return {
286
+ execute: vi.fn().mockResolvedValue({
287
+ success: false,
288
+ data: undefined,
289
+ errorMessage:
290
+ 'Failed to destroy SpatialObject: invalid inspect spatial object id obj-2 not exsit!',
291
+ }),
292
+ }
293
+ }),
294
+ }
295
+ })
296
+
297
+ const { SpatialObject } = await import('./SpatialObject')
298
+ class TestObject extends SpatialObject {
299
+ protected onDestroy() {
300
+ onDestroy()
301
+ }
302
+ }
303
+
304
+ const obj = new TestObject('obj-2')
305
+ await expect(obj.destroy()).resolves.toBeUndefined()
306
+ expect(obj.isDestroyed).toBe(true)
307
+ expect(onDestroy).toHaveBeenCalledTimes(1)
308
+ })
256
309
  })
257
310
 
258
311
  describe('platform adapters', () => {
@@ -263,132 +316,6 @@ describe('platform adapters', () => {
263
316
  vi.unmock('./JSBCommand')
264
317
  })
265
318
 
266
- // it('AndroidPlatform.callJSB resolves from async SpatialWebEvent callback', async () => {
267
- // const postMessage = vi.fn((rId: string) => {
268
- // expect(rId.startsWith('rId_')).toBe(true)
269
- // return ''
270
- // })
271
- // ;(window as any).webspatialBridge = { postMessage }
272
-
273
- // const { AndroidPlatform } = await import(
274
- // './platform-adapter/android/AndroidPlatform'
275
- // )
276
- // const { SpatialWebEvent: SpatialWebEventInstance } = await import(
277
- // './SpatialWebEvent'
278
- // )
279
- // const platform = new AndroidPlatform()
280
- // const p = platform.callJSB('c', '{"a":1}')
281
-
282
- // const rId = postMessage.mock.calls[0]?.[0] as string
283
- // SpatialWebEventInstance.eventReceiver[rId]({
284
- // success: true,
285
- // data: { ok: true },
286
- // })
287
-
288
- // await expect(p).resolves.toEqual({
289
- // success: true,
290
- // data: { ok: true },
291
- // errorCode: '',
292
- // errorMessage: '',
293
- // })
294
- // })
295
-
296
- // it('AndroidPlatform.callJSB handles sync bridge response and failures', async () => {
297
- // ;(window as any).webspatialBridge = {
298
- // postMessage: vi.fn(() =>
299
- // JSON.stringify({
300
- // success: false,
301
- // data: { code: 'E_SYNC', message: 'bad' },
302
- // }),
303
- // ),
304
- // }
305
-
306
- // const { AndroidPlatform } = await import(
307
- // './platform-adapter/android/AndroidPlatform'
308
- // )
309
- // const platform = new AndroidPlatform()
310
- // await expect(platform.callJSB('c', '{}')).resolves.toEqual({
311
- // success: false,
312
- // data: undefined,
313
- // errorCode: 'E_SYNC',
314
- // errorMessage: 'bad',
315
- // })
316
- // })
317
-
318
- // it('AndroidPlatform.callWebSpatialProtocol polls and returns injected SpatialId', async () => {
319
- // vi.useFakeTimers()
320
-
321
- // let canCount = 0
322
- // vi.doMock('./JSBCommand', () => {
323
- // return {
324
- // CheckWebViewCanCreateCommand: vi.fn().mockImplementation(() => ({
325
- // execute: vi.fn().mockImplementation(() => {
326
- // canCount += 1
327
- // return Promise.resolve({
328
- // success: true,
329
- // data: { can: canCount >= 2 },
330
- // errorCode: '',
331
- // errorMessage: '',
332
- // })
333
- // }),
334
- // })),
335
- // }
336
- // })
337
-
338
- // const windowProxy: any = {}
339
- // const openFn = vi.fn()
340
- // ;(window as any).open = vi.fn(() => windowProxy)
341
-
342
- // setTimeout(() => {
343
- // windowProxy.open = openFn
344
- // }, 20)
345
-
346
- // const { AndroidPlatform } = await import(
347
- // './platform-adapter/android/AndroidPlatform'
348
- // )
349
- // const { SpatialWebEvent: SpatialWebEventInstance } = await import(
350
- // './SpatialWebEvent'
351
- // )
352
- // const platform = new AndroidPlatform()
353
- // const p = platform.callWebSpatialProtocol('open', 'x=1', '_blank', '')
354
-
355
- // const receiverIds = Object.keys(SpatialWebEventInstance.eventReceiver)
356
- // const createdId = receiverIds[0] as string
357
- // const loadedId = receiverIds[1] as string
358
- // SpatialWebEventInstance.eventReceiver[createdId]?.({ spatialId: 'temp' })
359
- // await vi.advanceTimersByTimeAsync(100)
360
- // SpatialWebEventInstance.eventReceiver[loadedId]?.({
361
- // spatialId: 'spatial-1',
362
- // })
363
-
364
- // await vi.advanceTimersByTimeAsync(200)
365
-
366
- // const result = await p
367
- // expect(result.success).toBe(true)
368
- // expect(result.data.id).toBe('spatial-1')
369
- // expect(result.data.windowProxy).toBe(windowProxy)
370
- // const call = openFn.mock.calls[0] as unknown as [string, string | undefined]
371
- // expect(call?.[0]).toMatch(/^about:blank\?rid=/)
372
- // expect(call?.[1]).toBe('_self')
373
- // })
374
-
375
- it('SSRPlatform returns successful no-op results', async () => {
376
- const { SSRPlatform } = await import('./platform-adapter/ssr/SSRPlatform')
377
- const platform = new SSRPlatform()
378
-
379
- await expect(platform.callJSB('c', '{}')).resolves.toMatchObject({
380
- success: true,
381
- })
382
- await expect(
383
- platform.callWebSpatialProtocol('s', '', '', ''),
384
- ).resolves.toMatchObject({
385
- success: true,
386
- })
387
- expect(platform.callWebSpatialProtocolSync('s', '', '', '')).toMatchObject({
388
- success: true,
389
- })
390
- })
391
-
392
319
  it('VisionOSPlatform.callJSB returns success and parses failures', async () => {
393
320
  ;(window as any).webkit = {
394
321
  messageHandlers: {
@@ -437,11 +364,11 @@ describe('platform adapters', () => {
437
364
  './platform-adapter/vision-os/VisionOSPlatform'
438
365
  )
439
366
  const platform = new VisionOSPlatform()
440
- const r = await platform.callWebSpatialProtocol('open', 'a=1')
367
+ const r = await platform.createNativeSpatialDiv()
441
368
 
442
369
  expect(r.success).toBe(true)
443
- expect(r.data.id).toBe(uuid)
444
- expect(r.data.windowProxy).toBe(windowProxy)
370
+ expect(r.data?.id).toBe(uuid)
371
+ expect(r.data?.windowProxy).toBe(windowProxy)
445
372
  })
446
373
  })
447
374
 
@@ -570,6 +497,44 @@ describe('spatialWindowPolyfill', () => {
570
497
  expect(updateSpatialProperties).toHaveBeenCalledWith({
571
498
  material: 'none',
572
499
  })
500
+
501
+ await Promise.resolve()
502
+ await Promise.resolve()
503
+ updateSpatialProperties.mockClear()
504
+ ;(document.documentElement.style as any)['--xr-background-material'] =
505
+ 'translucent'
506
+ expect(updateSpatialProperties).toHaveBeenCalledWith({
507
+ material: 'translucent',
508
+ })
509
+ expect(
510
+ getComputedStyle(document.documentElement)
511
+ .getPropertyValue('--xr-background-material')
512
+ .trim(),
513
+ ).toBe('translucent')
514
+ expect(
515
+ (
516
+ (document.documentElement.style as any)[
517
+ '--xr-background-material'
518
+ ] as string
519
+ ).trim(),
520
+ ).toBe('translucent')
521
+
522
+ updateSpatialProperties.mockClear()
523
+ document.documentElement.style.setProperty('border-radius', '80px')
524
+ await Promise.resolve()
525
+ await Promise.resolve()
526
+
527
+ expect(updateSpatialProperties).toHaveBeenCalledWith({
528
+ cornerRadius: {
529
+ topLeading: 80,
530
+ topTrailing: 80,
531
+ bottomLeading: 80,
532
+ bottomTrailing: 80,
533
+ },
534
+ })
535
+ expect(updateSpatialProperties).not.toHaveBeenCalledWith({
536
+ material: 'none',
537
+ })
573
538
  })
574
539
  })
575
540
 
@@ -584,6 +549,14 @@ describe('SpatializedElementCreator', () => {
584
549
  const windowProxy: any = {
585
550
  document: { head: { innerHTML: '' } },
586
551
  }
552
+ vi.doMock('./spatial-host', () => ({
553
+ createNativeSpatialDiv: vi.fn().mockResolvedValue({
554
+ success: true,
555
+ data: { id: 'w1', windowProxy },
556
+ errorCode: '',
557
+ errorMessage: '',
558
+ }),
559
+ }))
587
560
 
588
561
  vi.doMock('./JSBCommand', () => {
589
562
  class OkCommand {
@@ -607,34 +580,42 @@ describe('SpatializedElementCreator', () => {
607
580
  UpdateSpatializedDynamic3DElementProperties: OkCommand,
608
581
  SetParentForEntityCommand: OkCommand,
609
582
  AddEntityToDynamic3DCommand: OkCommand,
610
- createSpatialized2DElementCommand: vi.fn().mockImplementation(() => ({
611
- execute: vi.fn().mockResolvedValue({
612
- success: true,
613
- data: { id: 'w1', windowProxy },
614
- errorCode: '',
615
- errorMessage: '',
583
+ createSpatialized2DElementCommand: vi
584
+ .fn()
585
+ .mockImplementation(function () {
586
+ return {
587
+ execute: vi.fn().mockResolvedValue({
588
+ success: true,
589
+ data: { id: 'w1', windowProxy },
590
+ errorCode: '',
591
+ errorMessage: '',
592
+ }),
593
+ }
616
594
  }),
617
- })),
618
595
  CreateSpatializedStatic3DElementCommand: vi
619
596
  .fn()
620
- .mockImplementation(() => ({
621
- execute: vi.fn().mockResolvedValue({
622
- success: true,
623
- data: { id: 's-default' },
624
- errorCode: '',
625
- errorMessage: '',
626
- }),
627
- })),
597
+ .mockImplementation(function () {
598
+ return {
599
+ execute: vi.fn().mockResolvedValue({
600
+ success: true,
601
+ data: { id: 's-default' },
602
+ errorCode: '',
603
+ errorMessage: '',
604
+ }),
605
+ }
606
+ }),
628
607
  CreateSpatializedDynamic3DElementCommand: vi
629
608
  .fn()
630
- .mockImplementation(() => ({
631
- execute: vi.fn().mockResolvedValue({
632
- success: true,
633
- data: { id: 'd-default' },
634
- errorCode: '',
635
- errorMessage: '',
636
- }),
637
- })),
609
+ .mockImplementation(function () {
610
+ return {
611
+ execute: vi.fn().mockResolvedValue({
612
+ success: true,
613
+ data: { id: 'd-default' },
614
+ errorCode: '',
615
+ errorMessage: '',
616
+ }),
617
+ }
618
+ }),
638
619
  }
639
620
  })
640
621
 
@@ -649,6 +630,15 @@ describe('SpatializedElementCreator', () => {
649
630
  })
650
631
 
651
632
  it('createSpatialized2DElement throws when command fails', async () => {
633
+ vi.doMock('./spatial-host', () => ({
634
+ createNativeSpatialDiv: vi.fn().mockResolvedValue({
635
+ success: false,
636
+ data: undefined,
637
+ errorCode: 'E',
638
+ errorMessage: 'bad',
639
+ }),
640
+ }))
641
+
652
642
  vi.doMock('./JSBCommand', () => {
653
643
  class OkCommand {
654
644
  execute() {
@@ -671,14 +661,18 @@ describe('SpatializedElementCreator', () => {
671
661
  UpdateSpatializedDynamic3DElementProperties: OkCommand,
672
662
  SetParentForEntityCommand: OkCommand,
673
663
  AddEntityToDynamic3DCommand: OkCommand,
674
- createSpatialized2DElementCommand: vi.fn().mockImplementation(() => ({
675
- execute: vi.fn().mockResolvedValue({
676
- success: false,
677
- data: undefined,
678
- errorCode: 'E',
679
- errorMessage: 'bad',
664
+ createSpatialized2DElementCommand: vi
665
+ .fn()
666
+ .mockImplementation(function () {
667
+ return {
668
+ execute: vi.fn().mockResolvedValue({
669
+ success: false,
670
+ data: undefined,
671
+ errorCode: 'E',
672
+ errorMessage: 'bad',
673
+ }),
674
+ }
680
675
  }),
681
- })),
682
676
  CreateSpatializedStatic3DElementCommand: vi.fn(),
683
677
  CreateSpatializedDynamic3DElementCommand: vi.fn(),
684
678
  }
@@ -719,22 +713,26 @@ describe('SpatializedElementCreator', () => {
719
713
  CreateSpatializedDynamic3DElementCommand: vi.fn(),
720
714
  CreateSpatializedStatic3DElementCommand: vi
721
715
  .fn()
722
- .mockImplementationOnce(() => ({
723
- execute: vi.fn().mockResolvedValue({
724
- success: true,
725
- data: { id: 's3' },
726
- errorCode: '',
727
- errorMessage: '',
728
- }),
729
- }))
730
- .mockImplementationOnce(() => ({
731
- execute: vi.fn().mockResolvedValue({
732
- success: false,
733
- data: undefined,
734
- errorCode: 'E',
735
- errorMessage: 'bad',
736
- }),
737
- })),
716
+ .mockImplementationOnce(function () {
717
+ return {
718
+ execute: vi.fn().mockResolvedValue({
719
+ success: true,
720
+ data: { id: 's3' },
721
+ errorCode: '',
722
+ errorMessage: '',
723
+ }),
724
+ }
725
+ })
726
+ .mockImplementationOnce(function () {
727
+ return {
728
+ execute: vi.fn().mockResolvedValue({
729
+ success: false,
730
+ data: undefined,
731
+ errorCode: 'E',
732
+ errorMessage: 'bad',
733
+ }),
734
+ }
735
+ }),
738
736
  }
739
737
  })
740
738
 
@@ -776,22 +774,26 @@ describe('SpatializedElementCreator', () => {
776
774
  CreateSpatializedStatic3DElementCommand: vi.fn(),
777
775
  CreateSpatializedDynamic3DElementCommand: vi
778
776
  .fn()
779
- .mockImplementationOnce(() => ({
780
- execute: vi.fn().mockResolvedValue({
781
- success: true,
782
- data: { id: 'd3' },
783
- errorCode: '',
784
- errorMessage: '',
785
- }),
786
- }))
787
- .mockImplementationOnce(() => ({
788
- execute: vi.fn().mockResolvedValue({
789
- success: false,
790
- data: undefined,
791
- errorCode: 'E',
792
- errorMessage: 'bad',
793
- }),
794
- })),
777
+ .mockImplementationOnce(function () {
778
+ return {
779
+ execute: vi.fn().mockResolvedValue({
780
+ success: true,
781
+ data: { id: 'd3' },
782
+ errorCode: '',
783
+ errorMessage: '',
784
+ }),
785
+ }
786
+ })
787
+ .mockImplementationOnce(function () {
788
+ return {
789
+ execute: vi.fn().mockResolvedValue({
790
+ success: false,
791
+ data: undefined,
792
+ errorCode: 'E',
793
+ errorMessage: 'bad',
794
+ }),
795
+ }
796
+ }),
795
797
  }
796
798
  })
797
799
 
@@ -814,72 +816,7 @@ describe('SpatializedStatic3DElement', () => {
814
816
  vi.unmock('./JSBCommand')
815
817
  })
816
818
 
817
- it('resets ready when modelURL changes and resolves on load events', async () => {
818
- const execute = vi.fn().mockResolvedValue({
819
- success: true,
820
- data: undefined,
821
- errorCode: '',
822
- errorMessage: '',
823
- })
824
- vi.doMock('./JSBCommand', () => {
825
- class OkCommand {
826
- execute() {
827
- return Promise.resolve({
828
- success: true,
829
- data: undefined,
830
- errorCode: '',
831
- errorMessage: '',
832
- })
833
- }
834
- }
835
-
836
- return {
837
- InspectCommand: OkCommand,
838
- DestroyCommand: OkCommand,
839
- UpdateSpatializedElementTransform: OkCommand,
840
- UpdateSpatialized2DElementProperties: OkCommand,
841
- AddSpatializedElementToSpatialized2DElement: OkCommand,
842
- UpdateSpatializedDynamic3DElementProperties: OkCommand,
843
- SetParentForEntityCommand: OkCommand,
844
- AddEntityToDynamic3DCommand: OkCommand,
845
- createSpatialized2DElementCommand: vi.fn(),
846
- CreateSpatializedStatic3DElementCommand: vi.fn(),
847
- CreateSpatializedDynamic3DElementCommand: vi.fn(),
848
- UpdateSpatializedStatic3DElementProperties: vi
849
- .fn()
850
- .mockImplementation(() => ({ execute })),
851
- }
852
- })
853
-
854
- const { SpatializedStatic3DElement } = await import(
855
- './SpatializedStatic3DElement'
856
- )
857
- const { SpatialWebMsgType } = await import('./WebMsgCommand')
858
-
859
- const el = new SpatializedStatic3DElement('m1')
860
- const onLoad = vi.fn()
861
- const onFail = vi.fn()
862
- el.onLoadCallback = onLoad
863
- el.onLoadFailureCallback = onFail
864
-
865
- const p1 = el.ready
866
- await el.updateProperties({ modelURL: 'a.glb' } as any)
867
- expect(execute).toHaveBeenCalledTimes(1)
868
- const p2 = el.ready
869
- expect(p2).not.toBe(p1)
870
-
871
- el.onReceiveEvent({ type: SpatialWebMsgType.modelloaded } as any)
872
- await expect(p2).resolves.toBe(true)
873
- expect(onLoad).toHaveBeenCalledTimes(1)
874
-
875
- await el.updateProperties({ modelURL: 'b.glb' } as any)
876
- const p3 = el.ready
877
- el.onReceiveEvent({ type: SpatialWebMsgType.modelloadfailed } as any)
878
- await expect(p3).resolves.toBe(false)
879
- expect(onFail).toHaveBeenCalledTimes(1)
880
- })
881
-
882
- it('updateModelTransform passes float64 array to updateProperties', async () => {
819
+ it('entityTransform setter passes float64 array to updateProperties', async () => {
883
820
  const execute = vi.fn().mockResolvedValue({
884
821
  success: true,
885
822
  data: undefined,
@@ -912,7 +849,9 @@ describe('SpatializedStatic3DElement', () => {
912
849
  CreateSpatializedDynamic3DElementCommand: vi.fn(),
913
850
  UpdateSpatializedStatic3DElementProperties: vi
914
851
  .fn()
915
- .mockImplementation(() => ({ execute })),
852
+ .mockImplementation(function () {
853
+ return { execute }
854
+ }),
916
855
  }
917
856
  })
918
857
 
@@ -929,7 +868,7 @@ describe('SpatializedStatic3DElement', () => {
929
868
  }
930
869
 
931
870
  const el = new SpatializedStatic3DElement('m2')
932
- el.updateModelTransform(new DOMMatrixWithArray() as any)
871
+ el.entityTransform = new DOMMatrixWithArray() as any
933
872
  expect(execute).toHaveBeenCalledTimes(1)
934
873
  })
935
874
  })
@@ -972,9 +911,9 @@ describe('SpatializedDynamic3DElement', () => {
972
911
  CreateSpatializedStatic3DElementCommand: vi.fn(),
973
912
  CreateSpatializedDynamic3DElementCommand: vi.fn(),
974
913
  AddEntityToDynamic3DCommand: OkCommand,
975
- SetParentForEntityCommand: vi
976
- .fn()
977
- .mockImplementation(() => ({ execute })),
914
+ SetParentForEntityCommand: vi.fn().mockImplementation(function () {
915
+ return { execute }
916
+ }),
978
917
  }
979
918
  })
980
919
 
@@ -1024,7 +963,9 @@ describe('SpatializedDynamic3DElement', () => {
1024
963
  CreateSpatializedDynamic3DElementCommand: vi.fn(),
1025
964
  UpdateSpatializedDynamic3DElementProperties: vi
1026
965
  .fn()
1027
- .mockImplementation(() => ({ execute })),
966
+ .mockImplementation(function () {
967
+ return { execute }
968
+ }),
1028
969
  }
1029
970
  })
1030
971
 
@@ -1037,24 +978,25 @@ describe('SpatializedDynamic3DElement', () => {
1037
978
  })
1038
979
  })
1039
980
 
1040
- describe('ssr-polyfill', () => {
981
+ describe('isSSREnv', () => {
1041
982
  it('isSSREnv returns false in jsdom', async () => {
1042
- const { isSSREnv } = await import('./ssr-polyfill')
983
+ const { isSSREnv } = await import('./isSSREnv')
1043
984
  expect(isSSREnv()).toBe(false)
1044
985
  })
1045
986
  })
1046
987
 
1047
988
  describe('platform-adapter', () => {
1048
- it('createPlatform returns SSRPlatform in SSR env', async () => {
989
+ it('createPlatform and createPlatformSync throw in SSR env', async () => {
1049
990
  vi.resetModules()
1050
- vi.doMock('./ssr-polyfill', () => {
991
+ vi.doMock('./isSSREnv', () => {
1051
992
  return { isSSREnv: () => true }
1052
993
  })
1053
994
 
1054
- const { createPlatform } = await import('./platform-adapter')
1055
- const p = createPlatform() as any
1056
- expect(typeof p.callJSB).toBe('function')
1057
- expect(typeof p.callWebSpatialProtocol).toBe('function')
1058
- expect(typeof p.callWebSpatialProtocolSync).toBe('function')
995
+ const { createPlatform, createPlatformSync } = await import(
996
+ './platform-adapter'
997
+ )
998
+ const expected = /cannot run during SSR/
999
+ await expect(createPlatform()).rejects.toThrow(expected)
1000
+ expect(() => createPlatformSync()).toThrow(expected)
1059
1001
  })
1060
1002
  })