@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.
Files changed (296) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +10 -0
  3. package/dist/JSBCommand.d.ts +398 -0
  4. package/dist/JSBCommand.js +668 -0
  5. package/dist/JSBCommand.js.map +1 -0
  6. package/dist/Spatial.d.ts +63 -0
  7. package/dist/Spatial.js +60 -0
  8. package/dist/Spatial.js.map +1 -0
  9. package/dist/SpatialObject.d.ts +19 -0
  10. package/dist/SpatialObject.js +44 -0
  11. package/dist/SpatialObject.js.map +1 -0
  12. package/dist/SpatialScene.d.ts +51 -0
  13. package/dist/SpatialScene.js +74 -0
  14. package/dist/SpatialScene.js.map +1 -0
  15. package/dist/SpatialSession.d.ts +143 -0
  16. package/dist/SpatialSession.js +173 -0
  17. package/dist/SpatialSession.js.map +1 -0
  18. package/dist/SpatialWebEvent.d.ts +8 -0
  19. package/dist/SpatialWebEvent.js +18 -0
  20. package/dist/SpatialWebEvent.js.map +1 -0
  21. package/dist/SpatialWebEventCreator.d.ts +11 -0
  22. package/dist/SpatialWebEventCreator.js +11 -0
  23. package/dist/SpatialWebEventCreator.js.map +1 -0
  24. package/dist/Spatialized2DElement.d.ts +42 -0
  25. package/dist/Spatialized2DElement.js +47 -0
  26. package/dist/Spatialized2DElement.js.map +1 -0
  27. package/dist/SpatializedDynamic3DElement.d.ts +7 -0
  28. package/dist/SpatializedDynamic3DElement.js +43 -0
  29. package/dist/SpatializedDynamic3DElement.js.map +1 -0
  30. package/dist/SpatializedElement.d.ts +7 -0
  31. package/dist/SpatializedElement.js +206 -0
  32. package/dist/SpatializedElement.js.map +1 -0
  33. package/dist/SpatializedElementCreator.d.ts +15 -0
  34. package/dist/SpatializedElementCreator.js +47 -0
  35. package/dist/SpatializedElementCreator.js.map +1 -0
  36. package/dist/SpatializedStatic3DElement.d.ts +195 -0
  37. package/dist/SpatializedStatic3DElement.js +327 -0
  38. package/dist/SpatializedStatic3DElement.js.map +1 -0
  39. package/dist/WebMsgCommand.d.ts +7 -0
  40. package/dist/WebMsgCommand.js +23 -0
  41. package/dist/WebMsgCommand.js.map +1 -0
  42. package/dist/index.d.ts +35 -1251
  43. package/dist/index.js +21 -3650
  44. package/dist/index.js.map +1 -1
  45. package/dist/install-polyfills.d.ts +2 -0
  46. package/dist/install-polyfills.js +13 -0
  47. package/dist/install-polyfills.js.map +1 -0
  48. package/dist/isSSREnv.d.ts +3 -0
  49. package/dist/isSSREnv.js +6 -0
  50. package/dist/isSSREnv.js.map +1 -0
  51. package/dist/motion/AnimationObject.d.ts +7 -0
  52. package/dist/motion/AnimationObject.js +140 -0
  53. package/dist/motion/AnimationObject.js.map +1 -0
  54. package/dist/motion/compute/index.d.ts +10 -0
  55. package/dist/motion/compute/index.js +19 -0
  56. package/dist/motion/compute/index.js.map +1 -0
  57. package/dist/motion/compute/motionPropertyValues.d.ts +19 -0
  58. package/dist/motion/compute/motionPropertyValues.js +50 -0
  59. package/dist/motion/compute/motionPropertyValues.js.map +1 -0
  60. package/dist/motion/compute/normalize.d.ts +31 -0
  61. package/dist/motion/compute/normalize.js +201 -0
  62. package/dist/motion/compute/normalize.js.map +1 -0
  63. package/dist/motion/compute/validate.d.ts +22 -0
  64. package/dist/motion/compute/validate.js +103 -0
  65. package/dist/motion/compute/validate.js.map +1 -0
  66. package/dist/motion/index.d.ts +8 -0
  67. package/dist/motion/index.js +6 -0
  68. package/dist/motion/index.js.map +1 -0
  69. package/dist/motion/native/serializeMotionTimeline.d.ts +12 -0
  70. package/dist/motion/native/serializeMotionTimeline.js +21 -0
  71. package/dist/motion/native/serializeMotionTimeline.js.map +1 -0
  72. package/dist/physicalMetrics-W5uZ5xKb.d.ts +48 -0
  73. package/dist/physicalMetrics.d.ts +1 -0
  74. package/dist/physicalMetrics.js +58 -0
  75. package/dist/physicalMetrics.js.map +1 -0
  76. package/dist/platform-adapter/CommandResultUtils.d.ts +12 -0
  77. package/dist/platform-adapter/CommandResultUtils.js +21 -0
  78. package/dist/platform-adapter/CommandResultUtils.js.map +1 -0
  79. package/dist/platform-adapter/createPlatformSync.d.ts +16 -0
  80. package/dist/platform-adapter/createPlatformSync.js +30 -0
  81. package/dist/platform-adapter/createPlatformSync.js.map +1 -0
  82. package/dist/platform-adapter/index.d.ts +12 -0
  83. package/dist/platform-adapter/index.js +10 -0
  84. package/dist/platform-adapter/index.js.map +1 -0
  85. package/dist/platform-adapter/interface.d.ts +7 -0
  86. package/dist/platform-adapter/interface.js +1 -0
  87. package/dist/platform-adapter/interface.js.map +1 -0
  88. package/dist/platform-adapter/pico-os/PicoOSPlatform.d.ts +25 -0
  89. package/dist/platform-adapter/pico-os/PicoOSPlatform.js +168 -0
  90. package/dist/platform-adapter/pico-os/PicoOSPlatform.js.map +1 -0
  91. package/dist/platform-adapter/puppeteer/PuppeteerPlatform.d.ts +66 -0
  92. package/dist/platform-adapter/puppeteer/PuppeteerPlatform.js +372 -0
  93. package/dist/platform-adapter/puppeteer/PuppeteerPlatform.js.map +1 -0
  94. package/dist/platform-adapter/spatialRequestMetadata.d.ts +6 -0
  95. package/dist/platform-adapter/spatialRequestMetadata.js +39 -0
  96. package/dist/platform-adapter/spatialRequestMetadata.js.map +1 -0
  97. package/dist/platform-adapter/spatialSceneQuery.d.ts +12 -0
  98. package/dist/platform-adapter/spatialSceneQuery.js +12 -0
  99. package/dist/platform-adapter/spatialSceneQuery.js.map +1 -0
  100. package/dist/platform-adapter/vision-os/VisionOSPlatform.d.ts +19 -0
  101. package/dist/platform-adapter/vision-os/VisionOSPlatform.js +77 -0
  102. package/dist/platform-adapter/vision-os/VisionOSPlatform.js.map +1 -0
  103. package/dist/platform-runtime.d.ts +12 -0
  104. package/dist/platform-runtime.js +14 -0
  105. package/dist/platform-runtime.js.map +1 -0
  106. package/dist/reality/Attachment.d.ts +19 -0
  107. package/dist/reality/Attachment.js +39 -0
  108. package/dist/reality/Attachment.js.map +1 -0
  109. package/dist/reality/component/ModelComponent.d.ts +14 -0
  110. package/dist/reality/component/ModelComponent.js +11 -0
  111. package/dist/reality/component/ModelComponent.js.map +1 -0
  112. package/dist/reality/component/SpatialComponent.d.ts +8 -0
  113. package/dist/reality/component/SpatialComponent.js +19 -0
  114. package/dist/reality/component/SpatialComponent.js.map +1 -0
  115. package/dist/reality/component/index.d.ts +8 -0
  116. package/dist/reality/component/index.js +3 -0
  117. package/dist/reality/component/index.js.map +1 -0
  118. package/dist/reality/entity/SpatialEntity.d.ts +7 -0
  119. package/dist/reality/entity/SpatialEntity.js +291 -0
  120. package/dist/reality/entity/SpatialEntity.js.map +1 -0
  121. package/dist/reality/entity/SpatialModelEntity.d.ts +17 -0
  122. package/dist/reality/entity/SpatialModelEntity.js +17 -0
  123. package/dist/reality/entity/SpatialModelEntity.js.map +1 -0
  124. package/dist/reality/entity/index.d.ts +8 -0
  125. package/dist/reality/entity/index.js +3 -0
  126. package/dist/reality/entity/index.js.map +1 -0
  127. package/dist/reality/geometry/SpatialBoxGeometry.d.ts +16 -0
  128. package/dist/reality/geometry/SpatialBoxGeometry.js +13 -0
  129. package/dist/reality/geometry/SpatialBoxGeometry.js.map +1 -0
  130. package/dist/reality/geometry/SpatialConeGeometry.d.ts +16 -0
  131. package/dist/reality/geometry/SpatialConeGeometry.js +13 -0
  132. package/dist/reality/geometry/SpatialConeGeometry.js.map +1 -0
  133. package/dist/reality/geometry/SpatialCylinderGeometry.d.ts +16 -0
  134. package/dist/reality/geometry/SpatialCylinderGeometry.js +13 -0
  135. package/dist/reality/geometry/SpatialCylinderGeometry.js.map +1 -0
  136. package/dist/reality/geometry/SpatialGeometry.d.ts +7 -0
  137. package/dist/reality/geometry/SpatialGeometry.js +13 -0
  138. package/dist/reality/geometry/SpatialGeometry.js.map +1 -0
  139. package/dist/reality/geometry/SpatialPlaneGeometry.d.ts +16 -0
  140. package/dist/reality/geometry/SpatialPlaneGeometry.js +13 -0
  141. package/dist/reality/geometry/SpatialPlaneGeometry.js.map +1 -0
  142. package/dist/reality/geometry/SpatialSphereGeometry.d.ts +16 -0
  143. package/dist/reality/geometry/SpatialSphereGeometry.js +13 -0
  144. package/dist/reality/geometry/SpatialSphereGeometry.js.map +1 -0
  145. package/dist/reality/geometry/index.d.ts +12 -0
  146. package/dist/reality/geometry/index.js +7 -0
  147. package/dist/reality/geometry/index.js.map +1 -0
  148. package/dist/reality/index.d.ts +18 -0
  149. package/dist/reality/index.js +7 -0
  150. package/dist/reality/index.js.map +1 -0
  151. package/dist/reality/material/SpatialMaterial.d.ts +7 -0
  152. package/dist/reality/material/SpatialMaterial.js +13 -0
  153. package/dist/reality/material/SpatialMaterial.js.map +1 -0
  154. package/dist/reality/material/SpatialUnlitMaterial.d.ts +16 -0
  155. package/dist/reality/material/SpatialUnlitMaterial.js +16 -0
  156. package/dist/reality/material/SpatialUnlitMaterial.js.map +1 -0
  157. package/dist/reality/material/index.d.ts +8 -0
  158. package/dist/reality/material/index.js +3 -0
  159. package/dist/reality/material/index.js.map +1 -0
  160. package/dist/reality/realityCreator.d.ts +22 -0
  161. package/dist/reality/realityCreator.js +89 -0
  162. package/dist/reality/realityCreator.js.map +1 -0
  163. package/dist/reality/resource/SpatialModelAsset.d.ts +15 -0
  164. package/dist/reality/resource/SpatialModelAsset.js +12 -0
  165. package/dist/reality/resource/SpatialModelAsset.js.map +1 -0
  166. package/dist/reality/resource/SpatialTextureResource.d.ts +16 -0
  167. package/dist/reality/resource/SpatialTextureResource.js +16 -0
  168. package/dist/reality/resource/SpatialTextureResource.js.map +1 -0
  169. package/dist/reality/resource/index.d.ts +9 -0
  170. package/dist/reality/resource/index.js +3 -0
  171. package/dist/reality/resource/index.js.map +1 -0
  172. package/dist/runtime/WebSpatialRuntimeError.d.ts +10 -0
  173. package/dist/runtime/WebSpatialRuntimeError.js +14 -0
  174. package/dist/runtime/WebSpatialRuntimeError.js.map +1 -0
  175. package/dist/runtime/capability-data.d.ts +12 -0
  176. package/dist/runtime/capability-data.js +134 -0
  177. package/dist/runtime/capability-data.js.map +1 -0
  178. package/dist/runtime/index.d.ts +8 -0
  179. package/dist/runtime/index.js +27 -0
  180. package/dist/runtime/index.js.map +1 -0
  181. package/dist/runtime/jsbAdapterPlatform.d.ts +9 -0
  182. package/dist/runtime/jsbAdapterPlatform.js +38 -0
  183. package/dist/runtime/jsbAdapterPlatform.js.map +1 -0
  184. package/dist/runtime/keys.d.ts +34 -0
  185. package/dist/runtime/keys.js +122 -0
  186. package/dist/runtime/keys.js.map +1 -0
  187. package/dist/runtime/semver.d.ts +8 -0
  188. package/dist/runtime/semver.js +32 -0
  189. package/dist/runtime/semver.js.map +1 -0
  190. package/dist/runtime/supports.d.ts +22 -0
  191. package/dist/runtime/supports.js +78 -0
  192. package/dist/runtime/supports.js.map +1 -0
  193. package/dist/runtime/types.d.ts +12 -0
  194. package/dist/runtime/types.js +1 -0
  195. package/dist/runtime/types.js.map +1 -0
  196. package/dist/runtime/userAgent.d.ts +20 -0
  197. package/dist/runtime/userAgent.js +41 -0
  198. package/dist/runtime/userAgent.js.map +1 -0
  199. package/dist/scene-polyfill.d.ts +18 -0
  200. package/dist/scene-polyfill.js +480 -0
  201. package/dist/scene-polyfill.js.map +1 -0
  202. package/dist/spatial-host.d.ts +13 -0
  203. package/dist/spatial-host.js +18 -0
  204. package/dist/spatial-host.js.map +1 -0
  205. package/dist/spatial-window-polyfill.d.ts +3 -0
  206. package/dist/spatial-window-polyfill.js +155 -0
  207. package/dist/spatial-window-polyfill.js.map +1 -0
  208. package/dist/spatializedElementMotion-_0XWPQCE.d.ts +1009 -0
  209. package/dist/types/animation.d.ts +7 -0
  210. package/dist/types/animation.js +1 -0
  211. package/dist/types/animation.js.map +1 -0
  212. package/dist/types/global.d.ts +38 -0
  213. package/dist/types/global.js +1 -0
  214. package/dist/types/global.js.map +1 -0
  215. package/dist/types/internal.d.ts +7 -0
  216. package/dist/types/internal.js +12 -0
  217. package/dist/types/internal.js.map +1 -0
  218. package/dist/types/motion/index.d.ts +7 -0
  219. package/dist/types/motion/index.js +3 -0
  220. package/dist/types/motion/index.js.map +1 -0
  221. package/dist/types/motion/spatializedElementMotion.d.ts +7 -0
  222. package/dist/types/motion/spatializedElementMotion.js +1 -0
  223. package/dist/types/motion/spatializedElementMotion.js.map +1 -0
  224. package/dist/types/motion/spatializedMotion.d.ts +7 -0
  225. package/dist/types/motion/spatializedMotion.js +16 -0
  226. package/dist/types/motion/spatializedMotion.js.map +1 -0
  227. package/dist/types/motion/spatializedPlayback.d.ts +11 -0
  228. package/dist/types/motion/spatializedPlayback.js +1 -0
  229. package/dist/types/motion/spatializedPlayback.js.map +1 -0
  230. package/dist/types/motion/spatializedVisual.d.ts +35 -0
  231. package/dist/types/motion/spatializedVisual.js +1 -0
  232. package/dist/types/motion/spatializedVisual.js.map +1 -0
  233. package/dist/types/types.d.ts +7 -0
  234. package/dist/types/types.js +117 -0
  235. package/dist/types/types.js.map +1 -0
  236. package/dist/utils.d.ts +44 -0
  237. package/dist/utils.js +86 -0
  238. package/dist/utils.js.map +1 -0
  239. package/package.json +20 -4
  240. package/src/JSBCommand.ts +132 -5
  241. package/src/SpatialObject.ts +10 -0
  242. package/src/Spatialized2DElement.ts +5 -0
  243. package/src/SpatializedDynamic3DElement.ts +5 -0
  244. package/src/SpatializedElement.ts +29 -0
  245. package/src/SpatializedStatic3DElement.ts +42 -3
  246. package/src/WebMsgCommand.ts +40 -0
  247. package/src/coverage-boost.test.ts +239 -216
  248. package/src/index.ts +25 -11
  249. package/src/install-polyfills.ts +38 -0
  250. package/src/jsbcommand.coverage.test.ts +23 -0
  251. package/src/motion/AnimationObject.test.ts +421 -0
  252. package/src/motion/AnimationObject.ts +208 -0
  253. package/src/motion/compute/index.ts +10 -0
  254. package/src/motion/compute/motionPropertyValues.test.ts +55 -0
  255. package/src/motion/compute/motionPropertyValues.ts +70 -0
  256. package/src/motion/compute/normalize.test.ts +99 -0
  257. package/src/motion/compute/normalize.ts +289 -0
  258. package/src/motion/compute/validate.test.ts +229 -0
  259. package/src/motion/compute/validate.ts +156 -0
  260. package/src/motion/index.ts +2 -0
  261. package/src/motion/native/serializeMotionTimeline.test.ts +61 -0
  262. package/src/motion/native/serializeMotionTimeline.ts +27 -0
  263. package/src/platform-adapter/createPlatformSync.ts +5 -3
  264. package/src/platform-adapter/pico-os/PicoOSPlatform.ts +76 -11
  265. package/src/platform-adapter/spatialRequestMetadata.test.ts +175 -0
  266. package/src/platform-adapter/spatialRequestMetadata.ts +48 -0
  267. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +6 -1
  268. package/src/reality/entity/SpatialEntity.ts +127 -0
  269. package/src/runtime/capability-data.ts +104 -4
  270. package/src/runtime/index.ts +0 -11
  271. package/src/runtime/keys.ts +12 -1
  272. package/src/runtime/supports.test.ts +143 -4
  273. package/src/runtime/supports.ts +3 -1
  274. package/src/runtime/useAnimation.capability.test.ts +275 -0
  275. package/src/scene-polyfill.manifest.test.ts +306 -5
  276. package/src/scene-polyfill.request-metadata.test.ts +39 -0
  277. package/src/scene-polyfill.test.ts +33 -94
  278. package/src/scene-polyfill.ts +117 -87
  279. package/src/spatial-window-polyfill.ts +18 -2
  280. package/src/transform-roundtrip.test.ts +90 -0
  281. package/src/types/animation.ts +224 -0
  282. package/src/types/global.ts +1 -8
  283. package/src/types/motion/index.ts +10 -0
  284. package/src/types/motion/spatializedElementMotion.ts +49 -0
  285. package/src/types/motion/spatializedMotion.ts +147 -0
  286. package/src/types/motion/spatializedPlayback.ts +17 -0
  287. package/src/types/motion/spatializedVisual.ts +24 -0
  288. package/src/types/types.ts +3 -0
  289. package/src/utils.ts +54 -0
  290. package/tsup.config.ts +61 -36
  291. package/vitest.config.ts +5 -1
  292. package/dist/iife/index.d.ts +0 -1251
  293. package/dist/iife/index.global.js +0 -75
  294. package/dist/iife/index.global.js.map +0 -1
  295. package/src/platform-adapter/ssr/SSRPlatform.ts +0 -52
  296. /package/src/{ssr-polyfill.ts → isSSREnv.ts} +0 -0
@@ -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,yBAAy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,MAAM,OAAO,CAAC;AAAA,MAC5C;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,WACN,SACA,OACA,QACA,UACwD;AACxD,UAAM,MAAM,QACR,gBAAgB,OAAO,IAAI,KAAK,KAChC,gBAAgB,OAAO;AAC3B,UAAM,cAAc,OAAO,KAAK,KAAK,QAAQ,QAAQ;AACrD,WAAO,EAAE,WAAW,IAAI,YAAY;AAAA,EACtC;AAAA,EAEQ,oBAAoB,KAA4B;AACtD,QAAI;AACF,YAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,aAAO,KAAK,gBAAgB,MAAM;AAAA,IACpC,QAAQ;AACN,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,gBAAgB,QAAoC;AAC1D,QAAI,OAAO,SAAS;AAClB,aAAO,qBAAqB,OAAO,IAAI;AAAA,IACzC;AACA,UAAM,EAAE,MAAM,QAAQ,IAAI,KAAK,cAAc,OAAO,IAAI;AACxD,WAAO,qBAAqB,MAAM,OAAO;AAAA,EAC3C;AAAA,EAEQ,cAAc,OAAmD;AACvE,WAAO;AAAA,MACL,MAAO,OAAoB,QAAQ;AAAA,MACnC,SACG,OAAoB,YACpB,OAAO,UAAU,WAAW,QAAQ;AAAA,IACzC;AAAA,EACF;AACF;","names":[]}
@@ -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 };
@@ -0,0 +1,372 @@
1
+ import { buildSpatialSceneQuery } from "../spatialSceneQuery";
2
+ import {
3
+ CommandResultFailure,
4
+ CommandResultSuccess
5
+ } from "../CommandResultUtils";
6
+ class PuppeteerPlatform {
7
+ // store iframe instance
8
+ iframeRegistry = /* @__PURE__ */ new Map();
9
+ constructor() {
10
+ }
11
+ callJSB(cmd, msg) {
12
+ return new Promise((resolve) => {
13
+ try {
14
+ if (window.__handleJSBMessage) {
15
+ try {
16
+ console.log(` core-sdk Puppeteer Platform: callJSB: ${cmd}::${msg}`);
17
+ const result = window.__handleJSBMessage(`${cmd}::${msg}`);
18
+ console.log(
19
+ ` core-sdk Puppeteer Platform callJSB result: ${result}`
20
+ );
21
+ resolve(CommandResultSuccess(result));
22
+ } catch (err) {
23
+ resolve(CommandResultFailure("500", "JSB execution error"));
24
+ }
25
+ } else {
26
+ resolve(CommandResultSuccess("ok"));
27
+ }
28
+ } catch (error) {
29
+ console.error(
30
+ `PuppeteerPlatform cmd Error: ${cmd}, msg: ${msg} error: ${error}`
31
+ );
32
+ resolve(CommandResultFailure("500", "Internal error"));
33
+ }
34
+ });
35
+ }
36
+ /**
37
+ * Synchronously create Spatialized2DElement to Puppeteer Runner
38
+ */
39
+ createSpatializedElementSync(spatialId, webspatialUrl) {
40
+ try {
41
+ console.log(
42
+ `[Puppeteer Platform] Creating spatialized element sync with id: ${spatialId}, url: ${webspatialUrl}`
43
+ );
44
+ const win = window;
45
+ if (win.__handleJSBMessage) {
46
+ const createCommand = {
47
+ id: spatialId,
48
+ url: webspatialUrl
49
+ };
50
+ win.__handleJSBMessage(
51
+ `CreateSpatialized2DElement::${JSON.stringify(createCommand)}`
52
+ );
53
+ }
54
+ } catch (error) {
55
+ console.error("Error creating spatialized element sync:", error);
56
+ }
57
+ }
58
+ openSpatialSceneSync(url, config, target, features) {
59
+ const query = buildSpatialSceneQuery(url, config);
60
+ return this.runProtocolSync("createSpatialScene", query, target, features);
61
+ }
62
+ createNativeSpatialDiv() {
63
+ return this.runProtocolAsync(
64
+ "createSpatialized2DElement",
65
+ "",
66
+ void 0,
67
+ void 0
68
+ );
69
+ }
70
+ createNativeAttachment(_options) {
71
+ return this.runProtocolAsync("createAttachment", "", void 0, void 0);
72
+ }
73
+ runProtocolAsync(command, query, target, features) {
74
+ console.log(
75
+ `PuppeteerPlatform: Calling webspatial protocol: webspatial://${command}${query ? `?${query}` : ""}`
76
+ );
77
+ return new Promise((resolve) => {
78
+ try {
79
+ const webspatialUrl = `webspatial://${command}${query ? `?${query}` : ""}`;
80
+ const { spatialId, iframe, windowProxy } = this.createIframeWindow(
81
+ webspatialUrl,
82
+ target,
83
+ features
84
+ );
85
+ if (command === "createSpatialized2DElement") {
86
+ this.createSpatializedElementSync(spatialId, webspatialUrl);
87
+ }
88
+ console.log(
89
+ `[Puppeteer Platform] iframe created with spatialId: ${spatialId}`
90
+ );
91
+ this.iframeRegistry.set(spatialId, iframe);
92
+ resolve(CommandResultSuccess({ windowProxy, id: spatialId }));
93
+ } catch (error) {
94
+ console.error("Error calling webspatial protocol:", error);
95
+ resolve(
96
+ CommandResultFailure("500", "Failed to call webspatial protocol")
97
+ );
98
+ }
99
+ });
100
+ }
101
+ runProtocolSync(command, query, target, features) {
102
+ try {
103
+ const webspatialUrl = `webspatial://${command}${query ? `?${query}` : ""}`;
104
+ console.log(`Calling webspatial protocol sync: ${webspatialUrl}`);
105
+ const { spatialId, iframe, windowProxy } = this.createIframeWindow(
106
+ webspatialUrl,
107
+ target,
108
+ features
109
+ );
110
+ if (command === "createSpatialized2DElement") {
111
+ this.createSpatializedElementSync(spatialId, webspatialUrl);
112
+ }
113
+ this.iframeRegistry.set(spatialId, iframe);
114
+ return CommandResultSuccess({ windowProxy, id: spatialId });
115
+ } catch (error) {
116
+ console.error("Error calling webspatial protocol sync:", error);
117
+ return CommandResultFailure(
118
+ "500",
119
+ "Failed to call webspatial protocol sync"
120
+ );
121
+ }
122
+ }
123
+ /**
124
+ * Synchronously create iframe-based window
125
+ */
126
+ createIframeWindow(url, target, features) {
127
+ const iframe = document.createElement("iframe");
128
+ iframe.style.border = "none";
129
+ iframe.style.display = "none";
130
+ iframe.style.width = "100%";
131
+ iframe.style.height = "100%";
132
+ const spatialId = this.generateUUID();
133
+ iframe.spatialId = spatialId;
134
+ iframe.id = `spatial-iframe-${spatialId}`;
135
+ const featuresObj = this.parseFeatures(features || "");
136
+ if (featuresObj.width) {
137
+ iframe.style.width = featuresObj.width;
138
+ }
139
+ if (featuresObj.height) {
140
+ iframe.style.height = featuresObj.height;
141
+ }
142
+ if (featuresObj.left) {
143
+ iframe.style.left = featuresObj.left;
144
+ iframe.style.position = "absolute";
145
+ }
146
+ if (featuresObj.top) {
147
+ iframe.style.top = featuresObj.top;
148
+ iframe.style.position = "absolute";
149
+ }
150
+ document.body.appendChild(iframe);
151
+ const windowProxy = this.createEnhancedWindowProxy(iframe, url, spatialId);
152
+ iframe.src = "about:blank";
153
+ console.log(
154
+ `PuppeteerPlatform created iframe window with spatialId: ${spatialId}, URL: ${url}`
155
+ );
156
+ this.initializeIframeContent(iframe, url, spatialId);
157
+ return { spatialId, iframe, windowProxy };
158
+ }
159
+ /**
160
+ * create enhanced windowProxy object
161
+ */
162
+ createEnhancedWindowProxy(iframe, url, spatialId) {
163
+ return {
164
+ // basic properties
165
+ location: {
166
+ href: url,
167
+ toString: () => url,
168
+ reload: () => {
169
+ if (iframe.contentWindow) {
170
+ iframe.contentWindow.location.reload();
171
+ }
172
+ }
173
+ },
174
+ navigator: {
175
+ userAgent: `Mozilla/5.0 (WebKit) SpatialId/${spatialId}`
176
+ },
177
+ // methods
178
+ close: () => {
179
+ console.log(`Closing iframe with spatialId: ${spatialId}`);
180
+ iframe.remove();
181
+ this.iframeRegistry.delete(spatialId);
182
+ },
183
+ // document access
184
+ document: iframe.contentDocument || {},
185
+ contentWindow: iframe.contentWindow || {},
186
+ // add message communication method
187
+ postMessage: (message, targetOrigin) => {
188
+ if (iframe.contentWindow) {
189
+ iframe.contentWindow.postMessage(message, targetOrigin || "*");
190
+ }
191
+ },
192
+ // add event listener method
193
+ addEventListener: (type, listener) => {
194
+ if (iframe.contentWindow) {
195
+ iframe.contentWindow.addEventListener(type, listener);
196
+ }
197
+ },
198
+ removeEventListener: (type, listener) => {
199
+ if (iframe.contentWindow) {
200
+ iframe.contentWindow.removeEventListener(type, listener);
201
+ }
202
+ },
203
+ // execute JavaScript
204
+ executeScript: (code) => {
205
+ if (iframe.contentWindow) {
206
+ try {
207
+ const win = iframe.contentWindow;
208
+ return win.eval(code);
209
+ } catch (error) {
210
+ console.error(
211
+ `Error executing script in iframe ${spatialId}:`,
212
+ error
213
+ );
214
+ return null;
215
+ }
216
+ }
217
+ return null;
218
+ },
219
+ // get iframe reference
220
+ getIframe: () => iframe,
221
+ // get spatialId
222
+ getSpatialId: () => spatialId
223
+ };
224
+ }
225
+ /**
226
+ * initialize iframe content
227
+ */
228
+ initializeIframeContent(iframe, url, spatialId) {
229
+ try {
230
+ iframe.onload = () => {
231
+ try {
232
+ const iframeContent = `
233
+ // inject communication script
234
+ window.webSpatialId = '${spatialId}';
235
+ window.SpatialId = '${spatialId}';
236
+
237
+ // override window.open to support webspatial protocol
238
+ const originalOpen = window.open;
239
+ window.open = function(url, target, features) {
240
+ if (url && url.startsWith('webspatial://')) {
241
+ // handle webspatial protocol through windowProxy
242
+ const windowProxy = new Proxy({}, {
243
+ get: function(target, prop) {
244
+ if (prop === 'toString') {
245
+ return function() { return url; };
246
+ }
247
+ return undefined;
248
+ }
249
+ });
250
+ return windowProxy;
251
+ }
252
+ return originalOpen.call(window, url, target, features);
253
+ };
254
+
255
+ // set navigator.userAgent to identify webspatial environment
256
+ Object.defineProperty(navigator, 'userAgent', {
257
+ value: 'WebSpatial/1.0 ' + navigator.userAgent,
258
+ configurable: true
259
+ });
260
+
261
+ // send loaded message
262
+ window.parent.postMessage({
263
+ type: 'iframe_loaded',
264
+ spatialId: '${spatialId}',
265
+ url: '${url}'
266
+ }, '${window.location.origin}');
267
+
268
+ // set message handler
269
+ window.addEventListener('message', (event) => {
270
+ if (event.origin !== window.parent.location.origin) return;
271
+
272
+ const data = event.data;
273
+ if (data && data.type === 'webspatial_command') {
274
+ // handle command from parent window
275
+ console.log('Received command in iframe from parent:', data.command);
276
+ // add command handling logic here
277
+ }
278
+ });
279
+ `;
280
+ const doc = iframe.contentDocument;
281
+ if (doc) {
282
+ doc.open();
283
+ doc.write(`
284
+ <!DOCTYPE html>
285
+ <html>
286
+ <head>
287
+ <title>Spatial Iframe - ${spatialId}</title>
288
+ <meta charset="UTF-8">
289
+ <style>
290
+ body {
291
+ margin: 0;
292
+ padding: 0;
293
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
294
+ }
295
+ </style>
296
+ </head>
297
+ <body>
298
+ <script>${iframeContent}</script>
299
+ </body>
300
+ </html>
301
+ `);
302
+ doc.close();
303
+ }
304
+ } catch (error) {
305
+ console.error("Error initializing iframe content:", error);
306
+ }
307
+ };
308
+ } catch (error) {
309
+ console.error("Error setting up iframe:", error);
310
+ }
311
+ }
312
+ /**
313
+ * parse features string to object
314
+ */
315
+ parseFeatures(features) {
316
+ const result = {};
317
+ const pairs = features.split(",");
318
+ pairs.forEach((pair) => {
319
+ const [key, value] = pair.split("=").map((s) => s.trim());
320
+ if (key && value) {
321
+ result[key] = value;
322
+ }
323
+ });
324
+ return result;
325
+ }
326
+ /**
327
+ * send message to iframe with specified spatialId
328
+ */
329
+ sendMessageToIframe(spatialId, message) {
330
+ const iframe = this.iframeRegistry.get(spatialId);
331
+ if (iframe && iframe.contentWindow) {
332
+ iframe.contentWindow.postMessage(message, window.location.origin);
333
+ return true;
334
+ }
335
+ return false;
336
+ }
337
+ /**
338
+ * get all active iframes
339
+ */
340
+ getAllActiveIframes() {
341
+ const result = [];
342
+ this.iframeRegistry.forEach((iframe, spatialId) => {
343
+ result.push({ spatialId, iframe });
344
+ });
345
+ return result;
346
+ }
347
+ /**
348
+ * dispose all active iframes
349
+ */
350
+ dispose() {
351
+ this.iframeRegistry.forEach((iframe, spatialId) => {
352
+ console.log(`Disposing iframe with spatialId: ${spatialId}`);
353
+ iframe.remove();
354
+ });
355
+ this.iframeRegistry.clear();
356
+ }
357
+ // generate UUID function
358
+ generateUUID() {
359
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
360
+ /[xy]/g,
361
+ function(c) {
362
+ const r = Math.random() * 16 | 0;
363
+ const v = c === "x" ? r : r & 3 | 8;
364
+ return v.toString(16).toUpperCase();
365
+ }
366
+ );
367
+ }
368
+ }
369
+ export {
370
+ PuppeteerPlatform
371
+ };
372
+ //# sourceMappingURL=PuppeteerPlatform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/platform-adapter/puppeteer/PuppeteerPlatform.ts"],"sourcesContent":["import {\n PlatformAbility,\n CommandResult,\n WebSpatialProtocolResult,\n} from '../interface'\nimport { buildSpatialSceneQuery } from '../spatialSceneQuery'\nimport type { SpatialSceneCreationOptionsInternal } from '../../types/internal'\nimport type { AttachmentEntityOptions } from '../../types/types'\nimport {\n CommandResultFailure,\n CommandResultSuccess,\n} from '../CommandResultUtils'\n\n// add window interface for JSB call\ndeclare global {\n interface Window {\n __handleJSBMessage: (message: string) => any\n SpatialId?: string\n }\n\n interface HTMLIFrameElement {\n spatialId?: string\n webSpatialId?: string\n }\n}\n\nexport class PuppeteerPlatform implements PlatformAbility {\n // store iframe instance\n private iframeRegistry: Map<string, HTMLIFrameElement> = new Map()\n\n constructor() {}\n\n callJSB(cmd: string, msg: string): Promise<CommandResult> {\n return new Promise(resolve => {\n try {\n // check __handleJSBMessage exist\n if (window.__handleJSBMessage) {\n try {\n console.log(` core-sdk Puppeteer Platform: callJSB: ${cmd}::${msg}`)\n const result = window.__handleJSBMessage(`${cmd}::${msg}`)\n console.log(\n ` core-sdk Puppeteer Platform callJSB result: ${result}`,\n )\n resolve(CommandResultSuccess(result))\n } catch (err) {\n resolve(CommandResultFailure('500', 'JSB execution error'))\n }\n } else {\n // if not exist, return default result\n resolve(CommandResultSuccess('ok'))\n }\n } catch (error: unknown) {\n console.error(\n `PuppeteerPlatform cmd Error: ${cmd}, msg: ${msg} error: ${error}`,\n )\n resolve(CommandResultFailure('500', 'Internal error'))\n }\n })\n }\n\n /**\n * Synchronously create Spatialized2DElement to Puppeteer Runner\n */\n private createSpatializedElementSync(\n spatialId: string,\n webspatialUrl: string,\n ): void {\n try {\n console.log(\n `[Puppeteer Platform] Creating spatialized element sync with id: ${spatialId}, url: ${webspatialUrl}`,\n )\n // directly call Puppeteer Runner method to create element\n const win = window as any\n if (win.__handleJSBMessage) {\n // use simpler format to ensure JSBManager can correctly use our passed spatialId\n const createCommand = {\n id: spatialId,\n url: webspatialUrl,\n }\n win.__handleJSBMessage(\n `CreateSpatialized2DElement::${JSON.stringify(createCommand)}`,\n )\n }\n } catch (error) {\n console.error('Error creating spatialized element sync:', error)\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 return this.runProtocolSync('createSpatialScene', query, target, features)\n }\n\n createNativeSpatialDiv(): Promise<WebSpatialProtocolResult> {\n return this.runProtocolAsync(\n 'createSpatialized2DElement',\n '',\n undefined,\n undefined,\n )\n }\n\n createNativeAttachment(\n _options?: AttachmentEntityOptions,\n ): Promise<WebSpatialProtocolResult> {\n return this.runProtocolAsync('createAttachment', '', undefined, undefined)\n }\n\n private runProtocolAsync(\n command: string,\n query?: string,\n target?: string,\n features?: string,\n ): Promise<WebSpatialProtocolResult> {\n console.log(\n `PuppeteerPlatform: Calling webspatial protocol: webspatial://${command}${query ? `?${query}` : ''}`,\n )\n return new Promise(resolve => {\n try {\n // create complete webspatial URL\n const webspatialUrl = `webspatial://${command}${query ? `?${query}` : ''}`\n // use iframe to create new window\n const { spatialId, iframe, windowProxy } = this.createIframeWindow(\n webspatialUrl,\n target,\n features,\n )\n\n // 对于createSpatialized2DElement命令,同步创建元素\n if (command === 'createSpatialized2DElement') {\n this.createSpatializedElementSync(spatialId, webspatialUrl)\n }\n console.log(\n `[Puppeteer Platform] iframe created with spatialId: ${spatialId}`,\n )\n // store iframe instance\n this.iframeRegistry.set(spatialId, iframe)\n resolve(CommandResultSuccess({ windowProxy, id: spatialId }))\n } catch (error) {\n console.error('Error calling webspatial protocol:', error)\n resolve(\n CommandResultFailure('500', 'Failed to call webspatial protocol'),\n )\n }\n })\n }\n\n private runProtocolSync(\n command: string,\n query?: string,\n target?: string,\n features?: string,\n ): WebSpatialProtocolResult {\n try {\n // create complete webspatial URL\n const webspatialUrl = `webspatial://${command}${query ? `?${query}` : ''}`\n console.log(`Calling webspatial protocol sync: ${webspatialUrl}`)\n\n // 使用iframe创建新窗口\n const { spatialId, iframe, windowProxy } = this.createIframeWindow(\n webspatialUrl,\n target,\n features,\n )\n\n // 对于createSpatialized2DElement命令,同步创建元素\n if (command === 'createSpatialized2DElement') {\n this.createSpatializedElementSync(spatialId, webspatialUrl)\n }\n\n // store iframe instance\n this.iframeRegistry.set(spatialId, iframe)\n\n return CommandResultSuccess({ windowProxy, id: spatialId })\n } catch (error) {\n console.error('Error calling webspatial protocol sync:', error)\n return CommandResultFailure(\n '500',\n 'Failed to call webspatial protocol sync',\n )\n }\n }\n\n /**\n * Synchronously create iframe-based window\n */\n private createIframeWindow(url: string, target?: string, features?: string) {\n // create iframe element\n const iframe = document.createElement('iframe')\n\n // set iframe attributes\n iframe.style.border = 'none'\n iframe.style.display = 'none'\n iframe.style.width = '100%'\n iframe.style.height = '100%'\n\n // set iframe id\n const spatialId = this.generateUUID()\n iframe.spatialId = spatialId\n iframe.id = `spatial-iframe-${spatialId}`\n\n // parse features parameter\n const featuresObj = this.parseFeatures(features || '')\n\n // set iframe styles based on features\n if (featuresObj.width) {\n iframe.style.width = featuresObj.width\n }\n if (featuresObj.height) {\n iframe.style.height = featuresObj.height\n }\n if (featuresObj.left) {\n iframe.style.left = featuresObj.left\n iframe.style.position = 'absolute'\n }\n if (featuresObj.top) {\n iframe.style.top = featuresObj.top\n iframe.style.position = 'absolute'\n }\n\n // add iframe to DOM\n document.body.appendChild(iframe)\n\n // create enhanced windowProxy object\n const windowProxy = this.createEnhancedWindowProxy(iframe, url, spatialId)\n\n // set iframe src\n iframe.src = 'about:blank'\n\n console.log(\n `PuppeteerPlatform created iframe window with spatialId: ${spatialId}, URL: ${url}`,\n )\n\n // initialize iframe content\n this.initializeIframeContent(iframe, url, spatialId)\n\n return { spatialId, iframe, windowProxy }\n }\n\n /**\n * create enhanced windowProxy object\n */\n private createEnhancedWindowProxy(\n iframe: HTMLIFrameElement,\n url: string,\n spatialId: string,\n ) {\n // create enhanced windowProxy object\n return {\n // basic properties\n location: {\n href: url,\n toString: () => url,\n reload: () => {\n if (iframe.contentWindow) {\n iframe.contentWindow.location.reload()\n }\n },\n },\n navigator: {\n userAgent: `Mozilla/5.0 (WebKit) SpatialId/${spatialId}`,\n },\n\n // methods\n close: () => {\n console.log(`Closing iframe with spatialId: ${spatialId}`)\n iframe.remove()\n this.iframeRegistry.delete(spatialId)\n },\n\n // document access\n document: iframe.contentDocument || ({} as Document),\n contentWindow: iframe.contentWindow || ({} as Window),\n\n // add message communication method\n postMessage: (message: any, targetOrigin?: string) => {\n if (iframe.contentWindow) {\n iframe.contentWindow.postMessage(message, targetOrigin || '*')\n }\n },\n\n // add event listener method\n addEventListener: (\n type: string,\n listener: EventListenerOrEventListenerObject,\n ) => {\n if (iframe.contentWindow) {\n iframe.contentWindow.addEventListener(type, listener)\n }\n },\n\n removeEventListener: (\n type: string,\n listener: EventListenerOrEventListenerObject,\n ) => {\n if (iframe.contentWindow) {\n iframe.contentWindow.removeEventListener(type, listener)\n }\n },\n\n // execute JavaScript\n executeScript: (code: string): any => {\n if (iframe.contentWindow) {\n try {\n // use type assertion and safer way to execute script\n const win = iframe.contentWindow as any\n return win.eval(code)\n } catch (error) {\n console.error(\n `Error executing script in iframe ${spatialId}:`,\n error,\n )\n return null\n }\n }\n return null\n },\n\n // get iframe reference\n getIframe: () => iframe,\n\n // get spatialId\n getSpatialId: () => spatialId,\n }\n }\n\n /**\n * initialize iframe content\n */\n private initializeIframeContent(\n iframe: HTMLIFrameElement,\n url: string,\n spatialId: string,\n ): void {\n try {\n // wait for iframe to load\n iframe.onload = () => {\n try {\n // set iframe content\n const iframeContent = `\n // inject communication script\n window.webSpatialId = '${spatialId}';\n window.SpatialId = '${spatialId}';\n \n // override window.open to support webspatial protocol\n const originalOpen = window.open;\n window.open = function(url, target, features) {\n if (url && url.startsWith('webspatial://')) {\n // handle webspatial protocol through windowProxy\n const windowProxy = new Proxy({}, {\n get: function(target, prop) {\n if (prop === 'toString') {\n return function() { return url; };\n }\n return undefined;\n }\n });\n return windowProxy;\n }\n return originalOpen.call(window, url, target, features);\n };\n \n // set navigator.userAgent to identify webspatial environment\n Object.defineProperty(navigator, 'userAgent', {\n value: 'WebSpatial/1.0 ' + navigator.userAgent,\n configurable: true\n });\n \n // send loaded message\n window.parent.postMessage({\n type: 'iframe_loaded',\n spatialId: '${spatialId}',\n url: '${url}'\n }, '${window.location.origin}');\n \n // set message handler\n window.addEventListener('message', (event) => {\n if (event.origin !== window.parent.location.origin) return;\n \n const data = event.data;\n if (data && data.type === 'webspatial_command') {\n // handle command from parent window\n console.log('Received command in iframe from parent:', data.command);\n // add command handling logic here\n }\n });\n `\n\n // use document.write instead of eval for security and type compliance\n const doc = iframe.contentDocument\n if (doc) {\n doc.open()\n doc.write(`\n <!DOCTYPE html>\n <html>\n <head>\n <title>Spatial Iframe - ${spatialId}</title>\n <meta charset=\"UTF-8\">\n <style>\n body {\n margin: 0;\n padding: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n }\n </style>\n </head>\n <body>\n <script>${iframeContent}</script>\n </body>\n </html>\n `)\n doc.close()\n }\n } catch (error) {\n console.error('Error initializing iframe content:', error)\n }\n }\n } catch (error) {\n console.error('Error setting up iframe:', error)\n }\n }\n\n /**\n * parse features string to object\n */\n private parseFeatures(features: string): Record<string, string> {\n const result: Record<string, string> = {}\n const pairs = features.split(',')\n\n pairs.forEach(pair => {\n const [key, value] = pair.split('=').map(s => s.trim())\n if (key && value) {\n result[key] = value\n }\n })\n\n return result\n }\n\n /**\n * send message to iframe with specified spatialId\n */\n public sendMessageToIframe(spatialId: string, message: any): boolean {\n const iframe = this.iframeRegistry.get(spatialId)\n if (iframe && iframe.contentWindow) {\n iframe.contentWindow.postMessage(message, window.location.origin)\n return true\n }\n return false\n }\n\n /**\n * get all active iframes\n */\n public getAllActiveIframes(): Array<{\n spatialId: string\n iframe: HTMLIFrameElement\n }> {\n const result: Array<{ spatialId: string; iframe: HTMLIFrameElement }> = []\n\n this.iframeRegistry.forEach((iframe, spatialId) => {\n result.push({ spatialId, iframe })\n })\n\n return result\n }\n\n /**\n * dispose all active iframes\n */\n public dispose(): void {\n // close all iframes\n this.iframeRegistry.forEach((iframe, spatialId) => {\n console.log(`Disposing iframe with spatialId: ${spatialId}`)\n iframe.remove()\n })\n this.iframeRegistry.clear()\n }\n\n // generate UUID function\n private generateUUID(): string {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(\n /[xy]/g,\n function (c) {\n const r = (Math.random() * 16) | 0\n const v = c === 'x' ? r : (r & 0x3) | 0x8\n return v.toString(16).toUpperCase()\n },\n )\n }\n}\n"],"mappings":"AAKA,SAAS,8BAA8B;AAGvC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAeA,MAAM,kBAA6C;AAAA;AAAA,EAEhD,iBAAiD,oBAAI,IAAI;AAAA,EAEjE,cAAc;AAAA,EAAC;AAAA,EAEf,QAAQ,KAAa,KAAqC;AACxD,WAAO,IAAI,QAAQ,aAAW;AAC5B,UAAI;AAEF,YAAI,OAAO,oBAAoB;AAC7B,cAAI;AACF,oBAAQ,IAAI,0CAA0C,GAAG,KAAK,GAAG,EAAE;AACnE,kBAAM,SAAS,OAAO,mBAAmB,GAAG,GAAG,KAAK,GAAG,EAAE;AACzD,oBAAQ;AAAA,cACN,gDAAgD,MAAM;AAAA,YACxD;AACA,oBAAQ,qBAAqB,MAAM,CAAC;AAAA,UACtC,SAAS,KAAK;AACZ,oBAAQ,qBAAqB,OAAO,qBAAqB,CAAC;AAAA,UAC5D;AAAA,QACF,OAAO;AAEL,kBAAQ,qBAAqB,IAAI,CAAC;AAAA,QACpC;A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EAGQ,eAAuB;AAC7B,WAAO,uCAAuC;AAAA,MAC5C;AAAA,MACA,SAAU,GAAG;AACX,cAAM,IAAK,KAAK,OAAO,IAAI,KAAM;AACjC,cAAM,IAAI,MAAM,MAAM,IAAK,IAAI,IAAO;AACtC,eAAO,EAAE,SAAS,EAAE,EAAE,YAAY;AAAA,MACpC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,6 @@
1
+ declare const DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS = 30000;
2
+ declare function createSpatialRequestId(): string;
3
+ declare function getCurrentPageEpoch(): string | undefined;
4
+ declare function buildSpatialRequestQuery(requestId: string, pageEpoch?: string | undefined): string;
5
+
6
+ export { DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS, buildSpatialRequestQuery, createSpatialRequestId, getCurrentPageEpoch };
@@ -0,0 +1,39 @@
1
+ const REQUEST_ID_PREFIX = "wsreq";
2
+ const DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS = 3e4;
3
+ let requestSequence = 0;
4
+ const contextNonce = createContextNonce();
5
+ function createContextNonce() {
6
+ const cryptoApi = globalThis.crypto;
7
+ if (cryptoApi?.getRandomValues) {
8
+ const values = new Uint32Array(2);
9
+ cryptoApi.getRandomValues(values);
10
+ return Array.from(values, (value) => value.toString(36)).join("");
11
+ }
12
+ return Math.random().toString(36).slice(2, 12);
13
+ }
14
+ function createSpatialRequestId() {
15
+ requestSequence += 1;
16
+ return `${REQUEST_ID_PREFIX}_${contextNonce}_${requestSequence}`;
17
+ }
18
+ function getCurrentPageEpoch() {
19
+ const pageEpoch = window.__webspatialsdk__?.pageEpoch;
20
+ if (pageEpoch === void 0 || pageEpoch === null || pageEpoch === "") {
21
+ return void 0;
22
+ }
23
+ return String(pageEpoch);
24
+ }
25
+ function buildSpatialRequestQuery(requestId, pageEpoch = getCurrentPageEpoch()) {
26
+ const params = new URLSearchParams();
27
+ params.set("rid", requestId);
28
+ if (pageEpoch !== void 0) {
29
+ params.set("wsepoch", pageEpoch);
30
+ }
31
+ return params.toString();
32
+ }
33
+ export {
34
+ DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS,
35
+ buildSpatialRequestQuery,
36
+ createSpatialRequestId,
37
+ getCurrentPageEpoch
38
+ };
39
+ //# sourceMappingURL=spatialRequestMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/platform-adapter/spatialRequestMetadata.ts"],"sourcesContent":["const REQUEST_ID_PREFIX = 'wsreq'\n\nexport const DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS = 30_000\n\nlet requestSequence = 0\n\n// One nonce per JS execution context keeps request ids refresh-safe without\n// exposing host-specific lifecycle details in the protocol surface.\nconst contextNonce = createContextNonce()\n\nfunction createContextNonce(): string {\n const cryptoApi = globalThis.crypto\n if (cryptoApi?.getRandomValues) {\n const values = new Uint32Array(2)\n cryptoApi.getRandomValues(values)\n return Array.from(values, value => value.toString(36)).join('')\n }\n\n return Math.random().toString(36).slice(2, 12)\n}\n\nexport function createSpatialRequestId(): string {\n requestSequence += 1\n return `${REQUEST_ID_PREFIX}_${contextNonce}_${requestSequence}`\n}\n\nexport function getCurrentPageEpoch(): string | undefined {\n const pageEpoch = window.__webspatialsdk__?.pageEpoch\n if (pageEpoch === undefined || pageEpoch === null || pageEpoch === '') {\n return undefined\n }\n\n return String(pageEpoch)\n}\n\nexport function buildSpatialRequestQuery(\n requestId: string,\n pageEpoch = getCurrentPageEpoch(),\n): string {\n const params = new URLSearchParams()\n params.set('rid', requestId)\n\n if (pageEpoch !== undefined) {\n params.set('wsepoch', pageEpoch)\n }\n\n return params.toString()\n}\n"],"mappings":"AAAA,MAAM,oBAAoB;AAEnB,MAAM,qCAAqC;AAElD,IAAI,kBAAkB;AAItB,MAAM,eAAe,mBAAmB;AAExC,SAAS,qBAA6B;AACpC,QAAM,YAAY,WAAW;AAC7B,MAAI,WAAW,iBAAiB;AAC9B,UAAM,SAAS,IAAI,YAAY,CAAC;AAChC,cAAU,gBAAgB,MAAM;AAChC,WAAO,MAAM,KAAK,QAAQ,WAAS,MAAM,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE;AAAA,EAChE;AAEA,SAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE;AAC/C;AAEO,SAAS,yBAAiC;AAC/C,qBAAmB;AACnB,SAAO,GAAG,iBAAiB,IAAI,YAAY,IAAI,eAAe;AAChE;AAEO,SAAS,sBAA0C;AACxD,QAAM,YAAY,OAAO,mBAAmB;AAC5C,MAAI,cAAc,UAAa,cAAc,QAAQ,cAAc,IAAI;AACrE,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,yBACd,WACA,YAAY,oBAAoB,GACxB;AACR,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,OAAO,SAAS;AAE3B,MAAI,cAAc,QAAW;AAC3B,WAAO,IAAI,WAAW,SAAS;AAAA,EACjC;AAEA,SAAO,OAAO,SAAS;AACzB;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { aQ as SpatialSceneCreationOptionsInternal } 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
+ /** Build query string for webspatial://createSpatialScene (url + config). */
10
+ declare function buildSpatialSceneQuery(url: string, config: SpatialSceneCreationOptionsInternal | undefined): string;
11
+
12
+ export { buildSpatialSceneQuery };
@@ -0,0 +1,12 @@
1
+ function buildSpatialSceneQuery(url, config) {
2
+ const params = { url, config };
3
+ return Object.keys(params).map((key) => {
4
+ const value = params[key];
5
+ const finalValue = typeof value === "object" ? JSON.stringify(value) : value;
6
+ return `${key}=${encodeURIComponent(finalValue)}`;
7
+ }).join("&");
8
+ }
9
+ export {
10
+ buildSpatialSceneQuery
11
+ };
12
+ //# sourceMappingURL=spatialSceneQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/platform-adapter/spatialSceneQuery.ts"],"sourcesContent":["import type { SpatialSceneCreationOptionsInternal } from '../types/internal'\n\n/** Build query string for webspatial://createSpatialScene (url + config). */\nexport function buildSpatialSceneQuery(\n url: string,\n config: SpatialSceneCreationOptionsInternal | undefined,\n): string {\n const params: Record<string, any> = { url, config }\n return Object.keys(params)\n .map(key => {\n const value = params[key]\n const finalValue =\n typeof value === 'object' ? JSON.stringify(value) : value\n return `${key}=${encodeURIComponent(finalValue)}`\n })\n .join('&')\n}\n"],"mappings":"AAGO,SAAS,uBACd,KACA,QACQ;AACR,QAAM,SAA8B,EAAE,KAAK,OAAO;AAClD,SAAO,OAAO,KAAK,MAAM,EACtB,IAAI,SAAO;AACV,UAAM,QAAQ,OAAO,GAAG;AACxB,UAAM,aACJ,OAAO,UAAU,WAAW,KAAK,UAAU,KAAK,IAAI;AACtD,WAAO,GAAG,GAAG,IAAI,mBAAmB,UAAU,CAAC;AAAA,EACjD,CAAC,EACA,KAAK,GAAG;AACb;","names":[]}
@@ -0,0 +1,19 @@
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 VisionOSPlatform 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
+ private openProtocolAsync;
15
+ private openWindow;
16
+ private parseJSBError;
17
+ }
18
+
19
+ export { VisionOSPlatform };