@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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getPlatform, getPlatformSync } from "./platform-runtime";
|
|
2
|
+
async function createNativeSpatialDiv() {
|
|
3
|
+
const platform = await getPlatform();
|
|
4
|
+
return platform.createNativeSpatialDiv();
|
|
5
|
+
}
|
|
6
|
+
async function createNativeAttachment(options) {
|
|
7
|
+
const platform = await getPlatform();
|
|
8
|
+
return platform.createNativeAttachment(options);
|
|
9
|
+
}
|
|
10
|
+
function openSpatialSceneSync(url, config, target, features) {
|
|
11
|
+
return getPlatformSync().openSpatialSceneSync(url, config, target, features);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
createNativeAttachment,
|
|
15
|
+
createNativeSpatialDiv,
|
|
16
|
+
openSpatialSceneSync
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=spatial-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spatial-host.ts"],"sourcesContent":["import type { WebSpatialProtocolResult } from './platform-adapter/interface'\nimport { getPlatform, getPlatformSync } from './platform-runtime'\nimport type { SpatialSceneCreationOptionsInternal } from './types/internal'\nimport type { AttachmentEntityOptions } from './types/types'\n\nexport async function createNativeSpatialDiv(): Promise<WebSpatialProtocolResult> {\n const platform = await getPlatform()\n return platform.createNativeSpatialDiv()\n}\n\nexport async function createNativeAttachment(\n options: AttachmentEntityOptions,\n): Promise<WebSpatialProtocolResult> {\n const platform = await getPlatform()\n return platform.createNativeAttachment(options)\n}\n\nexport function openSpatialSceneSync(\n url: string,\n config: SpatialSceneCreationOptionsInternal | undefined,\n target?: string,\n features?: string,\n): WebSpatialProtocolResult {\n return getPlatformSync().openSpatialSceneSync(url, config, target, features)\n}\n"],"mappings":"AACA,SAAS,aAAa,uBAAuB;AAI7C,eAAsB,yBAA4D;AAChF,QAAM,WAAW,MAAM,YAAY;AACnC,SAAO,SAAS,uBAAuB;AACzC;AAEA,eAAsB,uBACpB,SACmC;AACnC,QAAM,WAAW,MAAM,YAAY;AACnC,SAAO,SAAS,uBAAuB,OAAO;AAChD;AAEO,SAAS,qBACd,KACA,QACA,QACA,UAC0B;AAC1B,SAAO,gBAAgB,EAAE,qBAAqB,KAAK,QAAQ,QAAQ,QAAQ;AAC7E;","names":[]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { parseCornerRadius } from "./utils";
|
|
2
|
+
import { Spatial } from "./Spatial";
|
|
3
|
+
const spatial = new Spatial();
|
|
4
|
+
let session = void 0;
|
|
5
|
+
const SpatialGlobalCustomVars = {
|
|
6
|
+
backgroundMaterial: "--xr-background-material"
|
|
7
|
+
};
|
|
8
|
+
let htmlBackgroundMaterial = "";
|
|
9
|
+
function setCurrentWindowStyle(backgroundMaterial) {
|
|
10
|
+
if (backgroundMaterial !== htmlBackgroundMaterial) {
|
|
11
|
+
session?.getSpatialScene()?.updateSpatialProperties({
|
|
12
|
+
material: backgroundMaterial
|
|
13
|
+
});
|
|
14
|
+
htmlBackgroundMaterial = backgroundMaterial;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function checkHtmlBackgroundMaterial() {
|
|
18
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
19
|
+
const backgroundMaterial = computedStyle.getPropertyValue(
|
|
20
|
+
SpatialGlobalCustomVars.backgroundMaterial
|
|
21
|
+
);
|
|
22
|
+
setCurrentWindowStyle(backgroundMaterial || "none");
|
|
23
|
+
}
|
|
24
|
+
let htmlCornerRadius = {
|
|
25
|
+
topLeading: 0,
|
|
26
|
+
bottomLeading: 0,
|
|
27
|
+
topTrailing: 0,
|
|
28
|
+
bottomTrailing: 0
|
|
29
|
+
};
|
|
30
|
+
function checkCornerRadius() {
|
|
31
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
32
|
+
const cornerRadius = parseCornerRadius(computedStyle);
|
|
33
|
+
setCornerRadius(cornerRadius);
|
|
34
|
+
}
|
|
35
|
+
function setCornerRadius(cornerRadius) {
|
|
36
|
+
if (htmlCornerRadius.topLeading !== cornerRadius.topLeading || htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading || htmlCornerRadius.topTrailing !== cornerRadius.topTrailing || htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing) {
|
|
37
|
+
session?.getSpatialScene()?.updateSpatialProperties({
|
|
38
|
+
cornerRadius
|
|
39
|
+
});
|
|
40
|
+
htmlCornerRadius.topLeading = cornerRadius.topLeading;
|
|
41
|
+
htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading;
|
|
42
|
+
htmlCornerRadius.topTrailing = cornerRadius.topTrailing;
|
|
43
|
+
htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function setOpacity(opacity) {
|
|
47
|
+
session?.getSpatialScene().updateSpatialProperties({
|
|
48
|
+
opacity
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function checkOpacity() {
|
|
52
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
53
|
+
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
54
|
+
setOpacity(opacity);
|
|
55
|
+
}
|
|
56
|
+
function hijackDocumentElementStyle() {
|
|
57
|
+
const rawDocumentStyle = document.documentElement.style;
|
|
58
|
+
const styleProxy = new Proxy(rawDocumentStyle, {
|
|
59
|
+
set: function(target, key, value) {
|
|
60
|
+
let ret;
|
|
61
|
+
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
62
|
+
target.setProperty(
|
|
63
|
+
SpatialGlobalCustomVars.backgroundMaterial,
|
|
64
|
+
String(value)
|
|
65
|
+
);
|
|
66
|
+
ret = true;
|
|
67
|
+
} else {
|
|
68
|
+
ret = Reflect.set(target, key, value);
|
|
69
|
+
}
|
|
70
|
+
if (key === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
71
|
+
setCurrentWindowStyle(String(value));
|
|
72
|
+
}
|
|
73
|
+
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") {
|
|
74
|
+
checkCornerRadius();
|
|
75
|
+
}
|
|
76
|
+
if (key === "opacity") {
|
|
77
|
+
checkOpacity();
|
|
78
|
+
}
|
|
79
|
+
return ret;
|
|
80
|
+
},
|
|
81
|
+
get: function(target, prop) {
|
|
82
|
+
if (prop === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
83
|
+
return target.getPropertyValue(
|
|
84
|
+
SpatialGlobalCustomVars.backgroundMaterial
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (typeof target[prop] === "function") {
|
|
88
|
+
return function(...args) {
|
|
89
|
+
if (prop === "setProperty") {
|
|
90
|
+
const [property, value] = args;
|
|
91
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
92
|
+
setCurrentWindowStyle(value);
|
|
93
|
+
}
|
|
94
|
+
} else if (prop === "removeProperty") {
|
|
95
|
+
const [property] = args;
|
|
96
|
+
if (property === SpatialGlobalCustomVars.backgroundMaterial) {
|
|
97
|
+
setCurrentWindowStyle("none");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return target[prop](
|
|
101
|
+
...args
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return Reflect.get(target, prop);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(document.documentElement, "style", {
|
|
109
|
+
get: function() {
|
|
110
|
+
return styleProxy;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function monitorExternalStyleChange() {
|
|
115
|
+
const headObserver = new MutationObserver(checkCSSProperties);
|
|
116
|
+
headObserver.observe(document.head, { childList: true, subtree: true });
|
|
117
|
+
}
|
|
118
|
+
function checkCSSProperties() {
|
|
119
|
+
checkHtmlBackgroundMaterial();
|
|
120
|
+
checkCornerRadius();
|
|
121
|
+
checkOpacity();
|
|
122
|
+
}
|
|
123
|
+
function monitorHTMLAttributeChange() {
|
|
124
|
+
const observer = new MutationObserver((mutations) => {
|
|
125
|
+
mutations.forEach((mutation) => {
|
|
126
|
+
if (mutation.type === "attributes" && mutation.attributeName) {
|
|
127
|
+
checkCSSProperties();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
observer.observe(document.documentElement, {
|
|
132
|
+
attributes: true,
|
|
133
|
+
attributeFilter: ["style", "class"]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async function spatialWindowPolyfill() {
|
|
137
|
+
if (!spatial.runInSpatialWeb()) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
session = await spatial.requestSession();
|
|
141
|
+
if (document.readyState === "complete") {
|
|
142
|
+
checkCSSProperties();
|
|
143
|
+
} else {
|
|
144
|
+
window.addEventListener("load", () => {
|
|
145
|
+
checkCSSProperties();
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
hijackDocumentElementStyle();
|
|
149
|
+
monitorExternalStyleChange();
|
|
150
|
+
monitorHTMLAttributeChange();
|
|
151
|
+
}
|
|
152
|
+
export {
|
|
153
|
+
spatialWindowPolyfill
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=spatial-window-polyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/spatial-window-polyfill.ts"],"sourcesContent":["import { parseCornerRadius } from './utils'\nimport { Spatial } from './Spatial'\nimport { SpatialSession } from './SpatialSession'\nimport { BackgroundMaterialType } from './types/types'\n\nconst spatial = new Spatial()\nlet session: SpatialSession | undefined = undefined\n\nconst SpatialGlobalCustomVars = {\n backgroundMaterial: '--xr-background-material',\n}\n\n// keep track of current html background material\nlet htmlBackgroundMaterial = ''\nfunction setCurrentWindowStyle(backgroundMaterial: string) {\n if (backgroundMaterial !== htmlBackgroundMaterial) {\n session?.getSpatialScene()?.updateSpatialProperties({\n material: backgroundMaterial as BackgroundMaterialType,\n })\n htmlBackgroundMaterial = backgroundMaterial\n }\n}\n\nfunction checkHtmlBackgroundMaterial() {\n const computedStyle = getComputedStyle(document.documentElement)\n\n const backgroundMaterial = computedStyle.getPropertyValue(\n SpatialGlobalCustomVars.backgroundMaterial,\n )\n\n setCurrentWindowStyle(backgroundMaterial || 'none')\n}\n\n// keep track of current corner radius\nlet htmlCornerRadius = {\n topLeading: 0,\n bottomLeading: 0,\n topTrailing: 0,\n bottomTrailing: 0,\n}\n\nfunction checkCornerRadius() {\n const computedStyle = getComputedStyle(document.documentElement)\n const cornerRadius = parseCornerRadius(computedStyle)\n setCornerRadius(cornerRadius)\n}\n\nfunction setCornerRadius(cornerRadius: any) {\n if (\n htmlCornerRadius.topLeading !== cornerRadius.topLeading ||\n htmlCornerRadius.bottomLeading !== cornerRadius.bottomLeading ||\n htmlCornerRadius.topTrailing !== cornerRadius.topTrailing ||\n htmlCornerRadius.bottomTrailing !== cornerRadius.bottomTrailing\n ) {\n session?.getSpatialScene()?.updateSpatialProperties({\n cornerRadius,\n })\n htmlCornerRadius.topLeading = cornerRadius.topLeading\n htmlCornerRadius.bottomLeading = cornerRadius.bottomLeading\n htmlCornerRadius.topTrailing = cornerRadius.topTrailing\n htmlCornerRadius.bottomTrailing = cornerRadius.bottomTrailing\n }\n}\n\nfunction setOpacity(opacity: number) {\n session?.getSpatialScene().updateSpatialProperties({\n opacity,\n })\n}\n\nfunction checkOpacity() {\n const computedStyle = getComputedStyle(document.documentElement)\n const opacity = parseFloat(computedStyle.getPropertyValue('opacity'))\n setOpacity(opacity)\n}\n\nfunction hijackDocumentElementStyle() {\n const rawDocumentStyle = document.documentElement.style\n const styleProxy = new Proxy(rawDocumentStyle, {\n set: function (target, key, value) {\n let ret: boolean\n\n if (key === SpatialGlobalCustomVars.backgroundMaterial) {\n target.setProperty(\n SpatialGlobalCustomVars.backgroundMaterial,\n String(value),\n )\n ret = true\n } else {\n ret = Reflect.set(target, key, value)\n }\n\n if (key === SpatialGlobalCustomVars.backgroundMaterial) {\n setCurrentWindowStyle(String(value))\n }\n\n if (\n key === 'border-radius' ||\n key === 'borderRadius' ||\n key === 'border-top-left-radius' ||\n key === 'borderTopLeftRadius' ||\n key === 'border-top-right-radius' ||\n key === 'borderTopRightRadius' ||\n key === 'border-bottom-left-radius' ||\n key === 'borderBottomLeftRadius' ||\n key === 'border-bottom-right-radius' ||\n key === 'borderBottomRightRadius'\n ) {\n checkCornerRadius()\n }\n\n if (key === 'opacity') {\n checkOpacity()\n }\n\n return ret\n },\n get: function (target, prop: string) {\n if (prop === SpatialGlobalCustomVars.backgroundMaterial) {\n return target.getPropertyValue(\n SpatialGlobalCustomVars.backgroundMaterial,\n )\n }\n\n if (typeof target[prop as keyof CSSStyleDeclaration] === 'function') {\n return function (this: any, ...args: any[]) {\n if (prop === 'setProperty') {\n const [property, value] = args\n if (property === SpatialGlobalCustomVars.backgroundMaterial) {\n setCurrentWindowStyle(value)\n }\n } else if (prop === 'removeProperty') {\n const [property] = args\n if (property === SpatialGlobalCustomVars.backgroundMaterial) {\n setCurrentWindowStyle('none')\n }\n }\n return (target[prop as keyof CSSStyleDeclaration] as Function)(\n ...args,\n )\n }\n }\n return Reflect.get(target, prop)\n },\n })\n Object.defineProperty(document.documentElement, 'style', {\n get: function () {\n return styleProxy\n },\n })\n}\n\nfunction monitorExternalStyleChange() {\n const headObserver = new MutationObserver(checkCSSProperties)\n\n headObserver.observe(document.head, { childList: true, subtree: true })\n}\n\nfunction checkCSSProperties() {\n checkHtmlBackgroundMaterial()\n checkCornerRadius()\n checkOpacity()\n}\n\nfunction monitorHTMLAttributeChange() {\n const observer = new MutationObserver(mutations => {\n mutations.forEach(mutation => {\n if (mutation.type === 'attributes' && mutation.attributeName) {\n checkCSSProperties()\n }\n })\n })\n\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['style', 'class'],\n })\n}\n\nexport async function spatialWindowPolyfill() {\n if (!spatial.runInSpatialWeb()) {\n return\n }\n\n session = await spatial.requestSession()!\n\n if (document.readyState === 'complete') {\n checkCSSProperties()\n } else {\n window.addEventListener('load', () => {\n checkCSSProperties()\n })\n }\n\n hijackDocumentElementStyle()\n monitorExternalStyleChange()\n monitorHTMLAttributeChange()\n}\n"],"mappings":"AAAA,SAAS,yBAAyB;AAClC,SAAS,eAAe;AAIxB,MAAM,UAAU,IAAI,QAAQ;AAC5B,IAAI,UAAsC;AAE1C,MAAM,0BAA0B;AAAA,EAC9B,oBAAoB;AACtB;AAGA,IAAI,yBAAyB;AAC7B,SAAS,sBAAsB,oBAA4B;AACzD,MAAI,uBAAuB,wBAAwB;AACjD,aAAS,gBAAgB,GAAG,wBAAwB;AAAA,MAClD,UAAU;AAAA,IACZ,CAAC;AACD,6BAAyB;AAAA,EAC3B;AACF;AAEA,SAAS,8BAA8B;AACrC,QAAM,gBAAgB,iBAAiB,SAAS,eAAe;AAE/D,QAAM,qBAAqB,cAAc;AAAA,IACvC,wBAAwB;AAAA,EAC1B;AAEA,wBAAsB,sBAAsB,MAAM;AACpD;AAGA,IAAI,mBAAmB;AAAA,EACrB,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