semiotic 3.7.4 → 3.8.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 (517) hide show
  1. package/CLAUDE.md +60 -15
  2. package/README.md +135 -24
  3. package/agent-skill/semiotic-charts/SKILL.md +146 -0
  4. package/ai/cli.js +133 -45
  5. package/ai/componentMetadata.cjs +6 -1
  6. package/ai/dist/mcp-server.js +1651 -154
  7. package/ai/examples.md +174 -0
  8. package/ai/schema.json +2934 -517
  9. package/ai/surface-manifest.json +200 -0
  10. package/ai/system-prompt.md +19 -3
  11. package/dist/components/Annotation.d.ts +4 -0
  12. package/dist/components/CategoryColors.d.ts +1 -1
  13. package/dist/components/ChartContainer.d.ts +91 -0
  14. package/dist/components/ChartGrid.d.ts +11 -1
  15. package/dist/components/CircularBrush.d.ts +61 -0
  16. package/dist/components/ContextLayout.d.ts +5 -1
  17. package/dist/components/DataSummaryContext.d.ts +1 -0
  18. package/dist/components/DirectManipulationControl.d.ts +63 -0
  19. package/dist/components/LinkedCharts.d.ts +3 -1
  20. package/dist/components/MobileAnnotationCalloutList.d.ts +13 -0
  21. package/dist/components/MobileChartContainer.d.ts +51 -0
  22. package/dist/components/MobileStandardControls.d.ts +68 -0
  23. package/dist/components/SmallMultipleChart.d.ts +84 -0
  24. package/dist/components/Tooltip/FlippingTooltip.d.ts +21 -0
  25. package/dist/components/ai/ChartRecipe.d.ts +16 -0
  26. package/dist/components/ai/IntentMark.d.ts +15 -0
  27. package/dist/components/ai/chartCapabilities.d.ts +8 -1
  28. package/dist/components/ai/chartCapabilityTypes.d.ts +42 -1
  29. package/dist/components/ai/chartClinic.d.ts +91 -0
  30. package/dist/components/ai/chartRecipeRegistry.d.ts +14 -0
  31. package/dist/components/ai/chartRecipes.d.ts +278 -0
  32. package/dist/components/ai/dataPitfallsBridge.d.ts +203 -0
  33. package/dist/components/ai/dataQualityBridge.d.ts +201 -0
  34. package/dist/components/ai/describeChart.d.ts +9 -0
  35. package/dist/components/ai/describeRecipeChart.d.ts +16 -0
  36. package/dist/components/ai/generativeChart.d.ts +170 -0
  37. package/dist/components/ai/intentManifest.d.ts +62 -0
  38. package/dist/components/ai/navigationTree.d.ts +3 -0
  39. package/dist/components/ai/observedSceneAudit.d.ts +72 -0
  40. package/dist/components/ai/readerGrounding.d.ts +83 -0
  41. package/dist/components/ai/recipeCapability.d.ts +8 -0
  42. package/dist/components/ai/recipeNavigation.d.ts +13 -0
  43. package/dist/components/ai/recipeSemantics.d.ts +11 -0
  44. package/dist/components/ai/repairChartConfig.d.ts +9 -0
  45. package/dist/components/ai/suggestCharts.d.ts +11 -1
  46. package/dist/components/charts/custom/GeoCustomChart.d.ts +48 -0
  47. package/dist/components/charts/custom/NetworkCustomChart.d.ts +22 -3
  48. package/dist/components/charts/custom/OrdinalCustomChart.d.ts +8 -2
  49. package/dist/components/charts/custom/XYCustomChart.d.ts +11 -2
  50. package/dist/components/charts/geo/DistanceCartogram.d.ts +1 -1
  51. package/dist/components/charts/geo/FlowMap.d.ts +1 -1
  52. package/dist/components/charts/geo/ProportionalSymbolMap.d.ts +1 -1
  53. package/dist/components/charts/geo/index.d.ts +2 -0
  54. package/dist/components/charts/index.d.ts +29 -1
  55. package/dist/components/charts/network/ChordDiagram.d.ts +1 -1
  56. package/dist/components/charts/network/CirclePack.d.ts +1 -1
  57. package/dist/components/charts/network/ForceDirectedGraph.d.ts +15 -5
  58. package/dist/components/charts/network/OrbitDiagram.d.ts +1 -1
  59. package/dist/components/charts/network/ProcessSankey.d.ts +1 -1
  60. package/dist/components/charts/network/SankeyDiagram.d.ts +1 -1
  61. package/dist/components/charts/network/TreeDiagram.d.ts +1 -1
  62. package/dist/components/charts/network/Treemap.d.ts +1 -1
  63. package/dist/components/charts/network/useForceLayout.d.ts +17 -0
  64. package/dist/components/charts/ordinal/BarChart.d.ts +1 -1
  65. package/dist/components/charts/ordinal/BoxPlot.d.ts +1 -1
  66. package/dist/components/charts/ordinal/DonutChart.d.ts +1 -1
  67. package/dist/components/charts/ordinal/DotPlot.d.ts +1 -1
  68. package/dist/components/charts/ordinal/FunnelChart.d.ts +1 -1
  69. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +1 -1
  70. package/dist/components/charts/ordinal/Histogram.d.ts +1 -1
  71. package/dist/components/charts/ordinal/PieChart.d.ts +1 -1
  72. package/dist/components/charts/ordinal/RidgelinePlot.d.ts +1 -1
  73. package/dist/components/charts/ordinal/StackedBarChart.d.ts +1 -1
  74. package/dist/components/charts/ordinal/SwarmPlot.d.ts +8 -1
  75. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +1 -1
  76. package/dist/components/charts/ordinal/ViolinPlot.d.ts +1 -1
  77. package/dist/components/charts/physics/ChainReactionChart.d.ts +9 -0
  78. package/dist/components/charts/physics/CollisionSwarmChart.capability.d.ts +2 -0
  79. package/dist/components/charts/physics/CollisionSwarmChart.d.ts +47 -0
  80. package/dist/components/charts/physics/EventDropChart.capability.d.ts +2 -0
  81. package/dist/components/charts/physics/EventDropChart.d.ts +53 -0
  82. package/dist/components/charts/physics/GaltonBoardChart.capability.d.ts +2 -0
  83. package/dist/components/charts/physics/GaltonBoardChart.d.ts +66 -0
  84. package/dist/components/charts/physics/GauntletChart.capability.d.ts +2 -0
  85. package/dist/components/charts/physics/GauntletChart.d.ts +73 -0
  86. package/dist/components/charts/physics/PhysicalFlowChart.capability.d.ts +2 -0
  87. package/dist/components/charts/physics/PhysicalFlowChart.d.ts +63 -0
  88. package/dist/components/charts/physics/PhysicsCustomChart.d.ts +120 -0
  89. package/dist/components/charts/physics/PhysicsPileChart.capability.d.ts +2 -0
  90. package/dist/components/charts/physics/PhysicsPileChart.d.ts +53 -0
  91. package/dist/components/charts/physics/ProcessFlowChart.capability.d.ts +2 -0
  92. package/dist/components/charts/physics/ProcessFlowChart.d.ts +96 -0
  93. package/dist/components/charts/physics/chainReactionOverlay.d.ts +22 -0
  94. package/dist/components/charts/physics/chainReactionRuntime.d.ts +37 -0
  95. package/dist/components/charts/physics/chainReactionTypes.d.ts +97 -0
  96. package/dist/components/charts/physics/collisionSwarmPhysics.d.ts +27 -0
  97. package/dist/components/charts/physics/dependencyMachine.d.ts +188 -0
  98. package/dist/components/charts/physics/eventDropPhysics.d.ts +64 -0
  99. package/dist/components/charts/physics/galtonBoardPhysics.d.ts +28 -0
  100. package/dist/components/charts/physics/gauntletChartProps.d.ts +67 -0
  101. package/dist/components/charts/physics/gauntletChrome.d.ts +33 -0
  102. package/dist/components/charts/physics/gauntletController.d.ts +73 -0
  103. package/dist/components/charts/physics/gauntletEffects.d.ts +36 -0
  104. package/dist/components/charts/physics/gauntletPhysics.d.ts +71 -0
  105. package/dist/components/charts/physics/gauntletRuntime.d.ts +42 -0
  106. package/dist/components/charts/physics/gauntletTypes.d.ts +213 -0
  107. package/dist/components/charts/physics/physicalFlowPhysics.d.ts +57 -0
  108. package/dist/components/charts/physics/physicsChartShared.d.ts +41 -0
  109. package/dist/components/charts/physics/physicsChartUtils.d.ts +18 -0
  110. package/dist/components/charts/physics/physicsEncoding.d.ts +142 -0
  111. package/dist/components/charts/physics/physicsHocHandle.d.ts +53 -0
  112. package/dist/components/charts/physics/physicsHocUtils.d.ts +128 -0
  113. package/dist/components/charts/physics/physicsPilePhysics.d.ts +41 -0
  114. package/dist/components/charts/physics/physicsProcessPrimitives.d.ts +38 -0
  115. package/dist/components/charts/physics/processFlowPhysics.d.ts +97 -0
  116. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +9 -1
  117. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +9 -1
  118. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +30 -1
  119. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +16 -2
  120. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +9 -1
  121. package/dist/components/charts/realtime/aggregate.d.ts +51 -0
  122. package/dist/components/charts/realtime/eventTime.d.ts +26 -0
  123. package/dist/components/charts/shared/auditMobileVisualization.d.ts +91 -0
  124. package/dist/components/charts/shared/chartDefinitionPilot.d.ts +145 -0
  125. package/dist/components/charts/shared/chartFamilySets.d.ts +20 -0
  126. package/dist/components/charts/shared/chartSpecCore.d.ts +165 -0
  127. package/dist/components/charts/shared/chartSpecs.d.ts +8 -127
  128. package/dist/components/charts/shared/chartSpecsGeo.d.ts +2 -0
  129. package/dist/components/charts/shared/chartSpecsNetwork.d.ts +2 -0
  130. package/dist/components/charts/shared/chartSpecsOrdinal.d.ts +2 -0
  131. package/dist/components/charts/shared/chartSpecsPhysics.d.ts +2 -0
  132. package/dist/components/charts/shared/chartSpecsRealtime.d.ts +2 -0
  133. package/dist/components/charts/shared/chartSpecsValue.d.ts +2 -0
  134. package/dist/components/charts/shared/chartSpecsXY.d.ts +2 -0
  135. package/dist/components/charts/shared/colorContrast.d.ts +3 -0
  136. package/dist/components/charts/shared/colorPalettes.d.ts +2 -0
  137. package/dist/components/charts/shared/colorUtils.d.ts +17 -13
  138. package/dist/components/charts/shared/diagnoseAnnotationChecks.d.ts +4 -0
  139. package/dist/components/charts/shared/diagnoseConfig.d.ts +9 -14
  140. package/dist/components/charts/shared/diagnoseMisleadingChecks.d.ts +9 -0
  141. package/dist/components/charts/shared/diagnosePhysicsChecks.d.ts +3 -0
  142. package/dist/components/charts/shared/diagnoseTypes.d.ts +10 -0
  143. package/dist/components/charts/shared/hooks.d.ts +28 -5
  144. package/dist/components/charts/shared/minMax.d.ts +3 -0
  145. package/dist/components/charts/shared/motionEncoding.d.ts +145 -0
  146. package/dist/components/charts/shared/radialGeometry.d.ts +0 -18
  147. package/dist/components/charts/shared/responsiveRules.d.ts +56 -0
  148. package/dist/components/charts/shared/smartTooltip.d.ts +27 -0
  149. package/dist/components/charts/shared/statisticalOverlays.d.ts +35 -0
  150. package/dist/components/charts/shared/streamPropsHelpers.d.ts +12 -2
  151. package/dist/components/charts/shared/temporalStrings.d.ts +7 -0
  152. package/dist/components/charts/shared/tooltipUtils.d.ts +2 -0
  153. package/dist/components/charts/shared/types.d.ts +49 -1
  154. package/dist/components/charts/shared/useChartSetup.d.ts +10 -3
  155. package/dist/components/charts/shared/useCustomChartSetup.d.ts +15 -6
  156. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +6 -2
  157. package/dist/components/charts/shared/useOrdinalPieceStyle.d.ts +1 -1
  158. package/dist/components/charts/shared/useStreamingLegend.d.ts +1 -1
  159. package/dist/components/charts/shared/useSyncedPushData.d.ts +49 -0
  160. package/dist/components/charts/shared/validateChartData.d.ts +1 -1
  161. package/dist/components/charts/shared/validationMap.d.ts +0 -11
  162. package/dist/components/charts/xy/AreaChart.d.ts +1 -1
  163. package/dist/components/charts/xy/BubbleChart.d.ts +1 -1
  164. package/dist/components/charts/xy/LineChart.d.ts +1 -1
  165. package/dist/components/charts/xy/MinimapChart.d.ts +1 -1
  166. package/dist/components/charts/xy/MultiAxisLineChart.d.ts +2 -2
  167. package/dist/components/charts/xy/QuadrantChart.d.ts +1 -1
  168. package/dist/components/charts/xy/Scatterplot.d.ts +10 -1
  169. package/dist/components/charts/xy/ScatterplotMatrix.d.ts +11 -1
  170. package/dist/components/charts/xy/StackedAreaChart.d.ts +9 -4
  171. package/dist/components/controls/controlAudit.d.ts +24 -0
  172. package/dist/components/controls/controlContract.d.ts +57 -0
  173. package/dist/components/data/fromArrow.d.ts +54 -0
  174. package/dist/components/data/fromFlintChart.d.ts +74 -0
  175. package/dist/components/data/fromMermaid.d.ts +47 -0
  176. package/dist/components/data/fromObservablePlot.d.ts +69 -0
  177. package/dist/components/data/fromVegaLite.d.ts +27 -0
  178. package/dist/components/data/portability/index.d.ts +17 -0
  179. package/dist/components/data/portability/result.d.ts +52 -0
  180. package/dist/components/data/portability/spec.d.ts +160 -0
  181. package/dist/components/data/portability/vegaLite.d.ts +80 -0
  182. package/dist/components/export/chartConfig.d.ts +11 -0
  183. package/dist/components/realtime/ReorderBuffer.d.ts +54 -0
  184. package/dist/components/realtime/RunningStats.d.ts +66 -0
  185. package/dist/components/realtime/WindowAccumulator.d.ts +105 -0
  186. package/dist/components/realtime/parseWindowDuration.d.ts +12 -0
  187. package/dist/components/realtime/types.d.ts +11 -0
  188. package/dist/components/recipes/annotationLayout.d.ts +29 -0
  189. package/dist/components/recipes/axisFixedForce.d.ts +119 -0
  190. package/dist/components/recipes/boba.d.ts +23 -0
  191. package/dist/components/recipes/customTooltip.d.ts +31 -0
  192. package/dist/components/recipes/cyclical.d.ts +39 -0
  193. package/dist/components/recipes/edgeRouter.d.ts +103 -0
  194. package/dist/components/recipes/forceLayout.d.ts +48 -0
  195. package/dist/components/recipes/forceLayoutAsync.d.ts +17 -0
  196. package/dist/components/recipes/gofishBobaHandwritten.d.ts +3 -0
  197. package/dist/components/recipes/gofishDisplayListFixtures.generated.d.ts +37 -0
  198. package/dist/components/recipes/gofishIR.d.ts +215 -0
  199. package/dist/components/recipes/gofishIRExamples.d.ts +38 -0
  200. package/dist/components/recipes/intervalLanes.d.ts +87 -0
  201. package/dist/components/recipes/intervals.d.ts +80 -0
  202. package/dist/components/recipes/isometricLandmarks.d.ts +88 -0
  203. package/dist/components/recipes/isotypeGlyphs.d.ts +17 -0
  204. package/dist/components/recipes/mermaidDag.d.ts +44 -0
  205. package/dist/components/recipes/mobileAnnotationStrategy.d.ts +48 -0
  206. package/dist/components/recipes/mobileChartFamilyRecipes.d.ts +59 -0
  207. package/dist/components/recipes/networkAnalysis.d.ts +102 -0
  208. package/dist/components/recipes/networkLayouts.d.ts +83 -0
  209. package/dist/components/recipes/packedClusterMatrix.d.ts +166 -0
  210. package/dist/components/recipes/physics.d.ts +122 -0
  211. package/dist/components/recipes/physicsReference.d.ts +102 -0
  212. package/dist/components/recipes/processAggregates.d.ts +32 -0
  213. package/dist/components/recipes/processChrome.d.ts +67 -0
  214. package/dist/components/recipes/processJourney.d.ts +54 -0
  215. package/dist/components/recipes/processPhysics.d.ts +300 -0
  216. package/dist/components/recipes/processVolumeGeometry.d.ts +28 -0
  217. package/dist/components/recipes/radialCoords.d.ts +69 -0
  218. package/dist/components/recipes/random.d.ts +2 -0
  219. package/dist/components/recipes/recipeChrome.d.ts +191 -0
  220. package/dist/components/recipes/recipeGlyph.d.ts +42 -0
  221. package/dist/components/recipes/recipeLegend.d.ts +109 -0
  222. package/dist/components/recipes/recipeUtils.d.ts +157 -0
  223. package/dist/components/recipes/runs.d.ts +59 -0
  224. package/dist/components/recipes/tokenEncoding.d.ts +157 -0
  225. package/dist/components/recipes/tokenLayer.d.ts +79 -0
  226. package/dist/components/recipes/unitize.d.ts +108 -0
  227. package/dist/components/recipes/vector.d.ts +28 -0
  228. package/dist/components/recipes/waffle.d.ts +43 -0
  229. package/dist/components/semiotic-ai-core.d.ts +47 -0
  230. package/dist/components/semiotic-ai.d.ts +52 -4
  231. package/dist/components/semiotic-controls.d.ts +18 -0
  232. package/dist/components/semiotic-data.d.ts +2 -0
  233. package/dist/components/semiotic-experimental.d.ts +49 -0
  234. package/dist/components/semiotic-geo.d.ts +11 -0
  235. package/dist/components/semiotic-network.d.ts +14 -1
  236. package/dist/components/semiotic-ordinal.d.ts +10 -0
  237. package/dist/components/semiotic-physics-matter.d.ts +10 -0
  238. package/dist/components/semiotic-physics-rapier.d.ts +9 -0
  239. package/dist/components/semiotic-physics.d.ts +56 -0
  240. package/dist/components/semiotic-realtime-core.d.ts +34 -0
  241. package/dist/components/semiotic-realtime-react.d.ts +10 -0
  242. package/dist/components/semiotic-realtime.d.ts +4 -22
  243. package/dist/components/semiotic-recipes-core.d.ts +92 -0
  244. package/dist/components/semiotic-recipes-react.d.ts +7 -0
  245. package/dist/components/semiotic-recipes.d.ts +4 -26
  246. package/dist/components/semiotic-server-edge.d.ts +8 -0
  247. package/dist/components/semiotic-server-node.d.ts +5 -0
  248. package/dist/components/semiotic-server.d.ts +2 -2
  249. package/dist/components/semiotic-themes-core.d.ts +53 -0
  250. package/dist/components/semiotic-themes-react.d.ts +4 -0
  251. package/dist/components/semiotic-themes.d.ts +6 -74
  252. package/dist/components/semiotic-utils-core.d.ts +46 -0
  253. package/dist/components/semiotic-utils-react.d.ts +5 -0
  254. package/dist/components/semiotic-utils.d.ts +3 -39
  255. package/dist/components/semiotic-xy.d.ts +10 -0
  256. package/dist/components/semiotic.d.ts +39 -7
  257. package/dist/components/server/animatedGif.d.ts +36 -0
  258. package/dist/components/server/renderEvidence.d.ts +1 -1
  259. package/dist/components/server/renderToStaticSVG.d.ts +3 -35
  260. package/dist/components/server/serverChartConfigShared.d.ts +17 -0
  261. package/dist/components/server/serverChartConfigs.d.ts +19 -9
  262. package/dist/components/server/serverChartConfigsCustom.d.ts +5 -0
  263. package/dist/components/server/serverChartConfigsGeo.d.ts +9 -0
  264. package/dist/components/server/serverChartConfigsNetwork.d.ts +8 -0
  265. package/dist/components/server/serverChartConfigsOrdinal.d.ts +16 -0
  266. package/dist/components/server/serverChartConfigsPhysics.d.ts +9 -0
  267. package/dist/components/server/serverChartConfigsXY.d.ts +11 -0
  268. package/dist/components/server/staticGeo.d.ts +4 -0
  269. package/dist/components/server/staticLegend.d.ts +1 -1
  270. package/dist/components/server/staticNetwork.d.ts +8 -0
  271. package/dist/components/server/staticOrdinal.d.ts +11 -0
  272. package/dist/components/server/staticPhysics.d.ts +3 -0
  273. package/dist/components/server/staticSVGChrome.d.ts +110 -0
  274. package/dist/components/server/staticXY.d.ts +4 -0
  275. package/dist/components/store/ObservationStore.d.ts +23 -3
  276. package/dist/components/store/SelectionStore.d.ts +1 -1
  277. package/dist/components/store/ThemeStore.d.ts +1 -1
  278. package/dist/components/store/TooltipStore.d.ts +1 -1
  279. package/dist/components/store/createStore.d.ts +1 -1
  280. package/dist/components/store/designTokens.d.ts +15 -0
  281. package/dist/components/store/themeSerialization.d.ts +32 -0
  282. package/dist/components/store/useChartInterrogation.d.ts +9 -0
  283. package/dist/components/stream/AccessibleDataTable.d.ts +3 -13
  284. package/dist/components/stream/FocusRing.d.ts +4 -2
  285. package/dist/components/stream/GeoCanvasHitTester.d.ts +1 -1
  286. package/dist/components/stream/GeoPipelineStore.d.ts +28 -0
  287. package/dist/components/stream/NetworkHtmlMarksLayer.d.ts +44 -0
  288. package/dist/components/stream/NetworkPipelineStore.d.ts +62 -25
  289. package/dist/components/stream/NetworkSVGOverlay.d.ts +15 -0
  290. package/dist/components/stream/OrdinalPipelineStore.d.ts +64 -2
  291. package/dist/components/stream/PipelineStore.d.ts +100 -162
  292. package/dist/components/stream/SceneGraph.d.ts +14 -2
  293. package/dist/components/stream/StreamGeoFrame.d.ts +1 -1
  294. package/dist/components/stream/StreamNetworkFrame.d.ts +1 -1
  295. package/dist/components/stream/StreamOrdinalFrame.d.ts +1 -1
  296. package/dist/components/stream/StreamXYFrame.d.ts +2 -18
  297. package/dist/components/stream/accessibleDataRows.d.ts +33 -0
  298. package/dist/components/stream/accessorUtils.d.ts +23 -10
  299. package/dist/components/stream/brushAccessibility.d.ts +25 -0
  300. package/dist/components/stream/canvasBackground.d.ts +24 -0
  301. package/dist/components/stream/canvasSetup.d.ts +4 -1
  302. package/dist/components/stream/customLayout.d.ts +20 -0
  303. package/dist/components/stream/customLayoutDiagnostics.d.ts +11 -0
  304. package/dist/components/stream/customLayoutFailure.d.ts +33 -0
  305. package/dist/components/stream/customLayoutPalette.d.ts +19 -9
  306. package/dist/components/stream/customLayoutSelection.d.ts +52 -0
  307. package/dist/components/stream/frameThemeColors.d.ts +24 -0
  308. package/dist/components/stream/geoAnnotationAnchors.d.ts +14 -0
  309. package/dist/components/stream/geoCartogram.d.ts +17 -0
  310. package/dist/components/stream/geoCustomLayout.d.ts +59 -0
  311. package/dist/components/stream/geoDefaultTooltip.d.ts +11 -0
  312. package/dist/components/stream/geoFrameHelpers.d.ts +34 -0
  313. package/dist/components/stream/geoPipelineHelpers.d.ts +46 -0
  314. package/dist/components/stream/geoTypes.d.ts +56 -7
  315. package/dist/components/stream/glyphDef.d.ts +98 -0
  316. package/dist/components/stream/hitTarget.d.ts +170 -0
  317. package/dist/components/stream/hoverUtils.d.ts +3 -0
  318. package/dist/components/stream/keyboardNav.d.ts +4 -1
  319. package/dist/components/stream/layouts/forceLayoutPlugin.d.ts +9 -1
  320. package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +57 -0
  321. package/dist/components/stream/networkBezier.d.ts +10 -0
  322. package/dist/components/stream/networkColorAccessors.d.ts +49 -0
  323. package/dist/components/stream/networkCustomLayout.d.ts +66 -1
  324. package/dist/components/stream/networkDefaultTooltip.d.ts +10 -0
  325. package/dist/components/stream/networkFrameInteraction.d.ts +37 -0
  326. package/dist/components/stream/networkFramePaint.d.ts +43 -0
  327. package/dist/components/stream/networkPipelineConfig.d.ts +22 -0
  328. package/dist/components/stream/networkPipelineHelpers.d.ts +12 -0
  329. package/dist/components/stream/networkRealtimeEncoding.d.ts +41 -0
  330. package/dist/components/stream/networkTypes.d.ts +104 -5
  331. package/dist/components/stream/ordinalCanvasRenderers.d.ts +7 -0
  332. package/dist/components/stream/ordinalCustomLayout.d.ts +17 -1
  333. package/dist/components/stream/ordinalDataIndex.d.ts +5 -0
  334. package/dist/components/stream/ordinalDefaultTooltip.d.ts +10 -0
  335. package/dist/components/stream/ordinalDomain.d.ts +38 -0
  336. package/dist/components/stream/ordinalPipelineUpdateResults.d.ts +12 -0
  337. package/dist/components/stream/ordinalPulse.d.ts +10 -0
  338. package/dist/components/stream/ordinalPulseResources.d.ts +3 -0
  339. package/dist/components/stream/ordinalSceneBuilders/sceneBuilderMap.d.ts +5 -0
  340. package/dist/components/stream/ordinalSceneBuilders/types.d.ts +2 -0
  341. package/dist/components/stream/ordinalSpatialIndex.d.ts +9 -0
  342. package/dist/components/stream/ordinalTypes.d.ts +56 -8
  343. package/dist/components/stream/paintNeeds.d.ts +31 -0
  344. package/dist/components/stream/physics/CapacityQueueController.d.ts +5 -0
  345. package/dist/components/stream/physics/CapacityQueueTypes.d.ts +134 -0
  346. package/dist/components/stream/physics/MatterPhysicsEngineAdapter.d.ts +42 -0
  347. package/dist/components/stream/physics/PhysicsAccessibility.d.ts +48 -0
  348. package/dist/components/stream/physics/PhysicsAnnotations.d.ts +58 -0
  349. package/dist/components/stream/physics/PhysicsBodyBudget.d.ts +26 -0
  350. package/dist/components/stream/physics/PhysicsBodySpatialIndex.d.ts +10 -0
  351. package/dist/components/stream/physics/PhysicsCanvasTheme.d.ts +26 -0
  352. package/dist/components/stream/physics/PhysicsControllers.d.ts +75 -0
  353. package/dist/components/stream/physics/PhysicsEngineAdapter.d.ts +59 -0
  354. package/dist/components/stream/physics/PhysicsEngineConformance.d.ts +23 -0
  355. package/dist/components/stream/physics/PhysicsEvidence.d.ts +25 -0
  356. package/dist/components/stream/physics/PhysicsKernel.d.ts +207 -0
  357. package/dist/components/stream/physics/PhysicsOptionalEngineAdapters.d.ts +12 -0
  358. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +84 -0
  359. package/dist/components/stream/physics/PhysicsPipelineTypes.d.ts +181 -0
  360. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +72 -0
  361. package/dist/components/stream/physics/PhysicsSediment.d.ts +69 -0
  362. package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +18 -0
  363. package/dist/components/stream/physics/PhysicsSettledScene.d.ts +21 -0
  364. package/dist/components/stream/physics/PhysicsWorkerClient.d.ts +24 -0
  365. package/dist/components/stream/physics/PhysicsWorkerProtocol.d.ts +101 -0
  366. package/dist/components/stream/physics/PhysicsWorkerRuntime.d.ts +5 -0
  367. package/dist/components/stream/physics/RapierPhysicsEngineAdapter.d.ts +18 -0
  368. package/dist/components/stream/physics/ServiceOperationsControllers.d.ts +27 -0
  369. package/dist/components/stream/physics/ServiceOperationsTypes.d.ts +89 -0
  370. package/dist/components/stream/physics/StreamPhysicsFrame.d.ts +6 -0
  371. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +302 -0
  372. package/dist/components/stream/physics/physicsBodyCanvas.d.ts +27 -0
  373. package/dist/components/stream/physics/physicsPipelineControls.d.ts +4 -0
  374. package/dist/components/stream/physics/physicsPipelineHelpers.d.ts +41 -0
  375. package/dist/components/stream/physics/physicsPipelineObservations.d.ts +14 -0
  376. package/dist/components/stream/physics/physicsPipelineUpdateResults.d.ts +9 -0
  377. package/dist/components/stream/physics/physicsRegionRuntime.d.ts +54 -0
  378. package/dist/components/stream/physics/physicsSemanticUI.d.ts +20 -0
  379. package/dist/components/stream/physics/usePhysicsFrameLifecyclePolicy.d.ts +16 -0
  380. package/dist/components/stream/pipelineBufferUtils.d.ts +26 -0
  381. package/dist/components/stream/pipelineConfig.d.ts +177 -0
  382. package/dist/components/stream/pipelineDecay.d.ts +20 -2
  383. package/dist/components/stream/pipelineDomainResolution.d.ts +62 -0
  384. package/dist/components/stream/pipelineIdentityOps.d.ts +26 -0
  385. package/dist/components/stream/pipelinePulse.d.ts +16 -2
  386. package/dist/components/stream/pipelineRibbons.d.ts +41 -0
  387. package/dist/components/stream/pipelineSpatialIndex.d.ts +12 -0
  388. package/dist/components/stream/pipelineStoreUpdateResults.d.ts +12 -0
  389. package/dist/components/stream/pipelineStyleResolvers.d.ts +46 -0
  390. package/dist/components/stream/pipelineTransitions.d.ts +2 -0
  391. package/dist/components/stream/pipelineUpdateContract.d.ts +62 -0
  392. package/dist/components/stream/pulseFrameRefresh.d.ts +22 -0
  393. package/dist/components/stream/renderers/glyphCanvasRenderer.d.ts +6 -0
  394. package/dist/components/stream/renderers/networkSymbolRenderer.d.ts +2 -0
  395. package/dist/components/stream/renderers/resolveCSSColor.d.ts +6 -0
  396. package/dist/components/stream/renderers/symbolCanvasRenderer.d.ts +2 -0
  397. package/dist/components/stream/sceneRevisionDiagnostics.d.ts +18 -0
  398. package/dist/components/stream/stalenessBands.d.ts +28 -0
  399. package/dist/components/stream/streamStoreSync.d.ts +37 -0
  400. package/dist/components/stream/symbolPath.d.ts +24 -0
  401. package/dist/components/stream/types.d.ts +206 -9
  402. package/dist/components/stream/useFrame.d.ts +21 -2
  403. package/dist/components/stream/useHydration.d.ts +6 -0
  404. package/dist/components/stream/useLegendCategoryEmission.d.ts +5 -0
  405. package/dist/components/stream/useStalenessCheck.d.ts +6 -1
  406. package/dist/components/stream/workerModuleUrl.d.ts +10 -0
  407. package/dist/components/stream/xyAnnotationAnchors.d.ts +13 -0
  408. package/dist/components/stream/xyCanvasRenderers.d.ts +7 -0
  409. package/dist/components/stream/xyCrosshair.d.ts +11 -0
  410. package/dist/components/stream/xyDateTicks.d.ts +9 -0
  411. package/dist/components/stream/xyDefaultTooltip.d.ts +10 -0
  412. package/dist/components/stream/xySceneBuilders/pointScene.d.ts +2 -2
  413. package/dist/components/stream/xySceneBuilders/types.d.ts +9 -4
  414. package/dist/controls.min.js +2 -0
  415. package/dist/controls.module.min.js +2 -0
  416. package/dist/forceLayoutWorker.js +1 -0
  417. package/dist/geo.min.js +1 -1
  418. package/dist/geo.module.min.js +1 -1
  419. package/dist/network.min.js +1 -1
  420. package/dist/network.module.min.js +1 -1
  421. package/dist/ordinal.min.js +1 -1
  422. package/dist/ordinal.module.min.js +1 -1
  423. package/dist/physics-matter.min.js +1 -0
  424. package/dist/physics-matter.module.min.js +1 -0
  425. package/dist/physics-rapier.min.js +1 -0
  426. package/dist/physics-rapier.module.min.js +1 -0
  427. package/dist/physics.min.js +2 -0
  428. package/dist/physics.module.min.js +2 -0
  429. package/dist/physicsWorker.js +1 -0
  430. package/dist/realtime.min.js +1 -1
  431. package/dist/realtime.module.min.js +1 -1
  432. package/dist/semiotic-ai-chunk-OG7BQUUW.module.min.js +2 -0
  433. package/dist/semiotic-ai-core.d.ts +47 -0
  434. package/dist/semiotic-ai-core.min.js +1 -0
  435. package/dist/semiotic-ai-core.module.min.js +1 -0
  436. package/dist/semiotic-ai-statisticalOverlays-CY4WKR4A.module.min.js +2 -0
  437. package/dist/semiotic-ai.d.ts +52 -4
  438. package/dist/semiotic-ai.min.js +1 -1
  439. package/dist/semiotic-ai.module.min.js +1 -1
  440. package/dist/semiotic-chunk-3FSVZ46U.module.min.js +2 -0
  441. package/dist/semiotic-controls.d.ts +18 -0
  442. package/dist/semiotic-data.d.ts +2 -0
  443. package/dist/semiotic-data.min.js +1 -1
  444. package/dist/semiotic-data.module.min.js +1 -1
  445. package/dist/semiotic-experimental.d.ts +49 -0
  446. package/dist/semiotic-experimental.min.js +1 -0
  447. package/dist/semiotic-experimental.module.min.js +1 -0
  448. package/dist/semiotic-geo.d.ts +11 -0
  449. package/dist/semiotic-network.d.ts +14 -1
  450. package/dist/semiotic-ordinal.d.ts +10 -0
  451. package/dist/semiotic-physics-matter.d.ts +10 -0
  452. package/dist/semiotic-physics-rapier.d.ts +9 -0
  453. package/dist/semiotic-physics.d.ts +56 -0
  454. package/dist/semiotic-realtime-core.d.ts +34 -0
  455. package/dist/semiotic-realtime-core.min.js +1 -0
  456. package/dist/semiotic-realtime-core.module.min.js +1 -0
  457. package/dist/semiotic-realtime-react.d.ts +10 -0
  458. package/dist/semiotic-realtime-react.min.js +2 -0
  459. package/dist/semiotic-realtime-react.module.min.js +2 -0
  460. package/dist/semiotic-realtime.d.ts +4 -22
  461. package/dist/semiotic-recipes-core.d.ts +92 -0
  462. package/dist/semiotic-recipes-core.min.js +1 -0
  463. package/dist/semiotic-recipes-core.module.min.js +1 -0
  464. package/dist/semiotic-recipes-react.d.ts +7 -0
  465. package/dist/semiotic-recipes-react.min.js +2 -0
  466. package/dist/semiotic-recipes-react.module.min.js +2 -0
  467. package/dist/semiotic-recipes.d.ts +4 -26
  468. package/dist/semiotic-recipes.min.js +1 -1
  469. package/dist/semiotic-recipes.module.min.js +1 -1
  470. package/dist/semiotic-server-edge.d.ts +8 -0
  471. package/dist/semiotic-server-edge.min.js +1 -0
  472. package/dist/semiotic-server-edge.module.min.js +1 -0
  473. package/dist/semiotic-server-node.d.ts +5 -0
  474. package/dist/semiotic-server-node.min.js +1 -0
  475. package/dist/semiotic-server-node.module.min.js +1 -0
  476. package/dist/semiotic-server.d.ts +2 -2
  477. package/dist/semiotic-statisticalOverlays-UOMSFKVJ.module.min.js +2 -0
  478. package/dist/semiotic-themes-core.d.ts +53 -0
  479. package/dist/semiotic-themes-core.min.js +1 -0
  480. package/dist/semiotic-themes-core.module.min.js +1 -0
  481. package/dist/semiotic-themes-react.d.ts +4 -0
  482. package/dist/semiotic-themes-react.min.js +2 -0
  483. package/dist/semiotic-themes-react.module.min.js +2 -0
  484. package/dist/semiotic-themes.d.ts +6 -74
  485. package/dist/semiotic-themes.min.js +1 -2
  486. package/dist/semiotic-themes.module.min.js +1 -2
  487. package/dist/semiotic-utils-core.d.ts +46 -0
  488. package/dist/semiotic-utils-core.min.js +1 -0
  489. package/dist/semiotic-utils-core.module.min.js +1 -0
  490. package/dist/semiotic-utils-react.d.ts +5 -0
  491. package/dist/semiotic-utils-react.min.js +2 -0
  492. package/dist/semiotic-utils-react.module.min.js +2 -0
  493. package/dist/semiotic-utils.d.ts +3 -39
  494. package/dist/semiotic-utils.min.js +1 -2
  495. package/dist/semiotic-utils.module.min.js +1 -2
  496. package/dist/semiotic-value.min.js +1 -1
  497. package/dist/semiotic-value.module.min.js +1 -1
  498. package/dist/semiotic-xy.d.ts +10 -0
  499. package/dist/semiotic.d.ts +39 -7
  500. package/dist/semiotic.min.js +1 -1
  501. package/dist/semiotic.module.min.js +1 -1
  502. package/dist/server.min.js +1 -1
  503. package/dist/server.module.min.js +1 -1
  504. package/dist/xy-chunk-IWD6IB6V.module.min.js +2 -0
  505. package/dist/xy-statisticalOverlays-7RWG6LJT.module.min.js +2 -0
  506. package/dist/xy.min.js +1 -1
  507. package/dist/xy.module.min.js +1 -1
  508. package/package.json +246 -86
  509. package/spec/README.md +152 -0
  510. package/spec/bindings/README.md +35 -0
  511. package/spec/bindings/vega-lite.mjs +112 -0
  512. package/spec/v0.1/annotation-provenance.schema.json +127 -0
  513. package/spec/v0.1/audience-profile.schema.json +67 -0
  514. package/spec/v0.1/chart-capability.schema.json +186 -0
  515. package/dist/semiotic-ai-statisticalOverlays-C2PPlmXv.js +0 -1
  516. package/dist/semiotic-statisticalOverlays-C3DsOgr_.js +0 -1
  517. package/dist/xy-statisticalOverlays-C2PPlmXv.js +0 -1
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ "use strict";var e,t=Object.create,n=Object.defineProperty,i=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,a=(e,t,o,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of r(t))s.call(e,c)||c===o||n(e,c,{get:()=>t[c],enumerable:!(a=i(t,c))||a.enumerable});return e},c=(e,i,r)=>(r=null!=e?t(o(e)):{},a(!i&&e&&e.__esModule?r:n(r,"default",{value:e,enumerable:!0}),e)),l={};((e,t)=>{for(var i in t)n(e,i,{get:t[i],enumerable:!0})})(l,{BuiltInPhysicsEngineAdapter:()=>Nn,ChainReactionChart:()=>Al,CollisionSwarmChart:()=>ta,EventDropChart:()=>Ws,GaltonBoardChart:()=>Ns,GauntletChart:()=>tc,GuantletChart:()=>nc,PhysicalFlowChart:()=>fc,PhysicsCustomChart:()=>Qs,PhysicsPileChart:()=>Ls,PhysicsPipelineStore:()=>Ii,PhysicsSVGOverlay:()=>Jt,PhysicsSedimentAccumulator:()=>_n,ProcessFlowChart:()=>Ic,StreamPhysicsFrame:()=>Ur,absorbRegion:()=>Lo,aggregateRegionCounts:()=>Io,arrivalReplay:()=>el,bodiesToAnnotationAnchors:()=>Kt,bodyGroupSpec:()=>Ho,buildCollisionSwarmPhysics:()=>go,buildEventDropPhysics:()=>po,buildGaltonBoardPhysics:()=>lo,buildPhysicalFlowPhysics:()=>So,buildPhysicsAnnotationContext:()=>Qt,buildPhysicsPile:()=>mo,buildProcessFlowPhysics:()=>_o,calculateBlockerAmplification:()=>pl,capacitatedRegion:()=>Fo,chargeGateRegion:()=>qo,collidersFromScales:()=>Kc,comparePhysicsTrace:()=>Fc,compileDependencyMachine:()=>cl,compileMotionEncoding:()=>oa,compilePhysicsEncoding:()=>da,composePhysicsControllers:()=>Xi,createCapacityQueueController:()=>zi,createDefaultPhysicsEngineAdapter:()=>qn,createDependencyGateController:()=>Hi,createLogicalJoin:()=>dl,createPhysicsEncodingLayout:()=>ua,createPortalController:()=>_i,createProcessJourneyLedger:()=>Lc,createServiceLevelController:()=>Yi,createServiceResourcePoolController:()=>Oi,default:()=>Cl,deriveMotionVector:()=>la,evaluatePhysicsBodyBudget:()=>Kn,forceFieldRegion:()=>Yo,galtonPegs:()=>Qc,groupCompletionRows:()=>Ao,membraneRegion:()=>No,normalizePhysicsAnnotations:()=>Zt,opacityFromAge:()=>aa,physicsProcessBoundaryColliders:()=>pa,physicsProcessGroupSemanticItems:()=>ya,physicsProcessRegionSemanticItem:()=>fa,physicsProcessStageSemanticItems:()=>ma,physicsReferenceEnvelope:()=>Ec,planGauntletPropertyWork:()=>qa,portalRegion:()=>Oo,pressureFieldRegion:()=>Wo,processChrome:()=>Mc,processJourneyRows:()=>Hc,processLaneWalls:()=>Go,processStageLayout:()=>Bo,processStageRegions:()=>Eo,processVolumePolygons:()=>Ro,regionCountsToProjectionRows:()=>jo,replaceGauntletNegative:()=>za,replayStateTransitions:()=>hl,resolveMotionAccessor:()=>ra,resolveMotionAge:()=>sa,resolveMotionVector:()=>ca,routeDependencyTracks:()=>ll,routeSurfaceRegion:()=>zo,sedimentBake:()=>Jc,sedimentHeightfield:()=>Vn,spawnFromTokens:()=>Zc,stageTargetInVolume:()=>Po,updateProcessJourney:()=>Yc}),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")),f=require("react"),m=require("react"),y=require("react/jsx-runtime");function g(e,t){const n=new Set;let i={...e(function(e){const t=e(i);if(function(e){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!0;return!1}(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){if(!e.accessibility)return e;let t=e;if(e.accessibility.colorBlindSafe&&(t={...t,colors:{...t.colors,categorical:b}}),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 b=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],v={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}},w={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}},k={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:b,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 M(e,t){if("light"===t)return v;if("dark"===t)return w;if("high-contrast"===t)return k;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?w:v;return x({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}return x({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}}})}var[S,I]=function(e){let t=null;const n=()=>(t||(t=(0,m.createContext)(null)),t),i=g(e);return[function({children:t,initialState:i}){const r=(0,m.useRef)(i),o=(0,m.useMemo)(()=>g(e,r.current),[]),s=n();return(0,y.jsx)(s.Provider,{value:o,children:t})},(e,t)=>{const r=n(),o=(0,m.useContext)(r)??i,s=(0,m.useRef)(e);s.current=e;const a=(0,m.useRef)({hasValue:!1,value:void 0}),c=(0,m.useCallback)(()=>{const e=s.current(o.getState()),n=a.current;return n.hasValue&&t&&t(n.value,e)?n.value:(a.current={hasValue:!0,value:e},e)},[o,t]),l=(0,m.useCallback)(()=>s.current(o.getState()),[o]);return(0,m.useSyncExternalStore)(o.subscribe,c,l)}]}(e=>({theme:v,setTheme(t){e(e=>({theme:M(e.theme,t)}))}})),j=require("react");var A=require("react"),C=/^var\(\s*(--[^,)]+)(?:\s*,\s*([^)]+))?\s*\)$/,P=new WeakMap,R=0,D=!1,$=null,B=null;function T(e,t){if(!t)return t;const n=C.exec(t);if(!n)return t;const i=e.canvas;if(!i)return n[2]?.trim()||t;!function(){if(D)return;if("undefined"==typeof window||"undefined"==typeof document)return;D=!0;const e=()=>{R++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(e).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"]}),"function"==typeof window.matchMedia)try{$=window.matchMedia("(prefers-color-scheme: dark)"),B=e,"function"==typeof $.addEventListener?$.addEventListener("change",B):"function"==typeof $.addListener&&$.addListener(B)}catch{}}();let r=P.get(i);r&&r.version===R||(r={version:R,map:new Map},P.set(i,r));const o=r.map.get(t);if(void 0!==o)return o;const s=getComputedStyle(i).getPropertyValue(n[1]).trim()||n[2]?.trim()||t;return r.map.set(t,s),s}var E="undefined"==typeof window?f.useEffect:f.useLayoutEffect,N={requestAnimationFrame:e=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(e),cancelAnimationFrame:e=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(e)};function q(e,t,n){return"function"==typeof e?e({size:t,margin:n}):e}function z(e){const t=function(){const[e,t]=(0,j.useState)(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return(0,j.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}(),n=(0,f.useRef)(t);n.current=t;const[i,r]=function(e,t,n){const i=(0,A.useRef)(null),[r,o]=(0,A.useState)(null);return(0,A.useEffect)(()=>{if(!t&&!n)return;const e=i.current;if(!e)return;const r=new ResizeObserver(e=>{for(const t of e){const{width:e,height:n}=t.contentRect;o(t=>t&&t.w===e&&t.h===n?t:{w:e,h:n})}});return r.observe(e),()=>r.disconnect()},[t,n]),[i,[t&&r?r.w:e[0],n&&r?r.h:e[1]]]}(e.sizeProp,e.responsiveWidth,e.responsiveHeight),o=(0,f.useMemo)(()=>({...e.marginDefault,...e.userMargin}),[e.marginDefault,e.userMargin]),s=r[0]-o.left-o.right,a=r[1]-o.top-o.bottom,c=q(e.foregroundGraphics,r,o),l=q(e.backgroundGraphics,r,o),d=I(e=>e.theme),{transition:u,introEnabled:h}=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),m="semiotic-table-"+p.useId(),y=(0,f.useRef)(null),g=(0,f.useRef)(e.frameScheduler??N);g.current=e.frameScheduler??N;const x=(0,f.useRef)(null),b=(0,f.useRef)(!1),v=(0,f.useRef)(()=>{}),w=(0,f.useCallback)(()=>{if(null!==y.current||b.current)return;const e=g.current;let t=!1,n=!1;const i=e.requestAnimationFrame(()=>{t=!0;const e=!n;e&&(b.current=!0),y.current=null,x.current=null;try{v.current()}finally{e&&(b.current=!1)}});n=!0,t||(y.current=i,x.current=e)},[]),k=(0,f.useCallback)(()=>{null!==y.current&&((x.current??g.current).cancelAnimationFrame(y.current),y.current=null,x.current=null)},[]);(0,f.useEffect)(()=>()=>{k()},[k]);const M=(0,f.useRef)(()=>{}),S=(0,f.useRef)(()=>{}),C=(0,f.useRef)(null),P=(0,f.useRef)(null),D=(0,f.useRef)(null),$=(0,f.useCallback)(()=>{const e=C.current;C.current=null,e&&M.current(e)},[]),B=(0,f.useCallback)(e=>{if(C.current={clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType},null===P.current){const e=g.current;let t=!1;const n=e.requestAnimationFrame(()=>{t=!0,P.current=null,D.current=null,$()});t||(P.current=n,D.current=e)}},[$]),T=(0,f.useCallback)(()=>{C.current=null,null!==P.current&&((D.current??g.current).cancelAnimationFrame(P.current),P.current=null,D.current=null),S.current()},[]);(0,f.useEffect)(()=>()=>{C.current=null,null!==P.current&&((D.current??g.current).cancelAnimationFrame(P.current),P.current=null,D.current=null)},[]);const z=e.themeDirtyRef;return E(()=>{z&&(R++,z.current=!0,w())},[d,w,z]),{reducedMotion:t,reducedMotionRef:n,responsiveRef:i,size:r,margin:o,adjustedWidth:s,adjustedHeight:a,resolvedForeground:c,resolvedBackground:l,currentTheme:d,transition:u,introEnabled:h,tableId:m,rafRef:y,renderFnRef:v,scheduleRender:w,cancelRender:k,hoverHandlerRef:M,hoverLeaveRef:S,onPointerMove:B,onPointerLeave:T}}var W=require("react"),F="undefined"!=typeof window?W.useLayoutEffect:W.useEffect,O=()=>()=>{},L=()=>!1,Y=()=>!0;c(require("react")),require("d3-shape");var H=require("d3-shape"),G={circle:H.symbolCircle,square:H.symbolSquare,triangle:H.symbolTriangle,diamond:H.symbolDiamond,star:H.symbolStar,cross:H.symbolCross,wye:H.symbolWye};var X=[40,40],_=[.5,.5];function V(e,t,n,i){if("none"!==e)return"color"===e||null==e?t??i:"accent"===e?n:e}var U=require("react/jsx-runtime");function K(e,t="#4e79a7"){return e&&"string"==typeof e?e:t}function Q(e,t,n){switch(e.type){case"line":{const n=e;if(0===n.path.length)return null;const i="M"+n.path.map(([e,t])=>`${e},${t}`).join("L");return(0,U.jsx)("path",{d:i,fill:"none",stroke:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth||2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity},"line-"+t)}case"area":{const i=e;if(0===i.topPath.length)return null;const r=`M${i.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...i.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`;if(i.clipRect){const e=`${n?n+"-":""}area-clip-${t}`;return(0,U.jsxs)("g",{children:[(0,U.jsx)("defs",{children:(0,U.jsx)("clipPath",{id:e,children:(0,U.jsx)("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})}),(0,U.jsx)("path",{d:r,fill:K(i.style.fill),fillOpacity:i.style.fillOpacity??i.style.opacity??.7,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,clipPath:`url(#${e})`})]},"area-"+t)}return(0,U.jsx)("path",{d:r,fill:K(i.style.fill),fillOpacity:i.style.fillOpacity??i.style.opacity??.7,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth},"area-"+t)}case"point":{const n=e;return(0,U.jsx)("circle",{cx:n.x,cy:n.y,r:n.r,fill:K(n.style.fill),opacity:n.style.opacity??.8,stroke:n.style.stroke,strokeWidth:n.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,H.symbol)(G[i]??H.symbolCircle,Math.max(1,t))()??""}(e.symbolType,e.size,e.path);return(0,U.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?K(e.style.fill):"none",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 r=e.glyph;if(!r?.parts?.length||0>=e.size)return null;const o=function(e,t){const[n,i]=e.viewBox??X,[r,o]=e.anchor??_,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:-r*c,offsetY:-o*l}}(r,e.size);if(0>=o.scale)return null;const s=`translate(${t},${n})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${o.offsetX},${o.offsetY}) scale(${o.scale})`,a=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),c=function(e,t,n=0,i="horizontal"){const[r,o]=e.viewBox??X,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:o*(1-a),width:r,height:o*(a-s)}:{x:r*s,y:0,width:r*(a-s),height:o}:null:{x:0,y:0,width:0,height:0}}(r,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),l=c?function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"s_"+t:t}(i+"-clip"):void 0,d=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),u=t=>r.parts.map((n,i)=>{const r=t?"none"===n.fill?void 0:t:V(n.fill,a,e.accent),o=t?n.stroke&&"none"!==n.stroke?t:void 0:V(n.stroke??"none",a,e.accent);return r||o?(0,U.jsx)("path",{d:n.d,fill:r??"none",stroke:o,strokeWidth:o?n.strokeWidth??1:void 0,strokeLinecap:n.strokeLinecap,strokeLinejoin:n.strokeLinejoin,opacity:n.opacity},i):null});return(0,U.jsxs)("g",{transform:s,opacity:1===d?void 0:d,children:[c&&l&&(0,U.jsx)("clipPath",{id:l,children:(0,U.jsx)("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&e.ghostColor?(0,U.jsx)("g",{children:u(e.ghostColor)}):null,c&&l?(0,U.jsx)("g",{clipPath:`url(#${l})`,children:u()}):u()]},i)}(e,e.x,e.y,`${n??""}glyph-${e.pointId??t}`);case"rect":{const n=e;return(0,U.jsx)("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:K(n.style.fill),opacity:n.style.opacity,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth},"rect-"+t)}case"heatcell":{const n=e;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),[i,r,o]=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),s=.299*i+.587*r+.114*o>128?"#000":"#fff",a=Math.max(10,Math.min(16,.3*Math.min(n.w,n.h)));return(0,U.jsxs)("g",{children:[(0,U.jsx)("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill}),(0,U.jsx)("text",{x:n.x+n.w/2,y:n.y+n.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:a+"px",children:e})]},"heatcell-"+t)}return(0,U.jsx)("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:n.fill},"heatcell-"+t)}case"candlestick":{const n=e,i=Math.min(n.openY,n.closeY),r=Math.max(Math.abs(n.openY-n.closeY),1),o=n.isUp?n.upColor:n.downColor;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{x1:n.x,y1:n.highY,x2:n.x,y2:n.lowY,stroke:n.wickColor,strokeWidth:n.wickWidth}),(0,U.jsx)("rect",{x:n.x-n.bodyWidth/2,y:i,width:n.bodyWidth,height:r,fill:o,stroke:o,strokeWidth:1})]},"candle-"+t)}default:return null}}var Z="undefined"==typeof window||"undefined"==typeof document;var J=c(require("react")),ee=require("react/jsx-runtime"),te={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 ne(e,t){return"function"==typeof t?t(e):e[t]}function ie(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 re(e={}){const{fields:t,title:n,format:i,style:r={},className:o=""}=e;return e=>{if(!e||"object"!=typeof e)return null;let s;const a=[];if(n){const t=ne(e,n);s=ie(t,i)}if(t&&t.length>0)t.forEach(t=>{let n,r,o;"string"==typeof t?(n=t,r=t,o=i):(n=t.label,r=t.accessor||t.key||"",o=t.format||i);const s=ne(e,r);a.push({label:n,value:ie(s,o)})});else if(!n){const t=["value","y","name","id","label"];for(const n of t)if(void 0!==e[n]){s=ie(e[n],i);break}if(!s){const t=Object.keys(e).filter(e=>!e.startsWith("_"));t.length>0&&(s=ie(e[t[0]],i))}}const c={...te,...r};return(0,ee.jsxs)("div",{className:("semiotic-tooltip "+o).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 oe(e){if(!0!==e){if("function"==typeof e){const t=e;return e=>{let n=Array.isArray(i=!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)?e.data??{}:e)?i[0]:i;var i;("node"===e?.nodeOrEdge&&"number"==typeof n?.x0&&"number"==typeof n?.x1||"edge"===e?.nodeOrEdge&&"number"==typeof n?.sankeyWidth)&&n.data&&"object"==typeof n.data&&(n=n.data);const r=t(n);return null==r?null:(0,ee.jsx)("div",{className:"semiotic-tooltip",style:te,children:r})}}return!1!==e&&void 0!==e&&("object"==typeof e&&null!==e&&("fields"in e||"title"in e)?re(e):re())}}var se=require("react/jsx-runtime");function ae({x:e,y:t,containerWidth:n,containerHeight:i,margin:r,children:o,className:s="stream-frame-tooltip",zIndex:a=1}){const c=Number.isFinite(e)&&Number.isFinite(t),l=J.useRef(null),[d,u]=J.useState(null);J.useLayoutEffect(()=>{const e=l.current;if(!e)return;const t=e.getBoundingClientRect();u(e=>e&&e.width===t.width&&e.height===t.height?e:{width:t.width,height:t.height})},[o,s,n,i]);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(!J.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}(o),f=p?null:te;return c?(0,se.jsx)("div",{ref:l,className:p?s:(s+" semiotic-tooltip").trim(),style:{...f||{},position:"absolute",left:r.left+e,top:r.top+t,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:o}):null}var ce={names:["--semiotic-bg","--surface-1","--surface-0"],fallback:"#f8fafc"},le={names:["--semiotic-border","--surface-3"],fallback:"#334155"},de={names:["--semiotic-danger","--viz-4"],fallback:"#dc2626"},ue={names:["--semiotic-focus","--accent","--viz-9"],fallback:"#f97316"},he={names:["--semiotic-grid","--surface-3"],fallback:"#cbd5e1"},pe={names:["--semiotic-primary","--accent","--viz-5"],fallback:"#0ea5e9"},fe={names:["--semiotic-success","--viz-2"],fallback:"#22c55e"},me={names:["--semiotic-text","--text-primary"],fallback:"#0f172a"},ye={names:["--semiotic-text-secondary","--text-secondary"],fallback:"#475569"},ge={names:["--semiotic-warning","--viz-9","--viz-3"],fallback:"#f97316"};function xe(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 T(e,t)??t}return t.fallback}function be(e,t){const n=Math.max(0,Math.min(1,t)),i=e.trim(),r=i.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i);if(r){const[,e,t,i]=r;return be(`#${e}${e}${t}${t}${i}${i}`,n)}const o=i.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(o){const[,e,t,i]=o;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 ve=c(require("react")),we=require("d3-scale"),ke=c(require("react")),Me=require("react/jsx-runtime"),Se=16,Ie=6,je=10,Ae=22,Ce={fill:(e,t)=>(0,Me.jsx)("rect",{style:e,width:t,height:t}),line:(e,t)=>(0,Me.jsx)("line",{style:e,x1:0,y1:0,x2:t,y2:t})};function Pe(e,t,n,i,r){let o;return o="function"==typeof n?n(e):(0,Ce[n])(i(e,t),r),o}function Re({swatchSize:e}){return(0,Me.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 De(e,t,n){return n&&n.size>0?n.has(e.label)?1:.3:null!=t?e.label===t?1:.3:1}var $e=(e,t,n,i,r,o,s,a,c,l,d)=>{const{type:u="fill",styleFn:h,items:p}=e,f=[];let m=0;const y=!(!t&&!n),g="isolate"===l||void 0===l&&null!=r,{swatchSize:x,labelGap:b,rowHeight:v}=d;return p.forEach((e,l)=>{const d=Pe(e,l,u,h,x),w=De(e,i,r),k=r&&r.size>0&&r.has(e.label);f.push((0,Me.jsxs)("g",{transform:`translate(0,${m})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:y?a===o&&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,Me.jsx)("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:x+b+2+7*e.label.length,height:x+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),d,k&&(0,Me.jsx)(Re,{swatchSize:x}),(0,Me.jsx)("text",{y:x/2,x:x+b,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+l)),m+=v}),f},Be=({legendGroups:e,width:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:o,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:c,legendInteraction:l,metrics:d})=>{let u=24;const h=[];return e.forEach((e,p)=>{u+=5,h.push((0,Me.jsx)("line",{stroke:"gray",x1:0,y1:u,x2:t,y2:u},"legend-top-line legend-symbol-"+p)),u+=8,e.label&&(u+=16,h.push((0,Me.jsx)("text",{y:u,className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label},"legend-text-"+p)),u+=8),h.push((0,Me.jsx)("g",{className:"legend-item",transform:`translate(0,${u})`,children:$e(e,n,i,r,o,s,a,p,c,l,d)},"legend-group-"+p)),u+=e.items.length*d.rowHeight+8}),h},Te=({legendGroups:e,height:t,width:n,customClickBehavior:i,customHoverBehavior:r,highlightedCategory:o,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:c,onFocusedIndexChange:l,legendInteraction:d,metrics:u})=>{let h=0;const p=[];e.forEach((e,t)=>{let f=0;e.label&&(f+=16);const m=((e,t,n,i,r,o,s,a,c,l,d,u)=>{const{type:h="fill",styleFn:p,items:f}=e,m=[],{swatchSize:y,labelGap:g,itemGap:x,rowHeight:b,align:v}=d,w=!(!t&&!n),k="isolate"===l||void 0===l&&null!=r,M=f.map(e=>y+g+7*e.label.length),S=[];let I=0,j=0;M.forEach((e,t)=>{const n=0===j?e:j+x+e;u&&u>0&&j>0&&n>u?(S.push({start:I,end:t,width:j}),I=t,j=e):j=n}),f.length>0&&S.push({start:I,end:f.length,width:j}),S.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=f[u],v=Pe(e,u,h,p,y),S=De(e,i,r),I=r&&r.size>0&&r.has(e.label);m.push((0,Me.jsxs)("g",{transform:`translate(${d},${l*b})`,onClick:t?()=>t(e):void 0,onMouseEnter:n?()=>n(e):void 0,onMouseLeave:n?()=>n(null):void 0,tabIndex:w?a===o&&u===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?I||!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)+f.length)%f.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:S,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&(0,Me.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,I&&(0,Me.jsx)(Re,{swatchSize:y}),(0,Me.jsx)("text",{y:y/2,x:y+g,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:e.label})]},"legend-item-"+u)),d+=M[u]+x}});const A=Math.max(0,...S.map(e=>e.width)),C=S.length;return{items:m,offset:A,totalRows:C,totalHeight:C*b}})(e,i,r,o,s,a,c,t,l,d,u,u.maxWidth??n);f+=m.offset+5,p.push({label:e.label,...m,offset:f,totalRows:m.totalRows,totalHeight:m.totalHeight}),h+=f+12});const f=u.maxWidth??n;let m=h>f?0:"center"===u.align?Math.max(0,(f-h)/2):"end"===u.align?Math.max(0,f-h):0;const y=[];return p.forEach((n,i)=>{const r=e[i];r.label&&(y.push((0,Me.jsx)("text",{transform:`translate(${m},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:r.label},"legend-text-"+i)),m+=16),y.push((0,Me.jsx)("g",{className:"legend-item",transform:`translate(${m},0)`,children:n.items},"legend-group-"+i)),m+=n.offset+5,e[i+1]&&y.push((0,Me.jsx)("line",{stroke:"gray",x1:m,y1:-8,x2:m,y2:(n.totalHeight||t)+0+8},"legend-top-line legend-symbol-"+i)),m+=12}),(0,Me.jsx)("g",{children:y})};function Ee({config:e,orientation:t="vertical",width:n=100}){const{colorFn:i,domain:r,label:o,format:s}=e,a=s||(e=>Math.round(100*e)/100+""),c="grad-legend-"+ke.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,Me.jsx)("stop",{offset:100*t+"%",stopColor:i(r[0]+t*(r[1]-r[0]))},e))}return(0,Me.jsxs)("g",{"aria-label":o||"Gradient legend",children:[(0,Me.jsx)("defs",{children:(0,Me.jsx)("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),o&&(0,Me.jsx)("text",{x:s+t/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:o}),(0,Me.jsx)("rect",{x:s,y:0,width:t,height:e,fill:`url(#${c})`,rx:2}),(0,Me.jsx)("text",{x:s,y:e+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(r[0])}),(0,Me.jsx)("text",{x:s+t,y:e+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(r[1])})]})}const l=[];for(let e=0;64>=e;e++){const t=e/64;l.push((0,Me.jsx)("stop",{offset:100*t+"%",stopColor:i(r[1]-t*(r[1]-r[0]))},e))}return(0,Me.jsxs)("g",{"aria-label":o||"Gradient legend",children:[o&&(0,Me.jsx)("text",{x:7,y:-6,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:o}),(0,Me.jsx)("defs",{children:(0,Me.jsx)("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),(0,Me.jsx)("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),(0,Me.jsx)("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(r[1])}),(0,Me.jsx)("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(r[0])})]})}function Ne(e){const{legendGroups:t,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:o,legendInteraction:s,title:a="Legend",width:c=100,height:l=20,orientation:d="vertical",legendLayout:u}=e,h=function(e){const t=Math.max(1,e?.swatchSize??Se),n=Math.max(t,e?.rowHeight??Ae);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??Ie),itemGap:Math.max(0,e?.itemGap??je),rowHeight:n,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}(u),[p,f]=ke.useState(0),[m,y]=ke.useState(0),g=ke.useCallback((e,t)=>{f(e),y(t)},[]),x="vertical"===d?Be({legendGroups:t||[],width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:o,focusedGroupIndex:p,focusedItemIndex:m,onFocusedIndexChange:g,legendInteraction:s,metrics:h}):Te({legendGroups:t||[],title:a,height:l,width:c,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:o,focusedGroupIndex:p,focusedItemIndex:m,onFocusedIndexChange:g,legendInteraction:s,metrics:h}),b=!(!n&&!i);return(0,Me.jsxs)("g",{role:b?"listbox":void 0,"aria-multiselectable":!(!b||"isolate"!==s&&(void 0!==s||null==o))||void 0,"aria-label":"Chart legend",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[void 0!==a&&""!==a&&"vertical"===d&&(0,Me.jsx)("text",{className:"legend-title",y:16,x:c/2,textAnchor:"middle",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),x]})}function qe(e){return"object"==typeof e&&null!==e&&"legendGroups"in e}var ze=require("react/jsx-runtime");function We(e){const{legend:t,totalWidth:n,totalHeight:i,margin:r,legendPosition:o="right",legendLayout:s,title:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendInteraction:h}=e;if(!t)return null;const p="top"===o||"bottom"===o,f=!!a,m=Math.max(0,n-r.left-r.right),y=Math.max(1,p?s?.maxWidth??m:100);let g,x;return"left"===o?(g=Math.max(4,r.left-y-10),x=r.top):"top"===o?(g=r.left,x=f?32:8):"bottom"===o?(g=r.left,x=i-r.bottom+38):(g=n-r.right+10,x=r.top),(0,ze.jsx)("g",{transform:`translate(${g}, ${x})`,children:(b=t,"object"==typeof b&&null!==b&&"gradient"in b?(0,ze.jsx)(Ee,{config:t.gradient,orientation:p?"horizontal":"vertical",width:y}):qe(t)?(0,ze.jsx)(Ne,{legendGroups:t.legendGroups,title:"",width:y,orientation:p?"horizontal":"vertical",legendLayout:s,customHoverBehavior:c,customClickBehavior:l,highlightedCategory:d,isolatedCategories:u,legendInteraction:h}):t)});var b}var Fe=require("react/jsx-runtime"),Oe={secondary:0,primary:3},Le=1,Ye=2,He=.6,Ge="0.88em",Xe=.95,_e=.72,Ve=.06,Ue=".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}}",Ke=".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}";function Qe(e){return!0===e?._annotationDeferred}function Ze(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Je(e){const t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function et(e){return Math.max(_e,Xe-e*Ve)}var tt=c(require("react")),nt=require("react/jsx-runtime");function it(e,t=120,n=8){if(!e)return[];const i=Math.max(1,Math.floor(t/n)),r=e.split(/\s+/),o=[];let s="";for(const e of r)s&&s.length+1+e.length>i?(o.push(s),s=e):s=s?`${s} ${e}`:e;return s&&o.push(s),o}function rt(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 ot(e,t,n,i){if(!e)return(0,nt.jsx)("g",{className:"annotation-note"});const{label:r,title:o,orientation:s,align:a,wrap:c=120,noWrap:l}=e;if(!r&&!o)return(0,nt.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,f=o?l?[o]:it(o,c):[],m=r?l?[r]:it(r,c):[],y="leftRight"===d?"end"===h?-4:4:0;let g=0;const x=[],b=i||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";e.useHTML||e.html?x.push((0,nt.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,(f.length+m.length)*p+(o&&r?2:0))+p,style:{overflow:"visible"},children:(0,nt.jsxs)("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:b,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:l?"nowrap":"normal",wordBreak:"break-word"},children:[o&&(0,nt.jsx)("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:o}),r&&(0,nt.jsx)("div",{className:"annotation-note-label",children:r})]})},"annotation-note-html")):(f.length>0&&(x.push((0,nt.jsx)("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:f.map((e,t)=>(0,nt.jsx)("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-title")),g=f.length*p),m.length>0&&x.push((0,nt.jsx)("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:g,children:m.map((e,t)=>(0,nt.jsx)("tspan",{x:y,dy:0===t?0:p,children:e},t))},"annotation-note-label")));let v=null;if((o||r)&&(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,nt.jsx)("line",{className:"note-line",x1:t,x2:n,y1:0,y2:0,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}else{const e=(f.length+m.length)*p+(m.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,nt.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,f.length+m.length-1)*p;let k=0;return"topBottom"===d?k=0>n?-(w+2):18:"leftRight"===d&&(k="middle"===u?-(w+p+(m.length>0&&f.length>0?2:0))/2+8:"bottom"===u||0>n?-(w+2):18),(0,nt.jsxs)("g",{className:"annotation-note",transform:`translate(${t},${n})`,children:[(0,nt.jsx)("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function st(e,t,n,i,r){const o=[];switch(e){case"callout-circle":{const e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&o.push((0,nt.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)&&o.push((0,nt.jsx)("rect",{width:e,height:i,fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":t?.custom&&o.push(...Array.isArray(t.custom)?t.custom:[t.custom]);break;case"xy-threshold":{const e=i||0,s=r||0;if(void 0!==t?.x){const i=(t.x||0)-e;o.push((0,nt.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;o.push((0,nt.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?o.push((0,nt.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||o.push((0,nt.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&&o.push((0,nt.jsx)("path",{d:rt(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:n||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return(0,nt.jsx)("g",{className:"annotation-subject",children:o})}function at(e,t,n,i,r,o){const s=[];let a=0,c=0;if("callout-circle"!==r&&"label"!==r||!o?.radius){if("callout-rect"===r&&o){const n=o.width||0,i=o.height||0;if(n>0||i>0){const r=n/2,o=i/2,s=e-r,l=t-o;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=r+s*h,c=o+l*h}}}else if("bracket"===r&&o){const e=o.width,t=o.height,n=o.depth||30;void 0!==e?(a=e/2,c=n):void 0!==t&&(a=n,c=t/2)}}else{const n=(o.radius||0)+(o.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 r=i||"var(--semiotic-text-secondary, currentColor)",o="curve"===n?.type;let d=Math.atan2(t-c,e-a);if(o){const i=(a+e)/2,o=(c+t)/2,u=-(t-c)/l,h=(e-a)/l,p=(n?.curve??.25)*l,f=i+u*p,m=o+h*p;s.push((0,nt.jsx)("path",{className:"connector-curve",d:`M${a},${c}Q${f},${m} ${e},${t}`,fill:"none",stroke:r},"connector-line")),d=Math.atan2(m-c,f-a)}else s.push((0,nt.jsx)("line",{x1:a,y1:c,x2:e,y2:t,stroke:r},"connector-line"));if("arrow"===n?.end){const e=10,t=16/180*Math.PI;s.push((0,nt.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:r,stroke:"none"},"connector-arrow"))}}return(0,nt.jsx)("g",{className:"annotation-connector",children:s})}function ct(e){const{x:t=0,y:n=0,dx:i,dy:r,nx:o,ny:s,note:a,connector:c,subject:l,type:d,color:u,className:h,disable:p,opacity:f,strokeDasharray:m,events:y={},"data-testid":g}=e,x=Array.isArray(t)?t[0]??0:t,b=Array.isArray(n)?n[0]??0:n,v=new Set(Array.isArray(p)?p:[]);let w=i||0,k=r||0;null!=o&&(w=o-x),null!=s&&(k=s-b);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,nt.jsxs)("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":g,...null!=f&&{opacity:f},...m&&{strokeDasharray:m},...y,children:[!v.has("connector")&&at(w,k,c,u,M,l),!v.has("subject")&&st(M,l,u,x,b),!v.has("note")&&ot(a,w,k,u)]})}function lt(e){const{noteData:t}=e,{screenCoordinates:n}=t,i="string"==typeof t.type?t.type:"label",r=t.eventListeners||t.events||{};if(t.coordinates&&n){const e=t.nx||n[0][0]+(t.dx??0),r=t.ny||n[0][1]+(t.dy??0),o=n.map((n,o)=>{const s=Object.assign({},t,{note:0===o?t.note:{label:""},x:n[0],y:n[1],nx:e,ny:r});return(0,nt.jsx)(ct,{"data-testid":"semiotic-annotation",...s,type:i},"multi-annotation-"+o)});return(0,nt.jsx)("g",{children:o})}const o=t.note||{title:"none",label:t.label},s=`${o.label}-${o.title}-${t.i}`;return(0,nt.jsx)(ct,{"data-testid":"semiotic-annotation",events:r,...t,type:i},s)}var dt=require("d3-hierarchy"),ut=require("d3-shape"),ht=c(require("regression"));function pt(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 ft(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 mt(e){return null==e?null:e+""}function yt(e,t,n){return t.stickyPositionCache?.set(e,n),n}function gt(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 r=n.pointNodes[i];if(r.pointId===e.pointId)return yt(t,n,{x:r.x,y:r.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,r=e.scales?.y??e.scales?.value;if(!i||!r)return null;const o=n[e.xAccessor||"x"],s=n[e.yAccessor||"y"];return null==o||null==s?null:{x:i(o),y:r(s)}}(n);return i?yt(t,n,i):null}if("semantic"===i){const i=function(e,t,n){const i=function(e){return mt(e.provenance?.stableId??e.stableId)}(e);if(!i)return null;const r=n.pointNodes?.find(e=>mt(e.pointId)===i);if(r)return yt(t,n,{x:r.x,y:r.y});const o=n.data?.find(e=>function(e){return mt(e.stableId??e.id??e.provenance?.stableId)}(e)===i);if(!o)return null;const s=pt(o,n),a=ft(o,n);return null==s||null==a?null:yt(t,n,{x:s,y:a})}(e,t,n);if(i)return i}let r=null,o=null;if(null!=e.pointId&&n.pointNodes){const t=n.pointNodes.find(t=>t.pointId===e.pointId);t&&(r=t.x,o=t.y)}if(null!=r&&null!=o||(r=pt(e,n),o=ft(e,n)),null!=r&&null!=o)return yt(t,n,{x:r,y:o});if("sticky"===i){const e=n.stickyPositionCache?.get(t);if(e)return e}return null}function xt(e,t,n,i=50){return!(-i>e||e>(n.width||0)+i||-i>t||t>(n.height||0)+i)}function bt(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 vt=require("react/jsx-runtime"),wt={linear:ut.curveLinear,monotoneX:ut.curveMonotoneX,monotoneY:ut.curveMonotoneY,step:ut.curveStep,stepAfter:ut.curveStepAfter,stepBefore:ut.curveStepBefore,basis:ut.curveBasis,cardinal:ut.curveCardinal,catmullRom:ut.curveCatmullRom};var kt=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function Mt(e){return!!e&&"object"==typeof e&&kt.has(function(e){return"string"==typeof e?.type?e.type:""}(e))}new Set(["label","callout","callout-circle","callout-rect"]);var St=2e4,It=1;function jt(e){return"primary"===e?.emphasis||!0===e?.defensive}function At(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:St))):1/0}function Ct(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 Pt=32,Rt=6,Dt=4,$t=8,Bt=72,Tt=30,Et=-30,Nt=8,qt=480,zt=3;var Wt={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function Ft(e){if(!Ot(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 Ot(e){return Mt(e)}function Lt(e,t){if(!e)return[];const n=Math.max(1,Math.floor(t/7)),i=e.split(/\s+/).filter(Boolean),r=[];let o="";for(const e of i)o&&o.length+e.length+1>n?(r.push(o),o=e):o=o?`${o} ${e}`:e;return o&&r.push(o),r}function Yt(e,t,n,i,r){const o=e+n,s=t+i;return Math.abs(n)>Math.abs(i)?{x:0>n?o-r.width-4:o+4,y:0>i?s-r.height:s,width:r.width,height:r.height}:{x:0>n?o-r.width:o,y:0>i?s-r.height-4:s+4,width:r.width,height:r.height}}function Ht(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Gt(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 Xt(e,t,n,i,r,o,s,a){const c=Ht(e,s);let l=.4*Math.hypot(t.dx,t.dy)+80*function(e,t,n,i){const r=Math.max(0,i-e.x),o=Math.max(0,i-e.y);return(r+Math.max(0,e.x+e.width-(t-i)))*e.height+(o+Math.max(0,e.y+e.height-(n-i)))*e.width}(c,r,o,a);for(const e of n)l+=12*Gt(c,e);for(const e of i)l+=4*Gt(c,e);return l}function _t(e){const{annotations:t,context:n,defaultOffset:i=Pt,notePadding:r=Rt,markPadding:o=Dt,edgePadding:s=$t,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=Bt,density:d,progressiveDisclosure:u=!1,redundantCues:h=!1,responsive:p,mobile:f,cohesion:m,audience:y}=e,g=n.width||0,x=n.height||0,b="object"==typeof f?f:{},v=b.breakpoint??qt,w=!!f&&v>=g,k=w&&!1!==b.preferShortText?t.map(Ft):t,M=w&&!d?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:d,S=u||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),I=w&&!p?b.responsive??{minWidth:v}:p,j=w&&!m?b.cohesion:m;if(0===k.length||0>=g||0>=x)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,o);let P=!1;const R=k.map((e,t)=>{if(!Ot(e))return e;const o=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 r=e.coordinates,o=n.scales?.geoProjection;if(Array.isArray(r)&&r.length>=2&&o){const e=r[0],t=r[1];if("number"==typeof e&&"number"==typeof t){const n=o([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?gt(e,t,n):{x:e.x,y:e.y}}(e,t,n);if(!o)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=[...Lt("string"==typeof e.title?e.title:void 0,t),...Lt("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:Tt,dy:Et}}(e);return A.push(Ht(Yt(o.x,o.y,"number"==typeof e.dx?e.dx:t.dx,"number"==typeof e.dy?e.dy:t.dy,d),r)),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=Xt(Yt(o.x,o.y,e.dx,e.dy,d),e,A,C,g,x,r,s);p>t&&(h=e,p=t)}if(!h)return e;const f=Ht(Yt(o.x,o.y,h.dx,h.dy,d),r);A.push(f);const m=Math.hypot(h.dx,h.dy),y=c&&m>=l&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return P=!0,{...e,dx:h.dx,dy:h.dy,...y?{connector:y}:{}}}),D=P?R:k.slice();let $=D;if(h){let e=!1;const t=D.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)<Nt?e:{...e,_redundantConnector:!0}}(t);return n!==t&&(e=!0),n});$=e?t:D}{let e=!1;const t=$.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?Wt[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 r=[n,i].filter(Boolean).join(" · "),o="string"==typeof e.label?e.label:"";return o.includes(`(${r})`)?e:{...e,label:o?`${o} (${r})`:`(${r})`}}(t);return n!==t&&(e=!0),n});$=e?t:$}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 zt;const n=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===n.length?zt: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??At(g,x,e))*t))},{deferred:i}=function(e){const{annotations:t,width:n,height:i}=e,r=Math.max(0,e.minVisible??It),o=At(n,i,e),s=t.map((e,t)=>{return{annotation:e,index:t,note:(n=e,Mt(n))};var n}),a=s.filter(e=>e.note);if(0===a.length||o>=a.length)return{visible:t.slice(),deferred:[],budget:o};const c=a.filter(e=>jt(e.annotation)),l=a.filter(e=>!jt(e.annotation)).sort((e,t)=>Ct(t.annotation)-Ct(e.annotation)||e.index-t.index),d=Math.min(l.length,Math.max(Math.max(0,o-c.length),Math.max(0,r-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:o}}({annotations:$,width:g,height:x,...n});for(const e of i)B.add(e)}if(I&&("object"==typeof I&&"number"==typeof I.minWidth?I.minWidth:qt)>=g)for(const e of $)Ot(e)&&"secondary"===e.emphasis&&B.add(e);if(B.size>0)for(const e of $)!0===e?.defensive&&B.delete(e);let T;return T=0===B.size?$:S?$.map(e=>B.has(e)?{...e,_annotationDeferred:!0}:e):$.filter(e=>!B.has(e)),j?function(e,t){let n=!1;const i=e.map(e=>Ot(e)?"blended"===e.cohesion||"layer"===e.cohesion?e:(n=!0,{...e,cohesion:t}):e);return n?i:e}(T,j):T}var Vt=require("react/jsx-runtime");function Ut(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function Kt(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,Ut(e))}))}function Qt(e){const{width:t,height:n,pointNodes:i=[],data:r}=e;return{scales:{x:(0,we.scaleLinear)().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:(0,we.scaleLinear)().domain([0,Math.max(1,n)]).range([0,Math.max(1,n)])},width:t,height:n,frameType:"network",pointNodes:i,data:r,xAccessor:"x",yAccessor:"y"}}function Zt(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:e.bodyId+""}):e}function Jt(e){const{width:t,height:n,totalWidth:i,totalHeight:r,margin:o,title:s,legend:a,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u,legendPosition:h="right",legendLayout:p,pointNodes:f=[],annotations:m,autoPlaceAnnotations:y,svgAnnotationRules:g,children:x}=e,b=ve.useMemo(()=>Zt(m),[m]),v=ve.useMemo(()=>Qt({width:t,height:n,pointNodes:f}),[n,f,t]),w=ve.useMemo(()=>b&&y?_t({annotations:b,context:v,..."object"==typeof y?y:{}}):b,[v,y,b]),k=ve.useMemo(()=>function(e,t,n){switch(e.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const i=gt(e,t,n);if(!i)return null;const{x:r,y:o}=i;if(!xt(r,o,n))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,vt.jsx)(lt,{noteData:{x:r,y:o,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-"+t)}case"x-threshold":{const i=pt(null!=e.value?{...e,x:e.value}:e,n);if(null==i)return null;const r=e.color||"#f97316",o=e.labelPosition||"top";let s;s="bottom"===o?(n.height||0)-4:"center"===o?(n.height||0)/2:12;const a=i>.6*(n.width||0),c=a?i-4:i+4,l=a?"end":"start";return(0,vt.jsxs)("g",{opacity:e.opacity,children:[(0,vt.jsx)("line",{x1:i,y1:0,x2:i,y2:n.height||0,stroke:r,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,vt.jsx)("text",{x:c,y:s,textAnchor:l,fill:r,fontSize:12,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"y-threshold":{const i=ft(null!=e.value?{...e,y:e.value}:e,n);if(null==i)return null;const r=e.color||"#f97316",o=e.labelPosition||"right";let s,a;return"left"===o?(s=4,a="start"):"center"===o?(s=(n.width||0)/2,a="middle"):(s=(n.width||0)-4,a="end"),(0,vt.jsxs)("g",{opacity:e.opacity,children:[(0,vt.jsx)("line",{x1:0,y1:i,x2:n.width||0,y2:i,stroke:r,strokeWidth:e.strokeWidth||1.5,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,vt.jsx)("text",{x:s,y:i-4,textAnchor:a,fill:r,fontSize:12,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"enclose":{const i=(e.coordinates||[]).map(e=>({x:pt({...e,type:"point"},n),y:ft({...e,type:"point"},n),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>i.length)return null;const r=(0,dt.packEnclose)(i),o=e.padding||10;return(0,vt.jsxs)("g",{children:[(0,vt.jsx)("circle",{cx:r.x,cy:r.y,r:r.r+o,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,vt.jsx)("text",{x:r.x,y:r.y-r.r-o-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,children:e.label})]},"ann-"+t)}case"rect-enclose":{const i=(e.coordinates||[]).map(e=>({x:pt({...e,type:"point"},n),y:ft({...e,type:"point"},n)})).filter(e=>null!=e.x&&null!=e.y);if(2>i.length)return null;const r=e.padding||10,o=i.map(e=>e.x),s=i.map(e=>e.y),[a,c]=bt(o),[l,d]=bt(s),u=a-r,h=c+r,p=l-r;return(0,vt.jsxs)("g",{children:[(0,vt.jsx)("rect",{x:u,y:p,width:h-u,height:d+r-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,vt.jsx)("text",{x:(u+h)/2,y:p-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,children:e.label})]},"ann-"+t)}case"highlight":{const i=n.data||[],r="function"==typeof e.filter?i.filter(e.filter):e.field&&null!=e.value?i.filter(t=>t[e.field]===e.value):[],o={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return(0,vt.jsx)("g",{children:r.map((t,i)=>{const r=pt(t,n),s=ft(t,n);if(null==r||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||o;return(0,vt.jsx)("circle",{cx:r,cy:s,r:a,...c},"hl-"+i)})},"ann-"+t)}case"bracket":{const i=pt(e,n),r=ft(e,n);return(0,vt.jsx)(lt,{noteData:{x:i??0,y:r??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-"+t)}case"trend":{const i=n.data||[];if(2>i.length)return null;const r=n.xAccessor||"x",o=n.yAccessor||"y",s="ordinal"===n.frameType,a="horizontal"===n.projection,c=s?r:null,l=s?o:null;let d;const u=[],h=new Map;if(s&&c&&l){for(const e of i){const t=e[c];if(null==t)continue;const n=t+"";h.has(n)||(h.set(n,u.length),u.push(n))}d=i.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=i.map(e=>[e[r],e[o]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>d.length)return null;const p=n.scales?.x??n.scales?.time,f=n.scales?.y??n.scales?.value;if(!p||!f)return null;const m=e=>t=>{const n=Math.max(0,Math.floor(t)),i=Math.min(u.length-1,n+1),r=t-n,o=e(u[n]);return o+(e(u[i])-o)*r},y=p,g=f;let x;if(s)if(a){const e=m(g);x=(t,n)=>[y(n),e(t)]}else{const e=m(y);x=(t,n)=>[e(t),g(n)]}else x=(e,t)=>[y(e),g(t)];const b=e.method||"linear";let v;v="loess"===b?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]),r=i.map(e=>e[0]),o=i.map(e=>e[1]),s=Math.max(2,Math.ceil(t*n)),a=[];for(let e=0;n>e;e++){const t=r[e],i=r.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,f=0;for(let e=0;n>e;e++){const t=l[e];0!==t&&(d+=t,u+=t*r[e],h+=t*o[e],p+=t*r[e]*r[e],f+=t*r[e]*o[e])}if(0===d){a.push([t,o[e]]);continue}const m=d*p-u*u;if(1e-12>Math.abs(m))a.push([t,h/d]);else{const e=(d*f-u*h)/m;a.push([t,(h-e*u)/d+e*t])}}return a}(d,e.bandwidth??.3):("polynomial"===b?ht.default.polynomial(d,{order:e.order||2}):ht.default.linear(d)).points;const w=v.map(([e,t])=>{const[n,i]=x(e,t);return`${n},${i}`}).join(" "),k=e.color||"#6366f1",M=v[v.length-1],[S,I]=x(M[0],M[1]);return(0,vt.jsxs)("g",{children:[(0,vt.jsx)("polyline",{points:w,fill:"none",stroke:k,strokeWidth:e.strokeWidth||2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&(0,vt.jsx)("text",{x:S+4,y:I-4,fill:k,fontSize:11,children:e.label})]},"ann-"+t)}case"band":{const i=n.scales?.y??n.scales?.value,r=i?.(e.y0)??0,o=i?.(e.y1)??(n.height||0);return(0,vt.jsxs)("g",{opacity:e.opacity,children:[(0,vt.jsx)("rect",{x:0,y:Math.min(r,o),width:n.width||0,height:Math.abs(o-r),fill:e.fill||"var(--semiotic-primary, #6366f1)",fillOpacity:e.fillOpacity||.1}),e.label&&(0,vt.jsx)("text",{x:(n.width||0)-4,y:Math.max(Math.min(r,o),0)+13,textAnchor:"end",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"x-band":{const i=n.scales?.x??n.scales?.time,r=null!=e.x0&&i?i(e.x0):null,o=null!=e.x1&&i?i(e.x1):null;return null==r||null==o?null:(0,vt.jsxs)("g",{opacity:e.opacity,children:[(0,vt.jsx)("rect",{x:Math.min(r,o),y:0,width:Math.abs(o-r),height:n.height||0,fill:e.fill||e.color||"var(--semiotic-primary, #6366f1)",fillOpacity:e.fillOpacity??.1}),e.label&&(0,vt.jsx)("text",{x:Math.min(r,o)+4,y:13,textAnchor:"start",fill:e.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",stroke:"var(--semiotic-bg, #ffffff)",strokeWidth:3,paintOrder:"stroke",children:e.label})]},"ann-"+t)}case"envelope":{const i=n.data||[];if(2>i.length)return null;const r=n.xAccessor||"x",o=n.scales?.x??n.scales?.time,s=n.scales?.y??n.scales?.value;if(!o||!s)return null;const a=e.upperAccessor||"upperBounds",c=e.lowerAccessor||"lowerBounds",l=e.filter,d=i.filter(e=>null!=e[a]&&null!=e[c]&&!(l&&!l(e))).sort((e,t)=>e[r]-t[r]);if(2>d.length)return null;const u=wt[n.curve||"linear"]||ut.curveLinear,h=(0,ut.area)().x(e=>o(e[r])).y0(e=>s(e[c])).y1(e=>s(e[a])).curve(u)(d);if(!h)return null;const p=e.fill||"#6366f1";return(0,vt.jsxs)("g",{children:[(0,vt.jsx)("path",{d:h,fill:p,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&d.length>0&&(0,vt.jsx)("text",{x:o(d[d.length-1][r])+4,y:s(d[d.length-1][a])-4,fill:p,fontSize:11,children:e.label})]},"ann-"+t)}case"anomaly-band":{const i=n.data||[];if(2>i.length)return null;const r=n.yAccessor||"y",o=n.scales?.x??n.scales?.time,s=n.scales?.y??n.scales?.value;if(!o||!s)return null;const a=i.map(e=>e[r]).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,f=e.fill||"#6366f1",m=e.fillOpacity??.1,y=e.anomalyColor||"#ef4444",g=e.anomalyRadius??6,x=s(c+u*d),b=s(h),v=i.filter(e=>{const t=e[r];return null!=t&&Math.abs(t-c)>u*d});return(0,vt.jsxs)("g",{children:[p&&(0,vt.jsx)("rect",{x:0,y:Math.min(x,b),width:n.width||0,height:Math.abs(b-x),fill:f,fillOpacity:m}),v.map((e,t)=>{const i=pt(e,n),r=ft(e,n);return null==i||null==r?null:(0,vt.jsx)("circle",{cx:i,cy:r,r:g,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+t)}),e.label&&(0,vt.jsx)("text",{x:(n.width||0)-4,y:Math.min(x,b)-4,textAnchor:"end",fill:f,fontSize:11,children:e.label})]},"ann-"+t)}case"forecast":{const i=n.data||[];if(3>i.length)return null;const r=n.xAccessor||"x",o=n.yAccessor||"y",s=n.scales?.x??n.scales?.time,a=n.scales?.y??n.scales?.value;if(!s||!a)return null;const c=i.map(e=>[e[r],e[o]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>c.length)return null;let l;if("polynomial"===(e.method||"linear")){const t=ht.default.polynomial(c,{order:e.order||2}).equation;l=e=>t.reduce((t,n,i)=>t+n*Math.pow(e,i),0)}else{const e=c.length;let t=0,n=0,i=0,r=0;for(const[e,o]of c)t+=e,n+=o,i+=e*e,r+=e*o;const o=e*i-t*t;if(1e-12>Math.abs(o))return null;const s=(e*r-t*n)/o,a=(n-s*t)/e;l=e=>a+s*e}const d=c.length,u=c.map(([e,t])=>t-l(e)).reduce((e,t)=>e+t*t,0),h=Math.sqrt(u/Math.max(d-2,1)),p=c.reduce((e,t)=>e+t[0],0)/d,f=c.reduce((e,t)=>e+(t[0]-p)**2,0),m=e.confidence??.95,y=.99>m?.95>m?.9>m?1:1.645:1.96:2.576,g=e.steps??5,x=c[d-1][0],b=(x-c[0][0])/Math.max(d-1,1),v=[];for(let e=1;g>=e;e++)v.push(x+e*b);const w=[];for(const e of v){const t=l(e),n=h*Math.sqrt(1+1/d+(f>0?(e-p)**2/f:0))*y;w.push({x:e,yCenter:t,yUpper:t+n,yLower:t-n})}const k=`M${w.map(e=>`${s(e.x)},${a(e.yUpper)}`).join(" L")} L${w.slice().reverse().map(e=>`${s(e.x)},${a(e.yLower)}`).join(" L")} Z`,M=w.map(e=>`${s(e.x)},${a(e.yCenter)}`).join(" "),S=`${s(x)},${a(l(x))}`,I=e.strokeColor||"#6366f1";return(0,vt.jsxs)("g",{children:[(0,vt.jsx)("path",{d:k,fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity??.15,stroke:"none"}),(0,vt.jsx)("polyline",{points:`${S} ${M}`,fill:"none",stroke:I,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&w.length>0&&(0,vt.jsx)("text",{x:s(w[w.length-1].x)+4,y:a(w[w.length-1].yCenter)-4,fill:I,fontSize:11,children:e.label})]},"ann-"+t)}case"widget":{let i,r;if(null!=e.px&&null!=e.py)i=e.px,r=e.py;else{const o=gt(e,t,n);if(!o)return null;i=o.x,r=o.y}if(!xt(i,r,n))return null;const o=e.width??32,s=e.height??32;return(0,vt.jsx)("foreignObject",{x:i+(e.dx??0)-o/2,y:r+(e.dy??0)-s/2,width:o,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:(0,vt.jsx)("div",{style:{width:o,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:e.content??(0,vt.jsx)("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"})})},"ann-"+t)}case"text":{const i=gt(e,t,n);if(!i)return null;const{x:r,y:o}=i,s=r+(e.dx||0),a=o+(e.dy||0),c=e.color||"var(--semiotic-text, #333)",l=(0,vt.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?tt.cloneElement(l,{key:"ann-text-"+t}):(0,vt.jsxs)("g",{opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:[(0,vt.jsx)("line",{x1:r,y1:o,x2:s,y2:a,stroke:c,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),tt.cloneElement(l,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+t)}case"category-highlight":{const i=e.category;if(null==i)return null;const r=e=>"function"==typeof e&&"function"==typeof e.bandwidth,o=n.scales?.o,s=n.scales?.x,a=n.scales?.y,c=r(o)?o:r(s)?s:r(a)?a:null;if(!c)return null;const l=c(i+"");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,vt.jsxs)("g",(n.projection?"vertical"===n.projection:c===s)?{children:[(0,vt.jsx)("rect",{x:l,y:0,width:d,height:n.height||0,fill:u,fillOpacity:h}),p&&(0,vt.jsx)("text",{x:l+d/2,y:12,textAnchor:"middle",fill:u,fontSize:12,fontWeight:"bold",children:p})]}:{children:[(0,vt.jsx)("rect",{x:0,y:l,width:n.width||0,height:d,fill:u,fillOpacity:h}),p&&(0,vt.jsx)("text",{x:12,y:l+d/2,dominantBaseline:"middle",fill:u,fontSize:12,fontWeight:"bold",children:p})]},"ann-"+t)}default:return null}},[]),M=w?function(e,t,n,i){const r=[];return e.forEach((e,o)=>{let s;if(n){const r=n(e,o,i);s=null!=r?r:t(e,o,i)}else s=t(e,o,i);s&&r.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:Je(e.annotation),readingOrder:null,rank:Le};var n}),n=t.some(e=>null!=e.emphasis||null!=e.confidence),i=e.some(e=>Qe(e.annotation)),r=e.some(e=>null!=Ze(e.annotation)),o=e.some(e=>"layer"===Ze(e.annotation));if(!n&&!i&&!r)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=Ye-t/Math.max(1,s.length)});for(const e of t)e.emphasis&&(e.rank=Oe[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:r}=e,o=Qe(t.annotation);let s=t.node;if("primary"===i||"secondary"===i||null!=r){const e=null==i&&null!=r;s=(0,Fe.jsx)("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+i,..."secondary"===i?{opacity:He,fontSize:Ge}:{},...e?{opacity:et(r),"data-annotation-reading-order":r}:{},children:t.node},"annotation-emphasis-"+n)}const a=Ze(t.annotation);return a&&(s=(0,Fe.jsx)("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+n)),o&&(s=(0,Fe.jsx)("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+n)),s});return i&&a.unshift((0,Fe.jsx)("style",{children:Ue},"annotation-disclosure-style")),o&&a.unshift((0,Fe.jsx)("style",{children:Ke},"annotation-cohesion-style")),a}(r)}(w.filter(e=>"widget"!==e.type),k,g,v):null,S=!0===w?.some(e=>"widget"===e.type&&!0===e._annotationDeferred);return(0,Vt.jsxs)(Vt.Fragment,{children:[S?(0,Vt.jsx)("style",{children:Ue},"physics-annotation-disclosure-style"):null,(0,Vt.jsxs)("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i,height:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[(0,Vt.jsxs)("g",{transform:`translate(${o.left},${o.top})`,children:[M,x]}),s&&"string"==typeof s?(0,Vt.jsx)("text",{x:i/2,y:16,textAnchor:"middle",fontWeight:600,fill:"var(--semiotic-text, #333)",className:"semiotic-chart-title",style:{fontSize:"var(--semiotic-title-font-size, 14px)"},children:s}):s?(0,Vt.jsx)("foreignObject",{x:0,y:0,width:i,height:Math.max(o.top,28),children:s}):null,a?We({legend:a,totalWidth:i,totalHeight:r,margin:o,legendPosition:h,legendLayout:p,title:s,legendHoverBehavior:c,legendClickBehavior:l,legendHighlightedCategory:d,legendIsolatedCategories:u}):null]})]})}function en(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function tn(e,t){const n="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,en(e.thickness)??en(n)??en(t.thickness)??4)}var nn=2500;function rn(e){return"function"==typeof e}function on(e){return void 0===e||!1===e||!rn(e.binAccessor)&&!rn(e.labelAccessor)&&!rn(e.valueAccessor)}function sn(e){if(void 0!==e){if(!1===e)return!1;if(!on(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 an(e){if(e)return{chartId:e.chartId,chartType:e.chartType,sensors:e.sensors}}function cn(e){return function(e){return!rn(e?.timeAccessor)}(e)}function ln(e={}){if(e.engine)throw new TypeError("Physics workers use the built-in kernel adapter");const{engine:t,observation:n,sediment:i,...r}=e;return{...r,observation:an(n),sediment:sn(i)}}var dn={};function un(){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 hn=class{constructor(e=function(){const e="string"==typeof dn.url&&dn.url?new URL("./physicsWorker.js",dn.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(un());const n=this.nextRequestId;this.nextRequestId+=1;const i={command:e,requestId:n};return new Promise((e,r)=>{const o=()=>{this.pending.delete(n),t?.removeEventListener("abort",o),r(un())},s=()=>t?.removeEventListener("abort",o);this.pending.set(n,{cleanup:s,reject:r,resolve:e}),t?.addEventListener("abort",o,{once:!0});try{this.worker.postMessage(i)}catch(e){this.pending.delete(n),s(),r(e)}})}async init(e,t,n,i){if(!cn(n))throw new TypeError("Physics worker spawn pacing only supports string time accessors");const r=await this.request({type:"init",config:ln(e),initialSpawns:t,initialSpawnPacing:n},i);if("frame"!==r.type)throw Error("Physics worker returned a non-frame init response");return r.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:ln(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(!cn(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 pn(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 fn={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},mn=1e-9,yn=.005;function gn(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function xn(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 bn(e,t,n){return Math.max(t,Math.min(n,e))}function vn(e){return 0>e?-1:1}function wn(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 kn(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 Mn(e,t){return!(e.minX>t.maxX||t.minX>e.maxX||e.minY>t.maxY||t.minY>e.maxY)}function Sn(e,t,n,i,r,o,s,a){const c=r-e,l=(n+s)/2-Math.abs(c);if(0>=l)return null;const d=o-t,u=(i+a)/2-Math.abs(d);return u>0?u>l?{nx:vn(c),ny:0,penetration:l}:{nx:0,ny:vn(d),penetration:u}:null}function In(e,t,n,i,r,o,s){const a=o/2,c=s/2;let l=e-bn(e,i-a,i+a),d=t-bn(t,r-c,r+c);const u=l*l+d*d;if(u>n*n)return null;if(mn>=u){const o=Math.abs(e-(i-a)),s=Math.abs(e-(i+a)),u=Math.abs(t-(r-c)),h=Math.abs(t-(r+c)),p=Math.min(o,s,u,h);return p===o?(l=-1,d=0,{nx:l,ny:d,penetration:n+o}):p===s?(l=1,d=0,{nx:l,ny:d,penetration:n+s}):p===u?(l=0,d=-1,{nx:l,ny:d,penetration:n+u}):(l=0,d=1,{nx:l,ny:d,penetration:n+h})}const h=Math.sqrt(u);return{nx:l/h,ny:d/h,penetration:n-h}}function jn(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return function(e,t,n,i,r,o){const s=i-e,a=r-t,c=n+o,l=s*s+a*a;if(l>=c*c)return null;if(mn>=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 Sn(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=In(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?In(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height):null}function An(e,t){const n=t.shape;return"aabb"===n.type?"circle"===e.shape.type?In(e.x,e.y,e.shape.radius,n.x,n.y,n.width,n.height):Sn(n.x,n.y,n.width,n.height,e.x,e.y,e.shape.width,e.shape.height):function(e,t,n,i,r,o,s,a=0){const c=o-i,l=s-r,d=c*c+l*l,u=d>mn?bn(((e-i)*c+(t-r)*l)/d,0,1):0,h=n+a/2,p=e-(i+c*u),f=t-(r+l*u),m=p*p+f*f;if(m>=h*h)return null;if(mn>=m){const e=Math.sqrt(d);return e>mn?{nx:-l/e,ny:c/e,penetration:h}:{nx:1,ny:0,penetration:h}}const y=Math.sqrt(m);return{nx:p/y,ny:f/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 Cn(e,t){return`${e}\0${t}`}function Pn(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function Rn(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:gn(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function Dn(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 $n(e){return{id:e.id,shape:xn(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:Dn(e.bodyFilter),index:e.index}}function Bn(e,t){return!!t?.some(t=>Object.is(e,t))}function Tn(e,t){const n=e.bodyFilter;if(!n)return!0;if("function"==typeof n)return n(t);const i=function(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}(t,n.property);return!("equals"in n&&!Object.is(i,n.equals)||"notEquals"in n&&Object.is(i,n.notEquals)||n.oneOf&&!Bn(i,n.oneOf)||n.notOneOf&&Bn(i,n.notOneOf))}var En=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={...fn,...e},this.random=pn(this.options.seed)}init(e={}){this.options={...fn,...e},this.random=pn(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(mn,e.mass??1),bodyCollisions:e.bodyCollisions??!0,shape:gn(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))Pn(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:xn(t.shape),bodyFilter:Dn(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 r=this.bodyPairKeys(n),o=this.sortedColliders().filter(e=>!e.sensor);for(let e=0;this.options.collisionIterations>e;e+=1)this.resolveBodyPairs(n,r,0===e),this.resolveColliders(n,o,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:gn(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Pn)}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(Rn),colliders:this.sortedColliders().map($n),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=pn(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=Rn(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=$n(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 r=i.x-n.x,o=i.y-n.y,s=Math.sqrt(r*r+o*o);if(mn>=s)continue;const a=r/s,c=o/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,r]=i.split(":").map(Number),o=e[t],s=e[r];if(!o||!s)continue;const a=jn(o,s);a&&(this.resolveDynamicCollision(o,s,a),n&&this.lastEvents.push({type:"contact",bodyId:o.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 r=wn(e[i]),o=Math.floor(r.minX/t),s=Math.floor(r.maxX/t),a=Math.floor(r.minY/t),c=Math.floor(r.maxY/t);for(let e=o;s>=e;e+=1)for(let t=a;c>=t;t+=1){const r=`${e}:${t}`,o=n.get(r);o?o.push(i):n.set(r,[i])}}const i=new Set;for(const t of Array.from(n.keys()).sort()){const r=n.get(t)??[];r.sort((e,t)=>e-t);for(let t=0;r.length>t;t+=1)for(let n=t+1;r.length>n;n+=1){const o=r[t],s=r[n];!1!==e[o].bodyCollisions&&!1!==e[s].bodyCollisions&&Mn(wn(e[o]),wn(e[s]))&&i.add(`${o}:${s}`)}}return Array.from(i).sort((e,t)=>{const[n,i]=e.split(":").map(Number),[r,o]=t.split(":").map(Number);return n===r?i-o:n-r})}resolveDynamicCollision(e,t,n){e.sleeping&&this.supportedThisStep.add(t.id),t.sleeping&&this.supportedThisStep.add(e.id);const i=e.sleeping?0:1/e.mass,r=t.sleeping?0:1/t.mass,o=i+r;if(mn>=o)return;const s=Math.max(0,n.penetration-yn)/o;e.x-=n.nx*s*i,e.y-=n.ny*s*i,t.x+=n.nx*s*r,t.y+=n.ny*s*r;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+Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution))*a/o,d=l*n.nx,u=l*n.ny;e.vx-=d*i,e.vy-=u*i,t.vx+=d*r,t.vy+=u*r,this.applyFriction(e,t,n,l,i,r),c>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,n,i,r,o){const s=-n.ny,a=n.nx,c=(t.vx-e.vx)*s+(t.vy-e.vy)*a,l=r+o;if(mn>=Math.abs(c)||mn>=l)return;const d=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction))),u=bn(-c/l,-i*d,i*d),h=u*s,p=u*a;e.vx-=h*r,e.vy-=p*r,t.vx+=h*o,t.vy+=p*o}resolveColliders(e,t,n){for(const i of e)for(const e of t){if(!Tn(e,i))continue;if(!Mn(wn(i),kn(e)))continue;const t=An(i,e);t&&(this.resolveStaticCollision(i,e,t),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-yn),e.y+=n.ny*Math.max(0,n.penetration-yn);const i=e.vx*n.nx+e.vy*n.ny;if(0>i){const r=Math.min(e.restitution??this.options.restitution,t.restitution??this.options.restitution);e.vx-=(1+r)*i*n.nx,e.vy-=(1+r)*i*n.ny;const o=-n.ny,s=n.nx,a=e.vx*o+e.vy*s,c=Math.max(0,Math.min(1,Math.max(e.friction??this.options.friction,t.friction??this.options.friction)));e.vx-=a*o*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=wn(i);for(const r of n){if(!Tn(r,i))continue;if(!Mn(e,kn(r)))continue;if(!An(i,r))continue;const n=Cn(r.id,i.id);t.add(n),this.activeSensors.has(n)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:r.id})}}for(const e of Array.from(this.activeSensors).sort()){if(t.has(e))continue;const{sensorId:n,bodyId:i}=Pn(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})))}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Nn=class{constructor(e={}){this.id="builtin",this.capabilities={...(new En).capabilities,engine:"builtin"},this.world=new En(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 qn(e={}){return new Nn(e)}function zn(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):qn(t)}var Wn=["binId","targetBin","category","windowIndex","lane","group"];function Fn(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 On(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 Ln(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 Yn(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function Hn(e,t,n){return"function"==typeof e?e(t,n):"string"==typeof e?Yn(t,e):void 0}function Gn(e){if(null==e)return;const t=e+"";return t.trim()?t:void 0}function Xn(e){const t=On(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:On(e.x),y:On(e.y),value:t}}var _n=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=Gn(Hn(this.config.binAccessor,e,t))??function(e){for(const t of Wn){const n=Gn(Yn(e,t));if(n)return n}return"sediment"}(e),i=Gn(Hn(this.config.labelAccessor,e,t))??n,r=function(e,t,n){if("number"==typeof e)return e;const i="function"==typeof e?e(t,n):"string"==typeof e?Yn(t,e):1,r="number"==typeof i?i:Number(i);return Number.isFinite(r)?r:1}(this.config.valueAccessor,e,t),o=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,Fn(s.x,e.x),Fn(s.y,e.y),Fn(s.value,r),o>0&&(s.bodyIds.push(e.id),s.bodyIds.length>o&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-o))),Xn(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(Xn)}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:Ln(t.x),y:Ln(t.y),value:Ln(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 Vn(e,t={}){const{baselineY:n=0,binWidth:i=24,gap:r=2,maxHeight:o=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*o),d=a?.(e,t)??t*(i+r);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 Un(e){const t=Number(e);if(Number.isFinite(t)&&t>0)return Math.floor(t)}function Kn(e){const t=Math.max(0,Math.floor(e.liveBodies)),n=Math.max(0,Math.floor(e.queuedBodies??0)),i=t+n,r=Un(e.bodyLimit),o=Un(e.engineMaxBodiesHint),s=function(e,t,n){if(!1===n)return;const i=Un(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}(r,o,e.options),a=null==r?0:Math.max(0,t-r),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:r,engineMaxBodiesHint:o,liveBodies:t,overflow:a,projectedBodies:i,queuedBodies:n,state:c,warnAt:s}}var Qn={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Zn={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Jn(e={},t=Zn){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 ei(e){return{...e,shape:{...e.shape},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function ti(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 ni(e,t){if(null!=e[t])return e[t];const n=e.datum;return n&&"object"==typeof n?n[t]:void 0}function ii(e){return{...ei(e),sequence:e.sequence,spawnAt:e.spawnAt}}function ri(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 oi(e){return!1!==e&&{...e}}function si(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function ai(e){return{...e,gravity:{...e.gravity}}}function ci(e,t,n,i){if("circle"===e.shape.type){const r=e.x-t,o=e.y-n,s=e.shape.radius+i,a=r*r+o*o;return a>s*s?null:a}const r=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),o=Math.max(Math.abs(n-e.y)-e.shape.height/2,0),s=r*r+o*o;return s>i*i?null:s}function li(e){const t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function di(e,t={}){const{idPrefix:n="plot",includeFloor:i=!0,includeCeiling:r=!1,includeLeftWall:o=!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}}),r&&l.push({id:n+"-ceiling",shape:{type:"aabb",x:d,y:e.y-c/2,width:e.width+2*a,height:c}}),o&&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 ui(e){const{idPrefix:t="bin",count:n,domainStart:i,domainStep:r,xScale:o,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,f=[],m=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=o(i+e*r);f.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:s,y:m,width:c,height:y}})}if(null!=u)for(let e=0;n>e;e+=1){const n=i+e*r,s=n+r;if(s>=u)continue;const a=o(n),l=o(s);f.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 f}var hi={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 pi(e,t){const n={...e};for(const e of t)n[hi[e]]++;return n}function fi(e,t,n){const i=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:i,revisions:pi(n,i)}}var mi=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=fi({kind:"initialize"},[],this.revisions)}get last(){return this.latest}record(e,t){const n=fi(e,t,this.revisions);return this.revisions=n.revisions,this.latest=n,n}},yi=require("d3-quadtree"),gi=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,n,i,r,o=0){const s=this.ensure(e,t);if(!s)return null;let a=null,c=1/0;const l=Math.max(0,o)+this.maxSearchRadius,d=i-l,u=i+l,h=r-l,p=r+l;return s.visit((e,t,s,l,f)=>{if(d>l||t>u||h>f||s>p)return!0;if(e.length)return!1;let m=e;for(;m;){const e=m.data;if(e){const t=ci(e,i,r,Math.max(0,o));null!=t&&(c>t||t===c&&n.indexOf(e.id)>n.indexOf(a?.id??""))&&(a=e,c=t)}m=m.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,yi.quadtree)().x(e=>e.x).y(e=>e.y).addAll(n),this.revision=t,this.tree)}},xi=["data","scene-geometry","data-paint","accessibility","evidence"],bi=["scene-geometry","data-paint","accessibility","evidence"],vi=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],wi=["overlay","accessibility","evidence"],ki=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function Mi(e,t){return e===t||!(!e||!t)&&e.gravity?.x===t.gravity?.x&&e.gravity?.y===t.gravity?.y&&ki.every(n=>e[n]===t[n])}function Si(e,t,n,i){return e||!t?"paused":n||!i?"running":"settled"}var Ii=class{constructor(e={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new gi,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new mi,this.simulationState="settled",this.visible=!0;const{bodyBudget:t,colliders:n,engine:i,kernel:r,observation:o,sediment:s,...a}=e;this.config={...Qn,...a},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=i,this.observation=Jn(o),this.sediment=new _n(s??!1),this.world=zn(i,{fixedDt:this.config.fixedDt,...r}),n&&this.world.setColliders(ri(n))}updateConfig(e){const t=function(e,t){return Object.keys(e).filter(n=>"kernel"===n?!Mi(e.kernel,t.kernel):e[n]!==t[n])}(e,this.configInput),{colliders:n,bodyBudget:i,engine:r,kernel:o,observation:s,sediment:a,...c}=e;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),r&&r!==this.engineInput){const e=this.world.snapshot();this.world.dispose(),this.engineInput=r,this.world=zn(r,e.options),this.world.restore(e),this.revision+=1}if(o&&!Mi(o,this.configInput.kernel)){const e=this.world.snapshot(),t={...e.options,...o,gravity:{...e.options.gravity,...o.gravity}};this.world.restore({...e,options:t}),this.revision+=1}s&&(this.observation=Jn(s,this.observation)),this.sediment.updateConfig(a),n&&(this.world.setColliders(ri(n)),this.revision+=1),this.configInput={...this.configInput,...e},this.updateResults.record({kind:"config",keys:t},t.length?vi:[])}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(ri(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},vi)}enqueue(e,t){const n=Array.isArray(e)?e:[e],i=t?function(e,t={}){const n=ti(t.startAt)??0,i=t.pacing??"immediate";if("arrival"===i){const i=e.map((e,n)=>function(e,t,n){return"function"==typeof n?ti(n(e,t)):"string"==typeof n?ti(ni(e,n)):ti(e.spawnAt)??ti(ni(e,"arrivalTime"))??ti(ni(e,"timestamp"))??ti(ni(e,"time"))??ti(ni(e,"eventTime"))}(e,n,t.timeAccessor)),r=i.filter(e=>null!=e),o=r.length>0?Math.min(...r):0,s=ti(t.timeScale)??1,a=s>0?s:1;return e.map((e,t)=>{const r=i[t],s=null==r?0:Math.max(0,r-o);return{...ei(e),spawnAt:n+s/a}})}if("object"==typeof i){const t=ti(i.ratePerSec);if(t&&t>0)return e.map((e,i)=>({...ei(e),spawnAt:n+i/t}))}return e.map(e=>({...ei(e),spawnAt:n}))}(n,{...t,startAt:t.startAt??this.elapsedSeconds}):n;for(const e of i)this.queue.push({...ei(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(si),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?xi:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(ei(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},xi)}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.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},xi)}tick(e){const t=this.revision,n=[],i=[],r=[],o=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,r,o,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),r.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();o.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)),(d>0||n.length>0||i.length>0||r.length>0||o.length>0)&&(this.revision+=1);const u=this.result(d,n,i,r,o,s,void 0,c);return this.updateResults.record({kind:"tick",count:d},this.revision!==t?n.length||i.length||r.length?xi:bi:[]),u}settle(e=this.config.settleStepLimit){const t=this.revision;this.spawnDue([],[]);const n=this.world.settle(e,this.config.fixedDt);return n>0&&(this.revision+=1),this.syncSimulationState(),this.updateResults.record({kind:"settle",count:n},this.revision!==t?bi:[]),n}settleWithObservations(e=this.config.settleStepLimit){const t=this.revision,n=[],i=[],r=[],o=[],s=[];if(this.paused||!this.visible){const e=this.result(0,n,i,r,o,s,!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(n,s);const a=this.observeBodyBudget(s),c=this.evictOverflow(s);i.push(...c.evicted),r.push(...c.sedimented),this.syncSimulationState(s);let l=0;for(;e>l&&!this.world.allSleeping();){this.world.step(this.config.fixedDt);const e=this.world.events();o.push(...e),this.observeKernelEvents(e,s),this.observeSensorTransitions(s),l+=1}(l>0||n.length>0||i.length>0||r.length>0||o.length>0)&&(this.revision+=1);const d=this.result(l,n,i,r,o,s,void 0,a);return this.updateResults.record({kind:"settle",count:l},this.revision!==t?n.length||i.length||r.length?xi:bi:[]),d}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return Vn(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()}hasPendingWork(){return this.queue.length>0||!this.world.allSleeping()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){const{timestamp:t,chartType:n,chartId:i,...r}=e,o={...r,timestamp:t??this.elapsedSeconds,chartType:n??this.observation.chartType,chartId:i??this.observation.chartId};return this.emitObservation(o),this.updateResults.record({kind:"update",count:1},["evidence"]),o}getLastUpdateResult(){return this.updateResults.last}version(){return this.revision}setPaused(e){const t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?wi:[])}setVisible(e){const t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?wi:[])}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 r=e.filter(e=>n.has(e)||i.has(e));return r.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:r,count:r.length},r.length?xi:[]),r}setConstraint(e){const t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},bi),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},bi)}applyImpulse(e,t,n){this.world.applyImpulse(e,t,n),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},bi)}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:oi(this.bodyBudget),config:{...this.config,kernel:ai(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(ii),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:oi(e.bodyBudget??{}),kernel:ai(e.world.options)},this.bodyBudget=oi(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(ii).sort(si),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??Si(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"},vi)}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,r,o,s,a=this.evaluateBodyBudget()){this.syncSimulationState(o);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:n,events:r,observations:o,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!c),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 r=new Map(e.readState().map(e=>[e.id,e])),o=(e,t)=>{const{sensorId:i,bodyId:o}=li(t),s=n.observation.sensors[i],a=r.get(o);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:o,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)||o("enter",e);for(const e of Array.from(t).sort())i.has(e)||o("exit",e);return i}(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){!function(e,t){for(const n of e)t.has(li(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 Kn({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=Si(this.paused,this.visible,this.queue.length>0,this.world.allSleeping());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){if(!1===this.config.eviction)return{evicted:[],sedimented:[]};const t=Math.max(0,Math.floor(this.config.bodyLimit));if(!Number.isFinite(t))return{evicted:[],sedimented:[]};const n=this.liveBodyOrder.length-t;if(0>=n)return{evicted:[],sedimented:[]};const i=("sleeping-first"===this.config.eviction?this.sleepingFirstEvictionOrder():this.liveBodyOrder.slice()).slice(0,n);if(0===i.length)return{evicted:[],sedimented:[]};const r=this.absorbSediment(i,e);this.world.remove(i);const o=new Set(i);return this.liveBodyOrder=this.liveBodyOrder.filter(e=>!o.has(e)),this.removeActiveSensorPairsForBodies(o),{evicted:i,sedimented:r}}absorbSediment(e,t){const n=new Map(this.world.readState().map(e=>[e.id,e])),i=[];for(const r of e){const e=n.get(r);if(!e)continue;const o=this.sediment.add(e);o&&(i.push(r),this.emitObservation({type:"physics-sediment",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:r,datum:e.datum,x:e.x,y:e.y,binId:o.id,count:o.count,total:o.total},t))}return i}sleepingFirstEvictionOrder(){const e=new Map(this.world.readState().map(e=>[e.id,e.sleeping])),t=[],n=[];for(const i of this.liveBodyOrder)e.get(i)?t.push(i):n.push(i);return[...t,...n]}},ji=c(require("react-dom/server"));function Ai(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 Ci={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Pi(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 Ri(e,t){const n="function"==typeof t?t(e):t;return{...Ci,...n??{}}}function Di(e,t={}){const n=e.settle(t.maxSteps),i=e.readBodies(),r=e.snapshot(),o=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)??Pi(e)},r={style:Ri(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,...r}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...r}}(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;return{bodyCount:n.length,sleepingCount:i,settled:"settled"===e.simulationState&&0===e.queue.length&&i===n.length,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:Ai(t.projectionRows)}}(r,{bodies:i,projectionRows:t.projectionRows,stepsRun:n});return{snapshot:r,bodies:i,sceneNodes:o,evidence:s,stepsRun:n}}var $i=require("react/jsx-runtime");function Bi(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 Ti(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=Ni(e.datum,t),i=Ni(e,t),r=n??i;if(null!=r&&(r+"").length>0)return r+""}return e.id}function Ei(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 Ni(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 qi(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=Ni(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function zi(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),i=e.queueLayout??"lane",r=e.queueSlotSpacing??14,o=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,f=new Map,m=new Map,y=new Map,g=[];let x=0,b=new Map,v=new Map,w=0,k=0,M=0,S=null,I=0,j=0,A=0,C=0,P=0,R=0,D=0,$=0,B=0,T=0,E=0,N=0,q=-1,z=!1;function W(e,n){const i=n(e);return!!i&&i.activeRegionIds.includes(t)}function F(){N+=1}function O(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,r,o){const s={bodyId:n.id,jobId:i.jobId,visitId:i.visitId,visit:i.visit,remaining:i.work,total:i.work,queuedAt:i.queuedAt,sequence:o};return d.set(i.jobId,s),y.delete(n.id),m.set(n.id,i.jobId),j+=1,A+=i.work,F(),function(n,i,r){const o=O(i);e.onQueued?.(n,o),r.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,r),s}function Y(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=f.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 H(){let e=0;for(const t of d.values())e+=t.remaining;return e}function G(){B=Math.max(B,d.size),T=Math.max(T,H())}function X(){const e=M-a,t=Math.max(0,Math.min(a,M-(S??M)));let i=0,r=0,o=0,s=0,c=0;for(const t of g){if(e>t.end)continue;i+=t.arrivals,r+=t.arrivalWork,o+=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?r/t:0;return{seconds:t,arrivals:i,arrivalWork:r,completions:o,completedWork:s,processedWork:c,arrivalsPerSecond:t>0?i/t:0,throughputPerSecond:t>0?o/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 r=i.controls.readBodies(),o=new Map,j=new Map;for(const t of r){if(o.set(t.id,t),!W(t.id,i.getRegionState))continue;if(!qi(t,e.bodyFilter))continue;const n=Ti(t,e.jobKey),r=j.get(n)??[];r.push(t),j.set(n,r)}const A=Number.isFinite(i.dt)?Math.max(0,i.dt):0;if(!z){const e=Number.isFinite(i.elapsed)?Math.max(0,i.elapsed):A;M=Math.max(0,e-A),z=!0}const B=M,T=B+A;M=T,S=null==S?B:Math.min(S,B);const N={start:B,end:T,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},H=new Map;for(const[e,t]of j){const n=h.get(e)?.bodyId,i=t.find(e=>e.id===n)??t[0];H.set(e,i),f.set(e,i)}for(const[n,r]of h){if(H.has(n))continue;const s=d.get(n),a=o.get(r.bodyId)??f.get(n);if(s){d.delete(n),m.delete(s.bodyId),D+=1,$+=s.remaining,F();const o={...O(s),abandonedAt:M,remainingWork:s.remaining,queueSeconds:Math.max(0,M-s.queuedAt)};a&&e.onAbandoned?.(a,o),i.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:r.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:o.queueSeconds,queueDepth:d.size})}u.delete(n),y.delete(r.bodyId),h.delete(n),f.delete(n)}for(const[n,r]of H){if(h.has(n))continue;const o=(p.get(n)??0)+1;p.set(n,o);const a=Bi(r,e.unitAccessor),c={bodyId:r.id,jobId:n,visitId:`${t}:${n}:${o}`,visit:o,regionId:t,work:a,queuedAt:M};h.set(n,c),I+=1,N.arrivals+=1,N.arrivalWork+=a;const l=x++;if(s>d.size)L(r,c,i,l);else{const s={...c,blockedAt:M,sequence:l};u.set(n,s),y.set(r.id,n),R+=1,F(),e.onBlocked?.(r,s),i.controls.recordObservation({type:"physics-capacity-blocked",bodyId:r.id,datum:r.datum,x:r.x,y:r.y,regionId:t,work:a,jobId:n,visitId:c.visitId,visit:o,queuedAt:M,blockedAt:M,queueDepth:d.size,blockedDepth:u.size})}}Y(i),G();const X=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);let _=n*A;for(const n of X){if(0>=_)break;const r=Math.min(n.remaining,_);if(n.remaining-=r,_-=r,C+=r,N.processedWork+=r,n.remaining>1e-6)continue;d.delete(n.jobId),m.delete(n.bodyId),k+=1,P+=n.total,N.completions+=1,N.completedWork+=n.total;const s=Math.max(0,M-n.queuedAt);E+=s,F();const a=o.get(n.bodyId);if(!a)continue;i.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...O(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})}Y(i),G(),function(){const e=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);b=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 V=Math.floor(M/c);V!==q&&(q=V,F())},getSnapshot:()=>{const e=H(),i=function(){let e=0;for(const t of u.values())e+=t.work;return e}(),r=d.size,o=Array.from(d.values()).map(e=>Math.max(0,M-e.queuedAt)).sort((e,t)=>e-t),s=o.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:r,processedCount:k,unitsPerSecond:n,remainingWork:e,meanRemainingWork:r>0?e/r:0,waitingWork:e+i,blockedDepth:u.size,blockedWork:i,arrivalCount:I,admittedCount:j,admittedWork:A,processedWork:C,completedWork:P,blockedCount:R,abandonedCount:D,abandonedWork:$,peakQueueDepth:B,peakRemainingWork:T,queueAge:{count:o.length,meanSeconds:o.length>0?s/o.length:0,p50Seconds:Ei(o,.5),p95Seconds:Ei(o,.95),oldestSeconds:o.at(-1)??0},meanCompletedQueueSeconds:k>0?E/k:0,window:X(),simulatedAt:M,metricRevision:N}},bodyForce:e=>{if("none"===i)return null;const n=m.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?b.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*r))-e.body.x)*o,y:(h.y-(l-((c?u.size:w)-1)/2)*r/Math.max(1,Math.sqrt(c?u.size:w))-e.body.y)*o*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function Wi(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 Fi(e,t){if(!t)return!0;if("function"==typeof t)return t(e);const n=Wi(e,t.property);return!("equals"in t&&!Object.is(n,t.equals)||"notEquals"in t&&Object.is(n,t.notEquals)||t.oneOf&&!t.oneOf.some(e=>Object.is(n,e))||t.notOneOf&&t.notOneOf.some(e=>Object.is(n,e)))}function Oi(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,r=new Map,o=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 o=t.find(e=>!r.has(e.id));if(!o)return null;const s={resourceId:o.id,resourceBodyId:o.bodyId,caseBodyId:e,assignedAt:d};return i.set(e,s),r.set(o.id,s),u+=1,s},release:e=>{const t=i.get(e);return!!t&&(i.delete(e),r.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),r.delete(t.resourceId),u+=1)},getSnapshot:()=>({total:t.length,available:t.length-r.size,assigned:r.size,assignments:Array.from(i.values()),simulatedAt:d,metricRevision:u}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=r.get(t.id),i=n?l.get(n.caseBodyId):void 0,a=n?o: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 Li(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):Wi(e.datum,t.deadlineAccessor)??Wi(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function Yi(e){const t=new Map;let n=0,i=0;function r(n){t.set(n.bodyId,n),i+=1,e.onStateChange?.({...n})}function o(e){const i=t.get(e);return!(!i||null!=i.completedAt||(r({...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||(r({...i,state:"protected",protectedAt:n}),0))},complete:o,getCase:e=>t.get(e),tick:i=>{n=Math.max(n,i.elapsed);for(const s of i.controls.readBodies()){if(!Fi(s,e.bodyFilter))continue;if(!t.has(s.id)){const t=Li(s,e);r({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)?o(s.id):"waiting"!==a.state||a.deadlineAt>n||r({...a,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),r=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:r("waiting"),protected:r("protected"),unhappy:r("unhappy"),resolved:r("resolved"),resolvedUnhappy:r("resolved-unhappy"),simulatedAt:n,metricRevision:i}}}}function Hi(e){const t=new Set;let n=0,i=0,r=0,o=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:s=>{n=Math.max(n,s.elapsed);const a=o;var c;c=n,o=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&&Fi(n,e.bodyFilter)&&(o||t.has(n.id)||(t.add(n.id),r+=1,e.onHeld?.(n)))}if(o&&!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(),r+=1}for(const e of t)d.has(e)||(t.delete(e),r+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:o,blocked:t.size,released:i,simulatedAt:n,metricRevision:r}),bodyForce:n=>{if(o||!t.has(n.body.id))return null;const i=n.regions?.find(t=>t.id===e.regionId),r=i?.shape;if(!r||"aabb"!==r.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const s=e.holdForce??.4;return{x:(r.x-n.body.x)*s-.45*n.body.vx,y:(r.y-n.body.y)*s-.45*n.body.vy}}}}function Gi(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function Xi(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 r={result:e,controls:n,dt:i.dt,elapsed:i.elapsed,getRegionState:i.getRegionState};for(const e of t)e.tick(r)},bodyForce:e=>{let n=null;for(const i of t)i.bodyForce&&(n=Gi(n,i.bodyForce(e)));return n}}}function _i(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 r=i.controls.readBodies();for(const o of r){const r=i.getRegionState(o.id),s=r?.activeRegionIds.includes(e.fromRegionId);s?t.has(o.id)||(t.add(o.id),i.controls.applyImpulse(o.id,n.x??0,n.y??0),e.onPortal?.(o)):t.delete(o.id)}}}}var Vi=require("react");function Ui(){return"undefined"==typeof document||!document.hidden}var Ki=require("react/jsx-runtime"),Qi="var(--semiotic-focus, #005fcc)";function Zi({active:e,hoverPoint:t,margin:n,size:i,shape:r="circle",width:o,height:s,pathData:a}){if(!e||!t)return null;const c=t.x+n.left,l=t.y+n.top;let d;if("geoarea"!==r&&"path"!==r||!a)if("rect"===r&&null!=o&&null!=s){const e=Math.max(o,4),t=Math.max(s,4);d=(0,Ki.jsx)("rect",{x:c-e/2-3,y:l-t/2-3,width:e+6,height:t+6,rx:3,fill:"none",stroke:Qi,strokeWidth:2,strokeDasharray:"4,2"})}else d=(0,Ki.jsx)("circle","wedge"===r?{cx:c,cy:l,r:12,fill:"none",stroke:Qi,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:c,cy:l,r:8,fill:"none",stroke:Qi,strokeWidth:2,strokeDasharray:"4,2"});else d=(0,Ki.jsx)("g",{transform:`translate(${n.left},${n.top})`,children:(0,Ki.jsx)("path",{d:a,fill:"none",stroke:Qi,strokeWidth:2.5,strokeDasharray:"6,3"})});return(0,Ki.jsx)("svg",{style:{position:"absolute",left:0,top:0,width:i[0],height:i[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:d})}c(require("react"));var Ji=c(require("react")),er=(require("react/jsx-runtime"),Ji.createContext(null)),tr=require("react/jsx-runtime"),nr={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function ir({summary:e}){return e?(0,tr.jsx)("div",{role:"note",style:nr,children:e}):null}function rr({tableId:e}){return(0,tr.jsx)("a",{href:"#"+e,style:nr,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,nr)},children:"Skip to data table"})}function or({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,tr.jsx)("div",{"aria-live":"polite","aria-atomic":"true",style:nr,children:t})}function sr(e,t,n){const i=n.fill??"#4e79a7",r=n.stroke,o=n.strokeWidth??0,s=n.opacity??1,a=n.fillOpacity??1,c=function(e,t){const n=t.mark;if(n)return n;const i=e.datum,r=i?.__physicsMark??i?.mark;return"circle"===r||"halo"===r||"faceted"===r||"pill"===r||"diamond"===r||"square"===r?r:"circle"===e.shape.type?"circle":"square"}(t,n),l="circle"===t.shape.type?n.r??t.shape.radius:Math.max(t.shape.width,t.shape.height)/2;if(e.save(),e.globalAlpha*=s,e.beginPath(),"pill"===c||"square"===c||"aabb"===t.shape.type){const n="pill"===c?2.4*l:"aabb"===t.shape.type?t.shape.width:1.7*l,i="pill"===c?1.35*l:"aabb"===t.shape.type?t.shape.height:1.7*l,r=t.x-n/2,o=t.y-i/2,s="pill"===c?i/2:Math.min(4,n/4);e.moveTo(r+s,o),e.arcTo(r+n,o,r+n,o+i,s),e.arcTo(r+n,o+i,r,o+i,s),e.arcTo(r,o+i,r,o,s),e.arcTo(r,o,r+n,o,s),e.closePath()}else if("diamond"===c)e.moveTo(t.x,t.y-l),e.lineTo(t.x+l,t.y),e.lineTo(t.x,t.y+l),e.lineTo(t.x-l,t.y),e.closePath();else if("faceted"===c){const n=6;for(let i=0;n>i;i+=1){const r=2*Math.PI*i/n-Math.PI/2,o=t.x+Math.cos(r)*l,s=t.y+Math.sin(r)*l;0===i?e.moveTo(o,s):e.lineTo(o,s)}e.closePath()}else e.arc(t.x,t.y,l,0,2*Math.PI);i&&(e.save(),e.globalAlpha*=a,e.fillStyle=i,e.fill(),e.restore()),"halo"===c&&(e.beginPath(),e.arc(t.x,t.y,1.35*l,0,2*Math.PI),e.strokeStyle=r??i,e.lineWidth=Math.max(1.5,o||1.5),e.globalAlpha*=.55,e.stroke(),e.globalAlpha/=.55),r&&o>0&&(e.strokeStyle=r,e.lineWidth=o,n.strokeDasharray&&e.setLineDash(n.strokeDasharray.split(/[,\s]+/).map(e=>Number(e)).filter(e=>Number.isFinite(e))),e.stroke()),e.restore()}function ar(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function cr(e){return e.sensorId??"stream-region-"+e.id}function lr(e){const t=cr(e),n={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){const i=e.colliderThickness??8,r=e.shape.x-e.shape.width/2,o=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:r,y1:s,x2:o,y2:s,thickness:i}},{...n,id:t+"-right",shape:{type:"segment",x1:o,y1:s,x2:o,y2:a,thickness:i}},{...n,id:t+"-bottom",shape:{type:"segment",x1:o,y1:a,x2:r,y2:a,thickness:i}},{...n,id:t+"-left",shape:{type:"segment",x1:r,y1:a,x2:r,y2:s,thickness:i}}]}return e.collider?[{...n,id:t+"-collider",shape:e.shape}]:[]}function dr(e){if(e)return{activeRegionIds:Array.from(e.activeRegionIds),regionIds:Array.from(e.regionIds),charges:{...e.charges},attributes:{...e.attributes},energy:e.energy}}function ur(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),r=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(r)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(r)?r:0}:null}function hr(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 pr(e){return e.some(e=>null!=e.force||null!=e.damping||null!=e.impulseOnEnter||null!=e.impulseOnExit)}function fr(e,t){const n="function"==typeof e?e(t):e;if(!n)return null;const i=Number(n.x??0),r=Number(n.y??0);return Number.isFinite(i)||Number.isFinite(r)?{x:Number.isFinite(i)?i:0,y:Number.isFinite(r)?r:0}:null}var mr=[];function yr(e){const t=e.store.controls(),n=e.store.snapshot(),i=Math.max(0,e.result.steps*(n.config.fixedDt||1/60)),r=function(e,t,n,i){const r=Number.isFinite(i)?Math.max(0,i):0;if(0>=r||!pr(t))return!1;const o=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=dr(i);if(s)for(const n of i.activeRegionIds){const i=o.get(n);if(!i)continue;const c=ur(i.force,{body:t,region:i,regionState:s}),l=Number(i.damping??0),d=(c?.x??0)*r-(Number.isFinite(l)?t.vx*l*r:0),u=(c?.y??0)*r-(Number.isFinite(l)?t.vy*l*r:0);(d||u)&&(e.applyImpulse(t.id,d,u),a=!0)}}return a}(t,e.regionEffects,e.regionState,i),o=function(e,t,n,i,r,o){const s=Number.isFinite(o)?Math.max(0,o):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 o=c[n],d=i.get(o.id),u=dr(d);let h=mr;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=fr(t,{body:o,bodies:c,index:n,regionState:u,regions:h,simulationState:r});if(!p)continue;const f=(p.x??0)*s,m=(p.y??0)*s;(f||m)&&(e.applyImpulse(o.id,f,m),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=>dr(e.regionState.get(t))}),e.onTick?.(e.result,t),{regionEffectsApplied:r,bodyForcesApplied:o,snapshot:n}}function gr(e,t,n,i,r,o,s,a,c,l){const d=function(e,t){return!!t?.isActive&&(t.predicate?.(e)??!0)}(e,r),u={selected:d,simulationState:t,regionState:o,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,{}),f=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,...f}}var xr=c(require("react")),br=require("react/jsx-runtime"),vr={border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1},wr="semiotic-accessible-data-table",kr=wr+" semiotic-accessible-data-table-hidden",Mr=wr+" semiotic-accessible-data-table-visible",Sr={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"},Ir={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},jr={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)"},Ar={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},Cr={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))"},Pr={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},Rr={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},Dr={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 $r(e){return null==e?null:"string"==typeof e||"number"==typeof e||"boolean"==typeof e?e+"":null}function Br(e){return{__semioticHoverData:!0,body:e,data:e.datum??e,id:e.id,type:"body",x:e.x,y:e.y}}function Tr(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 Er(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 Nr(e){const t=qr(e.datum??e);return t.length?t.map(([e,t])=>`${e}: ${t}`).join(", "):"Physics body "+e.id}function qr(e){return e&&"object"==typeof e?Object.entries(e).map(([e,t])=>{if(e.startsWith("_"))return null;const n=$r(t);return null==n?null:[e,n]}).filter(e=>null!=e).slice(0,8):[]}function zr({hover:e}){const t=qr(e.data);return(0,br.jsxs)("div",{className:"semiotic-tooltip",style:te,children:[(0,br.jsx)("div",{style:{fontWeight:700,marginBottom:t.length?4:0},children:e.id}),t.map(([e,t])=>(0,br.jsxs)("div",{children:[(0,br.jsxs)("span",{style:{opacity:.72},children:[e,": "]}),(0,br.jsx)("span",{children:t})]},e))]})}function Wr(e){return e.datum&&"object"==typeof e.datum?Object.entries(e.datum).map(([e,t])=>{const n=$r(t);return null==n?null:`${e}: ${n}`}).filter(e=>null!=e).slice(0,8).join(", "):""}function Fr(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 Or(e){const{chartTitle:t,items:n,tableId:i}=e,[r,o]=xr.useState(!1),[s,a]=xr.useState(5),c=Ji.useContext(er),l=c?.visible??!1,d=r||l,u=xr.useRef(null),h="Data summary for "+(t??"physics chart");xr.useEffect(()=>{d||a(5)},[d]);const p=xr.useCallback(e=>{e.target===e.currentTarget&&(r||l||o(!0))},[r,l]),f=xr.useCallback(e=>{l||u.current?.contains(e.relatedTarget)||o(!1)},[l]);if(!n.length)return(0,br.jsx)("span",{id:i,tabIndex:-1,style:vr});if(!d)return(0,br.jsx)("div",{id:i,className:kr,role:"region","aria-label":h,tabIndex:-1,style:vr,onFocus:p,children:(0,br.jsxs)("button",{type:"button",onClick:()=>o(!0),children:["View data summary (",n.length," semantic items)"]})});const m=Math.min(s,n.length),y=n.slice(0,m),g=n.length-m;return(0,br.jsxs)("div",{ref:u,id:i,className:Mr,role:"region","aria-label":h,tabIndex:-1,onBlur:f,style:Sr,children:[(0,br.jsx)("button",{type:"button",className:"semiotic-accessible-data-table-close","aria-label":"Close data summary",onClick:()=>{l&&c&&c.setVisible(!1),o(!1)},style:jr,children:"×"}),(0,br.jsx)("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:Ir,children:Fr(n)}),(0,br.jsxs)("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Semantic items for "+(t??"physics chart"),style:Ar,children:[(0,br.jsx)("caption",{className:"semiotic-accessible-data-table-caption",style:Rr,children:g>0?`First ${m} of ${n.length} semantic items`:`All ${n.length} semantic items`}),(0,br.jsx)("thead",{children:(0,br.jsxs)("tr",{children:[(0,br.jsx)("th",{scope:"col",style:Cr,children:"Item"}),(0,br.jsx)("th",{scope:"col",style:Cr,children:"Description"}),(0,br.jsx)("th",{scope:"col",style:Cr,children:"Group"}),(0,br.jsx)("th",{scope:"col",style:Cr,children:"Position"}),(0,br.jsx)("th",{scope:"col",style:Cr,children:"Data"})]})}),(0,br.jsx)("tbody",{children:y.map((e,t)=>(0,br.jsxs)("tr",{children:[(0,br.jsx)("th",{scope:"row",style:Pr,children:e.label}),(0,br.jsx)("td",{style:Pr,children:e.description??e.label}),(0,br.jsx)("td",{style:Pr,children:e.group??""}),(0,br.jsxs)("td",{style:Pr,children:[Math.round(e.x),", ",Math.round(e.y)]}),(0,br.jsx)("td",{style:Pr,children:Wr(e)})]},e.id??`${e.label}-${t}`))})]}),g>0?(0,br.jsxs)("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(e=>e+25),style:Dr,children:["Show ",Math.min(25,g)," more"," ",1===g?"row":"rows"," (",g," remaining)"]}):null]})}zr.ownsChrome=!0;var Lr=require("react/jsx-runtime"),Yr=[640,360],Hr={top:0,right:0,bottom:0,left:0},Gr=new Set(["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]);function Xr(e,t,n){const i=new Ii(e);return t?.length&&i.enqueue(t,n),i}var _r="StreamPhysicsFrame";function Vr(){return"undefined"!=typeof performance?performance.now():Date.now()}var Ur=(0,h.memo)((0,h.forwardRef)(function(e,t){const{accessibleTable:n=!0,annotations:i,autoPlaceAnnotations:r,background:o,backgroundGraphics:s,bodySemanticItemLimit:a=200,bodySemanticItems:c=!1,bodySemanticUpdateMs:l=200,bodyForces:d,bodyStyle:p,chartId:f,className:m,frameScheduler:y,clock:g,color:x,config:b,controllers:v,continuous:w=!1,description:k,emphasis:M,chartMode:S,enableHover:I=!0,foregroundGraphics:j,hoverRadius:A=16,initialSpawns:C,initialSpawnPacing:P,legend:R,legendClickBehavior:D,legendHighlightedCategory:$,legendHoverBehavior:B,legendIsolatedCategories:T,legendLayout:E,legendPosition:N,margin:q,onClick:H,onObservation:G,onRegionEvent:X,onSimulationExecutionChange:_,onBodyHover:V,onBodyPointerDown:U,onSemanticItemActivate:K,onSemanticItemFocus:J,onTick:ee,opacity:te,paused:ne=!1,regionEffects:ie=[],responsiveHeight:re,responsiveWidth:oe,selectedBodyStyle:se={stroke:"#111827",strokeWidth:2,opacity:1},selection:ve,semanticItems:we=[],simulationExecution:ke="auto",size:Me=Yr,stroke:Se,strokeWidth:Ie,summary:je,suspendWhenHidden:Ae=!0,svgAnnotationRules:Ce,title:Pe,tooltipContent:Re,workerBodyThreshold:De=nn,renderBody:$e,beforePaint:Be,afterPaint:Te}=e,Ee=u.useMemo(()=>({color:x,stroke:Se,strokeWidth:Ie,opacity:te}),[x,te,Se,Ie]),Ne=(0,h.useRef)(G);Ne.current=G;const qe=(0,h.useRef)(f);qe.current=f;const ze=(0,h.useRef)(new Map),We=(0,h.useRef)(ie);We.current=ie;const Fe=(0,h.useRef)(d);Fe.current=d;const Oe=(0,h.useRef)(ee);Oe.current=ee;const Le=u.useMemo(()=>Xi(v),[v]),Ye=(0,h.useRef)(Le);Ye.current=Le;const He=w||!!Le?.continuous,Ge=(0,h.useRef)(He);Ge.current=He;const Xe=u.useMemo(()=>{if(!d&&!Le?.bodyForce)return d;if(!Le?.bodyForce)return d;if(!d)return Le.bodyForce;const e=Le.bodyForce;return t=>{const n="function"==typeof d?d(t):d,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}},[d,Le]);Fe.current=Xe;const _e=u.useMemo(()=>new Map(ie.map(e=>[cr(e),e])),[ie]),Ve=u.useMemo(()=>new Map(ie.map(e=>[e.id,e])),[ie]),Ue=u.useMemo(()=>ie.map(hr).filter(e=>null!=e),[ie]),[Ke,Qe]=u.useState([]),Ze=u.useMemo(()=>Ke.length||Ue.length?[...we,...Ke,...Ue]:we,[Ke,Ue,we]),Je=u.useMemo(()=>pr(ie),[ie]),et=!!Xe,tt=(0,h.useRef)(null),nt=(0,h.useRef)(g??Vr);nt.current=g??Vr;const it=(0,h.useCallback)((e,t,n)=>{const i=tt.current;if(!i||!n)return!1;const r=i.readBodies().find(t=>t.id===e),o=dr(ze.current.get(e));if(!r||!o)return!1;const s=ur(n,{body:r,region:t,regionState:o});return!(!s||!s.x&&!s.y||(i.applyImpulse(e,s.x??0,s.y??0),0))},[]),rt=(0,h.useCallback)((e,t,n)=>{if(!n.bodyId)return;const i=dr(ze.current.get(n.bodyId));if(!i)return;const r={bodyId:n.bodyId,datum:n.datum,observation:n,region:t,regionState:i,type:e};"region-enter"===e?t.onEnter?.(r):t.onExit?.(r),X?.(r)},[X]),ot=(0,h.useCallback)(e=>{const t=e.sensorId?_e.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}(ze.current,e.bodyId),i=tt.current?.readBodies().find(t=>t.id===e.bodyId),r=dr(n),o=i&&r?{body:i,region:t,regionState:r}:null;if("physics-proximity-enter"===e.type){if(n.activeRegionIds.add(t.id),n.regionIds.add(t.id),n.energy+=t.energyDelta??0,o){!function(e,t,n){const i="function"==typeof e.attributes?e.attributes(t):e.attributes;i&&(n.attributes={...n.attributes,...i})}(t,o,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,o);void 0!==e&&(n.charges[t.id]=e)}it(e.bodyId,t,t.impulseOnEnter),rt("region-enter",t,e)}else"physics-proximity-exit"===e.type&&(n.activeRegionIds.delete(t.id),it(e.bodyId,t,t.impulseOnExit),rt("region-exit",t,e))},[it,rt,_e]),st=u.useMemo(()=>{if(!i?.length)return[];const e=i.filter(e=>"barrier"===e.physics||"sensor"===e.physics);return e.length?function(e=[],t={}){const n=t.idPrefix?t.idPrefix+"-":"",i=[];for(const r of e){if("barrier"!==r.physics&&"sensor"!==r.physics)continue;const e=r.axis??t.defaultAxis??"x",o=tn(r,t),s=r.colliderId??`${n}${r.id}`;let a;if("x"===e){const e=en(r.x),n=en(r.y1)??en(t.plotBounds?.y)??en(r.y),i=en(r.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??en(r.y);if(null==e||null==n||null==i)continue;a={type:"segment",x1:e,y1:n,x2:e,y2:i,thickness:o}}else{const e=en(r.y),n=en(r.x1)??en(t.plotBounds?.x)??en(r.x),i=en(r.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??en(r.x);if(null==e||null==n||null==i)continue;a={type:"segment",x1:n,y1:e,x2:i,y2:e,thickness:o}}i.push({id:s,shape:a,sensor:"sensor"===r.physics,..."barrier"!==r.physics||null==r.restitution&&null==t.barrierRestitution?{}:{restitution:en(r.restitution)??en(t.barrierRestitution)},..."barrier"!==r.physics||null==r.friction&&null==t.barrierFriction?{}:{friction:en(r.friction)??en(t.barrierFriction)}})}return i}(e,{idPrefix:f?f+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:Me?.[0]??Yr[0],height:Me?.[1]??Yr[1]}}):[]},[i,f,Me]),at=u.useMemo(()=>{const e=ie.flatMap(e=>[{id:cr(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...lr(e)]),t=Object.fromEntries(ie.map(e=>[cr(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),n=b?.observation,i=ie.length>0;return i||e.length>0||st.length>0||null!=f||n?{...b,colliders:[...b?.colliders??[],...e,...st],observation:{...n,chartId:f??n?.chartId,chartType:n?.chartType??_r,sensors:{...n?.sensors??{},...t},onObservation:e=>{i&&ot(e),n?.onObservation?.(e)}}}:b},[st,f,b,ot,ie]);if(!tt.current){const e=Xr(at,C,P);e.setPaused(ne),Ae&&e.setVisible(Ui()),tt.current=e}const ct=(0,h.useRef)(null),lt=(0,h.useRef)(-1),dt=(0,h.useRef)(null),ut=(0,h.useRef)(!0),ht=(0,h.useRef)(""),pt=(0,h.useId)().replace(/:/g,""),ft=(0,h.useRef)(!1),mt=(0,h.useRef)(!1),yt=(0,h.useRef)(0),gt=(0,h.useRef)(!1),xt=(0,h.useRef)(null),bt=(0,h.useRef)(!1),vt=z({sizeProp:Me,responsiveWidth:oe,responsiveHeight:re,userMargin:q,marginDefault:Hr,foregroundGraphics:j,backgroundGraphics:s,frameScheduler:y}),{margin:wt,rafRef:kt,reducedMotionRef:Mt,renderFnRef:St,cancelRender:It,resolvedBackground:jt,resolvedForeground:At,responsiveRef:Ct,scheduleRender:Pt,size:Rt}=vt,Dt=function(){const[e,t]=(0,W.useState)(!1);return F(()=>{t(!0)},[]),e}(),$t=function(){const e=(0,W.useSyncExternalStore)(O,L,Y);return(0,W.useRef)(e).current}(),[Bt,Tt]=u.useState(null),[Et,Nt]=u.useState(null),qt=(0,h.useRef)(null),zt=(0,h.useRef)(0),Wt=(0,h.useRef)(new Map),Ft=pt+"-physics-live",Ot=(0,h.useCallback)((e,t,n=!1)=>{if(!c)return void Qe(e=>e.length?[]:e);const i=nt.current();if(!n&&l>0&&l>i-zt.current)return;zt.current=i;const r=function(e,t,n,i){if(!n)return[];const r=Math.max(0,Math.floor(i));if(!r)return[];const o=[];for(let i=0;e.length>i&&r>o.length;i+=1){const r=e[i],s="function"==typeof n?n(r,{index:i,simulationState:t}):void 0;if(!1===s)continue;const a=Tr(r);o.push({datum:r.datum??r,description:Nr(r),group:"body",label:Er(r),...a,...s??{},bodyId:s?.bodyId??r.id,id:s?.id??"body:"+r.id,x:s?.x??r.x,y:s?.y??r.y})}return o}(e,t,c,a);Qe(e=>function(e,t){if(e.length!==t.length)return!0;for(let n=0;e.length>n;n+=1){const i=e[n],r=t[n];if(i.id!==r.id||i.label!==r.label||i.description!==r.description||i.group!==r.group||i.bodyId!==r.bodyId||Math.round(i.x)!==Math.round(r.x)||Math.round(i.y)!==Math.round(r.y))return!0}return!1}(e,r)?r:e)},[a,c,l]),Lt=(0,h.useCallback)(e=>{if(!Ze.length)return;const t=Math.max(0,Math.min(e,Ze.length-1));lt.current=t;const n=Ze[t];if(qt.current=n.bodyId??null,Tt(n),J?.(n),n.bodyId&&tt.current){const e=tt.current.readBodies().find(e=>e.id===n.bodyId);if(e){const t=Br(e);Nt(t),V?.(e,t)}}},[Ze,V,J]),Yt=(0,h.useCallback)(()=>{lt.current=-1,qt.current=null,Tt(null),J?.(null)},[J]),Ht=(0,h.useCallback)((e,t)=>{const n=Ne.current;if(!n)return;const i=nt.current();n("hover"!==e&&"click"!==e?{type:e,timestamp:i,chartType:_r,chartId:qe.current}:{type:e,datum:t?.datum??{},x:t?.x??0,y:t?.y??0,timestamp:i,chartType:_r,chartId:qe.current})},[]),Gt=(0,h.useCallback)(()=>{Nt(e=>e?(V?.(null,null),Ht("hover-end"),null):e)},[Ht,V]),Xt=(0,h.useCallback)(e=>{if(!I||!tt.current)return;const t=e.currentTarget.getBoundingClientRect(),n=tt.current.hitTest(e.clientX-t.left,e.clientY-t.top,A);if(!n)return void Gt();const i=Br(n);Nt(e=>e&&e.id===i.id&&e.x===i.x&&e.y===i.y?e:(V?.(n,i),Ht("hover",{datum:n.datum,x:n.x,y:n.y}),i))},[Gt,Ht,I,A,V]),_t=(0,h.useCallback)(e=>{Yt();const t=tt.current,n=e.currentTarget.getBoundingClientRect(),i=e.clientX-n.left,r=e.clientY-n.top,o=t?t.hitTest(i,r,Math.max(16,A)):null;U?.(o,e),o?(Ht("click",{datum:o.datum,x:o.x,y:o.y}),H?.(o.datum??null,{x:o.x,y:o.y,body:o})):(Ht("click-end"),H?.(null,{x:i,y:r,body:null}),Gt())},[Gt,Yt,Ht,A,U,H]);(0,h.useEffect)(()=>{if(!Ze.length)return void Yt();const e=lt.current;if(Ze.length>e){if(e>=0){const t=Ze[e];if(qt.current=t.bodyId??null,Tt(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&&tt.current){const e=tt.current.readBodies().find(e=>e.id===t.bodyId);if(e){const t=Br(e);Nt(e=>e?.id===t.id&&Math.round(e.x)===Math.round(t.x)&&Math.round(e.y)===Math.round(t.y)?e:t)}}}}else Lt(Ze.length-1)},[Ze,Yt,Lt]),(0,h.useEffect)(()=>{I||Gt()},[Gt,I]);const Vt=(0,h.useCallback)(e=>{if(!Ze.length)return;if("Escape"===e.key)return e.preventDefault(),void Yt();if(("Enter"===e.key||" "===e.key)&&lt.current>=0)return e.preventDefault(),void K?.(Ze[lt.current]);if(!Gr.has(e.key))return;e.preventDefault();const t=lt.current;if(0>t)return void Lt(0);const n=Math.max(1,Math.floor(.1*Ze.length));let i=t;"Home"===e.key?i=0:"End"===e.key?i=Ze.length-1:"PageDown"===e.key?i=Math.min(Ze.length-1,t+n):"PageUp"===e.key?i=Math.max(0,t-n):"ArrowRight"===e.key||"ArrowDown"===e.key?i=Math.min(Ze.length-1,t+1):"ArrowLeft"!==e.key&&"ArrowUp"!==e.key||(i=Math.max(0,t-1)),Lt(i)},[Yt,Lt,K,Ze]),[Ut,Qt]=u.useState([]),Zt=(0,h.useRef)(0),rn=!!i?.length&&i.some(e=>null!=e.pointId||null!=e.bodyId||"latest"===e.anchor),sn=(0,h.useCallback)(()=>{const e=ct.current,t=tt.current;if(!e||!t)return;const n=function(){if("undefined"==typeof window)return 1;const e=window.devicePixelRatio||1,t=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(e,t))}(),i=function(e,t,n,i){const r=e.getContext("2d");if(!r)return null;const o=Math.round(t[0]*i),s=Math.round(t[1]*i),a=o/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===o&&e.height===s||(e.width=o,e.height=s),r.setTransform(a,0,0,c,0,0),r.translate(n.left,n.top),r}(e,Rt,wt,n);if(!i)return;const r=function(e){const t=xe(e,pe),n=xe(e,de),i=xe(e,ge),r=xe(e,fe),o=xe(e,le),s=xe(e,ce),a=xe(e,me),c=xe(e,ye),l=xe(e,ue),d=xe(e,he);return{annotationBackground:be(s,.94),annotationStroke:o,annotationText:a,background:s,border:o,closedWindowFill:be(n,.08),closedWindowStroke:be(n,.55),danger:n,focus:l,grid:d,gutterFill:be(c,.14),lateFill:i,openWindowFill:be(t,.07),openWindowStroke:be(t,.3),primary:t,selectedFill:i,selectedStroke:l,success:r,text:a,textSecondary:c,warning:i}}(i);i.clearRect(-wt.left,-wt.top,Rt[0],Rt[1]),s||"transparent"===o||(i.fillStyle=o??r.background,i.fillRect(-wt.left,-wt.top,Rt[0],Rt[1]));const a=t.snapshot(),c=t.readBodies();if(Ot(c,a.simulationState),rn){const e=nt.current();if(e-Zt.current>=100){Zt.current=e;const t=Kt(c);Qt(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&&(i.save(),Be(i,c),i.restore());for(const e of c){const t=ze.current.get(e.id),n=t?Array.from(t.activeRegionIds).map(e=>Ve.get(e)).filter(e=>null!=e):[],o=gr(e,a.simulationState,p,se,ve,dr(t),n,r.primary,r.text,Ee);$e?(i.save(),$e(i,e,o),i.restore()):sr(i,e,o)}Te&&(i.save(),Te(i,c),i.restore()),function(e,t,n){let i=!1;for(const[r,o]of t){const s=Math.min(1,Math.max(0,(n-o.startedAt)/o.durationMs));if(s>=1){t.delete(r);continue}i=!0;const a=1-Math.pow(1-s,3),{body:c}=o,l=o.radius+28*a,d=1-s;e.save(),e.globalAlpha*=d,e.strokeStyle=o.color,e.fillStyle=o.color,e.lineWidth=2.4*d+.4,e.beginPath(),e.arc(c.x,c.y,l,0,2*Math.PI),e.stroke(),e.globalAlpha*=.18,e.beginPath(),e.arc(c.x,c.y,.52*l,0,2*Math.PI),e.fill(),e.restore(),e.save(),e.globalAlpha*=d,e.strokeStyle=o.color,e.lineWidth=1.8;for(let t=0;8>t;t+=1){const n=t*(Math.PI/4)+1.4*s,i=o.radius+5+12*a,r=o.radius+12+34*a;e.beginPath(),e.moveTo(c.x+Math.cos(n)*i,c.y+Math.sin(n)*i),e.lineTo(c.x+Math.cos(n)*r,c.y+Math.sin(n)*r),e.stroke()}e.restore()}}(i,Wt.current,nt.current()),ut.current=!1},[Te,o,s,Be,p,wt,rn,Ve,$e,se,ve,Ee,Ot,Rt]),an=(0,h.useCallback)((e,t)=>{const n=tt.current,i=`${ke}:${e}:${t??""}`;ht.current!==i&&(ht.current=i,_?.({execution:e,liveBodies:n?.liveBodyCount()??0,queuedBodies:n?.queueSize()??0,reason:t,requested:ke}))},[_,ke]),ln=(0,h.useCallback)((e,t=!0)=>{yt.current+=1,ft.current=!1,gt.current=!1,bt.current=!1,xt.current?.terminate(),xt.current=null,t&&an("sync",e)},[an]),dn=(0,h.useCallback)(()=>Dt?"undefined"==typeof window||"undefined"==typeof Worker?"worker unavailable":Je?"runtime region effects require sync":et?"body forces require sync":Le?"physics controllers require sync":function(e){return!e||!e.engine&&on(e.sediment)&&(!(t=e.colliders)||t.every(e=>{const t=e.bodyFilter;return!t||"function"!=typeof t}));var t}(at??{})?cn(P)?mt.current?"worker fallback":null:"spawn pacing is not worker-cloneable":"config is not worker-cloneable":"hydrating",[at,Le,et,Je,Dt,P]),un=(0,h.useCallback)(()=>{const e=tt.current,t=dn();if(!e||t)return{reason:t,useWorker:!1};const n=e.liveBodyCount(),i=e.queueSize(),r=function(e,t,n=0,i=nn){return"sync"!==e&&("worker"===e||t+n>=i)}(ke,n,i,De);return{reason:r?"worker"===ke?"forced worker":"body threshold":"below threshold",useWorker:r}},[ke,De,dn]),pn=(0,h.useCallback)(e=>{const t=tt.current;return t&&e.snapshot?(t.restore(e.snapshot),ut.current=!0,t):t},[]),fn=(0,h.useCallback)((e,t=!0)=>{const n=pn(e);if(!n)return;t&&ee?.(e.result,n.controls()),sn();const i=n.snapshot();!e.result.shouldContinue&&Wt.current.size<=0||i.paused||!i.visible||Mt.current||Pt()},[pn,ee,sn,Mt,Pt]),mn=(0,h.useCallback)(e=>{mt.current=!0,ln("worker failed: "+((e instanceof Error?e.message:e+"")||"unknown error"))},[ln]),yn=(0,h.useCallback)(()=>{const e=tt.current;if(!e)return!1;const t=un();if(!t.useWorker)return ft.current||bt.current?ln(t.reason??"sync fallback"):an("sync",t.reason??"sync"),!1;if(ft.current||bt.current)return!0;const n=xt.current??new hn;xt.current=n,bt.current=!0;const i=yt.current+1;return yt.current=i,n.initFromSnapshot(at??{},e.snapshot()).then(e=>{if(yt.current!==i)return;bt.current=!1,ft.current=!0,mt.current=!1,pn(e),an("worker",t.reason??"worker"),sn();const n=tt.current?.snapshot();e.result.shouldContinue&&n&&!n.paused&&n.visible&&!Mt.current&&(dt.current=null,Pt())}).catch(e=>{yt.current===i&&mn(e)}),!0},[pn,at,mn,sn,Mt,an,Pt,ln,un]),gn=(0,h.useCallback)(e=>"frame"===e.type||"removed"===e.type?e.frame:null,[]),xn=(0,h.useCallback)((e,t=!0)=>{const n=xt.current;if(!n||!ft.current)return;const i=yt.current;n.request(e).then(e=>{if(yt.current!==i)return;const n=gn(e);n&&fn(n,t)}).catch(mn)},[fn,gn,mn]),bn=(0,h.useCallback)(()=>{const e=tt.current;if(!e)return;const t=yn(),n=e.snapshot(),i=He||et||Je||!!Le;n.paused||!n.visible||!e.hasPendingWork()&&!i||Mt.current?St.current():t&&bt.current||(dt.current=null,Pt())},[Le,He,et,Je,Mt,St,Pt,yn]),vn=(0,h.useCallback)(()=>{It(),kt.current=null;const e=tt.current;if(!e)return;if(ft.current&&xt.current){if(gt.current)return;let t=0;if(!Mt.current){const e=nt.current();t=null!==dt.current?(e-dt.current)/1e3:0,dt.current=e}const n=xt.current,i=yt.current;return gt.current=!0,void(Mt.current?n.settle():n.tick(t)).then(e=>{gt.current=!1,yt.current===i&&fn(e)}).catch(n=>{if(gt.current=!1,yt.current!==i)return;mn(n);const r=Mt.current?e.settleWithObservations():e.tick(t);yr({store:e,result:r,regionEffects:We.current,regionState:ze.current,bodyForces:Fe.current,composed:Ye.current,onTick:Oe.current}),sn()})}let t;if(Mt.current)t=e.settleWithObservations();else{const n=nt.current(),i=null!==dt.current?(n-dt.current)/1e3:0;dt.current=n,t=e.tick(i)}const n=Ye.current,{regionEffectsApplied:i,bodyForcesApplied:r,snapshot:o}=yr({store:e,result:t,regionEffects:We.current,regionState:ze.current,bodyForces:Fe.current,composed:n,onTick:Oe.current});sn(),(Ge.current||t.shouldContinue||i||r||n||Wt.current.size>0)&&!o.paused&&o.visible&&!Mt.current&&Pt()},[fn,mn,sn,It,Pt,Mt,kt]);St.current=vn,function(e){const{hydrated:t,wasHydratingFromSSR:n,storeRef:i,dirtyRef:r,renderFnRef:o,cancelRender:s,cleanup:a}=e;F(()=>{t&&n&&i.current?.cancelIntroAnimation?.(),r.current=!0,s?.(),o.current()},[t,n]);const c=(0,W.useRef)(a);c.current=a,(0,W.useEffect)(()=>()=>c.current?.(),[])}({hydrated:Dt,wasHydratingFromSSR:$t,storeRef:tt,dirtyRef:ut,renderFnRef:St,cancelRender:It}),(0,h.useEffect)(()=>{mt.current=!1,(ft.current||bt.current)&&ln("config changed",!1),tt.current?.updateConfig(at??{}),bn()},[at,ln]),(0,h.useEffect)(()=>{mt.current=!1,bn()},[Dt,ke,De]),function({cancelRender:e,lastFrameTimeRef:t,paused:n,postWorkerCommand:i,requestRender:r,storeRef:o,suspendWhenHidden:s}){const a=(0,Vi.useRef)(i);a.current=i;const c=(0,Vi.useRef)(r);c.current=r,(0,Vi.useEffect)(()=>{const i=o.current;i&&(i.setPaused(n),n&&(t.current=null,e()),a.current({type:"setPaused",paused:n},!1),c.current())},[e,n]),(0,Vi.useEffect)(()=>{if(!s||"undefined"==typeof document)return;const n=()=>{const n=o.current;if(!n)return;const i=Ui();n.setVisible(i),i||(t.current=null,e()),a.current({type:"setVisible",visible:i},!1),c.current()};return n(),document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[e,s])}({cancelRender:It,lastFrameTimeRef:dt,paused:ne,postWorkerCommand:xn,requestRender:bn,storeRef:tt,suspendWhenHidden:Ae}),(0,h.useEffect)(()=>()=>ln("unmount",!1),[ln]),(0,h.useEffect)(()=>{sn()},[sn]),(0,h.useImperativeHandle)(t,()=>({...tt.current.controls(),applyImpulse:(e,t,n)=>{tt.current.applyImpulse(e,t,n),xn({type:"applyImpulse",id:e,ix:t,iy:n}),bn()},clear:()=>{tt.current.clear(),ze.current.clear(),Wt.current.clear(),xn({type:"clear"}),bn()},clearRegionState:e=>{e?ze.current.delete(e):ze.current.clear(),bn()},getData:()=>tt.current.readBodies(),getRegionState:e=>e?dr(ze.current.get(e)):function(e){const t={};return e.forEach((e,n)=>{const i=dr(e);i&&(t[n]=i)}),t}(ze.current),getStore:()=>tt.current,pause:()=>{tt.current.setPaused(!0),xn({type:"setPaused",paused:!0},!1),bn()},push:(e,t)=>{tt.current.enqueue(e,t),cn(t)?xn({type:"enqueue",spawns:[e],pacing:t}):(ft.current||bt.current)&&ln("spawn pacing is not worker-cloneable"),bn()},pushMany:(e,t)=>{tt.current.enqueue(e,t),cn(t)?xn({type:"enqueue",spawns:e,pacing:t}):(ft.current||bt.current)&&ln("spawn pacing is not worker-cloneable"),bn()},popBodies:(e,t={})=>{const n=tt.current,i=new Map(n.readBodies().map(e=>[e.id,e])),r=n.remove(e),o=nt.current();for(const e of r){const n=i.get(e);n&&(ze.current.delete(e),Wt.current.set(e,{body:n,color:t.color??"#f59e0b",durationMs:Math.max(120,t.durationMs??520),radius:t.radius??ar(n),startedAt:o}),qt.current===e&&(qt.current=null,Tt(null)),Nt(t=>t?.id===e?null:t))}return r.length&&(xn({type:"remove",ids:r}),bn()),r},remove:e=>{const t=tt.current.remove(e);for(const t of e)ze.current.delete(t);return xn({type:"remove",ids:e}),bn(),t},restore:e=>{tt.current.restore(e),ze.current.clear(),Wt.current.clear(),xn({type:"restore",snapshot:e},!1),bn()},resume:()=>{tt.current.setPaused(!1),xn({type:"setPaused",paused:!1},!1),bn()},settle:e=>{const t=tt.current.settle(e);return xn({type:"settle",maxSteps:e}),bn(),t},settleWithObservations:e=>{const t=tt.current.settleWithObservations(e);return xn({type:"settle",maxSteps:e}),bn(),t},step:e=>{const t=tt.current,n=t.tick(e);return yr({store:t,result:n,regionEffects:We.current,regionState:ze.current,bodyForces:Fe.current,composed:Ye.current,onTick:Oe.current}),xn({type:"tick",deltaSeconds:e}),sn(),n}}),[sn,xn,bn,ln]);const wn=Z||!Dt&&$t,kn=["stream-physics-frame",S?"stream-physics-frame--mode-"+S:null,M?"stream-physics-frame--emphasis-"+M:null,m].filter(Boolean).join(" "),Mn=k??("string"==typeof Pe?Pe:void 0)??"Physics chart",Sn=pt+"-physics-table",In=Math.max(1,Rt[0]-wt.left-wt.right),jn=Math.max(1,Rt[1]-wt.top-wt.bottom),An=I&&Et?Re?Re(Et):(0,Lr.jsx)(zr,{hover:Et}):null,Cn=An&&Et?(0,Lr.jsx)(ae,{x:Et.x-wt.left,y:Et.y-wt.top,containerWidth:Math.max(1,Rt[0]-wt.left-wt.right),containerHeight:Math.max(1,Rt[1]-wt.top-wt.bottom),margin:wt,className:"stream-physics-tooltip",children:An}):null;if(wn){const e=tt.current??Xr(at,C,P),t="string"==typeof Pe?Pe:void 0,{svg:n}=function(e,t={}){const{width:n=640,height:i=360,title:r,description:o,background:s,className:a,idPrefix:c="physics",...l}=t,d=Di(e,l),u=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(c),h=r?u+"-title":void 0,p=o?u+"-desc":void 0,f=[h,p].filter(Boolean).join(" ")||void 0;return{svg:ji.renderToStaticMarkup((0,$i.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:a??"stream-physics-frame",width:n,height:i,viewBox:`0 0 ${n} ${i}`,role:"img","aria-labelledby":f,children:[r&&(0,$i.jsx)("title",{id:h,children:r}),o&&(0,$i.jsx)("desc",{id:p,children:o}),s&&"transparent"!==s?(0,$i.jsx)("rect",{x:0,y:0,width:n,height:i,fill:s}):null,(0,$i.jsx)("g",{id:u+"-data-area",children:d.sceneNodes.map((e,t)=>Q(e,t,u))})]})),scene:d,evidence:d.evidence}}(e,{width:Rt[0],height:Rt[1],title:t,description:k,background:"transparent"===o?void 0:o,className:"stream-physics-frame__svg",idPrefix:"physics-"+pt});return(0,Lr.jsxs)("div",{ref:Ct,className:kn,"data-semiotic-mode":S,role:"img","aria-label":Mn,style:{width:Rt[0],height:Rt[1]},children:[(0,Lr.jsx)(ir,{summary:je}),(0,Lr.jsx)("div",{dangerouslySetInnerHTML:{__html:n}})]})}return(0,Lr.jsxs)("div",{ref:Ct,className:kn,"data-semiotic-mode":S,role:"group","aria-label":Mn,"aria-describedby":Bt?Ft:void 0,tabIndex:0,style:{position:"relative",width:Rt[0],height:Rt[1]},onKeyDown:Vt,children:[n?(0,Lr.jsx)(rr,{tableId:Sn}):null,n?(0,Lr.jsx)(Or,{chartTitle:"string"==typeof Pe?Pe:Mn,items:Ze,tableId:Sn}):null,(0,Lr.jsx)(ir,{summary:je}),(0,Lr.jsx)(or,{hoverPoint:Et}),(0,Lr.jsx)("div",{id:Ft,"aria-live":"polite","aria-atomic":"true",style:vr,children:Bt?Bt.description??Bt.label:""}),(0,Lr.jsxs)("div",{role:"img","aria-label":Mn,style:{position:"relative",width:"100%",height:"100%"},children:[jt,(0,Lr.jsx)("canvas",{ref:ct,width:Rt[0],height:Rt[1],"aria-hidden":"true",onPointerDown:_t,onPointerMove:I?Xt:void 0,onPointerLeave:I?Gt:void 0}),At,(0,Lr.jsx)(Jt,{width:In,height:jn,totalWidth:Rt[0],totalHeight:Rt[1],margin:wt,title:Pe,legend:R,legendPosition:N,legendLayout:E,legendHoverBehavior:B,legendClickBehavior:D,legendHighlightedCategory:$,legendIsolatedCategories:T,pointNodes:Ut,annotations:i,autoPlaceAnnotations:r,svgAnnotationRules:Ce}),(0,Lr.jsx)(Zi,{active:null!=Bt,hoverPoint:Bt?{x:Bt.x,y:Bt.y}:null,margin:wt,size:Rt,shape:Bt?.shape,width:Bt?.width,height:Bt?.height,pathData:Bt?.pathData}),Cn]})]})}));Ur.displayName="StreamPhysicsFrame";var Kr=Ur;function Qr(e){const[t,n]=e;return{width:t,height:n,plot:{x:32,y:24,width:Math.max(80,t-64),height:Math.max(80,n-58)}}}function Zr(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 Jr(e,t="#4e79a7"){return n=>{const i=n.datum,r=i&&e?"function"==typeof e?e(i,0):i[e]:void 0;return{fill:null==r?t:Zr(r),stroke:"#111827",strokeWidth:1,opacity:.9}}}function eo(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 to(e,t,n){if(!e.length)return[];const i=Qr(t),r=i.plot.width/Math.max(1,e.length),o=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/o*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)*r,y:a-c/2,shape:"rect",width:Math.max(12,.58*r),height:c,group:n}})}function no(e,t,n){return"function"==typeof n?n(e,t):e[n]}function io(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 ro(e,t,n){return Math.max(t,Math.min(n,e))}function oo(e,t){const n=io(e);return null!=n&&n>0?n:t}function so(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function ao(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 co=require("d3-scale");function lo(e){const{data:t,valueAccessor:n,bins:i,ballRadius:r,seed:o,size:s,valueExtent:a}=e,c=Qr(s),l=t.map((e,t)=>io(no(e,t,n))).filter(e=>null!=e),d=function(e){if(!e)return;const t=io(e[0]),n=io(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,f=(0,co.scaleLinear)().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),m=Array.from({length:i},()=>0),y=[];t.forEach((e,t)=>{const o=io(no(e,t,n));if(null==o)return;const s=Math.max(0,Math.min(i-1,Math.floor((o-u)/p*i)));m[s]+=1,y.push({id:(e.id??"galton-"+t)+"",x:f(s+.5),y:c.plot.y+r+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,value:o,bin:s}})});const g=c.plot.y+c.plot.height;return{config:eo(o,[...di({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...ui({idPrefix:"galton-bin",count:i,domainStart:0,domainStep:1,xScale:f,yTop:c.plot.y-400,yBottom:g,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:i,plot:c.plot,valueExtent:[u,h]}}}var uo=require("d3-scale");function ho(e){const{count:t,idPrefix:n,wallThickness:i,xScale:r,yBottom:o,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const c=Math.min(o-1,a?.(t)??s),l=Math.max(1,o-c);return{id:`${n}-wall-${t}`,shape:{type:"aabb",x:r(t),y:c+l/2,width:i,height:l}}})}function po(e){const{data:t,timeAccessor:n,arrivalAccessor:i,windows:r,watermark:o,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:d=1}=e,u=Qr(c),h=t.map((e,t)=>io(no(e,t,n))).filter(e=>null!=e),p=io(l?.[0]),f=io(l?.[1]),m=h.length?Math.min(...h):0,y=h.length?Math.max(...h):m+r.size,g=Math.min(p??m,m),x=Math.max(f??y,y),b=Math.floor(g/r.size)*r.size,v=Math.max(1,Math.ceil((x-b+r.size)/r.size)),w=h.length?Math.max(...h):0,k="function"==typeof o?o(w):io(o?.value)??w-(o?.delay??r.size),M=Math.max(0,Math.min(v,Array.from({length:v},(e,t)=>t).reduce((e,t)=>b+(t+1)*r.size>k?e:e+1,0))),S=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),I=b+v*r.size,j=(0,uo.scaleLinear)().domain([b,I]).range([S.windowPlot.x,S.windowPlot.x+S.windowPlot.width]),A=Array.from({length:v},()=>({value:0,secondary:0})),C=[];t.forEach((e,t)=>{const o=io(no(e,t,n));if(null==o)return;const a=io(no(e,t,i))??o,c=Math.max(0,Math.min(v-1,Math.floor((o-b)/r.size))),l=k>=b+(c+1)*r.size;A[c].value+=l?0:1,A[c].secondary+=l?1:0,C.push({id:(e.id??"event-"+t)+"",x:Math.max(S.windowPlot.x+s,Math.min(S.windowPlot.x+S.windowPlot.width-s,j(o))),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:o,arrivalTime:a,windowIndex:c,late:l}})});const P=u.plot.y+u.plot.height,R=function(e,t){const n=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!n)return[];const i=e.windowStart,r=e.windowStart+e.windowCount*e.windowSize,o=(0,uo.scaleLinear)().domain([i,r]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=o(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,r=o(n),s=o(i);d.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:r,y1:l(r),x2:s,y2:l(s)})}return d}({closedWindowCount:M,gutter:S.gutter,plot:u.plot,windowCount:v,windowPlot:S.windowPlot,windowSize:r.size,windowStart:b},u.plot.y+.28*u.plot.height);return{config:eo(a,[...di({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...ho({idPrefix:"eventdrop-window",count:v,xScale:e=>j(b+e*r.size),yTop:S.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>M)return null;const t=0===e?R[0]?.y1:R[e-1]?.y2??R[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?S.wallTop:t+1.25*s},yBottom:P,wallThickness:6}),...R.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:`${b+t*r.size}-${b+(t+1)*r.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:M,gutter:S.gutter,lidSegments:R,lateCount:A.reduce((e,t)=>e+t.secondary,0),plot:u.plot,windowPlot:S.windowPlot,watermarkValue:k,windowCount:v,windowSize:r.size,windowStart:b}}}function fo(e,t,n){const i=e.width/Math.max(1,t),r=Math.max(2,2*n),o=Math.min(.7*i,Math.max(3.2*r,r+8)),s=Math.max(1,Math.floor(o/r));return{laneWidth:i,tubeWidth:o,ballDiameter:r,perRow:s,centerX:t=>e.x+(t+.5)*i,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*r}}function mo(e){const{data:t,categoryAccessor:n,valueAccessor:i,unitValue:r,ballRadius:o,seed:s,size:a}=e,c=oo(r,1),l=Qr(a),d=[],u=new Map,h=new Map,p=[];function f(e){let t=u.get(e);return null==t&&(t=d.length,d.push(e),u.set(e,t)),t}t.forEach((e,t)=>{f((no(e,t,n)??"unknown")+"")});const m=Math.max(1,d.length),y=fo(l.plot,m,o),g=Math.max(0,y.tubeWidth/2-o-1),x=d.map(()=>[]);t.forEach((e,t)=>{const r=(no(e,t,n)??"unknown")+"",s=f(r),a=i?io(no(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(r)??0,a=y.perRow>1?((y.perRow>1?i%y.perRow:0)/(y.perRow-1)*2-1)*g:0;h.set(r,i+1),x[s].push({id:`${(e.id??"pile-"+t)+""}-${n}`,x:u+a,y:l.plot.y+o+2,vx:(n%3-1)*o/2,vy:0,mass:1,shape:{type:"circle",radius:o},datum:{...e,category:r,unitIndex:n}})}});const b=x.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;b>e;e+=1)for(const t of x)t.length>e&&p.push(t[e]);const v=l.plot.y+l.plot.height,w=[...di({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;m>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:eo(s,w,"PhysicsPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:h.get(e)??0}))}}var yo=require("d3-scale");function go(e){const{data:t,xAccessor:n,groupAccessor:i,radiusAccessor:r,pointRadius:o,seed:s,size:a,xExtent:c,collisionIterations:l,settle:d}=e,u=Qr(a),h=ao(s),p=[],f=[],m=new Map;t.forEach((e,t)=>{const s=io(no(e,t,n));if(null==s)return;const a=i?(no(e,t,i)??"All")+"":"All",c=r?io(no(e,t,r)):null,l=ro(null!=c&&c>0?c:o,2,18);!function(e){let t=m.get(e);null==t&&(t=f.length,f.push(e),m.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?io(c[0]):null,x=c?io(c[1]):null,b=y.length?Math.min(...y):0,v=y.length?Math.max(...y):1;let w=g??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){const e=k;k=w,w=e}const M=Math.max(o,...p.map(e=>e.radius)),S=u.plot.x+M+8,I=u.plot.x+u.plot.width-M-8,j=(0,yo.scaleLinear)().domain([w,k]).range([S,I]),A=Math.max(1,f.length),C=u.plot.y+Math.max(28,3*M),P=Math.max(0,u.plot.y+u.plot.height-Math.max(28,3*M)-C),R=e=>{const t=m.get(e)??0;return 1===A?u.plot.y+.54*u.plot.height:C+t/(A-1)*P},D=new Map,$=p.map((e,t)=>{D.set(e.group,(D.get(e.group)??0)+1);const n=j(e.value),i=R(e.group),r=(h()-.5)*e.radius*1.6,o=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:d?n+r:ro(n+(t%9-4)*e.radius*2.5,S,I),y:d?i+o: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:eo(s,di({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:$,projectionRows:f.map(e=>({label:e,value:D.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[S,I],groups:f.map(e=>({label:e,y:R(e),count:D.get(e)??0})),plot:u.plot}}}function xo(e){if(Array.isArray(e)&&e.length>=2){const t=io(e[0]),n=io(e[1]);return null!=t&&null!=n?{x:t,y:n}:null}if(e&&"object"==typeof e){const t=e,n=io(t.x),i=io(t.y);return null!=n&&null!=i?{x:n,y:i}:null}return null}function bo(e){return Array.isArray(e)?e.map(xo).filter(e=>null!=e):[]}function vo(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:ro(e.x,t.plot.x,t.plot.x+t.plot.width),y:ro(e.y,t.plot.y,t.plot.y+t.plot.height)}}function wo(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 ko(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const n=ro(t,0,1)*wo(e);let i=0;for(let t=1;e.length>t;t+=1){const r=e[t-1],o=e[t],s=Math.hypot(o.x-r.x,o.y-r.y);if(s>0){if(i+s>=n){const e=(n-i)/s;return{x:r.x+(o.x-r.x)*e,y:r.y+(o.y-r.y)*e}}i+=s}}return{...e[e.length-1]}}function Mo(e,t){const n=ko(e,Math.max(0,t-.02)),i=ko(e,Math.min(1,t+.02)),r=i.x-n.x,o=i.y-n.y,s=Math.hypot(r,o)||1;return{x:r/s,y:o/s}}function So(e){const{coordinateMode:t,flowSpeed:n,links:i,maxParticles:r,nodeIdAccessor:o,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:d,pathAccessor:u,pathConstraint:h="path",reducedMotion:p,seed:f,size:m,sourceAccessor:y,targetAccessor:g,throughputAccessor:x}=e,b=Qr(m),v=ao(f),w=new Map,k=new Map,M=[];function S(e){if(e&&"object"==typeof e){const t=e;if("function"==typeof o){const e=o(t,0);if(null!=e)return e+""}if("string"==typeof o&&null!=t[o])return t[o]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}c.forEach((e,t)=>{const n=(no(e,t,o)??e.id??t)+"",i=io(no(e,t,s)),r=io(no(e,t,a));if(null!=i&&null!=r){const e={x:i,y:r};w.set(n,e),M.push(e)}k.set(n,(e.label??e.name??n)+"")});const I=[];i.forEach((e,t)=>{const n=S(no(e,t,y)),i=S(no(e,t,g)),r=Math.max(0,io(no(e,t,x))??0),o=bo(u?no(e,t,u):void 0),s=o.length?o:bo(e.path??e.points??e.route);s.forEach(e=>M.push(e)),I.push({id:(e.id??`physical-flow-${n}-${i}-${t}`)+"",link:e,index:t,source:n,target:i,throughput:r,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 P=new Map;for(const[e,t]of w)P.set(e,vo(t,b,j));const R=[];for(const e of I){let t=e.rawPath.map(e=>vo(e,b,j));if(2>t.length){const n=P.get(e.source),i=P.get(e.target);n&&i&&(t=[n,i])}else P.has(e.source)||P.set(e.source,t[0]),P.has(e.target)||P.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),R.push({...e,path:t,packetCount:0}))}const D=oo(d,.12),$=Math.max(1,Math.round(r)),B=R.map(e=>Math.max(1,Math.round(e.throughput*D))),T=B.reduce((e,t)=>e+t,0),E=T>$?$/T:1;R.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(B[t]*E))});let N=R.reduce((e,t)=>e+t.packetCount,0);for(;N>$;){const e=R.reduce((e,t,n)=>t.packetCount>1&&(-1===e||t.packetCount>R[e].packetCount)?n:e,-1);if(-1===e)break;R[e].packetCount-=1,N-=1}const q=new Map,z=new Map,W=[],F=oo(n,90),O=oo(l,4);R.forEach((e,t)=>{q.set(e.target,(q.get(e.target)??0)+e.throughput),z.set(e.source,(z.get(e.source)??0)+e.throughput);const n=wo(e.path);for(let i=0;e.packetCount>i;i+=1){const r=(i+.5)/e.packetCount,o=p?r:ro(.12+.84*r+.04*(v()-.5),.04,.98),s=p?o:Math.max(0,o-(.18+.12*v())),a=ko(e.path,s),c=ko(e.path,o),l=Mo(e.path,s),d={x:-l.y,y:l.x},u=(v()-.5)*O*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*F+10*(v()-.5),vy:p?0:l.y*F+10*(v()-.5),mass:.8,spawnAt:p?0:.04*t+i/32,shape:{type:"circle",radius:O},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:i,packetCount:e.packetCount,routeProgress:o,flowPath:e.path,flowPathLength:n,flowRouteId:e.id,flowSpeed:F,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*O,stiffness:26,damping:4.25}]:void 0})}});const L=Math.max(18,5*O),Y=Array.from(P,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:"physical-flow-node-"+so(e),point:t})),H=Y.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:L,height:L}})),G=Object.fromEntries(Y.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),X=eo(f,[...di({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...H],"PhysicalFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*O),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});X.bodyLimit=$,X.eviction="oldest",X.observation={...X.observation,sensors:G};const _=Array.from(P,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+so(e),incoming:q.get(e)??0,outgoing:z.get(e)??0})),V=R.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:X,initialSpawns:W,projectionRows:_.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:R.reduce((e,t)=>e+t.throughput,0),plot:b.plot,nodes:_,links:V}}}function Io(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 r=[...i.bodyIds,t.bodyId];return{...e,[n]:{...i,count:r.length,bodyIds:r}}}function jo(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 Ao(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)),r=t.length-i.length,o=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"===o?Number.isFinite(d)&&Number(d)>=0?Number(d):c:void 0;return{id:e.id,label:e.label??e.id,mode:o,complete:t.length>0&&("anyAbsorbed"===o?r>0:"threshold"===o?l>=(u??c):0===i.length),absorbed:r,total:t.length,absorbedValue:l,totalValue:c,threshold:u,missing:i}})}function Co(e,t,n){return Math.max(t,Math.min(n,e))}function Po(e,t,n={}){const i=n.random??Math.random,r=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],o=Co(n.along??.5,.05,.95),s=n.jitterX??0,a=n.padY??20,c=r.x0+(r.x1-r.x0)*o+(2*i()-1)*s,l=Math.min(1,r.width/2),d=Co(c,r.x0+l,r.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 Ro(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 Do(e,t,n){return Math.max(t,Math.min(n,e))}function $o(e,t,n,i,r,o={}){return{id:e,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:t,y1:n,x2:i,y2:r,thickness:o.thickness??8}}}function Bo(e){const t=e.shape??"lane",n=Math.max(1,Math.round(e.width)),i=Math.max(1,Math.round(e.height)),r=e.padX??46,o=e.padY??72,s=r,a=n-r,c=o,l=i-Math.max(24,Math.round(.45*o)),d=(c+l)/2,u=Math.max(1,l-c),h=Do(e.pinchRatio??.18,.06,.5),p=Number(e.pinchHeightOffset??0),f=Number.isFinite(p)?p:0,m=Do(u*h+f,.06*u,.5*u),y=m/2,g=d-y,x=d+y,b=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 S=Do(e.centerStageIndex??Math.floor(M.length/2),0,M.length-1),I=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)/I*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}}),P=C[S],R=P.x0,D=P.x1,$=(e,n)=>{if("lane"===t)return"top"===n?c:l;if("funnel"===t){const t=Do((e-s)/Math.max(1,a-s),0,1);return"top"===n?c+(g-c)*t:l+(x-l)*t}if(R>=e){const t=Do((e-s)/Math.max(1,R-s),0,1);return"top"===n?c+(g-c)*t:l+(x-l)*t}if(D>=e)return"top"===n?g:x;const i=Do((e-D)/Math.max(1,a-D),0,1);return"top"===n?g+(c-g)*i:x+(l-x)*i},B=C.map(e=>{const t=Math.min($(e.x0,"top"),$(e.x1,"top")),n=Math.max($(e.x0,"bottom"),$(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($o(b+"-top",s,c,a,c,T),$o(b+"-bottom",s,l,a,l,T),$o(b+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),$o(b+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)})):"funnel"===t?E.push($o(b+"-top",s,c,a,g,T),$o(b+"-bottom",s,l,a,x,T),$o(b+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),$o(b+"-right",a,g,a,x,{...T,thickness:Math.max(6,k)})):E.push($o(b+"-left-top",s,c,R,g,T),$o(b+"-left-bottom",s,l,R,x,T),$o(b+"-center-top",R,g,D,g,T),$o(b+"-center-bottom",R,x,D,x,T),$o(b+"-right-top",D,g,a,c,T),$o(b+"-right-bottom",D,x,a,l,T),$o(b+"-left",s,c,s,l,{...T,thickness:Math.max(6,k-2)}),$o(b+"-right",a,c,a,l,{...T,thickness:Math.max(6,k)}));const N=e.membraneDampingScale??.5,q=s,z=Math.max(1,("bowtie"===t?R:a)-q),W=(e.membranes??[]).map(e=>{const t=q+Do(e.offset,0,1)*z,n=e.width??18+18*e.cost,i=u-16,r=d+.25*(e.wobble??0);return{...e,x:t,y:r,width:n,height:i}}),F=!1===e.includeMembraneRegions?[]:W.map(e=>No({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:r,padY:o,left:s,right:a,topY:c,bottomY:l,midY:d,centerLeft:R,centerRight:D,pinchHeight:m,pinchTop:g,pinchBottom:x,stages:B,membranes:W,colliders:E,regionEffects:F,boundaryY:$}}function To(e){return{id:e.id,label:e.label,description:e.description,kind:e.kind,shape:(t=e.x,n=e.y,i=e.width,r=e.height,{type:"aabb",x:t,y:n,width:i,height:r}),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,r}function Eo(e,t={}){const n=t.idPrefix??"stage",i=Math.max(0,t.insetX??0),r=Math.max(0,t.insetY??1);return e.stages.map(e=>{const o="function"==typeof t.metadata?t.metadata(e):t.metadata??{};return{...To({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*r),bodyFilter:t.bodyFilter,semanticItem:t.semanticItem,attributes:{primitive:"processStage",stageId:e.id,stageIndex:e.index},metadata:{...o,primitive:"processStage",stageId:e.id,stageIndex:e.index}})}})}function No(e){const t=e.dampingScale??.5,n=e.energyScale??1,i=Do(e.cost,0,2);return{...To({...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 qo(e){return{...To({...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 zo(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...To({...e,kind:e.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),force:t,damping:e.damping??.015}}function Wo(e){const t=e.pressure??e.occupancy??0,n=e.baseDamping??.08,i=e.dampingPerUnit??.12,r=e.energyPerUnit??0;return{...To({...e,kind:e.kind??"membrane",attributes:{primitive:"pressureField",pressure:t,..."object"==typeof e.attributes&&e.attributes?e.attributes:{}}}),damping:n+t*i,energyDelta:r?-t*r:void 0,force:e.force}}function Fo(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...To({...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 Oo(e){return{...To({...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 Lo(e){const t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...To({...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 Yo(e){return{...To({...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 Ho(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 Go(e){const t=e.idPrefix??"lane",n={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},i=[$o(t+"-top",e.left,e.top,e.right,e.top,n),$o(t+"-bottom",e.left,e.bottom,e.right,e.bottom,n)];return e.openEnds||i.push($o(t+"-left",e.left,e.top,e.left,e.bottom,n),$o(t+"-right",e.right,e.top,e.right,e.bottom,n)),i}function Xo(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 _o(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=e.size,i=Qr(n),r=ro(e.ballRadius??6,2,18),o=e.seed??1,s=ao(o),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"),f=e.springStiffness??.28,m=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})),x=Bo({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}),b=new Map(x.stages.map((e,t)=>[e.id,t])),v=new Map(x.stages.map(e=>[e.id,e])),w=x.stages[0].id,k=x.stages[0],M=new Set(t.filter(e=>e.absorb).map(e=>e.id)),S=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 Lo({...n,kind:e.kind??"sink",force:Xo(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 Oo({...n,kind:e.kind??"force-field",force:Xo(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 Fo({...n,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Xo(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 Wo({...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:Xo(e.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?zo({...n,kind:e.kind??"force-field",force:Xo(e.force,14),damping:e.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):Yo({...n,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(e,{x:t.x,y:x.midY,width:t.width,height:x.bottomY-x.topY})});S.unshift(zo({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));const I=new Map;for(const e of x.stages)I.set(e.id,0);const j=[];e.data.forEach((e,t)=>{const n=(a?no(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",i=(no(e,t,c)??w)+"",o=b.has(i)?i:w;I.set(o,(I.get(o)??0)+1);const s=l?(no(e,t,l)??"")+"":void 0,p=s&&d?(no(e,t,d)??s)+"":s,f=u?io(no(e,t,u))??1:1,m=h?io(no(e,t,h)):null,y=ro(null!=m&&m>0?m:r,2,18);j.push({datum:e,id:n,stageId:o,groupId:s||void 0,groupLabel:p||void 0,work:f,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 P=ro(e.groupAnchorAlong??.55,.15,.9),R=x.left+(x.right-x.left)*P,D=Array.from(A.keys()),$=D.map((e,n)=>{const i=A.get(e)??[],r=D.length>1?x.topY+28+n/Math.max(1,D.length-1)*(x.bottomY-x.topY-56):x.midY;return Ho({id:e,label:C.get(e)??e,bodyIds:i,anchor:{x:R,y:r},x:R,y:r,completion:"allAbsorbed"===p?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),B=Ao($,j.filter(e=>M.has(e.stageId)).map(e=>e.id)),T=new Map($.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),r=x.boundaryY(i,"top")+e.radius+10,o=x.boundaryY(i,"bottom")-e.radius-10,a=o>r?r+s()*Math.max(1,o-r):x.midY,c=y?i:x.left+18+t%7*4,l=y?a:x.midY+(s()-.5)*(x.bottomY-x.topY)*.35,d=[{target:{type:"point",x:i,y:a},restLength:.45*e.radius,stiffness:f,damping:m}];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:o,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},q=x.stages.map(e=>({label:e.label??e.id,value:I.get(e.id)??0})),z=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:I.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:q,metadata:{kind:"process-flow",plot:i.plot,volume:x,stages:z,groups:$,groupCompletion:B,regionEffects:S}}}var Vo=require("react");function Uo(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 Ko(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 Qo(e,t){const n=e?.getData().find(e=>e.id===t),i=n?.datum;if(i&&"object"==typeof i)return i}function Zo(e,t){const{frameRef:n,spawnDatum:i,seedRows:r,idAccessor:o,bodyIdsForSeed:s,seedSpawns:a}=t,c=(0,Vo.useRef)(new Map),l=(0,Vo.useRef)(new Map),d=(0,Vo.useRef)(""),u=r?r.map((e,t)=>Ko(e,t,o)).join("\0"):"";if(u!==d.current&&(d.current=u,r))for(let e=0;r.length>e;e+=1){const t=r[e],n=Ko(t,e,o);c.current.set(n,t),l.current.set(n,s?.(t,n,e)??Uo(n,a))}(0,Vo.useImperativeHandle)(e,()=>{const e=c.current,t=l.current;function r(e,t){const n=i(e,t);return{datumId:n.datumId||Ko(e,t,o),spawns:n.spawns.map(e=>({...e,spawnAt:void 0}))}}function s(i){const r=[];for(const{datum:n,result:o}of i)e.set(o.datumId,n),t.set(o.datumId,o.spawns.map(e=>e.id)),r.push(...o.spawns);if(!r.length)return;const o=n.current;o?(o.pushMany(r),o.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 r=e.get(i);if(r)return r;const o=t.get(i)??[i];for(const r of o){const o=Qo(n.current,r);if(o)return e.set(i,o),t.has(i)||t.set(i,[r]),o}}return{push:t=>{s([{datum:t,result:r(t,e.size)}])},pushMany:t=>{const n=e.size;s(t.map((e,t)=>({datum:e,result:r(e,n+t)})))},remove:i=>{const r=Array.isArray(i)?i:[i],o=[],s=[];for(const n of r){const i=a(n);i&&o.push(i),e.delete(n),s.push(...t.get(n)??[n]),t.delete(n)}return s.length&&n.current?.remove(s),o},update:(i,o)=>{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=o(c);s([{datum:u,result:r(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)??[]}},[s,n,o,i])}var Jo=require("react"),es=c(require("react")),ts=require("react/jsx-runtime");function ns({componentName:e,message:t,diagnosticHint:n,width:i,height:r}){return(0,ts.jsx)("div",{role:"alert",style:{width:i,height:Math.max(r,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,ts.jsxs)("div",{style:{textAlign:"center",maxWidth:400},children:[(0,ts.jsx)("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:e}),(0,ts.jsx)("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:t}),n&&(0,ts.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 is=require("react/jsx-runtime"),rs=class extends es.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,is.jsx)(ns,{componentName:"ChartErrorBoundary",message:t.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}},os=require("react/jsx-runtime");function ss({componentName:e,width:t,height:n,children:i}){return(0,os.jsx)(rs,{fallback:i=>(0,os.jsx)(ns,{componentName:e,message:i.message,width:t,height:n}),children:i})}"undefined"!=typeof process&&process;var as={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"},cs={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2};function ls(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function ds(e,t,n){const i=e=>e.toString(16).padStart(2,"0");return`#${i(e)}${i(t)}${i(n)}`}function us(e){const t=e.map(ls),n=t.length-1;return e=>{if(0>=e){const[e,n,i]=t[0];return ds(e,n,i)}if(e>=1){const[e,i,r]=t[n];return ds(e,i,r)}const i=e*n,r=Math.floor(i),o=i-r,[s,a,c]=t[r],[l,d,u]=t[r+1];return ds(Math.round(s+(l-s)*o),Math.round(a+(d-a)*o),Math.round(c+(u-c)*o))}}require("react"),require("d3-scale");var hs=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],ps=us(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),fs=us(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),ms=us(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),ys=us(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),gs=us(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),xs=us(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),bs={blues:ps,reds:fs,greens:ms,viridis:us(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),oranges:ys,purples:gs,greys:xs,plasma:us(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:us(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:us(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:us(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:us(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])},vs=(us(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),us(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),us(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),us(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),us(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),us(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),us(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),{category10:hs,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...bs});function ws(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}function ks(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}var Ms={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function Ss(e,t={}){const n=t.mobileSemantics?.interaction,i="number"==typeof n?.targetSize?n.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,r="mobile"===t.mode||"number"==typeof t.width&&480>=t.width,o=!!n||void 0!==i,s=e&&"object"==typeof e?e:void 0;if(!1===e||!1===s?.enabled||void 0===e&&!r&&!o)return Ms;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 Is={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 js(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}var As=require("react/jsx-runtime"),Cs=new Set(["sample","mechanical"]);function Ps(e,t,n){const i=n?.hasSimulationMode?function(e){const t=e=>"string"==typeof e&&Cs.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"},r=function(e,t,n){const i=Is[e||"primary"],r=e&&"primary"!==e||!n?.width?i.width:n.width,o=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,r=t.height,o=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 r||n.minHeight>r)||"number"==typeof n.maxHeight&&("number"!=typeof r||r>n.maxHeight)||"number"==typeof n.minAspectRatio&&("number"!=typeof o||n.minAspectRatio>o)||"number"==typeof n.maxAspectRatio&&("number"!=typeof o||o>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"])ks(e[i])&&ks(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??r,height:t.height??o}).props,a=s.mode||e,c=Is[a||"primary"],l="context"===a||"sparkline"===a,d=a&&"primary"!==a||!n?.width?c.width:n.width;return{width:s.width??d,height:s.height??(a&&"primary"!==a||!n?.height?c.height:n.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:js(c.marginDefaults,s.showCategoryTicks,s.orientation),compactMode:l,mobileInteraction:Ss(s.mobileInteraction,{mode:a,width:s.width??d,mobileSemantics:s.mobileSemantics}),mobileSemantics:s.mobileSemantics}}(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]}),o=e.size?.[0],s=e.size?.[1],a=t[0],c=t[1],l=(0,Jo.useMemo)(()=>{return e=[a,c],(null!=o&&null!=s?[o,s]:void 0)??[r.width??e[0],r.height??e[1]];var e},[c,a,r.height,r.width,s,o]),d=r.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??!r.compactMode,h=e.showChrome??!r.compactMode,p=Bs(e.tooltip,void 0),f=void 0!==p.enableHover?p.enableHover:r.enableHover,m=r.compactMode?r.title:r.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:r,chartSize:l,margin:d,showProjection:u,showChrome:h,enableHover:f,title:m,description:r.description??e.description,summary:r.summary??e.summary,accessibleTable:r.accessibleTable??e.accessibleTable,className:y,compactMode:r.compactMode,mobileInteraction:r.mobileInteraction,mobileSemantics:r.mobileSemantics}}function Rs(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,os.jsx)("div",{style:{width:t,height:n,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:i});const r=Math.min(5,Math.floor(n/40)),o=Math.max(8,Math.floor(n/(3*r))),s=Math.max(6,Math.floor(n/(2.5*r))),a=Math.floor((n-(r*(o+s)-s))/2);return(0,os.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:r},(e,n)=>(0,os.jsx)("div",{className:"semiotic-loading-bar",style:{...cs,position:"absolute",top:a+n*(o+s),left:Math.floor(.1*t),width:30+(37*n+13)%50+"%",height:o,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,os.jsx)("div",{style:{...as,width:t,height:n},children:i||"No data available"}):null}(e.data,t,n,e.emptyContent)}function Ds(e,t,n){return(0,As.jsx)(ss,{componentName:e,width:t[0],height:t[1],children:n})}function $s(e,t){return e?t?n=>(0,As.jsxs)(As.Fragment,{children:["function"==typeof e?e(n):e,"function"==typeof t?t(n):t]}):e:t}function Bs(e,t){return!1===e?{enableHover:!1}:{enableHover:t?.enableHover,tooltipContent:oe(e)||t?.tooltipContent}}function Ts(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,onClick:null!=e.onClick?(t,n)=>{e.onClick?.(t,{x:n.x,y:n.y})}:t?.onClick,onObservation:e.onObservation??t?.onObservation,opacity:e.opacity??t?.opacity,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 Es=require("react/jsx-runtime"),Ns=(0,d.forwardRef)(function(e,t){const{data:n,valueAccessor:i="value",bins:r=21,ballRadius:o=6,colorBy:s,branchProbability:a=.5,emptyContent:c,frameProps:l,loading:u,loadingContent:h,mechanicalCount:p,paused:f,pegRows:m,referenceLines:y,responsiveHeight:g,responsiveWidth:x,seed:b=1,valueExtent:v}=e,w=Ps(e,[700,420],{hasSimulationMode:!0}),{chartSize:k,simulationMode:M,showProjection:S,className:I,title:j,chartMode:A,margin:C,enableHover:P,description:R,summary:D,accessibleTable:$}=w,B=(0,d.useRef)(null),T=Math.max(1,Math.round(m??r-1)),E=(0,d.useMemo)(()=>"mechanical"===M?[0,T]: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}(v),[T,M,v]),N=(0,d.useMemo)(()=>"mechanical"===M?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))),r=ro(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),o=ao(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)o()<r&&(i+=1);const a=n/2;return{id:`${s}-${t}`,value:i,mechanical:!0,pegRows:n,branchProbability:r,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}({bins:r,branchProbability:a,count:p,pegRows:T,seed:b}):n??[],[r,a,n,p,T,b,M]),q=(0,d.useMemo)(()=>lo({data:N,valueAccessor:i,bins:r,ballRadius:o,seed:b,size:k,valueExtent:E}),[o,r,N,k,E,b,i]);Zo(t,{frameRef:B,spawnDatum:(0,d.useCallback)((e,t)=>{const n=lo({data:[e],valueAccessor:i,bins:r,ballRadius:o,seed:b+t+1,size:k,valueExtent:E}).initialSpawns[0]??{id:(e.id??"galton-push-"+t)+"",x:Qr(k).plot.x,y:Qr(k).plot.y,mass:1,shape:{type:"circle",radius:o},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[o,r,k,E,b,i]),seedRows:N,seedSpawns:q.initialSpawns});const z="mechanical"===M&&null==s?"side":s,W=(0,d.useMemo)(()=>Jr(z),[z]),F=(0,d.useMemo)(()=>to(q.projectionRows,k,"bin"),[k,q.projectionRows]),O=Rs({data:"mechanical"===M?N:n,emptyContent:c,loading:u,loadingContent:h,size:k});if(O)return O;const L=function(e,t,n,i,r){const o=Array.isArray(r)?r:r?[r]:[];if(!1!==n||0!==o.length)return({size:r})=>{const s=[Number(r[0])||700,Number(r[1])||420],a=Qr(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,f]=i?.valueExtent??[0,c],m=f===p?1:f-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,Es.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,Es.jsxs)(Es.Fragment,{children:[Array.from({length:c+1},(e,t)=>{const n=a.plot.x+t*l;return(0,Es.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,Es.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,Es.jsx)("path",{d:y,fill:"none",stroke:"var(--semiotic-accent, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>e.value>0?(0,Es.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,o.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)/m))*a.plot.width,r=e.color??"var(--semiotic-warning, #f28e2b)",o="bottom"===e.labelPosition?Math.min(s[1]-8,d+16):a.plot.y+16;return(0,Es.jsxs)("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[(0,Es.jsx)("line",{x1:i,x2:i,y1:a.plot.y+8,y2:d-4,stroke:r,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:(0,Es.jsx)("text",{x:Math.min(a.plot.x+a.plot.width-4,i+6),y:o,fill:r,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${n}`)})]})}}(q.projectionRows,r,S,q.metadata,y),Y=Bs(e.tooltip,l),H=Ts(e,l,F,{chartMode:A,className:I,title:j,description:R,summary:D,accessibleTable:$,enableHover:P,margin:C});return Ds("GaltonBoardChart",k,(0,Es.jsx)(Kr,{...l,...Y,...H,ref:B,config:q.config,foregroundGraphics:$s(L,l?.foregroundGraphics),initialSpawns:q.initialSpawns,initialSpawnPacing:q.initialSpawnPacing,paused:f,responsiveHeight:g,responsiveWidth:x,size:k,bodyStyle:W}))}),qs=require("react"),zs=require("react/jsx-runtime"),Ws=(0,qs.forwardRef)(function(e,t){const{arrivalAccessor:n="arrivalTime",ballRadius:i=7,colorBy:r,data:o,emptyContent:s,frameProps:a,loading:c,loadingContent:l,paused:d,responsiveHeight:u,responsiveWidth:h,seed:p=1,timeAccessor:f="time",timeExtent:m,timeScale:y=1,watermark:g,windows:x={size:10}}=e,b=Ps(e,[760,360]),{chartSize:v,showProjection:w,className:k,title:M,chartMode:S,margin:I,enableHover:j,description:A,summary:C,accessibleTable:P}=b,R=(0,qs.useRef)(null),D=(0,qs.useMemo)(()=>o??[],[o]),$=(0,qs.useMemo)(()=>po({data:D,timeAccessor:f,arrivalAccessor:n,windows:x,watermark:g,ballRadius:i,seed:p,size:v,timeExtent:m,timeScale:y}),[n,i,v,D,p,f,m,y,g,x]),B=$.metadata;Zo(t,{frameRef:R,spawnDatum:(0,qs.useCallback)((e,t)=>{const r=B?function(e,t,n,i){const r=io(no(e,t,i.timeAccessor));if(null==r)return null;const o=io(no(e,t,i.arrivalAccessor))??r,{windowPlot:s,windowStart:a,windowCount:c,windowSize:l,watermarkValue:d}=n,u=a+c*l,h=(0,uo.scaleLinear)().domain([a,u]).range([s.x,s.x+s.width]),p=Math.max(0,Math.min(c-1,Math.floor((r-a)/l))),f=d>=a+(p+1)*l,{ballRadius:m}=i;return{id:(e.id??"event-push-"+t)+"",x:Math.max(s.x+m,Math.min(s.x+s.width-m,h(r))),y:s.y+m+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,shape:{type:"circle",radius:m},datum:{...e,eventTime:r,arrivalTime:o,windowIndex:p,late:f}}}(e,t,B,{timeAccessor:f,arrivalAccessor:n,ballRadius:i}):null,o=r??{id:(e.id??"event-push-"+t)+"",x:Qr(v).plot.x,y:Qr(v).plot.y,mass:1,shape:{type:"circle",radius:i},datum:e};return{datumId:(e.id??o.id)+"",spawns:[o]}},[n,i,v,B,f]),seedRows:D,seedSpawns:$.initialSpawns});const T=(0,qs.useMemo)(()=>Jr(r),[r]),E=(0,qs.useMemo)(()=>function(e,t,n){if(!t)return to(e,n,"window");const i=t.windowPlot.width/Math.max(1,e.length),r=Math.max(1,...e.map(e=>e.value+(e.secondary??0))),o=.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))/r*o),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"}})}($.projectionRows,B,v),[v,$.projectionRows,B]),N=Rs({data:o,emptyContent:s,loading:c,loadingContent:l,size:v});if(N)return N;const q=function(e,t,n){if(!1!==n&&t)return({size:n})=>{const i=[Number(n[0])||760,Number(n[1])||360],r=Qr(i),o=Math.max(1,t.windowCount),s=t.plot??r.plot,a=t.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=t.windowPlot??s,l=c.width/o,d=s.y+s.height,u=s.y+.48*s.height,h=t.lidSegments[0]?.y1??u,p=t.windowStart,f=t.windowStart+o*t.windowSize,m=c.x+Math.max(0,Math.min(1,f===p?0:(t.watermarkValue-p)/(f-p)))*c.width;return(0,zs.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,zs.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,zs.jsxs)("g",{children:[(0,zs.jsx)("rect",{x:a.x,y:h,width:a.width,height:d-h,fill:"var(--semiotic-negative, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),(0,zs.jsx)("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-negative, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:o},(n,r)=>{const o=e[r],s=c.x+r*l,a=t.closedWindowCount>r,h=o?.secondary??0;return(0,zs.jsxs)("g",{children:[(0,zs.jsx)("rect",{x:s,y:u,width:l,height:d-u,fill:a?"var(--semiotic-negative, #e15759)":"var(--semiotic-accent, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?t.lidSegments.filter(e=>e.windowIndex===r).map(e=>(0,zs.jsx)("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-negative, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,(0,zs.jsxs)("text",{x:s+l/2,y:u-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[o?.value??0,h?` / ${h} late`:""]}),(0,zs.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:o?.label??""})]},"window-"+r)}),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>(0,zs.jsx)("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-negative, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),(0,zs.jsx)("line",{x1:s.x,x2:s.x+s.width,y1:d,y2:d,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),(0,zs.jsx)("line",{"data-testid":"event-drop-watermark",x1:m,x2:m,y1:s.y+8,y2:d,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),(0,zs.jsxs)("text",{x:Math.min(s.x+s.width-4,m+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,zs.jsxs)("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-negative, #e15759)",fontSize:10,fontWeight:700,children:[t.lateCount," late"]}):null]})}}($.projectionRows,$.metadata,w),z=Bs(e.tooltip,a),W=Ts(e,a,E,{chartMode:S,className:k,title:M,description:A,summary:C,accessibleTable:P,enableHover:j,margin:I});return Ds("EventDropChart",v,(0,zs.jsx)(Kr,{...a,...z,...W,ref:R,config:$.config,foregroundGraphics:$s(q,a?.foregroundGraphics),initialSpawns:$.initialSpawns,initialSpawnPacing:$.initialSpawnPacing,paused:d,responsiveHeight:u,responsiveWidth:h,size:v,bodyStyle:T}))}),Fs=require("react"),Os=require("react/jsx-runtime"),Ls=(0,Fs.forwardRef)(function(e,t){const{ballRadius:n=8,categoryAccessor:i="category",colorBy:r,data:o,emptyContent:s,frameProps:a,loading:c,loadingContent:l,mechanicalCategories:d,mechanicalCount:u,paused:h,responsiveHeight:p,responsiveWidth:f,seed:m=1,unitValue:y=1,valueAccessor:g}=e,x=Ps(e,[700,380],{hasSimulationMode:!0}),{chartSize:b,simulationMode:v,showProjection:w,className:k,title:M,chartMode:S,margin:I,enableHover:j,description:A,summary:C,accessibleTable:P}=x,R=(0,Fs.useRef)(null),D="mechanical"===v&&null==g?"value":g,$=(0,Fs.useMemo)(()=>"mechanical"===v?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))),r=oo(e.unitValue,1),o=ao(e.seed??1),s=e.idPrefix??"mechanical-pile",a=n.map(()=>.65+.9*o()),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]*r,mechanical:!0,unitCount:u[t],unitValue:r,share:u[t]/i}))}({categories:d,count:u,seed:m,unitValue:y}):o??[],[o,d,u,m,v,y]),B=(0,Fs.useMemo)(()=>mo({data:$,categoryAccessor:i,valueAccessor:D,unitValue:y,ballRadius:n,seed:m,size:b}),[n,i,b,$,D,m,y]);Zo(t,{frameRef:R,spawnDatum:(0,Fs.useCallback)((e,t)=>{const r=mo({data:[e],categoryAccessor:i,valueAccessor:D,unitValue:y,ballRadius:n,seed:m+t+1,size:b}),o={id:(e.id??"pile-push-"+t)+"",x:Qr(b).plot.x,y:Qr(b).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e},s=r.initialSpawns.length?r.initialSpawns:[o];return{datumId:(e.id??s[0].id)+"",spawns:s}},[n,i,b,D,m,y]),seedRows:$,seedSpawns:B.initialSpawns});const T="mechanical"===v&&null==r?"category":r,E=(0,Fs.useMemo)(()=>Jr(T),[T]),N=(0,Fs.useMemo)(()=>to(B.projectionRows,b,"category"),[b,B.projectionRows]),q=Rs({data:"mechanical"===v?$:o,emptyContent:s,loading:c,loadingContent:l,size:b});if(q)return q;const z=function(e,t,n){if(!1!==n&&0!==e.length)return({size:n})=>{const i=[Number(n[0])||700,Number(n[1])||380],r=Qr(i),o=fo(r.plot,e.length,t),s=r.plot.y+r.plot.height;return(0,Os.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,Os.jsx)("line",{x1:r.plot.x,x2:r.plot.x+r.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{const n=Math.min(r.plot.height,o.pileHeight(e.value)),a=o.tubeWidth,c=o.centerX(t),l=s-n;return(0,Os.jsxs)("g",{children:[(0,Os.jsx)("rect",{x:c-a/2,y:l,width:a,height:n,rx:3,fill:"var(--semiotic-accent, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-accent, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),(0,Os.jsx)("text",{x:c,y:Math.max(r.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),(0,Os.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}`)})]})}}(B.projectionRows,n,w),W=Bs(e.tooltip,a),F=Ts(e,a,N,{chartMode:S,className:k,title:M,description:A,summary:C,accessibleTable:P,enableHover:j,margin:I});return Ds("PhysicsPileChart",b,(0,Os.jsx)(Kr,{...a,...W,...F,ref:R,config:B.config,foregroundGraphics:$s(z,a?.foregroundGraphics),initialSpawns:B.initialSpawns,initialSpawnPacing:B.initialSpawnPacing,paused:h,responsiveHeight:p,responsiveWidth:f,size:b,bodyStyle:E}))}),Ys=require("react"),Hs=require("d3-scale");function Gs(e,t){const n=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>n&&ws(n,e)||"#4e79a7":t=>{if(n){const e=ws(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"}}var Xs=Object.freeze([]);function _s(e){if(!e)return Xs;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 Vs=require("react/jsx-runtime");function Us(e,t){const n=t.config??{},i=(t.sensors??[]).map(e=>({...e,sensor:!0})),r=[...t.colliders??[],...i],o=[...e.colliders??[],...n.colliders??[],...r];return{...e,...n,observation:{...e.observation,...n.observation},...o.length>0&&{colliders:o}}}function Ks(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){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=vs[e];if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:n}(e.colorScheme,e.themeCategorical,hs),i=Qr(e.size),r={data:e.data,scales:{x:(0,Hs.scaleLinear)().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:(0,Hs.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:Gs(n,e.colorScheme),config:e.layoutConfig??{},world:new Ii(t)},o=e.skipLayout?{}:e.layout(r)??{},s=function(e,t){if(!t?.length)return e;const n=new Map;for(const e of t){const{bodyId:t,...i}=e,r=n.get(t)??[];r.push(i),n.set(t,r)}return e.map(e=>{const t=n.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...o.initialSpawns??o.bodies??[]],o.constraints);return{config:Us(t,o),context:r,initialSpawnPacing:o.initialSpawnPacing,initialSpawns:s,result:o}}var Qs=(0,Ys.forwardRef)(function(e,t){const{chartId:n,color:i,colorBy:r,colorScheme:o,config:s,controllers:a,data:c,emptyContent:l,frameProps:d={},layout:u,layoutConfig:h,loading:p,loadingContent:f,onObservation:m,opacity:y,paused:g,spawnDatum:x,stroke:b,strokeWidth:w,title:k,xExtent:M,yExtent:S}=e,j=Ps(e,[700,380]),{chartSize:A,className:C,title:P,chartMode:R,margin:D,enableHover:$,description:B,summary:T,accessibleTable:E}=j,N=(0,Ys.useRef)(null),q=(0,Ys.useRef)(null),z=(0,Ys.useRef)(""),W=Rs({data:c,emptyContent:l,loading:p,loadingContent:f,size:A}),F=null!=W,O=(0,Ys.useMemo)(()=>_s(c??[]),[c]),L=I(e=>e.theme),Y=(0,Ys.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}}(L)??{},[L]),H=L?.colors?.categorical??v.colors.categorical,G=(0,Ys.useMemo)(()=>[A[0],A[1],O.length,O.map((e,t)=>(e.id??t)+"").join("|"),M?.join(",")??"",S?.join(",")??""].join("::"),[A,O,M,S]),X=(0,Ys.useMemo)(()=>Ks({chartId:n,colorScheme:o,config:s,data:O,layout:u,layoutConfig:h,onObservation:m,semantic:Y,skipLayout:F,size:A,themeCategorical:H,xExtent:M,yExtent:S}),[n,A,o,s,u,h,m,O,Y,F,H,M,S]);z.current===G&&null!=q.current||(z.current=G,q.current=X.initialSpawns);const _=q.current,V=(0,Ys.useMemo)(()=>{const e=[...X.result.controllers??[],...a??[],...d.controllers??[]];return e.length?e:void 0},[d.controllers,a,X.result.controllers]),U=(0,Ys.useMemo)(()=>{const e=[...X.result.regionEffects??[],...d.regionEffects??[]];return e.length?e:void 0},[d.regionEffects,X.result.regionEffects]),K=(0,Ys.useCallback)(e=>{const t=e.datum,n=t&&r?function(e,t,n){return"function"==typeof n?n(e,0):e[n]}(t,0,r)+"":e.id;return{fill:i??X.context.resolveColor(n,t),stroke:b??"#111827",strokeWidth:w??1,opacity:y??.9}},[i,r,y,X.context,b,w]);Zo(t,{frameRef:N,spawnDatum:(0,Ys.useCallback)((e,t)=>{const i=e;if(x)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,x(i,t,X.context));const r=Ks({chartId:n,colorScheme:o,config:s,data:[i],layout:u,layoutConfig:h,onObservation:m,semantic:Y,size:A,themeCategorical:H,xExtent:M,yExtent:S}),a=r.initialSpawns.length?r.initialSpawns:[{id:(e.id??"physics-custom-"+t)+"",x:r.context.dimensions.plot.x+r.context.dimensions.plot.width/2,y:r.context.dimensions.plot.y+12,mass:1,shape:{type:"circle",radius:5},datum:e}];return{datumId:(e.id??a[0].id)+"",spawns:a}},[n,A,o,s,x,u,h,m,X.context,Y,H,M,S]),seedRows:O,seedSpawns:_});const Q=(0,Ys.useCallback)((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]);if(W)return W;const Z=Bs(e.tooltip,d),J=Ts(e,d,X.result.semanticItems,{chartMode:R,className:C,title:P??k,description:B,summary:T,accessibleTable:E,enableHover:$,margin:D});return Ds("PhysicsCustomChart",A,(0,Vs.jsx)(Kr,{...d,...Z,...J,ref:N,backgroundGraphics:$s(d.backgroundGraphics,X.result.backgroundOverlays),bodyForces:X.result.bodyForces??d.bodyForces,bodyStyle:X.result.bodyStyle??d.bodyStyle??K,config:X.config,controllers:V,foregroundGraphics:$s(d.foregroundGraphics,X.result.overlays),initialSpawnPacing:X.initialSpawnPacing,initialSpawns:_,onBodyPointerDown:Q,paused:g,regionEffects:U,responsiveHeight:e.responsiveHeight,responsiveWidth:e.responsiveWidth,selectedBodyStyle:X.result.selectedBodyStyle??d.selectedBodyStyle,size:A}))});Qs.displayName="PhysicsCustomChart";var Zs=require("react"),Js=require("react/jsx-runtime");function ea(e){return e.toLocaleString(void 0,Math.abs(e)>=1e3||.01>Math.abs(e)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}var ta=(0,Zs.forwardRef)(function(e,t){const{colorBy:n,collisionIterations:i,data:r,emptyContent:o,frameProps:s,groupAccessor:a,loading:c,loadingContent:l,paused:d,pointRadius:u=5,radiusAccessor:h,responsiveHeight:p,responsiveWidth:f,seed:m=1,settle:y,xAccessor:g="x",xExtent:x}=e,b=Ps(e,[700,360]),{chartSize:v,showProjection:w,className:k,title:M,chartMode:S,margin:I,enableHover:j,description:A,summary:C,accessibleTable:P}=b,R=(0,Zs.useRef)(null),D=(0,Zs.useMemo)(()=>r??[],[r]),$=(0,Zs.useMemo)(()=>go({data:D,xAccessor:g,groupAccessor:a,radiusAccessor:h,pointRadius:u,seed:m,size:v,xExtent:x,collisionIterations:i,settle:y}),[D,v,i,a,u,h,m,y,g,x]);Zo(t,{frameRef:R,spawnDatum:(0,Zs.useCallback)((e,t)=>{const n=go({data:[e],xAccessor:g,groupAccessor:a,radiusAccessor:h,pointRadius:u,seed:m+t+1,size:v,xExtent:x,collisionIterations:i,settle:y}).initialSpawns[0]??{id:(e.id??"collision-swarm-push-"+t)+"",x:Qr(v).plot.x,y:Qr(v).plot.y,mass:1,shape:{type:"circle",radius:u},datum:e};return{datumId:(e.id??n.id)+"",spawns:[n]}},[v,i,a,u,h,m,y,g,x]),seedRows:D,seedSpawns:$.initialSpawns});const B=n??a,T=(0,Zs.useMemo)(()=>Jr(B),[B]),E=Rs({data:r,emptyContent:o,loading:c,loadingContent:l,size:v});if(E)return E;const N=function(e,t){if(!1!==t&&e)return({size:t})=>{const n=[Number(t[0])||700,Number(t[1])||360],i=Qr(n),r=i.plot.y+i.plot.height,[o,s]=e.xExtent,a=o+(s-o)/2,c=[{label:ea(o),x:e.xRange[0]},{label:ea(a),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:ea(s),x:e.xRange[1]}];return(0,Js.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,Js.jsxs)("g",{children:[(0,Js.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,Js.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,Js.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,Js.jsx)("line",{x1:e.xRange[0],x2:e.xRange[1],y1:r,y2:r,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(e=>(0,Js.jsxs)("g",{children:[(0,Js.jsx)("line",{x1:e.x,x2:e.x,y1:r,y2:r+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),(0,Js.jsx)("text",{x:e.x,y:Math.min(n[1]-8,r+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}($.metadata,w),q=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"}})}($.metadata),z=Bs(e.tooltip,s),W=Ts(e,s,q,{chartMode:S,className:k,title:M,description:A,summary:C,accessibleTable:P,enableHover:j,margin:I});return Ds("CollisionSwarmChart",v,(0,Js.jsx)(Kr,{...s,...z,...W,ref:R,config:$.config,foregroundGraphics:$s(N,s?.foregroundGraphics),initialSpawns:$.initialSpawns,paused:d,responsiveHeight:p,responsiveWidth:f,size:v,bodyStyle:T}))}),na={fresh:1,aging:1.5,stale:3};function ia(e,t,n={}){return Number.isFinite(t)&&t>0?Number.isNaN(e)?"fresh":e===1/0?"expired":0>e||t*(n.fresh??na.fresh)>e?"fresh":t*(n.aging??na.aging)>e?"aging":t*(n.stale??na.stale)>e?"stale":"expired":"fresh"}function ra(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 oa(e){const{data:t,encoding:n}=e,i=[],r=new Map;return t.forEach((e,t)=>{const o=ra(n.id,e,t);if(null==o||""===o)throw Error(`[semiotic] Motion encoding row ${t} resolved an empty id.`);const s=o+"";if(r.has(s))throw Error(`[semiotic] Duplicate motion encoding id "${s}".`);const a=ra(n.process?.group,e,t),c=ra(n.process?.stage,e,t),l=ra(n.accessible?.group,e,t)??(null!=a?a+"":null!=c?c+"":void 0),d={};for(const i of Object.keys(n.evidence??{}))d[i]=ra(n.evidence?.[i],e,t);const u={id:s,datum:e,time:{arrival:ra(n.time?.arrival,e,t),basis:n.time?.basis,unit:n.time?.unit},placement:{x:ra(n.placement?.x,e,t),y:ra(n.placement?.y,e,t),lane:ra(n.placement?.lane,e,t),space:n.placement?.space},kinematics:{velocityX:ra(n.kinematics?.velocityX,e,t),velocityY:ra(n.kinematics?.velocityY,e,t),space:n.kinematics?.space},process:{group:a,stage:c,target:ra(n.process?.target,e,t),work:ra(n.process?.work,e,t)},evidence:d,accessible:{description:ra(n.accessible?.description,e,t),group:l,label:ra(n.accessible?.label,e,t)??s}};i.push(u),r.set(s,u)}),{rows:i,byId:r}}function sa(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:ia(t,e.ttl,e.thresholds)}}function aa(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 ca(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 la(e,t,n){return Number.isFinite(n)&&n>0?ca((t.x-e.x)/n,(t.y-e.y)/n):ca(0,0)}function da(e){const{data:t,encoding:n,defaults:i={},scales:r}=e,o=oa({data:t,encoding:n}),s=[],a=new Map,c=[],l=[],d=new Map;return o.rows.forEach((e,t)=>{const{id:o,datum:u}=e,h=Math.max(0,ra(n.appearance?.size,u,t)??i.size??6),p=ra(n.appearance?.shape,u,t)??i.shape??{type:"circle",radius:h},f=e.placement.x??i.x??0,m=e.placement.y??i.y??0,y=r?.x?r.x(f):f,g=r?.y?r.y(m):m,x=ra(n.appearance?.color,u,t)??i.color,b=ra(n.appearance?.opacity,u,t)??i.opacity,v=ra(n.appearance?.stroke,u,t)??i.stroke,w=ra(n.appearance?.strokeWidth,u,t)??i.strokeWidth,k=ra(n.time?.spawnAt,u,t)??e.time.arrival,M=e.kinematics.velocityX,S=e.kinematics.velocityY,I=ra(n.dynamics?.mass,u,t)??i.mass??1,j=ra(n.dynamics?.friction,u,t),A=ra(n.dynamics?.restitution,u,t),C=ra(n.dynamics?.bodyCollisions,u,t),P={id:o,x:y,y:g,mass:I,shape:{...p},datum:u,...null!=k&&{spawnAt:k},...null!=M&&{vx:M},...null!=S&&{vy:S},...null!=j&&{friction:j},...null!=A&&{restitution:A},...null!=C&&{bodyCollisions:C}},R={...null!=x&&{fill:x},...null!=b&&{opacity:b},...null!=v&&{stroke:v},...null!=w&&{strokeWidth:w}},D={id:o,datum:u,appearance:{color:x,opacity:b,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:S,space:n.kinematics?.space??"world"},dynamics:{bodyCollisions:C,friction:j,mass:I,restitution:A},process:e.process,evidence:e.evidence,accessible:e.accessible,spawn:P};s.push(D),a.set(o,D),c.push(P),d.set(o,R),l.push({id:o,bodyId:o,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 ua(e){return t=>{const n=da({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 ha=require("react");function pa(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 r=t.thickness??8,o=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:o,y1:a,x2:s,y2:a,thickness:r}},{...i,id:n+"-right",shape:{type:"segment",x1:s,y1:a,x2:s,y2:c,thickness:r}},{...i,id:n+"-bottom",shape:{type:"segment",x1:s,y1:c,x2:o,y2:c,thickness:r}},{...i,id:n+"-left",shape:{type:"segment",x1:o,y1:c,x2:o,y2:a,thickness:r}}]}function fa(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 ma(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 ya(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 ga="gauntlet-core",xa="gauntlet-positive",ba="gauntlet-negative";function va(e){return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:28,y2:e.floorY,thickness:8}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:76,x2:e.width-30,y2:76,thickness:8}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:28,y1:e.floorY,x2:e.width-30,y2:e.floorY,thickness:8}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-30,y1:76,x2:e.width-30,y2:e.floorY,thickness:8}}]}function wa(e,t,n,i){return n?"function"==typeof n?n(e,t):e[n]??i:i}function ka(e){return e?.label??e?.id??"property"}function Ma(e){return`gauntlet:${e}:core`}function Sa(e,t){return`gauntlet:${e}:positive:${t}`}function Ia(e,t,n){return`gauntlet:${e}:negative:${t}:${n}`}function ja(e,t,n,i){const r=Math.max(2,n+2),o=80+r,s=i.floorY-r;return{x:Math.max(32+r,Math.min(i.width-30-4-r,e)),y:Math.max(o,Math.min(s,t))}}function Aa(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 Ca(e,t,n,i){const r=Aa(n),o=i?.(e,t,n)??{};return{...r,...o,startY:o.startY??o.routeY??r.startY,socketY:o.socketY??o.routeY??r.socketY,graveyardY:o.graveyardY??r.graveyardY}}function Pa(e,t){const n=[...e].sort((e,t)=>e.localeCompare(t)),i=Math.max(0,n.indexOf(t));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:48+i%2*6}}function Ra(e,t,n){const i=e.activePositiveIds.reduce((e,n)=>e+(t.get(n)?.value??1),0),r=e.missingPositiveIds.length+e.poppedPositiveIds.length,o=e.negativeIds.reduce((e,t)=>e+(n.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*o-1.2*e.delay-5*r))}function Da(e,t,n,i,r){const o=wa(e,t,n.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",s=i.map(e=>e.id),a=[...wa(e,t,n.positiveAccessor,s)],c=[...wa(e,t,n.negativeAccessor,[])].filter(e=>r.has(e));return{id:o,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...wa(e,t,n.metricsAccessor,{})},missingPositiveIds:s.filter(e=>!a.includes(e)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(wa(e,t,n.startTimeAccessor,0))||0),stage:"project filed",viability:wa(e,t,n.initialViability,100)}}function $a(e,t,n,i,r,o,s){const a=i.startX,c=i.startY+(i.startY===n.routeY?38*t:0),l=s?.(e,t,n,i)??{},d={__gauntlet:!0,kind:ga,projectId:e.id,sourceDatum:e.datum},u=[{...l,id:Ma(e.id),x:l.x??a,y:l.y??c,vx:l.vx??42,vy:l.vy??0,mass:l.mass??7,bodyCollisions:l.bodyCollisions??!0,shape:l.shape??{type:"circle",radius:28},spawnAt:l.spawnAt??e.startedAt,datum:d}],h=ja(a,c,l.shape&&"radius"in l.shape&&Number(l.shape.radius)||28,n);u[0].x=h.x,u[0].y=h.y;for(const t of e.activePositiveIds){const i=r.get(t);if(!i)continue;const o=Pa(e.activePositiveIds,t),s=i.radius??10,a=ja(h.x+Math.cos(o.angle)*o.radius,h.y+Math.sin(o.angle)*o.radius,s,n);u.push({id:Sa(e.id,t),x:a.x,y:a.y,vx:18*Math.cos(o.angle),vy:18*Math.sin(o.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:l.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:xa,projectId:e.id,property:i,sourceDatum:e.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:Ma(e.id)},stiffness:.56,damping:.9,restLength:52+o.index%2*4,...i.spring??{}}]})}return e.negativeIds.forEach((t,i)=>{const r=o.get(t);r&&u.push(Ba(e,r,i,h.x,h.y,n,l.spawnAt??e.startedAt))}),u}function Ba(e,t,n,i,r,o,s){const a=t.radius??7.2,c=ja(i-12+n%4*12,r+54+12*Math.floor(n/4),a,o);return{id:Ia(e.id,t.id,n),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:s,datum:{__gauntlet:!0,kind:ba,projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Ma(e.id)},stiffness:.62,damping:.92,restLength:52+n%4*3,...t.spring??{}}]}}function Ta(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 Ea(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 Na(e,t){return Ea(e.activePositiveIds,t.popPositive)}function qa(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])),r=e.candidates?new Set(e.candidates):null,o=e.attachedIds.map((e,t)=>{const n=i.get(e),r=Number(n?.work??1),o=Number(n?.priority??t);return{id:e,index:t,priority:Number.isFinite(o)?o:t,work:Number.isFinite(r)&&r>0?r:1}}).filter(e=>!r||r.has(e.id)).sort((e,t)=>e.priority-t.priority||e.index-t.index),s=[],a=[];let c=0;for(const e of o)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 za(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,r=Math.min(n,i);return r?{addNegative:{[t.to]:r},popNegative:{ids:Array.from({length:r},()=>t.from)}}:{}}function Wa(e,t){const n=Ea(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 r=[];return e.negativeIds.forEach((e,t)=>{const n=i.get(e)??0;n>0&&(r.push({propertyId:e,index:t}),i.set(e,n-1))}),r}function Fa(e,t,n){if(t.when&&!t.when(n))return e;let i={...e};const r=Na(i,t);r.length&&(i={...i,activePositiveIds:i.activePositiveIds.filter(e=>!r.includes(e)),poppedPositiveIds:Array.from(new Set([...i.poppedPositiveIds,...r]))});const o=Wa(i,t);if(o.length){const e=new Set(o.map(e=>e.index));i={...i,negativeIds:i.negativeIds.filter((t,n)=>!e.has(n)),poppedNegativeIds:[...i.poppedNegativeIds,...o.map(e=>e.propertyId)]}}const s=Ta(t.addPositive);s.length&&(i={...i,activePositiveIds:Array.from(new Set([...i.activePositiveIds,...s])),missingPositiveIds:i.missingPositiveIds.filter(e=>!s.includes(e))});const a=Ta(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 Oa(e,t){return{id:e.id,label:e.label??e.id,summary:e.summary??t.find(e=>e.summary)?.summary,time:e.time}}function La(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 Ya(e,t){const n=e.datum;return!(!n?.__gauntlet||n.projectId!==t||n.kind!==ba)}function Ha(e){const t=e.id.slice(e.id.lastIndexOf(":")+1),n=Number(t);return Number.isFinite(n)?n:-1}var Ga=require("react/jsx-runtime");function Xa(e){const t=e.data;return t?.__gauntlet?(0,Ga.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,Ga.jsx)("strong",{children:t.kind===ga?"string"==typeof t.sourceDatum?.label?t.sourceDatum.label:t.projectId:ka(t.property)}),(0,Ga.jsx)("div",{children:t.kind===xa?"Positive property":t.kind===ba?"Negative property":"Project core"})]}):null}function _a(e,t,n){const i=t.datum;if(!i?.__gauntlet)return;const r="circle"===t.shape.type?t.shape.radius:8;if(e.save(),e.translate(t.x,t.y),i.kind===ga)e.fillStyle=Va(e,n.fill,"#0f766e"),e.strokeStyle=Va(e,n.stroke,"#f8fafc"),e.lineWidth=2.4,e.beginPath(),e.arc(0,0,r,0,2*Math.PI),e.fill(),e.stroke();else{const t=i.property;e.fillStyle=Va(e,n.fill??t?.color,"#38bdf8"),e.strokeStyle=Va(e,n.stroke,"#0f172a"),e.lineWidth=1.1,e.beginPath(),i.kind===ba?e.rect(-r,-r,2*r,2*r):e.arc(0,0,r,0,2*Math.PI),e.fill(),e.stroke(),e.fillStyle=Va(e,"var(--semiotic-background, #07111f)","#07111f"),e.font=`900 ${i.kind===ba?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 Va(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 Ua({layout:e,states:t}){return(0,Ga.jsxs)("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[(0,Ga.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-accent, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),(0,Ga.jsx)("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-negative, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),(0,Ga.jsx)("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-negative, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),e.gates.map(t=>(0,Ga.jsxs)("g",{children:[(0,Ga.jsx)("rect",{x:t.x-t.width/2,y:Math.max(80,e.routeY-180),width:t.width,height:Math.min(360,e.height-170),rx:12,fill:t.color??"var(--semiotic-accent, #38bdf8)",fillOpacity:.1,stroke:t.color??"var(--semiotic-accent, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),(0,Ga.jsx)("text",{x:t.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:t.label??t.id})]},t.id)),(0,Ga.jsxs)("g",{children:[(0,Ga.jsx)("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-positive, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-positive, #22c55e)",strokeWidth:1.5}),(0,Ga.jsx)("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),(0,Ga.jsxs)("g",{children:[(0,Ga.jsx)("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-negative, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-negative, #ef4444)",strokeOpacity:.7}),(0,Ga.jsx)("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-negative, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),(0,Ga.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 Ka(e){const t=e.datum;return!!t?.__gauntlet&&(t.kind===ga?{label:t.projectId+" project core",group:"project",description:"Project core carrying positive and negative properties."}:{label:`${ka(t.property)} ${t.kind===xa?"positive":"negative"} property`,group:t.kind===xa?"positive property":"negative property",description:`${ka(t.property)} attached to ${t.projectId}.`})}function Qa({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)),r=Math.max(40,(t.width-80)/n.length);return(0,Ga.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,Ga.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*r,o=Math.max(2,e.value/i*28),s=/kill|crash|block|grave/i.test(e.outcome);return(0,Ga.jsxs)("g",{children:[(0,Ga.jsx)("rect",{x:n+.18*r,y:28-o+22,width:Math.max(10,.45*r),height:o,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,Ga.jsx)("text",{x:n+.4*r,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}var Za=require("react/jsx-runtime"),Ja=require("react"),ec=[],tc=(0,ha.forwardRef)(function(e,t){const{bodyGroups:n,coreBody:i,coreForceMode:r="route",crashDetection:o=!0,crashOffset:s=30,data:a,emptyContent:c,events:l,frameProps:d={},gates:u,initialSpawnPacing:h,loading:p,loadingContent:f,negativeProperties:m,onCapacityChange:y,onClick:g,onStateChange:x,outcome:b,paused:v,positiveProperties:w=ec,projectPlacement:k,responsiveHeight:M,responsiveWidth:S,showTethers:I=!0,terminalBehavior:j="outcome",viability:A}=e,C=(0,ha.useRef)(null),P=(0,ha.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]),R=Ps(e,[900,520]),{chartSize:D,showProjection:$,showChrome:B,className:T,title:E,chartMode:N,margin:q,enableHover:z,description:W,summary:F,accessibleTable:O}=R,L=Rs({data:a,emptyContent:c,loading:p,loadingContent:f,size:D}),Y=(0,ha.useMemo)(()=>_s(a??[]),[a]),H=(0,ha.useMemo)(()=>Y.map((e,t)=>wa(e,t,P.idAccessor,null!=e.id?e.id+"":"project-"+t)+"").join("|"),[Y,P.idAccessor]),G=(0,ha.useMemo)(()=>new Map(w.map(e=>[e.id,e])),[w]),X=(0,ha.useMemo)(()=>new Map(m.map(e=>[e.id,e])),[m]),_=(0,ha.useMemo)(()=>function(e,t,n){const[i,r]=e,o=Math.round(.48*r),s=r-36,a=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,a.length),l=.22*i,d=c>1?(.78*i-l)/(c-1):0,u=Math.max(Math.round(.14*i),110);return{crashY:s-n,floorY:s,gates:a.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(l+t*d),width:e.width??Math.max(54,Math.round(.07*i))})),graveyardX:Math.round(.84*i),graveyardY:s-4,height:r,routeY:o,socketX:Math.round(.92*i),startX:u,width:i}}(D,u,s),[D,s,u]),V=(0,ha.useMemo)(()=>new Map(_.gates.map(e=>[e.id,e])),[_.gates]),U=(0,ha.useMemo)(()=>_.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:ga}:e.regionEffect?.bodyFilter,shape:{type:"aabb",x:e.x,y:_.routeY,width:e.capacity?e.capacity.sensorWidth??Math.max(96,6*e.width):Math.max(e.width,54),height:Math.min(360,_.height-170)}})),[_.gates,_.height,_.routeY]),[K,Q]=(0,ha.useState)(()=>Y.map((e,t)=>{const n=Da(e,t,P,w,X);return{...n,viability:A?.(n,{negativeProperties:X,positiveProperties:G})??Ra(n,G,X)}})),Z=(0,ha.useRef)(K),J=(0,ha.useRef)(0),ee=(0,ha.useRef)(new Map),te=(0,ha.useRef)([]),ne=(0,ha.useRef)(y);ne.current=y;const ie=(0,ha.useMemo)(()=>function(e){const{dataKey:t,gates:n,statesRef:i,processedGateVisitsRef:r}=e;return n.flatMap(e=>e.capacity&&e.capacity.unitsPerSecond>0?[zi({id:`gauntlet-capacity-${t}-${e.id}`,regionId:"gauntlet-gate-"+e.id,unitsPerSecond:e.capacity.unitsPerSecond,bodyFilter:{property:"datum.kind",equals:ga},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,r=n?.sourceDatum,o=e.capacity?.unitAccessor,s=i.current.find(e=>e.id===n?.projectId);let a;"function"==typeof o?a=s?o(s):void 0:o&&(a=r?.[o]);const c=Number(a??r?.reviewWork??r?.work??s?.metrics.reviewWork??r?.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}`;r.current.set(i,(r.current.get(i)??0)+1)}})]:[])}({dataKey:H,gates:_.gates,statesRef:Z,processedGateVisitsRef:ee}),[H,_.gates]),re=(0,ha.useMemo)(()=>[...ie,...d.controllers??[]],[ie,d.controllers]),oe=(0,ha.useRef)(Y);oe.current=Y;const se=(0,ha.useRef)(x);se.current=x;const ae=(0,ha.useRef)({negativeById:X,positiveById:G,positiveProperties:w,stateAccessors:P,viability:A});ae.current={negativeById:X,positiveById:G,positiveProperties:w,stateAccessors:P,viability:A};const ce=(0,ha.useCallback)((e,t,n=0)=>{const i=ae.current,r=Da(e,t,i.stateAccessors,i.positiveProperties,i.negativeById);return i.stateAccessors.startTimeAccessor||(r.startedAt=Math.max(0,n)),{...r,viability:i.viability?.(r,{negativeProperties:i.negativeById,positiveProperties:i.positiveById})??Ra(r,i.positiveById,i.negativeById)}},[]);(0,ha.useEffect)(()=>{ee.current.clear(),te.current=[];const e=oe.current.map((e,t)=>ce(e,t));Z.current=e,Q(e)},[ce,H]),(0,ha.useEffect)(()=>{Z.current=K,se.current?.(K)},[K]);const le=(0,ha.useCallback)(e=>[...("function"==typeof l?l(e,_):l)??[]].sort((e,t)=>e.time-t.time),[l,_]),de=(0,ha.useCallback)((e,t,n)=>{if(!t.gateId||!V.get(t.gateId)?.capacity)return!0;const i=Number(t.gateVisit),r=Number.isFinite(i)&&i>0?Math.floor(i):n.filter(e=>e.gateId===t.gateId).findIndex(e=>e.id===t.id)+1;return r>0&&(ee.current.get(`${e.id}:${t.gateId}`)??0)>=r},[V]),ue=(0,ha.useCallback)(()=>{if(!ie.length)return;const e=ie.flatMap(e=>{const t=e.getSnapshot?.();return t?[t]:[]});var t,n;(t=te.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})||(te.current=e,ne.current?.(e))},[ie]),he=(0,ha.useMemo)(()=>K.flatMap((e,t)=>{const n=Ca(e,t,_,k);return $a(e,t,_,n,G,X,i)}),[i,_,X,G,k,K]),pe=(0,ha.useCallback)((e,t)=>{let n=!1;const i=Z.current.map(i=>{if(i.id!==e)return i;const r=t(i);return n=n||r!==i,r});n&&(Z.current=i,Q(i))},[]);(0,ha.useImperativeHandle)(t,()=>function(e){const{statesRef:t,setStates:n,elapsedRef:i,frameRef:r,layout:o,projectPlacement:s,positiveById:a,negativeById:c,coreBody:l,createState:d}=e;return{push:e=>{const u=d(e,t.current.length,i.current),h=Ca(u,t.current.length,o,s),p=$a(u,t.current.length,o,h,a,c,l),f=[...t.current,u];t.current=f,n(f),r.current?.pushMany(p),r.current?.step(0)},pushMany:e=>{const u=[...t.current],h=[],p=i.current;e.forEach(e=>{const t=d(e,u.length,p),n=Ca(t,u.length,o,s);h.push(...$a(t,u.length,o,n,a,c,l)),u.push(t)}),t.current=u,n(u),h.length&&r.current?.pushMany(h),r.current?.step(0)},remove:e=>{const i=Array.isArray(e)?e:[e],o=[],s=[];for(const e of i){const n=t.current.find(t=>t.id===e);n&&(o.push(n.datum),s.push(Ma(n.id),...n.activePositiveIds.map(e=>Sa(n.id,e))),n.negativeIds.forEach((e,t)=>{s.push(Ia(n.id,e,t))}))}return t.current=t.current.filter(e=>!i.includes(e.id)),n(t.current),r.current?.remove(s),o},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 f=u(n.datum),m=d(f,0>h?t.current.length:h,n.startedAt??i.current),y=Ca(m,0>h?t.current.length:h,o,s);r.current?.remove([Ma(n.id),...n.activePositiveIds.map(e=>Sa(n.id,e)),...n.negativeIds.map((e,t)=>Ia(n.id,e,t))]),r.current?.pushMany($a(m,0>h?t.current.length:h,o,y,a,c,l)),t.current=t.current.map(t=>t.id===e?m:t)}return n(t.current),p},clear:()=>{t.current=[],n([]),r.current?.clear()},getData:()=>t.current.map(e=>e.datum),getScales:()=>null,getCustomLayout:()=>r.current?.snapshot()??null,popBodies:(e,t)=>r.current?.popBodies(e,t)??[]}}({statesRef:Z,setStates:Q,elapsedRef:J,frameRef:C,layout:_,projectPlacement:k,positiveById:G,negativeById:X,coreBody:i,createState:ce}),[i,ce,_,X,G,k]);const fe=(0,ha.useCallback)((e,t,n)=>{!function(e){const{project:t,effect:n,controls:i,layout:r,positiveById:o,negativeById:s,coreBody:a,popBodies:c}=e,l=i.readBodies().find(e=>e.id===Ma(t.id)),d=i.readBodies(),u=l?.x??r.startX,h=l?.y??r.routeY,p=function(e,t){let n=-1;for(const i of t)Ya(i,e.id)&&(n=Math.max(n,Ha(i)));return Math.max(e.negativeIds.length,n+1)}(t,d),f=Ta(n.addNegative).flatMap((e,n)=>{const i=s.get(e);return i?[Ba(t,i,p+n,u,h,r)]:[]}),m=Ta(n.addPositive).flatMap(e=>{if(!o.get(e)||t.activePositiveIds.includes(e))return[];const n={...Aa(r),routeY:h,socketY:h,startX:u,startY:h};return $a({...t,activePositiveIds:[e],negativeIds:[]},0,r,n,o,s,a).filter(e=>e.id.includes(":positive:"))});(f.length||m.length)&&i.pushMany([...f,...m]);const y=Na(t,n);for(const e of y){const n=o.get(e);c([Sa(t.id,e)],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??10)+3})}const g=Wa(t,n),x=function(e,t,n){const i=t.filter(t=>Ya(t,e.id)).sort((e,t)=>Ha(e)-Ha(t)||e.id.localeCompare(t.id)),r=new Set;return n.map(t=>{const n=i.find(e=>!r.has(e.id)&&e.datum.property?.id===t.propertyId);return n?(r.add(n.id),n.id):Ia(e.id,t.propertyId,t.index)})}(t,d,g);g.forEach((e,t)=>{const n=s.get(e.propertyId);c([x[t]],{color:n?.popColor??n?.color,durationMs:900,radius:(n?.radius??7)+3})})}({project:e,effect:t,controls:n,layout:_,positiveById:G,negativeById:X,coreBody:i,popBodies:(e,t)=>C.current?.popBodies(e,t)})},[i,_,X,G]),me=(0,ha.useCallback)(({body:e,bodies:t})=>function(e){const{body:t,bodies:n,layout:i,states:r,projectPlacement:o,positiveById:s,negativeById:a,projectEvents:c,gateById:l,coreForceMode:d,terminalBehavior:u,elapsed:h}=e,p=t.datum;if(!p?.__gauntlet)return null;const f=r.findIndex(e=>e.id===p.projectId),m=0>f?void 0:r[f];if(!m)return null;const y=Ca(m,f,i,o),g=n.find(e=>e.id===Ma(m.id)),x=m.negativeIds.reduce((e,t)=>e+(a.get(t)?.load??1),0),b=m.killed?0:58;if(p.kind!==ga){if(!g)return null;let e;const r=p.property;if(r?.target){const o=n.filter(e=>{const t=e.datum;return t?.__gauntlet&&t.projectId===m.id&&t.kind===p.kind}).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),s=Math.max(0,o.findIndex(e=>e.id===t.id));e=r.target({body:t,bodies:n,core:g,index:s,layout:i,placement:y,project:m})??{x:g.x,y:g.y}}else if(p.kind===xa&&p.property){const t=Pa(m.activePositiveIds,p.property.id);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===ba&&e.datum.projectId===m.id).sort((e,t)=>(e.id+"").localeCompare(t.id+"")),r=Math.max(0,i.findIndex(e=>e.id===t.id)),o=Math.floor(r/4);e={x:g.x+18*(r%4-(Math.min(4,i.length-4*o)-1)/2),y:g.y+54+13*o}}const o="circle"===t.shape.type?t.shape.radius:8;e=ja(e.x,e.y,o,i);const s=ja(t.x,t.y,o,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!==xa||m.killed?0:3.2*(r?.buoyancy??r?.value??1),c=p.kind===ba?{x:.22*(r?.pull?.x??-8),y:.22*(r?.pull?.y??22)}:{x:0,y:0};return{x:28*(e.x-t.x)-3*(t.vx-g.vx)+c.x+.01*b,y:28*(e.y-t.y)-3*(t.vy-g.vy)+c.y-a}}if(m.killed)return{x:44*((m.crashX??m.metrics.lastX??t.x)-t.x)-9*t.vx,y:160+12*x-1.6*t.vy};const v=c(m),w=function(e,t,n,i,r,o,s){if(t.killed)return{x:t.metrics.lastX??i.graveyardX,y:i.graveyardY};const a=r[r.length-1];if(!a)return{x:i.socketX,y:i.routeY};const c=r.find(n=>e>=n.time&&!t.eventsApplied.includes(n.id)&&!(!n.gateId||!o.get(n.gateId)?.capacity)),l=c?Math.min(e,c.time):e,d="built"===t.outcome||"built_diminished"===t.outcome;if(l>a.time+.85){if("hold-last"===s){const e=a.gateId?o.get(a.gateId):void 0;return{x:a.routeX??e?.x??i.socketX,y:a.routeY??i.routeY}}return d?{x:i.socketX,y:i.socketY}:{x:i.graveyardX,y:i.graveyardY-14}}const u=.85*t.delay+12*t.negativeIds.length+8*(t.poppedPositiveIds.length+t.missingPositiveIds.length),h=[{time:0,x:i.startX,y:i.startY},...r.map(e=>{const t=e.gateId?o.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,u)}})].sort((e,t)=>e.time-t.time);let p=h[0],f=h[h.length-1];for(let e=1;h.length>e;e+=1){if(h[e].time>=l){f=h[e];break}p=h[e]}const m=Math.max(0,Math.min(1,(l-p.time)/Math.max(.1,f.time-p.time))),y=m*m*(3-2*m);return{x:p.x+(f.x-p.x)*y,y:p.y+(f.y-p.y)*y+7*Math.sin(2.6*l)}}(Math.max(0,h-(m.startedAt??0)),m,0,y,v,l,u),k=m.activePositiveIds.reduce((e,t)=>e+(s.get(t)?.buoyancy??s.get(t)?.value??1),0);return"net"===d?{x:15*(w.x-t.x)-1.8*t.vx+.18*b,y:1.25*(y.routeY-t.y)-1.4*t.vy+32*(x-k)}:{x:15*(w.x-t.x)-1.8*t.vx+.18*b,y:15*(w.y-t.y)-1.8*t.vy+13*x-2.2*k}}({body:e,bodies:t,layout:_,states:Z.current,projectPlacement:k,positiveById:G,negativeById:X,projectEvents:le,gateById:V,coreForceMode:r,terminalBehavior:j,elapsed:J.current}),[r,V,_,X,G,le,k,j]),ye=(0,ha.useCallback)((e,t)=>{!function(e,t,n){const{frameProps:i,elapsedRef:r,statesRef:o,crashDetection:s,layout:a,projectEvents:c,gateById:l,capacityEventReady:d,addBodiesForEffect:u,updateProjectState:h,viability:p,positiveById:f,negativeById:m,outcome:y,reportCapacity:g}=n;i.onTick?.(e,t),r.current=e.elapsedSeconds??t.snapshot().elapsedSeconds,g();for(const e of o.current){const n=t.readBodies().find(t=>t.id===Ma(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,r.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,r.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,r.current-(e.startedAt??0)),o=c(e),g=o.filter(t=>i>=t.time&&!e.eventsApplied.includes(t.id)&&d(e,t,o));let x=e;for(const n of g){const r=n.gateId?l.get(n.gateId):void 0,o=n.effects??[];for(const e of o){const i={event:n,gate:r,negativeProperties:m,positiveProperties:f,project:x};e.when&&!e.when(i)||(u(x,e,t),x=Fa(x,e,i))}const s={...Oa(n,o),appliedAt:i};x=La(x,s),h(e.id,e=>{let t=La(e,s);if(t===e)return e;for(const e of o)t=Fa(t,e,{event:n,gate:r,negativeProperties:m,positiveProperties:f,project:t});const i=p?.(t,{negativeProperties:m,positiveProperties:f})??Ra(t,f,m);return t={...t,viability:i},n.final&&(t={...t,outcome:n.outcome??y?.(t,{layout:a,negativeProperties:m,positiveProperties:f})??(t.viability>20?"built":"approved_not_built")}),t})}}}(e,t,{frameProps:d,elapsedRef:J,statesRef:Z,crashDetection:o,layout:_,projectEvents:le,gateById:V,capacityEventReady:de,addBodiesForEffect:fe,updateProjectState:pe,viability:A,positiveById:G,negativeById:X,outcome:b,reportCapacity:ue})},[fe,de,o,d,V,_,X,b,G,le,ue,pe,A]),ge=(0,ha.useCallback)((e,t)=>{const n="function"==typeof d.bodyStyle?d.bodyStyle(e,t):d.bodyStyle,i=e.datum;return i?.__gauntlet?{fill:i.kind===ga?"var(--semiotic-accent, #0f766e)":i.property?.color??"var(--semiotic-accent, #38bdf8)",stroke:i.kind===ga?"#f8fafc":"#0f172a",opacity:.96,...n}:n??{}},[d]),xe=(0,ha.useMemo)(()=>"function"==typeof n?n(K,_):n??[],[n,_,K]),be=(0,ha.useMemo)(()=>ya(xe),[xe]),ve=(0,ha.useMemo)(()=>$?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"}})}(K,_):[],[_,$,K]),we=(0,ha.useMemo)(()=>[...ve,...be],[be,ve]),ke=(0,ha.useCallback)((e,t)=>{d.onBodyPointerDown?.(e,t)},[d]),Me=(0,ha.useCallback)((e,t)=>{g&&g(e&&"object"==typeof e&&e.__gauntlet?e.sourceDatum:e,{x:t.x,y:t.y})},[g]);if(L)return L;const Se=Bs(e.tooltip,d),Ie=Ts(e,d,we,{chartMode:N,className:T,title:E,description:W,summary:F,accessibleTable:O,enableHover:z,margin:q}),je=$?(0,Za.jsx)(Qa,{states:K,layout:_}):void 0,Ae=$s(B?(0,Za.jsx)(Ua,{layout:_,states:K}):void 0,d.backgroundGraphics),Ce=$s(je,d.foregroundGraphics),Pe=d.renderBody??_a,Re=Se.tooltipContent??Xa;return Ds("GauntletChart",D,(0,Ja.createElement)(Kr,{...d,...Se,...Ie,key:`${D[0]}x${D[1]}:${H}`,ref:C,accessibleTable:e.accessibleTable??d.accessibleTable,backgroundGraphics:Ae,bodyForces:me,bodySemanticItems:d.bodySemanticItems??Ka,bodyStyle:ge,beforePaint:(e,t)=>{d.beforePaint?.(e,t),I&&function(e,t){const n=new Map(t.filter(e=>e.datum?.kind===ga).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===ga)continue;const r=n.get(t.projectId);r&&(e.globalAlpha=t.kind===ba?.24:.36,e.strokeStyle=t.kind===ba?"#d94a45":"#7a8794",e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke())}e.restore()}(e,t)},onClick:g?Me:Ie.onClick,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7,...d.config?.kernel??{}},colliders:[...va(_),...d.config?.colliders??[]]},controllers:re,enableHover:Se.enableHover??!0,foregroundGraphics:Ce,hoverRadius:e.hoverRadius??d.hoverRadius??18,initialSpawns:he,initialSpawnPacing:h,onBodyPointerDown:ke,onTick:ye,paused:v,regionEffects:[...U,...d.regionEffects??[]],renderBody:Pe,responsiveHeight:M,responsiveWidth:S,size:D,tooltipContent:Re}))});tc.displayName="GauntletChart";var nc=tc,ic=require("react"),rc=require("react/jsx-runtime");function oc(e){return e.toLocaleString(void 0,1e3>Math.abs(e)?{maximumFractionDigits:1}:{maximumFractionDigits:0})}function sc(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}function ac(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 cc(e){if(!e||"object"!=typeof e)return[];const t=e.flowPath;return Array.isArray(t)?t.map(ac).filter(e=>null!=e):[]}function lc(e,t){if(2>t.length)return null;let n=0;const i=[];for(let e=1;t.length>e;e+=1){const r=Math.hypot(t[e].x-t[e-1].x,t[e].y-t[e-1].y);i.push(r),n+=r}if(0>=n)return null;let r=null,o=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},f={distance:Math.hypot(e.x-p.x,e.y-p.y),point:p,progress:(o+h*l)/n,tangent:{x:d/l,y:u/l},totalLength:n};r&&f.distance>=r.distance||(r=f),o+=l}return r}function dc(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 r=Math.max(0,Math.min(1,t))*n;for(let t=1;e.length>t;t+=1){const n=e[t-1],o=e[t],s=Math.hypot(o.x-n.x,o.y-n.y);if(s>0){if(i+s>=r){const e=(r-i)/s;return{x:n.x+(o.x-n.x)*e,y:n.y+(o.y-n.y)*e}}i+=s}}return{...e[e.length-1]}}function uc(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function hc(e,t,n){const i=Math.hypot(e,t);if(n>=i||0>=i)return[e,t];const r=n/i;return[e*r,t*r]}function pc(e,t,n){const i=lc({...e,x:t[0].x,y:t[0].y},t),r=i?.tangent??{x:t[1].x-t[0].x,y:t[1].y-t[0].y},o=Math.hypot(r.x,r.y)||1,s=r.x/o,a=r.y/o,c=uc(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 fc=(0,ic.forwardRef)(function(e,t){const{chartId:n,colorBy:i,coordinateMode:r="auto",data:o,edges:s,emptyContent:a,flowSpeed:c=90,frameProps:l,links:d,loading:u,loadingContent:h,maxParticles:p=180,nodeIdAccessor:f="id",nodeXAccessor:m="x",nodeYAccessor:y="y",nodes:g,onObservation:x,particleRadius:b=4,particleRate:v=.16,pathAccessor:w="path",pathConstraint:k="path",paused:M,reducedMotion:S=!1,responsiveHeight:I,responsiveWidth:j,seed:A=1,showNodeLabels:C=!0,showSensors:P=!1,showStaticFlow:R=!0,sourceAccessor:D="source",targetAccessor:$="target",throughputAccessor:B="value"}=e,T=Ps(e,[760,420]),{chartSize:E,className:N,title:q,chartMode:z,margin:W,enableHover:F,description:O,summary:L,accessibleTable:Y}=T,H=(0,ic.useRef)(null),G=(0,ic.useMemo)(()=>g??[],[g]),X=(0,ic.useMemo)(()=>d??s??o??[],[o,s,d]),_=(0,ic.useMemo)(()=>So({nodes:G,links:X,nodeIdAccessor:f,nodeXAccessor:m,nodeYAccessor:y,sourceAccessor:D,targetAccessor:$,throughputAccessor:B,pathAccessor:w,coordinateMode:r,particleRate:v,maxParticles:p,particleRadius:b,flowSpeed:c,pathConstraint:k,reducedMotion:S,seed:A,size:E}),[X,G,E,r,c,p,f,m,y,b,v,w,k,S,A,D,$,B]);Zo(t,{frameRef:H,spawnDatum:(0,ic.useCallback)((e,t)=>{const n=So({nodes:G,links:[e],nodeIdAccessor:f,nodeXAccessor:m,nodeYAccessor:y,sourceAccessor:D,targetAccessor:$,throughputAccessor:B,pathAccessor:w,coordinateMode:r,particleRate:v,maxParticles:p,particleRadius:b,flowSpeed:c,pathConstraint:k,reducedMotion:S,seed:A+t+1,size:E}),i={id:(e.id??"physical-flow-push-"+t)+"",x:Qr(E).plot.x,y:Qr(E).plot.y,mass:1,shape:{type:"circle",radius:b},datum:e},o=n.initialSpawns.length?n.initialSpawns:[i];return{datumId:(e.id??o[0].id)+"",spawns:o}},[G,E,r,c,p,f,m,y,b,v,w,k,S,A,D,$,B]),seedRows:X,seedSpawns:_.initialSpawns});const V=i??"source",U=(0,ic.useMemo)(()=>Jr(V,"#2563eb"),[V]),K=(0,ic.useMemo)(()=>function(e,t,n){return{...e,observation:{...e.observation,chartId:t??e.observation?.chartId??"physical-flow",chartType:"PhysicalFlowChart",onObservation:n??e.observation?.onObservation}}}(_.config,n,x),[n,_.config,x]),Q=(0,ic.useRef)(l?.onTick);Q.current=l?.onTick;const Z=(0,ic.useCallback)((e,t)=>{S||"none"===k||function(e,t){const n=e.readBodies(),i=[],r=[];for(const o of n){const n=cc(o.datum);if(2>n.length)continue;const s=lc(o,n);if(!s)continue;const a=o.datum,c=Number(a?.flowSpeed),l=Number.isFinite(c)&&c>0?c:t;if(s.progress>=.985||s.distance>Math.max(90,14*uc(o))){i.push(o.id),r.push(pc(o,n,l));continue}const d=dc(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-o.vx)*o.mass*.16+(d.x-o.x)*o.mass*.045+(s.point.x-o.x)*o.mass*.08,p=(u.y*l-o.vy)*o.mass*.16+(d.y-o.y)*o.mass*.045+(s.point.y-o.y)*o.mass*.08,[f,m]=hc(h,p,o.mass*l*.35);e.applyImpulse(o.id,f,m)}i.length&&e.remove(i),r.length&&e.pushMany(r)}(t,c),Q.current?.(e,t)},[c,k,S]),J=Rs({data:null==d&&null==s&&null==o?void 0:X,emptyContent:a,loading:u,loadingContent:h,size:E});if(J)return J;const ee=function(e,t){const{showNodeLabels:n,showSensors:i,showStaticFlow:r}=t;if(e&&(r||i))return({size:t})=>{const o=[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,rc.jsxs)("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[r?e.links.map(e=>{const t=3+e.throughput/s*16,n=e.path[Math.floor(e.path.length/2)];return(0,rc.jsxs)("g",{children:[(0,rc.jsx)("path",{d:sc(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),(0,rc.jsx)("path",{d:sc(e.path),fill:"none",stroke:"var(--semiotic-accent, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),n?(0,rc.jsx)("text",{x:n.x,y:n.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:oc(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>(0,rc.jsxs)("g",{children:[i&&a.has(e.sensorId)?(0,rc.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,r?(0,rc.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,rc.jsx)("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text-primary, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}(_.metadata,{showNodeLabels:C,showSensors:P,showStaticFlow:R}),te=(ne=_.metadata)?ne.links.map(e=>{const t=e.path[Math.floor(e.path.length/2)]??e.path[0],n=`${e.sourceLabel} to ${e.targetLabel}: ${oc(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:sc(e.path),group:"flow"}}):[];var ne;const ie=Bs(e.tooltip,l),re=Ts(e,l,te,{chartMode:z,className:N,title:q,description:O,summary:L,accessibleTable:Y,enableHover:F,margin:W});return Ds("PhysicalFlowChart",E,(0,rc.jsx)(Kr,{...l,...ie,...re,ref:H,config:K,continuous:!S&&"none"!==k,foregroundGraphics:$s(ee,l?.foregroundGraphics),initialSpawns:_.initialSpawns,onTick:Z,paused:M||S,responsiveHeight:I,responsiveWidth:j,simulationExecution:"none"===k?l?.simulationExecution:"sync",size:E,bodyStyle:U,workerBodyThreshold:l?.workerBodyThreshold??1/0}))});fc.displayName="PhysicalFlowChart";var mc=require("react"),yc=require("react/jsx-runtime"),gc={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"}},xc=6.2;function bc(e,t,n){return Math.max(t,Math.min(n,e))}function vc(e){return e.length*xc}function wc(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 kc(e,t,n="auto"){const i=Math.max(1,Math.floor(t/xc)),r="compact"===n?wc(e,i):"full"===n?e:vc(e)>t?wc(e,i):e;return{text:r,textLength:vc(r)>t?Math.max(4,t):void 0}}function Mc(e,t={}){const{showFlowSpine:n=!0,showStageCounts:i=!0,showCapacityBadges:r=!0,showGroupSockets:o=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=t,{width:l,height:d,left:u,right:h,topY:p,bottomY:f,midY:m,stages:y,groups:g=[]}=e,x=f-p;return(0,yc.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,yc.jsx)("defs",{children:(0,yc.jsxs)("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[(0,yc.jsx)("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),(0,yc.jsx)("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),(0,yc.jsx)("rect",{x:0,y:0,width:l,height:d,fill:"url(#semiotic-process-floor)"}),(0,yc.jsx)("rect",{x:u-6,y:p-8,width:h-u+12,height:x+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,yc.jsx)("line",{x1:u+8,x2:h-8,y1:m,y2:m,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),o=gc[n],c=Math.max(12,e.width-8),l=bc(c-8,22,88),u=kc(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),b=kc(g,Math.max(16,c-10),"auto"),v=r&&!1!==e.showBadge&&c>=32,w=null!=e.count?`n=${e.count}${null!=e.processed?" done "+e.processed:""}`:"",k=kc(w,Math.max(16,c-8),"auto"),M=Math.max(30,p-15),S=M-13;return(0,yc.jsxs)("g",{"data-stage":e.id,"data-role":n,children:[(0,yc.jsx)("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:p+6,width:c,height:x-12,rx:10,fill:a?"none":o.fill,stroke:o.stroke,strokeWidth:a?1.85:"flow"===n?1:1.6}),y.length-1>t?(0,yc.jsx)("polygon",{points:`${e.x1-2},${m-7} ${e.x1+8},${m} ${e.x1-2},${m+7}`,fill:o.accent,opacity:.85}):null,h?(0,yc.jsxs)(yc.Fragment,{children:[(0,yc.jsx)("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-l/2,y:S,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),(0,yc.jsxs)("text",{x:e.x,y:M,textAnchor:"middle",fill:o.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[(0,yc.jsx)("title",{children:e.label}),u.text]})]}):null,v?(0,yc.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:b.textLength,lengthAdjust:b.textLength?"spacingAndGlyphs":void 0,children:[(0,yc.jsx)("title",{children:g}),b.text]}):null,i&&null!=e.count?(0,yc.jsxs)("text",{x:e.x,y:Math.min(d-8,f+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,yc.jsx)("title",{children:w}),k.text]}):null]},e.id)}),o?g.map((e,t)=>{const n=e.total??0,i=e.absorbed??0,r=e.complete??(n>0&&i>=n),o=!r&&n>0&&i/n>=.75,s=r?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=r?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",c=n>0?`${i}/${n}${r?" shipped":o?" almost":""}`:"feature "+(t+1),l=bc(Math.max(54,vc(e.label)+18,vc(c)+16),54,104),d=kc(e.label,l-12,"auto"),u=kc(c,l-12,"auto");return(0,yc.jsxs)("g",{"data-group":e.id,children:[(0,yc.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,yc.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,yc.jsx)("title",{children:e.label}),d.text]}),(0,yc.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,yc.jsx)("title",{children:c}),u.text]})]},e.id)}):null]})}var Sc=require("react/jsx-runtime"),Ic=(0,mc.forwardRef)(function(e,t){const{ballRadius:n=6,chromeOptions:i,colorBy:r,data:o,emptyContent:s,frameProps:a={},groupAnchorAlong:c,groupBy:l,groupCompletion:d,groupLabelAccessor:u,gravityX:h,gravityY:p,idAccessor:f,initialSpawnPacing:m,liveCapacity:y=!0,onCapacityChange:g,selection:x,bodyLimit:b,bodyMark:v,loading:w,loadingContent:k,paused:M,radiusAccessor:S,responsiveHeight:I,responsiveWidth:j,route:A="horizontal",seed:C=1,settle:P,springDamping:R,springStiffness:D,stageAccessor:$="stage",stages:B,workAccessor:T}=e,E=Ps(e,[900,420]),{chartSize:N,showProjection:q,showChrome:z,className:W,title:F,chartMode:O,margin:L,enableHover:Y,description:H,summary:G,accessibleTable:X}=E,_=(0,mc.useRef)(null),V=(0,mc.useMemo)(()=>_s(o??[]),[o]),U=(0,mc.useMemo)(()=>({data:V,stages:B,size:N,idAccessor:f,stageAccessor:$,groupBy:l,groupLabelAccessor:u,workAccessor:T,radiusAccessor:S,ballRadius:n,seed:C,route:A,groupCompletion:d,groupAnchorAlong:c,springStiffness:D,springDamping:R,gravityX:h,gravityY:p,settle:P}),[n,N,h,p,c,l,d,u,f,S,A,V,C,P,R,D,$,B,T]),K=(0,mc.useMemo)(()=>_o(U),[U]),Q=K.metadata;Zo(t,{frameRef:_,spawnDatum:(0,mc.useCallback)((e,t)=>{const i=_o({...U,data:[e],seed:C+t+1,settle:!0}).initialSpawns[0]??{id:(e.id??"process-flow-push-"+t)+"",x:Qr(N).plot.x,y:Qr(N).plot.y,mass:1,shape:{type:"circle",radius:n},datum:e};return{datumId:(e.id??i.id)+"",spawns:[i]}},[n,U,N,C]),seedRows:V,seedSpawns:K.initialSpawns});const Z=(0,mc.useMemo)(()=>Jr(r),[r]),J=(0,mc.useMemo)(()=>{if(!y)return a.controllers;const e=[...B.filter(e=>e.capacity&&e.capacity.unitsPerSecond>0).map(e=>{const t=e.capacity.unitsPerSecond;return zi({id:"process-capacity-"+e.id,regionId:"process-stage-"+e.id,unitsPerSecond:t,unitAccessor:e.capacity.unitAccessor??(T?"string"==typeof T?T:e=>{const t=e.datum;if(!t)return 1;try{return Number(T(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,B,T]),[ee,te]=(0,mc.useState)({}),ne=(0,mc.useRef)(J);ne.current=J;const ie=(0,mc.useRef)(a.onTick);ie.current=a.onTick;const re=!1!==z||null!=g;(0,mc.useEffect)(()=>{if(!g)return;const e=Object.values(ee);e.length&&g(e)},[ee,g]);const oe=(0,mc.useCallback)((e,t)=>{if(ie.current?.(e,t),!re)return;const n=ne.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)}te(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],r=t[i];if(!r)return!1;if(n.queueDepth!==r.queueDepth||n.blockedDepth!==r.blockedDepth||n.processedCount!==r.processedCount||n.unitsPerSecond!==r.unitsPerSecond||n.regionId!==r.regionId||n.metricRevision!==r.metricRevision)return!1}return!0}(e,i)?e:i)},[re]),se=(0,mc.useMemo)(()=>{const e=Z,t=a.bodyStyle;return v||t?(n,i)=>{const r="function"==typeof t?t(n,i):t;return{..."function"==typeof e?e(n):e,...r,mark:r?.mark??n.datum?.__physicsMark??n.datum?.mark??v}}:e},[v,Z,a.bodyStyle]),ae=Rs({data:o,emptyContent:s,loading:w,loadingContent:k,size:N});if(ae)return ae;if(!B?.length)return Ds("ProcessFlowChart",N,(0,Sc.jsx)("div",{role:"status",style:{width:N[0],height:N[1],display:"grid",placeItems:"center",color:"var(--semiotic-text-secondary, #64748b)"},children:"ProcessFlowChart requires a non-empty stages array."}));const ce=function(e,t,n={},i){if(!1===t||!e)return;const{volume:r,stages:o,groups:s,groupCompletion:a}=e,c=new Map(r.stages.map(e=>[e.id,e])),l=new Map(a.map(e=>[e.id,e]));return({size:e})=>{const t=Number(e[0])||r.width,a=Number(e[1])||r.height,d=o.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 Mc({width:t,height:a,left:r.left,right:r.right,topY:r.topY,bottomY:r.bottomY,midY:r.midY,stages:d,groups:u},{showCapacityBadges:!0,showGroupSockets:!0,...i})}}(Q,z,ee,i),le=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 r=[Number(n[0])||t.volume.width,Number(n[1])||t.volume.height],o=Qr(r),s=Math.max(1,...e.map(e=>e.value)),a=Math.min(48,.18*o.plot.height),c=o.plot.y+6;return(0,Sc.jsx)("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,n)=>{const r=e[n];if(!r)return null;const o=i.get(t.id);if(!o)return null;const l=Math.max(2,r.value/s*a),d=Math.max(8,.35*o.width);return(0,Sc.jsx)("rect",{x:o.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)})})}}(K.projectionRows,Q,q),de=[...to(K.projectionRows,N,"stage"),...ya(Q?.groups??[])],ue=Bs(e.tooltip,a),he=Ts(e,a,de,{chartMode:O,className:W,title:F,description:H,summary:G,accessibleTable:X,enableHover:Y,margin:L}),pe=[...Q?.regionEffects??[],...a.regionEffects??[]];return Ds("ProcessFlowChart",N,(0,Sc.jsx)(Kr,{...a,...ue,...he,ref:_,controllers:J,regionEffects:pe,selection:x??a.selection,backgroundGraphics:$s(ce,a.backgroundGraphics),foregroundGraphics:$s(le,a.foregroundGraphics),initialSpawns:K.initialSpawns,initialSpawnPacing:m??K.initialSpawnPacing,onTick:oe,paused:M,responsiveHeight:I,responsiveWidth:j,size:N,bodyStyle:se,config:{...K.config,...null!=b?{bodyLimit:b,eviction:"oldest"}:{},...a.config}}))});Ic.displayName="ProcessFlowChart";var jc=[.1,.5,.9],Ac=1e6,Cc=12;function Pc(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Rc(e,t,n,i,r){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??r)}function Dc(e){const t=Number(e.toFixed(Cc));return Object.is(t,-0)?0:t}function $c(e,t,n,i){const r=e.flatMap((e,r)=>{const o=Pc(Rc(e,r,t,n,"time")),s=Pc(Rc(e,r,t,i,"value"));return null==o||null==s?[]:[{time:Dc(o),value:s,index:r}]});r.sort((e,t)=>e.time-t.time||e.index-t.index);const o=[];for(const e of r){const t=o[o.length-1];t?.time===e.time?t.value=e.value:o.push({time:e.time,value:e.value})}return o}function Bc(e,t,n,i){if(!e.length)return null;const r=e[0],o=e[e.length-1];if(r.time>t)return"clamp"===i?r.value:null;if(t>o.time)return"clamp"===i?o.value:null;const s=function(e,t){let n=0,i=e.length;for(;i>n;){const r=n+i>>>1;t>e[r].time?n=r+1:i=r}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 Tc(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,i=Math.floor(n),r=Math.ceil(n);return i===r?e[i]:e[i]+(e[r]-e[i])*(n-i)}function Ec(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",i=function(e){const t=(e??jc).map(e=>{const t=Pc(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return Dc(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),r=function(e){if(Array.isArray(e)){if(e.length>Ac)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ac} points`);return Array.from(new Set(e.map(Pc).filter(e=>null!=e).map(Dc))).sort((e,t)=>e-t)}const t=e,n=Pc(t.start),i=Pc(t.end),r=Pc(t.step);if(null==n||null==i||null==r||0>=r||n>i)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const o=Math.floor((i-n)/r)+1;if(o>Ac)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ac} points`);const s=[],a=1e-10*Math.max(1,Math.abs(i),Math.abs(n));for(let e=0;o>e;e+=1){const t=n+e*r;if(t>i+a)break;s.push(Dc(Math.min(t,i)))}if(s.length&&a>=Math.abs(s[s.length-1]-i)||s.push(Dc(i)),s.length>Ac)throw new RangeError(`physicsReferenceEnvelope sampleAt exceeds ${Ac} points`);return Array.from(new Set(s)).sort((e,t)=>e-t)}(e.sampleAt),o=e.runs.map(t=>$c(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:r.map(e=>{const r=o.map(i=>Bc(i,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),s={};for(const e of i)s[e]=r.length?Tc(r,e):null;return{time:e,count:r.length,min:r.length?r[0]:null,max:r.length?r[r.length-1]:null,median:r.length?Tc(r,.5):null,quantiles:s}}),quantiles:i,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Nc(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function qc(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Pc(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const i=Dc(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 zc(e,t,n){return t>e?"below":e>n?"above":"inside"}function Wc(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,r=t.value-t.lower,o=e.value-e.upper,s=t.value-t.upper,a=[0,1];for(const[e,t]of[[i,r],[o,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 r=a[i],o=a[i+1];if(r>=o)continue;const s=(r+o)/2,u=(o-r)*n,h=zc(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 Fc(e,t,n={}){const i=n.interpolation??t.interpolation,r=n.outsideDomain??t.outsideDomain,o=$c(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),s=n.lower??Nc(t,"lower"),a=n.upper??Nc(t,"upper"),c=t.points.map(e=>{const t=Bc(o,e.time,i,r),n=qc(e,s),c=qc(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":zc(t,n,c)}});let l=0,d=0,u=0,h=0,p=null,f=0,m=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>f&&(f=n,m=e.time)}let y=0,g=0,x=0,b=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],r=Math.max(0,n.time-t.time);if(r>0){if("linear"===i){const e=Wc(t,n);y+=e.below,g+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=r,"below"===t.status?y+=r:"above"===t.status?x+=r:g+=r)}}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:b,unobservedDuration:Math.max(0,k-b),belowDuration:y,insideDuration:g,aboveDuration:x,peakExcess:h,peakExcessAt:p,peakDeficit:f,peakDeficitAt:m}}function Oc(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function Lc(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,Oc(e)]))}}function Yc(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),r=e.stages.findIndex(e=>e.id===i);if(0>r)return e;const o=n.entityId?.(t)??t.bodyId;if(!o)return e;const s=e.entities[o]??Oc(o),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:r>s.furthestStageIndex?i:s.furthestStageId,furthestStageIndex:Math.max(s.furthestStageIndex,r),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>r?s.regressionCount+1:s.regressionCount};return{...e,bodyIds:e.bodyIds.includes(o)?e.bodyIds:[...e.bodyIds,o],entities:{...e.entities,[o]:u}}}function Hc(e){const t=e.bodyIds.map(t=>e.entities[t]??Oc(t)),n=t.length;let i=n;return e.stages.map((e,r)=>{const o=t.filter(e=>e.furthestStageIndex>=r).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:o,entered:s,total:n,conversion:n>0?o/n:0,fromPrevious:i>0?o/i:0,dropoff:Math.max(0,i-o),visits:a,repeatVisits:Math.max(0,a-s)};return i=o,c})}function Gc(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Xc(e,t,n,i){const r="function"==typeof e?e(t,n):e;return Number.isFinite(r)?Number(r):i}function _c(e,t,n){return Gc(e[t])??n}function Vc(e,t){return"number"==typeof e?e:e?.[t]??0}function Uc(e){const{band:t,idPrefix:n,plot:i,projection:r}=e,{includeBoundaryWalls:o=!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 r=e.scale(i);Number.isFinite(r)&&(n.add(Number(r)),n.add(Number(r)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=o?c.length-1:c.length-2,d=[];for(let e=o?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"===r?{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 Kc(e){const{plot:t,idPrefix:n="physics-scale",bounds:i={},xBins:r,xBands:o,yBands:s}=e,a=[];if(!1!==i&&a.push(...di(t,{idPrefix:n,...i})),r){const{idPrefix:e,yTop:i,yBottom:o,...s}=r;a.push(...ui({...s,idPrefix:e??n+"-xbin",yTop:i??t.y,yBottom:o??t.y+t.height}))}return o&&a.push(...Uc({band:o,idPrefix:o.idPrefix??n+"-xband",plot:t,projection:"x"})),s&&a.push(...Uc({band:s,idPrefix:s.idPrefix??n+"-yband",plot:t,projection:"y"})),a}function Qc(e){const{plot:t,rows:n,columns:i=n+1,pegRadius:r=3,idPrefix:o="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,f=t.width/h,m=[];for(let e=0;u>e;e+=1){const n=c&&e%2==1?f/2:0;for(let i=0;h>i;i+=1){const a=t.x+f*(i+.5)+n;t.x+r>a||a>t.x+t.width-r||m.push({id:`${o}-${e}-${i}`,shape:{type:"aabb",x:a,y:s+e*p,width:2*r,height:2*r},restitution:l,friction:d})}}return m}function Zc(e,t={}){const{idPrefix:n="physics-token",radius:i=5,shape:r,mass:o,vx:s,vy:a,spawnAt:c,seed:l=1,jitter:d,datum:u}=t,h=pn(l),p=Vc(d,"x"),f=Vc(d,"y");return e.map((e,l)=>{const d=Xc(t.x,e,l,_c(e,"x",0)),m=Xc(t.y,e,l,_c(e,"y",0)),y=Xc(i,e,l,5),g="function"==typeof r?r(e,l):r??{type:"circle",radius:y};return{id:`${n}-${e.index??l}`,x:d+(h()-.5)*p,y:m+(h()-.5)*f,vx:Xc(s,e,l,0),vy:Xc(a,e,l,0),mass:Xc(o,e,l,1),spawnAt:Xc(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 Jc(e,t={}){const{idPrefix:n="sediment",collider:i=!0,colliderThickness:r=1,restitution:o=.05,friction:s=.2,...a}=t,c=Vn(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+r/2,width:e.width,height:r},restitution:o,friction:s})):[];return{columns:c,colliders:l}}function el(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:i=1,startAt:r=0,rebase:o=!0,sort:s=!0}=t,a=e.map((e,t)=>({spawn:e,time:function(e,t,n){return Gc("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:r+(o?t-c:t)})).sort((e,t)=>s?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:r,timeAccessor:"spawnAt",timeScale:i}}}var tl=require("react");function nl(e,t,n={}){const i=new Set,r=[...e.get(t)??[]];let o=0;for(;r.length>o;){const t=r[o];if(o+=1,!i.has(t)){i.add(t);for(const n of e.get(t)??[])r.push(n)}}return n.includeStart&&i.add(t),i}function il(e,t,n){return ra(n,e,t)}function rl(e,t){return t>e?-1:e>t?1:0}function ol(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function sl(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function al(e){const t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function cl(e){const t=[],n=new Map,i=[],r=new Set;e.data.forEach((o,s)=>{const a=(il(o,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=(il(o,s,e.laneAccessor)??"Unassigned")+"";r.has(c)||(r.add(c),i.push(c));const l=il(o,s,e.dependencyAccessor)??[],d=Array.from(new Set(Array.from(l,e=>e+""))).sort(rl),u=il(o,s,e.blockerAccessor),h=il(o,s,e.statusAccessor)??(u?"blocked":"waiting");n.set(a,{id:a,label:(il(o,s,e.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:s,datum:o,dependencyIDs:d,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:il(o,s,e.startAccessor),end:il(o,s,e.endAccessor),progress:al(il(o,s,e.progressAccessor)),status:h,completionTime:il(o,s,e.completionTimeAccessor),blockerReason:u||void 0,milestone:!!il(o,s,e.milestoneAccessor)})});const o=e.laneOrder?[...e.laneOrder,...i.filter(t=>!e.laneOrder?.includes(t))]:i,s=new Map(o.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,r)=>{const o=n.get(i);if(!o)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${i}".`,taskIDs:[e.id,i]});const s={id:ol(i,e.id),sourceID:i,targetID:e.id,sourceIndex:o.index,targetIndex:e.index,socketID:sl(e.id,r),socketIndex:r};l.push(s),a.get(e.id)?.push(s),c.get(i)?.push(s),e.incomingEdgeIDs.push(s.id),e.socketIDs.push(s.socketID),o.outgoingEdgeIDs.push(s.id)});for(const e of a.values())e.sort((e,t)=>rl(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=sl(e.targetID,t)});for(const e of c.values())e.sort((e,t)=>rl(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(rl);let f=0;for(;p.length;){const e=p.shift();f+=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(f!==n.size){const e=[...n.keys()].filter(e=>(u.get(e)??0)>0).sort(rl);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let m=0;const y=[...n.values()].sort((e,t)=>e.index-t.index);for(const e of y)e.level=h.get(e.id)??0,m=Math.max(m,e.level);return{nodes:y,edges:l,byID:n,incoming:a,outgoing:c,lanes:o,maxLevel:m,diagnostics:t,valid:0===t.length}}function ll(e,t,n={}){const i=Math.max(240,t.width),r=Math.max(220,t.height),o=t.paddingX??48,s=t.paddingTop??48,a=t.paddingBottom??44,c=Math.max(70,(i-2*o)/Math.max(1,e.lanes.length)),l=Math.max(76,(r-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)),f=new Map;for(const t of e.nodes){const e=`${t.laneIndex}:${t.level}`,n=f.get(e)??[];n.push(t),f.set(e,n)}for(const e of f.values())e.sort((e,t)=>rl(e.id,t.id));const m=e.nodes.map(e=>{const t=f.get(`${e.laneIndex}:${e.level}`)??[e],n=Math.max(0,t.findIndex(t=>t.id===e.id));return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:o+c*(e.laneIndex+.5),y:s+l*(e.level+.5)+(n-(t.length-1)/2)*Math.min(18,.3*u),width:d,height:u}}),y=new Map(m.map(e=>[e.taskID,e])),g=[],x=[];e.edges.forEach((t,n)=>{const i=y.get(t.sourceID),r=y.get(t.targetID);if(!i||!r)return;const o=e.incoming.get(t.targetID)??[],s=Math.min(.72*r.width,14*Math.max(1,o.length-1)),a=o.length>1?r.x-s/2+s*t.socketIndex/(o.length-1):r.x,c=r.y-r.height/2-h-2;g.push({id:t.socketID,edgeID:t.id,taskID:r.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 b=new Map(g.map(e=>[e.id,e])),v=new Map(x.map(e=>[e.edgeID,e]));return{tasks:m,sockets:g,routes:x,taskByID:y,socketByID:b,routeByEdgeID:v}}function dl(e,t,n="all"){const i=Array.from(new Set(t)).sort(rl),r=new Set,o=()=>i.every(e=>r.has(e));return{taskID:e,mode:n,incomingEdgeIDs:i,deliver:e=>i.includes(e)?(r.add(e),o()):o(),reset:(e=[])=>{r.clear();for(const t of e)i.includes(t)&&r.add(t)},isSatisfied:o,getSnapshot:()=>({taskID:e,mode:n,incomingEdgeIDs:[...i],deliveredEdgeIDs:[...r].sort(rl),satisfied:o()})}}function ul(e){return e instanceof Date?e.getTime():Number(e)}function hl(e,t){const n=ul("object"!=typeof t||t instanceof Date?t:t.currentTime),i=e.map((e,t)=>({event:e,index:t,time:ul(e.at)})).filter(e=>Number.isFinite(e.time)&&n>=e.time).sort((e,t)=>e.time-t.time||e.index-t.index),r=new Set,o=new Map,s=new Set,a=new Set;for(const{event:e}of i)"task-completed"===e.type?(r.add(e.taskID),o.delete(e.taskID)):"task-blocked"===e.type?o.set(e.taskID,e.reason):"task-unblocked"===e.type?o.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:r,blockedByTaskID:o,deliveredEdgeIDs:s,armedTaskIDs:a}}function pl(e,t,n={}){const i=new Set(n.completedTaskIDs??[]),r=[...nl(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),o=Array.from(new Set(r.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:r.length,affectedLaneCount:o.length,downstreamTaskIDs:r.map(e=>e.id),affectedLanes:o}}var fl=[];function ml(e,t=0){if(e instanceof Date)return e.getTime();const n=Number(e);return Number.isFinite(n)?n:t}function yl(e){if(null==e.completionTime)return null;const t=ml(e.completionTime,NaN);return Number.isFinite(t)?t:null}function gl(e,t,n,i){const r=new Set;for(const o of e.nodes){const s=e.incoming.get(o.id)??[];(i.has(o.id)||!n.has(o.id)&&s.every(e=>t.has(e.id)))&&r.add(o.id)}return r}function xl(e,t,n,i){const r=e.nodes.map(yl).filter(e=>null!=e),o=r.length?Math.min(...r)-1:0,s="replay"!==t||i?n:o,a=new Set,c=new Map;for(const n of e.nodes){const e=yl(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:gl(e,l,c,a),blockers:c,previewTaskID:null}}function bl(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 vl(e){const t=e.datum;return"dependency-ball"===t?.kind&&Array.isArray(t.route)?t:null}function wl(e){const t=vl(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,r=0;for(let o=1;t.length>o;o+=1){const s=t[o-1],a=t[o],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=r+h*u),r+=u}return i}(e.body,t.route),r=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 r=e[i-1],o=e[i],s=o.x-r.x,a=o.y-r.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:r.x+s*e,y:r.y+a*e},tangent:{x:s/c,y:a/c}}}n+=c}}const i=e[e.length-2],r=e[e.length-1],o=r.x-i.x,s=r.y-i.y,a=Math.hypot(o,s)||1;return{point:r,tangent:{x:o/a,y:s/a}}}(t.route,Math.min(n,i+22));return{x:2.5*(78*r.tangent.x-e.body.vx)+8*(r.point.x-e.body.x),y:2.5*(78*r.tangent.y-e.body.vy)+8*(r.point.y-e.body.y)}}function kl(e,t){const n=t.points[0]??{x:0,y:0},i=t.points[1]??n,r=i.x-n.x,o=i.y-n.y,s=Math.hypot(r,o)||1;return{id:"dependency-ball:"+e.id,x:n.x,y:n.y,vx:r/s*42,vy:o/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 Ml=require("react/jsx-runtime");function Sl({machine:e,layout:t,runtime:n,downstreamSet:i,selectedSet:r,width:o,height:s,seed:a,reduced:c,onSelectTask:l}){return(0,Ml.jsxs)("svg",{"aria-hidden":"true",width:o,height:s,viewBox:`0 0 ${o} ${s}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[(0,Ml.jsx)("defs",{children:(0,Ml.jsx)("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:(0,Ml.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),r=i[0]?.x??0;return(0,Ml.jsxs)("g",{children:[(0,Ml.jsx)("line",{x1:r,x2:r,y1:32,y2:s-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),(0,Ml.jsx)("text",{x:r,y:23,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),r=n.inFlight.has(e.edgeID),o=i.has(e.targetID)||i.has(e.sourceID),s=e.points.map(e=>`${e.x},${e.y}`).join(" ");return(0,Ml.jsx)("polyline",{points:s,fill:"none",stroke:o?"var(--semiotic-highlight, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:o?4:r?3:2,strokeOpacity:t||r||o?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{const t=n.delivered.has(e.edgeID);return(0,Ml.jsxs)("g",{children:[(0,Ml.jsx)("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-background, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&(0,Ml.jsx)("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{const o=t.taskByID.get(e.id);if(!o)return null;const s=n.completed.has(e.id),d=n.blockers.has(e.id),u=n.previewTaskID===e.id,h=r.has(e.id)||u,p=i.has(e.id),f=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-muted, #75818a)"}(e,n),m=o.x-o.width/2,y=o.y-o.height/2,g=Math.max(2,o.height*e.progress);return(0,Ml.jsxs)("g",{children:[(0,Ml.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,Ml.jsx)("rect",{x:m,y:y,width:o.width,height:o.height,rx:e.milestone?12:4,fill:"var(--semiotic-background, #fff)",stroke:h||p?"var(--semiotic-highlight, #e08a1e)":f,strokeWidth:h?4:p?3:2}),(0,Ml.jsx)("rect",{x:m+3,y:y+o.height-g+1,width:o.width-6,height:Math.max(0,g-4),rx:2,fill:f,opacity:s?.86:.46})]}),d&&(0,Ml.jsxs)("g",{opacity:u?.28:1,children:[(0,Ml.jsx)("line",{x1:m-8,x2:m+14,y1:o.y+9,y2:o.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),(0,Ml.jsx)("circle",{cx:m-8,cy:o.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),(0,Ml.jsxs)("g",{onPointerDown:()=>l(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[(0,Ml.jsx)("rect",{x:m,y:y,width:o.width,height:o.height,fill:"transparent"}),(0,Ml.jsx)("text",{x:o.x,y:o.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,Ml.jsxs)("text",{x:o.x,y:o.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-muted, #5f6b72)",children:[Math.round(100*e.progress),"% · ",s?"done":d?"blocked":n.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}var Il=require("react/jsx-runtime"),jl={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},Al=(0,tl.forwardRef)(function(e,t){const{data:n,taskIDAccessor:i,labelAccessor:r,laneAccessor:o,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p,mode:f="snapshot",insight:m="blocker-amplification",currentTime:y,controls:g=!1,selectedTaskIDs:x,onSelectionChange:b,onObservation:v,reducedMotion:w,seed:k=31,width:M=920,height:S=620,responsiveWidth:I,responsiveHeight:j,title:A="Dependency chain reaction",description:C,className:P,accessibleTable:R=!0,enableHover:D=!0}=e,$=(0,tl.useRef)(null),[B,T]=(0,tl.useState)([]),E=x?Array.from(x):B,N=(0,tl.useMemo)(()=>new Set(E),[E]),q=ml(y,1/0),z="settle"===w,W=(0,tl.useMemo)(()=>cl({data:n,taskIDAccessor:i,labelAccessor:r,laneAccessor:o,dependencyAccessor:s,startAccessor:a,endAccessor:c,progressAccessor:l,statusAccessor:d,completionTimeAccessor:u,blockerAccessor:h,milestoneAccessor:p}),[n,i,r,o,s,a,c,l,d,u,h,p]),F=(0,tl.useMemo)(()=>ll(W,{width:M,height:S}),[W,M,S]),[O,L]=(0,tl.useState)(()=>xl(W,f,q,z)),Y=(0,tl.useRef)(O),H=(0,tl.useCallback)(e=>{Y.current=e,L(e)},[]),G=(0,tl.useCallback)(e=>v?.(e),[v]);(0,tl.useEffect)(()=>{const e=xl(W,f,q,z);$.current?.clear(),Y.current=e,L(e)},[W,f,q,z]);const X=(0,tl.useCallback)(e=>{const t=N.has(e)?E.filter(t=>t!==e):[e];x||T(t),b?.(t)},[x,b,N,E]),_=(0,tl.useCallback)(e=>{if(z)return;const t=bl(Y.current),n=[];for(const i of W.outgoing.get(e)??[]){if(t.delivered.has(i.id)||t.inFlight.has(i.id))continue;const e=F.routeByEdgeID.get(i.id);e&&(t.inFlight.add(i.id),n.push(kl(i,e)))}n.length&&(H(t),$.current?.pushMany(n,{pacing:{ratePerSec:8}}))},[H,F,W,z]),V=(0,tl.useCallback)((e,t)=>{const n=W.byID.get(e),i=Y.current;if(!n||i.completed.has(e))return;const r=bl(i);r.completed.add(e),r.blockers.delete(e),r.armed.add(e),null!=t&&(r.currentTime=t),H(r),G({type:"task-completed",taskID:e,datum:n.datum}),_(e)},[H,G,W,_]),U=(0,tl.useCallback)(e=>{const t=bl(Y.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){H(t);for(const e of n)G({type:"dependency-delivered",sourceID:e.sourceID,targetID:e.targetID});for(const e of i)G({type:"task-armed",taskID:e})}},[H,G,W]),K=(0,tl.useCallback)((e,t)=>{const n=[],i=[];for(const e of t.readBodies()){const t=vl(e);if(!t||Y.current.delivered.has(t.edgeID))continue;const r=t.route[t.route.length-1];r&&9>=Math.hypot(e.x-r.x,e.y-r.y)&&(n.push(t.edgeID),i.push(e.id))}i.length&&t.remove(i),n.length&&U(n)},[U]),Q=(0,tl.useCallback)(()=>{const e=bl(Y.current);for(const t of W.edges)e.completed.has(t.sourceID)&&e.delivered.add(t.id);e.inFlight.clear(),e.armed=gl(W,e.delivered,e.blockers,e.completed),e.playing=!1,$.current?.settle(),H(e),G({type:"machine-settled"})},[H,G,W]),Z=(0,tl.useCallback)(()=>{const e=bl(Y.current);e.playing=!1,H(e)},[H]),J=(0,tl.useCallback)(()=>{const e=Y.current,t=W.nodes.map(e=>({node:e,time:yl(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 V(t.node.id,t.time);Z();const n=[...e.blockers.keys()].map(t=>pl(W,t,{completedTaskIDs:e.completed})).sort((e,t)=>t.affectedLaneCount-e.affectedLaneCount||t.downstreamTaskCount-e.downstreamTaskCount);n[0]&&G({type:"machine-stalled",blockerID:n[0].blockerID,downstreamTaskCount:n[0].downstreamTaskCount,affectedLaneCount:n[0].affectedLaneCount})},[G,W,Z,V]),ee=(0,tl.useCallback)(()=>{if(z)return void Q();const e=bl(Y.current);e.playing=!0,H(e)},[H,z,Q]);(0,tl.useEffect)(()=>{if(!O.playing||"replay"!==f||z)return;const e=window.setInterval(J,760);return()=>window.clearInterval(e)},[f,z,O.playing,J]);const te=(0,tl.useCallback)(()=>{$.current?.clear(),H(xl(W,f,q,z))},[H,W,f,q,z]),ne=(0,tl.useCallback)(e=>{if(!W.byID.has(e))return;const t=bl(Y.current);t.previewTaskID=e,H(t);const n=pl(W,e,{completedTaskIDs:t.completed});G({type:"blocker-previewed",blockerID:e,downstreamTaskIDs:n.downstreamTaskIDs})},[H,G,W]),ie=(0,tl.useCallback)(()=>{const e=bl(Y.current);e.previewTaskID=null,H(e)},[H]),re=(0,tl.useCallback)((e,t)=>{if(!W.byID.has(e))return;const n=bl(Y.current);n.blockers.set(e,t),n.armed.delete(e),H(n)},[H,W]),oe=(0,tl.useCallback)(e=>{if(!W.byID.has(e))return;const t=bl(Y.current);t.blockers.delete(e),(W.incoming.get(e)??[]).every(e=>t.delivered.has(e.id))&&t.armed.add(e),H(t)},[H,W]),se=(0,tl.useCallback)(e=>pl(W,e,{completedTaskIDs:Y.current.completed}),[W]),ae=(0,tl.useCallback)(()=>{const e=Y.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,tl.useImperativeHandle)(t,()=>({play:ee,pause:Z,step:J,reset:te,settle:Q,previewResolve:ne,clearPreview:ie,completeTask:V,blockTask:re,unblockTask:oe,getAmplification:se,getMachineState:ae}),[re,ie,se,ae,Z,V,ee,ne,te,Q,J,oe]);const ce=O.previewTaskID??E[0]??null,le=ce?pl(W,ce,{completedTaskIDs:O.completed}):null,de=(0,tl.useMemo)(()=>new Set(le?.downstreamTaskIDs??[]),[le?.downstreamTaskIDs.join("|")]),ue=(0,tl.useMemo)(()=>function(e,t,n){return e.nodes.flatMap(i=>{const r=t.taskByID.get(i.id);if(!r)return[];const o=e.incoming.get(i.id)??[],s=o.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 ${o.length} prerequisites delivered.`,datum:i.datum,x:r.x,y:r.y,width:r.width,height:r.height,shape:"rect",group:i.lane}]})}(W,F,O),[F,W,O]),he=(0,tl.useMemo)(()=>(0,Il.jsx)(Sl,{machine:W,layout:F,runtime:O,downstreamSet:de,selectedSet:N,width:M,height:S,seed:k,reduced:z,onSelectTask:X}),[de,S,F,W,z,O,k,X,N,M]),pe=(0,tl.useMemo)(()=>{const e=[...O.blockers.keys()].map(e=>pl(W,e,{completedTaskIDs:O.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,O.blockers,O.completed]),fe=(0,tl.useMemo)(()=>[{id:"chain-left",shape:{type:"segment",x1:2,y1:0,x2:2,y2:S,thickness:4}},{id:"chain-right",shape:{type:"segment",x1:M-2,y1:0,x2:M-2,y2:S,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:S-2,x2:M,y2:S-2,thickness:4}}],[S,M]),me=!0===g?["play","pause","step","reset","settle"]:g||[];return(0,Il.jsxs)("div",W.valid?{className:P,style:{width:M,maxWidth:"100%",position:"relative"},children:[me.length>0&&(0,Il.jsx)("div",{"aria-label":"Chain reaction replay controls",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:me.map(e=>(0,Il.jsx)("button",{type:"button",onClick:"play"===e?ee:"pause"===e?Z:"step"===e?J:"reset"===e?te:Q,"aria-pressed":"play"===e?O.playing:void 0,children:e[0].toUpperCase()+e.slice(1)},e))}),(0,Il.jsx)(Kr,{ref:$,size:[M,S],responsiveWidth:I,responsiveHeight:j,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"===m?` Selected task reaches ${le.downstreamTaskCount} unfinished tasks across ${le.affectedLaneCount} lanes.`:""}`,accessibleTable:!1,enableHover:D,initialSpawns:fl,bodyForces:wl,bodyStyle:{fill:"var(--semiotic-accent, #f0a329)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.25},bodySemanticItems:!1,semanticItems:ue,onSemanticItemActivate:e=>e.id&&X(e.id),foregroundGraphics:()=>he,paused:z,continuous:O.inFlight.size>0,onTick:K,config:{bodyLimit:Math.max(16,W.edges.length+4),colliders:fe,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"}}}),R&&(0,Il.jsxs)("table",{style:jl,children:[(0,Il.jsx)("caption",{children:pe}),(0,Il.jsx)("thead",{children:(0,Il.jsxs)("tr",{children:[(0,Il.jsx)("th",{children:"Task"}),(0,Il.jsx)("th",{children:"Lane"}),(0,Il.jsx)("th",{children:"Progress"}),(0,Il.jsx)("th",{children:"State"}),(0,Il.jsx)("th",{children:"Waiting on"}),(0,Il.jsx)("th",{children:"Downstream reach"})]})}),(0,Il.jsx)("tbody",{children:W.nodes.map(e=>{const t=pl(W,e.id,{completedTaskIDs:O.completed});return(0,Il.jsxs)("tr",{children:[(0,Il.jsx)("th",{scope:"row",children:e.label}),(0,Il.jsx)("td",{children:e.lane}),(0,Il.jsxs)("td",{children:[Math.round(100*e.progress),"%"]}),(0,Il.jsx)("td",{children:O.completed.has(e.id)?"Completed":O.blockers.has(e.id)?"Blocked":O.armed.has(e.id)?"Armed":"Waiting"}),(0,Il.jsx)("td",{children:O.blockers.get(e.id)??(e.dependencyIDs.filter(e=>!O.completed.has(e)).join(", ")||"None")}),(0,Il.jsxs)("td",{children:[t.downstreamTaskCount," tasks / ",t.affectedLaneCount," lanes"]})]},e.id)})})]})]}:{className:P,role:"alert",style:{width:M,maxWidth:"100%"},children:[(0,Il.jsx)("strong",{children:"ChainReactionChart could not compile this dependency graph."}),(0,Il.jsx)("ul",{children:W.diagnostics.map((e,t)=>(0,Il.jsx)("li",{children:e.message},`${e.code}-${t}`))})]})});Al.displayName="ChainReactionChart";var Cl=Kr;