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