semiotic 3.8.9 → 3.9.0

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 (500) hide show
  1. package/README.md +83 -67
  2. package/agent-skill/semiotic-charts/SKILL.md +11 -2
  3. package/ai/behaviorContracts.cjs +33 -3
  4. package/ai/cli.js +53 -2
  5. package/ai/componentMetadata.cjs +15 -0
  6. package/ai/dist/mcp-server.js +1530 -611
  7. package/ai/examples.md +48 -42
  8. package/{CLAUDE.md → ai/reference.md} +43 -22
  9. package/ai/schema.json +10603 -986
  10. package/ai/surface-manifest.json +643 -2
  11. package/ai/system-prompt.md +83 -130
  12. package/dist/c-3BLJEQNG.min.js +1 -0
  13. package/dist/c-3KZD6AXJ.min.js +1 -0
  14. package/dist/c-4TWEX5HG.min.js +1 -0
  15. package/dist/c-52TEGIUJ.min.js +1 -0
  16. package/dist/c-5YCIX3VZ.min.js +1 -0
  17. package/dist/c-6FEKTA3U.min.js +1 -0
  18. package/dist/c-6O5EVOPH.min.js +1 -0
  19. package/dist/c-74HEEZGK.min.js +1 -0
  20. package/dist/c-AKAF6JAD.min.js +1 -0
  21. package/dist/c-BBKITSXB.min.js +1 -0
  22. package/dist/c-BWNB6USU.min.js +1 -0
  23. package/dist/c-C25ENHIK.min.js +1 -0
  24. package/dist/c-CDR5AO3R.min.js +1 -0
  25. package/dist/c-COHXCW3Q.min.js +1 -0
  26. package/dist/{chunk-scatterplotMatrixBrushOverlay-SDIZSN66.module.min.js → c-DADXPJXV.min.js} +0 -1
  27. package/dist/c-E3JFRRMI.min.js +1 -0
  28. package/dist/c-EBFPQHHO.min.js +1 -0
  29. package/dist/c-G36WS6LN.min.js +1 -0
  30. package/dist/c-GIKRQI4X.min.js +1 -0
  31. package/dist/c-GPYOFETM.min.js +1 -0
  32. package/dist/c-IDUHYYSI.min.js +1 -0
  33. package/dist/{chunk-chunk-FQPKOAIH.module.min.js → c-IUHFPMHD.min.js} +0 -1
  34. package/dist/c-J5G56TUH.min.js +1 -0
  35. package/dist/c-JAZ73J32.min.js +1 -0
  36. package/dist/c-KG3NXHAL.min.js +1 -0
  37. package/dist/c-KII3PLZE.min.js +1 -0
  38. package/dist/c-LIXGXMNS.min.js +1 -0
  39. package/dist/c-LVEY6D6B.min.js +1 -0
  40. package/dist/c-M4Y3BHFR.min.js +1 -0
  41. package/dist/c-MAIICR2Z.min.js +1 -0
  42. package/dist/c-MG5DM6VE.min.js +1 -0
  43. package/dist/{chunk-minimapBrushOverlay-JU57U7NM.module.min.js → c-MNF2S4AA.min.js} +0 -1
  44. package/dist/c-MT3WBK7M.min.js +1 -0
  45. package/dist/c-NY3JWV2K.min.js +1 -0
  46. package/dist/c-O6U6K4CW.min.js +1 -0
  47. package/dist/c-OCI56QF2.min.js +1 -0
  48. package/dist/c-OQ7M4AGV.min.js +1 -0
  49. package/dist/c-OXYMVK7Q.min.js +1 -0
  50. package/dist/c-PPWDL5ZI.min.js +1 -0
  51. package/dist/c-QHF5YON3.min.js +1 -0
  52. package/dist/c-RR3GO5SW.min.js +1 -0
  53. package/dist/{chunk-chunk-J5QD4RAM.module.min.js → c-RSVIHIQ4.min.js} +0 -1
  54. package/dist/{chunk-chunk-EMO5NUGE.module.min.js → c-S2BXNNJN.min.js} +0 -1
  55. package/dist/{chunk-chunk-YCQYG6J5.module.min.js → c-SLGMUBUL.min.js} +0 -1
  56. package/dist/c-SUILCHWU.min.js +1 -0
  57. package/dist/c-TZW3JGJ5.min.js +1 -0
  58. package/dist/c-US5ZFT6E.min.js +1 -0
  59. package/dist/{chunk-chunk-RZH7VZYS.module.min.js → c-USFMFKIH.min.js} +0 -1
  60. package/dist/c-UUKVD4WB.min.js +1 -0
  61. package/dist/{chunk-chunk-SV4XAZ3Q.module.min.js → c-VGW3VG3I.min.js} +0 -1
  62. package/dist/c-W3CE4A4S.min.js +1 -0
  63. package/dist/{chunk-chunk-2NVFEB7P.module.min.js → c-WJCD5EUY.min.js} +0 -1
  64. package/dist/{chunk-chunk-2JGJ5GUG.module.min.js → c-X5UBGU2V.min.js} +0 -1
  65. package/dist/c-YDAY2WFR.min.js +1 -0
  66. package/dist/c-ZOWWU34K.min.js +1 -0
  67. package/dist/components/AccessibleNavTree.d.ts +1 -1
  68. package/dist/components/CategoryColors.d.ts +1 -1
  69. package/dist/components/GradientLegend.d.ts +14 -0
  70. package/dist/components/Legend.d.ts +2 -7
  71. package/dist/components/LinkedCharts.d.ts +1 -1
  72. package/dist/components/MobileAnnotationCalloutList.d.ts +1 -1
  73. package/dist/components/ObservationReadout.d.ts +45 -0
  74. package/dist/components/ThemeProvider.d.ts +4 -4
  75. package/dist/components/Tooltip/FlippingTooltip.d.ts +5 -7
  76. package/dist/components/Tooltip/Tooltip.d.ts +30 -5
  77. package/dist/components/Tooltip/tooltipChrome.d.ts +43 -0
  78. package/dist/components/ai/chartCapabilityTypes.d.ts +86 -2
  79. package/dist/components/ai/chartClinic.d.ts +2 -0
  80. package/dist/components/ai/deriveProfileFields.d.ts +40 -0
  81. package/dist/components/ai/evaluateChart.d.ts +85 -0
  82. package/dist/components/ai/fieldPolicy.d.ts +7 -0
  83. package/dist/components/ai/fieldRoles.d.ts +24 -0
  84. package/dist/components/ai/generativeChart.d.ts +18 -2
  85. package/dist/components/ai/inferIntent.d.ts +26 -2
  86. package/dist/components/ai/intents.d.ts +35 -0
  87. package/dist/components/ai/navigationTree.d.ts +2 -2
  88. package/dist/components/ai/observedSceneAudit.d.ts +2 -1
  89. package/dist/components/ai/profileData.d.ts +11 -0
  90. package/dist/components/ai/repairChartConfig.d.ts +2 -3
  91. package/dist/components/ai/semanticEvidence.d.ts +4 -0
  92. package/dist/components/ai/semanticViability.d.ts +11 -0
  93. package/dist/components/ai/semanticViabilityRegistry.d.ts +5 -0
  94. package/dist/components/ai/streamingTypes.d.ts +4 -0
  95. package/dist/components/ai/suggestCharts.d.ts +5 -6
  96. package/dist/components/ai/suggestDashboard.d.ts +2 -3
  97. package/dist/components/ai/suggestStreamCharts.d.ts +1 -1
  98. package/dist/components/ai/suggestStretchCharts.d.ts +2 -3
  99. package/dist/components/ai/suggestionPropContracts.d.ts +20 -0
  100. package/dist/components/ai/variantDiscovery.d.ts +3 -1
  101. package/dist/components/charts/custom/NetworkCustomChart.d.ts +3 -0
  102. package/dist/components/charts/custom/OrdinalCustomChart.d.ts +3 -0
  103. package/dist/components/charts/custom/XYCustomChart.d.ts +1 -1
  104. package/dist/components/charts/geo/ChoroplethMap.d.ts +3 -1
  105. package/dist/components/charts/geo/DistanceCartogram.d.ts +2 -7
  106. package/dist/components/charts/geo/cartogramOverlay.d.ts +28 -0
  107. package/dist/components/charts/index.d.ts +4 -3
  108. package/dist/components/charts/network/ProcessSankey.d.ts +2 -136
  109. package/dist/components/charts/network/ProcessSankeyProps.d.ts +139 -0
  110. package/dist/components/charts/network/Treemap.d.ts +2 -1
  111. package/dist/components/charts/network/processSankey/boundaryHubOrdering.d.ts +23 -0
  112. package/dist/components/charts/network/processSankey/layoutGeometry.d.ts +2 -0
  113. package/dist/components/charts/network/processSankey/ordering.d.ts +3 -41
  114. package/dist/components/charts/network/processSankey/orderingTypes.d.ts +32 -0
  115. package/dist/components/charts/network/processSankey/packing.d.ts +1 -1
  116. package/dist/components/charts/network/processSankey/packingCache.d.ts +1 -1
  117. package/dist/components/charts/network/processSankey/packingOptimization.d.ts +72 -0
  118. package/dist/components/charts/ordinal/BarChart.d.ts +4 -3
  119. package/dist/components/charts/ordinal/FunnelChart.d.ts +2 -0
  120. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -2
  121. package/dist/components/charts/ordinal/StackedBarChart.d.ts +4 -3
  122. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +2 -2
  123. package/dist/components/charts/physics/GaltonBoardChart.d.ts +2 -9
  124. package/dist/components/charts/physics/GauntletChart.d.ts +10 -41
  125. package/dist/components/charts/physics/ProcessFlowChart.d.ts +1 -1
  126. package/dist/components/charts/physics/chainReactionAccessibleTable.d.ts +9 -0
  127. package/dist/components/charts/physics/chainReactionRuntime.d.ts +2 -1
  128. package/dist/components/charts/physics/chainReactionTypes.d.ts +5 -1
  129. package/dist/components/charts/physics/crucibleBodyRenderers.d.ts +2 -2
  130. package/dist/components/charts/physics/crucibleClone.d.ts +6 -0
  131. package/dist/components/charts/physics/crucibleEffects.d.ts +1 -2
  132. package/dist/components/charts/physics/crucibleRecord.d.ts +7 -0
  133. package/dist/components/charts/physics/gauntletChrome.d.ts +4 -4
  134. package/dist/components/charts/physics/gauntletPhysics.d.ts +1 -0
  135. package/dist/components/charts/physics/gauntletPublic.d.ts +4 -0
  136. package/dist/components/charts/physics/packetFlowOverlay.d.ts +7 -0
  137. package/dist/components/charts/physics/physicsChartLayout.d.ts +8 -0
  138. package/dist/components/charts/physics/physicsChartShared.d.ts +3 -1
  139. package/dist/components/charts/physics/physicsChartUtils.d.ts +1 -1
  140. package/dist/components/charts/physics/physicsHocUtils.d.ts +25 -12
  141. package/dist/components/charts/physics/physicsProjectionOverlays.d.ts +24 -0
  142. package/dist/components/charts/physics/processFlowOverlays.d.ts +9 -0
  143. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +15 -12
  144. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +10 -7
  145. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +35 -14
  146. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +21 -14
  147. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +20 -13
  148. package/dist/components/charts/realtime/aggregate.d.ts +4 -1
  149. package/dist/components/charts/realtime/eventTime.d.ts +4 -0
  150. package/dist/components/charts/realtime/realtimeChartRuntime.d.ts +27 -0
  151. package/dist/components/charts/realtime/realtimeChartTypes.d.ts +30 -0
  152. package/dist/components/charts/realtime/useRealtimeCategoryColors.d.ts +30 -0
  153. package/dist/components/charts/shared/FrameTextAnnotationSVG.d.ts +10 -0
  154. package/dist/components/charts/shared/annotationActivation.d.ts +3 -7
  155. package/dist/components/charts/shared/annotationBandFill.d.ts +6 -0
  156. package/dist/components/charts/shared/annotationDispatch.d.ts +31 -0
  157. package/dist/components/charts/shared/annotationIdentity.d.ts +8 -0
  158. package/dist/components/charts/shared/annotationRules.d.ts +1 -15
  159. package/dist/components/charts/shared/boundedCategoryRegistry.d.ts +8 -0
  160. package/dist/components/charts/shared/chainReactionChartSpec.d.ts +3 -0
  161. package/dist/components/charts/shared/chartMode.d.ts +3 -2
  162. package/dist/components/charts/shared/chartSpecCore.d.ts +1 -0
  163. package/dist/components/charts/shared/frameTextAnnotation.d.ts +63 -0
  164. package/dist/components/charts/shared/gradient.d.ts +16 -0
  165. package/dist/components/charts/shared/hatchFill.d.ts +15 -0
  166. package/dist/components/charts/shared/hooks.d.ts +4 -4
  167. package/dist/components/charts/shared/legendUtils.d.ts +1 -0
  168. package/dist/components/charts/shared/streamPropsHelpers.d.ts +2 -1
  169. package/dist/components/charts/shared/styleRules.d.ts +9 -2
  170. package/dist/components/charts/shared/styleRulesWireSchema.d.ts +353 -0
  171. package/dist/components/charts/shared/types.d.ts +18 -9
  172. package/dist/components/charts/shared/useChartLegend.d.ts +43 -9
  173. package/dist/components/charts/shared/useChartSetup.d.ts +3 -1
  174. package/dist/components/charts/shared/useCustomChartSetup.d.ts +5 -2
  175. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +5 -1
  176. package/dist/components/charts/shared/useOrdinalBrush.d.ts +3 -3
  177. package/dist/components/charts/shared/useStreamingLegend.d.ts +6 -1
  178. package/dist/components/charts/value/types.d.ts +1 -1
  179. package/dist/components/charts/xy/BubbleChart.d.ts +1 -1
  180. package/dist/components/charts/xy/BumpChart.capability.d.ts +14 -1
  181. package/dist/components/charts/xy/BumpChart.d.ts +13 -73
  182. package/dist/components/charts/xy/BumpChart.semanticViability.d.ts +5 -0
  183. package/dist/components/charts/xy/CandlestickChart.d.ts +2 -2
  184. package/dist/components/charts/xy/LineChart.d.ts +2 -2
  185. package/dist/components/charts/xy/Scatterplot.d.ts +1 -1
  186. package/dist/components/charts/xy/bumpData.d.ts +44 -0
  187. package/dist/components/charts/xy/bumpIdentity.d.ts +2 -0
  188. package/dist/components/charts/xy/bumpLayout.d.ts +45 -0
  189. package/dist/components/charts/xy/bumpTooltip.d.ts +20 -0
  190. package/dist/components/legendLayout.d.ts +131 -4
  191. package/dist/components/realtime/ReorderBuffer.d.ts +2 -0
  192. package/dist/components/realtime/types.d.ts +10 -1
  193. package/dist/components/recipes/balanceSnapshotsToFlows.d.ts +42 -0
  194. package/dist/components/recipes/directedReachability.d.ts +14 -0
  195. package/dist/components/recipes/gofishDisplayListFixtures.generated.d.ts +6 -6
  196. package/dist/components/recipes/gridObservatory.d.ts +1 -1
  197. package/dist/components/recipes/networkAnalysis.d.ts +1 -18
  198. package/dist/components/recipes/physics.d.ts +7 -4
  199. package/dist/components/recipes/processPhysics.d.ts +0 -1
  200. package/dist/components/recipes/waffle.d.ts +7 -4
  201. package/dist/components/semiotic-ai-core.d.ts +13 -4
  202. package/dist/components/semiotic-ai-observations.d.ts +3 -0
  203. package/dist/components/semiotic-ai.d.ts +16 -9
  204. package/dist/components/semiotic-client-shared.d.ts +10 -0
  205. package/dist/components/semiotic-experimental.d.ts +1 -1
  206. package/dist/components/semiotic-geo.d.ts +4 -1
  207. package/dist/components/semiotic-network.d.ts +7 -4
  208. package/dist/components/semiotic-ordinal.d.ts +4 -1
  209. package/dist/components/semiotic-physics.d.ts +11 -4
  210. package/dist/components/semiotic-realtime-core.d.ts +11 -4
  211. package/dist/components/semiotic-realtime-react.d.ts +4 -3
  212. package/dist/components/semiotic-realtime.d.ts +3 -1
  213. package/dist/components/semiotic-recipes-core.d.ts +7 -5
  214. package/dist/components/semiotic-server-edge.d.ts +3 -2
  215. package/dist/components/semiotic-server.d.ts +3 -2
  216. package/dist/components/semiotic-themes-core.d.ts +5 -48
  217. package/dist/components/semiotic-utils-core.d.ts +10 -5
  218. package/dist/components/semiotic-utils-react.d.ts +2 -0
  219. package/dist/components/semiotic-xy.d.ts +4 -1
  220. package/dist/components/semiotic.d.ts +68 -26
  221. package/dist/components/server/animatedGif.d.ts +1 -1
  222. package/dist/components/server/renderEvidence.d.ts +25 -2
  223. package/dist/components/server/renderToStaticSVG.d.ts +15 -7
  224. package/dist/components/server/serverChartConfigShared.d.ts +8 -1
  225. package/dist/components/server/serverChartConfigs.d.ts +1 -0
  226. package/dist/components/server/serverChartConfigsNetwork.d.ts +3 -3
  227. package/dist/components/server/serverChartConfigsNetworkChord.d.ts +2 -0
  228. package/dist/components/server/serverChartConfigsNetworkForce.d.ts +2 -0
  229. package/dist/components/server/serverChartConfigsNetworkHierarchy.d.ts +3 -0
  230. package/dist/components/server/serverChartConfigsXY.d.ts +3 -3
  231. package/dist/components/server/serverChartConfigsXYBubble.d.ts +5 -0
  232. package/dist/components/server/serverChartConfigsXYBump.d.ts +7 -0
  233. package/dist/components/server/serverChartConfigsXYScatter.d.ts +5 -0
  234. package/dist/components/server/staticAnnotationFallbacks.d.ts +10 -0
  235. package/dist/components/server/staticAnnotations.d.ts +28 -1
  236. package/dist/components/server/staticAxisTickLabel.d.ts +13 -0
  237. package/dist/components/server/staticLegend.d.ts +1 -1
  238. package/dist/components/server/staticLegendMargin.d.ts +41 -0
  239. package/dist/components/server/staticOrdinal.d.ts +8 -2
  240. package/dist/components/server/staticPhysics.d.ts +13 -1
  241. package/dist/components/server/staticPhysicsChrome.d.ts +20 -0
  242. package/dist/components/server/staticRawLegend.d.ts +15 -0
  243. package/dist/components/server/staticSVGChrome.d.ts +16 -55
  244. package/dist/components/server/staticXYAxes.d.ts +27 -0
  245. package/dist/components/server/staticXYAxisTicks.d.ts +39 -0
  246. package/dist/components/server/staticXYGrid.d.ts +11 -0
  247. package/dist/components/server/themeResolver.d.ts +5 -1
  248. package/dist/components/store/ThemeStore.d.ts +2 -98
  249. package/dist/components/store/designTokens.d.ts +1 -1
  250. package/dist/components/store/themeCSSVariables.d.ts +10 -0
  251. package/dist/components/store/themeCore.d.ts +91 -0
  252. package/dist/components/store/themePresets.d.ts +81 -0
  253. package/dist/components/store/themeSerialization.d.ts +2 -1
  254. package/dist/components/stream/AccessibleDataTable.d.ts +12 -14
  255. package/dist/components/stream/AccessibleTablePortalImpl.d.ts +6 -0
  256. package/dist/components/stream/GeoTileRenderer.d.ts +2 -0
  257. package/dist/components/stream/NetworkCanvasHitTester.d.ts +3 -1
  258. package/dist/components/stream/NetworkSSRFrame.d.ts +2 -1
  259. package/dist/components/stream/NetworkSVGOverlay.d.ts +3 -31
  260. package/dist/components/stream/OrdinalCanvasHitTester.d.ts +2 -0
  261. package/dist/components/stream/SVGChartTitle.d.ts +9 -0
  262. package/dist/components/stream/SVGOverlay.d.ts +1 -21
  263. package/dist/components/stream/SVGUnderlay.d.ts +24 -0
  264. package/dist/components/stream/SceneToSVG.d.ts +1 -1
  265. package/dist/components/stream/StreamGeoFrame.d.ts +1 -1
  266. package/dist/components/stream/StreamOrdinalFrame.d.ts +1 -1
  267. package/dist/components/stream/StreamXYFrame.d.ts +1 -1
  268. package/dist/components/stream/accessibleDataRows.d.ts +11 -0
  269. package/dist/components/stream/accessibleDataTableModel.d.ts +40 -0
  270. package/dist/components/stream/accessibleTableTypes.d.ts +11 -0
  271. package/dist/components/stream/axisTickUtils.d.ts +19 -0
  272. package/dist/components/stream/canvasBackground.d.ts +10 -0
  273. package/dist/components/stream/canvasSetup.d.ts +9 -0
  274. package/dist/components/stream/frameCursorInteraction.d.ts +25 -0
  275. package/dist/components/stream/frameDefaultMargins.d.ts +37 -0
  276. package/dist/components/stream/frameGraphics.d.ts +18 -0
  277. package/dist/components/stream/frameGraphicsSubscription.d.ts +26 -0
  278. package/dist/components/stream/frameLegendOptions.d.ts +18 -0
  279. package/dist/components/stream/geoFrameCursorInteraction.d.ts +9 -0
  280. package/dist/components/stream/geoFrameHelpers.d.ts +29 -1
  281. package/dist/components/stream/geoTypes.d.ts +10 -11
  282. package/dist/components/stream/hitTarget.d.ts +61 -2
  283. package/dist/components/stream/moduleWorkerSession.d.ts +6 -0
  284. package/dist/components/stream/networkAnnotationAnchors.d.ts +37 -0
  285. package/dist/components/stream/networkCustomLayout.d.ts +2 -2
  286. package/dist/components/stream/networkFrameCursorInteraction.d.ts +12 -0
  287. package/dist/components/stream/networkFrameInteraction.d.ts +2 -0
  288. package/dist/components/stream/networkFramePaint.d.ts +7 -0
  289. package/dist/components/stream/networkPipelineConfig.d.ts +1 -1
  290. package/dist/components/stream/networkTypes.d.ts +30 -32
  291. package/dist/components/stream/normalizeXYData.d.ts +7 -0
  292. package/dist/components/stream/ordinalFrameCursorInteraction.d.ts +7 -0
  293. package/dist/components/stream/ordinalFrameInteraction.d.ts +29 -0
  294. package/dist/components/stream/ordinalSceneSVG.d.ts +10 -0
  295. package/dist/components/stream/ordinalTypes.d.ts +10 -4
  296. package/dist/components/stream/physics/PhysicsBodySpatialIndex.d.ts +9 -1
  297. package/dist/components/stream/physics/PhysicsCanvasTheme.d.ts +25 -0
  298. package/dist/components/stream/physics/PhysicsControllers.d.ts +0 -3
  299. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +4 -1
  300. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +3 -24
  301. package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +9 -21
  302. package/dist/components/stream/physics/PhysicsSettledSVGElement.d.ts +37 -0
  303. package/dist/components/stream/physics/PhysicsSettledScene.d.ts +7 -3
  304. package/dist/components/stream/physics/StreamPhysicsFrame.d.ts +1 -1
  305. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +23 -4
  306. package/dist/components/stream/physics/physicsAnnotationContext.d.ts +19 -0
  307. package/dist/components/stream/physics/physicsBodyCanvas.d.ts +4 -0
  308. package/dist/components/stream/physics/physicsSettledChrome.d.ts +7 -0
  309. package/dist/components/stream/physics/usePhysicsCanvasPointer.d.ts +32 -0
  310. package/dist/components/stream/physics/usePhysicsSemanticNavigation.d.ts +36 -0
  311. package/dist/components/stream/pipelineConfig.d.ts +6 -17
  312. package/dist/components/stream/pipelineDomainResolution.d.ts +1 -1
  313. package/dist/components/stream/renderBackend.d.ts +2 -0
  314. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +13 -2
  315. package/dist/components/stream/renderers/resolveCSSColor.d.ts +7 -0
  316. package/dist/components/stream/responsiveSize.d.ts +17 -0
  317. package/dist/components/stream/sceneCursor.d.ts +41 -0
  318. package/dist/components/stream/sceneRevisionDiagnostics.d.ts +1 -1
  319. package/dist/components/stream/svgOverlayUtils.d.ts +22 -1
  320. package/dist/components/stream/types.d.ts +25 -12
  321. package/dist/components/stream/useCanvasFrameHost.d.ts +3 -1
  322. package/dist/components/stream/useFrame.d.ts +24 -1
  323. package/dist/components/stream/useResponsiveSize.d.ts +6 -1
  324. package/dist/components/stream/useStalenessCheck.d.ts +1 -1
  325. package/dist/components/stream/xyFrameAxisTypes.d.ts +15 -4
  326. package/dist/components/stream/xyFrameCursorInteraction.d.ts +6 -0
  327. package/dist/components/stream/xySceneBuilders/swarmScene.d.ts +1 -1
  328. package/dist/components/stream/xySceneBuilders/types.d.ts +6 -26
  329. package/dist/components/types/legendTypes.d.ts +6 -0
  330. package/dist/components/types/marginType.d.ts +7 -8
  331. package/dist/controls.min.js +1 -1
  332. package/dist/controls.module.min.js +1 -1
  333. package/dist/forceLayoutWorker.js +1 -1
  334. package/dist/geo.min.js +1 -1
  335. package/dist/geo.module.min.js +1 -1
  336. package/dist/network.min.js +1 -1
  337. package/dist/network.module.min.js +1 -1
  338. package/dist/ordinal.min.js +1 -1
  339. package/dist/ordinal.module.min.js +1 -1
  340. package/dist/physics-matter.module.min.js +1 -1
  341. package/dist/physics-rapier.module.min.js +1 -1
  342. package/dist/physics.min.js +1 -1
  343. package/dist/physics.module.min.js +1 -1
  344. package/dist/physicsWorker.js +1 -1
  345. package/dist/processSankeyLayoutWorker.js +1 -1
  346. package/dist/realtime.min.js +1 -1
  347. package/dist/realtime.module.min.js +1 -1
  348. package/dist/rough.min.js +1 -1
  349. package/dist/rough.module.min.js +1 -1
  350. package/dist/semiotic-ai-core.d.ts +13 -4
  351. package/dist/semiotic-ai-core.min.js +1 -1
  352. package/dist/semiotic-ai-core.module.min.js +1 -1
  353. package/dist/semiotic-ai.d.ts +16 -9
  354. package/dist/semiotic-ai.min.js +1 -1
  355. package/dist/semiotic-ai.module.min.js +1 -1
  356. package/dist/semiotic-client-cjs-shared.min.js +1 -0
  357. package/dist/semiotic-client-glyph.module.min.js +2 -0
  358. package/dist/semiotic-client-responsive.module.min.js +2 -0
  359. package/dist/semiotic-client-shared.module.min.js +2 -0
  360. package/dist/semiotic-custom-layout-selection-cjs-shared.min.js +2 -0
  361. package/dist/semiotic-data.min.js +1 -1
  362. package/dist/semiotic-data.module.min.js +1 -1
  363. package/dist/semiotic-experimental-auxiliary.module.min.js +2 -0
  364. package/dist/semiotic-experimental-node-auxiliary.module.min.js +2 -0
  365. package/dist/semiotic-experimental-node.module.min.js +2 -0
  366. package/dist/semiotic-experimental-react-shared.module.min.js +2 -0
  367. package/dist/semiotic-experimental-vacp.min.js +1 -1
  368. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  369. package/dist/semiotic-experimental.d.ts +1 -1
  370. package/dist/semiotic-experimental.min.js +1 -1
  371. package/dist/semiotic-experimental.module.min.js +1 -1
  372. package/dist/semiotic-geo.d.ts +4 -1
  373. package/dist/semiotic-network.d.ts +7 -4
  374. package/dist/semiotic-ordinal.d.ts +4 -1
  375. package/dist/semiotic-physics.d.ts +11 -4
  376. package/dist/semiotic-realtime-core.d.ts +11 -4
  377. package/dist/semiotic-realtime-core.min.js +2 -1
  378. package/dist/semiotic-realtime-core.module.min.js +2 -1
  379. package/dist/semiotic-realtime-react.d.ts +4 -3
  380. package/dist/semiotic-realtime-react.min.js +1 -1
  381. package/dist/semiotic-realtime-react.module.min.js +1 -1
  382. package/dist/semiotic-realtime.d.ts +3 -1
  383. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -0
  384. package/dist/semiotic-recipes-core.d.ts +7 -5
  385. package/dist/semiotic-recipes-core.min.js +9 -1
  386. package/dist/semiotic-recipes-core.module.min.js +1 -1
  387. package/dist/semiotic-recipes-geo-cjs.min.js +1 -0
  388. package/dist/semiotic-recipes-react.min.js +1 -1
  389. package/dist/semiotic-recipes-react.module.min.js +1 -1
  390. package/dist/semiotic-recipes.min.js +7 -1
  391. package/dist/semiotic-recipes.module.min.js +2 -1
  392. package/dist/semiotic-server-edge-node.module.min.js +1 -0
  393. package/dist/semiotic-server-edge.d.ts +3 -2
  394. package/dist/semiotic-server-edge.min.js +1 -1
  395. package/dist/semiotic-server-edge.module.min.js +1 -1
  396. package/dist/semiotic-server-node.min.js +1 -1
  397. package/dist/semiotic-server-node.module.min.js +1 -1
  398. package/dist/semiotic-server.d.ts +3 -2
  399. package/dist/semiotic-themes-core.d.ts +5 -48
  400. package/dist/semiotic-themes-core.min.js +1 -1
  401. package/dist/semiotic-themes-core.module.min.js +1 -1
  402. package/dist/semiotic-themes-react.min.js +1 -1
  403. package/dist/semiotic-themes-react.module.min.js +1 -1
  404. package/dist/semiotic-themes.min.js +1 -1
  405. package/dist/semiotic-themes.module.min.js +1 -1
  406. package/dist/semiotic-utils-core.d.ts +10 -5
  407. package/dist/semiotic-utils-core.min.js +1 -1
  408. package/dist/semiotic-utils-core.module.min.js +1 -1
  409. package/dist/semiotic-utils-react.d.ts +2 -0
  410. package/dist/semiotic-utils-react.min.js +1 -1
  411. package/dist/semiotic-utils-react.module.min.js +1 -1
  412. package/dist/semiotic-utils.min.js +2 -1
  413. package/dist/semiotic-utils.module.min.js +2 -1
  414. package/dist/semiotic-value.min.js +1 -1
  415. package/dist/semiotic-value.module.min.js +1 -1
  416. package/dist/semiotic-xy.d.ts +4 -1
  417. package/dist/semiotic.d.ts +68 -26
  418. package/dist/semiotic.min.js +1 -1
  419. package/dist/semiotic.module.min.js +1 -1
  420. package/dist/server.min.js +1 -1
  421. package/dist/server.module.min.js +1 -1
  422. package/dist/xy.min.js +1 -1
  423. package/dist/xy.module.min.js +1 -1
  424. package/package.json +53 -19
  425. package/dist/__tests__/scenarios/mcpProtocolTypes.d.ts +0 -20
  426. package/dist/chunk-OrdinalBrushOverlay-PXHQYDB2.module.min.js +0 -2
  427. package/dist/chunk-XYBrushOverlay-ECZJJLAJ.module.min.js +0 -1
  428. package/dist/chunk-XYBrushOverlay-EP2SV3UI.module.min.js +0 -2
  429. package/dist/chunk-chartContainerDataAudit-IQ3NBN3Q.module.min.js +0 -2
  430. package/dist/chunk-chunk-2B3AIKUZ.module.min.js +0 -2
  431. package/dist/chunk-chunk-2CXCXRB4.module.min.js +0 -1
  432. package/dist/chunk-chunk-2X3FJCME.module.min.js +0 -1
  433. package/dist/chunk-chunk-2ZHHWZQM.module.min.js +0 -2
  434. package/dist/chunk-chunk-4ITOQRXM.module.min.js +0 -2
  435. package/dist/chunk-chunk-5UKL5W76.module.min.js +0 -2
  436. package/dist/chunk-chunk-5VVNW5AZ.module.min.js +0 -1
  437. package/dist/chunk-chunk-5ZON5NMV.module.min.js +0 -2
  438. package/dist/chunk-chunk-66PCWJUG.module.min.js +0 -1
  439. package/dist/chunk-chunk-6S3YGYW7.module.min.js +0 -1
  440. package/dist/chunk-chunk-6V5VQVCT.module.min.js +0 -2
  441. package/dist/chunk-chunk-7C5EDZ3Z.module.min.js +0 -2
  442. package/dist/chunk-chunk-A3I4HBD5.module.min.js +0 -1
  443. package/dist/chunk-chunk-ACLDBMRH.module.min.js +0 -2
  444. package/dist/chunk-chunk-AFQHURLO.module.min.js +0 -2
  445. package/dist/chunk-chunk-DDB4TLQG.module.min.js +0 -2
  446. package/dist/chunk-chunk-DTH3SUOU.module.min.js +0 -2
  447. package/dist/chunk-chunk-DTSNLGRK.module.min.js +0 -2
  448. package/dist/chunk-chunk-DVCWU7MT.module.min.js +0 -2
  449. package/dist/chunk-chunk-FEPXDKJP.module.min.js +0 -1
  450. package/dist/chunk-chunk-FJ76HWQZ.module.min.js +0 -1
  451. package/dist/chunk-chunk-FSIHAW6L.module.min.js +0 -2
  452. package/dist/chunk-chunk-G2RGVEYY.module.min.js +0 -2
  453. package/dist/chunk-chunk-G75OPF5N.module.min.js +0 -2
  454. package/dist/chunk-chunk-HADHLMY5.module.min.js +0 -1
  455. package/dist/chunk-chunk-HAJVODLO.module.min.js +0 -2
  456. package/dist/chunk-chunk-HBFA4NN6.module.min.js +0 -1
  457. package/dist/chunk-chunk-HIV7AW2V.module.min.js +0 -2
  458. package/dist/chunk-chunk-IY7RYD4S.module.min.js +0 -1
  459. package/dist/chunk-chunk-J3QOW4OE.module.min.js +0 -0
  460. package/dist/chunk-chunk-J3XWETBJ.module.min.js +0 -2
  461. package/dist/chunk-chunk-JZAMMSQQ.module.min.js +0 -2
  462. package/dist/chunk-chunk-KTWEBFMX.module.min.js +0 -2
  463. package/dist/chunk-chunk-LSJUXBMF.module.min.js +0 -1
  464. package/dist/chunk-chunk-MXMRXSCI.module.min.js +0 -2
  465. package/dist/chunk-chunk-MXVBXFKW.module.min.js +0 -2
  466. package/dist/chunk-chunk-NWIGA3UK.module.min.js +0 -1
  467. package/dist/chunk-chunk-OFAP623Y.module.min.js +0 -2
  468. package/dist/chunk-chunk-OHLRAEQZ.module.min.js +0 -2
  469. package/dist/chunk-chunk-OZK46A5U.module.min.js +0 -1
  470. package/dist/chunk-chunk-PMR47KRY.module.min.js +0 -2
  471. package/dist/chunk-chunk-PRNXOCYZ.module.min.js +0 -2
  472. package/dist/chunk-chunk-Q2YADC2V.module.min.js +0 -2
  473. package/dist/chunk-chunk-RLKZVJMQ.module.min.js +0 -2
  474. package/dist/chunk-chunk-ROP4HI7H.module.min.js +0 -2
  475. package/dist/chunk-chunk-SK2TQMG4.module.min.js +0 -2
  476. package/dist/chunk-chunk-SKLYXNYW.module.min.js +0 -2
  477. package/dist/chunk-chunk-TCMHJWFJ.module.min.js +0 -1
  478. package/dist/chunk-chunk-TSCFL235.module.min.js +0 -1
  479. package/dist/chunk-chunk-U4NZCU5T.module.min.js +0 -2
  480. package/dist/chunk-chunk-U66USBWU.module.min.js +0 -1
  481. package/dist/chunk-chunk-UOQRPGPK.module.min.js +0 -2
  482. package/dist/chunk-chunk-VKL6DI43.module.min.js +0 -2
  483. package/dist/chunk-chunk-W62673ZE.module.min.js +0 -1
  484. package/dist/chunk-chunk-WFHZHWT7.module.min.js +0 -1
  485. package/dist/chunk-chunk-XCC25CZZ.module.min.js +0 -2
  486. package/dist/chunk-chunk-XECNOUZY.module.min.js +0 -2
  487. package/dist/chunk-chunk-XYZDTYAF.module.min.js +0 -2
  488. package/dist/chunk-chunk-YHNZCPOZ.module.min.js +0 -2
  489. package/dist/chunk-chunk-YWZB3KPI.module.min.js +0 -2
  490. package/dist/chunk-statisticalOverlays-HMYYSGPE.module.min.js +0 -2
  491. package/dist/components/stream/test-utils/frameScheduler.d.ts +0 -12
  492. package/dist/components/stream/test-utils/revisionConsumption.d.ts +0 -13
  493. package/dist/test-utils/canvasMock.d.ts +0 -86
  494. package/dist/test-utils/capturedFrameProps.d.ts +0 -67
  495. package/dist/test-utils/frameMock.d.ts +0 -81
  496. package/dist/test-utils/ordinalFixtures.d.ts +0 -48
  497. /package/dist/{chunk-chunk-JJ2OOIET.module.min.js → c-GGISSW5E.min.js} +0 -0
  498. /package/dist/{chunk-chunk-SIRIJ3DY.module.min.js → c-N4G2L7ID.min.js} +0 -0
  499. /package/dist/{chunk-chunk-CA3YDW6F.module.min.js → c-S6U5CGT5.min.js} +0 -0
  500. /package/dist/components/recipes/{mobileAnnotationStrategy.d.ts → mobileAnnotationBehavior.d.ts} +0 -0
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- var e,t=Object.create,n=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,r,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))s.call(e,c)||c===r||n(e,c,{get:()=>t[c],enumerable:!(a=i(t,c))||a.enumerable});return e},c=(e,i,o)=>(o=null!=e?t(r(e)):{},a(!i&&e&&e.__esModule?o:n(o,"default",{value:e,enumerable:!0}),e)),l={};((e,t)=>{for(var i in t)n(e,i,{get:t[i],enumerable:!0})})(l,{BuiltInPhysicsEngineAdapter:()=>qi,ChainReactionChart:()=>Pp,CollisionSwarmChart:()=>Jc,CrucibleChart:()=>op,DEFAULT_CRUCIBLE_HEIGHT:()=>Wu,DEFAULT_CRUCIBLE_OUTLETS:()=>zu,DEFAULT_CRUCIBLE_SIZE:()=>qu,DEFAULT_CRUCIBLE_WIDTH:()=>Fu,EventDropChart:()=>Ec,GaltonBoardChart:()=>Pc,GauntletChart:()=>od,GuantletChart:()=>rd,PacketFlowChart:()=>vd,PhysicalFlowChart:()=>wd,PhysicsCustomChart:()=>Uc,PhysicsPileChart:()=>qc,PhysicsPipelineStore:()=>Oo,PhysicsSVGOverlay:()=>ni,PhysicsSedimentAccumulator:()=>Qi,ProcessFlowChart:()=>Dd,StreamPhysicsFrame:()=>gs,UnitPileChart:()=>Wc,absorbRegion:()=>fa,aggregateRegionCounts:()=>Zs,applyCrucibleEvent:()=>Bu,arrivalReplay:()=>pu,bodiesToAnnotationAnchors:()=>Jn,bodyGroupSpec:()=>ga,buildCollisionSwarmPhysics:()=>Ys,buildCrucibleEvidence:()=>Ou,buildCrucibleInitialSpawns:()=>lh,buildCrucibleLayout:()=>Zu,buildCruciblePhysicsConfig:()=>ih,buildCrucibleProductEvents:()=>tp,buildCrucibleProjection:()=>Tu,buildCrucibleStateSpawns:()=>ph,buildCrucibleTerminalSpawns:()=>mh,buildEventDropPhysics:()=>qs,buildGaltonBoardPhysics:()=>Os,buildPhysicalFlowPhysics:()=>Qs,buildPhysicsAnnotationContext:()=>ei,buildPhysicsPile:()=>Ls,buildProcessFlowPhysics:()=>va,calculateBlockerAmplification:()=>gp,capacitatedRegion:()=>pa,chargeGateRegion:()=>da,cloneCrucibleState:()=>xu,collidersFromScales:()=>lu,comparePhysicsTrace:()=>Vd,compileCruciblePlan:()=>vh,compileDependencyMachine:()=>hp,compileMotionEncoding:()=>il,compilePhysicsEncoding:()=>cl,composePhysicsControllers:()=>or,composeStyleRules:()=>Is,createCapacityQueueController:()=>Zo,createDefaultPhysicsEngineAdapter:()=>zi,createDependencyGateController:()=>nr,createInitialCrucibleState:()=>Ku,createLogicalJoin:()=>mp,createPhysicsEncodingLayout:()=>ll,createPortalController:()=>rr,createProcessJourneyLedger:()=>Ud,createServiceLevelController:()=>tr,createServiceResourcePoolController:()=>Jo,crucibleBondId:()=>sh,crucibleBoundaryColliders:()=>eh,crucibleComponentBodyId:()=>oh,crucibleProductBodyId:()=>rh,crucibleProjectionRows:()=>Eu,crucibleSemanticKey:()=>yh,default:()=>Dp,deriveMotionVector:()=>al,describePhysicsStageGeography:()=>iu,evaluateCrucibleConservation:()=>Nu,evaluatePhysicsBodyBudget:()=>eo,forceFieldRegion:()=>ya,galtonPegs:()=>du,groupCompletionRows:()=>ea,hatchFillId:()=>ae,hatchPatternDef:()=>le,isHatchFill:()=>re,makeRuleValueResolver:()=>xs,matchesThreshold:()=>ws,membraneRegion:()=>la,normalizePhysicsAnnotations:()=>ti,opacityFromAge:()=>rl,physicsChargePoint:()=>tu,physicsDestination:()=>eu,physicsProcessBoundaryColliders:()=>ul,physicsProcessGroupSemanticItems:()=>ml,physicsProcessRegionSemanticItem:()=>hl,physicsProcessStageSemanticItems:()=>pl,physicsReferenceEnvelope:()=>Ld,physicsStageColliders:()=>nu,physicsStageGeography:()=>Jd,planGauntletPropertyWork:()=>Fl,portalRegion:()=>ma,pressureFieldRegion:()=>ha,processChrome:()=>$d,processJourneyRows:()=>Qd,processLaneWalls:()=>ba,processStageLayout:()=>sa,processStageRegions:()=>ca,processVolumePolygons:()=>ia,regionCountsToProjectionRows:()=>Js,replaceGauntletNegative:()=>Wl,replayCruciblePlan:()=>xh,replayStateTransitions:()=>yp,resolveCrucibleSelector:()=>Iu,resolveCrucibleSnapshotAt:()=>bh,resolveCrucibleTime:()=>gh,resolveGauntletTerminalState:()=>sd,resolveGauntletTerminalStates:()=>ad,resolveMotionAccessor:()=>nl,resolveMotionAge:()=>ol,resolveMotionVector:()=>sl,resolveStyleRules:()=>Ms,resolveSvgFill:()=>de,routeDependencyTracks:()=>pp,routeSurfaceRegion:()=>ua,ruleMatches:()=>ks,sedimentBake:()=>hu,sedimentHeightfield:()=>Zi,spawnFromTokens:()=>uu,stageTargetInVolume:()=>na,updateProcessJourney:()=>Kd}),module.exports=(e=l,a(n({},"__esModule",{value:!0}),e));var d=require("react"),u=c(require("react")),h=require("react"),p=c(require("react")),m=require("react"),f=require("react"),y=require("react/jsx-runtime");function g(e){let t=null;const n=()=>(t||(t=(0,f.createContext)(null)),t),i=b(e);return[function({children:t,initialState:i}){const o=(0,f.useRef)(i),r=(0,f.useMemo)(()=>b(e,o.current),[]),s=n();return(0,y.jsx)(s.Provider,{value:r,children:t})},(e,t)=>{const o=n(),r=(0,f.useContext)(o)??i,s=(0,f.useRef)(e);s.current=e;const a=(0,f.useRef)({hasValue:!1,value:void 0}),c=(0,f.useCallback)(()=>{const e=s.current(r.getState()),n=a.current;return n.hasValue&&t&&t(n.value,e)?n.value:(a.current={hasValue:!0,value:e},e)},[r,t]),l=(0,f.useCallback)(()=>s.current(r.getState()),[r]);return(0,f.useSyncExternalStore)(r.subscribe,c,l)}]}function b(e,t){const n=new Set;let i={...e(function(e){const t=e(i);if(x(t)){i={...i,...t};for(const e of n)e()}}),...t??{}};return{getState:()=>i,subscribe:function(e){return n.add(e),()=>{n.delete(e)}}}}function x(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1}function v(e){if(!e.accessibility)return e;let t=e;if(e.accessibility.colorBlindSafe&&(t={...t,colors:{...t.colors,categorical:w}}),e.accessibility.highContrast){const e="dark"===t.mode;t={...t,colors:{...t.colors,text:e?"#ffffff":"#000000",textSecondary:e?"#cccccc":"#333333",grid:e?"#666666":"#999999",border:e?"#888888":"#000000"}}}return t}var w=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],k={mode:"light",colors:{primary:"#00a2ce",secondary:"#6c757d",categorical:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],sequential:"blues",diverging:"RdBu",background:"transparent",surface:"#ffffff",text:"#333",textSecondary:"#666",grid:"#e0e0e0",border:"#ccc",selection:"#00a2ce",selectionOpacity:.15,success:"#2ca02c",danger:"#d62728",warning:"#f0ad4e",error:"#b4181b",info:"#00a2ce"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},M={mode:"dark",colors:{primary:"#4fc3f7",secondary:"#90a4ae",categorical:["#4fc3f7","#ffb74d","#81c784","#ef5350","#ba68c8","#a1887f","#f06292","#90a4ae","#dce775","#4dd0e1"],sequential:"blues",diverging:"RdBu",background:"#1a1a2e",surface:"#252540",text:"#e0e0e0",textSecondary:"#aaa",grid:"#333",border:"#555",selection:"#4fc3f7",selectionOpacity:.15,success:"#81c784",danger:"#ef5350",warning:"#ffb74d",error:"#d84848",info:"#4fc3f7"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},I={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:w,sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#000000",textSecondary:"#333333",grid:"#999999",border:"#000000",focus:"#0000cc",selection:"#0000cc",selectionOpacity:.1,success:"#006400",danger:"#cc0000",warning:"#b15a00",error:"#8b0000",info:"#0000cc"},typography:{fontFamily:"system-ui, sans-serif",titleSize:18,labelSize:14,tickSize:12},tooltip:{background:"#000000",text:"#ffffff",borderRadius:"4px",fontSize:"14px",shadow:"0 2px 8px rgba(0, 0, 0, 0.3)"},borderRadius:"4px"};function S(e,t){if("light"===t)return k;if("dark"===t)return M;if("high-contrast"===t)return I;if("string"==typeof t)return void 0!==console&&console.warn(`[ThemeStore] Unknown theme preset "${t}". Keeping current theme.`),e;if(t.mode&&"auto"!==t.mode){const e="dark"===t.mode?M:k;return v({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}return v({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}var[j,A]=g(e=>({theme:k,setTheme(t){e(e=>({theme:S(e.theme,t)}))}})),C=require("react");function R(){const[e,t]=(0,C.useState)(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return(0,C.useEffect)(()=>{if("undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(prefers-reduced-motion: reduce)");return t(e.matches),function(e,t){if("function"==typeof e.addEventListener)return e.addEventListener("change",t),()=>e.removeEventListener("change",t);const n=e;return n.addListener(t),()=>n.removeListener(t)}(e,e=>t(e.matches))},[]),e}var $=require("react");function P(e,t,n){const i=(0,$.useRef)(null),[o,r]=(0,$.useState)(null);return(0,$.useEffect)(()=>{if(!t&&!n)return;const e=i.current;if(!e)return;const o=new ResizeObserver(e=>{for(const t of e){const{width:e,height:n}=t.contentRect;r(t=>t&&t.w===e&&t.h===n?t:{w:e,h:n})}});return o.observe(e),()=>o.disconnect()},[t,n]),[i,[t&&o?o.w:e[0],n&&o?o.h:e[1]]]}var D=new WeakMap,B=0,T=!1,E=null,N=null;function O(e,t){if(!t)return t;const n=function(e){const t=e.trim();if(!t.startsWith("var(")||!t.endsWith(")"))return null;const n=t.slice(4,-1),i=n.indexOf(",");if(-1===i){const e=n.trim();return e.startsWith("--")?{name:e}:null}const o=n.slice(0,i).trim(),r=n.slice(i+1).trim();return o.startsWith("--")?{name:o,fallback:r||void 0}:null}(t);if(!n)return t;const i=()=>n.fallback?O(e,n.fallback):t,o=e.canvas;if(!o)return i();!function(){if(T)return;if("undefined"==typeof window||"undefined"==typeof document)return;T=!0;const e=()=>{B++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(e).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"],subtree:!0}),"function"==typeof window.matchMedia)try{E=window.matchMedia("(prefers-color-scheme: dark)"),N=e,"function"==typeof E.addEventListener?E.addEventListener("change",N):"function"==typeof E.addListener&&E.addListener(N)}catch{}}();let r=D.get(o);r&&r.version===B||(r={version:B,map:new Map},D.set(o,r));const s=r.map.get(t);if(void 0!==s)return s;const a=getComputedStyle(o).getPropertyValue(n.name).trim()||i()||t;return r.map.set(t,a),a}var F=()=>"undefined"!=typeof performance?performance.now():Date.now();function W(e,t){const n=e();return Number.isFinite(n)?n:t}var q=class{constructor(e={}){this.randomSource=Math.random,this.subscribers=new Set,this.now=()=>this.advance(),this.random=()=>this.randomSource(),this.clock=e.clock??F,this.lastWallTime=W(this.clock,0),this.logicalTime=this.lastWallTime,this.pausedValue=!0===e.paused,this.visibleValue=!1!==e.visible,this.setRandomSource(e.random,e.seed)}get isActive(){return!this.pausedValue&&this.visibleValue}get paused(){return this.pausedValue}get seed(){return this.seedValue}get visible(){return this.visibleValue}configure(e){this.setClock(e.clock),this.setRandomSource(e.random,e.seed)}setPaused(e){this.pausedValue!==e&&(this.advance(),this.pausedValue=e,this.emit())}setVisible(e){this.visibleValue!==e&&(this.advance(),this.visibleValue=e,this.emit())}snapshot(){return{now:this.now(),paused:this.pausedValue,seed:this.seedValue,visible:this.visibleValue}}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}advance(){const e=W(this.clock,this.lastWallTime),t=Math.max(0,e-this.lastWallTime);return this.lastWallTime=e,this.isActive&&(this.logicalTime+=t),this.logicalTime}emit(){for(const e of this.subscribers)e()}setClock(e){const t=e??F;t!==this.clock&&(this.advance(),this.clock=t,this.lastWallTime=W(t,this.lastWallTime))}setRandomSource(e,t){const n=function(e){return"number"==typeof e&&Number.isFinite(e)?Math.trunc(e):void 0}(t);e===this.randomInput&&n===this.seedValue||(this.randomInput=e,this.seedValue=n,this.randomSource=e??(void 0===n?Math.random:function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(n)))}},z="undefined"==typeof window?m.useEffect:m.useLayoutEffect,L={requestAnimationFrame:e=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(e),cancelAnimationFrame:e=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(e)};function H(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}var Y=require("react"),_="undefined"!=typeof window?Y.useLayoutEffect:Y.useEffect,G=()=>()=>{},V=()=>!1,X=()=>!0;function U(){const e=(0,Y.useSyncExternalStore)(G,V,X);return(0,Y.useRef)(e).current}var K=require("react");var Q=require("react/jsx-runtime");function Z(e){const{cancelRender:t,dirtyRef:n,frameRuntime:i,manageFrameRuntime:o,maxDevicePixelRatio:r,scheduleRender:s}=e,a=(0,K.useRef)(null),c=(0,K.useRef)(null),l=(0,K.useRef)(!1),d=(0,K.useRef)(!1),u=(0,K.useRef)(!1);return function(e){const{hydrated:t,wasHydratingFromSSR:n,storeRef:i,dirtyRef:o,renderFnRef:r,cancelRender:s,cleanup:a}=e;_(()=>{const e=i.current;t&&n&&e?.cancelIntroAnimation?.(),!n&&e?.sceneNodes&&e.sceneNodes.length>0&&e?.markStylePaintPending?e.markStylePaintPending():o.current=!0,s?.(),r.current()},[t,n]);const c=(0,Y.useRef)(a);c.current=a,(0,Y.useEffect)(()=>()=>c.current?.(),[])}({hydrated:e.hydrated,wasHydratingFromSSR:e.wasHydratingFromSSR,storeRef:e.storeRef,dirtyRef:e.dirtyRef,renderFnRef:e.renderFnRef,cancelRender:e.cancelRender,cleanup:e.cleanup}),(0,K.useEffect)(()=>{if(!1!==o)return i.subscribe(()=>{i.isActive?(n.current=!0,s()):t()})},[t,n,i,o,s]),(0,K.useEffect)(()=>function(){if("undefined"==typeof window||"function"!=typeof window.matchMedia)return()=>{};let e=null,t=!1;const n=()=>{e&&("function"==typeof e.removeEventListener?e.removeEventListener("change",o):"function"==typeof e.removeListener&&e.removeListener(o))},i=()=>{const t=`(resolution: ${window.devicePixelRatio||1}dppx)`;e=window.matchMedia(t),e.media.includes("resolution")?"function"==typeof e.addEventListener?e.addEventListener("change",o):"function"==typeof e.addListener&&e.addListener(o):e=null};function o(){t||(n(),e=null,l.current=!0,s(),queueMicrotask(()=>{t||i()}))}return i(),()=>{t=!0,n(),e=null}}(),[s]),(0,K.useEffect)(()=>{u.current?(l.current=!0,s()):u.current=!0},[r,s]),(0,K.useEffect)(()=>{!d.current&&(d.current=!0,e.skipInitialCanvasPaintInvalidation)||(e.canvasPaintInvalidator?e.canvasPaintInvalidator():e.dirtyRef.current=!0,e.scheduleRender())},e.canvasPaintDependencies),{canvasRef:a,interactionCanvasRef:c,resolutionDirtyRef:l}}function J({children:e,size:t,margin:n,overflowVisible:i=!1}){return e?(0,Q.jsx)("svg",{style:{position:"absolute",left:0,top:0,width:t[0],height:t[1],pointerEvents:"none",overflow:i?"visible":void 0},children:(0,Q.jsx)("g",{transform:`translate(${n.left},${n.top})`,children:e})}):null}var ee=c(require("react")),te=require("d3-shape");function ne(e){return{type:"hatch",background:e.background,stroke:e.stroke,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle}}var ie=null;var oe=require("react/jsx-runtime");function re(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function se(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}function ae(e,t){let n=2166136261;const i=se(t);for(let e=0;i.length>e;e++)n^=i.charCodeAt(e),n=Math.imul(n,16777619);return`${e}-hatch-${(n>>>0).toString(36)}`}var ce=new Map;function le(e,t){const{background:n="transparent",stroke:i="#000",lineWidth:o=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=e,c=Math.max(8,Math.ceil(2*r));return(0,oe.jsxs)("pattern",{id:t,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[n&&"transparent"!==n&&(0,oe.jsx)("rect",{width:c,height:c,fill:n}),(0,oe.jsx)("line",{x1:0,y1:0,x2:0,y2:c,stroke:i,strokeWidth:o,strokeOpacity:a}),(0,oe.jsx)("line",{x1:r,y1:0,x2:r,y2:c,stroke:i,strokeWidth:o,strokeOpacity:a})]},t)}function de(e,t,n="#4e79a7"){if(re(e)){const n=ae(t,e);return{fill:`url(#${n})`,def:le(e,n)}}return e&&"string"==typeof e?{fill:e}:{fill:n}}var ue=require("d3-shape");function he(e){switch(e){case"monotoneX":return ue.curveMonotoneX;case"monotoneY":return ue.curveMonotoneY;case"cardinal":return ue.curveCardinal;case"catmullRom":return ue.curveCatmullRom;case"step":return ue.curveStep;case"stepBefore":return ue.curveStepBefore;case"stepAfter":return ue.curveStepAfter;case"basis":return ue.curveBasis;case"natural":return ue.curveNatural;default:return null}}function pe(e,t,n){if(null==t)return n;if(re(t)){const i=function(e,t){const n=e.background??"transparent",i=e.stroke??"#000",o="transparent"===n||"none"===n?n:O(t,n)||n,r=O(t,i)||i||"#000",s="undefined"!=typeof window&&window.devicePixelRatio||1,a=`${se(e)}|${o}|${r}@${s}`,c=ce.get(a);if(void 0!==c)return c;const l=function(e={},t){const{background:n="transparent",stroke:i="#000",lineWidth:o=1.5,spacing:r=6,angle:s=45}=e,a={background:n,stroke:i,lineWidth:o,spacing:r,angle:s},c=Math.max(8,Math.ceil(2*r));let l;try{l=function(e){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(e,e):(ie||(ie=document.createElement("canvas")),ie.width=e,ie.height=e,ie)}(c)}catch{return ne(a)}const d=l.getContext("2d");if(!d)return ne(a);n&&"transparent"!==n?(d.fillStyle=n,d.fillRect(0,0,c,c)):d.clearRect(0,0,c,c),d.strokeStyle=i,d.lineWidth=o,d.lineCap="square";const u=s*Math.PI/180;if(45===s||-45===s){const e=s>0?1:-1;for(let t=-c;2*c>=t;t+=r)d.beginPath(),d.moveTo(t,0),d.lineTo(t+e*c,c),d.stroke()}else{d.save(),d.translate(c/2,c/2),d.rotate(u);const e=2*c;for(let t=-e;e>=t;t+=r)d.beginPath(),d.moveTo(-e,t),d.lineTo(e,t),d.stroke();d.restore()}return(t||d).createPattern(l,"repeat")}({background:o,stroke:r,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle},t),d=re(l)?null:l;return ce.set(a,d),d}(t,e);return i||t.background&&O(e,t.background)||n}return"string"!=typeof t?t:O(e,t)||n}function me(e,t){if(null==t)return;const n=pe(e,t,"");return""===n?void 0:n}function fe(e,t,n){let i=n;for(const n of t)"lesser"===n.thresholdType?n.value>e&&(i=n.color):e>n.value&&(i=n.color);return i}var ye=[40,40],ge=[.5,.5];function be(e,t,n,i){if("none"!==e)return"color"===e||null==e?t??i:"accent"===e?n:e}var xe=require("d3-shape"),ve={circle:xe.symbolCircle,square:xe.symbolSquare,triangle:xe.symbolTriangle,diamond:xe.symbolDiamond,star:xe.symbolStar,cross:xe.symbolCross,wye:xe.symbolWye};var we=require("react/jsx-runtime");function ke(e,t="#4e79a7"){return re(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function Me(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"s_"+t:t}function Ie(e,t){const n=e.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity))).map(e=>({offset:Math.max(0,Math.min(1,e.offset)),color:e.color??t,opacity:null==e.opacity?void 0:Math.max(0,Math.min(1,e.opacity))}));return 2>n.length?null:n.map((e,t)=>(0,we.jsx)("stop",{offset:e.offset,stopColor:e.color,stopOpacity:e.opacity},t))}var Se=require("react/jsx-runtime");function je(e,t,n,i){if(!e||2>t.length)return null;const o=Ie(e.stops,i);return o?(0,Se.jsx)("linearGradient",{id:n,gradientUnits:"userSpaceOnUse",x1:t[0][0],y1:0,x2:t[t.length-1][0],y2:0,children:o}):null}function Ae(e,t,n){switch(e.type){case"line":{const i=e;if(0===i.path.length)return null;const o=he(i.curve),r=o?(0,te.line)().x(([e])=>e).y(([,e])=>e).curve(o)(i.path)??"":"M"+i.path.map(([e,t])=>`${e},${t}`).join("L"),s=Me(`${n?n+"-":""}line-${t}-stroke-gradient`),a=je(i.strokeGradient,i.path,s,i.style.stroke||"#4e79a7");return(0,Se.jsxs)(ee.Fragment,{children:[a&&(0,Se.jsx)("defs",{children:a}),(0,Se.jsx)("path",{d:r,fill:"none",stroke:a?`url(#${s})`:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth||2,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity})]},"line-"+t)}case"area":{const i=e;if(0===i.topPath.length)return null;const o=he(i.curve),r=!o||2>i.topPath.length||2>i.bottomPath.length?`M${i.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...i.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`:(0,te.area)().x(([e])=>e).y0((e,t)=>i.bottomPath[t][1]).y1(([,e])=>e).curve(o)(i.topPath)??"",s=`${n?n+"-":""}area-${t}-hatch`,a=re(i.style.fill)?le(i.style.fill,s):void 0,c=Me(`${n?n+"-":""}area-${t}-gradient`),l=function(e,t){const n=e.fillGradient;if(!n||"object"!=typeof n)return null;let i=1/0;for(const[,t]of e.topPath)i=Math.min(i,t);let o=-1/0;for(const[,t]of e.bottomPath)o=Math.max(o,t);if(!Number.isFinite(i)||!Number.isFinite(o))return null;const r=Ie(n.stops,ke(e.style.fill));return r?(0,Se.jsx)("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:0,y1:i,x2:0,y2:o,children:r}):null}(i,c),d=l?`url(#${c})`:a?`url(#${s})`:ke(i.style.fill),u=l?void 0:i.style.fillOpacity??i.style.opacity??.7,h=o?(0,te.line)().x(([e])=>e).y(([,e])=>e).curve(o)(i.topPath)??"":"M"+i.topPath.map(([e,t])=>`${e},${t}`).join("L"),p=Me(`${n?n+"-":""}area-${t}-stroke-gradient`),m=!(!i.colorThresholds?.length||!i.rawValues||i.rawValues.length!==i.topPath.length),f=!!i.strokeColorBands?.length,y=m||f?null:je(i.strokeGradient,i.topPath,p,i.style.stroke||"#4e79a7"),g=i.style.strokeWidth||2;let b=1/0,x=-1/0;for(const[e]of i.topPath)b>e&&(b=e),e>x&&(x=e);const v=f?i.strokeColorBands.map((e,i)=>Me(`${n?n+"-":""}area-${t}-stroke-band-${i}`)):[],w=f?i.strokeColorBands.map((e,t)=>(0,Se.jsx)("clipPath",{id:v[t],children:(0,Se.jsx)("rect",{x:b-g,y:e.y,width:x-b+2*g,height:e.height})},v[t])):null,k=i.style.stroke&&"none"!==i.style.stroke?f?i.strokeColorBands.map((e,n)=>(0,Se.jsx)("path",{d:h,fill:"none",stroke:e.color??ke(i.style.stroke),strokeWidth:g,opacity:i.style.opacity,clipPath:`url(#${v[n]})`},`area-${t}-stroke-band-${n}`)):m?function(e,t,n,i){if(2>e.length||t.length!==e.length||0===n.length)return[];const o=[],r=(e,t,n)=>{const i=o[o.length-1];i?.color===e?i.path.push(n):o.push({color:e,path:[t,n]})};for(let o=1;e.length>o;o++){const[s,a]=e[o-1],[c,l]=e[o],d=t[o-1],u=t[o]-d,h=[0,...0===u?[]:n.map(({value:e})=>(e-d)/u).filter(e=>e>0&&1>e&&Number.isFinite(e)).sort((e,t)=>e-t).filter((e,t,n)=>0===t||e!==n[t-1]),1];for(let e=1;h.length>e;e++){const t=h[e-1],o=h[e];r(fe(d+u*((t+o)/2),n,i),[s+(c-s)*t,a+(l-a)*t],[s+(c-s)*o,a+(l-a)*o])}}return o}(i.topPath,i.rawValues,i.colorThresholds,ke(i.style.stroke)).map((e,n)=>(0,Se.jsx)("path",{d:"M"+e.path.map(([e,t])=>`${e},${t}`).join("L"),fill:"none",stroke:e.color,strokeWidth:g,opacity:i.style.opacity},`area-${t}-threshold-${n}`)):(0,Se.jsx)("path",{d:h,fill:"none",stroke:y?`url(#${p})`:ke(i.style.stroke),strokeWidth:g,opacity:i.style.opacity}):null;if(i.clipRect){const e=`${n?n+"-":""}area-clip-${t}`;return(0,Se.jsxs)("g",{children:[(0,Se.jsxs)("defs",{children:[l,!l&&a,y,w,(0,Se.jsx)("clipPath",{id:e,children:(0,Se.jsx)("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),(0,Se.jsxs)("g",{clipPath:`url(#${e})`,children:[(0,Se.jsx)("path",{d:r,fill:d,fillOpacity:u,opacity:l?i.style.opacity:void 0,stroke:"none"}),k]})]},"area-"+t)}return(0,Se.jsxs)(ee.Fragment,{children:[(l||a||y||w)&&(0,Se.jsxs)("defs",{children:[l,!l&&a,y,w]}),(0,Se.jsx)("path",{d:r,fill:d,fillOpacity:u,opacity:l?i.style.opacity:void 0,stroke:"none"}),k]},"area-"+t)}case"point":{const i=e,o=`${n?n+"-":""}point-${t}-hatch`,r=re(i.style.fill)?le(i.style.fill,o):void 0;return(0,Se.jsxs)(ee.Fragment,{children:[r&&(0,Se.jsx)("defs",{children:r}),(0,Se.jsx)("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#${o})`:ke(i.style.fill),opacity:i.style.opacity??i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"point-"+t)}case"symbol":return function(e,t){const n=function(e,t,n){if(n)return n;const i=e??"circle";return"chevron"===i?function(e){const t=1.5*function(e){return Math.sqrt(Math.max(1,e)/Math.PI)}(e),n=.92*t;return`M0,${-t}L${n},${(.78*t).toFixed(3)}L0,${(.28*t).toFixed(3)}L${-n},${(.78*t).toFixed(3)}Z`}(t):(0,xe.symbol)(ve[i]??xe.symbolCircle,Math.max(1,t))()??""}(e.symbolType,e.size,e.path);return(0,we.jsx)("path",{d:n,transform:e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`,fill:e.style.fill?ke(e.style.fill):"none",fillOpacity:e.style.fillOpacity,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},"symbol-"+t)}(e,t);case"glyph":return function(e,t,n,i){const o=e.glyph;if(!o?.parts?.length||0>=e.size)return null;const r=function(e,t){const[n,i]=e.viewBox??ye,[o,r]=e.anchor??ge,s=i>0?i:1,a=Math.max(0,t)/s,c=(n>0?n:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-o*c,offsetY:-r*l}}(o,e.size);if(0>=r.scale)return null;const s=`translate(${t},${n})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),c=function(e,t,n=0,i="horizontal"){const[o,r]=e.viewBox??ye,s=Math.min(1,Math.max(0,n)),a=Math.min(1,Math.max(0,t));return a>s?s>0||1>a?"vertical"===i?{x:0,y:r*(1-a),width:o,height:r*(a-s)}:{x:o*s,y:0,width:o*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}(o,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),l=c?Me(i+"-clip"):void 0,d=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),u=t=>o.parts.map((n,i)=>{const o=t?"none"===n.fill?void 0:t:be(n.fill,a,e.accent),r=t?n.stroke&&"none"!==n.stroke?t:void 0:be(n.stroke??"none",a,e.accent);return o||r?(0,we.jsx)("path",{d:n.d,fill:o??"none",stroke:r,strokeWidth:r?n.strokeWidth??1:void 0,strokeLinecap:n.strokeLinecap,strokeLinejoin:n.strokeLinejoin,opacity:n.opacity},i):null});return(0,we.jsxs)("g",{transform:s,opacity:1===d?void 0:d,children:[c&&l&&(0,we.jsx)("clipPath",{id:l,children:(0,we.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&e.ghostColor?(0,we.jsx)("g",{children:u(e.ghostColor)}):null,c&&l?(0,we.jsx)("g",{clipPath:`url(#${l})`,children:u()}):u()]},i)}(e,e.x,e.y,`${n??""}glyph-${e.pointId??t}`);case"rect":{const i=e,o=`${n?n+"-":""}xyrect-${t}-hatch`,r=re(i.style.fill)?le(i.style.fill,o):void 0;return(0,Se.jsxs)(ee.Fragment,{children:[r&&(0,Se.jsx)("defs",{children:r}),(0,Se.jsx)("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:r?`url(#${o})`:ke(i.style.fill),opacity:i.style.opacity,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"rect-"+t)}case"heatcell":{const n=e,i={x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill,stroke:n.style?.stroke,strokeWidth:n.style?.strokeWidth,...null!=n.style?.opacity&&{opacity:n.style.opacity}};if(n.showValues&&null!=n.value&&n.w>=20&&n.h>=20){const e=n.valueFormat?n.valueFormat(n.value):Number.isInteger(n.value)?n.value+"":100>Math.abs(n.value)?1>Math.abs(n.value)?n.value.toPrecision(3):n.value.toFixed(1):n.value.toFixed(0),[o,r,s]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(n.fill),a=.299*o+.587*r+.114*s>128?"#000":"#fff",c=Math.max(10,Math.min(16,.3*Math.min(n.w,n.h)));return(0,Se.jsxs)("g",{children:[(0,Se.jsx)("rect",{...i}),(0,Se.jsx)("text",{x:n.x+n.w/2,y:n.y+n.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:c+"px",children:e})]},"heatcell-"+t)}return(0,Se.jsx)("rect",{...i},"heatcell-"+t)}case"candlestick":{const n=e;if(n.isRange){const e=n.dotRadius??Math.max(2,n.bodyWidth/2);return(0,Se.jsxs)("g",{children:[(0,Se.jsx)("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),(0,Se.jsx)("circle",{cx:n.x,cy:n.highY,r:e,fill:n.wickColor}),(0,Se.jsx)("circle",{cx:n.x,cy:n.lowY,r:e,fill:n.wickColor})]},"candle-"+t)}const i=Math.min(n.openY,n.closeY),o=Math.max(Math.abs(n.openY-n.closeY),1),r=n.isUp?n.upColor:n.downColor;return(0,Se.jsxs)("g",{children:[(0,Se.jsx)("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),(0,Se.jsx)("rect",{x:n.x-n.bodyWidth/2,y:i,width:n.bodyWidth,height:o,fill:r,stroke:r,strokeWidth:1})]},"candle-"+t)}default:return null}}var Ce="undefined"==typeof window||"undefined"==typeof document,Re=c(require("react")),$e=["name","label","title"],Pe=["type","kind","category","group","class","status","role","shape"],De=["value","amount","total","count","weight","score"],Be=new Set(["x","y","z","x0","x1","y0","y1","r","cx","cy","radius","layer","row","rowindex","col","column","depth","index","order","sankeywidth","coincidentpoints","sourcelinks","targetlinks","parent","children","fx","fy","vx","vy"]);function Te(e,t){for(const n of t){const t=e.find(e=>e.lower===n);if(t)return t}}var Ee=require("react/jsx-runtime"),Ne={background:"var(--semiotic-tooltip-bg, rgba(0, 0, 0, 0.85))",color:"var(--semiotic-tooltip-text, white)",padding:"8px 12px",borderRadius:"var(--semiotic-tooltip-radius, 6px)",fontSize:"var(--semiotic-tooltip-font-size, 14px)",fontFamily:"var(--semiotic-font-family, inherit)",lineHeight:"1.5",boxShadow:"var(--semiotic-tooltip-shadow, 0 2px 8px rgba(0, 0, 0, 0.15))",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Oe(e,t){return"function"==typeof t?t(e):e[t]}function Fe(e,t){if(t)return t(e);if(null==e)return"";if("number"==typeof e){if(!Number.isFinite(e))return e+"";const t=Number.isInteger(e)?e:parseFloat(e.toPrecision(6));return Math.abs(t)>9999?t.toLocaleString():t+""}return e instanceof Date?e.toLocaleDateString():"object"==typeof e&&null!==e?void 0!==e.id?e.id+"":void 0!==e.name?e.name+"":JSON.stringify(e):e+""}function We(e={}){const{fields:t,title:n,format:i,style:o={},className:r=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let s;const a=[];if(n){const t=Oe(e,n);s=Fe(t,i)}if(t&&t.length>0)t.forEach(t=>{let n,o,r;"string"==typeof t?(n=t,o=t,r=i):(n=t.label,o=t.accessor||t.key||"",r=t.format||i);const s=Oe(e,o);a.push({label:n,value:Fe(s,r)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){s=Fe(e[n],i);break}if(!s){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(s=Fe(e[t[0]],i))}}const c={...Ne,...o};return(0,Ee.jsxs)("div",{className:("semiotic-tooltip "+r).trim(),style:c,children:[s&&(0,Ee.jsx)("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((e,t)=>(0,Ee.jsxs)("div",{style:{marginTop:0===t&&s?"4px":0},children:[e.label&&(0,Ee.jsxs)("span",{children:[e.label,": "]}),e.value]},t))]})}}function qe(e){if(!0!==e){if("function"==typeof e){const t=e;return e=>{const n=!0===e?.__semioticHoverData||e&&void 0!==e.data&&"number"==typeof e.x&&"number"==typeof e.y&&e&&("node"===e.type||"edge"===e.type||void 0!==e.nodeOrEdge||void 0!==e.allSeries||void 0!==e.stats||void 0!==e.__chartType);let i=Array.isArray(o=n?e.data??{}:e)?o[0]:o;var o;if(!i)return null;if(("node"===e?.nodeOrEdge&&"number"==typeof i?.x0&&"number"==typeof i?.x1||"edge"===e?.nodeOrEdge&&"number"==typeof i?.sankeyWidth)&&i.data&&"object"==typeof i.data&&(i=i.data),!i)return null;if(n&&(void 0!==e.allSeries||void 0!==e.xValue)){const t={...i};void 0!==e.allSeries&&void 0===t.allSeries&&(t.allSeries=e.allSeries),void 0!==e.xValue&&void 0===t.xValue&&(t.xValue=e.xValue),i=t}const r=t(i);return null==r?null:(0,Ee.jsx)("div",{className:"semiotic-tooltip",style:Ne,children:r})}}return!1!==e&&void 0!==e&&(function(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)&&"mode"in e&&"multi"===e.mode}(e)?"function"==typeof e.content?qe(e.content):("undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&console.warn('[semiotic] tooltip={{ mode: "multi" }} reached normalizeTooltip without a chart that wires tooltipMode. Prefer LineChart/AreaChart/StackedAreaChart/DifferenceChart, or pass frameProps.tooltipMode: "multi".'),e=>{const t=e.allSeries;if(!t||0===t.length)return(0,Ee.jsx)("div",{className:"semiotic-tooltip",style:Ne,children:(0,Ee.jsx)("div",{children:Fe(e.data?.value??e.data?.y)})});const n=e.xValue??e.data?.time??e.data?.x;return(0,Ee.jsxs)("div",{className:"semiotic-tooltip",style:Ne,children:[null!=n&&(0,Ee.jsx)("div",{style:{fontWeight:600,marginBottom:4,fontSize:"0.9em",borderBottom:"1px solid var(--semiotic-border, #eee)",paddingBottom:4},children:Fe(n)}),t.map((e,t)=>(0,Ee.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"1px 0"},children:[(0,Ee.jsx)("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:e.color,flexShrink:0}}),(0,Ee.jsx)("span",{style:{flex:1,fontSize:"0.85em"},children:e.group}),(0,Ee.jsx)("span",{style:{fontWeight:500,fontSize:"0.85em"},children:Fe(e.value)})]},t))]})}):"object"==typeof e&&null!==e&&("fields"in e||"title"in e)?We(e):"multi"===e?("undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&console.warn('[semiotic] tooltip="multi" reached normalizeTooltip — prefer charts that set tooltipMode (LineChart, AreaChart, StackedAreaChart, DifferenceChart). Rendering MultiLineTooltip content as a fallback.'),function(e={}){const{fields:t=[],title:n,format:i,style:o={},className:r="",showLabels:s=!0,separator:a=": "}=e;return e=>{if(!e||"object"!=typeof e)return null;const c=[];if(n){const t=Oe(e,n);c.push({value:Fe(t,i)})}if(t&&Array.isArray(t)&&t.length>0)t.forEach(t=>{let n,o,r;"string"==typeof t?(n=t,o=t,r=i):(n=t.label,o=t.accessor||t.key||"",r=t.format||i);const a=Fe(Oe(e,o),r);c.push({label:s?n:void 0,value:a})});else{const t=function(e,t={}){if(!e||"object"!=typeof e)return{entries:[]};const n=t.maxEntries??6,i=!1!==t.skipPositional,o=[];for(const[t,n]of Object.entries(e)){if(t.startsWith("_"))continue;if("data"===t)continue;if(i&&Be.has(t.toLowerCase()))continue;if(null==n)continue;const e=typeof n;("string"===e||"number"===e||"boolean"===e||n instanceof Date)&&o.push({key:t,lower:t.toLowerCase(),value:n})}if(0===o.length)return{entries:[]};let r=o.findIndex(e=>$e.includes(e.lower));const s=r>=0;0>r&&(r=o.findIndex(e=>"id"===e.lower)),0>r&&(r=o.findIndex(e=>"string"==typeof e.value));const a=0>r?void 0:o[r];let c=o.filter((e,t)=>t!==r);s&&(c=c.filter(e=>"id"!==e.lower));const l=Te(c,Pe),d=Te(c,De),u=new Set(Pe),h=new Set(De),p=[];l&&p.push({key:l.key,value:l.value}),d&&p.push({key:d.key,value:d.value});for(const e of c){if(p.length>=n)break;e!==l&&e!==d&&(u.has(e.lower)||h.has(e.lower)||p.push({key:e.key,value:e.value}))}return{titleKey:a?.key,title:a?.value,entries:p}}(e,{skipPositional:!1});null!=t.title&&c.push({label:void 0,value:Fe(t.title,i),bold:!0}),t.entries.forEach(e=>{c.push({label:s?e.key:void 0,value:Fe(e.value,i)})})}const l={...Ne,...o};return Array.isArray(c)&&0!==c.length?(0,Ee.jsx)("div",{className:("semiotic-tooltip semiotic-tooltip-multiline "+r).trim(),style:l,children:c.map((e,t)=>(0,Ee.jsxs)("div",{style:{marginBottom:c.length-1>t?"4px":0,fontWeight:e.bold?"bold":void 0},children:[e.label&&(0,Ee.jsxs)("strong",{children:[e.label,a]}),e.value]},t))}):null}}()):We())}}var ze=require("react/jsx-runtime");function Le({x:e,y:t,containerWidth:n,containerHeight:i,margin:o,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const c=Number.isFinite(e)&&Number.isFinite(t),l=Re.useRef(null),[d,u]=Re.useState(null);Re.useLayoutEffect(()=>{const e=l.current;if(!e)return;const t=()=>{const t=e.getBoundingClientRect();Number.isFinite(t.width)&&Number.isFinite(t.height)&&u(e=>e&&.5>Math.abs(e.width-t.width)&&.5>Math.abs(e.height-t.height)?e:{width:t.width,height:t.height})};if(t(),"undefined"==typeof ResizeObserver)return;const n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[s,n,i,c]);let h;h=d?`translate(${d.width+12>n-e?"calc(-100% - 12px)":"12px"}, ${d.height+12>i-t?"calc(-100% - 4px)":"4px"})`:`translate(${e>.7*n?"calc(-100% - 12px)":"12px"}, ${.3*i>t?"4px":"calc(-100% - 4px)"})`;const p=function(e){if(!Re.isValidElement(e))return!1;const t=e.type;if("string"!=typeof t&&t&&!0===t.ownsChrome)return!0;const n=e.props;if(!0===n["data-semiotic-tooltip-chrome"])return!0;if("true"===n["data-semiotic-tooltip-chrome"])return!0;const i=n.style;if(i&&"object"==typeof i){if(null!=i.background&&""!==i.background&&"transparent"!==i.background)return!0;if(null!=i.backgroundColor&&""!==i.backgroundColor&&"transparent"!==i.backgroundColor)return!0}return!1}(r),m=p?null:Ne;return c?(0,ze.jsx)("div",{ref:l,className:p?s:(s+" semiotic-tooltip").trim(),style:{...m||{},position:"absolute",left:o.left+e,top:o.top+t,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:r}):null}var He={names:["--semiotic-bg","--surface-1","--surface-0"],fallback:"#f8fafc"},Ye={names:["--semiotic-border","--surface-3"],fallback:"#334155"},_e={names:["--semiotic-danger","--viz-4"],fallback:"#dc2626"},Ge={names:["--semiotic-focus","--accent","--viz-9"],fallback:"#f97316"},Ve={names:["--semiotic-grid","--surface-3"],fallback:"#cbd5e1"},Xe={names:["--semiotic-primary","--accent","--viz-5"],fallback:"#0ea5e9"},Ue={names:["--semiotic-success","--viz-2"],fallback:"#22c55e"},Ke={names:["--semiotic-text","--text-primary"],fallback:"#0f172a"},Qe={names:["--semiotic-text-secondary","--text-secondary"],fallback:"#475569"},Ze={names:["--semiotic-warning","--viz-9","--viz-3"],fallback:"#f97316"};function Je(e,t){const n=e.canvas;if("function"!=typeof getComputedStyle||!n)return t.fallback;const i=getComputedStyle(n);for(const n of t.names){const t=i.getPropertyValue(n).trim();if(t)return O(e,t)??t}return t.fallback}function et(e,t){const n=Math.max(0,Math.min(1,t)),i=e.trim(),o=i.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);if(o){const[,e,t,i]=o;return et(`#${e}${e}${t}${t}${i}${i}`,n)}const r=i.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(r){const[,e,t,i]=r;return`rgba(${parseInt(e,16)}, ${parseInt(t,16)}, ${parseInt(i,16)}, ${n})`}const s=i.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);if(s)return`rgba(${s[1]}, ${n})`;const a=i.match(/^rgba\s*\(\s*([^,]+,\s*[^,]+,\s*[^,]+),\s*[^)]+\)$/i);return a?`rgba(${a[1]}, ${n})`:i}var tt=c(require("react")),nt=require("d3-scale"),it=c(require("react"));function ot(e){return"object"==typeof e&&null!==e&&"legendGroups"in e&&Array.isArray(e.legendGroups)}function rt(e){return"object"==typeof e&&null!==e&&"gradient"in e}var st=16,at=6,ct=10,lt=22,dt=100,ut=10;function ht(e){return Math.ceil(7*e.length)}var pt=22,mt=46,ft=64;function yt(e,t){return null!=t?.axisGutter?Math.max(0,t.axisGutter):e?.hasAxis?e.hasAxisLabel?e.rotatedTicks?ft:mt:pt:0}function gt(e){const t=Math.max(1,e?.swatchSize??st),n=Math.max(t,e?.rowHeight??lt);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??at),itemGap:Math.max(0,e?.itemGap??ct),rowHeight:n,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}var bt=require("react/jsx-runtime"),xt={fill:(e,t)=>(0,bt.jsx)("rect",{style:e,width:t,height:t}),line:(e,t)=>(0,bt.jsx)("line",{style:e,x1:0,y1:0,x2:t,y2:t})};function vt(e,t,n,i,o){let r;return r="function"==typeof n?n(e):(0,xt[n])(i(e,t),o),r}function wt({swatchSize:e}){return(0,bt.jsx)("path",{d:`M${.25*e},${.55*e} L${.45*e},${.75*e} L${.8*e},${.3*e}`,fill:"none",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}function kt(e,t,n){return n&&n.size>0?n.has(e.label)?1:.3:null!=t?e.label===t?1:.3:1}var Mt=(e,t,n,i,o,r,s,a,c,l,d)=>{const{type:u="fill",styleFn:h,items:p}=e,m=[];let f=0;const y=!(!t&&!n),g="isolate"===l||void 0===l&&null!=o,{swatchSize:b,labelGap:x,rowHeight:v}=d;return p.forEach((e,l)=>{const d=vt(e,l,u,h,b),w=kt(e,i,o),k=o&&o.size>0&&o.has(e.label);m.push((0,bt.jsxs)("g",{transform:`translate(0,${f})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:y?a===r&&l===s?0:-1:void 0,role:y?"option":void 0,"aria-selected":y&&g?k||!1:void 0,"aria-current":y&&!g&&null!=i&&e.label===i||void 0,"aria-label":e.label,onKeyDown:y?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),t&&t(e)),"ArrowDown"===n.key||"ArrowUp"===n.key){n.preventDefault();const e=(l+("ArrowDown"===n.key?1:-1)+p.length)%p.length;c(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:y?t=>{c(a,l),n&&n(e);const i=t.currentTarget.querySelector(".semiotic-legend-focus-ring");i&&i.setAttribute("visibility","visible")}:void 0,onBlur:y?e=>{n&&n(null);const t=e.currentTarget.querySelector(".semiotic-legend-focus-ring");t&&t.setAttribute("visibility","hidden")}:void 0,style:{cursor:y?"pointer":"default",opacity:w,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[y&&(0,bt.jsx)("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:b+x+2+7*e.label.length,height:b+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),d,k&&(0,bt.jsx)(wt,{swatchSize:b}),(0,bt.jsx)("text",{y:b/2,x:b+x,dominantBaseline:"central",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+l)),f+=v}),m},It=({legendGroups:e,width:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:c,legendInteraction:l,metrics:d})=>{const u=[],h=function(e,t){let n=24;return e.map(({hasLabel:e,itemCount:i})=>{n+=5;const o=n;let r;n+=8,e&&(n+=16,r=n,n+=8);const s=n;return n+=i*t+8,{lineY:o,labelY:r,itemsY:s,endY:n}})}(e.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),d.rowHeight);return e.forEach((e,p)=>{const m=h[p];u.push((0,bt.jsx)("line",{stroke:"gray",x1:0,y1:m.lineY,x2:t,y2:m.lineY},"legend-top-line legend-symbol-"+p)),e.label&&null!=m.labelY&&u.push((0,bt.jsx)("text",{y:m.labelY,className:"legend-group-label",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label},"legend-text-"+p)),u.push((0,bt.jsx)("g",{className:"legend-item",transform:`translate(0,${m.itemsY})`,children:Mt(e,n,i,o,r,s,a,p,c,l,d)},"legend-group-"+p))}),u},St=({legendGroups:e,height:t,width:n,customClickBehavior:i,customHoverBehavior:o,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:c,onFocusedIndexChange:l,legendInteraction:d,metrics:u})=>{let h=0;const p=[];e.forEach((e,t)=>{let m=0;e.label&&(m+=16);const f=((e,t,n,i,o,r,s,a,c,l,d,u)=>{const{type:h="fill",styleFn:p,items:m}=e,f=[],{swatchSize:y,labelGap:g,itemGap:b,rowHeight:x,align:v}=d,w=!(!t&&!n),k="isolate"===l||void 0===l&&null!=o,M=m.map(e=>y+g+7*e.label.length),I=[];let S=0,j=0;M.forEach((e,t)=>{const n=0===j?e:j+b+e;u&&u>0&&j>0&&n>u?(I.push({start:S,end:t,width:j}),S=t,j=e):j=n}),m.length>0&&I.push({start:S,end:m.length,width:j}),I.forEach((e,l)=>{let d="center"===v?Math.max(0,((u??e.width)-e.width)/2):"end"===v?Math.max(0,(u??e.width)-e.width):0;for(let u=e.start;e.end>u;u++){const e=m[u],v=vt(e,u,h,p,y),I=kt(e,i,o),S=o&&o.size>0&&o.has(e.label);f.push((0,bt.jsxs)("g",{transform:`translate(${d},${l*x})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:w?a===r&&u===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?S||!1:void 0,"aria-current":w&&!k&&null!=i&&e.label===i||void 0,"aria-label":e.label,onKeyDown:w?n=>{if("Enter"!==n.key&&" "!==n.key||(n.preventDefault(),t&&t(e)),"ArrowRight"===n.key||"ArrowLeft"===n.key){n.preventDefault();const e=(u+("ArrowRight"===n.key?1:-1)+m.length)%m.length;c(a,e);const t=n.currentTarget.parentElement?.children[e];t instanceof SVGElement&&t.focus()}}:void 0,onFocus:w?t=>{c(a,u),n&&n(e);const i=t.currentTarget.querySelector(".semiotic-legend-focus-ring");i&&i.setAttribute("visibility","visible")}:void 0,onBlur:w?e=>{n&&n(null);const t=e.currentTarget.querySelector(".semiotic-legend-focus-ring");t&&t.setAttribute("visibility","hidden")}:void 0,style:{cursor:w?"pointer":"default",opacity:I,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&(0,bt.jsx)("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:y+g+2+7*e.label.length,height:y+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,S&&(0,bt.jsx)(wt,{swatchSize:y}),(0,bt.jsx)("text",{y:y/2,x:y+g,dominantBaseline:"central",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+u)),d+=M[u]+b}});const A=Math.max(0,...I.map(e=>e.width)),C=I.length;return{items:f,offset:A,totalRows:C,totalHeight:C*x}})(e,i,o,r,s,a,c,t,l,d,u,u.maxWidth??n);m+=f.offset+5,p.push({label:e.label,...f,offset:m,totalRows:f.totalRows,totalHeight:f.totalHeight}),h+=m+12});const m=u.maxWidth??n;let f=h>m?0:"center"===u.align?Math.max(0,(m-h)/2):"end"===u.align?Math.max(0,m-h):0;const y=[];return p.forEach((n,i)=>{const o=e[i];o.label&&(y.push((0,bt.jsx)("text",{transform:`translate(${f},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:o.label},"legend-text-"+i)),f+=16),y.push((0,bt.jsx)("g",{className:"legend-item",transform:`translate(${f},0)`,children:n.items},"legend-group-"+i)),f+=n.offset+5,e[i+1]&&y.push((0,bt.jsx)("line",{stroke:"gray",x1:f,y1:-8,x2:f,y2:(n.totalHeight||t)+0+8},"legend-top-line legend-symbol-"+i)),f+=12}),(0,bt.jsx)("g",{children:y})};function jt({config:e,orientation:t="vertical",width:n=100}){const{colorFn:i,domain:o,label:r,format:s}=e,a=s||(e=>Math.round(100*e)/100+""),c="grad-legend-"+it.useId();if("horizontal"===t){const e=12,t=Math.min(n,200),s=Math.max(0,(n-t)/2),l=[];for(let e=0;64>=e;e++){const t=e/64;l.push((0,bt.jsx)("stop",{offset:100*t+"%",stopColor:i(o[0]+t*(o[1]-o[0]))},e))}return(0,bt.jsxs)("g",{"aria-label":r||"Gradient legend",children:[(0,bt.jsx)("defs",{children:(0,bt.jsx)("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),r&&(0,bt.jsx)("text",{x:s+t/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),(0,bt.jsx)("rect",{x:s,y:0,width:t,height:e,fill:`url(#${c})`,rx:2}),(0,bt.jsx)("text",{x:s,y:e+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[0])}),(0,bt.jsx)("text",{x:s+t,y:e+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[1])})]})}const l=[];for(let e=0;64>=e;e++){const t=e/64;l.push((0,bt.jsx)("stop",{offset:100*t+"%",stopColor:i(o[1]-t*(o[1]-o[0]))},e))}return(0,bt.jsxs)("g",{"aria-label":r||"Gradient legend",children:[r&&(0,bt.jsx)("text",{x:0,y:-6,textAnchor:"start",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),(0,bt.jsx)("defs",{children:(0,bt.jsx)("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),(0,bt.jsx)("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),(0,bt.jsx)("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[1])}),(0,bt.jsx)("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(o[0])})]})}function At(e){const{legendGroups:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:c=100,height:l=20,orientation:d="vertical",legendLayout:u}=e,h=gt(u),[p,m]=it.useState(0),[f,y]=it.useState(0),g=it.useCallback((e,t)=>{m(e),y(t)},[]),b="vertical"===d?It({legendGroups:t||[],width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:p,focusedItemIndex:f,onFocusedIndexChange:g,legendInteraction:s,metrics:h}):St({legendGroups:t||[],title:a,height:l,width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:o,isolatedCategories:r,focusedGroupIndex:p,focusedItemIndex:f,onFocusedIndexChange:g,legendInteraction:s,metrics:h}),x=!(!n&&!i);return(0,bt.jsxs)("g",{role:x?"listbox":void 0,"aria-multiselectable":!(!x||"isolate"!==s&&(void 0!==s||null==r))||void 0,"aria-label":"Chart legend",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[void 0!==a&&""!==a&&"vertical"===d&&(0,bt.jsx)("text",{className:"legend-title",y:16,x:c/2,textAnchor:"middle",fontSize:12,style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),b]})}var Ct=require("react/jsx-runtime");function Rt(e){const{legend:t,totalWidth:n,totalHeight:i,margin:o,legendPosition:r="right",legendLayout:s,legendHoverBehavior:a,legendClickBehavior:c,legendHighlightedCategory:l,legendIsolatedCategories:d,legendInteraction:u}=e;if(!t)return null;const h="top"===r||"bottom"===r,p=Math.max(0,n-o.left-o.right),m=Math.max(1,h?s?.maxWidth??p:function(e,t){if(ot(e)){const n=gt(t),i=e.legendGroups.flatMap(e=>[e.label?ht(e.label):0,...e.items.map(e=>n.swatchSize+n.labelGap+ht(e.label))]);return Math.max(dt,...i)}if(rt(e)){const{gradient:t}=e,n=t.format||(e=>Math.round(100*e)/100+""),i=Math.max(ht(n(t.domain[0])),ht(n(t.domain[1]))),o=t.label?ht(t.label):0;return Math.max(dt,19+i,o)}return dt}(t,s)),f=function(e){return(ot(e)||rt(e))&&Number.isFinite(e.legendDistance)?Math.max(0,e.legendDistance):ut}(t),y=(g=s,Math.max(0,g?.sideGutter??0));var g;const b=yt(e.axisChrome,s),x=yt(void 0,s),v=function(e,t,n){if(rt(e))return e.gradient.label?34:26;if(!ot(e))return 20;const i=gt(n),o=Math.max(1,n?.maxWidth??t);let r=i.rowHeight;for(const t of e.legendGroups){let e=0,n=0;for(const r of t.items){const t=i.swatchSize+i.labelGap+ht(r.label),s=0===n?t:n+i.itemGap+t;n>0&&s>o?(e+=1,n=t):n=s}t.items.length>0&&(e+=1),r=Math.max(r,e*i.rowHeight,t.label?ht(t.label):0)}return r+(e.legendGroups.length>1?16:0)}(t,p,s);let w,k;if("left"===r)w=o.left-y-m-f,k=o.top;else if("top"===r)w=o.left,k=o.top-x-f-v;else if("bottom"===r){w=o.left;const e=i-o.bottom;k=Math.max(e+f,Math.min(e+b+f,i-v))}else w=n-o.right+y+f,k=o.top;return(0,Ct.jsx)("g",{transform:`translate(${w}, ${k})`,children:rt(t)?(0,Ct.jsx)(jt,{config:t.gradient,orientation:h?"horizontal":"vertical",width:m}):ot(t)?(0,Ct.jsx)(At,{legendGroups:t.legendGroups,title:"",width:m,orientation:h?"horizontal":"vertical",legendLayout:s,customHoverBehavior:a,customClickBehavior:c,highlightedCategory:l,isolatedCategories:d,legendInteraction:u}):t})}var $t=require("react/jsx-runtime"),Pt={secondary:0,primary:3},Dt=1,Bt=2,Tt=.6,Et="0.88em",Nt=.95,Ot=.72,Ft=.06,Wt=".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}",qt=".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}";function zt(e){return!0===e?._annotationDeferred}function Lt(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Ht(e){const t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function Yt(e){return Math.max(Ot,Nt-e*Ft)}var _t=c(require("react")),Gt=require("react/jsx-runtime");function Vt(e,t=120,n=8){if(!e)return[];const i=Math.max(1,Math.floor(t/n)),o=e.split(/\s+/),r=[];let s="";for(const e of o)s&&s.length+1+e.length>i?(r.push(s),s=e):s=s?`${s} ${e}`:e;return s&&r.push(s),r}function Xt(e,t,n,i){return"curly"===e?i?`M0,0 C${.6*n},0 ${.4*n},${t/2} ${n},${t/2} C${.4*n},${t/2} ${.6*n},${t} 0,${t}`:`M0,0 C0,${.6*n} ${t/2},${.4*n} ${t/2},${n} C${t/2},${.4*n} ${t},${.6*n} ${t},0`:i?`M0,0 L${n},0 L${n},${t} L0,${t}`:`M0,0 L0,${n} L${t},${n} L${t},0`}function Ut(e,t,n,i){if(!e)return(0,Gt.jsx)("g",{className:"annotation-note"});const{label:o,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=e;if(!o&&!r)return(0,Gt.jsx)("g",{className:"annotation-note"});let d=s;d||(d=Math.abs(t)>Math.abs(n)?"leftRight":"topBottom");let u=a;u&&"dynamic"!==u||(u="topBottom"===d?0>t?"right":"left":0>n?"bottom":"top");let h="start";"topBottom"===d?"right"===u?h="end":"middle"===u&&(h="middle"):h=0>t?"end":"start";const p=16,m=r?l?[r]:Vt(r,c):[],f=o?l?[o]:Vt(o,c):[],y="leftRight"===d?"end"===h?-4:4:0;let g=0;const b=[],x=i||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";e.useHTML||e.html?b.push((0,Gt.jsx)("foreignObject",{className:"annotation-note-html",x:"end"===h?y-c:"middle"===h?y-c/2:y,y:-16,width:c,height:Math.max(p,(m.length+f.length)*p+(r&&o?2:0))+p,style:{overflow:"visible"},children:(0,Gt.jsxs)("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:x,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:l?"nowrap":"normal",wordBreak:"break-word"},children:[r&&(0,Gt.jsx)("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),o&&(0,Gt.jsx)("div",{className:"annotation-note-label",children:o})]})},"annotation-note-html")):(m.length>0&&(b.push((0,Gt.jsx)("text",{className:"annotation-note-title",fill:x,textAnchor:h,fontWeight:"bold",children:m.map((e,t)=>(0,Gt.jsx)("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-title")),g=m.length*p),f.length>0&&b.push((0,Gt.jsx)("text",{className:"annotation-note-label",fill:x,textAnchor:h,y:g,children:f.map((e,t)=>(0,Gt.jsx)("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-label")));let v=null;if((r||o)&&(0!==t||0!==n))if("topBottom"===d){const e=Math.min(c,120);let t=0,n=e;"end"===h?(t=-e,n=0):"middle"===h&&(t=-e/2,n=e/2),v=(0,Gt.jsx)("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}else{const e=(m.length+f.length)*p+(f.length>0?p:0);let t=0,n=e;"bottom"===u?(t=-e,n=0):"middle"===u&&(t=-e/2,n=e/2),v=(0,Gt.jsx)("line",{className:"note-line",x1:0,x2:0,y1:t,y2:n,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,m.length+f.length-1)*p;let k=0;return"topBottom"===d?k=0>n?-(w+2):18:"leftRight"===d&&(k="middle"===u?-(w+p+(f.length>0&&m.length>0?2:0))/2+8:"bottom"===u||0>n?-(w+2):18),(0,Gt.jsxs)("g",{className:"annotation-note",transform:`translate(${t},${n})`,children:[(0,Gt.jsx)("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:b}),v]})}function Kt(e,t,n,i,o){const r=[];switch(e){case"callout-circle":{const e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&r.push((0,Gt.jsx)("circle",{r:e,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const e=t?.width||0,i=t?.height||0;(e>0||i>0)&&r.push((0,Gt.jsx)("rect",{width:e,height:i,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":t?.custom&&r.push(...Array.isArray(t.custom)?t.custom:[t.custom]);break;case"xy-threshold":{const e=i||0,s=o||0;if(void 0!==t?.x){const i=(t.x||0)-e;r.push((0,Gt.jsx)("line",{x1:i,y1:(t.y1||0)-s,x2:i,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==t?.y){const i=(t.y||0)-s;r.push((0,Gt.jsx)("line",{x1:(t.x1||0)-e,y1:i,x2:(t.x2||0)-e,y2:i,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==t?.x1||void 0!==t?.x2?r.push((0,Gt.jsx)("line",{x1:(t.x1||0)-e,y1:0,x2:(t.x2||0)-e,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===t?.y1&&void 0===t?.y2||r.push((0,Gt.jsx)("line",{x1:0,y1:(t.y1||0)-s,x2:0,y2:(t.y2||0)-s,stroke:n||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const e=t?.type||"curly",i=t?.width??t?.height;void 0!==i&&r.push((0,Gt.jsx)("path",{d:Xt(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return(0,Gt.jsx)("g",{className:"annotation-subject",children:r})}function Qt(e,t,n,i,o,r){const s=[];let a=0,c=0;if("callout-circle"!==o&&"label"!==o||!r?.radius){if("callout-rect"===o&&r){const n=r.width||0,i=r.height||0;if(n>0||i>0){const o=n/2,r=i/2,s=e-o,l=t-r;if(0!==s||0!==l){const e=Math.abs(s),t=Math.abs(l),d=n/2,u=i/2,h=e*u>t*d?d/e:u/t;a=o+s*h,c=r+l*h}}}else if("bracket"===o&&r){const e=r.width,t=r.height,n=r.depth||30;void 0!==e?(a=e/2,c=n):void 0!==t&&(a=n,c=t/2)}}else{const n=(r.radius||0)+(r.radiusPadding||0);if(n>0&&(0!==e||0!==t)){const i=Math.atan2(t,e);a=Math.cos(i)*n,c=Math.sin(i)*n}}const l=Math.sqrt((e-a)**2+(t-c)**2);if(l>.5){const o=i||"var(--semiotic-text-secondary, currentColor)",r="curve"===n?.type;let d=Math.atan2(t-c,e-a);if(r){const i=(a+e)/2,r=(c+t)/2,u=-(t-c)/l,h=(e-a)/l,p=(n?.curve??.25)*l,m=i+u*p,f=r+h*p;s.push((0,Gt.jsx)("path",{className:"connector-curve",d:`M${a},${c}Q${m},${f} ${e},${t}`,fill:"none",stroke:o},"connector-line")),d=Math.atan2(f-c,m-a)}else s.push((0,Gt.jsx)("line",{x1:a,y1:c,x2:e,y2:t,stroke:o},"connector-line"));if("arrow"===n?.end){const e=10,t=16/180*Math.PI;s.push((0,Gt.jsx)("path",{d:`M${a},${c}L${a+e*Math.cos(d+t)},${c+e*Math.sin(d+t)}L${a+e*Math.cos(d-t)},${c+e*Math.sin(d-t)}Z`,fill:o,stroke:"none"},"connector-arrow"))}}return(0,Gt.jsx)("g",{className:"annotation-connector",children:s})}function Zt(e){const{x:t=0,y:n=0,dx:i,dy:o,nx:r,ny:s,note:a,connector:c,subject:l,type:d,color:u,className:h,disable:p,opacity:m,strokeDasharray:f,events:y={},"data-testid":g}=e,b=Array.isArray(t)?t[0]??0:t,x=Array.isArray(n)?n[0]??0:n,v=new Set(Array.isArray(p)?p:[]);let w=i||0,k=o||0;null!=r&&(w=r-b),null!=s&&(k=s-x);const M="string"==typeof d?d:"label";if("bracket"===M&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const e=l.depth||30;k=e+(0>e?-5:5)}else if(void 0!==l.height){const e=l.depth||30;w=e+(0>e?-5:5),k=l.height/2}return(0,Gt.jsxs)("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${b},${x})`,"data-testid":g,...null!=m&&{opacity:m},...f&&{strokeDasharray:f},...y,children:[!v.has("connector")&&Qt(w,k,c,u,M,l),!v.has("subject")&&Kt(M,l,u,b,x),!v.has("note")&&Ut(a,w,k,u)]})}function Jt(e){const{noteData:t}=e,{screenCoordinates:n}=t,i="string"==typeof t.type?t.type:"label",o=t.eventListeners||t.events||{};if(t.coordinates&&n){const e=t.nx||n[0][0]+(t.dx??0),o=t.ny||n[0][1]+(t.dy??0),r=n.map((n,r)=>{const s=Object.assign({},t,{note:0===r?t.note:{label:""},x:n[0],y:n[1],nx:e,ny:o});return(0,Gt.jsx)(Zt,{"data-testid":"semiotic-annotation",...s,type:i},"multi-annotation-"+r)});return(0,Gt.jsx)("g",{children:r})}const r=t.note||{title:"none",label:t.label},s=`${r.label}-${r.title}-${t.i}`;return(0,Gt.jsx)(Zt,{"data-testid":"semiotic-annotation",events:o,...t,type:i},s)}var en=require("d3-hierarchy"),tn=require("d3-shape"),nn=2;function on(e){const t=10**nn;return Math.round(e*t)/t}function rn(e,t=2){const n=[],i=[],o=t+1;for(let t=0;o>t;t++){let r=0;for(const[n,i]of e)null!==i&&(r+=n**t*i);n.push(r);const s=[];for(let n=0;o>n;n++){let i=0;for(const[o,r]of e)null!==r&&(i+=o**(t+n));s.push(i)}i.push(s)}i.push(n);const r=function(e,t){const n=e,i=e.length-1,o=[t];for(let e=0;i>e;e++){let t=e;for(let o=e+1;i>o;o++)Math.abs(n[e][o])>Math.abs(n[e][t])&&(t=o);for(let o=e;i+1>o;o++){const i=n[o][e];n[o][e]=n[o][t],n[o][t]=i}for(let t=e+1;i>t;t++)for(let o=i;o>=e;o--)n[o][t]-=n[o][e]*n[e][t]/n[e][e]}for(let e=i-1;e>=0;e--){let t=0;for(let r=e+1;i>r;r++)t+=n[r][e]*o[r];o[e]=(n[i][e]-t)/n[e][e]}return o}(i,o).map(on);return{points:e.map(([e])=>[on(e),on(r.reduce((t,n,i)=>t+n*e**i,0))]),equation:[...r].reverse()}}function sn(e,t){const n=t.scales?.x??t.scales?.time;return n?null!=e.x?n(e.x):t.xAccessor&&null!=e[t.xAccessor]?n(e[t.xAccessor]):null:null}function an(e,t){const n=t.scales?.y??t.scales?.value;return n?null!=e.y?n(e.y):t.yAccessor&&null!=e[t.yAccessor]?n(e[t.yAccessor]):null:null}function cn(e){return null==e?null:e+""}function ln(e,t,n){return t.stickyPositionCache?.set(e,n),n}function dn(e,t,n){const i=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===i){if(null!=e.pointId&&n.pointNodes&&n.pointNodes.length>0)for(let i=n.pointNodes.length-1;i>=0;i--){const o=n.pointNodes[i];if(o.pointId===e.pointId)return ln(t,n,{x:o.x,y:o.y})}const i=function(e){const t=e.data;if(!t||0===t.length)return null;const n=t[t.length-1],i=e.scales?.x??e.scales?.time,o=e.scales?.y??e.scales?.value;if(!i||!o)return null;const r=n[e.xAccessor||"x"],s=n[e.yAccessor||"y"];return null==r||null==s?null:{x:i(r),y:o(s)}}(n);return i?ln(t,n,i):null}if("semantic"===i){const i=function(e,t,n){const i=function(e){return cn(e.provenance?.stableId??e.stableId)}(e);if(!i)return null;const o=n.pointNodes?.find(e=>cn(e.pointId)===i);if(o)return ln(t,n,{x:o.x,y:o.y});const r=n.data?.find(e=>function(e){return cn(e.stableId??e.id??e.provenance?.stableId)}(e)===i);if(!r)return null;const s=sn(r,n),a=an(r,n);return null==s||null==a?null:ln(t,n,{x:s,y:a})}(e,t,n);if(i)return i}let o=null,r=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(o=t.x,r=t.y)}if(null!=o&&null!=r||(o=sn(e,n),r=an(e,n)),null!=o&&null!=r)return ln(t,n,{x:o,y:r});if("sticky"===i){const e=n.stickyPositionCache?.get(t);if(e)return e}return null}function un(e,t,n,i=50){return!(-i>e||e>(n.width||0)+i||-i>t||t>(n.height||0)+i)}function hn(e){let t=1/0,n=-1/0;for(const i of e)t>i&&(t=i),i>n&&(n=i);return[t,n]}var pn=c(require("react")),[mn,fn]=g(e=>({observations:[],maxObservations:100,version:0,pushObservation(t){e(e=>{const n=e.observations;return n.push(t),n.length>e.maxObservations&&n.shift(),{version:e.version+1}})},clearObservations(){e(()=>({observations:[],version:0}))}}));function yn(e,t={}){const n=function(e){const t=e.provenance,n=e.id??e.stableId??t?.stableId;return null==n||""===n?void 0:n+""}(e);return{"data-semiotic-annotation-widget":"",...n?{"data-semiotic-annotation-id":n}:{},onClickCapture(i){const o=function(e){const t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}(i);t.onAnnotationActivate?.({annotation:e,annotationId:n,chartId:t.chartId,inputType:o}),n&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:n,inputType:o,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}var gn=16,bn=20,xn=require("react/jsx-runtime"),vn="var(--semiotic-bg, #ffffff)",wn=.85;function kn(e){const{x:t,y:n,text:i,fill:o,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:c="start",dominantBaseline:l,background:d,className:u}=e,h=function(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{type:e.type??"halo",...e}}(d),p=e=>(0,xn.jsx)("text",{x:t,y:n,textAnchor:c,dominantBaseline:l,fill:o,fontSize:r,fontWeight:s,fontFamily:a,className:u,...e?{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}:{},children:i});if(!h)return p();if("halo"===h.type)return p({stroke:h.fill??vn,strokeWidth:h.haloWidth??3});const m=h.padding??{x:6,y:3},f="number"==typeof m?m:m.x,y="number"==typeof m?m:m.y,g=function(e,t){return(e+"").length*t*.6}(i,r),b=r+2*y;let x,v;return x="middle"===c?t-g/2-f:"end"===c?t-g-f:t-f,v="middle"===l||"central"===l?n-b/2:"hanging"===l||"text-before-edge"===l?n-y:n-.8*r-y,(0,xn.jsxs)("g",{className:u,children:[(0,xn.jsx)("rect",{x:x,y:v,width:g+2*f,height:b,rx:h.radius??3,ry:h.radius??3,fill:h.fill??vn,fillOpacity:h.opacity??wn,stroke:h.stroke,strokeWidth:h.strokeWidth}),p()]})}var Mn=require("react/jsx-runtime"),In={linear:tn.curveLinear,monotoneX:tn.curveMonotoneX,monotoneY:tn.curveMonotoneY,step:tn.curveStep,stepAfter:tn.curveStepAfter,stepBefore:tn.curveStepBefore,basis:tn.curveBasis,cardinal:tn.curveCardinal,catmullRom:tn.curveCatmullRom};var Sn=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function jn(e){return!!e&&"object"==typeof e&&Sn.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}new Set(["label","callout","callout-circle","callout-rect"]);var An=2e4,Cn=1;function Rn(e){return"primary"===e?.emphasis||!0===e?.defensive}function $n(e,t,n={}){return"number"==typeof n.maxAnnotations&&Number.isFinite(n.maxAnnotations)?Math.max(0,Math.floor(n.maxAnnotations)):e>0&&t>0?Math.max(1,Math.round(e*t/(n.areaPerAnnotation&&n.areaPerAnnotation>0?n.areaPerAnnotation:An))):1/0}function Pn(e){let t;const n=e?.emphasis;t="primary"===n?100:"secondary"===n?10:50;const i=e?.provenance?.confidence;switch("number"==typeof i&&Number.isFinite(i)&&(t+=15*Math.max(0,Math.min(1,i))),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}var Dn=32,Bn=6,Tn=4,En=8,Nn=72,On=30,Fn=-30,Wn=8,qn=480,zn=3;var Ln={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function Hn(e){if(!Yn(e))return e;const t=("string"==typeof e.mobileText?e.mobileText:void 0)??("string"==typeof e.shortText?e.shortText:void 0);return!t||"string"!=typeof e.label&&null!=e.label?e:{...e,label:t}}function Yn(e){return jn(e)}function _n(e,t){if(!e)return[];const n=Math.max(1,Math.floor(t/7)),i=e.split(/\s+/).filter(Boolean),o=[];let r="";for(const e of i)r&&r.length+e.length+1>n?(o.push(r),r=e):r=r?`${r} ${e}`:e;return r&&o.push(r),o}function Gn(e,t,n,i,o){const r=e+n,s=t+i;return Math.abs(n)>Math.abs(i)?{x:0>n?r-o.width-4:r+4,y:0>i?s-o.height:s,width:o.width,height:o.height}:{x:0>n?r-o.width:r,y:0>i?s-o.height-4:s+4,width:o.width,height:o.height}}function Vn(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Xn(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function Un(e,t,n,i,o,r,s,a){const c=Vn(e,s);let l=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,i){const o=Math.max(0,i-e.x),r=Math.max(0,i-e.y);return(o+Math.max(0,e.x+e.width-(t-i)))*e.height+(r+Math.max(0,e.y+e.height-(n-i)))*e.width}(c,o,r,a);for(const e of n)l+=12*Xn(c,e);for(const e of i)l+=4*Xn(c,e);return l}function Kn(e){const{annotations:t,context:n,defaultOffset:i=Dn,notePadding:o=Bn,markPadding:r=Tn,edgePadding:s=En,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=Nn,density:d,progressiveDisclosure:u=!1,redundantCues:h=!1,responsive:p,mobile:m,cohesion:f,audience:y}=e,g=n.width||0,b=n.height||0,x="object"==typeof m?m:{},v=x.breakpoint??qn,w=!!m&&v>=g,k=w&&!1!==x.preferShortText?t.map(Hn):t,M=w&&!d?{maxAnnotations:x.maxAnnotations??("callout-list"===x.strategy?1:2),minVisible:x.minVisible??1}:d,I=u||w&&(!1!==x.progressiveDisclosure||"callout-list"===x.strategy),S=w&&!p?x.responsive??{minWidth:v}:p,j=w&&!f?x.cohesion:f;if(0===k.length||0>=g||0>=b)return k.slice();const A=[],C=function(e,t){return(e.pointNodes||[]).map(e=>{const n=Math.max(1,e.r||1)+t;return{x:e.x-n,y:e.y-n,width:2*n,height:2*n}})}(n,r);let R=!1;const $=k.map((e,t)=>{if(!Yn(e))return e;const r=function(e,t,n){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};const i=e.pointId??e.nodeId;if(null!=i&&n.pointNodes){const e=n.pointNodes.find(e=>e.pointId===i);if(e)return{x:e.x,y:e.y}}const o=e.coordinates,r=n.scales?.geoProjection;if(Array.isArray(o)&&o.length>=2&&r){const e=o[0],t=o[1];if("number"==typeof e&&"number"==typeof t){const n=r([e,t]);if(n&&"number"==typeof n[0]&&"number"==typeof n[1])return{x:n[0],y:n[1]}}}return n.scales||"number"!=typeof e.x||"number"!=typeof e.y?dn(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!r)return e;const d=function(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};const t="number"==typeof e.wrap?e.wrap:120,n=[..._n("string"==typeof e.title?e.title:void 0,t),..._n("string"==typeof e.label?e.label:void 0,t)],i=n.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(t,7*i)+10),height:Math.max(18,16*n.length+6)}}(e);if(a&&("number"==typeof(u=e).dx||"number"==typeof u.dy)){const t=function(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:On,dy:Fn}}(e);return A.push(Vn(Gn(r.x,r.y,"number"==typeof e.dx?e.dx:t.dx,"number"==typeof e.dy?e.dy:t.dy,d),o)),e}var u;let h=null,p=1/0;for(const e of function(e){const t=1.6*e;return[{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e},{dx:e,dy:0},{dx:-e,dy:0},{dx:0,dy:-e},{dx:0,dy:e},{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t}]}(i)){const t=Un(Gn(r.x,r.y,e.dx,e.dy,d),e,A,C,g,b,o,s);p>t&&(h=e,p=t)}if(!h)return e;const m=Vn(Gn(r.x,r.y,h.dx,h.dy,d),o);A.push(m);const f=Math.hypot(h.dx,h.dy),y=c&&f>=l&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return R=!0,{...e,dx:h.dx,dy:h.dy,...y?{connector:y}:{}}}),P=R?$:k.slice();let D=P;if(h){let e=!1;const t=P.map(t=>{const n=function(e){return"text"!==e.type||"string"!=typeof e.color||Math.hypot("number"==typeof e.dx?e.dx:0,"number"==typeof e.dy?e.dy:0)<Wn?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});D=e?t:P}{let e=!1;const t=D.map(t=>{if(!0!==t?.defensive)return t;const n=function(e){const t=e?.provenance;if(!t||"object"!=typeof t)return e;const n="string"==typeof t.source?Ln[t.source]??t.source:null,i="number"==typeof t.confidence&&Number.isFinite(t.confidence)?Math.round(100*Math.max(0,Math.min(1,t.confidence)))+"%":null;if(!n&&!i)return e;if(null!=e.label&&"string"!=typeof e.label)return e;const o=[n,i].filter(Boolean).join(" · "),r="string"==typeof e.label?e.label:"";return r.includes(`(${o})`)?e:{...e,label:r?`${r} (${o})`:`(${o})`}}(t);return n!==t&&(e=!0),n});D=e?t:D}const B=new Set;if(M){const e="object"==typeof M?M:{},t=function(e){if(!e)return 1;const t=function(e){const t=e?.familiarity;if(!t)return zn;const n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?zn:n.reduce((e,t)=>e+t,0)/n.length}(e);return t>2?4>t?1:.6:1.5}(y),n=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??$n(g,b,e))*t))},{deferred:i}=function(e){const{annotations:t,width:n,height:i}=e,o=Math.max(0,e.minVisible??Cn),r=$n(n,i,e),s=t.map((e,t)=>{return{annotation:e,index:t,note:(n=e,jn(n))};var n}),a=s.filter(e=>e.note);if(0===a.length||r>=a.length)return{visible:t.slice(),deferred:[],budget:r};const c=a.filter(e=>Rn(e.annotation)),l=a.filter(e=>!Rn(e.annotation)).sort((e,t)=>Pn(t.annotation)-Pn(e.annotation)||e.index-t.index),d=Math.min(l.length,Math.max(Math.max(0,r-c.length),Math.max(0,o-c.length))),u=new Set([...c.map(e=>e.index),...l.slice(0,d).map(e=>e.index)]),h=[],p=[];for(const{annotation:e,index:t,note:n}of s)!n||u.has(t)?h.push(e):p.push(e);return{visible:h,deferred:p,budget:r}}({annotations:D,width:g,height:b,...n});for(const e of i)B.add(e)}if(S&&("object"==typeof S&&"number"==typeof S.minWidth?S.minWidth:qn)>=g)for(const e of D)Yn(e)&&"secondary"===e.emphasis&&B.add(e);if(B.size>0)for(const e of D)!0===e?.defensive&&B.delete(e);let T;return T=0===B.size?D:I?D.map(e=>B.has(e)?{...e,_annotationDeferred:!0}:e):D.filter(e=>!B.has(e)),j?function(e,t){let n=!1;const i=e.map(e=>Yn(e)?"blended"===e.cohesion||"layer"===e.cohesion?e:(n=!0,{...e,cohesion:t}):e);return n?i:e}(T,j):T}var Qn=require("react/jsx-runtime");function Zn(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function Jn(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,Zn(e))}))}function ei(e){const{width:t,height:n,pointNodes:i=[],data:o}=e;return{scales:{x:(0,nt.scaleLinear)().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:(0,nt.scaleLinear)().domain([0,Math.max(1,n)]).range([0,Math.max(1,n)])},width:t,height:n,frameType:"network",pointNodes:i,data:o,xAccessor:"x",yAccessor:"y"}}function ti(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:e.bodyId+""}):e}function ni(e){const{width:t,height:n,totalWidth:i,totalHeight:o,margin:r,title:s,legend:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendPosition:h="right",legendLayout:p,pointNodes:m=[],annotations:f,onAnnotationActivate:y,onObservation:g,chartId:b,chartType:x,autoPlaceAnnotations:v,svgAnnotationRules:w,children:k}=e,M=function(e){const t=fn(e=>e.pushObservation),n=pn.useCallback(n=>{e.onObservation?.(n),t?.(n)},[e,t]);return pn.useMemo(()=>({...e,onObservation:n}),[n,e])}({onAnnotationActivate:y,onObservation:g,chartId:b,chartType:x}),I=tt.useMemo(()=>ti(f),[f]),S=tt.useMemo(()=>ei({width:t,height:n,pointNodes:m}),[n,m,t]),j=tt.useMemo(()=>I&&v?Kn({annotations:I,context:S,..."object"==typeof v?v:{}}):I,[S,v,I]),A=tt.useMemo(()=>function(e,t={}){return function(e,n,i){switch(e.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const t=dn(e,n,i);if(!t)return null;const{x:o,y:r}=t;if(!un(o,r,i))return null;const s="callout"===e.type?"callout-circle":e.type,a="callout-circle"===s?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===s?{width:e.width,height:e.height}:void 0;return(0,Mn.jsx)(Jt,{noteData:{x:o,y:r,dx:e.dx??30,dy:e.dy??-30,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:s,...a?{subject:a}:{},connector:e.connector||{end:"arrow"},color:e.color,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-"+n)}case"x-threshold":{const t=sn(null!=e.value?{...e,x:e.value}:e,i);if(null==t)return null;const o=e.color||"#f97316",r=e.labelPosition||"top";let s;s="bottom"===r?(i.height||0)-4:"center"===r?(i.height||0)/2:gn;const a=t>.6*(i.width||0),c=a?t-4:t+4,l=a?"end":"start";return(0,Mn.jsxs)("g",{opacity:e.opacity,children:[(0,Mn.jsx)("line",{x1:t,y1:0,x2:t,y2:i.height||0,stroke:o,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,Mn.jsx)(kn,{x:c,y:s,text:e.label,textAnchor:l,fill:o,fontSize:12,fontWeight:"bold",background:e.labelBackground??"halo"})]},"ann-"+n)}case"y-threshold":{const t=an(null!=e.value?{...e,y:e.value}:e,i);if(null==t)return null;const o=e.color||"#f97316",r=e.labelPosition||"right";let s,c;"left"===r?(s=4,c="start"):"center"===r?(s=(i.width||0)/2,c="middle"):(s=(i.width||0)-4,c="end");const l=bn>(a=t)?Math.min((i.height||0)-4,a+gn):a-4;return(0,Mn.jsxs)("g",{opacity:e.opacity,children:[(0,Mn.jsx)("line",{x1:0,y1:t,x2:i.width||0,y2:t,stroke:o,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,Mn.jsx)(kn,{x:s,y:l,text:e.label,textAnchor:c,fill:o,fontSize:12,fontWeight:"bold",background:e.labelBackground??"halo"})]},"ann-"+n)}case"enclose":{const t=(e.coordinates||[]).map(e=>({x:sn({...e,type:"point"},i),y:an({...e,type:"point"},i),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>t.length)return null;const o=(0,en.packEnclose)(t),r=e.padding||10;return(0,Mn.jsxs)("g",{children:[(0,Mn.jsx)("circle",{cx:o.x,cy:o.y,r:o.r+r,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&(0,Mn.jsx)(kn,{x:o.x,y:o.y-o.r-r-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+n)}case"rect-enclose":{const t=(e.coordinates||[]).map(e=>({x:sn({...e,type:"point"},i),y:an({...e,type:"point"},i)})).filter(e=>null!=e.x&&null!=e.y);if(2>t.length)return null;const o=e.padding||10,r=t.map(e=>e.x),s=t.map(e=>e.y),[a,c]=hn(r),[l,d]=hn(s),u=a-o,h=c+o,p=l-o;return(0,Mn.jsxs)("g",{children:[(0,Mn.jsx)("rect",{x:u,y:p,width:h-u,height:d+o-p,fill:e.fill||"none",fillOpacity:e.fillOpacity||.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&(0,Mn.jsx)(kn,{x:(u+h)/2,y:p-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+n)}case"highlight":{const t=i.data||[],o="function"==typeof e.filter?t.filter(e.filter):e.field&&null!=e.value?t.filter(t=>t[e.field]===e.value):[],r={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return(0,Mn.jsx)("g",{children:o.map((t,n)=>{const o=sn(t,i),s=an(t,i);if(null==o||null==s)return null;const a="function"==typeof e.r?e.r(t):e.r||6,c="function"==typeof e.style?e.style(t):e.style||r;return(0,Mn.jsx)("circle",{cx:o,cy:s,r:a,...c},"hl-"+n)})},"ann-"+n)}case"bracket":{const t=sn(e,i),o=an(e,i);return(0,Mn.jsx)(Jt,{noteData:{x:t??0,y:o??0,dx:e.dx||0,dy:e.dy||0,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},"ann-"+n)}case"trend":{const t=i.data||[];if(2>t.length)return null;const o=i.xAccessor||"x",r=i.yAccessor||"y",s="ordinal"===i.frameType,a="horizontal"===i.projection,c=s?o:null,l=s?r:null;let d;const u=[],h=new Map;if(s&&c&&l){for(const e of t){const t=e[c];if(null==t)continue;const n=t+"";h.has(n)||(h.set(n,u.length),u.push(n))}d=t.map(e=>{const t=e[c],n=e[l];if(null==t||null==n)return null;const i=h.get(t+"");return null!=i?[i,+n]:null}).filter(e=>null!==e)}else d=t.map(e=>[e[o],e[r]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>d.length)return null;const p=i.scales?.x??i.scales?.time,m=i.scales?.y??i.scales?.value;if(!p||!m)return null;const f=e=>t=>{const n=Math.max(0,Math.floor(t)),i=Math.min(u.length-1,n+1),o=t-n,r=e(u[n]);return r+(e(u[i])-r)*o},y=p,g=m;let b;if(s)if(a){const e=f(g);b=(t,n)=>[y(n),e(t)]}else{const e=f(y);b=(t,n)=>[e(t),g(n)]}else b=(e,t)=>[y(e),g(t)];const x=e.method||"linear";let v;if("loess"===x)v=function(e,t=.3){const n=e.length;if(2>n)return e.slice();const i=e.slice().sort((e,t)=>e[0]-t[0]),o=i.map(e=>e[0]),r=i.map(e=>e[1]),s=Math.max(2,Math.ceil(t*n)),a=[];for(let e=0;n>e;e++){const t=o[e],i=o.map(e=>Math.abs(e-t)),c=i.slice().sort((e,t)=>e-t)[Math.min(s-1,n-1)]||1,l=[];for(let e=0;n>e;e++){const t=0===c?0:i[e]/c;l[e]=1>t?Math.pow(1-Math.pow(t,3),3):0}let d=0,u=0,h=0,p=0,m=0;for(let e=0;n>e;e++){const t=l[e];0!==t&&(d+=t,u+=t*o[e],h+=t*r[e],p+=t*o[e]*o[e],m+=t*o[e]*r[e])}if(0===d){a.push([t,r[e]]);continue}const f=d*p-u*u;if(1e-12>Math.abs(f))a.push([t,h/d]);else{const e=(d*m-u*h)/f;a.push([t,(h-e*u)/d+e*t])}}return a}(d,e.bandwidth??.3);else{const t="polynomial"===x?rn(d,e.order||2):function(e){const t=[0,0,0,0];let n=0;for(const[i,o]of e)null!==o&&(n++,t[0]+=i,t[1]+=o,t[2]+=i*i,t[3]+=i*o);const i=n*t[2]-t[0]*t[0],o=0===i?0:on((n*t[3]-t[0]*t[1])/i),r=on(t[1]/n-o*t[0]/n);return{points:e.map(([e])=>[on(e),on(o*e+r)]),equation:[o,r]}}(d);v=t.points}const w=v.map(([e,t])=>{const[n,i]=b(e,t);return`${n},${i}`}).join(" "),k=e.color||"#6366f1",M=v[v.length-1],[I,S]=b(M[0],M[1]);return(0,Mn.jsxs)("g",{children:[(0,Mn.jsx)("polyline",{points:w,fill:"none",stroke:k,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,Mn.jsx)("text",{x:I+4,y:S-4,fill:k,fontSize:11,children:e.label})]},"ann-"+n)}case"band":{const t=i.scales?.y??i.scales?.value,o=t?.domain?.(),a=e.y0??o?.[0],c=e.y1??o?.[1],l=null!=a&&t?t(a):0,d=null!=c&&t?t(c):i.height||0,u=de(e.fill,"ann-"+n,"var(--semiotic-primary, #6366f1)");return(0,Mn.jsxs)("g",{opacity:e.opacity,children:[u.def&&(0,Mn.jsx)("defs",{children:u.def}),(0,Mn.jsx)("rect",{x:0,y:Math.min(l,d),width:i.width||0,height:Math.abs(d-l),fill:u.fill,fillOpacity:e.fillOpacity||.1}),e.label&&(0,Mn.jsx)(kn,{x:(i.width||0)-4,y:(r=l,s=d,Math.max(Math.min(r,s),0)+gn),textAnchor:"end",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:e.label,background:e.labelBackground??"halo"})]},"ann-"+n)}case"x-band":{const t=i.scales?.x??i.scales?.time,o=t?.domain?.(),r=e.x0??o?.[0],s=e.x1??o?.[1],a=null!=r&&t?t(r):null,c=null!=s&&t?t(s):null;if(null==a||null==c)return null;const l=de(e.fill||e.color,"ann-"+n,"var(--semiotic-primary, #6366f1)");return(0,Mn.jsxs)("g",{opacity:e.opacity,children:[l.def&&(0,Mn.jsx)("defs",{children:l.def}),(0,Mn.jsx)("rect",{x:Math.min(a,c),y:0,width:Math.abs(c-a),height:i.height||0,fill:l.fill,fillOpacity:e.fillOpacity??.1}),e.label&&(0,Mn.jsx)(kn,{x:Math.min(a,c)+4,y:gn,textAnchor:"start",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:e.label,background:e.labelBackground??"halo"})]},"ann-"+n)}case"envelope":{const t=i.data||[];if(2>t.length)return null;const o=i.xAccessor||"x",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=e.upperAccessor||"upperBounds",c=e.lowerAccessor||"lowerBounds",l=e.filter,d=t.filter(e=>null!=e[a]&&null!=e[c]&&!(l&&!l(e))).sort((e,t)=>e[o]-t[o]);if(2>d.length)return null;const u=In[i.curve||"linear"]||tn.curveLinear,h=(0,tn.area)().x(e=>r(e[o])).y0(e=>s(e[c])).y1(e=>s(e[a])).curve(u)(d);if(!h)return null;const p=e.fill||"#6366f1";return(0,Mn.jsxs)("g",{children:[(0,Mn.jsx)("path",{d:h,fill:p,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&d.length>0&&(0,Mn.jsx)("text",{x:r(d[d.length-1][o])+4,y:s(d[d.length-1][a])-4,fill:p,fontSize:11,children:e.label})]},"ann-"+n)}case"anomaly-band":{const t=i.data||[];if(2>t.length)return null;const o=i.yAccessor||"y",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=t.map(e=>e[o]).filter(e=>null!=e&&isFinite(e));if(2>a.length)return null;const c=a.reduce((e,t)=>e+t,0)/a.length,l=a.reduce((e,t)=>e+(t-c)**2,0)/a.length,d=Math.sqrt(l),u=e.threshold??2,h=c-u*d,p=!1!==e.showBand,m=e.fill||"#6366f1",f=e.fillOpacity??.1,y=e.anomalyColor||"#ef4444",g=e.anomalyRadius??6,b=s(c+u*d),x=s(h),v=t.filter(e=>{const t=e[o];return null!=t&&Math.abs(t-c)>u*d});return(0,Mn.jsxs)("g",{children:[p&&(0,Mn.jsx)("rect",{x:0,y:Math.min(b,x),width:i.width||0,height:Math.abs(x-b),fill:m,fillOpacity:f}),v.map((e,t)=>{const n=sn(e,i),o=an(e,i);return null==n||null==o?null:(0,Mn.jsx)("circle",{cx:n,cy:o,r:g,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+t)}),e.label&&(0,Mn.jsx)("text",{x:(i.width||0)-4,y:Math.min(b,x)-4,textAnchor:"end",fill:m,fontSize:11,children:e.label})]},"ann-"+n)}case"forecast":{const t=i.data||[];if(3>t.length)return null;const r=i.xAccessor||"x",s=i.yAccessor||"y",a=i.scales?.x??i.scales?.time,c=i.scales?.y??i.scales?.value;if(!a||!c)return null;const l=t.map(e=>[e[r],e[s]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>l.length)return null;let d;if("polynomial"===(e.method||"linear")){const t=rn(l,e.order||2).equation;d=e=>t.reduce((t,n,i)=>t+n*Math.pow(e,i),0)}else{const e=function(e){const t=e.length;let n=0,i=0,o=0,r=0;for(const[t,s]of e)n+=t,i+=s,o+=t*t,r+=t*s;const s=t*o-n*n;if(1e-12>Math.abs(s))return null;const a=(t*r-n*i)/s,c=(i-a*n)/t;return e=>c+a*e}(l);if(!e)return null;d=e}const u=l.length,{se:h,meanX:p,ssX:m}=function(e,t){const n=e.length,i=e.map(([e,n])=>n-t(e)).reduce((e,t)=>e+t*t,0),o=Math.sqrt(i/Math.max(n-2,1)),r=e.reduce((e,t)=>e+t[0],0)/n,s=e.reduce((e,t)=>e+(t[0]-r)**2,0);return{se:o,meanX:r,ssX:s}}(l,d),f=.99>(o=e.confidence??.95)?.95>o?.9>o?1:1.645:1.96:2.576,y=e.steps??5,g=l[u-1][0],b=(g-l[0][0])/Math.max(u-1,1),x=[];for(let e=1;y>=e;e++)x.push(g+e*b);const v=[];for(const e of x){const t=d(e),n=h*Math.sqrt(1+1/u+(m>0?(e-p)**2/m:0))*f;v.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const w=`M${v.map(e=>`${a(e.x)},${c(e.yUpper)}`).join(" L")} L${v.slice().reverse().map(e=>`${a(e.x)},${c(e.yLower)}`).join(" L")} Z`,k=v.map(e=>`${a(e.x)},${c(e.yCenter)}`).join(" "),M=`${a(g)},${c(d(g))}`,I=e.strokeColor||"#6366f1";return(0,Mn.jsxs)("g",{children:[(0,Mn.jsx)("path",{d:w,fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity??.15,stroke:"none"}),(0,Mn.jsx)("polyline",{points:`${M} ${k}`,fill:"none",stroke:I,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&v.length>0&&(0,Mn.jsx)("text",{x:a(v[v.length-1].x)+4,y:c(v[v.length-1].yCenter)-4,fill:I,fontSize:11,children:e.label})]},"ann-"+n)}case"widget":{let o,r;if(null!=e.px&&null!=e.py)o=e.px,r=e.py;else{const t=dn(e,n,i);if(!t)return null;o=t.x,r=t.y}if(!un(o,r,i))return null;const s=e.dx??0,a=e.dy??0,c=e.width??32,l=e.height??32,d=e.content??(0,Mn.jsx)("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});return(0,Mn.jsx)("foreignObject",{x:o+s-c/2,y:r+a-l/2,width:c,height:l,style:{overflow:"visible",pointerEvents:"auto"},children:(0,Mn.jsx)("div",{...yn(e,t),style:{width:c,height:l,display:"flex",alignItems:"center",justifyContent:"center"},children:d})},"ann-"+n)}case"text":{const t=dn(e,n,i);if(!t)return null;const{x:o,y:r}=t,s=o+(e.dx||0),a=r+(e.dy||0),c=e.color||"var(--semiotic-text, #333)",l=(0,Mn.jsx)("text",{x:s,y:a,fill:c,fontSize:e.fontSize||11,opacity:e.opacity,strokeDasharray:e.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:e.label});return!0!==e._redundantConnector?_t.cloneElement(l,{key:"ann-text-"+n}):(0,Mn.jsxs)("g",{opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:[(0,Mn.jsx)("line",{x1:o,y1:r,x2:s,y2:a,stroke:c,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),_t.cloneElement(l,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+n)}case"category-highlight":{const t=e.category;if(null==t)return null;const o=e=>"function"==typeof e&&"function"==typeof e.bandwidth,r=i.scales?.o,s=i.scales?.x,a=i.scales?.y,c=o(r)?r:o(s)?s:o(a)?a:null;if(!c)return null;const l=c(t+"");if(null==l)return null;const d=c.bandwidth(),u=e.color||"var(--semiotic-primary, #4589ff)",h=e.opacity??.15,p=e.label;return(0,Mn.jsxs)("g",(i.projection?"vertical"===i.projection:c===s)?{children:[(0,Mn.jsx)("rect",{x:l,y:0,width:d,height:i.height||0,fill:u,fillOpacity:h}),p&&(0,Mn.jsx)(kn,{x:l+d/2,y:gn,textAnchor:"middle",fill:u,fontSize:12,fontWeight:"bold",text:p,background:e.labelBackground??"none"})]}:{children:[(0,Mn.jsx)("rect",{x:0,y:l,width:i.width||0,height:d,fill:u,fillOpacity:h}),p&&(0,Mn.jsx)(kn,{x:12,y:l+d/2,dominantBaseline:"middle",fill:u,fontSize:12,fontWeight:"bold",text:p,background:e.labelBackground??"none"})]},"ann-"+n)}default:return null}var o,r,s,a}}(0,M),[M]),C=j?function(e,t,n,i){const o=[];return e.forEach((e,r)=>{let s;if(n){const o=n(e,r,i);s=null!=o?o:t(e,r,i)}else s=t(e,r,i);s&&o.push({node:s,annotation:e})}),function(e){const t=e.map((e,t)=>{return{p:e,i:t,emphasis:(n=e.annotation,"primary"===n?.emphasis||"secondary"===n?.emphasis?n.emphasis:null),confidence:Ht(e.annotation),readingOrder:null,rank:Dt};var n}),n=t.some(e=>null!=e.emphasis||null!=e.confidence),i=e.some(e=>zt(e.annotation)),o=e.some(e=>null!=Lt(e.annotation)),r=e.some(e=>"layer"===Lt(e.annotation));if(!n&&!i&&!o)return e.map(e=>e.node);const s=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);s.forEach((e,t)=>{e.readingOrder=t,e.rank=Bt-t/Math.max(1,s.length)});for(const e of t)e.emphasis&&(e.rank=Pt[e.emphasis]);const a=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{const{p:t,i:n,emphasis:i,readingOrder:o}=e,r=zt(t.annotation);let s=t.node;if("primary"===i||"secondary"===i||null!=o){const e=null==i&&null!=o;s=(0,$t.jsx)("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+i,..."secondary"===i?{opacity:Tt,fontSize:Et}:{},...e?{opacity:Yt(o),"data-annotation-reading-order":o}:{},children:t.node},"annotation-emphasis-"+n)}const a=Lt(t.annotation);return a&&(s=(0,$t.jsx)("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+n)),r&&(s=(0,$t.jsx)("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+n)),s});return i&&a.unshift((0,$t.jsx)("style",{children:Wt},"annotation-disclosure-style")),r&&a.unshift((0,$t.jsx)("style",{children:qt},"annotation-cohesion-style")),a}(o)}(j,A,w,S):null,R=!0===j?.some(e=>"widget"===e.type&&!0===e._annotationDeferred);return(0,Qn.jsxs)(Qn.Fragment,{children:[R?(0,Qn.jsx)("style",{children:Wt},"physics-annotation-disclosure-style"):null,(0,Qn.jsxs)("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i,height:o,style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[(0,Qn.jsxs)("g",{transform:`translate(${r.left},${r.top})`,children:[C,k]}),s&&"string"==typeof s?(0,Qn.jsx)("text",{x:i/2,y:16,textAnchor:"middle",fontWeight:600,fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{fontSize:"var(--semiotic-title-font-size, 14px)"},children:s}):s?(0,Qn.jsx)("foreignObject",{x:0,y:0,width:i,height:Math.max(r.top,28),children:s}):null,a?Rt({legend:a,totalWidth:i,totalHeight:o,margin:r,legendPosition:h,legendLayout:p,title:s,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u}):null]})]})}var ii=2500;function oi(e){return"function"==typeof e}function ri(e){return void 0===e||!1===e||!oi(e.binAccessor)&&!oi(e.labelAccessor)&&!oi(e.valueAccessor)}function si(e){if(void 0!==e){if(!1===e)return!1;if(!ri(e))throw new TypeError("Physics worker sediment config only supports string or numeric accessors");return{binAccessor:"string"==typeof e.binAccessor?e.binAccessor:void 0,labelAccessor:"string"==typeof e.labelAccessor?e.labelAccessor:void 0,valueAccessor:"string"==typeof e.valueAccessor||"number"==typeof e.valueAccessor?e.valueAccessor:void 0,retainBodyIds:e.retainBodyIds}}}function ai(e){if(e)return{chartId:e.chartId,chartType:e.chartType,sensors:e.sensors}}function ci(e){return function(e){return!oi(e?.timeAccessor)}(e)}function li(e={}){if(e.engine)throw new TypeError("Physics workers use the built-in kernel adapter");const{engine:t,observation:n,sediment:i,...o}=e;return{...o,observation:ai(n),sediment:si(i)}}var di={};function ui(){if("undefined"!=typeof DOMException)return new DOMException("Physics worker request aborted","AbortError");const e=Error("Physics worker request aborted");return e.name="AbortError",e}var hi=class{constructor(e=function(){const e="string"==typeof di.url&&di.url?new URL("./physicsWorker.js",di.url):function(e){if("undefined"!=typeof __filename){const t=__filename.replace(/\\/g,"/"),n=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+n)}throw Error("Cannot resolve module worker asset: "+e)}("physicsWorker.js");return new Worker(e,{type:"module",name:"semiotic-physics"})}()){this.nextRequestId=1,this.pending=new Map,this.worker=e,this.worker.onmessage=e=>{const t=e.data,n=this.pending.get(t.requestId);n&&(this.pending.delete(t.requestId),n.cleanup(),t.ok?n.resolve(t.payload):n.reject(function(e){const t=Error(e.error.message);return t.name=e.error.name??"Error",e.error.stack&&(t.stack=e.error.stack),t}(t)))},this.worker.onerror=e=>{this.rejectAll(Error(e.message||"Physics worker failed")),this.worker.terminate()}}request(e,t){if(t?.aborted)return Promise.reject(ui());const n=this.nextRequestId;this.nextRequestId+=1;const i={command:e,requestId:n};return new Promise((e,o)=>{const r=()=>{this.pending.delete(n),t?.removeEventListener("abort",r),o(ui())},s=()=>t?.removeEventListener("abort",r);this.pending.set(n,{cleanup:s,reject:o,resolve:e}),t?.addEventListener("abort",r,{once:!0});try{this.worker.postMessage(i)}catch(e){this.pending.delete(n),s(),o(e)}})}async init(e,t,n,i){if(!ci(n))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const o=await this.request({type:"init",config:li(e),initialSpawns:t,initialSpawnPacing:n},i);if("frame"!==o.type)throw Error("Physics worker returned a non-frame init response");return o.frame}async restore(e,t){const n=await this.request({type:"restore",snapshot:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame restore response");return n.frame}async initFromSnapshot(e,t,n){const i=await this.request({type:"init",config:li(e),snapshot:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame init response");return i.frame}async enqueue(e,t,n){if(!ci(t))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const i=await this.request({type:"enqueue",spawns:e,pacing:t},n);if("frame"!==i.type)throw Error("Physics worker returned a non-frame enqueue response");return i.frame}async tick(e,t){const n=await this.request({type:"tick",deltaSeconds:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame tick response");return n.frame}async settle(e,t){const n=await this.request({type:"settle",maxSteps:e},t);if("frame"!==n.type)throw Error("Physics worker returned a non-frame settle response");return n.frame}async snapshot(e){const t=await this.request({type:"snapshot"},e);if("snapshot"!==t.type)throw Error("Physics worker returned a non-snapshot response");return t.snapshot}async remove(e,t){const n=await this.request({type:"remove",ids:e},t);if("removed"!==n.type)throw Error("Physics worker returned a non-remove response");return{frame:n.frame,removed:n.removed}}terminate(){this.rejectAll(Error("Physics worker terminated")),this.worker.terminate()}rejectAll(e){for(const[t,n]of this.pending)this.pending.delete(t),n.cleanup(),n.reject(e)}};function pi(e){let t=e>>>0;return function(){t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}var mi={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},fi=1e-9,yi=.005;function gi(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function bi(e){return"aabb"===e.type?{type:"aabb",x:e.x,y:e.y,width:e.width,height:e.height}:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:e.thickness}}function xi(e,t,n){return Math.max(t,Math.min(n,e))}function vi(e,t,n){return Math.min(e??n,t??n)}function wi(e,t,n){return xi(Math.max(e??n,t??n),0,1)}function ki(e){return 0>e?-1:1}function Mi(e){if("circle"===e.shape.type){const t=e.shape.radius;return{minX:e.x-t,minY:e.y-t,maxX:e.x+t,maxY:e.y+t}}const t=e.shape.width/2,n=e.shape.height/2;return{minX:e.x-t,minY:e.y-n,maxX:e.x+t,maxY:e.y+n}}function Ii(e){const t=e.shape;if("aabb"===t.type){const e=t.width/2,n=t.height/2;return{minX:t.x-e,minY:t.y-n,maxX:t.x+e,maxY:t.y+n}}const n=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-n,minY:Math.min(t.y1,t.y2)-n,maxX:Math.max(t.x1,t.x2)+n,maxY:Math.max(t.y1,t.y2)+n}}function Si(e,t){return!(e.minX>t.maxX||t.minX>e.maxX||e.minY>t.maxY||t.minY>e.maxY)}function ji(e,t,n,i,o,r,s,a){const c=o-e,l=(n+s)/2-Math.abs(c);if(0>=l)return null;const d=r-t,u=(i+a)/2-Math.abs(d);return u>0?u>l?{nx:ki(c),ny:0,penetration:l}:{nx:0,ny:ki(d),penetration:u}:null}function Ai(e,t,n,i,o,r,s){const a=r/2,c=s/2,l=e-xi(e,i-a,i+a),d=t-xi(t,o-c,o+c),u=l*l+d*d;if(u>n*n)return null;if(fi>=u){const r=Math.abs(e-(i-a)),s=Math.abs(e-(i+a)),l=Math.abs(t-(o-c)),d=Math.abs(t-(o+c)),u=Math.min(r,s,l,d);return u===r?{nx:-1,ny:0,penetration:n+r}:u===s?{nx:1,ny:0,penetration:n+s}:u===l?{nx:0,ny:-1,penetration:n+l}:{nx:0,ny:1,penetration:n+d}}const h=Math.sqrt(u);return{nx:l/h,ny:d/h,penetration:n-h}}function Ci(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,n,i,o,r){const s=i-e,a=o-t,c=n+r,l=s*s+a*a;if(l>=c*c)return null;if(fi>=l)return{nx:1,ny:0,penetration:c};const d=Math.sqrt(l);return{nx:s/d,ny:a/d,penetration:c-d}}(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return ji(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);if("circle"===e.shape.type&&"aabb"===t.shape.type){const n=Ai(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height);return n?{nx:-n.nx,ny:-n.ny,penetration:n.penetration}:null}return"aabb"===e.shape.type&&"circle"===t.shape.type?Ai(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height):null}function Ri(e,t){const n=t.shape;return"aabb"===n.type?"circle"===e.shape.type?Ai(e.x,e.y,e.shape.radius,n.x,n.y,n.width,n.height):ji(n.x,n.y,n.width,n.height,e.x,e.y,e.shape.width,e.shape.height):function(e,t,n,i,o,r,s,a=0){const c=r-i,l=s-o,d=c*c+l*l,u=d>fi?xi(((e-i)*c+(t-o)*l)/d,0,1):0,h=n+a/2,p=e-(i+c*u),m=t-(o+l*u),f=p*p+m*m;if(f>=h*h)return null;if(fi>=f){const e=Math.sqrt(d);return e>fi?{nx:-l/e,ny:c/e,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(f);return{nx:p/y,ny:m/y,penetration:h-y}}(e.x,e.y,"circle"===e.shape.type?e.shape.radius:Math.sqrt(e.shape.width*e.shape.width+e.shape.height*e.shape.height)/2,n.x1,n.y1,n.x2,n.y2,n.thickness??0)}function $i(e,t){return`${e}\0${t}`}function Pi(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Di(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,shape:gi(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function Bi(e){return e&&"function"!=typeof e?{property:e.property,equals:e.equals,notEquals:e.notEquals,oneOf:e.oneOf?.slice(),notOneOf:e.notOneOf?.slice()}:e}function Ti(e){return{id:e.id,shape:bi(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:Bi(e.bodyFilter),index:e.index}}function Ei(e,t){if(!t)return;let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}function Ni(e,t){return!!t?.some(t=>Object.is(e,t))}function Oi(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=Ei(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!Ni(n,t.oneOf)||t.notOneOf&&Ni(n,t.notOneOf))}function Fi(e,t){return Oi(t,e.bodyFilter)}var Wi=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...mi,...e},this.random=pi(this.options.seed)}init(e={}){this.options={...mi,...e},this.random=pi(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){const t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(fi,e.mass??1),bodyCollisions:e.bodyCollisions??!0,shape:gi(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(const t of e){this.bodies.delete(t);for(const e of Array.from(this.activeSensors))Pi(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const t of e)this.colliders.set(t.id,{...t,shape:bi(t.shape),bodyFilter:Bi(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(e){const t=e.id??"spring-"+this.nextSpringIndex;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,n){const i=this.bodies.get(e);i&&(i.vx+=t/i.mass,i.vy+=n/i.mass,this.wake(i))}step(e=this.options.fixedDt){const t=Math.max(0,e);if(this.lastEvents=[],0===t)return;const n=this.sortedBodies();for(const e of n)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);const i=this.options.maxVelocity;for(const e of n)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=this.options.velocityDamping,e.vy*=this.options.velocityDamping,i>0){const t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>i){const n=i/t;e.vx*=n,e.vy*=n}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear();const o=this.bodyPairKeys(n),r=this.sortedColliders().filter(e=>!e.sensor);for(let e=0;this.options.collisionIterations>e;e+=1)this.resolveBodyPairs(n,o,0===e),this.resolveColliders(n,r,0===e);this.updateSensors(n),this.updateSleeping(n,t)}settle(e=1200,t=this.options.fixedDt){let n=0;for(;e>n&&!this.allSleeping();)this.step(t),n+=1;return n}readState(e=[]){e.length=0;for(const t of this.sortedBodies())e.push({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:gi(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Pi)}allSleeping(){for(const e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(Di),colliders:this.sortedColliders().map(Ti),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){this.options={...e.options,gravity:{...e.options.gravity}},this.random=pi(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const t of e.bodies){const e=Di(t);this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(const t of e.colliders){const e=Ti(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(const t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});const e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(const t of Array.from(this.springs.values()).sort((e,t)=>e.id.localeCompare(t.id))){const n=this.bodies.get(t.bodyId);if(!n||n.sleeping)continue;const i="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!i)continue;const o=i.x-n.x,r=i.y-n.y,s=Math.sqrt(o*o+r*r);if(fi>=s)continue;const a=o/s,c=r/s,l=(s-t.restLength)*t.stiffness+((("vx"in i?i.vx:0)-n.vx)*a+(("vy"in i?i.vy:0)-n.vy)*c)*t.damping;n.vx+=l*a*e/n.mass,n.vy+=l*c*e/n.mass}}resolveBodyPairs(e,t,n){for(const i of t){const[t,o]=i.split(":").map(Number),r=e[t],s=e[o];if(!r||!s)continue;const a=Ci(r,s);a&&(this.resolveDynamicCollision(r,s,a),n&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(e){const t=Math.max(1,this.options.cellSize),n=new Map;for(let i=0;e.length>i;i+=1){if(!1===e[i].bodyCollisions)continue;const o=Mi(e[i]),r=Math.floor(o.minX/t),s=Math.floor(o.maxX/t),a=Math.floor(o.minY/t),c=Math.floor(o.maxY/t);for(let e=r;s>=e;e+=1)for(let t=a;c>=t;t+=1){const o=`${e}:${t}`,r=n.get(o);r?r.push(i):n.set(o,[i])}}const i=new Set;for(const t of Array.from(n.keys()).sort()){const o=n.get(t)??[];o.sort((e,t)=>e-t);for(let t=0;o.length>t;t+=1)for(let n=t+1;o.length>n;n+=1){const r=o[t],s=o[n];!1!==e[r].bodyCollisions&&!1!==e[s].bodyCollisions&&Si(Mi(e[r]),Mi(e[s]))&&i.add(`${r}:${s}`)}}return Array.from(i).sort((e,t)=>{const[n,i]=e.split(":").map(Number),[o,r]=t.split(":").map(Number);return n===o?i-r:n-o})}resolveDynamicCollision(e,t,n){e.sleeping&&this.contactOpposesGravity(n.nx,n.ny)&&this.supportedThisStep.add(t.id),t.sleeping&&this.contactOpposesGravity(-n.nx,-n.ny)&&this.supportedThisStep.add(e.id);const i=e.sleeping?0:1/e.mass,o=t.sleeping?0:1/t.mass,r=i+o;if(fi>=r)return;const s=Math.max(0,n.penetration-yi)/r;e.x-=n.nx*s*i,e.y-=n.ny*s*i,t.x+=n.nx*s*o,t.y+=n.ny*s*o;const a=(t.vx-e.vx)*n.nx+(t.vy-e.vy)*n.ny;if(a>0)return;const c=Math.abs(a),l=-(1+vi(e.restitution,t.restitution,this.options.restitution))*a/r,d=l*n.nx,u=l*n.ny;e.vx-=d*i,e.vy-=u*i,t.vx+=d*o,t.vy+=u*o,this.applyFriction(e,t,n,l,i,o),c>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,n,i,o,r){const s=-n.ny,a=n.nx,c=(t.vx-e.vx)*s+(t.vy-e.vy)*a,l=o+r;if(fi>=Math.abs(c)||fi>=l)return;const d=wi(e.friction,t.friction,this.options.friction),u=xi(-c/l,-i*d,i*d),h=u*s,p=u*a;e.vx-=h*o,e.vy-=p*o,t.vx+=h*r,t.vy+=p*r}resolveColliders(e,t,n){for(const i of e)for(const e of t){if(!Fi(e,i))continue;if(!Si(Mi(i),Ii(e)))continue;const t=Ri(i,e);t&&(this.resolveStaticCollision(i,e,t),this.contactOpposesGravity(t.nx,t.ny)&&this.supportedThisStep.add(i.id),n&&this.lastEvents.push({type:"contact",bodyId:i.id,otherId:e.id,sensor:!1}))}}resolveStaticCollision(e,t,n){e.x+=n.nx*Math.max(0,n.penetration-yi),e.y+=n.ny*Math.max(0,n.penetration-yi);const i=e.vx*n.nx+e.vy*n.ny;if(0>i){const o=vi(e.restitution,t.restitution,this.options.restitution);e.vx-=(1+o)*i*n.nx,e.vy-=(1+o)*i*n.ny;const r=-n.ny,s=n.nx,a=e.vx*r+e.vy*s,c=wi(e.friction,t.friction,this.options.friction);e.vx-=a*r*c,e.vy-=a*s*c}}updateSensors(e){const t=new Set,n=this.sortedColliders().filter(e=>e.sensor);for(const i of e){const e=Mi(i);for(const o of n){if(!Fi(o,i))continue;if(!Si(e,Ii(o)))continue;if(!Ri(i,o))continue;const n=$i(o.id,i.id);t.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:o.id})}}for(const e of Array.from(this.activeSensors).sort()){if(t.has(e))continue;const{sensorId:n,bodyId:i}=Pi(e);this.lastEvents.push({type:"sensor-exit",bodyId:i,sensorId:n})}this.activeSensors=t}updateSleeping(e,t){const n=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const i of e)Math.sqrt(i.vx*i.vx+i.vy*i.vy)>=this.options.sleepSpeed||Math.sqrt((i.x-i.prevX)*(i.x-i.prevX)+(i.y-i.prevY)*(i.y-i.prevY))>=this.options.sleepSpeed*t||n&&!this.supportedThisStep.has(i.id)?i.sleeping?this.wake(i):i.sleepTime=0:(i.sleepTime+=t,i.sleeping||this.options.sleepAfter>i.sleepTime||(i.sleeping=!0,i.vx=0,i.vy=0,this.lastEvents.push({type:"sleep",bodyId:i.id})))}contactOpposesGravity(e,t){const{x:n,y:i}=this.options.gravity,o=Math.hypot(n,i);return 1e-9>=o||-.2>(e*n+t*i)/o}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},qi=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Wi).capabilities,engine:"builtin"},this.world=new Wi(e)}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function zi(e={}){return new qi(e)}function Li(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):zi(t)}var Hi=["binId","targetBin","category","windowIndex","lane","group"];function Yi(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);const n=t-e.mean;e.mean+=n/e.count,e.m2+=n*(t-e.mean)}function _i(e){return{count:e.count,total:e.total,mean:e.count>0?e.mean:0,min:e.count>0?e.min:0,max:e.count>0?e.max:0,variance:e.count>1?e.m2/(e.count-1):0}}function Gi(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:1/0,max:e.count>0?e.max:-1/0}}function Vi(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Xi(e,t,n){return"function"==typeof e?e(t,n):"string"==typeof e?Vi(t,e):void 0}function Ui(e){if(null==e)return;const t=e+"";return t.trim()?t:void 0}function Ki(e){const t=_i(e.value);return{id:e.id,label:e.label,count:t.count,total:t.total,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:_i(e.x),y:_i(e.y),value:t}}var Qi=class{constructor(e=!1){this.bins=new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;const t=this.nextIndex;this.nextIndex+=1;const n=Ui(Xi(this.config.binAccessor,e,t))??function(e){for(const t of Hi){const n=Ui(Vi(e,t));if(n)return n}return"sediment"}(e),i=Ui(Xi(this.config.labelAccessor,e,t))??n,o=function(e,t,n){if("number"==typeof e)return e;const i="function"==typeof e?e(t,n):"string"==typeof e?Vi(t,e):1,o="number"==typeof i?i:Number(i);return Number.isFinite(o)?o:1}(this.config.valueAccessor,e,t),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(n);return s||(s={id:n,label:i,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(n,s)),s.label=i,s.lastBodyId=e.id,s.lastDatum=e.datum,Yi(s.x,e.x),Yi(s.y,e.y),Yi(s.value,o),r>0&&(s.bodyIds.push(e.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),Ki(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Ki)}restore(e=[]){this.bins.clear();for(const t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Gi(t.x),y:Gi(t.y),value:Gi(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){const e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function Zi(e,t={}){const{baselineY:n=0,binWidth:i=24,gap:o=2,maxHeight:r=80,value:s="count",x:a}=t,c=Math.max(1,...e.map(e=>e[s]));return e.map((e,t)=>{const l=Math.max(0,e[s]/c*r),d=a?.(e,t)??t*(i+o);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:d,y:n-l,width:i,height:l,meanX:e.x.mean,meanY:e.y.mean}})}function Ji(e){const t=Number(e);if(Number.isFinite(t)&&t>0)return Math.floor(t)}function eo(e){const t=Math.max(0,Math.floor(e.liveBodies)),n=Math.max(0,Math.floor(e.queuedBodies??0)),i=t+n,o=Ji(e.bodyLimit),r=Ji(e.engineMaxBodiesHint),s=function(e,t,n){if(!1===n)return;const i=Ji(n?.warnAt);return null!=i?i:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}(o,r,e.options),a=null==o?0:Math.max(0,t-o),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:o,engineMaxBodiesHint:r,liveBodies:t,overflow:a,projectedBodies:i,queuedBodies:n,state:c,warnAt:s}}var to={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},no={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function io(e={},t=no){return{chartId:e.chartId??t.chartId,chartType:e.chartType??t.chartType,sensors:e.sensors??t.sensors,onObservation:e.onObservation??t.onObservation,onSimulationStateChange:e.onSimulationStateChange??t.onSimulationStateChange}}function oo(e){return{...e,shape:{...e.shape},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function ro(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:void 0}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function so(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function ao(e){return{...oo(e),sequence:e.sequence,spawnAt:e.spawnAt}}function co(e){return e.map(e=>({...e,shape:{...e.shape},bodyFilter:e.bodyFilter&&"function"!=typeof e.bodyFilter?{...e.bodyFilter,oneOf:e.bodyFilter.oneOf?.slice(),notOneOf:e.bodyFilter.notOneOf?.slice()}:e.bodyFilter}))}function lo(e){return!1!==e&&{...e}}function uo(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function ho(e){return{...e,gravity:{...e.gravity}}}function po(e,t,n,i){if("circle"===e.shape.type){const o=e.x-t,r=e.y-n,s=e.shape.radius+i,a=o*o+r*r;return a>s*s?null:a}const o=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),r=Math.max(Math.abs(n-e.y)-e.shape.height/2,0),s=o*o+r*r;return s>i*i?null:s}function mo(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function fo(e,t={}){const{idPrefix:n="plot",includeFloor:i=!0,includeCeiling:o=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=t,l=[],d=e.x+e.width/2,u=e.y+e.height/2;return i&&l.push({id:n+"-floor",shape:{type:"aabb",x:d,y:e.y+e.height+c/2,width:e.width+2*a,height:c}}),o&&l.push({id:n+"-ceiling",shape:{type:"aabb",x:d,y:e.y-c/2,width:e.width+2*a,height:c}}),r&&l.push({id:n+"-left-wall",shape:{type:"aabb",x:e.x-a/2,y:u,width:a,height:e.height+2*c}}),s&&l.push({id:n+"-right-wall",shape:{type:"aabb",x:e.x+e.width+a/2,y:u,width:a,height:e.height+2*c}}),l}function yo(e){const{idPrefix:t="bin",count:n,domainStart:i,domainStep:o,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:d=!0,closedBefore:u,lidY:h=s,lidThickness:p=Math.max(2,c)}=e,m=[],f=s+(a-s)/2,y=Math.abs(a-s),g=l?n:n-1;if(d||l)for(let e=l?0:1;g>=e;e+=1){if(!d&&e>0&&n>e)continue;const s=r(i+e*o);m.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:s,y:f,width:c,height:y}})}if(null!=u)for(let e=0;n>e;e+=1){const n=i+e*o,s=n+o;if(s>=u)continue;const a=r(n),l=r(s);m.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:p}})}return m}var go={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function bo(e,t){const n={...e};for(const e of t)n[go[e]]++;return n}function xo(e,t,n){const i=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:i,revisions:bo(n,i)}}var vo=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=xo({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){const n=xo(e,t,this.revisions);this.revisions=n.revisions,this.latest=n;for(const e of[...this.listeners])e();return n}},wo=require("d3-quadtree"),ko=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,n,i,o,r=0){const s=this.ensure(e,t);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,r)+this.maxSearchRadius,d=i-l,u=i+l,h=o-l,p=o+l;return s.visit((e,t,s,l,m)=>{if(d>l||t>u||h>m||s>p)return!0;if(e.length)return!1;let f=e;for(;f;){const e=f.data;if(e){const t=po(e,i,o,Math.max(0,r));null!=t&&(c>t||t===c&&n.indexOf(e.id)>n.indexOf(a?.id??""))&&(a=e,c=t)}f=f.next}return!1}),a}ensure(e,t){if(this.tree&&this.revision===t)return this.tree;const n=e.readState();return 0===n.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=n.reduce((e,t)=>Math.max(e,function(e){return"circle"===e.shape.type?e.shape.radius:Math.hypot(e.shape.width,e.shape.height)/2}(t)),0),this.tree=(0,wo.quadtree)().x(e=>e.x).y(e=>e.y).addAll(n),this.revision=t,this.tree)}},Mo=["data","scene-geometry","data-paint","accessibility","evidence"],Io=["scene-geometry","data-paint","accessibility","evidence"],So=["overlay","accessibility","evidence"],jo=(e,t)=>({retainedData:e,invalidations:t}),Ao=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Co=["scene-geometry","data-paint","accessibility","evidence"],Ro=[],$o={engine:jo("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:jo("preserve",Co),colliders:jo("preserve",Co),sediment:jo("preserve",Co),bodyBudget:jo("preserve",Ao),bodyLimit:jo("preserve",Ao),eviction:jo("preserve",Ao),fixedDt:jo("preserve",Ro),maxDeltaSeconds:jo("preserve",Ro),maxSubsteps:jo("preserve",Ro),settleStepLimit:jo("preserve",Ro),timeScale:jo("preserve",Ro),observation:jo("preserve",Ro)},Po=jo("preserve",Ao);function Do(e){let t="preserve";const n=new Set;for(const i of e){const e=$o[i]??Po;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)n.add(t)}return{retainedData:t,invalidations:n}}var Bo=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function To(e,t){return e===t||!(!e||!t)&&e.gravity?.x===t.gravity?.x&&e.gravity?.y===t.gravity?.y&&Bo.every(n=>e[n]===t[n])}function Eo(e,t,n,i){return e||!t?"paused":n||!i?"running":"settled"}var No=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=function(e){const t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,n){if(n>0)return void(this.seconds=0);const i=e.readState(this.scratch),o=this.speed*this.speed;let r=!0;for(const e of i)if(!e.sleeping&&e.vx*e.vx+e.vy*e.vy>=o){r=!1;break}this.seconds=r?this.seconds+Math.max(0,t):0}},Oo=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new ko,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new vo,this.simulationState="settled",this.visible=!0,this.quiescence=new No;const{bodyBudget:t,colliders:n,engine:i,kernel:o,observation:r,sediment:s,...a}=e;this.config={...to,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=i,this.observation=io(r),this.sediment=new Qi(s??!1),this.world=Li(i,{fixedDt:this.config.fixedDt,...o}),this.quiescence.setKernelOptions(o),n&&this.world.setColliders(co(n))}updateConfig(e){const t=function(e,t){return Object.keys(e).filter(n=>"kernel"===n?!To(e.kernel,t.kernel):e[n]!==t[n])}(e,this.configInput),{colliders:n,bodyBudget:i,engine:o,kernel:r,observation:s,sediment:a,...c}=e;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),o&&o!==this.engineInput){const e=this.world.snapshot();this.world.dispose(),this.engineInput=o,this.world=Li(o,e.options),this.world.restore(e),this.revision+=1}if(r&&!To(r,this.configInput.kernel)){const e=this.world.snapshot(),t={...e.options,...r,gravity:{...e.options.gravity,...r.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}s&&(this.observation=io(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(co(n)),this.revision+=1),this.configInput={...this.configInput,...e};const l=Do(t);this.updateResults.record({kind:"config",keys:t},l.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(co(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Do(["colliders"]).invalidations)}enqueue(e,t){const n=Array.isArray(e)?e:[e],i=t?function(e,t={}){const n=ro(t.startAt)??0,i=t.pacing??"immediate";if("arrival"===i){const i=e.map((e,n)=>function(e,t,n){return"function"==typeof n?ro(n(e,t)):"string"==typeof n?ro(so(e,n)):ro(e.spawnAt)??ro(so(e,"arrivalTime"))??ro(so(e,"timestamp"))??ro(so(e,"time"))??ro(so(e,"eventTime"))}(e,n,t.timeAccessor)),o=i.filter(e=>null!=e),r=o.length>0?Math.min(...o):0,s=ro(t.timeScale)??1,a=s>0?s:1;return e.map((e,t)=>{const o=i[t],s=null==o?0:Math.max(0,o-r);return{...oo(e),spawnAt:n+s/a}})}if("object"==typeof i){const t=ro(i.ratePerSec);if(t&&t>0)return e.map((e,i)=>({...oo(e),spawnAt:n+i/t}))}return e.map(e=>({...oo(e),spawnAt:n}))}(n,{...t,startAt:t.startAt??this.elapsedSeconds}):n;for(const e of i)this.queue.push({...oo(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(uo),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?Mo:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(oo(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},Mo)}materializeDueSpawns(){const e=this.revision,t=[],n=[];return this.spawnDue(t,n),0===t.length||(this.observeBodyBudget(n),this.evictOverflow(n),this.syncSimulationState(n),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?Mo:[])),t}clear(){const e=this.world.snapshot().options;this.world.init({...e,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},Mo)}tick(e){const t=this.revision,n=[],i=[],o=[],r=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,o,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}const a=Math.max(0,Math.min(e,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(n,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);i.push(...l.evicted),o.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let d=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>d;){this.world.step(this.config.fixedDt);const e=this.world.events();r.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,d+=1}d===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,n.length),(d>0||n.length>0||i.length>0||o.length>0||r.length>0)&&(this.revision+=1);const u=this.result(d,n,i,o,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:d},this.revision!==t?n.length||i.length||o.length?Mo:Io:[]),u}settle(e=this.config.settleStepLimit){return this.runSettle(e,!1).steps}settleWithObservations(e=this.config.settleStepLimit){return this.runSettle(e,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:e=>{this.elapsedSeconds+=e},spawnDue:(e,t)=>this.spawnDue(e,t),observeBodyBudget:e=>this.observeBodyBudget(e),evictOverflow:e=>this.evictOverflow(e),step:e=>this.world.step(e),drainEvents:()=>this.world.events(),observeKernelEvents:(e,t)=>this.observeKernelEvents(e,t),observeSensorTransitions:e=>this.observeSensorTransitions(e),refreshQuiescence:(e,t)=>this.quiescence.refresh(this.world,e,t)}}runSettle(e,t){const n=this.revision,i=[],o=[],r=[],s=[],a=t?[]:void 0;if(t&&(this.paused||!this.visible)){const e=this.result(0,i,o,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(i,a);const c=this.observeBodyBudget(a),l=this.evictOverflow(a);o.push(...l.evicted),r.push(...l.sedimented),this.syncSimulationState(a),i.length>0&&this.quiescence.reset();const d=t?{spawned:i,evicted:o,sedimented:r,events:s,observations:a}:{spawned:i},{steps:u,budget:h}=function(e,t,n){let i,o=0;for(;t>o&&(e.queueSize()>0||!e.atRest());){e.advanceTime(e.fixedDt);const t=[];if(e.spawnDue(t,n.observations),t.length>0){n.spawned.push(...t),i=e.observeBodyBudget(n.observations);const o=e.evictOverflow(n.observations);n.evicted?.push(...o.evicted),n.sedimented?.push(...o.sedimented)}e.step(e.fixedDt);const r=e.drainEvents();n.events&&(n.events.push(...r),e.observeKernelEvents(r,n.observations),e.observeSensorTransitions(n.observations)),o+=1,e.refreshQuiescence(e.fixedDt,t.length)}return{steps:o,budget:i}}(this.settleHost(),e,d),p=i.length+o.length+r.length>0;(u>0||p||s.length>0)&&(this.revision+=1);const m=this.result(u,i,o,r,s,a??[],void 0,h??c);return this.updateResults.record({kind:"settle",count:u},this.revision===n?[]:p?Mo:Io),m}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return Zi(this.readSediment(),e)}hitTest(e,t,n=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){const{timestamp:t,chartType:n,chartId:i,...o}=e,r={...o,timestamp:t??this.elapsedSeconds,chartType:n??this.observation.chartType,chartId:i??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){const t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?So:[])}setVisible(e){const t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?So:[])}remove(e){const t=new Set(e),n=new Set(this.liveBodyOrder),i=new Set(this.queue.map(e=>e.id));this.queue=this.queue.filter(e=>!t.has(e.id)),this.liveBodyOrder=this.liveBodyOrder.filter(e=>!t.has(e)),this.world.remove(e),this.removeActiveSensorPairsForBodies(t);const o=e.filter(e=>n.has(e)||i.has(e));return o.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:o,count:o.length},o.length?Mo:[]),o}setConstraint(e){const t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},Io),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},Io)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},Io)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,n,i)=>e.applyImpulse(t,n,i),clear:()=>e.clear(),hitTest:(t,n,i)=>e.hitTest(t,n,i),pause:()=>e.setPaused(!0),push:(t,n)=>e.enqueue(t,n),pushMany:(t,n)=>e.enqueue(t,n),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}snapshot(){const e=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:lo(this.bodyBudget),config:{...this.config,kernel:ho(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(ao),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:e}}restore(e){this.config={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale},this.configInput={...e.config,bodyBudget:lo(e.bodyBudget??{}),kernel:ho(e.world.options)},this.bodyBudget=lo(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(e.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(ao).sort(uo),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??Eo(e.paused,e.visible,e.queue.length>0,e.world.bodies.every(e=>e.sleeping)),this.liveBodyOrder=e.liveBodyOrder.slice(),this.visible=e.visible,this.nextSequence=this.queue.reduce((e,t)=>Math.max(e,t.sequence),-1)+1,this.world.restore(e.world),this.updateResults.record({kind:"restore"},Mo)}spawnDue(e,t){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const n=this.queue.shift();if(!n)return;this.spawnOne(n,t),e.push(n.id)}}spawnOne(e,t){this.liveBodyOrder=this.liveBodyOrder.filter(t=>t!==e.id),this.removeActiveSensorPairsForBodies(new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.push(e.id);for(const t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});const n=this.world.readState().find(t=>t.id===e.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:e.id,datum:n?.datum??e.datum,x:n?.x??e.x,y:n?.y??e.y},t)}result(e,t,n,i,o,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:o,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:c,sedimented:i,spawned:t,steps:e}}observeKernelEvents(e,t){!function(e,t,n){if(0===t.length)return;const i=new Map(e.readState().map(e=>[e.id,e]));for(const e of t){if("sleep"!==e.type)continue;const t=i.get(e.bodyId);n.emit({type:"physics-settle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}(this.world,e,this.observationContext(t))}observeSensorTransitions(e){this.activeSensorPairs=function(e,t,n){const i=new Set(e.activeSensorPairs().map(e=>`${e.sensorId}\0${e.bodyId}`));if(0===i.size&&0===t.size)return i;const o=new Map(e.readState().map(e=>[e.id,e])),r=(e,t)=>{const{sensorId:i,bodyId:r}=mo(t),s=n.observation.sensors[i],a=o.get(r);n.emit({type:"enter"===e?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:i,binId:s?.binId??i})};for(const e of Array.from(i).sort())t.has(e)||r("enter",e);for(const e of Array.from(t).sort())i.has(e)||r("exit",e);return i}(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){!function(e,t){for(const n of e)t.has(mo(n).bodyId)&&e.delete(n)}(this.activeSensorPairs,e)}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return eo({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){const t=this.evaluateBodyBudget();if("ok"===t.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",t;const n=`${t.state}:${t.action}`;return n===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=n,this.emitObservation({type:"overflow"===t.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:t.action,bodyLimit:t.bodyLimit,engineMaxBodiesHint:t.engineMaxBodiesHint,liveBodies:t.liveBodies,overflow:t.overflow,projectedBodies:t.projectedBodies,queuedBodies:t.queuedBodies,warnAt:t.warnAt},e)),t}syncSimulationState(e){const t=Eo(this.paused,this.visible,this.queue.length>0,this.atRest());if(t===this.simulationState)return;const n=this.simulationState;this.simulationState=t,function(e,t,n){n.observation.onSimulationStateChange?.(t,e),"running"!==t&&"settled"!==t||n.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,simulationState:t,previousSimulationState:e})}(n,t,this.observationContext(e))}evictOverflow(e){const{evicted:t,sedimented:n,liveBodyOrder:i}=function(e,t,n,i,o,r){const s={evicted:[],sedimented:[],liveBodyOrder:o};if(!1===n)return s;const a=Math.max(0,Math.floor(i));if(!Number.isFinite(a))return s;const c=o.length-a;if(0>=c)return s;const l=function(e,t,n){if("sleeping-first"!==t)return n.slice();const i=new Map(e.readState().map(e=>[e.id,e.sleeping])),o=[],r=[];for(const e of n)i.get(e)?o.push(e):r.push(e);return[...o,...r]}(e,n,o),d=l.slice(0,c);if(0===d.length)return s;const u=function(e,t,n,i){const o=new Map(e.readState().map(e=>[e.id,e])),r=[];for(const e of n){const n=o.get(e);if(!n)continue;const s=t.add(n);s&&(r.push(e),i.emit({type:"physics-sediment",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:e,datum:n.datum,x:n.x,y:n.y,binId:s.id,count:s.count,total:s.total}))}return r}(e,t,d,r);e.remove(d);const h=new Set(d);return{evicted:d,sedimented:u,liveBodyOrder:o.filter(e=>!h.has(e))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=i,this.removeActiveSensorPairsForBodies(new Set(t))),{evicted:t,sedimented:n}}};function Fo(e,t,n){const i=new Oo(e);return t?.length&&(i.enqueue(t,n),i.materializeDueSpawns()),i}function Wo(){return"undefined"!=typeof performance?performance.now():Date.now()}var qo=c(require("react-dom/server"));function zo(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}var Lo={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Ho(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Yo(e,t){const n="function"==typeof t?t(e):t;return{...Lo,...n??{}}}function _o(e,t={}){const n=e.settle(t.maxSteps),i=e.readBodies(),o=e.snapshot(),r=function(e,t={}){return e.map(e=>function(e,t={}){const n=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),i={label:t.getBodyLabel?.(e)??Ho(e)},o={style:Yo(e,t.bodyStyle),datum:n,accessibleDatum:n,accessibility:i,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}(e,t))}(i,t),s=function(e,t={}){const n=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),i=n.filter(e=>e.sleeping).length,o=e.queue.length,r=e.sediment.reduce((e,t)=>e+t.count,0),s="settled"===e.simulationState&&0===o&&i===n.length,a=[];o>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const c=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,n,i){const o=e-(t+n+i);return{charge:e,live:t,queued:n,sedimented:i,unaccounted:o,balanced:0===o}}(t.charge,n.length,o,r):void 0;return c&&!c.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:n.length,sleepingCount:i,settled:s,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:zo(t.projectionRows),queuedCount:o,sedimentedCount:r,...c?{ledger:c}:{},warnings:a}}(o,{bodies:i,projectionRows:t.projectionRows,stepsRun:n,charge:t.charge});return{snapshot:o,bodies:i,sceneNodes:r,evidence:s,stepsRun:n}}var Go=require("react/jsx-runtime"),Vo={top:0,right:0,bottom:0,left:0};function Xo(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function Uo(e,t){if("function"==typeof t){const n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}const n=e.datum;if(t&&n&&"object"==typeof n){const e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}const i=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(i)&&i>0?i:1}function Ko(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=Ei(e.datum,t),i=Ei(e,t),o=n??i;if(null!=o&&(o+"").length>0)return o+""}return e.id}function Qo(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];const n=Math.max(0,Math.min(1,t))*(e.length-1),i=Math.floor(n);return e[i]+(e[Math.ceil(n)]-e[i])*(n-i)}function Zo(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),i=e.queueLayout??"lane",o=e.queueSlotSpacing??14,r=e.queueStiffness??.35,s=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,a=Math.max(.25,e.metricWindowSeconds??30),c=Math.max(1/60,e.snapshotIntervalSeconds??.25),l=e.releaseImpulse??{x:90,y:0},d=new Map,u=new Map,h=new Map,p=new Map,m=new Map,f=new Map,y=new Map,g=[];let b=0,x=new Map,v=new Map,w=0,k=0,M=0,I=null,S=0,j=0,A=0,C=0,R=0,$=0,P=0,D=0,B=0,T=0,E=0,N=0,O=-1,F=!1;function W(e,n){const i=n(e);return!!i&&i.activeRegionIds.includes(t)}function q(){N+=1}function z(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function L(n,i,o,r){const s={bodyId:n.id,jobId:i.jobId,visitId:i.visitId,visit:i.visit,remaining:i.work,total:i.work,queuedAt:i.queuedAt,sequence:r};return d.set(i.jobId,s),y.delete(n.id),f.set(n.id,i.jobId),j+=1,A+=i.work,q(),function(n,i,o){const r=z(i);e.onQueued?.(n,r),o.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:i.total,jobId:i.jobId,visitId:i.visitId,visit:i.visit,queuedAt:i.queuedAt,queueDepth:d.size})}(n,s,o),s}function H(e){if(d.size>=s||0===u.size)return;const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);for(const n of t){if(d.size>=s)break;const t=m.get(n.jobId);t&&h.has(n.jobId)?(u.delete(n.jobId),y.delete(n.bodyId),L(t,n,e,n.sequence)):u.delete(n.jobId)}}function Y(){let e=0;for(const t of d.values())e+=t.remaining;return e}function _(){B=Math.max(B,d.size),T=Math.max(T,Y())}function G(){const e=M-a,t=Math.max(0,Math.min(a,M-(I??M)));let i=0,o=0,r=0,s=0,c=0;for(const t of g){if(e>t.end)continue;i+=t.arrivals,o+=t.arrivalWork,r+=t.completions,s+=t.completedWork;const n=t.end-t.start;c+=n>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/n):t.processedWork}const l=t>0?o/t:0;return{seconds:t,arrivals:i,arrivalWork:o,completions:r,completedWork:s,processedWork:c,arrivalsPerSecond:t>0?i/t:0,throughputPerSecond:t>0?r/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,c/(n*t))):0,pressure:n>0?l/n:0}}return{id:e.id??"capacity-queue:"+t,continuous:!1!==e.continuous,tick:i=>{const o=i.controls.readBodies(),r=new Map,j=new Map;for(const t of o){if(r.set(t.id,t),!W(t.id,i.getRegionState))continue;if(!Oi(t,e.bodyFilter))continue;const n=Ko(t,e.jobKey),o=j.get(n)??[];o.push(t),j.set(n,o)}const A=Number.isFinite(i.dt)?Math.max(0,i.dt):0;if(!F){const e=Number.isFinite(i.elapsed)?Math.max(0,i.elapsed):A;M=Math.max(0,e-A),F=!0}const B=M,T=B+A;M=T,I=null==I?B:Math.min(I,B);const N={start:B,end:T,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},Y=new Map;for(const[e,t]of j){const n=h.get(e)?.bodyId,i=t.find(e=>e.id===n)??t[0];Y.set(e,i),m.set(e,i)}for(const[n,o]of h){if(Y.has(n))continue;const s=d.get(n),a=r.get(o.bodyId)??m.get(n);if(s){d.delete(n),f.delete(s.bodyId),P+=1,D+=s.remaining,q();const r={...z(s),abandonedAt:M,remainingWork:s.remaining,queueSeconds:Math.max(0,M-s.queuedAt)};a&&e.onAbandoned?.(a,r),i.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:o.bodyId,datum:a?.datum,x:a?.x,y:a?.y,regionId:t,work:s.total,remainingWork:s.remaining,jobId:n,visitId:s.visitId,visit:s.visit,queuedAt:s.queuedAt,abandonedAt:M,queueSeconds:r.queueSeconds,queueDepth:d.size})}u.delete(n),y.delete(o.bodyId),h.delete(n),m.delete(n)}for(const[n,o]of Y){if(h.has(n))continue;const r=(p.get(n)??0)+1;p.set(n,r);const a=Uo(o,e.unitAccessor),c={bodyId:o.id,jobId:n,visitId:`${t}:${n}:${r}`,visit:r,regionId:t,work:a,queuedAt:M};h.set(n,c),S+=1,N.arrivals+=1,N.arrivalWork+=a;const l=b++;if(s>d.size)L(o,c,i,l);else{const s={...c,blockedAt:M,sequence:l};u.set(n,s),y.set(o.id,n),$+=1,q(),e.onBlocked?.(o,s),i.controls.recordObservation({type:"physics-capacity-blocked",bodyId:o.id,datum:o.datum,x:o.x,y:o.y,regionId:t,work:a,jobId:n,visitId:c.visitId,visit:r,queuedAt:M,blockedAt:M,queueDepth:d.size,blockedDepth:u.size})}}H(i),_();const G=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);let V=n*A;for(const n of G){if(0>=V)break;const o=Math.min(n.remaining,V);if(n.remaining-=o,V-=o,C+=o,N.processedWork+=o,n.remaining>1e-6)continue;d.delete(n.jobId),f.delete(n.bodyId),k+=1,R+=n.total,N.completions+=1,N.completedWork+=n.total;const s=Math.max(0,M-n.queuedAt);E+=s,q();const a=r.get(n.bodyId);if(!a)continue;i.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...z(n),completedAt:M,queueSeconds:s};e.onProcessed?.(a,c),i.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:a.datum,x:a.x,y:a.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:M,queueSeconds:s,queueDepth:d.size})}H(i),_(),function(){const e=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);x=new Map(e.map((e,t)=>[e.bodyId,t]));const t=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);v=new Map(t.map((e,t)=>[e.bodyId,t])),w=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&g.push(e);const t=M-a;for(;g.length>0&&t>g[0].end;)g.shift()}(N);const X=Math.floor(M/c);X!==O&&(O=X,q())},getSnapshot:()=>{const e=Y(),i=function(){let e=0;for(const t of u.values())e+=t.work;return e}(),o=d.size,r=Array.from(d.values()).map(e=>Math.max(0,M-e.queuedAt)).sort((e,t)=>e-t),s=r.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:o,processedCount:k,unitsPerSecond:n,remainingWork:e,meanRemainingWork:o>0?e/o:0,waitingWork:e+i,blockedDepth:u.size,blockedWork:i,arrivalCount:S,admittedCount:j,admittedWork:A,processedWork:C,completedWork:R,blockedCount:$,abandonedCount:P,abandonedWork:D,peakQueueDepth:B,peakRemainingWork:T,queueAge:{count:r.length,meanSeconds:r.length>0?s/r.length:0,p50Seconds:Qo(r,.5),p95Seconds:Qo(r,.95),oldestSeconds:r.at(-1)??0},meanCompletedQueueSeconds:k>0?E/k:0,window:G(),simulatedAt:M,metricRevision:N}},bodyForce:e=>{if("none"===i)return null;const n=f.get(e.body.id),s=y.get(e.body.id),a=n?d.get(n):void 0,c=s?u.get(s):void 0;if(!a&&!c)return null;const l=a?x.get(e.body.id):v.get(e.body.id);if(null==l)return null;let h;const p=e.regions;if(p)for(let e=0;p.length>e;e+=1)if(p[e].id===t){const t=p[e].shape;t&&"aabb"===t.type&&(h=t);break}return h?{x:((c?h.x-.44*h.width:h.x-.22*h.width-l*(.15*o))-e.body.x)*r,y:(h.y-(l-((c?u.size:w)-1)/2)*o/Math.max(1,Math.sqrt(c?u.size:w))-e.body.y)*r*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function Jo(e){const t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),i=new Map,o=new Map,r=e.assignmentForce??.45,s=e.returnForce??.35,a=e.caseAttraction??.08,c=e.assignmentOffset??{x:0,y:0};let l=new Map,d=0,u=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{const n=i.get(e);if(n)return n;const r=t.find(e=>!o.has(e.id));if(!r)return null;const s={resourceId:r.id,resourceBodyId:r.bodyId,caseBodyId:e,assignedAt:d};return i.set(e,s),o.set(r.id,s),u+=1,s},release:e=>{const t=i.get(e);return!!t&&(i.delete(e),o.delete(t.resourceId),u+=1,!0)},getAssignment:e=>i.get(e),tick:e=>{d=Math.max(d,e.elapsed),l=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(const[e,t]of i)l.has(e)&&l.has(t.resourceBodyId)||(i.delete(e),o.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-o.size,assigned:o.size,assignments:Array.from(i.values()),simulatedAt:d,metricRevision:u}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=o.get(t.id),i=n?l.get(n.caseBodyId):void 0,a=n?r:s;return{x:((i?i.x+(c.x??0):t.home.x)-e.body.x)*a,y:((i?i.y+(c.y??0):t.home.y)-e.body.y)*a}}const d=i.get(e.body.id);if(!d||0>=a)return null;const u=l.get(d.resourceBodyId);return u?{x:(u.x-e.body.x)*a,y:(u.y-e.body.y)*a}:null}}}function er(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):Ei(e.datum,t.deadlineAccessor)??Ei(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function tr(e){const t=new Map;let n=0,i=0;function o(n){t.set(n.bodyId,n),i+=1,e.onStateChange?.({...n})}function r(e){const i=t.get(e);return!(!i||null!=i.completedAt||(o({...i,completedAt:n,state:"unhappy"===i.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{const i=t.get(e);return!(!i||null!=i.completedAt||"unhappy"===i.state||(o({...i,state:"protected",protectedAt:n}),0))},complete:r,getCase:e=>t.get(e),tick:i=>{n=Math.max(n,i.elapsed);for(const s of i.controls.readBodies()){if(!Oi(s,e.bodyFilter))continue;if(!t.has(s.id)){const t=er(s,e);o({bodyId:s.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}const a=t.get(s.id);a&&null==a.completedAt&&(e.completionRegionId&&i.getRegionState(s.id)?.activeRegionIds.includes(e.completionRegionId)?r(s.id):"waiting"!==a.state||a.deadlineAt>n||o({...a,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),o=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:o("waiting"),protected:o("protected"),unhappy:o("unhappy"),resolved:o("resolved"),resolvedUnhappy:o("resolved-unhappy"),simulatedAt:n,metricRevision:i}}}}function nr(e){const t=new Set;let n=0,i=0,o=0,r=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:s=>{n=Math.max(n,s.elapsed);const a=r;var c;c=n,r=e.isOpen?e.isOpen(c):null!=e.opensAt&&c>=e.opensAt;const l=s.controls.readBodies(),d=new Map(l.map(e=>[e.id,e]));for(const n of l){const i=s.getRegionState(n.id)?.activeRegionIds.includes(e.regionId);i&&Oi(n,e.bodyFilter)&&(r||t.has(n.id)||(t.add(n.id),o+=1,e.onHeld?.(n)))}if(r&&!a){for(const n of t){const t=d.get(n);t&&(s.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),i+=1,e.onReleased?.(t))}t.clear(),o+=1}for(const e of t)d.has(e)||(t.delete(e),o+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:r,blocked:t.size,released:i,simulatedAt:n,metricRevision:o}),bodyForce:n=>{if(r||!t.has(n.body.id))return null;const i=n.regions?.find(t=>t.id===e.regionId),o=i?.shape;if(!o||"aabb"!==o.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const s=e.holdForce??.4;return{x:(o.x-n.body.x)*s-.45*n.body.vx,y:(o.y-n.body.y)*s-.45*n.body.vy}}}}function ir(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function or(e){if(!e?.length)return null;const t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,i)=>{const o={result:e,controls:n,dt:i.dt,elapsed:i.elapsed,getRegionState:i.getRegionState};for(const e of t)e.tick(o)},bodyForce:e=>{let n=null;for(const i of t)i.bodyForce&&(n=ir(n,i.bodyForce(e)));return n}}}function rr(e){const t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:i=>{const o=i.controls.readBodies();for(const r of o){const o=i.getRegionState(r.id),s=o?.activeRegionIds.includes(e.fromRegionId);s?t.has(r.id)||(t.add(r.id),i.controls.applyImpulse(r.id,n.x??0,n.y??0),e.onPortal?.(r)):t.delete(r.id)}}}}var sr=require("react");function ar(){return"undefined"==typeof document||!document.hidden}var cr=require("react/jsx-runtime"),lr="var(--semiotic-focus, #005fcc)";function dr({active:e,hoverPoint:t,margin:n,size:i,shape:o="circle",width:r,height:s,pathData:a}){if(!e||!t)return null;const c=t.x+n.left,l=t.y+n.top;let d;if("geoarea"!==o&&"path"!==o||!a)if("rect"===o&&null!=r&&null!=s){const e=Math.max(r,4),t=Math.max(s,4);d=(0,cr.jsx)("rect",{x:c-e/2-3,y:l-t/2-3,width:e+6,height:t+6,rx:3,fill:"none",stroke:lr,strokeWidth:2,strokeDasharray:"4,2"})}else d=(0,cr.jsx)("circle","wedge"===o?{cx:c,cy:l,r:12,fill:"none",stroke:lr,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:c,cy:l,r:8,fill:"none",stroke:lr,strokeWidth:2,strokeDasharray:"4,2"});else d=(0,cr.jsx)("g",{transform:`translate(${n.left},${n.top})`,children:(0,cr.jsx)("path",{d:a,fill:"none",stroke:lr,strokeWidth:2.5,strokeDasharray:"6,3"})});return(0,cr.jsx)("svg",{style:{position:"absolute",left:0,top:0,width:i[0],height:i[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:d})}var ur=require("react"),hr={sceneGeometry:0,layout:0,domain:0};function pr(e){const{domain:t,layout:n,sceneGeometry:i}=e.revisions;return{domain:t,layout:n,sceneGeometry:i}}function mr(e,t){return{sceneGeometry:Math.max(e.sceneGeometry,t.sceneGeometry),layout:Math.max(e.layout,t.layout),domain:Math.max(e.domain,t.domain)}}var fr="production"!==process.env.NODE_ENV,yr={revisions:hr,signature:"",sawSignals:!1,wasUnconsumed:!1,warnUnconsumed:!1},gr=class{constructor(e="scene host"){this.hostName=e,this.lastConsumed=hr,this.lastObserved=hr,this.lastDuplicateWarning="",this.lastUnconsumedWarning=""}observeUpdateResult(e){fr&&(this.lastObserved=mr(this.lastObserved,pr(e)))}beforeCompute(e,t){if(!fr)return yr;const n=mr(pr(e),this.lastObserved),i=function(e){return`${e.sceneGeometry}|${e.layout}|${e.domain}`}(n),o=!((r=n).sceneGeometry===(s=this.lastConsumed).sceneGeometry&&r.layout===s.layout&&r.domain===s.domain);var r,s;return{revisions:n,signature:i,sawSignals:e.changed.has("scene-geometry")||e.changed.has("layout")||e.changed.has("domain"),wasUnconsumed:o,warnUnconsumed:!t&&o&&this.lastUnconsumedWarning!==i}}afterCompute(e,t,n){if(fr){if(t&&e.wasUnconsumed&&(this.lastConsumed=e.revisions),e.warnUnconsumed&&!t)return console.warn(`[semiotic] ${this.hostName} observed scene-affecting revisions without a scene rebuild: ${e.signature}.`),void(this.lastUnconsumedWarning=e.signature);t&&e.sawSignals&&!e.wasUnconsumed&&!n&&this.lastDuplicateWarning!==e.signature?(console.warn(`[semiotic] ${this.hostName} performed scene rebuild with unchanged scene revisions: ${e.signature}.`),this.lastDuplicateWarning=e.signature):t&&!e.sawSignals&&(this.lastDuplicateWarning="")}}},br=(0,ur.memo)(function({store:e,diagnostics:t}){return(0,ur.useEffect)(()=>{const n=()=>t.observeUpdateResult(e.getUpdateSnapshot());return n(),e.subscribeUpdateResult(n)},[t,e]),null}),xr=(c(require("react")),c(require("react"))),vr=(require("react/jsx-runtime"),xr.createContext(null)),wr=require("react/jsx-runtime"),kr={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function Mr({hoverPoint:e}){let t="";if(e){const n=e.data||e;t="object"==typeof n?"Data point: "+Object.entries(n).filter(([,e])=>"object"!=typeof e&&"function"!=typeof e).map(([e,t])=>`${e}: ${t}`).join(", "):"Data point: "+n}return(0,wr.jsx)("div",{"aria-live":"polite","aria-atomic":"true",style:kr,children:t})}var Ir=require("react/jsx-runtime");function Sr({summary:e}){return e?(0,Ir.jsx)("div",{role:"note",style:kr,children:e}):null}function jr({tableId:e}){return(0,Ir.jsx)("a",{href:"#"+e,style:kr,onClick:t=>{t.preventDefault();const n=document.getElementById(e);n&&requestAnimationFrame(()=>n.focus())},onFocus:e=>{Object.assign(e.currentTarget.style,{position:"absolute",width:"auto",height:"auto",overflow:"visible",clip:"auto",whiteSpace:"normal",padding:"4px 8px",background:"var(--semiotic-bg, #fff)",color:"var(--semiotic-text, #000)",border:"2px solid var(--semiotic-focus, #005fcc)",borderRadius:"4px",zIndex:"10",fontSize:"12px",top:"4px",left:"4px"})},onBlur:e=>{const t=e.currentTarget;t.removeAttribute("style"),Object.assign(t.style,kr)},children:"Skip to data table"})}function Ar(e,t,n){const i=me(e,n.fill)??"#4e79a7",o=me(e,n.stroke),r="none"!==o?o:void 0,s=n.strokeWidth??0,a=n.opacity??1,c=n.fillOpacity??1,l=function(e,t){const n=t.mark;if(n)return n;const i=e.datum,o=i?.__physicsMark??i?.mark;return"circle"===o||"halo"===o||"faceted"===o||"pill"===o||"diamond"===o||"square"===o?o:"circle"===e.shape.type?"circle":"square"}(t,n),d="circle"===t.shape.type?n.r??t.shape.radius:Math.max(t.shape.width,t.shape.height)/2;if(e.save(),e.globalAlpha*=a,e.beginPath(),"pill"===l||"square"===l||"aabb"===t.shape.type){const n="pill"===l?2.4*d:"aabb"===t.shape.type?t.shape.width:1.7*d,i="pill"===l?1.35*d:"aabb"===t.shape.type?t.shape.height:1.7*d,o=t.x-n/2,r=t.y-i/2,s="pill"===l?i/2:Math.min(4,n/4);e.moveTo(o+s,r),e.arcTo(o+n,r,o+n,r+i,s),e.arcTo(o+n,r+i,o,r+i,s),e.arcTo(o,r+i,o,r,s),e.arcTo(o,r,o+n,r,s),e.closePath()}else if("diamond"===l)e.moveTo(t.x,t.y-d),e.lineTo(t.x+d,t.y),e.lineTo(t.x,t.y+d),e.lineTo(t.x-d,t.y),e.closePath();else if("faceted"===l){const n=6;for(let i=0;n>i;i+=1){const o=2*Math.PI*i/n-Math.PI/2,r=t.x+Math.cos(o)*d,s=t.y+Math.sin(o)*d;0===i?e.moveTo(r,s):e.lineTo(r,s)}e.closePath()}else e.arc(t.x,t.y,d,0,2*Math.PI);i&&(e.save(),e.globalAlpha*=c,e.fillStyle=i,e.fill(),e.restore()),"halo"===l&&(e.beginPath(),e.arc(t.x,t.y,1.35*d,0,2*Math.PI),e.strokeStyle=r??i,e.lineWidth=Math.max(1.5,s||1.5),e.globalAlpha*=.55,e.stroke(),e.globalAlpha/=.55),r&&s>0&&(e.strokeStyle=r,e.lineWidth=s,n.strokeDasharray&&e.setLineDash(n.strokeDasharray.split(/[,\s]+/).map(e=>Number(e)).filter(e=>Number.isFinite(e))),e.stroke()),e.restore()}function Cr(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function Rr(e){return e.sensorId??"stream-region-"+e.id}function $r(e){const t=Rr(e),n={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){const i=e.colliderThickness??8,o=e.shape.x-e.shape.width/2,r=e.shape.x+e.shape.width/2,s=e.shape.y-e.shape.height/2,a=e.shape.y+e.shape.height/2;return[{...n,id:t+"-top",shape:{type:"segment",x1:o,y1:s,x2:r,y2:s,thickness:i}},{...n,id:t+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:i}},{...n,id:t+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:o,y2:a,thickness:i}},{...n,id:t+"-left",shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:i}}]}return e.collider?[{...n,id:t+"-collider",shape:e.shape}]:[]}function Pr(e){if(e)return{activeRegionIds:Array.from(e.activeRegionIds),regionIds:Array.from(e.regionIds),charges:{...e.charges},attributes:{...e.attributes},energy:e.energy}}function Dr(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}function Br(e){if(!1===e.semanticItem)return null;const t=e.shape,n=e.semanticItem??{},i="aabb"===t.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:t.x,y:t.y,width:t.width,height:t.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2,pathData:`M ${t.x1} ${t.y1} L ${t.x2} ${t.y2}`};return{...i,...n,id:n.id??i.id}}function Tr(e){return e.some(e=>null!=e.force||null!=e.damping||null!=e.impulseOnEnter||null!=e.impulseOnExit)}function Er(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),o=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(o)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(o)?o:0}:null}var Nr=[];function Or(e){const t=e.store.controls(),n=e.store.snapshot(),i=Math.max(0,e.result.steps*(n.config.fixedDt||1/60)),o=function(e,t,n,i){const o=Number.isFinite(i)?Math.max(0,i):0;if(0>=o||!Tr(t))return!1;const r=new Map(t.map(e=>[e.id,e])),s=e.readBodies();let a=!1;for(const t of s){const i=n.get(t.id);if(!i||!i.activeRegionIds.size)continue;const s=Pr(i);if(s)for(const n of i.activeRegionIds){const i=r.get(n);if(!i)continue;const c=Dr(i.force,{body:t,region:i,regionState:s}),l=Number(i.damping??0),d=(c?.x??0)*o-(Number.isFinite(l)?t.vx*l*o:0),u=(c?.y??0)*o-(Number.isFinite(l)?t.vy*l*o:0);(d||u)&&(e.applyImpulse(t.id,d,u),a=!0)}}return a}(t,e.regionEffects,e.regionState,i),r=function(e,t,n,i,o,r){const s=Number.isFinite(r)?Math.max(0,r):0;if(0>=s||!t)return!1;const a=new Map(n.map(e=>[e.id,e])),c=e.readBodies();let l=!1;for(let n=0;c.length>n;n+=1){const r=c[n],d=i.get(r.id),u=Pr(d);let h=Nr;if(d&&d.activeRegionIds.size>0){const e=[];for(const t of d.activeRegionIds){const n=a.get(t);n&&e.push(n)}h=e}const p=Er(t,{body:r,bodies:c,index:n,regionState:u,regions:h,simulationState:o});if(!p)continue;const m=(p.x??0)*s,f=(p.y??0)*s;(m||f)&&(e.applyImpulse(r.id,m,f),l=!0)}return l}(t,e.bodyForces,e.regionEffects,e.regionState,n.simulationState,i);return e.composed&&e.composed.onTick(e.result,t,{dt:i,elapsed:e.result.elapsedSeconds,getRegionState:t=>Pr(e.regionState.get(t))}),e.onTick?.(e.result,t),{regionEffectsApplied:o,bodyForcesApplied:r,snapshot:n}}function Fr(e,t,n,i,o,r,s,a,c,l){const d=function(e,t){return!!t?.isActive&&(t.predicate?.(e)??!0)}(e,o),u={selected:d,simulationState:t,regionState:r,regions:s},h="function"==typeof n?n(e,u):n,p=s.reduce((t,n)=>n.bodyStyle?{...t,..."function"==typeof n.bodyStyle?n.bodyStyle(e,u):n.bodyStyle}:t,{}),m=d?"function"==typeof i?i(e,u):i:void 0;return{fill:l?.color??a,stroke:l?.stroke??c,strokeWidth:l?.strokeWidth??1,opacity:l?.opacity??.9,...h,...p,...m}}var Wr=require("react");function qr(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function zr(e,t){const n="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,qr(e.thickness)??qr(n)??qr(t.thickness)??4)}var Lr=c(require("react")),Hr=require("react/jsx-runtime"),Yr={border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},_r="semiotic-accessible-data-table",Gr=_r+" semiotic-accessible-data-table-hidden",Vr=_r+" semiotic-accessible-data-table-visible",Xr={position:"absolute",top:0,left:0,right:0,zIndex:"var(--semiotic-data-table-z-index, var(--semiotic-overlay-z-index, 20))",padding:"14px 16px 12px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontFamily:"var(--semiotic-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif)",fontSize:13,lineHeight:1.5,color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",borderRadius:"var(--semiotic-border-radius, 0px) var(--semiotic-border-radius, 0px) 0 0"},Ur={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},Kr={position:"absolute",top:10,right:10,width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",cursor:"pointer",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:13,lineHeight:1,padding:0,borderRadius:"var(--semiotic-border-radius, 4px)"},Qr={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},Zr={textAlign:"left",padding:"5px 10px",borderBottom:"2px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))"},Jr={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},es={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},ts={marginTop:8,padding:"4px 10px",fontSize:12,cursor:"pointer",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",borderRadius:"var(--semiotic-border-radius, 4px)",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",fontFamily:"inherit"};function ns(e){return null==e?null:"string"==typeof e||"number"==typeof e||"boolean"==typeof e?e+"":null}function is(e){return{__semioticHoverData:!0,body:e,data:e.datum??e,id:e.id,type:"body",x:e.x,y:e.y}}function os(e){if("circle"===e.shape.type){const t=Math.max(4,2*e.shape.radius);return{height:t,shape:"circle",width:t}}return{height:e.shape.height,shape:"rect",width:e.shape.width}}function rs(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if("string"==typeof e||"number"==typeof e||"boolean"==typeof e)return e+""}return e.id}function ss(e){const t=as(e.datum??e);return t.length?t.map(([e,t])=>`${e}: ${t}`).join(", "):"Physics body "+e.id}function as(e){return e&&"object"==typeof e?Object.entries(e).map(([e,t])=>{if(e.startsWith("_"))return null;const n=ns(t);return null==n?null:[e,n]}).filter(e=>null!=e).slice(0,8):[]}function cs({hover:e}){const t=as(e.data);return(0,Hr.jsxs)("div",{className:"semiotic-tooltip",style:Ne,children:[(0,Hr.jsx)("div",{style:{fontWeight:700,marginBottom:t.length?4:0},children:e.id}),t.map(([e,t])=>(0,Hr.jsxs)("div",{children:[(0,Hr.jsxs)("span",{style:{opacity:.72},children:[e,": "]}),(0,Hr.jsx)("span",{children:t})]},e))]})}function ls(e){return e.datum&&"object"==typeof e.datum?Object.entries(e.datum).map(([e,t])=>{const n=ns(t);return null==n?null:`${e}: ${n}`}).filter(e=>null!=e).slice(0,8).join(", "):""}function ds(e){const t=[`${e.length} semantic item${1===e.length?"":"s"}.`],n=new Map;for(const t of e)t.group&&n.set(t.group,(n.get(t.group)??0)+1);return n.size&&t.push(Array.from(n).map(([e,t])=>`${e}: ${t}`).join(", ")),t.join(" ")}function us(e){const{chartTitle:t,items:n,tableId:i}=e,[o,r]=Lr.useState(!1),[s,a]=Lr.useState(5),c=xr.useContext(vr),l=c?.visible??!1,d=o||l,u=Lr.useRef(null),h="Data summary for "+(t??"physics chart");Lr.useEffect(()=>{d||a(5)},[d]);const p=Lr.useCallback(e=>{e.target===e.currentTarget&&(o||l||r(!0))},[o,l]),m=Lr.useCallback(e=>{l||u.current?.contains(e.relatedTarget)||r(!1)},[l]);if(!n.length)return(0,Hr.jsx)("span",{id:i,tabIndex:-1,style:Yr});if(!d)return(0,Hr.jsx)("div",{id:i,className:Gr,role:"region","aria-label":h,tabIndex:-1,style:Yr,onFocus:p,children:(0,Hr.jsxs)("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",n.length," semantic items)"]})});const f=Math.min(s,n.length),y=n.slice(0,f),g=n.length-f;return(0,Hr.jsxs)("div",{ref:u,id:i,className:Vr,role:"region","aria-label":h,tabIndex:-1,onBlur:m,style:Xr,children:[(0,Hr.jsx)("button",{type:"button",className:"semiotic-accessible-data-table-close","aria-label":"Close data summary",onClick:()=>{l&&c&&c.setVisible(!1),r(!1)},style:Kr,children:"×"}),(0,Hr.jsx)("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:Ur,children:ds(n)}),(0,Hr.jsxs)("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Semantic items for "+(t??"physics chart"),style:Qr,children:[(0,Hr.jsx)("caption",{className:"semiotic-accessible-data-table-caption",style:es,children:g>0?`First ${f} of ${n.length} semantic items`:`All ${n.length} semantic items`}),(0,Hr.jsx)("thead",{children:(0,Hr.jsxs)("tr",{children:[(0,Hr.jsx)("th",{scope:"col",style:Zr,children:"Item"}),(0,Hr.jsx)("th",{scope:"col",style:Zr,children:"Description"}),(0,Hr.jsx)("th",{scope:"col",style:Zr,children:"Group"}),(0,Hr.jsx)("th",{scope:"col",style:Zr,children:"Position"}),(0,Hr.jsx)("th",{scope:"col",style:Zr,children:"Data"})]})}),(0,Hr.jsx)("tbody",{children:y.map((e,t)=>(0,Hr.jsxs)("tr",{children:[(0,Hr.jsx)("th",{scope:"row",style:Jr,children:e.label}),(0,Hr.jsx)("td",{style:Jr,children:e.description??e.label}),(0,Hr.jsx)("td",{style:Jr,children:e.group??""}),(0,Hr.jsxs)("td",{style:Jr,children:[Math.round(e.x),", ",Math.round(e.y)]}),(0,Hr.jsx)("td",{style:Jr,children:ls(e)})]},e.id??`${e.label}-${t}`))})]}),g>0?(0,Hr.jsxs)("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(e=>e+25),style:ts,children:["Show ",Math.min(25,g)," more"," ",1===g?"row":"rows"," (",g," remaining)"]}):null]})}cs.ownsChrome=!0;var hs=require("react/jsx-runtime"),ps=[640,360],ms={top:0,right:0,bottom:0,left:0},fs=new Set(["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]),ys="StreamPhysicsFrame",gs=(0,h.memo)((0,h.forwardRef)(function(e,t){const{accessibleTable:n=!0,annotations:i,onAnnotationActivate:o,autoPlaceAnnotations:r,background:s,backgroundGraphics:a,maxDevicePixelRatio:c,bodySemanticItemLimit:l=200,bodySemanticItems:d=!1,bodySemanticUpdateMs:f=200,bodyForces:y,bodyStyle:g,chartId:b,className:x,frameScheduler:v,clock:w,random:k,seed:M,color:I,config:S,controllers:j,continuous:C=!1,description:$,emphasis:D,chartMode:T,enableHover:E=!0,foregroundGraphics:N,hoverRadius:O=16,initialSpawns:F,initialSpawnPacing:W,legend:G,legendClickBehavior:V,legendHighlightedCategory:X,legendHoverBehavior:K,legendIsolatedCategories:Q,legendLayout:ee,legendPosition:te,margin:ne,onClick:ie,onObservation:oe,onRegionEvent:re,onSimulationExecutionChange:se,onBodyHover:ae,onBodyPointerDown:ce,onSemanticItemActivate:le,onSemanticItemFocus:de,onTick:ue,opacity:he,paused:pe=!1,regionEffects:me=[],responsiveHeight:fe,responsiveWidth:ye,selectedBodyStyle:ge={stroke:"#111827",strokeWidth:2,opacity:1},selection:be,semanticItems:xe=[],simulationExecution:ve="auto",size:we=ps,stroke:ke,strokeWidth:Me,summary:Ie,suspendWhenHidden:Se=!0,svgAnnotationRules:je,title:Re,tooltipContent:$e,workerBodyThreshold:Pe=ii,renderBody:De,beforePaint:Be,afterPaint:Te}=e,Ee=u.useMemo(()=>({color:I,stroke:ke,strokeWidth:Me,opacity:he}),[I,he,ke,Me]),Ne=(0,h.useRef)(oe);Ne.current=oe;const Oe=(0,h.useRef)(b);Oe.current=b;const Fe=(0,h.useRef)(new Map),We=(0,h.useRef)(me);We.current=me;const qe=(0,h.useRef)(y),ze=(0,h.useRef)(ue);ze.current=ue;const tt=u.useMemo(()=>or(j),[j]),nt=(0,h.useRef)(tt);nt.current=tt;const it=C||!!tt?.continuous,ot=(0,h.useRef)(it);ot.current=it;const rt=u.useMemo(()=>{if(!y&&!tt?.bodyForce)return y;if(!tt?.bodyForce)return y;if(!y)return tt.bodyForce;const e=tt.bodyForce;return t=>{const n="function"==typeof y?y(t):y,i="function"==typeof e?e(t):e;return n||i?{x:(n?.x??0)+(i?.x??0),y:(n?.y??0)+(i?.y??0)}:null}},[y,tt]);qe.current=rt;const st=u.useMemo(()=>new Map(me.map(e=>[Rr(e),e])),[me]),at=u.useMemo(()=>new Map(me.map(e=>[e.id,e])),[me]),ct=u.useMemo(()=>me.map(Br).filter(e=>null!=e),[me]),[lt,dt]=u.useState([]),ut=u.useMemo(()=>lt.length||ct.length?[...xe,...lt,...ct]:xe,[lt,ct,xe]),ht=u.useMemo(()=>Tr(me),[me]),pt=!!rt,mt=(0,h.useRef)(null),ft=(0,h.useRef)(w??Wo);ft.current=w??Wo;const yt=(0,h.useCallback)((e,t,n)=>{const i=mt.current;if(!i||!n)return!1;const o=i.readBodies().find(t=>t.id===e),r=Pr(Fe.current.get(e));if(!o||!r)return!1;const s=Dr(n,{body:o,region:t,regionState:r});return!(!s||!s.x&&!s.y||(i.applyImpulse(e,s.x??0,s.y??0),0))},[]),gt=(0,h.useCallback)((e,t,n)=>{if(!n.bodyId)return;const i=Pr(Fe.current.get(n.bodyId));if(!i)return;const o={bodyId:n.bodyId,datum:n.datum,observation:n,region:t,regionState:i,type:e};"region-enter"===e?t.onEnter?.(o):t.onExit?.(o),re?.(o)},[re]),bt=(0,h.useCallback)(e=>{const t=e.sensorId?st.get(e.sensorId):void 0;if(!t||!e.bodyId)return;const n=function(e,t){let n=e.get(t);return n||(n={activeRegionIds:new Set,attributes:{},charges:{},energy:0,regionIds:new Set},e.set(t,n)),n}(Fe.current,e.bodyId),i=mt.current?.readBodies().find(t=>t.id===e.bodyId),o=Pr(n),r=i&&o?{body:i,region:t,regionState:o}:null;if("physics-proximity-enter"===e.type){if(n.activeRegionIds.add(t.id),n.regionIds.add(t.id),n.energy+=t.energyDelta??0,r){!function(e,t,n){const i="function"==typeof e.attributes?e.attributes(t):e.attributes;i&&(n.attributes={...n.attributes,...i})}(t,r,n);const e=function(e,t){return void 0!==e.charge?"function"==typeof e.charge?e.charge(t):e.charge:"charge-gate"===e.kind?1:void 0}(t,r);void 0!==e&&(n.charges[t.id]=e)}yt(e.bodyId,t,t.impulseOnEnter),gt("region-enter",t,e)}else"physics-proximity-exit"===e.type&&(n.activeRegionIds.delete(t.id),yt(e.bodyId,t,t.impulseOnExit),gt("region-exit",t,e))},[yt,gt,st]),xt=u.useMemo(()=>function({annotations:e,chartId:t,chartType:n,config:i,onRegionObservation:o,regionEffects:r,seed:s,size:a}){const c=function(e=[],t={}){const n=t.idPrefix?t.idPrefix+"-":"",i=[];for(const o of e){if("barrier"!==o.physics&&"sensor"!==o.physics)continue;const e=o.axis??t.defaultAxis??"x",r=zr(o,t),s=o.colliderId??`${n}${o.id}`;let a;if("x"===e){const e=qr(o.x),n=qr(o.y1)??qr(t.plotBounds?.y)??qr(o.y),i=qr(o.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??qr(o.y);if(null==e||null==n||null==i)continue;a={type:"segment",x1:e,y1:n,x2:e,y2:i,thickness:r}}else{const e=qr(o.y),n=qr(o.x1)??qr(t.plotBounds?.x)??qr(o.x),i=qr(o.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??qr(o.x);if(null==e||null==n||null==i)continue;a={type:"segment",x1:n,y1:e,x2:i,y2:e,thickness:r}}i.push({id:s,shape:a,sensor:"sensor"===o.physics,..."barrier"!==o.physics||null==o.restitution&&null==t.barrierRestitution?{}:{restitution:qr(o.restitution)??qr(t.barrierRestitution)},..."barrier"!==o.physics||null==o.friction&&null==t.barrierFriction?{}:{friction:qr(o.friction)??qr(t.barrierFriction)}})}return i}((e??[]).filter(e=>"barrier"===e.physics||"sensor"===e.physics),{idPrefix:t?t+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),l=void 0===s||void 0!==i?.kernel?.seed?i:{...i,kernel:{...i?.kernel,seed:s}},d=r.flatMap(e=>[{id:Rr(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...$r(e)]),u=Object.fromEntries(r.map(e=>[Rr(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=l?.observation,p=r.length>0;return p||d.length>0||c.length>0||null!=t||h?{...l,colliders:[...l?.colliders??[],...d,...c],observation:{...h,chartId:t??h?.chartId,chartType:h?.chartType??n,sensors:{...h?.sensors??{},...u},onObservation:e=>{p&&o(e),h?.onObservation?.(e)}}}:l}({annotations:i,chartId:b,chartType:ys,config:S,onRegionObservation:bt,regionEffects:me,seed:M,size:we}),[i,b,S,bt,me,M,we]);if(!mt.current){const e=Fo(xt,F,W);e.setPaused(pe),Se&&e.setVisible(ar()),mt.current=e}const vt=(0,h.useRef)(-1),wt=(0,h.useRef)(null),kt=(0,h.useRef)(!0),Mt=(0,ur.useRef)(new gr("StreamPhysicsFrame")),It=(0,h.useRef)(""),St=(0,h.useId)().replace(/:/g,""),jt=(0,h.useRef)(!1),At=(0,h.useRef)(!1),Ct=(0,h.useRef)(0),Rt=(0,h.useRef)(!1),$t=(0,h.useRef)(!1),Pt=(0,h.useRef)(null),Dt=(0,h.useRef)(!1),Bt=function(e){const t=R(),n=(0,m.useRef)(t);n.current=t;const[i,o]=P(e.sizeProp,e.responsiveWidth,e.responsiveHeight),r=!!e.title,s=!!e.legend&&"top"===e.legendPosition,a=(0,m.useMemo)(()=>function(e,t,n=!1){const i=n?t?58:34:t?36:0;return i>e.top?{...e,top:i}:e}({...e.marginDefault,...e.userMargin},r,s),[e.marginDefault,e.userMargin,r,s]),c=o[0]-a.left-a.right,l=o[1]-a.top-a.bottom,d=H(e.foregroundGraphics,o,a),u=H(e.backgroundGraphics,o,a),h=A(e=>e.theme),{transition:f,introEnabled:y}=function(e,t){if(!1===e)return{transition:void 0,introEnabled:!1};const n="undefined"!=typeof window&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return{transition:e?!0===e?{duration:300}:{duration:e.duration??300,easing:"linear"===e.easing?"linear":"ease-out"}:t,introEnabled:!(n||!e||!0!==e&&!1===e.intro)}}(e.animate,e.transitionProp),g="semiotic-table-"+p.useId(),b=(0,m.useRef)(null);if(!b.current){const t=!e.suspendWhenHidden||"undefined"==typeof document||!document.hidden;b.current=new q({clock:e.clock,random:e.random,seed:e.seed,paused:e.paused,visible:t})}const x=b.current;x.configure({clock:e.clock,random:e.random,seed:e.seed});const v=(0,m.useRef)(null),w=(0,m.useRef)(e.frameScheduler??L);w.current=e.frameScheduler??L;const k=(0,m.useRef)(null),M=(0,m.useRef)(!1),I=(0,m.useRef)(()=>{}),S=(0,m.useCallback)(()=>{if(null!==v.current||M.current)return;const e=w.current;let t=!1,n=!1;const i=e.requestAnimationFrame(()=>{t=!0;const e=!n;e&&(M.current=!0),v.current=null,k.current=null;try{I.current()}finally{e&&(M.current=!1)}});n=!0,t||(v.current=i,k.current=e)},[]),j=(0,m.useCallback)(()=>{null!==v.current&&((k.current??w.current).cancelAnimationFrame(v.current),v.current=null,k.current=null)},[]);z(()=>{x.setPaused(!0===e.paused)},[x,e.paused]),(0,m.useEffect)(()=>{if(!e.suspendWhenHidden||"undefined"==typeof document)return void x.setVisible(!0);const t=()=>x.setVisible(!document.hidden);return t(),document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[x,e.suspendWhenHidden]),(0,m.useEffect)(()=>()=>{j()},[j]);const C=(0,m.useRef)(()=>{}),$=(0,m.useRef)(()=>{}),D=(0,m.useRef)(null),T=(0,m.useRef)(null),E=(0,m.useRef)(null),N=(0,m.useCallback)(()=>{const e=D.current;D.current=null,e&&C.current(e)},[]),O=(0,m.useCallback)(e=>{if(D.current={clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType},null===T.current){const e=w.current;let t=!1;const n=e.requestAnimationFrame(()=>{t=!0,T.current=null,E.current=null,N()});t||(T.current=n,E.current=e)}},[N]),F=(0,m.useCallback)(()=>{D.current=null,null!==T.current&&((E.current??w.current).cancelAnimationFrame(T.current),T.current=null,E.current=null),$.current()},[]);(0,m.useEffect)(()=>()=>{D.current=null,null!==T.current&&((E.current??w.current).cancelAnimationFrame(T.current),T.current=null,E.current=null)},[]);const W=e.themeDirtyRef;return z(()=>{W&&(B++,W.current=!0,S())},[h,S,W]),{reducedMotion:t,reducedMotionRef:n,responsiveRef:i,size:o,margin:a,adjustedWidth:c,adjustedHeight:l,resolvedForeground:d,resolvedBackground:u,currentTheme:h,transition:f,introEnabled:y,tableId:g,frameRuntime:x,rafRef:v,renderFnRef:I,scheduleRender:S,cancelRender:j,hoverHandlerRef:C,hoverLeaveRef:$,onPointerMove:O,onPointerLeave:F}}({sizeProp:we,responsiveWidth:ye,responsiveHeight:fe,userMargin:ne,marginDefault:ms,foregroundGraphics:N,backgroundGraphics:a,frameScheduler:v,clock:w,random:k,seed:M,paused:pe,suspendWhenHidden:Se}),{margin:Tt,rafRef:Et,reducedMotion:Nt,reducedMotionRef:Ot,renderFnRef:Ft,cancelRender:Wt,resolvedBackground:qt,resolvedForeground:zt,responsiveRef:Lt,scheduleRender:Ht,size:Yt,frameRuntime:_t}=Bt,Gt=(0,h.useRef)(_t.now);Gt.current=_t.now;const Vt=function(){const[e,t]=(0,Y.useState)(!1);return _(()=>{t(!0)},[]),e}(),Xt=U(),[Ut,Kt]=u.useState(null),[Qt,Zt]=u.useState(null),Jt=(0,h.useRef)(null),en=(0,h.useRef)(0),tn=(0,h.useRef)(new Map),nn=St+"-physics-live",on=(0,h.useCallback)((e,t,n=!1)=>{if(!d)return void dt(e=>e.length?[]:e);const i=Gt.current();if(!n&&f>0&&f>i-en.current)return;en.current=i;const o=function(e,t,n,i){if(!n)return[];const o=Math.max(0,Math.floor(i));if(!o)return[];const r=[];for(let i=0;e.length>i&&o>r.length;i+=1){const o=e[i],s="function"==typeof n?n(o,{index:i,simulationState:t}):void 0;if(!1===s)continue;const a=os(o);r.push({datum:o.datum??o,description:ss(o),group:"body",label:rs(o),...a,...s??{},bodyId:s?.bodyId??o.id,id:s?.id??"body:"+o.id,x:s?.x??o.x,y:s?.y??o.y})}return r}(e,t,d,l);dt(e=>function(e,t){if(e.length!==t.length)return!0;for(let n=0;e.length>n;n+=1){const i=e[n],o=t[n];if(i.id!==o.id||i.label!==o.label||i.description!==o.description||i.group!==o.group||i.bodyId!==o.bodyId||Math.round(i.x)!==Math.round(o.x)||Math.round(i.y)!==Math.round(o.y))return!0}return!1}(e,o)?o:e)},[l,d,f]),rn=(0,h.useCallback)(e=>{if(!ut.length)return;const t=Math.max(0,Math.min(e,ut.length-1));vt.current=t;const n=ut[t];if(Jt.current=n.bodyId??null,Kt(n),de?.(n),n.bodyId&&mt.current){const e=mt.current.readBodies().find(e=>e.id===n.bodyId);if(e){const t=is(e);Zt(t),ae?.(e,t)}}},[ut,ae,de]),sn=(0,h.useCallback)(()=>{vt.current=-1,Jt.current=null,Kt(null),de?.(null)},[de]),an=function({onObservationRef:e,chartIdRef:t,wallClockRef:n}){return(0,Wr.useCallback)((i,o)=>{const r=e.current;if(!r)return;const s={timestamp:n.current(),chartType:"StreamPhysicsFrame",chartId:t.current};r("hover"===i||"click"===i?{...s,type:i,datum:o?.datum??{},x:o?.x??0,y:o?.y??0}:"focus"===i?{...s,type:i,datum:o?.datum??{},inputType:"touch"===o?.inputType?"pointer":o?.inputType??"keyboard"}:"activate"===i?{...s,type:i,datum:o?.datum??{},inputType:o?.inputType??"keyboard"}:{...s,type:i})},[t,e,n])}({onObservationRef:Ne,chartIdRef:Oe,wallClockRef:ft}),cn=(0,h.useCallback)(()=>{Zt(e=>e?(ae?.(null,null),an("hover-end"),null):e)},[an,ae]),ln=(0,h.useCallback)(e=>{if(!E||!mt.current)return;const t=e.currentTarget.getBoundingClientRect(),n=mt.current.hitTest(e.clientX-t.left,e.clientY-t.top,O);if(!n)return void cn();const i=is(n);Zt(e=>e&&e.id===i.id&&e.x===i.x&&e.y===i.y?e:(ae?.(n,i),an("hover",{datum:n.datum,x:n.x,y:n.y}),i))},[cn,an,E,O,ae]),dn=(0,h.useCallback)(e=>{sn();const t=mt.current,n=e.currentTarget.getBoundingClientRect(),i=e.clientX-n.left,o=e.clientY-n.top,r=t?t.hitTest(i,o,Math.max(16,O)):null;ce?.(r,e),r?(an("click",{datum:r.datum,x:r.x,y:r.y}),an("activate",{datum:r.datum,inputType:"touch"===e.pointerType?"touch":"pointer"}),ie?.(r.datum??null,{x:r.x,y:r.y,body:r})):(an("click-end"),ie?.(null,{x:i,y:o,body:null}),cn())},[cn,sn,an,O,ce,ie]);(0,h.useEffect)(()=>{if(!ut.length)return void sn();const e=vt.current;if(ut.length>e){if(e>=0){const t=ut[e];if(Jt.current=t.bodyId??null,Kt(e=>null!=e&&e.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t),t.bodyId&&mt.current){const e=mt.current.readBodies().find(e=>e.id===t.bodyId);if(e){const t=is(e);Zt(e=>e?.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t)}}}}else rn(ut.length-1)},[ut,sn,rn]),(0,h.useEffect)(()=>{E||cn()},[cn,E]);const un=(0,h.useCallback)(e=>{if(function(e){const t=e.target;return t instanceof Element&&t!==e.currentTarget&&null!=t.closest("button, a[href], input, select, textarea, summary, [contenteditable='true'], [role='button'], [role='link'], [role='checkbox'], [role='radio'], [role='switch']")}(e))return;if(!ut.length)return;if("Escape"===e.key)return e.preventDefault(),void sn();if(("Enter"===e.key||" "===e.key)&&vt.current>=0){e.preventDefault();const t=ut[vt.current];return an("activate",{datum:t.datum??{id:t.id,label:t.label},inputType:"keyboard"}),void le?.(t)}if(!fs.has(e.key))return;e.preventDefault();const t=vt.current;if(0>t){rn(0);const e=ut[0];return void an("focus",{datum:e.datum??{id:e.id,label:e.label},inputType:"keyboard"})}const n=Math.max(1,Math.floor(.1*ut.length));let i=t;if("Home"===e.key?i=0:"End"===e.key?i=ut.length-1:"PageDown"===e.key?i=Math.min(ut.length-1,t+n):"PageUp"===e.key?i=Math.max(0,t-n):"ArrowRight"===e.key||"ArrowDown"===e.key?i=Math.min(ut.length-1,t+1):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(i=Math.max(0,t-1)),rn(i),i!==t){const e=ut[i];an("focus",{datum:e.datum??{id:e.id,label:e.label},inputType:"keyboard"})}},[sn,an,rn,le,ut]),[hn,pn]=u.useState([]),mn=(0,h.useRef)(0),fn=!!i?.length&&i.some(e=>null!=e.pointId||null!=e.bodyId||"latest"===e.anchor),{canvasRef:yn,resolutionDirtyRef:gn}=function(e,t){return Z({...t,renderFnRef:e.renderFnRef,scheduleRender:e.scheduleRender,cancelRender:e.cancelRender,frameRuntime:e.frameRuntime})}(Bt,{hydrated:Vt,wasHydratingFromSSR:Xt,storeRef:mt,dirtyRef:kt,manageFrameRuntime:!1,skipInitialCanvasPaintInvalidation:!0,maxDevicePixelRatio:c,canvasPaintDependencies:[s,a,Ht]}),bn=(0,h.useCallback)(()=>{const e=yn.current,t=mt.current;if(!e||!t)return;const n=Mt.current.beforeCompute(t.getLastUpdateResult(),!1);gn.current=!1;const i=function(e){if("undefined"==typeof window)return 1;const t=window.devicePixelRatio||1,n=function(){if("undefined"==typeof window)return!1;const e="function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches,t=768>Math.min(window.innerWidth||1/0,window.innerHeight||1/0);return e||t}()?2:3;return Math.max(1,Math.min(t,"number"==typeof e&&e>0?e:n))}(c),o=function(e,t,n,i){const o=e.getContext("2d");if(!o)return null;const r=Math.round(t[0]*i),s=Math.round(t[1]*i),a=r/t[0],c=s/t[1],l=t[0]+"px",d=t[1]+"px";return e.style.width!==l&&(e.style.width=l),e.style.height!==d&&(e.style.height=d),e.width===r&&e.height===s||(e.width=r,e.height=s),o.setTransform(a,0,0,c,0,0),o.translate(n.left,n.top),o}(e,Yt,Tt,i);if(!o)return void Mt.current.afterCompute(n,!1,!1);const r=function(e){const t=Je(e,Xe),n=Je(e,_e),i=Je(e,Ze),o=Je(e,Ue),r=Je(e,Ye),s=Je(e,He),a=Je(e,Ke),c=Je(e,Qe),l=Je(e,Ge),d=Je(e,Ve);return{annotationBackground:et(s,.94),annotationStroke:r,annotationText:a,background:s,border:r,closedWindowFill:et(n,.08),closedWindowStroke:et(n,.55),danger:n,focus:l,grid:d,gutterFill:et(c,.14),lateFill:i,openWindowFill:et(t,.07),openWindowStroke:et(t,.3),primary:t,selectedFill:i,selectedStroke:l,success:o,text:a,textSecondary:c,warning:i}}(o);o.clearRect(-Tt.left,-Tt.top,Yt[0],Yt[1]),a||"transparent"===s||(o.fillStyle=s??r.background,o.fillRect(-Tt.left,-Tt.top,Yt[0],Yt[1]));const l=t.snapshot(),d=t.readBodies();if(on(d,l.simulationState),fn){const e=Gt.current();if(e-mn.current>=100){mn.current=e;const t=Jn(d);pn(e=>e.length===t.length&&e.every((e,n)=>e.pointId===t[n].pointId&&Math.round(e.x)===Math.round(t[n].x)&&Math.round(e.y)===Math.round(t[n].y))?e:t)}}Be&&(o.save(),Be(o,d),o.restore());for(const e of d){const t=Fe.current.get(e.id),n=t?Array.from(t.activeRegionIds).map(e=>at.get(e)).filter(e=>null!=e):[],i=Fr(e,l.simulationState,g,ge,be,Pr(t),n,r.primary,r.text,Ee);De?(o.save(),De(o,e,i),o.restore()):Ar(o,e,i)}Te&&(o.save(),Te(o,d),o.restore()),function(e,t,n){let i=!1;for(const[o,r]of t){const s=Math.min(1,Math.max(0,(n-r.startedAt)/r.durationMs));if(s>=1){t.delete(o);continue}i=!0;const a=1-Math.pow(1-s,3),{body:c}=r,l=r.scale>0?r.scale:1,d=(r.radius+28*a)*l,u=1-s;e.save(),e.globalAlpha*=u,e.strokeStyle=r.color,e.fillStyle=r.color,e.lineWidth=Math.max(.5,(2.4*u+.4)*l),e.beginPath(),e.arc(c.x,c.y,d,0,2*Math.PI),e.stroke(),e.globalAlpha*=.18,e.beginPath(),e.arc(c.x,c.y,.52*d,0,2*Math.PI),e.fill(),e.restore(),e.save(),e.globalAlpha*=u,e.strokeStyle=r.color,e.lineWidth=Math.max(.5,1.8*l);for(let t=0;8>t;t+=1){const n=t*(Math.PI/4)+1.4*s,i=(r.radius+5+12*a)*l,o=(r.radius+12+34*a)*l;e.beginPath(),e.moveTo(c.x+Math.cos(n)*i,c.y+Math.sin(n)*i),e.lineTo(c.x+Math.cos(n)*o,c.y+Math.sin(n)*o),e.stroke()}e.restore()}}(o,tn.current,Gt.current()),Mt.current.afterCompute(n,!0,!1),kt.current=!1},[yn,gn,Mt,Yt,Tt,a,s,c,on,fn,Be,Te,g,ge,be,Ee,De,at]),xn=(0,h.useCallback)((e,t)=>{const n=mt.current,i=`${ve}:${e}:${t??""}`;It.current!==i&&(It.current=i,se?.({execution:e,liveBodies:n?.liveBodyCount()??0,queuedBodies:n?.queueSize()??0,reason:t,requested:ve}))},[se,ve]),vn=(0,h.useCallback)((e,t=!0)=>{Ct.current+=1,jt.current=!1,Rt.current=!1,$t.current=!1,Dt.current=!1,Pt.current?.terminate(),Pt.current=null,t&&xn("sync",e)},[xn]),wn=(0,h.useCallback)(()=>Vt?"undefined"==typeof window||"undefined"==typeof Worker?"worker unavailable":ht?"runtime region effects require sync":pt?"body forces require sync":tt?"physics controllers require sync":function(e){return!e||!e.engine&&ri(e.sediment)&&(!(t=e.colliders)||t.every(e=>{const t=e.bodyFilter;return!t||"function"!=typeof t}));var t}(xt??{})?ci(W)?At.current?"worker fallback":null:"spawn pacing is not worker-cloneable":"config is not worker-cloneable":"hydrating",[xt,tt,pt,ht,Vt,W]),kn=(0,h.useCallback)(()=>{const e=mt.current,t=wn();if(!e||t)return{reason:t,useWorker:!1};const n=e.liveBodyCount(),i=e.queueSize(),o=function(e,t,n=0,i=ii){return"sync"!==e&&("worker"===e||t+n>=i)}(ve,n,i,Pe);return{reason:o?"worker"===ve?"forced worker":"body threshold":"below threshold",useWorker:o}},[ve,Pe,wn]),Mn=(0,h.useCallback)(e=>{const t=mt.current;return t&&e.snapshot?(t.restore(e.snapshot),kt.current=!0,t):t},[]),In=(0,h.useCallback)((e,t=!0)=>{const n=Mn(e);if(!n)return;t&&ue?.(e.result,n.controls()),bn();const i=n.snapshot();!e.result.shouldContinue&&tn.current.size<=0||i.paused||!i.visible||Ot.current||Ht()},[Mn,ue,bn,Ot,Ht]),Sn=(0,h.useCallback)(e=>{At.current=!0,vn("worker failed: "+((e instanceof Error?e.message:e+"")||"unknown error"))},[vn]),jn=(0,h.useCallback)(()=>{const e=mt.current;if(!e)return!1;const t=kn();if(!t.useWorker)return jt.current||Dt.current?vn(t.reason??"sync fallback"):xn("sync",t.reason??"sync"),!1;if(jt.current||Dt.current)return!0;const n=Pt.current??new hi;Pt.current=n,Dt.current=!0;const i=Ct.current+1;return Ct.current=i,n.initFromSnapshot(xt??{},e.snapshot()).then(e=>{if(Ct.current!==i)return;Dt.current=!1,jt.current=!0,At.current=!1,Mn(e),xn("worker",t.reason??"worker"),bn();const n=mt.current?.snapshot();e.result.shouldContinue&&n&&!n.paused&&n.visible&&!Ot.current&&(wt.current=null,Ht())}).catch(e=>{Ct.current===i&&Sn(e)}),!0},[Mn,xt,Sn,bn,Ot,xn,Ht,vn,kn]),An=(0,h.useCallback)(e=>"frame"===e.type||"removed"===e.type?e.frame:null,[]),Cn=(0,h.useCallback)((e,t=!0)=>{const n=Pt.current;if(!n||!jt.current)return;const i=Ct.current;n.request(e).then(e=>{if(Ct.current!==i)return;const n=An(e);n&&In(n,t)}).catch(Sn)},[In,An,Sn]),Rn=(0,h.useCallback)(()=>{const e=mt.current;if(!e)return;const t=jn(),n=e.snapshot(),i=it||pt||ht||!!tt;n.paused||!n.visible||!e.hasPendingWork()&&!i||Ot.current?Ft.current():t&&Dt.current||Ht()},[tt,it,pt,ht,Ot,Ft,Ht,jn]),$n=(0,h.useCallback)(()=>{Wt(),Et.current=null;const e=mt.current;if(!e)return;const t=Ot.current;if(t&&(wt.current=null),jt.current&&Pt.current){if(Rt.current)return void($t.current=!0);let n=0;if(!t){const e=Gt.current();n=null!==wt.current?(e-wt.current)/1e3:0,wt.current=e}const i=Pt.current,o=Ct.current;return Rt.current=!0,void(t?i.settle():i.tick(n)).then(e=>{Rt.current=!1;const t=$t.current;$t.current=!1,Ct.current===o&&(In(e),t&&Rn())}).catch(i=>{Rt.current=!1;const r=$t.current;if($t.current=!1,Ct.current!==o)return;Sn(i);const s=t?e.settleWithObservations():e.tick(n);Or({store:e,result:s,regionEffects:We.current,regionState:Fe.current,bodyForces:qe.current,composed:nt.current,onTick:ze.current}),bn(),r&&Rn()})}const n=nt.current,i=t=>Or({store:e,result:t,composed:n,regionEffects:We.current,regionState:Fe.current,bodyForces:qe.current,onTick:ze.current});let o;if(t)o=function(e,t,n=4){let i,o=!1,r=!1,s=0;do{const n=e.settleWithObservations(),a=t(n);o=o||a.regionEffectsApplied,r=r||a.bodyForcesApplied,i={...a,regionEffectsApplied:o,bodyForcesApplied:r,result:n},s+=1}while(n>s&&e.hasPendingWork());return i}(e,i);else{const t=Gt.current(),n=wt.current;wt.current=t;const r=e.tick(null===n?0:(t-n)/1e3);o={...i(r),result:r}}const{result:r,regionEffectsApplied:s,bodyForcesApplied:a,snapshot:c}=o;bn(),(ot.current||r.shouldContinue||s||a||n||tn.current.size>0)&&!c.paused&&c.visible&&!Ot.current&&Ht()},[In,Sn,bn,Wt,Rn,Ht,Ot,Et]);Ft.current=$n,(0,h.useEffect)(()=>{At.current=!1,(jt.current||Dt.current)&&vn("config changed",!1),mt.current?.updateConfig(xt??{}),Rn()},[xt,vn]),(0,h.useEffect)(()=>{At.current=!1,Rn()},[Vt,ve,Pe]),(0,h.useEffect)(()=>{Rn()},[Nt,Rn]),function({cancelRender:e,frameRuntime:t,lastFrameTimeRef:n,paused:i,postWorkerCommand:o,requestRender:r,storeRef:s,suspendWhenHidden:a}){const c=(0,sr.useRef)(o);c.current=o;const l=(0,sr.useRef)(r);l.current=r,(0,sr.useEffect)(()=>{const o=s.current;o&&(t.setPaused(i),o.setPaused(i),i&&(n.current=null,e()),c.current({type:"setPaused",paused:i},!1),l.current())},[e,t,i]),(0,sr.useEffect)(()=>{if(!a){const e=s.current;return t.setVisible(!0),void(e&&!e.snapshot().visible&&(e.setVisible(!0),c.current({type:"setVisible",visible:!0},!1),l.current()))}if("undefined"==typeof document)return;const i=()=>{const i=s.current;if(!i)return;const o=ar();t.setVisible(o),i.setVisible(o),o||(n.current=null,e()),c.current({type:"setVisible",visible:o},!1),l.current()};return i(),document.addEventListener("visibilitychange",i),()=>document.removeEventListener("visibilitychange",i)},[e,t,a])}({cancelRender:Wt,frameRuntime:_t,lastFrameTimeRef:wt,paused:pe,postWorkerCommand:Cn,requestRender:Rn,storeRef:mt,suspendWhenHidden:Se}),(0,h.useEffect)(()=>()=>vn("unmount",!1),[vn]),(0,h.useEffect)(()=>{bn()},[bn]),(0,h.useImperativeHandle)(t,()=>({...mt.current.controls(),applyImpulse:(e,t,n)=>{mt.current.applyImpulse(e,t,n),Cn({type:"applyImpulse",id:e,ix:t,iy:n}),Rn()},clear:()=>{mt.current.clear(),Fe.current.clear(),tn.current.clear(),Cn({type:"clear"}),Rn()},clearRegionState:e=>{e?Fe.current.delete(e):Fe.current.clear(),Rn()},getData:()=>mt.current.readBodies(),getRegionState:e=>e?Pr(Fe.current.get(e)):function(e){const t={};return e.forEach((e,n)=>{const i=Pr(e);i&&(t[n]=i)}),t}(Fe.current),getStore:()=>mt.current,pause:()=>{_t.setPaused(!0),wt.current=null,Wt(),mt.current.setPaused(!0),Cn({type:"setPaused",paused:!0},!1),Rn()},push:(e,t)=>{mt.current.enqueue(e,t),ci(t)?Cn({type:"enqueue",spawns:[e],pacing:t}):(jt.current||Dt.current)&&vn("spawn pacing is not worker-cloneable"),Rn()},pushMany:(e,t)=>{mt.current.enqueue(e,t),ci(t)?Cn({type:"enqueue",spawns:e,pacing:t}):(jt.current||Dt.current)&&vn("spawn pacing is not worker-cloneable"),Rn()},popBodies:(e,t={})=>{const n=mt.current,i=new Map(n.readBodies().map(e=>[e.id,e])),o=n.remove(e),r=Gt.current();for(const e of o){const n=i.get(e);n&&(Fe.current.delete(e),tn.current.set(e,{body:n,color:t.color??"#f59e0b",durationMs:Math.max(120,t.durationMs??520),radius:t.radius??Cr(n),scale:null!=t.scale&&t.scale>0?t.scale:1,startedAt:r}),Jt.current===e&&(Jt.current=null,Kt(null)),Zt(t=>t?.id===e?null:t))}return o.length&&(Cn({type:"remove",ids:o}),Rn()),o},remove:e=>{const t=mt.current.remove(e);for(const t of e)Fe.current.delete(t);return Cn({type:"remove",ids:e}),Rn(),t},restore:e=>{mt.current.restore(e),Fe.current.clear(),tn.current.clear(),Cn({type:"restore",snapshot:e},!1),Rn()},resume:()=>{_t.setPaused(!1),wt.current=null,mt.current.setPaused(!1),Cn({type:"setPaused",paused:!1},!1),Rn()},settle:e=>{const t=mt.current.settle(e);return Cn({type:"settle",maxSteps:e}),Rn(),t},settleWithObservations:e=>{const t=mt.current.settleWithObservations(e);return Cn({type:"settle",maxSteps:e}),Rn(),t},step:e=>{const t=mt.current,n=t.tick(e);return Or({store:t,result:n,regionEffects:We.current,regionState:Fe.current,bodyForces:qe.current,composed:nt.current,onTick:ze.current}),Cn({type:"tick",deltaSeconds:e}),bn(),n}}),[Wt,_t,bn,Cn,Rn,vn]);const Pn=Ce||!Vt&&Xt,Dn=["stream-physics-frame",T?"stream-physics-frame--mode-"+T:null,D?"stream-physics-frame--emphasis-"+D:null,x].filter(Boolean).join(" "),Bn=$??("string"==typeof Re?Re:void 0)??"Physics chart",Tn=St+"-physics-table",En=Math.max(1,Yt[0]-Tt.left-Tt.right),Nn=Math.max(1,Yt[1]-Tt.top-Tt.bottom),On=E&&Qt?$e?$e(Qt):(0,hs.jsx)(cs,{hover:Qt}):null,Fn=On&&Qt?(0,hs.jsx)(Le,{x:Qt.x-Tt.left,y:Qt.y-Tt.top,containerWidth:En,containerHeight:Nn,margin:Tt,className:"stream-physics-tooltip",children:On}):null;if(Pn){const e=mt.current??Fo(xt,F,W),t="string"==typeof Re?Re:void 0,{svg:n}=function(e,t={}){const{width:n=640,height:i=360,title:o,description:r,background:s,backgroundGraphics:a,className:c,foregroundGraphics:l,idPrefix:d="physics",margin:u,renderBodySVG:h,...p}=t,m=_o(e,p),f={...Vo,...u},y=[n,i],g=Xo(a,y,f),b=Xo(l,y,f),x=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(d),v=o?x+"-title":void 0,w=r?x+"-desc":void 0,k=[v,w].filter(Boolean).join(" ")||void 0;return{svg:qo.renderToStaticMarkup((0,Go.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:n,height:i,viewBox:`0 0 ${n} ${i}`,role:"img","aria-labelledby":k,children:[o&&(0,Go.jsx)("title",{id:v,children:o}),r&&(0,Go.jsx)("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?(0,Go.jsx)("rect",{x:0,y:0,width:n,height:i,fill:s}):null,g,(0,Go.jsx)("g",{id:x+"-data-area",children:m.sceneNodes.map((e,t)=>{const n=m.bodies[t];return(n&&h?h(n,e.style??{},t,x):void 0)??Ae(e,t,x)})}),b]})),scene:m,evidence:m.evidence}}(e,{width:Yt[0],height:Yt[1],title:t,description:$,background:a||"transparent"===s?void 0:s,backgroundGraphics:qt,className:"stream-physics-frame__svg",foregroundGraphics:zt,idPrefix:"physics-"+St,margin:Tt});return(0,hs.jsxs)("div",{ref:Lt,className:Dn,"data-semiotic-mode":T,role:"img","aria-label":Bn,style:{width:Yt[0],height:Yt[1]},children:[(0,hs.jsx)(Sr,{summary:Ie}),(0,hs.jsx)("div",{dangerouslySetInnerHTML:{__html:n}})]})}return(0,hs.jsxs)("div",{ref:Lt,className:Dn,"data-semiotic-mode":T,role:"group","aria-label":Bn,"aria-describedby":Ut?nn:void 0,tabIndex:0,style:{position:"relative",width:Yt[0],height:Yt[1]},onKeyDown:un,children:["production"!==process.env.NODE_ENV&&mt.current&&(0,hs.jsx)(br,{store:mt.current,diagnostics:Mt.current}),n?(0,hs.jsx)(jr,{tableId:Tn}):null,n?(0,hs.jsx)(us,{chartTitle:"string"==typeof Re?Re:Bn,items:ut,tableId:Tn}):null,(0,hs.jsx)(Sr,{summary:Ie}),(0,hs.jsx)(Mr,{hoverPoint:Qt}),(0,hs.jsx)("div",{id:nn,"aria-live":"polite","aria-atomic":"true",style:Yr,children:Ut?Ut.description??Ut.label:""}),(0,hs.jsxs)("div",{role:"img","aria-label":Bn,style:{position:"relative",width:"100%",height:"100%"},children:[(0,hs.jsx)(J,{size:Yt,margin:Tt,children:qt}),(0,hs.jsx)("canvas",{ref:yn,width:Yt[0],height:Yt[1],"aria-hidden":"true",style:{position:"absolute",left:0,top:0,display:"block"},onPointerDown:dn,onPointerMove:E?ln:void 0,onPointerLeave:E?cn:void 0}),zt,(0,hs.jsx)(ni,{width:En,height:Nn,totalWidth:Yt[0],totalHeight:Yt[1],margin:Tt,title:Re,legend:G,legendPosition:te,legendLayout:ee,legendHoverBehavior:K,legendClickBehavior:V,legendHighlightedCategory:X,legendIsolatedCategories:Q,pointNodes:hn,annotations:i,onAnnotationActivate:o,onObservation:oe,chartId:b,chartType:ys,autoPlaceAnnotations:r,svgAnnotationRules:je}),(0,hs.jsx)(dr,{active:null!=Ut,hoverPoint:Ut?{x:Ut.x,y:Ut.y}:null,margin:Tt,size:Yt,shape:Ut?.shape,width:Ut?.width,height:Ut?.height,pathData:Ut?.pathData}),Fn]})]})}));gs.displayName="StreamPhysicsFrame";var bs=gs;function xs(e){if(null==e)return()=>{};const t="function"==typeof e?e:t=>t[e];return e=>vs(t(e))}function vs(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e&&""!==e.trim()){const t=Number(e);return Number.isFinite(t)?t:void 0}}function ws(e,t,n){const i=null!=e.axis?n[e.axis]:null!=e.field?t[e.field]:n.value;if(void 0!==e.eq&&i!==e.eq)return!1;if(void 0!==e.ne&&i===e.ne)return!1;if(void 0!==e.in&&!e.in.includes(i))return!1;if(void 0===e.gt&&void 0===e.gte&&void 0===e.lt&&void 0===e.lte&&void 0===e.within&&void 0===e.outside)return!0;const o=vs(i);if(void 0===o)return!1;if(void 0!==e.gt&&e.gt>=o)return!1;if(void 0!==e.gte&&e.gte>o)return!1;if(void 0!==e.lt&&o>=e.lt)return!1;if(void 0!==e.lte&&o>e.lte)return!1;if(void 0!==e.within){const[t,n]=e.within;if(t>o||o>n)return!1}if(void 0!==e.outside){const[t,n]=e.outside;if(o>=t&&n>=o)return!1}return!0}function ks(e,t,n){const i=e.when;return void 0===i||!0===i||!1!==i&&("function"==typeof i?i(t,n):ws(i,t,n))}function Ms(e,t,n){if(!t||0===t.length)return{};let i={};for(const o of t){if(!ks(o,e,n))continue;const t="function"==typeof o.style?o.style(e,n):o.style;t&&(i={...i,...t})}return i}function Is(e,t,n,i=e=>e){const o=e??(()=>({}));return t&&0!==t.length?(e,r)=>{const s=i(e),a={...o(e,r)};return Object.assign(a,Ms(s,t,n(s,r))),a}:o}function Ss(e){const[t,n]=e,i=160>t||116>n,o=i?Math.min(12,Math.max(2,.08*t)):32,r=i?Math.min(8,Math.max(2,.12*n)):24,s=i?r:34;return{width:t,height:n,plot:{x:o,y:r,width:Math.max(1,t-2*o),height:Math.max(1,n-r-s)}}}function js(e){const t=(e??"")+"";if(!t)return"#4e79a7";const n=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let i=0;for(let e=0;t.length>e;e+=1)i=31*i+t.charCodeAt(e)>>>0;return n[i%n.length]}function As(e,t="#4e79a7",n){const i=n?.styleRules,o=!!i&&i.length>0,r=o?xs(n?.valueAccessor):void 0;return n=>{const s=n.datum,a=s&&e?"function"==typeof e?e(s,0):s[e]:void 0,c={fill:null==a?t:js(a),stroke:"#111827",strokeWidth:1,opacity:.9};return o&&s&&Object.assign(c,Ms(s,i,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function Cs(e,t,n,i){return{fixedDt:1/120,maxSubsteps:8,colliders:t,observation:{chartType:n},kernel:{seed:e,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...i}}}function Rs(e,t,n){if(!e.length)return[];const i=Ss(t),o=i.plot.width/Math.max(1,e.length),r=Math.max(1,...e.map(e=>e.value)),s=.62*i.plot.height,a=i.plot.y+i.plot.height;return e.map((e,t)=>{const c=Math.max(8,e.value/r*s),l=`${n} ${e.label}: ${e.value}${null==e.secondary?"":`, ${e.secondary} secondary`}`;return{id:`${n}-${e.label}`,label:l,description:l,datum:e,x:i.plot.x+(t+.5)*o,y:a-c/2,shape:"rect",width:Math.max(12,.58*o),height:c,group:n}})}function $s(e,t,n){return"function"==typeof n?n(e,t):e[n]}function Ps(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:null}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Ds(e,t,n){return Math.max(t,Math.min(n,e))}function Bs(e,t){const n=Ps(e);return null!=n&&n>0?n:t}function Ts(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Es(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}var Ns=require("d3-scale");function Os(e){const{data:t,valueAccessor:n,bins:i,ballRadius:o,seed:r,size:s,valueExtent:a}=e,c=Ss(s),l=t.map((e,t)=>Ps($s(e,t,n))).filter(e=>null!=e),d=function(e){if(!e)return;const t=Ps(e[0]),n=Ps(e[1]);return null!=t&&null!=n?t>n?[n,t]:[t,n]:void 0}(a),u=d?.[0]??(l.length?Math.min(...l):0),h=d?.[1]??(l.length?Math.max(...l):1),p=h===u?1:h-u,m=(0,Ns.scaleLinear)().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),f=Array.from({length:i},()=>0),y=[];t.forEach((e,t)=>{const r=Ps($s(e,t,n));if(null==r)return;const s=Math.max(0,Math.min(i-1,Math.floor((r-u)/p*i)));f[s]+=1,y.push({id:(e.id??"galton-"+t)+"",x:m(s+.5),y:c.plot.y+o+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:o},datum:{...e,value:r,bin:s}})});const g=c.plot.y+c.plot.height;return{config:Cs(r,[...fo({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...yo({idPrefix:"galton-bin",count:i,domainStart:0,domainStep:1,xScale:m,yTop:c.plot.y-400,yBottom:g,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:f.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:i,plot:c.plot,valueExtent:[u,h]}}}var Fs=require("d3-scale");function Ws(e){const{count:t,idPrefix:n,wallThickness:i,xScale:o,yBottom:r,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const c=Math.min(r-1,a?.(t)??s),l=Math.max(1,r-c);return{id:`${n}-wall-${t}`,shape:{type:"aabb",x:o(t),y:c+l/2,width:i,height:l}}})}function qs(e){const{data:t,timeAccessor:n,arrivalAccessor:i,windows:o,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:d=1}=e,u=Ss(c),h=t.map((e,t)=>Ps($s(e,t,n))).filter(e=>null!=e),p=Ps(l?.[0]),m=Ps(l?.[1]),f=h.length?Math.min(...h):0,y=h.length?Math.max(...h):f+o.size,g=Math.min(p??f,f),b=Math.max(m??y,y),x=Math.floor(g/o.size)*o.size,v=Math.max(1,Math.ceil((b-x+o.size)/o.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Ps(r?.value)??w-(r?.delay??o.size),M=Math.max(0,Math.min(v,Array.from({length:v},(e,t)=>t).reduce((e,t)=>x+(t+1)*o.size>k?e:e+1,0))),I=function(e,t){const n=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:n,height:e.plot.height},windowPlot:{x:e.plot.x+n,y:e.plot.y,width:Math.max(40,e.plot.width-n),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(u,s),S=x+v*o.size,j=(0,Fs.scaleLinear)().domain([x,S]).range([I.windowPlot.x,I.windowPlot.x+I.windowPlot.width]),A=Array.from({length:v},()=>({value:0,secondary:0})),C=[];t.forEach((e,t)=>{const r=Ps($s(e,t,n));if(null==r)return;const a=Ps($s(e,t,i))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-x)/o.size))),l=k>=x+(c+1)*o.size;A[c].value+=l?0:1,A[c].secondary+=l?1:0,C.push({id:(e.id??"event-"+t)+"",x:Math.max(I.windowPlot.x+s,Math.min(I.windowPlot.x+I.windowPlot.width-s,j(r))),y:u.plot.y+s+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...e,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const R=u.plot.y+u.plot.height,$=function(e,t){const n=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!n)return[];const i=e.windowStart,o=e.windowStart+e.windowCount*e.windowSize,r=(0,Fs.scaleLinear)().domain([i,o]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=r(e.windowStart+n*e.windowSize),a=e.windowPlot.x,c=t+Math.max(18,Math.min(.3*e.windowPlot.height,s-a)),l=e=>s===a?t:c+(e-a)/(s-a)*(t-c),d=[];for(let t=0;n>t;t+=1){const n=e.windowStart+t*e.windowSize,i=n+e.windowSize,o=r(n),s=r(i);d.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:o,y1:l(o),x2:s,y2:l(s)})}return d}({closedWindowCount:M,gutter:I.gutter,plot:u.plot,windowCount:v,windowPlot:I.windowPlot,windowSize:o.size,windowStart:x},u.plot.y+.28*u.plot.height);return{config:Cs(a,[...fo({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Ws({idPrefix:"eventdrop-window",count:v,xScale:e=>j(x+e*o.size),yTop:I.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>M)return null;const t=0===e?$[0]?.y1:$[e-1]?.y2??$[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?I.wallTop:t+1.25*s},yBottom:R,wallThickness:6}),...$.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:C,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>e.datum?.arrivalTime,timeScale:d},projectionRows:A.map((e,t)=>({label:`${x+t*o.size}-${x+(t+1)*o.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:M,gutter:I.gutter,lidSegments:$,lateCount:A.reduce((e,t)=>e+t.secondary,0),plot:u.plot,windowPlot:I.windowPlot,watermarkValue:k,windowCount:v,windowSize:o.size,windowStart:x}}}function zs(e,t,n){const i=e.width/Math.max(1,t),o=Math.max(2,2*n),r=Math.min(.7*i,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(r/o));return{laneWidth:i,tubeWidth:r,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*i,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}function Ls(e){const{data:t,categoryAccessor:n,valueAccessor:i,unitValue:o,ballRadius:r,seed:s,size:a}=e,c=Bs(o,1),l=Ss(a),d=[],u=new Map,h=new Map,p=[];function m(e){let t=u.get(e);return null==t&&(t=d.length,d.push(e),u.set(e,t)),t}t.forEach((e,t)=>{m(($s(e,t,n)??"unknown")+"")});const f=Math.max(1,d.length),y=zs(l.plot,f,r),g=Math.max(0,y.tubeWidth/2-r-1),b=d.map(()=>[]);t.forEach((e,t)=>{const o=($s(e,t,n)??"unknown")+"",s=m(o),a=i?Ps($s(e,t,i)):1,d=Math.max(0,Math.round((a??0)/c)),u=y.centerX(s);for(let n=0;d>n;n+=1){const i=h.get(o)??0,a=y.perRow>1?((y.perRow>1?i%y.perRow:0)/(y.perRow-1)*2-1)*g:0;h.set(o,i+1),b[s].push({id:`${(e.id??"pile-"+t)+""}-${n}`,x:u+a,y:l.plot.y+r+2,vx:(n%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,category:o,unitIndex:n}})}});const x=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;x>e;e+=1)for(const t of b)t.length>e&&p.push(t[e]);const v=l.plot.y+l.plot.height,w=[...fo({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=l.plot.y-400;for(let e=0;f>e;e+=1){const t=y.centerX(e);for(const n of[-1,1])w.push({id:`pile-tube-${e}-${0>n?"l":"r"}`,shape:{type:"aabb",x:t+n*y.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:Cs(s,w,"UnitPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:h.get(e)??0}))}}var Hs=require("d3-scale");function Ys(e){const{data:t,xAccessor:n,groupAccessor:i,radiusAccessor:o,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:d}=e,u=Ss(a),h=Es(s),p=[],m=[],f=new Map;t.forEach((e,t)=>{const s=Ps($s(e,t,n));if(null==s)return;const a=i?($s(e,t,i)??"All")+"":"All",c=o?Ps($s(e,t,o)):null,l=Ds(null!=c&&c>0?c:r,2,18);!function(e){let t=f.get(e);null==t&&(t=m.length,m.push(e),f.set(e,t))}(a),p.push({datum:e,index:t,value:s,group:a,radius:l})});const y=p.map(e=>e.value),g=c?Ps(c[0]):null,b=c?Ps(c[1]):null,x=y.length?Math.min(...y):0,v=y.length?Math.max(...y):1;let w=g??x,k=b??v;if(w===k&&(w-=.5,k+=.5),w>k){const e=k;k=w,w=e}const M=Math.max(r,...p.map(e=>e.radius)),I=u.plot.x+M+8,S=u.plot.x+u.plot.width-M-8,j=(0,Hs.scaleLinear)().domain([w,k]).range([I,S]),A=Math.max(1,m.length),C=Math.min(Math.max(28,3*M),u.plot.height/4),R=u.plot.y+C,$=Math.max(0,u.plot.y+u.plot.height-C-R),P=e=>{const t=f.get(e)??0;return 1===A?u.plot.y+.54*u.plot.height:R+t/(A-1)*$},D=new Map,B=p.map((e,t)=>{D.set(e.group,(D.get(e.group)??0)+1);const n=j(e.value),i=P(e.group),o=(h()-.5)*e.radius*1.6,r=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:d?n+o:Ds(n+(t%9-4)*e.radius*2.5,I,S),y:d?i+r:u.plot.y-18-t%12*e.radius,vx:d?0:22*(h()-.5),vy:d?0:24+18*h(),mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:n,targetY:i},springs:[{target:{type:"point",x:n,y:i},restLength:0,stiffness:34,damping:5.5}]}});return{config:Cs(s,fo({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*M),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:B,projectionRows:m.map(e=>({label:e,value:D.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[I,S],groups:m.map(e=>({label:e,y:P(e),count:D.get(e)??0})),plot:u.plot}}}function _s(e){if(Array.isArray(e)&&e.length>=2){const t=Ps(e[0]),n=Ps(e[1]);return null!=t&&null!=n?{x:t,y:n}:null}if(e&&"object"==typeof e){const t=e,n=Ps(t.x),i=Ps(t.y);return null!=n&&null!=i?{x:n,y:i}:null}return null}function Gs(e){return Array.isArray(e)?e.map(_s).filter(e=>null!=e):[]}function Vs(e,t,n){return"normalized"===n?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:Ds(e.x,t.plot.x,t.plot.x+t.plot.width),y:Ds(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Xs(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}function Us(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const n=Ds(t,0,1)*Xs(e);let i=0;for(let t=1;e.length>t;t+=1){const o=e[t-1],r=e[t],s=Math.hypot(r.x-o.x,r.y-o.y);if(s>0){if(i+s>=n){const e=(n-i)/s;return{x:o.x+(r.x-o.x)*e,y:o.y+(r.y-o.y)*e}}i+=s}}return{...e[e.length-1]}}function Ks(e,t){const n=Us(e,Math.max(0,t-.02)),i=Us(e,Math.min(1,t+.02)),o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{x:o/s,y:r/s}}function Qs(e){const{coordinateMode:t,flowSpeed:n,links:i,maxParticles:o,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:d,pathAccessor:u,pathConstraint:h="path",reducedMotion:p,seed:m,size:f,sourceAccessor:y,targetAccessor:g,throughputAccessor:b}=e,x=Ss(f),v=Es(m),w=new Map,k=new Map,M=[];function I(e){if(e&&"object"==typeof e){const t=e;if("function"==typeof r){const e=r(t,0);if(null!=e)return e+""}if("string"==typeof r&&null!=t[r])return t[r]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}c.forEach((e,t)=>{const n=($s(e,t,r)??e.id??t)+"",i=Ps($s(e,t,s)),o=Ps($s(e,t,a));if(null!=i&&null!=o){const e={x:i,y:o};w.set(n,e),M.push(e)}k.set(n,(e.label??e.name??n)+"")});const S=[];i.forEach((e,t)=>{const n=I($s(e,t,y)),i=I($s(e,t,g)),o=Math.max(0,Ps($s(e,t,b))??0),r=Gs(u?$s(e,t,u):void 0),s=r.length?r:Gs(e.path??e.points??e.route);s.forEach(e=>M.push(e)),S.push({id:(e.id??`physical-flow-${n}-${i}-${t}`)+"",link:e,index:t,source:n,target:i,throughput:o,rawPath:s})});const j=(C=M,"normalized"===(A=t)||"pixels"===A?A:C.length>0&&C.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels");var A,C;const R=new Map;for(const[e,t]of w)R.set(e,Vs(t,x,j));const $=[];for(const e of S){let t=e.rawPath.map(e=>Vs(e,x,j));if(2>t.length){const n=R.get(e.source),i=R.get(e.target);n&&i&&(t=[n,i])}else R.has(e.source)||R.set(e.source,t[0]),R.has(e.target)||R.set(e.target,t[t.length-1]);t.length>=2&&e.throughput>0&&(k.has(e.source)||k.set(e.source,e.source),k.has(e.target)||k.set(e.target,e.target),$.push({...e,path:t,packetCount:0}))}const P=Bs(d,.12),D=Math.max(1,Math.round(o)),B=$.map(e=>Math.max(1,Math.round(e.throughput*P))),T=B.reduce((e,t)=>e+t,0),E=T>D?D/T:1;$.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(B[t]*E))});let N=$.reduce((e,t)=>e+t.packetCount,0);for(;N>D;){const e=$.reduce((e,t,n)=>t.packetCount>1&&(-1===e||t.packetCount>$[e].packetCount)?n:e,-1);if(-1===e)break;$[e].packetCount-=1,N-=1}const O=new Map,F=new Map,W=[],q=Bs(n,90),z=Bs(l,4);$.forEach((e,t)=>{O.set(e.target,(O.get(e.target)??0)+e.throughput),F.set(e.source,(F.get(e.source)??0)+e.throughput);const n=Xs(e.path);for(let i=0;e.packetCount>i;i+=1){const o=(i+.5)/e.packetCount,r=p?o:Ds(.12+.84*o+.04*(v()-.5),.04,.98),s=p?r:Math.max(0,r-(.18+.12*v())),a=Us(e.path,s),c=Us(e.path,r),l=Ks(e.path,s),d={x:-l.y,y:l.x},u=(v()-.5)*z*1.5;W.push({id:`${e.id}-packet-${i}`,x:a.x+d.x*u,y:a.y+d.y*u,vx:p?0:l.x*q+10*(v()-.5),vy:p?0:l.y*q+10*(v()-.5),mass:.8,spawnAt:p?0:.04*t+i/32,shape:{type:"circle",radius:z},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:i,packetCount:e.packetCount,routeProgress:r,flowPath:e.path,flowPathLength:n,flowRouteId:e.id,flowSpeed:q,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*z,stiffness:26,damping:4.25}]:void 0})}});const L=Math.max(18,5*z),H=Array.from(R,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:"physical-flow-node-"+Ts(e),point:t})),Y=H.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:L,height:L}})),_=Object.fromEntries(H.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=Cs(m,[...fo({x:x.plot.x,y:x.plot.y,width:x.plot.width,height:x.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...Y],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*z),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});G.bodyLimit=D,G.eviction="oldest",G.observation={...G.observation,sensors:_};const V=Array.from(R,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+Ts(e),incoming:O.get(e)??0,outgoing:F.get(e)??0})),X=$.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:G,initialSpawns:W,projectionRows:V.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:j,particleCount:W.length,totalThroughput:$.reduce((e,t)=>e+t.throughput,0),plot:x.plot,nodes:V,links:X}}}function Zs(e,t){if("region-enter"!==t.type)return e;const n=t.region.id,i=e[n]??{id:n,label:t.region.label??n,count:0,bodyIds:[]};if(i.bodyIds.includes(t.bodyId))return e;const o=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:o.length,bodyIds:o}}}function Js(e,t){return(t??Object.keys(e)).map(t=>e[t]).filter(e=>null!=e).map(e=>({label:e.label??e.id,value:e.count}))}function ea(e,t){const n=t instanceof Set?t:new Set(t);return e.map(e=>{const t=e.bodyIds??[],i=t.filter(e=>!n.has(e)),o=t.length-i.length,r=e.completion?.mode??"allMembersAbsorbed",s=e.completion?.valueByBodyId,a=e=>{const t=s?.[e];return Number.isFinite(t)&&Number(t)>=0?Number(t):1},c=t.reduce((e,t)=>e+a(t),0),l=t.reduce((e,t)=>e+(n.has(t)?a(t):0),0),d=e.completion?.threshold,u="threshold"===r?Number.isFinite(d)&&Number(d)>=0?Number(d):c:void 0;return{id:e.id,label:e.label??e.id,mode:r,complete:t.length>0&&("anyAbsorbed"===r?o>0:"threshold"===r?l>=(u??c):0===i.length),absorbed:o,total:t.length,absorbedValue:l,totalValue:c,threshold:u,missing:i}})}function ta(e,t,n){return Math.max(t,Math.min(n,e))}function na(e,t,n={}){const i=n.random??Math.random,o=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],r=ta(n.along??.5,.05,.95),s=n.jitterX??0,a=n.padY??20,c=o.x0+(o.x1-o.x0)*r+(2*i()-1)*s,l=Math.min(1,o.width/2),d=ta(c,o.x0+l,o.x1-l),u=e.boundaryY(d,"top")+a,h=e.boundaryY(d,"bottom")-a;return{x:d,y:h>u?u+i()*Math.max(1,h-u):e.midY}}function ia(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}function oa(e,t,n){return Math.max(t,Math.min(n,e))}function ra(e,t,n,i,o,r={}){return{id:e,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:i,y2:o,thickness:r.thickness??8}}}function sa(e){const t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height)),o=e.padX??46,r=e.padY??72,s=o,a=n-o,c=r,l=i-Math.max(24,Math.round(.45*r)),d=(c+l)/2,u=Math.max(1,l-c),h=oa(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),m=Number.isFinite(p)?p:0,f=oa(u*h+m,.06*u,.5*u),y=f/2,g=d-y,b=d+y,x=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,k=e.wallThickness??8,M=e.stages;if(!M.length)throw Error("processStageLayout requires at least one stage");const I=oa(e.centerStageIndex??Math.floor(M.length/2),0,M.length-1),S=function(e){const t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}(M),j=a-s;let A=s;const C=M.map((e,t)=>{const n=A,i=t===M.length-1?a:A+(e.share??1)/S*j;return A=i,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:n,x1:i,x:(n+i)/2,width:i-n,y:d,height:u}}),R=C[I],$=R.x0,P=R.x1,D=(e,n)=>{if("lane"===t)return"top"===n?c:l;if("funnel"===t){const t=oa((e-s)/Math.max(1,a-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if($>=e){const t=oa((e-s)/Math.max(1,$-s),0,1);return"top"===n?c+(g-c)*t:l+(b-l)*t}if(P>=e)return"top"===n?g:b;const i=oa((e-P)/Math.max(1,a-P),0,1);return"top"===n?g+(c-g)*i:b+(l-b)*i},B=C.map(e=>{const t=Math.min(D(e.x0,"top"),D(e.x1,"top")),n=Math.max(D(e.x0,"bottom"),D(e.x1,"bottom"));return{...e,y:(t+n)/2,height:Math.max(1,n-t)}}),T={thickness:k,friction:v,restitution:w},E=[];"lane"===t?E.push(ra(x+"-top",s,c,a,c,T),ra(x+"-bottom",s,l,a,l,T),ra(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),ra(x+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)})):"funnel"===t?E.push(ra(x+"-top",s,c,a,g,T),ra(x+"-bottom",s,l,a,b,T),ra(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),ra(x+"-right",a,g,a,b,{...T,thickness:Math.max(6,k)})):E.push(ra(x+"-left-top",s,c,$,g,T),ra(x+"-left-bottom",s,l,$,b,T),ra(x+"-center-top",$,g,P,g,T),ra(x+"-center-bottom",$,b,P,b,T),ra(x+"-right-top",P,g,a,c,T),ra(x+"-right-bottom",P,b,a,l,T),ra(x+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),ra(x+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)}));const N=e.membraneDampingScale??.5,O=s,F=Math.max(1,("bowtie"===t?$:a)-O),W=(e.membranes??[]).map(e=>{const t=O+oa(e.offset,0,1)*F,n=e.width??18+18*e.cost,i=u-16,o=d+.25*(e.wobble??0);return{...e,x:t,y:o,width:n,height:i}}),q=!1===e.includeMembraneRegions?[]:W.map(e=>la({id:e.id,label:e.label??e.id,description:e.description??(e.label??e.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:e.x,y:e.y,width:e.width,height:e.height,cost:e.cost,dampingScale:e.dampingScale??N,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:n,height:i,padX:o,padY:r,left:s,right:a,topY:c,bottomY:l,midY:d,centerLeft:$,centerRight:P,pinchHeight:f,pinchTop:g,pinchBottom:b,stages:B,membranes:W,colliders:E,regionEffects:q,boundaryY:D}}function aa(e){return{id:e.id,label:e.label,description:e.description,kind:e.kind,shape:(t=e.x,n=e.y,i=e.width,o=e.height,{type:"aabb",x:t,y:n,width:i,height:o}),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:e.attributes,onEnter:e.onEnter,onExit:e.onExit};var t,n,i,o}function ca(e,t={}){const n=t.idPrefix??"stage",i=Math.max(0,t.insetX??0),o=Math.max(0,t.insetY??1);return e.stages.map(e=>{const r="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...aa({id:n?`${n}:${e.id}`:e.id,label:e.label??e.id,description:e.description,kind:"region",x:e.x,y:e.y,width:Math.max(1,e.width-2*i),height:Math.max(1,e.height-2*o),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...r,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function la(e){const t=e.dampingScale??.5,n=e.energyScale??1,i=oa(e.cost,0,2);return{...aa({...e,kind:e.kind??"membrane",attributes:{primitive:"membrane",membraneCost:i,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:i*t,energyDelta:-i*n}}function da(e){return{...aa({...e,kind:e.kind??"charge-gate",attributes:{primitive:"chargeGate",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),charge:e.charge??!0,energyDelta:e.energyDelta,impulseOnEnter:e.impulseOnEnter}}function ua(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...aa({...e,kind:e.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.015}}function ha(e){const t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,i=e.dampingPerUnit??.12,o=e.energyPerUnit??0;return{...aa({...e,kind:e.kind??"membrane",attributes:{primitive:"pressureField",pressure:t,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:n+t*i,energyDelta:o?-t*o:void 0,force:e.force}}function pa(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...aa({...e,kind:e.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function ma(e){return{...aa({...e,kind:e.kind??"force-field",attributes:{primitive:"portal",targetStage:e.targetStage,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function fa(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...aa({...e,kind:e.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function ya(e){return{...aa({...e,kind:e.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function ga(e){const t=e.x??e.anchor?.x??0,n=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:n,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:n},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function ba(e){const t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},i=[ra(t+"-top",e.left,e.top,e.right,e.top,n),ra(t+"-bottom",e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||i.push(ra(t+"-left",e.left,e.top,e.left,e.bottom,n),ra(t+"-right",e.right,e.top,e.right,e.bottom,n)),i}function xa(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}function va(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=e.size,i=Ss(n),o=Ds(e.ballRadius??6,2,18),r=e.seed??1,s=Es(r),a=e.idAccessor,c=e.stageAccessor??"stage",l=e.groupBy,d=e.groupLabelAccessor,u=e.workAccessor,h=e.radiusAccessor,p=e.groupCompletion??(l?"allAbsorbed":"none"),m=e.springStiffness??.28,f=e.springDamping??.72,y=!0===e.settle,g=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),b=sa({width:n[0],height:n[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:g,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),x=new Map(b.stages.map((e,t)=>[e.id,t])),v=new Map(b.stages.map(e=>[e.id,e])),w=b.stages[0].id,k=b.stages[0],M=new Set(t.filter(e=>e.absorb).map(e=>e.id)),I=t.map(e=>{const t=v.get(e.id)??k;return function(e,t){const n={id:"process-stage-"+e.id,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return fa({...n,kind:e.kind??"sink",force:xa(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...n.attributes,primitive:"absorb"}});if(e.portal){const t=e.portal.force??e.force??{x:-40,y:0};return ma({...n,kind:e.kind??"force-field",force:xa(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){const t=Math.max(.1,e.capacity.unitsPerSecond);return pa({...n,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:xa(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...n.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){const t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return ha({...n,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:xa(e.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?ua({...n,kind:e.kind??"force-field",force:xa(e.force,14),damping:e.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):ya({...n,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(e,{x:t.x,y:b.midY,width:t.width,height:b.bottomY-b.topY})});I.unshift(ua({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(b.left+b.right)/2,y:b.midY,width:b.right-b.left,height:b.bottomY-b.topY-12,force:8,damping:.012,semanticItem:!1}));const S=new Map;for(const e of b.stages)S.set(e.id,0);const j=[];e.data.forEach((e,t)=>{const n=(a?$s(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",i=($s(e,t,c)??w)+"",r=x.has(i)?i:w;S.set(r,(S.get(r)??0)+1);const s=l?($s(e,t,l)??"")+"":void 0,p=s&&d?($s(e,t,d)??s)+"":s,m=u?Ps($s(e,t,u))??1:1,f=h?Ps($s(e,t,h)):null,y=Ds(null!=f&&f>0?f:o,2,18);j.push({datum:e,id:n,stageId:r,groupId:s||void 0,groupLabel:p||void 0,work:m,radius:y,index:t})});const A=new Map,C=new Map;for(const e of j){if(!e.groupId)continue;const t=A.get(e.groupId)??[];t.push(e.id),A.set(e.groupId,t),e.groupLabel&&C.set(e.groupId,e.groupLabel)}const R=Ds(e.groupAnchorAlong??.55,.15,.9),$=b.left+(b.right-b.left)*R,P=Array.from(A.keys()),D=P.map((e,n)=>{const i=A.get(e)??[],o=P.length>1?b.topY+28+n/Math.max(1,P.length-1)*(b.bottomY-b.topY-56):b.midY;return ga({id:e,label:C.get(e)??e,bodyIds:i,anchor:{x:$,y:o},x:$,y:o,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),B=ea(D,j.filter(e=>M.has(e.stageId)).map(e=>e.id)),T=new Map(D.map(e=>[e.id,e])),E=j.map((e,t)=>{const n=v.get(e.stageId)??k,i=n.x+(s()-.5)*Math.min(24,.2*n.width),o=b.boundaryY(i,"top")+e.radius+10,r=b.boundaryY(i,"bottom")-e.radius-10,a=r>o?o+s()*Math.max(1,r-o):b.midY,c=y?i:b.left+18+t%7*4,l=y?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,d=[{target:{type:"point",x:i,y:a},restLength:.45*e.radius,stiffness:m,damping:f}];if(e.groupId){const t=T.get(e.groupId);t?.anchor&&!M.has(e.stageId)&&d.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:c,y:l,vx:y?0:40+40*s(),vy:y?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:y?0:.03*t,springs:d,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),N={kernel:{seed:r,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:b.colliders,fixedDt:1/60,maxSubsteps:8},O=b.stages.map(e=>({label:e.label??e.id,value:S.get(e.id)??0})),F=t.map(e=>{const t=v.get(e.id)??k;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:S.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:N,initialSpawns:E,initialSpawnPacing:y?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:O,metadata:{kind:"process-flow",plot:i.plot,volume:b,stages:F,groups:D,groupCompletion:B,regionEffects:I}}}var wa=require("react");function ka(e,t){if(!t?.length)return[e];const n=t.filter(t=>{if(t.id===e||t.id.startsWith(e+"-"))return!0;const n=t.datum;return!(!n||"object"!=typeof n||null==n.id)&&n.id+""===e}).map(e=>e.id);return n.length?n:[e]}function Ma(e,t,n){if("function"==typeof n)return n(e,t)+"";if("string"==typeof n){const t=e[n];if(null!=t)return t+""}return null!=e&&"object"==typeof e&&"id"in e&&null!=e.id?e.id+"":"physics-row-"+t}function Ia(e,t){const n=e?.getData().find(e=>e.id===t),i=n?.datum;if(i&&"object"==typeof i)return i}function Sa(e,t){const{frameRef:n,spawnDatum:i,seedRows:o,idAccessor:r,bodyIdsForSeed:s,seedSpawns:a}=t,c=(0,wa.useRef)(new Map),l=(0,wa.useRef)(new Map),d=(0,wa.useRef)(""),u=o?o.map((e,t)=>Ma(e,t,r)).join("\0"):"";if(u!==d.current&&(d.current=u,o))for(let e=0;o.length>e;e+=1){const t=o[e],n=Ma(t,e,r);c.current.set(n,t),l.current.set(n,s?.(t,n,e)??ka(n,a))}(0,wa.useImperativeHandle)(e,()=>{const e=c.current,t=l.current;function o(e,t){const n=i(e,t);return{datumId:n.datumId||Ma(e,t,r),spawns:n.spawns.map(e=>({...e,spawnAt:void 0}))}}function s(i){const o=[];for(const{datum:n,result:r}of i)e.set(r.datumId,n),t.set(r.datumId,r.spawns.map(e=>e.id)),o.push(...r.spawns);if(!o.length)return;const r=n.current;r?(r.pushMany(o),r.step(0)):"production"!==process.env.NODE_ENV&&console.warn("[semiotic/physics] push() called before the physics frame mounted (loading/empty early-return). Omit data for push mode and ensure the chart is mounted.")}function a(i){const o=e.get(i);if(o)return o;const r=t.get(i)??[i];for(const o of r){const r=Ia(n.current,o);if(r)return e.set(i,r),t.has(i)||t.set(i,[o]),r}}return{push:t=>{s([{datum:t,result:o(t,e.size)}])},pushMany:t=>{const n=e.size;s(t.map((e,t)=>({datum:e,result:o(e,n+t)})))},remove:i=>{const o=Array.isArray(i)?i:[i],r=[],s=[];for(const n of o){const i=a(n);i&&r.push(i),e.delete(n),s.push(...t.get(n)??[n]),t.delete(n)}return s.length&&n.current?.remove(s),r},update:(i,r)=>{const c=Array.isArray(i)?i:[i],l=[];for(const i of c){const c=a(i);if(!c)continue;l.push(c);const d=t.get(i)??[i];n.current?.remove(d),e.delete(i),t.delete(i);const u=r(c);s([{datum:u,result:o(u,e.size)}])}return l},clear:()=>{e.clear(),t.clear(),d.current="",n.current?.clear()},getData:()=>{const t=n.current;if(!t)return Array.from(e.values());const i=t.getData().map(e=>e.datum).filter(e=>!!e&&"object"==typeof e);return i.length?i:Array.from(e.values())},getScales:()=>null,getCustomLayout:()=>n.current?.snapshot()??null,popBodies:(e,t)=>n.current?.popBodies(e,t)??[]}},[n,r,i])}var ja=require("react"),Aa=c(require("react")),Ca=require("react/jsx-runtime");function Ra({componentName:e,message:t,diagnosticHint:n,width:i,height:o}){return(0,Ca.jsx)("div",{role:"alert",style:{width:i,height:Math.max(o,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"},children:(0,Ca.jsxs)("div",{style:{textAlign:"center",maxWidth:400},children:[(0,Ca.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:e}),(0,Ca.jsx)("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:t}),n&&(0,Ca.jsx)("div",{"data-testid":"semiotic-diagnostic-hint",style:{marginTop:10,padding:"8px 12px",background:"rgba(128, 128, 128, 0.06)",borderRadius:4,fontSize:12,color:"rgba(128, 128, 128, 0.8)",fontFamily:"monospace",textAlign:"left",whiteSpace:"pre-wrap",lineHeight:1.6},children:n})]})})}var $a=require("react/jsx-runtime"),Pa=class extends Aa.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.onError?.(e,t)}render(){if(this.state.error){const{fallback:e}=this.props,t=this.state.error;return"function"==typeof e?e(t):void 0!==e?e:(0,$a.jsx)(Ra,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}},Da=require("react/jsx-runtime");function Ba({componentName:e,width:t,height:n,children:i}){return(0,Da.jsx)(Pa,{fallback:i=>(0,Da.jsx)(Ra,{componentName:e,message:i.message,width:t,height:n}),children:i})}"undefined"!=typeof process&&process;var Ta={display:"flex",alignItems:"center",justifyContent:"center",color:"var(--semiotic-text-secondary, #666)",fontSize:13,fontFamily:"inherit",border:"1px dashed var(--semiotic-border, #ddd)",borderRadius:4,boxSizing:"border-box"},Ea={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2},Na=require("react");function Oa(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function Fa(e,t,n){const i=e=>e.toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(n)}`}function Wa(e){const t=e.map(Oa),n=t.length-1;return e=>{if(0>=e){const[e,n,i]=t[0];return Fa(e,n,i)}if(e>=1){const[e,i,o]=t[n];return Fa(e,i,o)}const i=e*n,o=Math.floor(i),r=i-o,[s,a,c]=t[o],[l,d,u]=t[o+1];return Fa(Math.round(s+(l-s)*r),Math.round(a+(d-a)*r),Math.round(c+(u-c)*r))}}require("d3-scale");var qa=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],za=Wa(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),La=Wa(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),Ha=Wa(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Ya=Wa(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),_a=Wa(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),Ga=Wa(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),Va={blues:za,reds:La,greens:Ha,viridis:Wa(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),oranges:Ya,purples:_a,greys:Ga,plasma:Wa(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:Wa(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:Wa(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:Wa(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:Wa(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])},Xa=(Wa(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),Wa(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),Wa(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),Wa(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),Wa(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Wa(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),Wa(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),{category10:qa,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...Va}),Ua=qa;function Ka(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;const n=e[t];return"string"==typeof n&&n.length>0?n:void 0}var Qa=require("react");function Za(e){const t=[];for(const[n,i]of Object.entries(e.fields))if("point"===i.type)t.push(e=>i.values.has(e[n]));else{const[e,o]=i.range;t.push(t=>{const i=t[n];return i>=e&&o>=i})}return e=>t.every(t=>t(e))}function Ja(e,t){let n=e.get(t);return n||(n={name:t,resolution:"union",clauses:new Map},e.set(t,n)),n}function ec(e,t){if(e.type!==t.type)return!1;if("interval"===e.type&&"interval"===t.type)return e.range[0]===t.range[0]&&e.range[1]===t.range[1];if("point"===e.type&&"point"===t.type){if(e.values.size!==t.values.size)return!1;for(const n of e.values)if(!t.values.has(n))return!1;return!0}return!1}var[tc,nc]=g(e=>({selections:new Map,setClause(t,n){e(e=>{const i=e.selections.get(t),o=i?.clauses.get(n.clientId);if(o&&function(e,t){if(e.clientId!==t.clientId||e.type!==t.type)return!1;const n=Object.entries(e.fields);if(n.length!==function(e){let t=0;for(const n in e)t++;return t}(t.fields))return!1;for(const[e,i]of n){const n=t.fields[e];if(!n||!ec(i,n))return!1}return!0}(o,n))return{};const r=new Map(e.selections),s=Ja(r,t),a=new Map(s.clauses);return a.set(n.clientId,n),r.set(t,{...s,clauses:a}),{selections:r}})},clearClause(t,n){e(e=>{const i=e.selections.get(t);if(!i||!i.clauses.has(n))return{};const o=new Map(e.selections),r=new Map(i.clauses);return r.delete(n),o.set(t,{...i,clauses:r}),{selections:o}})},setResolution(t,n){e(e=>{const i=e.selections.get(t);if(i?.resolution===n)return{};const o=new Map(e.selections),r=Ja(o,t);return o.set(t,{...r,resolution:n}),{selections:o}})},clearSelection(t){e(e=>{const n=e.selections.get(t);if(!n||0===n.clauses.size)return{};const i=new Map(e.selections);return i.set(t,{...n,clauses:new Map}),{selections:i}})}})),ic=(require("react"),{positions:new Map}),oc=new Set;function rc(){for(const e of oc)e()}function sc(e,t){const n=ic.positions.get(e);if(n?.locked)return;if(!n||n.sourceId!==t)return;const i=new Map(ic.positions);i.delete(e),ic={positions:i},rc()}function ac(e,t){const n=ic.positions.get(e);if(!n?.locked)return;if(t&&n.sourceId!==t)return;const i=new Map(ic.positions);i.delete(e),ic={positions:i},rc()}function cc(e){const t=(0,Qa.useId)(),n=e.clientId||t,{name:i}=e,o=nc(e=>e.selections.get(i)),r=nc(e=>e.setClause),s=nc(e=>e.clearClause),a=(0,Qa.useMemo)(()=>!!o&&o.clauses.size>0,[o]);return{predicate:(0,Qa.useMemo)(()=>o&&0!==o.clauses.size?function(e,t){const n=[];for(const[i,o]of e.clauses)"crossfilter"===e.resolution&&i===t||n.push(Za(o));return 0===n.length?()=>!0:"intersect"===e.resolution?e=>n.every(t=>t(e)):e=>n.some(t=>t(e))}(o,n):()=>!0,[o,n]),isActive:a,selectPoints:(0,Qa.useCallback)(e=>{const t={};let o=!1;for(const[n,i]of Object.entries(e))t[n]={type:"point",values:new Set(i)},o=!0;o&&r(i,{clientId:n,type:"point",fields:t})},[n,i,r]),selectInterval:(0,Qa.useCallback)(e=>{const t={};let o=!1;for(const[n,i]of Object.entries(e))t[n]={type:"interval",range:i},o=!0;o&&r(i,{clientId:n,type:"interval",fields:t})},[n,i,r]),clear:(0,Qa.useCallback)(()=>{s(i,n)},[s,i,n]),clientId:n}}function lc(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}var dc={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function uc(e,t={}){const n=t.mobileSemantics?.interaction,i="number"==typeof n?.targetSize?n.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,o="mobile"===t.mode||"number"==typeof t.width&&480>=t.width,r=!!n||void 0!==i,s=e&&"object"==typeof e?e:void 0;if(!1===e||!1===s?.enabled||void 0===e&&!o&&!r)return dc;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??i??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var hc={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function pc(e,t,n){if(!1!==t)return e;const i={...e};return"horizontal"===n?i.left=Math.min(i.left,15):i.bottom=Math.min(i.bottom,15),i}function mc(e,t,n){const i=e.xValue??t?.[n];if(null==i)return null;const o=Number(i);return Number.isFinite(o)?o:null}function fc(e){let t=e.data||e.datum||e;return Array.isArray(t)&&(t=t[0]),null!=e.xValue&&t&&"object"==typeof t&&!Array.isArray(t)&&null==t.xValue?{...t,xValue:e.xValue}:t||{}}var yc=[];function gc(e,t,n){return function(e,t,n){const i=hc[e||"primary"],o=e&&"primary"!==e||!n?.width?i.width:n.width,r=e&&"primary"!==e||!n?.height?i.height:n.height,s=function(e,t,n=e.responsiveRules){if(!Array.isArray(n)||0===n.length)return{props:e,matches:[]};const i=n.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){const{when:n}=e,i=t.width,o=t.height,r=function(e){if("number"==typeof e.height&&e.height>0)return e.width/e.height}(t),s=function(e){if("number"==typeof e.height&&e.height>0)return e.height>e.width?"portrait":"landscape"}(t);return!("number"==typeof n.minWidth&&n.minWidth>i||"number"==typeof n.maxWidth&&i>n.maxWidth||"number"==typeof n.minHeight&&("number"!=typeof o||n.minHeight>o)||"number"==typeof n.maxHeight&&("number"!=typeof o||o>n.maxHeight)||"number"==typeof n.minAspectRatio&&("number"!=typeof r||n.minAspectRatio>r)||"number"==typeof n.maxAspectRatio&&("number"!=typeof r||r>n.maxAspectRatio)||n.orientation&&s!==n.orientation)}(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:i.reduce((e,t)=>function(e,t){const n={...e,...t};for(const i of["margin","frameProps","mobileSemantics","style"])lc(e[i])&&lc(t[i])&&(n[i]={...e[i],...t[i]});return"string"==typeof e.className&&"string"==typeof t.className&&(n.className=`${e.className} ${t.className}`),n}(e,t.rule.transform),e),matches:i}}({...t,mode:e},{width:t.width??o,height:t.height??r}).props,a=s.mode||e||"primary",c=hc[a],l="context"===a||"sparkline"===a,d="primary"===a&&n?.width?n.width:c.width;return{mode:a,width:s.width??d,height:s.height??("primary"===a&&n?.height?n.height:c.height),showAxes:s.showAxes??c.showAxes,showGrid:s.showGrid??c.showGrid,enableHover:s.enableHover??(!!s.linkedHover||c.enableHover),showLegend:s.showLegend??c.showLegend,showLabels:s.showLabels??c.showLabels,title:l?void 0:s.title,description:s.description,summary:s.summary,accessibleTable:s.accessibleTable,xLabel:l?void 0:s.xLabel,yLabel:l?void 0:s.yLabel,categoryLabel:l?void 0:s.categoryLabel,valueLabel:l?void 0:s.valueLabel,marginDefaults:pc(c.marginDefaults,s.showCategoryTicks,s.orientation),compactMode:l,mobileInteraction:uc(s.mobileInteraction,{mode:a,width:s.width??d,mobileSemantics:s.mobileSemantics}),mobileSemantics:s.mobileSemantics}}(e,t,n)}var bc=require("react/jsx-runtime");function xc(e){return!!e&&"string"==typeof e.name}function vc(e,t=!1){if(!e?.datum)return null;const n=e.datum,i=n.sourceDatum;return t&&i&&"object"==typeof i?i:n}function wc(e){const{selection:t,linkedHover:n,colorBy:i,chartType:o,chartId:r,onBodyHover:s,fallbackFields:a,unwrapSourceDatum:c}=e,l="string"==typeof i?i:void 0,d=xc(t)?t:void 0,{activeSelectionHook:u,customHoverBehavior:h}=function({selection:e,linkedHover:t,fallbackFields:n=yc,unwrapData:i=!1,onObservation:o,chartType:r,chartId:s,onClick:a,hoverHighlight:c,colorByField:l,mobileInteraction:d}){const u=(0,Na.useId)(),h=(0,Na.useMemo)(()=>function(e,t){return e?!0===e?{name:"hover",fields:t||[]}:"string"==typeof e?{name:e,fields:t||[]}:{name:e.name||"hover",fields:e.fields||t||[],mode:e.mode,xField:e.xField,seriesField:e.seriesField}:null}(t,n),[t,n]),p=(0,Na.useMemo)(()=>"series"===h?.mode?[h.seriesField||l||n[0]].filter(e=>!!e):h?.fields||n,[h,l,n]),m=cc({name:e?.name||"__unused__",fields:p}),f=function(e){const t=e.name||"hover",{fields:n}=e,{predicate:i,isActive:o,selectPoints:r,clear:s}=cc({name:t,fields:n});return{onHover:(0,Qa.useCallback)(e=>{if(!e)return void s();const t={};for(const i of n){const n=e[i];void 0!==n&&(t[i]=[n])}x(t)&&r(t)},[n,r,s]),predicate:i,isActive:o}}({name:h?.name||"hover",fields:p}),y=fn(e=>e.pushObservation),g=(0,Na.useCallback)(e=>{o?.(e),y?.(e)},[o,y]),b=e?{isActive:m.isActive,predicate:m.predicate}:null,[v,w]=(0,Na.useState)(null),k=(0,Na.useRef)(!1),M=l||n[0],I=(0,Na.useMemo)(()=>{if(!c||null==v||!M)return null;const e=v,t=M;return{isActive:!0,predicate:n=>("string"==typeof n[t]?n[t]:(n[t]??"")+"")===e}},[c,v,M]),S=(0,Na.useCallback)((e,n)=>{const i=!e&&k.current&&!!d?.enabled&&d.tapToLockTooltip;if(t)if(e){let t=e.data||e.datum||e;if(Array.isArray(t)&&(t=t[0]),"x-position"===h?.mode&&h.xField){const n=mc(e,t,h.xField);null!=n&&function(e,t,n){const i=ic.positions.get(e);i?.locked||i&&i.xValue===t&&i.sourceId===n||(ic={positions:new Map(ic.positions).set(e,{xValue:t,sourceId:n})},rc())}(h.name||"hover",n,u)}"x-position"!==h?.mode&&f.onHover(t)}else"x-position"!==h?.mode||i||sc(h.name||"hover",u),"x-position"===h?.mode||i||f.onHover(null);if(c&&M)if(e){let t=e.data||e.datum||e;Array.isArray(t)&&(t=t[0]);const n=t?.[M];w(null!=n?n+"":null)}else i||w(null);(o||y)&&function(e){const{onObservation:t,datum:n,x:i=0,y:o=0,chartType:r,chartId:s,context:a,timestamp:c=Date.now()}=e;t&&(n?(t({type:"hover",datum:n,x:i,y:o,timestamp:c,chartType:r,chartId:s}),"focus"===a?.type&&t({type:"focus",datum:n,inputType:"touch"===a.inputType?"pointer":a.inputType,timestamp:c,chartType:r,chartId:s})):t({type:"hover-end",timestamp:c,chartType:r,chartId:s}))}({onObservation:g,datum:e?fc(e):null,x:e?.x,y:e?.y,chartType:r||"unknown",chartId:s,context:n})},[t,f,h,u,o,r,s,y,g,c,M,d]),j=(0,Na.useCallback)((n=!0)=>{k.current=!1,t&&"x-position"!==h?.mode&&f.onHover(null),e&&d?.tapToSelect&&m.clear(),n&&c&&w(null),"x-position"===h?.mode&&(ac(h.name||"hover",u),sc(h.name||"hover",u))},[t,h,f,e,d,m,c,u]),A=(0,Na.useCallback)((n,i)=>{const l=!!d?.enabled&&(d.tapToLockTooltip||d.tapToSelect),b=!!d?.enabled&&"backgroundTap"===d.clearSelection;if("x-position"===h?.mode&&h.xField&&n){let e=n.data||n.datum||n;Array.isArray(e)&&(e=e[0]);const t=mc(n,e,h.xField);null!=t&&function(e,t,n){const i=ic.positions.get(e);if(i?.locked){const t=new Map(ic.positions);return t.delete(e),ic={positions:t},rc(),!1}ic={positions:new Map(ic.positions).set(e,{xValue:t,sourceId:n,locked:!0})},rc()}(h.name||"hover",t,u)}if(l)if(n){k.current=!0;const i=fc(n);if(t&&"x-position"!==h?.mode&&f.onHover(i),e&&d?.tapToSelect&&p.length>0){const e={};for(const t of p){const n=i[t];void 0!==n&&(e[t]=[n])}(function(e){if(!e)return!1;for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1})(e)&&m.selectPoints(e)}if(c&&M){const e=i?.[M];w(null!=e?e+"":null)}}else b&&j();if(n||b){if(n&&a){let e=n.data||n.datum||n;Array.isArray(e)&&(e=e[0]),a(e,{x:n.x??0,y:n.y??0})}(o||y)&&function(e){const{onObservation:t,datum:n,x:i=0,y:o=0,chartType:r,chartId:s,context:a,timestamp:c=Date.now()}=e;t&&(n?(t({type:"click",datum:n,x:i,y:o,timestamp:c,chartType:r,chartId:s}),"activate"===a?.type&&t({type:"activate",datum:n,inputType:a.inputType,timestamp:c,chartType:r,chartId:s})):t({type:"click-end",timestamp:c,chartType:r,chartId:s}))}({onObservation:g,datum:n?fc(n):null,x:n?.x,y:n?.y,chartType:r||"unknown",chartId:s,context:i})}},[a,o,y,g,r,s,h,u,d,t,f,e,m,p,c,M,j]);return(0,Na.useEffect)(()=>{if(!d?.enabled||"undefined"==typeof document)return;const e=e=>{"Escape"===e.key&&k.current&&j()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[d?.enabled,j]),(0,Na.useEffect)(()=>()=>{k.current&&j(!1)},[j]),(0,Na.useEffect)(()=>{if("x-position"!==h?.mode)return;const e=h.name||"hover";return()=>{ac(e,u),sc(e,u)}},[h?.mode,h?.name,u]),{activeSelectionHook:b,hoverSelectionHook:I,customHoverBehavior:S,customClickBehavior:A,crosshairSourceId:u}}({selection:d,linkedHover:n,fallbackFields:l?[l]:a,onObservation:e.onObservation,onClick:e.onClick,chartType:o,chartId:r,colorByField:l}),p=xc(t)?null:t??null,m=(0,ja.useMemo)(()=>{if(p)return p;if(!u?.isActive)return null;const e=u.predicate;return{isActive:!0,predicate:t=>{const n=vc(t,c);return null!=n&&e(n)}}},[u?.isActive,u?.predicate,p,c]),f=(0,ja.useMemo)(()=>{if(n||s)return(e,t)=>{if(s?.(e,t),!n)return;const i=vc(e,c);h(i&&t?{...t,data:i}:null)}},[h,s,n,c]);return(0,ja.useMemo)(()=>({selection:m,onBodyHover:f}),[f,m])}var kc=new Set(["sample","mechanical"]);function Mc(e,t,n,i){const[o,r]=(0,ja.useState)(0),s=(0,ja.useRef)(null),a=(0,ja.useRef)(!1),c=function(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:null}(t),l=(0,ja.useRef)(c),d=(0,ja.useRef)(!!n),u=(0,ja.useRef)(i);l.current=c,d.current=!!n,u.current=i;const h=(0,ja.useCallback)(()=>{null!=s.current&&(clearTimeout(s.current),s.current=null)},[]),p=(0,ja.useCallback)(()=>{h();const e=l.current;null!=e&&!d.current&&a.current&&(s.current=setTimeout(()=>{s.current=null,a.current=!1,u.current?.(),r(e=>e+1)},e))},[h]);(0,ja.useEffect)(()=>{null==c||n?h():a.current&&p()},[h,c,n,p]),(0,ja.useEffect)(()=>h,[h]);const m=e?.observation?.onSimulationStateChange,f=(0,ja.useCallback)((e,t)=>{if(m?.(e,t),"running"===e)return a.current=!1,void h();"settled"===e&&"running"===t&&(a.current=!0,p())},[h,m,p]);return{config:(0,ja.useMemo)(()=>null==c?e:{...e,observation:{...e?.observation,onSimulationStateChange:f}},[e,c,f]),rerunKey:o}}function Ic(e,t,n){const i=n?.hasSimulationMode?function(e){const t=e=>"string"==typeof e&&kc.has(e);return e.simulationMode?{chartMode:t(e.mode)?void 0:e.mode,simulationMode:e.simulationMode}:t(e.mode)?{chartMode:void 0,simulationMode:e.mode}:{chartMode:e.mode,simulationMode:"sample"}}({mode:e.mode,simulationMode:e.simulationMode}):{chartMode:"sample"===e.mode||"mechanical"===e.mode?void 0:e.mode,simulationMode:"sample"},o=gc(i.chartMode,{width:e.width,height:e.height,enableHover:e.enableHover,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules},{width:t[0],height:t[1]}),r=e.size?.[0],s=e.size?.[1],a=t[0],c=t[1],l=(0,ja.useMemo)(()=>{return e=[a,c],(null!=r&&null!=s?[r,s]:void 0)??[o.width??e[0],o.height??e[1]];var e},[c,a,o.height,o.width,s,r]),d=o.compactMode?"sparkline"===i.chartMode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0};const u=e.showProjection??!o.compactMode,h=e.showChrome??!o.compactMode,p=Cc(e.tooltip,void 0),m=void 0!==p.enableHover?p.enableHover:o.enableHover,f=o.compactMode?o.title:o.title??e.title,y=[e.className,i.chartMode&&"primary"!==i.chartMode?"semiotic-physics--"+i.chartMode:null].filter(Boolean).join(" ")||void 0;return{chartMode:i.chartMode,simulationMode:i.simulationMode,resolved:o,chartSize:l,margin:d,showProjection:u,showChrome:h,enableHover:m,title:f,description:o.description??e.description,summary:o.summary??e.summary,accessibleTable:o.accessibleTable??e.accessibleTable,className:y,compactMode:o.compactMode,mobileInteraction:o.mobileInteraction,mobileSemantics:o.mobileSemantics}}function Sc(e){const[t,n]=e.size,i=function(e,t,n,i){if(!e)return null;if(!1===i)return null;if(null!=i)return(0,Da.jsx)("div",{style:{width:t,height:n,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:i});const o=Math.min(5,Math.floor(n/40)),r=Math.max(8,Math.floor(n/(3*o))),s=Math.max(6,Math.floor(n/(2.5*o))),a=Math.floor((n-(o*(r+s)-s))/2);return(0,Da.jsx)("div",{style:{width:t,height:n,position:"relative",overflow:"hidden",border:"1px solid var(--semiotic-border, #e0e0e0)",borderRadius:4,boxSizing:"border-box"},children:Array.from({length:o},(e,n)=>(0,Da.jsx)("div",{className:"semiotic-loading-bar",style:{...Ea,position:"absolute",top:a+n*(r+s),left:Math.floor(.1*t),width:30+(37*n+13)%50+"%",height:r,opacity:.5+n%2*.2}},n))})}(e.loading,t,n,e.loadingContent);return i||function(e,t,n,i){return!1===i||null==e||Array.isArray(e)&&e.length>0?null:Array.isArray(e)?(0,Da.jsx)("div",{style:{...Ta,width:t,height:n},children:i||"No data available"}):null}(e.data,t,n,e.emptyContent)}function jc(e,t,n){return(0,bc.jsx)(Ba,{componentName:e,width:t[0],height:t[1],children:n})}function Ac(e,t){return e?t?n=>(0,bc.jsxs)(bc.Fragment,{children:["function"==typeof e?e(n):e,"function"==typeof t?t(n):t]}):e:t}function Cc(e,t){return!1===e?{enableHover:!1}:{enableHover:t?.enableHover,tooltipContent:qe(e)||t?.tooltipContent}}function Rc(e,t,n,i){return{accessibleTable:i?.accessibleTable??e.accessibleTable??t?.accessibleTable,annotations:e.annotations??t?.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations??t?.autoPlaceAnnotations,background:e.background??t?.background,chartId:e.chartId??t?.chartId,chartMode:i?.chartMode??t?.chartMode,className:i?.className??e.className??t?.className,color:e.color??t?.color,description:i?.description??e.description??t?.description,emphasis:e.emphasis??t?.emphasis,enableHover:i?.enableHover??t?.enableHover,hoverRadius:e.hoverRadius??t?.hoverRadius,legend:e.legend??t?.legend,legendLayout:e.legendLayout??t?.legendLayout,legendPosition:e.legendPosition??t?.legendPosition,margin:i?.margin??t?.margin,maxDevicePixelRatio:e.maxDevicePixelRatio??t?.maxDevicePixelRatio,onClick:null!=e.onClick?(t,n)=>{t&&e.onClick?.(t,{x:n.x,y:n.y})}:t?.onClick,onObservation:e.onObservation??t?.onObservation,onAnnotationActivate:t?.onAnnotationActivate,opacity:e.opacity??t?.opacity,selection:i?.selection??t?.selection,semanticItems:t?.semanticItems??n,stroke:e.stroke??t?.stroke,strokeWidth:e.strokeWidth??t?.strokeWidth,summary:i?.summary??e.summary??t?.summary,svgAnnotationRules:e.svgAnnotationRules??t?.svgAnnotationRules,title:i?.title??e.title??t?.title}}var $c=require("react/jsx-runtime"),Pc=(0,d.forwardRef)(function(e,t){const{data:n,valueAccessor:i="value",styleRules:o,bins:r=21,ballRadius:s,colorBy:a,branchProbability:c=.5,emptyContent:l,frameProps:u,loading:h,loadingContent:p,mechanicalCount:m,paused:f,pegRows:y,referenceLines:g,rerunMS:b,responsiveHeight:x,responsiveWidth:v,seed:w=1,valueExtent:k}=e,M=Ic(e,[700,420],{hasSimulationMode:!0}),{chartSize:I,simulationMode:S,showProjection:j,className:A,title:C,chartMode:R,margin:$,enableHover:P,description:D,summary:B,accessibleTable:T}=M,E=s??("sparkline"===R?1.5:"context"===R?4:6),N=(0,d.useRef)(null),O=Math.max(1,Math.round(y??r-1)),F=(0,d.useMemo)(()=>"mechanical"===S?[0,O]:function(e){if(!e)return;const t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?t>n?[n,t]:[t,n]:void 0}(k),[O,S,k]),W=(0,d.useMemo)(()=>"mechanical"===S?function(e){const t=Math.max(2,Math.round(e.bins)),n=Math.max(1,Math.round(e.pegRows??t-1)),i=Math.max(1,Math.round(e.count??Math.max(64,4*t))),o=Ds(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),r=Es(e.seed??1),s=e.idPrefix??"mechanical";return Array.from({length:i},(e,t)=>{let i=0;for(let e=0;n>e;e+=1)r()<o&&(i+=1);const a=n/2;return{id:`${s}-${t}`,value:i,mechanical:!0,pegRows:n,branchProbability:o,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}({bins:r,branchProbability:c,count:m,pegRows:O,seed:w}):n??[],[r,c,n,m,O,w,S]),q=(0,d.useMemo)(()=>Os({data:W,valueAccessor:i,bins:r,ballRadius:E,seed:w,size:I,valueExtent:F}),[r,W,I,E,F,w,i]),z=Mc(q.config,b,f);Sa(t,{frameRef:N,spawnDatum:(0,d.useCallback)((e,t)=>{const n=Os({data:[e],valueAccessor:i,bins:r,ballRadius:E,seed:w+t+1,size:I,valueExtent:F}).initialSpawns[0]??{id:(e.id??"galton-push-"+t)+"",x:Ss(I).plot.x,y:Ss(I).plot.y,mass:1,shape:{type:"circle",radius:E},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[r,I,E,F,w,i]),seedRows:W,seedSpawns:q.initialSpawns});const L="mechanical"===S&&null==a?"side":a,H=(0,d.useMemo)(()=>As(L,"#4e79a7",{styleRules:o,valueAccessor:i}),[L,o,i]),Y=(0,d.useMemo)(()=>Rs(q.projectionRows,I,"bin"),[I,q.projectionRows]),{selection:_,onBodyHover:G}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:a,chartType:"GaltonBoardChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:u?.onBodyHover,fallbackFields:"string"==typeof i?[i]:void 0}),V=Sc({data:"mechanical"===S?W:n,emptyContent:l,loading:h,loadingContent:p,size:I});if(V)return V;const X=function(e,t,n,i,o){const r=Array.isArray(o)?o:o?[o]:[];if(!1!==n||0!==r.length)return({size:o})=>{const s=[Number(o[0])||700,Number(o[1])||420],a=Ss(s),c=Math.max(2,Math.round(t)),l=a.plot.width/c,d=a.plot.y+a.plot.height,u=Math.max(1,...e.map(e=>e.value)),h=!1!==n,[p,m]=i?.valueExtent??[0,c],f=m===p?1:m-p,y=e.map((e,t)=>{const n=d-e.value/u*a.plot.height*.9;return`${0===t?"M":"L"} ${(a.plot.x+(t+.5)*l).toFixed(1)} ${n.toFixed(1)}`}).join(" ");return(0,$c.jsxs)("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:s[0],height:s[1],viewBox:`0 0 ${s[0]} ${s[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?(0,$c.jsxs)($c.Fragment,{children:[Array.from({length:c+1},(e,t)=>{const n=a.plot.x+t*l;return(0,$c.jsx)("line",{"data-testid":"galton-board-bin-wall",x1:n,x2:n,y1:a.plot.y,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+t)}),(0,$c.jsx)("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),(0,$c.jsx)("path",{d:y,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>e.value>0?(0,$c.jsx)("text",{x:a.plot.x+(t+.5)*l,y:Math.max(a.plot.y+10,d-e.value/u*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`):null)]}):null,r.map((e,t)=>{const n=Number(e.value);if(!Number.isFinite(n))return null;const i=a.plot.x+Math.max(0,Math.min(1,(n-p)/f))*a.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===e.labelPosition?Math.min(s[1]-8,d+16):a.plot.y+16;return(0,$c.jsxs)("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[(0,$c.jsx)("line",{x1:i,x2:i,y1:a.plot.y+8,y2:d-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:(0,$c.jsx)("text",{x:Math.min(a.plot.x+a.plot.width-4,i+6),y:r,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${n}`)})]})}}(q.projectionRows,r,j,q.metadata,g),U=Cc(e.tooltip,u),K=Rc(e,u,Y,{selection:_,chartMode:R,className:A,title:C,description:D,summary:B,accessibleTable:T,enableHover:P,margin:$});return jc("GaltonBoardChart",I,(0,$c.jsx)(bs,{...u,...U,...K,ref:N,onBodyHover:G,config:z.config,foregroundGraphics:Ac(X,u?.foregroundGraphics),initialSpawns:q.initialSpawns,initialSpawnPacing:q.initialSpawnPacing,paused:f,responsiveHeight:x,responsiveWidth:v,size:I,bodyStyle:H},z.rerunKey))}),Dc=require("react"),Bc=require("react/jsx-runtime"),Tc=require("react"),Ec=(0,Dc.forwardRef)(function(e,t){const{arrivalAccessor:n="arrivalTime",ballRadius:i=7,colorBy:o,styleRules:r,data:s,emptyContent:a,frameProps:c,loading:l,loadingContent:d,paused:u,rerunMS:h,responsiveHeight:p,responsiveWidth:m,seed:f=1,timeAccessor:y="time",timeExtent:g,timeScale:b=1,watermark:x,windows:v={size:10}}=e,w=Ic(e,[760,360]),{chartSize:k,showProjection:M,className:I,title:S,chartMode:j,margin:A,enableHover:C,description:R,summary:$,accessibleTable:P}=w,D=(0,Dc.useRef)(null),B=(0,Dc.useMemo)(()=>s??[],[s]),T=(0,Dc.useMemo)(()=>qs({data:B,timeAccessor:y,arrivalAccessor:n,windows:v,watermark:x,ballRadius:i,seed:f,size:k,timeExtent:g,timeScale:b}),[n,i,k,B,f,y,g,b,x,v]),E=Mc(T.config,h,u),N=T.metadata;Sa(t,{frameRef:D,spawnDatum:(0,Dc.useCallback)((e,t)=>{const o=N?function(e,t,n,i){const o=Ps($s(e,t,i.timeAccessor));if(null==o)return null;const r=Ps($s(e,t,i.arrivalAccessor))??o,{windowPlot:s,windowStart:a,windowCount:c,windowSize:l,watermarkValue:d}=n,u=a+c*l,h=(0,Fs.scaleLinear)().domain([a,u]).range([s.x,s.x+s.width]),p=Math.max(0,Math.min(c-1,Math.floor((o-a)/l))),m=d>=a+(p+1)*l,{ballRadius:f}=i;return{id:(e.id??"event-push-"+t)+"",x:Math.max(s.x+f,Math.min(s.x+s.width-f,h(o))),y:s.y+f+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,shape:{type:"circle",radius:f},datum:{...e,eventTime:o,arrivalTime:r,windowIndex:p,late:m}}}(e,t,N,{timeAccessor:y,arrivalAccessor:n,ballRadius:i}):null,r=o??{id:(e.id??"event-push-"+t)+"",x:Ss(k).plot.x,y:Ss(k).plot.y,mass:1,shape:{type:"circle",radius:i},datum:e};return{datumId:(e.id??r.id)+"",spawns:[r]}},[n,i,k,N,y]),seedRows:B,seedSpawns:T.initialSpawns});const O=(0,Dc.useMemo)(()=>As(o,"#4e79a7",{styleRules:r,valueAccessor:y}),[o,r,y]),F=(0,Dc.useMemo)(()=>function(e,t,n){if(!t)return Rs(e,n,"window");const i=t.windowPlot.width/Math.max(1,e.length),o=Math.max(1,...e.map(e=>e.value+(e.secondary??0))),r=.62*t.windowPlot.height,s=t.windowPlot.y+t.windowPlot.height;return e.map((e,n)=>{const a=Math.max(8,(e.value+(e.secondary??0))/o*r),c=`window ${e.label}: ${e.value} on time${e.secondary?`, ${e.secondary} late`:""}`;return{id:"window-"+e.label,label:c,description:c,datum:e,x:t.windowPlot.x+(n+.5)*i,y:s-a/2,shape:"rect",width:Math.max(12,.58*i),height:a,group:"window"}})}(T.projectionRows,N,k),[k,T.projectionRows,N]),{selection:W,onBodyHover:q}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:o,chartType:"EventDropChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:c?.onBodyHover,fallbackFields:"string"==typeof y?[y]:void 0}),z=Sc({data:s,emptyContent:a,loading:l,loadingContent:d,size:k});if(z)return z;const L=function(e,t,n){if(!1!==n&&t)return({size:n})=>{const i=[Number(n[0])||760,Number(n[1])||360],o=Ss(i),r=Math.max(1,t.windowCount),s=t.plot??o.plot,a=t.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=t.windowPlot??s,l=c.width/r,d=s.y+s.height,u=s.y+.48*s.height,h=t.lidSegments[0]?.y1??u,p=t.windowStart,m=t.windowStart+r*t.windowSize,f=c.x+Math.max(0,Math.min(1,m===p?0:(t.watermarkValue-p)/(m-p)))*c.width;return(0,Bc.jsxs)("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,Bc.jsx)("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),a.width>0?(0,Bc.jsxs)("g",{children:[(0,Bc.jsx)("rect",{x:a.x,y:h,width:a.width,height:d-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),(0,Bc.jsx)("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(n,o)=>{const r=e[o],s=c.x+o*l,a=t.closedWindowCount>o,h=r?.secondary??0;return(0,Bc.jsxs)("g",{children:[(0,Bc.jsx)("rect",{x:s,y:u,width:l,height:d-u,fill:a?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?t.lidSegments.filter(e=>e.windowIndex===o).map(e=>(0,Bc.jsx)("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,(0,Bc.jsxs)("text",{x:s+l/2,y:u-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),(0,Bc.jsx)("text",{x:s+l/2,y:Math.min(i[1]-8,d+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+o)}),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>(0,Bc.jsx)("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),(0,Bc.jsx)("line",{x1:s.x,x2:s.x+s.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),(0,Bc.jsx)("line",{"data-testid":"event-drop-watermark",x1:f,x2:f,y1:s.y+8,y2:d,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),(0,Bc.jsxs)("text",{x:Math.min(s.x+s.width-4,f+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]}),t.lateCount>0?(0,Bc.jsxs)("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[t.lateCount," late"]}):null]})}}(T.projectionRows,T.metadata,M),H=Cc(e.tooltip,c),Y=Rc(e,c,F,{selection:W,chartMode:j,className:I,title:S,description:R,summary:$,accessibleTable:P,enableHover:C,margin:A});return jc("EventDropChart",k,(0,Tc.createElement)(bs,{...c,...H,...Y,ref:D,onBodyHover:q,key:E.rerunKey,config:E.config,foregroundGraphics:Ac(L,c?.foregroundGraphics),initialSpawns:T.initialSpawns,initialSpawnPacing:T.initialSpawnPacing,paused:u,responsiveHeight:p,responsiveWidth:m,size:k,bodyStyle:O}))}),Nc=require("react"),Oc=require("react/jsx-runtime"),Fc=require("react"),Wc=(0,Nc.forwardRef)(function(e,t){const{ballRadius:n=8,categoryAccessor:i="category",colorBy:o,data:r,emptyContent:s,frameProps:a,loading:c,loadingContent:l,mechanicalCategories:d,mechanicalCount:u,paused:h,rerunMS:p,responsiveHeight:m,responsiveWidth:f,seed:y=1,unitValue:g=1,valueAccessor:b,styleRules:x}=e,v=Ic(e,[700,380],{hasSimulationMode:!0}),{chartSize:w,simulationMode:k,showProjection:M,className:I,title:S,chartMode:j,margin:A,enableHover:C,description:R,summary:$,accessibleTable:P}=v,D=(0,Nc.useRef)(null),B="mechanical"===k&&null==b?"value":b,T=(0,Nc.useMemo)(()=>"mechanical"===k?function(e={}){const t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>(e+"").trim()).filter(Boolean),n=t.length?t:["Intake"],i=Math.max(n.length,Math.round(e.count??Math.max(48,12*n.length))),o=Bs(e.unitValue,1),r=Es(e.seed??1),s=e.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*r()),c=a.reduce((e,t)=>e+t,0)||1,l=i-n.length,d=a.map(e=>e/c*l),u=d.map(e=>1+Math.floor(e));let h=i-u.reduce((e,t)=>e+t,0);const p=d.map((e,t)=>({index:t,fraction:e-Math.floor(e)})).sort((e,t)=>t.fraction-e.fraction);for(let e=0;h>0;e=(e+1)%p.length)u[p[e].index]+=1,h-=1;return n.map((e,t)=>({id:`${s}-${t}`,category:e,value:u[t]*o,mechanical:!0,unitCount:u[t],unitValue:o,share:u[t]/i}))}({categories:d,count:u,seed:y,unitValue:g}):r??[],[r,d,u,y,k,g]),E=(0,Nc.useMemo)(()=>Ls({data:T,categoryAccessor:i,valueAccessor:B,unitValue:g,ballRadius:n,seed:y,size:w}),[n,i,w,T,B,y,g]),N=Mc(E.config,p,h);Sa(t,{frameRef:D,spawnDatum:(0,Nc.useCallback)((e,t)=>{const o=Ls({data:[e],categoryAccessor:i,valueAccessor:B,unitValue:g,ballRadius:n,seed:y+t+1,size:w}),r={id:(e.id??"pile-push-"+t)+"",x:Ss(w).plot.x,y:Ss(w).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e},s=o.initialSpawns.length?o.initialSpawns:[r];return{datumId:(e.id??s[0].id)+"",spawns:s}},[n,i,w,B,y,g]),seedRows:T,seedSpawns:E.initialSpawns});const O="mechanical"===k&&null==o?"category":o,F=(0,Nc.useMemo)(()=>As(O,"#4e79a7",{styleRules:x,valueAccessor:b}),[O,x,b]),W=(0,Nc.useMemo)(()=>Rs(E.projectionRows,w,"category"),[w,E.projectionRows]),{selection:q,onBodyHover:z}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:o,chartType:"UnitPileChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:a?.onBodyHover,fallbackFields:"string"==typeof i?[i]:void 0}),L=Sc({data:"mechanical"===k?T:r,emptyContent:s,loading:c,loadingContent:l,size:w});if(L)return L;const H=function(e,t,n){if(!1!==n&&0!==e.length)return({size:n})=>{const i=[Number(n[0])||700,Number(n[1])||380],o=Ss(i),r=zs(o.plot,e.length,t),s=o.plot.y+o.plot.height;return(0,Oc.jsxs)("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,Oc.jsx)("line",{x1:o.plot.x,x2:o.plot.x+o.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{const n=Math.min(o.plot.height,r.pileHeight(e.value)),a=r.tubeWidth,c=r.centerX(t),l=s-n;return(0,Oc.jsxs)("g",{children:[(0,Oc.jsx)("rect",{x:c-a/2,y:l,width:a,height:n,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),(0,Oc.jsx)("text",{x:c,y:Math.max(o.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),(0,Oc.jsx)("text",{x:c,y:Math.min(i[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)})]})}}(E.projectionRows,n,M),Y=Cc(e.tooltip,a),_=Rc(e,a,W,{selection:q,chartMode:j,className:I,title:S,description:R,summary:$,accessibleTable:P,enableHover:C,margin:A});return jc("UnitPileChart",w,(0,Fc.createElement)(bs,{...a,...Y,..._,ref:D,onBodyHover:z,key:N.rerunKey,config:N.config,foregroundGraphics:Ac(H,a?.foregroundGraphics),initialSpawns:E.initialSpawns,initialSpawnPacing:E.initialSpawnPacing,paused:h,responsiveHeight:m,responsiveWidth:f,size:w,bodyStyle:F}))}),qc=Wc,zc=require("react"),Lc=Object.freeze([]);function Hc(e){if(!e)return Lc;let t=!1;for(let n=0;e.length>n;n++){const i=e[n];if(null==i||"object"!=typeof i){t=!0;break}}if(!t)return e;const n=[];for(const t of e)null!=t&&"object"==typeof t&&n.push(t);return n}var Yc=require("d3-scale");function _c(e,t){const n=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>n&&Ka(n,e)||"#4e79a7":t=>{if(n){const e=Ka(n,t);if(e)return e}let i=0;for(let e=0;t.length>e;e++)i=31*i+t.charCodeAt(e)|0;return e[Math.abs(i)%e.length]??"#4e79a7"}}function Gc(e,t){const n=t.config??{},i=(t.sensors??[]).map(e=>({...e,sensor:!0})),o=[...t.colliders??[],...i],r=[...e.colliders??[],...n.colliders??[],...o];return{...e,...n,observation:{...e.observation,...n.observation},...r.length>0&&{colliders:r}}}function Vc(e){const t=function(e,t,n){const i=e?.observation;return{...e,observation:{...i,chartId:t??i?.chartId??"physics-custom",chartType:i?.chartType??"PhysicsCustomChart",onObservation:n??i?.onObservation}}}(e.config,e.chartId,e.onObservation),n=function(e,t,n=Ua){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){const t=Xa[e];if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:n}(e.colorScheme,e.themeCategorical,qa),i=Ss(e.size),o={data:e.data,scales:{x:(0,Yc.scaleLinear)().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:(0,Yc.scaleLinear)().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:_c(n,e.colorScheme),config:e.layoutConfig??{},world:new Oo(t)},r=e.skipLayout?{}:e.layout(o)??{},s=function(e,t){if(!t?.length)return e;const n=new Map;for(const e of t){const{bodyId:t,...i}=e,o=n.get(t)??[];o.push(i),n.set(t,o)}return e.map(e=>{const t=n.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:Gc(t,r),context:o,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}var Xc=require("react/jsx-runtime"),Uc=(0,zc.forwardRef)(function(e,t){const{chartId:n,color:i,colorBy:o,colorScheme:r,config:s,controllers:a,data:c,emptyContent:l,frameProps:d={},layout:u,layoutConfig:h,loading:p,loadingContent:m,onObservation:f,opacity:y,paused:g,spawnDatum:b,stroke:x,strokeWidth:v,title:w,xExtent:M,yExtent:I}=e,S=Ic(e,[700,380]),{chartSize:j,className:C,title:R,chartMode:$,margin:P,enableHover:D,description:B,summary:T,accessibleTable:E}=S,N=(0,zc.useRef)(null),O=(0,zc.useRef)(null),F=(0,zc.useRef)(""),{selection:W,onBodyHover:q}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:o,chartType:"PhysicsCustomChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:d?.onBodyHover}),z=Sc({data:c,emptyContent:l,loading:p,loadingContent:m,size:j}),L=null!=z,H=(0,zc.useMemo)(()=>Hc(c??[]),[c]),Y=A(e=>e.theme),_=(0,zc.useMemo)(()=>function(e){if(!e?.colors)return;const t=e.colors;return{primary:t.primary,secondary:t.secondary||t.primary,surface:t.surface||t.background,success:t.success,danger:t.danger,warning:t.warning,error:t.error,info:t.info,text:t.text,textSecondary:t.textSecondary,border:t.border,grid:t.grid}}(Y)??{},[Y]),G=Y?.colors?.categorical??k.colors.categorical,V=(0,zc.useMemo)(()=>[j[0],j[1],H.length,H.map((e,t)=>(e.id??t)+"").join("|"),M?.join(",")??"",I?.join(",")??""].join("::"),[j,H,M,I]),X=(0,zc.useMemo)(()=>Vc({chartId:n,colorScheme:r,config:s,data:H,layout:u,layoutConfig:h,onObservation:f,semantic:_,skipLayout:L,size:j,themeCategorical:G,xExtent:M,yExtent:I}),[n,j,r,s,u,h,f,H,_,L,G,M,I]);F.current===V&&null!=O.current||(F.current=V,O.current=X.initialSpawns);const U=O.current,K=(0,zc.useMemo)(()=>{const e=[...X.result.controllers??[],...a??[],...d.controllers??[]];return e.length?e:void 0},[d.controllers,a,X.result.controllers]),Q=(0,zc.useMemo)(()=>{const e=[...X.result.regionEffects??[],...d.regionEffects??[]];return e.length?e:void 0},[d.regionEffects,X.result.regionEffects]),Z=(0,zc.useCallback)(e=>{const t=e.datum,n=t&&o?function(e,t,n){return"function"==typeof n?n(e,0):e[n]}(t,0,o)+"":e.id;return{fill:i??X.context.resolveColor(n,t),stroke:x??"#111827",strokeWidth:v??1,opacity:y??.9}},[i,o,y,X.context,x,v]);Sa(t,{frameRef:N,spawnDatum:(0,zc.useCallback)((e,t)=>{const i=e;if(b)return function(e,t,n){return Array.isArray(n)?{datumId:(e.id??n[0]?.id??"physics-custom-"+t)+"",spawns:n}:"spawns"in n?n:{datumId:(e.id??n.id??"physics-custom-"+t)+"",spawns:[n]}}(e,t,b(i,t,X.context));const o=Vc({chartId:n,colorScheme:r,config:s,data:[i],layout:u,layoutConfig:h,onObservation:f,semantic:_,size:j,themeCategorical:G,xExtent:M,yExtent:I}),a=o.initialSpawns.length?o.initialSpawns:[{id:(e.id??"physics-custom-"+t)+"",x:o.context.dimensions.plot.x+o.context.dimensions.plot.width/2,y:o.context.dimensions.plot.y+12,mass:1,shape:{type:"circle",radius:5},datum:e}];return{datumId:(e.id??a[0].id)+"",spawns:a}},[n,j,r,s,b,u,h,f,X.context,_,G,M,I]),seedRows:H,seedSpawns:U});const J=(0,zc.useCallback)((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]);if(z)return z;const ee=Cc(e.tooltip,d),te=Rc(e,d,X.result.semanticItems,{selection:W,chartMode:$,className:C,title:R??w,description:B,summary:T,accessibleTable:E,enableHover:D,margin:P});return jc("PhysicsCustomChart",j,(0,Xc.jsx)(bs,{...d,...ee,...te,ref:N,onBodyHover:q,backgroundGraphics:Ac(d.backgroundGraphics,X.result.backgroundOverlays),bodyForces:X.result.bodyForces??d.bodyForces,bodyStyle:X.result.bodyStyle??d.bodyStyle??Z,config:X.config,controllers:K,foregroundGraphics:Ac(d.foregroundGraphics,X.result.overlays),initialSpawnPacing:X.initialSpawnPacing,initialSpawns:U,onBodyPointerDown:J,paused:g,regionEffects:Q,responsiveHeight:e.responsiveHeight,responsiveWidth:e.responsiveWidth,selectedBodyStyle:X.result.selectedBodyStyle??d.selectedBodyStyle,size:j}))});Uc.displayName="PhysicsCustomChart";var Kc=require("react"),Qc=require("react/jsx-runtime");function Zc(e){return e.toLocaleString(void 0,Math.abs(e)>=1e3||.01>Math.abs(e)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}var Jc=(0,Kc.forwardRef)(function(e,t){const{colorBy:n,styleRules:i,collisionIterations:o,data:r,emptyContent:s,frameProps:a,groupAccessor:c,loading:l,loadingContent:d,paused:u,pointRadius:h,radiusAccessor:p,rerunMS:m,responsiveHeight:f,responsiveWidth:y,seed:g=1,settle:b,xAccessor:x="x",xExtent:v}=e,w=Ic(e,[700,360]),{chartSize:k,showProjection:M,className:I,title:S,chartMode:j,margin:A,enableHover:C,description:R,summary:$,accessibleTable:P}=w,D=h??("sparkline"===j?2:"context"===j?4:5),B=(0,Kc.useRef)(null),T=(0,Kc.useMemo)(()=>r??[],[r]),E=(0,Kc.useMemo)(()=>Ys({data:T,xAccessor:x,groupAccessor:c,radiusAccessor:p,pointRadius:D,seed:g,size:k,xExtent:v,collisionIterations:o,settle:b}),[T,k,o,c,D,p,g,b,x,v]),N=Mc(E.config,m,u);Sa(t,{frameRef:B,spawnDatum:(0,Kc.useCallback)((e,t)=>{const n=Ys({data:[e],xAccessor:x,groupAccessor:c,radiusAccessor:p,pointRadius:D,seed:g+t+1,size:k,xExtent:v,collisionIterations:o,settle:b}).initialSpawns[0]??{id:(e.id??"collision-swarm-push-"+t)+"",x:Ss(k).plot.x,y:Ss(k).plot.y,mass:1,shape:{type:"circle",radius:D},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[k,o,c,D,p,g,b,x,v]),seedRows:T,seedSpawns:E.initialSpawns});const O=n??c,F=(0,Kc.useMemo)(()=>As(O,"#4e79a7",{styleRules:i,valueAccessor:x}),[O,i,x]),{selection:W,onBodyHover:q}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:O,chartType:"CollisionSwarmChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:a?.onBodyHover,fallbackFields:"string"==typeof x?[x]:void 0}),z=Sc({data:r,emptyContent:s,loading:l,loadingContent:d,size:k});if(z)return z;const L=function(e,t){if(!1!==t&&e)return({size:t})=>{const n=[Number(t[0])||700,Number(t[1])||360],i=Ss(n),o=i.plot.y+i.plot.height,[r,s]=e.xExtent,a=r+(s-r)/2,c=[{label:Zc(r),x:e.xRange[0]},{label:Zc(a),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:Zc(s),x:e.xRange[1]}];return(0,Qc.jsxs)("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.map(e=>(0,Qc.jsxs)("g",{children:[(0,Qc.jsx)("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),(0,Qc.jsx)("text",{x:i.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),(0,Qc.jsxs)("text",{x:i.plot.x+i.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count]})]},e.label)),(0,Qc.jsx)("line",{x1:e.xRange[0],x2:e.xRange[1],y1:o,y2:o,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(e=>(0,Qc.jsxs)("g",{children:[(0,Qc.jsx)("line",{x1:e.x,x2:e.x,y1:o,y2:o+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),(0,Qc.jsx)("text",{x:e.x,y:Math.min(n[1]-8,o+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}(E.metadata,M),H=function(e){if(!e)return[];const t=Math.max(24,e.xRange[1]-e.xRange[0]),n=e.xRange[0]+t/2;return e.groups.map(e=>{const i=`${e.label} lane: ${e.count} points`;return{id:"collision-swarm-"+e.label,label:i,description:i,datum:e,x:n,y:e.y,shape:"rect",width:t,height:28,group:"lane"}})}(E.metadata),Y=Cc(e.tooltip,a),_=Rc(e,a,H,{selection:W,chartMode:j,className:I,title:S,description:R,summary:$,accessibleTable:P,enableHover:C,margin:A});return jc("CollisionSwarmChart",k,(0,Qc.jsx)(bs,{...a,...Y,..._,ref:B,onBodyHover:q,config:N.config,foregroundGraphics:Ac(L,a?.foregroundGraphics),initialSpawns:E.initialSpawns,paused:u,responsiveHeight:f,responsiveWidth:y,size:k,bodyStyle:F},N.rerunKey))}),el={fresh:1,aging:1.5,stale:3};function tl(e,t,n={}){return Number.isFinite(t)&&t>0?Number.isNaN(e)?"fresh":e===1/0?"expired":0>e||t*(n.fresh??el.fresh)>e?"fresh":t*(n.aging??el.aging)>e?"aging":t*(n.stale??el.stale)>e?"stale":"expired":"fresh"}function nl(e,t,n){if(null!=e)return"function"==typeof e?e(t,n):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}function il(e){const{data:t,encoding:n}=e,i=[],o=new Map;return t.forEach((e,t)=>{const r=nl(n.id,e,t);if(null==r||""===r)throw Error(`[semiotic] Motion encoding row ${t} resolved an empty id.`);const s=r+"";if(o.has(s))throw Error(`[semiotic] Duplicate motion encoding id "${s}".`);const a=nl(n.process?.group,e,t),c=nl(n.process?.stage,e,t),l=nl(n.accessible?.group,e,t)??(null!=a?a+"":null!=c?c+"":void 0),d={};for(const i of Object.keys(n.evidence??{}))d[i]=nl(n.evidence?.[i],e,t);const u={id:s,datum:e,time:{arrival:nl(n.time?.arrival,e,t),basis:n.time?.basis,unit:n.time?.unit},placement:{x:nl(n.placement?.x,e,t),y:nl(n.placement?.y,e,t),lane:nl(n.placement?.lane,e,t),space:n.placement?.space},kinematics:{velocityX:nl(n.kinematics?.velocityX,e,t),velocityY:nl(n.kinematics?.velocityY,e,t),space:n.kinematics?.space},process:{group:a,stage:c,target:nl(n.process?.target,e,t),work:nl(n.process?.work,e,t)},evidence:d,accessible:{description:nl(n.accessible?.description,e,t),group:l,label:nl(n.accessible?.label,e,t)??s}};i.push(u),o.set(s,u)}),{rows:i,byId:o}}function ol(e){const t=e.now-e.arrival;return{age:t,progress:Number.isFinite(t)&&Number.isFinite(e.ttl)&&e.ttl>0?Math.max(0,t)/e.ttl:t===1/0&&Number.isFinite(e.ttl)&&e.ttl>0?1/0:0,lifecycle:tl(t,e.ttl,e.thresholds)}}function rl(e){const t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||0>=e.extent)return 1;const n=Math.max(0,e.age);if("step"===e.type)return(e.threshold??.5*e.extent)>n?1:t;if("exponential"===e.type){const i=e.halfLife??e.extent/2;return t+Math.pow(.5,n/(i>0?i:e.extent/2))*(1-t)}return t+Math.max(0,Math.min(1,1-n/e.extent))*(1-t)}function sl(e,t){const n=Number.isFinite(e)?e:0,i=Number.isFinite(t)?t:0;return{velocityX:n,velocityY:i,speed:Math.hypot(n,i),direction:Math.atan2(i,n)}}function al(e,t,n){return Number.isFinite(n)&&n>0?sl((t.x-e.x)/n,(t.y-e.y)/n):sl(0,0)}function cl(e){const{data:t,encoding:n,defaults:i={},scales:o}=e,r=il({data:t,encoding:n}),s=[],a=new Map,c=[],l=[],d=new Map;return r.rows.forEach((e,t)=>{const{id:r,datum:u}=e,h=Math.max(0,nl(n.appearance?.size,u,t)??i.size??6),p=nl(n.appearance?.shape,u,t)??i.shape??{type:"circle",radius:h},m=e.placement.x??i.x??0,f=e.placement.y??i.y??0,y=o?.x?o.x(m):m,g=o?.y?o.y(f):f,b=nl(n.appearance?.color,u,t)??i.color,x=nl(n.appearance?.opacity,u,t)??i.opacity,v=nl(n.appearance?.stroke,u,t)??i.stroke,w=nl(n.appearance?.strokeWidth,u,t)??i.strokeWidth,k=nl(n.time?.spawnAt,u,t)??e.time.arrival,M=e.kinematics.velocityX,I=e.kinematics.velocityY,S=nl(n.dynamics?.mass,u,t)??i.mass??1,j=nl(n.dynamics?.friction,u,t),A=nl(n.dynamics?.restitution,u,t),C=nl(n.dynamics?.bodyCollisions,u,t),R={id:r,x:y,y:g,mass:S,shape:{...p},datum:u,...null!=k&&{spawnAt:k},...null!=M&&{vx:M},...null!=I&&{vy:I},...null!=j&&{friction:j},...null!=A&&{restitution:A},...null!=C&&{bodyCollisions:C}},$={...null!=b&&{fill:b},...null!=x&&{opacity:x},...null!=v&&{stroke:v},...null!=w&&{strokeWidth:w}},P={id:r,datum:u,appearance:{color:b,opacity:x,shape:p,size:h,stroke:v,strokeWidth:w},placement:{x:y,y:g,lane:e.placement.lane,space:n.placement?.space??"world"},time:{arrival:k,spawnAt:k,basis:n.time?.basis??"simulation",unit:n.time?.unit},kinematics:{velocityX:M,velocityY:I,space:n.kinematics?.space??"world"},dynamics:{bodyCollisions:C,friction:j,mass:S,restitution:A},process:e.process,evidence:e.evidence,accessible:e.accessible,spawn:R};s.push(P),a.set(r,P),c.push(R),d.set(r,$),l.push({id:r,bodyId:r,label:e.accessible.label,description:e.accessible.description,datum:u,x:y,y:g,group:e.accessible.group})}),{rows:s,byId:a,spawns:c,semanticItems:l,bodyStyle:e=>d.get(e.id)??{}}}function ll(e){return t=>{const n=cl({data:t.data,encoding:e.encoding,defaults:e.defaults,scales:t.scales}),i=e.extend?.(t,n)??{};return{...i,initialSpawns:n.spawns,bodyStyle:n.bodyStyle,semanticItems:[...n.semanticItems,...i.semanticItems??[]]}}}var dl=require("react");function ul(e,t={}){const n=t.id??"physics-process-boundary",i={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("segment"===e.type)return[{...i,id:n,shape:e}];const o=t.thickness??8,r=e.x-e.width/2,s=e.x+e.width/2,a=e.y-e.height/2,c=e.y+e.height/2;return[{...i,id:n+"-top",shape:{type:"segment",x1:r,y1:a,x2:s,y2:a,thickness:o}},{...i,id:n+"-right",shape:{type:"segment",x1:s,y1:a,x2:s,y2:c,thickness:o}},{...i,id:n+"-bottom",shape:{type:"segment",x1:s,y1:c,x2:r,y2:c,thickness:o}},{...i,id:n+"-left",shape:{type:"segment",x1:r,y1:c,x2:r,y2:a,thickness:o}}]}function hl(e){if(!1===e.semanticItem)return null;const t=e.semanticItem??{},n=e.shape,i="aabb"===n.type?{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:n.x,y:n.y,width:n.width,height:n.height}:{id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"region",x:(n.x1+n.x2)/2,y:(n.y1+n.y2)/2,pathData:`M ${n.x1} ${n.y1} L ${n.x2} ${n.y2}`};return{...i,...t,id:t.id??i.id}}function pl(e){return e.map(e=>({id:e.id,label:e.label??e.id,description:e.description,group:e.kind??"stage",x:e.x??0,y:e.y??0,width:e.width,height:e.height}))}function ml(e){return e.flatMap(e=>{if(!1===e.semanticItem)return[];const t=e.semanticItem??{},n={id:e.id,label:e.label??e.id,description:e.description,datum:e.datum,group:e.group??e.state??"body group",x:e.x??0,y:e.y??0,width:e.width,height:e.height};return[{...n,...t,id:t.id??n.id}]})}var fl="gauntlet-core",yl="gauntlet-positive",gl="gauntlet-negative";function bl(e){const t=Sl(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function xl(e,t,n,i){return n?"function"==typeof n?n(e,t):e[n]??i:i}function vl(e){return e?.label??e?.id??"property"}function wl(e){return`gauntlet:${e}:core`}function kl(e,t){return`gauntlet:${e}:positive:${t}`}function Ml(e,t,n){return`gauntlet:${e}:negative:${t}:${n}`}var Il={left:28,top:76,rightInset:30,thickness:8};function Sl(e){const t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return Il;const n=Math.max(1,Math.min(e.width,t)),i=Math.max(2,.04*e.width);return{left:i,top:Math.max(2,.08*t),rightInset:i,thickness:Math.max(1,Math.min(4,.04*n))}}function jl(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function Al(e,t,n,i){const o=Sl(i),r=Math.max(2,n+2),s=o.top+o.thickness/2+r,a=i.floorY-r,c=(e,t,n)=>t>n?(t+n)/2:Math.max(t,Math.min(n,e));return{x:c(e,o.left+o.thickness/2+r,i.width-o.rightInset-o.thickness/2-r),y:c(t,s,a)}}function Cl(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}function Rl(e,t,n,i){const o=Cl(n),r=i?.(e,t,n)??{};return{...o,...r,startY:r.startY??r.routeY??o.startY,socketY:r.socketY??r.routeY??o.socketY,graveyardY:r.graveyardY??o.graveyardY}}function $l(e,t,n=1){const i=[...e].sort((e,t)=>e.localeCompare(t)),o=Math.max(0,i.indexOf(t));return{angle:.82*-Math.PI+(i.length>1?o/(i.length-1):.5)*Math.PI*.64,index:o,radius:(48+o%2*6)*n}}function Pl(e,t,n){const i=e.activePositiveIds.reduce((e,n)=>e+(t.get(n)?.value??1),0),o=e.missingPositiveIds.length+e.poppedPositiveIds.length,r=e.negativeIds.reduce((e,t)=>e+(n.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*r-1.2*e.delay-5*o))}function Dl(e,t,n,i,o){const r=xl(e,t,n.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",s=i.map(e=>e.id),a=[...xl(e,t,n.positiveAccessor,s)],c=[...xl(e,t,n.negativeAccessor,[])].filter(e=>o.has(e));return{id:r,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...xl(e,t,n.metricsAccessor,{})},missingPositiveIds:s.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(xl(e,t,n.startTimeAccessor,0))||0),stage:"project filed",viability:xl(e,t,n.initialViability,100)}}function Bl(e,t,n,i,o,r,s){const a=jl(n),c=Math.max(3,28*a),l=i.startX,d=i.startY+(i.startY===n.routeY?38*t*a:0),u=s?.(e,t,n,i)??{},h=u.x??l,p=u.y??d,m={__gauntlet:!0,kind:fl,projectId:e.id,sourceDatum:e.datum},f=[{...u,id:wl(e.id),x:h,y:p,vx:u.vx??42,vy:u.vy??0,mass:u.mass??7,bodyCollisions:u.bodyCollisions??!0,shape:u.shape??{type:"circle",radius:c},spawnAt:u.spawnAt??e.startedAt,datum:m}],y=Al(h,p,u.shape&&"radius"in u.shape&&Number(u.shape.radius)||c,n);f[0].x=y.x,f[0].y=y.y;for(const t of e.activePositiveIds){const i=o.get(t);if(!i)continue;const r=$l(e.activePositiveIds,t,a),s=i.radius??Math.max(2,10*a),c=Al(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,n);f.push({id:kl(e.id,t),x:c.x,y:c.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:u.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:yl,projectId:e.id,property:i,sourceDatum:e.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:wl(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const o=r.get(t);o&&f.push(Tl(e,o,i,y.x,y.y,n,u.spawnAt??e.startedAt))}),f}function Tl(e,t,n,i,o,r,s){const a=jl(r),c=t.radius??Math.max(2,7.2*a),l=Al(i+(n%4*12-12)*a,o+(54+12*Math.floor(n/4))*a,c,r);return{id:Ml(e.id,t.id,n),x:l.x,y:l.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:c},spawnAt:s,datum:{__gauntlet:!0,kind:gl,projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:wl(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+n%4*3)*a),...t.spring??{}}]}}function El(e){return e?Array.isArray(e)?[...e]:Object.entries(e).flatMap(([e,t])=>Array.from({length:Math.max(0,Math.round(Number(t)||0))},()=>e)):[]}function Nl(e,t){return t?Array.isArray(t)?[...t]:t.ids?[...t.ids]:t.candidates?t.candidates.filter(t=>e.includes(t)).slice(0,t.count??1):[]:[]}function Ol(e,t){return Nl(e.activePositiveIds,t.popPositive)}function Fl(e){const t=Number(e.budget),n=Number.isFinite(t)?Math.max(0,t):0,i=e.properties instanceof Map?e.properties:new Map(e.properties.map(e=>[e.id,e])),o=e.candidates?new Set(e.candidates):null,r=e.attachedIds.map((e,t)=>{const n=i.get(e),o=Number(n?.work??1),r=Number(n?.priority??t);return{id:e,index:t,priority:Number.isFinite(r)?r:t,work:Number.isFinite(o)&&o>0?o:1}}).filter(e=>!o||o.has(e.id)).sort((e,t)=>e.priority-t.priority||e.index-t.index),s=[],a=[];let c=0;for(const e of r)c+e.work>n+Number.EPSILON?a.push(e.id):(s.push(e.id),c+=e.work);return{ids:s,used:c,budget:n,remaining:Math.max(0,n-c),skippedIds:a}}function Wl(e,t){if(!t.from||!t.to||t.from===t.to)return{};const n=Math.max(0,Math.floor(Number(t.count??1)||0)),i=e.negativeIds.filter(e=>e===t.from).length,o=Math.min(n,i);return o?{addNegative:{[t.to]:o},popNegative:{ids:Array.from({length:o},()=>t.from)}}:{}}function ql(e,t){const n=Nl(e.negativeIds,t.popNegative);if(!n.length)return[];const i=new Map;for(const e of n)i.set(e,(i.get(e)??0)+1);const o=[];return e.negativeIds.forEach((e,t)=>{const n=i.get(e)??0;n>0&&(o.push({propertyId:e,index:t}),i.set(e,n-1))}),o}function zl(e,t,n){if(t.when&&!t.when(n))return e;let i={...e};const o=Ol(i,t);o.length&&(i={...i,activePositiveIds:i.activePositiveIds.filter(e=>!o.includes(e)),poppedPositiveIds:Array.from(new Set([...i.poppedPositiveIds,...o]))});const r=ql(i,t);if(r.length){const e=new Set(r.map(e=>e.index));i={...i,negativeIds:i.negativeIds.filter((t,n)=>!e.has(n)),poppedNegativeIds:[...i.poppedNegativeIds,...r.map(e=>e.propertyId)]}}const s=El(t.addPositive);s.length&&(i={...i,activePositiveIds:Array.from(new Set([...i.activePositiveIds,...s])),missingPositiveIds:i.missingPositiveIds.filter(e=>!s.includes(e))});const a=El(t.addNegative);if(a.length&&(i={...i,negativeIds:[...i.negativeIds,...a]}),t.delayDelta&&(i={...i,delay:i.delay+t.delayDelta}),t.metricsDelta){const e={...i.metrics};for(const[n,i]of Object.entries(t.metricsDelta))e[n]=Number(e[n]??0)+i;i={...i,metrics:e}}return t.viabilityDelta&&(i={...i,viability:i.viability+t.viabilityDelta}),t.stage&&(i={...i,stage:t.stage}),t.outcome&&(i={...i,outcome:t.outcome}),i}function Ll(e,t){return{id:e.id,label:e.label??e.id,summary:e.summary??t.find(e=>e.summary)?.summary,time:e.time}}function Hl(e,t){return e.eventsApplied.includes(t.id)?e:{...e,eventsApplied:[...e.eventsApplied,t.id],eventHistory:[...e.eventHistory??[],t],lastEvent:t,stage:t.label??e.stage}}function Yl(e,t){const n=e.datum;return!(!n?.__gauntlet||n.projectId!==t||n.kind!==gl)}function _l(e){const t=e.id.slice(e.id.lastIndexOf(":")+1),n=Number(t);return Number.isFinite(n)?n:-1}function Gl(e,t){return 2>Math.hypot(e.vx,e.vy)&&4>Math.hypot(t.x,t.y)?null:t}var Vl=require("react/jsx-runtime");function Xl(e){const t=e.data;return t?.__gauntlet?(0,Vl.jsxs)("div",{className:"semiotic-tooltip",style:{background:"var(--semiotic-tooltip-bg, rgba(15, 23, 42, 0.94))",color:"var(--semiotic-tooltip-text, #f8fafc)",padding:"8px 12px",borderRadius:6,boxShadow:"var(--semiotic-tooltip-shadow, 0 8px 24px rgba(0,0,0,0.35))",maxWidth:280},children:[(0,Vl.jsx)("strong",{children:t.kind===fl?"string"==typeof t.sourceDatum?.label?t.sourceDatum.label:t.projectId:vl(t.property)}),(0,Vl.jsx)("div",{children:t.kind===yl?"Positive property":t.kind===gl?"Negative property":"Project core"})]}):null}function Ul(e,t,n){const i=t.datum;if(!i?.__gauntlet)return;const o="circle"===t.shape.type?t.shape.radius:8;if(e.save(),e.translate(t.x,t.y),i.kind===fl)e.fillStyle=Kl(e,n.fill,"#0f766e"),e.strokeStyle=Kl(e,n.stroke,"#f8fafc"),e.lineWidth=2.4,e.beginPath(),e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke();else{const t=i.property;e.fillStyle=Kl(e,n.fill??t?.color,"#38bdf8"),e.strokeStyle=Kl(e,n.stroke,"#0f172a"),e.lineWidth=1.1,e.beginPath(),i.kind===gl?e.rect(-o,-o,2*o,2*o):e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke(),e.fillStyle=Kl(e,"var(--semiotic-bg, #07111f)","#07111f"),e.font=`900 ${i.kind===gl?9:8}px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(t?.short??t?.id?.slice(0,1).toUpperCase()??"?",0,.5)}e.restore()}function Kl(e,t,n){if("string"!=typeof t)return n;if("function"!=typeof getComputedStyle||!e.canvas)return t||n;const i=t.startsWith("var(")?t.match(/var\((--[^,\s)]+)/)?.[1]:t.startsWith("--")?t:null;return i?getComputedStyle(e.canvas).getPropertyValue(i).trim()||n:t||n}function Ql({layout:e,compact:t,showLabels:n}){const i=t?Math.round(.14*e.height):Math.max(80,e.routeY-180),o=t?Math.max(6,Math.round(.72*e.height)):Math.min(360,e.height-170);return(0,Vl.jsx)(Vl.Fragment,{children:e.gates.map(r=>(0,Vl.jsxs)("g",{children:[(0,Vl.jsx)("rect",{x:r.x-r.width/2,y:i,width:r.width,height:o,rx:t?2:12,fill:r.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:r.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),n?(0,Vl.jsx)("text",{x:r.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:r.label??r.id}):null]},r.id))})}function Zl({layout:e,states:t,compact:n=!1}){return n?(0,Vl.jsx)("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:(0,Vl.jsx)(Ql,{layout:e,compact:!0,showLabels:!1})}):(0,Vl.jsxs)("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,Vl.jsx)("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),(0,Vl.jsx)("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),(0,Vl.jsx)("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),(0,Vl.jsx)(Ql,{layout:e,compact:!1,showLabels:!0}),(0,Vl.jsxs)("g",{children:[(0,Vl.jsx)("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),(0,Vl.jsx)("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),(0,Vl.jsxs)("g",{children:[(0,Vl.jsx)("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),(0,Vl.jsx)("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),(0,Vl.jsx)("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function Jl(e){const t=e.datum;return!!t?.__gauntlet&&(t.kind===fl?{label:t.projectId+" project core",group:"project",description:"Project core carrying positive and negative properties."}:{label:`${vl(t.property)} ${t.kind===yl?"positive":"negative"} property`,group:t.kind===yl?"positive property":"negative property",description:`${vl(t.property)} attached to ${t.projectId}.`})}function ed({states:e,layout:t}){const n=function(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}(e);if(!n.length)return null;const i=Math.max(1,...n.map(e=>e.value)),o=Math.max(40,(t.width-80)/n.length);return(0,Vl.jsxs)("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,Vl.jsx)("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),n.map((e,t)=>{const n=40+t*o,r=Math.max(2,e.value/i*28),s=/kill|crash|block|grave/i.test(e.outcome);return(0,Vl.jsxs)("g",{children:[(0,Vl.jsx)("rect",{x:n+.18*o,y:28-r+22,width:Math.max(10,.45*o),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),(0,Vl.jsx)("text",{x:n+.4*o,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}var td=require("react/jsx-runtime"),nd=require("react"),id=[],od=(0,dl.forwardRef)(function(e,t){const{bodyGroups:n,coreBody:i,coreForceMode:o="route",crashDetection:r=!0,crashOffset:s=30,data:a,emptyContent:c,events:l,frameProps:d={},gates:u,initialSpawnPacing:h,loading:p,loadingContent:m,negativeProperties:f,onCapacityChange:y,onClick:g,onStateChange:b,outcome:x,paused:v,positiveProperties:w=id,projectPlacement:k,rerunMS:M,responsiveHeight:I,responsiveWidth:S,seed:j,showTethers:A=!0,terminalBehavior:C="outcome",viability:R}=e,$=(0,dl.useRef)(null),P=(0,dl.useMemo)(()=>({idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor}),[e.idAccessor,e.initialViability,e.metricsAccessor,e.negativeAccessor,e.positiveAccessor,e.startTimeAccessor]),D=Ic(e,[900,520]),{chartSize:B,showProjection:T,showChrome:E,className:N,title:O,chartMode:F,margin:W,enableHover:q,description:z,summary:L,accessibleTable:H}=D,{selection:Y,onBodyHover:_}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:void 0,chartType:"GauntletChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:d?.onBodyHover,fallbackFields:"string"==typeof e.idAccessor?[e.idAccessor]:["id"],unwrapSourceDatum:!0}),G=Sc({data:a,emptyContent:c,loading:p,loadingContent:m,size:B}),V=(0,dl.useMemo)(()=>Hc(a??[]),[a]),X=(0,dl.useMemo)(()=>V.map((e,t)=>xl(e,t,P.idAccessor,null!=e.id?e.id+"":"project-"+t)+"").join("|"),[V,P.idAccessor]),U=(0,dl.useMemo)(()=>new Map(w.map(e=>[e.id,e])),[w]),K=(0,dl.useMemo)(()=>new Map(f.map(e=>[e.id,e])),[f]),Q=(0,dl.useMemo)(()=>function(e,t,n){const[i,o]=e,r=220>i||160>o,s=Math.round(.48*o),a=r?o-Math.max(3,Math.min(12,.1*o)):o-36,c=(t??[]).filter(e=>!1!==e.enabled),l=Math.max(1,c.length),d=.22*i,u=l>1?(.78*i-d)/(l-1):0,h=r?Math.max(Math.round(.12*i),.08*i+6):Math.max(Math.round(.14*i),110);return{crashY:a-(r?Math.min(n,Math.max(3,.22*o)):n),floorY:a,gates:c.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(d+t*u),width:e.width??Math.max(r?8:54,Math.round(.07*i))})),graveyardX:Math.round(i*(r?.72:.84)),graveyardY:a-4,height:o,routeY:s,socketX:Math.round(i*(r?.82:.92)),startX:h,width:i}}(B,u,s),[B,s,u]),Z=(0,dl.useMemo)(()=>new Map(Q.gates.map(e=>[e.id,e])),[Q.gates]),J=(0,dl.useMemo)(()=>Q.gates.map(e=>({kind:"force-field",damping:.035,force:{x:12,y:0},semanticItem:!1,...e.regionEffect,id:"gauntlet-gate-"+e.id,label:e.label??e.id,description:e.description,bodyFilter:e.capacity?{property:"datum.kind",equals:fl}:e.regionEffect?.bodyFilter,shape:{type:"aabb",x:e.x,y:Q.routeY,width:e.capacity?e.capacity.sensorWidth??Math.max(220>Q.width?12:96,e.width*(220>Q.width?2:6)):Math.max(e.width,220>Q.width?10:54),height:Math.max(4,Math.min(360,Q.height-(160>Q.height?8:170)))}})),[Q.gates,Q.height,Q.routeY,Q.width]),[ee,te]=(0,dl.useState)(()=>V.map((e,t)=>{const n=Dl(e,t,P,w,K);return{...n,viability:R?.(n,{negativeProperties:K,positiveProperties:U})??Pl(n,U,K)}})),ne=(0,dl.useRef)(ee),ie=(0,dl.useRef)(0),oe=(0,dl.useRef)(new Map),re=(0,dl.useRef)([]),se=(0,dl.useRef)(y);se.current=y;const ae=(0,dl.useRef)(V);ae.current=V;const ce=(0,dl.useRef)(b);ce.current=b;const le=(0,dl.useRef)({negativeById:K,positiveById:U,positiveProperties:w,stateAccessors:P,viability:R});le.current={negativeById:K,positiveById:U,positiveProperties:w,stateAccessors:P,viability:R};const de=(0,dl.useCallback)((e,t,n=0)=>{const i=le.current,o=Dl(e,t,i.stateAccessors,i.positiveProperties,i.negativeById);return i.stateAccessors.startTimeAccessor||(o.startedAt=Math.max(0,n)),{...o,viability:i.viability?.(o,{negativeProperties:i.negativeById,positiveProperties:i.positiveById})??Pl(o,i.positiveById,i.negativeById)}},[]),ue=(0,dl.useCallback)(()=>{oe.current.clear(),re.current=[],ie.current=0;const e=ae.current.map((e,t)=>de(e,t));ne.current=e,te(e)},[de]),he=Mc((0,dl.useMemo)(()=>({fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7,...null!=j&&{seed:j},...d.config?.kernel??{}},colliders:[...bl(Q),...d.config?.colliders??[]]}),[d.config?.colliders,d.config?.kernel,Q,j]),M,v,ue),pe=(0,dl.useMemo)(()=>function(e){const{dataKey:t,gates:n,statesRef:i,processedGateVisitsRef:o}=e;return n.flatMap(e=>e.capacity&&e.capacity.unitsPerSecond>0?[Zo({id:`gauntlet-capacity-${t}-${e.id}`,regionId:"gauntlet-gate-"+e.id,unitsPerSecond:e.capacity.unitsPerSecond,bodyFilter:{property:"datum.kind",equals:fl},maxQueue:e.capacity.maxQueue,queueLayout:e.capacity.queueLayout,queueSlotSpacing:e.capacity.queueSlotSpacing,queueStiffness:e.capacity.queueStiffness??24,releaseImpulse:{x:36,y:0},unitAccessor:t=>{const n=t.datum,o=n?.sourceDatum,r=e.capacity?.unitAccessor,s=i.current.find(e=>e.id===n?.projectId);let a;"function"==typeof r?a=s?r(s):void 0:r&&(a=o?.[r]);const c=Number(a??o?.reviewWork??o?.work??s?.metrics.reviewWork??o?.points);return Number.isFinite(c)&&c>0?c:1},onProcessed:t=>{const n=t.datum;if(!n?.projectId)return;const i=`${n.projectId}:${e.id}`;o.current.set(i,(o.current.get(i)??0)+1)}})]:[])}({dataKey:`${X}:${he.rerunKey}`,gates:Q.gates,statesRef:ne,processedGateVisitsRef:oe}),[X,Q.gates,he.rerunKey]),me=(0,dl.useMemo)(()=>[...pe,...d.controllers??[]],[pe,d.controllers]);(0,dl.useEffect)(()=>{oe.current.clear(),re.current=[],ie.current=0;const e=ae.current.map((e,t)=>de(e,t));ne.current=e,te(e)},[de,X]),(0,dl.useEffect)(()=>{ne.current=ee,ce.current?.(ee)},[ee]);const fe=(0,dl.useCallback)(e=>[...("function"==typeof l?l(e,Q):l)??[]].sort((e,t)=>e.time-t.time),[l,Q]),ye=(0,dl.useCallback)((e,t,n)=>{if(!t.gateId||!Z.get(t.gateId)?.capacity)return!0;const i=Number(t.gateVisit),o=Number.isFinite(i)&&i>0?Math.floor(i):n.filter(e=>e.gateId===t.gateId).findIndex(e=>e.id===t.id)+1;return o>0&&(oe.current.get(`${e.id}:${t.gateId}`)??0)>=o},[Z]),ge=(0,dl.useCallback)(()=>{if(!pe.length)return;const e=pe.flatMap(e=>{const t=e.getSnapshot?.();return t?[t]:[]});var t,n;(t=re.current).length===(n=e).length&&t.every((e,t)=>{const i=n[t];return!!i&&e.regionId===i.regionId&&e.queueDepth===i.queueDepth&&e.blockedDepth===i.blockedDepth&&e.processedCount===i.processedCount&&e.metricRevision===i.metricRevision})||(re.current=e,se.current?.(e))},[pe]),be=(0,dl.useMemo)(()=>ee.flatMap((e,t)=>{const n=Rl(e,t,Q,k);return Bl(e,t,Q,n,U,K,i)}),[i,Q,K,U,k,ee]),xe=(0,dl.useCallback)((e,t)=>{let n=!1;const i=ne.current.map(i=>{if(i.id!==e)return i;const o=t(i);return n=n||o!==i,o});n&&(ne.current=i,te(i))},[]);(0,dl.useImperativeHandle)(t,()=>function(e){const{statesRef:t,setStates:n,elapsedRef:i,frameRef:o,layout:r,projectPlacement:s,positiveById:a,negativeById:c,coreBody:l,createState:d}=e;return{push:e=>{const u=d(e,t.current.length,i.current),h=Rl(u,t.current.length,r,s),p=Bl(u,t.current.length,r,h,a,c,l),m=[...t.current,u];t.current=m,n(m),o.current?.pushMany(p),o.current?.step(0)},pushMany:e=>{const u=[...t.current],h=[],p=i.current;e.forEach(e=>{const t=d(e,u.length,p),n=Rl(t,u.length,r,s);h.push(...Bl(t,u.length,r,n,a,c,l)),u.push(t)}),t.current=u,n(u),h.length&&o.current?.pushMany(h),o.current?.step(0)},remove:e=>{const i=Array.isArray(e)?e:[e],r=[],s=[];for(const e of i){const n=t.current.find(t=>t.id===e);n&&(r.push(n.datum),s.push(wl(n.id),...n.activePositiveIds.map(e=>kl(n.id,e))),n.negativeIds.forEach((e,t)=>{s.push(Ml(n.id,e,t))}))}return t.current=t.current.filter(e=>!i.includes(e.id)),n(t.current),o.current?.remove(s),r},update:(e,u)=>{const h=Array.isArray(e)?e:[e],p=[];for(const e of h){const n=t.current.find(t=>t.id===e);if(!n)continue;const h=t.current.findIndex(t=>t.id===e);p.push(n.datum);const m=u(n.datum),f=d(m,0>h?t.current.length:h,n.startedAt??i.current),y=Rl(f,0>h?t.current.length:h,r,s);o.current?.remove([wl(n.id),...n.activePositiveIds.map(e=>kl(n.id,e)),...n.negativeIds.map((e,t)=>Ml(n.id,e,t))]),o.current?.pushMany(Bl(f,0>h?t.current.length:h,r,y,a,c,l)),t.current=t.current.map(t=>t.id===e?f:t)}return n(t.current),p},clear:()=>{t.current=[],n([]),o.current?.clear()},getData:()=>t.current.map(e=>e.datum),getScales:()=>null,getCustomLayout:()=>o.current?.snapshot()??null,popBodies:(e,t)=>o.current?.popBodies(e,t)??[]}}({statesRef:ne,setStates:te,elapsedRef:ie,frameRef:$,layout:Q,projectPlacement:k,positiveById:U,negativeById:K,coreBody:i,createState:de}),[i,de,Q,K,U,k]);const ve="sparkline"===F?.22:"mobile"===F?.55:1,we=(0,dl.useCallback)((e,t,n)=>{!function(e){const{project:t,effect:n,controls:i,layout:o,positiveById:r,negativeById:s,coreBody:a,popBodies:c,popScale:l}=e,d=i.readBodies().find(e=>e.id===wl(t.id)),u=i.readBodies(),h=d?.x??o.startX,p=d?.y??o.routeY,m=function(e,t){let n=-1;for(const i of t)Yl(i,e.id)&&(n=Math.max(n,_l(i)));return Math.max(e.negativeIds.length,n+1)}(t,u),f=El(n.addNegative).flatMap((e,n)=>{const i=s.get(e);return i?[Tl(t,i,m+n,h,p,o)]:[]}),y=El(n.addPositive).flatMap(e=>{if(!r.get(e)||t.activePositiveIds.includes(e))return[];const n={...Cl(o),routeY:p,socketY:p,startX:h,startY:p};return Bl({...t,activePositiveIds:[e],negativeIds:[]},0,o,n,r,s,a).filter(e=>e.id.includes(":positive:"))});(f.length||y.length)&&i.pushMany([...f,...y]);const g=Ol(t,n);for(const e of g){const n=r.get(e);c([kl(t.id,e)],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??10)+3,scale:l})}const b=ql(t,n),x=function(e,t,n){const i=t.filter(t=>Yl(t,e.id)).sort((e,t)=>_l(e)-_l(t)||e.id.localeCompare(t.id)),o=new Set;return n.map(t=>{const n=i.find(e=>!o.has(e.id)&&e.datum.property?.id===t.propertyId);return n?(o.add(n.id),n.id):Ml(e.id,t.propertyId,t.index)})}(t,u,b);b.forEach((e,t)=>{const n=s.get(e.propertyId);c([x[t]],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??7)+3,scale:l})})}({project:e,effect:t,controls:n,layout:Q,positiveById:U,negativeById:K,coreBody:i,popBodies:(e,t)=>$.current?.popBodies(e,t),popScale:ve})},[i,Q,K,U,ve]),ke=(0,dl.useCallback)(({body:e,bodies:t})=>function(e){const{body:t,bodies:n,layout:i,states:o,projectPlacement:r,positiveById:s,negativeById:a,projectEvents:c,gateById:l,coreForceMode:d,terminalBehavior:u,elapsed:h}=e,p=t.datum;if(!p?.__gauntlet)return null;const m=o.findIndex(e=>e.id===p.projectId),f=0>m?void 0:o[m];if(!f)return null;const y=Rl(f,m,i,r),g=n.find(e=>e.id===wl(f.id)),b=jl(i),x=f.negativeIds.reduce((e,t)=>e+(a.get(t)?.load??1),0),v=f.killed?0:58*Math.max(.25,b);if(p.kind!==fl){if(!g)return null;let e;const o=p.property;if(o?.target){const r=n.filter(e=>{const t=e.datum;return t?.__gauntlet&&t.projectId===f.id&&t.kind===p.kind}).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),s=Math.max(0,r.findIndex(e=>e.id===t.id));e=o.target({body:t,bodies:n,core:g,index:s,layout:i,placement:y,project:f})??{x:g.x,y:g.y}}else if(p.kind===yl&&p.property){const t=$l(f.activePositiveIds,p.property.id,b);e={x:g.x+Math.cos(t.angle)*t.radius,y:g.y+Math.sin(t.angle)*t.radius-2}}else{const i=n.filter(e=>e.datum?.kind===gl&&e.datum.projectId===f.id).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),o=Math.max(0,i.findIndex(e=>e.id===t.id)),r=Math.floor(o/4);e={x:g.x+18*(o%4-(Math.min(4,i.length-4*r)-1)/2)*b,y:g.y+(54+13*r)*b}}const r="circle"===t.shape.type?t.shape.radius:8;e=Al(e.x,e.y,r,i);const s=Al(t.x,t.y,r,i);if(Math.abs(s.x-t.x)>.5||Math.abs(s.y-t.y)>.5)return{x:48*(s.x-t.x)-6*t.vx,y:48*(s.y-t.y)-6*t.vy};const a=p.kind!==yl||f.killed?0:3.2*(o?.buoyancy??o?.value??1),c=p.kind===gl?{x:.22*(o?.pull?.x??-8),y:.22*(o?.pull?.y??22)}:{x:0,y:0};return Gl(t,{x:28*(e.x-t.x)-3*(t.vx-g.vx)+c.x+.01*v,y:28*(e.y-t.y)-3*(t.vy-g.vy)+c.y-a})}if(f.killed)return Gl(t,{x:44*((f.crashX??f.metrics.lastX??t.x)-t.x)-9*t.vx,y:(160+12*x)*b-1.6*t.vy});const w=c(f),k=function(e,t,n,i,o,r,s){const a=jl(n);if(t.killed)return{x:t.metrics.lastX??i.graveyardX,y:i.graveyardY};const c=o[o.length-1];if(!c)return{x:i.socketX,y:i.routeY};const l=o.find(n=>e>=n.time&&!t.eventsApplied.includes(n.id)&&!(!n.gateId||!r.get(n.gateId)?.capacity)),d=l?Math.min(e,l.time):e,u="built"===t.outcome||"built_diminished"===t.outcome;if(d>c.time+.85){if("hold-last"===s){const e=c.gateId?r.get(c.gateId):void 0;return{x:c.routeX??e?.x??i.socketX,y:c.routeY??i.routeY}}return u?{x:i.socketX,y:i.socketY}:{x:i.graveyardX,y:i.graveyardY-14}}const h=.85*t.delay+12*t.negativeIds.length+8*(t.poppedPositiveIds.length+t.missingPositiveIds.length),p=[{time:0,x:i.startX,y:i.startY},...o.map(e=>{const t=e.gateId?r.get(e.gateId):void 0;return{time:e.time,x:e.routeX??t?.x??i.startX,y:e.routeY??i.routeY+.28*Math.min(180,h)*a}})].sort((e,t)=>e.time-t.time);let m=p[0],f=p[p.length-1];for(let e=1;p.length>e;e+=1){if(p[e].time>=d){f=p[e];break}m=p[e]}const y=Math.max(0,Math.min(1,(d-m.time)/Math.max(.1,f.time-m.time))),g=y*y*(3-2*y);return{x:m.x+(f.x-m.x)*g,y:m.y+(f.y-m.y)*g+7*Math.sin(2.6*d)*a}}(Math.max(0,h-(f.startedAt??0)),f,i,y,w,l,u),M=f.activePositiveIds.reduce((e,t)=>e+(s.get(t)?.buoyancy??s.get(t)?.value??1),0);return Gl(t,"net"===d?{x:15*(k.x-t.x)-1.8*t.vx+.18*v,y:1.25*(y.routeY-t.y)-1.4*t.vy+32*(x-M)}:{x:15*(k.x-t.x)-1.8*t.vx+.18*v,y:15*(k.y-t.y)-1.8*t.vy+13*x-2.2*M})}({body:e,bodies:t,layout:Q,states:ne.current,projectPlacement:k,positiveById:U,negativeById:K,projectEvents:fe,gateById:Z,coreForceMode:o,terminalBehavior:C,elapsed:ie.current}),[o,Z,Q,K,U,fe,k,C]),Me=(0,dl.useCallback)((e,t)=>{!function(e,t,n){const{frameProps:i,elapsedRef:o,statesRef:r,crashDetection:s,layout:a,projectEvents:c,gateById:l,capacityEventReady:d,addBodiesForEffect:u,updateProjectState:h,viability:p,positiveById:m,negativeById:f,outcome:y,reportCapacity:g}=n;i.onTick?.(e,t),o.current=e.elapsedSeconds??t.snapshot().elapsedSeconds,g();for(const e of r.current){const n=t.readBodies().find(t=>t.id===wl(e.id));if(!n)continue;if(s&&!e.killed&&n.y+("circle"===n.shape.type?n.shape.radius:28)>=a.crashY){t.readBodies().forEach(n=>{const i=n.datum;i?.__gauntlet&&i.projectId===e.id&&t.applyImpulse(n.id,-n.vx*n.mass,0)}),h(e.id,e=>{const t={appliedAt:Math.max(0,o.current-(e.startedAt??0)),id:"gauntlet-crash-line",label:"Crash Line",summary:"The project hit the crash threshold; lift and forward motion shut off.",time:Math.max(0,o.current-(e.startedAt??0))};return{...e,crashX:n.x,eventHistory:[...e.eventHistory??[],t],killed:!0,lastEvent:t,metrics:{...e.metrics,lastX:n.x},outcome:"bad_design_crash",stage:"Crash Line",viability:Math.min(0,e.viability)}});continue}if(e.killed)continue;const i=Math.max(0,o.current-(e.startedAt??0)),r=c(e),g=r.filter(t=>i>=t.time&&!e.eventsApplied.includes(t.id)&&d(e,t,r));let b=e;for(const n of g){const o=n.gateId?l.get(n.gateId):void 0,r=n.effects??[];for(const e of r){const i={event:n,gate:o,negativeProperties:f,positiveProperties:m,project:b};e.when&&!e.when(i)||(u(b,e,t),b=zl(b,e,i))}const s={...Ll(n,r),appliedAt:i};b=Hl(b,s),h(e.id,e=>{let t=Hl(e,s);if(t===e)return e;for(const e of r)t=zl(t,e,{event:n,gate:o,negativeProperties:f,positiveProperties:m,project:t});const i=p?.(t,{negativeProperties:f,positiveProperties:m})??Pl(t,m,f);return t={...t,viability:i},n.final&&(t={...t,outcome:n.outcome??y?.(t,{layout:a,negativeProperties:f,positiveProperties:m})??(t.viability>20?"built":"approved_not_built")}),t})}}}(e,t,{frameProps:d,elapsedRef:ie,statesRef:ne,crashDetection:r,layout:Q,projectEvents:fe,gateById:Z,capacityEventReady:ye,addBodiesForEffect:we,updateProjectState:xe,viability:R,positiveById:U,negativeById:K,outcome:x,reportCapacity:ge})},[we,ye,r,d,Z,Q,K,x,U,fe,ge,xe,R]),Ie=(0,dl.useCallback)((e,t)=>{const n="function"==typeof d.bodyStyle?d.bodyStyle(e,t):d.bodyStyle,i=e.datum;return i?.__gauntlet?{fill:i.kind===fl?"var(--semiotic-primary, #0f766e)":i.property?.color??"var(--semiotic-primary, #38bdf8)",stroke:i.kind===fl?"#f8fafc":"#0f172a",opacity:.96,...n}:n??{}},[d]),Se=(0,dl.useMemo)(()=>"function"==typeof n?n(ee,Q):n??[],[n,Q,ee]),je=(0,dl.useMemo)(()=>ml(Se),[Se]),Ae=(0,dl.useMemo)(()=>T?function(e,t){if(!e.length)return[];const n=Math.max(40,(t.width-80)/e.length);return e.map((e,t)=>{const i=`${e.id}: viability ${Math.round(e.viability)}, ${e.outcome||e.stage}`;return{id:"gauntlet-projection-"+e.id,label:i,description:i,datum:e,x:40+(t+.5)*n,y:28,shape:"rect",width:Math.max(16,.55*n),height:22,group:"settled projection"}})}(ee,Q):[],[Q,T,ee]),Ce=(0,dl.useMemo)(()=>[...Ae,...je],[je,Ae]),Re=(0,dl.useCallback)((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]),$e=(0,dl.useCallback)((e,t)=>{g&&(e&&"object"==typeof e&&e.__gauntlet?g(e.sourceDatum,{x:t.x,y:t.y}):e&&g(e,{x:t.x,y:t.y}))},[g]),Pe=(0,dl.useCallback)((e,t)=>{d.beforePaint?.(e,t),A&&function(e,t){const n=new Map(t.filter(e=>e.datum?.kind===fl).map(e=>[e.datum.projectId,e]));e.save(),e.lineWidth=1.1,e.setLineDash([3,4]);for(const i of t){const t=i.datum;if(!t?.__gauntlet||t.kind===fl)continue;const o=n.get(t.projectId);o&&(e.globalAlpha=t.kind===gl?.24:.36,e.strokeStyle=t.kind===gl?"#d94a45":"#7a8794",e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke())}e.restore()}(e,t)},[d,A]),De=(0,dl.useMemo)(()=>[...J,...d.regionEffects??[]],[d.regionEffects,J]);if(G)return G;const Be=Cc(e.tooltip,d),Te=Rc(e,d,Ce,{selection:Y,chartMode:F,className:N,title:O,description:z,summary:L,accessibleTable:H,enableHover:q,margin:W}),Ee=T?(0,td.jsx)(ed,{states:ee,layout:Q}):void 0,Ne=Ac(E?(0,td.jsx)(Zl,{layout:Q,states:ee,compact:D.resolved.compactMode}):void 0,d.backgroundGraphics),Oe=Ac(Ee,d.foregroundGraphics),Fe=d.renderBody??Ul,We=Be.tooltipContent??Xl;return jc("GauntletChart",B,(0,nd.createElement)(bs,{...d,...Be,...Te,key:`${B[0]}x${B[1]}:${X}:${he.rerunKey}`,ref:$,onBodyHover:_,accessibleTable:e.accessibleTable??d.accessibleTable,backgroundGraphics:Ne,bodyForces:ke,bodySemanticItems:d.bodySemanticItems??Jl,bodyStyle:Ie,beforePaint:Pe,onClick:g?$e:Te.onClick,config:he.config,controllers:me,enableHover:Be.enableHover??!0,foregroundGraphics:Oe,hoverRadius:e.hoverRadius??d.hoverRadius??18,initialSpawns:be,initialSpawnPacing:h,onBodyPointerDown:Re,onTick:Me,paused:v,regionEffects:De,renderBody:Fe,responsiveHeight:I,responsiveWidth:S,size:B,tooltipContent:We}))});od.displayName="GauntletChart";var rd=od;function sd(e,t){const{layout:n,positiveProperties:i,negativeProperties:o,viability:r,outcome:s}=t,a=function(e){return new Map(e.gates.map(e=>[e.id,e]))}(n),c=[...("function"==typeof t.events?t.events(e,n):t.events)??[]].sort((e,t)=>e.time-t.time);let l=e;for(const e of c){const t=e.gateId?a.get(e.gateId):void 0,c=e.effects??[],d=Hl(l,{...Ll(e,c),appliedAt:e.time});if(d!==l){l=d;for(const n of c){const r={event:e,gate:t,negativeProperties:o,positiveProperties:i,project:l};n.when&&!n.when(r)||(l=zl(l,n,r))}l={...l,viability:r?.(l,{negativeProperties:o,positiveProperties:i})??Pl(l,i,o)},e.final&&(l={...l,outcome:e.outcome??s?.(l,{layout:n,negativeProperties:o,positiveProperties:i})??(l.viability>20?"built":"approved_not_built")})}}return l}function ad(e){return e.projects.map(t=>sd(t,e))}var cd=require("react");function ld(e){return e.toLocaleString(void 0,1e3>Math.abs(e)?{maximumFractionDigits:1}:{maximumFractionDigits:0})}function dd(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}var ud=require("react/jsx-runtime"),hd=require("react");function pd(e){if(!e||"object"!=typeof e)return null;const t=e,n=Number(t.x),i=Number(t.y);return Number.isFinite(n)&&Number.isFinite(i)?{x:n,y:i}:null}function md(e){if(!e||"object"!=typeof e)return[];const t=e.flowPath;return Array.isArray(t)?t.map(pd).filter(e=>null!=e):[]}function fd(e,t){if(2>t.length)return null;let n=0;const i=[];for(let e=1;t.length>e;e+=1){const o=Math.hypot(t[e].x-t[e-1].x,t[e].y-t[e-1].y);i.push(o),n+=o}if(0>=n)return null;let o=null,r=0;for(let s=1;t.length>s;s+=1){const a=t[s-1],c=t[s],l=i[s-1];if(0>=l)continue;const d=c.x-a.x,u=c.y-a.y,h=Math.max(0,Math.min(1,((e.x-a.x)*d+(e.y-a.y)*u)/(l*l))),p={x:a.x+d*h,y:a.y+u*h},m={distance:Math.hypot(e.x-p.x,e.y-p.y),point:p,progress:(r+h*l)/n,tangent:{x:d/l,y:u/l},totalLength:n};o&&m.distance>=o.distance||(o=m),r+=l}return o}function yd(e,t,n){if(0===e.length)return{x:0,y:0};if(1===e.length||0>=n)return{...e[0]};let i=0;const o=Math.max(0,Math.min(1,t))*n;for(let t=1;e.length>t;t+=1){const n=e[t-1],r=e[t],s=Math.hypot(r.x-n.x,r.y-n.y);if(s>0){if(i+s>=o){const e=(o-i)/s;return{x:n.x+(r.x-n.x)*e,y:n.y+(r.y-n.y)*e}}i+=s}}return{...e[e.length-1]}}function gd(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function bd(e,t,n){const i=Math.hypot(e,t);if(n>=i||0>=i)return[e,t];const o=n/i;return[e*o,t*o]}function xd(e,t,n){const i=fd({...e,x:t[0].x,y:t[0].y},t),o=i?.tangent??{x:t[1].x-t[0].x,y:t[1].y-t[0].y},r=Math.hypot(o.x,o.y)||1,s=o.x/r,a=o.y/r,c=gd(e),l=function(e,t){let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return(n%1e3/1e3-.5)*t*1.4}(e.id,c);return{id:e.id,x:t[0].x+-a*l,y:t[0].y+s*l,vx:s*n,vy:a*n,mass:e.mass,shape:e.shape,datum:{...e.datum&&"object"==typeof e.datum?e.datum:{},routeProgress:0}}}var vd=(0,cd.forwardRef)(function(e,t){const{chartId:n,colorBy:i,coordinateMode:o="auto",data:r,edges:s,emptyContent:a,flowSpeed:c=90,frameProps:l,links:d,loading:u,loadingContent:h,maxParticles:p=180,nodeIdAccessor:m="id",nodeXAccessor:f="x",nodeYAccessor:y="y",nodes:g,onObservation:b,particleRadius:x=4,particleRate:v=.16,pathAccessor:w="path",pathConstraint:k="path",paused:M,reducedMotion:I=!1,rerunMS:S,responsiveHeight:j,responsiveWidth:A,seed:C=1,showNodeLabels:R=!0,showSensors:$=!1,showStaticFlow:P=!0,sourceAccessor:D="source",styleRules:B,targetAccessor:T="target",throughputAccessor:E="value"}=e,N=Ic(e,[760,420]),{chartSize:O,className:F,title:W,chartMode:q,margin:z,enableHover:L,description:H,summary:Y,accessibleTable:_}=N,G=(0,cd.useRef)(null),V=(0,cd.useMemo)(()=>g??[],[g]),X=(0,cd.useMemo)(()=>d??s??r??[],[r,s,d]),U=(0,cd.useMemo)(()=>Qs({nodes:V,links:X,nodeIdAccessor:m,nodeXAccessor:f,nodeYAccessor:y,sourceAccessor:D,targetAccessor:T,throughputAccessor:E,pathAccessor:w,coordinateMode:o,particleRate:v,maxParticles:p,particleRadius:x,flowSpeed:c,pathConstraint:k,reducedMotion:I,seed:C,size:O}),[X,V,O,o,c,p,m,f,y,x,v,w,k,I,C,D,T,E]);Sa(t,{frameRef:G,spawnDatum:(0,cd.useCallback)((e,t)=>{const n=Qs({nodes:V,links:[e],nodeIdAccessor:m,nodeXAccessor:f,nodeYAccessor:y,sourceAccessor:D,targetAccessor:T,throughputAccessor:E,pathAccessor:w,coordinateMode:o,particleRate:v,maxParticles:p,particleRadius:x,flowSpeed:c,pathConstraint:k,reducedMotion:I,seed:C+t+1,size:O}),i={id:(e.id??"physical-flow-push-"+t)+"",x:Ss(O).plot.x,y:Ss(O).plot.y,mass:1,shape:{type:"circle",radius:x},datum:e},r=n.initialSpawns.length?n.initialSpawns:[i];return{datumId:(e.id??r[0].id)+"",spawns:r}},[V,O,o,c,p,m,f,y,x,v,w,k,I,C,D,T,E]),seedRows:X,seedSpawns:U.initialSpawns});const K=i??"source",Q=(0,cd.useMemo)(()=>As(K,"#2563eb",{styleRules:B,valueAccessor:E}),[K,B,E]),Z=Mc((0,cd.useMemo)(()=>function(e,t,n){return{...e,observation:{...e.observation,chartId:t??e.observation?.chartId??"physical-flow",chartType:"PacketFlowChart",onObservation:n??e.observation?.onObservation}}}(U.config,n,b),[n,U.config,b]),S,M),J=(0,cd.useRef)(l?.onTick);J.current=l?.onTick;const ee=(0,cd.useCallback)((e,t)=>{I||"none"===k||function(e,t){const n=e.readBodies(),i=[],o=[];for(const r of n){const n=md(r.datum);if(2>n.length)continue;const s=fd(r,n);if(!s)continue;const a=r.datum,c=Number(a?.flowSpeed),l=Number.isFinite(c)&&c>0?c:t;if(s.progress>=.985||s.distance>Math.max(90,14*gd(r))){i.push(r.id),o.push(xd(r,n,l));continue}const d=yd(n,Math.min(1,s.progress+Math.max(.035,Math.min(.12,l/s.totalLength*.16))),s.totalLength),u=s.tangent,h=(u.x*l-r.vx)*r.mass*.16+(d.x-r.x)*r.mass*.045+(s.point.x-r.x)*r.mass*.08,p=(u.y*l-r.vy)*r.mass*.16+(d.y-r.y)*r.mass*.045+(s.point.y-r.y)*r.mass*.08,[m,f]=bd(h,p,r.mass*l*.35);e.applyImpulse(r.id,m,f)}i.length&&e.remove(i),o.length&&e.pushMany(o)}(t,c),J.current?.(e,t)},[c,k,I]),{selection:te,onBodyHover:ne}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:i,chartType:"PacketFlowChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:l?.onBodyHover,fallbackFields:"string"==typeof D?[D]:void 0}),ie=Sc({data:null==d&&null==s&&null==r?void 0:X,emptyContent:a,loading:u,loadingContent:h,size:O});if(ie)return ie;const oe=function(e,t){const{showNodeLabels:n,showSensors:i,showStaticFlow:o}=t;if(e&&(o||i))return({size:t})=>{const r=[Number(t[0])||760,Number(t[1])||420],s=Math.max(1,...e.links.map(e=>e.throughput)),a=new Set(e.nodes.map(e=>e.sensorId));return(0,ud.jsxs)("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[o?e.links.map(e=>{const t=3+e.throughput/s*16,n=e.path[Math.floor(e.path.length/2)];return(0,ud.jsxs)("g",{children:[(0,ud.jsx)("path",{d:dd(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),(0,ud.jsx)("path",{d:dd(e.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),n?(0,ud.jsx)("text",{x:n.x,y:n.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:ld(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>(0,ud.jsxs)("g",{children:[i&&a.has(e.sensorId)?(0,ud.jsx)("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,o?(0,ud.jsx)("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,n?(0,ud.jsx)("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}(U.metadata,{showNodeLabels:R,showSensors:$,showStaticFlow:P}),re=(se=U.metadata)?se.links.map(e=>{const t=e.path[Math.floor(e.path.length/2)]??e.path[0],n=`${e.sourceLabel} to ${e.targetLabel}: ${ld(e.throughput)} throughput, ${e.packetCount} packets`;return{id:e.id,label:n,description:n,datum:e,x:t?.x??0,y:t?.y??0,shape:"path",pathData:dd(e.path),group:"flow"}}):[];var se;const ae=Cc(e.tooltip,l),ce=Rc(e,l,re,{selection:te,chartMode:q,className:F,title:W,description:H,summary:Y,accessibleTable:_,enableHover:L,margin:z});return jc("PacketFlowChart",O,(0,hd.createElement)(bs,{...l,...ae,...ce,key:Z.rerunKey,ref:G,onBodyHover:ne,config:Z.config,continuous:!I&&"none"!==k,foregroundGraphics:Ac(oe,l?.foregroundGraphics),initialSpawns:U.initialSpawns,onTick:ee,paused:M||I,responsiveHeight:j,responsiveWidth:A,simulationExecution:"none"===k?l?.simulationExecution:"sync",size:O,bodyStyle:Q,workerBodyThreshold:l?.workerBodyThreshold??1/0}))});vd.displayName="PacketFlowChart";var wd=vd,kd=require("react"),Md=require("react/jsx-runtime"),Id={flow:{fill:"rgba(59, 130, 246, 0.14)",stroke:"rgba(96, 165, 250, 0.7)",accent:"#60a5fa"},capacity:{fill:"rgba(251, 146, 60, 0.18)",stroke:"rgba(251, 146, 60, 0.85)",accent:"#fb923c"},portal:{fill:"rgba(244, 114, 182, 0.14)",stroke:"rgba(244, 114, 182, 0.7)",accent:"#f472b6"},absorb:{fill:"rgba(52, 211, 153, 0.18)",stroke:"rgba(52, 211, 153, 0.8)",accent:"#34d399"}},Sd=6.2;function jd(e,t,n){return Math.max(t,Math.min(n,e))}function Ad(e){return e.length*Sd}function Cd(e,t){const n=e.trim();if(t>=n.length)return n;if(1>=t)return n.slice(0,1);const i=n.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return i.length>1&&t>=i.length?i:t>3?n.slice(0,Math.max(1,t-2))+"..":n.slice(0,t).toUpperCase()}function Rd(e,t,n="auto"){const i=Math.max(1,Math.floor(t/Sd)),o="compact"===n?Cd(e,i):"full"===n?e:Ad(e)>t?Cd(e,i):e;return{text:o,textLength:Ad(o)>t?Math.max(4,t):void 0}}function $d(e,t={}){const{showFlowSpine:n=!0,showStageCounts:i=!0,showCapacityBadges:o=!0,showGroupSockets:r=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=t,{width:l,height:d,left:u,right:h,topY:p,bottomY:m,midY:f,stages:y,groups:g=[]}=e,b=m-p;return(0,Md.jsxs)("svg",{"aria-hidden":"true","data-testid":c,"data-outline-stages":a?"true":void 0,width:l,height:d,viewBox:`0 0 ${l} ${d}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",a?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[(0,Md.jsx)("defs",{children:(0,Md.jsxs)("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[(0,Md.jsx)("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),(0,Md.jsx)("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),(0,Md.jsx)("rect",{x:0,y:0,width:l,height:d,fill:"url(#semiotic-process-floor)"}),(0,Md.jsx)("rect",{x:u-6,y:p-8,width:h-u+12,height:b+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),n?(0,Md.jsx)("line",{x1:u+8,x2:h-8,y1:f,y2:f,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,y.map((e,t)=>{const n=function(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}(e),r=Id[n],c=Math.max(12,e.width-8),l=jd(c-8,22,88),u=Rd(e.label,Math.max(8,l-10),s),h="none"!==s&&c-8>=22,g=function(e){if(null!=e.capacity){const t=null!=e.queueDepth?" · q "+e.queueDepth:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?e.capacity+"":e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}(e),x=Rd(g,Math.max(16,c-10),"auto"),v=o&&!1!==e.showBadge&&c>=32,w=null!=e.count?`n=${e.count}${null!=e.processed?" done "+e.processed:""}`:"",k=Rd(w,Math.max(16,c-8),"auto"),M=Math.max(30,p-15),I=M-13;return(0,Md.jsxs)("g",{"data-stage":e.id,"data-role":n,children:[(0,Md.jsx)("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:c,height:b-12,rx:10,fill:a?"none":r.fill,stroke:r.stroke,strokeWidth:a?1.85:"flow"===n?1:1.6}),y.length-1>t?(0,Md.jsx)("polygon",{points:`${e.x1-2},${f-7} ${e.x1+8},${f} ${e.x1-2},${f+7}`,fill:r.accent,opacity:.85}):null,h?(0,Md.jsxs)(Md.Fragment,{children:[(0,Md.jsx)("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-l/2,y:I,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:r.stroke}),(0,Md.jsxs)("text",{x:e.x,y:M,textAnchor:"middle",fill:r.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[(0,Md.jsx)("title",{children:e.label}),u.text]})]}):null,v?(0,Md.jsxs)("text",{x:e.x,y:p+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:x.textLength,lengthAdjust:x.textLength?"spacingAndGlyphs":void 0,children:[(0,Md.jsx)("title",{children:g}),x.text]}):null,i&&null!=e.count?(0,Md.jsxs)("text",{x:e.x,y:Math.min(d-8,m+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:k.textLength,lengthAdjust:k.textLength?"spacingAndGlyphs":void 0,children:[(0,Md.jsx)("title",{children:w}),k.text]}):null]},e.id)}),r?g.map((e,t)=>{const n=e.total??0,i=e.absorbed??0,o=e.complete??(n>0&&i>=n),r=!o&&n>0&&i/n>=.75,s=o?"rgba(52, 211, 153, 0.35)":r?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=o?"#34d399":r?"#fbbf24":"var(--semiotic-border, #64748b)",c=n>0?`${i}/${n}${o?" shipped":r?" almost":""}`:"feature "+(t+1),l=jd(Math.max(54,Ad(e.label)+18,Ad(c)+16),54,104),d=Rd(e.label,l-12,"auto"),u=Rd(c,l-12,"auto");return(0,Md.jsxs)("g",{"data-group":e.id,children:[(0,Md.jsx)("rect",{x:e.x-l/2,y:e.y-22,width:l,height:44,rx:10,fill:s,stroke:a,strokeWidth:1.5}),(0,Md.jsxs)("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[(0,Md.jsx)("title",{children:e.label}),d.text]}),(0,Md.jsxs)("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:a,fontSize:9,fontWeight:700,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[(0,Md.jsx)("title",{children:c}),u.text]})]},e.id)}):null]})}var Pd=require("react/jsx-runtime"),Dd=(0,kd.forwardRef)(function(e,t){const{ballRadius:n=6,chromeOptions:i,colorBy:o,data:r,emptyContent:s,frameProps:a={},groupAnchorAlong:c,groupBy:l,groupCompletion:d,groupLabelAccessor:u,gravityX:h,gravityY:p,idAccessor:m,initialSpawnPacing:f,liveCapacity:y=!0,onCapacityChange:g,selection:b,bodyLimit:x,bodyMark:v,loading:w,loadingContent:k,paused:M,radiusAccessor:I,rerunMS:S,responsiveHeight:j,responsiveWidth:A,route:C="horizontal",seed:R=1,settle:$,springDamping:P,springStiffness:D,stageAccessor:B="stage",stages:T,workAccessor:E}=e,N=Ic(e,[900,420]),{chartSize:O,showProjection:F,showChrome:W,className:q,title:z,chartMode:L,margin:H,enableHover:Y,description:_,summary:G,accessibleTable:V}=N,X=(0,kd.useRef)(null),U=(0,kd.useMemo)(()=>Hc(r??[]),[r]),K=(0,kd.useMemo)(()=>({data:U,stages:T,size:O,idAccessor:m,stageAccessor:B,groupBy:l,groupLabelAccessor:u,workAccessor:E,radiusAccessor:I,ballRadius:n,seed:R,route:C,groupCompletion:d,groupAnchorAlong:c,springStiffness:D,springDamping:P,gravityX:h,gravityY:p,settle:$}),[n,O,h,p,c,l,d,u,m,I,C,U,R,$,P,D,B,T,E]),Q=(0,kd.useMemo)(()=>va(K),[K]),Z=Q.metadata;Sa(t,{frameRef:X,spawnDatum:(0,kd.useCallback)((e,t)=>{const i=va({...K,data:[e],seed:R+t+1,settle:!0}).initialSpawns[0]??{id:(e.id??"process-flow-push-"+t)+"",x:Ss(O).plot.x,y:Ss(O).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e};return{datumId:(e.id??i.id)+"",spawns:[i]}},[n,K,O,R]),seedRows:U,seedSpawns:Q.initialSpawns});const J=(0,kd.useMemo)(()=>As(o),[o]),ee=(0,kd.useMemo)(()=>{if(!y)return a.controllers;const e=[...T.filter(e=>e.capacity&&e.capacity.unitsPerSecond>0).map(e=>{const t=e.capacity.unitsPerSecond;return Zo({id:"process-capacity-"+e.id,regionId:"process-stage-"+e.id,unitsPerSecond:t,unitAccessor:e.capacity.unitAccessor??(E?"string"==typeof E?E:e=>{const t=e.datum;if(!t)return 1;try{return Number(E(t,0))||1}catch{return 1}}:"work"),releaseImpulse:{x:70+Math.min(40,2*t),y:0},queueLayout:"lane",continuous:!0})}),...a.controllers??[]];return e.length?e:void 0},[a.controllers,y,T,E]),[te,ne]=(0,kd.useState)({}),ie=(0,kd.useRef)(ee);ie.current=ee;const oe=(0,kd.useRef)(a.onTick);oe.current=a.onTick;const re=!1!==W||null!=g;(0,kd.useEffect)(()=>{if(!g)return;const e=Object.values(te);e.length&&g(e)},[te,g]);const se=(0,kd.useCallback)((e,t)=>{if(oe.current?.(e,t),!re)return;const n=ie.current;if(!n?.length)return;const i={};for(const e of n){const t=e.getSnapshot?.();t&&"string"==typeof t.regionId&&(i[t.regionId]=t)}ne(e=>function(e,t){const n=Object.keys(e),i=Object.keys(t);if(n.length!==i.length)return!1;for(const i of n){const n=e[i],o=t[i];if(!o)return!1;if(n.queueDepth!==o.queueDepth||n.blockedDepth!==o.blockedDepth||n.processedCount!==o.processedCount||n.unitsPerSecond!==o.unitsPerSecond||n.regionId!==o.regionId||n.metricRevision!==o.metricRevision)return!1}return!0}(e,i)?e:i)},[re]),ae=(0,kd.useMemo)(()=>{const e=J,t=a.bodyStyle;return v||t?(n,i)=>{const o="function"==typeof t?t(n,i):t;return{..."function"==typeof e?e(n):e,...o,mark:o?.mark??n.datum?.__physicsMark??n.datum?.mark??v}}:e},[v,J,a.bodyStyle]),ce=Mc((0,kd.useMemo)(()=>({...Q.config,...null!=x?{bodyLimit:x,eviction:"oldest"}:{},...a.config}),[x,a.config,Q.config]),S,M),{selection:le,onBodyHover:de}=wc({selection:b,linkedHover:e.linkedHover,colorBy:o,chartType:"ProcessFlowChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:a?.onBodyHover,fallbackFields:"string"==typeof B?[B]:void 0}),ue=Sc({data:r,emptyContent:s,loading:w,loadingContent:k,size:O});if(ue)return ue;if(!T?.length)return jc("ProcessFlowChart",O,(0,Pd.jsx)("div",{role:"status",style:{width:O[0],height:O[1],display:"grid",placeItems:"center",color:"var(--semiotic-text-secondary, #64748b)"},children:"ProcessFlowChart requires a non-empty stages array."}));const he=function(e,t,n={},i){if(!1===t||!e)return;const{volume:o,stages:r,groups:s,groupCompletion:a}=e,c=new Map(o.stages.map(e=>[e.id,e])),l=new Map(a.map(e=>[e.id,e]));return({size:e})=>{const t=Number(e[0])||o.width,a=Number(e[1])||o.height,d=r.map(e=>{const t=c.get(e.id),i=n["process-stage-"+e.id];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:i?.queueDepth,processed:i?.processedCount}}),u=s.map(e=>{const t=l.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return $d({width:t,height:a,left:o.left,right:o.right,topY:o.topY,bottomY:o.bottomY,midY:o.midY,stages:d,groups:u},{showCapacityBadges:!0,showGroupSockets:!0,...i})}}(Z,W,te,i),pe=function(e,t,n){if(!1===n||!t||0===e.length)return;const i=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:n})=>{const o=[Number(n[0])||t.volume.width,Number(n[1])||t.volume.height],r=Ss(o),s=Math.max(1,...e.map(e=>e.value)),a=Math.min(48,.18*r.plot.height),c=r.plot.y+6;return(0,Pd.jsx)("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,n)=>{const o=e[n];if(!o)return null;const r=i.get(t.id);if(!r)return null;const l=Math.max(2,o.value/s*a),d=Math.max(8,.35*r.width);return(0,Pd.jsx)("rect",{x:r.x-d/2,y:c,width:d,height:l,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}(Q.projectionRows,Z,F),me=[...Rs(Q.projectionRows,O,"stage"),...ml(Z?.groups??[])],fe=Cc(e.tooltip,a),ye=Rc(e,a,me,{chartMode:L,className:q,title:z,description:_,summary:G,accessibleTable:V,enableHover:Y,margin:H}),ge=[...Z?.regionEffects??[],...a.regionEffects??[]];return jc("ProcessFlowChart",O,(0,Pd.jsx)(bs,{...a,...fe,...ye,ref:X,onBodyHover:de,controllers:ee,regionEffects:ge,selection:le??a.selection,backgroundGraphics:Ac(he,a.backgroundGraphics),foregroundGraphics:Ac(pe,a.foregroundGraphics),initialSpawns:Q.initialSpawns,initialSpawnPacing:f??Q.initialSpawnPacing,onTick:se,paused:M,responsiveHeight:j,responsiveWidth:A,size:O,bodyStyle:ae,config:ce.config}))});Dd.displayName="ProcessFlowChart";var Bd=[.1,.5,.9],Td=1e6,Ed=12;function Nd(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Od(e,t,n,i,o){return"function"==typeof i?i(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;n=n[e]}return n}(e,i??o)}function Fd(e){const t=Number(e.toFixed(Ed));return Object.is(t,-0)?0:t}function Wd(e,t,n,i){const o=e.flatMap((e,o)=>{const r=Nd(Od(e,o,t,n,"time")),s=Nd(Od(e,o,t,i,"value"));return null==r||null==s?[]:[{time:Fd(r),value:s,index:o}]});o.sort((e,t)=>e.time-t.time||e.index-t.index);const r=[];for(const e of o){const t=r[r.length-1];t?.time===e.time?t.value=e.value:r.push({time:e.time,value:e.value})}return r}function qd(e,t,n,i){if(!e.length)return null;const o=e[0],r=e[e.length-1];if(o.time>t)return"clamp"===i?o.value:null;if(t>r.time)return"clamp"===i?r.value:null;const s=function(e,t){let n=0,i=e.length;for(;i>n;){const o=n+i>>>1;t>e[o].time?n=o+1:i=o}return n}(e,t),a=e[s];if(a?.time===t)return a.value;const c=e[Math.max(0,s-1)];return"step"!==n&&a&&a.time!==c.time?c.value+(t-c.time)/(a.time-c.time)*(a.value-c.value):c.value}function zd(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,i=Math.floor(n),o=Math.ceil(n);return i===o?e[i]:e[i]+(e[o]-e[i])*(n-i)}function Ld(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",i=function(e){const t=(e??Bd).map(e=>{const t=Nd(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return Fd(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),o=function(e){if(Array.isArray(e)){if(e.length>Td)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Td} points`);return Array.from(new Set(e.map(Nd).filter(e=>null!=e).map(Fd))).sort((e,t)=>e-t)}const t=e,n=Nd(t.start),i=Nd(t.end),o=Nd(t.step);if(null==n||null==i||null==o||0>=o||n>i)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const r=Math.floor((i-n)/o)+1;if(r>Td)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Td} points`);const s=[],a=1e-10*Math.max(1,Math.abs(i),Math.abs(n));for(let e=0;r>e;e+=1){const t=n+e*o;if(t>i+a)break;s.push(Fd(Math.min(t,i)))}if(s.length&&a>=Math.abs(s[s.length-1]-i)||s.push(Fd(i)),s.length>Td)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Td} points`);return Array.from(new Set(s)).sort((e,t)=>e-t)}(e.sampleAt),r=e.runs.map(t=>Wd(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:o.map(e=>{const o=r.map(i=>qd(i,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),s={};for(const e of i)s[e]=o.length?zd(o,e):null;return{time:e,count:o.length,min:o.length?o[0]:null,max:o.length?o[o.length-1]:null,median:o.length?zd(o,.5):null,quantiles:s}}),quantiles:i,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Hd(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function Yd(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Nd(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const i=Fd(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,i))throw Error(`comparePhysicsTrace could not find quantile ${i} in the reference envelope`);return e.quantiles[i]??null}function _d(e,t,n){return t>e?"below":e>n?"above":"inside"}function Gd(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const i=e.value-e.lower,o=t.value-t.lower,r=e.value-e.upper,s=t.value-t.upper,a=[0,1];for(const[e,t]of[[i,o],[r,s]])(0>e&&t>0||e>0&&0>t)&&a.push(-e/(t-e));a.sort((e,t)=>e-t);let c=0,l=0,d=0;for(let i=0;a.length-1>i;i+=1){const o=a[i],r=a[i+1];if(o>=r)continue;const s=(o+r)/2,u=(r-o)*n,h=_d(e.value+(t.value-e.value)*s,e.lower+(t.lower-e.lower)*s,e.upper+(t.upper-e.upper)*s);"below"===h?c+=u:"above"===h?d+=u:l+=u}return{below:c,inside:l,above:d,observed:n}}function Vd(e,t,n={}){const i=n.interpolation??t.interpolation,o=n.outsideDomain??t.outsideDomain,r=Wd(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),s=n.lower??Hd(t,"lower"),a=n.upper??Hd(t,"upper"),c=t.points.map(e=>{const t=qd(r,e.time,i,o),n=Yd(e,s),c=Yd(e,a);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":_d(t,n,c)}});let l=0,d=0,u=0,h=0,p=null,m=0,f=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?d+=1:"above"===e.status&&(u+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,p=e.time),n>m&&(m=n,f=e.time)}let y=0,g=0,b=0,x=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],o=Math.max(0,n.time-t.time);if(o>0){if("linear"===i){const e=Gd(t,n);y+=e.below,g+=e.inside,b+=e.above,x+=e.observed;continue}"unobserved"!==t.status&&(x+=o,"below"===t.status?y+=o:"above"===t.status?b+=o:g+=o)}}const v=c[0]?.time,w=c[c.length-1]?.time,k=null==v||null==w?0:Math.max(0,w-v);return{points:c,sampleCount:c.length,observedSamples:l+d+u,belowSamples:l,insideSamples:d,aboveSamples:u,totalDuration:k,observedDuration:x,unobservedDuration:Math.max(0,k-x),belowDuration:y,insideDuration:g,aboveDuration:b,peakExcess:h,peakExcessAt:p,peakDeficit:m,peakDeficitAt:f}}function Xd(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function Ud(e){const t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,Xd(e)]))}}function Kd(e,t,n={}){if("region-enter"!==t.type)return e;const i=function(e,t){const n=t.stageId?.(e);if(n)return n;const i=e.region.metadata;if(i&&"object"==typeof i){const e=i.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),o=e.stages.findIndex(e=>e.id===i);if(0>o)return e;const r=n.entityId?.(t)??t.bodyId;if(!r)return e;const s=e.entities[r]??Xd(r),a=s.currentStageId?e.stages.findIndex(e=>e.id===s.currentStageId):-1,c=!s.visitedStageIds.includes(i),l=Number(t.observation.timestamp),d=Number.isFinite(l)?l:0,u={...s,currentStageId:i,furthestStageId:o>s.furthestStageIndex?i:s.furthestStageId,furthestStageIndex:Math.max(s.furthestStageIndex,o),visitedStageIds:c?[...s.visitedStageIds,i]:s.visitedStageIds,visitsByStage:{...s.visitsByStage,[i]:(s.visitsByStage[i]??0)+1},firstEnteredAt:c?{...s.firstEnteredAt,[i]:d}:s.firstEnteredAt,lastEnteredAt:{...s.lastEnteredAt,[i]:d},regressionCount:a>=0&&a>o?s.regressionCount+1:s.regressionCount};return{...e,bodyIds:e.bodyIds.includes(r)?e.bodyIds:[...e.bodyIds,r],entities:{...e.entities,[r]:u}}}function Qd(e){const t=e.bodyIds.map(t=>e.entities[t]??Xd(t)),n=t.length;let i=n;return e.stages.map((e,o)=>{const r=t.filter(e=>e.furthestStageIndex>=o).length,s=t.filter(t=>t.visitedStageIds.includes(e.id)).length,a=t.reduce((t,n)=>t+(n.visitsByStage[e.id]??0),0),c={id:e.id,label:e.label??e.id,reached:r,entered:s,total:n,conversion:n>0?r/n:0,fromPrevious:i>0?r/i:0,dropoff:Math.max(0,i-r),visits:a,repeatVisits:Math.max(0,a-s)};return i=r,c})}var Zd={flow:"down",padding:24,chargeExtent:.12,destinationExtent:.55,projectionExtent:0,channelRatio:1};function Jd(e){const[t,n]=e.size,i=e.flow??Zd.flow,o=function(e){if(null==e){const e=Zd.padding;return{top:e,right:e,bottom:e,left:e}}return"number"==typeof e?{top:e,right:e,bottom:e,left:e}:{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}(e.padding),r=Math.max(.05,Math.min(1,e.channelRatio??Zd.channelRatio)),s={x:o.left,y:o.top,width:Math.max(1,t-o.left-o.right),height:Math.max(1,n-o.top-o.bottom)},a="down"===i?s.height:s.width,c=a*Math.max(0,e.chargeExtent??Zd.chargeExtent),l=a*Math.max(0,e.projectionExtent??Zd.projectionExtent),d=a*Math.max(0,e.destinationExtent??Zd.destinationExtent),u=Math.max(0,a-c-d-l),h=function(e){return"number"==typeof e?Array.from({length:Math.max(1,Math.round(e))},(e,t)=>({id:"bin-"+t,label:t+""})):0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??t+""}))}(e.destinations),p=("down"===i?s.width:s.height)/h.length,m="down"===i?(e,t)=>({x:s.x,y:s.y+e,width:s.width,height:t}):(e,t)=>({x:s.x+e,y:s.y,width:t,height:s.height}),f=m(0,c),y=m(c,u),g=c+u,b=m(g,d),x=m(g+d,l),v=h.map((e,t)=>{const n=t*p,o=p*r,a=(p-o)/2;return"down"===i?{id:e.id,label:e.label,order:t,x:s.x+n+a,y:b.y,width:o,height:b.height,centerX:s.x+(t+.5)*p,centerY:b.y+b.height/2}:{id:e.id,label:e.label,order:t,x:b.x,y:s.y+n+a,width:b.width,height:o,centerX:b.x+b.width/2,centerY:s.y+(t+.5)*p}});return{width:t,height:n,flow:i,charge:f,apparatus:y,destinations:v,projection:x}}function eu(e,t){return e.destinations.find(e=>e.id===t)}function tu(e,t,n){const{charge:i,flow:o}=e,r=Math.max(1,n),s=(t%r+.5)/r;return"down"===o?{x:i.x+i.width*s,y:i.y+i.height/2}:{x:i.x+i.width/2,y:i.y+i.height*s}}function nu(e,t={}){const n=t.thickness??4,i=t.idPrefix??"stage",{destinations:o,flow:r,width:s,height:a}=e,c=[];if(o.length>0){const t=o[0];if("down"===r){const r=t.y+t.height;c.push({id:i+"-floor",shape:{type:"segment",x1:e.charge.x,y1:r,x2:e.charge.x+e.charge.width,y2:r,thickness:n}});for(let e=1;o.length>e;e+=1){const s=o[e].centerX-(o[e].centerX-o[e-1].centerX)/2;c.push({id:`${i}-divider-${e}`,shape:{type:"segment",x1:s,y1:t.y,x2:s,y2:r,thickness:n}})}}else{const r=t.x+t.width;c.push({id:i+"-floor",shape:{type:"segment",x1:r,y1:e.charge.y,x2:r,y2:e.charge.y+e.charge.height,thickness:n}});for(let e=1;o.length>e;e+=1){const s=o[e].centerY-(o[e].centerY-o[e-1].centerY)/2;c.push({id:`${i}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:s,x2:r,y2:s,thickness:n}})}}}return!1!==t.walls&&c.push({id:i+"-wall-left",shape:{type:"segment",x1:1,y1:0,x2:1,y2:a,thickness:n}},{id:i+"-wall-right",shape:{type:"segment",x1:s-1,y1:0,x2:s-1,y2:a,thickness:n}}),c}function iu(e,t={}){return`${t.charge??"bodies"} enter at the ${"down"===e.flow?"top":"left"}, travel ${"down"===e.flow?"downward":"left to right"} through ${t.apparatus??"the apparatus"}, and come to rest in ${e.destinations.length} ${t.destination??"destinations"}: ${e.destinations.map(e=>e.label).join(", ")}.`}function ou(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function ru(e,t,n,i){const o="function"==typeof e?e(t,n):e;return Number.isFinite(o)?Number(o):i}function su(e,t,n){return ou(e[t])??n}function au(e,t){return"number"==typeof e?e:e?.[t]??0}function cu(e){const{band:t,idPrefix:n,plot:i,projection:o}=e,{includeBoundaryWalls:r=!0,includeInteriorWalls:s=!0,wallThickness:a=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const i of e.values){const o=e.scale(i);Number.isFinite(o)&&(n.add(Number(o)),n.add(Number(o)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=r?c.length-1:c.length-2,d=[];for(let e=r?0:1;l>=e;e+=1){if(!s&&e>0&&c.length-1>e)continue;const t=c[e];d.push({id:`${n}-wall-${e}`,shape:"x"===o?{type:"aabb",x:t,y:i.y+i.height/2,width:a,height:i.height}:{type:"aabb",x:i.x+i.width/2,y:t,width:i.width,height:a}})}return d}function lu(e){const{plot:t,idPrefix:n="physics-scale",bounds:i={},xBins:o,xBands:r,yBands:s}=e,a=[];if(!1!==i&&a.push(...fo(t,{idPrefix:n,...i})),o){const{idPrefix:e,yTop:i,yBottom:r,...s}=o;a.push(...yo({...s,idPrefix:e??n+"-xbin",yTop:i??t.y,yBottom:r??t.y+t.height}))}return r&&a.push(...cu({band:r,idPrefix:r.idPrefix??n+"-xband",plot:t,projection:"x"})),s&&a.push(...cu({band:s,idPrefix:s.idPrefix??n+"-yband",plot:t,projection:"y"})),a}function du(e){const{plot:t,rows:n,columns:i=n+1,pegRadius:o=3,idPrefix:r="galton-peg",yStart:s=t.y+.18*t.height,yEnd:a=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:d=.04}=e,u=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(i));if(0===u)return[];const p=u>1?(a-s)/(u-1):0,m=t.width/h,f=[];for(let e=0;u>e;e+=1){const n=c&&e%2==1?m/2:0;for(let i=0;h>i;i+=1){const a=t.x+m*(i+.5)+n;t.x+o>a||a>t.x+t.width-o||f.push({id:`${r}-${e}-${i}`,shape:{type:"aabb",x:a,y:s+e*p,width:2*o,height:2*o},restitution:l,friction:d})}}return f}function uu(e,t={}){const{idPrefix:n="physics-token",radius:i=5,shape:o,mass:r,vx:s,vy:a,spawnAt:c,seed:l=1,jitter:d,datum:u}=t,h=pi(l),p=au(d,"x"),m=au(d,"y");return e.map((e,l)=>{const d=ru(t.x,e,l,su(e,"x",0)),f=ru(t.y,e,l,su(e,"y",0)),y=ru(i,e,l,5),g="function"==typeof o?o(e,l):o??{type:"circle",radius:y};return{id:`${n}-${e.index??l}`,x:d+(h()-.5)*p,y:f+(h()-.5)*m,vx:ru(s,e,l,0),vy:ru(a,e,l,0),mass:ru(r,e,l,1),spawnAt:ru(c,e,l,void 0),shape:g,datum:u?u(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function hu(e,t={}){const{idPrefix:n="sediment",collider:i=!0,colliderThickness:o=1,restitution:r=.05,friction:s=.2,...a}=t,c=Zi(e,a),l=i?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+o/2,width:e.width,height:o},restitution:r,friction:s})):[];return{columns:c,colliders:l}}function pu(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:i=1,startAt:o=0,rebase:r=!0,sort:s=!0}=t,a=e.map((e,t)=>({spawn:e,time:function(e,t,n){return ou("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=a.length?Math.min(...a.map(e=>e.time)):0;return{initialSpawns:a.map(({spawn:e,time:t})=>({...e,spawnAt:o+(r?t-c:t)})).sort((e,t)=>s?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:o,timeAccessor:"spawnAt",timeScale:i}}}var mu=require("react"),fu=1e-9;function yu(e,t){return t>e?-1:e>t?1:0}function gu(e){return{...e}}function bu(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function xu(e){const t=Object.fromEntries(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:gu(t.initialMetrics),metrics:gu(t.metrics),productIds:[...t.productIds],history:bu(t.history)}])),n=Object.fromEntries(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:gu(t.metrics),sourceIds:[...t.sourceIds],history:bu(t.history)}])),i=Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?gu(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:n,relations:i,input:{amount:e.input.amount,metrics:gu(e.input.metrics)},metrics:gu(e.metrics),loss:{amount:e.loss.amount,metrics:gu(e.loss.metrics)},history:bu(e.history)}}function vu(e,t,n,i,o){return{severity:e,code:t,message:n,path:i,ids:o?[...o]:void 0}}function wu(e){const t=new Set,n=new Set;for(const i of e)t.has(i)&&n.add(i),t.add(i);return[...n].sort(yu)}function ku(e,t){return e?Object.entries(e).flatMap(([e,n])=>Number.isFinite(n)?[]:[vu("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function Mu(e,t){for(const[n,i]of Object.entries(t))e[n]=Number(e[n]??0)+i}function Iu(e,t,n="selector"){const i=[],o=Object.values(e.components),r=new Set(o.map(e=>e.id)),s=(t.ids??[]).filter(e=>!r.has(e));if(s.length&&i.push(vu("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,n+".ids",s)),void 0===t.count||Number.isInteger(t.count)&&t.count>=0||i.push(vu("error","invalid-selector-count","Selector count must be a non-negative integer.",n+".count")),i.some(e=>"error"===e.severity))return{ids:[],diagnostics:i};const a=t.ids?new Set(t.ids):null,c=t.categories?new Set(t.categories):null,l=t.statuses?new Set(t.statuses):null,d=t.outletIds?new Set(t.outletIds):null;let u=o.filter(e=>!a||a.has(e.id)).filter(e=>!c||c.has(e.category)).filter(e=>!l||l.has(e.status)).filter(e=>!d||void 0!==e.outletId&&d.has(e.outletId)).map(e=>e.id).sort(yu);return void 0!==t.count&&(u=u.slice(0,t.count)),u.length||i.push(vu("warning","empty-selector","Selector matched no source components.",n)),{ids:u,diagnostics:i}}function Su(e,t,n={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...n}}function ju(e,t){const n={...t,eventId:e.event.id};e.materializations.push(n),e.observations.push({...n,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function Au(e,t,n){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(vu("error","unknown-outlet",`Unknown outlet "${t}".`,n,[t])),1))}function Cu(e,t,n){const i=wu(t);t.length||e.diagnostics.push(vu("error","empty-source-list","A product requires at least one source component.",n)),i.length&&e.diagnostics.push(vu("error","duplicate-source",`Source ids may appear only once: ${i.join(", ")}.`,n,i));const o=t.filter(t=>!e.state.components[t]);o.length&&e.diagnostics.push(vu("error","unknown-component",`Unknown source component id${1===o.length?"":"s"}: ${o.join(", ")}.`,n,o));const r=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);r.length&&e.diagnostics.push(vu("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,n,r));const s=t.filter(t=>"consumed"===e.state.components[t]?.status&&!r.includes(t));return s.length&&e.diagnostics.push(vu("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,n,s)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function Ru(e,t,n,i,o){const r=i?.amount??0;(!Number.isFinite(r)||0>r||r>t+fu)&&e.diagnostics.push(vu("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",o+".amount")),e.diagnostics.push(...ku(i?.metrics,o+".metrics"));for(const[t,r]of Object.entries(i?.metrics??{}))(0>r||r>Number(n[t]??0)+fu)&&e.diagnostics.push(vu("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${o}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function $u(e,t,n,i,o,r,s){return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:r&&void 0!==e.amount?e.amount:n,metrics:r&&e.metrics?{...i,...e.metrics}:i,status:r?"complete":"forming",sourceIds:[...t],outletId:r?e.outletId??(o.outletIds.has("product")?"product":void 0):void 0,createdByEventId:o.event.id,createdAt:o.context.appliedAt,completedByEventId:r?o.event.id:void 0,completedAt:r?o.context.appliedAt:void 0,history:[s]}}function Pu(e,t,n,i){void 0!==t.amount&&Math.abs(t.amount-n)>fu&&e.diagnostics.push(vu("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${n}.`,i,[t.id]))}function Du(e,t,n){const i=`events.${e.event.id}.effects.${n}`,o=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(vu("error","invalid-component-state",`set-state cannot assign "${t.state+""}".`,i+".state")),e.diagnostics.push(...ku(t.metricsDelta,i+".metricsDelta")),Au(e,t.outletId,i+".outletId");const n=Iu(o,t.select,i+".select");e.diagnostics.push(...n.diagnostics);const r=n.ids.filter(e=>o.components[e].productIds.length);if(r.length&&e.diagnostics.push(vu("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,i+".select",r)),e.diagnostics.some(e=>"error"===e.severity))return;const s=Su(e,t,{sourceIds:n.ids,outletIds:t.outletId?[t.outletId]:void 0});for(const e of n.ids){const n=o.components[e];n.status=t.state,n.outletId=t.outletId,n.reason=t.reason,t.metricsDelta&&Mu(n.metrics,t.metricsDelta),n.history.push(s)}return o.history.push(s),void(n.ids.length&&ju(e,{type:"retarget-component",sourceIds:n.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){const{relation:n}=t;n.id&&!o.relations[n.id]||e.diagnostics.push(vu("error","duplicate-relation",`Relation id "${n.id}" is missing or already active.`,i+".relation.id",[n.id]));const r=function(e,t,n){const i=wu(t),o=t.filter(t=>!e.state.components[t]);return 2>t.length&&e.diagnostics.push(vu("error","insufficient-relation-sources","A relation requires at least two source components.",n)),i.length&&e.diagnostics.push(vu("error","duplicate-source",`Relation source ids must be unique: ${i.join(", ")}.`,n,i)),o.length&&e.diagnostics.push(vu("error","unknown-component",`Relation references unknown source component${1===o.length?"":"s"}: ${o.join(", ")}.`,n,o)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,n.sourceIds,i+".relation.sourceIds");if(e.diagnostics.push(...ku(n.metrics,i+".relation.metrics")),!r||e.diagnostics.some(e=>"error"===e.severity))return;o.relations[n.id]={...n,sourceIds:[...n.sourceIds],metrics:n.metrics?{...n.metrics}:void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};const s=Su(e,t,{sourceIds:[...n.sourceIds],relationIds:[n.id]});return o.history.push(s),void ju(e,{type:"activate-relation",sourceIds:[...n.sourceIds],relationIds:[n.id]})}if("resolve-relation"===t.type){const n=wu(t.relationIds),r=t.relationIds.filter(e=>!o.relations[e]),s=t.relationIds.filter(e=>"resolved"===o.relations[e]?.status);if(n.length&&e.diagnostics.push(vu("error","duplicate-relation","Relation ids must be unique.",i+".relationIds",n)),r.length&&e.diagnostics.push(vu("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,i+".relationIds",r)),s.length&&e.diagnostics.push(vu("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,i+".relationIds",s)),e.diagnostics.some(e=>"error"===e.severity))return;for(const n of t.relationIds){const i=o.relations[n];i.status="resolved",i.resolution=t.resolution,i.resolvedByEventId=e.event.id,i.resolvedAt=e.context.appliedAt,i.reason=t.reason}const a=Su(e,t,{relationIds:[...t.relationIds]});return o.history.push(a),void ju(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){const n=e.productDefinitions.get(t.productId);n||e.diagnostics.push(vu("error","unknown-product",`Product "${t.productId}" has no declared mold.`,i+".productId",[t.productId]));const r=o.products[t.productId];"combine"===t.type&&r&&e.diagnostics.push(vu("error","duplicate-product",`Product "${t.productId}" has already been formed.`,i+".productId",[t.productId])),"contribute"!==t.type||r&&"forming"===r.status||e.diagnostics.push(vu("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,i+".productId",[t.productId]));const s=Cu(e,t.sourceIds,i+".sourceIds"),a="contribute"===t.type&&r?[...r.sourceIds,...t.sourceIds]:t.sourceIds,c=function(e,t,n,i){if(!t?.length)return[];const o=wu(t),r=t.filter(t=>!e.state.relations[t]),s=t.filter(t=>"resolved"===e.state.relations[t]?.status),a=new Set(n),c=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!a.has(e)));return o.length&&e.diagnostics.push(vu("error","duplicate-relation","Basis relations must be unique.",i,o)),r.length&&e.diagnostics.push(vu("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,i,r)),s.length&&e.diagnostics.push(vu("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,i,s)),c.length&&e.diagnostics.push(vu("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${c.join(", ")}.`,i,c)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,a,i+".basisRelationIds");if(!s||!c||!n||e.diagnostics.some(e=>"error"===e.severity))return;const l=s.reduce((e,t)=>e+t.amount,0),d=function(e){const t={};for(const n of e)Mu(t,n.metrics);return t}(s);if(!Ru(e,l,d,t.loss,i+".loss"))return;const u=l-(t.loss?.amount??0);!function(e,t,n){e.state.loss.amount+=n?.amount??0;for(const[i,o]of Object.entries(n?.metrics??{}))t[i]=Number(t[i]??0)-o,e.state.loss.metrics[i]=Number(e.state.loss.metrics[i]??0)+o}(e,d,t.loss);const h="combine"===t.type&&!1!==t.complete,p=Su(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});let m;if("combine"===t.type){if(h&&Pu(e,n,u,i+".productId"),m=$u(n,t.sourceIds,u,d,e,h,p),h&&!Au(e,m.outletId,i+".productId"))return;o.products[t.productId]=m}else m=r,m.sourceIds.push(...t.sourceIds),m.amount+=u,Mu(m.metrics,d),m.history.push(p);for(const e of s)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(p);return o.history.push(p),function(e,t){if(t.length){for(const n of t)n.status="resolved",n.resolution="combined",n.resolvedByEventId=e.event.id,n.resolvedAt=e.context.appliedAt;ju(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,c),ju(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:m.outletId?[m.outletId]:void 0}),void(h&&ju(e,{type:"complete-product",sourceIds:[...m.sourceIds],productIds:[m.id],outletIds:m.outletId?[m.outletId]:void 0}))}if("complete-product"===t.type){const n=o.products[t.productId];return n?void function(e,t,n,i,o,r){const s=e.productDefinitions.get(t.id),a=n??s?.outletId??(e.outletIds.has("product")?"product":void 0);if(!Au(e,a,r+".outletId"))return;if("complete"===t.status)return void e.diagnostics.push(vu("error","product-already-complete",`Product "${t.id}" is already complete.`,r,[t.id]));s&&(Pu(e,s,t.amount,r+".productId"),void 0!==s.amount&&(t.amount=s.amount),s.metrics&&(t.metrics={...t.metrics,...s.metrics})),t.status="complete",t.outletId=a,t.reason=i,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;const c=Su(e,o,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0});t.history.push(c),e.state.history.push(c),ju(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0})}(e,n,t.outletId,t.reason,t,i):void e.diagnostics.push(vu("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,i+".productId",[t.productId]))}if("split"===t.type){const n=Cu(e,[t.sourceId],i+".sourceId");t.products.length||e.diagnostics.push(vu("error","empty-split","A split requires at least one product allocation.",i+".products"));const r=t.products.map(e=>e.productId),s=wu(r);s.length&&e.diagnostics.push(vu("error","duplicate-product","Split product ids must be unique.",i+".products",s));const a=r.map(t=>e.productDefinitions.get(t)),c=r.filter((e,t)=>!a[t]),l=r.filter(e=>o.products[e]);c.length&&e.diagnostics.push(vu("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,i+".products",c)),l.length&&e.diagnostics.push(vu("error","duplicate-product",`Split products already exist: ${l.join(", ")}.`,i+".products",l));for(const[n,o]of t.products.entries())void 0===o.amount||Number.isFinite(o.amount)&&o.amount>=0||e.diagnostics.push(vu("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${i}.products.${n}.amount`)),e.diagnostics.push(...ku(o.metrics,`${i}.products.${n}.metrics`));if(!n?.length||e.diagnostics.some(e=>"error"===e.severity))return;const d=n[0];if(!Ru(e,d.amount,d.metrics,t.loss,i+".loss"))return;const u=d.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??a[t]?.amount),p=h.filter(e=>void 0!==e).length;if(0!==p&&p!==h.length)return void e.diagnostics.push(vu("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",i+".products"));const m=p?h:t.products.map(()=>u/t.products.length),f=m.reduce((e,t)=>e+t,0);if(Math.abs(f-u)>fu)return void e.diagnostics.push(vu("error","split-amount-mismatch",`Split allocations total ${f}, but ${u} remains after loss.`,i+".products"));const y={...d.metrics};for(const[e,n]of Object.entries(t.loss?.metrics??{}))y[e]=Number(y[e]??0)-n;const g=Su(e,t,{sourceIds:[d.id],productIds:r});if(t.products.forEach((n,r)=>{const s=a[r],c=u>fu?m[r]/u:1/t.products.length,l=Object.fromEntries(Object.entries(y).map(([e,t])=>[e,t*c])),h=n.metrics??s.metrics??l,p=$u({...s,amount:m[r],metrics:h},[d.id],m[r],{...h},e,!0,g);Au(e,p.outletId,`${i}.products.${r}.productId`)&&(o.products[p.id]=p)}),e.diagnostics.some(e=>"error"===e.severity))return;d.productIds=r,d.status="consumed",d.outletId=void 0,d.history.push(g),o.loss.amount+=t.loss?.amount??0;for(const[e,n]of Object.entries(t.loss?.metrics??{}))o.loss.metrics[e]=Number(o.loss.metrics[e]??0)+n;o.history.push(g),ju(e,{type:"split-source",sourceIds:[d.id],productIds:r});for(const t of r)ju(e,{type:"complete-product",sourceIds:[d.id],productIds:[t],outletIds:o.products[t].outletId?[o.products[t].outletId]:void 0});return}if("eject"===t.type){Au(e,t.outletId,i+".outletId");const n=Iu(o,t.select,i+".select");e.diagnostics.push(...n.diagnostics);const r=n.ids.filter(e=>o.components[e].productIds.length);if(r.length&&e.diagnostics.push(vu("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,i+".select",r)),e.diagnostics.some(e=>"error"===e.severity))return;const s=Su(e,t,{sourceIds:n.ids,outletIds:[t.outletId]});for(const e of n.ids){const n=o.components[e];n.status=t.state??"ejected",n.outletId=t.outletId,n.reason=t.reason,n.history.push(s)}return o.history.push(s),void(n.ids.length&&ju(e,{type:"retarget-component",sourceIds:n.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...ku(t.metricsDelta,i+".metricsDelta")),e.diagnostics.some(e=>"error"===e.severity))return;let n,r;if("run"===t.target)Mu(o.metrics,t.metricsDelta);else if("components"in t.target){const r=Iu(o,t.target.components,i+".target.components");if(e.diagnostics.push(...r.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;n=r.ids;for(const e of r.ids)Mu(o.components[e].metrics,t.metricsDelta)}else{r=[...t.target.productIds];const n=wu(r),s=r.filter(e=>!o.products[e]);if(n.length&&e.diagnostics.push(vu("error","duplicate-product","Metric target product ids must be unique.",i+".target.productIds",n)),s.length&&e.diagnostics.push(vu("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,i+".target.productIds",s)),e.diagnostics.some(e=>"error"===e.severity))return;for(const e of r)Mu(o.products[e].metrics,t.metricsDelta)}return void o.history.push(Su(e,t,{sourceIds:n,productIds:r}))}t.outcome.trim()?(o.outcome=t.outcome,o.summary=t.summary,o.history.push(Su(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(vu("error","invalid-outcome","Outcome must be a non-empty string.",i+".outcome"))}function Bu(e,t,n){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[vu("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,"events."+t.id,[t.id])]};const i=xu(e),o={state:i,event:t,context:n,productDefinitions:new Map(n.products.map(e=>[e.id,e])),outletIds:new Set(n.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(const[n,i]of t.effects.entries())if(Du(o,i,n),o.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:o.diagnostics};return i.elapsed=Math.max(i.elapsed,n.appliedAt),i.phaseId=n.phaseId,i.eventsApplied.push(t.id),o.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:n.phaseId,authoredAt:n.authoredAt,appliedAt:n.appliedAt}),{applied:!0,state:i,materializations:o.materializations,observations:o.observations,diagnostics:o.diagnostics}}function Tu(e,t={}){const n=t.groupBy??"outlet",i=new Map,o=e=>{const t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},n),o=i.get(t);if(o)return o.count+=1,o.amount+=e.amount,void Mu(o.metrics,e.metrics);i.set(t,{key:t,label:"product"===n&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:{...e.metrics},status:"status"===n?e.status:void 0,outletId:"outlet"===n?e.outletId:void 0,category:"category"===n?e.category:void 0,productId:"product"===n&&"product"===e.kind?e.id:void 0})};for(const t of Object.values(e.components))t.productIds.length||"consumed"===t.status||o({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(const t of Object.values(e.products))o({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});const r=new Map((t.order??[]).map((e,t)=>[e,t]));return[...i.values()].sort((e,t)=>(r.get(e.key)??Number.MAX_SAFE_INTEGER)-(r.get(t.key)??Number.MAX_SAFE_INTEGER)||yu(e.key,t.key))}var Eu=Tu;function Nu(e,t={}){const n=t.field??"amount",i=e=>"amount"===n?e.amount:Number(e.metrics[n]??0),o="amount"===n?e.input.amount:Number(e.input.metrics[n]??0),r=Object.values(e.products).reduce((e,t)=>e+i(t),0),s=Object.values(e.components).filter(e=>!e.productIds.length&&"consumed"!==e.status).reduce((e,t)=>e+i(t),0),a="amount"===n?e.loss.amount:Number(e.loss.metrics[n]??0),c=r+s+a,l=c-o;return{field:n,input:o,products:r,unassigned:s,loss:a,output:c,delta:l,conserved:Math.max(0,t.tolerance??1e-6)>=Math.abs(l)}}function Ou(e,t={}){return{history:bu(e.history),projection:Tu(e,t.projection),conservation:Nu(e,t.conservation)}}var Fu=900,Wu=520,qu=[Fu,Wu],zu=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],Lu=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Hu=1e-9;function Yu(e,t){return t>e?-1:e>t?1:0}function _u(e,t,n,i,o){return{severity:e,code:t,message:n,path:i,ids:o?[...o]:void 0}}function Gu(e){const t=new Set,n=new Set;for(const i of e)t.has(i)&&n.add(i),t.add(i);return[...n].sort(Yu)}function Vu(e){const t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Xu(e,t,n,i,o,r){if(!n)return i;try{return("function"==typeof n?n(e,t):e[n])??i}catch(e){return o.push(_u("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:e+""}.`,r)),i}}function Uu(e,t,n){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(_u("error","invalid-metrics","Metrics must be a numeric object.",n)),{};const i={};for(const[o,r]of Object.entries(e)){const e=Vu(r);null!=e?i[o]=e:t.push(_u("error","invalid-metric",`Metric "${o}" must be finite.`,`${n}.${o}`))}return i}function Ku(e){const t=[],n={},i=[];let o=0;const r={};e.data.forEach((s,a)=>{const c=(s.id??"component-"+a)+"",l=((Xu(s,a,e.idAccessor,c,t,`data.${a}.id`)??c)+"").trim();if(!l)return void t.push(_u("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));i.push(l);const d=Vu(Xu(s,a,e.amountAccessor,1,t,`data.${a}.amount`)),u=null==d||0>d?0:d;(null==d||0>d)&&t.push(_u("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=Uu(Xu(s,a,e.metricsAccessor,{},t,`data.${a}.metrics`),t,`data.${a}.metrics`),p=Xu(s,a,e.initialStateAccessor,"active",t,`data.${a}.status`),m=Lu.has(p)?p:"active";Lu.has(p)||t.push(_u("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[l]));const f=Xu(s,a,e.labelAccessor,(s.label??s.name??l)+"",t,`data.${a}.label`)+"",y=Xu(s,a,e.categoryAccessor,"component",t,`data.${a}.category`)+"";n[l]||(n[l]={id:l,label:f,category:y,datum:s,status:m,initialAmount:u,amount:u,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},o+=u,function(e,t){for(const[n,i]of Object.entries(t))e[n]=Number(e[n]??0)+i}(r,h))});const s=Gu(i);s.length&&t.push(_u("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=Uu(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:n,products:{},relations:{},input:{amount:o,metrics:r},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:t}}function Qu(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function Zu(e=qu,t=zu){const n=Math.max(1,Vu(e[0])??Fu),i=Math.max(1,Vu(e[1])??Wu),o=360>n||260>i,r=o?Math.max(4,.035*Math.min(n,i)):20,s=o?Math.max(10,.075*i):34,a={x:r,y:r,width:Math.max(1,n-2*r),height:s},c=o?Math.max(16,.14*i):Math.min(78,.16*i),l={x:r,y:i-r-c,width:Math.max(1,n-2*r),height:c},d=o?Math.max(12,.08*n):Math.min(150,.17*n),u=a.y+a.height+(o?12:38),h=l.y-(o?10:34),p={x:d,y:u,width:Math.max(24,n-2*d),height:Math.max(24,h-u)},m=Math.max(18,Math.min(.32*p.width,o?84:180)),f={x:p.x+(p.width-m)/2,y:p.y-(o?10:24),width:m,height:o?12:28},y=Qu(t),g={left:y.filter(e=>"left"===(e.side??"bottom")),right:y.filter(e=>"right"===e.side),bottom:y.filter(e=>"bottom"===(e.side??"bottom"))},b=[],x=(e,t)=>{const i=Math.max(8,d-1.5*r),s=p.height/Math.max(1,t.length);t.forEach((t,a)=>{b.push({...t,side:e,x:"left"===e?r:n-r-i,y:p.y+a*s,width:i,height:Math.max(8,s-(o?2:8))})})};x("left",g.left),x("right",g.right);const v=p.width/Math.max(1,g.bottom.length);return g.bottom.forEach((e,t)=>{b.push({...e,side:"bottom",x:p.x+t*v,y:p.y+p.height+(o?2:7),width:Math.max(8,v-(o?2:8)),height:Math.max(8,l.y-p.y-p.height-(o?4:12))})}),b.sort((e,t)=>y.findIndex(t=>t.id===e.id)-y.findIndex(e=>e.id===t.id)),{width:n,height:i,phaseRail:a,chamber:p,mouth:f,projection:l,outlets:b}}function Ju(e){const{id:t,orientation:n,fixed:i,start:o,end:r,openings:s,thickness:a,friction:c,restitution:l}=e,d=function(e,t,n){const i=n.map(([n,i])=>[Math.max(e,Math.min(n,i)),Math.min(t,Math.max(n,i))]).filter(([e,t])=>t>e+Hu).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),o=[];let r=e;for(const[e,t]of i)e>r+Hu&&o.push([r,e]),r=Math.max(r,t);return t>r+Hu&&o.push([r,t]),o}(o,r,s);return d.map(([e,o],r)=>({id:1===d.length?t:`${t}:${r}`,friction:c,restitution:l,shape:"horizontal"===n?{type:"segment",x1:e,y1:i,x2:o,y2:i,thickness:a}:{type:"segment",x1:i,y1:e,x2:i,y2:o,thickness:a}}))}function eh(e){const{chamber:t,mouth:n}=e,i=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),o=Math.max(t.x,n.x),r=Math.min(t.x+t.width,n.x+n.width),s={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:o,y2:t.y,thickness:i}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:i}}];a.push(...Ju({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:s.left.map(e=>[e.y,e.y+e.height]),thickness:i,friction:.46,restitution:.12}),...Ju({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:s.right.map(e=>[e.y,e.y+e.height]),thickness:i,friction:.46,restitution:.12}),...Ju({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:s.bottom.map(e=>[e.x,e.x+e.width]),thickness:i,friction:.5,restitution:.08}));for(const t of e.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(t.id),sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return a}function th(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function nh(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?th(e):1}function ih(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:nh(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function oh(e){return"crucible:component:"+encodeURIComponent(e)}function rh(e){return"crucible:product:"+encodeURIComponent(e)}function sh(e,t){return`crucible:bond:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function ah(e,t,n,i){if(void 0!==n&&Number.isFinite(n)&&n>0)return n;const o=Math.min(...t,e),r=Math.max(...t,e);return r-o>Hu?i[0]+(i[1]-i[0])*Math.sqrt(Math.max(0,e-o)/(r-o)):(i[0]+i[1])/2}function ch(e,t){const n=Math.max(.25,Math.min(1,t.width/900,t.height/520)),i=e?.[0]??7*n,o=e?.[1]??18*n,r=Math.max(1,Math.min(i,o));return[r,Math.max(r,Math.max(i,o))]}function lh(e,t,n={}){const i=Object.values(e.components).sort((e,t)=>Yu(e.id,t.id)),o=i.map(e=>e.amount),r=ch(n.radiusRange,t),s=function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(nh(n.seed)),a=t.mouth.x+t.mouth.width/2,c=t.chamber.y+Math.max(18,.18*t.chamber.height),l=Math.max(4,.28*t.chamber.width),d=Math.max(4,.12*t.chamber.height);return i.map((e,t)=>{const u=t/Math.max(1,i.length)*Math.PI*2+.18*(s()-.5),h=ah(e.amount,o,n.bodyRadius,r),p={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:oh(e.id),x:a+Math.cos(u)*l*(.45+.45*s()),y:c+Math.sin(u)*d*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}function dh(e,t){if(!e)return[];const n=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),i=Math.max(1,Math.ceil(e/n));return Array.from({length:e},(e,o)=>({x:t.x+t.width/n*(o%n+.5),y:t.y+(Math.floor(o/n)+.5)*(t.height/i)}))}function uh(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function hh(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function ph(e,t,n={}){const i=Object.values(e.products).sort((e,t)=>Yu(e.id,t.id)),o=Object.values(e.components).sort((e,t)=>Yu(e.id,t.id)),r=[...o.map(e=>e.amount),...i.map(e=>e.amount)],s=ch(n.radiusRange,t),a=function(e,t){const n=new Map;for(const t of e){const e=t.outletId??"__chamber__",i=n.get(e)??[];i.push(t),n.set(e,i)}const i=new Map;for(const[e,o]of n){o.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||Yu(e.id,t.id));const n=dh(o.length,hh(t,"__chamber__"===e?void 0:e));o.forEach((e,t)=>i.set(e.id,n[t]))}return i}(i,t),c=i.map(e=>{const i=a.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},o=1.28*ah(e.amount,r,n.bodyRadius,s),c={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:rh(e.id),x:i.x,y:i.y,mass:Math.max(.25,o*o*.018),bodyCollisions:!1,shape:{type:"circle",radius:o},datum:c}}),l=new Map;for(const e of o.filter(e=>!e.productIds.length)){const t=uh(e)??"__chamber__",n=l.get(t)??[];n.push(e),l.set(t,n)}const d=new Map;for(const[e,n]of l){const i=dh(n.length,hh(t,"__chamber__"===e?void 0:e));n.forEach((e,t)=>d.set(e.id,i[t]))}return[...o.map(e=>{let i=d.get(e.id);if(e.productIds.length){const n=e.productIds.map(e=>a.get(e)).filter(e=>!!e);if(n.length){i={x:n.reduce((e,t)=>e+t.x,0)/n.length,y:n.reduce((e,t)=>e+t.y,0)/n.length};const o=th(e.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*t.width));i={x:i.x+Math.cos(o)*r,y:i.y+Math.sin(o)*r}}}i??(i={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});const o=ah(e.amount,r,n.bodyRadius,s),c={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:oh(e.id),x:i.x,y:i.y,mass:Math.max(.25,o*o*.015),shape:{type:"circle",radius:o},datum:c}}),...c]}var mh=ph;function fh(e){return Array.isArray(e)?e.map(fh):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>Yu(e,t)).map(([e,t])=>[e,fh(t)])):e}function yh(e){return JSON.stringify(fh(e))}function gh(e,t){const n=Vu(t)??0,i=Math.max(0,Math.min(e.duration,n));if(!e.phases.length)return{elapsed:i,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const o=i>=e.duration-Hu,r=o?e.phases[e.phases.length-1]:e.phases.find(e=>i>=e.start&&e.end>i)??e.phases[0];return{elapsed:i,phaseId:r.id,phaseIndex:r.index,phaseElapsed:o?r.duration:Math.max(0,i-r.start),complete:o}}function bh(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,Vu(t)??0));const n=e.phases.find(e=>e.id===t.phaseId);if(!n)return e.duration;const i=Math.max(0,Math.min(1,Vu(t.progress??0)??0));return n.start+n.duration*i}function xh(e,t=e.duration){const n=gh(e,t);let i=xu(e.initialState);const o=[],r=[],s=[];for(const t of e.events){if(t.authoredAt>n.elapsed+Hu)break;const a=Bu(i,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});o.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(i=a.state)}return i.elapsed=n.elapsed,i.phaseId=n.phaseId,i.phaseIndex=n.phaseIndex,i.phaseElapsed=n.phaseElapsed,i.complete=n.complete,n.complete&&"in_process"===i.outcome&&(i.outcome="complete"),i.playing=!1,{state:i,diagnostics:o,materializations:r,observations:s}}function vh(e){const t=function(e){const t=[];e.length||t.push(_u("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const n=Gu(e.map(e=>e.id));n.length&&t.push(_u("error","duplicate-phase-id",`Phase ids must be unique: ${n.join(", ")}.`,"phases",n));let i=0;return{phases:e.map((e,n)=>{const o=Vu(e.duration),r=null!=o&&o>0?o:0;e.id.trim()||t.push(_u("error","invalid-phase-id","Phase ids may not be empty.",`phases.${n}.id`)),null!=o&&o>0||t.push(_u("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${n}.duration`,[e.id])),void 0===e.intensity||Number.isFinite(e.intensity)||t.push(_u("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${n}.intensity`,[e.id]));const s={...e,duration:r,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:n,start:i,end:i+r};return i=s.end,s}),diagnostics:t}}(e.phases),n=t.phases.at(-1)?.end??0,i=Qu(e.outlets??zu),o=(e.products??[]).map(e=>({...e,metrics:e.metrics?{...e.metrics}:void 0})),r=function(e,t,n){const i=[],o=Gu(e.map(e=>e.id));o.length&&i.push(_u("error","duplicate-event-id",`Event ids must be unique: ${o.join(", ")}.`,"events",o));const r=[];return e.forEach((e,o)=>{let s,a,c;if(e.id.trim()||i.push(_u("error","invalid-event-id","Event ids may not be empty.",`events.${o}.id`)),"time"in e.at&&void 0!==e.at.time){const r=Vu(e.at.time);if(null==r||0>r||r>n+Hu)return void i.push(_u("error","event-time-out-of-range",`Event time must fall between 0 and ${n}.`,`events.${o}.at.time`,[e.id]));s=Math.max(0,Math.min(n,r));const l=function(e,t,n){const i=e.find(e=>Hu>=Math.abs(e.start-n));if(i)return{phase:i,boundaryRank:1};const o=e.find(e=>n>=e.start&&e.end>n);return o?{phase:o,boundaryRank:0}:Hu>=Math.abs(n-t)&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,n,s);a=l.phase,c=l.boundaryRank}else{if(a=t.find(t=>t.id===e.at.phaseId),!a)return void i.push(_u("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${o}.at.phaseId`,[e.id,e.at.phaseId]));const n=e.at.progress??0;if(!Number.isFinite(n)||0>n||n>1)return void i.push(_u("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${o}.at.progress`,[e.id]));s=a.start+a.duration*n,c=0===n?1:0}a?r.push({...e,index:o,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:c}):i.push(_u("error","event-without-phase","Event could not be assigned to a phase.",`events.${o}.at`,[e.id]))}),r.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:r,diagnostics:i}}(e.events??[],t.phases,n),s=Ku(e),a=Zu(e.size??qu,i),c=eh(a),l=function(e,t){const n=[],i=new Set(t.map(e=>e.id)),o=Gu(t.map(e=>e.id)),r=Gu(e.map(e=>e.id));return o.length&&n.push(_u("error","duplicate-outlet-id",`Outlet ids must be unique: ${o.join(", ")}.`,"outlets",o)),r.length&&n.push(_u("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),t.forEach((e,t)=>{e.id.trim()||n.push(_u("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0===e.order||Number.isFinite(e.order)||n.push(_u("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||n.push(_u("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0===e.amount||Number.isFinite(e.amount)&&e.amount>=0||n.push(_u("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0===e.outletId||i.has(e.outletId)||n.push(_u("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Uu(e.metrics??{},n,`products.${t}.metrics`)}),n}(o,i),d=yh({seed:e.seed??1,components:Object.values(s.state.components).sort((e,t)=>Yu(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:n,description:i,intensity:o,motion:r,color:s,metrics:a})=>({id:e,duration:t,label:n,description:i,intensity:o,motion:r,color:s,metrics:a})),products:o,outlets:i,events:r.events.map(({id:e,label:t,description:n,summary:i,authoredAt:o,phaseId:r,boundaryRank:s,effects:a})=>({id:e,label:t,description:n,summary:i,authoredAt:o,phaseId:r,boundaryRank:s,effects:a}))}),u=lh(s.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),h=[...t.diagnostics,...r.diagnostics,...s.diagnostics,...l],p={phases:t.phases,events:r.events,products:o,outlets:i,duration:n,initialState:s.state,terminalState:s.state,layout:a,colliders:c,config:ih(e.seed,c),initialSpawns:u,terminalSpawns:[],semanticKey:d,diagnostics:h},m=xh(p),f=Object.values(m.state.products).filter(e=>"forming"===e.status).map(e=>e.id),y=f.length?[_u("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${f.join(", ")}.`,"events",f)]:[];return p.terminalState=m.state,p.terminalSpawns=mh(m.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),p.diagnostics=[...h,...m.diagnostics,...y],p}function wh(e,t){return e.playing=t&&!e.complete,e}function kh(e,t,n=!1){const i=xh(e,t);return{...i,state:wh(i.state,n)}}function Mh(e,t,n,i=t.playing){const o=kh(e,n,i),r=new Set(t.eventsApplied);return{...o,observations:o.observations.filter(e=>!r.has(e.eventId)),materializations:o.materializations.filter(e=>!r.has(e.eventId))}}function Ih(e,t,n={}){return ph(t,e.layout,n)}function Sh(e,t){return function(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}(`${t}:${e}`)/4294967295}function jh(e,t){return e.phases[t.phaseIndex]??e.phases.find(e=>e.id===t.phaseId)}function Ah(e,t,n={}){return new Map(Ih(e,t,n).flatMap(e=>{const t=e.datum;return t?.__crucible?[[`${t.kind}:${t.semanticId}`,{x:e.x,y:e.y}]]:[]}))}function Ch(e,t){const n=Object.values(e.terminalState.products).map(e=>e.id).sort(),i=Math.max(0,n.indexOf(t))/Math.max(1,n.length)*Math.PI*2-Math.PI/2,o=Math.min(58,.19*e.layout.chamber.width),r=Math.min(38,.16*e.layout.chamber.height);return{x:e.layout.chamber.x+e.layout.chamber.width/2+Math.cos(i)*o,y:e.layout.chamber.y+.52*e.layout.chamber.height+Math.sin(i)*r}}function Rh(e,t,n){if("string"!=typeof t)return n;if("function"!=typeof getComputedStyle||!e.canvas)return t||n;const i=t.startsWith("var(")?t.match(/var\((--[^,\s)]+)/)?.[1]:t.startsWith("--")?t:null;return i?getComputedStyle(e.canvas).getPropertyValue(i).trim()||n:t||n}function $h(e){return Number.isFinite(e)?1e3>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):e.toLocaleString():"0"}function Ph(e){const t=e.productIds.length?` Contributes to ${e.productIds.join(", ")}.`:e.outletId?` Routed to ${e.outletId}.`:"",n=e.reason?` ${e.reason}.`:"";return`${$h(e.amount)} amount; ${e.status}.${t}${n}`}function Dh(e){const t=e.outletId?` Routed to ${e.outletId}.`:"";return`${e.status} product with ${e.sourceIds.length} source${1===e.sourceIds.length?"":"s"} and ${$h(e.amount)} amount.${t}`}function Bh(e,t,n){const i=t.datum;if(!i?.__crucible)return;const o="circle"===t.shape.type?t.shape.radius:8,r=Rh(e,n.fill,"product"===i.kind?"#b8792d":"#356b63"),s=Rh(e,n.stroke,"#26323a");if(e.save(),e.translate(t.x,t.y),e.globalAlpha="number"==typeof n.opacity?n.opacity:.96,e.fillStyle=r,e.strokeStyle=s,e.lineWidth="number"==typeof n.strokeWidth?n.strokeWidth:1.25,"product"===i.kind){e.shadowColor=r,e.shadowBlur=10,e.beginPath();for(let t=0;6>t;t+=1){const n=-Math.PI/2+t/6*Math.PI*2,i=Math.cos(n)*o,r=Math.sin(n)*o;0===t?e.moveTo(i,r):e.lineTo(i,r)}e.closePath(),e.fill(),e.shadowBlur=0,e.stroke(),e.beginPath(),e.arc(0,0,Math.max(2,.36*o),0,2*Math.PI),e.strokeStyle=Rh(e,"var(--semiotic-bg, #fffaf0)","#fffaf0"),e.globalAlpha*=.72,e.stroke()}else e.beginPath(),e.arc(0,0,o,0,2*Math.PI),e.fill(),e.stroke(),e.beginPath(),e.arc(.25*-o,.28*-o,Math.max(1,.18*o),0,2*Math.PI),e.fillStyle="rgba(255,255,255,0.34)",e.fill();e.restore()}c(require("react")),require("react/jsx-runtime");var Th=require("react/jsx-runtime"),Eh="var(--semiotic-text, #26323a)",Nh="var(--semiotic-text-secondary, #6c7377)",Oh="var(--semiotic-primary, #b8792d)",Fh="var(--semiotic-danger, #9f3d35)",Wh="var(--semiotic-success, #356b63)";function qh(e){const{x:t,y:n,width:i,height:o}=e.chamber,r=Math.min(.14*i,48),s=n+o;return[`M ${t} ${n}`,`L ${t+r} ${s-.16*o}`,`Q ${t+i/2} ${s+.1*o} ${t+i-r} ${s-.16*o}`,`L ${t+i} ${n}`].join(" ")}function zh({layout:e,phases:t,state:n,compact:i=!1}){const o=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return(0,Th.jsxs)("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[(0,Th.jsxs)("defs",{children:[(0,Th.jsxs)("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[(0,Th.jsx)("stop",{offset:"0",stopColor:Oh,stopOpacity:"0.03"}),(0,Th.jsx)("stop",{offset:"0.66",stopColor:Oh,stopOpacity:"0.1"}),(0,Th.jsx)("stop",{offset:"1",stopColor:Fh,stopOpacity:"0.18"})]}),(0,Th.jsx)("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:(0,Th.jsx)("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Eh,strokeOpacity:"0.08",strokeWidth:"1"})})]}),(0,Th.jsx)("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:Eh,strokeOpacity:"0.52",strokeWidth:i?1:2.2}),(0,Th.jsx)("path",{d:qh(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),(0,Th.jsx)("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:Eh,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:i?2:5}),i?null:(0,Th.jsx)("g",{"data-testid":"crucible-phase-rail",children:t.map((i,r)=>{const s=t.slice(0,r).reduce((e,t)=>e+Math.max(0,t.duration),0),a=e.phaseRail.x+s/o*e.phaseRail.width,c=Math.max(0,i.duration)/o*e.phaseRail.width,l=i.id===n.phaseId,d=n.phaseIndex>r||n.complete;return(0,Th.jsxs)("g",{children:[(0,Th.jsx)("rect",{x:a,y:e.phaseRail.y,width:Math.max(1,c-2),height:e.phaseRail.height,rx:2,fill:l?i.color??Oh:d?Wh:Eh,fillOpacity:l?.68:d?.28:.09}),46>c?null:(0,Th.jsx)("text",{x:a+c/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:l?Eh:Nh,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:l?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(i.label??i.id).toUpperCase()})]},i.id)})}),e.outlets.map(e=>(0,Th.jsxs)("g",{children:[(0,Th.jsx)("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?Fh:Wh),fillOpacity:"0.1",stroke:e.color??("left"===e.side?Fh:Wh),strokeDasharray:"3 3",strokeOpacity:"0.62"}),i?null:(0,Th.jsx)("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:Nh,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function Lh(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}function Hh({rows:e,layout:t,projection:n,amountLabel:i}){if(!e.length)return null;const o=n.measure??"count",r=e.map(e=>Math.max(0,Lh(e,o))),s=Math.max(1,...r),a=t.projection.width/Math.max(1,e.length),c=t.projection.height>48?21:4,l=Math.max(5,t.projection.height-c-5);return(0,Th.jsx)("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,n)=>{const d=r[n],u=Math.max(d>0?2:0,d/s*l),h=t.projection.x+n*a+.18*a;return(0,Th.jsxs)("g",{children:[(0,Th.jsx)("rect",{x:h,y:t.projection.y+l-u,width:Math.max(3,.64*a),height:u,rx:2,fill:"failed"===e.status||"ejected"===e.status?Fh:"complete"===e.status?Oh:Wh,fillOpacity:"0.68"}),c>4&&a>=34?(0,Th.jsxs)(Th.Fragment,{children:[(0,Th.jsx)("text",{x:h+.32*a,y:t.projection.y+l+10,fill:Nh,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?e.label.slice(0,12)+"…":e.label}),(0,Th.jsxs)("text",{x:h+.32*a,y:t.projection.y+l+19,fill:Eh,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[$h(d),"amount"===o&&i?" "+i:""]})]}):null]},e.key)})})}function Yh({controls:e,duration:t,elapsed:n,phaseLabel:i,playing:o,complete:r,playbackRate:s,disabled:a,onPlayPause:c,onReset:l,onStepPhase:d,onPlaybackRateChange:u}){const h=t>0?Math.min(1,Math.max(0,n/t)):1;return(0,Th.jsxs)("div",{"aria-label":"Crucible replay controls",className:"semiotic-crucible-controls",style:{alignItems:"center",color:Eh,display:"flex",flexWrap:"wrap",fontFamily:"system-ui, sans-serif",fontSize:11,gap:6,marginBottom:7},children:[e.playPause?(0,Th.jsx)("button",{type:"button",disabled:a,onClick:c,"aria-pressed":o,children:o?"Pause":r?"Replay":"Play"}):null,e.stepPhase?(0,Th.jsx)("button",{type:"button",disabled:a,onClick:d,children:"Next phase"}):null,e.reset?(0,Th.jsx)("button",{type:"button",disabled:a,onClick:l,children:"Reset"}):null,e.timeline?(0,Th.jsxs)("div",{style:{alignItems:"center",display:"flex",flex:"1 1 150px",gap:7,minWidth:130},children:[(0,Th.jsx)("span",{style:{fontWeight:750,whiteSpace:"nowrap"},children:i}),(0,Th.jsx)("span",{"aria-hidden":"true",style:{background:"rgba(38,50,58,0.14)",borderRadius:2,flex:1,height:4,overflow:"hidden"},children:(0,Th.jsx)("span",{style:{background:Oh,display:"block",height:"100%",transform:`scaleX(${h})`,transformOrigin:"left center"}})}),(0,Th.jsxs)("span",{style:{color:Nh,fontVariantNumeric:"tabular-nums"},children:[n.toFixed(1),"s"]})]}):null,e.speed?(0,Th.jsxs)("label",{style:{alignItems:"center",display:"flex",gap:4},children:["Speed",(0,Th.jsxs)("select",{disabled:a,value:s,onChange:e=>u(Number(e.currentTarget.value)),children:[(0,Th.jsx)("option",{value:.25,children:"¼×"}),(0,Th.jsx)("option",{value:.5,children:"½×"}),(0,Th.jsx)("option",{value:1,children:"1×"}),(0,Th.jsx)("option",{value:2,children:"2×"})]})]}):null]})}function _h(e,t,n,i){const o="function"==typeof i?i(t,n):i,r=t.datum;return{fill:e,stroke:"product"===r?.kind?"var(--semiotic-bg, #fffaf0)":Eh,strokeWidth:"product"===r?.kind?1.8:1.1,opacity:.96,...o}}var Gh=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Vh(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function Xh(e){return"number"==typeof e&&Number.isFinite(e)?e:Vh((e??"crucible")+"")}function Uh(e){const t=Number(e);return Number.isFinite(t)&&t>0?Math.max(.05,Math.min(8,t)):1}function Kh(e,t,n){return"category"===t?e.category:"status"===t?e.status:"outlet"===t?e.outletId??"in chamber":"product"===t?e.productIds[0]??"unalloyed":function(e,t,n){return(("function"==typeof e?e(t,n):t[e])??"unassigned")+""}(t,e.datum,n)}function Qh(e){return Gh[Vh(e)%Gh.length]}function Zh(e,t){const n=Object.keys(e.components).length,i=Object.keys(e.products).length,o=Object.values(e.products).reduce((e,t)=>e+t.amount,0),r=t?" "+t:" amount",s=e.outcome?` Outcome: ${e.outcome}.`:"";return`${n} source component${1===n?"":"s"}; ${i} product${1===i?"":"s"}; ${o.toLocaleString()}${r} in products.${s}`}function Jh(e,t,n){return{id:e.id??t,at:{...e.at},effects:n,...void 0===e.label?null:{label:e.label},...void 0===e.description?null:{description:e.description},...void 0===e.summary?null:{summary:e.summary}}}function ep(e){if(e)return{...e,...e.metrics?{metrics:{...e.metrics}}:null}}function tp(e){const{productId:t,form:n,contributions:i=[],complete:o}=e,r=e.idPrefix??t,s=ep(n.loss),a=[Jh(n,r+"-form",[{type:"combine",sourceIds:[...n.sourceIds],productId:t,...n.basisRelationIds?{basisRelationIds:[...n.basisRelationIds]}:null,...s?{loss:s}:null,complete:!1}])];return i.forEach((e,n)=>{const i=ep(e.loss);a.push(Jh(e,`${r}-contribute-${n+1}`,[{type:"contribute",sourceIds:[...e.sourceIds],productId:t,...e.basisRelationIds?{basisRelationIds:[...e.basisRelationIds]}:null,...i?{loss:i}:null}]))}),a.push(Jh(o,r+"-complete",[{type:"complete-product",productId:t,...void 0===o.outletId?null:{outletId:o.outletId},...void 0===o.reason?null:{reason:o.reason}}])),a}var np=require("react/jsx-runtime"),ip=require("react"),op=(0,mu.forwardRef)(function(e,t){const{amountAccessor:n,amountLabel:i,bodyRadius:o,categoryAccessor:r,colorBy:s="category",conservation:a,controls:c,data:l,emptyContent:d,events:u,frameProps:h={},idAccessor:p,initialStateAccessor:m,initialSpawnPacing:f,labelAccessor:y,loading:g,loadingContent:b,metrics:x,metricsAccessor:v,onClick:w,onConservation:k,onCrucibleObservation:M,onDiagnostic:I,onStateChange:S,outlets:j,paused:A,phases:C,playback:$="replay",playbackRate:D=1,products:B,projection:T,radiusRange:E,rerunMS:N,responsiveHeight:O,responsiveWidth:F,seed:W,showBonds:q=!0,snapshotAt:z}=e,L=(0,mu.useRef)(null),H=(0,mu.useRef)(A);H.current=A;const Y=R(),_=U(),G=Ic(e,qu),{chartMode:V,chartSize:X,showChrome:K,showProjection:Q,className:Z,title:J,description:ee,summary:te,accessibleTable:ne,enableHover:ie,margin:oe}=G,[re,se]=P(X,F,!1),ae=F?Math.max(1,se[0]):X[0],ce=X[1],le=(0,mu.useMemo)(()=>[ae,ce],[ce,ae]),de=(0,mu.useMemo)(()=>Hc(l??[]),[l]),ue=(0,mu.useMemo)(()=>vh({data:de,phases:C,products:B,outlets:j,events:u,idAccessor:p,labelAccessor:y,categoryAccessor:r,amountAccessor:n,metricsAccessor:v,initialStateAccessor:m,metrics:x,size:le,seed:W,bodyRadius:o,radiusRange:E}),[n,o,r,u,p,m,y,x,v,j,C,B,E,le,de,W]),he=Object.values(ue.initialState.components).map((e,t)=>Kh(e,s,t)).join("\0"),pe=`${ue.semanticKey}:${le[0]}x${le[1]}:${(o??"auto")+""}:${E?.join(",")??"auto"}:${he}`,me=(0,mu.useRef)(ue),fe=(0,mu.useRef)(pe);fe.current!==pe&&(fe.current=pe,me.current=ue);const ye=me.current,ge="snapshot"===$||Y||_,be=ge?function(e,t){return bh(e,t)}(ye,z):0,xe=!ge,ve=(0,mu.useMemo)(()=>kh(ye,be,xe&&!A),[fe.current,be,xe]),[we,ke]=(0,mu.useState)(ve),Me=(0,mu.useRef)(we),[Ie,Se]=(0,mu.useState)(xe),je=(0,mu.useRef)(Ie),[Ae,Ce]=(0,mu.useState)(0),[Re,$e]=(0,mu.useState)(()=>Uh(D)),Pe=(0,mu.useRef)(Ah(ye,ve.state,{seed:W,bodyRadius:o,radiusRange:E})),De=(0,mu.useRef)(""),Be=(0,mu.useRef)(S),Te=(0,mu.useRef)(M),Ee=(0,mu.useRef)(I),Ne=(0,mu.useRef)(k);Be.current=S,Te.current=M,Ee.current=I,Ne.current=k;const Oe=(0,mu.useRef)({seed:W,bodyRadius:o,radiusRange:E});Oe.current={seed:W,bodyRadius:o,radiusRange:E};const Fe=(0,mu.useCallback)((e,t=!1)=>{if(Me.current=e,Pe.current=Ah(me.current,e.state,Oe.current),ke(e),t)for(const t of e.observations)Te.current?.(t)},[]);(0,mu.useEffect)(()=>{$e(Uh(D))},[D]),(0,mu.useEffect)(()=>{const e=!ge,t=kh(ye,ge?be:0,e&&!H.current);je.current=e,Se(e),Fe(t)},[Fe,ye,be,ge,pe]),(0,mu.useEffect)(()=>{const e=Me.current,t=je.current&&!A&&!e.state.complete;if(e.state.playing===t)return;const n={...e,state:xu(e.state)};n.state.playing=t,Fe(n)},[Fe,A]),(0,mu.useEffect)(()=>{for(const e of ye.diagnostics)Ee.current?.(e)},[pe,ye.diagnostics]),(0,mu.useEffect)(()=>{if(Be.current?.(we.state),a){const e=!0===a?{}:a;Ne.current?.(Nu(we.state,e))}},[a,we.state]);const We=(0,mu.useCallback)(()=>{De.current="";const e=!ge,t=kh(me.current,0,e&&!A);je.current=e,Se(e),Fe(t)},[Fe,A,ge]),qe=(0,mu.useMemo)(()=>({...ye.config,...h.config,fixedDt:h.config?.fixedDt??ye.config.fixedDt,maxSubsteps:h.config?.maxSubsteps??ye.config.maxSubsteps,settleStepLimit:h.config?.settleStepLimit??ye.config.settleStepLimit,timeScale:Re,colliders:[...ye.config.colliders??[],...h.config?.colliders??[]],kernel:{...ye.config.kernel,...h.config?.kernel,gravity:h.config?.kernel?.gravity??ye.config.kernel?.gravity??{x:0,y:0}},observation:{...ye.config.observation,...h.config?.observation,chartType:"CrucibleChart"}}),[h.config,Re,ye.config]),ze=ge||!!A||!Ie&&!we.state.complete,Le=Mc(qe,N,ze,We),He=(0,mu.useCallback)(()=>{if("number"!=typeof N||!Number.isFinite(N)||0>N)return;const e=`${pe}:${Ae}:${Le.rerunKey}`;De.current!==e&&(De.current=e,Le.config?.observation?.onSimulationStateChange?.("settled","running"))},[Le.config,Le.rerunKey,N,Ae,pe]),Ye=(0,mu.useCallback)(()=>{const e=kh(me.current,0,!1);je.current=!1,Se(!1),Fe(e),Ce(e=>e+1)},[Fe]),_e=(0,mu.useCallback)(()=>{const e=me.current,t=Mh(e,Me.current.state,e.duration,!1);je.current=!1,Se(!1),Fe(t,!0);const n=Ih(e,t.state,Oe.current),i=L.current;i&&(i.clear(),i.pushMany(n),i.step(0),i.settle()),He()},[Fe,He]),Ge=(0,mu.useCallback)(()=>{je.current=!1,Se(!1);const e={...Me.current,state:xu(Me.current.state)};e.state.playing=!1,Fe(e)},[Fe]),Ve=(0,mu.useCallback)(()=>{if(De.current="",ge){const e=kh(me.current,be,!1);return je.current=!1,Se(!1),Fe(e),void Ce(e=>e+1)}const e=kh(me.current,0,!A);je.current=!0,Se(!0),Fe(e),Ce(e=>e+1)},[Fe,A,be,ge]),Xe=(0,mu.useCallback)(()=>{if(ge)return void Ve();if(Me.current.state.complete)return void Ve();je.current=!0,Se(!0);const e={...Me.current,state:xu(Me.current.state)};e.state.playing=!A,Fe(e)},[Fe,A,Ve,ge]),Ue=(0,mu.useCallback)(()=>{const e=me.current,t=function(e,t){const n=e.phases.find(e=>e.end>t+1e-7);return n?.end??e.duration}(e,Me.current.state.elapsed),n=Mh(e,Me.current.state,t,!1);je.current=!1,Se(!1),Fe(n,!0);const i=L.current;i&&(i.clear(),i.pushMany(Ih(e,n.state,Oe.current)),i.step(0))},[Fe]);(0,mu.useImperativeHandle)(t,()=>({play:Xe,pause:Ge,reset:Ye,replay:Ve,stepPhase:Ue,settle:_e,getCrucibleState:()=>xu(Me.current.state)}),[Ge,Xe,Ve,Ye,_e,Ue]);const Ke=(0,mu.useCallback)((e,t)=>{if(h.onTick?.(e,t),ge||A||!je.current)return;const n=Me.current.state,i=Math.min(me.current.duration,e.elapsedSeconds);if(n.elapsed+.045>=i&&me.current.duration>i)return;const o=Mh(me.current,n,i,me.current.duration>i),r=o.state.eventsApplied.length!==n.eventsApplied.length;if(r&&function(e,t){const n=new Set(e.readBodies().map(e=>e.id)),i=t.filter(e=>!n.has(e.id));i.length&&e.pushMany([...i]),i.map(e=>e.id)}(t,Ih(me.current,o.state,Oe.current)),o.state.complete){je.current=!1,Se(!1);const e=Ih(me.current,o.state,Oe.current);t.clear(),t.pushMany(e),t.step(0),t.settle()}Fe(o,r),o.state.complete&&He()},[Fe,h,A,He,ge]),Qe=(0,mu.useCallback)(({body:e})=>function(e){const t=function(e){const{body:t,plan:n,state:i,targets:o}=e,r=t.datum;if(!r?.__crucible)return null;let s=o.get(`${r.kind}:${r.semanticId}`);if(!s)return null;const a=jh(n,i),c=Math.max(0,Math.min(2,Number(a?.intensity??.5))),l=a?.motion??"hold",d=i.elapsed;if("product"===r.kind){const e=i.products[r.semanticId];"forming"===e?.status&&(s=Ch(n,e.id))}else{const e=i.components[r.semanticId],t=e?.productIds.map(e=>i.products[e]).find(e=>"forming"===e?.status);if(t){const i=Ch(n,t.id),o=Sh(e.id,17)*Math.PI*2,r=Math.max(5,Math.min(18,.026*n.layout.width));s={x:i.x+Math.cos(o)*r,y:i.y+Math.sin(o)*r}}}const u=r.semanticId,h=Sh(u,23)*Math.PI*2;if(!i.complete&&!(n.layout.chamber.x>s.x||s.x>n.layout.chamber.x+n.layout.chamber.width||n.layout.chamber.y>s.y||s.y>n.layout.chamber.y+n.layout.chamber.height))if("mix"===l){const e=Math.min(34,.1*n.layout.chamber.width)*c,t=Math.min(24,.09*n.layout.chamber.height)*c;s={x:s.x+Math.cos(d*(1.4+Sh(u,29))+h)*e,y:s.y+Math.sin(d*(1.8+Sh(u,31))+h)*t}}else if("press"===l){const e=n.layout.chamber.x+n.layout.chamber.width/2,t=n.layout.chamber.y+.56*n.layout.chamber.height;s={x:e+(s.x-e)*Math.max(.3,1-.32*c),y:t+(s.y-t)*Math.max(.35,1-.26*c)}}else if("separate"===l){const e=.5>Sh(u,41)?-1:1;s={x:s.x+e*Math.min(28,.075*n.layout.chamber.width)*c,y:s.y}}else if("bind"===l){const e=n.layout.chamber.x+n.layout.chamber.width/2,t=n.layout.chamber.y+.5*n.layout.chamber.height;s={x:e+.72*(s.x-e),y:t+.72*(s.y-t)}}else"charge"===l?s={x:s.x,y:s.y+4*Math.sin(2*d+h)*c}:"quench"===l&&(s={x:s.x+2*Math.sin(h)*c,y:s.y});return s}(e);if(!t)return null;const{body:n,state:i}=e,o=t.x-n.x,r=t.y-n.y,s=Math.hypot(o,r),a=Math.hypot(n.vx,n.vy);if(i.complete&&.7>s&&.45>a)return null;const c=!i.complete&&"pour"===jh(e.plan,i)?.motion,l=i.complete?.68:c?.72:.5,d=i.complete?.22:c?.18:.14,u=i.complete?42:c?72:56;return{x:Math.max(-u,Math.min(u,o*l-n.vx*d)),y:Math.max(-u,Math.min(u,r*l-n.vy*d))}}({body:e,plan:me.current,state:Me.current.state,targets:Pe.current}),[]),Ze=(0,mu.useMemo)(()=>new Map(Object.keys(ye.initialState.components).map((e,t)=>[e,t])),[ye.initialState.components]),Je=(0,mu.useCallback)(t=>{if(e.color)return e.color;const n=t.datum;if(!n?.__crucible)return"var(--semiotic-primary, #b8792d)";if("product"===n.kind){const e=Me.current.state.products[n.semanticId];return e?.color??Qh(e?.id??n.semanticId)}const i=Me.current.state.components[n.semanticId];return i?Qh(Kh(i,s,Ze.get(i.id)??0)):"var(--semiotic-primary, #356b63)"},[s,Ze,e.color]),et=(0,mu.useCallback)((t,n)=>({..._h(Je(t),t,n,h.bodyStyle),...void 0!==e.stroke?{stroke:e.stroke}:null,...void 0!==e.strokeWidth?{strokeWidth:e.strokeWidth}:null,...void 0!==e.opacity?{opacity:e.opacity}:null}),[Je,h.bodyStyle,e.opacity,e.stroke,e.strokeWidth]),tt=(0,mu.useCallback)((e,t)=>("function"==typeof h.bodySemanticItems?h.bodySemanticItems(e,t):void 0)??function(e,t){const n=e.datum;if(!n?.__crucible)return!1;if("component"===n.kind){const e=t.components[n.semanticId];return!!e&&{id:"crucible-component-"+e.id,label:e.label,description:Ph(e),group:"source component · "+e.status,datum:e}}const i=t.products[n.semanticId];return!!i&&{id:"crucible-product-"+i.id,label:i.label,description:Dh(i),group:"derived product · "+i.status,datum:i}}(e,Me.current.state),[h]),nt=(0,mu.useCallback)(e=>{if(!w||!e||"object"!=typeof e)return;if(!e.__crucible)return;const t=Me.current.state,n="component"===e.kind?t.components[e.semanticId]:t.products[e.semanticId];n&&w(n)},[w]),it=(0,mu.useCallback)((e,t)=>{h.beforePaint?.(e,t),q&&function(e,t,n){const i=new Map;for(const e of t){const t=e.datum;t?.__crucible&&i.set(`${t.kind}:${t.semanticId}`,e)}e.save(),e.lineCap="round";for(const t of Object.values(n.relations)){if("active"!==t.status)continue;const n=t.sourceIds.map(e=>i.get("component:"+e)).filter(e=>!!e);2>n.length||(e.strokeStyle="rejected"===t.category?"#9f3d35":"#b8792d",e.globalAlpha=.4,e.lineWidth=Math.max(.8,1.3*Number(t.strength??1)),e.setLineDash([3,4]),e.beginPath(),n.forEach((t,n)=>{0===n?e.moveTo(t.x,t.y):e.lineTo(t.x,t.y)}),e.stroke())}e.setLineDash([]);for(const t of Object.values(n.products)){const n=i.get("product:"+t.id);if(n)for(const o of t.sourceIds){const r=i.get("component:"+o);r&&(e.strokeStyle=t.color??"#b8792d",e.globalAlpha="complete"===t.status?.5:.28,e.lineWidth="complete"===t.status?1.6:1,e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(n.x,n.y),e.stroke())}}e.restore()}(e,t,Me.current.state)},[h,q]),ot=(0,mu.useMemo)(()=>T??{groupBy:"outlet",measure:"count"},[T]),rt=(0,mu.useMemo)(()=>Tu(we.state,ot),[ot,we.state]),st=(0,mu.useMemo)(()=>Q?function(e,t,n,i){if(!e.length)return[];const o=n.measure??"count",r=t.projection.width/Math.max(1,e.length);return e.map((e,n)=>{const s=Lh(e,o),a="amount"===o&&i?`${$h(s)} ${i}`:`${$h(s)} ${o}`;return{id:"crucible-projection-"+e.key,label:`${e.label}: ${a}`,description:`${e.count} source component${1===e.count?"":"s"}; ${$h(e.amount)} amount.`,datum:e,group:"settled composition",x:t.projection.x+(n+.5)*r,y:t.projection.y+t.projection.height/2,shape:"rect",width:Math.max(12,.62*r),height:Math.max(8,t.projection.height-8)}})}(rt,ye.layout,ot,i):[],[i,ye.layout,ot,rt,Q]),at=Cc(e.tooltip,h),{selection:ct,onBodyHover:lt}=wc({selection:e.selection,linkedHover:e.linkedHover,colorBy:s,chartType:"CrucibleChart",chartId:e.chartId,onObservation:e.onObservation,onClick:e.onClick,onBodyHover:h?.onBodyHover}),dt=Rc({...e,onClick:void 0},h,st,{selection:ct,chartMode:V,className:Z,title:J??"Crucible",description:ee??"A bounded inventory is transformed by an authored phase and event tape; physics explains the motion but does not determine the outcome.",summary:te??Zh(we.state,i),accessibleTable:ne,enableHover:ie,margin:oe}),ut=Ac(K?(0,np.jsx)(zh,{layout:ye.layout,phases:ye.phases,state:we.state,compact:G.compactMode||360>le[0]||260>le[1]}):void 0,h.backgroundGraphics),ht=Ac(Q?(0,np.jsx)(Hh,{rows:rt,layout:ye.layout,projection:ot,amountLabel:i}):void 0,h.foregroundGraphics),pt=(0,mu.useCallback)(e=>function(e,t){const n=e.data;if(!n?.__crucible)return null;const i="component"===n.kind?t.components[n.semanticId]:t.products[n.semanticId];if(!i)return null;const o="product"===n.kind;return(0,Th.jsxs)("div",{className:"semiotic-tooltip semiotic-crucible-tooltip",style:{background:"var(--semiotic-tooltip-bg, rgba(38, 50, 58, 0.96))",border:"1px solid rgba(255,255,255,0.2)",borderRadius:3,boxShadow:"0 8px 24px rgba(0,0,0,0.28)",color:"var(--semiotic-tooltip-text, #fffaf0)",maxWidth:290,padding:"9px 12px"},children:[(0,Th.jsx)("strong",{children:i.label}),(0,Th.jsx)("div",{style:{opacity:.78,fontSize:11,letterSpacing:"0.06em",textTransform:"uppercase"},children:o?"Product · "+i.status:"Source · "+i.status}),(0,Th.jsx)("div",{style:{marginTop:4},children:o?Dh(i):Ph(i)})]})}(e,Me.current.state),[]),mt=ge?Ih(ye,we.state,Oe.current):ye.initialSpawns,ft=function(e){return e?!0===e?{playPause:!0,reset:!0,stepPhase:!0,timeline:!0,speed:!0}:{playPause:e.playPause??!0,reset:e.reset??!0,stepPhase:e.stepPhase??!0,timeline:e.timeline??!0,speed:e.speed??!1}:{playPause:!1,reset:!1,stepPhase:!1,timeline:!1,speed:!1}}(c),yt=Object.values(ft).some(Boolean),gt=ye.phases[we.state.phaseIndex],bt=Sc({data:l,emptyContent:d,loading:g,loadingContent:b,size:le});if(bt)return bt;const xt=ye.diagnostics.filter(e=>"error"===e.severity);return xt.length?(0,np.jsxs)("div",{className:Z,role:"alert",style:{maxWidth:"100%",width:le[0]},children:[(0,np.jsx)("strong",{children:"CrucibleChart could not compile this treatment tape."}),(0,np.jsx)("ul",{children:xt.map((e,t)=>(0,np.jsx)("li",{children:e.message},`${e.code}-${t}`))})]}):jc("CrucibleChart",le,(0,np.jsxs)("div",{ref:re,className:"semiotic-crucible-chart",style:{maxWidth:"100%",overflow:"hidden",position:"relative",width:F?"100%":le[0]},children:[yt?(0,np.jsx)(Yh,{controls:ft,duration:ye.duration,elapsed:we.state.elapsed,phaseLabel:gt?.label??gt?.id??"Complete",playing:Ie&&!A,complete:we.state.complete,playbackRate:Re,disabled:ge,onPlayPause:Ie?Ge:Xe,onReset:Ye,onStepPhase:Ue,onPlaybackRateChange:$e}):null,(0,ip.createElement)(bs,{...h,...at,...dt,key:`${pe}:${Ae}:${Le.rerunKey}:${ge?be:"replay"}`,ref:L,onBodyHover:lt,accessibleTable:e.accessibleTable??h.accessibleTable,backgroundGraphics:ut,bodyForces:Qe,bodySemanticItems:tt,bodyStyle:et,beforePaint:it,config:Le.config,continuous:!ge&&Ie&&!A&&!we.state.complete,enableHover:at.enableHover??ie,foregroundGraphics:ht,hoverRadius:e.hoverRadius??h.hoverRadius??18,initialSpawns:mt,initialSpawnPacing:f,onClick:w?nt:dt.onClick,onTick:Ke,paused:ze,renderBody:h.renderBody??Bh,responsiveHeight:O,responsiveWidth:!1,seed:Xh(W),size:le,tooltipContent:at.tooltipContent??pt})]}))});op.displayName="CrucibleChart";var rp=require("react");function sp(e,t,n={}){const i=new Set,o=[...e.get(t)??[]];let r=0;for(;o.length>r;){const t=o[r];if(r+=1,!i.has(t)){i.add(t);for(const n of e.get(t)??[])o.push(n)}}return n.includeStart&&i.add(t),i}function ap(e,t,n){return nl(n,e,t)}function cp(e,t){return t>e?-1:e>t?1:0}function lp(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function dp(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function up(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function hp(e){const t=[],n=new Map,i=[],o=new Set;e.data.forEach((r,s)=>{const a=(ap(r,s,e.taskIDAccessor)??"")+"";if(!a)return void t.push({code:"duplicate-task-id",message:`Task row ${s} has an empty id.`,taskIDs:[]});if(n.has(a))return void t.push({code:"duplicate-task-id",message:`Task id "${a}" occurs more than once.`,taskIDs:[a]});const c=(ap(r,s,e.laneAccessor)??"Unassigned")+"";o.has(c)||(o.add(c),i.push(c));const l=ap(r,s,e.dependencyAccessor)??[],d=Array.from(new Set(Array.from(l,e=>e+""))).sort(cp),u=ap(r,s,e.blockerAccessor),h=ap(r,s,e.statusAccessor)??(u?"blocked":"waiting");n.set(a,{id:a,label:(ap(r,s,e.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:s,datum:r,dependencyIDs:d,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:ap(r,s,e.startAccessor),end:ap(r,s,e.endAccessor),progress:up(ap(r,s,e.progressAccessor)),status:h,completionTime:ap(r,s,e.completionTimeAccessor),blockerReason:u||void 0,milestone:!!ap(r,s,e.milestoneAccessor)})});const r=e.laneOrder?[...e.laneOrder,...i.filter(t=>!e.laneOrder?.includes(t))]:i,s=new Map(r.map((e,t)=>[e,t]));for(const e of n.values())e.laneIndex=s.get(e.lane)??0;const a=new Map,c=new Map;for(const e of n.keys())a.set(e,[]),c.set(e,[]);const l=[],d=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of d)e.dependencyIDs.forEach((i,o)=>{const r=n.get(i);if(!r)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${i}".`,taskIDs:[e.id,i]});const s={id:lp(i,e.id),sourceID:i,targetID:e.id,sourceIndex:r.index,targetIndex:e.index,socketID:dp(e.id,o),socketIndex:o};l.push(s),a.get(e.id)?.push(s),c.get(i)?.push(s),e.incomingEdgeIDs.push(s.id),e.socketIDs.push(s.socketID),r.outgoingEdgeIDs.push(s.id)});for(const e of a.values())e.sort((e,t)=>cp(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=dp(e.targetID,t)});for(const e of c.values())e.sort((e,t)=>cp(e.targetID,t.targetID));for(const e of n.values()){const t=a.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(c.get(e.id)??[]).map(e=>e.id)}const u=new Map,h=new Map;for(const e of n.keys())u.set(e,a.get(e)?.length??0),h.set(e,0);const p=[...n.keys()].filter(e=>0===u.get(e)).sort(cp);let m=0;for(;p.length;){const e=p.shift();m+=1;for(const t of c.get(e)??[]){const n=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,n);const i=(u.get(t.targetID)??0)-1;if(u.set(t.targetID,i),0===i){const e=p.findIndex(e=>e>t.targetID);0>e?p.push(t.targetID):p.splice(e,0,t.targetID)}}}if(m!==n.size){const e=[...n.keys()].filter(e=>(u.get(e)??0)>0).sort(cp);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let f=0;const y=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of y)e.level=h.get(e.id)??0,f=Math.max(f,e.level);return{nodes:y,edges:l,byID:n,incoming:a,outgoing:c,lanes:r,maxLevel:f,diagnostics:t,valid:0===t.length}}function pp(e,t,n={}){const i=Math.max(240,t.width),o=Math.max(220,t.height),r=t.paddingX??48,s=t.paddingTop??48,a=t.paddingBottom??44,c=Math.max(70,(i-2*r)/Math.max(1,e.lanes.length)),l=Math.max(76,(o-s-a)/Math.max(1,e.maxLevel+1)),d=Math.min(n.taskWidth??112,Math.max(58,.78*c)),u=Math.min(n.taskHeight??58,.64*l),h=n.socketRadius??5,p=Math.max(1,Math.round(n.gutterCount??3)),m=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=m.get(e)??[];n.push(t),m.set(e,n)}for(const e of m.values())e.sort((e,t)=>cp(e.id,t.id));const f=.86*l,y=e.nodes.map(e=>{const t=m.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,i=(o=t.length)>1?Math.max(22,Math.min(u,(f-4*(o-1))/o)):u;var o;return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:r+c*(e.laneIndex+.5),y:s+l*(e.level+.5)+n*(i+4),width:d,height:i}}),g=new Map(y.map(e=>[e.taskID,e])),b=[],x=[];e.edges.forEach((t,n)=>{const i=g.get(t.sourceID),o=g.get(t.targetID);if(!i||!o)return;const r=e.incoming.get(t.targetID)??[],s=Math.min(.72*o.width,14*Math.max(1,r.length-1)),a=r.length>1?o.x-s/2+s*t.socketIndex/(r.length-1):o.x,c=o.y-o.height/2-h-2;b.push({id:t.socketID,edgeID:t.id,taskID:o.taskID,index:t.socketIndex,x:a,y:c,radius:h});const l={x:i.x,y:i.y+i.height/2+3},d=Math.min(c-10,l.y+.48*Math.max(18,c-l.y)+7*(n%p-(p-1)/2));var u;x.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(u=[l,{x:l.x,y:d},{x:a,y:d},{x:a,y:c}],u.filter((e,t)=>{const n=u[t-1];return!n||n.x!==e.x||n.y!==e.y}))})});const v=new Map(b.map(e=>[e.id,e])),w=new Map(x.map(e=>[e.edgeID,e]));return{tasks:y,sockets:b,routes:x,taskByID:g,socketByID:v,routeByEdgeID:w}}function mp(e,t,n="all"){const i=Array.from(new Set(t)).sort(cp),o=new Set,r=()=>i.every(e=>o.has(e));return{taskID:e,mode:n,incomingEdgeIDs:i,deliver:e=>i.includes(e)?(o.add(e),r()):r(),reset:(e=[])=>{o.clear();for(const t of e)i.includes(t)&&o.add(t)},isSatisfied:r,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...i],deliveredEdgeIDs:[...o].sort(cp),satisfied:r()})}}function fp(e){return e instanceof Date?e.getTime():Number(e)}function yp(e,t){const n=fp("object"!=typeof t||t instanceof Date?t:t.currentTime),i=e.map((e,t)=>({event:e,index:t,time:fp(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),o=new Set,r=new Map,s=new Set,a=new Set;for(const{event:e}of i)"task-completed"===e.type?(o.add(e.taskID),r.delete(e.taskID)):"task-blocked"===e.type?r.set(e.taskID,e.reason):"task-unblocked"===e.type?r.delete(e.taskID):"dependency-delivered"===e.type?s.add(e.edgeID):"task-armed"===e.type&&a.add(e.taskID);return{currentTime:n,appliedEvents:i.map(e=>e.event),completedTaskIDs:o,blockedByTaskID:r,deliveredEdgeIDs:s,armedTaskIDs:a}}function gp(e,t,n={}){const i=new Set(n.completedTaskIDs??[]),o=[...sp(function(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target);return n}(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(n.isComplete?n.isComplete(e):i.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),r=Array.from(new Set(o.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:o.length,affectedLaneCount:r.length,downstreamTaskIDs:o.map(e=>e.id),affectedLanes:r}}var bp=[];function xp(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function vp(e){if(null==e.completionTime)return null;const t=xp(e.completionTime,NaN);return Number.isFinite(t)?t:null}function wp(e,t,n,i){const o=new Set;for(const r of e.nodes){const s=e.incoming.get(r.id)??[];(i.has(r.id)||!n.has(r.id)&&s.every(e=>t.has(e.id)))&&o.add(r.id)}return o}function kp(e,t,n,i){const o=e.nodes.map(vp).filter(e=>null!=e),r=o.length?Math.min(...o)-1:0,s="replay"!==t||i?n:r,a=new Set,c=new Map;for(const n of e.nodes){const e=vp(n);(null!=e&&s>=e||"done"===n.status&&"replay"!==t)&&a.add(n.id),n.blockerReason&&!a.has(n.id)&&c.set(n.id,n.blockerReason)}const l=new Set;if("replay"!==t||i)for(const t of e.edges)a.has(t.sourceID)&&l.add(t.id);return{currentTime:s,playing:!1,completed:a,delivered:l,inFlight:new Set,armed:wp(e,l,c,a),blockers:c,previewTaskID:null}}function Mp(e){return{...e,completed:new Set(e.completed),delivered:new Set(e.delivered),inFlight:new Set(e.inFlight),armed:new Set(e.armed),blockers:new Map(e.blockers)}}function Ip(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function Sp(e){const t=Ip(e.body);if(!t||2>t.route.length)return null;const n=function(e){let t=0;for(let n=1;e.length>n;n+=1)t+=Math.hypot(e[n].x-e[n-1].x,e[n].y-e[n-1].y);return t}(t.route),i=function(e,t){let n=1/0,i=0,o=0;for(let r=1;t.length>r;r+=1){const s=t[r-1],a=t[r],c=a.x-s.x,l=a.y-s.y,d=c*c+l*l,u=Math.sqrt(d);if(0>=u)continue;const h=Math.max(0,Math.min(1,((e.x-s.x)*c+(e.y-s.y)*l)/d)),p=Math.hypot(e.x-(s.x+c*h),e.y-(s.y+l*h));n>p&&(n=p,i=o+h*u),o+=u}return i}(e.body,t.route),o=function(e,t){if(2>e.length)return{point:e[0]??{x:0,y:0},tangent:{x:0,y:1}};let n=0;for(let i=1;e.length>i;i+=1){const o=e[i-1],r=e[i],s=r.x-o.x,a=r.y-o.y,c=Math.hypot(s,a);if(c>0){if(n+c>=t){const e=Math.max(0,Math.min(1,(t-n)/c));return{point:{x:o.x+s*e,y:o.y+a*e},tangent:{x:s/c,y:a/c}}}n+=c}}const i=e[e.length-2],o=e[e.length-1],r=o.x-i.x,s=o.y-i.y,a=Math.hypot(r,s)||1;return{point:o,tangent:{x:r/a,y:s/a}}}(t.route,Math.min(n,i+22));return{x:2.5*(78*o.tangent.x-e.body.vx)+8*(o.point.x-e.body.x),y:2.5*(78*o.tangent.y-e.body.vy)+8*(o.point.y-e.body.y)}}function jp(e,t){const n=t.points[0]??{x:0,y:0},i=t.points[1]??n,o=i.x-n.x,r=i.y-n.y,s=Math.hypot(o,r)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:o/s*42,vy:r/s*42,mass:.7,restitution:.02,friction:.12,bodyCollisions:!1,shape:{type:"circle",radius:5},datum:{kind:"dependency-ball",edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,route:t.points}}}var Ap=require("react/jsx-runtime");function Cp({machine:e,layout:t,runtime:n,downstreamSet:i,selectedSet:o,width:r,height:s,seed:a,reduced:c,onSelectTask:l}){const d=t.tasks.length?Math.min(...t.tasks.map(e=>e.y-e.height/2)):60,u=Math.max(20,d-12),h=Math.max(26,d-6);return(0,Ap.jsxs)("svg",{"aria-hidden":"true",width:r,height:s,viewBox:`0 0 ${r} ${s}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[(0,Ap.jsx)("defs",{children:(0,Ap.jsx)("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:(0,Ap.jsx)("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,n)=>{const i=t.tasks.filter(e=>e.laneIndex===n),o=i[0]?.x??0;return(0,Ap.jsxs)("g",{children:[(0,Ap.jsx)("line",{x1:o,x2:o,y1:h,y2:s-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),(0,Ap.jsx)("text",{x:o,y:u,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{const t=n.delivered.has(e.edgeID),o=n.inFlight.has(e.edgeID),r=i.has(e.targetID)||i.has(e.sourceID),s=e.points.map(e=>`${e.x},${e.y}`).join(" ");return(0,Ap.jsx)("polyline",{points:s,fill:"none",stroke:r?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:r?4:o?3:2,strokeOpacity:t||o||r?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return(0,Ap.jsxs)("g",{children:[(0,Ap.jsx)("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&(0,Ap.jsx)("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const r=t.taskByID.get(e.id);if(!r)return null;const s=n.completed.has(e.id),d=n.blockers.has(e.id),u=n.previewTaskID===e.id,h=o.has(e.id)||u,p=i.has(e.id),m=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(e,n),f=r.x-r.width/2,y=r.y-r.height/2,g=Math.max(2,r.height*e.progress);return(0,Ap.jsxs)("g",{children:[(0,Ap.jsxs)("g",{style:{transform:`rotate(${s?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:c?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[(0,Ap.jsx)("rect",{x:f,y:y,width:r.width,height:r.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:h||p?"var(--semiotic-selection-color, #e08a1e)":m,strokeWidth:h?4:p?3:2}),(0,Ap.jsx)("rect",{x:f+3,y:y+r.height-g+1,width:r.width-6,height:Math.max(0,g-4),rx:2,fill:m,opacity:s?.86:.46})]}),d&&(0,Ap.jsxs)("g",{opacity:u?.28:1,children:[(0,Ap.jsx)("line",{x1:f-8,x2:f+14,y1:r.y+9,y2:r.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),(0,Ap.jsx)("circle",{cx:f-8,cy:r.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),(0,Ap.jsxs)("g",{onPointerDown:()=>l(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[(0,Ap.jsx)("rect",{x:f,y:y,width:r.width,height:r.height,fill:"transparent"}),(0,Ap.jsx)("text",{x:r.x,y:r.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),(0,Ap.jsxs)("text",{x:r.x,y:r.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% · ",s?"done":d?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}var Rp=require("react/jsx-runtime"),$p={border:0,clip:"rect(0 0 0 0)",clipPath:"inset(50%)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},Pp=(0,rp.forwardRef)(function(e,t){const{data:n,taskIDAccessor:i,labelAccessor:o,laneAccessor:r,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p,mode:m="snapshot",insight:f="blocker-amplification",currentTime:y,controls:g=!1,selectedTaskIDs:b,onSelectionChange:x,onObservation:v,reducedMotion:w,seed:k=31,width:M=920,height:I=620,responsiveWidth:S,responsiveHeight:j,title:A="Dependency chain reaction",description:C,className:R,accessibleTable:$=!0,enableHover:P=!0}=e,D=(0,rp.useRef)(null),[B,T]=(0,rp.useState)([]),E=b?Array.from(b):B,N=(0,rp.useMemo)(()=>new Set(E),[E]),O=xp(y,1/0),F="settle"===w,W=(0,rp.useMemo)(()=>hp({data:n,taskIDAccessor:i,labelAccessor:o,laneAccessor:r,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p}),[n,i,o,r,s,a,c,l,d,u,h,p]),q=(0,rp.useMemo)(()=>pp(W,{width:M,height:I}),[W,M,I]),[z,L]=(0,rp.useState)(()=>kp(W,m,O,F)),H=(0,rp.useRef)(z),Y=(0,rp.useCallback)(e=>{H.current=e,L(e)},[]),_=(0,rp.useCallback)(e=>v?.(e),[v]);(0,rp.useEffect)(()=>{const e=kp(W,m,O,F);D.current?.clear(),H.current=e,L(e)},[W,m,O,F]);const G=(0,rp.useCallback)(e=>{const t=N.has(e)?E.filter(t=>t!==e):[e];b||T(t),x?.(t)},[b,x,N,E]),V=(0,rp.useCallback)(e=>{if(F)return;const t=Mp(H.current),n=[];for(const i of W.outgoing.get(e)??[]){if(t.delivered.has(i.id)||t.inFlight.has(i.id))continue;const e=q.routeByEdgeID.get(i.id);e&&(t.inFlight.add(i.id),n.push(jp(i,e)))}n.length&&(Y(t),D.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[Y,q,W,F]),X=(0,rp.useCallback)((e,t)=>{const n=W.byID.get(e),i=H.current;if(!n||i.completed.has(e))return;const o=Mp(i);o.completed.add(e),o.blockers.delete(e),o.armed.add(e),null!=t&&(o.currentTime=t),Y(o),_({type:"task-completed",taskID:e,datum:n.datum}),V(e)},[Y,_,W,V]),U=(0,rp.useCallback)(e=>{const t=Mp(H.current),n=[],i=[];for(const i of e){if(t.delivered.has(i))continue;const e=W.edges.find(e=>e.id===i);e&&(t.delivered.add(i),t.inFlight.delete(i),n.push(e))}for(const e of n){const n=W.byID.get(e.targetID);!n||t.blockers.has(n.id)||t.armed.has(n.id)||(W.incoming.get(n.id)??[]).every(e=>t.delivered.has(e.id))&&(t.armed.add(n.id),i.push(n.id))}if(n.length){Y(t);for(const e of n)_({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of i)_({type:"task-armed",taskID:e})}},[Y,_,W]),K=(0,rp.useCallback)((e,t)=>{const n=[],i=[];for(const e of t.readBodies()){const t=Ip(e);if(!t||H.current.delivered.has(t.edgeID))continue;const o=t.route[t.route.length-1];o&&9>=Math.hypot(e.x-o.x,e.y-o.y)&&(n.push(t.edgeID),i.push(e.id))}i.length&&t.remove(i),n.length&&U(n)},[U]),Q=(0,rp.useCallback)(()=>{const e=Mp(H.current);for(const t of W.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=wp(W,e.delivered,e.blockers,e.completed),e.playing=!1,D.current?.settle(),Y(e),_({type:"machine-settled"})},[Y,_,W]),Z=(0,rp.useCallback)(()=>{const e=Mp(H.current);e.playing=!1,Y(e)},[Y]),J=(0,rp.useCallback)(()=>{const e=H.current,t=W.nodes.map(e=>({node:e,time:vp(e)})).filter(t=>null!=t.time&&t.time>e.currentTime&&!e.completed.has(t.node.id)).sort((e,t)=>e.time-t.time||e.node.index-t.node.index)[0];if(t)return void X(t.node.id,t.time);Z();const n=[...e.blockers.keys()].map(t=>gp(W,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&_({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[_,W,Z,X]),ee=(0,rp.useCallback)(()=>{if(F)return void Q();const e=Mp(H.current);e.playing=!0,Y(e)},[Y,F,Q]);(0,rp.useEffect)(()=>{if(!z.playing||"replay"!==m||F)return;const e=window.setInterval(J,760);return()=>window.clearInterval(e)},[m,F,z.playing,J]);const te=(0,rp.useCallback)(()=>{D.current?.clear(),Y(kp(W,m,O,F))},[Y,W,m,O,F]),ne=(0,rp.useCallback)(e=>{if(!W.byID.has(e))return;const t=Mp(H.current);t.previewTaskID=e,Y(t);const n=gp(W,e,{completedTaskIDs:t.completed});_({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[Y,_,W]),ie=(0,rp.useCallback)(()=>{const e=Mp(H.current);e.previewTaskID=null,Y(e)},[Y]),oe=(0,rp.useCallback)((e,t)=>{if(!W.byID.has(e))return;const n=Mp(H.current);n.blockers.set(e,t),n.armed.delete(e),Y(n)},[Y,W]),re=(0,rp.useCallback)(e=>{if(!W.byID.has(e))return;const t=Mp(H.current);t.blockers.delete(e),(W.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),Y(t)},[Y,W]),se=(0,rp.useCallback)(e=>gp(W,e,{completedTaskIDs:H.current.completed}),[W]),ae=(0,rp.useCallback)(()=>{const e=H.current;return{currentTime:e.currentTime,playing:e.playing,previewTaskID:e.previewTaskID,selectedTaskIDs:[...E],tasks:W.nodes.map(t=>({taskID:t.id,completed:e.completed.has(t.id),armed:e.armed.has(t.id),blocked:e.blockers.has(t.id),blockerReason:e.blockers.get(t.id)})),dependencies:W.edges.map(t=>({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,state:e.delivered.has(t.id)?"delivered":e.inFlight.has(t.id)?"in-flight":"waiting"}))}},[W,E]);(0,rp.useImperativeHandle)(t,()=>({play:ee,pause:Z,step:J,reset:te,settle:Q,previewResolve:ne,clearPreview:ie,completeTask:X,blockTask:oe,unblockTask:re,getAmplification:se,getMachineState:ae}),[oe,ie,se,ae,Z,X,ee,ne,te,Q,J,re]);const ce=z.previewTaskID??E[0]??null,le=ce?gp(W,ce,{completedTaskIDs:z.completed}):null,de=(0,rp.useMemo)(()=>new Set(le?.downstreamTaskIDs??[]),[le?.downstreamTaskIDs]),ue=(0,rp.useMemo)(()=>function(e,t,n){return e.nodes.flatMap(i=>{const o=t.taskByID.get(i.id);if(!o)return[];const r=e.incoming.get(i.id)??[],s=r.filter(e=>n.delivered.has(e.id)).length,a=n.blockers.get(i.id),c=n.completed.has(i.id)?"completed":a?"blocked: "+a:n.armed.has(i.id)?"armed":"waiting";return[{id:i.id,label:`${i.label}, ${i.lane}, ${Math.round(100*i.progress)}%, ${c}`,description:`${s} of ${r.length} prerequisites delivered.`,datum:i.datum,x:o.x,y:o.y,width:o.width,height:o.height,shape:"rect",group:i.lane}]})}(W,q,z),[q,W,z]),he=(0,rp.useMemo)(()=>(0,Rp.jsx)(Cp,{machine:W,layout:q,runtime:z,downstreamSet:de,selectedSet:N,width:M,height:I,seed:k,reduced:F,onSelectTask:G}),[de,I,q,W,F,z,k,G,N,M]),pe=(0,rp.useMemo)(()=>{const e=[...z.blockers.keys()].map(e=>gp(W,e,{completedTaskIDs:z.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);return e.length?e.map(e=>`${W.byID.get(e.blockerID)?.label??e.blockerID} affects ${e.downstreamTaskCount} unfinished tasks across ${e.affectedLaneCount} lanes.`).join(" "):"No explicit blockers are active."},[W,z.blockers,z.completed]),me=(0,rp.useMemo)(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:I,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:M-2,y1:0,x2:M-2,y2:I,thickness:4}},{id:"chain-top",shape:{type:"segment",x1:0,y1:2,x2:M,y2:2,thickness:4}},{id:"chain-bottom",shape:{type:"segment",x1:0,y1:I-2,x2:M,y2:I-2,thickness:4}}],[I,M]),fe=!0===g?["play","pause","step","reset","settle"]:g||[];return(0,Rp.jsxs)("div",W.valid?{className:R,style:{width:M,maxWidth:"100%",position:"relative"},children:[fe.length>0&&(0,Rp.jsx)("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:fe.map(e=>(0,Rp.jsx)("button",{type:"button",onClick:"play"===e?ee:"pause"===e?Z:"step"===e?J:"reset"===e?te:Q,"aria-pressed":"play"===e?z.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),(0,Rp.jsx)(bs,{ref:D,size:[M,I],responsiveWidth:S,responsiveHeight:j,maxDevicePixelRatio:e.maxDevicePixelRatio,title:A,description:C??"Tasks are arranged by workstream and dependency depth. Balls represent satisfied prerequisites; task completion remains an explicit data event.",summary:`${pe}${le&&"blocker-amplification"===f?` Selected task reaches ${le.downstreamTaskCount} unfinished tasks across ${le.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:P,initialSpawns:bp,bodyForces:Sp,bodyStyle:{fill:"var(--semiotic-primary, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:ue,onSemanticItemActivate:e=>e.id&&G(e.id),foregroundGraphics:()=>he,paused:F,continuous:z.inFlight.size>0,onTick:K,config:{bodyLimit:Math.max(16,W.edges.length+4),colliders:me,settleStepLimit:2200,kernel:{seed:k,gravity:{x:0,y:7},fixedDt:1/60,cellSize:28,collisionIterations:2,velocityDamping:.992,restitution:.02,friction:.12,maxVelocity:150,sleepSpeed:1.1,sleepAfter:.8},observation:{chartType:"ChainReactionChart"}}}),$&&(0,Rp.jsxs)("table",{style:$p,children:[(0,Rp.jsx)("caption",{children:pe}),(0,Rp.jsx)("thead",{children:(0,Rp.jsxs)("tr",{children:[(0,Rp.jsx)("th",{children:"Task"}),(0,Rp.jsx)("th",{children:"Lane"}),(0,Rp.jsx)("th",{children:"Progress"}),(0,Rp.jsx)("th",{children:"State"}),(0,Rp.jsx)("th",{children:"Waiting on"}),(0,Rp.jsx)("th",{children:"Downstream reach"})]})}),(0,Rp.jsx)("tbody",{children:W.nodes.map(e=>{const t=gp(W,e.id,{completedTaskIDs:z.completed});return(0,Rp.jsxs)("tr",{children:[(0,Rp.jsx)("th",{scope:"row",children:e.label}),(0,Rp.jsx)("td",{children:e.lane}),(0,Rp.jsxs)("td",{children:[Math.round(100*e.progress),"%"]}),(0,Rp.jsx)("td",{children:z.completed.has(e.id)?"Completed":z.blockers.has(e.id)?"Blocked":z.armed.has(e.id)?"Armed":"Waiting"}),(0,Rp.jsx)("td",{children:z.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!z.completed.has(e)).join(", ")||"None")}),(0,Rp.jsxs)("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:R,role:"alert",style:{width:M,maxWidth:"100%"},children:[(0,Rp.jsx)("strong",{children:"ChainReactionChart could not compile this dependency graph."}),(0,Rp.jsx)("ul",{children:W.diagnostics.map((e,t)=>(0,Rp.jsx)("li",{children:e.message},`${e.code}-${t}`))})]})});Pp.displayName="ChainReactionChart";var Dp=bs;
2
+ module.exports=require("./semiotic-client-cjs-shared.min.js").physics;