@webspatial/core-sdk 1.6.1 → 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 +84 -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 -1101
- package/dist/index.js +21 -3393
- 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 +148 -91
- package/src/Spatial.ts +0 -21
- package/src/SpatialObject.ts +10 -0
- package/src/SpatialScene.ts +1 -5
- package/src/SpatialSession.ts +17 -3
- package/src/Spatialized2DElement.ts +5 -0
- package/src/SpatializedDynamic3DElement.ts +5 -1
- package/src/SpatializedElement.ts +29 -0
- package/src/SpatializedElementCreator.ts +6 -4
- package/src/SpatializedStatic3DElement.test.ts +99 -0
- package/src/SpatializedStatic3DElement.ts +141 -4
- package/src/WebMsgCommand.ts +50 -0
- package/src/coverage-boost.test.ts +258 -316
- package/src/index.ts +28 -12
- package/src/install-polyfills.ts +38 -0
- package/src/jsbcommand.coverage.test.ts +42 -48
- 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/CommandResultUtils.ts +2 -2
- package/src/platform-adapter/createPlatformSync.ts +36 -0
- package/src/platform-adapter/index.ts +5 -51
- package/src/platform-adapter/interface.ts +35 -23
- package/src/platform-adapter/pico-os/PicoOSPlatform.ts +156 -59
- package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +37 -11
- package/src/platform-adapter/spatialRequestMetadata.test.ts +175 -0
- package/src/platform-adapter/spatialRequestMetadata.ts +48 -0
- package/src/platform-adapter/spatialSceneQuery.ts +17 -0
- package/src/platform-adapter/vision-os/VisionOSPlatform.ts +60 -24
- package/src/platform-runtime.ts +13 -0
- package/src/reality/Attachment.ts +2 -2
- package/src/reality/entity/SpatialEntity.ts +127 -2
- package/src/reality/realityCreator.ts +15 -1
- package/src/reality/resource/SpatialTextureResource.ts +16 -0
- package/src/reality/resource/index.ts +1 -0
- package/src/runtime/WebSpatialRuntimeError.ts +16 -0
- package/src/runtime/capability-data.ts +213 -0
- package/src/runtime/contract-review.test.ts +44 -0
- package/src/runtime/index.ts +17 -0
- package/src/runtime/jsbAdapterPlatform.test.ts +36 -0
- package/src/runtime/jsbAdapterPlatform.ts +51 -0
- package/src/runtime/keys.ts +140 -0
- package/src/runtime/semver.ts +33 -0
- package/src/runtime/supports.test.ts +346 -0
- package/src/runtime/supports.ts +112 -0
- package/src/runtime/types.ts +11 -0
- package/src/runtime/useAnimation.capability.test.ts +275 -0
- package/src/runtime/userAgent.ts +64 -0
- package/src/scene-polyfill.manifest.test.ts +312 -9
- package/src/scene-polyfill.request-metadata.test.ts +39 -0
- package/src/scene-polyfill.test.ts +33 -94
- package/src/scene-polyfill.ts +125 -92
- package/src/spatial-host.ts +25 -0
- 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.d.ts → global.ts} +10 -12
- 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 +12 -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 -1101
- package/dist/iife/index.global.js +0 -75
- package/dist/iife/index.global.js.map +0 -1
- package/src/platform-adapter/android/AndroidPlatform.ts +0 -133
- package/src/platform-adapter/ssr/SSRPlatform.ts +0 -43
- /package/src/{ssr-polyfill.ts → isSSREnv.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/motion/compute/validate.ts"],"sourcesContent":["import { SPATIALIZED_MOTION_PROPERTIES } from '../../types/motion/spatializedMotion'\nimport type {\n NormalizedSpatializedMotionConfig,\n SpatializedMotionProperty,\n SpatializedMotionConfig,\n SpatializedMotionTrack,\n} from '../../types/motion/spatializedMotion'\nimport { normalizeMotionConfig } from './normalize'\nconst ALLOWED_PROPERTIES = new Set<SpatializedMotionProperty>(\n SPATIALIZED_MOTION_PROPERTIES,\n)\n\nconst FORBIDDEN_PREFIXES = [\n 'width',\n 'height',\n 'back',\n 'backOffset',\n 'depth',\n] as const\n\n/**\n * Validates any supported motion config shape before playback or serialization.\n *\n * @param config Motion config in any supported input shape.\n */\nexport function validateSpatializedMotionConfig(\n config: SpatializedMotionConfig,\n): void {\n if (config.tracks !== undefined) {\n throw new Error('[SpatializedMotion] tracks authoring is internal')\n }\n const normalized = normalizeMotionConfig(config)\n validateNormalizedMotionConfig(normalized)\n}\n\n/**\n * Validates the canonical track-based motion config form.\n *\n * @param config Canonical motion config to validate.\n */\nexport function validateNormalizedMotionConfig(\n config: NormalizedSpatializedMotionConfig,\n): void {\n const { duration, tracks } = config\n\n if (\n typeof duration !== 'number' ||\n !Number.isFinite(duration) ||\n duration <= 0\n ) {\n throw new Error('[SpatializedMotion] duration must be a finite number > 0')\n }\n\n if (!Array.isArray(tracks) || tracks.length === 0) {\n throw new Error('[SpatializedMotion] tracks must be a non-empty array')\n }\n\n const seen = new Set<string>()\n for (const track of tracks) {\n validateTrack(track, duration, seen)\n }\n\n if (config.delay !== undefined) {\n const d = config.delay\n if (typeof d !== 'number' || !Number.isFinite(d) || d < 0) {\n throw new Error('[SpatializedMotion] delay must be >= 0 and finite')\n }\n }\n\n if (config.playbackRate !== undefined) {\n const r = config.playbackRate\n if (typeof r !== 'number' || !Number.isFinite(r) || r <= 0) {\n throw new Error('[SpatializedMotion] playbackRate must be > 0 and finite')\n }\n }\n}\n\n/**\n * Validates a single track against property and keyframe invariants.\n *\n * @param track Motion track to validate.\n * @param duration Parent motion duration.\n * @param seen Track-property set used to detect duplicates.\n */\nfunction validateTrack(\n track: SpatializedMotionTrack,\n duration: number,\n seen: Set<string>,\n): void {\n const prop = track.property as string\n for (const forbidden of FORBIDDEN_PREFIXES) {\n if (prop === forbidden || prop.startsWith(`${forbidden}.`)) {\n throw new Error(\n `[SpatializedMotion] property \"${prop}\" is not animatable`,\n )\n }\n }\n\n if (!ALLOWED_PROPERTIES.has(track.property)) {\n throw new Error(`[SpatializedMotion] unknown property \"${prop}\"`)\n }\n\n if (seen.has(prop)) {\n throw new Error(`[SpatializedMotion] duplicate track for \"${prop}\"`)\n }\n seen.add(prop)\n\n const kf = track.keyframes\n if (!Array.isArray(kf) || kf.length < 2) {\n throw new Error(\n `[SpatializedMotion] track \"${prop}\" needs at least 2 keyframes`,\n )\n }\n\n let prevAt = -Infinity\n for (const frame of kf) {\n if (typeof frame.at !== 'number' || !Number.isFinite(frame.at)) {\n throw new Error(\n `[SpatializedMotion] keyframe.at must be finite for \"${prop}\"`,\n )\n }\n if (frame.at < 0 || frame.at > duration) {\n throw new Error(\n `[SpatializedMotion] keyframe.at must be within [0, duration] for \"${prop}\"`,\n )\n }\n if (frame.at <= prevAt) {\n throw new Error(\n `[SpatializedMotion] keyframe times must be strictly increasing for \"${prop}\"`,\n )\n }\n prevAt = frame.at\n validateScalar(frame.value, track.property)\n }\n}\n\n/**\n * Validates a numeric sample for a specific motion property.\n *\n * @param value Numeric sample value to validate.\n * @param property Motion property the value belongs to.\n */\nfunction validateScalar(\n value: number,\n property: SpatializedMotionProperty,\n): void {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new Error(`[SpatializedMotion] invalid value for ${property}`)\n }\n if (property === 'opacity' && (value < 0 || value > 1)) {\n throw new Error('[SpatializedMotion] opacity must be in [0, 1]')\n }\n if (property.startsWith('transform.scale.') && value < 0) {\n throw new Error('[SpatializedMotion] scale must be >=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M,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { b0 as AnimationObject, b1 as AnimationObjectCallbacks, b2 as AnimationObjectCreateOptions } from '../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
export { validateSpatializedMotionConfig } from './compute/validate.js';
|
|
3
|
+
import '../types/motion/spatializedVisual.js';
|
|
4
|
+
import '../types/motion/spatializedPlayback.js';
|
|
5
|
+
import '../types/global.js';
|
|
6
|
+
import '../physicalMetrics-W5uZ5xKb.js';
|
|
7
|
+
import '../SpatialObject.js';
|
|
8
|
+
import '../reality/component/SpatialComponent.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/motion/index.ts"],"sourcesContent":["export * from './AnimationObject'\nexport { validateSpatializedMotionConfig } from './compute/validate'\n"],"mappings":"AAAA,cAAc;AACd,SAAS,uCAAuC;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a$ as NormalizedSpatializedMotionConfig, aO as SpatializedMotionTimeline } from '../../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
import '../../types/motion/spatializedVisual.js';
|
|
3
|
+
import '../../types/motion/spatializedPlayback.js';
|
|
4
|
+
import '../../types/global.js';
|
|
5
|
+
import '../../physicalMetrics-W5uZ5xKb.js';
|
|
6
|
+
import '../../SpatialObject.js';
|
|
7
|
+
import '../../reality/component/SpatialComponent.js';
|
|
8
|
+
|
|
9
|
+
/** Full timeline payload for native. */
|
|
10
|
+
declare function motionConfigToNativeTimeline(config: NormalizedSpatializedMotionConfig): SpatializedMotionTimeline;
|
|
11
|
+
|
|
12
|
+
export { motionConfigToNativeTimeline };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function motionConfigToNativeTimeline(config) {
|
|
2
|
+
return {
|
|
3
|
+
duration: config.duration,
|
|
4
|
+
delay: config.delay,
|
|
5
|
+
playbackRate: config.playbackRate,
|
|
6
|
+
loop: config.loop,
|
|
7
|
+
tracks: config.tracks.map((track) => ({
|
|
8
|
+
property: track.property,
|
|
9
|
+
keyframes: track.keyframes.map((k) => ({
|
|
10
|
+
at: k.at,
|
|
11
|
+
value: k.value,
|
|
12
|
+
...k.timingFunction !== void 0 ? { timingFunction: k.timingFunction } : {}
|
|
13
|
+
})),
|
|
14
|
+
timingFunction: track.timingFunction ?? config.timingFunction ?? "linear"
|
|
15
|
+
}))
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
motionConfigToNativeTimeline
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=serializeMotionTimeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/motion/native/serializeMotionTimeline.ts"],"sourcesContent":["import type {\n NormalizedSpatializedMotionConfig,\n SpatializedMotionTimeline,\n} from '../../types/motion/spatializedMotion'\n\n/** Full timeline payload for native. */\nexport function motionConfigToNativeTimeline(\n config: NormalizedSpatializedMotionConfig,\n): SpatializedMotionTimeline {\n return {\n duration: config.duration,\n delay: config.delay,\n playbackRate: config.playbackRate,\n loop: config.loop,\n tracks: config.tracks.map(track => ({\n property: track.property,\n keyframes: track.keyframes.map(k => ({\n at: k.at,\n value: k.value,\n ...(k.timingFunction !== undefined\n ? { timingFunction: k.timingFunction }\n : {}),\n })),\n timingFunction: track.timingFunction ?? config.timingFunction ?? 'linear',\n })),\n }\n}\n"],"mappings":"AAMO,SAAS,6BACd,QAC2B;AAC3B,SAAO;AAAA,IACL,UAAU,OAAO;AAAA,IACjB,OAAO,OAAO;AAAA,IACd,cAAc,OAAO;AAAA,IACrB,MAAM,OAAO;AAAA,IACb,QAAQ,OAAO,OAAO,IAAI,YAAU;AAAA,MAClC,UAAU,MAAM;AAAA,MAChB,WAAW,MAAM,UAAU,IAAI,QAAM;AAAA,QACnC,IAAI,EAAE;AAAA,QACN,OAAO,EAAE;AAAA,QACT,GAAI,EAAE,mBAAmB,SACrB,EAAE,gBAAgB,EAAE,eAAe,IACnC,CAAC;AAAA,MACP,EAAE;AAAA,MACF,gBAAgB,MAAM,kBAAkB,OAAO,kBAAkB;AAAA,IACnE,EAAE;AAAA,EACJ;AACF;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
type PhysicalMetricsValueShape = {
|
|
2
|
+
meterToPtUnscaled: number;
|
|
3
|
+
meterToPtScaled: number;
|
|
4
|
+
};
|
|
5
|
+
type WorldScalingCompensation = 'unscaled' | 'scaled';
|
|
6
|
+
type ConvertOption = {
|
|
7
|
+
worldScalingCompensation: WorldScalingCompensation;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Converts scene points (pt) to physical meters (m).
|
|
11
|
+
*
|
|
12
|
+
* @param point Points value to convert.
|
|
13
|
+
* @param options Optional conversion options to select world scaling compensation.
|
|
14
|
+
* @returns Physical length in meters.
|
|
15
|
+
*/
|
|
16
|
+
declare function pointToPhysical(point: number, options?: ConvertOption): number;
|
|
17
|
+
/**
|
|
18
|
+
* Converts physical meters (m) to scene points (pt).
|
|
19
|
+
*
|
|
20
|
+
* @param physical Physical length in meters to convert.
|
|
21
|
+
* @param options Optional conversion options to select world scaling compensation.
|
|
22
|
+
* @returns Points length in the scene.
|
|
23
|
+
*/
|
|
24
|
+
declare function physicalToPoint(physical: number, options?: ConvertOption): number;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the current physical metrics used for conversions.
|
|
27
|
+
*
|
|
28
|
+
* @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.
|
|
29
|
+
*/
|
|
30
|
+
declare function getValue(): PhysicalMetricsValueShape;
|
|
31
|
+
/**
|
|
32
|
+
* Subscribes to physical metrics changes.
|
|
33
|
+
*
|
|
34
|
+
* @param cb Callback invoked when metrics update is detected.
|
|
35
|
+
* @returns Unsubscribe function to remove the listener.
|
|
36
|
+
*/
|
|
37
|
+
declare function subscribe(cb: () => void): () => void;
|
|
38
|
+
|
|
39
|
+
type physicalMetrics_PhysicalMetricsValueShape = PhysicalMetricsValueShape;
|
|
40
|
+
declare const physicalMetrics_getValue: typeof getValue;
|
|
41
|
+
declare const physicalMetrics_physicalToPoint: typeof physicalToPoint;
|
|
42
|
+
declare const physicalMetrics_pointToPhysical: typeof pointToPhysical;
|
|
43
|
+
declare const physicalMetrics_subscribe: typeof subscribe;
|
|
44
|
+
declare namespace physicalMetrics {
|
|
45
|
+
export { type physicalMetrics_PhysicalMetricsValueShape as PhysicalMetricsValueShape, physicalMetrics_getValue as getValue, physicalMetrics_physicalToPoint as physicalToPoint, physicalMetrics_pointToPhysical as pointToPhysical, physicalMetrics_subscribe as subscribe };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { type PhysicalMetricsValueShape as P, physicalToPoint as a, pointToPhysical as b, getValue as g, physicalMetrics as p, subscribe as s };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { P as PhysicalMetricsValueShape, g as getValue, a as physicalToPoint, b as pointToPhysical, s as subscribe } from './physicalMetrics-W5uZ5xKb.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SpatialWebEvent } from "./SpatialWebEvent";
|
|
2
|
+
let snapshot = {
|
|
3
|
+
meterToPtUnscaled: 1360,
|
|
4
|
+
meterToPtScaled: 1360
|
|
5
|
+
};
|
|
6
|
+
function getWorldScalingCompensation(options) {
|
|
7
|
+
return options?.worldScalingCompensation ?? "scaled";
|
|
8
|
+
}
|
|
9
|
+
function pointToPhysical(point, options) {
|
|
10
|
+
updateValue();
|
|
11
|
+
const compensation = getWorldScalingCompensation(options);
|
|
12
|
+
if (compensation === "unscaled") {
|
|
13
|
+
return point / snapshot.meterToPtUnscaled;
|
|
14
|
+
}
|
|
15
|
+
return point / snapshot.meterToPtScaled;
|
|
16
|
+
}
|
|
17
|
+
function physicalToPoint(physical, options) {
|
|
18
|
+
updateValue();
|
|
19
|
+
const compensation = getWorldScalingCompensation(options);
|
|
20
|
+
if (compensation === "unscaled") {
|
|
21
|
+
return physical * snapshot.meterToPtUnscaled;
|
|
22
|
+
}
|
|
23
|
+
return physical * snapshot.meterToPtScaled;
|
|
24
|
+
}
|
|
25
|
+
function updateValue() {
|
|
26
|
+
if (typeof window === "undefined") return;
|
|
27
|
+
const src = window.__webspatialsdk__?.physicalMetrics;
|
|
28
|
+
if (!src) return;
|
|
29
|
+
const next = {
|
|
30
|
+
meterToPtScaled: src.meterToPtScaled ?? snapshot.meterToPtScaled,
|
|
31
|
+
meterToPtUnscaled: src.meterToPtUnscaled ?? snapshot.meterToPtUnscaled
|
|
32
|
+
};
|
|
33
|
+
if (next.meterToPtScaled !== snapshot.meterToPtScaled || next.meterToPtUnscaled !== snapshot.meterToPtUnscaled) {
|
|
34
|
+
snapshot = next;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function getValue() {
|
|
38
|
+
updateValue();
|
|
39
|
+
return snapshot;
|
|
40
|
+
}
|
|
41
|
+
function subscribe(cb) {
|
|
42
|
+
if (typeof window === "undefined") return () => {
|
|
43
|
+
};
|
|
44
|
+
const handler = () => {
|
|
45
|
+
cb();
|
|
46
|
+
};
|
|
47
|
+
SpatialWebEvent.addEventReceiver("window", handler);
|
|
48
|
+
return () => {
|
|
49
|
+
SpatialWebEvent.removeEventReceiver("window");
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
getValue,
|
|
54
|
+
physicalToPoint,
|
|
55
|
+
pointToPhysical,
|
|
56
|
+
subscribe
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=physicalMetrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/physicalMetrics.ts"],"sourcesContent":["import { SpatialWebEvent } from './SpatialWebEvent'\nexport type PhysicalMetricsValueShape = {\n meterToPtUnscaled: number\n meterToPtScaled: number\n}\n\ntype WorldScalingCompensation = 'unscaled' | 'scaled'\n\ntype ConvertOption = { worldScalingCompensation: WorldScalingCompensation }\n\n// Fallback calibration: 1 meter ≈ 1360 pt for both scaled and unscaled modes.\n// This baseline ensures pointToPhysical(1360) === 1 and physicalToPoint(1) === 1360\n// until native physical metrics are injected into window.__webspatialsdk__.physicalMetrics\n// and a 'WebSpatialPhysicalMetricsUpdate' event updates the snapshot at runtime.\nlet snapshot: PhysicalMetricsValueShape = {\n meterToPtUnscaled: 1360,\n meterToPtScaled: 1360,\n}\n\nfunction getWorldScalingCompensation(options?: ConvertOption) {\n return options?.worldScalingCompensation ?? 'scaled' // default to scaled\n}\n\n/**\n * Converts scene points (pt) to physical meters (m).\n *\n * @param point Points value to convert.\n * @param options Optional conversion options to select world scaling compensation.\n * @returns Physical length in meters.\n */\nexport function pointToPhysical(point: number, options?: ConvertOption) {\n updateValue()\n const compensation = getWorldScalingCompensation(options)\n if (compensation === 'unscaled') {\n return point / snapshot.meterToPtUnscaled\n }\n return point / snapshot.meterToPtScaled\n}\n\n/**\n * Converts physical meters (m) to scene points (pt).\n *\n * @param physical Physical length in meters to convert.\n * @param options Optional conversion options to select world scaling compensation.\n * @returns Points length in the scene.\n */\nexport function physicalToPoint(physical: number, options?: ConvertOption) {\n updateValue()\n const compensation = getWorldScalingCompensation(options)\n if (compensation === 'unscaled') {\n return physical * snapshot.meterToPtUnscaled\n }\n return physical * snapshot.meterToPtScaled\n}\n\nfunction updateValue() {\n // ssr protected\n if (typeof window === 'undefined') return\n const src = window.__webspatialsdk__?.physicalMetrics\n if (!src) return\n const next = {\n meterToPtScaled: src.meterToPtScaled ?? snapshot.meterToPtScaled,\n meterToPtUnscaled: src.meterToPtUnscaled ?? snapshot.meterToPtUnscaled,\n }\n // only update if there is a change\n if (\n next.meterToPtScaled !== snapshot.meterToPtScaled ||\n next.meterToPtUnscaled !== snapshot.meterToPtUnscaled\n ) {\n snapshot = next\n }\n}\n\n/**\n * Returns the current physical metrics used for conversions.\n *\n * @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.\n */\nexport function getValue(): PhysicalMetricsValueShape {\n updateValue()\n return snapshot\n}\n\n/**\n * Subscribes to physical metrics changes.\n *\n * @param cb Callback invoked when metrics update is detected.\n * @returns Unsubscribe function to remove the listener.\n */\nexport function subscribe(cb: () => void) {\n // ssr protected\n if (typeof window === 'undefined') return () => {}\n const handler = () => {\n cb()\n }\n // receive metrics update from native via SpatialWebEvent, id: \"window\"\n SpatialWebEvent.addEventReceiver('window', handler)\n return () => {\n SpatialWebEvent.removeEventReceiver('window')\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAchC,IAAI,WAAsC;AAAA,EACxC,mBAAmB;AAAA,EACnB,iBAAiB;AACnB;AAEA,SAAS,4BAA4B,SAAyB;AAC5D,SAAO,SAAS,4BAA4B;AAC9C;AASO,SAAS,gBAAgB,OAAe,SAAyB;AACtE,cAAY;AACZ,QAAM,eAAe,4BAA4B,OAAO;AACxD,MAAI,iBAAiB,YAAY;AAC/B,WAAO,QAAQ,SAAS;AAAA,EAC1B;AACA,SAAO,QAAQ,SAAS;AAC1B;AASO,SAAS,gBAAgB,UAAkB,SAAyB;AACzE,cAAY;AACZ,QAAM,eAAe,4BAA4B,OAAO;AACxD,MAAI,iBAAiB,YAAY;AAC/B,WAAO,WAAW,SAAS;AAAA,EAC7B;AACA,SAAO,WAAW,SAAS;AAC7B;AAEA,SAAS,cAAc;AAErB,MAAI,OAAO,WAAW,YAAa;AACnC,QAAM,MAAM,OAAO,mBAAmB;AACtC,MAAI,CAAC,IAAK;AACV,QAAM,OAAO;AAAA,IACX,iBAAiB,IAAI,mBAAmB,SAAS;AAAA,IACjD,mBAAmB,IAAI,qBAAqB,SAAS;AAAA,EACvD;AAEA,MACE,KAAK,oBAAoB,SAAS,mBAClC,KAAK,sBAAsB,SAAS,mBACpC;AACA,eAAW;AAAA,EACb;AACF;AAOO,SAAS,WAAsC;AACpD,cAAY;AACZ,SAAO;AACT;AAQO,SAAS,UAAU,IAAgB;AAExC,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AACjD,QAAM,UAAU,MAAM;AACpB,OAAG;AAAA,EACL;AAEA,kBAAgB,iBAAiB,UAAU,OAAO;AAClD,SAAO,MAAM;AACX,oBAAgB,oBAAoB,QAAQ;AAAA,EAC9C;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { aK as CommandResult } from '../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
import '../types/motion/spatializedVisual.js';
|
|
3
|
+
import '../types/motion/spatializedPlayback.js';
|
|
4
|
+
import '../types/global.js';
|
|
5
|
+
import '../physicalMetrics-W5uZ5xKb.js';
|
|
6
|
+
import '../SpatialObject.js';
|
|
7
|
+
import '../reality/component/SpatialComponent.js';
|
|
8
|
+
|
|
9
|
+
declare function CommandResultSuccess<TData>(data: TData): CommandResult<TData>;
|
|
10
|
+
declare function CommandResultFailure(errorCode: string, errorMessage?: string): CommandResult<undefined>;
|
|
11
|
+
|
|
12
|
+
export { CommandResultFailure, CommandResultSuccess };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function CommandResultSuccess(data) {
|
|
2
|
+
return {
|
|
3
|
+
success: true,
|
|
4
|
+
data,
|
|
5
|
+
errorCode: "",
|
|
6
|
+
errorMessage: ""
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function CommandResultFailure(errorCode, errorMessage = "") {
|
|
10
|
+
return {
|
|
11
|
+
success: false,
|
|
12
|
+
data: void 0,
|
|
13
|
+
errorCode,
|
|
14
|
+
errorMessage
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
CommandResultFailure,
|
|
19
|
+
CommandResultSuccess
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=CommandResultUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/platform-adapter/CommandResultUtils.ts"],"sourcesContent":["import { CommandResult } from './interface'\n\nexport function CommandResultSuccess<TData>(data: TData): CommandResult<TData> {\n return {\n success: true,\n data,\n errorCode: '',\n errorMessage: '',\n }\n}\n\nexport function CommandResultFailure(\n errorCode: string,\n errorMessage = '',\n): CommandResult<undefined> {\n return {\n success: false,\n data: undefined,\n errorCode,\n errorMessage,\n }\n}\n"],"mappings":"AAEO,SAAS,qBAA4B,MAAmC;AAC7E,SAAO;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA,WAAW;AAAA,IACX,cAAc;AAAA,EAChB;AACF;AAEO,SAAS,qBACd,WACA,eAAe,IACW;AAC1B,SAAO;AAAA,IACL,SAAS;AAAA,IACT,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { aY as PlatformAbility } from '../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
import '../types/motion/spatializedVisual.js';
|
|
3
|
+
import '../types/motion/spatializedPlayback.js';
|
|
4
|
+
import '../types/global.js';
|
|
5
|
+
import '../physicalMetrics-W5uZ5xKb.js';
|
|
6
|
+
import '../SpatialObject.js';
|
|
7
|
+
import '../reality/component/SpatialComponent.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Construct the JSB platform synchronously (static imports).
|
|
11
|
+
* Used by getPlatformSync (e.g. scene-polyfill openSpatialSceneSync) and kept
|
|
12
|
+
* consistent with async createPlatform so paths share one implementation.
|
|
13
|
+
*/
|
|
14
|
+
declare function createPlatformSync(): PlatformAbility;
|
|
15
|
+
|
|
16
|
+
export { createPlatformSync };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { resolveJsbAdapterPlatform } from "../runtime/jsbAdapterPlatform";
|
|
2
|
+
import { isSSREnv } from "../isSSREnv";
|
|
3
|
+
import { PicoOSPlatform } from "./pico-os/PicoOSPlatform";
|
|
4
|
+
import { PuppeteerPlatform } from "./puppeteer/PuppeteerPlatform";
|
|
5
|
+
import { VisionOSPlatform } from "./vision-os/VisionOSPlatform";
|
|
6
|
+
const SSR_PLATFORM_ERROR = "WebSpatial platform APIs (JSB / openSpatialScene) cannot run during SSR or without window. Use @webspatial/react-sdk default entry with facades, or CSR-gate spatial UI on the client.";
|
|
7
|
+
function assertNever(_) {
|
|
8
|
+
throw new Error("Unhandled jsb adapter platform kind");
|
|
9
|
+
}
|
|
10
|
+
function createPlatformSync() {
|
|
11
|
+
if (isSSREnv()) {
|
|
12
|
+
throw new Error(SSR_PLATFORM_ERROR);
|
|
13
|
+
}
|
|
14
|
+
const userAgent = window.navigator.userAgent;
|
|
15
|
+
const kind = resolveJsbAdapterPlatform(userAgent);
|
|
16
|
+
switch (kind) {
|
|
17
|
+
case "puppeteer":
|
|
18
|
+
return new PuppeteerPlatform();
|
|
19
|
+
case "picoos":
|
|
20
|
+
return new PicoOSPlatform();
|
|
21
|
+
case "visionos":
|
|
22
|
+
return new VisionOSPlatform();
|
|
23
|
+
default:
|
|
24
|
+
return assertNever(kind);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
createPlatformSync
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=createPlatformSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/platform-adapter/createPlatformSync.ts"],"sourcesContent":["import { resolveJsbAdapterPlatform } from '../runtime/jsbAdapterPlatform'\nimport { isSSREnv } from '../isSSREnv'\nimport { PlatformAbility } from './interface'\nimport { PicoOSPlatform } from './pico-os/PicoOSPlatform'\nimport { PuppeteerPlatform } from './puppeteer/PuppeteerPlatform'\nimport { VisionOSPlatform } from './vision-os/VisionOSPlatform'\n\nconst SSR_PLATFORM_ERROR =\n 'WebSpatial platform APIs (JSB / openSpatialScene) cannot run during SSR or without window. Use @webspatial/react-sdk default entry with facades, or CSR-gate spatial UI on the client.'\n\nfunction assertNever(_: never): never {\n throw new Error('Unhandled jsb adapter platform kind')\n}\n\n/**\n * Construct the JSB platform synchronously (static imports).\n * Used by getPlatformSync (e.g. scene-polyfill openSpatialSceneSync) and kept\n * consistent with async createPlatform so paths share one implementation.\n */\nexport function createPlatformSync(): PlatformAbility {\n if (isSSREnv()) {\n throw new Error(SSR_PLATFORM_ERROR)\n }\n const userAgent = window.navigator.userAgent\n const kind = resolveJsbAdapterPlatform(userAgent)\n switch (kind) {\n case 'puppeteer':\n return new PuppeteerPlatform()\n case 'picoos':\n return new PicoOSPlatform()\n case 'visionos':\n return new VisionOSPlatform()\n default:\n return assertNever(kind)\n }\n}\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAEjC,MAAM,qBACJ;AAEF,SAAS,YAAY,GAAiB;AACpC,QAAM,IAAI,MAAM,qCAAqC;AACvD;AAOO,SAAS,qBAAsC;AACpD,MAAI,SAAS,GAAG;AACd,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AACA,QAAM,YAAY,OAAO,UAAU;AACnC,QAAM,OAAO,0BAA0B,SAAS;AAChD,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,IAAI,kBAAkB;AAAA,IAC/B,KAAK;AACH,aAAO,IAAI,eAAe;AAAA,IAC5B,KAAK;AACH,aAAO,IAAI,iBAAiB;AAAA,IAC9B;AACE,aAAO,YAAY,IAAI;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { createPlatformSync } from './createPlatformSync.js';
|
|
2
|
+
import { aY as PlatformAbility } from '../spatializedElementMotion-_0XWPQCE.js';
|
|
3
|
+
import '../types/motion/spatializedVisual.js';
|
|
4
|
+
import '../types/motion/spatializedPlayback.js';
|
|
5
|
+
import '../types/global.js';
|
|
6
|
+
import '../physicalMetrics-W5uZ5xKb.js';
|
|
7
|
+
import '../SpatialObject.js';
|
|
8
|
+
import '../reality/component/SpatialComponent.js';
|
|
9
|
+
|
|
10
|
+
declare function createPlatform(): Promise<PlatformAbility>;
|
|
11
|
+
|
|
12
|
+
export { createPlatform };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createPlatformSync } from "./createPlatformSync";
|
|
2
|
+
import { createPlatformSync as createPlatformSync2 } from "./createPlatformSync";
|
|
3
|
+
async function createPlatform() {
|
|
4
|
+
return createPlatformSync2();
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
createPlatform,
|
|
8
|
+
createPlatformSync
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/platform-adapter/index.ts"],"sourcesContent":["export { createPlatformSync } from './createPlatformSync'\nimport { createPlatformSync } from './createPlatformSync'\nimport type { PlatformAbility } from './interface'\n\nexport async function createPlatform(): Promise<PlatformAbility> {\n return createPlatformSync()\n}\n"],"mappings":"AAAA,SAAS,0BAA0B;AACnC,SAAS,sBAAAA,2BAA0B;AAGnC,eAAsB,iBAA2C;AAC/D,SAAOA,oBAAmB;AAC5B;","names":["createPlatformSync"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { aK as CommandResult, aY as PlatformAbility, aZ as WebSpatialProtocolResult } from '../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
import '../types/motion/spatializedVisual.js';
|
|
3
|
+
import '../types/motion/spatializedPlayback.js';
|
|
4
|
+
import '../types/global.js';
|
|
5
|
+
import '../physicalMetrics-W5uZ5xKb.js';
|
|
6
|
+
import '../SpatialObject.js';
|
|
7
|
+
import '../reality/component/SpatialComponent.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { aY as PlatformAbility, aK as CommandResult, aQ as SpatialSceneCreationOptionsInternal, aZ as WebSpatialProtocolResult, h as AttachmentEntityOptions } from '../../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
import '../../types/motion/spatializedVisual.js';
|
|
3
|
+
import '../../types/motion/spatializedPlayback.js';
|
|
4
|
+
import '../../types/global.js';
|
|
5
|
+
import '../../physicalMetrics-W5uZ5xKb.js';
|
|
6
|
+
import '../../SpatialObject.js';
|
|
7
|
+
import '../../reality/component/SpatialComponent.js';
|
|
8
|
+
|
|
9
|
+
declare class PicoOSPlatform implements PlatformAbility {
|
|
10
|
+
callJSB(cmd: string, msg: string): Promise<CommandResult>;
|
|
11
|
+
openSpatialSceneSync(url: string, config: SpatialSceneCreationOptionsInternal | undefined, target?: string, features?: string): WebSpatialProtocolResult;
|
|
12
|
+
createNativeSpatialDiv(): Promise<WebSpatialProtocolResult>;
|
|
13
|
+
createNativeAttachment(_options?: AttachmentEntityOptions): Promise<WebSpatialProtocolResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Async path for createNativeSpatialDiv / createNativeAttachment: open webspatial URL
|
|
16
|
+
* with rid= correlation (Pico OS 6).
|
|
17
|
+
*/
|
|
18
|
+
private waitForRidProtocolAsync;
|
|
19
|
+
private openWindow;
|
|
20
|
+
private parseBridgeResponse;
|
|
21
|
+
private toCommandResult;
|
|
22
|
+
private parseJSBError;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { PicoOSPlatform };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommandResultFailure,
|
|
3
|
+
CommandResultSuccess
|
|
4
|
+
} from "../CommandResultUtils";
|
|
5
|
+
import { buildSpatialSceneQuery } from "../spatialSceneQuery";
|
|
6
|
+
import { SpatialWebEvent } from "../../SpatialWebEvent";
|
|
7
|
+
import {
|
|
8
|
+
buildSpatialRequestQuery,
|
|
9
|
+
createSpatialRequestId,
|
|
10
|
+
DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS
|
|
11
|
+
} from "../spatialRequestMetadata";
|
|
12
|
+
let requestId = 0;
|
|
13
|
+
const MAX_ID = 1e5;
|
|
14
|
+
const DEFAULT_JSB_ERROR_CODE = "E_PICO_JSB";
|
|
15
|
+
const DEFAULT_JSB_ERROR_MESSAGE = "Pico JSB execution failed";
|
|
16
|
+
function nextRequestId() {
|
|
17
|
+
requestId = (requestId + 1) % MAX_ID;
|
|
18
|
+
return `rId_${requestId}`;
|
|
19
|
+
}
|
|
20
|
+
class PicoOSPlatform {
|
|
21
|
+
async callJSB(cmd, msg) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
try {
|
|
24
|
+
const rId = nextRequestId();
|
|
25
|
+
SpatialWebEvent.addEventReceiver(rId, (result) => {
|
|
26
|
+
SpatialWebEvent.removeEventReceiver(rId);
|
|
27
|
+
resolve(this.toCommandResult(result));
|
|
28
|
+
});
|
|
29
|
+
const ans = window.webspatialBridge.postMessage(rId, cmd, msg);
|
|
30
|
+
if (ans !== "") {
|
|
31
|
+
SpatialWebEvent.removeEventReceiver(rId);
|
|
32
|
+
resolve(this.parseBridgeResponse(ans));
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
|
|
36
|
+
const { code, message } = this.parseJSBError(error);
|
|
37
|
+
resolve(CommandResultFailure(code, message));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
openSpatialSceneSync(url, config, target, features) {
|
|
42
|
+
const query = buildSpatialSceneQuery(url, config);
|
|
43
|
+
const { spatialId: id = "", windowProxy } = this.openWindow(
|
|
44
|
+
"createSpatialScene",
|
|
45
|
+
query,
|
|
46
|
+
target,
|
|
47
|
+
features
|
|
48
|
+
);
|
|
49
|
+
return CommandResultSuccess({ windowProxy, id });
|
|
50
|
+
}
|
|
51
|
+
createNativeSpatialDiv() {
|
|
52
|
+
return this.waitForRidProtocolAsync("createSpatialized2DElement");
|
|
53
|
+
}
|
|
54
|
+
createNativeAttachment(_options) {
|
|
55
|
+
return this.waitForRidProtocolAsync("createAttachment");
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Async path for createNativeSpatialDiv / createNativeAttachment: open webspatial URL
|
|
59
|
+
* with rid= correlation (Pico OS 6).
|
|
60
|
+
*/
|
|
61
|
+
waitForRidProtocolAsync(command) {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
const createdId = createSpatialRequestId();
|
|
64
|
+
let settled = false;
|
|
65
|
+
let timeoutId;
|
|
66
|
+
let cleanupDocumentReadyListener;
|
|
67
|
+
const settle = (result) => {
|
|
68
|
+
if (settled) return;
|
|
69
|
+
settled = true;
|
|
70
|
+
if (timeoutId !== void 0) {
|
|
71
|
+
clearTimeout(timeoutId);
|
|
72
|
+
}
|
|
73
|
+
cleanupDocumentReadyListener?.();
|
|
74
|
+
cleanupDocumentReadyListener = void 0;
|
|
75
|
+
SpatialWebEvent.removeEventReceiver(createdId);
|
|
76
|
+
resolve(result);
|
|
77
|
+
};
|
|
78
|
+
try {
|
|
79
|
+
let windowProxy = null;
|
|
80
|
+
const settleWhenDocumentComplete = (spatialId) => {
|
|
81
|
+
const successResult = CommandResultSuccess({
|
|
82
|
+
windowProxy,
|
|
83
|
+
id: spatialId
|
|
84
|
+
});
|
|
85
|
+
const childDocument = windowProxy?.document;
|
|
86
|
+
if (!childDocument) {
|
|
87
|
+
settle(
|
|
88
|
+
CommandResultFailure(
|
|
89
|
+
"E_SPATIAL_DOCUMENT_UNAVAILABLE",
|
|
90
|
+
`${command} document is unavailable`
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (childDocument.readyState === "complete") {
|
|
96
|
+
settle(successResult);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const onReadyStateChange = () => {
|
|
100
|
+
if (childDocument.readyState !== "complete") return;
|
|
101
|
+
settle(successResult);
|
|
102
|
+
};
|
|
103
|
+
cleanupDocumentReadyListener = () => {
|
|
104
|
+
childDocument.removeEventListener(
|
|
105
|
+
"readystatechange",
|
|
106
|
+
onReadyStateChange
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
childDocument.addEventListener("readystatechange", onReadyStateChange);
|
|
110
|
+
};
|
|
111
|
+
timeoutId = setTimeout(() => {
|
|
112
|
+
settle(
|
|
113
|
+
CommandResultFailure(
|
|
114
|
+
"E_SPATIAL_REQUEST_TIMEOUT",
|
|
115
|
+
`${command} request timed out`
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
}, DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS);
|
|
119
|
+
SpatialWebEvent.addEventReceiver(
|
|
120
|
+
createdId,
|
|
121
|
+
(result) => {
|
|
122
|
+
settleWhenDocumentComplete(result.spatialId);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
windowProxy = this.openWindow(
|
|
126
|
+
command,
|
|
127
|
+
buildSpatialRequestQuery(createdId)
|
|
128
|
+
).windowProxy;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const { code, message } = this.parseJSBError(error);
|
|
131
|
+
settle(CommandResultFailure(code, message));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
openWindow(command, query, target, features) {
|
|
136
|
+
const url = query ? `webspatial://${command}?${query}` : `webspatial://${command}`;
|
|
137
|
+
const windowProxy = window.open(url, target, features);
|
|
138
|
+
return { spatialId: "", windowProxy };
|
|
139
|
+
}
|
|
140
|
+
parseBridgeResponse(ans) {
|
|
141
|
+
try {
|
|
142
|
+
const result = JSON.parse(ans);
|
|
143
|
+
return this.toCommandResult(result);
|
|
144
|
+
} catch {
|
|
145
|
+
return CommandResultFailure(
|
|
146
|
+
DEFAULT_JSB_ERROR_CODE,
|
|
147
|
+
"Invalid Pico JSB response payload"
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
toCommandResult(result) {
|
|
152
|
+
if (result.success) {
|
|
153
|
+
return CommandResultSuccess(result.data);
|
|
154
|
+
}
|
|
155
|
+
const { code, message } = this.parseJSBError(result.data);
|
|
156
|
+
return CommandResultFailure(code, message);
|
|
157
|
+
}
|
|
158
|
+
parseJSBError(error) {
|
|
159
|
+
return {
|
|
160
|
+
code: error?.code ?? DEFAULT_JSB_ERROR_CODE,
|
|
161
|
+
message: error?.message ?? (typeof error === "string" ? error : DEFAULT_JSB_ERROR_MESSAGE)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
PicoOSPlatform
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=PicoOSPlatform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/platform-adapter/pico-os/PicoOSPlatform.ts"],"sourcesContent":["import {\n PlatformAbility,\n CommandResult,\n WebSpatialProtocolResult,\n} from '../interface'\nimport {\n CommandResultFailure,\n CommandResultSuccess,\n} from '../CommandResultUtils'\nimport { buildSpatialSceneQuery } from '../spatialSceneQuery'\nimport { SpatialWebEvent } from '../../SpatialWebEvent'\nimport type { SpatialSceneCreationOptionsInternal } from '../../types/internal'\nimport type { AttachmentEntityOptions } from '../../types/types'\nimport {\n buildSpatialRequestQuery,\n createSpatialRequestId,\n DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS,\n} from '../spatialRequestMetadata'\n\ninterface JSBResponse {\n success: boolean\n data: any\n}\ntype JSBError = {\n code?: string\n message: string\n}\n\nlet requestId = 0\n\nconst MAX_ID = 100000\nconst DEFAULT_JSB_ERROR_CODE = 'E_PICO_JSB'\nconst DEFAULT_JSB_ERROR_MESSAGE = 'Pico JSB execution failed'\n\nfunction nextRequestId() {\n requestId = (requestId + 1) % MAX_ID\n return `rId_${requestId}`\n}\n\n// Only supports Pico OS 6\nexport class PicoOSPlatform implements PlatformAbility {\n async callJSB(cmd: string, msg: string): Promise<CommandResult> {\n // swan JS Bridge interface only support sync invoking\n // in order to implement promise API, register every request by requestId and remove when resolve/reject.\n return new Promise(resolve => {\n try {\n const rId = nextRequestId()\n\n SpatialWebEvent.addEventReceiver(rId, (result: JSBResponse) => {\n SpatialWebEvent.removeEventReceiver(rId)\n resolve(this.toCommandResult(result))\n })\n\n const ans = window.webspatialBridge.postMessage(rId, cmd, msg)\n if (ans !== '') {\n SpatialWebEvent.removeEventReceiver(rId)\n // sync call\n resolve(this.parseBridgeResponse(ans))\n }\n } catch (error: unknown) {\n console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`)\n const { code, message } = this.parseJSBError(error)\n resolve(CommandResultFailure(code, message))\n }\n })\n }\n\n openSpatialSceneSync(\n url: string,\n config: SpatialSceneCreationOptionsInternal | undefined,\n target?: string,\n features?: string,\n ): WebSpatialProtocolResult {\n const query = buildSpatialSceneQuery(url, config)\n const { spatialId: id = '', windowProxy } = this.openWindow(\n 'createSpatialScene',\n query,\n target,\n features,\n )\n\n return CommandResultSuccess({ windowProxy, id })\n }\n\n createNativeSpatialDiv(): Promise<WebSpatialProtocolResult> {\n return this.waitForRidProtocolAsync('createSpatialized2DElement')\n }\n\n createNativeAttachment(\n _options?: AttachmentEntityOptions,\n ): Promise<WebSpatialProtocolResult> {\n return this.waitForRidProtocolAsync('createAttachment')\n }\n\n /**\n * Async path for createNativeSpatialDiv / createNativeAttachment: open webspatial URL\n * with rid= correlation (Pico OS 6).\n */\n private waitForRidProtocolAsync(\n command: string,\n ): Promise<WebSpatialProtocolResult> {\n return new Promise(resolve => {\n const createdId = createSpatialRequestId()\n let settled = false\n let timeoutId: ReturnType<typeof setTimeout> | undefined\n let cleanupDocumentReadyListener: (() => void) | undefined\n\n // Native creation may respond synchronously, asynchronously, or never.\n // Funnel every path through one settle() helper so receiver cleanup is\n // exactly-once.\n const settle = (result: WebSpatialProtocolResult) => {\n if (settled) return\n settled = true\n if (timeoutId !== undefined) {\n clearTimeout(timeoutId)\n }\n cleanupDocumentReadyListener?.()\n cleanupDocumentReadyListener = undefined\n SpatialWebEvent.removeEventReceiver(createdId)\n resolve(result)\n }\n\n try {\n let windowProxy: WindowProxy | null = null\n const settleWhenDocumentComplete = (spatialId: string) => {\n const successResult = CommandResultSuccess({\n windowProxy: windowProxy,\n id: spatialId,\n })\n const childDocument = windowProxy?.document\n\n if (!childDocument) {\n settle(\n CommandResultFailure(\n 'E_SPATIAL_DOCUMENT_UNAVAILABLE',\n `${command} document is unavailable`,\n ),\n )\n return\n }\n\n if (childDocument.readyState === 'complete') {\n settle(successResult)\n return\n }\n\n const onReadyStateChange = () => {\n if (childDocument.readyState !== 'complete') return\n settle(successResult)\n }\n\n cleanupDocumentReadyListener = () => {\n childDocument.removeEventListener(\n 'readystatechange',\n onReadyStateChange,\n )\n }\n childDocument.addEventListener('readystatechange', onReadyStateChange)\n }\n\n timeoutId = setTimeout(() => {\n settle(\n CommandResultFailure(\n 'E_SPATIAL_REQUEST_TIMEOUT',\n `${command} request timed out`,\n ),\n )\n }, DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS)\n\n SpatialWebEvent.addEventReceiver(\n createdId,\n (result: { spatialId: string }) => {\n settleWhenDocumentComplete(result.spatialId)\n },\n )\n windowProxy = this.openWindow(\n command,\n buildSpatialRequestQuery(createdId),\n ).windowProxy\n } catch (error: unknown) {\n const { code, message } = this.parseJSBError(error)\n settle(CommandResultFailure(code, message))\n }\n })\n }\n\n private openWindow(\n command: string,\n query?: string,\n target?: string,\n features?: string,\n ): { spatialId: string; windowProxy: WindowProxy | null } {\n const url = query\n ? `webspatial://${command}?${query}`\n : `webspatial://${command}`\n const windowProxy = window.open(url, target, features)\n return { spatialId: '', windowProxy }\n }\n\n private parseBridgeResponse(ans: string): CommandResult {\n try {\n const result = JSON.parse(ans) as JSBResponse\n return this.toCommandResult(result)\n } catch {\n return CommandResultFailure(\n DEFAULT_JSB_ERROR_CODE,\n 'Invalid Pico JSB response payload',\n )\n }\n }\n\n private toCommandResult(result: JSBResponse): CommandResult {\n if (result.success) {\n return CommandResultSuccess(result.data)\n }\n const { code, message } = this.parseJSBError(result.data)\n return CommandResultFailure(code, message)\n }\n\n private parseJSBError(error: unknown): { code: string; message: string } {\n return {\n code: (error as JSBError)?.code ?? DEFAULT_JSB_ERROR_CODE,\n message:\n (error as JSBError)?.message ??\n (typeof error === 'string' ? error : DEFAULT_JSB_ERROR_MESSAGE),\n }\n }\n}\n"],"mappings":"AAKA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,uBAAuB;AAGhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAWP,IAAI,YAAY;AAEhB,MAAM,SAAS;AACf,MAAM,yBAAyB;AAC/B,MAAM,4BAA4B;AAElC,SAAS,gBAAgB;AACvB,eAAa,YAAY,KAAK;AAC9B,SAAO,OAAO,SAAS;AACzB;AAGO,MAAM,eAA0C;AAAA,EACrD,MAAM,QAAQ,KAAa,KAAqC;AAG9D,WAAO,IAAI,QAAQ,aAAW;AAC5B,UAAI;AACF,cAAM,MAAM,cAAc;AAE1B,wBAAgB,iBAAiB,KAAK,CAAC,WAAwB;AAC7D,0BAAgB,oBAAoB,GAAG;AACvC,kBAAQ,KAAK,gBAAgB,MAAM,CAAC;AAAA,QACtC,CAAC;AAED,cAAM,MAAM,OAAO,iBAAiB,YAAY,KAAK,KAAK,GAAG;AAC7D,YAAI,QAAQ,IAAI;AACd,0BAAgB,oBAAoB,GAAG;AAEvC,kBAAQ,KAAK,oBAAoB,GAAG,CAAC;AAAA,QACvC;AAAA,MACF,SAAS,OAAgB;AACvB,gBAAQ,MAAM,qBAAqB,GAAG,UAAU,GAAG,WAAW,KAAK,EAAE;AACrE,cAAM,EAAE,MAAM,QAAQ,IAAI,KAAK,cAAc,KAAK;AAClD,gBAAQ,qBAAqB,MAAM,OAAO,CAAC;AAAA,MAC7C;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,qBACE,KACA,QACA,QACA,UAC0B;AAC1B,UAAM,QAAQ,uBAAuB,KAAK,MAAM;AAChD,UA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0,0 +1,66 @@
|
|
|
1
|
+
import { aY as PlatformAbility, aK as CommandResult, aQ as SpatialSceneCreationOptionsInternal, aZ as WebSpatialProtocolResult, h as AttachmentEntityOptions } from '../../spatializedElementMotion-_0XWPQCE.js';
|
|
2
|
+
import '../../types/motion/spatializedVisual.js';
|
|
3
|
+
import '../../types/motion/spatializedPlayback.js';
|
|
4
|
+
import '../../types/global.js';
|
|
5
|
+
import '../../physicalMetrics-W5uZ5xKb.js';
|
|
6
|
+
import '../../SpatialObject.js';
|
|
7
|
+
import '../../reality/component/SpatialComponent.js';
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
__handleJSBMessage: (message: string) => any;
|
|
12
|
+
SpatialId?: string;
|
|
13
|
+
}
|
|
14
|
+
interface HTMLIFrameElement {
|
|
15
|
+
spatialId?: string;
|
|
16
|
+
webSpatialId?: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
declare class PuppeteerPlatform implements PlatformAbility {
|
|
20
|
+
private iframeRegistry;
|
|
21
|
+
constructor();
|
|
22
|
+
callJSB(cmd: string, msg: string): Promise<CommandResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Synchronously create Spatialized2DElement to Puppeteer Runner
|
|
25
|
+
*/
|
|
26
|
+
private createSpatializedElementSync;
|
|
27
|
+
openSpatialSceneSync(url: string, config: SpatialSceneCreationOptionsInternal | undefined, target?: string, features?: string): WebSpatialProtocolResult;
|
|
28
|
+
createNativeSpatialDiv(): Promise<WebSpatialProtocolResult>;
|
|
29
|
+
createNativeAttachment(_options?: AttachmentEntityOptions): Promise<WebSpatialProtocolResult>;
|
|
30
|
+
private runProtocolAsync;
|
|
31
|
+
private runProtocolSync;
|
|
32
|
+
/**
|
|
33
|
+
* Synchronously create iframe-based window
|
|
34
|
+
*/
|
|
35
|
+
private createIframeWindow;
|
|
36
|
+
/**
|
|
37
|
+
* create enhanced windowProxy object
|
|
38
|
+
*/
|
|
39
|
+
private createEnhancedWindowProxy;
|
|
40
|
+
/**
|
|
41
|
+
* initialize iframe content
|
|
42
|
+
*/
|
|
43
|
+
private initializeIframeContent;
|
|
44
|
+
/**
|
|
45
|
+
* parse features string to object
|
|
46
|
+
*/
|
|
47
|
+
private parseFeatures;
|
|
48
|
+
/**
|
|
49
|
+
* send message to iframe with specified spatialId
|
|
50
|
+
*/
|
|
51
|
+
sendMessageToIframe(spatialId: string, message: any): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* get all active iframes
|
|
54
|
+
*/
|
|
55
|
+
getAllActiveIframes(): Array<{
|
|
56
|
+
spatialId: string;
|
|
57
|
+
iframe: HTMLIFrameElement;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* dispose all active iframes
|
|
61
|
+
*/
|
|
62
|
+
dispose(): void;
|
|
63
|
+
private generateUUID;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { PuppeteerPlatform };
|