@webspatial/core-sdk 1.0.3 → 1.0.5

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 (82) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +112 -81
  3. package/dist/iife/index.d.ts +683 -561
  4. package/dist/iife/index.global.js +3 -4
  5. package/dist/iife/index.global.js.map +1 -1
  6. package/dist/index.d.ts +683 -561
  7. package/dist/index.js +2175 -1291
  8. package/dist/index.js.map +1 -1
  9. package/package.json +7 -4
  10. package/src/JSBCommand.ts +631 -0
  11. package/src/Spatial.ts +68 -0
  12. package/src/SpatialObject.ts +46 -0
  13. package/src/SpatialScene.ts +75 -0
  14. package/src/SpatialSession.ts +187 -0
  15. package/src/SpatialWebEvent.ts +23 -0
  16. package/src/SpatialWebEventCreator.ts +12 -0
  17. package/src/Spatialized2DElement.ts +51 -0
  18. package/src/SpatializedDynamic3DElement.ts +30 -0
  19. package/src/SpatializedElement.ts +331 -0
  20. package/src/SpatializedElementCreator.ts +45 -0
  21. package/src/SpatializedStatic3DElement.ts +111 -0
  22. package/src/WebMsgCommand.ts +88 -0
  23. package/src/index.ts +23 -1
  24. package/src/platform-adapter/CommandResultUtils.ts +22 -0
  25. package/src/platform-adapter/android/AndroidPlatform.ts +133 -0
  26. package/src/platform-adapter/index.ts +21 -0
  27. package/src/platform-adapter/interface.ts +36 -0
  28. package/src/platform-adapter/ssr/SSRPlatform.ts +43 -0
  29. package/src/platform-adapter/vision-os/VisionOSPlatform.ts +77 -0
  30. package/src/reality/component/ModelComponent.ts +11 -0
  31. package/src/reality/component/SpatialComponent.ts +17 -0
  32. package/src/reality/component/index.ts +2 -0
  33. package/src/reality/entity/SpatialEntity.ts +255 -0
  34. package/src/reality/entity/SpatialModelEntity.ts +15 -0
  35. package/src/reality/entity/index.ts +2 -0
  36. package/src/reality/geometry/SpatialBoxGeometry.ts +12 -0
  37. package/src/reality/geometry/SpatialConeGeometry.ts +15 -0
  38. package/src/reality/geometry/SpatialCylinderGeometry.ts +15 -0
  39. package/src/reality/geometry/SpatialGeometry.ts +12 -0
  40. package/src/reality/geometry/SpatialPlaneGeometry.ts +15 -0
  41. package/src/reality/geometry/SpatialSphereGeometry.ts +15 -0
  42. package/src/reality/geometry/index.ts +6 -0
  43. package/src/reality/index.ts +5 -0
  44. package/src/reality/material/SpatialMaterial.ts +14 -0
  45. package/src/reality/material/SpatialUnlitMaterial.ts +16 -0
  46. package/src/reality/material/index.ts +2 -0
  47. package/src/reality/realityCreator.ts +94 -0
  48. package/src/reality/resource/SpatialModelAsset.ts +11 -0
  49. package/src/reality/resource/index.ts +1 -0
  50. package/src/scene-polyfill.test.ts +376 -0
  51. package/src/scene-polyfill.ts +359 -0
  52. package/src/spatial-window-polyfill.ts +182 -0
  53. package/src/ssr-polyfill.ts +3 -0
  54. package/src/types/global.d.ts +33 -1
  55. package/src/types/internal.ts +13 -0
  56. package/src/types/types.ts +380 -0
  57. package/src/utils.ts +61 -0
  58. package/tsconfig.json +1 -1
  59. package/vitest.config.ts +8 -0
  60. package/src/core/Spatial.ts +0 -50
  61. package/src/core/SpatialEntity.ts +0 -147
  62. package/src/core/SpatialHelper.ts +0 -230
  63. package/src/core/SpatialObject.ts +0 -26
  64. package/src/core/SpatialSession.ts +0 -457
  65. package/src/core/SpatialTransform.ts +0 -26
  66. package/src/core/SpatialWindowContainer.ts +0 -59
  67. package/src/core/component/EventSpatialComponent.ts +0 -32
  68. package/src/core/component/SpatialComponent.ts +0 -26
  69. package/src/core/component/SpatialInputComponent.ts +0 -24
  70. package/src/core/component/SpatialModel3DComponent.ts +0 -223
  71. package/src/core/component/SpatialModelComponent.ts +0 -39
  72. package/src/core/component/SpatialViewComponent.ts +0 -32
  73. package/src/core/component/SpatialWindowComponent.ts +0 -177
  74. package/src/core/component/index.ts +0 -14
  75. package/src/core/index.ts +0 -10
  76. package/src/core/private/WebSpatial.ts +0 -383
  77. package/src/core/private/remote-command/RemoteCommand.ts +0 -15
  78. package/src/core/private/remote-command/index.ts +0 -1
  79. package/src/core/resource/SpatialMeshResource.ts +0 -6
  80. package/src/core/resource/SpatialPhysicallyBasedMaterialResource.ts +0 -42
  81. package/src/core/resource/index.ts +0 -2
  82. package/src/core/types.ts +0 -32
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @webspatial/core-sdk
2
2
 
3
+ ## 1.0.5
4
+
5
+ ## 1.0.4
6
+
3
7
  ## 1.0.3
4
8
 
5
9
  ## 1.0.2
package/README.md CHANGED
@@ -1,115 +1,146 @@
1
- > [!NOTE]
2
- > This library is still in development. APIs may change as we enable additional platforms/features
1
+ # WebSpatial Core SDK
3
2
 
4
- # Core SDK for WebSpatial
3
+ > [!NOTE]
4
+ > This library is still in development. APIs may change as we enable additional platforms/features.
5
5
 
6
- WebSpatial SDK is implemented on top of the Core SDK, which is a framework-agnostic pure-JS API that enables the WebSpatial App Shell to natively spatialize 2D HTML content and render 3D content.
6
+ ## Overview
7
7
 
8
- The core-sdk library is responsible for interacting with the target platforms native APIs to expose behavior not commonly found on the web.
8
+ WebSpatial Core SDK is a framework-agnostic pure JavaScript API that enables the WebSpatial App Shell to natively spatialize 2D HTML content and render 3D content. The core-sdk library is responsible for interacting with the target platform's native APIs to expose spatial behaviors not commonly found on the web.
9
9
 
10
- # How to use
11
- To run a WebSpatial website you currently need to package it within a native app.
12
-
13
- See docs on our [github](https://github.com/webspatial/webspatial-sd) for more information.
10
+ ## Installation
14
11
 
15
- ## Hello World Example
12
+ ```bash
13
+ npm install @webspatial/core-sdk
14
+ ```
16
15
 
17
- ```jsx
18
- import { Spatial, SpatialHelper } from '@webspatial/core-sdk'
16
+ ## Getting Started
17
+
18
+ To run a WebSpatial website, you currently need to package it within a native app. See documentation on our [GitHub repository](https://github.com/webspatial/webspatial-sdk) for more information.
19
+
20
+ ### Hello World Example
21
+
22
+ ```javascript
23
+ import { Spatial } from '@webspatial/core-sdk'
24
+
25
+ const main = async () => {
26
+ // Initialize the Spatial environment
27
+ const spatial = new Spatial()
28
+
29
+ if (spatial.isSupported()) {
30
+ const session = spatial.requestSession()
31
+ if (session) {
32
+ console.log("Session supported and created")
33
+
34
+ // Now you can create spatial elements
35
+ // Example: Create a 2D element
36
+ const element2D = await session.createSpatialized2DElement()
37
+
38
+ // Example: Create a 3D static element (for models)
39
+ const static3DElement = await session.createSpatializedStatic3DElement()
40
+
41
+ // Example: Create a 3D dynamic element (for custom geometry)
42
+ const dynamic3DElement = await session.createSpatializedDynamic3DElement()
43
+ }
44
+ }
45
+ }
19
46
 
20
- var main = async () => {
21
- var spatial = new Spatial()
22
- var versionInfo = "clientVersion:" + spatial.getClientVersion() + "\nnativeVersion:" + spatial.getNativeVersion() + "\nisSupported:" + spatial.isSupported()
47
+ main()
48
+ ```
23
49
 
24
- let sh = SpatialHelper.instance!
25
- if (sh) {
26
- // Create a new window container
27
- var container = await sh.session.createWindowContainer({ style: 'Volumetric' })
50
+ ## Core Concepts
28
51
 
29
- // Setup volume for the entity
30
- var rootEntity = await sh.session.createEntity()
31
- await rootEntity.setCoordinateSpace("Root")
32
- rootEntity.setComponent(await sh.session.createViewComponent())
52
+ ### Initialization
33
53
 
34
- // Create a mesh. and add it tot the root volume
35
- var box = await sh.shape.createShapeEntity("box")
36
- await box.setParent(rootEntity)
54
+ Create a new `Spatial` object which is the root entry point to the API. This object should be available in standard browsers as well as WebSpatial environments. It can check client and native versions of the library and detect if WebSpatial is available in your setup.
37
55
 
38
- // add the volume to the window
39
- await container.setRootEntity(rootEntity)
40
- }
56
+ ```javascript
57
+ const spatial = new Spatial()
58
+ if (spatial.isSupported()) {
59
+ const session = spatial.requestSession()
60
+ if (session) {
61
+ console.log("Session supported and created")
62
+ }
41
63
  }
42
- main()
43
64
  ```
44
65
 
45
- # **Initialization**
66
+ ### Async/Await/Promises
46
67
 
47
- Create a new spatial object which is the root entry point to the API. This object should be available in standard browsers as well as webspatial environments. This object can check client and native versions of the library and detect if webspatial is available in this setup.
68
+ Due to the architecture of WebSpatial, the client library communicates with native code over a JS Bridge provided by the platform. Because of this, function calls may not be completed immediately. To accommodate this, the majority of WebSpatial API uses [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to track completion. It is recommended you create an async main function to allow you to use the await syntax for app setup.
48
69
 
49
- ```
50
- var spatial = new Spatial()
51
- if(spatial.isSupported()){
52
- var session = spatial.requestSession()
53
- if(session){
54
- console.log("session supported and created")
55
- }
70
+ ```javascript
71
+ const main = async () => {
72
+ // Your code goes here
56
73
  }
74
+ main()
57
75
  ```
58
76
 
59
- # **Async/Await/Promises**
77
+ ## Key Components
60
78
 
61
- Due to the architecture of webspatial, the client library communicates to native code over a JS Bridge provided by the platform. Because of this, function calls may not be completed immediately. To accomidate this, the majority of webspatial api use [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to keep track of completion. It is recommended you create an async main function to allow you to use the await syntax for app setup.
79
+ ### SpatialSession
62
80
 
63
- ```
64
- var main = async ()=>{
65
- // Your code goes here
66
- };
67
- main()'
81
+ The `SpatialSession` class is used to establish a connection to the spatial renderer of the system. All spatial resources must be created through this session.
82
+
83
+ ```javascript
84
+ const session = spatial.requestSession()
68
85
  ```
69
86
 
70
- # **WindowContainer**
87
+ Key methods include:
88
+ - `getSpatialScene()`: Returns the current spatial scene
89
+ - `createSpatialized2DElement()`: Creates a 2D element in spatial environment
90
+ - `createSpatializedStatic3DElement()`: Creates a static 3D element for models
91
+ - `createSpatializedDynamic3DElement()`: Creates a dynamic 3D element for custom geometry
71
92
 
72
- To create a new WindowContainer (aka WindowGroup on apple vision pro)
93
+ ### SpatializedElement
73
94
 
74
- ```
75
- var windowContainer = await session.createWindowContainer({ style: 'Volumetric' })
76
- ```
95
+ The base class for all spatial elements. It provides common functionality for:
77
96
 
78
- Depending on if you want to display content as a panel or within a volume, you can choose to use "Plain" or "Volumetric" style.
97
+ - Updating element properties
98
+ - Handling spatial transforms
99
+ - Processing spatial events (tap, drag, rotate, magnify)
79
100
 
80
- # **Entity/Component api**
101
+ ### Element Types
81
102
 
82
- To start displaying content within a WindowContainer, you must create an entity.
103
+ #### Spatialized2DElement
83
104
 
84
- ```
85
- // Create entity
86
- var entity = await session.createEntity()
87
-
88
- // Create component
89
- await entity.setComponent(
90
- await session.createViewComponent({ windowContainer: windowContainer }),
91
- )
92
- await entity.setCoordinateSpace('Root')
93
-
94
- // Set root entity on the window container.
95
- // Note the entity much have:
96
- // - Root coordinate space
97
- // - have a ViewComponent for Volumetric windowContainer
98
- // - have a WindowComponent for Plain windowContainer
99
- await windowContainer.setRootEntity(entity)
100
- ```
105
+ Represents HTML content in a spatial environment with properties like:
106
+ - Corner radius
107
+ - Background material type
108
+ - Scroll behavior
101
109
 
102
- Entity maps to an object that will be displayed. Components tell how that object should be displayed.
110
+ #### SpatializedStatic3DElement
103
111
 
104
- # **Helper**
112
+ Represents static 3D models loaded from URLs.
105
113
 
106
- This library, similar to (webGL or webXR) may be a bit too verbose to use directly. You can use the helper we provide to do some common tasks such as opening a new webpage panel or use our higher level react API.
114
+ #### SpatializedDynamic3DElement
107
115
 
108
- ```
109
- import { SpatialHelper } from '@webspatial/core-sdk'
110
- SpatialHelper.instance.navigation.openPanel(
111
- 'https://www.npmjs.com/package/@webspatial/core-sdk',
112
- { resolution: { width: 600, height: 100 } },
113
- )
114
- ```
116
+ Represents dynamic 3D content with custom geometry and materials.
117
+
118
+ ## Spatial Geometry and Materials
115
119
 
120
+ The SDK provides various geometry types:
121
+ - `SpatialBoxGeometry`
122
+ - `SpatialPlaneGeometry`
123
+ - `SpatialSphereGeometry`
124
+ - `SpatialConeGeometry`
125
+ - `SpatialCylinderGeometry`
126
+
127
+ And material options including:
128
+ - Background material types: 'none', 'translucent', 'thick', 'regular', 'thin', 'transparent'
129
+ - Custom unlit materials
130
+
131
+ ## Event Handling
132
+
133
+ The SDK supports various spatial events:
134
+ - Tap events
135
+ - Drag events (start, drag, end)
136
+ - Rotate events (start, rotate, end)
137
+ - Magnify events (start, magnify, end)
138
+
139
+ ## Advanced Usage
140
+
141
+ For more advanced usage and detailed API documentation, please refer to the [official documentation](https://github.com/webspatial/webspatial-sdk).
142
+
143
+ ## License
144
+
145
+ See the LICENSE file in the repository root for more information.
146
+