@webspatial/core-sdk 1.0.5 → 1.2.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 +16 -0
- package/dist/iife/index.d.ts +29 -32
- package/dist/iife/index.global.js +3 -3
- package/dist/iife/index.global.js.map +1 -1
- package/dist/index.d.ts +29 -32
- package/dist/index.js +170 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/JSBCommand.ts +1 -1
- package/src/SpatialScene.ts +2 -2
- package/src/SpatialSession.ts +7 -4
- package/src/SpatializedElement.ts +13 -53
- package/src/SpatializedStatic3DElement.ts +1 -1
- package/src/WebMsgCommand.ts +8 -3
- package/src/coverage-boost.test.ts +1060 -0
- package/src/jsbcommand.coverage.test.ts +542 -0
- package/src/platform-adapter/android/AndroidPlatform.ts +2 -2
- package/src/platform-adapter/index.ts +31 -3
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +0 -1
- package/src/platform-adapter/xr/XRPlatform.ts +133 -0
- package/src/reality/component/index.ts +1 -1
- package/src/reality/entity/SpatialEntity.ts +6 -14
- package/src/reality/entity/index.ts +1 -1
- package/src/reality/geometry/SpatialBoxGeometry.ts +4 -1
- package/src/reality/geometry/index.ts +1 -1
- package/src/reality/material/index.ts +1 -1
- package/src/reality/resource/index.ts +1 -1
- package/src/scene-polyfill.ts +25 -9
- package/src/types/internal.ts +5 -5
- package/src/types/types.ts +23 -17
package/dist/index.d.ts
CHANGED
|
@@ -55,10 +55,8 @@ declare enum SpatialWebMsgType {
|
|
|
55
55
|
spatialdragstart = "spatialdragstart",
|
|
56
56
|
spatialdrag = "spatialdrag",
|
|
57
57
|
spatialdragend = "spatialdragend",
|
|
58
|
-
spatialrotatestart = "spatialrotatestart",
|
|
59
58
|
spatialrotate = "spatialrotate",
|
|
60
59
|
spatialrotateend = "spatialrotateend",
|
|
61
|
-
spatialmagnifystart = "spatialmagnifystart",
|
|
62
60
|
spatialmagnify = "spatialmagnify",
|
|
63
61
|
spatialmagnifyend = "spatialmagnifyend",
|
|
64
62
|
objectdestroy = "objectdestroy"
|
|
@@ -89,13 +87,17 @@ interface SpatialTapMsg {
|
|
|
89
87
|
type: SpatialWebMsgType.spatialtap;
|
|
90
88
|
detail: SpatialTapEventDetail;
|
|
91
89
|
}
|
|
90
|
+
interface SpatialDragStartMsg {
|
|
91
|
+
type: SpatialWebMsgType.spatialdragstart;
|
|
92
|
+
detail: SpatialDragStartEventDetail;
|
|
93
|
+
}
|
|
92
94
|
interface SpatialDragMsg {
|
|
93
95
|
type: SpatialWebMsgType.spatialdrag;
|
|
94
96
|
detail: SpatialDragEventDetail;
|
|
95
97
|
}
|
|
96
98
|
interface SpatialDragEndMsg {
|
|
97
99
|
type: SpatialWebMsgType.spatialdragend;
|
|
98
|
-
detail:
|
|
100
|
+
detail: SpatialDragEndEventDetail;
|
|
99
101
|
}
|
|
100
102
|
interface SpatialRotateMsg {
|
|
101
103
|
type: SpatialWebMsgType.spatialrotate;
|
|
@@ -167,26 +169,19 @@ declare abstract class SpatializedElement extends SpatialObject {
|
|
|
167
169
|
* Handles various spatial events like transforms, gestures, and interactions.
|
|
168
170
|
* @param data The event data received from the WebSpatial system
|
|
169
171
|
*/
|
|
170
|
-
protected onReceiveEvent(data: CubeInfoMsg | TransformMsg | SpatialTapMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
|
|
172
|
+
protected onReceiveEvent(data: CubeInfoMsg | TransformMsg | SpatialTapMsg | SpatialDragStartMsg | SpatialDragMsg | SpatialDragEndMsg | SpatialRotateMsg | SpatialRotateEndMsg | ObjectDestroyMsg): void;
|
|
171
173
|
private _onSpatialTap?;
|
|
172
174
|
set onSpatialTap(value: (event: SpatialTapEvent) => void | undefined);
|
|
173
|
-
private _isDragging;
|
|
174
175
|
private _onSpatialDragStart?;
|
|
175
|
-
set onSpatialDragStart(value: (event:
|
|
176
|
+
set onSpatialDragStart(value: (event: SpatialDragStartEvent) => void | undefined);
|
|
176
177
|
private _onSpatialDrag?;
|
|
177
178
|
set onSpatialDrag(value: (event: SpatialDragEvent) => void | undefined);
|
|
178
179
|
private _onSpatialDragEnd?;
|
|
179
180
|
set onSpatialDragEnd(value: ((event: SpatialDragEndEvent) => void) | undefined);
|
|
180
|
-
private _isRotating;
|
|
181
|
-
private _onSpatialRotateStart?;
|
|
182
|
-
set onSpatialRotateStart(value: ((event: SpatialRotateEvent) => void) | undefined);
|
|
183
181
|
private _onSpatialRotate?;
|
|
184
182
|
set onSpatialRotate(value: ((event: SpatialRotateEvent) => void) | undefined);
|
|
185
183
|
private _onSpatialRotateEnd?;
|
|
186
184
|
set onSpatialRotateEnd(value: ((event: SpatialRotateEndEvent) => void) | undefined);
|
|
187
|
-
private _isMagnify;
|
|
188
|
-
private _onSpatialMagnifyStart?;
|
|
189
|
-
set onSpatialMagnifyStart(value: ((event: SpatialMagnifyEvent) => void) | undefined);
|
|
190
185
|
private _onSpatialMagnify?;
|
|
191
186
|
set onSpatialMagnify(value: ((event: SpatialMagnifyEvent) => void) | undefined);
|
|
192
187
|
private _onSpatialMagnifyEnd?;
|
|
@@ -211,6 +206,12 @@ interface Vec3 {
|
|
|
211
206
|
z: number;
|
|
212
207
|
}
|
|
213
208
|
type Point3D = Vec3;
|
|
209
|
+
interface Quaternion {
|
|
210
|
+
x: number;
|
|
211
|
+
y: number;
|
|
212
|
+
z: number;
|
|
213
|
+
w: number;
|
|
214
|
+
}
|
|
214
215
|
/**
|
|
215
216
|
* Material type for SpatialDiv or HTML document.
|
|
216
217
|
*
|
|
@@ -259,10 +260,8 @@ interface SpatializedElementProperties {
|
|
|
259
260
|
enableDragStartGesture: boolean;
|
|
260
261
|
enableDragGesture: boolean;
|
|
261
262
|
enableDragEndGesture: boolean;
|
|
262
|
-
enableRotateStartGesture: boolean;
|
|
263
263
|
enableRotateGesture: boolean;
|
|
264
264
|
enableRotateEndGesture: boolean;
|
|
265
|
-
enableMagnifyStartGesture: boolean;
|
|
266
265
|
enableMagnifyGesture: boolean;
|
|
267
266
|
enableMagnifyEndGesture: boolean;
|
|
268
267
|
}
|
|
@@ -405,33 +404,31 @@ interface SpatialTapEventDetail {
|
|
|
405
404
|
location3D: Point3D;
|
|
406
405
|
}
|
|
407
406
|
type SpatialTapEvent = CustomEvent<SpatialTapEventDetail>;
|
|
408
|
-
interface
|
|
409
|
-
location3D: Point3D;
|
|
407
|
+
interface SpatialDragStartEventDetail {
|
|
410
408
|
startLocation3D: Point3D;
|
|
409
|
+
}
|
|
410
|
+
interface SpatialDragEventDetail {
|
|
411
411
|
translation3D: Vec3;
|
|
412
|
-
predictedEndTranslation3D: Vec3;
|
|
413
|
-
predictedEndLocation3D: Point3D;
|
|
414
|
-
velocity: Size;
|
|
415
412
|
}
|
|
413
|
+
interface SpatialDragEndEventDetail {
|
|
414
|
+
}
|
|
415
|
+
type SpatialDragStartEvent = CustomEvent<SpatialDragStartEventDetail>;
|
|
416
416
|
type SpatialDragEvent = CustomEvent<SpatialDragEventDetail>;
|
|
417
|
-
type SpatialDragEndEvent =
|
|
417
|
+
type SpatialDragEndEvent = CustomEvent<SpatialDragEndEventDetail>;
|
|
418
418
|
interface SpatialRotateEventDetail {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
startAnchor3D: Vec3;
|
|
423
|
-
startLocation3D: Point3D;
|
|
419
|
+
quaternion: Quaternion;
|
|
420
|
+
}
|
|
421
|
+
interface SpatialRotateEndEventDetail {
|
|
424
422
|
}
|
|
425
423
|
type SpatialRotateEvent = CustomEvent<SpatialRotateEventDetail>;
|
|
426
|
-
type SpatialRotateEndEvent =
|
|
424
|
+
type SpatialRotateEndEvent = CustomEvent<SpatialRotateEndEventDetail>;
|
|
427
425
|
interface SpatialMagnifyEventDetail {
|
|
428
426
|
magnification: number;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
startLocation3D: Point3D;
|
|
427
|
+
}
|
|
428
|
+
interface SpatialMagnifyEndEventDetail {
|
|
432
429
|
}
|
|
433
430
|
type SpatialMagnifyEvent = CustomEvent<SpatialMagnifyEventDetail>;
|
|
434
|
-
type SpatialMagnifyEndEvent =
|
|
431
|
+
type SpatialMagnifyEndEvent = CustomEvent<SpatialMagnifyEndEventDetail>;
|
|
435
432
|
type SpatialEntityOrReality = SpatialEntity | SpatializedDynamic3DElement;
|
|
436
433
|
|
|
437
434
|
declare class SpatialComponent extends SpatialObject {
|
|
@@ -670,7 +667,7 @@ declare class SpatializedStatic3DElement extends SpatializedElement {
|
|
|
670
667
|
* @param callback Function to call when the model fails to load
|
|
671
668
|
*/
|
|
672
669
|
set onLoadFailureCallback(callback: undefined | (() => void));
|
|
673
|
-
updateModelTransform(transform:
|
|
670
|
+
updateModelTransform(transform: DOMMatrixReadOnly): void;
|
|
674
671
|
}
|
|
675
672
|
|
|
676
673
|
/**
|
|
@@ -859,4 +856,4 @@ declare global {
|
|
|
859
856
|
|
|
860
857
|
declare const isSSREnv: () => boolean;
|
|
861
858
|
|
|
862
|
-
export { type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo$1 as CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, type Point3D, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEvent, type SpatialDragEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEvent, type SpatialRotateEventDetail, SpatialScene, type SpatialSceneCreationOptions$1 as SpatialSceneCreationOptions, type SpatialSceneProperties, SpatialSceneState$1 as SpatialSceneState, type SpatialSceneType$1 as SpatialSceneType, SpatialSceneValues, SpatialSession, SpatialSphereGeometry, type SpatialSphereGeometryOptions, type SpatialTapEvent, type SpatialTapEventDetail, SpatialUnlitMaterial, type SpatialUnlitMaterialOptions, Spatialized2DElement, type Spatialized2DElementProperties, SpatializedDynamic3DElement, SpatializedElement, type SpatializedElementProperties, SpatializedElementType, SpatializedStatic3DElement, type SpatializedStatic3DElementProperties, type Vec3, type WorldAlignmentType, WorldAlignmentValues, type WorldScalingType, WorldScalingValues, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
|
|
859
|
+
export { type BackgroundMaterialType, type BaseplateVisibilityType, BaseplateVisibilityValues, type CornerRadius, CubeInfo$1 as CubeInfo, type ModelAssetOptions, ModelComponent, type ModelComponentOptions, type Point3D, type Quaternion, type Size, type Size3D, Spatial, SpatialBoxGeometry, type SpatialBoxGeometryOptions, SpatialComponent, SpatialConeGeometry, type SpatialConeGeometryOptions, SpatialCylinderGeometry, type SpatialCylinderGeometryOptions, type SpatialDragEndEvent, type SpatialDragEndEventDetail, type SpatialDragEvent, type SpatialDragEventDetail, type SpatialDragStartEvent, type SpatialDragStartEventDetail, SpatialEntity, type SpatialEntityEventType, type SpatialEntityOrReality, type SpatialEntityProperties, type SpatialEntityUserData, SpatialGeometry, type SpatialGeometryOptions, type SpatialGeometryType, type SpatialMagnifyEndEvent, type SpatialMagnifyEndEventDetail, type SpatialMagnifyEvent, type SpatialMagnifyEventDetail, SpatialMaterial, type SpatialMaterialType, SpatialModelAsset, type SpatialModelDragEvent, SpatialModelEntity, type SpatialModelEntityCreationOptions, SpatialObject, SpatialPlaneGeometry, type SpatialPlaneGeometryOptions, type SpatialRotateEndEvent, type SpatialRotateEndEventDetail, type SpatialRotateEvent, type SpatialRotateEventDetail, SpatialScene, type SpatialSceneCreationOptions$1 as SpatialSceneCreationOptions, type SpatialSceneProperties, SpatialSceneState$1 as SpatialSceneState, type SpatialSceneType$1 as SpatialSceneType, SpatialSceneValues, SpatialSession, SpatialSphereGeometry, type SpatialSphereGeometryOptions, type SpatialTapEvent, type SpatialTapEventDetail, SpatialUnlitMaterial, type SpatialUnlitMaterialOptions, Spatialized2DElement, type Spatialized2DElementProperties, SpatializedDynamic3DElement, SpatializedElement, type SpatializedElementProperties, SpatializedElementType, SpatializedStatic3DElement, type SpatializedStatic3DElementProperties, type Vec3, type WorldAlignmentType, WorldAlignmentValues, type WorldScalingType, WorldScalingValues, isSSREnv, isValidBaseplateVisibilityType, isValidSceneUnit, isValidSpatialSceneType, isValidWorldAlignmentType, isValidWorldScalingType };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
(function(){
|
|
3
3
|
if(typeof window === 'undefined') return;
|
|
4
4
|
if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
|
|
5
|
-
window.__webspatialsdk__['core-sdk-version'] = "1.0
|
|
5
|
+
window.__webspatialsdk__['core-sdk-version'] = "1.2.0"
|
|
6
6
|
})()
|
|
7
7
|
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
@@ -115,16 +115,119 @@ var init_SpatialWebEvent = __esm({
|
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
+
// src/platform-adapter/xr/XRPlatform.ts
|
|
119
|
+
var XRPlatform_exports = {};
|
|
120
|
+
__export(XRPlatform_exports, {
|
|
121
|
+
XRPlatform: () => XRPlatform
|
|
122
|
+
});
|
|
123
|
+
function nextRequestId() {
|
|
124
|
+
requestId = (requestId + 1) % MAX_ID;
|
|
125
|
+
return `rId_${requestId}`;
|
|
126
|
+
}
|
|
127
|
+
var requestId, MAX_ID, XRPlatform;
|
|
128
|
+
var init_XRPlatform = __esm({
|
|
129
|
+
"src/platform-adapter/xr/XRPlatform.ts"() {
|
|
130
|
+
"use strict";
|
|
131
|
+
init_CommandResultUtils();
|
|
132
|
+
init_SpatialWebEvent();
|
|
133
|
+
requestId = 0;
|
|
134
|
+
MAX_ID = 1e5;
|
|
135
|
+
XRPlatform = class {
|
|
136
|
+
async callJSB(cmd, msg) {
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
try {
|
|
139
|
+
const rId = nextRequestId();
|
|
140
|
+
SpatialWebEvent.addEventReceiver(rId, (result) => {
|
|
141
|
+
SpatialWebEvent.removeEventReceiver(rId);
|
|
142
|
+
if (result.success) {
|
|
143
|
+
resolve(CommandResultSuccess(result.data));
|
|
144
|
+
} else {
|
|
145
|
+
const { code, message } = result.data;
|
|
146
|
+
resolve(CommandResultFailure(code, message));
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const ans = window.webspatialBridge.postMessage(rId, cmd, msg);
|
|
150
|
+
if (ans !== "") {
|
|
151
|
+
SpatialWebEvent.removeEventReceiver(rId);
|
|
152
|
+
const result = JSON.parse(ans);
|
|
153
|
+
if (result.success) {
|
|
154
|
+
resolve(CommandResultSuccess(result.data));
|
|
155
|
+
} else {
|
|
156
|
+
const { code, message } = result.data;
|
|
157
|
+
resolve(CommandResultFailure(code, message));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error(`XRPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
|
|
162
|
+
const { code, message } = error;
|
|
163
|
+
resolve(CommandResultFailure(code, message));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async callWebSpatialProtocol(command, query, target, features) {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
const createdId = nextRequestId();
|
|
170
|
+
try {
|
|
171
|
+
let windowProxy = null;
|
|
172
|
+
SpatialWebEvent.addEventReceiver(
|
|
173
|
+
createdId,
|
|
174
|
+
(result) => {
|
|
175
|
+
console.log("createdId", createdId, result.spatialId);
|
|
176
|
+
resolve(
|
|
177
|
+
CommandResultSuccess({
|
|
178
|
+
windowProxy,
|
|
179
|
+
id: result.spatialId
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
SpatialWebEvent.removeEventReceiver(createdId);
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
windowProxy = this.openWindow(
|
|
186
|
+
command,
|
|
187
|
+
query,
|
|
188
|
+
target,
|
|
189
|
+
features
|
|
190
|
+
).windowProxy;
|
|
191
|
+
windowProxy?.open(`about:blank?rid=${createdId}`, "_self");
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error(`open window error: ${error}`);
|
|
194
|
+
const { code, message } = error;
|
|
195
|
+
SpatialWebEvent.removeEventReceiver(createdId);
|
|
196
|
+
resolve(CommandResultFailure(code, message));
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
callWebSpatialProtocolSync(command, query, target, features) {
|
|
201
|
+
const { spatialId: id = "", windowProxy } = this.openWindow(
|
|
202
|
+
command,
|
|
203
|
+
query,
|
|
204
|
+
target,
|
|
205
|
+
features
|
|
206
|
+
);
|
|
207
|
+
return CommandResultSuccess({ windowProxy, id });
|
|
208
|
+
}
|
|
209
|
+
openWindow(command, query, target, features) {
|
|
210
|
+
const windowProxy = window.open(
|
|
211
|
+
`webspatial://${command}?${query || ""}`,
|
|
212
|
+
target,
|
|
213
|
+
features
|
|
214
|
+
);
|
|
215
|
+
return { spatialId: "", windowProxy };
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
118
221
|
// src/platform-adapter/android/AndroidPlatform.ts
|
|
119
222
|
var AndroidPlatform_exports = {};
|
|
120
223
|
__export(AndroidPlatform_exports, {
|
|
121
224
|
AndroidPlatform: () => AndroidPlatform
|
|
122
225
|
});
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
return `rId_${
|
|
226
|
+
function nextRequestId2() {
|
|
227
|
+
requestId2 = (requestId2 + 1) % MAX_ID2;
|
|
228
|
+
return `rId_${requestId2}`;
|
|
126
229
|
}
|
|
127
|
-
var creatingElementCount,
|
|
230
|
+
var creatingElementCount, requestId2, MAX_ID2, AndroidPlatform;
|
|
128
231
|
var init_AndroidPlatform = __esm({
|
|
129
232
|
"src/platform-adapter/android/AndroidPlatform.ts"() {
|
|
130
233
|
"use strict";
|
|
@@ -132,13 +235,13 @@ var init_AndroidPlatform = __esm({
|
|
|
132
235
|
init_JSBCommand();
|
|
133
236
|
init_SpatialWebEvent();
|
|
134
237
|
creatingElementCount = 0;
|
|
135
|
-
|
|
136
|
-
|
|
238
|
+
requestId2 = 0;
|
|
239
|
+
MAX_ID2 = 1e5;
|
|
137
240
|
AndroidPlatform = class {
|
|
138
241
|
async callJSB(cmd, msg) {
|
|
139
242
|
return new Promise((resolve, reject) => {
|
|
140
243
|
try {
|
|
141
|
-
const rId =
|
|
244
|
+
const rId = nextRequestId2();
|
|
142
245
|
SpatialWebEvent.addEventReceiver(rId, (result) => {
|
|
143
246
|
SpatialWebEvent.removeEventReceiver(rId);
|
|
144
247
|
if (result.success) {
|
|
@@ -181,10 +284,10 @@ var init_AndroidPlatform = __esm({
|
|
|
181
284
|
await new Promise((resolve) => setTimeout(resolve, 16));
|
|
182
285
|
}
|
|
183
286
|
windowProxy?.open("about:blank", "_self");
|
|
184
|
-
while (!windowProxy?.
|
|
287
|
+
while (!windowProxy?.__SpatialId) {
|
|
185
288
|
await new Promise((resolve) => setTimeout(resolve, 16));
|
|
186
289
|
}
|
|
187
|
-
let spatialId = windowProxy?.
|
|
290
|
+
let spatialId = windowProxy?.__SpatialId;
|
|
188
291
|
creatingElementCount--;
|
|
189
292
|
return Promise.resolve(
|
|
190
293
|
CommandResultSuccess({ windowProxy, id: spatialId })
|
|
@@ -270,11 +373,38 @@ var init_VisionOSPlatform = __esm({
|
|
|
270
373
|
});
|
|
271
374
|
|
|
272
375
|
// src/platform-adapter/index.ts
|
|
376
|
+
function getWebSpatialVersion(ua) {
|
|
377
|
+
const match = ua.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);
|
|
378
|
+
if (!match) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
382
|
+
}
|
|
383
|
+
function isVersionGreater(a, b) {
|
|
384
|
+
if (!a) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
for (let index = 0; index < 3; index += 1) {
|
|
388
|
+
const diff = a[index] - b[index];
|
|
389
|
+
if (diff > 0) {
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
if (diff < 0) {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
273
398
|
function createPlatform() {
|
|
274
399
|
if (isSSREnv()) {
|
|
275
400
|
return new SSRPlatform();
|
|
276
401
|
}
|
|
277
|
-
|
|
402
|
+
const userAgent = window.navigator.userAgent;
|
|
403
|
+
const webSpatialVersion = getWebSpatialVersion(userAgent);
|
|
404
|
+
if (userAgent.includes("PicoWebApp") && isVersionGreater(webSpatialVersion, [0, 0, 1])) {
|
|
405
|
+
const XRPlatform2 = (init_XRPlatform(), __toCommonJS(XRPlatform_exports)).XRPlatform;
|
|
406
|
+
return new XRPlatform2();
|
|
407
|
+
} else if (userAgent.includes("Android") || userAgent.includes("Linux")) {
|
|
278
408
|
const AndroidPlatform2 = (init_AndroidPlatform(), __toCommonJS(AndroidPlatform_exports)).AndroidPlatform;
|
|
279
409
|
return new AndroidPlatform2();
|
|
280
410
|
} else {
|
|
@@ -997,14 +1127,29 @@ var SceneManager = class _SceneManager {
|
|
|
997
1127
|
if (name === void 0 || !this.configMap[name]) return void 0;
|
|
998
1128
|
return this.configMap[name];
|
|
999
1129
|
}
|
|
1130
|
+
// Ensure URL is absolute; only convert when a relative path is provided
|
|
1131
|
+
// - Keep external and special schemes untouched (http, https, data, blob, about, file, mailto, etc.)
|
|
1132
|
+
// - Handle protocol-relative URLs (//example.com/path)
|
|
1133
|
+
// - Resolve relative paths against document.baseURI (respects <base href>)
|
|
1134
|
+
ensureAbsoluteUrl(raw) {
|
|
1135
|
+
if (!raw) return raw;
|
|
1136
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(raw)) {
|
|
1137
|
+
return raw;
|
|
1138
|
+
}
|
|
1139
|
+
if (raw.startsWith("//")) {
|
|
1140
|
+
return `${window.location.protocol}${raw}`;
|
|
1141
|
+
}
|
|
1142
|
+
try {
|
|
1143
|
+
return new URL(raw, document.baseURI).toString();
|
|
1144
|
+
} catch {
|
|
1145
|
+
return raw;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1000
1148
|
open = (url, target, features) => {
|
|
1001
1149
|
if (url?.startsWith(INTERNAL_SCHEMA_PREFIX)) {
|
|
1002
1150
|
return this.originalOpen(url, target, features);
|
|
1003
1151
|
}
|
|
1004
|
-
|
|
1005
|
-
if (!url?.startsWith(prefix)) {
|
|
1006
|
-
url = prefix + url;
|
|
1007
|
-
}
|
|
1152
|
+
url = this.ensureAbsoluteUrl(url);
|
|
1008
1153
|
if (target === "_self" || target === "_parent" || target === "_top") {
|
|
1009
1154
|
const newWindow = this.originalOpen(url, target, features);
|
|
1010
1155
|
return newWindow;
|
|
@@ -1012,9 +1157,6 @@ var SceneManager = class _SceneManager {
|
|
|
1012
1157
|
const cfg = target ? this.getConfig(target) : void 0;
|
|
1013
1158
|
const cmd = new createSpatialSceneCommand(url, cfg, target, features);
|
|
1014
1159
|
const result = cmd.executeSync();
|
|
1015
|
-
if (typeof target === "string" && this.configMap[target]) {
|
|
1016
|
-
delete this.configMap[target];
|
|
1017
|
-
}
|
|
1018
1160
|
const id = result.data?.id;
|
|
1019
1161
|
if (id) {
|
|
1020
1162
|
let focusCmd = new FocusScene(id);
|
|
@@ -1338,64 +1480,43 @@ var SpatializedElement = class extends SpatialObject {
|
|
|
1338
1480
|
data.detail
|
|
1339
1481
|
);
|
|
1340
1482
|
this._onSpatialTap?.(event);
|
|
1483
|
+
} else if (type === "spatialdragstart" /* spatialdragstart */) {
|
|
1484
|
+
const dragStartEvent = createSpatialEvent(
|
|
1485
|
+
"spatialdragstart" /* spatialdragstart */,
|
|
1486
|
+
data.detail
|
|
1487
|
+
);
|
|
1488
|
+
this._onSpatialDragStart?.(dragStartEvent);
|
|
1341
1489
|
} else if (type === "spatialdrag" /* spatialdrag */) {
|
|
1342
|
-
if (!this._isDragging) {
|
|
1343
|
-
const dragStartEvent = createSpatialEvent(
|
|
1344
|
-
"spatialdragstart" /* spatialdragstart */,
|
|
1345
|
-
data.detail
|
|
1346
|
-
);
|
|
1347
|
-
this._onSpatialDragStart?.(dragStartEvent);
|
|
1348
|
-
}
|
|
1349
|
-
this._isDragging = true;
|
|
1350
1490
|
const event = createSpatialEvent(
|
|
1351
1491
|
"spatialdrag" /* spatialdrag */,
|
|
1352
1492
|
data.detail
|
|
1353
1493
|
);
|
|
1354
1494
|
this._onSpatialDrag?.(event);
|
|
1355
1495
|
} else if (type === "spatialdragend" /* spatialdragend */) {
|
|
1356
|
-
this._isDragging = false;
|
|
1357
1496
|
const event = createSpatialEvent(
|
|
1358
1497
|
"spatialdragend" /* spatialdragend */,
|
|
1359
1498
|
data.detail
|
|
1360
1499
|
);
|
|
1361
1500
|
this._onSpatialDragEnd?.(event);
|
|
1362
1501
|
} else if (type === "spatialrotate" /* spatialrotate */) {
|
|
1363
|
-
if (!this._isRotating) {
|
|
1364
|
-
const rotationStartEvent = createSpatialEvent(
|
|
1365
|
-
"spatialrotatestart" /* spatialrotatestart */,
|
|
1366
|
-
data.detail
|
|
1367
|
-
);
|
|
1368
|
-
this._onSpatialRotateStart?.(rotationStartEvent);
|
|
1369
|
-
}
|
|
1370
|
-
this._isRotating = true;
|
|
1371
1502
|
const event = createSpatialEvent(
|
|
1372
1503
|
"spatialrotate" /* spatialrotate */,
|
|
1373
1504
|
data.detail
|
|
1374
1505
|
);
|
|
1375
1506
|
this._onSpatialRotate?.(event);
|
|
1376
1507
|
} else if (type === "spatialrotateend" /* spatialrotateend */) {
|
|
1377
|
-
this._isRotating = false;
|
|
1378
1508
|
const event = createSpatialEvent(
|
|
1379
1509
|
"spatialrotateend" /* spatialrotateend */,
|
|
1380
1510
|
data.detail
|
|
1381
1511
|
);
|
|
1382
1512
|
this._onSpatialRotateEnd?.(event);
|
|
1383
1513
|
} else if (type === "spatialmagnify" /* spatialmagnify */) {
|
|
1384
|
-
if (!this._isMagnify) {
|
|
1385
|
-
const magnifyStartEvent = createSpatialEvent(
|
|
1386
|
-
"spatialmagnifystart" /* spatialmagnifystart */,
|
|
1387
|
-
data.detail
|
|
1388
|
-
);
|
|
1389
|
-
this._onSpatialMagnifyStart?.(magnifyStartEvent);
|
|
1390
|
-
}
|
|
1391
|
-
this._isMagnify = true;
|
|
1392
1514
|
const event = createSpatialEvent(
|
|
1393
1515
|
"spatialmagnify" /* spatialmagnify */,
|
|
1394
1516
|
data.detail
|
|
1395
1517
|
);
|
|
1396
1518
|
this._onSpatialMagnify?.(event);
|
|
1397
1519
|
} else if (type === "spatialmagnifyend" /* spatialmagnifyend */) {
|
|
1398
|
-
this._isMagnify = false;
|
|
1399
1520
|
const event = createSpatialEvent(
|
|
1400
1521
|
"spatialmagnifyend" /* spatialmagnifyend */,
|
|
1401
1522
|
data.detail
|
|
@@ -1410,7 +1531,6 @@ var SpatializedElement = class extends SpatialObject {
|
|
|
1410
1531
|
enableTapGesture: value !== void 0
|
|
1411
1532
|
});
|
|
1412
1533
|
}
|
|
1413
|
-
_isDragging = false;
|
|
1414
1534
|
_onSpatialDragStart;
|
|
1415
1535
|
set onSpatialDragStart(value) {
|
|
1416
1536
|
this._onSpatialDragStart = value;
|
|
@@ -1432,14 +1552,6 @@ var SpatializedElement = class extends SpatialObject {
|
|
|
1432
1552
|
enableDragEndGesture: value !== void 0
|
|
1433
1553
|
});
|
|
1434
1554
|
}
|
|
1435
|
-
_isRotating = false;
|
|
1436
|
-
_onSpatialRotateStart;
|
|
1437
|
-
set onSpatialRotateStart(value) {
|
|
1438
|
-
this._onSpatialRotateStart = value;
|
|
1439
|
-
this.updateProperties({
|
|
1440
|
-
enableRotateStartGesture: this._onSpatialRotateStart !== void 0
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
1555
|
_onSpatialRotate;
|
|
1444
1556
|
set onSpatialRotate(value) {
|
|
1445
1557
|
this._onSpatialRotate = value;
|
|
@@ -1454,14 +1566,6 @@ var SpatializedElement = class extends SpatialObject {
|
|
|
1454
1566
|
enableRotateEndGesture: value !== void 0
|
|
1455
1567
|
});
|
|
1456
1568
|
}
|
|
1457
|
-
_isMagnify = false;
|
|
1458
|
-
_onSpatialMagnifyStart;
|
|
1459
|
-
set onSpatialMagnifyStart(value) {
|
|
1460
|
-
this._onSpatialMagnifyStart = value;
|
|
1461
|
-
this.updateProperties({
|
|
1462
|
-
enableMagnifyStartGesture: value !== void 0
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
1569
|
_onSpatialMagnify;
|
|
1466
1570
|
set onSpatialMagnify(value) {
|
|
1467
1571
|
this._onSpatialMagnify = value;
|
|
@@ -1772,12 +1876,6 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
|
|
|
1772
1876
|
data.detail
|
|
1773
1877
|
);
|
|
1774
1878
|
this.dispatchEvent(evt);
|
|
1775
|
-
} else if (type === "spatialrotatestart" /* spatialrotatestart */) {
|
|
1776
|
-
const evt = createSpatialEvent(
|
|
1777
|
-
"spatialrotatestart" /* spatialrotatestart */,
|
|
1778
|
-
data.detail
|
|
1779
|
-
);
|
|
1780
|
-
this.dispatchEvent(evt);
|
|
1781
1879
|
} else if (type === "spatialrotate" /* spatialrotate */) {
|
|
1782
1880
|
const evt = createSpatialEvent(
|
|
1783
1881
|
"spatialrotate" /* spatialrotate */,
|
|
@@ -1790,12 +1888,6 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
|
|
|
1790
1888
|
data.detail
|
|
1791
1889
|
);
|
|
1792
1890
|
this.dispatchEvent(evt);
|
|
1793
|
-
} else if (type === "spatialmagnifystart" /* spatialmagnifystart */) {
|
|
1794
|
-
const evt = createSpatialEvent(
|
|
1795
|
-
"spatialmagnifystart" /* spatialmagnifystart */,
|
|
1796
|
-
data.detail
|
|
1797
|
-
);
|
|
1798
|
-
this.dispatchEvent(evt);
|
|
1799
1891
|
} else if (type === "spatialmagnify" /* spatialmagnify */) {
|
|
1800
1892
|
const evt = createSpatialEvent(
|
|
1801
1893
|
"spatialmagnify" /* spatialmagnify */,
|
|
@@ -1811,6 +1903,9 @@ var SpatialEntity = class _SpatialEntity extends SpatialObject {
|
|
|
1811
1903
|
}
|
|
1812
1904
|
};
|
|
1813
1905
|
dispatchEvent(evt) {
|
|
1906
|
+
if (!evt.__origin) {
|
|
1907
|
+
Object.defineProperty(evt, "__origin", { value: this, enumerable: false });
|
|
1908
|
+
}
|
|
1814
1909
|
this.events[evt.type]?.(evt);
|
|
1815
1910
|
if (evt.bubbles && !evt.cancelBubble) {
|
|
1816
1911
|
if (this.parent && this.parent instanceof _SpatialEntity) {
|
|
@@ -2217,7 +2312,7 @@ var Spatial = class {
|
|
|
2217
2312
|
* @returns Client SDK version string in format "x.x.x"
|
|
2218
2313
|
*/
|
|
2219
2314
|
getClientVersion() {
|
|
2220
|
-
return "1.0
|
|
2315
|
+
return "1.2.0";
|
|
2221
2316
|
}
|
|
2222
2317
|
};
|
|
2223
2318
|
|