@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.
Files changed (320) hide show
  1. package/CHANGELOG.md +84 -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 -1101
  43. package/dist/index.js +21 -3393
  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 +148 -91
  241. package/src/Spatial.ts +0 -21
  242. package/src/SpatialObject.ts +10 -0
  243. package/src/SpatialScene.ts +1 -5
  244. package/src/SpatialSession.ts +17 -3
  245. package/src/Spatialized2DElement.ts +5 -0
  246. package/src/SpatializedDynamic3DElement.ts +5 -1
  247. package/src/SpatializedElement.ts +29 -0
  248. package/src/SpatializedElementCreator.ts +6 -4
  249. package/src/SpatializedStatic3DElement.test.ts +99 -0
  250. package/src/SpatializedStatic3DElement.ts +141 -4
  251. package/src/WebMsgCommand.ts +50 -0
  252. package/src/coverage-boost.test.ts +258 -316
  253. package/src/index.ts +28 -12
  254. package/src/install-polyfills.ts +38 -0
  255. package/src/jsbcommand.coverage.test.ts +42 -48
  256. package/src/motion/AnimationObject.test.ts +421 -0
  257. package/src/motion/AnimationObject.ts +208 -0
  258. package/src/motion/compute/index.ts +10 -0
  259. package/src/motion/compute/motionPropertyValues.test.ts +55 -0
  260. package/src/motion/compute/motionPropertyValues.ts +70 -0
  261. package/src/motion/compute/normalize.test.ts +99 -0
  262. package/src/motion/compute/normalize.ts +289 -0
  263. package/src/motion/compute/validate.test.ts +229 -0
  264. package/src/motion/compute/validate.ts +156 -0
  265. package/src/motion/index.ts +2 -0
  266. package/src/motion/native/serializeMotionTimeline.test.ts +61 -0
  267. package/src/motion/native/serializeMotionTimeline.ts +27 -0
  268. package/src/platform-adapter/CommandResultUtils.ts +2 -2
  269. package/src/platform-adapter/createPlatformSync.ts +36 -0
  270. package/src/platform-adapter/index.ts +5 -51
  271. package/src/platform-adapter/interface.ts +35 -23
  272. package/src/platform-adapter/pico-os/PicoOSPlatform.ts +156 -59
  273. package/src/platform-adapter/puppeteer/PuppeteerPlatform.ts +37 -11
  274. package/src/platform-adapter/spatialRequestMetadata.test.ts +175 -0
  275. package/src/platform-adapter/spatialRequestMetadata.ts +48 -0
  276. package/src/platform-adapter/spatialSceneQuery.ts +17 -0
  277. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +60 -24
  278. package/src/platform-runtime.ts +13 -0
  279. package/src/reality/Attachment.ts +2 -2
  280. package/src/reality/entity/SpatialEntity.ts +127 -2
  281. package/src/reality/realityCreator.ts +15 -1
  282. package/src/reality/resource/SpatialTextureResource.ts +16 -0
  283. package/src/reality/resource/index.ts +1 -0
  284. package/src/runtime/WebSpatialRuntimeError.ts +16 -0
  285. package/src/runtime/capability-data.ts +213 -0
  286. package/src/runtime/contract-review.test.ts +44 -0
  287. package/src/runtime/index.ts +17 -0
  288. package/src/runtime/jsbAdapterPlatform.test.ts +36 -0
  289. package/src/runtime/jsbAdapterPlatform.ts +51 -0
  290. package/src/runtime/keys.ts +140 -0
  291. package/src/runtime/semver.ts +33 -0
  292. package/src/runtime/supports.test.ts +346 -0
  293. package/src/runtime/supports.ts +112 -0
  294. package/src/runtime/types.ts +11 -0
  295. package/src/runtime/useAnimation.capability.test.ts +275 -0
  296. package/src/runtime/userAgent.ts +64 -0
  297. package/src/scene-polyfill.manifest.test.ts +312 -9
  298. package/src/scene-polyfill.request-metadata.test.ts +39 -0
  299. package/src/scene-polyfill.test.ts +33 -94
  300. package/src/scene-polyfill.ts +125 -92
  301. package/src/spatial-host.ts +25 -0
  302. package/src/spatial-window-polyfill.ts +18 -2
  303. package/src/transform-roundtrip.test.ts +90 -0
  304. package/src/types/animation.ts +224 -0
  305. package/src/types/{global.d.ts → global.ts} +10 -12
  306. package/src/types/motion/index.ts +10 -0
  307. package/src/types/motion/spatializedElementMotion.ts +49 -0
  308. package/src/types/motion/spatializedMotion.ts +147 -0
  309. package/src/types/motion/spatializedPlayback.ts +17 -0
  310. package/src/types/motion/spatializedVisual.ts +24 -0
  311. package/src/types/types.ts +12 -0
  312. package/src/utils.ts +54 -0
  313. package/tsup.config.ts +61 -36
  314. package/vitest.config.ts +5 -1
  315. package/dist/iife/index.d.ts +0 -1101
  316. package/dist/iife/index.global.js +0 -75
  317. package/dist/iife/index.global.js.map +0 -1
  318. package/src/platform-adapter/android/AndroidPlatform.ts +0 -133
  319. package/src/platform-adapter/ssr/SSRPlatform.ts +0 -43
  320. /package/src/{ssr-polyfill.ts → isSSREnv.ts} +0 -0
@@ -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;AAAA,MACF,SAAS,OAAgB;AACvB,gBAAQ;AAAA,UACN,gCAAgC,GAAG,UAAU,GAAG,WAAW,KAAK;AAAA,QAClE;AACA,gBAAQ,qBAAqB,OAAO,gBAAgB,CAAC;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M,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 };
@@ -0,0 +1,77 @@
1
+ import {
2
+ CommandResultFailure,
3
+ CommandResultSuccess
4
+ } from "../CommandResultUtils";
5
+ import { buildSpatialSceneQuery } from "../spatialSceneQuery";
6
+ import {
7
+ buildSpatialRequestQuery,
8
+ createSpatialRequestId
9
+ } from "../spatialRequestMetadata";
10
+ const UUID_RE = /\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\b/gi;
11
+ class VisionOSPlatform {
12
+ async callJSB(cmd, msg) {
13
+ try {
14
+ const result = await window.webkit.messageHandlers.bridge.postMessage(
15
+ `${cmd}::${msg}`
16
+ );
17
+ return CommandResultSuccess(result);
18
+ } catch (error) {
19
+ const { code, message } = this.parseJSBError(error);
20
+ return CommandResultFailure(code, message);
21
+ }
22
+ }
23
+ openSpatialSceneSync(url, config, target, features) {
24
+ const query = buildSpatialSceneQuery(url, config);
25
+ const { spatialId: id = "", windowProxy } = this.openWindow(
26
+ "createSpatialScene",
27
+ query,
28
+ target,
29
+ features
30
+ );
31
+ return CommandResultSuccess({ windowProxy, id });
32
+ }
33
+ createNativeSpatialDiv() {
34
+ return this.openProtocolAsync("createSpatialized2DElement");
35
+ }
36
+ createNativeAttachment(_options) {
37
+ return this.openProtocolAsync("createAttachment");
38
+ }
39
+ async openProtocolAsync(command) {
40
+ const requestId = createSpatialRequestId();
41
+ const { spatialId: id = "", windowProxy } = this.openWindow(
42
+ command,
43
+ buildSpatialRequestQuery(requestId),
44
+ void 0,
45
+ void 0
46
+ );
47
+ return CommandResultSuccess({ windowProxy, id });
48
+ }
49
+ openWindow(command, query, target, features) {
50
+ const windowProxy = window.open(
51
+ `webspatial://${command}?${query || ""}`,
52
+ target,
53
+ features
54
+ );
55
+ const ua = windowProxy?.navigator.userAgent;
56
+ const spatialId = ua?.match(UUID_RE)?.[0];
57
+ return { spatialId, windowProxy };
58
+ }
59
+ parseJSBError(error) {
60
+ try {
61
+ const parsed = JSON.parse(error.message ?? "");
62
+ return {
63
+ code: parsed.code ?? "E_VISIONOS_JSB",
64
+ message: parsed.message ?? "VisionOS JSB execution failed"
65
+ };
66
+ } catch {
67
+ return {
68
+ code: "E_VISIONOS_JSB",
69
+ message: error?.message ?? "VisionOS JSB execution failed"
70
+ };
71
+ }
72
+ }
73
+ }
74
+ export {
75
+ VisionOSPlatform
76
+ };
77
+ //# sourceMappingURL=VisionOSPlatform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/platform-adapter/vision-os/VisionOSPlatform.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 type { SpatialSceneCreationOptionsInternal } from '../../types/internal'\nimport type { AttachmentEntityOptions } from '../../types/types'\nimport {\n buildSpatialRequestQuery,\n createSpatialRequestId,\n} from '../spatialRequestMetadata'\n\ntype JSBError = {\n code?: string\n message: string\n}\n\nconst UUID_RE =\n /\\b([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\\b/gi\n\nexport class VisionOSPlatform implements PlatformAbility {\n async callJSB(cmd: string, msg: string): Promise<CommandResult> {\n try {\n const result = await window.webkit.messageHandlers.bridge.postMessage(\n `${cmd}::${msg}`,\n )\n return CommandResultSuccess(result)\n } catch (error: unknown) {\n // console.error(`VisionOSPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`)\n const { code, message } = this.parseJSBError(error)\n return CommandResultFailure(code, message)\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.openProtocolAsync('createSpatialized2DElement')\n }\n\n createNativeAttachment(\n _options?: AttachmentEntityOptions,\n ): Promise<WebSpatialProtocolResult> {\n return this.openProtocolAsync('createAttachment')\n }\n\n private async openProtocolAsync(\n command: string,\n ): Promise<WebSpatialProtocolResult> {\n const requestId = createSpatialRequestId()\n const { spatialId: id = '', windowProxy } = this.openWindow(\n command,\n buildSpatialRequestQuery(requestId),\n undefined,\n undefined,\n )\n return CommandResultSuccess({ windowProxy, id })\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 windowProxy = window.open(\n `webspatial://${command}?${query || ''}`,\n target,\n features,\n )\n const ua = windowProxy?.navigator.userAgent\n const spatialId = ua?.match(UUID_RE)?.[0]\n\n return { spatialId, windowProxy }\n }\n\n private parseJSBError(error: unknown): { code: string; message: string } {\n try {\n const parsed = JSON.parse((error as JSBError).message ?? '')\n return {\n code: parsed.code ?? 'E_VISIONOS_JSB',\n message: parsed.message ?? 'VisionOS JSB execution failed',\n }\n } catch {\n return {\n code: 'E_VISIONOS_JSB',\n message:\n (error as JSBError)?.message ?? 'VisionOS JSB execution failed',\n }\n }\n }\n}\n"],"mappings":"AAKA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AAGvC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAOP,MAAM,UACJ;AAEK,MAAM,iBAA4C;AAAA,EACvD,MAAM,QAAQ,KAAa,KAAqC;AAC9D,QAAI;AACF,YAAM,SAAS,MAAM,OAAO,OAAO,gBAAgB,OAAO;AAAA,QACxD,GAAG,GAAG,KAAK,GAAG;AAAA,MAChB;AACA,aAAO,qBAAqB,MAAM;AAAA,IACpC,SAAS,OAAgB;AAEvB,YAAM,EAAE,MAAM,QAAQ,IAAI,KAAK,cAAc,KAAK;AAClD,aAAO,qBAAqB,MAAM,OAAO;AAAA,IAC3C;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} 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 getPlatformSync(): PlatformAbility;
10
+ declare function getPlatform(): Promise<PlatformAbility>;
11
+
12
+ export { getPlatform, getPlatformSync };
@@ -0,0 +1,14 @@
1
+ import { createPlatformSync } from "./platform-adapter";
2
+ let platformResolved;
3
+ function getPlatformSync() {
4
+ platformResolved ??= createPlatformSync();
5
+ return platformResolved;
6
+ }
7
+ async function getPlatform() {
8
+ return getPlatformSync();
9
+ }
10
+ export {
11
+ getPlatform,
12
+ getPlatformSync
13
+ };
14
+ //# sourceMappingURL=platform-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/platform-runtime.ts"],"sourcesContent":["import { createPlatformSync } from './platform-adapter'\nimport type { PlatformAbility } from './platform-adapter/interface'\n\nlet platformResolved: PlatformAbility | undefined\n\nexport function getPlatformSync(): PlatformAbility {\n platformResolved ??= createPlatformSync()\n return platformResolved\n}\n\nexport async function getPlatform(): Promise<PlatformAbility> {\n return getPlatformSync()\n}\n"],"mappings":"AAAA,SAAS,0BAA0B;AAGnC,IAAI;AAEG,SAAS,kBAAmC;AACjD,uBAAqB,mBAAmB;AACxC,SAAO;AACT;AAEA,eAAsB,cAAwC;AAC5D,SAAO,gBAAgB;AACzB;","names":[]}