@webspatial/core-sdk 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +112 -81
- package/dist/iife/index.d.ts +683 -561
- package/dist/iife/index.global.js +3 -4
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +683 -561
- package/dist/index.js +2193 -1291
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
- package/src/JSBCommand.ts +631 -0
- package/src/Spatial.ts +68 -0
- package/src/SpatialObject.ts +46 -0
- package/src/SpatialScene.ts +75 -0
- package/src/SpatialSession.ts +187 -0
- package/src/SpatialWebEvent.ts +23 -0
- package/src/SpatialWebEventCreator.ts +12 -0
- package/src/Spatialized2DElement.ts +51 -0
- package/src/SpatializedDynamic3DElement.ts +30 -0
- package/src/SpatializedElement.ts +331 -0
- package/src/SpatializedElementCreator.ts +45 -0
- package/src/SpatializedStatic3DElement.ts +111 -0
- package/src/WebMsgCommand.ts +88 -0
- package/src/index.ts +23 -1
- package/src/platform-adapter/CommandResultUtils.ts +22 -0
- package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
- package/src/platform-adapter/index.ts +21 -0
- package/src/platform-adapter/interface.ts +36 -0
- package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
- package/src/reality/component/ModelComponent.ts +11 -0
- package/src/reality/component/SpatialComponent.ts +17 -0
- package/src/reality/component/index.ts +2 -0
- package/src/reality/entity/SpatialEntity.ts +259 -0
- package/src/reality/entity/SpatialModelEntity.ts +15 -0
- package/src/reality/entity/index.ts +2 -0
- package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
- package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
- package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
- package/src/reality/geometry/SpatialGeometry.ts +12 -0
- package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
- package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
- package/src/reality/geometry/index.ts +6 -0
- package/src/reality/index.ts +5 -0
- package/src/reality/material/SpatialMaterial.ts +14 -0
- package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
- package/src/reality/material/index.ts +2 -0
- package/src/reality/realityCreator.ts +94 -0
- package/src/reality/resource/SpatialModelAsset.ts +11 -0
- package/src/reality/resource/index.ts +1 -0
- package/src/scene-polyfill.test.ts +376 -0
- package/src/scene-polyfill.ts +379 -0
- package/src/spatial-window-polyfill.ts +182 -0
- package/src/ssr-polyfill.ts +3 -0
- package/src/types/global.d.ts +33 -1
- package/src/types/internal.ts +13 -0
- package/src/types/types.ts +380 -0
- package/src/utils.ts +61 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +8 -0
- package/src/core/Spatial.ts +0 -50
- package/src/core/SpatialEntity.ts +0 -147
- package/src/core/SpatialHelper.ts +0 -230
- package/src/core/SpatialObject.ts +0 -26
- package/src/core/SpatialSession.ts +0 -457
- package/src/core/SpatialTransform.ts +0 -26
- package/src/core/SpatialWindowContainer.ts +0 -59
- package/src/core/component/EventSpatialComponent.ts +0 -32
- package/src/core/component/SpatialComponent.ts +0 -26
- package/src/core/component/SpatialInputComponent.ts +0 -24
- package/src/core/component/SpatialModel3DComponent.ts +0 -223
- package/src/core/component/SpatialModelComponent.ts +0 -39
- package/src/core/component/SpatialViewComponent.ts +0 -32
- package/src/core/component/SpatialWindowComponent.ts +0 -177
- package/src/core/component/index.ts +0 -14
- package/src/core/index.ts +0 -10
- package/src/core/private/WebSpatial.ts +0 -383
- package/src/core/private/remote-command/RemoteCommand.ts +0 -15
- package/src/core/private/remote-command/index.ts +0 -1
- package/src/core/resource/SpatialMeshResource.ts +0 -6
- package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
- package/src/core/resource/index.ts +0 -2
- package/src/core/types.ts +0 -32
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SpatialGeometryType,
|
|
3
|
+
SpatialPlaneGeometryOptions,
|
|
4
|
+
} from '../../types/types'
|
|
5
|
+
import { SpatialGeometry } from './SpatialGeometry'
|
|
6
|
+
|
|
7
|
+
export class SpatialPlaneGeometry extends SpatialGeometry {
|
|
8
|
+
static type: SpatialGeometryType = 'PlaneGeometry'
|
|
9
|
+
constructor(
|
|
10
|
+
public id: string,
|
|
11
|
+
public options: SpatialPlaneGeometryOptions,
|
|
12
|
+
) {
|
|
13
|
+
super(id, options)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SpatialGeometryType,
|
|
3
|
+
SpatialSphereGeometryOptions,
|
|
4
|
+
} from '../../types/types'
|
|
5
|
+
import { SpatialGeometry } from './SpatialGeometry'
|
|
6
|
+
|
|
7
|
+
export class SpatialSphereGeometry extends SpatialGeometry {
|
|
8
|
+
static type: SpatialGeometryType = 'SphereGeometry'
|
|
9
|
+
constructor(
|
|
10
|
+
public id: string,
|
|
11
|
+
public options: SpatialSphereGeometryOptions,
|
|
12
|
+
) {
|
|
13
|
+
super(id, options)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SpatialObject } from '../../SpatialObject'
|
|
2
|
+
import { SpatialMaterialType } from '../../types/types'
|
|
3
|
+
|
|
4
|
+
export abstract class SpatialMaterial extends SpatialObject {
|
|
5
|
+
constructor(
|
|
6
|
+
public id: string,
|
|
7
|
+
public type: SpatialMaterialType,
|
|
8
|
+
) {
|
|
9
|
+
super(id)
|
|
10
|
+
this.type = type
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
abstract updateProperties(properties: any): void
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UpdateUnlitMaterialProperties } from '../../JSBCommand'
|
|
2
|
+
import { SpatialUnlitMaterialOptions } from '../../types/types'
|
|
3
|
+
import { SpatialMaterial } from './SpatialMaterial'
|
|
4
|
+
|
|
5
|
+
export class SpatialUnlitMaterial extends SpatialMaterial {
|
|
6
|
+
constructor(
|
|
7
|
+
public id: string,
|
|
8
|
+
public options: SpatialUnlitMaterialOptions,
|
|
9
|
+
) {
|
|
10
|
+
super(id, 'unlit')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
updateProperties(properties: Partial<SpatialUnlitMaterialOptions>) {
|
|
14
|
+
return new UpdateUnlitMaterialProperties(this, properties).execute()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateModelComponentCommand,
|
|
3
|
+
CreateModelAssetCommand,
|
|
4
|
+
CreateSpatialEntityCommand,
|
|
5
|
+
CreateSpatialGeometryCommand,
|
|
6
|
+
CreateSpatialModelEntityCommand,
|
|
7
|
+
CreateSpatialUnlitMaterialCommand,
|
|
8
|
+
} from '../JSBCommand'
|
|
9
|
+
import {
|
|
10
|
+
ModelComponentOptions,
|
|
11
|
+
ModelAssetOptions,
|
|
12
|
+
SpatialGeometryOptions,
|
|
13
|
+
SpatialModelEntityCreationOptions,
|
|
14
|
+
SpatialUnlitMaterialOptions,
|
|
15
|
+
SpatialEntityUserData,
|
|
16
|
+
} from '../types/types'
|
|
17
|
+
import { SpatialEntity, SpatialModelEntity } from './entity'
|
|
18
|
+
import { ModelComponent } from './component'
|
|
19
|
+
import { SpatialGeometry } from './geometry'
|
|
20
|
+
import { SpatialUnlitMaterial } from './material'
|
|
21
|
+
import { SpatialModelAsset } from './resource'
|
|
22
|
+
|
|
23
|
+
export async function createSpatialEntity(
|
|
24
|
+
userData?: SpatialEntityUserData,
|
|
25
|
+
): Promise<SpatialEntity> {
|
|
26
|
+
const result = await new CreateSpatialEntityCommand(userData?.name).execute()
|
|
27
|
+
if (!result.success) {
|
|
28
|
+
throw new Error('createSpatialEntity failed:' + result?.errorMessage)
|
|
29
|
+
} else {
|
|
30
|
+
const { id } = result.data
|
|
31
|
+
return new SpatialEntity(id, userData)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function createSpatialGeometry<T extends SpatialGeometry>(
|
|
36
|
+
ctor: new (...args: any[]) => T,
|
|
37
|
+
options: SpatialGeometryOptions,
|
|
38
|
+
) {
|
|
39
|
+
const result = await new CreateSpatialGeometryCommand(
|
|
40
|
+
(ctor as any).type,
|
|
41
|
+
options,
|
|
42
|
+
).execute()
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
throw new Error('createSpatialGeometry failed:' + result?.errorMessage)
|
|
45
|
+
} else {
|
|
46
|
+
const { id } = result.data
|
|
47
|
+
return new ctor(id, options) as T
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function createSpatialUnlitMaterial(
|
|
52
|
+
options: SpatialUnlitMaterialOptions,
|
|
53
|
+
) {
|
|
54
|
+
const result = await new CreateSpatialUnlitMaterialCommand(options).execute()
|
|
55
|
+
if (!result.success) {
|
|
56
|
+
throw new Error('createSpatialUnlitMaterial failed:' + result?.errorMessage)
|
|
57
|
+
} else {
|
|
58
|
+
const { id } = result.data
|
|
59
|
+
return new SpatialUnlitMaterial(id, options)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function createModelComponent(options: ModelComponentOptions) {
|
|
64
|
+
const result = await new CreateModelComponentCommand(options).execute()
|
|
65
|
+
if (!result.success) {
|
|
66
|
+
throw new Error('createModelComponent failed:' + result?.errorMessage)
|
|
67
|
+
} else {
|
|
68
|
+
const { id } = result.data
|
|
69
|
+
return new ModelComponent(id, options)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function createSpatialModelEntity(
|
|
74
|
+
options: SpatialModelEntityCreationOptions,
|
|
75
|
+
userData?: SpatialEntityUserData,
|
|
76
|
+
) {
|
|
77
|
+
const result = await new CreateSpatialModelEntityCommand(options).execute()
|
|
78
|
+
if (!result.success) {
|
|
79
|
+
throw new Error('createSpatialModelEntity failed:' + result?.errorMessage)
|
|
80
|
+
} else {
|
|
81
|
+
const { id } = result.data
|
|
82
|
+
return new SpatialModelEntity(id, options, userData)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function createModelAsset(options: ModelAssetOptions) {
|
|
87
|
+
const result = await new CreateModelAssetCommand(options).execute()
|
|
88
|
+
if (!result.success) {
|
|
89
|
+
throw new Error('createModelAsset failed:' + result?.errorMessage)
|
|
90
|
+
} else {
|
|
91
|
+
const { id } = result.data
|
|
92
|
+
return new SpatialModelAsset(id, options)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpatialObject } from '../../SpatialObject'
|
|
2
|
+
import { ModelAssetOptions } from '../../types/types'
|
|
3
|
+
|
|
4
|
+
export class SpatialModelAsset extends SpatialObject {
|
|
5
|
+
constructor(
|
|
6
|
+
public id: string,
|
|
7
|
+
public options: ModelAssetOptions,
|
|
8
|
+
) {
|
|
9
|
+
super(id)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SpatialModelAsset';
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { describe, expect, test, vi, beforeEach, afterEach, it } from 'vitest'
|
|
2
|
+
import { formatSceneConfig, initScene, injectSceneHook } from './scene-polyfill'
|
|
3
|
+
import { SpatialSceneCreationOptions } from './types/types'
|
|
4
|
+
|
|
5
|
+
describe('test formatSceneConfig in window', () => {
|
|
6
|
+
test('should format window with no unit', () => {
|
|
7
|
+
const config = {
|
|
8
|
+
defaultSize: {
|
|
9
|
+
width: 100,
|
|
10
|
+
height: 100,
|
|
11
|
+
},
|
|
12
|
+
resizability: {
|
|
13
|
+
minWidth: 100,
|
|
14
|
+
minHeight: 100,
|
|
15
|
+
maxWidth: 100,
|
|
16
|
+
maxHeight: 100,
|
|
17
|
+
},
|
|
18
|
+
} satisfies SpatialSceneCreationOptions
|
|
19
|
+
const [formattedConfig] = formatSceneConfig(config, 'window')
|
|
20
|
+
expect(formattedConfig.defaultSize).toEqual({
|
|
21
|
+
width: 100,
|
|
22
|
+
height: 100,
|
|
23
|
+
})
|
|
24
|
+
expect(formattedConfig.resizability).toEqual({
|
|
25
|
+
minWidth: 100,
|
|
26
|
+
minHeight: 100,
|
|
27
|
+
maxWidth: 100,
|
|
28
|
+
maxHeight: 100,
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('should format window with px', () => {
|
|
33
|
+
const config = {
|
|
34
|
+
defaultSize: {
|
|
35
|
+
width: '100px',
|
|
36
|
+
height: '100px',
|
|
37
|
+
},
|
|
38
|
+
resizability: {
|
|
39
|
+
minWidth: '100px',
|
|
40
|
+
minHeight: '100px',
|
|
41
|
+
maxWidth: '100px',
|
|
42
|
+
maxHeight: '100px',
|
|
43
|
+
},
|
|
44
|
+
} satisfies SpatialSceneCreationOptions
|
|
45
|
+
const [formattedConfig] = formatSceneConfig(config, 'window')
|
|
46
|
+
expect(formattedConfig.defaultSize).toEqual({
|
|
47
|
+
width: 100,
|
|
48
|
+
height: 100,
|
|
49
|
+
})
|
|
50
|
+
expect(formattedConfig.resizability).toEqual({
|
|
51
|
+
minWidth: 100,
|
|
52
|
+
minHeight: 100,
|
|
53
|
+
maxWidth: 100,
|
|
54
|
+
maxHeight: 100,
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('should format window with invalid unit', () => {
|
|
59
|
+
const config = {
|
|
60
|
+
defaultSize: {
|
|
61
|
+
width: '100cm',
|
|
62
|
+
height: '100cm',
|
|
63
|
+
},
|
|
64
|
+
resizability: {
|
|
65
|
+
minWidth: '100cm',
|
|
66
|
+
minHeight: '100cm',
|
|
67
|
+
maxWidth: '100cm',
|
|
68
|
+
maxHeight: '100cm',
|
|
69
|
+
},
|
|
70
|
+
} satisfies SpatialSceneCreationOptions
|
|
71
|
+
const [, errors] = formatSceneConfig(config, 'window')
|
|
72
|
+
expect(errors).toEqual([
|
|
73
|
+
'defaultSize.width',
|
|
74
|
+
'defaultSize.height',
|
|
75
|
+
'resizability.minWidth',
|
|
76
|
+
'resizability.minHeight',
|
|
77
|
+
'resizability.maxWidth',
|
|
78
|
+
'resizability.maxHeight',
|
|
79
|
+
])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('should format window with meter', () => {
|
|
83
|
+
const config = {
|
|
84
|
+
defaultSize: {
|
|
85
|
+
width: '1m',
|
|
86
|
+
height: '1m',
|
|
87
|
+
},
|
|
88
|
+
resizability: {
|
|
89
|
+
minWidth: '1m',
|
|
90
|
+
minHeight: '1m',
|
|
91
|
+
maxWidth: '1m',
|
|
92
|
+
maxHeight: '1m',
|
|
93
|
+
},
|
|
94
|
+
} satisfies SpatialSceneCreationOptions
|
|
95
|
+
const [formattedConfig] = formatSceneConfig(config, 'window')
|
|
96
|
+
expect(formattedConfig.defaultSize).toEqual({
|
|
97
|
+
width: 1360,
|
|
98
|
+
height: 1360,
|
|
99
|
+
})
|
|
100
|
+
expect(formattedConfig.resizability).toEqual({
|
|
101
|
+
minWidth: 1360,
|
|
102
|
+
minHeight: 1360,
|
|
103
|
+
maxWidth: 1360,
|
|
104
|
+
maxHeight: 1360,
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('test formatSceneConfig in volume', () => {
|
|
110
|
+
test('should format volume with no unit', () => {
|
|
111
|
+
const config = {
|
|
112
|
+
defaultSize: {
|
|
113
|
+
width: 1,
|
|
114
|
+
height: 1,
|
|
115
|
+
depth: 1,
|
|
116
|
+
},
|
|
117
|
+
resizability: {
|
|
118
|
+
minWidth: 1,
|
|
119
|
+
minHeight: 1,
|
|
120
|
+
maxWidth: 1,
|
|
121
|
+
maxHeight: 1,
|
|
122
|
+
},
|
|
123
|
+
} satisfies SpatialSceneCreationOptions
|
|
124
|
+
const [formattedConfig] = formatSceneConfig(config, 'volume')
|
|
125
|
+
expect(formattedConfig.defaultSize).toEqual({
|
|
126
|
+
width: 1,
|
|
127
|
+
height: 1,
|
|
128
|
+
depth: 1,
|
|
129
|
+
})
|
|
130
|
+
expect(formattedConfig.resizability).toEqual({
|
|
131
|
+
minWidth: 1360,
|
|
132
|
+
minHeight: 1360,
|
|
133
|
+
maxWidth: 1360,
|
|
134
|
+
maxHeight: 1360,
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('should format volume with px', () => {
|
|
139
|
+
const config = {
|
|
140
|
+
defaultSize: {
|
|
141
|
+
width: '1360px',
|
|
142
|
+
height: '1360px',
|
|
143
|
+
depth: '1360px',
|
|
144
|
+
},
|
|
145
|
+
resizability: {
|
|
146
|
+
minWidth: '1360px',
|
|
147
|
+
minHeight: '1360px',
|
|
148
|
+
maxWidth: '1360px',
|
|
149
|
+
maxHeight: '1360px',
|
|
150
|
+
},
|
|
151
|
+
} satisfies SpatialSceneCreationOptions
|
|
152
|
+
const [formattedConfig] = formatSceneConfig(config, 'volume')
|
|
153
|
+
expect(formattedConfig.defaultSize).toEqual({
|
|
154
|
+
width: 1,
|
|
155
|
+
height: 1,
|
|
156
|
+
depth: 1,
|
|
157
|
+
})
|
|
158
|
+
expect(formattedConfig.resizability).toEqual({
|
|
159
|
+
minWidth: 1360,
|
|
160
|
+
minHeight: 1360,
|
|
161
|
+
maxWidth: 1360,
|
|
162
|
+
maxHeight: 1360,
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('should format volume with meter', () => {
|
|
167
|
+
const config = {
|
|
168
|
+
defaultSize: {
|
|
169
|
+
width: '1m',
|
|
170
|
+
height: '1m',
|
|
171
|
+
depth: '1m',
|
|
172
|
+
},
|
|
173
|
+
resizability: {
|
|
174
|
+
minWidth: '1m',
|
|
175
|
+
minHeight: '1m',
|
|
176
|
+
maxWidth: '1m',
|
|
177
|
+
maxHeight: '1m',
|
|
178
|
+
},
|
|
179
|
+
} satisfies SpatialSceneCreationOptions
|
|
180
|
+
const [formattedConfig] = formatSceneConfig(config, 'volume')
|
|
181
|
+
expect(formattedConfig.defaultSize).toEqual({
|
|
182
|
+
width: 1,
|
|
183
|
+
height: 1,
|
|
184
|
+
depth: 1,
|
|
185
|
+
})
|
|
186
|
+
expect(formattedConfig.resizability).toEqual({
|
|
187
|
+
minWidth: 1360,
|
|
188
|
+
minHeight: 1360,
|
|
189
|
+
maxWidth: 1360,
|
|
190
|
+
maxHeight: 1360,
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('should format volume with invalid unit', () => {
|
|
195
|
+
const config = {
|
|
196
|
+
defaultSize: {
|
|
197
|
+
width: '100cm',
|
|
198
|
+
height: '100cm',
|
|
199
|
+
depth: '100cm',
|
|
200
|
+
},
|
|
201
|
+
resizability: {
|
|
202
|
+
minWidth: '100cm',
|
|
203
|
+
minHeight: '100cm',
|
|
204
|
+
maxWidth: '100cm',
|
|
205
|
+
maxHeight: '100cm',
|
|
206
|
+
},
|
|
207
|
+
} satisfies SpatialSceneCreationOptions
|
|
208
|
+
const [, errors] = formatSceneConfig(config, 'volume')
|
|
209
|
+
expect(errors).toEqual([
|
|
210
|
+
'defaultSize.width',
|
|
211
|
+
'defaultSize.height',
|
|
212
|
+
'defaultSize.depth',
|
|
213
|
+
'resizability.minWidth',
|
|
214
|
+
'resizability.minHeight',
|
|
215
|
+
'resizability.maxWidth',
|
|
216
|
+
'resizability.maxHeight',
|
|
217
|
+
])
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
vi.mock('./JSBCommand', () => {
|
|
222
|
+
return {
|
|
223
|
+
GetSpatialSceneState: vi.fn().mockImplementation(() => ({
|
|
224
|
+
execute: vi.fn().mockResolvedValue({ data: { name: 'pending' } }),
|
|
225
|
+
})),
|
|
226
|
+
UpdateSceneConfig: vi.fn().mockImplementation(() => ({
|
|
227
|
+
execute: vi.fn().mockResolvedValue(undefined),
|
|
228
|
+
})),
|
|
229
|
+
UpdateSpatialSceneProperties: vi.fn().mockImplementation(() => ({
|
|
230
|
+
execute: vi.fn().mockResolvedValue(undefined),
|
|
231
|
+
})),
|
|
232
|
+
AddSpatializedElementToSpatialScene: vi.fn().mockImplementation(() => ({
|
|
233
|
+
execute: vi.fn().mockResolvedValue(undefined),
|
|
234
|
+
})),
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
describe('injectScenePolyfill should call xrCurrentSceneDefaults and update scene config', () => {
|
|
239
|
+
beforeEach(() => {
|
|
240
|
+
;(window as any).opener = {}
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('with no type', async () => {
|
|
244
|
+
vi.useFakeTimers()
|
|
245
|
+
|
|
246
|
+
const mockFn = vi
|
|
247
|
+
.fn()
|
|
248
|
+
.mockResolvedValue({ defaultSize: { width: 800, height: 600 } })
|
|
249
|
+
window.xrCurrentSceneDefaults = mockFn
|
|
250
|
+
|
|
251
|
+
injectSceneHook()
|
|
252
|
+
|
|
253
|
+
document.dispatchEvent(new Event('DOMContentLoaded'))
|
|
254
|
+
|
|
255
|
+
await vi.runAllTimersAsync()
|
|
256
|
+
|
|
257
|
+
expect(mockFn).toHaveBeenCalledWith(
|
|
258
|
+
expect.objectContaining({ defaultSize: { width: 1280, height: 720 } }),
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
// verify UpdateSceneConfig.execute
|
|
262
|
+
const { UpdateSceneConfig } = await import('./JSBCommand')
|
|
263
|
+
expect(UpdateSceneConfig).toHaveBeenCalledWith({
|
|
264
|
+
type: 'window',
|
|
265
|
+
defaultSize: { width: 800, height: 600 },
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
it('with window type', async () => {
|
|
270
|
+
vi.useFakeTimers()
|
|
271
|
+
|
|
272
|
+
const mockFn = vi
|
|
273
|
+
.fn()
|
|
274
|
+
.mockResolvedValue({ defaultSize: { width: 800, height: 600 } })
|
|
275
|
+
window.xrCurrentSceneDefaults = mockFn
|
|
276
|
+
window.xrCurrentSceneType = 'window'
|
|
277
|
+
|
|
278
|
+
injectSceneHook()
|
|
279
|
+
|
|
280
|
+
document.dispatchEvent(new Event('DOMContentLoaded'))
|
|
281
|
+
|
|
282
|
+
await vi.runAllTimersAsync()
|
|
283
|
+
|
|
284
|
+
expect(mockFn).toHaveBeenCalledWith(
|
|
285
|
+
expect.objectContaining({ defaultSize: { width: 1280, height: 720 } }),
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
// verify UpdateSceneConfig.execute
|
|
289
|
+
const { UpdateSceneConfig } = await import('./JSBCommand')
|
|
290
|
+
expect(UpdateSceneConfig).toHaveBeenCalledWith({
|
|
291
|
+
type: 'window',
|
|
292
|
+
defaultSize: { width: 800, height: 600 },
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
it('with volume type', async () => {
|
|
297
|
+
vi.useFakeTimers()
|
|
298
|
+
|
|
299
|
+
const mockFn = vi.fn().mockResolvedValue({
|
|
300
|
+
defaultSize: { width: 1, height: 1, depth: 1 },
|
|
301
|
+
resizability: {
|
|
302
|
+
minWidth: 0.5,
|
|
303
|
+
minHeight: 1,
|
|
304
|
+
maxWidth: 0.5,
|
|
305
|
+
maxHeight: 1,
|
|
306
|
+
},
|
|
307
|
+
})
|
|
308
|
+
window.xrCurrentSceneDefaults = mockFn
|
|
309
|
+
window.xrCurrentSceneType = 'volume'
|
|
310
|
+
|
|
311
|
+
injectSceneHook()
|
|
312
|
+
|
|
313
|
+
document.dispatchEvent(new Event('DOMContentLoaded'))
|
|
314
|
+
|
|
315
|
+
await vi.runAllTimersAsync()
|
|
316
|
+
|
|
317
|
+
expect(mockFn).toHaveBeenCalledWith(
|
|
318
|
+
expect.objectContaining({
|
|
319
|
+
defaultSize: { width: 0.94, height: 0.94, depth: 0.94 },
|
|
320
|
+
}),
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
// verify UpdateSceneConfig.execute
|
|
324
|
+
const { UpdateSceneConfig } = await import('./JSBCommand')
|
|
325
|
+
expect(UpdateSceneConfig).toHaveBeenCalledWith({
|
|
326
|
+
type: 'volume',
|
|
327
|
+
defaultSize: { width: 1, height: 1, depth: 1 },
|
|
328
|
+
resizability: {
|
|
329
|
+
minWidth: 0.5 * 1360,
|
|
330
|
+
minHeight: 1 * 1360,
|
|
331
|
+
maxWidth: 0.5 * 1360,
|
|
332
|
+
maxHeight: 1 * 1360,
|
|
333
|
+
},
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
describe('initScene should receive defaultScene config by type', () => {
|
|
339
|
+
it('with no type', async () => {
|
|
340
|
+
const mockFn = vi
|
|
341
|
+
.fn()
|
|
342
|
+
.mockResolvedValue({ defaultSize: { width: 800, height: 600 } })
|
|
343
|
+
|
|
344
|
+
initScene('sa', mockFn)
|
|
345
|
+
|
|
346
|
+
expect(mockFn).toHaveBeenCalledWith(
|
|
347
|
+
expect.objectContaining({ defaultSize: { width: 1280, height: 720 } }),
|
|
348
|
+
)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
it('with window type', async () => {
|
|
352
|
+
const mockFn = vi
|
|
353
|
+
.fn()
|
|
354
|
+
.mockResolvedValue({ defaultSize: { width: 800, height: 600 } })
|
|
355
|
+
|
|
356
|
+
initScene('sa', mockFn, { type: 'window' })
|
|
357
|
+
|
|
358
|
+
expect(mockFn).toHaveBeenCalledWith(
|
|
359
|
+
expect.objectContaining({ defaultSize: { width: 1280, height: 720 } }),
|
|
360
|
+
)
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
it('with volume type', async () => {
|
|
364
|
+
const mockFn = vi
|
|
365
|
+
.fn()
|
|
366
|
+
.mockResolvedValue({ defaultSize: { width: 800, height: 600 } })
|
|
367
|
+
|
|
368
|
+
initScene('sa', mockFn, { type: 'volume' })
|
|
369
|
+
|
|
370
|
+
expect(mockFn).toHaveBeenCalledWith(
|
|
371
|
+
expect.objectContaining({
|
|
372
|
+
defaultSize: { width: 0.94, height: 0.94, depth: 0.94 },
|
|
373
|
+
}),
|
|
374
|
+
)
|
|
375
|
+
})
|
|
376
|
+
})
|