@spatial-elements/core 0.1.0-beta.1

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 (299) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +17 -0
  3. package/dist/catalog/CarouselGlassCompositor.d.ts +24 -0
  4. package/dist/catalog/CarouselGlassCompositor.d.ts.map +1 -0
  5. package/dist/catalog/CarouselGlassCompositor.js +132 -0
  6. package/dist/catalog/CarouselGlassCompositor.js.map +1 -0
  7. package/dist/catalog/CatalogEndpointRegistry.d.ts +59 -0
  8. package/dist/catalog/CatalogEndpointRegistry.d.ts.map +1 -0
  9. package/dist/catalog/CatalogEndpointRegistry.js +187 -0
  10. package/dist/catalog/CatalogEndpointRegistry.js.map +1 -0
  11. package/dist/catalog/CatalogGeometryFade.d.ts +12 -0
  12. package/dist/catalog/CatalogGeometryFade.d.ts.map +1 -0
  13. package/dist/catalog/CatalogGeometryFade.js +67 -0
  14. package/dist/catalog/CatalogGeometryFade.js.map +1 -0
  15. package/dist/catalog/CatalogPreparation.d.ts +40 -0
  16. package/dist/catalog/CatalogPreparation.d.ts.map +1 -0
  17. package/dist/catalog/CatalogPreparation.js +141 -0
  18. package/dist/catalog/CatalogPreparation.js.map +1 -0
  19. package/dist/catalog/CatalogSections.d.ts +36 -0
  20. package/dist/catalog/CatalogSections.d.ts.map +1 -0
  21. package/dist/catalog/CatalogSections.js +51 -0
  22. package/dist/catalog/CatalogSections.js.map +1 -0
  23. package/dist/catalog/CatalogSpatialElementLayer.d.ts +149 -0
  24. package/dist/catalog/CatalogSpatialElementLayer.d.ts.map +1 -0
  25. package/dist/catalog/CatalogSpatialElementLayer.js +920 -0
  26. package/dist/catalog/CatalogSpatialElementLayer.js.map +1 -0
  27. package/dist/catalog/CatalogTransition.d.ts +93 -0
  28. package/dist/catalog/CatalogTransition.d.ts.map +1 -0
  29. package/dist/catalog/CatalogTransition.js +1299 -0
  30. package/dist/catalog/CatalogTransition.js.map +1 -0
  31. package/dist/catalog/EnvironmentCache.d.ts +30 -0
  32. package/dist/catalog/EnvironmentCache.d.ts.map +1 -0
  33. package/dist/catalog/EnvironmentCache.js +128 -0
  34. package/dist/catalog/EnvironmentCache.js.map +1 -0
  35. package/dist/catalog/PreparationGate.d.ts +10 -0
  36. package/dist/catalog/PreparationGate.d.ts.map +1 -0
  37. package/dist/catalog/PreparationGate.js +66 -0
  38. package/dist/catalog/PreparationGate.js.map +1 -0
  39. package/dist/catalog/PresentationLease.d.ts +16 -0
  40. package/dist/catalog/PresentationLease.d.ts.map +1 -0
  41. package/dist/catalog/PresentationLease.js +33 -0
  42. package/dist/catalog/PresentationLease.js.map +1 -0
  43. package/dist/catalog/SpatialGeometryCapture.d.ts +63 -0
  44. package/dist/catalog/SpatialGeometryCapture.d.ts.map +1 -0
  45. package/dist/catalog/SpatialGeometryCapture.js +158 -0
  46. package/dist/catalog/SpatialGeometryCapture.js.map +1 -0
  47. package/dist/catalog/assets/SpatialElementAssetManager.d.ts +92 -0
  48. package/dist/catalog/assets/SpatialElementAssetManager.d.ts.map +1 -0
  49. package/dist/catalog/assets/SpatialElementAssetManager.js +305 -0
  50. package/dist/catalog/assets/SpatialElementAssetManager.js.map +1 -0
  51. package/dist/catalog/assets/assetCosts.d.ts +4 -0
  52. package/dist/catalog/assets/assetCosts.d.ts.map +1 -0
  53. package/dist/catalog/assets/assetCosts.js +33 -0
  54. package/dist/catalog/assets/assetCosts.js.map +1 -0
  55. package/dist/catalog/assets/spatialElementAssetResources.d.ts +25 -0
  56. package/dist/catalog/assets/spatialElementAssetResources.d.ts.map +1 -0
  57. package/dist/catalog/assets/spatialElementAssetResources.js +100 -0
  58. package/dist/catalog/assets/spatialElementAssetResources.js.map +1 -0
  59. package/dist/catalog/carouselPanelProjection.d.ts +9 -0
  60. package/dist/catalog/carouselPanelProjection.d.ts.map +1 -0
  61. package/dist/catalog/carouselPanelProjection.js +33 -0
  62. package/dist/catalog/carouselPanelProjection.js.map +1 -0
  63. package/dist/catalog/carouselSelection.d.ts +7 -0
  64. package/dist/catalog/carouselSelection.d.ts.map +1 -0
  65. package/dist/catalog/carouselSelection.js +15 -0
  66. package/dist/catalog/carouselSelection.js.map +1 -0
  67. package/dist/catalog/catalogAction.d.ts +4 -0
  68. package/dist/catalog/catalogAction.d.ts.map +1 -0
  69. package/dist/catalog/catalogAction.js +9 -0
  70. package/dist/catalog/catalogAction.js.map +1 -0
  71. package/dist/catalog/catalogGeometryRequest.d.ts +13 -0
  72. package/dist/catalog/catalogGeometryRequest.d.ts.map +1 -0
  73. package/dist/catalog/catalogGeometryRequest.js +8 -0
  74. package/dist/catalog/catalogGeometryRequest.js.map +1 -0
  75. package/dist/catalog/catalogItems.d.ts +10 -0
  76. package/dist/catalog/catalogItems.d.ts.map +1 -0
  77. package/dist/catalog/catalogItems.js +23 -0
  78. package/dist/catalog/catalogItems.js.map +1 -0
  79. package/dist/catalog/catalogJourney.d.ts +38 -0
  80. package/dist/catalog/catalogJourney.d.ts.map +1 -0
  81. package/dist/catalog/catalogJourney.js +64 -0
  82. package/dist/catalog/catalogJourney.js.map +1 -0
  83. package/dist/catalog/catalogPage.d.ts +11 -0
  84. package/dist/catalog/catalogPage.d.ts.map +1 -0
  85. package/dist/catalog/catalogPage.js +2 -0
  86. package/dist/catalog/catalogPage.js.map +1 -0
  87. package/dist/catalog/catalogPose.d.ts +30 -0
  88. package/dist/catalog/catalogPose.d.ts.map +1 -0
  89. package/dist/catalog/catalogPose.js +35 -0
  90. package/dist/catalog/catalogPose.js.map +1 -0
  91. package/dist/catalog/catalogPresentation.d.ts +24 -0
  92. package/dist/catalog/catalogPresentation.d.ts.map +1 -0
  93. package/dist/catalog/catalogPresentation.js +56 -0
  94. package/dist/catalog/catalogPresentation.js.map +1 -0
  95. package/dist/catalog/catalogRecipes.d.ts +21 -0
  96. package/dist/catalog/catalogRecipes.d.ts.map +1 -0
  97. package/dist/catalog/catalogRecipes.js +84 -0
  98. package/dist/catalog/catalogRecipes.js.map +1 -0
  99. package/dist/catalog/catalogSurfaceCapture.d.ts +11 -0
  100. package/dist/catalog/catalogSurfaceCapture.d.ts.map +1 -0
  101. package/dist/catalog/catalogSurfaceCapture.js +11 -0
  102. package/dist/catalog/catalogSurfaceCapture.js.map +1 -0
  103. package/dist/catalog/catalogViewLink.d.ts +8 -0
  104. package/dist/catalog/catalogViewLink.d.ts.map +1 -0
  105. package/dist/catalog/catalogViewLink.js +37 -0
  106. package/dist/catalog/catalogViewLink.js.map +1 -0
  107. package/dist/catalog/rebasePresentation.d.ts +3 -0
  108. package/dist/catalog/rebasePresentation.d.ts.map +1 -0
  109. package/dist/catalog/rebasePresentation.js +26 -0
  110. package/dist/catalog/rebasePresentation.js.map +1 -0
  111. package/dist/catalog/spatialElementAssets.d.ts +158 -0
  112. package/dist/catalog/spatialElementAssets.d.ts.map +1 -0
  113. package/dist/catalog/spatialElementAssets.js +92 -0
  114. package/dist/catalog/spatialElementAssets.js.map +1 -0
  115. package/dist/catalog/spatialElementLodPair.d.ts +17 -0
  116. package/dist/catalog/spatialElementLodPair.d.ts.map +1 -0
  117. package/dist/catalog/spatialElementLodPair.js +5 -0
  118. package/dist/catalog/spatialElementLodPair.js.map +1 -0
  119. package/dist/catalog/transitionTiming.d.ts +15 -0
  120. package/dist/catalog/transitionTiming.d.ts.map +1 -0
  121. package/dist/catalog/transitionTiming.js +22 -0
  122. package/dist/catalog/transitionTiming.js.map +1 -0
  123. package/dist/index.d.ts +11 -0
  124. package/dist/index.d.ts.map +1 -0
  125. package/dist/index.js +8 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/spatial-element/SpatialElementDockController.d.ts +101 -0
  128. package/dist/spatial-element/SpatialElementDockController.d.ts.map +1 -0
  129. package/dist/spatial-element/SpatialElementDockController.js +627 -0
  130. package/dist/spatial-element/SpatialElementDockController.js.map +1 -0
  131. package/dist/spatial-element/spatialElement.d.ts +28 -0
  132. package/dist/spatial-element/spatialElement.d.ts.map +1 -0
  133. package/dist/spatial-element/spatialElement.js +45 -0
  134. package/dist/spatial-element/spatialElement.js.map +1 -0
  135. package/dist/spatial-element/spatialElementDock.d.ts +43 -0
  136. package/dist/spatial-element/spatialElementDock.d.ts.map +1 -0
  137. package/dist/spatial-element/spatialElementDock.js +126 -0
  138. package/dist/spatial-element/spatialElementDock.js.map +1 -0
  139. package/dist/spatial-element/spatialElementSectionRegistry.d.ts +29 -0
  140. package/dist/spatial-element/spatialElementSectionRegistry.d.ts.map +1 -0
  141. package/dist/spatial-element/spatialElementSectionRegistry.js +67 -0
  142. package/dist/spatial-element/spatialElementSectionRegistry.js.map +1 -0
  143. package/dist/spatial-element/types.d.ts +165 -0
  144. package/dist/spatial-element/types.d.ts.map +1 -0
  145. package/dist/spatial-element/types.js +2 -0
  146. package/dist/spatial-element/types.js.map +1 -0
  147. package/dist/stage/LiquidGlassPanel.d.ts +55 -0
  148. package/dist/stage/LiquidGlassPanel.d.ts.map +1 -0
  149. package/dist/stage/LiquidGlassPanel.js +447 -0
  150. package/dist/stage/LiquidGlassPanel.js.map +1 -0
  151. package/dist/stage/MinimapBlurPipeline.d.ts +34 -0
  152. package/dist/stage/MinimapBlurPipeline.d.ts.map +1 -0
  153. package/dist/stage/MinimapBlurPipeline.js +147 -0
  154. package/dist/stage/MinimapBlurPipeline.js.map +1 -0
  155. package/dist/stage/MinimapController.d.ts +113 -0
  156. package/dist/stage/MinimapController.d.ts.map +1 -0
  157. package/dist/stage/MinimapController.js +803 -0
  158. package/dist/stage/MinimapController.js.map +1 -0
  159. package/dist/stage/OrbitControlsInterop.d.ts +8 -0
  160. package/dist/stage/OrbitControlsInterop.d.ts.map +1 -0
  161. package/dist/stage/OrbitControlsInterop.js +19 -0
  162. package/dist/stage/OrbitControlsInterop.js.map +1 -0
  163. package/dist/stage/PageBindingController.d.ts +41 -0
  164. package/dist/stage/PageBindingController.d.ts.map +1 -0
  165. package/dist/stage/PageBindingController.js +92 -0
  166. package/dist/stage/PageBindingController.js.map +1 -0
  167. package/dist/stage/PanelPresentationController.d.ts +92 -0
  168. package/dist/stage/PanelPresentationController.d.ts.map +1 -0
  169. package/dist/stage/PanelPresentationController.js +569 -0
  170. package/dist/stage/PanelPresentationController.js.map +1 -0
  171. package/dist/stage/PresentationReadiness.d.ts +30 -0
  172. package/dist/stage/PresentationReadiness.d.ts.map +1 -0
  173. package/dist/stage/PresentationReadiness.js +94 -0
  174. package/dist/stage/PresentationReadiness.js.map +1 -0
  175. package/dist/stage/SpaceMouseAdapter.d.ts +76 -0
  176. package/dist/stage/SpaceMouseAdapter.d.ts.map +1 -0
  177. package/dist/stage/SpaceMouseAdapter.js +197 -0
  178. package/dist/stage/SpaceMouseAdapter.js.map +1 -0
  179. package/dist/stage/SpatialElementInteractionController.d.ts +126 -0
  180. package/dist/stage/SpatialElementInteractionController.d.ts.map +1 -0
  181. package/dist/stage/SpatialElementInteractionController.js +581 -0
  182. package/dist/stage/SpatialElementInteractionController.js.map +1 -0
  183. package/dist/stage/SpatialElementPresentationController.d.ts +82 -0
  184. package/dist/stage/SpatialElementPresentationController.d.ts.map +1 -0
  185. package/dist/stage/SpatialElementPresentationController.js +372 -0
  186. package/dist/stage/SpatialElementPresentationController.js.map +1 -0
  187. package/dist/stage/SpatialElementRefinement.d.ts +26 -0
  188. package/dist/stage/SpatialElementRefinement.d.ts.map +1 -0
  189. package/dist/stage/SpatialElementRefinement.js +105 -0
  190. package/dist/stage/SpatialElementRefinement.js.map +1 -0
  191. package/dist/stage/StageExperience.d.ts +536 -0
  192. package/dist/stage/StageExperience.d.ts.map +1 -0
  193. package/dist/stage/StageExperience.js +2399 -0
  194. package/dist/stage/StageExperience.js.map +1 -0
  195. package/dist/stage/StagePanelLayout.d.ts +15 -0
  196. package/dist/stage/StagePanelLayout.d.ts.map +1 -0
  197. package/dist/stage/StagePanelLayout.js +20 -0
  198. package/dist/stage/StagePanelLayout.js.map +1 -0
  199. package/dist/stage/StagePanelRuntime.d.ts +20 -0
  200. package/dist/stage/StagePanelRuntime.d.ts.map +1 -0
  201. package/dist/stage/StagePanelRuntime.js +2 -0
  202. package/dist/stage/StagePanelRuntime.js.map +1 -0
  203. package/dist/stage/StageRenderPipeline.d.ts +179 -0
  204. package/dist/stage/StageRenderPipeline.d.ts.map +1 -0
  205. package/dist/stage/StageRenderPipeline.js +901 -0
  206. package/dist/stage/StageRenderPipeline.js.map +1 -0
  207. package/dist/stage/VirtualScrollController.d.ts +64 -0
  208. package/dist/stage/VirtualScrollController.d.ts.map +1 -0
  209. package/dist/stage/VirtualScrollController.js +329 -0
  210. package/dist/stage/VirtualScrollController.js.map +1 -0
  211. package/dist/stage/cssProjection.d.ts +18 -0
  212. package/dist/stage/cssProjection.d.ts.map +1 -0
  213. package/dist/stage/cssProjection.js +52 -0
  214. package/dist/stage/cssProjection.js.map +1 -0
  215. package/dist/stage/damping.d.ts +3 -0
  216. package/dist/stage/damping.d.ts.map +1 -0
  217. package/dist/stage/damping.js +8 -0
  218. package/dist/stage/damping.js.map +1 -0
  219. package/dist/stage/minimap/MinimapGeometry.d.ts +31 -0
  220. package/dist/stage/minimap/MinimapGeometry.d.ts.map +1 -0
  221. package/dist/stage/minimap/MinimapGeometry.js +163 -0
  222. package/dist/stage/minimap/MinimapGeometry.js.map +1 -0
  223. package/dist/stage/minimap/MinimapModel.d.ts +16 -0
  224. package/dist/stage/minimap/MinimapModel.d.ts.map +1 -0
  225. package/dist/stage/minimap/MinimapModel.js +51 -0
  226. package/dist/stage/minimap/MinimapModel.js.map +1 -0
  227. package/dist/stage/minimap/MinimapProjection.d.ts +41 -0
  228. package/dist/stage/minimap/MinimapProjection.d.ts.map +1 -0
  229. package/dist/stage/minimap/MinimapProjection.js +113 -0
  230. package/dist/stage/minimap/MinimapProjection.js.map +1 -0
  231. package/dist/stage/minimap/MinimapState.d.ts +102 -0
  232. package/dist/stage/minimap/MinimapState.d.ts.map +1 -0
  233. package/dist/stage/minimap/MinimapState.js +2 -0
  234. package/dist/stage/minimap/MinimapState.js.map +1 -0
  235. package/dist/stage/minimapMeasurement.d.ts +5 -0
  236. package/dist/stage/minimapMeasurement.d.ts.map +1 -0
  237. package/dist/stage/minimapMeasurement.js +11 -0
  238. package/dist/stage/minimapMeasurement.js.map +1 -0
  239. package/dist/stage/panelContext.d.ts +71 -0
  240. package/dist/stage/panelContext.d.ts.map +1 -0
  241. package/dist/stage/panelContext.js +6 -0
  242. package/dist/stage/panelContext.js.map +1 -0
  243. package/dist/stage/panelShadow.d.ts +20 -0
  244. package/dist/stage/panelShadow.d.ts.map +1 -0
  245. package/dist/stage/panelShadow.js +22 -0
  246. package/dist/stage/panelShadow.js.map +1 -0
  247. package/dist/stage/renderMeasurement.d.ts +3 -0
  248. package/dist/stage/renderMeasurement.d.ts.map +1 -0
  249. package/dist/stage/renderMeasurement.js +19 -0
  250. package/dist/stage/renderMeasurement.js.map +1 -0
  251. package/dist/stage/renderTargetInventory.d.ts +17 -0
  252. package/dist/stage/renderTargetInventory.d.ts.map +1 -0
  253. package/dist/stage/renderTargetInventory.js +27 -0
  254. package/dist/stage/renderTargetInventory.js.map +1 -0
  255. package/dist/stage/rendererState.d.ts +14 -0
  256. package/dist/stage/rendererState.d.ts.map +1 -0
  257. package/dist/stage/rendererState.js +35 -0
  258. package/dist/stage/rendererState.js.map +1 -0
  259. package/dist/stage/resolveStageProfile.d.ts +44 -0
  260. package/dist/stage/resolveStageProfile.d.ts.map +1 -0
  261. package/dist/stage/resolveStageProfile.js +30 -0
  262. package/dist/stage/resolveStageProfile.js.map +1 -0
  263. package/dist/stage/scrollAnimation.d.ts +10 -0
  264. package/dist/stage/scrollAnimation.d.ts.map +1 -0
  265. package/dist/stage/scrollAnimation.js +11 -0
  266. package/dist/stage/scrollAnimation.js.map +1 -0
  267. package/dist/stage/scrollFrame.d.ts +43 -0
  268. package/dist/stage/scrollFrame.d.ts.map +1 -0
  269. package/dist/stage/scrollFrame.js +232 -0
  270. package/dist/stage/scrollFrame.js.map +1 -0
  271. package/dist/stage/spatialElementFrame.d.ts +6 -0
  272. package/dist/stage/spatialElementFrame.d.ts.map +1 -0
  273. package/dist/stage/spatialElementFrame.js +22 -0
  274. package/dist/stage/spatialElementFrame.js.map +1 -0
  275. package/dist/stage/stageConstants.d.ts +85 -0
  276. package/dist/stage/stageConstants.d.ts.map +1 -0
  277. package/dist/stage/stageConstants.js +85 -0
  278. package/dist/stage/stageConstants.js.map +1 -0
  279. package/dist/stage/stageDom.d.ts +10 -0
  280. package/dist/stage/stageDom.d.ts.map +1 -0
  281. package/dist/stage/stageDom.js +22 -0
  282. package/dist/stage/stageDom.js.map +1 -0
  283. package/dist/stage/stageMath.d.ts +187 -0
  284. package/dist/stage/stageMath.d.ts.map +1 -0
  285. package/dist/stage/stageMath.js +344 -0
  286. package/dist/stage/stageMath.js.map +1 -0
  287. package/dist/stage/stageSceneUtils.d.ts +42 -0
  288. package/dist/stage/stageSceneUtils.d.ts.map +1 -0
  289. package/dist/stage/stageSceneUtils.js +154 -0
  290. package/dist/stage/stageSceneUtils.js.map +1 -0
  291. package/dist/stage/stageTypes.d.ts +189 -0
  292. package/dist/stage/stageTypes.d.ts.map +1 -0
  293. package/dist/stage/stageTypes.js +2 -0
  294. package/dist/stage/stageTypes.js.map +1 -0
  295. package/dist/stage/stageVisualTest.d.ts +92 -0
  296. package/dist/stage/stageVisualTest.d.ts.map +1 -0
  297. package/dist/stage/stageVisualTest.js +5 -0
  298. package/dist/stage/stageVisualTest.js.map +1 -0
  299. package/package.json +61 -0
@@ -0,0 +1,2399 @@
1
+ import { describeRenderTargets } from './renderTargetInventory.js';
2
+ import { StageRenderPipeline } from './StageRenderPipeline.js';
3
+ import { PanelPresentationController } from './PanelPresentationController.js';
4
+ import { MinimapController } from './MinimapController.js';
5
+ import { SpatialElementInteractionController } from './SpatialElementInteractionController.js';
6
+ import { SpatialElementPresentationController } from './SpatialElementPresentationController.js';
7
+ import { PageBindingController } from './PageBindingController.js';
8
+ import { resolveStageProfile } from './resolveStageProfile.js';
9
+ import { PreparationGate } from '../catalog/PreparationGate.js';
10
+ import { EnvironmentCache } from '../catalog/EnvironmentCache.js';
11
+ import { CatalogPreparation } from '../catalog/CatalogPreparation.js';
12
+ import {} from '../catalog/transitionTiming.js';
13
+ import * as THREE from 'three/webgpu';
14
+ import { SpatialElementAssetManager } from '../catalog/assets/SpatialElementAssetManager.js';
15
+ import { SpatialElementEntityStore } from '../catalog/spatialElementAssets.js';
16
+ import { CatalogSpatialElementLayer } from '../catalog/CatalogSpatialElementLayer.js';
17
+ import { SpatialGeometryCapture, captureSpatialElementProjection } from '../catalog/SpatialGeometryCapture.js';
18
+ import { captureCssSurface } from '../catalog/catalogSurfaceCapture.js';
19
+ import { getCatalogTransitionOpacity, normalizeCatalogPresentation, RESTING_CATALOG_PRESENTATION } from '../catalog/catalogPresentation.js';
20
+ import { CSS3DRenderer } from 'three/addons/renderers/CSS3DRenderer.js';
21
+ import { uniform } from 'three/tsl';
22
+ import { LiquidGlassPanel, resolveLiquidGlassPanelOptions } from './LiquidGlassPanel.js';
23
+ import { STAGE_PANEL_LAYOUT_EVENT, STAGE_PANEL_VISUAL_EVENT } from './panelContext.js';
24
+ import { DEFAULT_INTERACTION_THEME, DEFAULT_PANELS, PANEL_CAMERA_FOV, PANEL_CONTENT_Z, SPATIAL_ELEMENT_CAMERA_FIT_MARGIN, ZOOM_FOCUS_NOTIFY_EPSILON } from './stageConstants.js';
25
+ import { getStagePositionFromRect, isViewportRectVisible } from './stageDom.js';
26
+ import { STAGE_SCROLL_PRIORITY, getStageVisualScrollPosition, subscribeStageScrollFrame } from './scrollFrame.js';
27
+ import { getCameraFitDistance, getCameraOrbitDirection, getBoxCorners, getPanelFocusOpacity, getPerspectiveDistance, getSequencedMinimapFocus, getStageUiFocus, getZoomFocusDistanceRange, hasPanelGeometryChanged } from './stageMath.js';
28
+ import {} from './SpaceMouseAdapter.js';
29
+ import { disposeMinimapModelMaterials } from './minimap/MinimapModel.js';
30
+ import {} from './minimap/MinimapProjection.js';
31
+ import { disposeMaterialOnly, getMeshBounds, getMeshMaterials, isMesh } from './stageSceneUtils.js';
32
+ const SCROLL_SETTLE_DELAY = 120;
33
+ const VIEWPORT_CULL_MARGIN = 96;
34
+ /** Shared spatial state for both WebGPU glass and DOM-backed panel surfaces. */
35
+ /**
36
+ * Coordinates the WebGPU element scene, glass panels, accessible CSS3D content,
37
+ * pointer interaction, camera controls, and optional element minimaps.
38
+ *
39
+ * Rendering helpers and deterministic calculations live in focused modules; this
40
+ * class remains the public lifecycle facade consumed by the Svelte component.
41
+ */
42
+ export class StageExperience {
43
+ container;
44
+ captureGeometry(source) {
45
+ switch (source.slot) {
46
+ case 'detail.dock':
47
+ return this.captureDockPresentation(source.spatialElementId);
48
+ case 'detail.hero':
49
+ return this.captureReturnGeometry(source.spatialElementId);
50
+ default:
51
+ return this.captureCatalogGeometry(source.spatialElementId);
52
+ }
53
+ }
54
+ prepareGeometryDestination(destination) {
55
+ return destination.kind === 'content'
56
+ ? this.prepareReturnDestination()
57
+ : this.prepareCatalogDestination(destination.kind === 'dock');
58
+ }
59
+ pipeline;
60
+ backgroundSettings;
61
+ pageBackground = '#ffffff';
62
+ hdr;
63
+ glb;
64
+ lodPair;
65
+ get lowModel() {
66
+ return this.presentation.lowModel;
67
+ }
68
+ get referenceBounds() {
69
+ return this.presentation.referenceBounds;
70
+ }
71
+ get highInstance() {
72
+ return this.presentation.highInstance;
73
+ }
74
+ get highPose() {
75
+ return this.presentation.highPose;
76
+ }
77
+ get refinement() {
78
+ return this.presentation.refinement;
79
+ }
80
+ get refinementState() {
81
+ return this.presentation.refinementState;
82
+ }
83
+ get refinementFrames() {
84
+ return this.presentation.refinementFrames;
85
+ }
86
+ modelSettings;
87
+ cameraSettings;
88
+ excludedMeshNames;
89
+ interactionTheme;
90
+ pageBinding = new PageBindingController();
91
+ get panelTargets() {
92
+ return this.pageBinding.panels;
93
+ }
94
+ get viewportTarget() {
95
+ return this.pageBinding.viewport;
96
+ }
97
+ panels;
98
+ minimapController;
99
+ interaction;
100
+ spaceMouseEnabled;
101
+ fallbackPanelOptions;
102
+ catalog;
103
+ catalogLayer;
104
+ catalogHandoff = false;
105
+ catalogMotionComplete = false;
106
+ catalogLayerAnimating = false;
107
+ catalogPresentation = { ...RESTING_CATALOG_PRESENTATION };
108
+ pageModelReady = false;
109
+ preparationGate = new PreparationGate();
110
+ /** Optional High build/warm must not compete with required Low destination binding. */
111
+ detailPreparationGate = new PreparationGate();
112
+ assets = new SpatialElementAssetManager({ preparationGate: this.preparationGate });
113
+ presentation = new SpatialElementPresentationController(this.assets, () => this.requestRender());
114
+ environments;
115
+ preparation;
116
+ get pagePreparation() {
117
+ return this.presentation.readiness.entry;
118
+ }
119
+ get catalogMode() {
120
+ return this.presentation.readiness.mode;
121
+ }
122
+ get catalogBlend() {
123
+ return this.presentation.catalogBlend;
124
+ }
125
+ get returnBlend() {
126
+ return this.presentation.returnBlend;
127
+ }
128
+ spatialCapture;
129
+ exitingMinimaps = [];
130
+ adoptedForward = false;
131
+ returnSpatialElement;
132
+ contentSecondaries = [];
133
+ returnProjection;
134
+ returnProgress = 0;
135
+ outgoingBackground = false;
136
+ catalogDockTarget = false;
137
+ get deferDetailPreparation() {
138
+ return this.presentation.readiness.deferred;
139
+ }
140
+ heroIsPresented = () => true;
141
+ get backgroundPending() {
142
+ return this.presentation.readiness.backgroundPending;
143
+ }
144
+ get catalogBackgroundPrepared() {
145
+ return this.presentation.readiness.backgroundPrepared;
146
+ }
147
+ get backgroundApplied() {
148
+ return this.presentation.readiness.backgroundApplied;
149
+ }
150
+ spatialElements = new SpatialElementEntityStore();
151
+ get assetInstance() {
152
+ return this.presentation.assetInstance;
153
+ }
154
+ get loadedModelKey() {
155
+ return this.presentation.modelKey;
156
+ }
157
+ scene = new THREE.Scene();
158
+ backgroundScene = new THREE.Scene();
159
+ tintScene = new THREE.Scene();
160
+ panelScene = new THREE.Scene();
161
+ get minimapScene() {
162
+ return this.minimapController.scene;
163
+ }
164
+ panelContentScene = new THREE.Scene();
165
+ camera = new THREE.PerspectiveCamera(45, 1, 0.01, 100);
166
+ tintCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
167
+ panelCamera = new THREE.PerspectiveCamera(PANEL_CAMERA_FOV, 1, 0.1, 5000);
168
+ renderer = new THREE.WebGPURenderer({ antialias: true });
169
+ backgroundCanvasTarget = this.renderer.getCanvasTarget();
170
+ backgroundCanvas = this.renderer.domElement;
171
+ cssRenderer = new CSS3DRenderer();
172
+ flatPanelLayer = document.createElement('div');
173
+ nativePanelLayer = document.createElement('div');
174
+ get panelRuntimes() {
175
+ return this.panels.runtimes;
176
+ }
177
+ get minimaps() {
178
+ return this.minimapController.views;
179
+ }
180
+ resize = () => this.resizeRenderer();
181
+ render = () => {
182
+ this.renderRequestId = 0;
183
+ this.renderFrame();
184
+ };
185
+ visibilityChange = () => {
186
+ if (!document.hidden)
187
+ this.requestRender();
188
+ };
189
+ pointerMove = (event) => this.handlePointerMove(event);
190
+ pointerLeave = () => this.handlePointerLeave();
191
+ pointerDown = (event) => this.handlePointerDown(event);
192
+ pointerUp = (event) => this.handlePointerUp(event);
193
+ wheel = (event) => this.handleWheel(event);
194
+ scroll = (frame) => this.handleScrollFrame(frame);
195
+ finishScroll = () => {
196
+ this.scrollEndTimer = 0;
197
+ if (this.disposed)
198
+ return;
199
+ this.scrollActive = false;
200
+ this.pipeline.setScrollRenderQuality(false);
201
+ this.panelMeasurementsDirty = true;
202
+ this.viewportMeasurementDirty = true;
203
+ this.layoutDirty = true;
204
+ this.requestRender();
205
+ };
206
+ requestPanelSync = () => {
207
+ this.layoutDirty = true;
208
+ this.panelMeasurementsDirty = true;
209
+ this.viewportMeasurementDirty = true;
210
+ this.requestRender();
211
+ };
212
+ requestPanelVisualSync = () => this.requestRender();
213
+ get pointer() {
214
+ return this.interaction.pointer;
215
+ }
216
+ onZoomFocusChange;
217
+ viewportFrame = new THREE.Vector4(0, 0, 1, 1);
218
+ viewportLayoutSize = new THREE.Vector2(1, 1);
219
+ fittedViewportMetrics = new THREE.Vector4();
220
+ modelBounds = new THREE.Box3();
221
+ get controls() {
222
+ return this.interaction.controls;
223
+ }
224
+ get spaceMouseMoving() {
225
+ return this.interaction.spaceMouseMoving;
226
+ }
227
+ environmentTarget;
228
+ get model() {
229
+ return this.presentation.model;
230
+ }
231
+ get modelHover() {
232
+ return this.interaction.modelHover;
233
+ }
234
+ get modelInteractionActive() {
235
+ return this.interaction.modelInteractionActive;
236
+ }
237
+ tintGeometry;
238
+ disposed = false;
239
+ tintMaterial;
240
+ catalogBackgroundReveal = uniform(1);
241
+ stopScrollFrames;
242
+ renderRequestId = 0;
243
+ renderInvalidated = true;
244
+ animationActive = false;
245
+ scrollActive = false;
246
+ scrollEndTimer = 0;
247
+ lastInteractionTime = performance.now();
248
+ layoutDirty = true;
249
+ panelMeasurementsDirty = true;
250
+ viewportMeasurementDirty = true;
251
+ stageViewportVisible = true;
252
+ get visiblePanelCount() {
253
+ return this.panels.visiblePanels;
254
+ }
255
+ get visibleMinimapCount() {
256
+ return this.panels.visibleMinimaps;
257
+ }
258
+ get focusCloseDistance() {
259
+ return this.interaction.focusCloseDistance;
260
+ }
261
+ modelRadius = 1;
262
+ panelFocus = 0;
263
+ panelUiFocus = 0;
264
+ minimapFocus = 0;
265
+ currentScrollX = 0;
266
+ currentScrollY = 0;
267
+ lastScrollY = 0;
268
+ lastReportedZoomFocus = {
269
+ focus: -1,
270
+ uiFocus: -1,
271
+ uiOpacity: -1,
272
+ minimapFocus: -1
273
+ };
274
+ get zoomResetTargetDistance() {
275
+ return this.interaction.zoomResetTargetDistance;
276
+ }
277
+ get wheelZoomTargetDistance() {
278
+ return this.interaction.wheelZoomTargetDistance;
279
+ }
280
+ get initialCameraPosition() {
281
+ return this.interaction.initialCameraPosition;
282
+ }
283
+ get initialControlsTarget() {
284
+ return this.interaction.initialControlsTarget;
285
+ }
286
+ initialCameraWorldQuaternion = new THREE.Quaternion();
287
+ initialModelWorldQuaternion = new THREE.Quaternion();
288
+ get initialCameraFov() {
289
+ return this.interaction.initialCameraFov;
290
+ }
291
+ get initialViewCaptured() {
292
+ return this.interaction.initialViewCaptured;
293
+ }
294
+ get viewResetActive() {
295
+ return this.interaction.viewResetActive;
296
+ }
297
+ /**
298
+ * Creates a stage lifecycle facade for one container.
299
+ *
300
+ * @param container - Element that receives the WebGPU and CSS3D renderer layers.
301
+ * @param options - Scene assets, panel registrations, viewport anchor, and callbacks.
302
+ */
303
+ constructor(container, options = {}) {
304
+ this.container = container;
305
+ if (options.dracoDecoderPath)
306
+ this.assets.setDracoDecoderPath(options.dracoDecoderPath);
307
+ this.interaction = new SpatialElementInteractionController({
308
+ camera: this.camera,
309
+ canvas: this.backgroundCanvas,
310
+ container,
311
+ cssRoot: this.cssRenderer.domElement,
312
+ requestRender: () => this.requestRender(),
313
+ markActivity: () => {
314
+ this.lastInteractionTime = performance.now();
315
+ },
316
+ updateProjection: () => this.updateStageCameraProjection(),
317
+ readGeometry: () => ({
318
+ poseOwner: this.catalogHandoff || this.spatialCapture
319
+ ? 'transition'
320
+ : this.catalog && !this.viewportTarget
321
+ ? 'none'
322
+ : 'page',
323
+ visible: this.stageViewportVisible,
324
+ viewport: this.viewportFrame,
325
+ bounds: this.modelBounds
326
+ })
327
+ });
328
+ this.minimapController = new MinimapController({
329
+ renderer: this.renderer,
330
+ camera: this.camera,
331
+ panelCamera: this.panelCamera,
332
+ panelScene: this.panelScene,
333
+ panel: (index) => this.panelRuntimes[index],
334
+ target: (index) => this.panelTargets[index],
335
+ spatialElement: () => ({
336
+ model: this.model,
337
+ low: this.lowModel,
338
+ camera: this.cameraSettings,
339
+ restCamera: this.initialCameraWorldQuaternion,
340
+ restModel: this.initialModelWorldQuaternion,
341
+ hasControls: Boolean(this.controls),
342
+ referenceTarget: this.getZoomReferenceTarget()
343
+ }),
344
+ frame: () => ({
345
+ hovering: this.modelHover,
346
+ interacting: this.modelInteractionActive,
347
+ scrolling: this.scrollActive
348
+ }),
349
+ environment: () => this.environmentTarget,
350
+ capture: () => this.pipeline.activeRenderTargets,
351
+ blurTexture: (options) => this.pipeline.getPanelBlurTexture(options),
352
+ transitionOpacity: (panel) => this.getPanelTransitionOpacity(panel),
353
+ pixelRatio: () => this.pipeline.getFullPixelRatio(),
354
+ includeMesh: (mesh) => this.isSpatialElementMesh(mesh)
355
+ });
356
+ this.panels = new PanelPresentationController({
357
+ camera: this.panelCamera,
358
+ contentScene: this.panelContentScene,
359
+ flatLayer: this.flatPanelLayer,
360
+ nativeLayer: this.nativePanelLayer,
361
+ registrations: () => this.panelTargets,
362
+ minimaps: () => this.minimaps,
363
+ updateMinimap: (minimap, focus) => this.minimapController.updateMinimapState(minimap, focus),
364
+ frame: () => ({
365
+ presentation: this.catalogPresentation,
366
+ minimapFocus: this.minimapFocus,
367
+ uiFocus: this.panelUiFocus,
368
+ pointer: this.pointer
369
+ }),
370
+ visible: (index) => this.isPanelTargetVisible(index),
371
+ transitionOpacity: (panel) => this.getPanelTransitionOpacity(panel),
372
+ requestRender: () => this.requestRender()
373
+ });
374
+ const reportDeviceLost = this.renderer.onDeviceLost.bind(this.renderer);
375
+ this.renderer.onDeviceLost = (info) => {
376
+ reportDeviceLost(info);
377
+ if (!this.disposed)
378
+ queueMicrotask(() => {
379
+ if (!this.disposed)
380
+ options.onDeviceLost?.();
381
+ });
382
+ };
383
+ const profile = resolveStageProfile(options);
384
+ this.backgroundSettings = profile.background;
385
+ this.catalog = options.catalog ?? false;
386
+ this.hdr = profile.hdr;
387
+ this.glb = profile.glb;
388
+ this.lodPair = profile.lodPair;
389
+ this.modelSettings = profile.model;
390
+ this.cameraSettings = profile.camera;
391
+ this.excludedMeshNames = new Set(this.modelSettings.excludeMeshes ?? []);
392
+ this.interactionTheme = { ...DEFAULT_INTERACTION_THEME, ...options.interactionTheme };
393
+ this.pageBinding.attach(options.panels, options.viewport);
394
+ this.spaceMouseEnabled = options.enableSpaceMouse ?? true;
395
+ this.fallbackPanelOptions = this.panelTargets.length
396
+ ? this.panelTargets
397
+ .filter((panel) => panel.surface === 'glass' || (panel.surface === 'frosted' && Boolean(panel.minimap)))
398
+ .map((panel) => panel.options)
399
+ : this.catalog
400
+ ? []
401
+ : DEFAULT_PANELS;
402
+ this.pipeline = new StageRenderPipeline({
403
+ pageBackground: (this.pageBackground = options.pageBackground ?? '#ffffff'),
404
+ renderer: this.renderer,
405
+ container: this.container,
406
+ backgroundCanvas: this.backgroundCanvas,
407
+ backgroundCanvasTarget: this.backgroundCanvasTarget,
408
+ scene: this.scene,
409
+ backgroundScene: this.backgroundScene,
410
+ tintScene: this.tintScene,
411
+ panelScene: this.panelScene,
412
+ camera: this.camera,
413
+ panelCamera: this.panelCamera,
414
+ tintCamera: this.tintCamera,
415
+ panelRuntimes: () => this.panelRuntimes,
416
+ minimaps: () => this.minimaps,
417
+ minimapScene: () => this.minimapScene,
418
+ catalogLayer: () => this.catalogLayer,
419
+ spatialCapture: () => this.spatialCapture,
420
+ exitingMinimaps: () => this.exitingMinimaps,
421
+ contentSecondaries: () => this.contentSecondaries,
422
+ fallbackPanelOptions: () => this.fallbackPanelOptions,
423
+ interactionTheme: () => this.interactionTheme,
424
+ frame: () => ({
425
+ outgoingBackground: this.outgoingBackground,
426
+ catalogDockTarget: this.catalogDockTarget,
427
+ catalogHandoff: this.catalogHandoff,
428
+ catalogMotionComplete: this.catalogMotionComplete,
429
+ stageViewportVisible: this.stageViewportVisible,
430
+ modelHover: this.modelHover,
431
+ modelInteractionActive: this.modelInteractionActive,
432
+ catalog: this.catalog,
433
+ pageModelReady: this.pageModelReady,
434
+ backgroundReveal: this.catalogBackgroundReveal.value
435
+ }),
436
+ renderStage: () => this.renderStage(),
437
+ renderMinimapBlur: (view) => this.minimapController.renderMinimapBlur(view),
438
+ renderMinimapPanelCapture: (view) => this.minimapController.renderMinimapPanelCapture(view),
439
+ getPanelTransitionOpacity: (panel) => this.getPanelTransitionOpacity(panel),
440
+ isInteractionMesh: (mesh) => this.isInteractionMesh(mesh)
441
+ });
442
+ this.onZoomFocusChange = options.onZoomFocusChange;
443
+ }
444
+ /** Loads GPU resources and assets, creates panels, and starts the render loop. */
445
+ async init() {
446
+ if (!navigator.gpu) {
447
+ throw new Error('WebGPU is not available in this browser');
448
+ }
449
+ this.pipeline.configureRenderer();
450
+ await this.renderer.init();
451
+ this.environments = new EnvironmentCache(this.renderer, this.preparationGate);
452
+ this.preparation = new CatalogPreparation(this.assets, this.environments, this.detailPreparationGate, (high, environment, signal) => this.warmPreparedHigh(high, environment, signal), () => this.requestRender());
453
+ // Three reports unexpected loss but deliberately ignores device.destroy().
454
+ // A destroyed device is also unusable if our stage has not been disposed.
455
+ const device = this.renderer.backend.device;
456
+ void device?.lost.then((info) => {
457
+ if (!this.disposed && info.reason === 'destroyed') {
458
+ this.renderer.onDeviceLost({
459
+ api: 'WebGPU',
460
+ message: info.message,
461
+ reason: info.reason,
462
+ originalEvent: info
463
+ });
464
+ }
465
+ });
466
+ if (this.disposed) {
467
+ this.renderer.dispose();
468
+ return;
469
+ }
470
+ this.backgroundCanvas.className = 'stage-webgpu-background';
471
+ this.container.appendChild(this.backgroundCanvas);
472
+ this.configureCssRenderer();
473
+ this.container.appendChild(this.cssRenderer.domElement);
474
+ this.configureFlatPanelLayer();
475
+ this.container.appendChild(this.flatPanelLayer);
476
+ this.configureNativePanelLayer();
477
+ this.container.appendChild(this.nativePanelLayer);
478
+ this.pipeline.createForegroundCanvas();
479
+ this.interaction.initialize();
480
+ await this.loadEnvironment();
481
+ if (this.disposed)
482
+ return;
483
+ this.createBackgroundTint();
484
+ //this.createLights();
485
+ if (!this.catalog || this.viewportTarget)
486
+ await this.loadModel();
487
+ if (this.disposed)
488
+ return;
489
+ this.pageModelReady = Boolean(this.model);
490
+ if (!this.catalog || this.viewportTarget)
491
+ this.pipeline.createSceneCapture();
492
+ this.createPanels();
493
+ this.resizeRenderer();
494
+ this.pipeline.warmRenderTargetSets();
495
+ await this.pipeline.prepareZoomEffects();
496
+ if (this.disposed)
497
+ return;
498
+ this.observePanelTargets();
499
+ const scrollPosition = getStageVisualScrollPosition();
500
+ this.currentScrollX = scrollPosition.scrollX;
501
+ this.currentScrollY = scrollPosition.scrollY;
502
+ this.lastScrollY = this.currentScrollY;
503
+ window.addEventListener('resize', this.resize);
504
+ this.stopScrollFrames = subscribeStageScrollFrame(this.scroll, STAGE_SCROLL_PRIORITY.stage);
505
+ window.addEventListener(STAGE_PANEL_LAYOUT_EVENT, this.requestPanelSync);
506
+ window.addEventListener(STAGE_PANEL_VISUAL_EVENT, this.requestPanelVisualSync);
507
+ window.addEventListener('pointermove', this.pointerMove);
508
+ window.addEventListener('pointerup', this.pointerUp);
509
+ window.addEventListener('pointercancel', this.pointerUp);
510
+ window.addEventListener('pointerleave', this.pointerLeave);
511
+ window.addEventListener('blur', this.pointerLeave);
512
+ document.addEventListener('visibilitychange', this.visibilityChange);
513
+ this.backgroundCanvas.addEventListener('pointerdown', this.pointerDown, { capture: true });
514
+ this.backgroundCanvas.addEventListener('wheel', this.wheel, {
515
+ capture: true,
516
+ passive: false
517
+ });
518
+ if (this.spaceMouseEnabled)
519
+ void this.initializeSpaceMouse();
520
+ this.requestRender();
521
+ }
522
+ /** Releases listeners, DOM layers, scene resources, controls, and GPU allocations. */
523
+ dispose() {
524
+ if (this.disposed)
525
+ return;
526
+ this.disposed = true;
527
+ this.releaseSpatialCapture();
528
+ this.container.removeAttribute('data-stage-scroll-rendering');
529
+ window.removeEventListener('resize', this.resize);
530
+ this.stopScrollFrames?.();
531
+ this.stopScrollFrames = undefined;
532
+ window.removeEventListener(STAGE_PANEL_LAYOUT_EVENT, this.requestPanelSync);
533
+ window.removeEventListener(STAGE_PANEL_VISUAL_EVENT, this.requestPanelVisualSync);
534
+ window.removeEventListener('pointermove', this.pointerMove);
535
+ window.removeEventListener('pointerup', this.pointerUp);
536
+ window.removeEventListener('pointercancel', this.pointerUp);
537
+ window.removeEventListener('pointerleave', this.pointerLeave);
538
+ window.removeEventListener('blur', this.pointerLeave);
539
+ document.removeEventListener('visibilitychange', this.visibilityChange);
540
+ this.backgroundCanvas.removeEventListener('pointerdown', this.pointerDown, {
541
+ capture: true
542
+ });
543
+ this.backgroundCanvas.removeEventListener('wheel', this.wheel, { capture: true });
544
+ if (this.renderRequestId)
545
+ cancelAnimationFrame(this.renderRequestId);
546
+ this.renderRequestId = 0;
547
+ if (this.scrollEndTimer)
548
+ window.clearTimeout(this.scrollEndTimer);
549
+ this.scrollEndTimer = 0;
550
+ this.interaction.dispose();
551
+ this.releasePage();
552
+ this.tintGeometry?.dispose();
553
+ this.tintMaterial?.dispose();
554
+ this.pipeline.disposeSceneCapture();
555
+ this.pageBinding.clearMeasurements();
556
+ this.pageBinding.viewportRect = undefined;
557
+ this.releaseModel();
558
+ this.catalogLayer?.dispose();
559
+ this.assets.dispose();
560
+ this.spatialElements.clear();
561
+ this.preparationGate.setPaused(false);
562
+ this.preparation?.dispose();
563
+ this.detailPreparationGate.setPaused(false);
564
+ this.presentation.disposeEnvironment();
565
+ this.environments?.dispose();
566
+ this.pipeline.dispose();
567
+ this.renderer.dispose();
568
+ this.backgroundCanvas.remove();
569
+ this.cssRenderer.domElement.remove();
570
+ this.flatPanelLayer.remove();
571
+ this.nativePanelLayer.remove();
572
+ }
573
+ /** Page DOM is a replaceable binding, not the owner of the device or element cache. */
574
+ releasePage() {
575
+ this.pageBinding.invalidate();
576
+ this.pageModelReady = false;
577
+ this.presentation.cancelRequests();
578
+ this.minimapController.dispose();
579
+ this.panels.release();
580
+ this.pageBinding.release();
581
+ this.fallbackPanelOptions = [];
582
+ this.interaction.releasePage();
583
+ this.requestPanelSync();
584
+ }
585
+ /** A failed page binding owns no model or panels; the device/cache remain reusable. */
586
+ discardFailedPage() {
587
+ this.releasePage();
588
+ this.releaseModel();
589
+ this.pipeline.disposeSceneCapture();
590
+ this.finishCatalogGeometry();
591
+ // With no viewport the catalog path clears its overlay instead of retaining
592
+ // the last transition frame while the semantic page shows its poster.
593
+ this.renderFrame(true);
594
+ }
595
+ rememberDomHome(element) {
596
+ return this.panels.rememberDomHome(element);
597
+ }
598
+ resolvePanelSurface(element) {
599
+ return (this.panelTargets.find((target) => target.content === element || target.content.contains(element))?.frame ??
600
+ element.closest('[data-catalog-card]') ??
601
+ element);
602
+ }
603
+ capturePanelSurface(element) {
604
+ if (element.hasAttribute('data-catalog-dock-surface')) {
605
+ const header = element.closest('[data-spatial-element-sticky-header]');
606
+ if (header)
607
+ return captureCssSurface(element, header, '::before');
608
+ }
609
+ const panel = this.panelTargets.find((target) => target.content === element || target.content.contains(element));
610
+ if (!panel)
611
+ return captureCssSurface(element);
612
+ const surface = panel.surfaceElement;
613
+ const rect = surface.getBoundingClientRect();
614
+ const bounds = rect.width > 0 && rect.height > 0 && getComputedStyle(surface).visibility !== 'hidden'
615
+ ? surface
616
+ : panel.frame;
617
+ const paint = captureCssSurface(bounds, surface, '::before');
618
+ const runtime = this.panelRuntimes[this.panelTargets.indexOf(panel)];
619
+ if (runtime && !panel.minimap && runtime.domRenderMode === 'spatial') {
620
+ runtime.group.updateWorldMatrix(true, false);
621
+ const { width, height } = runtime.options;
622
+ const corners = [
623
+ [-width / 2, height / 2],
624
+ [width / 2, height / 2],
625
+ [width / 2, -height / 2],
626
+ [-width / 2, -height / 2]
627
+ ].map(([x, y]) => {
628
+ const point = new THREE.Vector3(x, y, 0)
629
+ .applyMatrix4(runtime.group.matrixWorld)
630
+ .project(this.panelCamera);
631
+ return new THREE.Vector2(((point.x + 1) * innerWidth) / 2, ((1 - point.y) * innerHeight) / 2);
632
+ });
633
+ return { ...paint, corners };
634
+ }
635
+ return paint;
636
+ }
637
+ /** Project authored DOM depth inside the actual CSS3D object, without flattening its type. */
638
+ capturePanelElement(element) {
639
+ const runtime = this.panelRuntimes.find((panel) => panel.domRenderMode === 'spatial' && panel.content?.element.contains(element));
640
+ const content = runtime?.content;
641
+ if (!content)
642
+ return;
643
+ const root = content.element;
644
+ const size = (node) => ({
645
+ width: Number.parseFloat(getComputedStyle(node).width) || node.offsetWidth,
646
+ height: Number.parseFloat(getComputedStyle(node).height) || node.offsetHeight
647
+ });
648
+ const { width, height } = size(element);
649
+ const rootSize = size(root);
650
+ if (!width || !height || !rootSize.width || !rootSize.height)
651
+ return;
652
+ content.updateWorldMatrix(true, false);
653
+ const project = (x, y) => {
654
+ let point = new DOMPoint(x, y, 0);
655
+ for (let node = element; node && node !== root;) {
656
+ const style = getComputedStyle(node);
657
+ const origin = style.transformOrigin.split(' ').map(Number.parseFloat);
658
+ const matrix = new DOMMatrix(style.transform === 'none' ? undefined : style.transform);
659
+ point = new DOMPoint(point.x - origin[0], point.y - origin[1], point.z - (origin[2] || 0)).matrixTransform(matrix);
660
+ point.x += origin[0] + node.offsetLeft;
661
+ point.y += origin[1] + node.offsetTop;
662
+ point.z += origin[2] || 0;
663
+ node = node.offsetParent;
664
+ if (!node || (node !== root && !root.contains(node)))
665
+ return;
666
+ }
667
+ const projected = new THREE.Vector3(point.x - rootSize.width / 2, rootSize.height / 2 - point.y, point.z)
668
+ .applyMatrix4(content.matrixWorld)
669
+ .project(this.panelCamera);
670
+ return { x: ((projected.x + 1) * innerWidth) / 2, y: ((1 - projected.y) * innerHeight) / 2 };
671
+ };
672
+ const corners = [project(0, 0), project(width, 0), project(width, height), project(0, height)];
673
+ if (corners.some((point) => !point))
674
+ return;
675
+ return { width, height, corners: corners };
676
+ }
677
+ async updatePage(options) {
678
+ if (this.disposed)
679
+ return;
680
+ this.pageBackground = options.pageBackground ?? '#ffffff';
681
+ this.pipeline.setPageBackground(this.pageBackground);
682
+ this.catalogLayer?.setPageBackground(this.pageBackground);
683
+ this.releasePage();
684
+ const generation = this.pageBinding.token;
685
+ const profile = resolveStageProfile(options, { glb: this.glb, hdr: this.hdr });
686
+ this.pageBinding.attach(options.panels, options.viewport);
687
+ this.hdr = profile.hdr;
688
+ this.backgroundSettings = profile.background;
689
+ this.presentation.readiness.reset(Boolean(options.deferDetailPreparation));
690
+ if (this.catalogPresentation.active)
691
+ this.catalogBackgroundReveal.value = 0;
692
+ this.heroIsPresented = options.heroIsPresented ?? (() => true);
693
+ if (this.catalog && this.viewportTarget && !this.deferDetailPreparation) {
694
+ this.presentation.readiness.attach(this.preparation.prepare({
695
+ hdr: this.hdr,
696
+ background: this.backgroundSettings,
697
+ glb: options.glb ?? this.glb,
698
+ lodPair: options.lodPair,
699
+ model: options.model
700
+ }));
701
+ }
702
+ else {
703
+ this.presentation.readiness.attach(undefined);
704
+ this.preparation.dispose();
705
+ if (!this.deferDetailPreparation)
706
+ await this.loadEnvironment();
707
+ }
708
+ if (this.disposed || !this.pageBinding.isCurrent(generation))
709
+ return;
710
+ this.fallbackPanelOptions = this.panelTargets
711
+ .filter((panel) => panel.surface === 'glass' || Boolean(panel.minimap))
712
+ .map((panel) => panel.options);
713
+ const requestedModelKey = profile.modelKey;
714
+ this.lodPair = profile.lodPair;
715
+ this.glb = profile.glb;
716
+ this.modelSettings = profile.model;
717
+ this.cameraSettings = profile.camera;
718
+ this.excludedMeshNames = new Set(this.modelSettings.excludeMeshes ?? []);
719
+ if (this.viewportTarget && (this.loadedModelKey !== requestedModelKey || !this.model))
720
+ await this.loadModel();
721
+ if (!this.viewportTarget)
722
+ this.releaseModel();
723
+ if (this.disposed || generation !== this.pageBinding.token)
724
+ return;
725
+ if (this.viewportTarget && this.model)
726
+ this.fitModelCamera();
727
+ this.pageModelReady = Boolean(this.viewportTarget && this.model);
728
+ if (this.pageModelReady)
729
+ this.startHighRequest();
730
+ this.pipeline.disposeSceneCapture();
731
+ if (!this.catalog || this.viewportTarget)
732
+ this.pipeline.createSceneCapture();
733
+ this.createPanels();
734
+ this.observePanelTargets();
735
+ this.resizeRenderer();
736
+ this.renderFrame(true);
737
+ await this.pipeline.prepareZoomEffects();
738
+ if (this.disposed || !this.pageBinding.isCurrent(generation))
739
+ return;
740
+ // A submitted Low/panel frame is not yet GPU-ready. Drain the required binding work
741
+ // before the navigation bridge starts motion, especially on the first cold DETAIL.
742
+ const device = this.renderer.backend.device;
743
+ await device?.queue.onSubmittedWorkDone();
744
+ if (this.disposed || generation !== this.pageBinding.token)
745
+ return;
746
+ if (this.spaceMouseEnabled && this.viewportTarget)
747
+ void this.initializeSpaceMouse();
748
+ }
749
+ setCatalogSpatialElements(brandId, items) {
750
+ this.catalogLayer ??= new CatalogSpatialElementLayer(this.assets, () => this.requestRender());
751
+ this.catalogLayer.setPageBackground(this.pageBackground);
752
+ this.catalogLayer.setExitOpacity(this.returnSpatialElement
753
+ ? this.catalogPresentation.enterOpacity
754
+ : this.catalogPresentation.exitOpacity, this.catalogPresentation.active);
755
+ return this.catalogLayer.setSpatialElements(brandId, items);
756
+ }
757
+ setCatalogTransitionPresentation(state) {
758
+ this.catalogPresentation = normalizeCatalogPresentation(state);
759
+ for (const entry of this.exitingMinimaps) {
760
+ this.setMinimapDisplayModelOpacity(entry.minimap, entry.opacity * state.exitOpacity);
761
+ entry.ring.material.opacity = entry.ringOpacity * state.exitOpacity;
762
+ }
763
+ if (this.presentation.readiness.acceptsClockOpacity())
764
+ this.catalogBackgroundReveal.value = this.catalogPresentation.active
765
+ ? (this.catalogPresentation.backgroundOpacity ?? this.catalogPresentation.enterOpacity)
766
+ : 1;
767
+ if (this.catalogMode === 'synchronous' && this.catalogHandoff) {
768
+ this.catalogLayer?.setHighHandoff(this.highPose, this.catalogBlend, state.geometryOpacity ?? 0, this.pagePreparation?.environment.value?.target.texture);
769
+ if (this.catalogBlend && (state.geometryOpacity ?? 0) > 0 && !this.catalogMotionComplete) {
770
+ this.presentation.markRefinement('refining', this.catalogBlend.frames);
771
+ }
772
+ }
773
+ this.catalogLayer?.setExitOpacity(this.returnSpatialElement
774
+ ? this.catalogPresentation.enterOpacity
775
+ : this.catalogPresentation.exitOpacity, this.catalogPresentation.active);
776
+ if (this.returnProjection)
777
+ this.spatialCapture?.setTarget(this.returnProjection, this.returnProgress, state.geometryOpacity ?? 0);
778
+ if (this.outgoingBackground)
779
+ this.backgroundCanvas.style.opacity = String(state.active ? state.exitOpacity : 0);
780
+ this.requestRender();
781
+ }
782
+ /** Reports actual applied GPU alpha for browser verification without layout or style reads. */
783
+ getCatalogPresentation() {
784
+ const triangles = (root) => {
785
+ let count = 0;
786
+ root?.traverse((child) => {
787
+ if (isMesh(child))
788
+ count +=
789
+ (child.geometry.index?.count ?? child.geometry.getAttribute('position')?.count ?? 0) /
790
+ 3;
791
+ });
792
+ return count;
793
+ };
794
+ return {
795
+ mode: this.catalogMode ?? null,
796
+ exitingMinimaps: this.exitingMinimaps.map(({ capture, minimap }) => ({
797
+ ...capture.getSnapshot(),
798
+ opacity: minimap.displayOpacity
799
+ })),
800
+ preparation: this.preparation?.current
801
+ ? {
802
+ background: this.preparation.current.backgroundState,
803
+ high: this.preparation.current.highState,
804
+ timings: this.preparation.current.timings,
805
+ key: this.preparation.current.key
806
+ }
807
+ : null,
808
+ channels: { ...this.catalogPresentation },
809
+ backgroundReveal: this.catalogBackgroundReveal.value,
810
+ backgroundPrepared: this.catalogBackgroundPrepared,
811
+ handoffPoint: this.getCatalogGeometryPoint(),
812
+ representations: {
813
+ retainedBlendTargets: this.returnBlend?.targetCount ?? 0,
814
+ state: this.refinementState,
815
+ hero: this.model ? (this.refinementState === 'high' ? 'high' : 'low') : null,
816
+ minimap: this.minimaps.size ? 'low' : null,
817
+ frames: this.refinementFrames,
818
+ temporaryTargets: this.refinement?.targetCount ?? 0,
819
+ heroTriangles: triangles(this.refinementState === 'high' ? this.highPose : this.assetInstance?.scene),
820
+ minimapTriangles: [...this.minimaps.values()].map((minimap) => triangles(minimap.displayModel)),
821
+ lowUrl: this.lodPair?.low.url ?? this.glb,
822
+ highUrl: this.lodPair?.high.url ?? null
823
+ },
824
+ model: {
825
+ loadedKey: this.loadedModelKey ?? null,
826
+ ready: this.pageModelReady,
827
+ handoff: this.catalogHandoff
828
+ },
829
+ panels: this.panelRuntimes.map((panel) => {
830
+ const backdrop = panel.glass?.group.children.find((child) => isMesh(child) && child.renderOrder === 3);
831
+ return {
832
+ group: panel.transitionGroup ?? null,
833
+ surface: panel.surface,
834
+ transitionOpacity: this.getPanelTransitionOpacity(panel),
835
+ glassOpacity: backdrop && isMesh(backdrop) ? (getMeshMaterials(backdrop)[0]?.opacity ?? null) : null,
836
+ visible: panel.group.visible
837
+ };
838
+ }),
839
+ minimaps: [...this.minimaps.values()].map((minimap) => ({
840
+ group: this.panelRuntimes[minimap.panelIndex]?.transitionGroup ?? null,
841
+ transitionOpacity: this.getPanelTransitionOpacity(this.panelRuntimes[minimap.panelIndex]),
842
+ modelOpacity: minimap.displayOpacity,
843
+ materialOpacities: minimap.displayMaterials.map(({ material }) => material.opacity),
844
+ ringOpacity: minimap.overlayRing.material.opacity,
845
+ compositeOpacity: minimap.overlayVisibility.value,
846
+ visible: minimap.layer.visible
847
+ }))
848
+ };
849
+ }
850
+ /** Exercises the actual WebGPU loss callback; exposed only by the opt-in test controller. */
851
+ loseDeviceForTest() {
852
+ const device = this.renderer.backend.device;
853
+ if (!device)
854
+ throw new Error('A native WebGPU device is required');
855
+ device.destroy();
856
+ }
857
+ getPanelTransitionOpacity(panel) {
858
+ return getCatalogTransitionOpacity(this.catalogPresentation, panel?.transitionGroup);
859
+ }
860
+ captureCatalogGeometry(spatialElementId) {
861
+ this.catalogMotionComplete = false;
862
+ this.catalogHandoff = this.catalogLayer?.capture(spatialElementId) ?? false;
863
+ if (this.catalogHandoff)
864
+ this.detailPreparationGate.setPaused(true);
865
+ return this.catalogHandoff;
866
+ }
867
+ /** Content-to-content motion owns only the prepared Low representation. */
868
+ captureContentGeometry(spatialElementId, secondary = []) {
869
+ if (!this.captureCatalogGeometry(spatialElementId))
870
+ return false;
871
+ if (!this.adoptCatalogPresentation({ spatialElementId, kind: 'content' }))
872
+ return false;
873
+ this.outgoingBackground = false;
874
+ for (const source of secondary.slice(0, 4)) {
875
+ if (!this.catalogLayer?.capture(source.spatialElementId, source.occurrence))
876
+ continue;
877
+ const moving = this.catalogLayer.detachHandoff();
878
+ if (!moving)
879
+ continue;
880
+ const environment = this.environments.pinTexture(moving.environment);
881
+ const capture = new SpatialGeometryCapture(moving.model, moving.projection, {
882
+ environment: moving.environment,
883
+ environmentIntensity: moving.projection.environmentIntensity,
884
+ referencePoint: moving.referencePoint,
885
+ lights: [],
886
+ release: () => {
887
+ environment?.release();
888
+ moving.release();
889
+ }
890
+ });
891
+ this.contentSecondaries.push({ source, capture });
892
+ }
893
+ return true;
894
+ }
895
+ prepareContentParticipants(pairs) {
896
+ const retained = [];
897
+ const targets = [];
898
+ const prepared = [];
899
+ for (const entry of this.contentSecondaries) {
900
+ const pair = pairs.find((p) => p.source.spatialElementId === entry.source.spatialElementId &&
901
+ p.source.occurrence === entry.source.occurrence);
902
+ const target = pair &&
903
+ this.catalogLayer?.getDestinationProjection(pair.target.spatialElementId, pair.target.occurrence);
904
+ if (!target || !pair) {
905
+ entry.capture.dispose();
906
+ continue;
907
+ }
908
+ entry.target = target;
909
+ retained.push(entry);
910
+ targets.push(pair.target);
911
+ prepared.push(pair);
912
+ }
913
+ this.contentSecondaries = retained;
914
+ this.catalogLayer?.setDestinationOccurrences(targets);
915
+ this.presentation.readiness.useSynchronousMotion();
916
+ this.preparationGate.setPaused(true);
917
+ this.requestRender();
918
+ return prepared;
919
+ }
920
+ /** Rebase matching neighbours from their submitted pose; release unmatched owners once. */
921
+ adoptContentParticipants(pairs) {
922
+ this.contentSecondaries = this.contentSecondaries.filter((entry) => {
923
+ const pair = pairs.find((pair) => pair.source.spatialElementId === entry.source.spatialElementId &&
924
+ pair.source.occurrence === entry.source.occurrence);
925
+ if (!pair) {
926
+ entry.capture.dispose();
927
+ return false;
928
+ }
929
+ entry.capture.freeze();
930
+ entry.source = pair.target;
931
+ entry.target = undefined;
932
+ return true;
933
+ });
934
+ this.catalogLayer?.setDestinationOccurrences([]);
935
+ }
936
+ promoteContentParticipant(source) {
937
+ const entry = this.contentSecondaries.find((entry) => entry.source.spatialElementId === source.spatialElementId && entry.source.occurrence === source.occurrence);
938
+ if (!entry)
939
+ return false;
940
+ this.spatialCapture?.dispose();
941
+ this.spatialCapture = entry.capture;
942
+ this.contentSecondaries = this.contentSecondaries.filter((candidate) => candidate !== entry);
943
+ this.returnSpatialElement = source.spatialElementId;
944
+ this.catalogLayer?.setDestinationSpatialElement(source.spatialElementId);
945
+ return true;
946
+ }
947
+ getCatalogGeometryPoint() {
948
+ return this.spatialCapture?.getPoint() ?? this.catalogLayer?.getHandoffPoint() ?? null;
949
+ }
950
+ /** Lease the last submitted element frame before another page binding can release it. */
951
+ adoptCatalogPresentation(destination) {
952
+ const { spatialElementId } = destination;
953
+ const reverse = destination.kind === 'content';
954
+ if (!this.spatialCapture) {
955
+ const moving = this.catalogLayer?.detachHandoff();
956
+ if (moving) {
957
+ const high = this.highInstance;
958
+ const highPose = this.highPose;
959
+ const blend = this.catalogBlend;
960
+ const transferredHigh = this.presentation.takeHigh();
961
+ const environment = this.environments.pinTexture(moving.environment);
962
+ const highEnvironment = this.environments.pinTexture(moving.highEnvironment ?? null);
963
+ const generation = this.pageBinding.token;
964
+ const parent = highPose?.parent;
965
+ if (highPose)
966
+ moving.model.add(highPose);
967
+ this.spatialCapture = new SpatialGeometryCapture(moving.model, moving.projection, {
968
+ environment: moving.environment,
969
+ highEnvironment: moving.highEnvironment,
970
+ environmentIntensity: moving.projection.environmentIntensity,
971
+ referencePoint: moving.referencePoint,
972
+ lights: [],
973
+ high: highPose,
974
+ blend,
975
+ highWeight: blend ? (this.catalogPresentation.geometryOpacity ?? 0) : 0,
976
+ release: () => {
977
+ environment?.release();
978
+ highEnvironment?.release();
979
+ if (!this.disposed && this.pageBinding.token === generation && parent && highPose) {
980
+ parent.add(highPose);
981
+ if (transferredHigh)
982
+ this.presentation.restoreHigh(transferredHigh);
983
+ for (const child of parent.children)
984
+ child.visible = child === highPose;
985
+ moving.release();
986
+ return false;
987
+ }
988
+ highPose?.removeFromParent();
989
+ transferredHigh?.overrides.forEach(disposeMaterialOnly);
990
+ high?.dispose();
991
+ moving.release();
992
+ }
993
+ });
994
+ }
995
+ else if (!(this.catalogDockTarget
996
+ ? this.captureDockPresentation(spatialElementId)
997
+ : this.captureHeroPresentation()))
998
+ return false;
999
+ }
1000
+ this.spatialCapture.freeze();
1001
+ this.returnProjection = undefined;
1002
+ this.returnSpatialElement = reverse ? spatialElementId : undefined;
1003
+ this.adoptedForward = !reverse;
1004
+ this.catalogLayer?.setDestinationSpatialElement(reverse ? spatialElementId : undefined);
1005
+ this.catalogMotionComplete = false;
1006
+ this.catalogHandoff = true;
1007
+ this.detailPreparationGate.setPaused(true);
1008
+ // Required Low binding must remain possible while the successor resolves.
1009
+ this.preparationGate.setPaused(false);
1010
+ if (reverse) {
1011
+ this.captureExitingMinimaps();
1012
+ if (this.pipeline.freezeBackground())
1013
+ this.outgoingBackground = true;
1014
+ }
1015
+ else
1016
+ this.outgoingBackground = false;
1017
+ return true;
1018
+ }
1019
+ /** Transfer already prepared hero resources before releasePage/cancelHighRequest can dispose them. */
1020
+ captureHeroPresentation() {
1021
+ if (!this.model || !this.pageModelReady || !this.stageViewportVisible || this.spatialCapture)
1022
+ return false;
1023
+ const highWeight = this.refinementState === 'high' ? 1 : (this.refinement?.presentedProgress ?? 0);
1024
+ const blend = this.returnBlend ?? this.catalogBlend ?? this.refinement;
1025
+ if (highWeight > 0 && !blend)
1026
+ return false;
1027
+ const model = this.model;
1028
+ const projection = captureSpatialElementProjection(model, this.camera);
1029
+ const transfer = this.presentation.takeHero();
1030
+ const highPose = transfer.high?.pose;
1031
+ const environment = this.environments.pinTexture(this.scene.environment);
1032
+ const generation = this.pageBinding.token;
1033
+ this.pageModelReady = false;
1034
+ this.spatialCapture = new SpatialGeometryCapture(model, projection, {
1035
+ environment: this.scene.environment,
1036
+ environmentIntensity: this.scene.environmentIntensity,
1037
+ lights: this.scene.children.filter((child) => child instanceof THREE.Light),
1038
+ high: highPose,
1039
+ highWeight,
1040
+ blend,
1041
+ release: () => {
1042
+ environment?.release();
1043
+ if (!this.disposed && this.pageBinding.token === generation && !this.model) {
1044
+ // Cancellation before page release restores ownership to the still-live DETAIL.
1045
+ model.matrixAutoUpdate = true;
1046
+ this.presentation.restoreHero(transfer);
1047
+ this.scene.add(model);
1048
+ this.pageModelReady = true;
1049
+ return false;
1050
+ }
1051
+ else {
1052
+ this.presentation.disposeTransfer(transfer);
1053
+ }
1054
+ }
1055
+ });
1056
+ this.requestRender();
1057
+ return true;
1058
+ }
1059
+ getSpatialCapture() {
1060
+ return this.spatialCapture
1061
+ ? {
1062
+ ...this.spatialCapture.getSnapshot(),
1063
+ secondary: this.contentSecondaries.map((entry) => ({
1064
+ spatialElementId: entry.source.spatialElementId,
1065
+ occurrence: entry.source.occurrence,
1066
+ ...entry.capture.getSnapshot()
1067
+ }))
1068
+ }
1069
+ : null;
1070
+ }
1071
+ captureReturnGeometry(spatialElementId) {
1072
+ if (!this.captureHeroPresentation())
1073
+ return false;
1074
+ this.captureExitingMinimaps();
1075
+ this.returnSpatialElement = spatialElementId;
1076
+ this.returnProgress = 0;
1077
+ this.catalogLayer?.setDestinationSpatialElement(spatialElementId);
1078
+ // Freeze the existing background canvas without the independently retained hero.
1079
+ if (this.pipeline.freezeBackground())
1080
+ this.outgoingBackground = true;
1081
+ return true;
1082
+ }
1083
+ getDockProjection() {
1084
+ const candidates = [...this.minimaps.values()].filter((minimap) => minimap.viewportVisible);
1085
+ if (candidates.length !== 1)
1086
+ return;
1087
+ const minimap = candidates[0];
1088
+ const rect = this.getProjectedMinimapModelRect(minimap);
1089
+ if (!rect ||
1090
+ rect.x < 0 ||
1091
+ rect.y < 0 ||
1092
+ rect.x + rect.width > innerWidth ||
1093
+ rect.y + rect.height > innerHeight)
1094
+ return;
1095
+ return {
1096
+ ...captureSpatialElementProjection(minimap.spatialElementRoot, minimap.screenCamera),
1097
+ environmentIntensity: this.minimapScene.environmentIntensity
1098
+ };
1099
+ }
1100
+ captureDockPresentation(spatialElementId) {
1101
+ if (this.spatialCapture || !this.assetInstance)
1102
+ return false;
1103
+ const candidates = [...this.minimaps.values()].filter((minimap) => minimap.viewportVisible);
1104
+ if (candidates.length !== 1)
1105
+ return false;
1106
+ const minimap = candidates[0];
1107
+ const projection = this.getDockProjection();
1108
+ if (!projection || minimap.displayOpacity < 0.999 || minimap.overlayProgress > 0.001)
1109
+ return false;
1110
+ const model = minimap.spatialElementRoot;
1111
+ const parent = model.parent;
1112
+ const low = this.assetInstance;
1113
+ const generation = this.pageBinding.token;
1114
+ const environment = this.environments.pinTexture(this.minimapScene.environment);
1115
+ this.presentation.takeLowInstance();
1116
+ this.spatialCapture = new SpatialGeometryCapture(model, projection, {
1117
+ environment: this.minimapScene.environment,
1118
+ environmentIntensity: this.minimapScene.environmentIntensity,
1119
+ lights: this.minimapScene.children.filter((child) => child instanceof THREE.Light),
1120
+ release: () => {
1121
+ environment?.release();
1122
+ if (!this.disposed && this.pageBinding.token === generation) {
1123
+ this.presentation.restoreLowInstance(low);
1124
+ model.matrixAutoUpdate = true;
1125
+ model.updateMatrix();
1126
+ parent.add(model);
1127
+ }
1128
+ else {
1129
+ disposeMinimapModelMaterials(model);
1130
+ low.dispose();
1131
+ }
1132
+ }
1133
+ });
1134
+ this.returnSpatialElement = spatialElementId;
1135
+ this.returnProgress = 0;
1136
+ this.catalogLayer?.setDestinationSpatialElement(spatialElementId);
1137
+ this.requestRender();
1138
+ return true;
1139
+ }
1140
+ prepareCatalogDestination(dock) {
1141
+ this.catalogDockTarget = dock;
1142
+ if (this.adoptedForward) {
1143
+ this.returnProjection = dock
1144
+ ? this.getDockProjection()
1145
+ : this.model
1146
+ ? {
1147
+ ...captureSpatialElementProjection(this.model, this.camera),
1148
+ environmentIntensity: this.scene.environmentIntensity
1149
+ }
1150
+ : undefined;
1151
+ return Boolean(this.returnProjection);
1152
+ }
1153
+ return !dock || Boolean(this.getDockProjection());
1154
+ }
1155
+ prepareReturnDestination() {
1156
+ if (!this.returnSpatialElement || !this.spatialCapture)
1157
+ return false;
1158
+ // Lay out the suppressed matching actor before freezing its destination projection.
1159
+ this.catalogLayer?.setExitOpacity(1, true);
1160
+ this.flushCatalogFrame();
1161
+ this.returnProjection = this.catalogLayer?.getDestinationProjection(this.returnSpatialElement);
1162
+ this.catalogLayer?.setExitOpacity(this.catalogPresentation.enterOpacity, true);
1163
+ return Boolean(this.returnProjection);
1164
+ }
1165
+ /** Retain unshared rail geometry until its exit fade completes, independently of the page. */
1166
+ captureExitingMinimaps() {
1167
+ if (this.exitingMinimaps.length) {
1168
+ for (const entry of this.exitingMinimaps) {
1169
+ entry.opacity = entry.minimap.displayOpacity;
1170
+ entry.ringOpacity = entry.ring.material.opacity;
1171
+ }
1172
+ return;
1173
+ }
1174
+ for (const minimap of this.minimaps.values()) {
1175
+ const model = minimap.spatialElementRoot;
1176
+ if (!minimap.viewportVisible ||
1177
+ minimap.displayOpacity <= 0 ||
1178
+ model === this.spatialCapture?.model)
1179
+ continue;
1180
+ const parent = model.parent;
1181
+ if (!parent)
1182
+ continue;
1183
+ const projection = captureSpatialElementProjection(model, minimap.screenCamera);
1184
+ const ring = minimap.overlayRing.clone();
1185
+ ring.geometry = minimap.overlayRing.geometry.clone();
1186
+ ring.material = minimap.overlayRing.material.clone();
1187
+ minimap.overlayRing.updateWorldMatrix(true, false);
1188
+ ring.matrixAutoUpdate = false;
1189
+ ring.matrix.copy(projection.model).invert().multiply(minimap.overlayRing.matrixWorld);
1190
+ const ringOpacity = ring.material.opacity;
1191
+ const environment = this.environments.pinTexture(this.minimapScene.environment);
1192
+ const lease = this.assets.acquire(this.lodPair?.low ?? {
1193
+ url: this.glb,
1194
+ format: 'glb',
1195
+ revision: 'legacy-unversioned',
1196
+ requirements: { decoders: ['draco'], extensions: [] }
1197
+ });
1198
+ const generation = this.pageBinding.token;
1199
+ const opacity = minimap.displayOpacity;
1200
+ const capture = new SpatialGeometryCapture(model, projection, {
1201
+ environment: this.minimapScene.environment,
1202
+ environmentIntensity: this.minimapScene.environmentIntensity,
1203
+ lights: this.minimapScene.children.filter((child) => child instanceof THREE.Light),
1204
+ release: () => {
1205
+ ring.removeFromParent();
1206
+ ring.geometry.dispose();
1207
+ ring.material.dispose();
1208
+ if (!this.disposed && generation === this.pageBinding.token) {
1209
+ model.matrixAutoUpdate = true;
1210
+ model.updateMatrix();
1211
+ parent.add(model);
1212
+ this.setMinimapDisplayModelOpacity(minimap, opacity);
1213
+ }
1214
+ else
1215
+ disposeMinimapModelMaterials(model);
1216
+ environment?.release();
1217
+ lease.release();
1218
+ }
1219
+ });
1220
+ model.add(ring);
1221
+ this.exitingMinimaps.push({ capture, minimap, opacity, ring, ringOpacity });
1222
+ }
1223
+ }
1224
+ releaseSpatialCapture() {
1225
+ for (const entry of this.contentSecondaries)
1226
+ entry.capture.dispose();
1227
+ this.contentSecondaries = [];
1228
+ this.catalogLayer?.setDestinationOccurrences([]);
1229
+ for (const entry of this.exitingMinimaps)
1230
+ entry.capture.dispose();
1231
+ this.exitingMinimaps = [];
1232
+ const capture = this.spatialCapture;
1233
+ this.spatialCapture = undefined;
1234
+ capture?.dispose();
1235
+ this.requestRender();
1236
+ }
1237
+ setCatalogGeometryProgress(progress) {
1238
+ for (const entry of this.contentSecondaries)
1239
+ if (entry.target)
1240
+ entry.capture.setTarget(entry.target, progress, 0);
1241
+ if (this.returnProjection && this.spatialCapture) {
1242
+ this.returnProgress = progress;
1243
+ this.spatialCapture.setTarget(this.returnProjection, progress, this.adoptedForward ? progress : (this.catalogPresentation.geometryOpacity ?? 0));
1244
+ if (this.adoptedForward && progress >= 1) {
1245
+ this.catalogMotionComplete = true;
1246
+ this.releaseSpatialCapture();
1247
+ this.returnProjection = undefined;
1248
+ }
1249
+ this.requestRender();
1250
+ return;
1251
+ }
1252
+ if (!this.catalogHandoff || !this.model)
1253
+ return;
1254
+ const dock = this.catalogDockTarget
1255
+ ? [...this.minimaps.values()].find((minimap) => minimap.viewportVisible)
1256
+ : undefined;
1257
+ this.catalogLayer?.setHandoffTarget({
1258
+ camera: dock?.screenCamera ?? this.camera,
1259
+ model: dock?.spatialElementRoot ?? this.model,
1260
+ environmentIntensity: dock
1261
+ ? this.minimapScene.environmentIntensity
1262
+ : this.scene.environmentIntensity,
1263
+ progress
1264
+ });
1265
+ const previouslyComplete = this.catalogMotionComplete;
1266
+ this.catalogMotionComplete = progress >= 1;
1267
+ // Submit the first final-pose frame before releasing deferred preparation work.
1268
+ if (this.catalogMotionComplete && !previouslyComplete) {
1269
+ this.catalogLayer?.finishHandoff();
1270
+ if (this.catalogMode === 'synchronous' && this.highPose) {
1271
+ for (const child of this.model.children)
1272
+ child.visible = child === this.highPose;
1273
+ this.presentation.markRefinement('high', this.catalogBlend?.frames ?? 0);
1274
+ }
1275
+ if (this.catalogMode === 'synchronous')
1276
+ this.presentation.readiness.completeMotion();
1277
+ }
1278
+ if (previouslyComplete) {
1279
+ this.preparationGate.setPaused(false);
1280
+ this.detailPreparationGate.setPaused(false);
1281
+ this.startHighRequest();
1282
+ }
1283
+ this.requestRender();
1284
+ }
1285
+ /** Commit GPU and DOM motion in the same browser frame, not on consecutive RAFs. */
1286
+ flushCatalogFrame() {
1287
+ cancelAnimationFrame(this.renderRequestId);
1288
+ this.renderRequestId = 0;
1289
+ this.renderFrame(true);
1290
+ // After the transition's external clock stops, optional refinement resumes its own RAF.
1291
+ if (!this.catalogPresentation.active && (this.animationActive || this.renderInvalidated))
1292
+ this.scheduleRender();
1293
+ }
1294
+ finishCatalogGeometry() {
1295
+ this.releaseSpatialCapture();
1296
+ this.adoptedForward = false;
1297
+ this.returnSpatialElement = undefined;
1298
+ this.catalogDockTarget = false;
1299
+ this.returnProjection = undefined;
1300
+ this.catalogLayer?.setDestinationSpatialElement();
1301
+ this.outgoingBackground = false;
1302
+ this.backgroundCanvas.style.removeProperty('opacity');
1303
+ this.preparationGate.setPaused(false);
1304
+ this.detailPreparationGate.setPaused(false);
1305
+ if (this.catalogMode === 'synchronous') {
1306
+ this.presentation.readiness.completeMotion();
1307
+ }
1308
+ this.catalogHandoff = false;
1309
+ this.catalogMotionComplete = false;
1310
+ this.catalogLayer?.finishHandoff();
1311
+ this.presentation.finishHandoff(this.catalogMode === 'synchronous');
1312
+ if (!this.disposed && this.highPose && this.model && this.refinementState === 'high') {
1313
+ this.collectModelPickTargets(this.highPose);
1314
+ const outline = this.model.clone(false);
1315
+ outline.add(this.highPose.clone(true));
1316
+ this.pipeline.createModelOutline(outline);
1317
+ }
1318
+ if (this.pageModelReady && !this.disposed)
1319
+ this.startHighRequest();
1320
+ this.requestRender();
1321
+ }
1322
+ releaseModel() {
1323
+ this.presentation.release();
1324
+ this.pipeline.releaseOutline();
1325
+ this.interaction.setPickTargets(undefined, () => false);
1326
+ }
1327
+ /** Smoothly restores the initial fitted camera position and orbit target. */
1328
+ resetView() {
1329
+ return this.interaction.resetView();
1330
+ }
1331
+ /** @deprecated Use {@link resetView} to restore the complete fitted pose. */
1332
+ resetZoom() {
1333
+ this.resetView();
1334
+ }
1335
+ /**
1336
+ * Applies an exact camera pose for screenshot tests.
1337
+ *
1338
+ * This bypasses OrbitControls damping so a visual test can capture a known
1339
+ * state. It is only called by the query-gated
1340
+ * test controller installed by the Svelte stage component.
1341
+ *
1342
+ * @param view - Normalized zoom, orbit offsets, and optional target translation.
1343
+ */
1344
+ setVisualTestView(view = {}) {
1345
+ if (!this.controls || !this.initialViewCaptured) {
1346
+ throw new Error('The stage camera is not ready for visual testing');
1347
+ }
1348
+ this.clearZoomReset();
1349
+ this.clearWheelZoom();
1350
+ this.interaction.stopViewReset();
1351
+ const targetOffset = view.targetOffset ?? {};
1352
+ const target = this.initialControlsTarget
1353
+ .clone()
1354
+ .add(new THREE.Vector3((targetOffset.x ?? 0) * this.modelRadius, (targetOffset.y ?? 0) * this.modelRadius, (targetOffset.z ?? 0) * this.modelRadius));
1355
+ const spherical = new THREE.Spherical().setFromVector3(this.initialCameraPosition.clone().sub(this.initialControlsTarget));
1356
+ spherical.theta += THREE.MathUtils.degToRad(view.azimuth ?? 0);
1357
+ spherical.phi = THREE.MathUtils.clamp(spherical.phi + THREE.MathUtils.degToRad(view.polar ?? 0), 0.05, Math.PI - 0.05);
1358
+ const zoom = THREE.MathUtils.clamp(view.zoom ?? 0, 0, 1);
1359
+ const distance = THREE.MathUtils.lerp(this.controls.maxDistance, this.controls.minDistance, zoom);
1360
+ const cameraOffset = new THREE.Vector3().setFromSpherical(spherical).setLength(distance);
1361
+ this.controls.target.copy(target);
1362
+ this.camera.fov = this.initialCameraFov;
1363
+ this.camera.position.copy(target).add(cameraOffset);
1364
+ this.camera.updateProjectionMatrix();
1365
+ this.camera.updateMatrixWorld(true);
1366
+ this.controls.update();
1367
+ this.panelFocus = this.getZoomFocusFactor();
1368
+ this.panelUiFocus = getStageUiFocus(this.panelFocus);
1369
+ this.minimapFocus = getSequencedMinimapFocus(this.panelFocus, this.panelUiFocus);
1370
+ this.layoutDirty = true;
1371
+ this.lastInteractionTime = performance.now();
1372
+ this.requestRender();
1373
+ }
1374
+ /** Applies the camera/target dolly produced by a real SpaceMouse zoom transaction. */
1375
+ setVisualTestSpaceMouseZoom(zoom = 0) {
1376
+ if (!this.controls || !this.initialViewCaptured) {
1377
+ throw new Error('The stage camera is not ready for visual testing');
1378
+ }
1379
+ const normalizedZoom = THREE.MathUtils.clamp(zoom, 0, 1);
1380
+ const spatialElementDistance = THREE.MathUtils.lerp(this.controls.maxDistance, this.controls.minDistance, normalizedZoom);
1381
+ const nextPosition = this.camera.position
1382
+ .clone()
1383
+ .sub(this.initialControlsTarget)
1384
+ .setLength(spatialElementDistance)
1385
+ .add(this.initialControlsTarget);
1386
+ const translation = nextPosition.clone().sub(this.camera.position);
1387
+ const nextTarget = this.controls.target.clone().add(translation);
1388
+ const rotation = new THREE.Quaternion().setFromRotationMatrix(new THREE.Matrix4().lookAt(nextPosition, nextTarget, this.camera.up));
1389
+ const viewMatrix = new THREE.Matrix4().compose(nextPosition, rotation, new THREE.Vector3(1, 1, 1));
1390
+ this.applySpaceMouseNavigationUpdate({
1391
+ viewMatrix: viewMatrix.elements,
1392
+ target: nextTarget.toArray(),
1393
+ fov: THREE.MathUtils.degToRad(this.initialCameraFov)
1394
+ });
1395
+ }
1396
+ /** Repeats SpaceMouse navigation transactions while synthetic frames are rendered. */
1397
+ driveVisualTestSpaceMouseZoom(zoom = 0, frames = 60) {
1398
+ const frameCount = THREE.MathUtils.clamp(Math.floor(frames), 1, 120);
1399
+ this.setSpaceMouseMoving(true);
1400
+ for (let index = 0; index < frameCount; index += 1) {
1401
+ this.setVisualTestSpaceMouseZoom(zoom);
1402
+ this.advanceVisualTestFrames(1);
1403
+ }
1404
+ }
1405
+ /** Ends the synthetic SpaceMouse gesture used by browser regression tests. */
1406
+ stopVisualTestSpaceMouseMotion() {
1407
+ this.setSpaceMouseMoving(false);
1408
+ }
1409
+ /** Returns the live rendered minimap bounds rather than its hidden DOM fallback bounds. */
1410
+ getVisualTestMinimapRect() {
1411
+ const minimap = this.minimaps.values().next().value;
1412
+ if (!minimap)
1413
+ return null;
1414
+ minimap.layer.updateWorldMatrix(true, true);
1415
+ minimap.screenCamera.updateMatrixWorld(true);
1416
+ const halfWidth = minimap.currentWidth * 0.5;
1417
+ const halfHeight = minimap.currentHeight * 0.5;
1418
+ const viewportWidth = Math.max(window.innerWidth, 1);
1419
+ const viewportHeight = Math.max(window.innerHeight, 1);
1420
+ const projected = [
1421
+ new THREE.Vector3(-halfWidth, -halfHeight, 0),
1422
+ new THREE.Vector3(halfWidth, -halfHeight, 0),
1423
+ new THREE.Vector3(halfWidth, halfHeight, 0),
1424
+ new THREE.Vector3(-halfWidth, halfHeight, 0)
1425
+ ].map((corner) => minimap.layer.localToWorld(corner).project(minimap.screenCamera));
1426
+ const xCoordinates = projected.map((point) => (point.x + 1) * viewportWidth * 0.5);
1427
+ const yCoordinates = projected.map((point) => (1 - point.y) * viewportHeight * 0.5);
1428
+ const left = Math.min(...xCoordinates);
1429
+ const top = Math.min(...yCoordinates);
1430
+ return {
1431
+ x: left,
1432
+ y: top,
1433
+ width: Math.max(...xCoordinates) - left,
1434
+ height: Math.max(...yCoordinates) - top
1435
+ };
1436
+ }
1437
+ /** Returns the main element's projected bounds for query-gated layout regressions. */
1438
+ getVisualTestModelRect() {
1439
+ if (!this.model || this.modelBounds.isEmpty())
1440
+ return null;
1441
+ this.camera.updateMatrixWorld(true);
1442
+ const points = getBoxCorners(this.modelBounds).map((point) => point.project(this.camera));
1443
+ const xCoordinates = points.map((point) => (point.x + 1) * window.innerWidth * 0.5);
1444
+ const yCoordinates = points.map((point) => (1 - point.y) * window.innerHeight * 0.5);
1445
+ const left = Math.min(...xCoordinates);
1446
+ const top = Math.min(...yCoordinates);
1447
+ return {
1448
+ x: left,
1449
+ y: top,
1450
+ width: Math.max(...xCoordinates) - left,
1451
+ height: Math.max(...yCoordinates) - top
1452
+ };
1453
+ }
1454
+ /** Returns the projected element bounds used by the dock's header-top anchor. */
1455
+ getVisualTestMinimapModelRect() {
1456
+ const minimap = this.minimaps.values().next().value;
1457
+ return minimap ? this.getProjectedMinimapModelRect(minimap) : null;
1458
+ }
1459
+ /** Returns minimap orientation endpoints for query-gated browser regressions. */
1460
+ getVisualTestMinimapOrientation() {
1461
+ const minimap = this.minimaps.values().next().value;
1462
+ if (!minimap || !this.model)
1463
+ return null;
1464
+ const cameraWorldQuaternion = this.camera.getWorldQuaternion(new THREE.Quaternion());
1465
+ const modelWorldQuaternion = this.model.getWorldQuaternion(new THREE.Quaternion());
1466
+ const liveQuaternion = cameraWorldQuaternion.invert().multiply(modelWorldQuaternion);
1467
+ const serialize = (quaternion) => [
1468
+ quaternion.x,
1469
+ quaternion.y,
1470
+ quaternion.z,
1471
+ quaternion.w
1472
+ ];
1473
+ return {
1474
+ rest: serialize(minimap.restQuaternion),
1475
+ display: serialize(minimap.displayModel.quaternion),
1476
+ live: serialize(liveQuaternion),
1477
+ docked: minimap.dockedQuaternion ? serialize(minimap.dockedQuaternion) : null,
1478
+ dockProgress: THREE.MathUtils.clamp(this.panelTargets[minimap.panelIndex]?.getMinimapDockProgress?.() ?? 0, 0, 1)
1479
+ };
1480
+ }
1481
+ /** Returns overlay capture submissions for query-gated performance regression tests. */
1482
+ getVisualTestMinimapRenderStats() {
1483
+ const minimap = this.minimaps.values().next().value;
1484
+ return {
1485
+ overlayCapturePasses: this.pipeline.minimapOverlayCapturePasses,
1486
+ depthNear: minimap?.screenCamera.near ?? 0,
1487
+ depthFar: minimap?.screenCamera.far ?? 0,
1488
+ viewportRingInForeground: minimap ? !minimap.overlayRing.material.depthTest : false
1489
+ };
1490
+ }
1491
+ /** Returns Low-band and glass-compositor counters without scheduling rendering. */
1492
+ getCarouselStats() {
1493
+ return this.catalogLayer?.getStats() ?? null;
1494
+ }
1495
+ /** Returns render-target lifecycle counters for query-gated performance tests. */
1496
+ getVisualTestRenderTargetStats() {
1497
+ // Captured minimaps retain only their spatialElement/ring, not disposed page-local blur targets.
1498
+ const views = [...this.minimaps.values()];
1499
+ const inventory = describeRenderTargets({
1500
+ pipeline: this.pipeline.getRenderTargets(),
1501
+ minimap: views.flatMap((view) => [
1502
+ view.contextTarget,
1503
+ view.displayTarget,
1504
+ view.panelTarget,
1505
+ ...view.blurPipeline.getRenderTargets()
1506
+ ]),
1507
+ catalog: this.catalogLayer?.getRenderTargets() ?? [],
1508
+ presentation: this.presentation.getRenderTargets(),
1509
+ preparation: this.preparation?.current?.high?.blend.getRenderTargets() ?? [],
1510
+ capture: [
1511
+ this.spatialCapture,
1512
+ ...this.contentSecondaries.map((entry) => entry.capture),
1513
+ ...this.exitingMinimaps.map((entry) => entry.capture)
1514
+ ].flatMap((capture) => capture?.getRenderTargets() ?? []),
1515
+ environment: this.environments?.getRenderTargets() ?? []
1516
+ });
1517
+ return {
1518
+ ...inventory,
1519
+ canvases: this.pipeline.getCanvasOutputs(),
1520
+ creations: this.pipeline.renderTargetSetCreations,
1521
+ resizes: this.pipeline.renderTargetSetResizes,
1522
+ warmups: this.pipeline.renderTargetSetWarmups,
1523
+ activeScale: this.pipeline.activeRenderTargets?.scale ?? 0
1524
+ };
1525
+ }
1526
+ /** Returns live visibility and submitted-pass counters for culling regressions. */
1527
+ getVisualTestVisibilityStats() {
1528
+ return {
1529
+ stageViewportVisible: this.stageViewportVisible,
1530
+ visiblePanels: this.visiblePanelCount,
1531
+ visibleMinimaps: this.visibleMinimapCount,
1532
+ stageModelRenderPasses: this.pipeline.stageModelRenderPasses,
1533
+ panelBlurRenderPasses: this.pipeline.panelBlurRenderPasses,
1534
+ panelSceneRenderPasses: this.pipeline.panelSceneRenderPasses,
1535
+ minimapSceneRenderPasses: this.pipeline.minimapSceneRenderPasses
1536
+ };
1537
+ }
1538
+ /**
1539
+ * Advances the complete stage by a fixed number of synthetic 60 Hz frames.
1540
+ *
1541
+ * Headless browsers can throttle `requestAnimationFrame` even while WebGPU is
1542
+ * active. Visual regression tests use this method to settle damping, panel
1543
+ * layout, minimap composition, and GPU submissions without relying on wall
1544
+ * clock timing. The method is only reachable through the query-gated visual
1545
+ * test controller installed by {@link Stage}.
1546
+ *
1547
+ * @param frames - Number of frames to advance, clamped to a practical limit.
1548
+ */
1549
+ advanceVisualTestFrames(frames = 12) {
1550
+ const frameCount = THREE.MathUtils.clamp(Math.floor(frames), 1, 120);
1551
+ for (let index = 0; index < frameCount; index += 1) {
1552
+ this.lastInteractionTime = performance.now() - 1000 / 60;
1553
+ this.renderFrame(true);
1554
+ }
1555
+ }
1556
+ /**
1557
+ * Attaches accessible HTML content to an imperative panel.
1558
+ *
1559
+ * @param element - DOM subtree rendered by the CSS3D layer.
1560
+ * @param panelIndex - Index of the panel that owns the content.
1561
+ * @param inset - Padding, in panel-local pixels, around the content.
1562
+ * @returns The CSS3D object that tracks the panel.
1563
+ */
1564
+ attachPanelContent(element, panelIndex = 0, inset = 28) {
1565
+ return this.panels.attachPanelContent(element, panelIndex, inset);
1566
+ }
1567
+ /** Attaches a complete CSS surface and its content to the shared panel transform. */
1568
+ attachPanelSurface(element, panelIndex, minimap = false) {
1569
+ return this.panels.attachPanelSurface(element, panelIndex, minimap);
1570
+ }
1571
+ updateContentElement(element, runtime, inset = 28) {
1572
+ return this.panels.updateContentElement(element, runtime, inset);
1573
+ }
1574
+ updateSurfaceElement(element, runtime, width = runtime.options.width, height = runtime.options.height, projected = false) {
1575
+ return this.panels.updateSurfaceElement(element, runtime, width, height, projected);
1576
+ }
1577
+ /** Marks the scene as dirty and schedules a browser frame if none is pending. */
1578
+ requestRender() {
1579
+ if (this.disposed)
1580
+ return;
1581
+ this.renderInvalidated = true;
1582
+ this.scheduleRender();
1583
+ }
1584
+ scheduleRender() {
1585
+ if (this.disposed || document.hidden || this.renderRequestId)
1586
+ return;
1587
+ this.renderRequestId = requestAnimationFrame(this.render);
1588
+ }
1589
+ configureCssRenderer() {
1590
+ const element = this.cssRenderer.domElement;
1591
+ element.className = 'stage-css3d';
1592
+ element.style.position = 'fixed';
1593
+ element.style.inset = '0';
1594
+ element.style.width = '100vw';
1595
+ element.style.height = '100vh';
1596
+ element.style.overflow = 'hidden';
1597
+ element.style.pointerEvents = 'none';
1598
+ }
1599
+ configureFlatPanelLayer() {
1600
+ const element = this.flatPanelLayer;
1601
+ element.className = 'stage-css3d-flat';
1602
+ element.style.position = 'fixed';
1603
+ element.style.inset = '0';
1604
+ element.style.width = '100vw';
1605
+ element.style.height = '100vh';
1606
+ element.style.perspectiveOrigin = '50% 50%';
1607
+ element.style.transformStyle = 'flat';
1608
+ element.style.pointerEvents = 'none';
1609
+ }
1610
+ configureNativePanelLayer() {
1611
+ const element = this.nativePanelLayer;
1612
+ element.className = 'stage-panel-native';
1613
+ element.style.position = 'fixed';
1614
+ element.style.inset = '0';
1615
+ element.style.width = '100vw';
1616
+ element.style.height = '100vh';
1617
+ element.style.perspective = 'none';
1618
+ element.style.transformStyle = 'flat';
1619
+ element.style.pointerEvents = 'none';
1620
+ }
1621
+ async loadEnvironment() {
1622
+ const token = this.pageBinding.token;
1623
+ const lease = this.environments.acquire(this.hdr);
1624
+ try {
1625
+ const environment = await lease.ready;
1626
+ if (this.disposed || !this.pageBinding.isCurrent(token))
1627
+ return;
1628
+ this.applyEnvironment(environment);
1629
+ }
1630
+ finally {
1631
+ lease.release();
1632
+ }
1633
+ }
1634
+ applyEnvironment(environment) {
1635
+ this.presentation.retainEnvironment(this.environments, environment);
1636
+ this.environmentTarget = environment.target;
1637
+ const texture = environment.target.texture;
1638
+ this.backgroundScene.background =
1639
+ this.backgroundSettings.blurriness <= 0 ? environment.source : texture;
1640
+ this.backgroundScene.backgroundBlurriness = this.backgroundSettings.blurriness;
1641
+ this.backgroundScene.backgroundIntensity = 1;
1642
+ this.scene.environment = texture;
1643
+ this.scene.environmentIntensity = 0.5;
1644
+ this.panelScene.environment = this.minimapScene.environment = texture;
1645
+ this.panelScene.environmentIntensity = this.minimapScene.environmentIntensity = 1;
1646
+ for (const minimap of this.minimaps.values())
1647
+ minimap.sourceScene.environment = texture;
1648
+ if (this.tintMaterial) {
1649
+ this.tintMaterial.color.set(this.backgroundSettings.tint);
1650
+ this.tintMaterial.opacity = this.backgroundSettings.tintIntensity;
1651
+ }
1652
+ this.presentation.readiness.markApplied();
1653
+ }
1654
+ prefetchSpatialElement(stage) {
1655
+ if (!this.disposed && this.preparation && !this.catalogHandoff)
1656
+ this.preparation.prepare(stage);
1657
+ }
1658
+ isCatalogBackgroundPrepared() {
1659
+ return this.catalogBackgroundPrepared;
1660
+ }
1661
+ /** Freeze readiness only after Kit has supplied and bound the complete destination DOM. */
1662
+ beginCatalogMotion() {
1663
+ if (this.catalogDockTarget) {
1664
+ this.preparationGate.setPaused(true);
1665
+ this.presentation.readiness.useSynchronousMotion();
1666
+ return 'synchronous';
1667
+ }
1668
+ const entry = this.pagePreparation;
1669
+ const ready = this.presentation.readiness.freeze(false, this.adoptedForward) === 'synchronous';
1670
+ this.catalogBackgroundReveal.value = 0;
1671
+ if (this.catalogBackgroundPrepared && entry) {
1672
+ const lowEnvironment = this.scene.environment;
1673
+ this.applyEnvironment(entry.environment.value);
1674
+ if (!ready && this.lodPair)
1675
+ this.scene.environment = lowEnvironment;
1676
+ }
1677
+ if (ready)
1678
+ this.adoptPreparedHigh(true);
1679
+ this.preparationGate.setPaused(true);
1680
+ return ready ? 'synchronous' : 'asynchronous';
1681
+ }
1682
+ async warmPreparedHigh(high, environment, signal) {
1683
+ return this.detailPreparationGate.run(() => this.preparationGate.run(async () => {
1684
+ if (this.disposed)
1685
+ throw new Error('Stage disposed');
1686
+ await this.pipeline.warmHigh(high, environment.target.texture, () => this.catalogLayer?.renderForPreparation(this.renderer));
1687
+ }, signal), signal);
1688
+ }
1689
+ adoptPreparedHigh(moving = false) {
1690
+ const entry = this.pagePreparation;
1691
+ if (!entry || !this.model || this.highInstance)
1692
+ return;
1693
+ if (entry.highState === 'failed' || entry.highState === 'loading') {
1694
+ this.presentation.markRefinement(entry.highState);
1695
+ return;
1696
+ }
1697
+ const high = this.preparation.takeHigh(entry);
1698
+ if (high)
1699
+ this.presentation.adoptHigh(high, moving);
1700
+ }
1701
+ advancePreparedPage(now) {
1702
+ if (this.deferDetailPreparation) {
1703
+ const rect = this.pageBinding.viewportRect
1704
+ ? this.resolveStageRect(this.pageBinding.viewportRect)
1705
+ : undefined;
1706
+ if (this.catalogPresentation.active ||
1707
+ !this.stageViewportVisible ||
1708
+ !this.heroIsPresented() ||
1709
+ !this.viewportTarget ||
1710
+ !rect ||
1711
+ rect.bottom <= 0 ||
1712
+ rect.top >= innerHeight)
1713
+ return;
1714
+ this.presentation.readiness.resume(this.preparation.prepare({
1715
+ hdr: this.hdr,
1716
+ background: this.backgroundSettings,
1717
+ glb: this.glb,
1718
+ lodPair: this.lodPair,
1719
+ model: this.modelSettings
1720
+ }));
1721
+ }
1722
+ if (!this.pageModelReady || (this.catalogHandoff && !this.catalogMotionComplete))
1723
+ return;
1724
+ if (this.pagePreparation && this.catalogMode !== 'synchronous')
1725
+ this.adoptPreparedHigh();
1726
+ if (!this.backgroundPending && this.catalogMode)
1727
+ return;
1728
+ const entry = this.pagePreparation;
1729
+ if (!entry || entry.backgroundState === 'loading')
1730
+ return;
1731
+ if (!this.backgroundApplied && entry.environment.value) {
1732
+ const lowEnvironment = this.scene.environment;
1733
+ this.applyEnvironment(entry.environment.value);
1734
+ if (this.lodPair && this.refinementState !== 'high')
1735
+ this.scene.environment = lowEnvironment;
1736
+ }
1737
+ const reveal = this.presentation.readiness.advance(now, matchMedia('(prefers-reduced-motion: reduce)').matches);
1738
+ if (reveal !== undefined)
1739
+ this.catalogBackgroundReveal.value = reveal;
1740
+ }
1741
+ createBackgroundTint() {
1742
+ this.tintMaterial = new THREE.MeshBasicMaterial({
1743
+ color: this.backgroundSettings.tint,
1744
+ depthTest: false,
1745
+ depthWrite: false,
1746
+ opacity: this.backgroundSettings.tintIntensity,
1747
+ transparent: true
1748
+ });
1749
+ this.tintMaterial.toneMapped = false;
1750
+ this.tintGeometry = new THREE.PlaneGeometry(2, 2);
1751
+ const tintOverlay = new THREE.Mesh(this.tintGeometry, this.tintMaterial);
1752
+ tintOverlay.position.z = -0.5;
1753
+ tintOverlay.frustumCulled = false;
1754
+ this.tintScene.add(tintOverlay);
1755
+ }
1756
+ createLights() {
1757
+ const hemiLight = new THREE.HemisphereLight(0xffffff, 0x20242d, 0.8);
1758
+ this.scene.add(hemiLight);
1759
+ const keyLight = new THREE.DirectionalLight(0xffffff, 2.6);
1760
+ keyLight.position.set(4, 5, 3);
1761
+ this.scene.add(keyLight);
1762
+ const panelKeyLight = new THREE.DirectionalLight(0xffffff, 2.2);
1763
+ panelKeyLight.position.set(-2, 3, 8);
1764
+ this.panelScene.add(panelKeyLight);
1765
+ this.panelScene.add(new THREE.AmbientLight(0xffffff, 0.7));
1766
+ const minimapKeyLight = new THREE.DirectionalLight(0xffffff, 2.2);
1767
+ minimapKeyLight.position.copy(panelKeyLight.position);
1768
+ this.minimapScene.add(minimapKeyLight);
1769
+ this.minimapScene.add(new THREE.AmbientLight(0xffffff, 0.7));
1770
+ }
1771
+ startHighRequest() {
1772
+ if (this.deferDetailPreparation)
1773
+ return;
1774
+ if (this.pagePreparation) {
1775
+ if (!this.catalogHandoff || this.catalogMotionComplete)
1776
+ this.adoptPreparedHigh();
1777
+ return;
1778
+ }
1779
+ if (!this.catalogHandoff || this.catalogMotionComplete)
1780
+ this.presentation.startHigh();
1781
+ }
1782
+ async loadModel() {
1783
+ const model = await this.presentation.load(resolveStageProfile({
1784
+ glb: this.glb,
1785
+ hdr: this.hdr,
1786
+ lodPair: this.lodPair,
1787
+ model: this.modelSettings,
1788
+ camera: this.cameraSettings,
1789
+ background: this.backgroundSettings
1790
+ }));
1791
+ if (!model)
1792
+ return;
1793
+ this.collectModelPickTargets(model);
1794
+ this.pipeline.createModelOutline(model);
1795
+ this.scene.add(model);
1796
+ this.fitModelCamera();
1797
+ this.startHighRequest();
1798
+ }
1799
+ fitModelCamera() {
1800
+ if (!this.model)
1801
+ return;
1802
+ const bounds = getMeshBounds(this.model, (mesh) => this.isSpatialElementMesh(mesh));
1803
+ if (bounds.isEmpty()) {
1804
+ throw new Error('The stage model does not contain any spatialElement meshes after exclusions');
1805
+ }
1806
+ if (this.referenceBounds)
1807
+ bounds.copy(this.referenceBounds);
1808
+ this.modelBounds.copy(bounds);
1809
+ const sphere = bounds.getBoundingSphere(new THREE.Sphere());
1810
+ const radius = Math.max(sphere.radius, 1);
1811
+ this.modelRadius = radius;
1812
+ const orbitDirection = getCameraOrbitDirection(this.cameraSettings.azimuth, this.cameraSettings.elevation);
1813
+ this.updateViewportFrame();
1814
+ this.camera.aspect = window.innerWidth / window.innerHeight;
1815
+ this.camera.updateProjectionMatrix();
1816
+ const fitDistance = this.getSpatialElementCameraFitDistance(bounds, orbitDirection);
1817
+ const maxDistance = Math.max(fitDistance, radius * 0.6);
1818
+ this.rememberFittedViewportMetrics();
1819
+ this.camera.position.copy(sphere.center).addScaledVector(orbitDirection, maxDistance);
1820
+ this.camera.near = Math.max(maxDistance / 100, 0.01);
1821
+ this.camera.far = Math.max(maxDistance * 100, radius * 20);
1822
+ this.camera.updateProjectionMatrix();
1823
+ const focusRange = getZoomFocusDistanceRange(maxDistance, radius);
1824
+ this.interaction.setFocusRange(focusRange.restDistance, focusRange.closeDistance);
1825
+ this.controls?.target.copy(sphere.center);
1826
+ if (this.controls) {
1827
+ this.controls.minDistance = this.focusCloseDistance * 0.64;
1828
+ this.controls.maxDistance = maxDistance;
1829
+ this.controls.update();
1830
+ this.camera.updateMatrixWorld(true);
1831
+ this.model.updateWorldMatrix(true, true);
1832
+ this.interaction.captureInitialView();
1833
+ this.camera.getWorldQuaternion(this.initialCameraWorldQuaternion);
1834
+ this.model.getWorldQuaternion(this.initialModelWorldQuaternion);
1835
+ }
1836
+ }
1837
+ initializeSpaceMouse() {
1838
+ return this.interaction.initializeSpaceMouse();
1839
+ }
1840
+ applySpaceMouseNavigationUpdate(update) {
1841
+ return this.interaction.applySpaceMouseNavigationUpdate(update);
1842
+ }
1843
+ setSpaceMouseMoving(moving) {
1844
+ return this.interaction.setSpaceMouseMoving(moving);
1845
+ }
1846
+ isSpatialElementMesh(mesh) {
1847
+ return !this.excludedMeshNames.has(mesh.name);
1848
+ }
1849
+ hideExcludedMeshes(model) {
1850
+ model.traverse((child) => {
1851
+ if (isMesh(child) && !this.isSpatialElementMesh(child))
1852
+ child.visible = false;
1853
+ });
1854
+ }
1855
+ collectModelPickTargets(model) {
1856
+ this.interaction.setPickTargets(model, (mesh) => this.isInteractionMesh(mesh));
1857
+ }
1858
+ isInteractionMesh(mesh) {
1859
+ if (!this.isSpatialElementMesh(mesh))
1860
+ return false;
1861
+ if (this.interactionTheme.excludeMesh?.(mesh))
1862
+ return false;
1863
+ if (mesh.userData.stagePick === false || mesh.userData.stageOutline === false)
1864
+ return false;
1865
+ const materialNames = getMeshMaterials(mesh)
1866
+ .map((material) => material.name)
1867
+ .filter(Boolean)
1868
+ .join(' ');
1869
+ const label = `${mesh.name} ${materialNames}`.toLowerCase();
1870
+ return !/(shadow|ground|floor|plane|helper|collision|collider|reflection)/i.test(label);
1871
+ }
1872
+ createPanels() {
1873
+ if (!this.pipeline.activeRenderTargets &&
1874
+ this.panelTargets.some((target) => target.surface === 'glass'))
1875
+ return;
1876
+ if (!this.panelTargets.length) {
1877
+ this.fallbackPanelOptions.forEach((options) => {
1878
+ const panel = new LiquidGlassPanel(this.pipeline.getPanelBlurTexture(options), options);
1879
+ const projectionRoot = this.createPanelProjectionRoot(panel.group);
1880
+ this.panels.add({
1881
+ domRenderMode: 'spatial',
1882
+ glass: panel,
1883
+ group: panel.group,
1884
+ nativeRestFrames: 0,
1885
+ options: panel.options,
1886
+ pointerLift: 0,
1887
+ pointerReactive: true,
1888
+ projectionRoot,
1889
+ surface: 'glass'
1890
+ });
1891
+ this.panelScene.add(projectionRoot);
1892
+ });
1893
+ return;
1894
+ }
1895
+ this.panelTargets.forEach((target, index) => {
1896
+ // Both nodes receive renderer-owned styles, including when only the surface is
1897
+ // reparented. Restore both before persistent panels switch page/surface bindings.
1898
+ this.rememberDomHome(target.surfaceElement);
1899
+ this.rememberDomHome(target.content);
1900
+ const measuredOptions = this.getMeasuredPanelOptions(target);
1901
+ if (target.surface === 'glass') {
1902
+ const panel = new LiquidGlassPanel(this.pipeline.getPanelBlurTexture(target.options), measuredOptions);
1903
+ const projectionRoot = target.minimap
1904
+ ? undefined
1905
+ : this.createPanelProjectionRoot(panel.group);
1906
+ this.panels.set(index, {
1907
+ domRenderMode: 'spatial',
1908
+ glass: panel,
1909
+ group: panel.group,
1910
+ nativeRestFrames: 0,
1911
+ options: panel.options,
1912
+ pointerLift: 0,
1913
+ pointerReactive: target.pointerReactive ?? true,
1914
+ projectionRoot,
1915
+ surface: target.surface
1916
+ });
1917
+ this.panelScene.add(projectionRoot ?? panel.group);
1918
+ this.attachPanelContent(target.content, index, target.contentInset);
1919
+ }
1920
+ else {
1921
+ const options = resolveLiquidGlassPanelOptions(measuredOptions);
1922
+ const group = new THREE.Group();
1923
+ const projectionRoot = target.minimap ? undefined : this.createPanelProjectionRoot(group);
1924
+ if (!projectionRoot)
1925
+ group.position.set(options.position.x, options.position.y, 0);
1926
+ this.panels.set(index, {
1927
+ domRenderMode: 'spatial',
1928
+ group,
1929
+ nativeRestFrames: 0,
1930
+ options,
1931
+ pointerLift: 0,
1932
+ pointerReactive: target.pointerReactive ?? true,
1933
+ projectionRoot,
1934
+ surface: target.surface
1935
+ });
1936
+ if (projectionRoot)
1937
+ this.panelScene.add(projectionRoot);
1938
+ this.attachPanelSurface(target.surfaceElement, index, Boolean(target.minimap));
1939
+ }
1940
+ this.createMinimap(index, target.minimap);
1941
+ const panel = this.panelRuntimes[index];
1942
+ const group = target.frame.dataset.catalogTransitionGroup;
1943
+ panel.transitionGroup = group === 'enter' || group === 'shared' ? group : undefined;
1944
+ panel.glass?.setVisibilityAlpha(this.getPanelTransitionOpacity(panel) * (target.getSurfaceOpacity?.() ?? 1));
1945
+ const minimap = this.minimaps.get(index);
1946
+ if (minimap) {
1947
+ this.updateMinimapOverlayVisibility(minimap);
1948
+ minimap.layer.visible = this.getPanelTransitionOpacity(panel) > 0.001;
1949
+ }
1950
+ target.frame.dataset.stagePanelBound = '';
1951
+ });
1952
+ }
1953
+ createPanelProjectionRoot(child) {
1954
+ return this.panels.createPanelProjectionRoot(child);
1955
+ }
1956
+ setPanelProjectionTransform(root, targetX, targetY, targetZ) {
1957
+ return this.panels.setPanelProjectionTransform(root, targetX, targetY, targetZ);
1958
+ }
1959
+ createMinimap(index, options) {
1960
+ return this.minimapController.createMinimap(index, options);
1961
+ }
1962
+ observePanelTargets() {
1963
+ this.pageBinding.observe(this.requestPanelSync);
1964
+ }
1965
+ syncPanelLayouts(force = false) {
1966
+ if (!this.panelTargets.length || (!this.layoutDirty && !force))
1967
+ return;
1968
+ this.layoutDirty = false;
1969
+ const measurePanels = force || this.panelMeasurementsDirty;
1970
+ this.panelTargets.forEach((target, index) => {
1971
+ const runtime = this.panelRuntimes[index];
1972
+ if (!runtime)
1973
+ return;
1974
+ const options = this.getMeasuredPanelOptions(target, measurePanels);
1975
+ const geometryChanged = hasPanelGeometryChanged(runtime.options, options);
1976
+ if (geometryChanged && runtime.glass && target.minimap) {
1977
+ this.replacePanel(index, options);
1978
+ }
1979
+ else {
1980
+ if (geometryChanged) {
1981
+ const radius = options.radius ?? runtime.options.radius;
1982
+ runtime.glass?.setVisualSize(options.width, options.height, radius);
1983
+ runtime.options.width = options.width;
1984
+ runtime.options.height = options.height;
1985
+ runtime.options.radius = radius;
1986
+ }
1987
+ }
1988
+ const currentRuntime = this.panelRuntimes[index];
1989
+ if (!currentRuntime)
1990
+ return;
1991
+ currentRuntime.options.position.x = options.position.x;
1992
+ currentRuntime.options.position.y = options.position.y;
1993
+ if (currentRuntime.projectionRoot) {
1994
+ currentRuntime.group.position.set(0, 0, 0);
1995
+ this.setPanelProjectionTransform(currentRuntime.projectionRoot, options.position.x, options.position.y, 0);
1996
+ }
1997
+ else {
1998
+ currentRuntime.group.position.set(options.position.x, options.position.y, 0);
1999
+ }
2000
+ if (currentRuntime.surface === 'glass') {
2001
+ this.updateContentElement(target.content, currentRuntime, target.contentInset);
2002
+ }
2003
+ else {
2004
+ this.updateSurfaceElement(target.surfaceElement, currentRuntime, currentRuntime.options.width, currentRuntime.options.height, Boolean(target.minimap));
2005
+ }
2006
+ if (currentRuntime.content) {
2007
+ if (currentRuntime.contentProjectionRoot) {
2008
+ currentRuntime.content.position.set(0, 0, 0);
2009
+ this.setPanelProjectionTransform(currentRuntime.contentProjectionRoot, currentRuntime.options.position.x, currentRuntime.options.position.y, PANEL_CONTENT_Z);
2010
+ }
2011
+ else {
2012
+ currentRuntime.content.position.set(currentRuntime.options.position.x, currentRuntime.options.position.y, PANEL_CONTENT_Z);
2013
+ }
2014
+ }
2015
+ if (geometryChanged && target.minimap)
2016
+ this.createMinimap(index, target.minimap);
2017
+ });
2018
+ this.panelMeasurementsDirty = false;
2019
+ }
2020
+ replacePanel(index, options) {
2021
+ if (!this.pipeline.activeRenderTargets)
2022
+ return;
2023
+ const runtime = this.panelRuntimes[index];
2024
+ const previousPanel = runtime?.glass;
2025
+ if (!runtime || !previousPanel)
2026
+ return;
2027
+ const nextPanel = new LiquidGlassPanel(this.pipeline.getPanelBlurTexture(options), options);
2028
+ nextPanel.group.rotation.copy(previousPanel.group.rotation);
2029
+ nextPanel.group.scale.copy(previousPanel.group.scale);
2030
+ previousPanel.group.removeFromParent();
2031
+ previousPanel.dispose();
2032
+ runtime.glass = nextPanel;
2033
+ runtime.group = nextPanel.group;
2034
+ runtime.options = nextPanel.options;
2035
+ if (runtime.projectionRoot) {
2036
+ nextPanel.group.position.set(0, 0, 0);
2037
+ runtime.projectionRoot.add(nextPanel.group);
2038
+ }
2039
+ else {
2040
+ this.panelScene.add(nextPanel.group);
2041
+ }
2042
+ }
2043
+ getMeasuredPanelOptions(target, forceMeasurement = false) {
2044
+ let cachedRect = this.pageBinding.getPanelRect(target.frame);
2045
+ if (!cachedRect || forceMeasurement) {
2046
+ cachedRect = this.measureStageRect(target.frame);
2047
+ this.pageBinding.setPanelRect(target.frame, cachedRect);
2048
+ }
2049
+ const rect = this.resolveStageRect(cachedRect);
2050
+ const width = Math.max(rect.width, 1);
2051
+ const height = Math.max(rect.height, 1);
2052
+ return {
2053
+ ...target.options,
2054
+ width,
2055
+ height,
2056
+ position: getStagePositionFromRect(rect)
2057
+ };
2058
+ }
2059
+ measureStageRect(element) {
2060
+ return this.pageBinding.measure(element, this.currentScrollX, this.currentScrollY);
2061
+ }
2062
+ resolveStageRect(rect) {
2063
+ return this.pageBinding.resolve(rect, this.currentScrollX, this.currentScrollY);
2064
+ }
2065
+ isPanelTargetVisible(index) {
2066
+ const target = this.panelTargets[index];
2067
+ if (!target)
2068
+ return true;
2069
+ const cachedRect = this.pageBinding.getPanelRect(target.frame);
2070
+ if (!cachedRect)
2071
+ return true;
2072
+ return isViewportRectVisible(this.resolveStageRect(cachedRect), window.innerWidth, window.innerHeight, VIEWPORT_CULL_MARGIN);
2073
+ }
2074
+ resizeRenderer() {
2075
+ const width = window.innerWidth;
2076
+ const height = window.innerHeight;
2077
+ this.panelMeasurementsDirty = true;
2078
+ this.viewportMeasurementDirty = true;
2079
+ this.pipeline.resizeRenderTargets();
2080
+ this.pipeline.resizeOutline(width, height);
2081
+ this.updateStageCameraProjection();
2082
+ const panelCameraDistance = getPerspectiveDistance(height, PANEL_CAMERA_FOV);
2083
+ this.panelCamera.aspect = width / height;
2084
+ this.panelCamera.near = Math.max(panelCameraDistance / 1000, 0.1);
2085
+ this.panelCamera.far = panelCameraDistance + 2000;
2086
+ this.panelCamera.position.set(0, 0, panelCameraDistance);
2087
+ this.panelCamera.lookAt(0, 0, 0);
2088
+ this.panelCamera.updateProjectionMatrix();
2089
+ this.cssRenderer.setSize(width, height);
2090
+ this.flatPanelLayer.style.width = `${width}px`;
2091
+ this.flatPanelLayer.style.height = `${height}px`;
2092
+ this.flatPanelLayer.style.perspective = `${panelCameraDistance}px`;
2093
+ this.nativePanelLayer.style.width = `${width}px`;
2094
+ this.nativePanelLayer.style.height = `${height}px`;
2095
+ this.layoutDirty = true;
2096
+ this.syncPanelLayouts(true);
2097
+ this.requestRender();
2098
+ }
2099
+ /**
2100
+ * Forces WebGPU to allocate and bind both quality levels before input starts.
2101
+ * `RenderTarget` construction and `setSize()` only configure descriptors; the
2102
+ * backend textures, blur intermediates, pipelines, and texture bindings are
2103
+ * materialized by these real offscreen/canvas render passes.
2104
+ */
2105
+ updateViewportFrame() {
2106
+ const width = window.innerWidth;
2107
+ const height = window.innerHeight;
2108
+ const element = this.viewportTarget?.element;
2109
+ if (!element) {
2110
+ this.stageViewportVisible = true;
2111
+ this.viewportFrame.set(0, 0, width, height);
2112
+ this.viewportLayoutSize.set(width, height);
2113
+ return;
2114
+ }
2115
+ if (!this.pageBinding.viewportRect || this.viewportMeasurementDirty) {
2116
+ this.pageBinding.viewportRect = this.measureStageRect(element);
2117
+ this.viewportMeasurementDirty = false;
2118
+ }
2119
+ const rect = this.resolveStageRect(this.pageBinding.viewportRect);
2120
+ if (rect.width < 1 || rect.height < 1) {
2121
+ this.stageViewportVisible = false;
2122
+ this.viewportFrame.set(0, 0, width, height);
2123
+ this.viewportLayoutSize.set(width, height);
2124
+ return;
2125
+ }
2126
+ this.viewportLayoutSize.set(Math.min(rect.width, width), Math.min(rect.height, height));
2127
+ this.stageViewportVisible = isViewportRectVisible(rect, width, height, VIEWPORT_CULL_MARGIN);
2128
+ const left = THREE.MathUtils.clamp(rect.left, 0, width);
2129
+ const top = THREE.MathUtils.clamp(rect.top, 0, height);
2130
+ const right = THREE.MathUtils.clamp(rect.right, 0, width);
2131
+ const bottom = THREE.MathUtils.clamp(rect.bottom, 0, height);
2132
+ const frameWidth = Math.max(right - left, 1);
2133
+ const frameHeight = Math.max(bottom - top, 1);
2134
+ this.viewportFrame.set(left, top, frameWidth, frameHeight);
2135
+ }
2136
+ getViewportScale() {
2137
+ const width = Math.max(window.innerWidth, 1);
2138
+ const height = Math.max(window.innerHeight, 1);
2139
+ const maximumPadding = Math.max(Math.min(this.viewportLayoutSize.x, this.viewportLayoutSize.y) * 0.5 - 1, 0);
2140
+ const padding = THREE.MathUtils.clamp(this.cameraSettings.fitPadding ?? 0, 0, maximumPadding);
2141
+ return {
2142
+ x: THREE.MathUtils.clamp((this.viewportLayoutSize.x - padding * 2) / width, 0.08, 1),
2143
+ y: THREE.MathUtils.clamp((this.viewportLayoutSize.y - padding * 2) / height, 0.08, 1)
2144
+ };
2145
+ }
2146
+ getSpatialElementCameraFitDistance(bounds, viewDirection) {
2147
+ const fitScale = THREE.MathUtils.clamp(this.cameraSettings.fitScale ?? 1, 0.2, 4);
2148
+ return (getCameraFitDistance(bounds, viewDirection, this.camera, SPATIAL_ELEMENT_CAMERA_FIT_MARGIN, this.getViewportScale()) / fitScale);
2149
+ }
2150
+ rememberFittedViewportMetrics() {
2151
+ this.fittedViewportMetrics.set(window.innerWidth, window.innerHeight, this.viewportLayoutSize.x, this.viewportLayoutSize.y);
2152
+ }
2153
+ refitCameraForViewport() {
2154
+ if (!this.controls || !this.initialViewCaptured || this.modelBounds.isEmpty())
2155
+ return;
2156
+ const metricsChanged = Math.abs(this.fittedViewportMetrics.x - window.innerWidth) > 0.5 ||
2157
+ Math.abs(this.fittedViewportMetrics.y - window.innerHeight) > 0.5 ||
2158
+ Math.abs(this.fittedViewportMetrics.z - this.viewportLayoutSize.x) > 0.5 ||
2159
+ Math.abs(this.fittedViewportMetrics.w - this.viewportLayoutSize.y) > 0.5;
2160
+ if (!metricsChanged)
2161
+ return;
2162
+ const previousMinDistance = this.controls.minDistance;
2163
+ const previousMaxDistance = this.controls.maxDistance;
2164
+ const previousEffectiveDistance = this.getEffectiveCameraDistance();
2165
+ const zoom = previousMaxDistance - previousMinDistance > 0.0001
2166
+ ? THREE.MathUtils.clamp((previousMaxDistance - previousEffectiveDistance) /
2167
+ (previousMaxDistance - previousMinDistance), 0, 1)
2168
+ : 0;
2169
+ const initialDirection = this.initialCameraPosition
2170
+ .clone()
2171
+ .sub(this.initialControlsTarget)
2172
+ .normalize();
2173
+ const currentDirection = this.camera.position.clone().sub(this.controls.target).normalize();
2174
+ const maxDistance = Math.max(this.getSpatialElementCameraFitDistance(this.modelBounds, initialDirection), this.modelRadius * 0.6);
2175
+ const focusRange = getZoomFocusDistanceRange(maxDistance, this.modelRadius);
2176
+ const minDistance = focusRange.closeDistance * 0.64;
2177
+ const nextEffectiveDistance = THREE.MathUtils.lerp(maxDistance, minDistance, zoom);
2178
+ const currentFovTangent = Math.tan(THREE.MathUtils.degToRad(this.camera.fov * 0.5));
2179
+ const initialFovTangent = Math.tan(THREE.MathUtils.degToRad(this.initialCameraFov * 0.5));
2180
+ const nextPhysicalDistance = nextEffectiveDistance * (initialFovTangent / Math.max(currentFovTangent, 0.0001));
2181
+ this.interaction.setFocusRange(focusRange.restDistance, focusRange.closeDistance);
2182
+ this.controls.minDistance = minDistance;
2183
+ this.controls.maxDistance = maxDistance;
2184
+ this.camera.position
2185
+ .copy(this.controls.target)
2186
+ .addScaledVector(currentDirection, nextPhysicalDistance);
2187
+ this.initialCameraPosition
2188
+ .copy(this.initialControlsTarget)
2189
+ .addScaledVector(initialDirection, maxDistance);
2190
+ this.camera.near = Math.max(maxDistance / 100, 0.01);
2191
+ this.camera.far = Math.max(maxDistance * 100, this.modelRadius * 20);
2192
+ this.camera.updateProjectionMatrix();
2193
+ this.camera.updateMatrixWorld(true);
2194
+ this.controls.update();
2195
+ this.rememberFittedViewportMetrics();
2196
+ }
2197
+ updateStageCameraProjection() {
2198
+ const width = window.innerWidth;
2199
+ const height = window.innerHeight;
2200
+ this.updateViewportFrame();
2201
+ const viewportCenterX = this.viewportFrame.x + this.viewportFrame.z * 0.5;
2202
+ const viewportCenterY = this.viewportFrame.y + this.viewportFrame.w * 0.5;
2203
+ const offsetX = width * 0.5 - viewportCenterX;
2204
+ const offsetY = height * 0.5 - viewportCenterY;
2205
+ this.camera.aspect = width / height;
2206
+ if (Math.abs(offsetX) > 0.25 || Math.abs(offsetY) > 0.25) {
2207
+ this.camera.setViewOffset(width, height, offsetX, offsetY, width, height);
2208
+ }
2209
+ else {
2210
+ this.camera.clearViewOffset();
2211
+ }
2212
+ this.refitCameraForViewport();
2213
+ }
2214
+ handlePointerMove(event) {
2215
+ return this.interaction.handlePointerMove(event);
2216
+ }
2217
+ handlePointerDown(event) {
2218
+ return this.interaction.handlePointerDown(event);
2219
+ }
2220
+ handlePointerUp(event) {
2221
+ return this.interaction.handlePointerUp(event);
2222
+ }
2223
+ handleWheel(event) {
2224
+ return this.interaction.handleWheel(event);
2225
+ }
2226
+ handleScrollFrame(frame) {
2227
+ if (this.disposed)
2228
+ return;
2229
+ this.currentScrollX = frame.scrollX;
2230
+ this.currentScrollY = frame.scrollY;
2231
+ if (this.renderRequestId)
2232
+ cancelAnimationFrame(this.renderRequestId);
2233
+ this.renderRequestId = 0;
2234
+ if (!this.scrollActive) {
2235
+ // Refresh document-space anchors once at the start of a scroll gesture.
2236
+ // Subsequent frames only subtract the current scroll offset.
2237
+ this.panelMeasurementsDirty = true;
2238
+ this.viewportMeasurementDirty = true;
2239
+ this.pipeline.setScrollRenderQuality(true);
2240
+ }
2241
+ this.scrollActive = true;
2242
+ this.layoutDirty = true;
2243
+ this.renderInvalidated = true;
2244
+ if (this.scrollEndTimer)
2245
+ window.clearTimeout(this.scrollEndTimer);
2246
+ this.scrollEndTimer = window.setTimeout(this.finishScroll, SCROLL_SETTLE_DELAY);
2247
+ const scrollY = frame.scrollY;
2248
+ const scrollDelta = scrollY - this.lastScrollY;
2249
+ this.lastScrollY = scrollY;
2250
+ if (scrollDelta > 0.5 && !this.spaceMouseMoving) {
2251
+ this.requestScrollZoomReset(scrollDelta);
2252
+ }
2253
+ // The shared scroll callback already runs inside requestAnimationFrame and
2254
+ // after dock mutations, so rendering here avoids adding another frame of lag.
2255
+ this.renderFrame();
2256
+ }
2257
+ requestScrollZoomReset(scrollDelta) {
2258
+ return this.interaction.requestScrollZoomReset(scrollDelta);
2259
+ }
2260
+ clearZoomReset() {
2261
+ return this.interaction.clearZoomReset();
2262
+ }
2263
+ clearWheelZoom() {
2264
+ return this.interaction.clearWheelZoom();
2265
+ }
2266
+ getEffectiveCameraDistance() {
2267
+ return this.interaction.getEffectiveCameraDistance();
2268
+ }
2269
+ handlePointerLeave() {
2270
+ return this.interaction.handlePointerLeave();
2271
+ }
2272
+ updateControlsAvailability() {
2273
+ return this.interaction.updateControlsAvailability();
2274
+ }
2275
+ reportZoomFocus(state) {
2276
+ const change = Math.max(Math.abs(state.focus - this.lastReportedZoomFocus.focus), Math.abs(state.uiFocus - this.lastReportedZoomFocus.uiFocus), Math.abs(state.uiOpacity - this.lastReportedZoomFocus.uiOpacity), Math.abs(state.minimapFocus - this.lastReportedZoomFocus.minimapFocus));
2277
+ if (!this.onZoomFocusChange || change < ZOOM_FOCUS_NOTIFY_EPSILON)
2278
+ return;
2279
+ this.lastReportedZoomFocus = { ...state };
2280
+ this.onZoomFocusChange(state);
2281
+ }
2282
+ getZoomFocusFactor() {
2283
+ return this.interaction.getZoomFocusFactor();
2284
+ }
2285
+ getZoomReferenceTarget() {
2286
+ return this.interaction.getZoomReferenceTarget();
2287
+ }
2288
+ getProjectedMinimapModelRect(minimap) {
2289
+ return this.minimapController.getProjectedMinimapModelRect(minimap);
2290
+ }
2291
+ updateMinimapOverlayVisibility(minimap) {
2292
+ return this.minimapController.updateMinimapOverlayVisibility(minimap);
2293
+ }
2294
+ setMinimapDisplayModelOpacity(minimap, opacity) {
2295
+ return this.minimapController.setMinimapDisplayModelOpacity(minimap, opacity);
2296
+ }
2297
+ updatePanelPointerInteraction(delta) {
2298
+ return this.panels.updatePanelPointerInteraction(delta);
2299
+ }
2300
+ /**
2301
+ * Switches settled, screen-aligned panels out of every transformed ancestor.
2302
+ * Two stable frames prevent mode churn while the damped pose snaps back to rest.
2303
+ */
2304
+ updatePanelDomRenderModes() {
2305
+ return this.panels.updatePanelDomRenderModes();
2306
+ }
2307
+ renderFlatPanelSurfaces() {
2308
+ return this.panels.renderFlatPanelSurfaces();
2309
+ }
2310
+ renderFrame(force = false) {
2311
+ const renderTargets = this.pipeline.activeRenderTargets;
2312
+ const listOnly = this.catalog && !this.viewportTarget;
2313
+ if (this.disposed || (!listOnly && (!renderTargets || !this.pipeline.stageDisplayQuad)))
2314
+ return;
2315
+ if (!force && document.hidden)
2316
+ return;
2317
+ if (!force && !this.renderInvalidated && !this.animationActive)
2318
+ return;
2319
+ this.renderInvalidated = false;
2320
+ this.renderer.setCanvasTarget(this.backgroundCanvasTarget);
2321
+ this.renderer.setClearColor(0xffffff, 1);
2322
+ const now = performance.now();
2323
+ const delta = Math.min((now - this.lastInteractionTime) / 1000, 0.05);
2324
+ this.advancePreparedPage(now);
2325
+ this.lastInteractionTime = now;
2326
+ this.backgroundCanvas.style.visibility = '';
2327
+ this.catalogLayerAnimating =
2328
+ this.catalogLayer?.update(this.renderer, this.scene.environment, now) ?? false;
2329
+ this.updateControlsAvailability();
2330
+ if (listOnly) {
2331
+ // The list has no hero camera. Never inherit close-up hiding/offsets from the DETAIL.
2332
+ this.panelFocus = 0;
2333
+ this.panelUiFocus = 0;
2334
+ this.minimapFocus = 0;
2335
+ this.reportZoomFocus({ focus: 0, uiFocus: 0, uiOpacity: 1, minimapFocus: 0 });
2336
+ this.syncPanelLayouts();
2337
+ const panelsAnimating = this.updatePanelPointerInteraction(delta);
2338
+ const domAnimating = this.updatePanelDomRenderModes();
2339
+ this.pipeline.renderFrame(true, false);
2340
+ this.cssRenderer.render(this.panelContentScene, this.panelCamera);
2341
+ this.renderFlatPanelSurfaces();
2342
+ this.animationActive = this.catalogLayerAnimating || panelsAnimating || domAnimating;
2343
+ if (!force && (this.animationActive || this.renderInvalidated))
2344
+ this.scheduleRender();
2345
+ return;
2346
+ }
2347
+ if (!renderTargets)
2348
+ return;
2349
+ const { controls: controlsAnimating, wheel: wheelZoomAnimating } = this.interaction.advance(now, delta);
2350
+ // The damped camera distance is the single animation clock for geometry and
2351
+ // every close-up UI phase. Phase remapping remains, temporal lag does not.
2352
+ this.panelFocus = this.getZoomFocusFactor();
2353
+ this.panelUiFocus = getStageUiFocus(this.panelFocus);
2354
+ this.minimapFocus = getSequencedMinimapFocus(this.panelFocus, this.panelUiFocus);
2355
+ this.updateStageCameraProjection();
2356
+ this.reportZoomFocus({
2357
+ focus: this.panelFocus,
2358
+ uiFocus: this.panelUiFocus,
2359
+ uiOpacity: getPanelFocusOpacity(this.panelUiFocus),
2360
+ minimapFocus: this.minimapFocus
2361
+ });
2362
+ this.syncPanelLayouts();
2363
+ const panelsAnimating = this.updatePanelPointerInteraction(delta);
2364
+ const panelDomModeAnimating = this.updatePanelDomRenderModes();
2365
+ this.pipeline.renderFrame(false, !this.scrollActive && !this.catalogHandoff);
2366
+ this.cssRenderer.render(this.panelContentScene, this.panelCamera);
2367
+ this.renderFlatPanelSurfaces();
2368
+ this.animationActive =
2369
+ this.presentation.readiness.animating ||
2370
+ this.catalogLayerAnimating ||
2371
+ (this.stageViewportVisible &&
2372
+ (!this.catalogHandoff || this.catalogMotionComplete) &&
2373
+ Boolean(this.refinement)) ||
2374
+ this.spaceMouseMoving ||
2375
+ controlsAnimating ||
2376
+ wheelZoomAnimating ||
2377
+ this.wheelZoomTargetDistance !== undefined ||
2378
+ this.zoomResetTargetDistance !== undefined ||
2379
+ this.viewResetActive ||
2380
+ panelsAnimating ||
2381
+ panelDomModeAnimating;
2382
+ if (!force && (this.animationActive || this.renderInvalidated))
2383
+ this.scheduleRender();
2384
+ }
2385
+ /** Draws only spatial UI into the transparent canvas above the page DOM. */
2386
+ /** Renders every glass surface below the DOM while preserving minimap screen projection. */
2387
+ renderStage() {
2388
+ if (this.stageViewportVisible &&
2389
+ (!this.catalogHandoff || this.catalogMotionComplete) &&
2390
+ this.pageModelReady &&
2391
+ this.presentation.renderRefinement(this.renderer, this.scene, this.pagePreparation?.environment.value?.target.texture, () => this.pipeline.renderStageContents(), (model, outline) => {
2392
+ this.collectModelPickTargets(model);
2393
+ this.pipeline.createModelOutline(outline);
2394
+ }, window.matchMedia('(prefers-reduced-motion: reduce)').matches))
2395
+ return;
2396
+ this.pipeline.renderStageContents();
2397
+ }
2398
+ }
2399
+ //# sourceMappingURL=StageExperience.js.map