@webspatial/react-sdk 0.0.3 → 0.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 (274) hide show
  1. package/dist/default/index.d.mts +164 -0
  2. package/dist/default/index.d.ts +164 -0
  3. package/dist/{cjs/default → default}/index.js +69 -136
  4. package/dist/default/index.js.map +1 -0
  5. package/dist/default/index.mjs +3346 -0
  6. package/dist/default/index.mjs.map +1 -0
  7. package/dist/jsx/jsx-dev-runtime.d.mts +4 -0
  8. package/dist/jsx/jsx-dev-runtime.d.ts +3 -2
  9. package/dist/jsx/jsx-dev-runtime.js +3093 -6747
  10. package/dist/jsx/jsx-dev-runtime.js.map +1 -7
  11. package/dist/jsx/jsx-dev-runtime.mjs +3445 -0
  12. package/dist/jsx/jsx-dev-runtime.mjs.map +1 -0
  13. package/dist/jsx/jsx-runtime-C06ExmCC.d.mts +9 -0
  14. package/dist/jsx/jsx-runtime-C06ExmCC.d.ts +9 -0
  15. package/dist/jsx/jsx-runtime.d.mts +4 -0
  16. package/dist/jsx/jsx-runtime.d.ts +3 -2
  17. package/dist/jsx/jsx-runtime.js +3094 -6748
  18. package/dist/jsx/jsx-runtime.js.map +1 -7
  19. package/dist/jsx/jsx-runtime.mjs +3445 -0
  20. package/dist/jsx/jsx-runtime.mjs.map +1 -0
  21. package/dist/web/index.d.mts +164 -0
  22. package/dist/web/index.d.ts +164 -0
  23. package/dist/{cjs/web → web}/index.js +73 -142
  24. package/dist/web/index.js.map +1 -0
  25. package/dist/web/index.mjs +3346 -0
  26. package/dist/web/index.mjs.map +1 -0
  27. package/npm/plugin/vite.js +23 -22
  28. package/package.json +26 -11
  29. package/dist/cjs/default/XRApp.d.ts +0 -21
  30. package/dist/cjs/default/XRApp.d.ts.map +0 -1
  31. package/dist/cjs/default/index.d.ts +0 -5
  32. package/dist/cjs/default/index.d.ts.map +0 -1
  33. package/dist/cjs/default/index.js.map +0 -7
  34. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialComponent.d.ts +0 -3
  35. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialComponent.d.ts.map +0 -1
  36. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialDebugNameContext.d.ts +0 -2
  37. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialDebugNameContext.d.ts.map +0 -1
  38. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialDiv.d.ts +0 -6
  39. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialDiv.d.ts.map +0 -1
  40. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialLayerContext.d.ts +0 -2
  41. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialLayerContext.d.ts.map +0 -1
  42. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialRootContext.d.ts +0 -14
  43. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/CSSSpatialRootContext.d.ts.map +0 -1
  44. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/const.d.ts +0 -6
  45. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/const.d.ts.map +0 -1
  46. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/index.d.ts +0 -2
  47. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/index.d.ts.map +0 -1
  48. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/injectClassStyle.d.ts +0 -2
  49. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/injectClassStyle.d.ts.map +0 -1
  50. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/math/index.d.ts +0 -4
  51. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/math/index.d.ts.map +0 -1
  52. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/useHijackSpatialDivRef.d.ts +0 -4
  53. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/useHijackSpatialDivRef.d.ts.map +0 -1
  54. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/useSpatialStyle.d.ts +0 -29
  55. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/useSpatialStyle.d.ts.map +0 -1
  56. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/utils.d.ts +0 -7
  57. package/dist/cjs/default/spatial-react-components/CSSSpatialDiv/utils.d.ts.map +0 -1
  58. package/dist/cjs/default/spatial-react-components/Model/index.d.ts +0 -42
  59. package/dist/cjs/default/spatial-react-components/Model/index.d.ts.map +0 -1
  60. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3D.d.ts +0 -4
  61. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3D.d.ts.map +0 -1
  62. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3DNotInSpatialDiv.d.ts +0 -3
  63. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3DNotInSpatialDiv.d.ts.map +0 -1
  64. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3DPortalInstance.d.ts +0 -3
  65. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3DPortalInstance.d.ts.map +0 -1
  66. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3DStandardInstance.d.ts +0 -3
  67. package/dist/cjs/default/spatial-react-components/Model3D/CSSModel3DStandardInstance.d.ts.map +0 -1
  68. package/dist/cjs/default/spatial-react-components/Model3D/Model3D.d.ts +0 -3
  69. package/dist/cjs/default/spatial-react-components/Model3D/Model3D.d.ts.map +0 -1
  70. package/dist/cjs/default/spatial-react-components/Model3D/Model3DNative.d.ts +0 -48
  71. package/dist/cjs/default/spatial-react-components/Model3D/Model3DNative.d.ts.map +0 -1
  72. package/dist/cjs/default/spatial-react-components/Model3D/Model3DNotInSpatialDiv.d.ts +0 -3
  73. package/dist/cjs/default/spatial-react-components/Model3D/Model3DNotInSpatialDiv.d.ts.map +0 -1
  74. package/dist/cjs/default/spatial-react-components/Model3D/Model3DPortalInstance.d.ts +0 -3
  75. package/dist/cjs/default/spatial-react-components/Model3D/Model3DPortalInstance.d.ts.map +0 -1
  76. package/dist/cjs/default/spatial-react-components/Model3D/Model3DStandardInstance.d.ts +0 -3
  77. package/dist/cjs/default/spatial-react-components/Model3D/Model3DStandardInstance.d.ts.map +0 -1
  78. package/dist/cjs/default/spatial-react-components/Model3D/index.d.ts +0 -4
  79. package/dist/cjs/default/spatial-react-components/Model3D/index.d.ts.map +0 -1
  80. package/dist/cjs/default/spatial-react-components/Model3D/types.d.ts +0 -46
  81. package/dist/cjs/default/spatial-react-components/Model3D/types.d.ts.map +0 -1
  82. package/dist/cjs/default/spatial-react-components/Model3D/useDetectLayoutDomUpdated.d.ts +0 -2
  83. package/dist/cjs/default/spatial-react-components/Model3D/useDetectLayoutDomUpdated.d.ts.map +0 -1
  84. package/dist/cjs/default/spatial-react-components/Model3D/useModel3DNative.d.ts +0 -15
  85. package/dist/cjs/default/spatial-react-components/Model3D/useModel3DNative.d.ts.map +0 -1
  86. package/dist/cjs/default/spatial-react-components/Model3D/useSyncDomInfoFromStandardInstance.d.ts +0 -19
  87. package/dist/cjs/default/spatial-react-components/Model3D/useSyncDomInfoFromStandardInstance.d.ts.map +0 -1
  88. package/dist/cjs/default/spatial-react-components/Model3D/utils.d.ts +0 -4
  89. package/dist/cjs/default/spatial-react-components/Model3D/utils.d.ts.map +0 -1
  90. package/dist/cjs/default/spatial-react-components/SpatialMonitor.d.ts +0 -6
  91. package/dist/cjs/default/spatial-react-components/SpatialMonitor.d.ts.map +0 -1
  92. package/dist/cjs/default/spatial-react-components/SpatialPrimitive.d.ts +0 -6
  93. package/dist/cjs/default/spatial-react-components/SpatialPrimitive.d.ts.map +0 -1
  94. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/PortalInstance.d.ts +0 -20
  95. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/PortalInstance.d.ts.map +0 -1
  96. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialDebugNameContext.d.ts +0 -2
  97. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialDebugNameContext.d.ts.map +0 -1
  98. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialIsStandardInstanceContext.d.ts +0 -2
  99. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialIsStandardInstanceContext.d.ts.map +0 -1
  100. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialLayerContext.d.ts +0 -2
  101. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialLayerContext.d.ts.map +0 -1
  102. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialReactComponent.d.ts +0 -3
  103. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialReactComponent.d.ts.map +0 -1
  104. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialReactContext.d.ts +0 -24
  105. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialReactContext.d.ts.map +0 -1
  106. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialWindowManager.d.ts +0 -17
  107. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialWindowManager.d.ts.map +0 -1
  108. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialWindowManagerContext.d.ts +0 -3
  109. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/SpatialWindowManagerContext.d.ts.map +0 -1
  110. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/StandardInstance.d.ts +0 -10
  111. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/StandardInstance.d.ts.map +0 -1
  112. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/const.d.ts +0 -2
  113. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/const.d.ts.map +0 -1
  114. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/index.d.ts +0 -3
  115. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/index.d.ts.map +0 -1
  116. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/types.d.ts +0 -31
  117. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/types.d.ts.map +0 -1
  118. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/usePortalContainer.d.ts +0 -8
  119. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/usePortalContainer.d.ts.map +0 -1
  120. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/utils.d.ts +0 -15
  121. package/dist/cjs/default/spatial-react-components/SpatialReactComponent/utils.d.ts.map +0 -1
  122. package/dist/cjs/default/spatial-react-components/SpatialView.d.ts +0 -15
  123. package/dist/cjs/default/spatial-react-components/SpatialView.d.ts.map +0 -1
  124. package/dist/cjs/default/spatial-react-components/hooks/useForceUpdate.d.ts +0 -2
  125. package/dist/cjs/default/spatial-react-components/hooks/useForceUpdate.d.ts.map +0 -1
  126. package/dist/cjs/default/spatial-react-components/hooks/useMonitorDocumentHeaderChange.d.ts +0 -2
  127. package/dist/cjs/default/spatial-react-components/hooks/useMonitorDocumentHeaderChange.d.ts.map +0 -1
  128. package/dist/cjs/default/spatial-react-components/hooks/useMonitorDomChange.d.ts +0 -2
  129. package/dist/cjs/default/spatial-react-components/hooks/useMonitorDomChange.d.ts.map +0 -1
  130. package/dist/cjs/default/spatial-react-components/index.d.ts +0 -11
  131. package/dist/cjs/default/spatial-react-components/index.d.ts.map +0 -1
  132. package/dist/cjs/default/spatial-react-components/notifyUpdateStandInstanceLayout.d.ts +0 -13
  133. package/dist/cjs/default/spatial-react-components/notifyUpdateStandInstanceLayout.d.ts.map +0 -1
  134. package/dist/cjs/default/spatial-react-components/primitives.d.ts +0 -3
  135. package/dist/cjs/default/spatial-react-components/primitives.d.ts.map +0 -1
  136. package/dist/cjs/default/spatial-react-components/types.d.ts +0 -18
  137. package/dist/cjs/default/spatial-react-components/types.d.ts.map +0 -1
  138. package/dist/cjs/default/types.d.ts +0 -2
  139. package/dist/cjs/default/types.d.ts.map +0 -1
  140. package/dist/cjs/default/utils/debugTool.d.ts +0 -2
  141. package/dist/cjs/default/utils/debugTool.d.ts.map +0 -1
  142. package/dist/cjs/default/utils/getSession.d.ts +0 -6
  143. package/dist/cjs/default/utils/getSession.d.ts.map +0 -1
  144. package/dist/cjs/default/utils/index.d.ts +0 -3
  145. package/dist/cjs/default/utils/index.d.ts.map +0 -1
  146. package/dist/cjs/web/XRApp.d.ts +0 -21
  147. package/dist/cjs/web/XRApp.d.ts.map +0 -1
  148. package/dist/cjs/web/index.d.ts +0 -5
  149. package/dist/cjs/web/index.d.ts.map +0 -1
  150. package/dist/cjs/web/index.js.map +0 -7
  151. package/dist/cjs/web/noRuntime.d.ts +0 -5
  152. package/dist/cjs/web/noRuntime.d.ts.map +0 -1
  153. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialComponent.d.ts +0 -3
  154. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialComponent.d.ts.map +0 -1
  155. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialDebugNameContext.d.ts +0 -2
  156. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialDebugNameContext.d.ts.map +0 -1
  157. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialDiv.d.ts +0 -6
  158. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialDiv.d.ts.map +0 -1
  159. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialLayerContext.d.ts +0 -2
  160. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialLayerContext.d.ts.map +0 -1
  161. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialRootContext.d.ts +0 -14
  162. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/CSSSpatialRootContext.d.ts.map +0 -1
  163. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/const.d.ts +0 -6
  164. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/const.d.ts.map +0 -1
  165. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/index.d.ts +0 -2
  166. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/index.d.ts.map +0 -1
  167. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/injectClassStyle.d.ts +0 -2
  168. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/injectClassStyle.d.ts.map +0 -1
  169. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/math/index.d.ts +0 -4
  170. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/math/index.d.ts.map +0 -1
  171. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/useHijackSpatialDivRef.d.ts +0 -4
  172. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/useHijackSpatialDivRef.d.ts.map +0 -1
  173. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/useSpatialStyle.d.ts +0 -29
  174. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/useSpatialStyle.d.ts.map +0 -1
  175. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/utils.d.ts +0 -7
  176. package/dist/cjs/web/spatial-react-components/CSSSpatialDiv/utils.d.ts.map +0 -1
  177. package/dist/cjs/web/spatial-react-components/Model/index.d.ts +0 -42
  178. package/dist/cjs/web/spatial-react-components/Model/index.d.ts.map +0 -1
  179. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3D.d.ts +0 -4
  180. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3D.d.ts.map +0 -1
  181. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3DNotInSpatialDiv.d.ts +0 -3
  182. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3DNotInSpatialDiv.d.ts.map +0 -1
  183. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3DPortalInstance.d.ts +0 -3
  184. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3DPortalInstance.d.ts.map +0 -1
  185. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3DStandardInstance.d.ts +0 -3
  186. package/dist/cjs/web/spatial-react-components/Model3D/CSSModel3DStandardInstance.d.ts.map +0 -1
  187. package/dist/cjs/web/spatial-react-components/Model3D/Model3D.d.ts +0 -3
  188. package/dist/cjs/web/spatial-react-components/Model3D/Model3D.d.ts.map +0 -1
  189. package/dist/cjs/web/spatial-react-components/Model3D/Model3DNative.d.ts +0 -48
  190. package/dist/cjs/web/spatial-react-components/Model3D/Model3DNative.d.ts.map +0 -1
  191. package/dist/cjs/web/spatial-react-components/Model3D/Model3DNotInSpatialDiv.d.ts +0 -3
  192. package/dist/cjs/web/spatial-react-components/Model3D/Model3DNotInSpatialDiv.d.ts.map +0 -1
  193. package/dist/cjs/web/spatial-react-components/Model3D/Model3DPortalInstance.d.ts +0 -3
  194. package/dist/cjs/web/spatial-react-components/Model3D/Model3DPortalInstance.d.ts.map +0 -1
  195. package/dist/cjs/web/spatial-react-components/Model3D/Model3DStandardInstance.d.ts +0 -3
  196. package/dist/cjs/web/spatial-react-components/Model3D/Model3DStandardInstance.d.ts.map +0 -1
  197. package/dist/cjs/web/spatial-react-components/Model3D/index.d.ts +0 -4
  198. package/dist/cjs/web/spatial-react-components/Model3D/index.d.ts.map +0 -1
  199. package/dist/cjs/web/spatial-react-components/Model3D/types.d.ts +0 -46
  200. package/dist/cjs/web/spatial-react-components/Model3D/types.d.ts.map +0 -1
  201. package/dist/cjs/web/spatial-react-components/Model3D/useDetectLayoutDomUpdated.d.ts +0 -2
  202. package/dist/cjs/web/spatial-react-components/Model3D/useDetectLayoutDomUpdated.d.ts.map +0 -1
  203. package/dist/cjs/web/spatial-react-components/Model3D/useModel3DNative.d.ts +0 -15
  204. package/dist/cjs/web/spatial-react-components/Model3D/useModel3DNative.d.ts.map +0 -1
  205. package/dist/cjs/web/spatial-react-components/Model3D/useSyncDomInfoFromStandardInstance.d.ts +0 -19
  206. package/dist/cjs/web/spatial-react-components/Model3D/useSyncDomInfoFromStandardInstance.d.ts.map +0 -1
  207. package/dist/cjs/web/spatial-react-components/Model3D/utils.d.ts +0 -4
  208. package/dist/cjs/web/spatial-react-components/Model3D/utils.d.ts.map +0 -1
  209. package/dist/cjs/web/spatial-react-components/SpatialMonitor.d.ts +0 -6
  210. package/dist/cjs/web/spatial-react-components/SpatialMonitor.d.ts.map +0 -1
  211. package/dist/cjs/web/spatial-react-components/SpatialPrimitive.d.ts +0 -6
  212. package/dist/cjs/web/spatial-react-components/SpatialPrimitive.d.ts.map +0 -1
  213. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/PortalInstance.d.ts +0 -20
  214. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/PortalInstance.d.ts.map +0 -1
  215. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialDebugNameContext.d.ts +0 -2
  216. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialDebugNameContext.d.ts.map +0 -1
  217. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialIsStandardInstanceContext.d.ts +0 -2
  218. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialIsStandardInstanceContext.d.ts.map +0 -1
  219. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialLayerContext.d.ts +0 -2
  220. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialLayerContext.d.ts.map +0 -1
  221. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialReactComponent.d.ts +0 -3
  222. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialReactComponent.d.ts.map +0 -1
  223. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialReactContext.d.ts +0 -24
  224. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialReactContext.d.ts.map +0 -1
  225. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialWindowManager.d.ts +0 -17
  226. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialWindowManager.d.ts.map +0 -1
  227. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialWindowManagerContext.d.ts +0 -3
  228. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/SpatialWindowManagerContext.d.ts.map +0 -1
  229. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/StandardInstance.d.ts +0 -10
  230. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/StandardInstance.d.ts.map +0 -1
  231. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/const.d.ts +0 -2
  232. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/const.d.ts.map +0 -1
  233. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/index.d.ts +0 -3
  234. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/index.d.ts.map +0 -1
  235. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/types.d.ts +0 -31
  236. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/types.d.ts.map +0 -1
  237. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/usePortalContainer.d.ts +0 -8
  238. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/usePortalContainer.d.ts.map +0 -1
  239. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/utils.d.ts +0 -15
  240. package/dist/cjs/web/spatial-react-components/SpatialReactComponent/utils.d.ts.map +0 -1
  241. package/dist/cjs/web/spatial-react-components/SpatialView.d.ts +0 -15
  242. package/dist/cjs/web/spatial-react-components/SpatialView.d.ts.map +0 -1
  243. package/dist/cjs/web/spatial-react-components/hooks/useForceUpdate.d.ts +0 -2
  244. package/dist/cjs/web/spatial-react-components/hooks/useForceUpdate.d.ts.map +0 -1
  245. package/dist/cjs/web/spatial-react-components/hooks/useMonitorDocumentHeaderChange.d.ts +0 -2
  246. package/dist/cjs/web/spatial-react-components/hooks/useMonitorDocumentHeaderChange.d.ts.map +0 -1
  247. package/dist/cjs/web/spatial-react-components/hooks/useMonitorDomChange.d.ts +0 -2
  248. package/dist/cjs/web/spatial-react-components/hooks/useMonitorDomChange.d.ts.map +0 -1
  249. package/dist/cjs/web/spatial-react-components/index.d.ts +0 -11
  250. package/dist/cjs/web/spatial-react-components/index.d.ts.map +0 -1
  251. package/dist/cjs/web/spatial-react-components/notifyUpdateStandInstanceLayout.d.ts +0 -13
  252. package/dist/cjs/web/spatial-react-components/notifyUpdateStandInstanceLayout.d.ts.map +0 -1
  253. package/dist/cjs/web/spatial-react-components/primitives.d.ts +0 -3
  254. package/dist/cjs/web/spatial-react-components/primitives.d.ts.map +0 -1
  255. package/dist/cjs/web/spatial-react-components/types.d.ts +0 -18
  256. package/dist/cjs/web/spatial-react-components/types.d.ts.map +0 -1
  257. package/dist/cjs/web/types.d.ts +0 -2
  258. package/dist/cjs/web/types.d.ts.map +0 -1
  259. package/dist/cjs/web/utils/debugTool.d.ts +0 -2
  260. package/dist/cjs/web/utils/debugTool.d.ts.map +0 -1
  261. package/dist/cjs/web/utils/getSession.d.ts +0 -6
  262. package/dist/cjs/web/utils/getSession.d.ts.map +0 -1
  263. package/dist/cjs/web/utils/index.d.ts +0 -3
  264. package/dist/cjs/web/utils/index.d.ts.map +0 -1
  265. package/dist/jsx/injectSceneHook.d.ts +0 -2
  266. package/dist/jsx/injectSceneHook.d.ts.map +0 -1
  267. package/dist/jsx/jsx-dev-runtime.d.ts.map +0 -1
  268. package/dist/jsx/jsx-runtime.d.ts.map +0 -1
  269. package/dist/jsx/jsx-shared.d.ts +0 -6
  270. package/dist/jsx/jsx-shared.d.ts.map +0 -1
  271. package/dist/jsx/spatialPolyfill.d.ts +0 -2
  272. package/dist/jsx/spatialPolyfill.d.ts.map +0 -1
  273. package/npm/index.d.ts +0 -1
  274. package/npm/index.js +0 -7
@@ -0,0 +1,3346 @@
1
+ // src/spatial-react-components/SpatialPrimitive.tsx
2
+ import { forwardRef as forwardRef3 } from "react";
3
+
4
+ // src/spatial-react-components/primitives.ts
5
+ var primitives = [
6
+ "a",
7
+ "abbr",
8
+ "address",
9
+ "area",
10
+ "article",
11
+ "aside",
12
+ "audio",
13
+ "b",
14
+ "base",
15
+ "bdi",
16
+ "bdo",
17
+ "big",
18
+ "blockquote",
19
+ "body",
20
+ "br",
21
+ "button",
22
+ "canvas",
23
+ "caption",
24
+ "cite",
25
+ "code",
26
+ "col",
27
+ "colgroup",
28
+ "data",
29
+ "datalist",
30
+ "dd",
31
+ "del",
32
+ "details",
33
+ "dfn",
34
+ "dialog",
35
+ "div",
36
+ "dl",
37
+ "dt",
38
+ "em",
39
+ "embed",
40
+ "fieldset",
41
+ "figcaption",
42
+ "figure",
43
+ "footer",
44
+ "form",
45
+ "h1",
46
+ "h2",
47
+ "h3",
48
+ "h4",
49
+ "h5",
50
+ "h6",
51
+ "head",
52
+ "header",
53
+ "hgroup",
54
+ "hr",
55
+ "html",
56
+ "i",
57
+ "iframe",
58
+ "img",
59
+ "input",
60
+ "ins",
61
+ "kbd",
62
+ "keygen",
63
+ "label",
64
+ "legend",
65
+ "li",
66
+ "link",
67
+ "main",
68
+ "map",
69
+ "mark",
70
+ "menu",
71
+ "menuitem",
72
+ "meta",
73
+ "meter",
74
+ "nav",
75
+ "noscript",
76
+ "object",
77
+ "ol",
78
+ "optgroup",
79
+ "option",
80
+ "output",
81
+ "p",
82
+ "param",
83
+ "picture",
84
+ "pre",
85
+ "progress",
86
+ "q",
87
+ "rp",
88
+ "rt",
89
+ "ruby",
90
+ "s",
91
+ "samp",
92
+ "script",
93
+ "section",
94
+ "select",
95
+ "small",
96
+ "source",
97
+ "span",
98
+ "strong",
99
+ "style",
100
+ "sub",
101
+ "summary",
102
+ "sup",
103
+ "table",
104
+ "tbody",
105
+ "td",
106
+ "textarea",
107
+ "tfoot",
108
+ "th",
109
+ "thead",
110
+ "time",
111
+ "title",
112
+ "tr",
113
+ "track",
114
+ "u",
115
+ "ul",
116
+ "var",
117
+ "video",
118
+ "wbr",
119
+ // SVG
120
+ "circle",
121
+ "clipPath",
122
+ "defs",
123
+ "ellipse",
124
+ "foreignObject",
125
+ "g",
126
+ "image",
127
+ "line",
128
+ "linearGradient",
129
+ "mask",
130
+ "path",
131
+ "pattern",
132
+ "polygon",
133
+ "polyline",
134
+ "radialGradient",
135
+ "rect",
136
+ "stop",
137
+ "svg",
138
+ "text",
139
+ "tspan"
140
+ ];
141
+
142
+ // src/spatial-react-components/SpatialReactComponent/SpatialReactComponent.tsx
143
+ import { forwardRef as forwardRef2, useMemo as useMemo2, useContext as useContext4 } from "react";
144
+
145
+ // src/utils/getSession.ts
146
+ import { Spatial } from "@webspatial/core-sdk";
147
+ var spatial = null;
148
+ var _currentSession = null;
149
+ function getSession() {
150
+ if ("false") return null;
151
+ if (!spatial) {
152
+ spatial = new Spatial();
153
+ }
154
+ if (!spatial.isSupported()) {
155
+ return null;
156
+ }
157
+ if (_currentSession) {
158
+ return _currentSession;
159
+ }
160
+ _currentSession = spatial.requestSession();
161
+ return _currentSession;
162
+ }
163
+
164
+ // src/utils/debugTool.ts
165
+ async function getStat() {
166
+ if ("false") return;
167
+ const statsInfo = await getSession()._getStats();
168
+ return statsInfo;
169
+ }
170
+ function simplifyEntityTree(rootTree) {
171
+ const rootEntity = Object.values(rootTree.childEntities)[0];
172
+ function traverseTree(node, parent, callback) {
173
+ callback(node, parent);
174
+ const childrenNodes = Object.values(node.childEntities);
175
+ if (childrenNodes) {
176
+ childrenNodes.forEach((child) => {
177
+ traverseTree(child, node, callback);
178
+ });
179
+ }
180
+ }
181
+ let rootNode;
182
+ const nodeMap = {};
183
+ function visitNode(node, parent) {
184
+ let newNode = {
185
+ id: node.id,
186
+ name: node.name,
187
+ children: [],
188
+ position: node.position,
189
+ scale: node.scale,
190
+ width: node.components[0].resolutionX,
191
+ height: node.components[0].resolutionY,
192
+ zIndex: node.zIndex,
193
+ visible: node.visible,
194
+ cornerRadius: node.components[0].cornerRadius,
195
+ backgroundMaterial: node.components[0].backgroundMaterial,
196
+ isOpaque: node.components[0].isOpaque
197
+ };
198
+ nodeMap[node.id] = newNode;
199
+ if (!parent) {
200
+ rootNode = newNode;
201
+ } else {
202
+ const parentNode = nodeMap[parent.id];
203
+ parentNode.children.push(newNode);
204
+ }
205
+ }
206
+ traverseTree(rootEntity, null, visitNode);
207
+ console.log("rootNode", rootNode);
208
+ return rootNode;
209
+ }
210
+ async function inspectRootWindowContainer(simple) {
211
+ const rootWindowContainerInfo = await getSession()._inspectRootWindowContainer();
212
+ console.log(rootWindowContainerInfo);
213
+ if (simple) {
214
+ return simplifyEntityTree(rootWindowContainerInfo);
215
+ }
216
+ return rootWindowContainerInfo;
217
+ }
218
+ function enableDebugTool() {
219
+ if ("false") return;
220
+ const session = getSession();
221
+ Object.assign(window, {
222
+ session,
223
+ getStat,
224
+ inspectRootWindowContainer
225
+ });
226
+ }
227
+
228
+ // src/spatial-react-components/SpatialReactComponent/StandardInstance.tsx
229
+ import {
230
+ useRef,
231
+ useLayoutEffect,
232
+ useEffect,
233
+ useContext,
234
+ forwardRef
235
+ } from "react";
236
+
237
+ // src/spatial-react-components/hooks/useForceUpdate.ts
238
+ import { useState } from "react";
239
+ function useForceUpdate() {
240
+ const [, setToggle] = useState(false);
241
+ return () => setToggle((toggle) => !toggle);
242
+ }
243
+
244
+ // src/spatial-react-components/SpatialReactComponent/SpatialIsStandardInstanceContext.ts
245
+ import { createContext } from "react";
246
+ var SpatialIsStandardInstanceContext = createContext(
247
+ null
248
+ );
249
+
250
+ // src/spatial-react-components/SpatialReactComponent/SpatialReactContext.ts
251
+ import { createContext as createContext2 } from "react";
252
+
253
+ // src/spatial-react-components/SpatialReactComponent/const.ts
254
+ var SpatialID = "data-spatial-id";
255
+
256
+ // src/spatial-react-components/SpatialReactComponent/SpatialReactContext.ts
257
+ var SpatialReactContextObject = class {
258
+ debugName;
259
+ constructor(debugName) {
260
+ this.debugName = debugName;
261
+ }
262
+ dom = null;
263
+ domSpatialId = null;
264
+ fns = {};
265
+ // cache dom for each spatialId
266
+ spatialId2dom = {};
267
+ spatialId2parentSpatialDom = {};
268
+ // layer : [standardInstance sequence, portalInstance sequence]
269
+ layerSequences = {};
270
+ getSpatialID(layer, isInStandardInstance, debugName = "") {
271
+ if (this.layerSequences[layer] === void 0) {
272
+ this.layerSequences[layer] = [0, 0];
273
+ }
274
+ const idx = isInStandardInstance ? 0 : 1;
275
+ const sequenceId = this.layerSequences[layer][idx];
276
+ this.layerSequences[layer][idx] = sequenceId + 1;
277
+ const spatialId = `${debugName}_${layer}_${sequenceId}`;
278
+ return spatialId;
279
+ }
280
+ onDomChange(spatialId, fn) {
281
+ this.fns[spatialId] = fn;
282
+ if (this.dom) {
283
+ fn();
284
+ }
285
+ }
286
+ offDomChange(spatialId) {
287
+ delete this.fns[spatialId];
288
+ delete this.spatialId2dom[spatialId];
289
+ delete this.spatialId2parentSpatialDom[spatialId];
290
+ }
291
+ notifyDomChange(dom) {
292
+ this.dom = dom;
293
+ this.domSpatialId = dom.getAttribute(SpatialID);
294
+ Object.values(this.fns).forEach((fn) => fn());
295
+ }
296
+ querySpatialDom(spatialId) {
297
+ if (this.domSpatialId === spatialId) {
298
+ return this.dom;
299
+ }
300
+ if (!this.dom) {
301
+ return null;
302
+ }
303
+ if (!this.spatialId2dom[spatialId]) {
304
+ const spatialDom = this.dom.querySelector(`[${SpatialID}="${spatialId}"]`);
305
+ if (spatialDom) {
306
+ this.spatialId2dom[spatialId] = spatialDom;
307
+ }
308
+ }
309
+ return this.spatialId2dom[spatialId];
310
+ }
311
+ queryParentSpatialDom(spatialId) {
312
+ if (this.domSpatialId === spatialId) {
313
+ return null;
314
+ }
315
+ if (this.spatialId2parentSpatialDom[spatialId]) {
316
+ return this.spatialId2parentSpatialDom[spatialId];
317
+ }
318
+ let spatialDom = this.querySpatialDom(spatialId);
319
+ if (spatialDom) {
320
+ if (spatialDom === this.dom) return null;
321
+ let parentSpatialDom = spatialDom.parentElement;
322
+ while (parentSpatialDom && spatialDom !== this.dom) {
323
+ if (parentSpatialDom.hasAttribute(SpatialID)) {
324
+ break;
325
+ } else {
326
+ parentSpatialDom = parentSpatialDom.parentElement;
327
+ }
328
+ }
329
+ this.spatialId2parentSpatialDom[spatialId] = parentSpatialDom;
330
+ return parentSpatialDom;
331
+ }
332
+ return null;
333
+ }
334
+ // Used for CSSModel3D
335
+ // layer : [standardInstance sequence, portalInstance sequence]
336
+ subDivLayerSequences = {};
337
+ subDivEventHandlers = {};
338
+ getSubDivSpatialID(layer, isInStandardInstance, prefix = "") {
339
+ if (this.subDivLayerSequences[layer] === void 0) {
340
+ this.subDivLayerSequences[layer] = [0, 0];
341
+ }
342
+ const idx = isInStandardInstance ? 0 : 1;
343
+ const sequenceId = this.subDivLayerSequences[layer][idx];
344
+ this.subDivLayerSequences[layer][idx] = sequenceId + 1;
345
+ const spatialId = `${prefix}_${layer}_${sequenceId}`;
346
+ return spatialId;
347
+ }
348
+ onSubDivEvent(subSpatialId, eventHandler) {
349
+ this.subDivEventHandlers[subSpatialId] = eventHandler;
350
+ }
351
+ offSubDivEvent(subSpatialId) {
352
+ delete this.subDivEventHandlers[subSpatialId];
353
+ }
354
+ notifySubDivEvent(subSpatialId, args) {
355
+ const eventHandler = this.subDivEventHandlers[subSpatialId];
356
+ if (eventHandler) {
357
+ eventHandler(args);
358
+ }
359
+ }
360
+ };
361
+ var SpatialReactContext = createContext2(null);
362
+
363
+ // src/spatial-react-components/SpatialReactComponent/StandardInstance.tsx
364
+ import { jsx } from "react/jsx-runtime";
365
+ function useDetectDomRectChange() {
366
+ const ref = useRef(null);
367
+ const forceUpdate = useForceUpdate();
368
+ const spatialReactContextObject = useContext(SpatialReactContext);
369
+ useLayoutEffect(() => {
370
+ ref.current && spatialReactContextObject?.notifyDomChange(ref.current);
371
+ });
372
+ useEffect(() => {
373
+ if (!ref.current || !spatialReactContextObject) {
374
+ console.warn(
375
+ "Ref is not attached to the DOM or spatialReactContextObject is not available"
376
+ );
377
+ return;
378
+ }
379
+ const handleResize = () => {
380
+ forceUpdate();
381
+ };
382
+ window.addEventListener("resize", handleResize);
383
+ return () => {
384
+ window.removeEventListener("resize", handleResize);
385
+ };
386
+ }, [spatialReactContextObject]);
387
+ useEffect(() => {
388
+ if (!ref.current) {
389
+ console.warn("Ref is not attached to the DOM");
390
+ return;
391
+ }
392
+ let ro = new ResizeObserver((elements) => {
393
+ forceUpdate();
394
+ });
395
+ ro.observe(ref.current);
396
+ return () => {
397
+ ro.disconnect();
398
+ };
399
+ }, []);
400
+ useEffect(() => {
401
+ if (!ref.current) {
402
+ console.warn("Ref is not attached to the DOM");
403
+ return;
404
+ }
405
+ let ro = new MutationObserver((elements) => {
406
+ forceUpdate();
407
+ });
408
+ ro.observe(ref.current, {
409
+ attributeFilter: ["class", "style"],
410
+ subtree: true
411
+ });
412
+ return () => {
413
+ ro.disconnect();
414
+ };
415
+ }, []);
416
+ return ref;
417
+ }
418
+ var StandardInstance = forwardRef(function(inProps, refIn) {
419
+ const { El, style: inStyle, debugShowStandardInstance, ...props } = inProps;
420
+ const extraStyle = {
421
+ visibility: debugShowStandardInstance ? void 0 : "hidden",
422
+ transition: "none"
423
+ };
424
+ const style = { ...inStyle, ...extraStyle };
425
+ var ref = useDetectDomRectChange();
426
+ const proxyRef = new Proxy(ref, {
427
+ get(target, prop, receiver) {
428
+ return Reflect.get(target, prop, receiver);
429
+ },
430
+ set(target, prop, value, receiver) {
431
+ if (prop === "current") {
432
+ const domElement = value;
433
+ if (refIn) {
434
+ if (typeof refIn === "function") {
435
+ refIn(domElement);
436
+ } else {
437
+ refIn.current = domElement;
438
+ }
439
+ }
440
+ }
441
+ return Reflect.set(target, prop, value, receiver);
442
+ }
443
+ });
444
+ return /* @__PURE__ */ jsx(SpatialIsStandardInstanceContext.Provider, { value: true, children: /* @__PURE__ */ jsx(El, { "data-standardinstance": true, ref: proxyRef, style, ...props }) });
445
+ });
446
+ StandardInstance.displayName = "StandardInstance";
447
+
448
+ // src/spatial-react-components/SpatialReactComponent/PortalInstance.tsx
449
+ import {
450
+ useRef as useRef3,
451
+ useCallback,
452
+ useEffect as useEffect3,
453
+ useState as useState2,
454
+ useContext as useContext3,
455
+ useMemo
456
+ } from "react";
457
+ import { createPortal } from "react-dom";
458
+
459
+ // src/spatial-react-components/SpatialReactComponent/usePortalContainer.tsx
460
+ import { useContext as useContext2, useRef as useRef2, useEffect as useEffect2 } from "react";
461
+
462
+ // src/spatial-react-components/SpatialReactComponent/SpatialWindowManager.ts
463
+ var SpatialWindowManager = class {
464
+ initPromise;
465
+ entity;
466
+ webview;
467
+ window = null;
468
+ setDebugName(debugName) {
469
+ this.entity?._setName(debugName);
470
+ }
471
+ async initInternal(url) {
472
+ if ("false") return;
473
+ this.entity = await getSession().createEntity();
474
+ this.webview = await getSession().createWindowComponent();
475
+ await this.webview.loadURL(url);
476
+ await this.entity.setCoordinateSpace("Dom");
477
+ await this.webview.setScrollWithParent(true);
478
+ await this.webview.setScrollEnabled(false);
479
+ await this.entity.setComponent(this.webview);
480
+ var wc = await getSession().getCurrentWindowComponent();
481
+ var ent = await wc.getEntity();
482
+ await this.entity.setParent(ent);
483
+ }
484
+ async initInternalFromWindow(parentSpatialWindowManager) {
485
+ if ("false") return;
486
+ var w = await getSession().createWindowContext();
487
+ this.window = w;
488
+ this.entity = await getSession().createEntity();
489
+ this.webview = await getSession().createWindowComponent();
490
+ await this.webview.setFromWindow(w);
491
+ await this.entity.setCoordinateSpace("Dom");
492
+ await this.webview.setScrollWithParent(true);
493
+ await this.webview.setScrollEnabled(false);
494
+ await this.entity.setComponent(this.webview);
495
+ if (parentSpatialWindowManager !== void 0) {
496
+ if (parentSpatialWindowManager !== null) {
497
+ await parentSpatialWindowManager.initPromise;
498
+ this.entity.setParent(parentSpatialWindowManager.entity);
499
+ } else {
500
+ var wc = await getSession().getCurrentWindowComponent();
501
+ var ent = await wc.getEntity();
502
+ await this.entity.setParent(ent);
503
+ }
504
+ }
505
+ }
506
+ async init(url) {
507
+ this.initPromise = this.initInternal(url);
508
+ await this.initPromise;
509
+ }
510
+ async initFromWidow(parentSpatialWindowManager) {
511
+ this.initPromise = this.initInternalFromWindow(parentSpatialWindowManager);
512
+ await this.initPromise;
513
+ }
514
+ async resize(rect, offset, rotation = { x: 0, y: 0, z: 0, w: 1 }, scale = { x: 1, y: 1, z: 1 }, rotationOrigin = { x: 0, y: 0, z: 0 }) {
515
+ let targetPosX = rect.x + rect.width / 2;
516
+ let targetPosY = rect.y + rect.height / 2 + window.scrollY;
517
+ if (!this.webview) {
518
+ return;
519
+ }
520
+ var entity = this.entity;
521
+ entity.transform.position.x = targetPosX + (offset ? offset.x : 0);
522
+ entity.transform.position.y = targetPosY + (offset ? offset.y : 0);
523
+ entity.transform.position.z = offset ? offset.z : 0;
524
+ entity.transform.orientation.x = rotation.x;
525
+ entity.transform.orientation.y = rotation.y;
526
+ entity.transform.orientation.z = rotation.z;
527
+ entity.transform.orientation.w = rotation.w;
528
+ entity.transform.scale.x = scale.x;
529
+ entity.transform.scale.y = scale.y;
530
+ entity.transform.scale.z = scale.z;
531
+ await entity.updateTransform();
532
+ var webview = this.webview;
533
+ await webview.setResolution(rect.width, rect.height);
534
+ await webview.setRotationAnchor(rotationOrigin);
535
+ }
536
+ async setZIndex(zIndex) {
537
+ let entity = this.entity;
538
+ entity.updateZIndex(zIndex);
539
+ }
540
+ async destroy() {
541
+ if (this.initPromise) {
542
+ await this.initPromise;
543
+ this.entity?.destroy();
544
+ this.webview?.destroy();
545
+ this.window = null;
546
+ }
547
+ }
548
+ };
549
+
550
+ // src/spatial-react-components/SpatialReactComponent/SpatialWindowManagerContext.ts
551
+ import { createContext as createContext3 } from "react";
552
+ var SpatialWindowManagerContext = createContext3(null);
553
+
554
+ // src/spatial-react-components/SpatialReactComponent/usePortalContainer.tsx
555
+ function usePortalContainer(options) {
556
+ const isStandard = useContext2(SpatialIsStandardInstanceContext);
557
+ const parentSpatialWindowManager = useContext2(SpatialWindowManagerContext);
558
+ const forceUpdate = useForceUpdate();
559
+ const spatialWindowManagerRef = useRef2();
560
+ useEffect2(() => {
561
+ let isDestroyed = false;
562
+ let spawnedResult;
563
+ async function asyncCreatePortalContainer() {
564
+ const session = getSession();
565
+ let windowMgr = new SpatialWindowManager();
566
+ await windowMgr.initFromWidow(parentSpatialWindowManager);
567
+ if (isDestroyed) {
568
+ windowMgr.destroy();
569
+ return;
570
+ }
571
+ spawnedResult = await options.onContainerSpawned(windowMgr);
572
+ if (isDestroyed) {
573
+ options.onContainerDestroyed(windowMgr, spawnedResult);
574
+ windowMgr.destroy();
575
+ return;
576
+ }
577
+ spatialWindowManagerRef.current = windowMgr;
578
+ forceUpdate();
579
+ }
580
+ if (isStandard !== true) {
581
+ asyncCreatePortalContainer();
582
+ }
583
+ return () => {
584
+ isDestroyed = true;
585
+ const spatialWindowManager = spatialWindowManagerRef.current;
586
+ if (spatialWindowManager) {
587
+ options.onContainerDestroyed(spatialWindowManager, spawnedResult);
588
+ spatialWindowManager.destroy();
589
+ }
590
+ };
591
+ }, []);
592
+ return [spatialWindowManagerRef.current];
593
+ }
594
+
595
+ // src/spatial-react-components/SpatialReactComponent/utils.ts
596
+ function getInheritedStyleProps(computedStyle) {
597
+ var propNames = [
598
+ "azimuth",
599
+ "borderCollapse",
600
+ "borderSpacing",
601
+ "captionSide",
602
+ "color",
603
+ "cursor",
604
+ "direction",
605
+ "elevation",
606
+ "emptyCells",
607
+ "fontFamily",
608
+ "fontSize",
609
+ "fontStyle",
610
+ "fontVariant",
611
+ "fontWeight",
612
+ "font",
613
+ "letterSpacing",
614
+ "lineHeight",
615
+ "listStyleImage",
616
+ "listStylePosition",
617
+ "listStyleType",
618
+ "listStyle",
619
+ "orphans",
620
+ "pitchRange",
621
+ "pitch",
622
+ "quotes",
623
+ "richness",
624
+ "speakHeader",
625
+ "speakNumeral",
626
+ "speakPunctuation",
627
+ "speak",
628
+ "speechRate",
629
+ "stress",
630
+ "textAlign",
631
+ "textIndent",
632
+ "textTransform",
633
+ "visibility",
634
+ "voiceFamily",
635
+ "volume",
636
+ "whiteSpace",
637
+ "widows",
638
+ "wordSpacing",
639
+ // background also need to be synced
640
+ "background",
641
+ // position also need to be synced
642
+ "position"
643
+ ];
644
+ var props = {};
645
+ for (var cssName of propNames) {
646
+ if (computedStyle[cssName]) {
647
+ props[cssName] = computedStyle[cssName];
648
+ }
649
+ }
650
+ return props;
651
+ }
652
+ function domRect2rectType(from) {
653
+ return {
654
+ x: from.x,
655
+ y: from.y,
656
+ width: from.width,
657
+ height: from.height
658
+ };
659
+ }
660
+ function parseTransformOrigin(computedStyle) {
661
+ const transformOriginProperty = computedStyle.getPropertyValue("transform-origin");
662
+ const [x, y] = transformOriginProperty.split(" ").map(parseFloat);
663
+ const width = parseFloat(computedStyle.getPropertyValue("width"));
664
+ const height = parseFloat(computedStyle.getPropertyValue("height"));
665
+ return {
666
+ x: width > 0 ? x / width : 0.5,
667
+ y: height > 0 ? y / height : 0.5,
668
+ z: 0.5
669
+ };
670
+ }
671
+ function parseBorderRadius(borderProperty, width) {
672
+ if (borderProperty === "") {
673
+ return 0;
674
+ }
675
+ if (borderProperty.endsWith("%")) {
676
+ return width * parseFloat(borderProperty) / 100;
677
+ }
678
+ return parseFloat(borderProperty);
679
+ }
680
+ function parseCornerRadius(computedStyle) {
681
+ const width = parseFloat(computedStyle.getPropertyValue("width"));
682
+ const topLeftPropertyValue = computedStyle.getPropertyValue(
683
+ "border-top-left-radius"
684
+ );
685
+ const topRightPropertyValue = computedStyle.getPropertyValue(
686
+ "border-top-right-radius"
687
+ );
688
+ const bottomLeftPropertyValue = computedStyle.getPropertyValue(
689
+ "border-bottom-left-radius"
690
+ );
691
+ const bottomRightPropertyValue = computedStyle.getPropertyValue(
692
+ "border-bottom-right-radius"
693
+ );
694
+ const cornerRadius = {
695
+ topLeading: parseBorderRadius(topLeftPropertyValue, width),
696
+ bottomLeading: parseBorderRadius(bottomLeftPropertyValue, width),
697
+ topTrailing: parseBorderRadius(topRightPropertyValue, width),
698
+ bottomTrailing: parseBorderRadius(bottomRightPropertyValue, width)
699
+ };
700
+ return cornerRadius;
701
+ }
702
+
703
+ // src/spatial-react-components/SpatialReactComponent/SpatialDebugNameContext.ts
704
+ import { createContext as createContext4 } from "react";
705
+ var SpatialDebugNameContext = createContext4("");
706
+
707
+ // src/spatial-react-components/SpatialReactComponent/PortalInstance.tsx
708
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
709
+ function renderJSXPortalInstance(inProps, elWidth, elHeight, inheritedPortalStyle, className) {
710
+ const { El, style: inStyle = {}, className: _, ...props } = inProps;
711
+ const extraStyle = {
712
+ visibility: "visible",
713
+ position: "",
714
+ top: "0px",
715
+ left: "0px",
716
+ margin: "0px",
717
+ marginLeft: "0px",
718
+ marginRight: "0px",
719
+ marginTop: "0px",
720
+ marginBottom: "0px",
721
+ borderRadius: "0px",
722
+ overflow: ""
723
+ };
724
+ const elWHStyle = {
725
+ width: `${elWidth}px`,
726
+ height: `${elHeight}px`
727
+ };
728
+ const style = {
729
+ ...inStyle,
730
+ ...inheritedPortalStyle,
731
+ ...extraStyle,
732
+ ...elWHStyle
733
+ };
734
+ return /* @__PURE__ */ jsx2(El, { style, className, ...props });
735
+ }
736
+ function setOpenWindowStyle(openedWindow) {
737
+ openedWindow.document.documentElement.style.cssText += document.documentElement.style.cssText;
738
+ openedWindow.document.documentElement.style.backgroundColor = "transparent";
739
+ openedWindow.document.body.style.margin = "0px";
740
+ }
741
+ function handleOpenWindowDocumentClick(openedWindow) {
742
+ openedWindow.document.onclick = function(e) {
743
+ let element = e.target;
744
+ let found = false;
745
+ while (!found) {
746
+ if (element && element.tagName == "A") {
747
+ if (!element.onclick) {
748
+ window.location.href = element.href;
749
+ }
750
+ return false;
751
+ }
752
+ if (element && element.parentElement) {
753
+ element = element.parentElement;
754
+ } else {
755
+ break;
756
+ }
757
+ }
758
+ };
759
+ }
760
+ function asyncLoadStyleToChildWindow(childWindow, n, debugName) {
761
+ return new Promise((resolve) => {
762
+ n.href += "?uniqueURL=" + Math.random();
763
+ n.onerror = function() {
764
+ console.error(
765
+ "Failed to load style link",
766
+ debugName,
767
+ n.href
768
+ );
769
+ resolve(false);
770
+ };
771
+ n.onload = function() {
772
+ resolve(true);
773
+ };
774
+ childWindow.document.head.appendChild(n);
775
+ });
776
+ }
777
+ async function syncParentHeadToChild(childWindow, debugName) {
778
+ const styleLoadedPromises = [];
779
+ for (let i = document.head.children.length - 1; i >= 0; i--) {
780
+ let n = document.head.children[i].cloneNode(true);
781
+ if (n.nodeName == "LINK" && n.rel == "stylesheet" && n.href) {
782
+ const promise = asyncLoadStyleToChildWindow(
783
+ childWindow,
784
+ n,
785
+ debugName
786
+ );
787
+ styleLoadedPromises.push(promise);
788
+ } else {
789
+ childWindow.document.head.appendChild(n);
790
+ }
791
+ }
792
+ if (debugName) {
793
+ childWindow.document.title = debugName;
794
+ }
795
+ return Promise.all(styleLoadedPromises);
796
+ }
797
+ async function syncHeaderStyle(openedWindow, debugName) {
798
+ await syncParentHeadToChild(openedWindow, debugName);
799
+ const headObserver = new MutationObserver((mutations) => {
800
+ syncParentHeadToChild(openedWindow, debugName);
801
+ });
802
+ headObserver.observe(document.head, { childList: true, subtree: true });
803
+ return headObserver;
804
+ }
805
+ function syncDefaultSpatialStyle(openedWindow, debugName) {
806
+ const styleElement = document.createElement("style");
807
+ styleElement.type = "text/css";
808
+ styleElement.innerHTML = " .xr-spatial-default { --xr-back: 0.001; --xr-background-material: none } ";
809
+ openedWindow.document.head.appendChild(styleElement);
810
+ }
811
+ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity, stylePosition) {
812
+ let { allowScroll, scrollWithParent, style, spatialStyle = {} } = props;
813
+ let {
814
+ position = { x: 0, y: 0, z: 1 },
815
+ rotation = { x: 0, y: 0, z: 0, w: 1 },
816
+ scale = { x: 1, y: 1, z: 1 },
817
+ material = { type: "none" },
818
+ cornerRadius = cornerRadiusFromStyle,
819
+ zIndex = 0
820
+ } = spatialStyle;
821
+ let styleOverflow = style?.overflow;
822
+ const visible = useMemo(() => {
823
+ return spatialStyle.visible !== false && domRect.width > 0 && domRect.height > 0;
824
+ }, [spatialStyle.visible, domRect.width, domRect.height]);
825
+ if (position.x === void 0) position.x = 0;
826
+ if (position.y === void 0) position.y = 0;
827
+ if (position.z === void 0) position.z = 1;
828
+ if (scale.x === void 0) scale.x = 1;
829
+ if (scale.y === void 0) scale.y = 1;
830
+ if (scale.z === void 0) scale.z = 1;
831
+ const cornerRadiusObject = {
832
+ topLeading: 0,
833
+ bottomLeading: 0,
834
+ topTrailing: 0,
835
+ bottomTrailing: 0
836
+ };
837
+ if (typeof cornerRadius == "number") {
838
+ cornerRadiusObject.topLeading = cornerRadius;
839
+ cornerRadiusObject.bottomLeading = cornerRadius;
840
+ cornerRadiusObject.topTrailing = cornerRadius;
841
+ cornerRadiusObject.bottomTrailing = cornerRadius;
842
+ } else {
843
+ Object.assign(cornerRadiusObject, cornerRadius);
844
+ }
845
+ useEffect3(() => {
846
+ if (spatialWindowManager && spatialWindowManager.webview) {
847
+ const webview = spatialWindowManager.webview;
848
+ (async function() {
849
+ webview.setStyle({
850
+ material: { type: material.type },
851
+ cornerRadius: cornerRadiusObject
852
+ });
853
+ })();
854
+ }
855
+ }, [
856
+ spatialWindowManager,
857
+ material.type,
858
+ cornerRadiusObject.topLeading,
859
+ cornerRadiusObject.bottomLeading,
860
+ cornerRadiusObject.topTrailing,
861
+ cornerRadiusObject.bottomTrailing
862
+ ]);
863
+ useEffect3(() => {
864
+ if (spatialWindowManager && spatialWindowManager.webview) {
865
+ const webview = spatialWindowManager.webview;
866
+ (async function() {
867
+ webview.setScrollEnabled(allowScroll || styleOverflow == "scroll");
868
+ const isFixed = scrollWithParent == false || stylePosition == "fixed";
869
+ webview.setScrollWithParent(!isFixed);
870
+ })();
871
+ }
872
+ }, [
873
+ spatialWindowManager,
874
+ allowScroll,
875
+ scrollWithParent,
876
+ stylePosition,
877
+ styleOverflow
878
+ ]);
879
+ useEffect3(() => {
880
+ if (spatialWindowManager) {
881
+ ;
882
+ (async function() {
883
+ await spatialWindowManager.resize(
884
+ domRect,
885
+ position,
886
+ rotation,
887
+ scale,
888
+ anchor
889
+ );
890
+ spatialWindowManager?.setZIndex(zIndex);
891
+ })();
892
+ }
893
+ }, [
894
+ spatialWindowManager,
895
+ domRect.x,
896
+ domRect.y,
897
+ domRect.width,
898
+ domRect.height,
899
+ position,
900
+ rotation,
901
+ scale,
902
+ anchor,
903
+ zIndex
904
+ ]);
905
+ useEffect3(() => {
906
+ if (spatialWindowManager && spatialWindowManager.webview) {
907
+ const webview = spatialWindowManager.webview;
908
+ webview.setOpacity(opacity);
909
+ }
910
+ }, [spatialWindowManager, opacity]);
911
+ useEffect3(() => {
912
+ if (spatialWindowManager) {
913
+ spatialWindowManager.entity?.setVisible(visible);
914
+ }
915
+ }, [spatialWindowManager, visible]);
916
+ useEffect3(() => {
917
+ if (spatialWindowManager?.window && spatialWindowManager.webview) {
918
+ ;
919
+ (async function() {
920
+ const bodyWidth = document.body.getBoundingClientRect().width;
921
+ const viewport = spatialWindowManager.window?.document.querySelector(
922
+ 'meta[name="viewport"]'
923
+ );
924
+ viewport?.setAttribute(
925
+ "content",
926
+ `width=${bodyWidth}, initial-scale=1.0 user-scalable=no`
927
+ );
928
+ await spatialWindowManager.webview?.setScrollEdgeInsets({
929
+ top: 0,
930
+ left: 0,
931
+ bottom: 0,
932
+ right: domRect.width - bodyWidth
933
+ });
934
+ })();
935
+ }
936
+ }, [spatialWindowManager, domRect.width]);
937
+ }
938
+ function useSyncDomRect(spatialId) {
939
+ const [domRect, setDomRect] = useState2({
940
+ x: 0,
941
+ y: 0,
942
+ width: 0,
943
+ height: 0
944
+ });
945
+ const inheritedPortalStyleRef = useRef3({});
946
+ const anchorRef = useRef3({
947
+ x: 0.5,
948
+ y: 0.5,
949
+ z: 0.5
950
+ });
951
+ const cornerRadiusRef = useRef3({
952
+ topLeading: 0,
953
+ bottomLeading: 0,
954
+ topTrailing: 0,
955
+ bottomTrailing: 0
956
+ });
957
+ const opacityRef = useRef3(1);
958
+ const spatialReactContextObject = useContext3(SpatialReactContext);
959
+ const inheritedPortalClassNameRef = useRef3("");
960
+ useEffect3(() => {
961
+ const syncDomRect = () => {
962
+ const dom = spatialReactContextObject?.querySpatialDom(spatialId);
963
+ if (!dom) {
964
+ return;
965
+ }
966
+ let domRect2 = dom.getBoundingClientRect();
967
+ let rectType = domRect2rectType(domRect2);
968
+ const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
969
+ if (parentDom) {
970
+ const parentDomRect = parentDom.getBoundingClientRect();
971
+ const parentRectType = domRect2rectType(parentDomRect);
972
+ rectType.x -= parentRectType.x;
973
+ rectType.y -= parentRectType.y;
974
+ }
975
+ const computedStyle = getComputedStyle(dom);
976
+ inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
977
+ const anchor = parseTransformOrigin(computedStyle);
978
+ anchorRef.current = anchor;
979
+ const cornerRadius = parseCornerRadius(computedStyle);
980
+ cornerRadiusRef.current = cornerRadius;
981
+ const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
982
+ opacityRef.current = opacity;
983
+ inheritedPortalClassNameRef.current = dom.className;
984
+ setDomRect(rectType);
985
+ };
986
+ spatialReactContextObject?.onDomChange(spatialId, syncDomRect);
987
+ return () => {
988
+ spatialReactContextObject?.offDomChange(spatialId);
989
+ };
990
+ }, []);
991
+ return {
992
+ domRect,
993
+ inheritedPortalStyle: inheritedPortalStyleRef.current,
994
+ anchor: anchorRef.current,
995
+ cornerRadius: cornerRadiusRef.current,
996
+ opacity: opacityRef.current,
997
+ className: inheritedPortalClassNameRef.current
998
+ };
999
+ }
1000
+ function PortalInstance(inProps) {
1001
+ const { allowScroll, scrollWithParent, spatialStyle, isSubPortal, ...props } = inProps;
1002
+ const debugName = useContext3(SpatialDebugNameContext);
1003
+ const onContainerSpawned = useCallback(
1004
+ async (spatialWindowManager2) => {
1005
+ const openWindow = spatialWindowManager2.window;
1006
+ setOpenWindowStyle(openWindow);
1007
+ handleOpenWindowDocumentClick(openWindow);
1008
+ syncDefaultSpatialStyle(openWindow, debugName);
1009
+ const headObserver = await syncHeaderStyle(openWindow, debugName);
1010
+ const spawnedResult = {
1011
+ headObserver
1012
+ };
1013
+ spatialWindowManager2.setDebugName(debugName);
1014
+ return spawnedResult;
1015
+ },
1016
+ []
1017
+ );
1018
+ const onContainerDestroyed = useCallback(
1019
+ (spatialWindowManager2, spawnedResult) => {
1020
+ const { headObserver } = spawnedResult;
1021
+ headObserver.disconnect();
1022
+ },
1023
+ []
1024
+ );
1025
+ const [spatialWindowManager] = usePortalContainer({
1026
+ onContainerSpawned,
1027
+ onContainerDestroyed
1028
+ });
1029
+ const spatialId = props[SpatialID];
1030
+ const {
1031
+ domRect,
1032
+ inheritedPortalStyle,
1033
+ anchor,
1034
+ cornerRadius,
1035
+ opacity,
1036
+ className
1037
+ } = useSyncDomRect(spatialId);
1038
+ useSyncSpatialProps(
1039
+ spatialWindowManager,
1040
+ {
1041
+ style: props.style,
1042
+ allowScroll,
1043
+ scrollWithParent,
1044
+ spatialStyle
1045
+ },
1046
+ domRect,
1047
+ anchor,
1048
+ cornerRadius,
1049
+ opacity,
1050
+ inheritedPortalStyle.position
1051
+ );
1052
+ const JSXPortalInstance = renderJSXPortalInstance(
1053
+ props,
1054
+ domRect.width,
1055
+ domRect.height,
1056
+ inheritedPortalStyle,
1057
+ className
1058
+ );
1059
+ const needRenderPlaceHolder = isSubPortal && inheritedPortalStyle.position !== "absolute" && inheritedPortalStyle.position !== "fixed";
1060
+ return /* @__PURE__ */ jsxs(SpatialWindowManagerContext.Provider, { value: spatialWindowManager, children: [
1061
+ needRenderPlaceHolder && /* @__PURE__ */ jsx2(
1062
+ "div",
1063
+ {
1064
+ className,
1065
+ style: {
1066
+ position: "relative",
1067
+ width: `${domRect.width}px`,
1068
+ height: `${domRect.height}px`
1069
+ }
1070
+ }
1071
+ ),
1072
+ spatialWindowManager && spatialWindowManager.window && createPortal(
1073
+ JSXPortalInstance,
1074
+ spatialWindowManager.window.document.body
1075
+ )
1076
+ ] });
1077
+ }
1078
+ PortalInstance.displayName = "PortalInstance";
1079
+
1080
+ // src/spatial-react-components/SpatialReactComponent/SpatialLayerContext.ts
1081
+ import { createContext as createContext5 } from "react";
1082
+ var SpatialLayerContext = createContext5(0);
1083
+
1084
+ // src/spatial-react-components/SpatialReactComponent/SpatialReactComponent.tsx
1085
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1086
+ function parseProps(inProps) {
1087
+ const {
1088
+ debugShowStandardInstance,
1089
+ debugName = "",
1090
+ component,
1091
+ allowScroll,
1092
+ spatialStyle,
1093
+ scrollWithParent,
1094
+ ...props
1095
+ } = inProps;
1096
+ const El = component ? component : "div";
1097
+ const componentDesc = { El };
1098
+ const spatialDesc = { spatialStyle, allowScroll, scrollWithParent };
1099
+ const debugDesc = { debugName, debugShowStandardInstance };
1100
+ return { componentDesc, spatialDesc, debugDesc, props };
1101
+ }
1102
+ function renderWebReactComponent(inProps, ref) {
1103
+ const { componentDesc, props } = parseProps(inProps);
1104
+ const { El } = componentDesc;
1105
+ return /* @__PURE__ */ jsx3(El, { ...props, ref });
1106
+ }
1107
+ function renderSpatialReactComponent(inProps, ref) {
1108
+ const { componentDesc, spatialDesc, debugDesc, props } = parseProps(inProps);
1109
+ const standardInstanceProps = {
1110
+ ...props,
1111
+ ...componentDesc,
1112
+ debugShowStandardInstance: debugDesc.debugShowStandardInstance
1113
+ };
1114
+ const portalInstanceProps = {
1115
+ ...props,
1116
+ ...componentDesc,
1117
+ ...spatialDesc
1118
+ };
1119
+ const spatialReactContextObject = useMemo2(
1120
+ () => new SpatialReactContextObject(debugDesc.debugName),
1121
+ []
1122
+ );
1123
+ return /* @__PURE__ */ jsxs2(SpatialReactContext.Provider, { value: spatialReactContextObject, children: [
1124
+ /* @__PURE__ */ jsx3(StandardInstance, { ...standardInstanceProps, ref }),
1125
+ /* @__PURE__ */ jsx3(PortalInstance, { isSubPortal: false, ...portalInstanceProps })
1126
+ ] });
1127
+ }
1128
+ function renderSubPortalInstance(inProps) {
1129
+ const { componentDesc, spatialDesc, props } = parseProps(inProps);
1130
+ const portalInstanceProps = {
1131
+ ...props,
1132
+ ...componentDesc,
1133
+ ...spatialDesc
1134
+ };
1135
+ return /* @__PURE__ */ jsx3(PortalInstance, { isSubPortal: true, ...portalInstanceProps });
1136
+ }
1137
+ function SpatialReactComponentRefactor(inProps, ref) {
1138
+ const layer = useContext4(SpatialLayerContext) + 1;
1139
+ const parentSpatialReactContextObject = useContext4(SpatialReactContext);
1140
+ const isRootInstance = !parentSpatialReactContextObject;
1141
+ const isInStandardInstance = !!useContext4(SpatialIsStandardInstanceContext);
1142
+ const spatialID = useMemo2(() => {
1143
+ return isRootInstance ? layer.toString() : parentSpatialReactContextObject.getSpatialID(
1144
+ layer,
1145
+ isInStandardInstance,
1146
+ inProps.debugName
1147
+ );
1148
+ }, []);
1149
+ const props = { ...inProps, [SpatialID]: spatialID };
1150
+ const contentInLayer = renderContentInLayer(props, ref);
1151
+ return /* @__PURE__ */ jsx3(SpatialDebugNameContext.Provider, { value: inProps.debugName || "", children: /* @__PURE__ */ jsx3(SpatialLayerContext.Provider, { value: layer, children: contentInLayer }) });
1152
+ }
1153
+ function renderContentInLayer(inProps, ref) {
1154
+ const isInStandardInstance = useContext4(SpatialIsStandardInstanceContext);
1155
+ const isWebSpatialEnv = getSession() !== null;
1156
+ if (isInStandardInstance || !isWebSpatialEnv) {
1157
+ return renderWebReactComponent(inProps, ref);
1158
+ } else {
1159
+ const parentSpatialReactContextObject = useContext4(SpatialReactContext);
1160
+ if (parentSpatialReactContextObject) {
1161
+ return renderSubPortalInstance(inProps);
1162
+ } else {
1163
+ return renderSpatialReactComponent(inProps, ref);
1164
+ }
1165
+ }
1166
+ }
1167
+ var SpatialReactComponent = forwardRef2(SpatialReactComponentRefactor);
1168
+ SpatialReactComponent.displayName = "SpatialReactComponent";
1169
+
1170
+ // src/spatial-react-components/SpatialPrimitive.tsx
1171
+ import { jsx as jsx4 } from "react/jsx-runtime";
1172
+ var cachedWithSpatialType = /* @__PURE__ */ new Map();
1173
+ function withSpatial(Component) {
1174
+ if (cachedWithSpatialType.has(Component)) {
1175
+ return cachedWithSpatialType.get(Component);
1176
+ } else {
1177
+ const WithSpatialComponent = forwardRef3(
1178
+ (givenProps, givenRef) => {
1179
+ const { component: ignoreComponent, ...props } = givenProps;
1180
+ return /* @__PURE__ */ jsx4(
1181
+ SpatialReactComponent,
1182
+ {
1183
+ component: Component,
1184
+ ...props,
1185
+ ref: givenRef
1186
+ }
1187
+ );
1188
+ }
1189
+ );
1190
+ WithSpatialComponent.displayName = `WithSpatial(${typeof Component === "string" ? Component : Component.displayName || Component.name})`;
1191
+ cachedWithSpatialType.set(Component, WithSpatialComponent);
1192
+ cachedWithSpatialType.set(WithSpatialComponent, WithSpatialComponent);
1193
+ return WithSpatialComponent;
1194
+ }
1195
+ }
1196
+ var SpatialPrimitive = {};
1197
+ (function createSpatialPrimitive(SpatialPrimitive2) {
1198
+ primitives.forEach((primitive) => {
1199
+ SpatialPrimitive2[primitive] = withSpatial(primitive);
1200
+ });
1201
+ })(SpatialPrimitive);
1202
+ var SpatialDiv = SpatialPrimitive.div;
1203
+
1204
+ // src/spatial-react-components/hooks/useMonitorDomChange.tsx
1205
+ import { useRef as useRef4, useEffect as useEffect4 } from "react";
1206
+
1207
+ // src/spatial-react-components/notifyUpdateStandInstanceLayout.ts
1208
+ function notifyUpdateStandInstanceLayout() {
1209
+ document.dispatchEvent(
1210
+ new CustomEvent("standInstanceLayout" /* standInstanceLayout */, {
1211
+ detail: {}
1212
+ })
1213
+ );
1214
+ }
1215
+ function notifyDOMUpdate(mutationsList) {
1216
+ document.dispatchEvent(
1217
+ new CustomEvent("domUpdated" /* domUpdated */, {
1218
+ detail: mutationsList
1219
+ })
1220
+ );
1221
+ }
1222
+
1223
+ // src/spatial-react-components/hooks/useMonitorDomChange.tsx
1224
+ function useMonitorDomChange() {
1225
+ const ref = useRef4(void 0);
1226
+ useEffect4(() => {
1227
+ const observer = new MutationObserver((mutationsList) => {
1228
+ notifyDOMUpdate(mutationsList);
1229
+ });
1230
+ const config = {
1231
+ childList: true,
1232
+ subtree: true,
1233
+ attributes: true,
1234
+ attributeFilter: ["style", "class"]
1235
+ };
1236
+ ref.current && observer.observe(ref.current, config);
1237
+ return () => {
1238
+ observer.disconnect();
1239
+ };
1240
+ }, []);
1241
+ return ref;
1242
+ }
1243
+
1244
+ // src/spatial-react-components/hooks/useMonitorDocumentHeaderChange.tsx
1245
+ import { useEffect as useEffect5 } from "react";
1246
+ function useMonitorDocumentHeaderChange() {
1247
+ useEffect5(() => {
1248
+ const observer = new MutationObserver((mutationsList) => {
1249
+ notifyUpdateStandInstanceLayout();
1250
+ });
1251
+ const config = {
1252
+ childList: true,
1253
+ subtree: true,
1254
+ attributes: true
1255
+ };
1256
+ observer.observe(document.head, config);
1257
+ return () => {
1258
+ observer.disconnect();
1259
+ };
1260
+ }, []);
1261
+ }
1262
+
1263
+ // src/spatial-react-components/SpatialMonitor.tsx
1264
+ import { jsxs as jsxs3 } from "react/jsx-runtime";
1265
+ function SpatialMonitor(props) {
1266
+ const { children, ...otherProps } = props;
1267
+ const ref = useMonitorDomChange();
1268
+ useMonitorDocumentHeaderChange();
1269
+ return /* @__PURE__ */ jsxs3("div", { ref, ...otherProps, children: [
1270
+ " ",
1271
+ children,
1272
+ " "
1273
+ ] });
1274
+ }
1275
+
1276
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialDiv.tsx
1277
+ import { forwardRef as forwardRef5 } from "react";
1278
+
1279
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialComponent.tsx
1280
+ import {
1281
+ forwardRef as forwardRef4,
1282
+ useContext as useContext5,
1283
+ useEffect as useEffect7,
1284
+ useMemo as useMemo3,
1285
+ useRef as useRef6
1286
+ } from "react";
1287
+
1288
+ // src/spatial-react-components/CSSSpatialDiv/useSpatialStyle.ts
1289
+ import { useCallback as useCallback2, useEffect as useEffect6, useRef as useRef5, useState as useState3 } from "react";
1290
+ import isEqual from "lodash.isequal";
1291
+
1292
+ // src/spatial-react-components/CSSSpatialDiv/math/index.ts
1293
+ import { Matrix4 } from "three/src/math/Matrix4.js";
1294
+ import { Vector3 } from "three/src/math/Vector3.js";
1295
+ import { Quaternion } from "three/src/math/Quaternion.js";
1296
+
1297
+ // src/spatial-react-components/CSSSpatialDiv/const.ts
1298
+ var SpatialCustomVars = {
1299
+ back: "--xr-back",
1300
+ backgroundMaterial: "--xr-background-material"
1301
+ };
1302
+ var BackgroundMaterialDefault = "none";
1303
+
1304
+ // src/spatial-react-components/CSSSpatialDiv/useSpatialStyle.ts
1305
+ function parse2dMatrix(transformDataArray) {
1306
+ const [n11, n21, n12, n22, n13, n23] = transformDataArray;
1307
+ const matrix4 = new Matrix4(
1308
+ n11,
1309
+ n12,
1310
+ 0,
1311
+ n13,
1312
+ n21,
1313
+ n22,
1314
+ 0,
1315
+ n23,
1316
+ 0,
1317
+ 0,
1318
+ 1,
1319
+ 0,
1320
+ 0,
1321
+ 0,
1322
+ 0,
1323
+ 1
1324
+ );
1325
+ return matrix4;
1326
+ }
1327
+ function parse3dMatrix(transformDataArray) {
1328
+ const matrix4 = new Matrix4().fromArray(transformDataArray);
1329
+ return matrix4;
1330
+ }
1331
+ function parseTransform(computedStyle) {
1332
+ let transform = computedStyle.getPropertyValue("transform");
1333
+ const matrixFlagString = "matrix(";
1334
+ const idxOfMatrix = transform.indexOf(matrixFlagString);
1335
+ if (idxOfMatrix !== -1) {
1336
+ const transformDataArray = transform.substring(matrixFlagString.length, transform.length - 1).split(",").map((item) => parseFloat(item));
1337
+ return parse2dMatrix(transformDataArray);
1338
+ } else {
1339
+ const matrix3dFlagString = "matrix3d(";
1340
+ const idxOfMatrix3d = transform.indexOf(matrix3dFlagString);
1341
+ if (idxOfMatrix3d !== -1) {
1342
+ const transform3dDataArray = transform.substring(matrix3dFlagString.length, transform.length - 1).split(",").map((item) => parseFloat(item));
1343
+ return parse3dMatrix(transform3dDataArray);
1344
+ } else {
1345
+ return new Matrix4();
1346
+ }
1347
+ }
1348
+ }
1349
+ function parseBack(computedStyle) {
1350
+ let useBackProperty = computedStyle.position === "absolute" || computedStyle.position === "relative" || computedStyle.position === "fixed";
1351
+ if (!useBackProperty) return new Matrix4();
1352
+ let backProperty = computedStyle.getPropertyValue(SpatialCustomVars.back);
1353
+ let back = void 0;
1354
+ try {
1355
+ back = parseFloat(backProperty);
1356
+ } catch (error) {
1357
+ }
1358
+ return new Matrix4().makeTranslation(0, 0, back || 1);
1359
+ }
1360
+ function parseSpatialStyle(node) {
1361
+ const computedStyle = getComputedStyle(node);
1362
+ const mat4ForBack = parseBack(computedStyle);
1363
+ const mat4ForTransform = parseTransform(computedStyle);
1364
+ const resultMatrix = new Matrix4();
1365
+ resultMatrix.multiplyMatrices(mat4ForBack, mat4ForTransform);
1366
+ const position = new Vector3();
1367
+ const quaternion = new Quaternion();
1368
+ const scale = new Vector3();
1369
+ resultMatrix.decompose(position, quaternion, scale);
1370
+ const zIndex = parseFloat(computedStyle.getPropertyValue("z-index"));
1371
+ const visible = computedStyle.getPropertyValue("visibility") === "visible";
1372
+ const backgroundMaterialType = computedStyle.getPropertyValue(
1373
+ SpatialCustomVars.backgroundMaterial
1374
+ );
1375
+ return {
1376
+ position: { x: position.x, y: position.y, z: position.z },
1377
+ rotation: {
1378
+ x: quaternion.x,
1379
+ y: quaternion.y,
1380
+ z: quaternion.z,
1381
+ w: quaternion.w
1382
+ },
1383
+ scale: { x: scale.x, y: scale.y, z: scale.z },
1384
+ zIndex,
1385
+ material: {
1386
+ type: backgroundMaterialType
1387
+ },
1388
+ visible
1389
+ };
1390
+ }
1391
+ function useSpatialStyle() {
1392
+ const ref = useRef5(null);
1393
+ const [spatialStyle, setSpatialStyle] = useState3({
1394
+ position: { x: 0, y: 0, z: 1 },
1395
+ rotation: { x: 0, y: 0, z: 0, w: 1 },
1396
+ scale: { x: 1, y: 1, z: 1 },
1397
+ zIndex: 0,
1398
+ material: {
1399
+ type: "none"
1400
+ },
1401
+ visible: true
1402
+ });
1403
+ const [ready, setReady] = useState3(false);
1404
+ const checkSpatialStyleUpdate = useCallback2(() => {
1405
+ const nextSpatialStyle = parseSpatialStyle(ref.current);
1406
+ if (!isEqual(spatialStyle, nextSpatialStyle)) {
1407
+ setSpatialStyle(nextSpatialStyle);
1408
+ }
1409
+ }, []);
1410
+ useEffect6(() => {
1411
+ if (!ref.current) {
1412
+ return;
1413
+ }
1414
+ const spatialStyle2 = parseSpatialStyle(ref.current);
1415
+ setSpatialStyle(spatialStyle2);
1416
+ setReady(true);
1417
+ }, []);
1418
+ useEffect6(() => {
1419
+ if (!ref.current) {
1420
+ return;
1421
+ }
1422
+ const observer = new MutationObserver((mutationsList) => {
1423
+ checkSpatialStyleUpdate();
1424
+ });
1425
+ const config = {
1426
+ childList: true,
1427
+ subtree: true,
1428
+ attributes: true,
1429
+ // attributeOldValue: true,
1430
+ attributeFilter: ["style", "class"]
1431
+ };
1432
+ observer.observe(ref.current, config);
1433
+ return () => {
1434
+ observer.disconnect();
1435
+ };
1436
+ }, []);
1437
+ useEffect6(() => {
1438
+ if (!ref.current) {
1439
+ return;
1440
+ }
1441
+ function isDescendant(child, parent) {
1442
+ if (child === parent) {
1443
+ return true;
1444
+ }
1445
+ let node = child;
1446
+ while (node) {
1447
+ if (node === parent) {
1448
+ return true;
1449
+ }
1450
+ node = node.parentElement;
1451
+ }
1452
+ return false;
1453
+ }
1454
+ const onDomUpdated = (event) => {
1455
+ const mutationsList = event.detail;
1456
+ const spatialReactComponentDiv = ref.current.previousElementSibling;
1457
+ const targets = mutationsList.map((m) => m.target).filter(
1458
+ (node) => node !== ref.current && !isDescendant(node, spatialReactComponentDiv)
1459
+ );
1460
+ if (targets.length > 0) {
1461
+ checkSpatialStyleUpdate();
1462
+ }
1463
+ };
1464
+ document.addEventListener(
1465
+ "domUpdated" /* domUpdated */,
1466
+ onDomUpdated
1467
+ );
1468
+ return () => {
1469
+ document.removeEventListener(
1470
+ "domUpdated" /* domUpdated */,
1471
+ onDomUpdated
1472
+ );
1473
+ };
1474
+ }, []);
1475
+ return { ref, ready, spatialStyle };
1476
+ }
1477
+
1478
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialDebugNameContext.ts
1479
+ import { createContext as createContext6 } from "react";
1480
+ var CSSSpatialDebugNameContext = createContext6("");
1481
+
1482
+ // src/spatial-react-components/CSSSpatialDiv/useHijackSpatialDivRef.ts
1483
+ import { useCallback as useCallback3 } from "react";
1484
+
1485
+ // src/spatial-react-components/CSSSpatialDiv/injectClassStyle.ts
1486
+ var InjectClassName = "xr-css-spatial-default";
1487
+ function injectClassStyle() {
1488
+ const style = document.createElement("style");
1489
+ style.innerHTML = `
1490
+ .${InjectClassName} {
1491
+ ${SpatialCustomVars.backgroundMaterial}: ${BackgroundMaterialDefault};
1492
+ }
1493
+ `;
1494
+ document.head.prepend(style);
1495
+ }
1496
+ injectClassStyle();
1497
+
1498
+ // src/spatial-react-components/CSSSpatialDiv/utils.ts
1499
+ function extractAndRemoveCustomProperties(cssText, properties) {
1500
+ if (!cssText) {
1501
+ return { extractedValues: {}, filteredCssText: "" };
1502
+ }
1503
+ const extractedValues = {};
1504
+ const rules = cssText.split(";");
1505
+ const filteredRules = rules.filter((rule) => {
1506
+ const [key, value] = rule.split(":").map((part) => part.trim());
1507
+ if (properties.includes(key)) {
1508
+ extractedValues[key] = value;
1509
+ return false;
1510
+ }
1511
+ return true;
1512
+ });
1513
+ const filteredCssText = filteredRules.join(";").trim();
1514
+ return { extractedValues, filteredCssText };
1515
+ }
1516
+ function joinToCSSText(cssKV) {
1517
+ const rules = Object.entries(cssKV).map(([key, value]) => `${key}: ${value}`);
1518
+ return rules.join(";");
1519
+ }
1520
+
1521
+ // src/spatial-react-components/CSSSpatialDiv/useHijackSpatialDivRef.ts
1522
+ function makeOriginalKey(key) {
1523
+ return `__original_${key}`;
1524
+ }
1525
+ function useHijackSpatialDivRef(refIn, cssParserRef) {
1526
+ const ref = cssParserRef;
1527
+ const spatialDivRef = useCallback3(
1528
+ (domElement) => {
1529
+ if (domElement && refIn) {
1530
+ const domStyle = domElement.style;
1531
+ const domStyleProxy = new Proxy(domStyle, {
1532
+ get(target, prop) {
1533
+ if (typeof target[prop] === "function") {
1534
+ return function(...args) {
1535
+ if (prop === "setProperty") {
1536
+ const [property, value] = args;
1537
+ if (property === SpatialCustomVars.backgroundMaterial) {
1538
+ ref.current?.style.setProperty(
1539
+ SpatialCustomVars.backgroundMaterial,
1540
+ value
1541
+ );
1542
+ } else if (property === SpatialCustomVars.back) {
1543
+ ref.current?.style.setProperty(
1544
+ SpatialCustomVars.back,
1545
+ value
1546
+ );
1547
+ } else if (property === "transform") {
1548
+ ref.current?.style.setProperty(property, value);
1549
+ return true;
1550
+ }
1551
+ } else if (prop === "removeProperty") {
1552
+ const [property] = args;
1553
+ if (property === SpatialCustomVars.backgroundMaterial || property === SpatialCustomVars.back || property === "transform") {
1554
+ ref.current?.style.removeProperty(property);
1555
+ }
1556
+ } else if (prop === "getPropertyValue") {
1557
+ const [property] = args;
1558
+ if (property === "transform") {
1559
+ return ref.current?.style[property];
1560
+ }
1561
+ }
1562
+ return target[prop](
1563
+ ...args
1564
+ );
1565
+ };
1566
+ }
1567
+ if (prop === "transform") {
1568
+ return ref.current?.style[prop];
1569
+ }
1570
+ if (prop === "visibility") {
1571
+ return ref.current?.style.visibility;
1572
+ }
1573
+ if (prop === "cssText") {
1574
+ }
1575
+ return Reflect.get(target, prop);
1576
+ },
1577
+ set(target, property, value) {
1578
+ if (property === SpatialCustomVars.backgroundMaterial) {
1579
+ ref.current?.style.setProperty(
1580
+ SpatialCustomVars.backgroundMaterial,
1581
+ value
1582
+ );
1583
+ } else if (property === SpatialCustomVars.back) {
1584
+ ref.current?.style.setProperty(
1585
+ SpatialCustomVars.back,
1586
+ value
1587
+ );
1588
+ } else if (property === "transform") {
1589
+ ref.current?.style.setProperty(property, value);
1590
+ return true;
1591
+ } else if (property === "visibility") {
1592
+ ref.current?.style.setProperty(property, value);
1593
+ return true;
1594
+ } else if (property === "cssText") {
1595
+ const toFilteredCSSProperties = [
1596
+ "transform",
1597
+ "visibility",
1598
+ SpatialCustomVars.back,
1599
+ SpatialCustomVars.backgroundMaterial
1600
+ ];
1601
+ const { extractedValues, filteredCssText } = extractAndRemoveCustomProperties(
1602
+ value,
1603
+ toFilteredCSSProperties
1604
+ );
1605
+ toFilteredCSSProperties.forEach((key) => {
1606
+ if (extractedValues[key]) {
1607
+ ref.current?.style.setProperty(key, extractedValues[key]);
1608
+ } else {
1609
+ ref.current?.style.removeProperty(key);
1610
+ }
1611
+ });
1612
+ const appendedCSSText = joinToCSSText({
1613
+ transform: "none",
1614
+ visibility: "hidden"
1615
+ });
1616
+ return Reflect.set(
1617
+ target,
1618
+ property,
1619
+ [appendedCSSText, filteredCssText].join(";")
1620
+ );
1621
+ }
1622
+ return Reflect.set(target, property, value);
1623
+ }
1624
+ });
1625
+ const domClassList = domElement.classList;
1626
+ const domClassMethodKeys = ["add", "remove", "toggle", "replace"];
1627
+ domClassMethodKeys.forEach((key) => {
1628
+ const hiddenKey = makeOriginalKey(key);
1629
+ const hiddenKeyExist = domClassList[hiddenKey] !== void 0;
1630
+ const originalMethod = hiddenKeyExist ? domClassList[hiddenKey] : domClassList[key].bind(domClassList);
1631
+ domClassList[hiddenKey] = originalMethod;
1632
+ domClassList[key] = function(...args) {
1633
+ const result = originalMethod(...args);
1634
+ if (ref.current) {
1635
+ ref.current.className = domElement.className + " " + InjectClassName;
1636
+ }
1637
+ return result;
1638
+ };
1639
+ });
1640
+ const __getComputedStyle = (originalGetComputedStyle, pseudoElt) => {
1641
+ return originalGetComputedStyle(domElement, pseudoElt);
1642
+ };
1643
+ const proxyDomElement = new Proxy(domElement, {
1644
+ get(target, prop) {
1645
+ if (prop === "style") {
1646
+ return domStyleProxy;
1647
+ }
1648
+ if (prop === "__isSpatialDiv") {
1649
+ return true;
1650
+ }
1651
+ if (prop === "__getComputedStyle") {
1652
+ return __getComputedStyle;
1653
+ }
1654
+ if (typeof target[prop] === "function") {
1655
+ return function(...args) {
1656
+ if ("removeAttribute" === prop) {
1657
+ const [property] = args;
1658
+ if (property === "style") {
1659
+ domStyleProxy.cssText = "";
1660
+ return true;
1661
+ }
1662
+ if (property === "class") {
1663
+ proxyDomElement.className = "";
1664
+ return true;
1665
+ }
1666
+ }
1667
+ return target[prop](...args);
1668
+ };
1669
+ }
1670
+ return Reflect.get(target, prop, target);
1671
+ },
1672
+ set(target, prop, value) {
1673
+ if (ref.current) {
1674
+ if (prop === "className") {
1675
+ ref.current.className = value + " " + InjectClassName;
1676
+ }
1677
+ if (prop === "style") {
1678
+ domStyleProxy.cssText = joinToCSSText(value);
1679
+ return true;
1680
+ }
1681
+ }
1682
+ return Reflect.set(target, prop, value);
1683
+ }
1684
+ });
1685
+ if (typeof refIn === "function") {
1686
+ refIn(proxyDomElement);
1687
+ } else {
1688
+ refIn.current = proxyDomElement;
1689
+ }
1690
+ } else if (refIn) {
1691
+ if (typeof refIn === "function") {
1692
+ refIn(null);
1693
+ } else {
1694
+ refIn.current = null;
1695
+ }
1696
+ }
1697
+ },
1698
+ [refIn]
1699
+ );
1700
+ return spatialDivRef;
1701
+ }
1702
+
1703
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialLayerContext.ts
1704
+ import { createContext as createContext7 } from "react";
1705
+ var CSSSpatialLayerContext = createContext7(0);
1706
+
1707
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialRootContext.ts
1708
+ import { createContext as createContext8 } from "react";
1709
+ var CSSSpatialID = "CSSSpatialID";
1710
+ var CSSSpatialRootContextObject = class {
1711
+ prefix = "css";
1712
+ domSpatialId = null;
1713
+ fns = {};
1714
+ // cache dom for each spatialId
1715
+ spatialId2dom = {};
1716
+ // layer : [standardInstance sequence, portalInstance sequence]
1717
+ layerSequences = {};
1718
+ getSpatialID(layer, isInStandardInstance, debugName = "") {
1719
+ if (this.layerSequences[layer] === void 0) {
1720
+ this.layerSequences[layer] = [0, 0];
1721
+ }
1722
+ const idx = isInStandardInstance ? 0 : 1;
1723
+ const sequenceId = this.layerSequences[layer][idx];
1724
+ this.layerSequences[layer][idx] = sequenceId + 1;
1725
+ const spatialId = `${this.prefix}_${debugName}_${layer}_${sequenceId}`;
1726
+ return spatialId;
1727
+ }
1728
+ onDomChange(spatialId, fn) {
1729
+ this.fns[spatialId] = fn;
1730
+ }
1731
+ offDomChange(spatialId, fn) {
1732
+ delete this.fns[spatialId];
1733
+ }
1734
+ setCSSParserRef(cssSpatialID, domElement) {
1735
+ if (domElement) {
1736
+ this.spatialId2dom[cssSpatialID] = domElement;
1737
+ } else {
1738
+ delete this.spatialId2dom[cssSpatialID];
1739
+ }
1740
+ this.fns[cssSpatialID]?.(domElement);
1741
+ }
1742
+ };
1743
+ var CSSSpatialRootContext = createContext8(null);
1744
+
1745
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialComponent.tsx
1746
+ import { Fragment, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1747
+ function renderRootCSSSpatialComponent(inProps, refIn) {
1748
+ const cssSpatialRootContextObject = useMemo3(
1749
+ () => new CSSSpatialRootContextObject(),
1750
+ []
1751
+ );
1752
+ const {
1753
+ style = {},
1754
+ className = "",
1755
+ children,
1756
+ debugName,
1757
+ debugShowStandardInstance,
1758
+ ...props
1759
+ } = inProps;
1760
+ const { ref, spatialStyle, ready } = useSpatialStyle();
1761
+ const divRefStyle = {
1762
+ ...style,
1763
+ width: 0,
1764
+ height: 0,
1765
+ padding: 0,
1766
+ transition: "none"
1767
+ };
1768
+ const spatialDivStyle = {
1769
+ ...style,
1770
+ transform: "none"
1771
+ };
1772
+ const El = inProps.component || "div";
1773
+ const spatialDivRef = useHijackSpatialDivRef(refIn, ref);
1774
+ const divRefClassName = className + " " + InjectClassName;
1775
+ return /* @__PURE__ */ jsxs4(CSSSpatialRootContext.Provider, { value: cssSpatialRootContextObject, children: [
1776
+ ready && /* @__PURE__ */ jsx5(
1777
+ SpatialReactComponent,
1778
+ {
1779
+ style: spatialDivStyle,
1780
+ className,
1781
+ children,
1782
+ ...props,
1783
+ spatialStyle,
1784
+ debugName,
1785
+ debugShowStandardInstance,
1786
+ ref: spatialDivRef
1787
+ }
1788
+ ),
1789
+ /* @__PURE__ */ jsx5(
1790
+ El,
1791
+ {
1792
+ style: divRefStyle,
1793
+ className: divRefClassName,
1794
+ ...props,
1795
+ ref,
1796
+ "data-cssparser": true
1797
+ }
1798
+ )
1799
+ ] });
1800
+ }
1801
+ function renderInWebEnv(props, ref) {
1802
+ return /* @__PURE__ */ jsx5(SpatialReactComponent, { ...props, ref });
1803
+ }
1804
+ function renderInStandardInstance(cssSpatialRootContextObject, cssSpatialID, inProps, refIn) {
1805
+ const { style: inStyle = {}, ...props } = inProps;
1806
+ const style = {
1807
+ ...inStyle,
1808
+ transform: "none",
1809
+ visibility: "hidden"
1810
+ };
1811
+ var cssParserRef = useRef6(null);
1812
+ const spatialDivRef = useHijackSpatialDivRef(refIn, cssParserRef);
1813
+ useEffect7(() => {
1814
+ const onDomChangeAction = (dom) => {
1815
+ cssParserRef.current = dom;
1816
+ };
1817
+ cssSpatialRootContextObject.onDomChange(cssSpatialID, onDomChangeAction);
1818
+ return () => {
1819
+ cssSpatialRootContextObject.offDomChange(cssSpatialID, onDomChangeAction);
1820
+ };
1821
+ }, []);
1822
+ return /* @__PURE__ */ jsx5(SpatialReactComponent, { style, ...props, ref: spatialDivRef });
1823
+ }
1824
+ function renderInPortalInstance(cssSpatialRootContextObject, cssSpatialID, inProps) {
1825
+ const {
1826
+ style = {},
1827
+ className = "",
1828
+ children,
1829
+ debugName,
1830
+ debugShowStandardInstance,
1831
+ ...props
1832
+ } = inProps;
1833
+ const { ref, spatialStyle, ready } = useSpatialStyle();
1834
+ const divRefStyle = {
1835
+ ...style,
1836
+ width: 0,
1837
+ height: 0,
1838
+ padding: 0,
1839
+ transition: "none"
1840
+ };
1841
+ const spatialDivStyle = {
1842
+ ...style,
1843
+ transform: "none"
1844
+ };
1845
+ const El = inProps.component || "div";
1846
+ const divRefClassName = className + " " + InjectClassName;
1847
+ useEffect7(() => {
1848
+ cssSpatialRootContextObject.setCSSParserRef(cssSpatialID, ref.current);
1849
+ }, [ref.current]);
1850
+ return /* @__PURE__ */ jsxs4(Fragment, { children: [
1851
+ ready && /* @__PURE__ */ jsx5(
1852
+ SpatialReactComponent,
1853
+ {
1854
+ style: spatialDivStyle,
1855
+ className,
1856
+ children,
1857
+ ...props,
1858
+ spatialStyle,
1859
+ debugName,
1860
+ debugShowStandardInstance
1861
+ }
1862
+ ),
1863
+ /* @__PURE__ */ jsx5(
1864
+ El,
1865
+ {
1866
+ style: divRefStyle,
1867
+ className: divRefClassName,
1868
+ ...props,
1869
+ ref
1870
+ }
1871
+ )
1872
+ ] });
1873
+ }
1874
+ function CSSSpatialComponentBase(inProps, ref) {
1875
+ const { [CSSSpatialID]: cssSpatialID, ...props } = inProps;
1876
+ const isWebEnv = "false";
1877
+ if (isWebEnv) {
1878
+ return renderInWebEnv(props, ref);
1879
+ } else {
1880
+ const cssSpatialRootContextObject = useContext5(CSSSpatialRootContext);
1881
+ if (cssSpatialRootContextObject) {
1882
+ const isInStandardInstance = !!useContext5(
1883
+ SpatialIsStandardInstanceContext
1884
+ );
1885
+ if (isInStandardInstance) {
1886
+ return renderInStandardInstance(
1887
+ cssSpatialRootContextObject,
1888
+ cssSpatialID,
1889
+ props,
1890
+ ref
1891
+ );
1892
+ } else {
1893
+ return renderInPortalInstance(
1894
+ cssSpatialRootContextObject,
1895
+ cssSpatialID,
1896
+ props
1897
+ );
1898
+ }
1899
+ } else {
1900
+ return renderRootCSSSpatialComponent(props, ref);
1901
+ }
1902
+ }
1903
+ }
1904
+ var CSSSpatialComponentBaseWithRef = forwardRef4(CSSSpatialComponentBase);
1905
+ function CSSSpatialComponentWithRef(inProps, ref) {
1906
+ const layer = useContext5(CSSSpatialLayerContext) + 1;
1907
+ const cssSpatialRootContextObject = useContext5(CSSSpatialRootContext);
1908
+ const isRootInstance = !cssSpatialRootContextObject;
1909
+ const isInStandardInstance = !!useContext5(SpatialIsStandardInstanceContext);
1910
+ const cssSpatialID = useMemo3(() => {
1911
+ return isRootInstance ? layer.toString() : cssSpatialRootContextObject.getSpatialID(
1912
+ layer,
1913
+ isInStandardInstance,
1914
+ inProps.debugName
1915
+ );
1916
+ }, []);
1917
+ const props = { ...inProps, [CSSSpatialID]: cssSpatialID };
1918
+ return /* @__PURE__ */ jsx5(CSSSpatialDebugNameContext.Provider, { value: inProps.debugName || "", children: /* @__PURE__ */ jsx5(CSSSpatialLayerContext.Provider, { value: layer, children: /* @__PURE__ */ jsx5(CSSSpatialComponentBaseWithRef, { ...props, ref }) }) });
1919
+ }
1920
+ var CSSSpatialComponent = forwardRef4(CSSSpatialComponentWithRef);
1921
+
1922
+ // src/spatial-react-components/CSSSpatialDiv/CSSSpatialDiv.tsx
1923
+ import { jsx as jsx6 } from "react/jsx-runtime";
1924
+ var cachedWithCSSSpatialType = /* @__PURE__ */ new Map();
1925
+ function withCSSSpatial(Component) {
1926
+ if (cachedWithCSSSpatialType.has(Component)) {
1927
+ return cachedWithCSSSpatialType.get(Component);
1928
+ } else {
1929
+ const WithCSSSpatialComponent = forwardRef5(
1930
+ (givenProps, givenRef) => {
1931
+ const {
1932
+ component: ignoreComponent,
1933
+ className: origClassName = "",
1934
+ ...props
1935
+ } = givenProps;
1936
+ const className = "xr-spatial-default " + origClassName;
1937
+ return /* @__PURE__ */ jsx6(
1938
+ CSSSpatialComponent,
1939
+ {
1940
+ component: Component,
1941
+ className,
1942
+ ...props,
1943
+ ref: givenRef
1944
+ }
1945
+ );
1946
+ }
1947
+ );
1948
+ WithCSSSpatialComponent.displayName = `WithCSSSpatial(${typeof Component === "string" ? Component : Component.displayName || Component.name})`;
1949
+ cachedWithCSSSpatialType.set(Component, WithCSSSpatialComponent);
1950
+ cachedWithCSSSpatialType.set(
1951
+ WithCSSSpatialComponent,
1952
+ WithCSSSpatialComponent
1953
+ );
1954
+ return WithCSSSpatialComponent;
1955
+ }
1956
+ }
1957
+ var CSSSpatialPrimitive = {};
1958
+ (function createSpatialPrimitive2(CSSSpatialPrimitive2) {
1959
+ primitives.forEach((primitive) => {
1960
+ CSSSpatialPrimitive2[primitive] = withCSSSpatial(primitive);
1961
+ });
1962
+ })(CSSSpatialPrimitive);
1963
+ var CSSSpatialDiv = CSSSpatialPrimitive.div;
1964
+
1965
+ // src/spatial-react-components/SpatialView.tsx
1966
+ import { SpatialHelper } from "@webspatial/core-sdk";
1967
+ import {
1968
+ useRef as useRef7,
1969
+ useImperativeHandle,
1970
+ forwardRef as forwardRef6,
1971
+ useEffect as useEffect8
1972
+ } from "react";
1973
+ import { jsx as jsx7 } from "react/jsx-runtime";
1974
+ var runAsync = (fn) => {
1975
+ return fn();
1976
+ };
1977
+ var SpatialViewEl = forwardRef6(
1978
+ (props, ref) => {
1979
+ const divRef = useRef7(null);
1980
+ const spatialEntity = useRef7(null);
1981
+ const activePromise = useRef7(null);
1982
+ useImperativeHandle(ref, () => ({
1983
+ ...divRef.current,
1984
+ getViewEntity: async () => {
1985
+ if (activePromise.current) {
1986
+ await activePromise.current;
1987
+ }
1988
+ return spatialEntity.current;
1989
+ }
1990
+ }));
1991
+ if (getSession() == null) {
1992
+ return /* @__PURE__ */ jsx7("div", { ref: divRef, ...props, children: "WebSpatial is not supported in this browser" });
1993
+ }
1994
+ useEffect8(() => {
1995
+ if ("false") return;
1996
+ activePromise.current = runAsync(async () => {
1997
+ if (activePromise.current) {
1998
+ await activePromise.current;
1999
+ }
2000
+ let sh = new SpatialHelper(getSession());
2001
+ let x = await sh.dom.attachSpatialView(divRef.current);
2002
+ spatialEntity.current = x.entity;
2003
+ if (props.onViewLoad) {
2004
+ props.onViewLoad(x.entity);
2005
+ }
2006
+ });
2007
+ return () => {
2008
+ if ("false") return;
2009
+ runAsync(async () => {
2010
+ await activePromise.current;
2011
+ spatialEntity.current?.destroy();
2012
+ if (props.onViewUnload) {
2013
+ props.onViewUnload();
2014
+ }
2015
+ });
2016
+ };
2017
+ }, []);
2018
+ const { onViewLoad, onViewUnload, ...divProps } = props;
2019
+ return /* @__PURE__ */ jsx7("div", { ref: divRef, ...divProps });
2020
+ }
2021
+ );
2022
+ var SpatialView = SpatialViewEl;
2023
+
2024
+ // src/spatial-react-components/Model/index.tsx
2025
+ import {
2026
+ forwardRef as forwardRef9,
2027
+ Children,
2028
+ useMemo as useMemo8,
2029
+ useRef as useRef12,
2030
+ useEffect as useEffect16
2031
+ } from "react";
2032
+
2033
+ // src/spatial-react-components/Model3D/Model3D.tsx
2034
+ import { forwardRef as forwardRef7, useContext as useContext8, useMemo as useMemo6 } from "react";
2035
+
2036
+ // src/spatial-react-components/Model3D/useDetectLayoutDomUpdated.ts
2037
+ import { useRef as useRef8, useEffect as useEffect9 } from "react";
2038
+ function useDetectLayoutDomUpdated(onDomUpdated) {
2039
+ const ref = useRef8(null);
2040
+ useEffect9(() => {
2041
+ if (!ref.current) {
2042
+ console.warn("Ref is not attached to the DOM");
2043
+ return;
2044
+ }
2045
+ let ro = new ResizeObserver((elements) => {
2046
+ onDomUpdated();
2047
+ });
2048
+ ro.observe(ref.current);
2049
+ return () => {
2050
+ ro.disconnect();
2051
+ };
2052
+ }, []);
2053
+ useEffect9(() => {
2054
+ if (!ref.current) {
2055
+ console.warn("Ref is not attached to the DOM");
2056
+ return;
2057
+ }
2058
+ let ro = new MutationObserver((elements) => {
2059
+ onDomUpdated();
2060
+ });
2061
+ ro.observe(ref.current, {
2062
+ attributeFilter: ["class", "style"],
2063
+ subtree: true,
2064
+ attributeOldValue: false
2065
+ });
2066
+ return () => {
2067
+ ro.disconnect();
2068
+ };
2069
+ }, []);
2070
+ return ref;
2071
+ }
2072
+
2073
+ // src/spatial-react-components/Model3D/useModel3DNative.ts
2074
+ import { useRef as useRef9, useEffect as useEffect10, useState as useState4 } from "react";
2075
+
2076
+ // src/spatial-react-components/Model3D/utils.ts
2077
+ function PopulatePartialSpatialTransformType(spatialTransform = {}) {
2078
+ const {
2079
+ position = { x: 0, y: 0, z: 0 },
2080
+ rotation = { x: 0, y: 0, z: 0, w: 1 },
2081
+ scale = { x: 1, y: 1, z: 1 }
2082
+ } = spatialTransform;
2083
+ const { x: tx = 0, y: ty = 0, z: tz = 0 } = position;
2084
+ const { x: rx = 0, y: ry = 0, z: rz = 0, w = 1 } = rotation;
2085
+ const { x: sx = 1, y: sy = 1, z: sz = 1 } = scale;
2086
+ return {
2087
+ position: { x: tx, y: ty, z: tz },
2088
+ rotation: { x: rx, y: ry, z: rz, w },
2089
+ scale: { x: sx, y: sy, z: sz }
2090
+ };
2091
+ }
2092
+ function getAbsoluteURL(url) {
2093
+ if (!url) {
2094
+ return "";
2095
+ }
2096
+ if (url.startsWith("http")) {
2097
+ return url;
2098
+ }
2099
+ return `${location.origin}${url}`;
2100
+ }
2101
+
2102
+ // src/spatial-react-components/Model3D/Model3DNative.ts
2103
+ var Model3DNative = class {
2104
+ constructor(parentEntity) {
2105
+ this.parentEntity = parentEntity;
2106
+ }
2107
+ parentEntity;
2108
+ initPromise;
2109
+ entity;
2110
+ spatialModel3DComponent;
2111
+ // private modelUrl: string
2112
+ isDestroyed = false;
2113
+ _onDragStart;
2114
+ _onDrag;
2115
+ _onDragEnd;
2116
+ _onTap;
2117
+ _onDoubleTap;
2118
+ _onLongPress;
2119
+ async init(modelUrl, onSuccess, onFailure) {
2120
+ if (this.isDestroyed) {
2121
+ return;
2122
+ }
2123
+ this.initPromise = this.initInternal(modelUrl, onSuccess, onFailure);
2124
+ return this.initPromise;
2125
+ }
2126
+ async initInternal(modelUrl, onSuccess, onFailure) {
2127
+ if ("false") return;
2128
+ var session = getSession();
2129
+ if (!session) {
2130
+ return;
2131
+ }
2132
+ const entity = await session.createEntity();
2133
+ await entity.setCoordinateSpace("Dom");
2134
+ const spatialModel3DComponent = await session.createModel3DComponent({
2135
+ url: getAbsoluteURL(modelUrl)
2136
+ });
2137
+ await entity.setComponent(spatialModel3DComponent);
2138
+ if (this.isDestroyed) {
2139
+ return;
2140
+ }
2141
+ if (this.parentEntity) {
2142
+ await entity.setParent(this.parentEntity);
2143
+ } else {
2144
+ var wc = session.getCurrentWindowComponent();
2145
+ var ent = await wc.getEntity();
2146
+ await entity.setParent(ent);
2147
+ }
2148
+ this.entity = entity;
2149
+ this.spatialModel3DComponent = spatialModel3DComponent;
2150
+ this.spatialModel3DComponent.onSuccess = onSuccess;
2151
+ this.spatialModel3DComponent.onFailure = onFailure;
2152
+ this.spatialModel3DComponent.onDragStart = this._onDragStart;
2153
+ this.spatialModel3DComponent.onDrag = this._onDrag;
2154
+ this.spatialModel3DComponent.onDragEnd = this._onDragEnd;
2155
+ this.spatialModel3DComponent.onTap = this._onTap;
2156
+ this.spatialModel3DComponent.onDoubleTap = this._onDoubleTap;
2157
+ this.spatialModel3DComponent.onLongPress = this._onLongPress;
2158
+ }
2159
+ async setVisible(visible) {
2160
+ if (this.entity) {
2161
+ await this.entity.setVisible(visible);
2162
+ }
2163
+ }
2164
+ async setContentMode(contentMode) {
2165
+ if (this.spatialModel3DComponent) {
2166
+ await this.spatialModel3DComponent.setContentMode(contentMode);
2167
+ }
2168
+ }
2169
+ async setResizable(resizable) {
2170
+ if (this.spatialModel3DComponent) {
2171
+ await this.spatialModel3DComponent.setResizable(resizable);
2172
+ }
2173
+ }
2174
+ async setAspectRatio(aspectRatio) {
2175
+ if (this.spatialModel3DComponent) {
2176
+ await this.spatialModel3DComponent.setAspectRatio(aspectRatio);
2177
+ }
2178
+ }
2179
+ async updateByDom(dom, options) {
2180
+ if (!this.entity || !this.spatialModel3DComponent) {
2181
+ return;
2182
+ }
2183
+ const rect = dom.getBoundingClientRect();
2184
+ const targetPosX = rect.left + (rect.right - rect.left) / 2;
2185
+ const targetPosY = rect.bottom + (rect.top - rect.bottom) / 2 + window.scrollY;
2186
+ const { spatialTransform } = options;
2187
+ const { position, rotation, scale } = spatialTransform;
2188
+ const entity = this.entity;
2189
+ entity.transform.position.x = targetPosX + position.x;
2190
+ entity.transform.position.y = targetPosY + position.y;
2191
+ entity.transform.position.z = position.z;
2192
+ entity.transform.orientation.x = rotation.x;
2193
+ entity.transform.orientation.y = rotation.y;
2194
+ entity.transform.orientation.z = rotation.z;
2195
+ entity.transform.orientation.w = rotation.w;
2196
+ entity.transform.scale.x = scale.x;
2197
+ entity.transform.scale.y = scale.y;
2198
+ entity.transform.scale.z = scale.z;
2199
+ await entity.updateTransform();
2200
+ const spatialModel3DComponent = this.spatialModel3DComponent;
2201
+ await spatialModel3DComponent.setResolution(rect.width, rect.height);
2202
+ const computedStyle = getComputedStyle(dom);
2203
+ const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
2204
+ await spatialModel3DComponent.setOpacity(opacity);
2205
+ const anchor = parseTransformOrigin(computedStyle);
2206
+ await spatialModel3DComponent.setRotationAnchor(anchor);
2207
+ }
2208
+ async updateRectAndTransform(rect, spatialTransform) {
2209
+ if (!this.entity || !this.spatialModel3DComponent) {
2210
+ return;
2211
+ }
2212
+ const targetPosX = rect.x + (rect.width - rect.x) / 2;
2213
+ const targetPosY = rect.y + (rect.height - rect.y) / 2 + window.scrollY;
2214
+ const { position, rotation, scale } = spatialTransform;
2215
+ const entity = this.entity;
2216
+ entity.transform.position.x = targetPosX + position.x;
2217
+ entity.transform.position.y = targetPosY + position.y;
2218
+ entity.transform.position.z = position.z;
2219
+ entity.transform.orientation.x = rotation.x;
2220
+ entity.transform.orientation.y = rotation.y;
2221
+ entity.transform.orientation.z = rotation.z;
2222
+ entity.transform.orientation.w = rotation.w;
2223
+ entity.transform.scale.x = scale.x;
2224
+ entity.transform.scale.y = scale.y;
2225
+ entity.transform.scale.z = scale.z;
2226
+ await entity.updateTransform();
2227
+ const spatialModel3DComponent = this.spatialModel3DComponent;
2228
+ await spatialModel3DComponent.setResolution(rect.width, rect.height);
2229
+ }
2230
+ async setRotationAnchor(anchor) {
2231
+ if (this.spatialModel3DComponent) {
2232
+ await this.spatialModel3DComponent.setRotationAnchor(anchor);
2233
+ }
2234
+ }
2235
+ async setOpacity(opacity) {
2236
+ if (this.spatialModel3DComponent) {
2237
+ this.spatialModel3DComponent.setOpacity(opacity);
2238
+ }
2239
+ }
2240
+ set onDragStart(callback) {
2241
+ if (this.spatialModel3DComponent) {
2242
+ this.spatialModel3DComponent.onDragStart = callback;
2243
+ }
2244
+ this._onDragStart = callback;
2245
+ }
2246
+ set onDrag(callback) {
2247
+ if (this.spatialModel3DComponent) {
2248
+ this.spatialModel3DComponent.onDrag = callback;
2249
+ }
2250
+ this._onDrag = callback;
2251
+ }
2252
+ set onDragEnd(callback) {
2253
+ if (this.spatialModel3DComponent) {
2254
+ this.spatialModel3DComponent.onDragEnd = callback;
2255
+ }
2256
+ this._onDragEnd = callback;
2257
+ }
2258
+ set onTap(callback) {
2259
+ if (this.spatialModel3DComponent) {
2260
+ this.spatialModel3DComponent.onTap = callback;
2261
+ }
2262
+ this._onTap = callback;
2263
+ }
2264
+ set onDoubleTap(callback) {
2265
+ if (this.spatialModel3DComponent) {
2266
+ this.spatialModel3DComponent.onDoubleTap = callback;
2267
+ }
2268
+ this._onDoubleTap = callback;
2269
+ }
2270
+ set onLongPress(callback) {
2271
+ if (this.spatialModel3DComponent) {
2272
+ this.spatialModel3DComponent.onLongPress = callback;
2273
+ }
2274
+ this._onLongPress = callback;
2275
+ }
2276
+ /**
2277
+ * Destroys the current 3D model instance
2278
+ * 1. Marks the instance as destroyed
2279
+ * 2. Waits for initialization to complete (if in progress)
2280
+ * 3. Destroys the spatial entity
2281
+ * 4. Cleans up all related references
2282
+ */
2283
+ async destroy() {
2284
+ this.isDestroyed = true;
2285
+ if (this.initPromise) {
2286
+ await this.initPromise;
2287
+ }
2288
+ this.entity?.destroy();
2289
+ this.entity = void 0;
2290
+ this.spatialModel3DComponent = void 0;
2291
+ this.initPromise = void 0;
2292
+ }
2293
+ };
2294
+
2295
+ // src/spatial-react-components/Model3D/useModel3DNative.ts
2296
+ function useModel3DNative(modelUrl, parentEntity, eventHandlers = {}, onModel3DNativeReadyCb) {
2297
+ let model3DNativeRef = useRef9(null);
2298
+ const [phase, setPhase] = useState4(
2299
+ "loading"
2300
+ );
2301
+ const [failureReason, setFailureReason] = useState4("");
2302
+ useEffect10(() => {
2303
+ let isDestroyed = false;
2304
+ const model3DContainer = new Model3DNative(parentEntity);
2305
+ model3DContainer.init(
2306
+ modelUrl,
2307
+ () => {
2308
+ setPhase("success");
2309
+ },
2310
+ (error) => {
2311
+ setPhase("failure");
2312
+ setFailureReason(error);
2313
+ }
2314
+ ).then(() => {
2315
+ if (!isDestroyed) {
2316
+ model3DNativeRef.current = model3DContainer;
2317
+ if (onModel3DNativeReadyCb) {
2318
+ onModel3DNativeReadyCb(model3DContainer);
2319
+ }
2320
+ }
2321
+ });
2322
+ return () => {
2323
+ isDestroyed = true;
2324
+ model3DContainer.destroy();
2325
+ model3DNativeRef.current = null;
2326
+ setPhase("loading");
2327
+ };
2328
+ }, [modelUrl]);
2329
+ useEffect10(() => {
2330
+ if (model3DNativeRef.current) {
2331
+ model3DNativeRef.current.onDragStart = eventHandlers.onDragStart;
2332
+ }
2333
+ }, [model3DNativeRef.current, eventHandlers.onDragStart]);
2334
+ useEffect10(() => {
2335
+ if (model3DNativeRef.current) {
2336
+ model3DNativeRef.current.onDrag = eventHandlers.onDrag;
2337
+ }
2338
+ }, [model3DNativeRef.current, eventHandlers.onDrag]);
2339
+ useEffect10(() => {
2340
+ if (model3DNativeRef.current) {
2341
+ model3DNativeRef.current.onDragEnd = eventHandlers.onDragEnd;
2342
+ }
2343
+ });
2344
+ useEffect10(() => {
2345
+ if (model3DNativeRef.current) {
2346
+ model3DNativeRef.current.onTap = eventHandlers.onTap;
2347
+ }
2348
+ }, [model3DNativeRef.current, eventHandlers.onTap]);
2349
+ useEffect10(() => {
2350
+ if (model3DNativeRef.current) {
2351
+ model3DNativeRef.current.onDoubleTap = eventHandlers.onDoubleTap;
2352
+ }
2353
+ }, [model3DNativeRef.current, eventHandlers.onDoubleTap]);
2354
+ useEffect10(() => {
2355
+ if (model3DNativeRef.current) {
2356
+ model3DNativeRef.current.onLongPress = eventHandlers.onLongPress;
2357
+ }
2358
+ }, [model3DNativeRef.current, eventHandlers.onLongPress]);
2359
+ return { model3DNativeRef, phase, failureReason };
2360
+ }
2361
+
2362
+ // src/spatial-react-components/Model3D/Model3DNotInSpatialDiv.tsx
2363
+ import { useCallback as useCallback4, useEffect as useEffect11, useMemo as useMemo4 } from "react";
2364
+ import { jsx as jsx8 } from "react/jsx-runtime";
2365
+ function renderModel3DNotInSpatialDiv(props, refIn) {
2366
+ const {
2367
+ className,
2368
+ style = {},
2369
+ modelUrl,
2370
+ visible,
2371
+ spatialTransform,
2372
+ contentMode = "fit",
2373
+ resizable = true,
2374
+ aspectRatio = 0,
2375
+ onLoad,
2376
+ children,
2377
+ onDragStart,
2378
+ onDrag,
2379
+ onDragEnd,
2380
+ onTap,
2381
+ onDoubleTap,
2382
+ onLongPress
2383
+ } = props;
2384
+ const theSpatialTransform = PopulatePartialSpatialTransformType(spatialTransform);
2385
+ const onDomUpdated = useCallback4(() => {
2386
+ if (model3DNativeRef.current && layoutInstanceRef.current) {
2387
+ const model3DNative = model3DNativeRef.current;
2388
+ model3DNative.updateByDom(layoutInstanceRef.current, {
2389
+ spatialTransform: theSpatialTransform
2390
+ });
2391
+ }
2392
+ }, [
2393
+ theSpatialTransform.position.x,
2394
+ theSpatialTransform.position.y,
2395
+ theSpatialTransform.position.z,
2396
+ theSpatialTransform.rotation.x,
2397
+ theSpatialTransform.rotation.y,
2398
+ theSpatialTransform.rotation.z,
2399
+ theSpatialTransform.rotation.w,
2400
+ theSpatialTransform.scale.x,
2401
+ theSpatialTransform.scale.y,
2402
+ theSpatialTransform.scale.z
2403
+ ]);
2404
+ const onModel3DContainerReadyCb = useCallback4(() => {
2405
+ if (model3DNativeRef.current && layoutInstanceRef.current) {
2406
+ model3DNativeRef.current.updateByDom(layoutInstanceRef.current, {
2407
+ spatialTransform: theSpatialTransform
2408
+ });
2409
+ }
2410
+ }, [
2411
+ theSpatialTransform.position.x,
2412
+ theSpatialTransform.position.y,
2413
+ theSpatialTransform.position.z,
2414
+ theSpatialTransform.rotation.x,
2415
+ theSpatialTransform.rotation.y,
2416
+ theSpatialTransform.rotation.z,
2417
+ theSpatialTransform.rotation.w,
2418
+ theSpatialTransform.scale.x,
2419
+ theSpatialTransform.scale.y,
2420
+ theSpatialTransform.scale.z
2421
+ ]);
2422
+ const onDragStartCb = useCallback4(
2423
+ (spatialDragEvent) => {
2424
+ if (onDragStart) {
2425
+ const dragEvent = {
2426
+ ...spatialDragEvent,
2427
+ target: layoutInstanceRef.current
2428
+ };
2429
+ onDragStart(dragEvent);
2430
+ }
2431
+ },
2432
+ [onDragStart]
2433
+ );
2434
+ const onDragCb = useCallback4(
2435
+ (spatialDragEvent) => {
2436
+ if (onDrag) {
2437
+ const dragEvent = {
2438
+ ...spatialDragEvent,
2439
+ target: layoutInstanceRef.current
2440
+ };
2441
+ onDrag(dragEvent);
2442
+ }
2443
+ },
2444
+ [onDrag]
2445
+ );
2446
+ const onDragEndCb = useCallback4(
2447
+ (spatialDragEvent) => {
2448
+ if (onDragEnd) {
2449
+ const dragEvent = {
2450
+ ...spatialDragEvent,
2451
+ target: layoutInstanceRef.current
2452
+ };
2453
+ onDragEnd(dragEvent);
2454
+ }
2455
+ },
2456
+ [onDragEnd]
2457
+ );
2458
+ const onTapCb = useCallback4(() => {
2459
+ if (onTap) {
2460
+ const event = {
2461
+ target: layoutInstanceRef.current
2462
+ };
2463
+ onTap(event);
2464
+ }
2465
+ }, [onTap]);
2466
+ const onDoubleTapCb = useCallback4(() => {
2467
+ if (onDoubleTap) {
2468
+ const event = {
2469
+ target: layoutInstanceRef.current
2470
+ };
2471
+ onDoubleTap(event);
2472
+ }
2473
+ }, [onDoubleTap]);
2474
+ const onLongPressCb = useCallback4(() => {
2475
+ if (onLongPress) {
2476
+ const event = {
2477
+ target: layoutInstanceRef.current
2478
+ };
2479
+ onLongPress(event);
2480
+ }
2481
+ }, [onLongPress]);
2482
+ const layoutInstanceRef = useDetectLayoutDomUpdated(onDomUpdated);
2483
+ const { model3DNativeRef, phase, failureReason } = useModel3DNative(
2484
+ modelUrl,
2485
+ void 0,
2486
+ {
2487
+ onDragStart: onDragStart ? onDragStartCb : void 0,
2488
+ onDrag: onDrag ? onDragCb : void 0,
2489
+ onDragEnd: onDragEnd ? onDragEndCb : void 0,
2490
+ onTap: onTap ? onTapCb : void 0,
2491
+ onDoubleTap: onDoubleTap ? onDoubleTapCb : void 0,
2492
+ onLongPress: onLongPress ? onLongPressCb : void 0
2493
+ },
2494
+ onModel3DContainerReadyCb
2495
+ );
2496
+ const onSuccess = useCallback4(() => {
2497
+ ;
2498
+ layoutInstanceRef.current.ready = true;
2499
+ if (onLoad) {
2500
+ onLoad({
2501
+ target: layoutInstanceRef.current
2502
+ });
2503
+ }
2504
+ }, [onLoad]);
2505
+ const onFailure = useCallback4(
2506
+ (_) => {
2507
+ const modelElement = layoutInstanceRef.current;
2508
+ modelElement.ready = false;
2509
+ if (onLoad) {
2510
+ onLoad({
2511
+ target: layoutInstanceRef.current
2512
+ });
2513
+ }
2514
+ },
2515
+ [onLoad]
2516
+ );
2517
+ useEffect11(() => {
2518
+ if (phase === "failure") {
2519
+ onFailure(failureReason);
2520
+ } else if (phase === "success") {
2521
+ onSuccess();
2522
+ }
2523
+ }, [phase]);
2524
+ useEffect11(() => {
2525
+ if (model3DNativeRef.current) {
2526
+ model3DNativeRef.current.setVisible(visible);
2527
+ }
2528
+ }, [model3DNativeRef.current, visible]);
2529
+ useEffect11(() => {
2530
+ if (model3DNativeRef.current && layoutInstanceRef.current) {
2531
+ model3DNativeRef.current.updateByDom(layoutInstanceRef.current, {
2532
+ spatialTransform: theSpatialTransform
2533
+ });
2534
+ }
2535
+ }, [
2536
+ theSpatialTransform.position.x,
2537
+ theSpatialTransform.position.y,
2538
+ theSpatialTransform.position.z,
2539
+ theSpatialTransform.rotation.x,
2540
+ theSpatialTransform.rotation.y,
2541
+ theSpatialTransform.rotation.z,
2542
+ theSpatialTransform.rotation.w,
2543
+ theSpatialTransform.scale.x,
2544
+ theSpatialTransform.scale.y,
2545
+ theSpatialTransform.scale.z
2546
+ ]);
2547
+ useEffect11(() => {
2548
+ if (model3DNativeRef.current) {
2549
+ model3DNativeRef.current.setContentMode(contentMode);
2550
+ }
2551
+ }, [model3DNativeRef.current, contentMode]);
2552
+ useEffect11(() => {
2553
+ if (model3DNativeRef.current) {
2554
+ model3DNativeRef.current.setResizable(resizable);
2555
+ }
2556
+ }, [model3DNativeRef.current, resizable]);
2557
+ useEffect11(() => {
2558
+ if (model3DNativeRef.current) {
2559
+ model3DNativeRef.current.setAspectRatio(aspectRatio);
2560
+ }
2561
+ }, [model3DNativeRef.current, aspectRatio]);
2562
+ const layoutDomStyle = {
2563
+ ...style,
2564
+ visibility: phase === "failure" ? "visible" : "hidden",
2565
+ transform: ""
2566
+ };
2567
+ const proxyRef = useMemo4(
2568
+ () => new Proxy(layoutInstanceRef, {
2569
+ get(target, prop, receiver) {
2570
+ return Reflect.get(target, prop, receiver);
2571
+ },
2572
+ set(target, prop, value, receiver) {
2573
+ if (prop === "current") {
2574
+ const domElement = value;
2575
+ if (domElement) {
2576
+ domElement.ready = false;
2577
+ domElement.currentSrc = modelUrl;
2578
+ }
2579
+ if (refIn) {
2580
+ if (typeof refIn === "function") {
2581
+ refIn(domElement);
2582
+ } else {
2583
+ refIn.current = domElement;
2584
+ }
2585
+ }
2586
+ }
2587
+ return Reflect.set(target, prop, value, receiver);
2588
+ }
2589
+ }),
2590
+ [layoutInstanceRef, refIn]
2591
+ );
2592
+ useEffect11(() => {
2593
+ return () => {
2594
+ if (layoutInstanceRef.current) {
2595
+ const modelElement = layoutInstanceRef.current;
2596
+ modelElement.ready = false;
2597
+ modelElement.currentSrc = modelUrl;
2598
+ }
2599
+ };
2600
+ }, [modelUrl]);
2601
+ return /* @__PURE__ */ jsx8("div", { className, style: layoutDomStyle, ref: proxyRef, children: phase === "failure" && children });
2602
+ }
2603
+
2604
+ // src/spatial-react-components/Model3D/Model3DStandardInstance.tsx
2605
+ import { jsx as jsx9 } from "react/jsx-runtime";
2606
+ function renderModel3DStandardInstance(spatialId, props, refIn) {
2607
+ const { className, style } = props;
2608
+ const extraProps = {
2609
+ [SpatialID]: spatialId
2610
+ };
2611
+ return /* @__PURE__ */ jsx9(
2612
+ "div",
2613
+ {
2614
+ "data-model3d-spatialid": spatialId,
2615
+ className,
2616
+ style,
2617
+ ref: refIn,
2618
+ ...extraProps
2619
+ }
2620
+ );
2621
+ }
2622
+
2623
+ // src/spatial-react-components/Model3D/Model3DPortalInstance.tsx
2624
+ import {
2625
+ useCallback as useCallback5,
2626
+ useContext as useContext7,
2627
+ useEffect as useEffect13,
2628
+ useMemo as useMemo5
2629
+ } from "react";
2630
+
2631
+ // src/spatial-react-components/Model3D/useSyncDomInfoFromStandardInstance.ts
2632
+ import { useRef as useRef10, useEffect as useEffect12, useState as useState5, useContext as useContext6 } from "react";
2633
+ function useSyncDomInfoFromStandardInstance(spatialId) {
2634
+ const [domRect, setDomRect] = useState5({
2635
+ x: 0,
2636
+ y: 0,
2637
+ width: 0,
2638
+ height: 0
2639
+ });
2640
+ const inheritedPortalStyleRef = useRef10({});
2641
+ const anchorRef = useRef10({
2642
+ x: 0.5,
2643
+ y: 0.5,
2644
+ z: 0.5
2645
+ });
2646
+ const opacityRef = useRef10(1);
2647
+ const spatialReactContextObject = useContext6(SpatialReactContext);
2648
+ const inheritedPortalClassNameRef = useRef10("");
2649
+ const modelRef = useRef10(null);
2650
+ useEffect12(() => {
2651
+ const syncDomRect = () => {
2652
+ const dom = spatialReactContextObject?.querySpatialDom(spatialId);
2653
+ if (!dom) {
2654
+ return;
2655
+ }
2656
+ modelRef.current = dom;
2657
+ let domRect2 = dom.getBoundingClientRect();
2658
+ let rectType = domRect2rectType(domRect2);
2659
+ const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
2660
+ if (parentDom) {
2661
+ const parentDomRect = parentDom.getBoundingClientRect();
2662
+ const parentRectType = domRect2rectType(parentDomRect);
2663
+ rectType.x -= parentRectType.x;
2664
+ rectType.y -= parentRectType.y;
2665
+ }
2666
+ const computedStyle = getComputedStyle(dom);
2667
+ inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
2668
+ const anchor = parseTransformOrigin(computedStyle);
2669
+ anchorRef.current = anchor;
2670
+ const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
2671
+ opacityRef.current = opacity;
2672
+ inheritedPortalClassNameRef.current = dom.className;
2673
+ setDomRect(rectType);
2674
+ };
2675
+ spatialReactContextObject?.onDomChange(spatialId, syncDomRect);
2676
+ return () => {
2677
+ spatialReactContextObject?.offDomChange(spatialId);
2678
+ };
2679
+ }, []);
2680
+ return {
2681
+ modelRef,
2682
+ domRect,
2683
+ inheritedPortalStyle: inheritedPortalStyleRef.current,
2684
+ anchor: anchorRef.current,
2685
+ opacity: opacityRef.current,
2686
+ className: inheritedPortalClassNameRef.current
2687
+ };
2688
+ }
2689
+
2690
+ // src/spatial-react-components/Model3D/Model3DPortalInstance.tsx
2691
+ import { Fragment as Fragment2, jsx as jsx10 } from "react/jsx-runtime";
2692
+ function useModelEvents(props, modelRef) {
2693
+ const {
2694
+ onDragStart,
2695
+ onDrag,
2696
+ onDragEnd,
2697
+ onTap,
2698
+ onDoubleTap,
2699
+ onLongPress
2700
+ } = props;
2701
+ const onDragStartCb = useCallback5(
2702
+ (spatialDragEvent) => {
2703
+ if (onDragStart) {
2704
+ const dragEvent = {
2705
+ ...spatialDragEvent,
2706
+ target: modelRef.current
2707
+ };
2708
+ onDragStart(dragEvent);
2709
+ }
2710
+ },
2711
+ [onDragStart]
2712
+ );
2713
+ const onDragCb = useCallback5(
2714
+ (spatialDragEvent) => {
2715
+ if (onDrag) {
2716
+ const dragEvent = {
2717
+ ...spatialDragEvent,
2718
+ target: modelRef.current
2719
+ };
2720
+ onDrag(dragEvent);
2721
+ }
2722
+ },
2723
+ [onDrag]
2724
+ );
2725
+ const onDragEndCb = useCallback5(
2726
+ (spatialDragEvent) => {
2727
+ if (onDragEnd) {
2728
+ const dragEvent = {
2729
+ ...spatialDragEvent,
2730
+ target: modelRef.current
2731
+ };
2732
+ onDragEnd(dragEvent);
2733
+ }
2734
+ },
2735
+ [onDragEnd]
2736
+ );
2737
+ const onTapCb = useCallback5(() => {
2738
+ if (onTap) {
2739
+ const event = {
2740
+ target: modelRef.current
2741
+ };
2742
+ onTap(event);
2743
+ }
2744
+ }, [onTap]);
2745
+ const onDoubleTapCb = useCallback5(() => {
2746
+ if (onDoubleTap) {
2747
+ const event = {
2748
+ target: modelRef.current
2749
+ };
2750
+ onDoubleTap(event);
2751
+ }
2752
+ }, [onDoubleTap]);
2753
+ const onLongPressCb = useCallback5(() => {
2754
+ if (onLongPress) {
2755
+ const event = {
2756
+ target: modelRef.current
2757
+ };
2758
+ onLongPress(event);
2759
+ }
2760
+ }, [onLongPress]);
2761
+ return {
2762
+ onDragStart: onDragStartCb,
2763
+ onDrag: onDragCb,
2764
+ onDragEnd: onDragEndCb,
2765
+ onTap: onTapCb,
2766
+ onDoubleTap: onDoubleTapCb,
2767
+ onLongPress: onLongPressCb
2768
+ };
2769
+ }
2770
+ function renderModel3DPortalInstance(spatialId, props) {
2771
+ const {
2772
+ style: _,
2773
+ modelUrl,
2774
+ visible,
2775
+ spatialTransform,
2776
+ contentMode = "fit",
2777
+ resizable = true,
2778
+ aspectRatio = 0,
2779
+ onLoad,
2780
+ children
2781
+ } = props;
2782
+ const theSpatialTransform = useMemo5(() => {
2783
+ return PopulatePartialSpatialTransformType(spatialTransform);
2784
+ }, [spatialTransform]);
2785
+ const {
2786
+ modelRef,
2787
+ domRect,
2788
+ inheritedPortalStyle,
2789
+ anchor,
2790
+ opacity,
2791
+ className
2792
+ } = useSyncDomInfoFromStandardInstance(spatialId);
2793
+ const parentSpatialWindowManager = useContext7(SpatialWindowManagerContext);
2794
+ const eventHandlers = useModelEvents(
2795
+ props,
2796
+ modelRef
2797
+ );
2798
+ const { model3DNativeRef, phase, failureReason } = useModel3DNative(
2799
+ modelUrl,
2800
+ parentSpatialWindowManager.entity,
2801
+ eventHandlers
2802
+ );
2803
+ useEffect13(() => {
2804
+ if (model3DNativeRef.current) {
2805
+ model3DNativeRef.current.updateRectAndTransform(
2806
+ domRect,
2807
+ theSpatialTransform
2808
+ );
2809
+ }
2810
+ }, [model3DNativeRef.current, domRect, theSpatialTransform]);
2811
+ useEffect13(() => {
2812
+ if (model3DNativeRef.current) {
2813
+ model3DNativeRef.current.setRotationAnchor(anchor);
2814
+ }
2815
+ }, [model3DNativeRef.current, anchor]);
2816
+ useEffect13(() => {
2817
+ if (model3DNativeRef.current) {
2818
+ model3DNativeRef.current.setVisible(visible);
2819
+ }
2820
+ }, [model3DNativeRef.current, visible]);
2821
+ useEffect13(() => {
2822
+ if (model3DNativeRef.current) {
2823
+ model3DNativeRef.current.setContentMode(contentMode);
2824
+ }
2825
+ }, [model3DNativeRef.current, contentMode]);
2826
+ useEffect13(() => {
2827
+ if (model3DNativeRef.current) {
2828
+ model3DNativeRef.current.setResizable(resizable);
2829
+ }
2830
+ }, [model3DNativeRef.current, resizable]);
2831
+ useEffect13(() => {
2832
+ if (model3DNativeRef.current) {
2833
+ model3DNativeRef.current.setAspectRatio(aspectRatio);
2834
+ }
2835
+ }, [model3DNativeRef.current, aspectRatio]);
2836
+ useEffect13(() => {
2837
+ if (model3DNativeRef.current) {
2838
+ model3DNativeRef.current.setOpacity(opacity);
2839
+ }
2840
+ }, [model3DNativeRef.current, opacity]);
2841
+ const onSuccess = useCallback5(() => {
2842
+ ;
2843
+ modelRef.current.ready = true;
2844
+ if (onLoad) {
2845
+ onLoad({
2846
+ target: modelRef.current
2847
+ });
2848
+ }
2849
+ }, [onLoad]);
2850
+ const onFailure = useCallback5(
2851
+ (_2) => {
2852
+ const modelElement = modelRef.current;
2853
+ modelElement.ready = false;
2854
+ if (onLoad) {
2855
+ onLoad({
2856
+ target: modelRef.current
2857
+ });
2858
+ }
2859
+ },
2860
+ [onLoad]
2861
+ );
2862
+ useEffect13(() => {
2863
+ if (phase === "failure") {
2864
+ onFailure(failureReason);
2865
+ } else if (phase === "success") {
2866
+ onSuccess();
2867
+ }
2868
+ }, [phase]);
2869
+ useEffect13(() => {
2870
+ return () => {
2871
+ const modelElement = modelRef.current;
2872
+ if (modelElement) {
2873
+ modelElement.ready = false;
2874
+ modelElement.currentSrc = modelUrl;
2875
+ }
2876
+ };
2877
+ }, [modelUrl]);
2878
+ const needRenderPlaceHolder = inheritedPortalStyle.position !== "absolute";
2879
+ if (!needRenderPlaceHolder && phase !== "failure") {
2880
+ return /* @__PURE__ */ jsx10(Fragment2, {});
2881
+ } else {
2882
+ const extraStyle = {
2883
+ visibility: "visible",
2884
+ top: "0px",
2885
+ left: "0px",
2886
+ margin: "0px",
2887
+ marginLeft: "0px",
2888
+ marginRight: "0px",
2889
+ marginTop: "0px",
2890
+ marginBottom: "0px",
2891
+ borderRadius: "0px",
2892
+ overflow: "",
2893
+ width: `${domRect.width}px`,
2894
+ height: `${domRect.height}px`
2895
+ };
2896
+ const style = {
2897
+ ...inheritedPortalStyle,
2898
+ ...extraStyle
2899
+ };
2900
+ return /* @__PURE__ */ jsx10(
2901
+ "div",
2902
+ {
2903
+ "data-model3d-spatialid": spatialId,
2904
+ className,
2905
+ style,
2906
+ children: phase === "failure" && children
2907
+ }
2908
+ );
2909
+ }
2910
+ }
2911
+
2912
+ // src/spatial-react-components/Model3D/Model3D.tsx
2913
+ function Model3DBase(props, refIn) {
2914
+ const parentSpatialReactContextObject = useContext8(SpatialReactContext);
2915
+ const isInSpatialDiv = !!parentSpatialReactContextObject;
2916
+ if (isInSpatialDiv) {
2917
+ const layer = useContext8(SpatialLayerContext) + 1;
2918
+ const isInStandardInstance = !!useContext8(SpatialIsStandardInstanceContext);
2919
+ const spatialId = useMemo6(() => {
2920
+ return parentSpatialReactContextObject.getSpatialID(
2921
+ layer,
2922
+ isInStandardInstance,
2923
+ "Model3D"
2924
+ );
2925
+ }, []);
2926
+ if (isInStandardInstance) {
2927
+ return renderModel3DStandardInstance(spatialId, props, refIn);
2928
+ } else {
2929
+ return renderModel3DPortalInstance(spatialId, props);
2930
+ }
2931
+ } else {
2932
+ return renderModel3DNotInSpatialDiv(props, refIn);
2933
+ }
2934
+ }
2935
+ var Model3D = forwardRef7(Model3DBase);
2936
+ Model3D.displayName = "Model3D";
2937
+
2938
+ // src/spatial-react-components/Model3D/CSSModel3D.tsx
2939
+ import { forwardRef as forwardRef8, useContext as useContext11, useMemo as useMemo7 } from "react";
2940
+
2941
+ // src/spatial-react-components/Model3D/CSSModel3DNotInSpatialDiv.tsx
2942
+ import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
2943
+ function renderCSSModel3DNotInSpatialDiv(inProps, refIn) {
2944
+ const { className, style = {}, ...props } = inProps;
2945
+ const cssParserDomStyle = {
2946
+ ...style,
2947
+ width: 0,
2948
+ height: 0,
2949
+ padding: 0
2950
+ };
2951
+ const { ref: cssParserDomRef, spatialStyle, ready } = useSpatialStyle();
2952
+ const ref = useHijackSpatialDivRef(
2953
+ refIn,
2954
+ cssParserDomRef
2955
+ );
2956
+ const spatialTransform = {
2957
+ position: spatialStyle.position,
2958
+ rotation: spatialStyle.rotation,
2959
+ scale: spatialStyle.scale
2960
+ };
2961
+ const visible = spatialStyle.visible;
2962
+ const model3DStyle = {
2963
+ ...style,
2964
+ transform: "none"
2965
+ };
2966
+ return /* @__PURE__ */ jsxs5(Fragment3, { children: [
2967
+ ready && /* @__PURE__ */ jsx11(
2968
+ Model3D,
2969
+ {
2970
+ className,
2971
+ style: model3DStyle,
2972
+ ref,
2973
+ spatialTransform,
2974
+ visible,
2975
+ ...props
2976
+ }
2977
+ ),
2978
+ /* @__PURE__ */ jsx11(
2979
+ "div",
2980
+ {
2981
+ className,
2982
+ style: cssParserDomStyle,
2983
+ ref: cssParserDomRef
2984
+ }
2985
+ )
2986
+ ] });
2987
+ }
2988
+
2989
+ // src/spatial-react-components/Model3D/CSSModel3DStandardInstance.tsx
2990
+ import { useContext as useContext9, useEffect as useEffect14, useRef as useRef11 } from "react";
2991
+ import { jsx as jsx12 } from "react/jsx-runtime";
2992
+ function renderCSSModel3DStandardInstance(spatialId, inProps, refIn) {
2993
+ const { style: inStyle = {}, ...props } = inProps;
2994
+ const style = {
2995
+ ...inStyle,
2996
+ transform: "none",
2997
+ visibility: "hidden"
2998
+ };
2999
+ var cssParserRef = useRef11(null);
3000
+ const ref = useHijackSpatialDivRef(
3001
+ refIn,
3002
+ cssParserRef
3003
+ );
3004
+ const rootSpatialReactContextObject = useContext9(SpatialReactContext);
3005
+ useEffect14(() => {
3006
+ const onSubEvent = (dom) => {
3007
+ cssParserRef.current = dom;
3008
+ };
3009
+ rootSpatialReactContextObject.onSubDivEvent(spatialId, onSubEvent);
3010
+ return () => {
3011
+ rootSpatialReactContextObject.offSubDivEvent(spatialId);
3012
+ };
3013
+ }, []);
3014
+ return /* @__PURE__ */ jsx12(Model3D, { style, ...props, ref, visible: true });
3015
+ }
3016
+
3017
+ // src/spatial-react-components/Model3D/CSSModel3DPortalInstance.tsx
3018
+ import { useContext as useContext10, useEffect as useEffect15 } from "react";
3019
+ import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
3020
+ function renderCSSModel3DPortalInstance(spatialId, inProps) {
3021
+ const { className, style = {}, ...props } = inProps;
3022
+ const rootSpatialReactContextObject = useContext10(SpatialReactContext);
3023
+ const { ref, spatialStyle, ready } = useSpatialStyle();
3024
+ const spatialTransform = {
3025
+ position: spatialStyle.position,
3026
+ rotation: spatialStyle.rotation,
3027
+ scale: spatialStyle.scale
3028
+ };
3029
+ const visible = spatialStyle.visible;
3030
+ useEffect15(() => {
3031
+ rootSpatialReactContextObject.notifySubDivEvent(spatialId, ref.current);
3032
+ }, [ref.current]);
3033
+ const cssParserDomStyle = {
3034
+ ...style,
3035
+ width: 0,
3036
+ height: 0,
3037
+ padding: 0
3038
+ };
3039
+ const model3DStyle = {
3040
+ ...style,
3041
+ transform: "none"
3042
+ };
3043
+ return /* @__PURE__ */ jsxs6(Fragment4, { children: [
3044
+ ready && /* @__PURE__ */ jsx13(
3045
+ Model3D,
3046
+ {
3047
+ className,
3048
+ style: model3DStyle,
3049
+ spatialTransform,
3050
+ visible,
3051
+ ...props
3052
+ }
3053
+ ),
3054
+ /* @__PURE__ */ jsx13("div", { className, style: cssParserDomStyle, ref })
3055
+ ] });
3056
+ }
3057
+
3058
+ // src/spatial-react-components/Model3D/CSSModel3D.tsx
3059
+ function CSSModel3DBase(props, refIn) {
3060
+ const rootSpatialReactContextObject = useContext11(SpatialReactContext);
3061
+ const isInSpatialDiv = !!rootSpatialReactContextObject;
3062
+ if (isInSpatialDiv) {
3063
+ const layer = useContext11(SpatialLayerContext) + 1;
3064
+ const isInStandardInstance = !!useContext11(SpatialIsStandardInstanceContext);
3065
+ const spatialId = useMemo7(() => {
3066
+ return rootSpatialReactContextObject.getSubDivSpatialID(
3067
+ layer,
3068
+ isInStandardInstance,
3069
+ "CSSModel3D"
3070
+ );
3071
+ }, []);
3072
+ if (isInStandardInstance) {
3073
+ return renderCSSModel3DStandardInstance(spatialId, props, refIn);
3074
+ } else {
3075
+ return renderCSSModel3DPortalInstance(spatialId, props);
3076
+ }
3077
+ } else {
3078
+ return renderCSSModel3DNotInSpatialDiv(props, refIn);
3079
+ }
3080
+ }
3081
+ var CSSModel3D = forwardRef8(CSSModel3DBase);
3082
+ CSSModel3D.displayName = "CSSModel3D";
3083
+
3084
+ // src/spatial-react-components/Model/index.tsx
3085
+ import "@google/model-viewer";
3086
+ import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
3087
+ function renderInModel3D(inProps, ref, modelUrl, placeHolder) {
3088
+ const { poster, ...props } = inProps;
3089
+ return /* @__PURE__ */ jsxs7(CSSModel3D, { modelUrl, ...props, ref, children: [
3090
+ " ",
3091
+ placeHolder,
3092
+ " "
3093
+ ] });
3094
+ }
3095
+ function parseChildren(child) {
3096
+ if (child === void 0) {
3097
+ throw new Error("children with <source> required ");
3098
+ }
3099
+ const children = Children.toArray(child);
3100
+ const sourceElements = children.filter(
3101
+ (node) => node.type === "source"
3102
+ );
3103
+ if (sourceElements.length === 0) {
3104
+ throw new Error("children with at least one <source> required ");
3105
+ }
3106
+ const gltfSources = sourceElements.filter((node) => {
3107
+ const type = node.props?.type.trim();
3108
+ return type.startsWith("model/gltf-binary") || type.startsWith("model/gltf+json");
3109
+ });
3110
+ const usdzSources = sourceElements.filter(
3111
+ (node) => node.props?.type.trim().startsWith("model/vnd.usdz+zip")
3112
+ );
3113
+ let lastChild = children[children.length - 1];
3114
+ const placeHolder = sourceElements.indexOf(lastChild) < 0 ? lastChild : void 0;
3115
+ const gltfSourceURL = gltfSources.length > 0 && gltfSources[0].props?.src;
3116
+ const usdzSourceURL = usdzSources.length > 0 && usdzSources[0].props?.src;
3117
+ return {
3118
+ placeHolder,
3119
+ gltfSourceURL: getAbsoluteURL(gltfSourceURL),
3120
+ usdzSourceURL: getAbsoluteURL(usdzSourceURL)
3121
+ };
3122
+ }
3123
+ function ModelBase(inProps, ref) {
3124
+ const { children, ...props } = inProps;
3125
+ const { placeHolder, gltfSourceURL, usdzSourceURL } = useMemo8(
3126
+ () => parseChildren(children),
3127
+ [children]
3128
+ );
3129
+ const isWebEnv = !getSession();
3130
+ if (isWebEnv) {
3131
+ const myModelViewer = useRef12(null);
3132
+ const { className, style = {}, ...props2 } = inProps;
3133
+ useEffect16(() => {
3134
+ myModelViewer.current.addEventListener("load", (event) => {
3135
+ if (props2.onLoad) {
3136
+ props2.onLoad({
3137
+ target: { ready: true, currentSrc: gltfSourceURL }
3138
+ });
3139
+ }
3140
+ });
3141
+ myModelViewer.current.addEventListener("pointerdown", (event) => {
3142
+ if (props2.onDragStart) {
3143
+ props2.onDragStart({
3144
+ eventType: "dragstart",
3145
+ translation3D: { x: 0, y: 0, z: 0 },
3146
+ startLocation3D: { x: 0, y: 0, z: 0 },
3147
+ target: ref.current
3148
+ });
3149
+ }
3150
+ });
3151
+ myModelViewer.current.addEventListener("pointermove", (event) => {
3152
+ if (props2.onDrag) {
3153
+ props2.onDrag({
3154
+ eventType: "drag",
3155
+ translation3D: { x: 0, y: 0, z: 0 },
3156
+ startLocation3D: { x: 0, y: 0, z: 0 },
3157
+ target: ref.current
3158
+ });
3159
+ }
3160
+ });
3161
+ myModelViewer.current.addEventListener("pointerup", (event) => {
3162
+ if (props2.onDragEnd) {
3163
+ props2.onDragEnd({
3164
+ eventType: "dragend",
3165
+ translation3D: { x: 0, y: 0, z: 0 },
3166
+ startLocation3D: { x: 0, y: 0, z: 0 },
3167
+ target: ref.current
3168
+ });
3169
+ }
3170
+ });
3171
+ }, []);
3172
+ useEffect16(() => {
3173
+ if (props2.contentMode !== void 0 && props2.contentMode !== "fit") {
3174
+ console.warn(
3175
+ "Model element contentMode != fit isn't supported on 2D screens"
3176
+ );
3177
+ }
3178
+ if (props2.resizable !== void 0 && props2.resizable !== false) {
3179
+ console.warn(
3180
+ "Model element resizable != false isn't supported on 2D screens"
3181
+ );
3182
+ }
3183
+ if (props2.aspectRatio !== void 0 && props2.aspectRatio !== 1) {
3184
+ console.warn(
3185
+ "Model element aspectRatio != 1 isn't supported on 2D screens"
3186
+ );
3187
+ }
3188
+ }, [props2.contentMode, props2.resizable, props2.aspectRatio]);
3189
+ return /* @__PURE__ */ jsx14("div", { ref, className, style, children: /* @__PURE__ */ jsx14(
3190
+ "model-viewer",
3191
+ {
3192
+ ref: myModelViewer,
3193
+ style: {
3194
+ width: "100%",
3195
+ height: "100%"
3196
+ },
3197
+ src: gltfSourceURL,
3198
+ "camera-controls": true,
3199
+ "touch-action": "pan-y",
3200
+ poster: props2.poster
3201
+ }
3202
+ ) });
3203
+ } else {
3204
+ return renderInModel3D(props, ref, usdzSourceURL, placeHolder);
3205
+ }
3206
+ }
3207
+ var Model = forwardRef9(ModelBase);
3208
+ Model.displayName = "Model";
3209
+
3210
+ // src/XRApp.ts
3211
+ var defaultSceneConfig = {
3212
+ defaultSize: {
3213
+ width: 900,
3214
+ height: 700
3215
+ },
3216
+ resizability: "automatic"
3217
+ };
3218
+ var CONTEXT_WINDOW_URL = "webspatial://createWindowContext";
3219
+ var originalOpen = window.open;
3220
+ var XRApp = class _XRApp {
3221
+ static instance;
3222
+ static getInstance() {
3223
+ if (!_XRApp.instance) {
3224
+ _XRApp.instance = new _XRApp();
3225
+ }
3226
+ return _XRApp.instance;
3227
+ }
3228
+ handleATag(event) {
3229
+ const targetElement = event.target;
3230
+ if (targetElement.tagName === "A") {
3231
+ const link = targetElement;
3232
+ const target = link.target;
3233
+ const url = link.href;
3234
+ if (target && target !== "_self") {
3235
+ event.preventDefault();
3236
+ window.open(url, target);
3237
+ }
3238
+ }
3239
+ }
3240
+ init() {
3241
+ ;
3242
+ window.open = this.open;
3243
+ document.addEventListener("click", this.handleATag);
3244
+ }
3245
+ deinit() {
3246
+ ;
3247
+ window.open = originalOpen;
3248
+ document.removeEventListener("click", this.handleATag);
3249
+ }
3250
+ configMap = {};
3251
+ // name=>config
3252
+ getConfig(name) {
3253
+ if (name === void 0 || !this.configMap[name]) return void 0;
3254
+ return this.configMap[name];
3255
+ }
3256
+ async show(window2, cfg) {
3257
+ try {
3258
+ let session = getSession();
3259
+ await session._createScene(
3260
+ "Plain",
3261
+ // only support Plain for now
3262
+ {
3263
+ sceneData: {
3264
+ method: "showRoot",
3265
+ sceneConfig: cfg,
3266
+ // url: url,
3267
+ window: window2
3268
+ }
3269
+ }
3270
+ );
3271
+ } catch (error) {
3272
+ console.error(error);
3273
+ }
3274
+ }
3275
+ open = (url, target, features) => {
3276
+ const newWindow = originalOpen(url, target, features);
3277
+ if (url === CONTEXT_WINDOW_URL) return newWindow;
3278
+ if (target === "_self" || target === "_parent" || target === "_top") {
3279
+ return newWindow;
3280
+ }
3281
+ let cnt = 2;
3282
+ let timer = setInterval(async () => {
3283
+ cnt -= 1;
3284
+ if (cnt < 0) {
3285
+ clearInterval(timer);
3286
+ return;
3287
+ }
3288
+ if (newWindow._webSpatialID) {
3289
+ clearInterval(timer);
3290
+ let session = getSession();
3291
+ if (!session) {
3292
+ console.error("no session");
3293
+ } else {
3294
+ const cfg = this.getConfig(target);
3295
+ try {
3296
+ await session._createScene(
3297
+ "Plain",
3298
+ // only support Plain for now
3299
+ {
3300
+ sceneData: {
3301
+ method: "createRoot",
3302
+ sceneConfig: cfg,
3303
+ url,
3304
+ window: newWindow
3305
+ // windowID: (newWindow as any)._webSpatialID,
3306
+ // windowContainerID: (newWindow as any)._webSpatialGroupID,
3307
+ }
3308
+ }
3309
+ );
3310
+ if (typeof target === "string" && this.configMap[target]) {
3311
+ delete this.configMap[target];
3312
+ }
3313
+ } catch (error) {
3314
+ console.error(error);
3315
+ }
3316
+ }
3317
+ }
3318
+ }, 0);
3319
+ return newWindow;
3320
+ };
3321
+ initScene(name, callback) {
3322
+ this.configMap[name] = callback({ ...defaultSceneConfig });
3323
+ }
3324
+ };
3325
+ function initScene(name, callback) {
3326
+ return XRApp.getInstance().initScene(name, callback);
3327
+ }
3328
+ export {
3329
+ CSSSpatialDiv,
3330
+ CSSSpatialPrimitive,
3331
+ Model,
3332
+ SpatialDiv,
3333
+ SpatialMonitor,
3334
+ SpatialPrimitive,
3335
+ SpatialView,
3336
+ XRApp,
3337
+ defaultSceneConfig,
3338
+ enableDebugTool,
3339
+ getSession,
3340
+ initScene,
3341
+ notifyUpdateStandInstanceLayout,
3342
+ parseCornerRadius,
3343
+ withCSSSpatial,
3344
+ withSpatial
3345
+ };
3346
+ //# sourceMappingURL=index.mjs.map