@webspatial/core-sdk 1.7.0 → 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 +61 -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 -1251
- package/dist/index.js +21 -3650
- 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 +132 -5
- package/src/SpatialObject.ts +10 -0
- package/src/Spatialized2DElement.ts +5 -0
- package/src/SpatializedDynamic3DElement.ts +5 -0
- package/src/SpatializedElement.ts +29 -0
- package/src/SpatializedStatic3DElement.ts +42 -3
- package/src/WebMsgCommand.ts +40 -0
- package/src/coverage-boost.test.ts +239 -216
- package/src/index.ts +25 -11
- package/src/install-polyfills.ts +38 -0
- package/src/jsbcommand.coverage.test.ts +23 -0
- 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/createPlatformSync.ts +5 -3
- package/src/platform-adapter/pico-os/PicoOSPlatform.ts +76 -11
- package/src/platform-adapter/spatialRequestMetadata.test.ts +175 -0
- package/src/platform-adapter/spatialRequestMetadata.ts +48 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +6 -1
- package/src/reality/entity/SpatialEntity.ts +127 -0
- package/src/runtime/capability-data.ts +104 -4
- package/src/runtime/index.ts +0 -11
- package/src/runtime/keys.ts +12 -1
- package/src/runtime/supports.test.ts +143 -4
- package/src/runtime/supports.ts +3 -1
- package/src/runtime/useAnimation.capability.test.ts +275 -0
- package/src/scene-polyfill.manifest.test.ts +306 -5
- package/src/scene-polyfill.request-metadata.test.ts +39 -0
- package/src/scene-polyfill.test.ts +33 -94
- package/src/scene-polyfill.ts +117 -87
- 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.ts +1 -8
- 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 +3 -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 -1251
- package/dist/iife/index.global.js +0 -75
- package/dist/iife/index.global.js.map +0 -1
- package/src/platform-adapter/ssr/SSRPlatform.ts +0 -52
- /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,18 +316,6 @@ describe('platform adapters', () => {
|
|
|
263
316
|
vi.unmock('./JSBCommand')
|
|
264
317
|
})
|
|
265
318
|
|
|
266
|
-
it('SSRPlatform returns successful no-op results', async () => {
|
|
267
|
-
const { SSRPlatform } = await import('./platform-adapter/ssr/SSRPlatform')
|
|
268
|
-
const platform = new SSRPlatform()
|
|
269
|
-
|
|
270
|
-
await expect(platform.callJSB('c', '{}')).resolves.toMatchObject({
|
|
271
|
-
success: true,
|
|
272
|
-
})
|
|
273
|
-
expect(platform.openSpatialSceneSync('s', undefined)).toMatchObject({
|
|
274
|
-
success: true,
|
|
275
|
-
})
|
|
276
|
-
})
|
|
277
|
-
|
|
278
319
|
it('VisionOSPlatform.callJSB returns success and parses failures', async () => {
|
|
279
320
|
;(window as any).webkit = {
|
|
280
321
|
messageHandlers: {
|
|
@@ -326,8 +367,8 @@ describe('platform adapters', () => {
|
|
|
326
367
|
const r = await platform.createNativeSpatialDiv()
|
|
327
368
|
|
|
328
369
|
expect(r.success).toBe(true)
|
|
329
|
-
expect(r.data
|
|
330
|
-
expect(r.data
|
|
370
|
+
expect(r.data?.id).toBe(uuid)
|
|
371
|
+
expect(r.data?.windowProxy).toBe(windowProxy)
|
|
331
372
|
})
|
|
332
373
|
})
|
|
333
374
|
|
|
@@ -456,6 +497,44 @@ describe('spatialWindowPolyfill', () => {
|
|
|
456
497
|
expect(updateSpatialProperties).toHaveBeenCalledWith({
|
|
457
498
|
material: 'none',
|
|
458
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
|
+
})
|
|
459
538
|
})
|
|
460
539
|
})
|
|
461
540
|
|
|
@@ -501,34 +580,42 @@ describe('SpatializedElementCreator', () => {
|
|
|
501
580
|
UpdateSpatializedDynamic3DElementProperties: OkCommand,
|
|
502
581
|
SetParentForEntityCommand: OkCommand,
|
|
503
582
|
AddEntityToDynamic3DCommand: OkCommand,
|
|
504
|
-
createSpatialized2DElementCommand: vi
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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
|
+
}
|
|
510
594
|
}),
|
|
511
|
-
})),
|
|
512
595
|
CreateSpatializedStatic3DElementCommand: vi
|
|
513
596
|
.fn()
|
|
514
|
-
.mockImplementation(()
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
+
}),
|
|
522
607
|
CreateSpatializedDynamic3DElementCommand: vi
|
|
523
608
|
.fn()
|
|
524
|
-
.mockImplementation(()
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
+
}),
|
|
532
619
|
}
|
|
533
620
|
})
|
|
534
621
|
|
|
@@ -574,14 +661,18 @@ describe('SpatializedElementCreator', () => {
|
|
|
574
661
|
UpdateSpatializedDynamic3DElementProperties: OkCommand,
|
|
575
662
|
SetParentForEntityCommand: OkCommand,
|
|
576
663
|
AddEntityToDynamic3DCommand: OkCommand,
|
|
577
|
-
createSpatialized2DElementCommand: vi
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|
+
}
|
|
583
675
|
}),
|
|
584
|
-
})),
|
|
585
676
|
CreateSpatializedStatic3DElementCommand: vi.fn(),
|
|
586
677
|
CreateSpatializedDynamic3DElementCommand: vi.fn(),
|
|
587
678
|
}
|
|
@@ -622,22 +713,26 @@ describe('SpatializedElementCreator', () => {
|
|
|
622
713
|
CreateSpatializedDynamic3DElementCommand: vi.fn(),
|
|
623
714
|
CreateSpatializedStatic3DElementCommand: vi
|
|
624
715
|
.fn()
|
|
625
|
-
.mockImplementationOnce(()
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
+
}),
|
|
641
736
|
}
|
|
642
737
|
})
|
|
643
738
|
|
|
@@ -679,22 +774,26 @@ describe('SpatializedElementCreator', () => {
|
|
|
679
774
|
CreateSpatializedStatic3DElementCommand: vi.fn(),
|
|
680
775
|
CreateSpatializedDynamic3DElementCommand: vi
|
|
681
776
|
.fn()
|
|
682
|
-
.mockImplementationOnce(()
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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
|
+
}),
|
|
698
797
|
}
|
|
699
798
|
})
|
|
700
799
|
|
|
@@ -717,72 +816,7 @@ describe('SpatializedStatic3DElement', () => {
|
|
|
717
816
|
vi.unmock('./JSBCommand')
|
|
718
817
|
})
|
|
719
818
|
|
|
720
|
-
it('
|
|
721
|
-
const execute = vi.fn().mockResolvedValue({
|
|
722
|
-
success: true,
|
|
723
|
-
data: undefined,
|
|
724
|
-
errorCode: '',
|
|
725
|
-
errorMessage: '',
|
|
726
|
-
})
|
|
727
|
-
vi.doMock('./JSBCommand', () => {
|
|
728
|
-
class OkCommand {
|
|
729
|
-
execute() {
|
|
730
|
-
return Promise.resolve({
|
|
731
|
-
success: true,
|
|
732
|
-
data: undefined,
|
|
733
|
-
errorCode: '',
|
|
734
|
-
errorMessage: '',
|
|
735
|
-
})
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
return {
|
|
740
|
-
InspectCommand: OkCommand,
|
|
741
|
-
DestroyCommand: OkCommand,
|
|
742
|
-
UpdateSpatializedElementTransform: OkCommand,
|
|
743
|
-
UpdateSpatialized2DElementProperties: OkCommand,
|
|
744
|
-
AddSpatializedElementToSpatialized2DElement: OkCommand,
|
|
745
|
-
UpdateSpatializedDynamic3DElementProperties: OkCommand,
|
|
746
|
-
SetParentForEntityCommand: OkCommand,
|
|
747
|
-
AddEntityToDynamic3DCommand: OkCommand,
|
|
748
|
-
createSpatialized2DElementCommand: vi.fn(),
|
|
749
|
-
CreateSpatializedStatic3DElementCommand: vi.fn(),
|
|
750
|
-
CreateSpatializedDynamic3DElementCommand: vi.fn(),
|
|
751
|
-
UpdateSpatializedStatic3DElementProperties: vi
|
|
752
|
-
.fn()
|
|
753
|
-
.mockImplementation(() => ({ execute })),
|
|
754
|
-
}
|
|
755
|
-
})
|
|
756
|
-
|
|
757
|
-
const { SpatializedStatic3DElement } = await import(
|
|
758
|
-
'./SpatializedStatic3DElement'
|
|
759
|
-
)
|
|
760
|
-
const { SpatialWebMsgType } = await import('./WebMsgCommand')
|
|
761
|
-
|
|
762
|
-
const el = new SpatializedStatic3DElement('m1')
|
|
763
|
-
const onLoad = vi.fn()
|
|
764
|
-
const onFail = vi.fn()
|
|
765
|
-
el.onLoadCallback = onLoad
|
|
766
|
-
el.onLoadFailureCallback = onFail
|
|
767
|
-
|
|
768
|
-
const p1 = el.ready
|
|
769
|
-
await el.updateProperties({ modelURL: 'a.glb' } as any)
|
|
770
|
-
expect(execute).toHaveBeenCalledTimes(1)
|
|
771
|
-
const p2 = el.ready
|
|
772
|
-
expect(p2).not.toBe(p1)
|
|
773
|
-
|
|
774
|
-
el.onReceiveEvent({ type: SpatialWebMsgType.modelloaded } as any)
|
|
775
|
-
await expect(p2).resolves.toBe(true)
|
|
776
|
-
expect(onLoad).toHaveBeenCalledTimes(1)
|
|
777
|
-
|
|
778
|
-
await el.updateProperties({ modelURL: 'b.glb' } as any)
|
|
779
|
-
const p3 = el.ready
|
|
780
|
-
el.onReceiveEvent({ type: SpatialWebMsgType.modelloadfailed } as any)
|
|
781
|
-
await expect(p3).resolves.toBe(false)
|
|
782
|
-
expect(onFail).toHaveBeenCalledTimes(1)
|
|
783
|
-
})
|
|
784
|
-
|
|
785
|
-
it('updateModelTransform passes float64 array to updateProperties', async () => {
|
|
819
|
+
it('entityTransform setter passes float64 array to updateProperties', async () => {
|
|
786
820
|
const execute = vi.fn().mockResolvedValue({
|
|
787
821
|
success: true,
|
|
788
822
|
data: undefined,
|
|
@@ -815,7 +849,9 @@ describe('SpatializedStatic3DElement', () => {
|
|
|
815
849
|
CreateSpatializedDynamic3DElementCommand: vi.fn(),
|
|
816
850
|
UpdateSpatializedStatic3DElementProperties: vi
|
|
817
851
|
.fn()
|
|
818
|
-
.mockImplementation(()
|
|
852
|
+
.mockImplementation(function () {
|
|
853
|
+
return { execute }
|
|
854
|
+
}),
|
|
819
855
|
}
|
|
820
856
|
})
|
|
821
857
|
|
|
@@ -832,7 +868,7 @@ describe('SpatializedStatic3DElement', () => {
|
|
|
832
868
|
}
|
|
833
869
|
|
|
834
870
|
const el = new SpatializedStatic3DElement('m2')
|
|
835
|
-
el.
|
|
871
|
+
el.entityTransform = new DOMMatrixWithArray() as any
|
|
836
872
|
expect(execute).toHaveBeenCalledTimes(1)
|
|
837
873
|
})
|
|
838
874
|
})
|
|
@@ -875,9 +911,9 @@ describe('SpatializedDynamic3DElement', () => {
|
|
|
875
911
|
CreateSpatializedStatic3DElementCommand: vi.fn(),
|
|
876
912
|
CreateSpatializedDynamic3DElementCommand: vi.fn(),
|
|
877
913
|
AddEntityToDynamic3DCommand: OkCommand,
|
|
878
|
-
SetParentForEntityCommand: vi
|
|
879
|
-
|
|
880
|
-
|
|
914
|
+
SetParentForEntityCommand: vi.fn().mockImplementation(function () {
|
|
915
|
+
return { execute }
|
|
916
|
+
}),
|
|
881
917
|
}
|
|
882
918
|
})
|
|
883
919
|
|
|
@@ -927,7 +963,9 @@ describe('SpatializedDynamic3DElement', () => {
|
|
|
927
963
|
CreateSpatializedDynamic3DElementCommand: vi.fn(),
|
|
928
964
|
UpdateSpatializedDynamic3DElementProperties: vi
|
|
929
965
|
.fn()
|
|
930
|
-
.mockImplementation(()
|
|
966
|
+
.mockImplementation(function () {
|
|
967
|
+
return { execute }
|
|
968
|
+
}),
|
|
931
969
|
}
|
|
932
970
|
})
|
|
933
971
|
|
|
@@ -940,40 +978,25 @@ describe('SpatializedDynamic3DElement', () => {
|
|
|
940
978
|
})
|
|
941
979
|
})
|
|
942
980
|
|
|
943
|
-
describe('
|
|
981
|
+
describe('isSSREnv', () => {
|
|
944
982
|
it('isSSREnv returns false in jsdom', async () => {
|
|
945
|
-
const { isSSREnv } = await import('./
|
|
983
|
+
const { isSSREnv } = await import('./isSSREnv')
|
|
946
984
|
expect(isSSREnv()).toBe(false)
|
|
947
985
|
})
|
|
948
986
|
})
|
|
949
987
|
|
|
950
988
|
describe('platform-adapter', () => {
|
|
951
|
-
it('createPlatform
|
|
952
|
-
vi.resetModules()
|
|
953
|
-
vi.doMock('./ssr-polyfill', () => {
|
|
954
|
-
return { isSSREnv: () => true }
|
|
955
|
-
})
|
|
956
|
-
|
|
957
|
-
const { createPlatform } = await import('./platform-adapter')
|
|
958
|
-
const p = await createPlatform()
|
|
959
|
-
expect(typeof p.callJSB).toBe('function')
|
|
960
|
-
expect(typeof p.openSpatialSceneSync).toBe('function')
|
|
961
|
-
expect(typeof p.createNativeSpatialDiv).toBe('function')
|
|
962
|
-
expect(typeof p.createNativeAttachment).toBe('function')
|
|
963
|
-
})
|
|
964
|
-
|
|
965
|
-
it('createPlatformSync uses SSR sync noop in SSR env', async () => {
|
|
989
|
+
it('createPlatform and createPlatformSync throw in SSR env', async () => {
|
|
966
990
|
vi.resetModules()
|
|
967
|
-
vi.doMock('./
|
|
991
|
+
vi.doMock('./isSSREnv', () => {
|
|
968
992
|
return { isSSREnv: () => true }
|
|
969
993
|
})
|
|
970
994
|
|
|
971
|
-
const { createPlatformSync } = await import(
|
|
972
|
-
'./platform-adapter
|
|
995
|
+
const { createPlatform, createPlatformSync } = await import(
|
|
996
|
+
'./platform-adapter'
|
|
973
997
|
)
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
expect(
|
|
977
|
-
expect(r.data).toBeUndefined()
|
|
998
|
+
const expected = /cannot run during SSR/
|
|
999
|
+
await expect(createPlatform()).rejects.toThrow(expected)
|
|
1000
|
+
expect(() => createPlatformSync()).toThrow(expected)
|
|
978
1001
|
})
|
|
979
1002
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// `@webspatial/core-sdk` ESM entry — side-effect-free.
|
|
3
|
+
//
|
|
4
|
+
// The previous top-level polyfill installation (`if (UA contains
|
|
5
|
+
// 'WebSpatial/') { injectSceneHook(); spatialWindowPolyfill(); }`) lived
|
|
6
|
+
// here historically and was extracted out per the lazy-load proposal
|
|
7
|
+
// `tasks.md §12.9` ("Pre-v1 budget calibration"). ESM bundlers cannot
|
|
8
|
+
// tree-shake observable top-level side effects, so the runtime UA guard
|
|
9
|
+
// was useless for bundle size — every consumer that imported anything
|
|
10
|
+
// from this package statically bundled `scene-polyfill.ts` + the
|
|
11
|
+
// `spatial-window-polyfill.ts` pair regardless of whether they ran in a
|
|
12
|
+
// WebSpatial browser. After this extraction, consumers opt in:
|
|
13
|
+
//
|
|
14
|
+
// import '@webspatial/core-sdk/install-polyfills'
|
|
15
|
+
//
|
|
16
|
+
// `@webspatial/react-sdk` does this from inside its spatial chunk so the
|
|
17
|
+
// polyfills install only when `bootSpatial()` resolves, never in the
|
|
18
|
+
// lean default-entry bundle.
|
|
19
|
+
// =============================================================================
|
|
20
|
+
|
|
1
21
|
export type {} from './types/global'
|
|
2
22
|
|
|
3
23
|
export { SpatialObject } from './SpatialObject'
|
|
@@ -12,16 +32,10 @@ export * as PhysicalMetrics from './physicalMetrics'
|
|
|
12
32
|
|
|
13
33
|
export * from './reality'
|
|
14
34
|
export * from './types/types'
|
|
35
|
+
export * from './types/animation'
|
|
36
|
+
export * from './types/motion'
|
|
37
|
+
export { validateSpatializedMotionConfig } from './motion'
|
|
15
38
|
export * from './runtime'
|
|
16
39
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { isSSREnv } from './ssr-polyfill'
|
|
20
|
-
import { spatialWindowPolyfill } from './spatial-window-polyfill'
|
|
21
|
-
|
|
22
|
-
export { isSSREnv }
|
|
23
|
-
|
|
24
|
-
if (!isSSREnv() && navigator.userAgent.indexOf('WebSpatial/') > 0) {
|
|
25
|
-
injectSceneHook()
|
|
26
|
-
spatialWindowPolyfill()
|
|
27
|
-
}
|
|
40
|
+
export { composeSRT, decomposeSRT } from './utils'
|
|
41
|
+
export { isSSREnv } from './isSSREnv'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// `@webspatial/core-sdk/install-polyfills` — opt-in polyfill installer.
|
|
3
|
+
//
|
|
4
|
+
// Side-effect-only module: installs the spatial scene hook + the
|
|
5
|
+
// `window.spatial` polyfill iff the page is running inside a
|
|
6
|
+
// WebSpatial-capable browser (UA contains `WebSpatial/`) AND we are not
|
|
7
|
+
// in an SSR / non-browser environment.
|
|
8
|
+
//
|
|
9
|
+
// Previously this side effect lived as a top-level `if (...)` block in
|
|
10
|
+
// `src/index.ts`, which forced every consumer of the package — even
|
|
11
|
+
// consumers that only imported pure runtime helpers like `supports()` —
|
|
12
|
+
// to bundle `scene-polyfill.ts` (~636 LoC) and `spatial-window-polyfill.ts`
|
|
13
|
+
// (~182 LoC) statically. ESM bundlers cannot tree-shake observable
|
|
14
|
+
// side effects, so the if-statement guard was useless for bundle size.
|
|
15
|
+
//
|
|
16
|
+
// After this extraction, `src/index.ts` is side-effect-free and consumers
|
|
17
|
+
// who need the polyfills opt in explicitly:
|
|
18
|
+
//
|
|
19
|
+
// import '@webspatial/core-sdk/install-polyfills'
|
|
20
|
+
//
|
|
21
|
+
// `@webspatial/react-sdk` does this from inside its spatial chunk
|
|
22
|
+
// (`packages/react/src/spatial/index.ts`) so the polyfill installs only
|
|
23
|
+
// when the spatial chunk dynamically loads — never in the SDK's lean
|
|
24
|
+
// default entry.
|
|
25
|
+
//
|
|
26
|
+
// Per the lazy-load proposal `tasks.md §12.9` ("Pre-v1 budget calibration"),
|
|
27
|
+
// extracting these polyfills is one of the named optimization candidates
|
|
28
|
+
// for closing the marginal-delta gap on the 8 KB strict budget.
|
|
29
|
+
// =============================================================================
|
|
30
|
+
|
|
31
|
+
import { injectSceneHook } from './scene-polyfill'
|
|
32
|
+
import { spatialWindowPolyfill } from './spatial-window-polyfill'
|
|
33
|
+
import { isSSREnv } from './isSSREnv'
|
|
34
|
+
|
|
35
|
+
if (!isSSREnv() && navigator.userAgent.indexOf('WebSpatial/') > 0) {
|
|
36
|
+
injectSceneHook()
|
|
37
|
+
spatialWindowPolyfill()
|
|
38
|
+
}
|