@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
package/dist/index.js
CHANGED
|
@@ -1,3662 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const pico = /\bPicoWebApp\/([\w.-]+)/i.exec(ua);
|
|
19
|
-
if (pico?.[1]) return { version: pico[1], source: "picoapp" };
|
|
20
|
-
return { version: null, source: null };
|
|
21
|
-
}
|
|
22
|
-
function inferPicoOs(ua) {
|
|
23
|
-
return /\bPicoWebApp\//i.test(ua) || /\bPicoBrowser\b/i.test(ua);
|
|
24
|
-
}
|
|
25
|
-
function inferVisionOsFromUa(ua) {
|
|
26
|
-
return /Mac OS X/i.test(ua);
|
|
27
|
-
}
|
|
28
|
-
function computeRuntimeFromUserAgent(userAgent) {
|
|
29
|
-
if (userAgent === void 0 || userAgent === "") {
|
|
30
|
-
return { type: null, shellVersion: null };
|
|
31
|
-
}
|
|
32
|
-
if (userAgent.includes("Puppeteer")) {
|
|
33
|
-
const { version: version2 } = parseShellToken(userAgent);
|
|
34
|
-
return { type: "puppeteer", shellVersion: version2 };
|
|
35
|
-
}
|
|
36
|
-
const { version, source } = parseShellToken(userAgent);
|
|
37
|
-
if (!version) {
|
|
38
|
-
return { type: null, shellVersion: null };
|
|
39
|
-
}
|
|
40
|
-
if (source === "picoapp" || inferPicoOs(userAgent)) {
|
|
41
|
-
return { type: "picoos", shellVersion: version };
|
|
42
|
-
}
|
|
43
|
-
if (source === "wsapp") {
|
|
44
|
-
if (inferVisionOsFromUa(userAgent)) {
|
|
45
|
-
return { type: "visionos", shellVersion: version };
|
|
46
|
-
}
|
|
47
|
-
return { type: null, shellVersion: version };
|
|
48
|
-
}
|
|
49
|
-
return { type: null, shellVersion: version };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/runtime/jsbAdapterPlatform.ts
|
|
53
|
-
function getWebSpatialVersion(ua) {
|
|
54
|
-
const match = ua.match(/WebSpatial\/(\d+)\.(\d+)\.(\d+)/);
|
|
55
|
-
if (!match) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
59
|
-
}
|
|
60
|
-
function isVersionGreater(a, b) {
|
|
61
|
-
if (!a) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
for (let index = 0; index < 3; index += 1) {
|
|
65
|
-
const diff = a[index] - b[index];
|
|
66
|
-
if (diff > 0) {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
if (diff < 0) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
function resolveJsbAdapterPlatform(userAgent) {
|
|
76
|
-
const rt = computeRuntimeFromUserAgent(userAgent);
|
|
77
|
-
if (rt.type === "puppeteer") {
|
|
78
|
-
return "puppeteer";
|
|
79
|
-
}
|
|
80
|
-
const webSpatialVersion = getWebSpatialVersion(userAgent);
|
|
81
|
-
if (userAgent.includes("PicoWebApp") && isVersionGreater(webSpatialVersion, [0, 0, 1])) {
|
|
82
|
-
return "picoos";
|
|
83
|
-
}
|
|
84
|
-
return "visionos";
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// src/ssr-polyfill.ts
|
|
88
|
-
var isSSR = typeof window === "undefined";
|
|
89
|
-
var isSSREnv = () => isSSR;
|
|
90
|
-
|
|
91
|
-
// src/platform-adapter/CommandResultUtils.ts
|
|
92
|
-
function CommandResultSuccess(data) {
|
|
93
|
-
return {
|
|
94
|
-
success: true,
|
|
95
|
-
data,
|
|
96
|
-
errorCode: "",
|
|
97
|
-
errorMessage: ""
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function CommandResultFailure(errorCode, errorMessage = "") {
|
|
101
|
-
return {
|
|
102
|
-
success: false,
|
|
103
|
-
data: void 0,
|
|
104
|
-
errorCode,
|
|
105
|
-
errorMessage
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/platform-adapter/spatialSceneQuery.ts
|
|
110
|
-
function buildSpatialSceneQuery(url, config) {
|
|
111
|
-
const params = { url, config };
|
|
112
|
-
return Object.keys(params).map((key) => {
|
|
113
|
-
const value = params[key];
|
|
114
|
-
const finalValue = typeof value === "object" ? JSON.stringify(value) : value;
|
|
115
|
-
return `${key}=${encodeURIComponent(finalValue)}`;
|
|
116
|
-
}).join("&");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/SpatialWebEvent.ts
|
|
120
|
-
var SpatialWebEvent = class _SpatialWebEvent {
|
|
121
|
-
static eventReceiver = {};
|
|
122
|
-
static init() {
|
|
123
|
-
window.__SpatialWebEvent = ({ id, data }) => {
|
|
124
|
-
_SpatialWebEvent.eventReceiver[id]?.(data);
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
static addEventReceiver(id, callback) {
|
|
128
|
-
_SpatialWebEvent.eventReceiver[id] = callback;
|
|
129
|
-
}
|
|
130
|
-
static removeEventReceiver(id) {
|
|
131
|
-
delete _SpatialWebEvent.eventReceiver[id];
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/platform-adapter/pico-os/PicoOSPlatform.ts
|
|
136
|
-
var requestId = 0;
|
|
137
|
-
var MAX_ID = 1e5;
|
|
138
|
-
var DEFAULT_JSB_ERROR_CODE = "E_PICO_JSB";
|
|
139
|
-
var DEFAULT_JSB_ERROR_MESSAGE = "Pico JSB execution failed";
|
|
140
|
-
function nextRequestId() {
|
|
141
|
-
requestId = (requestId + 1) % MAX_ID;
|
|
142
|
-
return `rId_${requestId}`;
|
|
143
|
-
}
|
|
144
|
-
var PicoOSPlatform = class {
|
|
145
|
-
async callJSB(cmd, msg) {
|
|
146
|
-
return new Promise((resolve) => {
|
|
147
|
-
try {
|
|
148
|
-
const rId = nextRequestId();
|
|
149
|
-
SpatialWebEvent.addEventReceiver(rId, (result) => {
|
|
150
|
-
SpatialWebEvent.removeEventReceiver(rId);
|
|
151
|
-
resolve(this.toCommandResult(result));
|
|
152
|
-
});
|
|
153
|
-
const ans = window.webspatialBridge.postMessage(rId, cmd, msg);
|
|
154
|
-
if (ans !== "") {
|
|
155
|
-
SpatialWebEvent.removeEventReceiver(rId);
|
|
156
|
-
resolve(this.parseBridgeResponse(ans));
|
|
157
|
-
}
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
|
|
160
|
-
const { code, message } = this.parseJSBError(error);
|
|
161
|
-
resolve(CommandResultFailure(code, message));
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
openSpatialSceneSync(url, config, target, features) {
|
|
166
|
-
const query = buildSpatialSceneQuery(url, config);
|
|
167
|
-
const { spatialId: id = "", windowProxy } = this.openWindow(
|
|
168
|
-
"createSpatialScene",
|
|
169
|
-
query,
|
|
170
|
-
target,
|
|
171
|
-
features
|
|
172
|
-
);
|
|
173
|
-
return CommandResultSuccess({ windowProxy, id });
|
|
174
|
-
}
|
|
175
|
-
createNativeSpatialDiv() {
|
|
176
|
-
return this.waitForRidProtocolAsync("createSpatialized2DElement");
|
|
177
|
-
}
|
|
178
|
-
createNativeAttachment(_options) {
|
|
179
|
-
return this.waitForRidProtocolAsync("createAttachment");
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Async path for createNativeSpatialDiv / createNativeAttachment: open webspatial URL
|
|
183
|
-
* with rid= correlation (Pico OS 6).
|
|
184
|
-
*/
|
|
185
|
-
waitForRidProtocolAsync(command) {
|
|
186
|
-
return new Promise((resolve) => {
|
|
187
|
-
const createdId = nextRequestId();
|
|
188
|
-
try {
|
|
189
|
-
let windowProxy = null;
|
|
190
|
-
SpatialWebEvent.addEventReceiver(
|
|
191
|
-
createdId,
|
|
192
|
-
(result) => {
|
|
193
|
-
resolve(
|
|
194
|
-
CommandResultSuccess({
|
|
195
|
-
windowProxy,
|
|
196
|
-
id: result.spatialId
|
|
197
|
-
})
|
|
198
|
-
);
|
|
199
|
-
SpatialWebEvent.removeEventReceiver(createdId);
|
|
200
|
-
}
|
|
201
|
-
);
|
|
202
|
-
windowProxy = this.openWindow(command, "rid=" + createdId).windowProxy;
|
|
203
|
-
} catch (error) {
|
|
204
|
-
const { code, message } = this.parseJSBError(error);
|
|
205
|
-
SpatialWebEvent.removeEventReceiver(createdId);
|
|
206
|
-
resolve(CommandResultFailure(code, message));
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
openWindow(command, query, target, features) {
|
|
211
|
-
const url = query ? `webspatial://${command}?${query}` : `webspatial://${command}`;
|
|
212
|
-
const windowProxy = window.open(url, target, features);
|
|
213
|
-
return { spatialId: "", windowProxy };
|
|
214
|
-
}
|
|
215
|
-
parseBridgeResponse(ans) {
|
|
216
|
-
try {
|
|
217
|
-
const result = JSON.parse(ans);
|
|
218
|
-
return this.toCommandResult(result);
|
|
219
|
-
} catch {
|
|
220
|
-
return CommandResultFailure(
|
|
221
|
-
DEFAULT_JSB_ERROR_CODE,
|
|
222
|
-
"Invalid Pico JSB response payload"
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
toCommandResult(result) {
|
|
227
|
-
if (result.success) {
|
|
228
|
-
return CommandResultSuccess(result.data);
|
|
229
|
-
}
|
|
230
|
-
const { code, message } = this.parseJSBError(result.data);
|
|
231
|
-
return CommandResultFailure(code, message);
|
|
232
|
-
}
|
|
233
|
-
parseJSBError(error) {
|
|
234
|
-
return {
|
|
235
|
-
code: error?.code ?? DEFAULT_JSB_ERROR_CODE,
|
|
236
|
-
message: error?.message ?? (typeof error === "string" ? error : DEFAULT_JSB_ERROR_MESSAGE)
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// src/platform-adapter/puppeteer/PuppeteerPlatform.ts
|
|
242
|
-
var PuppeteerPlatform = class {
|
|
243
|
-
// store iframe instance
|
|
244
|
-
iframeRegistry = /* @__PURE__ */ new Map();
|
|
245
|
-
constructor() {
|
|
246
|
-
}
|
|
247
|
-
callJSB(cmd, msg) {
|
|
248
|
-
return new Promise((resolve) => {
|
|
249
|
-
try {
|
|
250
|
-
if (window.__handleJSBMessage) {
|
|
251
|
-
try {
|
|
252
|
-
console.log(` core-sdk Puppeteer Platform: callJSB: ${cmd}::${msg}`);
|
|
253
|
-
const result = window.__handleJSBMessage(`${cmd}::${msg}`);
|
|
254
|
-
console.log(
|
|
255
|
-
` core-sdk Puppeteer Platform callJSB result: ${result}`
|
|
256
|
-
);
|
|
257
|
-
resolve(CommandResultSuccess(result));
|
|
258
|
-
} catch (err) {
|
|
259
|
-
resolve(CommandResultFailure("500", "JSB execution error"));
|
|
260
|
-
}
|
|
261
|
-
} else {
|
|
262
|
-
resolve(CommandResultSuccess("ok"));
|
|
263
|
-
}
|
|
264
|
-
} catch (error) {
|
|
265
|
-
console.error(
|
|
266
|
-
`PuppeteerPlatform cmd Error: ${cmd}, msg: ${msg} error: ${error}`
|
|
267
|
-
);
|
|
268
|
-
resolve(CommandResultFailure("500", "Internal error"));
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Synchronously create Spatialized2DElement to Puppeteer Runner
|
|
274
|
-
*/
|
|
275
|
-
createSpatializedElementSync(spatialId, webspatialUrl) {
|
|
276
|
-
try {
|
|
277
|
-
console.log(
|
|
278
|
-
`[Puppeteer Platform] Creating spatialized element sync with id: ${spatialId}, url: ${webspatialUrl}`
|
|
279
|
-
);
|
|
280
|
-
const win = window;
|
|
281
|
-
if (win.__handleJSBMessage) {
|
|
282
|
-
const createCommand = {
|
|
283
|
-
id: spatialId,
|
|
284
|
-
url: webspatialUrl
|
|
285
|
-
};
|
|
286
|
-
win.__handleJSBMessage(
|
|
287
|
-
`CreateSpatialized2DElement::${JSON.stringify(createCommand)}`
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
} catch (error) {
|
|
291
|
-
console.error("Error creating spatialized element sync:", error);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
openSpatialSceneSync(url, config, target, features) {
|
|
295
|
-
const query = buildSpatialSceneQuery(url, config);
|
|
296
|
-
return this.runProtocolSync("createSpatialScene", query, target, features);
|
|
297
|
-
}
|
|
298
|
-
createNativeSpatialDiv() {
|
|
299
|
-
return this.runProtocolAsync(
|
|
300
|
-
"createSpatialized2DElement",
|
|
301
|
-
"",
|
|
302
|
-
void 0,
|
|
303
|
-
void 0
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
createNativeAttachment(_options) {
|
|
307
|
-
return this.runProtocolAsync("createAttachment", "", void 0, void 0);
|
|
308
|
-
}
|
|
309
|
-
runProtocolAsync(command, query, target, features) {
|
|
310
|
-
console.log(
|
|
311
|
-
`PuppeteerPlatform: Calling webspatial protocol: webspatial://${command}${query ? `?${query}` : ""}`
|
|
312
|
-
);
|
|
313
|
-
return new Promise((resolve) => {
|
|
314
|
-
try {
|
|
315
|
-
const webspatialUrl = `webspatial://${command}${query ? `?${query}` : ""}`;
|
|
316
|
-
const { spatialId, iframe, windowProxy } = this.createIframeWindow(
|
|
317
|
-
webspatialUrl,
|
|
318
|
-
target,
|
|
319
|
-
features
|
|
320
|
-
);
|
|
321
|
-
if (command === "createSpatialized2DElement") {
|
|
322
|
-
this.createSpatializedElementSync(spatialId, webspatialUrl);
|
|
323
|
-
}
|
|
324
|
-
console.log(
|
|
325
|
-
`[Puppeteer Platform] iframe created with spatialId: ${spatialId}`
|
|
326
|
-
);
|
|
327
|
-
this.iframeRegistry.set(spatialId, iframe);
|
|
328
|
-
resolve(CommandResultSuccess({ windowProxy, id: spatialId }));
|
|
329
|
-
} catch (error) {
|
|
330
|
-
console.error("Error calling webspatial protocol:", error);
|
|
331
|
-
resolve(
|
|
332
|
-
CommandResultFailure("500", "Failed to call webspatial protocol")
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
runProtocolSync(command, query, target, features) {
|
|
338
|
-
try {
|
|
339
|
-
const webspatialUrl = `webspatial://${command}${query ? `?${query}` : ""}`;
|
|
340
|
-
console.log(`Calling webspatial protocol sync: ${webspatialUrl}`);
|
|
341
|
-
const { spatialId, iframe, windowProxy } = this.createIframeWindow(
|
|
342
|
-
webspatialUrl,
|
|
343
|
-
target,
|
|
344
|
-
features
|
|
345
|
-
);
|
|
346
|
-
if (command === "createSpatialized2DElement") {
|
|
347
|
-
this.createSpatializedElementSync(spatialId, webspatialUrl);
|
|
348
|
-
}
|
|
349
|
-
this.iframeRegistry.set(spatialId, iframe);
|
|
350
|
-
return CommandResultSuccess({ windowProxy, id: spatialId });
|
|
351
|
-
} catch (error) {
|
|
352
|
-
console.error("Error calling webspatial protocol sync:", error);
|
|
353
|
-
return CommandResultFailure(
|
|
354
|
-
"500",
|
|
355
|
-
"Failed to call webspatial protocol sync"
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
/**
|
|
360
|
-
* Synchronously create iframe-based window
|
|
361
|
-
*/
|
|
362
|
-
createIframeWindow(url, target, features) {
|
|
363
|
-
const iframe = document.createElement("iframe");
|
|
364
|
-
iframe.style.border = "none";
|
|
365
|
-
iframe.style.display = "none";
|
|
366
|
-
iframe.style.width = "100%";
|
|
367
|
-
iframe.style.height = "100%";
|
|
368
|
-
const spatialId = this.generateUUID();
|
|
369
|
-
iframe.spatialId = spatialId;
|
|
370
|
-
iframe.id = `spatial-iframe-${spatialId}`;
|
|
371
|
-
const featuresObj = this.parseFeatures(features || "");
|
|
372
|
-
if (featuresObj.width) {
|
|
373
|
-
iframe.style.width = featuresObj.width;
|
|
374
|
-
}
|
|
375
|
-
if (featuresObj.height) {
|
|
376
|
-
iframe.style.height = featuresObj.height;
|
|
377
|
-
}
|
|
378
|
-
if (featuresObj.left) {
|
|
379
|
-
iframe.style.left = featuresObj.left;
|
|
380
|
-
iframe.style.position = "absolute";
|
|
381
|
-
}
|
|
382
|
-
if (featuresObj.top) {
|
|
383
|
-
iframe.style.top = featuresObj.top;
|
|
384
|
-
iframe.style.position = "absolute";
|
|
385
|
-
}
|
|
386
|
-
document.body.appendChild(iframe);
|
|
387
|
-
const windowProxy = this.createEnhancedWindowProxy(iframe, url, spatialId);
|
|
388
|
-
iframe.src = "about:blank";
|
|
389
|
-
console.log(
|
|
390
|
-
`PuppeteerPlatform created iframe window with spatialId: ${spatialId}, URL: ${url}`
|
|
391
|
-
);
|
|
392
|
-
this.initializeIframeContent(iframe, url, spatialId);
|
|
393
|
-
return { spatialId, iframe, windowProxy };
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* create enhanced windowProxy object
|
|
397
|
-
*/
|
|
398
|
-
createEnhancedWindowProxy(iframe, url, spatialId) {
|
|
399
|
-
return {
|
|
400
|
-
// basic properties
|
|
401
|
-
location: {
|
|
402
|
-
href: url,
|
|
403
|
-
toString: () => url,
|
|
404
|
-
reload: () => {
|
|
405
|
-
if (iframe.contentWindow) {
|
|
406
|
-
iframe.contentWindow.location.reload();
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
navigator: {
|
|
411
|
-
userAgent: `Mozilla/5.0 (WebKit) SpatialId/${spatialId}`
|
|
412
|
-
},
|
|
413
|
-
// methods
|
|
414
|
-
close: () => {
|
|
415
|
-
console.log(`Closing iframe with spatialId: ${spatialId}`);
|
|
416
|
-
iframe.remove();
|
|
417
|
-
this.iframeRegistry.delete(spatialId);
|
|
418
|
-
},
|
|
419
|
-
// document access
|
|
420
|
-
document: iframe.contentDocument || {},
|
|
421
|
-
contentWindow: iframe.contentWindow || {},
|
|
422
|
-
// add message communication method
|
|
423
|
-
postMessage: (message, targetOrigin) => {
|
|
424
|
-
if (iframe.contentWindow) {
|
|
425
|
-
iframe.contentWindow.postMessage(message, targetOrigin || "*");
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
// add event listener method
|
|
429
|
-
addEventListener: (type, listener) => {
|
|
430
|
-
if (iframe.contentWindow) {
|
|
431
|
-
iframe.contentWindow.addEventListener(type, listener);
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
removeEventListener: (type, listener) => {
|
|
435
|
-
if (iframe.contentWindow) {
|
|
436
|
-
iframe.contentWindow.removeEventListener(type, listener);
|
|
437
|
-
}
|
|
438
|
-
},
|
|
439
|
-
// execute JavaScript
|
|
440
|
-
executeScript: (code) => {
|
|
441
|
-
if (iframe.contentWindow) {
|
|
442
|
-
try {
|
|
443
|
-
const win = iframe.contentWindow;
|
|
444
|
-
return win.eval(code);
|
|
445
|
-
} catch (error) {
|
|
446
|
-
console.error(
|
|
447
|
-
`Error executing script in iframe ${spatialId}:`,
|
|
448
|
-
error
|
|
449
|
-
);
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return null;
|
|
454
|
-
},
|
|
455
|
-
// get iframe reference
|
|
456
|
-
getIframe: () => iframe,
|
|
457
|
-
// get spatialId
|
|
458
|
-
getSpatialId: () => spatialId
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* initialize iframe content
|
|
463
|
-
*/
|
|
464
|
-
initializeIframeContent(iframe, url, spatialId) {
|
|
465
|
-
try {
|
|
466
|
-
iframe.onload = () => {
|
|
467
|
-
try {
|
|
468
|
-
const iframeContent = `
|
|
469
|
-
// inject communication script
|
|
470
|
-
window.webSpatialId = '${spatialId}';
|
|
471
|
-
window.SpatialId = '${spatialId}';
|
|
472
|
-
|
|
473
|
-
// override window.open to support webspatial protocol
|
|
474
|
-
const originalOpen = window.open;
|
|
475
|
-
window.open = function(url, target, features) {
|
|
476
|
-
if (url && url.startsWith('webspatial://')) {
|
|
477
|
-
// handle webspatial protocol through windowProxy
|
|
478
|
-
const windowProxy = new Proxy({}, {
|
|
479
|
-
get: function(target, prop) {
|
|
480
|
-
if (prop === 'toString') {
|
|
481
|
-
return function() { return url; };
|
|
482
|
-
}
|
|
483
|
-
return undefined;
|
|
484
|
-
}
|
|
485
|
-
});
|
|
486
|
-
return windowProxy;
|
|
487
|
-
}
|
|
488
|
-
return originalOpen.call(window, url, target, features);
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
// set navigator.userAgent to identify webspatial environment
|
|
492
|
-
Object.defineProperty(navigator, 'userAgent', {
|
|
493
|
-
value: 'WebSpatial/1.0 ' + navigator.userAgent,
|
|
494
|
-
configurable: true
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
// send loaded message
|
|
498
|
-
window.parent.postMessage({
|
|
499
|
-
type: 'iframe_loaded',
|
|
500
|
-
spatialId: '${spatialId}',
|
|
501
|
-
url: '${url}'
|
|
502
|
-
}, '${window.location.origin}');
|
|
503
|
-
|
|
504
|
-
// set message handler
|
|
505
|
-
window.addEventListener('message', (event) => {
|
|
506
|
-
if (event.origin !== window.parent.location.origin) return;
|
|
507
|
-
|
|
508
|
-
const data = event.data;
|
|
509
|
-
if (data && data.type === 'webspatial_command') {
|
|
510
|
-
// handle command from parent window
|
|
511
|
-
console.log('Received command in iframe from parent:', data.command);
|
|
512
|
-
// add command handling logic here
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
`;
|
|
516
|
-
const doc = iframe.contentDocument;
|
|
517
|
-
if (doc) {
|
|
518
|
-
doc.open();
|
|
519
|
-
doc.write(`
|
|
520
|
-
<!DOCTYPE html>
|
|
521
|
-
<html>
|
|
522
|
-
<head>
|
|
523
|
-
<title>Spatial Iframe - ${spatialId}</title>
|
|
524
|
-
<meta charset="UTF-8">
|
|
525
|
-
<style>
|
|
526
|
-
body {
|
|
527
|
-
margin: 0;
|
|
528
|
-
padding: 0;
|
|
529
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
530
|
-
}
|
|
531
|
-
</style>
|
|
532
|
-
</head>
|
|
533
|
-
<body>
|
|
534
|
-
<script>${iframeContent}</script>
|
|
535
|
-
</body>
|
|
536
|
-
</html>
|
|
537
|
-
`);
|
|
538
|
-
doc.close();
|
|
539
|
-
}
|
|
540
|
-
} catch (error) {
|
|
541
|
-
console.error("Error initializing iframe content:", error);
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
} catch (error) {
|
|
545
|
-
console.error("Error setting up iframe:", error);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* parse features string to object
|
|
550
|
-
*/
|
|
551
|
-
parseFeatures(features) {
|
|
552
|
-
const result = {};
|
|
553
|
-
const pairs = features.split(",");
|
|
554
|
-
pairs.forEach((pair) => {
|
|
555
|
-
const [key, value] = pair.split("=").map((s) => s.trim());
|
|
556
|
-
if (key && value) {
|
|
557
|
-
result[key] = value;
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
return result;
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* send message to iframe with specified spatialId
|
|
564
|
-
*/
|
|
565
|
-
sendMessageToIframe(spatialId, message) {
|
|
566
|
-
const iframe = this.iframeRegistry.get(spatialId);
|
|
567
|
-
if (iframe && iframe.contentWindow) {
|
|
568
|
-
iframe.contentWindow.postMessage(message, window.location.origin);
|
|
569
|
-
return true;
|
|
570
|
-
}
|
|
571
|
-
return false;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* get all active iframes
|
|
575
|
-
*/
|
|
576
|
-
getAllActiveIframes() {
|
|
577
|
-
const result = [];
|
|
578
|
-
this.iframeRegistry.forEach((iframe, spatialId) => {
|
|
579
|
-
result.push({ spatialId, iframe });
|
|
580
|
-
});
|
|
581
|
-
return result;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* dispose all active iframes
|
|
585
|
-
*/
|
|
586
|
-
dispose() {
|
|
587
|
-
this.iframeRegistry.forEach((iframe, spatialId) => {
|
|
588
|
-
console.log(`Disposing iframe with spatialId: ${spatialId}`);
|
|
589
|
-
iframe.remove();
|
|
590
|
-
});
|
|
591
|
-
this.iframeRegistry.clear();
|
|
592
|
-
}
|
|
593
|
-
// generate UUID function
|
|
594
|
-
generateUUID() {
|
|
595
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
596
|
-
/[xy]/g,
|
|
597
|
-
function(c) {
|
|
598
|
-
const r = Math.random() * 16 | 0;
|
|
599
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
600
|
-
return v.toString(16).toUpperCase();
|
|
601
|
-
}
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
// src/platform-adapter/ssr/SSRPlatform.ts
|
|
607
|
-
var SSRPlatform = class {
|
|
608
|
-
callJSB(cmd, msg) {
|
|
609
|
-
return Promise.resolve({
|
|
610
|
-
success: true,
|
|
611
|
-
data: void 0,
|
|
612
|
-
errorCode: void 0,
|
|
613
|
-
errorMessage: void 0
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
openSpatialSceneSync(_url, _config, _target, _features) {
|
|
617
|
-
return {
|
|
618
|
-
success: true,
|
|
619
|
-
data: void 0,
|
|
620
|
-
errorCode: void 0,
|
|
621
|
-
errorMessage: void 0
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
createNativeSpatialDiv() {
|
|
625
|
-
return Promise.resolve({
|
|
626
|
-
success: true,
|
|
627
|
-
data: void 0,
|
|
628
|
-
errorCode: void 0,
|
|
629
|
-
errorMessage: void 0
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
createNativeAttachment(_options) {
|
|
633
|
-
return Promise.resolve({
|
|
634
|
-
success: true,
|
|
635
|
-
data: void 0,
|
|
636
|
-
errorCode: void 0,
|
|
637
|
-
errorMessage: void 0
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
// src/platform-adapter/vision-os/VisionOSPlatform.ts
|
|
643
|
-
var UUID_RE = /\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi;
|
|
644
|
-
var VisionOSPlatform = class {
|
|
645
|
-
async callJSB(cmd, msg) {
|
|
646
|
-
try {
|
|
647
|
-
const result = await window.webkit.messageHandlers.bridge.postMessage(
|
|
648
|
-
`${cmd}::${msg}`
|
|
649
|
-
);
|
|
650
|
-
return CommandResultSuccess(result);
|
|
651
|
-
} catch (error) {
|
|
652
|
-
const { code, message } = this.parseJSBError(error);
|
|
653
|
-
return CommandResultFailure(code, message);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
openSpatialSceneSync(url, config, target, features) {
|
|
657
|
-
const query = buildSpatialSceneQuery(url, config);
|
|
658
|
-
const { spatialId: id = "", windowProxy } = this.openWindow(
|
|
659
|
-
"createSpatialScene",
|
|
660
|
-
query,
|
|
661
|
-
target,
|
|
662
|
-
features
|
|
663
|
-
);
|
|
664
|
-
return CommandResultSuccess({ windowProxy, id });
|
|
665
|
-
}
|
|
666
|
-
createNativeSpatialDiv() {
|
|
667
|
-
return this.openProtocolAsync("createSpatialized2DElement");
|
|
668
|
-
}
|
|
669
|
-
createNativeAttachment(_options) {
|
|
670
|
-
return this.openProtocolAsync("createAttachment");
|
|
671
|
-
}
|
|
672
|
-
async openProtocolAsync(command) {
|
|
673
|
-
const { spatialId: id = "", windowProxy } = this.openWindow(
|
|
674
|
-
command,
|
|
675
|
-
"",
|
|
676
|
-
void 0,
|
|
677
|
-
void 0
|
|
678
|
-
);
|
|
679
|
-
return CommandResultSuccess({ windowProxy, id });
|
|
680
|
-
}
|
|
681
|
-
openWindow(command, query, target, features) {
|
|
682
|
-
const windowProxy = window.open(
|
|
683
|
-
`webspatial://${command}?${query || ""}`,
|
|
684
|
-
target,
|
|
685
|
-
features
|
|
686
|
-
);
|
|
687
|
-
const ua = windowProxy?.navigator.userAgent;
|
|
688
|
-
const spatialId = ua?.match(UUID_RE)?.[0];
|
|
689
|
-
return { spatialId, windowProxy };
|
|
690
|
-
}
|
|
691
|
-
parseJSBError(error) {
|
|
692
|
-
try {
|
|
693
|
-
const parsed = JSON.parse(error.message ?? "");
|
|
694
|
-
return {
|
|
695
|
-
code: parsed.code ?? "E_VISIONOS_JSB",
|
|
696
|
-
message: parsed.message ?? "VisionOS JSB execution failed"
|
|
697
|
-
};
|
|
698
|
-
} catch {
|
|
699
|
-
return {
|
|
700
|
-
code: "E_VISIONOS_JSB",
|
|
701
|
-
message: error?.message ?? "VisionOS JSB execution failed"
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
// src/platform-adapter/createPlatformSync.ts
|
|
708
|
-
function assertNever(_) {
|
|
709
|
-
throw new Error("Unhandled jsb adapter platform kind");
|
|
710
|
-
}
|
|
711
|
-
function createPlatformSync() {
|
|
712
|
-
if (isSSREnv()) {
|
|
713
|
-
return new SSRPlatform();
|
|
714
|
-
}
|
|
715
|
-
const userAgent = window.navigator.userAgent;
|
|
716
|
-
const kind = resolveJsbAdapterPlatform(userAgent);
|
|
717
|
-
switch (kind) {
|
|
718
|
-
case "puppeteer":
|
|
719
|
-
return new PuppeteerPlatform();
|
|
720
|
-
case "picoos":
|
|
721
|
-
return new PicoOSPlatform();
|
|
722
|
-
case "visionos":
|
|
723
|
-
return new VisionOSPlatform();
|
|
724
|
-
default:
|
|
725
|
-
return assertNever(kind);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// src/platform-runtime.ts
|
|
730
|
-
var platformResolved;
|
|
731
|
-
function getPlatformSync() {
|
|
732
|
-
platformResolved ??= createPlatformSync();
|
|
733
|
-
return platformResolved;
|
|
734
|
-
}
|
|
735
|
-
async function getPlatform() {
|
|
736
|
-
return getPlatformSync();
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
// src/utils.ts
|
|
740
|
-
function parseBorderRadius(borderProperty, width) {
|
|
741
|
-
if (borderProperty === "") {
|
|
742
|
-
return 0;
|
|
743
|
-
}
|
|
744
|
-
if (borderProperty.endsWith("%")) {
|
|
745
|
-
return width * parseFloat(borderProperty) / 100;
|
|
746
|
-
}
|
|
747
|
-
return parseFloat(borderProperty);
|
|
748
|
-
}
|
|
749
|
-
function parseCornerRadius(computedStyle) {
|
|
750
|
-
const width = parseFloat(computedStyle.getPropertyValue("width"));
|
|
751
|
-
const topLeftPropertyValue = computedStyle.getPropertyValue(
|
|
752
|
-
"border-top-left-radius"
|
|
753
|
-
);
|
|
754
|
-
const topRightPropertyValue = computedStyle.getPropertyValue(
|
|
755
|
-
"border-top-right-radius"
|
|
756
|
-
);
|
|
757
|
-
const bottomLeftPropertyValue = computedStyle.getPropertyValue(
|
|
758
|
-
"border-bottom-left-radius"
|
|
759
|
-
);
|
|
760
|
-
const bottomRightPropertyValue = computedStyle.getPropertyValue(
|
|
761
|
-
"border-bottom-right-radius"
|
|
762
|
-
);
|
|
763
|
-
const cornerRadius = {
|
|
764
|
-
topLeading: parseBorderRadius(topLeftPropertyValue, width),
|
|
765
|
-
bottomLeading: parseBorderRadius(bottomLeftPropertyValue, width),
|
|
766
|
-
topTrailing: parseBorderRadius(topRightPropertyValue, width),
|
|
767
|
-
bottomTrailing: parseBorderRadius(bottomRightPropertyValue, width)
|
|
768
|
-
};
|
|
769
|
-
return cornerRadius;
|
|
770
|
-
}
|
|
771
|
-
function composeSRT(position, rotation, scale) {
|
|
772
|
-
const { x: px, y: py, z: pz } = position;
|
|
773
|
-
const { x: rx, y: ry, z: rz } = rotation;
|
|
774
|
-
const { x: sx, y: sy, z: sz } = scale;
|
|
775
|
-
let m = new DOMMatrix();
|
|
776
|
-
m = m.translate(px, py, pz);
|
|
777
|
-
m = m.rotate(rx, ry, rz);
|
|
778
|
-
m = m.scale(sx, sy, sz);
|
|
779
|
-
return m;
|
|
780
|
-
}
|
|
781
|
-
function deepCloneJSON(value) {
|
|
782
|
-
const sc = globalThis.structuredClone;
|
|
783
|
-
if (typeof sc === "function") {
|
|
784
|
-
try {
|
|
785
|
-
return sc(value);
|
|
786
|
-
} catch {
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
return JSON.parse(JSON.stringify(value));
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
// src/JSBCommand.ts
|
|
793
|
-
var JSBCommand = class {
|
|
794
|
-
commandType = "";
|
|
795
|
-
async execute() {
|
|
796
|
-
const param = this.getParams();
|
|
797
|
-
const msg = param ? JSON.stringify(param) : "";
|
|
798
|
-
const platform = await getPlatform();
|
|
799
|
-
return platform.callJSB(this.commandType, msg);
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
var UpdateEntityPropertiesCommand = class extends JSBCommand {
|
|
803
|
-
constructor(entity, properties) {
|
|
804
|
-
super();
|
|
805
|
-
this.entity = entity;
|
|
806
|
-
this.properties = properties;
|
|
807
|
-
}
|
|
808
|
-
commandType = "UpdateEntityProperties";
|
|
809
|
-
getParams() {
|
|
810
|
-
const transform = composeSRT(
|
|
811
|
-
this.properties.position ?? this.entity.position,
|
|
812
|
-
this.properties.rotation ?? this.entity.rotation,
|
|
813
|
-
this.properties.scale ?? this.entity.scale
|
|
814
|
-
).toFloat64Array();
|
|
815
|
-
return {
|
|
816
|
-
entityId: this.entity.id,
|
|
817
|
-
transform
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
var UpdateEntityEventCommand = class extends JSBCommand {
|
|
822
|
-
constructor(entity, type, isEnable) {
|
|
823
|
-
super();
|
|
824
|
-
this.entity = entity;
|
|
825
|
-
this.type = type;
|
|
826
|
-
this.isEnable = isEnable;
|
|
827
|
-
}
|
|
828
|
-
commandType = "UpdateEntityEvent";
|
|
829
|
-
getParams() {
|
|
830
|
-
return {
|
|
831
|
-
type: this.type,
|
|
832
|
-
entityId: this.entity.id,
|
|
833
|
-
isEnable: this.isEnable
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
};
|
|
837
|
-
var UpdateSpatialSceneProperties = class extends JSBCommand {
|
|
838
|
-
properties;
|
|
839
|
-
commandType = "UpdateSpatialSceneProperties";
|
|
840
|
-
constructor(properties) {
|
|
841
|
-
super();
|
|
842
|
-
this.properties = properties;
|
|
843
|
-
}
|
|
844
|
-
getParams() {
|
|
845
|
-
return this.properties;
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
var UpdateSceneConfig = class extends JSBCommand {
|
|
849
|
-
config;
|
|
850
|
-
commandType = "UpdateSceneConfig";
|
|
851
|
-
constructor(config) {
|
|
852
|
-
super();
|
|
853
|
-
this.config = config;
|
|
854
|
-
}
|
|
855
|
-
getParams() {
|
|
856
|
-
return { config: this.config };
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
var FocusScene = class extends JSBCommand {
|
|
860
|
-
constructor(id) {
|
|
861
|
-
super();
|
|
862
|
-
this.id = id;
|
|
863
|
-
}
|
|
864
|
-
commandType = "FocusScene";
|
|
865
|
-
getParams() {
|
|
866
|
-
return { id: this.id };
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
var GetSpatialSceneState = class extends JSBCommand {
|
|
870
|
-
commandType = "GetSpatialSceneState";
|
|
871
|
-
constructor() {
|
|
872
|
-
super();
|
|
873
|
-
}
|
|
874
|
-
getParams() {
|
|
875
|
-
return {};
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
var SpatializedElementCommand = class extends JSBCommand {
|
|
879
|
-
constructor(spatialObject) {
|
|
880
|
-
super();
|
|
881
|
-
this.spatialObject = spatialObject;
|
|
882
|
-
}
|
|
883
|
-
getParams() {
|
|
884
|
-
const extraParams = this.getExtraParams();
|
|
885
|
-
return { id: this.spatialObject.id, ...extraParams };
|
|
886
|
-
}
|
|
887
|
-
};
|
|
888
|
-
var UpdateSpatialized2DElementProperties = class extends SpatializedElementCommand {
|
|
889
|
-
properties;
|
|
890
|
-
commandType = "UpdateSpatialized2DElementProperties";
|
|
891
|
-
constructor(spatialObject, properties) {
|
|
892
|
-
super(spatialObject);
|
|
893
|
-
this.properties = properties;
|
|
894
|
-
}
|
|
895
|
-
getExtraParams() {
|
|
896
|
-
return this.properties;
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
var UpdateSpatializedDynamic3DElementProperties = class extends SpatializedElementCommand {
|
|
900
|
-
properties;
|
|
901
|
-
commandType = "UpdateSpatializedDynamic3DElementProperties";
|
|
902
|
-
constructor(spatialObject, properties) {
|
|
903
|
-
super(spatialObject);
|
|
904
|
-
this.properties = properties;
|
|
905
|
-
}
|
|
906
|
-
getExtraParams() {
|
|
907
|
-
return {
|
|
908
|
-
id: this.spatialObject.id,
|
|
909
|
-
...this.properties
|
|
910
|
-
};
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
var UpdateUnlitMaterialProperties = class extends SpatializedElementCommand {
|
|
914
|
-
properties;
|
|
915
|
-
commandType = "UpdateUnlitMaterialProperties";
|
|
916
|
-
constructor(spatialObject, properties) {
|
|
917
|
-
super(spatialObject);
|
|
918
|
-
this.properties = properties;
|
|
919
|
-
}
|
|
920
|
-
getExtraParams() {
|
|
921
|
-
return this.properties;
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
var UpdateSpatializedElementTransform = class extends SpatializedElementCommand {
|
|
925
|
-
matrix;
|
|
926
|
-
commandType = "UpdateSpatializedElementTransform";
|
|
927
|
-
constructor(spatialObject, matrix) {
|
|
928
|
-
super(spatialObject);
|
|
929
|
-
this.matrix = matrix;
|
|
930
|
-
}
|
|
931
|
-
getExtraParams() {
|
|
932
|
-
return { matrix: Array.from(this.matrix.toFloat64Array()) };
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
var UpdateSpatializedStatic3DElementProperties = class extends SpatializedElementCommand {
|
|
936
|
-
properties;
|
|
937
|
-
commandType = "UpdateSpatializedStatic3DElementProperties";
|
|
938
|
-
constructor(spatialObject, properties) {
|
|
939
|
-
super(spatialObject);
|
|
940
|
-
this.properties = properties;
|
|
941
|
-
}
|
|
942
|
-
getExtraParams() {
|
|
943
|
-
return this.properties;
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
var AddSpatializedElementToSpatialized2DElement = class extends SpatializedElementCommand {
|
|
947
|
-
commandType = "AddSpatializedElementToSpatialized2DElement";
|
|
948
|
-
spatializedElement;
|
|
949
|
-
constructor(spatialObject, spatializedElement) {
|
|
950
|
-
super(spatialObject);
|
|
951
|
-
this.spatializedElement = spatializedElement;
|
|
952
|
-
}
|
|
953
|
-
getExtraParams() {
|
|
954
|
-
return { spatializedElementId: this.spatializedElement.id };
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
var AddSpatializedElementToSpatialScene = class extends JSBCommand {
|
|
958
|
-
commandType = "AddSpatializedElementToSpatialScene";
|
|
959
|
-
spatializedElement;
|
|
960
|
-
constructor(spatializedElement) {
|
|
961
|
-
super();
|
|
962
|
-
this.spatializedElement = spatializedElement;
|
|
963
|
-
}
|
|
964
|
-
getParams() {
|
|
965
|
-
return {
|
|
966
|
-
spatializedElementId: this.spatializedElement.id
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
var CreateSpatializedStatic3DElementCommand = class extends JSBCommand {
|
|
971
|
-
constructor(modelURL, sources, loading = "eager") {
|
|
972
|
-
super();
|
|
973
|
-
this.modelURL = modelURL;
|
|
974
|
-
this.sources = sources;
|
|
975
|
-
this.loading = loading;
|
|
976
|
-
this.modelURL = modelURL;
|
|
977
|
-
this.sources = sources;
|
|
978
|
-
this.loading = loading;
|
|
979
|
-
}
|
|
980
|
-
commandType = "CreateSpatializedStatic3DElement";
|
|
981
|
-
getParams() {
|
|
982
|
-
return {
|
|
983
|
-
modelURL: this.modelURL,
|
|
984
|
-
sources: this.sources,
|
|
985
|
-
loading: this.loading
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
var CreateSpatializedDynamic3DElementCommand = class extends JSBCommand {
|
|
990
|
-
getParams() {
|
|
991
|
-
return { test: true };
|
|
992
|
-
}
|
|
993
|
-
commandType = "CreateSpatializedDynamic3DElement";
|
|
994
|
-
};
|
|
995
|
-
var CreateSpatialEntityCommand = class extends JSBCommand {
|
|
996
|
-
constructor(name) {
|
|
997
|
-
super();
|
|
998
|
-
this.name = name;
|
|
999
|
-
}
|
|
1000
|
-
getParams() {
|
|
1001
|
-
return { name: this.name };
|
|
1002
|
-
}
|
|
1003
|
-
commandType = "CreateSpatialEntity";
|
|
1004
|
-
};
|
|
1005
|
-
var CreateModelComponentCommand = class extends JSBCommand {
|
|
1006
|
-
constructor(options) {
|
|
1007
|
-
super();
|
|
1008
|
-
this.options = options;
|
|
1009
|
-
}
|
|
1010
|
-
getParams() {
|
|
1011
|
-
let geometryId = this.options.mesh.id;
|
|
1012
|
-
let materialIds = this.options.materials.map((material) => material.id);
|
|
1013
|
-
return { geometryId, materialIds };
|
|
1014
|
-
}
|
|
1015
|
-
commandType = "CreateModelComponent";
|
|
1016
|
-
};
|
|
1017
|
-
var CreateSpatialModelEntityCommand = class extends JSBCommand {
|
|
1018
|
-
constructor(options) {
|
|
1019
|
-
super();
|
|
1020
|
-
this.options = options;
|
|
1021
|
-
}
|
|
1022
|
-
getParams() {
|
|
1023
|
-
return this.options;
|
|
1024
|
-
}
|
|
1025
|
-
commandType = "CreateSpatialModelEntity";
|
|
1026
|
-
};
|
|
1027
|
-
var CreateModelAssetCommand = class extends JSBCommand {
|
|
1028
|
-
constructor(options) {
|
|
1029
|
-
super();
|
|
1030
|
-
this.options = options;
|
|
1031
|
-
}
|
|
1032
|
-
getParams() {
|
|
1033
|
-
return { url: this.options.url };
|
|
1034
|
-
}
|
|
1035
|
-
commandType = "CreateModelAsset";
|
|
1036
|
-
};
|
|
1037
|
-
var CreateSpatialGeometryCommand = class extends JSBCommand {
|
|
1038
|
-
constructor(type, options = {}) {
|
|
1039
|
-
super();
|
|
1040
|
-
this.type = type;
|
|
1041
|
-
this.options = options;
|
|
1042
|
-
}
|
|
1043
|
-
getParams() {
|
|
1044
|
-
return { type: this.type, ...this.options };
|
|
1045
|
-
}
|
|
1046
|
-
commandType = "CreateGeometry";
|
|
1047
|
-
};
|
|
1048
|
-
var CreateSpatialUnlitMaterialCommand = class extends JSBCommand {
|
|
1049
|
-
constructor(options) {
|
|
1050
|
-
super();
|
|
1051
|
-
this.options = options;
|
|
1052
|
-
}
|
|
1053
|
-
getParams() {
|
|
1054
|
-
return this.options;
|
|
1055
|
-
}
|
|
1056
|
-
commandType = "CreateUnlitMaterial";
|
|
1057
|
-
};
|
|
1058
|
-
var AddComponentToEntityCommand = class extends JSBCommand {
|
|
1059
|
-
constructor(entity, comp) {
|
|
1060
|
-
super();
|
|
1061
|
-
this.entity = entity;
|
|
1062
|
-
this.comp = comp;
|
|
1063
|
-
}
|
|
1064
|
-
getParams() {
|
|
1065
|
-
return {
|
|
1066
|
-
entityId: this.entity.id,
|
|
1067
|
-
componentId: this.comp.id
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
commandType = "AddComponentToEntity";
|
|
1071
|
-
};
|
|
1072
|
-
var RemoveComponentFromEntityCommand = class extends JSBCommand {
|
|
1073
|
-
constructor(entity, comp) {
|
|
1074
|
-
super();
|
|
1075
|
-
this.entity = entity;
|
|
1076
|
-
this.comp = comp;
|
|
1077
|
-
}
|
|
1078
|
-
getParams() {
|
|
1079
|
-
return {
|
|
1080
|
-
entityId: this.entity.id,
|
|
1081
|
-
componentId: this.comp.id
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
commandType = "RemoveComponentFromEntity";
|
|
1085
|
-
};
|
|
1086
|
-
var SetMaterialsOnEntityCommand = class extends JSBCommand {
|
|
1087
|
-
constructor(entityId, materials) {
|
|
1088
|
-
super();
|
|
1089
|
-
this.entityId = entityId;
|
|
1090
|
-
this.materials = materials;
|
|
1091
|
-
}
|
|
1092
|
-
getParams() {
|
|
1093
|
-
return {
|
|
1094
|
-
entityId: this.entityId,
|
|
1095
|
-
materialIds: this.materials.map((m) => m.id)
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
commandType = "SetMaterialsOnEntity";
|
|
1099
|
-
};
|
|
1100
|
-
var SetParentForEntityCommand = class extends JSBCommand {
|
|
1101
|
-
// childId, parentId
|
|
1102
|
-
constructor(childId, parentId) {
|
|
1103
|
-
super();
|
|
1104
|
-
this.childId = childId;
|
|
1105
|
-
this.parentId = parentId;
|
|
1106
|
-
}
|
|
1107
|
-
getParams() {
|
|
1108
|
-
return {
|
|
1109
|
-
childId: this.childId,
|
|
1110
|
-
parentId: this.parentId
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
commandType = "SetParentToEntity";
|
|
1114
|
-
};
|
|
1115
|
-
var ConvertFromEntityToEntityCommand = class extends JSBCommand {
|
|
1116
|
-
constructor(fromEntityId, toEntityId, fromPosition) {
|
|
1117
|
-
super();
|
|
1118
|
-
this.fromEntityId = fromEntityId;
|
|
1119
|
-
this.toEntityId = toEntityId;
|
|
1120
|
-
this.fromPosition = fromPosition;
|
|
1121
|
-
}
|
|
1122
|
-
getParams() {
|
|
1123
|
-
return {
|
|
1124
|
-
fromEntityId: this.fromEntityId,
|
|
1125
|
-
toEntityId: this.toEntityId,
|
|
1126
|
-
position: this.fromPosition
|
|
1127
|
-
};
|
|
1128
|
-
}
|
|
1129
|
-
commandType = "ConvertFromEntityToEntity";
|
|
1130
|
-
};
|
|
1131
|
-
var ConvertFromEntityToSceneCommand = class extends JSBCommand {
|
|
1132
|
-
constructor(fromEntityId, position) {
|
|
1133
|
-
super();
|
|
1134
|
-
this.fromEntityId = fromEntityId;
|
|
1135
|
-
this.position = position;
|
|
1136
|
-
}
|
|
1137
|
-
getParams() {
|
|
1138
|
-
return {
|
|
1139
|
-
fromEntityId: this.fromEntityId,
|
|
1140
|
-
position: this.position
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
commandType = "ConvertFromEntityToScene";
|
|
1144
|
-
};
|
|
1145
|
-
var ConvertFromSceneToEntityCommand = class extends JSBCommand {
|
|
1146
|
-
// let entityId: String
|
|
1147
|
-
// let position:Vec3
|
|
1148
|
-
constructor(entityId, position) {
|
|
1149
|
-
super();
|
|
1150
|
-
this.entityId = entityId;
|
|
1151
|
-
this.position = position;
|
|
1152
|
-
}
|
|
1153
|
-
getParams() {
|
|
1154
|
-
return {
|
|
1155
|
-
entityId: this.entityId,
|
|
1156
|
-
position: this.position
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
commandType = "ConvertFromSceneToEntity";
|
|
1160
|
-
};
|
|
1161
|
-
var ConvertCoordinateCommand = class extends JSBCommand {
|
|
1162
|
-
constructor(position, fromId, toId) {
|
|
1163
|
-
super();
|
|
1164
|
-
this.position = position;
|
|
1165
|
-
this.fromId = fromId;
|
|
1166
|
-
this.toId = toId;
|
|
1167
|
-
}
|
|
1168
|
-
getParams() {
|
|
1169
|
-
return {
|
|
1170
|
-
position: this.position,
|
|
1171
|
-
fromId: this.fromId,
|
|
1172
|
-
toId: this.toId
|
|
1173
|
-
};
|
|
1174
|
-
}
|
|
1175
|
-
commandType = "ConvertCoordinate";
|
|
1176
|
-
};
|
|
1177
|
-
var CreateTextureCommand = class extends JSBCommand {
|
|
1178
|
-
constructor(url) {
|
|
1179
|
-
super();
|
|
1180
|
-
this.url = url;
|
|
1181
|
-
}
|
|
1182
|
-
getParams() {
|
|
1183
|
-
return {
|
|
1184
|
-
url: this.url
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
commandType = "CreateTexture";
|
|
1188
|
-
};
|
|
1189
|
-
var UpdateTexturePropertiesCommand = class extends SpatializedElementCommand {
|
|
1190
|
-
properties;
|
|
1191
|
-
commandType = "UpdateTextureProperties";
|
|
1192
|
-
constructor(spatialObject, properties) {
|
|
1193
|
-
super(spatialObject);
|
|
1194
|
-
this.properties = properties;
|
|
1195
|
-
}
|
|
1196
|
-
getExtraParams() {
|
|
1197
|
-
return this.properties;
|
|
1198
|
-
}
|
|
1199
|
-
};
|
|
1200
|
-
var InspectCommand = class extends JSBCommand {
|
|
1201
|
-
constructor(id = "") {
|
|
1202
|
-
super();
|
|
1203
|
-
this.id = id;
|
|
1204
|
-
}
|
|
1205
|
-
commandType = "Inspect";
|
|
1206
|
-
getParams() {
|
|
1207
|
-
return this.id ? { id: this.id } : { id: "" };
|
|
1208
|
-
}
|
|
1209
|
-
};
|
|
1210
|
-
var DestroyCommand = class extends JSBCommand {
|
|
1211
|
-
constructor(id) {
|
|
1212
|
-
super();
|
|
1213
|
-
this.id = id;
|
|
1214
|
-
}
|
|
1215
|
-
commandType = "Destroy";
|
|
1216
|
-
getParams() {
|
|
1217
|
-
return { id: this.id };
|
|
1218
|
-
}
|
|
1219
|
-
};
|
|
1220
|
-
var InitializeAttachmentCommand = class extends JSBCommand {
|
|
1221
|
-
constructor(attachmentId, options) {
|
|
1222
|
-
super();
|
|
1223
|
-
this.attachmentId = attachmentId;
|
|
1224
|
-
this.options = options;
|
|
1225
|
-
}
|
|
1226
|
-
commandType = "InitializeAttachment";
|
|
1227
|
-
getParams() {
|
|
1228
|
-
return {
|
|
1229
|
-
id: this.attachmentId,
|
|
1230
|
-
parentEntityId: this.options.parentEntityId,
|
|
1231
|
-
position: this.options.position ?? [0, 0, 0],
|
|
1232
|
-
size: this.options.size,
|
|
1233
|
-
ownerViewId: this.options.ownerViewId
|
|
1234
|
-
};
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
var UpdateAttachmentEntityCommand = class extends JSBCommand {
|
|
1238
|
-
constructor(attachmentId, options) {
|
|
1239
|
-
super();
|
|
1240
|
-
this.attachmentId = attachmentId;
|
|
1241
|
-
this.options = options;
|
|
1242
|
-
}
|
|
1243
|
-
commandType = "UpdateAttachmentEntity";
|
|
1244
|
-
getParams() {
|
|
1245
|
-
return {
|
|
1246
|
-
id: this.attachmentId,
|
|
1247
|
-
...this.options
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
|
|
1252
|
-
// src/SpatialObject.ts
|
|
1253
|
-
var SpatialObject = class {
|
|
1254
|
-
/** @hidden */
|
|
1255
|
-
constructor(id) {
|
|
1256
|
-
this.id = id;
|
|
1257
|
-
}
|
|
1258
|
-
name;
|
|
1259
|
-
isDestroyed = false;
|
|
1260
|
-
async inspect() {
|
|
1261
|
-
const ret = await new InspectCommand(this.id).execute();
|
|
1262
|
-
if (ret.success) {
|
|
1263
|
-
return ret.data;
|
|
1264
|
-
}
|
|
1265
|
-
throw new Error(ret.errorMessage);
|
|
1266
|
-
}
|
|
1267
|
-
async destroy() {
|
|
1268
|
-
if (this.isDestroyed) {
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
const ret = await new DestroyCommand(this.id).execute();
|
|
1272
|
-
if (ret.success) {
|
|
1273
|
-
this.onDestroy();
|
|
1274
|
-
this.isDestroyed = true;
|
|
1275
|
-
return ret.data;
|
|
1276
|
-
} else if (this.isDestroyed) {
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
throw new Error(ret.errorMessage);
|
|
1280
|
-
}
|
|
1281
|
-
// override this method to do some cleanup
|
|
1282
|
-
onDestroy() {
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
|
|
1286
|
-
// src/spatial-host.ts
|
|
1287
|
-
async function createNativeSpatialDiv() {
|
|
1288
|
-
const platform = await getPlatform();
|
|
1289
|
-
return platform.createNativeSpatialDiv();
|
|
1290
|
-
}
|
|
1291
|
-
async function createNativeAttachment(options) {
|
|
1292
|
-
const platform = await getPlatform();
|
|
1293
|
-
return platform.createNativeAttachment(options);
|
|
1294
|
-
}
|
|
1295
|
-
function openSpatialSceneSync(url, config, target, features) {
|
|
1296
|
-
return getPlatformSync().openSpatialSceneSync(url, config, target, features);
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
// src/SpatialScene.ts
|
|
1300
|
-
var instance;
|
|
1301
|
-
var SpatialScene = class _SpatialScene extends SpatialObject {
|
|
1302
|
-
/**
|
|
1303
|
-
* Gets the singleton instance of the SpatialScene.
|
|
1304
|
-
* Creates a new instance if one doesn't exist yet.
|
|
1305
|
-
* @returns The singleton SpatialScene instance
|
|
1306
|
-
*/
|
|
1307
|
-
static getInstance() {
|
|
1308
|
-
if (!instance) {
|
|
1309
|
-
instance = new _SpatialScene("");
|
|
1310
|
-
}
|
|
1311
|
-
return instance;
|
|
1312
|
-
}
|
|
1313
|
-
async convertCoordinate(position, fromId, toId) {
|
|
1314
|
-
try {
|
|
1315
|
-
const ret = await new ConvertCoordinateCommand(
|
|
1316
|
-
position,
|
|
1317
|
-
fromId,
|
|
1318
|
-
toId
|
|
1319
|
-
).execute();
|
|
1320
|
-
return ret?.data ?? position;
|
|
1321
|
-
} catch (error) {
|
|
1322
|
-
console.warn("SpatialScene.convertCoordinate error:", error);
|
|
1323
|
-
throw error;
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
/**
|
|
1327
|
-
* Updates the properties of the spatial scene.
|
|
1328
|
-
* This can include background settings, lighting, and other scene-wide properties.
|
|
1329
|
-
* @param properties Partial set of properties to update
|
|
1330
|
-
* @returns Promise resolving when the update is complete
|
|
1331
|
-
*/
|
|
1332
|
-
async updateSpatialProperties(properties) {
|
|
1333
|
-
return new UpdateSpatialSceneProperties(properties).execute();
|
|
1334
|
-
}
|
|
1335
|
-
/**
|
|
1336
|
-
* Adds a spatialized element to the scene.
|
|
1337
|
-
* This makes the element visible and interactive in the spatial environment.
|
|
1338
|
-
* @param element The SpatializedElement to add to the scene
|
|
1339
|
-
* @returns Promise resolving when the element is added
|
|
1340
|
-
*/
|
|
1341
|
-
async addSpatializedElement(element) {
|
|
1342
|
-
return new AddSpatializedElementToSpatialScene(element).execute();
|
|
1343
|
-
}
|
|
1344
|
-
/**
|
|
1345
|
-
* Updates the scene creation configuration.
|
|
1346
|
-
* This allows changing scene parameters after initial creation.
|
|
1347
|
-
* @param config The new scene creation configuration
|
|
1348
|
-
* @returns Promise resolving when the update is complete
|
|
1349
|
-
*/
|
|
1350
|
-
async updateSceneCreationConfig(config) {
|
|
1351
|
-
return new UpdateSceneConfig(config).execute();
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Gets the current state of the spatial scene.
|
|
1355
|
-
* This includes information about active elements and scene configuration.
|
|
1356
|
-
* @returns Promise resolving to the current SpatialSceneState
|
|
1357
|
-
*/
|
|
1358
|
-
async getState() {
|
|
1359
|
-
return (await new GetSpatialSceneState().execute()).data.name;
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
|
|
1363
|
-
// src/types/types.ts
|
|
1364
|
-
var SpatializedElementType = /* @__PURE__ */ ((SpatializedElementType2) => {
|
|
1365
|
-
SpatializedElementType2[SpatializedElementType2["Spatialized2DElement"] = 0] = "Spatialized2DElement";
|
|
1366
|
-
SpatializedElementType2[SpatializedElementType2["SpatializedStatic3DElement"] = 1] = "SpatializedStatic3DElement";
|
|
1367
|
-
SpatializedElementType2[SpatializedElementType2["SpatializedDynamic3DElement"] = 2] = "SpatializedDynamic3DElement";
|
|
1368
|
-
return SpatializedElementType2;
|
|
1369
|
-
})(SpatializedElementType || {});
|
|
1370
|
-
var BaseplateVisibilityValues = [
|
|
1371
|
-
"automatic",
|
|
1372
|
-
"visible",
|
|
1373
|
-
"hidden"
|
|
1374
|
-
];
|
|
1375
|
-
function isValidBaseplateVisibilityType(type) {
|
|
1376
|
-
return BaseplateVisibilityValues.includes(type);
|
|
1377
|
-
}
|
|
1378
|
-
var WorldScalingValues = ["automatic", "dynamic"];
|
|
1379
|
-
function isValidWorldScalingType(type) {
|
|
1380
|
-
return WorldScalingValues.includes(type);
|
|
1381
|
-
}
|
|
1382
|
-
var WorldAlignmentValues = [
|
|
1383
|
-
"adaptive",
|
|
1384
|
-
"automatic",
|
|
1385
|
-
"gravityAligned"
|
|
1386
|
-
];
|
|
1387
|
-
function isValidWorldAlignmentType(type) {
|
|
1388
|
-
return WorldAlignmentValues.includes(type);
|
|
1389
|
-
}
|
|
1390
|
-
var SpatialSceneValues = ["window", "volume"];
|
|
1391
|
-
function isValidSpatialSceneType(type) {
|
|
1392
|
-
return SpatialSceneValues.includes(type);
|
|
1393
|
-
}
|
|
1394
|
-
function isValidSceneUnit(val) {
|
|
1395
|
-
if (typeof val === "number") {
|
|
1396
|
-
return val >= 0;
|
|
1397
|
-
}
|
|
1398
|
-
if (typeof val === "string") {
|
|
1399
|
-
if (val.endsWith("px")) {
|
|
1400
|
-
if (isNaN(Number(val.slice(0, -2)))) {
|
|
1401
|
-
return false;
|
|
1402
|
-
}
|
|
1403
|
-
return Number(val.slice(0, -2)) >= 0;
|
|
1404
|
-
}
|
|
1405
|
-
if (val.endsWith("m")) {
|
|
1406
|
-
if (isNaN(Number(val.slice(0, -1)))) {
|
|
1407
|
-
return false;
|
|
1408
|
-
}
|
|
1409
|
-
return Number(val.slice(0, -1)) >= 0;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
return false;
|
|
1413
|
-
}
|
|
1414
|
-
var SpatialSceneState = /* @__PURE__ */ ((SpatialSceneState2) => {
|
|
1415
|
-
SpatialSceneState2["idle"] = "idle";
|
|
1416
|
-
SpatialSceneState2["pending"] = "pending";
|
|
1417
|
-
SpatialSceneState2["willVisible"] = "willVisible";
|
|
1418
|
-
SpatialSceneState2["visible"] = "visible";
|
|
1419
|
-
SpatialSceneState2["fail"] = "fail";
|
|
1420
|
-
return SpatialSceneState2;
|
|
1421
|
-
})(SpatialSceneState || {});
|
|
1422
|
-
var CubeInfo = class {
|
|
1423
|
-
constructor(size, origin) {
|
|
1424
|
-
this.size = size;
|
|
1425
|
-
this.origin = origin;
|
|
1426
|
-
this.size = size;
|
|
1427
|
-
this.origin = origin;
|
|
1428
|
-
}
|
|
1429
|
-
get x() {
|
|
1430
|
-
return this.origin.x;
|
|
1431
|
-
}
|
|
1432
|
-
get y() {
|
|
1433
|
-
return this.origin.y;
|
|
1434
|
-
}
|
|
1435
|
-
get z() {
|
|
1436
|
-
return this.origin.z;
|
|
1437
|
-
}
|
|
1438
|
-
get width() {
|
|
1439
|
-
return this.size.width;
|
|
1440
|
-
}
|
|
1441
|
-
get height() {
|
|
1442
|
-
return this.size.height;
|
|
1443
|
-
}
|
|
1444
|
-
get depth() {
|
|
1445
|
-
return this.size.depth;
|
|
1446
|
-
}
|
|
1447
|
-
get left() {
|
|
1448
|
-
return this.x;
|
|
1449
|
-
}
|
|
1450
|
-
get top() {
|
|
1451
|
-
return this.y;
|
|
1452
|
-
}
|
|
1453
|
-
get right() {
|
|
1454
|
-
return this.x + this.width;
|
|
1455
|
-
}
|
|
1456
|
-
get bottom() {
|
|
1457
|
-
return this.y + this.height;
|
|
1458
|
-
}
|
|
1459
|
-
get back() {
|
|
1460
|
-
return this.z;
|
|
1461
|
-
}
|
|
1462
|
-
get front() {
|
|
1463
|
-
return this.z + this.depth;
|
|
1464
|
-
}
|
|
1465
|
-
};
|
|
1466
|
-
|
|
1467
|
-
// src/physicalMetrics.ts
|
|
1468
|
-
var physicalMetrics_exports = {};
|
|
1469
|
-
__export(physicalMetrics_exports, {
|
|
1470
|
-
getValue: () => getValue,
|
|
1471
|
-
physicalToPoint: () => physicalToPoint,
|
|
1472
|
-
pointToPhysical: () => pointToPhysical,
|
|
1473
|
-
subscribe: () => subscribe
|
|
1474
|
-
});
|
|
1475
|
-
var snapshot = {
|
|
1476
|
-
meterToPtUnscaled: 1360,
|
|
1477
|
-
meterToPtScaled: 1360
|
|
1478
|
-
};
|
|
1479
|
-
function getWorldScalingCompensation(options) {
|
|
1480
|
-
return options?.worldScalingCompensation ?? "scaled";
|
|
1481
|
-
}
|
|
1482
|
-
function pointToPhysical(point, options) {
|
|
1483
|
-
updateValue();
|
|
1484
|
-
const compensation = getWorldScalingCompensation(options);
|
|
1485
|
-
if (compensation === "unscaled") {
|
|
1486
|
-
return point / snapshot.meterToPtUnscaled;
|
|
1487
|
-
}
|
|
1488
|
-
return point / snapshot.meterToPtScaled;
|
|
1489
|
-
}
|
|
1490
|
-
function physicalToPoint(physical, options) {
|
|
1491
|
-
updateValue();
|
|
1492
|
-
const compensation = getWorldScalingCompensation(options);
|
|
1493
|
-
if (compensation === "unscaled") {
|
|
1494
|
-
return physical * snapshot.meterToPtUnscaled;
|
|
1495
|
-
}
|
|
1496
|
-
return physical * snapshot.meterToPtScaled;
|
|
1497
|
-
}
|
|
1498
|
-
function updateValue() {
|
|
1499
|
-
if (typeof window === "undefined") return;
|
|
1500
|
-
const src = window.__webspatialsdk__?.physicalMetrics;
|
|
1501
|
-
if (!src) return;
|
|
1502
|
-
const next = {
|
|
1503
|
-
meterToPtScaled: src.meterToPtScaled ?? snapshot.meterToPtScaled,
|
|
1504
|
-
meterToPtUnscaled: src.meterToPtUnscaled ?? snapshot.meterToPtUnscaled
|
|
1505
|
-
};
|
|
1506
|
-
if (next.meterToPtScaled !== snapshot.meterToPtScaled || next.meterToPtUnscaled !== snapshot.meterToPtUnscaled) {
|
|
1507
|
-
snapshot = next;
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
function getValue() {
|
|
1511
|
-
updateValue();
|
|
1512
|
-
return snapshot;
|
|
1513
|
-
}
|
|
1514
|
-
function subscribe(cb) {
|
|
1515
|
-
if (typeof window === "undefined") return () => {
|
|
1516
|
-
};
|
|
1517
|
-
const handler = () => {
|
|
1518
|
-
cb();
|
|
1519
|
-
};
|
|
1520
|
-
SpatialWebEvent.addEventReceiver("window", handler);
|
|
1521
|
-
return () => {
|
|
1522
|
-
SpatialWebEvent.removeEventReceiver("window");
|
|
1523
|
-
};
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
// src/scene-polyfill.ts
|
|
1527
|
-
var defaultSceneConfig = {
|
|
1528
|
-
defaultSize: {
|
|
1529
|
-
width: 1280,
|
|
1530
|
-
height: 720
|
|
1531
|
-
}
|
|
1532
|
-
};
|
|
1533
|
-
var defaultSceneConfigVolume = {
|
|
1534
|
-
defaultSize: {
|
|
1535
|
-
width: "0.94m",
|
|
1536
|
-
height: "0.94m",
|
|
1537
|
-
depth: "0.94m"
|
|
1538
|
-
}
|
|
1539
|
-
};
|
|
1540
|
-
var xr_window_defaults = {
|
|
1541
|
-
...defaultSceneConfig
|
|
1542
|
-
};
|
|
1543
|
-
var xr_volume_defaults = {
|
|
1544
|
-
...defaultSceneConfigVolume
|
|
1545
|
-
};
|
|
1546
|
-
var INTERNAL_SCHEMA_PREFIX = "webspatial://";
|
|
1547
|
-
function deepMergePlain(base, over) {
|
|
1548
|
-
if (!over) return { ...base || {} };
|
|
1549
|
-
const out = { ...base || {} };
|
|
1550
|
-
for (const k of Object.keys(over)) {
|
|
1551
|
-
const bv = out[k];
|
|
1552
|
-
const ov = over[k];
|
|
1553
|
-
if (ov && typeof ov === "object" && !Array.isArray(ov) && bv && typeof bv === "object" && !Array.isArray(bv)) {
|
|
1554
|
-
out[k] = deepMergePlain(bv, ov);
|
|
1555
|
-
} else {
|
|
1556
|
-
out[k] = ov;
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
return out;
|
|
1560
|
-
}
|
|
1561
|
-
function normalizeXRDefaultsToSceneOptions(src) {
|
|
1562
|
-
const out = { ...src || {} };
|
|
1563
|
-
const ds = src.defaultSize !== void 0 ? src.defaultSize : src.default_size;
|
|
1564
|
-
if (ds !== void 0) {
|
|
1565
|
-
out.defaultSize = ds;
|
|
1566
|
-
}
|
|
1567
|
-
if ("default_size" in out) {
|
|
1568
|
-
delete out.default_size;
|
|
1569
|
-
}
|
|
1570
|
-
return out;
|
|
1571
|
-
}
|
|
1572
|
-
var SceneManager = class _SceneManager {
|
|
1573
|
-
originalOpen;
|
|
1574
|
-
static instance;
|
|
1575
|
-
manifestReady = null;
|
|
1576
|
-
static getInstance() {
|
|
1577
|
-
if (!_SceneManager.instance) {
|
|
1578
|
-
_SceneManager.instance = new _SceneManager();
|
|
1579
|
-
}
|
|
1580
|
-
return _SceneManager.instance;
|
|
1581
|
-
}
|
|
1582
|
-
init(window2) {
|
|
1583
|
-
this.manifestReady = this.setupManifest();
|
|
1584
|
-
this.originalOpen = window2.open.bind(window2);
|
|
1585
|
-
window2.open = this.open;
|
|
1586
|
-
}
|
|
1587
|
-
// Stores the latest formatted config used by the platform (per scene name).
|
|
1588
|
-
// This object contains normalized values and is safe for internal consumption.
|
|
1589
|
-
configMap = {};
|
|
1590
|
-
// Stores the raw callback return value (per scene name) to feed into the next initScene call as `pre`.
|
|
1591
|
-
// We keep this unformatted so developers receive exactly what they last returned.
|
|
1592
|
-
callbackReturnMap = {};
|
|
1593
|
-
getConfig(name) {
|
|
1594
|
-
if (name === void 0 || !this.configMap[name]) return void 0;
|
|
1595
|
-
return this.configMap[name];
|
|
1596
|
-
}
|
|
1597
|
-
waitManifest() {
|
|
1598
|
-
return this.manifestReady ?? Promise.resolve();
|
|
1599
|
-
}
|
|
1600
|
-
// Ensure URL is absolute; only convert when a relative path is provided
|
|
1601
|
-
// - Keep external and special schemes untouched (http, https, data, blob, about, file, mailto, etc.)
|
|
1602
|
-
// - Handle protocol-relative URLs (//example.com/path)
|
|
1603
|
-
// - Resolve relative paths against document.baseURI (respects <base href>)
|
|
1604
|
-
ensureAbsoluteUrl(raw) {
|
|
1605
|
-
if (!raw) return raw;
|
|
1606
|
-
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(raw)) {
|
|
1607
|
-
return raw;
|
|
1608
|
-
}
|
|
1609
|
-
if (raw.startsWith("//")) {
|
|
1610
|
-
return `${window.location.protocol}${raw}`;
|
|
1611
|
-
}
|
|
1612
|
-
try {
|
|
1613
|
-
return new URL(raw, document.baseURI).toString();
|
|
1614
|
-
} catch {
|
|
1615
|
-
return raw;
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
async setupManifest() {
|
|
1619
|
-
const manifest = await this.getPWAManifest();
|
|
1620
|
-
try {
|
|
1621
|
-
const xr = manifest?.xr_spatial_scene;
|
|
1622
|
-
if (!xr || typeof xr !== "object") return;
|
|
1623
|
-
const { overrides, ...topLevel } = xr;
|
|
1624
|
-
const windowRaw = deepMergePlain(topLevel, overrides?.window_scene);
|
|
1625
|
-
const volumeRaw = deepMergePlain(topLevel, overrides?.volume_scene);
|
|
1626
|
-
const windowNext = normalizeXRDefaultsToSceneOptions(windowRaw);
|
|
1627
|
-
const volumeNext = normalizeXRDefaultsToSceneOptions(volumeRaw);
|
|
1628
|
-
if (windowNext && Object.keys(windowNext).length > 0) {
|
|
1629
|
-
xr_window_defaults = windowNext;
|
|
1630
|
-
}
|
|
1631
|
-
if (volumeNext && Object.keys(volumeNext).length > 0) {
|
|
1632
|
-
xr_volume_defaults = volumeNext;
|
|
1633
|
-
}
|
|
1634
|
-
} catch (error) {
|
|
1635
|
-
console.warn(
|
|
1636
|
-
"SceneManager.setupManifest failed; using built-in defaults.",
|
|
1637
|
-
error?.message || error
|
|
1638
|
-
);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
open = (url, target, features) => {
|
|
1642
|
-
if (url?.startsWith(INTERNAL_SCHEMA_PREFIX)) {
|
|
1643
|
-
if (url.includes("createSpatialized2DElement") || url.includes("createAttachment")) {
|
|
1644
|
-
const token = (
|
|
1645
|
-
//@ts-ignore
|
|
1646
|
-
(window.webSpatial || window.__webspatialShell__)?.genToken?.()
|
|
1647
|
-
);
|
|
1648
|
-
if (token) {
|
|
1649
|
-
const command = url.includes("createAttachment") ? "createAttachment" : "createSpatialized2DElement";
|
|
1650
|
-
const host = window.location.host;
|
|
1651
|
-
const protocol = window.location.protocol;
|
|
1652
|
-
const finalURL = `${protocol}//${host}/${token}/?command=${command}`;
|
|
1653
|
-
const rid = new URL(url).searchParams.get("rid");
|
|
1654
|
-
const final = new URL(finalURL);
|
|
1655
|
-
if (rid) final.searchParams.set("rid", rid);
|
|
1656
|
-
return this.originalOpen(final.toString(), target, features);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
return this.originalOpen(url, target, features);
|
|
1660
|
-
}
|
|
1661
|
-
url = this.ensureAbsoluteUrl(url);
|
|
1662
|
-
if (target === "_self" || target === "_parent" || target === "_top") {
|
|
1663
|
-
const newWindow = this.originalOpen(url, target, features);
|
|
1664
|
-
return newWindow;
|
|
1665
|
-
}
|
|
1666
|
-
let cfg = target ? this.getConfig(target) : void 0;
|
|
1667
|
-
if (cfg === void 0) {
|
|
1668
|
-
const preFormatted = deepCloneJSON(getSceneDefaultConfig("window"));
|
|
1669
|
-
const [ans] = formatSceneConfig(preFormatted, "window");
|
|
1670
|
-
cfg = { ...ans, type: "window" };
|
|
1671
|
-
}
|
|
1672
|
-
const result = openSpatialSceneSync(
|
|
1673
|
-
url,
|
|
1674
|
-
cfg,
|
|
1675
|
-
target,
|
|
1676
|
-
features
|
|
1677
|
-
);
|
|
1678
|
-
const id = result.data?.id;
|
|
1679
|
-
if (id) {
|
|
1680
|
-
let focusCmd = new FocusScene(id);
|
|
1681
|
-
focusCmd.execute();
|
|
1682
|
-
}
|
|
1683
|
-
return result.data?.windowProxy;
|
|
1684
|
-
};
|
|
1685
|
-
initScene(name, callback, options) {
|
|
1686
|
-
const sceneType = options?.type ?? "window";
|
|
1687
|
-
const defaultConfigRaw = getSceneDefaultConfig(sceneType);
|
|
1688
|
-
const previousOrDefault = this.callbackReturnMap[name] ?? (() => {
|
|
1689
|
-
const cloned = deepCloneJSON(defaultConfigRaw);
|
|
1690
|
-
return cloned;
|
|
1691
|
-
})();
|
|
1692
|
-
const rawReturnVal = callback(previousOrDefault);
|
|
1693
|
-
const sanitizedReturnVal = sanitizeSceneOptionsUnits(
|
|
1694
|
-
deepCloneJSON(rawReturnVal)
|
|
1695
|
-
);
|
|
1696
|
-
const clonedForFormat = deepCloneJSON(sanitizedReturnVal);
|
|
1697
|
-
const baseDefaults = deepCloneJSON(getSceneDefaultConfig(sceneType));
|
|
1698
|
-
const mergedForFormat = deepMergePlain(baseDefaults, clonedForFormat);
|
|
1699
|
-
const [formattedConfig, errors] = formatSceneConfig(
|
|
1700
|
-
mergedForFormat,
|
|
1701
|
-
sceneType
|
|
1702
|
-
);
|
|
1703
|
-
if (errors.length > 0) {
|
|
1704
|
-
console.warn(`initScene ${name} with errors: ${errors.join(", ")}`);
|
|
1705
|
-
}
|
|
1706
|
-
this.callbackReturnMap[name] = sanitizedReturnVal;
|
|
1707
|
-
this.configMap[name] = {
|
|
1708
|
-
...formattedConfig,
|
|
1709
|
-
type: sceneType
|
|
1710
|
-
};
|
|
1711
|
-
}
|
|
1712
|
-
/**
|
|
1713
|
-
* Resolve and load a PWA manifest as JSON:
|
|
1714
|
-
* 1) Determine href:
|
|
1715
|
-
* - Prefer explicit manifestUrl if provided;
|
|
1716
|
-
* - Fallback to <link rel="manifest">, preferring the raw attribute over computed href.
|
|
1717
|
-
* 2) Normalize href to absolute using ensureAbsoluteUrl (respects <base href>).
|
|
1718
|
-
* 3) Handle data URLs inline:
|
|
1719
|
-
* - data:...;base64,... → atob then JSON.parse
|
|
1720
|
-
* - data:...,... → decodeURIComponent then JSON.parse
|
|
1721
|
-
* 4) Fetch with credentials same-origin first; if that fails (e.g., CORS), attempt unauthenticated fetch.
|
|
1722
|
-
* 5) Parse as JSON; if response body is text, parse the text as JSON.
|
|
1723
|
-
*/
|
|
1724
|
-
async getPWAManifest(manifestUrl) {
|
|
1725
|
-
let href = manifestUrl;
|
|
1726
|
-
if (!href) {
|
|
1727
|
-
const el = document.querySelector(
|
|
1728
|
-
'link[rel="manifest"]'
|
|
1729
|
-
);
|
|
1730
|
-
href = el?.getAttribute("href") || el?.href;
|
|
1731
|
-
}
|
|
1732
|
-
if (!href) return;
|
|
1733
|
-
href = this.ensureAbsoluteUrl(href);
|
|
1734
|
-
if (!href) return;
|
|
1735
|
-
if (href.startsWith("data:")) {
|
|
1736
|
-
try {
|
|
1737
|
-
const comma = href.indexOf(",");
|
|
1738
|
-
if (comma < 0) return;
|
|
1739
|
-
const meta = href.slice(5, comma);
|
|
1740
|
-
const data = href.slice(comma + 1);
|
|
1741
|
-
const isBase64 = /;base64/i.test(meta);
|
|
1742
|
-
const decoded = isBase64 ? atob(data) : decodeURIComponent(data);
|
|
1743
|
-
return JSON.parse(decoded);
|
|
1744
|
-
} catch {
|
|
1745
|
-
return;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
try {
|
|
1749
|
-
const res = await fetch(href, { credentials: "same-origin" });
|
|
1750
|
-
if (!res.ok) throw new Error(String(res.status));
|
|
1751
|
-
try {
|
|
1752
|
-
return await res.json();
|
|
1753
|
-
} catch {
|
|
1754
|
-
const t = await res.text();
|
|
1755
|
-
return JSON.parse(t);
|
|
1756
|
-
}
|
|
1757
|
-
} catch {
|
|
1758
|
-
try {
|
|
1759
|
-
const res = await fetch(href);
|
|
1760
|
-
if (!res.ok) return;
|
|
1761
|
-
try {
|
|
1762
|
-
return await res.json();
|
|
1763
|
-
} catch {
|
|
1764
|
-
const t = await res.text();
|
|
1765
|
-
return JSON.parse(t);
|
|
1766
|
-
}
|
|
1767
|
-
} catch {
|
|
1768
|
-
return;
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
};
|
|
1773
|
-
function sanitizeSceneOptionsUnits(val) {
|
|
1774
|
-
if (val?.defaultSize) {
|
|
1775
|
-
const keys = ["width", "height", "depth"];
|
|
1776
|
-
for (const k of keys) {
|
|
1777
|
-
if (k in val.defaultSize && !isValidSceneUnit(val.defaultSize[k])) {
|
|
1778
|
-
delete val.defaultSize[k];
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
if (val?.resizability) {
|
|
1783
|
-
const keys = ["minWidth", "minHeight", "maxWidth", "maxHeight"];
|
|
1784
|
-
for (const k of keys) {
|
|
1785
|
-
if (k in val.resizability && !isValidSceneUnit(val.resizability[k])) {
|
|
1786
|
-
delete val.resizability[k];
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
return val;
|
|
1791
|
-
}
|
|
1792
|
-
function pxToMeter(px) {
|
|
1793
|
-
return pointToPhysical(px);
|
|
1794
|
-
}
|
|
1795
|
-
function meterToPx(meter) {
|
|
1796
|
-
return physicalToPoint(meter);
|
|
1797
|
-
}
|
|
1798
|
-
function formatToNumber(str, targetUnit, defaultUnit) {
|
|
1799
|
-
if (typeof str === "number") {
|
|
1800
|
-
if (defaultUnit === "px" && targetUnit === "px" || defaultUnit === "m" && targetUnit === "m") {
|
|
1801
|
-
return str;
|
|
1802
|
-
}
|
|
1803
|
-
if (defaultUnit === "px" && targetUnit === "m") {
|
|
1804
|
-
return pxToMeter(str);
|
|
1805
|
-
} else if (defaultUnit === "m" && targetUnit === "px") {
|
|
1806
|
-
return meterToPx(str);
|
|
1807
|
-
}
|
|
1808
|
-
return str;
|
|
1809
|
-
}
|
|
1810
|
-
if (targetUnit === "m") {
|
|
1811
|
-
if (str.endsWith("m")) {
|
|
1812
|
-
return Number(str.slice(0, -1));
|
|
1813
|
-
} else if (str.endsWith("px")) {
|
|
1814
|
-
return pxToMeter(Number(str.slice(0, -2)));
|
|
1815
|
-
} else {
|
|
1816
|
-
throw new Error("formatToNumber: invalid str");
|
|
1817
|
-
}
|
|
1818
|
-
} else if (targetUnit === "px") {
|
|
1819
|
-
if (str.endsWith("px")) {
|
|
1820
|
-
return Number(str.slice(0, -2));
|
|
1821
|
-
} else if (str.endsWith("m")) {
|
|
1822
|
-
return meterToPx(Number(str.slice(0, -1)));
|
|
1823
|
-
} else {
|
|
1824
|
-
throw new Error("formatToNumber: invalid str");
|
|
1825
|
-
}
|
|
1826
|
-
} else {
|
|
1827
|
-
throw new Error("formatToNumber: invalid targetUnit");
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
function formatSceneConfig(config, sceneType) {
|
|
1831
|
-
const errors = [];
|
|
1832
|
-
const isWindow = sceneType === "window";
|
|
1833
|
-
if (!isValidSpatialSceneType(sceneType)) {
|
|
1834
|
-
errors.push(`sceneType`);
|
|
1835
|
-
}
|
|
1836
|
-
if (config.defaultSize) {
|
|
1837
|
-
const iterKeys = ["width", "height", "depth"];
|
|
1838
|
-
for (let k of iterKeys) {
|
|
1839
|
-
if (!(k in config.defaultSize)) continue;
|
|
1840
|
-
if (isValidSceneUnit(config.defaultSize[k])) {
|
|
1841
|
-
;
|
|
1842
|
-
config.defaultSize[k] = formatToNumber(
|
|
1843
|
-
config.defaultSize[k],
|
|
1844
|
-
isWindow ? "px" : "m",
|
|
1845
|
-
"px"
|
|
1846
|
-
);
|
|
1847
|
-
} else {
|
|
1848
|
-
delete config.defaultSize[k];
|
|
1849
|
-
errors.push(`defaultSize.${k}`);
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
if (config.resizability) {
|
|
1854
|
-
const iterKeys = ["minWidth", "minHeight", "maxWidth", "maxHeight"];
|
|
1855
|
-
for (let k of iterKeys) {
|
|
1856
|
-
if (!(k in config.resizability)) continue;
|
|
1857
|
-
if (isValidSceneUnit(config.resizability[k])) {
|
|
1858
|
-
;
|
|
1859
|
-
config.resizability[k] = formatToNumber(
|
|
1860
|
-
config.resizability[k],
|
|
1861
|
-
"px",
|
|
1862
|
-
"px"
|
|
1863
|
-
);
|
|
1864
|
-
} else {
|
|
1865
|
-
delete config.resizability[k];
|
|
1866
|
-
errors.push(`resizability.${k}`);
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
}
|
|
1870
|
-
if (config.worldScaling) {
|
|
1871
|
-
if (!isValidWorldScalingType(config.worldScaling)) {
|
|
1872
|
-
config.worldScaling = "automatic";
|
|
1873
|
-
errors.push("worldScaling");
|
|
1874
|
-
}
|
|
1875
|
-
}
|
|
1876
|
-
if (config.worldAlignment) {
|
|
1877
|
-
if (!isValidWorldAlignmentType(config.worldAlignment)) {
|
|
1878
|
-
config.worldAlignment = "automatic";
|
|
1879
|
-
errors.push("worldAlignment");
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
if (config.baseplateVisibility) {
|
|
1883
|
-
if (!isValidBaseplateVisibilityType(config.baseplateVisibility)) {
|
|
1884
|
-
config.baseplateVisibility = "automatic";
|
|
1885
|
-
errors.push("baseplateVisibility");
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
return [config, errors];
|
|
1889
|
-
}
|
|
1890
|
-
function initScene(name, callback, options) {
|
|
1891
|
-
return SceneManager.getInstance().initScene(name, callback, options);
|
|
1892
|
-
}
|
|
1893
|
-
function hijackWindowOpen(window2) {
|
|
1894
|
-
SceneManager.getInstance().init(window2);
|
|
1895
|
-
}
|
|
1896
|
-
function hijackWindowATag(openedWindow) {
|
|
1897
|
-
openedWindow.document.onclick = function(e) {
|
|
1898
|
-
let element = e.target;
|
|
1899
|
-
while (element) {
|
|
1900
|
-
if (element.tagName == "A") {
|
|
1901
|
-
if (handleATag(e, element)) {
|
|
1902
|
-
return false;
|
|
1903
|
-
}
|
|
1904
|
-
return true;
|
|
1905
|
-
}
|
|
1906
|
-
if (element.parentElement) {
|
|
1907
|
-
element = element.parentElement;
|
|
1908
|
-
} else {
|
|
1909
|
-
break;
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
function handleATag(event, link) {
|
|
1915
|
-
if (event.defaultPrevented) return false;
|
|
1916
|
-
const target = link.target;
|
|
1917
|
-
const url = link.href;
|
|
1918
|
-
if (target && target !== "_self") {
|
|
1919
|
-
event.preventDefault();
|
|
1920
|
-
window.open(url, target);
|
|
1921
|
-
return true;
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
function getSceneDefaultConfig(sceneType) {
|
|
1925
|
-
return sceneType === "window" ? xr_window_defaults || defaultSceneConfig : xr_volume_defaults || defaultSceneConfigVolume;
|
|
1926
|
-
}
|
|
1927
|
-
async function injectScenePolyfill() {
|
|
1928
|
-
if (!window.opener) return;
|
|
1929
|
-
const state = await SpatialScene.getInstance().getState();
|
|
1930
|
-
if (state !== "pending" /* pending */) return;
|
|
1931
|
-
function onContentLoaded(callback) {
|
|
1932
|
-
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
1933
|
-
callback();
|
|
1934
|
-
} else {
|
|
1935
|
-
document.addEventListener("DOMContentLoaded", callback);
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
onContentLoaded(async () => {
|
|
1939
|
-
await SceneManager.getInstance().waitManifest();
|
|
1940
|
-
const sceneType = window.xrCurrentSceneType ?? "window";
|
|
1941
|
-
const rawDefault = getSceneDefaultConfig(sceneType);
|
|
1942
|
-
const pre = deepCloneJSON(rawDefault);
|
|
1943
|
-
let cfg = pre;
|
|
1944
|
-
if (typeof window.xrCurrentSceneDefaults === "function") {
|
|
1945
|
-
try {
|
|
1946
|
-
cfg = await window.xrCurrentSceneDefaults?.(pre);
|
|
1947
|
-
} catch (error) {
|
|
1948
|
-
console.error(error);
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
await new Promise((resolve, reject) => {
|
|
1952
|
-
setTimeout(() => {
|
|
1953
|
-
resolve(null);
|
|
1954
|
-
}, 1e3);
|
|
1955
|
-
});
|
|
1956
|
-
const mergedCfg = deepMergePlain(deepCloneJSON(rawDefault), cfg);
|
|
1957
|
-
const [formattedConfig, errors] = formatSceneConfig(mergedCfg, sceneType);
|
|
1958
|
-
if (errors.length > 0) {
|
|
1959
|
-
console.warn(
|
|
1960
|
-
`window.xrCurrentSceneDefaults with errors: ${errors.join(", ")}`
|
|
1961
|
-
);
|
|
1962
|
-
}
|
|
1963
|
-
const finalCfg = {
|
|
1964
|
-
...formattedConfig,
|
|
1965
|
-
type: sceneType
|
|
1966
|
-
};
|
|
1967
|
-
await SpatialScene.getInstance().updateSceneCreationConfig(finalCfg);
|
|
1968
|
-
});
|
|
1969
|
-
}
|
|
1970
|
-
function injectSceneHook() {
|
|
1971
|
-
hijackWindowOpen(window);
|
|
1972
|
-
hijackWindowATag(window);
|
|
1973
|
-
injectScenePolyfill();
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
|
-
// src/SpatialWebEventCreator.ts
|
|
1977
|
-
function createSpatialEvent(type, detail) {
|
|
1978
|
-
return new CustomEvent(type, {
|
|
1979
|
-
bubbles: true,
|
|
1980
|
-
cancelable: false,
|
|
1981
|
-
detail
|
|
1982
|
-
});
|
|
1983
|
-
}
|
|
1984
|
-
|
|
1985
|
-
// src/SpatializedElement.ts
|
|
1986
|
-
var SpatializedElement = class extends SpatialObject {
|
|
1987
|
-
/**
|
|
1988
|
-
* Creates a new spatialized element with the specified ID.
|
|
1989
|
-
* Registers the element to receive spatial events.
|
|
1990
|
-
* @param id Unique identifier for this element
|
|
1991
|
-
*/
|
|
1992
|
-
constructor(id) {
|
|
1993
|
-
super(id);
|
|
1994
|
-
this.id = id;
|
|
1995
|
-
SpatialWebEvent.addEventReceiver(id, this.onReceiveEvent.bind(this));
|
|
1996
|
-
}
|
|
1997
|
-
/**
|
|
1998
|
-
* Updates the transformation matrix of this element in 3D space.
|
|
1999
|
-
* This affects the position, rotation, and scale of the element.
|
|
2000
|
-
* @param matrix The new transformation matrix
|
|
2001
|
-
* @returns Promise resolving when the transform is updated
|
|
2002
|
-
*/
|
|
2003
|
-
async updateTransform(matrix) {
|
|
2004
|
-
return new UpdateSpatializedElementTransform(this, matrix).execute();
|
|
2005
|
-
}
|
|
2006
|
-
/**
|
|
2007
|
-
* Information about the element's bounding cube.
|
|
2008
|
-
* Used for spatial calculations and hit testing.
|
|
2009
|
-
*/
|
|
2010
|
-
_cubeInfo;
|
|
2011
|
-
/**
|
|
2012
|
-
* Gets the current cube information for this element.
|
|
2013
|
-
* @returns The current CubeInfo or undefined if not set
|
|
2014
|
-
*/
|
|
2015
|
-
get cubeInfo() {
|
|
2016
|
-
return this._cubeInfo;
|
|
2017
|
-
}
|
|
2018
|
-
/**
|
|
2019
|
-
* The current transformation matrix of this element.
|
|
2020
|
-
*/
|
|
2021
|
-
_transform;
|
|
2022
|
-
/**
|
|
2023
|
-
* The inverse of the current transformation matrix.
|
|
2024
|
-
* Used for converting world coordinates to local coordinates.
|
|
2025
|
-
*/
|
|
2026
|
-
_transformInv;
|
|
2027
|
-
/**
|
|
2028
|
-
* Gets the current transformation matrix.
|
|
2029
|
-
* @returns The current transformation matrix or undefined if not set
|
|
2030
|
-
*/
|
|
2031
|
-
get transform() {
|
|
2032
|
-
return this._transform;
|
|
2033
|
-
}
|
|
2034
|
-
/**
|
|
2035
|
-
* Gets the inverse of the current transformation matrix.
|
|
2036
|
-
* @returns The inverse transformation matrix or undefined if not set
|
|
2037
|
-
*/
|
|
2038
|
-
get transformInv() {
|
|
2039
|
-
return this._transformInv;
|
|
2040
|
-
}
|
|
2041
|
-
/**
|
|
2042
|
-
* Processes events received from the WebSpatial environment.
|
|
2043
|
-
* Handles various spatial events like transforms, gestures, and interactions.
|
|
2044
|
-
* @param data The event data received from the WebSpatial system
|
|
2045
|
-
*/
|
|
2046
|
-
onReceiveEvent(data) {
|
|
2047
|
-
const { type } = data;
|
|
2048
|
-
if (type === "objectdestroy" /* objectdestroy */) {
|
|
2049
|
-
this.isDestroyed = true;
|
|
2050
|
-
} else if (type === "spatialtap" /* spatialtap */) {
|
|
2051
|
-
const event = createSpatialEvent(
|
|
2052
|
-
"spatialtap" /* spatialtap */,
|
|
2053
|
-
data.detail
|
|
2054
|
-
);
|
|
2055
|
-
this._onSpatialTap?.(event);
|
|
2056
|
-
} else if (type === "spatialdragstart" /* spatialdragstart */) {
|
|
2057
|
-
const dragStartEvent = createSpatialEvent(
|
|
2058
|
-
"spatialdragstart" /* spatialdragstart */,
|
|
2059
|
-
data.detail
|
|
2060
|
-
);
|
|
2061
|
-
this._onSpatialDragStart?.(dragStartEvent);
|
|
2062
|
-
} else if (type === "spatialdrag" /* spatialdrag */) {
|
|
2063
|
-
const event = createSpatialEvent(
|
|
2064
|
-
"spatialdrag" /* spatialdrag */,
|
|
2065
|
-
data.detail
|
|
2066
|
-
);
|
|
2067
|
-
this._onSpatialDrag?.(event);
|
|
2068
|
-
} else if (type === "spatialdragend" /* spatialdragend */) {
|
|
2069
|
-
const event = createSpatialEvent(
|
|
2070
|
-
"spatialdragend" /* spatialdragend */,
|
|
2071
|
-
data.detail
|
|
2072
|
-
);
|
|
2073
|
-
this._onSpatialDragEnd?.(event);
|
|
2074
|
-
} else if (type === "spatialrotate" /* spatialrotate */) {
|
|
2075
|
-
const event = createSpatialEvent(
|
|
2076
|
-
"spatialrotate" /* spatialrotate */,
|
|
2077
|
-
data.detail
|
|
2078
|
-
);
|
|
2079
|
-
this._onSpatialRotate?.(event);
|
|
2080
|
-
} else if (type === "spatialrotateend" /* spatialrotateend */) {
|
|
2081
|
-
const event = createSpatialEvent(
|
|
2082
|
-
"spatialrotateend" /* spatialrotateend */,
|
|
2083
|
-
data.detail
|
|
2084
|
-
);
|
|
2085
|
-
this._onSpatialRotateEnd?.(event);
|
|
2086
|
-
} else if (type === "spatialmagnify" /* spatialmagnify */) {
|
|
2087
|
-
const event = createSpatialEvent(
|
|
2088
|
-
"spatialmagnify" /* spatialmagnify */,
|
|
2089
|
-
data.detail
|
|
2090
|
-
);
|
|
2091
|
-
this._onSpatialMagnify?.(event);
|
|
2092
|
-
} else if (type === "spatialmagnifyend" /* spatialmagnifyend */) {
|
|
2093
|
-
const event = createSpatialEvent(
|
|
2094
|
-
"spatialmagnifyend" /* spatialmagnifyend */,
|
|
2095
|
-
data.detail
|
|
2096
|
-
);
|
|
2097
|
-
this._onSpatialMagnifyEnd?.(event);
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
_onSpatialTap;
|
|
2101
|
-
set onSpatialTap(value) {
|
|
2102
|
-
this._onSpatialTap = value;
|
|
2103
|
-
this.updateProperties({
|
|
2104
|
-
enableTapGesture: value !== void 0
|
|
2105
|
-
});
|
|
2106
|
-
}
|
|
2107
|
-
_onSpatialDragStart;
|
|
2108
|
-
set onSpatialDragStart(value) {
|
|
2109
|
-
this._onSpatialDragStart = value;
|
|
2110
|
-
this.updateProperties({
|
|
2111
|
-
enableDragStartGesture: this._onSpatialDragStart !== void 0
|
|
2112
|
-
});
|
|
2113
|
-
}
|
|
2114
|
-
_onSpatialDrag;
|
|
2115
|
-
set onSpatialDrag(value) {
|
|
2116
|
-
this._onSpatialDrag = value;
|
|
2117
|
-
this.updateProperties({
|
|
2118
|
-
enableDragGesture: this._onSpatialDrag !== void 0
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
_onSpatialDragEnd;
|
|
2122
|
-
set onSpatialDragEnd(value) {
|
|
2123
|
-
this._onSpatialDragEnd = value;
|
|
2124
|
-
this.updateProperties({
|
|
2125
|
-
enableDragEndGesture: value !== void 0
|
|
2126
|
-
});
|
|
2127
|
-
}
|
|
2128
|
-
_onSpatialRotate;
|
|
2129
|
-
set onSpatialRotate(value) {
|
|
2130
|
-
this._onSpatialRotate = value;
|
|
2131
|
-
this.updateProperties({
|
|
2132
|
-
enableRotateGesture: this._onSpatialRotate !== void 0
|
|
2133
|
-
});
|
|
2134
|
-
}
|
|
2135
|
-
_onSpatialRotateEnd;
|
|
2136
|
-
set onSpatialRotateEnd(value) {
|
|
2137
|
-
this._onSpatialRotateEnd = value;
|
|
2138
|
-
this.updateProperties({
|
|
2139
|
-
enableRotateEndGesture: value !== void 0
|
|
2140
|
-
});
|
|
2141
|
-
}
|
|
2142
|
-
_onSpatialMagnify;
|
|
2143
|
-
set onSpatialMagnify(value) {
|
|
2144
|
-
this._onSpatialMagnify = value;
|
|
2145
|
-
this.updateProperties({
|
|
2146
|
-
enableMagnifyGesture: value !== void 0
|
|
2147
|
-
});
|
|
2148
|
-
}
|
|
2149
|
-
_onSpatialMagnifyEnd;
|
|
2150
|
-
set onSpatialMagnifyEnd(value) {
|
|
2151
|
-
this._onSpatialMagnifyEnd = value;
|
|
2152
|
-
this.updateProperties({
|
|
2153
|
-
enableMagnifyEndGesture: value !== void 0
|
|
2154
|
-
});
|
|
2155
|
-
}
|
|
2156
|
-
/**
|
|
2157
|
-
* Cleans up resources when this element is destroyed.
|
|
2158
|
-
* Removes event receivers to prevent memory leaks.
|
|
2159
|
-
*/
|
|
2160
|
-
onDestroy() {
|
|
2161
|
-
SpatialWebEvent.removeEventReceiver(this.id);
|
|
2162
|
-
}
|
|
2163
|
-
};
|
|
2164
|
-
|
|
2165
|
-
// src/Spatialized2DElement.ts
|
|
2166
|
-
var Spatialized2DElement = class extends SpatializedElement {
|
|
2167
|
-
/**
|
|
2168
|
-
* Creates a new spatialized 2D element.
|
|
2169
|
-
* @param id Unique identifier for this element
|
|
2170
|
-
* @param windowProxy Reference to the window object containing the 2D content
|
|
2171
|
-
*/
|
|
2172
|
-
constructor(id, windowProxy) {
|
|
2173
|
-
super(id);
|
|
2174
|
-
this.windowProxy = windowProxy;
|
|
2175
|
-
hijackWindowATag(windowProxy);
|
|
2176
|
-
}
|
|
2177
|
-
/**
|
|
2178
|
-
* Updates the properties of this 2D element.
|
|
2179
|
-
* This can include size, position, background, and other visual properties.
|
|
2180
|
-
* @param properties Partial set of properties to update
|
|
2181
|
-
* @returns Promise resolving when the update is complete
|
|
2182
|
-
*/
|
|
2183
|
-
async updateProperties(properties) {
|
|
2184
|
-
return new UpdateSpatialized2DElementProperties(this, properties).execute();
|
|
2185
|
-
}
|
|
2186
|
-
/**
|
|
2187
|
-
* Adds a child spatialized element to this 2D element.
|
|
2188
|
-
* This allows for creating hierarchical structures of spatial elements.
|
|
2189
|
-
* @param element The child element to add
|
|
2190
|
-
* @returns Promise resolving when the element is added
|
|
2191
|
-
*/
|
|
2192
|
-
async addSpatializedElement(element) {
|
|
2193
|
-
return new AddSpatializedElementToSpatialized2DElement(
|
|
2194
|
-
this,
|
|
2195
|
-
element
|
|
2196
|
-
).execute();
|
|
2197
|
-
}
|
|
2198
|
-
};
|
|
2199
|
-
|
|
2200
|
-
// src/SpatializedStatic3DElement.ts
|
|
2201
|
-
var SpatializedStatic3DElement = class extends SpatializedElement {
|
|
2202
|
-
/**
|
|
2203
|
-
* Creates a new spatialized static 3D element with the specified ID and URL.
|
|
2204
|
-
* Registers the element to receive spatial events.
|
|
2205
|
-
* @param id Unique identifier for this element
|
|
2206
|
-
* @param modelURL URL of the 3D model
|
|
2207
|
-
* @param sources Optional fallback model sources
|
|
2208
|
-
* @param loading Initial loading mode (`'eager'` by default)
|
|
2209
|
-
*/
|
|
2210
|
-
constructor(id, modelURL, sources, loading = "eager") {
|
|
2211
|
-
super(id);
|
|
2212
|
-
this.modelURL = modelURL;
|
|
2213
|
-
this.sources = sources;
|
|
2214
|
-
this._loading = loading;
|
|
2215
|
-
}
|
|
2216
|
-
/**
|
|
2217
|
-
* Promise resolver for the ready state.
|
|
2218
|
-
* Used to resolve the ready promise when the model is loaded.
|
|
2219
|
-
*/
|
|
2220
|
-
_readyResolve;
|
|
2221
|
-
/**
|
|
2222
|
-
* Caches the last model URL to detect changes.
|
|
2223
|
-
* Used to reset the ready promise when the model URL changes.
|
|
2224
|
-
*/
|
|
2225
|
-
modelURL;
|
|
2226
|
-
// @TODO: Deprecate modelURL property from Web and Swift code
|
|
2227
|
-
get modelUrl() {
|
|
2228
|
-
return this.modelURL;
|
|
2229
|
-
}
|
|
2230
|
-
/**
|
|
2231
|
-
* Caches the last sources array to detect changes.
|
|
2232
|
-
*/
|
|
2233
|
-
sources;
|
|
2234
|
-
/**
|
|
2235
|
-
* The model URL that was successfully loaded by the native runtime.
|
|
2236
|
-
*/
|
|
2237
|
-
_currentSrc = "";
|
|
2238
|
-
get currentSrc() {
|
|
2239
|
-
return this._currentSrc;
|
|
2240
|
-
}
|
|
2241
|
-
/**
|
|
2242
|
-
* Creates a new promise for tracking the ready state of the model.
|
|
2243
|
-
* @returns Promise that resolves when the model is loaded (true) or fails to load (false)
|
|
2244
|
-
*/
|
|
2245
|
-
createReadyPromise() {
|
|
2246
|
-
this._readyResolve?.(false);
|
|
2247
|
-
return new Promise((resolve) => {
|
|
2248
|
-
this._readyResolve = resolve;
|
|
2249
|
-
});
|
|
2250
|
-
}
|
|
2251
|
-
/**
|
|
2252
|
-
* Promise that resolves when the model is loaded.
|
|
2253
|
-
* Resolves to true on successful load, false on failure.
|
|
2254
|
-
*/
|
|
2255
|
-
ready = this.createReadyPromise();
|
|
2256
|
-
/**
|
|
2257
|
-
* Updates the properties of this static 3D element.
|
|
2258
|
-
* Handles special case for modelURL changes by resetting the ready promise.
|
|
2259
|
-
* @param properties Partial set of properties to update
|
|
2260
|
-
* @returns Promise resolving when the update is complete
|
|
2261
|
-
*/
|
|
2262
|
-
async updateProperties(properties) {
|
|
2263
|
-
let needsReadyReset = false;
|
|
2264
|
-
if (properties.modelURL !== void 0) {
|
|
2265
|
-
if (this.modelURL !== properties.modelURL) {
|
|
2266
|
-
this.modelURL = properties.modelURL;
|
|
2267
|
-
needsReadyReset = true;
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
if (properties.sources !== void 0) {
|
|
2271
|
-
const prevJson = JSON.stringify(this.sources);
|
|
2272
|
-
const nextJson = JSON.stringify(properties.sources);
|
|
2273
|
-
if (prevJson !== nextJson) {
|
|
2274
|
-
this.sources = properties.sources;
|
|
2275
|
-
needsReadyReset = true;
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
if (needsReadyReset) {
|
|
2279
|
-
this.ready = this.createReadyPromise();
|
|
2280
|
-
}
|
|
2281
|
-
if (properties.autoplay !== void 0) {
|
|
2282
|
-
this._autoplay = properties.autoplay;
|
|
2283
|
-
}
|
|
2284
|
-
if (properties.loop !== void 0) {
|
|
2285
|
-
this._loop = properties.loop;
|
|
2286
|
-
}
|
|
2287
|
-
if (properties.playbackRate !== void 0) {
|
|
2288
|
-
if (!this._paused) {
|
|
2289
|
-
this._currentTime = this.currentTime;
|
|
2290
|
-
this._anchorTimestamp = Date.now();
|
|
2291
|
-
}
|
|
2292
|
-
this._playbackRate = properties.playbackRate;
|
|
2293
|
-
}
|
|
2294
|
-
if (properties.currentTime !== void 0) {
|
|
2295
|
-
this._currentTime = properties.currentTime;
|
|
2296
|
-
this._anchorTimestamp = Date.now();
|
|
2297
|
-
}
|
|
2298
|
-
if (properties.loading !== void 0) {
|
|
2299
|
-
this._loading = properties.loading;
|
|
2300
|
-
}
|
|
2301
|
-
return new UpdateSpatializedStatic3DElementProperties(
|
|
2302
|
-
this,
|
|
2303
|
-
properties
|
|
2304
|
-
).execute();
|
|
2305
|
-
}
|
|
2306
|
-
/**
|
|
2307
|
-
* Total animation duration in seconds, synced from native.
|
|
2308
|
-
*/
|
|
2309
|
-
_duration = 0;
|
|
2310
|
-
/**
|
|
2311
|
-
* Returns the total animation duration in seconds.
|
|
2312
|
-
*/
|
|
2313
|
-
get duration() {
|
|
2314
|
-
return this._duration;
|
|
2315
|
-
}
|
|
2316
|
-
/**
|
|
2317
|
-
* Playback speed multiplier.
|
|
2318
|
-
*/
|
|
2319
|
-
_playbackRate = 1;
|
|
2320
|
-
/**
|
|
2321
|
-
* Returns the current playback rate.
|
|
2322
|
-
*/
|
|
2323
|
-
get playbackRate() {
|
|
2324
|
-
return this._playbackRate;
|
|
2325
|
-
}
|
|
2326
|
-
/**
|
|
2327
|
-
* Sets the playback rate and sends it to native.
|
|
2328
|
-
*/
|
|
2329
|
-
set playbackRate(value) {
|
|
2330
|
-
this.updateProperties({ playbackRate: value });
|
|
2331
|
-
}
|
|
2332
|
-
/**
|
|
2333
|
-
* Last playback position sampled from native (seconds).
|
|
2334
|
-
*/
|
|
2335
|
-
_currentTime = 0;
|
|
2336
|
-
/**
|
|
2337
|
-
* Unix epoch time (ms) corresponding to `_currentTime`. Sourced from the
|
|
2338
|
-
* native `timestamp` on samples, or `Date.now()` on local seeks/transitions.
|
|
2339
|
-
*/
|
|
2340
|
-
_anchorTimestamp = 0;
|
|
2341
|
-
clampTime(time) {
|
|
2342
|
-
if (!Number.isFinite(time) || time < 0) return 0;
|
|
2343
|
-
if (time > this._duration) {
|
|
2344
|
-
return this.loop && this.duration > 0 ? time % this._duration : this.duration;
|
|
2345
|
-
}
|
|
2346
|
-
return time;
|
|
2347
|
-
}
|
|
2348
|
-
/**
|
|
2349
|
-
* Returns the current (un-scaled) playback position in seconds. While
|
|
2350
|
-
* playing, the value is extrapolated from the last anchor using
|
|
2351
|
-
* `playbackRate` and clamped to `[0, duration]`; while paused it returns
|
|
2352
|
-
* the anchor directly.
|
|
2353
|
-
*/
|
|
2354
|
-
get currentTime() {
|
|
2355
|
-
if (this._paused) return this._currentTime;
|
|
2356
|
-
const elapsed = (Date.now() - this._anchorTimestamp) / 1e3;
|
|
2357
|
-
return this.clampTime(this._currentTime + elapsed * this._playbackRate);
|
|
2358
|
-
}
|
|
2359
|
-
/**
|
|
2360
|
-
* Seeks the animation to `value` seconds (clamped to `[0, duration]`) and
|
|
2361
|
-
* forwards the request to native.
|
|
2362
|
-
*/
|
|
2363
|
-
set currentTime(value) {
|
|
2364
|
-
const time = Number.isNaN(value) ? 0 : clamp(value, 0, this.duration);
|
|
2365
|
-
this.updateProperties({ currentTime: time });
|
|
2366
|
-
}
|
|
2367
|
-
/**
|
|
2368
|
-
* Whether the animation is currently paused.
|
|
2369
|
-
*/
|
|
2370
|
-
_paused = true;
|
|
2371
|
-
/**
|
|
2372
|
-
* Returns whether the animation is currently paused.
|
|
2373
|
-
*/
|
|
2374
|
-
get paused() {
|
|
2375
|
-
return this._paused;
|
|
2376
|
-
}
|
|
2377
|
-
/**
|
|
2378
|
-
* Callback for animation state changes.
|
|
2379
|
-
*/
|
|
2380
|
-
_onAnimationStateChangeCallback;
|
|
2381
|
-
/**
|
|
2382
|
-
* Sets the callback for animation state changes.
|
|
2383
|
-
*/
|
|
2384
|
-
set onAnimationStateChangeCallback(callback) {
|
|
2385
|
-
this._onAnimationStateChangeCallback = callback;
|
|
2386
|
-
}
|
|
2387
|
-
/**
|
|
2388
|
-
* Starts or resumes animation playback.
|
|
2389
|
-
* @returns Promise resolving when the command is sent
|
|
2390
|
-
*/
|
|
2391
|
-
async play() {
|
|
2392
|
-
if (this._paused) {
|
|
2393
|
-
this._anchorTimestamp = Date.now();
|
|
2394
|
-
}
|
|
2395
|
-
this._paused = false;
|
|
2396
|
-
await this.updateProperties({ animationPaused: false });
|
|
2397
|
-
}
|
|
2398
|
-
/**
|
|
2399
|
-
* Pauses animation playback.
|
|
2400
|
-
* @returns Promise resolving when the command is sent
|
|
2401
|
-
*/
|
|
2402
|
-
async pause() {
|
|
2403
|
-
if (!this._paused) {
|
|
2404
|
-
this._currentTime = this.currentTime;
|
|
2405
|
-
this._anchorTimestamp = Date.now();
|
|
2406
|
-
}
|
|
2407
|
-
this._paused = true;
|
|
2408
|
-
await this.updateProperties({ animationPaused: true });
|
|
2409
|
-
}
|
|
2410
|
-
/**
|
|
2411
|
-
* Processes events received from the WebSpatial environment.
|
|
2412
|
-
* Handles model loading events in addition to base spatial events.
|
|
2413
|
-
* @param data The event data received from the WebSpatial system
|
|
2414
|
-
*/
|
|
2415
|
-
onReceiveEvent(data) {
|
|
2416
|
-
if (data.type === "modelloaded" /* modelloaded */) {
|
|
2417
|
-
this._currentSrc = data.detail?.src ?? this.modelURL ?? "";
|
|
2418
|
-
this._onLoadCallback?.();
|
|
2419
|
-
this._readyResolve?.(true);
|
|
2420
|
-
} else if (data.type === "modelloadfailed" /* modelloadfailed */) {
|
|
2421
|
-
this._onLoadFailureCallback?.();
|
|
2422
|
-
this._readyResolve?.(false);
|
|
2423
|
-
} else if (data.type === "animationstatechange" /* animationstatechange */) {
|
|
2424
|
-
this._paused = data.detail.paused;
|
|
2425
|
-
this._duration = data.detail.duration;
|
|
2426
|
-
this._currentTime = data.detail.currentTime ?? 0;
|
|
2427
|
-
this._anchorTimestamp = data.detail.timestamp ?? Date.now();
|
|
2428
|
-
this._onAnimationStateChangeCallback?.(data.detail);
|
|
2429
|
-
} else {
|
|
2430
|
-
super.onReceiveEvent(data);
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Whether the model should automatically play its first animation on load.
|
|
2435
|
-
*/
|
|
2436
|
-
_autoplay = false;
|
|
2437
|
-
/**
|
|
2438
|
-
* Returns whether autoplay is enabled for this element.
|
|
2439
|
-
*/
|
|
2440
|
-
get autoplay() {
|
|
2441
|
-
return this._autoplay;
|
|
2442
|
-
}
|
|
2443
|
-
/**
|
|
2444
|
-
* Asset fetch policy. `'lazy'` defers fetching until the host signals the
|
|
2445
|
-
* element is in view; `'eager'` fetches immediately.
|
|
2446
|
-
*/
|
|
2447
|
-
_loading = "eager";
|
|
2448
|
-
get loading() {
|
|
2449
|
-
return this._loading;
|
|
2450
|
-
}
|
|
2451
|
-
/**
|
|
2452
|
-
* Whether the model animation should loop continuously.
|
|
2453
|
-
*/
|
|
2454
|
-
_loop = false;
|
|
2455
|
-
/**
|
|
2456
|
-
* Returns whether loop is enabled for this element.
|
|
2457
|
-
*/
|
|
2458
|
-
get loop() {
|
|
2459
|
-
return this._loop;
|
|
2460
|
-
}
|
|
2461
|
-
/**
|
|
2462
|
-
* Callback function for successful model loading.
|
|
2463
|
-
*/
|
|
2464
|
-
_onLoadCallback;
|
|
2465
|
-
/**
|
|
2466
|
-
* Sets the callback function for successful model loading.
|
|
2467
|
-
* @param callback Function to call when the model is loaded successfully
|
|
2468
|
-
*/
|
|
2469
|
-
set onLoadCallback(callback) {
|
|
2470
|
-
this._onLoadCallback = callback;
|
|
2471
|
-
}
|
|
2472
|
-
/**
|
|
2473
|
-
* Callback function for model loading failure.
|
|
2474
|
-
*/
|
|
2475
|
-
_onLoadFailureCallback;
|
|
2476
|
-
/**
|
|
2477
|
-
* Sets the callback function for model loading failure.
|
|
2478
|
-
* @param callback Function to call when the model fails to load
|
|
2479
|
-
*/
|
|
2480
|
-
set onLoadFailureCallback(callback) {
|
|
2481
|
-
this._onLoadFailureCallback = callback;
|
|
2482
|
-
}
|
|
2483
|
-
updateModelTransform(transform) {
|
|
2484
|
-
const modelTransform = Array.from(transform.toFloat64Array());
|
|
2485
|
-
this.updateProperties({ modelTransform });
|
|
2486
|
-
}
|
|
2487
|
-
};
|
|
2488
|
-
function clamp(num, min, max) {
|
|
2489
|
-
return num <= min ? min : num >= max ? max : num;
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
// src/SpatializedDynamic3DElement.ts
|
|
2493
|
-
var SpatializedDynamic3DElement = class extends SpatializedElement {
|
|
2494
|
-
children = [];
|
|
2495
|
-
events = {};
|
|
2496
|
-
constructor(id) {
|
|
2497
|
-
super(id);
|
|
2498
|
-
}
|
|
2499
|
-
async addEntity(entity) {
|
|
2500
|
-
const ans = new SetParentForEntityCommand(entity.id, this.id).execute();
|
|
2501
|
-
this.children.push(entity);
|
|
2502
|
-
entity.parent = this;
|
|
2503
|
-
return ans;
|
|
2504
|
-
}
|
|
2505
|
-
addEvent(type, callback) {
|
|
2506
|
-
this.events[type] = callback;
|
|
2507
|
-
}
|
|
2508
|
-
removeEvent(eventName) {
|
|
2509
|
-
if (this.events[eventName]) {
|
|
2510
|
-
delete this.events[eventName];
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
dispatchEvent(evt) {
|
|
2514
|
-
this.events[evt.type]?.(evt);
|
|
2515
|
-
}
|
|
2516
|
-
async updateProperties(properties) {
|
|
2517
|
-
return new UpdateSpatializedDynamic3DElementProperties(
|
|
2518
|
-
this,
|
|
2519
|
-
properties
|
|
2520
|
-
).execute();
|
|
2521
|
-
}
|
|
2522
|
-
};
|
|
2523
|
-
|
|
2524
|
-
// src/SpatializedElementCreator.ts
|
|
2525
|
-
async function createSpatialized2DElement() {
|
|
2526
|
-
const result = await createNativeSpatialDiv();
|
|
2527
|
-
if (!result.success) {
|
|
2528
|
-
throw new Error("createSpatialized2DElement failed");
|
|
2529
|
-
} else {
|
|
2530
|
-
const { id, windowProxy } = result.data;
|
|
2531
|
-
windowProxy.document.head.innerHTML = `<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2532
|
-
<base href="${document.baseURI}">`;
|
|
2533
|
-
return new Spatialized2DElement(id, windowProxy);
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
async function createSpatializedStatic3DElement(modelURL, sources, loading = "eager") {
|
|
2537
|
-
const result = await new CreateSpatializedStatic3DElementCommand(
|
|
2538
|
-
modelURL,
|
|
2539
|
-
sources,
|
|
2540
|
-
loading
|
|
2541
|
-
).execute();
|
|
2542
|
-
if (!result.success) {
|
|
2543
|
-
throw new Error("createSpatializedStatic3DElement failed");
|
|
2544
|
-
} else {
|
|
2545
|
-
const { id } = result.data;
|
|
2546
|
-
return new SpatializedStatic3DElement(id, modelURL, sources, loading);
|
|
2547
|
-
}
|
|
2548
|
-
}
|
|
2549
|
-
async function createSpatializedDynamic3DElement() {
|
|
2550
|
-
const result = await new CreateSpatializedDynamic3DElementCommand().execute();
|
|
2551
|
-
if (!result.success) {
|
|
2552
|
-
throw new Error("createSpatializedDynamic3DElement failed");
|
|
2553
|
-
} else {
|
|
2554
|
-
const { id } = result.data;
|
|
2555
|
-
return new SpatializedDynamic3DElement(id);
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
// src/reality/Attachment.ts
|
|
2560
|
-
var Attachment = class extends SpatialObject {
|
|
2561
|
-
constructor(id, windowProxy, options) {
|
|
2562
|
-
super(id);
|
|
2563
|
-
this.windowProxy = windowProxy;
|
|
2564
|
-
this.options = options;
|
|
2565
|
-
}
|
|
2566
|
-
getContainer() {
|
|
2567
|
-
return this.windowProxy.document.body;
|
|
2568
|
-
}
|
|
2569
|
-
getWindowProxy() {
|
|
2570
|
-
return this.windowProxy;
|
|
2571
|
-
}
|
|
2572
|
-
async update(options) {
|
|
2573
|
-
if (this.isDestroyed) return;
|
|
2574
|
-
if (options.position) this.options.position = options.position;
|
|
2575
|
-
if (options.size) this.options.size = options.size;
|
|
2576
|
-
return new UpdateAttachmentEntityCommand(this.id, options).execute();
|
|
2577
|
-
}
|
|
2578
|
-
};
|
|
2579
|
-
async function createAttachmentEntity(options) {
|
|
2580
|
-
const result = await createNativeAttachment(options);
|
|
2581
|
-
if (!result.success) {
|
|
2582
|
-
throw new Error("createAttachmentEntity failed: " + result?.errorMessage);
|
|
2583
|
-
}
|
|
2584
|
-
const { id, windowProxy } = result.data;
|
|
2585
|
-
await new InitializeAttachmentCommand(id, options).execute();
|
|
2586
|
-
return new Attachment(id, windowProxy, options);
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
|
-
// src/reality/entity/SpatialEntity.ts
|
|
2590
|
-
var SpatialEntity = class extends SpatialObject {
|
|
2591
|
-
constructor(id, userData) {
|
|
2592
|
-
super(id);
|
|
2593
|
-
this.userData = userData;
|
|
2594
|
-
SpatialWebEvent.addEventReceiver(id, this.onReceiveEvent);
|
|
2595
|
-
}
|
|
2596
|
-
position = { x: 0, y: 0, z: 0 };
|
|
2597
|
-
rotation = { x: 0, y: 0, z: 0 };
|
|
2598
|
-
scale = { x: 1, y: 1, z: 1 };
|
|
2599
|
-
events = {};
|
|
2600
|
-
children = [];
|
|
2601
|
-
parent = null;
|
|
2602
|
-
_enableInput = false;
|
|
2603
|
-
get enableInput() {
|
|
2604
|
-
return this._enableInput;
|
|
2605
|
-
}
|
|
2606
|
-
set enableInput(value) {
|
|
2607
|
-
if (this._enableInput === value) return;
|
|
2608
|
-
this._enableInput = value;
|
|
2609
|
-
void this.updateEntityEvent("spatialtap", value).catch((err) => {
|
|
2610
|
-
console.error("enableInput updateEntityEvent failed", "spatialtap", err);
|
|
2611
|
-
if (this._enableInput === value) {
|
|
2612
|
-
this._enableInput = !value;
|
|
2613
|
-
}
|
|
2614
|
-
});
|
|
2615
|
-
}
|
|
2616
|
-
async addComponent(component) {
|
|
2617
|
-
return new AddComponentToEntityCommand(this, component).execute();
|
|
2618
|
-
}
|
|
2619
|
-
async removeComponent(component) {
|
|
2620
|
-
return new RemoveComponentFromEntityCommand(this, component).execute();
|
|
2621
|
-
}
|
|
2622
|
-
async setPosition(position) {
|
|
2623
|
-
return this.updateTransform({ position });
|
|
2624
|
-
}
|
|
2625
|
-
async setRotation(rotation) {
|
|
2626
|
-
return this.updateTransform({ rotation });
|
|
2627
|
-
}
|
|
2628
|
-
async setScale(scale) {
|
|
2629
|
-
return this.updateTransform({ scale });
|
|
2630
|
-
}
|
|
2631
|
-
async addEntity(ent) {
|
|
2632
|
-
const ans = await new SetParentForEntityCommand(ent.id, this.id).execute();
|
|
2633
|
-
this.children.push(ent);
|
|
2634
|
-
ent.parent = this;
|
|
2635
|
-
return ans;
|
|
2636
|
-
}
|
|
2637
|
-
async removeFromParent() {
|
|
2638
|
-
const ans = await new SetParentForEntityCommand(
|
|
2639
|
-
this.id,
|
|
2640
|
-
void 0
|
|
2641
|
-
).execute();
|
|
2642
|
-
if (this.parent) {
|
|
2643
|
-
this.parent.children = this.parent.children.filter(
|
|
2644
|
-
(child) => child.id !== this.id
|
|
2645
|
-
);
|
|
2646
|
-
this.parent = null;
|
|
2647
|
-
}
|
|
2648
|
-
return ans;
|
|
2649
|
-
}
|
|
2650
|
-
async updateTransform(properties) {
|
|
2651
|
-
this.position = properties.position ?? this.position;
|
|
2652
|
-
this.rotation = properties.rotation ?? this.rotation;
|
|
2653
|
-
this.scale = properties.scale ?? this.scale;
|
|
2654
|
-
return new UpdateEntityPropertiesCommand(this, properties).execute();
|
|
2655
|
-
}
|
|
2656
|
-
async addEvent(type, callback) {
|
|
2657
|
-
if (this.events[type]) {
|
|
2658
|
-
this.events[type] = callback;
|
|
2659
|
-
} else {
|
|
2660
|
-
try {
|
|
2661
|
-
await this.updateEntityEvent(type, true);
|
|
2662
|
-
this.events[type] = callback;
|
|
2663
|
-
} catch (error) {
|
|
2664
|
-
console.error("addEvent failed", type);
|
|
2665
|
-
}
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
async removeEvent(eventName) {
|
|
2669
|
-
if (this.events[eventName]) {
|
|
2670
|
-
delete this.events[eventName];
|
|
2671
|
-
try {
|
|
2672
|
-
await this.updateEntityEvent(eventName, false);
|
|
2673
|
-
} catch (error) {
|
|
2674
|
-
console.error("removeEvent failed", eventName);
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
async updateEntityEvent(eventName, isEnable) {
|
|
2679
|
-
return new UpdateEntityEventCommand(this, eventName, isEnable).execute();
|
|
2680
|
-
}
|
|
2681
|
-
onReceiveEvent = (data) => {
|
|
2682
|
-
const { type } = data;
|
|
2683
|
-
if (type === "objectdestroy" /* objectdestroy */) {
|
|
2684
|
-
this.isDestroyed = true;
|
|
2685
|
-
} else if (type === "spatialtap" /* spatialtap */) {
|
|
2686
|
-
const evt = createSpatialEvent("spatialtap" /* spatialtap */, data.detail);
|
|
2687
|
-
this.dispatchEvent(evt);
|
|
2688
|
-
} else if (type === "spatialdragstart" /* spatialdragstart */) {
|
|
2689
|
-
const evt = createSpatialEvent(
|
|
2690
|
-
"spatialdragstart" /* spatialdragstart */,
|
|
2691
|
-
data.detail
|
|
2692
|
-
);
|
|
2693
|
-
this.dispatchEvent(evt);
|
|
2694
|
-
} else if (type === "spatialdrag" /* spatialdrag */) {
|
|
2695
|
-
const evt = createSpatialEvent("spatialdrag" /* spatialdrag */, data.detail);
|
|
2696
|
-
this.dispatchEvent(evt);
|
|
2697
|
-
} else if (type === "spatialdragend" /* spatialdragend */) {
|
|
2698
|
-
const evt = createSpatialEvent(
|
|
2699
|
-
"spatialdragend" /* spatialdragend */,
|
|
2700
|
-
data.detail
|
|
2701
|
-
);
|
|
2702
|
-
this.dispatchEvent(evt);
|
|
2703
|
-
} else if (type === "spatialrotate" /* spatialrotate */) {
|
|
2704
|
-
const evt = createSpatialEvent(
|
|
2705
|
-
"spatialrotate" /* spatialrotate */,
|
|
2706
|
-
data.detail
|
|
2707
|
-
);
|
|
2708
|
-
this.dispatchEvent(evt);
|
|
2709
|
-
} else if (type === "spatialrotateend" /* spatialrotateend */) {
|
|
2710
|
-
const evt = createSpatialEvent(
|
|
2711
|
-
"spatialrotateend" /* spatialrotateend */,
|
|
2712
|
-
data.detail
|
|
2713
|
-
);
|
|
2714
|
-
this.dispatchEvent(evt);
|
|
2715
|
-
} else if (type === "spatialmagnify" /* spatialmagnify */) {
|
|
2716
|
-
const evt = createSpatialEvent(
|
|
2717
|
-
"spatialmagnify" /* spatialmagnify */,
|
|
2718
|
-
data.detail
|
|
2719
|
-
);
|
|
2720
|
-
this.dispatchEvent(evt);
|
|
2721
|
-
} else if (type === "spatialmagnifyend" /* spatialmagnifyend */) {
|
|
2722
|
-
const evt = createSpatialEvent(
|
|
2723
|
-
"spatialmagnifyend" /* spatialmagnifyend */,
|
|
2724
|
-
data.detail
|
|
2725
|
-
);
|
|
2726
|
-
this.dispatchEvent(evt);
|
|
2727
|
-
}
|
|
2728
|
-
};
|
|
2729
|
-
dispatchEvent(evt) {
|
|
2730
|
-
if (!evt.__origin) {
|
|
2731
|
-
Object.defineProperty(evt, "__origin", { value: this, enumerable: false });
|
|
2732
|
-
}
|
|
2733
|
-
this.events[evt.type]?.(evt);
|
|
2734
|
-
if (evt.bubbles && !evt.cancelBubble) {
|
|
2735
|
-
if (this.parent) {
|
|
2736
|
-
this.parent.dispatchEvent(evt);
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
}
|
|
2740
|
-
onDestroy() {
|
|
2741
|
-
SpatialWebEvent.removeEventReceiver(this.id);
|
|
2742
|
-
this.children.forEach((child) => {
|
|
2743
|
-
child.parent = null;
|
|
2744
|
-
});
|
|
2745
|
-
this.children = [];
|
|
2746
|
-
if (this.parent) {
|
|
2747
|
-
this.parent.children = this.parent.children.filter(
|
|
2748
|
-
(child) => child.id !== this.id
|
|
2749
|
-
);
|
|
2750
|
-
this.parent = null;
|
|
2751
|
-
}
|
|
2752
|
-
}
|
|
2753
|
-
// onUpdate(properties: SpatialEntityProperties) {
|
|
2754
|
-
// this.position = properties.position
|
|
2755
|
-
// this.rotation = properties.rotation
|
|
2756
|
-
// this.scale = properties.scale
|
|
2757
|
-
// }
|
|
2758
|
-
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2759
|
-
return new ConvertFromEntityToEntityCommand(
|
|
2760
|
-
fromEntityId,
|
|
2761
|
-
toEntityId,
|
|
2762
|
-
position
|
|
2763
|
-
).execute();
|
|
2764
|
-
}
|
|
2765
|
-
async convertFromEntityToScene(fromEntityId, position) {
|
|
2766
|
-
return new ConvertFromEntityToSceneCommand(fromEntityId, position).execute();
|
|
2767
|
-
}
|
|
2768
|
-
async convertFromSceneToEntity(entityId, position) {
|
|
2769
|
-
return new ConvertFromSceneToEntityCommand(entityId, position).execute();
|
|
2770
|
-
}
|
|
2771
|
-
};
|
|
2772
|
-
|
|
2773
|
-
// src/reality/entity/SpatialModelEntity.ts
|
|
2774
|
-
var SpatialModelEntity = class extends SpatialEntity {
|
|
2775
|
-
constructor(id, options, userData) {
|
|
2776
|
-
super(id, userData);
|
|
2777
|
-
this.id = id;
|
|
2778
|
-
this.options = options;
|
|
2779
|
-
this.userData = userData;
|
|
2780
|
-
}
|
|
2781
|
-
async setMaterials(materials) {
|
|
2782
|
-
return new SetMaterialsOnEntityCommand(this.id, materials).execute();
|
|
2783
|
-
}
|
|
2784
|
-
};
|
|
2785
|
-
|
|
2786
|
-
// src/reality/component/SpatialComponent.ts
|
|
2787
|
-
var SpatialComponent = class extends SpatialObject {
|
|
2788
|
-
constructor(id) {
|
|
2789
|
-
super(id);
|
|
2790
|
-
SpatialWebEvent.addEventReceiver(id, this.onReceiveEvent);
|
|
2791
|
-
}
|
|
2792
|
-
onReceiveEvent = (data) => {
|
|
2793
|
-
const { type } = data;
|
|
2794
|
-
if (type === "objectdestroy" /* objectdestroy */) {
|
|
2795
|
-
this.isDestroyed = true;
|
|
2796
|
-
}
|
|
2797
|
-
};
|
|
2798
|
-
};
|
|
2799
|
-
|
|
2800
|
-
// src/reality/component/ModelComponent.ts
|
|
2801
|
-
var ModelComponent = class extends SpatialComponent {
|
|
2802
|
-
constructor(id, options) {
|
|
2803
|
-
super(id);
|
|
2804
|
-
this.options = options;
|
|
2805
|
-
}
|
|
2806
|
-
};
|
|
2807
|
-
|
|
2808
|
-
// src/reality/material/SpatialMaterial.ts
|
|
2809
|
-
var SpatialMaterial = class extends SpatialObject {
|
|
2810
|
-
constructor(id, type) {
|
|
2811
|
-
super(id);
|
|
2812
|
-
this.id = id;
|
|
2813
|
-
this.type = type;
|
|
2814
|
-
this.type = type;
|
|
2815
|
-
}
|
|
2816
|
-
};
|
|
2817
|
-
|
|
2818
|
-
// src/reality/material/SpatialUnlitMaterial.ts
|
|
2819
|
-
var SpatialUnlitMaterial = class extends SpatialMaterial {
|
|
2820
|
-
constructor(id, options) {
|
|
2821
|
-
super(id, "unlit");
|
|
2822
|
-
this.id = id;
|
|
2823
|
-
this.options = options;
|
|
2824
|
-
}
|
|
2825
|
-
updateProperties(properties) {
|
|
2826
|
-
return new UpdateUnlitMaterialProperties(this, properties).execute();
|
|
2827
|
-
}
|
|
2828
|
-
};
|
|
2829
|
-
|
|
2830
|
-
// src/reality/resource/SpatialModelAsset.ts
|
|
2831
|
-
var SpatialModelAsset = class extends SpatialObject {
|
|
2832
|
-
constructor(id, options) {
|
|
2833
|
-
super(id);
|
|
2834
|
-
this.id = id;
|
|
2835
|
-
this.options = options;
|
|
2836
|
-
}
|
|
2837
|
-
};
|
|
2838
|
-
|
|
2839
|
-
// src/reality/resource/SpatialTextureResource.ts
|
|
2840
|
-
var SpatialTextureResource = class extends SpatialObject {
|
|
2841
|
-
constructor(id, options) {
|
|
2842
|
-
super(id);
|
|
2843
|
-
this.id = id;
|
|
2844
|
-
this.options = options;
|
|
2845
|
-
}
|
|
2846
|
-
updateProperties(properties) {
|
|
2847
|
-
return new UpdateTexturePropertiesCommand(this, properties).execute();
|
|
2848
|
-
}
|
|
2849
|
-
};
|
|
2850
|
-
|
|
2851
|
-
// src/reality/realityCreator.ts
|
|
2852
|
-
async function createSpatialEntity(userData) {
|
|
2853
|
-
const result = await new CreateSpatialEntityCommand(userData?.name).execute();
|
|
2854
|
-
if (!result.success) {
|
|
2855
|
-
throw new Error("createSpatialEntity failed:" + result?.errorMessage);
|
|
2856
|
-
} else {
|
|
2857
|
-
const { id } = result.data;
|
|
2858
|
-
return new SpatialEntity(id, userData);
|
|
2859
|
-
}
|
|
2860
|
-
}
|
|
2861
|
-
async function createSpatialGeometry(ctor, options) {
|
|
2862
|
-
const result = await new CreateSpatialGeometryCommand(
|
|
2863
|
-
ctor.type,
|
|
2864
|
-
options
|
|
2865
|
-
).execute();
|
|
2866
|
-
if (!result.success) {
|
|
2867
|
-
throw new Error("createSpatialGeometry failed:" + result?.errorMessage);
|
|
2868
|
-
} else {
|
|
2869
|
-
const { id } = result.data;
|
|
2870
|
-
return new ctor(id, options);
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
async function createSpatialUnlitMaterial(options) {
|
|
2874
|
-
const result = await new CreateSpatialUnlitMaterialCommand(options).execute();
|
|
2875
|
-
if (!result.success) {
|
|
2876
|
-
throw new Error("createSpatialUnlitMaterial failed:" + result?.errorMessage);
|
|
2877
|
-
} else {
|
|
2878
|
-
const { id } = result.data;
|
|
2879
|
-
return new SpatialUnlitMaterial(id, options);
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
|
-
async function createModelComponent(options) {
|
|
2883
|
-
const result = await new CreateModelComponentCommand(options).execute();
|
|
2884
|
-
if (!result.success) {
|
|
2885
|
-
throw new Error("createModelComponent failed:" + result?.errorMessage);
|
|
2886
|
-
} else {
|
|
2887
|
-
const { id } = result.data;
|
|
2888
|
-
return new ModelComponent(id, options);
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
async function createSpatialModelEntity(options, userData) {
|
|
2892
|
-
const result = await new CreateSpatialModelEntityCommand(options).execute();
|
|
2893
|
-
if (!result.success) {
|
|
2894
|
-
throw new Error("createSpatialModelEntity failed:" + result?.errorMessage);
|
|
2895
|
-
} else {
|
|
2896
|
-
const { id } = result.data;
|
|
2897
|
-
return new SpatialModelEntity(id, options, userData);
|
|
2898
|
-
}
|
|
2899
|
-
}
|
|
2900
|
-
async function createModelAsset(options) {
|
|
2901
|
-
const result = await new CreateModelAssetCommand(options).execute();
|
|
2902
|
-
if (!result.success) {
|
|
2903
|
-
throw new Error("createModelAsset failed:" + result?.errorMessage);
|
|
2904
|
-
} else {
|
|
2905
|
-
const { id } = result.data;
|
|
2906
|
-
return new SpatialModelAsset(id, options);
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
async function createSpatialTexture(options) {
|
|
2910
|
-
const result = await new CreateTextureCommand(options.url).execute();
|
|
2911
|
-
if (!result.success) {
|
|
2912
|
-
throw new Error("createSpatialTexture failed:" + result?.errorMessage);
|
|
2913
|
-
} else {
|
|
2914
|
-
const { id } = result.data;
|
|
2915
|
-
return new SpatialTextureResource(id, options);
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
// src/reality/geometry/SpatialGeometry.ts
|
|
2920
|
-
var SpatialGeometry = class extends SpatialObject {
|
|
2921
|
-
constructor(id, options) {
|
|
2922
|
-
super(id);
|
|
2923
|
-
this.id = id;
|
|
2924
|
-
this.options = options;
|
|
2925
|
-
}
|
|
2926
|
-
static type;
|
|
2927
|
-
};
|
|
2928
|
-
|
|
2929
|
-
// src/reality/geometry/SpatialBoxGeometry.ts
|
|
2930
|
-
var SpatialBoxGeometry = class extends SpatialGeometry {
|
|
2931
|
-
constructor(id, options) {
|
|
2932
|
-
super(id, options);
|
|
2933
|
-
this.id = id;
|
|
2934
|
-
this.options = options;
|
|
2935
|
-
}
|
|
2936
|
-
static type = "BoxGeometry";
|
|
2937
|
-
};
|
|
2938
|
-
|
|
2939
|
-
// src/reality/geometry/SpatialSphereGeometry.ts
|
|
2940
|
-
var SpatialSphereGeometry = class extends SpatialGeometry {
|
|
2941
|
-
constructor(id, options) {
|
|
2942
|
-
super(id, options);
|
|
2943
|
-
this.id = id;
|
|
2944
|
-
this.options = options;
|
|
2945
|
-
}
|
|
2946
|
-
static type = "SphereGeometry";
|
|
2947
|
-
};
|
|
2948
|
-
|
|
2949
|
-
// src/reality/geometry/SpatialCylinderGeometry.ts
|
|
2950
|
-
var SpatialCylinderGeometry = class extends SpatialGeometry {
|
|
2951
|
-
constructor(id, options) {
|
|
2952
|
-
super(id, options);
|
|
2953
|
-
this.id = id;
|
|
2954
|
-
this.options = options;
|
|
2955
|
-
}
|
|
2956
|
-
static type = "CylinderGeometry";
|
|
2957
|
-
};
|
|
2958
|
-
|
|
2959
|
-
// src/reality/geometry/SpatialPlaneGeometry.ts
|
|
2960
|
-
var SpatialPlaneGeometry = class extends SpatialGeometry {
|
|
2961
|
-
constructor(id, options) {
|
|
2962
|
-
super(id, options);
|
|
2963
|
-
this.id = id;
|
|
2964
|
-
this.options = options;
|
|
2965
|
-
}
|
|
2966
|
-
static type = "PlaneGeometry";
|
|
2967
|
-
};
|
|
2968
|
-
|
|
2969
|
-
// src/reality/geometry/SpatialConeGeometry.ts
|
|
2970
|
-
var SpatialConeGeometry = class extends SpatialGeometry {
|
|
2971
|
-
constructor(id, options) {
|
|
2972
|
-
super(id, options);
|
|
2973
|
-
this.id = id;
|
|
2974
|
-
this.options = options;
|
|
2975
|
-
}
|
|
2976
|
-
static type = "ConeGeometry";
|
|
2977
|
-
};
|
|
2978
|
-
|
|
2979
|
-
// src/SpatialSession.ts
|
|
2980
|
-
var SpatialSession = class {
|
|
2981
|
-
/**
|
|
2982
|
-
* Gets the singleton instance of the spatial scene.
|
|
2983
|
-
* The spatial scene is the root container for all spatial elements.
|
|
2984
|
-
* @returns The SpatialScene singleton instance
|
|
2985
|
-
*/
|
|
2986
|
-
getSpatialScene() {
|
|
2987
|
-
return SpatialScene.getInstance();
|
|
2988
|
-
}
|
|
2989
|
-
/**
|
|
2990
|
-
* Creates a new 2D element that can be spatialized in the 3D environment.
|
|
2991
|
-
* 2D elements represent HTML content that can be positioned in 3D space.
|
|
2992
|
-
* @returns Promise resolving to a new Spatialized2DElement instance
|
|
2993
|
-
*/
|
|
2994
|
-
createSpatialized2DElement() {
|
|
2995
|
-
return createSpatialized2DElement();
|
|
2996
|
-
}
|
|
2997
|
-
/**
|
|
2998
|
-
* Creates a new static 3D element with an optional model URL.
|
|
2999
|
-
* Static 3D elements represent pre-built 3D models that can be loaded from a URL.
|
|
3000
|
-
* @param modelURL Optional URL to the 3D model to load
|
|
3001
|
-
* @param sources Optional list of fallback model sources
|
|
3002
|
-
* @param loading Whether the asset should fetch eagerly or be deferred (`'lazy'`)
|
|
3003
|
-
* @returns Promise resolving to a new SpatializedStatic3DElement instance
|
|
3004
|
-
*/
|
|
3005
|
-
createSpatializedStatic3DElement(modelURL, sources, loading = "eager") {
|
|
3006
|
-
return createSpatializedStatic3DElement(modelURL, sources, loading);
|
|
3007
|
-
}
|
|
3008
|
-
/**
|
|
3009
|
-
* Initializes the spatial scene with custom configuration.
|
|
3010
|
-
* This is a reference to the initScene function from scene-polyfill.
|
|
3011
|
-
*/
|
|
3012
|
-
initScene = initScene;
|
|
3013
|
-
/**
|
|
3014
|
-
* Creates a new dynamic 3D element that can be manipulated at runtime.
|
|
3015
|
-
* Dynamic 3D elements allow for programmatic creation and modification of 3D content.
|
|
3016
|
-
* @returns Promise resolving to a new SpatializedDynamic3DElement instance
|
|
3017
|
-
*/
|
|
3018
|
-
createSpatializedDynamic3DElement() {
|
|
3019
|
-
return createSpatializedDynamic3DElement();
|
|
3020
|
-
}
|
|
3021
|
-
/**
|
|
3022
|
-
* Creates a new spatial entity with an optional name.
|
|
3023
|
-
* Entities are the basic building blocks for creating custom 3D content.
|
|
3024
|
-
* @param name Optional name for the entity
|
|
3025
|
-
* @returns Promise resolving to a new SpatialEntity instance
|
|
3026
|
-
*/
|
|
3027
|
-
createEntity(userData) {
|
|
3028
|
-
return createSpatialEntity(userData);
|
|
3029
|
-
}
|
|
3030
|
-
/**
|
|
3031
|
-
* Creates a box geometry with optional configuration.
|
|
3032
|
-
* @param options Configuration options for the box geometry
|
|
3033
|
-
* @returns Promise resolving to a new SpatialBoxGeometry instance
|
|
3034
|
-
*/
|
|
3035
|
-
createBoxGeometry(options = {}) {
|
|
3036
|
-
return createSpatialGeometry(SpatialBoxGeometry, options);
|
|
3037
|
-
}
|
|
3038
|
-
/**
|
|
3039
|
-
* Creates a plane geometry with optional configuration.
|
|
3040
|
-
* @param options Configuration options for the plane geometry
|
|
3041
|
-
* @returns Promise resolving to a new SpatialPlaneGeometry instance
|
|
3042
|
-
*/
|
|
3043
|
-
createPlaneGeometry(options = {}) {
|
|
3044
|
-
return createSpatialGeometry(SpatialPlaneGeometry, options);
|
|
3045
|
-
}
|
|
3046
|
-
/**
|
|
3047
|
-
* Creates a sphere geometry with optional configuration.
|
|
3048
|
-
* @param options Configuration options for the sphere geometry
|
|
3049
|
-
* @returns Promise resolving to a new SpatialSphereGeometry instance
|
|
3050
|
-
*/
|
|
3051
|
-
createSphereGeometry(options = {}) {
|
|
3052
|
-
return createSpatialGeometry(SpatialSphereGeometry, options);
|
|
3053
|
-
}
|
|
3054
|
-
/**
|
|
3055
|
-
* Creates a cone geometry with the specified configuration.
|
|
3056
|
-
* @param options Configuration options for the cone geometry
|
|
3057
|
-
* @returns Promise resolving to a new SpatialConeGeometry instance
|
|
3058
|
-
*/
|
|
3059
|
-
createConeGeometry(options) {
|
|
3060
|
-
return createSpatialGeometry(SpatialConeGeometry, options);
|
|
3061
|
-
}
|
|
3062
|
-
/**
|
|
3063
|
-
* Creates a cylinder geometry with the specified configuration.
|
|
3064
|
-
* @param options Configuration options for the cylinder geometry
|
|
3065
|
-
* @returns Promise resolving to a new SpatialCylinderGeometry instance
|
|
3066
|
-
*/
|
|
3067
|
-
createCylinderGeometry(options) {
|
|
3068
|
-
return createSpatialGeometry(SpatialCylinderGeometry, options);
|
|
3069
|
-
}
|
|
3070
|
-
/**
|
|
3071
|
-
* Creates a model component with the specified configuration.
|
|
3072
|
-
* Model components are used to add 3D model rendering capabilities to entities.
|
|
3073
|
-
* @param options Configuration options for the model component
|
|
3074
|
-
* @returns Promise resolving to a new ModelComponent instance
|
|
3075
|
-
*/
|
|
3076
|
-
createModelComponent(options) {
|
|
3077
|
-
return createModelComponent(options);
|
|
3078
|
-
}
|
|
3079
|
-
/**
|
|
3080
|
-
* Creates an unlit material with the specified configuration.
|
|
3081
|
-
* Unlit materials don't respond to lighting in the scene.
|
|
3082
|
-
* @param options Configuration options for the unlit material
|
|
3083
|
-
* @returns Promise resolving to a new SpatialUnlitMaterial instance
|
|
3084
|
-
*/
|
|
3085
|
-
createUnlitMaterial(options) {
|
|
3086
|
-
return createSpatialUnlitMaterial(options);
|
|
3087
|
-
}
|
|
3088
|
-
/**
|
|
3089
|
-
* Creates a texture resource from the specified image URL.
|
|
3090
|
-
* Texture resources can be referenced by materials and other spatial content.
|
|
3091
|
-
* @param options Configuration options for the texture resource
|
|
3092
|
-
* @returns Promise resolving to a new SpatialTextureResource instance
|
|
3093
|
-
*/
|
|
3094
|
-
createTexture(options) {
|
|
3095
|
-
return createSpatialTexture(options);
|
|
3096
|
-
}
|
|
3097
|
-
/**
|
|
3098
|
-
* Creates a model asset with the specified configuration.
|
|
3099
|
-
* Model assets represent 3D model resources that can be used by entities.
|
|
3100
|
-
* @param options Configuration options for the model asset
|
|
3101
|
-
* @returns Promise resolving to a new SpatialModelAsset instance
|
|
3102
|
-
*/
|
|
3103
|
-
createModelAsset(options) {
|
|
3104
|
-
return createModelAsset(options);
|
|
3105
|
-
}
|
|
3106
|
-
/**
|
|
3107
|
-
* Creates a spatial model entity with the specified configuration.
|
|
3108
|
-
* This is a convenience method for creating an entity with a model component.
|
|
3109
|
-
* @param options Configuration options for the spatial model entity
|
|
3110
|
-
* @returns Promise resolving to a new SpatialModelEntity instance
|
|
3111
|
-
*/
|
|
3112
|
-
createSpatialModelEntity(options, userData) {
|
|
3113
|
-
return createSpatialModelEntity(options, userData);
|
|
3114
|
-
}
|
|
3115
|
-
/**
|
|
3116
|
-
* Creates an attachment entity that renders 2D HTML content as a child
|
|
3117
|
-
* of a 3D entity in the scene graph.
|
|
3118
|
-
* @param options Configuration options including parent entity ID, position, and size
|
|
3119
|
-
* @returns Promise resolving to a new Attachment instance
|
|
3120
|
-
*/
|
|
3121
|
-
createAttachmentEntity(options) {
|
|
3122
|
-
return createAttachmentEntity(options);
|
|
3123
|
-
}
|
|
3124
|
-
};
|
|
3125
|
-
|
|
3126
|
-
// src/Spatial.ts
|
|
3127
|
-
var Spatial = class {
|
|
3128
|
-
/**
|
|
3129
|
-
* Requests a spatial session object from the browser.
|
|
3130
|
-
* This is the primary method to initialize spatial functionality.
|
|
3131
|
-
* @returns The SpatialSession instance or null if not available in the current browser
|
|
3132
|
-
* [TODO] discuss implications of this not being async
|
|
3133
|
-
*/
|
|
3134
|
-
requestSession() {
|
|
3135
|
-
if (this.runInSpatialWeb()) {
|
|
3136
|
-
SpatialWebEvent.init();
|
|
3137
|
-
return new SpatialSession();
|
|
3138
|
-
} else {
|
|
3139
|
-
return null;
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
/**
|
|
3143
|
-
* Checks if the current page is running in a spatial web environment.
|
|
3144
|
-
* This method detects if the application is running in a WebSpatial-compatible browser.
|
|
3145
|
-
* @returns True if running in a spatial web environment, false otherwise
|
|
3146
|
-
*/
|
|
3147
|
-
runInSpatialWeb() {
|
|
3148
|
-
if (navigator.userAgent.indexOf("WebSpatial/") >= 0) {
|
|
3149
|
-
return true;
|
|
3150
|
-
}
|
|
3151
|
-
return false;
|
|
3152
|
-
}
|
|
3153
|
-
/** @deprecated
|
|
3154
|
-
* Checks if WebSpatial is supported in the current environment.
|
|
3155
|
-
* Verifies compatibility between native and client versions.
|
|
3156
|
-
* @returns True if web spatial is supported by this webpage
|
|
3157
|
-
*/
|
|
3158
|
-
isSupported() {
|
|
3159
|
-
return true;
|
|
3160
|
-
}
|
|
3161
|
-
/** @deprecated
|
|
3162
|
-
* Gets the native WebSpatial version from the browser environment.
|
|
3163
|
-
* The version format follows semantic versioning (x.x.x).
|
|
3164
|
-
* @returns Native version string in format "x.x.x"
|
|
3165
|
-
*/
|
|
3166
|
-
getNativeVersion() {
|
|
3167
|
-
if (window.__WebSpatialData && window.__WebSpatialData.getNativeVersion) {
|
|
3168
|
-
return window.__WebSpatialData.getNativeVersion();
|
|
3169
|
-
}
|
|
3170
|
-
return window.WebSpatailNativeVersion === "WS_SHELL_VERSION" ? this.getClientVersion() : window.WebSpatailNativeVersion;
|
|
3171
|
-
}
|
|
3172
|
-
/** @deprecated
|
|
3173
|
-
* Gets the client SDK version.
|
|
3174
|
-
* The version format follows semantic versioning (x.x.x).
|
|
3175
|
-
* @returns Client SDK version string in format "x.x.x"
|
|
3176
|
-
*/
|
|
3177
|
-
getClientVersion() {
|
|
3178
|
-
return "1.7.0";
|
|
3179
|
-
}
|
|
3180
|
-
};
|
|
3181
|
-
|
|
3182
|
-
// src/runtime/WebSpatialRuntimeError.ts
|
|
3183
|
-
var WebSpatialRuntimeError = class extends Error {
|
|
3184
|
-
capability;
|
|
3185
|
-
constructor(capability, message) {
|
|
3186
|
-
super(
|
|
3187
|
-
message ?? `Capability "${capability}" is not supported in this WebSpatial runtime`
|
|
3188
|
-
);
|
|
3189
|
-
this.name = "WebSpatialRuntimeError";
|
|
3190
|
-
this.capability = capability;
|
|
3191
|
-
}
|
|
3192
|
-
};
|
|
3193
|
-
|
|
3194
|
-
// src/runtime/keys.ts
|
|
3195
|
-
var COMPONENT_KEYS = [
|
|
3196
|
-
"Model",
|
|
3197
|
-
"Reality",
|
|
3198
|
-
"Entity",
|
|
3199
|
-
"BoxEntity",
|
|
3200
|
-
"SphereEntity",
|
|
3201
|
-
"ConeEntity",
|
|
3202
|
-
"CylinderEntity",
|
|
3203
|
-
"PlaneEntity",
|
|
3204
|
-
"SceneGraph",
|
|
3205
|
-
"ModelAsset",
|
|
3206
|
-
"ModelEntity",
|
|
3207
|
-
"UnlitMaterial",
|
|
3208
|
-
"Material",
|
|
3209
|
-
"AttachmentAsset",
|
|
3210
|
-
"AttachmentEntity"
|
|
3211
|
-
];
|
|
3212
|
-
var CSS_KEYS = [
|
|
3213
|
-
"-xr-background-material",
|
|
3214
|
-
"-xr-back",
|
|
3215
|
-
"-xr-depth",
|
|
3216
|
-
"-xr-transform"
|
|
3217
|
-
];
|
|
3218
|
-
var GESTURE_KEYS = [
|
|
3219
|
-
"SpatialTapEvent",
|
|
3220
|
-
"SpatialDragStartEvent",
|
|
3221
|
-
"SpatialDragEvent",
|
|
3222
|
-
"SpatialDragEndEvent",
|
|
3223
|
-
"SpatialRotateEvent",
|
|
3224
|
-
"SpatialRotateEndEvent",
|
|
3225
|
-
"SpatialMagnifyEvent",
|
|
3226
|
-
"SpatialMagnifyEndEvent"
|
|
3227
|
-
];
|
|
3228
|
-
var JS_SCENE_KEYS = [
|
|
3229
|
-
"useMetrics",
|
|
3230
|
-
"convertCoordinate",
|
|
3231
|
-
"initScene",
|
|
3232
|
-
"WindowScene",
|
|
3233
|
-
"VolumeScene"
|
|
3234
|
-
];
|
|
3235
|
-
var ELEMENT_DOM_DEPTH_KEYS = ["xrClientDepth", "xrOffsetBack"];
|
|
3236
|
-
var WINDOW_DOM_DEPTH_KEYS = ["xrInnerDepth", "xrOuterDepth"];
|
|
3237
|
-
var DOM_DEPTH_KEYS = [
|
|
3238
|
-
...ELEMENT_DOM_DEPTH_KEYS,
|
|
3239
|
-
...WINDOW_DOM_DEPTH_KEYS
|
|
3240
|
-
];
|
|
3241
|
-
var TOP_LEVEL_KEYS = [
|
|
3242
|
-
...COMPONENT_KEYS,
|
|
3243
|
-
...CSS_KEYS,
|
|
3244
|
-
...GESTURE_KEYS,
|
|
3245
|
-
...JS_SCENE_KEYS,
|
|
3246
|
-
...DOM_DEPTH_KEYS
|
|
3247
|
-
];
|
|
3248
|
-
var ALIAS_TO_CANONICAL = {
|
|
3249
|
-
Box: "BoxEntity",
|
|
3250
|
-
Sphere: "SphereEntity",
|
|
3251
|
-
Cone: "ConeEntity",
|
|
3252
|
-
Cylinder: "CylinderEntity",
|
|
3253
|
-
Plane: "PlaneEntity",
|
|
3254
|
-
World: "SceneGraph"
|
|
3255
|
-
};
|
|
3256
|
-
function normalizeCapabilityName(name) {
|
|
3257
|
-
return ALIAS_TO_CANONICAL[name] ?? name;
|
|
3258
|
-
}
|
|
3259
|
-
var SUB_TOKENS_BY_NAME = {
|
|
3260
|
-
Material: ["unlit"],
|
|
3261
|
-
WindowScene: ["defaultSize", "resizability"],
|
|
3262
|
-
VolumeScene: [
|
|
3263
|
-
"defaultSize",
|
|
3264
|
-
"resizability",
|
|
3265
|
-
"worldScaling",
|
|
3266
|
-
"worldAlignment",
|
|
3267
|
-
"baseplateVisibility"
|
|
3268
|
-
],
|
|
3269
|
-
SpatialRotateEvent: ["constrainedToAxis"],
|
|
3270
|
-
Model: [
|
|
3271
|
-
"autoplay",
|
|
3272
|
-
"loop",
|
|
3273
|
-
"stagemode",
|
|
3274
|
-
"poster",
|
|
3275
|
-
"loading",
|
|
3276
|
-
"source",
|
|
3277
|
-
"ready",
|
|
3278
|
-
"currentSrc",
|
|
3279
|
-
"entityTransform",
|
|
3280
|
-
"paused",
|
|
3281
|
-
"duration",
|
|
3282
|
-
"playbackRate",
|
|
3283
|
-
"play",
|
|
3284
|
-
"pause",
|
|
3285
|
-
"currentTime"
|
|
3286
|
-
]
|
|
3287
|
-
};
|
|
3288
|
-
function isKnownTopLevel(name) {
|
|
3289
|
-
return TOP_LEVEL_KEYS.includes(name);
|
|
3290
|
-
}
|
|
3291
|
-
function isKnownSubToken(name, token) {
|
|
3292
|
-
const allowed = SUB_TOKENS_BY_NAME[name];
|
|
3293
|
-
return allowed !== void 0 && allowed.includes(token);
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
// src/runtime/capability-data.ts
|
|
3297
|
-
function baseTrueFlags() {
|
|
3298
|
-
const flags = {};
|
|
3299
|
-
for (const k of TOP_LEVEL_KEYS) {
|
|
3300
|
-
flags[k] = true;
|
|
3301
|
-
}
|
|
3302
|
-
for (const [name, toks] of Object.entries(SUB_TOKENS_BY_NAME)) {
|
|
3303
|
-
for (const t of toks) {
|
|
3304
|
-
flags[`${name}:${t}`] = true;
|
|
3305
|
-
}
|
|
3306
|
-
}
|
|
3307
|
-
return flags;
|
|
3308
|
-
}
|
|
3309
|
-
function matrixVision_1_5_0_Flags() {
|
|
3310
|
-
const flags = baseTrueFlags();
|
|
3311
|
-
const modelNo = [
|
|
3312
|
-
"autoplay",
|
|
3313
|
-
"loop",
|
|
3314
|
-
"stagemode",
|
|
3315
|
-
"poster",
|
|
3316
|
-
"loading",
|
|
3317
|
-
"source",
|
|
3318
|
-
"paused",
|
|
3319
|
-
"duration",
|
|
3320
|
-
"playbackRate",
|
|
3321
|
-
"play",
|
|
3322
|
-
"pause",
|
|
3323
|
-
"currentTime"
|
|
3324
|
-
];
|
|
3325
|
-
for (const t of modelNo) {
|
|
3326
|
-
flags[`Model:${t}`] = false;
|
|
3327
|
-
}
|
|
3328
|
-
flags["SpatialRotateEvent:constrainedToAxis"] = true;
|
|
3329
|
-
return flags;
|
|
3330
|
-
}
|
|
3331
|
-
function matrixVision_1_6_0_Flags() {
|
|
3332
|
-
const flags = baseTrueFlags();
|
|
3333
|
-
for (const t of ["stagemode", "poster", "loading", "currentTime"]) {
|
|
3334
|
-
flags[`Model:${t}`] = false;
|
|
3335
|
-
}
|
|
3336
|
-
flags["SpatialRotateEvent:constrainedToAxis"] = true;
|
|
3337
|
-
return flags;
|
|
3338
|
-
}
|
|
3339
|
-
function matrixPico_0_1_1_Flags() {
|
|
3340
|
-
const flags = matrixVision_1_5_0_Flags();
|
|
3341
|
-
flags.xrInnerDepth = false;
|
|
3342
|
-
flags.xrOuterDepth = false;
|
|
3343
|
-
return flags;
|
|
3344
|
-
}
|
|
3345
|
-
function matrixPico_0_1_2_Flags() {
|
|
3346
|
-
const flags = matrixVision_1_6_0_Flags();
|
|
3347
|
-
flags.xrInnerDepth = false;
|
|
3348
|
-
flags.xrOuterDepth = false;
|
|
3349
|
-
return flags;
|
|
3350
|
-
}
|
|
3351
|
-
function visionOsRow_1_5_0() {
|
|
3352
|
-
return { version: "1.5.0", flags: matrixVision_1_5_0_Flags() };
|
|
3353
|
-
}
|
|
3354
|
-
function visionOsRow_1_6_0() {
|
|
3355
|
-
return { version: "1.6.0", flags: matrixVision_1_6_0_Flags() };
|
|
3356
|
-
}
|
|
3357
|
-
function picoOsRow_0_1_1() {
|
|
3358
|
-
return { version: "0.1.1", flags: matrixPico_0_1_1_Flags() };
|
|
3359
|
-
}
|
|
3360
|
-
function picoOsRow_0_1_2() {
|
|
3361
|
-
return { version: "0.1.2", flags: matrixPico_0_1_2_Flags() };
|
|
3362
|
-
}
|
|
3363
|
-
var CAPABILITY_TABLE = {
|
|
3364
|
-
visionos: [visionOsRow_1_5_0(), visionOsRow_1_6_0()],
|
|
3365
|
-
picoos: [picoOsRow_0_1_1(), picoOsRow_0_1_2()]
|
|
3366
|
-
};
|
|
3367
|
-
|
|
3368
|
-
// src/runtime/semver.ts
|
|
3369
|
-
function compareSemver(a, b) {
|
|
3370
|
-
const pa = parseSemverParts(a);
|
|
3371
|
-
const pb = parseSemverParts(b);
|
|
3372
|
-
if (!pa || !pb) {
|
|
3373
|
-
return String(a).localeCompare(String(b));
|
|
3374
|
-
}
|
|
3375
|
-
const len = Math.max(pa.length, pb.length);
|
|
3376
|
-
for (let i = 0; i < len; i++) {
|
|
3377
|
-
const da = pa[i] ?? 0;
|
|
3378
|
-
const db = pb[i] ?? 0;
|
|
3379
|
-
if (da !== db) return da - db;
|
|
3380
|
-
}
|
|
3381
|
-
return 0;
|
|
3382
|
-
}
|
|
3383
|
-
function parseSemverParts(v) {
|
|
3384
|
-
const m = /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/.exec(v.trim());
|
|
3385
|
-
if (!m) return null;
|
|
3386
|
-
const major = Number(m[1]);
|
|
3387
|
-
const minor = m[2] !== void 0 ? Number(m[2]) : 0;
|
|
3388
|
-
const patch = m[3] !== void 0 ? Number(m[3]) : 0;
|
|
3389
|
-
if ([major, minor, patch].some((n) => Number.isNaN(n))) return null;
|
|
3390
|
-
return [major, minor, patch];
|
|
3391
|
-
}
|
|
3392
|
-
function parseSemverOrNull(v) {
|
|
3393
|
-
const m = /^(\d+(?:\.\d+){0,2})/.exec(v.trim());
|
|
3394
|
-
return m ? m[1] : null;
|
|
3395
|
-
}
|
|
3396
|
-
|
|
3397
|
-
// src/runtime/supports.ts
|
|
3398
|
-
var VISIONOS_DEBUG_SHELL_VERSION_PLACEHOLDER = "WS_SHELL_VERSION";
|
|
3399
|
-
var runtimeCache;
|
|
3400
|
-
function resetRuntimeCacheForTests() {
|
|
3401
|
-
runtimeCache = void 0;
|
|
3402
|
-
}
|
|
3403
|
-
function getRuntime() {
|
|
3404
|
-
if (runtimeCache !== void 0) return runtimeCache;
|
|
3405
|
-
if (typeof navigator === "undefined") {
|
|
3406
|
-
runtimeCache = { type: null, shellVersion: null };
|
|
3407
|
-
return runtimeCache;
|
|
3408
|
-
}
|
|
3409
|
-
runtimeCache = computeRuntimeFromUserAgent(navigator.userAgent);
|
|
3410
|
-
return runtimeCache;
|
|
3411
|
-
}
|
|
3412
|
-
function selectRow(type, shellVersion) {
|
|
3413
|
-
const norm = parseSemverOrNull(shellVersion);
|
|
3414
|
-
if (!norm) return null;
|
|
3415
|
-
const rows = CAPABILITY_TABLE[type];
|
|
3416
|
-
if (!rows.length) return null;
|
|
3417
|
-
const sorted = [...rows].sort((a, b) => compareSemver(a.version, b.version));
|
|
3418
|
-
const minV = sorted[0].version;
|
|
3419
|
-
if (compareSemver(norm, minV) < 0) return null;
|
|
3420
|
-
let chosen = null;
|
|
3421
|
-
for (const row of sorted) {
|
|
3422
|
-
if (compareSemver(row.version, norm) <= 0) {
|
|
3423
|
-
chosen = row;
|
|
3424
|
-
} else {
|
|
3425
|
-
break;
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
return chosen;
|
|
3429
|
-
}
|
|
3430
|
-
function supports(name, tokens) {
|
|
3431
|
-
if (typeof name !== "string") return false;
|
|
3432
|
-
const canonical = normalizeCapabilityName(name);
|
|
3433
|
-
if (!isKnownTopLevel(canonical)) return false;
|
|
3434
|
-
const tokList = tokens === void 0 ? [] : Array.isArray(tokens) ? [...tokens] : [];
|
|
3435
|
-
if (tokList.some((t) => typeof t !== "string")) return false;
|
|
3436
|
-
for (const t of tokList) {
|
|
3437
|
-
if (!isKnownSubToken(canonical, t)) return false;
|
|
3438
|
-
}
|
|
3439
|
-
const rt = getRuntime();
|
|
3440
|
-
if (rt.type === "puppeteer") {
|
|
3441
|
-
return true;
|
|
3442
|
-
}
|
|
3443
|
-
if (rt.type === null) return false;
|
|
3444
|
-
if (rt.shellVersion === null) return false;
|
|
3445
|
-
if (rt.type === "visionos" && rt.shellVersion === VISIONOS_DEBUG_SHELL_VERSION_PLACEHOLDER) {
|
|
3446
|
-
return true;
|
|
3447
|
-
}
|
|
3448
|
-
const parsedShell = parseSemverOrNull(rt.shellVersion);
|
|
3449
|
-
if (!parsedShell) return false;
|
|
3450
|
-
if (rt.type !== "visionos" && rt.type !== "picoos") return false;
|
|
3451
|
-
const row = selectRow(rt.type, parsedShell);
|
|
3452
|
-
if (!row) return false;
|
|
3453
|
-
if (tokList.length === 0) {
|
|
3454
|
-
return row.flags[canonical] === true;
|
|
3455
|
-
}
|
|
3456
|
-
if (row.flags[canonical] !== true) return false;
|
|
3457
|
-
return tokList.every((t) => row.flags[`${canonical}:${t}`] === true);
|
|
3458
|
-
}
|
|
3459
|
-
|
|
3460
|
-
// src/spatial-window-polyfill.ts
|
|
3461
|
-
var spatial = new Spatial();
|
|
3462
|
-
var session = void 0;
|
|
3463
|
-
var SpatialGlobalCustomVars = {
|
|
3464
|
-
backgroundMaterial: "--xr-background-material"
|
|
3465
|
-
};
|
|
3466
|
-
var htmlBackgroundMaterial = "";
|
|
3467
|
-
function setCurrentWindowStyle(backgroundMaterial) {
|
|
3468
|
-
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
3469
|
-
session?.getSpatialScene()?.updateSpatialProperties({
|
|
3470
|
-
material: backgroundMaterial
|
|
3471
|
-
});
|
|
3472
|
-
htmlBackgroundMaterial = backgroundMaterial;
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
function checkHtmlBackgroundMaterial() {
|
|
3476
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
3477
|
-
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
3478
|
-
SpatialGlobalCustomVars.backgroundMaterial
|
|
3479
|
-
);
|
|
3480
|
-
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
3481
|
-
}
|
|
3482
|
-
var htmlCornerRadius = {
|
|
3483
|
-
topLeading: 0,
|
|
3484
|
-
bottomLeading: 0,
|
|
3485
|
-
topTrailing: 0,
|
|
3486
|
-
bottomTrailing: 0
|
|
3487
|
-
};
|
|
3488
|
-
function checkCornerRadius() {
|
|
3489
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
3490
|
-
const cornerRadius = parseCornerRadius(computedStyle);
|
|
3491
|
-
setCornerRadius(cornerRadius);
|
|
3492
|
-
}
|
|
3493
|
-
function setCornerRadius(cornerRadius) {
|
|
3494
|
-
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
3495
|
-
session?.getSpatialScene()?.updateSpatialProperties({
|
|
3496
|
-
cornerRadius
|
|
3497
|
-
});
|
|
3498
|
-
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
3499
|
-
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
3500
|
-
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
3501
|
-
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
function setOpacity(opacity) {
|
|
3505
|
-
session?.getSpatialScene().updateSpatialProperties({
|
|
3506
|
-
opacity
|
|
3507
|
-
});
|
|
3508
|
-
}
|
|
3509
|
-
function checkOpacity() {
|
|
3510
|
-
const computedStyle = getComputedStyle(document.documentElement);
|
|
3511
|
-
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
3512
|
-
setOpacity(opacity);
|
|
3513
|
-
}
|
|
3514
|
-
function hijackDocumentElementStyle() {
|
|
3515
|
-
const rawDocumentStyle = document.documentElement.style;
|
|
3516
|
-
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
3517
|
-
set: function(target, key, value) {
|
|
3518
|
-
const ret = Reflect.set(target, key, value);
|
|
3519
|
-
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3520
|
-
setCurrentWindowStyle(value);
|
|
3521
|
-
}
|
|
3522
|
-
if (key === "border-radius" || key === "borderRadius" || key === "border-top-left-radius" || key === "borderTopLeftRadius" || key === "border-top-right-radius" || key === "borderTopRightRadius" || key === "border-bottom-left-radius" || key === "borderBottomLeftRadius" || key === "border-bottom-right-radius" || key === "borderBottomRightRadius") {
|
|
3523
|
-
checkCornerRadius();
|
|
3524
|
-
}
|
|
3525
|
-
if (key === "opacity") {
|
|
3526
|
-
checkOpacity();
|
|
3527
|
-
}
|
|
3528
|
-
return ret;
|
|
3529
|
-
},
|
|
3530
|
-
get: function(target, prop) {
|
|
3531
|
-
if (typeof target[prop] === "function") {
|
|
3532
|
-
return function(...args) {
|
|
3533
|
-
if (prop === "setProperty") {
|
|
3534
|
-
const [property, value] = args;
|
|
3535
|
-
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3536
|
-
setCurrentWindowStyle(value);
|
|
3537
|
-
}
|
|
3538
|
-
} else if (prop === "removeProperty") {
|
|
3539
|
-
const [property] = args;
|
|
3540
|
-
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
3541
|
-
setCurrentWindowStyle("none");
|
|
3542
|
-
}
|
|
3543
|
-
}
|
|
3544
|
-
return target[prop](
|
|
3545
|
-
...args
|
|
3546
|
-
);
|
|
3547
|
-
};
|
|
3548
|
-
}
|
|
3549
|
-
return Reflect.get(target, prop);
|
|
3550
|
-
}
|
|
3551
|
-
});
|
|
3552
|
-
Object.defineProperty(document.documentElement, "style", {
|
|
3553
|
-
get: function() {
|
|
3554
|
-
return styleProxy;
|
|
3555
|
-
}
|
|
3556
|
-
});
|
|
3557
|
-
}
|
|
3558
|
-
function monitorExternalStyleChange() {
|
|
3559
|
-
const headObserver = new MutationObserver(checkCSSProperties);
|
|
3560
|
-
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
3561
|
-
}
|
|
3562
|
-
function checkCSSProperties() {
|
|
3563
|
-
checkHtmlBackgroundMaterial();
|
|
3564
|
-
checkCornerRadius();
|
|
3565
|
-
checkOpacity();
|
|
3566
|
-
}
|
|
3567
|
-
function monitorHTMLAttributeChange() {
|
|
3568
|
-
const observer = new MutationObserver((mutations) => {
|
|
3569
|
-
mutations.forEach((mutation) => {
|
|
3570
|
-
if (mutation.type === "attributes" && mutation.attributeName) {
|
|
3571
|
-
checkCSSProperties();
|
|
3572
|
-
}
|
|
3573
|
-
});
|
|
3574
|
-
});
|
|
3575
|
-
observer.observe(document.documentElement, {
|
|
3576
|
-
attributes: true,
|
|
3577
|
-
attributeFilter: ["style", "class"]
|
|
3578
|
-
});
|
|
3579
|
-
}
|
|
3580
|
-
async function spatialWindowPolyfill() {
|
|
3581
|
-
if (!spatial.runInSpatialWeb()) {
|
|
3582
|
-
return;
|
|
3583
|
-
}
|
|
3584
|
-
session = await spatial.requestSession();
|
|
3585
|
-
if (document.readyState === "complete") {
|
|
3586
|
-
checkCSSProperties();
|
|
3587
|
-
} else {
|
|
3588
|
-
window.addEventListener("load", () => {
|
|
3589
|
-
checkCSSProperties();
|
|
3590
|
-
});
|
|
3591
|
-
}
|
|
3592
|
-
hijackDocumentElementStyle();
|
|
3593
|
-
monitorExternalStyleChange();
|
|
3594
|
-
monitorHTMLAttributeChange();
|
|
3595
|
-
}
|
|
3596
|
-
|
|
3597
|
-
// src/index.ts
|
|
3598
|
-
if (!isSSREnv() && navigator.userAgent.indexOf("WebSpatial/") > 0) {
|
|
3599
|
-
injectSceneHook();
|
|
3600
|
-
spatialWindowPolyfill();
|
|
3601
|
-
}
|
|
1
|
+
import { SpatialObject } from "./SpatialObject";
|
|
2
|
+
import { Spatial } from "./Spatial";
|
|
3
|
+
import { SpatialSession } from "./SpatialSession";
|
|
4
|
+
import { SpatialScene } from "./SpatialScene";
|
|
5
|
+
import { SpatializedElement } from "./SpatializedElement";
|
|
6
|
+
import { Spatialized2DElement } from "./Spatialized2DElement";
|
|
7
|
+
import { SpatializedStatic3DElement } from "./SpatializedStatic3DElement";
|
|
8
|
+
import { SpatializedDynamic3DElement } from "./SpatializedDynamic3DElement";
|
|
9
|
+
import * as PhysicalMetrics from "./physicalMetrics";
|
|
10
|
+
export * from "./reality";
|
|
11
|
+
export * from "./types/types";
|
|
12
|
+
export * from "./types/animation";
|
|
13
|
+
export * from "./types/motion";
|
|
14
|
+
import { validateSpatializedMotionConfig } from "./motion";
|
|
15
|
+
export * from "./runtime";
|
|
16
|
+
import { composeSRT, decomposeSRT } from "./utils";
|
|
17
|
+
import { isSSREnv } from "./isSSREnv";
|
|
3602
18
|
export {
|
|
3603
|
-
|
|
3604
|
-
BaseplateVisibilityValues,
|
|
3605
|
-
CAPABILITY_TABLE,
|
|
3606
|
-
COMPONENT_KEYS,
|
|
3607
|
-
CSS_KEYS,
|
|
3608
|
-
CubeInfo,
|
|
3609
|
-
DOM_DEPTH_KEYS,
|
|
3610
|
-
ELEMENT_DOM_DEPTH_KEYS,
|
|
3611
|
-
GESTURE_KEYS,
|
|
3612
|
-
JS_SCENE_KEYS,
|
|
3613
|
-
ModelComponent,
|
|
3614
|
-
physicalMetrics_exports as PhysicalMetrics,
|
|
3615
|
-
SUB_TOKENS_BY_NAME,
|
|
19
|
+
PhysicalMetrics,
|
|
3616
20
|
Spatial,
|
|
3617
|
-
SpatialBoxGeometry,
|
|
3618
|
-
SpatialComponent,
|
|
3619
|
-
SpatialConeGeometry,
|
|
3620
|
-
SpatialCylinderGeometry,
|
|
3621
|
-
SpatialEntity,
|
|
3622
|
-
SpatialGeometry,
|
|
3623
|
-
SpatialMaterial,
|
|
3624
|
-
SpatialModelAsset,
|
|
3625
|
-
SpatialModelEntity,
|
|
3626
21
|
SpatialObject,
|
|
3627
|
-
SpatialPlaneGeometry,
|
|
3628
22
|
SpatialScene,
|
|
3629
|
-
SpatialSceneState,
|
|
3630
|
-
SpatialSceneValues,
|
|
3631
23
|
SpatialSession,
|
|
3632
|
-
SpatialSphereGeometry,
|
|
3633
|
-
SpatialTextureResource,
|
|
3634
|
-
SpatialUnlitMaterial,
|
|
3635
24
|
Spatialized2DElement,
|
|
3636
25
|
SpatializedDynamic3DElement,
|
|
3637
26
|
SpatializedElement,
|
|
3638
|
-
SpatializedElementType,
|
|
3639
27
|
SpatializedStatic3DElement,
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
WINDOW_DOM_DEPTH_KEYS,
|
|
3643
|
-
WebSpatialRuntimeError,
|
|
3644
|
-
WorldAlignmentValues,
|
|
3645
|
-
WorldScalingValues,
|
|
3646
|
-
compareSemver,
|
|
3647
|
-
computeRuntimeFromUserAgent,
|
|
3648
|
-
createAttachmentEntity,
|
|
3649
|
-
getRuntime,
|
|
28
|
+
composeSRT,
|
|
29
|
+
decomposeSRT,
|
|
3650
30
|
isSSREnv,
|
|
3651
|
-
|
|
3652
|
-
isValidSceneUnit,
|
|
3653
|
-
isValidSpatialSceneType,
|
|
3654
|
-
isValidWorldAlignmentType,
|
|
3655
|
-
isValidWorldScalingType,
|
|
3656
|
-
parseSemverOrNull,
|
|
3657
|
-
parseShellToken,
|
|
3658
|
-
resetRuntimeCacheForTests,
|
|
3659
|
-
resolveJsbAdapterPlatform,
|
|
3660
|
-
supports
|
|
31
|
+
validateSpatializedMotionConfig
|
|
3661
32
|
};
|
|
3662
33
|
//# sourceMappingURL=index.js.map
|