@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,224 @@
1
+ import type { Vec3 } from './types'
2
+
3
+ // ---- Timing function ----
4
+
5
+ export type TimingFunction = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
6
+
7
+ // ---- Transform values ----
8
+
9
+ /**
10
+ * Transform values used in animation callbacks (`onComplete`, `onCancel`).
11
+ * Rotation values are Euler angles in **degrees**, matching the input convention
12
+ * of `AnimationConfig` and the entity `rotation` prop.
13
+ */
14
+ export interface TransformValues {
15
+ position?: Vec3
16
+ rotation?: Vec3
17
+ scale?: Vec3
18
+ }
19
+
20
+ // ---- Play state ----
21
+
22
+ /**
23
+ * Represents the current state of an animation session as exposed by
24
+ * `api.playState`. The internal `delaying` state maps to `'running'`
25
+ * because from the developer's perspective the session is actively progressing.
26
+ */
27
+ export type AnimationPlayState =
28
+ | 'idle'
29
+ | 'queued'
30
+ | 'running'
31
+ | 'paused'
32
+ | 'finished'
33
+
34
+ // ---- Animation config ----
35
+
36
+ /**
37
+ * Configuration for `useAnimation`.
38
+ *
39
+ * `to` is required and declares which transform fields are animated.
40
+ * `from` is optional; omitting it causes the native layer to snapshot
41
+ * the entity's current transform at playback time.
42
+ */
43
+ export interface AnimationConfig {
44
+ /**
45
+ * Target transform values (required).
46
+ * Rotation values are Euler angles in degrees.
47
+ * Single-axis rotation > 180 deg may produce unexpected results (shortest-path SLERP).
48
+ */
49
+ to: TransformValues
50
+
51
+ /** Starting transform values. Omit to animate from the entity's current state. */
52
+ from?: TransformValues
53
+
54
+ /** Duration in seconds. Default: 0.3 */
55
+ duration?: number
56
+
57
+ /**
58
+ * Easing curve. Default: 'easeInOut'
59
+ * Only these four values are valid; other strings will throw at validation time.
60
+ */
61
+ timingFunction?: TimingFunction
62
+
63
+ /** Delay before playback starts, in seconds. Default: 0 */
64
+ delay?: number
65
+
66
+ /** Start automatically when the entity mounts. Default: true */
67
+ autoStart?: boolean
68
+
69
+ /**
70
+ * Loop behavior.
71
+ * - true: reset to `from` and replay (infinite reset loop)
72
+ * - { reverse: true }: alternate direction each cycle (infinite reverse loop)
73
+ * - undefined / false: play once
74
+ */
75
+ loop?: boolean | { reverse?: boolean }
76
+
77
+ /**
78
+ * Playback speed multiplier. Default: 1
79
+ * Values > 1 speed up; values between 0 and 1 slow down.
80
+ * Must be a positive finite number (> 0).
81
+ * Applied at session creation time and remains constant for the session.
82
+ * Maps to AnimationView.speed on the native (AVP) side.
83
+ */
84
+ playbackRate?: number
85
+
86
+ /** Called when the session is established successfully. */
87
+ onStart?: () => void
88
+
89
+ /** Called when a non-looping animation finishes naturally. */
90
+ onComplete?: (finalValues: TransformValues) => void
91
+
92
+ /** Called when playback is canceled via api.cancel(). Receives the restored transform. */
93
+ onCancel?: (currentValues: TransformValues) => void
94
+
95
+ /**
96
+ * Called when an asynchronous error occurs during a bridge or native operation.
97
+ * If not provided, the SDK logs the error via console.error.
98
+ */
99
+ onError?: (error: AnimationError) => void
100
+ }
101
+
102
+ // ---- Animation error ----
103
+
104
+ export interface AnimationError {
105
+ /** The session that encountered the error. */
106
+ animationId: string
107
+ /** The command that failed. */
108
+ command: 'play' | 'pause' | 'resume' | 'cancel'
109
+ /** Optional machine-readable error code. */
110
+ code?: string
111
+ /** Human-readable failure reason. */
112
+ reason: string
113
+ }
114
+
115
+ // ---- Animation API (returned by useAnimation) ----
116
+
117
+ export interface AnimationApi {
118
+ /** Start the animation, or continue it from paused progress. */
119
+ play(): void
120
+
121
+ /** Pause the animation at the current progress. */
122
+ pause(): void
123
+
124
+ /** Cancel the animation and restore `from`, or the start snapshot when `from` is omitted. */
125
+ cancel(): void
126
+
127
+ /** Whether the session is currently queued, delaying, or running (false while paused or idle). */
128
+ readonly isAnimating: boolean
129
+
130
+ /** Whether the animation is currently paused. */
131
+ readonly isPaused: boolean
132
+
133
+ /** Current session state. */
134
+ readonly playState: AnimationPlayState
135
+
136
+ /** Whether the most recent current session completed naturally. */
137
+ readonly finished: boolean
138
+ }
139
+
140
+ // ---- Animated props (opaque, passed to entity `animation` prop) ----
141
+
142
+ /**
143
+ * Opaque object returned as the first tuple element of `useAnimation`.
144
+ * Pass it directly to the entity's `animation` prop.
145
+ * Application code should not read or modify its internal fields.
146
+ */
147
+ export interface AnimatedProps {
148
+ /** @internal Unique identifier for this animation object. */
149
+ readonly __animationObjectId: string
150
+ /** @internal Transform fields targeted by this animation. */
151
+ readonly __animatedFields: readonly ('position' | 'rotation' | 'scale')[]
152
+ /** @internal Whether the animation currently has an alive session. */
153
+ readonly __animating: boolean
154
+ }
155
+
156
+ // ---- Cross-layer command / result ----
157
+
158
+ /**
159
+ * Float4x4 is a 16-element column-major matrix stored in a Float64Array,
160
+ * matching `DOMMatrix.toFloat64Array()`.
161
+ */
162
+ export type Float4x4 = Float64Array
163
+
164
+ /**
165
+ * Unified command sent from React SDK -> Core SDK -> native.
166
+ */
167
+ export interface AnimateTransformCommand {
168
+ /**
169
+ * Unique session identifier. A new `animationId` is generated for each
170
+ * `play` command; `pause`, `resume`, and `stop` reuse the session's id.
171
+ */
172
+ animationId: string
173
+ type: 'play' | 'pause' | 'resume' | 'cancel'
174
+ /** Required when type is 'play'; ignored otherwise. */
175
+ entityId?: string
176
+ toTransform?: Float4x4
177
+ fromTransform?: Float4x4
178
+ duration?: number
179
+ timingFunction?: TimingFunction
180
+ delay?: number
181
+ loop?: boolean | { reverse?: boolean }
182
+ /** Playback speed multiplier. Default: 1. Must be positive (> 0). Maps to AnimationView.speed on AVP. */
183
+ playbackRate?: number
184
+ }
185
+
186
+ /**
187
+ * Result returned by `SpatialEntity.animateTransform({ type: 'play' })`.
188
+ */
189
+ export interface AnimateTransformResult {
190
+ animationId: string
191
+ /** Resolves when a non-looping animation completes naturally. */
192
+ finished: Promise<TransformValues>
193
+ /**
194
+ * Resolves when the animation is canceled and restored to `from`.
195
+ * After cancel, `finished` MUST remain pending (not rejected).
196
+ */
197
+ canceled: Promise<TransformValues>
198
+ /**
199
+ * Resolves when the animation fails due to a native or bridge error.
200
+ * Optional because older native runtimes may not emit the failed event.
201
+ */
202
+ failed?: Promise<AnimationError>
203
+ }
204
+
205
+ // ---- Internal animated props (cross-layer communication) ----
206
+
207
+ /**
208
+ * @internal
209
+ * Extended interface for `AnimatedProps` used internally by the entity layer
210
+ * to bind/unbind animations and query suppressed transform fields.
211
+ * Application code should never use this interface directly.
212
+ */
213
+ export interface AnimatedPropsInternal extends AnimatedProps {
214
+ /** Called by the entity layer when the entity instance becomes available. */
215
+ __bind: (
216
+ entity: import('../reality/entity/SpatialEntity').SpatialEntity,
217
+ ) => void
218
+ /** Called by the entity layer when the entity is destroyed or animation prop changes. */
219
+ __unbind: () => void
220
+ /** Returns the transform fields currently suppressed by an alive animation session. */
221
+ __getSuppressedFields: () =>
222
+ | readonly ('position' | 'rotation' | 'scale')[]
223
+ | null
224
+ }
@@ -1,14 +1,8 @@
1
1
  import type { PhysicalMetricsValueShape } from '../physicalMetrics'
2
-
3
2
  declare global {
4
- declare const __WEBSPATIAL_CORE_SDK_VERSION__: string
3
+ const __WEBSPATIAL_CORE_SDK_VERSION__: string
5
4
 
6
5
  interface Window {
7
- xrCurrentSceneType: SpatialSceneType
8
- xrCurrentSceneDefaults: (
9
- defaultConfig: SpatialSceneCreationOptions,
10
- ) => Promise<SpatialSceneCreationOptions>
11
-
12
6
  // Location for webspatial custom functions
13
7
  __WebSpatialData: {
14
8
  androidNativeMessage: Function
@@ -34,20 +28,24 @@ declare global {
34
28
  WebSpatailNativeVersion: string
35
29
 
36
30
  __webspatialsdk__?: {
37
- XR_ENV?: string
38
31
  'natvie-version'?: string
39
32
  'react-sdk-version'?: string
40
33
  'core-sdk-version'?: string
41
34
  physicalMetrics?: PhysicalMetricsValueShape
35
+ pageEpoch?: string | number
42
36
  }
43
37
 
44
- xrInnerDepth: number
45
- xrOuterDepth: number
38
+ /** Present when `supports('xrInnerDepth')` is true; otherwise `undefined`. */
39
+ xrInnerDepth?: number
40
+ /** Present when `supports('xrOuterDepth')` is true; otherwise `undefined`. */
41
+ xrOuterDepth?: number
46
42
  }
47
43
 
48
44
  interface HTMLElement {
49
- xrOffsetBack: number
50
- xrClientDepth: number
45
+ /** Present when `supports('xrOffsetBack')` is true for element readbacks. */
46
+ xrOffsetBack?: number
47
+ /** Present when `supports('xrClientDepth')` is true for element readbacks. */
48
+ xrClientDepth?: number
51
49
  }
52
50
  }
53
51
 
@@ -0,0 +1,10 @@
1
+ export * from './spatializedVisual'
2
+ export * from './spatializedPlayback'
3
+ export type {
4
+ SpatializedMotionKind,
5
+ SpatializedMotionSegmentConfig,
6
+ SpatializedMotionTimelineConfig,
7
+ SpatializedMotionConfig,
8
+ SpatializedMotionPlayState,
9
+ SpatializedPlaybackApi,
10
+ } from './spatializedMotion'
@@ -0,0 +1,49 @@
1
+ import type { SpatializedMotionTimeline } from './spatializedMotion'
2
+ import type { SpatializedMotionPlayState } from './spatializedMotion'
3
+ import type { SpatializedVisualValues } from './spatializedVisual'
4
+ import type { SpatialWebMsgType } from '../../WebMsgCommand'
5
+
6
+ /** Native playback error payload carried by the bridge event. */
7
+ interface SpatializedElementAnimationErrorDetail {
8
+ /** Machine-readable native error code. */
9
+ code: string
10
+ /** Human-readable native error message. */
11
+ message: string
12
+ }
13
+
14
+ export interface CreateSpatializedElementAnimationCommand {
15
+ elementId: string
16
+ timeline: SpatializedMotionTimeline
17
+ }
18
+
19
+ export type SpatializedElementAnimationControlType =
20
+ | 'play'
21
+ | 'pause'
22
+ | 'resume'
23
+ | 'stop'
24
+ | 'reset'
25
+ | 'finish'
26
+ | 'destroy'
27
+
28
+ export interface ControlSpatializedElementAnimationCommand {
29
+ animationId: string
30
+ type: SpatializedElementAnimationControlType
31
+ }
32
+
33
+ export interface SpatialAnimationStateChangedDetail {
34
+ animationId: string
35
+ action:
36
+ | SpatializedElementAnimationControlType
37
+ | 'start'
38
+ | 'complete'
39
+ | 'error'
40
+ playState: SpatializedMotionPlayState
41
+ finished: boolean
42
+ values?: SpatializedVisualValues
43
+ error?: SpatializedElementAnimationErrorDetail
44
+ }
45
+
46
+ export interface SpatialAnimationStateChangedMsg {
47
+ type: SpatialWebMsgType.animationstatechange
48
+ detail: SpatialAnimationStateChangedDetail
49
+ }
@@ -0,0 +1,147 @@
1
+ import type { TimingFunction } from '../animation'
2
+ import type { SpatializedPlaybackError } from './spatializedPlayback'
3
+ import type { SpatializedVisualValues } from './spatializedVisual'
4
+
5
+ /** Spatialized container kinds with declarative timeline motion. */
6
+ export type SpatializedMotionKind = 'spatialized2d' | 'static3d' | 'dynamic3d'
7
+
8
+ /** Scalar property path on the spatialized visual whitelist. */
9
+ export const SPATIALIZED_MOTION_PROPERTIES = [
10
+ 'opacity',
11
+ 'transform.translate.x',
12
+ 'transform.translate.y',
13
+ 'transform.translate.z',
14
+ 'transform.rotate.x',
15
+ 'transform.rotate.y',
16
+ 'transform.rotate.z',
17
+ 'transform.scale.x',
18
+ 'transform.scale.y',
19
+ 'transform.scale.z',
20
+ ] as const
21
+
22
+ export type SpatializedMotionProperty =
23
+ (typeof SPATIALIZED_MOTION_PROPERTIES)[number]
24
+
25
+ export interface SpatializedMotionKeyframe {
26
+ /** Time in seconds from timeline start, in `[0, duration]`. */
27
+ at: number
28
+ value: number
29
+ timingFunction?: TimingFunction
30
+ }
31
+
32
+ export type SpatializedMotionKeyframeValues = SpatializedVisualValues & {
33
+ timingFunction?: TimingFunction
34
+ }
35
+
36
+ /** One animatable property path and its keyframes (config-only, not a runtime handle). */
37
+ export interface SpatializedMotionTrack {
38
+ property: SpatializedMotionProperty
39
+ keyframes: SpatializedMotionKeyframe[]
40
+ timingFunction?: TimingFunction
41
+ }
42
+
43
+ /** Single-segment motion: `from` → `to` over `duration`. */
44
+ export interface SpatializedMotionSegmentConfig {
45
+ to: SpatializedVisualValues
46
+ from: SpatializedVisualValues
47
+ tracks?: never
48
+ timeline?: never
49
+ duration?: number
50
+ timingFunction?: TimingFunction
51
+ delay?: number
52
+ autoStart?: boolean
53
+ loop?: boolean | { reverse?: boolean }
54
+ playbackRate?: number
55
+ onStart?: () => void
56
+ onComplete?: (values: SpatializedVisualValues) => void
57
+ onStop?: (values: SpatializedVisualValues) => void
58
+ onReset?: (values: SpatializedVisualValues) => void
59
+ onError?: (error: SpatializedPlaybackError) => void
60
+ }
61
+
62
+ /** Percentage-keyframe timeline authoring shape before desugaring. */
63
+ export interface SpatializedMotionTimelineConfig {
64
+ duration?: number
65
+ timeline: Record<string, SpatializedMotionKeyframeValues>
66
+ /** Ignored when timeline authoring is present. */
67
+ from?: SpatializedVisualValues
68
+ /** Ignored when timeline authoring is present. */
69
+ to?: SpatializedVisualValues
70
+ tracks?: never
71
+ timingFunction?: TimingFunction
72
+ delay?: number
73
+ autoStart?: boolean
74
+ loop?: boolean | { reverse?: boolean }
75
+ playbackRate?: number
76
+ onStart?: () => void
77
+ onComplete?: (values: SpatializedVisualValues) => void
78
+ onStop?: (values: SpatializedVisualValues) => void
79
+ onReset?: (values: SpatializedVisualValues) => void
80
+ onError?: (error: SpatializedPlaybackError) => void
81
+ }
82
+
83
+ /** Public authoring accepted by spatialized container motion. */
84
+ export type SpatializedMotionConfig =
85
+ | SpatializedMotionSegmentConfig
86
+ | SpatializedMotionTimelineConfig
87
+
88
+ /** Canonical internal track document produced before native create. */
89
+ export interface NormalizedSpatializedMotionConfig {
90
+ /** Timeline duration in seconds. */
91
+ duration: number
92
+ /** Canonical per-property numeric tracks. */
93
+ tracks: SpatializedMotionTrack[]
94
+ /** Default interpolation for tracks without an override. */
95
+ timingFunction?: TimingFunction
96
+ /** Playback delay in seconds. */
97
+ delay?: number
98
+ /** Whether playback starts automatically after binding. */
99
+ autoStart?: boolean
100
+ /** Loop behavior for the animation session. */
101
+ loop?: boolean | { reverse?: boolean }
102
+ /** Playback speed multiplier. */
103
+ playbackRate?: number
104
+ /** Called when playback starts. */
105
+ onStart?: () => void
106
+ /** Called when playback completes. */
107
+ onComplete?: (values: SpatializedVisualValues) => void
108
+ /** Called when playback stops. */
109
+ onStop?: (values: SpatializedVisualValues) => void
110
+ /** Called when playback resets. */
111
+ onReset?: (values: SpatializedVisualValues) => void
112
+ /** Called when asynchronous playback fails. */
113
+ onError?: (error: SpatializedPlaybackError) => void
114
+ }
115
+
116
+ /** Normalized timeline wire payload for native playback. */
117
+ export interface SpatializedMotionTimeline {
118
+ duration: number
119
+ delay?: number
120
+ playbackRate?: number
121
+ loop?: boolean | { reverse?: boolean }
122
+ tracks: Array<{
123
+ property: SpatializedMotionProperty
124
+ keyframes: SpatializedMotionKeyframe[]
125
+ timingFunction: TimingFunction
126
+ }>
127
+ }
128
+
129
+ export type SpatializedMotionPlayState =
130
+ | 'idle'
131
+ | 'queued'
132
+ | 'running'
133
+ | 'paused'
134
+ | 'finished'
135
+
136
+ /** Public imperative playback controls exposed to spatialized motion consumers. */
137
+ export interface SpatializedPlaybackApi {
138
+ play(): void
139
+ pause(): void
140
+ stop(): void
141
+ reset(): void
142
+ finish(): void
143
+ readonly isAnimating: boolean
144
+ readonly isPaused: boolean
145
+ readonly finished: boolean
146
+ readonly playState: SpatializedMotionPlayState
147
+ }
@@ -0,0 +1,17 @@
1
+ /** Async playback failure from native bridge. */
2
+ export interface SpatializedPlaybackError {
3
+ /** Operation that failed. */
4
+ command:
5
+ | 'create'
6
+ | 'play'
7
+ | 'pause'
8
+ | 'resume'
9
+ | 'stop'
10
+ | 'reset'
11
+ | 'finish'
12
+ | 'destroy'
13
+ /** Native or SDK error code when available. */
14
+ code?: string
15
+ /** Human-readable failure reason. */
16
+ reason: string
17
+ }
@@ -0,0 +1,24 @@
1
+ // ---- Spatialized element visual value model (segment + timeline motion) ----
2
+
3
+ /**
4
+ * Structured visual transform for a spatialized container element.
5
+ * Composed in fixed order: translate → rotate → scale.
6
+ * Does NOT support arbitrary CSS transform strings, skew, perspective, or matrix interpolation.
7
+ */
8
+ export interface SpatializedVisualTransform {
9
+ /** Translation in CSS pixels. */
10
+ translate?: { x?: number; y?: number; z?: number }
11
+ /** Rotation in degrees, aligning with CSS rotateX/Y/Z(). */
12
+ rotate?: { x?: number; y?: number; z?: number }
13
+ /** Scale as unitless multipliers, aligning with CSS scaleX/Y/Z(). */
14
+ scale?: { x?: number; y?: number; z?: number }
15
+ }
16
+
17
+ /**
18
+ * Whitelisted visual fields on a spatialized element at an instant in time.
19
+ * Does not include layout/size fields (width, height, back, depth).
20
+ */
21
+ export interface SpatializedVisualValues {
22
+ transform?: SpatializedVisualTransform
23
+ opacity?: number
24
+ }
@@ -100,15 +100,23 @@ export interface ModelSource {
100
100
  type?: string
101
101
  }
102
102
 
103
+ export type ModelLoadingMode = 'eager' | 'lazy'
104
+
105
+ export type StageMode = 'orbit' | 'none'
106
+
103
107
  export interface SpatializedStatic3DElementProperties
104
108
  extends SpatializedElementProperties {
105
109
  modelURL: string
106
110
  sources?: ModelSource[]
107
111
  modelTransform?: number[]
112
+ stagemode?: StageMode
108
113
  autoplay?: boolean
109
114
  loop?: boolean
110
115
  animationPaused?: boolean
111
116
  playbackRate?: number
117
+ currentTime?: number
118
+ posterURL?: string
119
+ loading?: ModelLoadingMode
112
120
  }
113
121
 
114
122
  export interface SpatialSceneCreationOptions {
@@ -262,6 +270,10 @@ export interface SpatialUnlitMaterialOptions {
262
270
  opacity?: number
263
271
  }
264
272
 
273
+ export interface SpatialTextureResourceOptions {
274
+ url: string
275
+ }
276
+
265
277
  export interface ModelComponentOptions {
266
278
  mesh: SpatialGeometry
267
279
  materials: SpatialMaterial[]
package/src/utils.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Vec3 } from './types/types'
2
+ import type { TransformValues } from './types/animation'
2
3
 
3
4
  function parseBorderRadius(borderProperty: string, width: number) {
4
5
  if (borderProperty === '') {
@@ -80,3 +81,56 @@ export function deepCloneJSON<T>(value: T): T {
80
81
  }
81
82
  return JSON.parse(JSON.stringify(value))
82
83
  }
84
+
85
+ /**
86
+ * Decompose a column-major 4x4 matrix (16 numbers) back into
87
+ * position, rotation (Euler degrees), and scale Vec3 values.
88
+ *
89
+ * This is the inverse of `composeSRT`. It extracts:
90
+ * - Translation from the last column
91
+ * - Scale from the lengths of the first three column vectors
92
+ * - Rotation from the normalised upper-3x3 → Euler XYZ in degrees
93
+ */
94
+ export function decomposeSRT(m: number[]): TransformValues {
95
+ // Translation
96
+ const position: Vec3 = { x: m[12], y: m[13], z: m[14] }
97
+
98
+ // Scale — column vector lengths
99
+ const sx = Math.sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2])
100
+ const sy = Math.sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6])
101
+ const sz = Math.sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10])
102
+ const scale: Vec3 = { x: sx, y: sy, z: sz }
103
+
104
+ // Normalise columns to get rotation matrix
105
+ const r00 = sx !== 0 ? m[0] / sx : 0
106
+ const r10 = sx !== 0 ? m[1] / sx : 0
107
+ const r20 = sx !== 0 ? m[2] / sx : 0
108
+ const r11 = sy !== 0 ? m[5] / sy : 0
109
+ const r21 = sy !== 0 ? m[6] / sy : 0
110
+ const r12 = sz !== 0 ? m[9] / sz : 0
111
+ const r22 = sz !== 0 ? m[10] / sz : 0
112
+
113
+ // DOMMatrix.rotate(rx, ry, rz) uses ZYX intrinsic order which maps to
114
+ // extrinsic XYZ. The decomposition below extracts Euler angles that
115
+ // match this convention.
116
+ const RAD2DEG = 180 / Math.PI
117
+ let rx: number, ry: number, rz: number
118
+
119
+ // clamp to avoid NaN from asin
120
+ const sinY = -r20
121
+ const clampedSinY = Math.max(-1, Math.min(1, sinY))
122
+ ry = Math.asin(clampedSinY) * RAD2DEG
123
+
124
+ if (Math.abs(sinY) < 0.9999999) {
125
+ rx = Math.atan2(r21, r22) * RAD2DEG
126
+ rz = Math.atan2(r10, r00) * RAD2DEG
127
+ } else {
128
+ // Gimbal lock
129
+ rx = Math.atan2(-r12, r11) * RAD2DEG
130
+ rz = 0
131
+ }
132
+
133
+ const rotation: Vec3 = { x: rx, y: ry, z: rz }
134
+
135
+ return { position, rotation, scale }
136
+ }