@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,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
+ }
@@ -102,11 +102,14 @@ export interface ModelSource {
102
102
 
103
103
  export type ModelLoadingMode = 'eager' | 'lazy'
104
104
 
105
+ export type StageMode = 'orbit' | 'none'
106
+
105
107
  export interface SpatializedStatic3DElementProperties
106
108
  extends SpatializedElementProperties {
107
109
  modelURL: string
108
110
  sources?: ModelSource[]
109
111
  modelTransform?: number[]
112
+ stagemode?: StageMode
110
113
  autoplay?: boolean
111
114
  loop?: boolean
112
115
  animationPaused?: boolean
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
+ }
package/tsup.config.ts CHANGED
@@ -1,51 +1,76 @@
1
1
  // tsup.config.ts
2
+ import { readFileSync, writeFileSync } from 'node:fs'
3
+ import { resolve } from 'node:path'
2
4
  import { defineConfig, Options } from 'tsup'
3
5
  import { version } from './package.json'
6
+
7
+ // `bundle: false` makes tsup transpile each source file to its own
8
+ // output file (the ESM module graph is preserved 1-to-1). This is a
9
+ // precondition for fine-grained downstream tree-shaking: with the
10
+ // previous `bundle: true` (tsup's default) every source file collapsed
11
+ // into a single `dist/index.js` (or with `splitting: true`, into one
12
+ // shared chunk per entry) whose internal `__export` helper for wildcard
13
+ // re-exports (`export * from './reality'`, etc.) **defeated** consumer
14
+ // tree-shaking — Rollup / Vite / esbuild could not statically determine
15
+ // which named exports were reachable from a given consumer call site,
16
+ // so consumers ended up bundling `Spatial`, `SpatialSession`, all
17
+ // geometry creators, `scene-polyfill`, etc. even when they only imported
18
+ // a single helper like `isSSREnv` or `supports`. Per the lazy-load
19
+ // proposal `tasks.md §12.9` ("Pre-v1 budget calibration"), this is a
20
+ // precondition for react-sdk's marginal-delta budget to hold against
21
+ // typical consumers.
4
22
  const baseConfig: Options = {
5
- splitting: false,
23
+ bundle: false,
6
24
  sourcemap: true,
7
25
  clean: true,
8
26
  dts: true,
9
- banner: {
10
- js: `
11
- (function(){
12
- if(typeof window === 'undefined') return;
13
- if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
14
- window.__webspatialsdk__['core-sdk-version'] = ${JSON.stringify(version)}
15
- })()
16
- `,
17
- },
18
27
  }
19
28
 
20
29
  const versionDefine = {
21
30
  __WEBSPATIAL_CORE_SDK_VERSION__: JSON.stringify(version),
22
31
  }
23
32
 
24
- export default defineConfig([
25
- {
26
- ...baseConfig,
27
- entry: ['src/index.ts'],
28
- format: ['esm'],
29
- outDir: 'dist',
30
- esbuildOptions(options) {
31
- options.define = {
32
- ...options.define,
33
- ...versionDefine,
34
- }
35
- },
33
+ // Diagnostic version stamp. This is intentionally NOT a tsup `banner`: with
34
+ // `bundle: false` a banner is injected into EVERY emitted `dist/*.js` file,
35
+ // turning each one into a top-level `window.__webspatialsdk__` write. That
36
+ // (a) contradicts the `package.json` `sideEffects` allowlist (which declares
37
+ // only `install-polyfills.js` as side-effectful) and (b) multiplies the stamp
38
+ // across a consumer's bundle (one copy per source file pulled in). Instead we
39
+ // post-build stamp ONLY the single ESM file that legitimately already has a
40
+ // side effect — `dist/install-polyfills.js` so a bundled WebSpatial consumer
41
+ // still reports `core-sdk-version` when the polyfill installs, and every other
42
+ // ESM module stays side-effect-free.
43
+ const versionStamp = `
44
+ (function(){
45
+ if(typeof window === 'undefined') return;
46
+ if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
47
+ window.__webspatialsdk__['core-sdk-version'] = ${JSON.stringify(version)}
48
+ })()
49
+ `.trim()
50
+
51
+ const prependVersionStamp = (filePath: string): void => {
52
+ const current = readFileSync(filePath, 'utf8')
53
+ if (current.includes("__webspatialsdk__['core-sdk-version']")) return
54
+ writeFileSync(filePath, `${versionStamp}\n${current}`)
55
+ }
56
+
57
+ export default defineConfig({
58
+ ...baseConfig,
59
+ // ESM build: emit one output file per source file (`bundle: false`
60
+ // above) so consumer bundlers can tree-shake at file granularity.
61
+ // The entry points to the entire `src/` tree; `**/*.test.ts` is
62
+ // excluded so Vitest fixtures don't ship in the published package.
63
+ entry: ['src/**/*.ts', '!src/**/*.test.ts'],
64
+ format: ['esm'],
65
+ outDir: 'dist',
66
+ esbuildOptions(options) {
67
+ options.define = {
68
+ ...options.define,
69
+ ...versionDefine,
70
+ }
36
71
  },
37
- {
38
- ...baseConfig,
39
- entry: ['src/index.ts'],
40
- format: ['iife'],
41
- outDir: 'dist/iife',
42
- globalName: 'webspatialCore',
43
- esbuildOptions(options) {
44
- options.define = {
45
- ...options.define,
46
- ...versionDefine,
47
- }
48
- },
49
- minify: true,
72
+ onSuccess: async () => {
73
+ // Stamp only the side-effectful ESM entry (see `versionStamp` rationale).
74
+ prependVersionStamp(resolve(__dirname, 'dist/install-polyfills.js'))
50
75
  },
51
- ])
76
+ })
package/vitest.config.ts CHANGED
@@ -3,6 +3,10 @@ import { defineConfig } from 'vitest/config'
3
3
  export default defineConfig({
4
4
  test: {
5
5
  globals: true,
6
- environment: 'jsdom', // provide window / document
6
+ // Use happy-dom instead of jsdom because jsdom does not implement
7
+ // W3C Geometry Interfaces (DOMMatrix, DOMPoint, etc.).
8
+ // composeSRT in utils.ts relies on `new DOMMatrix()` which is only
9
+ // available in happy-dom's environment.
10
+ environment: 'happy-dom',
7
11
  },
8
12
  })