semiotic 3.9.0 → 3.9.2

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 (331) hide show
  1. package/README.md +102 -90
  2. package/agent-skill/semiotic-charts/SKILL.md +14 -10
  3. package/ai/componentMetadata.cjs +13 -3
  4. package/ai/dist/mcp-server.js +140 -36407
  5. package/ai/examples.md +109 -6
  6. package/ai/reference.md +55 -18
  7. package/ai/schema.json +5964 -1190
  8. package/ai/surface-manifest.json +51 -7
  9. package/ai/system-prompt.md +16 -3
  10. package/dist/c-3SCUN5HI.min.js +1 -0
  11. package/dist/c-3VVKFA4M.min.js +1 -0
  12. package/dist/c-43TJZS3F.min.js +1 -0
  13. package/dist/c-4DTZPSUD.min.js +1 -0
  14. package/dist/c-4ES5367Y.min.js +1 -0
  15. package/dist/c-54IRWOGM.min.js +1 -0
  16. package/dist/c-5D2S4RMI.min.js +1 -0
  17. package/dist/c-5JWCTX3G.min.js +1 -0
  18. package/dist/c-6CMMSN6N.min.js +1 -0
  19. package/dist/c-6HRB2L7H.min.js +1 -0
  20. package/dist/c-7W4SV36A.min.js +1 -0
  21. package/dist/c-A4WRGZFX.min.js +1 -0
  22. package/dist/c-AG7WWVIH.min.js +1 -0
  23. package/dist/c-AH6J4MTN.min.js +1 -0
  24. package/dist/c-ALYR5LKK.min.js +1 -0
  25. package/dist/c-BYDPC44I.min.js +1 -0
  26. package/dist/c-CFFIU2MW.min.js +1 -0
  27. package/dist/c-CGNHBHCE.min.js +1 -0
  28. package/dist/c-CJYSXIFV.min.js +1 -0
  29. package/dist/c-CKLIFCGN.min.js +1 -0
  30. package/dist/c-CZF7MV67.min.js +1 -0
  31. package/dist/c-D53OKBSY.min.js +1 -0
  32. package/dist/c-DBQ2V7CH.min.js +1 -0
  33. package/dist/c-DPMVAUAW.min.js +1 -0
  34. package/dist/c-ECJCKLYY.min.js +1 -0
  35. package/dist/c-EGATGOWJ.min.js +1 -0
  36. package/dist/c-EGR6VYBW.min.js +1 -0
  37. package/dist/c-ENF72HU5.min.js +1 -0
  38. package/dist/c-ESNR43AN.min.js +1 -0
  39. package/dist/c-F3LIKINL.min.js +1 -0
  40. package/dist/c-F5ZB5GJ6.min.js +1 -0
  41. package/dist/c-G3VYMHKE.min.js +1 -0
  42. package/dist/c-GR6MOEQC.min.js +1 -0
  43. package/dist/c-GSVCN34B.min.js +1 -0
  44. package/dist/c-GYOQCEFP.min.js +1 -0
  45. package/dist/c-H3DNMTCC.min.js +1 -0
  46. package/dist/c-I6J3FEZE.min.js +1 -0
  47. package/dist/c-IGH6MGJ5.min.js +1 -0
  48. package/dist/c-II2EEAJN.min.js +1 -0
  49. package/dist/c-J6M4JHRS.min.js +1 -0
  50. package/dist/c-JM3MGLQV.min.js +1 -0
  51. package/dist/c-KM3N7F7R.min.js +1 -0
  52. package/dist/c-LF5BZFNC.min.js +1 -0
  53. package/dist/c-LKBSGFQC.min.js +1 -0
  54. package/dist/c-NDJADPIF.min.js +1 -0
  55. package/dist/c-NVPQCIL5.min.js +1 -0
  56. package/dist/c-OFWJBEE5.min.js +1 -0
  57. package/dist/c-OYFHP5F5.min.js +1 -0
  58. package/dist/c-PGKQGGQ2.min.js +1 -0
  59. package/dist/c-Q2IPZ3MU.min.js +1 -0
  60. package/dist/c-QKHMBE2E.min.js +1 -0
  61. package/dist/c-QMVM3AY6.min.js +1 -0
  62. package/dist/c-QSGWX53A.min.js +1 -0
  63. package/dist/c-RJKEKZOO.min.js +1 -0
  64. package/dist/c-SFDIIU5G.min.js +1 -0
  65. package/dist/c-SRTBCRVE.min.js +1 -0
  66. package/dist/c-T6UAIKBH.min.js +1 -0
  67. package/dist/c-TMCTEVVW.min.js +1 -0
  68. package/dist/c-TMOSJLT3.min.js +1 -0
  69. package/dist/c-U6ESPM7V.min.js +1 -0
  70. package/dist/c-UC5PTTFI.min.js +1 -0
  71. package/dist/c-VGKUEZBC.min.js +1 -0
  72. package/dist/c-VN2HG5BS.min.js +1 -0
  73. package/dist/{c-J5G56TUH.min.js → c-VPZDY5Q4.min.js} +1 -1
  74. package/dist/c-VRXUB2F2.min.js +1 -0
  75. package/dist/c-VUBQNQJH.min.js +1 -0
  76. package/dist/c-VUH4PGZY.min.js +1 -0
  77. package/dist/c-XDRV7RKW.min.js +1 -0
  78. package/dist/c-YGZHURXZ.min.js +1 -0
  79. package/dist/components/Annotation.d.ts +1 -1
  80. package/dist/components/access/chartAccessCapabilities.generated.d.ts +14 -0
  81. package/dist/components/access/chartAccessContract.d.ts +90 -0
  82. package/dist/components/access/chartAccessContractFixtures.d.ts +11 -0
  83. package/dist/components/ai/aestheticProfileTypes.d.ts +35 -0
  84. package/dist/components/ai/annotationProvenance.d.ts +2 -7
  85. package/dist/components/ai/auditVisualHierarchy.d.ts +49 -0
  86. package/dist/components/ai/builtInChartRecipeLayouts.d.ts +2 -0
  87. package/dist/components/ai/builtInChartRecipePublic.d.ts +4 -0
  88. package/dist/components/ai/builtInChartRecipes.d.ts +26 -0
  89. package/dist/components/ai/chartCapabilities.d.ts +3 -1
  90. package/dist/components/ai/chartRecipeRegistry.d.ts +2 -1
  91. package/dist/components/ai/chartRecipes.d.ts +6 -0
  92. package/dist/components/ai/colorEvidence.d.ts +12 -0
  93. package/dist/components/ai/evaluateAesthetics.d.ts +47 -0
  94. package/dist/components/ai/geoNavigation.d.ts +4 -0
  95. package/dist/components/ai/hierarchyNavigation.d.ts +4 -0
  96. package/dist/components/ai/navigationTree.d.ts +7 -1
  97. package/dist/components/ai/qualityFixtures.d.ts +8 -0
  98. package/dist/components/ai/suggestionPropContracts.d.ts +1 -1
  99. package/dist/components/ai/useNavigationSync.d.ts +3 -3
  100. package/dist/components/charts/index.d.ts +4 -0
  101. package/dist/components/charts/network/ChordDiagram.d.ts +5 -1
  102. package/dist/components/charts/network/CirclePack.d.ts +8 -1
  103. package/dist/components/charts/network/OrbitDiagram.d.ts +9 -0
  104. package/dist/components/charts/network/TreeDiagram.d.ts +8 -1
  105. package/dist/components/charts/network/Treemap.d.ts +8 -1
  106. package/dist/components/charts/ordinal/BarChart.d.ts +6 -0
  107. package/dist/components/charts/ordinal/BoxPlot.d.ts +3 -0
  108. package/dist/components/charts/ordinal/DonutChart.d.ts +3 -0
  109. package/dist/components/charts/ordinal/DotPlot.d.ts +3 -0
  110. package/dist/components/charts/ordinal/FunnelChart.d.ts +3 -0
  111. package/dist/components/charts/ordinal/GaugeChart.d.ts +3 -0
  112. package/dist/components/charts/ordinal/Histogram.d.ts +3 -0
  113. package/dist/components/charts/ordinal/LikertChart.d.ts +3 -0
  114. package/dist/components/charts/ordinal/PieChart.d.ts +3 -0
  115. package/dist/components/charts/ordinal/RadarChart.capability.d.ts +2 -0
  116. package/dist/components/charts/ordinal/RadarChart.d.ts +75 -0
  117. package/dist/components/charts/ordinal/RidgelinePlot.d.ts +3 -0
  118. package/dist/components/charts/ordinal/SwarmPlot.d.ts +3 -0
  119. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +3 -0
  120. package/dist/components/charts/ordinal/ViolinPlot.d.ts +3 -0
  121. package/dist/components/charts/physics/GauntletChart.d.ts +1 -5
  122. package/dist/components/charts/physics/chainReactionTypes.d.ts +3 -0
  123. package/dist/components/charts/physics/gauntletPhysics.d.ts +1 -0
  124. package/dist/components/charts/physics/physicsHocUtils.d.ts +7 -1
  125. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +10 -1
  126. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +11 -1
  127. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +14 -5
  128. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +7 -1
  129. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +7 -1
  130. package/dist/components/charts/realtime/aggregate.d.ts +12 -1
  131. package/dist/components/charts/realtime/realtimeChartRuntime.d.ts +4 -2
  132. package/dist/components/charts/realtime/realtimeStyleRules.d.ts +4 -0
  133. package/dist/components/charts/shared/annotationStatusFilter.d.ts +18 -0
  134. package/dist/components/charts/shared/chartDefinitionPilot.d.ts +5 -4
  135. package/dist/components/charts/shared/chartSpecCore.d.ts +2 -2
  136. package/dist/components/charts/shared/heatmapStyleRules.d.ts +13 -0
  137. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  138. package/dist/components/charts/shared/networkUtils.d.ts +14 -0
  139. package/dist/components/charts/shared/selectionUtils.d.ts +3 -1
  140. package/dist/components/charts/shared/types.d.ts +4 -2
  141. package/dist/components/charts/shared/useChartLegend.d.ts +2 -1
  142. package/dist/components/charts/shared/useLikertAggregation.d.ts +8 -2
  143. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +9 -5
  144. package/dist/components/charts/shared/useOrdinalPieceStyle.d.ts +1 -1
  145. package/dist/components/charts/shared/useXYBrush.d.ts +24 -0
  146. package/dist/components/charts/xy/Heatmap.d.ts +16 -0
  147. package/dist/components/charts/xy/LineChart.d.ts +9 -0
  148. package/dist/components/charts/xy/Scatterplot.d.ts +7 -0
  149. package/dist/components/charts/xy/WaterfallChart.capability.d.ts +2 -0
  150. package/dist/components/charts/xy/WaterfallChart.d.ts +68 -0
  151. package/dist/components/evidence/chartEvidenceEnvelope.d.ts +146 -0
  152. package/dist/components/evidence/evidenceGate.d.ts +28 -0
  153. package/dist/components/realtime/BinAccumulator.d.ts +5 -1
  154. package/dist/components/realtime/types.d.ts +16 -7
  155. package/dist/components/recipes/adjacencyFlow.d.ts +12 -0
  156. package/dist/components/recipes/adjacencyFlowAggregation.d.ts +72 -0
  157. package/dist/components/recipes/adjacencyFlowGeometry.d.ts +79 -0
  158. package/dist/components/recipes/lineageDag.d.ts +17 -0
  159. package/dist/components/recipes/lineageDagHulls.d.ts +22 -0
  160. package/dist/components/recipes/transitDiagram.d.ts +75 -0
  161. package/dist/components/recipes/transitDiagramGeometry.d.ts +47 -0
  162. package/dist/components/semiotic-access.d.ts +9 -0
  163. package/dist/components/semiotic-ai-audits.d.ts +17 -0
  164. package/dist/components/semiotic-ai-core.d.ts +9 -0
  165. package/dist/components/semiotic-ai.d.ts +5 -17
  166. package/dist/components/semiotic-evidence.d.ts +10 -0
  167. package/dist/components/semiotic-line.d.ts +9 -0
  168. package/dist/components/semiotic-network.d.ts +3 -0
  169. package/dist/components/semiotic-ordinal.d.ts +2 -0
  170. package/dist/components/semiotic-realtime-core.d.ts +3 -2
  171. package/dist/components/semiotic-recipes-core.d.ts +6 -0
  172. package/dist/components/semiotic-themes-core.d.ts +3 -0
  173. package/dist/components/semiotic-utils-core.d.ts +5 -0
  174. package/dist/components/semiotic-utils.d.ts +1 -1
  175. package/dist/components/semiotic-xy.d.ts +3 -0
  176. package/dist/components/semiotic.d.ts +9 -3
  177. package/dist/components/server/renderDashboard.d.ts +37 -0
  178. package/dist/components/server/renderEvidence.d.ts +27 -0
  179. package/dist/components/server/renderToStaticSVG.d.ts +2 -30
  180. package/dist/components/server/serverChartConfigShared.d.ts +13 -0
  181. package/dist/components/server/serverChartConfigs.d.ts +9 -0
  182. package/dist/components/server/serverChartConfigsComposite.d.ts +4 -0
  183. package/dist/components/server/serverChartConfigsCustom.d.ts +2 -0
  184. package/dist/components/server/serverChartConfigsGeo.d.ts +1 -0
  185. package/dist/components/server/serverChartConfigsOrdinal.d.ts +3 -2
  186. package/dist/components/server/serverChartConfigsXY.d.ts +1 -0
  187. package/dist/components/server/serverChartConfigsXYExtra.d.ts +3 -0
  188. package/dist/components/server/serverCompositeChainReaction.d.ts +3 -0
  189. package/dist/components/server/serverOrdinalGauge.d.ts +3 -0
  190. package/dist/components/server/serverOrdinalLikert.d.ts +2 -0
  191. package/dist/components/store/selectionProvenance.d.ts +8 -0
  192. package/dist/components/store/themeCore.d.ts +5 -1
  193. package/dist/components/stream/GeoPipelineStore.d.ts +1 -1
  194. package/dist/components/stream/MarginalGraphics.d.ts +3 -3
  195. package/dist/components/stream/MarginalGraphicsLazy.d.ts +22 -0
  196. package/dist/components/stream/NetworkPipelineStore.d.ts +2 -0
  197. package/dist/components/stream/OrdinalPipelineStore.d.ts +1 -1
  198. package/dist/components/stream/PipelineStore.d.ts +1 -1
  199. package/dist/components/stream/SceneToSVG.d.ts +1 -1
  200. package/dist/components/stream/canvasSetup.d.ts +8 -2
  201. package/dist/components/stream/customLayoutAttempt.d.ts +21 -0
  202. package/dist/components/stream/geoTypes.d.ts +1 -1
  203. package/dist/components/stream/isServerEnvironment.d.ts +6 -0
  204. package/dist/components/stream/layouts/forceLayoutNodeSize.d.ts +12 -0
  205. package/dist/components/stream/layouts/forceLayoutPlugin.d.ts +2 -9
  206. package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +2 -21
  207. package/dist/components/stream/layouts/forceLayoutWorkerPolicy.d.ts +21 -0
  208. package/dist/components/stream/layouts/index.d.ts +6 -12
  209. package/dist/components/stream/layouts/missingPlugin.d.ts +7 -0
  210. package/dist/components/stream/layouts/registerBuiltIn.d.ts +1 -0
  211. package/dist/components/stream/layouts/registry.d.ts +12 -0
  212. package/dist/components/stream/marginalConfig.d.ts +3 -0
  213. package/dist/components/stream/networkCustomLayout.d.ts +7 -0
  214. package/dist/components/stream/networkCustomLayoutOutput.d.ts +13 -0
  215. package/dist/components/stream/networkCustomLayoutRunner.d.ts +1 -1
  216. package/dist/components/stream/networkTypes.d.ts +5 -1
  217. package/dist/components/stream/ordinalTypes.d.ts +1 -1
  218. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +1 -1
  219. package/dist/components/stream/pipelineDomainResolution.d.ts +6 -0
  220. package/dist/components/stream/renderers/pointCanvasRenderer.d.ts +4 -0
  221. package/dist/components/stream/renderers/resolveCSSColor.d.ts +4 -4
  222. package/dist/components/stream/types.d.ts +8 -1
  223. package/dist/components/stream/useEnsureCustomXYRenderers.d.ts +18 -0
  224. package/dist/components/stream/useMarginalValues.d.ts +13 -0
  225. package/dist/components/stream/xyCanvasRenderers.d.ts +4 -4
  226. package/dist/components/stream/xyPlugins/areaPlugin.d.ts +2 -0
  227. package/dist/components/stream/xyPlugins/barPlugin.d.ts +2 -0
  228. package/dist/components/stream/xyPlugins/candlestickPlugin.d.ts +2 -0
  229. package/dist/components/stream/xyPlugins/customPlugin.d.ts +6 -0
  230. package/dist/components/stream/xyPlugins/heatmapPlugin.d.ts +2 -0
  231. package/dist/components/stream/xyPlugins/lineFamily.d.ts +5 -0
  232. package/dist/components/stream/xyPlugins/linePlugin.d.ts +2 -0
  233. package/dist/components/stream/xyPlugins/missingPlugin.d.ts +7 -0
  234. package/dist/components/stream/xyPlugins/mixedPlugin.d.ts +2 -0
  235. package/dist/components/stream/xyPlugins/pointPlugin.d.ts +3 -0
  236. package/dist/components/stream/xyPlugins/registerBuiltIn.d.ts +1 -0
  237. package/dist/components/stream/xyPlugins/registry.d.ts +31 -0
  238. package/dist/components/stream/xyPlugins/stackedAreaPlugin.d.ts +2 -0
  239. package/dist/components/stream/xyPlugins/swarmPlugin.d.ts +2 -0
  240. package/dist/components/stream/xyPlugins/waterfallPlugin.d.ts +2 -0
  241. package/dist/forceLayoutWorker.js +1 -1
  242. package/dist/geo.min.js +1 -1
  243. package/dist/geo.module.min.js +1 -1
  244. package/dist/network.module.min.js +1 -1
  245. package/dist/ordinal.module.min.js +1 -1
  246. package/dist/physics.module.min.js +1 -1
  247. package/dist/rough.module.min.js +1 -1
  248. package/dist/semiotic-access.d.ts +9 -0
  249. package/dist/semiotic-access.min.js +2 -0
  250. package/dist/semiotic-access.module.min.js +2 -0
  251. package/dist/semiotic-ai-core.d.ts +9 -0
  252. package/dist/semiotic-ai-core.min.js +1 -1
  253. package/dist/semiotic-ai-core.module.min.js +1 -1
  254. package/dist/semiotic-ai.d.ts +5 -17
  255. package/dist/semiotic-ai.module.min.js +1 -1
  256. package/dist/semiotic-client-cjs-shared.min.js +1 -1
  257. package/dist/semiotic-client-shared.module.min.js +1 -1
  258. package/dist/semiotic-evidence.d.ts +10 -0
  259. package/dist/semiotic-evidence.min.js +1 -0
  260. package/dist/semiotic-evidence.module.min.js +1 -0
  261. package/dist/semiotic-experimental-auxiliary.module.min.js +1 -1
  262. package/dist/semiotic-experimental-node-auxiliary.module.min.js +1 -1
  263. package/dist/semiotic-experimental-react-shared.module.min.js +1 -1
  264. package/dist/semiotic-experimental-vacp.min.js +1 -1
  265. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  266. package/dist/semiotic-line.d.ts +9 -0
  267. package/dist/semiotic-line.min.js +2 -0
  268. package/dist/semiotic-line.module.min.js +2 -0
  269. package/dist/semiotic-network.d.ts +3 -0
  270. package/dist/semiotic-ordinal.d.ts +2 -0
  271. package/dist/semiotic-realtime-core.d.ts +3 -2
  272. package/dist/semiotic-realtime-core.module.min.js +1 -1
  273. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -1
  274. package/dist/semiotic-recipes-core.d.ts +6 -0
  275. package/dist/semiotic-recipes-core.module.min.js +1 -1
  276. package/dist/semiotic-server-edge-node.module.min.js +1 -1
  277. package/dist/semiotic-server-edge.min.js +1 -1
  278. package/dist/semiotic-server-edge.module.min.js +1 -1
  279. package/dist/semiotic-server-node.min.js +1 -1
  280. package/dist/semiotic-server-node.module.min.js +1 -1
  281. package/dist/semiotic-themes-core.d.ts +3 -0
  282. package/dist/semiotic-themes-core.min.js +1 -1
  283. package/dist/semiotic-themes-core.module.min.js +1 -1
  284. package/dist/semiotic-themes.min.js +1 -1
  285. package/dist/semiotic-themes.module.min.js +1 -1
  286. package/dist/semiotic-utils-core.d.ts +5 -0
  287. package/dist/semiotic-utils-core.min.js +1 -1
  288. package/dist/semiotic-utils-core.module.min.js +1 -1
  289. package/dist/semiotic-utils.d.ts +1 -1
  290. package/dist/semiotic-utils.module.min.js +1 -1
  291. package/dist/semiotic-xy.d.ts +3 -0
  292. package/dist/semiotic.d.ts +9 -3
  293. package/dist/semiotic.module.min.js +1 -1
  294. package/dist/server.min.js +1 -1
  295. package/dist/server.module.min.js +1 -1
  296. package/dist/xy.module.min.js +1 -1
  297. package/package.json +39 -60
  298. package/dist/c-3KZD6AXJ.min.js +0 -1
  299. package/dist/c-4TWEX5HG.min.js +0 -1
  300. package/dist/c-5YCIX3VZ.min.js +0 -1
  301. package/dist/c-6FEKTA3U.min.js +0 -1
  302. package/dist/c-74HEEZGK.min.js +0 -1
  303. package/dist/c-BWNB6USU.min.js +0 -1
  304. package/dist/c-C25ENHIK.min.js +0 -1
  305. package/dist/c-CDR5AO3R.min.js +0 -1
  306. package/dist/c-E3JFRRMI.min.js +0 -1
  307. package/dist/c-EBFPQHHO.min.js +0 -1
  308. package/dist/c-GIKRQI4X.min.js +0 -1
  309. package/dist/c-GPYOFETM.min.js +0 -1
  310. package/dist/c-IDUHYYSI.min.js +0 -1
  311. package/dist/c-JAZ73J32.min.js +0 -1
  312. package/dist/c-KG3NXHAL.min.js +0 -1
  313. package/dist/c-KII3PLZE.min.js +0 -1
  314. package/dist/c-LIXGXMNS.min.js +0 -1
  315. package/dist/c-LVEY6D6B.min.js +0 -1
  316. package/dist/c-M4Y3BHFR.min.js +0 -1
  317. package/dist/c-MAIICR2Z.min.js +0 -1
  318. package/dist/c-MG5DM6VE.min.js +0 -1
  319. package/dist/c-O6U6K4CW.min.js +0 -1
  320. package/dist/c-OQ7M4AGV.min.js +0 -1
  321. package/dist/c-OXYMVK7Q.min.js +0 -1
  322. package/dist/c-QHF5YON3.min.js +0 -1
  323. package/dist/c-RR3GO5SW.min.js +0 -1
  324. package/dist/c-S2BXNNJN.min.js +0 -1
  325. package/dist/c-SUILCHWU.min.js +0 -1
  326. package/dist/c-US5ZFT6E.min.js +0 -1
  327. package/dist/c-UUKVD4WB.min.js +0 -1
  328. package/dist/c-WJCD5EUY.min.js +0 -1
  329. package/dist/c-YDAY2WFR.min.js +0 -1
  330. package/dist/c-ZOWWU34K.min.js +0 -1
  331. /package/dist/{c-COHXCW3Q.min.js → c-YZVRZGX2.min.js} +0 -0
@@ -1 +1 @@
1
- function t(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}var e={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function o(t,o={}){const i=o.mobileSemantics?.interaction,n="number"==typeof i?.targetSize?i.targetSize:"number"==typeof o.mobileSemantics?.minimumHitTarget?o.mobileSemantics.minimumHitTarget:void 0,r="mobile"===o.mode||"number"==typeof o.width&&480>=o.width,s=!!i||void 0!==n,a=t&&"object"==typeof t?t:void 0;if(!1===t||!1===a?.enabled||void 0===t&&!r&&!s)return e;const c=a??{};return{enabled:!0,tapToSelect:c.tapToSelect??!0,tapToLockTooltip:c.tapToLockTooltip??!0,clearSelection:c.clearSelection??"backgroundTap",targetSize:c.targetSize??n??44,snap:c.snap??"nearestDatum",brushHandleSize:c.brushHandleSize??44,standardControls:c.standardControls??!1}}var i={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 n(t,e,o){if(!1!==e)return t;const i={...t};return"horizontal"===o?i.left=Math.min(i.left,15):i.bottom=Math.min(i.bottom,15),i}function r(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var s={kind:"rank-competition"};function a(t,e,o,i){const n=t??e;return"function"==typeof n?n(o,i):o[n+""]}var c=Symbol.for("semiotic.semantic-viability"),l=globalThis,u=l[c]??(l[c]=new Map);function d(t){return"string"==typeof t?.code&&t.code.length>0&&("warning"===t.severity||"error"===t.severity)&&"string"==typeof t.message&&t.message.length>0}function h(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const i=function(t){return function(t){return u.has(t)}(t)?function(t){return u.get(t)}(t):"BumpChart"===t?s:void 0}(e);if(!i)return;let n;try{const e="function"==typeof i?i(o,t):function(t){const e=new Map;(Array.isArray(t.data)?t.data:[]).forEach((o,i)=>{if(!Number.isFinite(Number(a(t.yAccessor,"y",o,i))))return;const n=r(a(t.xAccessor,"x",o,i)),s=e.get(n)??new Set;s.add(a(t.lineBy,"series",o,i)+""),e.set(n,s)});const o=Array.from(e.values(),t=>t.size).sort((t,e)=>t-e);if(0===o.length)return[];const i=Math.floor(o.length/2),n={columns:o.length,median:o.length%2?o[i]:(o[i-1]+o[i])/2,max:o[o.length-1],contestedColumns:o.filter(t=>t>=2).length},s=2>n.max;return s||2>n.contestedColumns||2>n.median?[{code:s?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:s?"error":"warning",message:s?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...n}}]:[]}(o);n=Array.from(e).filter(d)}catch{return void(t.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||t.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}t.semanticDiagnostics=n,t.semanticStatus=n.some(t=>"error"===t.severity)?"degenerate":n.some(t=>"warning"===t.severity)?"degraded":"meaningful";for(const e of n)t.warnings.includes(e.code)||t.warnings.push(e.code)}import*as f from"react-dom/server";import*as p from"react";var y=Object.freeze([]);function g(t){if(!t)return y;let e=!1;for(let o=0;t.length>o;o++){const i=t[o];if(null==i||"object"!=typeof i){e=!0;break}}if(!e)return t;const o=[];for(const e of t)null!=e&&"object"==typeof e&&o.push(e);return o}import{scaleOrdinal as m}from"d3-scale";function x(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function b(t,e,o){const i=t=>t.toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(o)}`}function v(t){const e=t.map(x),o=e.length-1;return t=>{if(0>=t){const[t,o,i]=e[0];return b(t,o,i)}if(t>=1){const[t,i,n]=e[o];return b(t,i,n)}const i=t*o,n=Math.floor(i),r=i-n,[s,a,c]=e[n],[l,u,d]=e[n+1];return b(Math.round(s+(l-s)*r),Math.round(a+(u-a)*r),Math.round(c+(d-c)*r))}}var w=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],k=v(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),S=v(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),A=v(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),M=v(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),_=v(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),P=v(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),L=v(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),$=v(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),R=v(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),C=v(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),I=v(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),T=v(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),O={blues:k,reds:S,greens:A,viridis:L,oranges:M,purples:_,greys:P,plasma:$,inferno:R,magma:C,cividis:I,turbo:T};function z(t){return t&&Object.prototype.hasOwnProperty.call(O,t)?O[t]:k}var F=v(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),N=v(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),E=v(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),D=v(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),B=v(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),W=v(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),j=v(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),Y={category10:w,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...O},X=w,q="#007bff";function G(t,e,o=X){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=Object.values(t).filter(t=>"string"==typeof t&&t.length>0);if(e.length>0)return e}if(Array.isArray(t)&&t.length>0)return t;if("string"==typeof t){const e=Object.prototype.hasOwnProperty.call(Y,t)?Y[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var V=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],H=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],U=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function K(t,e,o){if("function"==typeof e){const i=e(t);return o&&i&&"string"==typeof i&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||U.has(e)}(i)?o(i):i}const i=t?.[e]+"";return o?o(i):X[Math.abs(function(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o),e&=e;return Math.abs(e)}(i))%X.length]}function Z(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const o=t[e];return"string"==typeof o&&o.length>0?o:void 0}function Q(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>Z(t,e)??"#999"}const i=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),n=i.every(t=>!isNaN(Number(t)));if(Array.isArray(o))return m().domain(i).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(Y,o)?Y[o]:Y.category10;if(n&&"function"==typeof r){let t=-1/0;for(const e of i){const o=Number(e);o>t&&(t=o)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:X;return m().domain(i).range(t).unknown("#999")}}function J(t,e,o=[3,20],i){let n;if(n="function"==typeof e?e(t):t?.[e],!i)return n;const[r,s]=i,[a,c]=o;if(s===r)return(a+c)/2;let l=(n-r)/(s-r);return 0>l?l=0:l>1&&(l=1),a+l*(c-a)}function tt(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function et(t,e){if(!tt(e))return t??((...t)=>({}));const o={};return void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...o}):(...t)=>({...o})}function ot(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>rt(e(t))}function it(t,e){const o=ot(t),i=ot(e);return(t,e)=>{const n=i(t);return{value:n,x:o(t),y:n,category:e}}}function nt(t,e){const o=ot(e??"value"),i=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=i?i(t):void 0;return{value:o(t),category:null==e?void 0:e+""}}}function rt(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function st(t,e,o){const i=t.when;return void 0===i||!0===i||!1!==i&&("function"==typeof i?i(e,o):function(t,e,o){const i=null!=t.axis?o[t.axis]:null!=t.field?e[t.field]:o.value;if(void 0!==t.eq&&i!==t.eq)return!1;if(void 0!==t.ne&&i===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(i))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const n=rt(i);if(void 0===n)return!1;if(void 0!==t.gt&&t.gt>=n)return!1;if(void 0!==t.gte&&t.gte>n)return!1;if(void 0!==t.lt&&n>=t.lt)return!1;if(void 0!==t.lte&&n>t.lte)return!1;if(void 0!==t.within){const[e,o]=t.within;if(e>n||n>o)return!1}if(void 0!==t.outside){const[e,o]=t.outside;if(n>=e&&o>=n)return!1}return!0}(i,e,o))}function at(t,e,o){if(!e||0===e.length)return{};let i={};for(const n of e){if(!st(n,t,o))continue;const e="function"==typeof n.style?n.style(t,o):n.style;e&&(i={...i,...e})}return i}function ct(t,e,o,i=t=>t){const n=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=i(t),a={...n(t,r)};return Object.assign(a,at(s,e,o(s,r))),a}:n}function lt(t,e,o,i){if(!t||0===t.length)return i;const n=nt(e,o);return(e,o)=>{const r=e&&e.data||e,s=at(r,t,n(r)),a=i?i(e,o):void 0;return a?{...s,...a}:s}}var ut={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function dt(t,e=ut){if(t)return!0===t?e:"stops"in t?Array.isArray(t.stops)?t:void 0:"colorStops"in t?Array.isArray(t.colorStops)?{stops:t.colorStops.map(({offset:t,color:e})=>({offset:t,color:e}))}:void 0:{stops:[{offset:0,opacity:t.topOpacity??e.stops[0]?.opacity??.8},{offset:1,opacity:t.bottomOpacity??e.stops.at(-1)?.opacity??.05}]}}function ht(t){return t?dt(t):void 0}function ft(t,e,o){return"function"==typeof t?t(o):o[t||e]}function pt(t){return t instanceof Date?t.getTime():Number(t)}function yt(t,e){return L(1===e?.5:t/(e-1))}function gt(t){const e={};return void 0!==t.stroke&&(e.stroke=t.stroke),void 0!==t.strokeWidth&&(e.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(e.opacity=t.opacity),e}function mt(t,e){const o=function(t){if(!t)return;const e="boolean"==typeof t?{}:"string"==typeof t?{method:t}:t;return{type:"trend",method:e.method??"linear",...null!=e.bandwidth&&{bandwidth:e.bandwidth},...null!=e.order&&{order:e.order},...null!=e.color&&{color:e.color},...null!=e.strokeWidth&&{strokeWidth:e.strokeWidth},...null!=e.strokeDasharray&&{strokeDasharray:e.strokeDasharray},...null!=e.label&&{label:e.label}}}(e),i=Array.isArray(t)?t:void 0;return o?[o,...i??[]]:i}var xt=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],bt={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}},vt={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}},wt={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:xt,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 kt(t){if(!t?.colors)return;const e=t.colors;return{primary:e.primary,secondary:e.secondary||e.primary,surface:e.surface||e.background,success:e.success,danger:e.danger,warning:e.warning,error:e.error,info:e.info,text:e.text,textSecondary:e.textSecondary,border:e.border,grid:e.grid}}var St={light:bt,dark:vt,"high-contrast":wt,pastels:{mode:"light",colors:{primary:"#c9a0dc",secondary:"#b8a8c8",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#fdf6f0",surface:"#fff5ee",text:"#4a3728",textSecondary:"#7a644a",grid:"#e8d5c4",border:"#e8d5c4",focus:"#8a5fae",annotation:"#8a5fae",success:"#9ad4a3",danger:"#e8869a",warning:"#f0c888",error:"#c86070",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#fff5ee",text:"#4a3728",borderRadius:"8px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"10px"},"pastels-dark":{mode:"dark",colors:{primary:"#c9a0dc",secondary:"#a899c0",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#1a1525",surface:"#251e35",text:"#e8ddf0",textSecondary:"#a899c0",grid:"#3d3455",border:"#3d3455",focus:"#c9a0dc",annotation:"#c9a0dc",success:"#88d4ab",danger:"#f0a0c0",warning:"#f0c888",error:"#e87690",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#251e35",text:"#e8ddf0",borderRadius:"8px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"10px"},"bi-tool":{mode:"light",colors:{primary:"#2563eb",secondary:"#6b7280",categorical:["#2563eb","#0d9488","#ea580c","#6b7280"],sequential:"blues",background:"#f5f6f8",surface:"#ffffff",text:"#2c3e50",textSecondary:"#64717f",grid:"#d8dce3",border:"#d8dce3",focus:"#2563eb",annotation:"#2563eb",success:"#10b981",danger:"#ef4444",warning:"#f59e0b",error:"#dc2626",info:"#2563eb"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2c3e50",borderRadius:"6px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"8px"},"bi-tool-dark":{mode:"dark",colors:{primary:"#3b82f6",secondary:"#9ca3af",categorical:["#3b82f6","#14b8a6","#f97316","#9ca3af"],sequential:"blues",background:"#111827",surface:"#1f2937",text:"#f3f4f6",textSecondary:"#9ca3af",grid:"#374151",border:"#374151",focus:"#3b82f6",annotation:"#3b82f6",success:"#34d399",danger:"#f87171",warning:"#fbbf24",error:"#ef4444",info:"#60a5fa"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f2937",text:"#f3f4f6",borderRadius:"6px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"8px"},italian:{mode:"light",colors:{primary:"#cc0000",secondary:"#666666",categorical:["#cc0000","#333333","#c8a415","#4682b4"],sequential:"reds",background:"#fafafa",surface:"#ffffff",text:"#1a1a1a",textSecondary:"#666666",grid:"#e0e0e0",border:"#e0e0e0",focus:"#cc0000",annotation:"#cc0000",success:"#556b2f",danger:"#cc0000",warning:"#c8a415",error:"#8b0000",info:"#4682b4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#1a1a1a",borderRadius:"2px",shadow:"0 2px 4px rgba(0, 0, 0, 0.15)"},borderRadius:"2px"},"italian-dark":{mode:"dark",colors:{primary:"#ff3333",secondary:"#aaaaaa",categorical:["#ff3333","#aaaaaa","#d4a843","#6aa4d4"],sequential:"reds",background:"#0a0a0a",surface:"#1a1a1a",text:"#f5f5f5",textSecondary:"#aaaaaa",grid:"#333333",border:"#333333",focus:"#ff3333",annotation:"#ff3333",success:"#7a8b5a",danger:"#ff3333",warning:"#d4a843",error:"#cc0000",info:"#6aa4d4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1a1a1a",text:"#f5f5f5",borderRadius:"2px",shadow:"0 2px 8px rgba(0, 0, 0, 0.5)"},borderRadius:"2px"},tufte:{mode:"light",colors:{primary:"#8b0000",secondary:"#555555",categorical:["#8b4513","#556b2f","#4a5568","#800020"],sequential:"oranges",background:"#fffff8",surface:"#fffff8",text:"#111111",textSecondary:"#555555",grid:"#e0ddd0",border:"#e0ddd0",focus:"#8b0000",annotation:"#8b0000",success:"#556b2f",danger:"#8b0000",warning:"#b88700",error:"#6b0000",info:"#4a5568"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#fffff8",text:"#111111",borderRadius:"2px",shadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},borderRadius:"0px"},"tufte-dark":{mode:"dark",colors:{primary:"#c05050",secondary:"#a09880",categorical:["#c08050","#7a8b5a","#8090a0","#a05060"],sequential:"oranges",background:"#1c1b18",surface:"#262520",text:"#e8e4d8",textSecondary:"#a09880",grid:"#3d3c35",border:"#3d3c35",focus:"#c05050",annotation:"#d06a6a",success:"#7a8b5a",danger:"#c05050",warning:"#c8a060",error:"#a04040",info:"#8090a0"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262520",text:"#e8e4d8",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.4)"},borderRadius:"0px"},journalist:{mode:"light",colors:{primary:"#e45050",secondary:"#666666",categorical:["#3a86c8","#e45050","#d4a843","#888888"],sequential:"blues",background:"#ffffff",surface:"#f8f8f8",text:"#222222",textSecondary:"#666666",grid:"#d4d4d4",border:"#d4d4d4",focus:"#e45050",annotation:"#c63b3b",success:"#2d7a3d",danger:"#c8303a",warning:"#d4a843",error:"#a02028",info:"#3a86c8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:18,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#f8f8f8",text:"#222222",borderRadius:"4px",shadow:"0 2px 6px rgba(0, 0, 0, 0.12)"},borderRadius:"4px"},"journalist-dark":{mode:"dark",colors:{primary:"#ff6b6b",secondary:"#a0a0a0",categorical:["#5a9fd8","#ff6b6b","#e0c060","#aaaaaa"],sequential:"blues",background:"#141414",surface:"#1e1e1e",text:"#ededed",textSecondary:"#a0a0a0",grid:"#383838",border:"#383838",focus:"#ff6b6b",annotation:"#ff6b6b",success:"#6fba78",danger:"#ff6b6b",warning:"#e0c060",error:"#d04040",info:"#5a9fd8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1e1e1e",text:"#ededed",borderRadius:"4px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"4px"},playful:{mode:"light",colors:{primary:"#8b5cf6",secondary:"#7c5a9e",categorical:["#8b5cf6","#ec4899","#06b6d4","#84cc16"],sequential:"viridis",background:"#fdf8ff",surface:"#ffffff",text:"#2d1b4e",textSecondary:"#7c5a9e",grid:"#e8d0f8",border:"#e8d0f8",focus:"#8b5cf6",annotation:"#7a47e8",success:"#10d870",danger:"#ff4b6e",warning:"#ffaa33",error:"#e11d48",info:"#06b6d4"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2d1b4e",borderRadius:"12px",shadow:"0 4px 12px rgba(139, 92, 246, 0.15)"},borderRadius:"12px"},"playful-dark":{mode:"dark",colors:{primary:"#a78bfa",secondary:"#b8a0d8",categorical:["#a78bfa","#f472b6","#22d3ee","#a3e635"],sequential:"viridis",background:"#150a28",surface:"#1f1138",text:"#f0e8ff",textSecondary:"#b8a0d8",grid:"#3a2560",border:"#3a2560",focus:"#a78bfa",annotation:"#a78bfa",success:"#4ade80",danger:"#fb7185",warning:"#fbbf24",error:"#f43f5e",info:"#22d3ee"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f1138",text:"#f0e8ff",borderRadius:"12px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"12px"},carbon:{mode:"light",colors:{primary:"#0f62fe",secondary:"#525252",categorical:["#6929c4","#1192e8","#005d5d","#9f1853"],sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#161616",textSecondary:"#525252",grid:"#e0e0e0",border:"#e0e0e0",focus:"#0f62fe",annotation:"#0f62fe",success:"#24a148",danger:"#da1e28",warning:"#f1c21b",error:"#a2191f",info:"#0043ce"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#161616",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.2)"},borderRadius:"0px"},"carbon-dark":{mode:"dark",colors:{primary:"#4589ff",secondary:"#a8a8a8",categorical:["#a56eff","#33b1ff","#08bdba","#ff7eb6"],sequential:"blues",diverging:"RdBu",background:"#161616",surface:"#262626",text:"#f4f4f4",textSecondary:"#a8a8a8",grid:"#393939",border:"#393939",focus:"#4589ff",annotation:"#4589ff",success:"#42be65",danger:"#fa4d56",warning:"#f1c21b",error:"#da1e28",info:"#4589ff"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262626",text:"#f4f4f4",borderRadius:"2px",shadow:"0 4px 12px rgba(0, 0, 0, 0.5)"},borderRadius:"0px"}};function At(t){if(!t)return bt;if("string"==typeof t){if("light"===t)return bt;if("dark"===t)return vt;if("high-contrast"===t)return wt;return(Object.prototype.hasOwnProperty.call(St,e=t)?St[e]:void 0)||bt}var e;const o="dark"===t.mode?vt:bt;return function(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:xt}}),t.accessibility.highContrast){const t="dark"===e.mode;e={...e,colors:{...e.colors,text:t?"#ffffff":"#000000",textSecondary:t?"#cccccc":"#333333",grid:t?"#666666":"#999999",border:t?"#888888":"#000000"}}}return e}({...o,...t,colors:{...o.colors,...t.colors||{}},typography:{...o.typography,...t.typography||{}},tooltip:{...o.tooltip,...t.tooltip||{}}})}function Mt(t){return{background:t.colors.background,text:t.colors.text,textSecondary:t.colors.textSecondary,grid:t.colors.grid,border:t.colors.border,primary:t.colors.primary,fontFamily:t.typography.fontFamily,titleSize:t.typography.titleSize,labelSize:t.typography.labelSize,tickSize:t.typography.tickSize,categorical:t.colors.categorical,annotation:t.colors.annotation??t.colors.text,legendSize:t.typography.legendSize??t.typography.labelSize,legendFontFamily:t.typography.legendFontFamily??t.typography.fontFamily,legendFontWeight:t.typography.legendFontWeight,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,titleFontFamily:t.typography.titleFontFamily??t.typography.fontFamily,titleFontWeight:t.typography.titleFontWeight??"bold",tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}function _t(t,e,o){const i="function"==typeof e?e(t):t[e??o];if(null==i)return null;if(i instanceof Date)return i.getTime();if("string"==typeof i&&""===i.trim())return null;const n=Number(i);return Number.isFinite(n)?n:null}function Pt(t){let e=1/0,o=-1/0;for(const i of t)e>i&&(e=i),i>o&&(o=i);return[e,o]}function Lt(t,e=-1/0){let o=e;for(const e of t)e>o&&(o=e);return o}function $t(t){return Math.round(100*t)/100}function Rt(t,e=2){const o=[],i=[],n=e+1;for(let e=0;n>e;e++){let r=0;for(const[o,i]of t)null!==i&&(r+=o**e*i);o.push(r);const s=[];for(let o=0;n>o;o++){let i=0;for(const[n,r]of t)null!==r&&(i+=n**(e+o));s.push(i)}i.push(s)}i.push(o);const r=function(t,e){const o=t,i=t.length-1,n=[e];for(let t=0;i>t;t++){let e=t;for(let n=t+1;i>n;n++)Math.abs(o[t][n])>Math.abs(o[t][e])&&(e=n);for(let n=t;i+1>n;n++){const i=o[n][t];o[n][t]=o[n][e],o[n][e]=i}for(let e=t+1;i>e;e++)for(let n=i;n>=t;n--)o[n][e]-=o[n][t]*o[t][e]/o[t][t]}for(let t=i-1;t>=0;t--){let e=0;for(let r=t+1;i>r;r++)e+=o[r][t]*n[r];n[t]=(o[i][t]-e)/o[t][t]}return n}(i,n).map($t);return{points:t.map(([t])=>[$t(t),$t(r.reduce((e,o,i)=>e+o*t**i,0))]),equation:[...r].reverse()}}function Ct(t){const e=t.length;let o=0,i=0,n=0,r=0;for(const[e,s]of t)o+=e,i+=s,n+=e*e,r+=e*s;const s=e*n-o*o;if(1e-12>Math.abs(s))return null;const a=(e*r-o*i)/s,c=(i-a*o)/e;return t=>c+a*t}function It(t,e){const o=t.length,i=t.map(([t,o])=>o-e(t)).reduce((t,e)=>t+e*e,0),n=Math.sqrt(i/Math.max(o-2,1)),r=t.reduce((t,e)=>t+e[0],0)/o,s=t.reduce((t,e)=>t+(e[0]-r)**2,0);return{se:n,meanX:r,ssX:s}}function Tt(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Ot="__forecastSegment",zt="__forecastOpacity";function Ft(t,e,o,i){const n=e.uncertaintyOpacity,r=e.confidenceAccessor;if(!n&&!r)return;const s="object"==typeof n?n:{},a=s.min??.15,c=s.max??1;if(r){const e="function"==typeof r?r:t=>t[r];for(const o of t){const t=e(o);null!=t&&Number.isFinite(t)&&(o[zt]=a+Math.max(0,Math.min(1,t))*(c-a))}return}const l=t.map(t=>{const e=o(t),n=i(t);return null!=e&&null!=n&&Number.isFinite(e)&&Number.isFinite(n)?Math.abs(e-n):NaN}),u=l.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=Pt(u),f=h-d;t.forEach((t,e)=>{const o=l[e];Number.isFinite(o)&&(t[zt]=c-(f>0?(o-d)/f:0)*(c-a))})}function Nt(t,e){return"function"==typeof e?e(t):!!t[e]}var Et="__semiotic_resolvedX",Dt="__semiotic_resolvedY",Bt="__compoundGroup";function Wt(t,e,o){const i=t[e],n=t[o];return null==i||null==n||Number.isNaN(i)||Number.isNaN(n)}function jt(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",i=t.lineBy,n=t.colorBy||i;let r=Array.isArray(t.data)?g(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,o){const i="function"==typeof e,n="function"==typeof o,r=i?Et:e,s=n?Dt:o;return i||n?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return i&&(r[Et]=e(t)),n&&(r[Dt]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,c=s.yKey,l=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d="string"==typeof i||"function"==typeof i?i:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,o,i,n){return(r=i).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,o,i,n){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:c,lowerBounds:l,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=i,y=t.map(t=>{let e="observed";return s&&Nt(t,s)?e="forecast":r&&Nt(t,r)&&(e="training"),{...t,[Ot]:e}}),g=i._groupBy,m=[];if(g){const t=new Map;for(const e of y){const o=e[g]??"__default";t.has(o)||t.set(o,[]),t.get(o).push(e)}const e=[];for(const[,o]of t)for(let t=0;o.length-1>t;t++)o[t][Ot]!==o[t+1][Ot]&&(e.push({...o[t+1],[Ot]:o[t][Ot]}),e.push({...o[t],[Ot]:o[t+1][Ot]}));m.push(...y,...e)}else for(let t=0;y.length>t;t++)m.push(y[t]),y.length-1>t&&y[t][Ot]!==y[t+1][Ot]&&(m.push({...y[t+1],[Ot]:y[t][Ot]}),m.push({...y[t],[Ot]:y[t+1][Ot]}));if(i.trainUnderline){const t=[];for(const e of m)"training"===e[Ot]&&t.push({...e,[Ot]:"training-base"});m.unshift(...t)}const x=[];if(c&&l){const t="string"==typeof c?c:"__envUpper",e="string"==typeof l?l:"__envLower";if("function"==typeof c||"function"==typeof l)for(const o of m)"function"==typeof c&&(o[t]=c(o)),"function"==typeof l&&(o[e]=l(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:p})}if(i.uncertaintyOpacity||i.confidenceAccessor){const t=c?"function"==typeof c?c:t=>t[c]:()=>{},e=l?"function"==typeof l?l:t=>t[l]:()=>{};Ft(m.filter(t=>"forecast"===t[Ot]),i,t,e)}if(a){const t=i.anomalyStyle,e={type:"highlight",filter:t=>Nt(t,a)};t?(e.style=t,e.r=f):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=f):(e.color=h,e.r=f,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(e)}return n&&x.push({type:"anomaly-band",threshold:n.threshold??2,showBand:!1!==n.showBand,fill:n.bandColor||"#6366f1",fillOpacity:n.bandOpacity??.1,anomalyColor:n.anomalyColor||"#ef4444",anomalyRadius:n.anomalyRadius??6,label:n.label}),{processedData:m,annotations:x}}(t,0,0,i,n):function(t,e,o,i,n){const{trainEnd:r,steps:s=10,confidence:a=.95,color:c="#6366f1",bandOpacity:l=.15,label:u}=i;if(null==r)return{processedData:t,annotations:[]};const d=[],h=[];for(const o of t)o[e]>r?h.push({...o,[Ot]:"observed"}):d.push({...o,[Ot]:"training"});const f=d.map(t=>[t[e],t[o]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),p=[],y=[];if(f.length>=3){const n=f.length,r=Ct(f);if(r){const{se:d,meanX:h,ssX:g}=It(f,r),m=Tt(a),x=Lt(t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t))),b=f.length>1?(f[n-1][0]-f[0][0])/(n-1):1;for(let t=1;s>=t;t++){const i=x+t*b,s=r(i),a=d*Math.sqrt(1+1/n+(g>0?(i-h)**2/g:0))*m;y.push({[e]:i,[o]:s,[Ot]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}Ft(y,i,t=>t.__forecastUpper,t=>t.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:c,fillOpacity:l,label:u})}}p.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),n&&p.push({type:"anomaly-band",threshold:n.threshold??2,showBand:!1!==n.showBand,fill:n.bandColor||"#6366f1",fillOpacity:n.bandOpacity??.1,anomalyColor:n.anomalyColor||"#ef4444",anomalyRadius:n.anomalyRadius??6,label:n.label});const g=[];if(g.push(...d),d.length>0&&h.length>0&&g.push({...d[d.length-1],[Ot]:"observed"}),g.push(...h),y.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&g.push({...t,[Ot]:"forecast"}),g.push(...y)}return{processedData:g,annotations:p}}(t,e,o,i,n);var r}(r,a,c,i&&"string"==typeof i&&"object"==typeof t.forecast?{...t.forecast,_groupBy:i}:t.forecast,t.anomaly);if(r=e.processedData,l.push(...e.annotations),u=function(t,e,o){const i=o.upperBounds,n=o.lowerBounds;if(!i&&!n)return;const r="function"==typeof i?i:"string"==typeof i?t=>t[i]:null,s="function"==typeof n?n:"string"==typeof n?t=>t[n]:null;let a=1/0,c=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>c&&(c=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>c&&(c=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>c&&(c=t))}}return Number.isFinite(a)&&Number.isFinite(c)?[a,c]:void 0}(r,c,t.forecast),i&&"string"==typeof i?(r=r.map(t=>({...t,[Bt]:`${t[i]}__${t[Ot]||"observed"}`})),d=Bt):d=Ot,t.baseLineStyle){const e=function(t,e){const o=e.trainDasharray??"8,4",i=e.forecastDasharray??"4,4",n=e.color||"#6366f1",r=e.trainOpacity,s=e.forecastOpacity,a=e.trainStroke,c=e.trainLinecap,l=e.trainUnderline;return e=>{const u=t(e),d=e[Ot];if("training"===d){let t=u.stroke;return"darken"===a?t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const i=Math.round(parseInt(o[1],16)*(1-e)),n=Math.round(parseInt(o[2],16)*(1-e)),r=Math.round(parseInt(o[3],16)*(1-e));return`#${i.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):a&&(t=a),{...u,stroke:t,strokeDasharray:o,...c&&{strokeLinecap:c},...null!=r&&{strokeOpacity:r}}}if("training-base"===d){let t=u.stroke||"#666";return"lighten"===l&&(t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const i=Math.round(parseInt(o[1],16)+(255-parseInt(o[1],16))*e),n=Math.round(parseInt(o[2],16)+(255-parseInt(o[2],16))*e),r=Math.round(parseInt(o[3],16)+(255-parseInt(o[3],16))*e);return`#${i.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(t,.4)),{...u,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[zt],o=null!=t?t:s;return{...u,stroke:n,strokeDasharray:i,...null!=o&&{strokeOpacity:o}}}return u}}(e=>t.baseLineStyle(e),t.forecast);h=t=>e(t)}}else t.anomaly&&l.push(...(f=t.anomaly,[{type:"anomaly-band",threshold:f.threshold??2,showBand:!1!==f.showBand,fill:f.bandColor||"#6366f1",fillOpacity:f.bandOpacity??.1,anomalyColor:f.anomalyColor||"#ef4444",anomalyRadius:f.anomalyRadius??6,label:f.label}]));var f;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,o,i,n){const r=new Map;for(const e of t){const t=n?(e[n]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const n of e)Wt(n,o,i)||t.push(n);return{rows:t,groupKey:n}}if("zero"===e){const t=[];for(const[,e]of r)for(const n of e)Wt(n,o,i)?t.push({...n,[i]:0}):t.push(n);return{rows:t,groupKey:n}}const s=[],a="_gapSegment";for(const[t,e]of r){let n=0,r=[];const c=()=>{if(0===r.length)return;const e="__single"===t?"__seg"+n:`${t}__seg${n}`;for(const t of r)s.push({...t,[a]:e});r=[],n++};for(const t of e)Wt(t,o,i)?c():r.push(t);c()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,c,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let p;if(t.directLabel){const e=function(t,e,o,i,n,r,s,a){if(!e||!o)return{annotations:[]};const c="object"==typeof e?e:{},l=c.position||"end",u=c.fontSize||11,d="function"==typeof o?o:t=>t[o],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const o=t+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(e))}const f=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[i])-Number(e[i])),f.set(t,"end"===l?e[e.length-1]:e[0]);const p=Q(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),y=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[i]:e[i],[n]:e[n],dx:"end"===l?6:-6,dy:0,color:p?K({__lbl:t},"__lbl",p):a||q,fontSize:u}));y.sort((t,e)=>Number(t[n])-Number(e[n]));for(let t=1;y.length>t;t++){const e=y[t-1],o=y[t],i=Number(e[n])+e.dy;u+2>Math.abs(Number(o[n])+o.dy-i)&&(o.dy+=u+2)}const g=y.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:y,marginExtra:"end"===l?{right:g}:{left:g}}}(r,t.directLabel,"string"==typeof n||"function"==typeof n?n:void 0,a,c,t.colorScheme,t.themeCategorical,t.color);l.push(...e.annotations),p=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?c:o,groupAccessor:d,colorAccessor:n,annotations:l,lineStyle:h,yExtent:u,marginExtra:p}}function Yt(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=At(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrScatterColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[3,15],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?Pt(f):void 0,y=it(n.xAccessor,n.yAccessor),g=n.styleRules;return t=>{const o={fill:e&&u?K(t,e,u):"string"==typeof n.color?n.color:q,fillOpacity:"number"==typeof n.pointOpacity?n.pointOpacity:.8,r:d?J(t,d,h,p):"number"==typeof n.pointRadius?n.pointRadius:5};return g?.length&&Object.assign(o,at(t,g,y(t))),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}var Xt={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=jt({data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:i.annotations,themeCategorical:At(i.theme).colors.categorical}),s=mt(r.annotations,n.regression);return{chartType:"scatter",data:r.data,xAccessor:r.xAccessor,yAccessor:r.yAccessor,colorAccessor:e,sizeAccessor:n.sizeBy,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:o,...i,...s&&s.length>0&&{annotations:s},...r.yExtent&&!i.yExtent&&{yExtent:r.yExtent},sizeRange:n.sizeRange||[3,15],pointStyle:i.pointStyle||Yt(t,e,o,i,n),showLegend:i.showLegend??!!e}}},qt={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=mt(i.annotations,n.regression);return{chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[5,40],colorScheme:o,...i,...r&&{annotations:r},pointStyle:i.pointStyle||Gt(t,e,o,i,n),showLegend:i.showLegend??!!e}}};function Gt(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=At(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrBubbleColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[5,40],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?Pt(f):void 0,y=it(n.xAccessor,n.yAccessor),g=n.styleRules;return t=>{const o={fill:e&&u?K(t,e,u):"string"==typeof n.color?n.color:q,fillOpacity:"number"==typeof n.bubbleOpacity?n.bubbleOpacity:.6,r:d?J(t,d,h,p):h[0],stroke:n.bubbleStrokeColor??"white",strokeWidth:n.bubbleStrokeWidth??1};return g?.length&&Object.assign(o,at(t,g,y(t))),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}import{useMemo as Vt,useCallback as Ht,useState as Ut,useId as Kt,useEffect as Zt,useRef as Qt}from"react";function Jt(...t){let e;for(const o of t)o&&(e=te(e)&&te(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function te(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function ee(t){return"object"==typeof t&&null!==t&&"gradient"in t}function oe(t){return"string"==typeof t&&t.length>0}function ie(t,e,o=!1){const i=o?e?58:34:e?36:0;return i>t.top?{...t,top:i}:t}function ne(t,e){return ie(t,oe(e))}function re(t,e,o,i,n=8){const r=i,s="left"===i?"right":"right"===i?"left":"top"===i?"bottom":"top",a=Math.max(e[r],Math.max(0,("left"===i||"right"===i?o[0]:o[1])-n)-t[s]);t[r]>a&&(t[r]=a)}function se(t){return Math.ceil(7*t.length)}function ae(t,e){if(te(t)){const o=xe(e),i=t.legendGroups.flatMap(t=>[t.label?se(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+se(t.label))]);return Math.max(100,...i)}if(ee(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),i=Math.max(se(o(e.domain[0])),se(o(e.domain[1]))),n=e.label?se(e.label):0;return Math.max(100,19+i,n)}return 100}function ce(t){return(te(t)||ee(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function le(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?he:de:0}function ue(t){return Math.max(0,t?.edgeGutter??3)}var de=34,he=70;function fe(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function pe(t,e,o){if(ee(t))return t.gradient.label?46:26;if(!te(t))return 20;const i=xe(o),n=Math.max(1,o?.maxWidth??e);let r=i.rowHeight;for(const e of t.legendGroups){let t=0,o=0;for(const r of e.items){const e=i.swatchSize+i.labelGap+se(r.label),s=0===o?e:o+i.itemGap+e;o>0&&s>n?(t+=1,o=e):o=s}e.items.length>0&&(t+=1),r=Math.max(r,t*i.rowHeight,e.label?se(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function ye(t,e,o){return ae(t,e)+ce(t)+le(e,o)+ue(e)}function ge(t,e){const{legend:o}=e;if(!o)return;const i=e.position??"right",n=pe(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+ce(o)+fe("bottom"===i?e.axisChrome:"top"===i?e.axisChrome?.topAxis:void 0,e.legendLayout)+("top"===i&&e.hasTitle?24:0),r=Math.max(e.minimumMargin??0,"top"===i?e.hasTitle?58:34:0);"right"===i?t.right=Math.max(t.right,r,ye(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===i?t.left=Math.max(t.left,r,ye(o,e.legendLayout,e.axisChrome?.leftAxis)):"top"===i?t.top=Math.max(t.top,r,n):t.bottom=Math.max(t.bottom,r,n)}function me(t,e){const o=e.position??"right",i="top"===o||"bottom"===o,n=Math.max(0,e.totalWidth-e.margin.left-e.margin.right),r=Math.max(1,i?e.legendLayout?.maxWidth??n:e.reservedWidth??ae(t,e.legendLayout)),s=ce(t),a=le(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),c=ue(e.legendLayout),l=pe(t,n,e.legendLayout),u=fe(e.axisChrome,e.legendLayout),d=fe(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(c,e.margin.left-a-r-s),y:e.margin.top,width:r,height:l};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-l,width:r,height:l};if("bottom"===o){const t=e.totalHeight-e.margin.bottom;return{x:e.margin.left,y:Math.max(t+s,Math.min(t+u+s,e.totalHeight-l)),width:r,height:l}}return{x:Math.min(e.totalWidth-r-c,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:l}}function xe(t){const e=Math.max(1,t?.swatchSize??16),o=Math.max(e,t?.rowHeight??22);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??6),itemGap:Math.max(0,t?.itemGap??10),rowHeight:o,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function be(t,e){let o=24;return t.map(({hasLabel:t,itemCount:i})=>{o+=5;const n=o;let r;o+=8,t&&(o+=16,r=o,o+=8);const s=o;return o+=i*e+8,{lineY:n,labelY:r,itemsY:s,endY:o}})}function ve(t,e,o,i,n){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=Z(o,i);if(t)return t}let r;if(Array.isArray(o))r=o;else if(e&&e.length>0)r=e;else if("string"==typeof o){const t=Y[o];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=i?(n.has(i)||n.set(i,n.size),r[n.get(i)%r.length]):r[0]:q}function we(t,e,o){return"function"==typeof t?t(e,o):e[t]}function ke(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[r(t),e]));return t.map(t=>{const e={...t},i=i=>{if(!(i in t))return;const n=o.get(r(t[i]));void 0!==n&&(e[i]=n)};return i("x"),i("x0"),i("x1"),"string"!=typeof t.type||"x-threshold"!==t.type&&"x"!==t.type||i("value"),e})}import*as Se from"react";import{jsx as Ae}from"react/jsx-runtime";var Me,_e={isActive:!1,predicate:()=>!0};function Pe(t,e,o,i,n){const r=1-n;return r*r*r*t+3*r*r*n*e+3*r*n*n*o+n*n*n*i}function Le(t,e,o,i,n){const r=1-n;return 3*r*r*(e-t)+6*r*n*(o-e)+3*n*n*(i-o)}function $e(t,e,o,i,n){const r=[],s=(t.x+e.x)/2;for(let a=0;n>=a;a++){const c=a/n;let l,u,d,h;"linear"===i?(l=t.x+(e.x-t.x)*c,u=t.y+(e.y-t.y)*c,d=e.x-t.x,h=e.y-t.y):(l=Pe(t.x,s,s,e.x,c),u=Pe(t.y,t.y,e.y,e.y,c),d=Le(t.x,s,s,e.x,c),h=Le(t.y,t.y,e.y,e.y,c)),r.push({x:l,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*c,datumIndex:.5>c?o:o+1})}return r}function Re(t,e={}){const o=[],i=[],n=[];if(2>t.length)return{topPath:o,bottomPath:i,datumIndices:n};const r=e.curve??"smooth",s=Math.max(2,Math.floor(e.samplesPerSegment??12));for(let e=0;t.length-1>e;e++){const a=$e(t[e],t[e+1],e,r,s);for(let t=0===e?0:1;a.length>t;t++){const e=a[t],r=Math.hypot(e.dx,e.dy)||1,s=-e.dy/r,c=e.dx/r,l=Math.max(0,e.radius);o.push([e.x+s*l,e.y+c*l]),i.push([e.x-s*l,e.y-c*l]),n.push(e.datumIndex)}}return{topPath:o,bottomPath:i,datumIndices:n}}import{jsx as Ce}from"react/jsx-runtime";function Ie({datum:t,x:e,y:o,side:i,color:n,highlighted:r,labelStyle:s}){const a=function(){const t=(Me??(Me=Se.createContext(null)),Me);return Se.useContext(t)??_e}(),c=a.isActive&&!a.predicate(t),l="function"==typeof s?s(t.__bumpRaw):s;return Ce("text",{className:"semiotic-bump-label",x:e+("end"===i?8:-8),y:o,dy:"0.35em",textAnchor:"end"===i?"start":"end",fill:n,fillOpacity:c?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...l},children:t.__bumpSeries})}function Te(t,e,o){const[i,n]=e,[r,s]=o;return n===i?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(t-i)/(n-i)))}function Oe(t){const e=t.__bumpXValue instanceof Date?t.__bumpXValue.getTime():Number(t.__bumpXValue);return{value:t.__bumpValue,x:Number.isFinite(e)?e:void 0,y:t.__bumpValue,category:t.__bumpSeries}}function ze(t){const e=t.config,o=new Map;for(const e of t.data){const t=o.get(e.__bumpSeries)??[];t.push(e),o.set(e.__bumpSeries,t)}const i=e.seriesOrder.filter(t=>o.has(t)).sort((t,i)=>(o.get(t)?.[0]?.__bumpHighlighted?1:0)-(o.get(i)?.[0]?.__bumpHighlighted?1:0)||e.seriesOrder.indexOf(t)-e.seriesOrder.indexOf(i)),n=[],r=[],s=[];for(const r of i){const i=(o.get(r)??[]).sort((t,e)=>t.x-e.x);if(2>i.length)continue;const a=i[0].__bumpHighlighted,c=(e.colorMap&&Z(e.colorMap,r))??t.resolveColor(i[0].__bumpSeries,i[0]),l=e.color??(a?c:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??c),u=i.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?Te(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=Re(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:l,fillOpacity:1,opacity:a?e.ribbon?e.ribbonOpacity:e.lineOpacity:Math.min(e.ribbon?e.ribbonOpacity:e.lineOpacity,.58)};e.styleRules?.length&&Object.assign(h,at(i[0].__bumpRaw,e.styleRules,Oe(i[0]))),e.areaStyle&&Object.assign(h,e.areaStyle(i[0].__bumpRaw)??{}),void 0!==e.stroke&&(h.stroke=e.stroke),void 0!==e.strokeWidth&&(h.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(h.opacity=e.opacity),n.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:h,datum:d.datumIndices.map(t=>i[t]),accessibleDatum:i.map(t=>t.__bumpRaw),accessibility:{label:r+" ranking trajectory",tableFields:i.map(t=>t.__bumpRaw)},group:r,interactive:!0}),e.showPoints&&i.forEach((t,o)=>{const i={fill:l,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(i,at(t.__bumpRaw,e.styleRules,Oe(t))),e.pointStyle&&Object.assign(i,e.pointStyle(t.__bumpRaw)??{}),void 0!==e.stroke&&(i.stroke=e.stroke),void 0!==e.strokeWidth&&(i.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(i.opacity=e.opacity),n.push({type:"point",x:u[o].x,y:u[o].y,r:i.r??e.pointRadius,style:i,datum:t,accessibleDatum:t.__bumpRaw,accessibility:{label:`${r}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${r}:${t.x}`})});const f=!0===e.showLabels?"end":e.showLabels,p=(t,o,i)=>{const n=null==e.labelPriorityAccessor?void 0:"function"==typeof e.labelPriorityAccessor?e.labelPriorityAccessor(t.__bumpRaw):Number(t.__bumpRaw[e.labelPriorityAccessor]);s.push({id:`${r}\0${i}`,datum:t,x:u[o].x,y:u[o].y,side:i,rank:t.__bumpRank,highlighted:a,priority:Number.isFinite(n)?n:void 0,color:"string"==typeof h.fill?h.fill:l})};"start"!==f&&"both"!==f||p(i[0],0,"start"),"end"!==f&&"both"!==f&&"auto"!==f||p(i.at(-1),i.length-1,"end")}const a=function(t,e,o,i){const n=Math.max(1,Math.floor(e/18)),r="auto"===o?Number.isFinite(i)&&(i??0)>=0?Math.min(n,Math.floor(i)):n:1/0,s=t.map((t,e)=>({candidate:t,index:e})).sort((t,e)=>(e.candidate.priority??0)-(t.candidate.priority??0)||Number(e.candidate.highlighted)-Number(t.candidate.highlighted)||t.candidate.rank-e.candidate.rank||t.index-e.index),a=[];for(const{candidate:t}of s){if(a.length>=r)break;a.some(e=>e.side===t.side&&14>Math.abs(e.y-t.y))||a.push(t)}return new Set(a.map(t=>t.id))}(s,t.dimensions.plot.height,"auto"!==(!0===e.showLabels?"end":e.showLabels)||"auto",e.maxLabels);for(const t of s)a.has(t.id)&&r.push(Ce(Ie,{datum:t.datum,x:t.x,y:t.y,side:t.side,color:t.color,highlighted:t.highlighted,labelStyle:e.labelStyle},t.id));return{nodes:n,overlays:r.length?Ce("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(t,e)=>{const o=function(t){const e=Array.isArray(t.datum)?t.datum[0]:t.datum;return e&&"object"==typeof e&&"__bumpSeries"in e?e:void 0}(t);if(e?.isActive&&o&&!e.predicate(o))return{opacity:.14}}}}var Fe={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,i,n)=>{const s=function(t,e={}){const o=e.xAccessor??"x",i=e.yAccessor??"y",n=e.lineBy??"series",s=e.rankDirection??"descending",a=[],c=new Map,l=new Map,u=[],d=new Map;let h=1/0,f=-1/0;t.forEach((t,e)=>{const s=we(o,t,e),p=r(s);let y=c.get(p);null==y&&(y=a.length,c.set(p,y),a.push(s),l.set(y,[]));const g=we(n,t,e)+"";d.has(g)||(d.set(g,u.length),u.push(g));const m=Number(we(i,t,e));Number.isFinite(m)&&(h=Math.min(h,m),f=Math.max(f,m),l.get(y)?.push({datum:t,inputIndex:e,series:g,value:m}))});const p=[],y=new Map,g=new Map;for(let t=0;a.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===s?e.value-t.value:t.value-e.value)||(d.get(t.series)??0)-(d.get(e.series)??0)),e.forEach((e,o)=>{const i=o+1;p.push({datum:e.datum,xIndex:t,xValue:a[t],series:e.series,value:e.value,rank:i}),y.set(e.series,(y.get(e.series)??0)+i),g.set(e.series,(g.get(e.series)??0)+1)})}const m=u.length+1,x=[...u].sort((t,e)=>{const o=g.get(t)??0,i=g.get(e)??0;return((y.get(t)??0)+(a.length-o)*m)/Math.max(1,a.length)-((y.get(e)??0)+(a.length-i)*m)/Math.max(1,a.length)||(d.get(t)??0)-(d.get(e)??0)}),b=new Set(x.slice(0,null==e.highlightTop?x.length:Math.max(0,Math.floor(e.highlightTop))));return{data:p.map(t=>{const e=b.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:a,seriesOrder:u,overallOrder:x,valueExtent:h===1/0?[0,0]:[h,f]}}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],{xAccessor:n.xAccessor,yAccessor:n.yAccessor,lineBy:n.lineBy,rankDirection:n.rankDirection,highlightTop:"number"==typeof n.highlightTop?n.highlightTop:void 0}),a=Math.max(1,s.seriesOrder.length),c=At(i.theme),l=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:i,color:n,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:c}=t;if(null==i&&null==n)return r;const l=new Set(o.slice(0,null==i?o.length:Math.max(0,Math.floor(i)))),u=new Map,d={};for(const t of e)Object.defineProperty(d,t,{configurable:!0,enumerable:!0,writable:!0,value:n??(l.has(t)?ve(void 0,a,r,t,u):s??c??"#b8bec8")});return d}({seriesOrder:s.seriesOrder,overallOrder:s.overallOrder,highlightTop:"number"==typeof n.highlightTop?n.highlightTop:void 0,color:"string"==typeof n.color?n.color:void 0,colorScheme:o,neutralColor:"string"==typeof n.neutralColor?n.neutralColor:void 0,themeCategorical:c.colors.categorical,themeNeutral:c.colors.textSecondary}),u={ribbon:!0===n.ribbon,curve:"linear"===n.curve?"linear":"smooth",samplesPerSegment:"number"==typeof n.samplesPerSegment?n.samplesPerSegment:12,ribbonSizeRange:Array.isArray(n.ribbonSizeRange)?n.ribbonSizeRange:[4,28],valueExtent:s.valueExtent,seriesOrder:s.seriesOrder,lineWidth:"number"==typeof n.lineWidth?n.lineWidth:3,ribbonOpacity:"number"==typeof n.ribbonOpacity?n.ribbonOpacity:.82,lineOpacity:"number"==typeof n.lineOpacity?n.lineOpacity:.9,neutralColor:"string"==typeof n.neutralColor?n.neutralColor:void 0,color:"string"==typeof n.color?n.color:void 0,colorMap:l&&"object"==typeof l&&!Array.isArray(l)?l:void 0,stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0,styleRules:n.styleRules,areaStyle:i.areaStyle,pointStyle:i.pointStyle,labelStyle:n.labelStyle,showPoints:!0===n.showPoints,pointRadius:"number"==typeof n.pointRadius?n.pointRadius:3,showLabels:n.showLabels??!0,labelPriorityAccessor:n.labelPriorityAccessor,maxLabels:"number"==typeof n.maxLabels?n.maxLabels:void 0},d=i.xFormat,h=(t,e)=>{if(0===s.xValues.length)return"";const o=s.xValues[Math.max(0,Math.min(s.xValues.length-1,Math.round(Number(t))))];return d?d(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},f=s.xValues.map((t,e)=>e),p=Array.from({length:a},(t,e)=>e+1),y=i.axes??[{orient:"left",tickValues:p,tickFormat:t=>t+"",label:i.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:f,tickFormat:h,label:i.xLabel,tickAnchor:"edges"}];return{...i,chartType:"custom",data:s.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,s.xValues.length-1)],yExtent:[a+.5,.5],customLayout:ze,layoutConfig:u,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:h,axes:y,axisExtent:"exact",showAxes:i.showAxes??!0,showLegend:i.showLegend??!1,annotations:ke(i.annotations,s.xValues)}}};function Ne(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=At(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrAreaColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=!1!==n.showLine,h="number"==typeof n.lineWidth?n.lineWidth:2,f="number"==typeof n.areaOpacity?n.areaOpacity:.7,p=ot(n.yAccessor),y=n.styleRules;return(t,o)=>{const i=e&&u?K(t,e,u):"string"==typeof n.color?n.color:q,r={fill:i,fillOpacity:f,stroke:d?i:"none",...d&&{strokeWidth:h}};return y?.length&&Object.assign(r,at(t,y,{value:p(t),category:o})),void 0!==n.stroke&&(r.stroke=n.stroke),void 0!==n.strokeWidth&&(r.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(r.opacity=n.opacity),r}}function Ee(t,e,o,i,n){if(!n.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=At(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrPointColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d="number"==typeof n.pointRadius?n.pointRadius:3;return t=>{const o=e&&u?K(t,e,u):"string"==typeof n.color?n.color:q;return{r:d,fill:o,stroke:"none"}}}var De={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=e||n.lineBy,s=n.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",c=At(i.theme).colors.categorical,l=function(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=At(i.theme).colors.categorical,a=o??i.colorScheme??s,c="string"==typeof e?e:"__ssrLineColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=it(n.xAccessor,n.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:i,color:n,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:c,ruleContext:l}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let f;return r?f=r(t,u):o?i&&(f=K(t,o,i)):f=n||q,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),c?.length&&Object.assign(d,at(t,c,l?l(t,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,colorBy:e,colorScale:u,color:"string"==typeof n.color?n.color:void 0,fillArea:n.fillArea,areaOpacity:"number"==typeof n.areaOpacity?n.areaOpacity:.3,styleRules:n.styleRules,ruleContext:d});return et(h,{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0})}(t,r,o,i,n),u=jt({data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof n.color?n.color:void 0,forecast:n.forecast,anomaly:n.anomaly,gapStrategy:n.gapStrategy,directLabel:n.directLabel,annotations:i.annotations,themeCategorical:c,baseLineStyle:l}),d=i.pointStyle||Ee(u.data,u.colorAccessor,o,i,n);let h=i.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const f=(!n.directLabel||void 0!==i.showLegend)&&(i.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||l,...Array.isArray(s)&&{areaGroups:s},...s&&null!=n.areaOpacity&&{areaOpacity:n.areaOpacity},...null!=n.band&&{band:n.band},...i,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!i.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},Be={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=Array.isArray(t)?g(t):[],s=n.timeAccessor||"time",a=n.valueAccessor||"value",c=n.categoryAccessor,l=n.valueExtent||i.yExtent,u="down"===n.direction?function({data:t,valueAccessor:e,timeAccessor:o,binSize:i,valueExtent:n,extentPadding:r}){if(n)return[n[1],n[0]];if(!t||0===t.length)return;const s=new Map;for(const n of t){const t=_t(n,o,"time"),r=_t(n,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/i)*i;s.set(a,(s.get(a)??0)+r)}let a=0;for(const t of s.values())a=Math.max(a,t);return[a>0?a+a*(r??.1):1,0]}({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(n.binSize),valueExtent:l,extentPadding:n.extentPadding}):l,d={...void 0!==n.fill&&{fill:n.fill},...void 0!==n.stroke&&{stroke:n.stroke},...void 0!==n.strokeWidth&&{strokeWidth:n.strokeWidth},...void 0!==n.opacity&&{opacity:n.opacity},...void 0!==n.cursor&&{cursor:n.cursor},...void 0!==n.gap&&{gap:n.gap}};return{chartType:"bar",data:r,...i,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:n.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:n.timeExtent||i.xExtent,yExtent:u,extentPadding:n.extentPadding??i.extentPadding,binSize:n.binSize,categoryAccessor:c,barColors:n.colors||i.barColors,colorScheme:n.colors||i.colorScheme,barStyle:i.barStyle||d,showLegend:i.showLegend??!!c}}},We={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=e||n.areaBy,s=jt({data:Array.isArray(t)?g(t):[],xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.areaBy,forecast:n.forecast,anomaly:n.anomaly,annotations:i.annotations,themeCategorical:At(i.theme).colors.categorical}),a=function({data:t,safeData:e,areaBy:o,lineDataAccessor:i}){if(null==t)return[];const n=void 0!==e[0]?.[i];if(!n&&!o)return e;let r;if(n)r=e;else{const t=e.reduce((t,e)=>{const n="function"==typeof o?o(e):e[o],r=n+"";if(!t[r]){const e={[i]:[]};"string"==typeof o&&(e[o]=n),t[r]=e}return t[r][i].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[i])?t[i]:[];return"string"==typeof o?e.map(e=>({...e,[o]:e[o]??t[o]})):e})}({data:t,safeData:s.data,areaBy:n.areaBy,lineDataAccessor:n.lineDataAccessor||"coordinates"}),c=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:o})=>({offset:t/100,color:e,...null!=o&&{opacity:o}}))}:Array.isArray(t.stops)?t:void 0}(n.semanticGradient),l=c?.stops.length?{stops:c.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:dt(i.gradientFill),u=!1!==n.semanticLine?function(t){const e=t?.stops.filter(t=>"string"==typeof t.color&&Number.isFinite(t.offset)).map(({offset:t,color:e,opacity:o})=>({offset:Math.max(0,Math.min(1,t)),color:e,...Number.isFinite(o)&&{opacity:Math.max(0,Math.min(1,o))}})).sort((t,e)=>t.offset-e.offset);if(!e?.length)return;const o=e[0];return o.offset>0?[{...o,offset:0},...e]:e}(c):void 0,d=i.pointStyle||Ee(a,r,o,i,n);return{chartType:"area",data:a,xAccessor:s.xAccessor,yAccessor:s.yAccessor,y0Accessor:n.y0Accessor,groupAccessor:n.areaBy||void 0,colorAccessor:r,colorScheme:o,...i,...s.annotations.length>0&&{annotations:s.annotations},...s.yExtent&&!i.yExtent&&{yExtent:s.yExtent},...void 0!==l&&{gradientFill:l},...u&&{semanticLineStops:u},lineStyle:i.lineStyle||Ne(a,r,o,i,n),...d&&{pointStyle:d}}}},je={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=n.xAccessor||"x",s=n.seriesAAccessor||"a",a=n.seriesBAccessor||"b",c=t=>pt(ft(r,"x",t)),l=t=>pt(ft(s,"a",t)),u=t=>pt(ft(a,"b",t)),d=n.seriesAColor||"var(--semiotic-danger, #dc2626)",h=n.seriesBColor||"var(--semiotic-info, #2563eb)",f=n.areaOpacity??.6,p=n.lineWidth??1.5,y=!1!==n.showLines,g=!1!==i.showLegend,m=n.seriesALabel||"A",x=n.seriesBLabel||"B",b=i.legendPosition||"right",v=function(t,e,o,i){if(!t.length)return[];const n=t.filter(t=>Number.isFinite(e(t))).sort((t,o)=>e(t)-e(o)),r=[];let s=0,a=null,c=null,l=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),f=(t,e)=>{h({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:d(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;n.length>t;t++){const r=n[t],p=e(r),y=o(r),g=i(r);if(!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g))continue;const m=u(y,g);if(null!==m)if(null!=a){if(c&&c.w!==m){let t,e;if(l.length>0)t=l[0].x,e=l[0].y;else{const o=y-c.a-(g-c.b);if(0!==o){const i=Math.max(0,Math.min(1,(c.b-c.a)/o));t=c.x+i*(p-c.x),e=c.a+i*(y-c.a)}else t=c.x,e=c.a}h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;l.length>t;t++)f(l[t],a)}else for(const t of l)f(t,a);l=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else{a=m;for(const t of l)f(t,a);l=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else l.push({x:p,y:y,datum:r})}for(const t of l)f(t,a??"A");return r}(Array.isArray(t)?t:[],c,l,u),w=[];if(y&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(c(t))).sort((t,e)=>c(t)-c(e));for(const t of e){const e=c(t),o=l(t),i=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(i)&&w.push({__x:e,__y:i,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:f}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:p,fill:"none"}),curve:n.curve||"linear",...i,...g&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},Ye={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=e||n.areaBy,s="string"==typeof r&&Array.isArray(t)?Q(t,r,o):void 0,a="number"==typeof n.areaOpacity?n.areaOpacity:.7,c=i.lineStyle||(t=>{const e=null==r?void 0:K(t,r,s),o=n.showLine??!0,i={fill:n.color??e,stroke:o?n.stroke??e:"none",...o?{strokeWidth:n.strokeWidth??n.lineWidth??2}:{},fillOpacity:a,...null==n.opacity?{}:{opacity:n.opacity}},c=n.styleRules;if(c?.length){const e=ot(n.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(i,at(t,c,{value:e(t),category:o}))}return i}),l=n.normalize?"zero":n.baseline??"zero",u=i.pointStyle||Ee(t,r,o,i,n);return{chartType:"stackedarea",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.areaBy,colorAccessor:r,colorScheme:o,normalize:n.normalize,baseline:l,stackOrder:n.stackOrder,lineStyle:c,...i,...u&&{pointStyle:u},curve:i.curve??n.curve??"monotoneX",showLegend:i.showLegend??!!r}}},Xe={frameType:"xy",buildProps:(t,e,o,i,n)=>{const[r]=i.size??[600,400];return{chartType:"candlestick",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.highAccessor||"high",highAccessor:n.highAccessor||"high",lowAccessor:n.lowAccessor||"low",openAccessor:n.openAccessor,closeAccessor:n.closeAccessor,candlestickStyle:n.candlestickStyle,...i,scalePadding:i.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:i.extentPadding??(r>200?.1:.02)}}},qe={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=n.xCenter,s=n.yCenter,a=n.quadrants,c=n.centerlineStyle||{},l=!1!==n.showQuadrantLabels,u=n.quadrantLabelSize??12,d=c.stroke||"#999",h=c.strokeWidth??1,f=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,y=p.createElement,g=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const i=o.width,n=o.height,c=null!=r?e.x(r):i/2,g=null!=s?e.y(s):n/2;if(null!=r&&!Number.isFinite(c))return null;if(null!=s&&!Number.isFinite(g))return null;const m=Math.max(0,Math.min(i,c)),x=Math.max(0,Math.min(n,g)),b=[{c:a.topLeft,x:0,y:0,w:m,h:x},{c:a.topRight,x:m,y:0,w:i-m,h:x},{c:a.bottomLeft,x:0,y:x,w:m,h:n-x},{c:a.bottomRight,x:m,y:x,w:i-m,h:n-x}],v=l?[y("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),y("text",{key:"ltr",x:i-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),y("text",{key:"lbl",x:8,y:n-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),y("text",{key:"lbr",x:i-8,y:n-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return y(p.Fragment,null,...b.map((t,e)=>t.w>0&&t.h>0?y("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),y("line",{key:"vc",x1:m,y1:0,x2:m,y2:n,stroke:d,strokeWidth:h,strokeDasharray:f}),y("line",{key:"hc",x1:0,y1:x,x2:i,y2:x,stroke:d,strokeWidth:h,strokeDasharray:f}),...v)}]:void 0;return{chartType:"scatter",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[3,15],colorScheme:o,pointStyle:i.pointStyle||n.pointStyle||Yt(t,e,o,i,n),...i,showLegend:i.showLegend??!!e,...g&&{svgPreRenderers:g}}}},Ge={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const o=e.xAccessor||"x",i=e.yAccessor||"y",n=e.orderAccessor?[...t].sort((t,o)=>null==t||"object"!=typeof t?1:null==o||"object"!=typeof o?-1:pt(ft(e.orderAccessor,"order",t))-pt(ft(e.orderAccessor,"order",o))):t,r=new WeakMap;let s=0;for(const t of n){if(null==t||"object"!=typeof t)continue;const e=pt(ft(o,"x",t)),n=pt(ft(i,"y",t));Number.isFinite(e)&&Number.isFinite(n)&&s++}let a=0;for(const t of n){if(null==t||"object"!=typeof t)continue;const e=pt(ft(o,"x",t)),n=pt(ft(i,"y",t));Number.isFinite(e)&&Number.isFinite(n)&&r.set(t,{idx:a++,total:s})}return{data:n,orderMap:r}}(t,n),s=jt({data:r.data,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:i.annotations,themeCategorical:At(i.theme).colors.categorical}),a=mt(s.annotations,n.regression),c=n.pointRadius??4,l=it(n.xAccessor,n.yAccessor),u=n.styleRules,d=[t=>{const e=t.filter(t=>"point"===t.type&&"number"==typeof t.x&&"number"==typeof t.y);if(2>e.length)return null;const o=[];for(let t=0;e.length-1>t;t++){const i=e[t],n=e[t+1],r=yt(t,e.length);100>e.length&&o.push(p.createElement("line",{key:"halo-"+t,x1:i.x,y1:i.y,x2:n.x,y2:n.y,stroke:"white",strokeWidth:c+2,strokeLinecap:"round",opacity:.5})),o.push(p.createElement("line",{key:"segment-"+t,x1:i.x,y1:i.y,x2:n.x,y2:n.y,stroke:r,strokeWidth:c,strokeLinecap:"round"}))}return p.createElement(p.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:et(t=>{const e=r.orderMap.get(t),o=e?.idx??0,i=e?.total??1,n={fill:i>0?yt(o,i):"#6366f1",stroke:"white",strokeWidth:1,r:c,fillOpacity:1};return u?.length&&Object.assign(n,at(t,u,l(t))),n},gt(n)),...i,...a&&a.length>0&&{annotations:a},...s.yExtent&&!i.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}},Ve={frameType:"xy",buildProps:(t,e,o,i,n)=>{const r=n.frameProps&&"object"==typeof n.frameProps?n.frameProps:void 0,s=Number.isFinite(n.cellBorderWidth)?Math.max(0,n.cellBorderWidth):1,a=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,c=null!=r&&Object.hasOwn(r,"heatmapColorScale"),l=r?.heatmapColorScale,u=c?"function"==typeof l?l:void 0:"custom"===a&&"function"==typeof n.customColorScale?n.customColorScale:void 0;return{chartType:"heatmap",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",valueAccessor:n.valueAccessor,showValues:n.showValues,heatmapValueFormat:n.valueFormat,areaStyle:()=>({stroke:n.cellBorderColor??"#fff",strokeWidth:s}),...i,...void 0!==a&&{colorScheme:a},...u&&{heatmapColorScale:u}}}};function He(t){return Math.max(0,Math.min(1,t))}function Ue(t){const e=t.trim();if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t.split("").map(t=>t+t).join("")),6===t.length&&/^[0-9a-f]{6}$/i.test(t))return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const t=[Number(o[1]),Number(o[2]),Number(o[3])];if(t.every(Number.isFinite))return t}return null}function Ke(t,e,o){const i=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${i(t)}${i(e)}${i(o)}`}function Ze(t,e,o){const i=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:He(t.offset),color:t.color??o,opacity:null==t.opacity?1:He(t.opacity)})).sort((t,e)=>t.offset-e.offset);if(0===i.length)return"#999999";const n=t=>{if(1===t.opacity)return t.color;const e=Ue(t.color);return e?`rgba(${e[0]},${e[1]},${e[2]},${t.opacity})`:t.color};if(1===i.length)return n(i[0]);const r=He(e);if(i[0].offset>=r)return n(i[0]);if(r>=i[i.length-1].offset)return n(i[i.length-1]);for(let t=0;i.length-1>t;t++){const e=i[t],o=i[t+1];if(e.offset>r||r>o.offset)continue;const s=o.offset-e.offset,a=s>0?(r-e.offset)/s:0,c=Ue(e.color),l=Ue(o.color);if(!c||!l)return n(.5>a?e:o);const[u,d,h]=c,[f,p,y]=l,g=u+(f-u)*a,m=d+(p-d)*a,x=h+(y-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?Ke(g,m,x):`rgba(${Math.round(g)},${Math.round(m)},${Math.round(x)},${b})`}return n(i[i.length-1])}function Qe(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as Je,jsx as to,jsxs as eo}from"react/jsx-runtime";function oo(t=240){const e=360-t,o=180+e/2,i=o*Math.PI/180;return{sweepRad:t*Math.PI/180,gapDeg:e,startAngleDeg:o,startAngleRad:i,offsetRad:-Math.PI/2+i}}import{useMemo as io,useCallback as no,useRef as ro}from"react";var so={RdBu:F,PiYG:N,PRGn:E,BrBG:D,RdYlBu:B,RdYlGn:W,Spectral:j},ao="__likert_neutral_neg",co="__likert_neutral_pos";function lo(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}import*as uo from"react";function ho(t){return dt(t)}function fo(t,e,o,i,n){const r=At(i.theme).colors.categorical,s=o??i.colorScheme,a=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],c="string"==typeof e?e:"__ssrColorBy",l="function"==typeof e?a.map(t=>({...t,__ssrColorBy:e(t)})):a,u=e?Q(l,c,s??r):void 0,d=ve("string"==typeof n.color?n.color:void 0,r,s,void 0,new Map),h=ot(n.valueAccessor),f=n.styleRules,p=i.pieceStyle;return(t,o)=>{const i={fill:e&&u?K(t,e,u):d};return f?.length&&Object.assign(i,at(t,f,{value:h(t),category:o})),"function"==typeof p?Object.assign(i,p(t,o)||{}):p&&"object"==typeof p&&Object.assign(i,p),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}function po(t,e,o,i,n){const r=fo(t,e,o,i,n);return(t,e)=>{const o=r(t,e);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function yo(t,e,o,i,n){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s="string"==typeof e?e:"__ssrViolinColorBy",a="function"==typeof e?r.map(t=>({...t,__ssrViolinColorBy:e(t)})):r,c=At(i.theme).colors.categorical,l=o??i.colorScheme,u=e?Q(a,s,l??c):void 0,d=ve("string"==typeof n.color?n.color:void 0,c,l,void 0,new Map);return t=>{const o=e&&u?K(t,e,u):d;return{fill:o,fillOpacity:.6,stroke:n.stroke??o,...void 0!==n.strokeWidth&&{strokeWidth:n.strokeWidth},...void 0!==n.opacity&&{opacity:n.opacity}}}}function go(t,e,o,i,n){const r=fo(t,e,o,i,n),s="number"==typeof n.dotRadius?n.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function mo(t,e,o,i,n){const r=fo(t,e,o,i,n),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=n.sizeBy,c=Array.isArray(n.sizeRange)?n.sizeRange:[3,8],l=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=l.length?Pt(l):void 0,d="number"==typeof n.pointRadius?n.pointRadius:4,h="number"==typeof n.pointOpacity?n.pointOpacity:.7;return(t,e)=>({r:a?J(t,a,c,u):d,fillOpacity:h,...r(t,e)})}var xo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=mt(i.annotations,n.regression);return{chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",oSort:n.sort??!1,colorAccessor:e,colorScheme:o,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,...r&&{annotations:r},gradientFill:ho(i.gradientFill),pieceStyle:fo(t,e,o,i,n)}}},bo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.stackBy;return{chartType:"bar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===n.orientation?"horizontal":"vertical",normalize:n.normalize,oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,gradientFill:ho(i.gradientFill),pieceStyle:fo(t,r,o,i,n),showLegend:i.showLegend??!!r}}},vo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.groupBy;return{chartType:"clusterbar",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",groupBy:n.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===n.orientation?"horizontal":"vertical",oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,gradientFill:ho(i.gradientFill),pieceStyle:fo(t,r,o,i,n),showLegend:i.showLegend??!!r}}},wo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.categoryAccessor;return{chartType:"pie",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...i,pieceStyle:fo(t,r,o,i,n),showLegend:i.showLegend??!!r}}},ko={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,i,n)=>{const r=e||n.categoryAccessor;return{chartType:"donut",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",margin:i.margin??{top:50,right:40,bottom:60,left:70},innerRadius:n.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...i,pieceStyle:fo(t,r,o,i,n)}}},So={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=n.valueAccessor||"value",a=r.map(t=>Number("function"==typeof s?s(t):t[s])).filter(Number.isFinite),c=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:t,oAccessor:n.categoryAccessor||(t=>null==t.category?"All":t.category+""),rAccessor:s,projection:"horizontal",bins:n.bins??25,normalize:n.relative??!1,colorAccessor:e,colorScheme:o,barPadding:n.categoryPadding??20,...n.valueExtent?{rExtent:n.valueExtent}:c?{rExtent:c}:{},...i,summaryStyle:po(t,e,o,i,n)}}},Ao={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"boxplot",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:o,...null!=n.showOutliers&&{showOutliers:n.showOutliers},...null!=n.outlierRadius&&{outlierRadius:n.outlierRadius},...i,summaryStyle:i.summaryStyle||po(t,e,o,i,n)})},Mo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"violin",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,projection:"horizontal"===n.orientation?"horizontal":"vertical",bins:n.bins??25,showIQR:n.showIQR??!0,barPadding:n.categoryPadding??20,colorScheme:o,...i,summaryStyle:i.summaryStyle||yo(t,e,o,i,n),showLegend:i.showLegend??!!e,...n.valueExtent&&{rExtent:n.valueExtent}})},_o={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"swarm",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:o,...i,sizeRange:n.sizeRange||[3,8],pieceStyle:i.pieceStyle||mo(t,e,o,i,n),showLegend:i.showLegend??!!e})},Po={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,i,n)=>{const r=mt(i.annotations,n.regression);return{chartType:"point",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===n.orientation?"vertical":"horizontal",oSort:n.sort??"auto",barPadding:n.categoryPadding??10,...i,...r&&{annotations:r},pieceStyle:go(t,e,o,i,n),showGrid:i.showGrid??!0,showLegend:i.showLegend??!!e}}},Lo={frameType:"ordinal",buildProps:(t,e,o,i,n)=>{const r=e||n.subcategoryAccessor;return{chartType:"swimlane",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.subcategoryAccessor,colorAccessor:r,categoryAccessor:n.categoryAccessor,subcategoryAccessor:n.subcategoryAccessor,colorScheme:o,projection:"vertical"===n.orientation?"vertical":"horizontal",...null!=n.trackFill&&{trackFill:n.trackFill},...n.valueExtent&&{rExtent:n.valueExtent},...null!=n.roundedTop&&{roundedTop:n.roundedTop},...i,gradientFill:ho(i.gradientFill),pieceStyle:i.pieceStyle||fo(t,r,o,i,n),showLegend:i.showLegend??!!r,barPadding:n.barPadding??40}}},$o={frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"ridgeline",data:t,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===n.orientation?"vertical":"horizontal",bins:n.bins??20,amplitude:n.amplitude??1.5,barPadding:n.categoryPadding??5,oSort:n.oSort??!1,...i,summaryStyle:i.summaryStyle||((r,s)=>({fillOpacity:.5,...fo(t,e,o,i,n)(r,s)})),showLegend:i.showLegend??!!e})},Ro={frameType:"ordinal",layout:{margin:(t,e)=>({...e.marginDefaults,left:"vertical"===t.orientation?e.marginDefaults.left:Math.max(100,e.marginDefaults.left)})},buildProps:(t,e,o,i,n)=>{const r=Array.isArray(n.levels)&&n.levels.length>=2?n.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==n.orientation;let a=function(t,e,o,i,n,r){const s=new Map,a=new Set(e);for(const c of t){const t=o(c);s.has(t)||s.set(t,new Map);const l=s.get(t);if(i){const t=i(c);if(null==t||!Number.isFinite(t))continue;if(!Number.isInteger(t)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",t);continue}const o=t-1;if(0>o||o>=e.length)continue;const n=e[o];l.set(n,(l.get(n)||0)+1)}else if(n&&r){const t=n(c),e=r(c);if(!a.has(t))continue;l.set(t,(l.get(t)||0)+(Number.isFinite(e)?e:0))}}const c=[];for(const[t,o]of s){let i=0;for(const t of e)i+=o.get(t)||0;if(0!==i)for(let n=0;e.length>n;n++){const r=e[n],s=o.get(r)||0;c.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/i*100,__likertLevelIndex:n})}}return c}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,lo(n.categoryAccessor,"question"),n.levelAccessor?null:lo(n.valueAccessor,"score"),n.levelAccessor?lo(n.levelAccessor,"level"):null,n.levelAccessor?lo(n.countAccessor,"count"):null);s&&(a=function(t,e){const o=e.length,i=o%2!=0,n=Math.floor(o/2),r=new Map;for(const e of t){const t=r.get(e.__likertCategory)||[];t.push(e),r.set(e.__likertCategory,t)}const s=[];for(const[,t]of r){const e=new Map;let r,a;for(const o of t)o.__likertLevel===ao?r=o:o.__likertLevel===co?a=o:e.set(o.__likertLevelIndex,o);i&&r&&s.push(r);for(let t=n-1;t>=0;t--){const o=e.get(t);o&&s.push(o)}i&&a&&s.push(a);for(let t=i?n+1:n;o>t;t++){const o=e.get(t);o&&s.push(o)}}return s}(function(t,e){const o=e.length,i=o%2!=0,n=Math.floor(o/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(i&&t===n){const t=e.__likertPct/2;r.push({...e,__likertLevel:ao,__likertPct:-t}),r.push({...e,__likertLevel:co,__likertPct:t})}else r.push(n>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const c=At(i.theme).colors.diverging,l=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(so,e)){const o=so[e];if(1===t)return[o(.5)];const i=[];for(let e=0;t>e;e++)i.push(o(e/(t-1)));return i}const o=["#da1e28","#ff8389","#ffb3b8"],i=["#a6c8ff","#4589ff","#0043ce"],n="#a8a8a8";if(1===t)return[n];const r=t%2!=0,s=Math.floor(t/2),a=[];for(let t=0;s>t;t++)a.push(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);r&&a.push(n);for(let t=0;s>t;t++)a.push(i[Math.min(Math.floor(t*i.length/s),i.length-1)]);return a}(r.length,c),u=new Map(r.map((t,e)=>[t,l[e]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof n.valueFormat?n.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",f=Jt(!1===i.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},i.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:n.barPadding,showGrid:i.showGrid,oLabel:n.categoryLabel,rLabel:n.valueLabel||(s?void 0:"Percentage"),rFormat:h,...n.categoryFormat&&{oFormat:n.categoryFormat},...n.valueExtent&&{rExtent:n.valueExtent},...i,pieceStyle:et(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===ao||e===co?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},gt(n)),showLegend:i.showLegend??!0,legendPosition:i.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}},Co={frameType:"ordinal",layout:{margin:(t,e)=>"vertical"===t.orientation?{top:e.title?60:40,right:20,bottom:60,left:60}:{top:e.title?40:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r="vertical"===n.orientation,s=e||n.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:n.stepAccessor||"step",rAccessor:n.valueAccessor||"value",colorAccessor:s,categoryAccessor:n.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:n.connectorAccessor,connectorStyle:n.connectorStyle,...!r&&null!=n.connectorOpacity&&{connectorOpacity:n.connectorOpacity},barPadding:r?40:0,colorScheme:o,...i,showAxes:r&&!1!==i.showAxes,showGrid:r,pieceStyle:fo(t,s,o,i,n),showLabels:n.showLabels??!0}}},Io={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const o=t.__gauge;if(!o)return null;const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,n=o.needleColor||e.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(t=>t.value>o.gMin&&o.gMax>t.value):[];return eo(Je,{children:[o.showNeedle&&eo(Je,{children:[to("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(i),y2:o.centerY+o.needleLength*Math.sin(i),stroke:n,strokeWidth:2.5,strokeLinecap:"round"}),to("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:n})]}),null!=o.contextValue&&to("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:n,children:o.contextValue}),r.map((t,i)=>{const n=(o.startAngleDeg+(o.gMax===o.gMin?0:(t.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,s=o.radius+1,a=o.radius+10,c=((n+Math.PI/2)/(2*Math.PI)*12+12)%12,l=c>=11||1>c?"middle":5>c?"start":7>c?"middle":"end",u=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return eo("g",{children:[to("line",{x1:o.centerX+Math.cos(n)*r,y1:o.centerY+Math.sin(n)*r,x2:o.centerX+Math.cos(n)*s,y2:o.centerY+Math.sin(n)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),to("text",{x:o.centerX+Math.cos(n)*a,y:o.centerY+Math.sin(n)*a,textAnchor:l,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+i)})]})},buildProps:(t,e,o,i,n)=>{const r=n.min??0,s=n.max??100,a=n.sweep??240,c=n.arcWidth??.3,l=!1!==n.showNeedle,u=!1!==n.fillZones,{startAngleDeg:d}=oo(a),h=n.thresholds||[{value:s,color:n.color||"#4e79a7"}],f=ht(i.gradientFill),p=function(t){const{min:e,max:o,value:i,thresholds:n,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,i))-e)/d;let f=n&&n.length>0?[...n].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];f=f.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>f[f.length-1].value&&f.push({value:o,color:f[f.length-1].color});const p=!!l&&l.stops.length>=2,y=[],g=new Map,m=[];if(p){const t=a?h:1,e=Qe("bg",0);if(y.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),g.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(e,Math.round(t*e))),i=[];for(let e=0;o>e;e++)i.push(Ze(l.stops,t*(e+.5)/o,r||f[0]?.color||"#007bff"));const n=Qe("fill",0);y.push({category:n,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:i}}),g.set(n,{fill:i[0]||s})}}else{let t=e;for(let o=0;f.length>o;o++){const i=f[o],n=(i.value-t)/d,r=(t-e)/d,c=(i.value-e)/d,l=Math.max(0,(a?Math.min(h,c):c)-r),u=a?Math.max(0,n-l):0;if(l>0){const t=Qe("fill",o);y.push({category:t,value:l,_zone:i.label||"Zone "+(o+1),_isFill:!0}),g.set(t,{fill:i.color})}if(u>0){const t=Qe("bg",o);y.push({category:t,value:u,_zone:i.label||"Zone "+(o+1),_isFill:!1}),g.set(t,{fill:s,opacity:.4})}t=i.value}}if(c&&n&&n.length>0)for(const t of n)t.value>e&&o>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:y,pieceStyle:(t,e)=>g.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:n.value,thresholds:h,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==n.showScaleLabels,gradientFill:f}),[y,g]=i.size||[300,250],m=function(t=240){const{sweepRad:e,offsetRad:o}=oo(t),i=[[Math.cos(o),Math.sin(o)],[Math.cos(o+e),Math.sin(o+e)],[0,0]];for(let t=0;2*Math.PI>t;t+=Math.PI/2)((t-o)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)>e+.001||i.push([Math.cos(t),Math.sin(t)]);const n=i.map(t=>t[0]),r=i.map(t=>t[1]),[s,a]=Pt(n),[c,l]=Pt(r);return{minX:s,maxX:a,minY:c,maxY:l,width:a-s,height:l-c,cx:(s+a)/2,cy:(c+l)/2}}(a),x=Math.min(10,Math.max(1,Math.min(y,g)/12)),b=Math.max(4,Math.min((y-2*x)/m.width,(g-2*x)/m.height)-2),v=Math.max(0,Math.min(b-1.5,b*(1-c))),w=y/2-m.cx*b,k=g/2-m.cy*b,S=2*(b+4),A=Math.max(r,Math.min(s,n.value??r)),M="function"==typeof n.valueFormat?n.valueFormat(A):Math.round(A)+"",_=n.centerContent??i.centerContent,P=null!=_?"function"==typeof _?_(A,r,s):_:"sparkline"===n.mode||"context"===n.mode?void 0:uo.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},uo.createElement("div",{style:{fontSize:Math.max(16,.3*b),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==n.showScaleLabels&&uo.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:p.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:v,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:et(p.pieceStyle,gt(n)),...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...i,size:[y,g],margin:{top:k-S/2,bottom:g-k-S/2,left:w-S/2,right:y-w-S/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(i.annotations)?i.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:c,value:A,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:b,innerRadius:v,showScaleLabels:!1!==n.showScaleLabels,needleLength:v>20?v-8:b-1,showNeedle:l,needleColor:n.needleColor,..."context"===n.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*b))}}}}};import{scaleTime as To}from"d3-scale";var Oo={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function zo(t="static"){return Oo[t]??Oo.static}var Fo=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function No(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:Fo.has(t.kind)?"fatal":"warn"}function Eo(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:"duplicate-node"===t.kind?`node id "${t.id}" is duplicated`:"duplicate-edge"===t.kind?`edge id "${t.id}" is duplicated`:"invalid-system-time"===t.kind?`edge ${t.id} has an invalid systemInTime or systemOutTime`:t.kind}function Do(t){const{desired:e,minGaps:o,weights:i}=t,n=e.length;if(0===n)return[];if(o.length!==Math.max(0,n-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const r=Array(n).fill(0);for(let t=1;n>t;t++)r[t]=r[t-1]+Math.max(0,Number.isFinite(o[t-1])?o[t-1]:0);const s=[];for(let t=0;n>t;t++){const o=Math.max(Number.EPSILON,Number.isFinite(i?.[t])?i[t]:1),n=(Number.isFinite(e[t])?e[t]:0)-r[t];for(s.push({start:t,end:t,weight:o,mean:n});s.length>1;){const t=s[s.length-1],e=s[s.length-2];if(t.mean>=e.mean)break;const o=e.weight+t.weight;s.splice(s.length-2,2,{start:e.start,end:t.end,weight:o,mean:(e.mean*e.weight+t.mean*t.weight)/o})}}const a=Number.isFinite(t.min)?t.min:-1/0,c=Number.isFinite(t.max)?t.max-r[n-1]:1/0,l=a>c?a:c,u=Array(n);for(const t of s){const e=Math.max(a,Math.min(l,t.mean));for(let o=t.start;t.end>=o;o++)u[o]=e+r[o]}return u}function Bo(t,e){let o=0,i=t.length-1,n=-1;for(;i>=o;){const r=o+i>>>1;t[r].at>e?i=r-1:(n=r,o=r+1)}return 0>n?{at:e,before:0,after:0}:t[n]}function Wo(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const o=[],i=[0];for(let n=0;t.length-1>n;n++){const r=t[n],s=t[n+1],a=[...new Set([...r.map(t=>t.at),...s.map(t=>t.at)])].sort((t,e)=>t-e);let c=0;for(const t of a){const e=Bo(r,t),o=Bo(s,t);c=Math.max(c,e.after+o.before)}o.push(c),i.push(i[i.length-1]+c+e)}return{adjacentClearance:o,positions:i}}function jo(t,e,o,i={}){let n=[...t];if(1>=n.length)return n;let r=[...n],s=o(n),a=1;const c=Math.max(0,i.passes??6),l=Math.max(1,i.maxEvaluations??1/0);for(let t=0;c>t&&l>a;t++){const t=new Map(n.map((t,e)=>[t,e])),c=new Map,l=new Map;for(const o of e){const e=t.get(o.source),i=t.get(o.target);if(null==e||null==i)continue;const n=Number.isFinite(o.weight)&&o.weight>0?o.weight:1;c.set(o.source,(c.get(o.source)??0)+i*n),l.set(o.source,(l.get(o.source)??0)+n),c.set(o.target,(c.get(o.target)??0)+e*n),l.set(o.target,(l.get(o.target)??0)+n)}n=n.map((t,e)=>({item:t,index:e,barycenter:(c.get(t)??e)/(l.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(i.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=o(n);if(a++,s>u)s=u,r=[...n];else if(u===s)break}return r}function Yo(t,e,o={}){const i=[...t],n=i.length;if(1>=n||n>(o.maxItems??8))return i;const r=Math.max(1,o.maxEvaluations??1/0);let s=0,a=[...i],c=1/0;const l=()=>{if(s>=r)return;const t=e(i);s++,c>t&&(c=t,a=[...i])};l();const u=Array(n).fill(0);let d=0;for(;n>d&&r>s;)if(d>u[d]){const t=d%2==0?0:u[d];[i[t],i[d]]=[i[d],i[t]],l(),u[d]++,d=0}else u[d]=0,d++;return a}function Xo(){return Object.create(null)}function qo(t,e){return e>t?-1:t>e?1:0}function Go(t){return t.occupants.map(t=>t.id).sort(qo).join("\0")}function Vo(t,e,o=0){return t.slice(0,-1).map((i,n)=>null!=i.group&&i.group===t[n+1].group?o:e)}function Ho(t,e){return t.map(t=>{const o=new Map;for(const i of t.occupants){const t=e[i.id];if(t)for(const e of t.samples){const t=o.get(e.t)??{before:0,after:0},i=e.boundaryOffset??0;o.set(e.t,{before:Math.max(t.before,e.topMass-i),after:Math.max(t.after,e.botMass+i)})}}return[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function Uo(t,e,o){if(0===t.length)return[];const{padding:i,plotH:n,valueScale:r}=o,s=o.stackValueScale??r,a=Vo(t,i,o.groupPadding??0),c=[i+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)c.push(c[o-1]+e[o-1]*s+a[o-1]);const l=c[c.length-1]+t[t.length-1].peak.botPeak*s+i;if(l>n&&l>0){const t=n/l;for(let e=0;c.length>e;e++)c[e]*=t}return c}function Ko(t,e){const o=(t.boundaryOffset??0)*e,i=t.value*e;if("out"===t.kind){const n=t.sideMassBefore*e;return o+("top"===t.side?i/2-n:n-i/2)}const n=t.sideMassAfter*e;return o+("top"===t.side?i/2-n:n-i/2)}function Zo(t,e,o,i,n,r){const s=r.adjacentClearance?[...r.adjacentClearance]:Wo(Ho(i,o)).adjacentClearance,a=Uo(i,s,r);let c="hug"===r.lanePlacement?function(t,e,o,i,n,r,s){const a=t.length;if(0===a)return[];const{padding:c,plotH:l,valueScale:u}=s,d=Vo(t,c,s.groupPadding??0),h=n.map((t,e)=>t*u+d[e]),f=c+t[0].peak.topPeak*u,p=l-c-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=p-f)return Uo(t,n,s);let y=1===a?[(f+p)/2]:[...r];for(let t=0;12>t;t++){const t=Array(a).fill(0),n=Array(a).fill(0);for(const r of o){const o=e[r.source],s=e[r.target];if(null==o||null==s||o===s)continue;const a=i[r.source]?.localAttachments.get(r.id),c=i[r.target]?.localAttachments.get(r.id);if(!a||!c)continue;const l=r.value>0&&Number.isFinite(r.value)?r.value:1,d=Ko(a,u),h=Ko(c,u);t[o]+=(y[s]+h-d)*l,n[o]+=l,t[s]+=(y[o]+d-h)*l,n[s]+=l}const r=Do({desired:y.map((e,o)=>0===n[o]?e:.45*e+t[o]/n[o]*.55),minGaps:h,weights:n.map(t=>Math.max(1,t)),min:f,max:p});let s=0;for(let t=0;a>t;t++)s=Math.max(s,Math.abs(r[t]-y[t]));if(y=r,.01>s)break}return y}(i,n,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=Xo();for(const i of t)o[i.id]=e[n[i.id]];return o};Qo(o(c),e)>Qo(o(a),e)+1e-6&&(c=[...a])}const l=Xo();for(const e of t)l[e.id]=c[n[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=l[e.id],i=o[e.id];Number.isFinite(t)&&i&&(u=Math.min(u,t-i.topPeak*r.valueScale),d=Math.max(d,t+i.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:l,slotCenter:c,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function Qo(t,e){let o=0;for(const i of e){const e=t[i.source],n=t[i.target];Number.isFinite(e)&&Number.isFinite(n)&&(o+=Math.abs(e-n)*(i.value>0?i.value:1))}return o}function Jo(t,e){const o=t?.samples;if(!o||0===o.length||o[0].t>e)return{top:0,bot:0};let i=0,n=o.length-1,r=0;for(;n>=i;){const t=i+n>>>1;o[t].t>e?n=t-1:(r=t,i=t+1)}const s=o[r].boundaryOffset??0;return{top:o[r].topMass-s,bot:o[r].botMass+s}}function ti(t,e,o,i,n){const r=1-n;return r*r*r*t+3*r*r*n*e+3*r*n*n*o+n*n*n*i}function ei(t,e){let o=0,i=1;for(let n=0;28>n;n++){const n=(o+i)/2;t>ti(0,e,e,1,n)?o=n:i=n}return(o+i)/2}function oi(t,e,o){const i=e+Ko(t,o),n=t.value*o/2;return[i-n,i+n]}function ii(t,e,o,i){return Math.max(0,Math.min(e,i)-Math.max(t,o))/Math.max(1e-9,e-t)}function ni(t,e,o,i,n,r,s){const{valueScale:a,domain:c,mode:l="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of t){const t=i[s.source],h=i[s.target];if(null==t||null==h||2>Math.abs(t-h))continue;const f=e[s.source]?.localAttachments.get(s.id),p=e[s.target]?.localAttachments.get(s.id);if(!f||!p)continue;const y=Math.max(s.startTime,c?.[0]??-1/0),g=Math.min(s.endTime,c?.[1]??1/0);if(y>=g)continue;const[m,x]=oi(f,n[s.source],a),[b,v]=oi(p,n[s.target],a),w=Math.min(t,h)+1,k=Math.max(t,h)-1;for(let t=w;k>=t;t++){const i=o[t];if(!i)continue;const c=[y,g];if("quality"===l)for(const t of i.occupants)for(const o of e[t.id]?.samples??[])o.t>y&&g>o.t&&c.push(o.t);const h=t=>{const o=ei((t-y)/(g-y),u),c=ti(m,m,b,b,o),l=ti(x,x,v,v,o);let d=0;for(const o of i.occupants){if(o.id===s.source||o.id===s.target)continue;const i=r[o.id];if(null!=i?.start&&i.start>t)continue;if(null!=i?.end&&t>i.end)continue;const u=Jo(e[o.id],t),h=n[o.id];d=Math.max(d,ii(c,l,h-u.top*a,h+u.bot*a))}return d},f=[...new Set(c)].sort((t,e)=>t-e);let p=0;for(let t=0;f.length-1>t;t++){const e=f[t],o=f[t+1]-e;p+=(h(e+.25*o)+h(e+.5*o)+h(e+.75*o))/3*o}d+=p/(g-y)*(s.value>0?s.value:1)}}return d}function ri(t,e,o,i,n,r,s,a,c,l,u="both",d){return{crossings:t,weightedLength:e,pixelLength:Qo(s,o),transitOcclusion:ni(o,i,n,r,s,a,{valueScale:c,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:l}}function si(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function ai(t,e){return t.map(t=>({t:si(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function ci(t,e,o){const i=e+(t.boundaryOffset??0)*o,n=t.value*o;if("out"===t.kind){const e=t.sideMassBefore*o;if("top"===t.side){const t=i-e;return[t,t+n]}const r=i+e;return[r-n,r]}const r=t.sideMassAfter*o;if("top"===t.side){const t=i-r;return[t,t+n]}const s=i+r;return[s-n,s]}function li(t,e,o,i,n="temporal"){const r=e.incoming[t.id],s=e.outgoing[t.id],a=[];for(const t of r)a.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of s)a.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const c={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},l=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(c[t.kind]??99)-(c[e.kind]??99)||((t,e)=>{if(!i||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const o=i.get(t.edge.id)?.target,n=i.get(e.edge.id)?.target;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof n&&Number.isFinite(n)&&o!==n?"top"===t.side?o-n:n-o:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const o=i.get(t.edge.id)?.source,n=i.get(e.edge.id)?.source;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof n&&Number.isFinite(n)&&o!==n?"top"===t.side?n-o:o-n:0}return 0})(t,e)||qo(t.edge?.id??"",e.edge?.id??"")||qo(t.side,e.side)||t.delta-e.delta)},u=a.length?function(t,e=1/0){let o=e;for(const e of t)o>e&&(o=e);return o}(a.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;l();let f=null,p=0;for(const t of a)t.time!==f&&(f=t.time,p=0),t.sequence=p++;const y=t=>({time:t.time,phase:0,sequence:t.sequence??0}),g=[];let m=0,x=0;for(const t of a)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?m:x);if(o>0){const e="top"===t.side?"bot":"top",i=Math.min(o,"top"===e?m:x);if(i>0){const n=y(t);g.push({...n,delta:-i,kind:"transfer-out",side:e}),g.push({...n,delta:+i,kind:"transfer-in",side:t.side}),"top"===e?m-=i:x-=i,"top"===t.side?m+=i:x+=i,o-=i}o>0&&null!==h&&(g.push({time:h,delta:+o,kind:"create",side:t.side}),"top"===t.side?m+=o:x+=o)}"top"===t.side?m-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?m+=e:x+=e}a.push(...g),l();let b=0,v=0,w=0,k=0,S=0,A=0;const M=[],_=new Map,P=t=>{M.push({t:t,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},L=()=>{k=Math.max(k,b+v),S=Math.max(S,b-w),A=Math.max(A,v+w)};for(const t of a){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&P(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?b:v;_.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?b+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,L(),P(t.time)):"transfer-out"!==t.kind&&(L(),"out"!==t.kind||b+v>1e-12||(w=0),P(t.time))}const $=[];let R=0;for(;M.length>R;){let t=R;for(;M.length>t+1&&M[t+1].t===M[R].t;)t++;$.push(M[R]);for(let e=R+1;t>=e;e++){const t=$[$.length-1];M[e].topMass===t.topMass&&M[e].botMass===t.botMass&&(M[e].boundaryOffset??0)===(t.boundaryOffset??0)||$.push(M[e])}R=t+1}const C=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let I=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===I||I>t.systemInTime)&&(I=t.systemInTime);let T=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===T||t.systemOutTime>T)&&(T=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=C?C:-1/0,null!=T?T:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&$.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const o=$[0],i=$.find(t=>t.topMass+t.botMass>0);let n,r=1/0;null!=d&&Number.isFinite(d)&&o.t>d&&o.topMass+o.botMass>0&&(r=d,n=o),i&&null!=I&&Number.isFinite(I)&&i.t>I&&r>I&&(r=I,n=i),n&&Number.isFinite(r)&&$.unshift({t:r,topMass:n.topMass,botMass:n.botMass,...null!=n.boundaryOffset&&{boundaryOffset:n.boundaryOffset}})}let O=$;if("max"===n&&null!=d&&null!=C&&C>d){let t,e=0;for(const o of $){const i=o.topMass+o.botMass;i>e&&(e=i,t=o)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};O=[...$.filter(t=>d>t.t),{t:d,...e},{t:C,...e},...$.filter(t=>t.t>C)]}}return{samples:O,peak:k,topPeak:S,botPeak:A,localAttachments:_}}function ui(t){const e=Xo();return t.forEach((t,o)=>{for(const i of t.occupants)e[i.id]=o}),e}function di(t,e,o){t.splice(0,t.length,...o);const i=ui(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,i)}function hi(t){const e=new Map,o=[];t.forEach((t,i)=>{if(!t.group)return void o.push({anchor:i,stableId:Go(t),slots:[t]});const n=e.get(t.group)??{indexes:[],slots:[]};n.indexes.push(i),n.slots.push(t),e.set(t.group,n)});for(const[t,i]of e)o.push({anchor:i.indexes.reduce((t,e)=>t+e,0)/i.indexes.length,stableId:`${t}\0${i.slots.map(Go).join("\0")}`,slots:i.slots});return o.sort((t,e)=>t.anchor-e.anchor||qo(t.stableId,e.stableId))}function fi(t){return t.some(t=>t.group)?hi(t).flatMap(t=>t.slots):[...t]}function pi(t){return t.flatMap(t=>t.slots)}function yi(t,e,o){const i=new Map;return t.forEach((t,e)=>{for(const o of t.slots)i.set(o,e)}),t.map((t,n)=>{if(1>=t.slots.length)return t;const r=new Map;for(const e of t.slots)r.set(e,0);for(const t of e){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o)continue;const s=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===n&&o!==n){const e=o>n?1:-1;r.set(t.source,(r.get(t.source)??0)+s*e)}else if(o===n&&e!==n){const o=e>n?1:-1;r.set(t.target,(r.get(t.target)??0)+s*o)}}const s=[...t.slots].sort((t,e)=>(r.get(t)??0)-(r.get(e)??0)||o(t,e));return{...t,slots:s}})}function gi(t,e){t.some(t=>t.group)&&di(t,e,fi(t))}function mi(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.min(t.endTime,e.endTime)>Math.max(t.startTime,e.startTime)}function xi(t,e){return function(t,e,o=()=>!0){let i=0;for(let n=0;t.length>n;n++){const[r,s]=e(t[n]);for(let a=n+1;t.length>a;a++){if(!o(t[n],t[a]))continue;const[c,l]=e(t[a]);0>(r-c)*(s-l)&&i++}}return i}(e,e=>[t[e.source],t[e.target]],mi)}function bi(t,e){let o=0;for(const i of e){const e=t[i.source],n=t[i.target];null!=e&&null!=n&&(o+=Math.abs(e-n)*(i.value>0?i.value:1))}return o}function vi(t,e,o){const[i,n]=o.get(t.first),[r,s]=o.get(t.second);return 0>(e.get(i)-e.get(r))*(e.get(n)-e.get(s))?1:0}var wi=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},ki=828*wi(8),Si=3e3;function Ai(t,e,o,i,n,r,s){const a=[...n],c=new Map(n.map(t=>[t,Go(t)])),l=new Map;for(const t of n)for(const e of t.occupants)l.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=l.get(t.source),o=l.get(t.target);e&&o&&(u.set(t,[e,o]),e!==o&&d.push({source:e,target:o,weight:t.value}))}const h=[];for(let t=0;e.length>t;t++)if(u.has(e[t]))for(let o=t+1;e.length>o;o++){if(!u.has(e[o])||!mi(e[t],e[o]))continue;const i=new Set([...u.get(e[t]),...u.get(e[o])]);h.push({index:h.length,first:e[t],second:e[o],involvedSlots:i})}const f=new Map;for(const t of n)f.set(t,[]);for(const t of h)for(const e of t.involvedSlots)f.get(e)?.push(t);const p=new Uint32Array(h.length);let y=0;const g=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),m=s.plotH/Math.max(1,n.length),x=n.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),b=Math.max(1,g)*(Math.max(1,s.plotH)+m*Math.max(x,n.length)+1e-6*Math.max(1,n.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,S=(t,e)=>{let i=k.get(t);i||(i=new Map,k.set(t,i));const n=i.get(e);if(null!=n)return n;const r=function(t,e,o){return Wo(Ho([t,e],o)).adjacentClearance[0]??0}(t,e,o);return i.set(e,r),r},A=new Map(n.map((t,e)=>[t,e])),M=e.flatMap(t=>{const e=u.get(t);return e?[{source:A.get(e[0]),target:A.get(e[1]),weight:t.value>0?t.value:1}]:[]}),_=new Map;for(const t of e){const e=u.get(t);e&&_.set(t,{source:A.get(e[0]),target:A.get(e[1])})}const P=new Map,L=new Map,$=new Map,R=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)R(P,t.source,t.target),R(L,t.target,t.source),R($,t.source,t.target),R($,t.target,t.source);const C=e.flatMap(t=>{if(!(t=>1===P.get(t.source)?.size&&P.get(t.source).has(t.target)||1===$.get(t.source)?.size||1===$.get(t.target)?.size)(t))return[];const e=_.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),I=t=>{let e=0;for(const o of C)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*v},T=t=>{const e=new Int16Array(n.length);for(let o=0;t.length>o;o++)e[A.get(t[o])]=o;return I(e)},O=h.map(t=>{const e=_.get(t.first),o=_.get(t.second);return[e.source,e.target,o.source,o.target]}),z=new Int16Array(n.length),F=new Float64Array(n.length),N=new Float64Array(n.length+1),E=t=>{for(let e=0;t.length>e;e++)z[A.get(t[e])]=e;let e=0;for(const[t,o,i,n]of O)0>(z[t]-z[i])*(z[o]-z[n])&&e++;if(t.length>0){const e=A.get(t[0]);F[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const o=A.get(t[e-1]),i=A.get(t[e]);F[i]=F[o]+S(t[e-1],t[e])*s.valueScale+s.padding}const o=A.get(t[t.length-1]),i=F[o]+t[t.length-1].peak.botPeak*s.valueScale+s.padding;if(i>s.plotH&&i>0){const t=s.plotH/i;for(let e=0;F.length>e;e++)F[e]*=t}}N[0]=0;for(let e=0;t.length>e;e++)N[e+1]=N[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,i=0,n=0;for(const t of M){const e=z[t.source],r=z[t.target];if(o+=Math.abs(e-r)*t.weight,i+=Math.abs(F[t.source]-F[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;n+=(N[Math.max(e,r)]-N[o])*t.weight}}return e*b+i+n*m+I(z)+1e-6*o},D=(t,o)=>{const i=Array(t.length+1).fill(0);for(let e=0;t.length>e;e++)i[e+1]=i[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0;for(const t of e){const e=o[t.source],r=o[t.target];if(null==e||null==r||2>Math.abs(e-r))continue;const s=Math.min(e,r)+1;n+=(i[Math.max(e,r)]-i[s])*(t.value>0?t.value:1)}return n},B=i=>{const n=ui(i),r=i.slice(0,-1).map((t,e)=>S(t,i[e+1])),a=Zo(t,e,o,i,n,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:n,geometry:a,weightedLength:bi(n,e),pixelLength:Qo(a.centerlines,e),transitOcclusion:D(i,n)}},W=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*b+e.pixelLength+e.transitOcclusion*m+T(o)+1e-6*e.weightedLength}),j=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+vi(o,e,u),0),w.fullCrossing++}return W(o,B(t),t)},Y=(t,n,r="quality")=>{let a=n;if(null==a){const e=new Map(t.map((t,e)=>[t,e]));a=h.reduce((t,o)=>t+vi(o,e,u),0),w.fullCrossing++}const c=B(t);return W(a,{...c,transitOcclusion:ni(e,o,t,c.map,c.geometry.centerlines,i,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let X=[...a];const q=(t,e)=>qo(c.get(t),c.get(e)),G=function(t){const e=new Set;for(const o of t)if(o.group){if(e.has(o.group))return!0;e.add(o.group)}return!1}(X),V=t=>{const e=(t=>{const e=jo(t,d,t=>j(t).cost,{passes:6,compare:q,maxEvaluations:Si});let o=j(e),i=Si;for(let t=0;6>t&&i>0;t++){let n=!1;const r=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&r.reverse();for(const t of r){if(0>=i--)break;const r=e[t],s=e[t+1],a=new Map(e.map((t,e)=>[t,e]));let c=0;const l=[];y++;for(const t of[...f.get(r)??[],...f.get(s)??[]])p[t.index]!==y&&(p[t.index]=y,l.push(t),c+=vi(t,a,u));[e[t],e[t+1]]=[s,r];const d=new Map(a);d.set(r,t+1),d.set(s,t);let h=0;for(const t of l)h+=vi(t,d,u);w.localCrossing+=l.length;const g=j(e,o.crossings-c+h);o.cost>g.cost?(o=g,n=!0):[e[t],e[t+1]]=[r,s]}if(!n)break}return e})(t);if((t.length>8?1/0:wi(t.length)*(t.length+M.length+O.length))>ki)return e;const o=Yo(t,E,{maxItems:8,maxEvaluations:5e4}),i=Y(o),n=Y(e);return i.crossings!==n.crossings&&n.crossings>i.crossings?o:e},H="geometry-refine"===s.mode;if(H||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!H&&"inside-out"===s.laneOrder)if(G){const t=hi(X),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||qo(t.stableId,o.stableId)),i=Array(o.length);let n=Math.floor((o.length-1)/2)-1,r=Math.floor((o.length-1)/2)+1;o.length>0&&(i[Math.floor((o.length-1)/2)]=o[0]);for(let t=1;o.length>t;t++)t%2==1&&o.length>r||0>n?i[r++]=o[t]:i[n--]=o[t];X=pi(i)}else{const t=[...X].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||q(t,e)),e=Array(t.length);let o=Math.floor((t.length-1)/2)-1,i=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let n=1;t.length>n;n++)n%2==1&&t.length>i||0>o?e[i++]=t[n]:e[o--]=t[n];X=e}}else X=G?(t=>{let e=hi(t);if(1>=e.length)return pi(e);const o=t=>j(pi(t)).cost;e=hi(V(t)),e=yi(e,d,q);const i=function(t,e){const o=new Map;for(const e of t)for(const t of e.slots)o.set(t,e);const i=new Map;for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(!e||!n||e===n)continue;const r=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,s=n.stableId>e.stableId?`${e.stableId}\0${n.stableId}`:`${n.stableId}\0${e.stableId}`,a=i.get(s);a?a.weight=(a.weight??0)+r:i.set(s,{source:e,target:n,weight:r})}return[...i.values()]}(e,d);e=jo(e,i,o,{passes:6,compare:(t,e)=>qo(t.stableId,e.stableId),maxEvaluations:Si}),e=function(t,e,o={}){const i=[...t];if(1>=i.length)return i;let n=e(i),r=1;const s=Math.max(0,o.passes??6),a=Math.max(1,o.maxEvaluations??1/0);for(let t=0;s>t&&a>r;t++){let t=!1;for(let o=0;i.length-1>o&&a>r;o++){[i[o],i[o+1]]=[i[o+1],i[o]];const s=e(i);r++,n>s?(n=s,t=!0):[i[o],i[o+1]]=[i[o+1],i[o]]}if(!t)break}return i}(e,o,{passes:8,maxEvaluations:Si});const n=e.length>8?1/0:wi(e.length)*(e.length+M.length+O.length);if(ki>=n){const t=Yo(e,t=>E(pi(t)),{maxItems:8,maxEvaluations:5e4}),o=pi(t),i=pi(e),n=Y(o),r=Y(i);n.crossings!==r.crossings?e=r.crossings>n.crossings?t:e:r.cost>n.cost&&(e=t)}return e=yi(e,d,q),pi(e)})(X):V(X);if(!H&&"crossing-min+inside-out"===s.laneOrder&&X.length>1)if(G){const t=hi(X);let e=j(pi(t)),o=pi(t),i=e;const n=Math.floor((t.length-1)/2),r=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),s=[...t].sort((t,e)=>r(e)-r(t)||qo(t.stableId,e.stableId));for(const r of s){const s=t.indexOf(r);if(s===n)continue;t.splice(s,1),t.splice(n,0,r);const a=pi(t),c=j(a);c.cost>e.cost?(t.splice(n,1),t.splice(s,0,r)):(e=c,i.cost>c.cost&&(o=a,i=c))}X=o}else{let t=j(X),e=[...X],o=t;const i=Math.floor((X.length-1)/2),n=[...X].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||q(t,e));for(const r of n){const n=X.indexOf(r);if(n===i)continue;X.splice(n,1),X.splice(i,0,r);const s=j(X);s.cost>t.cost?(X.splice(i,1),X.splice(n,0,r)):(t=s,o.cost>s.cost&&(e=[...X],o=s))}X=e}if((H||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&X.length>1)if(G){let t=hi(X),e=Y(pi(t),void 0,"score");for(let o=0;6>o&&t.length>1;o++){let o=!1;for(let i=0;t.length-1>i;i++){[t[i],t[i+1]]=[t[i+1],t[i]];const n=pi(t),r=Y(n,void 0,"score");e.cost>r.cost?(X=n,e=r,o=!0):[t[i],t[i+1]]=[t[i+1],t[i]]}if(!o)break}t=yi(hi(X),d,q),X=pi(t)}else{let t=Y(X,void 0,"score");for(let e=0;X.length-1>e;e++){const o=X[e],i=X[e+1],n=new Map(X.map((t,e)=>[t,e]));let r=0;const s=[];y++;for(const t of[...f.get(o)??[],...f.get(i)??[]])p[t.index]!==y&&(p[t.index]=y,s.push(t),r+=vi(t,n,u));[X[e],X[e+1]]=[i,o];const a=new Map(n);a.set(o,e+1),a.set(i,e);let c=0;for(const t of s)c+=vi(t,a,u);w.localCrossing+=s.length;const l=Y(X,t.crossings-r+c,"score");t.cost>l.cost?t=l:[X[e],X[e+1]]=[o,i]}}const U=fi(a);X=fi(X);let K=Y(X);const Z=Y(U);if(H){const t=T(U),e=T(X);(K.crossings>Z.crossings||K.crossings===Z.crossings&&e>t+1e-9||K.cost>Z.cost)&&(X=U,K=Z)}else K.cost>Z.cost&&(X=U,K=Z);const Q=function({order:t,after:e,nodes:o,edges:i,outgoingPartners:n,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:c}){const l=(o,n)=>{const r=[...new Set(n.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),l=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-l+1!==r.length||1>=Math.abs(2*s-l-u))return;const d=[...t];d.splice(s,1),d.splice(l+u>>1,0,o);const h=fi(d),f=c(h),p=new Set(o.occupants.map(t=>t.id)),y=new Set(n.flatMap(t=>t.occupants.map(t=>t.id))),g=i.reduce((t,e)=>p.has(e.source)&&y.has(e.target)||p.has(e.target)&&y.has(e.source)?t+(e.value>0?e.value:1):t,0);(function(t,e,o=0){return e.crossings>t.crossings||t.crossings===e.crossings&&e.cost+o>=t.cost})(f,e,Math.abs(2*s-l-u)*a*Math.max(1,g))&&(t=h,e=f)};for(const[t,e]of n)r.has(t)||3>e.size||l(s.get(t),[...e].map(t=>s.get(t)));for(const t of o){const e=s.get(t.id);t.group||!e.group||3>(r.get(t.id)?.size??0)||l(e,[...r.get(t.id)??[]].map(t=>s.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,o)=>o.indexOf(t)===e))}return{order:t,after:e}}({order:X,after:K,nodes:t,edges:e,outgoingPartners:P,incomingPartners:L,slotForNode:l,averageGap:m,evaluate:Y});return X=Q.order,K=Q.after,di(n,r,X),{before:Z,after:K,initialOrder:a.map(t=>c.get(t)),evaluations:w}}function Mi(t,e,o){const i=t.map(t=>{const i=t.occupants.map(t=>({id:t.id,end:o[t.id]?.end??t.end}));let n=0,r=0;for(const t of i){const o=e[t.id];n=Math.max(n,o?.topPeak||0),r=Math.max(r,o?.botPeak||0)}return{occupants:i,peak:{topPeak:n,botPeak:r},...null!=t.group?{group:t.group}:{}}}),n=Xo();return i.forEach((t,e)=>{for(const o of t.occupants)n[o.id]=e}),{slots:i,slotByNode:n}}var _i=new Map,Pi=1e5,Li=1e-9;function $i(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function Ri(t,e){return qo(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function Ci(t){const e=new Map,o=new Map;for(const i of t)o.has(i.source)||o.set(i.source,new Set),e.has(i.target)||e.set(i.target,new Set),o.get(i.source).add(i.target),e.get(i.target).add(i.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...o].map(([t,e])=>[t,e.size]))}}function Ii(t){const e=new Map,o=new Map,i=(t,e,o,i)=>{let n=t.get(e);n||(n=new Map,t.set(e,n)),n.set(o,(n.get(o)??0)+i)};for(const n of t){const t=n.value>0&&Number.isFinite(n.value)?n.value:1;i(e,n.source,n.target,t),i(o,n.target,n.source,t)}const n=new Map,r=t=>{if(n.has(t))return;const i=e.get(t),r=o.get(t),s=new Map;for(const[t,e]of i??[])s.set(t,(s.get(t)??0)+e);for(const[t,e]of r??[])s.set(t,(s.get(t)??0)+e);if(1===s.size){const[e,o]=[...s][0];n.set(t,{partner:e,weight:o})}};for(const e of t)r(e.source),r(e.target);return n}function Ti(t,e,o){const i=o.get(t),n=o.get(e);return!i||!n||i.partner===n.partner||i.partner===e||n.partner===t}function Oi(t,e,o){return!!o.has(t)&&e.some(e=>!Ti(t,e,o))}function zi(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function Fi(t,e,o,i){if(12>=t.length||1>=i.slotCount)return i.assignment;const n=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Map),s=Ci(o);for(const t of o){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o||e===o)continue;const i=zi(t,s);r[e].set(o,(r[e].get(o)??0)+i),r[o].set(e,(r[o].get(e)??0)+i)}const a=Ii(o),c=t.map(t=>a.get(t)?.weight??0),l=Array.from({length:t.length},()=>new Map);let u=0;for(let o=0;t.length-1>o&&5e4>u;o++)if(a.has(t[o]))for(let i=o+1;t.length>i;i++){if(!a.has(t[i]))continue;if(e.conflicts(t[o],t[i]))continue;u++;const n=Math.min(c[o],c[i])||Math.max(c[o],c[i]),r=Ti(t[o],t[i],a)?n:-n;if(Math.abs(r)>Li&&(l[o].set(i,r),l[i].set(o,r),u>=5e4))break}const d=[...i.assignment],h=Array.from({length:i.slotCount},()=>[]);d.forEach((t,e)=>h[t].push(e));const f=(t,e,o)=>{const i=d[e],n=d[o];let r=0;const s=new Set;for(const a of[e,o])for(const[c,l]of t[a]){const t=c>a?`${a}:${c}`:`${c}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?n:i)===(c===e?n:c===o?i:d[c]);d[a]===d[c]!==u&&(r+=u?l:-l)}return r},p=(t,e,o)=>{let i=0;for(const[n,r]of t[e]){const t=o===d[n];d[e]===d[n]!==t&&(i+=t?r:-r)}return i},y=(t,e)=>t>Li||Li>=Math.abs(t)&&e>Li,g=(t,e,o,i)=>t>o+Li||Li>=Math.abs(t-o)&&e>i+Li;let m=0;for(let o=0;32>o&&Pi>m;o++){let o=null,i=-1,n=-1,s=-1,a=-1/0,c=-1/0;for(let u=0;t.length>u;u++){for(let f=0;h.length>f&&m++<Pi;f++){if(f===d[u])continue;if(!h[f].every(o=>!e.conflicts(t[u],t[o])))continue;const m=p(r,u,f),x=p(l,u,f);y(m,x)&&g(m,x,a,c)&&(o="move",i=u,n=-1,s=f,a=m,c=x)}if(m>=Pi)break}for(let u=0;t.length-1>u;u++){for(let p=u+1;t.length>p&&m++<Pi;p++){const m=d[u],x=d[p];if(m===x)continue;if(!h[x].every(o=>o===p||!e.conflicts(t[u],t[o])))continue;if(!h[m].every(o=>o===u||!e.conflicts(t[p],t[o])))continue;const b=f(r,u,p),v=f(l,u,p);y(b,v)&&g(b,v,a,c)&&(o="swap",i=u,n=p,s=-1,a=b,c=v)}if(m>=Pi)break}if(null==o||-1===i)break;if("move"===o){const t=d[i];h[t].splice(h[t].indexOf(i),1),h[s].push(i),d[i]=s;continue}const u=d[i],x=d[n];h[u].splice(h[u].indexOf(i),1,n),h[x].splice(h[x].indexOf(n),1,i),d[i]=x,d[n]=u}return d}function Ni(t,e){let o=1/0,i=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass>1e-9&&(o=Math.min(o,e.t),i=Math.max(i,e.t));return Number.isFinite(o)&&Number.isFinite(i)?(null!=e.start&&(o=Math.max(o,e.start)),null!=e.end&&(i=Math.min(i,e.end)),o>i?{start:null,end:null}:{start:o,end:i}):{start:null,end:null}}function Ei(t,e,o,i){const n=function(t,e,o,i){return`${t.map(t=>{const e=o[t.id],n=i[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,n?.start??"",n?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,o,i),r=_i.get(n);if(r)return Mi(r.slots,o,i);const s=Xo();for(const e of t)s[e.id]=Ni(o[e.id],i[e.id]);const a=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,o)=>e[t.id].start-e[o.id].start||e[t.id].end-e[o.id].end||qo(t.id,o.id)).map(t=>t.id)}(t,s),c=new Map(t.map(t=>[t.id,t])),l=new Map(t.map(t=>[t.id,t.group||void 0])),u=Ii(e),d=function(t,e,o,i,n,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),c=new Map(t.map(t=>[t,new Set]));for(const t of i)s.add(Ri(t.source,t.target)),a.get(t.target)?.add(t.source),c.get(t.source)?.add(t.target);const l=new Map,u=new Set,d=(t,e)=>{for(let o=0;t.length>o;o++)for(let i=o+1;t.length>i;i++){const n=Ri(t[o],t[i]);e instanceof Map?e.set(n,[t[o],t[i]]):e.add(n)}};for(const t of c.values())d([...t],l);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[i,n]]of l)u.has(t)&&($i(e[i],e[n])||$i(o[i],o[n])&&(h.add(i),h.add(n)));return{conflicts:(t,o)=>{const i=n.get(t),a=n.get(o);return null!=i&&null!=a&&i!==a||!(null!=i==(null!=a)||s.has(Ri(t,o))||r.has(t)&&r.has(o)&&Ti(t,o,r))||!!$i(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(Ri(t,o))}}}(a,s,i,e,l,u),h=function(t,e,o=new Map){const i=[],n=[];for(const r of t){let t=i.findIndex(t=>t.every(t=>!e.conflicts(r,t))&&!Oi(r,t,o));-1!==t||o.has(r)||(t=i.findIndex(t=>t.every(t=>!e.conflicts(r,t)))),-1===t&&(t=i.length,i.push([])),i[t].push(r),n.push(t)}return{assignment:n,slotCount:i.length}}(a,d,u),f=function(t,e,o,i){if(0===t.length||t.length>12||1>=i.slotCount)return i.assignment;const n=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Float64Array(t.length)),s=Array.from({length:t.length},()=>new Map),a=Array.from({length:t.length},()=>new Map),c=Ci(o);for(const t of o){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o||e===o)continue;const i=zi(t,c);r[e][o]+=i,r[o][e]+=i,a[e].set(o,(a[e].get(o)??0)+i),s[o].set(e,(s[o].get(e)??0)+i)}const l=Ii(o),u=t.map(t=>l.get(t)?.weight??0),d=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;t.length>e;e++)for(let o=e+1;t.length>o;o++){for(const[t,i]of s[e])d[e][o]+=Math.min(i,s[o].get(t)??0);for(const[t,i]of a[e])d[e][o]+=Math.min(i,a[o].get(t)??0);if(l.has(t[e])&&l.has(t[o])){const i=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=Ti(t[e],t[o],l)?i:-i}d[o][e]=d[e][o]}let h=[...i.assignment],f=(e=>{let o=0,i=0;for(let n=0;t.length>n;n++)for(let s=n+1;t.length>s;s++)e[n]===e[s]&&(o+=r[n][s],i+=d[n][s]);return{flow:o,affinity:i}})(h),p=0;const y=Array(t.length).fill(-1),g=Array.from({length:i.slotCount},()=>[]),m=(o,n,s,a)=>{if(p>=75e3)return;if(o===t.length)return p++,void((s>f.flow||s===f.flow&&a>f.affinity||s===f.flow&&a===f.affinity&&function(t,e){for(let o=0;Math.min(t.length,e.length)>o;o++)if(t[o]!==e[o])return e[o]>t[o];return e.length>t.length}(y,h))&&(h=[...y],f={flow:s,affinity:a}));const c=Math.min(n+1,i.slotCount-1);for(let i=0;c>=i;i++){if(g[i].some(i=>e.conflicts(t[o],t[i])))continue;let c=0,l=0;for(const t of g[i])c+=r[o][t],l+=d[o][t];if(y[o]=i,g[i].push(o),m(o+1,Math.max(n,i),s+c,a+l),g[i].pop(),y[o]=-1,p>=75e3)return}};return y[0]=0,g[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:Fi(a,d,e,h)}),p=new Map,y=f.map(t=>(p.has(t)||p.set(t,p.size),p.get(t))),g=Array.from({length:p.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=Xo();a.forEach((t,e)=>{const o=y[e],i=g[o];i.occupants.push({id:t,end:s[t].end??-1/0});const n=c.get(t)?.group;n&&(i.group=n),m[t]=o});for(const e of[...t].sort((t,e)=>qo(t.id,e.id)))null==m[e.id]&&(g[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of g){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||qo(t.id,e.id));for(const e of t.occupants){const i=o[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,i?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,i?.botPeak||0)}}const x={slots:g,slotByNode:m};return function(t,e){for(_i.has(t)&&_i.delete(t),_i.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(Xo(),e.slotByNode)});_i.size>12;){const t=_i.keys().next().value;if(null==t)break;_i.delete(t)}}(n,x),x}function Di(t){return t.topMass+t.botMass}function Bi(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>Di(e)<Di(t)?t:e,o[0]);let i=null;for(const o of t.samples){if(o.t>e)break;i=o}return i}function Wi(t,e,o,i,n,r,s=0){const a=new Map;for(const o of t){if(!o.group||!e[o.id])continue;const t=a.get(o.group)??[];t.push(o),a.set(o.group,t)}if(0===a.size||0>=r)return e;const c=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}]));for(const[t,l]of a){const a=o.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=n[u.occupants[0]?.id],f=n[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;const p=(h-u.peak.topPeak*r+(f+d.peak.botPeak*r))/2,y=[...new Set(l.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),g=new Map;for(const t of l)g.set(t.id,new Map);for(const t of y){const o=new Map;for(const n of l){const r=Bi(e[n.id],t);if(!r||1e-9>=Di(r))continue;const s=i[n.id];if(null==s)continue;const a=o.get(s)??[];a.push({node:n,sample:r}),o.set(s,a)}const a=[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>Di(t)))}));if(0===a.length)continue;let c=p-(a.reduce((t,e)=>t+e.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const e of a){for(const{node:o,sample:i}of e.active){const e=(c-n[o.id])/r+i.topMass-(i.boundaryOffset??0);g.get(o.id).set(t,e)}c+=e.mass*r+Math.max(0,s)}}for(const t of l){const o=e[t.id],i=c[t.id],n=g.get(t.id),r=[];for(const t of y){const e=n.get(t),i=o.samples.filter(e=>e.t===t);if(i.length>0){r.push(...i.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const s=Bi(o,t);null!=e&&s&&Di(s)>1e-9&&r.push({...s,t:t,boundaryOffset:(s.boundaryOffset??0)+e})}i.samples=r,i.localAttachments=new Map([...o.localAttachments].map(([t,e])=>{const o=n.get(e.time);return[t,{...e,...null!=o?{boundaryOffset:(e.boundaryOffset??0)+o}:{}}]}))}}return c}function ji(t,e,o,i,n){const{plotH:r,padding:s,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=n,y=Xo(),g=Xo();for(const e of t)y[e.id]=o[e.id].topPeak||0,g[e.id]=o[e.id].botPeak||0;const m="half"===u,x=Xo();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,o=Array.isArray(e.xExtent)?e.xExtent[1]:null;let n=null!=t&&Number.isFinite(t)?t:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const t of i.outgoing[e.id]){n>t.startTime&&(n=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&n>t.systemInTime&&(n=t.systemInTime);const e=m?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of i.incoming[e.id]){const e=m?(t.startTime+t.endTime)/2:t.startTime;n>e&&(n=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}x[e.id]={start:Number.isFinite(n)?n:null,end:Number.isFinite(r)?r:null}}let b=Xo(),v=[],w=[];if(n.frozenSlots){const t=Mi(n.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(Go)}else if("reuse"===c){const i=Ei(t,e,o,x);v=i.slots,b=i.slotByNode}else t.forEach((t,e)=>{v.push({occupants:[{id:t.id,end:x[t.id]?.end??-1/0}],peak:{topPeak:y[t.id],botPeak:g[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});gi(v,b),0===w.length&&(w=v.map(Go));let k=null;n.frozenSlots||(n.fixedSlotOrder?function(t,e,o){const i=new Map(o.map((t,e)=>[t,e]));di(t,e,[...t].sort((t,e)=>(i.get(Go(t))??1/0)-(i.get(Go(e))??1/0)||qo(Go(t),Go(e))))}(v,b,n.fixedSlotOrder):n.runOrdering&&l&&"insertion"!==l&&(k=Ai(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:l,ribbonLane:f,domain:p}))),gi(v,b);const S=Zo(t,e,o,v,b,{plotH:r,padding:s,valueScale:a,stackValueScale:n.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((t,e)=>t+e,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,L=k?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:S.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(Go),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function Yi(t){const{sx:e,sTop:o,sBot:i,tx:n,tTop:r,tBot:s,cp1X:a,cp2X:c}=t,l=(o+i)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${c},${r} ${n},${r}`,`L${n},${s}`,`C${c},${s} ${a},${i} ${e},${i}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:l},{x:a,y:l},{x:c,y:u},{x:n,y:u}],halfWidth:(i-o)/2}}}function Xi(t,e,o,i,n,r,s,a,c={}){const l=n,u=t=>a?Math.max(a[0],Math.min(a[1],t)):t;let d=r(u(t.time));const h=r(u(o.time)),f=t.value*l,p=o.value*l,y=e+(t.boundaryOffset??0)*l,g=i+(o.boundaryOffset??0)*l,m=t.sideMassBefore*l,x=o.sideMassAfter*l;let b,v,w,k;"top"===t.side?(b=y-m,v=b+f):(v=y+m,b=v-f),"top"===o.side?(w=g-x,k=w+p):(k=g+x,w=k-p);const S=c.sourceRunwayStart,A=c.minRun,M=Math.abs((w+k)/2-(b+v)/2),_=h-d,P="number"==typeof S&&Number.isFinite(S),L="number"==typeof A&&Number.isFinite(A)&&A>0;if(P&&M>1e-9&&_>0&&("auto"===A||L)){const e="source"===s?.85:"target"===s?.15:.5,o="auto"===A?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(e*e,(1-e)*(1-e))))):A;if(o>_){const e=r(u(Math.min(S,t.time)));Number.isFinite(e)&&(d=Math.min(d,Math.max(Math.min(d,e),h-o)))}}const $="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:b,sBot:v,tx:h,tTop:w,tBot:k,cp1X:$,cp2X:$}}function qi(t){return Math.max(18,11*t.length*.58)}function Gi(t){const e=1.22*qi(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function Vi(t,e){const o=t.labelX-qi(t.labelText),i=e.labelX-qi(e.labelText);return e.labelX+3>=o&&t.labelX+3>=i}var Hi=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function Ui(t){return t.replace(Hi,(t,e,o)=>`${o},${e}`)}function Ki(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function Zi(t){return{...t,pathD:Ui(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}import{jsx as Qi,jsxs as Ji}from"react/jsx-runtime";function tn(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function en(t,e){const{background:o="transparent",stroke:i="#000",lineWidth:n=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,c=Math.max(8,Math.ceil(2*r));return Ji("pattern",{id:e,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Qi("rect",{width:c,height:c,fill:o}),Qi("line",{x1:0,y1:0,x2:0,y2:c,stroke:i,strokeWidth:n,strokeOpacity:a}),Qi("line",{x1:r,y1:0,x2:r,y2:c,stroke:i,strokeWidth:n,strokeOpacity:a})]},e)}function on(t){const{nodes:e,edges:o,domain:i,plotW:n,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:c,colorOf:l,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:y="raw",styleRules:g,colorBy:m,valueAccessor:x,usageMode:b="static"}=t,v="vertical"===d?r:n,w="vertical"===d?n:r,k=function(t,e,o,i={}){const n=zo(i.usageMode??"static"),r=[],s=new Set;for(const e of t)s.has(e.id)&&r.push({kind:"duplicate-node",id:e.id,severity:n.duplicateIds}),s.add(e.id);const a=new Set,c=Array.isArray(o)&&2===o.length,l=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]);c&&l&&l&&o[1]>=o[0]||r.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||r.push({kind:"invalid-node-time",id:e.id}));for(const t of e)a.has(t.id)&&r.push({kind:"duplicate-edge",id:t.id,severity:n.duplicateIds}),a.add(t.id),s.has(t.source)||r.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),s.has(t.target)||r.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&r.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),Number.isFinite(t.value)&&t.value>0||r.push({kind:"invalid-value",id:t.id}),t.startTime>t.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):r.push({kind:"invalid-edge-time",id:t.id});return r}(e,o,i,{usageMode:b}),{fatal:S,warnings:A}=function(t){const e=[],o=[];for(const i of t)"fatal"===No(i)?e.push(i):o.push(i);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==zo(o).invalidSystemTime)return t;const i=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===i.size?t:t.map(t=>{if(!i.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}(o,k,b),_=To().domain(i).range([0,v]);if(S.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:S,warnings:A,xScale:_};const P=function(t,e,o){const{plotH:i,pairing:n="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:c,lanePlacement:l="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=o,p=Number.isFinite(d)?Math.max(0,d):0,y=function(t,e){const o=Xo(),i=Xo();for(const e of t)o[e.id]=[],i[e.id]=[];for(const t of e)i[t.source]&&i[t.source].push(t),o[t.target]&&o[t.target].push(t);return{incoming:o,outgoing:i}}(t,e),g=function(t,e,o,i="temporal"){const n="temporal"===i?(t,e)=>t.endTime-e.endTime||qo(t.id,e.id):(t,e)=>e.value-t.value||qo(t.id,e.id),r="temporal"===i?(t,e)=>t.startTime-e.startTime||qo(t.id,e.id):(t,e)=>e.value-t.value||qo(t.id,e.id),s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const o=new Map;for(const i of t){const t=i[e];o.has(t)||o.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const n=o.get(t);n.edges.push(i),n.total+=i.value,n.earliestStart=Math.min(n.earliestStart,i.startTime),n.latestEnd=Math.max(n.latestEnd,i.endTime)}const s=[...o.values()];s.sort("temporal"===i?(t,o)=>"target"===e?t.earliestStart-o.earliestStart||qo(t.partner,o.partner):t.latestEnd-o.latestEnd||qo(t.partner,o.partner):(t,e)=>e.total-t.total||qo(t.partner,e.partner));for(const t of s)t.edges.sort("target"===e?r:n);return s};for(const e of t){const t=o.outgoing[e.id],i=o.incoming[e.id];if(0===i.length)a(t,"target").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=o});else if(0===t.length)a(i,"source").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=o});else{const e=a(i,"source"),o=a(t,"target"),n=Math.max(e.length,o.length);for(let t=0;n>t;t++){const i=t%2==0?"top":"bot";if(e[t])for(const o of e[t].edges)s.get(o.id).targetSide=i;if(o[t])for(const e of o[t].edges)s.get(e.id).sourceSide=i}}}return s}(t,e,y,n);let m=Xo();for(const e of t)m[e.id]=li(e,y,g,void 0,u);const x=ji(t,e,m,y,{plotH:i,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),b=x.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),v=new Set;for(const t of e){const e=x.slotByNode[t.source],o=x.slotByNode[t.target];if(void 0===e||void 0===o)continue;const i=g.get(t.id);e!==o?e>o?(i.sourceSide="top",i.targetSide="bot"):(i.sourceSide="bot",i.targetSide="top"):(v.add(t.id),i.sourceSide="bot",i.targetSide="bot")}for(const e of t){const t=y.outgoing[e.id],o=y.incoming[e.id],i=new Set(t.map(t=>g.get(t.id).sourceSide)),n=new Set(o.map(t=>g.get(t.id).targetSide));if(1===i.size&&o.length>0){const t=[...i][0];for(const e of o)x.slotByNode[e.source]===x.slotByNode[e.target]&&(g.get(e.id).targetSide=t)}if(1===n.size&&t.length>0){const e=[...n][0];for(const o of t)x.slotByNode[o.source]===x.slotByNode[o.target]&&(g.get(o.id).sourceSide=e)}}!function(t,e,o){const i=new Map,n=[];for(const e of t)n.push({time:e.startTime,kind:"out",edge:e}),n.push({time:e.endTime,kind:"in",edge:e});n.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||qo(t.edge.id,e.edge.id));const r=t=>{let e=i.get(t);return e||(e={top:0,bot:0},i.set(t,e)),e},s=(t,e,o)=>{const i="top"===e?"bot":"top",n=Math.min(o,t[e]);t[e]-=n;const r=o-n;r>0&&(t[i]=Math.max(0,t[i]-r))};for(const t of n){const{edge:i}=t;if("in"===t.kind){const t=e.get(i.id)?.targetSide??"bot";r(i.target)[t]+=i.value;continue}const n=r(i.source),a=e.get(i.id);let c=a.sourceSide??"bot";if(o[i.source]===o[i.target]){const t=n.top>=i.value,e=n.bot>=i.value;t!==e?c=t?"top":"bot":t||e||n.top===n.bot||(c=n.top>n.bot?"top":"bot"),a.sourceSide=c,a.targetSide=c}s(n,c,i.value)}}(e,g,x.slotByNode),function(t,e,o,i){for(const n of t){const t=e.incoming[n.id],r=e.outgoing[n.id];if(0===t.length||0===r.length)continue;const s=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const i of t)"top"===o.get(i.id).targetSide?e.inTop+=i.value:e.inBot+=i.value;for(const t of r)"top"===o.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},a=(t,e)=>{const n=s(),a="top"===t?n.outTop-n.inTop:n.outBot-n.inBot,c="top"===e?n.inTop-n.outTop:n.inBot-n.outBot;if(0>=a||0>=c)return!1;const l=Math.min(a,c),u=r.filter(e=>!i.has(e.id)&&o.get(e.id).sourceSide===t&&l>=e.value).sort((t,e)=>e.value-t.value||qo(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let c=r.length+1;for(;c-- >0&&(a("top","bot")||a("bot","top")););}}(t,y,g,v),m=Xo();for(const e of t)m[e.id]=li(e,y,g,void 0,u);const w=ji(t,e,m,y,{plotH:i,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((t,e,o)=>t+(null!=e.group&&e.group===w.slots[o+1].group?1:0),0),A=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*i-S*p)/A),_=2*M+Vo(w.slots,M,p).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(i-_)/k):1,L=Number.isFinite(c)&&c>0?Math.min(P,c):P;let $=ji(t,e,m,y,{plotH:i,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P});const R=Number.isFinite(c)&&c>0&&P>c+1e-12;if("insertion"!==s&&("hug"===l||R)&&$.slots.length>1&&(Ai(t,e,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:i,padding:M,valueScale:L,groupPadding:p,laneOrder:s,ribbonLane:h,domain:f,lanePlacement:l,mode:"geometry-refine"}),$=ji(t,e,m,y,{plotH:i,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Go),lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})),function(t,e){const o=(t,o)=>{for(const i of t){const t=new Map;for(const n of i){const i=`${("out"===o?e.get(n.id)?.sourceSide:e.get(n.id)?.targetSide)??""}\0${"out"===o?n.startTime:n.endTime}`,r="out"===o?`${n.target}\0${n.endTime}`:`${n.source}\0${n.startTime}`,s=t.get(i);if(null!=s&&s!==r)return!0;t.set(i,r)}}return!1};return o(Object.values(t.outgoing),"out")||o(Object.values(t.incoming),"in")}(y,g)){const o=function(t,e,o,i){const n=new Map;for(const r of t){const t=e[r.source]?.localAttachments.get(r.id),s=e[r.target]?.localAttachments.get(r.id),a=o[r.source],c=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(c)))continue;const l=ci(t,a,i),u=ci(s,c,i);n.set(r.id,{source:(l[0]+l[1])/2,target:(u[0]+u[1])/2})}return n}(e,m,$.centerlines,L);m=Xo();for(const e of t)m[e.id]=li(e,y,g,o,u);$=ji(t,e,m,y,{plotH:i,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Go),lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}const C=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),I=[...$.slots].sort((t,e)=>(C.get(Go(t))??1/0)-(C.get(Go(e))??1/0)||qo(Go(t),Go(e))),T=Xo();I.forEach((t,e)=>{for(const o of t.occupants)T[o.id]=e});const O=Zo(t,e,m,I,T,{plotH:i,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),z=Wi(t,m,I,T,O.centerlines,L,p),F=ri(xi(T,e),bi(T,e),e,z,I,T,O.centerlines,$.laneLifetime,L,O.verticalUtilization,h,f);m=Wi(t,m,$.slots,$.slotByNode,$.centerlines,L,p);const N=ri(xi($.slotByNode,e),bi($.slotByNode,e),e,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,f);return{nodeData:m,sides:g,valueScale:L,padding:M,compressedPadding:12>M,centerlines:$.centerlines,laneLifetime:$.laneLifetime,slots:$.slots,slotByNode:$.slotByNode,crossingsBefore:"insertion"===s?null:F.crossings,crossingsAfter:"insertion"===s?null:N.crossings,lengthBefore:"insertion"===s?null:F.weightedLength,lengthAfter:"insertion"===s?null:N.weightedLength,layoutQualityBefore:F,layoutQuality:N}}(e,M,{plotH:w,...u,ribbonLane:s,domain:i}),{centerlines:L,nodeData:$,valueScale:R}=P,C=nt(m,x),I=[],T=[],O=0===a?new Map:function(t,e,o){const i=new Set(e.map(t=>t.target)),n=new Map(t.map(t=>[t.id,t])),r=new Map;for(const t of e){if(i.has(t.source))continue;const e=r.get(t.source)??[];e.push(t),r.set(t.source,e)}const s=new Map;for(const e of t){if(!e.group)continue;const t=s.get(e.group)??[];t.push(e),s.set(e.group,t)}const a=new Set;for(const[t,e]of s){const o=e.flatMap(t=>r.get(t.id)??[]),n=new Set(o.map(t=>t.startTime));o.length>0&&1===n.size&&e.every(t=>{const e=t.xExtent?.[0],n=o[0].startTime;return!i.has(t.id)&&(r.get(t.id)?.length??0)>0&&Number.isFinite(e)&&n>e})&&a.add(t)}const c=new Map;for(const[t,e]of r){const i=n.get(t);if(i?.group&&!a.has(i.group))continue;const r=i?.xExtent?.[0],s=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),l=s[0]?.startTime-1;let u=null;for(let t=0;s.length>t;){const e=s[t].startTime;let i=t+1;for(;s.length>i&&s[i].startTime===e;)i++;for(let e=t;i>e;e++){const t=s[e],i=Number.isFinite(r)&&t.startTime>r,n=Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime;if(!i&&!n)continue;let a=o[0];i&&(a=Math.max(a,r)),n&&(a=Math.max(a,t.systemInTime)),!i&&n&&Number.isFinite(l)&&(a=Math.max(a,l)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&c.set(t.id,a)}u=e,t=i}}for(const[t,e]of s){if(!a.has(t))continue;const o=e.flatMap(t=>r.get(t.id)??[]);if(!o.every(t=>c.has(t.id))){for(const t of o)c.delete(t.id);continue}const i=Math.max(...o.map(t=>c.get(t.id)));for(const t of o)c.set(t.id,i)}return c}(e,M,i),z=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),F=new Map;for(const t of M){const e=$[t.source]?.localAttachments.get(t.id),o=$[t.target]?.localAttachments.get(t.id);e&&o&&F.set(t.id,Xi(e,L[t.source],o,L[t.target],R,_,s,i,{minRun:a,sourceRunwayStart:O.get(t.id)}))}const N=function(t,e,o,i,n,r){const s=new Map(e),a=new Map;for(const e of t){const t=r?.get(e.source),o=null==t?"node:"+e.source:"group:"+t,i=a.get(o)??new Map,n=i.get(e.startTime)??[];n.push(e),i.set(e.startTime,n),a.set(o,i)}for(const t of a.values())for(const[r,a]of t){if(!a.some(t=>o.has(t.id)))continue;const t=a.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const c=i(r),l=Math.min(...t.map(t=>t.sx));if(l>=c-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?c:Math.min(c,i(e))})),d=Math.min(c,Math.max(l,u));for(const t of a){const o=e.get(t.id),i=d+(o.tx-d)*("source"===n?.85:"target"===n?.15:.5);s.set(t.id,{...o,sx:d,cp1X:i,cp2X:i})}}return s}(M,F,O,_,s,z),E=function(t,e,o,i,n){const r=new Map;for(const s of t){if(!o.has(s.id))continue;const t=e.get(s.id);if(!t||t.sx>=i(s.startTime)-1e-9)continue;const a=n(t.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,N,O,_,t=>i[0]+t/v*(i[1]-i[0])),D=function(t,e,o){const i=new Map,n=new Map;for(const[t,e]of o??[]){const o=n.get(e)??[];o.push(t),n.set(e,o)}for(const r of t){const t=e.get(r.id);if(null==t||!Number.isFinite(t)||t>=r.startTime)continue;const s=o?.get(r.source),a=null==s?[r.source]:n.get(s)??[r.source];for(const e of a){const o=i.get(e)??new Map,n=o.get(r.startTime);o.set(r.startTime,null==n?t:Math.min(n,t)),i.set(e,o)}}return i}(M,E,z);e.forEach((t,e)=>{const o=$[t.id];if(!o||0===o.samples.length)return;const n=(r=o.samples,(s=D.get(t.id))&&0!==s.size?r.map(t=>{const e=s.get(t.t);return null==e?t:{...t,t:e}}):r);var r,s;const a=function(t,e,o,i,n){if(0===t.length)return null;const r=ai(t,n),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,c=t=>s(t)+r[t].botMass*o;let l=`M${i(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)l+=` L${i(r[t].t)},${a(t)}`;l+=` L${i(r[r.length-1].t)},${c(r.length-1)}`;for(let t=r.length-2;t>=0;t--)l+=` L${i(r[t].t)},${c(t)}`;return l+" Z"}(n,L[t.id],R,_,i);if(!a)return;const c=ai(n,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],h=L[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let f,p,y=l(t.id,e),m=y,x=.5;const b=t.__raw??t;if(g&&g.length>0){const t=at(b,g,C(b));"string"==typeof t.fill?y=t.fill:null!=t.fill&&tn(t.fill)&&(p=t.fill,y=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:y),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(x=t.strokeWidth),"number"==typeof t.fillOpacity&&(f=t.fillOpacity),"number"==typeof t.opacity&&null==f&&(f=t.opacity)}const v=function(t,e,o,i,n,r){const s=o.nodeData[t];if(!s||0===s.samples.length)return[];const a=o.valueScale,c=o.centerlines[t],l=ai(s.samples,n),u=l.find(t=>t.topMass+t.botMass>0)||l[0],d=[...l].reverse().find(t=>t.topMass+t.botMass>0)||l[l.length-1],h=i(u.t),f=i(d.t),p=t=>i(si(t,n)),y=[],g=(t,e,o,i)=>`M${t},${e} L${o},${e} L${o},${i} L${t},${i} Z`;for(const o of e){if(o.source===t&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const t=s.localAttachments.get(o.id),e=r?.get(o.id)??o.startTime;if(t&&"out"===t.kind&&e>o.systemInTime){const i=p(o.systemInTime),r=p(e),s=null!=n&&n[0]>o.systemInTime,l=s?i:i-20,u=s?Math.min(r,i+20):i,d=Math.max(h,l);if(r>d){const[e,o]=ci(t,c,a);y.push({pathD:g(d,e,r,o),x0:l,x1:u,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=s.localAttachments.get(o.id);if(t&&"in"===t.kind&&o.systemOutTime>o.endTime){const e=p(o.systemOutTime),i=p(o.endTime),n=e+20,r=Math.min(f,n);if(r>i){const[o,s]=ci(t,c,a);y.push({pathD:g(i,o,r,s),x0:e,x1:n,from:1,to:0})}}}}return y}(t.id,M,P,_,i,E);I.push({id:t.id,pathD:a,fill:y,stroke:m,strokeWidth:x,...null!=f&&{fillOpacity:f},...p&&{hatchFill:p},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&t.xExtent?t.xExtent[0]:u.t)-4,labelY:h,labelText:t.label??t.id})});const B=new Map;e.forEach((t,e)=>B.set(t.id,e)),M.forEach(t=>{const e=N.get(t.id);if(!e)return;const o=B.get(t.source)??0,i=l(t.source,o),{pathD:n,bezier:r}=Yi(e),s=t.__raw??t,a="function"==typeof c?Number(c(s)):c,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;T.push({id:t.id,pathD:n,fill:i,opacity:u,rawDatum:s,bezier:r})});const W=function(t,e,o){const i=t.map(t=>({...t})),n=new Map;for(const t of i){const o=e[t.id];if(null==o)continue;const i=n.get(o)??[];i.push(t),n.set(o,i)}const r=t=>{if(2>t.length)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,i=(t.length-1)/2;t.forEach((t,n)=>{t.labelY=Math.max(8,Math.min(o-8,e+16*(n-i)))})};for(const t of n.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],o=-1/0;for(const i of t){const t=i.labelX-qi(i.labelText);e.length>0&&t>o+3&&(r(e),e=[],o=-1/0),e.push(i),o=Math.max(o,i.labelX)}r(e)}return function(t,e){const o=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;3>t;t+=1){for(let t=0;o.length>t;t+=1){let e=8;for(let i=0;t>i;i+=1)Vi(o[t],o[i])&&(e=Math.max(e,o[i].labelY+16));o[t].labelY=Math.max(o[t].labelY,e)}for(let t=o.length-1;t>=0;t-=1){let i=e-8;for(let e=t+1;o.length>e;e+=1)Vi(o[t],o[e])&&(i=Math.min(i,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,i)}}}(i,o),i}(I,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ui(t.pathD),gradientStubs:t.gradientStubs?.map(Zi),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,d)),j="vertical"===d?function(t,e,o){const i=t.map(t=>({...t}));for(const t of i){const o=1.22*qi(t.labelText)+4;t.labelX=e-4>o?Math.max(o/2+2,Math.min(e-o/2-2,t.labelX)):e/2}const n=[],r=[...i].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of r){const e=n[n.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?n.push([t]):e.push(t)}for(const t of n){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],i=new Map;for(const o of t){const[t,n]=Gi(o);let r=e.findIndex(e=>t>e+8);-1===r&&(r=e.length),e[r]=n,i.set(o,r)}const n=t.reduce((t,e)=>t+e.labelY,0)/t.length,r=14*e.length+8>n;for(const e of t){const t=i.get(e)??0;e.labelY=r?Math.min(o-8,12+14*t):Math.max(8,n-14*t)}}return i}(W,n,r):W,Y=new Map;if(null!=f)for(const t of e){const e=t.__raw??t,o="function"==typeof f?f(e):Number(e[f]);Number.isFinite(o)&&Y.set(t.id,o)}const X=function(t,e,o,i,n={}){if(!1===i)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===i)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(t.length,Math.floor(Math.max(1,e*o)/14e3)));Number.isFinite(n.maxLabels)&&n.maxLabels>=0&&(r=Math.min(r,Math.floor(n.maxLabels)));const s=t.map((t,e)=>{const o=n.priorityById?.get(t.id),i=Math.abs(t.labelY);return{band:t,index:e,score:null!=o&&Number.isFinite(o)?1e6*o+qi(t.labelText):qi(t.labelText)+.01*i}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),a=new Set(s.slice(0,r).map(t=>t.band.id));return t.map(t=>a.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(j,n,r,h,{...Y.size>0&&{priorityById:Y},...null!=p&&{maxLabels:p}});return{layout:P,layoutConfig:{bands:X,ribbons:T.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ui(t.pathD),bezier:Ki(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:y},issues:[],warnings:A,xScale:_}}import{Fragment as nn,jsx as rn,jsxs as sn}from"react/jsx-runtime";var an="var(--semiotic-grid, #94a3b8)",cn="var(--semiotic-text-secondary, #475569)",ln="var(--semiotic-text-secondary, #94a3b8)",un=.22;function dn(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var hn=t=>{const{bands:e=[],ribbons:o=[],showLabels:i=!0,selectionDatum:n="raw"}=t.config,r=t.selection??null,s=[];for(const t of o){const e={__kind:"ribbon",data:t.rawDatum,id:t.id},o=!dn(e,r,n);s.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:o?Math.min(t.opacity,un):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!dn({__kind:"band",data:t.rawDatum,id:t.id},r,n);for(let o=0;t.gradientStubs.length>o;o++){const i=t.gradientStubs[o];s.push({type:"bezier",pathD:i.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:e?un:t.fillOpacity??.86,stroke:"none"},_gradient:{x0:i.x0,x1:i.x1,...null!=i.y0&&{y0:i.y0},...null!=i.y1&&{y1:i.y1},from:i.from,to:i.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${o}`}})}}for(const t of e){const e=!(!t.gradientStubs||0>=t.gradientStubs.length),o={__kind:"band",data:t.rawDatum,id:t.id},i=!dn(o,r,n);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:i?un:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...i&&e?{opacity:un}:{}},datum:o})}const a=i?e.flatMap(t=>{const e=t.labelDeferred&&t.labelFullText?.trim(),o=t.labelText.trim().length>0,i=e&&r?.isActive&&dn({__kind:"band",data:t.rawDatum,id:t.id},r,n),s=o?t.labelText:i?t.labelFullText:"";return s.trim()?[{x:t.labelX,y:t.labelY,text:s,anchor:t.labelAnchor??"end",baseline:t.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:s,labels:a}};function fn(t,e){if(!t)return[];const o=[],i=t=>{o.push(t);const n="function"==typeof e?e(t):t[e];n&&Array.isArray(n)&&n.forEach(i)};return i(t),o}function pn(t,e,o,i){if(t&&t.length>0)return t;const n=new Set;return e.forEach(t=>{const e="function"==typeof o?o(t):t[o],r="function"==typeof i?i(t):t[i];n.add(e),n.add(r)}),Array.from(n).map(t=>({id:t}))}function yn(t,e,o={}){return et(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var gn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{if(!(e||Array.isArray(n.styleRules)&&n.styleRules.length>0||i.nodeStyle||n.nodeStyle||tt(gt(n))))return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,showLabels:n.showLabels,colorBy:e,edgeColorBy:n.edgeColorBy,colorScheme:o,...i};const r=Array.isArray(n.edges)?n.edges:[],s=Array.isArray(n.nodes)&&n.nodes.length>0?n.nodes:pn([],r,n.sourceAccessor||"source",n.targetAccessor||"target"),a=At(i.theme).colors.categorical,c=G(o,a),l="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?Q(u,l,o??i.colorScheme??a):void 0,h=new Map,f=n.nodeIdAccessor||n.nodeIDAccessor||"id",p=(t,o)=>{const i=t?.data||t;let r;if(e)r=K(i,e,d);else{const e=(t.id??i?.[f]??"")+"";h.has(e)||h.set(e,h.size);const n=t.index??o??h.get(e);r=c[n%c.length]}return{fill:r,stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},y=lt(n.styleRules,e,n.valueAccessor);return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,showLabels:n.showLabels,colorBy:e,edgeColorBy:n.edgeColorBy,colorScheme:o,nodeStyle:et(n.nodeStyle||(y?(t,e)=>({...p(t,e),...y(t,e)}):p),gt(n)),...i}}},mn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=function(t){if(void 0!==t.edgeStyle)return t.edgeStyle;const{edgeWidth:e,edgeColor:o,edgeOpacity:i}=t,n=t.strokeWidth??1;return void 0!==e||void 0!==o||void 0!==i||void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity?r=>{const s=r?.data||r;let a=n;if("number"==typeof e)a=e;else if("function"==typeof e)a=e(s);else if("string"==typeof e){const t=s?.[e],o="number"==typeof t?t:Number(t);a=Number.isFinite(o)&&o>0?o:n}return{stroke:o??t.stroke??"#999",strokeWidth:a,opacity:i??t.opacity??.6}}:void 0}(n),s=At(i.theme).colors.categorical,a=new Map,c=n.nodeStyle??(t=>({fill:e?K(t?.data||t,e,void 0):ve(void 0,s,o,void 0,a),..."number"==typeof n.nodeSize&&{r:n.nodeSize}})),l=lt(n.styleRules,e,"number"==typeof n.nodeSize?void 0:n.nodeSize),u=et(l?(t,e)=>({...c(t),...l(t,e)}):c,{stroke:n.nodeStroke??n.stroke,strokeWidth:n.nodeStrokeWidth??n.strokeWidth,opacity:n.opacity});return{chartType:"force",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,colorBy:e,colorScheme:o,iterations:n.iterations,forceStrength:n.forceStrength,showLabels:n.showLabels??!1,nodeLabel:n.nodeLabel,nodeSize:n.nodeSize??8,nodeSizeRange:n.nodeSizeRange,nodeStyle:u,edgeStyle:r,...i}}},xn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=At(i.theme).colors.categorical,s=new Map,a=fn(t??null,n.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrCirclePackColorBy:c(t)})):a,u=c?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?Q(l,u,o??i.colorScheme??r):void 0,h=i.nodeStyle||n.nodeStyle;return{chartType:"circlepack",data:t,childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:e,colorByDepth:n.colorByDepth,showLabels:n.showLabels,nodeLabel:n.showLabels??i.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},colorScheme:o,...i,nodeStyle:yn(t=>{const i=t?.data||t;return{fill:n.colorByDepth?H[Number(t?.depth||0)%H.length]:e?c?K({__ssrCirclePackColorBy:c(i)},"__ssrCirclePackColorBy",d??void 0):K(i,e,d??void 0):ve(void 0,r,o,void 0,s),fillOpacity:n.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,gt(n))}}},bn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=t??n.data,s=n.childrenAccessor||"children",a=n.nodeIdAccessor||n.nodeIDAccessor||"name",c=At(i.theme).colors.categorical,l=o??i.colorScheme??c,u=G(l,c),d=fn(r,s),h="__ssrOrbitColorBy",f="function"==typeof e?e:null,p=e?Q(f?d.map(t=>({[h]:f(t)})):d,f?h:e,l):void 0;return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:l,colorByDepth:n.colorByDepth??!1,nodeSize:n.nodeRadius??6,nodeLabel:n.showLabels?a:void 0,showLabels:n.showLabels??!1,orbitMode:n.orbitMode??"flat",orbitSize:n.orbitSize??2.95,orbitSpeed:n.speed??.25,orbitRevolution:n.revolution,orbitRevolutionStyle:n.revolutionStyle,orbitEccentricity:n.eccentricity??1,orbitShowRings:n.showRings??!0,orbitAnimated:!1,nodeStyle:et(t=>{const o=t.data||t,i=Number(t.depth??0);return{fill:n.colorByDepth?0===i?u[0]:H[i%H.length]:e?f?K({[h]:f(o)},h,p):K(o,e,p):u[0],stroke:"#fff",strokeWidth:1,opacity:0===i?1:.85}},gt(n)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...i}}},vn={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,i,n)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=n.sourceAccessor||"source",a=n.targetAccessor||"target",c=n.valueAccessor||"value",l=n.nodeIdAccessor||"id",u=n.startTimeAccessor||"startTime",d=n.endTimeAccessor||"endTime",h=n.systemInTimeAccessor,f=n.systemOutTimeAccessor,p=n.xExtentAccessor||"xExtent",y=n.groupBy,g=n.edgeIdAccessor||"id",m=(t,e)=>"function"==typeof t?t(e):e[t],x=Array.isArray(n.edges)?n.edges:[],b=Array.isArray(n.nodes)?n.nodes:[],v=b.length>0?b:pn([],x,s,a),k=[r(n.domain?.[0]),r(n.domain?.[1])],S=v.map(t=>{const e=m(l,t)+"",o=m(p,t),i=n.nodeLabel?m(n.nodeLabel,t):e,s={id:e,label:null==i?e:i+"",__raw:t},a=y?m(y,t):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(s.xExtent=[t,e])}return s}),A=x.map((t,e)=>{const o=m(g,t),i={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(c,t)),startTime:r(m(u,t)),endTime:r(m(d,t)),__raw:t};if(h){const e=r(m(h,t));Number.isFinite(e)&&(i.systemInTime=e)}if(f){const e=r(m(f,t));Number.isFinite(e)&&(i.systemOutTime=e)}return i}),[M,_]=i.size??[600,400],P=i.margin,L="vertical"===n.orientation?"vertical":"horizontal",$=function(t,e,o,i="horizontal"){return"vertical"===i?{top:t?38:e?28:16,right:24,bottom:24,left:o?72:24}:{top:t?30:e?24:8,right:80,bottom:o?28:8,left:80}}(!!i.title,!!n.showQualityReadout,Array.isArray(n.axisTicks)&&n.axisTicks.length>0,L),R={...$,...P},C=(i.showLegend??!!e)&&!!e,I=i.legendPosition??"right";C&&("right"===I?R.right=Math.max(R.right,140):"left"===I?R.left=Math.max(R.left,140):"top"===I?R.top=Math.max(R.top,50):"bottom"===I&&(R.bottom=Math.max(R.bottom,80)));const T=R,O=M-T.left-T.right,z=_-T.top-T.bottom,F=G(o,At(i.theme).colors.categorical,w),N="function"==typeof e?e:null,E=N?v.map(t=>({_cat:N(t)})):v,D=N?"_cat":"string"==typeof e?e:void 0,B=o??[...F],W=D?Q(E,D,B):null,j=new Map;for(const t of S)j.set(t.id,t.__raw);const Y=(t,o)=>{if(e&&j.has(t)){const o=j.get(t);return N?K({_cat:N(o)},"_cat",W??void 0):K(o,"string"==typeof e?e:"id",W??void 0)}return F[o%F.length]},X=Jt(C&&e?(()=>{const t=new Map;v.forEach((o,i)=>{const n=m(e,o),r=null==n?"":n+"";r&&!t.has(r)&&t.set(r,{label:r,color:Y(m(l,o)+"",i)})});const o=Array.from(t.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:t=>{const e=t.color||"#333";return{fill:e,stroke:e}}}]}:void 0})():void 0,i.legend),q=!1!==n.showLabels&&("auto"!==n.showLabels||"auto"),{layout:V,layoutConfig:H,issues:U,xScale:Z}=on({nodes:S,edges:A,domain:k,plotW:O,plotH:z,orientation:L,ribbonLane:n.ribbonLane||"both",ribbonMinRun:"auto"===n.ribbonMinRun||"number"==typeof n.ribbonMinRun?n.ribbonMinRun:0,edgeOpacity:"number"==typeof n.edgeOpacity?n.edgeOpacity:.35,colorOf:Y,showLabels:q,styleRules:n.styleRules,colorBy:e,valueAccessor:c,layoutOpts:{pairing:n.pairing||"temporal",packing:n.packing||"reuse",laneOrder:n.laneOrder||"crossing-min",lifetimeMode:n.lifetimeMode||"half",maxValueScale:"number"==typeof n.maxValueScale?n.maxValueScale:void 0,lanePlacement:n.lanePlacement||"stack",nodeSizing:n.nodeSizing||"temporal",groupPadding:"number"==typeof n.groupPadding?n.groupPadding:0}});if(U.length>0){const t=U.map(Eo).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const J=V?function(t){const e=t.layout,o=t.nodes,i=t.orientation,n=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,c=t.showQualityReadout??!1,l=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,f=t.toTime,p=t.xScale,{centerlines:y,laneLifetime:g,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:S}=e;let A=null,M=null;for(const t of o){const e=g[t.id];if(!e||null===e.start||null===e.end)continue;const o=p(e.start),i=p(e.end);(null===A||A>o)&&(A=o),(null===M||i>M)&&(M=i)}const _=t=>Math.max(0,Math.min(s,t)),P=_(A??0),L=Math.max(P,_(M??s)),$=a.map((t,e)=>({tick:t,index:e,coordinate:p(f(t.date))})).filter(({coordinate:t})=>t>=P-.5&&L+.5>=t),R=null!==(w??null)&&null!=k&&null!=S,C=c&&(R||u.length>0)?sn("g",{fill:ln,fontSize:10,textAnchor:"end",children:[R&&sn(nn,{children:[sn("text",{x:n,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(S.pixelLength)]}),sn("text",{x:n,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),u.map((t,e)=>sn("text",{x:n,y:R?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,I=b?rn("text",{x:n,y:"vertical"===i?-3:2,fontSize:10,fill:ln,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,T=(t,e)=>h?h(t,e):an;return sn("g","vertical"===i?{children:[C,I,$.map(({index:t,coordinate:e})=>rn("line",{x1:0,y1:e,x2:n,y2:e,stroke:an,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),l&&o.map((t,e)=>{const o=g[t.id];if(!o||null===o.start)return null;const i=m[t.id],n=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},r=y[t.id]+(n.botPeak-n.topPeak)*x/2,s=p(o.start),a=p(o.end),c=T(t.id,e);return sn("g",{children:[rn("line",{x1:r,y1:s,x2:r,y2:a,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),rn("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:c,strokeOpacity:.5}),rn("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:c,strokeOpacity:.5})]},"lane-"+t.id)}),rn("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:an}),$.map(({tick:t,index:e,coordinate:o})=>{const i=f(t.date),n=null!=t.label?t.label:d?d(new Date(i)):"";return sn("g",{transform:`translate(-4,${o})`,children:[rn("line",{x2:-6,stroke:an}),rn("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:cn,children:n})]},e)})]}:{children:[C,I,$.map(({index:t,coordinate:e})=>rn("line",{x1:e,y1:0,x2:e,y2:r,stroke:an,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),l&&o.map((t,e)=>{const o=g[t.id];if(!o||null===o.start)return null;const i=m[t.id],n=i?{topPeak:i.topPeak,botPeak:i.botPeak}:{topPeak:0,botPeak:0},r=y[t.id]+(n.botPeak-n.topPeak)*x/2,s=p(o.start),a=p(o.end),c=T(t.id,e);return sn("g",{children:[rn("line",{x1:s,y1:r,x2:a,y2:r,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),rn("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:c,strokeOpacity:.5}),rn("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:c,strokeOpacity:.5})]},"lane-"+t.id)}),rn("line",{x1:P,y1:r+4,x2:L,y2:r+4,stroke:an}),$.map(({tick:t,index:e,coordinate:o})=>{const i=f(t.date),n=null!=t.label?t.label:d?d(new Date(i)):"";return sn("g",{transform:`translate(${o},${r+4})`,children:[rn("line",{y2:6,stroke:an}),rn("text",{y:20,textAnchor:"middle",fontSize:11,fill:cn,children:n})]},e)})]})}({layout:V,nodes:S,orientation:L,plotW:O,plotH:z,timelineExtent:"vertical"===L?z:O,axisTicks:Array.isArray(n.axisTicks)?n.axisTicks.map(t=>({date:t.date,label:t.label})):[],showQualityReadout:!!n.showQualityReadout,showLaneRails:!!n.showLaneRails,timeFormat:"function"==typeof n.timeFormat?t=>n.timeFormat(t):void 0,colorOf:Y,toTime:t=>r(t),xScale:t=>Number(Z(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:hn,layoutConfig:H,sourceAccessor:s,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:e,colorScheme:o,...J&&{backgroundGraphics:J},...i,showLegend:C,...X&&{legend:X,legendPosition:I},__legendIncludesAutomatic:!0,margin:T}}},wn={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,i,n)=>{const r=Array.isArray(n.nodes)?n.nodes:pn([],Array.isArray(n.edges)?n.edges:[],n.sourceAccessor||"source",n.targetAccessor||"target"),s=At(i.theme).colors.categorical,a=new Map,c="string"==typeof e?e:"__ssrSankeyColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?Q(l,c,o??i.colorScheme??s):void 0,d=t=>({fill:e?K(t?.data||t,e,u):ve(void 0,s,o,void 0,a),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),h=lt(n.styleRules,e,n.valueAccessor),f=h?(t,e)=>({...d(t),...h(t,e)}):d,p=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:i,edgeOpacity:n,baseStyle:r={}}){return s=>{const a={fillOpacity:n,...r};if("function"==typeof t)a.fill=t(s);else if("source"===t){const t="object"==typeof s.source?s.source:null;e&&t?a.fill=K(t.data||t,e,o):t&&(a.fill=i(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=K(t.data||t,e,o):t&&(a.fill=i(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*n);return a}}({edgeColorBy:n.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:f,edgeOpacity:n.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,valueAccessor:n.valueAccessor,orientation:n.orientation,nodeAlign:n.nodeAlign,nodeWidth:n.nodeWidth,nodePaddingRatio:n.nodePaddingRatio,showLabels:n.showLabels,nodeLabel:n.nodeLabel,colorBy:e,edgeColorBy:n.edgeColorBy,edgeOpacity:n.edgeOpacity,nodeStyle:et(n.nodeStyle||f,gt(n)),edgeStyle:et(n.edgeStyle||p,gt(n)),colorScheme:o,...i}}},kn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=At(i.theme).colors.categorical,s=new Map,a=fn(t??null,n.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrTreeColorBy:c(t)})):a,u=c?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?Q(l,u,o??i.colorScheme??r):void 0,h=i.nodeStyle||n.nodeStyle;return{chartType:"cluster"===n.layout?"cluster":"tree",data:t,childrenAccessor:n.childrenAccessor,colorBy:e,colorByDepth:n.colorByDepth,orientation:n.orientation,showLabels:n.showLabels,nodeLabel:!1!==n.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,colorScheme:o,...i,nodeStyle:yn(t=>{const i=t?.data||t;return{fill:n.colorByDepth?H[Number(t?.depth||0)%H.length]:e?c?K({__ssrTreeColorBy:c(i)},"__ssrTreeColorBy",d??void 0):K(i,e,d??void 0):ve(void 0,r,o,void 0,s),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},h,gt(n))}}},Sn={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,i,n)=>{const r=At(i.theme).colors.categorical,s=new Map,a=fn(t??null,n.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrTreemapColorBy:c(t)})):a,u=c?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?Q(l,u,o??i.colorScheme??r):void 0,h=n.showLabels??i.showLabels,f=n.labelMode,p=void 0!==n.paddingTop?n.paddingTop:i.paddingTop,y=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,g=i.nodeStyle||n.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:e,colorByDepth:n.colorByDepth,showLabels:n.showLabels,labelMode:f,nodeLabel:h?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...null!=y&&{paddingTop:y},colorScheme:o,...i,nodeStyle:yn(t=>{const i=t?.data||t;return{fill:n.colorByDepth?H[Number(t?.depth||0)%H.length]:e?c?K({__ssrTreemapColorBy:c(i)},"__ssrTreemapColorBy",d??void 0):K(i,e,d??void 0):ve(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},g,gt(n))}}},An={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Mn}from"d3-scale";function _n(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var Pn={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r="string"==typeof o?o:"blues",s=function(t,e,o){if(!Array.isArray(t))return;const i=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let n=1/0,r=-1/0;for(const e of t){const t=i(e);null!=t&&isFinite(t)&&(n>t&&(n=t),t>r&&(r=t))}const s=[Number.isFinite(n)?n:0,Number.isFinite(r)?r:1],a=Mn(z(o)).domain(s);return{domain:s,colorScale:t=>a(t),valueAccessor:i}}(n.areas,n.valueAccessor,r),a=n.areaStyle??function(t,e){if(t)return o=>{const i=t.valueAccessor(o);return{fill:null!=i&&isFinite(i)?t.colorScale(i):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:e}}}(s,n.areaOpacity??1),c=n.styleRules?ct(a,n.styleRules,t=>{return{value:(e=t,"function"==typeof n.valueAccessor?n.valueAccessor(e):null!=n.valueAccessor?e?.properties?.[n.valueAccessor]??e?.[n.valueAccessor]:void 0)};var e},_n):a,l=!1!==i.showLegend&&s?{gradient:{colorFn:s.colorScale,domain:s.domain,label:"string"==typeof n.valueAccessor?n.valueAccessor:"value"}}:void 0;return{areas:n.areas,projection:n.projection||"equalEarth",areaStyle:c,valueAccessor:n.valueAccessor,colorScheme:r,graticule:n.graticule,fitPadding:n.fitPadding,...i,...void 0===i.legend&&l?{legend:l}:{}}}},Ln={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r=t||n.points,s=n.pointStyle??function(t,e,o,i){const n=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",i="string"==typeof e?n:n.map(t=>({...t,__geoColorBy:e(t)}));r=Q(i,t,o)}if(i.sizeBy){const t=n.map("function"==typeof i.sizeBy?i.sizeBy:t=>t?.[i.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=Pt(t))}return t=>({fill:e&&r?K(t,e,r):q,fillOpacity:i.fillOpacity,stroke:"#fff",strokeWidth:i.strokeWidth,r:i.sizeBy?J(t,i.sizeBy,i.sizeRange,s):i.pointRadius??6})}(r,e,o,{sizeBy:n.sizeBy,sizeRange:n.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=n.styleRules?ct(s,n.styleRules,nt(e,n.sizeBy)):s;return{points:r,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",areas:n.areas,areaStyle:n.areaStyle||An,pointStyle:a,sizeBy:n.sizeBy,colorBy:e,colorScheme:o,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,...i}}},$n={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,i,n)=>{const r=(Array.isArray(t)?t:null)||n.flows||[],s=n.nodeIdAccessor||"id",a=n.valueAccessor||"value",c=n.xAccessor||"lon",l=n.yAccessor||"lat",u="function"==typeof c?c:t=>t[c],d="function"==typeof l?l:t=>t[l],h=(n.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),f=new Map;for(const t of h)f.set(t[s]+"",t);const p=n.edgeColorBy??e,y="function"==typeof p,g=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),o=f.get(t.target+"");return e&&o?{...t,coordinates:[{x:e.x,y:e.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=p?y?Q(g.map(t=>({[m]:p(t)})),m,o||"category10"):Q(g,p,o||"category10"):null,b=t=>p&&x?K(t,p,x):"#007bff";let v=1/0,w=-1/0;for(const t of g){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[S,A]=n.edgeWidthRange??[1,8],M=A-S,_=n.edgeOpacity??.6,P=n.edgeLinecap??"round";return{lines:g,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:n.lineType||"geo",flowStyle:n.flowStyle||"basic",areas:n.areas,areaStyle:n.areaStyle||An,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,colorScheme:o,lineStyle:t=>{const e=Number(t?.[a]),o=Number.isFinite(e)?e:v,i=S+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:b(t),strokeWidth:i,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...i}}};import*as Rn from"react";function Cn(t){const[e,o]=t,i=160>e||116>o,n=i?Math.min(12,Math.max(2,.08*e)):32,r=i?Math.min(8,Math.max(2,.12*o)):24,s=i?r:34;return{width:e,height:o,plot:{x:n,y:r,width:Math.max(1,e-2*n),height:Math.max(1,o-r-s)}}}function In(t){const e=(t??"")+"";if(!e)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let i=0;for(let t=0;e.length>t;t+=1)i=31*i+e.charCodeAt(t)>>>0;return o[i%o.length]}function Tn(t,e="#4e79a7",o){const i=o?.styleRules,n=!!i&&i.length>0,r=n?ot(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,c={fill:null==a?e:In(a),stroke:"#111827",strokeWidth:1,opacity:.9};return n&&s&&Object.assign(c,at(s,i,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function On(t,e,o,i){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:o},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...i}}}function zn(t,e,o){return"function"==typeof o?o(t,e):t[o]}function Fn(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:null}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:null}function Nn(t,e,o){return Math.max(e,Math.min(o,t))}function En(t,e){const o=Fn(t);return null!=o&&o>0?o:e}function Dn(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Bn(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}import{scaleLinear as Wn}from"d3-scale";function jn(t){let e=t>>>0;return function(){e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}var Yn={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},Xn=1e-9,qn=.005;function Gn(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function Vn(t){return"aabb"===t.type?{type:"aabb",x:t.x,y:t.y,width:t.width,height:t.height}:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:t.thickness}}function Hn(t,e,o){return Math.max(e,Math.min(o,t))}function Un(t,e,o){return Math.min(t??o,e??o)}function Kn(t,e,o){return Hn(Math.max(t??o,e??o),0,1)}function Zn(t){return 0>t?-1:1}function Qn(t){if("circle"===t.shape.type){const e=t.shape.radius;return{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e}}const e=t.shape.width/2,o=t.shape.height/2;return{minX:t.x-e,minY:t.y-o,maxX:t.x+e,maxY:t.y+o}}function Jn(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,o=e.height/2;return{minX:e.x-t,minY:e.y-o,maxX:e.x+t,maxY:e.y+o}}const o=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-o,minY:Math.min(e.y1,e.y2)-o,maxX:Math.max(e.x1,e.x2)+o,maxY:Math.max(e.y1,e.y2)+o}}function tr(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function er(t,e,o,i,n,r,s,a){const c=n-t,l=(o+s)/2-Math.abs(c);if(0>=l)return null;const u=r-e,d=(i+a)/2-Math.abs(u);return d>0?d>l?{nx:Zn(c),ny:0,penetration:l}:{nx:0,ny:Zn(u),penetration:d}:null}function or(t,e,o,i,n,r,s){const a=r/2,c=s/2,l=t-Hn(t,i-a,i+a),u=e-Hn(e,n-c,n+c),d=l*l+u*u;if(d>o*o)return null;if(Xn>=d){const r=Math.abs(t-(i-a)),s=Math.abs(t-(i+a)),l=Math.abs(e-(n-c)),u=Math.abs(e-(n+c)),d=Math.min(r,s,l,u);return d===r?{nx:-1,ny:0,penetration:o+r}:d===s?{nx:1,ny:0,penetration:o+s}:d===l?{nx:0,ny:-1,penetration:o+l}:{nx:0,ny:1,penetration:o+u}}const h=Math.sqrt(d);return{nx:l/h,ny:u/h,penetration:o-h}}function ir(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,o,i,n,r){const s=i-t,a=n-e,c=o+r,l=s*s+a*a;if(l>=c*c)return null;if(Xn>=l)return{nx:1,ny:0,penetration:c};const u=Math.sqrt(l);return{nx:s/u,ny:a/u,penetration:c-u}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return er(t.x,t.y,t.shape.width,t.shape.height,e.x,e.y,e.shape.width,e.shape.height);if("circle"===t.shape.type&&"aabb"===e.shape.type){const o=or(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return o?{nx:-o.nx,ny:-o.ny,penetration:o.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?or(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function nr(t,e){const o=e.shape;return"aabb"===o.type?"circle"===t.shape.type?or(t.x,t.y,t.shape.radius,o.x,o.y,o.width,o.height):er(o.x,o.y,o.width,o.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,o,i,n,r,s,a=0){const c=r-i,l=s-n,u=c*c+l*l,d=u>Xn?Hn(((t-i)*c+(e-n)*l)/u,0,1):0,h=o+a/2,f=t-(i+c*d),p=e-(n+l*d),y=f*f+p*p;if(y>=h*h)return null;if(Xn>=y){const t=Math.sqrt(u);return t>Xn?{nx:-l/t,ny:c/t,penetration:h}:{nx:1,ny:0,penetration:h}}const g=Math.sqrt(y);return{nx:f/g,ny:p/g,penetration:h-g}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,o.x1,o.y1,o.x2,o.y2,o.thickness??0)}function rr(t,e){return`${t}\0${e}`}function sr(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function ar(t){return{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,bodyCollisions:t.bodyCollisions,shape:Gn(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function cr(t){return t&&"function"!=typeof t?{property:t.property,equals:t.equals,notEquals:t.notEquals,oneOf:t.oneOf?.slice(),notOneOf:t.notOneOf?.slice()}:t}function lr(t){return{id:t.id,shape:Vn(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:cr(t.bodyFilter),index:t.index}}function ur(t,e){return!!e?.some(e=>Object.is(t,e))}function dr(t,e){return function(t,e){if(!e)return!0;if("function"==typeof e)return e(t);const o=function(t,e){if(!e)return;let o=t;for(const t of e.split(".")){if(null==o||"object"!=typeof o)return;if(!Object.prototype.hasOwnProperty.call(o,t))return;o=o[t]}return o}(t,e.property);return!("equals"in e&&!Object.is(o,e.equals)||"notEquals"in e&&Object.is(o,e.notEquals)||e.oneOf&&!ur(o,e.oneOf)||e.notOneOf&&ur(o,e.notOneOf))}(e,t.bodyFilter)}var hr=class{constructor(t={}){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={...Yn,...t},this.random=jn(this.options.seed)}init(t={}){this.options={...Yn,...t},this.random=jn(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(t){const e={id:t.id,x:t.x,y:t.y,prevX:t.x,prevY:t.y,vx:t.vx??0,vy:t.vy??0,angle:t.angle??0,mass:Math.max(Xn,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:Gn(t.shape),sleeping:!1,datum:t.datum,restitution:t.restitution,friction:t.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(t.id,e)}remove(t){for(const e of t){this.bodies.delete(e);for(const t of Array.from(this.activeSensors))sr(t).bodyId===e&&this.activeSensors.delete(t)}}setColliders(t){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const e of t)this.colliders.set(e.id,{...e,shape:Vn(e.shape),bodyFilter:cr(e.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(t){const e=t.id??"spring-"+this.nextSpringIndex;return this.springs.set(e,{id:e,bodyId:t.bodyId,target:t.target,restLength:t.restLength??0,stiffness:t.stiffness??40,damping:t.damping??3}),this.nextSpringIndex+=1,e}removeConstraint(t){this.springs.delete(t)}applyImpulse(t,e,o){const i=this.bodies.get(t);i&&(i.vx+=e/i.mass,i.vy+=o/i.mass,this.wake(i))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const o=this.sortedBodies();for(const t of o)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const i=this.options.maxVelocity;for(const t of o)if(!t.sleeping){if(t.vx+=this.options.gravity.x*e,t.vy+=this.options.gravity.y*e,t.vx*=this.options.velocityDamping,t.vy*=this.options.velocityDamping,i>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>i){const o=i/e;t.vx*=o,t.vy*=o}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const n=this.bodyPairKeys(o),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(o,n,0===t),this.resolveColliders(o,r,0===t);this.updateSensors(o),this.updateSleeping(o,e)}settle(t=1200,e=this.options.fixedDt){let o=0;for(;t>o&&!this.allSleeping();)this.step(e),o+=1;return o}readState(t=[]){t.length=0;for(const e of this.sortedBodies())t.push({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:Gn(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(sr)}allSleeping(){for(const t of this.bodies.values())if(!t.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(ar),colliders:this.sortedColliders().map(lr),springs:Array.from(this.springs.values()).map(t=>({...t,target:{...t.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(t){this.options={...t.options,gravity:{...t.options.gravity}},this.random=jn(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(t.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const e of t.bodies){const t=ar(e);this.bodies.set(t.id,t),this.nextBodyIndex=Math.max(this.nextBodyIndex,t.index+1)}this.nextColliderIndex=0;for(const e of t.colliders){const t=lr(e);this.colliders.set(t.id,t),this.nextColliderIndex=Math.max(this.nextColliderIndex,t.index+1)}this.nextSpringIndex=0;for(const e of t.springs){this.springs.set(e.id,{...e,target:{...e.target}});const t=/^spring-(\d+)$/.exec(e.id);t&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(t[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((t,e)=>t.index-e.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((t,e)=>t.index-e.index)}applySprings(t){for(const e of Array.from(this.springs.values()).sort((t,e)=>t.id.localeCompare(e.id))){const o=this.bodies.get(e.bodyId);if(!o||o.sleeping)continue;const i="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!i)continue;const n=i.x-o.x,r=i.y-o.y,s=Math.sqrt(n*n+r*r);if(Xn>=s)continue;const a=n/s,c=r/s,l=(s-e.restLength)*e.stiffness+((("vx"in i?i.vx:0)-o.vx)*a+(("vy"in i?i.vy:0)-o.vy)*c)*e.damping;o.vx+=l*a*t/o.mass,o.vy+=l*c*t/o.mass}}resolveBodyPairs(t,e,o){for(const i of e){const[e,n]=i.split(":").map(Number),r=t[e],s=t[n];if(!r||!s)continue;const a=ir(r,s);a&&(this.resolveDynamicCollision(r,s,a),o&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),o=new Map;for(let i=0;t.length>i;i+=1){if(!1===t[i].bodyCollisions)continue;const n=Qn(t[i]),r=Math.floor(n.minX/e),s=Math.floor(n.maxX/e),a=Math.floor(n.minY/e),c=Math.floor(n.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;c>=e;e+=1){const n=`${t}:${e}`,r=o.get(n);r?r.push(i):o.set(n,[i])}}const i=new Set;for(const e of Array.from(o.keys()).sort()){const n=o.get(e)??[];n.sort((t,e)=>t-e);for(let e=0;n.length>e;e+=1)for(let o=e+1;n.length>o;o+=1){const r=n[e],s=n[o];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&tr(Qn(t[r]),Qn(t[s]))&&i.add(`${r}:${s}`)}}return Array.from(i).sort((t,e)=>{const[o,i]=t.split(":").map(Number),[n,r]=e.split(":").map(Number);return o===n?i-r:o-n})}resolveDynamicCollision(t,e,o){t.sleeping&&this.contactOpposesGravity(o.nx,o.ny)&&this.supportedThisStep.add(e.id),e.sleeping&&this.contactOpposesGravity(-o.nx,-o.ny)&&this.supportedThisStep.add(t.id);const i=t.sleeping?0:1/t.mass,n=e.sleeping?0:1/e.mass,r=i+n;if(Xn>=r)return;const s=Math.max(0,o.penetration-qn)/r;t.x-=o.nx*s*i,t.y-=o.ny*s*i,e.x+=o.nx*s*n,e.y+=o.ny*s*n;const a=(e.vx-t.vx)*o.nx+(e.vy-t.vy)*o.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Un(t.restitution,e.restitution,this.options.restitution))*a/r,u=l*o.nx,d=l*o.ny;t.vx-=u*i,t.vy-=d*i,e.vx+=u*n,e.vy+=d*n,this.applyFriction(t,e,o,l,i,n),c>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,o,i,n,r){const s=-o.ny,a=o.nx,c=(e.vx-t.vx)*s+(e.vy-t.vy)*a,l=n+r;if(Xn>=Math.abs(c)||Xn>=l)return;const u=Kn(t.friction,e.friction,this.options.friction),d=Hn(-c/l,-i*u,i*u),h=d*s,f=d*a;t.vx-=h*n,t.vy-=f*n,e.vx+=h*r,e.vy+=f*r}resolveColliders(t,e,o){for(const i of t)for(const t of e){if(!dr(t,i))continue;if(!tr(Qn(i),Jn(t)))continue;const e=nr(i,t);e&&(this.resolveStaticCollision(i,t,e),this.contactOpposesGravity(e.nx,e.ny)&&this.supportedThisStep.add(i.id),o&&this.lastEvents.push({type:"contact",bodyId:i.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,o){t.x+=o.nx*Math.max(0,o.penetration-qn),t.y+=o.ny*Math.max(0,o.penetration-qn);const i=t.vx*o.nx+t.vy*o.ny;if(0>i){const n=Un(t.restitution,e.restitution,this.options.restitution);t.vx-=(1+n)*i*o.nx,t.vy-=(1+n)*i*o.ny;const r=-o.ny,s=o.nx,a=t.vx*r+t.vy*s,c=Kn(t.friction,e.friction,this.options.friction);t.vx-=a*r*c,t.vy-=a*s*c}}updateSensors(t){const e=new Set,o=this.sortedColliders().filter(t=>t.sensor);for(const i of t){const t=Qn(i);for(const n of o){if(!dr(n,i))continue;if(!tr(t,Jn(n)))continue;if(!nr(i,n))continue;const o=rr(n.id,i.id);e.add(o),this.activeSensors.has(o)||this.lastEvents.push({type:"sensor-enter",bodyId:i.id,sensorId:n.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:o,bodyId:i}=sr(t);this.lastEvents.push({type:"sensor-exit",bodyId:i,sensorId:o})}this.activeSensors=e}updateSleeping(t,e){const o=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const i of t)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*e||o&&!this.supportedThisStep.has(i.id)?i.sleeping?this.wake(i):i.sleepTime=0:(i.sleepTime+=e,i.sleeping||this.options.sleepAfter>i.sleepTime||(i.sleeping=!0,i.vx=0,i.vy=0,this.lastEvents.push({type:"sleep",bodyId:i.id})))}contactOpposesGravity(t,e){const{x:o,y:i}=this.options.gravity,n=Math.hypot(o,i);return 1e-9>=n||-.2>(t*o+e*i)/n}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},fr=class{constructor(t={}){this.id="builtin",this.capabilities={...(new hr).capabilities,engine:"builtin"},this.world=new hr(t)}init(t={}){this.world.init(t)}spawn(t){this.world.spawn(t)}remove(t){this.world.remove(t)}setColliders(t){this.world.setColliders(t)}setConstraint(t){return this.world.setConstraint(t)}removeConstraint(t){this.world.removeConstraint(t)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o)}step(t){this.world.step(t)}settle(t,e){return this.world.settle(t,e)}readState(t){return this.world.readState(t)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(t){this.world.restore(t)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function pr(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new fr(t)}(e)}var yr=["binId","targetBin","category","windowIndex","lane","group"];function gr(t,e){if(!Number.isFinite(e))return;t.count+=1,t.total+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e);const o=e-t.mean;t.mean+=o/t.count,t.m2+=o*(e-t.mean)}function mr(t){return{count:t.count,total:t.total,mean:t.count>0?t.mean:0,min:t.count>0?t.min:0,max:t.count>0?t.max:0,variance:t.count>1?t.m2/(t.count-1):0}}function xr(t){return{count:t.count,total:t.total,mean:t.mean,m2:t.variance*Math.max(0,t.count-1),min:t.count>0?t.min:1/0,max:t.count>0?t.max:-1/0}}function br(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function vr(t,e,o){return"function"==typeof t?t(e,o):"string"==typeof t?br(e,t):void 0}function wr(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function kr(t){const e=mr(t.value);return{id:t.id,label:t.label,count:e.count,total:e.total,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:mr(t.x),y:mr(t.y),value:e}}var Sr=class{constructor(t=!1){this.bins=new Map,this.nextIndex=0,this.config=t}updateConfig(t){void 0!==t&&(this.config=t,!1===t&&this.clear())}isEnabled(){return!1!==this.config}add(t){if(!1===this.config)return null;const e=this.nextIndex;this.nextIndex+=1;const o=wr(vr(this.config.binAccessor,t,e))??function(t){for(const e of yr){const o=wr(br(t,e));if(o)return o}return"sediment"}(t),i=wr(vr(this.config.labelAccessor,t,e))??o,n=function(t,e,o){if("number"==typeof t)return t;const i="function"==typeof t?t(e,o):"string"==typeof t?br(e,t):1,n="number"==typeof i?i:Number(i);return Number.isFinite(n)?n:1}(this.config.valueAccessor,t,e),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(o);return s||(s={id:o,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(o,s)),s.label=i,s.lastBodyId=t.id,s.lastDatum=t.datum,gr(s.x,t.x),gr(s.y,t.y),gr(s.value,n),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),kr(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(kr)}restore(t=[]){this.bins.clear();for(const e of t)this.bins.set(e.id,{id:e.id,label:e.label,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:xr(e.x),y:xr(e.y),value:xr(e.value)});this.nextIndex=t.reduce((t,e)=>t+e.count,0)}totals(){const t=this.snapshot();return{bins:t.length,count:t.reduce((t,e)=>t+e.count,0),total:t.reduce((t,e)=>t+e.total,0)}}};function Ar(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var Mr={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},_r={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Pr(t={},e=_r){return{chartId:t.chartId??e.chartId,chartType:t.chartType??e.chartType,sensors:t.sensors??e.sensors,onObservation:t.onObservation??e.onObservation,onSimulationStateChange:t.onSimulationStateChange??e.onSimulationStateChange}}function Lr(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function $r(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:void 0}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function Rr(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function Cr(t){return{...Lr(t),sequence:t.sequence,spawnAt:t.spawnAt}}function Ir(t){return t.map(t=>({...t,shape:{...t.shape},bodyFilter:t.bodyFilter&&"function"!=typeof t.bodyFilter?{...t.bodyFilter,oneOf:t.bodyFilter.oneOf?.slice(),notOneOf:t.bodyFilter.notOneOf?.slice()}:t.bodyFilter}))}function Tr(t){return!1!==t&&{...t}}function Or(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function zr(t){return{...t,gravity:{...t.gravity}}}function Fr(t,e,o,i){if("circle"===t.shape.type){const n=t.x-e,r=t.y-o,s=t.shape.radius+i,a=n*n+r*r;return a>s*s?null:a}const n=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),r=Math.max(Math.abs(o-t.y)-t.shape.height/2,0),s=n*n+r*r;return s>i*i?null:s}function Nr(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Er(t,e={}){const{idPrefix:o="plot",includeFloor:i=!0,includeCeiling:n=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=e,l=[],u=t.x+t.width/2,d=t.y+t.height/2;return i&&l.push({id:o+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+c/2,width:t.width+2*a,height:c}}),n&&l.push({id:o+"-ceiling",shape:{type:"aabb",x:u,y:t.y-c/2,width:t.width+2*a,height:c}}),r&&l.push({id:o+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:d,width:a,height:t.height+2*c}}),s&&l.push({id:o+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:d,width:a,height:t.height+2*c}}),l}function Dr(t){const{idPrefix:e="bin",count:o,domainStart:i,domainStep:n,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=s,lidThickness:f=Math.max(2,c)}=t,p=[],y=s+(a-s)/2,g=Math.abs(a-s),m=l?o:o-1;if(u||l)for(let t=l?0:1;m>=t;t+=1){if(!u&&t>0&&o>t)continue;const s=r(i+t*n);p.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:s,y:y,width:c,height:g}})}if(null!=d)for(let t=0;o>t;t+=1){const o=i+t*n,s=o+n;if(s>=d)continue;const a=r(o),l=r(s);p.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:f}})}return p}var Br={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 Wr(t,e){const o={...t};for(const t of e)o[Br[t]]++;return o}function jr(t,e,o){const i=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:i,revisions:Wr(o,i)}}var Yr=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=jr({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}record(t,e){const o=jr(t,e,this.revisions);this.revisions=o.revisions,this.latest=o;for(const t of[...this.listeners])t();return o}};import{quadtree as Xr}from"d3-quadtree";var qr=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,o,i,n,r=0,s){const a=this.ensure(t,e);if(!a)return null;let c=null,l=1/0;const u=Math.max(0,s?.searchRadius??Math.max(0,r)+this.maxSearchRadius),d=i-u,h=i+u,f=n-u,p=n+u;return a.visit((t,e,a,u,y)=>{if(d>u||e>h||f>y||a>p)return!0;if(t.length)return!1;let g=t;for(;g;){const t=g.data;if(t&&(!s?.include||s.include(t))){const e=s?.distanceSquared?s.distanceSquared(t,i,n):Fr(t,i,n,Math.max(0,r));null!=e&&(l>e||e===l&&o.indexOf(t.id)>o.indexOf(c?.id??""))&&(c=t,l=e)}g=g.next}return!1}),c}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const o=t.readState();return 0===o.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=o.reduce((t,e)=>Math.max(t,function(t){return"circle"===t.shape.type?t.shape.radius:Math.hypot(t.shape.width,t.shape.height)/2}(e)),0),this.tree=Xr().x(t=>t.x).y(t=>t.y).addAll(o),this.revision=e,this.tree)}},Gr=["data","scene-geometry","data-paint","accessibility","evidence"],Vr=["scene-geometry","data-paint","accessibility","evidence"],Hr=["overlay","accessibility","evidence"],Ur=(t,e)=>({retainedData:t,invalidations:e}),Kr=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zr=["scene-geometry","data-paint","accessibility","evidence"],Qr=[],Jr={engine:Ur("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:Ur("preserve",Zr),colliders:Ur("preserve",Zr),sediment:Ur("preserve",Zr),bodyBudget:Ur("preserve",Kr),bodyLimit:Ur("preserve",Kr),eviction:Ur("preserve",Kr),fixedDt:Ur("preserve",Qr),maxDeltaSeconds:Ur("preserve",Qr),maxSubsteps:Ur("preserve",Qr),settleStepLimit:Ur("preserve",Qr),timeScale:Ur("preserve",Qr),observation:Ur("preserve",Qr)},ts=Ur("preserve",Kr);function es(t){let e="preserve";const o=new Set;for(const i of t){const t=Jr[i]??ts;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}var os=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function is(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&os.every(o=>t[o]===e[o])}function ns(t,e,o,i){return t||!e?"paused":o||!i?"running":"settled"}var rs=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(t){this.speed=function(t){const e=t?.sleepSpeed;return"number"==typeof e&&Number.isFinite(e)&&e>0?e:8}(t)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(t,e,o){if(o>0)return void(this.seconds=0);const i=t.readState(this.scratch),n=this.speed*this.speed;let r=!0;for(const t of i)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=n){r=!1;break}this.seconds=r?this.seconds+Math.max(0,e):0}},ss=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new qr,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Yr,this.simulationState="settled",this.visible=!0,this.quiescence=new rs;const{bodyBudget:e,colliders:o,engine:i,kernel:n,observation:r,sediment:s,...a}=t;this.config={...Mr,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=i,this.observation=Pr(r),this.sediment=new Sr(s??!1),this.world=pr(i,{fixedDt:this.config.fixedDt,...n}),this.quiescence.setKernelOptions(n),o&&this.world.setColliders(Ir(o))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(o=>"kernel"===o?!is(t.kernel,e.kernel):t[o]!==e[o])}(t,this.configInput),{colliders:o,bodyBudget:i,engine:n,kernel:r,observation:s,sediment:a,...c}=t;if(this.config={...this.config,...c},void 0!==i&&(this.bodyBudget=i,!1===i&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=pr(n,t.options),this.world.restore(t),this.revision+=1}if(r&&!is(r,this.configInput.kernel)){const t=this.world.snapshot(),e={...t.options,...r,gravity:{...t.options.gravity,...r.gravity}};this.world.restore({...t,options:e}),this.quiescence.setKernelOptions(e),this.revision+=1}s&&(this.observation=Pr(s,this.observation)),this.sediment.updateConfig(a),o&&(this.world.setColliders(Ir(o)),this.revision+=1),this.configInput={...this.configInput,...t};const l=es(e);this.updateResults.record({kind:"config",keys:e},l.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(Ir(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},es(["colliders"]).invalidations)}enqueue(t,e){const o=Array.isArray(t)?t:[t],i=e?function(t,e={}){const o=$r(e.startAt)??0,i=e.pacing??"immediate";if("arrival"===i){const i=t.map((t,o)=>function(t,e,o){return"function"==typeof o?$r(o(t,e)):"string"==typeof o?$r(Rr(t,o)):$r(t.spawnAt)??$r(Rr(t,"arrivalTime"))??$r(Rr(t,"timestamp"))??$r(Rr(t,"time"))??$r(Rr(t,"eventTime"))}(t,o,e.timeAccessor)),n=i.filter(t=>null!=t),r=n.length>0?Math.min(...n):0,s=$r(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const n=i[e],s=null==n?0:Math.max(0,n-r);return{...Lr(t),spawnAt:o+s/a}})}if("object"==typeof i){const e=$r(i.ratePerSec);if(e&&e>0)return t.map((t,i)=>({...Lr(t),spawnAt:o+i/e}))}return t.map(t=>({...Lr(t),spawnAt:o}))}(o,{...e,startAt:e.startAt??this.elapsedSeconds}):o;for(const t of i)this.queue.push({...Lr(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Or),i.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:i.length},i.length?Gr:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(Lr(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},Gr)}materializeDueSpawns(){const t=this.revision,e=[],o=[];return this.spawnDue(e,o),0===e.length||(this.observeBodyBudget(o),this.evictOverflow(o),this.syncSimulationState(o),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?Gr:[])),e}clear(){const t=this.world.snapshot().options;this.world.init({...t,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},Gr)}tick(t){const e=this.revision,o=[],i=[],n=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,o,i,n,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(o,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);i.push(...l.evicted),n.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,o.length),(u>0||o.length>0||i.length>0||n.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,o,i,n,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?o.length||i.length||n.length?Gr:Vr:[]),d}settle(t=this.config.settleStepLimit){return this.runSettle(t,!1).steps}settleWithObservations(t=this.config.settleStepLimit){return this.runSettle(t,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:t=>{this.elapsedSeconds+=t},spawnDue:(t,e)=>this.spawnDue(t,e),observeBodyBudget:t=>this.observeBodyBudget(t),evictOverflow:t=>this.evictOverflow(t),step:t=>this.world.step(t),drainEvents:()=>this.world.events(),observeKernelEvents:(t,e)=>this.observeKernelEvents(t,e),observeSensorTransitions:t=>this.observeSensorTransitions(t),refreshQuiescence:(t,e)=>this.quiescence.refresh(this.world,t,e)}}runSettle(t,e){const o=this.revision,i=[],n=[],r=[],s=[],a=e?[]:void 0;if(e&&(this.paused||!this.visible)){const t=this.result(0,i,n,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(i,a);const c=this.observeBodyBudget(a),l=this.evictOverflow(a);n.push(...l.evicted),r.push(...l.sedimented),this.syncSimulationState(a),i.length>0&&this.quiescence.reset();const u=e?{spawned:i,evicted:n,sedimented:r,events:s,observations:a}:{spawned:i},{steps:d,budget:h}=function(t,e,o){let i,n=0;for(;e>n&&(t.queueSize()>0||!t.atRest());){t.advanceTime(t.fixedDt);const e=[];if(t.spawnDue(e,o.observations),e.length>0){o.spawned.push(...e),i=t.observeBodyBudget(o.observations);const n=t.evictOverflow(o.observations);o.evicted?.push(...n.evicted),o.sedimented?.push(...n.sedimented)}t.step(t.fixedDt);const r=t.drainEvents();o.events&&(o.events.push(...r),t.observeKernelEvents(r,o.observations),t.observeSensorTransitions(o.observations)),n+=1,t.refreshQuiescence(t.fixedDt,e.length)}return{steps:n,budget:i}}(this.settleHost(),t,u),f=i.length+n.length+r.length>0;(d>0||f||s.length>0)&&(this.revision+=1);const p=this.result(d,i,n,r,s,a??[],void 0,h??c);return this.updateResults.record({kind:"settle",count:d},this.revision===o?[]:f?Gr:Vr),p}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return function(t,e={}){const{baselineY:o=0,binWidth:i=24,gap:n=2,maxHeight:r=80,value:s="count",x:a}=e,c=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const l=Math.max(0,t[s]/c*r),u=a?.(t,e)??e*(i+n);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:o-l,width:i,height:l,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,o=0,i){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,o,i)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:o,chartId:i,...n}=t,r={...n,timestamp:e??this.elapsedSeconds,chartType:o??this.observation.chartType,chartId:i??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(t){return this.updateResults.subscribe(t)}version(){return this.revision}setPaused(t){const e=this.paused!==t;this.paused=t,this.syncSimulationState(),this.updateResults.record({kind:"pause"},e?Hr:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?Hr:[])}remove(t){const e=new Set(t),o=new Set(this.liveBodyOrder),i=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const n=t.filter(t=>o.has(t)||i.has(t));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?Gr:[]),n}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},Vr),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},Vr)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},Vr)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,o,i)=>t.applyImpulse(e,o,i),clear:()=>t.clear(),hitTest:(e,o,i)=>t.hitTest(e,o,i),pause:()=>t.setPaused(!0),push:(e,o)=>t.enqueue(e,o),pushMany:(e,o)=>t.enqueue(e,o),bodyBudgetStatus:()=>t.bodyBudgetStatus(),readBodies:e=>t.readBodies(e),readSediment:()=>t.readSediment(),recordObservation:e=>t.recordObservation(e),remove:e=>t.remove(e),restore:e=>t.restore(e),resume:()=>t.setPaused(!1),settle:e=>t.settle(e),settleWithObservations:e=>t.settleWithObservations(e),snapshot:()=>t.snapshot(),sedimentHeightfield:e=>t.sedimentHeightfield(e),sedimentTotals:()=>t.sedimentTotals(),step:e=>t.tick(e)};var t}snapshot(){const t=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:Tr(this.bodyBudget),config:{...this.config,kernel:zr(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Cr),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:t}}restore(t){this.config={bodyLimit:t.config.bodyLimit,eviction:t.config.eviction,fixedDt:t.config.fixedDt,maxDeltaSeconds:t.config.maxDeltaSeconds,maxSubsteps:t.config.maxSubsteps,settleStepLimit:t.config.settleStepLimit,timeScale:t.config.timeScale},this.configInput={...t.config,bodyBudget:Tr(t.bodyBudget??{}),kernel:zr(t.world.options)},this.bodyBudget=Tr(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(t.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(Cr).sort(Or),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??ns(t.paused,t.visible,t.queue.length>0,t.world.bodies.every(t=>t.sleeping)),this.liveBodyOrder=t.liveBodyOrder.slice(),this.visible=t.visible,this.nextSequence=this.queue.reduce((t,e)=>Math.max(t,e.sequence),-1)+1,this.world.restore(t.world),this.updateResults.record({kind:"restore"},Gr)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const o=this.queue.shift();if(!o)return;this.spawnOne(o,e),t.push(o.id)}}spawnOne(t,e){this.liveBodyOrder=this.liveBodyOrder.filter(e=>e!==t.id),this.removeActiveSensorPairsForBodies(new Set([t.id])),this.world.spawn(t),this.liveBodyOrder.push(t.id);for(const e of t.springs??[])this.world.setConstraint({...e,bodyId:t.id});const o=this.world.readState().find(e=>e.id===t.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:t.id,datum:o?.datum??t.datum,x:o?.x??t.x,y:o?.y??t.y},e)}result(t,e,o,i,n,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:o,events:n,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:c,sedimented:i,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,o){if(0===e.length)return;const i=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=i.get(t.bodyId);o.emit({type:"physics-settle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:t.bodyId,datum:e?.datum,x:e?.x,y:e?.y})}}(this.world,t,this.observationContext(e))}observeSensorTransitions(t){this.activeSensorPairs=function(t,e,o){const i=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===i.size&&0===e.size)return i;const n=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:i,bodyId:r}=Nr(e),s=o.observation.sensors[i],a=n.get(r);o.emit({type:"enter"===t?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:i,binId:s?.binId??i})};for(const t of Array.from(i).sort())e.has(t)||r("enter",t);for(const t of Array.from(e).sort())i.has(t)||r("exit",t);return i}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const o of t)e.has(Nr(o).bodyId)&&t.delete(o)}(this.activeSensorPairs,t)}observationContext(t){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:e=>this.emitObservation(e,t)}}emitObservation(t,e){e?.push(t),this.observation.onObservation?.(t)}evaluateBodyBudget(){return function(t){const e=Math.max(0,Math.floor(t.liveBodies)),o=Math.max(0,Math.floor(t.queuedBodies??0)),i=e+o,n=Ar(t.bodyLimit),r=Ar(t.engineMaxBodiesHint),s=function(t,e,o){if(!1===o)return;const i=Ar(o?.warnAt);return null!=i?i:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(n,r,t.options),a=null==n?0:Math.max(0,e-n),c=a>0?"overflow":null==s||s>i?"ok":"warning";return{action:"overflow"!==c?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:i,queuedBodies:o,state:c,warnAt:s}}({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(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const o=`${e.state}:${e.action}`;return o===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=o,this.emitObservation({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt},t)),e}syncSimulationState(t){const e=ns(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const o=this.simulationState;this.simulationState=e,function(t,e,o){o.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||o.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,simulationState:e,previousSimulationState:t})}(o,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:o,liveBodyOrder:i}=function(t,e,o,i,n,r){const s={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===o)return s;const a=Math.max(0,Math.floor(i));if(!Number.isFinite(a))return s;const c=n.length-a;if(0>=c)return s;const l=function(t,e,o){if("sleeping-first"!==e)return o.slice();const i=new Map(t.readState().map(t=>[t.id,t.sleeping])),n=[],r=[];for(const t of o)i.get(t)?n.push(t):r.push(t);return[...n,...r]}(t,o,n),u=l.slice(0,c);if(0===u.length)return s;const d=function(t,e,o,i){const n=new Map(t.readState().map(t=>[t.id,t])),r=[];for(const t of o){const o=n.get(t);if(!o)continue;const s=e.add(o);s&&(r.push(t),i.emit({type:"physics-sediment",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:t,datum:o.datum,x:o.x,y:o.y,binId:s.id,count:s.count,total:s.total}))}return r}(t,e,u,r);t.remove(u);const h=new Set(u);return{evicted:u,sedimented:d,liveBodyOrder:n.filter(t=>!h.has(t))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(t));return e.length>0&&(this.liveBodyOrder=i,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:o}}};import{scaleLinear as as}from"d3-scale";function cs(t){const{count:e,idPrefix:o,wallThickness:i,xScale:n,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const c=Math.min(r-1,a?.(e)??s),l=Math.max(1,r-c);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:n(e),y:c+l/2,width:i,height:l}}})}function ls(t,e,o){const i=t.width/Math.max(1,e),n=Math.max(2,2*o),r=Math.min(.7*i,Math.max(3.2*n,n+8)),s=Math.max(1,Math.floor(r/n));return{laneWidth:i,tubeWidth:r,ballDiameter:n,perRow:s,centerX:e=>t.x+(e+.5)*i,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*n}}import{scaleLinear as us}from"d3-scale";function ds(t){if(Array.isArray(t)&&t.length>=2){const e=Fn(t[0]),o=Fn(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=Fn(e.x),i=Fn(e.y);return null!=o&&null!=i?{x:o,y:i}:null}return null}function hs(t){return Array.isArray(t)?t.map(ds).filter(t=>null!=t):[]}function fs(t,e,o){return"normalized"===o?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:Nn(t.x,e.plot.x,e.plot.x+e.plot.width),y:Nn(t.y,e.plot.y,e.plot.y+e.plot.height)}}function ps(t){let e=0;for(let o=1;t.length>o;o+=1)e+=Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y);return e}function ys(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=Nn(e,0,1)*ps(t);let i=0;for(let e=1;t.length>e;e+=1){const n=t[e-1],r=t[e],s=Math.hypot(r.x-n.x,r.y-n.y);if(s>0){if(i+s>=o){const t=(o-i)/s;return{x:n.x+(r.x-n.x)*t,y:n.y+(r.y-n.y)*t}}i+=s}}return{...t[t.length-1]}}function gs(t,e){const o=ys(t,Math.max(0,e-.02)),i=ys(t,Math.min(1,e+.02)),n=i.x-o.x,r=i.y-o.y,s=Math.hypot(n,r)||1;return{x:n/s,y:r/s}}function ms(t,e,o){return Math.max(e,Math.min(o,t))}function xs(t,e,o,i,n,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:o,x2:i,y2:n,thickness:r.thickness??8}}}function bs(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,o=t.y,i=t.width,n=t.height,{type:"aabb",x:e,y:o,width:i,height:n}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,o,i,n}function vs(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...bs({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function ws(t,e=12){return"number"==typeof t?{x:t,y:0}:t&&"object"==typeof t?{x:Number.isFinite(t.x)?Number(t.x):e,y:Number.isFinite(t.y)?Number(t.y):0}:{x:e,y:0}}import{scaleLinear as ks}from"d3-scale";function Ss(t,e,o){return G(t,e,o)}function As(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&Z(o,t)||"#4e79a7":e=>{if(o){const t=Z(o,e);if(t)return t}let i=0;for(let t=0;e.length>t;t++)i=31*i+e.charCodeAt(t)|0;return t[Math.abs(i)%t.length]??"#4e79a7"}}function Ms(t,e){const o=e.config??{},i=(e.sensors??[]).map(t=>({...t,sensor:!0})),n=[...e.colliders??[],...i],r=[...t.colliders??[],...o.colliders??[],...n];return{...t,...o,observation:{...t.observation,...o.observation},...r.length>0&&{colliders:r}}}function _s(t){const e=Is(t);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:e.left,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:t.width-e.rightInset,y2:e.top,thickness:e.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:t.floorY,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:t.width-e.rightInset,y1:e.top,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}}]}function Ps(t,e,o,i){return o?"function"==typeof o?o(t,e):t[o]??i:i}function Ls(t){return`gauntlet:${t}:core`}function $s(t,e){return`gauntlet:${t}:positive:${e}`}function Rs(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var Cs={left:28,top:76,rightInset:30,thickness:8};function Is(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return Cs;const o=Math.max(1,Math.min(t.width,e)),i=Math.max(2,.04*t.width);return{left:i,top:Math.max(2,.08*e),rightInset:i,thickness:Math.max(1,Math.min(4,.04*o))}}function Ts(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Os(t,e,o,i){const n=Is(i),r=Math.max(2,o+2),s=n.top+n.thickness/2+r,a=i.floorY-r,c=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:c(t,n.left+n.thickness/2+r,i.width-n.rightInset-n.thickness/2-r),y:c(e,s,a)}}function zs(t,e,o=1){const i=[...t].sort((t,e)=>t.localeCompare(e)),n=Math.max(0,i.indexOf(e));return{angle:.82*-Math.PI+(i.length>1?n/(i.length-1):.5)*Math.PI*.64,index:n,radius:(48+n%2*6)*o}}function Fs(t,e,o){const i=t.activePositiveIds.reduce((t,o)=>t+(e.get(o)?.value??1),0),n=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(o.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*i-8*r-1.2*t.delay-5*n))}function Ns(t){const e=function(t,e,o){const[i,n]=t,r=220>i||160>n,s=Math.round(.48*n),a=r?n-Math.max(3,Math.min(12,.1*n)):n-36,c=(e??[]).filter(t=>!1!==t.enabled),l=Math.max(1,c.length),u=.22*i,d=l>1?(.78*i-u)/(l-1):0,h=r?Math.max(Math.round(.12*i),.08*i+6):Math.max(Math.round(.14*i),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*n)):o),floorY:a,gates:c.map((t,e)=>({...t,id:t.id,x:t.x??Math.round(u+e*d),width:t.width??Math.max(r?8:54,Math.round(.07*i))})),graveyardX:Math.round(i*(r?.72:.84)),graveyardY:a-4,height:n,routeY:s,socketX:Math.round(i*(r?.82:.92)),startX:h,width:i}}(t.size??[900,520],t.gates,t.crashOffset??30),o=t.positiveProperties??[],i=new Map(o.map(t=>[t.id,t])),n=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,o,i,n){const r=Ps(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=i.map(t=>t.id),a=[...Ps(t,e,o.positiveAccessor,s)],c=[...Ps(t,e,o.negativeAccessor,[])].filter(t=>n.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ps(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ps(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:Ps(t,e,o.initialViability,100)}}(e,s,r,o,n);return{...a,viability:t.viability?.(a,{negativeProperties:n,positiveProperties:i})??Fs(a,i,n)}}),a=s.flatMap((o,r)=>{const s=function(t,e,o,i){const n=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(o),r=i?.(t,e,o)??{};return{...n,...r,startY:r.startY??r.routeY??n.startY,socketY:r.socketY??r.routeY??n.socketY,graveyardY:r.graveyardY??n.graveyardY}}(o,r,e,t.projectPlacement);return function(t,e,o,i,n,r,s){const a=Ts(o),c=Math.max(3,28*a),l=i.startX,u=i.startY+(i.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,i)??{},h=d.x??l,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},y=[{...d,id:Ls(t.id),x:h,y:f,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:c},spawnAt:d.spawnAt??t.startedAt,datum:p}],g=Os(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||c,o);y[0].x=g.x,y[0].y=g.y;for(const e of t.activePositiveIds){const i=n.get(e);if(!i)continue;const r=zs(t.activePositiveIds,e,a),s=i.radius??Math.max(2,10*a),c=Os(g.x+Math.cos(r.angle)*r.radius,g.y+Math.sin(r.angle)*r.radius,s,o);y.push({id:$s(t.id,e),x:c.x,y:c.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:i.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:i,sourceDatum:t.datum},springs:!1===i.spring?[]:[{target:{type:"body",bodyId:Ls(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...i.spring??{}}]})}return t.negativeIds.forEach((e,i)=>{const n=r.get(e);n&&y.push(function(t,e,o,i,n,r,s){const a=Ts(r),c=e.radius??Math.max(2,7.2*a),l=Os(i+(o%4*12-12)*a,n+(54+12*Math.floor(o/4))*a,c,r);return{id:Rs(t.id,e.id,o),x:l.x,y:l.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:c},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:Ls(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,n,i,g.x,g.y,o,d.spawnAt??t.startedAt))}),y}(o,r,e,s,i,n,t.coreBody)});return{layout:e,states:s,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:_s(e)}}}function Es(t=[]){const e=Object.create(null);for(const[o,i]of t)e[o]=i;return e}function Ds(...t){const e=Es();for(const o of t)for(const[t,i]of Object.entries(o??{}))e[t]=i;return e}function Bs(t){return Ds(t)}function Ws(t){return t.map(t=>({...t,sourceIds:t.sourceIds?[...t.sourceIds]:void 0,productIds:t.productIds?[...t.productIds]:void 0,relationIds:t.relationIds?[...t.relationIds]:void 0,outletIds:t.outletIds?[...t.outletIds]:void 0}))}function js(t){const e=Es(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:Bs(e.initialMetrics),metrics:Bs(e.metrics),productIds:[...e.productIds],history:Ws(e.history)}])),o=Es(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:Bs(e.metrics),sourceIds:[...e.sourceIds],history:Ws(e.history)}])),i=Es(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?Bs(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:i,input:{amount:t.input.amount,metrics:Bs(t.input.metrics)},metrics:Bs(t.metrics),loss:{amount:t.loss.amount,metrics:Bs(t.loss.metrics)},history:Ws(t.history)}}var Ys=1e-9;function Xs(t,e){return e>t?-1:t>e?1:0}function qs(t,e,o,i,n){return{severity:t,code:e,message:o,path:i,ids:n?[...n]:void 0}}function Gs(t){const e=new Set,o=new Set;for(const i of t)e.has(i)&&o.add(i),e.add(i);return[...o].sort(Xs)}function Vs(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[qs("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function Hs(t,e){for(const[o,i]of Object.entries(e))t[o]=Number(t[o]??0)+i}function Us(t,e,o="selector"){const i=[],n=Object.values(t.components),r=new Set(n.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&i.push(qs("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,o+".ids",s)),void 0===e.count||Number.isInteger(e.count)&&e.count>=0||i.push(qs("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),i.some(t=>"error"===t.severity))return{ids:[],diagnostics:i};const a=e.ids?new Set(e.ids):null,c=e.categories?new Set(e.categories):null,l=e.statuses?new Set(e.statuses):null,u=e.outletIds?new Set(e.outletIds):null;let d=n.filter(t=>!a||a.has(t.id)).filter(t=>!c||c.has(t.category)).filter(t=>!l||l.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Xs);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||i.push(qs("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:i}}function Ks(t,e,o={}){return{eventId:t.event.id,effectType:e.type,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,label:t.event.label,summary:t.event.summary,...o}}function Zs(t,e){const o={...e,eventId:t.event.id};t.materializations.push(o),t.observations.push({...o,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt})}function Qs(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(qs("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function Js(t,e,o){const i=Gs(e);e.length||t.diagnostics.push(qs("error","empty-source-list","A product requires at least one source component.",o)),i.length&&t.diagnostics.push(qs("error","duplicate-source",`Source ids may appear only once: ${i.join(", ")}.`,o,i));const n=e.filter(e=>!t.state.components[e]);n.length&&t.diagnostics.push(qs("error","unknown-component",`Unknown source component id${1===n.length?"":"s"}: ${n.join(", ")}.`,o,n));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(qs("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,o,r));const s=e.filter(e=>"consumed"===t.state.components[e]?.status&&!r.includes(e));return s.length&&t.diagnostics.push(qs("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,o,s)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}function ta(t,e,o,i,n){const r=i?.amount??0;(!Number.isFinite(r)||0>r||r>e+Ys)&&t.diagnostics.push(qs("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",n+".amount")),t.diagnostics.push(...Vs(i?.metrics,n+".metrics"));for(const[e,r]of Object.entries(i?.metrics??{}))(0>r||r>Number(o[e]??0)+Ys)&&t.diagnostics.push(qs("error","invalid-metric-loss",`Metric loss "${e}" must be non-negative and no greater than its sources.`,`${n}.metrics.${e}`));return!t.diagnostics.some(t=>"error"===t.severity)}function ea(t,e,o,i,n,r,s){return{id:t.id,label:t.label??t.id,description:t.description,category:t.category??"product",color:t.color,order:t.order,declaredAmount:t.amount,amount:r&&void 0!==t.amount?t.amount:o,metrics:r&&t.metrics?Ds(i,t.metrics):Bs(i),status:r?"complete":"forming",sourceIds:[...e],outletId:r?t.outletId??(n.outletIds.has("product")?"product":void 0):void 0,createdByEventId:n.event.id,createdAt:n.context.appliedAt,completedByEventId:r?n.event.id:void 0,completedAt:r?n.context.appliedAt:void 0,history:[s]}}function oa(t,e,o,i){void 0!==e.amount&&Math.abs(e.amount-o)>Ys&&t.diagnostics.push(qs("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,i,[e.id]))}function ia(t,e,o){const i=`events.${t.event.id}.effects.${o}`,n=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(qs("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,i+".state")),t.diagnostics.push(...Vs(e.metricsDelta,i+".metricsDelta")),Qs(t,e.outletId,i+".outletId");const o=Us(n,e.select,i+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>n.components[t].productIds.length);if(r.length&&t.diagnostics.push(qs("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,i+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=Ks(t,e,{sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of o.ids){const o=n.components[t];o.status=e.state,o.outletId=e.outletId,o.reason=e.reason,e.metricsDelta&&Hs(o.metrics,e.metricsDelta),o.history.push(s)}return n.history.push(s),void(o.ids.length&&Zs(t,{type:"retarget-component",sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0}))}if("set-relation"===e.type){const{relation:o}=e;o.id&&!n.relations[o.id]||t.diagnostics.push(qs("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,i+".relation.id",[o.id]));const r=function(t,e,o){const i=Gs(e),n=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(qs("error","insufficient-relation-sources","A relation requires at least two source components.",o)),i.length&&t.diagnostics.push(qs("error","duplicate-source",`Relation source ids must be unique: ${i.join(", ")}.`,o,i)),n.length&&t.diagnostics.push(qs("error","unknown-component",`Relation references unknown source component${1===n.length?"":"s"}: ${n.join(", ")}.`,o,n)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,o.sourceIds,i+".relation.sourceIds");if(t.diagnostics.push(...Vs(o.metrics,i+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;n.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?Bs(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=Ks(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return n.history.push(s),void Zs(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Gs(e.relationIds),r=e.relationIds.filter(t=>!n.relations[t]),s=e.relationIds.filter(t=>"resolved"===n.relations[t]?.status);if(o.length&&t.diagnostics.push(qs("error","duplicate-relation","Relation ids must be unique.",i+".relationIds",o)),r.length&&t.diagnostics.push(qs("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,i+".relationIds",r)),s.length&&t.diagnostics.push(qs("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,i+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const o of e.relationIds){const i=n.relations[o];i.status="resolved",i.resolution=e.resolution,i.resolvedByEventId=t.event.id,i.resolvedAt=t.context.appliedAt,i.reason=e.reason}const a=Ks(t,e,{relationIds:[...e.relationIds]});return n.history.push(a),void Zs(t,{type:"resolve-relation",relationIds:[...e.relationIds]})}if("combine"===e.type||"contribute"===e.type){const o=t.productDefinitions.get(e.productId);o||t.diagnostics.push(qs("error","unknown-product",`Product "${e.productId}" has no declared mold.`,i+".productId",[e.productId]));const r=n.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(qs("error","duplicate-product",`Product "${e.productId}" has already been formed.`,i+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(qs("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,i+".productId",[e.productId]));const s=Js(t,e.sourceIds,i+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,c=function(t,e,o,i){if(!e?.length)return[];const n=Gs(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),c=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return n.length&&t.diagnostics.push(qs("error","duplicate-relation","Basis relations must be unique.",i,n)),r.length&&t.diagnostics.push(qs("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,i,r)),s.length&&t.diagnostics.push(qs("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,i,s)),c.length&&t.diagnostics.push(qs("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${c.join(", ")}.`,i,c)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,i+".basisRelationIds");if(!s||!c||!o||t.diagnostics.some(t=>"error"===t.severity))return;const l=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e=Es();for(const o of t)Hs(e,o.metrics);return e}(s);if(!ta(t,l,u,e.loss,i+".loss"))return;const d=l-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[i,n]of Object.entries(o?.metrics??{}))e[i]=Number(e[i]??0)-n,t.state.loss.metrics[i]=Number(t.state.loss.metrics[i]??0)+n}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,f=Ks(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&oa(t,o,d,i+".productId"),p=ea(o,e.sourceIds,d,u,t,h,f),h&&!Qs(t,p.outletId,i+".productId"))return;n.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,Hs(p.metrics,u),p.history.push(f);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(f);return n.history.push(f),function(t,e){if(e.length){for(const o of e)o.status="resolved",o.resolution="combined",o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt;Zs(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,c),Zs(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:p.outletId?[p.outletId]:void 0}),void(h&&Zs(t,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===e.type){const o=n.products[e.productId];return o?void function(t,e,o,i,n,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!Qs(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(qs("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(oa(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=Ds(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=i,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const c=Ks(t,n,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(c),t.state.history.push(c),Zs(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,o,e.outletId,e.reason,e,i):void t.diagnostics.push(qs("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,i+".productId",[e.productId]))}if("split"===e.type){const o=Js(t,[e.sourceId],i+".sourceId");e.products.length||t.diagnostics.push(qs("error","empty-split","A split requires at least one product allocation.",i+".products"));const r=e.products.map(t=>t.productId),s=Gs(r);s.length&&t.diagnostics.push(qs("error","duplicate-product","Split product ids must be unique.",i+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),c=r.filter((t,e)=>!a[e]),l=r.filter(t=>n.products[t]);c.length&&t.diagnostics.push(qs("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,i+".products",c)),l.length&&t.diagnostics.push(qs("error","duplicate-product",`Split products already exist: ${l.join(", ")}.`,i+".products",l));for(const[o,n]of e.products.entries())void 0===n.amount||Number.isFinite(n.amount)&&n.amount>=0||t.diagnostics.push(qs("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${i}.products.${o}.amount`)),t.diagnostics.push(...Vs(n.metrics,`${i}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!ta(t,u.amount,u.metrics,e.loss,i+".loss"))return;const d=u.amount-(e.loss?.amount??0),h=e.products.map((t,e)=>t.amount??a[e]?.amount),f=h.filter(t=>void 0!==t).length;if(0!==f&&f!==h.length)return void t.diagnostics.push(qs("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",i+".products"));const p=f?h:e.products.map(()=>d/e.products.length),y=p.reduce((t,e)=>t+e,0);if(Math.abs(y-d)>Ys)return void t.diagnostics.push(qs("error","split-amount-mismatch",`Split allocations total ${y}, but ${d} remains after loss.`,i+".products"));const g=Bs(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))g[t]=Number(g[t]??0)-o;const m=Ks(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],c=d>Ys?p[r]/d:1/e.products.length,l=Es(Object.entries(g).map(([t,e])=>[t,e*c])),h=o.metrics??s.metrics??l,f=ea({...s,amount:p[r],metrics:h},[u.id],p[r],Bs(h),t,!0,m);Qs(t,f.outletId,`${i}.products.${r}.productId`)&&(n.products[f.id]=f)}),t.diagnostics.some(t=>"error"===t.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),n.loss.amount+=e.loss?.amount??0;for(const[t,o]of Object.entries(e.loss?.metrics??{}))n.loss.metrics[t]=Number(n.loss.metrics[t]??0)+o;n.history.push(m),Zs(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)Zs(t,{type:"complete-product",sourceIds:[u.id],productIds:[e],outletIds:n.products[e].outletId?[n.products[e].outletId]:void 0});return}if("eject"===e.type){Qs(t,e.outletId,i+".outletId");const o=Us(n,e.select,i+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>n.components[t].productIds.length);if(r.length&&t.diagnostics.push(qs("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,i+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=Ks(t,e,{sourceIds:o.ids,outletIds:[e.outletId]});for(const t of o.ids){const o=n.components[t];o.status=e.state??"ejected",o.outletId=e.outletId,o.reason=e.reason,o.history.push(s)}return n.history.push(s),void(o.ids.length&&Zs(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...Vs(e.metricsDelta,i+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)Hs(n.metrics,e.metricsDelta);else if("components"in e.target){const r=Us(n,e.target.components,i+".target.components");if(t.diagnostics.push(...r.diagnostics),t.diagnostics.some(t=>"error"===t.severity))return;o=r.ids;for(const t of r.ids)Hs(n.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Gs(r),s=r.filter(t=>!n.products[t]);if(o.length&&t.diagnostics.push(qs("error","duplicate-product","Metric target product ids must be unique.",i+".target.productIds",o)),s.length&&t.diagnostics.push(qs("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,i+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)Hs(n.products[t].metrics,e.metricsDelta)}return void n.history.push(Ks(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(n.outcome=e.outcome,n.summary=e.summary,n.history.push(Ks(t,e)),t.observations.push({type:"crucible-outcome",eventId:t.event.id,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,outcome:e.outcome})):t.diagnostics.push(qs("error","invalid-outcome","Outcome must be a non-empty string.",i+".outcome"))}function na(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[qs("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const i=js(t),n={state:i,event:e,context:o,productDefinitions:new Map(o.products.map(t=>[t.id,t])),outletIds:new Set(o.outlets.map(t=>t.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,i]of e.effects.entries())if(ia(n,i,o),n.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:n.diagnostics};return i.elapsed=Math.max(i.elapsed,o.appliedAt),i.phaseId=o.phaseId,i.eventsApplied.push(e.id),n.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:i,materializations:n.materializations,observations:n.observations,diagnostics:n.diagnostics}}var ra=[900,520],sa=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],aa=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),ca=1e-9;function la(t,e){return e>t?-1:t>e?1:0}function ua(t,e,o,i,n){return{severity:t,code:e,message:o,path:i,ids:n?[...n]:void 0}}function da(t){const e=new Set,o=new Set;for(const i of t)e.has(i)&&o.add(i),e.add(i);return[...o].sort(la)}function ha(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function fa(t,e,o,i,n,r){if(!o)return i;try{return("function"==typeof o?o(t,e):t[o])??i}catch(t){return n.push(ua("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),i}}function pa(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(ua("error","invalid-metrics","Metrics must be a numeric object.",o)),Es();const i=Es();for(const[n,r]of Object.entries(t)){const t=ha(r);null!=t?i[n]=t:e.push(ua("error","invalid-metric",`Metric "${n}" must be finite.`,`${o}.${n}`))}return i}function ya(t){return t.map((t,e)=>({outlet:t,index:e})).sort((t,e)=>(t.outlet.order??t.index)-(e.outlet.order??e.index)||t.index-e.index).map(({outlet:t})=>({...t}))}function ga(t){const{id:e,orientation:o,fixed:i,start:n,end:r,openings:s,thickness:a,friction:c,restitution:l}=t,u=function(t,e,o){const i=o.map(([o,i])=>[Math.max(t,Math.min(o,i)),Math.min(e,Math.max(o,i))]).filter(([t,e])=>e>t+ca).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),n=[];let r=t;for(const[t,e]of i)t>r+ca&&n.push([r,t]),r=Math.max(r,e);return e>r+ca&&n.push([r,e]),n}(n,r,s);return u.map(([t,n],r)=>({id:1===u.length?e:`${e}:${r}`,friction:c,restitution:l,shape:"horizontal"===o?{type:"segment",x1:t,y1:i,x2:n,y2:i,thickness:a}:{type:"segment",x1:i,y1:t,x2:i,y2:n,thickness:a}}))}function ma(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function xa(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?ma(t):1}function ba(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:xa(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function va(t){return"crucible:component:"+encodeURIComponent(t)}function wa(t,e,o,i){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const n=Math.min(...e,t),r=Math.max(...e,t);return r-n>ca?i[0]+(i[1]-i[0])*Math.sqrt(Math.max(0,t-n)/(r-n)):(i[0]+i[1])/2}function ka(t,e){const o=Math.max(.25,Math.min(1,e.width/900,e.height/520)),i=t?.[0]??7*o,n=t?.[1]??18*o,r=Math.max(1,Math.min(i,n));return[r,Math.max(r,Math.max(i,n))]}function Sa(t,e){if(!t)return[];const o=Math.min(t,Math.max(1,Math.ceil(Math.sqrt(t*Math.max(.5,e.width/Math.max(1,e.height)))))),i=Math.max(1,Math.ceil(t/o));return Array.from({length:t},(t,n)=>({x:e.x+e.width/o*(n%o+.5),y:e.y+(Math.floor(n/o)+.5)*(e.height/i)}))}function Aa(t){return t.outletId?t.outletId:"failed"===t.status?"failed":"recovered"===t.status?"recovered":"retained"===t.status?"retained":"ejected"===t.status?"residue":void 0}function Ma(t,e){return t.outlets.find(t=>t.id===e)||{x:t.chamber.x+.18*t.chamber.width,y:t.chamber.y+.2*t.chamber.height,width:.64*t.chamber.width,height:.6*t.chamber.height}}function _a(t,e,o={}){const i=Object.values(t.products).sort((t,e)=>la(t.id,e.id)),n=Object.values(t.components).sort((t,e)=>la(t.id,e.id)),r=[...n.map(t=>t.amount),...i.map(t=>t.amount)],s=ka(o.radiusRange,e),a=function(t,e){const o=new Map;for(const e of t){const t=e.outletId??"__chamber__",i=o.get(t)??[];i.push(e),o.set(t,i)}const i=new Map;for(const[t,n]of o){n.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||la(t.id,e.id));const o=Sa(n.length,Ma(e,"__chamber__"===t?void 0:t));n.forEach((t,e)=>i.set(t.id,o[e]))}return i}(i,e),c=i.map(t=>{const i=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},n=1.28*wa(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(l=t.id,"crucible:product:"+encodeURIComponent(l)),x:i.x,y:i.y,mass:Math.max(.25,n*n*.018),bodyCollisions:!1,shape:{type:"circle",radius:n},datum:c};var l}),l=new Map;for(const t of n.filter(t=>!t.productIds.length)){const e=Aa(t)??"__chamber__",o=l.get(e)??[];o.push(t),l.set(e,o)}const u=new Map;for(const[t,o]of l){const i=Sa(o.length,Ma(e,"__chamber__"===t?void 0:t));o.forEach((t,e)=>u.set(t.id,i[e]))}return[...n.map(t=>{let i=u.get(t.id);if(t.productIds.length){const o=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(o.length){i={x:o.reduce((t,e)=>t+e.x,0)/o.length,y:o.reduce((t,e)=>t+e.y,0)/o.length};const n=ma(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));i={x:i.x+Math.cos(n)*r,y:i.y+Math.sin(n)*r}}}i??(i={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const n=wa(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:va(t.id),x:i.x,y:i.y,mass:Math.max(.25,n*n*.015),shape:{type:"circle",radius:n},datum:c}}),...c]}var Pa=_a;function La(t){return Array.isArray(t)?t.map(La):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>la(t,e)).map(([t,e])=>[t,La(e)])):t}function $a(t,e=t.duration){const o=function(t,e){const o=ha(e)??0,i=Math.max(0,Math.min(t.duration,o));if(!t.phases.length)return{elapsed:i,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const n=i>=t.duration-ca,r=n?t.phases[t.phases.length-1]:t.phases.find(t=>i>=t.start&&t.end>i)??t.phases[0];return{elapsed:i,phaseId:r.id,phaseIndex:r.index,phaseElapsed:n?r.duration:Math.max(0,i-r.start),complete:n}}(t,e);let i=js(t.initialState);const n=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+ca)break;const a=na(i,e,{phaseId:e.phaseId,authoredAt:e.authoredAt,appliedAt:e.authoredAt,products:t.products,outlets:t.outlets});n.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(i=a.state)}return i.elapsed=o.elapsed,i.phaseId=o.phaseId,i.phaseIndex=o.phaseIndex,i.phaseElapsed=o.phaseElapsed,i.complete=o.complete,o.complete&&"in_process"===i.outcome&&(i.outcome="complete"),i.playing=!1,{state:i,diagnostics:n,materializations:r,observations:s}}function Ra(t){const e=function(t){const e=[];t.length||e.push(ua("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=da(t.map(t=>t.id));o.length&&e.push(ua("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let i=0;return{phases:t.map((t,o)=>{const n=ha(t.duration),r=null!=n&&n>0?n:0;t.id.trim()||e.push(ua("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=n&&n>0||e.push(ua("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[t.id])),void 0===t.intensity||Number.isFinite(t.intensity)||e.push(ua("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.intensity`,[t.id]));const s={...t,duration:r,intensity:void 0===t.intensity?.5:Number.isFinite(t.intensity)?Math.max(0,Math.min(1,t.intensity)):.5,motion:t.motion??"hold",index:o,start:i,end:i+r};return i=s.end,s}),diagnostics:e}}(t.phases),o=e.phases.at(-1)?.end??0,i=ya(t.outlets??sa),n=(t.products??[]).map(t=>({...t,metrics:t.metrics?Ds(t.metrics):void 0})),r=function(t,e,o){const i=[],n=da(t.map(t=>t.id));n.length&&i.push(ua("error","duplicate-event-id",`Event ids must be unique: ${n.join(", ")}.`,"events",n));const r=[];return t.forEach((t,n)=>{let s,a,c;if(t.id.trim()||i.push(ua("error","invalid-event-id","Event ids may not be empty.",`events.${n}.id`)),"time"in t.at&&void 0!==t.at.time){const r=ha(t.at.time);if(null==r||0>r||r>o+ca)return void i.push(ua("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${n}.at.time`,[t.id]));s=Math.max(0,Math.min(o,r));const l=function(t,e,o){const i=t.find(t=>ca>=Math.abs(t.start-o));if(i)return{phase:i,boundaryRank:1};const n=t.find(t=>o>=t.start&&t.end>o);return n?{phase:n,boundaryRank:0}:ca>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=l.phase,c=l.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void i.push(ua("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${n}.at.phaseId`,[t.id,t.at.phaseId]));const o=t.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void i.push(ua("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${n}.at.progress`,[t.id]));s=a.start+a.duration*o,c=0===o?1:0}a?r.push({...t,index:n,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:c}):i.push(ua("error","event-without-phase","Event could not be assigned to a phase.",`events.${n}.at`,[t.id]))}),r.sort((t,e)=>t.authoredAt-e.authoredAt||t.boundaryRank-e.boundaryRank||t.index-e.index),{events:r,diagnostics:i}}(t.events??[],e.phases,o),s=function(t){const e=[],o=Es(),i=[];let n=0;const r=Es();t.data.forEach((s,a)=>{const c=(s.id??"component-"+a)+"",l=((fa(s,a,t.idAccessor,c,e,`data.${a}.id`)??c)+"").trim();if(!l)return void e.push(ua("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));i.push(l);const u=ha(fa(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(ua("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=pa(fa(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=fa(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=aa.has(f)?f:"active";aa.has(f)||e.push(ua("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[l]));const y=fa(s,a,t.labelAccessor,(s.label??s.name??l)+"",e,`data.${a}.label`)+"",g=fa(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,l)||(o[l]={id:l,label:y,category:g,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:Ds(h),metrics:Ds(h),productIds:[],history:[]},n+=d,function(t,e){for(const[o,i]of Object.entries(e))t[o]=Number(t[o]??0)+i}(r,h))});const s=da(i);s.length&&e.push(ua("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=pa(t.metrics??{},e,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:t.phases[0]?.id??"",phaseIndex:t.phases.length?0:-1,playing:!1,complete:0===t.phases.length,outcome:"in_process",eventsApplied:[],components:o,products:Es(),relations:Es(),input:{amount:n,metrics:r},metrics:a,loss:{amount:0,metrics:Es()},history:[]},diagnostics:e}}(t),a=function(t=ra,e=sa){const o=Math.max(1,ha(t[0])??900),i=Math.max(1,ha(t[1])??520),n=360>o||260>i,r=n?Math.max(4,.035*Math.min(o,i)):20,s=n?Math.max(10,.075*i):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},c=n?Math.max(16,.14*i):Math.min(78,.16*i),l={x:r,y:i-r-c,width:Math.max(1,o-2*r),height:c},u=n?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(n?12:38),h=l.y-(n?10:34),f={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,n?84:180)),y={x:f.x+(f.width-p)/2,y:f.y-(n?10:24),width:p,height:n?12:28},g=ya(e),m={left:g.filter(t=>"left"===(t.side??"bottom")),right:g.filter(t=>"right"===t.side),bottom:g.filter(t=>"bottom"===(t.side??"bottom"))},x=[],b=(t,e)=>{const i=Math.max(8,u-1.5*r),s=f.height/Math.max(1,e.length);e.forEach((e,a)=>{x.push({...e,side:t,x:"left"===t?r:o-r-i,y:f.y+a*s,width:i,height:Math.max(8,s-(n?2:8))})})};b("left",m.left),b("right",m.right);const v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{x.push({...t,side:"bottom",x:f.x+e*v,y:f.y+f.height+(n?2:7),width:Math.max(8,v-(n?2:8)),height:Math.max(8,l.y-f.y-f.height-(n?4:12))})}),x.sort((t,e)=>g.findIndex(e=>e.id===t.id)-g.findIndex(t=>t.id===e.id)),{width:o,height:i,phaseRail:a,chamber:f,mouth:y,projection:l,outlets:x}}(t.size??ra,i),c=function(t){const{chamber:e,mouth:o}=t,i=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),n=Math.max(e.x,o.x),r=Math.min(e.x+e.width,o.x+o.width),s={left:t.outlets.filter(t=>"left"===t.side),right:t.outlets.filter(t=>"right"===t.side),bottom:t.outlets.filter(t=>"bottom"===t.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:e.x,y1:e.y,x2:n,y2:e.y,thickness:i}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:e.y,x2:e.x+e.width,y2:e.y,thickness:i}}];a.push(...ga({id:"crucible:wall:left",orientation:"vertical",fixed:e.x,start:e.y,end:e.y+e.height,openings:s.left.map(t=>[t.y,t.y+t.height]),thickness:i,friction:.46,restitution:.12}),...ga({id:"crucible:wall:right",orientation:"vertical",fixed:e.x+e.width,start:e.y,end:e.y+e.height,openings:s.right.map(t=>[t.y,t.y+t.height]),thickness:i,friction:.46,restitution:.12}),...ga({id:"crucible:wall:bottom",orientation:"horizontal",fixed:e.y+e.height,start:e.x,end:e.x+e.width,openings:s.bottom.map(t=>[t.x,t.x+t.width]),thickness:i,friction:.5,restitution:.08}));for(const e of t.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(e.id),sensor:!0,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}});return a}(a),l=function(t,e){const o=[],i=new Set(e.map(t=>t.id)),n=da(e.map(t=>t.id)),r=da(t.map(t=>t.id));return n.length&&o.push(ua("error","duplicate-outlet-id",`Outlet ids must be unique: ${n.join(", ")}.`,"outlets",n)),r.length&&o.push(ua("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(ua("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(ua("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(ua("error","invalid-product-id","Product ids may not be empty.",`products.${e}.id`)),void 0===t.amount||Number.isFinite(t.amount)&&t.amount>=0||o.push(ua("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||i.has(t.outletId)||o.push(ua("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),pa(t.metrics??{},o,`products.${e}.metrics`)}),o}(n,i),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>la(t.id,e.id)).map(t=>({id:t.id,label:t.label,category:t.category,amount:t.amount,metrics:t.metrics,status:t.status})),phases:e.phases.map(({id:t,duration:e,label:o,description:i,intensity:n,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:o,description:i,intensity:n,motion:r,color:s,metrics:a})),products:n,outlets:i,events:r.events.map(({id:t,label:e,description:o,summary:i,authoredAt:n,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:o,summary:i,authoredAt:n,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(La(d)));var d;const h=function(t,e,o={}){const i=Object.values(t.components).sort((t,e)=>la(t.id,e.id)),n=i.map(t=>t.amount),r=ka(o.radiusRange,e),s=function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(xa(o.seed)),a=e.mouth.x+e.mouth.width/2,c=e.chamber.y+Math.max(18,.18*e.chamber.height),l=Math.max(4,.28*e.chamber.width),u=Math.max(4,.12*e.chamber.height);return i.map((t,e)=>{const d=e/Math.max(1,i.length)*Math.PI*2+.18*(s()-.5),h=wa(t.amount,n,o.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:va(t.id),x:a+Math.cos(d)*l*(.45+.45*s()),y:c+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...l],p={phases:e.phases,events:r.events,products:n,outlets:i,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:c,config:ba(t.seed,c),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},y=$a(p),g=Object.values(y.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=g.length?[ua("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return p.terminalState=y.state,p.terminalSpawns=Pa(y.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...y.diagnostics,...m],p}import*as Ca from"react";import{curveMonotoneX as Ia,curveMonotoneY as Ta,curveCardinal as Oa,curveCatmullRom as za,curveStep as Fa,curveStepBefore as Na,curveStepAfter as Ea,curveBasis as Da,curveNatural as Ba}from"d3-shape";function Wa(t){switch(t){case"monotoneX":return Ia;case"monotoneY":return Ta;case"cardinal":return Oa;case"catmullRom":return za;case"step":return Fa;case"stepBefore":return Na;case"stepAfter":return Ea;case"basis":return Da;case"natural":return Ba;default:return null}}import{jsx as ja,jsxs as Ya}from"react/jsx-runtime";function Xa(t){return Number.isFinite(t)?1e3>Math.abs(t)?Number.isInteger(t)?t+"":t.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):t.toLocaleString():"0"}function qa(t,e,o,i){const n=t.datum;if(!n?.__crucible)return;const r="circle"===t.shape.type?t.shape.radius:8,s="string"==typeof e.fill?e.fill:"product"===n.kind?"#b8792d":"#356b63",a="string"==typeof e.stroke?e.stroke:"#26323a",c="number"==typeof e.strokeWidth?e.strokeWidth:1.25,l="number"==typeof e.opacity?e.opacity:.96,u=i?`${i}-crucible-body-${o}`:"crucible-body-"+o;if("product"===n.kind){const e=Array.from({length:6},(e,o)=>{const i=-Math.PI/2+o/6*Math.PI*2;return`${t.x+Math.cos(i)*r},${t.y+Math.sin(i)*r}`}).join(" "),o=u+"-glow";return Ya(Ca.Fragment,{children:[ja("defs",{children:ja("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:ja("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),ja("polygon",{points:e,fill:s,stroke:a,strokeWidth:c,opacity:l,filter:`url(#${o})`}),ja("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:c,opacity:.72*l})]},u)}return Ya(Ca.Fragment,{children:[ja("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:c,opacity:l}),ja("circle",{cx:t.x-.25*r,cy:t.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as Ga,jsx as Va,jsxs as Ha}from"react/jsx-runtime";var Ua="var(--semiotic-text, #26323a)",Ka="var(--semiotic-text-secondary, #6c7377)",Za="var(--semiotic-primary, #b8792d)",Qa="var(--semiotic-danger, #9f3d35)",Ja="var(--semiotic-success, #356b63)";function tc(t){const{x:e,y:o,width:i,height:n}=t.chamber,r=Math.min(.14*i,48),s=o+n;return[`M ${e} ${o}`,`L ${e+r} ${s-.16*n}`,`Q ${e+i/2} ${s+.1*n} ${e+i-r} ${s-.16*n}`,`L ${e+i} ${o}`].join(" ")}function ec({layout:t,phases:e,state:o,compact:i=!1}){const n=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return Ha("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[Ha("defs",{children:[Ha("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[Va("stop",{offset:"0",stopColor:Za,stopOpacity:"0.03"}),Va("stop",{offset:"0.66",stopColor:Za,stopOpacity:"0.1"}),Va("stop",{offset:"1",stopColor:Qa,stopOpacity:"0.18"})]}),Va("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:Va("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Ua,strokeOpacity:"0.08",strokeWidth:"1"})})]}),Va("rect",{x:t.chamber.x,y:t.chamber.y,width:t.chamber.width,height:t.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:Ua,strokeOpacity:"0.52",strokeWidth:i?1:2.2}),Va("path",{d:tc(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),Va("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:Ua,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:i?2:5}),i?null:Va("g",{"data-testid":"crucible-phase-rail",children:e.map((i,r)=>{const s=e.slice(0,r).reduce((t,e)=>t+Math.max(0,e.duration),0),a=t.phaseRail.x+s/n*t.phaseRail.width,c=Math.max(0,i.duration)/n*t.phaseRail.width,l=i.id===o.phaseId,u=o.phaseIndex>r||o.complete;return Ha("g",{children:[Va("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,c-2),height:t.phaseRail.height,rx:2,fill:l?i.color??Za:u?Ja:Ua,fillOpacity:l?.68:u?.28:.09}),46>c?null:Va("text",{x:a+c/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:l?Ua:Ka,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:l?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(i.label??i.id).toUpperCase()})]},i.id)})}),t.outlets.map(t=>Ha("g",{children:[Va("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?Qa:Ja),fillOpacity:"0.1",stroke:t.color??("left"===t.side?Qa:Ja),strokeDasharray:"3 3",strokeOpacity:"0.62"}),i?null:Va("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:Ka,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function oc({rows:t,layout:e,projection:o,amountLabel:i}){if(!t.length)return null;const n=o.measure??"count",r=t.map(t=>Math.max(0,function(t,e){return"count"===e?t.count:"amount"===e?t.amount:Number(t.metrics[e]??0)}(t,n))),s=Math.max(1,...r),a=e.projection.width/Math.max(1,t.length),c=e.projection.height>48?21:4,l=Math.max(5,e.projection.height-c-5);return Va("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:t.map((t,o)=>{const u=r[o],d=Math.max(u>0?2:0,u/s*l),h=e.projection.x+o*a+.18*a;return Ha("g",{children:[Va("rect",{x:h,y:e.projection.y+l-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?Qa:"complete"===t.status?Za:Ja,fillOpacity:"0.68"}),c>4&&a>=34?Ha(Ga,{children:[Va("text",{x:h+.32*a,y:e.projection.y+l+10,fill:Ka,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),Ha("text",{x:h+.32*a,y:e.projection.y+l+19,fill:Ua,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Xa(u),"amount"===n&&i?" "+i:""]})]}):null]},t.key)})})}function ic(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}import{Fragment as nc,jsx as rc,jsxs as sc}from"react/jsx-runtime";function ac(t,e,o,i,n){const r=Array.isArray(n)?n:n?[n]:[];if(!1!==o||0!==r.length)return({size:n})=>{const s=[Number(n[0])||700,Number(n[1])||420],a=Cn(s),c=Math.max(2,Math.round(e)),l=a.plot.width/c,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[f,p]=i?.valueExtent??[0,c],y=p===f?1:p-f,g=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*l).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return sc("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?sc(nc,{children:[Array.from({length:c+1},(t,e)=>{const o=a.plot.x+e*l;return rc("line",{"data-testid":"galton-board-bin-wall",x1:o,x2:o,y1:a.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+e)}),rc("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),rc("path",{d:g,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?rc("text",{x:a.plot.x+(e+.5)*l,y:Math.max(a.plot.y+10,u-t.value/d*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.value},`${t.label}-${e}`):null)]}):null,r.map((t,e)=>{const o=Number(t.value);if(!Number.isFinite(o))return null;const i=a.plot.x+Math.max(0,Math.min(1,(o-f)/y))*a.plot.width,n=t.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===t.labelPosition?Math.min(s[1]-8,u+16):a.plot.y+16;return sc("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[rc("line",{x1:i,x2:i,y1:a.plot.y+8,y2:u-4,stroke:n,strokeDasharray:t.strokeDasharray??"6 5",strokeWidth:t.strokeWidth??2}),null==t.label?null:rc("text",{x:Math.min(a.plot.x+a.plot.width-4,i+6),y:r,fill:n,fontSize:10,fontWeight:700,children:t.label})]},`galton-reference-${e}-${o}`)})]})}}function cc(t,e,o){if(!1!==o&&e)return({size:o})=>{const i=[Number(o[0])||760,Number(o[1])||360],n=Cn(i),r=Math.max(1,e.windowCount),s=e.plot??n.plot,a=e.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=e.windowPlot??s,l=c.width/r,u=s.y+s.height,d=s.y+.48*s.height,h=e.lidSegments[0]?.y1??d,f=e.windowStart,p=e.windowStart+r*e.windowSize,y=c.x+Math.max(0,Math.min(1,p===f?0:(e.watermarkValue-f)/(p-f)))*c.width;return sc("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:[rc("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?sc("g",{children:[rc("rect",{x:a.x,y:h,width:a.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),rc("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(o,n)=>{const r=t[n],s=c.x+n*l,a=e.closedWindowCount>n,h=r?.secondary??0;return sc("g",{children:[rc("rect",{x:s,y:d,width:l,height:u-d,fill:a?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?e.lidSegments.filter(t=>t.windowIndex===n).map(t=>rc("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},t.id)):null,sc("text",{x:s+l/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),rc("text",{x:s+l/2,y:Math.min(i[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+n)}),e.lidSegments.filter(t=>null==t.windowIndex).map(t=>rc("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},t.id)),rc("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),rc("line",{"data-testid":"event-drop-watermark",x1:y,x2:y,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),sc("text",{x:Math.min(s.x+s.width-4,y+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*e.watermarkValue)/100]}),e.lateCount>0?sc("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[e.lateCount," late"]}):null]})}}function lc(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const i=[Number(o[0])||700,Number(o[1])||380],n=Cn(i),r=ls(n.plot,t.length,e),s=n.plot.y+n.plot.height;return sc("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:[rc("line",{x1:n.plot.x,x2:n.plot.x+n.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),t.map((t,e)=>{const o=Math.min(n.plot.height,r.pileHeight(t.value)),a=r.tubeWidth,c=r.centerX(e),l=s-o;return sc("g",{children:[rc("rect",{x:c-a/2,y:l,width:a,height:o,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),rc("text",{x:c,y:Math.max(n.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),rc("text",{x:c,y:Math.min(i[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${e}`)})]})}}function uc(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function dc(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],i=Cn(o),n=i.plot.y+i.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,c=[{label:uc(r),x:t.xRange[0]},{label:uc(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:uc(s),x:t.xRange[1]}];return sc("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[t.groups.map(t=>sc("g",{children:[rc("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:t.y,y2:t.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),rc("text",{x:i.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),sc("text",{x:i.plot.x+i.plot.width-4,y:t.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",t.count]})]},t.label)),rc("line",{x1:t.xRange[0],x2:t.xRange[1],y1:n,y2:n,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(t=>sc("g",{children:[rc("line",{x1:t.x,x2:t.x,y1:n,y2:n+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),rc("text",{x:t.x,y:Math.min(o[1]-8,n+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${t.x}`))]})}}import{Fragment as hc,jsx as fc,jsxs as pc}from"react/jsx-runtime";var yc={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"}};function gc(t,e,o){return Math.max(e,Math.min(o,t))}function mc(t){return 6.2*t.length}function xc(t,e){const o=t.trim();if(e>=o.length)return o;if(1>=e)return o.slice(0,1);const i=o.split(/\s+/).filter(Boolean).map(t=>t[0]).join("").toUpperCase();return i.length>1&&e>=i.length?i:e>3?o.slice(0,Math.max(1,e-2))+"..":o.slice(0,e).toUpperCase()}function bc(t,e,o="auto"){const i=Math.max(1,Math.floor(e/6.2)),n="compact"===o?xc(t,i):"full"===o?t:mc(t)>e?xc(t,i):t;return{text:n,textLength:mc(n)>e?Math.max(4,e):void 0}}import{jsx as vc}from"react/jsx-runtime";function wc(t,e,o={},i){if(!1===e||!t)return;const{volume:n,stages:r,groups:s,groupCompletion:a}=t,c=new Map(n.stages.map(t=>[t.id,t])),l=new Map(a.map(t=>[t.id,t]));return({size:t})=>{const e=Number(t[0])||n.width,a=Number(t[1])||n.height,u=r.map(t=>{const e=c.get(t.id),i=o["process-stage-"+t.id];return{id:t.id,label:t.label,x0:e?.x0??t.x-t.width/2,x1:(e?.x0??t.x-t.width/2)+(e?.width??t.width),x:t.x,width:e?.width??t.width,count:t.count,capacity:t.capacity,absorb:t.absorb,portalTarget:t.portalTarget,queueDepth:i?.queueDepth,processed:i?.processedCount}}),d=s.map(t=>{const e=l.get(t.id);return{id:t.id,label:t.label??t.id,x:t.anchor?.x??t.x??0,y:t.anchor?.y??t.y??0,absorbed:e?.absorbed,total:e?.total,complete:e?.complete}});return function(t,e={}){const{showFlowSpine:o=!0,showStageCounts:i=!0,showCapacityBadges:n=!0,showGroupSockets:r=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=e,{width:l,height:u,left:d,right:h,topY:f,bottomY:p,midY:y,stages:g,groups:m=[]}=t,x=p-f;return pc("svg",{"aria-hidden":"true","data-testid":c,"data-outline-stages":a?"true":void 0,width:l,height:u,viewBox:`0 0 ${l} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",a?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[fc("defs",{children:pc("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[fc("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),fc("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),fc("rect",{x:0,y:0,width:l,height:u,fill:"url(#semiotic-process-floor)"}),fc("rect",{x:d-6,y:f-8,width:h-d+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}),o?fc("line",{x1:d+8,x2:h-8,y1:y,y2:y,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,g.map((t,e)=>{const o=function(t){return t.absorb?"absorb":t.portalTarget?"portal":null!=t.capacity?"capacity":"flow"}(t),r=yc[o],c=Math.max(12,t.width-8),l=gc(c-8,22,88),d=bc(t.label,Math.max(8,l-10),s),h="none"!==s&&c-8>=22,m=function(t){if(null!=t.capacity){const e=null!=t.queueDepth?" · q "+t.queueDepth:"";return t.capacityLabel?`${t.capacityLabel}${e}`:`cap ${Number.isInteger(t.capacity)?t.capacity+"":t.capacity.toFixed(1)}${e}`}return t.absorb?"absorb":t.portalTarget?"portal":"flow"}(t),b=bc(m,Math.max(16,c-10),"auto"),v=n&&!1!==t.showBadge&&c>=32,w=null!=t.count?`n=${t.count}${null!=t.processed?" done "+t.processed:""}`:"",k=bc(w,Math.max(16,c-8),"auto"),S=Math.max(30,f-15),A=S-13;return pc("g",{"data-stage":t.id,"data-role":o,children:[fc("rect",{className:"semiotic-process-chrome__stage-bay",x:t.x0+4,y:f+6,width:c,height:x-12,rx:10,fill:a?"none":r.fill,stroke:r.stroke,strokeWidth:a?1.85:"flow"===o?1:1.6}),g.length-1>e?fc("polygon",{points:`${t.x1-2},${y-7} ${t.x1+8},${y} ${t.x1-2},${y+7}`,fill:r.accent,opacity:.85}):null,h?pc(hc,{children:[fc("rect",{className:"semiotic-process-chrome__stage-label-bg",x:t.x-l/2,y:A,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:r.stroke}),pc("text",{x:t.x,y:S,textAnchor:"middle",fill:r.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[fc("title",{children:t.label}),d.text]})]}):null,v?pc("text",{x:t.x,y:f+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:[fc("title",{children:m}),b.text]}):null,i&&null!=t.count?pc("text",{x:t.x,y:Math.min(u-8,p+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:[fc("title",{children:w}),k.text]}):null]},t.id)}),r?m.map((t,e)=>{const o=t.total??0,i=t.absorbed??0,n=t.complete??(o>0&&i>=o),r=!n&&o>0&&i/o>=.75,s=n?"rgba(52, 211, 153, 0.35)":r?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=n?"#34d399":r?"#fbbf24":"var(--semiotic-border, #64748b)",c=o>0?`${i}/${o}${n?" shipped":r?" almost":""}`:"feature "+(e+1),l=gc(Math.max(54,mc(t.label)+18,mc(c)+16),54,104),u=bc(t.label,l-12,"auto"),d=bc(c,l-12,"auto");return pc("g",{"data-group":t.id,children:[fc("rect",{x:t.x-l/2,y:t.y-22,width:l,height:44,rx:10,fill:s,stroke:a,strokeWidth:1.5}),pc("text",{x:t.x,y:t.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[fc("title",{children:t.label}),u.text]}),pc("text",{x:t.x,y:t.y+12,textAnchor:"middle",fill:a,fontSize:9,fontWeight:700,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[fc("title",{children:c}),d.text]})]},t.id)}):null]})}({width:e,height:a,left:n.left,right:n.right,topY:n.topY,bottomY:n.bottomY,midY:n.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...i})}}function kc(t,e,o){if(!1===o||!e||0===t.length)return;const i=new Map(e.volume.stages.map(t=>[t.id,t]));return({size:o})=>{const n=[Number(o[0])||e.volume.width,Number(o[1])||e.volume.height],r=Cn(n),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),c=r.plot.y+6;return vc("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:e.stages.map((e,o)=>{const n=t[o];if(!n)return null;const r=i.get(e.id);if(!r)return null;const l=Math.max(2,n.value/s*a),u=Math.max(8,.35*r.width);return vc("rect",{x:r.x-u/2,y:c,width:u,height:l,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function Sc(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}import{jsx as Ac,jsxs as Mc}from"react/jsx-runtime";function _c(t,e){const{showNodeLabels:o,showSensors:i,showStaticFlow:n}=e;if(t&&(n||i||o))return({size:e})=>{const r=[Number(e[0])||760,Number(e[1])||420],s=Math.max(1,...t.links.map(t=>t.throughput)),a=new Set(t.nodes.map(t=>t.sensorId));return Mc("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[n?t.links.map(t=>{const e=3+t.throughput/s*16,o=t.path[Math.floor(t.path.length/2)];return Mc("g",{children:[Ac("path",{d:Sc(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),Ac("path",{d:Sc(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?Ac("text",{x:o.x,y:o.y-e/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:(i=t.throughput,i.toLocaleString(void 0,1e3>Math.abs(i)?{maximumFractionDigits:1}:{maximumFractionDigits:0}))}):null]},t.id);var i}):null,t.nodes.map(t=>Mc("g",{children:[i&&a.has(t.sensorId)?Ac("rect",{"data-testid":"physical-flow-sensor-overlay",x:t.x-12,y:t.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,n?Ac("circle",{cx:t.x,cy:t.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,o?Ac("text",{x:t.x,y:t.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:t.label}):null]},t.id))]})}}import{Fragment as Pc,jsx as Lc,jsxs as $c}from"react/jsx-runtime";function Rc({layout:t,compact:e,showLabels:o}){const i=e?Math.round(.14*t.height):Math.max(80,t.routeY-180),n=e?Math.max(6,Math.round(.72*t.height)):Math.min(360,t.height-170);return Lc(Pc,{children:t.gates.map(r=>$c("g",{children:[Lc("rect",{x:r.x-r.width/2,y:i,width:r.width,height:n,rx:e?2:12,fill:r.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:r.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),o?Lc("text",{x:r.x,y:Math.max(64,t.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:r.label??r.id}):null]},r.id))})}function Cc({layout:t,states:e,compact:o=!1}){return o?Lc("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:Lc(Rc,{layout:t,compact:!0,showLabels:!1})}):$c("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Lc("path",{d:`M ${t.startX-42} ${t.routeY} C ${.24*t.width} ${t.routeY-70}, ${.42*t.width} ${t.routeY+78}, ${.58*t.width} ${t.routeY} S ${.78*t.width} ${t.routeY-82}, ${t.socketX+36} ${t.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),Lc("line",{x1:Math.round(.06*t.width),x2:Math.round(.94*t.width),y1:t.crashY,y2:t.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),Lc("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),Lc(Rc,{layout:t,compact:!1,showLabels:!0}),$c("g",{children:[Lc("rect",{x:t.socketX-52,y:t.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),Lc("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),$c("g",{children:[Lc("rect",{x:t.graveyardX-82,y:t.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),Lc("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),Lc("text",{x:t.graveyardX,y:t.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:e.some(t=>t.killed)?"lift shut off":"too heavy or too small"})]})]})}function Ic({states:t,layout:e}){const o=function(t){return t.map(t=>({label:t.id,value:Math.max(0,Number(t.viability)||0),outcome:t.outcome||t.stage||"in-process"}))}(t);if(!o.length)return null;const i=Math.max(1,...o.map(t=>t.value)),n=Math.max(40,(e.width-80)/o.length);return $c("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Lc("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),o.map((t,e)=>{const o=40+e*n,r=Math.max(2,t.value/i*28),s=/kill|crash|block|grave/i.test(t.outcome);return $c("g",{children:[Lc("rect",{x:o+.18*n,y:28-r+22,width:Math.max(10,.45*n),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),Lc("text",{x:o+.4*n,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:t.label})]},t.label)})]})}var Tc={margin:(t,e)=>e.compactMode?"sparkline"===t.mode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}};function Oc(t){return t.map(t=>({...t,spawnAt:void 0}))}function zc(t,e){return t?e?o=>Rn.createElement(Rn.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function Fc(t,e,o){const i=e[o];return"boolean"==typeof i?i:!0!==t.__compactMode}var Nc=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Ec(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return Nc[(e>>>0)%Nc.length]}var Dc={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,o,i,n)=>({chartType:"line",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||e,colorAccessor:e,...i,showAxes:!1,margin:i.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:Fe,LineChart:De,AreaChart:We,DifferenceChart:je,StackedAreaChart:Ye,Scatterplot:Xt,CandlestickChart:Xe,BubbleChart:qt,ConnectedScatterplot:Ge,QuadrantChart:qe,Heatmap:Ve,TemporalHistogram:Be,XYCustomChart:{frameType:"xy",buildProps:(t,e,o,i,n)=>({chartType:"custom",data:t,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:e,colorScheme:o,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...i,showAxes:n.frameProps?.showAxes??n.showAxes??!1,showLegend:i.showLegend??!!e})},BarChart:xo,StackedBarChart:bo,GroupedBarChart:vo,PieChart:wo,DonutChart:ko,Histogram:So,BoxPlot:Ao,ViolinPlot:Mo,SwarmPlot:_o,DotPlot:Po,SwimlaneChart:Lo,RidgelinePlot:$o,LikertChart:Ro,FunnelChart:Co,GaugeChart:Io,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,o,i,n)=>({chartType:"custom",data:t,oAccessor:n.categoryAccessor||n.oAccessor||"category",rAccessor:n.valueAccessor||n.rAccessor||"value",projection:n.projection||"vertical",colorAccessor:e,colorScheme:o,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...i,showAxes:n.frameProps?.showAxes??n.showAxes??!1})},ForceDirectedGraph:mn,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,o,i,n)=>({chartType:"force",nodes:n.nodes||t||[],edges:n.edges||[],nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor||"id",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",valueAccessor:n.valueAccessor||"value",colorBy:e,colorScheme:o,customNetworkLayout:n.layout||n.customNetworkLayout,layoutConfig:n.layoutConfig,...i})},SankeyDiagram:wn,ProcessSankey:vn,ChordDiagram:gn,TreeDiagram:kn,Treemap:Sn,CirclePack:xn,OrbitDiagram:bn,ChoroplethMap:Pn,ProportionalSymbolMap:Ln,FlowMap:$n,GeoCustomChart:{frameType:"geo",buildProps:(t,e,o,i,n)=>({points:n.points||t||[],areas:n.areas||[],lines:n.lines||[],projection:n.projection||"equirectangular",xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",lineDataAccessor:n.lineDataAccessor,colorBy:e,colorScheme:o,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...i})},GaltonBoardChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,400],s=n.bins??21,a=n.seed??1,c=Math.max(1,Math.round(n.pegRows??s-1)),l="mechanical"===n.mode,u=l?function(t){const e=Math.max(2,Math.round(t.bins)),o=Math.max(1,Math.round(t.pegRows??e-1)),i=Math.max(1,Math.round(t.count??Math.max(64,4*e))),n=Nn(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=Bn(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:i},(t,e)=>{let i=0;for(let t=0;o>t;t+=1)r()<n&&(i+=1);const a=o/2;return{id:`${s}-${e}`,value:i,mechanical:!0,pegRows:o,branchProbability:n,pathRights:i,side:a>i?"left":i>a?"right":"center"}})}({bins:s,branchProbability:n.branchProbability,count:n.mechanicalCount,pegRows:c,seed:a}):Array.isArray(t)?t:[],d=function(t){const{data:e,valueAccessor:o,bins:i,ballRadius:n,seed:r,size:s,valueExtent:a}=t,c=Cn(s),l=e.map((t,e)=>Fn(zn(t,e,o))).filter(t=>null!=t),u=function(t){if(!t)return;const e=Fn(t[0]),o=Fn(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(a),d=u?.[0]??(l.length?Math.min(...l):0),h=u?.[1]??(l.length?Math.max(...l):1),f=h===d?1:h-d,p=Wn().domain([0,i]).range([c.plot.x,c.plot.x+c.plot.width]),y=Array.from({length:i},()=>0),g=[];e.forEach((t,e)=>{const r=Fn(zn(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(i-1,Math.floor((r-d)/f*i)));y[s]+=1,g.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:c.plot.y+n+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:n},datum:{...t,value:r,bin:s}})});const m=c.plot.y+c.plot.height;return{config:On(r,[...Er({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...Dr({idPrefix:"galton-bin",count:i,domainStart:0,domainStep:1,xScale:p,yTop:c.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:g,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:y.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:i,plot:c.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:n.valueAccessor||"value",bins:s,ballRadius:n.ballRadius??4,seed:a,size:r,valueExtent:l?[0,c]:void 0});return{...i,config:d.config,initialSpawns:Oc(d.initialSpawns),projectionRows:d.projectionRows,foregroundGraphics:zc(ac(d.projectionRows,s,Fc(i,n,"showProjection"),d.metadata,n.referenceLines),i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy||(l?"side":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:i,windows:n,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:u=1}=t,d=Cn(c),h=e.map((t,e)=>Fn(zn(t,e,o))).filter(t=>null!=t),f=Fn(l?.[0]),p=Fn(l?.[1]),y=h.length?Math.min(...h):0,g=h.length?Math.max(...h):y+n.size,m=Math.min(f??y,y),x=Math.max(p??g,g),b=Math.floor(m/n.size)*n.size,v=Math.max(1,Math.ceil((x-b+n.size)/n.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Fn(r?.value)??w-(r?.delay??n.size),S=Math.max(0,Math.min(v,Array.from({length:v},(t,e)=>e).reduce((t,e)=>b+(e+1)*n.size>k?t:t+1,0))),A=function(t,e){const o=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:o,height:t.plot.height},windowPlot:{x:t.plot.x+o,y:t.plot.y,width:Math.max(40,t.plot.width-o),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(d,s),M=b+v*n.size,_=as().domain([b,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),L=[];e.forEach((t,e)=>{const r=Fn(zn(t,e,o));if(null==r)return;const a=Fn(zn(t,e,i))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-b)/n.size))),l=k>=b+(c+1)*n.size;P[c].value+=l?0:1,P[c].secondary+=l?1:0,L.push({id:(t.id??"event-"+e)+"",x:Math.max(A.windowPlot.x+s,Math.min(A.windowPlot.x+A.windowPlot.width-s,_(r))),y:d.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const $=d.plot.y+d.plot.height,R=function(t,e){const o=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!o)return[];const i=t.windowStart,n=t.windowStart+t.windowCount*t.windowSize,r=as().domain([i,n]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,c=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),l=t=>s===a?e:c+(t-a)/(s-a)*(e-c),u=[];for(let e=0;o>e;e+=1){const o=t.windowStart+e*t.windowSize,i=o+t.windowSize,n=r(o),s=r(i);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:n,y1:l(n),x2:s,y2:l(s)})}return u}({closedWindowCount:S,gutter:A.gutter,plot:d.plot,windowCount:v,windowPlot:A.windowPlot,windowSize:n.size,windowStart:b},d.plot.y+.28*d.plot.height);return{config:On(a,[...Er({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...cs({idPrefix:"eventdrop-window",count:v,xScale:t=>_(b+t*n.size),yTop:A.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?R[0]?.y1:R[t-1]?.y2??R[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?A.wallTop:e+1.25*s},yBottom:$,wallThickness:6}),...R.map(t=>({id:t.id,shape:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:L,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:u},projectionRows:P.map((t,e)=>({label:`${b+e*n.size}-${b+(e+1)*n.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:A.gutter,lidSegments:R,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:d.plot,windowPlot:A.windowPlot,watermarkValue:k,windowCount:v,windowSize:n.size,windowStart:b}}}({data:Array.isArray(t)?t:[],timeAccessor:n.timeAccessor||"time",arrivalAccessor:n.arrivalAccessor||"arrivalTime",windows:n.windows||{size:10},watermark:n.watermark,ballRadius:n.ballRadius??5,seed:n.seed??1,size:r,timeExtent:n.timeExtent,timeScale:n.timeScale??1});return{...i,config:s.config,initialSpawns:Oc(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:zc(cc(s.projectionRows,s.metadata,Fc(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||n.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,400],s="mechanical"===n.mode,a=function(t){const{data:e,categoryAccessor:o,valueAccessor:i,unitValue:n,ballRadius:r,seed:s,size:a}=t,c=En(n,1),l=Cn(a),u=[],d=new Map,h=new Map,f=[];function p(t){let e=d.get(t);return null==e&&(e=u.length,u.push(t),d.set(t,e)),e}e.forEach((t,e)=>{p((zn(t,e,o)??"unknown")+"")});const y=Math.max(1,u.length),g=ls(l.plot,y,r),m=Math.max(0,g.tubeWidth/2-r-1),x=u.map(()=>[]);e.forEach((t,e)=>{const n=(zn(t,e,o)??"unknown")+"",s=p(n),a=i?Fn(zn(t,e,i)):1,u=Math.max(0,Math.round((a??0)/c)),d=g.centerX(s);for(let o=0;u>o;o+=1){const i=h.get(n)??0,a=g.perRow>1?((g.perRow>1?i%g.perRow:0)/(g.perRow-1)*2-1)*m:0;h.set(n,i+1),x[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:l.plot.y+r+2,vx:(o%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:n,unitIndex:o}})}});const b=x.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;b>t;t+=1)for(const e of x)e.length>t&&f.push(e[t]);const v=l.plot.y+l.plot.height,w=[...Er({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 t=0;y>t;t+=1){const e=g.centerX(t);for(const o of[-1,1])w.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*g.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:On(s,w,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(t=>({label:t,value:h.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),o=e.length?e:["Intake"],i=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),n=En(t.unitValue,1),r=Bn(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),c=a.reduce((t,e)=>t+e,0)||1,l=i-o.length,u=a.map(t=>t/c*l),d=u.map(t=>1+Math.floor(t));let h=i-d.reduce((t,e)=>t+e,0);const f=u.map((t,e)=>({index:e,fraction:t-Math.floor(t)})).sort((t,e)=>e.fraction-t.fraction);for(let t=0;h>0;t=(t+1)%f.length)d[f[t].index]+=1,h-=1;return o.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*n,mechanical:!0,unitCount:d[e],unitValue:n,share:d[e]/i}))}({categories:n.mechanicalCategories,count:n.mechanicalCount,seed:n.seed??1,unitValue:n.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:n.categoryAccessor||"category",valueAccessor:n.valueAccessor||(s?"value":void 0),unitValue:n.unitValue??1,ballRadius:n.ballRadius??5,seed:n.seed??1,size:r});return{...i,config:a.config,initialSpawns:Oc(a.initialSpawns),projectionRows:a.projectionRows,foregroundGraphics:zc(lc(a.projectionRows,n.ballRadius??5,Fc(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:i,radiusAccessor:n,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:u}=t,d=Cn(a),h=Bn(s),f=[],p=[],y=new Map;e.forEach((t,e)=>{const s=Fn(zn(t,e,o));if(null==s)return;const a=i?(zn(t,e,i)??"All")+"":"All",c=n?Fn(zn(t,e,n)):null,l=Nn(null!=c&&c>0?c:r,2,18);!function(t){let e=y.get(t);null==e&&(e=p.length,p.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:l})});const g=f.map(t=>t.value),m=c?Fn(c[0]):null,x=c?Fn(c[1]):null,b=g.length?Math.min(...g):0,v=g.length?Math.max(...g):1;let w=m??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){const t=k;k=w,w=t}const S=Math.max(r,...f.map(t=>t.radius)),A=d.plot.x+S+8,M=d.plot.x+d.plot.width-S-8,_=us().domain([w,k]).range([A,M]),P=Math.max(1,p.length),L=Math.min(Math.max(28,3*S),d.plot.height/4),$=d.plot.y+L,R=Math.max(0,d.plot.y+d.plot.height-L-$),C=t=>{const e=y.get(t)??0;return 1===P?d.plot.y+.54*d.plot.height:$+e/(P-1)*R},I=new Map,T=f.map((t,e)=>{I.set(t.group,(I.get(t.group)??0)+1);const o=_(t.value),i=C(t.group),n=(h()-.5)*t.radius*1.6,r=(h()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:u?o+n:Nn(o+(e%9-4)*t.radius*2.5,A,M),y:u?i+r:d.plot.y-18-e%12*t.radius,vx:u?0:22*(h()-.5),vy:u?0:24+18*h(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:o,targetY:i},springs:[{target:{type:"point",x:o,y:i},restLength:0,stiffness:34,damping:5.5}]}});return{config:On(s,Er({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:T,projectionRows:p.map(t=>({label:t,value:I.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:p.map(t=>({label:t,y:C(t),count:I.get(t)??0})),plot:d.plot}}}({data:Array.isArray(t)?t:[],xAccessor:n.xAccessor||"x",groupAccessor:n.groupAccessor,radiusAccessor:n.radiusAccessor,pointRadius:n.pointRadius??5,seed:n.seed??1,size:r,xExtent:n.xExtent,collisionIterations:n.collisionIterations,settle:n.settle});return{...i,config:s.config,initialSpawns:Oc(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:zc(dc(s.metadata,Fc(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy||n.groupAccessor,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[900,420],s=Array.isArray(n.stages)?n.stages:[],a=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,i=Cn(o),n=Nn(t.ballRadius??6,2,18),r=t.seed??1,s=Bn(r),a=t.idAccessor,c=t.stageAccessor??"stage",l=t.groupBy,u=t.groupLabelAccessor,d=t.workAccessor,h=t.radiusAccessor,f=t.groupCompletion??(l?"allAbsorbed":"none"),p=t.springStiffness??.28,y=t.springDamping??.72,g=!0===t.settle,m=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),x=function(t){const e=t.shape??"lane",o=Math.max(1,Math.round(t.width)),i=Math.max(1,Math.round(t.height)),n=t.padX??46,r=t.padY??72,s=n,a=o-n,c=r,l=i-Math.max(24,Math.round(.45*r)),u=(c+l)/2,d=Math.max(1,l-c),h=ms(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,y=ms(d*h+p,.06*d,.5*d),g=y/2,m=u-g,x=u+g,b=t.idPrefix??"process",v=t.friction??.58,w=t.restitution??.18,k=t.wallThickness??8,S=t.stages;if(!S.length)throw Error("processStageLayout requires at least one stage");const A=ms(t.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(S),_=a-s;let P=s;const L=S.map((t,e)=>{const o=P,i=e===S.length-1?a:P+(t.share??1)/M*_;return P=i,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:o,x1:i,x:(o+i)/2,width:i-o,y:u,height:d}}),$=L[A],R=$.x0,C=$.x1,I=(t,o)=>{if("lane"===e)return"top"===o?c:l;if("funnel"===e){const e=ms((t-s)/Math.max(1,a-s),0,1);return"top"===o?c+(m-c)*e:l+(x-l)*e}if(R>=t){const e=ms((t-s)/Math.max(1,R-s),0,1);return"top"===o?c+(m-c)*e:l+(x-l)*e}if(C>=t)return"top"===o?m:x;const i=ms((t-C)/Math.max(1,a-C),0,1);return"top"===o?m+(c-m)*i:x+(l-x)*i},T=L.map(t=>{const e=Math.min(I(t.x0,"top"),I(t.x1,"top")),o=Math.max(I(t.x0,"bottom"),I(t.x1,"bottom"));return{...t,y:(e+o)/2,height:Math.max(1,o-e)}}),O={thickness:k,friction:v,restitution:w},z=[];"lane"===e?z.push(xs(b+"-top",s,c,a,c,O),xs(b+"-bottom",s,l,a,l,O),xs(b+"-left",s,c,s,l,{...O,thickness:Math.max(6,k-2)}),xs(b+"-right",a,c,a,l,{...O,thickness:Math.max(6,k)})):"funnel"===e?z.push(xs(b+"-top",s,c,a,m,O),xs(b+"-bottom",s,l,a,x,O),xs(b+"-left",s,c,s,l,{...O,thickness:Math.max(6,k-2)}),xs(b+"-right",a,m,a,x,{...O,thickness:Math.max(6,k)})):z.push(xs(b+"-left-top",s,c,R,m,O),xs(b+"-left-bottom",s,l,R,x,O),xs(b+"-center-top",R,m,C,m,O),xs(b+"-center-bottom",R,x,C,x,O),xs(b+"-right-top",C,m,a,c,O),xs(b+"-right-bottom",C,x,a,l,O),xs(b+"-left",s,c,s,l,{...O,thickness:Math.max(6,k-2)}),xs(b+"-right",a,c,a,l,{...O,thickness:Math.max(6,k)}));const F=t.membraneDampingScale??.5,N=s,E=Math.max(1,("bowtie"===e?R:a)-N),D=(t.membranes??[]).map(t=>{const e=N+ms(t.offset,0,1)*E,o=t.width??18+18*t.cost,i=d-16,n=u+.25*(t.wobble??0);return{...t,x:e,y:n,width:o,height:i}}),B=!1===t.includeMembraneRegions?[]:D.map(t=>function(t){const e=t.dampingScale??.5,o=t.energyScale??1,i=ms(t.cost,0,2);return{...bs({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:i,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:i*e,energyDelta:-i*o}}({id:t.id,label:t.label??t.id,description:t.description??(t.label??t.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:t.x,y:t.y,width:t.width,height:t.height,cost:t.cost,dampingScale:t.dampingScale??F,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:o,height:i,padX:n,padY:r,left:s,right:a,topY:c,bottomY:l,midY:u,centerLeft:R,centerRight:C,pinchHeight:y,pinchTop:m,pinchBottom:x,stages:T,membranes:D,colliders:z,regionEffects:B,boundaryY:I}}({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((t,e)=>[t.id,e])),v=new Map(x.stages.map(t=>[t.id,t])),w=x.stages[0].id,k=x.stages[0],S=new Set(e.filter(t=>t.absorb).map(t=>t.id)),A=e.map(t=>{const e=v.get(t.id)??k;return function(t,e){const o={id:"process-stage-"+t.id,label:t.label??t.id,description:t.description,x:e.x,y:e.y,width:Math.max(12,.92*e.width),height:Math.max(40,.88*e.height),semanticItem:!1,attributes:{stageId:t.id}};if(t.absorb)return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:24,y:0};return{...bs({...t,kind:t.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.02,charge:t.charge??"absorbed"}}({...o,kind:t.kind??"sink",force:ws(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return i={...o,kind:t.kind??"force-field",force:ws(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...bs({...i,kind:i.kind??"force-field",attributes:{primitive:"portal",targetStage:i.targetStage,..."object"==typeof i.attributes&&i.attributes?i.attributes:{}}}),force:i.force,impulseOnEnter:i.impulseOnEnter,damping:i.damping??.08}}var i;if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force;return{...bs({...t,kind:t.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:t.capacity,unitsPerSecond:t.unitsPerSecond??t.capacity,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping,charge:t.charge??t.capacity}}({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:ws(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...o.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return function(t){const e=t.pressure??t.occupancy??0,o=t.baseDamping??.08,i=t.dampingPerUnit??.12,n=t.energyPerUnit??0;return{...bs({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o+e*i,energyDelta:n?-e*n:void 0,force:t.force}}({...o,kind:t.kind??"membrane",pressure:e.pressure,occupancy:e.occupancy,baseDamping:e.baseDamping??t.damping??.1,dampingPerUnit:e.dampingPerUnit??.1,energyPerUnit:e.energyPerUnit??0,force:ws(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?vs({...o,kind:t.kind??"force-field",force:ws(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):function(t){return{...bs({...t,kind:t.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,damping:t.damping,energyDelta:t.energyDelta}}({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:x.midY,width:e.width,height:x.bottomY-x.topY})});A.unshift(vs({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 M=new Map;for(const t of x.stages)M.set(t.id,0);const _=[];t.data.forEach((t,e)=>{const o=(a?zn(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",i=(zn(t,e,c)??w)+"",r=b.has(i)?i:w;M.set(r,(M.get(r)??0)+1);const s=l?(zn(t,e,l)??"")+"":void 0,f=s&&u?(zn(t,e,u)??s)+"":s,p=d?Fn(zn(t,e,d))??1:1,y=h?Fn(zn(t,e,h)):null,g=Nn(null!=y&&y>0?y:n,2,18);_.push({datum:t,id:o,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:g,index:e})});const P=new Map,L=new Map;for(const t of _){if(!t.groupId)continue;const e=P.get(t.groupId)??[];e.push(t.id),P.set(t.groupId,e),t.groupLabel&&L.set(t.groupId,t.groupLabel)}const $=Nn(t.groupAnchorAlong??.55,.15,.9),R=x.left+(x.right-x.left)*$,C=Array.from(P.keys()),I=C.map((t,o)=>{const i=P.get(t)??[],n=C.length>1?x.topY+28+o/Math.max(1,C.length-1)*(x.bottomY-x.topY-56):x.midY;return function(t){const e=t.x??t.anchor?.x??0,o=t.y??t.anchor?.y??0;return{id:t.id,label:t.label,description:t.description,group:t.group,bodyIds:t.bodyIds,datum:t.datum,state:t.state,x:e,y:o,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:o},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}({id:t,label:L.get(t)??t,bodyIds:i,anchor:{x:R,y:n},x:R,y:n,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),T=function(t,e){const o=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],i=e.filter(t=>!o.has(t)),n=e.length-i.length,r=t.completion?.mode??"allMembersAbsorbed",s=t.completion?.valueByBodyId,a=t=>{const e=s&&Object.prototype.hasOwnProperty.call(o=s,i=t)?o[i]:void 0;var o,i;return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:1},c=e.reduce((t,e)=>t+a(e),0),l=e.reduce((t,e)=>t+(o.has(e)?a(e):0),0),u=t.completion?.threshold,d="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):c:void 0;return{id:t.id,label:t.label??t.id,mode:r,complete:e.length>0&&("anyAbsorbed"===r?n>0:"threshold"===r?l>=(d??c):0===i.length),absorbed:n,total:e.length,absorbedValue:l,totalValue:c,threshold:d,missing:i}})}(I,_.filter(t=>S.has(t.stageId)).map(t=>t.id)),O=new Map(I.map(t=>[t.id,t])),z=_.map((t,e)=>{const o=v.get(t.stageId)??k,i=o.x+(s()-.5)*Math.min(24,.2*o.width),n=x.boundaryY(i,"top")+t.radius+10,r=x.boundaryY(i,"bottom")-t.radius-10,a=r>n?n+s()*Math.max(1,r-n):x.midY,c=g?i:x.left+18+e%7*4,l=g?a:x.midY+(s()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:i,y:a},restLength:.45*t.radius,stiffness:p,damping:y}];if(t.groupId){const e=O.get(t.groupId);e?.anchor&&!S.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:c,y:l,vx:g?0:40+40*s(),vy:g?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:g?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),F={kernel:{seed:r,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},N=x.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),E=e.map(t=>{const e=v.get(t.id)??k;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:M.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:F,initialSpawns:z,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:N,metadata:{kind:"process-flow",plot:i.plot,volume:x,stages:E,groups:I,groupCompletion:T,regionEffects:A}}}({data:Array.isArray(t)?t:[],stages:s,size:r,idAccessor:n.idAccessor,stageAccessor:n.stageAccessor||"stage",groupBy:n.groupBy,groupLabelAccessor:n.groupLabelAccessor,workAccessor:n.workAccessor,radiusAccessor:n.radiusAccessor,ballRadius:n.ballRadius??6,seed:n.seed??1,groupCompletion:n.groupCompletion,groupAnchorAlong:n.groupAnchorAlong,settle:n.settle??!0,gravityX:n.gravityX,gravityY:n.gravityY}),c=a.metadata;return{...i,config:a.config,initialSpawns:Oc(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:c?.regionEffects,backgroundGraphics:zc(wc(a.metadata,Fc(i,n,"showChrome"),{},n.chromeOptions),i.backgroundGraphics),foregroundGraphics:zc(kc(a.projectionRows,a.metadata,Fc(i,n,"showProjection")),i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy||n.groupBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.workAccessor||n.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[900,520],s=Ns({data:Array.isArray(t)?t:[],size:r,gates:n.gates,positiveProperties:n.positiveProperties,negativeProperties:n.negativeProperties,crashOffset:n.crashOffset,idAccessor:n.idAccessor,positiveAccessor:n.positiveAccessor,negativeAccessor:n.negativeAccessor,metricsAccessor:n.metricsAccessor,initialViability:n.initialViability,projectPlacement:n.projectPlacement,coreBody:n.coreBody,viability:n.viability});return{...i,config:s.config,initialSpawns:Oc(s.initialSpawns),projectionRows:[],backgroundGraphics:zc(Fc(i,n,"showChrome")?Rn.createElement(Cc,{layout:s.layout,states:s.states,compact:!0===i.__compactMode}):void 0,i.backgroundGraphics),foregroundGraphics:zc(Fc(i,n,"showProjection")?Rn.createElement(Ic,{layout:s.layout,states:s.states}):void 0,i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy)}}},CrucibleChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[900,520],s=Ra({data:Array.isArray(t)?t:[],phases:Array.isArray(n.phases)?n.phases:[],products:Array.isArray(n.products)?n.products:void 0,outlets:Array.isArray(n.outlets)?n.outlets:void 0,events:Array.isArray(n.events)?n.events:void 0,idAccessor:n.idAccessor,labelAccessor:n.labelAccessor,categoryAccessor:n.categoryAccessor,amountAccessor:n.amountAccessor,metricsAccessor:n.metricsAccessor,initialStateAccessor:n.initialStateAccessor,metrics:n.metrics,size:r,seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange}),a="snapshot"===n.playback?function(t,e){if(void 0===e)return t.duration;if("number"==typeof e)return Math.max(0,Math.min(t.duration,ha(e)??0));const o=t.phases.find(t=>t.id===e.phaseId);if(!o)return t.duration;const i=Math.max(0,Math.min(1,ha(e.progress??0)??0));return o.start+o.duration*i}(s,n.snapshotAt):s.duration,c=$a(s,a).state,l=n.projection&&"object"==typeof n.projection?n.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const o=e.groupBy??"outlet",i=new Map,n=t=>{const e=function(t,e){return"product"===e?"product"===t.kind?t.id:"unassigned":"outlet"===e?t.outletId??"unassigned":"category"===e?t.category:t.status}({...t,status:t.status??"active"},o),n=i.get(e);if(n)return n.count+=1,n.amount+=t.amount,void Hs(n.metrics,t.metrics);i.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:Bs(t.metrics),status:"status"===o?t.status:void 0,outletId:"outlet"===o?t.outletId:void 0,category:"category"===o?t.category:void 0,productId:"product"===o&&"product"===t.kind?t.id:void 0})};for(const e of Object.values(t.components))e.productIds.length||"consumed"===e.status||n({kind:"component",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});for(const e of Object.values(t.products))n({kind:"product",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});const r=new Map((e.order??[]).map((t,e)=>[t,e]));return[...i.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||Xs(t.key,e.key))}(c,l),d=l.measure??"count",h=function(t,e={}){const o=e.bodies??[],i=Math.max(0,e.recentBodyLimit??6),n=new Map;for(const t of o){const o=e.getContainerId?.(t);if(!o)continue;const i=n.get(o);i?i.push(t):n.set(o,[t])}const r=t.map(t=>{const o=n.get(t.id)??[],r=Math.max(0,Math.floor(t.count??o.length)),s=o.slice(Math.max(0,o.length-i)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??ic(t),datum:t.datum}));return{id:t.id,label:t.label,count:r,share:0,secondary:t.secondary,secondaryLabel:t.secondaryLabel,observed:t.observed,bodyIds:o.map(t=>t.id),recentBodies:s,metadata:t.metadata}}),s=r.reduce((t,e)=>t+e.count,0);return r.map(t=>({...t,share:s>0?t.count/s:0}))}(u.map(t=>({id:t.key,label:t.label,count:t.count,secondary:"count"===d||"amount"===d?t.amount:Number(t.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?n.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),f={seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange},p=e??n.colorBy??"category",y=!1===n.showChrome?null:Rn.createElement(ec,{layout:s.layout,phases:s.phases,state:c,compact:520>r[0]||360>r[1]}),g=!1===n.showProjection?null:Rn.createElement(oc,{rows:u,layout:s.layout,projection:l,amountLabel:n.amountLabel});return{...i,config:s.config,initialSpawns:Oc(_a(c,s.layout,f)),projectionRows:h,bodyStyle:t=>function(t,e,o,i){const n=t.datum,r={stroke:i.stroke??("product"===n?.kind?"#fffaf0":"#26323a"),strokeWidth:i.strokeWidth??("product"===n?.kind?1.8:1.1),opacity:i.opacity??.96};if(!n?.__crucible)return{...r,fill:i.color??"#b8792d"};if("product"===n.kind){const t=e.products[n.semanticId];return{...r,fill:i.color??t?.color??Ec(t?.id??n.semanticId)}}const s=e.components[n.semanticId];if(!s)return{...r,fill:i.color??"#356b63"};let a;return a="status"===o?s.status:"outlet"===o?s.outletId??"in chamber":"product"===o?s.productIds[0]??"unalloyed":"category"===o||null==o?s.category:"function"==typeof o?(o(s.datum)??"unassigned")+"":(s.datum[o+""]??"unassigned")+"",{...r,fill:i.color??Ec(a)}}(t,c,p,n),getBodyLabel:t=>function(t,e){const o=t.datum;if(o?.__crucible)return"product"===o.kind?e.products[o.semanticId]?.label:e.components[o.semanticId]?.label}(t,c),renderBodySVG:qa,backgroundGraphics:zc(y,i.backgroundGraphics),foregroundGraphics:zc(g,i.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:i,maxParticles:n,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:y,sourceAccessor:g,targetAccessor:m,throughputAccessor:x}=t,b=Cn(y),v=Bn(p),w=new Map,k=new Map,S=[];function A(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const o=(zn(t,e,r)??t.id??e)+"",i=Fn(zn(t,e,s)),n=Fn(zn(t,e,a));if(null!=i&&null!=n){const t={x:i,y:n};w.set(o,t),S.push(t)}k.set(o,(t.label??t.name??o)+"")});const M=[];i.forEach((t,e)=>{const o=A(zn(t,e,g)),i=A(zn(t,e,m)),n=Math.max(0,Fn(zn(t,e,x))??0),r=hs(d?zn(t,e,d):void 0),s=r.length?r:hs(t.path??t.points??t.route);s.forEach(t=>S.push(t)),M.push({id:(t.id??`physical-flow-${o}-${i}-${e}`)+"",link:t,index:e,source:o,target:i,throughput:n,rawPath:s})});const _=(L=S,"normalized"===(P=e)||"pixels"===P?P:L.length>0&&L.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var P,L;const $=new Map;for(const[t,e]of w)$.set(t,fs(e,b,_));const R=[];for(const t of M){let e=t.rawPath.map(t=>fs(t,b,_));if(2>e.length){const o=$.get(t.source),i=$.get(t.target);o&&i&&(e=[o,i])}else $.has(t.source)||$.set(t.source,e[0]),$.has(t.target)||$.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(k.has(t.source)||k.set(t.source,t.source),k.has(t.target)||k.set(t.target,t.target),R.push({...t,path:e,packetCount:0}))}const C=En(u,.12),I=Math.max(1,Math.round(n)),T=R.map(t=>Math.max(1,Math.round(t.throughput*C))),O=T.reduce((t,e)=>t+e,0),z=O>I?I/O:1;R.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(T[e]*z))});let F=R.reduce((t,e)=>t+e.packetCount,0);for(;F>I;){const t=R.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>R[t].packetCount)?o:t,-1);if(-1===t)break;R[t].packetCount-=1,F-=1}const N=new Map,E=new Map,D=[],B=En(o,90),W=En(l,4);R.forEach((t,e)=>{N.set(t.target,(N.get(t.target)??0)+t.throughput),E.set(t.source,(E.get(t.source)??0)+t.throughput);const o=ps(t.path);for(let i=0;t.packetCount>i;i+=1){const n=(i+.5)/t.packetCount,r=f?n:Nn(.12+.84*n+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=ys(t.path,s),c=ys(t.path,r),l=gs(t.path,s),u={x:-l.y,y:l.x},d=(v()-.5)*W*1.5;D.push({id:`${t.id}-packet-${i}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:l.x*B+10*(v()-.5),vy:f?0:l.y*B+10*(v()-.5),mass:.8,spawnAt:f?0:.04*e+i/32,shape:{type:"circle",radius:W},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:i,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:B,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target},springs:"none"!==h&&f?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const j=Math.max(18,5*W),Y=Array.from($,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+Dn(t),point:e})),X=Y.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:j,height:j}})),q=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=On(p,[...Er({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});G.bodyLimit=I,G.eviction="oldest",G.observation={...G.observation,sensors:q};const V=Array.from($,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+Dn(t),incoming:N.get(t)??0,outgoing:E.get(t)??0})),H=R.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:G,initialSpawns:D,projectionRows:V.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:D.length,totalThroughput:R.reduce((t,e)=>t+e.throughput,0),plot:b.plot,nodes:V,links:H}}}({nodes:Array.isArray(n.nodes)?n.nodes:[],links:Array.isArray(n.links)?n.links:Array.isArray(n.edges)?n.edges:Array.isArray(t)?t:[],nodeIdAccessor:n.nodeIdAccessor||"id",nodeXAccessor:n.nodeXAccessor||"x",nodeYAccessor:n.nodeYAccessor||"y",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",throughputAccessor:n.throughputAccessor||"value",pathAccessor:n.pathAccessor||"path",coordinateMode:n.coordinateMode||"auto",particleRate:n.particleRate??.16,maxParticles:n.maxParticles??180,particleRadius:n.particleRadius??4,flowSpeed:n.flowSpeed??90,pathConstraint:n.pathConstraint||"path",reducedMotion:!0,seed:n.seed??1,size:r});return{...i,config:s.config,initialSpawns:Oc(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:zc(_c(s.metadata,{showNodeLabels:!1!==n.showNodeLabels,showSensors:!1!==n.showSensors,showStaticFlow:!1!==n.showStaticFlow}),i.foregroundGraphics),bodyStyle:Tn(e||n.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",layout:Tc,buildProps:(t,e,o,i,n)=>{const r=i.size??[700,380],s=At(i.theme),a=function(t){const e=function(t,e,o){const i=t?.observation;return{...t,observation:{...i,chartId:e??i?.chartId??"physics-custom",chartType:i?.chartType??"PhysicsCustomChart",onObservation:o??i?.onObservation}}}(t.config,t.chartId,t.onObservation),o=Ss(t.colorScheme,t.themeCategorical,w),i=Cn(t.size),n={data:t.data,scales:{x:ks().domain(t.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:ks().domain(t.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:t.semantic,categorical:[...o]},resolveColor:As(o,t.colorScheme),config:t.layoutConfig??{},world:new ss(e)},r=t.skipLayout?{}:t.layout(n)??{},s=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...i}=t,n=o.get(e)??[];n.push(i),o.set(e,n)}return t.map(t=>{const e=o.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:Ms(e,r),context:n,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:n.chartId,colorScheme:o,config:n.config,data:Array.isArray(t)?t:[],layout:n.layout,layoutConfig:n.layoutConfig,semantic:kt(s)??{},size:r,themeCategorical:s.colors.categorical,xExtent:n.xExtent,yExtent:n.yExtent});return{...i,config:a.config,initialSpawns:Oc(a.initialSpawns),projectionRows:[],bodyStyle:a.result.bodyStyle??Tn(e||n.colorBy),backgroundGraphics:zc(i.backgroundGraphics,a.result.backgroundOverlays),foregroundGraphics:zc(i.foregroundGraphics,a.result.overlays)}}}};function Bc(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Wc(t){if(!t||2>t.length)return;const e=Bc(t[0]),o=Bc(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function jc(t){const{count:e,byType:o}=function(t){const e={};for(const o of t){const t="string"==typeof o?.type&&o.type.length>0?o.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),i=0===e,n=[...t.extraWarnings??[]];i&&!n.includes("EMPTY_SCENE")&&n.push("EMPTY_SCENE"),t.annotationRender&&t.annotationRender.unrenderedCount>0&&!n.includes("UNRENDERED_ANNOTATIONS")&&n.push("UNRENDERED_ANNOTATIONS");const r=Array.isArray(t.annotations)?t.annotations.length:0,s=t.margin,a=s?{x:s.left,y:s.top,width:t.width-s.left-s.right,height:t.height-s.top-s.bottom}:void 0;return{component:"",frameType:t.frameType,status:i?"empty":"ok",empty:i,markCount:e,markCountByType:o,width:t.width,height:t.height,...t.xDomain?{xDomain:t.xDomain}:{},...t.yDomain?{yDomain:t.yDomain}:{},...t.categories?{categories:t.categories}:{},...void 0!==t.nodeCount?{nodeCount:t.nodeCount}:{},...void 0!==t.edgeCount?{edgeCount:t.edgeCount}:{},...void 0!==t.legendItems?{legendItems:t.legendItems}:{},annotationCount:t.annotationRender?.renderedCount??r,...t.annotationRender?{annotationInputCount:t.annotationRender.inputCount,unrenderedAnnotationCount:t.annotationRender.unrenderedCount,...t.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:t.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:n,semanticStatus:"not-assessed",semanticDiagnostics:[],...s?{margin:s}:{},...a?{plot:a}:{}}}import*as Yc from"react";import*as Xc from"react-dom/server";var qc=class{constructor(t){if(this._capacity=t,this.head=0,this._size=0,1>t)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(t)}push(t){let e;return this._size===this._capacity?e=this.buffer[this.head]:this._size++,this.buffer[this.head]=t,this.head=(this.head+1)%this._capacity,e}pushMany(t){const e=[];for(const o of t){const t=this.push(o);void 0!==t&&e.push(t)}return e}get(t){if(t>=0&&this._size>t)return this.buffer[(this.head-this._size+t+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let t=0;return{next:()=>this._size>t?{done:!1,value:this.get(t++)}:{done:!0,value:void 0}}}forEach(t){const e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t(this.buffer[(e+o)%this._capacity],o)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t[o]=this.buffer[(e+o)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let o=0,i=[];e.length>t&&(o=e.length-t,i=e.slice(0,o)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=o;e.length>t;t++)this.push(e[t]);return i}update(t,e){const o=[],i=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;this._size>n;n++){const r=(i+n)%this._capacity,s=this.buffer[r];if(t(s)){let t;t="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},o.push(t),this.buffer[r]=e(s)}}return o}remove(t){const e=[],o=[];if(this.forEach(i=>{t(i)?o.push(i):e.push(i)}),0===o.length)return o;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return o}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},Gc=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(t){Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}evict(t){t!==this._min&&t!==this._max||(this._dirty=!0)}recalculate(t,e){this._min=1/0,this._max=-1/0;for(const o of t){const t=e?e(o):o;Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function Vc(t,e){return t===e}function Hc(t,e){if("function"==typeof t)return e=>+t(e);const o=t||e;return t=>+t[o]}function Uc(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}function Kc(t,e){return"function"==typeof t?e=>t(e)+"":t?e=>e[t]+"":e?t=>t[e]+"":void 0}function Zc(t){return t?"function"==typeof t?t:e=>e[t]||e.id:null}function Qc(t){return"string"==typeof t?t:t.id}var Jc=/^\d{4}-\d{1,2}$/;function tl(t){const e=t.trim();if(!e||!Number.isNaN(Number(e)))return NaN;const o=Jc.test(e)?e+"-01":e;if(o===e&&10>e.length)return NaN;const i=Date.parse(o);return Number.isFinite(i)?i:NaN}function el(t){return t instanceof Date?t.getTime():"string"==typeof t?tl(t):+t}function ol(t){return new Set(Array.isArray(t)?t:[t])}function il(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function nl(t,e){return Math.min((t-e.startTime)/e.duration,1)}function rl(t,e,o){return t+(e-t)*o}function sl(){return"undefined"!=typeof performance?performance.now():Date.now()}function al(t,e,o){if(1>=o)return 1;const i=o-1;return function(t){const e=Math.max(0,Math.min(1,t.minOpacity??.1));if(Number.isNaN(t.age))return 1;if(t.age===1/0)return e;if(!Number.isFinite(t.extent)||0>=t.extent)return 1;const o=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>o?1:e;if("exponential"===t.type){const i=t.halfLife??t.extent/2;return e+Math.pow(.5,o/(i>0?i:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-o/t.extent))*(1-e)}({age:i-e,extent:i,type:t.type,halfLife:t.halfLife??o/2,threshold:t.stepThreshold??.5*o,minOpacity:t.minOpacity??.1})}function cl(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function ll(t,e,o){const i=t.duration??500,n=o-e;return i>n?1-n/i:0}function ul(t,e,o,i){let n=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,n=!0),t._pulseColor!==o&&(t._pulseColor=o,n=!0),t._pulseGlowRadius!==i&&(t._pulseGlowRadius=i,n=!0),n):(0!==t._pulseIntensity&&(t._pulseIntensity=0,n=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,n=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,n=!0),n)}function dl(t,e,o=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const i=t.duration??500,n=e.peek();return null!=n&&i>o-n}function hl(t,e,o){if(e._transitionKey)return e._transitionKey;switch(e.type){case"point":if(e.pointId)return"p:"+e.pointId;if("streaming"===t.runtimeMode&&e.datum){const o=t.getX(e.datum),i=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${o}:${i}`;if(null!=o&&null!=i)return`p:${o}:${i}`}return"p:"+o;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+o;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??o}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+o:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function fl(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}function pl(t,e,o,i,n,r){const s=[];for(const n of t){const t=o(n),r=i(n);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:n})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),c=Array(s.length),l=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],c[t]=e.rawY,l[t]=e.d}return{type:"line",path:a,rawValues:c,style:n,datum:l,group:r}}function yl(t,e,o,i,n,r,s,a){const c=[];for(const r of t){const t=o(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const l=e.x(t),u=a?a(r):n;c.push({px:l,topY:e.y(s),botY:e.y(u),rawY:s})}c.sort((t,e)=>t.px-e.px);const l=Array(c.length),u=Array(c.length),d=Array(c.length);for(let t=0;c.length>t;t++){const e=c[t];l[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:l,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function gl(t,e,o,i){const n=new Map;if("silhouette"===i)for(const i of t){let t=0;for(const n of e)t+=o(n,i)||0;n.set(i,-t/2)}else if("wiggle"===i){t.length>0&&n.set(t[0],0);for(let i=1;t.length>i;i++){const r=t[i-1],s=t[i];let a=0,c=0,l=0;for(const t of e){const e=o(t,s)||0;a+=(2*l+e)*(e-(o(t,r)||0)),c+=e,l+=e}const u=n.get(r)??0;n.set(s,u-(c>0?a/(2*c):0))}if(t.length>0){let i=0;for(const r of t){let t=0;for(const i of e)t+=o(i,r)||0;i+=(n.get(r)??0)+t/2}const r=i/t.length;for(const e of t)n.set(e,(n.get(e)??0)-r)}}else for(const e of t)n.set(e,0);return n}function ml(t,e,o,i,n,r,s){const a=o(t),c=i(t);if(!Number.isFinite(a)||!Number.isFinite(c))return null;const l={type:"point",x:e.x(a),y:e.y(c),r:n,style:r,datum:t};return void 0!==s&&(l.pointId=s),l}function xl(t,e,o,i,n,r,s,a){const c=o(t),l=i(t);if(!Number.isFinite(c)||!Number.isFinite(l))return null;const u={type:"symbol",x:e.x(c),y:e.y(l),size:n,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function bl(t,e,o,i,n,r,s){return{type:"rect",x:t,y:e,w:o,h:i,style:n,datum:r,group:s}}function vl(t,e,o,i,n,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:i,fill:n,datum:r};return void 0!==s?.value&&(a.value=s.value),s?.showValues&&(a.showValues=!0,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function wl(t,e,o,i){return"function"==typeof e.style?e.style(i||{},o):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(o,i)}function kl(t,e,o,i){if(!t.scales)return null;const n=[],r=[];for(const o of e){const e=t.getX(o);if(!Number.isFinite(e))continue;const s=i.getTop(o),a=i.getBottom(o);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const c=t.scales.x(e),l=t.scales.y(s),u=t.scales.y(a);Number.isFinite(c)&&Number.isFinite(l)&&Number.isFinite(u)&&(n.push([c,l]),r.push([c,u]))}return 2>n.length?null:{type:"area",topPath:n,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:wl(t,i,o,e[0]),datum:e,group:o,interactive:i.interactive}}function Sl(t){const e=[],o=[];if(!t)return{perSeries:e,aggregate:o};for(const i of t)i.perSeries?e.push(i):o.push(i);return{perSeries:e,aggregate:o}}function Al(t,e,o){const i=[];for(const n of o){const o=kl(t,e,"__ribbon_aggregate",n);o&&i.push(o)}return i}function Ml(t,e,o,i){const n=[];for(const r of i){const i=kl(t,e,o,r);i&&n.push(i)}return n}function _l(t,e,o,i){if(!t.config.pointStyle)return;const n=i??t.getY;for(const i of e){const e=t.resolveGroupColor(i.key);for(const r of i.data){let i=t.config.pointStyle(r);!i.fill&&e&&(i={...i,fill:e});const s=i.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,c=ml(r,t.scales,t.getX,n,s,i,a);c&&o.push(c)}}}function Pl(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function Ll(t){return dt(t)}import{symbol as $l,symbolCircle as Rl,symbolCross as Cl,symbolDiamond as Il,symbolSquare as Tl,symbolStar as Ol,symbolTriangle as zl,symbolWye as Fl}from"d3-shape";var Nl={circle:Rl,square:Tl,triangle:zl,diamond:Il,star:Ol,cross:Cl,wye:Fl},El=new Set(["circle","square","triangle","diamond","star","cross","wye","chevron"]),Dl=["circle","triangle","diamond","star","square","chevron","cross","wye"];function Bl(t,e,o){if(o)return o;const i=t??"circle";if("chevron"===i)return function(t){const e=1.5*Wl(t),o=.92*e;return`M0,${-e}L${o},${(.78*e).toFixed(3)}L0,${(.28*e).toFixed(3)}L${-o},${(.78*e).toFixed(3)}Z`}(e);const n=Object.prototype.hasOwnProperty.call(Nl,i)?Nl[i]:Rl;return $l(n,Math.max(1,e))()??""}function Wl(t){return Math.sqrt(Math.max(1,t)/Math.PI)}function jl(t,e){const o=new Map;let i=0;return n=>{const r=t(n)+"",s=e&&Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(s&&El.has(s))return s;let a=o.get(r);return a||(a=Dl[i%Dl.length],i++,o.set(r,a)),a}}var Yl=new Map;function Xl(t){const e=Object.prototype.hasOwnProperty.call(O,t)?t:"blues";let o=Yl.get(e);if(o)return o;o=Array(256);const i=z(e);for(let t=0;256>t;t++)o[t]=i(t/255);return Yl.set(e,o),o}function ql(t,e,o){const i=o.config.areaStyle?.(e);return i&&("string"==typeof i.fill&&(t.fill=i.fill),t.style=i),t}function Gl(t,e,o,i,n){const r=new Map;for(const s of t){const t=e(s),a=o(s);if(null==t||null==a||Number.isNaN(t)||Number.isNaN(a))continue;const c=Math.floor(t/i)*i;let l=r.get(c);if(l||(l={start:c,end:c+i,total:0,categories:new Map},r.set(c,l)),l.total+=a,n){const t=n(s);l.categories.set(t,(l.categories.get(t)||0)+a)}}return r}function Vl(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:i,warned:n}=t;Hl(i)&&0===o.length&&Ul(n,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),o.length>0&&o.every(t=>null==t.datum)&&Ul(n,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function Hl(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(Hl))}function Ul(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function Kl(t,e,o,i){const n=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${n.message}`,error:n,recovery:o?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:o,affectedRevision:i}}function Zl(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function Ql(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,i=Zl(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=Hc(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=i(t);if(!Number.isFinite(e))return NaN;const n=o(t);return Number.isFinite(n)&&0!==n?e+n:e},getBottom:t=>{const e=i(t);if(!Number.isFinite(e))return NaN;const n=o(t);return Number.isFinite(n)&&0!==n?e-n:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const o=Array.isArray(t.band)?t.band:[t.band];for(const t of o)e.push({kind:"band",getTop:Zl(t.y1Accessor,"y1"),getBottom:Zl(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as Jl,scaleLog as tu,scaleSymlog as eu,scaleTime as ou}from"d3-scale";function iu(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function nu(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return tu().domain(t).range(o).clamp(!0)}return"symlog"===t?eu().domain(e).range(o):"time"===t?ou().domain([new Date(e[0]),new Date(e[1])]).range(o):Jl().domain(e).range(o)}function ru(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function su(t,e){const o=new qc(t.capacity);return t.forEach(()=>o.push(e)),o}function au(t,e,o,i){const n=t.push(e);return o&&o.push(i),n}function cu(t,e,o){if(!e||0===e.size)return;const i=new Set;if(t.forEach((t,e)=>{o(t)&&i.add(e)}),0===i.size)return;const n=e.toArray();e.clear();for(let t=0;n.length>t;t++)i.has(t)||e.push(n[t])}var lu=new WeakMap;function uu(){return this.updateResults.last}function du(){return this.updateResults.last}function hu(t){return this.updateResults.subscribe(t)}function fu(t){this.config.layoutSelection=t}function pu(){lu.set(this,!0)}function yu(){const t=!0===lu.get(this);return lu.delete(this),t}function gu(t){Object.assign(t.prototype,{getLastUpdateResult:uu,getUpdateSnapshot:du,subscribeUpdateResult:hu,setLayoutSelection:fu,markStylePaintPending:pu,consumeStylePaintPending:yu})}var mu=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],xu=["scene-style","data-paint","accessibility","evidence"],bu=(t,e)=>({retainedData:t,invalidations:e}),vu=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],wu=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ku=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Su=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Au=["scene-geometry","data-paint","accessibility","evidence"],Mu=["scene-style","data-paint","accessibility","evidence"],_u=[],Pu={chartType:bu("rebuild",vu),runtimeMode:bu("rebuild",vu),xAccessor:bu("rebuild",vu),yAccessor:bu("rebuild",vu),timeAccessor:bu("rebuild",vu),valueAccessor:bu("rebuild",vu),y0Accessor:bu("rebuild",vu),boundsAccessor:bu("rebuild",vu),band:bu("rebuild",vu),openAccessor:bu("rebuild",vu),highAccessor:bu("rebuild",vu),lowAccessor:bu("rebuild",vu),closeAccessor:bu("rebuild",vu),candlestickRangeMode:bu("rebuild",vu),accessorRevision:bu("rebuild",vu),groupAccessor:bu("rebuild",wu),categoryAccessor:bu("rebuild",wu),lineDataAccessor:bu("rebuild",wu),colorAccessor:bu("rebuild",Mu),sizeAccessor:bu("rebuild",Au),symbolAccessor:bu("rebuild",Au),pointIdAccessor:bu("rebuild",Au),xScaleType:bu("preserve",ku),yScaleType:bu("preserve",ku),xExtent:bu("preserve",ku),yExtent:bu("preserve",ku),extentPadding:bu("preserve",ku),scalePadding:bu("preserve",ku),axisExtent:bu("preserve",ku),yAxisExtent:bu("preserve",ku),binSize:bu("preserve",ku),normalize:bu("preserve",ku),heatmapAggregation:bu("preserve",ku),heatmapXBins:bu("preserve",ku),heatmapYBins:bu("preserve",ku),arrowOfTime:bu("preserve",Su),baseline:bu("preserve",Su),stackOrder:bu("preserve",Su),sizeRange:bu("preserve",Su),curve:bu("preserve",Su),areaGroups:bu("preserve",Su),customLayout:bu("preserve",Su),layoutConfig:bu("preserve",Su),layoutMargin:bu("preserve",Su),symbolMap:bu("preserve",Au),showValues:bu("preserve",Au),heatmapValueFormat:bu("preserve",Au),lineStyle:bu("preserve",Mu),pointStyle:bu("preserve",Mu),areaStyle:bu("preserve",Mu),barStyle:bu("preserve",Mu),swarmStyle:bu("preserve",Mu),waterfallStyle:bu("preserve",Mu),candlestickStyle:bu("preserve",Mu),boundsStyle:bu("preserve",Mu),gradientFill:bu("preserve",Mu),lineGradient:bu("preserve",Mu),semanticLineStops:bu("preserve",Mu),colorScheme:bu("preserve",Mu),themeCategorical:bu("preserve",Mu),themeSemantic:bu("preserve",Mu),themeSequential:bu("preserve",Mu),themeDiverging:bu("preserve",Mu),barColors:bu("preserve",Mu),decay:bu("preserve",Mu),pulse:bu("preserve",Mu),staleness:bu("preserve",Mu),layoutSelection:bu("preserve",Mu),annotations:bu("preserve",["overlay","accessibility","evidence"]),windowSize:bu("preserve",_u),windowMode:bu("preserve",_u),maxCapacity:bu("preserve",_u),clock:bu("preserve",_u),transition:bu("preserve",_u),introAnimation:bu("preserve",_u),onLayoutError:bu("preserve",_u)},Lu=bu("preserve",Su),$u=class{constructor(){this.tracker=new Yr}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},mu)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},xu):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const i of t){const t=Pu[i]??Lu;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as Ru}from"d3-quadtree";var Cu=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(t,e){if("scatter"!==t&&"bubble"!==t&&"custom"!==t)return void this.clear();let o=0,i=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(o++,t.r>i&&(i=t.r));if(this.maxRadius=i,500>=o)return void(this.tree=null);const n=Array(o);let r=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(n[r++]=t);this.tree=Ru().x(t=>t.x).y(t=>t.y).addAll(n)}},Iu=class t{constructor(t){if(this.xExtent=new Gc,this.yExtent=new Gc,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new $u,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.spatialIndex=new Cu,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,o)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,i,n,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;const l=n??(()=>{const t=new Map;for(let e=0;o.length>e;e++)t.set(o[e],e);return t})();for(const o of e){if("line"===o.type)continue;if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[o.datum];let n=0,a=!1;for(const o of e){const e=l.get(o);if(null==e)continue;a=!0;const s=i.get(e);if(null==s)continue;const c=ll(t,s,r);c>n&&(n=c)}a&&(c=ul(o,n,s)||c);continue}const e=l.get(o.datum);if(null==e)continue;const n=i.get(e);c=ul(o,null==n?0:ll(t,n,r),s,a)||c}return c}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new qc(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=Hc(t.timeAccessor||t.xAccessor,"time"),this.getY=Hc(t.valueAccessor||t.yAccessor,"value")):(this.getX=Hc(t.xAccessor,"x"),this.getY=Hc(t.yAccessor,"y")),this.getGroup=Kc(t.groupAccessor),this.getCategory=Kc(t.categoryAccessor),this.getSize=t.sizeAccessor?Hc(t.sizeAccessor,"size"):void 0,this.getColor=Kc(t.colorAccessor),this.getSymbol=Kc(t.symbolAccessor),this.getY0=t.y0Accessor?Hc(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=Ql(t),this.getPointId=Kc(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?Hc(t.openAccessor,"open"):void 0,this.getHigh=Hc(t.highAccessor,"high"),this.getLow=Hc(t.lowAccessor,"low"),this.getClose=o?Hc(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new qc(t.windowSize))}currentTime(){return this.config.clock?.()??sl()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=su(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(t)),void this.yExtent.push(this.getLow(t));this.yExtent.push(this.getY(t)),this.getY0&&this.yExtent.push(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),i=e.getBottom(t);Number.isFinite(o)&&this.yExtent.push(o),Number.isFinite(i)&&this.yExtent.push(i)}}evictDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(t)),void this.yExtent.evict(this.getLow(t));this.yExtent.evict(this.getY(t)),this.getY0&&this.yExtent.evict(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),i=e.getBottom(t);Number.isFinite(o)&&this.yExtent.evict(o),Number.isFinite(i)&&this.yExtent.evict(i)}}rebuildYExtent(){this.yExtent.clear();for(const t of this.buffer)this.pushDatumYExtent(t)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(const t of this.buffer)this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t)}ingest(t){if(t.bounded&&this._lastBoundedInsertsRef===t.inserts)return this.updateResults.recordNoop("replace"),!1;const e=this.currentTime();if(this.lastIngestTime=e,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,t.bounded){this._lastBoundedInsertsRef=t.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const o=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=o?Hc(this.config.timeAccessor||this.config.xAccessor,"time"):Hc(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],o=this.config.xAccessor,i="function"==typeof o?o(e):e[o||"x"],n=i instanceof Date,r="string"==typeof i&&Number.isFinite(tl(i));if(this.xIsDate=n||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>el(e[t]):t=>el(o(t))}}ru(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)au(this.buffer,o,this.timestampBuffer,e),this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o)}else for(const o of t.inserts){if("growing"===this.config.windowMode&&this.buffer.full){const t=this.config.maxCapacity??1e5;t>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,t),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"===process.env.NODE_ENV||this.growingCapacityWarned||5e4>this.growingCap||(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${t}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}const t=au(this.buffer,o,this.timestampBuffer,e);this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o),null!=t&&(this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t))}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}computeScene(t){const{config:e,buffer:o}=this,i=this.scales,n=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(o,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=iu(this.xExtent.extent,e.xExtent),c=iu(s,e.yExtent);const l=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===(e.yAxisExtent??e.axisExtent);if("stackedarea"===e.chartType&&!l&&o.size>0){const t=function(t){const{config:e,groups:o,getX:i,getY:n}=t,r="exact"===(e.yAxisExtent??e.axisExtent);if(e.normalize){const o=[0,r?1:1+e.extentPadding];return{yDomain:o,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:o}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,c=new Set;let l=0;const u=new Map,d=new Map;for(const t of o){const e=new Map;let o=0;for(const r of t.data){const t=i(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),c.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>l&&(l=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",f=(t,e)=>e>t?-1:t>e?1:0;let p,y;if("input"===h)p=o.map(t=>t.key);else if("insideOut"===h){const t=[...o].map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}),e=[],i=[];let n=0,r=0;for(const o of t)r>n?(e.push(o),n+=d.get(o)??0):(i.push(o),r+=d.get(o)??0);p=[...i.reverse(),...e]}else p="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:f(t,e)}):"desc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}):o.map(t=>t.key).sort(f);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),o=gl(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let i=1/0,n=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;i>t&&(i=t),t+r>n&&(n=t+r)}Number.isFinite(i)&&Number.isFinite(n)||(i=0,n=0);const s=n-i,l=r?0:s>0?s*e.extentPadding:1;y=[i-l,n+l]}else if("diverging"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),[o,i]=function(t,e,o){let i=0,n=0;for(const r of t){let t=0,s=0;for(const i of e){const e=o(i,r)||0;0>e?s+=e:t+=e}i>s&&(i=s),t>n&&(n=t)}return[i,n]}(t,p,(t,e)=>a.get(t)?.get(e)||0),n=i-o,s=r?0:n>0?n*e.extentPadding:1;y=[o-s,i+s]}else y=[0,l+(r?0:l>0?l*e.extentPadding:1)];return{yDomain:y,stackExtentCache:{key:s,yDomain:y}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:o.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!l&&o.size>0?c=function(t,e,o,i,n,r,s){const[,a]=function(t,e,o,i,n){const r=Gl(t,e,o,i,n);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,o,i,n);return[0,s?a:a+a*r]}(o,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,d):"waterfall"===e.chartType&&!l&&o.size>0?c=function(t,e,o,i){const[n,r]=function(t,e){let o=0,i=0,n=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(n+=t,o>n&&(o=n),n>i&&(i=n))}return[o,i]}(t,e),s=r-n,a=i?0:s>0?s*o:1;return[Math.min(0,n-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(o,this.getY,e.extentPadding,d):l||c[0]===1/0||(c=function(t,e,o){if(!o.length)return t;let[i,n]=t;for(const t of e)for(const e of o){const o=e.getTop(t),r=e.getBottom(t);Number.isFinite(o)&&(i>o&&(i=o),o>n&&(n=o)),Number.isFinite(r)&&(i>r&&(i=r),r>n&&(n=r))}return[i,n]}(c,r,this.resolvedRibbons),c=function(t,e){const o=t[1]-t[0],i=e.exactMode?0:o>0?o*e.extentPadding:1,n=[null!=e.userMin?t[0]:t[0]-i,null!=e.userMax?t[1]:t[1]+i];return"log"!==e.yScaleType||n[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(n[0]=e.dataYDomain[0]/(1+e.extentPadding)),n}(c,{exactMode:d,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));c=function(t,e,o){if(!e||o)return t;const i=e[0],n=e[1];return null==i&&null==n?t:[null!=i?i:t[0],null!=n?n:t[1]]}(c,e.yExtent,!!l),({xDomain:a,yDomain:c}=function(t,e,o){let i=t,n=e;if(i[0]===1/0||i[1]===-1/0)if("time"===o){const t=Date.now();i=[t-864e5,t]}else i=[0,1];return n[0]!==1/0&&n[1]!==-1/0||(n=[0,1]),{xDomain:i,yDomain:n}}(a,c,e.xScaleType)),this.scales=function(t){const{config:e,layout:o,xDomain:i,yDomain:n}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(o.width,o.height)/2-1));if(r){const t="left"===e.arrowOfTime?[o.width-s,s]:[s,o.width-s];return{x:Jl().domain(i).range(t),y:nu(e.yScaleType,n,[o.height-s,s])}}return{x:nu(e.xScaleType,i,[s,o.width-s]),y:nu(e.yScaleType,n,[o.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:c}),this._customLayoutFailedThisBuild=!1;const h=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=i,this.lastLayout=n):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=h,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:t.width,height:t.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(t){const e=t.width/this.lastLayout.width,o=t.height/this.lastLayout.height;for(const t of this.scene)switch(t.type){case"line":for(const i of t.path)i[0]*=e,i[1]*=o;break;case"area":for(const i of t.topPath)i[0]*=e,i[1]*=o;for(const i of t.bottomPath)i[0]*=e,i[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*o,width:t.clipRect.width*e,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(t=>({...t,y:t.y*o,height:t.height*o})));break;case"point":case"glyph":t.x*=e,t.y*=o;break;case"rect":case"heatcell":t.x*=e,t.y*=o,t.w*=e,t.h*=o;break;case"candlestick":t.x*=e,t.openY*=o,t.closeY*=o,t.highY*=o,t.lowY*=o}const i=this.scales.x.domain(),n=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=nu,c=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),l=s[1]>s[0];this.scales={x:a(this.config.xScaleType,i,r[0]>r[1]?[t.width-c,c]:[c,t.width-c]),y:a(this.config.yScaleType,n,l?[c,t.height-c]:[t.height-c,c])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:o,scales:i}=this;if(!i)return[];if(o.customLayout){const n={data:e,scales:i,dimensions:{width:t.width,height:t.height,margin:o.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:o.themeCategorical??V},resolveColor:(t,e)=>{const i=this.resolveGroupColor(t);if(i)return i;const n=this.resolveLineStyle(t,e);return n.stroke?n.stroke:"string"==typeof n.fill?n.fill:o.themeSemantic?.primary??"#4e79a7"},config:o.layoutConfig??{},selection:o.layoutSelection??null};let r;try{r=o.customLayout(n)}catch(t){const e=null!==this.lastCustomLayoutResult,i=Kl("xy",t,e,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{o.onLayoutError?.(i)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null;const s=r.nodes??[];if(this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of s)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(s,o.layoutSelection??null)}return Vl({label:"customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const n={scales:i,config:o,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(t,e)=>this.resolveLineStyle(t,e),resolveAreaStyle:(t,e)=>this.resolveAreaStyle(t,e),resolveBoundsStyle:(t,e)=>this.resolveBoundsStyle(t,e),resolveColorMap:t=>this.resolveColorMap(t),resolveGroupColor:t=>this.resolveGroupColor(t),groupData:t=>this.groupData(t),barCategoryCache:this._barCategoryCache};switch(o.chartType){case"line":return function(t,e){const o=t.groupData(e),i=[],n=t.config.annotations?.filter(Pl).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=Sl(t.ribbons);if(r.length>0&&i.push(...Al(t,e,r)),n.length>0)for(const e of o)i.push(...Ml(t,e.data,e.key,n))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=pl(e.data,t.scales,t.getX,t.getY,o,e.key);n&&n.length>0&&(r.colorThresholds=n),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),i.push(r)}return _l(t,o,i),i}(n,e);case"area":return function(t,e){const o=t.groupData(e),i=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=Sl(t.ribbons);if(r.length>0&&i.push(...Al(t,e,r)),n.length>0)for(const e of o)i.push(...Ml(t,e.data,e.key,n))}const n=t.scales.y.domain(),r=n[0],s=t.config.semanticLineStops?.filter(t=>Number.isFinite(t.offset)).map(t=>({value:n[0]+Math.max(0,Math.min(1,t.offset))*(n[1]-n[0]),color:t.color,opacity:t.opacity,thresholdType:"greater"})).sort((t,e)=>t.value-e.value),a=s&&s.length>0?(()=>{const e=s.reduce((t,e)=>(t.at(-1)?.value===e.value?t[t.length-1]=e:t.push(e),t),[]),o=[{from:n[0],to:e[0].value,color:e[0].color,opacity:e[0].opacity}];for(let t=0;e.length>t;t++)o.push({from:e[t].value,to:e[t+1]?.value??n[1],color:e[t].color,opacity:e[t].opacity});return o.map(({from:e,to:o,color:i,opacity:n})=>{const r=t.scales.y(e),s=t.scales.y(o);return{y:Math.min(r,s),height:Math.abs(s-r),color:i,...null!=n&&{opacity:n}}}).filter(t=>t.height>0)})():void 0,c=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o){const o=t.resolveAreaStyle(e.key,e.data[0]),n=yl(e.data,t.scales,t.getX,t.getY,r,o,e.key,c),l=Ll(t.config.gradientFill);l&&(n.fillGradient=l),t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),s&&s.length>0&&(n.colorThresholds=s,n.strokeColorBands=a),i.push(n)}return _l(t,o,i),i}(n,e);case"mixed":return function(t,e){const o=t.groupData(e),i=[],n=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:n,aggregate:r}=Sl(t.ribbons);if(r.length>0&&i.push(...Al(t,e,r)),n.length>0)for(const e of o)i.push(...Ml(t,e.data,e.key,n))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o)if(n.has(e.key)){const o=t.resolveAreaStyle(e.key,e.data[0]),n=yl(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=Ll(t.config.gradientFill);a&&(n.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),i.push(n)}else{const o=t.resolveLineStyle(e.key,e.data[0]),n=pl(e.data,t.scales,t.getX,t.getY,o,e.key);t.config.curve&&"linear"!==t.config.curve&&(n.curve=t.config.curve),t.config.lineGradient&&(n.strokeGradient=t.config.lineGradient),i.push(n)}return _l(t,o,i),i}(n,e);case"stackedarea":return function(t,e){const o=t.groupData(e),i=t.config.stackOrder??"key",n=()=>o.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===i);else if("key"===i)n();else if("asc"===i||"desc"===i||"insideOut"===i){const e=new Map;for(const i of o){let o=0;for(const e of i.data){const i=t.getX(e),n=t.getY(e);Number.isFinite(i)&&Number.isFinite(n)&&(o+=n)}e.set(i.key,o)}const n=(t,e)=>e>t?-1:t>e?1:0;if("asc"===i)o.sort((t,o)=>{const i=(e.get(t.key)??0)-(e.get(o.key)??0);return 0!==i?i:n(t.key,o.key)});else if("desc"===i)o.sort((t,o)=>{const i=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==i?i:n(t.key,o.key)});else{const t=[...o].sort((t,o)=>{const i=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==i?i:n(t.key,o.key)}),i=[],r=[];let s=0,a=0;for(const o of t)a>s?(i.push(o),s+=e.get(o.key)??0):(r.push(o),a+=e.get(o.key)??0);o.length=0,o.push(...r.reverse(),...i)}}else n();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:c}=function(t,e,o,i,n,r,s,a="zero"){const c=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&c.add(e)}const l=Array.from(c).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const n of e.data){const e=o(n),r=i(n);Number.isFinite(e)&&Number.isFinite(r)&&t.set(e,(t.get(e)||0)+r)}u.set(e.key,t)}let d;if(r){d=new Map;for(const e of l){let o=0;for(const i of t)o+=u.get(i.key)?.get(e)||0;d.set(e,o||1)}}const h=gl(l,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],y=new Map,g=new Map,m=new Map,x=new Map;for(const t of l)g.set(t,h.get(t)??0),m.set(t,0),x.set(t,0);for(const o of t){const t=u.get(o.key),i=new Map;let a=[],c=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:c,style:n(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),p.push(t)}a=[],c=[]};for(const o of l){const n=t.has(o);let s,l,u=n?t.get(o):0;if(r&&n&&(u/=d.get(o)),!n||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(o),l=s+u,m.set(o,l)):(s=x.get(o),l=s+u,x.set(o,l)):(s=g.get(o),l=s+u,g.set(o,l));const p=e.x(o);c.push([p,e.y(s)]),a.push([p,e.y(l)]),i.set(o,l)}h(),y.set(o.key,i)}return{nodes:p,stackedTops:y}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),l=a;if(t.config.pointStyle){const e=new WeakMap;for(const i of o){const o=c.get(i.key);if(o)for(const n of i.data){const i=t.getX(n),r=t.getY(n);null==i||Number.isNaN(i)||null==r||Number.isNaN(r)||!o.has(i)||e.set(n,o.get(i))}}const i=o=>e.get(o)??t.getY(o);_l(t,o,l,i)}return l}(n,e);case"scatter":case"bubble":return function(t,e){const o=[],i="bubble"===t.config.chartType?10:5,n=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const o=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(o.length>0){let t=1/0,e=-1/0;for(const i of o)t>i&&(t=i),i>e&&(e=i);r=o=>t===e?(n[0]+n[1])/2:n[0]+(o-t)/(e-t)*(n[1]-n[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",c=t.getSymbol,l=c?jl(c,t.config.symbolMap):null;for(const n of e){let e=t.config.pointStyle?t.config.pointStyle(n):{fill:a,opacity:.8},c=e.r||i;if(r&&t.getSize){const e=t.getSize(n);null==e||Number.isNaN(e)||(c=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(n);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(n)+"":void 0;if(l){const i=l(n),r=xl(n,t.scales,t.getX,t.getY,Math.PI*c*c,i,e,u);r&&o.push(r)}else{const i=ml(n,t.scales,t.getX,t.getY,c,e,u);i&&o.push(i)}}return o}(n,e);case"heatmap":return function(t,e,o){if(t.config.heatmapAggregation)return function(t,e,o){const i=Math.max(1,Math.floor(t.config.heatmapXBins??20)),n=Math.max(1,Math.floor(t.config.heatmapYBins??20)),r=t.config.heatmapAggregation??"count",s=Hc(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,c]=t.scales.x.domain(),[l,u]=t.scales.y.domain(),d=(c-a||1)/i,h=(u-l||1)/n,f=i*n;if(f>1e6)return[];const p=new Int32Array(f),y=new Float64Array(f);for(let o=0;e.length>o;o++){const r=e[o],c=t.getX(r),u=t.getY(r);if(!isFinite(c)||!isFinite(u))continue;const f=Math.min(Math.floor((c-a)/d),i-1),g=Math.min(Math.floor((u-l)/h),n-1);if(0>f||0>g)continue;const m=g*i+f;p[m]++;const x=s(r);y[m]+=isFinite(x)?x:0}let g=1/0,m=-1/0;for(let t=0;f>t;t++){if(0===p[t])continue;let e;switch(r){case"sum":e=y[t];break;case"mean":e=y[t]/p[t];break;default:e=p[t]}g>e&&(g=e),e>m&&(m=e)}if(!isFinite(g))return[];const x=m-g||1,b=t.config.heatmapColorScale,v=b?void 0:Xl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),w=255/x,k=o.width/i,S=o.height/n,A=t.config.showValues,M=t.config.heatmapValueFormat,_=[];for(let e=0;n>e;e++){const o=e*i;for(let s=0;i>s;s++){const i=o+s;if(0===p[i])continue;let c;switch(r){case"sum":c=y[i];break;case"mean":c=y[i]/p[i];break;default:c=p[i]}const u=Math.min((c-g)*w+.5|0,255),f=b?b(c):v[u],m={xi:s,yi:e,value:c,count:p[i],sum:y[i],xCenter:a+(s+.5)*d,yCenter:l+(e+.5)*h,agg:r};_.push(ql(vl(s*k,(n-1-e)*S,k,S,f,m,A?{value:c,showValues:!0,valueFormat:M}:{value:c}),m,t))}}return _}(t,e,o);if(0===e.length)return[];const i=Hc(t.config.valueAccessor,"value"),n=Uc(t.config.xAccessor,"x"),r=Uc(t.config.yAccessor,"y"),s=new Map,a=new Map,c=Array(e.length),l=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],i=n(o),u=r(o);c[t]=i,l[t]=u,s.has(i)||s.set(i,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),f=Array.from(a.keys()),p=h.every(t=>"number"==typeof t&&!isNaN(t)),y=f.every(t=>"number"==typeof t&&!isNaN(t));if(p){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(y){f.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;f.length>t;t++)a.set(f[t],t)}const g=new Float64Array(e.length),m=new Float64Array(e.length),x=Array(e.length),b=new Map;let v=0;for(let t=0;e.length>t;t++){const o=e[t],n=s.get(c[t]),r=a.get(l[t]);if(void 0===n||void 0===r)continue;const d=i(o),h=r*u+n,f=b.get(h);let p;void 0!==f?p=f:(p=v++,b.set(h,p)),g[p]=h,m[p]=d,x[p]=o}let w=1/0,k=-1/0;for(let t=0;v>t;t++){const e=m[t];isFinite(e)&&(w>e&&(w=e),e>k&&(k=e))}if(!isFinite(w)||!isFinite(k))return[];const S=t.config.heatmapColorScale,A=S?void 0:Xl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),M=255/(k-w||1),_=o.width/u,P=o.height/d,L=t.config.showValues,$=t.config.heatmapValueFormat,R=[];for(let e=0;v>e;e++){const o=m[e];if(!isFinite(o))continue;const i=g[e],n=i%u,r=(i-n)/u,s=Math.min((o-w)*M+.5|0,255),a=S?S(o):A[s],c=x[e];R.push(ql(vl(n*_,(d-1-r)*P,_,P,a,c,L?{value:o,showValues:!0,valueFormat:$}:{value:o}),c,t))}return R}(n,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=Gl(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===o.size)return{nodes:[],binBoundaries:[]};let i=null;if(t.getCategory){const e=new Set;for(const t of o.values())for(const o of t.categories.keys())e.add(o);const n=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(n),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=n.filter(t=>e.has(t)),c=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===c?i=t.barCategoryCache.order:(i=[...a,...s],t.barCategoryCache={key:c,order:i})}const n=[],r=t.scales,[s,a]=r.x.domain(),c=t.config.barStyle,l=t.config.themeSemantic?.primary,u=c?.gap,d="number"!=typeof u||0>u?1:u,h={};c?.stroke&&(h.stroke=c.stroke),"number"==typeof c?.strokeWidth&&(h.strokeWidth=c.strokeWidth),"number"==typeof c?.opacity&&(h.opacity=c.opacity),c?.cursor&&(h.cursor=c.cursor);for(const e of o.values()){const o=Math.max(e.start,s),u=Math.min(e.end,a);if(o>=u)continue;const f=r.x(o),p=r.x(u),y=Math.abs(p-f),g=y>d+1?d:0,m=Math.min(f,p)+g/2,x=Math.max(y-g,1);if(x>0)if(i&&e.categories.size>0){let o=0;for(const s of i){const i=e.categories.get(s)||0;if(0===i)continue;const a=r.y(o),u=r.y(o+i),d=Math.min(a,u),f=Math.abs(a-u),p=(t.config.barColors?Z(t.config.barColors,s):void 0)??c?.fill??l??"#4e79a7",y={binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:i},g=t.config.areaStyle?.(y)??{};n.push(bl(m,d,x,f,{fill:p,...h,...g},y,s)),o+=i}}else{const o=r.y(0),i=r.y(e.total),s=Math.min(o,i),a=Math.abs(o-i),u=c?.fill||l||"#007bff",d={binStart:e.start,binEnd:e.end,total:e.total},f=t.config.areaStyle?.(d)??{};n.push(bl(m,s,x,a,{fill:u,...h,...f},d))}}const f=new Set;for(const t of o.values())f.add(t.start),f.add(t.end);return{nodes:n,binBoundaries:Array.from(f).sort((t,e)=>t-e)}}(n,e);return this._barCategoryCache=n.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return function(t,e){const o=[],i=t.config.swarmStyle||{},n=i.radius??3,r=i.fill??t.config.themeSemantic?.primary??"#007bff",s=i.opacity??.7,a=i.stroke,c=i.strokeWidth,l=i.cursor;for(const i of e){const e=t.getX(i),u=t.getY(i);if(null==u||Number.isNaN(u))continue;const d=t.scales.x(e),h=t.scales.y(u);let f=r;if(t.getCategory){const e=t.getCategory(i)+"";f=(t.config.barColors?Z(t.config.barColors,e):void 0)??f}const{r:p,...y}=t.config.pointStyle?.(i)??{},g={type:"point",x:d,y:h,r:p??n,style:{fill:f,opacity:s,stroke:a,strokeWidth:c,cursor:l,...y},datum:i};t.getPointId&&(g.pointId=t.getPointId(i)+""),o.push(g)}return o}(n,e);case"waterfall":return function(t,e,o){const i=[],n=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const o=t.getY(e),i=t.getX(e);return null!=o&&!Number.isNaN(o)&&null!=i&&isFinite(i)});if(0===s.length)return i;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",c=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",l=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let f=0;for(let e=0;s.length>e;e++){const p=s[e],y=t.getX(p),g=t.getY(p),m=f+g;let x;x=s.length-1>e?t.getX(s[e+1])-y:e>0?y-t.getX(s[e-1]):0;const b=n.x(y),v=0!==x?n.x(y+x):b+o.width/10,w=Math.min(b,v)+l/2,k=Math.max(b,v)-l/2-w;if(0>=k){f=m;continue}const S=n.y(f),A=n.y(m),M=Math.min(S,A),_=Math.abs(S-A),P=0>g?c:a,L={...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},$={fill:P,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(L)};i.push(bl(w,M,k,_,$,L)),f=m}return i}(n,e,t);case"candlestick":return function(t,e,o){if(!t.getHigh||!t.getLow||!t.scales)return[];const i=t.config.candlestickRangeMode??!1;if(!(i||t.getOpen&&t.getClose))return[];const n=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=i?s:r.upColor||"#28a745",c=i?s:r.downColor||"#dc3545",l=i?s:r.wickColor||"#333",u=r.wickWidth||(i?2:1),d=e.map(e=>t.getX(e)).filter(t=>null!=t&&!Number.isNaN(t)).sort((t,e)=>t-e);let h=r.bodyWidth??0;if(null==r.bodyWidth)if(d.length>1){let e=1/0;for(let o=1;d.length>o;o++){const i=Math.abs(t.scales.x(d[o])-t.scales.x(d[o-1]));i>0&&e>i&&(e=i)}h=e!==1/0?Math.max(2,Math.min(.6*e,20)):6}else h=6;for(const s of e){const e=t.getX(s);if(null==e||Number.isNaN(e))continue;const d=t.getHigh(s),f=t.getLow(s);if(null==d||Number.isNaN(d)||null==f||Number.isNaN(f))continue;const p=i?d:t.getOpen(s),y=i?f:t.getClose(s);if(!i&&[p,y].some(t=>null==t||Number.isNaN(t)))continue;const g=y>=p,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(p),closeY:t.scales.y(y),highY:t.scales.y(d),lowY:t.scales.y(f),bodyWidth:h,upColor:a,downColor:c,wickColor:l,wickWidth:u,isUp:g,style:{cursor:r.cursor},datum:s};i&&(m.isRange=!0,m.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),n.push(m)}return n}(n,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,o,i){const n=t.boundsStyle;if("function"==typeof n)return n(o||{},e);if(n&&"object"==typeof n)return n;const r=i(e,o);return{fill:r.stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none",cursor:r.cursor}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?al(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=cl(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,i=cl(o)){const n=o.length;if(n>1)for(const o of e){if("line"===o.type){const e=Array.isArray(o.datum)?o.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let o=0;e.length>o;o++){const a=i.get(e[o]);null!=a?(r[o]=al(t,a,n),1>r[o]&&(s=!0)):r[o]=1}s&&(o._decayOpacities=r);continue}if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[],r=o.topPath?o.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let o=0;e.length>o;o++){const r=i.get(e[o]);null!=r?(s[o]=al(t,r,n),1>s[o]&&(a=!0)):s[o]=1}a&&(o._decayOpacities=s)}else{let s=1;for(const o of e){const e=i.get(o);if(null!=e){const o=al(t,e,n);s>o&&(s=o)}}if(1>s){const t=Array(r);t.fill(s),o._decayOpacities=t}}continue}const e=i.get(o.datum);if(null==e)continue;const r=al(t,e,n);"candlestick"===o.type?o._decayOpacity=r:o.style={...o.style,opacity:(o.style?.opacity??1)*r}}}(this.config.decay,t,e,this.getDatumIndexMap(e))}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&dl(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory}}snapshotPositions(){!function(t,e,o,i){o.clear(),i.clear();for(let n=0;e.length>n;n++){const r=e[n],s=hl(t,r,n);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:fl(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:fl(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:fl(r.style)}):"candlestick"===r.type?o.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:fl(r.style)}):"line"===r.type?i.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&i.set(s,{topPath:r.topPath.map(t=>[t[0],t[1]]),bottomPath:r.bottomPath.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();const t=this.scales?.y(0)??0;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],i=hl(this.transitionContext,o,e);i&&("point"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,r:0,opacity:0}):"rect"===o.type?this.prevPositionMap.set(i,{x:o.x,y:t,w:o.w,h:0,opacity:o.style.opacity??1}):"heatcell"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:0}):"line"===o.type?(o._introClipFraction=0,this.prevPathMap.set(i,{path:o.path.map(t=>[t[0],t[1]]),opacity:o.style.opacity})):"area"===o.type&&(o._introClipFraction=0,this.prevPathMap.set(i,{topPath:o.topPath.map(t=>[t[0],t[1]]),bottomPath:o.bottomPath.map(t=>[t[0],t[1]]),opacity:o.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,o,i,n,r=sl()){if(0===i.size&&0===n.size)return o;const s=e.duration??300;if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}let a=!1;const c=new Set,l=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=hl(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=n.get(s);if(t){if(l.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=i.get(s);if("point"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=fl(r.style),u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=fl(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=fl(r.style),u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=fl(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=fl(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=fl(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=fl(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=fl(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){c.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=fl(r.style),(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=fl(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of n)if(!l.has(t))if(t.startsWith("l:")&&e.path){const i={type:"line",path:e.path.map(t=>[t[0],t[1]]),group:t.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(i),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const i={type:"area",topPath:e.topPath.map(t=>[t[0],t[1]]),bottomPath:e.bottomPath.map(t=>[t[0],t[1]]),group:t.slice(2),style:{fill:"#999",opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(i),a=!0}for(const[t,e]of i)if(!c.has(t)){if(t.startsWith("p:"))o.exitNodes.push({type:"point",x:e.x,y:e.y,r:e.r??3,style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("g:")&&e.glyph)o.exitNodes.push({type:"glyph",x:e.x,y:e.y,size:e.r??12,glyph:e.glyph,color:"#999",accent:"#999",style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))o.exitNodes.push({type:"rect",x:e.x,y:e.y,w:e.w??0,h:e.h??0,style:{opacity:e.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("h:"))o.exitNodes.push({type:"heatcell",x:e.x,y:e.y,w:e.w??0,h:e.h??0,fill:"#999",datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t});else if(t.startsWith("c:")){const i=e.openY??e.y;o.exitNodes.push({type:"candlestick",x:e.x,openY:i,closeY:e.closeY??i,highY:e.highY??i,lowY:e.lowY??i,bodyWidth:e.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t})}a=!0}return o.exitNodes.length>0&&(o.scene=[...o.scene,...o.exitNodes]),a&&(o.activeTransition={startTime:r,duration:s}),o}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(t){if(!this.activeTransition||!this.config.transition)return!1;const e={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},o=function(t,e,o,i){if(!o.activeTransition)return!1;const n=nl(t,o.activeTransition),r=il(n,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of o.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style.opacity=rl(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=rl(o.x,t._targetX,r),t.y=rl(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=rl(o.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style.opacity=rl(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=rl(o.x,t._targetX,r),t.y=rl(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=rl(o.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style.opacity=rl(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=rl(o.x,t._targetX,r),t.y=rl(o.y,t._targetY,r),void 0!==o.w&&(t.w=rl(o.w,t._targetW,r)),void 0!==o.h&&(t.h=rl(o.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style={...t.style||{},opacity:rl(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=rl(o.x,t._targetX,r),t.y=rl(o.y,t._targetY,r),void 0!==o.w&&(t.w=rl(o.w,t._targetW,r)),void 0!==o.h&&(t.h=rl(o.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const o=e?i.get(e):void 0;t.style={...t.style||{},opacity:rl(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=i.get(e);if(!o)continue;t.x=rl(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=rl(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=rl(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=rl(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=rl(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:rl(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,o=t._targetPath;if(e&&o&&e.length===t.path.length)for(let i=0;t.path.length>i;i++)t.path[i][0]=rl(e[i][0],o[i][0],r),t.path[i][1]=rl(e[i][1],o[i][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:rl(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,o=t._prevBottomPath,i=t._targetTopPath,n=t._targetBottomPath;if(e&&i&&e.length===t.topPath.length)for(let o=0;t.topPath.length>o;o++)t.topPath[o][0]=rl(e[o][0],i[o][0],r),t.topPath[o][1]=rl(e[o][1],i[o][1],r);if(o&&n&&o.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=rl(o[e][0],n[e][0],r),t.bottomPath[e][1]=rl(o[e][1],n[e][1],r)}}if(n>=1){for(const t of o.scene){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style="line"===t.type||"area"===t.type?{...t.style,opacity:0===e?0:e}:{...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("glyph"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("heatcell"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("candlestick"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0}else if("line"===t.type){const e=t._targetPath;if(e)for(let o=0;t.path.length>o;o++)t.path[o]=e[o];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,o=t._targetBottomPath;if(e)for(let o=0;t.topPath.length>o;o++)t.topPath[o]=e[o];if(o)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=o[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}return o.activeTransition=null,!1}return!0}(t,this.config.transition,e,this.prevPositionMap);return this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition,o}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("glyph"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("rect"===e.type||"heatcell"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0);else if("candlestick"===e.type)void 0!==e._targetX&&(e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0);else if("line"===e.type||"area"===e.type){if(e._introClipFraction=void 0,"line"===e.type&&e._targetPath){for(let t=0;e.path.length>t;t++)e.path[t]=e._targetPath[t];e._prevPath=void 0,e._targetPath=void 0}if("area"===e.type){if(e._targetTopPath)for(let t=0;e.topPath.length>t;t++)e.topPath[t]=e._targetTopPath[t];if(e._targetBottomPath)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=e._targetBottomPath[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(t){const{result:e,cache:o}=function(t,e,o,i){if(i&&i.version===o&&i.group===e&&i.data===t)return{result:i.result,cache:i};let n;if(e){const o=new Map;for(const i of t){const t=e(i);o.has(t)||o.set(t,[]),o.get(t).push(i)}n=Array.from(o.entries()).map(([t,e])=>({key:t,data:e}))}else n=[{key:"_default",data:t}];return{result:n,cache:{version:o,group:e,data:t,result:n}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=o,e}resolveColorMap(t){const{map:e,cache:o}=function(t,e,o,i,n){if(n&&n.version===i)return{map:n.map,cache:n};const r=new Set;if(e)for(const o of t){const t=e(o);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(n&&n.key===a){const t={...n,version:i};return{map:t.map,cache:t}}const c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||V,l=new Map;for(let t=0;s.length>t;t++)l.set(s[t],c[t%c.length]);return{map:l,cache:{key:a,map:l,version:i}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=o,e}resolveLineStyle(t,e){return function(t,e,o,i){const n=t.lineStyle;if("function"==typeof n){const t=n(o||{},e);if(t&&!t.stroke&&e){const o=i(e);if(o)return{...t,stroke:o}}return t}const r=t.themeSemantic?.primary;return n&&"object"==typeof n?{stroke:n.stroke||r||"#007bff",strokeWidth:n.strokeWidth??2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity,cursor:n.cursor}:{stroke:i(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,o,i){if(t.areaStyle){const n=t.areaStyle(o||{});if(n&&!n.fill&&e){const t=i(e);if(t)return{...n,fill:t,stroke:n.stroke||t}}return n}const n=t.lineStyle;if("function"==typeof n){const t=n(o||{},e);if(t&&!t.fill&&e){const o=i(e);if(o)return{...t,fill:o,stroke:t.stroke||o}}return t}const r=t.themeSemantic?.primary;if(n&&"object"==typeof n)return{fill:n.fill||n.stroke||r||"#4e79a7",fillOpacity:n.fillOpacity??.7,stroke:n.stroke||r||"#4e79a7",strokeWidth:n.strokeWidth??2,cursor:n.cursor};const s=i(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(e){const{color:o,groupColorCounter:i}=function(t){const{group:e,colorMapCache:o,groupColorMap:i,groupColorMapCap:n,config:r}=t;let{groupColorCounter:s}=t;if(o){const t=o.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=i.get(e);if(a)return{color:a,groupColorCounter:s};const c=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||V;if(0===c.length)return{color:null,groupColorCounter:s};const l=c[s%c.length];if(s++,i.set(e,l),i.size>n){const t=i.keys().next().value;void 0!==t&&i.delete(t)}return{color:l,groupColorCounter:s}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:t.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=i,o}getBufferArray(){return!this._bufferDirty&&this._bufferArrayCache||(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(t){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=ol(t),o=this.getPointId,i=t=>e.has(o(t));cu(this.buffer,this.timestampBuffer,i);const n=this.buffer.remove(i);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(const t of n)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const o=ol(t),i=this.getPointId,n=new Set;this.buffer.forEach((t,e)=>{o.has(i(t))&&n.add(e)});const r=this.buffer.update(t=>o.has(i(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.buffer.forEach((t,e)=>{n.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const i of t){const t=this._baseStyles.get(i)??i.style??{},n=o(i,e);i.style=n?{...t,...n}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t||"themeCategorical"in t||"colorAccessor"in t)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in t||"colorScheme"in t)&&(this._barCategoryCache=null),("normalize"in t||"extentPadding"in t||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t||"boundsAccessor"in t||"band"in t||"y0Accessor"in t||"openAccessor"in t||"highAccessor"in t||"lowAccessor"in t||"closeAccessor"in t||"groupAccessor"in t||"categoryAccessor"in t||"chartType"in t||"runtimeMode"in t)&&(this._stackExtentCache=null);let i=!1,n=!1;Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();const r="chartType"in t&&t.chartType!==e.chartType||"runtimeMode"in t&&t.runtimeMode!==e.runtimeMode;if(r||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t){const t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,o=t&&this.config.valueAccessor||this.config.yAccessor,s=t&&e.valueAccessor||e.yAccessor,a=r||!Vc(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),c=r||!Vc(o,s);(a||c)&&(t?(this.getX=Hc(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=Hc(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=Hc(this.config.xAccessor,"x"),this.getY=Hc(this.config.yAccessor,"y")),c&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=Ql(this.config)),i=!0,n=!0)}if("groupAccessor"in t&&!Vc(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?Kc(this.config.groupAccessor):void 0,i=!0),"categoryAccessor"in t&&!Vc(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?Kc(this.config.categoryAccessor):void 0,i=!0),"sizeAccessor"in t&&!Vc(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?Hc(this.config.sizeAccessor,"size"):void 0,i=!0),"symbolAccessor"in t&&!Vc(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Kc(this.config.symbolAccessor):void 0,i=!0),"colorAccessor"in t&&!Vc(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Kc(this.config.colorAccessor):void 0,i=!0),"y0Accessor"in t&&!Vc(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?Hc(this.config.y0Accessor,"y0"):void 0,i=!0,n=!0),("boundsAccessor"in t&&!Vc(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=Ql(this.config),i=!0,n=!0),"pointIdAccessor"in t&&!Vc(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?Kc(this.config.pointIdAccessor):void 0,i=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!Vc(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!Vc(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!Vc(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!Vc(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?Hc(this.config.openAccessor,"open"):void 0,this.getHigh=Hc(this.config.highAccessor,"high"),this.getLow=Hc(this.config.lowAccessor,"low"),this.getClose=e?Hc(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,i=!0,n=!0}if("accessorRevision"in t&&t.accessorRevision!==e.accessorRevision&&(i=!0,n=!0),!i){const o=Object.keys(t).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const n of o)if(t[n]!==e[n]){i=!0;break}}i&&(n&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Iu.GROUP_COLOR_MAP_CAP=1e3;var Tu=Iu;gu(Tu);import*as Ou from"react";import{area as zu,line as Fu}from"d3-shape";function Nu(t,e,o){let i=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(i=o.color):t>o.value&&(i=o.color);return i}var Eu=[40,40],Du=[.5,.5];function Bu(t,e){const[o,i]=t.viewBox??Eu,[n,r]=t.anchor??Du,s=i>0?i:1,a=Math.max(0,e)/s,c=(o>0?o:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-n*c,offsetY:-r*l}}function Wu(t,e,o,i){if("none"!==t)return"color"===t||null==t?e??i:"accent"===t?o:t}function ju(t,e){const o=Bu(t,e);return{centerDx:o.offsetX+o.width/2,centerDy:o.offsetY+o.height/2,halfWidth:o.width/2,halfHeight:o.height/2,radius:Math.hypot(o.width,o.height)/2}}import{jsx as Yu,jsxs as Xu}from"react/jsx-runtime";var qu={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function Gu(t,e="#4e79a7"){return tn(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function Vu(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function Hu(t,e,o,i){const n=t.glyph;if(!n?.parts?.length||0>=t.size)return null;const r=Bu(n,t.size);if(0>=r.scale)return null;const s=`translate(${e},${o})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),c=function(t,e,o=0,i="horizontal"){const[n,r]=t.viewBox??Eu,s=Math.min(1,Math.max(0,o)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===i?{x:0,y:r*(1-a),width:n,height:r*(a-s)}:{x:n*s,y:0,width:n*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}(n,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),l=c?Vu(i+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>n.parts.map((o,i)=>{const n=e?"none"===o.fill?void 0:e:Wu(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:Wu(o.stroke??"none",a,t.accent);return n||r?Yu("path",{d:o.d,fill:n??"none",stroke:r,strokeWidth:r?o.strokeWidth??1:void 0,strokeLinecap:o.strokeLinecap,strokeLinejoin:o.strokeLinejoin,opacity:o.opacity},i):null});return Xu("g",{transform:s,opacity:1===u?void 0:u,children:[c&&l&&Yu("clipPath",{id:l,children:Yu("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&t.ghostColor?Yu("g",{children:d(t.ghostColor)}):null,c&&l?Yu("g",{clipPath:`url(#${l})`,children:d()}):d()]},i)}function Uu(t,e){const o=t.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity))).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color??e,opacity:null==t.opacity?void 0:Math.max(0,Math.min(1,t.opacity))}));return 2>o.length?null:o.map((t,e)=>Yu("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function Ku(t,e,o){const i=Bl(t.symbolType,t.size,t.path);return Yu("path",{d:i,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?Gu(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${o??""}symbol-${e}`)}import*as Zu from"react";import{jsx as Qu}from"react/jsx-runtime";function Ju(t){if(!1!==t?.interactive)return t?.style?.cursor}function td(t,e,o){const i=Ju(e);return i&&null!=t&&!1!==t?Qu("g",{style:{cursor:i},"data-semiotic-mark-cursor":i,children:t},o):t}import*as ed from"react";import{arc as od}from"d3-shape";import{jsx as id,jsxs as nd}from"react/jsx-runtime";import*as rd from"react";import{jsx as sd,jsxs as ad}from"react/jsx-runtime";import*as cd from"react";import{arc as ld}from"d3-shape";var ud=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function dd(t){const{innerRadius:e,outerRadius:o,startAngle:i,endAngle:n}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=ud(o,i),e=ud(o,n);return`M0,0 L${t.x},${t.y} A${o},${o} 0 ${n-i>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=ud(o,i),s=ud(o,n),a=ud(e,n),c=ud(e,i),l=n-i>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${l} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${l} 0 ${c.x},${c.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return dd({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),c=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),l=n-i,u=t.roundStart&&t.roundEnd?l/2:l,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return dd({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=i+(d?a:0),p=n-(h?a:0),y=i+(d?c:0),g=n-(h?c:0),m=ud(o,f),x=ud(o,p),b=(o-s)*Math.cos(a),v=ud(b,i),w=ud(b,n),k=r?null:ud(e,g),S=r?null:ud(e,y),A=r?0:(e+s)*Math.cos(c),M=r?null:ud(A,i),_=r?null:ud(A,n),P=p-f>Math.PI?1:0,L=r?0:g-y>Math.PI?1:0;let $="";if(d)$+=`M${v.x},${v.y}`,$+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=ud(o,i);$+=`M${t.x},${t.y}`}if(h)$+=` A${o},${o} 0 ${P} 1 ${x.x},${x.y}`,$+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=ud(o,n);$+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)$+=" L0,0";else{if(h)$+=` L${_.x},${_.y}`,$+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=ud(e,n);$+=` L${t.x},${t.y}`}if(d)$+=` A${e},${e} 0 ${L} 0 ${S.x},${S.y}`,$+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=ud(e,i);$+=` A${e},${e} 0 ${L} 0 ${t.x},${t.y}`}}return $+=" Z",$}import{jsx as hd,jsxs as fd}from"react/jsx-runtime";function pd(t){return 1e6>t?1e4>t?1e3>t?t+"":(t/1e3).toFixed(1)+"K":(t/1e3).toFixed(0)+"K":(t/1e6).toFixed(1)+"M"}function yd(t,e){const o=t.datum;if(!o)return null;const i=[],n=o.__funnelStepLabel,r=Number(o.__funnelStepLabelX),s=Number(o.__funnelStepLabelY),a=Number(o.__funnelRowWidth);"string"!=typeof n||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*n.length+16>a||i.push(hd("text",{x:r,y:s+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:n},e+"-funnel-step"));const c=Number(o.__funnelValue),l=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(c)&&0!==c&&Number.isFinite(l)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let n=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${pd(c)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:pd(c);7.8*n.length+16>d&&(n=pd(c)),7.8*n.length+16>d||i.push(hd("text",{x:l,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:n},e+"-funnel-value"))}return i.length?hd("g",{children:i},e+"-funnel-labels"):null}function gd(t,e,o){return td(function(t,e,o){const i=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",n=o=>`ord-${t.type}-${i}-${e}-${o}`,r=`ord-${t.type}-${i}-${e}`;switch(t.type){case"rect":{const e=t,o=Vu(r)+"-grad",i=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let i=t.x,n=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(n=t.y+t.h,s=t.y):"right"===t.roundedEdge?(i=t.x+t.w,n=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(i=t.x,n=t.y,r=t.x+t.w,s=t.y);const a=Uu(o.stops,Gu(t.style.fill));return a?Yu("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:i,y1:n,x2:r,y2:s,children:a}):null}(e,o);let n,a;if(i)a=`url(#${o})`;else if(tn(e.style.fill)){const t=Vu(r)+"-hatch";n=en(e.style.fill,t),a=`url(#${t})`}else a=Gu(e.style.fill);const c=i||n?fd("defs",{children:[i,n]}):null;if(e.cornerRadii&&(((s=e.cornerRadii).tl??0)>0||(s.tr??0)>0||(s.br??0)>0||(s.bl??0)>0)){const t=function(t){const{x:e,y:o,w:i,h:n}=t,{tl:r,tr:s,br:a,bl:c}=function(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const o=Math.min(t.w,t.h)/2,i=t=>Math.max(0,Math.min(t??0,o));return{tl:i(e.tl),tr:i(e.tr),br:i(e.br),bl:i(e.bl)}}(t);let l=`M${e+r},${o}`;return l+=` L${e+i-s},${o}`,s>0&&(l+=` A${s},${s} 0 0 1 ${e+i},${o+s}`),l+=` L${e+i},${o+n-a}`,a>0&&(l+=` A${a},${a} 0 0 1 ${e+i-a},${o+n}`),l+=` L${e+c},${o+n}`,c>0&&(l+=` A${c},${c} 0 0 1 ${e},${o+n-c}`),l+=` L${e},${o+r}`,r>0&&(l+=` A${r},${r} 0 0 1 ${e+r},${o}`),l+=" Z",l}(e);return fd(cd.Fragment,{children:[c,hd("path",{d:t,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:o,y:i,w:n,h:s}=e;let l;switch(e.roundedEdge){case"right":l=`M${o},${i} L${o+n-t},${i} A${t},${t} 0 0 1 ${o+n},${i+t} L${o+n},${i+s-t} A${t},${t} 0 0 1 ${o+n-t},${i+s} L${o},${i+s} Z`;break;case"left":l=`M${o+n},${i} L${o+t},${i} A${t},${t} 0 0 0 ${o},${i+t} L${o},${i+s-t} A${t},${t} 0 0 0 ${o+t},${i+s} L${o+n},${i+s} Z`;break;case"bottom":l=`M${o},${i} L${o+n},${i} L${o+n},${i+s-t} A${t},${t} 0 0 1 ${o+n-t},${i+s} L${o+t},${i+s} A${t},${t} 0 0 1 ${o},${i+s-t} Z`;break;default:l=`M${o},${i+s} L${o},${i+t} A${t},${t} 0 0 1 ${o+t},${i} L${o+n-t},${i} A${t},${t} 0 0 1 ${o+n},${i+t} L${o+n},${i+s} Z`}return fd(cd.Fragment,{children:[c,hd("path",{d:l,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return fd(cd.Fragment,{children:[c,hd("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),yd(e,r)]},r)}case"point":{const e=t;return hd("circle",{cx:e.x,cy:e.y,r:e.r,fill:Gu(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return Ku(t,e,o);case"glyph":return Hu(t,t.x,t.y,`${o??""}ord-glyph-${t.pointId??e}`);case"wedge":{const i=t;if(i._gradientBand&&i._gradientBand.colors.length>0){const t=Vu(`${o?o+"-":""}gauge-grad-${i.category||r}-${e}`),{clipPath:n,slices:s}=function(t){const e=dd({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),o=[],i=t.colors;if(i.length>0){const e=(t.endAngle-t.startAngle)/i.length;for(let n=0;i.length>n;n++)o.push({d:dd({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+n*e,endAngle:t.endAngle}),color:i[n]})}return{clipPath:e,slices:o}}({innerRadius:i.innerRadius,outerRadius:i.outerRadius,startAngle:i.startAngle,endAngle:i.endAngle,cornerRadius:i.cornerRadius,roundStart:i.roundedEnds?.start??!0,roundEnd:i.roundedEnds?.end??!0,colors:i._gradientBand.colors});return fd("g",{transform:`translate(${i.cx},${i.cy})`,opacity:i.style.opacity,fillOpacity:i.style.fillOpacity,children:[hd("defs",{children:hd("clipPath",{id:t,children:hd("path",{d:n})})}),hd("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>hd("path",{d:t.d,fill:Gu(t.color)},e))}),i.style.stroke&&"none"!==i.style.stroke&&hd("path",{d:n,fill:"none",stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},r)}let n;if(i.roundedEnds)n=dd({innerRadius:i.innerRadius,outerRadius:i.outerRadius,startAngle:i.startAngle,endAngle:i.endAngle,cornerRadius:i.cornerRadius,roundStart:i.roundedEnds.start,roundEnd:i.roundedEnds.end});else{const t=ld().innerRadius(i.innerRadius).outerRadius(i.outerRadius).startAngle(i.startAngle+Math.PI/2).endAngle(i.endAngle+Math.PI/2);i.cornerRadius&&t.cornerRadius(i.cornerRadius),n=t(qu)||""}return hd("path",{d:n,transform:`translate(${i.cx},${i.cy})`,fill:Gu(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i.style.opacity},r)}case"boxplot":{const e=t,o=e.columnWidth/2,i=e.style.strokeWidth??1;return fd("g","vertical"===e.projection?{children:[hd("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:i}),hd("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:Gu(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:i}),hd("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*i}),hd("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:i}),hd("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:i})]}:{children:[hd("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:i}),hd("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:Gu(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:i}),hd("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*i}),hd("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:i}),hd("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:i})]},r)}case"violin":{const e=t,o=[hd("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:Gu(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth??1},n("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,i=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?o.push(hd("line",{x1:i,y1:e.iqrLine.q1Pos,x2:i,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},n("iqr")),hd("circle",{cx:i,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},n("med"))):o.push(hd("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},n("iqr")),hd("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},n("med")))}return hd("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?Gu(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return hd("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||o,strokeWidth:e.style.strokeWidth??1,opacity:e.style.opacity??.5},r)}case"trapezoid":{const e=t,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return hd("polygon",{points:o,fill:Gu(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}var s}(t,e,o),t,"ordinal-cursor-"+e)}import{jsx as md,jsxs as xd}from"react/jsx-runtime";function bd(t,e,o,i){if(!t||2>e.length)return null;const n=Uu(t.stops,i);return n?md("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:n}):null}function vd(t,e,o,i=30){const n=function(t,e,o,i=30){switch(t.type){case"line":{const i=t;if(0===i.path.length)return null;const n=Wa(i.curve),r=n?Fu().x(([t])=>t).y(([,t])=>t).curve(n)(i.path)??"":"M"+i.path.map(([t,e])=>`${t},${e}`).join("L"),s=Vu(`${o?o+"-":""}line-${e}-stroke-gradient`),a=bd(i.strokeGradient,i.path,s,i.style.stroke||"#4e79a7");return xd(Ou.Fragment,{children:[a&&md("defs",{children:a}),md("path",{d:r,fill:"none",stroke:a?`url(#${s})`:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth??2,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity})]},"line-"+e)}case"area":{const n=t;if(0===n.topPath.length)return null;const r=Wa(n.curve),s=!r||2>n.topPath.length||2>n.bottomPath.length?`M${n.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...n.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:zu().x(([t])=>t).y0((t,e)=>n.bottomPath[e][1]).y1(([,t])=>t).curve(r)(n.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,c=tn(n.style.fill)?en(n.style.fill,a):void 0,l=Vu(`${o?o+"-":""}area-${e}-gradient`),u=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let i=1/0;for(const[,e]of t.topPath)i=Math.min(i,e);let n=-1/0;for(const[,e]of t.bottomPath)n=Math.max(n,e);if(!Number.isFinite(i)||!Number.isFinite(n))return null;const r=Uu(o.stops,Gu(t.style.fill));return r?md("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:i,x2:0,y2:n,children:r}):null}(n,l),d=u?`url(#${l})`:c?`url(#${a})`:Gu(n.style.fill),h=u?void 0:n.style.fillOpacity??n.style.opacity??.7,f=r?Fu().x(([t])=>t).y(([,t])=>t).curve(r)(n.topPath)??"":"M"+n.topPath.map(([t,e])=>`${t},${e}`).join("L"),p=Ju(n),y=p&&i>=0?md("path",{d:f,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*i),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:p},"data-semiotic-mark-cursor":p,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${e}-cursor-target`):null,g=Vu(`${o?o+"-":""}area-${e}-stroke-gradient`),m=!(!n.colorThresholds?.length||!n.rawValues||n.rawValues.length!==n.topPath.length),x=!!n.strokeColorBands?.length,b=m||x?null:bd(n.strokeGradient,n.topPath,g,n.style.stroke||"#4e79a7"),v=n.style.strokeWidth??2;let w=1/0,k=-1/0;for(const[t]of n.topPath)w>t&&(w=t),t>k&&(k=t);const S=x?n.strokeColorBands.map((t,i)=>Vu(`${o?o+"-":""}area-${e}-stroke-band-${i}`)):[],A=x?n.strokeColorBands.map((t,e)=>md("clipPath",{id:S[e],children:md("rect",{x:w-v,y:t.y,width:k-w+2*v,height:t.height})},S[e])):null,M=n.style.stroke&&"none"!==n.style.stroke?x?n.strokeColorBands.map((t,o)=>md("path",{d:f,fill:"none",stroke:t.color??Gu(n.style.stroke),strokeWidth:v,opacity:(n.style.opacity??1)*(t.opacity??1),clipPath:`url(#${S[o]})`},`area-${e}-stroke-band-${o}`)):m?function(t,e,o,i){if(2>t.length||e.length!==t.length||0===o.length)return[];const n=[],r=(t,e,o)=>{const i=n[n.length-1];i?.color===t?i.path.push(o):n.push({color:t,path:[e,o]})};for(let n=1;t.length>n;n++){const[s,a]=t[n-1],[c,l]=t[n],u=e[n-1],d=e[n]-u,h=[0,...0===d?[]:o.map(({value:t})=>(t-u)/d).filter(t=>t>0&&1>t&&Number.isFinite(t)).sort((t,e)=>t-e).filter((t,e,o)=>0===e||t!==o[e-1]),1];for(let t=1;h.length>t;t++){const e=h[t-1],n=h[t];r(Nu(u+d*((e+n)/2),o,i),[s+(c-s)*e,a+(l-a)*e],[s+(c-s)*n,a+(l-a)*n])}}return n}(n.topPath,n.rawValues,n.colorThresholds,Gu(n.style.stroke)).map((t,o)=>md("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:v,opacity:n.style.opacity},`area-${e}-threshold-${o}`)):md("path",{d:f,fill:"none",stroke:b?`url(#${g})`:Gu(n.style.stroke),strokeWidth:v,opacity:n.style.opacity}):null;if(n.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return xd("g",{children:[xd("defs",{children:[u,!u&&c,b,A,md("clipPath",{id:t,children:md("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),xd("g",{clipPath:`url(#${t})`,children:[md("path",{d:s,fill:d,fillOpacity:h,opacity:u?n.style.opacity:void 0,stroke:"none"}),M,y]})]},"area-"+e)}return xd(Ou.Fragment,{children:[(u||c||b||A)&&xd("defs",{children:[u,!u&&c,b,A]}),md("path",{d:s,fill:d,fillOpacity:h,opacity:u?n.style.opacity:void 0,stroke:"none"}),M,y]},"area-"+e)}case"point":{const i=t,n=`${o?o+"-":""}point-${e}-hatch`,r=tn(i.style.fill)?en(i.style.fill,n):void 0;return xd(Ou.Fragment,{children:[r&&md("defs",{children:r}),md("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#${n})`:Gu(i.style.fill),opacity:i.style.opacity??i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"point-"+e)}case"symbol":return Ku(t,e);case"glyph":return Hu(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const i=t,n=`${o?o+"-":""}xyrect-${e}-hatch`,r=tn(i.style.fill)?en(i.style.fill,n):void 0;return xd(Ou.Fragment,{children:[r&&md("defs",{children:r}),md("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:r?`url(#${n})`:Gu(i.style.fill),opacity:i.style.opacity,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const o=t,i={x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth,...null!=o.style?.opacity&&{opacity:o.style.opacity}};if(o.showValues&&null!=o.value&&o.w>=20&&o.h>=20){const t=o.valueFormat?o.valueFormat(o.value):Number.isInteger(o.value)?o.value+"":100>Math.abs(o.value)?1>Math.abs(o.value)?o.value.toPrecision(3):o.value.toFixed(1):o.value.toFixed(0),[n,r,s]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(o.fill),a=.299*n+.587*r+.114*s>128?"#000":"#fff",c=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return xd("g",{children:[md("rect",{...i}),md("text",{x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:c+"px",children:t})]},"heatcell-"+e)}return md("rect",{...i},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return xd("g",{children:[md("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),md("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),md("circle",{cx:o.x,cy:o.lowY,r:t,fill:o.wickColor})]},"candle-"+e)}const i=Math.min(o.openY,o.closeY),n=Math.max(Math.abs(o.openY-o.closeY),1),r=o.isUp?o.upColor:o.downColor;return xd("g",{children:[md("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),md("rect",{x:o.x-o.bodyWidth/2,y:i,width:o.bodyWidth,height:n,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}(t,e,o,i);return"area"===t.type?n:td(n,t,"xy-cursor-"+e)}var wd=new Set;function kd(t){const{node:e,index:o,renderMode:i,fallback:n}=t,r=function(t,e){const o="function"==typeof t?t(e.datum??null,e):t;return(i=o)&&"object"==typeof i&&"string"==typeof i.id&&"function"==typeof i.cacheKey&&"function"==typeof i.drawCanvas&&"function"==typeof i.renderStaticSVG?o:void 0;var i}(i,e);if(!r)return{element:n(),renderedByBackend:!1};const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?{element:td(s,e,`${r.id}-${o}-cursor`),renderedByBackend:!0}:(function(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;wd.has(o)||(wd.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}(r.id,e.type??"unknown"),{element:n(),renderedByBackend:!1})}function Sd(t){const e=[];return t.nodes.forEach((o,i)=>{const n=kd({node:o,index:i,renderMode:t.renderMode,fallback:()=>t.fallback(o,i)});null!=n.element&&!1!==n.element&&e.push({node:o,index:i,...n})}),e}import{scaleOrdinal as Ad}from"d3-scale";import{jsx as Md,jsxs as _d}from"react/jsx-runtime";function Pd(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>Z(t,e)??"#999"}const i=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:w;return Ad().domain(t).range(i)}function Ld(t,e,o){if(0===t.length)return;const i=Pd(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:i(t.label)})}]}}function $d(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Rd(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function Cd(t){return t.typography.legendFontFamily??t.typography.fontFamily}function Id(t){return t.typography.legendFontWeight}function Td(t,e,o,i){const n=Rd(i);return e+o+Math.ceil(t.length*n*.58)}function Od(t){const{categories:e,theme:o,position:i="right",totalWidth:n,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:u}=xe(s),d=a+c,h="top"===i||"bottom"===i,f=Math.max(a,n-r.left-r.right),p=e.map(t=>Td(t,a,c,o));if(h){const t=Math.max(a,s?.maxWidth??f),o=[];let i=0,n=0;p.forEach((e,r)=>{const s=0===n?e:n+l+e;n>0&&s>t?(o.push({start:i,end:r,width:n}),i=r,n=e):n=s}),e.length>0&&o.push({start:i,end:e.length,width:n});const r=$d(s?.align),c=[];return o.forEach((o,i)=>{let n="center"===r?Math.max(0,(t-o.width)/2):"end"===r?Math.max(0,t-o.width):0;for(let t=o.start;o.end>t;t++)c.push({category:e[t],width:p[t],x:n,y:i*u}),n+=p[t]+l}),{items:c,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const y=Math.max(0,...p);return{items:e.map((t,e)=>({category:t,width:p[e],x:0,y:e*u})),width:y,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function zd(t,e){if(!e||!t||0===t.length)return[];const o="function"==typeof e?e:t=>t[e],i=new Set;for(const e of t){const t=o(e);null!=t&&i.add(t+"")}return Array.from(i)}import{jsx as Fd,jsxs as Nd}from"react/jsx-runtime";function Ed(t,e=120,o=8){if(!t)return[];const i=Math.max(1,Math.floor(e/o)),n=t.split(/\s+/),r=[];let s="";for(const t of n)s&&s.length+1+t.length>i?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function Dd(t,e,o,i){return"curly"===t?i?`M0,0 C${.6*o},0 ${.4*o},${e/2} ${o},${e/2} C${.4*o},${e/2} ${.6*o},${e} 0,${e}`:`M0,0 C0,${.6*o} ${e/2},${.4*o} ${e/2},${o} C${e/2},${.4*o} ${e},${.6*o} ${e},0`:i?`M0,0 L${o},0 L${o},${e} L0,${e}`:`M0,0 L0,${o} L${e},${o} L${e},0`}function Bd(t,e,o,i){if(!t)return Fd("g",{className:"annotation-note"});const{label:n,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=t;if(!n&&!r)return Fd("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(o)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>o?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>e?"end":"start";const f=16,p=r?l?[r]:Ed(r,c):[],y=n?l?[n]:Ed(n,c):[],g="leftRight"===u?"end"===h?-4:4:0;let m=0;const x=[],b=i||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?x.push(Fd("foreignObject",{className:"annotation-note-html",x:"end"===h?g-c:"middle"===h?g-c/2:g,y:-16,width:c,height:Math.max(f,(p.length+y.length)*f+(r&&n?2:0))+f,style:{overflow:"visible"},children:Nd("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:[r&&Fd("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),n&&Fd("div",{className:"annotation-note-label",children:n})]})},"annotation-note-html")):(p.length>0&&(x.push(Fd("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>Fd("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),y.length>0&&x.push(Fd("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:y.map((t,e)=>Fd("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||n)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(c,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=Fd("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+y.length)*f+(y.length>0?f:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=Fd("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:i||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+y.length-1)*f;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(y.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),Nd("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[Fd("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function Wd(t,e,o,i,n){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(Fd("circle",{r:t,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,i=e?.height||0;(t>0||i>0)&&r.push(Fd("rect",{width:t,height:i,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":e?.custom&&r.push(...Array.isArray(e.custom)?e.custom:[e.custom]);break;case"xy-threshold":{const t=i||0,s=n||0;if(void 0!==e?.x){const i=(e.x||0)-t;r.push(Fd("line",{x1:i,y1:(e.y1||0)-s,x2:i,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const i=(e.y||0)-s;r.push(Fd("line",{x1:(e.x1||0)-t,y1:i,x2:(e.x2||0)-t,y2:i,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(Fd("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(Fd("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const t=e?.type||"curly",i=e?.width??e?.height;void 0!==i&&r.push(Fd("path",{d:Dd(t,i,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return Fd("g",{className:"annotation-subject",children:r})}function jd(t,e,o,i,n,r){const s=[];let a=0,c=0;if("callout-circle"!==n&&"label"!==n||!r?.radius){if("callout-rect"===n&&r){const o=r.width||0,i=r.height||0;if(o>0||i>0){const n=o/2,r=i/2,s=t-n,l=e-r;if(0!==s||0!==l){const t=Math.abs(s),e=Math.abs(l),u=o/2,d=i/2,h=t*d>e*u?u/t:d/e;a=n+s*h,c=r+l*h}}}else if("bracket"===n&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,c=o):void 0!==e&&(a=o,c=e/2)}}else{const o=(r.radius||0)+(r.radiusPadding||0);if(o>0&&(0!==t||0!==e)){const i=Math.atan2(e,t);a=Math.cos(i)*o,c=Math.sin(i)*o}}const l=Math.sqrt((t-a)**2+(e-c)**2);if(l>.5){const n=i||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-c,t-a);if(r){const i=(a+t)/2,r=(c+e)/2,d=-(e-c)/l,h=(t-a)/l,f=(o?.curve??.25)*l,p=i+d*f,y=r+h*f;s.push(Fd("path",{className:"connector-curve",d:`M${a},${c}Q${p},${y} ${t},${e}`,fill:"none",stroke:n},"connector-line")),u=Math.atan2(y-c,p-a)}else s.push(Fd("line",{x1:a,y1:c,x2:t,y2:e,stroke:n},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(Fd("path",{d:`M${a},${c}L${a+t*Math.cos(u+e)},${c+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${c+t*Math.sin(u-e)}Z`,fill:n,stroke:"none"},"connector-arrow"))}}return Fd("g",{className:"annotation-connector",children:s})}function Yd(t){const{x:e=0,y:o=0,dx:i,dy:n,nx:r,ny:s,note:a,connector:c,subject:l,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:y,events:g={},"data-testid":m}=t,x=Array.isArray(e)?e[0]??0:e,b=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(f)?f:[]);let w=i||0,k=n||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const S="string"==typeof u?u:"label";if("bracket"===S&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const t=l.depth||30;k=t+(0>t?-5:5)}else if(void 0!==l.height){const t=l.depth||30;w=t+(0>t?-5:5),k=l.height/2}return Nd("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.has("connector")&&jd(w,k,c,d,S,l),!v.has("subject")&&Wd(S,l,d,x,b),!v.has("note")&&Bd(a,w,k,d)]})}function Xd(t){const{noteData:e}=t,{screenCoordinates:o}=e,i="string"==typeof e.type?e.type:"label",n=e.eventListeners||e.events||{};if(e.coordinates&&o){const t=e.nx||o[0][0]+(e.dx??0),n=e.ny||o[0][1]+(e.dy??0),r=o.map((o,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:o[0],y:o[1],nx:t,ny:n});return Fd(Yd,{"data-testid":"semiotic-annotation",...s,type:i},"multi-annotation-"+r)});return Fd("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return Fd(Yd,{"data-testid":"semiotic-annotation",events:n,...e,type:i},s)}import{jsx as qd}from"react/jsx-runtime";var Gd={secondary:0,primary:3};function Vd(t){return!0===t?._annotationDeferred}function Hd(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function Ud(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function Kd(t){return Math.max(.72,.95-.06*t)}function Zd(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(o=t.annotation,"primary"===o?.emphasis||"secondary"===o?.emphasis?o.emphasis:null),confidence:Ud(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),i=t.some(t=>Vd(t.annotation)),n=t.some(t=>null!=Hd(t.annotation)),r=t.some(t=>"layer"===Hd(t.annotation));if(!o&&!i&&!n)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=2-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=Gd[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:o,emphasis:i,readingOrder:n}=t,r=Vd(e.annotation);let s=e.node;if("primary"===i||"secondary"===i||null!=n){const t=null==i&&null!=n;s=qd("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+i,..."secondary"===i?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:Kd(n),"data-annotation-reading-order":n}:{},children:e.node},"annotation-emphasis-"+o)}const a=Hd(e.annotation);return a&&(s=qd("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=qd("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return i&&a.unshift(qd("style",{children:".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}}"},"annotation-disclosure-style")),r&&a.unshift(qd("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}function Qd(t,e){const o=e.scales?.x??e.scales?.time;return o?null!=t.x?o(t.x):e.xAccessor&&null!=t[e.xAccessor]?o(t[e.xAccessor]):null:null}function Jd(t,e){const o=e.scales?.y??e.scales?.value;return o?null!=t.y?o(t.y):e.yAccessor&&null!=t[e.yAccessor]?o(t[e.yAccessor]):null:null}function th(t){return null==t?null:t+""}function eh(t,e,o){return e.stickyPositionCache?.set(t,o),o}function oh(t,e,o){const i=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===i){if(null!=t.pointId&&o.pointNodes&&o.pointNodes.length>0)for(let i=o.pointNodes.length-1;i>=0;i--){const n=o.pointNodes[i];if(n.pointId===t.pointId)return eh(e,o,{x:n.x,y:n.y})}const i=function(t){const e=t.data;if(!e||0===e.length)return null;const o=e[e.length-1],i=t.scales?.x??t.scales?.time,n=t.scales?.y??t.scales?.value;if(!i||!n)return null;const r=o[t.xAccessor||"x"],s=o[t.yAccessor||"y"];return null==r||null==s?null:{x:i(r),y:n(s)}}(o);return i?eh(e,o,i):null}if("semantic"===i){const i=function(t,e,o){const i=function(t){return th(t.provenance?.stableId??t.stableId)}(t);if(!i)return null;const n=o.pointNodes?.find(t=>th(t.pointId)===i);if(n)return eh(e,o,{x:n.x,y:n.y});const r=o.data?.find(t=>function(t){return th(t.stableId??t.id??t.provenance?.stableId)}(t)===i);if(!r)return null;const s=Qd(r,o),a=Jd(r,o);return null==s||null==a?null:eh(e,o,{x:s,y:a})}(t,e,o);if(i)return i}let n=null,r=null;if(null!=t.pointId&&o.pointNodes){const e=o.pointNodes.find(e=>e.pointId===t.pointId);e&&(n=e.x,r=e.y)}if(null!=n&&null!=r||(n=Qd(t,o),r=Jd(t,o)),null!=n&&null!=r)return eh(e,o,{x:n,y:r});if("sticky"===i){const t=o.stickyPositionCache?.get(e);if(t)return t}return null}var ih=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function nh(t){return!!t&&"object"==typeof t&&ih.has(function(t){return"string"==typeof t?.type?t.type:""}(t))}function rh(t){return"primary"===t?.emphasis||!0===t?.defensive}function sh(t,e,o={}){return"number"==typeof o.maxAnnotations&&Number.isFinite(o.maxAnnotations)?Math.max(0,Math.floor(o.maxAnnotations)):t>0&&e>0?Math.max(1,Math.round(t*e/(o.areaPerAnnotation&&o.areaPerAnnotation>0?o.areaPerAnnotation:2e4))):1/0}function ah(t){let e;const o=t?.emphasis;e="primary"===o?100:"secondary"===o?10:50;const i=t?.provenance?.confidence;switch("number"==typeof i&&Number.isFinite(i)&&(e+=15*Math.max(0,Math.min(1,i))),t?.lifecycle?.freshness){case"fresh":e+=8;break;case"aging":e+=4;break;case"stale":e+=1;break;case"expired":e-=200}return e}new Set(["label","callout","callout-circle","callout-rect"]);var ch=32,lh=6,uh=4,dh=8,hh=72;var fh={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function ph(t){if(!yh(t))return t;const e=("string"==typeof t.mobileText?t.mobileText:void 0)??("string"==typeof t.shortText?t.shortText:void 0);return!e||"string"!=typeof t.label&&null!=t.label?t:{...t,label:e}}function yh(t){return nh(t)}function gh(t,e){if(!t)return[];const o=Math.max(1,Math.floor(e/7)),i=t.split(/\s+/).filter(Boolean),n=[];let r="";for(const t of i)r&&r.length+t.length+1>o?(n.push(r),r=t):r=r?`${r} ${t}`:t;return r&&n.push(r),n}function mh(t,e,o,i,n){const r=t+o,s=e+i;return Math.abs(o)>Math.abs(i)?{x:0>o?r-n.width-4:r+4,y:0>i?s-n.height:s,width:n.width,height:n.height}:{x:0>o?r-n.width:r,y:0>i?s-n.height-4:s+4,width:n.width,height:n.height}}function xh(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function bh(t,e){return Math.max(0,Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x))*Math.max(0,Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y))}function vh(t,e,o,i,n,r,s,a){const c=xh(t,s);let l=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,o,i){const n=Math.max(0,i-t.x),r=Math.max(0,i-t.y);return(n+Math.max(0,t.x+t.width-(e-i)))*t.height+(r+Math.max(0,t.y+t.height-(o-i)))*t.width}(c,n,r,a);for(const t of o)l+=12*bh(c,t);for(const t of i)l+=4*bh(c,t);return l}function wh(t){const{annotations:e,context:o,defaultOffset:i=ch,notePadding:n=lh,markPadding:r=uh,edgePadding:s=dh,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=hh,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:f,mobile:p,cohesion:y,audience:g}=t,m=o.width||0,x=o.height||0,b="object"==typeof p?p:{},v=b.breakpoint??480,w=!!p&&v>=m,k=w&&!1!==b.preferShortText?e.map(ph):e,S=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,A=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!f?b.responsive??{minWidth:v}:f,_=w&&!y?b.cohesion:y;if(0===k.length||0>=m||0>=x)return k.slice();const P=[],L=function(t,e){return(t.pointNodes||[]).map(t=>{const o=Math.max(1,t.r||1)+e;return{x:t.x-o,y:t.y-o,width:2*o,height:2*o}})}(o,r);let $=!1;const R=k.map((t,e)=>{if(!yh(t))return t;const r=function(t,e,o){if("widget"===t.type&&"number"==typeof t.px&&"number"==typeof t.py)return{x:t.px,y:t.py};const i=t.pointId??t.nodeId;if(null!=i&&o.pointNodes){const t=o.pointNodes.find(t=>t.pointId===i);if(t)return{x:t.x,y:t.y}}const n=t.coordinates,r=o.scales?.geoProjection;if(Array.isArray(n)&&n.length>=2&&r){const t=n[0],e=n[1];if("number"==typeof t&&"number"==typeof e){const o=r([t,e]);if(o&&"number"==typeof o[0]&&"number"==typeof o[1])return{x:o[0],y:o[1]}}}return o.scales||"number"!=typeof t.x||"number"!=typeof t.y?oh(t,e,o):{x:t.x,y:t.y}}(t,e,o);if(!r)return t;const u=function(t){if("widget"===t.type)return{width:"number"==typeof t.width?t.width:32,height:"number"==typeof t.height?t.height:32};const e="number"==typeof t.wrap?t.wrap:120,o=[...gh("string"==typeof t.title?t.title:void 0,e),...gh("string"==typeof t.label?t.label:void 0,e)],i=o.reduce((t,e)=>Math.max(t,e.length),0);return{width:Math.max(24,Math.min(e,7*i)+10),height:Math.max(18,16*o.length+6)}}(t);if(a&&("number"==typeof(d=t).dx||"number"==typeof d.dy)){const e=function(t){return"text"===t.type||"widget"===t.type?{dx:0,dy:0}:{dx:30,dy:-30}}(t);return P.push(xh(mh(r.x,r.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,u),n)),t}var d;let h=null,f=1/0;for(const t of function(t){const e=1.6*t;return[{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t},{dx:t,dy:0},{dx:-t,dy:0},{dx:0,dy:-t},{dx:0,dy:t},{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e}]}(i)){const e=vh(mh(r.x,r.y,t.dx,t.dy,u),t,P,L,m,x,n,s);f>e&&(h=t,f=e)}if(!h)return t;const p=xh(mh(r.x,r.y,h.dx,h.dy,u),n);P.push(p);const y=Math.hypot(h.dx,h.dy),g=c&&y>=l&&"text"!==t.type&&"widget"!==t.type?{...t.connector||{end:"arrow"},type:"curve"}:t.connector;return $=!0,{...t,dx:h.dx,dy:h.dy,...g?{connector:g}:{}}}),C=$?R:k.slice();let I=C;if(h){let t=!1;const e=C.map(e=>{const o=function(t){return"text"!==t.type||"string"!=typeof t.color||8>Math.hypot("number"==typeof t.dx?t.dx:0,"number"==typeof t.dy?t.dy:0)?t:{...t,_redundantConnector:!0}}(e);return o!==e&&(t=!0),o});I=t?e:C}{let t=!1;const e=I.map(e=>{if(!0!==e?.defensive)return e;const o=function(t){const e=t?.provenance;if(!e||"object"!=typeof e)return t;const o="string"==typeof e.source?Object.prototype.hasOwnProperty.call(fh,e.source)?fh[e.source]:e.source:null,i="number"==typeof e.confidence&&Number.isFinite(e.confidence)?Math.round(100*Math.max(0,Math.min(1,e.confidence)))+"%":null;if(!o&&!i)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const n=[o,i].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${n})`)?t:{...t,label:r?`${r} (${n})`:`(${n})`}}(e);return o!==e&&(t=!0),o});I=t?e:I}const T=new Set;if(S){const t="object"==typeof S?S:{},e=function(t){if(!t)return 1;const e=function(t){const e=t?.familiarity;if(!e)return 3;const o=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===o.length?3:o.reduce((t,e)=>t+e,0)/o.length}(t);return e>2?4>e?1:.6:1.5}(g),o=1===e?t:{...t,maxAnnotations:Math.max(0,Math.round((t.maxAnnotations??sh(m,x,t))*e))},{deferred:i}=function(t){const{annotations:e,width:o,height:i}=t,n=Math.max(0,t.minVisible??1),r=sh(o,i,t),s=e.map((t,e)=>{return{annotation:t,index:e,note:(o=t,nh(o))};var o}),a=s.filter(t=>t.note);if(0===a.length||r>=a.length)return{visible:e.slice(),deferred:[],budget:r};const c=a.filter(t=>rh(t.annotation)),l=a.filter(t=>!rh(t.annotation)).sort((t,e)=>ah(e.annotation)-ah(t.annotation)||t.index-e.index),u=Math.min(l.length,Math.max(Math.max(0,r-c.length),Math.max(0,n-c.length))),d=new Set([...c.map(t=>t.index),...l.slice(0,u).map(t=>t.index)]),h=[],f=[];for(const{annotation:t,index:e,note:o}of s)!o||d.has(e)?h.push(t):f.push(t);return{visible:h,deferred:f,budget:r}}({annotations:I,width:m,height:x,...o});for(const t of i)T.add(t)}if(M&&("object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:480)>=m)for(const t of I)yh(t)&&"secondary"===t.emphasis&&T.add(t);if(T.size>0)for(const t of I)!0===t?.defensive&&T.delete(t);let O;return O=0===T.size?I:A?I.map(t=>T.has(t)?{...t,_annotationDeferred:!0}:t):I.filter(t=>!T.has(t)),_?function(t,e){let o=!1;const i=t.map(t=>yh(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(o=!0,{...t,cohesion:e}):t);return o?i:t}(O,_):O}import{jsx as kh,jsxs as Sh}from"react/jsx-runtime";var Ah="var(--semiotic-bg, #ffffff)";function Mh(t){const{x:e,y:o,text:i,fill:n,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:c="start",dominantBaseline:l,background:u,className:d}=t,h=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),f=t=>kh("text",{x:e,y:o,textAnchor:c,dominantBaseline:l,fill:n,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{style:{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}}:{},children:i});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??Ah,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},y="number"==typeof p?p:p.x,g="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(i,r),x=r+2*g;let b,v;return b="middle"===c?e-m/2-y:"end"===c?e-m-y:e-y,v="middle"===l||"central"===l?o-x/2:"hanging"===l||"text-before-edge"===l?o-g:o-.8*r-g,Sh("g",{className:d,children:[kh("rect",{x:b,y:v,width:m+2*y,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??Ah,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}function _h(t,e,o,i){const n=function(t,e,o="#4e79a7"){if(tn(t)){const o=function(t,e){let o=2166136261;const i=function(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}(e);for(let t=0;i.length>t;t++)o^=i.charCodeAt(t),o=Math.imul(o,16777619);return`${t}-hatch-${(o>>>0).toString(36)}`}(e,t);return{fill:`url(#${o})`,def:en(t,o)}}return t&&"string"==typeof t?{fill:t}:{fill:o}}(t.fill??t.color,e,i);return function(t,e,o,i){if(!t||"object"!=typeof t)return;const n=t;if(!Array.isArray(n.stops))return;const r=n.stops.flatMap(t=>{if(!t||"object"!=typeof t)return[];const{offset:e,color:o,opacity:n}=t;return"number"==typeof e&&Number.isFinite(e)?[{offset:Math.max(0,Math.min(1,e)),color:"string"==typeof o&&o?o:i,opacity:"number"==typeof n&&Number.isFinite(n)?Math.max(0,Math.min(1,n)):void 0}]:[]}).sort((t,e)=>t.offset-e.offset);if(!r.length)return;const s="horizontal"===n.direction?"horizontal":"vertical"===n.direction?"vertical":o,a=e+"-gradient";return{fill:`url(#${a})`,def:Qi("linearGradient",{id:a,x1:0,y1:0,x2:"horizontal"===s?"100%":0,y2:"vertical"===s?"100%":0,children:r.map((t,e)=>Qi("stop",{offset:100*t.offset+"%",stopColor:t.color,stopOpacity:t.opacity},`${t.offset}-${e}`))},a)}}(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:i)??n}var Ph=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Lh(t,e,o,i){const n=function(t,e,o){const i=t.position,n="string"==typeof i&&Ph.has(i)?i:"bottom-left",r=n.endsWith("left")?"left":n.endsWith("right")?"right":"center",s=n.startsWith("top")?"top":n.startsWith("bottom")?"bottom":"middle",a="top"===s?0:"bottom"===s?o:o/2;return{x:("left"===r?0:"right"===r?e:e/2)+("number"==typeof t.dx&&Number.isFinite(t.dx)?t.dx:0),y:a+("number"==typeof t.dy&&Number.isFinite(t.dy)?t.dy:0),textAnchor:"start"===t.textAnchor||"middle"===t.textAnchor||"end"===t.textAnchor?t.textAnchor:"left"===r?"start":"right"===r?"end":"middle",dominantBaseline:"auto"===t.dominantBaseline||"middle"===t.dominantBaseline||"hanging"===t.dominantBaseline?t.dominantBaseline:"top"===s?"hanging":"bottom"===s?"auto":"middle"}}(t,e,o);return{...n,fill:t.fill??t.color??i.fill,fontSize:t.fontSize??i.fontSize,fontFamily:t.fontFamily??i.fontFamily,fontWeight:t.fontWeight,fontStyle:t.fontStyle,letterSpacing:t.letterSpacing,opacity:t.opacity,className:t.className,style:{pointerEvents:"none"}}}import{jsx as $h}from"react/jsx-runtime";var Rh={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Ch({annotation:t,width:e,height:o,defaults:i=Rh}){const n=t.label??t.text;return null==n?null:$h("text",{...Lh(t,e,o,i),children:n})}import{packEnclose as Ih}from"d3-hierarchy";import{area as Th,curveBasis as Oh,curveCardinal as zh,curveCatmullRom as Fh,curveLinear as Nh,curveMonotoneX as Eh,curveMonotoneY as Dh,curveStep as Bh,curveStepAfter as Wh,curveStepBefore as jh}from"d3-shape";import*as Yh from"react";function Xh(t,e={}){const o=function(t){const e=t.provenance,o=t.id??t.stableId??e?.stableId;return null==o||""===o?void 0:o+""}(t);return{"data-semiotic-annotation-widget":"",...o?{"data-semiotic-annotation-id":o}:{},onClickCapture(i){const n=function(t){const e=t.nativeEvent;return"touch"===e.pointerType?"touch":0===e.detail?"keyboard":"pointer"}(i);e.onAnnotationActivate?.({annotation:t,annotationId:o,chartId:e.chartId,inputType:n}),o&&e.onObservation&&e.onObservation({type:"annotation-activate",annotationId:o,inputType:n,timestamp:Date.now(),chartType:e.chartType??"unknown",chartId:e.chartId})}}}import{jsx as qh,jsxs as Gh}from"react/jsx-runtime";var Vh={linear:Nh,monotoneX:Eh,monotoneY:Dh,step:Bh,stepAfter:Wh,stepBefore:jh,basis:Oh,cardinal:zh,catmullRom:Fh};import{jsx as Hh,jsxs as Uh}from"react/jsx-runtime";var Kh=16;function Zh(t,e){return t.color||e.colors.annotation||e.colors.text}function Qh(t,e,o){const i=t.labelBackground,n=e.colors.background,r=n&&"transparent"!==n?n:e.colors.surface||n;return void 0===i?"none"===o?"none":{type:"halo",fill:r}:!1===i||"none"===i?"none":!0===i||"halo"===i?{type:"halo",fill:r}:"box"===i?{type:"box",fill:r}:{fill:r,...i}}function Jh(t,e,o){return null!=t.x&&e.x?e.x(t.x):o&&null!=t[o]&&e.x?e.x(t[o]):"number"==typeof t.x?t.x:null}function tf(t,e,o){return null!=t.y&&e.y?e.y(t.y):o&&null!=t[o]&&e.y?e.y(t[o]):"number"==typeof t.y?t.y:null}function ef(t){const{annotations:e}=t;if(!e||0===e.length)return t.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;const o=function(t,e={}){const o=!0===e.showRetractedAnnotations,i=!0===e.showSupersededAnnotations,n=new Set;for(const e of t){const t=e?.lifecycle?.supersedes;t&&"retracted"!==e?.lifecycle?.status&&n.add(t)}return t.filter(t=>{if("retracted"===t?.lifecycle?.status&&!o)return!1;const e=t?.provenance?.stableId;return!(e&&n.has(e)&&!i)})}(e),i=t.scales.geoProjection,n=i?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=i([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,r=!!i&&!t.scales.x&&!t.scales.y,s=t=>Number(t),a=t.scales.x??(r?s:void 0),c=t.scales.y??(r?s:void 0),l=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,u={scales:{..."vertical"===t.projection?{x:t.scales.o??a,y:t.scales.r??c,time:t.scales.o??a,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??a,y:t.scales.o??c,time:t.scales.r??a,value:t.scales.o??c,o:t.scales.o}:{x:a,y:c,time:a,value:c,o:t.scales.o},...i?{geoProjection:i}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,pointNodes:t.pointNodes,frameType:t.frameType??(t.projection?"ordinal":i||t.scales.x||t.scales.y?"xy":"network"),...l?{projection:l}:{}},d=t.autoPlaceAnnotations?wh({annotations:n,context:u,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):n,h=function(t,e,o,i){const n=[];return t.forEach((t,r)=>{let s;if(o){const n=o(t,r,i);s=null!=n?n:e(t,r,i)}else s=e(t,r,i);s&&n.push({node:s,annotation:t})}),{nodes:Zd(n),renderedAnnotations:n.map(t=>t.annotation)}}(d,(e,o,i)=>function(t,e,o,i){const{scales:n,layout:r,theme:s,xAccessor:a,yAccessor:c}=o;switch(t.type){case"frame-text":return Hh(Ch,{annotation:t,width:r.width,height:r.height,defaults:{fill:s.colors.text,fontSize:11,fontFamily:s.typography.fontFamily}},"ann-frame-text-"+e);case"y-threshold":{const i=t.value??t.y;if(null==i)return null;const a=Zh(t,s),c=t.label,l=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===o.projection&&n.r){const o=n.r(i);return null==o?null:Uh("g",{opacity:t.opacity,children:[Hh("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Hh(Mh,{x:o+4,y:Kh,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Qh(t,s,"halo")})]},"ann-ythresh-"+e)}const h=n.y?n.y(i):n.r?n.r(i):null;return null==h?null:Uh("g",{children:[Hh("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Hh(Mh,{x:"left"===l?4:"center"===l?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Kh):h-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Qh(t,s,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const i=t.value??t.x;if(null==i)return null;const a="horizontal"===o.projection&&n.r?n.r(i):n.x?n.x(i):null;if(null==a)return null;const c=Zh(t,s),l=t.label,u=t.labelPosition||"top";return Uh("g",{opacity:t.opacity,children:[Hh("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:c,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),l&&Hh(Mh,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Kh,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:c,fontFamily:s.typography.fontFamily,text:l,background:Qh(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=n.y?.domain?.(),i=t.y0??o?.[0],a=t.y1??o?.[1],c=null!=i&&n.y?n.y(i):null,l=null!=a&&n.y?n.y(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=_h(t,"ssr-band-"+e,"vertical",Zh(t,s)),f=t.fillOpacity??.1;return Uh("g",{opacity:t.opacity,children:[h.def&&Hh("defs",{children:h.def}),Hh("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&Hh(Mh,{x:r.width-4,y:Math.max(u,0)+Kh,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Zh(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Qh(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=n.x?.domain?.(),i=t.x0??o?.[0],a=t.x1??o?.[1],c=null!=i&&n.x?n.x(i):null,l=null!=a&&n.x?n.x(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=_h(t,"ssr-xband-"+e,"horizontal",Zh(t,s)),f=t.fillOpacity??.1;return Uh("g",{opacity:t.opacity,children:[h.def&&Hh("defs",{children:h.def}),Hh("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:f}),t.label&&Hh(Mh,{x:u+4,y:Kh,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Zh(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Qh(t,s,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!n.o)return null;const i=n.o(t.category+"");if(null==i)return null;const a=n.o.bandwidth?n.o.bandwidth():40,c=Zh(t,s),l=t.opacity??.1,u=t.label;return Uh("g","horizontal"===o.projection?{children:[Hh("rect",{x:0,y:i,width:r.width,height:a,fill:c,opacity:l}),u&&Hh(Mh,{x:12,y:i+a/2,dominantBaseline:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Qh(t,s,"none")})]}:{children:[Hh("rect",{x:i,y:0,width:a,height:r.height,fill:c,opacity:l}),u&&Hh(Mh,{x:i+a/2,y:Kh,textAnchor:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Qh(t,s,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const o=function(t,e,o,i){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const o=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Jh(t,e,o),y:tf(t,e,i)}}(t,n,a,c),r=null==o.x||null==o.y?oh(t,e,i):null,l=o.x??r?.x??null,u=o.y??r?.y??null;if(null==l||null==u)return null;const d="text"===t.type,h=t.dx??(d?0:30),f=t.dy??(d?0:-30),p=t.color||s.colors.text;if(!d){const o="callout"===t.type?"callout-circle":t.type,i="callout-circle"===o?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===o?{width:t.width,height:t.height}:void 0;return Hh(Xd,{noteData:{x:l,y:u,dx:h,dy:f,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...i?{subject:i}:{},connector:t.connector||{end:"arrow"},color:p,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return Hh("g",{children:Hh("text",{x:l+h,y:u+f,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||s.typography.labelSize,fill:p,fontFamily:s.typography.fontFamily,fontWeight:t.fontWeight,opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:t.label||t.title})},"ann-label-"+e)}default:return null}}(e,o,t,i)??function(t,e,o){switch(t.type){case"enclose":{const i=(t.coordinates||[]).map(t=>({x:Qd({...t,type:"point"},o),y:Jd({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>i.length)return null;const n=Ih(i),r=t.padding||10;return Gh("g",{children:[qh("circle",{cx:n.x,cy:n.y,r:n.r+r,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&qh(Mh,{x:n.x,y:n.y-n.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"rect-enclose":{const i=(t.coordinates||[]).map(t=>({x:Qd({...t,type:"point"},o),y:Jd({...t,type:"point"},o)})).filter(t=>null!=t.x&&null!=t.y);if(2>i.length)return null;const n=t.padding||10,[r,s]=Pt(i.map(t=>t.x)),[a,c]=Pt(i.map(t=>t.y)),l=r-n,u=s+n,d=a-n;return Gh("g",{children:[qh("rect",{x:l,y:d,width:u-l,height:c+n-d,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&qh(Mh,{x:(l+u)/2,y:d-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"highlight":{const i=o.data||[],n="function"==typeof t.filter?i.filter(t.filter):t.field&&null!=t.value?i.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return qh("g",{children:n.map((e,i)=>{const n=Qd(e,o),s=Jd(e,o);if(null==n||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,c="function"==typeof t.style?t.style(e):t.style||r;return qh("circle",{cx:n,cy:s,r:a,...c},"hl-"+i)})},"ann-"+e)}case"bracket":{const i=Qd(t,o),n=Jd(t,o);return qh(Xd,{noteData:{x:i??0,y:n??0,dx:t.dx||0,dy:t.dy||0,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:"bracket",subject:{type:t.bracketType||"curly",width:t.width,height:t.height,depth:t.depth||30},color:t.color}},"ann-"+e)}case"trend":{const i=o.data||[];if(2>i.length)return null;const n=o.xAccessor||"x",r=o.yAccessor||"y",s="ordinal"===o.frameType,a="horizontal"===o.projection,c=s?n:null,l=s?r:null;let u;const d=[],h=new Map;if(s&&c&&l){for(const t of i){const e=t[c];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=i.map(t=>{const e=t[c],o=t[l];if(null==e||null==o)return null;const i=h.get(e+"");return null!=i?[i,+o]:null}).filter(t=>null!==t)}else u=i.map(t=>[t[n],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const f=o.scales?.x??o.scales?.time,p=o.scales?.y??o.scales?.value;if(!f||!p)return null;const y=t=>e=>{const o=Math.max(0,Math.floor(e)),i=Math.min(d.length-1,o+1),n=e-o,r=t(d[o]);return r+(t(d[i])-r)*n},g=f,m=p;let x;if(s)if(a){const t=y(m);x=(e,o)=>[g(o),t(e)]}else{const t=y(g);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[g(t),m(e)];const b=t.method||"linear",v="loess"===b?function(t,e=.3){const o=t.length;if(2>o)return t.slice();const i=t.slice().sort((t,e)=>t[0]-e[0]),n=i.map(t=>t[0]),r=i.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=n[t],i=n.map(t=>Math.abs(t-e)),c=i.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,l=[];for(let t=0;o>t;t++){const e=0===c?0:i[t]/c;l[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,f=0,p=0;for(let t=0;o>t;t++){const e=l[t];0!==e&&(u+=e,d+=e*n[t],h+=e*r[t],f+=e*n[t]*n[t],p+=e*n[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const y=u*f-d*d;if(1e-12>Math.abs(y))a.push([e,h/u]);else{const t=(u*p-d*h)/y;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3):("polynomial"===b?Rt(u,t.order||2):function(t){const e=[0,0,0,0];let o=0;for(const[i,n]of t)null!==n&&(o++,e[0]+=i,e[1]+=n,e[2]+=i*i,e[3]+=i*n);const i=o*e[2]-e[0]*e[0],n=0===i?0:$t((o*e[3]-e[0]*e[1])/i),r=$t(e[1]/o-n*e[0]/o);return{points:t.map(([t])=>[$t(t),$t(n*t+r)]),equation:[n,r]}}(u)).points,w=v.map(([t,e])=>{const[o,i]=x(t,e);return`${o},${i}`}).join(" "),k=t.color||"#6366f1",S=v[v.length-1],[A,M]=x(S[0],S[1]);return Gh("g",{children:[qh("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&qh("text",{x:A+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+e)}case"envelope":{const i=o.data||[];if(2>i.length)return null;const n=o.xAccessor||"x",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",c=t.lowerAccessor||"lowerBounds",l=t.filter,u=i.filter(t=>null!=t[a]&&null!=t[c]&&(!l||l(t))).sort((t,e)=>t[n]-e[n]);if(2>u.length)return null;const d=Vh[o.curve||"linear"]||Nh,h=Th().x(t=>r(t[n])).y0(t=>s(t[c])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1",p=u[u.length-1];return Gh("g",{children:[qh("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&qh("text",{x:r(p[n])+4,y:s(p[a])-4,fill:f,fontSize:11,children:t.label})]},"ann-"+e)}case"anomaly-band":{const i=o.data||[];if(2>i.length)return null;const n=o.yAccessor||"y",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=i.map(t=>t[n]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const c=a.reduce((t,e)=>t+e,0)/a.length,l=a.reduce((t,e)=>t+(e-c)**2,0)/a.length,u=Math.sqrt(l),d=t.threshold??2,h=c-d*u,f=s(c+d*u),p=s(h),y=t.fill||"#6366f1",g=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=i.filter(t=>{const e=t[n];return null!=e&&Math.abs(e-c)>d*u});return Gh("g",{children:[!1!==t.showBand&&qh("rect",{x:0,y:Math.min(f,p),width:o.width||0,height:Math.abs(p-f),fill:y,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const i=Qd(t,o),n=Jd(t,o);return null==i||null==n?null:qh("circle",{cx:i,cy:n,r:m,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5},"anomaly-"+e)}),t.label&&qh("text",{x:(o.width||0)-4,y:Math.min(f,p)-4,textAnchor:"end",fill:y,fontSize:11,children:t.label})]},"ann-"+e)}case"forecast":{const i=o.data||[];if(3>i.length)return null;const n=o.xAccessor||"x",r=o.yAccessor||"y",s=o.scales?.x??o.scales?.time,a=o.scales?.y??o.scales?.value;if(!s||!a)return null;const c=i.map(t=>[t[n],t[r]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]);if(3>c.length)return null;let l;if("polynomial"===t.method){const e=Rt(c,t.order||2).equation;l=t=>e.reduce((e,o,i)=>e+o*Math.pow(t,i),0)}else{const t=Ct(c);if(!t)return null;l=t}const{se:u,meanX:d,ssX:h}=It(c,l),f=c.length,p=Tt(t.confidence??.95),y=c[f-1][0],g=(y-c[0][0])/Math.max(f-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=y+(e+1)*g,i=l(o),n=u*Math.sqrt(1+1/f+(h>0?(o-d)**2/h:0))*p;return{x:o,center:i,upper:i+n,lower:i-n}}),x=m.map(t=>`${s(t.x)},${a(t.upper)}`).join(" L"),b=m.slice().reverse().map(t=>`${s(t.x)},${a(t.lower)}`).join(" L"),v=m.map(t=>`${s(t.x)},${a(t.center)}`).join(" "),w=t.strokeColor||"#6366f1",k=m[m.length-1];return Gh("g",{children:[qh("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),qh("polyline",{points:`${s(y)},${a(l(y))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&qh("text",{x:s(k.x)+4,y:a(k.center)-4,fill:w,fontSize:11,children:t.label})]},"ann-"+e)}case"widget":{let i,n;if(null!=t.px&&null!=t.py)i=t.px,n=t.py;else{const r=oh(t,e,o);if(!r)return null;i=r.x,n=r.y}if(!function(t,e,o,i=50){return!(-i>t||t>(o.width||0)+i||-i>e||e>(o.height||0)+i)}(i,n,o))return null;const r=t.width??32,s=t.height??32,a=t.content??qh("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return qh("foreignObject",{x:i+(t.dx??0)-r/2,y:n+(t.dy??0)-s/2,width:r,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:qh("div",{...Xh(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,i),t.svgAnnotationRules,u),f=h.nodes,p=new Map;for(const t of h.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";p.set(e,(p.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=p.get(e)??0;o>0?p.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:d.length,renderedCount:h.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?Hh("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}import{jsx as of}from"react/jsx-runtime";function nf(t,e,o,i="right",n,r){if(null==t||!1===t)return null;const{x:s,y:a}=me(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:i,legendLayout:n,axisChrome:r});return of("g",{transform:`translate(${s}, ${a})`,children:t})}import*as rf from"react";function sf(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function af(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function cf(t){if(0===t.length)return{min:null,max:null};let e=1/0,o=-1/0;for(const i of t)e>i.pixel&&(e=i.pixel),i.pixel>o&&(o=i.pixel);return{min:e,max:o}}function lf(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function uf(t,e){return t&&"string"!=typeof t?{stroke:t.stroke??e.stroke,strokeWidth:t.strokeWidth??e.strokeWidth,...null!=t.strokeOpacity&&{strokeOpacity:t.strokeOpacity},...t.strokeDasharray&&{strokeDasharray:t.strokeDasharray}}:{...e,..."string"==typeof t&&{strokeDasharray:lf(t)}}}function df(t,e,o){if("left"===t||"right"===t){const i="left"===t?o:0,n="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+i;for(let t=0;r>t;t++){const o=8*(t+1);s+=`L${Math.min(8*t+4,e)},${i+4*n}`,s+=`L${Math.min(o,e)},${i}`}return s}const i="bottom"===t?0:e,n="bottom"===t?1:-1,r=Math.ceil(o/8);let s=`M${i},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${i+4*n},${Math.min(8*t+4,o)}`,s+=`L${i},${Math.min(e,o)}`}return s}function hf(t,e){return t?.ticks??t?.tickCount??e}function ff(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function pf(t,e,o){return"exact"===o?function(t,e){const o=t.domain(),i=o[0],n=o[o.length-1],r=i instanceof Date,s=i instanceof Date?i.getTime():i,a=n instanceof Date?n.getTime():n;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const c=(a-s)/(e-1),l=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*c;l[t]=r?new Date(o):o}return l}(t,e):t.ticks(e)}import{jsx as yf}from"react/jsx-runtime";function gf(t){return"string"==typeof t||"number"==typeof t}function mf(t){const{label:e,x:o,y:i,textAlign:n,fontSize:r,fontFamily:s,color:a}=t;return yf("foreignObject",{x:o,y:i,width:60,height:24,style:{overflow:"visible"},children:yf("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:n,userSelect:"none"},children:e})})}function xf(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function bf(t){const{values:e,scale:o,format:i}=t,n=e.map(t=>t.valueOf());return e.map((t,e)=>({value:t,pixel:o(t),label:i(t,e,n)}))}function vf(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function wf(t){const{candidates:e,scale:o,minPixelDistance:i,includeMax:n,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:c=!0,format:l}=t;let u=function(t,e){if(2>=t.length)return t;const o=[t[0]];for(let i=1;t.length-1>i;i++)e>Math.abs(t[i].pixel-o[o.length-1].pixel)||o.push(t[i]);const i=t[t.length-1];return e>Math.abs(i.pixel-o[o.length-1].pixel)?o[o.length-1]=i:o.push(i),o}(e,i);if(a&&u.length>1&&(u=u.filter((t,e)=>{return 0===e||(i=u[e-1].label,!!("string"!=typeof(o=t.label)&&"number"!=typeof o||"string"!=typeof i&&"number"!=typeof i||o+""!=i+""));var o,i})),!c||!n||0===u.length||"exact"===r||s)return u;const d=o.domain(),h=d[d.length-1];if(null==h)return u;const f=o(h),p=u[u.length-1].pixel;if(1>=Math.abs(f-p))return u;const y=e.map(t=>t.value.valueOf()),g={value:h,pixel:f,label:l(h,u.length,y)};return i>Math.abs(f-p)&&u.length>1&&(u=u.slice(0,-1)),[...u,g]}function kf(t,e,o,i){return!!t&&("function"==typeof t?t(e.value,o):function(t,e){const o=xf(t);if(!o)return!1;const i=xf(e);return!i||o.getFullYear()!==i.getFullYear()||o.getMonth()!==i.getMonth()}(e.value,o>0?i[o-1].value:void 0))}import{jsx as Sf,jsxs as Af}from"react/jsx-runtime";function Mf(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function _f(t){const e=t._idPrefix||t.chartId;if(e){const t=(e+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(t)?t:"c"+t}const o=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let i=0;for(let t=0;o.length>t;t++)i=31*i+o.charCodeAt(t)|0;return"c"+(i>>>0).toString(36)}function Pf(t,e,o){return Jt(t.showLegend&&!t.__legendIncludesAutomatic?Ld(e,t.colorScheme,o):void 0,t.legend)}var Lf={right:110,left:110,top:50,bottom:80};function $f(t,e){if(t.__autoLegendMargin)return Lf[e]}function Rf(t,e){const o={theme:e.theme,position:e.position||"right",totalWidth:e.size[0],totalHeight:e.size[1],margin:e.margin,hasTitle:e.hasTitle,legendLayout:e.legendLayout,idPrefix:e.idPrefix,reservedWidth:e.reservedWidth,axisChrome:e.axisChrome,legendDistance:te(t)||ee(t)?t.legendDistance:void 0};return te(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,o)=>({group:t,item:e,itemIndex:o,label:e.label})))).length)return null;var e;const o=function(t){const{legendGroups:e,theme:o,position:i="right",totalWidth:n,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,rowHeight:l}=xe(s),u=a+c,d=Math.max(12,Rd(o)),h="top"===i||"bottom"===i,f=Math.max(a,n-r.left-r.right);if(h){const i=Math.max(a,s?.maxWidth??f),n=$d(s?.align);let r=0,c=0;const l=[];for(const n of e){const e=n.items.map(t=>t.label),u=Od({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,i-d-8),align:"start"}}),h=n.label?d:0,f=n.label?Td(n.label,0,0,o):0,p=h>0?h+8:0,y=p+u.width,g=Math.max(u.height,f);l.push({group:n,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:y,height:g,items:u.items}),r+=y+12,c=Math.max(c,g)}const h=l.length>0?r-12:0,p=h>i?0:"center"===n?Math.max(0,(i-h)/2):"end"===n?Math.max(0,i-h):0;return{groups:l.map(t=>({...t,x:t.x+p})),width:h,height:c,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=be(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),l);let y=0;return{groups:e.map((t,e)=>{const i=t.items.map(t=>Td(t.label,a,c,o)),n=Math.max(0,...i,t.label?Td(t.label,0,0,o):0);return y=Math.max(y,n),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:n,height:t.items.length*l,items:t.items.map((t,e)=>({category:t.label,width:i[e],x:0,y:e*l}))}}),width:y,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}(t),i="top"===t.position||"bottom"===t.position,n={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??ae(n,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:c}=me(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:r});if(!i){const e=be(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)),i=t.legendGroups.flatMap((i,n)=>{const s=e[n],a=i.type??"fill",c=[Md("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+n)];return i.label&&null!=s.labelY&&c.push(Md("text",{y:s.labelY,fontSize:Rd(t.theme),fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:i.label},"legend-group-label-"+n)),c.push(Md("g",{transform:`translate(0,${s.itemsY})`,children:i.items.map((e,r)=>{const s=i.styleFn(e,r),c="function"==typeof a?a(e):"line"===a?Md("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):Md("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return _d("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[c,Md("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Rd(t.theme),fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:e.label})]},`legend-${n}-${r}`)})},"legend-group-"+n)),c});return Md("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,"data-orientation":"vertical",fontWeight:Id(t.theme),children:i})}const l=o.groups.flatMap((e,n)=>{const{group:r}=e,a=r.type??"fill",c=[];if(r.label&&c.push(Md("text",i?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Rd(t.theme),fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:r.label}:{x:e.x,y:e.y+Rd(t.theme),fontSize:Rd(t.theme),fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:r.label},"legend-group-label-"+n)),c.push(...e.items.map((i,s)=>{const c=r.items[s],l=r.styleFn(c,s),u="function"==typeof a?a(c):"line"===a?Md("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):Md("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return _d("g",{transform:`translate(${e.x+e.itemOffsetX+i.x},${e.y+e.itemOffsetY+i.y})`,children:[u,Md("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Rd(t.theme),fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:i.category})]},`legend-${n}-${s}`)})),i&&o.groups.length-1>n){const t=e.x+e.width+6;c.push(Md("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+n))}return c});return Md("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,"data-orientation":i?"horizontal":"vertical",fontWeight:Id(t.theme),children:l})}({...o,legendGroups:t.legendGroups}):ee(t)?function(t){const e=function(t){const e="top"===t.position||"bottom"===t.position,o=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??o,200),height:t.gradient.label?46:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?126:108,swatchSize:14}}(t),o="top"===t.position||"bottom"===t.position,i={gradient:t.gradient,legendDistance:t.legendDistance},n=ae(i),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:c}=me(i,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:n}),l=Array.from({length:17},(e,i)=>{const n=i/16;return Md("stop",{offset:100*n+"%",stopColor:t.gradient.colorFn(o?t.gradient.domain[0]+n*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-n*(t.gradient.domain[1]-t.gradient.domain[0]))},i)});if(o){const o=12,i=t.gradient.label?12:void 0,n=t.gradient.label?18:0;return _d("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,fontWeight:Id(t.theme),children:[Md("defs",{children:Md("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),t.gradient.label&&Md("text",{x:e.width/2,y:i,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:t.gradient.label}),Md("rect",{x:0,y:n,width:e.width,height:o,fill:`url(#${r})`,rx:2}),Md("text",{x:0,y:n+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Cd(t.theme),children:s(t.gradient.domain[0])}),Md("text",{x:e.width,y:n+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Cd(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?12:void 0,d=t.gradient.label?18:0;return _d("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,fontWeight:Id(t.theme),children:[Md("defs",{children:Md("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),t.gradient.label&&Md("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:Cd(t.theme),children:t.gradient.label}),Md("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),Md("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Cd(t.theme),children:s(t.gradient.domain[1])}),Md("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Cd(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function Cf(t,e){const{props:o,categories:i,theme:n,size:r,hasTitle:s}=e,a=o.legendPosition||"right",c={...t},l={theme:n,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:$f(o,a)};if(null!=o.legend){const e=Pf(o,i,n);null!=e&&!1!==e&&function(t,e){ge(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...l,legend:e})}else o.showLegend&&i.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";ge(t,{legend:Ld(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...l,categories:i,colorScheme:o.colorScheme});return re(t,c,r,a),a}function If(t){const{props:e,categories:o,theme:i,size:n,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",c={theme:i,position:a,size:n,margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix};if(null!=e.legend){const t=Pf(e,o,i);if(rf.isValidElement(t))return nf(t,n,r,a,e.legendLayout,e.axisChrome);return Rf(t,c)||(te(t)||ee(t)?null:nf(t??null,n,r,a,e.legendLayout,e.axisChrome))}return e.showLegend&&0!==o.length?function(t){const{categories:e,colorScheme:o,theme:i,position:n="right",totalWidth:r,totalHeight:s,margin:a}=t;if(!e||0===e.length)return null;const c=Pd(e,o,i),l="top"===n||"bottom"===n,u=Od(t),d={...Ld(e,o,i),legendDistance:t.legendDistance},h=t.reservedWidth??ae(d,t.legendLayout),{x:f,y:p}=me(d,{totalWidth:r,totalHeight:s,margin:a,position:n,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(l){const t=u.items.map((t,e)=>_d("g",{transform:`translate(${t.x},${t.y})`,children:[Md("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(t.category),rx:u.swatchRadius}),Md("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Rd(i),fill:i.colors.text,fontFamily:Cd(i),children:t.category})]},"legend-"+e));return Md("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:Id(i),children:t})}const y=be([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],g=u.items.map((t,e)=>_d("g",{transform:`translate(${t.x},${t.y+y.itemsY})`,children:[Md("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(t.category),rx:u.swatchRadius}),Md("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Rd(i),fill:i.colors.text,fontFamily:Cd(i),children:t.category})]},"legend-"+e));return _d("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:Id(i),children:[Md("line",{x1:0,y1:y.lineY,x2:h,y2:y.lineY,stroke:"gray"}),g]})}({categories:o,colorScheme:e.colorScheme,theme:i,position:a,totalWidth:n[0],totalHeight:n[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix}):null}var Tf=ff;function Of(t,e){const o=Mt(e.theme),i=e.background??o.background,n=e.idPrefix?e.idPrefix+"-":"",r="string"==typeof e.title?e.title:void 0,s=r?n+"semiotic-title":void 0,a=e.description?n+"semiotic-desc":void 0,c=[s,a].filter(Boolean).join(" ")||void 0;return Af("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":c,style:{fontFamily:o.fontFamily},children:[r&&Sf("title",{id:s,children:r}),e.description&&Sf("desc",{id:a,children:e.description}),e.defs&&Sf("defs",{children:e.defs}),i&&"transparent"!==i&&Sf("rect",{x:0,y:0,width:e.width,height:e.height,fill:i}),Sf("g",{id:n+"data-area",transform:e.innerTransform,children:t}),r&&Sf("text",{id:n+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:o.titleFontSize,fontWeight:o.titleFontWeight,fill:o.text,fontFamily:o.titleFontFamily,children:r}),e.legend&&Sf("g",{id:n+"legend",children:e.legend}),e.outerElements]})}import{jsx as zf,jsxs as Ff}from"react/jsx-runtime";function Nf(t,e,o,i){return"function"==typeof t?t({size:e,margin:o,scales:i}):t}var Ef={top:50,right:40,bottom:60,left:70},Df={top:20,right:80,bottom:20,left:80},Bf={top:40,right:40,bottom:40,left:40},Wf=new Set(["chord","force","circlepack","orbit"]);import{jsx as jf,jsxs as Yf}from"react/jsx-runtime";import{Fragment as Xf,jsx as qf,jsxs as Gf}from"react/jsx-runtime";function Vf(t,e){const o=At(t.theme),i=t.size||[500,300],n=ne({...Ef,...t.margin},t.title),r=oe(t.title),s=function(t,e){if(!e||0===t.length)return t;if(!t.some(t=>null!=t&&"object"==typeof t&&Array.isArray(t[e])))return t;const o=[];for(const i of t){if(null==i||"object"!=typeof i)continue;const t=i[e];if(!Array.isArray(t))continue;const n=i.label??i.id??i.key;for(const e of t)null!=e&&"object"==typeof e&&o.push(null==n?e:{...e,_lineGroup:n})}return o}(g(t.data),t.lineDataAccessor),a=t.showLegend?zd(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],c=function(t){const e=t.axes?.find(t=>"bottom"===t.orient),o=t.axes?.find(t=>"top"===t.orient),i=t.axes?.find(t=>"left"===t.orient),n=t.axes?.find(t=>"right"===t.orient),r=!o||!!e,s=!!o&&!e,a=!n||!!i,c=!!n,l=!1!==t.showAxes;return{hasAxis:l&&r,hasAxisLabel:l&&r&&!!(e?.label??t.xLabel),rotatedTicks:l&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:l,hasAxisLabel:l&&!!(o?.label??t.xLabel),rotatedTicks:l&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:l,hasAxisLabel:l&&!!(i?.label??t.yLabel)}:void 0,rightAxis:c?{hasAxis:l,hasAxisLabel:l&&!!(n?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});Cf(n,{props:{...t,axisChrome:c},categories:a,theme:o,size:i,hasTitle:r});const l=If({props:{...t,axisChrome:c},categories:a,theme:o,size:i,margin:n,hasTitle:r}),u=i[0]-n.left-n.right,d=i[1]-n.top-n.bottom,h="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),f=t.colorScheme||o.colors.categorical,p=(t.axes?.find(t=>"left"===t.orient)??t.axes?.find(t=>"right"===t.orient))?.extent??t.axisExtent,y={chartType:t.chartType,runtimeMode:h?"streaming":"bounded",windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:h?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:t.xAccessor,yAccessor:t.yAccessor,timeAccessor:h?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor||(t.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,yAxisExtent:p,sizeRange:t.sizeRange,xScaleType:t.xScaleType,yScaleType:t.yScaleType,scalePadding:t.scalePadding,binSize:t.binSize,normalize:t.normalize,baseline:t.baseline,stackOrder:t.stackOrder,boundsAccessor:t.boundsAccessor,boundsStyle:t.boundsStyle,band:t.band,y0Accessor:t.y0Accessor,areaGroups:t.areaGroups?t.areaGroups instanceof Set?t.areaGroups:new Set(t.areaGroups):void 0,curve:t.curve,gradientFill:dt(t.gradientFill),lineGradient:ht(t.lineGradient),semanticLineStops:t.semanticLineStops,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:f,themeCategorical:o.colors.categorical,themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging,themeSemantic:kt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat,heatmapColorScale:t.heatmapColorScale,heatmapAggregation:t.heatmapAggregation,heatmapXBins:t.heatmapXBins,heatmapYBins:t.heatmapYBins,pointIdAccessor:t.pointIdAccessor,onLayoutError:t.onLayoutError},m=new Tu(y);t.data&&m.ingest({inserts:s,bounded:!0}),m.computeScene({width:u,height:d});const x=Nf(t.backgroundGraphics,i,n,m.scales),b=Nf(t.foregroundGraphics,i,n,m.scales);if(!m.scales){let r;const a=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=jc({frameType:"xy",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:m.scales?[]:["NO_SCALES"],margin:n})),Xc.renderToStaticMarkup(Of(x||b||t.annotations?Gf(Xf,{children:[x,a,b]}):null,{width:i[0],height:i[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}const v=t._idPrefix,w=Sd({nodes:m.scene,renderMode:t.renderMode,fallback:(e,o)=>vd(e,o,v,t.hoverRadius??30)}),k=t.showGrid?function(t,e,o,i,n,r,s){const{grid:a}=Mt(o),c=i?i+"-":"",l=r?.find(t=>"bottom"===t.orient),u=r?.find(t=>"top"===t.orient),d=r?.find(t=>"left"===t.orient),h=r?.find(t=>"right"===t.orient),f=l??u,p=d??h,y=f?.extent??n,g=p?.extent??n,m="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=f?.tickValues??pf(t.x,hf(f,m),y),v=f?.tickFormat||s?.xFormat||s?.tickFormatTime||ff,w=bf({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,vf(e.label)),0),S=wf({candidates:w,scale:t.x,minPixelDistance:f?.autoRotate?Math.max(20,Math.min(k+8,55)):Math.max(55,k+8),includeMax:f?.includeMax,extentMode:y,hasExplicitTickValues:!!f?.tickValues,format:v}),A=p?.tickValues??pf(t.y,hf(p,x),g),M=p?.tickFormat||s?.yFormat||s?.tickFormatValue||ff,_=t=>M(t),P=wf({candidates:bf({values:A,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:p?.includeMax,extentMode:g,hasExplicitTickValues:!!p?.tickValues,format:_}),L=!1!==f?.grid,$=!1!==p?.grid,R=lf(f?.gridStyle),C=lf(p?.gridStyle),I=uf(f?.gridStyle,{stroke:a,strokeWidth:.5}),T=uf(p?.gridStyle,{stroke:a,strokeWidth:.5});return Ff("g",{id:c+"grid",className:"semiotic-grid",opacity:.8,children:[L&&S.map((t,o)=>zf("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...I,strokeDasharray:R??I.strokeDasharray},"gx-"+o)),$&&P.map((t,o)=>zf("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...T,strokeDasharray:C??T.strokeDasharray},"gy-"+o))]})}(m.scales,{width:u,height:d},o,v,t.axisExtent,t.axes,t):null,S=w.map(t=>t.element),A=_f(t)+"-plot-clip",M=!1!==t.showAxes,_=M?function(t,e,o,i,n,r,s,a=!1){const c=Mt(i),l=o.legendPosition??"right",u=le(o.legendLayout,s?.leftAxis),d=le(o.legendLayout,s?.rightAxis),h=a&&"left"===l&&u>0?u:r?.left??o.margin?.left??40,f=a&&"right"===l&&d>0?d:r?.right??o.margin?.right??40,p=o.axes?.find(t=>"bottom"===t.orient),y=o.axes?.find(t=>"top"===t.orient),g=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=p??y,b=g??m,v=p?"bottom":y?"top":"bottom",w=g?"left":m?"right":"left",k="top"===v?0:e.height,S="right"===w?e.width:0,A="top"===v?-1:1,M="right"===w?1:-1,_=x?.extent??o.axisExtent,P=b?.extent??o.axisExtent,L="exact"===_?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),$="exact"===P?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),R=x?.tickValues??pf(t.x,hf(x,L),_),C=x?.tickFormat||o.xFormat||o.tickFormatTime||Tf,I=bf({values:R,scale:t.x,format:C}),T=I.reduce((t,e)=>Math.max(t,vf(e.label)),0),O=wf({candidates:I,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(T+8,55)):Math.max(55,T+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:C}),z=b?.tickValues??pf(t.y,hf(b,$),P),F=b?.tickFormat||o.yFormat||o.tickFormatValue||Tf,N=t=>F(t),E=wf({candidates:bf({values:z,scale:t.y,format:N}),scale:t.y,minPixelDistance:22,includeMax:b?.includeMax,extentMode:P,hasExplicitTickValues:!!b?.tickValues,format:N}),D=!!(x?.autoRotate&&O.length>1&&e.width/Math.max(O.length-1,1)<O.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),B=cf(O),W=cf(E),j=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),X=uf(x?.axisStyle,{stroke:c.border,strokeWidth:1}),q=uf(b?.axisStyle,{stroke:c.border,strokeWidth:1}),G="right"===w?e.width+f-15:15-h;return Af("g",{id:(n?n+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&Sf("line",{x1:0,y1:k,x2:e.width,y2:k,...X}),x?.jaggedBase&&Sf("path",{d:df(v,e.width,e.height),fill:"none",...X}),O.map((t,e)=>{const o=kf(x?.landmarkTicks,t,e,O);return Af("g",{transform:`translate(${t.pixel},${k})`,children:[Sf("line",{y2:5*A,...X}),gf(t.label)?Sf("text",{y:A*(D?12:18),textAnchor:D?"end":sf(x?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,transform:D?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):mf({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"xtick-"+e)}),j&&Sf("text",{x:e.width/2,y:"top"===v?-(D?58:40):e.height+(D?58:40),textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:j}),!1!==b?.baseline&&!b?.jaggedBase&&Sf("line",{x1:S,y1:0,x2:S,y2:e.height,...q}),b?.jaggedBase&&Sf("path",{d:df(w,e.width,e.height),fill:"none",...q}),E.map((t,e)=>{const o=kf(b?.landmarkTicks,t,e,E);return Af("g",{transform:`translate(${S},${t.pixel})`,children:[Sf("line",{x2:5*M,...q}),gf(t.label)?Sf("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:af(b?.tickAnchor,t.pixel===W.min,t.pixel===W.max),fontWeight:o?600:400,fontSize:o?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):mf({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"ytick-"+e)}),Y&&Sf("text",{x:G,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${G}, ${e.height/2})`,children:Y})]})}(m.scales,{width:u,height:d},t,o,v,n,c,!!l):null,P=M?function(t){const{scales:e,layout:o,props:i,theme:n,leftAxis:r,rightAxis:s,margin:a,axisChrome:c,hasRenderedLegend:l}=t;if(!r||!s)return null;const u=Mt(n),d=s.extent??i.axisExtent,h="exact"===d?Math.max(2,hf(s,5)):Math.min(hf(s,5),Math.max(2,Math.floor(o.height/30))),f=s.tickValues??pf(e.y,h,d),p=s.tickFormat||i.yFormat||i.tickFormatValue||ff,y=t=>p(t),g=wf({candidates:bf({values:f,scale:e.y,format:y}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:y}),m=cf(g),x=s.label??i.yLabelRight,b=uf(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=i.legendPosition??"right",w=le(i.legendLayout,c?.rightAxis),k=o.width+(l&&"right"===v&&w>0?w:a.right)-15;return Yf("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&jf("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&jf("path",{d:df("right",o.width,o.height),fill:"none",...b}),g.map((t,e)=>{const i=kf(s.landmarkTicks,t,e,g);return Yf("g",{transform:`translate(${o.width},${t.pixel})`,children:[jf("line",{x2:5,...b}),gf(t.label)?jf("text",{x:8,textAnchor:"start",dominantBaseline:af(s.tickAnchor,t.pixel===m.min,t.pixel===m.max),fontWeight:i?600:400,fontSize:i?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:t.label}):mf({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&jf("text",{x:k,y:o.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${k}, ${o.height/2})`,children:x})]})}({scales:m.scales,layout:{width:u,height:d},props:t,theme:o,leftAxis:t.axes?.find(t=>"left"===t.orient),rightAxis:t.axes?.find(t=>"right"===t.orient),margin:n,axisChrome:c,hasRenderedLegend:!!l}):null;let L;const $=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:m.scales.x,y:m.scales.y},layout:{width:u,height:d},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:v,onRender:t=>{L=t}}):null;e&&(e.evidence=jc({frameType:"xy",width:i[0],height:i[1],marks:w.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:L,xDomain:Wc(m.scales.x?.domain?.()),yDomain:Wc(m.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:n}));const R=t.svgPreRenderers&&m.scales?t.svgPreRenderers.map((t,e)=>{try{return qf(Yc.Fragment,{children:t(m.scene,m.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Xc.renderToStaticMarkup(Of(Gf(Xf,{children:[x,R,k,qf("defs",{children:qf("clipPath",{id:A,children:qf("rect",{x:0,y:0,width:u,height:d})})}),qf("g",{clipPath:`url(#${A})`,children:S}),_,P,$,b,m.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}import*as Hf from"react";import*as Uf from"react-dom/server";import{scaleBand as Kf,scaleLinear as Zf}from"d3-scale";var Qf=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,o){if(e&&"function"==typeof t.pieceStyle){const i=t.pieceStyle(e,o);return i&&!i.fill&&o?{...i,fill:this.getColorFromScheme(t,o)}:i}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&o?{fill:Z(t.barColors,o)??"#007bff"}:{fill:o?this.getColorFromScheme(t,o):"#007bff"}}resolveSummaryStyle(t,e,o){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,o):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const o=this.colorSchemeMap.get(e);if(o)return o;const i=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||V,n=i[this.colorSchemeIndex%i.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,n),n}};function Jf(t,e,o){const i="function"==typeof t?t(o?e.w:e.h):t;return"number"==typeof i&&Number.isFinite(i)?Math.max(0,i):0}function tp(t){const e=t.getSymbol;return e?jl(e,t.config.symbolMap):null}function ep(t,e,o,i,n,r,s){t.push(e?{type:"symbol",x:i,y:n,size:Math.PI*r*r,symbolType:e(o),style:s,datum:o}:{type:"point",x:i,y:n,r:r,style:s,datum:o})}function op(t,e){const{columns:o,config:i,resolvePieceStyle:n}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===i.chartType?i.innerRadius||60:0,c=-Math.PI/2+(i.startAngle||0)*Math.PI/180,l=null!=i.sweepAngle?i.sweepAngle*Math.PI/180:2*Math.PI,u=null!=i.sweepAngle&&360>i.sweepAngle,d=Object.values(o),h=d.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),f=u&&!h&&d.length>1&&(i.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],o=e.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:e.pctStart,h=c+u*l,p=c+(u+("number"==typeof o?._pct?o._pct:e.pct))*l,y=n(e.pieceData[0],e.name),g=0===t,m=t===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...i.cornerRadius&&{cornerRadius:i.cornerRadius},style:y,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:f&&(x.roundedEnds={start:g,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as ip}from"d3-array";function np(t){const e=t.length,o=t[0],i=t[e-1];return{n:e,min:o,q1:ip(t,.25)??o,median:ip(t,.5)??(o+i)/2,q3:ip(t,.75)??i,max:i,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as rp}from"d3-scale";var sp={bar:function(t,e){const{scales:o,columns:i,config:n,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h="horizontal"===l,f=n.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(i))for(const o of e.pieceData){const e=s(o);t.has(e)||(t.add(e),p.push(e))}}else p.push("_default");for(const t of Object.values(i)){const e=new Map;for(const o of t.pieceData){const t=s?s(o):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const i=e.get(t);i.total+=r(o),i.pieces.push(o)}let o=0;if(f)for(const t of e.values())o+=Math.abs(t.total);let i=0,n=0;for(const r of p){const l=e.get(r);if(!l)continue;let p=l.total;f&&o>0&&(p/=o);const y=a(l.pieces[0],s?r:t.name),g={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:t.name};if(d){const e=c(0>p?n:i+p),o=0>p?c(n+p)-c(n):c(i)-c(i+p);u.push(bl(t.x,e,t.width,Math.abs(o),y,g,r)),0>p?n+=p:i+=p}else if(h){const e=c(0>p?n+p:i),o=0>p?c(n)-c(n+p):c(i+p)-c(i);u.push(bl(e,t.x,Math.abs(o),t.width,y,g,r)),0>p?n+=p:i+=p}}}const y="vertical"===l;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=y?0>e?"bottom":"top":0>e?"left":"right",n.gradientFill&&(t.fillGradient=n.gradientFill)}if(void 0!==n.roundedTop){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const o=e.datum?.category||"";t.has(o)||t.set(o,[]),t.get(o).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),o=e.filter(t=>0>(t.datum?.__aggregateValue??0));if(t.length>0){const e=t.reduce(y?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=Jf(n.roundedTop,e,y);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(y?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=Jf(n.roundedTop,t,y);e>0&&(t.roundedTop=e)}}}return u},clusterbar:function(t,e){const{scales:o,columns:i,config:n,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h=[],f=new Set;for(const t of Object.values(i))for(const e of t.pieceData){const t=s?s(e):"_default";f.has(t)||(f.add(t),h.push(t))}const p=h.length||1;for(const t of Object.values(i)){const e=t.width/p,o=.2*e,i=e-o,n=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";n.has(t)||n.set(t,[]),n.get(t).push(e)}for(let s=0;h.length>s;s++){const l=n.get(h[s])||[];for(const n of l){const l=r(n),f=a(n,h[s]);if(d){const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(bl(r,Math.min(a,d),i,Math.abs(a-d),f,n,h[s]))}else{const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(bl(Math.min(a,d),r,Math.abs(d-a),i,f,n,h[s]))}}}}for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum),o=Jf(n.roundedTop,t,d);o>0&&(t.roundedTop=o),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",n.gradientFill&&(t.fillGradient=n.gradientFill)}return u},point:function(t,e){const{scales:o,columns:i,getR:n,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d="radial"===c,h=r.length>0,f=tp(t),p=2*Math.PI,y=-Math.PI/2;for(const t of Object.values(i))for(const e of t.pieceData){const o=e.__rIndex??0,i=e.__rValue??n(e),c=h&&r[o]||a,g=s(e,t.name),m=g.r||5;let x,b;if(d){const e=y+(t.pctStart+t.pct/2)*p,o=c(i);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=c(i)):(x=c(i),b=t.middle);ep(l,f,e,x,b,m,g)}return l},swarm:function(t,e){const{scales:o,columns:i,getR:n,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="vertical"===a,u=tp(t);for(const t of Object.values(i)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const i=t.pieceData[o],a=n(i),d=r(i,t.name),h=d.r||4,f=(7919*o%100/100-.5)*e*.8;ep(c,u,i,l?t.middle+f:s(a),l?s(a):t.middle+f,h,d)}}return c},pie:op,donut:op,boxplot:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=!1!==n.showOutliers;for(const e of Object.values(i)){const o=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===o.length)continue;const i=o[0],n=o[o.length-1],c=ip(o,.25)??i,h=ip(o,.5)??(i+n)/2,f=ip(o,.75)??n,p=f-c,y=c-1.5*p,g=f+1.5*p,m=o.find(t=>t>=y)??i,x=[...o].reverse().find(t=>g>=t)??n,b=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const o=r(t);if(y>o||o>g){const i=u?e.middle:a(o),n=u?a(o):e.middle;v.push({px:i,py:n,value:o,datum:t})}}if(l.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(c),medianPos:a(h),q3Pos:a(f),maxPos:a(x),stats:{n:o.length,min:m,q1:c,median:h,q3:f,max:x,mean:o.reduce((t,e)=>t+e,0)/o.length},style:b,datum:e.pieceData,category:e.name,outliers:v}),d)for(const e of v)l.push({type:"point",x:e.px,y:e.py,r:3,style:{fill:b.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:b.cursor},datum:e.datum})}return l},violin:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=n.bins||20,h=!1!==n.showIQR;for(const t of Object.values(i)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],i=e[e.length-1],n=(i-o)/d||1,c=Array(d).fill(0);for(const t of e)c[Math.min(Math.floor((t-o)/n),d-1)]++;const f=Lt(c,1),p=t.width/2*.9;let y;if(u){y=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const i=a(o+(e+.5)*n);y+=` L ${t.middle+c[e]/f*p} ${i}`}y+=` L ${t.middle} ${a(i)}`;for(let e=d-1;e>=0;e--){const i=a(o+(e+.5)*n);y+=` L ${t.middle-c[e]/f*p} ${i}`}y+=" Z"}else{y=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)y+=` L ${a(o+(e+.5)*n)} ${t.middle-c[e]/f*p}`;y+=` L ${a(i)} ${t.middle}`;for(let e=d-1;e>=0;e--)y+=` L ${a(o+(e+.5)*n)} ${t.middle+c[e]/f*p}`;y+=" Z"}const g=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const n=ip(e,.25)??o,r=ip(e,.5)??(o+i)/2,s=ip(e,.75)??i;m={q1Pos:a(n),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const x=u?{x:t.x,y:Math.min(a(i),a(o)),width:t.width,height:Math.abs(a(i)-a(o))}:{x:Math.min(a(o),a(i)),y:t.x,width:Math.abs(a(i)-a(o)),height:t.width};l.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:np(e),style:g,datum:t.pieceData,category:t.name})}return l},histogram:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,c=[],l=n.bins||25,u=n.normalize,d=a.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(const t of Object.values(i)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,i]=Pt(e),n=null!=h&&isFinite(h)?h:o,d=null!=f&&isFinite(f)?f:i,p=(d-n)/l||1,y=Array(l).fill(0);for(const t of e)n>t||t>d||y[Math.min(Math.floor((t-n)/p),l-1)]++;const g=e.length,m=Lt(y,1),x=s(t.pieceData[0],t.name);for(let e=0;l>e;e++){if(0===y[e])continue;const o=(u?y[e]/g:y[e]/m)*t.width*.9,i=a(n+e*p),r=a(n+(e+1)*p);c.push(bl(Math.min(i,r),t.x+t.width-o,Math.abs(r-i),o,x,{bin:e,count:y[e],range:[n+e*p,n+(e+1)*p],category:t.name},t.name))}}return c},ridgeline:function(t,e){const{scales:o,columns:i,config:n,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u=n.bins||20,d="horizontal"===c,h=n.amplitude||1.5;for(const t of Object.values(i)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],i=e[e.length-1],n=(i-o)/u||1,c=Array(u).fill(0);for(const t of e)o>t||t>i||c[Math.min(Math.floor((t-o)/n),u-1)]++;const f=Lt(c,1),p=s(t.pieceData[0],t.name),y=t.width*h;let g;if(d){const e=t.x+t.width;g=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)g+=` L ${a(o+(t+.5)*n)} ${e-c[t]/f*y}`;g+=` L ${a(i)} ${e} Z`}else{const e=t.x;g=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const i=a(o+(t+.5)*n);g+=` L ${e+c[t]/f*y} ${i}`}g+=` L ${e} ${a(i)} Z`}const m=d?{x:Math.min(a(o),a(i)),y:t.x,width:Math.abs(a(i)-a(o)),height:t.width}:{x:t.x,y:Math.min(a(i),a(o)),width:t.width,height:Math.abs(a(i)-a(o))};l.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:m,stats:np(e),style:{...p,fillOpacity:p.fillOpacity??.5},datum:t.pieceData,category:t.name})}return l},timeline:function(t,e){const{scales:o,columns:i,getRawRange:n,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="horizontal"===a;for(const t of Object.values(i))for(const e of t.pieceData){const o=n(e);if(!o)continue;const[i,a]=o,u=r(e,t.name);if(l){const o=s(Math.min(i,a)),n=s(Math.max(i,a));c.push(bl(o,t.x,n-o,t.width,u,e,t.name))}else{const o=s(Math.max(i,a)),n=s(Math.min(i,a));c.push(bl(t.x,o,t.width,n-o,u,e,t.name))}}return c},funnel:function(t,e){const{columns:o,getR:i,getStack:n,resolvePieceStyle:r}=t,s=[],a=e.width/2,c=!1!==t.config.showLabels,l=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return s;const u=[],d=new Set;for(const t of l)for(const e of t.pieceData){const t=n?n(e):"_default";d.has(t)||(d.add(t),u.push(t))}const h=u.length>1&&"_default"!==u[0],f=[];let p=0;for(const t of l){const e=new Map;let o=0;for(const r of t.pieceData){const t=n?n(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=i(r);s.total+=a,s.pieces.push(r),o+=a}f.push({col:t,groups:e,stepTotal:o}),h||o>p&&(p=o)}if(h)for(const t of f){let e=0,o=0;for(let i=0;u.length>i;i++){const n=t.groups.get(u[i]);n&&(i%2==0?e+=n.total:o+=n.total)}const i=Math.max(e,o);i>p&&(p=i)}if(0===p)return s;const y=new Map;for(const t of u){const e=f[0].groups.get(t);y.set(t,e?.total??0)}const g=f[0].stepTotal,m=h?.95*a:.9*e.width,x=rp().domain([0,p]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const o=f[e],i=o.col,n=0===e,l=i.width,d=.55*l,p=i.x+(l-d)/2,m=new Map;if(h){let t=0;for(const e of u){const i=o.groups.get(e);i&&(t+=x(i.total))}let e=a,l=a;for(let h=0;u.length>h;h++){const f=u[h],g=o.groups.get(f);if(!g)continue;const b=x(g.total),v=h%2==0,w=v?e:l-b;v?e+=b:l-=b;const k=r(g.pieces[0],f),S=y.get(f)??g.total,A={...g.pieces[0],__funnelValue:g.total,__funnelPercent:S>0?g.total/S*100:0,__funnelStep:i.name,__funnelIsFirstStep:n,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};c&&(0===h&&(A.__funnelStepLabel=i.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=p,A.__funnelRowWidth=t),A.__funnelValueLabelX=w+b/2,A.__funnelValueLabelY=p,A.__funnelBarW=b),s.push(bl(w,p,b,d,k,A,f)),m.set(f,{x:w,y:p,w:b,h:d})}}else{const t=o.stepTotal,e=x(t),l=a-e/2,h=u[0],f="_default"!==h,y=o.groups.get(h)?.pieces[0]??i.pieceData[0],b=f?h:i.name,v=r(y,b),w=g>0?t/g*100:0,k={...y,__funnelValue:t,__funnelPercent:w,__funnelStep:i.name,__funnelIsFirstStep:n,category:f?h:i.name};c&&(k.__funnelStepLabel=i.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(bl(l,p,e,d,v,k,b)),m.set(h,{x:l,y:p,w:e,h:d})}if(e>0&&v.size>0){const e=h?u:[u[0]];for(const n of e){const e=v.get(n),a=m.get(n);if(!e||!a)continue;const c=(()=>{const t=o.groups.get(n);return r(t?t.pieces[0]:i.pieceData[0],"_default"===n?i.name:n)})(),l={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:c.cursor},datum:o.groups.get(n)?.pieces[0]??i.pieceData[0],category:"_default"===n?i.name:n};s.push(l)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:i,getStack:n,resolvePieceStyle:r,scales:s}=t,a=[],c=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return a;const l=[],u=new Set;for(const t of c)for(const e of t.pieceData){const t=n?n(e):"_default";u.has(t)||(u.add(t),l.push(t))}const d=l.length>1&&"_default"!==l[0],h=[];for(const t of c){const e=new Map;let o=0;for(const r of t.pieceData){const t=n?n(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=i(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:t,groups:e,stepTotal:o})}const f=new Map;for(const t of l){const e=h[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,y=d?l.length:1,g=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],o=e.col,i=0===t,n=t>0?h[t-1]:null,s=o.width/y,c=s*g,u=s-c;for(let t=0;l.length>t;t++){const h=l[t],y=e.groups.get(h);if(!y)continue;const g=y.total,m=f.get(h)??g,x=m>0?g/m*100:0,b=n?.groups.get(h),v=i?0:Math.max(0,(b?.total??g)-g),w=o.x+t*s+c/2,k=p(g),S=p(0)-k,A=r(y.pieces[0],d?h:o.name),M={...y.pieces[0],__barFunnelValue:g,__barFunnelPercent:x,__barFunnelIsFirstStep:i,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(g+v)};if(a.push(bl(w,k,u,S,A,M,d?h:o.name)),v>0){const t=p(g+v),e=k-t,i={...A},n={...y.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(bl(w,t,u,e,i,n,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:i,getR:n,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="horizontal"===c,d=t.config.gradientFill,h=u?"left":"bottom",f=new Map,p=e=>{const o=f.get(e);if(void 0!==o)return o;const i="function"==typeof t.config.roundedTop?t.config.roundedTop(e.width):t.config.roundedTop,n="number"==typeof i&&Number.isFinite(i)?Math.max(0,i):0;return f.set(e,n),n},y=t.config.trackFill;if(y){const t="string"==typeof y?y:y.color,e="string"==typeof y?1:y.opacity??1,[o,n]=a.range(),r=Math.min(o,n),s=Math.abs(n-o);for(const o of Object.values(i)){const i={fill:t,opacity:e},n=u?bl(r,o.x,s,o.width,i,null,"__track__"):bl(o.x,r,o.width,s,i,null,"__track__"),a=p(o);a>0&&(n.cornerRadii={tl:a,tr:a,br:a,bl:a}),l.push(n)}}for(const t of Object.values(i)){let e=0;const o=l.length,i=p(t);for(const o of t.pieceData){const i=Math.abs(n(o));if(0===i)continue;const c=r?r(o):t.name,f=s(o,c);let p;if(u){const n=a(e),r=a(e+i);p=bl(n,t.x,r-n,t.width,f,o,c)}else{const n=a(e+i),r=a(e);p=bl(t.x,n,t.width,r-n,f,o,c)}d&&(p.fillGradient=d,p.roundedEdge=h),l.push(p),e+=i}if(i>0&&l.length>o){const t=l.slice(o),e=t[0],n=t[t.length-1];1===t.length?e.cornerRadii={tl:i,tr:i,br:i,bl:i}:u?(e.cornerRadii={tl:i,bl:i},n.cornerRadii={tr:i,br:i}):(e.cornerRadii={bl:i,br:i},n.cornerRadii={tl:i,tr:i})}}return l}},ap=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],cp=["scene-style","data-paint","accessibility","evidence"],lp=(t,e)=>({retainedData:t,invalidations:e}),up=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],dp=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],hp=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],fp=["scene-geometry","data-paint","accessibility","evidence"],pp=["scene-style","data-paint","accessibility","evidence"],yp=[],gp={chartType:lp("rebuild",up),runtimeMode:lp("rebuild",up),categoryAccessor:lp("rebuild",up),valueAccessor:lp("rebuild",up),oAccessor:lp("rebuild",up),rAccessor:lp("rebuild",up),stackBy:lp("rebuild",up),groupBy:lp("rebuild",up),timeAccessor:lp("rebuild",up),accessorRevision:lp("rebuild",up),colorAccessor:lp("rebuild",pp),symbolAccessor:lp("rebuild",fp),connectorAccessor:lp("rebuild",fp),dataIdAccessor:lp("rebuild",fp),projection:lp("preserve",dp),extentPadding:lp("preserve",dp),axisExtent:lp("preserve",dp),rExtent:lp("preserve",dp),oExtent:lp("preserve",dp),multiAxis:lp("preserve",dp),normalize:lp("preserve",dp),bins:lp("preserve",dp),oSort:lp("preserve",hp),barPadding:lp("preserve",hp),roundedTop:lp("preserve",hp),baselinePadding:lp("preserve",hp),innerRadius:lp("preserve",hp),cornerRadius:lp("preserve",hp),startAngle:lp("preserve",hp),sweepAngle:lp("preserve",hp),trackFill:lp("preserve",hp),showOutliers:lp("preserve",hp),showIQR:lp("preserve",hp),amplitude:lp("preserve",hp),connectorOpacity:lp("preserve",hp),showLabels:lp("preserve",hp),dynamicColumnWidth:lp("rebuild",hp),customLayout:lp("preserve",hp),layoutConfig:lp("preserve",hp),layoutMargin:lp("preserve",hp),symbolMap:lp("preserve",fp),pieceStyle:lp("preserve",pp),summaryStyle:lp("preserve",pp),connectorStyle:lp("preserve",pp),gradientFill:lp("preserve",pp),colorScheme:lp("preserve",pp),themeCategorical:lp("preserve",pp),themeSemantic:lp("preserve",pp),themeSequential:lp("preserve",pp),themeDiverging:lp("preserve",pp),barColors:lp("preserve",pp),decay:lp("preserve",pp),pulse:lp("preserve",pp),staleness:lp("preserve",pp),layoutSelection:lp("preserve",pp),windowSize:lp("preserve",yp),windowMode:lp("preserve",yp),clock:lp("preserve",yp),transition:lp("preserve",yp),introAnimation:lp("preserve",yp),onLayoutError:lp("preserve",yp)},mp=lp("preserve",hp),xp=class{constructor(){this.tracker=new Yr}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},ap)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},cp):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const i of t){const t=gp[i]??mp;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as bp}from"d3-quadtree";var vp=class{constructor(t){this.rExtent=new Gc,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new xp,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Qf,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=t,this.buffer=new qc(t.windowSize),this.getO=Kc(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>Hc(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Gc)):(this.getR=Hc(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Kc(t.stackBy),this.getGroup=Kc(t.groupBy),this.getColor=Kc(t.colorAccessor),this.getSymbol=Kc(t.symbolAccessor),this.getConnector=Kc(t.connectorAccessor),this.getDataId=Kc(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new qc(t.windowSize))}syncPulseTimestampBuffer(){var t,e,o,i;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,o=this.timestampBuffer,i=this.currentTime(),t?null!=o&&o.capacity===e.capacity&&o.size===e.size?o:su(e,i):null)}currentTime(){return this.config.clock?.()??sl()}ingest(t){const e=this.currentTime();if(this.lastIngestTime=e,this._dataVersion++,t.bounded){this.buffer.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();t.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),ru(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)au(this.buffer,o,this.timestampBuffer,e),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of t.inserts){const t=au(this.buffer,o,this.timestampBuffer,e);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=t&&this.evictValueExtent(t)}}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}pushValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.push(e[0]),this.rExtent.push(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].push(this.rAccessors[e](t));this.rExtent.push(this.getR(t))}else this.rExtent.push(this.getR(t))}evictValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.evict(e[0]),this.rExtent.evict(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].evict(this.rAccessors[e](t));this.rExtent.evict(this.getR(t))}else this.rExtent.evict(this.getR(t))}getRawRange(t){const e=this.config.valueAccessor||this.config.rAccessor;if(!e)return null;const o="function"==typeof e?e(t):t[e];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(t){const{config:e,buffer:o}=this,i=this.scales,n=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",c=e.oExtent||this.resolveCategories(s),l=this.computeValueDomain(s,c),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let f,p;if(d){f=Kf().domain(c).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,i=e.innerRadius||0;p=Zf().domain(l).range([i,o])}else u?(f=Kf().domain(c).range([0,t.height]).padding(h),p=Zf().domain(l).range([0,t.width])):(f=Kf().domain(c).range([0,t.width]).padding(h),p=Zf().domain(l).range([t.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((i,n)=>{const r=this.rExtents[n];r.dirty&&r.recalculate(o,i);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const c=a-s,l=c>0?c*(e.extentPadding??.05):1;return s-=l,a+=l,s>0&&(s=0),u?Zf().domain([s,a]).range([0,t.width]):Zf().domain([s,a]).range([t.height,0])}):[];let y=s;this.rAccessors.length>1&&(y=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(y,c,f,a,t),this._customLayoutFailedThisBuild=!1;const g=this.buildSceneNodes(y,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=i,this.multiScales=n,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=g,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(e)?e[t]:e;return"string"==typeof o?o:"value"+t}resolveCategories(t){const e=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,i="auto"===e?void 0:e;let n=null;if(o){n=new Set;for(const e of t)n.add(this.getO(e))}const r=n?Array.from(this.categories).filter(t=>n.has(t)):Array.from(this.categories);if(o&&void 0===i){const t=Math.max(50,3*n.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;n.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===i)return r;if("function"==typeof i)return r.sort(i);const s=new Map;for(const e of t){const t=this.getO(e);s.set(t,(s.get(t)||0)+Math.abs(this.getR(e)))}return r.sort("asc"===i?(t,e)=>(s.get(t)||0)-(s.get(e)||0):(t,e)=>(s.get(e)||0)-(s.get(t)||0))}computeValueDomain(t,e){return function(t){const{data:e,chartType:o,projection:i,normalize:n,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===i&&("pie"===o||"donut"===o))return[0,1];let p=0,y=0;if("bar"===o&&d&&n)p=0,y=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const i of e){const e=l(i),n=u(i);0>n?o.set(e,(o.get(e)||0)+n):t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e);for(const t of o.values())p>t&&(p=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=l(o),i=u(o);t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>y&&(y=e),p>e&&(p=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=l(o),i=Math.abs(u(o));t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>y&&(y=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>y&&(y=e),p>e&&(p=e)}else{const t=h[0],e=h[1];t!==1/0&&(p=t),e!==-1/0&&(y=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(y=r[1]));const g="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(g&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>y&&(y=0)),"bar-funnel"!==o&&"exact"!==c){const t=y-p,e=t>0?t*f:1,i=g&&!a&&0===p,n=g&&!a&&0===y||"swimlane"===o;null!=r?.[0]||i||(p-=e),null!=r?.[1]||n||(y+=e)}return[p,y]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,i,n){return function(t){const{data:e,oExtent:o,oScale:i,projection:n,layout:r,dynamicColumnWidth:s,getO:a,getR:c}=t,l=Object.create(null),u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===n)for(const t of e)d+=Math.abs(c(t));let h=null;if(s&&"radial"!==n){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let i;i="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,i),t+=i}const e=("horizontal"===n?r.height:r.width)-i.padding()*i.step()*o.length;if(t>0)for(const[o,i]of h)h.set(o,i/t*e)}let f=0,p=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(c(e)),0),n=d>0?o/d:0;let r,s;h?(r=p,s=h.get(t)||i.bandwidth(),p+=s+i.padding()*i.step()):(r=i(t)??0,s=i.bandwidth()),l[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:i.padding()*i.step(),pieceData:e,pct:n,pctStart:f},f+=n}return l}({data:t,oExtent:e,oScale:o,projection:i,layout:n,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(t,e);let i;try{i=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=Kl("ordinal",t,e,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",t);try{this.config.onLayoutError?.(o)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=i.overlays??null,this.lastCustomLayoutResult=i,this.lastCustomLayoutFailure=null;const n=i.nodes??[];if(this._customRestyle=i.restyle,this.hasCustomRestyle=!!i.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of n)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(n,this.config.layoutSelection??null)}return Vl({label:"ordinal customLayout",nodes:n,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),n}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),i=sp[this.config.chartType];let n=i?i(o,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:o,config:i,getConnector:n,getO:r}=t;if(!n||!o)return[];const s=[],{projection:a}=o,c=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const o=n(e);if(!o)continue;let i,s;"point"===t.type?(i=t.x,s=t.y):(i=t.x+t.w/2,s=t.y+("vertical"===a?0:t.h/2)),c.has(o)||c.set(o,[]),c.get(o).push({x:i,y:s,datum:e,category:r(e)})}const l=o.o.domain(),u=i.connectorStyle;for(const[e,o]of c)if(o.length>=2){o.sort((t,e)=>l.indexOf(t.category)-l.indexOf(e.category));for(let i=0;o.length-1>i;i++){const n=o[i],r=o[i+1],a="function"==typeof u?u(n.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:n.x,y1:n.y,x2:r.x,y2:r.y,style:a,datum:n.datum,group:e})}}return s}(o,n);n=[...t,...n]}return n}buildLayoutContext(t,e){const o=this.config,i=o.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Ss(o.colorScheme,o.themeCategorical,V),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:i,plot:"radial"===r.projection?{x:-e.width/2,y:-e.height/2,width:e.width,height:e.height}:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:o.themeSemantic??{},categorical:[...n]},resolveColor:As(n,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?al(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=cl(t);return this._datumIndexCache={version:this._dataVersion,map:e},e}getCategoryIndexMap(t){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const e=function(t,e){const o="function"==typeof e,i=o?null:e||"category",n=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=o?e(s):s[i],c=n.get(a);c?c.push(r):n.set(a,[r])}return n}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,o=0;for(const i of t)"point"===i.type&&!1!==i.interactive&&(e++,i.r>o&&(o=i.r));if(500>=e)return{quadtree:null,maxRadius:o};const i=Array(e);let n=0;for(const e of t)"point"===e.type&&!1!==e.interactive&&(i[n++]=e);return{maxRadius:o,quadtree:bp().x(t=>t.x).y(t=>t.y).addAll(i)}}(this.scene);this._pointQuadtree=t.quadtree,this._maxPointRadius=t.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(t,e){if(!this.config.decay)return;const o=e.length;if(1>=o)return;const i=this.getDatumIndexMap(e);for(const e of t){if("connector"===e.type||"violin"===e.type||"boxplot"===e.type||"wedge"===e.type)continue;if(!e.datum)continue;const t=i.get(e.datum);if(null==t)continue;const n=this.computeDecayOpacity(t,o);e.style={...e.style,opacity:(e.style?.opacity??1)*n}}}applyPulse(t,e,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,i,n,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;for(const l of e){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const e=l.category;if(!e)continue;let i=0;for(const s of n(e)??[]){const e=o.get(s);null!=e&&(i=Math.max(i,ll(t,e,r)))}c=ul(l,i,s)||c;continue}if(null==l.datum)continue;const e=i.get(l.datum);if(null==e)continue;const u=o.get(e);c=ul(l,null==u?0:ll(t,u,r),s,a)||c}return c}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),o)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&dl(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const t=new Map,e=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let i;for(let n=0;this.scene.length>n;n++){const r=this.scene[n],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,o?{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}:{x:e,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===i&&(i=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:i,endAngle:i,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(t,e){if("point"===t.type){const o=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,i=e.get(o)||0;return e.set(o,i+1),`${o}:${i}`}if("rect"===t.type){const o=t.datum?null!=t.datum.category&&""!==t.datum.category?t.datum.category+"":(this.getO(t.datum)??"")+"":"",i=`r:${t.group||""}:${o}`,n=e.get(i)||0;return e.set(i,n+1),0===n?i:`${i}:${n}`}return"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],i=this.getNodeKey(o,t);i&&("point"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity??o.style.fillOpacity}):"rect"===o.type?this.prevPositionMap.set(i,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity??o.style.fillOpacity}):"wedge"===o.type&&this.prevPositionMap.set(i,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const t=this.config.transition.duration??300;if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}let e=!1;const o=new Set,i=new Map;for(let t=0;this.scene.length>t;t++){const n=this.scene[t],r=this.getNodeKey(n,i);if(!r)continue;n._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===n.type)s?(o.add(r),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(s.x!==n.x||s.y!==n.y||void 0!==s.r&&s.r!==n.r)&&(n._targetX=n.x,n._targetY=n.y,n._targetR=n.r,n.x=s.x,n.y=s.y,void 0!==s.r&&(n.r=s.r),e=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetR=n.r,n.r=0,n.style={...n.style,opacity:0},e=!0);else if("rect"===n.type)s?(o.add(r),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,s.x===n.x&&s.y===n.y&&s.w===n.w&&s.h===n.h||(n._targetX=n.x,n._targetY=n.y,n._targetW=n.w,n._targetH=n.h,n.x=s.x,n.y=s.y,n.w=s.w??n.w,n.h=s.h??n.h,e=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n.style={...n.style,opacity:0},e=!0);else if("wedge"===n.type)if(s)o.add(r),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,s.startAngle===n.startAngle&&s.endAngle===n.endAngle||(n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle,n.startAngle=s.startAngle,n.endAngle=s.endAngle,e=!0);else{n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle;const t=n.startAngle;n.startAngle=t,n.endAngle=t,n.style={...n.style,opacity:0},this.prevPositionMap.set(r,{x:n.cx,y:n.cy,startAngle:t,endAngle:t,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,i]of this.prevPositionMap)if(!o.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:i.x,y:i.y,r:i.r??3,style:{opacity:i.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:i.x,y:i.y,w:i.w??0,h:i.h??0,style:{opacity:i.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((i.startAngle??0)+(i.endAngle??0))/2,o={type:"wedge",cx:i.x,cy:i.y,innerRadius:i.innerRadius??0,outerRadius:i.outerRadius??100,startAngle:i.startAngle??0,endAngle:i.endAngle??0,style:{opacity:i.opacity??1},datum:null,category:t.slice(2),_targetStartAngle:e,_targetEndAngle:e,_targetOpacity:0,_transitionKey:t};this.exitNodes.push(o)}e=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),e&&(this.activeTransition={startTime:this.currentTime(),duration:t})}advanceTransition(t){if(!this.activeTransition)return!1;const e=nl(t,this.activeTransition),o=il(e,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const t of this.scene){const e=t._transitionKey;if(e)if("point"===t.type){if(void 0!==t._targetOpacity){const i=this.prevPositionMap.get(e);t.style.opacity=rl(i?i.opacity??1:0,t._targetOpacity,o)}const i=this.prevPositionMap.get(e);void 0!==t._targetX&&i&&(t.x=rl(i.x,t._targetX,o),t.y=rl(i.y,t._targetY,o)),void 0!==t._targetR&&void 0!==i?.r&&(t.r=rl(i.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const i=this.prevPositionMap.get(e);t.style.opacity=rl(i?i.opacity??1:0,t._targetOpacity,o)}if(void 0===t._targetX)continue;const i=this.prevPositionMap.get(e);if(!i)continue;t.x=rl(i.x,t._targetX,o),t.y=rl(i.y,t._targetY,o),void 0!==i.w&&(t.w=rl(i.w,t._targetW,o),t.h=rl(i.h,t._targetH,o))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const i=this.prevPositionMap.get(e);t.style={...t.style,opacity:rl(i?i.opacity??1:0,t._targetOpacity,o)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const i=this.prevPositionMap.get(e);i&&void 0!==i.startAngle&&(t.startAngle=rl(i.startAngle,t._targetStartAngle,o),t.endAngle=rl(i.endAngle,t._targetEndAngle,o))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}"point"===e.type?void 0!==e._targetX?(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0):void 0!==e._targetR&&(e.r=e._targetR,e._targetR=void 0):"rect"===e.type?void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0):"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=ol(t),o=this.getDataId,i=t=>e.has(o(t));cu(this.buffer,this.timestampBuffer,i);const n=this.buffer.remove(i);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(const t of n)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=ol(t),i=this.getDataId,n=new Set;this.buffer.forEach((t,e)=>{o.has(i(t))&&n.add(e)});const r=this.buffer.update(t=>o.has(i(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach((t,e)=>{this.categories.add(this.getO(t)),n.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const i of t){const t=this._baseStyles.get(i)??i.style??{},n=o(i,e);i.style=n?{...t,...n}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();this._categoryIndexCache=null,this.buffer.forEach(t=>{this.categories.add(this.getO(t)),this.pushValueExtent(t)})}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t&&t.colorScheme!==e.colorScheme||"themeCategorical"in t&&t.themeCategorical!==e.themeCategorical||"colorAccessor"in t&&!Vc(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!Vc(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!Vc(t.oAccessor,e.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in t||"oAccessor"in t)&&(Vc(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=Kc(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let n=!1;if("valueAccessor"in t||"rAccessor"in t){const t=this.config.valueAccessor||this.config.rAccessor,o=e.valueAccessor||e.rAccessor,i=Array.isArray(t)?t:[t],r=Array.isArray(o)?o:[o];if(n=i.length!==r.length||i.some((t,e)=>!Vc(t,r[e])),n){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>Hc(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new Gc)):(this.getR=Hc(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!Vc(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?Kc(this.config.stackBy):void 0),"groupBy"in t&&!Vc(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?Kc(this.config.groupBy):void 0),"colorAccessor"in t&&!Vc(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Kc(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!Vc(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Kc(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!Vc(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Kc(this.config.connectorAccessor):void 0),(i||n||"accessorRevision"in t&&t.accessorRevision!==e.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};gu(vp);import*as wp from"react";import{jsx as kp,jsxs as Sp}from"react/jsx-runtime";function Ap(t){return"connector"===t.node.type}function Mp(t,e,o,i){if(2>t.length)return null;const n=t[0].node,r=n.style.fill;if(!r||"none"===r)return null;const s=Vu(`${e?e+"-":""}connector-${o}-${i}-hatch`),a=tn(r)?en(r,s):null,c=[`${n.x1},${n.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return td(Sp(wp.Fragment,{children:[a&&kp("defs",{children:a}),kp("polygon",{points:c,fill:a?`url(#${s})`:Gu(r,"#999"),opacity:n.style.fillOpacity??n.style.opacity??.3,"data-semiotic-connector-fill":n.group||"_default"})]}),n,`ordinal-connector-fill-${o}-${i}`)}function _p(t,e,o){const i=new Map;for(const e of t){if(!Ap(e))continue;const t=e.node.group||"_default",o=i.get(t);o?o.push(e):i.set(t,[e])}if(0===i.size)return;const n=Array.from(i.values()).map((t,i)=>Sp("g",{children:[Mp(t,e,o,i),t.map(t=>t.element)]},`ordinal-connectors-${o}-${i}`)),r=t[0],s=Ap(r)?null:r.element;for(const t of i.values())for(const e of t)e.element=null;r.element=Sp(wp.Fragment,{children:[n,s]},"ordinal-connector-run-"+o)}function Pp(t){const e=Sd({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>gd(e,o,t.idPrefix)});let o=0;for(let i=0;e.length>i;){if(e[i].renderedByBackend){i++;continue}let n=i+1;for(;e.length>n&&!e[n].renderedByBackend;)n++;_p(e.slice(i,n),t.idPrefix,o++),i=n}return e}import{jsx as Lp,jsxs as $p}from"react/jsx-runtime";import{Fragment as Rp,jsx as Cp,jsxs as Ip}from"react/jsx-runtime";var Tp=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function Op(t,e){const o=At(t.theme),i=t.size||[500,400],n=ne({...Ef,...t.margin},t.title),r=oe(t.title),s=g(t.data),a=t.showLegend?zd(s,t.colorAccessor||t.stackBy||t.groupBy):[],c=function(t){const e=t.projection??"vertical",o=!1!==t.showAxes&&"radial"!==e;return{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasValueLabel:t.hasCategoryLabel),leftAxis:{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasCategoryLabel:t.hasValueLabel)}}}({showAxes:t.showAxes,projection:t.projection,hasCategoryLabel:!(!t.categoryLabel&&!t.oLabel),hasValueLabel:!(!t.valueLabel&&!t.rLabel)});Cf(n,{props:{...t,axisChrome:c},categories:a,theme:o,size:i,hasTitle:r});const l=If({props:{...t,axisChrome:c},categories:a,theme:o,size:i,margin:n,hasTitle:r}),u=i[0]-n.left-n.right,d=i[1]-n.top-n.bottom,h=t.projection||"vertical",f="radial"===h,p=t.colorScheme||o.colors.categorical,y={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:dt(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:p,themeCategorical:o.colors.categorical,themeSemantic:kt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors},m=new vp(y);t.data&&m.ingest({inserts:s,bounded:!0}),m.computeScene({width:u,height:d});const x=Nf(t.backgroundGraphics,i,n,m.scales),b=Nf(t.foregroundGraphics,i,n,m.scales);if(!m.scales){let r;const a=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,projection:h,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=jc({frameType:"ordinal",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:m.scales?[]:["NO_SCALES"],margin:n})),Uf.renderToStaticMarkup(Of(x||b||t.annotations?Ip(Rp,{children:[x,a,b,m.customLayoutOverlays]}):null,{width:i[0],height:i[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}const v=t._idPrefix,w=t.showGrid?function(t,e,o,i,n){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=Mt(o),a=i?i+"-":"",c="vertical"===r.projection,l=pf(r.r,5,n);return Sf("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const i=r.r(t);return Sf("line",{x1:0,y1:i,x2:e.width,y2:i,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const i=r.r(t);return Sf("line",{x1:i,y1:0,x2:i,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(m,{width:u,height:d},o,v,t.axisExtent):null;let k=null;if(m.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=_f(t),i=new Set;for(const t of m.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&i.add("string"==typeof t.style.fill?t.style.fill:"#666");k=Array.from(i).map((t,i)=>function(t){const{id:e,background:o="transparent",stroke:i="#000",lineWidth:n=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return $p("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Lp("rect",{width:a,height:a,fill:o}),Lp("line",{x1:0,y1:0,x2:0,y2:a,stroke:i,strokeWidth:n}),Lp("line",{x1:r,y1:0,x2:r,y2:a,stroke:i,strokeWidth:n})]},e)}({id:`funnel-hatch-${e}-${i}`,background:t,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const n=new Map;Array.from(i).forEach((t,o)=>n.set(t,`funnel-hatch-${e}-${o}`));for(const t of m.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${n.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const S=Pp({nodes:m.scene,renderMode:t.renderMode,idPrefix:v}),A=S.map(t=>t.element),M=!1!==t.showAxes?function(t,e,o,i,n,r,s,a=!1){const c=t.scales;if(!c)return null;if("radial"===c.projection)return null;const l=Mt(i),u="vertical"===c.projection,d=t.columns,h=o.categoryFormat||o.oFormat,f=o.valueFormat||o.rFormat,p=o.categoryLabel||o.oLabel,y=o.valueLabel||o.rLabel,g=o.legendPosition??"right",m=le(o.legendLayout,s?.leftAxis),x=a&&"left"===g&&m>0?m:r?.left??o.margin?.left??40,b=Object.values(d).map((t,e)=>({pixel:t.middle,label:h?h(t.name,e):t.name})),v=pf(c.r,5,o.axisExtent).map(t=>({pixel:c.r(t),label:(f||Tf)(t)}));return Ip("g",u?{id:(n?n+"-":"")+"axes",className:"ordinal-axes",children:[Cp("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:l.border,strokeWidth:1}),b.map((t,o)=>Ip("g",{transform:`translate(${t.pixel},${e.height})`,children:[Cp("line",{y2:5,stroke:l.border,strokeWidth:1}),gf(t.label)?Cp("text",{y:18,textAnchor:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):mf({label:t.label,x:-30,y:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"oxtick-"+o)),p&&Cp("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:p}),Cp("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:l.border,strokeWidth:1}),v.map((t,e)=>Ip("g",{transform:`translate(0,${t.pixel})`,children:[Cp("line",{x2:-5,stroke:l.border,strokeWidth:1}),Cp("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label})]},"oytick-"+e)),y&&Cp("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:y})]}:{id:(n?n+"-":"")+"axes",className:"ordinal-axes",children:[Cp("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:l.border,strokeWidth:1}),v.map((t,o)=>Ip("g",{transform:`translate(${t.pixel},${e.height})`,children:[Cp("line",{y2:5,stroke:l.border,strokeWidth:1}),Cp("text",{y:18,textAnchor:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label})]},"oxtick-"+o)),y&&Cp("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:y}),Cp("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:l.border,strokeWidth:1}),b.map((t,e)=>Ip("g",{transform:`translate(0,${t.pixel})`,children:[Cp("line",{x2:-5,stroke:l.border,strokeWidth:1}),gf(t.label)?Cp("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):mf({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"oytick-"+e)),p&&Cp("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:p})]})}(m,{width:u,height:d},t,o,v,n,c,!!l):null;let _;const P=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:m.scales.o,r:m.scales.r,y:"vertical"===m.scales.projection?m.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,xAccessor:"string"==typeof t.oAccessor?t.oAccessor:void 0,yAccessor:"string"==typeof t.rAccessor?t.rAccessor:void 0,idPrefix:v,onRender:t=>{_=t}}):null;if(e){const o=m.scales.o?.domain?.();e.evidence=jc({frameType:"ordinal",width:i[0],height:i[1],marks:S.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:_,yDomain:Wc(m.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:n})}const L=f&&t.centerContent?function(t,e,o){if(!Hf.isValidElement(t))return null;if("string"!=typeof t.type||!Tp.has(t.type))return null;const i=t,n="text"===i.type?Hf.cloneElement(i,{x:i.props.x??0,y:i.props.y??0,textAnchor:i.props.textAnchor??"middle",dominantBaseline:i.props.dominantBaseline??"middle"}):i;return Cp("g",{className:"semiotic-radial-center-content",transform:`translate(${e},${o})`,pointerEvents:"none",children:n})}(t.centerContent,n.left+u/2,n.top+d/2):null,$=f&&t.centerContent?L??Cp("foreignObject",{x:n.left,y:n.top,width:u,height:d,pointerEvents:"none",children:Cp("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,R=Ip(Rp,{children:[w,A,M,P,b,m.customLayoutOverlays]});return Uf.renderToStaticMarkup(Of(Ip(Rp,f?{children:[x?Cp("g",{transform:`translate(${-u/2},${-d/2})`,children:x}):null,R]}:{children:[x,R]}),{width:i[0],height:i[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:f?`translate(${n.left+u/2},${n.top+d/2})`:`translate(${n.left},${n.top})`,innerWidth:u,innerHeight:d,legend:l,defs:k,outerElements:$,idPrefix:t._idPrefix}))}import*as zp from"react-dom/server";function Fp(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function Np(t,e){var o,i=[],n=[],r=[],s={},a=[];function c(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&c(e)})}function l(t){var e,i,d=!1;for(n.push(t),r[t]=!0,e=0;a[t].length>e;e++)(i=a[t][e])===o?(u(o,n),d=!0):r[i]||(d=l(i));if(d)c(t);else for(e=0;a[t].length>e;e++){var h=s[i=a[t][e]];h||(s[i]=h={}),h[i]=!0}return n.pop(),d}function u(t,o){var n=[].concat(o).concat(t);e?e(n):i.push(n)}function d(e){!function(e){for(var o=0;t.length>o;o++)o>=e&&t[o]||(t[o]=[]),t[o]=t[o].filter(function(t){return t>=e})}(e);for(var o,i=function(t){for(var e=t.length,o=Array(e),i=Array(e),n=Array(e),r=Array(e),s=Array(e),a=Array(e),c=0;e>c;++c)o[c]=-1,i[c]=0,n[c]=!1,r[c]=0,s[c]=-1,a[c]=[];var l,u=0,d=[],h=[];function f(e){var c=[e],l=[e];for(o[e]=i[e]=u,n[e]=!0,u+=1;l.length>0;){var f=t[e=l[l.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var y=f[p];if(0>o[y]){o[y]=i[y]=u,n[y]=!0,u+=1,c.push(y),l.push(y);break}n[y]&&(i[e]=0|Math.min(i[e],i[y])),0>s[y]||a[e].push(s[y])}r[e]=p}else{if(i[e]===o[e]){var g=[],m=[],x=0;for(p=c.length-1;p>=0;--p){var b=c[p];if(n[b]=!1,g.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){c.length=p;break}}d.push(g);var v=Array(x);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--x]=m[p][w];h.push(v)}l.pop()}}}for(c=0;e>c;++c)0>o[c]&&f(c);for(c=0;h.length>c;c++){var p=h[c];if(0!==p.length){p.sort(function(t,e){return t-e}),l=[p[0]];for(var y=1;p.length>y;y++)p[y]!==p[y-1]&&l.push(p[y]);h[c]=l}}return{components:d,adjacencyList:h}}(t),n=i.components.filter(function(t){return t.length>1}),r=1/0,s=0;n.length>s;s++)for(var a=0;n[s].length>a;a++)r>n[s][a]&&(r=n[s][a],o=s);var c=n[o];return!!c&&{leastVertex:r,adjList:t.map(function(t,e){return-1===c.indexOf(e)?[]:t.filter(function(t){return-1!==c.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var f=d(o);if(o=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var y=0;a[p].length>y;y++){var g=a[p][y];r[+g]=!1,s[g]={}}l(o),o+=1}else o=h}return e?void 0:i}function Ep(t){return t.y0-t.y1>0?"up":"down"}function Dp(t,e){return e(t.source)==e(t.target)}function Bp(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var o=0;return t.target.targetLinks.forEach(function(t){o=t.circular?o+1:o}),1>=e&&1>=o}function Wp(t){return t.target.x0-t.source.x1}function jp(t,e){var o=Xp(t),i=Wp(e)/Math.tan(o);return"up"==Ep(t)?t.y1-i:t.y1+i}function Yp(t,e){var o=Xp(t),i=Wp(e)/Math.tan(o);return"up"==Ep(t)?t.y1+i:t.y1-i}function Xp(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function qp(t,e){return e(t)}function Gp(t){return Hp(t.source)}function Vp(t){return Hp(t.target)}function Hp(t){return(t.y0+t.y1)/2}function Up(t){return t.virtual?0:t.value}function Kp(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!Dp(t,e)?o+1:o});var i=0;return t.targetLinks.forEach(function(t){i=t.circular&&!Dp(t,e)?i+1:i}),o+i}function Zp(t){return t.target.depth}function Qp(t,e){return t.sourceLinks.length?t.depth:e-1}function Jp(t,e){return t.y0-e.y0}function ty(t,e){return e.y0-t.y0}function ey(t,e){return t.y1-e.y1}function oy(t,e){return e.y1-t.y1}function iy(t,e){return ry(t.source,e.source)||t.index-e.index}function ny(t,e){return ry(t.target,e.target)||t.index-e.index}function ry(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function sy(t,e){return ay(t)==ay(e)?"bottom"==t.circularLinkType?ty(t,e):Jp(t,e):ay(e)-ay(t)}function ay(t){return t.target.column-t.source.column}function cy(t,e){return ly(t)==ly(e)}function ly(t){return t.y0-t.y1>0?"up":"down"}import{min as uy}from"d3-array";function dy(t,e,o,i,n){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=uy(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var c=r.links.filter(function(t){return t.circular});return c.sort(function(t,e){return e.value-t.value}),c.forEach(function(t,e){t._circularStub=e>=4}),hy(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),hy(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,o),r.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+i,t.circularPathData.rightNodeBuffer=5,t.circularPathData.leftNodeBuffer=5,t.circularPathData.sourceWidth=t.source.x1-t.source.x0,t.circularPathData.sourceX=t.source.x0+t.circularPathData.sourceWidth,t.circularPathData.targetX=t.target.x0,t.circularPathData.sourceY=t.y0,t.circularPathData.targetY=t.y1,Dp(t,e)&&Bp(t))t.circularPathData.rightSmallArcRadius=i+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=i+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=i+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=i+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+n+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-n-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,c=t.circularLinkType,l=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==c});l.sort("bottom"==t.circularLinkType?ty:Jp);var u=0;l.forEach(function(e,n){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=i+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=i+t._circularWidth/2+n*o+u),u+=e._circularWidth||e.width}),s=t.target.column,(l=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==c})).sort("bottom"==t.circularLinkType?oy:ey),u=0,l.forEach(function(e,n){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=i+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=i+t._circularWidth/2+n*o+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+n+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-n-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,o=t.y0,i=t.target.x0,n=t.y1,r=(e+i)/2;return"M"+e+","+o+"C"+r+","+o+" "+r+","+n+" "+i+","+n}(t)}),r}function hy(t,e,o){t.sort(sy);var i=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,n){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(Dp(t,e)&&Bp(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;i.length>s;s++){var a=i[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&fy(t,a)){var c=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=c>r?c:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function fy(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as py,max as yy,sum as gy,mean as my,group as xy,groups as by}from"d3-array";function vy(t){return function(){return t}}function wy(t){return t.index}function ky(t){return t.nodes}function Sy(t){return t.links}function Ay(t,e,o){var i=by(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});i.forEach(function(n,r){var s=n.length;if(e)n.sort(e);else if(r>0){var a=new Map;n.forEach(function(t,e){var o,i,n,r=(i=0,n=0,(o=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;n+=Hp(t.source)*e,i+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;n+=Hp(t.target)*e,i+=e}}),i>0?n/i:NaN);a.set(t,{bc:r,idx:e})}),n.sort(function(t,e){var o=a.get(t),i=a.get(e),n=o.bc,r=i.bc;if(t.circularLinkType!==e.circularLinkType){if("top"==t.circularLinkType&&"bottom"==e.circularLinkType)return-1;if("bottom"==t.circularLinkType&&"top"==e.circularLinkType)return 1;if("top"==t.circularLinkType)return-1;if("top"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return-1}return isNaN(n)||isNaN(r)?isNaN(n)?isNaN(r)?o.idx-i.idx:1:-1:n-r})}else n.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Kp(e,o)-Kp(t,o):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});n.forEach(function(e,n){e.depth==i.length-1&&1==s||0==e.depth&&1==s?(e.y0=t.y1/2-e.value*t.ky,e.y1=e.y0+e.value*t.ky):e.partOfCycle?0==Kp(e,o)?(e.y0=t.y1/2+n,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+n,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-n,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*n,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+n,e.y1=e.y0+e.value*t.ky)})})}function My(t,e,o,i,n,r){var s=by(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,c=r;c>0;--c)l(a*=.99,o),u();function l(e,o){var i=s.length;s.forEach(function(n){var r=n.length,s=n[0].depth;n.forEach(function(n){var a;if(n.sourceLinks.length||n.targetLinks.length)if(n.partOfCycle&&Kp(n,o)>0){var c=my(n.sourceLinks,Vp),l=my(n.targetLinks,Gp),u=c&&l?(c+l)/2:c||l;if(u){var d=(u-Hp(n))*e*.3;n.y0+=d,n.y1+=d}}else if(0==s&&1==r)n.y0=t.y1/2-(a=n.y1-n.y0)/2,n.y1=t.y1/2+a/2;else if(s==i-1&&1==r)n.y0=t.y1/2-(a=n.y1-n.y0)/2,n.y1=t.y1/2+a/2;else if(1==n.targetLinks.length&&1==n.targetLinks[0].source.sourceLinks.length)a=n.y1-n.y0,n.y0=n.targetLinks[0].source.y0,n.y1=n.y0+a;else{var h=my(n.sourceLinks,Vp),f=my(n.targetLinks,Gp),p=((h&&f?(h+f)/2:h||f)-Hp(n))*e;n.y0+=p,n.y1+=p}})})}function u(){s.forEach(function(o){var r,s,a,c=t.y0,l=o.length;for(o.sort(e||ry),a=0;l>a;++a)(s=c-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),c=r.y1+i;if((s=c-i-t.y1)>0)for(c=r.y0-=s,r.y1-=s,a=l-2;a>=0;--a)(s=(r=o[a]).y1+n-c)>0&&(r.y0-=s,r.y1-=s),c=r.y0})}}function _y(t){t.nodes.forEach(function(t){t.sourceLinks.sort(ny),t.targetLinks.sort(iy)}),t.nodes.forEach(function(t){var e=t.y0,o=e,i=t.y1,n=i;t.sourceLinks.forEach(function(t){t.circular?(t.y0=i-t.width/2,i-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=n-t.width/2,n-=t.width):(t.y1=o+t.width/2,o+=t.width)})})}function Py(){var t=0,e=0,o=1,i=1,n=24,r=8,s=null,a=wy,c=Qp,l=void 0,u=32,d=2,h=ky,f=Sy;function p(){var p={nodes:h.apply(null,arguments),links:f.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=o,h.y1=i,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var o=function(t,e){var o=new Map;return xy(t,e).forEach(function(t,e){o.set(e,t[0])}),o}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var i=t.source,n=t.target;"object"!=typeof i&&(i=t.source=Fp(o,i)),"object"!=typeof n&&(n=t.target=Fp(o,n)),i.sourceLinks.push(t),n.targetLinks.push(t)})}(h,a),function(t,e){var o=0;if(null==e){for(var i=[],n=0;t.links.length>n;n++){var r=t.links[n],s=r.source.index,a=r.target.index;i[s]||(i[s]=[]),i[a]||(i[a]=[]),-1===i[s].indexOf(a)&&i[s].push(a)}var c=Np(i);c.sort(function(t,e){return t.length-e.length});var l={};for(n=0;c.length>n;n++){var u=c[n].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,i=t.source.index;e===i||l[i]&&l[i][e]?(t.circular=!0,t.circularLinkID=o++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=o++)})}(h,l),function(t,e){var o=0,i=0;t.links.forEach(function(n){n.circular&&(n.circularLinkType=n.source.circularLinkType||n.target.circularLinkType?n.source.circularLinkType?n.source.circularLinkType:n.target.circularLinkType:i>o?"top":"bottom","top"==n.circularLinkType?o++:i++,t.nodes.forEach(function(t){qp(t,e)!=qp(n.source,e)&&qp(t,e)!=qp(n.target,e)||(t.circularLinkType=n.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),Dp(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(gy(t.sourceLinks,Up),gy(t.targetLinks,Up)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,o){var i,n,r;if(null!=e){t.nodes.sort(function(t,o){return e(t)<e(o)?-1:1});var s=0,a=e(t.nodes[0]);t.nodes.forEach(function(t){s=e(t)==a?s:s+1,a=e(t)==a?a:e(t),t.column=s})}for(i=t.nodes,n=[],r=0;i.length;++r,i=n,n=[])i.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>n.indexOf(t.target)&&!t.circular&&n.push(t.target)})});for(i=t.nodes,n=[],r=0;i.length;++r,i=n,n=[])i.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>n.indexOf(t.source)&&!t.circular&&n.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?o(t,r):t.column})}(h,l,c);var f=r;if(null!==s){var p=by(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),y=yy(p,function(t){return t.length});y>1&&(f=Math.max(1,(i-e)*s/(y-1)))}(function(t,e,o){var i=by(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var n=py(i,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/gy(e,function(t){return t.value})});t.ky=n,t.links.forEach(function(e){e.width=e.value*t.ky});var r=yy(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-o)/r),e.x1=e.x0+o}:function(e){e.x0=t.x0,e.x1=e.x0+o})})(h,f,n),Ay(h,l,a),My(h,l,a,f,f,u),_y(h),dy(h,a,d,10,8),Ay(h,l,a),My(h,l,a,f,f,u),_y(h),dy(h,a,d,10,8),function(t,e){let o=t;o.nodes.forEach(function(t){t.y+(t.y1-t.y0)>o.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-o.y1));var i=o.links.filter(function(o){return qp(o.source,e)==qp(t,e)}),n=i.length;n>1&&i.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!cy(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=jp(e,t);return t.y1-o}if(e.target.column>t.target.column)return jp(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;i.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),i.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;n>r;r++)s+=i[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let o=t;o.nodes.forEach(function(t){var i=o.links.filter(function(o){return qp(o.target,e)==qp(t,e)}),n=i.length;n>1&&i.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!cy(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=Yp(e,t);return t.y0-o}if(e.source.column>t.source.column)return Yp(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;i.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),i.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;n>r;r++)s+=i[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,o=t.links,i=!1,n=!1;if(o.forEach(function(t){"top"==t.circularLinkType?i=!0:"bottom"==t.circularLinkType&&(n=!0)}),0==i||0==n){let i=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=py(e,function(t){return t.y0}),s=yy(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=i(t.y0),t.y1=i(t.y1)}),o.forEach(function(t){t.y0=i(t.y0),t.y1=i(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,o=i(t.y0)-t.y0;t.y0=i(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+o}),t.targetLinks.forEach(function(t){t.y1=t.y1+o})})}}(h),dy(h,a,d,10,8)}(p),p}return p.update=function(t){return _y(t),dy(t,a,d,10,8),t},p.nodeWidth=function(t){return arguments.length?(n=+t,p):n},p.nodePadding=function(t){return arguments.length?(r=+t,p):r},p.nodePaddingRatio=function(t){return arguments.length?(s=+t,p):s},p.nodes=function(t){return arguments.length?(h="function"==typeof t?t:vy(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:vy(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:vy(t),p):a},p.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:vy(t),p):c},p.nodeSort=function(t){return arguments.length?(l=t,p):l},p.iterations=function(t){return arguments.length?(u=+t,p):u},p.circularLinkGap=function(t){return arguments.length?(d=+t,p):d},p.extent=function(n){return arguments.length?(t=+n[0][0],e=+n[0][1],o=+n[1][0],i=+n[1][1],p):[[t,e],[o,i]]},p.size=function(n){return arguments.length?(t=e=0,o=+n[0],i=+n[1],p):[o-t,i-e]},p}import{interpolateNumber as Ly}from"d3-interpolate";import{line as $y,curveLinearClosed as Ry}from"d3-shape";var Cy=t=>{let e,o,i,n,r,s,a,c,l;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,o=t.y1-t.sankeyWidth/2,i=t.y1+t.sankeyWidth/2,n=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=Ly(r,s),c=a(.5),l=a(.5),`M${e},${r}C${e},${c} ${o},${l} ${o},${s}L${i},${s}C${i},${l} ${n},${c} ${n},${r}Z`;const u=t.sankeyWidth/2,d=Ly(t.source.x1,t.target.x0),{pathD:h}=Yi({sx:t.source.x1,sTop:t.y0-u,sBot:t.y0+u,tx:t.target.x0,tTop:t.y1-u,tBot:t.y1+u,cp1X:d(.5),cp2X:d(.5)});return h};function Iy(t){const e=t.sankeyWidth/2,o=(t._circularWidth??t.sankeyWidth)/2,i=t.circularPathData;if(!i)return null;if("down"===t.direction)return null;if(t._circularStub){const o=i.sourceX,n=i.sourceY,r=i.targetX,s=i.targetY;if("object"!=typeof t.source||!t.source||"object"!=typeof t.target||!t.target)return null;const a=Math.max(15,Math.min(40,.33*(i.rightFullExtent-o))),c=Math.max(15,Math.min(40,.33*(r-i.leftFullExtent)));return`M${o},${n-e}L${o+a},${n-e}L${o+a},${n+e}L${o},${n+e}ZM${r},${s-e}L${r-c},${s-e}L${r-c},${s+e}L${r},${s+e}Z`}const n=i.sourceX,r=i.sourceY,s=i.targetX,a=i.targetY,c=i.rightFullExtent,l=i.leftFullExtent,u=i.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(o,15));return`M${n},${r-d*e}L${c},${r-d*e}L${c+o},${r-d*e+d*h}L${c+o},${u+d*o-d*h}L${c+o-h},${u+d*o}L${l-o+h},${u+d*o}L${l-o},${u+d*o-d*h}L${l-o},${a-d*e+d*h}L${l-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${l+o},${a+d*e}L${l+o},${u-d*o}L${c-o},${u-d*o}L${c-o},${r+d*e}L${n},${r+d*e}Z`}var Ty=new Set,Oy=new WeakMap;function zy(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let o=Oy.get(t);if(o){const t=o.get(e);if(t)return t}else o=new Map,Oy.set(t,o);const i=new Proxy(t,{get(t,o,i){if("string"==typeof o&&!(o in t)&&t.data&&o in t.data){const t=`${e}:${o}`;Ty.has(t)||(Ty.add(t),console.warn(`[Semiotic] "${e}" callback accessed "${o}" on the wrapper object, but it only exists on ".data". Use d.data.${o} (or d.data?.${o}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(t,o,i)}});return o.set(e,i),i}var Fy={left:function(t){return t.depth},right:function(t,e){return e-1-t.height},center:function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?Math.min.apply(Math,t.sourceLinks.map(Zp))-1:0},justify:Qp},Ny={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,i){if(0===t.length)return;const n="vertical"===o.orientation?"down":"right",r=o.nodeAlign||"justify",s=o.nodeWidth??15,a=o.nodePaddingRatio??.05,c=o.iterations??100,l=t.map(t=>({...t})),u=e.map(t=>({...t,source:Qc(t.source),target:Qc(t.target),value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===n?[[0,0],[i[1],i[0]]]:[[0,0],[i[0],i[1]]];const h=Py().extent(d).links(u).nodes(l).nodeAlign(Fy[r]||Qp).nodeId(t=>t.id).nodeWidth(s).iterations(c);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,n=-1/0;for(const i of l)t>i.x0&&(t=i.x0),i.x1>e&&(e=i.x1),o>i.y0&&(o=i.y0),i.y1>n&&(n=i.y1);for(const i of u){if(!i.circular||!i.circularPathData)continue;const r=i.circularPathData,s=(i._circularWidth??i.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),o>r.verticalFullExtent-s&&(o=r.verticalFullExtent-s),r.verticalFullExtent+s>n&&(n=r.verticalFullExtent+s)}const r=e-t,s=n-o,a=i[0],c=i[1];if(r>0&&s>0&&(0>t||0>o||e>a||n>c)){const e=Math.min(a/r,c/s),i=-t*e+(a-r*e)/2,n=-o*e+(c-s*e)/2;for(const t of l)t.x0=t.x0*e+i,t.x1=t.x1*e+i,t.y0=t.y0*e+n,t.y1=t.y1*e+n;for(const t of u)if(t.y0=t.y0*e+n,t.y1=t.y1*e+n,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const o=t.circularPathData;o.sourceX=o.sourceX*e+i,o.targetX=o.targetX*e+i,o.sourceY=o.sourceY*e+n,o.targetY=o.targetY*e+n,o.rightFullExtent=o.rightFullExtent*e+i,o.leftFullExtent=o.leftFullExtent*e+i,o.verticalFullExtent=o.verticalFullExtent*e+n,o.rightInnerExtent=o.rightInnerExtent*e+i,o.leftInnerExtent=o.leftInnerExtent*e+i,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+n,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+n,o.rightSmallArcRadius*=e,o.rightLargeArcRadius*=e,o.leftSmallArcRadius*=e,o.leftLargeArcRadius*=e,o.sourceWidth*=e,o.rightNodeBuffer*=e,o.leftNodeBuffer*=e,o.arcRadius*=e}}}const f=new Map;for(const e of t)f.set(e.id,e);for(const t of l){const e=f.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const p=new Map;for(const t of e)if(t._edgeKey)p.set(t._edgeKey,t);else{const e=Qc(t.source),o=Qc(t.target);p.set(`${e}\0${o}`,t)}for(const t of u){const e=Qc(t.source),o=Qc(t.target),i=p.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(i){i.y0=t.y0,i.y1=t.y1,i.sankeyWidth=t.width??0,i.circular=!!t.circular,i.circularPathData=t.circularPathData,i._circularWidth=t._circularWidth,i._circularStub=t._circularStub,i.path=t.path,i.circularLinkType=t.circularLinkType,i.direction=n;const r=f.get(e),s=f.get(o);r&&(i.source=r),s&&(i.target=s)}}},buildScene(t,e,o,i){const n="vertical"===o.orientation?"down":"right",r=o.nodeStyle,s=o.edgeStyle,a=o.edgeOpacity??.5,c=o.edgeColorBy||"source",l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:w,u=new Map;t.forEach((t,e)=>{u.set(t.id,l[e%l.length])});const d=[],h=[],f=[],p=new Map;for(const e of t){const t=e.x1-e.x0,o=e.y1-e.y0;if(0>=t||0>=o)continue;const i=r?r(zy(e,"nodeStyle")):{},s={fill:i.fill||u.get(e.id)||"#4d430c",stroke:i.stroke,strokeWidth:i.strokeWidth,opacity:i.opacity,cursor:i.cursor};p.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===n?{type:"rect",x:e.y0,y:e.x0,w:o,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:o,style:s,datum:e,id:e.id,label:e.id})}const y=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of y){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,i="object"==typeof t.target?t.target:null;if(!e||!i)continue;let n=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";n="function"==typeof c?c(t)||n:"target"===c?p.get(i.id)||u.get(i.id)||n:p.get(e.id)||u.get(e.id)||n;const r=s?s(zy(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,o=t.sankeyWidth/2,i=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),c=r.fill||n;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-o}L${e.sourceX+i},${e.sourceY-o}L${e.sourceX+i},${e.sourceY+o}L${e.sourceX},${e.sourceY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+i}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-o}L${e.targetX-s},${e.targetY-o}L${e.targetX-s},${e.targetY+o}L${e.targetX},${e.targetY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let l;(l=t.circular&&t.circularPathData?Iy(t):Cy(t),l)&&h.push({type:"bezier",pathD:l,bezierCache:t.bezier,style:{fill:r.fill||n,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor},datum:t})}if(!1!==o.showLabels){const e=Zc(o.nodeLabel);for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=e?e(o):o.id;if(!s)continue;let a,c,l;"down"===n?(a=o.y0+(o.y1-o.y0)/2,c=o.x1+14,l="start"):(i[0]/2>o.x0+t/2?(a=o.x0-6,l="end"):(a=o.x1+6,l="start"),c=o.y0+r/2),f.push({x:a,y:c,text:s+"",anchor:"down"===n?"middle":l,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}};import{forceSimulation as Ey,forceCenter as Dy,forceX as By,forceY as Wy,forceLink as jy,forceManyBody as Yy,forceCollide as Xy}from"d3-force";import{scaleLinear as qy}from"d3-scale";var Gy={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,i){if(0===t.length)return;const n=o.forceStrength??.1,r=i[0]/2,s=i[1]/2,a=Math.max(.1,Math.min(1,Math.min(i[0],i[1])/200)),c=Math.min(.5,.06+1.8*(1-a)),l=o.__previousPositions;let u=0;const d=[];for(const e of t){const t=null!=e.x&&null!=e.y&&(0!==e.x||0!==e.y),o=l?.get(e.id);t?u++:o?(e.x=o.x,e.y=o.y,u++):d.push(e)}const h=u>0&&.3>=(t.length>0?d.length/t.length:1);if(h){const o=new Map;for(const e of t)o.set(e.id,e);for(const t of d){const i=Vy(t.id,e,o);if(i.length>0){let e=0,o=0;for(const t of i)e+=t.x,o+=t.y;const n=Hy(t.id),r=n%360*(Math.PI/180),s=(10+n%20)*a;t.x=e/i.length+s*Math.cos(r),t.y=o/i.length+s*Math.sin(r)}else{const e=Hy(t.id),o=e%360*(Math.PI/180),i=(15+e%30)*a;t.x=r+i*Math.cos(o),t.y=s+i*Math.sin(o)}}}else{const e=2.399963229728653;for(let o=0;t.length>o;o++){const i=t[o];if(null==i.x||null==i.y||0===i.x&&0===i.y){const t=10*Math.sqrt(o+.5)*a,n=o*e;i.x=r+t*Math.cos(n),i.y=s+t*Math.sin(n)}}}const f=o.__skipForceSimulation||0===o.iterations?0:h?40:o.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),p=Uy(o.nodeSize,o.nodeSizeRange,t),y=t=>p(t);if(f>0){const l=new Map,u=new Map;for(const e of t)l.set(e.id,0),u.set(e.id,e);for(const t of e){const e=Qc(t.source),o=Qc(t.target);l.set(e,(l.get(e)??0)+1),l.set(o,(l.get(o)??0)+1)}const d=jy().strength(t=>{const e=t.weight,o=Qc(t.source),i=Qc(t.target),r=Math.max(1,Math.min(l.get(o)??1,l.get(i)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*n/(.1*r))}).distance(t=>{const e="string"==typeof t.source?u.get(t.source):t.source,o="string"==typeof t.target?u.get(t.target):t.target,i=(e?y(e):0)+(o?y(o):0)+Math.max(6,12*a);return Math.max(16,40*a,i)}).id(t=>t.id),p=Ey();if(void 0===o.random&&void 0===o.seed||p.randomSource(o.random??function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(o.seed)),p.force("charge",Yy().strength(t=>{const e=l.get(t.id)??0;return-15*a*y(t)*Math.sqrt(e+1)})).force("collide",Xy(t=>y(t)+3*a).strength(.9).iterations(2)).force("center",Dy(r,s).strength(.8)).force("x",By(r).strength(c)).force("y",Wy(s).strength(c)).force("bounds",function(t,e,o=2,i=.6){let n=[];const r=r=>{const s=i*Math.max(r,.2);for(const i of n){const n=i.x??t[0]/2,r=i.y??t[1]/2,a=i.vx??0,c=i.vy??0,l=e(i)+o,u=Math.min(t[0]/2,l),d=Math.max(t[0]/2,t[0]-l),h=Math.min(t[1]/2,l),f=Math.max(t[1]/2,t[1]-l),p=n+a,y=r+c;u>p?i.vx=a+(u-p)*s:p>d&&(i.vx=a+(d-p)*s),h>y?i.vy=c+(h-y)*s:y>f&&(i.vy=c+(f-y)*s)}};return r.initialize=t=>{n=t},r}(i,y)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:Qc(t.source),target:Qc(t.target)}));d.links(t),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let t=0;f>t;++t)p.tick()}for(const e of t){if(null==e.x||null==e.y)continue;const t=y(e),o=f>0?2:0,n=Math.min(i[0]/2,t+o),r=Math.min(i[1]/2,t+o);e.x=Math.max(n,Math.min(i[0]-n,e.x)),e.y=Math.max(r,Math.min(i[1]-r,e.y)),e.x0=0,e.x1=0,e.y0=0,e.y1=0}const g=new Map;for(const e of t)g.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=g.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=g.get(t.target);e&&(t.target=e)}}},buildScene(t,e,o,i){const n=o.nodeStyle,r=o.edgeStyle,s=Uy(o.nodeSize,o.nodeSizeRange,t),a=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:w,c=new Map;t.forEach((t,e)=>{c.set(t.id,a[e%a.length])});const l=[],u=[],d=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(zy(e,"nodeSize")),i=n?n(zy(e,"nodeStyle")):{},r={fill:i.fill||c.get(e.id)||o.themeSemantic?.primary||"#007bff",stroke:i.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??2,opacity:i.opacity,cursor:i.cursor};l.push({type:"circle",cx:e.x,cy:e.y,r:t,style:r,datum:e,id:e.id,label:e.id})}const h=new Map;for(const e of t)h.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:h.get(t.source),i="object"==typeof t.target?t.target:h.get(t.target);if(!e||!i)continue;if(null==e.x||null==e.y)continue;if(null==i.x||null==i.y)continue;const n=r?r(zy(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:i.x,y2:i.y,style:{stroke:n.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor},datum:t})}if(!1!==o.showLabels){const e=Zc(o.nodeLabel);for(const o of t){if(null==o.x||null==o.y)continue;const t=e?e(o):o.id;if(!t)continue;const i=s(zy(o,"nodeSize"));d.push({x:o.x,y:o.y-i-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:l,sceneEdges:u,labels:d}}};function Vy(t,e,o){const i=[];for(const n of e){const e=Qc(n.source),r=Qc(n.target);let s=null;if(e===t?s=r:r===t&&(s=e),s){const t=o.get(s);!t||0===t.x&&0===t.y||i.push({x:t.x,y:t.y})}}return i}function Hy(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}function Uy(t,e,o){if(o.some(t=>null!=t.__forceRadius))return t=>t.__forceRadius??8;if(null==t)return()=>8;if("number"==typeof t)return()=>t;if("function"==typeof t)return e=>t(e)||8;const i=e||[5,20],n=[];for(const e of o){const o=e.data?.[t];"number"==typeof o&&n.push(o)}if(0===n.length)return()=>i[0];const[r,s]=Pt(n);if(r===s)return()=>(i[0]+i[1])/2;const a=qy().domain([r,s]).range(i).clamp(!0);return e=>{const o=e.data?.[t];return null==o||"number"!=typeof o?i[0]:a(o)}}import{chord as Ky,ribbon as Zy}from"d3-chord";import{arc as Qy}from"d3-shape";var Jy=w,tg={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,i){if(0===t.length)return;const{padAngle:n=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(i[0],i[1])/2,c=a-r,l=i[0]/2,u=i[1]/2,d=(h=o.valueAccessor)?"function"==typeof h?h:t=>t[h]??1:t=>t.value??1;var h;const f=new Map;for(let e=0;t.length>e;e++)f.set(t[e].id,e);const p=t.length,y=Array.from({length:p},()=>Array.from({length:p},()=>0));for(const t of e){const e=Qc(t.source),o=Qc(t.target),i=f.get(e),n=f.get(o);if(void 0===i||void 0===n)continue;const r=d(t);y[i][n]=r}const g=Ky().padAngle(n);s&&g.sortGroups(s);const m=g(y),x=m.groups,b=Qy().innerRadius(c).outerRadius(a);for(const e of x){const o=t[e.index],i=b.centroid({innerRadius:c,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=i[0]+l,o.y=i[1]+u,o.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const v=new Map;for(const e of t)v.set(e.id,e);for(const t of e){const e=Qc(t.source),o=Qc(t.target),i=v.get(e),n=v.get(o);i&&(t.source=i),n&&(t.target=n)}const w=new Map;for(const t of e){const e=Qc(t.source),o=Qc(t.target);w.set(`${e}\0${o}`,t)}for(const e of m){const o=t[e.source.index].id,i=t[e.target.index].id,n=w.get(`${o}\0${i}`)||w.get(`${i}\0${o}`);n&&(n.__chordData=e)}},buildScene(t,e,o,i){const{groupWidth:n=20,edgeOpacity:r=.5}=o,s=Math.min(i[0],i[1])/2,a=s-n,c=i[0]/2,l=i[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",f=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Jy,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const y=Zy().radius(a),g=[],m=[],x=[];for(let e=0;t.length>e;e++){const o=t[e],i=o.__arcData;if(!i)continue;let n;if(u){const t=u(zy(o,"nodeStyle"));n=("string"==typeof t.fill?t.fill:void 0)||p.get(o.id)||f[e%f.length]}else n=p.get(o.id)||f[e%f.length];const r=u?u(zy(o,"nodeStyle")):{};g.push({type:"arc",cx:c,cy:l,innerR:a,outerR:s,startAngle:i.startAngle-Math.PI/2,endAngle:i.endAngle-Math.PI/2,style:{fill:n,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const i=y(e);if(!i)continue;const n=eg(i,c,l);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(zy(t,"edgeStyle"));s=("string"==typeof e.fill?e.fill:void 0)||s}else{const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;"target"===h&&o?s=p.get(o.id)||s:e&&(s=p.get(e.id)||s)}const a=d?d(zy(t,"edgeStyle")):{};m.push({type:"ribbon",pathD:n,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor},datum:t})}if(!1!==o.showLabels){const e=Zc(o.nodeLabel),i=s+12;for(const o of t){const t=o.__arcData;if(!t)continue;const n=e?e(o):o.id;if(!n)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:c+Math.cos(s)*i,y:l+Math.sin(s)*i,text:n+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:g,sceneEdges:m,labels:x}}};function eg(t,e,o){const i=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!i)return t;const n=[];let r=0;for(;i.length>r;){const t=i[r];if("M"===t||"L"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)n.push(Number(i[r])+e+""),r++,i.length>r&&!isNaN(Number(i[r]))&&(n.push(Number(i[r])+o+""),r++);else if("C"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)for(let t=0;3>t&&i.length>r&&!isNaN(Number(i[r]));t++)n.push(Number(i[r])+e+""),r++,i.length>r&&!isNaN(Number(i[r]))&&(n.push(Number(i[r])+o+""),r++);else if("Q"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)for(let t=0;2>t&&i.length>r&&!isNaN(Number(i[r]));t++)n.push(Number(i[r])+e+""),r++,i.length>r&&!isNaN(Number(i[r]))&&(n.push(Number(i[r])+o+""),r++);else if("A"===t)for(n.push(t),r++;i.length>r&&!isNaN(Number(i[r]));)n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&n.push(i[r++]),i.length>r&&(n.push(Number(i[r])+e+""),r++),i.length>r&&(n.push(Number(i[r])+o+""),r++);else"Z"===t||"z"===t?(n.push(t),r++):(n.push(i[r]),r++)}return n.join(" ")}import{hierarchy as og,tree as ig,cluster as ng,treemap as rg,pack as sg,partition as ag,treemapBinary as cg}from"d3-hierarchy";var lg=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function ug(t){const[e,o,i]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(t);return.299*e+.587*o+.114*i>150?"#222":"#fff"}function dg(t,e,o){const i=e.nodeIDAccessor;return"function"==typeof i?i(t.data)+"":"string"==typeof i&&void 0!==t.data[i]?t.data[i]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+o}function hg(t){if(!t)return null;if("function"==typeof t){const e=t;return t=>e(t.data??t)}return e=>e.data?.[t]||e[t]||e.id}function fg(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:lg}function pg(t){return Array.isArray(t.colorScheme)&&t.colorScheme.length>0?t.colorScheme[0]:t.themeSemantic?.primary?t.themeSemantic.primary:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical[0]:"#4d430c"}function yg(t,e,o,i,n){if("horizontal"===n){const n=(t+o)/2;return`M ${t},${e} C ${n},${e} ${n},${i} ${o},${i}`}if("radial"===n){const n=(t+o)/2;return`M ${t},${e} Q ${n},${e} ${n},${(e+i)/2} T ${o},${i}`}{const n=(e+i)/2;return`M ${t},${e} C ${t},${n} ${o},${n} ${o},${i}`}}var gg={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,o,i){const n=o.__hierarchyRoot;if(!n)return;const r=o.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(o.childrenAccessor),a=o.hierarchySum,c="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,l=og(n,s);l.sum(c),l.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=i;switch(r){case"tree":!function(t,e,o,i){const n=e.treeOrientation||"vertical",r=ig();r.size("horizontal"===n?[i,o]:"radial"===n?[2*Math.PI,Math.min(o,i)/2*.8]:[o,i]),r(t)}(l,o,u,d);break;case"cluster":!function(t,e,o,i){const n=e.treeOrientation||"vertical",r=ng();r.size("horizontal"===n?[i,o]:"radial"===n?[2*Math.PI,Math.min(o,i)/2*.8]:[o,i]),r(t)}(l,o,u,d);break;case"treemap":!function(t,e,o,i){const n=e.padding??4,r=e.paddingTop??0,s=rg().size([o,i]).tile(cg).padding(n);r>0&&s.paddingTop(r),s(t)}(l,o,u,d);break;case"circlepack":!function(t,e,o,i){const n=e.padding??4;sg().size([o,i]).padding(n)(t)}(l,o,u,d);break;case"partition":!function(t,e,o,i){ag().size([o,i]).padding(e.padding??1)(t)}(l,o,u,d)}const h=l.descendants();t.length=0,e.length=0;const f=new Map;for(let e=0;h.length>e;e++){const i=h[e],n={id:dg(i,o,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:i.value??0,depth:i.depth,data:i.data,createdByFrame:!0};"tree"===r||"cluster"===r?mg(n,i,o):"treemap"===r||"partition"===r?xg(n,i):"circlepack"===r&&bg(n,i),n.__hierarchyNode=i,t.push(n),f.set(i,n)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=f.get(t.parent),i=f.get(t);o&&i&&e.push({source:o,target:i,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,i){const n=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,i,n,r){const s=[],a=[],c=[],l=o.treeOrientation||"vertical",u="radial"===l,d=i[0]/2,h=i[1]/2,f="number"==typeof(p=o.nodeSize)?p:5;var p;for(const e of t){let t=e.x,i=e.y;u&&(t+=d,i+=h);const r=n(zy(e,"nodeStyle"));let a=r.fill||pg(o);if(o.colorByDepth&&void 0!==e.depth){const t=fg(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:i,r:f,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const y=o.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,i="object"==typeof t.target?t.target:null;if(!e||!i)continue;let n=e.x,s=e.y,c=i.x,f=i.y;u&&(n+=d,s+=h,c+=d,f+=h);const p=yg(n,s,c,f,l),g=r(zy(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:g.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:g.strokeWidth??1.5,opacity:g.opacity??y,cursor:g.cursor},datum:t})}if(!1!==o.showLabels){const e=hg(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let i,n,r,s=o.x,a=o.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,o=Math.sqrt(t*t+e*e);o>0?(i=s+t/o*10,n=a+e/o*10,r=0>t?"end":"start"):(i=s,n=a-12,r="middle")}else"horizontal"===l?(o.data?.children&&0!==o.data.children.length?(i=s-f-6,r="end"):(i=s+f+6,r="start"),n=a):(i=s,n=a+f+14,r="middle");c.push({x:i,y:n,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:c}}(t,e,o,i,n,r);case"treemap":case"partition":return function(t,e,o,i){const n=[],r=[];for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=i(zy(o,"nodeStyle"));let a=s.fill||pg(e);if(e.colorByDepth&&void 0!==o.depth){const t=fg(e);a=t[o.depth%t.length]}n.push({type:"rect",x:o.x0,y:o.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity,cursor:s.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=hg(e.nodeLabel),n=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,c=a.y1-a.y0;if(0>=t||0>=c)continue;const l=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===n&&!l)continue;if("parent"===n&&l)continue}const u=o?o(a):a.id;if(!u)continue;if((l?30:40)>t||(l?16:14)>c)continue;let d=i(zy(a,"nodeStyle")).fill||pg(e);if(e.colorByDepth&&void 0!==a.depth){const t=fg(e);d=t[a.depth%t.length]}const h="string"==typeof d?ug(d):e.themeSemantic?.text??"#000";r.push(l?{x:a.x0+t/2,y:a.y0+c/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,c)/6)),fill:h}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:n,sceneEdges:[],labels:r}}(t,o,0,n);case"circlepack":return function(t,e,o,i){const n=[],r=[];for(const o of t){const t=o.__radius??5;if(0>=t)continue;const r=i(zy(o,"nodeStyle"));let s=r.fill||pg(e);if(e.colorByDepth&&void 0!==o.depth){const t=fg(e);s=t[o.depth%t.length]}n.push({type:"circle",cx:o.x,cy:o.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7,cursor:r.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=hg(e.nodeLabel);for(const n of t){const t=n.__radius??5,s=o?o(n):n.id;if(!s)continue;if(15>t)continue;const a=!(n.data?.children&&n.data.children.length>0);let c=i(zy(n,"nodeStyle")).fill||pg(e);if(e.colorByDepth&&void 0!==n.depth){const t=fg(e);c=t[n.depth%t.length]}if(a){const o="string"==typeof c?ug(c):e.themeSemantic?.text??"#000";r.push({x:n.x,y:n.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:o})}else r.push({x:n.x,y:n.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:n,sceneEdges:[],labels:r}}(t,o,0,n);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function mg(t,e,o){const i=o.treeOrientation||"vertical";if("radial"===i){const o=e.x,i=e.y;t.x=i*Math.cos(o-Math.PI/2),t.y=i*Math.sin(o-Math.PI/2)}else"horizontal"===i?(t.x=e.y,t.y=e.x):(t.x=e.x,t.y=e.y);t.x0=t.x-5,t.x1=t.x+5,t.y0=t.y-5,t.y1=t.y+5,t.width=10,t.height=10}function xg(t,e){t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.x=(e.x0+e.x1)/2,t.y=(e.y0+e.y1)/2,t.width=e.x1-e.x0,t.height=e.y1-e.y0}function bg(t,e){const o=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-o,t.x1=e.x+o,t.y0=e.y-o,t.y1=e.y+o,t.width=2*o,t.height=2*o,t.__radius=o}import{pie as vg}from"d3-shape";function wg(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var kg={sankey:Ny,force:Gy,chord:tg,tree:gg,cluster:gg,treemap:gg,circlepack:gg,partition:gg,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,o,i){const n=o.__hierarchyRoot;n&&function(t,e,o,i,n){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(o.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(o.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(o.orbitMode),c=o.orbitSize??2.95,l=o.orbitEccentricity??1,u="number"==typeof c?()=>c:c,d="number"==typeof l?()=>l:l,h=wg(o);h.metaMap.clear(),i.length=0,n.length=0;const f=new Map;function p(t){const e=f.get(t)??0;return f.set(t,e+1),0===e?t:`${t}__${e}`}const y=e[0]/2,g=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=p(s(t));i.push({id:x,x:y,y:g,x0:y,x1:y,y0:g,y1:g,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,o,c,l,f,y,g){const m=r(e);if(!m?.length)return;const x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const S=(x+1)/b,A={id:o,depth:y,data:e,parentId:o},M=g?f/u(A)*S:f*S,_=vg().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(A);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),d=c+M*Math.sin(r),f=l+M*Math.cos(r)*P;i.push({id:u,x:d,y:f,x0:d,x1:d,y0:f,y1:f,width:0,height:0,value:0,depth:y,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:y,parentId:o,eccentricity:P}),n.push({source:o,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:o,target:u}}),t(a,u,d,f,M,y+1,!0)}k+=v}}(t,x,y,g,m,1,!1)}(n,i,o,t,e)},buildScene(t,e,o,i){const n=o.nodeStyle,r=o.edgeStyle,s=o.nodeSize,a="number"==typeof s?()=>s:"function"==typeof s?s:()=>6,c=[],l=[],u=[];if(!1!==o.orbitShowRings){const e=wg(o),i=new Map;for(const e of t)i.set(e.id,e);const n=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=i.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;n.has(o)||n.set(o,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:t,parentY:e,ring:o,ecc:i}]of n)for(let n=0;r>n;n++){const a=n/r*Math.PI*2,c=(n+1)/r*Math.PI*2;l.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*i,x2:t+o*Math.sin(c),y2:e+o*Math.cos(c)*i,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(zy(e,"nodeSize")),i=n?n(zy(e,"nodeStyle")):{};c.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:i.fill||o.themeSemantic?.primary||"#6366f1",stroke:i.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity??(0===(e.depth??0)?1:.85),cursor:i.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const d=new Map;for(const e of t)d.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:d.get(t.source),o="object"==typeof t.target?t.target:d.get(t.target);if(!e||!o)continue;if(null==e.x||null==o.x)continue;const i=r?r(zy(t,"edgeStyle")):{};l.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:i.stroke||"rgba(128,128,128,0.35)",strokeWidth:i.strokeWidth??.5,opacity:i.opacity??1,cursor:i.cursor},datum:t})}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=a(zy(o,"nodeSize"));if(4>=t)continue;const i="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;u.push({x:o.x,y:o.y+t+12,text:i+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:c,sceneEdges:l,labels:u}},tick:(t,e,o,i,n)=>!1!==o.orbitAnimated&&(function(t,e){const o=wg(e),i=e.orbitSpeed??.25,n=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-o.startTime)/1e3,s=i*(Math.PI/6),a=new Map;for(const e of t)a.set(e.id,e);for(const e of t){const t=o.metaMap.get(e.id);if(!t||!t.parentId)continue;const i=a.get(t.parentId);if(!i)continue;const c=t.angle+r*s*n({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=i.x+t.ring*Math.sin(c),e.y=i.y+t.ring*Math.cos(c)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)}};function Sg(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function Ag(t){if("glyph"===t.type&&t.glyph&&"number"==typeof t.size){const e=t.cx??t.x,o=t.cy??t.y;if("number"!=typeof e||"number"!=typeof o)return null;const i=ju(t.glyph,t.size);return{x:e+i.centerDx,y:o+i.centerDy,r:Math.max(1,i.radius)}}const e=t.cx??(null!=t.x&&null!=t.w?t.x+t.w/2:t.x),o=t.cy??(null!=t.y&&null!=t.h?t.y+t.h/2:t.y);return"number"!=typeof e||"number"!=typeof o?null:{x:e,y:o,r:"number"==typeof t.r?Math.max(1,t.r):"number"==typeof t.outerR?Math.max(1,t.outerR):"number"==typeof t.size?Math.max(1,Wl(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function Mg(t){if(!t)return;const e=[];for(const o of t){const t=Ag(o);t&&e.push({pointId:Sg(o),...t})}return e}import{Fragment as _g,jsxs as Pg}from"react/jsx-runtime";function Lg(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var $g=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function Rg(t){return t.map(t=>{const e=t.datum&&"object"==typeof t.datum?t.datum:{},o=e.data&&"object"==typeof e.data?e.data:e,i="cx"in t?t.cx:t.x+t.w/2,n="cy"in t?t.cy:t.y+t.h/2;return{...o,...null==o.id&&null!=t.id?{id:t.id}:{},x:i,y:n}})}function Cg(t,e){const o=At(t.theme),i=t.chartType||"force",n=t.size||[500,500],r=function(t){return Wf.has(t)?Bf:Df}(i),s=ne({...r,...t.margin},t.title),a=oe(t.title),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const i=g(t.nodes||[]);if(i.length>0)return zd(i,e);const n=Array.isArray(t.edges)?g(t.edges):[];if(0===n.length)return[];const r=Lg(t.sourceAccessor,"source"),s=Lg(t.targetAccessor,"target");return zd(Array.from(new Set(n.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];Cf(s,{props:t,categories:c,theme:o,size:n,hasTitle:a});const l=If({props:t,categories:c,theme:o,size:n,margin:s,hasTitle:a}),u=n[0]-s.left-s.right,d=n[1]-s.top-s.bottom,h=Nf(t.backgroundGraphics,n,s,null),f=Nf(t.foregroundGraphics,n,s,null),p=()=>{let i;const r=t=>Number(t),a=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:r,y:r},layout:{width:u,height:d},theme:o,frameType:"network",idPrefix:t._idPrefix,onRender:t=>{i=t}}):null;return e&&(e.evidence=(e=>jc({frameType:"network",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:e,nodeCount:0,edgeCount:0,margin:s}))(i)),zp.renderToStaticMarkup(Of(h||f||t.annotations?Pg(_g,{children:[h,a,f]}):null,{width:n[0],height:n[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))},y=function(t){return kg[t]}(i);if(!y&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${i}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const m={chartType:i,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||o.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let x,b;if($g.has(i)){const e=t.data||t.edges;if(!e||Array.isArray(e))return p();m.__hierarchyRoot=e,x=[],b=[]}else{const e=g(t.nodes||[]),o=Array.isArray(t.edges)?g(t.edges):[];if(0===e.length&&0===o.length)return p();if(b=function(t,e){const o=Lg(e.sourceAccessor,"source"),i=Lg(e.targetAccessor,"target"),n=Lg(e.valueAccessor,"value");return t.map(t=>{const e=Number(n(t));return{source:o(t)+"",target:i(t)+"",value:Number.isFinite(e)?e:1,y0:0,y1:0,sankeyWidth:0,data:t}})}(o,m),0===e.length&&b.length>0){const t=new Set;for(const e of b){const o=Mf(e.source),i=Mf(e.target);o&&t.add(o),i&&t.add(i)}x=Array.from(t).map(t=>({id:t,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:t}}))}else x=function(t,e){const o=Lg(e.nodeIDAccessor,"id");return t.map(t=>({id:o(t)+"",x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t}))}(e,m)}let v=[],k=[],S=[],A=null;if(m.customNetworkLayout){const t=m.colorScheme,e=Ss(t,o.colors.categorical,w),i=As(e,t),n={nodes:x,edges:b,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:i,config:m.layoutConfig??{}},r=m.customNetworkLayout(n);v=r.sceneNodes??[],k=r.sceneEdges??[],S=r.labels??[],A=r.overlays??null}else if(y){y.computeLayout(x,b,m,[u,d]);const t=y.buildScene(x,b,m,[u,d]);v=t.sceneNodes,k=t.sceneEdges,S=t.labels}const M=Mt(o);for(const t of S)t.fill||(t.fill=M.text);const _=Sd({nodes:k,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return td(function(t,e){switch(t.type){case"line":return id("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||"#999",strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity},"net-edge-"+e);case"bezier":{const o=t,i=`net-bezier-${e}-hatch`,n=tn(o.style.fill)?en(o.style.fill,i):void 0;return nd(ed.Fragment,{children:[n&&id("defs",{children:n}),id("path",{d:o.pathD,fill:n?`url(#${i})`:Gu(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"ribbon":{const o=t,i=`net-ribbon-${e}-hatch`,n=tn(o.style.fill)?en(o.style.fill,i):void 0;return nd(ed.Fragment,{children:[n&&id("defs",{children:n}),id("path",{d:o.pathD,fill:n?`url(#${i})`:Gu(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"curved":{const o=t;return id("path",{d:o.pathD,fill:Gu(o.style.fill,"none"),stroke:o.style.stroke||"#999",strokeWidth:o.style.strokeWidth??1,opacity:o.style.opacity},"net-edge-"+e)}default:return null}}(t,e),t,"network-edge-cursor-"+e)}(t,e)}),P=Sd({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return td(function(t,e){switch(t.type){case"circle":{const o=t,i=tn(o.style.fill)?en(o.style.fill,`net-circle-${e}-hatch`):void 0;return nd(ed.Fragment,{children:[i&&id("defs",{children:i}),id("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:i?`url(#net-circle-${e}-hatch)`:Gu(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,i=tn(o.style.fill)?en(o.style.fill,`net-rect-${e}-hatch`):void 0;return nd(ed.Fragment,{children:[i&&id("defs",{children:i}),id("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:i?`url(#net-rect-${e}-hatch)`:Gu(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,i=od().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(qu)||"",n=tn(o.style.fill)?en(o.style.fill,`net-arc-${e}-hatch`):void 0;return nd(ed.Fragment,{children:[n&&id("defs",{children:n}),id("path",{d:i,transform:`translate(${o.cx},${o.cy})`,fill:n?`url(#net-arc-${e}-hatch)`:Gu(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,i=Bl(o.symbolType,o.size,o.path);return id("path",{d:i,transform:o.rotation?`translate(${o.cx},${o.cy}) rotate(${180*o.rotation/Math.PI})`:`translate(${o.cx},${o.cy})`,fill:o.style.fill?Gu(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return Hu(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),L=_.map(t=>t.element),$=P.map(t=>t.element),R=S.map((t,e)=>function(t,e){return id("text",{x:t.x,y:t.y,textAnchor:t.anchor||"middle",dominantBaseline:t.baseline||"auto",fontSize:t.fontSize||11,fontWeight:t.fontWeight,fill:t.fill||"var(--semiotic-text, #333)",stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:t.paintOrder,children:t.text},"net-label-"+e)}(t,e)).filter(Boolean);let C;const I=t=>Number(t),T=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:I,y:I},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:Rg(v),pointNodes:Mg(v),idPrefix:t._idPrefix,onRender:t=>{C=t}}):null;return e&&(e.evidence=jc({frameType:"network",width:n[0],height:n[1],marks:[...P.map(({node:t})=>({type:"node:"+(t.type??"node")})),..._.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:C,nodeCount:P.length,edgeCount:_.length,margin:s})),zp.renderToStaticMarkup(Of(Pg(_g,{children:[h,L,$,R,T,f,A]}),{width:n[0],height:n[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}import*as Ig from"react-dom/server";import{geoPath as Tg}from"d3-geo";import{quadtree as Og}from"d3-quadtree";import{geoMercator as zg,geoEqualEarth as Fg,geoAlbersUsa as Ng,geoOrthographic as Eg,geoNaturalEarth1 as Dg,geoEquirectangular as Bg}from"d3-geo";var Wg={mercator:zg,equalEarth:Fg,albersUsa:Ng,orthographic:Eg,naturalEarth:Dg,equirectangular:Bg};function jg(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function Yg(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Xg(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function qg(t,e){if(2>t.length)return[t];const o=.4*e,i=[];let n=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>o?(2>n.length||i.push(n),n=[r]):n.push(r)}return 2>n.length||i.push(n),i}function Gg(t,e,o=24){const i=e[0]-t[0],n=e[1]-t[1],r=Math.sqrt(i*i+n*n);if(0===r)return[t,e];const s=-n/r,a=i/r,c=Math.min(.3*r,80),l=(t[0]+e[0])/2+s*c,u=(t[1]+e[1])/2+a*c,d=[];for(let i=0;o>=i;i++){const n=i/o,r=1-n;d.push([r*r*t[0]+2*r*n*l+n*n*e[0],r*r*t[1]+2*r*n*u+n*n*e[1]])}return d}function Vg(t,e){if(2>t.length)return t;const o=e/2+1,i=[];for(let e=0;t.length>e;e++){const n=t[e];let r,s;0===e?(r=t[1][0]-n[0],s=t[1][1]-n[1]):e===t.length-1?(r=n[0]-t[e-1][0],s=n[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;i.push([n[0]+s/a*o,n[1]+-r/a*o])}return i}function Hg(t,e,o,i,n){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const c=s/a,l=-r/a,u=n/2+1;return[[t[0]+c*u,t[1]+l*u],[e[0]+c*u,e[1]+l*u]]}import{scaleLinear as Ug}from"d3-scale";var Kg=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zg=["scene-style","data-paint","accessibility","evidence"],Qg=(t,e)=>({retainedData:t,invalidations:e}),Jg=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],tm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],em=["scene-geometry","data-paint","accessibility","evidence"],om=["scene-style","data-paint","accessibility","evidence"],im=["overlay","accessibility","evidence"],nm=[],rm={xAccessor:Qg("rebuild",Jg),yAccessor:Qg("rebuild",Jg),lineDataAccessor:Qg("rebuild",Jg),pointIdAccessor:Qg("rebuild",em),lineIdAccessor:Qg("rebuild",em),windowSize:Qg("rebuild",Jg),projection:Qg("preserve",tm),projectionExtent:Qg("preserve",tm),fitPadding:Qg("preserve",tm),lineType:Qg("preserve",tm),flowStyle:Qg("preserve",tm),graticule:Qg("preserve",tm),projectionTransform:Qg("preserve",tm),customLayout:Qg("preserve",tm),layoutConfig:Qg("preserve",tm),layoutMargin:Qg("preserve",tm),areaStyle:Qg("preserve",om),pointStyle:Qg("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:Qg("preserve",om),colorScheme:Qg("preserve",om),themeCategorical:Qg("preserve",om),themeDiverging:Qg("preserve",om),themeSemantic:Qg("preserve",om),themeSequential:Qg("preserve",om),decay:Qg("preserve",om),pulse:Qg("preserve",om),layoutSelection:Qg("preserve",om),annotations:Qg("preserve",im),autoPlaceAnnotations:Qg("preserve",im),clock:Qg("preserve",nm),transition:Qg("preserve",nm),introAnimation:Qg("preserve",nm),onLayoutError:Qg("preserve",nm)},sm=Qg("preserve",tm),am=class{constructor(){this.tracker=new Yr}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Kg)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Zg):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const i of t){const t=rm[i]??sm;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t),i=new Set(o.invalidations);return e.retainedDataChanged&&i.add("data"),this.tracker.record({kind:"config",keys:t},i)}};import{geoDistance as cm,geoGraticule as lm,geoInterpolate as um}from"d3-geo";function dm(t){if(null==t)return 0;if("number"==typeof t&&Number.isFinite(t)&&t>=0&&.5>t)return t;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${t+""}.`)}var hm=class t{constructor(t){this.updateResults=new am,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(t){return{...t,fitPadding:dm(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??sl()}getConfiguredWindowSize(){const t=this.config.windowSize??500;if(!Number.isInteger(t)||1>t)throw Error("GeoPipelineStore windowSize must be a positive integer");return t}retainNewestLines(t=this.getConfiguredWindowSize()){this.lineData.length>t&&(this.lineData=this.lineData.slice(-t))}resizeStreamingWindow(t){if(this.pointBuffer){const e=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],i=e.slice(-t),n=o.slice(-i.length),r=this.currentTime();this.pointBuffer=new qc(t),this.timestampBuffer=new qc(t),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(n[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:dm(t.fitPadding)}:t}(t),o=this.config,i=this.getConfiguredWindowSize(),n=Object.keys(e).filter(t=>e[t]!==o[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==i;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(n,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,i=this.timestampBuffer?.toArray()??[],n=o.slice(-e),r=i.slice(-n.length),s=this.currentTime();this.pointBuffer=new qc(e),this.timestampBuffer=new qc(e),n.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();au(this.pointBuffer,t,this.timestampBuffer,e),this.lastIngestTime=e,this.updateResults.recordData("ingest",1)}pushPointWithResult(t){return this.pushPoint(t),this.updateResults.last}pushMany(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();for(const o of t)au(this.pointBuffer,o,this.timestampBuffer,e);this.lastIngestTime=e,this.updateResults.recordData("ingest",t.length)}pushManyWithResult(t){return this.pushMany(t),this.updateResults.last}pushLine(t){null!=t&&"object"==typeof t?(this.streaming||this.initStreaming(),this.lineData.push(t),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(t){if(!Array.isArray(t)||0===t.length)return void this.updateResults.recordNoop("ingest");const e=t.filter(t=>null!=t&&"object"==typeof t);if(0!==e.length){this.streaming||this.initStreaming();for(const t of e)this.lineData.push(t);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",e.length)}else this.updateResults.recordNoop("ingest")}removeLine(t){const{lineIdAccessor:e}=this.config;if(!e)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],i=new Set(Array.isArray(t)?t:[t]),n=[];return this.lineData=this.lineData.filter(t=>!i.has(o(t)+"")||(n.push(t),!1)),n.length>0?(this.version++,this.updateResults.recordData("remove",n.length)):this.updateResults.recordNoop("remove"),n}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],i=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>i.has(o(t)+"");cu(this.pointBuffer,this.timestampBuffer,t);const e=this.pointBuffer.remove(t);return e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}{const t=[];return this.pointData=this.pointData.filter(e=>!i.has(o(e)+"")||(t.push(e),!1)),t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(t){const e=this._customRestyle;if(e){for(const o of this.scene){const i=this._baseStyles.get(o)??o.style,n=e(o,t);o.style=n?{...i,...n}:i}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,o=this.projection,i=this.geoPath,n=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(t){if(!t)return Fg();if("string"==typeof t){const e=Wg[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),Fg())}if("object"==typeof t&&"type"in t){const e=Wg[t.type],o=e?e():Fg();return t.rotate&&"rotate"in o&&o.rotate(t.rotate),t.center&&"center"in o&&o.center(t.center),o}return t}(e.projection),this.geoPath=Tg(this.projection),this.fitProjection(t),this.geoPath=Tg(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(t,e)=>l([t,e]),invertedPoint:(t,e)=>l.invert?l.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=i,this.scales=n,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,o=t.height/2,i=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:o}));i.length>0&&this.startTransition(i)}this._hasRenderedOnce=!0,e.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(t){const e=this.projection,o=this.config,i=[...this.areas],n=jg(o.xAccessor,"lon"),r=jg(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[n(t),r(t)]);i.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=Yg(o.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[n(t),r(t)]);i.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==i.length){if(o.projectionExtent){const[[i,n],[r,s]]=o.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[i,n],[i,s],[r,s],[r,n],[i,n]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const i=o.fitPadding??0,n=Math.min(t.width,t.height);e.scale(n/2-n*i),e.translate([t.width/2,t.height/2])}else{const n=o.fitPadding??0,r=t.width*n,s=t.height*n;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:i})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const o=this.projection;if(!o)return;const i=this.geoPath,n=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t.k),o.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=Tg(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=i,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const o=this.projection;if(!o)return;const i=this.geoPath,n=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t),o.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=Tg(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=i,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const o=this.projection;if(!o||!o.rotate)return;const i=this.geoPath,n=this.scales,r=[...o.rotate()];o.rotate(t),this.geoPath=Tg(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(r),this.geoPath=i,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,o=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(o++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const i=Array(o);let n=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(i[n++]=t);this._quadtree=Og().x(t=>t.x).y(t=>t.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,o=this.projection,i=this.geoPath;if(e.customLayout&&this.scales){const o=e.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Ss(e.colorScheme,e.themeCategorical,V),n={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:o,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...i]},resolveColor:As(i,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(n)}catch(t){const o=null!==this.lastCustomLayoutResult,i=Kl("geo",t,o,this.version);this.lastCustomLayoutFailure=i,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(i)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return o?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const t of s)this._baseStyles.set(t,t.style);this.restyleScene(e.layoutSelection??null)}return Vl({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:t,projection:e,path:o,areas:i,points:n,lines:r,layout:s}){const a=jg(t.xAccessor,"lon"),c=jg(t.yAccessor,"lat"),l=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),d=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),h=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,i=lm();e.step&&i.step(e.step);const n=o(i())||"";n&&l.push({type:"geoarea",pathData:n,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth??.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of i){const i=o(e);if(!i)continue;const n=o.centroid(e),r=o.bounds(e),s=o.area(e);l.push({type:"geoarea",pathData:i,centroid:n,bounds:r,screenArea:s,style:Xg(t.areaStyle,e,u),datum:e,interactive:!0})}const f=Yg(t.lineDataAccessor);for(const o of r){const i=f(o);if(!i||2>i.length)continue;let n=[];if("geo"===t.lineType){const t=Array(i.length);for(let e=0;i.length>e;e++)t[e]=[a(i[e]),c(i[e])];for(let o=0;t.length-1>o;o++){const i=t[o],r=t[o+1],s=cm(i,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),c=um(i,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const i=e(c(t/a));null!=i&&n.push(i)}}}else for(let t=0;i.length>t;t++){const o=i[t],r=e([a(o),c(o)]);null!=r&&n.push(r)}if(2>n.length)continue;const r=Xg(t.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==i.length||2>n.length||"arc"!==t.flowStyle?2!==i.length||2>n.length||"offset"!==t.flowStyle||(n="geo"===t.lineType?Vg(n,u):Hg(n[0],n[n.length-1],0,0,u)):n=Gg(n[0],n[n.length-1]);const h=qg(n,s.width);if(h.length>1)for(const t of h)2>t.length||l.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else l.push({type:"line",path:2>n.length&&h[0]||n,style:r,datum:o})}const p=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,y=e.clipAngle?e.clipAngle()??0:0,g=y>0?y*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],x="function"==typeof e.center?e.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const o of n){const i=a(o),n=c(o);if(null!=g&&cm([i,n],b)>g)continue;const r=e([i,n]);if(!r)continue;const s=t.pointStyle?t.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:p?p(o)+"":void 0};l.push(u)}return l}({config:e,projection:o,path:i,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const o=function(t,e,o,i){const n=t.filter(t=>"point"===t.type);if(2>n.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const c=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,l="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=n.find(t=>t.datum&&c(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const d=Lt(n.map(t=>t.datum?Number(l(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),1);i>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const o=t[e];"geoarea"===o.type&&o.interactive&&t.splice(e,1)}const h="strip"===a?function(t,e,o,i,n){const r=Math.max(3,Math.min(8,.35*n.height)),s=Math.max(1,n.width-2*r),a=n.height/2,c=Ug().domain([0,i]).range([0,s]);e.x=r,e.y=a;const l=[];for(const n of t){if(n===e)continue;if(!n.datum){n.x=r,n.y=a;continue}const t=Number(o(n.datum)),s=r+(isFinite(t)&&t>=0&&i>0?c(t):0);n.x=s,n.y=a,l.push({node:n,x:s})}l.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(n.height/2-1,6));let d=0;for(;l.length>d;){let t=d+1;for(;l.length>t&&3>Math.abs(l[t].x-l[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)l[d+t].node.y=a+(t-(e-1)/2)*Math.min(2.5,2*u/Math.max(1,e-1));d=t}return{cx:r,cy:a,maxCost:i,availableRadius:s,layout:"strip"}}(n,u,l,d,o):function(t,e,o,i,n,r){const s=e.x,a=e.y,c=r.width/2,l=r.height/2,u=Math.min(r.width,r.height)/2,d=Ug().domain([0,i]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),f=Math.hypot(t-s,u-a),p=Number(o(r.datum)),y=isFinite(p)&&p>=0?i>0?d(p):0:f,g=c+Math.cos(h)*y,m=l+Math.sin(h)*y;r.x=t+(g-t)*n,r.y=u+(m-u)*n}return e.x=s+(c-s)*n,e.y=a+(l-a)*n,{cx:e.x,cy:e.y,maxCost:i,availableRadius:u,layout:"radial"}}(n,u,l,d,s,o),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of n)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const o of f){const i=o.datum?.source,n=o.datum?.target;if(null!=i&&null!=n){const r=t.get(i+""),s=t.get(n+"");if(r&&s)if("fractional"===e.lineMode&&o.path.length>2){const t=o.path[0],e=o.path[o.path.length-1],i=[r[0]-t[0],r[1]-t[1]],n=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;o.path.length>t;t++)a.push(a[t-1]+Math.hypot(o.path[t][0]-o.path[t-1][0],o.path[t][1]-o.path[t-1][1]));const c=a[a.length-1];o.path=o.path.map((t,e)=>{const r=c>0?a[e]/c:e/(o.path.length-1);return[t[0]+i[0]*(1-r)+n[0]*r,t[1]+i[1]*(1-r)+n[1]*r]})}else o.path=[r,s]}}}return h}(this.scene,t,e,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const o=this.scene.filter(t=>"point"===t.type);for(let i=0;o.length>i;i++){const n=al(t,i,e);o[i]._decayOpacity=n,o[i].style={...o[i].style,opacity:n}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const o=this.scene.filter(t=>"point"===t.type),i=this.timestampBuffer.toArray(),n=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;o.length>a&&i.length>a;a++){const c=ll(e,i[a],t);s=ul(o[a],c,n,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&dl(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(t){const e=this.config.transition?.duration??300;if(0>=e)return;const o=new Map;for(const e of t)"point"===e.type&&e.pointId&&o.set(e.pointId,[e.x,e.y]);const i=this.scene.filter(t=>"point"===t.type);let n=!1;for(const t of i)if(t.pointId){const e=o.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(n=!0))}for(const t of i)t.pointId&&!o.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},n=!0);n&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=nl(t,this.activeTransition),o=il(e),i=this.scene.filter(t=>"point"===t.type);for(const t of i){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=rl(t.x,t._targetX,o),t.y=rl(e,t._targetY,o)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*o})}if(e>=1){for(const t of i)null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0),null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};hm.QUADTREE_THRESHOLD=500;var fm=hm;function pm(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("glyph"===o.type){const t=o,i=ju(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+i.centerDx,y:t.y+i.centerDy,r:i.radius})}return e}gu(fm);import{Fragment as ym,jsxs as gm}from"react/jsx-runtime";function mm(t,e){const o=At(t.theme),i=t.size||[t.width||600,t.height||400],n=ne({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=oe(t.title),s=Array.isArray(t.areas)?g(t.areas):t.areas,a=g(t.points),c=g(t.lines),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return zd(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];Cf(n,{props:t,categories:l,theme:o,size:i,hasTitle:r});const u=If({props:t,categories:l,theme:o,size:i,margin:n,hasTitle:r}),d=i[0]-(n.left??0)-(n.right??0),h=i[1]-(n.top??0)-(n.bottom??0),f={projection:t.projection||"equalEarth",projectionExtent:t.projectionExtent,xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineIdAccessor:t.lineIdAccessor,lineType:t.lineType,flowStyle:t.flowStyle,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,colorScheme:t.colorScheme,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,onLayoutError:t.onLayoutError,themeCategorical:o.colors.categorical,themeSemantic:kt(o),themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging},p=new fm(f);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);p.setAreas(s)}t.points&&p.setPoints(a),t.lines&&p.setLines(c),p.computeScene({width:d,height:h});const y=Nf(t.backgroundGraphics,i,n,p.scales),m=Nf(t.foregroundGraphics,i,n,p.scales),x=Sd({nodes:p.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return td(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const i=tn(o.style.fill)?en(o.style.fill,`geoarea-${e}-hatch`):void 0;return ad(rd.Fragment,{children:[i&&sd("defs",{children:i}),sd("path",{d:o.pathData,fill:i?`url(#geoarea-${e}-hatch)`:Gu(o.style.fill,"#e0e0e0"),fillOpacity:o.style.fillOpacity??1,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth??.5,strokeDasharray:o.style.strokeDasharray,opacity:o._decayOpacity??1})]},"geoarea-"+e)}case"point":{const o=t,i=tn(o.style.fill)?en(o.style.fill,`geopoint-${e}-hatch`):void 0;return ad(rd.Fragment,{children:[i&&sd("defs",{children:i}),sd("circle",{cx:o.x,cy:o.y,r:o.r,fill:i?`url(#geopoint-${e}-hatch)`:Gu(o.style.fill),fillOpacity:o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o._decayOpacity??o.style.opacity??1})]},"point-"+e)}case"line":{const o=t;if(2>o.path.length)return null;const i="M"+o.path.map(t=>`${t[0]},${t[1]}`).join("L");return sd("path",{d:i,fill:"none",stroke:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth??1.5,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity??1},"line-"+e)}case"glyph":return Hu(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===x.length){let r;const s=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:pm(p.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=jc({frameType:"geo",width:i[0],height:i[1],marks:x.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:l.length>0?l.length:null!=t.legend?1:void 0,margin:n})),Ig.renderToStaticMarkup(Of(y||m||t.annotations||p.customLayoutOverlays?gm(ym,{children:[y,s,m,p.customLayoutOverlays]}):null,{width:i[0],height:i[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}const b=x.map(t=>t.element);let v;const w=t.annotations?ef({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:pm(p.scene),idPrefix:t._idPrefix,onRender:t=>{v=t}}):null;return e&&(e.evidence=jc({frameType:"geo",width:i[0],height:i[1],marks:x.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:v,legendItems:l.length>0?l.length:null!=t.legend?1:void 0,margin:n})),Ig.renderToStaticMarkup(Of(gm(ym,{children:[y,b,w,m,p.customLayoutOverlays]}),{width:i[0],height:i[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}import*as xm from"react-dom/server";function bm(t=[]){return t.map(t=>({id:t.id,label:t.label,count:t.count,...null!=t.secondary?{secondary:t.secondary}:{},...t.secondaryLabel?{secondaryLabel:t.secondaryLabel}:{},...null!=t.observed?{observed:t.observed}:{}}))}var vm={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function wm(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}function km(t,e,o){const i="function"==typeof e?e(t,o):e;return{...vm,...i??{}}}function Sm(t,e={},o="settled"){return t.map((t,i)=>function(t,e={},o={index:0,simulationState:"settled"}){const i=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),n={label:e.getBodyLabel?.(t)??wm(t)},r={style:km(t,e.bodyStyle,o),datum:i,accessibleDatum:i,accessibility:n,_transitionKey:t.id};return"aabb"===t.shape.type?{type:"rect",x:t.x-t.shape.width/2,y:t.y-t.shape.height/2,w:t.shape.width,h:t.shape.height,...r}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...r}}(t,e,{index:i,simulationState:o}))}import{jsx as Am,jsxs as Mm}from"react/jsx-runtime";var _m={top:0,right:0,bottom:0,left:0};function Pm(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function Lm(t,e={}){const{element:o,scene:i,evidence:n}=function(t,e={}){const{width:o=640,height:i=360,title:n,description:r,background:s,backgroundGraphics:a,backgroundGraphicsBackdrop:c,className:l,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:f,renderBodySVG:p,renderChrome:y,...g}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),i=t.readBodies(),n=t.snapshot(),r=Sm(i,e,n.simulationState),s=function(t,e={}){const o=e.bodies??function(t){return t.world.bodies.map(t=>({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:{...t.shape},sleeping:t.sleeping,datum:t.datum}))}(t),i=o.filter(t=>t.sleeping).length,n=t.queue.length,r=t.sediment.reduce((t,e)=>t+e.count,0),s="settled"===t.simulationState&&0===n&&i===o.length,a=[];n>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const c=null!=e.charge&&Number.isFinite(e.charge)?function(t,e,o,i){const n=t-(e+o+i);return{charge:t,live:e,queued:o,sedimented:i,unaccounted:n,balanced:0===n}}(e.charge,o.length,n,r):void 0;return c&&!c.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:o.length,sleepingCount:i,settled:s,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:bm(e.projectionRows),queuedCount:n,sedimentedCount:r,...c?{ledger:c}:{},warnings:a}}(n,{bodies:i,projectionRows:e.projectionRows,stepsRun:o,charge:e.charge});return{snapshot:n,bodies:i,sceneNodes:r,evidence:s,stepsRun:o}}(t,g),x={..._m,...h},b=[o,i],v=Pm(a,b,x),w=Pm(u,b,x),k=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(d),S=n?k+"-title":void 0,A=r?k+"-desc":void 0,M=[S,A].filter(Boolean).join(" ")||void 0,_=x.left||x.top?`translate(${x.left},${x.top})`:void 0,P=Math.max(1,o-x.left-x.right),L=Math.max(1,i-x.top-x.bottom),$=k+"-plot-clip",R=_&&null!=v?Am("g",{transform:_,children:v}):v;return{element:Mm("svg",{xmlns:"http://www.w3.org/2000/svg",className:l??"stream-physics-frame",width:o,height:i,viewBox:`0 0 ${o} ${i}`,role:"img","aria-labelledby":M,style:f,children:[n&&Am("title",{id:S,children:n}),r&&Am("desc",{id:A,children:r}),Am("defs",{children:Am("clipPath",{id:$,children:Am("rect",{width:P,height:L})})}),c&&"transparent"!==c?Am("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:i,fill:c}):null,!a&&s&&"transparent"!==s?Am("rect",{x:0,y:0,width:o,height:i,fill:s}):null,R,Am("g",{id:k+"-data-area",transform:_,clipPath:`url(#${$})`,children:m.sceneNodes.map((t,e)=>{const o=m.bodies[e],i=o&&p?p(o,t.style??{},e,k):void 0;return null!=i?td(i,t,e):vd(t,e,k)})}),w,y?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:xm.renderToStaticMarkup(o),scene:i,evidence:n}}function $m(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function Rm(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,$m(t.thickness)??$m(o)??$m(e.thickness)??4)}function Cm(t){return t.sensorId??"stream-region-"+t.id}function Im(t){const e=Cm(t),o={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("boundary"===t.collider&&"aabb"===t.shape.type){const i=t.colliderThickness??8,n=t.shape.x-t.shape.width/2,r=t.shape.x+t.shape.width/2,s=t.shape.y-t.shape.height/2,a=t.shape.y+t.shape.height/2;return[{...o,id:e+"-top",shape:{type:"segment",x1:n,y1:s,x2:r,y2:s,thickness:i}},{...o,id:e+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:i}},{...o,id:e+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:n,y2:a,thickness:i}},{...o,id:e+"-left",shape:{type:"segment",x1:n,y1:a,x2:n,y2:s,thickness:i}}]}return t.collider?[{...o,id:e+"-collider",shape:t.shape}]:[]}import{jsx as Tm}from"react/jsx-runtime";function Om({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?Tm("foreignObject",{x:0,y:0,width:e,height:o,children:t}):Tm("text",{x:e/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:t}):null}import{scaleLinear as zm}from"d3-scale";function Fm(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}import{jsx as Nm,jsxs as Em}from"react/jsx-runtime";var Dm={top:0,right:0,bottom:0,left:0};function Bm(t,e){const o=t.size??[t.width??600,t.height??400],i=At(t.theme),n=void 0===t.theme?{}:function(t){const e={"--semiotic-bg":t.colors.background,"--semiotic-text":t.colors.text,"--semiotic-text-secondary":t.colors.textSecondary,"--semiotic-grid":t.colors.grid,"--semiotic-border":t.colors.border,"--semiotic-cell-border":t.colors.cellBorder||t.colors.border,"--semiotic-primary":t.colors.primary,"--semiotic-font-family":t.typography.fontFamily,"--semiotic-secondary":t.colors.secondary||t.colors.primary,"--semiotic-surface":t.colors.surface||t.colors.background};t.colors.categorical.forEach((t,o)=>{e["--semiotic-category-"+(o+1)]=t}),t.colors.focus&&(e["--semiotic-focus"]=t.colors.focus),t.colors.selection&&(e["--semiotic-selection-color"]=t.colors.selection),null!=t.colors.selectionOpacity&&(e["--semiotic-selection-opacity"]=t.colors.selectionOpacity+""),t.colors.diverging&&(e["--semiotic-diverging"]=t.colors.diverging),t.colors.annotation&&(e["--semiotic-annotation-color"]=t.colors.annotation),t.colors.success&&(e["--semiotic-success"]=t.colors.success),t.colors.danger&&(e["--semiotic-danger"]=t.colors.danger),t.colors.warning&&(e["--semiotic-warning"]=t.colors.warning),t.colors.error&&(e["--semiotic-error"]=t.colors.error),t.colors.info&&(e["--semiotic-info"]=t.colors.info),t.tooltip?.background&&(e["--semiotic-tooltip-bg"]=t.tooltip.background),t.tooltip?.text&&(e["--semiotic-tooltip-text"]=t.tooltip.text),t.tooltip?.borderRadius&&(e["--semiotic-tooltip-radius"]=t.tooltip.borderRadius),t.tooltip?.fontSize&&(e["--semiotic-tooltip-font-size"]=t.tooltip.fontSize),t.tooltip?.shadow&&(e["--semiotic-tooltip-shadow"]=t.tooltip.shadow),t.borderRadius&&(e["--semiotic-border-radius"]=t.borderRadius);const o=t.typography.legendSize??t.typography.labelSize;null!=o&&(e["--semiotic-legend-font-size"]=o+"px"),null!=t.typography.legendFontFamily&&(e["--semiotic-legend-font-family"]=t.typography.legendFontFamily),null!=t.typography.legendFontWeight&&(e["--semiotic-legend-font-weight"]=t.typography.legendFontWeight+"");const i=t.typography.titleFontSize??t.typography.titleSize;return null!=i&&(e["--semiotic-title-font-size"]=i+"px"),null!=t.typography.titleFontFamily&&(e["--semiotic-title-font-family"]=t.typography.titleFontFamily),null!=t.typography.titleFontWeight&&(e["--semiotic-title-font-weight"]=t.typography.titleFontWeight+""),null!=t.typography.tickFontFamily&&(e["--semiotic-tick-font-family"]=t.typography.tickFontFamily),null!=t.typography.tickSize&&(e["--semiotic-tick-font-size"]=t.typography.tickSize+"px"),null!=t.typography.labelSize&&(e["--semiotic-axis-label-font-size"]=t.typography.labelSize+"px"),e}(i),r=t.bodyStyle,s=!1,a=t.legendPosition??"right",c=ie({...Dm,...t.margin},s,!!t.legend&&"top"===a);if(t.legend){const e={...c};ge(c,{legend:t.legend,position:a,size:o,hasTitle:s,legendLayout:t.legendLayout}),re(c,e,o,a)}let l;const u=function({annotations:t,chartId:e,chartType:o,config:i,onRegionObservation:n,regionEffects:r,seed:s,size:a}){const c=function(t=[],e={}){const o=e.idPrefix?e.idPrefix+"-":"",i=[];for(const n of t){if("barrier"!==n.physics&&"sensor"!==n.physics)continue;const t=n.axis??e.defaultAxis??"x",r=Rm(n,e),s=n.colliderId??`${o}${n.id}`;let a;if("x"===t){const t=$m(n.x),o=$m(n.y1)??$m(e.plotBounds?.y)??$m(n.y),i=$m(n.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??$m(n.y);if(null==t||null==o||null==i)continue;a={type:"segment",x1:t,y1:o,x2:t,y2:i,thickness:r}}else{const t=$m(n.y),o=$m(n.x1)??$m(e.plotBounds?.x)??$m(n.x),i=$m(n.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??$m(n.x);if(null==t||null==o||null==i)continue;a={type:"segment",x1:o,y1:t,x2:i,y2:t,thickness:r}}i.push({id:s,shape:a,sensor:"sensor"===n.physics,..."barrier"!==n.physics||null==n.restitution&&null==e.barrierRestitution?{}:{restitution:$m(n.restitution)??$m(e.barrierRestitution)},..."barrier"!==n.physics||null==n.friction&&null==e.barrierFriction?{}:{friction:$m(n.friction)??$m(e.barrierFriction)}})}return i}((t??[]).filter(t=>"barrier"===t.physics||"sensor"===t.physics),{idPrefix:e?e+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),l=void 0===s||void 0!==i?.kernel?.seed?i:{...i,kernel:{...i?.kernel,seed:s}},u=r.flatMap(t=>[{id:Cm(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...Im(t)]),d=Object.fromEntries(r.map(t=>[Cm(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=l?.observation,f=r.length>0;return f||u.length>0||c.length>0||null!=e||h?{...l,colliders:[...l?.colliders??[],...u,...c],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{f&&n(t),h?.onObservation?.(t)}}}:l}({annotations:t.annotations,chartId:t.chartId,chartType:"StreamPhysicsFrame",config:t.config,onRegionObservation:()=>{},regionEffects:t.regionEffects??[],seed:t.seed,size:[Math.max(1,o[0]-c.left-c.right),Math.max(1,o[1]-c.top-c.bottom)]}),d=new ss(u);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&d.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const h=Lm(d,{...t,width:o[0],height:o[1],background:t.background??i.colors.background,bodyStyle:(t,e)=>({fill:i.colors.primary,stroke:i.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof r?r(t,e):r}),style:{...n,fontFamily:i.typography.fontFamily,...t.style},charge:t.charge,idPrefix:t.idPrefix??t._idPrefix??"physics",margin:c,renderChrome:e=>{const n=function(t,e,o,i,n){const r=Math.max(1,o[0]-i.left-i.right),s=Math.max(1,o[1]-i.top-i.bottom),a=function(t){return t?.length?t.map(t=>null!=t.pointId||null==t.bodyId?t:{...t,pointId:t.bodyId+""}):t}(e.annotations),c=function(t){const{width:e,height:o,pointNodes:i=[],data:n}=t;return{scales:{x:zm().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:zm().domain([0,Math.max(1,o)]).range([0,Math.max(1,o)])},width:e,height:o,frameType:"network",pointNodes:i,data:n,xAccessor:"x",yAccessor:"y"}}({width:r,height:s,pointNodes:(l=t.bodies,l.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,Fm(t))})))});var l;const u=c.scales?.x,d=c.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const f=ef({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:n,frameType:"network",xAccessor:c.xAccessor,yAccessor:c.yAccessor,pointNodes:c.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),p=e.legend?Rf(e.legend,{theme:n,position:e.legendPosition,size:[o[0],o[1]],margin:i,hasTitle:!!e.title,legendLayout:e.legendLayout})??nf(e.legend,o,i,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:Em("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:o[0],height:o[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Nm("g",{transform:`translate(${i.left},${i.top})`,children:f}),Nm(Om,{title:e.title,totalWidth:o[0],marginTop:Math.max(i.top,28)}),p]})}}(e,t,o,c,i);return l=n.annotationRender,n.node}});return e&&(e.evidence=jc({frameType:"physics",width:o[0],height:o[1],marks:h.scene.sceneNodes,title:t.title,description:t.description,annotations:t.annotations,annotationRender:l,extraWarnings:[...0===h.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...h.scene.evidence.warnings]})),h.svg}import*as Wm from"react-dom/server";import{jsx as jm,jsxs as Ym}from"react/jsx-runtime";var Xm={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function qm(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var Gm={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",i=Xm[o],n=qm(t.width,i.width),r=qm(t.height,i.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):i.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:i.align,c="center"===a?"middle":"end"===a?"end":"start",l="center"===a?n/2:"end"===a?n-s:s,u=At(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const o=e.locale??"en-US";if("currency"===t){const t=e.precision??2,i=new Intl.NumberFormat(o,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>i.format(t)}if("percent"===t){const t=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",o=Math.abs(t);if(1e3>o)return`${e}${Math.round(o)}ms`;const i=o/1e3;if(60>i)return`${e}${n=i,Math.round(100*n)/100+""}s`;var n;const r=i/60;if(60>r){const t=Math.floor(r),o=Math.round(i-60*t);return 0===o?`${e}${t}m`:`${e}${t}m ${o}s`}const s=r/60;if(24>s){const t=Math.floor(s),o=Math.round(r-60*t);return 0===o?`${e}${t}h`:`${e}${t}h ${o}m`}const a=Math.floor(s/24),c=Math.round(s-24*a);return 0===c?`${e}${a}d`:`${e}${a}d ${c}h`}(t);const i=new Intl.NumberFormat(o,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>i.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),f=void 0===d?"No value":(p=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${p}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var p;const y=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const o=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let i=null;for(const e of o){if(e.at>t)break;i=e}return i}(d,t.thresholds),g="string"==typeof t.color?t.color:function(t,e,o){return e||("success"===t?o.colors.success??"#2ca02c":"warning"===t?o.colors.warning??"#b26a00":"danger"===t?o.colors.danger??"#d62728":"info"===t?o.colors.info??o.colors.primary:o.colors.text)}(y?.level??"neutral",y?.color,u),m="string"==typeof t.label?t.label:void 0,x="string"==typeof t.caption?t.caption:void 0,b="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,o){const i=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,n=i&&"number"==typeof i.value&&Number.isFinite(i.value)?i.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===n?void 0:e-n);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,o);return`${s}${i&&"string"==typeof i.label?" "+i.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,o){const i=t.target&&"object"==typeof t.target?t.target:void 0;if(!i||"number"!=typeof i.value||!Number.isFinite(i.value))return;const n="string"==typeof i.label?" "+i.label:"";return 0===i.value?`target ${o(i.value)}${n}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/i.value)} of ${o(i.value)}${n}`}(t,d,h),k=[v,w,y?.label].filter(Boolean).join(" · "),S="string"==typeof t.description&&t.description||[m,f,b,k].filter(Boolean).join(", "),A="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+i.labelSize,P=_+i.captionSize+4,L="presentation"===o?r/2+.32*i.valueSize:"thumbnail"===o?r/2+.34*i.valueSize:Math.min(r-s-(k?26:4),(i.showHeader&&(m||x)?x?P+10:_+14:s)+i.valueSize),$=l+("start"===c?Math.max(i.valueSize,f.length*i.valueSize*.55):0),R=Wm.renderToStaticMarkup(Ym("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:r,viewBox:`0 0 ${n} ${r}`,role:"img","aria-label":S,"data-semiotic-component":"BigNumber",children:[jm("title",{children:m??f}),"string"==typeof t.description&&jm("desc",{children:t.description}),jm("rect",{x:i.border?.5:0,y:i.border?.5:0,width:i.border?n-1:n,height:i.border?r-1:r,rx:i.border?8:0,fill:A,stroke:i.border?M:"none"}),i.showHeader&&m&&jm("text",{x:l,y:_,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.labelSize,fontWeight:600,fill:u.colors.text,children:m}),i.showHeader&&x&&jm("text",{x:l,y:P,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.captionSize,fill:u.colors.textSecondary,children:x}),jm("text",{x:l,y:L,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:g,"data-mark-type":"value",children:f}),b&&void 0!==d&&"start"===c&&jm("text",{x:$+6,y:L,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*i.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),i.showDetail&&k&&jm("text",{x:l,y:Math.min(r-s,L+i.detailSize+10),textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:i.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=jc({frameType:"value",width:n,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:S})),R}};function Vm(t,e,o){return Gm[t](e,o)}import{Fragment as Hm,jsx as Um,jsxs as Km}from"react/jsx-runtime";function Zm(t,e){switch(t){case"xy":return Vf(e);case"ordinal":return Op(e);case"network":return Cg(e);case"geo":return mm(e);case"physics":return Bm(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Qm(t){return Vf(t)}function Jm(t){return Op(t)}function tx(t){return Cg(t)}function ex(t){return mm(t)}var ox=new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),ix=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function nx(t,e){const o=Number(t);if(!Number.isFinite(o))return t;const i=10**e,n=Math.round((o+Number.EPSILON)*i)/i;return Object.is(n,-0)?"0":n+""}function rx(t,e){const o=function(t){if(Number.isFinite(t))return Math.max(0,Math.min(8,Math.floor(t)))}(e);return void 0===o?t:t.replace(/<[^>]+>/g,t=>t.replace(/\s([\w:-]+)="([^"]*)"/g,(t,e,i)=>!ox.has(e)||/\b(?:var|calc|url)\(/i.test(i)?t:` ${e}="${function(t,e){const o=RegExp(ix.source,ix.flags);let i,n="",r=0,s=!1;for(;i=o.exec(t);){const o=t.slice(r,i.index);n+=s&&0===o.length?" ":o,n+=nx(i[0],e),r=i.index+i[0].length,s=!0}return n+t.slice(r)}(i,o)}"`))}var sx=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],ax=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function cx(t,e){const o={};for(const i of e)void 0!==t[i]&&(o[i]=t[i]);return o}function lx(t,e,o){return dx(t,e,o).svg}function ux(t,e,o){const i={},{svg:n,frameType:r}=dx(t,e,o,i),s=i.evidence??jc({frameType:r,width:"number"==typeof e.width?e.width:600,height:"number"==typeof e.height?e.height:400,marks:[],title:"string"==typeof e.title?e.title:void 0,description:"string"==typeof e.description?e.description:void 0,annotations:e.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=t,h(s,t,e),{svg:n,evidence:s}}function dx(e,r,s,a){if(Object.prototype.hasOwnProperty.call(Gm,e))return{svg:rx(Vm(e,r,a),s?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(Dc,e))throw Error(`Unknown chart component: "${e}". Run \`npx semiotic-ai --list\` for supported chart types.`);const c=Dc[e];var l;const u=function(e,r,s){const a=i[e||"primary"],c=e&&"primary"!==e||!s?.width?a.width:s.width,l=e&&"primary"!==e||!s?.height?a.height:s.height,u=function(e,o,i=e.responsiveRules){if(!Array.isArray(i)||0===i.length)return{props:e,matches:[]};const n=i.map((t,e)=>({rule:t,index:e})).filter(t=>function(t,e){const{when:o}=t,i=e.width,n=e.height,r=function(t){if("number"==typeof t.height&&t.height>0)return t.width/t.height}(e),s=function(t){if("number"==typeof t.height&&t.height>0)return t.height>t.width?"portrait":"landscape"}(e);return!("number"==typeof o.minWidth&&o.minWidth>i||"number"==typeof o.maxWidth&&i>o.maxWidth||"number"==typeof o.minHeight&&("number"!=typeof n||o.minHeight>n)||"number"==typeof o.maxHeight&&("number"!=typeof n||n>o.maxHeight)||"number"==typeof o.minAspectRatio&&("number"!=typeof r||o.minAspectRatio>r)||"number"==typeof o.maxAspectRatio&&("number"!=typeof r||r>o.maxAspectRatio)||o.orientation&&s!==o.orientation)}(t.rule,o)).sort((t,e)=>("number"==typeof t.rule.priority?t.rule.priority:t.index)-("number"==typeof e.rule.priority?e.rule.priority:e.index));return{props:n.reduce((e,o)=>function(e,o){const i={...e,...o};for(const n of["margin","frameProps","mobileSemantics","style"])t(e[n])&&t(o[n])&&(i[n]={...e[n],...o[n]});return"string"==typeof e.className&&"string"==typeof o.className&&(i.className=`${e.className} ${o.className}`),i}(e,o.rule.transform),e),matches:n}}({...r,mode:e},{width:r.width??c,height:r.height??l}).props,d=u.mode||e||"primary",h=i[d],f="context"===d||"sparkline"===d,p="primary"===d&&s?.width?s.width:h.width;return{mode:d,width:u.width??p,height:u.height??("primary"===d&&s?.height?s.height:h.height),showAxes:u.showAxes??h.showAxes,showGrid:u.showGrid??h.showGrid,enableHover:u.enableHover??(!!u.linkedHover||h.enableHover),showLegend:u.showLegend??h.showLegend,showLabels:u.showLabels??h.showLabels,title:f?void 0:u.title,description:u.description,summary:u.summary,accessibleTable:u.accessibleTable,xLabel:f?void 0:u.xLabel,yLabel:f?void 0:u.yLabel,categoryLabel:f?void 0:u.categoryLabel,valueLabel:f?void 0:u.valueLabel,marginDefaults:n(h.marginDefaults,u.showCategoryTicks,u.orientation),compactMode:f,mobileInteraction:o(u.mobileInteraction,{mode:d,width:u.width??p,mobileSemantics:u.mobileSemantics}),mobileSemantics:u.mobileSemantics}}(c.layout?.mode??("string"==typeof(l=r.mode)&&Object.prototype.hasOwnProperty.call(i,l)?r.mode:void 0),{...c.layout?.modeDefaults,...cx(r,ax)},c.layout?.primarySize),{data:d,theme:h,background:p,className:y,annotations:g,margin:m,colorScheme:x,colorBy:b,legendPosition:v,...w}=r,{width:k,height:S}=u,A=[k,S],M=w.frameProps||{},_=c.layout?.margin,P="function"==typeof _?_(r,u):_??u.marginDefaults,L=void 0!==m?m:M.margin,$=function(t){if(null==t)return;if("number"==typeof t)return{top:t,right:t,bottom:t,left:t};const e={};return"number"==typeof t.top&&(e.top=t.top),"number"==typeof t.right&&(e.right=t.right),"number"==typeof t.bottom&&(e.bottom=t.bottom),"number"==typeof t.left&&(e.left=t.left),e}(L),R="number"==typeof L?{top:L,right:L,bottom:L,left:L}:{...P,...$},C=cx(w,sx),I=t=>M[t]??u[t],T={...M,...C,theme:h,title:u.title,description:u.description,showAxes:I("showAxes"),showLegend:I("showLegend"),showLabels:I("showLabels"),showGrid:I("showGrid"),xLabel:I("xLabel"),yLabel:I("yLabel"),categoryLabel:I("categoryLabel"),valueLabel:I("valueLabel"),background:p,className:y,annotations:g,size:A,margin:R,__compactMode:u.compactMode,__autoLegendMargin:!0,...void 0!==x&&{colorScheme:x},...void 0!==v&&{legendPosition:v},_idPrefix:w._idPrefix},O=c.buildProps(d,b,x,T,w);let z;switch(c.frameType){case"xy":z=Vf(O,a);break;case"ordinal":z=Op(O,a);break;case"network":z=Cg(O,a);break;case"geo":z=mm(O,a);break;case"physics":z=Bm(O,a)}const F=c.renderOverlay?.(O,{theme:At(h)});if(null!=F){const t=f.renderToStaticMarkup(Um(Hm,{children:F})),e=z.lastIndexOf("</svg>");z=0>e?`${z}${t}`:`${z.slice(0,e)}${t}${z.slice(e)}`}return{svg:rx(z,s?.precision),frameType:c.frameType}}function hx(t,e={}){const{title:o,subtitle:i,theme:n,width:r=1200,height:s,layout:a={},background:c}=e,l=Mt(At(n)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),i&&(h+=20),h>0&&(h+=10);const p=Math.floor((r-d-d*(u-1))/u),y=[];let g=0,m=h+d,x=0;for(const e of t){const t=Math.min(e.colSpan||1,u),o=e.props.height||300;g+t>u&&(m+=x+d,g=0,x=0),y.push({chart:e,x:d/2+g*(p+d),y:m,w:p*t+d*(t-1),h:o}),x=Math.max(x,o),g+=t}const b=s||m+x+d,v=y.map((t,e)=>{const{chart:o,x:i,y:r,w:s,h:a}=t,c={...o.props,width:s,height:a,theme:n,_idPrefix:"chart-"+e};let l;return l=o.component?lx(o.component,c):o.frameType?Zm(o.frameType,c):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,Um("g",{transform:`translate(${i},${r})`,children:Um("foreignObject",{width:s,height:a,children:Um("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:l}})})},"dashboard-chart-"+e)});return f.renderToStaticMarkup(Km("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:l.fontFamily},children:[o&&Um("title",{children:o}),c&&Um("rect",{x:0,y:0,width:r,height:b,fill:c}),o&&Um("text",{x:r/2,y:24,textAnchor:"middle",fontSize:l.titleFontSize+4,fontWeight:l.titleFontWeight,fill:l.text,fontFamily:l.titleFontFamily,children:o}),i&&Um("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:l.labelSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:i}),v]}))}import*as fx from"react-dom/server";import{Fragment as px,jsx as yx,jsxs as gx}from"react/jsx-runtime";function mx(t,e,o,i={}){const{stepSize:n,windowSize:r,frameCount:s,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:d="ease-out",decay:h}=i,f=o.width||600,p=o.height||400,y=At(o.theme),g={...o,...a&&{xExtent:a},...c&&{yExtent:c}};if(!e||0===e.length)return[];const m=n||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),x=[];for(let t=m;e.length>=t;t+=m)x.push(t);x[x.length-1]!==e.length&&x.push(e.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=ne({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=f-v.left-v.right,k=p-v.top-v.bottom,S=[];if(b)for(let i=0;x.length>i;i++){const n=x[i],s=e.slice(r?Math.max(0,n-r):0,n),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,connectorAccessor:o.connectorAccessor,connectorStyle:o.connectorStyle,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||y.colors.categorical,...h&&{decay:h}},c=new vp(a);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:w,height:k}),c.scene.length>0&&S.push(Sx(c.scene,f,p,y,g))}else for(let i=0;x.length>i;i++){const n=x[i],s=e.slice(r?Math.max(0,n-r):0,n),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:c,colorScheme:o.colorScheme||y.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...l>0&&{transition:{duration:l*(1e3/u),easing:d}}},b=new Tu(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(S.push(kx(b.scene,f,p,y,g,v)),l>0&&i>0&&b.activeTransition){const t=l*(1e3/u);for(let e=1;l>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/l*t),S.push(kx(b.scene,f,p,y,g,v))}}return S}function xx(t,e,o={}){return e.map(e=>{try{return lx(t,{...o,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||e.width||600}" height="${o.height||e.height||400}"></svg>`}})}function bx(t,e,o){const i=e.size??[e.width??600,e.height??400],n=At(e.theme),r=Mt(n),s=e.background||n.colors.background,a=e.idPrefix??"physics-gif",c=e.title?`${a}-title-${o}`:void 0,l=e.description?`${a}-desc-${o}`:void 0,u=[c,l].filter(Boolean).join(" ")||void 0,d=Sm(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=gx("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&yx("title",{id:c,children:e.title}),e.description&&yx("desc",{id:l,children:e.description}),s&&"transparent"!==s?yx("rect",{x:0,y:0,width:i[0],height:i[1],fill:s}):null,yx("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>vd(t,e,`${a}-${o}`))})]});return fx.renderToStaticMarkup(h)}function vx(t,e={}){const{fps:o=12,frameCount:i,durationSeconds:n=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:c}=e,l=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),d=i??Math.max(1,Math.ceil(n*Math.max(1,o))),h=c?{...t,background:c}:t,f=new ss(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(bx(f,h,0)));d>p.length;){for(let t=0;u>t;t+=1)f.tick(l);p.push(bx(f,h,p.length))}return p}function wx(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function kx(t,e,o,i,n,r){const s=Mt(i),a=ne({top:20,right:20,bottom:30,left:40,...n.margin},n.title),c=e-a.left-a.right,l=o-a.top-a.bottom,u=wx(n,i),d=n.renderMode,h=t.map((t,e)=>kd({node:t,index:e,renderMode:d,fallback:()=>vd(t,e)}).element).filter(Boolean),f=function(t,e,o,i,n,r){if(!t||0===t.length)return null;const s=Mt(i),a=[];for(let i=0;t.length>i;i++){const c=t[i];if("y-threshold"===c.type&&null!=c.value){let t=null;if(r)t=r(c.value);else if(n){const[e,i]=n,r=i-e;if(0===r)continue;t=o-(c.value-e)/r*o}if(null==t)continue;const l=c.color||s.primary,u=c.labelPosition||"right";a.push(gx("g",{children:[yx("line",{x1:0,y1:t,x2:e,y2:t,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&yx("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(o-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:l,fontFamily:s.fontFamily,children:c.label})]},"ann-"+i))}}return a.length>0?yx(px,{children:a}):null}(n.annotations,c,l,i,n.yExtent,r?.y),p="string"==typeof n.title?n.title:void 0,y="string"==typeof n.description?n.description:void 0,g=p?"semiotic-title":void 0,m=y?"semiotic-desc":void 0,x=[g,m].filter(Boolean).join(" ")||void 0;return fx.renderToStaticMarkup(gx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[p&&yx("title",{id:g,children:p}),y&&yx("desc",{id:m,children:y}),u&&yx("rect",{x:0,y:0,width:e,height:o,fill:u}),gx("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&yx("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:p})]}))}function Sx(t,e,o,i,n){const r=Mt(i),s=ne({top:20,right:20,bottom:30,left:40,...n.margin},n.title),a="radial"===n.projection,c=a?s.left+(e-s.left-s.right)/2:s.left,l=a?s.top+(o-s.top-s.bottom)/2:s.top,u=wx(n,i),d=Pp({nodes:t,renderMode:n.renderMode,idPrefix:n.idPrefix}).map(t=>t.element),h="string"==typeof n.title?n.title:void 0,f="string"==typeof n.description?n.description:void 0,p=h?"semiotic-title":void 0,y=f?"semiotic-desc":void 0,g=[p,y].filter(Boolean).join(" ")||void 0;return fx.renderToStaticMarkup(gx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":g,style:{fontFamily:r.fontFamily},children:[h&&yx("title",{id:p,children:h}),f&&yx("desc",{id:y,children:f}),u&&yx("rect",{x:0,y:0,width:e,height:o,fill:u}),yx("g",{transform:`translate(${c},${l})`,children:d}),h&&yx("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}export{mx as generateFrameSVGs,xx as generateFrameSequence,vx as generatePhysicsFrameSVGs,lx as renderChart,ux as renderChartWithEvidence,hx as renderDashboard,ex as renderGeoToStaticSVG,tx as renderNetworkToStaticSVG,Jm as renderOrdinalToStaticSVG,Zm as renderToStaticSVG,Qm as renderXYToStaticSVG,At as resolveTheme,rx as serializeSvgPrecision,Mt as themeStyles};
1
+ function t(t){return!!t&&"object"==typeof t&&!Array.isArray(t)}var e={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function o(t,o={}){const n=o.mobileSemantics?.interaction,i="number"==typeof n?.targetSize?n.targetSize:"number"==typeof o.mobileSemantics?.minimumHitTarget?o.mobileSemantics.minimumHitTarget:void 0,r="mobile"===o.mode||"number"==typeof o.width&&480>=o.width,s=!!n||void 0!==i,a=t&&"object"==typeof t?t:void 0;if(!1===t||!1===a?.enabled||void 0===t&&!r&&!s)return e;const c=a??{};return{enabled:!0,tapToSelect:c.tapToSelect??!0,tapToLockTooltip:c.tapToLockTooltip??!0,clearSelection:c.clearSelection??"backgroundTap",targetSize:c.targetSize??i??44,snap:c.snap??"nearestDatum",brushHandleSize:c.brushHandleSize??44,standardControls:c.standardControls??!1}}var n={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 i(t,e,o){if(!1!==e)return t;const n={...t};return"horizontal"===o?n.left=Math.min(n.left,15):n.bottom=Math.min(n.bottom,15),n}function r(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var s={kind:"rank-competition"};function a(t,e,o,n){const i=t??e;return"function"==typeof i?i(o,n):o[i+""]}var c=Symbol.for("semiotic.semantic-viability"),l=globalThis,u=l[c]??(l[c]=new Map);function d(t){return"string"==typeof t?.code&&t.code.length>0&&("warning"===t.severity||"error"===t.severity)&&"string"==typeof t.message&&t.message.length>0}function h(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const n=function(t){return function(t){return u.has(t)}(t)?function(t){return u.get(t)}(t):"BumpChart"===t?s:void 0}(e);if(!n)return;let i;try{const e="function"==typeof n?n(o,t):function(t){const e=new Map;(Array.isArray(t.data)?t.data:[]).forEach((o,n)=>{if(!Number.isFinite(Number(a(t.yAccessor,"y",o,n))))return;const i=r(a(t.xAccessor,"x",o,n)),s=e.get(i)??new Set;s.add(a(t.lineBy,"series",o,n)+""),e.set(i,s)});const o=Array.from(e.values(),t=>t.size).sort((t,e)=>t-e);if(0===o.length)return[];const n=Math.floor(o.length/2),i={columns:o.length,median:o.length%2?o[n]:(o[n-1]+o[n])/2,max:o[o.length-1],contestedColumns:o.filter(t=>t>=2).length},s=2>i.max;return s||2>i.contestedColumns||2>i.median?[{code:s?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:s?"error":"warning",message:s?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...i}}]:[]}(o);i=Array.from(e).filter(d)}catch{return void(t.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||t.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}t.semanticDiagnostics=i,t.semanticStatus=i.some(t=>"error"===t.severity)?"degenerate":i.some(t=>"warning"===t.severity)?"degraded":"meaningful";for(const e of i)t.warnings.includes(e.code)||t.warnings.push(e.code)}import*as f from"react-dom/server";import*as p from"react";var y=Object.freeze([]);function g(t){if(!t)return y;let e=!1;for(let o=0;t.length>o;o++){const n=t[o];if(null==n||"object"!=typeof n){e=!0;break}}if(!e)return t;const o=[];for(const e of t)null!=e&&"object"==typeof e&&o.push(e);return o}import{scaleOrdinal as m}from"d3-scale";function x(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function b(t,e,o){const n=t=>t.toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function v(t){const e=t.map(x),o=e.length-1;return t=>{if(Number.isNaN(t)&&(t=0),0>=t){const[t,o,n]=e[0];return b(t,o,n)}if(t>=1){const[t,n,i]=e[o];return b(t,n,i)}const n=t*o,i=Math.floor(n),r=n-i,[s,a,c]=e[i],[l,u,d]=e[i+1];return b(Math.round(s+(l-s)*r),Math.round(a+(u-a)*r),Math.round(c+(d-c)*r))}}var w=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],k=v(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),A=v(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),S=v(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),M=v(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),_=v(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),P=v(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),L=v(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),$=v(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),R=v(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),T=v(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),I=v(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),C=v(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),O={blues:k,reds:A,greens:S,viridis:L,oranges:M,purples:_,greys:P,plasma:$,inferno:R,magma:T,cividis:I,turbo:C};function F(t){return t&&Object.prototype.hasOwnProperty.call(O,t)?O[t]:k}var D=v(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),z=v(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),N=v(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),E=v(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),B=v(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),W=v(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),j=v(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),Y={category10:w,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...O},X=w,q="#007bff";function G(t,e,o=X){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=Object.values(t).filter(t=>"string"==typeof t&&t.length>0);if(e.length>0)return e}if(Array.isArray(t)&&t.length>0)return t;if("string"==typeof t){const e=Object.prototype.hasOwnProperty.call(Y,t)?Y[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var V=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],H=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],U=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function K(t,e,o){if("function"==typeof e){const n=e(t);return o&&n&&"string"==typeof n&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||U.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):X[Math.abs(function(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o),e&=e;return Math.abs(e)}(n))%X.length]}function Z(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const o=t[e];return"string"==typeof o&&o.length>0?o:void 0}function Q(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>Z(t,e)??"#999"}const n=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),i=n.every(t=>!isNaN(Number(t)));if(Array.isArray(o))return m().domain(n).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(Y,o)?Y[o]:Y.category10;if(i&&"function"==typeof r){let t=-1/0;for(const e of n){const o=Number(e);o>t&&(t=o)}return e=>r(0===t?0:Number(e)/t)}{const t=Array.isArray(r)?r:X;return m().domain(n).range(t).unknown("#999")}}function J(t,e,o=[3,20],n){let i;if(i="function"==typeof e?e(t):t?.[e],!n)return i;const[r,s]=n,[a,c]=o;if(s===r)return(a+c)/2;let l=(i-r)/(s-r);return 0>l?l=0:l>1&&(l=1),a+l*(c-a)}function tt(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function et(t,e){if(!tt(e))return t??((...t)=>({}));const o={};return void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...o}):(...t)=>({...o})}function ot(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>rt(e(t))}function nt(t,e){const o=ot(t),n=ot(e);return(t,e)=>{const i=n(t);return{value:i,x:o(t),y:i,category:e}}}function it(t,e){const o=ot(e??"value"),n=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=n?n(t):void 0;return{value:o(t),category:null==e?void 0:e+""}}}function rt(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function st(t,e,o){const n=t.when;return void 0===n||!0===n||!1!==n&&("function"==typeof n?n(e,o):function(t,e,o){const n=null!=t.axis?o[t.axis]:null!=t.field?e[t.field]:o.value;if(void 0!==t.eq&&n!==t.eq)return!1;if(void 0!==t.ne&&n===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(n))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const i=rt(n);if(void 0===i)return!1;if(void 0!==t.gt&&t.gt>=i)return!1;if(void 0!==t.gte&&t.gte>i)return!1;if(void 0!==t.lt&&i>=t.lt)return!1;if(void 0!==t.lte&&i>t.lte)return!1;if(void 0!==t.within){const[e,o]=t.within;if(e>i||i>o)return!1}if(void 0!==t.outside){const[e,o]=t.outside;if(i>=e&&o>=i)return!1}return!0}(n,e,o))}function at(t,e,o){if(!e||0===e.length)return{};let n={};for(const i of e){if(!st(i,t,o))continue;const e="function"==typeof i.style?i.style(t,o):i.style;e&&(n={...n,...e})}return n}function ct(t,e,o,n=t=>t){const i=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=n(t),a={...i(t,r)};return Object.assign(a,at(s,e,o(s,r))),a}:i}function lt(t,e,o,n){if(!t||0===t.length)return n;const i=it(e,o);return(e,o)=>{const r=e&&e.data||e,s=at(r,t,i(r)),a=n?n(e,o):void 0;return a?{...s,...a}:s}}var ut={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function dt(t,e=ut){if(t)return!0===t?e:"stops"in t?Array.isArray(t.stops)?t:void 0:"colorStops"in t?Array.isArray(t.colorStops)?{stops:t.colorStops.map(({offset:t,color:e})=>({offset:t,color:e}))}:void 0:{stops:[{offset:0,opacity:t.topOpacity??e.stops[0]?.opacity??.8},{offset:1,opacity:t.bottomOpacity??e.stops.at(-1)?.opacity??.05}]}}function ht(t){return t?dt(t):void 0}function ft(t,e,o){return"function"==typeof t?t(o):o[t||e]}function pt(t){return t instanceof Date?t.getTime():Number(t)}function yt(t,e){return L(1===e?.5:t/(e-1))}function gt(t){const e={};return void 0!==t.stroke&&(e.stroke=t.stroke),void 0!==t.strokeWidth&&(e.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(e.opacity=t.opacity),e}function mt(t,e){const o=function(t){if(!t)return;const e="boolean"==typeof t?{}:"string"==typeof t?{method:t}:t;return{type:"trend",method:e.method??"linear",...null!=e.bandwidth&&{bandwidth:e.bandwidth},...null!=e.order&&{order:e.order},...null!=e.color&&{color:e.color},...null!=e.strokeWidth&&{strokeWidth:e.strokeWidth},...null!=e.strokeDasharray&&{strokeDasharray:e.strokeDasharray},...null!=e.label&&{label:e.label}}}(e),n=Array.isArray(t)?t:void 0;return o?[o,...n??[]]:n}var xt=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],bt={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}},vt={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}},wt={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:xt,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 kt(t){if(!t?.colors)return;const e=t.colors;return{primary:e.primary,secondary:e.secondary||e.primary,surface:e.surface||e.background,success:e.success,danger:e.danger,warning:e.warning,error:e.error,info:e.info,text:e.text,textSecondary:e.textSecondary,border:e.border,grid:e.grid}}var At={light:bt,dark:vt,"high-contrast":wt,pastels:{mode:"light",colors:{primary:"#c9a0dc",secondary:"#b8a8c8",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#fdf6f0",surface:"#fff5ee",text:"#4a3728",textSecondary:"#7a644a",grid:"#e8d5c4",border:"#e8d5c4",focus:"#8a5fae",annotation:"#8a5fae",success:"#9ad4a3",danger:"#e8869a",warning:"#f0c888",error:"#c86070",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#fff5ee",text:"#4a3728",borderRadius:"8px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"10px"},"pastels-dark":{mode:"dark",colors:{primary:"#c9a0dc",secondary:"#a899c0",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#1a1525",surface:"#251e35",text:"#e8ddf0",textSecondary:"#a899c0",grid:"#3d3455",border:"#3d3455",focus:"#c9a0dc",annotation:"#c9a0dc",success:"#88d4ab",danger:"#f0a0c0",warning:"#f0c888",error:"#e87690",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#251e35",text:"#e8ddf0",borderRadius:"8px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"10px"},"bi-tool":{mode:"light",colors:{primary:"#2563eb",secondary:"#6b7280",categorical:["#2563eb","#0d9488","#ea580c","#6b7280"],sequential:"blues",background:"#f5f6f8",surface:"#ffffff",text:"#2c3e50",textSecondary:"#64717f",grid:"#d8dce3",border:"#d8dce3",focus:"#2563eb",annotation:"#2563eb",success:"#10b981",danger:"#ef4444",warning:"#f59e0b",error:"#dc2626",info:"#2563eb"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2c3e50",borderRadius:"6px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"8px"},"bi-tool-dark":{mode:"dark",colors:{primary:"#3b82f6",secondary:"#9ca3af",categorical:["#3b82f6","#14b8a6","#f97316","#9ca3af"],sequential:"blues",background:"#111827",surface:"#1f2937",text:"#f3f4f6",textSecondary:"#9ca3af",grid:"#374151",border:"#374151",focus:"#3b82f6",annotation:"#3b82f6",success:"#34d399",danger:"#f87171",warning:"#fbbf24",error:"#ef4444",info:"#60a5fa"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f2937",text:"#f3f4f6",borderRadius:"6px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"8px"},italian:{mode:"light",colors:{primary:"#cc0000",secondary:"#666666",categorical:["#cc0000","#333333","#c8a415","#4682b4"],sequential:"reds",background:"#fafafa",surface:"#ffffff",text:"#1a1a1a",textSecondary:"#666666",grid:"#e0e0e0",border:"#e0e0e0",focus:"#cc0000",annotation:"#cc0000",success:"#556b2f",danger:"#cc0000",warning:"#c8a415",error:"#8b0000",info:"#4682b4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#1a1a1a",borderRadius:"2px",shadow:"0 2px 4px rgba(0, 0, 0, 0.15)"},borderRadius:"2px"},"italian-dark":{mode:"dark",colors:{primary:"#ff3333",secondary:"#aaaaaa",categorical:["#ff3333","#aaaaaa","#d4a843","#6aa4d4"],sequential:"reds",background:"#0a0a0a",surface:"#1a1a1a",text:"#f5f5f5",textSecondary:"#aaaaaa",grid:"#333333",border:"#333333",focus:"#ff3333",annotation:"#ff3333",success:"#7a8b5a",danger:"#ff3333",warning:"#d4a843",error:"#cc0000",info:"#6aa4d4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1a1a1a",text:"#f5f5f5",borderRadius:"2px",shadow:"0 2px 8px rgba(0, 0, 0, 0.5)"},borderRadius:"2px"},tufte:{mode:"light",colors:{primary:"#8b0000",secondary:"#555555",categorical:["#8b4513","#556b2f","#4a5568","#800020"],sequential:"oranges",background:"#fffff8",surface:"#fffff8",text:"#111111",textSecondary:"#555555",grid:"#e0ddd0",border:"#e0ddd0",focus:"#8b0000",annotation:"#8b0000",success:"#556b2f",danger:"#8b0000",warning:"#b88700",error:"#6b0000",info:"#4a5568"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#fffff8",text:"#111111",borderRadius:"2px",shadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},borderRadius:"0px"},"tufte-dark":{mode:"dark",colors:{primary:"#c05050",secondary:"#a09880",categorical:["#c08050","#7a8b5a","#8090a0","#a05060"],sequential:"oranges",background:"#1c1b18",surface:"#262520",text:"#e8e4d8",textSecondary:"#a09880",grid:"#3d3c35",border:"#3d3c35",focus:"#c05050",annotation:"#d06a6a",success:"#7a8b5a",danger:"#c05050",warning:"#c8a060",error:"#a04040",info:"#8090a0"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262520",text:"#e8e4d8",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.4)"},borderRadius:"0px"},journalist:{mode:"light",colors:{primary:"#e45050",secondary:"#666666",categorical:["#3a86c8","#e45050","#d4a843","#888888"],sequential:"blues",background:"#ffffff",surface:"#f8f8f8",text:"#222222",textSecondary:"#666666",grid:"#d4d4d4",border:"#d4d4d4",focus:"#e45050",annotation:"#c63b3b",success:"#2d7a3d",danger:"#c8303a",warning:"#d4a843",error:"#a02028",info:"#3a86c8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:18,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#f8f8f8",text:"#222222",borderRadius:"4px",shadow:"0 2px 6px rgba(0, 0, 0, 0.12)"},borderRadius:"4px"},"journalist-dark":{mode:"dark",colors:{primary:"#ff6b6b",secondary:"#a0a0a0",categorical:["#5a9fd8","#ff6b6b","#e0c060","#aaaaaa"],sequential:"blues",background:"#141414",surface:"#1e1e1e",text:"#ededed",textSecondary:"#a0a0a0",grid:"#383838",border:"#383838",focus:"#ff6b6b",annotation:"#ff6b6b",success:"#6fba78",danger:"#ff6b6b",warning:"#e0c060",error:"#d04040",info:"#5a9fd8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1e1e1e",text:"#ededed",borderRadius:"4px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"4px"},playful:{mode:"light",colors:{primary:"#8b5cf6",secondary:"#7c5a9e",categorical:["#8b5cf6","#ec4899","#06b6d4","#84cc16"],sequential:"viridis",background:"#fdf8ff",surface:"#ffffff",text:"#2d1b4e",textSecondary:"#7c5a9e",grid:"#e8d0f8",border:"#e8d0f8",focus:"#8b5cf6",annotation:"#7a47e8",success:"#10d870",danger:"#ff4b6e",warning:"#ffaa33",error:"#e11d48",info:"#06b6d4"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2d1b4e",borderRadius:"12px",shadow:"0 4px 12px rgba(139, 92, 246, 0.15)"},borderRadius:"12px"},"playful-dark":{mode:"dark",colors:{primary:"#a78bfa",secondary:"#b8a0d8",categorical:["#a78bfa","#f472b6","#22d3ee","#a3e635"],sequential:"viridis",background:"#150a28",surface:"#1f1138",text:"#f0e8ff",textSecondary:"#b8a0d8",grid:"#3a2560",border:"#3a2560",focus:"#a78bfa",annotation:"#a78bfa",success:"#4ade80",danger:"#fb7185",warning:"#fbbf24",error:"#f43f5e",info:"#22d3ee"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f1138",text:"#f0e8ff",borderRadius:"12px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"12px"},carbon:{mode:"light",colors:{primary:"#0f62fe",secondary:"#525252",categorical:["#6929c4","#1192e8","#005d5d","#9f1853"],sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#161616",textSecondary:"#525252",grid:"#e0e0e0",border:"#e0e0e0",focus:"#0f62fe",annotation:"#0f62fe",success:"#24a148",danger:"#da1e28",warning:"#f1c21b",error:"#a2191f",info:"#0043ce"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#161616",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.2)"},borderRadius:"0px"},"carbon-dark":{mode:"dark",colors:{primary:"#4589ff",secondary:"#a8a8a8",categorical:["#a56eff","#33b1ff","#08bdba","#ff7eb6"],sequential:"blues",diverging:"RdBu",background:"#161616",surface:"#262626",text:"#f4f4f4",textSecondary:"#a8a8a8",grid:"#393939",border:"#393939",focus:"#4589ff",annotation:"#4589ff",success:"#42be65",danger:"#fa4d56",warning:"#f1c21b",error:"#da1e28",info:"#4589ff"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262626",text:"#f4f4f4",borderRadius:"2px",shadow:"0 4px 12px rgba(0, 0, 0, 0.5)"},borderRadius:"0px"}};function St(t){if(!t)return bt;if("string"==typeof t){if("light"===t)return bt;if("dark"===t)return vt;if("high-contrast"===t)return wt;return(Object.prototype.hasOwnProperty.call(At,e=t)?At[e]:void 0)||bt}var e;const o="dark"===t.mode?vt:bt;return function(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:xt}}),t.accessibility.highContrast){const t="dark"===e.mode;e={...e,colors:{...e.colors,text:t?"#ffffff":"#000000",textSecondary:t?"#cccccc":"#333333",grid:t?"#666666":"#999999",border:t?"#888888":"#000000"}}}return e}({...o,...t,colors:{...o.colors,...t.colors||{}},typography:{...o.typography,...t.typography||{}},tooltip:{...o.tooltip,...t.tooltip||{}}})}function Mt(t){return{background:t.colors.background,text:t.colors.text,textSecondary:t.colors.textSecondary,grid:t.colors.grid,border:t.colors.border,primary:t.colors.primary,fontFamily:t.typography.fontFamily,titleSize:t.typography.titleSize,labelSize:t.typography.labelSize,tickSize:t.typography.tickSize,categorical:t.colors.categorical,annotation:t.colors.annotation??t.colors.text,legendSize:t.typography.legendSize??t.typography.labelSize,legendFontFamily:t.typography.legendFontFamily??t.typography.fontFamily,legendFontWeight:t.typography.legendFontWeight,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,titleFontFamily:t.typography.titleFontFamily??t.typography.fontFamily,titleFontWeight:t.typography.titleFontWeight??"bold",tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}function _t(t,e,o){const n="function"==typeof e?e(t):t[e??o];if(null==n)return null;if(n instanceof Date)return n.getTime();if("string"==typeof n&&""===n.trim())return null;const i=Number(n);return Number.isFinite(i)?i:null}function Pt(t){let e=1/0,o=-1/0;for(const n of t)e>n&&(e=n),n>o&&(o=n);return[e,o]}function Lt(t,e=-1/0){let o=e;for(const e of t)e>o&&(o=e);return o}function $t(t){return Math.round(100*t)/100}function Rt(t,e=2){const o=[],n=[],i=e+1;for(let e=0;i>e;e++){let r=0;for(const[o,n]of t)null!==n&&(r+=o**e*n);o.push(r);const s=[];for(let o=0;i>o;o++){let n=0;for(const[i,r]of t)null!==r&&(n+=i**(e+o));s.push(n)}n.push(s)}n.push(o);const r=function(t,e){const o=t,n=t.length-1,i=[e];for(let t=0;n>t;t++){let e=t;for(let i=t+1;n>i;i++)Math.abs(o[t][i])>Math.abs(o[t][e])&&(e=i);for(let i=t;n+1>i;i++){const n=o[i][t];o[i][t]=o[i][e],o[i][e]=n}for(let e=t+1;n>e;e++)for(let i=n;i>=t;i--)o[i][e]-=o[i][t]*o[t][e]/o[t][t]}for(let t=n-1;t>=0;t--){let e=0;for(let r=t+1;n>r;r++)e+=o[r][t]*i[r];i[t]=(o[n][t]-e)/o[t][t]}return i}(n,i).map($t);return{points:t.map(([t])=>[$t(t),$t(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function Tt(t){const e=t.length;let o=0,n=0,i=0,r=0;for(const[e,s]of t)o+=e,n+=s,i+=e*e,r+=e*s;const s=e*i-o*o;if(1e-12>Math.abs(s))return null;const a=(e*r-o*n)/s,c=(n-a*o)/e;return t=>c+a*t}function It(t,e){const o=t.length,n=t.map(([t,o])=>o-e(t)).reduce((t,e)=>t+e*e,0),i=Math.sqrt(n/Math.max(o-2,1)),r=t.reduce((t,e)=>t+e[0],0)/o,s=t.reduce((t,e)=>t+(e[0]-r)**2,0);return{se:i,meanX:r,ssX:s}}function Ct(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Ot="__forecastSegment",Ft="__forecastOpacity";function Dt(t,e,o,n){const i=e.uncertaintyOpacity,r=e.confidenceAccessor;if(!i&&!r)return;const s="object"==typeof i?i:{},a=s.min??.15,c=s.max??1;if(r){const e="function"==typeof r?r:t=>t[r];for(const o of t){const t=e(o);null!=t&&Number.isFinite(t)&&(o[Ft]=a+Math.max(0,Math.min(1,t))*(c-a))}return}const l=t.map(t=>{const e=o(t),i=n(t);return null!=e&&null!=i&&Number.isFinite(e)&&Number.isFinite(i)?Math.abs(e-i):NaN}),u=l.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=Pt(u),f=h-d;t.forEach((t,e)=>{const o=l[e];Number.isFinite(o)&&(t[Ft]=c-(f>0?(o-d)/f:0)*(c-a))})}function zt(t,e){return"function"==typeof e?e(t):!!t[e]}var Nt="__semiotic_resolvedX",Et="__semiotic_resolvedY",Bt="__compoundGroup";function Wt(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function jt(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?g(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,o){const n="function"==typeof e,i="function"==typeof o,r=n?Nt:e,s=i?Et:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[Nt]=e(t)),i&&(r[Et]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,c=s.yKey,l=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d="string"==typeof n||"function"==typeof n?n:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,o,n,i){return(r=n).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,o,n,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:c,lowerBounds:l,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=n,y=t.map(t=>{let e="observed";return s&&zt(t,s)?e="forecast":r&&zt(t,r)&&(e="training"),{...t,[Ot]:e}}),g=n._groupBy,m=[];if(g){const t=new Map;for(const e of y){const o=e[g]??"__default";t.has(o)||t.set(o,[]),t.get(o).push(e)}const e=[];for(const[,o]of t)for(let t=0;o.length-1>t;t++)o[t][Ot]!==o[t+1][Ot]&&(e.push({...o[t+1],[Ot]:o[t][Ot]}),e.push({...o[t],[Ot]:o[t+1][Ot]}));m.push(...y,...e)}else for(let t=0;y.length>t;t++)m.push(y[t]),y.length-1>t&&y[t][Ot]!==y[t+1][Ot]&&(m.push({...y[t+1],[Ot]:y[t][Ot]}),m.push({...y[t],[Ot]:y[t+1][Ot]}));if(n.trainUnderline){const t=[];for(const e of m)"training"===e[Ot]&&t.push({...e,[Ot]:"training-base"});m.unshift(...t)}const x=[];if(c&&l){const t="string"==typeof c?c:"__envUpper",e="string"==typeof l?l:"__envLower";if("function"==typeof c||"function"==typeof l)for(const o of m)"function"==typeof c&&(o[t]=c(o)),"function"==typeof l&&(o[e]=l(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:p})}if(n.uncertaintyOpacity||n.confidenceAccessor){const t=c?"function"==typeof c?c:t=>t[c]:()=>{},e=l?"function"==typeof l?l:t=>t[l]:()=>{};Dt(m.filter(t=>"forecast"===t[Ot]),n,t,e)}if(a){const t=n.anomalyStyle,e={type:"highlight",filter:t=>zt(t,a)};t?(e.style=t,e.r=f):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=f):(e.color=h,e.r=f,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(e)}return i&&x.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label}),{processedData:m,annotations:x}}(t,0,0,n,i):function(t,e,o,n,i){const{trainEnd:r,steps:s=10,confidence:a=.95,color:c="#6366f1",bandOpacity:l=.15,label:u}=n;if(null==r)return{processedData:t,annotations:[]};const d=[],h=[];for(const o of t)o[e]>r?h.push({...o,[Ot]:"observed"}):d.push({...o,[Ot]:"training"});const f=d.map(t=>[t[e],t[o]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),p=[],y=[];if(f.length>=3){const i=f.length,r=Tt(f);if(r){const{se:d,meanX:h,ssX:g}=It(f,r),m=Ct(a),x=Lt(t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t))),b=f.length>1?(f[i-1][0]-f[0][0])/(i-1):1;for(let t=1;s>=t;t++){const n=x+t*b,s=r(n),a=d*Math.sqrt(1+1/i+(g>0?(n-h)**2/g:0))*m;y.push({[e]:n,[o]:s,[Ot]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}Dt(y,n,t=>t.__forecastUpper,t=>t.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:c,fillOpacity:l,label:u})}}p.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&p.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const g=[];if(g.push(...d),d.length>0&&h.length>0&&g.push({...d[d.length-1],[Ot]:"observed"}),g.push(...h),y.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&g.push({...t,[Ot]:"forecast"}),g.push(...y)}return{processedData:g,annotations:p}}(t,e,o,n,i);var r}(r,a,c,n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,t.anomaly);if(r=e.processedData,l.push(...e.annotations),u=function(t,e,o){const n=o.upperBounds,i=o.lowerBounds;if(!n&&!i)return;const r="function"==typeof n?n:"string"==typeof n?t=>t[n]:null,s="function"==typeof i?i:"string"==typeof i?t=>t[i]:null;let a=1/0,c=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>c&&(c=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>c&&(c=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>c&&(c=t))}}return Number.isFinite(a)&&Number.isFinite(c)?[a,c]:void 0}(r,c,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[Bt]:`${t[n]}__${t[Ot]||"observed"}`})),d=Bt):d=Ot,t.baseLineStyle){const e=function(t,e){const o=e.trainDasharray??"8,4",n=e.forecastDasharray??"4,4",i=e.color||"#6366f1",r=e.trainOpacity,s=e.forecastOpacity,a=e.trainStroke,c=e.trainLinecap,l=e.trainUnderline;return e=>{const u=t(e),d=e[Ot];if("training"===d){let t=u.stroke;return"darken"===a?t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const n=Math.round(parseInt(o[1],16)*(1-e)),i=Math.round(parseInt(o[2],16)*(1-e)),r=Math.round(parseInt(o[3],16)*(1-e));return`#${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):a&&(t=a),{...u,stroke:t,strokeDasharray:o,...c&&{strokeLinecap:c},...null!=r&&{strokeOpacity:r}}}if("training-base"===d){let t=u.stroke||"#666";return"lighten"===l&&(t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const n=Math.round(parseInt(o[1],16)+(255-parseInt(o[1],16))*e),i=Math.round(parseInt(o[2],16)+(255-parseInt(o[2],16))*e),r=Math.round(parseInt(o[3],16)+(255-parseInt(o[3],16))*e);return`#${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(t,.4)),{...u,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Ft],o=null!=t?t:s;return{...u,stroke:i,strokeDasharray:n,...null!=o&&{strokeOpacity:o}}}return u}}(e=>t.baseLineStyle(e),t.forecast);h=t=>e(t)}}else t.anomaly&&l.push(...(f=t.anomaly,[{type:"anomaly-band",threshold:f.threshold??2,showBand:!1!==f.showBand,fill:f.bandColor||"#6366f1",fillOpacity:f.bandOpacity??.1,anomalyColor:f.anomalyColor||"#ef4444",anomalyRadius:f.anomalyRadius??6,label:f.label}]));var f;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,o,n,i){const r=new Map;for(const e of t){const t=i?(e[i]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const i of e)Wt(i,o,n)||t.push(i);return{rows:t,groupKey:i}}if("zero"===e){const t=[];for(const[,e]of r)for(const i of e)Wt(i,o,n)?t.push({...i,[n]:0}):t.push(i);return{rows:t,groupKey:i}}const s=[],a="_gapSegment";for(const[t,e]of r){let i=0,r=[];const c=()=>{if(0===r.length)return;const e="__single"===t?"__seg"+i:`${t}__seg${i}`;for(const t of r)s.push({...t,[a]:e});r=[],i++};for(const t of e)Wt(t,o,n)?c():r.push(t);c()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,c,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let p;if(t.directLabel){const e=function(t,e,o,n,i,r,s,a){if(!e||!o)return{annotations:[]};const c="object"==typeof e?e:{},l=c.position||"end",u=c.fontSize||11,d="function"==typeof o?o:t=>t[o],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const o=t+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(e))}const f=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[n])-Number(e[n])),f.set(t,"end"===l?e[e.length-1]:e[0]);const p=Q(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),y=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===l?6:-6,dy:0,color:p?K({__lbl:t},"__lbl",p):a||q,fontSize:u}));y.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;y.length>t;t++){const e=y[t-1],o=y[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const g=y.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:y,marginExtra:"end"===l?{right:g}:{left:g}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,c,t.colorScheme,t.themeCategorical,t.color);l.push(...e.annotations),p=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?c:o,groupAccessor:d,colorAccessor:i,annotations:l,lineStyle:h,yExtent:u,marginExtra:p}}function Yt(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=St(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrScatterColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?Pt(f):void 0,y=nt(i.xAccessor,i.yAccessor),g=i.styleRules;return t=>{const o={fill:e&&u?K(t,e,u):"string"==typeof i.color?i.color:q,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?J(t,d,h,p):"number"==typeof i.pointRadius?i.pointRadius:5};return g?.length&&Object.assign(o,at(t,g,y(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}var Xt={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=jt({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:St(n.theme).colors.categorical}),s=mt(r.annotations,i.regression);return{chartType:"scatter",data:r.data,xAccessor:r.xAccessor,yAccessor:r.yAccessor,colorAccessor:e,sizeAccessor:i.sizeBy,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,...s&&s.length>0&&{annotations:s},...r.yExtent&&!n.yExtent&&{yExtent:r.yExtent},sizeRange:i.sizeRange||[3,15],pointStyle:n.pointStyle||Yt(t,e,o,n,i),showLegend:n.showLegend??!!e}}},qt={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=mt(n.annotations,i.regression);return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:o,...n,...r&&{annotations:r},pointStyle:n.pointStyle||Gt(t,e,o,n,i),showLegend:n.showLegend??!!e}}};function Gt(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=St(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrBubbleColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?Pt(f):void 0,y=nt(i.xAccessor,i.yAccessor),g=i.styleRules;return t=>{const o={fill:e&&u?K(t,e,u):"string"==typeof i.color?i.color:q,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?J(t,d,h,p):h[0],stroke:i.bubbleStrokeColor??"white",strokeWidth:i.bubbleStrokeWidth??1};return g?.length&&Object.assign(o,at(t,g,y(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}import{useMemo as Vt,useCallback as Ht,useState as Ut,useId as Kt,useEffect as Zt,useRef as Qt}from"react";var Jt="__semioticSelectionData";function te(t,e){return e?.length?(Object.defineProperty(t,Jt,{configurable:!0,enumerable:!1,value:e}),t):t}function ee(t){return t?.[Jt]}function oe(t){const e={"--semiotic-bg":t.colors.background,"--semiotic-text":t.colors.text,"--semiotic-text-secondary":t.colors.textSecondary,"--semiotic-grid":t.colors.grid,"--semiotic-border":t.colors.border,"--semiotic-cell-border":t.colors.cellBorder||t.colors.border,"--semiotic-primary":t.colors.primary,"--semiotic-font-family":t.typography.fontFamily,"--semiotic-secondary":t.colors.secondary||t.colors.primary,"--semiotic-surface":t.colors.surface||t.colors.background};t.colors.categorical.forEach((t,o)=>{e["--semiotic-category-"+(o+1)]=t}),t.colors.focus&&(e["--semiotic-focus"]=t.colors.focus),t.colors.selection&&(e["--semiotic-selection-color"]=t.colors.selection),null!=t.colors.selectionOpacity&&(e["--semiotic-selection-opacity"]=t.colors.selectionOpacity+""),t.colors.diverging&&(e["--semiotic-diverging"]=t.colors.diverging),t.colors.annotation&&(e["--semiotic-annotation-color"]=t.colors.annotation),t.colors.success&&(e["--semiotic-success"]=t.colors.success),t.colors.danger&&(e["--semiotic-danger"]=t.colors.danger),t.colors.warning&&(e["--semiotic-warning"]=t.colors.warning),t.colors.error&&(e["--semiotic-error"]=t.colors.error),t.colors.info&&(e["--semiotic-info"]=t.colors.info),t.tooltip?.background&&(e["--semiotic-tooltip-bg"]=t.tooltip.background),t.tooltip?.text&&(e["--semiotic-tooltip-text"]=t.tooltip.text),t.tooltip?.borderRadius&&(e["--semiotic-tooltip-radius"]=t.tooltip.borderRadius),t.tooltip?.fontSize&&(e["--semiotic-tooltip-font-size"]=t.tooltip.fontSize),t.tooltip?.shadow&&(e["--semiotic-tooltip-shadow"]=t.tooltip.shadow),t.borderRadius&&(e["--semiotic-border-radius"]=t.borderRadius);const o=t.typography.legendSize??t.typography.labelSize;null!=o&&(e["--semiotic-legend-font-size"]=o+"px"),null!=t.typography.legendFontFamily&&(e["--semiotic-legend-font-family"]=t.typography.legendFontFamily),null!=t.typography.legendFontWeight&&(e["--semiotic-legend-font-weight"]=t.typography.legendFontWeight+"");const n=t.typography.titleFontSize??t.typography.titleSize;return null!=n&&(e["--semiotic-title-font-size"]=n+"px"),null!=t.typography.titleFontFamily&&(e["--semiotic-title-font-family"]=t.typography.titleFontFamily),null!=t.typography.titleFontWeight&&(e["--semiotic-title-font-weight"]=t.typography.titleFontWeight+""),null!=t.typography.tickFontFamily&&(e["--semiotic-tick-font-family"]=t.typography.tickFontFamily),null!=t.typography.tickSize&&(e["--semiotic-tick-font-size"]=t.typography.tickSize+"px"),null!=t.typography.labelSize&&(e["--semiotic-axis-label-font-size"]=t.typography.labelSize+"px"),e}function ne(...t){let e;for(const o of t)o&&(e=ie(e)&&ie(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function ie(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function re(t){return"object"==typeof t&&null!==t&&"gradient"in t}function se(t){return"string"==typeof t&&t.length>0}function ae(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function ce(t,e){return ae(t,se(e))}function le(t,e,o,n,i=8){const r=n,s="left"===n?"right":"right"===n?"left":"top"===n?"bottom":"top",a=Math.max(e[r],Math.max(0,("left"===n||"right"===n?o[0]:o[1])-i)-t[s]);t[r]>a&&(t[r]=a)}function ue(t){return Math.ceil(7*t.length)}function de(t,e){if(ie(t)){const o=ke(e),n=t.legendGroups.flatMap(t=>[t.label?ue(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+ue(t.label))]);return Math.max(100,...n)}if(re(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),n=Math.max(ue(o(e.domain[0])),ue(o(e.domain[1]))),i=e.label?ue(e.label):0;return Math.max(100,19+n,i)}return 100}function he(t){return(ie(t)||re(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function fe(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?ge:ye:0}function pe(t){return Math.max(0,t?.edgeGutter??3)}var ye=34,ge=70;function me(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function xe(t,e,o){if(re(t))return t.gradient.label?46:26;if(!ie(t))return 20;const n=ke(o),i=Math.max(1,o?.maxWidth??e);let r=n.rowHeight;for(const e of t.legendGroups){let t=0,o=0;for(const r of e.items){const e=n.swatchSize+n.labelGap+ue(r.label),s=0===o?e:o+n.itemGap+e;o>0&&s>i?(t+=1,o=e):o=s}e.items.length>0&&(t+=1),r=Math.max(r,t*n.rowHeight,e.label?ue(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function be(t,e,o){return de(t,e)+he(t)+fe(e,o)+pe(e)}function ve(t,e){const{legend:o}=e;if(!o)return;const n=e.position??"right",i=xe(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+he(o)+me("bottom"===n?e.axisChrome:"top"===n?e.axisChrome?.topAxis:void 0,e.legendLayout)+("top"===n&&e.hasTitle?24:0),r=Math.max(e.minimumMargin??0,"top"===n?e.hasTitle?58:34:0);"right"===n?t.right=Math.max(t.right,r,be(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===n?t.left=Math.max(t.left,r,be(o,e.legendLayout,e.axisChrome?.leftAxis)):"top"===n?t.top=Math.max(t.top,r,i):t.bottom=Math.max(t.bottom,r,i)}function we(t,e){const o=e.position??"right",n="top"===o||"bottom"===o,i=Math.max(0,e.totalWidth-e.margin.left-e.margin.right),r=Math.max(1,n?e.legendLayout?.maxWidth??i:e.reservedWidth??de(t,e.legendLayout)),s=he(t),a=fe(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),c=pe(e.legendLayout),l=xe(t,i,e.legendLayout),u=me(e.axisChrome,e.legendLayout),d=me(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(c,e.margin.left-a-r-s),y:e.margin.top,width:r,height:l};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-l,width:r,height:l};if("bottom"===o){const t=e.totalHeight-e.margin.bottom;return{x:e.margin.left,y:Math.max(t+s,Math.min(t+u+s,e.totalHeight-l)),width:r,height:l}}return{x:Math.min(e.totalWidth-r-c,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:l}}function ke(t){const e=Math.max(1,t?.swatchSize??16),o=Math.max(e,t?.rowHeight??22);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??6),itemGap:Math.max(0,t?.itemGap??10),rowHeight:o,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function Ae(t,e){let o=24;return t.map(({hasLabel:t,itemCount:n})=>{o+=5;const i=o;let r;o+=8,t&&(o+=16,r=o,o+=8);const s=o;return o+=n*e+8,{lineY:i,labelY:r,itemsY:s,endY:o}})}function Se(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=Z(o,n);if(t)return t}let r;if(Array.isArray(o))r=o;else if(e&&e.length>0)r=e;else if("string"==typeof o){const t=Y[o];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=n?(i.has(n)||i.set(n,i.size),r[i.get(n)%r.length]):r[0]:q}function Me(t,e,o){return"function"==typeof t?t(e,o):e[t]}function _e(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[r(t),e]));return t.map(t=>{const e={...t},n=n=>{if(!(n in t))return;const i=o.get(r(t[n]));void 0!==i&&(e[n]=i)};return n("x"),n("x0"),n("x1"),"string"!=typeof t.type||"x-threshold"!==t.type&&"x"!==t.type||n("value"),e})}import*as Pe from"react";import{jsx as Le}from"react/jsx-runtime";var $e,Re={isActive:!1,predicate:()=>!0};function Te(t,e,o,n,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*o+i*i*i*n}function Ie(t,e,o,n,i){const r=1-i;return 3*r*r*(e-t)+6*r*i*(o-e)+3*i*i*(n-o)}function Ce(t,e,o,n,i){const r=[],s=(t.x+e.x)/2;for(let a=0;i>=a;a++){const c=a/i;let l,u,d,h;"linear"===n?(l=t.x+(e.x-t.x)*c,u=t.y+(e.y-t.y)*c,d=e.x-t.x,h=e.y-t.y):(l=Te(t.x,s,s,e.x,c),u=Te(t.y,t.y,e.y,e.y,c),d=Ie(t.x,s,s,e.x,c),h=Ie(t.y,t.y,e.y,e.y,c)),r.push({x:l,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*c,datumIndex:.5>c?o:o+1})}return r}function Oe(t,e={}){const o=[],n=[],i=[];if(2>t.length)return{topPath:o,bottomPath:n,datumIndices:i};const r=e.curve??"smooth",s=Math.max(2,Math.floor(e.samplesPerSegment??12));for(let e=0;t.length-1>e;e++){const a=Ce(t[e],t[e+1],e,r,s);for(let t=0===e?0:1;a.length>t;t++){const e=a[t],r=Math.hypot(e.dx,e.dy)||1,s=-e.dy/r,c=e.dx/r,l=Math.max(0,e.radius);o.push([e.x+s*l,e.y+c*l]),n.push([e.x-s*l,e.y-c*l]),i.push(e.datumIndex)}}return{topPath:o,bottomPath:n,datumIndices:i}}import{jsx as Fe}from"react/jsx-runtime";function De({datum:t,x:e,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=function(){const t=($e??($e=Pe.createContext(null)),$e);return Pe.useContext(t)??Re}(),c=a.isActive&&!a.predicate(t),l="function"==typeof s?s(t.__bumpRaw):s;return Fe("text",{className:"semiotic-bump-label",x:e+("end"===n?8:-8),y:o,dy:"0.35em",textAnchor:"end"===n?"start":"end",fill:i,fillOpacity:c?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...l},children:t.__bumpSeries})}function ze(t,e,o){const[n,i]=e,[r,s]=o;return i===n?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(t-n)/(i-n)))}function Ne(t){const e=t.__bumpXValue instanceof Date?t.__bumpXValue.getTime():Number(t.__bumpXValue);return{value:t.__bumpValue,x:Number.isFinite(e)?e:void 0,y:t.__bumpValue,category:t.__bumpSeries}}function Ee(t){const e=t.config,o=new Map;for(const e of t.data){const t=o.get(e.__bumpSeries)??[];t.push(e),o.set(e.__bumpSeries,t)}const n=e.seriesOrder.filter(t=>o.has(t)).sort((t,n)=>(o.get(t)?.[0]?.__bumpHighlighted?1:0)-(o.get(n)?.[0]?.__bumpHighlighted?1:0)||e.seriesOrder.indexOf(t)-e.seriesOrder.indexOf(n)),i=[],r=[],s=[];for(const r of n){const n=(o.get(r)??[]).sort((t,e)=>t.x-e.x);if(2>n.length)continue;const a=n[0].__bumpHighlighted,c=(e.colorMap&&Z(e.colorMap,r))??t.resolveColor(n[0].__bumpSeries,n[0]),l=e.color??(a?c:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??c),u=n.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?ze(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=Oe(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:l,fillOpacity:1,opacity:a?e.ribbon?e.ribbonOpacity:e.lineOpacity:Math.min(e.ribbon?e.ribbonOpacity:e.lineOpacity,.58)};e.styleRules?.length&&Object.assign(h,at(n[0].__bumpRaw,e.styleRules,Ne(n[0]))),e.areaStyle&&Object.assign(h,e.areaStyle(n[0].__bumpRaw)??{}),void 0!==e.stroke&&(h.stroke=e.stroke),void 0!==e.strokeWidth&&(h.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(h.opacity=e.opacity),i.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:h,datum:d.datumIndices.map(t=>n[t]),accessibleDatum:n.map(t=>t.__bumpRaw),accessibility:{label:r+" ranking trajectory",tableFields:n.map(t=>t.__bumpRaw)},group:r,interactive:!0}),e.showPoints&&n.forEach((t,o)=>{const n={fill:l,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(n,at(t.__bumpRaw,e.styleRules,Ne(t))),e.pointStyle&&Object.assign(n,e.pointStyle(t.__bumpRaw)??{}),void 0!==e.stroke&&(n.stroke=e.stroke),void 0!==e.strokeWidth&&(n.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(n.opacity=e.opacity),i.push({type:"point",x:u[o].x,y:u[o].y,r:n.r??e.pointRadius,style:n,datum:t,accessibleDatum:t.__bumpRaw,accessibility:{label:`${r}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${r}:${t.x}`})});const f=!0===e.showLabels?"end":e.showLabels,p=(t,o,n)=>{const i=null==e.labelPriorityAccessor?void 0:"function"==typeof e.labelPriorityAccessor?e.labelPriorityAccessor(t.__bumpRaw):Number(t.__bumpRaw[e.labelPriorityAccessor]);s.push({id:`${r}\0${n}`,datum:t,x:u[o].x,y:u[o].y,side:n,rank:t.__bumpRank,highlighted:a,priority:Number.isFinite(i)?i:void 0,color:"string"==typeof h.fill?h.fill:l})};"start"!==f&&"both"!==f||p(n[0],0,"start"),"end"!==f&&"both"!==f&&"auto"!==f||p(n.at(-1),n.length-1,"end")}const a=function(t,e,o,n){const i=Math.max(1,Math.floor(e/18)),r="auto"===o?Number.isFinite(n)&&(n??0)>=0?Math.min(i,Math.floor(n)):i:1/0,s=t.map((t,e)=>({candidate:t,index:e})).sort((t,e)=>(e.candidate.priority??0)-(t.candidate.priority??0)||Number(e.candidate.highlighted)-Number(t.candidate.highlighted)||t.candidate.rank-e.candidate.rank||t.index-e.index),a=[];for(const{candidate:t}of s){if(a.length>=r)break;a.some(e=>e.side===t.side&&14>Math.abs(e.y-t.y))||a.push(t)}return new Set(a.map(t=>t.id))}(s,t.dimensions.plot.height,"auto"!==(!0===e.showLabels?"end":e.showLabels)||"auto",e.maxLabels);for(const t of s)a.has(t.id)&&r.push(Fe(De,{datum:t.datum,x:t.x,y:t.y,side:t.side,color:t.color,highlighted:t.highlighted,labelStyle:e.labelStyle},t.id));return{nodes:i,overlays:r.length?Fe("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(t,e)=>{const o=function(t){const e=Array.isArray(t.datum)?t.datum[0]:t.datum;return e&&"object"==typeof e&&"__bumpSeries"in e?e:void 0}(t);if(e?.isActive&&o&&!e.predicate(o))return{opacity:.14}}}}var Be={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,n,i)=>{const s=function(t,e={}){const o=e.xAccessor??"x",n=e.yAccessor??"y",i=e.lineBy??"series",s=e.rankDirection??"descending",a=[],c=new Map,l=new Map,u=[],d=new Map;let h=1/0,f=-1/0;t.forEach((t,e)=>{const s=Me(o,t,e),p=r(s);let y=c.get(p);null==y&&(y=a.length,c.set(p,y),a.push(s),l.set(y,[]));const g=Me(i,t,e)+"";d.has(g)||(d.set(g,u.length),u.push(g));const m=Number(Me(n,t,e));Number.isFinite(m)&&(h=Math.min(h,m),f=Math.max(f,m),l.get(y)?.push({datum:t,inputIndex:e,series:g,value:m}))});const p=[],y=new Map,g=new Map;for(let t=0;a.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===s?e.value-t.value:t.value-e.value)||(d.get(t.series)??0)-(d.get(e.series)??0)),e.forEach((e,o)=>{const n=o+1;p.push({datum:e.datum,xIndex:t,xValue:a[t],series:e.series,value:e.value,rank:n}),y.set(e.series,(y.get(e.series)??0)+n),g.set(e.series,(g.get(e.series)??0)+1)})}const m=u.length+1,x=[...u].sort((t,e)=>{const o=g.get(t)??0,n=g.get(e)??0;return((y.get(t)??0)+(a.length-o)*m)/Math.max(1,a.length)-((y.get(e)??0)+(a.length-n)*m)/Math.max(1,a.length)||(d.get(t)??0)-(d.get(e)??0)}),b=new Set(x.slice(0,null==e.highlightTop?x.length:Math.max(0,Math.floor(e.highlightTop))));return{data:p.map(t=>{const e=b.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:a,seriesOrder:u,overallOrder:x,valueExtent:h===1/0?[0,0]:[h,f]}}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],{xAccessor:i.xAccessor,yAccessor:i.yAccessor,lineBy:i.lineBy,rankDirection:i.rankDirection,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0}),a=Math.max(1,s.seriesOrder.length),c=St(n.theme),l=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:n,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:c}=t;if(null==n&&null==i)return r;const l=new Set(o.slice(0,null==n?o.length:Math.max(0,Math.floor(n)))),u=new Map,d={};for(const t of e)Object.defineProperty(d,t,{configurable:!0,enumerable:!0,writable:!0,value:i??(l.has(t)?Se(void 0,a,r,t,u):s??c??"#b8bec8")});return d}({seriesOrder:s.seriesOrder,overallOrder:s.overallOrder,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0,color:"string"==typeof i.color?i.color:void 0,colorScheme:o,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,themeCategorical:c.colors.categorical,themeNeutral:c.colors.textSecondary}),u={ribbon:!0===i.ribbon,curve:"linear"===i.curve?"linear":"smooth",samplesPerSegment:"number"==typeof i.samplesPerSegment?i.samplesPerSegment:12,ribbonSizeRange:Array.isArray(i.ribbonSizeRange)?i.ribbonSizeRange:[4,28],valueExtent:s.valueExtent,seriesOrder:s.seriesOrder,lineWidth:"number"==typeof i.lineWidth?i.lineWidth:3,ribbonOpacity:"number"==typeof i.ribbonOpacity?i.ribbonOpacity:.82,lineOpacity:"number"==typeof i.lineOpacity?i.lineOpacity:.9,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,color:"string"==typeof i.color?i.color:void 0,colorMap:l&&"object"==typeof l&&!Array.isArray(l)?l:void 0,stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0,styleRules:i.styleRules,areaStyle:n.areaStyle,pointStyle:n.pointStyle,labelStyle:i.labelStyle,showPoints:!0===i.showPoints,pointRadius:"number"==typeof i.pointRadius?i.pointRadius:3,showLabels:i.showLabels??!0,labelPriorityAccessor:i.labelPriorityAccessor,maxLabels:"number"==typeof i.maxLabels?i.maxLabels:void 0},d=n.xFormat,h=(t,e)=>{if(0===s.xValues.length)return"";const o=s.xValues[Math.max(0,Math.min(s.xValues.length-1,Math.round(Number(t))))];return d?d(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},f=s.xValues.map((t,e)=>e),p=Array.from({length:a},(t,e)=>e+1),y=n.axes??[{orient:"left",tickValues:p,tickFormat:t=>t+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:f,tickFormat:h,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:s.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,s.xValues.length-1)],yExtent:[a+.5,.5],customLayout:Ee,layoutConfig:u,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:h,axes:y,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:_e(n.annotations,s.xValues)}}},We="__ma_unitized",je="__ma_series",Ye={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=Array.isArray(i.series)?i.series:[],a=Array.isArray(o)?o:[...X],c=s.some(t=>"string"==typeof t.color)?s.map((t,e)=>t.color||a[e%a.length]):o,l=2===s.length,u=s.map(t=>t.extent||function(t,e){const o="function"==typeof e?e:t=>Number(t[e||"y"]);let n=1/0,i=-1/0;for(const e of t){const t=o(e);"number"==typeof t&&Number.isFinite(t)&&(n>t&&(n=t),t>i&&(i=t))}if(!Number.isFinite(n)||!Number.isFinite(i))return[0,1];if(n===i){const t=0===n?1:.1*Math.abs(n);return[n-t,i+t]}return[n,i]}(r,t.yAccessor)),d=[];for(const t of r)s.forEach((e,o)=>{const n=("function"==typeof e.yAccessor?e.yAccessor:t=>t[e.yAccessor])(t);if(null==n||!Number.isFinite(Number(n)))return;const i=Number(n),r=u[o],s=r[1]-r[0]||1;d.push({...t,[We]:l?(i-r[0])/s:i,[je]:e.label||"Series "+(o+1)})});const h=(t,e)=>o=>{const n=t[0]+o*(t[1]-t[0]);return"function"==typeof e?e(n):Number.isInteger(n)?n+"":n.toFixed(1)},f=l?[{orient:"left",label:s[0].label,tickFormat:h(u[0],s[0].format)},{orient:"right",label:s[1].label,tickFormat:h(u[1],s[1].format)},{orient:"bottom"}]:void 0;return{chartType:"line",data:d,xAccessor:i.xAccessor||"x",yAccessor:We,groupAccessor:je,colorAccessor:je,colorScheme:c,...f&&{axes:f},...l&&{yExtent:[0,1]},...n,curve:i.curve||n.curve||"monotoneX",showLegend:n.showLegend??!0}}},Xe={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=i.xAccessor||"x",a="function"==typeof s?s:t=>t[s],c=r.some(t=>{const e=a(t);return!("number"==typeof e&&Number.isFinite(e)||e instanceof Date)}),l=c?r.map((t,e)=>({...t,__waterfallX:e,__waterfallTick:(a(t)??e)+""})):r;return{chartType:"waterfall",data:l,xAccessor:c?"__waterfallX":s,yAccessor:i.yAccessor||"y",waterfallStyle:{positiveColor:i.positiveColor,negativeColor:i.negativeColor,connectorStroke:i.connectorStroke,connectorWidth:i.connectorWidth,gap:i.gap,stroke:i.stroke,strokeWidth:i.strokeWidth,opacity:i.opacity},...n,...c&&{axes:n.axes??[{orient:"bottom",tickValues:l.map((t,e)=>e)}],xFormat:t=>{const e=r[Number(t)]?a(r[Number(t)]):t,o=i.xFormat??n.xFormat;return"function"==typeof o?o(e):(e??t)+""}}}}};function qe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=St(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrAreaColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,f="number"==typeof i.areaOpacity?i.areaOpacity:.7,p=ot(i.yAccessor),y=i.styleRules;return(t,o)=>{const n=e&&u?K(t,e,u):"string"==typeof i.color?i.color:q,r={fill:n,fillOpacity:f,stroke:d?n:"none",...d&&{strokeWidth:h}};return y?.length&&Object.assign(r,at(t,y,{value:p(t),category:o})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function Ge(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=St(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrPointColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?K(t,e,u):"string"==typeof i.color?i.color:q;return{r:d,fill:o,stroke:"none"}}}var Ve={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",c=St(n.theme).colors.categorical,l=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=St(n.theme).colors.categorical,a=o??n.colorScheme??s,c="string"==typeof e?e:"__ssrLineColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?Q(l,c,a):void 0,d=nt(i.xAccessor,i.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:n,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:c,ruleContext:l}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let f;return r?f=r(t,u):o?n&&(f=K(t,o,n)):f=i||q,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),c?.length&&Object.assign(d,at(t,c,l?l(t,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof i.lineWidth?i.lineWidth:2,colorBy:e,colorScale:u,color:"string"==typeof i.color?i.color:void 0,fillArea:i.fillArea,areaOpacity:"number"==typeof i.areaOpacity?i.areaOpacity:.3,styleRules:i.styleRules,ruleContext:d});return et(h,{stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0})}(t,r,o,n,i),u=jt({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:n.annotations,themeCategorical:c,baseLineStyle:l}),d=n.pointStyle||Ge(u.data,u.colorAccessor,o,n,i);let h=n.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const f=(!i.directLabel||void 0!==n.showLegend)&&(n.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||l,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...n,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!n.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},He={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?g(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",c=i.categoryAccessor,l=i.valueExtent||n.yExtent,u="down"===i.direction?function({data:t,valueAccessor:e,timeAccessor:o,binSize:n,valueExtent:i,extentPadding:r}){if(i)return[i[1],i[0]];if(!t||0===t.length)return;const s=new Map;for(const i of t){const t=_t(i,o,"time"),r=_t(i,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/n)*n;s.set(a,(s.get(a)??0)+r)}let a=0;for(const t of s.values())a=Math.max(a,t);return[a>0?a+a*(r??.1):1,0]}({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(i.binSize),valueExtent:l,extentPadding:i.extentPadding}):l,d={...void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.cursor&&{cursor:i.cursor},...void 0!==i.gap&&{gap:i.gap}},h=ct(void 0,i.styleRules,t=>{const e=t.categoryValue??t.total,o="number"==typeof e&&Number.isFinite(e)?e:void 0,n=Number(t.binStart),i=Number(t.binEnd);return{value:o,x:Number.isFinite(n)&&Number.isFinite(i)?(n+i)/2:void 0,y:o,category:null==t.category?void 0:t.category+""}});return{chartType:"bar",data:r,...n,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||n.xExtent,yExtent:u,extentPadding:i.extentPadding??n.extentPadding,binSize:i.binSize,categoryAccessor:c,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,areaStyle:n.areaStyle||(t=>({...h(t),...!c&&void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.cursor&&{cursor:i.cursor}})),showLegend:n.showLegend??!!c}}},Ue={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=jt({data:Array.isArray(t)?g(t):[],xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.areaBy,forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:St(n.theme).colors.categorical}),a=function({data:t,safeData:e,areaBy:o,lineDataAccessor:n}){if(null==t)return[];const i=void 0!==e[0]?.[n];if(!i&&!o)return e;let r;if(i)r=e;else{const t=e.reduce((t,e)=>{const i="function"==typeof o?o(e):e[o],r=i+"";if(!t[r]){const e={[n]:[]};"string"==typeof o&&(e[o]=i),t[r]=e}return t[r][n].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[n])?t[n]:[];return"string"==typeof o?e.map(e=>({...e,[o]:e[o]??t[o]})):e})}({data:t,safeData:s.data,areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),c=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:o})=>({offset:t/100,color:e,...null!=o&&{opacity:o}}))}:Array.isArray(t.stops)?t:void 0}(i.semanticGradient),l=c?.stops.length?{stops:c.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:dt(n.gradientFill),u=!1!==i.semanticLine?function(t){const e=t?.stops.filter(t=>"string"==typeof t.color&&Number.isFinite(t.offset)).map(({offset:t,color:e,opacity:o})=>({offset:Math.max(0,Math.min(1,t)),color:e,...Number.isFinite(o)&&{opacity:Math.max(0,Math.min(1,o))}})).sort((t,e)=>t.offset-e.offset);if(!e?.length)return;const o=e[0];return o.offset>0?[{...o,offset:0},...e]:e}(c):void 0,d=n.pointStyle||Ge(a,r,o,n,i);return{chartType:"area",data:a,xAccessor:s.xAccessor,yAccessor:s.yAccessor,y0Accessor:i.y0Accessor,groupAccessor:i.areaBy||void 0,colorAccessor:r,colorScheme:o,...n,...s.annotations.length>0&&{annotations:s.annotations},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},...void 0!==l&&{gradientFill:l},...u&&{semanticLineStops:u},lineStyle:n.lineStyle||qe(a,r,o,n,i),...d&&{pointStyle:d}}}},Ke={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",c=t=>pt(ft(r,"x",t)),l=t=>pt(ft(s,"a",t)),u=t=>pt(ft(a,"b",t)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",f=i.areaOpacity??.6,p=i.lineWidth??1.5,y=!1!==i.showLines,g=!1!==n.showLegend,m=i.seriesALabel||"A",x=i.seriesBLabel||"B",b=n.legendPosition||"right",v=function(t,e,o,n){if(!t.length)return[];const i=t.filter(t=>Number.isFinite(e(t))).sort((t,o)=>e(t)-e(o)),r=[];let s=0,a=null,c=null,l=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),f=(t,e)=>{h({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:d(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;i.length>t;t++){const r=i[t],p=e(r),y=o(r),g=n(r);if(!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g))continue;const m=u(y,g);if(null!==m)if(null!=a){if(c&&c.w!==m){let t,e;if(l.length>0)t=l[0].x,e=l[0].y;else{const o=y-c.a-(g-c.b);if(0!==o){const n=Math.max(0,Math.min(1,(c.b-c.a)/o));t=c.x+n*(p-c.x),e=c.a+n*(y-c.a)}else t=c.x,e=c.a}h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;l.length>t;t++)f(l[t],a)}else for(const t of l)f(t,a);l=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else{a=m;for(const t of l)f(t,a);l=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),c={x:p,a:y,b:g,w:m}}else l.push({x:p,y:y,datum:r})}for(const t of l)f(t,a??"A");return r}(Array.isArray(t)?t:[],c,l,u),w=[];if(y&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(c(t))).sort((t,e)=>c(t)-c(e));for(const t of e){const e=c(t),o=l(t),n=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(n)&&w.push({__x:e,__y:n,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:f}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:p,fill:"none"}),curve:i.curve||"linear",...n,...g&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},Ze={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?Q(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,c=n.lineStyle||(t=>{const e=null==r?void 0:K(t,r,s),o=i.showLine??!0,n={fill:i.color??e,stroke:o?i.stroke??e:"none",...o?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:a,...null==i.opacity?{}:{opacity:i.opacity}},c=i.styleRules;if(c?.length){const e=ot(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,at(t,c,{value:e(t),category:o}))}return n}),l=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Ge(t,r,o,n,i);return{chartType:"stackedarea",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:r,colorScheme:o,normalize:i.normalize,baseline:l,stackOrder:i.stackOrder,lineStyle:c,...n,...u&&{pointStyle:u},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!r}}},Qe={frameType:"xy",buildProps:(t,e,o,n,i)=>{const[r]=n.size??[600,400];return{chartType:"candlestick",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.highAccessor||"high",highAccessor:i.highAccessor||"high",lowAccessor:i.lowAccessor||"low",openAccessor:i.openAccessor,closeAccessor:i.closeAccessor,candlestickStyle:i.candlestickStyle,...n,scalePadding:n.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:n.extentPadding??(r>200?.1:.02)}}},Je={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,c=i.centerlineStyle||{},l=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=c.stroke||"#999",h=c.strokeWidth??1,f=Array.isArray(c.strokeDasharray)?c.strokeDasharray.join(","):c.strokeDasharray,y=p.createElement,g=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const n=o.width,i=o.height,c=null!=r?e.x(r):n/2,g=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(c))return null;if(null!=s&&!Number.isFinite(g))return null;const m=Math.max(0,Math.min(n,c)),x=Math.max(0,Math.min(i,g)),b=[{c:a.topLeft,x:0,y:0,w:m,h:x},{c:a.topRight,x:m,y:0,w:n-m,h:x},{c:a.bottomLeft,x:0,y:x,w:m,h:i-x},{c:a.bottomRight,x:m,y:x,w:n-m,h:i-x}],v=l?[y("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),y("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),y("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),y("text",{key:"lbr",x:n-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return y(p.Fragment,null,...b.map((t,e)=>t.w>0&&t.h>0?y("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),y("line",{key:"vc",x1:m,y1:0,x2:m,y2:i,stroke:d,strokeWidth:h,strokeDasharray:f}),y("line",{key:"hc",x1:0,y1:x,x2:n,y2:x,stroke:d,strokeWidth:h,strokeDasharray:f}),...v)}]:void 0;return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[3,15],colorScheme:o,pointStyle:n.pointStyle||i.pointStyle||Yt(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...g&&{svgPreRenderers:g}}}},to={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const o=e.xAccessor||"x",n=e.yAccessor||"y",i=e.orderAccessor?[...t].sort((t,o)=>null==t||"object"!=typeof t?1:null==o||"object"!=typeof o?-1:pt(ft(e.orderAccessor,"order",t))-pt(ft(e.orderAccessor,"order",o))):t,r=new WeakMap;let s=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=pt(ft(o,"x",t)),i=pt(ft(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&s++}let a=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=pt(ft(o,"x",t)),i=pt(ft(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=jt({data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:St(n.theme).colors.categorical}),a=mt(s.annotations,i.regression),c=i.pointRadius??4,l=nt(i.xAccessor,i.yAccessor),u=i.styleRules,d=[t=>{const e=t.filter(t=>"point"===t.type&&"number"==typeof t.x&&"number"==typeof t.y);if(2>e.length)return null;const o=[];for(let t=0;e.length-1>t;t++){const n=e[t],i=e[t+1],r=yt(t,e.length);100>e.length&&o.push(p.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:c+2,strokeLinecap:"round",opacity:.5})),o.push(p.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:c,strokeLinecap:"round"}))}return p.createElement(p.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:et(t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1,i={fill:n>0?yt(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:c,fillOpacity:1};return u?.length&&Object.assign(i,at(t,u,l(t))),i},gt(i)),...n,...a&&a.length>0&&{annotations:a},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}};function eo(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}var oo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.frameProps&&"object"==typeof i.frameProps?i.frameProps:void 0,s=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1,a=ct(()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:s}),i.styleRules,function(t,e,o){const n=ot(t),i=ot(e),r=ot(o);return t=>{const e="string"==typeof t.agg&&"number"==typeof t.count&&"number"==typeof t.xCenter&&"number"==typeof t.yCenter;return{value:e?eo(t.value):r(t),x:e?eo(t.xCenter):n(t),y:e?eo(t.yCenter):i(t)}}}(i.xAccessor,i.yAccessor,i.valueAccessor)),c=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,l=null!=r&&Object.hasOwn(r,"heatmapColorScale"),u=r?.heatmapColorScale,d=l?"function"==typeof u?u:void 0:"custom"===c&&"function"==typeof i.customColorScale?i.customColorScale:void 0;return{chartType:"heatmap",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,showValues:i.showValues,heatmapValueFormat:i.valueFormat,...i.heatmapAggregation&&{heatmapAggregation:i.heatmapAggregation},...null!=i.heatmapXBins&&{heatmapXBins:i.heatmapXBins},...null!=i.heatmapYBins&&{heatmapYBins:i.heatmapYBins},areaStyle:a,...n,...void 0!==c&&{colorScheme:c},...d&&{heatmapColorScale:d}}}};import{useMemo as no,useCallback as io,useRef as ro}from"react";var so={RdBu:D,PiYG:z,PRGn:N,BrBG:E,RdYlBu:B,RdYlGn:W,Spectral:j},ao="__likert_neutral_neg",co="__likert_neutral_pos";function lo(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}var uo={frameType:"ordinal",layout:{margin:(t,e)=>({...e.marginDefaults,left:"vertical"===t.orientation?e.marginDefaults.left:Math.max(100,e.marginDefaults.left)})},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.levels)&&i.levels.length>=2?i.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==i.orientation;let a=function(t,e,o,n,i,r,s={}){const a=new Map,c=new Set(e);for(const s of t){const t=o(s);a.has(t)||a.set(t,new Map);const l=a.get(t);if(n){const t=n(s);if(null==t||!Number.isFinite(t))continue;if(!Number.isInteger(t)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",t);continue}const o=t-1;if(0>o||o>=e.length)continue;const i=e[o];l.set(i,(l.get(i)||0)+1)}else if(i&&r){const t=i(s),e=r(s);if(!c.has(t))continue;l.set(t,(l.get(t)||0)+(Number.isFinite(e)?e:0))}}const l=[];for(const[t,o]of a){let n=0;for(const t of e)n+=o.get(t)||0;if(0!==n)for(let i=0;e.length>i;i++){const r=e[i],a=o.get(r)||0,c={};s.category&&(c[s.category]=t),s.level&&(c[s.level]=r),s.count&&(c[s.count]=a),s.score&&(c[s.score]=i+1),l.push({...c,__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:a,__likertPct:a/n*100,__likertLevelIndex:i})}}return l}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,lo(i.categoryAccessor,"question"),i.levelAccessor?null:lo(i.valueAccessor,"score"),i.levelAccessor?lo(i.levelAccessor,"level"):null,i.levelAccessor?lo(i.countAccessor,"count"):null,{category:"string"==typeof i.categoryAccessor?i.categoryAccessor:void 0,level:"string"==typeof i.levelAccessor?i.levelAccessor:void 0,count:"string"==typeof i.countAccessor?i.countAccessor:void 0,score:i.levelAccessor||"string"!=typeof i.valueAccessor?void 0:i.valueAccessor});s&&(a=function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=new Map;for(const e of t){const t=r.get(e.__likertCategory)||[];t.push(e),r.set(e.__likertCategory,t)}const s=[];for(const[,t]of r){const e=new Map;let r,a;for(const o of t)o.__likertLevel===ao?r=o:o.__likertLevel===co?a=o:e.set(o.__likertLevelIndex,o);n&&r&&s.push(r);for(let t=i-1;t>=0;t--){const o=e.get(t);o&&s.push(o)}n&&a&&s.push(a);for(let t=n?i+1:i;o>t;t++){const o=e.get(t);o&&s.push(o)}}return s}(function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(n&&t===i){const t=e.__likertPct/2;r.push({...e,__likertLevel:ao,__likertPct:-t}),r.push({...e,__likertLevel:co,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const c=St(n.theme).colors.diverging,l=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(so,e)){const o=so[e];if(1===t)return[o(.5)];const n=[];for(let e=0;t>e;e++)n.push(o(e/(t-1)));return n}const o=["#da1e28","#ff8389","#ffb3b8"],n=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===t)return[i];const r=t%2!=0,s=Math.floor(t/2),a=[];for(let t=0;s>t;t++)a.push(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);r&&a.push(i);for(let t=0;s>t;t++)a.push(n[Math.min(Math.floor(t*n.length/s),n.length-1)]);return a}(r.length,c),u=new Map(r.map((t,e)=>[t,l[e]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",f=ne(!1===n.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},n.legend),p=i.styleRules,y=n.pieceStyle;return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:n.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...n,pieceStyle:et((t,e)=>{const o=t.__likertLevel||t.data?.__likertLevel,n=t.__likertLevelLabel||t.data?.__likertLevelLabel,i=t.__likertPct??t.data?.__likertPct,r={fill:o===ao||o===co?d:u.get((n||o)+"")||"#888"};return p?.length&&Object.assign(r,at(t,p,{value:"number"==typeof i?i:void 0,category:e??(null==n?void 0:n+"")})),"function"==typeof y?Object.assign(r,y(t,e)||{}):y&&"object"==typeof y&&Object.assign(r,y),r},gt(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}};import*as ho from"react";function fo(t){return Math.max(0,Math.min(1,t))}function po(t){const e=t.trim();if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t.split("").map(t=>t+t).join("")),6===t.length&&/^[0-9a-f]{6}$/i.test(t))return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const t=[Number(o[1]),Number(o[2]),Number(o[3])];if(t.every(Number.isFinite))return t}return null}function yo(t,e,o){const n=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function go(t,e,o){const n=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:fo(t.offset),color:t.color??o,opacity:null==t.opacity?1:fo(t.opacity)})).sort((t,e)=>t.offset-e.offset);if(0===n.length)return"#999999";const i=t=>{if(1===t.opacity)return t.color;const e=po(t.color);return e?`rgba(${e[0]},${e[1]},${e[2]},${t.opacity})`:t.color};if(1===n.length)return i(n[0]);const r=fo(e);if(n[0].offset>=r)return i(n[0]);if(r>=n[n.length-1].offset)return i(n[n.length-1]);for(let t=0;n.length-1>t;t++){const e=n[t],o=n[t+1];if(e.offset>r||r>o.offset)continue;const s=o.offset-e.offset,a=s>0?(r-e.offset)/s:0,c=po(e.color),l=po(o.color);if(!c||!l)return i(.5>a?e:o);const[u,d,h]=c,[f,p,y]=l,g=u+(f-u)*a,m=d+(p-d)*a,x=h+(y-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?yo(g,m,x):`rgba(${Math.round(g)},${Math.round(m)},${Math.round(x)},${b})`}return i(n[n.length-1])}function mo(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}function xo(t=240){const e=360-t,o=180+e/2,n=o*Math.PI/180;return{sweepRad:t*Math.PI/180,gapDeg:e,startAngleDeg:o,startAngleRad:n,offsetRad:-Math.PI/2+n}}import{Fragment as bo,jsx as vo,jsxs as wo}from"react/jsx-runtime";var ko={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const o=t.__gauge;if(!o)return null;const n=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,i=o.needleColor||e.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(t=>t.value>o.gMin&&o.gMax>t.value):[];return wo(bo,{children:[o.showNeedle&&wo(bo,{children:[vo("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(n),y2:o.centerY+o.needleLength*Math.sin(n),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),vo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&vo("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:i,children:o.contextValue}),r.map((t,n)=>{const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(t.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,s=o.radius+1,a=o.radius+10,c=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,l=c>=11||1>c?"middle":5>c?"start":7>c?"middle":"end",u=c>=11||1>c?"auto":5>c?"middle":7>c?"hanging":"middle";return wo("g",{children:[vo("line",{x1:o.centerX+Math.cos(i)*r,y1:o.centerY+Math.sin(i)*r,x2:o.centerX+Math.cos(i)*s,y2:o.centerY+Math.sin(i)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),vo("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:l,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+n)})]})},buildProps:(t,e,o,n,i)=>{const r=i.min??0,s=i.max??100,a=i.sweep??240,c=i.arcWidth??.3,l=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=xo(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],f=ht(n.gradientFill),p=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:c,gradientFill:l,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,n))-e)/d;let f=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];f=f.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>f[f.length-1].value&&f.push({value:o,color:f[f.length-1].color});const p=!!l&&l.stops.length>=2,y=[],g=new Map,m=[];if(p){const t=a?h:1,e=mo("bg",0);if(y.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),g.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(e,Math.round(t*e))),n=[];for(let e=0;o>e;e++)n.push(go(l.stops,t*(e+.5)/o,r||f[0]?.color||"#007bff"));const i=mo("fill",0);y.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),g.set(i,{fill:n[0]||s})}}else{let t=e;for(let o=0;f.length>o;o++){const n=f[o],i=(n.value-t)/d,r=(t-e)/d,c=(n.value-e)/d,l=Math.max(0,(a?Math.min(h,c):c)-r),u=a?Math.max(0,i-l):0;if(l>0){const t=mo("fill",o);y.push({category:t,value:l,_zone:n.label||"Zone "+(o+1),_isFill:!0}),g.set(t,{fill:n.color})}if(u>0){const t=mo("bg",o);y.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),g.set(t,{fill:s,opacity:.4})}t=n.value}}if(c&&i&&i.length>0)for(const t of i)t.value>e&&o>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:y,pieceStyle:(t,e)=>g.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:f}),y=i.styleRules,[g,m]=n.size||[300,250],x=function(t=240){const{sweepRad:e,offsetRad:o}=xo(t),n=[[Math.cos(o),Math.sin(o)],[Math.cos(o+e),Math.sin(o+e)],[0,0]];for(let t=0;2*Math.PI>t;t+=Math.PI/2)((t-o)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)>e+.001||n.push([Math.cos(t),Math.sin(t)]);const i=n.map(t=>t[0]),r=n.map(t=>t[1]),[s,a]=Pt(i),[c,l]=Pt(r);return{minX:s,maxX:a,minY:c,maxY:l,width:a-s,height:l-c,cx:(s+a)/2,cy:(c+l)/2}}(a),b=Math.min(10,Math.max(1,Math.min(g,m)/12)),v=Math.max(4,Math.min((g-2*b)/x.width,(m-2*b)/x.height)-2),w=Math.max(0,Math.min(v-1.5,v*(1-c))),k=g/2-x.cx*v,A=m/2-x.cy*v,S=2*(v+4),M=Math.max(r,Math.min(s,i.value??r)),_="function"==typeof i.valueFormat?i.valueFormat(M):Math.round(M)+"",P=i.centerContent??n.centerContent,L=null!=P?"function"==typeof P?P(M,r,s):P:"sparkline"===i.mode||"context"===i.mode?void 0:ho.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},ho.createElement("div",{style:{fontSize:Math.max(16,.3*v),fontWeight:700,color:"var(--semiotic-text, #333)"}},_),!1!==i.showScaleLabels&&ho.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:p.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:w,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:et((t,e)=>{const o={...p.pieceStyle(t,e)};return y?.length&&Object.assign(o,at(t,y,{value:"number"==typeof t.value?t.value:void 0,category:e??(null==t.category?void 0:t.category+"")})),o},gt(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[g,m],margin:{top:A-S/2,bottom:m-A-S/2,left:k-S/2,right:g-k-S/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(n.annotations)?n.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:c,value:M,startAngleDeg:d,thresholds:h,centerX:k,centerY:A,radius:v,innerRadius:w,showScaleLabels:!1!==i.showScaleLabels,needleLength:w>20?w-8:v-1,showNeedle:l,needleColor:i.needleColor,..."context"===i.mode&&null==P&&{contextValue:_,contextValueY:A-.2*w,valueFontSize:Math.max(12,Math.min(22,.28*v))}}}}};function Ao(t){return dt(t)}function So(t,e,o,n,i,r){const s=St(n.theme).colors.categorical,a=o??n.colorScheme,c=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],l="string"==typeof e?e:"__ssrColorBy",u="function"==typeof e?c.map(t=>({...t,__ssrColorBy:e(t)})):c,d=e?Q(u,l,a??s):void 0,h=Se("string"==typeof i.color?i.color:void 0,s,a,void 0,new Map),f=r??ot(i.valueAccessor??"value"),p=i.styleRules,y=n.pieceStyle;return(t,o)=>{const n={fill:e&&d?K(t,e,d):h};return p?.length&&Object.assign(n,at(t,p,{value:f(t,o),category:o})),"function"==typeof y?Object.assign(n,y(t,o)||{}):y&&"object"==typeof y&&Object.assign(n,y),void 0!==i.stroke&&(n.stroke=i.stroke),void 0!==i.strokeWidth&&(n.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(n.opacity=i.opacity),n}}function Mo(t,e,o,n,i,r="median",s=.8){const a=ot(i.valueAccessor??"value"),c=So(t,e,o,n,i,t=>"number"==typeof t[r]?t[r]:a(t));return(t,e)=>{const o=c(t,e);return void 0===o.fillOpacity&&(o.fillOpacity=s),void 0===o.stroke&&(o.stroke=o.fill),o}}function _o(t,e,o,n,i){return Mo(t,e,o,n,i,"median",.6)}function Po(t,e,o,n,i){const r=So(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function Lo(t,e,o,n,i){const r=So(t,e,o,n,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,c=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],l=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=l.length?Pt(l):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?J(t,a,c,u):d,fillOpacity:h,...r(t,e)})}var $o={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=mt(n.annotations,i.regression);return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,colorAccessor:e,colorScheme:o,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,...r&&{annotations:r},gradientFill:Ao(n.gradientFill),pieceStyle:So(t,e,o,n,i)}}},Ro={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.stackBy;return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Ao(n.gradientFill),pieceStyle:So(t,r,o,n,i),showLegend:n.showLegend??!!r}}},To={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.groupBy;return{chartType:"clusterbar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",groupBy:i.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Ao(n.gradientFill),pieceStyle:So(t,r,o,n,i),showLegend:n.showLegend??!!r}}},Io={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor,s=ot(i.valueAccessor??"value");return{chartType:"pie",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:So(t,r,o,n,i,t=>{const e=s(t);return null==e?void 0:Math.abs(e)}),showLegend:n.showLegend??!!r}}},Co={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor,s=ot(i.valueAccessor??"value");return{chartType:"donut",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:n.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:So(t,r,o,n,i,t=>{const e=s(t);return null==e?void 0:Math.abs(e)})}}},Oo={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=i.valueAccessor||"value",a=r.map(t=>Number("function"==typeof s?s(t):t[s])).filter(Number.isFinite),c=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:t,oAccessor:i.categoryAccessor||(t=>null==t.category?"All":t.category+""),rAccessor:s,projection:"horizontal",bins:i.bins??25,normalize:i.relative??!1,colorAccessor:e,colorScheme:o,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:c?{rExtent:c}:{},...n,summaryStyle:Mo(t,e,o,n,i,"count")}}},Fo={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"boxplot",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...n,summaryStyle:Mo(t,e,o,n,i)})},Do={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"violin",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,projection:"horizontal"===i.orientation?"horizontal":"vertical",bins:i.bins??25,showIQR:i.showIQR??!0,barPadding:i.categoryPadding??20,colorScheme:o,...n,summaryStyle:_o(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},zo={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"swarm",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,sizeRange:i.sizeRange||[3,8],pieceStyle:Lo(t,e,o,n,i),showLegend:n.showLegend??!!e})},No={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>{const r=mt(n.annotations,i.regression);return{chartType:"point",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...n,...r&&{annotations:r},pieceStyle:Po(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e}}},Eo={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=i.seriesAccessor||e||"__radar",s=e||("__radar"===r?void 0:r),a=Po(t,s,o,n,{...i,dotRadius:i.pointRadius??4});return{chartType:"point",projection:"radial",data:t,oAccessor:i.categoryAccessor||"attribute",rAccessor:i.valueAccessor||"value",colorAccessor:s,colorScheme:o,connectorAccessor:r,connectorStyle:t=>{const e=a(t),o="string"==typeof e.fill?e.fill:void 0;return{fill:o,fillOpacity:.15,stroke:o,strokeWidth:2,opacity:.7}},pieceStyle:a,rExtent:i.valueExtent||[0],oLabel:"",...n,...i.categoryFormat&&{oFormat:i.categoryFormat},showLegend:n.showLegend??!!s}}},Bo={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.subcategoryAccessor;return{chartType:"swimlane",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.subcategoryAccessor,colorAccessor:r,categoryAccessor:i.categoryAccessor,subcategoryAccessor:i.subcategoryAccessor,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Ao(n.gradientFill),pieceStyle:So(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},Wo={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"ridgeline",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...n,summaryStyle:Mo(t,e,o,n,i,"median",.5),showLegend:n.showLegend??!!e})},jo={frameType:"ordinal",layout:{margin:(t,e)=>"vertical"===t.orientation?{top:e.title?60:40,right:20,bottom:60,left:60}:{top:e.title?40:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="vertical"===i.orientation,s=e||i.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:i.stepAccessor||"step",rAccessor:i.valueAccessor||"value",colorAccessor:s,categoryAccessor:i.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,...!r&&null!=i.connectorOpacity&&{connectorOpacity:i.connectorOpacity},barPadding:r?40:0,colorScheme:o,...n,showAxes:r&&!1!==n.showAxes,showGrid:r,pieceStyle:So(t,s,o,n,i),showLabels:i.showLabels??!0}}};import{scaleTime as Yo}from"d3-scale";var Xo={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function qo(t="static"){return Xo[t]??Xo.static}var Go=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function Vo(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:Go.has(t.kind)?"fatal":"warn"}function Ho(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:"duplicate-node"===t.kind?`node id "${t.id}" is duplicated`:"duplicate-edge"===t.kind?`edge id "${t.id}" is duplicated`:"invalid-system-time"===t.kind?`edge ${t.id} has an invalid systemInTime or systemOutTime`:t.kind}function Uo(t){const{desired:e,minGaps:o,weights:n}=t,i=e.length;if(0===i)return[];if(o.length!==Math.max(0,i-1))throw Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const r=Array(i).fill(0);for(let t=1;i>t;t++)r[t]=r[t-1]+Math.max(0,Number.isFinite(o[t-1])?o[t-1]:0);const s=[];for(let t=0;i>t;t++){const o=Math.max(Number.EPSILON,Number.isFinite(n?.[t])?n[t]:1),i=(Number.isFinite(e[t])?e[t]:0)-r[t];for(s.push({start:t,end:t,weight:o,mean:i});s.length>1;){const t=s[s.length-1],e=s[s.length-2];if(t.mean>=e.mean)break;const o=e.weight+t.weight;s.splice(s.length-2,2,{start:e.start,end:t.end,weight:o,mean:(e.mean*e.weight+t.mean*t.weight)/o})}}const a=Number.isFinite(t.min)?t.min:-1/0,c=Number.isFinite(t.max)?t.max-r[i-1]:1/0,l=a>c?a:c,u=Array(i);for(const t of s){const e=Math.max(a,Math.min(l,t.mean));for(let o=t.start;t.end>=o;o++)u[o]=e+r[o]}return u}function Ko(t,e){let o=0,n=t.length-1,i=-1;for(;n>=o;){const r=o+n>>>1;t[r].at>e?n=r-1:(i=r,o=r+1)}return 0>i?{at:e,before:0,after:0}:t[i]}function Zo(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const o=[],n=[0];for(let i=0;t.length-1>i;i++){const r=t[i],s=t[i+1],a=[...new Set([...r.map(t=>t.at),...s.map(t=>t.at)])].sort((t,e)=>t-e);let c=0;for(const t of a){const e=Ko(r,t),o=Ko(s,t);c=Math.max(c,e.after+o.before)}o.push(c),n.push(n[n.length-1]+c+e)}return{adjacentClearance:o,positions:n}}function Qo(t,e,o,n={}){let i=[...t];if(1>=i.length)return i;let r=[...i],s=o(i),a=1;const c=Math.max(0,n.passes??6),l=Math.max(1,n.maxEvaluations??1/0);for(let t=0;c>t&&l>a;t++){const t=new Map(i.map((t,e)=>[t,e])),c=new Map,l=new Map;for(const o of e){const e=t.get(o.source),n=t.get(o.target);if(null==e||null==n)continue;const i=Number.isFinite(o.weight)&&o.weight>0?o.weight:1;c.set(o.source,(c.get(o.source)??0)+n*i),l.set(o.source,(l.get(o.source)??0)+i),c.set(o.target,(c.get(o.target)??0)+e*i),l.set(o.target,(l.get(o.target)??0)+i)}i=i.map((t,e)=>({item:t,index:e,barycenter:(c.get(t)??e)/(l.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(n.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=o(i);if(a++,s>u)s=u,r=[...i];else if(u===s)break}return r}function Jo(t,e,o={}){const n=[...t],i=n.length;if(1>=i||i>(o.maxItems??8))return n;const r=Math.max(1,o.maxEvaluations??1/0);let s=0,a=[...n],c=1/0;const l=()=>{if(s>=r)return;const t=e(n);s++,c>t&&(c=t,a=[...n])};l();const u=Array(i).fill(0);let d=0;for(;i>d&&r>s;)if(d>u[d]){const t=d%2==0?0:u[d];[n[t],n[d]]=[n[d],n[t]],l(),u[d]++,d=0}else u[d]=0,d++;return a}function tn(){return Object.create(null)}function en(t,e){return e>t?-1:t>e?1:0}function on(t){return t.occupants.map(t=>t.id).sort(en).join("\0")}function nn(t,e,o=0){return t.slice(0,-1).map((n,i)=>null!=n.group&&n.group===t[i+1].group?o:e)}function rn(t,e){return t.map(t=>{const o=new Map;for(const n of t.occupants){const t=e[n.id];if(t)for(const e of t.samples){const t=o.get(e.t)??{before:0,after:0},n=e.boundaryOffset??0;o.set(e.t,{before:Math.max(t.before,e.topMass-n),after:Math.max(t.after,e.botMass+n)})}}return[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function sn(t,e,o){if(0===t.length)return[];const{padding:n,plotH:i,valueScale:r}=o,s=o.stackValueScale??r,a=nn(t,n,o.groupPadding??0),c=[n+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)c.push(c[o-1]+e[o-1]*s+a[o-1]);const l=c[c.length-1]+t[t.length-1].peak.botPeak*s+n;if(l>i&&l>0){const t=i/l;for(let e=0;c.length>e;e++)c[e]*=t}return c}function an(t,e){const o=(t.boundaryOffset??0)*e,n=t.value*e;if("out"===t.kind){const i=t.sideMassBefore*e;return o+("top"===t.side?n/2-i:i-n/2)}const i=t.sideMassAfter*e;return o+("top"===t.side?n/2-i:i-n/2)}function cn(t,e,o,n,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:Zo(rn(n,o)).adjacentClearance,a=sn(n,s,r);let c="hug"===r.lanePlacement?function(t,e,o,n,i,r,s){const a=t.length;if(0===a)return[];const{padding:c,plotH:l,valueScale:u}=s,d=nn(t,c,s.groupPadding??0),h=i.map((t,e)=>t*u+d[e]),f=c+t[0].peak.topPeak*u,p=l-c-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=p-f)return sn(t,i,s);let y=1===a?[(f+p)/2]:[...r];for(let t=0;12>t;t++){const t=Array(a).fill(0),i=Array(a).fill(0);for(const r of o){const o=e[r.source],s=e[r.target];if(null==o||null==s||o===s)continue;const a=n[r.source]?.localAttachments.get(r.id),c=n[r.target]?.localAttachments.get(r.id);if(!a||!c)continue;const l=r.value>0&&Number.isFinite(r.value)?r.value:1,d=an(a,u),h=an(c,u);t[o]+=(y[s]+h-d)*l,i[o]+=l,t[s]+=(y[o]+d-h)*l,i[s]+=l}const r=Uo({desired:y.map((e,o)=>0===i[o]?e:.45*e+t[o]/i[o]*.55),minGaps:h,weights:i.map(t=>Math.max(1,t)),min:f,max:p});let s=0;for(let t=0;a>t;t++)s=Math.max(s,Math.abs(r[t]-y[t]));if(y=r,.01>s)break}return y}(n,i,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=tn();for(const n of t)o[n.id]=e[i[n.id]];return o};ln(o(c),e)>ln(o(a),e)+1e-6&&(c=[...a])}const l=tn();for(const e of t)l[e.id]=c[i[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=l[e.id],n=o[e.id];Number.isFinite(t)&&n&&(u=Math.min(u,t-n.topPeak*r.valueScale),d=Math.max(d,t+n.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:l,slotCenter:c,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function ln(t,e){let o=0;for(const n of e){const e=t[n.source],i=t[n.target];Number.isFinite(e)&&Number.isFinite(i)&&(o+=Math.abs(e-i)*(n.value>0?n.value:1))}return o}function un(t,e){const o=t?.samples;if(!o||0===o.length||o[0].t>e)return{top:0,bot:0};let n=0,i=o.length-1,r=0;for(;i>=n;){const t=n+i>>>1;o[t].t>e?i=t-1:(r=t,n=t+1)}const s=o[r].boundaryOffset??0;return{top:o[r].topMass-s,bot:o[r].botMass+s}}function dn(t,e,o,n,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*o+i*i*i*n}function hn(t,e){let o=0,n=1;for(let i=0;28>i;i++){const i=(o+n)/2;t>dn(0,e,e,1,i)?o=i:n=i}return(o+n)/2}function fn(t,e,o){const n=e+an(t,o),i=t.value*o/2;return[n-i,n+i]}function pn(t,e,o,n){return Math.max(0,Math.min(e,n)-Math.max(t,o))/Math.max(1e-9,e-t)}function yn(t,e,o,n,i,r,s){const{valueScale:a,domain:c,mode:l="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of t){const t=n[s.source],h=n[s.target];if(null==t||null==h||2>Math.abs(t-h))continue;const f=e[s.source]?.localAttachments.get(s.id),p=e[s.target]?.localAttachments.get(s.id);if(!f||!p)continue;const y=Math.max(s.startTime,c?.[0]??-1/0),g=Math.min(s.endTime,c?.[1]??1/0);if(y>=g)continue;const[m,x]=fn(f,i[s.source],a),[b,v]=fn(p,i[s.target],a),w=Math.min(t,h)+1,k=Math.max(t,h)-1;for(let t=w;k>=t;t++){const n=o[t];if(!n)continue;const c=[y,g];if("quality"===l)for(const t of n.occupants)for(const o of e[t.id]?.samples??[])o.t>y&&g>o.t&&c.push(o.t);const h=t=>{const o=hn((t-y)/(g-y),u),c=dn(m,m,b,b,o),l=dn(x,x,v,v,o);let d=0;for(const o of n.occupants){if(o.id===s.source||o.id===s.target)continue;const n=r[o.id];if(null!=n?.start&&n.start>t)continue;if(null!=n?.end&&t>n.end)continue;const u=un(e[o.id],t),h=i[o.id];d=Math.max(d,pn(c,l,h-u.top*a,h+u.bot*a))}return d},f=[...new Set(c)].sort((t,e)=>t-e);let p=0;for(let t=0;f.length-1>t;t++){const e=f[t],o=f[t+1]-e;p+=(h(e+.25*o)+h(e+.5*o)+h(e+.75*o))/3*o}d+=p/(g-y)*(s.value>0?s.value:1)}}return d}function gn(t,e,o,n,i,r,s,a,c,l,u="both",d){return{crossings:t,weightedLength:e,pixelLength:ln(s,o),transitOcclusion:yn(o,n,i,r,s,a,{valueScale:c,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:l}}function mn(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function xn(t,e){return t.map(t=>({t:mn(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function bn(t,e,o){const n=e+(t.boundaryOffset??0)*o,i=t.value*o;if("out"===t.kind){const e=t.sideMassBefore*o;if("top"===t.side){const t=n-e;return[t,t+i]}const r=n+e;return[r-i,r]}const r=t.sideMassAfter*o;if("top"===t.side){const t=n-r;return[t,t+i]}const s=n+r;return[s-i,s]}function vn(t,e,o,n,i="temporal"){const r=e.incoming[t.id],s=e.outgoing[t.id],a=[];for(const t of r)a.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of s)a.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const c={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},l=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(c[t.kind]??99)-(c[e.kind]??99)||((t,e)=>{if(!n||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const o=n.get(t.edge.id)?.target,i=n.get(e.edge.id)?.target;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===t.side?o-i:i-o:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const o=n.get(t.edge.id)?.source,i=n.get(e.edge.id)?.source;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===t.side?i-o:o-i:0}return 0})(t,e)||en(t.edge?.id??"",e.edge?.id??"")||en(t.side,e.side)||t.delta-e.delta)},u=a.length?function(t,e=1/0){let o=e;for(const e of t)o>e&&(o=e);return o}(a.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;l();let f=null,p=0;for(const t of a)t.time!==f&&(f=t.time,p=0),t.sequence=p++;const y=t=>({time:t.time,phase:0,sequence:t.sequence??0}),g=[];let m=0,x=0;for(const t of a)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?m:x);if(o>0){const e="top"===t.side?"bot":"top",n=Math.min(o,"top"===e?m:x);if(n>0){const i=y(t);g.push({...i,delta:-n,kind:"transfer-out",side:e}),g.push({...i,delta:+n,kind:"transfer-in",side:t.side}),"top"===e?m-=n:x-=n,"top"===t.side?m+=n:x+=n,o-=n}o>0&&null!==h&&(g.push({time:h,delta:+o,kind:"create",side:t.side}),"top"===t.side?m+=o:x+=o)}"top"===t.side?m-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?m+=e:x+=e}a.push(...g),l();let b=0,v=0,w=0,k=0,A=0,S=0;const M=[],_=new Map,P=t=>{M.push({t:t,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},L=()=>{k=Math.max(k,b+v),A=Math.max(A,b-w),S=Math.max(S,v+w)};for(const t of a){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&P(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?b:v;_.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?b+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,L(),P(t.time)):"transfer-out"!==t.kind&&(L(),"out"!==t.kind||b+v>1e-12||(w=0),P(t.time))}const $=[];let R=0;for(;M.length>R;){let t=R;for(;M.length>t+1&&M[t+1].t===M[R].t;)t++;$.push(M[R]);for(let e=R+1;t>=e;e++){const t=$[$.length-1];M[e].topMass===t.topMass&&M[e].botMass===t.botMass&&(M[e].boundaryOffset??0)===(t.boundaryOffset??0)||$.push(M[e])}R=t+1}const T=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let I=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===I||I>t.systemInTime)&&(I=t.systemInTime);let C=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===C||t.systemOutTime>C)&&(C=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=T?T:-1/0,null!=C?C:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&$.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const o=$[0],n=$.find(t=>t.topMass+t.botMass>0);let i,r=1/0;null!=d&&Number.isFinite(d)&&o.t>d&&o.topMass+o.botMass>0&&(r=d,i=o),n&&null!=I&&Number.isFinite(I)&&n.t>I&&r>I&&(r=I,i=n),i&&Number.isFinite(r)&&$.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let O=$;if("max"===i&&null!=d&&null!=T&&T>d){let t,e=0;for(const o of $){const n=o.topMass+o.botMass;n>e&&(e=n,t=o)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};O=[...$.filter(t=>d>t.t),{t:d,...e},{t:T,...e},...$.filter(t=>t.t>T)]}}return{samples:O,peak:k,topPeak:A,botPeak:S,localAttachments:_}}function wn(t){const e=tn();return t.forEach((t,o)=>{for(const n of t.occupants)e[n.id]=o}),e}function kn(t,e,o){t.splice(0,t.length,...o);const n=wn(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,n)}function An(t){const e=new Map,o=[];t.forEach((t,n)=>{if(!t.group)return void o.push({anchor:n,stableId:on(t),slots:[t]});const i=e.get(t.group)??{indexes:[],slots:[]};i.indexes.push(n),i.slots.push(t),e.set(t.group,i)});for(const[t,n]of e)o.push({anchor:n.indexes.reduce((t,e)=>t+e,0)/n.indexes.length,stableId:`${t}\0${n.slots.map(on).join("\0")}`,slots:n.slots});return o.sort((t,e)=>t.anchor-e.anchor||en(t.stableId,e.stableId))}function Sn(t){return t.some(t=>t.group)?An(t).flatMap(t=>t.slots):[...t]}function Mn(t){return t.flatMap(t=>t.slots)}function _n(t,e,o){const n=new Map;return t.forEach((t,e)=>{for(const o of t.slots)n.set(o,e)}),t.map((t,i)=>{if(1>=t.slots.length)return t;const r=new Map;for(const e of t.slots)r.set(e,0);for(const t of e){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o)continue;const s=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===i&&o!==i){const e=o>i?1:-1;r.set(t.source,(r.get(t.source)??0)+s*e)}else if(o===i&&e!==i){const o=e>i?1:-1;r.set(t.target,(r.get(t.target)??0)+s*o)}}const s=[...t.slots].sort((t,e)=>(r.get(t)??0)-(r.get(e)??0)||o(t,e));return{...t,slots:s}})}function Pn(t,e){t.some(t=>t.group)&&kn(t,e,Sn(t))}function Ln(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.min(t.endTime,e.endTime)>Math.max(t.startTime,e.startTime)}function $n(t,e){return function(t,e,o=()=>!0){let n=0;for(let i=0;t.length>i;i++){const[r,s]=e(t[i]);for(let a=i+1;t.length>a;a++){if(!o(t[i],t[a]))continue;const[c,l]=e(t[a]);0>(r-c)*(s-l)&&n++}}return n}(e,e=>[t[e.source],t[e.target]],Ln)}function Rn(t,e){let o=0;for(const n of e){const e=t[n.source],i=t[n.target];null!=e&&null!=i&&(o+=Math.abs(e-i)*(n.value>0?n.value:1))}return o}function Tn(t,e,o){const[n,i]=o.get(t.first),[r,s]=o.get(t.second);return 0>(e.get(n)-e.get(r))*(e.get(i)-e.get(s))?1:0}var In=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},Cn=828*In(8),On=3e3;function Fn(t,e,o,n,i,r,s){const a=[...i],c=new Map(i.map(t=>[t,on(t)])),l=new Map;for(const t of i)for(const e of t.occupants)l.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=l.get(t.source),o=l.get(t.target);e&&o&&(u.set(t,[e,o]),e!==o&&d.push({source:e,target:o,weight:t.value}))}const h=[];for(let t=0;e.length>t;t++)if(u.has(e[t]))for(let o=t+1;e.length>o;o++){if(!u.has(e[o])||!Ln(e[t],e[o]))continue;const n=new Set([...u.get(e[t]),...u.get(e[o])]);h.push({index:h.length,first:e[t],second:e[o],involvedSlots:n})}const f=new Map;for(const t of i)f.set(t,[]);for(const t of h)for(const e of t.involvedSlots)f.get(e)?.push(t);const p=new Uint32Array(h.length);let y=0;const g=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),m=s.plotH/Math.max(1,i.length),x=i.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),b=Math.max(1,g)*(Math.max(1,s.plotH)+m*Math.max(x,i.length)+1e-6*Math.max(1,i.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,A=(t,e)=>{let n=k.get(t);n||(n=new Map,k.set(t,n));const i=n.get(e);if(null!=i)return i;const r=function(t,e,o){return Zo(rn([t,e],o)).adjacentClearance[0]??0}(t,e,o);return n.set(e,r),r},S=new Map(i.map((t,e)=>[t,e])),M=e.flatMap(t=>{const e=u.get(t);return e?[{source:S.get(e[0]),target:S.get(e[1]),weight:t.value>0?t.value:1}]:[]}),_=new Map;for(const t of e){const e=u.get(t);e&&_.set(t,{source:S.get(e[0]),target:S.get(e[1])})}const P=new Map,L=new Map,$=new Map,R=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)R(P,t.source,t.target),R(L,t.target,t.source),R($,t.source,t.target),R($,t.target,t.source);const T=e.flatMap(t=>{if(!(t=>1===P.get(t.source)?.size&&P.get(t.source).has(t.target)||1===$.get(t.source)?.size||1===$.get(t.target)?.size)(t))return[];const e=_.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),I=t=>{let e=0;for(const o of T)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*v},C=t=>{const e=new Int16Array(i.length);for(let o=0;t.length>o;o++)e[S.get(t[o])]=o;return I(e)},O=h.map(t=>{const e=_.get(t.first),o=_.get(t.second);return[e.source,e.target,o.source,o.target]}),F=new Int16Array(i.length),D=new Float64Array(i.length),z=new Float64Array(i.length+1),N=t=>{for(let e=0;t.length>e;e++)F[S.get(t[e])]=e;let e=0;for(const[t,o,n,i]of O)0>(F[t]-F[n])*(F[o]-F[i])&&e++;if(t.length>0){const e=S.get(t[0]);D[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const o=S.get(t[e-1]),n=S.get(t[e]);D[n]=D[o]+A(t[e-1],t[e])*s.valueScale+s.padding}const o=S.get(t[t.length-1]),n=D[o]+t[t.length-1].peak.botPeak*s.valueScale+s.padding;if(n>s.plotH&&n>0){const t=s.plotH/n;for(let e=0;D.length>e;e++)D[e]*=t}}z[0]=0;for(let e=0;t.length>e;e++)z[e+1]=z[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,n=0,i=0;for(const t of M){const e=F[t.source],r=F[t.target];if(o+=Math.abs(e-r)*t.weight,n+=Math.abs(D[t.source]-D[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;i+=(z[Math.max(e,r)]-z[o])*t.weight}}return e*b+n+i*m+I(F)+1e-6*o},E=(t,o)=>{const n=Array(t.length+1).fill(0);for(let e=0;t.length>e;e++)n[e+1]=n[e]+t[e].peak.topPeak+t[e].peak.botPeak;let i=0;for(const t of e){const e=o[t.source],r=o[t.target];if(null==e||null==r||2>Math.abs(e-r))continue;const s=Math.min(e,r)+1;i+=(n[Math.max(e,r)]-n[s])*(t.value>0?t.value:1)}return i},B=n=>{const i=wn(n),r=n.slice(0,-1).map((t,e)=>A(t,n[e+1])),a=cn(t,e,o,n,i,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:i,geometry:a,weightedLength:Rn(i,e),pixelLength:ln(a.centerlines,e),transitOcclusion:E(n,i)}},W=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*b+e.pixelLength+e.transitOcclusion*m+C(o)+1e-6*e.weightedLength}),j=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+Tn(o,e,u),0),w.fullCrossing++}return W(o,B(t),t)},Y=(t,i,r="quality")=>{let a=i;if(null==a){const e=new Map(t.map((t,e)=>[t,e]));a=h.reduce((t,o)=>t+Tn(o,e,u),0),w.fullCrossing++}const c=B(t);return W(a,{...c,transitOcclusion:yn(e,o,t,c.map,c.geometry.centerlines,n,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let X=[...a];const q=(t,e)=>en(c.get(t),c.get(e)),G=function(t){const e=new Set;for(const o of t)if(o.group){if(e.has(o.group))return!0;e.add(o.group)}return!1}(X),V=t=>{const e=(t=>{const e=Qo(t,d,t=>j(t).cost,{passes:6,compare:q,maxEvaluations:On});let o=j(e),n=On;for(let t=0;6>t&&n>0;t++){let i=!1;const r=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&r.reverse();for(const t of r){if(0>=n--)break;const r=e[t],s=e[t+1],a=new Map(e.map((t,e)=>[t,e]));let c=0;const l=[];y++;for(const t of[...f.get(r)??[],...f.get(s)??[]])p[t.index]!==y&&(p[t.index]=y,l.push(t),c+=Tn(t,a,u));[e[t],e[t+1]]=[s,r];const d=new Map(a);d.set(r,t+1),d.set(s,t);let h=0;for(const t of l)h+=Tn(t,d,u);w.localCrossing+=l.length;const g=j(e,o.crossings-c+h);o.cost>g.cost?(o=g,i=!0):[e[t],e[t+1]]=[r,s]}if(!i)break}return e})(t);if((t.length>8?1/0:In(t.length)*(t.length+M.length+O.length))>Cn)return e;const o=Jo(t,N,{maxItems:8,maxEvaluations:5e4}),n=Y(o),i=Y(e);return n.crossings!==i.crossings&&i.crossings>n.crossings?o:e},H="geometry-refine"===s.mode;if(H||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!H&&"inside-out"===s.laneOrder)if(G){const t=An(X),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||en(t.stableId,o.stableId)),n=Array(o.length);let i=Math.floor((o.length-1)/2)-1,r=Math.floor((o.length-1)/2)+1;o.length>0&&(n[Math.floor((o.length-1)/2)]=o[0]);for(let t=1;o.length>t;t++)t%2==1&&o.length>r||0>i?n[r++]=o[t]:n[i--]=o[t];X=Mn(n)}else{const t=[...X].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||q(t,e)),e=Array(t.length);let o=Math.floor((t.length-1)/2)-1,n=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let i=1;t.length>i;i++)i%2==1&&t.length>n||0>o?e[n++]=t[i]:e[o--]=t[i];X=e}}else X=G?(t=>{let e=An(t);if(1>=e.length)return Mn(e);const o=t=>j(Mn(t)).cost;e=An(V(t)),e=_n(e,d,q);const n=function(t,e){const o=new Map;for(const e of t)for(const t of e.slots)o.set(t,e);const n=new Map;for(const t of e){const e=o.get(t.source),i=o.get(t.target);if(!e||!i||e===i)continue;const r=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,s=i.stableId>e.stableId?`${e.stableId}\0${i.stableId}`:`${i.stableId}\0${e.stableId}`,a=n.get(s);a?a.weight=(a.weight??0)+r:n.set(s,{source:e,target:i,weight:r})}return[...n.values()]}(e,d);e=Qo(e,n,o,{passes:6,compare:(t,e)=>en(t.stableId,e.stableId),maxEvaluations:On}),e=function(t,e,o={}){const n=[...t];if(1>=n.length)return n;let i=e(n),r=1;const s=Math.max(0,o.passes??6),a=Math.max(1,o.maxEvaluations??1/0);for(let t=0;s>t&&a>r;t++){let t=!1;for(let o=0;n.length-1>o&&a>r;o++){[n[o],n[o+1]]=[n[o+1],n[o]];const s=e(n);r++,i>s?(i=s,t=!0):[n[o],n[o+1]]=[n[o+1],n[o]]}if(!t)break}return n}(e,o,{passes:8,maxEvaluations:On});const i=e.length>8?1/0:In(e.length)*(e.length+M.length+O.length);if(Cn>=i){const t=Jo(e,t=>N(Mn(t)),{maxItems:8,maxEvaluations:5e4}),o=Mn(t),n=Mn(e),i=Y(o),r=Y(n);i.crossings!==r.crossings?e=r.crossings>i.crossings?t:e:r.cost>i.cost&&(e=t)}return e=_n(e,d,q),Mn(e)})(X):V(X);if(!H&&"crossing-min+inside-out"===s.laneOrder&&X.length>1)if(G){const t=An(X);let e=j(Mn(t)),o=Mn(t),n=e;const i=Math.floor((t.length-1)/2),r=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),s=[...t].sort((t,e)=>r(e)-r(t)||en(t.stableId,e.stableId));for(const r of s){const s=t.indexOf(r);if(s===i)continue;t.splice(s,1),t.splice(i,0,r);const a=Mn(t),c=j(a);c.cost>e.cost?(t.splice(i,1),t.splice(s,0,r)):(e=c,n.cost>c.cost&&(o=a,n=c))}X=o}else{let t=j(X),e=[...X],o=t;const n=Math.floor((X.length-1)/2),i=[...X].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||q(t,e));for(const r of i){const i=X.indexOf(r);if(i===n)continue;X.splice(i,1),X.splice(n,0,r);const s=j(X);s.cost>t.cost?(X.splice(n,1),X.splice(i,0,r)):(t=s,o.cost>s.cost&&(e=[...X],o=s))}X=e}if((H||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&X.length>1)if(G){let t=An(X),e=Y(Mn(t),void 0,"score");for(let o=0;6>o&&t.length>1;o++){let o=!1;for(let n=0;t.length-1>n;n++){[t[n],t[n+1]]=[t[n+1],t[n]];const i=Mn(t),r=Y(i,void 0,"score");e.cost>r.cost?(X=i,e=r,o=!0):[t[n],t[n+1]]=[t[n+1],t[n]]}if(!o)break}t=_n(An(X),d,q),X=Mn(t)}else{let t=Y(X,void 0,"score");for(let e=0;X.length-1>e;e++){const o=X[e],n=X[e+1],i=new Map(X.map((t,e)=>[t,e]));let r=0;const s=[];y++;for(const t of[...f.get(o)??[],...f.get(n)??[]])p[t.index]!==y&&(p[t.index]=y,s.push(t),r+=Tn(t,i,u));[X[e],X[e+1]]=[n,o];const a=new Map(i);a.set(o,e+1),a.set(n,e);let c=0;for(const t of s)c+=Tn(t,a,u);w.localCrossing+=s.length;const l=Y(X,t.crossings-r+c,"score");t.cost>l.cost?t=l:[X[e],X[e+1]]=[o,n]}}const U=Sn(a);X=Sn(X);let K=Y(X);const Z=Y(U);if(H){const t=C(U),e=C(X);(K.crossings>Z.crossings||K.crossings===Z.crossings&&e>t+1e-9||K.cost>Z.cost)&&(X=U,K=Z)}else K.cost>Z.cost&&(X=U,K=Z);const Q=function({order:t,after:e,nodes:o,edges:n,outgoingPartners:i,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:c}){const l=(o,i)=>{const r=[...new Set(i.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),l=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-l+1!==r.length||1>=Math.abs(2*s-l-u))return;const d=[...t];d.splice(s,1),d.splice(l+u>>1,0,o);const h=Sn(d),f=c(h),p=new Set(o.occupants.map(t=>t.id)),y=new Set(i.flatMap(t=>t.occupants.map(t=>t.id))),g=n.reduce((t,e)=>p.has(e.source)&&y.has(e.target)||p.has(e.target)&&y.has(e.source)?t+(e.value>0?e.value:1):t,0);(function(t,e,o=0){return e.crossings>t.crossings||t.crossings===e.crossings&&e.cost+o>=t.cost})(f,e,Math.abs(2*s-l-u)*a*Math.max(1,g))&&(t=h,e=f)};for(const[t,e]of i)r.has(t)||3>e.size||l(s.get(t),[...e].map(t=>s.get(t)));for(const t of o){const e=s.get(t.id);t.group||!e.group||3>(r.get(t.id)?.size??0)||l(e,[...r.get(t.id)??[]].map(t=>s.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,o)=>o.indexOf(t)===e))}return{order:t,after:e}}({order:X,after:K,nodes:t,edges:e,outgoingPartners:P,incomingPartners:L,slotForNode:l,averageGap:m,evaluate:Y});return X=Q.order,K=Q.after,kn(i,r,X),{before:Z,after:K,initialOrder:a.map(t=>c.get(t)),evaluations:w}}function Dn(t,e,o){const n=t.map(t=>{const n=t.occupants.map(t=>({id:t.id,end:o[t.id]?.end??t.end}));let i=0,r=0;for(const t of n){const o=e[t.id];i=Math.max(i,o?.topPeak||0),r=Math.max(r,o?.botPeak||0)}return{occupants:n,peak:{topPeak:i,botPeak:r},...null!=t.group?{group:t.group}:{}}}),i=tn();return n.forEach((t,e)=>{for(const o of t.occupants)i[o.id]=e}),{slots:n,slotByNode:i}}var zn=new Map,Nn=1e5,En=1e-9;function Bn(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function Wn(t,e){return en(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function jn(t){const e=new Map,o=new Map;for(const n of t)o.has(n.source)||o.set(n.source,new Set),e.has(n.target)||e.set(n.target,new Set),o.get(n.source).add(n.target),e.get(n.target).add(n.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...o].map(([t,e])=>[t,e.size]))}}function Yn(t){const e=new Map,o=new Map,n=(t,e,o,n)=>{let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(o,(i.get(o)??0)+n)};for(const i of t){const t=i.value>0&&Number.isFinite(i.value)?i.value:1;n(e,i.source,i.target,t),n(o,i.target,i.source,t)}const i=new Map,r=t=>{if(i.has(t))return;const n=e.get(t),r=o.get(t),s=new Map;for(const[t,e]of n??[])s.set(t,(s.get(t)??0)+e);for(const[t,e]of r??[])s.set(t,(s.get(t)??0)+e);if(1===s.size){const[e,o]=[...s][0];i.set(t,{partner:e,weight:o})}};for(const e of t)r(e.source),r(e.target);return i}function Xn(t,e,o){const n=o.get(t),i=o.get(e);return!n||!i||n.partner===i.partner||n.partner===e||i.partner===t}function qn(t,e,o){return!!o.has(t)&&e.some(e=>!Xn(t,e,o))}function Gn(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function Vn(t,e,o,n){if(12>=t.length||1>=n.slotCount)return n.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Map),s=jn(o);for(const t of o){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o||e===o)continue;const n=Gn(t,s);r[e].set(o,(r[e].get(o)??0)+n),r[o].set(e,(r[o].get(e)??0)+n)}const a=Yn(o),c=t.map(t=>a.get(t)?.weight??0),l=Array.from({length:t.length},()=>new Map);let u=0;for(let o=0;t.length-1>o&&5e4>u;o++)if(a.has(t[o]))for(let n=o+1;t.length>n;n++){if(!a.has(t[n]))continue;if(e.conflicts(t[o],t[n]))continue;u++;const i=Math.min(c[o],c[n])||Math.max(c[o],c[n]),r=Xn(t[o],t[n],a)?i:-i;if(Math.abs(r)>En&&(l[o].set(n,r),l[n].set(o,r),u>=5e4))break}const d=[...n.assignment],h=Array.from({length:n.slotCount},()=>[]);d.forEach((t,e)=>h[t].push(e));const f=(t,e,o)=>{const n=d[e],i=d[o];let r=0;const s=new Set;for(const a of[e,o])for(const[c,l]of t[a]){const t=c>a?`${a}:${c}`:`${c}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?i:n)===(c===e?i:c===o?n:d[c]);d[a]===d[c]!==u&&(r+=u?l:-l)}return r},p=(t,e,o)=>{let n=0;for(const[i,r]of t[e]){const t=o===d[i];d[e]===d[i]!==t&&(n+=t?r:-r)}return n},y=(t,e)=>t>En||En>=Math.abs(t)&&e>En,g=(t,e,o,n)=>t>o+En||En>=Math.abs(t-o)&&e>n+En;let m=0;for(let o=0;32>o&&Nn>m;o++){let o=null,n=-1,i=-1,s=-1,a=-1/0,c=-1/0;for(let u=0;t.length>u;u++){for(let f=0;h.length>f&&m++<Nn;f++){if(f===d[u])continue;if(!h[f].every(o=>!e.conflicts(t[u],t[o])))continue;const m=p(r,u,f),x=p(l,u,f);y(m,x)&&g(m,x,a,c)&&(o="move",n=u,i=-1,s=f,a=m,c=x)}if(m>=Nn)break}for(let u=0;t.length-1>u;u++){for(let p=u+1;t.length>p&&m++<Nn;p++){const m=d[u],x=d[p];if(m===x)continue;if(!h[x].every(o=>o===p||!e.conflicts(t[u],t[o])))continue;if(!h[m].every(o=>o===u||!e.conflicts(t[p],t[o])))continue;const b=f(r,u,p),v=f(l,u,p);y(b,v)&&g(b,v,a,c)&&(o="swap",n=u,i=p,s=-1,a=b,c=v)}if(m>=Nn)break}if(null==o||-1===n)break;if("move"===o){const t=d[n];h[t].splice(h[t].indexOf(n),1),h[s].push(n),d[n]=s;continue}const u=d[n],x=d[i];h[u].splice(h[u].indexOf(n),1,i),h[x].splice(h[x].indexOf(i),1,n),d[n]=x,d[i]=u}return d}function Hn(t,e){let o=1/0,n=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass>1e-9&&(o=Math.min(o,e.t),n=Math.max(n,e.t));return Number.isFinite(o)&&Number.isFinite(n)?(null!=e.start&&(o=Math.max(o,e.start)),null!=e.end&&(n=Math.min(n,e.end)),o>n?{start:null,end:null}:{start:o,end:n}):{start:null,end:null}}function Un(t,e,o,n){const i=function(t,e,o,n){return`${t.map(t=>{const e=o[t.id],i=n[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,i?.start??"",i?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,o,n),r=zn.get(i);if(r)return Dn(r.slots,o,n);const s=tn();for(const e of t)s[e.id]=Hn(o[e.id],n[e.id]);const a=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,o)=>e[t.id].start-e[o.id].start||e[t.id].end-e[o.id].end||en(t.id,o.id)).map(t=>t.id)}(t,s),c=new Map(t.map(t=>[t.id,t])),l=new Map(t.map(t=>[t.id,t.group||void 0])),u=Yn(e),d=function(t,e,o,n,i,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),c=new Map(t.map(t=>[t,new Set]));for(const t of n)s.add(Wn(t.source,t.target)),a.get(t.target)?.add(t.source),c.get(t.source)?.add(t.target);const l=new Map,u=new Set,d=(t,e)=>{for(let o=0;t.length>o;o++)for(let n=o+1;t.length>n;n++){const i=Wn(t[o],t[n]);e instanceof Map?e.set(i,[t[o],t[n]]):e.add(i)}};for(const t of c.values())d([...t],l);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[n,i]]of l)u.has(t)&&(Bn(e[n],e[i])||Bn(o[n],o[i])&&(h.add(n),h.add(i)));return{conflicts:(t,o)=>{const n=i.get(t),a=i.get(o);return null!=n&&null!=a&&n!==a||!(null!=n==(null!=a)||s.has(Wn(t,o))||r.has(t)&&r.has(o)&&Xn(t,o,r))||!!Bn(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(Wn(t,o))}}}(a,s,n,e,l,u),h=function(t,e,o=new Map){const n=[],i=[];for(const r of t){let t=n.findIndex(t=>t.every(t=>!e.conflicts(r,t))&&!qn(r,t,o));-1!==t||o.has(r)||(t=n.findIndex(t=>t.every(t=>!e.conflicts(r,t)))),-1===t&&(t=n.length,n.push([])),n[t].push(r),i.push(t)}return{assignment:i,slotCount:n.length}}(a,d,u),f=function(t,e,o,n){if(0===t.length||t.length>12||1>=n.slotCount)return n.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Float64Array(t.length)),s=Array.from({length:t.length},()=>new Map),a=Array.from({length:t.length},()=>new Map),c=jn(o);for(const t of o){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o||e===o)continue;const n=Gn(t,c);r[e][o]+=n,r[o][e]+=n,a[e].set(o,(a[e].get(o)??0)+n),s[o].set(e,(s[o].get(e)??0)+n)}const l=Yn(o),u=t.map(t=>l.get(t)?.weight??0),d=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;t.length>e;e++)for(let o=e+1;t.length>o;o++){for(const[t,n]of s[e])d[e][o]+=Math.min(n,s[o].get(t)??0);for(const[t,n]of a[e])d[e][o]+=Math.min(n,a[o].get(t)??0);if(l.has(t[e])&&l.has(t[o])){const n=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=Xn(t[e],t[o],l)?n:-n}d[o][e]=d[e][o]}let h=[...n.assignment],f=(e=>{let o=0,n=0;for(let i=0;t.length>i;i++)for(let s=i+1;t.length>s;s++)e[i]===e[s]&&(o+=r[i][s],n+=d[i][s]);return{flow:o,affinity:n}})(h),p=0;const y=Array(t.length).fill(-1),g=Array.from({length:n.slotCount},()=>[]),m=(o,i,s,a)=>{if(p>=75e3)return;if(o===t.length)return p++,void((s>f.flow||s===f.flow&&a>f.affinity||s===f.flow&&a===f.affinity&&function(t,e){for(let o=0;Math.min(t.length,e.length)>o;o++)if(t[o]!==e[o])return e[o]>t[o];return e.length>t.length}(y,h))&&(h=[...y],f={flow:s,affinity:a}));const c=Math.min(i+1,n.slotCount-1);for(let n=0;c>=n;n++){if(g[n].some(n=>e.conflicts(t[o],t[n])))continue;let c=0,l=0;for(const t of g[n])c+=r[o][t],l+=d[o][t];if(y[o]=n,g[n].push(o),m(o+1,Math.max(i,n),s+c,a+l),g[n].pop(),y[o]=-1,p>=75e3)return}};return y[0]=0,g[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:Vn(a,d,e,h)}),p=new Map,y=f.map(t=>(p.has(t)||p.set(t,p.size),p.get(t))),g=Array.from({length:p.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=tn();a.forEach((t,e)=>{const o=y[e],n=g[o];n.occupants.push({id:t,end:s[t].end??-1/0});const i=c.get(t)?.group;i&&(n.group=i),m[t]=o});for(const e of[...t].sort((t,e)=>en(t.id,e.id)))null==m[e.id]&&(g[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of g){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||en(t.id,e.id));for(const e of t.occupants){const n=o[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,n?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,n?.botPeak||0)}}const x={slots:g,slotByNode:m};return function(t,e){for(zn.has(t)&&zn.delete(t),zn.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(tn(),e.slotByNode)});zn.size>12;){const t=zn.keys().next().value;if(null==t)break;zn.delete(t)}}(i,x),x}function Kn(t){return t.topMass+t.botMass}function Zn(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>Kn(e)<Kn(t)?t:e,o[0]);let n=null;for(const o of t.samples){if(o.t>e)break;n=o}return n}function Qn(t,e,o,n,i,r,s=0){const a=new Map;for(const o of t){if(!o.group||!e[o.id])continue;const t=a.get(o.group)??[];t.push(o),a.set(o.group,t)}if(0===a.size||0>=r)return e;const c=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}]));for(const[t,l]of a){const a=o.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=i[u.occupants[0]?.id],f=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;const p=(h-u.peak.topPeak*r+(f+d.peak.botPeak*r))/2,y=[...new Set(l.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),g=new Map;for(const t of l)g.set(t.id,new Map);for(const t of y){const o=new Map;for(const i of l){const r=Zn(e[i.id],t);if(!r||1e-9>=Kn(r))continue;const s=n[i.id];if(null==s)continue;const a=o.get(s)??[];a.push({node:i,sample:r}),o.set(s,a)}const a=[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>Kn(t)))}));if(0===a.length)continue;let c=p-(a.reduce((t,e)=>t+e.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const e of a){for(const{node:o,sample:n}of e.active){const e=(c-i[o.id])/r+n.topMass-(n.boundaryOffset??0);g.get(o.id).set(t,e)}c+=e.mass*r+Math.max(0,s)}}for(const t of l){const o=e[t.id],n=c[t.id],i=g.get(t.id),r=[];for(const t of y){const e=i.get(t),n=o.samples.filter(e=>e.t===t);if(n.length>0){r.push(...n.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const s=Zn(o,t);null!=e&&s&&Kn(s)>1e-9&&r.push({...s,t:t,boundaryOffset:(s.boundaryOffset??0)+e})}n.samples=r,n.localAttachments=new Map([...o.localAttachments].map(([t,e])=>{const o=i.get(e.time);return[t,{...e,...null!=o?{boundaryOffset:(e.boundaryOffset??0)+o}:{}}]}))}}return c}function Jn(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:c,laneOrder:l,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=i,y=tn(),g=tn();for(const e of t)y[e.id]=o[e.id].topPeak||0,g[e.id]=o[e.id].botPeak||0;const m="half"===u,x=tn();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,o=Array.isArray(e.xExtent)?e.xExtent[1]:null;let i=null!=t&&Number.isFinite(t)?t:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const t of n.outgoing[e.id]){i>t.startTime&&(i=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&i>t.systemInTime&&(i=t.systemInTime);const e=m?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of n.incoming[e.id]){const e=m?(t.startTime+t.endTime)/2:t.startTime;i>e&&(i=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}x[e.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}let b=tn(),v=[],w=[];if(i.frozenSlots){const t=Dn(i.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(on)}else if("reuse"===c){const n=Un(t,e,o,x);v=n.slots,b=n.slotByNode}else t.forEach((t,e)=>{v.push({occupants:[{id:t.id,end:x[t.id]?.end??-1/0}],peak:{topPeak:y[t.id],botPeak:g[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});Pn(v,b),0===w.length&&(w=v.map(on));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(t,e,o){const n=new Map(o.map((t,e)=>[t,e]));kn(t,e,[...t].sort((t,e)=>(n.get(on(t))??1/0)-(n.get(on(e))??1/0)||en(on(t),on(e))))}(v,b,i.fixedSlotOrder):i.runOrdering&&l&&"insertion"!==l&&(k=Fn(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:l,ribbonLane:f,domain:p}))),Pn(v,b);const A=cn(t,e,o,v,b,{plotH:r,padding:s,valueScale:a,stackValueScale:i.stackValueScale,lanePlacement:d,groupPadding:h}),S=0===v.length?0:v[0].peak.topPeak+A.adjacentClearance.reduce((t,e)=>t+e,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,L=k?.after.weightedLength??null;return{effectiveSlotsHeight:S,centerlines:A.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:A.slotCenter,stackCenter:A.stackCenter,verticalUtilization:A.verticalUtilization,selectedSlotOrder:v.map(on),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function ti(t){const{sx:e,sTop:o,sBot:n,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:c}=t,l=(o+n)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${c},${r} ${i},${r}`,`L${i},${s}`,`C${c},${s} ${a},${n} ${e},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:l},{x:a,y:l},{x:c,y:u},{x:i,y:u}],halfWidth:(n-o)/2}}}function ei(t,e,o,n,i,r,s,a,c={}){const l=i,u=t=>a?Math.max(a[0],Math.min(a[1],t)):t;let d=r(u(t.time));const h=r(u(o.time)),f=t.value*l,p=o.value*l,y=e+(t.boundaryOffset??0)*l,g=n+(o.boundaryOffset??0)*l,m=t.sideMassBefore*l,x=o.sideMassAfter*l;let b,v,w,k;"top"===t.side?(b=y-m,v=b+f):(v=y+m,b=v-f),"top"===o.side?(w=g-x,k=w+p):(k=g+x,w=k-p);const A=c.sourceRunwayStart,S=c.minRun,M=Math.abs((w+k)/2-(b+v)/2),_=h-d,P="number"==typeof A&&Number.isFinite(A),L="number"==typeof S&&Number.isFinite(S)&&S>0;if(P&&M>1e-9&&_>0&&("auto"===S||L)){const e="source"===s?.85:"target"===s?.15:.5,o="auto"===S?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(e*e,(1-e)*(1-e))))):S;if(o>_){const e=r(u(Math.min(A,t.time)));Number.isFinite(e)&&(d=Math.min(d,Math.max(Math.min(d,e),h-o)))}}const $="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:b,sBot:v,tx:h,tTop:w,tBot:k,cp1X:$,cp2X:$}}function oi(t){return Math.max(18,11*t.length*.58)}function ni(t){const e=1.22*oi(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function ii(t,e){const o=t.labelX-oi(t.labelText),n=e.labelX-oi(e.labelText);return e.labelX+3>=o&&t.labelX+3>=n}var ri=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function si(t){return t.replace(ri,(t,e,o)=>`${o},${e}`)}function ai(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function ci(t){return{...t,pathD:si(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function li(t){return{type:"hatch",background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle}}var ui=null;var di=new WeakMap;function hi(t,e){if(!e)return e;const o=function(t){const e=t.trim();if(!e.startsWith("var(")||!e.endsWith(")"))return null;const o=e.slice(4,-1),n=o.indexOf(",");if(-1===n){const t=o.trim();return t.startsWith("--")?{name:t}:null}const i=o.slice(0,n).trim(),r=o.slice(n+1).trim();return i.startsWith("--")?{name:i,fallback:r||void 0}:null}(e);if(!o)return e;const n=()=>o.fallback?hi(t,o.fallback):e,i=t.canvas;if(!i)return n();let r=di.get(i);r&&0===r.version||(r={version:0,map:new Map},di.set(i,r));const s=r.map.get(e);if(void 0!==s)return s;const a=getComputedStyle(i).getPropertyValue(o.name).trim()||n()||e;return r.map.set(e,a),a}import{jsx as fi,jsxs as pi}from"react/jsx-runtime";function yi(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function gi(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}var mi=new Map;function xi(t,e){const{background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,c=Math.max(8,Math.ceil(2*r));return pi("pattern",{id:e,width:c,height:c,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&fi("rect",{width:c,height:c,fill:o}),fi("line",{x1:0,y1:0,x2:0,y2:c,stroke:n,strokeWidth:i,strokeOpacity:a}),fi("line",{x1:r,y1:0,x2:r,y2:c,stroke:n,strokeWidth:i,strokeOpacity:a})]},e)}function bi(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:c,colorOf:l,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:y="raw",styleRules:g,colorBy:m,valueAccessor:x,usageMode:b="static"}=t,v="vertical"===d?r:i,w="vertical"===d?i:r,k=function(t,e,o,n={}){const i=qo(n.usageMode??"static"),r=[],s=new Set;for(const e of t)s.has(e.id)&&r.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),s.add(e.id);const a=new Set,c=Array.isArray(o)&&2===o.length,l=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]);c&&l&&l&&o[1]>=o[0]||r.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||r.push({kind:"invalid-node-time",id:e.id}));for(const t of e)a.has(t.id)&&r.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),a.add(t.id),s.has(t.source)||r.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),s.has(t.target)||r.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&r.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),Number.isFinite(t.value)&&t.value>0||r.push({kind:"invalid-value",id:t.id}),t.startTime>t.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):r.push({kind:"invalid-edge-time",id:t.id});return r}(e,o,n,{usageMode:b}),{fatal:A,warnings:S}=function(t){const e=[],o=[];for(const n of t)"fatal"===Vo(n)?e.push(n):o.push(n);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==qo(o).invalidSystemTime)return t;const n=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===n.size?t:t.map(t=>{if(!n.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}(o,k,b),_=Yo().domain(n).range([0,v]);if(A.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:A,warnings:S,xScale:_};const P=function(t,e,o){const{plotH:n,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:c,lanePlacement:l="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=o,p=Number.isFinite(d)?Math.max(0,d):0,y=function(t,e){const o=tn(),n=tn();for(const e of t)o[e.id]=[],n[e.id]=[];for(const t of e)n[t.source]&&n[t.source].push(t),o[t.target]&&o[t.target].push(t);return{incoming:o,outgoing:n}}(t,e),g=function(t,e,o,n="temporal"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime||en(t.id,e.id):(t,e)=>e.value-t.value||en(t.id,e.id),r="temporal"===n?(t,e)=>t.startTime-e.startTime||en(t.id,e.id):(t,e)=>e.value-t.value||en(t.id,e.id),s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const o=new Map;for(const n of t){const t=n[e];o.has(t)||o.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=o.get(t);i.edges.push(n),i.total+=n.value,i.earliestStart=Math.min(i.earliestStart,n.startTime),i.latestEnd=Math.max(i.latestEnd,n.endTime)}const s=[...o.values()];s.sort("temporal"===n?(t,o)=>"target"===e?t.earliestStart-o.earliestStart||en(t.partner,o.partner):t.latestEnd-o.latestEnd||en(t.partner,o.partner):(t,e)=>e.total-t.total||en(t.partner,e.partner));for(const t of s)t.edges.sort("target"===e?r:i);return s};for(const e of t){const t=o.outgoing[e.id],n=o.incoming[e.id];if(0===n.length)a(t,"target").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=o});else if(0===t.length)a(n,"source").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=o});else{const e=a(n,"source"),o=a(t,"target"),i=Math.max(e.length,o.length);for(let t=0;i>t;t++){const n=t%2==0?"top":"bot";if(e[t])for(const o of e[t].edges)s.get(o.id).targetSide=n;if(o[t])for(const e of o[t].edges)s.get(e.id).sourceSide=n}}}return s}(t,e,y,i);let m=tn();for(const e of t)m[e.id]=vn(e,y,g,void 0,u);const x=Jn(t,e,m,y,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),b=x.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),v=new Set;for(const t of e){const e=x.slotByNode[t.source],o=x.slotByNode[t.target];if(void 0===e||void 0===o)continue;const n=g.get(t.id);e!==o?e>o?(n.sourceSide="top",n.targetSide="bot"):(n.sourceSide="bot",n.targetSide="top"):(v.add(t.id),n.sourceSide="bot",n.targetSide="bot")}for(const e of t){const t=y.outgoing[e.id],o=y.incoming[e.id],n=new Set(t.map(t=>g.get(t.id).sourceSide)),i=new Set(o.map(t=>g.get(t.id).targetSide));if(1===n.size&&o.length>0){const t=[...n][0];for(const e of o)x.slotByNode[e.source]===x.slotByNode[e.target]&&(g.get(e.id).targetSide=t)}if(1===i.size&&t.length>0){const e=[...i][0];for(const o of t)x.slotByNode[o.source]===x.slotByNode[o.target]&&(g.get(o.id).sourceSide=e)}}!function(t,e,o){const n=new Map,i=[];for(const e of t)i.push({time:e.startTime,kind:"out",edge:e}),i.push({time:e.endTime,kind:"in",edge:e});i.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||en(t.edge.id,e.edge.id));const r=t=>{let e=n.get(t);return e||(e={top:0,bot:0},n.set(t,e)),e},s=(t,e,o)=>{const n="top"===e?"bot":"top",i=Math.min(o,t[e]);t[e]-=i;const r=o-i;r>0&&(t[n]=Math.max(0,t[n]-r))};for(const t of i){const{edge:n}=t;if("in"===t.kind){const t=e.get(n.id)?.targetSide??"bot";r(n.target)[t]+=n.value;continue}const i=r(n.source),a=e.get(n.id);let c=a.sourceSide??"bot";if(o[n.source]===o[n.target]){const t=i.top>=n.value,e=i.bot>=n.value;t!==e?c=t?"top":"bot":t||e||i.top===i.bot||(c=i.top>i.bot?"top":"bot"),a.sourceSide=c,a.targetSide=c}s(i,c,n.value)}}(e,g,x.slotByNode),function(t,e,o,n){for(const i of t){const t=e.incoming[i.id],r=e.outgoing[i.id];if(0===t.length||0===r.length)continue;const s=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const n of t)"top"===o.get(n.id).targetSide?e.inTop+=n.value:e.inBot+=n.value;for(const t of r)"top"===o.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},a=(t,e)=>{const i=s(),a="top"===t?i.outTop-i.inTop:i.outBot-i.inBot,c="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=c)return!1;const l=Math.min(a,c),u=r.filter(e=>!n.has(e.id)&&o.get(e.id).sourceSide===t&&l>=e.value).sort((t,e)=>e.value-t.value||en(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let c=r.length+1;for(;c-- >0&&(a("top","bot")||a("bot","top")););}}(t,y,g,v),m=tn();for(const e of t)m[e.id]=vn(e,y,g,void 0,u);const w=Jn(t,e,m,y,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),A=w.slots.slice(0,-1).reduce((t,e,o)=>t+(null!=e.group&&e.group===w.slots[o+1].group?1:0),0),S=Math.max(1,w.slots.length+1-A),M=Math.min(12,Math.max(0,.35*n-A*p)/S),_=2*M+nn(w.slots,M,p).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(n-_)/k):1,L=Number.isFinite(c)&&c>0?Math.min(P,c):P;let $=Jn(t,e,m,y,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P});const R=Number.isFinite(c)&&c>0&&P>c+1e-12;if("insertion"!==s&&("hug"===l||R)&&$.slots.length>1&&(Fn(t,e,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:n,padding:M,valueScale:L,groupPadding:p,laneOrder:s,ribbonLane:h,domain:f,lanePlacement:l,mode:"geometry-refine"}),$=Jn(t,e,m,y,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(on),lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})),function(t,e){const o=(t,o)=>{for(const n of t){const t=new Map;for(const i of n){const n=`${("out"===o?e.get(i.id)?.sourceSide:e.get(i.id)?.targetSide)??""}\0${"out"===o?i.startTime:i.endTime}`,r="out"===o?`${i.target}\0${i.endTime}`:`${i.source}\0${i.startTime}`,s=t.get(n);if(null!=s&&s!==r)return!0;t.set(n,r)}}return!1};return o(Object.values(t.outgoing),"out")||o(Object.values(t.incoming),"in")}(y,g)){const o=function(t,e,o,n){const i=new Map;for(const r of t){const t=e[r.source]?.localAttachments.get(r.id),s=e[r.target]?.localAttachments.get(r.id),a=o[r.source],c=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(c)))continue;const l=bn(t,a,n),u=bn(s,c,n);i.set(r.id,{source:(l[0]+l[1])/2,target:(u[0]+u[1])/2})}return i}(e,m,$.centerlines,L);m=tn();for(const e of t)m[e.id]=vn(e,y,g,o,u);$=Jn(t,e,m,y,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(on),lanePlacement:l,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}const T=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),I=[...$.slots].sort((t,e)=>(T.get(on(t))??1/0)-(T.get(on(e))??1/0)||en(on(t),on(e))),C=tn();I.forEach((t,e)=>{for(const o of t.occupants)C[o.id]=e});const O=cn(t,e,m,I,C,{plotH:n,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),F=Qn(t,m,I,C,O.centerlines,L,p),D=gn($n(C,e),Rn(C,e),e,F,I,C,O.centerlines,$.laneLifetime,L,O.verticalUtilization,h,f);m=Qn(t,m,$.slots,$.slotByNode,$.centerlines,L,p);const z=gn($n($.slotByNode,e),Rn($.slotByNode,e),e,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,f);return{nodeData:m,sides:g,valueScale:L,padding:M,compressedPadding:12>M,centerlines:$.centerlines,laneLifetime:$.laneLifetime,slots:$.slots,slotByNode:$.slotByNode,crossingsBefore:"insertion"===s?null:D.crossings,crossingsAfter:"insertion"===s?null:z.crossings,lengthBefore:"insertion"===s?null:D.weightedLength,lengthAfter:"insertion"===s?null:z.weightedLength,layoutQualityBefore:D,layoutQuality:z}}(e,M,{plotH:w,...u,ribbonLane:s,domain:n}),{centerlines:L,nodeData:$,valueScale:R}=P,T=it(m,x),I=[],C=[],O=0===a?new Map:function(t,e,o){const n=new Set(e.map(t=>t.target)),i=new Map(t.map(t=>[t.id,t])),r=new Map;for(const t of e){if(n.has(t.source))continue;const e=r.get(t.source)??[];e.push(t),r.set(t.source,e)}const s=new Map;for(const e of t){if(!e.group)continue;const t=s.get(e.group)??[];t.push(e),s.set(e.group,t)}const a=new Set;for(const[t,e]of s){const o=e.flatMap(t=>r.get(t.id)??[]),i=new Set(o.map(t=>t.startTime));o.length>0&&1===i.size&&e.every(t=>{const e=t.xExtent?.[0],i=o[0].startTime;return!n.has(t.id)&&(r.get(t.id)?.length??0)>0&&Number.isFinite(e)&&i>e})&&a.add(t)}const c=new Map;for(const[t,e]of r){const n=i.get(t);if(n?.group&&!a.has(n.group))continue;const r=n?.xExtent?.[0],s=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),l=s[0]?.startTime-1;let u=null;for(let t=0;s.length>t;){const e=s[t].startTime;let n=t+1;for(;s.length>n&&s[n].startTime===e;)n++;for(let e=t;n>e;e++){const t=s[e],n=Number.isFinite(r)&&t.startTime>r,i=Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime;if(!n&&!i)continue;let a=o[0];n&&(a=Math.max(a,r)),i&&(a=Math.max(a,t.systemInTime)),!n&&i&&Number.isFinite(l)&&(a=Math.max(a,l)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&c.set(t.id,a)}u=e,t=n}}for(const[t,e]of s){if(!a.has(t))continue;const o=e.flatMap(t=>r.get(t.id)??[]);if(!o.every(t=>c.has(t.id))){for(const t of o)c.delete(t.id);continue}const n=Math.max(...o.map(t=>c.get(t.id)));for(const t of o)c.set(t.id,n)}return c}(e,M,n),F=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),D=new Map;for(const t of M){const e=$[t.source]?.localAttachments.get(t.id),o=$[t.target]?.localAttachments.get(t.id);e&&o&&D.set(t.id,ei(e,L[t.source],o,L[t.target],R,_,s,n,{minRun:a,sourceRunwayStart:O.get(t.id)}))}const z=function(t,e,o,n,i,r){const s=new Map(e),a=new Map;for(const e of t){const t=r?.get(e.source),o=null==t?"node:"+e.source:"group:"+t,n=a.get(o)??new Map,i=n.get(e.startTime)??[];i.push(e),n.set(e.startTime,i),a.set(o,n)}for(const t of a.values())for(const[r,a]of t){if(!a.some(t=>o.has(t.id)))continue;const t=a.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const c=n(r),l=Math.min(...t.map(t=>t.sx));if(l>=c-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?c:Math.min(c,n(e))})),d=Math.min(c,Math.max(l,u));for(const t of a){const o=e.get(t.id),n=d+(o.tx-d)*("source"===i?.85:"target"===i?.15:.5);s.set(t.id,{...o,sx:d,cp1X:n,cp2X:n})}}return s}(M,D,O,_,s,F),N=function(t,e,o,n,i){const r=new Map;for(const s of t){if(!o.has(s.id))continue;const t=e.get(s.id);if(!t||t.sx>=n(s.startTime)-1e-9)continue;const a=i(t.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,z,O,_,t=>n[0]+t/v*(n[1]-n[0])),E=function(t,e,o){const n=new Map,i=new Map;for(const[t,e]of o??[]){const o=i.get(e)??[];o.push(t),i.set(e,o)}for(const r of t){const t=e.get(r.id);if(null==t||!Number.isFinite(t)||t>=r.startTime)continue;const s=o?.get(r.source),a=null==s?[r.source]:i.get(s)??[r.source];for(const e of a){const o=n.get(e)??new Map,i=o.get(r.startTime);o.set(r.startTime,null==i?t:Math.min(i,t)),n.set(e,o)}}return n}(M,N,F);e.forEach((t,e)=>{const o=$[t.id];if(!o||0===o.samples.length)return;const i=(r=o.samples,(s=E.get(t.id))&&0!==s.size?r.map(t=>{const e=s.get(t.t);return null==e?t:{...t,t:e}}):r);var r,s;const a=function(t,e,o,n,i){if(0===t.length)return null;const r=xn(t,i),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,c=t=>s(t)+r[t].botMass*o;let l=`M${n(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)l+=` L${n(r[t].t)},${a(t)}`;l+=` L${n(r[r.length-1].t)},${c(r.length-1)}`;for(let t=r.length-2;t>=0;t--)l+=` L${n(r[t].t)},${c(t)}`;return l+" Z"}(i,L[t.id],R,_,n);if(!a)return;const c=xn(i,n),u=c.find(t=>t.topMass+t.botMass>0)||c[0],h=L[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let f,p,y=l(t.id,e),m=y,x=.5;const b=t.__raw??t;if(g&&g.length>0){const t=at(b,g,T(b));"string"==typeof t.fill?y=t.fill:null!=t.fill&&yi(t.fill)&&(p=t.fill,y=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:y),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(x=t.strokeWidth),"number"==typeof t.fillOpacity&&(f=t.fillOpacity),"number"==typeof t.opacity&&null==f&&(f=t.opacity)}const v=function(t,e,o,n,i,r){const s=o.nodeData[t];if(!s||0===s.samples.length)return[];const a=o.valueScale,c=o.centerlines[t],l=xn(s.samples,i),u=l.find(t=>t.topMass+t.botMass>0)||l[0],d=[...l].reverse().find(t=>t.topMass+t.botMass>0)||l[l.length-1],h=n(u.t),f=n(d.t),p=t=>n(mn(t,i)),y=[],g=(t,e,o,n)=>`M${t},${e} L${o},${e} L${o},${n} L${t},${n} Z`;for(const o of e){if(o.source===t&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const t=s.localAttachments.get(o.id),e=r?.get(o.id)??o.startTime;if(t&&"out"===t.kind&&e>o.systemInTime){const n=p(o.systemInTime),r=p(e),s=null!=i&&i[0]>o.systemInTime,l=s?n:n-20,u=s?Math.min(r,n+20):n,d=Math.max(h,l);if(r>d){const[e,o]=bn(t,c,a);y.push({pathD:g(d,e,r,o),x0:l,x1:u,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=s.localAttachments.get(o.id);if(t&&"in"===t.kind&&o.systemOutTime>o.endTime){const e=p(o.systemOutTime),n=p(o.endTime),i=e+20,r=Math.min(f,i);if(r>n){const[o,s]=bn(t,c,a);y.push({pathD:g(n,o,r,s),x0:e,x1:i,from:1,to:0})}}}}return y}(t.id,M,P,_,n,N);I.push({id:t.id,pathD:a,fill:y,stroke:m,strokeWidth:x,...null!=f&&{fillOpacity:f},...p&&{hatchFill:p},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&t.xExtent?t.xExtent[0]:u.t)-4,labelY:h,labelText:t.label??t.id})});const B=new Map;e.forEach((t,e)=>B.set(t.id,e)),M.forEach(t=>{const e=z.get(t.id);if(!e)return;const o=B.get(t.source)??0,n=l(t.source,o),{pathD:i,bezier:r}=ti(e),s=t.__raw??t,a="function"==typeof c?Number(c(s)):c,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;C.push({id:t.id,pathD:i,fill:n,opacity:u,rawDatum:s,bezier:r})});const W=function(t,e,o){const n=t.map(t=>({...t})),i=new Map;for(const t of n){const o=e[t.id];if(null==o)continue;const n=i.get(o)??[];n.push(t),i.set(o,n)}const r=t=>{if(2>t.length)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,n=(t.length-1)/2;t.forEach((t,i)=>{t.labelY=Math.max(8,Math.min(o-8,e+16*(i-n)))})};for(const t of i.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],o=-1/0;for(const n of t){const t=n.labelX-oi(n.labelText);e.length>0&&t>o+3&&(r(e),e=[],o=-1/0),e.push(n),o=Math.max(o,n.labelX)}r(e)}return function(t,e){const o=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;3>t;t+=1){for(let t=0;o.length>t;t+=1){let e=8;for(let n=0;t>n;n+=1)ii(o[t],o[n])&&(e=Math.max(e,o[n].labelY+16));o[t].labelY=Math.max(o[t].labelY,e)}for(let t=o.length-1;t>=0;t-=1){let n=e-8;for(let e=t+1;o.length>e;e+=1)ii(o[t],o[e])&&(n=Math.min(n,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,n)}}}(n,o),n}(I,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:si(t.pathD),gradientStubs:t.gradientStubs?.map(ci),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,d)),j="vertical"===d?function(t,e,o){const n=t.map(t=>({...t}));for(const t of n){const o=1.22*oi(t.labelText)+4;t.labelX=e-4>o?Math.max(o/2+2,Math.min(e-o/2-2,t.labelX)):e/2}const i=[],r=[...n].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of r){const e=i[i.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?i.push([t]):e.push(t)}for(const t of i){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],n=new Map;for(const o of t){const[t,i]=ni(o);let r=e.findIndex(e=>t>e+8);-1===r&&(r=e.length),e[r]=i,n.set(o,r)}const i=t.reduce((t,e)=>t+e.labelY,0)/t.length,r=14*e.length+8>i;for(const e of t){const t=n.get(e)??0;e.labelY=r?Math.min(o-8,12+14*t):Math.max(8,i-14*t)}}return n}(W,i,r):W,Y=new Map;if(null!=f)for(const t of e){const e=t.__raw??t,o="function"==typeof f?f(e):Number(e[f]);Number.isFinite(o)&&Y.set(t.id,o)}const X=function(t,e,o,n,i={}){if(!1===n)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===n)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(t.length,Math.floor(Math.max(1,e*o)/14e3)));Number.isFinite(i.maxLabels)&&i.maxLabels>=0&&(r=Math.min(r,Math.floor(i.maxLabels)));const s=t.map((t,e)=>{const o=i.priorityById?.get(t.id),n=Math.abs(t.labelY);return{band:t,index:e,score:null!=o&&Number.isFinite(o)?1e6*o+oi(t.labelText):oi(t.labelText)+.01*n}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),a=new Set(s.slice(0,r).map(t=>t.band.id));return t.map(t=>a.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(j,i,r,h,{...Y.size>0&&{priorityById:Y},...null!=p&&{maxLabels:p}});return{layout:P,layoutConfig:{bands:X,ribbons:C.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:si(t.pathD),bezier:ai(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:y},issues:[],warnings:S,xScale:_}}import{Fragment as vi,jsx as wi,jsxs as ki}from"react/jsx-runtime";var Ai="var(--semiotic-grid, #94a3b8)",Si="var(--semiotic-text-secondary, #475569)",Mi="var(--semiotic-text-secondary, #94a3b8)",_i=.22;function Pi(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var Li=t=>{const{bands:e=[],ribbons:o=[],showLabels:n=!0,selectionDatum:i="raw"}=t.config,r=t.selection??null,s=[];for(const t of o){const e={__kind:"ribbon",data:t.rawDatum,id:t.id},o=!Pi(e,r,i);s.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:o?Math.min(t.opacity,_i):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!Pi({__kind:"band",data:t.rawDatum,id:t.id},r,i);for(let o=0;t.gradientStubs.length>o;o++){const n=t.gradientStubs[o];s.push({type:"bezier",pathD:n.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:e?_i:t.fillOpacity??.86,stroke:"none"},_gradient:{x0:n.x0,x1:n.x1,...null!=n.y0&&{y0:n.y0},...null!=n.y1&&{y1:n.y1},from:n.from,to:n.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${o}`}})}}for(const t of e){const e=!(!t.gradientStubs||0>=t.gradientStubs.length),o={__kind:"band",data:t.rawDatum,id:t.id},n=!Pi(o,r,i);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:n?_i:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...n&&e?{opacity:_i}:{}},datum:o})}const a=n?e.flatMap(t=>{const e=t.labelDeferred&&t.labelFullText?.trim(),o=t.labelText.trim().length>0,n=e&&r?.isActive&&Pi({__kind:"band",data:t.rawDatum,id:t.id},r,i),s=o?t.labelText:n?t.labelFullText:"";return s.trim()?[{x:t.labelX,y:t.labelY,text:s,anchor:t.labelAnchor??"end",baseline:t.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:s,labels:a}};function $i(t,e){if(!t)return[];const o=[],n=t=>{o.push(t);const i="function"==typeof e?e(t):t[e];i&&Array.isArray(i)&&i.forEach(n)};return n(t),o}function Ri(t,e,o,n){if(t&&t.length>0)return t;const i=new Set;return e.forEach(t=>{const e="function"==typeof o?o(t):t[o],r="function"==typeof n?n(t):t[n];i.add(e),i.add(r)}),Array.from(i).map(t=>({id:t}))}function Ti(t,e,o={}){return et(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var Ii={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{if(!(e||Array.isArray(i.styleRules)&&i.styleRules.length>0||n.nodeStyle||i.nodeStyle||tt(gt(i))))return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:o,...n,showLegend:(n.showLegend??!!e)&&!!e};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:Ri([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=St(n.theme).colors.categorical,c=G(o,a),l="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?Q(u,l,o??n.colorScheme??a):void 0,h=new Map,f=i.nodeIdAccessor||i.nodeIDAccessor||"id",p=(t,o)=>{const n=t?.data||t;let r;if(e)r=K(n,e,d);else{const e=(t.id??n?.[f]??"")+"";h.has(e)||h.set(e,h.size);const i=t.index??o??h.get(e);r=c[i%c.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},y=lt(i.styleRules,e,i.valueAccessor);return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:o,nodeStyle:et(i.nodeStyle||(y?(t,e)=>({...p(t,e),...y(t,e)}):p),gt(i)),...n,showLegend:(n.showLegend??!!e)&&!!e}}},Ci={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=function(t){if(void 0!==t.edgeStyle)return t.edgeStyle;const{edgeWidth:e,edgeColor:o,edgeOpacity:n}=t,i=t.strokeWidth??1;return void 0!==e||void 0!==o||void 0!==n||void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity?r=>{const s=r?.data||r;let a=i;if("number"==typeof e)a=e;else if("function"==typeof e)a=e(s);else if("string"==typeof e){const t=s?.[e],o="number"==typeof t?t:Number(t);a=Number.isFinite(o)&&o>0?o:i}return{stroke:o??t.stroke??"#999",strokeWidth:a,opacity:n??t.opacity??.6}}:void 0}(i),s=St(n.theme).colors.categorical,a=new Map,c=i.nodeStyle??(t=>({fill:e?K(t?.data||t,e,void 0):Se(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),l=lt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=et(l?(t,e)=>({...c(t),...l(t,e)}):c,{stroke:i.nodeStroke??i.stroke,strokeWidth:i.nodeStrokeWidth??i.strokeWidth,opacity:i.opacity});return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:e,colorScheme:o,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:u,edgeStyle:r,...n,showLegend:(n.showLegend??!!e)&&!!e}}},Oi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=St(n.theme).colors.categorical,s=new Map,a=$i(t??null,i.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrCirclePackColorBy:c(t)})):a,u=c?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?Q(l,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,f=n.nodeStyle||i.nodeStyle,p=ct(t=>{const n=t?.data||t;return{fill:i.colorByDepth?H[Number(t?.depth||0)%H.length]:e?c?K({__ssrCirclePackColorBy:c(n)},"__ssrCirclePackColorBy",d??void 0):K(n,e,d??void 0):Se(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},i.styleRules,it(e,i.valueAccessor),t=>t?.data||t);return{chartType:"circlepack",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:o,...n,showLegend:(n.showLegend??!(!e||i.colorByDepth))&&!(!e||i.colorByDepth),nodeStyle:Ti(p,f,gt(i))}}},Fi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=t??i.data,s=i.childrenAccessor||"children",a=i.nodeIdAccessor||i.nodeIDAccessor||"name",c=St(n.theme).colors.categorical,l=o??n.colorScheme??c,u=G(l,c),d=$i(r,s),h="__ssrOrbitColorBy",f="function"==typeof e?e:null,p=e?Q(f?d.map(t=>({[h]:f(t)})):d,f?h:e,l):void 0,y=ct(t=>{const o=t.data||t,n=Number(t.depth??0);return{fill:i.colorByDepth?0===n?u[0]:H[n%H.length]:e?f?K({[h]:f(o)},h,p):K(o,e,p):u[0],stroke:"#fff",strokeWidth:1,opacity:0===n?1:.85}},i.styleRules,it(e,"value"),t=>t?.data||t);return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:l,colorByDepth:i.colorByDepth??!1,nodeSize:i.nodeRadius??6,nodeLabel:i.showLabels?a:void 0,showLabels:i.showLabels??!1,orbitMode:i.orbitMode??"flat",orbitSize:i.orbitSize??2.95,orbitSpeed:i.speed??.25,orbitRevolution:i.revolution,orbitRevolutionStyle:i.revolutionStyle,orbitEccentricity:i.eccentricity??1,orbitShowRings:i.showRings??!0,orbitAnimated:!1,nodeStyle:et(y,gt(i)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...n,showLegend:(n.showLegend??!(!e||i.colorByDepth))&&!(!e||i.colorByDepth)}}},Di={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,n,i)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",c=i.valueAccessor||"value",l=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,f=i.systemOutTimeAccessor,p=i.xExtentAccessor||"xExtent",y=i.groupBy,g=i.edgeIdAccessor||"id",m=(t,e)=>"function"==typeof t?t(e):e[t],x=Array.isArray(i.edges)?i.edges:[],b=Array.isArray(i.nodes)?i.nodes:[],v=b.length>0?b:Ri([],x,s,a),k=[r(i.domain?.[0]),r(i.domain?.[1])],A=v.map(t=>{const e=m(l,t)+"",o=m(p,t),n=i.nodeLabel?m(i.nodeLabel,t):e,s={id:e,label:null==n?e:n+"",__raw:t},a=y?m(y,t):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(s.xExtent=[t,e])}return s}),S=x.map((t,e)=>{const o=m(g,t),n={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(c,t)),startTime:r(m(u,t)),endTime:r(m(d,t)),__raw:t};if(h){const e=r(m(h,t));Number.isFinite(e)&&(n.systemInTime=e)}if(f){const e=r(m(f,t));Number.isFinite(e)&&(n.systemOutTime=e)}return n}),[M,_]=n.size??[600,400],P=n.margin,L="vertical"===i.orientation?"vertical":"horizontal",$=function(t,e,o,n="horizontal"){return"vertical"===n?{top:t?38:e?28:16,right:24,bottom:24,left:o?72:24}:{top:t?30:e?24:8,right:80,bottom:o?28:8,left:80}}(!!n.title,!!i.showQualityReadout,Array.isArray(i.axisTicks)&&i.axisTicks.length>0,L),R={...$,...P},T=(n.showLegend??!!e)&&!!e,I=n.legendPosition??"right";T&&("right"===I?R.right=Math.max(R.right,140):"left"===I?R.left=Math.max(R.left,140):"top"===I?R.top=Math.max(R.top,50):"bottom"===I&&(R.bottom=Math.max(R.bottom,80)));const C=R,O=M-C.left-C.right,F=_-C.top-C.bottom,D=G(o,St(n.theme).colors.categorical,w),z="function"==typeof e?e:null,N=z?v.map(t=>({_cat:z(t)})):v,E=z?"_cat":"string"==typeof e?e:void 0,B=o??[...D],W=E?Q(N,E,B):null,j=new Map;for(const t of A)j.set(t.id,t.__raw);const Y=(t,o)=>{if(e&&j.has(t)){const o=j.get(t);return z?K({_cat:z(o)},"_cat",W??void 0):K(o,"string"==typeof e?e:"id",W??void 0)}return D[o%D.length]},X=ne(T&&e?(()=>{const t=new Map;v.forEach((o,n)=>{const i=m(e,o),r=null==i?"":i+"";r&&!t.has(r)&&t.set(r,{label:r,color:Y(m(l,o)+"",n)})});const o=Array.from(t.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:t=>{const e=t.color||"#333";return{fill:e,stroke:e}}}]}:void 0})():void 0,n.legend),q=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:V,layoutConfig:H,issues:U,xScale:Z}=bi({nodes:A,edges:S,domain:k,plotW:O,plotH:F,orientation:L,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:Y,showLabels:q,styleRules:i.styleRules,colorBy:e,valueAccessor:c,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half",maxValueScale:"number"==typeof i.maxValueScale?i.maxValueScale:void 0,lanePlacement:i.lanePlacement||"stack",nodeSizing:i.nodeSizing||"temporal",groupPadding:"number"==typeof i.groupPadding?i.groupPadding:0}});if(U.length>0){const t=U.map(Ho).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const J=V?function(t){const e=t.layout,o=t.nodes,n=t.orientation,i=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,c=t.showQualityReadout??!1,l=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,f=t.toTime,p=t.xScale,{centerlines:y,laneLifetime:g,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:A}=e;let S=null,M=null;for(const t of o){const e=g[t.id];if(!e||null===e.start||null===e.end)continue;const o=p(e.start),n=p(e.end);(null===S||S>o)&&(S=o),(null===M||n>M)&&(M=n)}const _=t=>Math.max(0,Math.min(s,t)),P=_(S??0),L=Math.max(P,_(M??s)),$=a.map((t,e)=>({tick:t,index:e,coordinate:p(f(t.date))})).filter(({coordinate:t})=>t>=P-.5&&L+.5>=t),R=null!==(w??null)&&null!=k&&null!=A,T=c&&(R||u.length>0)?ki("g",{fill:Mi,fontSize:10,textAnchor:"end",children:[R&&ki(vi,{children:[ki("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(A.pixelLength)]}),ki("text",{x:i,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",A.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*A.verticalUtilization),"%"]})]}),u.map((t,e)=>ki("text",{x:i,y:R?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,I=b?wi("text",{x:i,y:"vertical"===n?-3:2,fontSize:10,fill:Mi,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,C=(t,e)=>h?h(t,e):Ai;return ki("g","vertical"===n?{children:[T,I,$.map(({index:t,coordinate:e})=>wi("line",{x1:0,y1:e,x2:i,y2:e,stroke:Ai,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),l&&o.map((t,e)=>{const o=g[t.id];if(!o||null===o.start)return null;const n=m[t.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=y[t.id]+(i.botPeak-i.topPeak)*x/2,s=p(o.start),a=p(o.end),c=C(t.id,e);return ki("g",{children:[wi("line",{x1:r,y1:s,x2:r,y2:a,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),wi("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:c,strokeOpacity:.5}),wi("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:c,strokeOpacity:.5})]},"lane-"+t.id)}),wi("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:Ai}),$.map(({tick:t,index:e,coordinate:o})=>{const n=f(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return ki("g",{transform:`translate(-4,${o})`,children:[wi("line",{x2:-6,stroke:Ai}),wi("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Si,children:i})]},e)})]}:{children:[T,I,$.map(({index:t,coordinate:e})=>wi("line",{x1:e,y1:0,x2:e,y2:r,stroke:Ai,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),l&&o.map((t,e)=>{const o=g[t.id];if(!o||null===o.start)return null;const n=m[t.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=y[t.id]+(i.botPeak-i.topPeak)*x/2,s=p(o.start),a=p(o.end),c=C(t.id,e);return ki("g",{children:[wi("line",{x1:s,y1:r,x2:a,y2:r,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),wi("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:c,strokeOpacity:.5}),wi("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:c,strokeOpacity:.5})]},"lane-"+t.id)}),wi("line",{x1:P,y1:r+4,x2:L,y2:r+4,stroke:Ai}),$.map(({tick:t,index:e,coordinate:o})=>{const n=f(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return ki("g",{transform:`translate(${o},${r+4})`,children:[wi("line",{y2:6,stroke:Ai}),wi("text",{y:20,textAnchor:"middle",fontSize:11,fill:Si,children:i})]},e)})]})}({layout:V,nodes:A,orientation:L,plotW:O,plotH:F,timelineExtent:"vertical"===L?F:O,axisTicks:Array.isArray(i.axisTicks)?i.axisTicks.map(t=>({date:t.date,label:t.label})):[],showQualityReadout:!!i.showQualityReadout,showLaneRails:!!i.showLaneRails,timeFormat:"function"==typeof i.timeFormat?t=>i.timeFormat(t):void 0,colorOf:Y,toTime:t=>r(t),xScale:t=>Number(Z(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:Li,layoutConfig:H,sourceAccessor:s,targetAccessor:a,valueAccessor:c,nodeIDAccessor:l,colorBy:e,colorScheme:o,...J&&{backgroundGraphics:J},...n,showLegend:T,...X&&{legend:X,legendPosition:I},__legendIncludesAutomatic:!0,margin:C}}},zi={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:Ri([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=St(n.theme).colors.categorical,a=new Map,c="string"==typeof e?e:"__ssrSankeyColorBy",l="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?Q(l,c,o??n.colorScheme??s):void 0,d=t=>({fill:e?K(t?.data||t,e,u):Se(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=lt(i.styleRules,e,i.valueAccessor),f=h?(t,e)=>({...d(t),...h(t,e)}):d,p=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:n,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof t)a.fill=t(s);else if("source"===t){const t="object"==typeof s.source?s.source:null;e&&t?a.fill=K(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=K(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:f,edgeOpacity:i.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,valueAccessor:i.valueAccessor,orientation:i.orientation,nodeAlign:i.nodeAlign,nodeWidth:i.nodeWidth,nodePaddingRatio:i.nodePaddingRatio,showLabels:i.showLabels,nodeLabel:i.nodeLabel,colorBy:e,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:et(i.nodeStyle||f,gt(i)),edgeStyle:et(i.edgeStyle||p,gt(i)),colorScheme:o,...n,showLegend:(n.showLegend??!!e)&&!!e}}},Ni={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=St(n.theme).colors.categorical,s=new Map,a=$i(t??null,i.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrTreeColorBy:c(t)})):a,u=c?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?Q(l,u,o??n.colorScheme??r):void 0,h=!1!==i.showLabels,f=n.nodeStyle||i.nodeStyle,p=ct(t=>{const n=t?.data||t;return{fill:i.colorByDepth?H[Number(t?.depth||0)%H.length]:e?c?K({__ssrTreeColorBy:c(n)},"__ssrTreeColorBy",d??void 0):K(n,e,d??void 0):Se(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},i.styleRules,it(e,i.valueAccessor),t=>t?.data||t);return{chartType:"cluster"===i.layout?"cluster":"tree",data:t,childrenAccessor:i.childrenAccessor,colorBy:e,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:o,...n,showLegend:(n.showLegend??!(!e||i.colorByDepth))&&!(!e||i.colorByDepth),nodeStyle:Ti(p,f,gt(i))}}},Ei={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=St(n.theme).colors.categorical,s=new Map,a=$i(t??null,i.childrenAccessor),c="function"==typeof e?e:null,l=c?a.map(t=>({__ssrTreemapColorBy:c(t)})):a,u=c?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?Q(l,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,f=i.labelMode,p=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,y=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,g=n.nodeStyle||i.nodeStyle,m=ct(t=>{const n=t?.data||t;return{fill:i.colorByDepth?H[Number(t?.depth||0)%H.length]:e?c?K({__ssrTreemapColorBy:c(n)},"__ssrTreemapColorBy",d??void 0):K(n,e,d??void 0):Se(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},i.styleRules,it(e,i.valueAccessor),t=>t?.data||t);return{chartType:"treemap",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:f,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=y&&{paddingTop:y},colorScheme:o,...n,showLegend:(n.showLegend??!(!e||i.colorByDepth))&&!(!e||i.colorByDepth),nodeStyle:Ti(m,g,gt(i))}}},Bi={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Wi}from"d3-scale";function ji(t,e,o,n){const i=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",n="string"==typeof e?i:i.map(t=>({...t,__geoColorBy:e(t)}));r=Q(n,t,o)}if(n.sizeBy){const t=i.map("function"==typeof n.sizeBy?n.sizeBy:t=>t?.[n.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=Pt(t))}return t=>({fill:e&&r?K(t,e,r):q,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?J(t,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}function Yi(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var Xi={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="string"==typeof o?o:"blues",s=function(t,e,o){if(!Array.isArray(t))return;const n=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let i=1/0,r=-1/0;for(const e of t){const t=n(e);null!=t&&isFinite(t)&&(i>t&&(i=t),t>r&&(r=t))}const s=[Number.isFinite(i)?i:0,Number.isFinite(r)?r:1],a=Wi(F(o)).domain(s);return{domain:s,colorScale:t=>a(t),valueAccessor:n}}(i.areas,i.valueAccessor,r),a=i.areaStyle??function(t,e){if(t)return o=>{const n=t.valueAccessor(o);return{fill:null!=n&&isFinite(n)?t.colorScale(n):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:e}}}(s,i.areaOpacity??1),c=i.styleRules?ct(a,i.styleRules,t=>{return{value:(e=t,"function"==typeof i.valueAccessor?i.valueAccessor(e):null!=i.valueAccessor?e?.properties?.[i.valueAccessor]??e?.[i.valueAccessor]:void 0)};var e},Yi):a,l=!1!==n.showLegend&&s?{gradient:{colorFn:s.colorScale,domain:s.domain,label:"string"==typeof i.valueAccessor?i.valueAccessor:"value"}}:void 0;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:c,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n,...void 0===n.legend&&l?{legend:l}:{}}}},qi={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=t||i.points,s=i.pointStyle??ji(r,e,o,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?ct(s,i.styleRules,it(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||Bi,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},Gi={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=t||i.points,s=i.pointStyle??ji(r,e,o,{pointRadius:"number"==typeof i.pointRadius?i.pointRadius:5,fillOpacity:.85,strokeWidth:1}),a=i.nodeIdAccessor||"id",c=i.cartogramLayout||("sparkline"===i.mode?"strip":"radial"),l="sparkline"===i.mode,u="strip"===c,d=i.styleRules?ct(s,i.styleRules,it(e)):s;return{points:r,lines:i.lines,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",pointStyle:t=>{const e="function"==typeof d?d(t):d,o="function"==typeof a?a(t):t[a],n=null!=o&&o+""==i.center+"",r="number"==typeof e.r?e.r:5;return{...e,fillOpacity:n?1:e.fillOpacity??.8,stroke:n?"var(--semiotic-text, #222)":e.stroke??"#fff",strokeWidth:n?1.25:e.strokeWidth??1,r:n?1.35*r:r}},colorBy:e,colorScheme:o,projection:i.projection||"mercator",graticule:i.graticule,fitPadding:i.fitPadding,projectionTransform:{center:i.center,centerAccessor:a,costAccessor:i.costAccessor,strength:i.strength??1,lineMode:i.lineMode||"straight",layout:c},...n,cartogramChrome:{showRings:i.showRings??!0,showNorth:i.showNorth??(!u&&!l),showRingLabels:i.showRingLabels??!u,costLabel:i.costLabel}}}},Vi={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=(Array.isArray(t)?t:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",c=i.xAccessor||"lon",l=i.yAccessor||"lat",u="function"==typeof c?c:t=>t[c],d="function"==typeof l?l:t=>t[l],h=(i.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),f=new Map;for(const t of h)f.set(t[s]+"",t);const p=i.edgeColorBy??e,y="function"==typeof p,g=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),o=f.get(t.target+"");return e&&o?{...t,coordinates:[{x:e.x,y:e.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=p?y?Q(g.map(t=>({[m]:p(t)})),m,o||"category10"):Q(g,p,o||"category10"):null,b=t=>p&&x?K(t,p,x):"#007bff";let v=1/0,w=-1/0;for(const t of g){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[A,S]=i.edgeWidthRange??[1,8],M=S-A,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:g,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||Bi,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:o,lineStyle:t=>{const e=Number(t?.[a]),o=Number.isFinite(e)?e:v,n=A+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:b(t),strokeWidth:n,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...n}}};import{interpolateRgb as Hi}from"d3-interpolate";var Ui=864e5,Ki=t=>{const e=t.config,{plot:o}=t.dimensions;if(0>=o.width||0>=o.height)return{nodes:[]};const n=t=>{const o="function"==typeof e.dateAccessor?e.dateAccessor(t):t[e.dateAccessor];return o instanceof Date?o:new Date(o)},i=t=>{const o="function"==typeof e.valueAccessor?e.valueAccessor(t):t[e.valueAccessor];return Number(o)},r=new Map;let s=null;for(const e of t.data){const t=n(e);if(!isFinite(t.getTime()))continue;null==s&&(s=t.getUTCFullYear());const o=Zi(t),a=i(e);r.set(o,(r.get(o)??0)+(Number.isFinite(a)?a:0))}const a=e.year??s??(new Date).getUTCFullYear();let c=1/0,l=-1/0;for(const t of r.values())c>t&&(c=t),t>l&&(l=t);c===1/0&&(c=0,l=0);const[u,d]=e.colorRamp??[t.theme.semantic.surface??"#ebedf0",t.theme.semantic.primary??"#216e39"],h=t=>{if(l===c)return u;const e=(t-c)/(l-c);return Hi(u,d)(e)},f=e.gutter??2,p=e.labelInset??0,y=Math.min((o.width-p-53*f)/54,(o.height-6*f)/7);if(0>=y)return{nodes:[]};const g=new Date(Date.UTC(a,0,1)),m=g.getUTCDay(),x=new Date(g.getTime()-m*Ui),b=[];for(let t=0;54>t;t++)for(let e=0;7>e;e++){const n=new Date(x.getTime()+(7*t+e)*Ui);if(n.getUTCFullYear()!==a)continue;const i=Zi(n),s=r.get(i),c=null==s?u:h(s);b.push({type:"rect",x:o.x+p+t*(y+f),y:o.y+e*(y+f),w:y,h:y,style:{fill:c,stroke:"none"},datum:{date:n,value:s??0}})}return{nodes:b}};function Zi(t){return`${t.getUTCFullYear()}-${Qi(t.getUTCMonth()+1)}-${Qi(t.getUTCDate())}`}function Qi(t){return 10>t?"0"+t:t+""}import*as Ji from"react";import{scaleLinear as tr}from"d3-scale";import{interpolateLab as er}from"d3-interpolate";function or(t,e={}){const o=e.baseOpacity??1;return e.highlight||e.predicate?!function(t,e){if(!e)return!0;const o=Array.isArray(e)?e:[e],n=t;for(const t of o)if(null!=t.value&&n[t.field]+""!=t.value+"")return!1;return!0}(t,e.highlight)||e.predicate&&!e.predicate(t)?e.dimOpacity??.16:Math.min(1,o+(e.brighten??0)):o}import{jsx as nr,jsxs as ir}from"react/jsx-runtime";function rr(t){const e=t.fontSize??12;return null!=t.maxWidth&&t.text.length*e*.56>t.maxWidth?null:nr("text",{className:t.className,x:t.x,y:t.y,textAnchor:t.anchor??"middle",dominantBaseline:t.baseline??"middle",fontSize:e,fontWeight:t.fontWeight,fill:t.color,style:{pointerEvents:"none"},children:t.text},t.keyId)}var sr=t=>{const e=t.config,{plot:o}=t.dimensions,n=e.fields??[];if(2>n.length||0>=o.width||0>=o.height)return{nodes:[]};if(0===t.data.length)return{nodes:[]};const i=Object.create(null);for(const o of n){const n=e.domains&&Object.prototype.hasOwnProperty.call(e.domains,o)?e.domains[o]:void 0;if(Array.isArray(n)&&n.length>=2&&"number"==typeof n[0]&&Number.isFinite(n[0])&&"number"==typeof n[1]&&Number.isFinite(n[1])){i[o]=[n[0],n[1]];continue}let r=1/0,s=-1/0;for(const e of t.data){const t=Number(e[o]);Number.isFinite(t)&&(r>t&&(r=t),t>s&&(s=t))}if(Number.isFinite(r)&&Number.isFinite(s))if(r===s){const t=Math.max(.01*Math.abs(r),.5);i[o]=[r-t,s+t]}else i[o]=[r,s];else i[o]=[0,1]}const r=!1!==e.showAxes,s=r?e.axisLabelPadding??24:8,a=r?18:8,c=n.map(t=>tr().domain(i[t]).range([o.y+o.height-a,o.y+s])),l=n.map((t,e)=>1===n.length?o.x+o.width/2:o.x+e/(n.length-1)*o.width),u=e.colorBy?"function"==typeof e.colorBy?e.colorBy:t=>(t[e.colorBy]??"")+"":null,d=e.opacity??.45,h=e.strokeWidth??1.25,f=t.theme.semantic.primary??"#3b6cb1",p=e.dimmedOpacity??.08,y=e.highlightFn,g=[],m=[];for(const o of t.data){const i=u?t.resolveColor(u(o)+""):f,r=!y||y(o),s=or(o,{predicate:y,baseOpacity:d,dimOpacity:p,brighten:.4}),a=r?m:g;for(let t=0;n.length-1>t;t++){const e=Number(o[n[t]]),u=Number(o[n[t+1]]);if(!Number.isFinite(e)||!Number.isFinite(u))continue;const d={type:"connector",x1:l[t],y1:c[t](e),x2:l[t+1],y2:c[t+1](u),style:{stroke:i,strokeWidth:y&&r?h+.75:h,opacity:s,fill:"none"},datum:o};a.push(d)}if(e.showPoints)for(let t=0;n.length>t;t++){const e=Number(o[n[t]]);if(!Number.isFinite(e))continue;const r={type:"point",x:l[t],y:c[t](e),r:2.5,style:{fill:i,stroke:"none",opacity:Math.min(1,s+.3)},datum:o};a.push(r)}}let x=null;if(r){const r=`var(--semiotic-border, ${t.theme.semantic.border??"#aaa"})`,u=`var(--semiotic-text, ${t.theme.semantic.text??"currentColor"})`,d=`var(--semiotic-text-secondary, ${t.theme.semantic.textSecondary??"#888"})`,h=o.y+s,f=o.y+o.height-a,p=[];for(let t=0;n.length>t;t++){const a=n[t],y=l[t],g=e.tickFormat&&Object.prototype.hasOwnProperty.call(e.tickFormat,a)?e.tickFormat[a]:void 0,m="function"==typeof g?g:t=>t.toLocaleString();p.push(Ji.createElement("line",{key:"pc-axis-line-"+t,x1:y,x2:y,y1:h,y2:f,stroke:r,strokeWidth:1})),p.push(rr({keyId:"pc-axis-label-"+t,text:a,x:y,y:o.y+s-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:u}));const[x,b]=i[a],v=5;for(let e=0;v>e;e++){const o=x+(b-x)*e/(v-1),n=c[t](o);p.push(Ji.createElement("line",{key:`pc-tick-${t}-${e}`,x1:y-3,x2:y+3,y1:n,y2:n,stroke:r,strokeWidth:1}),rr({keyId:`pc-ticktext-${t}-${e}`,text:m(o),x:y+6,y:n+3,anchor:"start",baseline:"auto",fontSize:10,color:d}))}}x=Ji.createElement(Ji.Fragment,null,...p)}return{nodes:g.concat(m),overlays:x}},ar={frameType:"xy",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:n.showLegend??!!e})},cr={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},lr={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({...cr.buildProps(t,e,o,n,i),customLayout:sr,showAxes:!1})},ur={frameType:"xy",buildProps:(t,e,o,n,i)=>({...ar.buildProps(t,e,o,n,i),customLayout:Ki,showAxes:!1})};import*as dr from"react";function hr(t){const[e,o]=t,n=160>e||116>o,i=n?Math.min(12,Math.max(2,.08*e)):32,r=n?Math.min(8,Math.max(2,.12*o)):24,s=n?r:34;return{width:e,height:o,plot:{x:i,y:r,width:Math.max(1,e-2*i),height:Math.max(1,o-r-s)}}}function fr(t){const e=(t??"")+"";if(!e)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return o[n%o.length]}function pr(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?ot(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,c={fill:null==a?e:fr(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(c,at(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),c}}function yr(t,e,o,n){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:o},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...n}}}function gr(t,e,o){return"function"==typeof o?o(t,e):t[o]}function mr(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:null}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:null}function xr(t,e,o){return Math.max(e,Math.min(o,t))}function br(t,e){const o=mr(t);return null!=o&&o>0?o:e}function vr(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function wr(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}import{scaleLinear as kr}from"d3-scale";function Ar(t){let e=t>>>0;return function(){e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}var Sr={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},Mr=1e-9,_r=.005;function Pr(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function Lr(t){return"aabb"===t.type?{type:"aabb",x:t.x,y:t.y,width:t.width,height:t.height}:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:t.thickness}}function $r(t,e,o){return Math.max(e,Math.min(o,t))}function Rr(t,e,o){return Math.min(t??o,e??o)}function Tr(t,e,o){return $r(Math.max(t??o,e??o),0,1)}function Ir(t){return 0>t?-1:1}function Cr(t){if("circle"===t.shape.type){const e=t.shape.radius;return{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e}}const e=t.shape.width/2,o=t.shape.height/2;return{minX:t.x-e,minY:t.y-o,maxX:t.x+e,maxY:t.y+o}}function Or(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,o=e.height/2;return{minX:e.x-t,minY:e.y-o,maxX:e.x+t,maxY:e.y+o}}const o=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-o,minY:Math.min(e.y1,e.y2)-o,maxX:Math.max(e.x1,e.x2)+o,maxY:Math.max(e.y1,e.y2)+o}}function Fr(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function Dr(t,e,o,n,i,r,s,a){const c=i-t,l=(o+s)/2-Math.abs(c);if(0>=l)return null;const u=r-e,d=(n+a)/2-Math.abs(u);return d>0?d>l?{nx:Ir(c),ny:0,penetration:l}:{nx:0,ny:Ir(u),penetration:d}:null}function zr(t,e,o,n,i,r,s){const a=r/2,c=s/2,l=t-$r(t,n-a,n+a),u=e-$r(e,i-c,i+c),d=l*l+u*u;if(d>o*o)return null;if(Mr>=d){const r=Math.abs(t-(n-a)),s=Math.abs(t-(n+a)),l=Math.abs(e-(i-c)),u=Math.abs(e-(i+c)),d=Math.min(r,s,l,u);return d===r?{nx:-1,ny:0,penetration:o+r}:d===s?{nx:1,ny:0,penetration:o+s}:d===l?{nx:0,ny:-1,penetration:o+l}:{nx:0,ny:1,penetration:o+u}}const h=Math.sqrt(d);return{nx:l/h,ny:u/h,penetration:o-h}}function Nr(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,o,n,i,r){const s=n-t,a=i-e,c=o+r,l=s*s+a*a;if(l>=c*c)return null;if(Mr>=l)return{nx:1,ny:0,penetration:c};const u=Math.sqrt(l);return{nx:s/u,ny:a/u,penetration:c-u}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return Dr(t.x,t.y,t.shape.width,t.shape.height,e.x,e.y,e.shape.width,e.shape.height);if("circle"===t.shape.type&&"aabb"===e.shape.type){const o=zr(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return o?{nx:-o.nx,ny:-o.ny,penetration:o.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?zr(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function Er(t,e){const o=e.shape;return"aabb"===o.type?"circle"===t.shape.type?zr(t.x,t.y,t.shape.radius,o.x,o.y,o.width,o.height):Dr(o.x,o.y,o.width,o.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,o,n,i,r,s,a=0){const c=r-n,l=s-i,u=c*c+l*l,d=u>Mr?$r(((t-n)*c+(e-i)*l)/u,0,1):0,h=o+a/2,f=t-(n+c*d),p=e-(i+l*d),y=f*f+p*p;if(y>=h*h)return null;if(Mr>=y){const t=Math.sqrt(u);return t>Mr?{nx:-l/t,ny:c/t,penetration:h}:{nx:1,ny:0,penetration:h}}const g=Math.sqrt(y);return{nx:f/g,ny:p/g,penetration:h-g}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,o.x1,o.y1,o.x2,o.y2,o.thickness??0)}function Br(t,e){return`${t}\0${e}`}function Wr(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function jr(t){return{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,bodyCollisions:t.bodyCollisions,shape:Pr(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function Yr(t){return t&&"function"!=typeof t?{property:t.property,equals:t.equals,notEquals:t.notEquals,oneOf:t.oneOf?.slice(),notOneOf:t.notOneOf?.slice()}:t}function Xr(t){return{id:t.id,shape:Lr(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:Yr(t.bodyFilter),index:t.index}}function qr(t,e){return!!e?.some(e=>Object.is(t,e))}function Gr(t,e){return function(t,e){if(!e)return!0;if("function"==typeof e)return e(t);const o=function(t,e){if(!e)return;let o=t;for(const t of e.split(".")){if(null==o||"object"!=typeof o)return;if(!Object.prototype.hasOwnProperty.call(o,t))return;o=o[t]}return o}(t,e.property);return!("equals"in e&&!Object.is(o,e.equals)||"notEquals"in e&&Object.is(o,e.notEquals)||e.oneOf&&!qr(o,e.oneOf)||e.notOneOf&&qr(o,e.notOneOf))}(e,t.bodyFilter)}var Vr=class{constructor(t={}){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={...Sr,...t},this.random=Ar(this.options.seed)}init(t={}){this.options={...Sr,...t},this.random=Ar(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(t){const e={id:t.id,x:t.x,y:t.y,prevX:t.x,prevY:t.y,vx:t.vx??0,vy:t.vy??0,angle:t.angle??0,mass:Math.max(Mr,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:Pr(t.shape),sleeping:!1,datum:t.datum,restitution:t.restitution,friction:t.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(t.id,e)}remove(t){for(const e of t){this.bodies.delete(e);for(const t of Array.from(this.activeSensors))Wr(t).bodyId===e&&this.activeSensors.delete(t)}}setColliders(t){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const e of t)this.colliders.set(e.id,{...e,shape:Lr(e.shape),bodyFilter:Yr(e.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(t){const e=t.id??"spring-"+this.nextSpringIndex;return this.springs.set(e,{id:e,bodyId:t.bodyId,target:t.target,restLength:t.restLength??0,stiffness:t.stiffness??40,damping:t.damping??3}),this.nextSpringIndex+=1,e}removeConstraint(t){this.springs.delete(t)}applyImpulse(t,e,o){const n=this.bodies.get(t);n&&(n.vx+=e/n.mass,n.vy+=o/n.mass,this.wake(n))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const o=this.sortedBodies();for(const t of o)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const n=this.options.maxVelocity;for(const t of o)if(!t.sleeping){if(t.vx+=this.options.gravity.x*e,t.vy+=this.options.gravity.y*e,t.vx*=this.options.velocityDamping,t.vy*=this.options.velocityDamping,n>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>n){const o=n/e;t.vx*=o,t.vy*=o}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const i=this.bodyPairKeys(o),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(o,i,0===t),this.resolveColliders(o,r,0===t);this.updateSensors(o),this.updateSleeping(o,e)}settle(t=1200,e=this.options.fixedDt){let o=0;for(;t>o&&!this.allSleeping();)this.step(e),o+=1;return o}readState(t=[]){t.length=0;for(const e of this.sortedBodies())t.push({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:Pr(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Wr)}allSleeping(){for(const t of this.bodies.values())if(!t.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(jr),colliders:this.sortedColliders().map(Xr),springs:Array.from(this.springs.values()).map(t=>({...t,target:{...t.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(t){this.options={...t.options,gravity:{...t.options.gravity}},this.random=Ar(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(t.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const e of t.bodies){const t=jr(e);this.bodies.set(t.id,t),this.nextBodyIndex=Math.max(this.nextBodyIndex,t.index+1)}this.nextColliderIndex=0;for(const e of t.colliders){const t=Xr(e);this.colliders.set(t.id,t),this.nextColliderIndex=Math.max(this.nextColliderIndex,t.index+1)}this.nextSpringIndex=0;for(const e of t.springs){this.springs.set(e.id,{...e,target:{...e.target}});const t=/^spring-(\d+)$/.exec(e.id);t&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(t[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((t,e)=>t.index-e.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((t,e)=>t.index-e.index)}applySprings(t){for(const e of Array.from(this.springs.values()).sort((t,e)=>t.id.localeCompare(e.id))){const o=this.bodies.get(e.bodyId);if(!o||o.sleeping)continue;const n="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!n)continue;const i=n.x-o.x,r=n.y-o.y,s=Math.sqrt(i*i+r*r);if(Mr>=s)continue;const a=i/s,c=r/s,l=(s-e.restLength)*e.stiffness+((("vx"in n?n.vx:0)-o.vx)*a+(("vy"in n?n.vy:0)-o.vy)*c)*e.damping;o.vx+=l*a*t/o.mass,o.vy+=l*c*t/o.mass}}resolveBodyPairs(t,e,o){for(const n of e){const[e,i]=n.split(":").map(Number),r=t[e],s=t[i];if(!r||!s)continue;const a=Nr(r,s);a&&(this.resolveDynamicCollision(r,s,a),o&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),o=new Map;for(let n=0;t.length>n;n+=1){if(!1===t[n].bodyCollisions)continue;const i=Cr(t[n]),r=Math.floor(i.minX/e),s=Math.floor(i.maxX/e),a=Math.floor(i.minY/e),c=Math.floor(i.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;c>=e;e+=1){const i=`${t}:${e}`,r=o.get(i);r?r.push(n):o.set(i,[n])}}const n=new Set;for(const e of Array.from(o.keys()).sort()){const i=o.get(e)??[];i.sort((t,e)=>t-e);for(let e=0;i.length>e;e+=1)for(let o=e+1;i.length>o;o+=1){const r=i[e],s=i[o];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&Fr(Cr(t[r]),Cr(t[s]))&&n.add(`${r}:${s}`)}}return Array.from(n).sort((t,e)=>{const[o,n]=t.split(":").map(Number),[i,r]=e.split(":").map(Number);return o===i?n-r:o-i})}resolveDynamicCollision(t,e,o){t.sleeping&&this.contactOpposesGravity(o.nx,o.ny)&&this.supportedThisStep.add(e.id),e.sleeping&&this.contactOpposesGravity(-o.nx,-o.ny)&&this.supportedThisStep.add(t.id);const n=t.sleeping?0:1/t.mass,i=e.sleeping?0:1/e.mass,r=n+i;if(Mr>=r)return;const s=Math.max(0,o.penetration-_r)/r;t.x-=o.nx*s*n,t.y-=o.ny*s*n,e.x+=o.nx*s*i,e.y+=o.ny*s*i;const a=(e.vx-t.vx)*o.nx+(e.vy-t.vy)*o.ny;if(a>0)return;const c=Math.abs(a),l=-(1+Rr(t.restitution,e.restitution,this.options.restitution))*a/r,u=l*o.nx,d=l*o.ny;t.vx-=u*n,t.vy-=d*n,e.vx+=u*i,e.vy+=d*i,this.applyFriction(t,e,o,l,n,i),c>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,o,n,i,r){const s=-o.ny,a=o.nx,c=(e.vx-t.vx)*s+(e.vy-t.vy)*a,l=i+r;if(Mr>=Math.abs(c)||Mr>=l)return;const u=Tr(t.friction,e.friction,this.options.friction),d=$r(-c/l,-n*u,n*u),h=d*s,f=d*a;t.vx-=h*i,t.vy-=f*i,e.vx+=h*r,e.vy+=f*r}resolveColliders(t,e,o){for(const n of t)for(const t of e){if(!Gr(t,n))continue;if(!Fr(Cr(n),Or(t)))continue;const e=Er(n,t);e&&(this.resolveStaticCollision(n,t,e),this.contactOpposesGravity(e.nx,e.ny)&&this.supportedThisStep.add(n.id),o&&this.lastEvents.push({type:"contact",bodyId:n.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,o){t.x+=o.nx*Math.max(0,o.penetration-_r),t.y+=o.ny*Math.max(0,o.penetration-_r);const n=t.vx*o.nx+t.vy*o.ny;if(0>n){const i=Rr(t.restitution,e.restitution,this.options.restitution);t.vx-=(1+i)*n*o.nx,t.vy-=(1+i)*n*o.ny;const r=-o.ny,s=o.nx,a=t.vx*r+t.vy*s,c=Tr(t.friction,e.friction,this.options.friction);t.vx-=a*r*c,t.vy-=a*s*c}}updateSensors(t){const e=new Set,o=this.sortedColliders().filter(t=>t.sensor);for(const n of t){const t=Cr(n);for(const i of o){if(!Gr(i,n))continue;if(!Fr(t,Or(i)))continue;if(!Er(n,i))continue;const o=Br(i.id,n.id);e.add(o),this.activeSensors.has(o)||this.lastEvents.push({type:"sensor-enter",bodyId:n.id,sensorId:i.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:o,bodyId:n}=Wr(t);this.lastEvents.push({type:"sensor-exit",bodyId:n,sensorId:o})}this.activeSensors=e}updateSleeping(t,e){const o=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const n of t)Math.sqrt(n.vx*n.vx+n.vy*n.vy)>=this.options.sleepSpeed||Math.sqrt((n.x-n.prevX)*(n.x-n.prevX)+(n.y-n.prevY)*(n.y-n.prevY))>=this.options.sleepSpeed*e||o&&!this.supportedThisStep.has(n.id)?n.sleeping?this.wake(n):n.sleepTime=0:(n.sleepTime+=e,n.sleeping||this.options.sleepAfter>n.sleepTime||(n.sleeping=!0,n.vx=0,n.vy=0,this.lastEvents.push({type:"sleep",bodyId:n.id})))}contactOpposesGravity(t,e){const{x:o,y:n}=this.options.gravity,i=Math.hypot(o,n);return 1e-9>=i||-.2>(t*o+e*n)/i}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},Hr=class{constructor(t={}){this.id="builtin",this.capabilities={...(new Vr).capabilities,engine:"builtin"},this.world=new Vr(t)}init(t={}){this.world.init(t)}spawn(t){this.world.spawn(t)}remove(t){this.world.remove(t)}setColliders(t){this.world.setColliders(t)}setConstraint(t){return this.world.setConstraint(t)}removeConstraint(t){this.world.removeConstraint(t)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o)}step(t){this.world.step(t)}settle(t,e){return this.world.settle(t,e)}readState(t){return this.world.readState(t)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(t){this.world.restore(t)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function Ur(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new Hr(t)}(e)}var Kr=["binId","targetBin","category","windowIndex","lane","group"];function Zr(t,e){if(!Number.isFinite(e))return;t.count+=1,t.total+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e);const o=e-t.mean;t.mean+=o/t.count,t.m2+=o*(e-t.mean)}function Qr(t){return{count:t.count,total:t.total,mean:t.count>0?t.mean:0,min:t.count>0?t.min:0,max:t.count>0?t.max:0,variance:t.count>1?t.m2/(t.count-1):0}}function Jr(t){return{count:t.count,total:t.total,mean:t.mean,m2:t.variance*Math.max(0,t.count-1),min:t.count>0?t.min:1/0,max:t.count>0?t.max:-1/0}}function ts(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function es(t,e,o){return"function"==typeof t?t(e,o):"string"==typeof t?ts(e,t):void 0}function os(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function ns(t){const e=Qr(t.value);return{id:t.id,label:t.label,count:e.count,total:e.total,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Qr(t.x),y:Qr(t.y),value:e}}var is=class{constructor(t=!1){this.bins=new Map,this.nextIndex=0,this.config=t}updateConfig(t){void 0!==t&&(this.config=t,!1===t&&this.clear())}isEnabled(){return!1!==this.config}add(t){if(!1===this.config)return null;const e=this.nextIndex;this.nextIndex+=1;const o=os(es(this.config.binAccessor,t,e))??function(t){for(const e of Kr){const o=os(ts(t,e));if(o)return o}return"sediment"}(t),n=os(es(this.config.labelAccessor,t,e))??o,i=function(t,e,o){if("number"==typeof t)return t;const n="function"==typeof t?t(e,o):"string"==typeof t?ts(e,t):1,i="number"==typeof n?n:Number(n);return Number.isFinite(i)?i:1}(this.config.valueAccessor,t,e),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(o);return s||(s={id:o,label:n,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(o,s)),s.label=n,s.lastBodyId=t.id,s.lastDatum=t.datum,Zr(s.x,t.x),Zr(s.y,t.y),Zr(s.value,i),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),ns(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(ns)}restore(t=[]){this.bins.clear();for(const e of t)this.bins.set(e.id,{id:e.id,label:e.label,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:Jr(e.x),y:Jr(e.y),value:Jr(e.value)});this.nextIndex=t.reduce((t,e)=>t+e.count,0)}totals(){const t=this.snapshot();return{bins:t.length,count:t.reduce((t,e)=>t+e.count,0),total:t.reduce((t,e)=>t+e.total,0)}}};function rs(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var ss={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},as={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function cs(t={},e=as){return{chartId:t.chartId??e.chartId,chartType:t.chartType??e.chartType,sensors:t.sensors??e.sensors,onObservation:t.onObservation??e.onObservation,onSimulationStateChange:t.onSimulationStateChange??e.onSimulationStateChange}}function ls(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function us(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:void 0}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function ds(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function hs(t){return{...ls(t),sequence:t.sequence,spawnAt:t.spawnAt}}function fs(t){return t.map(t=>({...t,shape:{...t.shape},bodyFilter:t.bodyFilter&&"function"!=typeof t.bodyFilter?{...t.bodyFilter,oneOf:t.bodyFilter.oneOf?.slice(),notOneOf:t.bodyFilter.notOneOf?.slice()}:t.bodyFilter}))}function ps(t){return!1!==t&&{...t}}function ys(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function gs(t){return{...t,gravity:{...t.gravity}}}function ms(t,e,o,n){if("circle"===t.shape.type){const i=t.x-e,r=t.y-o,s=t.shape.radius+n,a=i*i+r*r;return a>s*s?null:a}const i=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),r=Math.max(Math.abs(o-t.y)-t.shape.height/2,0),s=i*i+r*r;return s>n*n?null:s}function xs(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function bs(t,e={}){const{idPrefix:o="plot",includeFloor:n=!0,includeCeiling:i=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:c=a}=e,l=[],u=t.x+t.width/2,d=t.y+t.height/2;return n&&l.push({id:o+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+c/2,width:t.width+2*a,height:c}}),i&&l.push({id:o+"-ceiling",shape:{type:"aabb",x:u,y:t.y-c/2,width:t.width+2*a,height:c}}),r&&l.push({id:o+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:d,width:a,height:t.height+2*c}}),s&&l.push({id:o+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:d,width:a,height:t.height+2*c}}),l}function vs(t){const{idPrefix:e="bin",count:o,domainStart:n,domainStep:i,xScale:r,yTop:s,yBottom:a,wallThickness:c=4,includeBoundaryWalls:l=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=s,lidThickness:f=Math.max(2,c)}=t,p=[],y=s+(a-s)/2,g=Math.abs(a-s),m=l?o:o-1;if(u||l)for(let t=l?0:1;m>=t;t+=1){if(!u&&t>0&&o>t)continue;const s=r(n+t*i);p.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:s,y:y,width:c,height:g}})}if(null!=d)for(let t=0;o>t;t+=1){const o=n+t*i,s=o+i;if(s>=d)continue;const a=r(o),l=r(s);p.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,l)+c/2,y1:h,x2:Math.max(a,l)-c/2,y2:h,thickness:f}})}return p}var ws={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 ks(t,e){const o={...t};for(const t of e)o[ws[t]]++;return o}function As(t,e,o){const n=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:n,revisions:ks(o,n)}}var Ss=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=As({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}record(t,e){const o=As(t,e,this.revisions);this.revisions=o.revisions,this.latest=o;for(const t of[...this.listeners])t();return o}};import{quadtree as Ms}from"d3-quadtree";var _s=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,o,n,i,r=0,s){const a=this.ensure(t,e);if(!a)return null;let c=null,l=1/0;const u=Math.max(0,s?.searchRadius??Math.max(0,r)+this.maxSearchRadius),d=n-u,h=n+u,f=i-u,p=i+u;return a.visit((t,e,a,u,y)=>{if(d>u||e>h||f>y||a>p)return!0;if(t.length)return!1;let g=t;for(;g;){const t=g.data;if(t&&(!s?.include||s.include(t))){const e=s?.distanceSquared?s.distanceSquared(t,n,i):ms(t,n,i,Math.max(0,r));null!=e&&(l>e||e===l&&o.indexOf(t.id)>o.indexOf(c?.id??""))&&(c=t,l=e)}g=g.next}return!1}),c}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const o=t.readState();return 0===o.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=o.reduce((t,e)=>Math.max(t,function(t){return"circle"===t.shape.type?t.shape.radius:Math.hypot(t.shape.width,t.shape.height)/2}(e)),0),this.tree=Ms().x(t=>t.x).y(t=>t.y).addAll(o),this.revision=e,this.tree)}},Ps=["data","scene-geometry","data-paint","accessibility","evidence"],Ls=["scene-geometry","data-paint","accessibility","evidence"],$s=["overlay","accessibility","evidence"],Rs=(t,e)=>({retainedData:t,invalidations:e}),Ts=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Is=["scene-geometry","data-paint","accessibility","evidence"],Cs=[],Os={engine:Rs("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:Rs("preserve",Is),colliders:Rs("preserve",Is),sediment:Rs("preserve",Is),bodyBudget:Rs("preserve",Ts),bodyLimit:Rs("preserve",Ts),eviction:Rs("preserve",Ts),fixedDt:Rs("preserve",Cs),maxDeltaSeconds:Rs("preserve",Cs),maxSubsteps:Rs("preserve",Cs),settleStepLimit:Rs("preserve",Cs),timeScale:Rs("preserve",Cs),observation:Rs("preserve",Cs)},Fs=Rs("preserve",Ts);function Ds(t){let e="preserve";const o=new Set;for(const n of t){const t=Os[n]??Fs;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}var zs=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function Ns(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&zs.every(o=>t[o]===e[o])}function Es(t,e,o,n){return t||!e?"paused":o||!n?"running":"settled"}var Bs=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(t){this.speed=function(t){const e=t?.sleepSpeed;return"number"==typeof e&&Number.isFinite(e)&&e>0?e:8}(t)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(t,e,o){if(o>0)return void(this.seconds=0);const n=t.readState(this.scratch),i=this.speed*this.speed;let r=!0;for(const t of n)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=i){r=!1;break}this.seconds=r?this.seconds+Math.max(0,e):0}},Ws=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new _s,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Ss,this.simulationState="settled",this.visible=!0,this.quiescence=new Bs;const{bodyBudget:e,colliders:o,engine:n,kernel:i,observation:r,sediment:s,...a}=t;this.config={...ss,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=n,this.observation=cs(r),this.sediment=new is(s??!1),this.world=Ur(n,{fixedDt:this.config.fixedDt,...i}),this.quiescence.setKernelOptions(i),o&&this.world.setColliders(fs(o))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(o=>"kernel"===o?!Ns(t.kernel,e.kernel):t[o]!==e[o])}(t,this.configInput),{colliders:o,bodyBudget:n,engine:i,kernel:r,observation:s,sediment:a,...c}=t;if(this.config={...this.config,...c},void 0!==n&&(this.bodyBudget=n,!1===n&&(this.bodyBudgetObservationKey="ok")),i&&i!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=i,this.world=Ur(i,t.options),this.world.restore(t),this.revision+=1}if(r&&!Ns(r,this.configInput.kernel)){const t=this.world.snapshot(),e={...t.options,...r,gravity:{...t.options.gravity,...r.gravity}};this.world.restore({...t,options:e}),this.quiescence.setKernelOptions(e),this.revision+=1}s&&(this.observation=cs(s,this.observation)),this.sediment.updateConfig(a),o&&(this.world.setColliders(fs(o)),this.revision+=1),this.configInput={...this.configInput,...t};const l=Ds(e);this.updateResults.record({kind:"config",keys:e},l.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(fs(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Ds(["colliders"]).invalidations)}enqueue(t,e){const o=Array.isArray(t)?t:[t],n=e?function(t,e={}){const o=us(e.startAt)??0,n=e.pacing??"immediate";if("arrival"===n){const n=t.map((t,o)=>function(t,e,o){return"function"==typeof o?us(o(t,e)):"string"==typeof o?us(ds(t,o)):us(t.spawnAt)??us(ds(t,"arrivalTime"))??us(ds(t,"timestamp"))??us(ds(t,"time"))??us(ds(t,"eventTime"))}(t,o,e.timeAccessor)),i=n.filter(t=>null!=t),r=i.length>0?Math.min(...i):0,s=us(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const i=n[e],s=null==i?0:Math.max(0,i-r);return{...ls(t),spawnAt:o+s/a}})}if("object"==typeof n){const e=us(n.ratePerSec);if(e&&e>0)return t.map((t,n)=>({...ls(t),spawnAt:o+n/e}))}return t.map(t=>({...ls(t),spawnAt:o}))}(o,{...e,startAt:e.startAt??this.elapsedSeconds}):o;for(const t of n)this.queue.push({...ls(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(ys),n.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:n.length},n.length?Ps:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(ls(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},Ps)}materializeDueSpawns(){const t=this.revision,e=[],o=[];return this.spawnDue(e,o),0===e.length||(this.observeBodyBudget(o),this.evictOverflow(o),this.syncSimulationState(o),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?Ps:[])),e}clear(){const t=this.world.snapshot().options;this.world.init({...t,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},Ps)}tick(t){const e=this.revision,o=[],n=[],i=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,o,n,i,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(o,s);const c=this.observeBodyBudget(s),l=this.evictOverflow(s);n.push(...l.evicted),i.push(...l.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,o.length),(u>0||o.length>0||n.length>0||i.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,o,n,i,r,s,void 0,c);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?o.length||n.length||i.length?Ps:Ls:[]),d}settle(t=this.config.settleStepLimit){return this.runSettle(t,!1).steps}settleWithObservations(t=this.config.settleStepLimit){return this.runSettle(t,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:t=>{this.elapsedSeconds+=t},spawnDue:(t,e)=>this.spawnDue(t,e),observeBodyBudget:t=>this.observeBodyBudget(t),evictOverflow:t=>this.evictOverflow(t),step:t=>this.world.step(t),drainEvents:()=>this.world.events(),observeKernelEvents:(t,e)=>this.observeKernelEvents(t,e),observeSensorTransitions:t=>this.observeSensorTransitions(t),refreshQuiescence:(t,e)=>this.quiescence.refresh(this.world,t,e)}}runSettle(t,e){const o=this.revision,n=[],i=[],r=[],s=[],a=e?[]:void 0;if(e&&(this.paused||!this.visible)){const t=this.result(0,n,i,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(n,a);const c=this.observeBodyBudget(a),l=this.evictOverflow(a);i.push(...l.evicted),r.push(...l.sedimented),this.syncSimulationState(a),n.length>0&&this.quiescence.reset();const u=e?{spawned:n,evicted:i,sedimented:r,events:s,observations:a}:{spawned:n},{steps:d,budget:h}=function(t,e,o){let n,i=0;for(;e>i&&(t.queueSize()>0||!t.atRest());){t.advanceTime(t.fixedDt);const e=[];if(t.spawnDue(e,o.observations),e.length>0){o.spawned.push(...e),n=t.observeBodyBudget(o.observations);const i=t.evictOverflow(o.observations);o.evicted?.push(...i.evicted),o.sedimented?.push(...i.sedimented)}t.step(t.fixedDt);const r=t.drainEvents();o.events&&(o.events.push(...r),t.observeKernelEvents(r,o.observations),t.observeSensorTransitions(o.observations)),i+=1,t.refreshQuiescence(t.fixedDt,e.length)}return{steps:i,budget:n}}(this.settleHost(),t,u),f=n.length+i.length+r.length>0;(d>0||f||s.length>0)&&(this.revision+=1);const p=this.result(d,n,i,r,s,a??[],void 0,h??c);return this.updateResults.record({kind:"settle",count:d},this.revision===o?[]:f?Ps:Ls),p}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return function(t,e={}){const{baselineY:o=0,binWidth:n=24,gap:i=2,maxHeight:r=80,value:s="count",x:a}=e,c=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const l=Math.max(0,t[s]/c*r),u=a?.(t,e)??e*(n+i);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:o-l,width:n,height:l,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,o=0,n){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,o,n)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:o,chartId:n,...i}=t,r={...i,timestamp:e??this.elapsedSeconds,chartType:o??this.observation.chartType,chartId:n??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(t){return this.updateResults.subscribe(t)}version(){return this.revision}setPaused(t){const e=this.paused!==t;this.paused=t,this.syncSimulationState(),this.updateResults.record({kind:"pause"},e?$s:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?$s:[])}remove(t){const e=new Set(t),o=new Set(this.liveBodyOrder),n=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const i=t.filter(t=>o.has(t)||n.has(t));return i.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:i,count:i.length},i.length?Ps:[]),i}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},Ls),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},Ls)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},Ls)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,o,n)=>t.applyImpulse(e,o,n),clear:()=>t.clear(),hitTest:(e,o,n)=>t.hitTest(e,o,n),pause:()=>t.setPaused(!0),push:(e,o)=>t.enqueue(e,o),pushMany:(e,o)=>t.enqueue(e,o),bodyBudgetStatus:()=>t.bodyBudgetStatus(),readBodies:e=>t.readBodies(e),readSediment:()=>t.readSediment(),recordObservation:e=>t.recordObservation(e),remove:e=>t.remove(e),restore:e=>t.restore(e),resume:()=>t.setPaused(!1),settle:e=>t.settle(e),settleWithObservations:e=>t.settleWithObservations(e),snapshot:()=>t.snapshot(),sedimentHeightfield:e=>t.sedimentHeightfield(e),sedimentTotals:()=>t.sedimentTotals(),step:e=>t.tick(e)};var t}snapshot(){const t=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:ps(this.bodyBudget),config:{...this.config,kernel:gs(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(hs),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:t}}restore(t){this.config={bodyLimit:t.config.bodyLimit,eviction:t.config.eviction,fixedDt:t.config.fixedDt,maxDeltaSeconds:t.config.maxDeltaSeconds,maxSubsteps:t.config.maxSubsteps,settleStepLimit:t.config.settleStepLimit,timeScale:t.config.timeScale},this.configInput={...t.config,bodyBudget:ps(t.bodyBudget??{}),kernel:gs(t.world.options)},this.bodyBudget=ps(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(t.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(hs).sort(ys),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??Es(t.paused,t.visible,t.queue.length>0,t.world.bodies.every(t=>t.sleeping)),this.liveBodyOrder=t.liveBodyOrder.slice(),this.visible=t.visible,this.nextSequence=this.queue.reduce((t,e)=>Math.max(t,e.sequence),-1)+1,this.world.restore(t.world),this.updateResults.record({kind:"restore"},Ps)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const o=this.queue.shift();if(!o)return;this.spawnOne(o,e),t.push(o.id)}}spawnOne(t,e){this.liveBodyOrder=this.liveBodyOrder.filter(e=>e!==t.id),this.removeActiveSensorPairsForBodies(new Set([t.id])),this.world.spawn(t),this.liveBodyOrder.push(t.id);for(const e of t.springs??[])this.world.setConstraint({...e,bodyId:t.id});const o=this.world.readState().find(e=>e.id===t.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:t.id,datum:o?.datum??t.datum,x:o?.x??t.x,y:o?.y??t.y},e)}result(t,e,o,n,i,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const c=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:o,events:i,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:c,sedimented:n,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,o){if(0===e.length)return;const n=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=n.get(t.bodyId);o.emit({type:"physics-settle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:t.bodyId,datum:e?.datum,x:e?.x,y:e?.y})}}(this.world,t,this.observationContext(e))}observeSensorTransitions(t){this.activeSensorPairs=function(t,e,o){const n=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===n.size&&0===e.size)return n;const i=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:n,bodyId:r}=xs(e),s=o.observation.sensors[n],a=i.get(r);o.emit({type:"enter"===t?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:n,binId:s?.binId??n})};for(const t of Array.from(n).sort())e.has(t)||r("enter",t);for(const t of Array.from(e).sort())n.has(t)||r("exit",t);return n}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const o of t)e.has(xs(o).bodyId)&&t.delete(o)}(this.activeSensorPairs,t)}observationContext(t){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:e=>this.emitObservation(e,t)}}emitObservation(t,e){e?.push(t),this.observation.onObservation?.(t)}evaluateBodyBudget(){return function(t){const e=Math.max(0,Math.floor(t.liveBodies)),o=Math.max(0,Math.floor(t.queuedBodies??0)),n=e+o,i=rs(t.bodyLimit),r=rs(t.engineMaxBodiesHint),s=function(t,e,o){if(!1===o)return;const n=rs(o?.warnAt);return null!=n?n:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(i,r,t.options),a=null==i?0:Math.max(0,e-i),c=a>0?"overflow":null==s||s>n?"ok":"warning";return{action:"overflow"!==c?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:i,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:n,queuedBodies:o,state:c,warnAt:s}}({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(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const o=`${e.state}:${e.action}`;return o===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=o,this.emitObservation({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt},t)),e}syncSimulationState(t){const e=Es(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const o=this.simulationState;this.simulationState=e,function(t,e,o){o.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||o.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,simulationState:e,previousSimulationState:t})}(o,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:o,liveBodyOrder:n}=function(t,e,o,n,i,r){const s={evicted:[],sedimented:[],liveBodyOrder:i};if(!1===o)return s;const a=Math.max(0,Math.floor(n));if(!Number.isFinite(a))return s;const c=i.length-a;if(0>=c)return s;const l=function(t,e,o){if("sleeping-first"!==e)return o.slice();const n=new Map(t.readState().map(t=>[t.id,t.sleeping])),i=[],r=[];for(const t of o)n.get(t)?i.push(t):r.push(t);return[...i,...r]}(t,o,i),u=l.slice(0,c);if(0===u.length)return s;const d=function(t,e,o,n){const i=new Map(t.readState().map(t=>[t.id,t])),r=[];for(const t of o){const o=i.get(t);if(!o)continue;const s=e.add(o);s&&(r.push(t),n.emit({type:"physics-sediment",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:t,datum:o.datum,x:o.x,y:o.y,binId:s.id,count:s.count,total:s.total}))}return r}(t,e,u,r);t.remove(u);const h=new Set(u);return{evicted:u,sedimented:d,liveBodyOrder:i.filter(t=>!h.has(t))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(t));return e.length>0&&(this.liveBodyOrder=n,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:o}}};import{scaleLinear as js}from"d3-scale";function Ys(t){const{count:e,idPrefix:o,wallThickness:n,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const c=Math.min(r-1,a?.(e)??s),l=Math.max(1,r-c);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:i(e),y:c+l/2,width:n,height:l}}})}function Xs(t,e,o){const n=t.width/Math.max(1,e),i=Math.max(2,2*o),r=Math.min(.7*n,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:n,tubeWidth:r,ballDiameter:i,perRow:s,centerX:e=>t.x+(e+.5)*n,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*i}}import{scaleLinear as qs}from"d3-scale";function Gs(t){if(Array.isArray(t)&&t.length>=2){const e=mr(t[0]),o=mr(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=mr(e.x),n=mr(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Vs(t){return Array.isArray(t)?t.map(Gs).filter(t=>null!=t):[]}function Hs(t,e,o){return"normalized"===o?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:xr(t.x,e.plot.x,e.plot.x+e.plot.width),y:xr(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Us(t){let e=0;for(let o=1;t.length>o;o+=1)e+=Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y);return e}function Ks(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=xr(e,0,1)*Us(t);let n=0;for(let e=1;t.length>e;e+=1){const i=t[e-1],r=t[e],s=Math.hypot(r.x-i.x,r.y-i.y);if(s>0){if(n+s>=o){const t=(o-n)/s;return{x:i.x+(r.x-i.x)*t,y:i.y+(r.y-i.y)*t}}n+=s}}return{...t[t.length-1]}}function Zs(t,e){const o=Ks(t,Math.max(0,e-.02)),n=Ks(t,Math.min(1,e+.02)),i=n.x-o.x,r=n.y-o.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function Qs(t,e,o){return Math.max(e,Math.min(o,t))}function Js(t,e,o,n,i,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:o,x2:n,y2:i,thickness:r.thickness??8}}}function ta(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,o=t.y,n=t.width,i=t.height,{type:"aabb",x:e,y:o,width:n,height:i}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,o,n,i}function ea(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...ta({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function oa(t,e=12){return"number"==typeof t?{x:t,y:0}:t&&"object"==typeof t?{x:Number.isFinite(t.x)?Number(t.x):e,y:Number.isFinite(t.y)?Number(t.y):0}:{x:e,y:0}}import{scaleLinear as na}from"d3-scale";function ia(t,e,o){return G(t,e,o)}function ra(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&Z(o,t)||"#4e79a7":e=>{if(o){const t=Z(o,e);if(t)return t}let n=0;for(let t=0;e.length>t;t++)n=31*n+e.charCodeAt(t)|0;return t[Math.abs(n)%t.length]??"#4e79a7"}}function sa(t,e){const o=e.config??{},n=(e.sensors??[]).map(t=>({...t,sensor:!0})),i=[...e.colliders??[],...n],r=[...t.colliders??[],...o.colliders??[],...i];return{...t,...o,observation:{...t.observation,...o.observation},...r.length>0&&{colliders:r}}}function aa(t){const e=fa(t);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:e.left,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:t.width-e.rightInset,y2:e.top,thickness:e.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:t.floorY,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:t.width-e.rightInset,y1:e.top,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}}]}function ca(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function la(t){return`gauntlet:${t}:core`}function ua(t,e){return`gauntlet:${t}:positive:${e}`}function da(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var ha={left:28,top:76,rightInset:30,thickness:8};function fa(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return ha;const o=Math.max(1,Math.min(t.width,e)),n=Math.max(2,.04*t.width);return{left:n,top:Math.max(2,.08*e),rightInset:n,thickness:Math.max(1,Math.min(4,.04*o))}}function pa(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function ya(t,e,o,n){const i=fa(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,c=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:c(t,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:c(e,s,a)}}function ga(t,e,o=1){const n=[...t].sort((t,e)=>t.localeCompare(e)),i=Math.max(0,n.indexOf(e));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*o}}function ma(t,e,o){const n=t.activePositiveIds.reduce((t,o)=>t+(e.get(o)?.value??1),0),i=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(o.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*n-8*r-1.2*t.delay-5*i))}function xa(t){const e=function(t,e,o){const[n,i]=t,r=220>n||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,c=(e??[]).filter(t=>!1!==t.enabled),l=Math.max(1,c.length),u=.22*n,d=l>1?(.78*n-u)/(l-1):0,h=r?Math.max(Math.round(.12*n),.08*n+6):Math.max(Math.round(.14*n),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*i)):o),floorY:a,gates:c.map((t,e)=>({...t,id:t.id,x:t.x??Math.round(u+e*d),width:t.width??Math.max(r?8:54,Math.round(.07*n))})),graveyardX:Math.round(n*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(n*(r?.82:.92)),startX:h,width:n}}(t.size??[900,520],t.gates,t.crashOffset??30),o=t.positiveProperties??[],n=new Map(o.map(t=>[t.id,t])),i=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,o,n,i){const r=ca(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...ca(t,e,o.positiveAccessor,s)],c=[...ca(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...ca(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:c,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(ca(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:ca(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??ma(a,n,i)}}),a=s.flatMap((o,r)=>{const s=function(t,e,o,n){const i=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(o),r=n?.(t,e,o)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(o,r,e,t.projectPlacement);return function(t,e,o,n,i,r,s){const a=pa(o),c=Math.max(3,28*a),l=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??l,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},y=[{...d,id:la(t.id),x:h,y:f,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:c},spawnAt:d.spawnAt??t.startedAt,datum:p}],g=ya(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||c,o);y[0].x=g.x,y[0].y=g.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=ga(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),c=ya(g.x+Math.cos(r.angle)*r.radius,g.y+Math.sin(r.angle)*r.radius,s,o);y.push({id:ua(t.id,e),x:c.x,y:c.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:n.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:n,sourceDatum:t.datum},springs:!1===n.spring?[]:[{target:{type:"body",bodyId:la(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...n.spring??{}}]})}return t.negativeIds.forEach((e,n)=>{const i=r.get(e);i&&y.push(function(t,e,o,n,i,r,s){const a=pa(r),c=e.radius??Math.max(2,7.2*a),l=ya(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,c,r);return{id:da(t.id,e.id,o),x:l.x,y:l.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:c},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:la(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,g.x,g.y,o,d.spawnAt??t.startedAt))}),y}(o,r,e,s,n,i,t.coreBody)});return{layout:e,states:s,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:aa(e)}}}function ba(t=[]){const e=Object.create(null);for(const[o,n]of t)e[o]=n;return e}function va(...t){const e=ba();for(const o of t)for(const[t,n]of Object.entries(o??{}))e[t]=n;return e}function wa(t){return va(t)}function ka(t){return t.map(t=>({...t,sourceIds:t.sourceIds?[...t.sourceIds]:void 0,productIds:t.productIds?[...t.productIds]:void 0,relationIds:t.relationIds?[...t.relationIds]:void 0,outletIds:t.outletIds?[...t.outletIds]:void 0}))}function Aa(t){const e=ba(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:wa(e.initialMetrics),metrics:wa(e.metrics),productIds:[...e.productIds],history:ka(e.history)}])),o=ba(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:wa(e.metrics),sourceIds:[...e.sourceIds],history:ka(e.history)}])),n=ba(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?wa(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:wa(t.input.metrics)},metrics:wa(t.metrics),loss:{amount:t.loss.amount,metrics:wa(t.loss.metrics)},history:ka(t.history)}}var Sa=1e-9;function Ma(t,e){return e>t?-1:t>e?1:0}function _a(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Pa(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(Ma)}function La(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[_a("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function $a(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function Ra(t,e,o="selector"){const n=[],i=Object.values(t.components),r=new Set(i.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&n.push(_a("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,o+".ids",s)),void 0===e.count||Number.isInteger(e.count)&&e.count>=0||n.push(_a("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),n.some(t=>"error"===t.severity))return{ids:[],diagnostics:n};const a=e.ids?new Set(e.ids):null,c=e.categories?new Set(e.categories):null,l=e.statuses?new Set(e.statuses):null,u=e.outletIds?new Set(e.outletIds):null;let d=i.filter(t=>!a||a.has(t.id)).filter(t=>!c||c.has(t.category)).filter(t=>!l||l.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Ma);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(_a("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function Ta(t,e,o={}){return{eventId:t.event.id,effectType:e.type,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,label:t.event.label,summary:t.event.summary,...o}}function Ia(t,e){const o={...e,eventId:t.event.id};t.materializations.push(o),t.observations.push({...o,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt})}function Ca(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(_a("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function Oa(t,e,o){const n=Pa(e);e.length||t.diagnostics.push(_a("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(_a("error","duplicate-source",`Source ids may appear only once: ${n.join(", ")}.`,o,n));const i=e.filter(e=>!t.state.components[e]);i.length&&t.diagnostics.push(_a("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(_a("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,o,r));const s=e.filter(e=>"consumed"===t.state.components[e]?.status&&!r.includes(e));return s.length&&t.diagnostics.push(_a("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,o,s)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}function Fa(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+Sa)&&t.diagnostics.push(_a("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...La(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+Sa)&&t.diagnostics.push(_a("error","invalid-metric-loss",`Metric loss "${e}" must be non-negative and no greater than its sources.`,`${i}.metrics.${e}`));return!t.diagnostics.some(t=>"error"===t.severity)}function Da(t,e,o,n,i,r,s){return{id:t.id,label:t.label??t.id,description:t.description,category:t.category??"product",color:t.color,order:t.order,declaredAmount:t.amount,amount:r&&void 0!==t.amount?t.amount:o,metrics:r&&t.metrics?va(n,t.metrics):wa(n),status:r?"complete":"forming",sourceIds:[...e],outletId:r?t.outletId??(i.outletIds.has("product")?"product":void 0):void 0,createdByEventId:i.event.id,createdAt:i.context.appliedAt,completedByEventId:r?i.event.id:void 0,completedAt:r?i.context.appliedAt:void 0,history:[s]}}function za(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>Sa&&t.diagnostics.push(_a("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function Na(t,e,o){const n=`events.${t.event.id}.effects.${o}`,i=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(_a("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...La(e.metricsDelta,n+".metricsDelta")),Ca(t,e.outletId,n+".outletId");const o=Ra(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(_a("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=Ta(t,e,{sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of o.ids){const o=i.components[t];o.status=e.state,o.outletId=e.outletId,o.reason=e.reason,e.metricsDelta&&$a(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&Ia(t,{type:"retarget-component",sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0}))}if("set-relation"===e.type){const{relation:o}=e;o.id&&!i.relations[o.id]||t.diagnostics.push(_a("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,n+".relation.id",[o.id]));const r=function(t,e,o){const n=Pa(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(_a("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(_a("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(_a("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,o.sourceIds,n+".relation.sourceIds");if(t.diagnostics.push(...La(o.metrics,n+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;i.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?wa(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=Ta(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void Ia(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Pa(e.relationIds),r=e.relationIds.filter(t=>!i.relations[t]),s=e.relationIds.filter(t=>"resolved"===i.relations[t]?.status);if(o.length&&t.diagnostics.push(_a("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(_a("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(_a("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,n+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const o of e.relationIds){const n=i.relations[o];n.status="resolved",n.resolution=e.resolution,n.resolvedByEventId=t.event.id,n.resolvedAt=t.context.appliedAt,n.reason=e.reason}const a=Ta(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void Ia(t,{type:"resolve-relation",relationIds:[...e.relationIds]})}if("combine"===e.type||"contribute"===e.type){const o=t.productDefinitions.get(e.productId);o||t.diagnostics.push(_a("error","unknown-product",`Product "${e.productId}" has no declared mold.`,n+".productId",[e.productId]));const r=i.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(_a("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(_a("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=Oa(t,e.sourceIds,n+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,c=function(t,e,o,n){if(!e?.length)return[];const i=Pa(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),c=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(_a("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(_a("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(_a("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),c.length&&t.diagnostics.push(_a("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${c.join(", ")}.`,n,c)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,n+".basisRelationIds");if(!s||!c||!o||t.diagnostics.some(t=>"error"===t.severity))return;const l=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e=ba();for(const o of t)$a(e,o.metrics);return e}(s);if(!Fa(t,l,u,e.loss,n+".loss"))return;const d=l-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[n,i]of Object.entries(o?.metrics??{}))e[n]=Number(e[n]??0)-i,t.state.loss.metrics[n]=Number(t.state.loss.metrics[n]??0)+i}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,f=Ta(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&za(t,o,d,n+".productId"),p=Da(o,e.sourceIds,d,u,t,h,f),h&&!Ca(t,p.outletId,n+".productId"))return;i.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,$a(p.metrics,u),p.history.push(f);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(f);return i.history.push(f),function(t,e){if(e.length){for(const o of e)o.status="resolved",o.resolution="combined",o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt;Ia(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,c),Ia(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:p.outletId?[p.outletId]:void 0}),void(h&&Ia(t,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===e.type){const o=i.products[e.productId];return o?void function(t,e,o,n,i,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!Ca(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(_a("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(za(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=va(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=n,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const c=Ta(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(c),t.state.history.push(c),Ia(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,o,e.outletId,e.reason,e,n):void t.diagnostics.push(_a("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=Oa(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(_a("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=Pa(r);s.length&&t.diagnostics.push(_a("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),c=r.filter((t,e)=>!a[e]),l=r.filter(t=>i.products[t]);c.length&&t.diagnostics.push(_a("error","unknown-product",`Split references undeclared product molds: ${c.join(", ")}.`,n+".products",c)),l.length&&t.diagnostics.push(_a("error","duplicate-product",`Split products already exist: ${l.join(", ")}.`,n+".products",l));for(const[o,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(_a("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...La(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!Fa(t,u.amount,u.metrics,e.loss,n+".loss"))return;const d=u.amount-(e.loss?.amount??0),h=e.products.map((t,e)=>t.amount??a[e]?.amount),f=h.filter(t=>void 0!==t).length;if(0!==f&&f!==h.length)return void t.diagnostics.push(_a("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const p=f?h:e.products.map(()=>d/e.products.length),y=p.reduce((t,e)=>t+e,0);if(Math.abs(y-d)>Sa)return void t.diagnostics.push(_a("error","split-amount-mismatch",`Split allocations total ${y}, but ${d} remains after loss.`,n+".products"));const g=wa(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))g[t]=Number(g[t]??0)-o;const m=Ta(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],c=d>Sa?p[r]/d:1/e.products.length,l=ba(Object.entries(g).map(([t,e])=>[t,e*c])),h=o.metrics??s.metrics??l,f=Da({...s,amount:p[r],metrics:h},[u.id],p[r],wa(h),t,!0,m);Ca(t,f.outletId,`${n}.products.${r}.productId`)&&(i.products[f.id]=f)}),t.diagnostics.some(t=>"error"===t.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),i.loss.amount+=e.loss?.amount??0;for(const[t,o]of Object.entries(e.loss?.metrics??{}))i.loss.metrics[t]=Number(i.loss.metrics[t]??0)+o;i.history.push(m),Ia(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)Ia(t,{type:"complete-product",sourceIds:[u.id],productIds:[e],outletIds:i.products[e].outletId?[i.products[e].outletId]:void 0});return}if("eject"===e.type){Ca(t,e.outletId,n+".outletId");const o=Ra(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(_a("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=Ta(t,e,{sourceIds:o.ids,outletIds:[e.outletId]});for(const t of o.ids){const o=i.components[t];o.status=e.state??"ejected",o.outletId=e.outletId,o.reason=e.reason,o.history.push(s)}return i.history.push(s),void(o.ids.length&&Ia(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...La(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)$a(i.metrics,e.metricsDelta);else if("components"in e.target){const r=Ra(i,e.target.components,n+".target.components");if(t.diagnostics.push(...r.diagnostics),t.diagnostics.some(t=>"error"===t.severity))return;o=r.ids;for(const t of r.ids)$a(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Pa(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(_a("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(_a("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,n+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)$a(i.products[t].metrics,e.metricsDelta)}return void i.history.push(Ta(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(Ta(t,e)),t.observations.push({type:"crucible-outcome",eventId:t.event.id,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,outcome:e.outcome})):t.diagnostics.push(_a("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function Ea(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[_a("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=Aa(t),i={state:n,event:e,context:o,productDefinitions:new Map(o.products.map(t=>[t.id,t])),outletIds:new Set(o.outlets.map(t=>t.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,n]of e.effects.entries())if(Na(i,n,o),i.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:i.diagnostics};return n.elapsed=Math.max(n.elapsed,o.appliedAt),n.phaseId=o.phaseId,n.eventsApplied.push(e.id),i.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:n,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var Ba=[900,520],Wa=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],ja=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Ya=1e-9;function Xa(t,e){return e>t?-1:t>e?1:0}function qa(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Ga(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(Xa)}function Va(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Ha(t,e,o,n,i,r){if(!o)return n;try{return("function"==typeof o?o(t,e):t[o])??n}catch(t){return i.push(qa("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function Ua(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(qa("error","invalid-metrics","Metrics must be a numeric object.",o)),ba();const n=ba();for(const[i,r]of Object.entries(t)){const t=Va(r);null!=t?n[i]=t:e.push(qa("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function Ka(t){return t.map((t,e)=>({outlet:t,index:e})).sort((t,e)=>(t.outlet.order??t.index)-(e.outlet.order??e.index)||t.index-e.index).map(({outlet:t})=>({...t}))}function Za(t){const{id:e,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:c,restitution:l}=t,u=function(t,e,o){const n=o.map(([o,n])=>[Math.max(t,Math.min(o,n)),Math.min(e,Math.max(o,n))]).filter(([t,e])=>e>t+Ya).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+Ya&&i.push([r,t]),r=Math.max(r,e);return e>r+Ya&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:c,restitution:l,shape:"horizontal"===o?{type:"segment",x1:t,y1:n,x2:i,y2:n,thickness:a}:{type:"segment",x1:n,y1:t,x2:n,y2:i,thickness:a}}))}function Qa(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function Ja(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?Qa(t):1}function tc(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:Ja(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function ec(t){return"crucible:component:"+encodeURIComponent(t)}function oc(t,e,o,n){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const i=Math.min(...e,t),r=Math.max(...e,t);return r-i>Ya?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function nc(t,e){const o=Math.max(.25,Math.min(1,e.width/900,e.height/520)),n=t?.[0]??7*o,i=t?.[1]??18*o,r=Math.max(1,Math.min(n,i));return[r,Math.max(r,Math.max(n,i))]}function ic(t,e){if(!t)return[];const o=Math.min(t,Math.max(1,Math.ceil(Math.sqrt(t*Math.max(.5,e.width/Math.max(1,e.height)))))),n=Math.max(1,Math.ceil(t/o));return Array.from({length:t},(t,i)=>({x:e.x+e.width/o*(i%o+.5),y:e.y+(Math.floor(i/o)+.5)*(e.height/n)}))}function rc(t){return t.outletId?t.outletId:"failed"===t.status?"failed":"recovered"===t.status?"recovered":"retained"===t.status?"retained":"ejected"===t.status?"residue":void 0}function sc(t,e){return t.outlets.find(t=>t.id===e)||{x:t.chamber.x+.18*t.chamber.width,y:t.chamber.y+.2*t.chamber.height,width:.64*t.chamber.width,height:.6*t.chamber.height}}function ac(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>Xa(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>Xa(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=nc(o.radiusRange,e),a=function(t,e){const o=new Map;for(const e of t){const t=e.outletId??"__chamber__",n=o.get(t)??[];n.push(e),o.set(t,n)}const n=new Map;for(const[t,i]of o){i.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||Xa(t.id,e.id));const o=ic(i.length,sc(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>n.set(t.id,o[e]))}return n}(n,e),c=n.map(t=>{const n=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},i=1.28*oc(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(l=t.id,"crucible:product:"+encodeURIComponent(l)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:c};var l}),l=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=rc(t)??"__chamber__",o=l.get(e)??[];o.push(t),l.set(e,o)}const u=new Map;for(const[t,o]of l){const n=ic(o.length,sc(e,"__chamber__"===t?void 0:t));o.forEach((t,e)=>u.set(t.id,n[e]))}return[...i.map(t=>{let n=u.get(t.id);if(t.productIds.length){const o=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(o.length){n={x:o.reduce((t,e)=>t+e.x,0)/o.length,y:o.reduce((t,e)=>t+e.y,0)/o.length};const i=Qa(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));n={x:n.x+Math.cos(i)*r,y:n.y+Math.sin(i)*r}}}n??(n={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const i=oc(t.amount,r,o.bodyRadius,s),c={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:ec(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:c}}),...c]}var cc=ac;function lc(t){return Array.isArray(t)?t.map(lc):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>Xa(t,e)).map(([t,e])=>[t,lc(e)])):t}function uc(t,e=t.duration){const o=function(t,e){const o=Va(e)??0,n=Math.max(0,Math.min(t.duration,o));if(!t.phases.length)return{elapsed:n,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=n>=t.duration-Ya,r=i?t.phases[t.phases.length-1]:t.phases.find(t=>n>=t.start&&t.end>n)??t.phases[0];return{elapsed:n,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,n-r.start),complete:i}}(t,e);let n=Aa(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+Ya)break;const a=Ea(n,e,{phaseId:e.phaseId,authoredAt:e.authoredAt,appliedAt:e.authoredAt,products:t.products,outlets:t.outlets});i.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(n=a.state)}return n.elapsed=o.elapsed,n.phaseId=o.phaseId,n.phaseIndex=o.phaseIndex,n.phaseElapsed=o.phaseElapsed,n.complete=o.complete,o.complete&&"in_process"===n.outcome&&(n.outcome="complete"),n.playing=!1,{state:n,diagnostics:i,materializations:r,observations:s}}function dc(t){const e=function(t){const e=[];t.length||e.push(qa("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=Ga(t.map(t=>t.id));o.length&&e.push(qa("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=Va(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(qa("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(qa("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[t.id])),void 0===t.intensity||Number.isFinite(t.intensity)||e.push(qa("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.intensity`,[t.id]));const s={...t,duration:r,intensity:void 0===t.intensity?.5:Number.isFinite(t.intensity)?Math.max(0,Math.min(1,t.intensity)):.5,motion:t.motion??"hold",index:o,start:n,end:n+r};return n=s.end,s}),diagnostics:e}}(t.phases),o=e.phases.at(-1)?.end??0,n=Ka(t.outlets??Wa),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?va(t.metrics):void 0})),r=function(t,e,o){const n=[],i=Ga(t.map(t=>t.id));i.length&&n.push(qa("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,c;if(t.id.trim()||n.push(qa("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=Va(t.at.time);if(null==r||0>r||r>o+Ya)return void n.push(qa("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${i}.at.time`,[t.id]));s=Math.max(0,Math.min(o,r));const l=function(t,e,o){const n=t.find(t=>Ya>=Math.abs(t.start-o));if(n)return{phase:n,boundaryRank:1};const i=t.find(t=>o>=t.start&&t.end>o);return i?{phase:i,boundaryRank:0}:Ya>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=l.phase,c=l.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void n.push(qa("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${i}.at.phaseId`,[t.id,t.at.phaseId]));const o=t.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void n.push(qa("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${i}.at.progress`,[t.id]));s=a.start+a.duration*o,c=0===o?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:c}):n.push(qa("error","event-without-phase","Event could not be assigned to a phase.",`events.${i}.at`,[t.id]))}),r.sort((t,e)=>t.authoredAt-e.authoredAt||t.boundaryRank-e.boundaryRank||t.index-e.index),{events:r,diagnostics:n}}(t.events??[],e.phases,o),s=function(t){const e=[],o=ba(),n=[];let i=0;const r=ba();t.data.forEach((s,a)=>{const c=(s.id??"component-"+a)+"",l=((Ha(s,a,t.idAccessor,c,e,`data.${a}.id`)??c)+"").trim();if(!l)return void e.push(qa("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(l);const u=Va(Ha(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(qa("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[l]));const h=Ua(Ha(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=Ha(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=ja.has(f)?f:"active";ja.has(f)||e.push(qa("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[l]));const y=Ha(s,a,t.labelAccessor,(s.label??s.name??l)+"",e,`data.${a}.label`)+"",g=Ha(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,l)||(o[l]={id:l,label:y,category:g,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:va(h),metrics:va(h),productIds:[],history:[]},i+=d,function(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}(r,h))});const s=Ga(n);s.length&&e.push(qa("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=Ua(t.metrics??{},e,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:t.phases[0]?.id??"",phaseIndex:t.phases.length?0:-1,playing:!1,complete:0===t.phases.length,outcome:"in_process",eventsApplied:[],components:o,products:ba(),relations:ba(),input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:ba()},history:[]},diagnostics:e}}(t),a=function(t=Ba,e=Wa){const o=Math.max(1,Va(t[0])??900),n=Math.max(1,Va(t[1])??520),i=360>o||260>n,r=i?Math.max(4,.035*Math.min(o,n)):20,s=i?Math.max(10,.075*n):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},c=i?Math.max(16,.14*n):Math.min(78,.16*n),l={x:r,y:n-r-c,width:Math.max(1,o-2*r),height:c},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=l.y-(i?10:34),f={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,i?84:180)),y={x:f.x+(f.width-p)/2,y:f.y-(i?10:24),width:p,height:i?12:28},g=Ka(e),m={left:g.filter(t=>"left"===(t.side??"bottom")),right:g.filter(t=>"right"===t.side),bottom:g.filter(t=>"bottom"===(t.side??"bottom"))},x=[],b=(t,e)=>{const n=Math.max(8,u-1.5*r),s=f.height/Math.max(1,e.length);e.forEach((e,a)=>{x.push({...e,side:t,x:"left"===t?r:o-r-n,y:f.y+a*s,width:n,height:Math.max(8,s-(i?2:8))})})};b("left",m.left),b("right",m.right);const v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{x.push({...t,side:"bottom",x:f.x+e*v,y:f.y+f.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,l.y-f.y-f.height-(i?4:12))})}),x.sort((t,e)=>g.findIndex(e=>e.id===t.id)-g.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:f,mouth:y,projection:l,outlets:x}}(t.size??Ba,n),c=function(t){const{chamber:e,mouth:o}=t,n=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),i=Math.max(e.x,o.x),r=Math.min(e.x+e.width,o.x+o.width),s={left:t.outlets.filter(t=>"left"===t.side),right:t.outlets.filter(t=>"right"===t.side),bottom:t.outlets.filter(t=>"bottom"===t.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:e.x,y1:e.y,x2:i,y2:e.y,thickness:n}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:e.y,x2:e.x+e.width,y2:e.y,thickness:n}}];a.push(...Za({id:"crucible:wall:left",orientation:"vertical",fixed:e.x,start:e.y,end:e.y+e.height,openings:s.left.map(t=>[t.y,t.y+t.height]),thickness:n,friction:.46,restitution:.12}),...Za({id:"crucible:wall:right",orientation:"vertical",fixed:e.x+e.width,start:e.y,end:e.y+e.height,openings:s.right.map(t=>[t.y,t.y+t.height]),thickness:n,friction:.46,restitution:.12}),...Za({id:"crucible:wall:bottom",orientation:"horizontal",fixed:e.y+e.height,start:e.x,end:e.x+e.width,openings:s.bottom.map(t=>[t.x,t.x+t.width]),thickness:n,friction:.5,restitution:.08}));for(const e of t.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(e.id),sensor:!0,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}});return a}(a),l=function(t,e){const o=[],n=new Set(e.map(t=>t.id)),i=Ga(e.map(t=>t.id)),r=Ga(t.map(t=>t.id));return i.length&&o.push(qa("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(qa("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(qa("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(qa("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(qa("error","invalid-product-id","Product ids may not be empty.",`products.${e}.id`)),void 0===t.amount||Number.isFinite(t.amount)&&t.amount>=0||o.push(qa("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||n.has(t.outletId)||o.push(qa("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),Ua(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>Xa(t.id,e.id)).map(t=>({id:t.id,label:t.label,category:t.category,amount:t.amount,metrics:t.metrics,status:t.status})),phases:e.phases.map(({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:n,events:r.events.map(({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(lc(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>Xa(t.id,e.id)),i=n.map(t=>t.amount),r=nc(o.radiusRange,e),s=function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(Ja(o.seed)),a=e.mouth.x+e.mouth.width/2,c=e.chamber.y+Math.max(18,.18*e.chamber.height),l=Math.max(4,.28*e.chamber.width),u=Math.max(4,.12*e.chamber.height);return n.map((t,e)=>{const d=e/Math.max(1,n.length)*Math.PI*2+.18*(s()-.5),h=oc(t.amount,i,o.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:ec(t.id),x:a+Math.cos(d)*l*(.45+.45*s()),y:c+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...l],p={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:c,config:tc(t.seed,c),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},y=uc(p),g=Object.values(y.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=g.length?[qa("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return p.terminalState=y.state,p.terminalSpawns=cc(y.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...y.diagnostics,...m],p}import*as hc from"react";function fc(t,e){const o=t.fillStyle,n="#010203";try{t.fillStyle=n,t.fillStyle=e}catch{return t.fillStyle=o,[78,121,167]}const i=t.fillStyle;if(t.fillStyle=o,"string"!=typeof i)return[78,121,167];if(i.toLowerCase()===n&&e.trim().toLowerCase()!==n)return[78,121,167];if(i.startsWith("#"))return[parseInt(i.slice(1,3),16),parseInt(i.slice(3,5),16),parseInt(i.slice(5,7),16)];const r=i.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return r?[+r[1],+r[2],+r[3]]:[78,121,167]}import{curveMonotoneX as pc,curveMonotoneY as yc,curveCardinal as gc,curveCatmullRom as mc,curveStep as xc,curveStepBefore as bc,curveStepAfter as vc,curveBasis as wc,curveNatural as kc}from"d3-shape";function Ac(t){switch(t){case"monotoneX":return pc;case"monotoneY":return yc;case"cardinal":return gc;case"catmullRom":return mc;case"step":return xc;case"stepBefore":return bc;case"stepAfter":return vc;case"basis":return wc;case"natural":return kc;default:return null}}function Sc(t,e,o){if(null==e)return o;if(yi(e)){const n=function(t,e){const o=t.background??"transparent",n=t.stroke??"#000",i="transparent"===o||"none"===o?o:hi(e,o)||o,r=hi(e,n)||n||"#000",s="undefined"!=typeof window&&window.devicePixelRatio||1,a=`${gi(t)}|${i}|${r}@${s}`,c=mi.get(a);if(void 0!==c)return c;const l=function(t={},e){const{background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a={background:o,stroke:n,lineWidth:i,spacing:r,angle:s},c=Math.max(8,Math.ceil(2*r));let l;try{l=function(t){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(t,t):(ui||(ui=document.createElement("canvas")),ui.width=t,ui.height=t,ui)}(c)}catch{return li(a)}const u=l.getContext("2d");if(!u)return li(a);o&&"transparent"!==o?(u.fillStyle=o,u.fillRect(0,0,c,c)):u.clearRect(0,0,c,c),u.strokeStyle=n,u.lineWidth=i,u.lineCap="square";const d=s*Math.PI/180;if(45===s||-45===s){const t=s>0?1:-1;for(let e=-c;2*c>=e;e+=r)u.beginPath(),u.moveTo(e,0),u.lineTo(e+t*c,c),u.stroke()}else{u.save(),u.translate(c/2,c/2),u.rotate(d);const t=2*c;for(let e=-t;t>=e;e+=r)u.beginPath(),u.moveTo(-t,e),u.lineTo(t,e),u.stroke();u.restore()}return(e||u).createPattern(l,"repeat")}({background:i,stroke:r,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle},e),u=yi(l)?null:l;return mi.set(a,u),u}(e,t);return n||e.background&&hi(t,e.background)||o}return"string"!=typeof e?e:hi(t,e)||o}function Mc(t,e,o){const n=Sc(t,e,o);if("string"==typeof n&&n.trim().startsWith("var(")){const e=hi(t,o);return e&&!e.trim().startsWith("var(")?e:o}return n}function _c(t,e,o,n,i,r,s){const a=e.stops.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity)));if(2>a.length)return null;const c=t.createLinearGradient(n,i,r,s);for(const e of a)c.addColorStop(Math.max(0,Math.min(1,e.offset)),Pc(t,e,o));return c}function Pc(t,e,o){const n=e.color??o,i=hi(t,n)||n;if(null==e.opacity)return i;const r=Math.max(0,Math.min(1,e.opacity)),[s,a,c]=fc(t,i);return`rgba(${s},${a},${c},${r})`}import{jsx as Lc,jsxs as $c}from"react/jsx-runtime";function Rc(t){return Number.isFinite(t)?1e3>Math.abs(t)?Number.isInteger(t)?t+"":t.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):t.toLocaleString():"0"}function Tc(t,e,o,n){const i=t.datum;if(!i?.__crucible)return;const r="circle"===t.shape.type?t.shape.radius:8,s="string"==typeof e.fill?e.fill:"product"===i.kind?"#b8792d":"#356b63",a="string"==typeof e.stroke?e.stroke:"#26323a",c="number"==typeof e.strokeWidth?e.strokeWidth:1.25,l="number"==typeof e.opacity?e.opacity:.96,u=n?`${n}-crucible-body-${o}`:"crucible-body-"+o;if("product"===i.kind){const e=Array.from({length:6},(e,o)=>{const n=-Math.PI/2+o/6*Math.PI*2;return`${t.x+Math.cos(n)*r},${t.y+Math.sin(n)*r}`}).join(" "),o=u+"-glow";return $c(hc.Fragment,{children:[Lc("defs",{children:Lc("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Lc("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Lc("polygon",{points:e,fill:s,stroke:a,strokeWidth:c,opacity:l,filter:`url(#${o})`}),Lc("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:c,opacity:.72*l})]},u)}return $c(hc.Fragment,{children:[Lc("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:c,opacity:l}),Lc("circle",{cx:t.x-.25*r,cy:t.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as Ic,jsx as Cc,jsxs as Oc}from"react/jsx-runtime";var Fc="var(--semiotic-text, #26323a)",Dc="var(--semiotic-text-secondary, #6c7377)",zc="var(--semiotic-primary, #b8792d)",Nc="var(--semiotic-danger, #9f3d35)",Ec="var(--semiotic-success, #356b63)";function Bc(t){const{x:e,y:o,width:n,height:i}=t.chamber,r=Math.min(.14*n,48),s=o+i;return[`M ${e} ${o}`,`L ${e+r} ${s-.16*i}`,`Q ${e+n/2} ${s+.1*i} ${e+n-r} ${s-.16*i}`,`L ${e+n} ${o}`].join(" ")}function Wc({layout:t,phases:e,state:o,compact:n=!1}){const i=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return Oc("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[Oc("defs",{children:[Oc("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[Cc("stop",{offset:"0",stopColor:zc,stopOpacity:"0.03"}),Cc("stop",{offset:"0.66",stopColor:zc,stopOpacity:"0.1"}),Cc("stop",{offset:"1",stopColor:Nc,stopOpacity:"0.18"})]}),Cc("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:Cc("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Fc,strokeOpacity:"0.08",strokeWidth:"1"})})]}),Cc("rect",{x:t.chamber.x,y:t.chamber.y,width:t.chamber.width,height:t.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:Fc,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),Cc("path",{d:Bc(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),Cc("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:Fc,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:Cc("g",{"data-testid":"crucible-phase-rail",children:e.map((n,r)=>{const s=e.slice(0,r).reduce((t,e)=>t+Math.max(0,e.duration),0),a=t.phaseRail.x+s/i*t.phaseRail.width,c=Math.max(0,n.duration)/i*t.phaseRail.width,l=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return Oc("g",{children:[Cc("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,c-2),height:t.phaseRail.height,rx:2,fill:l?n.color??zc:u?Ec:Fc,fillOpacity:l?.68:u?.28:.09}),46>c?null:Cc("text",{x:a+c/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:l?Fc:Dc,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8.5,fontWeight:l?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),t.outlets.map(t=>Oc("g",{children:[Cc("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?Nc:Ec),fillOpacity:"0.1",stroke:t.color??("left"===t.side?Nc:Ec),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:Cc("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:Dc,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function jc({rows:t,layout:e,projection:o,amountLabel:n}){if(!t.length)return null;const i=o.measure??"count",r=t.map(t=>Math.max(0,function(t,e){return"count"===e?t.count:"amount"===e?t.amount:Number(t.metrics[e]??0)}(t,i))),s=Math.max(1,...r),a=e.projection.width/Math.max(1,t.length),c=e.projection.height>48?21:4,l=Math.max(5,e.projection.height-c-5);return Cc("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:t.map((t,o)=>{const u=r[o],d=Math.max(u>0?2:0,u/s*l),h=e.projection.x+o*a+.18*a;return Oc("g",{children:[Cc("rect",{x:h,y:e.projection.y+l-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?Nc:"complete"===t.status?zc:Ec,fillOpacity:"0.68"}),c>4&&a>=34?Oc(Ic,{children:[Cc("text",{x:h+.32*a,y:e.projection.y+l+10,fill:Dc,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),Oc("text",{x:h+.32*a,y:e.projection.y+l+19,fill:Fc,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Rc(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}function Yc(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}import{Fragment as Xc,jsx as qc,jsxs as Gc}from"react/jsx-runtime";function Vc(t,e,o,n,i){const r=Array.isArray(i)?i:i?[i]:[];if(!1!==o||0!==r.length)return({size:i})=>{const s=[Number(i[0])||700,Number(i[1])||420],a=hr(s),c=Math.max(2,Math.round(e)),l=a.plot.width/c,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[f,p]=n?.valueExtent??[0,c],y=p===f?1:p-f,g=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*l).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return Gc("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?Gc(Xc,{children:[Array.from({length:c+1},(t,e)=>{const o=a.plot.x+e*l;return qc("line",{"data-testid":"galton-board-bin-wall",x1:o,x2:o,y1:a.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+e)}),qc("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),qc("path",{d:g,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?qc("text",{x:a.plot.x+(e+.5)*l,y:Math.max(a.plot.y+10,u-t.value/d*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.value},`${t.label}-${e}`):null)]}):null,r.map((t,e)=>{const o=Number(t.value);if(!Number.isFinite(o))return null;const n=a.plot.x+Math.max(0,Math.min(1,(o-f)/y))*a.plot.width,i=t.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===t.labelPosition?Math.min(s[1]-8,u+16):a.plot.y+16;return Gc("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[qc("line",{x1:n,x2:n,y1:a.plot.y+8,y2:u-4,stroke:i,strokeDasharray:t.strokeDasharray??"6 5",strokeWidth:t.strokeWidth??2}),null==t.label?null:qc("text",{x:Math.min(a.plot.x+a.plot.width-4,n+6),y:r,fill:i,fontSize:10,fontWeight:700,children:t.label})]},`galton-reference-${e}-${o}`)})]})}}function Hc(t,e,o){if(!1!==o&&e)return({size:o})=>{const n=[Number(o[0])||760,Number(o[1])||360],i=hr(n),r=Math.max(1,e.windowCount),s=e.plot??i.plot,a=e.gutter??{x:s.x,y:s.y,width:0,height:s.height},c=e.windowPlot??s,l=c.width/r,u=s.y+s.height,d=s.y+.48*s.height,h=e.lidSegments[0]?.y1??d,f=e.windowStart,p=e.windowStart+r*e.windowSize,y=c.x+Math.max(0,Math.min(1,p===f?0:(e.watermarkValue-f)/(p-f)))*c.width;return Gc("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[qc("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?Gc("g",{children:[qc("rect",{x:a.x,y:h,width:a.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),qc("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(o,i)=>{const r=t[i],s=c.x+i*l,a=e.closedWindowCount>i,h=r?.secondary??0;return Gc("g",{children:[qc("rect",{x:s,y:d,width:l,height:u-d,fill:a?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?e.lidSegments.filter(t=>t.windowIndex===i).map(t=>qc("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},t.id)):null,Gc("text",{x:s+l/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),qc("text",{x:s+l/2,y:Math.min(n[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+i)}),e.lidSegments.filter(t=>null==t.windowIndex).map(t=>qc("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},t.id)),qc("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),qc("line",{"data-testid":"event-drop-watermark",x1:y,x2:y,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),Gc("text",{x:Math.min(s.x+s.width-4,y+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*e.watermarkValue)/100]}),e.lateCount>0?Gc("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[e.lateCount," late"]}):null]})}}function Uc(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const n=[Number(o[0])||700,Number(o[1])||380],i=hr(n),r=Xs(i.plot,t.length,e),s=i.plot.y+i.plot.height;return Gc("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[qc("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),t.map((t,e)=>{const o=Math.min(i.plot.height,r.pileHeight(t.value)),a=r.tubeWidth,c=r.centerX(e),l=s-o;return Gc("g",{children:[qc("rect",{x:c-a/2,y:l,width:a,height:o,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),qc("text",{x:c,y:Math.max(i.plot.y+12,l-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),qc("text",{x:c,y:Math.min(n[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${e}`)})]})}}function Kc(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function Zc(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],n=hr(o),i=n.plot.y+n.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,c=[{label:Kc(r),x:t.xRange[0]},{label:Kc(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:Kc(s),x:t.xRange[1]}];return Gc("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[t.groups.map(t=>Gc("g",{children:[qc("line",{x1:n.plot.x,x2:n.plot.x+n.plot.width,y1:t.y,y2:t.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),qc("text",{x:n.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),Gc("text",{x:n.plot.x+n.plot.width-4,y:t.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",t.count]})]},t.label)),qc("line",{x1:t.xRange[0],x2:t.xRange[1],y1:i,y2:i,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),c.map(t=>Gc("g",{children:[qc("line",{x1:t.x,x2:t.x,y1:i,y2:i+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),qc("text",{x:t.x,y:Math.min(o[1]-8,i+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${t.x}`))]})}}import{Fragment as Qc,jsx as Jc,jsxs as tl}from"react/jsx-runtime";var el={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"}};function ol(t,e,o){return Math.max(e,Math.min(o,t))}function nl(t){return 6.2*t.length}function il(t,e){const o=t.trim();if(e>=o.length)return o;if(1>=e)return o.slice(0,1);const n=o.split(/\s+/).filter(Boolean).map(t=>t[0]).join("").toUpperCase();return n.length>1&&e>=n.length?n:e>3?o.slice(0,Math.max(1,e-2))+"..":o.slice(0,e).toUpperCase()}function rl(t,e,o="auto"){const n=Math.max(1,Math.floor(e/6.2)),i="compact"===o?il(t,n):"full"===o?t:nl(t)>e?il(t,n):t;return{text:i,textLength:nl(i)>e?Math.max(4,e):void 0}}import{jsx as sl}from"react/jsx-runtime";function al(t,e,o={},n){if(!1===e||!t)return;const{volume:i,stages:r,groups:s,groupCompletion:a}=t,c=new Map(i.stages.map(t=>[t.id,t])),l=new Map(a.map(t=>[t.id,t]));return({size:t})=>{const e=Number(t[0])||i.width,a=Number(t[1])||i.height,u=r.map(t=>{const e=c.get(t.id),n=o["process-stage-"+t.id];return{id:t.id,label:t.label,x0:e?.x0??t.x-t.width/2,x1:(e?.x0??t.x-t.width/2)+(e?.width??t.width),x:t.x,width:e?.width??t.width,count:t.count,capacity:t.capacity,absorb:t.absorb,portalTarget:t.portalTarget,queueDepth:n?.queueDepth,processed:n?.processedCount}}),d=s.map(t=>{const e=l.get(t.id);return{id:t.id,label:t.label??t.id,x:t.anchor?.x??t.x??0,y:t.anchor?.y??t.y??0,absorbed:e?.absorbed,total:e?.total,complete:e?.complete}});return function(t,e={}){const{showFlowSpine:o=!0,showStageCounts:n=!0,showCapacityBadges:i=!0,showGroupSockets:r=!0,stageLabelMode:s="auto",outlineStages:a=!1,testId:c="process-flow-chrome"}=e,{width:l,height:u,left:d,right:h,topY:f,bottomY:p,midY:y,stages:g,groups:m=[]}=t,x=p-f;return tl("svg",{"aria-hidden":"true","data-testid":c,"data-outline-stages":a?"true":void 0,width:l,height:u,viewBox:`0 0 ${l} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",a?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[Jc("defs",{children:tl("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[Jc("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),Jc("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),Jc("rect",{x:0,y:0,width:l,height:u,fill:"url(#semiotic-process-floor)"}),Jc("rect",{x:d-6,y:f-8,width:h-d+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}),o?Jc("line",{x1:d+8,x2:h-8,y1:y,y2:y,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,g.map((t,e)=>{const o=function(t){return t.absorb?"absorb":t.portalTarget?"portal":null!=t.capacity?"capacity":"flow"}(t),r=el[o],c=Math.max(12,t.width-8),l=ol(c-8,22,88),d=rl(t.label,Math.max(8,l-10),s),h="none"!==s&&c-8>=22,m=function(t){if(null!=t.capacity){const e=null!=t.queueDepth?" · q "+t.queueDepth:"";return t.capacityLabel?`${t.capacityLabel}${e}`:`cap ${Number.isInteger(t.capacity)?t.capacity+"":t.capacity.toFixed(1)}${e}`}return t.absorb?"absorb":t.portalTarget?"portal":"flow"}(t),b=rl(m,Math.max(16,c-10),"auto"),v=i&&!1!==t.showBadge&&c>=32,w=null!=t.count?`n=${t.count}${null!=t.processed?" done "+t.processed:""}`:"",k=rl(w,Math.max(16,c-8),"auto"),A=Math.max(30,f-15),S=A-13;return tl("g",{"data-stage":t.id,"data-role":o,children:[Jc("rect",{className:"semiotic-process-chrome__stage-bay",x:t.x0+4,y:f+6,width:c,height:x-12,rx:10,fill:a?"none":r.fill,stroke:r.stroke,strokeWidth:a?1.85:"flow"===o?1:1.6}),g.length-1>e?Jc("polygon",{points:`${t.x1-2},${y-7} ${t.x1+8},${y} ${t.x1-2},${y+7}`,fill:r.accent,opacity:.85}):null,h?tl(Qc,{children:[Jc("rect",{className:"semiotic-process-chrome__stage-label-bg",x:t.x-l/2,y:S,width:l,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:r.stroke}),tl("text",{x:t.x,y:A,textAnchor:"middle",fill:r.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[Jc("title",{children:t.label}),d.text]})]}):null,v?tl("text",{x:t.x,y:f+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:[Jc("title",{children:m}),b.text]}):null,n&&null!=t.count?tl("text",{x:t.x,y:Math.min(u-8,p+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:[Jc("title",{children:w}),k.text]}):null]},t.id)}),r?m.map((t,e)=>{const o=t.total??0,n=t.absorbed??0,i=t.complete??(o>0&&n>=o),r=!i&&o>0&&n/o>=.75,s=i?"rgba(52, 211, 153, 0.35)":r?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",a=i?"#34d399":r?"#fbbf24":"var(--semiotic-border, #64748b)",c=o>0?`${n}/${o}${i?" shipped":r?" almost":""}`:"feature "+(e+1),l=ol(Math.max(54,nl(t.label)+18,nl(c)+16),54,104),u=rl(t.label,l-12,"auto"),d=rl(c,l-12,"auto");return tl("g",{"data-group":t.id,children:[Jc("rect",{x:t.x-l/2,y:t.y-22,width:l,height:44,rx:10,fill:s,stroke:a,strokeWidth:1.5}),tl("text",{x:t.x,y:t.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[Jc("title",{children:t.label}),u.text]}),tl("text",{x:t.x,y:t.y+12,textAnchor:"middle",fill:a,fontSize:9,fontWeight:700,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[Jc("title",{children:c}),d.text]})]},t.id)}):null]})}({width:e,height:a,left:i.left,right:i.right,topY:i.topY,bottomY:i.bottomY,midY:i.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...n})}}function cl(t,e,o){if(!1===o||!e||0===t.length)return;const n=new Map(e.volume.stages.map(t=>[t.id,t]));return({size:o})=>{const i=[Number(o[0])||e.volume.width,Number(o[1])||e.volume.height],r=hr(i),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),c=r.plot.y+6;return sl("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:e.stages.map((e,o)=>{const i=t[o];if(!i)return null;const r=n.get(e.id);if(!r)return null;const l=Math.max(2,i.value/s*a),u=Math.max(8,.35*r.width);return sl("rect",{x:r.x-u/2,y:c,width:u,height:l,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function ll(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}import{jsx as ul,jsxs as dl}from"react/jsx-runtime";function hl(t,e){const{showNodeLabels:o,showSensors:n,showStaticFlow:i}=e;if(t&&(i||n||o))return({size:e})=>{const r=[Number(e[0])||760,Number(e[1])||420],s=Math.max(1,...t.links.map(t=>t.throughput)),a=new Set(t.nodes.map(t=>t.sensorId));return dl("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[i?t.links.map(t=>{const e=3+t.throughput/s*16,o=t.path[Math.floor(t.path.length/2)];return dl("g",{children:[ul("path",{d:ll(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),ul("path",{d:ll(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?ul("text",{x:o.x,y:o.y-e/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:(n=t.throughput,n.toLocaleString(void 0,1e3>Math.abs(n)?{maximumFractionDigits:1}:{maximumFractionDigits:0}))}):null]},t.id);var n}):null,t.nodes.map(t=>dl("g",{children:[n&&a.has(t.sensorId)?ul("rect",{"data-testid":"physical-flow-sensor-overlay",x:t.x-12,y:t.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,i?ul("circle",{cx:t.x,cy:t.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,o?ul("text",{x:t.x,y:t.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:t.label}):null]},t.id))]})}}import{Fragment as fl,jsx as pl,jsxs as yl}from"react/jsx-runtime";function gl({layout:t,compact:e,showLabels:o}){const n=e?Math.round(.14*t.height):Math.max(80,t.routeY-180),i=e?Math.max(6,Math.round(.72*t.height)):Math.min(360,t.height-170);return pl(fl,{children:t.gates.map(r=>yl("g",{children:[pl("rect",{x:r.x-r.width/2,y:n,width:r.width,height:i,rx:e?2:12,fill:r.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:r.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),o?pl("text",{x:r.x,y:Math.max(64,t.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:r.label??r.id}):null]},r.id))})}function ml({layout:t,states:e,compact:o=!1}){return o?pl("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:pl(gl,{layout:t,compact:!0,showLabels:!1})}):yl("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[pl("path",{d:`M ${t.startX-42} ${t.routeY} C ${.24*t.width} ${t.routeY-70}, ${.42*t.width} ${t.routeY+78}, ${.58*t.width} ${t.routeY} S ${.78*t.width} ${t.routeY-82}, ${t.socketX+36} ${t.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),pl("line",{x1:Math.round(.06*t.width),x2:Math.round(.94*t.width),y1:t.crashY,y2:t.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),pl("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),pl(gl,{layout:t,compact:!1,showLabels:!0}),yl("g",{children:[pl("rect",{x:t.socketX-52,y:t.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),pl("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),yl("g",{children:[pl("rect",{x:t.graveyardX-82,y:t.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),pl("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),pl("text",{x:t.graveyardX,y:t.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:e.some(t=>t.killed)?"lift shut off":"too heavy or too small"})]})]})}function xl({states:t,layout:e}){const o=function(t){return t.map(t=>({label:t.id,value:Math.max(0,Number(t.viability)||0),outcome:t.outcome||t.stage||"in-process"}))}(t);if(!o.length)return null;const n=Math.max(1,...o.map(t=>t.value)),i=Math.max(40,(e.width-80)/o.length);return yl("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[pl("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),o.map((t,e)=>{const o=40+e*i,r=Math.max(2,t.value/n*28),s=/kill|crash|block|grave/i.test(t.outcome);return yl("g",{children:[pl("rect",{x:o+.18*i,y:28-r+22,width:Math.max(10,.45*i),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),pl("text",{x:o+.4*i,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:t.label})]},t.label)})]})}var bl={margin:(t,e)=>e.compactMode?"sparkline"===t.mode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}};function vl(t){return t.map(t=>({...t,spawnAt:void 0}))}function wl(t,e){return t?e?o=>dr.createElement(dr.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function kl(t,e,o){const n=e[o];return"boolean"==typeof n?n:!0!==t.__compactMode}var Al=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Sl(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return Al[(e>>>0)%Al.length]}var Ml={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,a=i.seed??1,c=Math.max(1,Math.round(i.pegRows??s-1)),l="mechanical"===i.mode,u=l?function(t){const e=Math.max(2,Math.round(t.bins)),o=Math.max(1,Math.round(t.pegRows??e-1)),n=Math.max(1,Math.round(t.count??Math.max(64,4*e))),i=xr(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=wr(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:n},(t,e)=>{let n=0;for(let t=0;o>t;t+=1)r()<i&&(n+=1);const a=o/2;return{id:`${s}-${e}`,value:n,mechanical:!0,pegRows:o,branchProbability:i,pathRights:n,side:a>n?"left":n>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:c,seed:a}):Array.isArray(t)?t:[],d=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:a}=t,c=hr(s),l=e.map((t,e)=>mr(gr(t,e,o))).filter(t=>null!=t),u=function(t){if(!t)return;const e=mr(t[0]),o=mr(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(a),d=u?.[0]??(l.length?Math.min(...l):0),h=u?.[1]??(l.length?Math.max(...l):1),f=h===d?1:h-d,p=kr().domain([0,n]).range([c.plot.x,c.plot.x+c.plot.width]),y=Array.from({length:n},()=>0),g=[];e.forEach((t,e)=>{const r=mr(gr(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-d)/f*n)));y[s]+=1,g.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:c.plot.y+i+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...t,value:r,bin:s}})});const m=c.plot.y+c.plot.height;return{config:yr(r,[...bs({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...vs({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:p,yTop:c.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:g,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:y.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot:c.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:a,size:r,valueExtent:l?[0,c]:void 0});return{...n,config:d.config,initialSpawns:vl(d.initialSpawns),projectionRows:d.projectionRows,foregroundGraphics:wl(Vc(d.projectionRows,s,kl(n,i,"showProjection"),d.metadata,i.referenceLines),n.foregroundGraphics),bodyStyle:pr(e||i.colorBy||(l?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},_l={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:n,windows:i,watermark:r,ballRadius:s,seed:a,size:c,timeExtent:l,timeScale:u=1}=t,d=hr(c),h=e.map((t,e)=>mr(gr(t,e,o))).filter(t=>null!=t),f=mr(l?.[0]),p=mr(l?.[1]),y=h.length?Math.min(...h):0,g=h.length?Math.max(...h):y+i.size,m=Math.min(f??y,y),x=Math.max(p??g,g),b=Math.floor(m/i.size)*i.size,v=Math.max(1,Math.ceil((x-b+i.size)/i.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):mr(r?.value)??w-(r?.delay??i.size),A=Math.max(0,Math.min(v,Array.from({length:v},(t,e)=>e).reduce((t,e)=>b+(e+1)*i.size>k?t:t+1,0))),S=function(t,e){const o=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:o,height:t.plot.height},windowPlot:{x:t.plot.x+o,y:t.plot.y,width:Math.max(40,t.plot.width-o),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(d,s),M=b+v*i.size,_=js().domain([b,M]).range([S.windowPlot.x,S.windowPlot.x+S.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),L=[];e.forEach((t,e)=>{const r=mr(gr(t,e,o));if(null==r)return;const a=mr(gr(t,e,n))??r,c=Math.max(0,Math.min(v-1,Math.floor((r-b)/i.size))),l=k>=b+(c+1)*i.size;P[c].value+=l?0:1,P[c].secondary+=l?1:0,L.push({id:(t.id??"event-"+e)+"",x:Math.max(S.windowPlot.x+s,Math.min(S.windowPlot.x+S.windowPlot.width-s,_(r))),y:d.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:c,late:l}})});const $=d.plot.y+d.plot.height,R=function(t,e){const o=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!o)return[];const n=t.windowStart,i=t.windowStart+t.windowCount*t.windowSize,r=js().domain([n,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,c=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),l=t=>s===a?e:c+(t-a)/(s-a)*(e-c),u=[];for(let e=0;o>e;e+=1){const o=t.windowStart+e*t.windowSize,n=o+t.windowSize,i=r(o),s=r(n);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:i,y1:l(i),x2:s,y2:l(s)})}return u}({closedWindowCount:A,gutter:S.gutter,plot:d.plot,windowCount:v,windowPlot:S.windowPlot,windowSize:i.size,windowStart:b},d.plot.y+.28*d.plot.height);return{config:yr(a,[...bs({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Ys({idPrefix:"eventdrop-window",count:v,xScale:t=>_(b+t*i.size),yTop:S.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>A)return null;const e=0===t?R[0]?.y1:R[t-1]?.y2??R[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?S.wallTop:e+1.25*s},yBottom:$,wallThickness:6}),...R.map(t=>({id:t.id,shape:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:L,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:u},projectionRows:P.map((t,e)=>({label:`${b+e*i.size}-${b+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:A,gutter:S.gutter,lidSegments:R,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:d.plot,windowPlot:S.windowPlot,watermarkValue:k,windowCount:v,windowSize:i.size,windowStart:b}}}({data:Array.isArray(t)?t:[],timeAccessor:i.timeAccessor||"time",arrivalAccessor:i.arrivalAccessor||"arrivalTime",windows:i.windows||{size:10},watermark:i.watermark,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r,timeExtent:i.timeExtent,timeScale:i.timeScale??1});return{...n,config:s.config,initialSpawns:vl(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:wl(Hc(s.projectionRows,s.metadata,kl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:pr(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},Pl={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,a=function(t){const{data:e,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:a}=t,c=br(i,1),l=hr(a),u=[],d=new Map,h=new Map,f=[];function p(t){let e=d.get(t);return null==e&&(e=u.length,u.push(t),d.set(t,e)),e}e.forEach((t,e)=>{p((gr(t,e,o)??"unknown")+"")});const y=Math.max(1,u.length),g=Xs(l.plot,y,r),m=Math.max(0,g.tubeWidth/2-r-1),x=u.map(()=>[]);e.forEach((t,e)=>{const i=(gr(t,e,o)??"unknown")+"",s=p(i),a=n?mr(gr(t,e,n)):1,u=Math.max(0,Math.round((a??0)/c)),d=g.centerX(s);for(let o=0;u>o;o+=1){const n=h.get(i)??0,a=g.perRow>1?((g.perRow>1?n%g.perRow:0)/(g.perRow-1)*2-1)*m:0;h.set(i,n+1),x[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:l.plot.y+r+2,vx:(o%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:i,unitIndex:o}})}});const b=x.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;b>t;t+=1)for(const e of x)e.length>t&&f.push(e[t]);const v=l.plot.y+l.plot.height,w=[...bs({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 t=0;y>t;t+=1){const e=g.centerX(t);for(const o of[-1,1])w.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*g.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:yr(s,w,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(t=>({label:t,value:h.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),o=e.length?e:["Intake"],n=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),i=br(t.unitValue,1),r=wr(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),c=a.reduce((t,e)=>t+e,0)||1,l=n-o.length,u=a.map(t=>t/c*l),d=u.map(t=>1+Math.floor(t));let h=n-d.reduce((t,e)=>t+e,0);const f=u.map((t,e)=>({index:e,fraction:t-Math.floor(t)})).sort((t,e)=>e.fraction-t.fraction);for(let t=0;h>0;t=(t+1)%f.length)d[f[t].index]+=1,h-=1;return o.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*i,mechanical:!0,unitCount:d[e],unitValue:i,share:d[e]/n}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...n,config:a.config,initialSpawns:vl(a.initialSpawns),projectionRows:a.projectionRows,foregroundGraphics:wl(Uc(a.projectionRows,i.ballRadius??5,kl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:pr(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},Ll={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:n,radiusAccessor:i,pointRadius:r,seed:s,size:a,xExtent:c,collisionIterations:l,settle:u}=t,d=hr(a),h=wr(s),f=[],p=[],y=new Map;e.forEach((t,e)=>{const s=mr(gr(t,e,o));if(null==s)return;const a=n?(gr(t,e,n)??"All")+"":"All",c=i?mr(gr(t,e,i)):null,l=xr(null!=c&&c>0?c:r,2,18);!function(t){let e=y.get(t);null==e&&(e=p.length,p.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:l})});const g=f.map(t=>t.value),m=c?mr(c[0]):null,x=c?mr(c[1]):null,b=g.length?Math.min(...g):0,v=g.length?Math.max(...g):1;let w=m??b,k=x??v;if(w===k&&(w-=.5,k+=.5),w>k){const t=k;k=w,w=t}const A=Math.max(r,...f.map(t=>t.radius)),S=d.plot.x+A+8,M=d.plot.x+d.plot.width-A-8,_=qs().domain([w,k]).range([S,M]),P=Math.max(1,p.length),L=Math.min(Math.max(28,3*A),d.plot.height/4),$=d.plot.y+L,R=Math.max(0,d.plot.y+d.plot.height-L-$),T=t=>{const e=y.get(t)??0;return 1===P?d.plot.y+.54*d.plot.height:$+e/(P-1)*R},I=new Map,C=f.map((t,e)=>{I.set(t.group,(I.get(t.group)??0)+1);const o=_(t.value),n=T(t.group),i=(h()-.5)*t.radius*1.6,r=(h()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:u?o+i:xr(o+(e%9-4)*t.radius*2.5,S,M),y:u?n+r:d.plot.y-18-e%12*t.radius,vx:u?0:22*(h()-.5),vy:u?0:24+18*h(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:o,targetY:n},springs:[{target:{type:"point",x:o,y:n},restLength:0,stiffness:34,damping:5.5}]}});return{config:yr(s,bs({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*A),collisionIterations:Math.max(1,Math.round(l??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:C,projectionRows:p.map(t=>({label:t,value:I.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[S,M],groups:p.map(t=>({label:t,y:T(t),count:I.get(t)??0})),plot:d.plot}}}({data:Array.isArray(t)?t:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...n,config:s.config,initialSpawns:vl(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:wl(Zc(s.metadata,kl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:pr(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},$l={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,420],s=Array.isArray(i.stages)?i.stages:[],a=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,n=hr(o),i=xr(t.ballRadius??6,2,18),r=t.seed??1,s=wr(r),a=t.idAccessor,c=t.stageAccessor??"stage",l=t.groupBy,u=t.groupLabelAccessor,d=t.workAccessor,h=t.radiusAccessor,f=t.groupCompletion??(l?"allAbsorbed":"none"),p=t.springStiffness??.28,y=t.springDamping??.72,g=!0===t.settle,m=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),x=function(t){const e=t.shape??"lane",o=Math.max(1,Math.round(t.width)),n=Math.max(1,Math.round(t.height)),i=t.padX??46,r=t.padY??72,s=i,a=o-i,c=r,l=n-Math.max(24,Math.round(.45*r)),u=(c+l)/2,d=Math.max(1,l-c),h=Qs(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,y=Qs(d*h+p,.06*d,.5*d),g=y/2,m=u-g,x=u+g,b=t.idPrefix??"process",v=t.friction??.58,w=t.restitution??.18,k=t.wallThickness??8,A=t.stages;if(!A.length)throw Error("processStageLayout requires at least one stage");const S=Qs(t.centerStageIndex??Math.floor(A.length/2),0,A.length-1),M=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(A),_=a-s;let P=s;const L=A.map((t,e)=>{const o=P,n=e===A.length-1?a:P+(t.share??1)/M*_;return P=n,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:o,x1:n,x:(o+n)/2,width:n-o,y:u,height:d}}),$=L[S],R=$.x0,T=$.x1,I=(t,o)=>{if("lane"===e)return"top"===o?c:l;if("funnel"===e){const e=Qs((t-s)/Math.max(1,a-s),0,1);return"top"===o?c+(m-c)*e:l+(x-l)*e}if(R>=t){const e=Qs((t-s)/Math.max(1,R-s),0,1);return"top"===o?c+(m-c)*e:l+(x-l)*e}if(T>=t)return"top"===o?m:x;const n=Qs((t-T)/Math.max(1,a-T),0,1);return"top"===o?m+(c-m)*n:x+(l-x)*n},C=L.map(t=>{const e=Math.min(I(t.x0,"top"),I(t.x1,"top")),o=Math.max(I(t.x0,"bottom"),I(t.x1,"bottom"));return{...t,y:(e+o)/2,height:Math.max(1,o-e)}}),O={thickness:k,friction:v,restitution:w},F=[];"lane"===e?F.push(Js(b+"-top",s,c,a,c,O),Js(b+"-bottom",s,l,a,l,O),Js(b+"-left",s,c,s,l,{...O,thickness:Math.max(6,k-2)}),Js(b+"-right",a,c,a,l,{...O,thickness:Math.max(6,k)})):"funnel"===e?F.push(Js(b+"-top",s,c,a,m,O),Js(b+"-bottom",s,l,a,x,O),Js(b+"-left",s,c,s,l,{...O,thickness:Math.max(6,k-2)}),Js(b+"-right",a,m,a,x,{...O,thickness:Math.max(6,k)})):F.push(Js(b+"-left-top",s,c,R,m,O),Js(b+"-left-bottom",s,l,R,x,O),Js(b+"-center-top",R,m,T,m,O),Js(b+"-center-bottom",R,x,T,x,O),Js(b+"-right-top",T,m,a,c,O),Js(b+"-right-bottom",T,x,a,l,O),Js(b+"-left",s,c,s,l,{...O,thickness:Math.max(6,k-2)}),Js(b+"-right",a,c,a,l,{...O,thickness:Math.max(6,k)}));const D=t.membraneDampingScale??.5,z=s,N=Math.max(1,("bowtie"===e?R:a)-z),E=(t.membranes??[]).map(t=>{const e=z+Qs(t.offset,0,1)*N,o=t.width??18+18*t.cost,n=d-16,i=u+.25*(t.wobble??0);return{...t,x:e,y:i,width:o,height:n}}),B=!1===t.includeMembraneRegions?[]:E.map(t=>function(t){const e=t.dampingScale??.5,o=t.energyScale??1,n=Qs(t.cost,0,2);return{...ta({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:n,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:n*e,energyDelta:-n*o}}({id:t.id,label:t.label??t.id,description:t.description??(t.label??t.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:t.x,y:t.y,width:t.width,height:t.height,cost:t.cost,dampingScale:t.dampingScale??D,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:o,height:n,padX:i,padY:r,left:s,right:a,topY:c,bottomY:l,midY:u,centerLeft:R,centerRight:T,pinchHeight:y,pinchTop:m,pinchBottom:x,stages:C,membranes:E,colliders:F,regionEffects:B,boundaryY:I}}({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,n.plot.x),padY:Math.max(36,n.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((t,e)=>[t.id,e])),v=new Map(x.stages.map(t=>[t.id,t])),w=x.stages[0].id,k=x.stages[0],A=new Set(e.filter(t=>t.absorb).map(t=>t.id)),S=e.map(t=>{const e=v.get(t.id)??k;return function(t,e){const o={id:"process-stage-"+t.id,label:t.label??t.id,description:t.description,x:e.x,y:e.y,width:Math.max(12,.92*e.width),height:Math.max(40,.88*e.height),semanticItem:!1,attributes:{stageId:t.id}};if(t.absorb)return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:24,y:0};return{...ta({...t,kind:t.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.02,charge:t.charge??"absorbed"}}({...o,kind:t.kind??"sink",force:oa(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return n={...o,kind:t.kind??"force-field",force:oa(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...ta({...n,kind:n.kind??"force-field",attributes:{primitive:"portal",targetStage:n.targetStage,..."object"==typeof n.attributes&&n.attributes?n.attributes:{}}}),force:n.force,impulseOnEnter:n.impulseOnEnter,damping:n.damping??.08}}var n;if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force;return{...ta({...t,kind:t.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:t.capacity,unitsPerSecond:t.unitsPerSecond??t.capacity,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping,charge:t.charge??t.capacity}}({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:oa(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...o.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return function(t){const e=t.pressure??t.occupancy??0,o=t.baseDamping??.08,n=t.dampingPerUnit??.12,i=t.energyPerUnit??0;return{...ta({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o+e*n,energyDelta:i?-e*i:void 0,force:t.force}}({...o,kind:t.kind??"membrane",pressure:e.pressure,occupancy:e.occupancy,baseDamping:e.baseDamping??t.damping??.1,dampingPerUnit:e.dampingPerUnit??.1,energyPerUnit:e.energyPerUnit??0,force:oa(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?ea({...o,kind:t.kind??"force-field",force:oa(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):function(t){return{...ta({...t,kind:t.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,damping:t.damping,energyDelta:t.energyDelta}}({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:x.midY,width:e.width,height:x.bottomY-x.topY})});S.unshift(ea({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 M=new Map;for(const t of x.stages)M.set(t.id,0);const _=[];t.data.forEach((t,e)=>{const o=(a?gr(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(gr(t,e,c)??w)+"",r=b.has(n)?n:w;M.set(r,(M.get(r)??0)+1);const s=l?(gr(t,e,l)??"")+"":void 0,f=s&&u?(gr(t,e,u)??s)+"":s,p=d?mr(gr(t,e,d))??1:1,y=h?mr(gr(t,e,h)):null,g=xr(null!=y&&y>0?y:i,2,18);_.push({datum:t,id:o,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:g,index:e})});const P=new Map,L=new Map;for(const t of _){if(!t.groupId)continue;const e=P.get(t.groupId)??[];e.push(t.id),P.set(t.groupId,e),t.groupLabel&&L.set(t.groupId,t.groupLabel)}const $=xr(t.groupAnchorAlong??.55,.15,.9),R=x.left+(x.right-x.left)*$,T=Array.from(P.keys()),I=T.map((t,o)=>{const n=P.get(t)??[],i=T.length>1?x.topY+28+o/Math.max(1,T.length-1)*(x.bottomY-x.topY-56):x.midY;return function(t){const e=t.x??t.anchor?.x??0,o=t.y??t.anchor?.y??0;return{id:t.id,label:t.label,description:t.description,group:t.group,bodyIds:t.bodyIds,datum:t.datum,state:t.state,x:e,y:o,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:o},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}({id:t,label:L.get(t)??t,bodyIds:n,anchor:{x:R,y:i},x:R,y:i,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),C=function(t,e){const o=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],n=e.filter(t=>!o.has(t)),i=e.length-n.length,r=t.completion?.mode??"allMembersAbsorbed",s=t.completion?.valueByBodyId,a=t=>{const e=s&&Object.prototype.hasOwnProperty.call(o=s,n=t)?o[n]:void 0;var o,n;return"number"==typeof e&&Number.isFinite(e)&&e>=0?e:1},c=e.reduce((t,e)=>t+a(e),0),l=e.reduce((t,e)=>t+(o.has(e)?a(e):0),0),u=t.completion?.threshold,d="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):c:void 0;return{id:t.id,label:t.label??t.id,mode:r,complete:e.length>0&&("anyAbsorbed"===r?i>0:"threshold"===r?l>=(d??c):0===n.length),absorbed:i,total:e.length,absorbedValue:l,totalValue:c,threshold:d,missing:n}})}(I,_.filter(t=>A.has(t.stageId)).map(t=>t.id)),O=new Map(I.map(t=>[t.id,t])),F=_.map((t,e)=>{const o=v.get(t.stageId)??k,n=o.x+(s()-.5)*Math.min(24,.2*o.width),i=x.boundaryY(n,"top")+t.radius+10,r=x.boundaryY(n,"bottom")-t.radius-10,a=r>i?i+s()*Math.max(1,r-i):x.midY,c=g?n:x.left+18+e%7*4,l=g?a:x.midY+(s()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:n,y:a},restLength:.45*t.radius,stiffness:p,damping:y}];if(t.groupId){const e=O.get(t.groupId);e?.anchor&&!A.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:c,y:l,vx:g?0:40+40*s(),vy:g?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:g?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),D={kernel:{seed:r,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},z=x.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),N=e.map(t=>{const e=v.get(t.id)??k;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:M.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:D,initialSpawns:F,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:z,metadata:{kind:"process-flow",plot:n.plot,volume:x,stages:N,groups:I,groupCompletion:C,regionEffects:S}}}({data:Array.isArray(t)?t:[],stages:s,size:r,idAccessor:i.idAccessor,stageAccessor:i.stageAccessor||"stage",groupBy:i.groupBy,groupLabelAccessor:i.groupLabelAccessor,workAccessor:i.workAccessor,radiusAccessor:i.radiusAccessor,ballRadius:i.ballRadius??6,seed:i.seed??1,groupCompletion:i.groupCompletion,groupAnchorAlong:i.groupAnchorAlong,settle:i.settle??!0,gravityX:i.gravityX,gravityY:i.gravityY}),c=a.metadata;return{...n,config:a.config,initialSpawns:vl(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:c?.regionEffects,backgroundGraphics:wl(al(a.metadata,kl(n,i,"showChrome"),{},i.chromeOptions),n.backgroundGraphics),foregroundGraphics:wl(cl(a.projectionRows,a.metadata,kl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:pr(e||i.colorBy||i.groupBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.workAccessor||i.stageAccessor||"stage"})}}},Rl={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=xa({data:Array.isArray(t)?t:[],size:r,gates:i.gates,positiveProperties:i.positiveProperties,negativeProperties:i.negativeProperties,crashOffset:i.crashOffset,idAccessor:i.idAccessor,positiveAccessor:i.positiveAccessor,negativeAccessor:i.negativeAccessor,metricsAccessor:i.metricsAccessor,initialViability:i.initialViability,projectPlacement:i.projectPlacement,coreBody:i.coreBody,viability:i.viability});return{...n,config:s.config,initialSpawns:vl(s.initialSpawns),projectionRows:[],backgroundGraphics:wl(kl(n,i,"showChrome")?dr.createElement(ml,{layout:s.layout,states:s.states,compact:!0===n.__compactMode}):void 0,n.backgroundGraphics),foregroundGraphics:wl(kl(n,i,"showProjection")?dr.createElement(xl,{layout:s.layout,states:s.states}):void 0,n.foregroundGraphics),bodyStyle:pr(e||i.colorBy)}}},Tl={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=dc({data:Array.isArray(t)?t:[],phases:Array.isArray(i.phases)?i.phases:[],products:Array.isArray(i.products)?i.products:void 0,outlets:Array.isArray(i.outlets)?i.outlets:void 0,events:Array.isArray(i.events)?i.events:void 0,idAccessor:i.idAccessor,labelAccessor:i.labelAccessor,categoryAccessor:i.categoryAccessor,amountAccessor:i.amountAccessor,metricsAccessor:i.metricsAccessor,initialStateAccessor:i.initialStateAccessor,metrics:i.metrics,size:r,seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange}),a="snapshot"===i.playback?function(t,e){if(void 0===e)return t.duration;if("number"==typeof e)return Math.max(0,Math.min(t.duration,Va(e)??0));const o=t.phases.find(t=>t.id===e.phaseId);if(!o)return t.duration;const n=Math.max(0,Math.min(1,Va(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,c=uc(s,a).state,l=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const o=e.groupBy??"outlet",n=new Map,i=t=>{const e=function(t,e){return"product"===e?"product"===t.kind?t.id:"unassigned":"outlet"===e?t.outletId??"unassigned":"category"===e?t.category:t.status}({...t,status:t.status??"active"},o),i=n.get(e);if(i)return i.count+=1,i.amount+=t.amount,void $a(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:wa(t.metrics),status:"status"===o?t.status:void 0,outletId:"outlet"===o?t.outletId:void 0,category:"category"===o?t.category:void 0,productId:"product"===o&&"product"===t.kind?t.id:void 0})};for(const e of Object.values(t.components))e.productIds.length||"consumed"===e.status||i({kind:"component",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});for(const e of Object.values(t.products))i({kind:"product",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});const r=new Map((e.order??[]).map((t,e)=>[t,e]));return[...n.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||Ma(t.key,e.key))}(c,l),d=l.measure??"count",h=function(t,e={}){const o=e.bodies??[],n=Math.max(0,e.recentBodyLimit??6),i=new Map;for(const t of o){const o=e.getContainerId?.(t);if(!o)continue;const n=i.get(o);n?n.push(t):i.set(o,[t])}const r=t.map(t=>{const o=i.get(t.id)??[],r=Math.max(0,Math.floor(t.count??o.length)),s=o.slice(Math.max(0,o.length-n)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??Yc(t),datum:t.datum}));return{id:t.id,label:t.label,count:r,share:0,secondary:t.secondary,secondaryLabel:t.secondaryLabel,observed:t.observed,bodyIds:o.map(t=>t.id),recentBodies:s,metadata:t.metadata}}),s=r.reduce((t,e)=>t+e.count,0);return r.map(t=>({...t,share:s>0?t.count/s:0}))}(u.map(t=>({id:t.key,label:t.label,count:t.count,secondary:"count"===d||"amount"===d?t.amount:Number(t.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),f={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},p=e??i.colorBy??"category",y=!1===i.showChrome?null:dr.createElement(Wc,{layout:s.layout,phases:s.phases,state:c,compact:520>r[0]||360>r[1]}),g=!1===i.showProjection?null:dr.createElement(jc,{rows:u,layout:s.layout,projection:l,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:vl(ac(c,s.layout,f)),projectionRows:h,bodyStyle:t=>function(t,e,o,n){const i=t.datum,r={stroke:n.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:n.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:n.opacity??.96};if(!i?.__crucible)return{...r,fill:n.color??"#b8792d"};if("product"===i.kind){const t=e.products[i.semanticId];return{...r,fill:n.color??t?.color??Sl(t?.id??i.semanticId)}}const s=e.components[i.semanticId];if(!s)return{...r,fill:n.color??"#356b63"};let a;return a="status"===o?s.status:"outlet"===o?s.outletId??"in chamber":"product"===o?s.productIds[0]??"unalloyed":"category"===o||null==o?s.category:"function"==typeof o?(o(s.datum)??"unassigned")+"":(s.datum[o+""]??"unassigned")+"",{...r,fill:n.color??Sl(a)}}(t,c,p,i),getBodyLabel:t=>function(t,e){const o=t.datum;if(o?.__crucible)return"product"===o.kind?e.products[o.semanticId]?.label:e.components[o.semanticId]?.label}(t,c),renderBodySVG:Tc,backgroundGraphics:wl(y,n.backgroundGraphics),foregroundGraphics:wl(g,n.foregroundGraphics)}}},Il={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:n,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:c,particleRadius:l,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:y,sourceAccessor:g,targetAccessor:m,throughputAccessor:x}=t,b=hr(y),v=wr(p),w=new Map,k=new Map,A=[];function S(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const o=(gr(t,e,r)??t.id??e)+"",n=mr(gr(t,e,s)),i=mr(gr(t,e,a));if(null!=n&&null!=i){const t={x:n,y:i};w.set(o,t),A.push(t)}k.set(o,(t.label??t.name??o)+"")});const M=[];n.forEach((t,e)=>{const o=S(gr(t,e,g)),n=S(gr(t,e,m)),i=Math.max(0,mr(gr(t,e,x))??0),r=Vs(d?gr(t,e,d):void 0),s=r.length?r:Vs(t.path??t.points??t.route);s.forEach(t=>A.push(t)),M.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const _=(L=A,"normalized"===(P=e)||"pixels"===P?P:L.length>0&&L.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var P,L;const $=new Map;for(const[t,e]of w)$.set(t,Hs(e,b,_));const R=[];for(const t of M){let e=t.rawPath.map(t=>Hs(t,b,_));if(2>e.length){const o=$.get(t.source),n=$.get(t.target);o&&n&&(e=[o,n])}else $.has(t.source)||$.set(t.source,e[0]),$.has(t.target)||$.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(k.has(t.source)||k.set(t.source,t.source),k.has(t.target)||k.set(t.target,t.target),R.push({...t,path:e,packetCount:0}))}const T=br(u,.12),I=Math.max(1,Math.round(i)),C=R.map(t=>Math.max(1,Math.round(t.throughput*T))),O=C.reduce((t,e)=>t+e,0),F=O>I?I/O:1;R.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(C[e]*F))});let D=R.reduce((t,e)=>t+e.packetCount,0);for(;D>I;){const t=R.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>R[t].packetCount)?o:t,-1);if(-1===t)break;R[t].packetCount-=1,D-=1}const z=new Map,N=new Map,E=[],B=br(o,90),W=br(l,4);R.forEach((t,e)=>{z.set(t.target,(z.get(t.target)??0)+t.throughput),N.set(t.source,(N.get(t.source)??0)+t.throughput);const o=Us(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=f?i:xr(.12+.84*i+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=Ks(t.path,s),c=Ks(t.path,r),l=Zs(t.path,s),u={x:-l.y,y:l.x},d=(v()-.5)*W*1.5;E.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:l.x*B+10*(v()-.5),vy:f?0:l.y*B+10*(v()-.5),mass:.8,spawnAt:f?0:.04*e+n/32,shape:{type:"circle",radius:W},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:n,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:B,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target},springs:"none"!==h&&f?[{target:{type:"point",x:c.x,y:c.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const j=Math.max(18,5*W),Y=Array.from($,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+vr(t),point:e})),X=Y.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:j,height:j}})),q=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),G=yr(p,[...bs({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});G.bodyLimit=I,G.eviction="oldest",G.observation={...G.observation,sensors:q};const V=Array.from($,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+vr(t),incoming:z.get(t)??0,outgoing:N.get(t)??0})),H=R.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:G,initialSpawns:E,projectionRows:V.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:E.length,totalThroughput:R.reduce((t,e)=>t+e.throughput,0),plot:b.plot,nodes:V,links:H}}}({nodes:Array.isArray(i.nodes)?i.nodes:[],links:Array.isArray(i.links)?i.links:Array.isArray(i.edges)?i.edges:Array.isArray(t)?t:[],nodeIdAccessor:i.nodeIdAccessor||"id",nodeXAccessor:i.nodeXAccessor||"x",nodeYAccessor:i.nodeYAccessor||"y",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",throughputAccessor:i.throughputAccessor||"value",pathAccessor:i.pathAccessor||"path",coordinateMode:i.coordinateMode||"auto",particleRate:i.particleRate??.16,maxParticles:i.maxParticles??180,particleRadius:i.particleRadius??4,flowSpeed:i.flowSpeed??90,pathConstraint:i.pathConstraint||"path",reducedMotion:!0,seed:i.seed??1,size:r});return{...n,config:s.config,initialSpawns:vl(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:wl(hl(s.metadata,{showNodeLabels:!1!==i.showNodeLabels,showSensors:!1!==i.showSensors,showStaticFlow:!1!==i.showStaticFlow}),n.foregroundGraphics),bodyStyle:pr(e||i.colorBy||"source")}}},Cl={frameType:"physics",layout:bl,buildProps:(t,e,o,n,i)=>{const r=n.size??[700,380],s=St(n.theme),a=function(t){const e=function(t,e,o){const n=t?.observation;return{...t,observation:{...n,chartId:e??n?.chartId??"physics-custom",chartType:n?.chartType??"PhysicsCustomChart",onObservation:o??n?.onObservation}}}(t.config,t.chartId,t.onObservation),o=ia(t.colorScheme,t.themeCategorical,w),n=hr(t.size),i={data:t.data,scales:{x:na().domain(t.xExtent??[0,1]).range([n.plot.x,n.plot.x+n.plot.width]),y:na().domain(t.yExtent??[0,1]).range([n.plot.y+n.plot.height,n.plot.y])},dimensions:n,theme:{semantic:t.semantic,categorical:[...o]},resolveColor:ra(o,t.colorScheme),config:t.layoutConfig??{},world:new Ws(e)},r=t.skipLayout?{}:t.layout(i)??{},s=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...n}=t,i=o.get(e)??[];i.push(n),o.set(e,i)}return t.map(t=>{const e=o.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:sa(e,r),context:i,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:i.chartId,colorScheme:o,config:i.config,data:Array.isArray(t)?t:[],layout:i.layout,layoutConfig:i.layoutConfig,semantic:kt(s)??{},size:r,themeCategorical:s.colors.categorical,xExtent:i.xExtent,yExtent:i.yExtent});return{...n,config:a.config,initialSpawns:vl(a.initialSpawns),projectionRows:[],bodyStyle:a.result.bodyStyle??pr(e||i.colorBy),backgroundGraphics:wl(n.backgroundGraphics,a.result.backgroundOverlays),foregroundGraphics:wl(n.foregroundGraphics,a.result.overlays)}}};import*as Ol from"react-dom/server";import*as Fl from"react";import*as Dl from"react-dom/server";var zl=class{constructor(t){if(this._capacity=t,this.head=0,this._size=0,1>t)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(t)}push(t){let e;return this._size===this._capacity?e=this.buffer[this.head]:this._size++,this.buffer[this.head]=t,this.head=(this.head+1)%this._capacity,e}pushMany(t){const e=[];for(const o of t){const t=this.push(o);void 0!==t&&e.push(t)}return e}get(t){if(t>=0&&this._size>t)return this.buffer[(this.head-this._size+t+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let t=0;return{next:()=>this._size>t?{done:!1,value:this.get(t++)}:{done:!0,value:void 0}}}forEach(t){const e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t(this.buffer[(e+o)%this._capacity],o)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t[o]=this.buffer[(e+o)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let o=0,n=[];e.length>t&&(o=e.length-t,n=e.slice(0,o)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=o;e.length>t;t++)this.push(e[t]);return n}update(t,e){const o=[],n=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++){const r=(n+i)%this._capacity,s=this.buffer[r];if(t(s)){let t;t="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},o.push(t),this.buffer[r]=e(s)}}return o}remove(t){const e=[],o=[];if(this.forEach(n=>{t(n)?o.push(n):e.push(n)}),0===o.length)return o;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return o}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},Nl=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(t){Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}evict(t){t!==this._min&&t!==this._max||(this._dirty=!0)}recalculate(t,e){this._min=1/0,this._max=-1/0;for(const o of t){const t=e?e(o):o;Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function El(t,e){return t===e}function Bl(t,e){if("function"==typeof t)return e=>+t(e);const o=t||e;return t=>+t[o]}function Wl(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}function jl(t,e){return"function"==typeof t?e=>t(e)+"":t?e=>e[t]+"":e?t=>t[e]+"":void 0}function Yl(t){return t?"function"==typeof t?t:e=>e[t]||e.id:null}function Xl(t){return"string"==typeof t?t:t.id}var ql=/^\d{4}-\d{1,2}$/;function Gl(t){const e=t.trim();if(!e||!Number.isNaN(Number(e)))return NaN;const o=ql.test(e)?e+"-01":e;if(o===e&&10>e.length)return NaN;const n=Date.parse(o);return Number.isFinite(n)?n:NaN}function Vl(t){return t instanceof Date?t.getTime():"string"==typeof t?Gl(t):+t}function Hl(t){return new Set(Array.isArray(t)?t:[t])}function Ul(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Kl(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Zl(t,e,o){return t+(e-t)*o}function Ql(){return"undefined"!=typeof performance?performance.now():Date.now()}function Jl(t,e,o){if(1>=o)return 1;const n=o-1;return function(t){const e=Math.max(0,Math.min(1,t.minOpacity??.1));if(Number.isNaN(t.age))return 1;if(t.age===1/0)return e;if(!Number.isFinite(t.extent)||0>=t.extent)return 1;const o=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>o?1:e;if("exponential"===t.type){const n=t.halfLife??t.extent/2;return e+Math.pow(.5,o/(n>0?n:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-o/t.extent))*(1-e)}({age:n-e,extent:n,type:t.type,halfLife:t.halfLife??o/2,threshold:t.stepThreshold??.5*o,minOpacity:t.minOpacity??.1})}function tu(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function eu(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function ou(t,e,o,n){let i=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,i=!0),t._pulseColor!==o&&(t._pulseColor=o,i=!0),t._pulseGlowRadius!==n&&(t._pulseGlowRadius=n,i=!0),i):(0!==t._pulseIntensity&&(t._pulseIntensity=0,i=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,i=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,i=!0),i)}function nu(t,e,o=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const n=t.duration??500,i=e.peek();return null!=i&&n>o-i}function iu(t,e,o){if(e._transitionKey)return e._transitionKey;switch(e.type){case"point":if(e.pointId)return"p:"+e.pointId;if("streaming"===t.runtimeMode&&e.datum){const o=t.getX(e.datum),n=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${o}:${n}`;if(null!=o&&null!=n)return`p:${o}:${n}`}return"p:"+o;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+o;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??o}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+o:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function ru(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}var su=Object.create(null);function au(t){su[t.chartType]=t}var cu="undefined"==typeof window||"undefined"==typeof document,lu=new Set;function uu(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;du(n)&&0===o.length&&hu(i,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),o.length>0&&o.every(t=>null==t.datum)&&hu(i,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function du(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(du))}function hu(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function fu(t){try{return{kind:"success",result:t.run()}}catch(e){const o=t.hasPreviousResult,n=function(t,e,o,n){const i=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${i.message}`,error:i,recovery:o?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:o,affectedRevision:n}}(t.family,e,o,t.revision);"production"!==process.env.NODE_ENV&&console.error(`[semiotic] ${t.logLabel} threw:`,e);try{t.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return{kind:"failure",diagnostic:n,preservedLastGoodScene:o}}}function pu(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function yu(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=pu(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=Bl(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e+i:e},getBottom:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e-i:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const o=Array.isArray(t.band)?t.band:[t.band];for(const t of o)e.push({kind:"band",getTop:pu(t.y1Accessor,"y1"),getBottom:pu(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as gu,scaleLog as mu,scaleSymlog as xu,scaleTime as bu}from"d3-scale";function vu(t,e,o,n,i,r=!1){const s=new Map;for(const a of t){const t=e(a),c=o(a);if(null==t||null==c||Number.isNaN(t)||Number.isNaN(c))continue;const l=Math.floor(t/n)*n;let u=s.get(l);if(u||(u={start:l,end:l+n,total:0,categories:new Map,...r?{rows:[],categoryRows:new Map}:{}},s.set(l,u)),u.total+=c,u.rows?.push(a),i){const t=i(a);if(u.categories.set(t,(u.categories.get(t)||0)+c),u.categoryRows){let e=u.categoryRows.get(t);e||(e=[],u.categoryRows.set(t,e)),e.push(a)}}}return s}function wu(t,e,o,n,i,r){const s=[];for(const i of t){const t=o(i),r=n(i);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:i})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),c=Array(s.length),l=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],c[t]=e.rawY,l[t]=e.d}return{type:"line",path:a,rawValues:c,style:i,datum:l,group:r}}function ku(t,e,o,n,i,r,s,a){const c=[];for(const r of t){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const l=e.x(t),u=a?a(r):i;c.push({px:l,topY:e.y(s),botY:e.y(u),rawY:s})}c.sort((t,e)=>t.px-e.px);const l=Array(c.length),u=Array(c.length),d=Array(c.length);for(let t=0;c.length>t;t++){const e=c[t];l[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:l,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function Au(t,e,o,n){const i=new Map;if("silhouette"===n)for(const n of t){let t=0;for(const i of e)t+=o(i,n)||0;i.set(n,-t/2)}else if("wiggle"===n){t.length>0&&i.set(t[0],0);for(let n=1;t.length>n;n++){const r=t[n-1],s=t[n];let a=0,c=0,l=0;for(const t of e){const e=o(t,s)||0;a+=(2*l+e)*(e-(o(t,r)||0)),c+=e,l+=e}const u=i.get(r)??0;i.set(s,u-(c>0?a/(2*c):0))}if(t.length>0){let n=0;for(const r of t){let t=0;for(const n of e)t+=o(n,r)||0;n+=(i.get(r)??0)+t/2}const r=n/t.length;for(const e of t)i.set(e,(i.get(e)??0)-r)}}else for(const e of t)i.set(e,0);return i}function Su(t,e,o,n,i,r,s){const a=o(t),c=n(t);if(!Number.isFinite(a)||!Number.isFinite(c))return null;const l={type:"point",x:e.x(a),y:e.y(c),r:i,style:r,datum:t};return void 0!==s&&(l.pointId=s),l}function Mu(t,e,o,n,i,r,s,a){const c=o(t),l=n(t);if(!Number.isFinite(c)||!Number.isFinite(l))return null;const u={type:"symbol",x:e.x(c),y:e.y(l),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function _u(t,e,o,n,i,r,s){return{type:"rect",x:t,y:e,w:o,h:n,style:i,datum:r,group:s}}function Pu(t,e,o,n,i,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:n,fill:i,datum:r};return void 0!==s?.value&&(a.value=s.value),s?.showValues&&(a.showValues=!0,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function Lu(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function $u(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return mu().domain(t).range(o).clamp(!0)}return"symlog"===t?xu().domain(e).range(o):"time"===t?bu().domain([new Date(e[0]),new Date(e[1])]).range(o):gu().domain(e).range(o)}function Ru(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Tu(t,e){const o=new zl(t.capacity);return t.forEach(()=>o.push(e)),o}function Iu(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function Cu(t,e,o){if(!e||0===e.size)return;const n=new Set;if(t.forEach((t,e)=>{o(t)&&n.add(e)}),0===n.size)return;const i=e.toArray();e.clear();for(let t=0;i.length>t;t++)n.has(t)||e.push(i[t])}var Ou=new WeakMap;function Fu(){return this.updateResults.last}function Du(){return this.updateResults.last}function zu(t){return this.updateResults.subscribe(t)}function Nu(t){this.config.layoutSelection=t}function Eu(){Ou.set(this,!0)}function Bu(){const t=!0===Ou.get(this);return Ou.delete(this),t}function Wu(t){Object.assign(t.prototype,{getLastUpdateResult:Fu,getUpdateSnapshot:Du,subscribeUpdateResult:zu,setLayoutSelection:Nu,markStylePaintPending:Eu,consumeStylePaintPending:Bu})}var ju=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Yu=["scene-style","data-paint","accessibility","evidence"],Xu=(t,e)=>({retainedData:t,invalidations:e}),qu=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Gu=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Vu=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Hu=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Uu=["scene-geometry","data-paint","accessibility","evidence"],Ku=["scene-style","data-paint","accessibility","evidence"],Zu=[],Qu={chartType:Xu("rebuild",qu),runtimeMode:Xu("rebuild",qu),xAccessor:Xu("rebuild",qu),yAccessor:Xu("rebuild",qu),timeAccessor:Xu("rebuild",qu),valueAccessor:Xu("rebuild",qu),y0Accessor:Xu("rebuild",qu),boundsAccessor:Xu("rebuild",qu),band:Xu("rebuild",qu),openAccessor:Xu("rebuild",qu),highAccessor:Xu("rebuild",qu),lowAccessor:Xu("rebuild",qu),closeAccessor:Xu("rebuild",qu),candlestickRangeMode:Xu("rebuild",qu),accessorRevision:Xu("rebuild",qu),groupAccessor:Xu("rebuild",Gu),categoryAccessor:Xu("rebuild",Gu),lineDataAccessor:Xu("rebuild",Gu),colorAccessor:Xu("rebuild",Ku),sizeAccessor:Xu("rebuild",Uu),symbolAccessor:Xu("rebuild",Uu),pointIdAccessor:Xu("rebuild",Uu),xScaleType:Xu("preserve",Vu),yScaleType:Xu("preserve",Vu),xExtent:Xu("preserve",Vu),yExtent:Xu("preserve",Vu),extentPadding:Xu("preserve",Vu),scalePadding:Xu("preserve",Vu),axisExtent:Xu("preserve",Vu),yAxisExtent:Xu("preserve",Vu),binSize:Xu("preserve",Vu),normalize:Xu("preserve",Vu),heatmapAggregation:Xu("preserve",Vu),heatmapXBins:Xu("preserve",Vu),heatmapYBins:Xu("preserve",Vu),arrowOfTime:Xu("preserve",Hu),baseline:Xu("preserve",Hu),stackOrder:Xu("preserve",Hu),sizeRange:Xu("preserve",Hu),curve:Xu("preserve",Hu),areaGroups:Xu("preserve",Hu),customLayout:Xu("preserve",Hu),layoutConfig:Xu("preserve",Hu),layoutMargin:Xu("preserve",Hu),symbolMap:Xu("preserve",Uu),showValues:Xu("preserve",Uu),heatmapValueFormat:Xu("preserve",Uu),lineStyle:Xu("preserve",Ku),pointStyle:Xu("preserve",Ku),areaStyle:Xu("preserve",Ku),barStyle:Xu("preserve",Ku),swarmStyle:Xu("preserve",Ku),waterfallStyle:Xu("preserve",Ku),candlestickStyle:Xu("preserve",Ku),boundsStyle:Xu("preserve",Ku),gradientFill:Xu("preserve",Ku),lineGradient:Xu("preserve",Ku),semanticLineStops:Xu("preserve",Ku),colorScheme:Xu("preserve",Ku),themeCategorical:Xu("preserve",Ku),themeSemantic:Xu("preserve",Ku),themeSequential:Xu("preserve",Ku),themeDiverging:Xu("preserve",Ku),barColors:Xu("preserve",Ku),decay:Xu("preserve",Ku),pulse:Xu("preserve",Ku),staleness:Xu("preserve",Ku),layoutSelection:Xu("preserve",Ku),annotations:Xu("preserve",["overlay","accessibility","evidence"]),windowSize:Xu("preserve",Zu),windowMode:Xu("preserve",Zu),maxCapacity:Xu("preserve",Zu),clock:Xu("preserve",Zu),transition:Xu("preserve",Zu),introAnimation:Xu("preserve",Zu),onLayoutError:Xu("preserve",Zu)},Ju=Xu("preserve",Hu),td=class{constructor(){this.tracker=new Ss}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},ju)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Yu):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=Qu[n]??Ju;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as ed}from"d3-quadtree";var od=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(t,e){if("scatter"!==t&&"bubble"!==t&&"custom"!==t)return void this.clear();let o=0,n=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(o++,t.r>n&&(n=t.r));if(this.maxRadius=n,500>=o)return void(this.tree=null);const i=Array(o);let r=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(i[r++]=t);this.tree=ed().x(t=>t.x).y(t=>t.y).addAll(i)}},nd=class t{constructor(t){if(this.xExtent=new Nl,this.yExtent=new Nl,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new td,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.spatialIndex=new od,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,o)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;const l=i??(()=>{const t=new Map;for(let e=0;o.length>e;e++)t.set(o[e],e);return t})();for(const o of e){if("line"===o.type)continue;if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[o.datum];let i=0,a=!1;for(const o of e){const e=l.get(o);if(null==e)continue;a=!0;const s=n.get(e);if(null==s)continue;const c=eu(t,s,r);c>i&&(i=c)}a&&(c=ou(o,i,s)||c);continue}const e=l.get(o.datum);if(null==e)continue;const i=n.get(e);c=ou(o,null==i?0:eu(t,i,r),s,a)||c}return c}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new zl(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=Bl(t.timeAccessor||t.xAccessor,"time"),this.getY=Bl(t.valueAccessor||t.yAccessor,"value")):(this.getX=Bl(t.xAccessor,"x"),this.getY=Bl(t.yAccessor,"y")),this.getGroup=jl(t.groupAccessor),this.getCategory=jl(t.categoryAccessor),this.getSize=t.sizeAccessor?Bl(t.sizeAccessor,"size"):void 0,this.getColor=jl(t.colorAccessor),this.getSymbol=jl(t.symbolAccessor),this.getY0=t.y0Accessor?Bl(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=yu(t),this.getPointId=jl(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?Bl(t.openAccessor,"open"):void 0,this.getHigh=Bl(t.highAccessor,"high"),this.getLow=Bl(t.lowAccessor,"low"),this.getClose=o?Bl(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new zl(t.windowSize))}currentTime(){return this.config.clock?.()??Ql()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Tu(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(t)),void this.yExtent.push(this.getLow(t));this.yExtent.push(this.getY(t)),this.getY0&&this.yExtent.push(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.push(o),Number.isFinite(n)&&this.yExtent.push(n)}}evictDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(t)),void this.yExtent.evict(this.getLow(t));this.yExtent.evict(this.getY(t)),this.getY0&&this.yExtent.evict(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.evict(o),Number.isFinite(n)&&this.yExtent.evict(n)}}rebuildYExtent(){this.yExtent.clear();for(const t of this.buffer)this.pushDatumYExtent(t)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(const t of this.buffer)this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t)}ingest(t){if(t.bounded&&this._lastBoundedInsertsRef===t.inserts)return this.updateResults.recordNoop("replace"),!1;const e=this.currentTime();if(this.lastIngestTime=e,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,t.bounded){this._lastBoundedInsertsRef=t.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const o=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=o?Bl(this.config.timeAccessor||this.config.xAccessor,"time"):Bl(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],o=this.config.xAccessor,n="function"==typeof o?o(e):e[o||"x"],i=n instanceof Date,r="string"==typeof n&&Number.isFinite(Gl(n));if(this.xIsDate=i||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>Vl(e[t]):t=>Vl(o(t))}}Ru(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Iu(this.buffer,o,this.timestampBuffer,e),this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o)}else for(const o of t.inserts){if("growing"===this.config.windowMode&&this.buffer.full){const t=this.config.maxCapacity??1e5;t>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,t),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"===process.env.NODE_ENV||this.growingCapacityWarned||5e4>this.growingCap||(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${t}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}const t=Iu(this.buffer,o,this.timestampBuffer,e);this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o),null!=t&&(this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t))}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(o,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.xExtent.extent,a=this.yExtent.extent;let c="waterfall"===e.chartType&&o.size>0?function(t,e,o,n,i){const r=Array.from(new Set(t.map(e).filter(t=>Number.isFinite(t)))).sort((t,e)=>t-e);if(2>r.length)return Lu(o,n);const s=r[0],a=r[1],c=r[r.length-1],l=r[r.length-2];return Lu("log"===i&&s>0?[s/Math.sqrt(a/s),c*Math.sqrt(c/l)]:[s-(a-s)/2,c+(c-l)/2],n)}(r,this.getX,s,e.xExtent,e.xScaleType):Lu(s,e.xExtent),l=Lu(a,e.yExtent);const u=!(!(d=e.yExtent)||null==d[0]||null==d[1]);var d;const h="exact"===(e.yAxisExtent??e.axisExtent);if("stackedarea"===e.chartType&&!u&&o.size>0){const t=function(t){const{config:e,groups:o,getX:n,getY:i}=t,r="exact"===(e.yAxisExtent??e.axisExtent);if(e.normalize){const o=[0,r?1:1+e.extentPadding];return{yDomain:o,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:o}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,c=new Set;let l=0;const u=new Map,d=new Map;for(const t of o){const e=new Map;let o=0;for(const r of t.data){const t=n(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),c.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>l&&(l=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",f=(t,e)=>e>t?-1:t>e?1:0;let p,y;if("input"===h)p=o.map(t=>t.key);else if("insideOut"===h){const t=[...o].map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}),e=[],n=[];let i=0,r=0;for(const o of t)r>i?(e.push(o),i+=d.get(o)??0):(n.push(o),r+=d.get(o)??0);p=[...n.reverse(),...e]}else p="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:f(t,e)}):"desc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}):o.map(t=>t.key).sort(f);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),o=Au(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let n=1/0,i=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;n>t&&(n=t),t+r>i&&(i=t+r)}Number.isFinite(n)&&Number.isFinite(i)||(n=0,i=0);const s=i-n,l=r?0:s>0?s*e.extentPadding:1;y=[n-l,i+l]}else if("diverging"===e.baseline){const t=Array.from(c).sort((t,e)=>t-e),[o,n]=function(t,e,o){let n=0,i=0;for(const r of t){let t=0,s=0;for(const n of e){const e=o(n,r)||0;0>e?s+=e:t+=e}n>s&&(n=s),t>i&&(i=t)}return[n,i]}(t,p,(t,e)=>a.get(t)?.get(e)||0),i=n-o,s=r?0:i>0?i*e.extentPadding:1;y=[o-s,n+s]}else y=[0,l+(r?0:l>0?l*e.extentPadding:1)];return{yDomain:y,stackExtentCache:{key:s,yDomain:y}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:o.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});l=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!u&&o.size>0?l=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=vu(t,e,o,n,i);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,o,n,i);return[0,s?a:a+a*r]}(o,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,h):"waterfall"===e.chartType&&!u&&o.size>0?l=function(t,e,o,n){const[i,r]=function(t,e){let o=0,n=0,i=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(i+=t,o>i&&(o=i),i>n&&(n=i))}return[o,n]}(t,e),s=r-i,a=n?0:s>0?s*o:1;return[Math.min(0,i-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(o,this.getY,e.extentPadding,h):u||l[0]===1/0||(l=function(t,e,o){if(!o.length)return t;let[n,i]=t;for(const t of e)for(const e of o){const o=e.getTop(t),r=e.getBottom(t);Number.isFinite(o)&&(n>o&&(n=o),o>i&&(i=o)),Number.isFinite(r)&&(n>r&&(n=r),r>i&&(i=r))}return[n,i]}(l,r,this.resolvedRibbons),l=function(t,e){const o=t[1]-t[0],n=e.exactMode?0:o>0?o*e.extentPadding:1,i=[null!=e.userMin?t[0]:t[0]-n,null!=e.userMax?t[1]:t[1]+n];return"log"!==e.yScaleType||i[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(i[0]=e.dataYDomain[0]/(1+e.extentPadding)),i}(l,{exactMode:h,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:a}));l=function(t,e,o){if(!e||o)return t;const n=e[0],i=e[1];return null==n&&null==i?t:[null!=n?n:t[0],null!=i?i:t[1]]}(l,e.yExtent,!!u),({xDomain:c,yDomain:l}=function(t,e,o){let n=t,i=e;if(n[0]===1/0||n[1]===-1/0)if("time"===o){const t=Date.now();n=[t-864e5,t]}else n=[0,1];return i[0]!==1/0&&i[1]!==-1/0||(i=[0,1]),{xDomain:n,yDomain:i}}(c,l,e.xScaleType)),this.scales=function(t){const{config:e,layout:o,xDomain:n,yDomain:i}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(o.width,o.height)/2-1));if(r){const t="left"===e.arrowOfTime?[o.width-s,s]:[s,o.width-s];return{x:gu().domain(n).range(t),y:$u(e.yScaleType,i,[o.height-s,s])}}return{x:$u(e.xScaleType,n,[s,o.width-s]),y:$u(e.yScaleType,i,[o.height-s,s])}}({config:e,layout:t,xDomain:c,yDomain:l}),this._customLayoutFailedThisBuild=!1;const f=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.lastLayout=i):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=f,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:t.width,height:t.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(t){const e=t.width/this.lastLayout.width,o=t.height/this.lastLayout.height;for(const t of this.scene)switch(t.type){case"line":for(const n of t.path)n[0]*=e,n[1]*=o;break;case"area":for(const n of t.topPath)n[0]*=e,n[1]*=o;for(const n of t.bottomPath)n[0]*=e,n[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*o,width:t.clipRect.width*e,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(t=>({...t,y:t.y*o,height:t.height*o})));break;case"point":case"glyph":t.x*=e,t.y*=o;break;case"rect":case"heatcell":t.x*=e,t.y*=o,t.w*=e,t.h*=o;break;case"candlestick":t.x*=e,t.openY*=o,t.closeY*=o,t.highY*=o,t.lowY*=o}const n=this.scales.x.domain(),i=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=$u,c=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),l=s[1]>s[0];this.scales={x:a(this.config.xScaleType,n,r[0]>r[1]?[t.width-c,c]:[c,t.width-c]),y:a(this.config.yScaleType,i,l?[c,t.height-c]:[t.height-c,c])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:o,scales:n}=this;if(!n)return[];if(o.customLayout){const i={data:e,scales:n,dimensions:{width:t.width,height:t.height,margin:o.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:o.themeCategorical??V},resolveColor:(t,e)=>{const n=this.resolveGroupColor(t);if(n)return n;const i=this.resolveLineStyle(t,e);return i.stroke?i.stroke:"string"==typeof i.fill?i.fill:o.themeSemantic?.primary??"#4e79a7"},config:o.layoutConfig??{},selection:o.layoutSelection??null},r=fu({family:"xy",logLabel:"customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:o.onLayoutError,run:()=>o.customLayout(i)});if("failure"===r.kind)return this.lastCustomLayoutFailure=r.diagnostic,this._customLayoutFailedThisBuild=!0,r.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);const s=r.result;this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null;const a=s.nodes??[];if(this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of a)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(a,o.layoutSelection??null)}return uu({label:"customLayout",nodes:a,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),a}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const i={scales:n,config:o,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(t,e)=>this.resolveLineStyle(t,e),resolveAreaStyle:(t,e)=>this.resolveAreaStyle(t,e),resolveBoundsStyle:(t,e)=>this.resolveBoundsStyle(t,e),resolveColorMap:t=>this.resolveColorMap(t),resolveGroupColor:t=>this.resolveGroupColor(t),groupData:t=>this.groupData(t),barCategoryCache:this._barCategoryCache},r=(s=o.chartType,su[s]?.buildScene);var s;if(!r)return function(t){(function(t){return su[t]})(t)||cu&&(lu.has(t)||(lu.add(t),console.warn(`[semiotic] StreamXYFrame: no XY plugin registered for "${t}" during SSR. Import a chart HOC, or call registerBuiltInXYPlugins() from "semiotic/xy" or "semiotic/realtime/core" before render.`)))}(o.chartType),[];const a=(c=r(i,e,t),Array.isArray(c)?{nodes:c,binBoundaries:[]}:{nodes:c.nodes,binBoundaries:c.binBoundaries});var c;return"bar"===o.chartType&&(this._barCategoryCache=i.barCategoryCache??null,this._binBoundaries=a.binBoundaries),a.nodes}resolveBoundsStyle(t,e){return function(t,e,o,n){const i=t.boundsStyle;if("function"==typeof i)return i(o||{},e);if(i&&"object"==typeof i)return i;const r=n(e,o);return{fill:r.stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none",cursor:r.cursor}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Jl(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=tu(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=tu(o)){const i=o.length;if(i>1)for(const o of e){if("line"===o.type){const e=Array.isArray(o.datum)?o.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let o=0;e.length>o;o++){const a=n.get(e[o]);null!=a?(r[o]=Jl(t,a,i),1>r[o]&&(s=!0)):r[o]=1}s&&(o._decayOpacities=r);continue}if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[],r=o.topPath?o.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let o=0;e.length>o;o++){const r=n.get(e[o]);null!=r?(s[o]=Jl(t,r,i),1>s[o]&&(a=!0)):s[o]=1}a&&(o._decayOpacities=s)}else{let s=1;for(const o of e){const e=n.get(o);if(null!=e){const o=Jl(t,e,i);s>o&&(s=o)}}if(1>s){const t=Array(r);t.fill(s),o._decayOpacities=t}}continue}const e=n.get(o.datum);if(null==e)continue;const r=Jl(t,e,i);"candlestick"===o.type?o._decayOpacity=r:o.style={...o.style,opacity:(o.style?.opacity??1)*r}}}(this.config.decay,t,e,this.getDatumIndexMap(e))}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&nu(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory}}snapshotPositions(){!function(t,e,o,n){o.clear(),n.clear();for(let i=0;e.length>i;i++){const r=e[i],s=iu(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:ru(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:ru(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:ru(r.style)}):"candlestick"===r.type?o.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:ru(r.style)}):"line"===r.type?n.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&n.set(s,{topPath:r.topPath.map(t=>[t[0],t[1]]),bottomPath:r.bottomPath.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();const t=this.scales?.y(0)??0;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=iu(this.transitionContext,o,e);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:0,opacity:0}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:t,w:o.w,h:0,opacity:o.style.opacity??1}):"heatcell"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:0}):"line"===o.type?(o._introClipFraction=0,this.prevPathMap.set(n,{path:o.path.map(t=>[t[0],t[1]]),opacity:o.style.opacity})):"area"===o.type&&(o._introClipFraction=0,this.prevPathMap.set(n,{topPath:o.topPath.map(t=>[t[0],t[1]]),bottomPath:o.bottomPath.map(t=>[t[0],t[1]]),opacity:o.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,o,n,i,r=Ql()){if(0===n.size&&0===i.size)return o;const s=e.duration??300;if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}let a=!1;const c=new Set,l=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=iu(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(l.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=n.get(s);if("point"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=ru(r.style),u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=ru(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=ru(r.style),u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=ru(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=ru(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=ru(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){c.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=ru(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=ru(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){c.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=ru(r.style),(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=ru(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!l.has(t))if(t.startsWith("l:")&&e.path){const n={type:"line",path:e.path.map(t=>[t[0],t[1]]),group:t.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(n),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const n={type:"area",topPath:e.topPath.map(t=>[t[0],t[1]]),bottomPath:e.bottomPath.map(t=>[t[0],t[1]]),group:t.slice(2),style:{fill:"#999",opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(n),a=!0}for(const[t,e]of n)if(!c.has(t)){if(t.startsWith("p:"))o.exitNodes.push({type:"point",x:e.x,y:e.y,r:e.r??3,style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("g:")&&e.glyph)o.exitNodes.push({type:"glyph",x:e.x,y:e.y,size:e.r??12,glyph:e.glyph,color:"#999",accent:"#999",style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))o.exitNodes.push({type:"rect",x:e.x,y:e.y,w:e.w??0,h:e.h??0,style:{opacity:e.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("h:"))o.exitNodes.push({type:"heatcell",x:e.x,y:e.y,w:e.w??0,h:e.h??0,fill:"#999",datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t});else if(t.startsWith("c:")){const n=e.openY??e.y;o.exitNodes.push({type:"candlestick",x:e.x,openY:n,closeY:e.closeY??n,highY:e.highY??n,lowY:e.lowY??n,bodyWidth:e.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t})}a=!0}return o.exitNodes.length>0&&(o.scene=[...o.scene,...o.exitNodes]),a&&(o.activeTransition={startTime:r,duration:s}),o}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(t){if(!this.activeTransition||!this.config.transition)return!1;const e={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},o=function(t,e,o,n){if(!o.activeTransition)return!1;const i=Kl(t,o.activeTransition),r=Ul(i,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of o.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Zl(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Zl(o.x,t._targetX,r),t.y=Zl(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Zl(o.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Zl(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Zl(o.x,t._targetX,r),t.y=Zl(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Zl(o.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Zl(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Zl(o.x,t._targetX,r),t.y=Zl(o.y,t._targetY,r),void 0!==o.w&&(t.w=Zl(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Zl(o.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Zl(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Zl(o.x,t._targetX,r),t.y=Zl(o.y,t._targetY,r),void 0!==o.w&&(t.w=Zl(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Zl(o.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Zl(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Zl(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Zl(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Zl(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Zl(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Zl(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Zl(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,o=t._targetPath;if(e&&o&&e.length===t.path.length)for(let n=0;t.path.length>n;n++)t.path[n][0]=Zl(e[n][0],o[n][0],r),t.path[n][1]=Zl(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Zl(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,o=t._prevBottomPath,n=t._targetTopPath,i=t._targetBottomPath;if(e&&n&&e.length===t.topPath.length)for(let o=0;t.topPath.length>o;o++)t.topPath[o][0]=Zl(e[o][0],n[o][0],r),t.topPath[o][1]=Zl(e[o][1],n[o][1],r);if(o&&i&&o.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=Zl(o[e][0],i[e][0],r),t.bottomPath[e][1]=Zl(o[e][1],i[e][1],r)}}if(i>=1){for(const t of o.scene){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style="line"===t.type||"area"===t.type?{...t.style,opacity:0===e?0:e}:{...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("glyph"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("heatcell"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("candlestick"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0}else if("line"===t.type){const e=t._targetPath;if(e)for(let o=0;t.path.length>o;o++)t.path[o]=e[o];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,o=t._targetBottomPath;if(e)for(let o=0;t.topPath.length>o;o++)t.topPath[o]=e[o];if(o)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=o[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}return o.activeTransition=null,!1}return!0}(t,this.config.transition,e,this.prevPositionMap);return this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition,o}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("glyph"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("rect"===e.type||"heatcell"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0);else if("candlestick"===e.type)void 0!==e._targetX&&(e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0);else if("line"===e.type||"area"===e.type){if(e._introClipFraction=void 0,"line"===e.type&&e._targetPath){for(let t=0;e.path.length>t;t++)e.path[t]=e._targetPath[t];e._prevPath=void 0,e._targetPath=void 0}if("area"===e.type){if(e._targetTopPath)for(let t=0;e.topPath.length>t;t++)e.topPath[t]=e._targetTopPath[t];if(e._targetBottomPath)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=e._targetBottomPath[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(t){const{result:e,cache:o}=function(t,e,o,n){if(n&&n.version===o&&n.group===e&&n.data===t)return{result:n.result,cache:n};let i;if(e){const o=new Map;for(const n of t){const t=e(n);o.has(t)||o.set(t,[]),o.get(t).push(n)}i=Array.from(o.entries()).map(([t,e])=>({key:t,data:e}))}else i=[{key:"_default",data:t}];return{result:i,cache:{version:o,group:e,data:t,result:i}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=o,e}resolveColorMap(t){const{map:e,cache:o}=function(t,e,o,n,i){if(i&&i.version===n)return{map:i.map,cache:i};const r=new Set;if(e)for(const o of t){const t=e(o);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(i&&i.key===a){const t={...i,version:n};return{map:t.map,cache:t}}const c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||V,l=new Map;for(let t=0;s.length>t;t++)l.set(s[t],c[t%c.length]);return{map:l,cache:{key:a,map:l,version:n}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=o,e}resolveLineStyle(t,e){return function(t,e,o,n){const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.stroke&&e){const o=n(e);if(o)return{...t,stroke:o}}return t}const r=t.themeSemantic?.primary;return i&&"object"==typeof i?{stroke:i.stroke||r||"#007bff",strokeWidth:i.strokeWidth??2,strokeDasharray:i.strokeDasharray,fill:i.fill,fillOpacity:i.fillOpacity,opacity:i.opacity,cursor:i.cursor}:{stroke:n(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,o,n){if(t.areaStyle){const i=t.areaStyle(o||{});if(i&&!i.fill&&e){const t=n(e);if(t)return{...i,fill:t,stroke:i.stroke||t}}return i}const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.fill&&e){const o=n(e);if(o)return{...t,fill:o,stroke:t.stroke||o}}return t}const r=t.themeSemantic?.primary;if(i&&"object"==typeof i)return{fill:i.fill||i.stroke||r||"#4e79a7",fillOpacity:i.fillOpacity??.7,stroke:i.stroke||r||"#4e79a7",strokeWidth:i.strokeWidth??2,cursor:i.cursor};const s=n(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(e){const{color:o,groupColorCounter:n}=function(t){const{group:e,colorMapCache:o,groupColorMap:n,groupColorMapCap:i,config:r}=t;let{groupColorCounter:s}=t;if(o){const t=o.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=n.get(e);if(a)return{color:a,groupColorCounter:s};const c=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||V;if(0===c.length)return{color:null,groupColorCounter:s};const l=c[s%c.length];if(s++,n.set(e,l),n.size>i){const t=n.keys().next().value;void 0!==t&&n.delete(t)}return{color:l,groupColorCounter:s}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:t.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=n,o}getBufferArray(){return!this._bufferDirty&&this._bufferArrayCache||(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(t){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Hl(t),o=this.getPointId,n=t=>e.has(o(t));Cu(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const o=Hl(t),n=this.getPointId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.buffer.forEach((t,e)=>{i.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t||"themeCategorical"in t||"colorAccessor"in t)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in t||"colorScheme"in t)&&(this._barCategoryCache=null),("normalize"in t||"extentPadding"in t||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t||"boundsAccessor"in t||"band"in t||"y0Accessor"in t||"openAccessor"in t||"highAccessor"in t||"lowAccessor"in t||"closeAccessor"in t||"groupAccessor"in t||"categoryAccessor"in t||"chartType"in t||"runtimeMode"in t)&&(this._stackExtentCache=null);let n=!1,i=!1;Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();const r="chartType"in t&&t.chartType!==e.chartType||"runtimeMode"in t&&t.runtimeMode!==e.runtimeMode;if(r||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t){const t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,o=t&&this.config.valueAccessor||this.config.yAccessor,s=t&&e.valueAccessor||e.yAccessor,a=r||!El(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),c=r||!El(o,s);(a||c)&&(t?(this.getX=Bl(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=Bl(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=Bl(this.config.xAccessor,"x"),this.getY=Bl(this.config.yAccessor,"y")),c&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=yu(this.config)),n=!0,i=!0)}if("groupAccessor"in t&&!El(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?jl(this.config.groupAccessor):void 0,n=!0),"categoryAccessor"in t&&!El(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?jl(this.config.categoryAccessor):void 0,n=!0),"sizeAccessor"in t&&!El(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?Bl(this.config.sizeAccessor,"size"):void 0,n=!0),"symbolAccessor"in t&&!El(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?jl(this.config.symbolAccessor):void 0,n=!0),"colorAccessor"in t&&!El(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?jl(this.config.colorAccessor):void 0,n=!0),"y0Accessor"in t&&!El(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?Bl(this.config.y0Accessor,"y0"):void 0,n=!0,i=!0),("boundsAccessor"in t&&!El(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=yu(this.config),n=!0,i=!0),"pointIdAccessor"in t&&!El(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?jl(this.config.pointIdAccessor):void 0,n=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!El(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!El(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!El(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!El(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?Bl(this.config.openAccessor,"open"):void 0,this.getHigh=Bl(this.config.highAccessor,"high"),this.getLow=Bl(this.config.lowAccessor,"low"),this.getClose=e?Bl(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,n=!0,i=!0}if("accessorRevision"in t&&t.accessorRevision!==e.accessorRevision&&(n=!0,i=!0),!n){const o=Object.keys(t).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const i of o)if(t[i]!==e[i]){n=!0;break}}n&&(i&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};nd.GROUP_COLOR_MAP_CAP=1e3;var id=nd;function rd(t,e,o,n){return"function"==typeof e.style?e.style(n||{},o):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(o,n)}function sd(t,e,o,n){if(!t.scales)return null;const i=[],r=[];for(const o of e){const e=t.getX(o);if(!Number.isFinite(e))continue;const s=n.getTop(o),a=n.getBottom(o);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const c=t.scales.x(e),l=t.scales.y(s),u=t.scales.y(a);Number.isFinite(c)&&Number.isFinite(l)&&Number.isFinite(u)&&(i.push([c,l]),r.push([c,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:rd(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function ad(t){const e=[],o=[];if(!t)return{perSeries:e,aggregate:o};for(const n of t)n.perSeries?e.push(n):o.push(n);return{perSeries:e,aggregate:o}}function cd(t,e,o){const n=[];for(const i of o){const o=sd(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function ld(t,e,o,n){const i=[];for(const r of n){const n=sd(t,e,o,r);n&&i.push(n)}return i}function ud(t,e,o,n){if(!t.config.pointStyle)return;const i=n??t.getY;for(const n of e){const e=t.resolveGroupColor(n.key);for(const r of n.data){let n=t.config.pointStyle(r);!n.fill&&e&&(n={...n,fill:e});const s=n.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,c=Su(r,t.scales,t.getX,i,s,n,a);c&&o.push(c)}}}function dd(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function hd(t){return!(!t._pulseIntensity||0>=t._pulseIntensity)}function fd(t,e,o=.3){hd(e)&&(t.globalAlpha=e._pulseIntensity*o,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.fillRect(e.x,e.y,e.w,e.h))}function pd(t,e,o,n=.35){hd(e)&&(t.globalAlpha=e._pulseIntensity*n,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",o?t.fill(o):t.fill())}Wu(id);import{area as yd,line as gd}from"d3-shape";function md(t,e,o){let n=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(n=o.color):t>o.value&&(n=o.color);return n}function xd(t,e,o,n){if(2>t.length||e.length!==t.length||0===o.length)return[];const i=[],r=(t,e,o)=>{const n=i[i.length-1];n?.color===t?n.path.push(o):i.push({color:t,path:[e,o]})};for(let i=1;t.length>i;i++){const[s,a]=t[i-1],[c,l]=t[i],u=e[i-1],d=e[i]-u,h=[0,...0===d?[]:o.map(({value:t})=>(t-u)/d).filter(t=>t>0&&1>t&&Number.isFinite(t)).sort((t,e)=>t-e).filter((t,e,o)=>0===e||t!==o[e-1]),1];for(let t=1;h.length>t;t++){const e=h[t-1],i=h[t];r(md(u+d*((e+i)/2),o,n),[s+(c-s)*e,a+(l-a)*e],[s+(c-s)*i,a+(l-a)*i])}}return i}function bd(t,e){const o=Ac(e.curve);if(!o||2>e.topPath.length||2>e.bottomPath.length){t.beginPath(),t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let o=1;e.topPath.length>o;o++)t.lineTo(e.topPath[o][0],e.topPath[o][1]);for(let o=e.bottomPath.length-1;o>=0;o--)t.lineTo(e.bottomPath[o][0],e.bottomPath[o][1]);t.closePath()}else{const n=yd().x(t=>t[0]).y0((t,o)=>e.bottomPath[o][1]).y1(t=>t[1]).curve(o).context(t);t.beginPath(),n(e.topPath)}}function vd(t,e){const o=Ac(e.curve);if(t.beginPath(),o)gd().x(t=>t[0]).y(t=>t[1]).curve(o).context(t)(e.topPath);else{t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let o=1;e.topPath.length>o;o++)t.lineTo(e.topPath[o][0],e.topPath[o][1])}}var wd=(t,e,o,n)=>{const i=e.filter(t=>"area"===t.type);for(const e of i){if(2>e.topPath.length)continue;let o=!1;e.clipRect&&(t.save(),t.beginPath(),t.rect(e.clipRect.x,e.clipRect.y,e.clipRect.width,e.clipRect.height),t.clip(),o=!0);const i=e._introClipFraction;void 0!==i&&1>i&&(t.save(),t.beginPath(),t.rect(0,0,n.width*i,n.height),t.clip());const r=Sc(t,e.style.fill,"#4e79a7"),s=e._decayOpacities,a=!(!e.colorThresholds?.length||!e.rawValues||e.rawValues.length!==e.topPath.length),c=!!e.strokeColorBands?.length;if(s&&s.length===e.topPath.length&&!a&&!c){const o=e.style.fillOpacity??.7;t.fillStyle=r;for(let n=0;e.topPath.length-1>n;n++)t.globalAlpha=.5*(s[n]+s[n+1])*o,t.beginPath(),t.moveTo(e.topPath[n][0],e.topPath[n][1]),t.lineTo(e.topPath[n+1][0],e.topPath[n+1][1]),t.lineTo(e.bottomPath[n+1][0],e.bottomPath[n+1][1]),t.lineTo(e.bottomPath[n][0],e.bottomPath[n][1]),t.closePath(),t.fill();const n=e.style.strokeWidth??2;if(e.style.stroke&&"none"!==e.style.stroke&&n>0){t.strokeStyle=hi(t,e.style.stroke)||e.style.stroke,t.lineWidth=n,t.setLineDash([]);for(let o=0;e.topPath.length-1>o;o++)t.globalAlpha=.5*(s[o]+s[o+1]),t.beginPath(),t.moveTo(e.topPath[o][0],e.topPath[o][1]),t.lineTo(e.topPath[o+1][0],e.topPath[o+1][1]),t.stroke()}t.globalAlpha=1;continue}const l=e.style.opacity??1;if(bd(t,e),e.fillGradient&&e.fillGradient.stops.length>=2&&e.fillGradient){let o=1/0;for(const t of e.topPath)o>t[1]&&(o=t[1]);let n=-1/0;for(const t of e.bottomPath)t[1]>n&&(n=t[1]);const i=_c(t,e.fillGradient,"string"==typeof r?r:"#4e79a7",0,o,0,n);t.fillStyle=i||r,t.globalAlpha=l}else t.globalAlpha=(e.style.fillOpacity??.7)*l,t.fillStyle=r;t.fill(),e._pulseIntensity&&e._pulseIntensity>0&&(bd(t,e),pd(t,e));const u=e.style.strokeWidth??2;if(e.style.stroke&&"none"!==e.style.stroke&&u>0){t.globalAlpha=l;const o=hi(t,e.style.stroke)||e.style.stroke,n=a||c||!e.strokeGradient||2>e.topPath.length?null:_c(t,e.strokeGradient,o,e.topPath[0][0],0,e.topPath[e.topPath.length-1][0],0);if(t.lineWidth=u,t.setLineDash([]),c){let n=1/0,i=-1/0;for(const[t]of e.topPath)n=Math.min(n,t),i=Math.max(i,t);const r=t.lineWidth;for(const s of e.strokeColorBands){t.save(),t.beginPath(),t.rect(n-r,s.y,i-n+2*r,s.height),t.clip();const a=s.color??o;t.strokeStyle=hi(t,a)||a,t.globalAlpha=l*(s.opacity??1),vd(t,e),t.stroke(),t.restore()}}else if(a){const n=xd(e.topPath,e.rawValues,e.colorThresholds,o);for(const e of n){t.beginPath(),t.strokeStyle=hi(t,e.color)||e.color,t.moveTo(e.path[0][0],e.path[0][1]);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1]);t.stroke()}}else t.strokeStyle=n||o,vd(t,e),t.stroke()}void 0!==i&&1>i&&t.restore(),o&&t.restore(),t.globalAlpha=1}};import{line as kd}from"d3-shape";function Ad(t,e,o,n,i,r){if(2>e.length)return;const s=[0];for(let t=1;e.length>t;t++){const o=e[t][0]-e[t-1][0],n=e[t][1]-e[t-1][1];s.push(s[t-1]+Math.sqrt(o*o+n*n))}const a=s[s.length-1];if(0===a)return;const c=Math.min(.2*a,40);t.strokeStyle=o,t.lineWidth=n,t.lineCap=r;for(let o=0;e.length-1>o;o++){const n=(s[o]+s[o+1])/2;let r=i;c>n&&(r*=n/c),c>a-n&&(r*=(a-n)/c),t.globalAlpha=Math.max(0,r),t.beginPath(),t.moveTo(e[o][0],e[o][1]),t.lineTo(e[o+1][0],e[o+1][1]),t.stroke()}}var Sd=(t,e,o,n)=>{const i=e.filter(t=>"line"===t.type);for(const e of i){if(2>e.path.length)continue;const o=e._introClipFraction;void 0!==o&&1>o&&(t.save(),t.beginPath(),t.rect(0,0,n.width*o,n.height),t.clip());const i=e.style.stroke||"#007bff",r=hi(t,i)||i,s=e.style.strokeWidth??2,a=e.colorThresholds,c=e.rawValues;if(t.setLineDash(e.style.strokeDasharray?e.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=e.style.opacity&&(t.globalAlpha=e.style.opacity),s>0&&(t.lineWidth=s),t.lineCap=e.style.strokeLinecap||"butt",e.style._edgeFade&&s>0){Ad(t,e.path,r,s,e.style.opacity??1,e.style.strokeLinecap||"butt"),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt";continue}const l=Ac(e.curve),u=a&&a.length>0&&c&&c.length===e.path.length,d=e._decayOpacities;if(s>0&&d&&d.length===e.path.length&&!u){t.strokeStyle=r;const o=e.style.opacity??1;for(let n=0;e.path.length-1>n;n++)t.globalAlpha=.5*(d[n]+d[n+1])*o,t.beginPath(),t.moveTo(e.path[n][0],e.path[n][1]),t.lineTo(e.path[n+1][0],e.path[n+1][1]),t.stroke()}else if(s>0&&!u){t.beginPath();const o=e.strokeGradient&&e.path.length>=2?_c(t,e.strokeGradient,r,e.path[0][0],0,e.path[e.path.length-1][0],0):null;if(t.strokeStyle=o||r,l)kd().x(t=>t[0]).y(t=>t[1]).curve(l).context(t)(e.path);else{const[o,n]=e.path[0];t.moveTo(o,n);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1])}t.stroke()}else if(s>0){const o=xd(e.path,c,a,r);for(const e of o){t.beginPath(),t.strokeStyle=hi(t,e.color)||e.color,t.moveTo(e.path[0][0],e.path[0][1]);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1]);t.stroke()}}if(e.style.fill&&e.style.fillOpacity&&e.style.fillOpacity>0){if(t.beginPath(),t.globalAlpha=e.style.fillOpacity,t.fillStyle=Sc(t,e.style.fill,e.style.fill),l&&!u)kd().x(t=>t[0]).y(t=>t[1]).curve(l).context(t)(e.path);else{const[o,n]=e.path[0];t.moveTo(o,n);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1])}const o=e.path[0][0];t.lineTo(e.path[e.path.length-1][0],n.height),t.lineTo(o,n.height),t.closePath(),t.fill()}void 0!==o&&1>o&&t.restore(),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt"}},Md=(t,e,o,n)=>{const i=e.filter(t=>"point"===t.type);if(0!==i.length){t.save();try{const e=t.globalAlpha;let o=[],n="";const r=o=>{t.beginPath(),t.arc(o.x,o.y,o.r,0,2*Math.PI),t.globalAlpha=e*(o.style.opacity??o.style.fillOpacity??1),t.fillStyle=Sc(t,o.style.fill,"#4e79a7"),t.fill();const n=o.style.strokeWidth??1;o.style.stroke&&"none"!==o.style.stroke&&n>0&&(t.strokeStyle=Sc(t,o.style.stroke,o.style.stroke),t.lineWidth=n,t.stroke()),function(t,e,o=.6){if(!hd(e))return;const n=e.r+(e._pulseGlowRadius??4)*e._pulseIntensity,i=e.cx??e.x??0,r=e.cy??e.y??0;t.beginPath(),t.arc(i,r,n,0,2*Math.PI),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=2*e._pulseIntensity,t.globalAlpha=e._pulseIntensity*o,t.stroke()}(t,o)},s=()=>{if(0===o.length)return;if(1===o.length)return r(o[0]),o=[],void(n="");const i=o[0];t.globalAlpha=e*(i.style.opacity??i.style.fillOpacity??1),t.beginPath();for(const e of o)t.moveTo(e.x+e.r,e.y),t.arc(e.x,e.y,e.r,0,2*Math.PI);t.fillStyle=Sc(t,i.style.fill,"#4e79a7"),t.fill();const s=i.style.strokeWidth??1;i.style.stroke&&"none"!==i.style.stroke&&s>0&&(t.strokeStyle=Sc(t,i.style.stroke,i.style.stroke),t.lineWidth=s,t.stroke()),o=[],n=""};for(const t of i){const e=t.style.opacity??t.style.fillOpacity??1,i=t.style.fill;if(hd(t)||null!=i&&"string"!=typeof i||1>e){s(),r(t);continue}const a=t.style.strokeWidth??1,c=`${i??"#4e79a7"}\0${t.style.stroke&&"none"!==t.style.stroke&&a>0?t.style.stroke+"":""}\0${a}\0${t.r}\0${e}`;o.length>0&&c!==n&&s(),n=c,o.push(t),2048>o.length||s()}s()}finally{t.restore()}}},_d={chartType:"line",buildScene:(t,e)=>function(t,e){const o=t.groupData(e),n=[],i=t.config.annotations?.filter(dd).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=ad(t.ribbons);if(r.length>0&&n.push(...cd(t,e,r)),i.length>0)for(const e of o)n.push(...ld(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=wu(e.data,t.scales,t.getX,t.getY,o,e.key);i&&i.length>0&&(r.colorThresholds=i),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),n.push(r)}return ud(t,o,n),n}(t,e),canvasRenderers:[wd,Sd,Md]};function Pd(t){return dt(t)}var Ld={chartType:"area",buildScene:(t,e)=>function(t,e){const o=t.groupData(e),n=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=ad(t.ribbons);if(r.length>0&&n.push(...cd(t,e,r)),i.length>0)for(const e of o)n.push(...ld(t,e.data,e.key,i))}const i=t.scales.y.domain(),r=i[0],s=t.config.semanticLineStops?.filter(t=>Number.isFinite(t.offset)).map(t=>({value:i[0]+Math.max(0,Math.min(1,t.offset))*(i[1]-i[0]),color:t.color,opacity:t.opacity,thresholdType:"greater"})).sort((t,e)=>t.value-e.value),a=s&&s.length>0?(()=>{const e=s.reduce((t,e)=>(t.at(-1)?.value===e.value?t[t.length-1]=e:t.push(e),t),[]),o=[{from:i[0],to:e[0].value,color:e[0].color,opacity:e[0].opacity}];for(let t=0;e.length>t;t++)o.push({from:e[t].value,to:e[t+1]?.value??i[1],color:e[t].color,opacity:e[t].opacity});return o.map(({from:e,to:o,color:n,opacity:i})=>{const r=t.scales.y(e),s=t.scales.y(o);return{y:Math.min(r,s),height:Math.abs(s-r),color:n,...null!=i&&{opacity:i}}}).filter(t=>t.height>0)})():void 0,c=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o){const o=t.resolveAreaStyle(e.key,e.data[0]),i=ku(e.data,t.scales,t.getX,t.getY,r,o,e.key,c),l=Pd(t.config.gradientFill);l&&(i.fillGradient=l),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),s&&s.length>0&&(i.colorThresholds=s,i.strokeColorBands=a),n.push(i)}return ud(t,o,n),n}(t,e),canvasRenderers:[wd,Md]},$d={chartType:"stackedarea",buildScene:(t,e)=>function(t,e){const o=t.groupData(e),n=t.config.stackOrder??"key",i=()=>o.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===n);else if("key"===n)i();else if("asc"===n||"desc"===n||"insideOut"===n){const e=new Map;for(const n of o){let o=0;for(const e of n.data){const n=t.getX(e),i=t.getY(e);Number.isFinite(n)&&Number.isFinite(i)&&(o+=i)}e.set(n.key,o)}const i=(t,e)=>e>t?-1:t>e?1:0;if("asc"===n)o.sort((t,o)=>{const n=(e.get(t.key)??0)-(e.get(o.key)??0);return 0!==n?n:i(t.key,o.key)});else if("desc"===n)o.sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)});else{const t=[...o].sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)}),n=[],r=[];let s=0,a=0;for(const o of t)a>s?(n.push(o),s+=e.get(o.key)??0):(r.push(o),a+=e.get(o.key)??0);o.length=0,o.push(...r.reverse(),...n)}}else i();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:c}=function(t,e,o,n,i,r,s,a="zero"){const c=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&c.add(e)}const l=Array.from(c).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const i of e.data){const e=o(i),r=n(i);Number.isFinite(e)&&Number.isFinite(r)&&t.set(e,(t.get(e)||0)+r)}u.set(e.key,t)}let d;if(r){d=new Map;for(const e of l){let o=0;for(const n of t)o+=u.get(n.key)?.get(e)||0;d.set(e,o||1)}}const h=Au(l,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],y=new Map,g=new Map,m=new Map,x=new Map;for(const t of l)g.set(t,h.get(t)??0),m.set(t,0),x.set(t,0);for(const o of t){const t=u.get(o.key),n=new Map;let a=[],c=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:c,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),p.push(t)}a=[],c=[]};for(const o of l){const i=t.has(o);let s,l,u=i?t.get(o):0;if(r&&i&&(u/=d.get(o)),!i||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(o),l=s+u,m.set(o,l)):(s=x.get(o),l=s+u,x.set(o,l)):(s=g.get(o),l=s+u,g.set(o,l));const p=e.x(o);c.push([p,e.y(s)]),a.push([p,e.y(l)]),n.set(o,l)}h(),y.set(o.key,n)}return{nodes:p,stackedTops:y}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),l=a;if(t.config.pointStyle){const e=new WeakMap;for(const n of o){const o=c.get(n.key);if(o)for(const i of n.data){const n=t.getX(i),r=t.getY(i);null==n||Number.isNaN(n)||null==r||Number.isNaN(r)||!o.has(n)||e.set(i,o.get(n))}}const n=o=>e.get(o)??t.getY(o);ud(t,o,l,n)}return l}(t,e),canvasRenderers:[wd,Md]},Rd={chartType:"mixed",buildScene:(t,e)=>function(t,e){const o=t.groupData(e),n=[],i=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=ad(t.ribbons);if(r.length>0&&n.push(...cd(t,e,r)),i.length>0)for(const e of o)n.push(...ld(t,e.data,e.key,i))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o)if(i.has(e.key)){const o=t.resolveAreaStyle(e.key,e.data[0]),i=ku(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=Pd(t.config.gradientFill);a&&(i.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}else{const o=t.resolveLineStyle(e.key,e.data[0]),i=wu(e.data,t.scales,t.getX,t.getY,o,e.key);t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}return ud(t,o,n),n}(t,e),canvasRenderers:[wd,Sd,Md]};import{symbol as Td,symbolCircle as Id,symbolCross as Cd,symbolDiamond as Od,symbolSquare as Fd,symbolStar as Dd,symbolTriangle as zd,symbolWye as Nd}from"d3-shape";var Ed={circle:Id,square:Fd,triangle:zd,diamond:Od,star:Dd,cross:Cd,wye:Nd},Bd=new Set(["circle","square","triangle","diamond","star","cross","wye","chevron"]),Wd=["circle","triangle","diamond","star","square","chevron","cross","wye"];function jd(t,e,o){if(o)return o;const n=t??"circle";if("chevron"===n)return function(t){const e=1.5*Yd(t),o=.92*e;return`M0,${-e}L${o},${(.78*e).toFixed(3)}L0,${(.28*e).toFixed(3)}L${-o},${(.78*e).toFixed(3)}Z`}(e);const i=Object.prototype.hasOwnProperty.call(Ed,n)?Ed[n]:Id;return Td(i,Math.max(1,e))()??""}function Yd(t){return Math.sqrt(Math.max(1,t)/Math.PI)}function Xd(t,e){const o=new Map;let n=0;return i=>{const r=t(i)+"",s=e&&Object.prototype.hasOwnProperty.call(e,r)?e[r]:void 0;if(s&&Bd.has(s))return s;let a=o.get(r);return a||(a=Wd[n%Wd.length],n++,o.set(r,a)),a}}function qd(t,e){const o=[],n="bubble"===t.config.chartType?10:5,i=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const o=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(o.length>0){let t=1/0,e=-1/0;for(const n of o)t>n&&(t=n),n>e&&(e=n);r=o=>t===e?(i[0]+i[1])/2:i[0]+(o-t)/(e-t)*(i[1]-i[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",c=t.getSymbol,l=c?Xd(c,t.config.symbolMap):null;for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},c=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(c=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(i);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(i)+"":void 0;if(l){const n=l(i),r=Mu(i,t.scales,t.getX,t.getY,Math.PI*c*c,n,e,u);r&&o.push(r)}else{const n=Su(i,t.scales,t.getX,t.getY,c,e,u);n&&o.push(n)}}return o}var Gd=new Map;function Vd(t,e,o,n,i,r){if(0>=e.size)return;const s=function(t,e,o){try{if(o)return new Path2D(o);const n=`${t??"circle"}:${Math.round(e)}`;let i=Gd.get(n);return i||(i=new Path2D(jd(t,e)),Gd.size>256&&Gd.clear(),Gd.set(n,i)),i}catch{return null}}(e.symbolType,e.size,e.path);if(!s)return;t.save(),t.translate(o,n),e.rotation&&t.rotate(e.rotation);const a=(e.style.opacity??1)*(e._decayOpacity??1);e.style.fill&&(t.globalAlpha=i*a*(e.style.fillOpacity??1),t.fillStyle=Sc(t,e.style.fill,r),t.fill(s)),e.style.stroke&&"none"!==e.style.stroke&&(t.globalAlpha=i*a,t.strokeStyle=hi(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth??1,t.stroke(s)),t.restore()}var Hd=(t,e)=>{const o=t.globalAlpha;for(const n of e)"symbol"===n.type&&Vd(t,n,n.x,n.y,o,"#4e79a7");t.globalAlpha=o},Ud=[Md,Hd],Kd={chartType:"scatter",buildScene:(t,e)=>qd(t,e),canvasRenderers:Ud},Zd={chartType:"bubble",buildScene:(t,e)=>qd(t,e),canvasRenderers:Ud},Qd=new Map;function Jd(t,e,o){return e===o?128:Math.min(Math.floor(255*(t-e)/(o-e)+.5),255)}function th(t){const e=Object.prototype.hasOwnProperty.call(O,t)?t:"blues";let o=Qd.get(e);if(o)return o;o=Array(256);const n=F(e);for(let t=0;256>t;t++)o[t]=n(t/255);return Qd.set(e,o),o}function eh(t,e,o){const n=o.config.areaStyle?.(e);return n&&("string"==typeof n.fill&&(t.fill=n.fill),t.style=n),t}function oh(t,e,o){const n=Math.max(1,Math.floor(t.config.heatmapXBins??20)),i=Math.max(1,Math.floor(t.config.heatmapYBins??20)),r=t.config.heatmapAggregation??"count",s=Bl(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,c]=t.scales.x.domain(),[l,u]=t.scales.y.domain(),d=(c-a||1)/n,h=(u-l||1)/i,f=n*i;if(f>1e6)return[];const p=new Int32Array(f),y=new Float64Array(f),g=ee(t.config.areaStyle)?.[0]===t.config.areaStyle?new Map:void 0;for(let o=0;e.length>o;o++){const r=e[o],c=t.getX(r),u=t.getY(r);if(!isFinite(c)||!isFinite(u))continue;const f=Math.min(Math.floor((c-a)/d),n-1),m=Math.min(Math.floor((u-l)/h),i-1);if(0>f||0>m)continue;const x=m*n+f;p[x]++;const b=s(r);if(y[x]+=isFinite(b)?b:0,g){let t=g.get(x);t||(t=[],g.set(x,t)),t.push(r)}}let m=1/0,x=-1/0;for(let t=0;f>t;t++){if(0===p[t])continue;let e;switch(r){case"sum":e=y[t];break;case"mean":e=y[t]/p[t];break;default:e=p[t]}m>e&&(m=e),e>x&&(x=e)}if(!isFinite(m))return[];const b=t.config.heatmapColorScale,v=b?void 0:th("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),w=o.width/n,k=o.height/i,A=t.config.showValues,S=t.config.heatmapValueFormat,M=[];for(let e=0;i>e;e++){const o=e*n;for(let s=0;n>s;s++){const n=o+s;if(0===p[n])continue;let c;switch(r){case"sum":c=y[n];break;case"mean":c=y[n]/p[n];break;default:c=p[n]}const u=Jd(c,m,x),f=b?b(c):v[u],_=A?{value:c,showValues:!0,valueFormat:S}:{value:c},P=te({xi:s,yi:e,value:c,count:p[n],sum:y[n],xCenter:a+(s+.5)*d,yCenter:l+(e+.5)*h,agg:r},g?.get(n));M.push(eh(Pu(s*w,(i-1-e)*k,w,k,f,P,_),P,t))}}return M}function nh(t,e){const[o,n,i]=fc(t,e);return.299*o+.587*n+.114*i>128?"#000":"#fff"}function ih(t){return Number.isInteger(t)?t+"":100>Math.abs(t)?1>Math.abs(t)?t.toPrecision(3):t.toFixed(1):t.toFixed(0)}var rh=(t,e,o,n)=>{const i=e.filter(t=>"heatcell"===t.type);t.save();try{const e=hi(t,"var(--semiotic-font-family, sans-serif)")||"sans-serif";for(const o of i){const n=o.style;null!=n?.opacity&&(t.globalAlpha=n.opacity);const i=Mc(t,o.fill,"#4e79a7");t.fillStyle=i,t.fillRect(o.x,o.y,o.w,o.h);const r=Math.max(0,n?.strokeWidth??1);if(r>0&&(t.strokeStyle=hi(t,n?.stroke??"var(--semiotic-surface, #fff)"),t.lineWidth=r,t.strokeRect(o.x,o.y,o.w,o.h)),fd(t,o),t.globalAlpha=1,o.showValues&&null!=o.value){if(20>o.w||20>o.h)continue;const n=o.valueFormat?o.valueFormat(o.value):ih(o.value),r=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h))),s=o.x+o.w/2,a=o.y+o.h/2;t.fillStyle=nh(t,"string"==typeof i?i:"#4e79a7"),t.font=`${r}px ${e}`,t.textAlign="center",t.textBaseline="middle",t.fillText(n,s,a)}}}finally{t.restore()}},sh={chartType:"heatmap",buildScene:(t,e,o)=>function(t,e,o){if(t.config.heatmapAggregation)return oh(t,e,o);if(0===e.length)return[];const n=Bl(t.config.valueAccessor,"value"),i=Wl(t.config.xAccessor,"x"),r=Wl(t.config.yAccessor,"y"),s=new Map,a=new Map,c=Array(e.length),l=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],n=i(o),u=r(o);c[t]=n,l[t]=u,s.has(n)||s.set(n,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),f=Array.from(a.keys()),p=h.every(t=>"number"==typeof t&&!isNaN(t)),y=f.every(t=>"number"==typeof t&&!isNaN(t)),g=4096;if(p&&y&&u*d>g&&e.length>g){const n=new Set;for(let i=0;e.length>i;i++){const r=s.get(c[i]),d=a.get(l[i]);if(void 0!==r&&void 0!==d&&(n.add(d*u+r),n.size>g))return oh({...t,config:{...t.config,heatmapAggregation:t.config.valueAccessor?"mean":"count"}},e,o)}}if(p){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(y){f.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;f.length>t;t++)a.set(f[t],t)}const m=new Float64Array(e.length),x=new Float64Array(e.length),b=Array(e.length),v=new Map;let w=0;for(let t=0;e.length>t;t++){const o=e[t],i=s.get(c[t]),r=a.get(l[t]);if(void 0===i||void 0===r)continue;const d=n(o),h=r*u+i,f=v.get(h);let p;void 0!==f?p=f:(p=w++,v.set(h,p)),m[p]=h,x[p]=d,b[p]=o}let k=1/0,A=-1/0;for(let t=0;w>t;t++){const e=x[t];isFinite(e)&&(k>e&&(k=e),e>A&&(A=e))}if(!isFinite(k)||!isFinite(A))return[];const S=t.config.heatmapColorScale,M=S?void 0:th("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),_=o.width/u,P=o.height/d,L=t.config.showValues,$=t.config.heatmapValueFormat,R=[];for(let e=0;w>e;e++){const o=x[e];if(!isFinite(o))continue;const n=m[e],i=n%u,r=(n-i)/u,s=Jd(o,k,A),a=S?S(o):M[s],c=b[e];R.push(eh(Pu(i*_,(d-1-r)*P,_,P,a,c,L?{value:o,showValues:!0,valueFormat:$}:{value:o}),c,t))}return R}(t,e,o),canvasRenderers:[rh]};function ah(t){return(t.tl??0)>0||(t.tr??0)>0||(t.br??0)>0||(t.bl??0)>0}function ch(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const o=Math.min(t.w,t.h)/2,n=t=>Math.max(0,Math.min(t??0,o));return{tl:n(e.tl),tr:n(e.tr),br:n(e.br),bl:n(e.bl)}}function lh(t,e){const{x:o,y:n,w:i,h:r}=e,{tl:s,tr:a,br:c,bl:l}=ch(e);t.beginPath(),t.moveTo(o+s,n),t.lineTo(o+i-a,n),a>0&&t.arcTo(o+i,n,o+i,n+a,a),t.lineTo(o+i,n+r-c),c>0&&t.arcTo(o+i,n+r,o+i-c,n+r,c),t.lineTo(o+l,n+r),l>0&&t.arcTo(o,n+r,o,n+r-l,l),t.lineTo(o,n+s),s>0&&t.arcTo(o,n,o+s,n,s),t.closePath()}function uh(t,e){const o=Sc(t,e.style.fill,hi(t,"var(--semiotic-primary, #007bff)")),n=function(t){switch(t.roundedEdge){case"bottom":return{x0:t.x,y0:t.y+t.h,x1:t.x,y1:t.y};case"right":return{x0:t.x+t.w,y0:t.y,x1:t.x,y1:t.y};case"left":return{x0:t.x,y0:t.y,x1:t.x+t.w,y1:t.y};default:return{x0:t.x,y0:t.y,x1:t.x,y1:t.y+t.h}}}(e);return(e.fillGradient&&"string"==typeof o?_c(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null)||o}function dh(t,e){if(!e.style.stroke||"none"===e.style.stroke)return!1;const o=e.style.strokeWidth??1;return o>0&&(t.strokeStyle=hi(t,e.style.stroke)||e.style.stroke,t.lineWidth=o,!0)}var hh=(t,e,o,n)=>{const i=e.filter(t=>"rect"===t.type);for(const e of i){if(null!=e.style.opacity&&(t.globalAlpha=e.style.opacity),e.style.icon)fh(t,e);else if(e.cornerRadii&&ah(e.cornerRadii))t.fillStyle=uh(t,e),lh(t,e),t.fill(),dh(t,e)&&t.stroke();else if(e.roundedTop&&e.roundedTop>0){t.fillStyle=uh(t,e);const o=Math.min(e.roundedTop,e.w/2,e.h/2);t.beginPath();const{x:n,y:i,w:r,h:s}=e;switch(e.roundedEdge){case"right":t.moveTo(n,i),t.lineTo(n+r-o,i),t.arcTo(n+r,i,n+r,i+o,o),t.lineTo(n+r,i+s-o),t.arcTo(n+r,i+s,n+r-o,i+s,o),t.lineTo(n,i+s);break;case"left":t.moveTo(n+r,i),t.lineTo(n+o,i),t.arcTo(n,i,n,i+o,o),t.lineTo(n,i+s-o),t.arcTo(n,i+s,n+o,i+s,o),t.lineTo(n+r,i+s);break;case"bottom":t.moveTo(n,i),t.lineTo(n+r,i),t.lineTo(n+r,i+s-o),t.arcTo(n+r,i+s,n+r-o,i+s,o),t.lineTo(n+o,i+s),t.arcTo(n,i+s,n,i+s-o,o);break;default:t.moveTo(n,i+s),t.lineTo(n,i+o),t.arcTo(n,i,n+o,i,o),t.lineTo(n+r-o,i),t.arcTo(n+r,i,n+r,i+o,o),t.lineTo(n+r,i+s)}t.closePath(),t.fill(),dh(t,e)&&t.stroke()}else t.fillStyle=uh(t,e),t.fillRect(e.x,e.y,e.w,e.h),dh(t,e)&&t.strokeRect(e.x,e.y,e.w,e.h);fd(t,e),t.globalAlpha=1}};function fh(t,e){const o=e.style.icon,n=e.style.iconPadding||2,i=Math.min(e.w,e.h)-n;if(0>=i)return;const r=e.h>e.w;if(t.save(),t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip(),r){const r=i+n,s=e.x+(e.w-i)/2;for(let n=e.y+e.h-i;n>=e.y-i;n-=r)t.drawImage(o,s,n,i,i)}else{const r=i+n,s=e.y+(e.h-i)/2;for(let n=e.x;e.x+e.w>n;n+=r)t.drawImage(o,n,s,i,i)}t.restore()}var ph={chartType:"bar",buildScene:(t,e)=>function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=vu(e,t.getX,t.getY,t.config.binSize,t.getCategory,ee(t.config.areaStyle)?.[0]===t.config.areaStyle);if(0===o.size)return{nodes:[],binBoundaries:[]};let n=null;if(t.getCategory){const e=new Set;for(const t of o.values())for(const o of t.categories.keys())e.add(o);const i=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(i),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=i.filter(t=>e.has(t)),c=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===c?n=t.barCategoryCache.order:(n=[...a,...s],t.barCategoryCache={key:c,order:n})}const i=[],r=t.scales,[s,a]=r.x.domain(),c=t.config.barStyle,l=t.config.themeSemantic?.primary,u=c?.gap,d="number"!=typeof u||0>u?1:u,h={};c?.stroke&&(h.stroke=c.stroke),"number"==typeof c?.strokeWidth&&(h.strokeWidth=c.strokeWidth),"number"==typeof c?.opacity&&(h.opacity=c.opacity),c?.cursor&&(h.cursor=c.cursor);for(const e of o.values()){const o=Math.max(e.start,s),u=Math.min(e.end,a);if(o>=u)continue;const f=r.x(o),p=r.x(u),y=Math.abs(p-f),g=y>d+1?d:0,m=Math.min(f,p)+g/2,x=Math.max(y-g,1);if(x>0)if(n&&e.categories.size>0){let o=0;for(const s of n){const n=e.categories.get(s)||0;if(0===n)continue;const a=r.y(o),u=r.y(o+n),d=Math.min(a,u),f=Math.abs(a-u),p=(t.config.barColors?Z(t.config.barColors,s):void 0)??c?.fill??l??"#4e79a7",y=te({binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},e.categoryRows?.get(s)),g=t.config.areaStyle?.(y)??{};i.push(_u(m,d,x,f,{fill:p,...h,...g},y,s)),o+=n}}else{const o=r.y(0),n=r.y(e.total),s=Math.min(o,n),a=Math.abs(o-n),u=c?.fill||l||"#007bff",d=te({binStart:e.start,binEnd:e.end,total:e.total},e.rows),f=t.config.areaStyle?.(d)??{};i.push(_u(m,s,x,a,{fill:u,...h,...f},d))}}const f=new Set;for(const t of o.values())f.add(t.start),f.add(t.end);return{nodes:i,binBoundaries:Array.from(f).sort((t,e)=>t-e)}}(t,e),canvasRenderers:[hh]},yh={chartType:"swarm",buildScene:(t,e)=>function(t,e){const o=[],n=t.config.swarmStyle||{},i=n.radius??3,r=n.fill??t.config.themeSemantic?.primary??"#007bff",s=n.opacity??.7,a=n.stroke,c=n.strokeWidth,l=n.cursor;for(const n of e){const e=t.getX(n),u=t.getY(n);if(null==u||Number.isNaN(u))continue;const d=t.scales.x(e),h=t.scales.y(u);let f=r;if(t.getCategory){const e=t.getCategory(n)+"";f=(t.config.barColors?Z(t.config.barColors,e):void 0)??f}const{r:p,...y}=t.config.pointStyle?.(n)??{},g={type:"point",x:d,y:h,r:p??i,style:{fill:f,opacity:s,stroke:a,strokeWidth:c,cursor:l,...y},datum:n};t.getPointId&&(g.pointId=t.getPointId(n)+""),o.push(g)}return o}(t,e),canvasRenderers:[Md]},gh=(t,e,o,n)=>{hh(t,e);const i=e.filter(t=>"rect"===t.type);if(2>i.length)return;const r=i[0].datum,s=r?._connectorStroke;if(s){t.save(),t.strokeStyle=hi(t,s)||s,t.lineWidth=r?._connectorWidth??1,t.setLineDash([]);for(let e=0;i.length-1>e;e++){const n=i[e],r=i[e+1],s=n.datum,a=r.datum;if(null==s?.cumEnd||null==a?.baseline)continue;const c=o.y(s.cumEnd),l=n.x+n.w,u=r.x;t.beginPath(),t.moveTo(l,c),t.lineTo(u,c),t.stroke()}t.restore()}},mh={chartType:"waterfall",buildScene:(t,e,o)=>function(t,e,o){const n=[],i=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const o=t.getY(e),n=t.getX(e);return null!=o&&!Number.isNaN(o)&&null!=n&&isFinite(n)});if(0===s.length)return n;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",c=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",l=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let f=0;for(let e=0;s.length>e;e++){const p=s[e],y=t.getX(p),g=t.getY(p),m=f+g,x=i.x(y),b=e>0?i.x(t.getX(s[e-1])):void 0,v=s.length-1>e?i.x(t.getX(s[e+1])):void 0,w=null!=b?(b+x)/2:null!=v?x-(v-x)/2:x-o.width/20,k=null!=v?(x+v)/2:null!=b?x+(x-b)/2:x+o.width/20,A=Math.min(w,k)+l/2,S=Math.max(w,k)-l/2-A;if(0>=S){f=m;continue}const M=i.y(f),_=i.y(m),P=Math.min(M,_),L=Math.abs(M-_),$=0>g?c:a,R={...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},T={fill:$,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(R)};n.push(_u(A,P,S,L,T,R)),f=m}return n}(t,e,o),canvasRenderers:[gh]},xh=(t,e,o,n)=>{for(const o of e){if("candlestick"!==o.type)continue;const e=o;t.save();const i=(e._decayOpacity??1)*(e.style?.opacity??1);1!==i&&(t.globalAlpha=i);const r=hi(t,e.wickColor)||e.wickColor,s=60>n.height,a=s?Math.max(e.wickWidth,2):e.wickWidth,c=()=>{t.beginPath(),t.moveTo(e.x,e.highY),t.lineTo(e.x,e.lowY),t.strokeStyle=r,t.lineWidth=a,t.stroke()};if(s||c(),e.isRange){const o=e.dotRadius??Math.max(2,Math.min(e.bodyWidth/2,.12*n.height));t.fillStyle=r,t.beginPath(),t.arc(e.x,e.highY,o,0,2*Math.PI),t.fill(),t.beginPath(),t.arc(e.x,e.lowY,o,0,2*Math.PI),t.fill()}else if(e.bodyWidth>0){const o=Math.min(e.openY,e.closeY),n=Math.abs(e.openY-e.closeY),i=e.isUp?e.upColor:e.downColor,r=hi(t,i)||i;t.fillStyle=r,t.fillRect(e.x-e.bodyWidth/2,o,e.bodyWidth,Math.max(n,1)),t.strokeStyle=r,t.lineWidth=1,t.strokeRect(e.x-e.bodyWidth/2,o,e.bodyWidth,Math.max(n,1))}s&&c(),t.restore()}},bh={chartType:"candlestick",buildScene:(t,e,o)=>function(t,e,o){if(!t.getHigh||!t.getLow||!t.scales)return[];const n=t.config.candlestickRangeMode??!1;if(!(n||t.getOpen&&t.getClose))return[];const i=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=n?s:r.upColor||"#28a745",c=n?s:r.downColor||"#dc3545",l=n?s:r.wickColor||"#333",u=r.wickWidth||(n?2:1),d=e.map(e=>t.getX(e)).filter(t=>null!=t&&!Number.isNaN(t)).sort((t,e)=>t-e);let h=r.bodyWidth??0;if(null==r.bodyWidth)if(d.length>1){let e=1/0;for(let o=1;d.length>o;o++){const n=Math.abs(t.scales.x(d[o])-t.scales.x(d[o-1]));n>0&&e>n&&(e=n)}h=e!==1/0?Math.max(2,Math.min(.6*e,20)):6}else h=6;for(const s of e){const e=t.getX(s);if(null==e||Number.isNaN(e))continue;const d=t.getHigh(s),f=t.getLow(s);if(null==d||Number.isNaN(d)||null==f||Number.isNaN(f))continue;const p=n?d:t.getOpen(s),y=n?f:t.getClose(s);if(!n&&[p,y].some(t=>null==t||Number.isNaN(t)))continue;const g=y>=p,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(p),closeY:t.scales.y(y),highY:t.scales.y(d),lowY:t.scales.y(f),bodyWidth:h,upColor:a,downColor:c,wickColor:l,wickWidth:u,isUp:g,style:{cursor:r.cursor,...t.config.pointStyle?.(s)??{}},datum:s};n&&(m.isRange=!0,m.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),i.push(m)}return i}(t,e,o),canvasRenderers:[xh]},vh=[40,40],wh=[.5,.5];function kh(t,e){const[o,n]=t.viewBox??vh,[i,r]=t.anchor??wh,s=n>0?n:1,a=Math.max(0,e)/s,c=(o>0?o:s)*a,l=s*a;return{width:c,height:l,scale:a,offsetX:-i*c,offsetY:-r*l}}function Ah(t,e,o,n){if("none"!==t)return"color"===t||null==t?e??n:"accent"===t?o:t}var Sh=null;function Mh(t){if("undefined"==typeof Path2D)return null;Sh||(Sh=new Map);const e=Sh.get(t);if(e)return e;const o=new Path2D(t);return Sh.size>1024&&Sh.clear(),Sh.set(t,o),o}function _h(t,e,o=0,n="horizontal"){const[i,r]=t.viewBox??vh,s=Math.min(1,Math.max(0,o)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===n?{x:0,y:r*(1-a),width:i,height:r*(a-s)}:{x:i*s,y:0,width:i*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}function Ph(t,e){const o=kh(t,e);return{centerDx:o.offsetX+o.width/2,centerDy:o.offsetY+o.height/2,halfWidth:o.width/2,halfHeight:o.height/2,radius:Math.hypot(o.width,o.height)/2}}function Lh(t,e,o,n,i,r=t=>t){for(const s of e.parts){const e=Mh(s.d);if(!e)continue;const a=s.opacity??1,c=t.globalAlpha;1!==a&&(t.globalAlpha=c*a);const l=i?"none"===s.fill?void 0:i:Ah(s.fill,o,n);l&&(t.fillStyle=r(l),t.fill(e));const u=i?s.stroke&&"none"!==s.stroke?i:void 0:Ah(s.stroke??"none",o,n);u&&(t.strokeStyle=r(u),t.lineWidth=s.strokeWidth??1,t.lineCap=s.strokeLinecap??"butt",t.lineJoin=s.strokeLinejoin??"miter",t.stroke(e)),1!==a&&(t.globalAlpha=c)}}function $h(t,e,o,n,i){if(0>=e.size)return;const r=e.glyph;if(!r||!r.parts?.length)return;const s=kh(r,e.size);if(0>=s.scale)return;const a=(e.style.opacity??1)*(e._decayOpacity??1);if(0>=a)return;const c=e=>{const o=Sc(t,e,e);return"string"==typeof o?o:e},l=e.color??("string"==typeof e.style.fill?e.style.fill:void 0);t.save(),t.translate(o,n),e.rotation&&t.rotate(e.rotation),t.translate(s.offsetX,s.offsetY),t.scale(s.scale,s.scale),t.globalAlpha=i*a*(e.style.fillOpacity??1);const u=_h(r,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal");u&&e.ghostColor&&Lh(t,r,l,e.accent,e.ghostColor,c),u&&(t.beginPath(),t.rect(u.x,u.y,u.width,u.height),t.clip()),Lh(t,r,l,e.accent,void 0,c),t.restore()}var Rh={chartType:"custom",buildScene:()=>[],canvasRenderers:[wd,hh,rh,Sd,Md,Hd,(t,e)=>{const o=t.globalAlpha;for(const n of e)"glyph"===n.type&&$h(t,n,n.x,n.y,o);t.globalAlpha=o},xh,Md,gh]};function Th(){au(_d),au(Ld),au($d),au(Rd),au(Kd),au(Zd),au(sh),au(ph),au(yh),au(mh),au(bh),au(Rh)}function Ih(t){const e=t.parts.filter(t=>null!=t),o={};for(const t of e)for(const[e,n]of Object.entries(t.markCountByType))o[e]=(o[e]??0)+n;for(const[e,n]of Object.entries(t.additionalMarkCountByType??{}))n>0&&(o[e]=(o[e]??0)+n);const n=Object.values(o).reduce((t,e)=>t+e,0),i=0===n,r=Array.from(new Set([...e.flatMap(t=>t.warnings),...t.extraWarnings??[],...i?["EMPTY_SCENE"]:[]])),s="string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${n} marks`;return{component:"",frameType:t.frameType,status:i?"empty":"ok",empty:i,markCount:n,markCountByType:o,width:t.width,height:t.height,...t.xDomain?{xDomain:t.xDomain}:{},...t.yDomain?{yDomain:t.yDomain}:{},...t.categories?{categories:t.categories}:{},...void 0!==t.nodeCount?{nodeCount:t.nodeCount}:{},...void 0!==t.edgeCount?{edgeCount:t.edgeCount}:{},...void 0!==t.legendItems?{legendItems:t.legendItems}:{},annotationCount:e.reduce((t,e)=>t+e.annotationCount,0),ariaLabel:s,warnings:r,semanticStatus:"not-assessed",semanticDiagnostics:[]}}function Ch(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Oh(t){if(!t||2>t.length)return;const e=Ch(t[0]),o=Ch(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Fh(t){const{count:e,byType:o}=function(t){const e={};for(const o of t){const t="string"==typeof o?.type&&o.type.length>0?o.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),n=0===e,i=[...t.extraWarnings??[]];n&&!i.includes("EMPTY_SCENE")&&i.push("EMPTY_SCENE"),t.annotationRender&&t.annotationRender.unrenderedCount>0&&!i.includes("UNRENDERED_ANNOTATIONS")&&i.push("UNRENDERED_ANNOTATIONS");const r=Array.isArray(t.annotations)?t.annotations.length:0,s=t.margin,a=s?{x:s.left,y:s.top,width:t.width-s.left-s.right,height:t.height-s.top-s.bottom}:void 0;return{component:"",frameType:t.frameType,status:n?"empty":"ok",empty:n,markCount:e,markCountByType:o,width:t.width,height:t.height,...t.xDomain?{xDomain:t.xDomain}:{},...t.yDomain?{yDomain:t.yDomain}:{},...t.categories?{categories:t.categories}:{},...void 0!==t.nodeCount?{nodeCount:t.nodeCount}:{},...void 0!==t.edgeCount?{edgeCount:t.edgeCount}:{},...void 0!==t.legendItems?{legendItems:t.legendItems}:{},annotationCount:t.annotationRender?.renderedCount??r,...t.annotationRender?{annotationInputCount:t.annotationRender.inputCount,unrenderedAnnotationCount:t.annotationRender.unrenderedCount,...t.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:t.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:i,semanticStatus:"not-assessed",semanticDiagnostics:[],...s?{margin:s}:{},...a?{plot:a}:{}}}import*as Dh from"react";import{area as zh,line as Nh}from"d3-shape";import{jsx as Eh,jsxs as Bh}from"react/jsx-runtime";var Wh={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function jh(t,e="#4e79a7"){return yi(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function Yh(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function Xh(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=kh(i,t.size);if(0>=r.scale)return null;const s=`translate(${e},${o})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),c=_h(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),l=c?Yh(n+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>i.parts.map((o,n)=>{const i=e?"none"===o.fill?void 0:e:Ah(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:Ah(o.stroke??"none",a,t.accent);return i||r?Eh("path",{d:o.d,fill:i??"none",stroke:r,strokeWidth:r?o.strokeWidth??1:void 0,strokeLinecap:o.strokeLinecap,strokeLinejoin:o.strokeLinejoin,opacity:o.opacity},n):null});return Bh("g",{transform:s,opacity:1===u?void 0:u,children:[c&&l&&Eh("clipPath",{id:l,children:Eh("rect",{x:c.x,y:c.y,width:c.width,height:c.height})}),c&&t.ghostColor?Eh("g",{children:d(t.ghostColor)}):null,c&&l?Eh("g",{clipPath:`url(#${l})`,children:d()}):d()]},n)}function qh(t,e){const o=t.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity))).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color??e,opacity:null==t.opacity?void 0:Math.max(0,Math.min(1,t.opacity))}));return 2>o.length?null:o.map((t,e)=>Eh("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function Gh(t,e,o){const n=jd(t.symbolType,t.size,t.path);return Eh("path",{d:n,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?jh(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${o??""}symbol-${e}`)}import*as Vh from"react";import{jsx as Hh}from"react/jsx-runtime";function Uh(t){if(!1!==t?.interactive)return t?.style?.cursor}function Kh(t,e,o){const n=Uh(e);return n&&null!=t&&!1!==t?Hh("g",{style:{cursor:n},"data-semiotic-mark-cursor":n,children:t},o):t}import*as Zh from"react";import{arc as Qh}from"d3-shape";import{jsx as Jh,jsxs as tf}from"react/jsx-runtime";import*as ef from"react";import{jsx as of,jsxs as nf}from"react/jsx-runtime";import*as rf from"react";import{arc as sf}from"d3-shape";var af=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function cf(t){const{innerRadius:e,outerRadius:o,startAngle:n,endAngle:i}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=af(o,n),e=af(o,i);return`M0,0 L${t.x},${t.y} A${o},${o} 0 ${i-n>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=af(o,n),s=af(o,i),a=af(e,i),c=af(e,n),l=i-n>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${l} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${l} 0 ${c.x},${c.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return cf({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),c=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),l=i-n,u=t.roundStart&&t.roundEnd?l/2:l,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return cf({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=n+(d?a:0),p=i-(h?a:0),y=n+(d?c:0),g=i-(h?c:0),m=af(o,f),x=af(o,p),b=(o-s)*Math.cos(a),v=af(b,n),w=af(b,i),k=r?null:af(e,g),A=r?null:af(e,y),S=r?0:(e+s)*Math.cos(c),M=r?null:af(S,n),_=r?null:af(S,i),P=p-f>Math.PI?1:0,L=r?0:g-y>Math.PI?1:0;let $="";if(d)$+=`M${v.x},${v.y}`,$+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=af(o,n);$+=`M${t.x},${t.y}`}if(h)$+=` A${o},${o} 0 ${P} 1 ${x.x},${x.y}`,$+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=af(o,i);$+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)$+=" L0,0";else{if(h)$+=` L${_.x},${_.y}`,$+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=af(e,i);$+=` L${t.x},${t.y}`}if(d)$+=` A${e},${e} 0 ${L} 0 ${A.x},${A.y}`,$+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=af(e,n);$+=` A${e},${e} 0 ${L} 0 ${t.x},${t.y}`}}return $+=" Z",$}import{jsx as lf,jsxs as uf}from"react/jsx-runtime";function df(t){return 1e6>t?1e4>t?1e3>t?t+"":(t/1e3).toFixed(1)+"K":(t/1e3).toFixed(0)+"K":(t/1e6).toFixed(1)+"M"}function hf(t,e){const o=t.datum;if(!o)return null;const n=[],i=o.__funnelStepLabel,r=Number(o.__funnelStepLabelX),s=Number(o.__funnelStepLabelY),a=Number(o.__funnelRowWidth);"string"!=typeof i||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*i.length+16>a||n.push(lf("text",{x:r,y:s+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-step"));const c=Number(o.__funnelValue),l=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(c)&&0!==c&&Number.isFinite(l)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let i=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${df(c)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:df(c);7.8*i.length+16>d&&(i=df(c)),7.8*i.length+16>d||n.push(lf("text",{x:l,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-value"))}return n.length?lf("g",{children:n},e+"-funnel-labels"):null}import{jsx as ff,jsxs as pf}from"react/jsx-runtime";function yf(t,e,o,n){if(!t||2>e.length)return null;const i=qh(t.stops,n);return i?ff("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function gf(t,e,o,n=30){const i=function(t,e,o,n=30){switch(t.type){case"line":{const n=t;if(0===n.path.length)return null;const i=Ac(n.curve),r=i?Nh().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=Yh(`${o?o+"-":""}line-${e}-stroke-gradient`),a=yf(n.strokeGradient,n.path,s,n.style.stroke||"#4e79a7");return pf(Dh.Fragment,{children:[a&&ff("defs",{children:a}),ff("path",{d:r,fill:"none",stroke:a?`url(#${s})`:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth??2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity})]},"line-"+e)}case"area":{const i=t;if(0===i.topPath.length)return null;const r=Ac(i.curve),s=!r||2>i.topPath.length||2>i.bottomPath.length?`M${i.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...i.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:zh().x(([t])=>t).y0((t,e)=>i.bottomPath[e][1]).y1(([,t])=>t).curve(r)(i.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,c=yi(i.style.fill)?xi(i.style.fill,a):void 0,l=Yh(`${o?o+"-":""}area-${e}-gradient`),u=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=1/0;for(const[,e]of t.topPath)n=Math.min(n,e);let i=-1/0;for(const[,e]of t.bottomPath)i=Math.max(i,e);if(!Number.isFinite(n)||!Number.isFinite(i))return null;const r=qh(o.stops,jh(t.style.fill));return r?ff("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r}):null}(i,l),d=u?`url(#${l})`:c?`url(#${a})`:jh(i.style.fill),h=u?void 0:i.style.fillOpacity??i.style.opacity??.7,f=r?Nh().x(([t])=>t).y(([,t])=>t).curve(r)(i.topPath)??"":"M"+i.topPath.map(([t,e])=>`${t},${e}`).join("L"),p=Uh(i),y=p&&n>=0?ff("path",{d:f,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*n),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:p},"data-semiotic-mark-cursor":p,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${e}-cursor-target`):null,g=Yh(`${o?o+"-":""}area-${e}-stroke-gradient`),m=!(!i.colorThresholds?.length||!i.rawValues||i.rawValues.length!==i.topPath.length),x=!!i.strokeColorBands?.length,b=m||x?null:yf(i.strokeGradient,i.topPath,g,i.style.stroke||"#4e79a7"),v=i.style.strokeWidth??2;let w=1/0,k=-1/0;for(const[t]of i.topPath)w>t&&(w=t),t>k&&(k=t);const A=x?i.strokeColorBands.map((t,n)=>Yh(`${o?o+"-":""}area-${e}-stroke-band-${n}`)):[],S=x?i.strokeColorBands.map((t,e)=>ff("clipPath",{id:A[e],children:ff("rect",{x:w-v,y:t.y,width:k-w+2*v,height:t.height})},A[e])):null,M=i.style.stroke&&"none"!==i.style.stroke?x?i.strokeColorBands.map((t,o)=>ff("path",{d:f,fill:"none",stroke:t.color??jh(i.style.stroke),strokeWidth:v,opacity:(i.style.opacity??1)*(t.opacity??1),clipPath:`url(#${A[o]})`},`area-${e}-stroke-band-${o}`)):m?xd(i.topPath,i.rawValues,i.colorThresholds,jh(i.style.stroke)).map((t,o)=>ff("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:v,opacity:i.style.opacity},`area-${e}-threshold-${o}`)):ff("path",{d:f,fill:"none",stroke:b?`url(#${g})`:jh(i.style.stroke),strokeWidth:v,opacity:i.style.opacity}):null;if(i.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return pf("g",{children:[pf("defs",{children:[u,!u&&c,b,S,ff("clipPath",{id:t,children:ff("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),pf("g",{clipPath:`url(#${t})`,children:[ff("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,y]})]},"area-"+e)}return pf(Dh.Fragment,{children:[(u||c||b||S)&&pf("defs",{children:[u,!u&&c,b,S]}),ff("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,y]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=yi(n.style.fill)?xi(n.style.fill,i):void 0;return pf(Dh.Fragment,{children:[r&&ff("defs",{children:r}),ff("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:jh(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return Gh(t,e);case"glyph":return Xh(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=yi(n.style.fill)?xi(n.style.fill,i):void 0;return pf(Dh.Fragment,{children:[r&&ff("defs",{children:r}),ff("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:jh(n.style.fill),opacity:n.style.opacity,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const o=t,n={x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth,...null!=o.style?.opacity&&{opacity:o.style.opacity}};if(o.showValues&&null!=o.value&&o.w>=20&&o.h>=20){const t=o.valueFormat?o.valueFormat(o.value):Number.isInteger(o.value)?o.value+"":100>Math.abs(o.value)?1>Math.abs(o.value)?o.value.toPrecision(3):o.value.toFixed(1):o.value.toFixed(0),[i,r,s]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(o.fill),a=.299*i+.587*r+.114*s>128?"#000":"#fff",c=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return pf("g",{children:[ff("rect",{...n}),ff("text",{className:"semiotic-heatmap-value",x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:c+"px",fontFamily:"var(--semiotic-font-family, sans-serif)",children:t})]},"heatcell-"+e)}return ff("rect",{...n},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return pf("g",{style:o.style,children:[ff("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),ff("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),ff("circle",{cx:o.x,cy:o.lowY,r:t,fill:o.wickColor})]},"candle-"+e)}const n=Math.min(o.openY,o.closeY),i=Math.max(Math.abs(o.openY-o.closeY),1),r=o.isUp?o.upColor:o.downColor;return pf("g",{style:o.style,children:[ff("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),ff("rect",{x:o.x-o.bodyWidth/2,y:n,width:o.bodyWidth,height:i,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}(t,e,o,n);return"area"===t.type?i:Kh(i,t,"xy-cursor-"+e)}var mf=new Set;function xf(t){const{node:e,index:o,renderMode:n,fallback:i}=t,r=function(t,e){const o="function"==typeof t?t(e.datum??null,e):t;return(n=o)&&"object"==typeof n&&"string"==typeof n.id&&"function"==typeof n.cacheKey&&"function"==typeof n.drawCanvas&&"function"==typeof n.renderStaticSVG?o:void 0;var n}(n,e);if(!r)return{element:i(),renderedByBackend:!1};const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?{element:Kh(s,e,`${r.id}-${o}-cursor`),renderedByBackend:!0}:(function(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;mf.has(o)||(mf.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}(r.id,e.type??"unknown"),{element:i(),renderedByBackend:!1})}function bf(t){const e=[];return t.nodes.forEach((o,n)=>{const i=xf({node:o,index:n,renderMode:t.renderMode,fallback:()=>t.fallback(o,n)});null!=i.element&&!1!==i.element&&e.push({node:o,index:n,...i})}),e}import{scaleOrdinal as vf}from"d3-scale";import{jsx as wf,jsxs as kf}from"react/jsx-runtime";function Af(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>Z(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:w;return vf().domain(t).range(n)}function Sf(t,e,o){if(0===t.length)return;const n=Af(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}function Mf(t){return"left"===t?"start":"right"===t?"end":t??"start"}function _f(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function Pf(t){return t.typography.legendFontFamily??t.typography.fontFamily}function Lf(t){return t.typography.legendFontWeight}function $f(t,e,o,n){const i=_f(n);return e+o+Math.ceil(t.length*i*.58)}function Rf(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,itemGap:l,rowHeight:u}=ke(s),d=a+c,h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right),p=e.map(t=>$f(t,a,c,o));if(h){const t=Math.max(a,s?.maxWidth??f),o=[];let n=0,i=0;p.forEach((e,r)=>{const s=0===i?e:i+l+e;i>0&&s>t?(o.push({start:n,end:r,width:i}),n=r,i=e):i=s}),e.length>0&&o.push({start:n,end:e.length,width:i});const r=Mf(s?.align),c=[];return o.forEach((o,n)=>{let i="center"===r?Math.max(0,(t-o.width)/2):"end"===r?Math.max(0,t-o.width):0;for(let t=o.start;o.end>t;t++)c.push({category:e[t],width:p[t],x:i,y:n*u}),i+=p[t]+l}),{items:c,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const y=Math.max(0,...p);return{items:e.map((t,e)=>({category:t,width:p[e],x:0,y:e*u})),width:y,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function Tf(t,e){if(!e||!t||0===t.length)return[];const o="function"==typeof e?e:t=>t[e],n=new Set;for(const e of t){const t=o(e);null!=t&&n.add(t+"")}return Array.from(n)}import{jsx as If,jsxs as Cf}from"react/jsx-runtime";function Of(t,e=120,o=8){if(!t)return[];const n=Math.max(1,Math.floor(e/o)),i=t.split(/\s+/),r=[];let s="";for(const t of i)s&&s.length+1+t.length>n?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function Ff(t,e,o,n){return"curly"===t?n?`M0,0 C${.6*o},0 ${.4*o},${e/2} ${o},${e/2} C${.4*o},${e/2} ${.6*o},${e} 0,${e}`:`M0,0 C0,${.6*o} ${e/2},${.4*o} ${e/2},${o} C${e/2},${.4*o} ${e},${.6*o} ${e},0`:n?`M0,0 L${o},0 L${o},${e} L0,${e}`:`M0,0 L0,${o} L${e},${o} L${e},0`}function Df(t,e,o,n){if(!t)return If("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:c=120,noWrap:l}=t;if(!i&&!r)return If("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(o)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>o?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>e?"end":"start";const f=16,p=r?l?[r]:Of(r,c):[],y=i?l?[i]:Of(i,c):[],g="leftRight"===u?"end"===h?-4:4:0;let m=0;const x=[],b=n||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?x.push(If("foreignObject",{className:"annotation-note-html",x:"end"===h?g-c:"middle"===h?g-c/2:g,y:-16,width:c,height:Math.max(f,(p.length+y.length)*f+(r&&i?2:0))+f,style:{overflow:"visible"},children:Cf("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:[r&&If("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&If("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(p.length>0&&(x.push(If("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>If("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),y.length>0&&x.push(If("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:y.map((t,e)=>If("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(c,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=If("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+y.length)*f+(y.length>0?f:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=If("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+y.length-1)*f;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(y.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),Cf("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[If("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function zf(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(If("circle",{r:t,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,n=e?.height||0;(t>0||n>0)&&r.push(If("rect",{width:t,height:n,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":e?.custom&&r.push(...Array.isArray(e.custom)?e.custom:[e.custom]);break;case"xy-threshold":{const t=n||0,s=i||0;if(void 0!==e?.x){const n=(e.x||0)-t;r.push(If("line",{x1:n,y1:(e.y1||0)-s,x2:n,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const n=(e.y||0)-s;r.push(If("line",{x1:(e.x1||0)-t,y1:n,x2:(e.x2||0)-t,y2:n,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(If("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(If("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const t=e?.type||"curly",n=e?.width??e?.height;void 0!==n&&r.push(If("path",{d:Ff(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return If("g",{className:"annotation-subject",children:r})}function Nf(t,e,o,n,i,r){const s=[];let a=0,c=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const o=r.width||0,n=r.height||0;if(o>0||n>0){const i=o/2,r=n/2,s=t-i,l=e-r;if(0!==s||0!==l){const t=Math.abs(s),e=Math.abs(l),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,c=r+l*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,c=o):void 0!==e&&(a=o,c=e/2)}}else{const o=(r.radius||0)+(r.radiusPadding||0);if(o>0&&(0!==t||0!==e)){const n=Math.atan2(e,t);a=Math.cos(n)*o,c=Math.sin(n)*o}}const l=Math.sqrt((t-a)**2+(e-c)**2);if(l>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-c,t-a);if(r){const n=(a+t)/2,r=(c+e)/2,d=-(e-c)/l,h=(t-a)/l,f=(o?.curve??.25)*l,p=n+d*f,y=r+h*f;s.push(If("path",{className:"connector-curve",d:`M${a},${c}Q${p},${y} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(y-c,p-a)}else s.push(If("line",{x1:a,y1:c,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(If("path",{d:`M${a},${c}L${a+t*Math.cos(u+e)},${c+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${c+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return If("g",{className:"annotation-connector",children:s})}function Ef(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:c,subject:l,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:y,events:g={},"data-testid":m}=t,x=Array.isArray(e)?e[0]??0:e,b=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(f)?f:[]);let w=n||0,k=i||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const A="string"==typeof u?u:"label";if("bracket"===A&&l&&0===w&&0===k)if(void 0!==l.width){w=l.width/2;const t=l.depth||30;k=t+(0>t?-5:5)}else if(void 0!==l.height){const t=l.depth||30;w=t+(0>t?-5:5),k=l.height/2}return Cf("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.has("connector")&&Nf(w,k,c,d,A,l),!v.has("subject")&&zf(A,l,d,x,b),!v.has("note")&&Df(a,w,k,d)]})}function Bf(t){const{noteData:e}=t,{screenCoordinates:o}=e,n="string"==typeof e.type?e.type:"label",i=e.eventListeners||e.events||{};if(e.coordinates&&o){const t=e.nx||o[0][0]+(e.dx??0),i=e.ny||o[0][1]+(e.dy??0),r=o.map((o,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:o[0],y:o[1],nx:t,ny:i});return If(Ef,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return If("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return If(Ef,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{jsx as Wf}from"react/jsx-runtime";var jf={secondary:0,primary:3};function Yf(t){return!0===t?._annotationDeferred}function Xf(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function qf(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function Gf(t){return Math.max(.72,.95-.06*t)}function Vf(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(o=t.annotation,"primary"===o?.emphasis||"secondary"===o?.emphasis?o.emphasis:null),confidence:qf(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>Yf(t.annotation)),i=t.some(t=>null!=Xf(t.annotation)),r=t.some(t=>"layer"===Xf(t.annotation));if(!o&&!n&&!i)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=2-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=jf[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:o,emphasis:n,readingOrder:i}=t,r=Yf(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=Wf("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:Gf(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=Xf(e.annotation);return a&&(s=Wf("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=Wf("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(Wf("style",{children:".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}}"},"annotation-disclosure-style")),r&&a.unshift(Wf("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}function Hf(t,e){const o=e.scales?.x??e.scales?.time;return o?null!=t.x?o(t.x):e.xAccessor&&null!=t[e.xAccessor]?o(t[e.xAccessor]):null:null}function Uf(t,e){const o=e.scales?.y??e.scales?.value;return o?null!=t.y?o(t.y):e.yAccessor&&null!=t[e.yAccessor]?o(t[e.yAccessor]):null:null}function Kf(t){return null==t?null:t+""}function Zf(t,e,o){return e.stickyPositionCache?.set(t,o),o}function Qf(t,e,o){const n=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===n){if(null!=t.pointId&&o.pointNodes&&o.pointNodes.length>0)for(let n=o.pointNodes.length-1;n>=0;n--){const i=o.pointNodes[n];if(i.pointId===t.pointId)return Zf(e,o,{x:i.x,y:i.y})}const n=function(t){const e=t.data;if(!e||0===e.length)return null;const o=e[e.length-1],n=t.scales?.x??t.scales?.time,i=t.scales?.y??t.scales?.value;if(!n||!i)return null;const r=o[t.xAccessor||"x"],s=o[t.yAccessor||"y"];return null==r||null==s?null:{x:n(r),y:i(s)}}(o);return n?Zf(e,o,n):null}if("semantic"===n){const n=function(t,e,o){const n=function(t){return Kf(t.provenance?.stableId??t.stableId)}(t);if(!n)return null;const i=o.pointNodes?.find(t=>Kf(t.pointId)===n);if(i)return Zf(e,o,{x:i.x,y:i.y});const r=o.data?.find(t=>function(t){return Kf(t.stableId??t.id??t.provenance?.stableId)}(t)===n);if(!r)return null;const s=Hf(r,o),a=Uf(r,o);return null==s||null==a?null:Zf(e,o,{x:s,y:a})}(t,e,o);if(n)return n}let i=null,r=null;if(null!=t.pointId&&o.pointNodes){const e=o.pointNodes.find(e=>e.pointId===t.pointId);e&&(i=e.x,r=e.y)}if(null!=i&&null!=r||(i=Hf(t,o),r=Uf(t,o)),null!=i&&null!=r)return Zf(e,o,{x:i,y:r});if("sticky"===n){const t=o.stickyPositionCache?.get(e);if(t)return t}return null}var Jf=new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function tp(t){return!!t&&"object"==typeof t&&Jf.has(function(t){return"string"==typeof t?.type?t.type:""}(t))}function ep(t){return"primary"===t?.emphasis||!0===t?.defensive}function op(t,e,o={}){return"number"==typeof o.maxAnnotations&&Number.isFinite(o.maxAnnotations)?Math.max(0,Math.floor(o.maxAnnotations)):t>0&&e>0?Math.max(1,Math.round(t*e/(o.areaPerAnnotation&&o.areaPerAnnotation>0?o.areaPerAnnotation:2e4))):1/0}function np(t){let e;const o=t?.emphasis;e="primary"===o?100:"secondary"===o?10:50;const n=t?.provenance?.confidence;switch("number"==typeof n&&Number.isFinite(n)&&(e+=15*Math.max(0,Math.min(1,n))),t?.lifecycle?.freshness){case"fresh":e+=8;break;case"aging":e+=4;break;case"stale":e+=1;break;case"expired":e-=200}return e}new Set(["label","callout","callout-circle","callout-rect"]);var ip=32,rp=6,sp=4,ap=8,cp=72;var lp={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function up(t){if(!dp(t))return t;const e=("string"==typeof t.mobileText?t.mobileText:void 0)??("string"==typeof t.shortText?t.shortText:void 0);return!e||"string"!=typeof t.label&&null!=t.label?t:{...t,label:e}}function dp(t){return tp(t)}function hp(t,e){if(!t)return[];const o=Math.max(1,Math.floor(e/7)),n=t.split(/\s+/).filter(Boolean),i=[];let r="";for(const t of n)r&&r.length+t.length+1>o?(i.push(r),r=t):r=r?`${r} ${t}`:t;return r&&i.push(r),i}function fp(t,e,o,n,i){const r=t+o,s=e+n;return Math.abs(o)>Math.abs(n)?{x:0>o?r-i.width-4:r+4,y:0>n?s-i.height:s,width:i.width,height:i.height}:{x:0>o?r-i.width:r,y:0>n?s-i.height-4:s+4,width:i.width,height:i.height}}function pp(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function yp(t,e){return Math.max(0,Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x))*Math.max(0,Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y))}function gp(t,e,o,n,i,r,s,a){const c=pp(t,s);let l=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,o,n){const i=Math.max(0,n-t.x),r=Math.max(0,n-t.y);return(i+Math.max(0,t.x+t.width-(e-n)))*t.height+(r+Math.max(0,t.y+t.height-(o-n)))*t.width}(c,i,r,a);for(const t of o)l+=12*yp(c,t);for(const t of n)l+=4*yp(c,t);return l}function mp(t){const{annotations:e,context:o,defaultOffset:n=ip,notePadding:i=rp,markPadding:r=sp,edgePadding:s=ap,preserveManualOffsets:a=!0,routeLongConnectors:c=!0,connectorThreshold:l=cp,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:f,mobile:p,cohesion:y,audience:g}=t,m=o.width||0,x=o.height||0,b="object"==typeof p?p:{},v=b.breakpoint??480,w=!!p&&v>=m,k=w&&!1!==b.preferShortText?e.map(up):e,A=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,S=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!f?b.responsive??{minWidth:v}:f,_=w&&!y?b.cohesion:y;if(0===k.length||0>=m||0>=x)return k.slice();const P=[],L=function(t,e){return(t.pointNodes||[]).map(t=>{const o=Math.max(1,t.r||1)+e;return{x:t.x-o,y:t.y-o,width:2*o,height:2*o}})}(o,r);let $=!1;const R=k.map((t,e)=>{if(!dp(t))return t;const r=function(t,e,o){if("widget"===t.type&&"number"==typeof t.px&&"number"==typeof t.py)return{x:t.px,y:t.py};const n=t.pointId??t.nodeId;if(null!=n&&o.pointNodes){const t=o.pointNodes.find(t=>t.pointId===n);if(t)return{x:t.x,y:t.y}}const i=t.coordinates,r=o.scales?.geoProjection;if(Array.isArray(i)&&i.length>=2&&r){const t=i[0],e=i[1];if("number"==typeof t&&"number"==typeof e){const o=r([t,e]);if(o&&"number"==typeof o[0]&&"number"==typeof o[1])return{x:o[0],y:o[1]}}}return o.scales||"number"!=typeof t.x||"number"!=typeof t.y?Qf(t,e,o):{x:t.x,y:t.y}}(t,e,o);if(!r)return t;const u=function(t){if("widget"===t.type)return{width:"number"==typeof t.width?t.width:32,height:"number"==typeof t.height?t.height:32};const e="number"==typeof t.wrap?t.wrap:120,o=[...hp("string"==typeof t.title?t.title:void 0,e),...hp("string"==typeof t.label?t.label:void 0,e)],n=o.reduce((t,e)=>Math.max(t,e.length),0);return{width:Math.max(24,Math.min(e,7*n)+10),height:Math.max(18,16*o.length+6)}}(t);if(a&&("number"==typeof(d=t).dx||"number"==typeof d.dy)){const e=function(t){return"text"===t.type||"widget"===t.type?{dx:0,dy:0}:{dx:30,dy:-30}}(t);return P.push(pp(fp(r.x,r.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,u),i)),t}var d;let h=null,f=1/0;for(const t of function(t){const e=1.6*t;return[{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t},{dx:t,dy:0},{dx:-t,dy:0},{dx:0,dy:-t},{dx:0,dy:t},{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e}]}(n)){const e=gp(fp(r.x,r.y,t.dx,t.dy,u),t,P,L,m,x,i,s);f>e&&(h=t,f=e)}if(!h)return t;const p=pp(fp(r.x,r.y,h.dx,h.dy,u),i);P.push(p);const y=Math.hypot(h.dx,h.dy),g=c&&y>=l&&"text"!==t.type&&"widget"!==t.type?{...t.connector||{end:"arrow"},type:"curve"}:t.connector;return $=!0,{...t,dx:h.dx,dy:h.dy,...g?{connector:g}:{}}}),T=$?R:k.slice();let I=T;if(h){let t=!1;const e=T.map(e=>{const o=function(t){return"text"!==t.type||"string"!=typeof t.color||8>Math.hypot("number"==typeof t.dx?t.dx:0,"number"==typeof t.dy?t.dy:0)?t:{...t,_redundantConnector:!0}}(e);return o!==e&&(t=!0),o});I=t?e:T}{let t=!1;const e=I.map(e=>{if(!0!==e?.defensive)return e;const o=function(t){const e=t?.provenance;if(!e||"object"!=typeof e)return t;const o="string"==typeof e.source?Object.prototype.hasOwnProperty.call(lp,e.source)?lp[e.source]:e.source:null,n="number"==typeof e.confidence&&Number.isFinite(e.confidence)?Math.round(100*Math.max(0,Math.min(1,e.confidence)))+"%":null;if(!o&&!n)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const i=[o,n].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${i})`)?t:{...t,label:r?`${r} (${i})`:`(${i})`}}(e);return o!==e&&(t=!0),o});I=t?e:I}const C=new Set;if(A){const t="object"==typeof A?A:{},e=function(t){if(!t)return 1;const e=function(t){const e=t?.familiarity;if(!e)return 3;const o=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===o.length?3:o.reduce((t,e)=>t+e,0)/o.length}(t);return e>2?4>e?1:.6:1.5}(g),o=1===e?t:{...t,maxAnnotations:Math.max(0,Math.round((t.maxAnnotations??op(m,x,t))*e))},{deferred:n}=function(t){const{annotations:e,width:o,height:n}=t,i=Math.max(0,t.minVisible??1),r=op(o,n,t),s=e.map((t,e)=>{return{annotation:t,index:e,note:(o=t,tp(o))};var o}),a=s.filter(t=>t.note);if(0===a.length||r>=a.length)return{visible:e.slice(),deferred:[],budget:r};const c=a.filter(t=>ep(t.annotation)),l=a.filter(t=>!ep(t.annotation)).sort((t,e)=>np(e.annotation)-np(t.annotation)||t.index-e.index),u=Math.min(l.length,Math.max(Math.max(0,r-c.length),Math.max(0,i-c.length))),d=new Set([...c.map(t=>t.index),...l.slice(0,u).map(t=>t.index)]),h=[],f=[];for(const{annotation:t,index:e,note:o}of s)!o||d.has(e)?h.push(t):f.push(t);return{visible:h,deferred:f,budget:r}}({annotations:I,width:m,height:x,...o});for(const t of n)C.add(t)}if(M&&("object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:480)>=m)for(const t of I)dp(t)&&"secondary"===t.emphasis&&C.add(t);if(C.size>0)for(const t of I)!0===t?.defensive&&C.delete(t);let O;return O=0===C.size?I:S?I.map(t=>C.has(t)?{...t,_annotationDeferred:!0}:t):I.filter(t=>!C.has(t)),_?function(t,e){let o=!1;const n=t.map(t=>dp(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(o=!0,{...t,cohesion:e}):t);return o?n:t}(O,_):O}import{jsx as xp,jsxs as bp}from"react/jsx-runtime";var vp="var(--semiotic-bg, #ffffff)";function wp(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:c="start",dominantBaseline:l,background:u,className:d}=t,h=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),f=t=>xp("text",{x:e,y:o,textAnchor:c,dominantBaseline:l,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{style:{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}}:{},children:n});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??vp,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},y="number"==typeof p?p:p.x,g="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(n,r),x=r+2*g;let b,v;return b="middle"===c?e-m/2-y:"end"===c?e-m-y:e-y,v="middle"===l||"central"===l?o-x/2:"hanging"===l||"text-before-edge"===l?o-g:o-.8*r-g,bp("g",{className:d,children:[xp("rect",{x:b,y:v,width:m+2*y,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??vp,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}function kp(t,e,o,n){const i=function(t,e,o="#4e79a7"){if(yi(t)){const o=function(t,e){let o=2166136261;const n=gi(e);for(let t=0;n.length>t;t++)o^=n.charCodeAt(t),o=Math.imul(o,16777619);return`${t}-hatch-${(o>>>0).toString(36)}`}(e,t);return{fill:`url(#${o})`,def:xi(t,o)}}return t&&"string"==typeof t?{fill:t}:{fill:o}}(t.fill??t.color,e,n);return function(t,e,o,n){if(!t||"object"!=typeof t)return;const i=t;if(!Array.isArray(i.stops))return;const r=i.stops.flatMap(t=>{if(!t||"object"!=typeof t)return[];const{offset:e,color:o,opacity:i}=t;return"number"==typeof e&&Number.isFinite(e)?[{offset:Math.max(0,Math.min(1,e)),color:"string"==typeof o&&o?o:n,opacity:"number"==typeof i&&Number.isFinite(i)?Math.max(0,Math.min(1,i)):void 0}]:[]}).sort((t,e)=>t.offset-e.offset);if(!r.length)return;const s="horizontal"===i.direction?"horizontal":"vertical"===i.direction?"vertical":o,a=e+"-gradient";return{fill:`url(#${a})`,def:fi("linearGradient",{id:a,x1:0,y1:0,x2:"horizontal"===s?"100%":0,y2:"vertical"===s?"100%":0,children:r.map((t,e)=>fi("stop",{offset:100*t.offset+"%",stopColor:t.color,stopOpacity:t.opacity},`${t.offset}-${e}`))},a)}}(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:n)??i}var Ap=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Sp(t,e,o,n){const i=function(t,e,o){const n=t.position,i="string"==typeof n&&Ap.has(n)?n:"bottom-left",r=i.endsWith("left")?"left":i.endsWith("right")?"right":"center",s=i.startsWith("top")?"top":i.startsWith("bottom")?"bottom":"middle",a="top"===s?0:"bottom"===s?o:o/2;return{x:("left"===r?0:"right"===r?e:e/2)+("number"==typeof t.dx&&Number.isFinite(t.dx)?t.dx:0),y:a+("number"==typeof t.dy&&Number.isFinite(t.dy)?t.dy:0),textAnchor:"start"===t.textAnchor||"middle"===t.textAnchor||"end"===t.textAnchor?t.textAnchor:"left"===r?"start":"right"===r?"end":"middle",dominantBaseline:"auto"===t.dominantBaseline||"middle"===t.dominantBaseline||"hanging"===t.dominantBaseline?t.dominantBaseline:"top"===s?"hanging":"bottom"===s?"auto":"middle"}}(t,e,o);return{...i,fill:t.fill??t.color??n.fill,fontSize:t.fontSize??n.fontSize,fontFamily:t.fontFamily??n.fontFamily,fontWeight:t.fontWeight,fontStyle:t.fontStyle,letterSpacing:t.letterSpacing,opacity:t.opacity,className:t.className,style:{pointerEvents:"none"}}}import{jsx as Mp}from"react/jsx-runtime";var _p={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Pp({annotation:t,width:e,height:o,defaults:n=_p}){const i=t.label??t.text;return null==i?null:Mp("text",{...Sp(t,e,o,n),children:i})}import{packEnclose as Lp}from"d3-hierarchy";import{area as $p,curveBasis as Rp,curveCardinal as Tp,curveCatmullRom as Ip,curveLinear as Cp,curveMonotoneX as Op,curveMonotoneY as Fp,curveStep as Dp,curveStepAfter as zp,curveStepBefore as Np}from"d3-shape";import*as Ep from"react";function Bp(t,e={}){const o=function(t){const e=t.provenance,o=t.id??t.stableId??e?.stableId;return null==o||""===o?void 0:o+""}(t);return{"data-semiotic-annotation-widget":"",...o?{"data-semiotic-annotation-id":o}:{},onClickCapture(n){const i=function(t){const e=t.nativeEvent;return"touch"===e.pointerType?"touch":0===e.detail?"keyboard":"pointer"}(n);e.onAnnotationActivate?.({annotation:t,annotationId:o,chartId:e.chartId,inputType:i}),o&&e.onObservation&&e.onObservation({type:"annotation-activate",annotationId:o,inputType:i,timestamp:Date.now(),chartType:e.chartType??"unknown",chartId:e.chartId})}}}import{jsx as Wp,jsxs as jp}from"react/jsx-runtime";var Yp={linear:Cp,monotoneX:Op,monotoneY:Fp,step:Dp,stepAfter:zp,stepBefore:Np,basis:Rp,cardinal:Tp,catmullRom:Ip};import{jsx as Xp,jsxs as qp}from"react/jsx-runtime";var Gp=16;function Vp(t,e){return t.color||e.colors.annotation||e.colors.text}function Hp(t,e,o){const n=t.labelBackground,i=e.colors.background,r=i&&"transparent"!==i?i:e.colors.surface||i;return void 0===n?"none"===o?"none":{type:"halo",fill:r}:!1===n||"none"===n?"none":!0===n||"halo"===n?{type:"halo",fill:r}:"box"===n?{type:"box",fill:r}:{fill:r,...n}}function Up(t,e,o){return null!=t.x&&e.x?e.x(t.x):o&&null!=t[o]&&e.x?e.x(t[o]):"number"==typeof t.x?t.x:null}function Kp(t,e,o){return null!=t.y&&e.y?e.y(t.y):o&&null!=t[o]&&e.y?e.y(t[o]):"number"==typeof t.y?t.y:null}function Zp(t){const{annotations:e}=t;if(!e||0===e.length)return t.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;const o=function(t,e={}){const o=!0===e.showRetractedAnnotations,n=!0===e.showSupersededAnnotations,i=new Set;for(const e of t){const t=e?.lifecycle?.supersedes;t&&"retracted"!==e?.lifecycle?.status&&i.add(t)}return t.filter(t=>{if("retracted"===t?.lifecycle?.status&&!o)return!1;const e=t?.provenance?.stableId;return!(e&&i.has(e)&&!n)})}(e),n=t.scales.geoProjection,i=n?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=n([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,r=!!n&&!t.scales.x&&!t.scales.y,s=t=>Number(t),a=t.scales.x??(r?s:void 0),c=t.scales.y??(r?s:void 0),l=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,u={scales:{..."vertical"===t.projection?{x:t.scales.o??a,y:t.scales.r??c,time:t.scales.o??a,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??a,y:t.scales.o??c,time:t.scales.r??a,value:t.scales.o??c,o:t.scales.o}:{x:a,y:c,time:a,value:c,o:t.scales.o},...n?{geoProjection:n}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,pointNodes:t.pointNodes,frameType:t.frameType??(t.projection?"ordinal":n||t.scales.x||t.scales.y?"xy":"network"),...l?{projection:l}:{}},d=t.autoPlaceAnnotations?mp({annotations:i,context:u,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):i,h=function(t,e,o,n){const i=[];return t.forEach((t,r)=>{let s;if(o){const i=o(t,r,n);s=null!=i?i:e(t,r,n)}else s=e(t,r,n);s&&i.push({node:s,annotation:t})}),{nodes:Vf(i),renderedAnnotations:i.map(t=>t.annotation)}}(d,(e,o,n)=>function(t,e,o,n){const{scales:i,layout:r,theme:s,xAccessor:a,yAccessor:c}=o;switch(t.type){case"frame-text":return Xp(Pp,{annotation:t,width:r.width,height:r.height,defaults:{fill:s.colors.text,fontSize:11,fontFamily:s.typography.fontFamily}},"ann-frame-text-"+e);case"y-threshold":{const n=t.value??t.y;if(null==n)return null;const a=Vp(t,s),c=t.label,l=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:qp("g",{opacity:t.opacity,children:[Xp("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Xp(wp,{x:o+4,y:Gp,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Hp(t,s,"halo")})]},"ann-ythresh-"+e)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:qp("g",{children:[Xp("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),c&&Xp(wp,{x:"left"===l?4:"center"===l?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Gp):h-6,textAnchor:"left"===l?"start":"center"===l?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:c,background:Hp(t,s,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const n=t.value??t.x;if(null==n)return null;const a="horizontal"===o.projection&&i.r?i.r(n):i.x?i.x(n):null;if(null==a)return null;const c=Vp(t,s),l=t.label,u=t.labelPosition||"top";return qp("g",{opacity:t.opacity,children:[Xp("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:c,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),l&&Xp(wp,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Gp,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:c,fontFamily:s.typography.fontFamily,text:l,background:Hp(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=i.y?.domain?.(),n=t.y0??o?.[0],a=t.y1??o?.[1],c=null!=n&&i.y?i.y(n):null,l=null!=a&&i.y?i.y(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=kp(t,"ssr-band-"+e,"vertical",Vp(t,s)),f=t.fillOpacity??.1;return qp("g",{opacity:t.opacity,children:[h.def&&Xp("defs",{children:h.def}),Xp("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&Xp(wp,{x:r.width-4,y:Math.max(u,0)+Gp,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Vp(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Hp(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=i.x?.domain?.(),n=t.x0??o?.[0],a=t.x1??o?.[1],c=null!=n&&i.x?i.x(n):null,l=null!=a&&i.x?i.x(a):null;if(null==c||null==l)return null;const u=Math.min(c,l),d=Math.abs(l-c),h=kp(t,"ssr-xband-"+e,"horizontal",Vp(t,s)),f=t.fillOpacity??.1;return qp("g",{opacity:t.opacity,children:[h.def&&Xp("defs",{children:h.def}),Xp("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:f}),t.label&&Xp(wp,{x:u+4,y:Gp,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Vp(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Hp(t,s,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!i.o)return null;const n=i.o(t.category+"");if(null==n)return null;const a=i.o.bandwidth?i.o.bandwidth():40,c=Vp(t,s),l=t.opacity??.1,u=t.label;return qp("g","horizontal"===o.projection?{children:[Xp("rect",{x:0,y:n,width:r.width,height:a,fill:c,opacity:l}),u&&Xp(wp,{x:12,y:n+a/2,dominantBaseline:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Hp(t,s,"none")})]}:{children:[Xp("rect",{x:n,y:0,width:a,height:r.height,fill:c,opacity:l}),u&&Xp(wp,{x:n+a/2,y:Gp,textAnchor:"middle",fill:c,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Hp(t,s,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const o=function(t,e,o,n){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const o=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Up(t,e,o),y:Kp(t,e,n)}}(t,i,a,c),r=null==o.x||null==o.y?Qf(t,e,n):null,l=o.x??r?.x??null,u=o.y??r?.y??null;if(null==l||null==u)return null;const d="text"===t.type,h=t.dx??(d?0:30),f=t.dy??(d?0:-30),p=t.color||s.colors.text;if(!d){const o="callout"===t.type?"callout-circle":t.type,n="callout-circle"===o?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===o?{width:t.width,height:t.height}:void 0;return Xp(Bf,{noteData:{x:l,y:u,dx:h,dy:f,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...n?{subject:n}:{},connector:t.connector||{end:"arrow"},color:p,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return Xp("g",{children:Xp("text",{x:l+h,y:u+f,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||s.typography.labelSize,fill:p,fontFamily:s.typography.fontFamily,fontWeight:t.fontWeight,opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:t.label||t.title})},"ann-label-"+e)}default:return null}}(e,o,t,n)??function(t,e,o){switch(t.type){case"enclose":{const n=(t.coordinates||[]).map(t=>({x:Hf({...t,type:"point"},o),y:Uf({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=Lp(n),r=t.padding||10;return jp("g",{children:[Wp("circle",{cx:i.x,cy:i.y,r:i.r+r,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Wp(wp,{x:i.x,y:i.y-i.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"rect-enclose":{const n=(t.coordinates||[]).map(t=>({x:Hf({...t,type:"point"},o),y:Uf({...t,type:"point"},o)})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=t.padding||10,[r,s]=Pt(n.map(t=>t.x)),[a,c]=Pt(n.map(t=>t.y)),l=r-i,u=s+i,d=a-i;return jp("g",{children:[Wp("rect",{x:l,y:d,width:u-l,height:c+i-d,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Wp(wp,{x:(l+u)/2,y:d-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"highlight":{const n=o.data||[],i="function"==typeof t.filter?n.filter(t.filter):t.field&&null!=t.value?n.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return Wp("g",{children:i.map((e,n)=>{const i=Hf(e,o),s=Uf(e,o);if(null==i||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,c="function"==typeof t.style?t.style(e):t.style||r;return Wp("circle",{cx:i,cy:s,r:a,...c},"hl-"+n)})},"ann-"+e)}case"bracket":{const n=Hf(t,o),i=Uf(t,o);return Wp(Bf,{noteData:{x:n??0,y:i??0,dx:t.dx||0,dy:t.dy||0,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:"bracket",subject:{type:t.bracketType||"curly",width:t.width,height:t.height,depth:t.depth||30},color:t.color}},"ann-"+e)}case"trend":{const n=o.data||[];if(2>n.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s="ordinal"===o.frameType,a="horizontal"===o.projection,c=s?i:null,l=s?r:null;let u;const d=[],h=new Map;if(s&&c&&l){for(const t of n){const e=t[c];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=n.map(t=>{const e=t[c],o=t[l];if(null==e||null==o)return null;const n=h.get(e+"");return null!=n?[n,+o]:null}).filter(t=>null!==t)}else u=n.map(t=>[t[i],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const f=o.scales?.x??o.scales?.time,p=o.scales?.y??o.scales?.value;if(!f||!p)return null;const y=t=>e=>{const o=Math.max(0,Math.floor(e)),n=Math.min(d.length-1,o+1),i=e-o,r=t(d[o]);return r+(t(d[n])-r)*i},g=f,m=p;let x;if(s)if(a){const t=y(m);x=(e,o)=>[g(o),t(e)]}else{const t=y(g);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[g(t),m(e)];const b=t.method||"linear",v="loess"===b?function(t,e=.3){const o=t.length;if(2>o)return t.slice();const n=t.slice().sort((t,e)=>t[0]-e[0]),i=n.map(t=>t[0]),r=n.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=i[t],n=i.map(t=>Math.abs(t-e)),c=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,l=[];for(let t=0;o>t;t++){const e=0===c?0:n[t]/c;l[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,f=0,p=0;for(let t=0;o>t;t++){const e=l[t];0!==e&&(u+=e,d+=e*i[t],h+=e*r[t],f+=e*i[t]*i[t],p+=e*i[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const y=u*f-d*d;if(1e-12>Math.abs(y))a.push([e,h/u]);else{const t=(u*p-d*h)/y;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3):("polynomial"===b?Rt(u,t.order||2):function(t){const e=[0,0,0,0];let o=0;for(const[n,i]of t)null!==i&&(o++,e[0]+=n,e[1]+=i,e[2]+=n*n,e[3]+=n*i);const n=o*e[2]-e[0]*e[0],i=0===n?0:$t((o*e[3]-e[0]*e[1])/n),r=$t(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[$t(t),$t(i*t+r)]),equation:[i,r]}}(u)).points,w=v.map(([t,e])=>{const[o,n]=x(t,e);return`${o},${n}`}).join(" "),k=t.color||"#6366f1",A=v[v.length-1],[S,M]=x(A[0],A[1]);return jp("g",{children:[Wp("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Wp("text",{x:S+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+e)}case"envelope":{const n=o.data||[];if(2>n.length)return null;const i=o.xAccessor||"x",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",c=t.lowerAccessor||"lowerBounds",l=t.filter,u=n.filter(t=>null!=t[a]&&null!=t[c]&&(!l||l(t))).sort((t,e)=>t[i]-e[i]);if(2>u.length)return null;const d=Yp[o.curve||"linear"]||Cp,h=$p().x(t=>r(t[i])).y0(t=>s(t[c])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1",p=u[u.length-1];return jp("g",{children:[Wp("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&Wp("text",{x:r(p[i])+4,y:s(p[a])-4,fill:f,fontSize:11,children:t.label})]},"ann-"+e)}case"anomaly-band":{const n=o.data||[];if(2>n.length)return null;const i=o.yAccessor||"y",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=n.map(t=>t[i]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const c=a.reduce((t,e)=>t+e,0)/a.length,l=a.reduce((t,e)=>t+(e-c)**2,0)/a.length,u=Math.sqrt(l),d=t.threshold??2,h=c-d*u,f=s(c+d*u),p=s(h),y=t.fill||"#6366f1",g=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=n.filter(t=>{const e=t[i];return null!=e&&Math.abs(e-c)>d*u});return jp("g",{children:[!1!==t.showBand&&Wp("rect",{x:0,y:Math.min(f,p),width:o.width||0,height:Math.abs(p-f),fill:y,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const n=Hf(t,o),i=Uf(t,o);return null==n||null==i?null:Wp("circle",{cx:n,cy:i,r:m,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Wp("text",{x:(o.width||0)-4,y:Math.min(f,p)-4,textAnchor:"end",fill:y,fontSize:11,children:t.label})]},"ann-"+e)}case"forecast":{const n=o.data||[];if(3>n.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s=o.scales?.x??o.scales?.time,a=o.scales?.y??o.scales?.value;if(!s||!a)return null;const c=n.map(t=>[t[i],t[r]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]);if(3>c.length)return null;let l;if("polynomial"===t.method){const e=Rt(c,t.order||2).equation;l=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=Tt(c);if(!t)return null;l=t}const{se:u,meanX:d,ssX:h}=It(c,l),f=c.length,p=Ct(t.confidence??.95),y=c[f-1][0],g=(y-c[0][0])/Math.max(f-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=y+(e+1)*g,n=l(o),i=u*Math.sqrt(1+1/f+(h>0?(o-d)**2/h:0))*p;return{x:o,center:n,upper:n+i,lower:n-i}}),x=m.map(t=>`${s(t.x)},${a(t.upper)}`).join(" L"),b=m.slice().reverse().map(t=>`${s(t.x)},${a(t.lower)}`).join(" L"),v=m.map(t=>`${s(t.x)},${a(t.center)}`).join(" "),w=t.strokeColor||"#6366f1",k=m[m.length-1];return jp("g",{children:[Wp("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Wp("polyline",{points:`${s(y)},${a(l(y))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&Wp("text",{x:s(k.x)+4,y:a(k.center)-4,fill:w,fontSize:11,children:t.label})]},"ann-"+e)}case"widget":{let n,i;if(null!=t.px&&null!=t.py)n=t.px,i=t.py;else{const r=Qf(t,e,o);if(!r)return null;n=r.x,i=r.y}if(!function(t,e,o,n=50){return!(-n>t||t>(o.width||0)+n||-n>e||e>(o.height||0)+n)}(n,i,o))return null;const r=t.width??32,s=t.height??32,a=t.content??Wp("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Wp("foreignObject",{x:n+(t.dx??0)-r/2,y:i+(t.dy??0)-s/2,width:r,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:Wp("div",{...Bp(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,n),t.svgAnnotationRules,u),f=h.nodes,p=new Map;for(const t of h.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";p.set(e,(p.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=p.get(e)??0;o>0?p.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:d.length,renderedCount:h.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?Xp("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}import{jsx as Qp}from"react/jsx-runtime";function Jp(t,e,o,n="right",i,r){if(null==t||!1===t)return null;const{x:s,y:a}=we(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:n,legendLayout:i,axisChrome:r});return Qp("g",{transform:`translate(${s}, ${a})`,children:t})}import*as ty from"react";function ey(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function oy(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function ny(t){if(0===t.length)return{min:null,max:null};let e=1/0,o=-1/0;for(const n of t)e>n.pixel&&(e=n.pixel),n.pixel>o&&(o=n.pixel);return{min:e,max:o}}function iy(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function ry(t,e){return t&&"string"!=typeof t?{stroke:t.stroke??e.stroke,strokeWidth:t.strokeWidth??e.strokeWidth,...null!=t.strokeOpacity&&{strokeOpacity:t.strokeOpacity},...t.strokeDasharray&&{strokeDasharray:t.strokeDasharray}}:{...e,..."string"==typeof t&&{strokeDasharray:iy(t)}}}function sy(t,e,o){if("left"===t||"right"===t){const n="left"===t?o:0,i="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+n;for(let t=0;r>t;t++){const o=8*(t+1);s+=`L${Math.min(8*t+4,e)},${n+4*i}`,s+=`L${Math.min(o,e)},${n}`}return s}const n="bottom"===t?0:e,i="bottom"===t?1:-1,r=Math.ceil(o/8);let s=`M${n},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${n+4*i},${Math.min(8*t+4,o)}`,s+=`L${n},${Math.min(e,o)}`}return s}function ay(t,e){return t?.ticks??t?.tickCount??e}function cy(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function ly(t,e,o){return"exact"===o?function(t,e){const o=t.domain(),n=o[0],i=o[o.length-1],r=n instanceof Date,s=n instanceof Date?n.getTime():n,a=i instanceof Date?i.getTime():i;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const c=(a-s)/(e-1),l=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*c;l[t]=r?new Date(o):o}return l}(t,e):t.ticks(e)}import{jsx as uy}from"react/jsx-runtime";function dy(t){return"string"==typeof t||"number"==typeof t}function hy(t){const{label:e,x:o,y:n,textAlign:i,fontSize:r,fontFamily:s,color:a}=t;return uy("foreignObject",{x:o,y:n,width:60,height:24,style:{overflow:"visible"},children:uy("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:i,userSelect:"none"},children:e})})}function fy(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function py(t){const{values:e,scale:o,format:n}=t,i=e.map(t=>t.valueOf());return e.map((t,e)=>({value:t,pixel:o(t),label:n(t,e,i)}))}function yy(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function gy(t){const{candidates:e,scale:o,minPixelDistance:n,includeMax:i,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:c=!0,format:l}=t;let u=function(t,e){if(2>=t.length)return t;const o=[t[0]];for(let n=1;t.length-1>n;n++)e>Math.abs(t[n].pixel-o[o.length-1].pixel)||o.push(t[n]);const n=t[t.length-1];return e>Math.abs(n.pixel-o[o.length-1].pixel)?o[o.length-1]=n:o.push(n),o}(e,n);if(a&&u.length>1&&(u=u.filter((t,e)=>{return 0===e||(n=u[e-1].label,!!("string"!=typeof(o=t.label)&&"number"!=typeof o||"string"!=typeof n&&"number"!=typeof n||o+""!=n+""));var o,n})),!c||!i||0===u.length||"exact"===r||s)return u;const d=o.domain(),h=d[d.length-1];if(null==h)return u;const f=o(h),p=u[u.length-1].pixel;if(1>=Math.abs(f-p))return u;const y=e.map(t=>t.value.valueOf()),g={value:h,pixel:f,label:l(h,u.length,y)};return n>Math.abs(f-p)&&u.length>1&&(u=u.slice(0,-1)),[...u,g]}function my(t,e,o,n){return!!t&&("function"==typeof t?t(e.value,o):function(t,e){const o=fy(t);if(!o)return!1;const n=fy(e);return!n||o.getFullYear()!==n.getFullYear()||o.getMonth()!==n.getMonth()}(e.value,o>0?n[o-1].value:void 0))}import{jsx as xy,jsxs as by}from"react/jsx-runtime";function vy(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function wy(t){const e=t._idPrefix||t.chartId;if(e){const t=(e+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(t)?t:"c"+t}const o=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let n=0;for(let t=0;o.length>t;t++)n=31*n+o.charCodeAt(t)|0;return"c"+(n>>>0).toString(36)}function ky(t,e,o){return ne(t.showLegend&&!t.__legendIncludesAutomatic?Sf(e,t.colorScheme,o):void 0,t.legend)}var Ay={right:110,left:110,top:50,bottom:80};function Sy(t,e){if(t.__autoLegendMargin)return Ay[e]}function My(t,e){const o={theme:e.theme,position:e.position||"right",totalWidth:e.size[0],totalHeight:e.size[1],margin:e.margin,hasTitle:e.hasTitle,legendLayout:e.legendLayout,idPrefix:e.idPrefix,reservedWidth:e.reservedWidth,axisChrome:e.axisChrome,legendDistance:ie(t)||re(t)?t.legendDistance:void 0};return ie(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,o)=>({group:t,item:e,itemIndex:o,label:e.label})))).length)return null;var e;const o=function(t){const{legendGroups:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:c,rowHeight:l}=ke(s),u=a+c,d=Math.max(12,_f(o)),h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??f),i=Mf(s?.align);let r=0,c=0;const l=[];for(const i of e){const e=i.items.map(t=>t.label),u=Rf({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,f=i.label?$f(i.label,0,0,o):0,p=h>0?h+8:0,y=p+u.width,g=Math.max(u.height,f);l.push({group:i,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:y,height:g,items:u.items}),r+=y+12,c=Math.max(c,g)}const h=l.length>0?r-12:0,p=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:l.map(t=>({...t,x:t.x+p})),width:h,height:c,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Ae(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),l);let y=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>$f(t.label,a,c,o)),i=Math.max(0,...n,t.label?$f(t.label,0,0,o):0);return y=Math.max(y,i),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*l,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*l}))}}),width:y,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}(t),n="top"===t.position||"bottom"===t.position,i={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??de(i,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:c}=we(i,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:r});if(!n){const e=Ae(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)),n=t.legendGroups.flatMap((n,i)=>{const s=e[i],a=n.type??"fill",c=[wf("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=s.labelY&&c.push(wf("text",{y:s.labelY,fontSize:_f(t.theme),fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:n.label},"legend-group-label-"+i)),c.push(wf("g",{transform:`translate(0,${s.itemsY})`,children:n.items.map((e,r)=>{const s=n.styleFn(e,r),c="function"==typeof a?a(e):"line"===a?wf("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):wf("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return kf("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[c,wf("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:_f(t.theme),fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),c});return wf("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,"data-orientation":"vertical",fontWeight:Lf(t.theme),children:n})}const l=o.groups.flatMap((e,i)=>{const{group:r}=e,a=r.type??"fill",c=[];if(r.label&&c.push(wf("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:_f(t.theme),fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:r.label}:{x:e.x,y:e.y+_f(t.theme),fontSize:_f(t.theme),fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:r.label},"legend-group-label-"+i)),c.push(...e.items.map((n,s)=>{const c=r.items[s],l=r.styleFn(c,s),u="function"==typeof a?a(c):"line"===a?wf("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:l}):wf("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:l});return kf("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,wf("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:_f(t.theme),fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:n.category})]},`legend-${i}-${s}`)})),n&&o.groups.length-1>i){const t=e.x+e.width+6;c.push(wf("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+i))}return c});return wf("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,"data-orientation":n?"horizontal":"vertical",fontWeight:Lf(t.theme),children:l})}({...o,legendGroups:t.legendGroups}):re(t)?function(t){const e=function(t){const e="top"===t.position||"bottom"===t.position,o=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??o,200),height:t.gradient.label?46:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?126:108,swatchSize:14}}(t),o="top"===t.position||"bottom"===t.position,n={gradient:t.gradient,legendDistance:t.legendDistance},i=de(n),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:c}=we(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:i}),l=Array.from({length:17},(e,n)=>{const i=n/16;return wf("stop",{offset:100*i+"%",stopColor:t.gradient.colorFn(o?t.gradient.domain[0]+i*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-i*(t.gradient.domain[1]-t.gradient.domain[0]))},n)});if(o){const o=12,n=t.gradient.label?12:void 0,i=t.gradient.label?18:0;return kf("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,fontWeight:Lf(t.theme),children:[wf("defs",{children:wf("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:l})}),t.gradient.label&&wf("text",{x:e.width/2,y:n,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:t.gradient.label}),wf("rect",{x:0,y:i,width:e.width,height:o,fill:`url(#${r})`,rx:2}),wf("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Pf(t.theme),children:s(t.gradient.domain[0])}),wf("text",{x:e.width,y:i+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Pf(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?12:void 0,d=t.gradient.label?18:0;return kf("g",{className:"semiotic-legend",transform:`translate(${a},${c})`,fontWeight:Lf(t.theme),children:[wf("defs",{children:wf("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:l})}),t.gradient.label&&wf("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:Pf(t.theme),children:t.gradient.label}),wf("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),wf("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Pf(t.theme),children:s(t.gradient.domain[1])}),wf("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Pf(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function _y(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",c={...t},l={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:Sy(o,a)};if(null!=o.legend){const e=ky(o,n,i);null!=e&&!1!==e&&function(t,e){ve(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...l,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";ve(t,{legend:Sf(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...l,categories:n,colorScheme:o.colorScheme});return le(t,c,r,a),a}function Py(t){const{props:e,categories:o,theme:n,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",c={theme:n,position:a,size:i,margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix};if(null!=e.legend){const t=ky(e,o,n);if(ty.isValidElement(t))return Jp(t,i,r,a,e.legendLayout,e.axisChrome);return My(t,c)||(ie(t)||re(t)?null:Jp(t??null,i,r,a,e.legendLayout,e.axisChrome))}return e.showLegend&&0!==o.length?function(t){const{categories:e,colorScheme:o,theme:n,position:i="right",totalWidth:r,totalHeight:s,margin:a}=t;if(!e||0===e.length)return null;const c=Af(e,o,n),l="top"===i||"bottom"===i,u=Rf(t),d={...Sf(e,o,n),legendDistance:t.legendDistance},h=t.reservedWidth??de(d,t.legendLayout),{x:f,y:p}=we(d,{totalWidth:r,totalHeight:s,margin:a,position:i,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(l){const t=u.items.map((t,e)=>kf("g",{transform:`translate(${t.x},${t.y})`,children:[wf("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(t.category),rx:u.swatchRadius}),wf("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:_f(n),fill:n.colors.text,fontFamily:Pf(n),children:t.category})]},"legend-"+e));return wf("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:Lf(n),children:t})}const y=Ae([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],g=u.items.map((t,e)=>kf("g",{transform:`translate(${t.x},${t.y+y.itemsY})`,children:[wf("rect",{width:u.swatchSize,height:u.swatchSize,fill:c(t.category),rx:u.swatchRadius}),wf("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:_f(n),fill:n.colors.text,fontFamily:Pf(n),children:t.category})]},"legend-"+e));return kf("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:Lf(n),children:[wf("line",{x1:0,y1:y.lineY,x2:h,y2:y.lineY,stroke:"gray"}),g]})}({categories:o,colorScheme:e.colorScheme,theme:n,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix}):null}var Ly=cy;function $y(t,e){const o=Mt(e.theme),n=e.background??o.background,i=e.idPrefix?e.idPrefix+"-":"",r="string"==typeof e.title?e.title:void 0,s=r?i+"semiotic-title":void 0,a=e.description?i+"semiotic-desc":void 0,c=[s,a].filter(Boolean).join(" ")||void 0;return by("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":c,style:{fontFamily:o.fontFamily},children:[r&&xy("title",{id:s,children:r}),e.description&&xy("desc",{id:a,children:e.description}),e.defs&&xy("defs",{children:e.defs}),n&&"transparent"!==n&&xy("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),xy("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&xy("text",{id:i+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:o.titleFontSize,fontWeight:o.titleFontWeight,fill:o.text,fontFamily:o.titleFontFamily,children:r}),e.legend&&xy("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{jsx as Ry,jsxs as Ty}from"react/jsx-runtime";function Iy(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}var Cy={top:50,right:40,bottom:60,left:70},Oy={top:20,right:80,bottom:20,left:80},Fy={top:40,right:40,bottom:40,left:40},Dy=new Set(["chord","force","circlepack","orbit"]);import{jsx as zy,jsxs as Ny}from"react/jsx-runtime";import{Fragment as Ey,jsx as By,jsxs as Wy}from"react/jsx-runtime";function jy(t,e){const o=St(t.theme),n=t.size||[500,300],i=ce({...Cy,...t.margin},t.title),r=se(t.title),s=function(t,e){if(!e||0===t.length)return t;if(!t.some(t=>null!=t&&"object"==typeof t&&Array.isArray(t[e])))return t;const o=[];for(const n of t){if(null==n||"object"!=typeof n)continue;const t=n[e];if(!Array.isArray(t))continue;const i=n.label??n.id??n.key;for(const e of t)null!=e&&"object"==typeof e&&o.push(null==i?e:{...e,_lineGroup:i})}return o}(g(t.data),t.lineDataAccessor),a=t.showLegend?Tf(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],c=function(t){const e=t.axes?.find(t=>"bottom"===t.orient),o=t.axes?.find(t=>"top"===t.orient),n=t.axes?.find(t=>"left"===t.orient),i=t.axes?.find(t=>"right"===t.orient),r=!o||!!e,s=!!o&&!e,a=!i||!!n,c=!!i,l=!1!==t.showAxes;return{hasAxis:l&&r,hasAxisLabel:l&&r&&!!(e?.label??t.xLabel),rotatedTicks:l&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:l,hasAxisLabel:l&&!!(o?.label??t.xLabel),rotatedTicks:l&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:l,hasAxisLabel:l&&!!(n?.label??t.yLabel)}:void 0,rightAxis:c?{hasAxis:l,hasAxisLabel:l&&!!(i?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});_y(i,{props:{...t,axisChrome:c},categories:a,theme:o,size:n,hasTitle:r});const l=Py({props:{...t,axisChrome:c},categories:a,theme:o,size:n,margin:i,hasTitle:r}),u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),f=t.colorScheme||o.colors.categorical,p=(t.axes?.find(t=>"left"===t.orient)??t.axes?.find(t=>"right"===t.orient))?.extent??t.axisExtent,y={chartType:t.chartType,runtimeMode:h?"streaming":"bounded",windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:h?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:t.xAccessor,yAccessor:t.yAccessor,timeAccessor:h?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor||(t.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,yAxisExtent:p,sizeRange:t.sizeRange,xScaleType:t.xScaleType,yScaleType:t.yScaleType,scalePadding:t.scalePadding,binSize:t.binSize,normalize:t.normalize,baseline:t.baseline,stackOrder:t.stackOrder,boundsAccessor:t.boundsAccessor,boundsStyle:t.boundsStyle,band:t.band,y0Accessor:t.y0Accessor,areaGroups:t.areaGroups?t.areaGroups instanceof Set?t.areaGroups:new Set(t.areaGroups):void 0,curve:t.curve,gradientFill:dt(t.gradientFill),lineGradient:ht(t.lineGradient),semanticLineStops:t.semanticLineStops,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:f,themeCategorical:o.colors.categorical,themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging,themeSemantic:kt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat,heatmapColorScale:t.heatmapColorScale,heatmapAggregation:t.heatmapAggregation,heatmapXBins:t.heatmapXBins,heatmapYBins:t.heatmapYBins,pointIdAccessor:t.pointIdAccessor,onLayoutError:t.onLayoutError},m=new id(y);t.data&&m.ingest({inserts:s,bounded:!0}),m.computeScene({width:u,height:d});const x=Iy(t.backgroundGraphics,n,i,m.scales),b=Iy(t.foregroundGraphics,n,i,m.scales);if(!m.scales){let r;const a=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Fh({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:m.scales?[]:["NO_SCALES"],margin:i})),Dl.renderToStaticMarkup($y(x||b||t.annotations?Wy(Ey,{children:[x,a,b]}):null,{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}const v=t._idPrefix,w=bf({nodes:m.scene,renderMode:t.renderMode,fallback:(e,o)=>gf(e,o,v,t.hoverRadius??30)}),k=t.showGrid?function(t,e,o,n,i,r,s){const{grid:a}=Mt(o),c=n?n+"-":"",l=r?.find(t=>"bottom"===t.orient),u=r?.find(t=>"top"===t.orient),d=r?.find(t=>"left"===t.orient),h=r?.find(t=>"right"===t.orient),f=l??u,p=d??h,y=f?.extent??i,g=p?.extent??i,m="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=f?.tickValues??ly(t.x,ay(f,m),y),v=f?.tickFormat||s?.xFormat||s?.tickFormatTime||cy,w=py({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,yy(e.label)),0),A=gy({candidates:w,scale:t.x,minPixelDistance:f?.autoRotate?Math.max(20,Math.min(k+8,55)):Math.max(55,k+8),includeMax:f?.includeMax,extentMode:y,hasExplicitTickValues:!!f?.tickValues,format:v}),S=p?.tickValues??ly(t.y,ay(p,x),g),M=p?.tickFormat||s?.yFormat||s?.tickFormatValue||cy,_=t=>M(t),P=gy({candidates:py({values:S,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:p?.includeMax,extentMode:g,hasExplicitTickValues:!!p?.tickValues,format:_}),L=!1!==f?.grid,$=!1!==p?.grid,R=iy(f?.gridStyle),T=iy(p?.gridStyle),I=ry(f?.gridStyle,{stroke:a,strokeWidth:.5}),C=ry(p?.gridStyle,{stroke:a,strokeWidth:.5});return Ty("g",{id:c+"grid",className:"semiotic-grid",opacity:.8,children:[L&&A.map((t,o)=>Ry("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...I,strokeDasharray:R??I.strokeDasharray},"gx-"+o)),$&&P.map((t,o)=>Ry("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...C,strokeDasharray:T??C.strokeDasharray},"gy-"+o))]})}(m.scales,{width:u,height:d},o,v,t.axisExtent,t.axes,t):null,A=w.map(t=>t.element),S=wy(t)+"-plot-clip",M=!1!==t.showAxes,_=M?function(t,e,o,n,i,r,s,a=!1){const c=Mt(n),l=o.legendPosition??"right",u=fe(o.legendLayout,s?.leftAxis),d=fe(o.legendLayout,s?.rightAxis),h=a&&"left"===l&&u>0?u:r?.left??o.margin?.left??40,f=a&&"right"===l&&d>0?d:r?.right??o.margin?.right??40,p=o.axes?.find(t=>"bottom"===t.orient),y=o.axes?.find(t=>"top"===t.orient),g=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=p??y,b=g??m,v=p?"bottom":y?"top":"bottom",w=g?"left":m?"right":"left",k="top"===v?0:e.height,A="right"===w?e.width:0,S="top"===v?-1:1,M="right"===w?1:-1,_=x?.extent??o.axisExtent,P=b?.extent??o.axisExtent,L="exact"===_?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),$="exact"===P?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),R=x?.tickValues??ly(t.x,ay(x,L),_),T=x?.tickFormat||o.xFormat||o.tickFormatTime||Ly,I=py({values:R,scale:t.x,format:T}),C=I.reduce((t,e)=>Math.max(t,yy(e.label)),0),O=gy({candidates:I,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(C+8,55)):Math.max(55,C+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:T}),F=b?.tickValues??ly(t.y,ay(b,$),P),D=b?.tickFormat||o.yFormat||o.tickFormatValue||Ly,z=t=>D(t),N=gy({candidates:py({values:F,scale:t.y,format:z}),scale:t.y,minPixelDistance:22,includeMax:b?.includeMax,extentMode:P,hasExplicitTickValues:!!b?.tickValues,format:z}),E=!!(x?.autoRotate&&O.length>1&&e.width/Math.max(O.length-1,1)<O.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),B=ny(O),W=ny(N),j=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),X=ry(x?.axisStyle,{stroke:c.border,strokeWidth:1}),q=ry(b?.axisStyle,{stroke:c.border,strokeWidth:1}),G="right"===w?e.width+f-15:15-h;return by("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&xy("line",{x1:0,y1:k,x2:e.width,y2:k,...X}),x?.jaggedBase&&xy("path",{d:sy(v,e.width,e.height),fill:"none",...X}),O.map((t,e)=>{const o=my(x?.landmarkTicks,t,e,O);return by("g",{transform:`translate(${t.pixel},${k})`,children:[xy("line",{y2:5*S,...X}),dy(t.label)?xy("text",{y:S*(E?12:18),textAnchor:E?"end":ey(x?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,transform:E?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):hy({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"xtick-"+e)}),j&&xy("text",{x:e.width/2,y:"top"===v?-(E?58:40):e.height+(E?58:40),textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:j}),!1!==b?.baseline&&!b?.jaggedBase&&xy("line",{x1:A,y1:0,x2:A,y2:e.height,...q}),b?.jaggedBase&&xy("path",{d:sy(w,e.width,e.height),fill:"none",...q}),N.map((t,e)=>{const o=my(b?.landmarkTicks,t,e,N);return by("g",{transform:`translate(${A},${t.pixel})`,children:[xy("line",{x2:5*M,...q}),dy(t.label)?xy("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:oy(b?.tickAnchor,t.pixel===W.min,t.pixel===W.max),fontWeight:o?600:400,fontSize:o?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):hy({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"ytick-"+e)}),Y&&xy("text",{x:G,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${G}, ${e.height/2})`,children:Y})]})}(m.scales,{width:u,height:d},t,o,v,i,c,!!l):null,P=M?function(t){const{scales:e,layout:o,props:n,theme:i,leftAxis:r,rightAxis:s,margin:a,axisChrome:c,hasRenderedLegend:l}=t;if(!r||!s)return null;const u=Mt(i),d=s.extent??n.axisExtent,h="exact"===d?Math.max(2,ay(s,5)):Math.min(ay(s,5),Math.max(2,Math.floor(o.height/30))),f=s.tickValues??ly(e.y,h,d),p=s.tickFormat||n.yFormat||n.tickFormatValue||cy,y=t=>p(t),g=gy({candidates:py({values:f,scale:e.y,format:y}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:y}),m=ny(g),x=s.label??n.yLabelRight,b=ry(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=n.legendPosition??"right",w=fe(n.legendLayout,c?.rightAxis),k=o.width+(l&&"right"===v&&w>0?w:a.right)-15;return Ny("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&zy("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&zy("path",{d:sy("right",o.width,o.height),fill:"none",...b}),g.map((t,e)=>{const n=my(s.landmarkTicks,t,e,g);return Ny("g",{transform:`translate(${o.width},${t.pixel})`,children:[zy("line",{x2:5,...b}),dy(t.label)?zy("text",{x:8,textAnchor:"start",dominantBaseline:oy(s.tickAnchor,t.pixel===m.min,t.pixel===m.max),fontWeight:n?600:400,fontSize:n?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:t.label}):hy({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&zy("text",{x:k,y:o.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${k}, ${o.height/2})`,children:x})]})}({scales:m.scales,layout:{width:u,height:d},props:t,theme:o,leftAxis:t.axes?.find(t=>"left"===t.orient),rightAxis:t.axes?.find(t=>"right"===t.orient),margin:i,axisChrome:c,hasRenderedLegend:!!l}):null;let L;const $=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:m.scales.x,y:m.scales.y},layout:{width:u,height:d},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:v,onRender:t=>{L=t}}):null;e&&(e.evidence=Fh({frameType:"xy",width:n[0],height:n[1],marks:w.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:L,xDomain:Oh(m.scales.x?.domain?.()),yDomain:Oh(m.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const R=t.svgPreRenderers&&m.scales?t.svgPreRenderers.map((t,e)=>{try{return By(Fl.Fragment,{children:t(m.scene,m.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Dl.renderToStaticMarkup($y(Wy(Ey,{children:[x,R,k,By("defs",{children:By("clipPath",{id:S,children:By("rect",{x:0,y:0,width:u,height:d})})}),By("g",{clipPath:`url(#${S})`,children:A}),_,P,$,b,m.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}Th();import*as Yy from"react-dom/server";import{jsx as Xy,jsxs as qy}from"react/jsx-runtime";function Gy({machine:t,layout:e,runtime:o,downstreamSet:n,selectedSet:i,width:r,height:s,seed:a,reduced:c,onSelectTask:l}){const u=e.tasks.length?Math.min(...e.tasks.map(t=>t.y-t.height/2)):60,d=Math.max(20,u-12),h=Math.max(26,u-6);return qy("svg",{"aria-hidden":"true",width:r,height:s,viewBox:`0 0 ${r} ${s}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Xy("defs",{children:Xy("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Xy("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),t.lanes.map((t,o)=>{const n=e.tasks.filter(t=>t.laneIndex===o),i=n[0]?.x??0;return qy("g",{children:[Xy("line",{x1:i,x2:i,y1:h,y2:s-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Xy("text",{x:i,y:d,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:t})]},t)}),e.routes.map(t=>{const e=o.delivered.has(t.edgeID),i=o.inFlight.has(t.edgeID),r=n.has(t.targetID)||n.has(t.sourceID),s=t.points.map(t=>`${t.x},${t.y}`).join(" ");return Xy("polyline",{points:s,fill:"none",stroke:r?"var(--semiotic-selection-color, #e08a1e)":e?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:r?4:i?3:2,strokeOpacity:e||i||r?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},t.edgeID)}),e.sockets.map(t=>{const e=o.delivered.has(t.edgeID);return qy("g",{children:[Xy("circle",{cx:t.x,cy:t.y,r:t.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),e&&Xy("circle",{cx:t.x,cy:t.y,r:t.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},t.id)}),t.nodes.map(t=>{const r=e.taskByID.get(t.id);if(!r)return null;const s=o.completed.has(t.id),u=o.blockers.has(t.id),d=o.previewTaskID===t.id,h=i.has(t.id)||d,f=n.has(t.id),p=function(t,e){return e.completed.has(t.id)?"var(--semiotic-success, #2b8a66)":e.blockers.has(t.id)?"var(--semiotic-error, #c64035)":"in-progress"===t.status?"var(--semiotic-warning, #d18a22)":e.armed.has(t.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(t,o),y=r.x-r.width/2,g=r.y-r.height/2,m=Math.max(2,r.height*t.progress);return qy("g",{children:[qy("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:[Xy("rect",{x:y,y:g,width:r.width,height:r.height,rx:t.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:h||f?"var(--semiotic-selection-color, #e08a1e)":p,strokeWidth:h?4:f?3:2}),Xy("rect",{x:y+3,y:g+r.height-m+1,width:r.width-6,height:Math.max(0,m-4),rx:2,fill:p,opacity:s?.86:.46})]}),u&&qy("g",{opacity:d?.28:1,children:[Xy("line",{x1:y-8,x2:y+14,y1:r.y+9,y2:r.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Xy("circle",{cx:y-8,cy:r.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),qy("g",{onPointerDown:()=>l(t.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Xy("rect",{x:y,y:g,width:r.width,height:r.height,fill:"transparent"}),Xy("text",{x:r.x,y:r.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:t.label.length>24?t.label.slice(0,22)+"…":t.label}),qy("text",{x:r.x,y:r.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*t.progress),"% · ",s?"done":u?"blocked":o.armed.has(t.id)?"ready":"waiting"]})]})]},t.id)})]})}function Vy(t,e=0){if(t instanceof Date)return t.getTime();const o=Number(t);return Number.isFinite(o)?o:e}function Hy(t){if(null==t.completionTime)return null;const e=Vy(t.completionTime,NaN);return Number.isFinite(e)?e:null}function Uy(t,e,o,n){const i=new Set;for(const r of t.nodes){const s=t.incoming.get(r.id)??[];(n.has(r.id)||!o.has(r.id)&&s.every(t=>e.has(t.id)))&&i.add(r.id)}return i}function Ky(t,e,o={}){const n=new Set,i=[...t.get(e)??[]];for(let e=0;i.length>e;e++){const o=i[e];n.has(o)||(n.add(o),i.push(...t.get(o)??[]))}return o.includeStart&&n.add(e),n}function Zy(t,e,o){return function(t,e,o){if(null!=t)return"function"==typeof t?t(e,o):"object"==typeof t&&null!==t&&"constant"in t?t.constant:e[t]}(o,t,e)}function Qy(t,e){return e>t?-1:t>e?1:0}function Jy(t,e){return`dependency:${encodeURIComponent(t)}:${encodeURIComponent(e)}`}function tg(t,e){return`socket:${encodeURIComponent(t)}:${e}`}function eg(t){const e=Number(t);return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function og(t,e,o={}){const n=new Set(o.completedTaskIDs??[]),i=[...Ky(function(t,e){const o=new Map;for(const e of t)o.set(e.id,new Set);for(const t of e)o.has(t.source)||o.set(t.source,new Set),o.has(t.target)||o.set(t.target,new Set),o.get(t.source).add(t.target);return o}(t.nodes,t.edges.map(t=>({source:t.sourceID,target:t.targetID}))),e)].map(e=>t.byID.get(e)).filter(t=>null!=t).filter(t=>!(o.isComplete?o.isComplete(t):n.has(t.id)||"done"===t.status)).sort((t,e)=>t.index-e.index),r=Array.from(new Set(i.map(t=>t.lane)));return{blockerID:e,downstreamTaskCount:i.length,affectedLaneCount:r.length,downstreamTaskIDs:i.map(t=>t.id),affectedLanes:r}}import{jsx as ng,jsxs as ig}from"react/jsx-runtime";import{jsx as rg,jsxs as sg}from"react/jsx-runtime";var ag={top:4,bottom:4,left:4,right:4};function cg(t,e,o,n,i){return{__composite:{data:t,colorBy:e,colorScheme:o,common:n,rest:i}}}function lg(t){return t.__composite}function ug(t,e){return"number"==typeof t&&Number.isFinite(t)?t:e}function dg(t,e){return Math.max(1,Math.floor(ug(t,e)))}function hg(t,e,o,n){return t.replace(/^<svg\b/,`<svg x="${e}" y="${o}" data-semiotic-composite-part="${n}"`)}function fg(t,e){for(const o of t){const t=o?.[e];if(Array.isArray(t)&&2===t.length&&"number"==typeof t[0]&&"number"==typeof t[1])return t}}var pg={frameType:"xy",buildProps:cg,renderStatic:function(t,e){const{data:o,colorBy:n,colorScheme:i,common:r,rest:s}=lg(t),[a,c]=r.size??[600,400],l=s.minimap&&"object"==typeof s.minimap?s.minimap:{},u=ug(l.height,60),d=r.margin,h=l.margin&&"object"==typeof l.margin?l.margin:{},f={top:ug(h.top,0),right:ug(h.right,ug(d?.right,20)),bottom:ug(h.bottom,20),left:ug(h.left,ug(d?.left,40))},p=u+f.top+f.bottom,y=s.frameProps&&"object"==typeof s.frameProps?s.frameProps:{},g={...r,size:[a,c],xExtent:y.xExtent??s.brushExtent??r.xExtent,yExtent:y.yExtent??s.yExtent??r.yExtent,_idPrefix:(r._idPrefix??"minimap")+"-detail"},m=Ve.buildProps(o,n,i,g,s);Object.assign(m,y);const x={...r,size:[a,p],margin:f,title:void 0,description:(r.description??r.title??"Chart")+" overview minimap",showAxes:l.showAxes??!1,showLegend:!1,showGrid:!1,accessibleTable:!1,background:l.background,xExtent:void 0,yExtent:s.yExtent??r.yExtent,_idPrefix:(r._idPrefix??"minimap")+"-overview"};delete x.lineStyle,delete x.pointStyle;const b={...s,fillArea:!1,lineWidth:1,showPoints:!1,directLabel:!1,forecast:void 0,anomaly:void 0,band:void 0},v=Ve.buildProps(o,n,i,x,b);v.chartType=s.fillArea?"area":"line","function"==typeof l.lineStyle&&(v.lineStyle=l.lineStyle);const w={},k={},A=jy(m,w),S=jy(v,k),M=!0===s.renderBefore,_=M?0:c,P=""+hg(A,0,M?p:0,"detail")+hg(S,0,_,"overview"),L=c+p,$=Mt(St(r.theme)),R="string"==typeof r.title?r.title:void 0,T="string"==typeof r.description?r.description:R||"Chart with overview minimap",I=wy(r),C=R?I+"-title":void 0,O=I+"-description",F="y"===l.brushDirection?"y":"x",D=Array.isArray(s.brushExtent)&&s.brushExtent.length>=2?[Number(s.brushExtent[0]),Number(s.brushExtent[1])]:null,z=k.evidence;let N=null;if(D&&D.every(Number.isFinite)&&z){const t="x"===F?z.xDomain:z.yDomain;if(t&&t[0]!==t[1]){const e=Math.max(0,a-f.left-f.right),o=u,n=e=>(e-t[0])/(t[1]-t[0]);if("x"===F){const t=n(Math.min(...D))*e,i=n(Math.max(...D))*e;N=rg("rect",{className:"selection",x:f.left+t,y:_+f.top,width:i-t,height:o,fill:"steelblue",fillOpacity:.2,stroke:"steelblue",strokeWidth:1})}else{const t=(1-n(Math.max(...D)))*o,i=(1-n(Math.min(...D)))*o;N=rg("rect",{className:"selection",x:f.left,y:_+f.top+t,width:e,height:i-t,fill:"steelblue",fillOpacity:.2,stroke:"steelblue",strokeWidth:1})}}}const E=Ol.renderToStaticMarkup(sg("svg",{xmlns:"http://www.w3.org/2000/svg",className:"minimap-chart",width:a,height:L,role:"img","aria-labelledby":[C,O].filter(Boolean).join(" "),style:{fontFamily:$.fontFamily},children:[R&&rg("title",{id:C,children:R}),rg("desc",{id:O,children:T}),rg("g",{dangerouslySetInnerHTML:{__html:P}}),N]}));if(e){const t=[w.evidence,k.evidence];e.evidence=Ih({frameType:"xy",width:a,height:L,parts:t,title:R,description:T,xDomain:fg(t,"xDomain"),yDomain:fg(t,"yDomain")})}return E}};function yg(t,e){return("function"==typeof e?e(t):t[e])+""}var gg={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,o,n,i)=>({chartType:"line",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||e,colorAccessor:e,...n,showAxes:!1,margin:n.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:Be,LineChart:Ve,AreaChart:Ue,DifferenceChart:Ke,StackedAreaChart:Ze,Scatterplot:Xt,CandlestickChart:Qe,BubbleChart:qt,ConnectedScatterplot:to,QuadrantChart:Je,Heatmap:oo,WaterfallChart:Xe,MultiAxisLineChart:Ye,MinimapChart:pg,ScatterplotMatrix:{frameType:"xy",buildProps:cg,renderStatic:function(t,e){const{data:o,colorBy:n,colorScheme:i,common:r,rest:s}=lg(t),a=Array.isArray(c=o)?c.filter(t=>null!=t&&"object"==typeof t&&!Array.isArray(t)):[];var c;const l=Array.isArray(s.fields)?s.fields.filter(t=>"string"==typeof t):[],u=s.fieldLabels&&"object"==typeof s.fieldLabels?s.fieldLabels:{},d=dg(s.cellSize,150),h=Math.max(0,ug(s.cellGap,4)),f=Math.max(0,ug(s.pointRadius,2)),p=Math.max(0,Math.min(1,ug(s.pointOpacity,.5))),y=dg(s.histogramBins,20),g="string"==typeof s.diagonal?s.diagonal:"histogram",m=40+l.length*d+l.length*h,x=l.length*d+40+l.length*h,b=St(r.theme),v=Mt(b),w=function(t,e,o,n){if(!e)return{categories:[],color:()=>q};const i=Array.from(new Set(t.map(t=>yg(t,e)))),r="string"==typeof e?e:"__semioticSplomColor",s=Q("function"==typeof e?t.map(t=>({...t,[r]:yg(t,e)})):t,r,o??n.colors.categorical);return{categories:i,color:t=>K(t,e,s)}}(a,n,i,b),k="string"==typeof r.title?r.title:void 0,A="string"==typeof r.description?r.description:`Scatterplot matrix comparing ${l.length} fields`,S=k?28:0,M=s.showLegend??n?w.categories:[];let _=0,P=0;const L=M.map(t=>{const e=(t=>Math.max(72,30+7*t.length))(t);_>0&&_+e>m&&(P+=1,_=0);const o={label:t,x:_,y:24*P};return _+=e,o}),$=S+(M.length?24*(P+1)+4:0),R=$+x,T=[],I=[];let C=0;l.forEach((t,e)=>{l.forEach((o,i)=>{const s=40+h+i*(d+h),c=$+e*(d+h);if(e===i){const e=function(t){const{data:e,field:o,label:n,cellSize:i,bins:r,diagonal:s,colorBy:a,color:c,x:l,y:u}=t;if("label"===s)return{visibleBars:0,svg:Ol.renderToStaticMarkup(rg("svg",{x:l,y:u,width:i,height:i,"data-semiotic-composite-part":"diagonal-"+o,children:rg("text",{x:i/2,y:i/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333",children:n})}))};const d=e.map(t=>Number(t[o])).filter(Number.isFinite),h=d.length?Math.min(...d):0,f=((d.length?Math.max(...d):0)-h)/r||1,p=Array.from({length:r},()=>new Map);for(const t of e){const e=Number(t[o]);if(!Number.isFinite(e))continue;const n=Math.max(0,Math.min(r-1,Math.floor((e-h)/f))),i=a?yg(t,a):"__all",s=p[n];s.set(i,[...s.get(i)??[],t])}const y=p.map(t=>Array.from(t.values()).reduce((t,e)=>t+e.length,0)),g=Math.max(1,...y);let m=0;const x=p.flatMap((t,e)=>{let o=0;return Array.from(t.entries()).flatMap(([t,n])=>{if(0===n.length)return[];m+=1;const s=n.length/g*(i-24),l=o;return o+=s,rg("rect",{x:e/r*i,y:i-l-s,width:Math.max(i/r-1,1),height:s,fill:a?c(n[0]):q,opacity:.6},`${e}-${t}`)})});return{visibleBars:m,svg:Ol.renderToStaticMarkup(sg("svg",{x:l,y:u,width:i,height:i,"data-semiotic-composite-part":"diagonal-"+o,children:[rg("text",{x:i/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333",children:n}),x]}))}}({data:a,field:t,label:Z(u,t)??t,cellSize:d,bins:y,diagonal:g,colorBy:n,color:w.color,x:s,y:c});return C+=e.visibleBars,void I.push(e.svg)}const l={},m=jy({chartType:"scatter",data:a,size:[d,d],xAccessor:o,yAccessor:t,pointStyle:t=>({r:f,opacity:p,fill:w.color(t)}),margin:ag,showAxes:!1,showGrid:!1,enableHover:!1,accessibleTable:!1,description:`${Z(u,o)??o} versus ${Z(u,t)??t} scatterplot`,theme:r.theme,_idPrefix:`${(r._idPrefix??"splom")+""}-${e}-${i}`},l);T.push(l.evidence),I.push(hg(m,s,c,`cell-${t}-${o}`))})});const O=wy(r),F=k?O+"-title":void 0,D=O+"-description",z=Ol.renderToStaticMarkup(sg("svg",{xmlns:"http://www.w3.org/2000/svg",className:"scatterplot-matrix",width:m,height:R,role:"img","aria-labelledby":[F,D].filter(Boolean).join(" "),style:{fontFamily:v.fontFamily},children:[k&&rg("title",{id:F,children:k}),rg("desc",{id:D,children:A}),rg("rect",{width:m,height:R,fill:v.background}),k&&rg("text",{x:0,y:18,fontSize:14,fontWeight:600,fill:v.text,children:k}),L.map(t=>{const e=a.find(e=>n&&yg(e,n)===t.label),o=e?w.color(e):q;return sg("g",{transform:`translate(${t.x},${S+t.y})`,children:[rg("circle",{cx:5,cy:8,r:5,fill:o}),rg("text",{x:14,y:12,fontSize:11,fill:v.text,children:t.label})]},t.label)}),l.map((t,e)=>{const o=$+e*(d+h)+d/2;return rg("text",{x:20,y:o,transform:`rotate(-90 20 ${o})`,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:v.text,children:Z(u,t)??t},"row-"+t)}),l.map((t,e)=>rg("text",{x:40+h+e*(d+h)+d/2,y:$+l.length*(d+h)+20,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:v.text,children:Z(u,t)??t},"column-"+t)),rg("g",{dangerouslySetInnerHTML:{__html:I.join("")}})]}));return e&&(e.evidence=Ih({frameType:"xy",width:m,height:R,parts:T,additionalMarkCountByType:C>0?{histogram:C}:void 0,title:k,description:A,categories:w.categories.length?w.categories:void 0,legendItems:M.length||void 0})),z}},TemporalHistogram:He,XYCustomChart:ar,BarChart:$o,StackedBarChart:Ro,GroupedBarChart:To,PieChart:Io,DonutChart:Co,Histogram:Oo,BoxPlot:Fo,ViolinPlot:Do,SwarmPlot:zo,DotPlot:No,SwimlaneChart:Bo,RidgelinePlot:Wo,LikertChart:uo,FunnelChart:jo,RadarChart:Eo,GaugeChart:ko,OrdinalCustomChart:cr,ParallelCoordinatesRecipe:lr,CalendarHeatmapRecipe:ur,ForceDirectedGraph:Ci,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,o,n,i)=>({chartType:"force",nodes:i.nodes||t||[],edges:i.edges||[],nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor||"id",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",valueAccessor:i.valueAccessor||"value",colorBy:e,colorScheme:o,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...n})},SankeyDiagram:zi,ProcessSankey:Di,ChordDiagram:Ii,TreeDiagram:Ni,Treemap:Ei,CirclePack:Oi,OrbitDiagram:Fi,ChoroplethMap:Xi,ProportionalSymbolMap:qi,FlowMap:Vi,DistanceCartogram:Gi,GeoCustomChart:{frameType:"geo",buildProps:(t,e,o,n,i)=>({points:i.points||t||[],areas:i.areas||[],lines:i.lines||[],projection:i.projection||"equirectangular",xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",lineDataAccessor:i.lineDataAccessor,colorBy:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n})},GaltonBoardChart:Ml,EventDropChart:_l,UnitPileChart:Pl,CollisionSwarmChart:Ll,ProcessFlowChart:$l,GauntletChart:Rl,CrucibleChart:Tl,PacketFlowChart:Il,ChainReactionChart:{frameType:"physics",layout:{primarySize:{width:920,height:620}},buildProps:cg,renderStatic:function(t,e){const{data:o,common:n,rest:i}=function(t){return t.__composite}(t),r=Array.isArray(s=o)?s.filter(t=>null!=t&&"object"==typeof t&&!Array.isArray(t)):[];var s;const[a,c]=n.size??[920,620],l="string"==typeof n.title?n.title:"Dependency chain reaction",u=function(t){const e=[],o=new Map,n=[],i=new Set;t.data.forEach((r,s)=>{const a=(Zy(r,s,t.taskIDAccessor)??"")+"";if(!a)return void e.push({code:"duplicate-task-id",message:`Task row ${s} has an empty id.`,taskIDs:[]});if(o.has(a))return void e.push({code:"duplicate-task-id",message:`Task id "${a}" occurs more than once.`,taskIDs:[a]});const c=(Zy(r,s,t.laneAccessor)??"Unassigned")+"";i.has(c)||(i.add(c),n.push(c));const l=Zy(r,s,t.dependencyAccessor)??[],u=Array.from(new Set(Array.from(l,t=>t+""))).sort(Qy),d=Zy(r,s,t.blockerAccessor),h=Zy(r,s,t.statusAccessor)??(d?"blocked":"waiting");o.set(a,{id:a,label:(Zy(r,s,t.labelAccessor)??a)+"",lane:c,laneIndex:0,level:0,index:s,datum:r,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:Zy(r,s,t.startAccessor),end:Zy(r,s,t.endAccessor),progress:eg(Zy(r,s,t.progressAccessor)),status:h,completionTime:Zy(r,s,t.completionTimeAccessor),blockerReason:d||void 0,milestone:!!Zy(r,s,t.milestoneAccessor)})});const r=t.laneOrder?[...t.laneOrder,...n.filter(e=>!t.laneOrder?.includes(e))]:n,s=new Map(r.map((t,e)=>[t,e]));for(const t of o.values())t.laneIndex=s.get(t.lane)??0;const a=new Map,c=new Map;for(const t of o.keys())a.set(t,[]),c.set(t,[]);const l=[],u=[...o.values()].sort((t,e)=>t.index-e.index);for(const t of u)t.dependencyIDs.forEach((n,i)=>{const r=o.get(n);if(!r)return void e.push({code:"missing-dependency",message:`Task "${t.id}" depends on missing task "${n}".`,taskIDs:[t.id,n]});const s={id:Jy(n,t.id),sourceID:n,targetID:t.id,sourceIndex:r.index,targetIndex:t.index,socketID:tg(t.id,i),socketIndex:i};l.push(s),a.get(t.id)?.push(s),c.get(n)?.push(s),t.incomingEdgeIDs.push(s.id),t.socketIDs.push(s.socketID),r.outgoingEdgeIDs.push(s.id)});for(const t of a.values())t.sort((t,e)=>Qy(t.sourceID,e.sourceID)),t.forEach((t,e)=>{t.socketIndex=e,t.socketID=tg(t.targetID,e)});for(const t of c.values())t.sort((t,e)=>Qy(t.targetID,e.targetID));for(const t of o.values()){const e=a.get(t.id)??[];t.incomingEdgeIDs=e.map(t=>t.id),t.socketIDs=e.map(t=>t.socketID),t.outgoingEdgeIDs=(c.get(t.id)??[]).map(t=>t.id)}const d=new Map,h=new Map;for(const t of o.keys())d.set(t,a.get(t)?.length??0),h.set(t,0);const f=[...o.keys()].filter(t=>0===d.get(t)).sort(Qy);let p=0;for(;f.length;){const t=f.shift();p+=1;for(const e of c.get(t)??[]){const o=Math.max(h.get(e.targetID)??0,(h.get(t)??0)+1);h.set(e.targetID,o);const n=(d.get(e.targetID)??0)-1;if(d.set(e.targetID,n),0===n){const t=f.findIndex(t=>t>e.targetID);0>t?f.push(e.targetID):f.splice(t,0,e.targetID)}}}if(p!==o.size){const t=[...o.keys()].filter(t=>(d.get(t)??0)>0).sort(Qy);e.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${t.join(", ")}.`,taskIDs:t})}let y=0;const g=[...o.values()].sort((t,e)=>t.index-e.index);for(const t of g)t.level=h.get(t.id)??0,y=Math.max(y,t.level);return{nodes:g,edges:l,byID:o,incoming:a,outgoing:c,lanes:r,maxLevel:y,diagnostics:e,valid:0===e.length}}({data:r,taskIDAccessor:i.taskIDAccessor,labelAccessor:i.labelAccessor,laneAccessor:i.laneAccessor,dependencyAccessor:i.dependencyAccessor,startAccessor:i.startAccessor,endAccessor:i.endAccessor,progressAccessor:i.progressAccessor,statusAccessor:i.statusAccessor,completionTimeAccessor:i.completionTimeAccessor,blockerAccessor:i.blockerAccessor,milestoneAccessor:i.milestoneAccessor}),d=St(n.theme),h=Mt(d),f=wy(n),p=f+"-title",y=f+"-description";if(!u.valid){const t=u.diagnostics.map(t=>t.message).join(" "),o=Yy.renderToStaticMarkup(ig("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:c,role:"img","aria-labelledby":`${p} ${y}`,style:{fontFamily:h.fontFamily},children:[ng("title",{id:p,children:l}),ng("desc",{id:y,children:t}),ng("rect",{width:a,height:c,fill:h.background}),ng("text",{x:24,y:36,fontSize:16,fontWeight:700,fill:h.text,children:l}),u.diagnostics.map((t,e)=>ng("text",{x:24,y:72+22*e,fontSize:12,fill:d.colors.error,children:t.message},`${t.code}-${e}`))]}));return e&&(e.evidence=Ih({frameType:"physics",width:a,height:c,parts:[],title:l,description:t,nodeCount:u.nodes.length,edgeCount:u.edges.length,extraWarnings:["INVALID_DEPENDENCY_GRAPH"]})),o}const g=function(t,e,o={}){const n=Math.max(240,e.width),i=Math.max(220,e.height),r=e.paddingX??48,s=e.paddingTop??48,a=e.paddingBottom??44,c=Math.max(70,(n-2*r)/Math.max(1,t.lanes.length)),l=Math.max(76,(i-s-a)/Math.max(1,t.maxLevel+1)),u=Math.min(o.taskWidth??112,Math.max(58,.78*c)),d=Math.min(o.taskHeight??58,.64*l),h=o.socketRadius??5,f=Math.max(1,Math.round(o.gutterCount??3)),p=new Map;for(const e of t.nodes){const t=`${e.laneIndex}:${e.level}`,o=p.get(t)??[];o.push(e),p.set(t,o)}for(const t of p.values())t.sort((t,e)=>Qy(t.id,e.id));const y=.86*l,g=t.nodes.map(t=>{const e=p.get(`${t.laneIndex}:${t.level}`)??[t],o=Math.max(0,e.findIndex(e=>e.id===t.id))-(e.length-1)/2,n=(i=e.length)>1?Math.max(22,Math.min(d,(y-4*(i-1))/i)):d;var i;return{taskID:t.id,lane:t.lane,laneIndex:t.laneIndex,level:t.level,x:r+c*(t.laneIndex+.5),y:s+l*(t.level+.5)+o*(n+4),width:u,height:n}}),m=new Map(g.map(t=>[t.taskID,t])),x=[],b=[];t.edges.forEach((e,o)=>{const n=m.get(e.sourceID),i=m.get(e.targetID);if(!n||!i)return;const r=t.incoming.get(e.targetID)??[],s=Math.min(.72*i.width,14*Math.max(1,r.length-1)),a=r.length>1?i.x-s/2+s*e.socketIndex/(r.length-1):i.x,c=i.y-i.height/2-h-2;x.push({id:e.socketID,edgeID:e.id,taskID:i.taskID,index:e.socketIndex,x:a,y:c,radius:h});const l={x:n.x,y:n.y+n.height/2+3},u=Math.min(c-10,l.y+.48*Math.max(18,c-l.y)+7*(o%f-(f-1)/2));var d;b.push({edgeID:e.id,sourceID:e.sourceID,targetID:e.targetID,socketID:e.socketID,points:(d=[l,{x:l.x,y:u},{x:a,y:u},{x:a,y:c}],d.filter((t,e)=>{const o=d[e-1];return!o||o.x!==t.x||o.y!==t.y}))})});const v=new Map(x.map(t=>[t.id,t])),w=new Map(b.map(t=>[t.edgeID,t]));return{tasks:g,sockets:x,routes:b,taskByID:m,socketByID:v,routeByEdgeID:w}}(u,{width:a,height:c}),m=function(t,e,o){const n=t.nodes.map(Hy).filter(t=>null!=t),i=o,r=new Set,s=new Map;for(const e of t.nodes){const t=Hy(e);(null!=t&&i>=t||"done"===e.status&&!0)&&r.add(e.id),e.blockerReason&&!r.has(e.id)&&s.set(e.id,e.blockerReason)}const a=new Set;for(const e of t.edges)r.has(e.sourceID)&&a.add(e.id);return{currentTime:i,playing:!1,completed:r,delivered:a,inFlight:new Set,armed:Uy(t,a,s,r),blockers:s,previewTaskID:null}}(u,0,Vy(i.currentTime,1/0)),x=Array.isArray(i.selectedTaskIDs)?i.selectedTaskIDs.map(String):[],b=new Set(x),v=x[0]??null,w=v&&"none"!==i.insight?og(u,v,{completedTaskIDs:m.completed}):null,k=new Set(w?.downstreamTaskIDs??[]),A=function(t){return"number"==typeof t&&Number.isFinite(t)?t:31}(i.seed),S=function(t,e,o){const n="string"==typeof o?o:"Tasks are arranged by workstream and dependency depth. Completed tasks deliver their authored prerequisites; task completion remains an explicit data event.",i=[...e.blockers.keys()].map(o=>{const n=og(t,o,{completedTaskIDs:e.completed});return`${t.byID.get(o)?.label??o} affects ${n.downstreamTaskCount} unfinished tasks across ${n.affectedLaneCount} lanes.`}).join(" ");return i?`${n} ${i}`:n+" No explicit blockers are active."}(u,m,n.description),M=Yy.renderToStaticMarkup(ng(Gy,{machine:u,layout:g,runtime:m,downstreamSet:k,selectedSet:b,width:a,height:c,seed:A,reduced:!0,onSelectTask:()=>{}})),_=void 0===n.theme?{}:oe(d),P=Yy.renderToStaticMarkup(ig("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:c,role:"img","aria-labelledby":`${p} ${y}`,style:{..._,fontFamily:h.fontFamily},children:[ng("title",{id:p,children:l}),ng("desc",{id:y,children:S}),ng("rect",{width:a,height:c,fill:h.background}),ng("text",{x:a/2,y:22,textAnchor:"middle",fontSize:h.titleFontSize,fontFamily:h.titleFontFamily,fontWeight:h.titleFontWeight,fill:h.text,children:l}),ng("g",{dangerouslySetInnerHTML:{__html:M}})]}));return e&&(e.evidence=Ih({frameType:"physics",width:a,height:c,parts:[],additionalMarkCountByType:{task:u.nodes.length,dependency:u.edges.length},title:l,description:S,categories:u.lanes,nodeCount:u.nodes.length,edgeCount:u.edges.length})),P}},PhysicsCustomChart:Cl};import*as mg from"react";import*as xg from"react-dom/server";import{scaleBand as bg,scaleLinear as vg}from"d3-scale";var wg=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,o){if(e&&"function"==typeof t.pieceStyle){const n=t.pieceStyle(e,o);return n&&!n.fill&&o?{...n,fill:this.getColorFromScheme(t,o)}:n}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&o?{fill:Z(t.barColors,o)??"#007bff"}:{fill:o?this.getColorFromScheme(t,o):"#007bff"}}resolveSummaryStyle(t,e,o){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,o):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const o=this.colorSchemeMap.get(e);if(o)return o;const n=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||V,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function kg(t,e,o){const n="function"==typeof t?t(o?e.w:e.h):t;return"number"==typeof n&&Number.isFinite(n)?Math.max(0,n):0}function Ag(t){const e=t.getSymbol;return e?Xd(e,t.config.symbolMap):null}function Sg(t,e,o,n,i,r,s){t.push(e?{type:"symbol",x:n,y:i,size:Math.PI*r*r,symbolType:e(o),style:s,datum:o}:{type:"point",x:n,y:i,r:r,style:s,datum:o})}function Mg(t,e){const{columns:o,config:n,resolvePieceStyle:i}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===n.chartType?n.innerRadius||60:0,c=-Math.PI/2+(n.startAngle||0)*Math.PI/180,l=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,u=null!=n.sweepAngle&&360>n.sweepAngle,d=Object.values(o),h=d.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),f=u&&!h&&d.length>1&&(n.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],o=e.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:e.pctStart,h=c+u*l,p=c+(u+("number"==typeof o?._pct?o._pct:e.pct))*l,y=i(e.pieceData[0],e.name),g=0===t,m=t===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:y,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:f&&(x.roundedEnds={start:g,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as _g}from"d3-array";function Pg(t,e,o){return{...t[0],...o,category:e,data:t}}function Lg(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:_g(t,.25)??o,median:_g(t,.5)??(o+n)/2,q3:_g(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as $g}from"d3-scale";var Rg={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h="horizontal"===l,f=i.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(n))for(const o of e.pieceData){const e=s(o);t.has(e)||(t.add(e),p.push(e))}}else p.push("_default");for(const t of Object.values(n)){const e=new Map;for(const o of t.pieceData){const t=s?s(o):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const n=e.get(t);n.total+=r(o),n.pieces.push(o)}let o=0;if(f)for(const t of e.values())o+=Math.abs(t.total);let n=0,i=0;for(const r of p){const l=e.get(r);if(!l)continue;let p=l.total;f&&o>0&&(p/=o);const y=a(l.pieces[0],s?r:t.name),g={...l.pieces[0],__aggregateValue:l.total,__pieceCount:l.pieces.length,category:t.name};if(d){const e=c(0>p?i:n+p),o=0>p?c(i+p)-c(i):c(n)-c(n+p);u.push(_u(t.x,e,t.width,Math.abs(o),y,g,r)),0>p?i+=p:n+=p}else if(h){const e=c(0>p?i+p:n),o=0>p?c(i)-c(i+p):c(n+p)-c(n);u.push(_u(e,t.x,Math.abs(o),t.width,y,g,r)),0>p?i+=p:n+=p}}}const y="vertical"===l;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=y?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}if(void 0!==i.roundedTop){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const o=e.datum?.category||"";t.has(o)||t.set(o,[]),t.get(o).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),o=e.filter(t=>0>(t.datum?.__aggregateValue??0));if(t.length>0){const e=t.reduce(y?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=kg(i.roundedTop,e,y);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(y?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=kg(i.roundedTop,t,y);e>0&&(t.roundedTop=e)}}}return u},clusterbar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:c,projection:l}=o,u=[],d="vertical"===l,h=[],f=new Set;for(const t of Object.values(n))for(const e of t.pieceData){const t=s?s(e):"_default";f.has(t)||(f.add(t),h.push(t))}const p=h.length||1;for(const t of Object.values(n)){const e=t.width/p,o=.2*e,n=e-o,i=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";i.has(t)||i.set(t,[]),i.get(t).push(e)}for(let s=0;h.length>s;s++){const l=i.get(h[s])||[];for(const i of l){const l=r(i),f=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(_u(r,Math.min(a,d),n,Math.abs(a-d),f,i,h[s]))}else{const r=t.x+s*e+o/2,a=c(0),d=c(l);u.push(_u(Math.min(a,d),r,Math.abs(d-a),n,f,i,h[s]))}}}}for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum),o=kg(i.roundedTop,t,d);o>0&&(t.roundedTop=o),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}return u},point:function(t,e){const{scales:o,columns:n,getR:i,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d="radial"===c,h=r.length>0,f=Ag(t),p=2*Math.PI,y=-Math.PI/2;for(const t of Object.values(n))for(const e of t.pieceData){const o=e.__rIndex??0,n=e.__rValue??i(e),c=h&&r[o]||a,g=s(e,t.name),m=g.r||5;let x,b;if(d){const e=y+(t.pctStart+t.pct/2)*p,o=c(n);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=c(n)):(x=c(n),b=t.middle);Sg(l,f,e,x,b,m,g)}return l},swarm:function(t,e){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="vertical"===a,u=Ag(t);for(const t of Object.values(n)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const n=t.pieceData[o],a=i(n),d=r(n,t.name),h=d.r||4,f=(7919*o%100/100-.5)*e*.8;Sg(c,u,n,l?t.middle+f:s(a),l?s(a):t.middle+f,h,d)}}return c},pie:Mg,donut:Mg,boxplot:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=!1!==i.showOutliers;for(const e of Object.values(n)){const o=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===o.length)continue;const n=o[0],i=o[o.length-1],c=_g(o,.25)??n,h=_g(o,.5)??(n+i)/2,f=_g(o,.75)??i,p=f-c,y=c-1.5*p,g=f+1.5*p,m=o.find(t=>t>=y)??n,x=[...o].reverse().find(t=>g>=t)??i,b={n:o.length,min:m,q1:c,median:h,q3:f,max:x,mean:o.reduce((t,e)=>t+e,0)/o.length},v=s(Pg(e.pieceData,e.name,b),e.name),w=[];if(d)for(const t of e.pieceData){const o=r(t);if(y>o||o>g){const n=u?e.middle:a(o),i=u?a(o):e.middle;w.push({px:n,py:i,value:o,datum:t})}}if(l.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(c),medianPos:a(h),q3Pos:a(f),maxPos:a(x),stats:b,style:v,datum:e.pieceData,category:e.name,outliers:w}),d)for(const e of w)l.push({type:"point",x:e.px,y:e.py,r:3,style:{fill:v.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:v.cursor},datum:e.datum})}return l},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u="vertical"===c,d=i.bins||20,h=!1!==i.showIQR;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/d||1,c=Array(d).fill(0);for(const t of e)c[Math.min(Math.floor((t-o)/i),d-1)]++;const f=Lt(c,1),p=t.width/2*.9;let y;if(u){y=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);y+=` L ${t.middle+c[e]/f*p} ${n}`}y+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);y+=` L ${t.middle-c[e]/f*p} ${n}`}y+=" Z"}else{y=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)y+=` L ${a(o+(e+.5)*i)} ${t.middle-c[e]/f*p}`;y+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)y+=` L ${a(o+(e+.5)*i)} ${t.middle+c[e]/f*p}`;y+=" Z"}const g=Lg(e),m=s(Pg(t.pieceData,t.name,g),t.name);let x;if(h&&e.length>=4){const i=_g(e,.25)??o,r=_g(e,.5)??(o+n)/2,s=_g(e,.75)??n;x={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const b=u?{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))}:{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width};l.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:b,iqrLine:x,stats:g,style:m,datum:t.pieceData,category:t.name})}return l},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,c=[],l=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,n]=Pt(e),i=null!=h&&isFinite(h)?h:o,d=null!=f&&isFinite(f)?f:n,p=(d-i)/l||1,y=Array(l).fill(0);for(const t of e)i>t||t>d||y[Math.min(Math.floor((t-i)/p),l-1)]++;const g=e.length,m=Lt(y,1);for(let e=0;l>e;e++){if(0===y[e])continue;const o=(u?y[e]/g:y[e]/m)*t.width*.9,n=a(i+e*p),r=a(i+(e+1)*p),l=Math.min(n,r),d=Math.abs(r-n),h=t.x+t.width-o,f={...t.pieceData[0],bin:e,count:y[e],range:[i+e*p,i+(e+1)*p],category:t.name,data:t.pieceData},x=s(f,t.name);c.push(_u(l,h,d,o,x,f,t.name))}}return c},ridgeline:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:c}=o,l=[],u=i.bins||20,d="horizontal"===c,h=i.amplitude||1.5;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/u||1,c=Array(u).fill(0);for(const t of e)o>t||t>n||c[Math.min(Math.floor((t-o)/i),u-1)]++;const f=Lt(c,1),p=Lg(e),y=s(Pg(t.pieceData,t.name,p),t.name),g=t.width*h;let m;if(d){const e=t.x+t.width;m=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)m+=` L ${a(o+(t+.5)*i)} ${e-c[t]/f*g}`;m+=` L ${a(n)} ${e} Z`}else{const e=t.x;m=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const n=a(o+(t+.5)*i);m+=` L ${e+c[t]/f*g} ${n}`}m+=` L ${e} ${a(n)} Z`}const x=d?{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width}:{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))};l.push({type:"violin",pathString:m,translateX:0,translateY:0,bounds:x,stats:p,style:{...y,fillOpacity:y.fillOpacity??.5},datum:t.pieceData,category:t.name})}return l},timeline:function(t,e){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,c=[],l="horizontal"===a;for(const t of Object.values(n))for(const e of t.pieceData){const o=i(e);if(!o)continue;const[n,a]=o,u=r(e,t.name);if(l){const o=s(Math.min(n,a)),i=s(Math.max(n,a));c.push(_u(o,t.x,i-o,t.width,u,e,t.name))}else{const o=s(Math.max(n,a)),i=s(Math.min(n,a));c.push(_u(t.x,o,t.width,i-o,u,e,t.name))}}return c},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,c=!1!==t.config.showLabels,l=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return s;const u=[],d=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";d.has(t)||(d.add(t),u.push(t))}const h=u.length>1&&"_default"!==u[0],f=[];let p=0;for(const t of l){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}f.push({col:t,groups:e,stepTotal:o}),h||o>p&&(p=o)}if(h)for(const t of f){let e=0,o=0;for(let n=0;u.length>n;n++){const i=t.groups.get(u[n]);i&&(n%2==0?e+=i.total:o+=i.total)}const n=Math.max(e,o);n>p&&(p=n)}if(0===p)return s;const y=new Map;for(const t of u){const e=f[0].groups.get(t);y.set(t,e?.total??0)}const g=f[0].stepTotal,m=h?.95*a:.9*e.width,x=$g().domain([0,p]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const o=f[e],n=o.col,i=0===e,l=n.width,d=.55*l,p=n.x+(l-d)/2,m=new Map;if(h){let t=0;for(const e of u){const n=o.groups.get(e);n&&(t+=x(n.total))}let e=a,l=a;for(let h=0;u.length>h;h++){const f=u[h],g=o.groups.get(f);if(!g)continue;const b=x(g.total),v=h%2==0,w=v?e:l-b;v?e+=b:l-=b;const k=r(g.pieces[0],f),A=y.get(f)??g.total,S={...g.pieces[0],__funnelValue:g.total,__funnelPercent:A>0?g.total/A*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};c&&(0===h&&(S.__funnelStepLabel=n.name,S.__funnelStepLabelX=a,S.__funnelStepLabelY=p,S.__funnelRowWidth=t),S.__funnelValueLabelX=w+b/2,S.__funnelValueLabelY=p,S.__funnelBarW=b),s.push(_u(w,p,b,d,k,S,f)),m.set(f,{x:w,y:p,w:b,h:d})}}else{const t=o.stepTotal,e=x(t),l=a-e/2,h=u[0],f="_default"!==h,y=o.groups.get(h)?.pieces[0]??n.pieceData[0],b=f?h:n.name,v=r(y,b),w=g>0?t/g*100:0,k={...y,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:f?h:n.name};c&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(_u(l,p,e,d,v,k,b)),m.set(h,{x:l,y:p,w:e,h:d})}if(e>0&&v.size>0){const e=h?u:[u[0]];for(const i of e){const e=v.get(i),a=m.get(i);if(!e||!a)continue;const c=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),l={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:c.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:c.cursor},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(l)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],c=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return a;const l=[],u=new Set;for(const t of c)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),l.push(t))}const d=l.length>1&&"_default"!==l[0],h=[];for(const t of c){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:t,groups:e,stepTotal:o})}const f=new Map;for(const t of l){const e=h[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,y=d?l.length:1,g=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],o=e.col,n=0===t,i=t>0?h[t-1]:null,s=o.width/y,c=s*g,u=s-c;for(let t=0;l.length>t;t++){const h=l[t],y=e.groups.get(h);if(!y)continue;const g=y.total,m=f.get(h)??g,x=m>0?g/m*100:0,b=i?.groups.get(h),v=n?0:Math.max(0,(b?.total??g)-g),w=o.x+t*s+c/2,k=p(g),A=p(0)-k,S=r(y.pieces[0],d?h:o.name),M={...y.pieces[0],__barFunnelValue:g,__barFunnelPercent:x,__barFunnelIsFirstStep:n,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(g+v)};if(a.push(_u(w,k,u,A,S,M,d?h:o.name)),v>0){const t=p(g+v),e=k-t,n={...S},i={...y.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(_u(w,t,u,e,n,i,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:n,getR:i,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:c}=o,l=[],u="horizontal"===c,d=t.config.gradientFill,h=u?"left":"bottom",f=new Map,p=e=>{const o=f.get(e);if(void 0!==o)return o;const n="function"==typeof t.config.roundedTop?t.config.roundedTop(e.width):t.config.roundedTop,i="number"==typeof n&&Number.isFinite(n)?Math.max(0,n):0;return f.set(e,i),i},y=t.config.trackFill;if(y){const t="string"==typeof y?y:y.color,e="string"==typeof y?1:y.opacity??1,[o,i]=a.range(),r=Math.min(o,i),s=Math.abs(i-o);for(const o of Object.values(n)){const n={fill:t,opacity:e},i=u?_u(r,o.x,s,o.width,n,null,"__track__"):_u(o.x,r,o.width,s,n,null,"__track__"),a=p(o);a>0&&(i.cornerRadii={tl:a,tr:a,br:a,bl:a}),l.push(i)}}for(const t of Object.values(n)){let e=0;const o=l.length,n=p(t);for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const c=r?r(o):t.name,f=s(o,c);let p;if(u){const i=a(e),r=a(e+n);p=_u(i,t.x,r-i,t.width,f,o,c)}else{const i=a(e+n),r=a(e);p=_u(t.x,i,t.width,r-i,f,o,c)}d&&(p.fillGradient=d,p.roundedEdge=h),l.push(p),e+=n}if(n>0&&l.length>o){const t=l.slice(o),e=t[0],i=t[t.length-1];1===t.length?e.cornerRadii={tl:n,tr:n,br:n,bl:n}:u?(e.cornerRadii={tl:n,bl:n},i.cornerRadii={tr:n,br:n}):(e.cornerRadii={bl:n,br:n},i.cornerRadii={tl:n,tr:n})}}return l}},Tg=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ig=["scene-style","data-paint","accessibility","evidence"],Cg=(t,e)=>({retainedData:t,invalidations:e}),Og=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Fg=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Dg=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],zg=["scene-geometry","data-paint","accessibility","evidence"],Ng=["scene-style","data-paint","accessibility","evidence"],Eg=[],Bg={chartType:Cg("rebuild",Og),runtimeMode:Cg("rebuild",Og),categoryAccessor:Cg("rebuild",Og),valueAccessor:Cg("rebuild",Og),oAccessor:Cg("rebuild",Og),rAccessor:Cg("rebuild",Og),stackBy:Cg("rebuild",Og),groupBy:Cg("rebuild",Og),timeAccessor:Cg("rebuild",Og),accessorRevision:Cg("rebuild",Og),colorAccessor:Cg("rebuild",Ng),symbolAccessor:Cg("rebuild",zg),connectorAccessor:Cg("rebuild",zg),dataIdAccessor:Cg("rebuild",zg),projection:Cg("preserve",Fg),extentPadding:Cg("preserve",Fg),axisExtent:Cg("preserve",Fg),rExtent:Cg("preserve",Fg),oExtent:Cg("preserve",Fg),multiAxis:Cg("preserve",Fg),normalize:Cg("preserve",Fg),bins:Cg("preserve",Fg),oSort:Cg("preserve",Dg),barPadding:Cg("preserve",Dg),roundedTop:Cg("preserve",Dg),baselinePadding:Cg("preserve",Dg),innerRadius:Cg("preserve",Dg),cornerRadius:Cg("preserve",Dg),startAngle:Cg("preserve",Dg),sweepAngle:Cg("preserve",Dg),trackFill:Cg("preserve",Dg),showOutliers:Cg("preserve",Dg),showIQR:Cg("preserve",Dg),amplitude:Cg("preserve",Dg),connectorOpacity:Cg("preserve",Dg),showLabels:Cg("preserve",Dg),dynamicColumnWidth:Cg("rebuild",Dg),customLayout:Cg("preserve",Dg),layoutConfig:Cg("preserve",Dg),layoutMargin:Cg("preserve",Dg),symbolMap:Cg("preserve",zg),pieceStyle:Cg("preserve",Ng),summaryStyle:Cg("preserve",Ng),connectorStyle:Cg("preserve",Ng),gradientFill:Cg("preserve",Ng),colorScheme:Cg("preserve",Ng),themeCategorical:Cg("preserve",Ng),themeSemantic:Cg("preserve",Ng),themeSequential:Cg("preserve",Ng),themeDiverging:Cg("preserve",Ng),barColors:Cg("preserve",Ng),decay:Cg("preserve",Ng),pulse:Cg("preserve",Ng),staleness:Cg("preserve",Ng),layoutSelection:Cg("preserve",Ng),windowSize:Cg("preserve",Eg),windowMode:Cg("preserve",Eg),clock:Cg("preserve",Eg),transition:Cg("preserve",Eg),introAnimation:Cg("preserve",Eg),onLayoutError:Cg("preserve",Eg)},Wg=Cg("preserve",Dg),jg=class{constructor(){this.tracker=new Ss}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Tg)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Ig):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=Bg[n]??Wg;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as Yg}from"d3-quadtree";var Xg=class{constructor(t){this.rExtent=new Nl,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new jg,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new wg,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=t,this.buffer=new zl(t.windowSize),this.getO=jl(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>Bl(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Nl)):(this.getR=Bl(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=jl(t.stackBy),this.getGroup=jl(t.groupBy),this.getColor=jl(t.colorAccessor),this.getSymbol=jl(t.symbolAccessor),this.getConnector=jl(t.connectorAccessor),this.getDataId=jl(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new zl(t.windowSize))}syncPulseTimestampBuffer(){var t,e,o,n;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,o=this.timestampBuffer,n=this.currentTime(),t?null!=o&&o.capacity===e.capacity&&o.size===e.size?o:Tu(e,n):null)}currentTime(){return this.config.clock?.()??Ql()}ingest(t){const e=this.currentTime();if(this.lastIngestTime=e,this._dataVersion++,t.bounded){this.buffer.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();t.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),Ru(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Iu(this.buffer,o,this.timestampBuffer,e),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of t.inserts){const t=Iu(this.buffer,o,this.timestampBuffer,e);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=t&&this.evictValueExtent(t)}}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}pushValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.push(e[0]),this.rExtent.push(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].push(this.rAccessors[e](t));this.rExtent.push(this.getR(t))}else this.rExtent.push(this.getR(t))}evictValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.evict(e[0]),this.rExtent.evict(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].evict(this.rAccessors[e](t));this.rExtent.evict(this.getR(t))}else this.rExtent.evict(this.getR(t))}getRawRange(t){const e=this.config.valueAccessor||this.config.rAccessor;if(!e)return null;const o="function"==typeof e?e(t):t[e];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",c=e.oExtent||this.resolveCategories(s),l=this.computeValueDomain(s,c),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let f,p;if(d){f=bg().domain(c).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;p=vg().domain(l).range([n,o])}else u?(f=bg().domain(c).range([0,t.height]).padding(h),p=vg().domain(l).range([0,t.width])):(f=bg().domain(c).range([0,t.width]).padding(h),p=vg().domain(l).range([t.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((n,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(o,n);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const c=a-s,l=c>0?c*(e.extentPadding??.05):1;return s-=l,a+=l,s>0&&(s=0),u?vg().domain([s,a]).range([0,t.width]):vg().domain([s,a]).range([t.height,0])}):[];let y=s;this.rAccessors.length>1&&(y=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(y,c,f,a,t),this._customLayoutFailedThisBuild=!1;const g=this.buildSceneNodes(y,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=g,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(e)?e[t]:e;return"string"==typeof o?o:"value"+t}resolveCategories(t){const e=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,n="auto"===e?void 0:e;let i=null;if(o){i=new Set;for(const e of t)i.add(this.getO(e))}const r=i?Array.from(this.categories).filter(t=>i.has(t)):Array.from(this.categories);if(o&&void 0===n){const t=Math.max(50,3*i.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;i.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===n)return r;if("function"==typeof n)return r.sort(n);const s=new Map;for(const e of t){const t=this.getO(e);s.set(t,(s.get(t)||0)+Math.abs(this.getR(e)))}return r.sort("asc"===n?(t,e)=>(s.get(t)||0)-(s.get(e)||0):(t,e)=>(s.get(e)||0)-(s.get(t)||0))}computeValueDomain(t,e){return function(t){const{data:e,chartType:o,projection:n,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:c,getO:l,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let p=0,y=0;if("bar"===o&&d&&i)p=0,y=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=l(n),i=u(n);0>i?o.set(e,(o.get(e)||0)+i):t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>y&&(y=e);for(const t of o.values())p>t&&(p=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=l(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e),p>e&&(p=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=l(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>y&&(y=e),p>e&&(p=e)}else{const t=h[0],e=h[1];t!==1/0&&(p=t),e!==-1/0&&(y=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(y=r[1]));const g="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(g&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>y&&(y=0)),"bar-funnel"!==o&&"exact"!==c){const t=y-p,e=t>0?t*f:1,n=g&&!a&&0===p,i=g&&!a&&0===y||"swimlane"===o;null!=r?.[0]||n||(p-=e),null!=r?.[1]||i||(y+=e)}return[p,y]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,n,i){return function(t){const{data:e,oExtent:o,oScale:n,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:c}=t,l=Object.create(null),u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===i)for(const t of e)d+=Math.abs(c(t));let h=null;if(s&&"radial"!==i){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let n;n="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,n),t+=n}const e=("horizontal"===i?r.height:r.width)-n.padding()*n.step()*o.length;if(t>0)for(const[o,n]of h)h.set(o,n/t*e)}let f=0,p=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(c(e)),0),i=d>0?o/d:0;let r,s;h?(r=p,s=h.get(t)||n.bandwidth(),p+=s+n.padding()*n.step()):(r=n(t)??0,s=n.bandwidth()),l[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:e,pct:i,pctStart:f},f+=i}return l}({data:t,oExtent:e,oScale:o,projection:n,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(t,e),n=fu({family:"ordinal",logLabel:"ordinal customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:this.config.onLayoutError,run:()=>this.config.customLayout(o)});if("failure"===n.kind)return this.lastCustomLayoutFailure=n.diagnostic,this._customLayoutFailedThisBuild=!0,n.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);const i=n.result;this.customLayoutOverlays=i.overlays??null,this.lastCustomLayoutResult=i,this.lastCustomLayoutFailure=null;const r=i.nodes??[];if(this._customRestyle=i.restyle,this.hasCustomRestyle=!!i.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of r)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(r,this.config.layoutSelection??null)}return uu({label:"ordinal customLayout",nodes:r,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),r}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),n=Rg[this.config.chartType];let i=n?n(o,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:o,config:n,getConnector:i,getO:r}=t;if(!i||!o)return[];const s=[],{projection:a}=o,c=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const o=i(e);if(!o)continue;let n,s;"point"===t.type?(n=t.x,s=t.y):(n=t.x+t.w/2,s=t.y+("vertical"===a?0:t.h/2)),c.has(o)||c.set(o,[]),c.get(o).push({x:n,y:s,datum:e,category:r(e)})}const l=o.o.domain(),u=n.connectorStyle,d={stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5},h=(t,e,o)=>{var n;s.push({type:"connector",x1:t.x,y1:t.y,x2:e.x,y2:e.y,style:(n=t.datum,"function"==typeof u?u(n):u||d),datum:t.datum,group:o})};for(const[t,e]of c)if(e.length>=2){e.sort((t,e)=>l.indexOf(t.category)-l.indexOf(e.category));for(let o=0;e.length-1>o;o++)h(e[o],e[o+1],t);"radial"!==a||3>e.length||h(e[e.length-1],e[0],t)}return s}(o,i);i=[...t,...i]}return i}buildLayoutContext(t,e){const o=this.config,n=o.layoutMargin??{top:0,right:0,bottom:0,left:0},i=ia(o.colorScheme,o.themeCategorical,V),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:n,plot:"radial"===r.projection?{x:-e.width/2,y:-e.height/2,width:e.width,height:e.height}:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:o.themeSemantic??{},categorical:[...i]},resolveColor:ra(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Jl(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=tu(t);return this._datumIndexCache={version:this._dataVersion,map:e},e}getCategoryIndexMap(t){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const e=function(t,e){const o="function"==typeof e,n=o?null:e||"category",i=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=o?e(s):s[n],c=i.get(a);c?c.push(r):i.set(a,[r])}return i}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,o=0;for(const n of t)"point"===n.type&&!1!==n.interactive&&(e++,n.r>o&&(o=n.r));if(500>=e)return{quadtree:null,maxRadius:o};const n=Array(e);let i=0;for(const e of t)"point"===e.type&&!1!==e.interactive&&(n[i++]=e);return{maxRadius:o,quadtree:Yg().x(t=>t.x).y(t=>t.y).addAll(n)}}(this.scene);this._pointQuadtree=t.quadtree,this._maxPointRadius=t.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(t,e){if(!this.config.decay)return;const o=e.length;if(1>=o)return;const n=this.getDatumIndexMap(e);for(const e of t){if("connector"===e.type||"violin"===e.type||"boxplot"===e.type||"wedge"===e.type)continue;if(!e.datum)continue;const t=n.get(e.datum);if(null==t)continue;const i=this.computeDecayOpacity(t,o);e.style={...e.style,opacity:(e.style?.opacity??1)*i}}}applyPulse(t,e,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let c=!1;for(const l of e){if("connector"===l.type||"violin"===l.type||"boxplot"===l.type)continue;if("wedge"===l.type){const e=l.category;if(!e)continue;let n=0;for(const s of i(e)??[]){const e=o.get(s);null!=e&&(n=Math.max(n,eu(t,e,r)))}c=ou(l,n,s)||c;continue}if(null==l.datum)continue;const e=n.get(l.datum);if(null==e)continue;const u=o.get(e);c=ou(l,null==u?0:eu(t,u,r),s,a)||c}return c}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),o)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&nu(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const t=new Map,e=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let n;for(let i=0;this.scene.length>i;i++){const r=this.scene[i],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,o?{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}:{x:e,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===n&&(n=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:n,endAngle:n,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(t,e){if("point"===t.type){const o=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,n=e.get(o)||0;return e.set(o,n+1),`${o}:${n}`}if("rect"===t.type){const o=t.datum?null!=t.datum.category&&""!==t.datum.category?t.datum.category+"":(this.getO(t.datum)??"")+"":"",n=`r:${t.group||""}:${o}`,i=e.get(n)||0;return e.set(n,i+1),0===i?n:`${n}:${i}`}return"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=this.getNodeKey(o,t);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity??o.style.fillOpacity}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity??o.style.fillOpacity}):"wedge"===o.type&&this.prevPositionMap.set(n,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const t=this.config.transition.duration??300;if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}let e=!1;const o=new Set,n=new Map;for(let t=0;this.scene.length>t;t++){const i=this.scene[t],r=this.getNodeKey(i,n);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,(s.x!==i.x||s.y!==i.y||void 0!==s.r&&s.r!==i.r)&&(i._targetX=i.x,i._targetY=i.y,i._targetR=i.r,i.x=s.x,i.y=s.y,void 0!==s.r&&(i.r=s.r),e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},e=!0);else if("rect"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.x===i.x&&s.y===i.y&&s.w===i.w&&s.h===i.h||(i._targetX=i.x,i._targetY=i.y,i._targetW=i.w,i._targetH=i.h,i.x=s.x,i.y=s.y,i.w=s.w??i.w,i.h=s.h??i.h,e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i.style={...i.style,opacity:0},e=!0);else if("wedge"===i.type)if(s)o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.startAngle===i.startAngle&&s.endAngle===i.endAngle||(i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle,i.startAngle=s.startAngle,i.endAngle=s.endAngle,e=!0);else{i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle;const t=i.startAngle;i.startAngle=t,i.endAngle=t,i.style={...i.style,opacity:0},this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:t,endAngle:t,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,n]of this.prevPositionMap)if(!o.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:n.x,y:n.y,r:n.r??3,style:{opacity:n.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:n.x,y:n.y,w:n.w??0,h:n.h??0,style:{opacity:n.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((n.startAngle??0)+(n.endAngle??0))/2,o={type:"wedge",cx:n.x,cy:n.y,innerRadius:n.innerRadius??0,outerRadius:n.outerRadius??100,startAngle:n.startAngle??0,endAngle:n.endAngle??0,style:{opacity:n.opacity??1},datum:null,category:t.slice(2),_targetStartAngle:e,_targetEndAngle:e,_targetOpacity:0,_transitionKey:t};this.exitNodes.push(o)}e=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),e&&(this.activeTransition={startTime:this.currentTime(),duration:t})}advanceTransition(t){if(!this.activeTransition)return!1;const e=Kl(t,this.activeTransition),o=Ul(e,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const t of this.scene){const e=t._transitionKey;if(e)if("point"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Zl(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Zl(n.x,t._targetX,o),t.y=Zl(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Zl(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Zl(n?n.opacity??1:0,t._targetOpacity,o)}if(void 0===t._targetX)continue;const n=this.prevPositionMap.get(e);if(!n)continue;t.x=Zl(n.x,t._targetX,o),t.y=Zl(n.y,t._targetY,o),void 0!==n.w&&(t.w=Zl(n.w,t._targetW,o),t.h=Zl(n.h,t._targetH,o))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style={...t.style,opacity:Zl(n?n.opacity??1:0,t._targetOpacity,o)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const n=this.prevPositionMap.get(e);n&&void 0!==n.startAngle&&(t.startAngle=Zl(n.startAngle,t._targetStartAngle,o),t.endAngle=Zl(n.endAngle,t._targetEndAngle,o))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}"point"===e.type?void 0!==e._targetX?(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0):void 0!==e._targetR&&(e.r=e._targetR,e._targetR=void 0):"rect"===e.type?void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0):"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Hl(t),o=this.getDataId,n=t=>e.has(o(t));Cu(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=Hl(t),n=this.getDataId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach((t,e)=>{this.categories.add(this.getO(t)),i.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();this._categoryIndexCache=null,this.buffer.forEach(t=>{this.categories.add(this.getO(t)),this.pushValueExtent(t)})}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t&&t.colorScheme!==e.colorScheme||"themeCategorical"in t&&t.themeCategorical!==e.themeCategorical||"colorAccessor"in t&&!El(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!El(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!El(t.oAccessor,e.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();let n=!1;("categoryAccessor"in t||"oAccessor"in t)&&(El(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=jl(this.config.categoryAccessor||this.config.oAccessor,"category"),n=!0));let i=!1;if("valueAccessor"in t||"rAccessor"in t){const t=this.config.valueAccessor||this.config.rAccessor,o=e.valueAccessor||e.rAccessor,n=Array.isArray(t)?t:[t],r=Array.isArray(o)?o:[o];if(i=n.length!==r.length||n.some((t,e)=>!El(t,r[e])),i){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>Bl(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new Nl)):(this.getR=Bl(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!El(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?jl(this.config.stackBy):void 0),"groupBy"in t&&!El(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?jl(this.config.groupBy):void 0),"colorAccessor"in t&&!El(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?jl(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!El(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?jl(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!El(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?jl(this.config.connectorAccessor):void 0),(n||i||"accessorRevision"in t&&t.accessorRevision!==e.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Wu(Xg);import*as qg from"react";import{jsx as Gg,jsxs as Vg}from"react/jsx-runtime";function Hg(t){return"connector"===t.node.type}function Ug(t,e,o,n){if(2>t.length)return null;const i=t[0].node,r=i.style.fill;if(!r||"none"===r)return null;const s=Yh(`${e?e+"-":""}connector-${o}-${n}-hatch`),a=yi(r)?xi(r,s):null,c=[`${i.x1},${i.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return Kh(Vg(qg.Fragment,{children:[a&&Gg("defs",{children:a}),Gg("polygon",{points:c,fill:a?`url(#${s})`:jh(r,"#999"),opacity:i.style.fillOpacity??i.style.opacity??.3,"data-semiotic-connector-fill":i.group||"_default"})]}),i,`ordinal-connector-fill-${o}-${n}`)}function Kg(t,e,o){const n=new Map;for(const e of t){if(!Hg(e))continue;const t=e.node.group||"_default",o=n.get(t);o?o.push(e):n.set(t,[e])}if(0===n.size)return;const i=Array.from(n.values()).map((t,n)=>Vg("g",{children:[Ug(t,e,o,n),t.map(t=>t.element)]},`ordinal-connectors-${o}-${n}`)),r=t[0],s=Hg(r)?null:r.element;for(const t of n.values())for(const e of t)e.element=null;r.element=Vg(qg.Fragment,{children:[i,s]},"ordinal-connector-run-"+o)}function Zg(t){const e=bf({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>function(t,e,o){return Kh(function(t,e,o){const n=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",i=o=>`ord-${t.type}-${n}-${e}-${o}`,r=`ord-${t.type}-${n}-${e}`;switch(t.type){case"rect":{const e=t,o=Yh(r)+"-grad",n=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=t.x,i=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(i=t.y+t.h,s=t.y):"right"===t.roundedEdge?(n=t.x+t.w,i=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(n=t.x,i=t.y,r=t.x+t.w,s=t.y);const a=qh(o.stops,jh(t.style.fill));return a?Eh("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:n,y1:i,x2:r,y2:s,children:a}):null}(e,o);let i,s;if(n)s=`url(#${o})`;else if(yi(e.style.fill)){const t=Yh(r)+"-hatch";i=xi(e.style.fill,t),s=`url(#${t})`}else s=jh(e.style.fill);const a=n||i?uf("defs",{children:[n,i]}):null;if(e.cornerRadii&&ah(e.cornerRadii)){const t=function(t){const{x:e,y:o,w:n,h:i}=t,{tl:r,tr:s,br:a,bl:c}=ch(t);let l=`M${e+r},${o}`;return l+=` L${e+n-s},${o}`,s>0&&(l+=` A${s},${s} 0 0 1 ${e+n},${o+s}`),l+=` L${e+n},${o+i-a}`,a>0&&(l+=` A${a},${a} 0 0 1 ${e+n-a},${o+i}`),l+=` L${e+c},${o+i}`,c>0&&(l+=` A${c},${c} 0 0 1 ${e},${o+i-c}`),l+=` L${e},${o+r}`,r>0&&(l+=` A${r},${r} 0 0 1 ${e+r},${o}`),l+=" Z",l}(e);return uf(rf.Fragment,{children:[a,lf("path",{d:t,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:o,y:n,w:i,h:c}=e;let l;switch(e.roundedEdge){case"right":l=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+c-t} A${t},${t} 0 0 1 ${o+i-t},${n+c} L${o},${n+c} Z`;break;case"left":l=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+c-t} A${t},${t} 0 0 0 ${o+t},${n+c} L${o+i},${n+c} Z`;break;case"bottom":l=`M${o},${n} L${o+i},${n} L${o+i},${n+c-t} A${t},${t} 0 0 1 ${o+i-t},${n+c} L${o+t},${n+c} A${t},${t} 0 0 1 ${o},${n+c-t} Z`;break;default:l=`M${o},${n+c} L${o},${n+t} A${t},${t} 0 0 1 ${o+t},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+c} Z`}return uf(rf.Fragment,{children:[a,lf("path",{d:l,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return uf(rf.Fragment,{children:[a,lf("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),hf(e,r)]},r)}case"point":{const e=t;return lf("circle",{cx:e.x,cy:e.y,r:e.r,fill:jh(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return Gh(t,e,o);case"glyph":return Xh(t,t.x,t.y,`${o??""}ord-glyph-${t.pointId??e}`);case"wedge":{const n=t;if(n._gradientBand&&n._gradientBand.colors.length>0){const t=Yh(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=cf({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),o=[],n=t.colors;if(n.length>0){const e=(t.endAngle-t.startAngle)/n.length;for(let i=0;n.length>i;i++)o.push({d:cf({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+i*e,endAngle:t.endAngle}),color:n[i]})}return{clipPath:e,slices:o}}({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});return uf("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[lf("defs",{children:lf("clipPath",{id:t,children:lf("path",{d:i})})}),lf("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>lf("path",{d:t.d,fill:jh(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&lf("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=cf({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{const t=sf().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&t.cornerRadius(n.cornerRadius),i=t(Wh)||""}return lf("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:jh(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n.style.opacity},r)}case"boxplot":{const e=t,o=e.columnWidth/2,n=e.style.strokeWidth??1;return uf("g","vertical"===e.projection?{children:[lf("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n}),lf("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:jh(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),lf("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*n}),lf("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:n}),lf("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n})]}:{children:[lf("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:n}),lf("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:jh(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),lf("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*n}),lf("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n}),lf("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n})]},r)}case"violin":{const e=t,o=[lf("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:jh(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth??1},i("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,n=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?o.push(lf("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),lf("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(lf("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),lf("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return lf("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?jh(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return lf("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||o,strokeWidth:e.style.strokeWidth??1,opacity:e.style.opacity??.5},r)}case"trapezoid":{const e=t,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return lf("polygon",{points:o,fill:jh(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}}(t,e,o),t,"ordinal-cursor-"+e)}(e,o,t.idPrefix)});let o=0;for(let n=0;e.length>n;){if(e[n].renderedByBackend){n++;continue}let i=n+1;for(;e.length>i&&!e[i].renderedByBackend;)i++;Kg(e.slice(n,i),t.idPrefix,o++),n=i}return e}import{jsx as Qg,jsxs as Jg}from"react/jsx-runtime";import{Fragment as tm,jsx as em,jsxs as om}from"react/jsx-runtime";var nm=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function im(t,e){const o=St(t.theme),n=t.size||[500,400],i=ce({...Cy,...t.margin},t.title),r=se(t.title),s=g(t.data),a=t.showLegend?Tf(s,t.colorAccessor||t.stackBy||t.groupBy):[],c=function(t){const e=t.projection??"vertical",o=!1!==t.showAxes&&"radial"!==e;return{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasValueLabel:t.hasCategoryLabel),leftAxis:{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasCategoryLabel:t.hasValueLabel)}}}({showAxes:t.showAxes,projection:t.projection,hasCategoryLabel:!(!t.categoryLabel&&!t.oLabel),hasValueLabel:!(!t.valueLabel&&!t.rLabel)});_y(i,{props:{...t,axisChrome:c},categories:a,theme:o,size:n,hasTitle:r});const l=Py({props:{...t,axisChrome:c},categories:a,theme:o,size:n,margin:i,hasTitle:r}),u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h=t.projection||"vertical",f="radial"===h,p=t.colorScheme||o.colors.categorical,y={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:dt(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:p,themeCategorical:o.colors.categorical,themeSemantic:kt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},m=new Xg(y);t.data&&m.ingest({inserts:s,bounded:!0}),m.computeScene({width:u,height:d});const x=Iy(t.backgroundGraphics,n,i,m.scales),b=Iy(t.foregroundGraphics,n,i,m.scales);if(!m.scales){let r;const a=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,projection:h,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Fh({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:m.scales?[]:["NO_SCALES"],margin:i})),xg.renderToStaticMarkup($y(x||b||t.annotations?om(tm,{children:[x,a,b,m.customLayoutOverlays]}):null,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}const v=t._idPrefix,w=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=Mt(o),a=n?n+"-":"",c="vertical"===r.projection,l=ly(r.r,5,i);return xy("g",c?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const n=r.r(t);return xy("line",{x1:0,y1:n,x2:e.width,y2:n,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:l.map((t,o)=>{const n=r.r(t);return xy("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(m,{width:u,height:d},o,v,t.axisExtent):null;let k=null;if(m.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=wy(t),n=new Set;for(const t of m.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");k=Array.from(n).map((t,n)=>function(t){const{id:e,background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return Jg("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Qg("rect",{width:a,height:a,fill:o}),Qg("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Qg("line",{x1:r,y1:0,x2:r,y2:a,stroke:n,strokeWidth:i})]},e)}({id:`funnel-hatch-${e}-${n}`,background:t,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(n).forEach((t,o)=>i.set(t,`funnel-hatch-${e}-${o}`));for(const t of m.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${i.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const A=Zg({nodes:m.scene,renderMode:t.renderMode,idPrefix:v}),S=A.map(t=>t.element),M=!1!==t.showAxes?function(t,e,o,n,i,r,s,a=!1){const c=t.scales;if(!c)return null;if("radial"===c.projection)return null;const l=Mt(n),u="vertical"===c.projection,d=t.columns,h=o.categoryFormat||o.oFormat,f=o.valueFormat||o.rFormat,p=o.categoryLabel||o.oLabel,y=o.valueLabel||o.rLabel,g=o.legendPosition??"right",m=fe(o.legendLayout,s?.leftAxis),x=a&&"left"===g&&m>0?m:r?.left??o.margin?.left??40,b=Object.values(d).map((t,e)=>({pixel:t.middle,label:h?h(t.name,e):t.name})),v=ly(c.r,5,o.axisExtent).map(t=>({pixel:c.r(t),label:(f||Ly)(t)}));return om("g",u?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[em("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:l.border,strokeWidth:1}),b.map((t,o)=>om("g",{transform:`translate(${t.pixel},${e.height})`,children:[em("line",{y2:5,stroke:l.border,strokeWidth:1}),dy(t.label)?em("text",{y:18,textAnchor:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):hy({label:t.label,x:-30,y:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"oxtick-"+o)),p&&em("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:p}),em("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:l.border,strokeWidth:1}),v.map((t,e)=>om("g",{transform:`translate(0,${t.pixel})`,children:[em("line",{x2:-5,stroke:l.border,strokeWidth:1}),em("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label})]},"oytick-"+e)),y&&em("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:y})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[em("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:l.border,strokeWidth:1}),v.map((t,o)=>om("g",{transform:`translate(${t.pixel},${e.height})`,children:[em("line",{y2:5,stroke:l.border,strokeWidth:1}),em("text",{y:18,textAnchor:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label})]},"oxtick-"+o)),y&&em("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:y}),em("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:l.border,strokeWidth:1}),b.map((t,e)=>om("g",{transform:`translate(0,${t.pixel})`,children:[em("line",{x2:-5,stroke:l.border,strokeWidth:1}),dy(t.label)?em("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):hy({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"oytick-"+e)),p&&em("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:p})]})}(m,{width:u,height:d},t,o,v,i,c,!!l):null;let _;const P=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:m.scales.o,r:m.scales.r,y:"vertical"===m.scales.projection?m.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,xAccessor:"string"==typeof t.oAccessor?t.oAccessor:void 0,yAccessor:"string"==typeof t.rAccessor?t.rAccessor:void 0,idPrefix:v,onRender:t=>{_=t}}):null;if(e){const o=m.scales.o?.domain?.();e.evidence=Fh({frameType:"ordinal",width:n[0],height:n[1],marks:A.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:_,yDomain:Oh(m.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const L=f&&t.centerContent?function(t,e,o){if(!mg.isValidElement(t))return null;if("string"!=typeof t.type||!nm.has(t.type))return null;const n=t,i="text"===n.type?mg.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return em("g",{className:"semiotic-radial-center-content",transform:`translate(${e},${o})`,pointerEvents:"none",children:i})}(t.centerContent,i.left+u/2,i.top+d/2):null,$=f&&t.centerContent?L??em("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:em("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,R=om(tm,{children:[w,S,M,P,b,m.customLayoutOverlays]});return xg.renderToStaticMarkup($y(om(tm,f?{children:[x?em("g",{transform:`translate(${-u/2},${-d/2})`,children:x}):null,R]}:{children:[x,R]}),{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:f?`translate(${i.left+u/2},${i.top+d/2})`:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:l,defs:k,outerElements:$,idPrefix:t._idPrefix}))}import*as rm from"react-dom/server";var sm=Object.create(null);function am(t,e){sm[t]=e}function cm(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function lm(t,e){var o,n=[],i=[],r=[],s={},a=[];function c(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&c(e)})}function l(t){var e,n,d=!1;for(i.push(t),r[t]=!0,e=0;a[t].length>e;e++)(n=a[t][e])===o?(u(o,i),d=!0):r[n]||(d=l(n));if(d)c(t);else for(e=0;a[t].length>e;e++){var h=s[n=a[t][e]];h||(s[n]=h={}),h[n]=!0}return i.pop(),d}function u(t,o){var i=[].concat(o).concat(t);e?e(i):n.push(i)}function d(e){!function(e){for(var o=0;t.length>o;o++)o>=e&&t[o]||(t[o]=[]),t[o]=t[o].filter(function(t){return t>=e})}(e);for(var o,n=function(t){for(var e=t.length,o=Array(e),n=Array(e),i=Array(e),r=Array(e),s=Array(e),a=Array(e),c=0;e>c;++c)o[c]=-1,n[c]=0,i[c]=!1,r[c]=0,s[c]=-1,a[c]=[];var l,u=0,d=[],h=[];function f(e){var c=[e],l=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;l.length>0;){var f=t[e=l[l.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var y=f[p];if(0>o[y]){o[y]=n[y]=u,i[y]=!0,u+=1,c.push(y),l.push(y);break}i[y]&&(n[e]=0|Math.min(n[e],n[y])),0>s[y]||a[e].push(s[y])}r[e]=p}else{if(n[e]===o[e]){var g=[],m=[],x=0;for(p=c.length-1;p>=0;--p){var b=c[p];if(i[b]=!1,g.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){c.length=p;break}}d.push(g);var v=Array(x);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--x]=m[p][w];h.push(v)}l.pop()}}}for(c=0;e>c;++c)0>o[c]&&f(c);for(c=0;h.length>c;c++){var p=h[c];if(0!==p.length){p.sort(function(t,e){return t-e}),l=[p[0]];for(var y=1;p.length>y;y++)p[y]!==p[y-1]&&l.push(p[y]);h[c]=l}}return{components:d,adjacencyList:h}}(t),i=n.components.filter(function(t){return t.length>1}),r=1/0,s=0;i.length>s;s++)for(var a=0;i[s].length>a;a++)r>i[s][a]&&(r=i[s][a],o=s);var c=i[o];return!!c&&{leastVertex:r,adjList:t.map(function(t,e){return-1===c.indexOf(e)?[]:t.filter(function(t){return-1!==c.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var f=d(o);if(o=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var y=0;a[p].length>y;y++){var g=a[p][y];r[+g]=!1,s[g]={}}l(o),o+=1}else o=h}return e?void 0:n}function um(t){return t.y0-t.y1>0?"up":"down"}function dm(t,e){return e(t.source)==e(t.target)}function hm(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var o=0;return t.target.targetLinks.forEach(function(t){o=t.circular?o+1:o}),1>=e&&1>=o}function fm(t){return t.target.x0-t.source.x1}function pm(t,e){var o=gm(t),n=fm(e)/Math.tan(o);return"up"==um(t)?t.y1-n:t.y1+n}function ym(t,e){var o=gm(t),n=fm(e)/Math.tan(o);return"up"==um(t)?t.y1+n:t.y1-n}function gm(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function mm(t,e){return e(t)}function xm(t){return vm(t.source)}function bm(t){return vm(t.target)}function vm(t){return(t.y0+t.y1)/2}function wm(t){return t.virtual?0:t.value}function km(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!dm(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!dm(t,e)?n+1:n}),o+n}function Am(t){return t.target.depth}function Sm(t,e){return t.sourceLinks.length?t.depth:e-1}function Mm(t,e){return t.y0-e.y0}function _m(t,e){return e.y0-t.y0}function Pm(t,e){return t.y1-e.y1}function Lm(t,e){return e.y1-t.y1}function $m(t,e){return Tm(t.source,e.source)||t.index-e.index}function Rm(t,e){return Tm(t.target,e.target)||t.index-e.index}function Tm(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function Im(t,e){return Cm(t)==Cm(e)?"bottom"==t.circularLinkType?_m(t,e):Mm(t,e):Cm(e)-Cm(t)}function Cm(t){return t.target.column-t.source.column}function Om(t,e){return Fm(t)==Fm(e)}function Fm(t){return t.y0-t.y1>0?"up":"down"}import{min as Dm}from"d3-array";function zm(t,e,o,n,i){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=Dm(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var c=r.links.filter(function(t){return t.circular});return c.sort(function(t,e){return e.value-t.value}),c.forEach(function(t,e){t._circularStub=e>=4}),Nm(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),Nm(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,o),r.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+n,t.circularPathData.rightNodeBuffer=5,t.circularPathData.leftNodeBuffer=5,t.circularPathData.sourceWidth=t.source.x1-t.source.x0,t.circularPathData.sourceX=t.source.x0+t.circularPathData.sourceWidth,t.circularPathData.targetX=t.target.x0,t.circularPathData.sourceY=t.y0,t.circularPathData.targetY=t.y1,dm(t,e)&&hm(t))t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,c=t.circularLinkType,l=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==c});l.sort("bottom"==t.circularLinkType?_m:Mm);var u=0;l.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),s=t.target.column,(l=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==c})).sort("bottom"==t.circularLinkType?Lm:Pm),u=0,l.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,o=t.y0,n=t.target.x0,i=t.y1,r=(e+n)/2;return"M"+e+","+o+"C"+r+","+o+" "+r+","+i+" "+n+","+i}(t)}),r}function Nm(t,e,o){t.sort(Im);var n=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,i){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(dm(t,e)&&hm(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;n.length>s;s++){var a=n[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&Em(t,a)){var c=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=c>r?c:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function Em(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as Bm,max as Wm,sum as jm,mean as Ym,group as Xm,groups as qm}from"d3-array";function Gm(t){return function(){return t}}function Vm(t){return t.index}function Hm(t){return t.nodes}function Um(t){return t.links}function Km(t,e,o){var n=qm(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});n.forEach(function(i,r){var s=i.length;if(e)i.sort(e);else if(r>0){var a=new Map;i.forEach(function(t,e){var o,n,i,r=(n=0,i=0,(o=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=vm(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=vm(t.target)*e,n+=e}}),n>0?i/n:NaN);a.set(t,{bc:r,idx:e})}),i.sort(function(t,e){var o=a.get(t),n=a.get(e),i=o.bc,r=n.bc;if(t.circularLinkType!==e.circularLinkType){if("top"==t.circularLinkType&&"bottom"==e.circularLinkType)return-1;if("bottom"==t.circularLinkType&&"top"==e.circularLinkType)return 1;if("top"==t.circularLinkType)return-1;if("top"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return-1}return isNaN(i)||isNaN(r)?isNaN(i)?isNaN(r)?o.idx-n.idx:1:-1:i-r})}else i.sort(function(t,e){return t.circularLinkType==e.circularLinkType?km(e,o)-km(t,o):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});i.forEach(function(e,i){e.depth==n.length-1&&1==s||0==e.depth&&1==s?(e.y0=t.y1/2-e.value*t.ky,e.y1=e.y0+e.value*t.ky):e.partOfCycle?0==km(e,o)?(e.y0=t.y1/2+i,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+i,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-i,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*i,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+i,e.y1=e.y0+e.value*t.ky)})})}function Zm(t,e,o,n,i,r){var s=qm(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,c=r;c>0;--c)l(a*=.99,o),u();function l(e,o){var n=s.length;s.forEach(function(i){var r=i.length,s=i[0].depth;i.forEach(function(i){var a;if(i.sourceLinks.length||i.targetLinks.length)if(i.partOfCycle&&km(i,o)>0){var c=Ym(i.sourceLinks,bm),l=Ym(i.targetLinks,xm),u=c&&l?(c+l)/2:c||l;if(u){var d=(u-vm(i))*e*.3;i.y0+=d,i.y1+=d}}else if(0==s&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(s==n-1&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(1==i.targetLinks.length&&1==i.targetLinks[0].source.sourceLinks.length)a=i.y1-i.y0,i.y0=i.targetLinks[0].source.y0,i.y1=i.y0+a;else{var h=Ym(i.sourceLinks,bm),f=Ym(i.targetLinks,xm),p=((h&&f?(h+f)/2:h||f)-vm(i))*e;i.y0+=p,i.y1+=p}})})}function u(){s.forEach(function(o){var r,s,a,c=t.y0,l=o.length;for(o.sort(e||Tm),a=0;l>a;++a)(s=c-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),c=r.y1+n;if((s=c-n-t.y1)>0)for(c=r.y0-=s,r.y1-=s,a=l-2;a>=0;--a)(s=(r=o[a]).y1+i-c)>0&&(r.y0-=s,r.y1-=s),c=r.y0})}}function Qm(t){t.nodes.forEach(function(t){t.sourceLinks.sort(Rm),t.targetLinks.sort($m)}),t.nodes.forEach(function(t){var e=t.y0,o=e,n=t.y1,i=n;t.sourceLinks.forEach(function(t){t.circular?(t.y0=n-t.width/2,n-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=i-t.width/2,i-=t.width):(t.y1=o+t.width/2,o+=t.width)})})}function Jm(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=Vm,c=Sm,l=void 0,u=32,d=2,h=Hm,f=Um;function p(){var p={nodes:h.apply(null,arguments),links:f.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=o,h.y1=n,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var o=function(t,e){var o=new Map;return Xm(t,e).forEach(function(t,e){o.set(e,t[0])}),o}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var n=t.source,i=t.target;"object"!=typeof n&&(n=t.source=cm(o,n)),"object"!=typeof i&&(i=t.target=cm(o,i)),n.sourceLinks.push(t),i.targetLinks.push(t)})}(h,a),function(t,e){var o=0;if(null==e){for(var n=[],i=0;t.links.length>i;i++){var r=t.links[i],s=r.source.index,a=r.target.index;n[s]||(n[s]=[]),n[a]||(n[a]=[]),-1===n[s].indexOf(a)&&n[s].push(a)}var c=lm(n);c.sort(function(t,e){return t.length-e.length});var l={};for(i=0;c.length>i;i++){var u=c[i].slice(-2);l[u[0]]||(l[u[0]]={}),l[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||l[n]&&l[n][e]?(t.circular=!0,t.circularLinkID=o++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=o++)})}(h,l),function(t,e){var o=0,n=0;t.links.forEach(function(i){i.circular&&(i.circularLinkType=i.source.circularLinkType||i.target.circularLinkType?i.source.circularLinkType?i.source.circularLinkType:i.target.circularLinkType:n>o?"top":"bottom","top"==i.circularLinkType?o++:n++,t.nodes.forEach(function(t){mm(t,e)!=mm(i.source,e)&&mm(t,e)!=mm(i.target,e)||(t.circularLinkType=i.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),dm(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(jm(t.sourceLinks,wm),jm(t.targetLinks,wm)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,o){var n,i,r;if(null!=e){t.nodes.sort(function(t,o){return e(t)<e(o)?-1:1});var s=0,a=e(t.nodes[0]);t.nodes.forEach(function(t){s=e(t)==a?s:s+1,a=e(t)==a?a:e(t),t.column=s})}for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>i.indexOf(t.target)&&!t.circular&&i.push(t.target)})});for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>i.indexOf(t.source)&&!t.circular&&i.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?o(t,r):t.column})}(h,l,c);var f=r;if(null!==s){var p=qm(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),y=Wm(p,function(t){return t.length});y>1&&(f=Math.max(1,(n-e)*s/(y-1)))}(function(t,e,o){var n=qm(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var i=Bm(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/jm(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=Wm(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-o)/r),e.x1=e.x0+o}:function(e){e.x0=t.x0,e.x1=e.x0+o})})(h,f,i),Km(h,l,a),Zm(h,l,a,f,f,u),Qm(h),zm(h,a,d,10,8),Km(h,l,a),Zm(h,l,a,f,f,u),Qm(h),zm(h,a,d,10,8),function(t,e){let o=t;o.nodes.forEach(function(t){t.y+(t.y1-t.y0)>o.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-o.y1));var n=o.links.filter(function(o){return mm(o.source,e)==mm(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!Om(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=pm(e,t);return t.y1-o}if(e.target.column>t.target.column)return pm(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;n.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let o=t;o.nodes.forEach(function(t){var n=o.links.filter(function(o){return mm(o.target,e)==mm(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!Om(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=ym(e,t);return t.y0-o}if(e.source.column>t.source.column)return ym(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;n.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,o=t.links,n=!1,i=!1;if(o.forEach(function(t){"top"==t.circularLinkType?n=!0:"bottom"==t.circularLinkType&&(i=!0)}),0==n||0==i){let n=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=Bm(e,function(t){return t.y0}),s=Wm(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1)}),o.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,o=n(t.y0)-t.y0;t.y0=n(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+o}),t.targetLinks.forEach(function(t){t.y1=t.y1+o})})}}(h),zm(h,a,d,10,8)}(p),p}return p.update=function(t){return Qm(t),zm(t,a,d,10,8),t},p.nodeWidth=function(t){return arguments.length?(i=+t,p):i},p.nodePadding=function(t){return arguments.length?(r=+t,p):r},p.nodePaddingRatio=function(t){return arguments.length?(s=+t,p):s},p.nodes=function(t){return arguments.length?(h="function"==typeof t?t:Gm(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:Gm(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:Gm(t),p):a},p.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:Gm(t),p):c},p.nodeSort=function(t){return arguments.length?(l=t,p):l},p.iterations=function(t){return arguments.length?(u=+t,p):u},p.circularLinkGap=function(t){return arguments.length?(d=+t,p):d},p.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],o=+i[1][0],n=+i[1][1],p):[[t,e],[o,n]]},p.size=function(i){return arguments.length?(t=e=0,o=+i[0],n=+i[1],p):[o-t,n-e]},p}import{interpolateNumber as tx}from"d3-interpolate";import{line as ex,curveLinearClosed as ox}from"d3-shape";var nx=t=>{let e,o,n,i,r,s,a,c,l;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,o=t.y1-t.sankeyWidth/2,n=t.y1+t.sankeyWidth/2,i=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=tx(r,s),c=a(.5),l=a(.5),`M${e},${r}C${e},${c} ${o},${l} ${o},${s}L${n},${s}C${n},${l} ${i},${c} ${i},${r}Z`;const u=t.sankeyWidth/2,d=tx(t.source.x1,t.target.x0),{pathD:h}=ti({sx:t.source.x1,sTop:t.y0-u,sBot:t.y0+u,tx:t.target.x0,tTop:t.y1-u,tBot:t.y1+u,cp1X:d(.5),cp2X:d(.5)});return h};function ix(t){const e=t.sankeyWidth/2,o=(t._circularWidth??t.sankeyWidth)/2,n=t.circularPathData;if(!n)return null;if("down"===t.direction)return null;if(t._circularStub){const o=n.sourceX,i=n.sourceY,r=n.targetX,s=n.targetY;if("object"!=typeof t.source||!t.source||"object"!=typeof t.target||!t.target)return null;const a=Math.max(15,Math.min(40,.33*(n.rightFullExtent-o))),c=Math.max(15,Math.min(40,.33*(r-n.leftFullExtent)));return`M${o},${i-e}L${o+a},${i-e}L${o+a},${i+e}L${o},${i+e}ZM${r},${s-e}L${r-c},${s-e}L${r-c},${s+e}L${r},${s+e}Z`}const i=n.sourceX,r=n.sourceY,s=n.targetX,a=n.targetY,c=n.rightFullExtent,l=n.leftFullExtent,u=n.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(o,15));return`M${i},${r-d*e}L${c},${r-d*e}L${c+o},${r-d*e+d*h}L${c+o},${u+d*o-d*h}L${c+o-h},${u+d*o}L${l-o+h},${u+d*o}L${l-o},${u+d*o-d*h}L${l-o},${a-d*e+d*h}L${l-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${l+o},${a+d*e}L${l+o},${u-d*o}L${c-o},${u-d*o}L${c-o},${r+d*e}L${i},${r+d*e}Z`}var rx=new Set,sx=new WeakMap;function ax(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let o=sx.get(t);if(o){const t=o.get(e);if(t)return t}else o=new Map,sx.set(t,o);const n=new Proxy(t,{get(t,o,n){if("string"==typeof o&&!(o in t)&&t.data&&o in t.data){const t=`${e}:${o}`;rx.has(t)||(rx.add(t),console.warn(`[Semiotic] "${e}" callback accessed "${o}" on the wrapper object, but it only exists on ".data". Use d.data.${o} (or d.data?.${o}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(t,o,n)}});return o.set(e,n),n}var cx={left:function(t){return t.depth},right:function(t,e){return e-1-t.height},center:function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?Math.min.apply(Math,t.sourceLinks.map(Am))-1:0},justify:Sm},lx={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i="vertical"===o.orientation?"down":"right",r=o.nodeAlign||"justify",s=o.nodeWidth??15,a=o.nodePaddingRatio??.05,c=o.iterations??100,l=t.map(t=>({...t})),u=e.map(t=>({...t,source:Xl(t.source),target:Xl(t.target),value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===i?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const h=Jm().extent(d).links(u).nodes(l).nodeAlign(cx[r]||Sm).nodeId(t=>t.id).nodeWidth(s).iterations(c);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of l)t>n.x0&&(t=n.x0),n.x1>e&&(e=n.x1),o>n.y0&&(o=n.y0),n.y1>i&&(i=n.y1);for(const n of u){if(!n.circular||!n.circularPathData)continue;const r=n.circularPathData,s=(n._circularWidth??n.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),o>r.verticalFullExtent-s&&(o=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=e-t,s=i-o,a=n[0],c=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>c)){const e=Math.min(a/r,c/s),n=-t*e+(a-r*e)/2,i=-o*e+(c-s*e)/2;for(const t of l)t.x0=t.x0*e+n,t.x1=t.x1*e+n,t.y0=t.y0*e+i,t.y1=t.y1*e+i;for(const t of u)if(t.y0=t.y0*e+i,t.y1=t.y1*e+i,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const o=t.circularPathData;o.sourceX=o.sourceX*e+n,o.targetX=o.targetX*e+n,o.sourceY=o.sourceY*e+i,o.targetY=o.targetY*e+i,o.rightFullExtent=o.rightFullExtent*e+n,o.leftFullExtent=o.leftFullExtent*e+n,o.verticalFullExtent=o.verticalFullExtent*e+i,o.rightInnerExtent=o.rightInnerExtent*e+n,o.leftInnerExtent=o.leftInnerExtent*e+n,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+i,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+i,o.rightSmallArcRadius*=e,o.rightLargeArcRadius*=e,o.leftSmallArcRadius*=e,o.leftLargeArcRadius*=e,o.sourceWidth*=e,o.rightNodeBuffer*=e,o.leftNodeBuffer*=e,o.arcRadius*=e}}}const f=new Map;for(const e of t)f.set(e.id,e);for(const t of l){const e=f.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const p=new Map;for(const t of e)if(t._edgeKey)p.set(t._edgeKey,t);else{const e=Xl(t.source),o=Xl(t.target);p.set(`${e}\0${o}`,t)}for(const t of u){const e=Xl(t.source),o=Xl(t.target),n=p.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(n){n.y0=t.y0,n.y1=t.y1,n.sankeyWidth=t.width??0,n.circular=!!t.circular,n.circularPathData=t.circularPathData,n._circularWidth=t._circularWidth,n._circularStub=t._circularStub,n.path=t.path,n.circularLinkType=t.circularLinkType,n.direction=i;const r=f.get(e),s=f.get(o);r&&(n.source=r),s&&(n.target=s)}}},buildScene(t,e,o,n){const i="vertical"===o.orientation?"down":"right",r=o.nodeStyle,s=o.edgeStyle,a=o.edgeOpacity??.5,c=o.edgeColorBy||"source",l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:w,u=new Map;t.forEach((t,e)=>{u.set(t.id,l[e%l.length])});const d=[],h=[],f=[],p=new Map;for(const e of t){const t=e.x1-e.x0,o=e.y1-e.y0;if(0>=t||0>=o)continue;const n=r?r(ax(e,"nodeStyle")):{},s={fill:n.fill||u.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity,cursor:n.cursor};p.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===i?{type:"rect",x:e.y0,y:e.x0,w:o,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:o,style:s,datum:e,id:e.id,label:e.id})}const y=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of y){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";i="function"==typeof c?c(t)||i:"target"===c?p.get(n.id)||u.get(n.id)||i:p.get(e.id)||u.get(e.id)||i;const r=s?s(ax(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,o=t.sankeyWidth/2,n=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),c=r.fill||i;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-o}L${e.sourceX+n},${e.sourceY-o}L${e.sourceX+n},${e.sourceY+o}L${e.sourceX},${e.sourceY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+n}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-o}L${e.targetX-s},${e.targetY-o}L${e.targetX-s},${e.targetY+o}L${e.targetX},${e.targetY+o}Z`,style:{fill:c,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let l;(l=t.circular&&t.circularPathData?ix(t):nx(t),l)&&h.push({type:"bezier",pathD:l,bezierCache:t.bezier,style:{fill:r.fill||i,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor},datum:t})}if(!1!==o.showLabels){const e=Yl(o.nodeLabel);for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=e?e(o):o.id;if(!s)continue;let a,c,l;"down"===i?(a=o.y0+(o.y1-o.y0)/2,c=o.x1+14,l="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,l="end"):(a=o.x1+6,l="start"),c=o.y0+r/2),f.push({x:a,y:c,text:s+"",anchor:"down"===i?"middle":l,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}};am("sankey",lx);import{forceSimulation as ux,forceCenter as dx,forceX as hx,forceY as fx,forceLink as px,forceManyBody as yx,forceCollide as gx}from"d3-force";import{scaleLinear as mx}from"d3-scale";function xx(t,e,o){if(o.some(t=>null!=t.__forceRadius))return t=>t.__forceRadius??8;if(null==t)return()=>8;if("number"==typeof t)return()=>t;if("function"==typeof t)return e=>t(e)||8;const n=e||[5,20],i=[];for(const e of o){const o=e.data?.[t];"number"==typeof o&&i.push(o)}if(0===i.length)return()=>n[0];const[r,s]=Pt(i);if(r===s)return()=>(n[0]+n[1])/2;const a=mx().domain([r,s]).range(n).clamp(!0);return e=>{const o=e.data?.[t];return null==o||"number"!=typeof o?n[0]:a(o)}}var bx={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i=o.forceStrength??.1,r=n[0]/2,s=n[1]/2,a=Math.max(.1,Math.min(1,Math.min(n[0],n[1])/200)),c=Math.min(.5,.06+1.8*(1-a)),l=o.__previousPositions;let u=0;const d=[];for(const e of t){const t=null!=e.x&&null!=e.y&&(0!==e.x||0!==e.y),o=l?.get(e.id);t?u++:o?(e.x=o.x,e.y=o.y,u++):d.push(e)}const h=u>0&&.3>=(t.length>0?d.length/t.length:1);if(h){const o=new Map;for(const e of t)o.set(e.id,e);for(const t of d){const n=vx(t.id,e,o);if(n.length>0){let e=0,o=0;for(const t of n)e+=t.x,o+=t.y;const i=wx(t.id),r=i%360*(Math.PI/180),s=(10+i%20)*a;t.x=e/n.length+s*Math.cos(r),t.y=o/n.length+s*Math.sin(r)}else{const e=wx(t.id),o=e%360*(Math.PI/180),n=(15+e%30)*a;t.x=r+n*Math.cos(o),t.y=s+n*Math.sin(o)}}}else{const e=2.399963229728653;for(let o=0;t.length>o;o++){const n=t[o];if(null==n.x||null==n.y||0===n.x&&0===n.y){const t=10*Math.sqrt(o+.5)*a,i=o*e;n.x=r+t*Math.cos(i),n.y=s+t*Math.sin(i)}}}const f=o.__skipForceSimulation||0===o.iterations?0:h?40:o.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),p=xx(o.nodeSize,o.nodeSizeRange,t),y=t=>p(t);if(f>0){const l=new Map,u=new Map;for(const e of t)l.set(e.id,0),u.set(e.id,e);for(const t of e){const e=Xl(t.source),o=Xl(t.target);l.set(e,(l.get(e)??0)+1),l.set(o,(l.get(o)??0)+1)}const d=px().strength(t=>{const e=t.weight,o=Xl(t.source),n=Xl(t.target),r=Math.max(1,Math.min(l.get(o)??1,l.get(n)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*i/(.1*r))}).distance(t=>{const e="string"==typeof t.source?u.get(t.source):t.source,o="string"==typeof t.target?u.get(t.target):t.target,n=(e?y(e):0)+(o?y(o):0)+Math.max(6,12*a);return Math.max(16,40*a,n)}).id(t=>t.id),p=ux();if(void 0===o.random&&void 0===o.seed||p.randomSource(o.random??function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(o.seed)),p.force("charge",yx().strength(t=>{const e=l.get(t.id)??0;return-15*a*y(t)*Math.sqrt(e+1)})).force("collide",gx(t=>y(t)+3*a).strength(.9).iterations(2)).force("center",dx(r,s).strength(.8)).force("x",hx(r).strength(c)).force("y",fx(s).strength(c)).force("bounds",function(t,e,o=2,n=.6){let i=[];const r=r=>{const s=n*Math.max(r,.2);for(const n of i){const i=n.x??t[0]/2,r=n.y??t[1]/2,a=n.vx??0,c=n.vy??0,l=e(n)+o,u=Math.min(t[0]/2,l),d=Math.max(t[0]/2,t[0]-l),h=Math.min(t[1]/2,l),f=Math.max(t[1]/2,t[1]-l),p=i+a,y=r+c;u>p?n.vx=a+(u-p)*s:p>d&&(n.vx=a+(d-p)*s),h>y?n.vy=c+(h-y)*s:y>f&&(n.vy=c+(f-y)*s)}};return r.initialize=t=>{i=t},r}(n,y)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:Xl(t.source),target:Xl(t.target)}));d.links(t),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let t=0;f>t;++t)p.tick()}for(const e of t){if(null==e.x||null==e.y)continue;const t=y(e),o=f>0?2:0,i=Math.min(n[0]/2,t+o),r=Math.min(n[1]/2,t+o);e.x=Math.max(i,Math.min(n[0]-i,e.x)),e.y=Math.max(r,Math.min(n[1]-r,e.y)),e.x0=0,e.x1=0,e.y0=0,e.y1=0}const g=new Map;for(const e of t)g.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=g.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=g.get(t.target);e&&(t.target=e)}}},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=xx(o.nodeSize,o.nodeSizeRange,t),a=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:w,c=new Map;t.forEach((t,e)=>{c.set(t.id,a[e%a.length])});const l=[],u=[],d=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(ax(e,"nodeSize")),n=i?i(ax(e,"nodeStyle")):{},r={fill:n.fill||c.get(e.id)||o.themeSemantic?.primary||"#007bff",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??2,opacity:n.opacity,cursor:n.cursor};l.push({type:"circle",cx:e.x,cy:e.y,r:t,style:r,datum:e,id:e.id,label:e.id})}const h=new Map;for(const e of t)h.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:h.get(t.source),n="object"==typeof t.target?t.target:h.get(t.target);if(!e||!n)continue;if(null==e.x||null==e.y)continue;if(null==n.x||null==n.y)continue;const i=r?r(ax(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:n.x,y2:n.y,style:{stroke:i.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:i.strokeWidth??1,opacity:i.opacity??.6,cursor:i.cursor},datum:t})}if(!1!==o.showLabels){const e=Yl(o.nodeLabel);for(const o of t){if(null==o.x||null==o.y)continue;const t=e?e(o):o.id;if(!t)continue;const n=s(ax(o,"nodeSize"));d.push({x:o.x,y:o.y-n-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:l,sceneEdges:u,labels:d}}};function vx(t,e,o){const n=[];for(const i of e){const e=Xl(i.source),r=Xl(i.target);let s=null;if(e===t?s=r:r===t&&(s=e),s){const t=o.get(s);!t||0===t.x&&0===t.y||n.push({x:t.x,y:t.y})}}return n}function wx(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}am("force",bx);import{chord as kx,ribbon as Ax}from"d3-chord";import{arc as Sx}from"d3-shape";var Mx=w,_x={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(n[0],n[1])/2,c=a-r,l=n[0]/2,u=n[1]/2,d=(h=o.valueAccessor)?"function"==typeof h?h:t=>t[h]??1:t=>t.value??1;var h;const f=new Map;for(let e=0;t.length>e;e++)f.set(t[e].id,e);const p=t.length,y=Array.from({length:p},()=>Array.from({length:p},()=>0));for(const t of e){const e=Xl(t.source),o=Xl(t.target),n=f.get(e),i=f.get(o);if(void 0===n||void 0===i)continue;const r=d(t);y[n][i]=r}const g=kx().padAngle(i);s&&g.sortGroups(s);const m=g(y),x=m.groups,b=Sx().innerRadius(c).outerRadius(a);for(const e of x){const o=t[e.index],n=b.centroid({innerRadius:c,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=n[0]+l,o.y=n[1]+u,o.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const v=new Map;for(const e of t)v.set(e.id,e);for(const t of e){const e=Xl(t.source),o=Xl(t.target),n=v.get(e),i=v.get(o);n&&(t.source=n),i&&(t.target=i)}const w=new Map;for(const t of e){const e=Xl(t.source),o=Xl(t.target);w.set(`${e}\0${o}`,t)}for(const e of m){const o=t[e.source.index].id,n=t[e.target.index].id,i=w.get(`${o}\0${n}`)||w.get(`${n}\0${o}`);i&&(i.__chordData=e)}},buildScene(t,e,o,n){const{groupWidth:i=20,edgeOpacity:r=.5}=o,s=Math.min(n[0],n[1])/2,a=s-i,c=n[0]/2,l=n[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",f=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Mx,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const y=Ax().radius(a),g=[],m=[],x=[];for(let e=0;t.length>e;e++){const o=t[e],n=o.__arcData;if(!n)continue;let i;if(u){const t=u(ax(o,"nodeStyle"));i=("string"==typeof t.fill?t.fill:void 0)||p.get(o.id)||f[e%f.length]}else i=p.get(o.id)||f[e%f.length];const r=u?u(ax(o,"nodeStyle")):{};g.push({type:"arc",cx:c,cy:l,innerR:a,outerR:s,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:{fill:i,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const n=y(e);if(!n)continue;const i=Px(n,c,l);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(ax(t,"edgeStyle"));s=("string"==typeof e.fill?e.fill:void 0)||s}else{const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;"target"===h&&o?s=p.get(o.id)||s:e&&(s=p.get(e.id)||s)}const a=d?d(ax(t,"edgeStyle")):{};m.push({type:"ribbon",pathD:i,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor},datum:t})}if(!1!==o.showLabels){const e=Yl(o.nodeLabel),n=s+12;for(const o of t){const t=o.__arcData;if(!t)continue;const i=e?e(o):o.id;if(!i)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:c+Math.cos(s)*n,y:l+Math.sin(s)*n,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:g,sceneEdges:m,labels:x}}};function Px(t,e,o){const n=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return t;const i=[];let r=0;for(;n.length>r;){const t=n[r];if("M"===t||"L"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("C"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;3>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("Q"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;2>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("A"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&(i.push(Number(n[r])+e+""),r++),n.length>r&&(i.push(Number(n[r])+o+""),r++);else"Z"===t||"z"===t?(i.push(t),r++):(i.push(n[r]),r++)}return i.join(" ")}am("chord",_x);import{hierarchy as Lx,tree as $x,cluster as Rx,treemap as Tx,pack as Ix,partition as Cx,treemapBinary as Ox}from"d3-hierarchy";var Fx=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Dx(t){const[e,o,n]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(t);return.299*e+.587*o+.114*n>150?"#222":"#fff"}function zx(t,e,o){const n=e.nodeIDAccessor;return"function"==typeof n?n(t.data)+"":"string"==typeof n&&void 0!==t.data[n]?t.data[n]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+o}function Nx(t){if(!t)return null;if("function"==typeof t){const e=t;return t=>e(t.data??t)}return e=>e.data?.[t]||e[t]||e.id}function Ex(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Fx}function Bx(t){return Array.isArray(t.colorScheme)&&t.colorScheme.length>0?t.colorScheme[0]:t.themeSemantic?.primary?t.themeSemantic.primary:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical[0]:"#4d430c"}function Wx(t,e,o,n,i){if("horizontal"===i){const i=(t+o)/2;return`M ${t},${e} C ${i},${e} ${i},${n} ${o},${n}`}if("radial"===i){const i=(t+o)/2;return`M ${t},${e} Q ${i},${e} ${i},${(e+n)/2} T ${o},${n}`}{const i=(e+n)/2;return`M ${t},${e} C ${t},${i} ${o},${i} ${o},${n}`}}var jx={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;if(!i)return;const r=o.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(o.childrenAccessor),a=o.hierarchySum,c="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,l=Lx(i,s);l.sum(c),l.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=n;switch(r){case"tree":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=$x();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(l,o,u,d);break;case"cluster":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=Rx();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(l,o,u,d);break;case"treemap":!function(t,e,o,n){const i=e.padding??4,r=e.paddingTop??0,s=Tx().size([o,n]).tile(Ox).padding(i);r>0&&s.paddingTop(r),s(t)}(l,o,u,d);break;case"circlepack":!function(t,e,o,n){const i=e.padding??4;Ix().size([o,n]).padding(i)(t)}(l,o,u,d);break;case"partition":!function(t,e,o,n){Cx().size([o,n]).padding(e.padding??1)(t)}(l,o,u,d)}const h=l.descendants();t.length=0,e.length=0;const f=new Map;for(let e=0;h.length>e;e++){const n=h[e],i={id:zx(n,o,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:n.value??0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===r||"cluster"===r?Yx(i,n,o):"treemap"===r||"partition"===r?Xx(i,n):"circlepack"===r&&qx(i,n),i.__hierarchyNode=n,t.push(i),f.set(n,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=f.get(t.parent),n=f.get(t);o&&n&&e.push({source:o,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,n){const i=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,n,i,r){const s=[],a=[],c=[],l=o.treeOrientation||"vertical",u="radial"===l,d=n[0]/2,h=n[1]/2,f="number"==typeof(p=o.nodeSize)?p:5;var p;for(const e of t){let t=e.x,n=e.y;u&&(t+=d,n+=h);const r=i(ax(e,"nodeStyle"));let a=r.fill||Bx(o);if(o.colorByDepth&&void 0!==e.depth){const t=Ex(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:n,r:f,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const y=o.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=e.x,s=e.y,c=n.x,f=n.y;u&&(i+=d,s+=h,c+=d,f+=h);const p=Wx(i,s,c,f,l),g=r(ax(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:g.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:g.strokeWidth??1.5,opacity:g.opacity??y,cursor:g.cursor},datum:t})}if(!1!==o.showLabels){const e=Nx(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let n,i,r,s=o.x,a=o.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,o=Math.sqrt(t*t+e*e);o>0?(n=s+t/o*10,i=a+e/o*10,r=0>t?"end":"start"):(n=s,i=a-12,r="middle")}else"horizontal"===l?(o.data?.children&&0!==o.data.children.length?(n=s-f-6,r="end"):(n=s+f+6,r="start"),i=a):(n=s,i=a+f+14,r="middle");c.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:c}}(t,e,o,n,i,r);case"treemap":case"partition":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=n(ax(o,"nodeStyle"));let a=s.fill||Bx(e);if(e.colorByDepth&&void 0!==o.depth){const t=Ex(e);a=t[o.depth%t.length]}i.push({type:"rect",x:o.x0,y:o.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity,cursor:s.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=Nx(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,c=a.y1-a.y0;if(0>=t||0>=c)continue;const l=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!l)continue;if("parent"===i&&l)continue}const u=o?o(a):a.id;if(!u)continue;if((l?30:40)>t||(l?16:14)>c)continue;let d=n(ax(a,"nodeStyle")).fill||Bx(e);if(e.colorByDepth&&void 0!==a.depth){const t=Ex(e);d=t[a.depth%t.length]}const h="string"==typeof d?Dx(d):e.themeSemantic?.text??"#000";r.push(l?{x:a.x0+t/2,y:a.y0+c/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,c)/6)),fill:h}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,o,0,i);case"circlepack":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.__radius??5;if(0>=t)continue;const r=n(ax(o,"nodeStyle"));let s=r.fill||Bx(e);if(e.colorByDepth&&void 0!==o.depth){const t=Ex(e);s=t[o.depth%t.length]}i.push({type:"circle",cx:o.x,cy:o.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7,cursor:r.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=Nx(e.nodeLabel);for(const i of t){const t=i.__radius??5,s=o?o(i):i.id;if(!s)continue;if(15>t)continue;const a=!(i.data?.children&&i.data.children.length>0);let c=n(ax(i,"nodeStyle")).fill||Bx(e);if(e.colorByDepth&&void 0!==i.depth){const t=Ex(e);c=t[i.depth%t.length]}if(a){const o="string"==typeof c?Dx(c):e.themeSemantic?.text??"#000";r.push({x:i.x,y:i.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:o})}else r.push({x:i.x,y:i.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,o,0,i);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Yx(t,e,o){const n=o.treeOrientation||"vertical";if("radial"===n){const o=e.x,n=e.y;t.x=n*Math.cos(o-Math.PI/2),t.y=n*Math.sin(o-Math.PI/2)}else"horizontal"===n?(t.x=e.y,t.y=e.x):(t.x=e.x,t.y=e.y);t.x0=t.x-5,t.x1=t.x+5,t.y0=t.y-5,t.y1=t.y+5,t.width=10,t.height=10}function Xx(t,e){t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.x=(e.x0+e.x1)/2,t.y=(e.y0+e.y1)/2,t.width=e.x1-e.x0,t.height=e.y1-e.y0}function qx(t,e){const o=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-o,t.x1=e.x+o,t.y0=e.y-o,t.y1=e.y+o,t.width=2*o,t.height=2*o,t.__radius=o}am("tree",jx),am("cluster",jx),am("treemap",jx),am("circlepack",jx),am("partition",jx);import{pie as Gx}from"d3-shape";function Vx(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var Hx={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;i&&function(t,e,o,n,i){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(o.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(o.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(o.orbitMode),c=o.orbitSize??2.95,l=o.orbitEccentricity??1,u="number"==typeof c?()=>c:c,d="number"==typeof l?()=>l:l,h=Vx(o);h.metaMap.clear(),n.length=0,i.length=0;const f=new Map;function p(t){const e=f.get(t)??0;return f.set(t,e+1),0===e?t:`${t}__${e}`}const y=e[0]/2,g=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=p(s(t));n.push({id:x,x:y,y:g,x0:y,x1:y,y0:g,y1:g,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,o,c,l,f,y,g){const m=r(e);if(!m?.length)return;const x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const A=(x+1)/b,S={id:o,depth:y,data:e,parentId:o},M=g?f/u(S)*A:f*A,_=Gx().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(S);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),d=c+M*Math.sin(r),f=l+M*Math.cos(r)*P;n.push({id:u,x:d,y:f,x0:d,x1:d,y0:f,y1:f,width:0,height:0,value:0,depth:y,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:y,parentId:o,eccentricity:P}),i.push({source:o,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:o,target:u}}),t(a,u,d,f,M,y+1,!0)}k+=v}}(t,x,y,g,m,1,!1)}(i,n,o,t,e)},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=o.nodeSize,a="number"==typeof s?()=>s:"function"==typeof s?s:()=>6,c=[],l=[],u=[];if(!1!==o.orbitShowRings){const e=Vx(o),n=new Map;for(const e of t)n.set(e.id,e);const i=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=n.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;i.has(o)||i.set(o,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:t,parentY:e,ring:o,ecc:n}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,c=(i+1)/r*Math.PI*2;l.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(c),y2:e+o*Math.cos(c)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(ax(e,"nodeSize")),n=i?i(ax(e,"nodeStyle")):{};c.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:n.fill||o.themeSemantic?.primary||"#6366f1",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??1,opacity:n.opacity??(0===(e.depth??0)?1:.85),cursor:n.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const d=new Map;for(const e of t)d.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:d.get(t.source),o="object"==typeof t.target?t.target:d.get(t.target);if(!e||!o)continue;if(null==e.x||null==o.x)continue;const n=r?r(ax(t,"edgeStyle")):{};l.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:n.stroke||"rgba(128,128,128,0.35)",strokeWidth:n.strokeWidth??.5,opacity:n.opacity??1,cursor:n.cursor},datum:t})}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=a(ax(o,"nodeSize"));if(4>=t)continue;const n="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;u.push({x:o.x,y:o.y+t+12,text:n+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:c,sceneEdges:l,labels:u}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=Vx(e),n=e.orbitSpeed??.25,i=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-o.startTime)/1e3,s=n*(Math.PI/6),a=new Map;for(const e of t)a.set(e.id,e);for(const e of t){const t=o.metaMap.get(e.id);if(!t||!t.parentId)continue;const n=a.get(t.parentId);if(!n)continue;const c=t.angle+r*s*i({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=n.x+t.ring*Math.sin(c),e.y=n.y+t.ring*Math.cos(c)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)};function Ux(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function Kx(t){if("glyph"===t.type&&t.glyph&&"number"==typeof t.size){const e=t.cx??t.x,o=t.cy??t.y;if("number"!=typeof e||"number"!=typeof o)return null;const n=Ph(t.glyph,t.size);return{x:e+n.centerDx,y:o+n.centerDy,r:Math.max(1,n.radius)}}const e=t.cx??(null!=t.x&&null!=t.w?t.x+t.w/2:t.x),o=t.cy??(null!=t.y&&null!=t.h?t.y+t.h/2:t.y);return"number"!=typeof e||"number"!=typeof o?null:{x:e,y:o,r:"number"==typeof t.r?Math.max(1,t.r):"number"==typeof t.outerR?Math.max(1,t.outerR):"number"==typeof t.size?Math.max(1,Yd(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function Zx(t){if(!t)return;const e=[];for(const o of t){const t=Kx(o);t&&e.push({pointId:Ux(o),...t})}return e}am("orbit",Hx);import{Fragment as Qx,jsxs as Jx}from"react/jsx-runtime";function tb(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}am("sankey",lx),am("force",bx),am("chord",_x),am("tree",jx),am("cluster",jx),am("treemap",jx),am("circlepack",jx),am("partition",jx),am("orbit",Hx);var eb=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function ob(t){return t.map(t=>{const e=t.datum&&"object"==typeof t.datum?t.datum:{},o=e.data&&"object"==typeof e.data?e.data:e,n="cx"in t?t.cx:t.x+t.w/2,i="cy"in t?t.cy:t.y+t.h/2;return{...o,...null==o.id&&null!=t.id?{id:t.id}:{},x:n,y:i}})}function nb(t,e){const o=St(t.theme),n=t.chartType||"force",i=t.size||[500,500],r=function(t){return Dy.has(t)?Fy:Oy}(n),s=ce({...r,...t.margin},t.title),a=se(t.title),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const i=g(t.nodes||[]);if(i.length>0)return Tf(i,e);if(eb.has(n)&&t.data)return Tf($i(t.data,t.childrenAccessor||"children"),e);const r=Array.isArray(t.edges)?g(t.edges):[];if(0===r.length)return[];const s=tb(t.sourceAccessor,"source"),a=tb(t.targetAccessor,"target");return Tf(Array.from(new Set(r.flatMap(t=>[s(t),a(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];_y(s,{props:t,categories:c,theme:o,size:i,hasTitle:a});const l=Py({props:t,categories:c,theme:o,size:i,margin:s,hasTitle:a}),u=i[0]-s.left-s.right,d=i[1]-s.top-s.bottom,h=Iy(t.backgroundGraphics,i,s,null),f=Iy(t.foregroundGraphics,i,s,null),p=()=>{let n;const r=t=>Number(t),a=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:r,y:r},layout:{width:u,height:d},theme:o,frameType:"network",idPrefix:t._idPrefix,onRender:t=>{n=t}}):null;return e&&(e.evidence=(e=>Fh({frameType:"network",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:e,nodeCount:0,edgeCount:0,margin:s}))(n)),rm.renderToStaticMarkup($y(h||f||t.annotations?Jx(Qx,{children:[h,a,f]}):null,{width:i[0],height:i[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))},y=function(t){return sm[t]}(n);if(!y&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const m={chartType:n,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||o.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let x,b;if(eb.has(n)){const e=t.data||t.edges;if(!e||Array.isArray(e))return p();m.__hierarchyRoot=e,x=[],b=[]}else{const e=g(t.nodes||[]),o=Array.isArray(t.edges)?g(t.edges):[];if(0===e.length&&0===o.length)return p();if(b=function(t,e){const o=tb(e.sourceAccessor,"source"),n=tb(e.targetAccessor,"target"),i=tb(e.valueAccessor,"value");return t.map(t=>{const e=Number(i(t));return{source:o(t)+"",target:n(t)+"",value:Number.isFinite(e)?e:1,y0:0,y1:0,sankeyWidth:0,data:t}})}(o,m),0===e.length&&b.length>0){const t=new Set;for(const e of b){const o=vy(e.source),n=vy(e.target);o&&t.add(o),n&&t.add(n)}x=Array.from(t).map(t=>({id:t,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:t}}))}else x=function(t,e){const o=tb(e.nodeIDAccessor,"id");return t.map(t=>({id:o(t)+"",x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t}))}(e,m)}let v=[],k=[],A=[],S=null,M=null;if(m.customNetworkLayout){const t=m.colorScheme,e=ia(t,o.colors.categorical,w),n=ra(e,t),i={nodes:x,edges:b,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:m.layoutConfig??{}},r=m.customNetworkLayout(i);v=r.sceneNodes??[],k=r.sceneEdges??[],A=r.labels??[],S=r.backgrounds??null,M=r.overlays??null}else if(y){y.computeLayout(x,b,m,[u,d]);const t=y.buildScene(x,b,m,[u,d]);v=t.sceneNodes,k=t.sceneEdges,A=t.labels}const _=Mt(o);for(const t of A)t.fill||(t.fill=_.text);const P=bf({nodes:k,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Kh(function(t,e){switch(t.type){case"line":return Jh("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||"#999",strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity},"net-edge-"+e);case"bezier":{const o=t,n=`net-bezier-${e}-hatch`,i=yi(o.style.fill)?xi(o.style.fill,n):void 0;return tf(Zh.Fragment,{children:[i&&Jh("defs",{children:i}),Jh("path",{d:o.pathD,fill:i?`url(#${n})`:jh(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"ribbon":{const o=t,n=`net-ribbon-${e}-hatch`,i=yi(o.style.fill)?xi(o.style.fill,n):void 0;return tf(Zh.Fragment,{children:[i&&Jh("defs",{children:i}),Jh("path",{d:o.pathD,fill:i?`url(#${n})`:jh(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"curved":{const o=t;return Jh("path",{d:o.pathD,fill:jh(o.style.fill,"none"),stroke:o.style.stroke||"#999",strokeWidth:o.style.strokeWidth??1,opacity:o.style.opacity},"net-edge-"+e)}default:return null}}(t,e),t,"network-edge-cursor-"+e)}(t,e)}),L=bf({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Kh(function(t,e){switch(t.type){case"circle":{const o=t,n=yi(o.style.fill)?xi(o.style.fill,`net-circle-${e}-hatch`):void 0;return tf(Zh.Fragment,{children:[n&&Jh("defs",{children:n}),Jh("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:jh(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,n=yi(o.style.fill)?xi(o.style.fill,`net-rect-${e}-hatch`):void 0;return tf(Zh.Fragment,{children:[n&&Jh("defs",{children:n}),Jh("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:jh(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,n=Qh().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(Wh)||"",i=yi(o.style.fill)?xi(o.style.fill,`net-arc-${e}-hatch`):void 0;return tf(Zh.Fragment,{children:[i&&Jh("defs",{children:i}),Jh("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:jh(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,n=jd(o.symbolType,o.size,o.path);return Jh("path",{d:n,transform:o.rotation?`translate(${o.cx},${o.cy}) rotate(${180*o.rotation/Math.PI})`:`translate(${o.cx},${o.cy})`,fill:o.style.fill?jh(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return Xh(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),$=P.map(t=>t.element),R=L.map(t=>t.element),T=A.map((t,e)=>function(t,e){return Jh("text",{x:t.x,y:t.y,textAnchor:t.anchor||"middle",dominantBaseline:t.baseline||"auto",fontSize:t.fontSize||11,fontWeight:t.fontWeight,fill:t.fill||"var(--semiotic-text, #333)",stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:t.paintOrder,children:t.text},"net-label-"+e)}(t,e)).filter(Boolean);let I;const C=t=>Number(t),O=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:C,y:C},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:ob(v),pointNodes:Zx(v),idPrefix:t._idPrefix,onRender:t=>{I=t}}):null;return e&&(e.evidence=Fh({frameType:"network",width:i[0],height:i[1],marks:[...L.map(({node:t})=>({type:"node:"+(t.type??"node")})),...P.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:I,nodeCount:L.length,edgeCount:P.length,margin:s})),rm.renderToStaticMarkup($y(Jx(Qx,{children:[h,S,$,R,T,O,f,M]}),{width:i[0],height:i[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:l,idPrefix:t._idPrefix}))}import*as ib from"react-dom/server";import{geoPath as rb}from"d3-geo";import{quadtree as sb}from"d3-quadtree";import{geoMercator as ab,geoEqualEarth as cb,geoAlbersUsa as lb,geoOrthographic as ub,geoNaturalEarth1 as db,geoEquirectangular as hb}from"d3-geo";var fb={mercator:ab,equalEarth:cb,albersUsa:lb,orthographic:ub,naturalEarth:db,equirectangular:hb};function pb(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function yb(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function gb(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function mb(t,e){if(2>t.length)return[t];const o=.4*e,n=[];let i=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>o?(2>i.length||n.push(i),i=[r]):i.push(r)}return 2>i.length||n.push(i),n}function xb(t,e,o=24){const n=e[0]-t[0],i=e[1]-t[1],r=Math.sqrt(n*n+i*i);if(0===r)return[t,e];const s=-i/r,a=n/r,c=Math.min(.3*r,80),l=(t[0]+e[0])/2+s*c,u=(t[1]+e[1])/2+a*c,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*t[0]+2*r*i*l+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function bb(t,e){if(2>t.length)return t;const o=e/2+1,n=[];for(let e=0;t.length>e;e++){const i=t[e];let r,s;0===e?(r=t[1][0]-i[0],s=t[1][1]-i[1]):e===t.length-1?(r=i[0]-t[e-1][0],s=i[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;n.push([i[0]+s/a*o,i[1]+-r/a*o])}return n}function vb(t,e,o,n,i){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const c=s/a,l=-r/a,u=i/2+1;return[[t[0]+c*u,t[1]+l*u],[e[0]+c*u,e[1]+l*u]]}import{scaleLinear as wb}from"d3-scale";var kb=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ab=["scene-style","data-paint","accessibility","evidence"],Sb=(t,e)=>({retainedData:t,invalidations:e}),Mb=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],_b=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Pb=["scene-geometry","data-paint","accessibility","evidence"],Lb=["scene-style","data-paint","accessibility","evidence"],$b=["overlay","accessibility","evidence"],Rb=[],Tb={xAccessor:Sb("rebuild",Mb),yAccessor:Sb("rebuild",Mb),lineDataAccessor:Sb("rebuild",Mb),pointIdAccessor:Sb("rebuild",Pb),lineIdAccessor:Sb("rebuild",Pb),windowSize:Sb("rebuild",Mb),projection:Sb("preserve",_b),projectionExtent:Sb("preserve",_b),fitPadding:Sb("preserve",_b),lineType:Sb("preserve",_b),flowStyle:Sb("preserve",_b),graticule:Sb("preserve",_b),projectionTransform:Sb("preserve",_b),customLayout:Sb("preserve",_b),layoutConfig:Sb("preserve",_b),layoutMargin:Sb("preserve",_b),areaStyle:Sb("preserve",Lb),pointStyle:Sb("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:Sb("preserve",Lb),colorScheme:Sb("preserve",Lb),themeCategorical:Sb("preserve",Lb),themeDiverging:Sb("preserve",Lb),themeSemantic:Sb("preserve",Lb),themeSequential:Sb("preserve",Lb),decay:Sb("preserve",Lb),pulse:Sb("preserve",Lb),layoutSelection:Sb("preserve",Lb),annotations:Sb("preserve",$b),autoPlaceAnnotations:Sb("preserve",$b),clock:Sb("preserve",Rb),transition:Sb("preserve",Rb),introAnimation:Sb("preserve",Rb),onLayoutError:Sb("preserve",Rb)},Ib=Sb("preserve",_b),Cb=class{constructor(){this.tracker=new Ss}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},kb)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Ab):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=Tb[n]??Ib;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t),n=new Set(o.invalidations);return e.retainedDataChanged&&n.add("data"),this.tracker.record({kind:"config",keys:t},n)}};import{geoDistance as Ob,geoGraticule as Fb,geoInterpolate as Db}from"d3-geo";function zb(t){if(null==t)return 0;if("number"==typeof t&&Number.isFinite(t)&&t>=0&&.5>t)return t;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${t+""}.`)}var Nb=class t{constructor(t){this.updateResults=new Cb,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(t){return{...t,fitPadding:zb(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??Ql()}getConfiguredWindowSize(){const t=this.config.windowSize??500;if(!Number.isInteger(t)||1>t)throw Error("GeoPipelineStore windowSize must be a positive integer");return t}retainNewestLines(t=this.getConfiguredWindowSize()){this.lineData.length>t&&(this.lineData=this.lineData.slice(-t))}resizeStreamingWindow(t){if(this.pointBuffer){const e=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],n=e.slice(-t),i=o.slice(-n.length),r=this.currentTime();this.pointBuffer=new zl(t),this.timestampBuffer=new zl(t),n.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(i[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:zb(t.fitPadding)}:t}(t),o=this.config,n=this.getConfiguredWindowSize(),i=Object.keys(e).filter(t=>e[t]!==o[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==n;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(i,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,n=this.timestampBuffer?.toArray()??[],i=o.slice(-e),r=n.slice(-i.length),s=this.currentTime();this.pointBuffer=new zl(e),this.timestampBuffer=new zl(e),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();Iu(this.pointBuffer,t,this.timestampBuffer,e),this.lastIngestTime=e,this.updateResults.recordData("ingest",1)}pushPointWithResult(t){return this.pushPoint(t),this.updateResults.last}pushMany(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();for(const o of t)Iu(this.pointBuffer,o,this.timestampBuffer,e);this.lastIngestTime=e,this.updateResults.recordData("ingest",t.length)}pushManyWithResult(t){return this.pushMany(t),this.updateResults.last}pushLine(t){null!=t&&"object"==typeof t?(this.streaming||this.initStreaming(),this.lineData.push(t),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(t){if(!Array.isArray(t)||0===t.length)return void this.updateResults.recordNoop("ingest");const e=t.filter(t=>null!=t&&"object"==typeof t);if(0!==e.length){this.streaming||this.initStreaming();for(const t of e)this.lineData.push(t);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",e.length)}else this.updateResults.recordNoop("ingest")}removeLine(t){const{lineIdAccessor:e}=this.config;if(!e)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]),i=[];return this.lineData=this.lineData.filter(t=>!n.has(o(t)+"")||(i.push(t),!1)),i.length>0?(this.version++,this.updateResults.recordData("remove",i.length)):this.updateResults.recordNoop("remove"),i}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>n.has(o(t)+"");Cu(this.pointBuffer,this.timestampBuffer,t);const e=this.pointBuffer.remove(t);return e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}{const t=[];return this.pointData=this.pointData.filter(e=>!n.has(o(e)+"")||(t.push(e),!1)),t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(t){const e=this._customRestyle;if(e){for(const o of this.scene){const n=this._baseStyles.get(o)??o.style,i=e(o,t);o.style=i?{...n,...i}:n}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,o=this.projection,n=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],c=this.scene;this.projection=function(t){if(!t)return cb();if("string"==typeof t){const e=fb[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),cb())}if("object"==typeof t&&"type"in t){const e=fb[t.type],o=e?e():cb();return t.rotate&&"rotate"in o&&o.rotate(t.rotate),t.center&&"center"in o&&o.center(t.center),o}return t}(e.projection),this.geoPath=rb(this.projection),this.fitProjection(t),this.geoPath=rb(this.projection);const l=this.projection;this.scales={projection:l,geoPath:this.geoPath,projectedPoint:(t,e)=>l([t,e]),invertedPoint:(t,e)=>l.invert?l.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=n,this.scales=i,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,o=t.height/2,n=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:o}));n.length>0&&this.startTransition(n)}this._hasRenderedOnce=!0,e.transition&&c.length>0&&this.startTransition(c),this.version++}}fitProjection(t){const e=this.projection,o=this.config,n=[...this.areas],i=pb(o.xAccessor,"lon"),r=pb(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=yb(o.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==n.length){if(o.projectionExtent){const[[n,i],[r,s]]=o.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[n,i],[n,s],[r,s],[r,i],[n,i]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const n=o.fitPadding??0,i=Math.min(t.width,t.height);e.scale(i/2-i*n),e.translate([t.width/2,t.height/2])}else{const i=o.fitPadding??0,r=t.width*i,s=t.height*i;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:n})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t.k),o.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=rb(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t),o.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=rb(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const c=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=c,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const o=this.projection;if(!o||!o.rotate)return;const n=this.geoPath,i=this.scales,r=[...o.rotate()];o.rotate(t),this.geoPath=rb(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(r),this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,o=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(o++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const n=Array(o);let i=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(n[i++]=t);this._quadtree=sb().x(t=>t.x).y(t=>t.y).addAll(n)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,o=this.projection,n=this.geoPath;if(e.customLayout&&this.scales){const o=e.layoutMargin??{top:0,right:0,bottom:0,left:0},n=ia(e.colorScheme,e.themeCategorical,V),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:o,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...n]},resolveColor:ra(n,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null},r=fu({family:"geo",logLabel:"geo customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:e.onLayoutError,run:()=>e.customLayout(i)});if("failure"===r.kind)return this.lastCustomLayoutFailure=r.diagnostic,this._customLayoutFailedThisBuild=!0,r.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);const s=r.result,a=s.nodes??[];if(this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null,this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const t of a)this._baseStyles.set(t,t.style);this.restyleScene(e.layoutSelection??null)}return uu({label:"geo customLayout",nodes:a,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),a}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:t,projection:e,path:o,areas:n,points:i,lines:r,layout:s}){const a=pb(t.xAccessor,"lon"),c=pb(t.yAccessor,"lat"),l=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),d=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),h=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,n=Fb();e.step&&n.step(e.step);const i=o(n())||"";i&&l.push({type:"geoarea",pathData:i,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth??.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of n){const n=o(e);if(!n)continue;const i=o.centroid(e),r=o.bounds(e),s=o.area(e);l.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:gb(t.areaStyle,e,u),datum:e,interactive:!0})}const f=yb(t.lineDataAccessor);for(const o of r){const n=f(o);if(!n||2>n.length)continue;let i=[];if("geo"===t.lineType){const t=Array(n.length);for(let e=0;n.length>e;e++)t[e]=[a(n[e]),c(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=Ob(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),c=Db(n,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const n=e(c(t/a));null!=n&&i.push(n)}}}else for(let t=0;n.length>t;t++){const o=n[t],r=e([a(o),c(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=gb(t.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==n.length||2>i.length||"arc"!==t.flowStyle?2!==n.length||2>i.length||"offset"!==t.flowStyle||(i="geo"===t.lineType?bb(i,u):vb(i[0],i[i.length-1],0,0,u)):i=xb(i[0],i[i.length-1]);const h=mb(i,s.width);if(h.length>1)for(const t of h)2>t.length||l.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else l.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const p=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,y=e.clipAngle?e.clipAngle()??0:0,g=y>0?y*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],x="function"==typeof e.center?e.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const o of i){const n=a(o),i=c(o);if(null!=g&&Ob([n,i],b)>g)continue;const r=e([n,i]);if(!r)continue;const s=t.pointStyle?t.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:p?p(o)+"":void 0};l.push(u)}return l}({config:e,projection:o,path:n,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const o=function(t,e,o,n){const i=t.filter(t=>"point"===t.type);if(2>i.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const c=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,l="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=i.find(t=>t.datum&&c(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const d=Lt(i.map(t=>t.datum?Number(l(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),1);n>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const o=t[e];"geoarea"===o.type&&o.interactive&&t.splice(e,1)}const h="strip"===a?function(t,e,o,n,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,c=wb().domain([0,n]).range([0,s]);e.x=r,e.y=a;const l=[];for(const i of t){if(i===e)continue;if(!i.datum){i.x=r,i.y=a;continue}const t=Number(o(i.datum)),s=r+(isFinite(t)&&t>=0&&n>0?c(t):0);i.x=s,i.y=a,l.push({node:i,x:s})}l.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;l.length>d;){let t=d+1;for(;l.length>t&&3>Math.abs(l[t].x-l[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)l[d+t].node.y=a+(t-(e-1)/2)*Math.min(2.5,2*u/Math.max(1,e-1));d=t}return{cx:r,cy:a,maxCost:n,availableRadius:s,layout:"strip"}}(i,u,l,d,o):function(t,e,o,n,i,r){const s=e.x,a=e.y,c=r.width/2,l=r.height/2,u=Math.min(r.width,r.height)/2,d=wb().domain([0,n]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),f=Math.hypot(t-s,u-a),p=Number(o(r.datum)),y=isFinite(p)&&p>=0?n>0?d(p):0:f,g=c+Math.cos(h)*y,m=l+Math.sin(h)*y;r.x=t+(g-t)*i,r.y=u+(m-u)*i}return e.x=s+(c-s)*i,e.y=a+(l-a)*i,{cx:e.x,cy:e.y,maxCost:n,availableRadius:u,layout:"radial"}}(i,u,l,d,s,o),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of i)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const o of f){const n=o.datum?.source,i=o.datum?.target;if(null!=n&&null!=i){const r=t.get(n+""),s=t.get(i+"");if(r&&s)if("fractional"===e.lineMode&&o.path.length>2){const t=o.path[0],e=o.path[o.path.length-1],n=[r[0]-t[0],r[1]-t[1]],i=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;o.path.length>t;t++)a.push(a[t-1]+Math.hypot(o.path[t][0]-o.path[t-1][0],o.path[t][1]-o.path[t-1][1]));const c=a[a.length-1];o.path=o.path.map((t,e)=>{const r=c>0?a[e]/c:e/(o.path.length-1);return[t[0]+n[0]*(1-r)+i[0]*r,t[1]+n[1]*(1-r)+i[1]*r]})}else o.path=[r,s]}}}return h}(this.scene,t,e,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const o=this.scene.filter(t=>"point"===t.type);for(let n=0;o.length>n;n++){const i=Jl(t,n,e);o[n]._decayOpacity=i,o[n].style={...o[n].style,opacity:i}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const o=this.scene.filter(t=>"point"===t.type),n=this.timestampBuffer.toArray(),i=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;o.length>a&&n.length>a;a++){const c=eu(e,n[a],t);s=ou(o[a],c,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&nu(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(t){const e=this.config.transition?.duration??300;if(0>=e)return;const o=new Map;for(const e of t)"point"===e.type&&e.pointId&&o.set(e.pointId,[e.x,e.y]);const n=this.scene.filter(t=>"point"===t.type);let i=!1;for(const t of n)if(t.pointId){const e=o.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(i=!0))}for(const t of n)t.pointId&&!o.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=Kl(t,this.activeTransition),o=Ul(e),n=this.scene.filter(t=>"point"===t.type);for(const t of n){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=Zl(t.x,t._targetX,o),t.y=Zl(e,t._targetY,o)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*o})}if(e>=1){for(const t of n)null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0),null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Nb.QUADTREE_THRESHOLD=500;var Eb=Nb;function Bb(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("glyph"===o.type){const t=o,n=Ph(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+n.centerDx,y:t.y+n.centerDy,r:n.radius})}return e}Wu(Eb);import{jsx as Wb,jsxs as jb}from"react/jsx-runtime";function Yb({bottomMargin:t,costLabel:e,layout:{cx:o,cy:n,maxCost:i,availableRadius:r,layout:s},ringStyle:a,ringValues:c,showNorth:l,showRingLabels:u,showRings:d}){const h="strip"===s,f={stroke:h?"var(--semiotic-border, #999)":"#999",strokeWidth:h?1:.8,strokeDasharray:h?"none":"4,3",labelColor:"var(--semiotic-text-secondary, #777)",labelSize:h?8:10,...a};return jb("g",h?{children:[Wb("line",{x1:o,y1:n,x2:o+r,y2:n,stroke:f.stroke,strokeWidth:f.strokeWidth,strokeLinecap:"round",opacity:.85}),Wb("line",{x1:o,y1:n-3.5,x2:o,y2:n+3.5,stroke:f.stroke,strokeWidth:f.strokeWidth,opacity:.9}),d&&c.map(s=>{const a=o+(i>0?s/i*r:0);return jb("g",{children:[Wb("line",{x1:a,y1:n-2.5,x2:a,y2:n+2.5,stroke:f.stroke,strokeWidth:.9,opacity:.65}),u&&jb("text",{x:a,y:n+Math.min(10,(t??2)+8),textAnchor:"middle",fontSize:f.labelSize,fill:f.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[s,e?" "+e:""]})]},s)})]}:{children:[c.map(t=>{const s=t/i*r;return jb("g",{children:[Wb("circle",{cx:o,cy:n,r:s,fill:"none",stroke:f.stroke,strokeWidth:f.strokeWidth,strokeDasharray:f.strokeDasharray,opacity:.5}),u&&jb("text",{x:o+s+3,y:n-2,fontSize:f.labelSize,fill:f.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[t,e?" "+e:""]})]},t)}),l&&jb("g",{transform:"translate(24, 24)",children:[Wb("circle",{r:16,fill:"white",fillOpacity:.85,stroke:"#bbb",strokeWidth:.8}),Wb("path",{d:"M0,-11 L3,-3 L1,-4 L1,7 L-1,7 L-1,-4 L-3,-3 Z",fill:"#555",stroke:"none"}),Wb("text",{y:-12,textAnchor:"middle",fontSize:7,fontWeight:700,fill:"#555",fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:"N"}),Wb("line",{x1:11,y1:0,x2:13,y2:0,stroke:"#bbb",strokeWidth:.8}),Wb("line",{x1:-11,y1:0,x2:-13,y2:0,stroke:"#bbb",strokeWidth:.8}),Wb("line",{x1:0,y1:11,x2:0,y2:13,stroke:"#bbb",strokeWidth:.8})]})]})}import{Fragment as Xb,jsx as qb,jsxs as Gb}from"react/jsx-runtime";function Vb(t,e){const o=St(t.theme),n=t.size||[t.width||600,t.height||400],i=ce({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=se(t.title),s=Array.isArray(t.areas)?g(t.areas):t.areas,a=g(t.points),c=g(t.lines),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return Tf(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];_y(i,{props:t,categories:l,theme:o,size:n,hasTitle:r});const u=Py({props:t,categories:l,theme:o,size:n,margin:i,hasTitle:r}),d=n[0]-(i.left??0)-(i.right??0),h=n[1]-(i.top??0)-(i.bottom??0),f={projection:t.projection||"equalEarth",projectionExtent:t.projectionExtent,xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineIdAccessor:t.lineIdAccessor,lineType:t.lineType,flowStyle:t.flowStyle,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,colorScheme:t.colorScheme,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,onLayoutError:t.onLayoutError,themeCategorical:o.colors.categorical,themeSemantic:kt(o),themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging},p=new Eb(f);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);p.setAreas(s)}t.points&&p.setPoints(a),t.lines&&p.setLines(c),p.computeScene({width:d,height:h});const y=Iy(t.backgroundGraphics,n,i,p.scales),m=Iy(t.foregroundGraphics,n,i,p.scales),x=bf({nodes:p.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Kh(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=yi(o.style.fill)?xi(o.style.fill,`geoarea-${e}-hatch`):void 0;return nf(ef.Fragment,{children:[n&&of("defs",{children:n}),of("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:jh(o.style.fill,"#e0e0e0"),fillOpacity:o.style.fillOpacity??1,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth??.5,strokeDasharray:o.style.strokeDasharray,opacity:o._decayOpacity??1})]},"geoarea-"+e)}case"point":{const o=t,n=yi(o.style.fill)?xi(o.style.fill,`geopoint-${e}-hatch`):void 0;return nf(ef.Fragment,{children:[n&&of("defs",{children:n}),of("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:jh(o.style.fill),fillOpacity:o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o._decayOpacity??o.style.opacity??1})]},"point-"+e)}case"line":{const o=t;if(2>o.path.length)return null;const n="M"+o.path.map(t=>`${t[0]},${t[1]}`).join("L");return of("path",{d:n,fill:"none",stroke:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth??1.5,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity??1},"line-"+e)}case"glyph":return Xh(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===x.length){let r;const s=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Bb(p.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Fh({frameType:"geo",width:n[0],height:n[1],marks:x.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:l.length>0?l.length:null!=t.legend?1:void 0,margin:i})),ib.renderToStaticMarkup($y(y||m||t.annotations||p.customLayoutOverlays?Gb(Xb,{children:[y,s,m,p.customLayoutOverlays]}):null,{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}const b=x.map(t=>t.element),v=t.cartogramChrome,w=p.cartogramLayout&&v?qb(Yb,{layout:{...p.cartogramLayout,layout:p.cartogramLayout.layout??"radial"},ringValues:Hb(p.cartogramLayout.maxCost,v.showRings),showRings:v.showRings??!0,showNorth:v.showNorth??!0,showRingLabels:v.showRingLabels??!0,costLabel:"string"==typeof v.costLabel?v.costLabel:void 0}):null;let k;const A=t.annotations?Zp({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([t,e])=>p.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Bb(p.scene),idPrefix:t._idPrefix,onRender:t=>{k=t}}):null;return e&&(e.evidence=Fh({frameType:"geo",width:n[0],height:n[1],marks:x.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:k,legendItems:l.length>0?l.length:null!=t.legend?1:void 0,margin:i})),ib.renderToStaticMarkup($y(Gb(Xb,{children:[y,b,A,w,m,p.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}function Hb(t,e){if(!1===e||0>=t)return[];if(Array.isArray(e))return e.filter(e=>e>0&&t>=e);const o="number"==typeof e?e:Math.min(5,Math.max(2,Math.ceil(t/5))),n=t/o,i=[];for(let t=1;o>=t;t++)i.push(Math.round(n*t*10)/10);return i}import*as Ub from"react-dom/server";function Kb(t=[]){return t.map(t=>({id:t.id,label:t.label,count:t.count,...null!=t.secondary?{secondary:t.secondary}:{},...t.secondaryLabel?{secondaryLabel:t.secondaryLabel}:{},...null!=t.observed?{observed:t.observed}:{}}))}var Zb={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Qb(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}function Jb(t,e,o){const n="function"==typeof e?e(t,o):e;return{...Zb,...n??{}}}function tv(t,e={},o="settled"){return t.map((t,n)=>function(t,e={},o={index:0,simulationState:"settled"}){const n=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),i={label:e.getBodyLabel?.(t)??Qb(t)},r={style:Jb(t,e.bodyStyle,o),datum:n,accessibleDatum:n,accessibility:i,_transitionKey:t.id};return"aabb"===t.shape.type?{type:"rect",x:t.x-t.shape.width/2,y:t.y-t.shape.height/2,w:t.shape.width,h:t.shape.height,...r}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...r}}(t,e,{index:n,simulationState:o}))}import{jsx as ev,jsxs as ov}from"react/jsx-runtime";var nv={top:0,right:0,bottom:0,left:0};function iv(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function rv(t,e={}){const{element:o,scene:n,evidence:i}=function(t,e={}){const{width:o=640,height:n=360,title:i,description:r,background:s,backgroundGraphics:a,backgroundGraphicsBackdrop:c,className:l,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:f,renderBodySVG:p,renderChrome:y,...g}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=tv(n,e,i.simulationState),s=function(t,e={}){const o=e.bodies??function(t){return t.world.bodies.map(t=>({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:{...t.shape},sleeping:t.sleeping,datum:t.datum}))}(t),n=o.filter(t=>t.sleeping).length,i=t.queue.length,r=t.sediment.reduce((t,e)=>t+e.count,0),s="settled"===t.simulationState&&0===i&&n===o.length,a=[];i>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const c=null!=e.charge&&Number.isFinite(e.charge)?function(t,e,o,n){const i=t-(e+o+n);return{charge:t,live:e,queued:o,sedimented:n,unaccounted:i,balanced:0===i}}(e.charge,o.length,i,r):void 0;return c&&!c.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:o.length,sleepingCount:n,settled:s,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:Kb(e.projectionRows),queuedCount:i,sedimentedCount:r,...c?{ledger:c}:{},warnings:a}}(i,{bodies:n,projectionRows:e.projectionRows,stepsRun:o,charge:e.charge});return{snapshot:i,bodies:n,sceneNodes:r,evidence:s,stepsRun:o}}(t,g),x={...nv,...h},b=[o,n],v=iv(a,b,x),w=iv(u,b,x),k=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(d),A=i?k+"-title":void 0,S=r?k+"-desc":void 0,M=[A,S].filter(Boolean).join(" ")||void 0,_=x.left||x.top?`translate(${x.left},${x.top})`:void 0,P=Math.max(1,o-x.left-x.right),L=Math.max(1,n-x.top-x.bottom),$=k+"-plot-clip",R=_&&null!=v?ev("g",{transform:_,children:v}):v;return{element:ov("svg",{xmlns:"http://www.w3.org/2000/svg",className:l??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":M,style:f,children:[i&&ev("title",{id:A,children:i}),r&&ev("desc",{id:S,children:r}),ev("defs",{children:ev("clipPath",{id:$,children:ev("rect",{width:P,height:L})})}),c&&"transparent"!==c?ev("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:n,fill:c}):null,!a&&s&&"transparent"!==s?ev("rect",{x:0,y:0,width:o,height:n,fill:s}):null,R,ev("g",{id:k+"-data-area",transform:_,clipPath:`url(#${$})`,children:m.sceneNodes.map((t,e)=>{const o=m.bodies[e],n=o&&p?p(o,t.style??{},e,k):void 0;return null!=n?Kh(n,t,e):gf(t,e,k)})}),w,y?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:Ub.renderToStaticMarkup(o),scene:n,evidence:i}}function sv(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function av(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,sv(t.thickness)??sv(o)??sv(e.thickness)??4)}function cv(t){return t.sensorId??"stream-region-"+t.id}function lv(t){const e=cv(t),o={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("boundary"===t.collider&&"aabb"===t.shape.type){const n=t.colliderThickness??8,i=t.shape.x-t.shape.width/2,r=t.shape.x+t.shape.width/2,s=t.shape.y-t.shape.height/2,a=t.shape.y+t.shape.height/2;return[{...o,id:e+"-top",shape:{type:"segment",x1:i,y1:s,x2:r,y2:s,thickness:n}},{...o,id:e+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:n}},{...o,id:e+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:i,y2:a,thickness:n}},{...o,id:e+"-left",shape:{type:"segment",x1:i,y1:a,x2:i,y2:s,thickness:n}}]}return t.collider?[{...o,id:e+"-collider",shape:t.shape}]:[]}import{jsx as uv}from"react/jsx-runtime";function dv({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?uv("foreignObject",{x:0,y:0,width:e,height:o,children:t}):uv("text",{x:e/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:t}):null}import{scaleLinear as hv}from"d3-scale";function fv(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}import{jsx as pv,jsxs as yv}from"react/jsx-runtime";var gv={top:0,right:0,bottom:0,left:0};function mv(t,e){const o=t.size??[t.width??600,t.height??400],n=St(t.theme),i=void 0===t.theme?{}:oe(n),r=t.bodyStyle,s=!1,a=t.legendPosition??"right",c=ae({...gv,...t.margin},s,!!t.legend&&"top"===a);if(t.legend){const e={...c};ve(c,{legend:t.legend,position:a,size:o,hasTitle:s,legendLayout:t.legendLayout}),le(c,e,o,a)}let l;const u=function({annotations:t,chartId:e,chartType:o,config:n,onRegionObservation:i,regionEffects:r,seed:s,size:a}){const c=function(t=[],e={}){const o=e.idPrefix?e.idPrefix+"-":"",n=[];for(const i of t){if("barrier"!==i.physics&&"sensor"!==i.physics)continue;const t=i.axis??e.defaultAxis??"x",r=av(i,e),s=i.colliderId??`${o}${i.id}`;let a;if("x"===t){const t=sv(i.x),o=sv(i.y1)??sv(e.plotBounds?.y)??sv(i.y),n=sv(i.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??sv(i.y);if(null==t||null==o||null==n)continue;a={type:"segment",x1:t,y1:o,x2:t,y2:n,thickness:r}}else{const t=sv(i.y),o=sv(i.x1)??sv(e.plotBounds?.x)??sv(i.x),n=sv(i.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??sv(i.x);if(null==t||null==o||null==n)continue;a={type:"segment",x1:o,y1:t,x2:n,y2:t,thickness:r}}n.push({id:s,shape:a,sensor:"sensor"===i.physics,..."barrier"!==i.physics||null==i.restitution&&null==e.barrierRestitution?{}:{restitution:sv(i.restitution)??sv(e.barrierRestitution)},..."barrier"!==i.physics||null==i.friction&&null==e.barrierFriction?{}:{friction:sv(i.friction)??sv(e.barrierFriction)}})}return n}((t??[]).filter(t=>"barrier"===t.physics||"sensor"===t.physics),{idPrefix:e?e+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),l=void 0===s||void 0!==n?.kernel?.seed?n:{...n,kernel:{...n?.kernel,seed:s}},u=r.flatMap(t=>[{id:cv(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...lv(t)]),d=Object.fromEntries(r.map(t=>[cv(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=l?.observation,f=r.length>0;return f||u.length>0||c.length>0||null!=e||h?{...l,colliders:[...l?.colliders??[],...u,...c],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{f&&i(t),h?.onObservation?.(t)}}}:l}({annotations:t.annotations,chartId:t.chartId,chartType:"StreamPhysicsFrame",config:t.config,onRegionObservation:()=>{},regionEffects:t.regionEffects??[],seed:t.seed,size:[Math.max(1,o[0]-c.left-c.right),Math.max(1,o[1]-c.top-c.bottom)]}),d=new Ws(u);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&d.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const h=rv(d,{...t,width:o[0],height:o[1],background:t.background??n.colors.background,bodyStyle:(t,e)=>({fill:n.colors.primary,stroke:n.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof r?r(t,e):r}),style:{...i,fontFamily:n.typography.fontFamily,...t.style},charge:t.charge,idPrefix:t.idPrefix??t._idPrefix??"physics",margin:c,renderChrome:e=>{const i=function(t,e,o,n,i){const r=Math.max(1,o[0]-n.left-n.right),s=Math.max(1,o[1]-n.top-n.bottom),a=function(t){return t?.length?t.map(t=>null!=t.pointId||null==t.bodyId?t:{...t,pointId:t.bodyId+""}):t}(e.annotations),c=function(t){const{width:e,height:o,pointNodes:n=[],data:i}=t;return{scales:{x:hv().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:hv().domain([0,Math.max(1,o)]).range([0,Math.max(1,o)])},width:e,height:o,frameType:"network",pointNodes:n,data:i,xAccessor:"x",yAccessor:"y"}}({width:r,height:s,pointNodes:(l=t.bodies,l.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,fv(t))})))});var l;const u=c.scales?.x,d=c.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const f=Zp({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:i,frameType:"network",xAccessor:c.xAccessor,yAccessor:c.yAccessor,pointNodes:c.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),p=e.legend?My(e.legend,{theme:i,position:e.legendPosition,size:[o[0],o[1]],margin:n,hasTitle:!!e.title,legendLayout:e.legendLayout})??Jp(e.legend,o,n,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:yv("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:o[0],height:o[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[pv("g",{transform:`translate(${n.left},${n.top})`,children:f}),pv(dv,{title:e.title,totalWidth:o[0],marginTop:Math.max(n.top,28)}),p]})}}(e,t,o,c,n);return l=i.annotationRender,i.node}});return e&&(e.evidence=Fh({frameType:"physics",width:o[0],height:o[1],marks:h.scene.sceneNodes,title:t.title,description:t.description,annotations:t.annotations,annotationRender:l,extraWarnings:[...0===h.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...h.scene.evidence.warnings]})),h.svg}import*as xv from"react-dom/server";import{jsx as bv,jsxs as vv}from"react/jsx-runtime";var wv={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function kv(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var Av={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",n=wv[o],i=kv(t.width,n.width),r=kv(t.height,n.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):n.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:n.align,c="center"===a?"middle":"end"===a?"end":"start",l="center"===a?i/2:"end"===a?i-s:s,u=St(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const o=e.locale??"en-US";if("currency"===t){const t=e.precision??2,n=new Intl.NumberFormat(o,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>n.format(t)}if("percent"===t){const t=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",o=Math.abs(t);if(1e3>o)return`${e}${Math.round(o)}ms`;const n=o/1e3;if(60>n)return`${e}${i=n,Math.round(100*i)/100+""}s`;var i;const r=n/60;if(60>r){const t=Math.floor(r),o=Math.round(n-60*t);return 0===o?`${e}${t}m`:`${e}${t}m ${o}s`}const s=r/60;if(24>s){const t=Math.floor(s),o=Math.round(r-60*t);return 0===o?`${e}${t}h`:`${e}${t}h ${o}m`}const a=Math.floor(s/24),c=Math.round(s-24*a);return 0===c?`${e}${a}d`:`${e}${a}d ${c}h`}(t);const n=new Intl.NumberFormat(o,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>n.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),f=void 0===d?"No value":(p=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${p}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var p;const y=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const o=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let n=null;for(const e of o){if(e.at>t)break;n=e}return n}(d,t.thresholds),g="string"==typeof t.color?t.color:function(t,e,o){return e||("success"===t?o.colors.success??"#2ca02c":"warning"===t?o.colors.warning??"#b26a00":"danger"===t?o.colors.danger??"#d62728":"info"===t?o.colors.info??o.colors.primary:o.colors.text)}(y?.level??"neutral",y?.color,u),m="string"==typeof t.label?t.label:void 0,x="string"==typeof t.caption?t.caption:void 0,b="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,o){const n=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,i=n&&"number"==typeof n.value&&Number.isFinite(n.value)?n.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===i?void 0:e-i);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,o);return`${s}${n&&"string"==typeof n.label?" "+n.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,o){const n=t.target&&"object"==typeof t.target?t.target:void 0;if(!n||"number"!=typeof n.value||!Number.isFinite(n.value))return;const i="string"==typeof n.label?" "+n.label:"";return 0===n.value?`target ${o(n.value)}${i}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/n.value)} of ${o(n.value)}${i}`}(t,d,h),k=[v,w,y?.label].filter(Boolean).join(" · "),A="string"==typeof t.description&&t.description||[m,f,b,k].filter(Boolean).join(", "),S="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+n.labelSize,P=_+n.captionSize+4,L="presentation"===o?r/2+.32*n.valueSize:"thumbnail"===o?r/2+.34*n.valueSize:Math.min(r-s-(k?26:4),(n.showHeader&&(m||x)?x?P+10:_+14:s)+n.valueSize),$=l+("start"===c?Math.max(n.valueSize,f.length*n.valueSize*.55):0),R=xv.renderToStaticMarkup(vv("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-label":A,"data-semiotic-component":"BigNumber",children:[bv("title",{children:m??f}),"string"==typeof t.description&&bv("desc",{children:t.description}),bv("rect",{x:n.border?.5:0,y:n.border?.5:0,width:n.border?i-1:i,height:n.border?r-1:r,rx:n.border?8:0,fill:S,stroke:n.border?M:"none"}),n.showHeader&&m&&bv("text",{x:l,y:_,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:m}),n.showHeader&&x&&bv("text",{x:l,y:P,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:x}),bv("text",{x:l,y:L,textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:g,"data-mark-type":"value",children:f}),b&&void 0!==d&&"start"===c&&bv("text",{x:$+6,y:L,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*n.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),n.showDetail&&k&&bv("text",{x:l,y:Math.min(r-s,L+n.detailSize+10),textAnchor:c,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Fh({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:A})),R}};function Sv(t,e,o){return Av[t](e,o)}import*as Mv from"react-dom/server";import{jsx as _v,jsxs as Pv}from"react/jsx-runtime";function Lv(t,e){const o=t.match(/^<svg\b[^>]*>/)?.[0];if(!o)return e;const n=(t,e)=>{const n=o.match(RegExp(`\\b${t}=(?:"([0-9]+(?:\\.[0-9]+)?)"|'([0-9]+(?:\\.[0-9]+)?)')`)),i=Number(n?.[1]??n?.[2]);return Number.isFinite(i)&&i>0?i:e};return{width:n("width",e.width),height:n("height",e.height)}}import{Fragment as $v,jsx as Rv}from"react/jsx-runtime";function Tv(t,e){switch(t){case"xy":return jy(e);case"ordinal":return im(e);case"network":return nb(e);case"geo":return Vb(e);case"physics":return mv(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function Iv(t){return jy(t)}function Cv(t){return im(t)}function Ov(t){return nb(t)}function Fv(t){return Vb(t)}var Dv=new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),zv=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function Nv(t,e){const o=Number(t);if(!Number.isFinite(o))return t;const n=10**e,i=Math.round((o+Number.EPSILON)*n)/n;return Object.is(i,-0)?"0":i+""}function Ev(t,e){const o=function(t){if(Number.isFinite(t))return Math.max(0,Math.min(8,Math.floor(t)))}(e);return void 0===o?t:t.replace(/<[^>]+>/g,t=>t.replace(/\s([\w:-]+)="([^"]*)"/g,(t,e,n)=>!Dv.has(e)||/\b(?:var|calc|url)\(/i.test(n)?t:` ${e}="${function(t,e){const o=RegExp(zv.source,zv.flags);let n,i="",r=0,s=!1;for(;n=o.exec(t);){const o=t.slice(r,n.index);i+=s&&0===o.length?" ":o,i+=Nv(n[0],e),r=n.index+n[0].length,s=!0}return i+t.slice(r)}(n,o)}"`))}var Bv=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],Wv=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function jv(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function Yv(t,e,o){return qv(t,e,o).svg}function Xv(t,e,o){const n={},{svg:i,frameType:r}=qv(t,e,o,n),s=n.evidence??Fh({frameType:r,width:"number"==typeof e.width?e.width:600,height:"number"==typeof e.height?e.height:400,marks:[],title:"string"==typeof e.title?e.title:void 0,description:"string"==typeof e.description?e.description:void 0,annotations:e.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=t,h(s,t,e),{svg:i,evidence:s}}function qv(e,r,s,a){if(Object.prototype.hasOwnProperty.call(Av,e))return{svg:Ev(Sv(e,r,a),s?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(gg,e))throw Error(`Unknown chart component: "${e}". Run \`npx semiotic-ai --list\` for supported chart types.`);const c=gg[e];var l;const u=function(e,r,s){const a=n[e||"primary"],c=e&&"primary"!==e||!s?.width?a.width:s.width,l=e&&"primary"!==e||!s?.height?a.height:s.height,u=function(e,o,n=e.responsiveRules){if(!Array.isArray(n)||0===n.length)return{props:e,matches:[]};const i=n.map((t,e)=>({rule:t,index:e})).filter(t=>function(t,e){const{when:o}=t,n=e.width,i=e.height,r=function(t){if("number"==typeof t.height&&t.height>0)return t.width/t.height}(e),s=function(t){if("number"==typeof t.height&&t.height>0)return t.height>t.width?"portrait":"landscape"}(e);return!("number"==typeof o.minWidth&&o.minWidth>n||"number"==typeof o.maxWidth&&n>o.maxWidth||"number"==typeof o.minHeight&&("number"!=typeof i||o.minHeight>i)||"number"==typeof o.maxHeight&&("number"!=typeof i||i>o.maxHeight)||"number"==typeof o.minAspectRatio&&("number"!=typeof r||o.minAspectRatio>r)||"number"==typeof o.maxAspectRatio&&("number"!=typeof r||r>o.maxAspectRatio)||o.orientation&&s!==o.orientation)}(t.rule,o)).sort((t,e)=>("number"==typeof t.rule.priority?t.rule.priority:t.index)-("number"==typeof e.rule.priority?e.rule.priority:e.index));return{props:i.reduce((e,o)=>function(e,o){const n={...e,...o};for(const i of["margin","frameProps","mobileSemantics","style"])t(e[i])&&t(o[i])&&(n[i]={...e[i],...o[i]});return"string"==typeof e.className&&"string"==typeof o.className&&(n.className=`${e.className} ${o.className}`),n}(e,o.rule.transform),e),matches:i}}({...r,mode:e},{width:r.width??c,height:r.height??l}).props,d=u.mode||e||"primary",h=n[d],f="context"===d||"sparkline"===d,p="primary"===d&&s?.width?s.width:h.width;return{mode:d,width:u.width??p,height:u.height??("primary"===d&&s?.height?s.height:h.height),showAxes:u.showAxes??h.showAxes,showGrid:u.showGrid??h.showGrid,enableHover:u.enableHover??(!!u.linkedHover||h.enableHover),showLegend:u.showLegend??h.showLegend,showLabels:u.showLabels??h.showLabels,title:f?void 0:u.title,description:u.description,summary:u.summary,accessibleTable:u.accessibleTable,xLabel:f?void 0:u.xLabel,yLabel:f?void 0:u.yLabel,categoryLabel:f?void 0:u.categoryLabel,valueLabel:f?void 0:u.valueLabel,marginDefaults:i(h.marginDefaults,u.showCategoryTicks,u.orientation),compactMode:f,mobileInteraction:o(u.mobileInteraction,{mode:d,width:u.width??p,mobileSemantics:u.mobileSemantics}),mobileSemantics:u.mobileSemantics}}(c.layout?.mode??("string"==typeof(l=r.mode)&&Object.prototype.hasOwnProperty.call(n,l)?r.mode:void 0),{...c.layout?.modeDefaults,...jv(r,Wv)},c.layout?.primarySize),{data:d,theme:h,background:p,className:y,annotations:g,margin:m,colorScheme:x,colorBy:b,legendPosition:v,...w}=r,{width:k,height:A}=u,S=[k,A],M=w.frameProps||{},_=c.layout?.margin,P="function"==typeof _?_(r,u):_??u.marginDefaults,L=void 0!==m?m:M.margin,$=function(t){if(null==t)return;if("number"==typeof t)return{top:t,right:t,bottom:t,left:t};const e={};return"number"==typeof t.top&&(e.top=t.top),"number"==typeof t.right&&(e.right=t.right),"number"==typeof t.bottom&&(e.bottom=t.bottom),"number"==typeof t.left&&(e.left=t.left),e}(L),R="number"==typeof L?{top:L,right:L,bottom:L,left:L}:{...P,...$},T=jv(w,Bv),I=t=>M[t]??u[t],C={...M,...T,theme:h,title:u.title,description:u.description,showAxes:I("showAxes"),showLegend:I("showLegend"),showLabels:I("showLabels"),showGrid:I("showGrid"),xLabel:I("xLabel"),yLabel:I("yLabel"),categoryLabel:I("categoryLabel"),valueLabel:I("valueLabel"),background:p,className:y,annotations:g,size:S,margin:R,__compactMode:u.compactMode,__autoLegendMargin:!0,...void 0!==x&&{colorScheme:x},...void 0!==v&&{legendPosition:v},_idPrefix:w._idPrefix},O=c.buildProps(d,b,x,C,w);let F;if(c.renderStatic)F=c.renderStatic(O,a);else switch(c.frameType){case"xy":F=jy(O,a);break;case"ordinal":F=im(O,a);break;case"network":F=nb(O,a);break;case"geo":F=Vb(O,a);break;case"physics":F=mv(O,a)}const D=c.renderOverlay?.(O,{theme:St(h)});if(null!=D){const t=f.renderToStaticMarkup(Rv($v,{children:D})),e=F.lastIndexOf("</svg>");F=0>e?`${F}${t}`:`${F.slice(0,e)}${t}${F.slice(e)}`}return{svg:Ev(F,s?.precision),frameType:c.frameType}}function Gv(t,e={}){return function(t,e,o){const{title:n,subtitle:i,theme:r,width:s=1200,height:a,layout:c={},background:l}=e,u=Mt(St(r)),d=c.columns||2,h=c.gap??16;let f=0;n&&(f+=30),i&&(f+=20),f>0&&(f+=10);const p=Math.floor((s-h-h*(d-1))/d),y=[];let g=0,m=f+h,x=0;for(const e of t){const t=Math.min(e.colSpan||1,d),n=p*t+h*(t-1),i=e.props.height||300;g+t>d&&(m+=x+h,g=0,x=0);const s=h/2+g*(p+h),a={...e.props,width:n,height:i,theme:r,_idPrefix:"chart-"+y.length},c=e.component?o.chart(e.component,a):e.frameType?o.frame(e.frameType,a):`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${i}"></svg>`,l=Lv(c,{width:n,height:i}),u=Math.max(i,l.height);y.push({x:s,y:m,width:n,height:u,svg:c,svgDimensions:l}),x=Math.max(x,u),g+=t}const b=a||m+x+h,v=y.map((t,e)=>{return _v("g",{transform:`translate(${t.x},${t.y})`,children:_v("foreignObject",{width:t.width,height:t.height,children:_v("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:(o=t.svg,n=t.svgDimensions,o.replace(/^<svg\b([^>]*)>/,(t,e)=>{const o=e.replace(/\swidth=(?:"[^"]*"|'[^']*')/,"").replace(/\sheight=(?:"[^"]*"|'[^']*')/,"");return`<svg${o} width="100%" height="100%"${/\sviewBox=/.test(o)?"":` viewBox="0 0 ${n.width} ${n.height}"`}${/\spreserveAspectRatio=/.test(o)?"":' preserveAspectRatio="xMidYMid meet"'}>`}))}})})},"dashboard-chart-"+e);var o,n});return Mv.renderToStaticMarkup(Pv("svg",{xmlns:"http://www.w3.org/2000/svg",width:s,height:b,role:"img","aria-label":n||"Dashboard",style:{fontFamily:u.fontFamily},children:[n&&_v("title",{children:n}),l&&_v("rect",{x:0,y:0,width:s,height:b,fill:l}),n&&_v("text",{x:s/2,y:24,textAnchor:"middle",fontSize:u.titleFontSize+4,fontWeight:u.titleFontWeight,fill:u.text,fontFamily:u.titleFontFamily,children:n}),i&&_v("text",{x:s/2,y:n?46:20,textAnchor:"middle",fontSize:u.labelSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:i}),v]}))}(t,e,{chart:Yv,frame:Tv})}import*as Vv from"react-dom/server";import{Fragment as Hv,jsx as Uv,jsxs as Kv}from"react/jsx-runtime";function Zv(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:c,transitionFrames:l=4,fps:u=12,easing:d="ease-out",decay:h}=n,f=o.width||600,p=o.height||400,y=St(o.theme),g={...o,...a&&{xExtent:a},...c&&{yExtent:c}};if(!e||0===e.length)return[];const m=i||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),x=[];for(let t=m;e.length>=t;t+=m)x.push(t);x[x.length-1]!==e.length&&x.push(e.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=ce({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=f-v.left-v.right,k=p-v.top-v.bottom,A=[];if(b)for(let n=0;x.length>n;n++){const i=x[n],s=e.slice(r?Math.max(0,i-r):0,i),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,connectorAccessor:o.connectorAccessor,connectorStyle:o.connectorStyle,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||y.colors.categorical,...h&&{decay:h}},c=new Xg(a);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:w,height:k}),c.scene.length>0&&A.push(nw(c.scene,f,p,y,g))}else for(let n=0;x.length>n;n++){const i=x[n],s=e.slice(r?Math.max(0,i-r):0,i),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:c,colorScheme:o.colorScheme||y.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...l>0&&{transition:{duration:l*(1e3/u),easing:d}}},b=new id(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(A.push(ow(b.scene,f,p,y,g,v)),l>0&&n>0&&b.activeTransition){const t=l*(1e3/u);for(let e=1;l>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/l*t),A.push(ow(b.scene,f,p,y,g,v))}}return A}function Qv(t,e,o={}){return e.map(e=>{try{return Yv(t,{...o,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||e.width||600}" height="${o.height||e.height||400}"></svg>`}})}function Jv(t,e,o){const n=e.size??[e.width??600,e.height??400],i=St(e.theme),r=Mt(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",c=e.title?`${a}-title-${o}`:void 0,l=e.description?`${a}-desc-${o}`:void 0,u=[c,l].filter(Boolean).join(" ")||void 0,d=tv(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=Kv("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&Uv("title",{id:c,children:e.title}),e.description&&Uv("desc",{id:l,children:e.description}),s&&"transparent"!==s?Uv("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,Uv("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>gf(t,e,`${a}-${o}`))})]});return Vv.renderToStaticMarkup(h)}function tw(t,e={}){const{fps:o=12,frameCount:n,durationSeconds:i=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:c}=e,l=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/l)),d=n??Math.max(1,Math.ceil(i*Math.max(1,o))),h=c?{...t,background:c}:t,f=new Ws(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(Jv(f,h,0)));d>p.length;){for(let t=0;u>t;t+=1)f.tick(l);p.push(Jv(f,h,p.length))}return p}function ew(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function ow(t,e,o,n,i,r){const s=Mt(n),a=ce({top:20,right:20,bottom:30,left:40,...i.margin},i.title),c=e-a.left-a.right,l=o-a.top-a.bottom,u=ew(i,n),d=i.renderMode,h=t.map((t,e)=>xf({node:t,index:e,renderMode:d,fallback:()=>gf(t,e)}).element).filter(Boolean),f=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=Mt(n),a=[];for(let n=0;t.length>n;n++){const c=t[n];if("y-threshold"===c.type&&null!=c.value){let t=null;if(r)t=r(c.value);else if(i){const[e,n]=i,r=n-e;if(0===r)continue;t=o-(c.value-e)/r*o}if(null==t)continue;const l=c.color||s.primary,u=c.labelPosition||"right";a.push(Kv("g",{children:[Uv("line",{x1:0,y1:t,x2:e,y2:t,stroke:l,strokeWidth:c.strokeWidth??1.5,strokeDasharray:c.strokeDasharray||"6,4"}),c.label&&Uv("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(o-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:l,fontFamily:s.fontFamily,children:c.label})]},"ann-"+n))}}return a.length>0?Uv(Hv,{children:a}):null}(i.annotations,c,l,n,i.yExtent,r?.y),p="string"==typeof i.title?i.title:void 0,y="string"==typeof i.description?i.description:void 0,g=p?"semiotic-title":void 0,m=y?"semiotic-desc":void 0,x=[g,m].filter(Boolean).join(" ")||void 0;return Vv.renderToStaticMarkup(Kv("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[p&&Uv("title",{id:g,children:p}),y&&Uv("desc",{id:m,children:y}),u&&Uv("rect",{x:0,y:0,width:e,height:o,fill:u}),Kv("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&Uv("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:p})]}))}function nw(t,e,o,n,i){const r=Mt(n),s=ce({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,c=a?s.left+(e-s.left-s.right)/2:s.left,l=a?s.top+(o-s.top-s.bottom)/2:s.top,u=ew(i,n),d=Zg({nodes:t,renderMode:i.renderMode,idPrefix:i.idPrefix}).map(t=>t.element),h="string"==typeof i.title?i.title:void 0,f="string"==typeof i.description?i.description:void 0,p=h?"semiotic-title":void 0,y=f?"semiotic-desc":void 0,g=[p,y].filter(Boolean).join(" ")||void 0;return Vv.renderToStaticMarkup(Kv("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":g,style:{fontFamily:r.fontFamily},children:[h&&Uv("title",{id:p,children:h}),f&&Uv("desc",{id:y,children:f}),u&&Uv("rect",{x:0,y:0,width:e,height:o,fill:u}),Uv("g",{transform:`translate(${c},${l})`,children:d}),h&&Uv("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}Th();export{Zv as generateFrameSVGs,Qv as generateFrameSequence,tw as generatePhysicsFrameSVGs,Yv as renderChart,Xv as renderChartWithEvidence,Gv as renderDashboard,Fv as renderGeoToStaticSVG,Ov as renderNetworkToStaticSVG,Cv as renderOrdinalToStaticSVG,Tv as renderToStaticSVG,Iv as renderXYToStaticSVG,St as resolveTheme,Ev as serializeSvgPrecision,Mt as themeStyles};