@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,103 @@
1
+ import { SPATIALIZED_MOTION_PROPERTIES } from "../../types/motion/spatializedMotion";
2
+ import { normalizeMotionConfig } from "./normalize";
3
+ const ALLOWED_PROPERTIES = new Set(
4
+ SPATIALIZED_MOTION_PROPERTIES
5
+ );
6
+ const FORBIDDEN_PREFIXES = [
7
+ "width",
8
+ "height",
9
+ "back",
10
+ "backOffset",
11
+ "depth"
12
+ ];
13
+ function validateSpatializedMotionConfig(config) {
14
+ if (config.tracks !== void 0) {
15
+ throw new Error("[SpatializedMotion] tracks authoring is internal");
16
+ }
17
+ const normalized = normalizeMotionConfig(config);
18
+ validateNormalizedMotionConfig(normalized);
19
+ }
20
+ function validateNormalizedMotionConfig(config) {
21
+ const { duration, tracks } = config;
22
+ if (typeof duration !== "number" || !Number.isFinite(duration) || duration <= 0) {
23
+ throw new Error("[SpatializedMotion] duration must be a finite number > 0");
24
+ }
25
+ if (!Array.isArray(tracks) || tracks.length === 0) {
26
+ throw new Error("[SpatializedMotion] tracks must be a non-empty array");
27
+ }
28
+ const seen = /* @__PURE__ */ new Set();
29
+ for (const track of tracks) {
30
+ validateTrack(track, duration, seen);
31
+ }
32
+ if (config.delay !== void 0) {
33
+ const d = config.delay;
34
+ if (typeof d !== "number" || !Number.isFinite(d) || d < 0) {
35
+ throw new Error("[SpatializedMotion] delay must be >= 0 and finite");
36
+ }
37
+ }
38
+ if (config.playbackRate !== void 0) {
39
+ const r = config.playbackRate;
40
+ if (typeof r !== "number" || !Number.isFinite(r) || r <= 0) {
41
+ throw new Error("[SpatializedMotion] playbackRate must be > 0 and finite");
42
+ }
43
+ }
44
+ }
45
+ function validateTrack(track, duration, seen) {
46
+ const prop = track.property;
47
+ for (const forbidden of FORBIDDEN_PREFIXES) {
48
+ if (prop === forbidden || prop.startsWith(`${forbidden}.`)) {
49
+ throw new Error(
50
+ `[SpatializedMotion] property "${prop}" is not animatable`
51
+ );
52
+ }
53
+ }
54
+ if (!ALLOWED_PROPERTIES.has(track.property)) {
55
+ throw new Error(`[SpatializedMotion] unknown property "${prop}"`);
56
+ }
57
+ if (seen.has(prop)) {
58
+ throw new Error(`[SpatializedMotion] duplicate track for "${prop}"`);
59
+ }
60
+ seen.add(prop);
61
+ const kf = track.keyframes;
62
+ if (!Array.isArray(kf) || kf.length < 2) {
63
+ throw new Error(
64
+ `[SpatializedMotion] track "${prop}" needs at least 2 keyframes`
65
+ );
66
+ }
67
+ let prevAt = -Infinity;
68
+ for (const frame of kf) {
69
+ if (typeof frame.at !== "number" || !Number.isFinite(frame.at)) {
70
+ throw new Error(
71
+ `[SpatializedMotion] keyframe.at must be finite for "${prop}"`
72
+ );
73
+ }
74
+ if (frame.at < 0 || frame.at > duration) {
75
+ throw new Error(
76
+ `[SpatializedMotion] keyframe.at must be within [0, duration] for "${prop}"`
77
+ );
78
+ }
79
+ if (frame.at <= prevAt) {
80
+ throw new Error(
81
+ `[SpatializedMotion] keyframe times must be strictly increasing for "${prop}"`
82
+ );
83
+ }
84
+ prevAt = frame.at;
85
+ validateScalar(frame.value, track.property);
86
+ }
87
+ }
88
+ function validateScalar(value, property) {
89
+ if (typeof value !== "number" || !Number.isFinite(value)) {
90
+ throw new Error(`[SpatializedMotion] invalid value for ${property}`);
91
+ }
92
+ if (property === "opacity" && (value < 0 || value > 1)) {
93
+ throw new Error("[SpatializedMotion] opacity must be in [0, 1]");
94
+ }
95
+ if (property.startsWith("transform.scale.") && value < 0) {
96
+ throw new Error("[SpatializedMotion] scale must be >= 0");
97
+ }
98
+ }
99
+ export {
100
+ validateNormalizedMotionConfig,
101
+ validateSpatializedMotionConfig
102
+ };
103
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/motion/compute/validate.ts"],"sourcesContent":["import { SPATIALIZED_MOTION_PROPERTIES } from '../../types/motion/spatializedMotion'\nimport type {\n NormalizedSpatializedMotionConfig,\n SpatializedMotionProperty,\n SpatializedMotionConfig,\n SpatializedMotionTrack,\n} from '../../types/motion/spatializedMotion'\nimport { normalizeMotionConfig } from './normalize'\nconst ALLOWED_PROPERTIES = new Set<SpatializedMotionProperty>(\n SPATIALIZED_MOTION_PROPERTIES,\n)\n\nconst FORBIDDEN_PREFIXES = [\n 'width',\n 'height',\n 'back',\n 'backOffset',\n 'depth',\n] as const\n\n/**\n * Validates any supported motion config shape before playback or serialization.\n *\n * @param config Motion config in any supported input shape.\n */\nexport function validateSpatializedMotionConfig(\n config: SpatializedMotionConfig,\n): void {\n if (config.tracks !== undefined) {\n throw new Error('[SpatializedMotion] tracks authoring is internal')\n }\n const normalized = normalizeMotionConfig(config)\n validateNormalizedMotionConfig(normalized)\n}\n\n/**\n * Validates the canonical track-based motion config form.\n *\n * @param config Canonical motion config to validate.\n */\nexport function validateNormalizedMotionConfig(\n config: NormalizedSpatializedMotionConfig,\n): void {\n const { duration, tracks } = config\n\n if (\n typeof duration !== 'number' ||\n !Number.isFinite(duration) ||\n duration <= 0\n ) {\n throw new Error('[SpatializedMotion] duration must be a finite number > 0')\n }\n\n if (!Array.isArray(tracks) || tracks.length === 0) {\n throw new Error('[SpatializedMotion] tracks must be a non-empty array')\n }\n\n const seen = new Set<string>()\n for (const track of tracks) {\n validateTrack(track, duration, seen)\n }\n\n if (config.delay !== undefined) {\n const d = config.delay\n if (typeof d !== 'number' || !Number.isFinite(d) || d < 0) {\n throw new Error('[SpatializedMotion] delay must be >= 0 and finite')\n }\n }\n\n if (config.playbackRate !== undefined) {\n const r = config.playbackRate\n if (typeof r !== 'number' || !Number.isFinite(r) || r <= 0) {\n throw new Error('[SpatializedMotion] playbackRate must be > 0 and finite')\n }\n }\n}\n\n/**\n * Validates a single track against property and keyframe invariants.\n *\n * @param track Motion track to validate.\n * @param duration Parent motion duration.\n * @param seen Track-property set used to detect duplicates.\n */\nfunction validateTrack(\n track: SpatializedMotionTrack,\n duration: number,\n seen: Set<string>,\n): void {\n const prop = track.property as string\n for (const forbidden of FORBIDDEN_PREFIXES) {\n if (prop === forbidden || prop.startsWith(`${forbidden}.`)) {\n throw new Error(\n `[SpatializedMotion] property \"${prop}\" is not animatable`,\n )\n }\n }\n\n if (!ALLOWED_PROPERTIES.has(track.property)) {\n throw new Error(`[SpatializedMotion] unknown property \"${prop}\"`)\n }\n\n if (seen.has(prop)) {\n throw new Error(`[SpatializedMotion] duplicate track for \"${prop}\"`)\n }\n seen.add(prop)\n\n const kf = track.keyframes\n if (!Array.isArray(kf) || kf.length < 2) {\n throw new Error(\n `[SpatializedMotion] track \"${prop}\" needs at least 2 keyframes`,\n )\n }\n\n let prevAt = -Infinity\n for (const frame of kf) {\n if (typeof frame.at !== 'number' || !Number.isFinite(frame.at)) {\n throw new Error(\n `[SpatializedMotion] keyframe.at must be finite for \"${prop}\"`,\n )\n }\n if (frame.at < 0 || frame.at > duration) {\n throw new Error(\n `[SpatializedMotion] keyframe.at must be within [0, duration] for \"${prop}\"`,\n )\n }\n if (frame.at <= prevAt) {\n throw new Error(\n `[SpatializedMotion] keyframe times must be strictly increasing for \"${prop}\"`,\n )\n }\n prevAt = frame.at\n validateScalar(frame.value, track.property)\n }\n}\n\n/**\n * Validates a numeric sample for a specific motion property.\n *\n * @param value Numeric sample value to validate.\n * @param property Motion property the value belongs to.\n */\nfunction validateScalar(\n value: number,\n property: SpatializedMotionProperty,\n): void {\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new Error(`[SpatializedMotion] invalid value for ${property}`)\n }\n if (property === 'opacity' && (value < 0 || value > 1)) {\n throw new Error('[SpatializedMotion] opacity must be in [0, 1]')\n }\n if (property.startsWith('transform.scale.') && value < 0) {\n throw new Error('[SpatializedMotion] scale must be >= 0')\n }\n}\n"],"mappings":"AAAA,SAAS,qCAAqC;AAO9C,SAAS,6BAA6B;AACtC,MAAM,qBAAqB,IAAI;AAAA,EAC7B;AACF;AAEA,MAAM,qBAAqB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAOO,SAAS,gCACd,QACM;AACN,MAAI,OAAO,WAAW,QAAW;AAC/B,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,QAAM,aAAa,sBAAsB,MAAM;AAC/C,iCAA+B,UAAU;AAC3C;AAOO,SAAS,+BACd,QACM;AACN,QAAM,EAAE,UAAU,OAAO,IAAI;AAE7B,MACE,OAAO,aAAa,YACpB,CAAC,OAAO,SAAS,QAAQ,KACzB,YAAY,GACZ;AACA,UAAM,IAAI,MAAM,0DAA0D;AAAA,EAC5E;AAEA,MAAI,CAAC,MAAM,QAAQ,MAAM,KAAK,OAAO,WAAW,GAAG;AACjD,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AAEA,QAAM,OAAO,oBAAI,IAAY;AAC7B,aAAW,SAAS,QAAQ;AAC1B,kBAAc,OAAO,UAAU,IAAI;AAAA,EACrC;AAEA,MAAI,OAAO,UAAU,QAAW;AAC9B,UAAM,IAAI,OAAO;AACjB,QAAI,OAAO,MAAM,YAAY,CAAC,OAAO,SAAS,CAAC,KAAK,IAAI,GAAG;AACzD,YAAM,IAAI,MAAM,mDAAmD;AAAA,IACrE;AAAA,EACF;AAEA,MAAI,OAAO,iBAAiB,QAAW;AACrC,UAAM,IAAI,OAAO;AACjB,QAAI,OAAO,MAAM,YAAY,CAAC,OAAO,SAAS,CAAC,KAAK,KAAK,GAAG;AAC1D,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC3E;AAAA,EACF;AACF;AASA,SAAS,cACP,OACA,UACA,MACM;AACN,QAAM,OAAO,MAAM;AACnB,aAAW,aAAa,oBAAoB;AAC1C,QAAI,SAAS,aAAa,KAAK,WAAW,GAAG,SAAS,GAAG,GAAG;AAC1D,YAAM,IAAI;AAAA,QACR,iCAAiC,IAAI;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,mBAAmB,IAAI,MAAM,QAAQ,GAAG;AAC3C,UAAM,IAAI,MAAM,yCAAyC,IAAI,GAAG;AAAA,EAClE;AAEA,MAAI,KAAK,IAAI,IAAI,GAAG;AAClB,UAAM,IAAI,MAAM,4CAA4C,IAAI,GAAG;AAAA,EACrE;AACA,OAAK,IAAI,IAAI;AAEb,QAAM,KAAK,MAAM;AACjB,MAAI,CAAC,MAAM,QAAQ,EAAE,KAAK,GAAG,SAAS,GAAG;AACvC,UAAM,IAAI;AAAA,MACR,8BAA8B,IAAI;AAAA,IACpC;AAAA,EACF;AAEA,MAAI,SAAS;AACb,aAAW,SAAS,IAAI;AACtB,QAAI,OAAO,MAAM,OAAO,YAAY,CAAC,OAAO,SAAS,MAAM,EAAE,GAAG;AAC9D,YAAM,IAAI;AAAA,QACR,uDAAuD,IAAI;AAAA,MAC7D;AAAA,IACF;AACA,QAAI,MAAM,KAAK,KAAK,MAAM,KAAK,UAAU;AACvC,YAAM,IAAI;AAAA,QACR,qEAAqE,IAAI;AAAA,MAC3E;AAAA,IACF;AACA,QAAI,MAAM,MAAM,QAAQ;AACtB,YAAM,IAAI;AAAA,QACR,uEAAuE,IAAI;AAAA,MAC7E;AAAA,IACF;AACA,aAAS,MAAM;AACf,mBAAe,MAAM,OAAO,MAAM,QAAQ;AAAA,EAC5C;AACF;AAQA,SAAS,eACP,OACA,UACM;AACN,MAAI,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,GAAG;AACxD,UAAM,IAAI,MAAM,yCAAyC,QAAQ,EAAE;AAAA,EACrE;AACA,MAAI,aAAa,cAAc,QAAQ,KAAK,QAAQ,IAAI;AACtD,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,MAAI,SAAS,WAAW,kBAAkB,KAAK,QAAQ,GAAG;AACxD,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACF;","names":[]}
@@ -0,0 +1,8 @@
1
+ export { b0 as AnimationObject, b1 as AnimationObjectCallbacks, b2 as AnimationObjectCreateOptions } from '../spatializedElementMotion-_0XWPQCE.js';
2
+ export { validateSpatializedMotionConfig } from './compute/validate.js';
3
+ import '../types/motion/spatializedVisual.js';
4
+ import '../types/motion/spatializedPlayback.js';
5
+ import '../types/global.js';
6
+ import '../physicalMetrics-W5uZ5xKb.js';
7
+ import '../SpatialObject.js';
8
+ import '../reality/component/SpatialComponent.js';
@@ -0,0 +1,6 @@
1
+ export * from "./AnimationObject";
2
+ import { validateSpatializedMotionConfig } from "./compute/validate";
3
+ export {
4
+ validateSpatializedMotionConfig
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/motion/index.ts"],"sourcesContent":["export * from './AnimationObject'\nexport { validateSpatializedMotionConfig } from './compute/validate'\n"],"mappings":"AAAA,cAAc;AACd,SAAS,uCAAuC;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { a$ as NormalizedSpatializedMotionConfig, aO as SpatializedMotionTimeline } from '../../spatializedElementMotion-_0XWPQCE.js';
2
+ import '../../types/motion/spatializedVisual.js';
3
+ import '../../types/motion/spatializedPlayback.js';
4
+ import '../../types/global.js';
5
+ import '../../physicalMetrics-W5uZ5xKb.js';
6
+ import '../../SpatialObject.js';
7
+ import '../../reality/component/SpatialComponent.js';
8
+
9
+ /** Full timeline payload for native. */
10
+ declare function motionConfigToNativeTimeline(config: NormalizedSpatializedMotionConfig): SpatializedMotionTimeline;
11
+
12
+ export { motionConfigToNativeTimeline };
@@ -0,0 +1,21 @@
1
+ function motionConfigToNativeTimeline(config) {
2
+ return {
3
+ duration: config.duration,
4
+ delay: config.delay,
5
+ playbackRate: config.playbackRate,
6
+ loop: config.loop,
7
+ tracks: config.tracks.map((track) => ({
8
+ property: track.property,
9
+ keyframes: track.keyframes.map((k) => ({
10
+ at: k.at,
11
+ value: k.value,
12
+ ...k.timingFunction !== void 0 ? { timingFunction: k.timingFunction } : {}
13
+ })),
14
+ timingFunction: track.timingFunction ?? config.timingFunction ?? "linear"
15
+ }))
16
+ };
17
+ }
18
+ export {
19
+ motionConfigToNativeTimeline
20
+ };
21
+ //# sourceMappingURL=serializeMotionTimeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/motion/native/serializeMotionTimeline.ts"],"sourcesContent":["import type {\n NormalizedSpatializedMotionConfig,\n SpatializedMotionTimeline,\n} from '../../types/motion/spatializedMotion'\n\n/** Full timeline payload for native. */\nexport function motionConfigToNativeTimeline(\n config: NormalizedSpatializedMotionConfig,\n): SpatializedMotionTimeline {\n return {\n duration: config.duration,\n delay: config.delay,\n playbackRate: config.playbackRate,\n loop: config.loop,\n tracks: config.tracks.map(track => ({\n property: track.property,\n keyframes: track.keyframes.map(k => ({\n at: k.at,\n value: k.value,\n ...(k.timingFunction !== undefined\n ? { timingFunction: k.timingFunction }\n : {}),\n })),\n timingFunction: track.timingFunction ?? config.timingFunction ?? 'linear',\n })),\n }\n}\n"],"mappings":"AAMO,SAAS,6BACd,QAC2B;AAC3B,SAAO;AAAA,IACL,UAAU,OAAO;AAAA,IACjB,OAAO,OAAO;AAAA,IACd,cAAc,OAAO;AAAA,IACrB,MAAM,OAAO;AAAA,IACb,QAAQ,OAAO,OAAO,IAAI,YAAU;AAAA,MAClC,UAAU,MAAM;AAAA,MAChB,WAAW,MAAM,UAAU,IAAI,QAAM;AAAA,QACnC,IAAI,EAAE;AAAA,QACN,OAAO,EAAE;AAAA,QACT,GAAI,EAAE,mBAAmB,SACrB,EAAE,gBAAgB,EAAE,eAAe,IACnC,CAAC;AAAA,MACP,EAAE;AAAA,MACF,gBAAgB,MAAM,kBAAkB,OAAO,kBAAkB;AAAA,IACnE,EAAE;AAAA,EACJ;AACF;","names":[]}
@@ -0,0 +1,48 @@
1
+ type PhysicalMetricsValueShape = {
2
+ meterToPtUnscaled: number;
3
+ meterToPtScaled: number;
4
+ };
5
+ type WorldScalingCompensation = 'unscaled' | 'scaled';
6
+ type ConvertOption = {
7
+ worldScalingCompensation: WorldScalingCompensation;
8
+ };
9
+ /**
10
+ * Converts scene points (pt) to physical meters (m).
11
+ *
12
+ * @param point Points value to convert.
13
+ * @param options Optional conversion options to select world scaling compensation.
14
+ * @returns Physical length in meters.
15
+ */
16
+ declare function pointToPhysical(point: number, options?: ConvertOption): number;
17
+ /**
18
+ * Converts physical meters (m) to scene points (pt).
19
+ *
20
+ * @param physical Physical length in meters to convert.
21
+ * @param options Optional conversion options to select world scaling compensation.
22
+ * @returns Points length in the scene.
23
+ */
24
+ declare function physicalToPoint(physical: number, options?: ConvertOption): number;
25
+ /**
26
+ * Returns the current physical metrics used for conversions.
27
+ *
28
+ * @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.
29
+ */
30
+ declare function getValue(): PhysicalMetricsValueShape;
31
+ /**
32
+ * Subscribes to physical metrics changes.
33
+ *
34
+ * @param cb Callback invoked when metrics update is detected.
35
+ * @returns Unsubscribe function to remove the listener.
36
+ */
37
+ declare function subscribe(cb: () => void): () => void;
38
+
39
+ type physicalMetrics_PhysicalMetricsValueShape = PhysicalMetricsValueShape;
40
+ declare const physicalMetrics_getValue: typeof getValue;
41
+ declare const physicalMetrics_physicalToPoint: typeof physicalToPoint;
42
+ declare const physicalMetrics_pointToPhysical: typeof pointToPhysical;
43
+ declare const physicalMetrics_subscribe: typeof subscribe;
44
+ declare namespace physicalMetrics {
45
+ export { type physicalMetrics_PhysicalMetricsValueShape as PhysicalMetricsValueShape, physicalMetrics_getValue as getValue, physicalMetrics_physicalToPoint as physicalToPoint, physicalMetrics_pointToPhysical as pointToPhysical, physicalMetrics_subscribe as subscribe };
46
+ }
47
+
48
+ export { type PhysicalMetricsValueShape as P, physicalToPoint as a, pointToPhysical as b, getValue as g, physicalMetrics as p, subscribe as s };
@@ -0,0 +1 @@
1
+ export { P as PhysicalMetricsValueShape, g as getValue, a as physicalToPoint, b as pointToPhysical, s as subscribe } from './physicalMetrics-W5uZ5xKb.js';
@@ -0,0 +1,58 @@
1
+ import { SpatialWebEvent } from "./SpatialWebEvent";
2
+ let snapshot = {
3
+ meterToPtUnscaled: 1360,
4
+ meterToPtScaled: 1360
5
+ };
6
+ function getWorldScalingCompensation(options) {
7
+ return options?.worldScalingCompensation ?? "scaled";
8
+ }
9
+ function pointToPhysical(point, options) {
10
+ updateValue();
11
+ const compensation = getWorldScalingCompensation(options);
12
+ if (compensation === "unscaled") {
13
+ return point / snapshot.meterToPtUnscaled;
14
+ }
15
+ return point / snapshot.meterToPtScaled;
16
+ }
17
+ function physicalToPoint(physical, options) {
18
+ updateValue();
19
+ const compensation = getWorldScalingCompensation(options);
20
+ if (compensation === "unscaled") {
21
+ return physical * snapshot.meterToPtUnscaled;
22
+ }
23
+ return physical * snapshot.meterToPtScaled;
24
+ }
25
+ function updateValue() {
26
+ if (typeof window === "undefined") return;
27
+ const src = window.__webspatialsdk__?.physicalMetrics;
28
+ if (!src) return;
29
+ const next = {
30
+ meterToPtScaled: src.meterToPtScaled ?? snapshot.meterToPtScaled,
31
+ meterToPtUnscaled: src.meterToPtUnscaled ?? snapshot.meterToPtUnscaled
32
+ };
33
+ if (next.meterToPtScaled !== snapshot.meterToPtScaled || next.meterToPtUnscaled !== snapshot.meterToPtUnscaled) {
34
+ snapshot = next;
35
+ }
36
+ }
37
+ function getValue() {
38
+ updateValue();
39
+ return snapshot;
40
+ }
41
+ function subscribe(cb) {
42
+ if (typeof window === "undefined") return () => {
43
+ };
44
+ const handler = () => {
45
+ cb();
46
+ };
47
+ SpatialWebEvent.addEventReceiver("window", handler);
48
+ return () => {
49
+ SpatialWebEvent.removeEventReceiver("window");
50
+ };
51
+ }
52
+ export {
53
+ getValue,
54
+ physicalToPoint,
55
+ pointToPhysical,
56
+ subscribe
57
+ };
58
+ //# sourceMappingURL=physicalMetrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/physicalMetrics.ts"],"sourcesContent":["import { SpatialWebEvent } from './SpatialWebEvent'\nexport type PhysicalMetricsValueShape = {\n meterToPtUnscaled: number\n meterToPtScaled: number\n}\n\ntype WorldScalingCompensation = 'unscaled' | 'scaled'\n\ntype ConvertOption = { worldScalingCompensation: WorldScalingCompensation }\n\n// Fallback calibration: 1 meter ≈ 1360 pt for both scaled and unscaled modes.\n// This baseline ensures pointToPhysical(1360) === 1 and physicalToPoint(1) === 1360\n// until native physical metrics are injected into window.__webspatialsdk__.physicalMetrics\n// and a 'WebSpatialPhysicalMetricsUpdate' event updates the snapshot at runtime.\nlet snapshot: PhysicalMetricsValueShape = {\n meterToPtUnscaled: 1360,\n meterToPtScaled: 1360,\n}\n\nfunction getWorldScalingCompensation(options?: ConvertOption) {\n return options?.worldScalingCompensation ?? 'scaled' // default to scaled\n}\n\n/**\n * Converts scene points (pt) to physical meters (m).\n *\n * @param point Points value to convert.\n * @param options Optional conversion options to select world scaling compensation.\n * @returns Physical length in meters.\n */\nexport function pointToPhysical(point: number, options?: ConvertOption) {\n updateValue()\n const compensation = getWorldScalingCompensation(options)\n if (compensation === 'unscaled') {\n return point / snapshot.meterToPtUnscaled\n }\n return point / snapshot.meterToPtScaled\n}\n\n/**\n * Converts physical meters (m) to scene points (pt).\n *\n * @param physical Physical length in meters to convert.\n * @param options Optional conversion options to select world scaling compensation.\n * @returns Points length in the scene.\n */\nexport function physicalToPoint(physical: number, options?: ConvertOption) {\n updateValue()\n const compensation = getWorldScalingCompensation(options)\n if (compensation === 'unscaled') {\n return physical * snapshot.meterToPtUnscaled\n }\n return physical * snapshot.meterToPtScaled\n}\n\nfunction updateValue() {\n // ssr protected\n if (typeof window === 'undefined') return\n const src = window.__webspatialsdk__?.physicalMetrics\n if (!src) return\n const next = {\n meterToPtScaled: src.meterToPtScaled ?? snapshot.meterToPtScaled,\n meterToPtUnscaled: src.meterToPtUnscaled ?? snapshot.meterToPtUnscaled,\n }\n // only update if there is a change\n if (\n next.meterToPtScaled !== snapshot.meterToPtScaled ||\n next.meterToPtUnscaled !== snapshot.meterToPtUnscaled\n ) {\n snapshot = next\n }\n}\n\n/**\n * Returns the current physical metrics used for conversions.\n *\n * @returns The current metrics snapshot `{ meterToPtUnscaled, meterToPtScaled }`.\n */\nexport function getValue(): PhysicalMetricsValueShape {\n updateValue()\n return snapshot\n}\n\n/**\n * Subscribes to physical metrics changes.\n *\n * @param cb Callback invoked when metrics update is detected.\n * @returns Unsubscribe function to remove the listener.\n */\nexport function subscribe(cb: () => void) {\n // ssr protected\n if (typeof window === 'undefined') return () => {}\n const handler = () => {\n cb()\n }\n // receive metrics update from native via SpatialWebEvent, id: \"window\"\n SpatialWebEvent.addEventReceiver('window', handler)\n return () => {\n SpatialWebEvent.removeEventReceiver('window')\n }\n}\n"],"mappings":"AAAA,SAAS,uBAAuB;AAchC,IAAI,WAAsC;AAAA,EACxC,mBAAmB;AAAA,EACnB,iBAAiB;AACnB;AAEA,SAAS,4BAA4B,SAAyB;AAC5D,SAAO,SAAS,4BAA4B;AAC9C;AASO,SAAS,gBAAgB,OAAe,SAAyB;AACtE,cAAY;AACZ,QAAM,eAAe,4BAA4B,OAAO;AACxD,MAAI,iBAAiB,YAAY;AAC/B,WAAO,QAAQ,SAAS;AAAA,EAC1B;AACA,SAAO,QAAQ,SAAS;AAC1B;AASO,SAAS,gBAAgB,UAAkB,SAAyB;AACzE,cAAY;AACZ,QAAM,eAAe,4BAA4B,OAAO;AACxD,MAAI,iBAAiB,YAAY;AAC/B,WAAO,WAAW,SAAS;AAAA,EAC7B;AACA,SAAO,WAAW,SAAS;AAC7B;AAEA,SAAS,cAAc;AAErB,MAAI,OAAO,WAAW,YAAa;AACnC,QAAM,MAAM,OAAO,mBAAmB;AACtC,MAAI,CAAC,IAAK;AACV,QAAM,OAAO;AAAA,IACX,iBAAiB,IAAI,mBAAmB,SAAS;AAAA,IACjD,mBAAmB,IAAI,qBAAqB,SAAS;AAAA,EACvD;AAEA,MACE,KAAK,oBAAoB,SAAS,mBAClC,KAAK,sBAAsB,SAAS,mBACpC;AACA,eAAW;AAAA,EACb;AACF;AAOO,SAAS,WAAsC;AACpD,cAAY;AACZ,SAAO;AACT;AAQO,SAAS,UAAU,IAAgB;AAExC,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AACjD,QAAM,UAAU,MAAM;AACpB,OAAG;AAAA,EACL;AAEA,kBAAgB,iBAAiB,UAAU,OAAO;AAClD,SAAO,MAAM;AACX,oBAAgB,oBAAoB,QAAQ;AAAA,EAC9C;AACF;","names":[]}
@@ -0,0 +1,12 @@
1
+ import { aK as CommandResult } from '../spatializedElementMotion-_0XWPQCE.js';
2
+ import '../types/motion/spatializedVisual.js';
3
+ import '../types/motion/spatializedPlayback.js';
4
+ import '../types/global.js';
5
+ import '../physicalMetrics-W5uZ5xKb.js';
6
+ import '../SpatialObject.js';
7
+ import '../reality/component/SpatialComponent.js';
8
+
9
+ declare function CommandResultSuccess<TData>(data: TData): CommandResult<TData>;
10
+ declare function CommandResultFailure(errorCode: string, errorMessage?: string): CommandResult<undefined>;
11
+
12
+ export { CommandResultFailure, CommandResultSuccess };
@@ -0,0 +1,21 @@
1
+ function CommandResultSuccess(data) {
2
+ return {
3
+ success: true,
4
+ data,
5
+ errorCode: "",
6
+ errorMessage: ""
7
+ };
8
+ }
9
+ function CommandResultFailure(errorCode, errorMessage = "") {
10
+ return {
11
+ success: false,
12
+ data: void 0,
13
+ errorCode,
14
+ errorMessage
15
+ };
16
+ }
17
+ export {
18
+ CommandResultFailure,
19
+ CommandResultSuccess
20
+ };
21
+ //# sourceMappingURL=CommandResultUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/platform-adapter/CommandResultUtils.ts"],"sourcesContent":["import { CommandResult } from './interface'\n\nexport function CommandResultSuccess<TData>(data: TData): CommandResult<TData> {\n return {\n success: true,\n data,\n errorCode: '',\n errorMessage: '',\n }\n}\n\nexport function CommandResultFailure(\n errorCode: string,\n errorMessage = '',\n): CommandResult<undefined> {\n return {\n success: false,\n data: undefined,\n errorCode,\n errorMessage,\n }\n}\n"],"mappings":"AAEO,SAAS,qBAA4B,MAAmC;AAC7E,SAAO;AAAA,IACL,SAAS;AAAA,IACT;AAAA,IACA,WAAW;AAAA,IACX,cAAc;AAAA,EAChB;AACF;AAEO,SAAS,qBACd,WACA,eAAe,IACW;AAC1B,SAAO;AAAA,IACL,SAAS;AAAA,IACT,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,16 @@
1
+ import { aY as PlatformAbility } from '../spatializedElementMotion-_0XWPQCE.js';
2
+ import '../types/motion/spatializedVisual.js';
3
+ import '../types/motion/spatializedPlayback.js';
4
+ import '../types/global.js';
5
+ import '../physicalMetrics-W5uZ5xKb.js';
6
+ import '../SpatialObject.js';
7
+ import '../reality/component/SpatialComponent.js';
8
+
9
+ /**
10
+ * Construct the JSB platform synchronously (static imports).
11
+ * Used by getPlatformSync (e.g. scene-polyfill openSpatialSceneSync) and kept
12
+ * consistent with async createPlatform so paths share one implementation.
13
+ */
14
+ declare function createPlatformSync(): PlatformAbility;
15
+
16
+ export { createPlatformSync };
@@ -0,0 +1,30 @@
1
+ import { resolveJsbAdapterPlatform } from "../runtime/jsbAdapterPlatform";
2
+ import { isSSREnv } from "../isSSREnv";
3
+ import { PicoOSPlatform } from "./pico-os/PicoOSPlatform";
4
+ import { PuppeteerPlatform } from "./puppeteer/PuppeteerPlatform";
5
+ import { VisionOSPlatform } from "./vision-os/VisionOSPlatform";
6
+ const SSR_PLATFORM_ERROR = "WebSpatial platform APIs (JSB / openSpatialScene) cannot run during SSR or without window. Use @webspatial/react-sdk default entry with facades, or CSR-gate spatial UI on the client.";
7
+ function assertNever(_) {
8
+ throw new Error("Unhandled jsb adapter platform kind");
9
+ }
10
+ function createPlatformSync() {
11
+ if (isSSREnv()) {
12
+ throw new Error(SSR_PLATFORM_ERROR);
13
+ }
14
+ const userAgent = window.navigator.userAgent;
15
+ const kind = resolveJsbAdapterPlatform(userAgent);
16
+ switch (kind) {
17
+ case "puppeteer":
18
+ return new PuppeteerPlatform();
19
+ case "picoos":
20
+ return new PicoOSPlatform();
21
+ case "visionos":
22
+ return new VisionOSPlatform();
23
+ default:
24
+ return assertNever(kind);
25
+ }
26
+ }
27
+ export {
28
+ createPlatformSync
29
+ };
30
+ //# sourceMappingURL=createPlatformSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/platform-adapter/createPlatformSync.ts"],"sourcesContent":["import { resolveJsbAdapterPlatform } from '../runtime/jsbAdapterPlatform'\nimport { isSSREnv } from '../isSSREnv'\nimport { PlatformAbility } from './interface'\nimport { PicoOSPlatform } from './pico-os/PicoOSPlatform'\nimport { PuppeteerPlatform } from './puppeteer/PuppeteerPlatform'\nimport { VisionOSPlatform } from './vision-os/VisionOSPlatform'\n\nconst SSR_PLATFORM_ERROR =\n 'WebSpatial platform APIs (JSB / openSpatialScene) cannot run during SSR or without window. Use @webspatial/react-sdk default entry with facades, or CSR-gate spatial UI on the client.'\n\nfunction assertNever(_: never): never {\n throw new Error('Unhandled jsb adapter platform kind')\n}\n\n/**\n * Construct the JSB platform synchronously (static imports).\n * Used by getPlatformSync (e.g. scene-polyfill openSpatialSceneSync) and kept\n * consistent with async createPlatform so paths share one implementation.\n */\nexport function createPlatformSync(): PlatformAbility {\n if (isSSREnv()) {\n throw new Error(SSR_PLATFORM_ERROR)\n }\n const userAgent = window.navigator.userAgent\n const kind = resolveJsbAdapterPlatform(userAgent)\n switch (kind) {\n case 'puppeteer':\n return new PuppeteerPlatform()\n case 'picoos':\n return new PicoOSPlatform()\n case 'visionos':\n return new VisionOSPlatform()\n default:\n return assertNever(kind)\n }\n}\n"],"mappings":"AAAA,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAEjC,MAAM,qBACJ;AAEF,SAAS,YAAY,GAAiB;AACpC,QAAM,IAAI,MAAM,qCAAqC;AACvD;AAOO,SAAS,qBAAsC;AACpD,MAAI,SAAS,GAAG;AACd,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AACA,QAAM,YAAY,OAAO,UAAU;AACnC,QAAM,OAAO,0BAA0B,SAAS;AAChD,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,IAAI,kBAAkB;AAAA,IAC/B,KAAK;AACH,aAAO,IAAI,eAAe;AAAA,IAC5B,KAAK;AACH,aAAO,IAAI,iBAAiB;AAAA,IAC9B;AACE,aAAO,YAAY,IAAI;AAAA,EAC3B;AACF;","names":[]}
@@ -0,0 +1,12 @@
1
+ export { createPlatformSync } from './createPlatformSync.js';
2
+ import { aY as PlatformAbility } from '../spatializedElementMotion-_0XWPQCE.js';
3
+ import '../types/motion/spatializedVisual.js';
4
+ import '../types/motion/spatializedPlayback.js';
5
+ import '../types/global.js';
6
+ import '../physicalMetrics-W5uZ5xKb.js';
7
+ import '../SpatialObject.js';
8
+ import '../reality/component/SpatialComponent.js';
9
+
10
+ declare function createPlatform(): Promise<PlatformAbility>;
11
+
12
+ export { createPlatform };
@@ -0,0 +1,10 @@
1
+ import { createPlatformSync } from "./createPlatformSync";
2
+ import { createPlatformSync as createPlatformSync2 } from "./createPlatformSync";
3
+ async function createPlatform() {
4
+ return createPlatformSync2();
5
+ }
6
+ export {
7
+ createPlatform,
8
+ createPlatformSync
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/platform-adapter/index.ts"],"sourcesContent":["export { createPlatformSync } from './createPlatformSync'\nimport { createPlatformSync } from './createPlatformSync'\nimport type { PlatformAbility } from './interface'\n\nexport async function createPlatform(): Promise<PlatformAbility> {\n return createPlatformSync()\n}\n"],"mappings":"AAAA,SAAS,0BAA0B;AACnC,SAAS,sBAAAA,2BAA0B;AAGnC,eAAsB,iBAA2C;AAC/D,SAAOA,oBAAmB;AAC5B;","names":["createPlatformSync"]}
@@ -0,0 +1,7 @@
1
+ export { aK as CommandResult, aY as PlatformAbility, aZ as WebSpatialProtocolResult } from '../spatializedElementMotion-_0XWPQCE.js';
2
+ import '../types/motion/spatializedVisual.js';
3
+ import '../types/motion/spatializedPlayback.js';
4
+ import '../types/global.js';
5
+ import '../physicalMetrics-W5uZ5xKb.js';
6
+ import '../SpatialObject.js';
7
+ import '../reality/component/SpatialComponent.js';
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,25 @@
1
+ import { aY as PlatformAbility, aK as CommandResult, aQ as SpatialSceneCreationOptionsInternal, aZ as WebSpatialProtocolResult, h as AttachmentEntityOptions } from '../../spatializedElementMotion-_0XWPQCE.js';
2
+ import '../../types/motion/spatializedVisual.js';
3
+ import '../../types/motion/spatializedPlayback.js';
4
+ import '../../types/global.js';
5
+ import '../../physicalMetrics-W5uZ5xKb.js';
6
+ import '../../SpatialObject.js';
7
+ import '../../reality/component/SpatialComponent.js';
8
+
9
+ declare class PicoOSPlatform implements PlatformAbility {
10
+ callJSB(cmd: string, msg: string): Promise<CommandResult>;
11
+ openSpatialSceneSync(url: string, config: SpatialSceneCreationOptionsInternal | undefined, target?: string, features?: string): WebSpatialProtocolResult;
12
+ createNativeSpatialDiv(): Promise<WebSpatialProtocolResult>;
13
+ createNativeAttachment(_options?: AttachmentEntityOptions): Promise<WebSpatialProtocolResult>;
14
+ /**
15
+ * Async path for createNativeSpatialDiv / createNativeAttachment: open webspatial URL
16
+ * with rid= correlation (Pico OS 6).
17
+ */
18
+ private waitForRidProtocolAsync;
19
+ private openWindow;
20
+ private parseBridgeResponse;
21
+ private toCommandResult;
22
+ private parseJSBError;
23
+ }
24
+
25
+ export { PicoOSPlatform };
@@ -0,0 +1,168 @@
1
+ import {
2
+ CommandResultFailure,
3
+ CommandResultSuccess
4
+ } from "../CommandResultUtils";
5
+ import { buildSpatialSceneQuery } from "../spatialSceneQuery";
6
+ import { SpatialWebEvent } from "../../SpatialWebEvent";
7
+ import {
8
+ buildSpatialRequestQuery,
9
+ createSpatialRequestId,
10
+ DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS
11
+ } from "../spatialRequestMetadata";
12
+ let requestId = 0;
13
+ const MAX_ID = 1e5;
14
+ const DEFAULT_JSB_ERROR_CODE = "E_PICO_JSB";
15
+ const DEFAULT_JSB_ERROR_MESSAGE = "Pico JSB execution failed";
16
+ function nextRequestId() {
17
+ requestId = (requestId + 1) % MAX_ID;
18
+ return `rId_${requestId}`;
19
+ }
20
+ class PicoOSPlatform {
21
+ async callJSB(cmd, msg) {
22
+ return new Promise((resolve) => {
23
+ try {
24
+ const rId = nextRequestId();
25
+ SpatialWebEvent.addEventReceiver(rId, (result) => {
26
+ SpatialWebEvent.removeEventReceiver(rId);
27
+ resolve(this.toCommandResult(result));
28
+ });
29
+ const ans = window.webspatialBridge.postMessage(rId, cmd, msg);
30
+ if (ans !== "") {
31
+ SpatialWebEvent.removeEventReceiver(rId);
32
+ resolve(this.parseBridgeResponse(ans));
33
+ }
34
+ } catch (error) {
35
+ console.error(`SwanPlatform cmd: ${cmd}, msg: ${msg} error: ${error}`);
36
+ const { code, message } = this.parseJSBError(error);
37
+ resolve(CommandResultFailure(code, message));
38
+ }
39
+ });
40
+ }
41
+ openSpatialSceneSync(url, config, target, features) {
42
+ const query = buildSpatialSceneQuery(url, config);
43
+ const { spatialId: id = "", windowProxy } = this.openWindow(
44
+ "createSpatialScene",
45
+ query,
46
+ target,
47
+ features
48
+ );
49
+ return CommandResultSuccess({ windowProxy, id });
50
+ }
51
+ createNativeSpatialDiv() {
52
+ return this.waitForRidProtocolAsync("createSpatialized2DElement");
53
+ }
54
+ createNativeAttachment(_options) {
55
+ return this.waitForRidProtocolAsync("createAttachment");
56
+ }
57
+ /**
58
+ * Async path for createNativeSpatialDiv / createNativeAttachment: open webspatial URL
59
+ * with rid= correlation (Pico OS 6).
60
+ */
61
+ waitForRidProtocolAsync(command) {
62
+ return new Promise((resolve) => {
63
+ const createdId = createSpatialRequestId();
64
+ let settled = false;
65
+ let timeoutId;
66
+ let cleanupDocumentReadyListener;
67
+ const settle = (result) => {
68
+ if (settled) return;
69
+ settled = true;
70
+ if (timeoutId !== void 0) {
71
+ clearTimeout(timeoutId);
72
+ }
73
+ cleanupDocumentReadyListener?.();
74
+ cleanupDocumentReadyListener = void 0;
75
+ SpatialWebEvent.removeEventReceiver(createdId);
76
+ resolve(result);
77
+ };
78
+ try {
79
+ let windowProxy = null;
80
+ const settleWhenDocumentComplete = (spatialId) => {
81
+ const successResult = CommandResultSuccess({
82
+ windowProxy,
83
+ id: spatialId
84
+ });
85
+ const childDocument = windowProxy?.document;
86
+ if (!childDocument) {
87
+ settle(
88
+ CommandResultFailure(
89
+ "E_SPATIAL_DOCUMENT_UNAVAILABLE",
90
+ `${command} document is unavailable`
91
+ )
92
+ );
93
+ return;
94
+ }
95
+ if (childDocument.readyState === "complete") {
96
+ settle(successResult);
97
+ return;
98
+ }
99
+ const onReadyStateChange = () => {
100
+ if (childDocument.readyState !== "complete") return;
101
+ settle(successResult);
102
+ };
103
+ cleanupDocumentReadyListener = () => {
104
+ childDocument.removeEventListener(
105
+ "readystatechange",
106
+ onReadyStateChange
107
+ );
108
+ };
109
+ childDocument.addEventListener("readystatechange", onReadyStateChange);
110
+ };
111
+ timeoutId = setTimeout(() => {
112
+ settle(
113
+ CommandResultFailure(
114
+ "E_SPATIAL_REQUEST_TIMEOUT",
115
+ `${command} request timed out`
116
+ )
117
+ );
118
+ }, DEFAULT_SPATIAL_REQUEST_TIMEOUT_MS);
119
+ SpatialWebEvent.addEventReceiver(
120
+ createdId,
121
+ (result) => {
122
+ settleWhenDocumentComplete(result.spatialId);
123
+ }
124
+ );
125
+ windowProxy = this.openWindow(
126
+ command,
127
+ buildSpatialRequestQuery(createdId)
128
+ ).windowProxy;
129
+ } catch (error) {
130
+ const { code, message } = this.parseJSBError(error);
131
+ settle(CommandResultFailure(code, message));
132
+ }
133
+ });
134
+ }
135
+ openWindow(command, query, target, features) {
136
+ const url = query ? `webspatial://${command}?${query}` : `webspatial://${command}`;
137
+ const windowProxy = window.open(url, target, features);
138
+ return { spatialId: "", windowProxy };
139
+ }
140
+ parseBridgeResponse(ans) {
141
+ try {
142
+ const result = JSON.parse(ans);
143
+ return this.toCommandResult(result);
144
+ } catch {
145
+ return CommandResultFailure(
146
+ DEFAULT_JSB_ERROR_CODE,
147
+ "Invalid Pico JSB response payload"
148
+ );
149
+ }
150
+ }
151
+ toCommandResult(result) {
152
+ if (result.success) {
153
+ return CommandResultSuccess(result.data);
154
+ }
155
+ const { code, message } = this.parseJSBError(result.data);
156
+ return CommandResultFailure(code, message);
157
+ }
158
+ parseJSBError(error) {
159
+ return {
160
+ code: error?.code ?? DEFAULT_JSB_ERROR_CODE,
161
+ message: error?.message ?? (typeof error === "string" ? error : DEFAULT_JSB_ERROR_MESSAGE)
162
+ };
163
+ }
164
+ }
165
+ export {
166
+ PicoOSPlatform
167
+ };
168
+ //# sourceMappingURL=PicoOSPlatform.js.map