@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.
- package/CHANGELOG.md +84 -0
- package/README.md +10 -0
- package/dist/JSBCommand.d.ts +398 -0
- package/dist/JSBCommand.js +668 -0
- package/dist/JSBCommand.js.map +1 -0
- package/dist/Spatial.d.ts +63 -0
- package/dist/Spatial.js +60 -0
- package/dist/Spatial.js.map +1 -0
- package/dist/SpatialObject.d.ts +19 -0
- package/dist/SpatialObject.js +44 -0
- package/dist/SpatialObject.js.map +1 -0
- package/dist/SpatialScene.d.ts +51 -0
- package/dist/SpatialScene.js +74 -0
- package/dist/SpatialScene.js.map +1 -0
- package/dist/SpatialSession.d.ts +143 -0
- package/dist/SpatialSession.js +173 -0
- package/dist/SpatialSession.js.map +1 -0
- package/dist/SpatialWebEvent.d.ts +8 -0
- package/dist/SpatialWebEvent.js +18 -0
- package/dist/SpatialWebEvent.js.map +1 -0
- package/dist/SpatialWebEventCreator.d.ts +11 -0
- package/dist/SpatialWebEventCreator.js +11 -0
- package/dist/SpatialWebEventCreator.js.map +1 -0
- package/dist/Spatialized2DElement.d.ts +42 -0
- package/dist/Spatialized2DElement.js +47 -0
- package/dist/Spatialized2DElement.js.map +1 -0
- package/dist/SpatializedDynamic3DElement.d.ts +7 -0
- package/dist/SpatializedDynamic3DElement.js +43 -0
- package/dist/SpatializedDynamic3DElement.js.map +1 -0
- package/dist/SpatializedElement.d.ts +7 -0
- package/dist/SpatializedElement.js +206 -0
- package/dist/SpatializedElement.js.map +1 -0
- package/dist/SpatializedElementCreator.d.ts +15 -0
- package/dist/SpatializedElementCreator.js +47 -0
- package/dist/SpatializedElementCreator.js.map +1 -0
- package/dist/SpatializedStatic3DElement.d.ts +195 -0
- package/dist/SpatializedStatic3DElement.js +327 -0
- package/dist/SpatializedStatic3DElement.js.map +1 -0
- package/dist/WebMsgCommand.d.ts +7 -0
- package/dist/WebMsgCommand.js +23 -0
- package/dist/WebMsgCommand.js.map +1 -0
- package/dist/index.d.ts +35 -1101
- package/dist/index.js +21 -3393
- package/dist/index.js.map +1 -1
- package/dist/install-polyfills.d.ts +2 -0
- package/dist/install-polyfills.js +13 -0
- package/dist/install-polyfills.js.map +1 -0
- package/dist/isSSREnv.d.ts +3 -0
- package/dist/isSSREnv.js +6 -0
- package/dist/isSSREnv.js.map +1 -0
- package/dist/motion/AnimationObject.d.ts +7 -0
- package/dist/motion/AnimationObject.js +140 -0
- package/dist/motion/AnimationObject.js.map +1 -0
- package/dist/motion/compute/index.d.ts +10 -0
- package/dist/motion/compute/index.js +19 -0
- package/dist/motion/compute/index.js.map +1 -0
- package/dist/motion/compute/motionPropertyValues.d.ts +19 -0
- package/dist/motion/compute/motionPropertyValues.js +50 -0
- package/dist/motion/compute/motionPropertyValues.js.map +1 -0
- package/dist/motion/compute/normalize.d.ts +31 -0
- package/dist/motion/compute/normalize.js +201 -0
- package/dist/motion/compute/normalize.js.map +1 -0
- package/dist/motion/compute/validate.d.ts +22 -0
- package/dist/motion/compute/validate.js +103 -0
- package/dist/motion/compute/validate.js.map +1 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +6 -0
- package/dist/motion/index.js.map +1 -0
- package/dist/motion/native/serializeMotionTimeline.d.ts +12 -0
- package/dist/motion/native/serializeMotionTimeline.js +21 -0
- package/dist/motion/native/serializeMotionTimeline.js.map +1 -0
- package/dist/physicalMetrics-W5uZ5xKb.d.ts +48 -0
- package/dist/physicalMetrics.d.ts +1 -0
- package/dist/physicalMetrics.js +58 -0
- package/dist/physicalMetrics.js.map +1 -0
- package/dist/platform-adapter/CommandResultUtils.d.ts +12 -0
- package/dist/platform-adapter/CommandResultUtils.js +21 -0
- package/dist/platform-adapter/CommandResultUtils.js.map +1 -0
- package/dist/platform-adapter/createPlatformSync.d.ts +16 -0
- package/dist/platform-adapter/createPlatformSync.js +30 -0
- package/dist/platform-adapter/createPlatformSync.js.map +1 -0
- package/dist/platform-adapter/index.d.ts +12 -0
- package/dist/platform-adapter/index.js +10 -0
- package/dist/platform-adapter/index.js.map +1 -0
- package/dist/platform-adapter/interface.d.ts +7 -0
- package/dist/platform-adapter/interface.js +1 -0
- package/dist/platform-adapter/interface.js.map +1 -0
- package/dist/platform-adapter/pico-os/PicoOSPlatform.d.ts +25 -0
- package/dist/platform-adapter/pico-os/PicoOSPlatform.js +168 -0
- package/dist/platform-adapter/pico-os/PicoOSPlatform.js.map +1 -0
- package/dist/platform-adapter/puppeteer/PuppeteerPlatform.d.ts +66 -0
- package/dist/platform-adapter/puppeteer/PuppeteerPlatform.js +372 -0
- package/dist/platform-adapter/puppeteer/PuppeteerPlatform.js.map +1 -0
- package/dist/platform-adapter/spatialRequestMetadata.d.ts +6 -0
- package/dist/platform-adapter/spatialRequestMetadata.js +39 -0
- package/dist/platform-adapter/spatialRequestMetadata.js.map +1 -0
- package/dist/platform-adapter/spatialSceneQuery.d.ts +12 -0
- package/dist/platform-adapter/spatialSceneQuery.js +12 -0
- package/dist/platform-adapter/spatialSceneQuery.js.map +1 -0
- package/dist/platform-adapter/vision-os/VisionOSPlatform.d.ts +19 -0
- package/dist/platform-adapter/vision-os/VisionOSPlatform.js +77 -0
- package/dist/platform-adapter/vision-os/VisionOSPlatform.js.map +1 -0
- package/dist/platform-runtime.d.ts +12 -0
- package/dist/platform-runtime.js +14 -0
- package/dist/platform-runtime.js.map +1 -0
- package/dist/reality/Attachment.d.ts +19 -0
- package/dist/reality/Attachment.js +39 -0
- package/dist/reality/Attachment.js.map +1 -0
- package/dist/reality/component/ModelComponent.d.ts +14 -0
- package/dist/reality/component/ModelComponent.js +11 -0
- package/dist/reality/component/ModelComponent.js.map +1 -0
- package/dist/reality/component/SpatialComponent.d.ts +8 -0
- package/dist/reality/component/SpatialComponent.js +19 -0
- package/dist/reality/component/SpatialComponent.js.map +1 -0
- package/dist/reality/component/index.d.ts +8 -0
- package/dist/reality/component/index.js +3 -0
- package/dist/reality/component/index.js.map +1 -0
- package/dist/reality/entity/SpatialEntity.d.ts +7 -0
- package/dist/reality/entity/SpatialEntity.js +291 -0
- package/dist/reality/entity/SpatialEntity.js.map +1 -0
- package/dist/reality/entity/SpatialModelEntity.d.ts +17 -0
- package/dist/reality/entity/SpatialModelEntity.js +17 -0
- package/dist/reality/entity/SpatialModelEntity.js.map +1 -0
- package/dist/reality/entity/index.d.ts +8 -0
- package/dist/reality/entity/index.js +3 -0
- package/dist/reality/entity/index.js.map +1 -0
- package/dist/reality/geometry/SpatialBoxGeometry.d.ts +16 -0
- package/dist/reality/geometry/SpatialBoxGeometry.js +13 -0
- package/dist/reality/geometry/SpatialBoxGeometry.js.map +1 -0
- package/dist/reality/geometry/SpatialConeGeometry.d.ts +16 -0
- package/dist/reality/geometry/SpatialConeGeometry.js +13 -0
- package/dist/reality/geometry/SpatialConeGeometry.js.map +1 -0
- package/dist/reality/geometry/SpatialCylinderGeometry.d.ts +16 -0
- package/dist/reality/geometry/SpatialCylinderGeometry.js +13 -0
- package/dist/reality/geometry/SpatialCylinderGeometry.js.map +1 -0
- package/dist/reality/geometry/SpatialGeometry.d.ts +7 -0
- package/dist/reality/geometry/SpatialGeometry.js +13 -0
- package/dist/reality/geometry/SpatialGeometry.js.map +1 -0
- package/dist/reality/geometry/SpatialPlaneGeometry.d.ts +16 -0
- package/dist/reality/geometry/SpatialPlaneGeometry.js +13 -0
- package/dist/reality/geometry/SpatialPlaneGeometry.js.map +1 -0
- package/dist/reality/geometry/SpatialSphereGeometry.d.ts +16 -0
- package/dist/reality/geometry/SpatialSphereGeometry.js +13 -0
- package/dist/reality/geometry/SpatialSphereGeometry.js.map +1 -0
- package/dist/reality/geometry/index.d.ts +12 -0
- package/dist/reality/geometry/index.js +7 -0
- package/dist/reality/geometry/index.js.map +1 -0
- package/dist/reality/index.d.ts +18 -0
- package/dist/reality/index.js +7 -0
- package/dist/reality/index.js.map +1 -0
- package/dist/reality/material/SpatialMaterial.d.ts +7 -0
- package/dist/reality/material/SpatialMaterial.js +13 -0
- package/dist/reality/material/SpatialMaterial.js.map +1 -0
- package/dist/reality/material/SpatialUnlitMaterial.d.ts +16 -0
- package/dist/reality/material/SpatialUnlitMaterial.js +16 -0
- package/dist/reality/material/SpatialUnlitMaterial.js.map +1 -0
- package/dist/reality/material/index.d.ts +8 -0
- package/dist/reality/material/index.js +3 -0
- package/dist/reality/material/index.js.map +1 -0
- package/dist/reality/realityCreator.d.ts +22 -0
- package/dist/reality/realityCreator.js +89 -0
- package/dist/reality/realityCreator.js.map +1 -0
- package/dist/reality/resource/SpatialModelAsset.d.ts +15 -0
- package/dist/reality/resource/SpatialModelAsset.js +12 -0
- package/dist/reality/resource/SpatialModelAsset.js.map +1 -0
- package/dist/reality/resource/SpatialTextureResource.d.ts +16 -0
- package/dist/reality/resource/SpatialTextureResource.js +16 -0
- package/dist/reality/resource/SpatialTextureResource.js.map +1 -0
- package/dist/reality/resource/index.d.ts +9 -0
- package/dist/reality/resource/index.js +3 -0
- package/dist/reality/resource/index.js.map +1 -0
- package/dist/runtime/WebSpatialRuntimeError.d.ts +10 -0
- package/dist/runtime/WebSpatialRuntimeError.js +14 -0
- package/dist/runtime/WebSpatialRuntimeError.js.map +1 -0
- package/dist/runtime/capability-data.d.ts +12 -0
- package/dist/runtime/capability-data.js +134 -0
- package/dist/runtime/capability-data.js.map +1 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/jsbAdapterPlatform.d.ts +9 -0
- package/dist/runtime/jsbAdapterPlatform.js +38 -0
- package/dist/runtime/jsbAdapterPlatform.js.map +1 -0
- package/dist/runtime/keys.d.ts +34 -0
- package/dist/runtime/keys.js +122 -0
- package/dist/runtime/keys.js.map +1 -0
- package/dist/runtime/semver.d.ts +8 -0
- package/dist/runtime/semver.js +32 -0
- package/dist/runtime/semver.js.map +1 -0
- package/dist/runtime/supports.d.ts +22 -0
- package/dist/runtime/supports.js +78 -0
- package/dist/runtime/supports.js.map +1 -0
- package/dist/runtime/types.d.ts +12 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/userAgent.d.ts +20 -0
- package/dist/runtime/userAgent.js +41 -0
- package/dist/runtime/userAgent.js.map +1 -0
- package/dist/scene-polyfill.d.ts +18 -0
- package/dist/scene-polyfill.js +480 -0
- package/dist/scene-polyfill.js.map +1 -0
- package/dist/spatial-host.d.ts +13 -0
- package/dist/spatial-host.js +18 -0
- package/dist/spatial-host.js.map +1 -0
- package/dist/spatial-window-polyfill.d.ts +3 -0
- package/dist/spatial-window-polyfill.js +155 -0
- package/dist/spatial-window-polyfill.js.map +1 -0
- package/dist/spatializedElementMotion-_0XWPQCE.d.ts +1009 -0
- package/dist/types/animation.d.ts +7 -0
- package/dist/types/animation.js +1 -0
- package/dist/types/animation.js.map +1 -0
- package/dist/types/global.d.ts +38 -0
- package/dist/types/global.js +1 -0
- package/dist/types/global.js.map +1 -0
- package/dist/types/internal.d.ts +7 -0
- package/dist/types/internal.js +12 -0
- package/dist/types/internal.js.map +1 -0
- package/dist/types/motion/index.d.ts +7 -0
- package/dist/types/motion/index.js +3 -0
- package/dist/types/motion/index.js.map +1 -0
- package/dist/types/motion/spatializedElementMotion.d.ts +7 -0
- package/dist/types/motion/spatializedElementMotion.js +1 -0
- package/dist/types/motion/spatializedElementMotion.js.map +1 -0
- package/dist/types/motion/spatializedMotion.d.ts +7 -0
- package/dist/types/motion/spatializedMotion.js +16 -0
- package/dist/types/motion/spatializedMotion.js.map +1 -0
- package/dist/types/motion/spatializedPlayback.d.ts +11 -0
- package/dist/types/motion/spatializedPlayback.js +1 -0
- package/dist/types/motion/spatializedPlayback.js.map +1 -0
- package/dist/types/motion/spatializedVisual.d.ts +35 -0
- package/dist/types/motion/spatializedVisual.js +1 -0
- package/dist/types/motion/spatializedVisual.js.map +1 -0
- package/dist/types/types.d.ts +7 -0
- package/dist/types/types.js +117 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils.d.ts +44 -0
- package/dist/utils.js +86 -0
- package/dist/utils.js.map +1 -0
- package/package.json +20 -4
- package/src/JSBCommand.ts +148 -91
- package/src/Spatial.ts +0 -21
- package/src/SpatialObject.ts +10 -0
- package/src/SpatialScene.ts +1 -5
- package/src/SpatialSession.ts +17 -3
- package/src/Spatialized2DElement.ts +5 -0
- package/src/SpatializedDynamic3DElement.ts +5 -1
- package/src/SpatializedElement.ts +29 -0
- package/src/SpatializedElementCreator.ts +6 -4
- package/src/SpatializedStatic3DElement.test.ts +99 -0
- package/src/SpatializedStatic3DElement.ts +141 -4
- package/src/WebMsgCommand.ts +50 -0
- package/src/coverage-boost.test.ts +258 -316
- package/src/index.ts +28 -12
- package/src/install-polyfills.ts +38 -0
- package/src/jsbcommand.coverage.test.ts +42 -48
- package/src/motion/AnimationObject.test.ts +421 -0
- package/src/motion/AnimationObject.ts +208 -0
- package/src/motion/compute/index.ts +10 -0
- package/src/motion/compute/motionPropertyValues.test.ts +55 -0
- package/src/motion/compute/motionPropertyValues.ts +70 -0
- package/src/motion/compute/normalize.test.ts +99 -0
- package/src/motion/compute/normalize.ts +289 -0
- package/src/motion/compute/validate.test.ts +229 -0
- package/src/motion/compute/validate.ts +156 -0
- package/src/motion/index.ts +2 -0
- package/src/motion/native/serializeMotionTimeline.test.ts +61 -0
- package/src/motion/native/serializeMotionTimeline.ts +27 -0
- package/src/platform-adapter/CommandResultUtils.ts +2 -2
- package/src/platform-adapter/createPlatformSync.ts +36 -0
- package/src/platform-adapter/index.ts +5 -51
- package/src/platform-adapter/interface.ts +35 -23
- package/src/platform-adapter/pico-os/PicoOSPlatform.ts +156 -59
- package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +37 -11
- package/src/platform-adapter/spatialRequestMetadata.test.ts +175 -0
- package/src/platform-adapter/spatialRequestMetadata.ts +48 -0
- package/src/platform-adapter/spatialSceneQuery.ts +17 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +60 -24
- package/src/platform-runtime.ts +13 -0
- package/src/reality/Attachment.ts +2 -2
- package/src/reality/entity/SpatialEntity.ts +127 -2
- package/src/reality/realityCreator.ts +15 -1
- package/src/reality/resource/SpatialTextureResource.ts +16 -0
- package/src/reality/resource/index.ts +1 -0
- package/src/runtime/WebSpatialRuntimeError.ts +16 -0
- package/src/runtime/capability-data.ts +213 -0
- package/src/runtime/contract-review.test.ts +44 -0
- package/src/runtime/index.ts +17 -0
- package/src/runtime/jsbAdapterPlatform.test.ts +36 -0
- package/src/runtime/jsbAdapterPlatform.ts +51 -0
- package/src/runtime/keys.ts +140 -0
- package/src/runtime/semver.ts +33 -0
- package/src/runtime/supports.test.ts +346 -0
- package/src/runtime/supports.ts +112 -0
- package/src/runtime/types.ts +11 -0
- package/src/runtime/useAnimation.capability.test.ts +275 -0
- package/src/runtime/userAgent.ts +64 -0
- package/src/scene-polyfill.manifest.test.ts +312 -9
- package/src/scene-polyfill.request-metadata.test.ts +39 -0
- package/src/scene-polyfill.test.ts +33 -94
- package/src/scene-polyfill.ts +125 -92
- package/src/spatial-host.ts +25 -0
- package/src/spatial-window-polyfill.ts +18 -2
- package/src/transform-roundtrip.test.ts +90 -0
- package/src/types/animation.ts +224 -0
- package/src/types/{global.d.ts → global.ts} +10 -12
- package/src/types/motion/index.ts +10 -0
- package/src/types/motion/spatializedElementMotion.ts +49 -0
- package/src/types/motion/spatializedMotion.ts +147 -0
- package/src/types/motion/spatializedPlayback.ts +17 -0
- package/src/types/motion/spatializedVisual.ts +24 -0
- package/src/types/types.ts +12 -0
- package/src/utils.ts +54 -0
- package/tsup.config.ts +61 -36
- package/vitest.config.ts +5 -1
- package/dist/iife/index.d.ts +0 -1101
- package/dist/iife/index.global.js +0 -75
- package/dist/iife/index.global.js.map +0 -1
- package/src/platform-adapter/android/AndroidPlatform.ts +0 -133
- package/src/platform-adapter/ssr/SSRPlatform.ts +0 -43
- /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).
|
|
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).
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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.
|
|
367
|
+
const r = await platform.createNativeSpatialDiv()
|
|
441
368
|
|
|
442
369
|
expect(r.success).toBe(true)
|
|
443
|
-
expect(r.data
|
|
444
|
-
expect(r.data
|
|
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
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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('
|
|
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(()
|
|
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.
|
|
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
|
-
|
|
977
|
-
|
|
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(()
|
|
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('
|
|
981
|
+
describe('isSSREnv', () => {
|
|
1041
982
|
it('isSSREnv returns false in jsdom', async () => {
|
|
1042
|
-
const { isSSREnv } = await import('./
|
|
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
|
|
989
|
+
it('createPlatform and createPlatformSync throw in SSR env', async () => {
|
|
1049
990
|
vi.resetModules()
|
|
1050
|
-
vi.doMock('./
|
|
991
|
+
vi.doMock('./isSSREnv', () => {
|
|
1051
992
|
return { isSSREnv: () => true }
|
|
1052
993
|
})
|
|
1053
994
|
|
|
1054
|
-
const { createPlatform } = await import(
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
expect(
|
|
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
|
})
|