@webspatial/platform-visionos 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 (74) hide show
  1. package/package.json +2 -2
  2. package/web-spatial/EventEmitter.swift +56 -0
  3. package/web-spatial/JSBCommand.swift +348 -0
  4. package/web-spatial/SpatialObject.swift +108 -0
  5. package/web-spatial/WebMsgCommand.swift +119 -0
  6. package/web-spatial/WebSpatialApp.swift +111 -0
  7. package/web-spatial/{libs/uiKitDelegate/Window.swift → Window.swift} +1 -0
  8. package/web-spatial/manager/Dynamic3DManager.swift +114 -0
  9. package/web-spatial/manager/JSBManager.swift +148 -0
  10. package/web-spatial/manager/WKWebViewManager.swift +39 -0
  11. package/web-spatial/{libs/webView/manifest.swift → manifest.swift} +16 -5
  12. package/web-spatial/model/SpatialApp.swift +190 -0
  13. package/web-spatial/model/SpatialScene.swift +1042 -0
  14. package/web-spatial/model/Spatialized2DElement.swift +128 -0
  15. package/web-spatial/model/SpatializedDynamic3DElement.swift +34 -0
  16. package/web-spatial/model/SpatializedElement.swift +95 -0
  17. package/web-spatial/model/SpatializedStatic3DElement.swift +19 -0
  18. package/web-spatial/model/dynamic3d/Geometry.swift +95 -0
  19. package/web-spatial/model/dynamic3d/SpatialComponent.swift +72 -0
  20. package/web-spatial/model/dynamic3d/SpatialEntity.swift +211 -0
  21. package/web-spatial/model/dynamic3d/SpatialMaterial.swift +39 -0
  22. package/web-spatial/model/dynamic3d/SpatialModelEntity.swift +39 -0
  23. package/web-spatial/model/dynamic3d/SpatialModelResource.swift +38 -0
  24. package/web-spatial/model/dynamic3d/SpatialTextureResource.swift +18 -0
  25. package/web-spatial/protocol/ScrollAbleSpatialElementContainer.swift +1 -0
  26. package/web-spatial/protocol/SpatialScrollAble.swift +8 -0
  27. package/web-spatial/protocol/SpatializedElementContainer.swift +8 -0
  28. package/web-spatial/protocol/WebMsgSender.swift +5 -0
  29. package/web-spatial/types/Vec2.swift +12 -0
  30. package/web-spatial/types/Vec3.swift +7 -0
  31. package/web-spatial/view/SceneHandlerUIView.swift +92 -0
  32. package/web-spatial/{views/ui/NavView.swift → view/SpatialNavView.swift} +149 -77
  33. package/web-spatial/view/SpatialSceneContentView.swift +218 -0
  34. package/web-spatial/view/SpatialSceneView.swift +53 -0
  35. package/web-spatial/view/Spatialized2DElementView.swift +96 -0
  36. package/web-spatial/view/SpatializedDynamic3DView.swift +104 -0
  37. package/web-spatial/view/SpatializedElementView.swift +178 -0
  38. package/web-spatial/view/SpatializedStatic3DView.swift +70 -0
  39. package/web-spatial/{views → view/view-modifier}/MaterialWithBorderCornerModifier.swift +28 -8
  40. package/web-spatial/webview/SpatialWebController.swift +300 -0
  41. package/web-spatial/webview/SpatialWebView.swift +34 -0
  42. package/web-spatial/webview/SpatialWebViewModel.swift +307 -0
  43. package/web-spatial.xcodeproj/project.pbxproj +126 -207
  44. package/web-spatial/libs/EventEmitter.swift +0 -25
  45. package/web-spatial/libs/SpatialComponent.swift +0 -24
  46. package/web-spatial/libs/SpatialEntity.swift +0 -172
  47. package/web-spatial/libs/SpatialInputComponent.swift +0 -19
  48. package/web-spatial/libs/SpatialMeshResource.swift +0 -12
  49. package/web-spatial/libs/SpatialModel3DComponent.swift +0 -51
  50. package/web-spatial/libs/SpatialModelComponent.swift +0 -25
  51. package/web-spatial/libs/SpatialObject.swift +0 -140
  52. package/web-spatial/libs/SpatialPhysicallyBasedMaterial.swift +0 -19
  53. package/web-spatial/libs/SpatialViewComponent.swift +0 -8
  54. package/web-spatial/libs/SpatialWindowComponent.swift +0 -454
  55. package/web-spatial/libs/SpatialWindowContainer.swift +0 -153
  56. package/web-spatial/libs/Utils/CommandManager.swift +0 -823
  57. package/web-spatial/libs/Utils/PerfClock.swift +0 -43
  58. package/web-spatial/libs/Utils/SceneManager.swift +0 -101
  59. package/web-spatial/libs/Utils/WindowContainerMgr.swift +0 -122
  60. package/web-spatial/libs/json/JsonParser.swift +0 -45
  61. package/web-spatial/libs/webView/UpdateSystem.swift +0 -26
  62. package/web-spatial/libs/webView/backend/NativeWebView.swift +0 -350
  63. package/web-spatial/views/ImmersiveView.swift +0 -17
  64. package/web-spatial/views/OpenDismissHandlerUI.swift +0 -45
  65. package/web-spatial/views/PlainWindowContainerView.swift +0 -132
  66. package/web-spatial/views/SpatialModel3DView.swift +0 -187
  67. package/web-spatial/views/SpatialViewUI.swift +0 -168
  68. package/web-spatial/views/SpatialWebViewUI.swift +0 -179
  69. package/web-spatial/views/VolumetricWindowContainerView.swift +0 -30
  70. package/web-spatial/web_spatialApp.swift +0 -141
  71. /package/web-spatial/{libs/Utils → Utils}/ColorExtension.swift +0 -0
  72. /package/web-spatial/{libs/Utils → Utils}/Logger.swift +0 -0
  73. /package/web-spatial/{views → view}/LoadingView.swift +0 -0
  74. /package/web-spatial/{views → view/view-modifier}/HideViewModifier.swift +0 -0
@@ -1,12 +0,0 @@
1
- import Foundation
2
- import RealityKit
3
-
4
- @Observable
5
- class SpatialMeshResource: SpatialObject {
6
- let meshResource: MeshResource
7
-
8
- init(_ meshResource: MeshResource) {
9
- self.meshResource = meshResource
10
- super.init()
11
- }
12
- }
@@ -1,51 +0,0 @@
1
- import Foundation
2
- import SwiftUI
3
-
4
- @Observable
5
- class SpatialModel3DComponent: SpatialComponent {
6
- var resolutionX: Double = 0
7
- var resolutionY: Double = 0
8
- var modelURL: String = ""
9
- var opacity: Double = 1.0
10
- var rotationAnchor: UnitPoint3D = .center
11
- var scrollWithParent = false
12
- var contentMode: ContentMode = .fit
13
- var resizable: Bool = true
14
- var aspectRatio: Double? = nil
15
-
16
- var enableTapEvent = false
17
- var enableDoubleTapEvent = false
18
- var enableLongPressEvent = false
19
- var enableDragEvent = false
20
-
21
- // SpatialModel3DView should not have dependency on SpatialWindowComponent.
22
- // It just need some JSB communication channel. This need to be refactor in future
23
- weak var wv: SpatialWindowComponent?
24
-
25
- public func setURL(_ url: String) {
26
- modelURL = url
27
- }
28
-
29
- override func inspect() -> [String: Any] {
30
- var inspectInfo: [String: Any] = [
31
- "scrollWithParent": scrollWithParent,
32
- "resolutionX": resolutionX,
33
- "resolutionY": resolutionY,
34
- "modelURL": modelURL,
35
- "opacity": opacity,
36
- "resizable": resizable,
37
- "aspectRatio": aspectRatio != nil ? String(describing: aspectRatio!) : "nil",
38
- "contentMode": contentMode == .fill ? "fill" : "fit",
39
- "enableTapEvent": enableTapEvent,
40
- "enableDoubleTapEvent": enableDoubleTapEvent,
41
- "enableLongPressEvent": enableLongPressEvent,
42
- "enableDragEvent": enableDragEvent,
43
- ]
44
-
45
- let baseInspectInfo = super.inspect()
46
- for (key, value) in baseInspectInfo {
47
- inspectInfo[key] = value
48
- }
49
- return inspectInfo
50
- }
51
- }
@@ -1,25 +0,0 @@
1
- import Combine
2
- import Foundation
3
- import RealityKit
4
-
5
- @Observable
6
- class SpatialModelComponent: SpatialComponent {
7
- var modelComponent: ModelComponent
8
-
9
- init(_ modelComponent: ModelComponent) {
10
- self.modelComponent = modelComponent
11
-
12
- super.init()
13
- }
14
-
15
- override func onAddToEntity() {
16
- entity?.modelEntity.model = modelComponent
17
- }
18
-
19
- // Since modelComponent is a struct instead of a class, we must sync it to the entity its attached to
20
- func onUpdate() {
21
- if entity != nil {
22
- entity?.modelEntity.model = modelComponent
23
- }
24
- }
25
- }
@@ -1,140 +0,0 @@
1
- import Foundation
2
-
3
- struct SpatialObjectInfo: Codable {
4
- var count: Int
5
- var windowArray: [String]
6
- var windowContainerArray: [String]
7
- var entityArray: [String]
8
- }
9
-
10
- // Stats from native code. Objects tracks number of native objects that were created but not yet explicitly destroyed. RefObjects tracks bjects that still have references. After an object is destroyed, we should be cleaning up all of the native references. Expect objects.count == refObjects.count , if not, there is likely a leak.
11
- struct SpatialObjectStatsInfo: Codable {
12
- var backend = "AVP"
13
- var objects: SpatialObjectInfo
14
- var refObjects: SpatialObjectInfo
15
- var perfStats: PerfStats
16
- }
17
-
18
- class WeakReference<T: AnyObject> {
19
- weak var value: T?
20
-
21
- init(_ value: T) {
22
- self.value = value
23
- }
24
- }
25
-
26
- class SpatialObject: EventEmitter, Equatable {
27
- static var objects = [String: SpatialObject]()
28
- static var weakRefObjects = [String: WeakReference<SpatialObject>]()
29
- static func get(_ id: String) -> SpatialObject? {
30
- return objects[id]
31
- }
32
-
33
- static func getRefObject(_ id: String) -> SpatialObject? {
34
- return weakRefObjects[id]?.value
35
- }
36
-
37
- // for debug
38
- static func stats() -> SpatialObjectStatsInfo {
39
- let webviews = objects.filter {
40
- $0.value is SpatialWindowComponent
41
- }
42
-
43
- let entities = objects.filter {
44
- $0.value is SpatialEntity
45
- }
46
-
47
- let windowContainers = objects.filter {
48
- $0.value is SpatialWindowContainer
49
- }
50
-
51
- let weakRefWebviews = weakRefObjects.filter {
52
- $0.value.value is SpatialWindowComponent
53
- }
54
-
55
- let weakRefWindowContainers = weakRefObjects.filter {
56
- $0.value.value is SpatialWindowContainer
57
- }
58
-
59
- let weakRefEntities = weakRefObjects.filter {
60
- $0.value.value is SpatialEntity
61
- }
62
-
63
- return SpatialObjectStatsInfo(
64
- objects: SpatialObjectInfo(
65
- count: objects.count,
66
- windowArray: Array(webviews.keys),
67
- windowContainerArray: Array(windowContainers.keys),
68
- entityArray: Array(entities.keys)
69
- ),
70
- refObjects: SpatialObjectInfo(
71
- count: weakRefObjects.count,
72
- windowArray: Array(weakRefWebviews.keys),
73
- windowContainerArray: Array(weakRefWindowContainers.keys),
74
- entityArray: Array(weakRefEntities.keys)
75
- ),
76
- perfStats: clock.perfStats
77
- )
78
- }
79
-
80
- static func getWeakRef(_ id: String) -> SpatialObject? {
81
- return weakRefObjects[id]?.value
82
- }
83
-
84
- let id: String
85
- var name: String = ""
86
-
87
- private var _isDestroyed = false
88
-
89
- var isDestroyed: Bool {
90
- _isDestroyed
91
- }
92
-
93
- static func == (lhs: SpatialObject, rhs: SpatialObject) -> Bool {
94
- return lhs.id == rhs.id
95
- }
96
-
97
- override init() {
98
- id = UUID().uuidString
99
- super.init()
100
- SpatialObject.objects[id] = self
101
- SpatialObject.weakRefObjects[id] = WeakReference(self)
102
- }
103
-
104
- init(_ _id: String) {
105
- id = _id
106
- super.init()
107
- SpatialObject.objects[id] = self
108
- SpatialObject.weakRefObjects[id] = WeakReference(self)
109
- }
110
-
111
- deinit {
112
- SpatialObject.weakRefObjects.removeValue(forKey: id)
113
- }
114
-
115
- enum Events: String {
116
- case BeforeDestroyed = "SpatialObject::BeforeDestroyed"
117
- case Destroyed = "SpatialObject::Destroyed"
118
- }
119
-
120
- func destroy() {
121
- if _isDestroyed {
122
- logger.warning("SpatialObject already destroyed \(self)")
123
- return
124
- }
125
- emit(event: Events.BeforeDestroyed.rawValue, data: ["object": self])
126
- onDestroy()
127
- _isDestroyed = true
128
-
129
- emit(event: Events.Destroyed.rawValue, data: ["object": self])
130
- SpatialObject.objects.removeValue(forKey: id)
131
-
132
- reset()
133
- }
134
-
135
- func onDestroy() {}
136
-
137
- func inspect() -> [String: Any] {
138
- return ["id": id, "isDestroyed": isDestroyed, "name": name]
139
- }
140
- }
@@ -1,19 +0,0 @@
1
- //
2
- // SpatialPhysicallyBasedMaterial.swift
3
- // web-spatial
4
- //
5
- // Created by ByteDance on 9/10/24.
6
- //
7
-
8
- import Foundation
9
- import RealityKit
10
-
11
- @Observable
12
- class SpatialPhysicallyBasedMaterial: SpatialObject {
13
- var physicallyBasedMaterial: PhysicallyBasedMaterial
14
-
15
- init(_ physicallyBasedMaterial: PhysicallyBasedMaterial) {
16
- self.physicallyBasedMaterial = physicallyBasedMaterial
17
- super.init()
18
- }
19
- }
@@ -1,8 +0,0 @@
1
- import Foundation
2
-
3
- @Observable
4
- class SpatialViewComponent: SpatialComponent {
5
- var resolutionX: Double = 100
6
- var resolutionY: Double = 100
7
- var isPortal = false
8
- }