semiotic 3.9.1 → 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 (328) hide show
  1. package/README.md +102 -48
  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-xy.d.ts +3 -0
  175. package/dist/components/semiotic.d.ts +9 -3
  176. package/dist/components/server/renderDashboard.d.ts +37 -0
  177. package/dist/components/server/renderEvidence.d.ts +27 -0
  178. package/dist/components/server/renderToStaticSVG.d.ts +2 -30
  179. package/dist/components/server/serverChartConfigShared.d.ts +13 -0
  180. package/dist/components/server/serverChartConfigs.d.ts +9 -0
  181. package/dist/components/server/serverChartConfigsComposite.d.ts +4 -0
  182. package/dist/components/server/serverChartConfigsCustom.d.ts +2 -0
  183. package/dist/components/server/serverChartConfigsGeo.d.ts +1 -0
  184. package/dist/components/server/serverChartConfigsOrdinal.d.ts +3 -2
  185. package/dist/components/server/serverChartConfigsXY.d.ts +1 -0
  186. package/dist/components/server/serverChartConfigsXYExtra.d.ts +3 -0
  187. package/dist/components/server/serverCompositeChainReaction.d.ts +3 -0
  188. package/dist/components/server/serverOrdinalGauge.d.ts +3 -0
  189. package/dist/components/server/serverOrdinalLikert.d.ts +2 -0
  190. package/dist/components/store/selectionProvenance.d.ts +8 -0
  191. package/dist/components/store/themeCore.d.ts +5 -1
  192. package/dist/components/stream/GeoPipelineStore.d.ts +1 -1
  193. package/dist/components/stream/MarginalGraphics.d.ts +3 -3
  194. package/dist/components/stream/MarginalGraphicsLazy.d.ts +22 -0
  195. package/dist/components/stream/NetworkPipelineStore.d.ts +2 -0
  196. package/dist/components/stream/OrdinalPipelineStore.d.ts +1 -1
  197. package/dist/components/stream/PipelineStore.d.ts +1 -1
  198. package/dist/components/stream/SceneToSVG.d.ts +1 -1
  199. package/dist/components/stream/canvasSetup.d.ts +8 -2
  200. package/dist/components/stream/customLayoutAttempt.d.ts +21 -0
  201. package/dist/components/stream/geoTypes.d.ts +1 -1
  202. package/dist/components/stream/isServerEnvironment.d.ts +6 -0
  203. package/dist/components/stream/layouts/forceLayoutNodeSize.d.ts +12 -0
  204. package/dist/components/stream/layouts/forceLayoutPlugin.d.ts +2 -9
  205. package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +2 -21
  206. package/dist/components/stream/layouts/forceLayoutWorkerPolicy.d.ts +21 -0
  207. package/dist/components/stream/layouts/index.d.ts +6 -12
  208. package/dist/components/stream/layouts/missingPlugin.d.ts +7 -0
  209. package/dist/components/stream/layouts/registerBuiltIn.d.ts +1 -0
  210. package/dist/components/stream/layouts/registry.d.ts +12 -0
  211. package/dist/components/stream/marginalConfig.d.ts +3 -0
  212. package/dist/components/stream/networkCustomLayout.d.ts +7 -0
  213. package/dist/components/stream/networkCustomLayoutOutput.d.ts +13 -0
  214. package/dist/components/stream/networkCustomLayoutRunner.d.ts +1 -1
  215. package/dist/components/stream/networkTypes.d.ts +5 -1
  216. package/dist/components/stream/ordinalTypes.d.ts +1 -1
  217. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +1 -1
  218. package/dist/components/stream/pipelineDomainResolution.d.ts +6 -0
  219. package/dist/components/stream/renderers/pointCanvasRenderer.d.ts +4 -0
  220. package/dist/components/stream/renderers/resolveCSSColor.d.ts +4 -4
  221. package/dist/components/stream/types.d.ts +8 -1
  222. package/dist/components/stream/useEnsureCustomXYRenderers.d.ts +18 -0
  223. package/dist/components/stream/useMarginalValues.d.ts +13 -0
  224. package/dist/components/stream/xyCanvasRenderers.d.ts +4 -4
  225. package/dist/components/stream/xyPlugins/areaPlugin.d.ts +2 -0
  226. package/dist/components/stream/xyPlugins/barPlugin.d.ts +2 -0
  227. package/dist/components/stream/xyPlugins/candlestickPlugin.d.ts +2 -0
  228. package/dist/components/stream/xyPlugins/customPlugin.d.ts +6 -0
  229. package/dist/components/stream/xyPlugins/heatmapPlugin.d.ts +2 -0
  230. package/dist/components/stream/xyPlugins/lineFamily.d.ts +5 -0
  231. package/dist/components/stream/xyPlugins/linePlugin.d.ts +2 -0
  232. package/dist/components/stream/xyPlugins/missingPlugin.d.ts +7 -0
  233. package/dist/components/stream/xyPlugins/mixedPlugin.d.ts +2 -0
  234. package/dist/components/stream/xyPlugins/pointPlugin.d.ts +3 -0
  235. package/dist/components/stream/xyPlugins/registerBuiltIn.d.ts +1 -0
  236. package/dist/components/stream/xyPlugins/registry.d.ts +31 -0
  237. package/dist/components/stream/xyPlugins/stackedAreaPlugin.d.ts +2 -0
  238. package/dist/components/stream/xyPlugins/swarmPlugin.d.ts +2 -0
  239. package/dist/components/stream/xyPlugins/waterfallPlugin.d.ts +2 -0
  240. package/dist/forceLayoutWorker.js +1 -1
  241. package/dist/geo.min.js +1 -1
  242. package/dist/geo.module.min.js +1 -1
  243. package/dist/network.module.min.js +1 -1
  244. package/dist/ordinal.module.min.js +1 -1
  245. package/dist/physics.module.min.js +1 -1
  246. package/dist/rough.module.min.js +1 -1
  247. package/dist/semiotic-access.d.ts +9 -0
  248. package/dist/semiotic-access.min.js +2 -0
  249. package/dist/semiotic-access.module.min.js +2 -0
  250. package/dist/semiotic-ai-core.d.ts +9 -0
  251. package/dist/semiotic-ai-core.min.js +1 -1
  252. package/dist/semiotic-ai-core.module.min.js +1 -1
  253. package/dist/semiotic-ai.d.ts +5 -17
  254. package/dist/semiotic-ai.module.min.js +1 -1
  255. package/dist/semiotic-client-cjs-shared.min.js +1 -1
  256. package/dist/semiotic-client-shared.module.min.js +1 -1
  257. package/dist/semiotic-evidence.d.ts +10 -0
  258. package/dist/semiotic-evidence.min.js +1 -0
  259. package/dist/semiotic-evidence.module.min.js +1 -0
  260. package/dist/semiotic-experimental-auxiliary.module.min.js +1 -1
  261. package/dist/semiotic-experimental-node-auxiliary.module.min.js +1 -1
  262. package/dist/semiotic-experimental-react-shared.module.min.js +1 -1
  263. package/dist/semiotic-experimental-vacp.min.js +1 -1
  264. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  265. package/dist/semiotic-line.d.ts +9 -0
  266. package/dist/semiotic-line.min.js +2 -0
  267. package/dist/semiotic-line.module.min.js +2 -0
  268. package/dist/semiotic-network.d.ts +3 -0
  269. package/dist/semiotic-ordinal.d.ts +2 -0
  270. package/dist/semiotic-realtime-core.d.ts +3 -2
  271. package/dist/semiotic-realtime-core.module.min.js +1 -1
  272. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -1
  273. package/dist/semiotic-recipes-core.d.ts +6 -0
  274. package/dist/semiotic-recipes-core.module.min.js +1 -1
  275. package/dist/semiotic-server-edge-node.module.min.js +1 -1
  276. package/dist/semiotic-server-edge.min.js +1 -1
  277. package/dist/semiotic-server-edge.module.min.js +1 -1
  278. package/dist/semiotic-server-node.min.js +1 -1
  279. package/dist/semiotic-server-node.module.min.js +1 -1
  280. package/dist/semiotic-themes-core.d.ts +3 -0
  281. package/dist/semiotic-themes-core.min.js +1 -1
  282. package/dist/semiotic-themes-core.module.min.js +1 -1
  283. package/dist/semiotic-themes.min.js +1 -1
  284. package/dist/semiotic-themes.module.min.js +1 -1
  285. package/dist/semiotic-utils-core.d.ts +5 -0
  286. package/dist/semiotic-utils-core.min.js +1 -1
  287. package/dist/semiotic-utils-core.module.min.js +1 -1
  288. package/dist/semiotic-xy.d.ts +3 -0
  289. package/dist/semiotic.d.ts +9 -3
  290. package/dist/semiotic.module.min.js +1 -1
  291. package/dist/server.min.js +1 -1
  292. package/dist/server.module.min.js +1 -1
  293. package/dist/xy.module.min.js +1 -1
  294. package/package.json +39 -60
  295. package/dist/c-3KZD6AXJ.min.js +0 -1
  296. package/dist/c-4TWEX5HG.min.js +0 -1
  297. package/dist/c-5YCIX3VZ.min.js +0 -1
  298. package/dist/c-6FEKTA3U.min.js +0 -1
  299. package/dist/c-74HEEZGK.min.js +0 -1
  300. package/dist/c-BWNB6USU.min.js +0 -1
  301. package/dist/c-C25ENHIK.min.js +0 -1
  302. package/dist/c-CDR5AO3R.min.js +0 -1
  303. package/dist/c-E3JFRRMI.min.js +0 -1
  304. package/dist/c-EBFPQHHO.min.js +0 -1
  305. package/dist/c-GIKRQI4X.min.js +0 -1
  306. package/dist/c-GPYOFETM.min.js +0 -1
  307. package/dist/c-IDUHYYSI.min.js +0 -1
  308. package/dist/c-JAZ73J32.min.js +0 -1
  309. package/dist/c-KG3NXHAL.min.js +0 -1
  310. package/dist/c-KII3PLZE.min.js +0 -1
  311. package/dist/c-LIXGXMNS.min.js +0 -1
  312. package/dist/c-LVEY6D6B.min.js +0 -1
  313. package/dist/c-M4Y3BHFR.min.js +0 -1
  314. package/dist/c-MAIICR2Z.min.js +0 -1
  315. package/dist/c-MG5DM6VE.min.js +0 -1
  316. package/dist/c-O6U6K4CW.min.js +0 -1
  317. package/dist/c-OQ7M4AGV.min.js +0 -1
  318. package/dist/c-OXYMVK7Q.min.js +0 -1
  319. package/dist/c-QHF5YON3.min.js +0 -1
  320. package/dist/c-RR3GO5SW.min.js +0 -1
  321. package/dist/c-S2BXNNJN.min.js +0 -1
  322. package/dist/c-SUILCHWU.min.js +0 -1
  323. package/dist/c-US5ZFT6E.min.js +0 -1
  324. package/dist/c-UUKVD4WB.min.js +0 -1
  325. package/dist/c-WJCD5EUY.min.js +0 -1
  326. package/dist/c-YDAY2WFR.min.js +0 -1
  327. package/dist/c-ZOWWU34K.min.js +0 -1
  328. /package/dist/{c-COHXCW3Q.min.js → c-YZVRZGX2.min.js} +0 -0
@@ -1 +1 @@
1
- import{PhysicsPipelineStore as t,SEQUENTIAL_INTERPOLATORS as e,UpdateResultTracker as o,absorbRegion as n,annotationLayout as i,bodyGroupSpec as r,capacitatedRegion as s,collidersFromPlotBounds as a,collidersFromXScaleBins as l,countPairwiseCrossings as c,forceFieldRegion as u,forceLayoutPlugin as d,getSequentialInterpolator as h,glyphFractionClipRect as p,glyphHitGeometry as f,glyphPlacement as g,groupCompletionRows as y,interpolateBrBG as m,interpolatePRGn as x,interpolatePiYG as b,interpolateRdBu as v,interpolateRdYlBu as w,interpolateRdYlGn as k,interpolateSpectral as A,interpolateViridis as S,isInBounds as M,makeSymbolResolver as _,orderByBarycenter as P,orderExactSmall as L,packBandsBySilhouette as $,placeWithMinGap as R,portalRegion as C,pressureFieldRegion as T,processChrome as O,processStageLayout as I,refineByAdjacentSwaps as z,resolveAnchoredPosition as F,resolveGlyphPaint as N,resolveX as E,resolveY as D,routeSurfaceRegion as W,schemeCategory10 as B,schemeSet3 as j,schemeTableau10 as Y,symbolPathString as X,symbolRadius as G,useCustomLayoutSelection as V,wrapWithDataHint as H}from"./c-LIXGXMNS.min.js";import{IncrementalExtent as q,RingBuffer as U,annotationStableId as K,coerceDateLikeValue as Z,composeStyleRules as Q,computeArcBoundingBox as J,darkenColor as tt,hatchPatternDef as et,isHatchFill as ot,isTimeLandmark as nt,lightenColor as it,makeNodeRuleContext as rt,makeRuleValueResolver as st,makeXYRuleContext as at,parseDateLikeString as lt,resolveAnnotationGradient as ct,resolveResponsiveRules as ut,resolveStyleRules as dt,resolveSvgFill as ht,styleRulesToNodeStyle as pt,sweepToAngles as ft}from"./c-4TWEX5HG.min.js";import"./c-SUILCHWU.min.js";import{filterAnnotationsByStatus as gt}from"./c-E3JFRRMI.min.js";import{accessorsEquivalent as yt,resolveAccessor as mt,resolveLabelFn as xt,resolveNodeRefId as bt,resolveRawAccessor as vt,resolveStringAccessor as wt}from"./c-MT3WBK7M.min.js";import{getMax as kt,getMin as At,getMinMax as St}from"./c-GGISSW5E.min.js";import"./c-COHXCW3Q.min.js";import{DARK_THEME as Mt,HIGH_CONTRAST_THEME as _t,LIGHT_THEME as Pt,applyThemeAccessibility as Lt,resolveThemePreset as $t,resolveThemeSemanticColors as Rt,themeToCSSVariables as Ct}from"./c-O6U6K4CW.min.js";var Tt={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function Ot(t,e={}){const o=e.mobileSemantics?.interaction,n="number"==typeof o?.targetSize?o.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,i="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!o||void 0!==n,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!i&&!r)return Tt;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??n??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var It={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 zt(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 Ft(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var Nt={kind:"rank-competition"};function Et(t,e,o,n){const i=t??e;return"function"==typeof i?i(o,n):o[i+""]}var Dt=Symbol.for("semiotic.semantic-viability"),Wt=globalThis,Bt=Wt[Dt]??(Wt[Dt]=new Map);function jt(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 Yt(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const n=function(t){return function(t){return Bt.has(t)}(t)?function(t){return Bt.get(t)}(t):"BumpChart"===t?Nt: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(Et(t.yAccessor,"y",o,n))))return;const i=Ft(Et(t.xAccessor,"x",o,n)),r=e.get(i)??new Set;r.add(Et(t.lineBy,"series",o,n)+""),e.set(i,r)});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},r=2>i.max;return r||2>i.contestedColumns||2>i.median?[{code:r?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:r?"error":"warning",message:r?"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(jt)}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 Xt from"react-dom/server.browser";import*as Gt from"react";var Vt=Object.freeze([]);function Ht(t){if(!t)return Vt;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 qt}from"d3-scale";var Ut={category10:B,tableau10:Y,set3:j,...e},Kt=B,Zt="#007bff";function Qt(t,e,o=Kt){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(Ut,t)?Ut[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var Jt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],te=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],ee=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 oe(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")||ee.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):Kt[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))%Kt.length]}function ne(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 ie(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>ne(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 qt().domain(n).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(Ut,o)?Ut[o]:Ut.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(Number(e)/t)}{const t=Array.isArray(r)?r:Kt;return qt().domain(n).range(t).unknown("#999")}}function re(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,l]=o;if(s===r)return(a+l)/2;let c=(i-r)/(s-r);return 0>c?c=0:c>1&&(c=1),a+c*(l-a)}function se(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function ae(t,e){if(!se(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})}var le={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function ce(t,e=le){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 ue(t){return t?ce(t):void 0}function de(t,e,o){return"function"==typeof t?t(o):o[t||e]}function he(t){return t instanceof Date?t.getTime():Number(t)}function pe(t,e){return S(1===e?.5:t/(e-1))}function fe(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 ge(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}function ye(t){if(!t)return Pt;if("string"==typeof t){if("light"===t)return Pt;if("dark"===t)return Mt;if("high-contrast"===t)return _t;return $t(t)||Pt}const e="dark"===t.mode?Mt:Pt,o={...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}};return Lt(o)}function me(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 xe(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 be(t){return Math.round(100*t)/100}function ve(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(be);return{points:t.map(([t])=>[be(t),be(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function we(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,l=(n-a*o)/e;return t=>l+a*t}function ke(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 Ae(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Se="__forecastSegment",Me="__forecastOpacity";function _e(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,l=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[Me]=a+Math.max(0,Math.min(1,t))*(l-a))}return}const c=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=c.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=St(u),p=h-d;t.forEach((t,e)=>{const o=c[e];Number.isFinite(o)&&(t[Me]=l-(p>0?(o-d)/p:0)*(l-a))})}function Pe(t,e){return"function"==typeof e?e(t):!!t[e]}var Le="__semiotic_resolvedX",$e="__semiotic_resolvedY",Re="__compoundGroup";function Ce(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function Te(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?Ht(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?Le:e,s=i?$e:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[Le]=e(t)),i&&(r[$e]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,l=s.yKey,c=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:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:f}=n,g=t.map(t=>{let e="observed";return s&&Pe(t,s)?e="forecast":r&&Pe(t,r)&&(e="training"),{...t,[Se]:e}}),y=n._groupBy,m=[];if(y){const t=new Map;for(const e of g){const o=e[y]??"__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][Se]!==o[t+1][Se]&&(e.push({...o[t+1],[Se]:o[t][Se]}),e.push({...o[t],[Se]:o[t+1][Se]}));m.push(...g,...e)}else for(let t=0;g.length>t;t++)m.push(g[t]),g.length-1>t&&g[t][Se]!==g[t+1][Se]&&(m.push({...g[t+1],[Se]:g[t][Se]}),m.push({...g[t],[Se]:g[t+1][Se]}));if(n.trainUnderline){const t=[];for(const e of m)"training"===e[Se]&&t.push({...e,[Se]:"training-base"});m.unshift(...t)}const x=[];if(l&&c){const t="string"==typeof l?l:"__envUpper",e="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const o of m)"function"==typeof l&&(o[t]=l(o)),"function"==typeof c&&(o[e]=c(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:f})}if(n.uncertaintyOpacity||n.confidenceAccessor){const t=l?"function"==typeof l?l:t=>t[l]:()=>{},e=c?"function"==typeof c?c:t=>t[c]:()=>{};_e(m.filter(t=>"forecast"===t[Se]),n,t,e)}if(a){const t=n.anomalyStyle,e={type:"highlight",filter:t=>Pe(t,a)};t?(e.style=t,e.r=p):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=p):(e.color=h,e.r=p,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:l="#6366f1",bandOpacity:c=.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,[Se]:"observed"}):d.push({...o,[Se]:"training"});const p=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]),f=[],g=[];if(p.length>=3){const i=p.length,r=we(p);if(r){const{se:d,meanX:h,ssX:y}=ke(p,r),m=Ae(a),x=t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t)),b=kt(x),v=p.length>1?(p[i-1][0]-p[0][0])/(i-1):1;for(let t=1;s>=t;t++){const n=b+t*v,s=r(n),a=d*Math.sqrt(1+1/i+(y>0?(n-h)**2/y:0))*m;g.push({[e]:n,[o]:s,[Se]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}_e(g,n,t=>t.__forecastUpper,t=>t.__forecastLower),f.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}f.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&f.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 y=[];if(y.push(...d),d.length>0&&h.length>0&&y.push({...d[d.length-1],[Se]:"observed"}),y.push(...h),g.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&y.push({...t,[Se]:"forecast"}),y.push(...g)}return{processedData:y,annotations:f}}(t,e,o,n,i);var r}(r,a,l,n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,t.anomaly);if(r=e.processedData,c.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,l=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>l&&(l=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[Re]:`${t[n]}__${t[Se]||"observed"}`})),d=Re):d=Se,t.baseLineStyle){const e=function(e,o){const n=o.trainDasharray??"8,4",i=o.forecastDasharray??"4,4",r=o.color||"#6366f1",s=o.trainOpacity,a=o.forecastOpacity,l=o.trainStroke,c=o.trainLinecap,u=o.trainUnderline;return e=>{const o=(e=>t.baseLineStyle(e))(e),d=e[Se];if("training"===d){let t=o.stroke;return"darken"===l?t=tt(o.stroke||"#666",.5):l&&(t=l),{...o,stroke:t,strokeDasharray:n,...c&&{strokeLinecap:c},...null!=s&&{strokeOpacity:s}}}if("training-base"===d){let t=o.stroke||"#666";return"lighten"===u&&(t=it(t,.4)),{...o,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Me],n=null!=t?t:a;return{...o,stroke:r,strokeDasharray:i,...null!=n&&{strokeOpacity:n}}}return o}}(0,t.forecast);h=t=>e(t)}}else t.anomaly&&c.push(...(p=t.anomaly,[{type:"anomaly-band",threshold:p.threshold??2,showBand:!1!==p.showBand,fill:p.bandColor||"#6366f1",fillOpacity:p.bandOpacity??.1,anomalyColor:p.anomalyColor||"#ef4444",anomalyRadius:p.anomalyRadius??6,label:p.label}]));var p;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)Ce(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)Ce(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 l=()=>{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)Ce(t,o,n)?l():r.push(t);l()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,l,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let f;if(t.directLabel){const e=function(t,e,o,n,i,r,s,a){if(!e||!o)return{annotations:[]};const l="object"==typeof e?e:{},c=l.position||"end",u=l.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 p=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[n])-Number(e[n])),p.set(t,"end"===c?e[e.length-1]:e[0]);const f=ie(Array.from(p.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),g=Array.from(p.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===c?6:-6,dy:0,color:f?oe({__lbl:t},"__lbl",f):a||Zt,fontSize:u}));g.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;g.length>t;t++){const e=g[t-1],o=g[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const y=g.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===c?{right:y}:{left:y}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,t.colorScheme,t.themeCategorical,t.color);c.push(...e.annotations),f=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?l:o,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:f}}function Oe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrScatterColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],p=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],f=p.length?St(p):void 0,g=at(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?re(t,d,h,f):"number"==typeof i.pointRadius?i.pointRadius:5};return y?.length&&Object.assign(o,dt(t,y,g(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 Ie={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Te({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),s=ge(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||Oe(t,e,o,n,i),showLegend:n.showLegend??!!e}}},ze={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=ge(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||Fe(t,e,o,n,i),showLegend:n.showLegend??!!e}}};function Fe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrBubbleColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],p=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],f=p.length?St(p):void 0,g=at(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?re(t,d,h,f):h[0],stroke:i.bubbleStrokeColor??"white",strokeWidth:i.bubbleStrokeWidth??1};return y?.length&&Object.assign(o,dt(t,y,g(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 Ne,useCallback as Ee,useState as De,useId as We,useEffect as Be,useRef as je}from"react";function Ye(...t){let e;for(const o of t)o&&(e=Xe(e)&&Xe(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function Xe(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function Ge(t){return"object"==typeof t&&null!==t&&"gradient"in t}function Ve(t){return"string"==typeof t&&t.length>0}function He(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function qe(t,e){return He(t,Ve(e))}function Ue(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 Ke(t){return Math.ceil(7*t.length)}function Ze(t,e){if(Xe(t)){const o=lo(e),n=t.legendGroups.flatMap(t=>[t.label?Ke(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+Ke(t.label))]);return Math.max(100,...n)}if(Ge(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),n=Math.max(Ke(o(e.domain[0])),Ke(o(e.domain[1]))),i=e.label?Ke(e.label):0;return Math.max(100,19+n,i)}return 100}function Qe(t){return(Xe(t)||Ge(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function Je(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?oo:eo:0}function to(t){return Math.max(0,t?.edgeGutter??3)}var eo=34,oo=70;function no(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function io(t,e,o){if(Ge(t))return t.gradient.label?46:26;if(!Xe(t))return 20;const n=lo(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+Ke(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?Ke(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function ro(t,e,o){return Ze(t,e)+Qe(t)+Je(e,o)+to(e)}function so(t,e){const{legend:o}=e;if(!o)return;const n=e.position??"right",i=io(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+Qe(o)+no("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,ro(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===n?t.left=Math.max(t.left,r,ro(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 ao(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??Ze(t,e.legendLayout)),s=Qe(t),a=Je(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),l=to(e.legendLayout),c=io(t,i,e.legendLayout),u=no(e.axisChrome,e.legendLayout),d=no(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(l,e.margin.left-a-r-s),y:e.margin.top,width:r,height:c};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-c,width:r,height:c};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-c)),width:r,height:c}}return{x:Math.min(e.totalWidth-r-l,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:c}}function lo(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 co(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 uo(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=ne(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=Ut[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]:Zt}function ho(t,e,o){return"function"==typeof t?t(e,o):e[t]}function po(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[Ft(t),e]));return t.map(t=>{const e={...t},n=n=>{if(!(n in t))return;const i=o.get(Ft(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})}function fo(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 go(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 yo(t,e,o,n,i){const r=[],s=(t.x+e.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===n?(c=t.x+(e.x-t.x)*l,u=t.y+(e.y-t.y)*l,d=e.x-t.x,h=e.y-t.y):(c=fo(t.x,s,s,e.x,l),u=fo(t.y,t.y,e.y,e.y,l),d=go(t.x,s,s,e.x,l),h=go(t.y,t.y,e.y,e.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*l,datumIndex:.5>l?o:o+1})}return r}function mo(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=yo(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,l=e.dx/r,c=Math.max(0,e.radius);o.push([e.x+s*c,e.y+l*c]),n.push([e.x-s*c,e.y-l*c]),i.push(e.datumIndex)}}return{topPath:o,bottomPath:n,datumIndices:i}}import{jsx as xo}from"react/jsx-runtime";function bo({datum:t,x:e,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=V(),l=a.isActive&&!a.predicate(t),c="function"==typeof s?s(t.__bumpRaw):s;return xo("text",{className:"semiotic-bump-label",x:e+("end"===n?8:-8),y:o,dy:"0.35em",textAnchor:"end"===n?"start":"end",fill:i,fillOpacity:l?.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)",...c},children:t.__bumpSeries})}function vo(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 wo(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 ko(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,l=(e.colorMap&&ne(e.colorMap,r))??t.resolveColor(n[0].__bumpSeries,n[0]),c=e.color??(a?l:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??l),u=n.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?vo(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=mo(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:c,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,dt(n[0].__bumpRaw,e.styleRules,wo(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:c,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(n,dt(t.__bumpRaw,e.styleRules,wo(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 p=!0===e.showLabels?"end":e.showLabels,f=(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:c})};"start"!==p&&"both"!==p||f(n[0],0,"start"),"end"!==p&&"both"!==p&&"auto"!==p||f(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(xo(bo,{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?xo("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 Ao={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,n,i)=>{const r=function(t,e={}){const o=e.xAccessor??"x",n=e.yAccessor??"y",i=e.lineBy??"series",r=e.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;t.forEach((t,e)=>{const r=ho(o,t,e),p=Ft(r);let f=a.get(p);null==f&&(f=s.length,a.set(p,f),s.push(r),l.set(f,[]));const g=ho(i,t,e)+"";u.has(g)||(u.set(g,c.length),c.push(g));const y=Number(ho(n,t,e));Number.isFinite(y)&&(d=Math.min(d,y),h=Math.max(h,y),l.get(f)?.push({datum:t,inputIndex:e,series:g,value:y}))});const p=[],f=new Map,g=new Map;for(let t=0;s.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,o)=>{const n=o+1;p.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:n}),f.set(e.series,(f.get(e.series)??0)+n),g.set(e.series,(g.get(e.series)??0)+1)})}const y=c.length+1,m=[...c].sort((t,e)=>{const o=g.get(t)??0,n=g.get(e)??0;return((f.get(t)??0)+(s.length-o)*y)/Math.max(1,s.length)-((f.get(e)??0)+(s.length-n)*y)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),x=new Set(m.slice(0,null==e.highlightTop?m.length:Math.max(0,Math.floor(e.highlightTop))));return{data:p.map(t=>{const e=x.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:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}(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}),s=Math.max(1,r.seriesOrder.length),a=ye(n.theme),l=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:n,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=t;if(null==n&&null==i)return r;const c=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??(c.has(t)?uo(void 0,a,r,t,u):s??l??"#b8bec8")});return d}({seriesOrder:r.seriesOrder,overallOrder:r.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:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={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:r.valueExtent,seriesOrder:r.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},u=n.xFormat,d=(t,e)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((t,e)=>e),p=Array.from({length:s},(t,e)=>e+1),f=n.axes??[{orient:"left",tickValues:p,tickFormat:t=>t+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:ko,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:f,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:po(n.annotations,r.xValues)}}};function So(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrAreaColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,p="number"==typeof i.areaOpacity?i.areaOpacity:.7,f=st(i.yAccessor),g=i.styleRules;return(t,o)=>{const n=e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,r={fill:n,fillOpacity:p,stroke:d?n:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(r,dt(t,g,{value:f(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 Mo(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrPointColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt;return{r:d,fill:o,stroke:"none"}}}var _o={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",l=ye(n.theme).colors.categorical,c=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrLineColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=at(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:l,ruleContext:c}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let p;return r?p=r(t,u):o?n&&(p=oe(t,o,n)):p=i||Zt,void 0!==p&&(d.stroke=p,h&&(d.fill=p,d.fillOpacity=a)),l?.length&&Object.assign(d,dt(t,l,c?c(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 ae(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=Te({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:l,baseLineStyle:c}),d=n.pointStyle||Mo(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 p=(!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||c,...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:p}}},Po={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?Ht(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=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=xe(i,o,"time"),r=xe(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:c,extentPadding:i.extentPadding}):c,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}};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:l,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,showLegend:n.showLegend??!!l}}},Lo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=Te({data:Array.isArray(t)?Ht(t):[],xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.areaBy,forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(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"}),l=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),c=l?.stops.length?{stops:l.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:ce(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}(l):void 0,d=n.pointStyle||Mo(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!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:n.lineStyle||So(a,r,o,n,i),...d&&{pointStyle:d}}}},$o={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=t=>he(de(r,"x",t)),c=t=>he(de(s,"a",t)),u=t=>he(de(a,"b",t)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",p=i.areaOpacity??.6,f=i.lineWidth??1.5,g=!1!==i.showLines,y=!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,l=null,c=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),p=(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],f=e(r),g=o(r),y=n(r);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(y))continue;const m=u(g,y);if(null!==m)if(null!=a){if(l&&l.w!==m){let t,e;if(c.length>0)t=c[0].x,e=c[0].y;else{const o=g-l.a-(y-l.b);if(0!==o){const n=Math.max(0,Math.min(1,(l.b-l.a)/o));t=l.x+n*(f-l.x),e=l.a+n*(g-l.a)}else t=l.x,e=l.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;c.length>t;t++)p(c[t],a)}else for(const t of c)p(t,a);c=[],h({__x:f,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:f,a:g,b:y,w:m}}else{a=m;for(const t of c)p(t,a);c=[],h({__x:f,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:f,a:g,b:y,w:m}}else c.push({x:f,y:g,datum:r})}for(const t of c)p(t,a??"A");return r}(Array.isArray(t)?t:[],l,c,u),w=[];if(g&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(l(t))).sort((t,e)=>l(t)-l(e));for(const t of e){const e=l(t),o=c(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:p}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:f,fill:"none"}),curve:i.curve||"linear",...n,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},Ro={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?ie(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=n.lineStyle||(t=>{const e=null==r?void 0:oe(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}},l=i.styleRules;if(l?.length){const e=st(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,dt(t,l,{value:e(t),category:o}))}return n}),c=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Mo(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:c,stackOrder:i.stackOrder,lineStyle:l,...n,...u&&{pointStyle:u},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!r}}},Co={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)}}},To={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,p=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,f=Gt.createElement,g=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const n=o.width,i=o.height,l=null!=r?e.x(r):n/2,g=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(g))return null;const y=Math.max(0,Math.min(n,l)),m=Math.max(0,Math.min(i,g)),x=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:n-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:i-m},{c:a.bottomRight,x:y,y:m,w:n-y,h:i-m}],b=c?[f("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),f("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),f("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),f("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 f(Gt.Fragment,null,...x.map((t,e)=>t.w>0&&t.h>0?f("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),f("line",{key:"vc",x1:y,y1:0,x2:y,y2:i,stroke:d,strokeWidth:h,strokeDasharray:p}),f("line",{key:"hc",x1:0,y1:m,x2:n,y2:m,stroke:d,strokeWidth:h,strokeDasharray:p}),...b)}]: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||Oe(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...g&&{svgPreRenderers:g}}}},Oo={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:he(de(e.orderAccessor,"order",t))-he(de(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=he(de(o,"x",t)),i=he(de(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=he(de(o,"x",t)),i=he(de(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=Te({data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),a=ge(s.annotations,i.regression),l=i.pointRadius??4,c=at(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=pe(t,e.length);100>e.length&&o.push(Gt.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),o.push(Gt.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:l,strokeLinecap:"round"}))}return Gt.createElement(Gt.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:ae(t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1,i={fill:n>0?pe(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(i,dt(t,u,c(t))),i},fe(i)),...n,...a&&a.length>0&&{annotations:a},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}},Io={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=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,l=null!=r&&Object.hasOwn(r,"heatmapColorScale"),c=r?.heatmapColorScale,u=l?"function"==typeof c?c:void 0:"custom"===a&&"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,areaStyle:()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:s}),...n,...void 0!==a&&{colorScheme:a},...u&&{heatmapColorScale:u}}}};function zo(t){return Math.max(0,Math.min(1,t))}function Fo(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 No(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 Eo(t,e,o){const n=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:zo(t.offset),color:t.color??o,opacity:null==t.opacity?1:zo(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=Fo(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=zo(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,l=Fo(e.color),c=Fo(o.color);if(!l||!c)return i(.5>a?e:o);const[u,d,h]=l,[p,f,g]=c,y=u+(p-u)*a,m=d+(f-d)*a,x=h+(g-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?No(y,m,x):`rgba(${Math.round(y)},${Math.round(m)},${Math.round(x)},${b})`}return i(n[n.length-1])}function Do(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as Wo,jsx as Bo,jsxs as jo}from"react/jsx-runtime";import{useMemo as Yo,useCallback as Xo,useRef as Go}from"react";var Vo={RdBu:v,PiYG:b,PRGn:x,BrBG:m,RdYlBu:w,RdYlGn:k,Spectral:A},Ho="__likert_neutral_neg",qo="__likert_neutral_pos";function Uo(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}import*as Ko from"react";function Zo(t){return ce(t)}function Qo(t,e,o,n,i){const r=ye(n.theme).colors.categorical,s=o??n.colorScheme,a=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],l="string"==typeof e?e:"__ssrColorBy",c="function"==typeof e?a.map(t=>({...t,__ssrColorBy:e(t)})):a,u=e?ie(c,l,s??r):void 0,d=uo("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=st(i.valueAccessor),p=i.styleRules,f=n.pieceStyle;return(t,o)=>{const n={fill:e&&u?oe(t,e,u):d};return p?.length&&Object.assign(n,dt(t,p,{value:h(t),category:o})),"function"==typeof f?Object.assign(n,f(t,o)||{}):f&&"object"==typeof f&&Object.assign(n,f),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 Jo(t,e,o,n,i){const r=Qo(t,e,o,n,i);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 tn(t,e,o,n,i){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,l=ye(n.theme).colors.categorical,c=o??n.colorScheme,u=e?ie(a,s,c??l):void 0,d=uo("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return t=>{const o=e&&u?oe(t,e,u):d;return{fill:o,fillOpacity:.6,stroke:i.stroke??o,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function en(t,e,o,n,i){const r=Qo(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function on(t,e,o,n,i){const r=Qo(t,e,o,n,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=c.length?St(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?re(t,a,l,u):d,fillOpacity:h,...r(t,e)})}var nn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=ge(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:Zo(n.gradientFill),pieceStyle:Qo(t,e,o,n,i)}}},rn={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:Zo(n.gradientFill),pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},sn={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:Zo(n.gradientFill),pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},an={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;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:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},ln={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;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:Qo(t,r,o,n,i)}}},cn={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),l=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}:l?{rExtent:l}:{},...n,summaryStyle:Jo(t,e,o,n,i)}}},un={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:n.summaryStyle||Jo(t,e,o,n,i)})},dn={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:n.summaryStyle||tn(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},hn={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:n.pieceStyle||on(t,e,o,n,i),showLegend:n.showLegend??!!e})},pn={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>{const r=ge(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:en(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e}}},fn={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:Zo(n.gradientFill),pieceStyle:n.pieceStyle||Qo(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},gn={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:n.summaryStyle||((r,s)=>({fillOpacity:.5,...Qo(t,e,o,n,i)(r,s)})),showLegend:n.showLegend??!!e})},yn={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){const s=new Map,a=new Set(e);for(const l of t){const t=o(l);s.has(t)||s.set(t,new Map);const c=s.get(t);if(n){const t=n(l);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];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const t=i(l),e=r(l);if(!a.has(t))continue;c.set(t,(c.get(t)||0)+(Number.isFinite(e)?e:0))}}const l=[];for(const[t,o]of s){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],s=o.get(r)||0;l.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/n*100,__likertLevelIndex:i})}}return l}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,Uo(i.categoryAccessor,"question"),i.levelAccessor?null:Uo(i.valueAccessor,"score"),i.levelAccessor?Uo(i.levelAccessor,"level"):null,i.levelAccessor?Uo(i.countAccessor,"count"):null);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===Ho?r=o:o.__likertLevel===qo?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:Ho,__likertPct:-t}),r.push({...e,__likertLevel:qo,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const l=ye(n.theme).colors.diverging,c=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(Vo,e)){const o=Vo[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,l),u=new Map(r.map((t,e)=>[t,c[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)+"%",p=Ye(!1===n.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},n.legend);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:ae(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===Ho||e===qo?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},fe(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}},mn={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:Qo(t,s,o,n,i),showLabels:i.showLabels??!0}}},xn={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 jo(Wo,{children:[o.showNeedle&&jo(Wo,{children:[Bo("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"}),Bo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&Bo("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,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return jo("g",{children:[Bo("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"}),Bo("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:c,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,l=i.arcWidth??.3,c=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=ft(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],p=ue(n.gradientFill),f=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,n))-e)/d;let p=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];p=p.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>p[p.length-1].value&&p.push({value:o,color:p[p.length-1].color});const f=!!c&&c.stops.length>=2,g=[],y=new Map,m=[];if(f){const t=a?h:1,e=Do("bg",0);if(g.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.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(Eo(c.stops,t*(e+.5)/o,r||p[0]?.color||"#007bff"));const i=Do("fill",0);g.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),y.set(i,{fill:n[0]||s})}}else{let t=e;for(let o=0;p.length>o;o++){const n=p[o],i=(n.value-t)/d,r=(t-e)/d,l=(n.value-e)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const t=Do("fill",o);g.push({category:t,value:c,_zone:n.label||"Zone "+(o+1),_isFill:!0}),y.set(t,{fill:n.color})}if(u>0){const t=Do("bg",o);g.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),y.set(t,{fill:s,opacity:.4})}t=n.value}}if(l&&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:g,pieceStyle:(t,e)=>y.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:p}),[g,y]=n.size||[300,250],m=J(a),x=Math.min(10,Math.max(1,Math.min(g,y)/12)),b=Math.max(4,Math.min((g-2*x)/m.width,(y-2*x)/m.height)-2),v=Math.max(0,Math.min(b-1.5,b*(1-l))),w=g/2-m.cx*b,k=y/2-m.cy*b,A=2*(b+4),S=Math.max(r,Math.min(s,i.value??r)),M="function"==typeof i.valueFormat?i.valueFormat(S):Math.round(S)+"",_=i.centerContent??n.centerContent,P=null!=_?"function"==typeof _?_(S,r,s):_:"sparkline"===i.mode||"context"===i.mode?void 0:Ko.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Ko.createElement("div",{style:{fontSize:Math.max(16,.3*b),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==i.showScaleLabels&&Ko.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:f.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:v,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:ae(f.pieceStyle,fe(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[g,y],margin:{top:k-A/2,bottom:y-k-A/2,left:w-A/2,right:g-w-A/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(n.annotations)?n.annotations:[],...f.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:l,value:S,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:b,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:b-1,showNeedle:c,needleColor:i.needleColor,..."context"===i.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*b))}}}}};import{scaleTime as bn}from"d3-scale";var vn={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function wn(t="static"){return vn[t]??vn.static}var kn=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function An(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:kn.has(t.kind)?"fatal":"warn"}function Sn(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 Mn(){return Object.create(null)}function _n(t,e){return e>t?-1:t>e?1:0}function Pn(t){return t.occupants.map(t=>t.id).sort(_n).join("\0")}function Ln(t,e,o=0){return t.slice(0,-1).map((n,i)=>null!=n.group&&n.group===t[i+1].group?o:e)}function $n(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 Rn(t,e,o){if(0===t.length)return[];const{padding:n,plotH:i,valueScale:r}=o,s=o.stackValueScale??r,a=Ln(t,n,o.groupPadding??0),l=[n+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)l.push(l[o-1]+e[o-1]*s+a[o-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*s+n;if(c>i&&c>0){const t=i/c;for(let e=0;l.length>e;e++)l[e]*=t}return l}function Cn(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 Tn(t,e,o,n,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:$($n(n,o)).adjacentClearance,a=Rn(n,s,r);let l="hug"===r.lanePlacement?function(t,e,o,n,i,r,s){const a=t.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=Ln(t,l,s.groupPadding??0),h=i.map((t,e)=>t*u+d[e]),p=l+t[0].peak.topPeak*u,f=c-l-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=f-p)return Rn(t,i,s);let g=1===a?[(p+f)/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),l=n[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=Cn(a,u),h=Cn(l,u);t[o]+=(g[s]+h-d)*c,i[o]+=c,t[s]+=(g[o]+d-h)*c,i[s]+=c}const r=g.map((e,o)=>0===i[o]?e:.45*e+t[o]/i[o]*.55),s=R({desired:r,minGaps:h,weights:i.map(t=>Math.max(1,t)),min:p,max:f});let l=0;for(let t=0;a>t;t++)l=Math.max(l,Math.abs(s[t]-g[t]));if(g=s,.01>l)break}return g}(n,i,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=Mn();for(const n of t)o[n.id]=e[i[n.id]];return o};On(o(l),e)>On(o(a),e)+1e-6&&(l=[...a])}const c=Mn();for(const e of t)c[e.id]=l[i[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=c[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:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function On(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 In(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 zn(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 Fn(t,e){let o=0,n=1;for(let i=0;28>i;i++){const i=(o+n)/2;t>zn(0,e,e,1,i)?o=i:n=i}return(o+n)/2}function Nn(t,e,o){const n=e+Cn(t,o),i=t.value*o/2;return[n-i,n+i]}function En(t,e,o,n){return Math.max(0,Math.min(e,n)-Math.max(t,o))/Math.max(1e-9,e-t)}function Dn(t,e,o,n,i,r,s){const{valueScale:a,domain:l,mode:c="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 p=e[s.source]?.localAttachments.get(s.id),f=e[s.target]?.localAttachments.get(s.id);if(!p||!f)continue;const g=Math.max(s.startTime,l?.[0]??-1/0),y=Math.min(s.endTime,l?.[1]??1/0);if(g>=y)continue;const[m,x]=Nn(p,i[s.source],a),[b,v]=Nn(f,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 l=[g,y];if("quality"===c)for(const t of n.occupants)for(const o of e[t.id]?.samples??[])o.t>g&&y>o.t&&l.push(o.t);const h=t=>{const o=Fn((t-g)/(y-g),u),l=zn(m,m,b,b,o),c=zn(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=In(e[o.id],t),h=i[o.id];d=Math.max(d,En(l,c,h-u.top*a,h+u.bot*a))}return d},p=[...new Set(l)].sort((t,e)=>t-e);let f=0;for(let t=0;p.length-1>t;t++){const e=p[t],o=p[t+1]-e;f+=(h(e+.25*o)+h(e+.5*o)+h(e+.75*o))/3*o}d+=f/(y-g)*(s.value>0?s.value:1)}}return d}function Wn(t,e,o,n,i,r,s,a,l,c,u="both",d){return{crossings:t,weightedLength:e,pixelLength:On(s,o),transitOcclusion:Dn(o,n,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Bn(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function jn(t,e){return t.map(t=>({t:Bn(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function Yn(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 Xn(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 l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(l[t.kind]??99)-(l[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)||_n(t.edge?.id??"",e.edge?.id??"")||_n(t.side,e.side)||t.delta-e.delta)},u=a.length?At(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;c();let p=null,f=0;for(const t of a)t.time!==p&&(p=t.time,f=0),t.sequence=f++;const g=t=>({time:t.time,phase:0,sequence:t.sequence??0}),y=[];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=g(t);y.push({...i,delta:-n,kind:"transfer-out",side:e}),y.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&&(y.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(...y),c();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 C=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let T=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===T||T>t.systemInTime)&&(T=t.systemInTime);let O=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===O||t.systemOutTime>O)&&(O=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=C?C:-1/0,null!=O?O:-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!=T&&Number.isFinite(T)&&n.t>T&&r>T&&(r=T,i=n),i&&Number.isFinite(r)&&$.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let I=$;if("max"===i&&null!=d&&null!=C&&C>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}};I=[...$.filter(t=>d>t.t),{t:d,...e},{t:C,...e},...$.filter(t=>t.t>C)]}}return{samples:I,peak:k,topPeak:A,botPeak:S,localAttachments:_}}function Gn(t){const e=Mn();return t.forEach((t,o)=>{for(const n of t.occupants)e[n.id]=o}),e}function Vn(t,e,o){t.splice(0,t.length,...o);const n=Gn(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,n)}function Hn(t){const e=new Map,o=[];t.forEach((t,n)=>{if(!t.group)return void o.push({anchor:n,stableId:Pn(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(Pn).join("\0")}`,slots:n.slots});return o.sort((t,e)=>t.anchor-e.anchor||_n(t.stableId,e.stableId))}function qn(t){return t.some(t=>t.group)?Hn(t).flatMap(t=>t.slots):[...t]}function Un(t){return t.flatMap(t=>t.slots)}function Kn(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 Zn(t,e){t.some(t=>t.group)&&Vn(t,e,qn(t))}function Qn(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 Jn(t,e){return c(e,e=>[t[e.source],t[e.target]],Qn)}function ti(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 ei(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 oi=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},ni=828*oi(8),ii=3e3;function ri(t,e,o,n,i,r,s){const a=[...i],l=new Map(i.map(t=>[t,Pn(t)])),c=new Map;for(const t of i)for(const e of t.occupants)c.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=c.get(t.source),o=c.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])||!Qn(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 p=new Map;for(const t of i)p.set(t,[]);for(const t of h)for(const e of t.involvedSlots)p.get(e)?.push(t);const f=new Uint32Array(h.length);let g=0;const y=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,y)*(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 $($n([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 R=new Map,C=new Map,T=new Map,O=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)O(R,t.source,t.target),O(C,t.target,t.source),O(T,t.source,t.target),O(T,t.target,t.source);const I=e.flatMap(t=>{if(!(t=>1===R.get(t.source)?.size&&R.get(t.source).has(t.target)||1===T.get(t.source)?.size||1===T.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}]:[]}),F=t=>{let e=0;for(const o of I)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*v},N=t=>{const e=new Int16Array(i.length);for(let o=0;t.length>o;o++)e[S.get(t[o])]=o;return F(e)},E=h.map(t=>{const e=_.get(t.first),o=_.get(t.second);return[e.source,e.target,o.source,o.target]}),D=new Int16Array(i.length),W=new Float64Array(i.length),B=new Float64Array(i.length+1),j=t=>{for(let e=0;t.length>e;e++)D[S.get(t[e])]=e;let e=0;for(const[t,o,n,i]of E)0>(D[t]-D[n])*(D[o]-D[i])&&e++;if(t.length>0){const e=S.get(t[0]);W[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]);W[n]=W[o]+A(t[e-1],t[e])*s.valueScale+s.padding}const o=S.get(t[t.length-1]),n=W[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;W.length>e;e++)W[e]*=t}}B[0]=0;for(let e=0;t.length>e;e++)B[e+1]=B[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,n=0,i=0;for(const t of M){const e=D[t.source],r=D[t.target];if(o+=Math.abs(e-r)*t.weight,n+=Math.abs(W[t.source]-W[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;i+=(B[Math.max(e,r)]-B[o])*t.weight}}return e*b+n+i*m+F(D)+1e-6*o},Y=(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},X=n=>{const i=Gn(n),r=n.slice(0,-1).map((t,e)=>A(t,n[e+1])),a=Tn(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:ti(i,e),pixelLength:On(a.centerlines,e),transitOcclusion:Y(n,i)}},G=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*b+e.pixelLength+e.transitOcclusion*m+N(o)+1e-6*e.weightedLength}),V=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+ei(o,e,u),0),w.fullCrossing++}return G(o,X(t),t)},H=(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+ei(o,e,u),0),w.fullCrossing++}const l=X(t);return G(a,{...l,transitOcclusion:Dn(e,o,t,l.map,l.geometry.centerlines,n,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let q=[...a];const U=(t,e)=>_n(l.get(t),l.get(e)),K=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}(q),Z=t=>{const e=(t=>{const e=P(t,d,t=>V(t).cost,{passes:6,compare:U,maxEvaluations:ii});let o=V(e),n=ii;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 l=0;const c=[];g++;for(const t of[...p.get(r)??[],...p.get(s)??[]])f[t.index]!==g&&(f[t.index]=g,c.push(t),l+=ei(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 c)h+=ei(t,d,u);w.localCrossing+=c.length;const y=V(e,o.crossings-l+h);o.cost>y.cost?(o=y,i=!0):[e[t],e[t+1]]=[r,s]}if(!i)break}return e})(t);if((t.length>8?1/0:oi(t.length)*(t.length+M.length+E.length))>ni)return e;const o=L(t,j,{maxItems:8,maxEvaluations:5e4}),n=H(o),i=H(e);return n.crossings!==i.crossings&&i.crossings>n.crossings?o:e},Q="geometry-refine"===s.mode;if(Q||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!Q&&"inside-out"===s.laneOrder)if(K){const t=Hn(q),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||_n(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];q=Un(n)}else{const t=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(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];q=e}}else q=K?(t=>{let e=Hn(t);if(1>=e.length)return Un(e);const o=t=>V(Un(t)).cost;e=Hn(Z(t)),e=Kn(e,d,U);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=P(e,n,o,{passes:6,compare:(t,e)=>_n(t.stableId,e.stableId),maxEvaluations:ii}),e=z(e,o,{passes:8,maxEvaluations:ii});const i=e.length>8?1/0:oi(e.length)*(e.length+M.length+E.length);if(ni>=i){const t=L(e,t=>j(Un(t)),{maxItems:8,maxEvaluations:5e4}),o=Un(t),n=Un(e),i=H(o),r=H(n);i.crossings!==r.crossings?e=r.crossings>i.crossings?t:e:r.cost>i.cost&&(e=t)}return e=Kn(e,d,U),Un(e)})(q):Z(q);if(!Q&&"crossing-min+inside-out"===s.laneOrder&&q.length>1)if(K){const t=Hn(q);let e=V(Un(t)),o=Un(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)||_n(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=Un(t),l=V(a);l.cost>e.cost?(t.splice(i,1),t.splice(s,0,r)):(e=l,n.cost>l.cost&&(o=a,n=l))}q=o}else{let t=V(q),e=[...q],o=t;const n=Math.floor((q.length-1)/2),i=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(t,e));for(const r of i){const i=q.indexOf(r);if(i===n)continue;q.splice(i,1),q.splice(n,0,r);const s=V(q);s.cost>t.cost?(q.splice(n,1),q.splice(i,0,r)):(t=s,o.cost>s.cost&&(e=[...q],o=s))}q=e}if((Q||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&q.length>1)if(K){let t=Hn(q),e=H(Un(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=Un(t),r=H(i,void 0,"score");e.cost>r.cost?(q=i,e=r,o=!0):[t[n],t[n+1]]=[t[n+1],t[n]]}if(!o)break}t=Kn(Hn(q),d,U),q=Un(t)}else{let t=H(q,void 0,"score");for(let e=0;q.length-1>e;e++){const o=q[e],n=q[e+1],i=new Map(q.map((t,e)=>[t,e]));let r=0;const s=[];g++;for(const t of[...p.get(o)??[],...p.get(n)??[]])f[t.index]!==g&&(f[t.index]=g,s.push(t),r+=ei(t,i,u));[q[e],q[e+1]]=[n,o];const a=new Map(i);a.set(o,e+1),a.set(n,e);let l=0;for(const t of s)l+=ei(t,a,u);w.localCrossing+=s.length;const c=H(q,t.crossings-r+l,"score");t.cost>c.cost?t=c:[q[e],q[e+1]]=[o,n]}}const J=qn(a);q=qn(q);let tt=H(q);const et=H(J);if(Q){const t=N(J),e=N(q);(tt.crossings>et.crossings||tt.crossings===et.crossings&&e>t+1e-9||tt.cost>et.cost)&&(q=J,tt=et)}else tt.cost>et.cost&&(q=J,tt=et);const ot=function({order:t,after:e,nodes:o,edges:n,outgoingPartners:i,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:l}){const c=(o,i)=>{const r=[...new Set(i.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),c=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-c+1!==r.length||1>=Math.abs(2*s-c-u))return;const d=[...t];d.splice(s,1),d.splice(c+u>>1,0,o);const h=qn(d),p=l(h),f=new Set(o.occupants.map(t=>t.id)),g=new Set(i.flatMap(t=>t.occupants.map(t=>t.id))),y=n.reduce((t,e)=>f.has(e.source)&&g.has(e.target)||f.has(e.target)&&g.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})(p,e,Math.abs(2*s-c-u)*a*Math.max(1,y))&&(t=h,e=p)};for(const[t,e]of i)r.has(t)||3>e.size||c(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)||c(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:q,after:tt,nodes:t,edges:e,outgoingPartners:R,incomingPartners:C,slotForNode:c,averageGap:m,evaluate:H});return q=ot.order,tt=ot.after,Vn(i,r,q),{before:et,after:tt,initialOrder:a.map(t=>l.get(t)),evaluations:w}}function si(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=Mn();return n.forEach((t,e)=>{for(const o of t.occupants)i[o.id]=e}),{slots:n,slotByNode:i}}var ai=new Map,li=1e5,ci=1e-9;function ui(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function di(t,e){return _n(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function hi(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 pi(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 fi(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 gi(t,e,o){return!!o.has(t)&&e.some(e=>!fi(t,e,o))}function yi(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 mi(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=hi(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=yi(t,s);r[e].set(o,(r[e].get(o)??0)+n),r[o].set(e,(r[o].get(e)??0)+n)}const a=pi(o),l=t.map(t=>a.get(t)?.weight??0),c=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(l[o],l[n])||Math.max(l[o],l[n]),r=fi(t[o],t[n],a)?i:-i;if(Math.abs(r)>ci&&(c[o].set(n,r),c[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 p=(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[l,c]of t[a]){const t=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?i:n)===(l===e?i:l===o?n:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}return r},f=(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},g=(t,e)=>t>ci||ci>=Math.abs(t)&&e>ci,y=(t,e,o,n)=>t>o+ci||ci>=Math.abs(t-o)&&e>n+ci;let m=0;for(let o=0;32>o&&li>m;o++){let o=null,n=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;t.length>u;u++){for(let p=0;h.length>p&&m++<li;p++){if(p===d[u])continue;if(!h[p].every(o=>!e.conflicts(t[u],t[o])))continue;const m=f(r,u,p),x=f(c,u,p);g(m,x)&&y(m,x,a,l)&&(o="move",n=u,i=-1,s=p,a=m,l=x)}if(m>=li)break}for(let u=0;t.length-1>u;u++){for(let f=u+1;t.length>f&&m++<li;f++){const m=d[u],x=d[f];if(m===x)continue;if(!h[x].every(o=>o===f||!e.conflicts(t[u],t[o])))continue;if(!h[m].every(o=>o===u||!e.conflicts(t[f],t[o])))continue;const b=p(r,u,f),v=p(c,u,f);g(b,v)&&y(b,v,a,l)&&(o="swap",n=u,i=f,s=-1,a=b,l=v)}if(m>=li)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 xi(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 bi(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=ai.get(i);if(r)return si(r.slots,o,n);const s=Mn();for(const e of t)s[e.id]=xi(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||_n(t.id,o.id)).map(t=>t.id)}(t,s),l=new Map(t.map(t=>[t.id,t])),c=new Map(t.map(t=>[t.id,t.group||void 0])),u=pi(e),d=function(t,e,o,n,i,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of n)s.add(di(t.source,t.target)),a.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=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=di(t[o],t[n]);e instanceof Map?e.set(i,[t[o],t[n]]):e.add(i)}};for(const t of l.values())d([...t],c);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[n,i]]of c)u.has(t)&&(ui(e[n],e[i])||ui(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(di(t,o))||r.has(t)&&r.has(o)&&fi(t,o,r))||!!ui(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(di(t,o))}}}(a,s,n,e,c,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))&&!gi(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),p=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),l=hi(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=yi(t,l);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 c=pi(o),u=t.map(t=>c.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(c.has(t[e])&&c.has(t[o])){const n=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=fi(t[e],t[o],c)?n:-n}d[o][e]=d[e][o]}let h=[...n.assignment],p=(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),f=0;const g=Array(t.length).fill(-1),y=Array.from({length:n.slotCount},()=>[]),m=(o,i,s,a)=>{if(f>=75e3)return;if(o===t.length)return f++,void((s>p.flow||s===p.flow&&a>p.affinity||s===p.flow&&a===p.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}(g,h))&&(h=[...g],p={flow:s,affinity:a}));const l=Math.min(i+1,n.slotCount-1);for(let n=0;l>=n;n++){if(y[n].some(n=>e.conflicts(t[o],t[n])))continue;let l=0,c=0;for(const t of y[n])l+=r[o][t],c+=d[o][t];if(g[o]=n,y[n].push(o),m(o+1,Math.max(i,n),s+l,a+c),y[n].pop(),g[o]=-1,f>=75e3)return}};return g[0]=0,y[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:mi(a,d,e,h)}),f=new Map,g=p.map(t=>(f.has(t)||f.set(t,f.size),f.get(t))),y=Array.from({length:f.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=Mn();a.forEach((t,e)=>{const o=g[e],n=y[o];n.occupants.push({id:t,end:s[t].end??-1/0});const i=l.get(t)?.group;i&&(n.group=i),m[t]=o});for(const e of[...t].sort((t,e)=>_n(t.id,e.id)))null==m[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||_n(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:y,slotByNode:m};return function(t,e){for(ai.has(t)&&ai.delete(t),ai.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(Mn(),e.slotByNode)});ai.size>12;){const t=ai.keys().next().value;if(null==t)break;ai.delete(t)}}(i,x),x}function vi(t){return t.topMass+t.botMass}function wi(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>vi(e)<vi(t)?t:e,o[0]);let n=null;for(const o of t.samples){if(o.t>e)break;n=o}return n}function ki(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 l=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,c]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],p=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(p))continue;const f=(h-u.peak.topPeak*r+(p+d.peak.botPeak*r))/2,g=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),y=new Map;for(const t of c)y.set(t.id,new Map);for(const t of g){const o=new Map;for(const i of c){const r=wi(e[i.id],t);if(!r||1e-9>=vi(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})=>vi(t)))}));if(0===a.length)continue;let l=f-(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=(l-i[o.id])/r+n.topMass-(n.boundaryOffset??0);y.get(o.id).set(t,e)}l+=e.mass*r+Math.max(0,s)}}for(const t of c){const o=e[t.id],n=l[t.id],i=y.get(t.id),r=[];for(const t of g){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=wi(o,t);null!=e&&s&&vi(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 l}function Ai(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:p="both",domain:f}=i,g=Mn(),y=Mn();for(const e of t)g[e.id]=o[e.id].topPeak||0,y[e.id]=o[e.id].botPeak||0;const m="half"===u,x=Mn();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=Mn(),v=[],w=[];if(i.frozenSlots){const t=si(i.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(Pn)}else if("reuse"===l){const n=bi(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:g[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});Zn(v,b),0===w.length&&(w=v.map(Pn));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(t,e,o){const n=new Map(o.map((t,e)=>[t,e]));Vn(t,e,[...t].sort((t,e)=>(n.get(Pn(t))??1/0)-(n.get(Pn(e))??1/0)||_n(Pn(t),Pn(e))))}(v,b,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(k=ri(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:p,domain:f}))),Zn(v,b);const A=Tn(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(Pn),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function Si(t){const{sx:e,sTop:o,sBot:n,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:l}=t,c=(o+n)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${l},${r} ${i},${r}`,`L${i},${s}`,`C${l},${s} ${a},${n} ${e},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:a,y:c},{x:l,y:u},{x:i,y:u}],halfWidth:(n-o)/2}}}function Mi(t,e,o,n,i,r,s,a,l={}){const c=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)),p=t.value*c,f=o.value*c,g=e+(t.boundaryOffset??0)*c,y=n+(o.boundaryOffset??0)*c,m=t.sideMassBefore*c,x=o.sideMassAfter*c;let b,v,w,k;"top"===t.side?(b=g-m,v=b+p):(v=g+m,b=v-p),"top"===o.side?(w=y-x,k=w+f):(k=y+x,w=k-f);const A=l.sourceRunwayStart,S=l.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 _i(t){return Math.max(18,11*t.length*.58)}function Pi(t){const e=1.22*_i(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 Li(t,e){const o=t.labelX-_i(t.labelText),n=e.labelX-_i(e.labelText);return e.labelX+3>=o&&t.labelX+3>=n}var $i=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function Ri(t){return t.replace($i,(t,e,o)=>`${o},${e}`)}function Ci(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 Ti(t){return{...t,pathD:Ri(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function Oi(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:l,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:p,maxLabels:f,selectionDatum:g="raw",styleRules:y,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=wn(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,l=Array.isArray(o)&&2===o.length,c=l&&Number.isFinite(o[0])&&Number.isFinite(o[1]);l&&c&&c&&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"===An(n)?e.push(n):o.push(n);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==wn(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),_=bn().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:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:p}=o,f=Number.isFinite(d)?Math.max(0,d):0,g=function(t,e){const o=Mn(),n=Mn();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),y=function(t,e,o,n="temporal"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime||_n(t.id,e.id):(t,e)=>e.value-t.value||_n(t.id,e.id),r="temporal"===n?(t,e)=>t.startTime-e.startTime||_n(t.id,e.id):(t,e)=>e.value-t.value||_n(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||_n(t.partner,o.partner):t.latestEnd-o.latestEnd||_n(t.partner,o.partner):(t,e)=>e.total-t.total||_n(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,g,i);let m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,void 0,u);const x=Ai(t,e,m,g,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),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=y.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=g.outgoing[e.id],o=g.incoming[e.id],n=new Set(t.map(t=>y.get(t.id).sourceSide)),i=new Set(o.map(t=>y.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]&&(y.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]&&(y.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)||_n(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 l=a.sourceSide??"bot";if(o[n.source]===o[n.target]){const t=i.top>=n.value,e=i.bot>=n.value;t!==e?l=t?"top":"bot":t||e||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,n.value)}}(e,y,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,l="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(e=>!n.has(e.id)&&o.get(e.id).sourceSide===t&&c>=e.value).sort((t,e)=>e.value-t.value||_n(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(t,g,y,v),m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,void 0,u);const w=Ai(t,e,m,g,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),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*f)/S),_=2*M+Ln(w.slots,M,f).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(n-_)/k):1,L=Number.isFinite(l)&&l>0?Math.min(P,l):P;let $=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P});const R=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||R)&&$.slots.length>1&&(ri(t,e,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:n,padding:M,valueScale:L,groupPadding:f,laneOrder:s,ribbonLane:h,domain:p,lanePlacement:c,mode:"geometry-refine"}),$=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Pn),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,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")}(g,y)){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],l=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=Yn(t,a,n),u=Yn(s,l,n);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(e,m,$.centerlines,L);m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,o,u);$=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Pn),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P})}const C=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),T=[...$.slots].sort((t,e)=>(C.get(Pn(t))??1/0)-(C.get(Pn(e))??1/0)||_n(Pn(t),Pn(e))),O=Mn();T.forEach((t,e)=>{for(const o of t.occupants)O[o.id]=e});const I=Tn(t,e,m,T,O,{plotH:n,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:f}),z=ki(t,m,T,O,I.centerlines,L,f),F=Wn(Jn(O,e),ti(O,e),e,z,T,O,I.centerlines,$.laneLifetime,L,I.verticalUtilization,h,p);m=ki(t,m,$.slots,$.slotByNode,$.centerlines,L,f);const N=Wn(Jn($.slotByNode,e),ti($.slotByNode,e),e,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,p);return{nodeData:m,sides:y,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:n}),{centerlines:L,nodeData:$,valueScale:R}=P,C=rt(m,x),T=[],O=[],I=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 l=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)),c=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(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&l.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=>l.has(t.id))){for(const t of o)l.delete(t.id);continue}const n=Math.max(...o.map(t=>l.get(t.id)));for(const t of o)l.set(t.id,n)}return l}(e,M,n),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,Mi(e,L[t.source],o,L[t.target],R,_,s,n,{minRun:a,sourceRunwayStart:I.get(t.id)}))}const N=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 l=n(r),c=Math.min(...t.map(t=>t.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?l:Math.min(l,n(e))})),d=Math.min(l,Math.max(c,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,F,I,_,s,z),E=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,N,I,_,t=>n[0]+t/v*(n[1]-n[0])),D=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,E,z);e.forEach((t,e)=>{const o=$[t.id];if(!o||0===o.samples.length)return;const i=(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,n,i){if(0===t.length)return null;const r=jn(t,i),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,l=t=>s(t)+r[t].botMass*o;let c=`M${n(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)c+=` L${n(r[t].t)},${a(t)}`;c+=` L${n(r[r.length-1].t)},${l(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${n(r[t].t)},${l(t)}`;return c+" Z"}(i,L[t.id],R,_,n);if(!a)return;const l=jn(i,n),u=l.find(t=>t.topMass+t.botMass>0)||l[0],h=L[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let p,f,g=c(t.id,e),m=g,x=.5;const b=t.__raw??t;if(y&&y.length>0){const t=dt(b,y,C(b));"string"==typeof t.fill?g=t.fill:null!=t.fill&&ot(t.fill)&&(f=t.fill,g=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:g),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(x=t.strokeWidth),"number"==typeof t.fillOpacity&&(p=t.fillOpacity),"number"==typeof t.opacity&&null==p&&(p=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,l=o.centerlines[t],c=jn(s.samples,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],d=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],h=n(u.t),p=n(d.t),f=t=>n(Bn(t,i)),g=[],y=(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=f(o.systemInTime),r=f(e),s=null!=i&&i[0]>o.systemInTime,c=s?n:n-20,u=s?Math.min(r,n+20):n,d=Math.max(h,c);if(r>d){const[e,o]=Yn(t,l,a);g.push({pathD:y(d,e,r,o),x0:c,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=f(o.systemOutTime),n=f(o.endTime),i=e+20,r=Math.min(p,i);if(r>n){const[o,s]=Yn(t,l,a);g.push({pathD:y(n,o,r,s),x0:e,x1:i,from:1,to:0})}}}}return g}(t.id,M,P,_,n,E);T.push({id:t.id,pathD:a,fill:g,stroke:m,strokeWidth:x,...null!=p&&{fillOpacity:p},...f&&{hatchFill:f},...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 W=new Map;e.forEach((t,e)=>W.set(t.id,e)),M.forEach(t=>{const e=N.get(t.id);if(!e)return;const o=W.get(t.source)??0,n=c(t.source,o),{pathD:i,bezier:r}=Si(e),s=t.__raw??t,a="function"==typeof l?Number(l(s)):l,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;O.push({id:t.id,pathD:i,fill:n,opacity:u,rawDatum:s,bezier:r})});const B=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-_i(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)Li(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)Li(o[t],o[e])&&(n=Math.min(n,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,n)}}}(n,o),n}(T,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ri(t.pathD),gradientStubs:t.gradientStubs?.map(Ti),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*_i(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]=Pi(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}(B,i,r):B,Y=new Map;if(null!=p)for(const t of e){const e=t.__raw??t,o="function"==typeof p?p(e):Number(e[p]);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+_i(t.labelText):_i(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!=f&&{maxLabels:f}});return{layout:P,layoutConfig:{bands:X,ribbons:O.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ri(t.pathD),bezier:Ci(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:S,xScale:_}}import{Fragment as Ii,jsx as zi,jsxs as Fi}from"react/jsx-runtime";var Ni="var(--semiotic-grid, #94a3b8)",Ei="var(--semiotic-text-secondary, #475569)",Di="var(--semiotic-text-secondary, #94a3b8)",Wi=.22;function Bi(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var ji=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=!Bi(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,Wi):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!Bi({__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?Wi: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=!Bi(o,r,i);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:n?Wi:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...n&&e?{opacity:Wi}:{}},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&&Bi({__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 Yi(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 Xi(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 Gi(t,e,o={}){return ae(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var Vi={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||se(fe(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};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:Xi([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=ye(n.theme).colors.categorical,l=Qt(o,a),c="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?ie(u,c,o??n.colorScheme??a):void 0,h=new Map,p=i.nodeIdAccessor||i.nodeIDAccessor||"id",f=(t,o)=>{const n=t?.data||t;let r;if(e)r=oe(n,e,d);else{const e=(t.id??n?.[p]??"")+"";h.has(e)||h.set(e,h.size);const i=t.index??o??h.get(e);r=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=pt(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:ae(i.nodeStyle||(g?(t,e)=>({...f(t,e),...g(t,e)}):f),fe(i)),...n}}},Hi={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=ye(n.theme).colors.categorical,a=new Map,l=i.nodeStyle??(t=>({fill:e?oe(t?.data||t,e,void 0):uo(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=pt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=ae(c?(t,e)=>({...l(t),...c(t,e)}):l,{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}}},qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrCirclePackColorBy:l(t)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"circlepack",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:i.showLabels??n.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrCirclePackColorBy:l(n)},"__ssrCirclePackColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,fe(i))}}},Ui={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",l=ye(n.theme).colors.categorical,c=o??n.colorScheme??l,u=Qt(c,l),d=Yi(r,s),h="__ssrOrbitColorBy",p="function"==typeof e?e:null,f=e?ie(p?d.map(t=>({[h]:p(t)})):d,p?h:e,c):void 0;return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:c,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:ae(t=>{const o=t.data||t,n=Number(t.depth??0);return{fill:i.colorByDepth?0===n?u[0]:te[n%te.length]:e?p?oe({[h]:p(o)},h,f):oe(o,e,f):u[0],stroke:"#fff",strokeWidth:1,opacity:0===n?1:.85}},fe(i)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...n}}},Ki={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",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,p=i.systemOutTimeAccessor,f=i.xExtentAccessor||"xExtent",g=i.groupBy,y=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:Xi([],x,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],k=v.map(t=>{const e=m(c,t)+"",o=m(f,t),n=i.nodeLabel?m(i.nodeLabel,t):e,s={id:e,label:null==n?e:n+"",__raw:t},a=g?m(g,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(y,t),n={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(l,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(p){const e=r(m(p,t));Number.isFinite(e)&&(n.systemOutTime=e)}return n}),[S,M]=n.size??[600,400],_=n.margin,P="vertical"===i.orientation?"vertical":"horizontal",L=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,P),$={...L,..._},R=(n.showLegend??!!e)&&!!e,C=n.legendPosition??"right";R&&("right"===C?$.right=Math.max($.right,140):"left"===C?$.left=Math.max($.left,140):"top"===C?$.top=Math.max($.top,50):"bottom"===C&&($.bottom=Math.max($.bottom,80)));const T=$,O=S-T.left-T.right,I=M-T.top-T.bottom,z=Qt(o,ye(n.theme).colors.categorical,B),F="function"==typeof e?e:null,N=F?v.map(t=>({_cat:F(t)})):v,E=F?"_cat":"string"==typeof e?e:void 0,D=o??[...z],W=E?ie(N,E,D):null,j=new Map;for(const t of k)j.set(t.id,t.__raw);const Y=(t,o)=>{if(e&&j.has(t)){const o=j.get(t);return F?oe({_cat:F(o)},"_cat",W??void 0):oe(o,"string"==typeof e?e:"id",W??void 0)}return z[o%z.length]},X=Ye(R&&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(c,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),G=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:V,layoutConfig:H,issues:q,xScale:U}=Oi({nodes:k,edges:A,domain:w,plotW:O,plotH:I,orientation:P,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:G,styleRules:i.styleRules,colorBy:e,valueAccessor:l,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(q.length>0){const t=q.map(Sn).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const K=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,l=t.showQualityReadout??!1,c=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,p=t.toTime,f=t.xScale,{centerlines:g,laneLifetime:y,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=y[t.id];if(!e||null===e.start||null===e.end)continue;const o=f(e.start),n=f(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:f(p(t.date))})).filter(({coordinate:t})=>t>=P-.5&&L+.5>=t),R=null!==(w??null)&&null!=k&&null!=A,C=l&&(R||u.length>0)?Fi("g",{fill:Di,fontSize:10,textAnchor:"end",children:[R&&Fi(Ii,{children:[Fi("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(A.pixelLength)]}),Fi("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)=>Fi("text",{x:i,y:R?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,T=b?zi("text",{x:i,y:"vertical"===n?-3:2,fontSize:10,fill:Di,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,O=(t,e)=>h?h(t,e):Ni;return Fi("g","vertical"===n?{children:[C,T,$.map(({index:t,coordinate:e})=>zi("line",{x1:0,y1:e,x2:i,y2:e,stroke:Ni,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[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=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=f(o.start),a=f(o.end),l=O(t.id,e);return Fi("g",{children:[zi("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),zi("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),zi("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),zi("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:Ni}),$.map(({tick:t,index:e,coordinate:o})=>{const n=p(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return Fi("g",{transform:`translate(-4,${o})`,children:[zi("line",{x2:-6,stroke:Ni}),zi("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Ei,children:i})]},e)})]}:{children:[C,T,$.map(({index:t,coordinate:e})=>zi("line",{x1:e,y1:0,x2:e,y2:r,stroke:Ni,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[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=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=f(o.start),a=f(o.end),l=O(t.id,e);return Fi("g",{children:[zi("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),zi("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),zi("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),zi("line",{x1:P,y1:r+4,x2:L,y2:r+4,stroke:Ni}),$.map(({tick:t,index:e,coordinate:o})=>{const n=p(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return Fi("g",{transform:`translate(${o},${r+4})`,children:[zi("line",{y2:6,stroke:Ni}),zi("text",{y:20,textAnchor:"middle",fontSize:11,fill:Ei,children:i})]},e)})]})}({layout:V,nodes:k,orientation:P,plotW:O,plotH:I,timelineExtent:"vertical"===P?I: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(U(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:ji,layoutConfig:H,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:e,colorScheme:o,...K&&{backgroundGraphics:K},...n,showLegend:R,...X&&{legend:X,legendPosition:C},__legendIncludesAutomatic:!0,margin:T}}},Zi={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:Xi([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=ye(n.theme).colors.categorical,a=new Map,l="string"==typeof e?e:"__ssrSankeyColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?ie(c,l,o??n.colorScheme??s):void 0,d=t=>({fill:e?oe(t?.data||t,e,u):uo(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=pt(i.styleRules,e,i.valueAccessor),p=h?(t,e)=>({...d(t),...h(t,e)}):d,f=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=oe(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=oe(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:p,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:ae(i.nodeStyle||p,fe(i)),edgeStyle:ae(i.edgeStyle||f,fe(i)),colorScheme:o,...n}}},Qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreeColorBy:l(t)})):a,u=l?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"cluster"===i.layout?"cluster":"tree",data:t,childrenAccessor:i.childrenAccessor,colorBy:e,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:!1!==i.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrTreeColorBy:l(n)},"__ssrTreeColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,fe(i))}}},Ji={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreemapColorBy:l(t)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,p=i.labelMode,f=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,g=void 0!==f?f:!h||"parent"!==p&&"all"!==p?void 0:18,y=n.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:p,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=g&&{paddingTop:g},colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrTreemapColorBy:l(n)},"__ssrTreemapColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},y,fe(i))}}},tr={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as er}from"d3-scale";function or(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var nr={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=er(h(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),l=i.styleRules?Q(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},or):a,c=!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:l,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n,...void 0===n.legend&&c?{legend:c}:{}}}},ir={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??function(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=ie(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=St(t))}return t=>({fill:e&&r?oe(t,e,r):Zt,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?re(t,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}(r,e,o,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?Q(s,i.styleRules,rt(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||tr,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},rr={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",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:t=>t[l],d="function"==typeof c?c:t=>t[c],h=(i.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),p=new Map;for(const t of h)p.set(t[s]+"",t);const f=i.edgeColorBy??e,g="function"==typeof f,y=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=p.get(t.source+""),o=p.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=f?g?ie(y.map(t=>({[m]:f(t)})),m,o||"category10"):ie(y,f,o||"category10"):null,b=t=>f&&x?oe(t,f,x):"#007bff";let v=1/0,w=-1/0;for(const t of y){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:y,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||tr,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*as sr from"react";function ar(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 lr(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 cr(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?st(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,l={fill:null==a?e:lr(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,dt(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}function ur(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 dr(t,e,o){return"function"==typeof o?o(t,e):t[o]}function hr(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 pr(t,e,o){return Math.max(e,Math.min(o,t))}function fr(t,e){const o=hr(t);return null!=o&&o>0?o:e}function gr(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function yr(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 mr}from"d3-scale";import{scaleLinear as xr}from"d3-scale";function br(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 l=Math.min(r-1,a?.(e)??s),c=Math.max(1,r-l);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:i(e),y:l+c/2,width:n,height:c}}})}function vr(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 wr}from"d3-scale";function kr(t){if(Array.isArray(t)&&t.length>=2){const e=hr(t[0]),o=hr(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=hr(e.x),n=hr(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Ar(t){return Array.isArray(t)?t.map(kr).filter(t=>null!=t):[]}function Sr(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:pr(t.x,e.plot.x,e.plot.x+e.plot.width),y:pr(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Mr(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 _r(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=pr(e,0,1)*Mr(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 Pr(t,e){const o=_r(t,Math.max(0,e-.02)),n=_r(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 Lr(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 $r}from"d3-scale";function Rr(t,e,o){return Qt(t,e,o)}function Cr(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&ne(o,t)||"#4e79a7":e=>{if(o){const t=ne(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 Tr(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 Or(t){const e=Dr(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 Ir(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function zr(t){return`gauntlet:${t}:core`}function Fr(t,e){return`gauntlet:${t}:positive:${e}`}function Nr(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var Er={left:28,top:76,rightInset:30,thickness:8};function Dr(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return Er;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 Wr(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Br(t,e,o,n){const i=Dr(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,l=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:l(t,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:l(e,s,a)}}function jr(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 Yr(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 Xr(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,l=(e??[]).filter(t=>!1!==t.enabled),c=Math.max(1,l.length),u=.22*n,d=c>1?(.78*n-u)/(c-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:l.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=Ir(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...Ir(t,e,o.positiveAccessor,s)],l=[...Ir(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ir(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ir(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:Ir(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??Yr(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=Wr(o),l=Math.max(3,28*a),c=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??c,p=d.y??u,f={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},g=[{...d,id:zr(t.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??t.startedAt,datum:f}],y=Br(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,o);g[0].x=y.x,g[0].y=y.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=jr(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),l=Br(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,o);g.push({id:Fr(t.id,e),x:l.x,y:l.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:zr(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&&g.push(function(t,e,o,n,i,r,s){const a=Wr(r),l=e.radius??Math.max(2,7.2*a),c=Br(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,l,r);return{id:Nr(t.id,e.id,o),x:c.x,y:c.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:zr(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,y.x,y.y,o,d.spawnAt??t.startedAt))}),g}(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:Or(e)}}}function Gr(t=[]){const e=Object.create(null);for(const[o,n]of t)e[o]=n;return e}function Vr(...t){const e=Gr();for(const o of t)for(const[t,n]of Object.entries(o??{}))e[t]=n;return e}function Hr(t){return Vr(t)}function qr(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 Ur(t){const e=Gr(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:Hr(e.initialMetrics),metrics:Hr(e.metrics),productIds:[...e.productIds],history:qr(e.history)}])),o=Gr(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:Hr(e.metrics),sourceIds:[...e.sourceIds],history:qr(e.history)}])),n=Gr(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?Hr(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:Hr(t.input.metrics)},metrics:Hr(t.metrics),loss:{amount:t.loss.amount,metrics:Hr(t.loss.metrics)},history:qr(t.history)}}var Kr=1e-9;function Zr(t,e){return e>t?-1:t>e?1:0}function Qr(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Jr(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(Zr)}function ts(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[Qr("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function es(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function os(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(Qr("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(Qr("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,l=e.categories?new Set(e.categories):null,c=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=>!l||l.has(t.category)).filter(t=>!c||c.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Zr);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(Qr("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function ns(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 is(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 rs(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(Qr("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function ss(t,e,o){const n=Jr(e);e.length||t.diagnostics.push(Qr("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(Qr("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(Qr("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(Qr("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(Qr("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 as(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+Kr)&&t.diagnostics.push(Qr("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...ts(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+Kr)&&t.diagnostics.push(Qr("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 ls(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?Vr(n,t.metrics):Hr(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 cs(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>Kr&&t.diagnostics.push(Qr("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function us(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(Qr("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...ts(e.metricsDelta,n+".metricsDelta")),rs(t,e.outletId,n+".outletId");const o=os(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(Qr("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=ns(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&&es(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&is(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(Qr("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=Jr(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(Qr("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(Qr("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(Qr("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(...ts(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?Hr(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=ns(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void is(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Jr(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(Qr("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(Qr("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(Qr("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=ns(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void is(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(Qr("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(Qr("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(Qr("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=ss(t,e.sourceIds,n+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,l=function(t,e,o,n){if(!e?.length)return[];const i=Jr(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),l=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(Qr("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(Qr("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(Qr("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),l.length&&t.diagnostics.push(Qr("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,n,l)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,n+".basisRelationIds");if(!s||!l||!o||t.diagnostics.some(t=>"error"===t.severity))return;const c=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e=Gr();for(const o of t)es(e,o.metrics);return e}(s);if(!as(t,c,u,e.loss,n+".loss"))return;const d=c-(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,p=ns(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let f;if("combine"===e.type){if(h&&cs(t,o,d,n+".productId"),f=ls(o,e.sourceIds,d,u,t,h,p),h&&!rs(t,f.outletId,n+".productId"))return;i.products[e.productId]=f}else f=r,f.sourceIds.push(...e.sourceIds),f.amount+=d,es(f.metrics,u),f.history.push(p);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(p);return i.history.push(p),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;is(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,l),is(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:f.outletId?[f.outletId]:void 0}),void(h&&is(t,{type:"complete-product",sourceIds:[...f.sourceIds],productIds:[f.id],outletIds:f.outletId?[f.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(!rs(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(Qr("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(cs(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=Vr(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=n,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const l=ns(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(l),t.state.history.push(l),is(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(Qr("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=ss(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(Qr("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=Jr(r);s.length&&t.diagnostics.push(Qr("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),l=r.filter((t,e)=>!a[e]),c=r.filter(t=>i.products[t]);l.length&&t.diagnostics.push(Qr("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,n+".products",l)),c.length&&t.diagnostics.push(Qr("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,n+".products",c));for(const[o,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(Qr("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...ts(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!as(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),p=h.filter(t=>void 0!==t).length;if(0!==p&&p!==h.length)return void t.diagnostics.push(Qr("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const f=p?h:e.products.map(()=>d/e.products.length),g=f.reduce((t,e)=>t+e,0);if(Math.abs(g-d)>Kr)return void t.diagnostics.push(Qr("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,n+".products"));const y=Hr(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))y[t]=Number(y[t]??0)-o;const m=ns(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],l=d>Kr?f[r]/d:1/e.products.length,c=Gr(Object.entries(y).map(([t,e])=>[t,e*l])),h=o.metrics??s.metrics??c,p=ls({...s,amount:f[r],metrics:h},[u.id],f[r],Hr(h),t,!0,m);rs(t,p.outletId,`${n}.products.${r}.productId`)&&(i.products[p.id]=p)}),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),is(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)is(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){rs(t,e.outletId,n+".outletId");const o=os(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(Qr("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=ns(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&&is(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...ts(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)es(i.metrics,e.metricsDelta);else if("components"in e.target){const r=os(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)es(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Jr(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(Qr("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(Qr("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)es(i.products[t].metrics,e.metricsDelta)}return void i.history.push(ns(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(ns(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(Qr("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function ds(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[Qr("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=Ur(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(us(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 hs=[900,520],ps=[{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}],fs=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),gs=1e-9;function ys(t,e){return e>t?-1:t>e?1:0}function ms(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function xs(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(ys)}function bs(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function vs(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(ms("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function ws(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(ms("error","invalid-metrics","Metrics must be a numeric object.",o)),Gr();const n=Gr();for(const[i,r]of Object.entries(t)){const t=bs(r);null!=t?n[i]=t:e.push(ms("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function ks(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 As(t){const{id:e,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=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+gs).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+gs&&i.push([r,t]),r=Math.max(r,e);return e>r+gs&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:l,restitution:c,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 Ss(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 Ms(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?Ss(t):1}function _s(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:Ms(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Ps(t){return"crucible:component:"+encodeURIComponent(t)}function Ls(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>gs?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function $s(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 Rs(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 Cs(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 Ts(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 Os(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>ys(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>ys(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=$s(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)||ys(t.id,e.id));const o=Rs(i.length,Ts(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>n.set(t.id,o[e]))}return n}(n,e),l=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*Ls(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(c=t.id,"crucible:product:"+encodeURIComponent(c)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=Cs(t)??"__chamber__",o=c.get(e)??[];o.push(t),c.set(e,o)}const u=new Map;for(const[t,o]of c){const n=Rs(o.length,Ts(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=Ss(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=Ls(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ps(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var Is=Os;function zs(t){return Array.isArray(t)?t.map(zs):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>ys(t,e)).map(([t,e])=>[t,zs(e)])):t}function Fs(t,e=t.duration){const o=function(t,e){const o=bs(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-gs,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=Ur(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+gs)break;const a=ds(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 Ns(t){const e=function(t){const e=[];t.length||e.push(ms("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=xs(t.map(t=>t.id));o.length&&e.push(ms("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=bs(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(ms("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(ms("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(ms("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=ks(t.outlets??ps),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?Vr(t.metrics):void 0})),r=function(t,e,o){const n=[],i=xs(t.map(t=>t.id));i.length&&n.push(ms("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,l;if(t.id.trim()||n.push(ms("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=bs(t.at.time);if(null==r||0>r||r>o+gs)return void n.push(ms("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 c=function(t,e,o){const n=t.find(t=>gs>=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}:gs>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=c.phase,l=c.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void n.push(ms("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(ms("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,l=0===o?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):n.push(ms("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=Gr(),n=[];let i=0;const r=Gr();t.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((vs(s,a,t.idAccessor,l,e,`data.${a}.id`)??l)+"").trim();if(!c)return void e.push(ms("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(c);const u=bs(vs(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(ms("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=ws(vs(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),p=vs(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),f=fs.has(p)?p:"active";fs.has(p)||e.push(ms("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[c]));const g=vs(s,a,t.labelAccessor,(s.label??s.name??c)+"",e,`data.${a}.label`)+"",y=vs(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,c)||(o[c]={id:c,label:g,category:y,datum:s,status:f,initialAmount:d,amount:d,initialMetrics:Vr(h),metrics:Vr(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=xs(n);s.length&&e.push(ms("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=ws(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:Gr(),relations:Gr(),input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:Gr()},history:[]},diagnostics:e}}(t),a=function(t=hs,e=ps){const o=Math.max(1,bs(t[0])??900),n=Math.max(1,bs(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},l=i?Math.max(16,.14*n):Math.min(78,.16*n),c={x:r,y:n-r-l,width:Math.max(1,o-2*r),height:l},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),p={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},f=Math.max(18,Math.min(.32*p.width,i?84:180)),g={x:p.x+(p.width-f)/2,y:p.y-(i?10:24),width:f,height:i?12:28},y=ks(e),m={left:y.filter(t=>"left"===(t.side??"bottom")),right:y.filter(t=>"right"===t.side),bottom:y.filter(t=>"bottom"===(t.side??"bottom"))},x=[],b=(t,e)=>{const n=Math.max(8,u-1.5*r),s=p.height/Math.max(1,e.length);e.forEach((e,a)=>{x.push({...e,side:t,x:"left"===t?r:o-r-n,y:p.y+a*s,width:n,height:Math.max(8,s-(i?2:8))})})};b("left",m.left),b("right",m.right);const v=p.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{x.push({...t,side:"bottom",x:p.x+e*v,y:p.y+p.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-p.y-p.height-(i?4:12))})}),x.sort((t,e)=>y.findIndex(e=>e.id===t.id)-y.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:p,mouth:g,projection:c,outlets:x}}(t.size??hs,n),l=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(...As({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}),...As({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}),...As({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),c=function(t,e){const o=[],n=new Set(e.map(t=>t.id)),i=xs(e.map(t=>t.id)),r=xs(t.map(t=>t.id));return i.length&&o.push(ms("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(ms("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(ms("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(ms("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(ms("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(ms("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(ms("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),ws(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>ys(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(zs(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>ys(t.id,e.id)),i=n.map(t=>t.amount),r=$s(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}}(Ms(o.seed)),a=e.mouth.x+e.mouth.width/2,l=e.chamber.y+Math.max(18,.18*e.chamber.height),c=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=Ls(t.amount,i,o.bodyRadius,r),p={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ps(t.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+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:p}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...c],f={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:_s(t.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:p},g=Fs(f),y=Object.values(g.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=y.length?[ms("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];return f.terminalState=g.state,f.terminalSpawns=Is(g.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f.diagnostics=[...p,...g.diagnostics,...m],f}import*as Es from"react";import{curveMonotoneX as Ds,curveMonotoneY as Ws,curveCardinal as Bs,curveCatmullRom as js,curveStep as Ys,curveStepBefore as Xs,curveStepAfter as Gs,curveBasis as Vs,curveNatural as Hs}from"d3-shape";function qs(t){switch(t){case"monotoneX":return Ds;case"monotoneY":return Ws;case"cardinal":return Bs;case"catmullRom":return js;case"step":return Ys;case"stepBefore":return Xs;case"stepAfter":return Gs;case"basis":return Vs;case"natural":return Hs;default:return null}}import{jsx as Us,jsxs as Ks}from"react/jsx-runtime";function Zs(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 Qs(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",l="number"==typeof e.strokeWidth?e.strokeWidth:1.25,c="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 Ks(Es.Fragment,{children:[Us("defs",{children:Us("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Us("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Us("polygon",{points:e,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${o})`}),Us("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return Ks(Es.Fragment,{children:[Us("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),Us("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 Js,jsx as ta,jsxs as ea}from"react/jsx-runtime";var oa="var(--semiotic-text, #26323a)",na="var(--semiotic-text-secondary, #6c7377)",ia="var(--semiotic-primary, #b8792d)",ra="var(--semiotic-danger, #9f3d35)",sa="var(--semiotic-success, #356b63)";function aa(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 la({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 ea("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[ea("defs",{children:[ea("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[ta("stop",{offset:"0",stopColor:ia,stopOpacity:"0.03"}),ta("stop",{offset:"0.66",stopColor:ia,stopOpacity:"0.1"}),ta("stop",{offset:"1",stopColor:ra,stopOpacity:"0.18"})]}),ta("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:ta("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:oa,strokeOpacity:"0.08",strokeWidth:"1"})})]}),ta("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:oa,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),ta("path",{d:aa(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),ta("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:oa,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:ta("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,l=Math.max(0,n.duration)/i*t.phaseRail.width,c=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return ea("g",{children:[ta("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,l-2),height:t.phaseRail.height,rx:2,fill:c?n.color??ia:u?sa:oa,fillOpacity:c?.68:u?.28:.09}),46>l?null:ta("text",{x:a+l/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:c?oa:na,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),t.outlets.map(t=>ea("g",{children:[ta("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?ra:sa),fillOpacity:"0.1",stroke:t.color??("left"===t.side?ra:sa),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:ta("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:na,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function ca({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),l=e.projection.height>48?21:4,c=Math.max(5,e.projection.height-l-5);return ta("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*c),h=e.projection.x+o*a+.18*a;return ea("g",{children:[ta("rect",{x:h,y:e.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?ra:"complete"===t.status?ia:sa,fillOpacity:"0.68"}),l>4&&a>=34?ea(Js,{children:[ta("text",{x:h+.32*a,y:e.projection.y+c+10,fill:na,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),ea("text",{x:h+.32*a,y:e.projection.y+c+19,fill:oa,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Zs(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}function ua(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 da,jsx as ha,jsxs as pa}from"react/jsx-runtime";function fa(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=ar(s),l=Math.max(2,Math.round(e)),c=a.plot.width/l,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[p,f]=n?.valueExtent??[0,l],g=f===p?1:f-p,y=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*c).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return pa("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?pa(da,{children:[Array.from({length:l+1},(t,e)=>{const o=a.plot.x+e*c;return ha("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)}),ha("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ha("path",{d:y,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?ha("text",{x:a.plot.x+(e+.5)*c,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-p)/g))*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 pa("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[ha("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:ha("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 ga(t,e,o){if(!1!==o&&e)return({size:o})=>{const n=[Number(o[0])||760,Number(o[1])||360],i=ar(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},l=e.windowPlot??s,c=l.width/r,u=s.y+s.height,d=s.y+.48*s.height,h=e.lidSegments[0]?.y1??d,p=e.windowStart,f=e.windowStart+r*e.windowSize,g=l.x+Math.max(0,Math.min(1,f===p?0:(e.watermarkValue-p)/(f-p)))*l.width;return pa("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:[ha("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?pa("g",{children:[ha("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}),ha("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=l.x+i*c,a=e.closedWindowCount>i,h=r?.secondary??0;return pa("g",{children:[ha("rect",{x:s,y:d,width:c,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=>ha("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,pa("text",{x:s+c/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),ha("text",{x:s+c/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=>ha("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)),ha("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ha("line",{"data-testid":"event-drop-watermark",x1:g,x2:g,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),pa("text",{x:Math.min(s.x+s.width-4,g+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?pa("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 ya(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const n=[Number(o[0])||700,Number(o[1])||380],i=ar(n),r=vr(i.plot,t.length,e),s=i.plot.y+i.plot.height;return pa("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:[ha("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,l=r.centerX(e),c=s-o;return pa("g",{children:[ha("rect",{x:l-a/2,y:c,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"}),ha("text",{x:l,y:Math.max(i.plot.y+12,c-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),ha("text",{x:l,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 ma(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function xa(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],n=ar(o),i=n.plot.y+n.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,l=[{label:ma(r),x:t.xRange[0]},{label:ma(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:ma(s),x:t.xRange[1]}];return pa("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=>pa("g",{children:[ha("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}),ha("text",{x:n.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),pa("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)),ha("line",{x1:t.xRange[0],x2:t.xRange[1],y1:i,y2:i,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(t=>pa("g",{children:[ha("line",{x1:t.x,x2:t.x,y1:i,y2:i+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),ha("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{jsx as ba}from"react/jsx-runtime";function va(t,e,o={},n){if(!1===e||!t)return;const{volume:i,stages:r,groups:s,groupCompletion:a}=t,l=new Map(i.stages.map(t=>[t.id,t])),c=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=l.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=c.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 O({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 wa(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=ar(i),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),l=r.plot.y+6;return ba("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 c=Math.max(2,i.value/s*a),u=Math.max(8,.35*r.width);return ba("rect",{x:r.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function ka(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}import{jsx as Aa,jsxs as Sa}from"react/jsx-runtime";function Ma(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 Sa("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 Sa("g",{children:[Aa("path",{d:ka(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),Aa("path",{d:ka(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?Aa("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=>Sa("g",{children:[n&&a.has(t.sensorId)?Aa("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?Aa("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?Aa("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 _a,jsx as Pa,jsxs as La}from"react/jsx-runtime";function $a({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 Pa(_a,{children:t.gates.map(r=>La("g",{children:[Pa("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?Pa("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 Ra({layout:t,states:e,compact:o=!1}){return o?Pa("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:Pa($a,{layout:t,compact:!0,showLabels:!1})}):La("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Pa("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}),Pa("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}),Pa("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),Pa($a,{layout:t,compact:!1,showLabels:!0}),La("g",{children:[Pa("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}),Pa("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),La("g",{children:[Pa("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}),Pa("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),Pa("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 Ca({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 La("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:[Pa("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 La("g",{children:[Pa("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}),Pa("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 Ta={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 Oa(t){return t.map(t=>({...t,spawnAt:void 0}))}function Ia(t,e){return t?e?o=>sr.createElement(sr.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function za(t,e,o){const n=e[o];return"boolean"==typeof n?n:!0!==t.__compactMode}var Fa=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Na(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return Fa[(e>>>0)%Fa.length]}var Ea={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:Ao,LineChart:_o,AreaChart:Lo,DifferenceChart:$o,StackedAreaChart:Ro,Scatterplot:Ie,CandlestickChart:Co,BubbleChart:ze,ConnectedScatterplot:Oo,QuadrantChart:To,Heatmap:Io,TemporalHistogram:Po,XYCustomChart:{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})},BarChart:nn,StackedBarChart:rn,GroupedBarChart:sn,PieChart:an,DonutChart:ln,Histogram:cn,BoxPlot:un,ViolinPlot:dn,SwarmPlot:hn,DotPlot:pn,SwimlaneChart:fn,RidgelinePlot:gn,LikertChart:yn,FunnelChart:mn,GaugeChart:xn,OrdinalCustomChart:{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})},ForceDirectedGraph:Hi,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:Ki,ChordDiagram:Vi,TreeDiagram:Qi,Treemap:Ji,CirclePack:qi,OrbitDiagram:Ui,ChoroplethMap:nr,ProportionalSymbolMap:ir,FlowMap:rr,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:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,c=i.seed??1,u=Math.max(1,Math.round(i.pegRows??s-1)),d="mechanical"===i.mode,h=d?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=pr(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=yr(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:u,seed:c}):Array.isArray(t)?t:[],p=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:c}=t,u=ar(s),d=e.map((t,e)=>hr(dr(t,e,o))).filter(t=>null!=t),h=function(t){if(!t)return;const e=hr(t[0]),o=hr(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(c),p=h?.[0]??(d.length?Math.min(...d):0),f=h?.[1]??(d.length?Math.max(...d):1),g=f===p?1:f-p,y=mr().domain([0,n]).range([u.plot.x,u.plot.x+u.plot.width]),m=Array.from({length:n},()=>0),x=[];e.forEach((t,e)=>{const r=hr(dr(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-p)/g*n)));m[s]+=1,x.push({id:(t.id??"galton-"+e)+"",x:y(s+.5),y:u.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 b=u.plot.y+u.plot.height;return{config:ur(r,[...a({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...l({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:y,yTop:u.plot.y-400,yBottom:b,wallThickness:6})],"GaltonBoardChart"),initialSpawns:x,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot:u.plot,valueExtent:[p,f]}}}({data:h,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:c,size:r,valueExtent:d?[0,u]:void 0});return{...n,config:p.config,initialSpawns:Oa(p.initialSpawns),projectionRows:p.projectionRows,foregroundGraphics:Ia(fa(p.projectionRows,s,za(n,i,"showProjection"),p.metadata,i.referenceLines),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||(d?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",layout:Ta,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:l,size:c,timeExtent:u,timeScale:d=1}=t,h=ar(c),p=e.map((t,e)=>hr(dr(t,e,o))).filter(t=>null!=t),f=hr(u?.[0]),g=hr(u?.[1]),y=p.length?Math.min(...p):0,m=p.length?Math.max(...p):y+i.size,x=Math.min(f??y,y),b=Math.max(g??m,m),v=Math.floor(x/i.size)*i.size,w=Math.max(1,Math.ceil((b-v+i.size)/i.size)),k=p.length?Math.max(...p):0,A="function"==typeof r?r(k):hr(r?.value)??k-(r?.delay??i.size),S=Math.max(0,Math.min(w,Array.from({length:w},(t,e)=>e).reduce((t,e)=>v+(e+1)*i.size>A?t:t+1,0))),M=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}}(h,s),_=v+w*i.size,P=xr().domain([v,_]).range([M.windowPlot.x,M.windowPlot.x+M.windowPlot.width]),L=Array.from({length:w},()=>({value:0,secondary:0})),$=[];e.forEach((t,e)=>{const r=hr(dr(t,e,o));if(null==r)return;const a=hr(dr(t,e,n))??r,l=Math.max(0,Math.min(w-1,Math.floor((r-v)/i.size))),c=A>=v+(l+1)*i.size;L[l].value+=c?0:1,L[l].secondary+=c?1:0,$.push({id:(t.id??"event-"+e)+"",x:Math.max(M.windowPlot.x+s,Math.min(M.windowPlot.x+M.windowPlot.width-s,P(r))),y:h.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:l,late:c}})});const R=h.plot.y+h.plot.height,C=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=xr().domain([n,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,l=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),c=t=>s===a?e:l+(t-a)/(s-a)*(e-l),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:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:S,gutter:M.gutter,plot:h.plot,windowCount:w,windowPlot:M.windowPlot,windowSize:i.size,windowStart:v},h.plot.y+.28*h.plot.height);return{config:ur(l,[...a({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...br({idPrefix:"eventdrop-window",count:w,xScale:t=>P(v+t*i.size),yTop:M.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?C[0]?.y1:C[t-1]?.y2??C[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?M.wallTop:e+1.25*s},yBottom:R,wallThickness:6}),...C.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:$,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:d},projectionRows:L.map((t,e)=>({label:`${v+e*i.size}-${v+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:M.gutter,lidSegments:C,lateCount:L.reduce((t,e)=>t+e.secondary,0),plot:h.plot,windowPlot:M.windowPlot,watermarkValue:A,windowCount:w,windowSize:i.size,windowStart:v}}}({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:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(ga(s.projectionRows,s.metadata,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,l=function(t){const{data:e,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:l}=t,c=fr(i,1),u=ar(l),d=[],h=new Map,p=new Map,f=[];function g(t){let e=h.get(t);return null==e&&(e=d.length,d.push(t),h.set(t,e)),e}e.forEach((t,e)=>{g((dr(t,e,o)??"unknown")+"")});const y=Math.max(1,d.length),m=vr(u.plot,y,r),x=Math.max(0,m.tubeWidth/2-r-1),b=d.map(()=>[]);e.forEach((t,e)=>{const i=(dr(t,e,o)??"unknown")+"",s=g(i),a=n?hr(dr(t,e,n)):1,l=Math.max(0,Math.round((a??0)/c)),d=m.centerX(s);for(let o=0;l>o;o+=1){const n=p.get(i)??0,a=m.perRow>1?((m.perRow>1?n%m.perRow:0)/(m.perRow-1)*2-1)*x:0;p.set(i,n+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:u.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 v=b.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;v>t;t+=1)for(const e of b)e.length>t&&f.push(e[t]);const w=u.plot.y+u.plot.height,k=[...a({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],A=u.plot.y-400;for(let t=0;y>t;t+=1){const e=m.centerX(t);for(const o of[-1,1])k.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*m.tubeWidth/2,y:(A+w)/2,width:6,height:w-A}})}return{config:ur(s,k,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(t=>({label:t,value:p.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=fr(t.unitValue,1),r=yr(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),l=a.reduce((t,e)=>t+e,0)||1,c=n-o.length,u=a.map(t=>t/l*c),d=u.map(t=>1+Math.floor(t));let h=n-d.reduce((t,e)=>t+e,0);const p=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)%p.length)d[p[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:l.config,initialSpawns:Oa(l.initialSpawns),projectionRows:l.projectionRows,foregroundGraphics:Ia(ya(l.projectionRows,i.ballRadius??5,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",layout:Ta,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:l,xExtent:c,collisionIterations:u,settle:d}=t,h=ar(l),p=yr(s),f=[],g=[],y=new Map;e.forEach((t,e)=>{const s=hr(dr(t,e,o));if(null==s)return;const a=n?(dr(t,e,n)??"All")+"":"All",l=i?hr(dr(t,e,i)):null,c=pr(null!=l&&l>0?l:r,2,18);!function(t){let e=y.get(t);null==e&&(e=g.length,g.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:c})});const m=f.map(t=>t.value),x=c?hr(c[0]):null,b=c?hr(c[1]):null,v=m.length?Math.min(...m):0,w=m.length?Math.max(...m):1;let k=x??v,A=b??w;if(k===A&&(k-=.5,A+=.5),k>A){const t=A;A=k,k=t}const S=Math.max(r,...f.map(t=>t.radius)),M=h.plot.x+S+8,_=h.plot.x+h.plot.width-S-8,P=wr().domain([k,A]).range([M,_]),L=Math.max(1,g.length),$=Math.min(Math.max(28,3*S),h.plot.height/4),R=h.plot.y+$,C=Math.max(0,h.plot.y+h.plot.height-$-R),T=t=>{const e=y.get(t)??0;return 1===L?h.plot.y+.54*h.plot.height:R+e/(L-1)*C},O=new Map,I=f.map((t,e)=>{O.set(t.group,(O.get(t.group)??0)+1);const o=P(t.value),n=T(t.group),i=(p()-.5)*t.radius*1.6,r=(p()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:d?o+i:pr(o+(e%9-4)*t.radius*2.5,M,_),y:d?n+r:h.plot.y-18-e%12*t.radius,vx:d?0:22*(p()-.5),vy:d?0:24+18*p(),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:ur(s,a({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.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(u??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:I,projectionRows:g.map(t=>({label:t,value:O.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[k,A],xRange:[M,_],groups:g.map(t=>({label:t,y:T(t),count:O.get(t)??0})),plot:h.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:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(xa(s.metadata,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,i,a)=>{const l=i.size??[900,420],c=Array.isArray(a.stages)?a.stages:[],d=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,i=ar(o),a=pr(t.ballRadius??6,2,18),l=t.seed??1,c=yr(l),d=t.idAccessor,h=t.stageAccessor??"stage",p=t.groupBy,f=t.groupLabelAccessor,g=t.workAccessor,m=t.radiusAccessor,x=t.groupCompletion??(p?"allAbsorbed":"none"),b=t.springStiffness??.28,v=t.springDamping??.72,w=!0===t.settle,k=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),A=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:k,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),S=new Map(A.stages.map((t,e)=>[t.id,e])),M=new Map(A.stages.map(t=>[t.id,t])),_=A.stages[0].id,P=A.stages[0],L=new Set(e.filter(t=>t.absorb).map(t=>t.id)),$=e.map(t=>{const e=M.get(t.id)??P;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 n({...o,kind:t.kind??"sink",force:Lr(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 C({...o,kind:t.kind??"force-field",force:Lr(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}})}if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return s({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:Lr(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 T({...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:Lr(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?W({...o,kind:t.kind??"force-field",force:Lr(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):u({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:A.midY,width:e.width,height:A.bottomY-A.topY})});$.unshift(W({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(A.left+A.right)/2,y:A.midY,width:A.right-A.left,height:A.bottomY-A.topY-12,force:8,damping:.012,semanticItem:!1}));const R=new Map;for(const t of A.stages)R.set(t.id,0);const O=[];t.data.forEach((t,e)=>{const o=(d?dr(t,e,d)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(dr(t,e,h)??_)+"",i=S.has(n)?n:_;R.set(i,(R.get(i)??0)+1);const r=p?(dr(t,e,p)??"")+"":void 0,s=r&&f?(dr(t,e,f)??r)+"":r,l=g?hr(dr(t,e,g))??1:1,c=m?hr(dr(t,e,m)):null,u=pr(null!=c&&c>0?c:a,2,18);O.push({datum:t,id:o,stageId:i,groupId:r||void 0,groupLabel:s||void 0,work:l,radius:u,index:e})});const z=new Map,F=new Map;for(const t of O){if(!t.groupId)continue;const e=z.get(t.groupId)??[];e.push(t.id),z.set(t.groupId,e),t.groupLabel&&F.set(t.groupId,t.groupLabel)}const N=pr(t.groupAnchorAlong??.55,.15,.9),E=A.left+(A.right-A.left)*N,D=Array.from(z.keys()),B=D.map((t,o)=>{const n=z.get(t)??[],i=D.length>1?A.topY+28+o/Math.max(1,D.length-1)*(A.bottomY-A.topY-56):A.midY;return r({id:t,label:F.get(t)??t,bodyIds:n,anchor:{x:E,y:i},x:E,y:i,completion:"allAbsorbed"===x?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),j=O.filter(t=>L.has(t.stageId)).map(t=>t.id),Y=y(B,j),X=new Map(B.map(t=>[t.id,t])),G=O.map((t,e)=>{const o=M.get(t.stageId)??P,n=o.x+(c()-.5)*Math.min(24,.2*o.width),i=A.boundaryY(n,"top")+t.radius+10,r=A.boundaryY(n,"bottom")-t.radius-10,s=r>i?i+c()*Math.max(1,r-i):A.midY,a=w?n:A.left+18+e%7*4,l=w?s:A.midY+(c()-.5)*(A.bottomY-A.topY)*.35,u=[{target:{type:"point",x:n,y:s},restLength:.45*t.radius,stiffness:b,damping:v}];if(t.groupId){const e=X.get(t.groupId);e?.anchor&&!L.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:a,y:l,vx:w?0:40+40*c(),vy:w?0:20*(c()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:w?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}}}),V={kernel:{seed:l,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:A.colliders,fixedDt:1/60,maxSubsteps:8},H=A.stages.map(t=>({label:t.label??t.id,value:R.get(t.id)??0})),q=e.map(t=>{const e=M.get(t.id)??P;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:R.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:V,initialSpawns:G,initialSpawnPacing:w?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:H,metadata:{kind:"process-flow",plot:i.plot,volume:A,stages:q,groups:B,groupCompletion:Y,regionEffects:$}}}({data:Array.isArray(t)?t:[],stages:c,size:l,idAccessor:a.idAccessor,stageAccessor:a.stageAccessor||"stage",groupBy:a.groupBy,groupLabelAccessor:a.groupLabelAccessor,workAccessor:a.workAccessor,radiusAccessor:a.radiusAccessor,ballRadius:a.ballRadius??6,seed:a.seed??1,groupCompletion:a.groupCompletion,groupAnchorAlong:a.groupAnchorAlong,settle:a.settle??!0,gravityX:a.gravityX,gravityY:a.gravityY}),h=d.metadata;return{...i,config:d.config,initialSpawns:Oa(d.initialSpawns),projectionRows:d.projectionRows,regionEffects:h?.regionEffects,backgroundGraphics:Ia(va(d.metadata,za(i,a,"showChrome"),{},a.chromeOptions),i.backgroundGraphics),foregroundGraphics:Ia(wa(d.projectionRows,d.metadata,za(i,a,"showProjection")),i.foregroundGraphics),bodyStyle:cr(e||a.colorBy||a.groupBy,"#4e79a7",{styleRules:a.styleRules,valueAccessor:a.workAccessor||a.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Xr({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:Oa(s.initialSpawns),projectionRows:[],backgroundGraphics:Ia(za(n,i,"showChrome")?sr.createElement(Ra,{layout:s.layout,states:s.states,compact:!0===n.__compactMode}):void 0,n.backgroundGraphics),foregroundGraphics:Ia(za(n,i,"showProjection")?sr.createElement(Ca,{layout:s.layout,states:s.states}):void 0,n.foregroundGraphics),bodyStyle:cr(e||i.colorBy)}}},CrucibleChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Ns({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,bs(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,bs(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,l=Fs(s,a).state,c=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 es(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:Hr(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)||Zr(t.key,e.key))}(l,c),d=c.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)??ua(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}}))),p={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},f=e??i.colorBy??"category",g=!1===i.showChrome?null:sr.createElement(la,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),y=!1===i.showProjection?null:sr.createElement(ca,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:Oa(Os(l,s.layout,p)),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??Na(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??Na(a)}}(t,l,f,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,l),renderBodySVG:Qs,backgroundGraphics:Ia(g,n.backgroundGraphics),foregroundGraphics:Ia(y,n.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",layout:Ta,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:l,nodes:c,particleRadius:u,particleRate:d,pathAccessor:h,pathConstraint:p="path",reducedMotion:f,seed:g,size:y,sourceAccessor:m,targetAccessor:x,throughputAccessor:b}=t,v=ar(y),w=yr(g),k=new Map,A=new Map,S=[];function M(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=(dr(t,e,r)??t.id??e)+"",n=hr(dr(t,e,s)),i=hr(dr(t,e,l));if(null!=n&&null!=i){const t={x:n,y:i};k.set(o,t),S.push(t)}A.set(o,(t.label??t.name??o)+"")});const _=[];n.forEach((t,e)=>{const o=M(dr(t,e,m)),n=M(dr(t,e,x)),i=Math.max(0,hr(dr(t,e,b))??0),r=Ar(h?dr(t,e,h):void 0),s=r.length?r:Ar(t.path??t.points??t.route);s.forEach(t=>S.push(t)),_.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const P=($=S,"normalized"===(L=e)||"pixels"===L?L:$.length>0&&$.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var L,$;const R=new Map;for(const[t,e]of k)R.set(t,Sr(e,v,P));const C=[];for(const t of _){let e=t.rawPath.map(t=>Sr(t,v,P));if(2>e.length){const o=R.get(t.source),n=R.get(t.target);o&&n&&(e=[o,n])}else R.has(t.source)||R.set(t.source,e[0]),R.has(t.target)||R.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(A.has(t.source)||A.set(t.source,t.source),A.has(t.target)||A.set(t.target,t.target),C.push({...t,path:e,packetCount:0}))}const T=fr(d,.12),O=Math.max(1,Math.round(i)),I=C.map(t=>Math.max(1,Math.round(t.throughput*T))),z=I.reduce((t,e)=>t+e,0),F=z>O?O/z:1;C.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(I[e]*F))});let N=C.reduce((t,e)=>t+e.packetCount,0);for(;N>O;){const t=C.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>C[t].packetCount)?o:t,-1);if(-1===t)break;C[t].packetCount-=1,N-=1}const E=new Map,D=new Map,W=[],B=fr(o,90),j=fr(u,4);C.forEach((t,e)=>{E.set(t.target,(E.get(t.target)??0)+t.throughput),D.set(t.source,(D.get(t.source)??0)+t.throughput);const o=Mr(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=f?i:pr(.12+.84*i+.04*(w()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*w())),a=_r(t.path,s),l=_r(t.path,r),c=Pr(t.path,s),u={x:-c.y,y:c.x},d=(w()-.5)*j*1.5;W.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:c.x*B+10*(w()-.5),vy:f?0:c.y*B+10*(w()-.5),mass:.8,spawnAt:f?0:.04*e+n/32,shape:{type:"circle",radius:j},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:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target},springs:"none"!==p&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*j,stiffness:26,damping:4.25}]:void 0})}});const Y=Math.max(18,5*j),X=Array.from(R,([t,e])=>({nodeId:t,label:A.get(t)??t,sensorId:"physical-flow-node-"+gr(t),point:e})),G=X.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:Y,height:Y}})),V=Object.fromEntries(X.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),H=ur(g,[...a({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...G],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*j),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=O,H.eviction="oldest",H.observation={...H.observation,sensors:V};const q=Array.from(R,([t,e])=>({id:t,label:A.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+gr(t),incoming:E.get(t)??0,outgoing:D.get(t)??0})),U=C.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:H,initialSpawns:W,projectionRows:q.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:P,particleCount:W.length,totalThroughput:C.reduce((t,e)=>t+e.throughput,0),plot:v.plot,nodes:q,links:U}}}({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:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(Ma(s.metadata,{showNodeLabels:!1!==i.showNodeLabels,showSensors:!1!==i.showSensors,showStaticFlow:!1!==i.showStaticFlow}),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",layout:Ta,buildProps:(e,o,n,i,r)=>{const s=i.size??[700,380],a=ye(i.theme),l=function(e){const o=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}}}(e.config,e.chartId,e.onObservation),n=Rr(e.colorScheme,e.themeCategorical,B),i=ar(e.size),r={data:e.data,scales:{x:$r().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:$r().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:Cr(n,e.colorScheme),config:e.layoutConfig??{},world:new t(o)},s=e.skipLayout?{}:e.layout(r)??{},a=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})}([...s.initialSpawns??s.bodies??[]],s.constraints);return{config:Tr(o,s),context:r,initialSpawnPacing:s.initialSpawnPacing,initialSpawns:a,result:s}}({chartId:r.chartId,colorScheme:n,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:Rt(a)??{},size:s,themeCategorical:a.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:l.config,initialSpawns:Oa(l.initialSpawns),projectionRows:[],bodyStyle:l.result.bodyStyle??cr(o||r.colorBy),backgroundGraphics:Ia(i.backgroundGraphics,l.result.backgroundOverlays),foregroundGraphics:Ia(i.foregroundGraphics,l.result.overlays)}}}};function Da(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Wa(t){if(!t||2>t.length)return;const e=Da(t[0]),o=Da(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Ba(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 ja from"react";import*as Ya from"react-dom/server.browser";function Xa(t){return new Set(Array.isArray(t)?t:[t])}function Ga(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Va(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Ha(t,e,o){return t+(e-t)*o}function qa(){return"undefined"!=typeof performance?performance.now():Date.now()}function Ua(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 Ka(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function Za(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function Qa(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 Ja(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 tl(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 el(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}function ol(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),l=Array(s.length),c=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],l[t]=e.rawY,c[t]=e.d}return{type:"line",path:a,rawValues:l,style:i,datum:c,group:r}}function nl(t,e,o,n,i,r,s,a){const l=[];for(const r of t){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const c=e.x(t),u=a?a(r):i;l.push({px:c,topY:e.y(s),botY:e.y(u),rawY:s})}l.sort((t,e)=>t.px-e.px);const c=Array(l.length),u=Array(l.length),d=Array(l.length);for(let t=0;l.length>t;t++){const e=l[t];c[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:c,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function il(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,l=0,c=0;for(const t of e){const e=o(t,s)||0;a+=(2*c+e)*(e-(o(t,r)||0)),l+=e,c+=e}const u=i.get(r)??0;i.set(s,u-(l>0?a/(2*l):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 rl(t,e,o,n,i,r,s){const a=o(t),l=n(t);if(!Number.isFinite(a)||!Number.isFinite(l))return null;const c={type:"point",x:e.x(a),y:e.y(l),r:i,style:r,datum:t};return void 0!==s&&(c.pointId=s),c}function sl(t,e,o,n,i,r,s,a){const l=o(t),c=n(t);if(!Number.isFinite(l)||!Number.isFinite(c))return null;const u={type:"symbol",x:e.x(l),y:e.y(c),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function al(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 ll(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 cl(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 ul(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 l=t.scales.x(e),c=t.scales.y(s),u=t.scales.y(a);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(u)&&(i.push([l,c]),r.push([l,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:cl(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function dl(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 hl(t,e,o){const n=[];for(const i of o){const o=ul(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function pl(t,e,o,n){const i=[];for(const r of n){const n=ul(t,e,o,r);n&&i.push(n)}return i}function fl(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,l=rl(r,t.scales,t.getX,i,s,n,a);l&&o.push(l)}}}function gl(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function yl(t){return ce(t)}var ml=new Map;function xl(t){const o=Object.prototype.hasOwnProperty.call(e,t)?t:"blues";let n=ml.get(o);if(n)return n;n=Array(256);const i=h(o);for(let t=0;256>t;t++)n[t]=i(t/255);return ml.set(o,n),n}function bl(t,e,o){const n=o.config.areaStyle?.(e);return n&&("string"==typeof n.fill&&(t.fill=n.fill),t.style=n),t}function vl(t,e,o,n,i){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 l=Math.floor(t/n)*n;let c=r.get(l);if(c||(c={start:l,end:l+n,total:0,categories:new Map},r.set(l,c)),c.total+=a,i){const t=i(s);c.categories.set(t,(c.categories.get(t)||0)+a)}}return r}function wl(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;kl(n)&&0===o.length&&Al(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)&&Al(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 kl(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(kl))}function Al(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function Sl(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}}function Ml(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function _l(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=Ml(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=mt(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:Ml(t.y1Accessor,"y1"),getBottom:Ml(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as Pl,scaleLog as Ll,scaleSymlog as $l,scaleTime as Rl}from"d3-scale";function Cl(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Tl(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return Ll().domain(t).range(o).clamp(!0)}return"symlog"===t?$l().domain(e).range(o):"time"===t?Rl().domain([new Date(e[0]),new Date(e[1])]).range(o):Pl().domain(e).range(o)}function Ol(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Il(t,e){const o=new U(t.capacity);return t.forEach(()=>o.push(e)),o}function zl(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function Fl(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 Nl=new WeakMap;function El(){return this.updateResults.last}function Dl(){return this.updateResults.last}function Wl(t){return this.updateResults.subscribe(t)}function Bl(t){this.config.layoutSelection=t}function jl(){Nl.set(this,!0)}function Yl(){const t=!0===Nl.get(this);return Nl.delete(this),t}function Xl(t){Object.assign(t.prototype,{getLastUpdateResult:El,getUpdateSnapshot:Dl,subscribeUpdateResult:Wl,setLayoutSelection:Bl,markStylePaintPending:jl,consumeStylePaintPending:Yl})}var Gl=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Vl=["scene-style","data-paint","accessibility","evidence"],Hl=(t,e)=>({retainedData:t,invalidations:e}),ql=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ul=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Kl=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zl=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ql=["scene-geometry","data-paint","accessibility","evidence"],Jl=["scene-style","data-paint","accessibility","evidence"],tc=[],ec={chartType:Hl("rebuild",ql),runtimeMode:Hl("rebuild",ql),xAccessor:Hl("rebuild",ql),yAccessor:Hl("rebuild",ql),timeAccessor:Hl("rebuild",ql),valueAccessor:Hl("rebuild",ql),y0Accessor:Hl("rebuild",ql),boundsAccessor:Hl("rebuild",ql),band:Hl("rebuild",ql),openAccessor:Hl("rebuild",ql),highAccessor:Hl("rebuild",ql),lowAccessor:Hl("rebuild",ql),closeAccessor:Hl("rebuild",ql),candlestickRangeMode:Hl("rebuild",ql),accessorRevision:Hl("rebuild",ql),groupAccessor:Hl("rebuild",Ul),categoryAccessor:Hl("rebuild",Ul),lineDataAccessor:Hl("rebuild",Ul),colorAccessor:Hl("rebuild",Jl),sizeAccessor:Hl("rebuild",Ql),symbolAccessor:Hl("rebuild",Ql),pointIdAccessor:Hl("rebuild",Ql),xScaleType:Hl("preserve",Kl),yScaleType:Hl("preserve",Kl),xExtent:Hl("preserve",Kl),yExtent:Hl("preserve",Kl),extentPadding:Hl("preserve",Kl),scalePadding:Hl("preserve",Kl),axisExtent:Hl("preserve",Kl),yAxisExtent:Hl("preserve",Kl),binSize:Hl("preserve",Kl),normalize:Hl("preserve",Kl),heatmapAggregation:Hl("preserve",Kl),heatmapXBins:Hl("preserve",Kl),heatmapYBins:Hl("preserve",Kl),arrowOfTime:Hl("preserve",Zl),baseline:Hl("preserve",Zl),stackOrder:Hl("preserve",Zl),sizeRange:Hl("preserve",Zl),curve:Hl("preserve",Zl),areaGroups:Hl("preserve",Zl),customLayout:Hl("preserve",Zl),layoutConfig:Hl("preserve",Zl),layoutMargin:Hl("preserve",Zl),symbolMap:Hl("preserve",Ql),showValues:Hl("preserve",Ql),heatmapValueFormat:Hl("preserve",Ql),lineStyle:Hl("preserve",Jl),pointStyle:Hl("preserve",Jl),areaStyle:Hl("preserve",Jl),barStyle:Hl("preserve",Jl),swarmStyle:Hl("preserve",Jl),waterfallStyle:Hl("preserve",Jl),candlestickStyle:Hl("preserve",Jl),boundsStyle:Hl("preserve",Jl),gradientFill:Hl("preserve",Jl),lineGradient:Hl("preserve",Jl),semanticLineStops:Hl("preserve",Jl),colorScheme:Hl("preserve",Jl),themeCategorical:Hl("preserve",Jl),themeSemantic:Hl("preserve",Jl),themeSequential:Hl("preserve",Jl),themeDiverging:Hl("preserve",Jl),barColors:Hl("preserve",Jl),decay:Hl("preserve",Jl),pulse:Hl("preserve",Jl),staleness:Hl("preserve",Jl),layoutSelection:Hl("preserve",Jl),annotations:Hl("preserve",["overlay","accessibility","evidence"]),windowSize:Hl("preserve",tc),windowMode:Hl("preserve",tc),maxCapacity:Hl("preserve",tc),clock:Hl("preserve",tc),transition:Hl("preserve",tc),introAnimation:Hl("preserve",tc),onLayoutError:Hl("preserve",tc)},oc=Hl("preserve",Zl),nc=class{constructor(){this.tracker=new o}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}},Gl)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Vl):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=ec[n]??oc;"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 ic}from"d3-quadtree";var rc=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=ic().x(t=>t.x).y(t=>t.y).addAll(i)}},sc=class t{constructor(t){if(this.xExtent=new q,this.yExtent=new q,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 nc,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 rc,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 l=!1;const c=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=c.get(o);if(null==e)continue;a=!0;const s=n.get(e);if(null==s)continue;const l=Za(t,s,r);l>i&&(i=l)}a&&(l=Qa(o,i,s)||l);continue}const e=c.get(o.datum);if(null==e)continue;const i=n.get(e);l=Qa(o,null==i?0:Za(t,i,r),s,a)||l}return l}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new U(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=mt(t.timeAccessor||t.xAccessor,"time"),this.getY=mt(t.valueAccessor||t.yAccessor,"value")):(this.getX=mt(t.xAccessor,"x"),this.getY=mt(t.yAccessor,"y")),this.getGroup=wt(t.groupAccessor),this.getCategory=wt(t.categoryAccessor),this.getSize=t.sizeAccessor?mt(t.sizeAccessor,"size"):void 0,this.getColor=wt(t.colorAccessor),this.getSymbol=wt(t.symbolAccessor),this.getY0=t.y0Accessor?mt(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=_l(t),this.getPointId=wt(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?mt(t.openAccessor,"open"):void 0,this.getHigh=mt(t.highAccessor,"high"),this.getLow=mt(t.lowAccessor,"low"),this.getClose=o?mt(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new U(t.windowSize))}currentTime(){return this.config.clock?.()??qa()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Il(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?mt(this.config.timeAccessor||this.config.xAccessor,"time"):mt(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(lt(n));if(this.xIsDate=i||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>Z(e[t]):t=>Z(o(t))}}Ol(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)zl(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=zl(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.yExtent.extent;let a=Cl(this.xExtent.extent,e.xExtent),l=Cl(s,e.yExtent);const c=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===(e.yAxisExtent??e.axisExtent);if("stackedarea"===e.chartType&&!c&&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,l=new Set;let c=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),l.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>c&&(c=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",p=(t,e)=>e>t?-1:t>e?1:0;let f,g;if("input"===h)f=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:p(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);f=[...n.reverse(),...e]}else f="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:p(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:p(t,e)}):o.map(t=>t.key).sort(p);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),o=il(t,f,(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,c=r?0:s>0?s*e.extentPadding:1;g=[n-c,i+c]}else if("diverging"===e.baseline){const t=Array.from(l).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,f,(t,e)=>a.get(t)?.get(e)||0),i=n-o,s=r?0:i>0?i*e.extentPadding:1;g=[o-s,n+s]}else g=[0,c+(r?0:c>0?c*e.extentPadding:1)];return{yDomain:g,stackExtentCache:{key:s,yDomain:g}}}({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&&!c&&o.size>0?l=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=vl(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,d):"waterfall"===e.chartType&&!c&&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,d):c||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:d,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));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,!!c),({xDomain:a,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}}(a,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:Pl().domain(n).range(t),y:Tl(e.yScaleType,i,[o.height-s,s])}}return{x:Tl(e.xScaleType,n,[s,o.width-s]),y:Tl(e.yScaleType,i,[o.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:l}),this._customLayoutFailedThisBuild=!1;const h=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=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 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=Tl,l=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),c=s[1]>s[0];this.scales={x:a(this.config.xScaleType,n,r[0]>r[1]?[t.width-l,l]:[l,t.width-l]),y:a(this.config.yScaleType,i,c?[l,t.height-l]:[t.height-l,l])},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??Jt},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};let r;try{r=o.customLayout(i)}catch(t){const e=null!==this.lastCustomLayoutResult,n=Sl("xy",t,e,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{o.onLayoutError?.(n)}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 wl({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 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};switch(o.chartType){case"line":return function(t,e){const o=t.groupData(e),n=[],i=t.config.annotations?.filter(gl).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=ol(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 fl(t,o,n),n}(i,e);case"area":return function(t,e){const o=t.groupData(e),n=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(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,l=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=nl(e.data,t.scales,t.getX,t.getY,r,o,e.key,l),c=yl(t.config.gradientFill);c&&(i.fillGradient=c),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 fl(t,o,n),n}(i,e);case"mixed":return 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}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(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=nl(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=yl(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=ol(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 fl(t,o,n),n}(i,e);case"stackedarea":return 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:l}=function(t,e,o,n,i,r,s,a="zero"){const l=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&l.add(e)}const c=Array.from(l).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 c){let o=0;for(const n of t)o+=u.get(n.key)?.get(e)||0;d.set(e,o||1)}}const h=il(c,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),p="diverging"===a&&!r,f=[],g=new Map,y=new Map,m=new Map,x=new Map;for(const t of c)y.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=[],l=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:l,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),f.push(t)}a=[],l=[]};for(const o of c){const i=t.has(o);let s,c,u=i?t.get(o):0;if(r&&i&&(u/=d.get(o)),!i||!Number.isFinite(u)||0===u){h();continue}p?u>0?(s=m.get(o),c=s+u,m.set(o,c)):(s=x.get(o),c=s+u,x.set(o,c)):(s=y.get(o),c=s+u,y.set(o,c));const f=e.x(o);l.push([f,e.y(s)]),a.push([f,e.y(c)]),n.set(o,c)}h(),g.set(o.key,n)}return{nodes:f,stackedTops:g}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),c=a;if(t.config.pointStyle){const e=new WeakMap;for(const n of o){const o=l.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);fl(t,o,c,n)}return c}(i,e);case"scatter":case"bubble":return function(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",l=t.getSymbol,c=l?_(l,t.config.symbolMap):null;for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},l=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(l=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(c){const n=c(i),r=sl(i,t.scales,t.getX,t.getY,Math.PI*l*l,n,e,u);r&&o.push(r)}else{const n=rl(i,t.scales,t.getX,t.getY,l,e,u);n&&o.push(n)}}return o}(i,e);case"heatmap":return function(t,e,o){if(t.config.heatmapAggregation)return function(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=mt(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,l]=t.scales.x.domain(),[c,u]=t.scales.y.domain(),d=(l-a||1)/n,h=(u-c||1)/i,p=n*i;if(p>1e6)return[];const f=new Int32Array(p),g=new Float64Array(p);for(let o=0;e.length>o;o++){const r=e[o],l=t.getX(r),u=t.getY(r);if(!isFinite(l)||!isFinite(u))continue;const p=Math.min(Math.floor((l-a)/d),n-1),y=Math.min(Math.floor((u-c)/h),i-1);if(0>p||0>y)continue;const m=y*n+p;f[m]++;const x=s(r);g[m]+=isFinite(x)?x:0}let y=1/0,m=-1/0;for(let t=0;p>t;t++){if(0===f[t])continue;let e;switch(r){case"sum":e=g[t];break;case"mean":e=g[t]/f[t];break;default:e=f[t]}y>e&&(y=e),e>m&&(m=e)}if(!isFinite(y))return[];const x=m-y||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/n,A=o.height/i,S=t.config.showValues,M=t.config.heatmapValueFormat,_=[];for(let e=0;i>e;e++){const o=e*n;for(let s=0;n>s;s++){const n=o+s;if(0===f[n])continue;let l;switch(r){case"sum":l=g[n];break;case"mean":l=g[n]/f[n];break;default:l=f[n]}const u=Math.min((l-y)*w+.5|0,255),p=b?b(l):v[u],m={xi:s,yi:e,value:l,count:f[n],sum:g[n],xCenter:a+(s+.5)*d,yCenter:c+(e+.5)*h,agg:r};_.push(bl(ll(s*k,(i-1-e)*A,k,A,p,m,S?{value:l,showValues:!0,valueFormat:M}:{value:l}),m,t))}}return _}(t,e,o);if(0===e.length)return[];const n=mt(t.config.valueAccessor,"value"),i=vt(t.config.xAccessor,"x"),r=vt(t.config.yAccessor,"y"),s=new Map,a=new Map,l=Array(e.length),c=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],n=i(o),u=r(o);l[t]=n,c[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()),p=Array.from(a.keys()),f=h.every(t=>"number"==typeof t&&!isNaN(t)),g=p.every(t=>"number"==typeof t&&!isNaN(t));if(f){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(g){p.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;p.length>t;t++)a.set(p[t],t)}const y=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],i=s.get(l[t]),r=a.get(c[t]);if(void 0===i||void 0===r)continue;const d=n(o),h=r*u+i,p=b.get(h);let f;void 0!==p?f=p:(f=v++,b.set(h,f)),y[f]=h,m[f]=d,x[f]=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 A=t.config.heatmapColorScale,S=A?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 n=y[e],i=n%u,r=(n-i)/u,s=Math.min((o-w)*M+.5|0,255),a=A?A(o):S[s],l=x[e];R.push(bl(ll(i*_,(d-1-r)*P,_,P,a,l,L?{value:o,showValues:!0,valueFormat:$}:{value:o}),l,t))}return R}(i,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=vl(e,t.getX,t.getY,t.config.binSize,t.getCategory);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)),l=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===l?n=t.barCategoryCache.order:(n=[...a,...s],t.barCategoryCache={key:l,order:n})}const i=[],r=t.scales,[s,a]=r.x.domain(),l=t.config.barStyle,c=t.config.themeSemantic?.primary,u=l?.gap,d="number"!=typeof u||0>u?1:u,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.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 p=r.x(o),f=r.x(u),g=Math.abs(f-p),y=g>d+1?d:0,m=Math.min(p,f)+y/2,x=Math.max(g-y,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),p=Math.abs(a-u),f=(t.config.barColors?ne(t.config.barColors,s):void 0)??l?.fill??c??"#4e79a7",g={binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},y=t.config.areaStyle?.(g)??{};i.push(al(m,d,x,p,{fill:f,...h,...y},g,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=l?.fill||c||"#007bff",d={binStart:e.start,binEnd:e.end,total:e.total},p=t.config.areaStyle?.(d)??{};i.push(al(m,s,x,a,{fill:u,...h,...p},d))}}const p=new Set;for(const t of o.values())p.add(t.start),p.add(t.end);return{nodes:i,binBoundaries:Array.from(p).sort((t,e)=>t-e)}}(i,e);return this._barCategoryCache=i.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return 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,l=n.strokeWidth,c=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 p=r;if(t.getCategory){const e=t.getCategory(n)+"";p=(t.config.barColors?ne(t.config.barColors,e):void 0)??p}const{r:f,...g}=t.config.pointStyle?.(n)??{},y={type:"point",x:d,y:h,r:f??i,style:{fill:p,opacity:s,stroke:a,strokeWidth:l,cursor:c,...g},datum:n};t.getPointId&&(y.pointId=t.getPointId(n)+""),o.push(y)}return o}(i,e);case"waterfall":return 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",l=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",c=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let p=0;for(let e=0;s.length>e;e++){const f=s[e],g=t.getX(f),y=t.getY(f),m=p+y;let x;x=s.length-1>e?t.getX(s[e+1])-g:e>0?g-t.getX(s[e-1]):0;const b=i.x(g),v=0!==x?i.x(g+x):b+o.width/10,w=Math.min(b,v)+c/2,k=Math.max(b,v)-c/2-w;if(0>=k){p=m;continue}const A=i.y(p),S=i.y(m),M=Math.min(A,S),_=Math.abs(A-S),P=0>y?l:a,L={...f,baseline:p,cumEnd:m,delta:y,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},$={fill:P,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(L)};n.push(al(w,M,k,_,$,L)),p=m}return n}(i,e,t);case"candlestick":return 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",l=n?s:r.downColor||"#dc3545",c=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),p=t.getLow(s);if(null==d||Number.isNaN(d)||null==p||Number.isNaN(p))continue;const f=n?d:t.getOpen(s),g=n?p:t.getClose(s);if(!n&&[f,g].some(t=>null==t||Number.isNaN(t)))continue;const y=g>=f,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(f),closeY:t.scales.y(g),highY:t.scales.y(d),lowY:t.scales.y(p),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:y,style:{cursor:r.cursor},datum:s};n&&(m.isRange=!0,m.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),i.push(m)}return i}(i,e,t);default:return[]}}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?Ua(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=Ka(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=Ka(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]=Ua(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]=Ua(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=Ua(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=Ua(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&&Ja(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=tl(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:el(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:el(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:el(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:el(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=tl(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=qa()){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 l=new Set,c=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=tl(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(c.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){l.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=el(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=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=el(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=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=el(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=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=el(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=el(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){l.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=el(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=el(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!c.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(!l.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=Va(t,o.activeTransition),r=Ga(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=Ha(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=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Ha(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=Ha(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=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Ha(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=Ha(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=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==o.w&&(t.w=Ha(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Ha(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:Ha(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=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==o.w&&(t.w=Ha(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Ha(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:Ha(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=Ha(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Ha(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Ha(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Ha(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Ha(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ha(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]=Ha(e[n][0],o[n][0],r),t.path[n][1]=Ha(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ha(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]=Ha(e[o][0],n[o][0],r),t.topPath[o][1]=Ha(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]=Ha(o[e][0],i[e][0],r),t.bottomPath[e][1]=Ha(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 l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||Jt,c=new Map;for(let t=0;s.length>t;t++)c.set(s[t],l[t%l.length]);return{map:c,cache:{key:a,map:c,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 l=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||Jt;if(0===l.length)return{color:null,groupColorCounter:s};const c=l[s%l.length];if(s++,n.set(e,c),n.size>i){const t=n.keys().next().value;void 0!==t&&n.delete(t)}return{color:c,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=Xa(t),o=this.getPointId,n=t=>e.has(o(t));Fl(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=Xa(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||!yt(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),l=r||!yt(o,s);(a||l)&&(t?(this.getX=mt(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=mt(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=mt(this.config.xAccessor,"x"),this.getY=mt(this.config.yAccessor,"y")),l&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=_l(this.config)),n=!0,i=!0)}if("groupAccessor"in t&&!yt(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?wt(this.config.groupAccessor):void 0,n=!0),"categoryAccessor"in t&&!yt(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?wt(this.config.categoryAccessor):void 0,n=!0),"sizeAccessor"in t&&!yt(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?mt(this.config.sizeAccessor,"size"):void 0,n=!0),"symbolAccessor"in t&&!yt(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?wt(this.config.symbolAccessor):void 0,n=!0),"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?wt(this.config.colorAccessor):void 0,n=!0),"y0Accessor"in t&&!yt(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?mt(this.config.y0Accessor,"y0"):void 0,n=!0,i=!0),("boundsAccessor"in t&&!yt(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=_l(this.config),n=!0,i=!0),"pointIdAccessor"in t&&!yt(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?wt(this.config.pointIdAccessor):void 0,n=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!yt(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!yt(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!yt(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!yt(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?mt(this.config.openAccessor,"open"):void 0,this.getHigh=mt(this.config.highAccessor,"high"),this.getLow=mt(this.config.lowAccessor,"low"),this.getClose=e?mt(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}};sc.GROUP_COLOR_MAP_CAP=1e3;var ac=sc;Xl(ac);import*as lc from"react";import{area as cc,line as uc}from"d3-shape";function dc(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}import{jsx as hc,jsxs as pc}from"react/jsx-runtime";var fc={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function gc(t,e="#4e79a7"){return ot(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function yc(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function mc(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=g(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),l=p(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),c=l?yc(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:N(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:N(o.stroke??"none",a,t.accent);return i||r?hc("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 pc("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&hc("clipPath",{id:c,children:hc("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&t.ghostColor?hc("g",{children:d(t.ghostColor)}):null,l&&c?hc("g",{clipPath:`url(#${c})`,children:d()}):d()]},n)}function xc(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)=>hc("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function bc(t,e,o){const n=X(t.symbolType,t.size,t.path);return hc("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?gc(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 vc from"react";import{jsx as wc}from"react/jsx-runtime";function kc(t){if(!1!==t?.interactive)return t?.style?.cursor}function Ac(t,e,o){const n=kc(e);return n&&null!=t&&!1!==t?wc("g",{style:{cursor:n},"data-semiotic-mark-cursor":n,children:t},o):t}import*as Sc from"react";import{arc as Mc}from"d3-shape";import{jsx as _c,jsxs as Pc}from"react/jsx-runtime";import*as Lc from"react";import{jsx as $c,jsxs as Rc}from"react/jsx-runtime";import*as Cc from"react";import{arc as Tc}from"d3-shape";var Oc=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function Ic(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=Oc(o,n),e=Oc(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=Oc(o,n),s=Oc(o,i),a=Oc(e,i),l=Oc(e,n),c=i-n>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${c} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${c} 0 ${l.x},${l.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return Ic({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),l=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),c=i-n,u=t.roundStart&&t.roundEnd?c/2:c,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return Ic({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const p=n+(d?a:0),f=i-(h?a:0),g=n+(d?l:0),y=i-(h?l:0),m=Oc(o,p),x=Oc(o,f),b=(o-s)*Math.cos(a),v=Oc(b,n),w=Oc(b,i),k=r?null:Oc(e,y),A=r?null:Oc(e,g),S=r?0:(e+s)*Math.cos(l),M=r?null:Oc(S,n),_=r?null:Oc(S,i),P=f-p>Math.PI?1:0,L=r?0:y-g>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=Oc(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=Oc(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=Oc(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=Oc(e,n);$+=` A${e},${e} 0 ${L} 0 ${t.x},${t.y}`}}return $+=" Z",$}import{jsx as zc,jsxs as Fc}from"react/jsx-runtime";function Nc(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 Ec(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(zc("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:i},e+"-funnel-step"));const l=Number(o.__funnelValue),c=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let i=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${Nc(l)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:Nc(l);7.8*i.length+16>d&&(i=Nc(l)),7.8*i.length+16>d||n.push(zc("text",{x:c,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:i},e+"-funnel-value"))}return n.length?zc("g",{children:n},e+"-funnel-labels"):null}function Dc(t,e,o){return Ac(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=yc(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=xc(o.stops,gc(t.style.fill));return a?hc("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:n,y1:i,x2:r,y2:s,children:a}):null}(e,o);let i,a;if(n)a=`url(#${o})`;else if(ot(e.style.fill)){const t=yc(r)+"-hatch";i=et(e.style.fill,t),a=`url(#${t})`}else a=gc(e.style.fill);const l=n||i?Fc("defs",{children:[n,i]}):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:n,h:i}=t,{tl:r,tr:s,br:a,bl:l}=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,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)}}(t);let c=`M${e+r},${o}`;return c+=` L${e+n-s},${o}`,s>0&&(c+=` A${s},${s} 0 0 1 ${e+n},${o+s}`),c+=` L${e+n},${o+i-a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${e+n-a},${o+i}`),c+=` L${e+l},${o+i}`,l>0&&(c+=` A${l},${l} 0 0 1 ${e},${o+i-l}`),c+=` L${e},${o+r}`,r>0&&(c+=` A${r},${r} 0 0 1 ${e+r},${o}`),c+=" Z",c}(e);return Fc(Cc.Fragment,{children:[l,zc("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:n,w:i,h:s}=e;let c;switch(e.roundedEdge){case"right":c=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+s-t} A${t},${t} 0 0 1 ${o+i-t},${n+s} L${o},${n+s} Z`;break;case"left":c=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+s-t} A${t},${t} 0 0 0 ${o+t},${n+s} L${o+i},${n+s} Z`;break;case"bottom":c=`M${o},${n} L${o+i},${n} L${o+i},${n+s-t} A${t},${t} 0 0 1 ${o+i-t},${n+s} L${o+t},${n+s} A${t},${t} 0 0 1 ${o},${n+s-t} Z`;break;default:c=`M${o},${n+s} 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+s} Z`}return Fc(Cc.Fragment,{children:[l,zc("path",{d:c,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return Fc(Cc.Fragment,{children:[l,zc("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}),Ec(e,r)]},r)}case"point":{const e=t;return zc("circle",{cx:e.x,cy:e.y,r:e.r,fill:gc(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return bc(t,e,o);case"glyph":return mc(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=yc(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=Ic({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:Ic({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 Fc("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[zc("defs",{children:zc("clipPath",{id:t,children:zc("path",{d:i})})}),zc("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>zc("path",{d:t.d,fill:gc(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&zc("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=Ic({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=Tc().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(fc)||""}return zc("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:gc(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 Fc("g","vertical"===e.projection?{children:[zc("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*n}),zc("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("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:[zc("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*n}),zc("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("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=[zc("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:gc(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(zc("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),zc("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(zc("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),zc("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return zc("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?gc(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return zc("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 zc("polygon",{points:o,fill:gc(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 Wc,jsxs as Bc}from"react/jsx-runtime";function jc(t,e,o,n){if(!t||2>e.length)return null;const i=xc(t.stops,n);return i?Wc("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function Yc(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=qs(n.curve),r=i?uc().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=yc(`${o?o+"-":""}line-${e}-stroke-gradient`),a=jc(n.strokeGradient,n.path,s,n.style.stroke||"#4e79a7");return Bc(lc.Fragment,{children:[a&&Wc("defs",{children:a}),Wc("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=qs(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`:cc().x(([t])=>t).y0((t,e)=>i.bottomPath[e][1]).y1(([,t])=>t).curve(r)(i.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,l=ot(i.style.fill)?et(i.style.fill,a):void 0,c=yc(`${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=xc(o.stops,gc(t.style.fill));return r?Wc("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r}):null}(i,c),d=u?`url(#${c})`:l?`url(#${a})`:gc(i.style.fill),h=u?void 0:i.style.fillOpacity??i.style.opacity??.7,p=r?uc().x(([t])=>t).y(([,t])=>t).curve(r)(i.topPath)??"":"M"+i.topPath.map(([t,e])=>`${t},${e}`).join("L"),f=kc(i),g=f&&n>=0?Wc("path",{d:p,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*n),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:f},"data-semiotic-mark-cursor":f,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${e}-cursor-target`):null,y=yc(`${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:jc(i.strokeGradient,i.topPath,y,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)=>yc(`${o?o+"-":""}area-${e}-stroke-band-${n}`)):[],S=x?i.strokeColorBands.map((t,e)=>Wc("clipPath",{id:A[e],children:Wc("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)=>Wc("path",{d:p,fill:"none",stroke:t.color??gc(i.style.stroke),strokeWidth:v,opacity:(i.style.opacity??1)*(t.opacity??1),clipPath:`url(#${A[o]})`},`area-${e}-stroke-band-${o}`)):m?function(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],[l,c]=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(dc(u+d*((e+i)/2),o,n),[s+(l-s)*e,a+(c-a)*e],[s+(l-s)*i,a+(c-a)*i])}}return i}(i.topPath,i.rawValues,i.colorThresholds,gc(i.style.stroke)).map((t,o)=>Wc("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}`)):Wc("path",{d:p,fill:"none",stroke:b?`url(#${y})`:gc(i.style.stroke),strokeWidth:v,opacity:i.style.opacity}):null;if(i.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return Bc("g",{children:[Bc("defs",{children:[u,!u&&l,b,S,Wc("clipPath",{id:t,children:Wc("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),Bc("g",{clipPath:`url(#${t})`,children:[Wc("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]})]},"area-"+e)}return Bc(lc.Fragment,{children:[(u||l||b||S)&&Bc("defs",{children:[u,!u&&l,b,S]}),Wc("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=ot(n.style.fill)?et(n.style.fill,i):void 0;return Bc(lc.Fragment,{children:[r&&Wc("defs",{children:r}),Wc("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:gc(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return bc(t,e);case"glyph":return mc(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=ot(n.style.fill)?et(n.style.fill,i):void 0;return Bc(lc.Fragment,{children:[r&&Wc("defs",{children:r}),Wc("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:gc(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",l=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return Bc("g",{children:[Wc("rect",{...n}),Wc("text",{x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:l+"px",children:t})]},"heatcell-"+e)}return Wc("rect",{...n},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return Bc("g",{children:[Wc("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),Wc("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),Wc("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 Bc("g",{children:[Wc("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),Wc("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:Ac(i,t,"xy-cursor-"+e)}var Xc=new Set;function Gc(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:Ac(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}`;Xc.has(o)||(Xc.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 Vc(t){const e=[];return t.nodes.forEach((o,n)=>{const i=Gc({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 Hc}from"d3-scale";import{jsx as qc,jsxs as Uc}from"react/jsx-runtime";function Kc(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>ne(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:B;return Hc().domain(t).range(n)}function Zc(t,e,o){if(0===t.length)return;const n=Kc(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}function Qc(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Jc(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function tu(t){return t.typography.legendFontFamily??t.typography.fontFamily}function eu(t){return t.typography.legendFontWeight}function ou(t,e,o,n){const i=Jc(n);return e+o+Math.ceil(t.length*i*.58)}function nu(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=lo(s),d=a+l,h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right),f=e.map(t=>ou(t,a,l,o));if(h){const t=Math.max(a,s?.maxWidth??p),o=[];let n=0,i=0;f.forEach((e,r)=>{const s=0===i?e:i+c+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=Qc(s?.align),l=[];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++)l.push({category:e[t],width:f[t],x:i,y:n*u}),i+=f[t]+c}),{items:l,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...f);return{items:e.map((t,e)=>({category:t,width:f[e],x:0,y:e*u})),width:g,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function iu(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 ru,jsxs as su}from"react/jsx-runtime";function au(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 lu(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 cu(t,e,o,n){if(!t)return ru("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=t;if(!i&&!r)return ru("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 p=16,f=r?c?[r]:au(r,l):[],g=i?c?[i]:au(i,l):[],y="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(ru("foreignObject",{className:"annotation-note-html",x:"end"===h?y-l:"middle"===h?y-l/2:y,y:-16,width:l,height:Math.max(p,(f.length+g.length)*p+(r&&i?2:0))+p,style:{overflow:"visible"},children:su("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:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&ru("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&ru("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(f.length>0&&(x.push(ru("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:f.map((t,e)=>ru("tspan",{x:y,dy:0===e?0:p,children:t},e))},"annotation-note-title")),m=f.length*p),g.length>0&&x.push(ru("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:g.map((t,e)=>ru("tspan",{x:y,dy:0===e?0:p,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(l,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=ru("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(f.length+g.length)*p+(g.length>0?p:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=ru("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,f.length+g.length-1)*p;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+p+(g.length>0&&f.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),su("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[ru("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function uu(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(ru("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(ru("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(ru("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(ru("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(ru("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(ru("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(ru("path",{d:lu(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return ru("g",{className:"annotation-subject",children:r})}function du(t,e,o,n,i,r){const s=[];let a=0,l=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,c=e-r;if(0!==s||0!==c){const t=Math.abs(s),e=Math.abs(c),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,l=o):void 0!==e&&(a=o,l=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,l=Math.sin(n)*o}}const c=Math.sqrt((t-a)**2+(e-l)**2);if(c>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-l,t-a);if(r){const n=(a+t)/2,r=(l+e)/2,d=-(e-l)/c,h=(t-a)/c,p=(o?.curve??.25)*c,f=n+d*p,g=r+h*p;s.push(ru("path",{className:"connector-curve",d:`M${a},${l}Q${f},${g} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(g-l,f-a)}else s.push(ru("line",{x1:a,y1:l,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(ru("path",{d:`M${a},${l}L${a+t*Math.cos(u+e)},${l+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${l+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return ru("g",{className:"annotation-connector",children:s})}function hu(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:p,opacity:f,strokeDasharray:g,events:y={},"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(p)?p:[]);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&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;const t=c.depth||30;k=t+(0>t?-5:5)}else if(void 0!==c.height){const t=c.depth||30;w=t+(0>t?-5:5),k=c.height/2}return su("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=f&&{opacity:f},...g&&{strokeDasharray:g},...y,children:[!v.has("connector")&&du(w,k,l,d,A,c),!v.has("subject")&&uu(A,c,d,x,b),!v.has("note")&&cu(a,w,k,d)]})}function pu(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 ru(hu,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return ru("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return ru(hu,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{jsx as fu}from"react/jsx-runtime";var gu={secondary:0,primary:3};function yu(t){return!0===t?._annotationDeferred}function mu(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function xu(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function bu(t){return Math.max(.72,.95-.06*t)}function vu(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:xu(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>yu(t.annotation)),i=t.some(t=>null!=mu(t.annotation)),r=t.some(t=>"layer"===mu(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=gu[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=yu(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=fu("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:bu(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=mu(e.annotation);return a&&(s=fu("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=fu("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(fu("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(fu("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}import{jsx as wu,jsxs as ku}from"react/jsx-runtime";var Au="var(--semiotic-bg, #ffffff)";function Su(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,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),p=t=>wu("text",{x:e,y:o,textAnchor:l,dominantBaseline:c,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 p();if("halo"===h.type)return p({stroke:h.fill??Au,strokeWidth:h.haloWidth??3});const f=h.padding??{x:6,y:3},g="number"==typeof f?f:f.x,y="number"==typeof f?f:f.y,m=function(t,e){return(t+"").length*e*.6}(n,r),x=r+2*y;let b,v;return b="middle"===l?e-m/2-g:"end"===l?e-m-g:e-g,v="middle"===c||"central"===c?o-x/2:"hanging"===c||"text-before-edge"===c?o-y:o-.8*r-y,ku("g",{className:d,children:[wu("rect",{x:b,y:v,width:m+2*g,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??Au,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),p()]})}function Mu(t,e,o,n){const i=ht(t.fill??t.color,e,n);return ct(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:n)??i}var _u=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Pu(t,e,o,n){const i=function(t,e,o){const n=t.position,i="string"==typeof n&&_u.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 Lu}from"react/jsx-runtime";var $u={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Ru({annotation:t,width:e,height:o,defaults:n=$u}){const i=t.label??t.text;return null==i?null:Lu("text",{...Pu(t,e,o,n),children:i})}import{packEnclose as Cu}from"d3-hierarchy";import{area as Tu,curveBasis as Ou,curveCardinal as Iu,curveCatmullRom as zu,curveLinear as Fu,curveMonotoneX as Nu,curveMonotoneY as Eu,curveStep as Du,curveStepAfter as Wu,curveStepBefore as Bu}from"d3-shape";import*as ju from"react";function Yu(t,e={}){const o=K(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 Xu,jsxs as Gu}from"react/jsx-runtime";var Vu={linear:Fu,monotoneX:Nu,monotoneY:Eu,step:Du,stepAfter:Wu,stepBefore:Bu,basis:Ou,cardinal:Iu,catmullRom:zu};import{jsx as Hu,jsxs as qu}from"react/jsx-runtime";var Uu=16;function Ku(t,e){return t.color||e.colors.annotation||e.colors.text}function Zu(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 Qu(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 Ju(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 td(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=gt(e),n=t.scales.geoProjection,r=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,s=!!n&&!t.scales.x&&!t.scales.y,a=t=>Number(t),l=t.scales.x??(s?a:void 0),c=t.scales.y??(s?a:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{..."vertical"===t.projection?{x:t.scales.o??l,y:t.scales.r??c,time:t.scales.o??l,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??l,y:t.scales.o??c,time:t.scales.r??l,value:t.scales.o??c,o:t.scales.o}:{x:l,y:c,time:l,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"),...u?{projection:u}:{}},h=t.autoPlaceAnnotations?i({annotations:r,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):r,p=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:vu(i),renderedAnnotations:i.map(t=>t.annotation)}}(h,(e,o,n)=>function(t,e,o,n){const{scales:i,layout:r,theme:s,xAccessor:a,yAccessor:l}=o;switch(t.type){case"frame-text":return Hu(Ru,{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=Ku(t,s),l=t.label,c=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:qu("g",{opacity:t.opacity,children:[Hu("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Hu(Su,{x:o+4,y:Uu,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Zu(t,s,"halo")})]},"ann-ythresh-"+e)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:qu("g",{children:[Hu("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Hu(Su,{x:"left"===c?4:"center"===c?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Uu):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Zu(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 l=Ku(t,s),c=t.label,u=t.labelPosition||"top";return qu("g",{opacity:t.opacity,children:[Hu("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:l,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&Hu(Su,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Uu,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:l,fontFamily:s.typography.fontFamily,text:c,background:Zu(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=i.y?.domain?.(),n=t.y0??o?.[0],a=t.y1??o?.[1],l=null!=n&&i.y?i.y(n):null,c=null!=a&&i.y?i.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=Mu(t,"ssr-band-"+e,"vertical",Ku(t,s)),p=t.fillOpacity??.1;return qu("g",{opacity:t.opacity,children:[h.def&&Hu("defs",{children:h.def}),Hu("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:p}),t.label&&Hu(Su,{x:r.width-4,y:Math.max(u,0)+Uu,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Ku(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Zu(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=i.x?.domain?.(),n=t.x0??o?.[0],a=t.x1??o?.[1],l=null!=n&&i.x?i.x(n):null,c=null!=a&&i.x?i.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=Mu(t,"ssr-xband-"+e,"horizontal",Ku(t,s)),p=t.fillOpacity??.1;return qu("g",{opacity:t.opacity,children:[h.def&&Hu("defs",{children:h.def}),Hu("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:p}),t.label&&Hu(Su,{x:u+4,y:Uu,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Ku(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Zu(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,l=Ku(t,s),c=t.opacity??.1,u=t.label;return qu("g","horizontal"===o.projection?{children:[Hu("rect",{x:0,y:n,width:r.width,height:a,fill:l,opacity:c}),u&&Hu(Su,{x:12,y:n+a/2,dominantBaseline:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Zu(t,s,"none")})]}:{children:[Hu("rect",{x:n,y:0,width:a,height:r.height,fill:l,opacity:c}),u&&Hu(Su,{x:n+a/2,y:Uu,textAnchor:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Zu(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:Qu(t,e,o),y:Ju(t,e,n)}}(t,i,a,l),r=null==o.x||null==o.y?F(t,e,n):null,c=o.x??r?.x??null,u=o.y??r?.y??null;if(null==c||null==u)return null;const d="text"===t.type,h=t.dx??(d?0:30),p=t.dy??(d?0:-30),f=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 Hu(pu,{noteData:{x:c,y:u,dx:h,dy:p,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...n?{subject:n}:{},connector:t.connector||{end:"arrow"},color:f,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return Hu("g",{children:Hu("text",{x:c+h,y:u+p,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||s.typography.labelSize,fill:f,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:E({...t,type:"point"},o),y:D({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=Cu(n),r=t.padding||10;return Gu("g",{children:[Xu("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&&Xu(Su,{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:E({...t,type:"point"},o),y:D({...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]=St(n.map(t=>t.x)),[a,l]=St(n.map(t=>t.y)),c=r-i,u=s+i,d=a-i;return Gu("g",{children:[Xu("rect",{x:c,y:d,width:u-c,height:l+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&&Xu(Su,{x:(c+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 Xu("g",{children:i.map((e,n)=>{const i=E(e,o),s=D(e,o);if(null==i||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,l="function"==typeof t.style?t.style(e):t.style||r;return Xu("circle",{cx:i,cy:s,r:a,...l},"hl-"+n)})},"ann-"+e)}case"bracket":{const n=E(t,o),i=D(t,o);return Xu(pu,{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,l=s?i:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const t of n){const e=t[l];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[l],o=t[c];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 p=o.scales?.x??o.scales?.time,f=o.scales?.y??o.scales?.value;if(!p||!f)return null;const g=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},y=p,m=f;let x;if(s)if(a){const t=g(m);x=(e,o)=>[y(o),t(e)]}else{const t=g(y);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[y(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)),l=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,c=[];for(let t=0;o>t;t++){const e=0===l?0:n[t]/l;c[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,p=0,f=0;for(let t=0;o>t;t++){const e=c[t];0!==e&&(u+=e,d+=e*i[t],h+=e*r[t],p+=e*i[t]*i[t],f+=e*i[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const g=u*p-d*d;if(1e-12>Math.abs(g))a.push([e,h/u]);else{const t=(u*f-d*h)/g;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3):("polynomial"===b?ve(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:be((o*e[3]-e[0]*e[1])/n),r=be(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[be(t),be(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 Gu("g",{children:[Xu("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Xu("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",l=t.lowerAccessor||"lowerBounds",c=t.filter,u=n.filter(t=>null!=t[a]&&null!=t[l]&&(!c||c(t))).sort((t,e)=>t[i]-e[i]);if(2>u.length)return null;const d=Vu[o.curve||"linear"]||Fu,h=Tu().x(t=>r(t[i])).y0(t=>s(t[l])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const p=t.fill||"#6366f1",f=u[u.length-1];return Gu("g",{children:[Xu("path",{d:h,fill:p,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&Xu("text",{x:r(f[i])+4,y:s(f[a])-4,fill:p,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 l=a.reduce((t,e)=>t+e,0)/a.length,c=a.reduce((t,e)=>t+(e-l)**2,0)/a.length,u=Math.sqrt(c),d=t.threshold??2,h=l-d*u,p=s(l+d*u),f=s(h),g=t.fill||"#6366f1",y=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=n.filter(t=>{const e=t[i];return null!=e&&Math.abs(e-l)>d*u});return Gu("g",{children:[!1!==t.showBand&&Xu("rect",{x:0,y:Math.min(p,f),width:o.width||0,height:Math.abs(f-p),fill:g,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const n=E(t,o),i=D(t,o);return null==n||null==i?null:Xu("circle",{cx:n,cy:i,r:m,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Xu("text",{x:(o.width||0)-4,y:Math.min(p,f)-4,textAnchor:"end",fill:g,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 l=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>l.length)return null;let c;if("polynomial"===t.method){const e=ve(l,t.order||2).equation;c=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=we(l);if(!t)return null;c=t}const{se:u,meanX:d,ssX:h}=ke(l,c),p=l.length,f=Ae(t.confidence??.95),g=l[p-1][0],y=(g-l[0][0])/Math.max(p-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=g+(e+1)*y,n=c(o),i=u*Math.sqrt(1+1/p+(h>0?(o-d)**2/h:0))*f;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 Gu("g",{children:[Xu("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Xu("polyline",{points:`${s(g)},${a(c(g))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&Xu("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=F(t,e,o);if(!r)return null;n=r.x,i=r.y}if(!M(n,i,o))return null;const r=t.width??32,s=t.height??32,a=t.content??Xu("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Xu("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:Xu("div",{...Yu(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,n),t.svgAnnotationRules,d),f=p.nodes,g=new Map;for(const t of p.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";g.set(e,(g.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=g.get(e)??0;o>0?g.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:h.length,renderedCount:p.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?Hu("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}import{jsx as ed}from"react/jsx-runtime";function od(t,e,o,n="right",i,r){if(null==t||!1===t)return null;const{x:s,y:a}=ao(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:n,legendLayout:i,axisChrome:r});return ed("g",{transform:`translate(${s}, ${a})`,children:t})}import*as nd from"react";function id(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function rd(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function sd(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 ad(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function ld(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:ad(t)}}}function cd(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 ud(t,e){return t?.ticks??t?.tickCount??e}function dd(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function hd(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 l=(a-s)/(e-1),c=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*l;c[t]=r?new Date(o):o}return c}(t,e):t.ticks(e)}import{jsx as pd}from"react/jsx-runtime";function fd(t){return"string"==typeof t||"number"==typeof t}function gd(t){const{label:e,x:o,y:n,textAlign:i,fontSize:r,fontFamily:s,color:a}=t;return pd("foreignObject",{x:o,y:n,width:60,height:24,style:{overflow:"visible"},children:pd("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:i,userSelect:"none"},children:e})})}function yd(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 md(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function xd(t){const{candidates:e,scale:o,minPixelDistance:n,includeMax:i,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:l=!0,format:c}=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})),!l||!i||0===u.length||"exact"===r||s)return u;const d=o.domain(),h=d[d.length-1];if(null==h)return u;const p=o(h),f=u[u.length-1].pixel;if(1>=Math.abs(p-f))return u;const g=e.map(t=>t.value.valueOf()),y={value:h,pixel:p,label:c(h,u.length,g)};return n>Math.abs(p-f)&&u.length>1&&(u=u.slice(0,-1)),[...u,y]}function bd(t,e,o,n){return!!t&&("function"==typeof t?t(e.value,o):nt(e.value,o>0?n[o-1].value:void 0))}import{jsx as vd,jsxs as wd}from"react/jsx-runtime";function kd(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function Ad(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 Sd(t,e,o){return Ye(t.showLegend&&!t.__legendIncludesAutomatic?Zc(e,t.colorScheme,o):void 0,t.legend)}var Md={right:110,left:110,top:50,bottom:80};function _d(t,e){if(t.__autoLegendMargin)return Md[e]}function Pd(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:Xe(t)||Ge(t)?t.legendDistance:void 0};return Xe(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:l,rowHeight:c}=lo(s),u=a+l,d=Math.max(12,Jc(o)),h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??p),i=Qc(s?.align);let r=0,l=0;const c=[];for(const i of e){const e=i.items.map(t=>t.label),u=nu({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,p=i.label?ou(i.label,0,0,o):0,f=h>0?h+8:0,g=f+u.width,y=Math.max(u.height,p);c.push({group:i,x:r,y:0,itemOffsetX:f,itemOffsetY:0,width:g,height:y,items:u.items}),r+=g+12,l=Math.max(l,y)}const h=c.length>0?r-12:0,f=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:c.map(t=>({...t,x:t.x+f})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const f=co(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),c);let g=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>ou(t.label,a,l,o)),i=Math.max(0,...n,t.label?ou(t.label,0,0,o):0);return g=Math.max(g,i),{group:t,x:0,y:f[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*c,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*c}))}}),width:g,height:f.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??Ze(i,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:l}=ao(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=co(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",l=[qc("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=s.labelY&&l.push(qc("text",{y:s.labelY,fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:n.label},"legend-group-label-"+i)),l.push(qc("g",{transform:`translate(0,${s.itemsY})`,children:n.items.map((e,r)=>{const s=n.styleFn(e,r),l="function"==typeof a?a(e):"line"===a?qc("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):qc("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return Uc("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[l,qc("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return qc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":"vertical",fontWeight:eu(t.theme),children:n})}const c=o.groups.flatMap((e,i)=>{const{group:r}=e,a=r.type??"fill",l=[];if(r.label&&l.push(qc("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:r.label}:{x:e.x,y:e.y+Jc(t.theme),fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:r.label},"legend-group-label-"+i)),l.push(...e.items.map((n,s)=>{const l=r.items[s],c=r.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?qc("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:c}):qc("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:c});return Uc("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,qc("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:n.category})]},`legend-${i}-${s}`)})),n&&o.groups.length-1>i){const t=e.x+e.width+6;l.push(qc("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+i))}return l});return qc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":n?"horizontal":"vertical",fontWeight:eu(t.theme),children:c})}({...o,legendGroups:t.legendGroups}):Ge(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=Ze(n),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:l}=ao(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:i}),c=Array.from({length:17},(e,n)=>{const i=n/16;return qc("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 Uc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:eu(t.theme),children:[qc("defs",{children:qc("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),t.gradient.label&&qc("text",{x:e.width/2,y:n,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:tu(t.theme),children:t.gradient.label}),qc("rect",{x:0,y:i,width:e.width,height:o,fill:`url(#${r})`,rx:2}),qc("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[0])}),qc("text",{x:e.width,y:i+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?12:void 0,d=t.gradient.label?18:0;return Uc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:eu(t.theme),children:[qc("defs",{children:qc("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),t.gradient.label&&qc("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:tu(t.theme),children:t.gradient.label}),qc("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),qc("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[1])}),qc("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function Ld(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",l={...t},c={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:_d(o,a)};if(null!=o.legend){const e=Sd(o,n,i);null!=e&&!1!==e&&function(t,e){so(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";so(t,{legend:Zc(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,categories:n,colorScheme:o.colorScheme});return Ue(t,l,r,a),a}function $d(t){const{props:e,categories:o,theme:n,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",l={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=Sd(e,o,n);if(nd.isValidElement(t))return od(t,i,r,a,e.legendLayout,e.axisChrome);return Pd(t,l)||(Xe(t)||Ge(t)?null:od(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 l=Kc(e,o,n),c="top"===i||"bottom"===i,u=nu(t),d={...Zc(e,o,n),legendDistance:t.legendDistance},h=t.reservedWidth??Ze(d,t.legendLayout),{x:p,y:f}=ao(d,{totalWidth:r,totalHeight:s,margin:a,position:i,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(c){const t=u.items.map((t,e)=>Uc("g",{transform:`translate(${t.x},${t.y})`,children:[qc("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),qc("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Jc(n),fill:n.colors.text,fontFamily:tu(n),children:t.category})]},"legend-"+e));return qc("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:eu(n),children:t})}const g=co([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],y=u.items.map((t,e)=>Uc("g",{transform:`translate(${t.x},${t.y+g.itemsY})`,children:[qc("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),qc("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Jc(n),fill:n.colors.text,fontFamily:tu(n),children:t.category})]},"legend-"+e));return Uc("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:eu(n),children:[qc("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),y]})}({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 Rd=dd;function Cd(t,e){const o=me(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,l=[s,a].filter(Boolean).join(" ")||void 0;return wd("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":l,style:{fontFamily:o.fontFamily},children:[r&&vd("title",{id:s,children:r}),e.description&&vd("desc",{id:a,children:e.description}),e.defs&&vd("defs",{children:e.defs}),n&&"transparent"!==n&&vd("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),vd("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&vd("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&&vd("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{jsx as Td,jsxs as Od}from"react/jsx-runtime";function Id(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}var zd={top:50,right:40,bottom:60,left:70},Fd={top:20,right:80,bottom:20,left:80},Nd={top:40,right:40,bottom:40,left:40},Ed=new Set(["chord","force","circlepack","orbit"]);import{jsx as Dd,jsxs as Wd}from"react/jsx-runtime";import{Fragment as Bd,jsx as jd,jsxs as Yd}from"react/jsx-runtime";function Xd(t,e){const o=ye(t.theme),n=t.size||[500,300],i=qe({...zd,...t.margin},t.title),r=Ve(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}(Ht(t.data),t.lineDataAccessor),a=t.showLegend?iu(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],l=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,l=!!i,c=!1!==t.showAxes;return{hasAxis:c&&r,hasAxisLabel:c&&r&&!!(e?.label??t.xLabel),rotatedTicks:c&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(o?.label??t.xLabel),rotatedTicks:c&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??t.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});Ld(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=$d({props:{...t,axisChrome:l},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),p=t.colorScheme||o.colors.categorical,f=(t.axes?.find(t=>"left"===t.orient)??t.axes?.find(t=>"right"===t.orient))?.extent??t.axisExtent,g={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:f,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:ce(t.gradientFill),lineGradient:ue(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:p,themeCategorical:o.colors.categorical,themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging,themeSemantic:Rt(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},y=new ac(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Id(t.backgroundGraphics,n,i,y.scales),x=Id(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?td({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=Ba({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Ya.renderToStaticMarkup(Cd(m||x||t.annotations?Yd(Bd,{children:[m,a,x]}):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:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=Vc({nodes:y.scene,renderMode:t.renderMode,fallback:(e,o)=>Yc(e,o,b,t.hoverRadius??30)}),w=t.showGrid?function(t,e,o,n,i,r,s){const{grid:a}=me(o),l=n?n+"-":"",c=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),p=c??u,f=d??h,g=p?.extent??i,y=f?.extent??i,m="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=p?.tickValues??hd(t.x,ud(p,m),g),v=p?.tickFormat||s?.xFormat||s?.tickFormatTime||dd,w=yd({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,md(e.label)),0),A=xd({candidates:w,scale:t.x,minPixelDistance:p?.autoRotate?Math.max(20,Math.min(k+8,55)):Math.max(55,k+8),includeMax:p?.includeMax,extentMode:g,hasExplicitTickValues:!!p?.tickValues,format:v}),S=f?.tickValues??hd(t.y,ud(f,x),y),M=f?.tickFormat||s?.yFormat||s?.tickFormatValue||dd,_=t=>M(t),P=xd({candidates:yd({values:S,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:f?.includeMax,extentMode:y,hasExplicitTickValues:!!f?.tickValues,format:_}),L=!1!==p?.grid,$=!1!==f?.grid,R=ad(p?.gridStyle),C=ad(f?.gridStyle),T=ld(p?.gridStyle,{stroke:a,strokeWidth:.5}),O=ld(f?.gridStyle,{stroke:a,strokeWidth:.5});return Od("g",{id:l+"grid",className:"semiotic-grid",opacity:.8,children:[L&&A.map((t,o)=>Td("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...T,strokeDasharray:R??T.strokeDasharray},"gx-"+o)),$&&P.map((t,o)=>Td("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...O,strokeDasharray:C??O.strokeDasharray},"gy-"+o))]})}(y.scales,{width:u,height:d},o,b,t.axisExtent,t.axes,t):null,k=v.map(t=>t.element),A=Ad(t)+"-plot-clip",S=!1!==t.showAxes,M=S?function(t,e,o,n,i,r,s,a=!1){const l=me(n),c=o.legendPosition??"right",u=Je(o.legendLayout,s?.leftAxis),d=Je(o.legendLayout,s?.rightAxis),h=a&&"left"===c&&u>0?u:r?.left??o.margin?.left??40,p=a&&"right"===c&&d>0?d:r?.right??o.margin?.right??40,f=o.axes?.find(t=>"bottom"===t.orient),g=o.axes?.find(t=>"top"===t.orient),y=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=f??g,b=y??m,v=f?"bottom":g?"top":"bottom",w=y?"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??hd(t.x,ud(x,L),_),C=x?.tickFormat||o.xFormat||o.tickFormatTime||Rd,T=yd({values:R,scale:t.x,format:C}),O=T.reduce((t,e)=>Math.max(t,md(e.label)),0),I=xd({candidates:T,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(O+8,55)):Math.max(55,O+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:C}),z=b?.tickValues??hd(t.y,ud(b,$),P),F=b?.tickFormat||o.yFormat||o.tickFormatValue||Rd,N=t=>F(t),E=xd({candidates:yd({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&&I.length>1&&e.width/Math.max(I.length-1,1)<I.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),W=sd(I),B=sd(E),j=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),X=ld(x?.axisStyle,{stroke:l.border,strokeWidth:1}),G=ld(b?.axisStyle,{stroke:l.border,strokeWidth:1}),V="right"===w?e.width+p-15:15-h;return wd("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&vd("line",{x1:0,y1:k,x2:e.width,y2:k,...X}),x?.jaggedBase&&vd("path",{d:cd(v,e.width,e.height),fill:"none",...X}),I.map((t,e)=>{const o=bd(x?.landmarkTicks,t,e,I);return wd("g",{transform:`translate(${t.pixel},${k})`,children:[vd("line",{y2:5*S,...X}),fd(t.label)?vd("text",{y:S*(D?12:18),textAnchor:D?"end":id(x?.tickAnchor,t.pixel===W.min,t.pixel===W.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:D?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):gd({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"xtick-"+e)}),j&&vd("text",{x:e.width/2,y:"top"===v?-(D?58:40):e.height+(D?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:j}),!1!==b?.baseline&&!b?.jaggedBase&&vd("line",{x1:A,y1:0,x2:A,y2:e.height,...G}),b?.jaggedBase&&vd("path",{d:cd(w,e.width,e.height),fill:"none",...G}),E.map((t,e)=>{const o=bd(b?.landmarkTicks,t,e,E);return wd("g",{transform:`translate(${A},${t.pixel})`,children:[vd("line",{x2:5*M,...G}),fd(t.label)?vd("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:rd(b?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):gd({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"ytick-"+e)}),Y&&vd("text",{x:V,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${V}, ${e.height/2})`,children:Y})]})}(y.scales,{width:u,height:d},t,o,b,i,l,!!c):null,_=S?function(t){const{scales:e,layout:o,props:n,theme:i,leftAxis:r,rightAxis:s,margin:a,axisChrome:l,hasRenderedLegend:c}=t;if(!r||!s)return null;const u=me(i),d=s.extent??n.axisExtent,h="exact"===d?Math.max(2,ud(s,5)):Math.min(ud(s,5),Math.max(2,Math.floor(o.height/30))),p=s.tickValues??hd(e.y,h,d),f=s.tickFormat||n.yFormat||n.tickFormatValue||dd,g=t=>f(t),y=xd({candidates:yd({values:p,scale:e.y,format:g}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:g}),m=sd(y),x=s.label??n.yLabelRight,b=ld(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=n.legendPosition??"right",w=Je(n.legendLayout,l?.rightAxis),k=o.width+(c&&"right"===v&&w>0?w:a.right)-15;return Wd("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&Dd("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&Dd("path",{d:cd("right",o.width,o.height),fill:"none",...b}),y.map((t,e)=>{const n=bd(s.landmarkTicks,t,e,y);return Wd("g",{transform:`translate(${o.width},${t.pixel})`,children:[Dd("line",{x2:5,...b}),fd(t.label)?Dd("text",{x:8,textAnchor:"start",dominantBaseline:rd(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}):gd({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&Dd("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:y.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:l,hasRenderedLegend:!!c}):null;let P;const L=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.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:b,onRender:t=>{P=t}}):null;e&&(e.evidence=Ba({frameType:"xy",width:n[0],height:n[1],marks:v.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:P,xDomain:Wa(y.scales.x?.domain?.()),yDomain:Wa(y.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const $=t.svgPreRenderers&&y.scales?t.svgPreRenderers.map((t,e)=>{try{return jd(ja.Fragment,{children:t(y.scene,y.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Ya.renderToStaticMarkup(Cd(Yd(Bd,{children:[m,$,w,jd("defs",{children:jd("clipPath",{id:A,children:jd("rect",{x:0,y:0,width:u,height:d})})}),jd("g",{clipPath:`url(#${A})`,children:k}),M,_,L,x,y.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:c,idPrefix:t._idPrefix}))}import*as Gd from"react";import*as Vd from"react-dom/server.browser";import{scaleBand as Hd,scaleLinear as qd}from"d3-scale";var Ud=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:ne(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||Jt,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function Kd(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 Zd(t){const e=t.getSymbol;return e?_(e,t.config.symbolMap):null}function Qd(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 Jd(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,l=-Math.PI/2+(n.startAngle||0)*Math.PI/180,c=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)}),p=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=l+u*c,f=l+(u+("number"==typeof o?._pct?o._pct:e.pct))*c,g=i(e.pieceData[0],e.name),y=0===t,m=t===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:f,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:g,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:p&&(x.roundedEnds={start:y,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as th}from"d3-array";function eh(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:th(t,.25)??o,median:th(t,.5)??(o+n)/2,q3:th(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as oh}from"d3-scale";var nh={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h="horizontal"===c,p=i.normalize,f=[];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),f.push(e))}}else f.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(p)for(const t of e.values())o+=Math.abs(t.total);let n=0,i=0;for(const r of f){const c=e.get(r);if(!c)continue;let f=c.total;p&&o>0&&(f/=o);const g=a(c.pieces[0],s?r:t.name),y={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:t.name};if(d){const e=l(0>f?i:n+f),o=0>f?l(i+f)-l(i):l(n)-l(n+f);u.push(al(t.x,e,t.width,Math.abs(o),g,y,r)),0>f?i+=f:n+=f}else if(h){const e=l(0>f?i+f:n),o=0>f?l(i)-l(i+f):l(n+f)-l(n);u.push(al(e,t.x,Math.abs(o),t.width,g,y,r)),0>f?i+=f:n+=f}}}const g="vertical"===c;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=g?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(g?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=Kd(i.roundedTop,e,g);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(g?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=Kd(i.roundedTop,t,g);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:l,projection:c}=o,u=[],d="vertical"===c,h=[],p=new Set;for(const t of Object.values(n))for(const e of t.pieceData){const t=s?s(e):"_default";p.has(t)||(p.add(t),h.push(t))}const f=h.length||1;for(const t of Object.values(n)){const e=t.width/f,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 c=i.get(h[s])||[];for(const i of c){const c=r(i),p=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(al(r,Math.min(a,d),n,Math.abs(a-d),p,i,h[s]))}else{const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(al(Math.min(a,d),r,Math.abs(d-a),n,p,i,h[s]))}}}}for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum),o=Kd(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:l}=o,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,p=Zd(t),f=2*Math.PI,g=-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),l=h&&r[o]||a,y=s(e,t.name),m=y.r||5;let x,b;if(d){const e=g+(t.pctStart+t.pct/2)*f,o=l(n);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=l(n)):(x=l(n),b=t.middle);Qd(c,p,e,x,b,m,y)}return c},swarm:function(t,e){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="vertical"===a,u=Zd(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,p=(7919*o%100/100-.5)*e*.8;Qd(l,u,n,c?t.middle+p:s(a),c?s(a):t.middle+p,h,d)}}return l},pie:Jd,donut:Jd,boxplot:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,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],l=th(o,.25)??n,h=th(o,.5)??(n+i)/2,p=th(o,.75)??i,f=p-l,g=l-1.5*f,y=p+1.5*f,m=o.find(t=>t>=g)??n,x=[...o].reverse().find(t=>y>=t)??i,b=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const o=r(t);if(g>o||o>y){const n=u?e.middle:a(o),i=u?a(o):e.middle;v.push({px:n,py:i,value:o,datum:t})}}if(c.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(l),medianPos:a(h),q3Pos:a(p),maxPos:a(x),stats:{n:o.length,min:m,q1:l,median:h,q3:p,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)c.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 c},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,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,l=Array(d).fill(0);for(const t of e)l[Math.min(Math.floor((t-o)/i),d-1)]++;const p=kt(l,1),f=t.width/2*.9;let g;if(u){g=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);g+=` L ${t.middle+l[e]/p*f} ${n}`}g+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);g+=` L ${t.middle-l[e]/p*f} ${n}`}g+=" Z"}else{g=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)g+=` L ${a(o+(e+.5)*i)} ${t.middle-l[e]/p*f}`;g+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)g+=` L ${a(o+(e+.5)*i)} ${t.middle+l[e]/p*f}`;g+=" Z"}const y=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const i=th(e,.25)??o,r=th(e,.5)??(o+n)/2,s=th(e,.75)??n;m={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const x=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};c.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:eh(e),style:y,datum:t.pieceData,category:t.name})}return c},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,p=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]=St(e),i=null!=h&&isFinite(h)?h:o,d=null!=p&&isFinite(p)?p:n,f=(d-i)/c||1,g=Array(c).fill(0);for(const t of e)i>t||t>d||g[Math.min(Math.floor((t-i)/f),c-1)]++;const y=e.length,m=kt(g,1),x=s(t.pieceData[0],t.name);for(let e=0;c>e;e++){if(0===g[e])continue;const o=(u?g[e]/y:g[e]/m)*t.width*.9,n=a(i+e*f),r=a(i+(e+1)*f);l.push(al(Math.min(n,r),t.x+t.width-o,Math.abs(r-n),o,x,{bin:e,count:g[e],range:[i+e*f,i+(e+1)*f],category:t.name},t.name))}}return l},ridgeline:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u=i.bins||20,d="horizontal"===l,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,l=Array(u).fill(0);for(const t of e)o>t||t>n||l[Math.min(Math.floor((t-o)/i),u-1)]++;const p=kt(l,1),f=s(t.pieceData[0],t.name),g=t.width*h;let y;if(d){const e=t.x+t.width;y=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)y+=` L ${a(o+(t+.5)*i)} ${e-l[t]/p*g}`;y+=` L ${a(n)} ${e} Z`}else{const e=t.x;y=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const n=a(o+(t+.5)*i);y+=` L ${e+l[t]/p*g} ${n}`}y+=` L ${e} ${a(n)} Z`}const m=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))};c.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:m,stats:eh(e),style:{...f,fillOpacity:f.fillOpacity??.5},datum:t.pieceData,category:t.name})}return c},timeline:function(t,e){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="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(c){const o=s(Math.min(n,a)),i=s(Math.max(n,a));l.push(al(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));l.push(al(t.x,o,t.width,i-o,u,e,t.name))}}return l},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,l=!1!==t.config.showLabels,c=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const t of c)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],p=[];let f=0;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}p.push({col:t,groups:e,stepTotal:o}),h||o>f&&(f=o)}if(h)for(const t of p){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>f&&(f=n)}if(0===f)return s;const g=new Map;for(const t of u){const e=p[0].groups.get(t);g.set(t,e?.total??0)}const y=p[0].stepTotal,m=h?.95*a:.9*e.width,x=oh().domain([0,f]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;p.length>e;e++){const o=p[e],n=o.col,i=0===e,c=n.width,d=.55*c,f=n.x+(c-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,c=a;for(let h=0;u.length>h;h++){const p=u[h],y=o.groups.get(p);if(!y)continue;const b=x(y.total),v=h%2==0,w=v?e:c-b;v?e+=b:c-=b;const k=r(y.pieces[0],p),A=g.get(p)??y.total,S={...y.pieces[0],__funnelValue:y.total,__funnelPercent:A>0?y.total/A*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:p};l&&(0===h&&(S.__funnelStepLabel=n.name,S.__funnelStepLabelX=a,S.__funnelStepLabelY=f,S.__funnelRowWidth=t),S.__funnelValueLabelX=w+b/2,S.__funnelValueLabelY=f,S.__funnelBarW=b),s.push(al(w,f,b,d,k,S,p)),m.set(p,{x:w,y:f,w:b,h:d})}}else{const t=o.stepTotal,e=x(t),c=a-e/2,h=u[0],p="_default"!==h,g=o.groups.get(h)?.pieces[0]??n.pieceData[0],b=p?h:n.name,v=r(g,b),w=y>0?t/y*100:0,k={...g,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:p?h:n.name};l&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=f,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=f,k.__funnelBarW=e),s.push(al(c,f,e,d,v,k,b)),m.set(h,{x:c,y:f,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 l=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),c={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:l.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:l.cursor},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],l=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),c.push(t))}const d=c.length>1&&"_default"!==c[0],h=[];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}h.push({col:t,groups:e,stepTotal:o})}const p=new Map;for(const t of c){const e=h[0]?.groups.get(t);p.set(t,e?.total??0)}const f=s.r,g=d?c.length:1,y=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/g,l=s*y,u=s-l;for(let t=0;c.length>t;t++){const h=c[t],g=e.groups.get(h);if(!g)continue;const y=g.total,m=p.get(h)??y,x=m>0?y/m*100:0,b=i?.groups.get(h),v=n?0:Math.max(0,(b?.total??y)-y),w=o.x+t*s+l/2,k=f(y),A=f(0)-k,S=r(g.pieces[0],d?h:o.name),M={...g.pieces[0],__barFunnelValue:y,__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:f(y+v)};if(a.push(al(w,k,u,A,S,M,d?h:o.name)),v>0){const t=f(y+v),e=k-t,n={...S},i={...g.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(al(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:l}=o,c=[],u="horizontal"===l,d=t.config.gradientFill,h=u?"left":"bottom",p=new Map,f=e=>{const o=p.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 p.set(e,i),i},g=t.config.trackFill;if(g){const t="string"==typeof g?g:g.color,e="string"==typeof g?1:g.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?al(r,o.x,s,o.width,n,null,"__track__"):al(o.x,r,o.width,s,n,null,"__track__"),a=f(o);a>0&&(i.cornerRadii={tl:a,tr:a,br:a,bl:a}),c.push(i)}}for(const t of Object.values(n)){let e=0;const o=c.length,n=f(t);for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const l=r?r(o):t.name,p=s(o,l);let f;if(u){const i=a(e),r=a(e+n);f=al(i,t.x,r-i,t.width,p,o,l)}else{const i=a(e+n),r=a(e);f=al(t.x,i,t.width,r-i,p,o,l)}d&&(f.fillGradient=d,f.roundedEdge=h),c.push(f),e+=n}if(n>0&&c.length>o){const t=c.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 c}},ih=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],rh=["scene-style","data-paint","accessibility","evidence"],sh=(t,e)=>({retainedData:t,invalidations:e}),ah=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],lh=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ch=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],uh=["scene-geometry","data-paint","accessibility","evidence"],dh=["scene-style","data-paint","accessibility","evidence"],hh=[],ph={chartType:sh("rebuild",ah),runtimeMode:sh("rebuild",ah),categoryAccessor:sh("rebuild",ah),valueAccessor:sh("rebuild",ah),oAccessor:sh("rebuild",ah),rAccessor:sh("rebuild",ah),stackBy:sh("rebuild",ah),groupBy:sh("rebuild",ah),timeAccessor:sh("rebuild",ah),accessorRevision:sh("rebuild",ah),colorAccessor:sh("rebuild",dh),symbolAccessor:sh("rebuild",uh),connectorAccessor:sh("rebuild",uh),dataIdAccessor:sh("rebuild",uh),projection:sh("preserve",lh),extentPadding:sh("preserve",lh),axisExtent:sh("preserve",lh),rExtent:sh("preserve",lh),oExtent:sh("preserve",lh),multiAxis:sh("preserve",lh),normalize:sh("preserve",lh),bins:sh("preserve",lh),oSort:sh("preserve",ch),barPadding:sh("preserve",ch),roundedTop:sh("preserve",ch),baselinePadding:sh("preserve",ch),innerRadius:sh("preserve",ch),cornerRadius:sh("preserve",ch),startAngle:sh("preserve",ch),sweepAngle:sh("preserve",ch),trackFill:sh("preserve",ch),showOutliers:sh("preserve",ch),showIQR:sh("preserve",ch),amplitude:sh("preserve",ch),connectorOpacity:sh("preserve",ch),showLabels:sh("preserve",ch),dynamicColumnWidth:sh("rebuild",ch),customLayout:sh("preserve",ch),layoutConfig:sh("preserve",ch),layoutMargin:sh("preserve",ch),symbolMap:sh("preserve",uh),pieceStyle:sh("preserve",dh),summaryStyle:sh("preserve",dh),connectorStyle:sh("preserve",dh),gradientFill:sh("preserve",dh),colorScheme:sh("preserve",dh),themeCategorical:sh("preserve",dh),themeSemantic:sh("preserve",dh),themeSequential:sh("preserve",dh),themeDiverging:sh("preserve",dh),barColors:sh("preserve",dh),decay:sh("preserve",dh),pulse:sh("preserve",dh),staleness:sh("preserve",dh),layoutSelection:sh("preserve",dh),windowSize:sh("preserve",hh),windowMode:sh("preserve",hh),clock:sh("preserve",hh),transition:sh("preserve",hh),introAnimation:sh("preserve",hh),onLayoutError:sh("preserve",hh)},fh=sh("preserve",ch),gh=class{constructor(){this.tracker=new o}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}},ih)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},rh):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=ph[n]??fh;"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 yh}from"d3-quadtree";var mh=class{constructor(t){this.rExtent=new q,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new gh,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Ud,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 U(t.windowSize),this.getO=wt(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>mt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new q)):(this.getR=mt(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=wt(t.stackBy),this.getGroup=wt(t.groupBy),this.getColor=wt(t.colorAccessor),this.getSymbol=wt(t.symbolAccessor),this.getConnector=wt(t.connectorAccessor),this.getDataId=wt(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new U(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:Il(e,n):null)}currentTime(){return this.config.clock?.()??qa()}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(),Ol(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)zl(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=zl(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",l=e.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),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 p,f;if(d){p=Hd().domain(l).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;f=qd().domain(c).range([n,o])}else u?(p=Hd().domain(l).range([0,t.height]).padding(h),f=qd().domain(c).range([0,t.width])):(p=Hd().domain(l).range([0,t.width]).padding(h),f=qd().domain(c).range([t.height,0]));this.scales={o:p,r:f,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 l=a-s,c=l>0?l*(e.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?qd().domain([s,a]).range([0,t.width]):qd().domain([s,a]).range([t.height,0])}):[];let g=s;this.rAccessors.length>1&&(g=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(g,l,p,a,t),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(g,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=y,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:l,getO:c,getR:u,getStack:d,rawRExtent:h}=t,p=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let f=0,g=0;if("bar"===o&&d&&i)f=0,g=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=c(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>g&&(g=e);for(const t of o.values())f>t&&(f=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=c(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e),f>e&&(f=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=c(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>g&&(g=e),f>e&&(f=e)}else{const t=h[0],e=h[1];t!==1/0&&(f=t),e!==-1/0&&(g=e)}r&&(null!=r[0]&&(f=r[0]),null!=r[1]&&(g=r[1]));const y="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(y&&null==r?.[0]&&null==r?.[1]&&(f>0&&(f=0),0>g&&(g=0)),"bar-funnel"!==o&&"exact"!==l){const t=g-f,e=t>0?t*p:1,n=y&&!a&&0===f,i=y&&!a&&0===g||"swimlane"===o;null!=r?.[0]||n||(f-=e),null!=r?.[1]||i||(g+=e)}return[f,g]}({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:l}=t,c=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(l(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 p=0,f=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(l(e)),0),i=d>0?o/d:0;let r,s;h?(r=f,s=h.get(t)||n.bandwidth(),f+=s+n.padding()*n.step()):(r=n(t)??0,s=n.bandwidth()),c[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:e,pct:i,pctStart:p},p+=i}return c}({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);let n;try{n=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=Sl("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=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;const i=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of i)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(i,this.config.layoutSelection??null)}return wl({label:"ordinal customLayout",nodes:i,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),i}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),n=nh[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,l=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)),l.has(o)||l.set(o,[]),l.get(o).push({x:n,y:s,datum:e,category:r(e)})}const c=o.o.domain(),u=n.connectorStyle;for(const[e,o]of l)if(o.length>=2){o.sort((t,e)=>c.indexOf(t.category)-c.indexOf(e.category));for(let n=0;o.length-1>n;n++){const i=o[n],r=o[n+1],a="function"==typeof u?u(i.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:i.x,y1:i.y,x2:r.x,y2:r.y,style:a,datum:i.datum,group:e})}}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=Rr(o.colorScheme,o.themeCategorical,Jt),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:Cr(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Ua(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=Ka(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],l=i.get(a);l?l.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:yh().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 l=!1;for(const c of e){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const e=c.category;if(!e)continue;let n=0;for(const s of i(e)??[]){const e=o.get(s);null!=e&&(n=Math.max(n,Za(t,e,r)))}l=Qa(c,n,s)||l;continue}if(null==c.datum)continue;const e=n.get(c.datum);if(null==e)continue;const u=o.get(e);l=Qa(c,null==u?0:Za(t,u,r),s,a)||l}return l}(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&&Ja(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=Va(t,this.activeTransition),o=Ga(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=Ha(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Ha(n.x,t._targetX,o),t.y=Ha(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Ha(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Ha(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=Ha(n.x,t._targetX,o),t.y=Ha(n.y,t._targetY,o),void 0!==n.w&&(t.w=Ha(n.w,t._targetW,o),t.h=Ha(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:Ha(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=Ha(n.startAngle,t._targetStartAngle,o),t.endAngle=Ha(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=Xa(t),o=this.getDataId,n=t=>e.has(o(t));Fl(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=Xa(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&&!yt(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!yt(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!yt(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)&&(yt(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=wt(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)=>!yt(t,r[e])),i){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>mt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new q)):(this.getR=mt(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!yt(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?wt(this.config.stackBy):void 0),"groupBy"in t&&!yt(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?wt(this.config.groupBy):void 0),"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?wt(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!yt(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?wt(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!yt(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?wt(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}};Xl(mh);import*as xh from"react";import{jsx as bh,jsxs as vh}from"react/jsx-runtime";function wh(t){return"connector"===t.node.type}function kh(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=yc(`${e?e+"-":""}connector-${o}-${n}-hatch`),a=ot(r)?et(r,s):null,l=[`${i.x1},${i.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return Ac(vh(xh.Fragment,{children:[a&&bh("defs",{children:a}),bh("polygon",{points:l,fill:a?`url(#${s})`:gc(r,"#999"),opacity:i.style.fillOpacity??i.style.opacity??.3,"data-semiotic-connector-fill":i.group||"_default"})]}),i,`ordinal-connector-fill-${o}-${n}`)}function Ah(t,e,o){const n=new Map;for(const e of t){if(!wh(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)=>vh("g",{children:[kh(t,e,o,n),t.map(t=>t.element)]},`ordinal-connectors-${o}-${n}`)),r=t[0],s=wh(r)?null:r.element;for(const t of n.values())for(const e of t)e.element=null;r.element=vh(xh.Fragment,{children:[i,s]},"ordinal-connector-run-"+o)}function Sh(t){const e=Vc({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>Dc(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++;Ah(e.slice(n,i),t.idPrefix,o++),n=i}return e}import{jsx as Mh,jsxs as _h}from"react/jsx-runtime";import{Fragment as Ph,jsx as Lh,jsxs as $h}from"react/jsx-runtime";var Rh=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function Ch(t,e){const o=ye(t.theme),n=t.size||[500,400],i=qe({...zd,...t.margin},t.title),r=Ve(t.title),s=Ht(t.data),a=t.showLegend?iu(s,t.colorAccessor||t.stackBy||t.groupBy):[],l=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)});Ld(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=$d({props:{...t,axisChrome:l},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",p="radial"===h,f=t.colorScheme||o.colors.categorical,g={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:ce(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:f,themeCategorical:o.colors.categorical,themeSemantic:Rt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},y=new mh(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Id(t.backgroundGraphics,n,i,y.scales),x=Id(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?td({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=Ba({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Vd.renderToStaticMarkup(Cd(m||x||t.annotations?$h(Ph,{children:[m,a,x,y.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:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=me(o),a=n?n+"-":"",l="vertical"===r.projection,c=hd(r.r,5,i);return vd("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return vd("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:c.map((t,o)=>{const n=r.r(t);return vd("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(y,{width:u,height:d},o,b,t.axisExtent):null;let w=null;if(y.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=Ad(t),n=new Set;for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");w=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 _h("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Mh("rect",{width:a,height:a,fill:o}),Mh("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Mh("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 y.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 k=Sh({nodes:y.scene,renderMode:t.renderMode,idPrefix:b}),A=k.map(t=>t.element),S=!1!==t.showAxes?function(t,e,o,n,i,r,s,a=!1){const l=t.scales;if(!l)return null;if("radial"===l.projection)return null;const c=me(n),u="vertical"===l.projection,d=t.columns,h=o.categoryFormat||o.oFormat,p=o.valueFormat||o.rFormat,f=o.categoryLabel||o.oLabel,g=o.valueLabel||o.rLabel,y=o.legendPosition??"right",m=Je(o.legendLayout,s?.leftAxis),x=a&&"left"===y&&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=hd(l.r,5,o.axisExtent).map(t=>({pixel:l.r(t),label:(p||Rd)(t)}));return $h("g",u?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Lh("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,o)=>$h("g",{transform:`translate(${t.pixel},${e.height})`,children:[Lh("line",{y2:5,stroke:c.border,strokeWidth:1}),fd(t.label)?Lh("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):gd({label:t.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oxtick-"+o)),f&&Lh("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:f}),Lh("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,e)=>$h("g",{transform:`translate(0,${t.pixel})`,children:[Lh("line",{x2:-5,stroke:c.border,strokeWidth:1}),Lh("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oytick-"+e)),g&&Lh("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:g})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Lh("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,o)=>$h("g",{transform:`translate(${t.pixel},${e.height})`,children:[Lh("line",{y2:5,stroke:c.border,strokeWidth:1}),Lh("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oxtick-"+o)),g&&Lh("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),Lh("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,e)=>$h("g",{transform:`translate(0,${t.pixel})`,children:[Lh("line",{x2:-5,stroke:c.border,strokeWidth:1}),fd(t.label)?Lh("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):gd({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oytick-"+e)),f&&Lh("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:f})]})}(y,{width:u,height:d},t,o,b,i,l,!!c):null;let M;const _=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.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:b,onRender:t=>{M=t}}):null;if(e){const o=y.scales.o?.domain?.();e.evidence=Ba({frameType:"ordinal",width:n[0],height:n[1],marks:k.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:M,yDomain:Wa(y.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const P=p&&t.centerContent?function(t,e,o){if(!Gd.isValidElement(t))return null;if("string"!=typeof t.type||!Rh.has(t.type))return null;const n=t,i="text"===n.type?Gd.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return Lh("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,L=p&&t.centerContent?P??Lh("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:Lh("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,$=$h(Ph,{children:[v,A,S,_,x,y.customLayoutOverlays]});return Vd.renderToStaticMarkup(Cd($h(Ph,p?{children:[m?Lh("g",{transform:`translate(${-u/2},${-d/2})`,children:m}):null,$]}:{children:[m,$]}),{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:p?`translate(${i.left+u/2},${i.top+d/2})`:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,defs:w,outerElements:L,idPrefix:t._idPrefix}))}import*as Th from"react-dom/server.browser";function Oh(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function Ih(t,e){var o,n=[],i=[],r=[],s={},a=[];function l(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&l(e)})}function c(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=c(n));if(d)l(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),l=0;e>l;++l)o[l]=-1,n[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function p(e){var l=[e],c=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;c.length>0;){var p=t[e=c[c.length-1]];if(p.length>r[e]){for(var f=r[e];p.length>f;++f){var g=p[f];if(0>o[g]){o[g]=n[g]=u,i[g]=!0,u+=1,l.push(g),c.push(g);break}i[g]&&(n[e]=0|Math.min(n[e],n[g])),0>s[g]||a[e].push(s[g])}r[e]=f}else{if(n[e]===o[e]){var y=[],m=[],x=0;for(f=l.length-1;f>=0;--f){var b=l[f];if(i[b]=!1,y.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){l.length=f;break}}d.push(y);var v=Array(x);for(f=0;m.length>f;f++)for(var w=0;m[f].length>w;w++)v[--x]=m[f][w];h.push(v)}c.pop()}}}for(l=0;e>l;++l)0>o[l]&&p(l);for(l=0;h.length>l;l++){var f=h[l];if(0!==f.length){f.sort(function(t,e){return t-e}),c=[f[0]];for(var g=1;f.length>g;g++)f[g]!==f[g-1]&&c.push(f[g]);h[l]=c}}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 l=i[o];return!!l&&{leastVertex:r,adjList:t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var p=d(o);if(o=p.leastVertex,a=p.adjList){for(var f=0;a.length>f;f++)for(var g=0;a[f].length>g;g++){var y=a[f][g];r[+y]=!1,s[y]={}}c(o),o+=1}else o=h}return e?void 0:n}function zh(t){return t.y0-t.y1>0?"up":"down"}function Fh(t,e){return e(t.source)==e(t.target)}function Nh(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 Eh(t){return t.target.x0-t.source.x1}function Dh(t,e){var o=Bh(t),n=Eh(e)/Math.tan(o);return"up"==zh(t)?t.y1-n:t.y1+n}function Wh(t,e){var o=Bh(t),n=Eh(e)/Math.tan(o);return"up"==zh(t)?t.y1+n:t.y1-n}function Bh(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function jh(t,e){return e(t)}function Yh(t){return Gh(t.source)}function Xh(t){return Gh(t.target)}function Gh(t){return(t.y0+t.y1)/2}function Vh(t){return t.virtual?0:t.value}function Hh(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!Fh(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!Fh(t,e)?n+1:n}),o+n}function qh(t){return t.target.depth}function Uh(t,e){return t.sourceLinks.length?t.depth:e-1}function Kh(t,e){return t.y0-e.y0}function Zh(t,e){return e.y0-t.y0}function Qh(t,e){return t.y1-e.y1}function Jh(t,e){return e.y1-t.y1}function tp(t,e){return op(t.source,e.source)||t.index-e.index}function ep(t,e){return op(t.target,e.target)||t.index-e.index}function op(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function np(t,e){return ip(t)==ip(e)?"bottom"==t.circularLinkType?Zh(t,e):Kh(t,e):ip(e)-ip(t)}function ip(t){return t.target.column-t.source.column}function rp(t,e){return sp(t)==sp(e)}function sp(t){return t.y0-t.y1>0?"up":"down"}import{min as ap}from"d3-array";function lp(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=ap(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var l=r.links.filter(function(t){return t.circular});return l.sort(function(t,e){return e.value-t.value}),l.forEach(function(t,e){t._circularStub=e>=4}),cp(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),cp(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,Fh(t,e)&&Nh(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,l=t.circularLinkType,c=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==l});c.sort("bottom"==t.circularLinkType?Zh:Kh);var u=0;c.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,(c=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==l})).sort("bottom"==t.circularLinkType?Jh:Qh),u=0,c.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 cp(t,e,o){t.sort(np);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(Fh(t,e)&&Nh(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&&up(t,a)){var l=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=l>r?l:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function up(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as dp,max as hp,sum as pp,mean as fp,group as gp,groups as yp}from"d3-array";function mp(t){return function(){return t}}function xp(t){return t.index}function bp(t){return t.nodes}function vp(t){return t.links}function wp(t,e,o){var n=yp(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+=Gh(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Gh(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?Hh(e,o)-Hh(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==Hh(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 kp(t,e,o,n,i,r){var s=yp(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,l=r;l>0;--l)c(a*=.99,o),u();function c(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&&Hh(i,o)>0){var l=fp(i.sourceLinks,Xh),c=fp(i.targetLinks,Yh),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-Gh(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=fp(i.sourceLinks,Xh),p=fp(i.targetLinks,Yh),f=((h&&p?(h+p)/2:h||p)-Gh(i))*e;i.y0+=f,i.y1+=f}})})}function u(){s.forEach(function(o){var r,s,a,l=t.y0,c=o.length;for(o.sort(e||op),a=0;c>a;++a)(s=l-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),l=r.y1+n;if((s=l-n-t.y1)>0)for(l=r.y0-=s,r.y1-=s,a=c-2;a>=0;--a)(s=(r=o[a]).y1+i-l)>0&&(r.y0-=s,r.y1-=s),l=r.y0})}}function Ap(t){t.nodes.forEach(function(t){t.sourceLinks.sort(ep),t.targetLinks.sort(tp)}),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 Sp(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=xp,l=Uh,c=void 0,u=32,d=2,h=bp,p=vp;function f(){var f={nodes:h.apply(null,arguments),links:p.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 gp(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=Oh(o,n)),"object"!=typeof i&&(i=t.target=Oh(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 l=Ih(n);l.sort(function(t,e){return t.length-e.length});var c={};for(i=0;l.length>i;i++){var u=l[i].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||c[n]&&c[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,c),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){jh(t,e)!=jh(i.source,e)&&jh(t,e)!=jh(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),Fh(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(pp(t.sourceLinks,Vh),pp(t.targetLinks,Vh)),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,c,l);var p=r;if(null!==s){var f=yp(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),g=hp(f,function(t){return t.length});g>1&&(p=Math.max(1,(n-e)*s/(g-1)))}(function(t,e,o){var n=yp(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=dp(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/pp(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=hp(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,p,i),wp(h,c,a),kp(h,c,a,p,p,u),Ap(h),lp(h,a,d,10,8),wp(h,c,a),kp(h,c,a,p,p,u),Ap(h),lp(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 jh(o.source,e)==jh(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(!rp(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=Dh(e,t);return t.y1-o}if(e.target.column>t.target.column)return Dh(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 jh(o.target,e)==jh(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(!rp(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=Wh(e,t);return t.y0-o}if(e.source.column>t.source.column)return Wh(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=dp(e,function(t){return t.y0}),s=hp(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),lp(h,a,d,10,8)}(f),f}return f.update=function(t){return Ap(t),lp(t,a,d,10,8),t},f.nodeWidth=function(t){return arguments.length?(i=+t,f):i},f.nodePadding=function(t){return arguments.length?(r=+t,f):r},f.nodePaddingRatio=function(t){return arguments.length?(s=+t,f):s},f.nodes=function(t){return arguments.length?(h="function"==typeof t?t:mp(t),f):h},f.links=function(t){return arguments.length?(p="function"==typeof t?t:mp(t),f):p},f.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:mp(t),f):a},f.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:mp(t),f):l},f.nodeSort=function(t){return arguments.length?(c=t,f):c},f.iterations=function(t){return arguments.length?(u=+t,f):u},f.circularLinkGap=function(t){return arguments.length?(d=+t,f):d},f.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],o=+i[1][0],n=+i[1][1],f):[[t,e],[o,n]]},f.size=function(i){return arguments.length?(t=e=0,o=+i[0],n=+i[1],f):[o-t,n-e]},f}import{interpolateNumber as Mp}from"d3-interpolate";import{line as _p,curveLinearClosed as Pp}from"d3-shape";var Lp=t=>{let e,o,n,i,r,s,a,l,c;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=Mp(r,s),l=a(.5),c=a(.5),`M${e},${r}C${e},${l} ${o},${c} ${o},${s}L${n},${s}C${n},${c} ${i},${l} ${i},${r}Z`;const u=t.sankeyWidth/2,d=Mp(t.source.x1,t.target.x0),{pathD:h}=Si({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 $p(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))),l=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-l},${s-e}L${r-l},${s+e}L${r},${s+e}Z`}const i=n.sourceX,r=n.sourceY,s=n.targetX,a=n.targetY,l=n.rightFullExtent,c=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${l},${r-d*e}L${l+o},${r-d*e+d*h}L${l+o},${u+d*o-d*h}L${l+o-h},${u+d*o}L${c-o+h},${u+d*o}L${c-o},${u+d*o-d*h}L${c-o},${a-d*e+d*h}L${c-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${c+o},${a+d*e}L${c+o},${u-d*o}L${l-o},${u-d*o}L${l-o},${r+d*e}L${i},${r+d*e}Z`}var Rp={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(qh))-1:0},justify:Uh},Cp={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,l=o.iterations??100,c=t.map(t=>({...t})),u=e.map(t=>({...t,source:bt(t.source),target:bt(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=Sp().extent(d).links(u).nodes(c).nodeAlign(Rp[r]||Uh).nodeId(t=>t.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of c)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],l=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>l)){const e=Math.min(a/r,l/s),n=-t*e+(a-r*e)/2,i=-o*e+(l-s*e)/2;for(const t of c)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 p=new Map;for(const e of t)p.set(e.id,e);for(const t of c){const e=p.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 f=new Map;for(const t of e)if(t._edgeKey)f.set(t._edgeKey,t);else{const e=bt(t.source),o=bt(t.target);f.set(`${e}\0${o}`,t)}for(const t of u){const e=bt(t.source),o=bt(t.target),n=f.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=p.get(e),s=p.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,l=o.edgeColorBy||"source",c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:B,u=new Map;t.forEach((t,e)=>{u.set(t.id,c[e%c.length])});const d=[],h=[],p=[],f=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(H(e,"nodeStyle")):{},s={fill:n.fill||u.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity,cursor:n.cursor};f.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 g=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of g){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 l?l(t)||i:"target"===l?f.get(n.id)||u.get(n.id)||i:f.get(e.id)||u.get(e.id)||i;const r=s?s(H(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))),l=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:l,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:l,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 c;(c=t.circular&&t.circularPathData?$p(t):Lp(t),c)&&h.push({type:"bezier",pathD:c,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=xt(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,l,c;"down"===i?(a=o.y0+(o.y1-o.y0)/2,l=o.x1+14,c="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,c="end"):(a=o.x1+6,c="start"),l=o.y0+r/2),p.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:p}}};import{chord as Tp,ribbon as Op}from"d3-chord";import{arc as Ip}from"d3-shape";var zp=B,Fp={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,l=a-r,c=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 p=new Map;for(let e=0;t.length>e;e++)p.set(t[e].id,e);const f=t.length,g=Array.from({length:f},()=>Array.from({length:f},()=>0));for(const t of e){const e=bt(t.source),o=bt(t.target),n=p.get(e),i=p.get(o);if(void 0===n||void 0===i)continue;const r=d(t);g[n][i]=r}const y=Tp().padAngle(i);s&&y.sortGroups(s);const m=y(g),x=m.groups,b=Ip().innerRadius(l).outerRadius(a);for(const e of x){const o=t[e.index],n=b.centroid({innerRadius:l,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=n[0]+c,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=bt(t.source),o=bt(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=bt(t.source),o=bt(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,l=n[0]/2,c=n[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",p=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:zp,f=new Map;t.forEach((t,e)=>{f.set(t.id,p[e%p.length])});const g=Op().radius(a),y=[],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(H(o,"nodeStyle"));i=("string"==typeof t.fill?t.fill:void 0)||f.get(o.id)||p[e%p.length]}else i=f.get(o.id)||p[e%p.length];const r=u?u(H(o,"nodeStyle")):{};y.push({type:"arc",cx:l,cy:c,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=g(e);if(!n)continue;const i=Np(n,l,c);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(H(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=f.get(o.id)||s:e&&(s=f.get(e.id)||s)}const a=d?d(H(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=xt(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:l+Math.cos(s)*n,y:c+Math.sin(s)*n,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:y,sceneEdges:m,labels:x}}};function Np(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(" ")}import{hierarchy as Ep,tree as Dp,cluster as Wp,treemap as Bp,pack as jp,partition as Yp,treemapBinary as Xp}from"d3-hierarchy";var Gp=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Vp(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 Hp(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 qp(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 Up(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Gp}function Kp(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 Zp(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 Qp={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,l="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,c=Ep(i,s);c.sum(l),c.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=Dp();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"cluster":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=Wp();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"treemap":!function(t,e,o,n){const i=e.padding??4,r=e.paddingTop??0,s=Bp().size([o,n]).tile(Xp).padding(i);r>0&&s.paddingTop(r),s(t)}(c,o,u,d);break;case"circlepack":!function(t,e,o,n){const i=e.padding??4;jp().size([o,n]).padding(i)(t)}(c,o,u,d);break;case"partition":!function(t,e,o,n){Yp().size([o,n]).padding(e.padding??1)(t)}(c,o,u,d)}const h=c.descendants();t.length=0,e.length=0;const p=new Map;for(let e=0;h.length>e;e++){const n=h[e],i={id:Hp(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?Jp(i,n,o):"treemap"===r||"partition"===r?tf(i,n):"circlepack"===r&&ef(i,n),i.__hierarchyNode=n,t.push(i),p.set(n,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=p.get(t.parent),n=p.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=[],l=[],c=o.treeOrientation||"vertical",u="radial"===c,d=n[0]/2,h=n[1]/2,p="number"==typeof(f=o.nodeSize)?f:5;var f;for(const e of t){let t=e.x,n=e.y;u&&(t+=d,n+=h);const r=i(H(e,"nodeStyle"));let a=r.fill||Kp(o);if(o.colorByDepth&&void 0!==e.depth){const t=Up(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:n,r:p,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 g=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,l=n.x,p=n.y;u&&(i+=d,s+=h,l+=d,p+=h);const f=Zp(i,s,l,p,c),y=r(H(t,"edgeStyle"));a.push({type:"curved",pathD:f,style:{fill:"none",stroke:y.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??g,cursor:y.cursor},datum:t})}if(!1!==o.showLabels){const e=qp(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"===c?(o.data?.children&&0!==o.data.children.length?(n=s-p-6,r="end"):(n=s+p+6,r="start"),i=a):(n=s,i=a+p+14,r="middle");l.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(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(H(o,"nodeStyle"));let a=s.fill||Kp(e);if(e.colorByDepth&&void 0!==o.depth){const t=Up(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=qp(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,l=a.y1-a.y0;if(0>=t||0>=l)continue;const c=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!c)continue;if("parent"===i&&c)continue}const u=o?o(a):a.id;if(!u)continue;if((c?30:40)>t||(c?16:14)>l)continue;let d=n(H(a,"nodeStyle")).fill||Kp(e);if(e.colorByDepth&&void 0!==a.depth){const t=Up(e);d=t[a.depth%t.length]}const h="string"==typeof d?Vp(d):e.themeSemantic?.text??"#000";r.push(c?{x:a.x0+t/2,y:a.y0+l/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,l)/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(H(o,"nodeStyle"));let s=r.fill||Kp(e);if(e.colorByDepth&&void 0!==o.depth){const t=Up(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=qp(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 l=n(H(i,"nodeStyle")).fill||Kp(e);if(e.colorByDepth&&void 0!==i.depth){const t=Up(e);l=t[i.depth%t.length]}if(a){const o="string"==typeof l?Vp(l):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 Jp(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 tf(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 ef(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 of}from"d3-shape";function nf(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var rf={sankey:Cp,force:d,chord:Fp,tree:Qp,cluster:Qp,treemap:Qp,circlepack:Qp,partition:Qp,orbit:{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),l=o.orbitSize??2.95,c=o.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=nf(o);h.metaMap.clear(),n.length=0,i.length=0;const p=new Map;function f(t){const e=p.get(t)??0;return p.set(t,e+1),0===e?t:`${t}__${e}`}const g=e[0]/2,y=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=f(s(t));n.push({id:x,x:g,y:y,x0:g,x1:g,y0:y,y1:y,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,l,c,p,g,y){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:g,data:e,parentId:o},M=y?p/u(S)*A:p*A,_=of().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=f(s(a)),d=l+M*Math.sin(r),p=c+M*Math.cos(r)*P;n.push({id:u,x:d,y:p,x0:d,x1:d,y0:p,y1:p,width:0,height:0,value:0,depth:g,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:g,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,p,M,g+1,!0)}k+=v}}(t,x,g,y,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,l=[],c=[],u=[];if(!1!==o.orbitShowRings){const e=nf(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,l=(i+1)/r*Math.PI*2;c.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(l),y2:e+o*Math.cos(l)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(H(e,"nodeSize")),n=i?i(H(e,"nodeStyle")):{};l.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(H(t,"edgeStyle")):{};c.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(H(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:l,sceneEdges:c,labels:u}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=nf(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 l=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(l),e.y=n.y+t.ring*Math.cos(l)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)}};function sf(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function af(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=f(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,G(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function lf(t){if(!t)return;const e=[];for(const o of t){const t=af(o);t&&e.push({pointId:sf(o),...t})}return e}import{Fragment as cf,jsxs as uf}from"react/jsx-runtime";function df(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var hf=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function pf(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 ff(t,e){const o=ye(t.theme),n=t.chartType||"force",i=t.size||[500,500],r=function(t){return Ed.has(t)?Nd:Fd}(n),s=qe({...r,...t.margin},t.title),a=Ve(t.title),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const n=Ht(t.nodes||[]);if(n.length>0)return iu(n,e);const i=Array.isArray(t.edges)?Ht(t.edges):[];if(0===i.length)return[];const r=df(t.sourceAccessor,"source"),s=df(t.targetAccessor,"target");return iu(Array.from(new Set(i.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];Ld(s,{props:t,categories:l,theme:o,size:i,hasTitle:a});const c=$d({props:t,categories:l,theme:o,size:i,margin:s,hasTitle:a}),u=i[0]-s.left-s.right,d=i[1]-s.top-s.bottom,h=Id(t.backgroundGraphics,i,s,null),p=Id(t.foregroundGraphics,i,s,null),f=()=>{let n;const r=t=>Number(t),a=t.annotations?td({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=>Ba({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)),Th.renderToStaticMarkup(Cd(h||p||t.annotations?uf(cf,{children:[h,a,p]}):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:c,idPrefix:t._idPrefix}))},g=function(t){return rf[t]}(n);if(!g&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const y={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 m,x;if(hf.has(n)){const e=t.data||t.edges;if(!e||Array.isArray(e))return f();y.__hierarchyRoot=e,m=[],x=[]}else{const e=Ht(t.nodes||[]),o=Array.isArray(t.edges)?Ht(t.edges):[];if(0===e.length&&0===o.length)return f();if(x=function(t,e){const o=df(e.sourceAccessor,"source"),n=df(e.targetAccessor,"target"),i=df(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,y),0===e.length&&x.length>0){const t=new Set;for(const e of x){const o=kd(e.source),n=kd(e.target);o&&t.add(o),n&&t.add(n)}m=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 m=function(t,e){const o=df(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,y)}let b=[],v=[],w=[],k=null;if(y.customNetworkLayout){const t=y.colorScheme,e=Rr(t,o.colors.categorical,B),n=Cr(e,t),i={nodes:m,edges:x,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:y.layoutConfig??{}},r=y.customNetworkLayout(i);b=r.sceneNodes??[],v=r.sceneEdges??[],w=r.labels??[],k=r.overlays??null}else if(g){g.computeLayout(m,x,y,[u,d]);const t=g.buildScene(m,x,y,[u,d]);b=t.sceneNodes,v=t.sceneEdges,w=t.labels}const A=me(o);for(const t of w)t.fill||(t.fill=A.text);const S=Vc({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"line":return _c("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=ot(o.style.fill)?et(o.style.fill,n):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:o.pathD,fill:i?`url(#${n})`:gc(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=ot(o.style.fill)?et(o.style.fill,n):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:o.pathD,fill:i?`url(#${n})`:gc(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 _c("path",{d:o.pathD,fill:gc(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)}),M=Vc({nodes:b,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"circle":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`net-circle-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[n&&_c("defs",{children:n}),_c("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:gc(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=ot(o.style.fill)?et(o.style.fill,`net-rect-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[n&&_c("defs",{children:n}),_c("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:gc(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=Mc().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(fc)||"",i=ot(o.style.fill)?et(o.style.fill,`net-arc-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:gc(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=X(o.symbolType,o.size,o.path);return _c("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?gc(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 mc(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),_=S.map(t=>t.element),P=M.map(t=>t.element),L=w.map((t,e)=>function(t,e){return _c("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 $;const R=t=>Number(t),C=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:R,y:R},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:pf(b),pointNodes:lf(b),idPrefix:t._idPrefix,onRender:t=>{$=t}}):null;return e&&(e.evidence=Ba({frameType:"network",width:i[0],height:i[1],marks:[...M.map(({node:t})=>({type:"node:"+(t.type??"node")})),...S.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:$,nodeCount:M.length,edgeCount:S.length,margin:s})),Th.renderToStaticMarkup(Cd(uf(cf,{children:[h,_,P,L,C,p,k]}),{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:c,idPrefix:t._idPrefix}))}import*as gf from"react-dom/server.browser";import{geoPath as yf}from"d3-geo";import{quadtree as mf}from"d3-quadtree";import{geoMercator as xf,geoEqualEarth as bf,geoAlbersUsa as vf,geoOrthographic as wf,geoNaturalEarth1 as kf,geoEquirectangular as Af}from"d3-geo";var Sf={mercator:xf,equalEarth:bf,albersUsa:vf,orthographic:wf,naturalEarth:kf,equirectangular:Af};function Mf(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function _f(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Pf(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function Lf(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 $f(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,l=Math.min(.3*r,80),c=(t[0]+e[0])/2+s*l,u=(t[1]+e[1])/2+a*l,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*t[0]+2*r*i*c+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function Rf(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 Cf(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 l=s/a,c=-r/a,u=i/2+1;return[[t[0]+l*u,t[1]+c*u],[e[0]+l*u,e[1]+c*u]]}import{scaleLinear as Tf}from"d3-scale";var Of=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],If=["scene-style","data-paint","accessibility","evidence"],zf=(t,e)=>({retainedData:t,invalidations:e}),Ff=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Nf=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ef=["scene-geometry","data-paint","accessibility","evidence"],Df=["scene-style","data-paint","accessibility","evidence"],Wf=["overlay","accessibility","evidence"],Bf=[],jf={xAccessor:zf("rebuild",Ff),yAccessor:zf("rebuild",Ff),lineDataAccessor:zf("rebuild",Ff),pointIdAccessor:zf("rebuild",Ef),lineIdAccessor:zf("rebuild",Ef),windowSize:zf("rebuild",Ff),projection:zf("preserve",Nf),projectionExtent:zf("preserve",Nf),fitPadding:zf("preserve",Nf),lineType:zf("preserve",Nf),flowStyle:zf("preserve",Nf),graticule:zf("preserve",Nf),projectionTransform:zf("preserve",Nf),customLayout:zf("preserve",Nf),layoutConfig:zf("preserve",Nf),layoutMargin:zf("preserve",Nf),areaStyle:zf("preserve",Df),pointStyle:zf("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:zf("preserve",Df),colorScheme:zf("preserve",Df),themeCategorical:zf("preserve",Df),themeDiverging:zf("preserve",Df),themeSemantic:zf("preserve",Df),themeSequential:zf("preserve",Df),decay:zf("preserve",Df),pulse:zf("preserve",Df),layoutSelection:zf("preserve",Df),annotations:zf("preserve",Wf),autoPlaceAnnotations:zf("preserve",Wf),clock:zf("preserve",Bf),transition:zf("preserve",Bf),introAnimation:zf("preserve",Bf),onLayoutError:zf("preserve",Bf)},Yf=zf("preserve",Nf),Xf=class{constructor(){this.tracker=new o}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}},Of)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},If):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=jf[n]??Yf;"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 Gf,geoGraticule as Vf,geoInterpolate as Hf}from"d3-geo";function qf(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 Uf=class t{constructor(t){this.updateResults=new Xf,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:qf(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??qa()}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 U(t),this.timestampBuffer=new U(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:qf(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 U(e),this.timestampBuffer=new U(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();zl(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)zl(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)+"");Fl(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],l=this.scene;this.projection=function(t){if(!t)return bf();if("string"==typeof t){const e=Sf[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),bf())}if("object"==typeof t&&"type"in t){const e=Sf[t.type],o=e?e():bf();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=yf(this.projection),this.fitProjection(t),this.geoPath=yf(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(t,e)=>c([t,e]),invertedPoint:(t,e)=>c.invert?c.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&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(t){const e=this.projection,o=this.config,n=[...this.areas],i=Mf(o.xAccessor,"lon"),r=Mf(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=_f(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=yf(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 l=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=l,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=yf(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 l=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=l,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=yf(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=mf().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=Rr(e.colorScheme,e.themeCategorical,Jt),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:Cr(n,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(i)}catch(t){const o=null!==this.lastCustomLayoutResult,n=Sl("geo",t,o,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(n)}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 wl({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:n,points:i,lines:r,layout:s}){const a=Mf(t.xAccessor,"lon"),l=Mf(t.yAccessor,"lat"),c=[],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=Vf();e.step&&n.step(e.step);const i=o(n())||"";i&&c.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);c.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:Pf(t.areaStyle,e,u),datum:e,interactive:!0})}const p=_f(t.lineDataAccessor);for(const o of r){const n=p(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]),l(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=Gf(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Hf(n,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const n=e(l(t/a));null!=n&&i.push(n)}}}else for(let t=0;n.length>t;t++){const o=n[t],r=e([a(o),l(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=Pf(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?Rf(i,u):Cf(i[0],i[i.length-1],0,0,u)):i=$f(i[0],i[i.length-1]);const h=Lf(i,s.width);if(h.length>1)for(const t of h)2>t.length||c.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const f=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,g=e.clipAngle?e.clipAngle()??0:0,y=g>0?g*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=l(o);if(null!=y&&Gf([n,i],b)>y)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:f?f(o)+"":void 0};c.push(u)}return c}({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 l=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,c="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=i.find(t=>t.datum&&l(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=i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),h=kt(d,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 p="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,l=Tf().domain([0,n]).range([0,s]);e.x=r,e.y=a;const c=[];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?l(t):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let t=d+1;for(;c.length>t&&3>Math.abs(c[t].x-c[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)c[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,c,h,o):function(t,e,o,n,i,r){const s=e.x,a=e.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=Tf().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),p=Math.hypot(t-s,u-a),f=Number(o(r.datum)),g=isFinite(f)&&f>=0?n>0?d(f):0:p,y=l+Math.cos(h)*g,m=c+Math.sin(h)*g;r.x=t+(y-t)*i,r.y=u+(m-u)*i}return e.x=s+(l-s)*i,e.y=a+(c-a)*i,{cx:e.x,cy:e.y,maxCost:n,availableRadius:u,layout:"radial"}}(i,u,c,h,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 l=a[a.length-1];o.path=o.path.map((t,e)=>{const r=l>0?a[e]/l: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 p}(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=Ua(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 l=Za(e,n[a],t);s=Qa(o[a],l,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(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=Va(t,this.activeTransition),o=Ga(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=Ha(t.x,t._targetX,o),t.y=Ha(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}};Uf.QUADTREE_THRESHOLD=500;var Kf=Uf;function Zf(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=f(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+n.centerDx,y:t.y+n.centerDy,r:n.radius})}return e}Xl(Kf);import{Fragment as Qf,jsxs as Jf}from"react/jsx-runtime";function tg(t,e){const o=ye(t.theme),n=t.size||[t.width||600,t.height||400],i=qe({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Ve(t.title),s=Array.isArray(t.areas)?Ht(t.areas):t.areas,a=Ht(t.points),l=Ht(t.lines),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return iu(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];Ld(i,{props:t,categories:c,theme:o,size:n,hasTitle:r});const u=$d({props:t,categories:c,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),p={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:Rt(o),themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging},f=new Kf(p);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.`);f.setAreas(s)}t.points&&f.setPoints(a),t.lines&&f.setLines(l),f.computeScene({width:d,height:h});const g=Id(t.backgroundGraphics,n,i,f.scales),y=Id(t.foregroundGraphics,n,i,f.scales),m=Vc({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=ot(o.style.fill)?et(o.style.fill,`geoarea-${e}-hatch`):void 0;return Rc(Lc.Fragment,{children:[n&&$c("defs",{children:n}),$c("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:gc(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=ot(o.style.fill)?et(o.style.fill,`geopoint-${e}-hatch`):void 0;return Rc(Lc.Fragment,{children:[n&&$c("defs",{children:n}),$c("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:gc(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 $c("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 mc(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===m.length){let r;const s=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Zf(f.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),gf.renderToStaticMarkup(Cd(g||y||t.annotations||f.customLayoutOverlays?Jf(Qf,{children:[g,s,y,f.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 x=m.map(t=>t.element);let b;const v=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Zf(f.scene),idPrefix:t._idPrefix,onRender:t=>{b=t}}):null;return e&&(e.evidence=Ba({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:b,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),gf.renderToStaticMarkup(Cd(Jf(Qf,{children:[g,x,v,y,f.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}))}import*as eg from"react-dom/server.browser";function og(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 ng={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function ig(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 rg(t,e,o){const n="function"==typeof e?e(t,o):e;return{...ng,...n??{}}}function sg(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)??ig(t)},r={style:rg(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 ag,jsxs as lg}from"react/jsx-runtime";var cg={top:0,right:0,bottom:0,left:0};function ug(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function dg(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:l,className:c,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:p,renderBodySVG:f,renderChrome:g,...y}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=sg(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 l=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 l&&!l.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:og(e.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},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,y),x={...cg,...h},b=[o,n],v=ug(a,b,x),w=ug(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?ag("g",{transform:_,children:v}):v;return{element:lg("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":M,style:p,children:[i&&ag("title",{id:A,children:i}),r&&ag("desc",{id:S,children:r}),ag("defs",{children:ag("clipPath",{id:$,children:ag("rect",{width:P,height:L})})}),l&&"transparent"!==l?ag("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:n,fill:l}):null,!a&&s&&"transparent"!==s?ag("rect",{x:0,y:0,width:o,height:n,fill:s}):null,R,ag("g",{id:k+"-data-area",transform:_,clipPath:`url(#${$})`,children:m.sceneNodes.map((t,e)=>{const o=m.bodies[e],n=o&&f?f(o,t.style??{},e,k):void 0;return null!=n?Ac(n,t,e):Yc(t,e,k)})}),w,g?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:eg.renderToStaticMarkup(o),scene:n,evidence:i}}function hg(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function pg(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,hg(t.thickness)??hg(o)??hg(e.thickness)??4)}function fg(t){return t.sensorId??"stream-region-"+t.id}function gg(t){const e=fg(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 yg}from"react/jsx-runtime";function mg({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?yg("foreignObject",{x:0,y:0,width:e,height:o,children:t}):yg("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 xg}from"d3-scale";function bg(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}import{jsx as vg,jsxs as wg}from"react/jsx-runtime";var kg={top:0,right:0,bottom:0,left:0};function Ag(e,o){const n=e.size??[e.width??600,e.height??400],i=ye(e.theme),r=void 0===e.theme?{}:Ct(i),s=e.bodyStyle,a=!1,l=e.legendPosition??"right",c=He({...kg,...e.margin},a,!!e.legend&&"top"===l);if(e.legend){const t={...c};so(c,{legend:e.legend,position:l,size:n,hasTitle:a,legendLayout:e.legendLayout}),Ue(c,t,n,l)}let u;const d=function({annotations:t,chartId:e,chartType:o,config:n,onRegionObservation:i,regionEffects:r,seed:s,size:a}){const l=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=pg(i,e),s=i.colliderId??`${o}${i.id}`;let a;if("x"===t){const t=hg(i.x),o=hg(i.y1)??hg(e.plotBounds?.y)??hg(i.y),n=hg(i.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??hg(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=hg(i.y),o=hg(i.x1)??hg(e.plotBounds?.x)??hg(i.x),n=hg(i.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??hg(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:hg(i.restitution)??hg(e.barrierRestitution)},..."barrier"!==i.physics||null==i.friction&&null==e.barrierFriction?{}:{friction:hg(i.friction)??hg(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]}}),c=void 0===s||void 0!==n?.kernel?.seed?n:{...n,kernel:{...n?.kernel,seed:s}},u=r.flatMap(t=>[{id:fg(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...gg(t)]),d=Object.fromEntries(r.map(t=>[fg(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,p=r.length>0;return p||u.length>0||l.length>0||null!=e||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{p&&i(t),h?.onObservation?.(t)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:[Math.max(1,n[0]-c.left-c.right),Math.max(1,n[1]-c.top-c.bottom)]}),h=new t(d);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&h.enqueue(e.initialSpawns.map(t=>({...t,spawnAt:void 0})));const p=dg(h,{...e,width:n[0],height:n[1],background:e.background??i.colors.background,bodyStyle:(t,e)=>({fill:i.colors.primary,stroke:i.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof s?s(t,e):s}),style:{...r,fontFamily:i.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:c,renderChrome:t=>{const o=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),l=function(t){const{width:e,height:o,pointNodes:n=[],data:i}=t;return{scales:{x:xg().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:xg().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:(c=t.bodies,c.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,bg(t))})))});var c;const u=l.scales?.x,d=l.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const p=td({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:i,frameType:"network",xAccessor:l.xAccessor,yAccessor:l.yAccessor,pointNodes:l.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),f=e.legend?Pd(e.legend,{theme:i,position:e.legendPosition,size:[o[0],o[1]],margin:n,hasTitle:!!e.title,legendLayout:e.legendLayout})??od(e.legend,o,n,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:wg("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:[vg("g",{transform:`translate(${n.left},${n.top})`,children:p}),vg(mg,{title:e.title,totalWidth:o[0],marginTop:Math.max(n.top,28)}),f]})}}(t,e,n,c,i);return u=o.annotationRender,o.node}});return o&&(o.evidence=Ba({frameType:"physics",width:n[0],height:n[1],marks:p.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:u,extraWarnings:[...0===p.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...p.scene.evidence.warnings]})),p.svg}import*as Sg from"react-dom/server.browser";import{jsx as Mg,jsxs as _g}from"react/jsx-runtime";var Pg={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 Lg(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var $g={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",n=Pg[o],i=Lg(t.width,n.width),r=Lg(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,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=ye(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),l=Math.round(s-24*a);return 0===l?`${e}${a}d`:`${e}${a}d ${l}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}),p=void 0===d?"No value":(f=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${f}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var f;const g=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),y="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)}(g?.level??"neutral",g?.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,g?.label].filter(Boolean).join(" · "),A="string"==typeof t.description&&t.description||[m,p,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),$=c+("start"===l?Math.max(n.valueSize,p.length*n.valueSize*.55):0),R=Sg.renderToStaticMarkup(_g("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:[Mg("title",{children:m??p}),"string"==typeof t.description&&Mg("desc",{children:t.description}),Mg("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&&Mg("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:m}),n.showHeader&&x&&Mg("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:x}),Mg("text",{x:c,y:L,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:p}),b&&void 0!==d&&"start"===l&&Mg("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&&Mg("text",{x:c,y:Math.min(r-s,L+n.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Ba({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:A})),R}};function Rg(t,e,o){return $g[t](e,o)}import{Fragment as Cg,jsx as Tg,jsxs as Og}from"react/jsx-runtime";function Ig(t,e){switch(t){case"xy":return Xd(e);case"ordinal":return Ch(e);case"network":return ff(e);case"geo":return tg(e);case"physics":return Ag(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function zg(t){return Xd(t)}function Fg(t){return Ch(t)}function Ng(t){return ff(t)}function Eg(t){return tg(t)}var Dg=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"]),Wg=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function Bg(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 jg(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)=>!Dg.has(e)||/\b(?:var|calc|url)\(/i.test(n)?t:` ${e}="${function(t,e){const o=RegExp(Wg.source,Wg.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+=Bg(n[0],e),r=n.index+n[0].length,s=!0}return i+t.slice(r)}(n,o)}"`))}var Yg=["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"],Xg=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Gg(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function Vg(t,e,o){return qg(t,e,o).svg}function Hg(t,e,o){const n={},{svg:i,frameType:r}=qg(t,e,o,n),s=n.evidence??Ba({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,Yt(s,t,e),{svg:i,evidence:s}}function qg(t,e,o,n){if(Object.prototype.hasOwnProperty.call($g,t))return{svg:jg(Rg(t,e,n),o?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(Ea,t))throw Error(`Unknown chart component: "${t}". Run \`npx semiotic-ai --list\` for supported chart types.`);const i=Ea[t];var r;const s=function(t,e,o){const n=It[t||"primary"],i=t&&"primary"!==t||!o?.width?n.width:o.width,r=t&&"primary"!==t||!o?.height?n.height:o.height,s={...e,mode:t},a=ut(s,{width:e.width??i,height:e.height??r}).props,l=a.mode||t||"primary",c=It[l],u="context"===l||"sparkline"===l,d="primary"===l&&o?.width?o.width:c.width;return{mode:l,width:a.width??d,height:a.height??("primary"===l&&o?.height?o.height:c.height),showAxes:a.showAxes??c.showAxes,showGrid:a.showGrid??c.showGrid,enableHover:a.enableHover??(!!a.linkedHover||c.enableHover),showLegend:a.showLegend??c.showLegend,showLabels:a.showLabels??c.showLabels,title:u?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:u?void 0:a.xLabel,yLabel:u?void 0:a.yLabel,categoryLabel:u?void 0:a.categoryLabel,valueLabel:u?void 0:a.valueLabel,marginDefaults:zt(c.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:Ot(a.mobileInteraction,{mode:l,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(It,r)?e.mode:void 0),{...i.layout?.modeDefaults,...Gg(e,Xg)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:p,colorBy:f,legendPosition:g,...y}=e,{width:m,height:x}=s,b=[m,x],v=y.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,A=void 0!==h?h:v.margin,S=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}(A),M="number"==typeof A?{top:A,right:A,bottom:A,left:A}:{...k,...S},_=Gg(y,Yg),P=t=>v[t]??s[t],L={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:b,margin:M,__compactMode:s.compactMode,__autoLegendMargin:!0,...void 0!==p&&{colorScheme:p},...void 0!==g&&{legendPosition:g},_idPrefix:y._idPrefix},$=i.buildProps(a,f,p,L,y);let R;switch(i.frameType){case"xy":R=Xd($,n);break;case"ordinal":R=Ch($,n);break;case"network":R=ff($,n);break;case"geo":R=tg($,n);break;case"physics":R=Ag($,n)}const C=i.renderOverlay?.($,{theme:ye(l)});if(null!=C){const t=Xt.renderToStaticMarkup(Tg(Cg,{children:C})),e=R.lastIndexOf("</svg>");R=0>e?`${R}${t}`:`${R.slice(0,e)}${t}${R.slice(e)}`}return{svg:jg(R,o?.precision),frameType:i.frameType}}function Ug(t,e={}){const{title:o,subtitle:n,theme:i,width:r=1200,height:s,layout:a={},background:l}=e,c=me(ye(i)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),n&&(h+=20),h>0&&(h+=10);const p=Math.floor((r-d-d*(u-1))/u),f=[];let g=0,y=h+d,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),o=e.props.height||300;g+t>u&&(y+=m+d,g=0,m=0),f.push({chart:e,x:d/2+g*(p+d),y:y,w:p*t+d*(t-1),h:o}),m=Math.max(m,o),g+=t}const x=s||y+m+d,b=f.map((t,e)=>{const{chart:o,x:n,y:r,w:s,h:a}=t,l={...o.props,width:s,height:a,theme:i,_idPrefix:"chart-"+e};let c;return c=o.component?Vg(o.component,l):o.frameType?Ig(o.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,Tg("g",{transform:`translate(${n},${r})`,children:Tg("foreignObject",{width:s,height:a,children:Tg("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+e)});return Xt.renderToStaticMarkup(Og("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":o||"Dashboard",style:{fontFamily:c.fontFamily},children:[o&&Tg("title",{children:o}),l&&Tg("rect",{x:0,y:0,width:r,height:x,fill:l}),o&&Tg("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleFontSize+4,fontWeight:c.titleFontWeight,fill:c.text,fontFamily:c.titleFontFamily,children:o}),n&&Tg("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:n}),b]}))}import*as Kg from"react-dom/server.browser";import{Fragment as Zg,jsx as Qg,jsxs as Jg}from"react/jsx-runtime";function ty(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=n,p=o.width||600,f=o.height||400,g=ye(o.theme),y={...o,...a&&{xExtent:a},...l&&{yExtent:l}};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=qe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=p-v.left-v.right,k=f-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||g.colors.categorical,...h&&{decay:h}},l=new mh(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&A.push(sy(l.scene,p,f,g,y))}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:l,colorScheme:o.colorScheme||g.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},b=new ac(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(ry(b.scene,p,f,g,y,v)),c>0&&n>0&&b.activeTransition){const t=c*(1e3/u);for(let e=1;c>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/c*t),A.push(ry(b.scene,p,f,g,y,v))}}return A}function ey(t,e,o={}){return e.map(e=>{try{return Vg(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 oy(t,e,o){const n=e.size??[e.width??600,e.height??400],i=ye(e.theme),r=me(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",l=e.title?`${a}-title-${o}`:void 0,c=e.description?`${a}-desc-${o}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=sg(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=Jg("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&&Qg("title",{id:l,children:e.title}),e.description&&Qg("desc",{id:c,children:e.description}),s&&"transparent"!==s?Qg("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,Qg("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>Yc(t,e,`${a}-${o}`))})]});return Kg.renderToStaticMarkup(h)}function ny(e,o={}){const{fps:n=12,frameCount:i,durationSeconds:r=2,includeInitialFrame:s=!0,stepDt:a,stepsPerFrame:l,background:c}=o,u=Math.max(.001,a??e.config?.fixedDt??1/120),d=l??Math.max(1,Math.round(1/Math.max(1,n)/u)),h=i??Math.max(1,Math.ceil(r*Math.max(1,n))),p=c?{...e,background:c}:e,f=new t(e.config);e.initialSpawns?.length&&f.enqueue(e.initialSpawns,e.initialSpawnPacing);const g=[];for(s&&(f.tick(0),g.push(oy(f,p,0)));h>g.length;){for(let t=0;d>t;t+=1)f.tick(u);g.push(oy(f,p,g.length))}return g}function iy(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function ry(t,e,o,n,i,r){const s=me(n),a=qe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=e-a.left-a.right,c=o-a.top-a.bottom,u=iy(i,n),d=i.renderMode,h=t.map((t,e)=>Gc({node:t,index:e,renderMode:d,fallback:()=>Yc(t,e)}).element).filter(Boolean),p=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=me(n),a=[];for(let n=0;t.length>n;n++){const l=t[n];if("y-threshold"===l.type&&null!=l.value){let t=null;if(r)t=r(l.value);else if(i){const[e,n]=i,r=n-e;if(0===r)continue;t=o-(l.value-e)/r*o}if(null==t)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push(Jg("g",{children:[Qg("line",{x1:0,y1:t,x2:e,y2:t,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&Qg("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:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+n))}}return a.length>0?Qg(Zg,{children:a}):null}(i.annotations,l,c,n,i.yExtent,r?.y),f="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,y=f?"semiotic-title":void 0,m=g?"semiotic-desc":void 0,x=[y,m].filter(Boolean).join(" ")||void 0;return Kg.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[f&&Qg("title",{id:y,children:f}),g&&Qg("desc",{id:m,children:g}),u&&Qg("rect",{x:0,y:0,width:e,height:o,fill:u}),Jg("g",{transform:`translate(${a.left},${a.top})`,children:[p,h]}),f&&Qg("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:f})]}))}function sy(t,e,o,n,i){const r=me(n),s=qe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(e-s.left-s.right)/2:s.left,c=a?s.top+(o-s.top-s.bottom)/2:s.top,u=iy(i,n),d=Sh({nodes:t,renderMode:i.renderMode,idPrefix:i.idPrefix}).map(t=>t.element),h="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,f=h?"semiotic-title":void 0,g=p?"semiotic-desc":void 0,y=[f,g].filter(Boolean).join(" ")||void 0;return Kg.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":y,style:{fontFamily:r.fontFamily},children:[h&&Qg("title",{id:f,children:h}),p&&Qg("desc",{id:g,children:p}),u&&Qg("rect",{x:0,y:0,width:e,height:o,fill:u}),Qg("g",{transform:`translate(${l},${c})`,children:d}),h&&Qg("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}export{ty as generateFrameSVGs,ey as generateFrameSequence,ny as generatePhysicsFrameSVGs,Vg as renderChart,Hg as renderChartWithEvidence,Ug as renderDashboard,Eg as renderGeoToStaticSVG,Ng as renderNetworkToStaticSVG,Fg as renderOrdinalToStaticSVG,Ig as renderToStaticSVG,zg as renderXYToStaticSVG,ye as resolveTheme,jg as serializeSvgPrecision,me as themeStyles};
1
+ import{PhysicsPipelineStore as t,UpdateResultTracker as e,absorbRegion as o,annotationLayout as n,bodyGroupSpec as i,buildDirectedAdjacency as r,calendarLayout as s,capacitatedRegion as a,collidersFromPlotBounds as l,collidersFromXScaleBins as c,countPairwiseCrossings as u,drawGlyphParts as d,forceFieldRegion as h,glyphFractionClipRect as f,glyphHitGeometry as p,glyphPlacement as g,groupCompletionRows as y,isInBounds as m,makeSymbolResolver as x,orderByBarycenter as b,orderExactSmall as v,packBandsBySilhouette as w,parallelCoordinatesLayout as k,placeWithMinGap as A,portalRegion as S,pressureFieldRegion as M,processChrome as _,processStageLayout as P,reachableFrom as L,refineByAdjacentSwaps as $,resolveAnchoredPosition as T,resolveGlyphPaint as R,resolveNodeSizeFn as C,resolveX as I,resolveY as D,routeSurfaceRegion as F,symbolPathString as O,symbolRadius as N,useCustomLayoutSelection as z}from"./c-DPMVAUAW.min.js";import{IncrementalExtent as E,RingBuffer as W,annotationStableId as B,computeArcBoundingBox as j,darkenColor as Y,hatchPatternDef as X,isHatchFill as G,isTimeLandmark as V,lightenColor as H,resolveAnnotationGradient as q,resolveHatchCanvasPattern as U,resolveResponsiveRules as Z,resolveSvgFill as K,sweepToAngles as Q}from"./c-LF5BZFNC.min.js";import"./c-Q2IPZ3MU.min.js";import{coerceDateLikeValue as J,parseDateLikeString as tt}from"./c-W3CE4A4S.min.js";import"./c-4ES5367Y.min.js";import{accessorsEquivalent as et,filterAnnotationsByStatus as ot,resolveAccessor as nt,resolveLabelFn as it,resolveNodeRefId as rt,resolveRawAccessor as st,resolveStringAccessor as at}from"./c-NDJADPIF.min.js";import{getMax as lt,getMin as ct,getMinMax as ut}from"./c-GGISSW5E.min.js";import{resolveCSSColor as dt}from"./c-YZVRZGX2.min.js";import{DARK_THEME as ht,HIGH_CONTRAST_THEME as ft,LIGHT_THEME as pt,applyThemeAccessibility as gt,composeStyleRules as yt,makeNodeRuleContext as mt,makeRuleValueResolver as xt,makeXYRuleContext as bt,resolveStyleRules as vt,resolveThemePreset as wt,resolveThemeSemanticColors as kt,styleRulesToNodeStyle as At,themeToCSSVariables as St}from"./c-CJYSXIFV.min.js";var Mt={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function _t(t,e={}){const o=e.mobileSemantics?.interaction,n="number"==typeof o?.targetSize?o.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,i="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!o||void 0!==n,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!i&&!r)return Mt;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??n??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var Pt={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 Lt(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 $t(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var Tt={kind:"rank-competition"};function Rt(t,e,o,n){const i=t??e;return"function"==typeof i?i(o,n):o[i+""]}var Ct=Symbol.for("semiotic.semantic-viability"),It=globalThis,Dt=It[Ct]??(It[Ct]=new Map);function Ft(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 Ot(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const n=function(t){return function(t){return Dt.has(t)}(t)?function(t){return Dt.get(t)}(t):"BumpChart"===t?Tt: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(Rt(t.yAccessor,"y",o,n))))return;const i=$t(Rt(t.xAccessor,"x",o,n)),r=e.get(i)??new Set;r.add(Rt(t.lineBy,"series",o,n)+""),e.set(i,r)});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},r=2>i.max;return r||2>i.contestedColumns||2>i.median?[{code:r?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:r?"error":"warning",message:r?"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(Ft)}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 Nt from"react-dom/server";import*as zt from"react";var Et=Object.freeze([]);function Wt(t){if(!t)return Et;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 Bt}from"d3-scale";function jt(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function Yt(t,e,o){const n=t=>t.toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function Xt(t){const e=t.map(jt),o=e.length-1;return t=>{if(Number.isNaN(t)&&(t=0),0>=t){const[t,o,n]=e[0];return Yt(t,o,n)}if(t>=1){const[t,n,i]=e[o];return Yt(t,n,i)}const n=t*o,i=Math.floor(n),r=n-i,[s,a,l]=e[i],[c,u,d]=e[i+1];return Yt(Math.round(s+(c-s)*r),Math.round(a+(u-a)*r),Math.round(l+(d-l)*r))}}var Gt=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],Vt=Xt(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),Ht=Xt(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),qt=Xt(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Ut=Xt(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),Zt=Xt(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),Kt=Xt(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),Qt=Xt(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),Jt=Xt(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),te=Xt(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),ee=Xt(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),oe=Xt(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),ne=Xt(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),ie={blues:Vt,reds:Ht,greens:qt,viridis:Qt,oranges:Ut,purples:Zt,greys:Kt,plasma:Jt,inferno:te,magma:ee,cividis:oe,turbo:ne};function re(t){return t&&Object.prototype.hasOwnProperty.call(ie,t)?ie[t]:Vt}var se=Xt(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),ae=Xt(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),le=Xt(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),ce=Xt(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),ue=Xt(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),de=Xt(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),he=Xt(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),fe={category10:Gt,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...ie},pe=Gt,ge="#007bff";function ye(t,e,o=pe){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(fe,t)?fe[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var me=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],xe=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],be=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 ve(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")||be.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):pe[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))%pe.length]}function we(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 ke(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>we(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 Bt().domain(n).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(fe,o)?fe[o]:fe.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:pe;return Bt().domain(n).range(t).unknown("#999")}}function Ae(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,l]=o;if(s===r)return(a+l)/2;let c=(i-r)/(s-r);return 0>c?c=0:c>1&&(c=1),a+c*(l-a)}function Se(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function Me(t,e){if(!Se(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})}var _e={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function Pe(t,e=_e){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 Le(t){return t?Pe(t):void 0}function $e(t,e,o){return"function"==typeof t?t(o):o[t||e]}function Te(t){return t instanceof Date?t.getTime():Number(t)}function Re(t,e){return Qt(1===e?.5:t/(e-1))}function Ce(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 Ie(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}function De(t){if(!t)return pt;if("string"==typeof t){if("light"===t)return pt;if("dark"===t)return ht;if("high-contrast"===t)return ft;return wt(t)||pt}const e="dark"===t.mode?ht:pt,o={...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}};return gt(o)}function Fe(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 Oe(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 Ne(t){return Math.round(100*t)/100}function ze(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(Ne);return{points:t.map(([t])=>[Ne(t),Ne(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function Ee(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,l=(n-a*o)/e;return t=>l+a*t}function We(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 Be(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var je="__forecastSegment",Ye="__forecastOpacity";function Xe(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,l=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[Ye]=a+Math.max(0,Math.min(1,t))*(l-a))}return}const c=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=c.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=ut(u),f=h-d;t.forEach((t,e)=>{const o=c[e];Number.isFinite(o)&&(t[Ye]=l-(f>0?(o-d)/f:0)*(l-a))})}function Ge(t,e){return"function"==typeof e?e(t):!!t[e]}var Ve="__semiotic_resolvedX",He="__semiotic_resolvedY",qe="__compoundGroup";function Ue(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function Ze(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?Wt(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?Ve:e,s=i?He:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[Ve]=e(t)),i&&(r[He]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,l=s.yKey,c=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:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=n,g=t.map(t=>{let e="observed";return s&&Ge(t,s)?e="forecast":r&&Ge(t,r)&&(e="training"),{...t,[je]:e}}),y=n._groupBy,m=[];if(y){const t=new Map;for(const e of g){const o=e[y]??"__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][je]!==o[t+1][je]&&(e.push({...o[t+1],[je]:o[t][je]}),e.push({...o[t],[je]:o[t+1][je]}));m.push(...g,...e)}else for(let t=0;g.length>t;t++)m.push(g[t]),g.length-1>t&&g[t][je]!==g[t+1][je]&&(m.push({...g[t+1],[je]:g[t][je]}),m.push({...g[t],[je]:g[t+1][je]}));if(n.trainUnderline){const t=[];for(const e of m)"training"===e[je]&&t.push({...e,[je]:"training-base"});m.unshift(...t)}const x=[];if(l&&c){const t="string"==typeof l?l:"__envUpper",e="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const o of m)"function"==typeof l&&(o[t]=l(o)),"function"==typeof c&&(o[e]=c(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:p})}if(n.uncertaintyOpacity||n.confidenceAccessor){const t=l?"function"==typeof l?l:t=>t[l]:()=>{},e=c?"function"==typeof c?c:t=>t[c]:()=>{};Xe(m.filter(t=>"forecast"===t[je]),n,t,e)}if(a){const t=n.anomalyStyle,e={type:"highlight",filter:t=>Ge(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:l="#6366f1",bandOpacity:c=.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,[je]:"observed"}):d.push({...o,[je]:"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=[],g=[];if(f.length>=3){const i=f.length,r=Ee(f);if(r){const{se:d,meanX:h,ssX:y}=We(f,r),m=Be(a),x=t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t)),b=lt(x),v=f.length>1?(f[i-1][0]-f[0][0])/(i-1):1;for(let t=1;s>=t;t++){const n=b+t*v,s=r(n),a=d*Math.sqrt(1+1/i+(y>0?(n-h)**2/y:0))*m;g.push({[e]:n,[o]:s,[je]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}Xe(g,n,t=>t.__forecastUpper,t=>t.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,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 y=[];if(y.push(...d),d.length>0&&h.length>0&&y.push({...d[d.length-1],[je]:"observed"}),y.push(...h),g.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&y.push({...t,[je]:"forecast"}),y.push(...g)}return{processedData:y,annotations:p}}(t,e,o,n,i);var r}(r,a,l,n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,t.anomaly);if(r=e.processedData,c.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,l=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>l&&(l=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[qe]:`${t[n]}__${t[je]||"observed"}`})),d=qe):d=je,t.baseLineStyle){const e=function(e,o){const n=o.trainDasharray??"8,4",i=o.forecastDasharray??"4,4",r=o.color||"#6366f1",s=o.trainOpacity,a=o.forecastOpacity,l=o.trainStroke,c=o.trainLinecap,u=o.trainUnderline;return e=>{const o=(e=>t.baseLineStyle(e))(e),d=e[je];if("training"===d){let t=o.stroke;return"darken"===l?t=Y(o.stroke||"#666",.5):l&&(t=l),{...o,stroke:t,strokeDasharray:n,...c&&{strokeLinecap:c},...null!=s&&{strokeOpacity:s}}}if("training-base"===d){let t=o.stroke||"#666";return"lighten"===u&&(t=H(t,.4)),{...o,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Ye],n=null!=t?t:a;return{...o,stroke:r,strokeDasharray:i,...null!=n&&{strokeOpacity:n}}}return o}}(0,t.forecast);h=t=>e(t)}}else t.anomaly&&c.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)Ue(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)Ue(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 l=()=>{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)Ue(t,o,n)?l():r.push(t);l()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,l,"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 l="object"==typeof e?e:{},c=l.position||"end",u=l.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"===c?e[e.length-1]:e[0]);const p=ke(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),g=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===c?6:-6,dy:0,color:p?ve({__lbl:t},"__lbl",p):a||ge,fontSize:u}));g.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;g.length>t;t++){const e=g[t-1],o=g[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const y=g.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===c?{right:y}:{left:y}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,t.colorScheme,t.themeCategorical,t.color);c.push(...e.annotations),p=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?l:o,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:p}}function Ke(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=De(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrScatterColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?ke(c,l,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?ut(f):void 0,g=bt(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?ve(t,e,u):"string"==typeof i.color?i.color:ge,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?Ae(t,d,h,p):"number"==typeof i.pointRadius?i.pointRadius:5};return y?.length&&Object.assign(o,vt(t,y,g(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 Qe={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Ze({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:De(n.theme).colors.categorical}),s=Ie(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||Ke(t,e,o,n,i),showLegend:n.showLegend??!!e}}},Je={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Ie(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||to(t,e,o,n,i),showLegend:n.showLegend??!!e}}};function to(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=De(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrBubbleColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?ke(c,l,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?ut(f):void 0,g=bt(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?ve(t,e,u):"string"==typeof i.color?i.color:ge,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?Ae(t,d,h,p):h[0],stroke:i.bubbleStrokeColor??"white",strokeWidth:i.bubbleStrokeWidth??1};return y?.length&&Object.assign(o,vt(t,y,g(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 eo,useCallback as oo,useState as no,useId as io,useEffect as ro,useRef as so}from"react";var ao="__semioticSelectionData";function lo(t,e){return e?.length?(Object.defineProperty(t,ao,{configurable:!0,enumerable:!1,value:e}),t):t}function co(t){return t?.[ao]}function uo(...t){let e;for(const o of t)o&&(e=ho(e)&&ho(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function ho(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function fo(t){return"object"==typeof t&&null!==t&&"gradient"in t}function po(t){return"string"==typeof t&&t.length>0}function go(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function yo(t,e){return go(t,po(e))}function mo(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 xo(t){return Math.ceil(7*t.length)}function bo(t,e){if(ho(t)){const o=To(e),n=t.legendGroups.flatMap(t=>[t.label?xo(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+xo(t.label))]);return Math.max(100,...n)}if(fo(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),n=Math.max(xo(o(e.domain[0])),xo(o(e.domain[1]))),i=e.label?xo(e.label):0;return Math.max(100,19+n,i)}return 100}function vo(t){return(ho(t)||fo(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function wo(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?So:Ao:0}function ko(t){return Math.max(0,t?.edgeGutter??3)}var Ao=34,So=70;function Mo(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function _o(t,e,o){if(fo(t))return t.gradient.label?46:26;if(!ho(t))return 20;const n=To(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+xo(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?xo(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function Po(t,e,o){return bo(t,e)+vo(t)+wo(e,o)+ko(e)}function Lo(t,e){const{legend:o}=e;if(!o)return;const n=e.position??"right",i=_o(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+vo(o)+Mo("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,Po(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===n?t.left=Math.max(t.left,r,Po(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 $o(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??bo(t,e.legendLayout)),s=vo(t),a=wo(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),l=ko(e.legendLayout),c=_o(t,i,e.legendLayout),u=Mo(e.axisChrome,e.legendLayout),d=Mo(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(l,e.margin.left-a-r-s),y:e.margin.top,width:r,height:c};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-c,width:r,height:c};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-c)),width:r,height:c}}return{x:Math.min(e.totalWidth-r-l,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:c}}function To(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 Ro(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 Co(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=we(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=fe[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]:ge}function Io(t,e,o){return"function"==typeof t?t(e,o):e[t]}function Do(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[$t(t),e]));return t.map(t=>{const e={...t},n=n=>{if(!(n in t))return;const i=o.get($t(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})}function Fo(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 Oo(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 No(t,e,o,n,i){const r=[],s=(t.x+e.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===n?(c=t.x+(e.x-t.x)*l,u=t.y+(e.y-t.y)*l,d=e.x-t.x,h=e.y-t.y):(c=Fo(t.x,s,s,e.x,l),u=Fo(t.y,t.y,e.y,e.y,l),d=Oo(t.x,s,s,e.x,l),h=Oo(t.y,t.y,e.y,e.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*l,datumIndex:.5>l?o:o+1})}return r}function zo(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=No(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,l=e.dx/r,c=Math.max(0,e.radius);o.push([e.x+s*c,e.y+l*c]),n.push([e.x-s*c,e.y-l*c]),i.push(e.datumIndex)}}return{topPath:o,bottomPath:n,datumIndices:i}}import{jsx as Eo}from"react/jsx-runtime";function Wo({datum:t,x:e,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=z(),l=a.isActive&&!a.predicate(t),c="function"==typeof s?s(t.__bumpRaw):s;return Eo("text",{className:"semiotic-bump-label",x:e+("end"===n?8:-8),y:o,dy:"0.35em",textAnchor:"end"===n?"start":"end",fill:i,fillOpacity:l?.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)",...c},children:t.__bumpSeries})}function Bo(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 jo(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 Yo(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,l=(e.colorMap&&we(e.colorMap,r))??t.resolveColor(n[0].__bumpSeries,n[0]),c=e.color??(a?l:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??l),u=n.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?Bo(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=zo(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:c,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,vt(n[0].__bumpRaw,e.styleRules,jo(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:c,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(n,vt(t.__bumpRaw,e.styleRules,jo(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:c})};"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(Eo(Wo,{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?Eo("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 Xo={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,n,i)=>{const r=function(t,e={}){const o=e.xAccessor??"x",n=e.yAccessor??"y",i=e.lineBy??"series",r=e.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;t.forEach((t,e)=>{const r=Io(o,t,e),f=$t(r);let p=a.get(f);null==p&&(p=s.length,a.set(f,p),s.push(r),l.set(p,[]));const g=Io(i,t,e)+"";u.has(g)||(u.set(g,c.length),c.push(g));const y=Number(Io(n,t,e));Number.isFinite(y)&&(d=Math.min(d,y),h=Math.max(h,y),l.get(p)?.push({datum:t,inputIndex:e,series:g,value:y}))});const f=[],p=new Map,g=new Map;for(let t=0;s.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,o)=>{const n=o+1;f.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:n}),p.set(e.series,(p.get(e.series)??0)+n),g.set(e.series,(g.get(e.series)??0)+1)})}const y=c.length+1,m=[...c].sort((t,e)=>{const o=g.get(t)??0,n=g.get(e)??0;return((p.get(t)??0)+(s.length-o)*y)/Math.max(1,s.length)-((p.get(e)??0)+(s.length-n)*y)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),x=new Set(m.slice(0,null==e.highlightTop?m.length:Math.max(0,Math.floor(e.highlightTop))));return{data:f.map(t=>{const e=x.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:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}(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}),s=Math.max(1,r.seriesOrder.length),a=De(n.theme),l=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:n,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=t;if(null==n&&null==i)return r;const c=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??(c.has(t)?Co(void 0,a,r,t,u):s??l??"#b8bec8")});return d}({seriesOrder:r.seriesOrder,overallOrder:r.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:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={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:r.valueExtent,seriesOrder:r.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},u=n.xFormat,d=(t,e)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((t,e)=>e),f=Array.from({length:s},(t,e)=>e+1),p=n.axes??[{orient:"left",tickValues:f,tickFormat:t=>t+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:Yo,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:p,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:Do(n.annotations,r.xValues)}}},Go="__ma_unitized",Vo="__ma_series",Ho={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:[...pe],l=s.some(t=>"string"==typeof t.color)?s.map((t,e)=>t.color||a[e%a.length]):o,c=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,[Go]:c?(i-r[0])/s:i,[Vo]: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=c?[{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:Go,groupAccessor:Vo,colorAccessor:Vo,colorScheme:l,...f&&{axes:f},...c&&{yExtent:[0,1]},...n,curve:i.curve||n.curve||"monotoneX",showLegend:n.showLegend??!0}}},qo={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],l=r.some(t=>{const e=a(t);return!("number"==typeof e&&Number.isFinite(e)||e instanceof Date)}),c=l?r.map((t,e)=>({...t,__waterfallX:e,__waterfallTick:(a(t)??e)+""})):r;return{chartType:"waterfall",data:c,xAccessor:l?"__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,...l&&{axes:n.axes??[{orient:"bottom",tickValues:c.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 Uo(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=De(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrAreaColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?ke(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,f="number"==typeof i.areaOpacity?i.areaOpacity:.7,p=xt(i.yAccessor),g=i.styleRules;return(t,o)=>{const n=e&&u?ve(t,e,u):"string"==typeof i.color?i.color:ge,r={fill:n,fillOpacity:f,stroke:d?n:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(r,vt(t,g,{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 Zo(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=De(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrPointColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?ke(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?ve(t,e,u):"string"==typeof i.color?i.color:ge;return{r:d,fill:o,stroke:"none"}}}var Ko={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",l=De(n.theme).colors.categorical,c=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=De(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrLineColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?ke(c,l,a):void 0,d=bt(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:l,ruleContext:c}=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=ve(t,o,n)):f=i||ge,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),l?.length&&Object.assign(d,vt(t,l,c?c(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 Me(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=Ze({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:l,baseLineStyle:c}),d=n.pointStyle||Zo(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||c,...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}}},Qo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?Wt(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=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=Oe(i,o,"time"),r=Oe(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:c,extentPadding:i.extentPadding}):c,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=yt(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:l,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,areaStyle:n.areaStyle||(t=>({...h(t),...!l&&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??!!l}}},Jo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=Ze({data:Array.isArray(t)?Wt(t):[],xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.areaBy,forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:De(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"}),l=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),c=l?.stops.length?{stops:l.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:Pe(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}(l):void 0,d=n.pointStyle||Zo(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!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:n.lineStyle||Uo(a,r,o,n,i),...d&&{pointStyle:d}}}},tn={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=t=>Te($e(r,"x",t)),c=t=>Te($e(s,"a",t)),u=t=>Te($e(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,g=!1!==i.showLines,y=!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,l=null,c=[];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),g=o(r),y=n(r);if(!Number.isFinite(p)||!Number.isFinite(g)||!Number.isFinite(y))continue;const m=u(g,y);if(null!==m)if(null!=a){if(l&&l.w!==m){let t,e;if(c.length>0)t=c[0].x,e=c[0].y;else{const o=g-l.a-(y-l.b);if(0!==o){const n=Math.max(0,Math.min(1,(l.b-l.a)/o));t=l.x+n*(p-l.x),e=l.a+n*(g-l.a)}else t=l.x,e=l.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;c.length>t;t++)f(c[t],a)}else for(const t of c)f(t,a);c=[],h({__x:p,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:p,a:g,b:y,w:m}}else{a=m;for(const t of c)f(t,a);c=[],h({__x:p,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:p,a:g,b:y,w:m}}else c.push({x:p,y:g,datum:r})}for(const t of c)f(t,a??"A");return r}(Array.isArray(t)?t:[],l,c,u),w=[];if(g&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(l(t))).sort((t,e)=>l(t)-l(e));for(const t of e){const e=l(t),o=c(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,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},en={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?ke(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=n.lineStyle||(t=>{const e=null==r?void 0:ve(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}},l=i.styleRules;if(l?.length){const e=xt(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,vt(t,l,{value:e(t),category:o}))}return n}),c=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Zo(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:c,stackOrder:i.stackOrder,lineStyle:l,...n,...u&&{pointStyle:u},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!r}}},on={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)}}},nn={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,f=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,p=zt.createElement,g=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const n=o.width,i=o.height,l=null!=r?e.x(r):n/2,g=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(g))return null;const y=Math.max(0,Math.min(n,l)),m=Math.max(0,Math.min(i,g)),x=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:n-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:i-m},{c:a.bottomRight,x:y,y:m,w:n-y,h:i-m}],b=c?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("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 p(zt.Fragment,null,...x.map((t,e)=>t.w>0&&t.h>0?p("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),p("line",{key:"vc",x1:y,y1:0,x2:y,y2:i,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:n,y2:m,stroke:d,strokeWidth:h,strokeDasharray:f}),...b)}]: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||Ke(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...g&&{svgPreRenderers:g}}}},rn={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:Te($e(e.orderAccessor,"order",t))-Te($e(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=Te($e(o,"x",t)),i=Te($e(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=Te($e(o,"x",t)),i=Te($e(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=Ze({data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:De(n.theme).colors.categorical}),a=Ie(s.annotations,i.regression),l=i.pointRadius??4,c=bt(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=Re(t,e.length);100>e.length&&o.push(zt.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),o.push(zt.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:l,strokeLinecap:"round"}))}return zt.createElement(zt.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:Me(t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1,i={fill:n>0?Re(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(i,vt(t,u,c(t))),i},Ce(i)),...n,...a&&a.length>0&&{annotations:a},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}};function sn(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}var an={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=yt(()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:s}),i.styleRules,function(t,e,o){const n=xt(t),i=xt(e),r=xt(o);return t=>{const e="string"==typeof t.agg&&"number"==typeof t.count&&"number"==typeof t.xCenter&&"number"==typeof t.yCenter;return{value:e?sn(t.value):r(t),x:e?sn(t.xCenter):n(t),y:e?sn(t.yCenter):i(t)}}}(i.xAccessor,i.yAccessor,i.valueAccessor)),l=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,c=null!=r&&Object.hasOwn(r,"heatmapColorScale"),u=r?.heatmapColorScale,d=c?"function"==typeof u?u:void 0:"custom"===l&&"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!==l&&{colorScheme:l},...d&&{heatmapColorScale:d}}}};import{useMemo as ln,useCallback as cn,useRef as un}from"react";var dn={RdBu:se,PiYG:ae,PRGn:le,BrBG:ce,RdYlBu:ue,RdYlGn:de,Spectral:he},hn="__likert_neutral_neg",fn="__likert_neutral_pos";function pn(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}var gn={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,l=new Set(e);for(const s of t){const t=o(s);a.has(t)||a.set(t,new Map);const c=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];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const t=i(s),e=r(s);if(!l.has(t))continue;c.set(t,(c.get(t)||0)+(Number.isFinite(e)?e:0))}}const c=[];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,l={};s.category&&(l[s.category]=t),s.level&&(l[s.level]=r),s.count&&(l[s.count]=a),s.score&&(l[s.score]=i+1),c.push({...l,__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:a,__likertPct:a/n*100,__likertLevelIndex:i})}}return c}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,pn(i.categoryAccessor,"question"),i.levelAccessor?null:pn(i.valueAccessor,"score"),i.levelAccessor?pn(i.levelAccessor,"level"):null,i.levelAccessor?pn(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===hn?r=o:o.__likertLevel===fn?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:hn,__likertPct:-t}),r.push({...e,__likertLevel:fn,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const l=De(n.theme).colors.diverging,c=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(dn,e)){const o=dn[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,l),u=new Map(r.map((t,e)=>[t,c[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=uo(!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,g=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:Me((t,e)=>{const o=t.__likertLevel||t.data?.__likertLevel,n=t.__likertLevelLabel||t.data?.__likertLevelLabel,i=t.__likertPct??t.data?.__likertPct,r={fill:o===hn||o===fn?d:u.get((n||o)+"")||"#888"};return p?.length&&Object.assign(r,vt(t,p,{value:"number"==typeof i?i:void 0,category:e??(null==n?void 0:n+"")})),"function"==typeof g?Object.assign(r,g(t,e)||{}):g&&"object"==typeof g&&Object.assign(r,g),r},Ce(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}};import*as yn from"react";function mn(t){return Math.max(0,Math.min(1,t))}function xn(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 bn(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 vn(t,e,o){const n=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:mn(t.offset),color:t.color??o,opacity:null==t.opacity?1:mn(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=xn(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=mn(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,l=xn(e.color),c=xn(o.color);if(!l||!c)return i(.5>a?e:o);const[u,d,h]=l,[f,p,g]=c,y=u+(f-u)*a,m=d+(p-d)*a,x=h+(g-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?bn(y,m,x):`rgba(${Math.round(y)},${Math.round(m)},${Math.round(x)},${b})`}return i(n[n.length-1])}function wn(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as kn,jsx as An,jsxs as Sn}from"react/jsx-runtime";var Mn={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 Sn(kn,{children:[o.showNeedle&&Sn(kn,{children:[An("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"}),An("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&An("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,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return Sn("g",{children:[An("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"}),An("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:c,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,l=i.arcWidth??.3,c=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=Q(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],f=Le(n.gradientFill),p=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,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=!!c&&c.stops.length>=2,g=[],y=new Map,m=[];if(p){const t=a?h:1,e=wn("bg",0);if(g.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.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(vn(c.stops,t*(e+.5)/o,r||f[0]?.color||"#007bff"));const i=wn("fill",0);g.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),y.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,l=(n.value-e)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const t=wn("fill",o);g.push({category:t,value:c,_zone:n.label||"Zone "+(o+1),_isFill:!0}),y.set(t,{fill:n.color})}if(u>0){const t=wn("bg",o);g.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),y.set(t,{fill:s,opacity:.4})}t=n.value}}if(l&&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:g,pieceStyle:(t,e)=>y.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}),g=i.styleRules,[y,m]=n.size||[300,250],x=j(a),b=Math.min(10,Math.max(1,Math.min(y,m)/12)),v=Math.max(4,Math.min((y-2*b)/x.width,(m-2*b)/x.height)-2),w=Math.max(0,Math.min(v-1.5,v*(1-l))),k=y/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:yn.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},yn.createElement("div",{style:{fontSize:Math.max(16,.3*v),fontWeight:700,color:"var(--semiotic-text, #333)"}},_),!1!==i.showScaleLabels&&yn.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:Me((t,e)=>{const o={...p.pieceStyle(t,e)};return g?.length&&Object.assign(o,vt(t,g,{value:"number"==typeof t.value?t.value:void 0,category:e??(null==t.category?void 0:t.category+"")})),o},Ce(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[y,m],margin:{top:A-S/2,bottom:m-A-S/2,left:k-S/2,right:y-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:l,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:c,needleColor:i.needleColor,..."context"===i.mode&&null==P&&{contextValue:_,contextValueY:A-.2*w,valueFontSize:Math.max(12,Math.min(22,.28*v))}}}}};function _n(t){return Pe(t)}function Pn(t,e,o,n,i,r){const s=De(n.theme).colors.categorical,a=o??n.colorScheme,l=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],c="string"==typeof e?e:"__ssrColorBy",u="function"==typeof e?l.map(t=>({...t,__ssrColorBy:e(t)})):l,d=e?ke(u,c,a??s):void 0,h=Co("string"==typeof i.color?i.color:void 0,s,a,void 0,new Map),f=r??xt(i.valueAccessor??"value"),p=i.styleRules,g=n.pieceStyle;return(t,o)=>{const n={fill:e&&d?ve(t,e,d):h};return p?.length&&Object.assign(n,vt(t,p,{value:f(t,o),category:o})),"function"==typeof g?Object.assign(n,g(t,o)||{}):g&&"object"==typeof g&&Object.assign(n,g),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 Ln(t,e,o,n,i,r="median",s=.8){const a=xt(i.valueAccessor??"value"),l=Pn(t,e,o,n,i,t=>"number"==typeof t[r]?t[r]:a(t));return(t,e)=>{const o=l(t,e);return void 0===o.fillOpacity&&(o.fillOpacity=s),void 0===o.stroke&&(o.stroke=o.fill),o}}function $n(t,e,o,n,i){return Ln(t,e,o,n,i,"median",.6)}function Tn(t,e,o,n,i){const r=Pn(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function Rn(t,e,o,n,i){const r=Pn(t,e,o,n,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=c.length?ut(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?Ae(t,a,l,u):d,fillOpacity:h,...r(t,e)})}var Cn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=Ie(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:_n(n.gradientFill),pieceStyle:Pn(t,e,o,n,i)}}},In={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:_n(n.gradientFill),pieceStyle:Pn(t,r,o,n,i),showLegend:n.showLegend??!!r}}},Dn={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:_n(n.gradientFill),pieceStyle:Pn(t,r,o,n,i),showLegend:n.showLegend??!!r}}},Fn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor,s=xt(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:Pn(t,r,o,n,i,t=>{const e=s(t);return null==e?void 0:Math.abs(e)}),showLegend:n.showLegend??!!r}}},On={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor,s=xt(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:Pn(t,r,o,n,i,t=>{const e=s(t);return null==e?void 0:Math.abs(e)})}}},Nn={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),l=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}:l?{rExtent:l}:{},...n,summaryStyle:Ln(t,e,o,n,i,"count")}}},zn={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:Ln(t,e,o,n,i)})},En={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:$n(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},Wn={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:Rn(t,e,o,n,i),showLegend:n.showLegend??!!e})},Bn={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>{const r=Ie(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:Tn(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e}}},jn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=i.seriesAccessor||e||"__radar",s=e||("__radar"===r?void 0:r),a=Tn(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}}},Yn={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:_n(n.gradientFill),pieceStyle:Pn(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},Xn={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:Ln(t,e,o,n,i,"median",.5),showLegend:n.showLegend??!!e})},Gn={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:Pn(t,s,o,n,i),showLabels:i.showLabels??!0}}};import{scaleTime as Vn}from"d3-scale";var Hn={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function qn(t="static"){return Hn[t]??Hn.static}var Un=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function Zn(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:Un.has(t.kind)?"fatal":"warn"}function Kn(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 Qn(){return Object.create(null)}function Jn(t,e){return e>t?-1:t>e?1:0}function ti(t){return t.occupants.map(t=>t.id).sort(Jn).join("\0")}function ei(t,e,o=0){return t.slice(0,-1).map((n,i)=>null!=n.group&&n.group===t[i+1].group?o:e)}function oi(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 ni(t,e,o){if(0===t.length)return[];const{padding:n,plotH:i,valueScale:r}=o,s=o.stackValueScale??r,a=ei(t,n,o.groupPadding??0),l=[n+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)l.push(l[o-1]+e[o-1]*s+a[o-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*s+n;if(c>i&&c>0){const t=i/c;for(let e=0;l.length>e;e++)l[e]*=t}return l}function ii(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 ri(t,e,o,n,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:w(oi(n,o)).adjacentClearance,a=ni(n,s,r);let l="hug"===r.lanePlacement?function(t,e,o,n,i,r,s){const a=t.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=ei(t,l,s.groupPadding??0),h=i.map((t,e)=>t*u+d[e]),f=l+t[0].peak.topPeak*u,p=c-l-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=p-f)return ni(t,i,s);let g=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),l=n[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=ii(a,u),h=ii(l,u);t[o]+=(g[s]+h-d)*c,i[o]+=c,t[s]+=(g[o]+d-h)*c,i[s]+=c}const r=g.map((e,o)=>0===i[o]?e:.45*e+t[o]/i[o]*.55),s=A({desired:r,minGaps:h,weights:i.map(t=>Math.max(1,t)),min:f,max:p});let l=0;for(let t=0;a>t;t++)l=Math.max(l,Math.abs(s[t]-g[t]));if(g=s,.01>l)break}return g}(n,i,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=Qn();for(const n of t)o[n.id]=e[i[n.id]];return o};si(o(l),e)>si(o(a),e)+1e-6&&(l=[...a])}const c=Qn();for(const e of t)c[e.id]=l[i[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=c[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:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function si(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 ai(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 li(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 ci(t,e){let o=0,n=1;for(let i=0;28>i;i++){const i=(o+n)/2;t>li(0,e,e,1,i)?o=i:n=i}return(o+n)/2}function ui(t,e,o){const n=e+ii(t,o),i=t.value*o/2;return[n-i,n+i]}function di(t,e,o,n){return Math.max(0,Math.min(e,n)-Math.max(t,o))/Math.max(1e-9,e-t)}function hi(t,e,o,n,i,r,s){const{valueScale:a,domain:l,mode:c="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 g=Math.max(s.startTime,l?.[0]??-1/0),y=Math.min(s.endTime,l?.[1]??1/0);if(g>=y)continue;const[m,x]=ui(f,i[s.source],a),[b,v]=ui(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 l=[g,y];if("quality"===c)for(const t of n.occupants)for(const o of e[t.id]?.samples??[])o.t>g&&y>o.t&&l.push(o.t);const h=t=>{const o=ci((t-g)/(y-g),u),l=li(m,m,b,b,o),c=li(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=ai(e[o.id],t),h=i[o.id];d=Math.max(d,di(l,c,h-u.top*a,h+u.bot*a))}return d},f=[...new Set(l)].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/(y-g)*(s.value>0?s.value:1)}}return d}function fi(t,e,o,n,i,r,s,a,l,c,u="both",d){return{crossings:t,weightedLength:e,pixelLength:si(s,o),transitOcclusion:hi(o,n,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function pi(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function gi(t,e){return t.map(t=>({t:pi(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function yi(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 mi(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 l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(l[t.kind]??99)-(l[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)||Jn(t.edge?.id??"",e.edge?.id??"")||Jn(t.side,e.side)||t.delta-e.delta)},u=a.length?ct(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;c();let f=null,p=0;for(const t of a)t.time!==f&&(f=t.time,p=0),t.sequence=p++;const g=t=>({time:t.time,phase:0,sequence:t.sequence??0}),y=[];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=g(t);y.push({...i,delta:-n,kind:"transfer-out",side:e}),y.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&&(y.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(...y),c();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 T=0;for(;M.length>T;){let t=T;for(;M.length>t+1&&M[t+1].t===M[T].t;)t++;$.push(M[T]);for(let e=T+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])}T=t+1}const R=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let C=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===C||C>t.systemInTime)&&(C=t.systemInTime);let I=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===I||t.systemOutTime>I)&&(I=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=R?R:-1/0,null!=I?I:-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!=C&&Number.isFinite(C)&&n.t>C&&r>C&&(r=C,i=n),i&&Number.isFinite(r)&&$.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let D=$;if("max"===i&&null!=d&&null!=R&&R>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}};D=[...$.filter(t=>d>t.t),{t:d,...e},{t:R,...e},...$.filter(t=>t.t>R)]}}return{samples:D,peak:k,topPeak:A,botPeak:S,localAttachments:_}}function xi(t){const e=Qn();return t.forEach((t,o)=>{for(const n of t.occupants)e[n.id]=o}),e}function bi(t,e,o){t.splice(0,t.length,...o);const n=xi(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,n)}function vi(t){const e=new Map,o=[];t.forEach((t,n)=>{if(!t.group)return void o.push({anchor:n,stableId:ti(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(ti).join("\0")}`,slots:n.slots});return o.sort((t,e)=>t.anchor-e.anchor||Jn(t.stableId,e.stableId))}function wi(t){return t.some(t=>t.group)?vi(t).flatMap(t=>t.slots):[...t]}function ki(t){return t.flatMap(t=>t.slots)}function Ai(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 Si(t,e){t.some(t=>t.group)&&bi(t,e,wi(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 _i(t,e){return u(e,e=>[t[e.source],t[e.target]],Mi)}function Pi(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 Li(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 $i=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},Ti=828*$i(8),Ri=3e3;function Ci(t,e,o,n,i,r,s){const a=[...i],l=new Map(i.map(t=>[t,ti(t)])),c=new Map;for(const t of i)for(const e of t.occupants)c.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=c.get(t.source),o=c.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 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 g=0;const y=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),k=Math.max(1,y)*(Math.max(1,s.plotH)+m*Math.max(x,i.length)+1e-6*Math.max(1,i.length-1))+1,A=4*m,S={fullCrossing:0,localCrossing:0},M=new Map,_=(t,e)=>{let n=M.get(t);n||(n=new Map,M.set(t,n));const i=n.get(e);if(null!=i)return i;const r=function(t,e,o){return w(oi([t,e],o)).adjacentClearance[0]??0}(t,e,o);return n.set(e,r),r},P=new Map(i.map((t,e)=>[t,e])),L=e.flatMap(t=>{const e=u.get(t);return e?[{source:P.get(e[0]),target:P.get(e[1]),weight:t.value>0?t.value:1}]:[]}),T=new Map;for(const t of e){const e=u.get(t);e&&T.set(t,{source:P.get(e[0]),target:P.get(e[1])})}const R=new Map,C=new Map,I=new Map,D=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)D(R,t.source,t.target),D(C,t.target,t.source),D(I,t.source,t.target),D(I,t.target,t.source);const F=e.flatMap(t=>{if(!(t=>1===R.get(t.source)?.size&&R.get(t.source).has(t.target)||1===I.get(t.source)?.size||1===I.get(t.target)?.size)(t))return[];const e=T.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),O=t=>{let e=0;for(const o of F)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*A},N=t=>{const e=new Int16Array(i.length);for(let o=0;t.length>o;o++)e[P.get(t[o])]=o;return O(e)},z=h.map(t=>{const e=T.get(t.first),o=T.get(t.second);return[e.source,e.target,o.source,o.target]}),E=new Int16Array(i.length),W=new Float64Array(i.length),B=new Float64Array(i.length+1),j=t=>{for(let e=0;t.length>e;e++)E[P.get(t[e])]=e;let e=0;for(const[t,o,n,i]of z)0>(E[t]-E[n])*(E[o]-E[i])&&e++;if(t.length>0){const e=P.get(t[0]);W[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const o=P.get(t[e-1]),n=P.get(t[e]);W[n]=W[o]+_(t[e-1],t[e])*s.valueScale+s.padding}const o=P.get(t[t.length-1]),n=W[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;W.length>e;e++)W[e]*=t}}B[0]=0;for(let e=0;t.length>e;e++)B[e+1]=B[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,n=0,i=0;for(const t of L){const e=E[t.source],r=E[t.target];if(o+=Math.abs(e-r)*t.weight,n+=Math.abs(W[t.source]-W[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;i+=(B[Math.max(e,r)]-B[o])*t.weight}}return e*k+n+i*m+O(E)+1e-6*o},Y=(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},X=n=>{const i=xi(n),r=n.slice(0,-1).map((t,e)=>_(t,n[e+1])),a=ri(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:Pi(i,e),pixelLength:si(a.centerlines,e),transitOcclusion:Y(n,i)}},G=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*k+e.pixelLength+e.transitOcclusion*m+N(o)+1e-6*e.weightedLength}),V=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+Li(o,e,u),0),S.fullCrossing++}return G(o,X(t),t)},H=(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+Li(o,e,u),0),S.fullCrossing++}const l=X(t);return G(a,{...l,transitOcclusion:hi(e,o,t,l.map,l.geometry.centerlines,n,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let q=[...a];const U=(t,e)=>Jn(l.get(t),l.get(e)),Z=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}(q),K=t=>{const e=(t=>{const e=b(t,d,t=>V(t).cost,{passes:6,compare:U,maxEvaluations:Ri});let o=V(e),n=Ri;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 l=0;const c=[];g++;for(const t of[...f.get(r)??[],...f.get(s)??[]])p[t.index]!==g&&(p[t.index]=g,c.push(t),l+=Li(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 c)h+=Li(t,d,u);S.localCrossing+=c.length;const y=V(e,o.crossings-l+h);o.cost>y.cost?(o=y,i=!0):[e[t],e[t+1]]=[r,s]}if(!i)break}return e})(t);if((t.length>8?1/0:$i(t.length)*(t.length+L.length+z.length))>Ti)return e;const o=v(t,j,{maxItems:8,maxEvaluations:5e4}),n=H(o),i=H(e);return n.crossings!==i.crossings&&i.crossings>n.crossings?o:e},Q="geometry-refine"===s.mode;if(Q||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!Q&&"inside-out"===s.laneOrder)if(Z){const t=vi(q),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||Jn(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];q=ki(n)}else{const t=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(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];q=e}}else q=Z?(t=>{let e=vi(t);if(1>=e.length)return ki(e);const o=t=>V(ki(t)).cost;e=vi(K(t)),e=Ai(e,d,U);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=b(e,n,o,{passes:6,compare:(t,e)=>Jn(t.stableId,e.stableId),maxEvaluations:Ri}),e=$(e,o,{passes:8,maxEvaluations:Ri});const i=e.length>8?1/0:$i(e.length)*(e.length+L.length+z.length);if(Ti>=i){const t=v(e,t=>j(ki(t)),{maxItems:8,maxEvaluations:5e4}),o=ki(t),n=ki(e),i=H(o),r=H(n);i.crossings!==r.crossings?e=r.crossings>i.crossings?t:e:r.cost>i.cost&&(e=t)}return e=Ai(e,d,U),ki(e)})(q):K(q);if(!Q&&"crossing-min+inside-out"===s.laneOrder&&q.length>1)if(Z){const t=vi(q);let e=V(ki(t)),o=ki(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)||Jn(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=ki(t),l=V(a);l.cost>e.cost?(t.splice(i,1),t.splice(s,0,r)):(e=l,n.cost>l.cost&&(o=a,n=l))}q=o}else{let t=V(q),e=[...q],o=t;const n=Math.floor((q.length-1)/2),i=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(t,e));for(const r of i){const i=q.indexOf(r);if(i===n)continue;q.splice(i,1),q.splice(n,0,r);const s=V(q);s.cost>t.cost?(q.splice(n,1),q.splice(i,0,r)):(t=s,o.cost>s.cost&&(e=[...q],o=s))}q=e}if((Q||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&q.length>1)if(Z){let t=vi(q),e=H(ki(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=ki(t),r=H(i,void 0,"score");e.cost>r.cost?(q=i,e=r,o=!0):[t[n],t[n+1]]=[t[n+1],t[n]]}if(!o)break}t=Ai(vi(q),d,U),q=ki(t)}else{let t=H(q,void 0,"score");for(let e=0;q.length-1>e;e++){const o=q[e],n=q[e+1],i=new Map(q.map((t,e)=>[t,e]));let r=0;const s=[];g++;for(const t of[...f.get(o)??[],...f.get(n)??[]])p[t.index]!==g&&(p[t.index]=g,s.push(t),r+=Li(t,i,u));[q[e],q[e+1]]=[n,o];const a=new Map(i);a.set(o,e+1),a.set(n,e);let l=0;for(const t of s)l+=Li(t,a,u);S.localCrossing+=s.length;const c=H(q,t.crossings-r+l,"score");t.cost>c.cost?t=c:[q[e],q[e+1]]=[o,n]}}const J=wi(a);q=wi(q);let tt=H(q);const et=H(J);if(Q){const t=N(J),e=N(q);(tt.crossings>et.crossings||tt.crossings===et.crossings&&e>t+1e-9||tt.cost>et.cost)&&(q=J,tt=et)}else tt.cost>et.cost&&(q=J,tt=et);const ot=function({order:t,after:e,nodes:o,edges:n,outgoingPartners:i,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:l}){const c=(o,i)=>{const r=[...new Set(i.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),c=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-c+1!==r.length||1>=Math.abs(2*s-c-u))return;const d=[...t];d.splice(s,1),d.splice(c+u>>1,0,o);const h=wi(d),f=l(h),p=new Set(o.occupants.map(t=>t.id)),g=new Set(i.flatMap(t=>t.occupants.map(t=>t.id))),y=n.reduce((t,e)=>p.has(e.source)&&g.has(e.target)||p.has(e.target)&&g.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-c-u)*a*Math.max(1,y))&&(t=h,e=f)};for(const[t,e]of i)r.has(t)||3>e.size||c(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)||c(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:q,after:tt,nodes:t,edges:e,outgoingPartners:R,incomingPartners:C,slotForNode:c,averageGap:m,evaluate:H});return q=ot.order,tt=ot.after,bi(i,r,q),{before:et,after:tt,initialOrder:a.map(t=>l.get(t)),evaluations:S}}function Ii(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=Qn();return n.forEach((t,e)=>{for(const o of t.occupants)i[o.id]=e}),{slots:n,slotByNode:i}}var Di=new Map,Fi=1e5,Oi=1e-9;function Ni(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function zi(t,e){return Jn(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function Ei(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 Wi(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 Bi(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 ji(t,e,o){return!!o.has(t)&&e.some(e=>!Bi(t,e,o))}function Yi(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 Xi(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=Ei(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=Yi(t,s);r[e].set(o,(r[e].get(o)??0)+n),r[o].set(e,(r[o].get(e)??0)+n)}const a=Wi(o),l=t.map(t=>a.get(t)?.weight??0),c=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(l[o],l[n])||Math.max(l[o],l[n]),r=Bi(t[o],t[n],a)?i:-i;if(Math.abs(r)>Oi&&(c[o].set(n,r),c[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[l,c]of t[a]){const t=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?i:n)===(l===e?i:l===o?n:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}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},g=(t,e)=>t>Oi||Oi>=Math.abs(t)&&e>Oi,y=(t,e,o,n)=>t>o+Oi||Oi>=Math.abs(t-o)&&e>n+Oi;let m=0;for(let o=0;32>o&&Fi>m;o++){let o=null,n=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;t.length>u;u++){for(let f=0;h.length>f&&m++<Fi;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(c,u,f);g(m,x)&&y(m,x,a,l)&&(o="move",n=u,i=-1,s=f,a=m,l=x)}if(m>=Fi)break}for(let u=0;t.length-1>u;u++){for(let p=u+1;t.length>p&&m++<Fi;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(c,u,p);g(b,v)&&y(b,v,a,l)&&(o="swap",n=u,i=p,s=-1,a=b,l=v)}if(m>=Fi)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 Gi(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 Vi(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=Di.get(i);if(r)return Ii(r.slots,o,n);const s=Qn();for(const e of t)s[e.id]=Gi(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||Jn(t.id,o.id)).map(t=>t.id)}(t,s),l=new Map(t.map(t=>[t.id,t])),c=new Map(t.map(t=>[t.id,t.group||void 0])),u=Wi(e),d=function(t,e,o,n,i,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of n)s.add(zi(t.source,t.target)),a.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=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=zi(t[o],t[n]);e instanceof Map?e.set(i,[t[o],t[n]]):e.add(i)}};for(const t of l.values())d([...t],c);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[n,i]]of c)u.has(t)&&(Ni(e[n],e[i])||Ni(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(zi(t,o))||r.has(t)&&r.has(o)&&Bi(t,o,r))||!!Ni(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(zi(t,o))}}}(a,s,n,e,c,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))&&!ji(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),l=Ei(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=Yi(t,l);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 c=Wi(o),u=t.map(t=>c.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(c.has(t[e])&&c.has(t[o])){const n=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=Bi(t[e],t[o],c)?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 g=Array(t.length).fill(-1),y=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}(g,h))&&(h=[...g],f={flow:s,affinity:a}));const l=Math.min(i+1,n.slotCount-1);for(let n=0;l>=n;n++){if(y[n].some(n=>e.conflicts(t[o],t[n])))continue;let l=0,c=0;for(const t of y[n])l+=r[o][t],c+=d[o][t];if(g[o]=n,y[n].push(o),m(o+1,Math.max(i,n),s+l,a+c),y[n].pop(),g[o]=-1,p>=75e3)return}};return g[0]=0,y[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:Xi(a,d,e,h)}),p=new Map,g=f.map(t=>(p.has(t)||p.set(t,p.size),p.get(t))),y=Array.from({length:p.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=Qn();a.forEach((t,e)=>{const o=g[e],n=y[o];n.occupants.push({id:t,end:s[t].end??-1/0});const i=l.get(t)?.group;i&&(n.group=i),m[t]=o});for(const e of[...t].sort((t,e)=>Jn(t.id,e.id)))null==m[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||Jn(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:y,slotByNode:m};return function(t,e){for(Di.has(t)&&Di.delete(t),Di.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(Qn(),e.slotByNode)});Di.size>12;){const t=Di.keys().next().value;if(null==t)break;Di.delete(t)}}(i,x),x}function Hi(t){return t.topMass+t.botMass}function qi(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>Hi(e)<Hi(t)?t:e,o[0]);let n=null;for(const o of t.samples){if(o.t>e)break;n=o}return n}function Ui(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 l=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,c]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,g=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),y=new Map;for(const t of c)y.set(t.id,new Map);for(const t of g){const o=new Map;for(const i of c){const r=qi(e[i.id],t);if(!r||1e-9>=Hi(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})=>Hi(t)))}));if(0===a.length)continue;let l=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=(l-i[o.id])/r+n.topMass-(n.boundaryOffset??0);y.get(o.id).set(t,e)}l+=e.mass*r+Math.max(0,s)}}for(const t of c){const o=e[t.id],n=l[t.id],i=y.get(t.id),r=[];for(const t of g){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=qi(o,t);null!=e&&s&&Hi(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 l}function Zi(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=i,g=Qn(),y=Qn();for(const e of t)g[e.id]=o[e.id].topPeak||0,y[e.id]=o[e.id].botPeak||0;const m="half"===u,x=Qn();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=Qn(),v=[],w=[];if(i.frozenSlots){const t=Ii(i.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(ti)}else if("reuse"===l){const n=Vi(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:g[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});Si(v,b),0===w.length&&(w=v.map(ti));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(t,e,o){const n=new Map(o.map((t,e)=>[t,e]));bi(t,e,[...t].sort((t,e)=>(n.get(ti(t))??1/0)-(n.get(ti(e))??1/0)||Jn(ti(t),ti(e))))}(v,b,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(k=Ci(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:f,domain:p}))),Si(v,b);const A=ri(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(ti),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function Ki(t){const{sx:e,sTop:o,sBot:n,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:l}=t,c=(o+n)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${l},${r} ${i},${r}`,`L${i},${s}`,`C${l},${s} ${a},${n} ${e},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:a,y:c},{x:l,y:u},{x:i,y:u}],halfWidth:(n-o)/2}}}function Qi(t,e,o,n,i,r,s,a,l={}){const c=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*c,p=o.value*c,g=e+(t.boundaryOffset??0)*c,y=n+(o.boundaryOffset??0)*c,m=t.sideMassBefore*c,x=o.sideMassAfter*c;let b,v,w,k;"top"===t.side?(b=g-m,v=b+f):(v=g+m,b=v-f),"top"===o.side?(w=y-x,k=w+p):(k=y+x,w=k-p);const A=l.sourceRunwayStart,S=l.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 Ji(t){return Math.max(18,11*t.length*.58)}function tr(t){const e=1.22*Ji(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 er(t,e){const o=t.labelX-Ji(t.labelText),n=e.labelX-Ji(e.labelText);return e.labelX+3>=o&&t.labelX+3>=n}var or=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function nr(t){return t.replace(or,(t,e,o)=>`${o},${e}`)}function ir(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 rr(t){return{...t,pathD:nr(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function sr(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:l,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:g="raw",styleRules:y,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=qn(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,l=Array.isArray(o)&&2===o.length,c=l&&Number.isFinite(o[0])&&Number.isFinite(o[1]);l&&c&&c&&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"===Zn(n)?e.push(n):o.push(n);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==qn(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),_=Vn().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:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=o,p=Number.isFinite(d)?Math.max(0,d):0,g=function(t,e){const o=Qn(),n=Qn();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),y=function(t,e,o,n="temporal"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime||Jn(t.id,e.id):(t,e)=>e.value-t.value||Jn(t.id,e.id),r="temporal"===n?(t,e)=>t.startTime-e.startTime||Jn(t.id,e.id):(t,e)=>e.value-t.value||Jn(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||Jn(t.partner,o.partner):t.latestEnd-o.latestEnd||Jn(t.partner,o.partner):(t,e)=>e.total-t.total||Jn(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,g,i);let m=Qn();for(const e of t)m[e.id]=mi(e,g,y,void 0,u);const x=Zi(t,e,m,g,{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=y.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=g.outgoing[e.id],o=g.incoming[e.id],n=new Set(t.map(t=>y.get(t.id).sourceSide)),i=new Set(o.map(t=>y.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]&&(y.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]&&(y.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)||Jn(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 l=a.sourceSide??"bot";if(o[n.source]===o[n.target]){const t=i.top>=n.value,e=i.bot>=n.value;t!==e?l=t?"top":"bot":t||e||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,n.value)}}(e,y,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,l="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(e=>!n.has(e.id)&&o.get(e.id).sourceSide===t&&c>=e.value).sort((t,e)=>e.value-t.value||Jn(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(t,g,y,v),m=Qn();for(const e of t)m[e.id]=mi(e,g,y,void 0,u);const w=Zi(t,e,m,g,{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+ei(w.slots,M,p).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(n-_)/k):1,L=Number.isFinite(l)&&l>0?Math.min(P,l):P;let $=Zi(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P});const T=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||T)&&$.slots.length>1&&(Ci(t,e,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:n,padding:M,valueScale:L,groupPadding:p,laneOrder:s,ribbonLane:h,domain:f,lanePlacement:c,mode:"geometry-refine"}),$=Zi(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(ti),lanePlacement:c,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")}(g,y)){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],l=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=yi(t,a,n),u=yi(s,l,n);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(e,m,$.centerlines,L);m=Qn();for(const e of t)m[e.id]=mi(e,g,y,o,u);$=Zi(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(ti),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}const R=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),C=[...$.slots].sort((t,e)=>(R.get(ti(t))??1/0)-(R.get(ti(e))??1/0)||Jn(ti(t),ti(e))),I=Qn();C.forEach((t,e)=>{for(const o of t.occupants)I[o.id]=e});const D=ri(t,e,m,C,I,{plotH:n,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),F=Ui(t,m,C,I,D.centerlines,L,p),O=fi(_i(I,e),Pi(I,e),e,F,C,I,D.centerlines,$.laneLifetime,L,D.verticalUtilization,h,f);m=Ui(t,m,$.slots,$.slotByNode,$.centerlines,L,p);const N=fi(_i($.slotByNode,e),Pi($.slotByNode,e),e,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,f);return{nodeData:m,sides:y,valueScale:L,padding:M,compressedPadding:12>M,centerlines:$.centerlines,laneLifetime:$.laneLifetime,slots:$.slots,slotByNode:$.slotByNode,crossingsBefore:"insertion"===s?null:O.crossings,crossingsAfter:"insertion"===s?null:N.crossings,lengthBefore:"insertion"===s?null:O.weightedLength,lengthAfter:"insertion"===s?null:N.weightedLength,layoutQualityBefore:O,layoutQuality:N}}(e,M,{plotH:w,...u,ribbonLane:s,domain:n}),{centerlines:L,nodeData:$,valueScale:T}=P,R=mt(m,x),C=[],I=[],D=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 l=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)),c=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(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&l.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=>l.has(t.id))){for(const t of o)l.delete(t.id);continue}const n=Math.max(...o.map(t=>l.get(t.id)));for(const t of o)l.set(t.id,n)}return l}(e,M,n),F=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),O=new Map;for(const t of M){const e=$[t.source]?.localAttachments.get(t.id),o=$[t.target]?.localAttachments.get(t.id);e&&o&&O.set(t.id,Qi(e,L[t.source],o,L[t.target],T,_,s,n,{minRun:a,sourceRunwayStart:D.get(t.id)}))}const N=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 l=n(r),c=Math.min(...t.map(t=>t.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?l:Math.min(l,n(e))})),d=Math.min(l,Math.max(c,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,O,D,_,s,F),z=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,N,D,_,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,z,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=gi(t,i),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,l=t=>s(t)+r[t].botMass*o;let c=`M${n(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)c+=` L${n(r[t].t)},${a(t)}`;c+=` L${n(r[r.length-1].t)},${l(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${n(r[t].t)},${l(t)}`;return c+" Z"}(i,L[t.id],T,_,n);if(!a)return;const l=gi(i,n),u=l.find(t=>t.topMass+t.botMass>0)||l[0],h=L[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*T/2;let f,p,g=c(t.id,e),m=g,x=.5;const b=t.__raw??t;if(y&&y.length>0){const t=vt(b,y,R(b));"string"==typeof t.fill?g=t.fill:null!=t.fill&&G(t.fill)&&(p=t.fill,g=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:g),"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,l=o.centerlines[t],c=gi(s.samples,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],d=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],h=n(u.t),f=n(d.t),p=t=>n(pi(t,i)),g=[],y=(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,c=s?n:n-20,u=s?Math.min(r,n+20):n,d=Math.max(h,c);if(r>d){const[e,o]=yi(t,l,a);g.push({pathD:y(d,e,r,o),x0:c,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]=yi(t,l,a);g.push({pathD:y(n,o,r,s),x0:e,x1:i,from:1,to:0})}}}}return g}(t.id,M,P,_,n,z);C.push({id:t.id,pathD:a,fill:g,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 W=new Map;e.forEach((t,e)=>W.set(t.id,e)),M.forEach(t=>{const e=N.get(t.id);if(!e)return;const o=W.get(t.source)??0,n=c(t.source,o),{pathD:i,bezier:r}=Ki(e),s=t.__raw??t,a="function"==typeof l?Number(l(s)):l,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;I.push({id:t.id,pathD:i,fill:n,opacity:u,rawDatum:s,bezier:r})});const B=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-Ji(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)er(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)er(o[t],o[e])&&(n=Math.min(n,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,n)}}}(n,o),n}(C,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:nr(t.pathD),gradientStubs:t.gradientStubs?.map(rr),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*Ji(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]=tr(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}(B,i,r):B,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+Ji(t.labelText):Ji(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:I.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:nr(t.pathD),bezier:ir(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:S,xScale:_}}import{Fragment as ar,jsx as lr,jsxs as cr}from"react/jsx-runtime";var ur="var(--semiotic-grid, #94a3b8)",dr="var(--semiotic-text-secondary, #475569)",hr="var(--semiotic-text-secondary, #94a3b8)",fr=.22;function pr(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var gr=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=!pr(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,fr):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!pr({__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?fr: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=!pr(o,r,i);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:n?fr:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...n&&e?{opacity:fr}:{}},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&&pr({__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 yr(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 mr(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 xr(t,e,o={}){return Me(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var br={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||Se(Ce(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:mr([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=De(n.theme).colors.categorical,l=ye(o,a),c="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?ke(u,c,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=ve(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=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=At(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:Me(i.nodeStyle||(g?(t,e)=>({...p(t,e),...g(t,e)}):p),Ce(i)),...n,showLegend:(n.showLegend??!!e)&&!!e}}},vr={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=De(n.theme).colors.categorical,a=new Map,l=i.nodeStyle??(t=>({fill:e?ve(t?.data||t,e,void 0):Co(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=At(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=Me(c?(t,e)=>({...l(t),...c(t,e)}):l,{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}}},wr={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=De(n.theme).colors.categorical,s=new Map,a=yr(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrCirclePackColorBy:l(t)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?ke(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,f=n.nodeStyle||i.nodeStyle,p=yt(t=>{const n=t?.data||t;return{fill:i.colorByDepth?xe[Number(t?.depth||0)%xe.length]:e?l?ve({__ssrCirclePackColorBy:l(n)},"__ssrCirclePackColorBy",d??void 0):ve(n,e,d??void 0):Co(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},i.styleRules,mt(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:xr(p,f,Ce(i))}}},kr={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",l=De(n.theme).colors.categorical,c=o??n.colorScheme??l,u=ye(c,l),d=yr(r,s),h="__ssrOrbitColorBy",f="function"==typeof e?e:null,p=e?ke(f?d.map(t=>({[h]:f(t)})):d,f?h:e,c):void 0,g=yt(t=>{const o=t.data||t,n=Number(t.depth??0);return{fill:i.colorByDepth?0===n?u[0]:xe[n%xe.length]:e?f?ve({[h]:f(o)},h,p):ve(o,e,p):u[0],stroke:"#fff",strokeWidth:1,opacity:0===n?1:.85}},i.styleRules,mt(e,"value"),t=>t?.data||t);return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:c,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:Me(g,Ce(i)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...n,showLegend:(n.showLegend??!(!e||i.colorByDepth))&&!(!e||i.colorByDepth)}}},Ar={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",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,f=i.systemOutTimeAccessor,p=i.xExtentAccessor||"xExtent",g=i.groupBy,y=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:mr([],x,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],k=v.map(t=>{const e=m(c,t)+"",o=m(p,t),n=i.nodeLabel?m(i.nodeLabel,t):e,s={id:e,label:null==n?e:n+"",__raw:t},a=g?m(g,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(y,t),n={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(l,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}),[S,M]=n.size??[600,400],_=n.margin,P="vertical"===i.orientation?"vertical":"horizontal",L=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,P),$={...L,..._},T=(n.showLegend??!!e)&&!!e,R=n.legendPosition??"right";T&&("right"===R?$.right=Math.max($.right,140):"left"===R?$.left=Math.max($.left,140):"top"===R?$.top=Math.max($.top,50):"bottom"===R&&($.bottom=Math.max($.bottom,80)));const C=$,I=S-C.left-C.right,D=M-C.top-C.bottom,F=ye(o,De(n.theme).colors.categorical,Gt),O="function"==typeof e?e:null,N=O?v.map(t=>({_cat:O(t)})):v,z=O?"_cat":"string"==typeof e?e:void 0,E=o??[...F],W=z?ke(N,z,E):null,B=new Map;for(const t of k)B.set(t.id,t.__raw);const j=(t,o)=>{if(e&&B.has(t)){const o=B.get(t);return O?ve({_cat:O(o)},"_cat",W??void 0):ve(o,"string"==typeof e?e:"id",W??void 0)}return F[o%F.length]},Y=uo(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:j(m(c,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),X=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:G,layoutConfig:V,issues:H,xScale:q}=sr({nodes:k,edges:A,domain:w,plotW:I,plotH:D,orientation:P,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:j,showLabels:X,styleRules:i.styleRules,colorBy:e,valueAccessor:l,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(H.length>0){const t=H.map(Kn).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const U=G?function(t){const e=t.layout,o=t.nodes,n=t.orientation,i=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,l=t.showQualityReadout??!1,c=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,f=t.toTime,p=t.xScale,{centerlines:g,laneLifetime:y,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=y[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),T=null!==(w??null)&&null!=k&&null!=A,R=l&&(T||u.length>0)?cr("g",{fill:hr,fontSize:10,textAnchor:"end",children:[T&&cr(ar,{children:[cr("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(A.pixelLength)]}),cr("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)=>cr("text",{x:i,y:T?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,C=b?lr("text",{x:i,y:"vertical"===n?-3:2,fontSize:10,fill:hr,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,I=(t,e)=>h?h(t,e):ur;return cr("g","vertical"===n?{children:[R,C,$.map(({index:t,coordinate:e})=>lr("line",{x1:0,y1:e,x2:i,y2:e,stroke:ur,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[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=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=p(o.start),a=p(o.end),l=I(t.id,e);return cr("g",{children:[lr("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),lr("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),lr("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),lr("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:ur}),$.map(({tick:t,index:e,coordinate:o})=>{const n=f(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return cr("g",{transform:`translate(-4,${o})`,children:[lr("line",{x2:-6,stroke:ur}),lr("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:dr,children:i})]},e)})]}:{children:[R,C,$.map(({index:t,coordinate:e})=>lr("line",{x1:e,y1:0,x2:e,y2:r,stroke:ur,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[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=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=p(o.start),a=p(o.end),l=I(t.id,e);return cr("g",{children:[lr("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),lr("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),lr("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),lr("line",{x1:P,y1:r+4,x2:L,y2:r+4,stroke:ur}),$.map(({tick:t,index:e,coordinate:o})=>{const n=f(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return cr("g",{transform:`translate(${o},${r+4})`,children:[lr("line",{y2:6,stroke:ur}),lr("text",{y:20,textAnchor:"middle",fontSize:11,fill:dr,children:i})]},e)})]})}({layout:G,nodes:k,orientation:P,plotW:I,plotH:D,timelineExtent:"vertical"===P?D:I,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:j,toTime:t=>r(t),xScale:t=>Number(q(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:gr,layoutConfig:V,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:e,colorScheme:o,...U&&{backgroundGraphics:U},...n,showLegend:T,...Y&&{legend:Y,legendPosition:R},__legendIncludesAutomatic:!0,margin:C}}},Sr={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:mr([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=De(n.theme).colors.categorical,a=new Map,l="string"==typeof e?e:"__ssrSankeyColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?ke(c,l,o??n.colorScheme??s):void 0,d=t=>({fill:e?ve(t?.data||t,e,u):Co(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=At(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=ve(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=ve(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:Me(i.nodeStyle||f,Ce(i)),edgeStyle:Me(i.edgeStyle||p,Ce(i)),colorScheme:o,...n,showLegend:(n.showLegend??!!e)&&!!e}}},Mr={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=De(n.theme).colors.categorical,s=new Map,a=yr(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreeColorBy:l(t)})):a,u=l?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?ke(c,u,o??n.colorScheme??r):void 0,h=!1!==i.showLabels,f=n.nodeStyle||i.nodeStyle,p=yt(t=>{const n=t?.data||t;return{fill:i.colorByDepth?xe[Number(t?.depth||0)%xe.length]:e?l?ve({__ssrTreeColorBy:l(n)},"__ssrTreeColorBy",d??void 0):ve(n,e,d??void 0):Co(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},i.styleRules,mt(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:xr(p,f,Ce(i))}}},_r={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=De(n.theme).colors.categorical,s=new Map,a=yr(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreemapColorBy:l(t)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?ke(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,f=i.labelMode,p=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,g=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,y=n.nodeStyle||i.nodeStyle,m=yt(t=>{const n=t?.data||t;return{fill:i.colorByDepth?xe[Number(t?.depth||0)%xe.length]:e?l?ve({__ssrTreemapColorBy:l(n)},"__ssrTreemapColorBy",d??void 0):ve(n,e,d??void 0):Co(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},i.styleRules,mt(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!=g&&{paddingTop:g},colorScheme:o,...n,showLegend:(n.showLegend??!(!e||i.colorByDepth))&&!(!e||i.colorByDepth),nodeStyle:xr(m,y,Ce(i))}}},Pr={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Lr}from"d3-scale";function $r(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=ke(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=ut(t))}return t=>({fill:e&&r?ve(t,e,r):ge,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?Ae(t,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}function Tr(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var Rr={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=Lr(re(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),l=i.styleRules?yt(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},Tr):a,c=!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:l,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n,...void 0===n.legend&&c?{legend:c}:{}}}},Cr={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??$r(r,e,o,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?yt(s,i.styleRules,mt(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||Pr,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},Ir={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??$r(r,e,o,{pointRadius:"number"==typeof i.pointRadius?i.pointRadius:5,fillOpacity:.85,strokeWidth:1}),a=i.nodeIdAccessor||"id",l=i.cartogramLayout||("sparkline"===i.mode?"strip":"radial"),c="sparkline"===i.mode,u="strip"===l,d=i.styleRules?yt(s,i.styleRules,mt(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:l},...n,cartogramChrome:{showRings:i.showRings??!0,showNorth:i.showNorth??(!u&&!c),showRingLabels:i.showRingLabels??!u,costLabel:i.costLabel}}}},Dr={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",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:t=>t[l],d="function"==typeof c?c:t=>t[c],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,g="function"==typeof p,y=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?g?ke(y.map(t=>({[m]:p(t)})),m,o||"category10"):ke(y,p,o||"category10"):null,b=t=>p&&x?ve(t,p,x):"#007bff";let v=1/0,w=-1/0;for(const t of y){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:y,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||Pr,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}}},Fr={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})},Or={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})},Nr={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({...Or.buildProps(t,e,o,n,i),customLayout:k,showAxes:!1})},zr={frameType:"xy",buildProps:(t,e,o,n,i)=>({...Fr.buildProps(t,e,o,n,i),customLayout:s,showAxes:!1})};import*as Er from"react";function Wr(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 Br(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 jr(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?xt(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,l={fill:null==a?e:Br(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,vt(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}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 Xr(t,e,o){return"function"==typeof o?o(t,e):t[o]}function Gr(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 Vr(t,e,o){return Math.max(e,Math.min(o,t))}function Hr(t,e){const o=Gr(t);return null!=o&&o>0?o:e}function qr(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Ur(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 Zr}from"d3-scale";import{scaleLinear as Kr}from"d3-scale";function Qr(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 l=Math.min(r-1,a?.(e)??s),c=Math.max(1,r-l);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:i(e),y:l+c/2,width:n,height:c}}})}function Jr(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 ts}from"d3-scale";function es(t){if(Array.isArray(t)&&t.length>=2){const e=Gr(t[0]),o=Gr(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=Gr(e.x),n=Gr(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function os(t){return Array.isArray(t)?t.map(es).filter(t=>null!=t):[]}function ns(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:Vr(t.x,e.plot.x,e.plot.x+e.plot.width),y:Vr(t.y,e.plot.y,e.plot.y+e.plot.height)}}function is(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 rs(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=Vr(e,0,1)*is(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 ss(t,e){const o=rs(t,Math.max(0,e-.02)),n=rs(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 as(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 ls}from"d3-scale";function cs(t,e,o){return ye(t,e,o)}function us(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&we(o,t)||"#4e79a7":e=>{if(o){const t=we(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 ds(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 hs(t){const e=xs(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 fs(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function ps(t){return`gauntlet:${t}:core`}function gs(t,e){return`gauntlet:${t}:positive:${e}`}function ys(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var ms={left:28,top:76,rightInset:30,thickness:8};function xs(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return ms;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 bs(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function vs(t,e,o,n){const i=xs(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,l=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:l(t,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:l(e,s,a)}}function ws(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 ks(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 As(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,l=(e??[]).filter(t=>!1!==t.enabled),c=Math.max(1,l.length),u=.22*n,d=c>1?(.78*n-u)/(c-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:l.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=fs(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...fs(t,e,o.positiveAccessor,s)],l=[...fs(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...fs(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(fs(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:fs(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??ks(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=bs(o),l=Math.max(3,28*a),c=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??c,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},g=[{...d,id:ps(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:l},spawnAt:d.spawnAt??t.startedAt,datum:p}],y=vs(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,o);g[0].x=y.x,g[0].y=y.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=ws(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),l=vs(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,o);g.push({id:gs(t.id,e),x:l.x,y:l.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:ps(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&&g.push(function(t,e,o,n,i,r,s){const a=bs(r),l=e.radius??Math.max(2,7.2*a),c=vs(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,l,r);return{id:ys(t.id,e.id,o),x:c.x,y:c.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:ps(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,y.x,y.y,o,d.spawnAt??t.startedAt))}),g}(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:hs(e)}}}function Ss(t=[]){const e=Object.create(null);for(const[o,n]of t)e[o]=n;return e}function Ms(...t){const e=Ss();for(const o of t)for(const[t,n]of Object.entries(o??{}))e[t]=n;return e}function _s(t){return Ms(t)}function Ps(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 Ls(t){const e=Ss(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:_s(e.initialMetrics),metrics:_s(e.metrics),productIds:[...e.productIds],history:Ps(e.history)}])),o=Ss(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:_s(e.metrics),sourceIds:[...e.sourceIds],history:Ps(e.history)}])),n=Ss(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?_s(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:_s(t.input.metrics)},metrics:_s(t.metrics),loss:{amount:t.loss.amount,metrics:_s(t.loss.metrics)},history:Ps(t.history)}}var $s=1e-9;function Ts(t,e){return e>t?-1:t>e?1:0}function Rs(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Cs(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(Ts)}function Is(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[Rs("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function Ds(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function Fs(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(Rs("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(Rs("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,l=e.categories?new Set(e.categories):null,c=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=>!l||l.has(t.category)).filter(t=>!c||c.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Ts);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(Rs("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function Os(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 Ns(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 zs(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(Rs("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function Es(t,e,o){const n=Cs(e);e.length||t.diagnostics.push(Rs("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(Rs("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(Rs("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(Rs("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(Rs("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 Ws(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+$s)&&t.diagnostics.push(Rs("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...Is(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+$s)&&t.diagnostics.push(Rs("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 Bs(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?Ms(n,t.metrics):_s(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 js(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>$s&&t.diagnostics.push(Rs("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function Ys(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(Rs("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...Is(e.metricsDelta,n+".metricsDelta")),zs(t,e.outletId,n+".outletId");const o=Fs(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(Rs("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=Os(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&&Ds(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&Ns(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(Rs("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=Cs(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(Rs("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(Rs("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(Rs("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(...Is(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?_s(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=Os(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void Ns(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Cs(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(Rs("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(Rs("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(Rs("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=Os(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void Ns(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(Rs("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(Rs("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(Rs("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=Es(t,e.sourceIds,n+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,l=function(t,e,o,n){if(!e?.length)return[];const i=Cs(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),l=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(Rs("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(Rs("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(Rs("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),l.length&&t.diagnostics.push(Rs("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,n,l)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,n+".basisRelationIds");if(!s||!l||!o||t.diagnostics.some(t=>"error"===t.severity))return;const c=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e=Ss();for(const o of t)Ds(e,o.metrics);return e}(s);if(!Ws(t,c,u,e.loss,n+".loss"))return;const d=c-(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=Os(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&js(t,o,d,n+".productId"),p=Bs(o,e.sourceIds,d,u,t,h,f),h&&!zs(t,p.outletId,n+".productId"))return;i.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,Ds(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;Ns(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,l),Ns(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&&Ns(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(!zs(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(Rs("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(js(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=Ms(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=n,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const l=Os(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(l),t.state.history.push(l),Ns(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(Rs("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=Es(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(Rs("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=Cs(r);s.length&&t.diagnostics.push(Rs("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),l=r.filter((t,e)=>!a[e]),c=r.filter(t=>i.products[t]);l.length&&t.diagnostics.push(Rs("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,n+".products",l)),c.length&&t.diagnostics.push(Rs("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,n+".products",c));for(const[o,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(Rs("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...Is(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!Ws(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(Rs("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),g=p.reduce((t,e)=>t+e,0);if(Math.abs(g-d)>$s)return void t.diagnostics.push(Rs("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,n+".products"));const y=_s(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))y[t]=Number(y[t]??0)-o;const m=Os(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],l=d>$s?p[r]/d:1/e.products.length,c=Ss(Object.entries(y).map(([t,e])=>[t,e*l])),h=o.metrics??s.metrics??c,f=Bs({...s,amount:p[r],metrics:h},[u.id],p[r],_s(h),t,!0,m);zs(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),Ns(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)Ns(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){zs(t,e.outletId,n+".outletId");const o=Fs(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(Rs("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=Os(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&&Ns(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...Is(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)Ds(i.metrics,e.metricsDelta);else if("components"in e.target){const r=Fs(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)Ds(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Cs(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(Rs("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(Rs("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)Ds(i.products[t].metrics,e.metricsDelta)}return void i.history.push(Os(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(Os(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(Rs("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function Xs(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[Rs("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=Ls(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(Ys(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 Gs=[900,520],Vs=[{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}],Hs=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),qs=1e-9;function Us(t,e){return e>t?-1:t>e?1:0}function Zs(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Ks(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(Us)}function Qs(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Js(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(Zs("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function ta(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(Zs("error","invalid-metrics","Metrics must be a numeric object.",o)),Ss();const n=Ss();for(const[i,r]of Object.entries(t)){const t=Qs(r);null!=t?n[i]=t:e.push(Zs("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function ea(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 oa(t){const{id:e,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=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+qs).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+qs&&i.push([r,t]),r=Math.max(r,e);return e>r+qs&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:l,restitution:c,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 na(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 ia(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?na(t):1}function ra(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:ia(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function sa(t){return"crucible:component:"+encodeURIComponent(t)}function aa(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>qs?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function la(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 ca(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 ua(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 da(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 ha(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>Us(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>Us(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=la(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)||Us(t.id,e.id));const o=ca(i.length,da(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>n.set(t.id,o[e]))}return n}(n,e),l=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*aa(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(c=t.id,"crucible:product:"+encodeURIComponent(c)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=ua(t)??"__chamber__",o=c.get(e)??[];o.push(t),c.set(e,o)}const u=new Map;for(const[t,o]of c){const n=ca(o.length,da(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=na(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=aa(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:sa(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var fa=ha;function pa(t){return Array.isArray(t)?t.map(pa):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>Us(t,e)).map(([t,e])=>[t,pa(e)])):t}function ga(t,e=t.duration){const o=function(t,e){const o=Qs(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-qs,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=Ls(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+qs)break;const a=Xs(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 ya(t){const e=function(t){const e=[];t.length||e.push(Zs("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=Ks(t.map(t=>t.id));o.length&&e.push(Zs("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=Qs(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(Zs("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(Zs("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(Zs("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=ea(t.outlets??Vs),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?Ms(t.metrics):void 0})),r=function(t,e,o){const n=[],i=Ks(t.map(t=>t.id));i.length&&n.push(Zs("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,l;if(t.id.trim()||n.push(Zs("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=Qs(t.at.time);if(null==r||0>r||r>o+qs)return void n.push(Zs("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 c=function(t,e,o){const n=t.find(t=>qs>=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}:qs>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=c.phase,l=c.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void n.push(Zs("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(Zs("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,l=0===o?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):n.push(Zs("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=Ss(),n=[];let i=0;const r=Ss();t.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((Js(s,a,t.idAccessor,l,e,`data.${a}.id`)??l)+"").trim();if(!c)return void e.push(Zs("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(c);const u=Qs(Js(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(Zs("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=ta(Js(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=Js(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=Hs.has(f)?f:"active";Hs.has(f)||e.push(Zs("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[c]));const g=Js(s,a,t.labelAccessor,(s.label??s.name??c)+"",e,`data.${a}.label`)+"",y=Js(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,c)||(o[c]={id:c,label:g,category:y,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:Ms(h),metrics:Ms(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=Ks(n);s.length&&e.push(Zs("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=ta(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:Ss(),relations:Ss(),input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:Ss()},history:[]},diagnostics:e}}(t),a=function(t=Gs,e=Vs){const o=Math.max(1,Qs(t[0])??900),n=Math.max(1,Qs(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},l=i?Math.max(16,.14*n):Math.min(78,.16*n),c={x:r,y:n-r-l,width:Math.max(1,o-2*r),height:l},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=c.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)),g={x:f.x+(f.width-p)/2,y:f.y-(i?10:24),width:p,height:i?12:28},y=ea(e),m={left:y.filter(t=>"left"===(t.side??"bottom")),right:y.filter(t=>"right"===t.side),bottom:y.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,c.y-f.y-f.height-(i?4:12))})}),x.sort((t,e)=>y.findIndex(e=>e.id===t.id)-y.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:f,mouth:g,projection:c,outlets:x}}(t.size??Gs,n),l=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(...oa({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}),...oa({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}),...oa({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),c=function(t,e){const o=[],n=new Set(e.map(t=>t.id)),i=Ks(e.map(t=>t.id)),r=Ks(t.map(t=>t.id));return i.length&&o.push(Zs("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(Zs("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(Zs("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(Zs("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(Zs("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(Zs("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(Zs("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),ta(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>Us(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(pa(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>Us(t.id,e.id)),i=n.map(t=>t.amount),r=la(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}}(ia(o.seed)),a=e.mouth.x+e.mouth.width/2,l=e.chamber.y+Math.max(18,.18*e.chamber.height),c=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=aa(t.amount,i,o.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:sa(t.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+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,...c],p={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:ra(t.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},g=ga(p),y=Object.values(g.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=y.length?[Zs("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];return p.terminalState=g.state,p.terminalSpawns=fa(g.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...g.diagnostics,...m],p}import*as ma from"react";function xa(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 ba,curveMonotoneY as va,curveCardinal as wa,curveCatmullRom as ka,curveStep as Aa,curveStepBefore as Sa,curveStepAfter as Ma,curveBasis as _a,curveNatural as Pa}from"d3-shape";function La(t){switch(t){case"monotoneX":return ba;case"monotoneY":return va;case"cardinal":return wa;case"catmullRom":return ka;case"step":return Aa;case"stepBefore":return Sa;case"stepAfter":return Ma;case"basis":return _a;case"natural":return Pa;default:return null}}function $a(t,e,o){if(null==e)return o;if(G(e)){return U(e,t)||e.background&&dt(t,e.background)||o}return"string"!=typeof e?e:dt(t,e)||o}function Ta(t,e,o){const n=$a(t,e,o);if("string"==typeof n&&n.trim().startsWith("var(")){const e=dt(t,o);return e&&!e.trim().startsWith("var(")?e:o}return n}function Ra(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 l=t.createLinearGradient(n,i,r,s);for(const e of a)l.addColorStop(Math.max(0,Math.min(1,e.offset)),Ca(t,e,o));return l}function Ca(t,e,o){const n=e.color??o,i=dt(t,n)||n;if(null==e.opacity)return i;const r=Math.max(0,Math.min(1,e.opacity)),[s,a,l]=xa(t,i);return`rgba(${s},${a},${l},${r})`}import{jsx as Ia,jsxs as Da}from"react/jsx-runtime";function Fa(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 Oa(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",l="number"==typeof e.strokeWidth?e.strokeWidth:1.25,c="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 Da(ma.Fragment,{children:[Ia("defs",{children:Ia("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Ia("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Ia("polygon",{points:e,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${o})`}),Ia("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return Da(ma.Fragment,{children:[Ia("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),Ia("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 Na,jsx as za,jsxs as Ea}from"react/jsx-runtime";var Wa="var(--semiotic-text, #26323a)",Ba="var(--semiotic-text-secondary, #6c7377)",ja="var(--semiotic-primary, #b8792d)",Ya="var(--semiotic-danger, #9f3d35)",Xa="var(--semiotic-success, #356b63)";function Ga(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 Va({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 Ea("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[Ea("defs",{children:[Ea("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[za("stop",{offset:"0",stopColor:ja,stopOpacity:"0.03"}),za("stop",{offset:"0.66",stopColor:ja,stopOpacity:"0.1"}),za("stop",{offset:"1",stopColor:Ya,stopOpacity:"0.18"})]}),za("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:za("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Wa,strokeOpacity:"0.08",strokeWidth:"1"})})]}),za("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:Wa,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),za("path",{d:Ga(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),za("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:Wa,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:za("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,l=Math.max(0,n.duration)/i*t.phaseRail.width,c=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return Ea("g",{children:[za("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,l-2),height:t.phaseRail.height,rx:2,fill:c?n.color??ja:u?Xa:Wa,fillOpacity:c?.68:u?.28:.09}),46>l?null:za("text",{x:a+l/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:c?Wa:Ba,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),t.outlets.map(t=>Ea("g",{children:[za("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?Ya:Xa),fillOpacity:"0.1",stroke:t.color??("left"===t.side?Ya:Xa),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:za("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:Ba,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 Ha({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),l=e.projection.height>48?21:4,c=Math.max(5,e.projection.height-l-5);return za("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*c),h=e.projection.x+o*a+.18*a;return Ea("g",{children:[za("rect",{x:h,y:e.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?Ya:"complete"===t.status?ja:Xa,fillOpacity:"0.68"}),l>4&&a>=34?Ea(Na,{children:[za("text",{x:h+.32*a,y:e.projection.y+c+10,fill:Ba,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}),Ea("text",{x:h+.32*a,y:e.projection.y+c+19,fill:Wa,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Fa(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}function qa(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 Ua,jsx as Za,jsxs as Ka}from"react/jsx-runtime";function Qa(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=Wr(s),l=Math.max(2,Math.round(e)),c=a.plot.width/l,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[f,p]=n?.valueExtent??[0,l],g=p===f?1:p-f,y=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*c).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return Ka("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?Ka(Ua,{children:[Array.from({length:l+1},(t,e)=>{const o=a.plot.x+e*c;return Za("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)}),Za("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),Za("path",{d:y,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?Za("text",{x:a.plot.x+(e+.5)*c,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)/g))*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 Ka("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[Za("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:Za("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 Ja(t,e,o){if(!1!==o&&e)return({size:o})=>{const n=[Number(o[0])||760,Number(o[1])||360],i=Wr(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},l=e.windowPlot??s,c=l.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,g=l.x+Math.max(0,Math.min(1,p===f?0:(e.watermarkValue-f)/(p-f)))*l.width;return Ka("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:[Za("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?Ka("g",{children:[Za("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}),Za("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=l.x+i*c,a=e.closedWindowCount>i,h=r?.secondary??0;return Ka("g",{children:[Za("rect",{x:s,y:d,width:c,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=>Za("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,Ka("text",{x:s+c/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),Za("text",{x:s+c/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=>Za("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)),Za("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),Za("line",{"data-testid":"event-drop-watermark",x1:g,x2:g,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),Ka("text",{x:Math.min(s.x+s.width-4,g+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?Ka("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 tl(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const n=[Number(o[0])||700,Number(o[1])||380],i=Wr(n),r=Jr(i.plot,t.length,e),s=i.plot.y+i.plot.height;return Ka("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:[Za("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,l=r.centerX(e),c=s-o;return Ka("g",{children:[Za("rect",{x:l-a/2,y:c,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"}),Za("text",{x:l,y:Math.max(i.plot.y+12,c-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),Za("text",{x:l,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 el(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function ol(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],n=Wr(o),i=n.plot.y+n.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,l=[{label:el(r),x:t.xRange[0]},{label:el(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:el(s),x:t.xRange[1]}];return Ka("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=>Ka("g",{children:[Za("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}),Za("text",{x:n.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),Ka("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)),Za("line",{x1:t.xRange[0],x2:t.xRange[1],y1:i,y2:i,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(t=>Ka("g",{children:[Za("line",{x1:t.x,x2:t.x,y1:i,y2:i+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),Za("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{jsx as nl}from"react/jsx-runtime";function il(t,e,o={},n){if(!1===e||!t)return;const{volume:i,stages:r,groups:s,groupCompletion:a}=t,l=new Map(i.stages.map(t=>[t.id,t])),c=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=l.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=c.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 _({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 rl(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=Wr(i),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),l=r.plot.y+6;return nl("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 c=Math.max(2,i.value/s*a),u=Math.max(8,.35*r.width);return nl("rect",{x:r.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function sl(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}import{jsx as al,jsxs as ll}from"react/jsx-runtime";function cl(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 ll("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 ll("g",{children:[al("path",{d:sl(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),al("path",{d:sl(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?al("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=>ll("g",{children:[n&&a.has(t.sensorId)?al("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?al("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?al("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 ul,jsx as dl,jsxs as hl}from"react/jsx-runtime";function fl({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 dl(ul,{children:t.gates.map(r=>hl("g",{children:[dl("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?dl("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 pl({layout:t,states:e,compact:o=!1}){return o?dl("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:dl(fl,{layout:t,compact:!0,showLabels:!1})}):hl("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[dl("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}),dl("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}),dl("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),dl(fl,{layout:t,compact:!1,showLabels:!0}),hl("g",{children:[dl("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}),dl("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),hl("g",{children:[dl("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}),dl("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),dl("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 gl({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 hl("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:[dl("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 hl("g",{children:[dl("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}),dl("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 yl={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 ml(t){return t.map(t=>({...t,spawnAt:void 0}))}function xl(t,e){return t?e?o=>Er.createElement(Er.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function bl(t,e,o){const n=e[o];return"boolean"==typeof n?n:!0!==t.__compactMode}var vl=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function wl(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return vl[(e>>>0)%vl.length]}var kl={frameType:"physics",layout:yl,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,a=i.seed??1,u=Math.max(1,Math.round(i.pegRows??s-1)),d="mechanical"===i.mode,h=d?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=Vr(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=Ur(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:u,seed:a}):Array.isArray(t)?t:[],f=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:a}=t,u=Wr(s),d=e.map((t,e)=>Gr(Xr(t,e,o))).filter(t=>null!=t),h=function(t){if(!t)return;const e=Gr(t[0]),o=Gr(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(a),f=h?.[0]??(d.length?Math.min(...d):0),p=h?.[1]??(d.length?Math.max(...d):1),g=p===f?1:p-f,y=Zr().domain([0,n]).range([u.plot.x,u.plot.x+u.plot.width]),m=Array.from({length:n},()=>0),x=[];e.forEach((t,e)=>{const r=Gr(Xr(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-f)/g*n)));m[s]+=1,x.push({id:(t.id??"galton-"+e)+"",x:y(s+.5),y:u.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 b=u.plot.y+u.plot.height;return{config:Yr(r,[...l({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...c({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:y,yTop:u.plot.y-400,yBottom:b,wallThickness:6})],"GaltonBoardChart"),initialSpawns:x,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot:u.plot,valueExtent:[f,p]}}}({data:h,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:a,size:r,valueExtent:d?[0,u]:void 0});return{...n,config:f.config,initialSpawns:ml(f.initialSpawns),projectionRows:f.projectionRows,foregroundGraphics:xl(Qa(f.projectionRows,s,bl(n,i,"showProjection"),f.metadata,i.referenceLines),n.foregroundGraphics),bodyStyle:jr(e||i.colorBy||(d?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},Al={frameType:"physics",layout:yl,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:u,timeScale:d=1}=t,h=Wr(c),f=e.map((t,e)=>Gr(Xr(t,e,o))).filter(t=>null!=t),p=Gr(u?.[0]),g=Gr(u?.[1]),y=f.length?Math.min(...f):0,m=f.length?Math.max(...f):y+i.size,x=Math.min(p??y,y),b=Math.max(g??m,m),v=Math.floor(x/i.size)*i.size,w=Math.max(1,Math.ceil((b-v+i.size)/i.size)),k=f.length?Math.max(...f):0,A="function"==typeof r?r(k):Gr(r?.value)??k-(r?.delay??i.size),S=Math.max(0,Math.min(w,Array.from({length:w},(t,e)=>e).reduce((t,e)=>v+(e+1)*i.size>A?t:t+1,0))),M=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}}(h,s),_=v+w*i.size,P=Kr().domain([v,_]).range([M.windowPlot.x,M.windowPlot.x+M.windowPlot.width]),L=Array.from({length:w},()=>({value:0,secondary:0})),$=[];e.forEach((t,e)=>{const r=Gr(Xr(t,e,o));if(null==r)return;const a=Gr(Xr(t,e,n))??r,l=Math.max(0,Math.min(w-1,Math.floor((r-v)/i.size))),c=A>=v+(l+1)*i.size;L[l].value+=c?0:1,L[l].secondary+=c?1:0,$.push({id:(t.id??"event-"+e)+"",x:Math.max(M.windowPlot.x+s,Math.min(M.windowPlot.x+M.windowPlot.width-s,P(r))),y:h.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:l,late:c}})});const T=h.plot.y+h.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=Kr().domain([n,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,l=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),c=t=>s===a?e:l+(t-a)/(s-a)*(e-l),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:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:S,gutter:M.gutter,plot:h.plot,windowCount:w,windowPlot:M.windowPlot,windowSize:i.size,windowStart:v},h.plot.y+.28*h.plot.height);return{config:Yr(a,[...l({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Qr({idPrefix:"eventdrop-window",count:w,xScale:t=>P(v+t*i.size),yTop:M.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?M.wallTop:e+1.25*s},yBottom:T,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:$,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:d},projectionRows:L.map((t,e)=>({label:`${v+e*i.size}-${v+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:M.gutter,lidSegments:R,lateCount:L.reduce((t,e)=>t+e.secondary,0),plot:h.plot,windowPlot:M.windowPlot,watermarkValue:A,windowCount:w,windowSize:i.size,windowStart:v}}}({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:ml(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:xl(Ja(s.projectionRows,s.metadata,bl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:jr(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},Sl={frameType:"physics",layout:yl,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=Hr(i,1),u=Wr(a),d=[],h=new Map,f=new Map,p=[];function g(t){let e=h.get(t);return null==e&&(e=d.length,d.push(t),h.set(t,e)),e}e.forEach((t,e)=>{g((Xr(t,e,o)??"unknown")+"")});const y=Math.max(1,d.length),m=Jr(u.plot,y,r),x=Math.max(0,m.tubeWidth/2-r-1),b=d.map(()=>[]);e.forEach((t,e)=>{const i=(Xr(t,e,o)??"unknown")+"",s=g(i),a=n?Gr(Xr(t,e,n)):1,l=Math.max(0,Math.round((a??0)/c)),d=m.centerX(s);for(let o=0;l>o;o+=1){const n=f.get(i)??0,a=m.perRow>1?((m.perRow>1?n%m.perRow:0)/(m.perRow-1)*2-1)*x:0;f.set(i,n+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:u.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 v=b.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;v>t;t+=1)for(const e of b)e.length>t&&p.push(e[t]);const w=u.plot.y+u.plot.height,k=[...l({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],A=u.plot.y-400;for(let t=0;y>t;t+=1){const e=m.centerX(t);for(const o of[-1,1])k.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*m.tubeWidth/2,y:(A+w)/2,width:6,height:w-A}})}return{config:Yr(s,k,"UnitPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(t=>({label:t,value:f.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=Hr(t.unitValue,1),r=Ur(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),l=a.reduce((t,e)=>t+e,0)||1,c=n-o.length,u=a.map(t=>t/l*c),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:ml(a.initialSpawns),projectionRows:a.projectionRows,foregroundGraphics:xl(tl(a.projectionRows,i.ballRadius??5,bl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:jr(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},Ml={frameType:"physics",layout:yl,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:u,settle:d}=t,h=Wr(a),f=Ur(s),p=[],g=[],y=new Map;e.forEach((t,e)=>{const s=Gr(Xr(t,e,o));if(null==s)return;const a=n?(Xr(t,e,n)??"All")+"":"All",l=i?Gr(Xr(t,e,i)):null,c=Vr(null!=l&&l>0?l:r,2,18);!function(t){let e=y.get(t);null==e&&(e=g.length,g.push(t),y.set(t,e))}(a),p.push({datum:t,index:e,value:s,group:a,radius:c})});const m=p.map(t=>t.value),x=c?Gr(c[0]):null,b=c?Gr(c[1]):null,v=m.length?Math.min(...m):0,w=m.length?Math.max(...m):1;let k=x??v,A=b??w;if(k===A&&(k-=.5,A+=.5),k>A){const t=A;A=k,k=t}const S=Math.max(r,...p.map(t=>t.radius)),M=h.plot.x+S+8,_=h.plot.x+h.plot.width-S-8,P=ts().domain([k,A]).range([M,_]),L=Math.max(1,g.length),$=Math.min(Math.max(28,3*S),h.plot.height/4),T=h.plot.y+$,R=Math.max(0,h.plot.y+h.plot.height-$-T),C=t=>{const e=y.get(t)??0;return 1===L?h.plot.y+.54*h.plot.height:T+e/(L-1)*R},I=new Map,D=p.map((t,e)=>{I.set(t.group,(I.get(t.group)??0)+1);const o=P(t.value),n=C(t.group),i=(f()-.5)*t.radius*1.6,r=(f()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:d?o+i:Vr(o+(e%9-4)*t.radius*2.5,M,_),y:d?n+r:h.plot.y-18-e%12*t.radius,vx:d?0:22*(f()-.5),vy:d?0:24+18*f(),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,l({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.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(u??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:D,projectionRows:g.map(t=>({label:t,value:I.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[k,A],xRange:[M,_],groups:g.map(t=>({label:t,y:C(t),count:I.get(t)??0})),plot:h.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:ml(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:xl(ol(s.metadata,bl(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:jr(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},_l={frameType:"physics",layout:yl,buildProps:(t,e,n,r,s)=>{const l=r.size??[900,420],c=Array.isArray(s.stages)?s.stages:[],u=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const n=t.size,r=Wr(n),s=Vr(t.ballRadius??6,2,18),l=t.seed??1,c=Ur(l),u=t.idAccessor,d=t.stageAccessor??"stage",f=t.groupBy,p=t.groupLabelAccessor,g=t.workAccessor,m=t.radiusAccessor,x=t.groupCompletion??(f?"allAbsorbed":"none"),b=t.springStiffness??.28,v=t.springDamping??.72,w=!0===t.settle,k=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),A=P({width:n[0],height:n[1],shape:"lane",padX:Math.max(28,r.plot.x),padY:Math.max(36,r.plot.y+8),stages:k,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),_=new Map(A.stages.map((t,e)=>[t.id,e])),L=new Map(A.stages.map(t=>[t.id,t])),$=A.stages[0].id,T=A.stages[0],R=new Set(e.filter(t=>t.absorb).map(t=>t.id)),C=e.map(t=>{const e=L.get(t.id)??T;return function(t,e){const n={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 o({...n,kind:t.kind??"sink",force:as(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...n.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return S({...n,kind:t.kind??"force-field",force:as(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...n.attributes,primitive:"portal",targetStage:t.portal.targetStageId}})}if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return a({...n,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:as(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...n.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return M({...n,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:as(t.force,8),attributes:{...n.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?F({...n,kind:t.kind??"force-field",force:as(t.force,14),damping:t.damping??.02,attributes:{...n.attributes,primitive:"routeSurface"}}):h({...n,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...n.attributes,primitive:"forceField"}})}(t,{x:e.x,y:A.midY,width:e.width,height:A.bottomY-A.topY})});C.unshift(F({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(A.left+A.right)/2,y:A.midY,width:A.right-A.left,height:A.bottomY-A.topY-12,force:8,damping:.012,semanticItem:!1}));const I=new Map;for(const t of A.stages)I.set(t.id,0);const D=[];t.data.forEach((t,e)=>{const o=(u?Xr(t,e,u)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(Xr(t,e,d)??$)+"",i=_.has(n)?n:$;I.set(i,(I.get(i)??0)+1);const r=f?(Xr(t,e,f)??"")+"":void 0,a=r&&p?(Xr(t,e,p)??r)+"":r,l=g?Gr(Xr(t,e,g))??1:1,c=m?Gr(Xr(t,e,m)):null,h=Vr(null!=c&&c>0?c:s,2,18);D.push({datum:t,id:o,stageId:i,groupId:r||void 0,groupLabel:a||void 0,work:l,radius:h,index:e})});const O=new Map,N=new Map;for(const t of D){if(!t.groupId)continue;const e=O.get(t.groupId)??[];e.push(t.id),O.set(t.groupId,e),t.groupLabel&&N.set(t.groupId,t.groupLabel)}const z=Vr(t.groupAnchorAlong??.55,.15,.9),E=A.left+(A.right-A.left)*z,W=Array.from(O.keys()),B=W.map((t,o)=>{const n=O.get(t)??[],r=W.length>1?A.topY+28+o/Math.max(1,W.length-1)*(A.bottomY-A.topY-56):A.midY;return i({id:t,label:N.get(t)??t,bodyIds:n,anchor:{x:E,y:r},x:E,y:r,completion:"allAbsorbed"===x?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),j=D.filter(t=>R.has(t.stageId)).map(t=>t.id),Y=y(B,j),X=new Map(B.map(t=>[t.id,t])),G=D.map((t,e)=>{const o=L.get(t.stageId)??T,n=o.x+(c()-.5)*Math.min(24,.2*o.width),i=A.boundaryY(n,"top")+t.radius+10,r=A.boundaryY(n,"bottom")-t.radius-10,s=r>i?i+c()*Math.max(1,r-i):A.midY,a=w?n:A.left+18+e%7*4,l=w?s:A.midY+(c()-.5)*(A.bottomY-A.topY)*.35,u=[{target:{type:"point",x:n,y:s},restLength:.45*t.radius,stiffness:b,damping:v}];if(t.groupId){const e=X.get(t.groupId);e?.anchor&&!R.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:a,y:l,vx:w?0:40+40*c(),vy:w?0:20*(c()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:w?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}}}),V={kernel:{seed:l,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:A.colliders,fixedDt:1/60,maxSubsteps:8},H=A.stages.map(t=>({label:t.label??t.id,value:I.get(t.id)??0})),q=e.map(t=>{const e=L.get(t.id)??T;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:I.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:V,initialSpawns:G,initialSpawnPacing:w?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:H,metadata:{kind:"process-flow",plot:r.plot,volume:A,stages:q,groups:B,groupCompletion:Y,regionEffects:C}}}({data:Array.isArray(t)?t:[],stages:c,size:l,idAccessor:s.idAccessor,stageAccessor:s.stageAccessor||"stage",groupBy:s.groupBy,groupLabelAccessor:s.groupLabelAccessor,workAccessor:s.workAccessor,radiusAccessor:s.radiusAccessor,ballRadius:s.ballRadius??6,seed:s.seed??1,groupCompletion:s.groupCompletion,groupAnchorAlong:s.groupAnchorAlong,settle:s.settle??!0,gravityX:s.gravityX,gravityY:s.gravityY}),d=u.metadata;return{...r,config:u.config,initialSpawns:ml(u.initialSpawns),projectionRows:u.projectionRows,regionEffects:d?.regionEffects,backgroundGraphics:xl(il(u.metadata,bl(r,s,"showChrome"),{},s.chromeOptions),r.backgroundGraphics),foregroundGraphics:xl(rl(u.projectionRows,u.metadata,bl(r,s,"showProjection")),r.foregroundGraphics),bodyStyle:jr(e||s.colorBy||s.groupBy,"#4e79a7",{styleRules:s.styleRules,valueAccessor:s.workAccessor||s.stageAccessor||"stage"})}}},Pl={frameType:"physics",layout:yl,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=As({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:ml(s.initialSpawns),projectionRows:[],backgroundGraphics:xl(bl(n,i,"showChrome")?Er.createElement(pl,{layout:s.layout,states:s.states,compact:!0===n.__compactMode}):void 0,n.backgroundGraphics),foregroundGraphics:xl(bl(n,i,"showProjection")?Er.createElement(gl,{layout:s.layout,states:s.states}):void 0,n.foregroundGraphics),bodyStyle:jr(e||i.colorBy)}}},Ll={frameType:"physics",layout:yl,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=ya({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,Qs(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,Qs(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,l=ga(s,a).state,c=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 Ds(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:_s(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)||Ts(t.key,e.key))}(l,c),d=c.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)??qa(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",g=!1===i.showChrome?null:Er.createElement(Va,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),y=!1===i.showProjection?null:Er.createElement(Ha,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:ml(ha(l,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??wl(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??wl(a)}}(t,l,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,l),renderBodySVG:Oa,backgroundGraphics:xl(g,n.backgroundGraphics),foregroundGraphics:xl(y,n.foregroundGraphics)}}},$l={frameType:"physics",layout:yl,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:u,particleRate:d,pathAccessor:h,pathConstraint:f="path",reducedMotion:p,seed:g,size:y,sourceAccessor:m,targetAccessor:x,throughputAccessor:b}=t,v=Wr(y),w=Ur(g),k=new Map,A=new Map,S=[];function M(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=(Xr(t,e,r)??t.id??e)+"",n=Gr(Xr(t,e,s)),i=Gr(Xr(t,e,a));if(null!=n&&null!=i){const t={x:n,y:i};k.set(o,t),S.push(t)}A.set(o,(t.label??t.name??o)+"")});const _=[];n.forEach((t,e)=>{const o=M(Xr(t,e,m)),n=M(Xr(t,e,x)),i=Math.max(0,Gr(Xr(t,e,b))??0),r=os(h?Xr(t,e,h):void 0),s=r.length?r:os(t.path??t.points??t.route);s.forEach(t=>S.push(t)),_.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const P=($=S,"normalized"===(L=e)||"pixels"===L?L:$.length>0&&$.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var L,$;const T=new Map;for(const[t,e]of k)T.set(t,ns(e,v,P));const R=[];for(const t of _){let e=t.rawPath.map(t=>ns(t,v,P));if(2>e.length){const o=T.get(t.source),n=T.get(t.target);o&&n&&(e=[o,n])}else T.has(t.source)||T.set(t.source,e[0]),T.has(t.target)||T.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(A.has(t.source)||A.set(t.source,t.source),A.has(t.target)||A.set(t.target,t.target),R.push({...t,path:e,packetCount:0}))}const C=Hr(d,.12),I=Math.max(1,Math.round(i)),D=R.map(t=>Math.max(1,Math.round(t.throughput*C))),F=D.reduce((t,e)=>t+e,0),O=F>I?I/F:1;R.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(D[e]*O))});let N=R.reduce((t,e)=>t+e.packetCount,0);for(;N>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,N-=1}const z=new Map,E=new Map,W=[],B=Hr(o,90),j=Hr(u,4);R.forEach((t,e)=>{z.set(t.target,(z.get(t.target)??0)+t.throughput),E.set(t.source,(E.get(t.source)??0)+t.throughput);const o=is(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=p?i:Vr(.12+.84*i+.04*(w()-.5),.04,.98),s=p?r:Math.max(0,r-(.18+.12*w())),a=rs(t.path,s),l=rs(t.path,r),c=ss(t.path,s),u={x:-c.y,y:c.x},d=(w()-.5)*j*1.5;W.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:p?0:c.x*B+10*(w()-.5),vy:p?0:c.y*B+10*(w()-.5),mass:.8,spawnAt:p?0:.04*e+n/32,shape:{type:"circle",radius:j},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:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target},springs:"none"!==f&&p?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*j,stiffness:26,damping:4.25}]:void 0})}});const Y=Math.max(18,5*j),X=Array.from(T,([t,e])=>({nodeId:t,label:A.get(t)??t,sensorId:"physical-flow-node-"+qr(t),point:e})),G=X.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:Y,height:Y}})),V=Object.fromEntries(X.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),H=Yr(g,[...l({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...G],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*j),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=I,H.eviction="oldest",H.observation={...H.observation,sensors:V};const q=Array.from(T,([t,e])=>({id:t,label:A.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+qr(t),incoming:z.get(t)??0,outgoing:E.get(t)??0})),U=R.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:H,initialSpawns:W,projectionRows:q.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:P,particleCount:W.length,totalThroughput:R.reduce((t,e)=>t+e.throughput,0),plot:v.plot,nodes:q,links:U}}}({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:ml(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:xl(cl(s.metadata,{showNodeLabels:!1!==i.showNodeLabels,showSensors:!1!==i.showSensors,showStaticFlow:!1!==i.showStaticFlow}),n.foregroundGraphics),bodyStyle:jr(e||i.colorBy||"source")}}},Tl={frameType:"physics",layout:yl,buildProps:(e,o,n,i,r)=>{const s=i.size??[700,380],a=De(i.theme),l=function(e){const o=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}}}(e.config,e.chartId,e.onObservation),n=cs(e.colorScheme,e.themeCategorical,Gt),i=Wr(e.size),r={data:e.data,scales:{x:ls().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:ls().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:us(n,e.colorScheme),config:e.layoutConfig??{},world:new t(o)},s=e.skipLayout?{}:e.layout(r)??{},a=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})}([...s.initialSpawns??s.bodies??[]],s.constraints);return{config:ds(o,s),context:r,initialSpawnPacing:s.initialSpawnPacing,initialSpawns:a,result:s}}({chartId:r.chartId,colorScheme:n,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:kt(a)??{},size:s,themeCategorical:a.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:l.config,initialSpawns:ml(l.initialSpawns),projectionRows:[],bodyStyle:l.result.bodyStyle??jr(o||r.colorBy),backgroundGraphics:xl(i.backgroundGraphics,l.result.backgroundOverlays),foregroundGraphics:xl(i.foregroundGraphics,l.result.overlays)}}};import*as Rl from"react-dom/server";import*as Cl from"react";import*as Il from"react-dom/server";function Dl(t){return new Set(Array.isArray(t)?t:[t])}function Fl(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Ol(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Nl(t,e,o){return t+(e-t)*o}function zl(){return"undefined"!=typeof performance?performance.now():Date.now()}function El(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 Wl(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function Bl(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function jl(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 Yl(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 Xl(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 Gl(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}var Vl=Object.create(null);function Hl(t){Vl[t.chartType]=t}var ql="undefined"==typeof window||"undefined"==typeof document,Ul=new Set;function Zl(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;Kl(n)&&0===o.length&&Ql(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)&&Ql(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 Kl(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(Kl))}function Ql(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function Jl(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 tc(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function ec(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=tc(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=nt(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:tc(t.y1Accessor,"y1"),getBottom:tc(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as oc,scaleLog as nc,scaleSymlog as ic,scaleTime as rc}from"d3-scale";function sc(t,e,o,n,i,r=!1){const s=new Map;for(const a of t){const t=e(a),l=o(a);if(null==t||null==l||Number.isNaN(t)||Number.isNaN(l))continue;const c=Math.floor(t/n)*n;let u=s.get(c);if(u||(u={start:c,end:c+n,total:0,categories:new Map,...r?{rows:[],categoryRows:new Map}:{}},s.set(c,u)),u.total+=l,u.rows?.push(a),i){const t=i(a);if(u.categories.set(t,(u.categories.get(t)||0)+l),u.categoryRows){let e=u.categoryRows.get(t);e||(e=[],u.categoryRows.set(t,e)),e.push(a)}}}return s}function ac(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),l=Array(s.length),c=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],l[t]=e.rawY,c[t]=e.d}return{type:"line",path:a,rawValues:l,style:i,datum:c,group:r}}function lc(t,e,o,n,i,r,s,a){const l=[];for(const r of t){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const c=e.x(t),u=a?a(r):i;l.push({px:c,topY:e.y(s),botY:e.y(u),rawY:s})}l.sort((t,e)=>t.px-e.px);const c=Array(l.length),u=Array(l.length),d=Array(l.length);for(let t=0;l.length>t;t++){const e=l[t];c[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:c,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function cc(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,l=0,c=0;for(const t of e){const e=o(t,s)||0;a+=(2*c+e)*(e-(o(t,r)||0)),l+=e,c+=e}const u=i.get(r)??0;i.set(s,u-(l>0?a/(2*l):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 uc(t,e,o,n,i,r,s){const a=o(t),l=n(t);if(!Number.isFinite(a)||!Number.isFinite(l))return null;const c={type:"point",x:e.x(a),y:e.y(l),r:i,style:r,datum:t};return void 0!==s&&(c.pointId=s),c}function dc(t,e,o,n,i,r,s,a){const l=o(t),c=n(t);if(!Number.isFinite(l)||!Number.isFinite(c))return null;const u={type:"symbol",x:e.x(l),y:e.y(c),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function hc(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 fc(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 pc(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function gc(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return nc().domain(t).range(o).clamp(!0)}return"symlog"===t?ic().domain(e).range(o):"time"===t?rc().domain([new Date(e[0]),new Date(e[1])]).range(o):oc().domain(e).range(o)}function yc(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function mc(t,e){const o=new W(t.capacity);return t.forEach(()=>o.push(e)),o}function xc(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function bc(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 vc=new WeakMap;function wc(){return this.updateResults.last}function kc(){return this.updateResults.last}function Ac(t){return this.updateResults.subscribe(t)}function Sc(t){this.config.layoutSelection=t}function Mc(){vc.set(this,!0)}function _c(){const t=!0===vc.get(this);return vc.delete(this),t}function Pc(t){Object.assign(t.prototype,{getLastUpdateResult:wc,getUpdateSnapshot:kc,subscribeUpdateResult:Ac,setLayoutSelection:Sc,markStylePaintPending:Mc,consumeStylePaintPending:_c})}var Lc=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],$c=["scene-style","data-paint","accessibility","evidence"],Tc=(t,e)=>({retainedData:t,invalidations:e}),Rc=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Cc=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ic=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Dc=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Fc=["scene-geometry","data-paint","accessibility","evidence"],Oc=["scene-style","data-paint","accessibility","evidence"],Nc=[],zc={chartType:Tc("rebuild",Rc),runtimeMode:Tc("rebuild",Rc),xAccessor:Tc("rebuild",Rc),yAccessor:Tc("rebuild",Rc),timeAccessor:Tc("rebuild",Rc),valueAccessor:Tc("rebuild",Rc),y0Accessor:Tc("rebuild",Rc),boundsAccessor:Tc("rebuild",Rc),band:Tc("rebuild",Rc),openAccessor:Tc("rebuild",Rc),highAccessor:Tc("rebuild",Rc),lowAccessor:Tc("rebuild",Rc),closeAccessor:Tc("rebuild",Rc),candlestickRangeMode:Tc("rebuild",Rc),accessorRevision:Tc("rebuild",Rc),groupAccessor:Tc("rebuild",Cc),categoryAccessor:Tc("rebuild",Cc),lineDataAccessor:Tc("rebuild",Cc),colorAccessor:Tc("rebuild",Oc),sizeAccessor:Tc("rebuild",Fc),symbolAccessor:Tc("rebuild",Fc),pointIdAccessor:Tc("rebuild",Fc),xScaleType:Tc("preserve",Ic),yScaleType:Tc("preserve",Ic),xExtent:Tc("preserve",Ic),yExtent:Tc("preserve",Ic),extentPadding:Tc("preserve",Ic),scalePadding:Tc("preserve",Ic),axisExtent:Tc("preserve",Ic),yAxisExtent:Tc("preserve",Ic),binSize:Tc("preserve",Ic),normalize:Tc("preserve",Ic),heatmapAggregation:Tc("preserve",Ic),heatmapXBins:Tc("preserve",Ic),heatmapYBins:Tc("preserve",Ic),arrowOfTime:Tc("preserve",Dc),baseline:Tc("preserve",Dc),stackOrder:Tc("preserve",Dc),sizeRange:Tc("preserve",Dc),curve:Tc("preserve",Dc),areaGroups:Tc("preserve",Dc),customLayout:Tc("preserve",Dc),layoutConfig:Tc("preserve",Dc),layoutMargin:Tc("preserve",Dc),symbolMap:Tc("preserve",Fc),showValues:Tc("preserve",Fc),heatmapValueFormat:Tc("preserve",Fc),lineStyle:Tc("preserve",Oc),pointStyle:Tc("preserve",Oc),areaStyle:Tc("preserve",Oc),barStyle:Tc("preserve",Oc),swarmStyle:Tc("preserve",Oc),waterfallStyle:Tc("preserve",Oc),candlestickStyle:Tc("preserve",Oc),boundsStyle:Tc("preserve",Oc),gradientFill:Tc("preserve",Oc),lineGradient:Tc("preserve",Oc),semanticLineStops:Tc("preserve",Oc),colorScheme:Tc("preserve",Oc),themeCategorical:Tc("preserve",Oc),themeSemantic:Tc("preserve",Oc),themeSequential:Tc("preserve",Oc),themeDiverging:Tc("preserve",Oc),barColors:Tc("preserve",Oc),decay:Tc("preserve",Oc),pulse:Tc("preserve",Oc),staleness:Tc("preserve",Oc),layoutSelection:Tc("preserve",Oc),annotations:Tc("preserve",["overlay","accessibility","evidence"]),windowSize:Tc("preserve",Nc),windowMode:Tc("preserve",Nc),maxCapacity:Tc("preserve",Nc),clock:Tc("preserve",Nc),transition:Tc("preserve",Nc),introAnimation:Tc("preserve",Nc),onLayoutError:Tc("preserve",Nc)},Ec=Tc("preserve",Dc),Wc=class{constructor(){this.tracker=new e}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}},Lc)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},$c):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=zc[n]??Ec;"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 Bc}from"d3-quadtree";var jc=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=Bc().x(t=>t.x).y(t=>t.y).addAll(i)}},Yc=class t{constructor(t){if(this.xExtent=new E,this.yExtent=new E,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 Wc,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 jc,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 l=!1;const c=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=c.get(o);if(null==e)continue;a=!0;const s=n.get(e);if(null==s)continue;const l=Bl(t,s,r);l>i&&(i=l)}a&&(l=jl(o,i,s)||l);continue}const e=c.get(o.datum);if(null==e)continue;const i=n.get(e);l=jl(o,null==i?0:Bl(t,i,r),s,a)||l}return l}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new W(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=nt(t.timeAccessor||t.xAccessor,"time"),this.getY=nt(t.valueAccessor||t.yAccessor,"value")):(this.getX=nt(t.xAccessor,"x"),this.getY=nt(t.yAccessor,"y")),this.getGroup=at(t.groupAccessor),this.getCategory=at(t.categoryAccessor),this.getSize=t.sizeAccessor?nt(t.sizeAccessor,"size"):void 0,this.getColor=at(t.colorAccessor),this.getSymbol=at(t.symbolAccessor),this.getY0=t.y0Accessor?nt(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=ec(t),this.getPointId=at(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?nt(t.openAccessor,"open"):void 0,this.getHigh=nt(t.highAccessor,"high"),this.getLow=nt(t.lowAccessor,"low"),this.getClose=o?nt(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new W(t.windowSize))}currentTime(){return this.config.clock?.()??zl()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=mc(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?nt(this.config.timeAccessor||this.config.xAccessor,"time"):nt(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(tt(n));if(this.xIsDate=i||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>J(e[t]):t=>J(o(t))}}yc(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)xc(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=xc(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 l="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 pc(o,n);const s=r[0],a=r[1],l=r[r.length-1],c=r[r.length-2];return pc("log"===i&&s>0?[s/Math.sqrt(a/s),l*Math.sqrt(l/c)]:[s-(a-s)/2,l+(l-c)/2],n)}(r,this.getX,s,e.xExtent,e.xScaleType):pc(s,e.xExtent),c=pc(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,l=new Set;let c=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),l.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>c&&(c=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,g;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(l).sort((t,e)=>t-e),o=cc(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,c=r?0:s>0?s*e.extentPadding:1;g=[n-c,i+c]}else if("diverging"===e.baseline){const t=Array.from(l).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;g=[o-s,n+s]}else g=[0,c+(r?0:c>0?c*e.extentPadding:1)];return{yDomain:g,stackExtentCache:{key:s,yDomain:g}}}({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&&!u&&o.size>0?c=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=sc(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?c=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||c[0]===1/0||(c=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]}(c,r,this.resolvedRibbons),c=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}(c,{exactMode:h,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:a}));c=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]]}(c,e.yExtent,!!u),({xDomain:l,yDomain:c}=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}}(l,c,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:oc().domain(n).range(t),y:gc(e.yScaleType,i,[o.height-s,s])}}return{x:gc(e.xScaleType,n,[s,o.width-s]),y:gc(e.yScaleType,i,[o.height-s,s])}}({config:e,layout:t,xDomain:l,yDomain:c}),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=gc,l=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),c=s[1]>s[0];this.scales={x:a(this.config.xScaleType,n,r[0]>r[1]?[t.width-l,l]:[l,t.width-l]),y:a(this.config.yScaleType,i,c?[l,t.height-l]:[t.height-l,l])},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??me},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=Jl({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 Zl({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,Vl[s]?.buildScene);var s;if(!r)return function(t){(function(t){return Vl[t]})(t)||ql&&(Ul.has(t)||(Ul.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=(l=r(i,e,t),Array.isArray(l)?{nodes:l,binBoundaries:[]}:{nodes:l.nodes,binBoundaries:l.binBoundaries});var l;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?El(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=Wl(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=Wl(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]=El(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]=El(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=El(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=El(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&&Yl(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=Xl(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:Gl(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:Gl(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:Gl(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:Gl(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=Xl(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=zl()){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 l=new Set,c=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=Xl(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(c.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){l.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=Gl(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=Gl(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=Gl(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=Gl(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=Gl(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=Gl(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=Gl(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=Gl(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){l.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=Gl(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=Gl(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!c.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(!l.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=Ol(t,o.activeTransition),r=Fl(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=Nl(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=Nl(o.x,t._targetX,r),t.y=Nl(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Nl(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=Nl(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=Nl(o.x,t._targetX,r),t.y=Nl(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Nl(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=Nl(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=Nl(o.x,t._targetX,r),t.y=Nl(o.y,t._targetY,r),void 0!==o.w&&(t.w=Nl(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Nl(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:Nl(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=Nl(o.x,t._targetX,r),t.y=Nl(o.y,t._targetY,r),void 0!==o.w&&(t.w=Nl(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Nl(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:Nl(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=Nl(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Nl(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Nl(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Nl(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Nl(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Nl(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]=Nl(e[n][0],o[n][0],r),t.path[n][1]=Nl(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Nl(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]=Nl(e[o][0],n[o][0],r),t.topPath[o][1]=Nl(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]=Nl(o[e][0],i[e][0],r),t.bottomPath[e][1]=Nl(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 l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||me,c=new Map;for(let t=0;s.length>t;t++)c.set(s[t],l[t%l.length]);return{map:c,cache:{key:a,map:c,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 l=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||me;if(0===l.length)return{color:null,groupColorCounter:s};const c=l[s%l.length];if(s++,n.set(e,c),n.size>i){const t=n.keys().next().value;void 0!==t&&n.delete(t)}return{color:c,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=Dl(t),o=this.getPointId,n=t=>e.has(o(t));bc(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=Dl(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||!et(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),l=r||!et(o,s);(a||l)&&(t?(this.getX=nt(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=nt(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=nt(this.config.xAccessor,"x"),this.getY=nt(this.config.yAccessor,"y")),l&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=ec(this.config)),n=!0,i=!0)}if("groupAccessor"in t&&!et(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?at(this.config.groupAccessor):void 0,n=!0),"categoryAccessor"in t&&!et(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?at(this.config.categoryAccessor):void 0,n=!0),"sizeAccessor"in t&&!et(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?nt(this.config.sizeAccessor,"size"):void 0,n=!0),"symbolAccessor"in t&&!et(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?at(this.config.symbolAccessor):void 0,n=!0),"colorAccessor"in t&&!et(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?at(this.config.colorAccessor):void 0,n=!0),"y0Accessor"in t&&!et(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?nt(this.config.y0Accessor,"y0"):void 0,n=!0,i=!0),("boundsAccessor"in t&&!et(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=ec(this.config),n=!0,i=!0),"pointIdAccessor"in t&&!et(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?at(this.config.pointIdAccessor):void 0,n=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!et(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!et(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!et(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!et(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?nt(this.config.openAccessor,"open"):void 0,this.getHigh=nt(this.config.highAccessor,"high"),this.getLow=nt(this.config.lowAccessor,"low"),this.getClose=e?nt(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}};Yc.GROUP_COLOR_MAP_CAP=1e3;var Xc=Yc;function Gc(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 Vc(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 l=t.scales.x(e),c=t.scales.y(s),u=t.scales.y(a);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(u)&&(i.push([l,c]),r.push([l,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:Gc(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function Hc(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 qc(t,e,o){const n=[];for(const i of o){const o=Vc(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function Uc(t,e,o,n){const i=[];for(const r of n){const n=Vc(t,e,o,r);n&&i.push(n)}return i}function Zc(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,l=uc(r,t.scales,t.getX,i,s,n,a);l&&o.push(l)}}}function Kc(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function Qc(t){return!(!t._pulseIntensity||0>=t._pulseIntensity)}function Jc(t,e,o=.3){Qc(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 tu(t,e,o,n=.35){Qc(e)&&(t.globalAlpha=e._pulseIntensity*n,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",o?t.fill(o):t.fill())}Pc(Xc);import{area as eu,line as ou}from"d3-shape";function nu(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 iu(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],[l,c]=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(nu(u+d*((e+i)/2),o,n),[s+(l-s)*e,a+(c-a)*e],[s+(l-s)*i,a+(c-a)*i])}}return i}function ru(t,e){const o=La(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=eu().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 su(t,e){const o=La(e.curve);if(t.beginPath(),o)ou().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 au=(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=$a(t,e.style.fill,"#4e79a7"),s=e._decayOpacities,a=!(!e.colorThresholds?.length||!e.rawValues||e.rawValues.length!==e.topPath.length),l=!!e.strokeColorBands?.length;if(s&&s.length===e.topPath.length&&!a&&!l){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=dt(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 c=e.style.opacity??1;if(ru(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=Ra(t,e.fillGradient,"string"==typeof r?r:"#4e79a7",0,o,0,n);t.fillStyle=i||r,t.globalAlpha=c}else t.globalAlpha=(e.style.fillOpacity??.7)*c,t.fillStyle=r;t.fill(),e._pulseIntensity&&e._pulseIntensity>0&&(ru(t,e),tu(t,e));const u=e.style.strokeWidth??2;if(e.style.stroke&&"none"!==e.style.stroke&&u>0){t.globalAlpha=c;const o=dt(t,e.style.stroke)||e.style.stroke,n=a||l||!e.strokeGradient||2>e.topPath.length?null:Ra(t,e.strokeGradient,o,e.topPath[0][0],0,e.topPath[e.topPath.length-1][0],0);if(t.lineWidth=u,t.setLineDash([]),l){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=dt(t,a)||a,t.globalAlpha=c*(s.opacity??1),su(t,e),t.stroke(),t.restore()}}else if(a){const n=iu(e.topPath,e.rawValues,e.colorThresholds,o);for(const e of n){t.beginPath(),t.strokeStyle=dt(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,su(t,e),t.stroke()}void 0!==i&&1>i&&t.restore(),o&&t.restore(),t.globalAlpha=1}};import{line as lu}from"d3-shape";function cu(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 l=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;l>n&&(r*=n/l),l>a-n&&(r*=(a-n)/l),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 uu=(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=dt(t,i)||i,s=e.style.strokeWidth??2,a=e.colorThresholds,l=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){cu(t,e.path,r,s,e.style.opacity??1,e.style.strokeLinecap||"butt"),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt";continue}const c=La(e.curve),u=a&&a.length>0&&l&&l.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?Ra(t,e.strokeGradient,r,e.path[0][0],0,e.path[e.path.length-1][0],0):null;if(t.strokeStyle=o||r,c)lu().x(t=>t[0]).y(t=>t[1]).curve(c).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=iu(e.path,l,a,r);for(const e of o){t.beginPath(),t.strokeStyle=dt(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=$a(t,e.style.fill,e.style.fill),c&&!u)lu().x(t=>t[0]).y(t=>t[1]).curve(c).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"}},du=(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=$a(t,o.style.fill,"#4e79a7"),t.fill();const n=o.style.strokeWidth??1;o.style.stroke&&"none"!==o.style.stroke&&n>0&&(t.strokeStyle=$a(t,o.style.stroke,o.style.stroke),t.lineWidth=n,t.stroke()),function(t,e,o=.6){if(!Qc(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=$a(t,i.style.fill,"#4e79a7"),t.fill();const s=i.style.strokeWidth??1;i.style.stroke&&"none"!==i.style.stroke&&s>0&&(t.strokeStyle=$a(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(Qc(t)||null!=i&&"string"!=typeof i||1>e){s(),r(t);continue}const a=t.style.strokeWidth??1,l=`${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&&l!==n&&s(),n=l,o.push(t),2048>o.length||s()}s()}finally{t.restore()}}},hu={chartType:"line",buildScene:(t,e)=>function(t,e){const o=t.groupData(e),n=[],i=t.config.annotations?.filter(Kc).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=Hc(t.ribbons);if(r.length>0&&n.push(...qc(t,e,r)),i.length>0)for(const e of o)n.push(...Uc(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=ac(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 Zc(t,o,n),n}(t,e),canvasRenderers:[au,uu,du]};function fu(t){return Pe(t)}var pu={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}=Hc(t.ribbons);if(r.length>0&&n.push(...qc(t,e,r)),i.length>0)for(const e of o)n.push(...Uc(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,l=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=lc(e.data,t.scales,t.getX,t.getY,r,o,e.key,l),c=fu(t.config.gradientFill);c&&(i.fillGradient=c),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 Zc(t,o,n),n}(t,e),canvasRenderers:[au,du]},gu={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:l}=function(t,e,o,n,i,r,s,a="zero"){const l=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&l.add(e)}const c=Array.from(l).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 c){let o=0;for(const n of t)o+=u.get(n.key)?.get(e)||0;d.set(e,o||1)}}const h=cc(c,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],g=new Map,y=new Map,m=new Map,x=new Map;for(const t of c)y.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=[],l=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:l,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),p.push(t)}a=[],l=[]};for(const o of c){const i=t.has(o);let s,c,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),c=s+u,m.set(o,c)):(s=x.get(o),c=s+u,x.set(o,c)):(s=y.get(o),c=s+u,y.set(o,c));const p=e.x(o);l.push([p,e.y(s)]),a.push([p,e.y(c)]),n.set(o,c)}h(),g.set(o.key,n)}return{nodes:p,stackedTops:g}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),c=a;if(t.config.pointStyle){const e=new WeakMap;for(const n of o){const o=l.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);Zc(t,o,c,n)}return c}(t,e),canvasRenderers:[au,du]},yu={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}=Hc(t.ribbons);if(r.length>0&&n.push(...qc(t,e,r)),i.length>0)for(const e of o)n.push(...Uc(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=lc(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=fu(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=ac(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 Zc(t,o,n),n}(t,e),canvasRenderers:[au,uu,du]};function mu(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",l=t.getSymbol,c=l?x(l,t.config.symbolMap):null;for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},l=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(l=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(c){const n=c(i),r=dc(i,t.scales,t.getX,t.getY,Math.PI*l*l,n,e,u);r&&o.push(r)}else{const n=uc(i,t.scales,t.getX,t.getY,l,e,u);n&&o.push(n)}}return o}var xu=new Map;function bu(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=xu.get(n);return i||(i=new Path2D(O(t,e)),xu.size>256&&xu.clear(),xu.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=$a(t,e.style.fill,r),t.fill(s)),e.style.stroke&&"none"!==e.style.stroke&&(t.globalAlpha=i*a,t.strokeStyle=dt(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth??1,t.stroke(s)),t.restore()}var vu=(t,e)=>{const o=t.globalAlpha;for(const n of e)"symbol"===n.type&&bu(t,n,n.x,n.y,o,"#4e79a7");t.globalAlpha=o},wu=[du,vu],ku={chartType:"scatter",buildScene:(t,e)=>mu(t,e),canvasRenderers:wu},Au={chartType:"bubble",buildScene:(t,e)=>mu(t,e),canvasRenderers:wu},Su=new Map;function Mu(t,e,o){return e===o?128:Math.min(Math.floor(255*(t-e)/(o-e)+.5),255)}function _u(t){const e=Object.prototype.hasOwnProperty.call(ie,t)?t:"blues";let o=Su.get(e);if(o)return o;o=Array(256);const n=re(e);for(let t=0;256>t;t++)o[t]=n(t/255);return Su.set(e,o),o}function Pu(t,e,o){const n=o.config.areaStyle?.(e);return n&&("string"==typeof n.fill&&(t.fill=n.fill),t.style=n),t}function Lu(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=nt(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,l]=t.scales.x.domain(),[c,u]=t.scales.y.domain(),d=(l-a||1)/n,h=(u-c||1)/i,f=n*i;if(f>1e6)return[];const p=new Int32Array(f),g=new Float64Array(f),y=co(t.config.areaStyle)?.[0]===t.config.areaStyle?new Map:void 0;for(let o=0;e.length>o;o++){const r=e[o],l=t.getX(r),u=t.getY(r);if(!isFinite(l)||!isFinite(u))continue;const f=Math.min(Math.floor((l-a)/d),n-1),m=Math.min(Math.floor((u-c)/h),i-1);if(0>f||0>m)continue;const x=m*n+f;p[x]++;const b=s(r);if(g[x]+=isFinite(b)?b:0,y){let t=y.get(x);t||(t=[],y.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=g[t];break;case"mean":e=g[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:_u("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 l;switch(r){case"sum":l=g[n];break;case"mean":l=g[n]/p[n];break;default:l=p[n]}const u=Mu(l,m,x),f=b?b(l):v[u],_=A?{value:l,showValues:!0,valueFormat:S}:{value:l},P=lo({xi:s,yi:e,value:l,count:p[n],sum:g[n],xCenter:a+(s+.5)*d,yCenter:c+(e+.5)*h,agg:r},y?.get(n));M.push(Pu(fc(s*w,(i-1-e)*k,w,k,f,P,_),P,t))}}return M}function $u(t,e){const[o,n,i]=xa(t,e);return.299*o+.587*n+.114*i>128?"#000":"#fff"}function Tu(t){return Number.isInteger(t)?t+"":100>Math.abs(t)?1>Math.abs(t)?t.toPrecision(3):t.toFixed(1):t.toFixed(0)}var Ru=(t,e,o,n)=>{const i=e.filter(t=>"heatcell"===t.type);t.save();try{const e=dt(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=Ta(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=dt(t,n?.stroke??"var(--semiotic-surface, #fff)"),t.lineWidth=r,t.strokeRect(o.x,o.y,o.w,o.h)),Jc(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):Tu(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=$u(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()}},Cu={chartType:"heatmap",buildScene:(t,e,o)=>function(t,e,o){if(t.config.heatmapAggregation)return Lu(t,e,o);if(0===e.length)return[];const n=nt(t.config.valueAccessor,"value"),i=st(t.config.xAccessor,"x"),r=st(t.config.yAccessor,"y"),s=new Map,a=new Map,l=Array(e.length),c=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],n=i(o),u=r(o);l[t]=n,c[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)),g=f.every(t=>"number"==typeof t&&!isNaN(t)),y=4096;if(p&&g&&u*d>y&&e.length>y){const n=new Set;for(let i=0;e.length>i;i++){const r=s.get(l[i]),d=a.get(c[i]);if(void 0!==r&&void 0!==d&&(n.add(d*u+r),n.size>y))return Lu({...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(g){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(l[t]),r=a.get(c[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:_u("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,T=[];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=Mu(o,k,A),a=S?S(o):M[s],l=b[e];T.push(Pu(fc(i*_,(d-1-r)*P,_,P,a,l,L?{value:o,showValues:!0,valueFormat:$}:{value:o}),l,t))}return T}(t,e,o),canvasRenderers:[Ru]};function Iu(t){return(t.tl??0)>0||(t.tr??0)>0||(t.br??0)>0||(t.bl??0)>0}function Du(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 Fu(t,e){const{x:o,y:n,w:i,h:r}=e,{tl:s,tr:a,br:l,bl:c}=Du(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-l),l>0&&t.arcTo(o+i,n+r,o+i-l,n+r,l),t.lineTo(o+c,n+r),c>0&&t.arcTo(o,n+r,o,n+r-c,c),t.lineTo(o,n+s),s>0&&t.arcTo(o,n,o+s,n,s),t.closePath()}function Ou(t,e){const o=$a(t,e.style.fill,dt(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?Ra(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null)||o}function Nu(t,e){if(!e.style.stroke||"none"===e.style.stroke)return!1;const o=e.style.strokeWidth??1;return o>0&&(t.strokeStyle=dt(t,e.style.stroke)||e.style.stroke,t.lineWidth=o,!0)}var zu=(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)Eu(t,e);else if(e.cornerRadii&&Iu(e.cornerRadii))t.fillStyle=Ou(t,e),Fu(t,e),t.fill(),Nu(t,e)&&t.stroke();else if(e.roundedTop&&e.roundedTop>0){t.fillStyle=Ou(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(),Nu(t,e)&&t.stroke()}else t.fillStyle=Ou(t,e),t.fillRect(e.x,e.y,e.w,e.h),Nu(t,e)&&t.strokeRect(e.x,e.y,e.w,e.h);Jc(t,e),t.globalAlpha=1}};function Eu(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 Wu={chartType:"bar",buildScene:(t,e)=>function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=sc(e,t.getX,t.getY,t.config.binSize,t.getCategory,co(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)),l=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===l?n=t.barCategoryCache.order:(n=[...a,...s],t.barCategoryCache={key:l,order:n})}const i=[],r=t.scales,[s,a]=r.x.domain(),l=t.config.barStyle,c=t.config.themeSemantic?.primary,u=l?.gap,d="number"!=typeof u||0>u?1:u,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.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),g=Math.abs(p-f),y=g>d+1?d:0,m=Math.min(f,p)+y/2,x=Math.max(g-y,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?we(t.config.barColors,s):void 0)??l?.fill??c??"#4e79a7",g=lo({binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},e.categoryRows?.get(s)),y=t.config.areaStyle?.(g)??{};i.push(hc(m,d,x,f,{fill:p,...h,...y},g,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=l?.fill||c||"#007bff",d=lo({binStart:e.start,binEnd:e.end,total:e.total},e.rows),f=t.config.areaStyle?.(d)??{};i.push(hc(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:[zu]},Bu={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,l=n.strokeWidth,c=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?we(t.config.barColors,e):void 0)??f}const{r:p,...g}=t.config.pointStyle?.(n)??{},y={type:"point",x:d,y:h,r:p??i,style:{fill:f,opacity:s,stroke:a,strokeWidth:l,cursor:c,...g},datum:n};t.getPointId&&(y.pointId=t.getPointId(n)+""),o.push(y)}return o}(t,e),canvasRenderers:[du]},ju=(t,e,o,n)=>{zu(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=dt(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 l=o.y(s.cumEnd),c=n.x+n.w,u=r.x;t.beginPath(),t.moveTo(c,l),t.lineTo(u,l),t.stroke()}t.restore()}},Yu={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",l=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",c=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],g=t.getX(p),y=t.getY(p),m=f+y,x=i.x(g),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)+c/2,S=Math.max(w,k)-c/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>y?l:a,T={...p,baseline:f,cumEnd:m,delta:y,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},R={fill:$,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(T)};n.push(hc(A,P,S,L,R,T)),f=m}return n}(t,e,o),canvasRenderers:[ju]},Xu=(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=dt(t,e.wickColor)||e.wickColor,s=60>n.height,a=s?Math.max(e.wickWidth,2):e.wickWidth,l=()=>{t.beginPath(),t.moveTo(e.x,e.highY),t.lineTo(e.x,e.lowY),t.strokeStyle=r,t.lineWidth=a,t.stroke()};if(s||l(),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=dt(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&&l(),t.restore()}},Gu={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",l=n?s:r.downColor||"#dc3545",c=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),g=n?f:t.getClose(s);if(!n&&[p,g].some(t=>null==t||Number.isNaN(t)))continue;const y=g>=p,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(p),closeY:t.scales.y(g),highY:t.scales.y(d),lowY:t.scales.y(f),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:y,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:[Xu]};function Vu(t,e,o,n,i){if(0>=e.size)return;const r=e.glyph;if(!r||!r.parts?.length)return;const s=g(r,e.size);if(0>=s.scale)return;const a=(e.style.opacity??1)*(e._decayOpacity??1);if(0>=a)return;const l=e=>{const o=$a(t,e,e);return"string"==typeof o?o:e},c=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=f(r,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal");u&&e.ghostColor&&d(t,r,c,e.accent,e.ghostColor,l),u&&(t.beginPath(),t.rect(u.x,u.y,u.width,u.height),t.clip()),d(t,r,c,e.accent,void 0,l),t.restore()}var Hu={chartType:"custom",buildScene:()=>[],canvasRenderers:[au,zu,Ru,uu,du,vu,(t,e)=>{const o=t.globalAlpha;for(const n of e)"glyph"===n.type&&Vu(t,n,n.x,n.y,o);t.globalAlpha=o},Xu,du,ju]};function qu(){Hl(hu),Hl(pu),Hl(gu),Hl(yu),Hl(ku),Hl(Au),Hl(Cu),Hl(Wu),Hl(Bu),Hl(Yu),Hl(Gu),Hl(Hu)}function Uu(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 Zu(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Ku(t){if(!t||2>t.length)return;const e=Zu(t[0]),o=Zu(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Qu(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 Ju from"react";import{area as td,line as ed}from"d3-shape";import{jsx as od,jsxs as nd}from"react/jsx-runtime";var id={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function rd(t,e="#4e79a7"){return G(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function sd(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function ad(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=g(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),l=f(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),c=l?sd(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:R(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:R(o.stroke??"none",a,t.accent);return i||r?od("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 nd("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&od("clipPath",{id:c,children:od("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&t.ghostColor?od("g",{children:d(t.ghostColor)}):null,l&&c?od("g",{clipPath:`url(#${c})`,children:d()}):d()]},n)}function ld(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)=>od("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function cd(t,e,o){const n=O(t.symbolType,t.size,t.path);return od("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?rd(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 ud from"react";import{jsx as dd}from"react/jsx-runtime";function hd(t){if(!1!==t?.interactive)return t?.style?.cursor}function fd(t,e,o){const n=hd(e);return n&&null!=t&&!1!==t?dd("g",{style:{cursor:n},"data-semiotic-mark-cursor":n,children:t},o):t}import*as pd from"react";import{arc as gd}from"d3-shape";import{jsx as yd,jsxs as md}from"react/jsx-runtime";import*as xd from"react";import{jsx as bd,jsxs as vd}from"react/jsx-runtime";import*as wd from"react";import{arc as kd}from"d3-shape";var Ad=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function Sd(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=Ad(o,n),e=Ad(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=Ad(o,n),s=Ad(o,i),a=Ad(e,i),l=Ad(e,n),c=i-n>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${c} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${c} 0 ${l.x},${l.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return Sd({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),l=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),c=i-n,u=t.roundStart&&t.roundEnd?c/2:c,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return Sd({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=n+(d?a:0),p=i-(h?a:0),g=n+(d?l:0),y=i-(h?l:0),m=Ad(o,f),x=Ad(o,p),b=(o-s)*Math.cos(a),v=Ad(b,n),w=Ad(b,i),k=r?null:Ad(e,y),A=r?null:Ad(e,g),S=r?0:(e+s)*Math.cos(l),M=r?null:Ad(S,n),_=r?null:Ad(S,i),P=p-f>Math.PI?1:0,L=r?0:y-g>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=Ad(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=Ad(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=Ad(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=Ad(e,n);$+=` A${e},${e} 0 ${L} 0 ${t.x},${t.y}`}}return $+=" Z",$}import{jsx as Md,jsxs as _d}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 Ld(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(Md("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 l=Number(o.__funnelValue),c=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let i=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${Pd(l)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:Pd(l);7.8*i.length+16>d&&(i=Pd(l)),7.8*i.length+16>d||n.push(Md("text",{x:c,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?Md("g",{children:n},e+"-funnel-labels"):null}import{jsx as $d,jsxs as Td}from"react/jsx-runtime";function Rd(t,e,o,n){if(!t||2>e.length)return null;const i=ld(t.stops,n);return i?$d("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function Cd(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=La(n.curve),r=i?ed().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=sd(`${o?o+"-":""}line-${e}-stroke-gradient`),a=Rd(n.strokeGradient,n.path,s,n.style.stroke||"#4e79a7");return Td(Ju.Fragment,{children:[a&&$d("defs",{children:a}),$d("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=La(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`:td().x(([t])=>t).y0((t,e)=>i.bottomPath[e][1]).y1(([,t])=>t).curve(r)(i.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,l=G(i.style.fill)?X(i.style.fill,a):void 0,c=sd(`${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=ld(o.stops,rd(t.style.fill));return r?$d("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r}):null}(i,c),d=u?`url(#${c})`:l?`url(#${a})`:rd(i.style.fill),h=u?void 0:i.style.fillOpacity??i.style.opacity??.7,f=r?ed().x(([t])=>t).y(([,t])=>t).curve(r)(i.topPath)??"":"M"+i.topPath.map(([t,e])=>`${t},${e}`).join("L"),p=hd(i),g=p&&n>=0?$d("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,y=sd(`${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:Rd(i.strokeGradient,i.topPath,y,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)=>sd(`${o?o+"-":""}area-${e}-stroke-band-${n}`)):[],S=x?i.strokeColorBands.map((t,e)=>$d("clipPath",{id:A[e],children:$d("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)=>$d("path",{d:f,fill:"none",stroke:t.color??rd(i.style.stroke),strokeWidth:v,opacity:(i.style.opacity??1)*(t.opacity??1),clipPath:`url(#${A[o]})`},`area-${e}-stroke-band-${o}`)):m?iu(i.topPath,i.rawValues,i.colorThresholds,rd(i.style.stroke)).map((t,o)=>$d("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}`)):$d("path",{d:f,fill:"none",stroke:b?`url(#${y})`:rd(i.style.stroke),strokeWidth:v,opacity:i.style.opacity}):null;if(i.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return Td("g",{children:[Td("defs",{children:[u,!u&&l,b,S,$d("clipPath",{id:t,children:$d("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),Td("g",{clipPath:`url(#${t})`,children:[$d("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]})]},"area-"+e)}return Td(Ju.Fragment,{children:[(u||l||b||S)&&Td("defs",{children:[u,!u&&l,b,S]}),$d("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=G(n.style.fill)?X(n.style.fill,i):void 0;return Td(Ju.Fragment,{children:[r&&$d("defs",{children:r}),$d("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:rd(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return cd(t,e);case"glyph":return ad(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=G(n.style.fill)?X(n.style.fill,i):void 0;return Td(Ju.Fragment,{children:[r&&$d("defs",{children:r}),$d("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:rd(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",l=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return Td("g",{children:[$d("rect",{...n}),$d("text",{className:"semiotic-heatmap-value",x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:l+"px",fontFamily:"var(--semiotic-font-family, sans-serif)",children:t})]},"heatcell-"+e)}return $d("rect",{...n},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return Td("g",{style:o.style,children:[$d("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),$d("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),$d("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 Td("g",{style:o.style,children:[$d("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),$d("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:fd(i,t,"xy-cursor-"+e)}var Id=new Set;function Dd(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:fd(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}`;Id.has(o)||(Id.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 Fd(t){const e=[];return t.nodes.forEach((o,n)=>{const i=Dd({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 Od}from"d3-scale";import{jsx as Nd,jsxs as zd}from"react/jsx-runtime";function Ed(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>we(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:Gt;return Od().domain(t).range(n)}function Wd(t,e,o){if(0===t.length)return;const n=Ed(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}function Bd(t){return"left"===t?"start":"right"===t?"end":t??"start"}function jd(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function Yd(t){return t.typography.legendFontFamily??t.typography.fontFamily}function Xd(t){return t.typography.legendFontWeight}function Gd(t,e,o,n){const i=jd(n);return e+o+Math.ceil(t.length*i*.58)}function Vd(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=To(s),d=a+l,h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right),p=e.map(t=>Gd(t,a,l,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+c+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=Bd(s?.align),l=[];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++)l.push({category:e[t],width:p[t],x:i,y:n*u}),i+=p[t]+c}),{items:l,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...p);return{items:e.map((t,e)=>({category:t,width:p[e],x:0,y:e*u})),width:g,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function Hd(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 qd,jsxs as Ud}from"react/jsx-runtime";function Zd(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 Kd(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 Qd(t,e,o,n){if(!t)return qd("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=t;if(!i&&!r)return qd("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?c?[r]:Zd(r,l):[],g=i?c?[i]:Zd(i,l):[],y="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(qd("foreignObject",{className:"annotation-note-html",x:"end"===h?y-l:"middle"===h?y-l/2:y,y:-16,width:l,height:Math.max(f,(p.length+g.length)*f+(r&&i?2:0))+f,style:{overflow:"visible"},children:Ud("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:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&qd("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&qd("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(p.length>0&&(x.push(qd("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>qd("tspan",{x:y,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),g.length>0&&x.push(qd("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:g.map((t,e)=>qd("tspan",{x:y,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(l,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=qd("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+g.length)*f+(g.length>0?f:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=qd("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+g.length-1)*f;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(g.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),Ud("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[qd("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function Jd(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(qd("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(qd("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(qd("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(qd("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(qd("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(qd("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(qd("path",{d:Kd(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return qd("g",{className:"annotation-subject",children:r})}function th(t,e,o,n,i,r){const s=[];let a=0,l=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,c=e-r;if(0!==s||0!==c){const t=Math.abs(s),e=Math.abs(c),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,l=o):void 0!==e&&(a=o,l=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,l=Math.sin(n)*o}}const c=Math.sqrt((t-a)**2+(e-l)**2);if(c>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-l,t-a);if(r){const n=(a+t)/2,r=(l+e)/2,d=-(e-l)/c,h=(t-a)/c,f=(o?.curve??.25)*c,p=n+d*f,g=r+h*f;s.push(qd("path",{className:"connector-curve",d:`M${a},${l}Q${p},${g} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(g-l,p-a)}else s.push(qd("line",{x1:a,y1:l,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(qd("path",{d:`M${a},${l}L${a+t*Math.cos(u+e)},${l+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${l+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return qd("g",{className:"annotation-connector",children:s})}function eh(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:g,events:y={},"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&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;const t=c.depth||30;k=t+(0>t?-5:5)}else if(void 0!==c.height){const t=c.depth||30;w=t+(0>t?-5:5),k=c.height/2}return Ud("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...g&&{strokeDasharray:g},...y,children:[!v.has("connector")&&th(w,k,l,d,A,c),!v.has("subject")&&Jd(A,c,d,x,b),!v.has("note")&&Qd(a,w,k,d)]})}function oh(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 qd(eh,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return qd("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return qd(eh,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{jsx as nh}from"react/jsx-runtime";var ih={secondary:0,primary:3};function rh(t){return!0===t?._annotationDeferred}function sh(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function ah(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function lh(t){return Math.max(.72,.95-.06*t)}function ch(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:ah(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>rh(t.annotation)),i=t.some(t=>null!=sh(t.annotation)),r=t.some(t=>"layer"===sh(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=ih[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=rh(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=nh("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:lh(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=sh(e.annotation);return a&&(s=nh("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=nh("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(nh("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(nh("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}import{jsx as uh,jsxs as dh}from"react/jsx-runtime";var hh="var(--semiotic-bg, #ffffff)";function fh(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,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=>uh("text",{x:e,y:o,textAnchor:l,dominantBaseline:c,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??hh,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},g="number"==typeof p?p:p.x,y="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(n,r),x=r+2*y;let b,v;return b="middle"===l?e-m/2-g:"end"===l?e-m-g:e-g,v="middle"===c||"central"===c?o-x/2:"hanging"===c||"text-before-edge"===c?o-y:o-.8*r-y,dh("g",{className:d,children:[uh("rect",{x:b,y:v,width:m+2*g,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??hh,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}function ph(t,e,o,n){const i=K(t.fill??t.color,e,n);return q(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:n)??i}var gh=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function yh(t,e,o,n){const i=function(t,e,o){const n=t.position,i="string"==typeof n&&gh.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 mh}from"react/jsx-runtime";var xh={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function bh({annotation:t,width:e,height:o,defaults:n=xh}){const i=t.label??t.text;return null==i?null:mh("text",{...yh(t,e,o,n),children:i})}import{packEnclose as vh}from"d3-hierarchy";import{area as wh,curveBasis as kh,curveCardinal as Ah,curveCatmullRom as Sh,curveLinear as Mh,curveMonotoneX as _h,curveMonotoneY as Ph,curveStep as Lh,curveStepAfter as $h,curveStepBefore as Th}from"d3-shape";import*as Rh from"react";function Ch(t,e={}){const o=B(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 Ih,jsxs as Dh}from"react/jsx-runtime";var Fh={linear:Mh,monotoneX:_h,monotoneY:Ph,step:Lh,stepAfter:$h,stepBefore:Th,basis:kh,cardinal:Ah,catmullRom:Sh};import{jsx as Oh,jsxs as Nh}from"react/jsx-runtime";var zh=16;function Eh(t,e){return t.color||e.colors.annotation||e.colors.text}function Wh(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 Bh(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 jh(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 Yh(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=ot(e),i=t.scales.geoProjection,r=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,s=!!i&&!t.scales.x&&!t.scales.y,a=t=>Number(t),l=t.scales.x??(s?a:void 0),c=t.scales.y??(s?a:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{..."vertical"===t.projection?{x:t.scales.o??l,y:t.scales.r??c,time:t.scales.o??l,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??l,y:t.scales.o??c,time:t.scales.r??l,value:t.scales.o??c,o:t.scales.o}:{x:l,y:c,time:l,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"),...u?{projection:u}:{}},h=t.autoPlaceAnnotations?n({annotations:r,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):r,f=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:ch(i),renderedAnnotations:i.map(t=>t.annotation)}}(h,(e,o,n)=>function(t,e,o,n){const{scales:i,layout:r,theme:s,xAccessor:a,yAccessor:l}=o;switch(t.type){case"frame-text":return Oh(bh,{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=Eh(t,s),l=t.label,c=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:Nh("g",{opacity:t.opacity,children:[Oh("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Oh(fh,{x:o+4,y:zh,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Wh(t,s,"halo")})]},"ann-ythresh-"+e)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:Nh("g",{children:[Oh("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Oh(fh,{x:"left"===c?4:"center"===c?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+zh):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Wh(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 l=Eh(t,s),c=t.label,u=t.labelPosition||"top";return Nh("g",{opacity:t.opacity,children:[Oh("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:l,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&Oh(fh,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:zh,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:l,fontFamily:s.typography.fontFamily,text:c,background:Wh(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=i.y?.domain?.(),n=t.y0??o?.[0],a=t.y1??o?.[1],l=null!=n&&i.y?i.y(n):null,c=null!=a&&i.y?i.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=ph(t,"ssr-band-"+e,"vertical",Eh(t,s)),f=t.fillOpacity??.1;return Nh("g",{opacity:t.opacity,children:[h.def&&Oh("defs",{children:h.def}),Oh("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&Oh(fh,{x:r.width-4,y:Math.max(u,0)+zh,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Eh(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Wh(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=i.x?.domain?.(),n=t.x0??o?.[0],a=t.x1??o?.[1],l=null!=n&&i.x?i.x(n):null,c=null!=a&&i.x?i.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=ph(t,"ssr-xband-"+e,"horizontal",Eh(t,s)),f=t.fillOpacity??.1;return Nh("g",{opacity:t.opacity,children:[h.def&&Oh("defs",{children:h.def}),Oh("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:f}),t.label&&Oh(fh,{x:u+4,y:zh,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Eh(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Wh(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,l=Eh(t,s),c=t.opacity??.1,u=t.label;return Nh("g","horizontal"===o.projection?{children:[Oh("rect",{x:0,y:n,width:r.width,height:a,fill:l,opacity:c}),u&&Oh(fh,{x:12,y:n+a/2,dominantBaseline:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Wh(t,s,"none")})]}:{children:[Oh("rect",{x:n,y:0,width:a,height:r.height,fill:l,opacity:c}),u&&Oh(fh,{x:n+a/2,y:zh,textAnchor:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Wh(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:Bh(t,e,o),y:jh(t,e,n)}}(t,i,a,l),r=null==o.x||null==o.y?T(t,e,n):null,c=o.x??r?.x??null,u=o.y??r?.y??null;if(null==c||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 Oh(oh,{noteData:{x:c,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 Oh("g",{children:Oh("text",{x:c+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:I({...t,type:"point"},o),y:D({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=vh(n),r=t.padding||10;return Dh("g",{children:[Ih("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&&Ih(fh,{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:I({...t,type:"point"},o),y:D({...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]=ut(n.map(t=>t.x)),[a,l]=ut(n.map(t=>t.y)),c=r-i,u=s+i,d=a-i;return Dh("g",{children:[Ih("rect",{x:c,y:d,width:u-c,height:l+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&&Ih(fh,{x:(c+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 Ih("g",{children:i.map((e,n)=>{const i=I(e,o),s=D(e,o);if(null==i||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,l="function"==typeof t.style?t.style(e):t.style||r;return Ih("circle",{cx:i,cy:s,r:a,...l},"hl-"+n)})},"ann-"+e)}case"bracket":{const n=I(t,o),i=D(t,o);return Ih(oh,{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,l=s?i:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const t of n){const e=t[l];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[l],o=t[c];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 g=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},y=f,m=p;let x;if(s)if(a){const t=g(m);x=(e,o)=>[y(o),t(e)]}else{const t=g(y);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[y(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)),l=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,c=[];for(let t=0;o>t;t++){const e=0===l?0:n[t]/l;c[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=c[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 g=u*f-d*d;if(1e-12>Math.abs(g))a.push([e,h/u]);else{const t=(u*p-d*h)/g;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3):("polynomial"===b?ze(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:Ne((o*e[3]-e[0]*e[1])/n),r=Ne(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[Ne(t),Ne(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 Dh("g",{children:[Ih("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Ih("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",l=t.lowerAccessor||"lowerBounds",c=t.filter,u=n.filter(t=>null!=t[a]&&null!=t[l]&&(!c||c(t))).sort((t,e)=>t[i]-e[i]);if(2>u.length)return null;const d=Fh[o.curve||"linear"]||Mh,h=wh().x(t=>r(t[i])).y0(t=>s(t[l])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1",p=u[u.length-1];return Dh("g",{children:[Ih("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&Ih("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 l=a.reduce((t,e)=>t+e,0)/a.length,c=a.reduce((t,e)=>t+(e-l)**2,0)/a.length,u=Math.sqrt(c),d=t.threshold??2,h=l-d*u,f=s(l+d*u),p=s(h),g=t.fill||"#6366f1",y=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=n.filter(t=>{const e=t[i];return null!=e&&Math.abs(e-l)>d*u});return Dh("g",{children:[!1!==t.showBand&&Ih("rect",{x:0,y:Math.min(f,p),width:o.width||0,height:Math.abs(p-f),fill:g,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const n=I(t,o),i=D(t,o);return null==n||null==i?null:Ih("circle",{cx:n,cy:i,r:m,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Ih("text",{x:(o.width||0)-4,y:Math.min(f,p)-4,textAnchor:"end",fill:g,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 l=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>l.length)return null;let c;if("polynomial"===t.method){const e=ze(l,t.order||2).equation;c=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=Ee(l);if(!t)return null;c=t}const{se:u,meanX:d,ssX:h}=We(l,c),f=l.length,p=Be(t.confidence??.95),g=l[f-1][0],y=(g-l[0][0])/Math.max(f-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=g+(e+1)*y,n=c(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 Dh("g",{children:[Ih("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Ih("polyline",{points:`${s(g)},${a(c(g))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&Ih("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=T(t,e,o);if(!r)return null;n=r.x,i=r.y}if(!m(n,i,o))return null;const r=t.width??32,s=t.height??32,a=t.content??Ih("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Ih("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:Ih("div",{...Ch(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,n),t.svgAnnotationRules,d),p=f.nodes,g=new Map;for(const t of f.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";g.set(e,(g.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=g.get(e)??0;o>0?g.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:h.length,renderedCount:f.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),p.length>0?Oh("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:p}):null}import{jsx as Xh}from"react/jsx-runtime";function Gh(t,e,o,n="right",i,r){if(null==t||!1===t)return null;const{x:s,y:a}=$o(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:n,legendLayout:i,axisChrome:r});return Xh("g",{transform:`translate(${s}, ${a})`,children:t})}import*as Vh from"react";function Hh(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function qh(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function Uh(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 Zh(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function Kh(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:Zh(t)}}}function Qh(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 Jh(t,e){return t?.ticks??t?.tickCount??e}function tf(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function ef(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 l=(a-s)/(e-1),c=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*l;c[t]=r?new Date(o):o}return c}(t,e):t.ticks(e)}import{jsx as of}from"react/jsx-runtime";function nf(t){return"string"==typeof t||"number"==typeof t}function rf(t){const{label:e,x:o,y:n,textAlign:i,fontSize:r,fontFamily:s,color:a}=t;return of("foreignObject",{x:o,y:n,width:60,height:24,style:{overflow:"visible"},children:of("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:i,userSelect:"none"},children:e})})}function sf(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 af(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function lf(t){const{candidates:e,scale:o,minPixelDistance:n,includeMax:i,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:l=!0,format:c}=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})),!l||!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 g=e.map(t=>t.value.valueOf()),y={value:h,pixel:f,label:c(h,u.length,g)};return n>Math.abs(f-p)&&u.length>1&&(u=u.slice(0,-1)),[...u,y]}function cf(t,e,o,n){return!!t&&("function"==typeof t?t(e.value,o):V(e.value,o>0?n[o-1].value:void 0))}import{jsx as uf,jsxs as df}from"react/jsx-runtime";function hf(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function ff(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 pf(t,e,o){return uo(t.showLegend&&!t.__legendIncludesAutomatic?Wd(e,t.colorScheme,o):void 0,t.legend)}var gf={right:110,left:110,top:50,bottom:80};function yf(t,e){if(t.__autoLegendMargin)return gf[e]}function mf(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:ho(t)||fo(t)?t.legendDistance:void 0};return ho(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:l,rowHeight:c}=To(s),u=a+l,d=Math.max(12,jd(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=Bd(s?.align);let r=0,l=0;const c=[];for(const i of e){const e=i.items.map(t=>t.label),u=Vd({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,f=i.label?Gd(i.label,0,0,o):0,p=h>0?h+8:0,g=p+u.width,y=Math.max(u.height,f);c.push({group:i,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:g,height:y,items:u.items}),r+=g+12,l=Math.max(l,y)}const h=c.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:c.map(t=>({...t,x:t.x+p})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Ro(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),c);let g=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>Gd(t.label,a,l,o)),i=Math.max(0,...n,t.label?Gd(t.label,0,0,o):0);return g=Math.max(g,i),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*c,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*c}))}}),width:g,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??bo(i,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:l}=$o(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=Ro(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",l=[Nd("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=s.labelY&&l.push(Nd("text",{y:s.labelY,fontSize:jd(t.theme),fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:n.label},"legend-group-label-"+i)),l.push(Nd("g",{transform:`translate(0,${s.itemsY})`,children:n.items.map((e,r)=>{const s=n.styleFn(e,r),l="function"==typeof a?a(e):"line"===a?Nd("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):Nd("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return zd("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[l,Nd("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:jd(t.theme),fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return Nd("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":"vertical",fontWeight:Xd(t.theme),children:n})}const c=o.groups.flatMap((e,i)=>{const{group:r}=e,a=r.type??"fill",l=[];if(r.label&&l.push(Nd("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:jd(t.theme),fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:r.label}:{x:e.x,y:e.y+jd(t.theme),fontSize:jd(t.theme),fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:r.label},"legend-group-label-"+i)),l.push(...e.items.map((n,s)=>{const l=r.items[s],c=r.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?Nd("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:c}):Nd("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:c});return zd("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,Nd("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:jd(t.theme),fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:n.category})]},`legend-${i}-${s}`)})),n&&o.groups.length-1>i){const t=e.x+e.width+6;l.push(Nd("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+i))}return l});return Nd("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":n?"horizontal":"vertical",fontWeight:Xd(t.theme),children:c})}({...o,legendGroups:t.legendGroups}):fo(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=bo(n),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:l}=$o(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:i}),c=Array.from({length:17},(e,n)=>{const i=n/16;return Nd("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 zd("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:Xd(t.theme),children:[Nd("defs",{children:Nd("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),t.gradient.label&&Nd("text",{x:e.width/2,y:n,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:t.gradient.label}),Nd("rect",{x:0,y:i,width:e.width,height:o,fill:`url(#${r})`,rx:2}),Nd("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Yd(t.theme),children:s(t.gradient.domain[0])}),Nd("text",{x:e.width,y:i+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Yd(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?12:void 0,d=t.gradient.label?18:0;return zd("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:Xd(t.theme),children:[Nd("defs",{children:Nd("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),t.gradient.label&&Nd("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:Yd(t.theme),children:t.gradient.label}),Nd("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),Nd("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Yd(t.theme),children:s(t.gradient.domain[1])}),Nd("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:Yd(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function xf(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",l={...t},c={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:yf(o,a)};if(null!=o.legend){const e=pf(o,n,i);null!=e&&!1!==e&&function(t,e){Lo(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";Lo(t,{legend:Wd(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,categories:n,colorScheme:o.colorScheme});return mo(t,l,r,a),a}function bf(t){const{props:e,categories:o,theme:n,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",l={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=pf(e,o,n);if(Vh.isValidElement(t))return Gh(t,i,r,a,e.legendLayout,e.axisChrome);return mf(t,l)||(ho(t)||fo(t)?null:Gh(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 l=Ed(e,o,n),c="top"===i||"bottom"===i,u=Vd(t),d={...Wd(e,o,n),legendDistance:t.legendDistance},h=t.reservedWidth??bo(d,t.legendLayout),{x:f,y:p}=$o(d,{totalWidth:r,totalHeight:s,margin:a,position:i,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(c){const t=u.items.map((t,e)=>zd("g",{transform:`translate(${t.x},${t.y})`,children:[Nd("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),Nd("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:jd(n),fill:n.colors.text,fontFamily:Yd(n),children:t.category})]},"legend-"+e));return Nd("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:Xd(n),children:t})}const g=Ro([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],y=u.items.map((t,e)=>zd("g",{transform:`translate(${t.x},${t.y+g.itemsY})`,children:[Nd("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),Nd("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:jd(n),fill:n.colors.text,fontFamily:Yd(n),children:t.category})]},"legend-"+e));return zd("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:Xd(n),children:[Nd("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),y]})}({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 vf=tf;function wf(t,e){const o=Fe(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,l=[s,a].filter(Boolean).join(" ")||void 0;return df("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":l,style:{fontFamily:o.fontFamily},children:[r&&uf("title",{id:s,children:r}),e.description&&uf("desc",{id:a,children:e.description}),e.defs&&uf("defs",{children:e.defs}),n&&"transparent"!==n&&uf("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),uf("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&uf("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&&uf("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{jsx as kf,jsxs as Af}from"react/jsx-runtime";function Sf(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}var Mf={top:50,right:40,bottom:60,left:70},_f={top:20,right:80,bottom:20,left:80},Pf={top:40,right:40,bottom:40,left:40},Lf=new Set(["chord","force","circlepack","orbit"]);import{jsx as $f,jsxs as Tf}from"react/jsx-runtime";import{Fragment as Rf,jsx as Cf,jsxs as If}from"react/jsx-runtime";function Df(t,e){const o=De(t.theme),n=t.size||[500,300],i=yo({...Mf,...t.margin},t.title),r=po(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}(Wt(t.data),t.lineDataAccessor),a=t.showLegend?Hd(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],l=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,l=!!i,c=!1!==t.showAxes;return{hasAxis:c&&r,hasAxisLabel:c&&r&&!!(e?.label??t.xLabel),rotatedTicks:c&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(o?.label??t.xLabel),rotatedTicks:c&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??t.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});xf(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=bf({props:{...t,axisChrome:l},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,g={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:Pe(t.gradientFill),lineGradient:Le(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},y=new Xc(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Sf(t.backgroundGraphics,n,i,y.scales),x=Sf(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?Yh({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=Qu({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Il.renderToStaticMarkup(wf(m||x||t.annotations?If(Rf,{children:[m,a,x]}):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:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=Fd({nodes:y.scene,renderMode:t.renderMode,fallback:(e,o)=>Cd(e,o,b,t.hoverRadius??30)}),w=t.showGrid?function(t,e,o,n,i,r,s){const{grid:a}=Fe(o),l=n?n+"-":"",c=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=c??u,p=d??h,g=f?.extent??i,y=p?.extent??i,m="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=f?.tickValues??ef(t.x,Jh(f,m),g),v=f?.tickFormat||s?.xFormat||s?.tickFormatTime||tf,w=sf({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,af(e.label)),0),A=lf({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:g,hasExplicitTickValues:!!f?.tickValues,format:v}),S=p?.tickValues??ef(t.y,Jh(p,x),y),M=p?.tickFormat||s?.yFormat||s?.tickFormatValue||tf,_=t=>M(t),P=lf({candidates:sf({values:S,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:p?.includeMax,extentMode:y,hasExplicitTickValues:!!p?.tickValues,format:_}),L=!1!==f?.grid,$=!1!==p?.grid,T=Zh(f?.gridStyle),R=Zh(p?.gridStyle),C=Kh(f?.gridStyle,{stroke:a,strokeWidth:.5}),I=Kh(p?.gridStyle,{stroke:a,strokeWidth:.5});return Af("g",{id:l+"grid",className:"semiotic-grid",opacity:.8,children:[L&&A.map((t,o)=>kf("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...C,strokeDasharray:T??C.strokeDasharray},"gx-"+o)),$&&P.map((t,o)=>kf("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...I,strokeDasharray:R??I.strokeDasharray},"gy-"+o))]})}(y.scales,{width:u,height:d},o,b,t.axisExtent,t.axes,t):null,k=v.map(t=>t.element),A=ff(t)+"-plot-clip",S=!1!==t.showAxes,M=S?function(t,e,o,n,i,r,s,a=!1){const l=Fe(n),c=o.legendPosition??"right",u=wo(o.legendLayout,s?.leftAxis),d=wo(o.legendLayout,s?.rightAxis),h=a&&"left"===c&&u>0?u:r?.left??o.margin?.left??40,f=a&&"right"===c&&d>0?d:r?.right??o.margin?.right??40,p=o.axes?.find(t=>"bottom"===t.orient),g=o.axes?.find(t=>"top"===t.orient),y=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=p??g,b=y??m,v=p?"bottom":g?"top":"bottom",w=y?"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))),T=x?.tickValues??ef(t.x,Jh(x,L),_),R=x?.tickFormat||o.xFormat||o.tickFormatTime||vf,C=sf({values:T,scale:t.x,format:R}),I=C.reduce((t,e)=>Math.max(t,af(e.label)),0),D=lf({candidates:C,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(I+8,55)):Math.max(55,I+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:R}),F=b?.tickValues??ef(t.y,Jh(b,$),P),O=b?.tickFormat||o.yFormat||o.tickFormatValue||vf,N=t=>O(t),z=lf({candidates:sf({values:F,scale:t.y,format:N}),scale:t.y,minPixelDistance:22,includeMax:b?.includeMax,extentMode:P,hasExplicitTickValues:!!b?.tickValues,format:N}),E=!!(x?.autoRotate&&D.length>1&&e.width/Math.max(D.length-1,1)<D.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),W=Uh(D),B=Uh(z),j=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),X=Kh(x?.axisStyle,{stroke:l.border,strokeWidth:1}),G=Kh(b?.axisStyle,{stroke:l.border,strokeWidth:1}),V="right"===w?e.width+f-15:15-h;return df("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&uf("line",{x1:0,y1:k,x2:e.width,y2:k,...X}),x?.jaggedBase&&uf("path",{d:Qh(v,e.width,e.height),fill:"none",...X}),D.map((t,e)=>{const o=cf(x?.landmarkTicks,t,e,D);return df("g",{transform:`translate(${t.pixel},${k})`,children:[uf("line",{y2:5*S,...X}),nf(t.label)?uf("text",{y:S*(E?12:18),textAnchor:E?"end":Hh(x?.tickAnchor,t.pixel===W.min,t.pixel===W.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:E?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):rf({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"xtick-"+e)}),j&&uf("text",{x:e.width/2,y:"top"===v?-(E?58:40):e.height+(E?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:j}),!1!==b?.baseline&&!b?.jaggedBase&&uf("line",{x1:A,y1:0,x2:A,y2:e.height,...G}),b?.jaggedBase&&uf("path",{d:Qh(w,e.width,e.height),fill:"none",...G}),z.map((t,e)=>{const o=cf(b?.landmarkTicks,t,e,z);return df("g",{transform:`translate(${A},${t.pixel})`,children:[uf("line",{x2:5*M,...G}),nf(t.label)?uf("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:qh(b?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):rf({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"ytick-"+e)}),Y&&uf("text",{x:V,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${V}, ${e.height/2})`,children:Y})]})}(y.scales,{width:u,height:d},t,o,b,i,l,!!c):null,_=S?function(t){const{scales:e,layout:o,props:n,theme:i,leftAxis:r,rightAxis:s,margin:a,axisChrome:l,hasRenderedLegend:c}=t;if(!r||!s)return null;const u=Fe(i),d=s.extent??n.axisExtent,h="exact"===d?Math.max(2,Jh(s,5)):Math.min(Jh(s,5),Math.max(2,Math.floor(o.height/30))),f=s.tickValues??ef(e.y,h,d),p=s.tickFormat||n.yFormat||n.tickFormatValue||tf,g=t=>p(t),y=lf({candidates:sf({values:f,scale:e.y,format:g}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:g}),m=Uh(y),x=s.label??n.yLabelRight,b=Kh(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=n.legendPosition??"right",w=wo(n.legendLayout,l?.rightAxis),k=o.width+(c&&"right"===v&&w>0?w:a.right)-15;return Tf("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&$f("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&$f("path",{d:Qh("right",o.width,o.height),fill:"none",...b}),y.map((t,e)=>{const n=cf(s.landmarkTicks,t,e,y);return Tf("g",{transform:`translate(${o.width},${t.pixel})`,children:[$f("line",{x2:5,...b}),nf(t.label)?$f("text",{x:8,textAnchor:"start",dominantBaseline:qh(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}):rf({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&$f("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:y.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:l,hasRenderedLegend:!!c}):null;let P;const L=t.annotations?Yh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.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:b,onRender:t=>{P=t}}):null;e&&(e.evidence=Qu({frameType:"xy",width:n[0],height:n[1],marks:v.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:P,xDomain:Ku(y.scales.x?.domain?.()),yDomain:Ku(y.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const $=t.svgPreRenderers&&y.scales?t.svgPreRenderers.map((t,e)=>{try{return Cf(Cl.Fragment,{children:t(y.scene,y.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Il.renderToStaticMarkup(wf(If(Rf,{children:[m,$,w,Cf("defs",{children:Cf("clipPath",{id:A,children:Cf("rect",{x:0,y:0,width:u,height:d})})}),Cf("g",{clipPath:`url(#${A})`,children:k}),M,_,L,x,y.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:c,idPrefix:t._idPrefix}))}qu();import*as Ff from"react-dom/server";import{jsx as Of,jsxs as Nf}from"react/jsx-runtime";function zf({machine:t,layout:e,runtime:o,downstreamSet:n,selectedSet:i,width:r,height:s,seed:a,reduced:l,onSelectTask:c}){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 Nf("svg",{"aria-hidden":"true",width:r,height:s,viewBox:`0 0 ${r} ${s}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Of("defs",{children:Of("filter",{id:"chain-shadow-"+a,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Of("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 Nf("g",{children:[Of("line",{x1:i,x2:i,y1:h,y2:s-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Of("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 Of("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 Nf("g",{children:[Of("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&&Of("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),g=r.x-r.width/2,y=r.y-r.height/2,m=Math.max(2,r.height*t.progress);return Nf("g",{children:[Nf("g",{style:{transform:`rotate(${s?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:l?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+a+")"},children:[Of("rect",{x:g,y:y,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}),Of("rect",{x:g+3,y:y+r.height-m+1,width:r.width-6,height:Math.max(0,m-4),rx:2,fill:p,opacity:s?.86:.46})]}),u&&Nf("g",{opacity:d?.28:1,children:[Of("line",{x1:g-8,x2:g+14,y1:r.y+9,y2:r.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Of("circle",{cx:g-8,cy:r.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),Nf("g",{onPointerDown:()=>c(t.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Of("rect",{x:g,y:y,width:r.width,height:r.height,fill:"transparent"}),Of("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}),Nf("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 Ef(t,e=0){if(t instanceof Date)return t.getTime();const o=Number(t);return Number.isFinite(o)?o:e}function Wf(t){if(null==t.completionTime)return null;const e=Ef(t.completionTime,NaN);return Number.isFinite(e)?e:null}function Bf(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 jf(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 Yf(t,e){return e>t?-1:t>e?1:0}function Xf(t,e){return`dependency:${encodeURIComponent(t)}:${encodeURIComponent(e)}`}function Gf(t,e){return`socket:${encodeURIComponent(t)}:${e}`}function Vf(t){const e=Number(t);return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function Hf(t,e,o={}){const n=new Set(o.completedTaskIDs??[]),i=r(t.nodes,t.edges.map(t=>({source:t.sourceID,target:t.targetID}))),s=[...L(i,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),a=Array.from(new Set(s.map(t=>t.lane)));return{blockerID:e,downstreamTaskCount:s.length,affectedLaneCount:a.length,downstreamTaskIDs:s.map(t=>t.id),affectedLanes:a}}import{jsx as qf,jsxs as Uf}from"react/jsx-runtime";import{jsx as Zf,jsxs as Kf}from"react/jsx-runtime";var Qf={top:4,bottom:4,left:4,right:4};function Jf(t,e,o,n,i){return{__composite:{data:t,colorBy:e,colorScheme:o,common:n,rest:i}}}function tp(t){return t.__composite}function ep(t,e){return"number"==typeof t&&Number.isFinite(t)?t:e}function op(t,e){return Math.max(1,Math.floor(ep(t,e)))}function np(t,e,o,n){return t.replace(/^<svg\b/,`<svg x="${e}" y="${o}" data-semiotic-composite-part="${n}"`)}function ip(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 rp={frameType:"xy",buildProps:Jf,renderStatic:function(t,e){const{data:o,colorBy:n,colorScheme:i,common:r,rest:s}=tp(t),[a,l]=r.size??[600,400],c=s.minimap&&"object"==typeof s.minimap?s.minimap:{},u=ep(c.height,60),d=r.margin,h=c.margin&&"object"==typeof c.margin?c.margin:{},f={top:ep(h.top,0),right:ep(h.right,ep(d?.right,20)),bottom:ep(h.bottom,20),left:ep(h.left,ep(d?.left,40))},p=u+f.top+f.bottom,g=s.frameProps&&"object"==typeof s.frameProps?s.frameProps:{},y={...r,size:[a,l],xExtent:g.xExtent??s.brushExtent??r.xExtent,yExtent:g.yExtent??s.yExtent??r.yExtent,_idPrefix:(r._idPrefix??"minimap")+"-detail"},m=Ko.buildProps(o,n,i,y,s);Object.assign(m,g);const x={...r,size:[a,p],margin:f,title:void 0,description:(r.description??r.title??"Chart")+" overview minimap",showAxes:c.showAxes??!1,showLegend:!1,showGrid:!1,accessibleTable:!1,background:c.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=Ko.buildProps(o,n,i,x,b);v.chartType=s.fillArea?"area":"line","function"==typeof c.lineStyle&&(v.lineStyle=c.lineStyle);const w={},k={},A=Df(m,w),S=Df(v,k),M=!0===s.renderBefore,_=M?0:l,P=""+np(A,0,M?p:0,"detail")+np(S,0,_,"overview"),L=l+p,$=Fe(De(r.theme)),T="string"==typeof r.title?r.title:void 0,R="string"==typeof r.description?r.description:T||"Chart with overview minimap",C=ff(r),I=T?C+"-title":void 0,D=C+"-description",F="y"===c.brushDirection?"y":"x",O=Array.isArray(s.brushExtent)&&s.brushExtent.length>=2?[Number(s.brushExtent[0]),Number(s.brushExtent[1])]:null,N=k.evidence;let z=null;if(O&&O.every(Number.isFinite)&&N){const t="x"===F?N.xDomain:N.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(...O))*e,i=n(Math.max(...O))*e;z=Zf("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(...O)))*o,i=(1-n(Math.min(...O)))*o;z=Zf("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=Rl.renderToStaticMarkup(Kf("svg",{xmlns:"http://www.w3.org/2000/svg",className:"minimap-chart",width:a,height:L,role:"img","aria-labelledby":[I,D].filter(Boolean).join(" "),style:{fontFamily:$.fontFamily},children:[T&&Zf("title",{id:I,children:T}),Zf("desc",{id:D,children:R}),Zf("g",{dangerouslySetInnerHTML:{__html:P}}),z]}));if(e){const t=[w.evidence,k.evidence];e.evidence=Uu({frameType:"xy",width:a,height:L,parts:t,title:T,description:R,xDomain:ip(t,"xDomain"),yDomain:ip(t,"yDomain")})}return E}};function sp(t,e){return("function"==typeof e?e(t):t[e])+""}var ap={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:Xo,LineChart:Ko,AreaChart:Jo,DifferenceChart:tn,StackedAreaChart:en,Scatterplot:Qe,CandlestickChart:on,BubbleChart:Je,ConnectedScatterplot:rn,QuadrantChart:nn,Heatmap:an,WaterfallChart:qo,MultiAxisLineChart:Ho,MinimapChart:rp,ScatterplotMatrix:{frameType:"xy",buildProps:Jf,renderStatic:function(t,e){const{data:o,colorBy:n,colorScheme:i,common:r,rest:s}=tp(t),a=Array.isArray(l=o)?l.filter(t=>null!=t&&"object"==typeof t&&!Array.isArray(t)):[];var l;const c=Array.isArray(s.fields)?s.fields.filter(t=>"string"==typeof t):[],u=s.fieldLabels&&"object"==typeof s.fieldLabels?s.fieldLabels:{},d=op(s.cellSize,150),h=Math.max(0,ep(s.cellGap,4)),f=Math.max(0,ep(s.pointRadius,2)),p=Math.max(0,Math.min(1,ep(s.pointOpacity,.5))),g=op(s.histogramBins,20),y="string"==typeof s.diagonal?s.diagonal:"histogram",m=40+c.length*d+c.length*h,x=c.length*d+40+c.length*h,b=De(r.theme),v=Fe(b),w=function(t,e,o,n){if(!e)return{categories:[],color:()=>ge};const i=Array.from(new Set(t.map(t=>sp(t,e)))),r="string"==typeof e?e:"__semioticSplomColor",s=ke("function"==typeof e?t.map(t=>({...t,[r]:sp(t,e)})):t,r,o??n.colors.categorical);return{categories:i,color:t=>ve(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 ${c.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),T=$+x,R=[],C=[];let I=0;c.forEach((t,e)=>{c.forEach((o,i)=>{const s=40+h+i*(d+h),l=$+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:l,x:c,y:u}=t;if("label"===s)return{visibleBars:0,svg:Rl.renderToStaticMarkup(Zf("svg",{x:c,y:u,width:i,height:i,"data-semiotic-composite-part":"diagonal-"+o,children:Zf("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?sp(t,a):"__all",s=p[n];s.set(i,[...s.get(i)??[],t])}const g=p.map(t=>Array.from(t.values()).reduce((t,e)=>t+e.length,0)),y=Math.max(1,...g);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/y*(i-24),c=o;return o+=s,Zf("rect",{x:e/r*i,y:i-c-s,width:Math.max(i/r-1,1),height:s,fill:a?l(n[0]):ge,opacity:.6},`${e}-${t}`)})});return{visibleBars:m,svg:Rl.renderToStaticMarkup(Kf("svg",{x:c,y:u,width:i,height:i,"data-semiotic-composite-part":"diagonal-"+o,children:[Zf("text",{x:i/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333",children:n}),x]}))}}({data:a,field:t,label:we(u,t)??t,cellSize:d,bins:g,diagonal:y,colorBy:n,color:w.color,x:s,y:l});return I+=e.visibleBars,void C.push(e.svg)}const c={},m=Df({chartType:"scatter",data:a,size:[d,d],xAccessor:o,yAccessor:t,pointStyle:t=>({r:f,opacity:p,fill:w.color(t)}),margin:Qf,showAxes:!1,showGrid:!1,enableHover:!1,accessibleTable:!1,description:`${we(u,o)??o} versus ${we(u,t)??t} scatterplot`,theme:r.theme,_idPrefix:`${(r._idPrefix??"splom")+""}-${e}-${i}`},c);R.push(c.evidence),C.push(np(m,s,l,`cell-${t}-${o}`))})});const D=ff(r),F=k?D+"-title":void 0,O=D+"-description",N=Rl.renderToStaticMarkup(Kf("svg",{xmlns:"http://www.w3.org/2000/svg",className:"scatterplot-matrix",width:m,height:T,role:"img","aria-labelledby":[F,O].filter(Boolean).join(" "),style:{fontFamily:v.fontFamily},children:[k&&Zf("title",{id:F,children:k}),Zf("desc",{id:O,children:A}),Zf("rect",{width:m,height:T,fill:v.background}),k&&Zf("text",{x:0,y:18,fontSize:14,fontWeight:600,fill:v.text,children:k}),L.map(t=>{const e=a.find(e=>n&&sp(e,n)===t.label),o=e?w.color(e):ge;return Kf("g",{transform:`translate(${t.x},${S+t.y})`,children:[Zf("circle",{cx:5,cy:8,r:5,fill:o}),Zf("text",{x:14,y:12,fontSize:11,fill:v.text,children:t.label})]},t.label)}),c.map((t,e)=>{const o=$+e*(d+h)+d/2;return Zf("text",{x:20,y:o,transform:`rotate(-90 20 ${o})`,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:v.text,children:we(u,t)??t},"row-"+t)}),c.map((t,e)=>Zf("text",{x:40+h+e*(d+h)+d/2,y:$+c.length*(d+h)+20,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:v.text,children:we(u,t)??t},"column-"+t)),Zf("g",{dangerouslySetInnerHTML:{__html:C.join("")}})]}));return e&&(e.evidence=Uu({frameType:"xy",width:m,height:T,parts:R,additionalMarkCountByType:I>0?{histogram:I}:void 0,title:k,description:A,categories:w.categories.length?w.categories:void 0,legendItems:M.length||void 0})),N}},TemporalHistogram:Qo,XYCustomChart:Fr,BarChart:Cn,StackedBarChart:In,GroupedBarChart:Dn,PieChart:Fn,DonutChart:On,Histogram:Nn,BoxPlot:zn,ViolinPlot:En,SwarmPlot:Wn,DotPlot:Bn,SwimlaneChart:Yn,RidgelinePlot:Xn,LikertChart:gn,FunnelChart:Gn,RadarChart:jn,GaugeChart:Mn,OrdinalCustomChart:Or,ParallelCoordinatesRecipe:Nr,CalendarHeatmapRecipe:zr,ForceDirectedGraph:vr,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:Sr,ProcessSankey:Ar,ChordDiagram:br,TreeDiagram:Mr,Treemap:_r,CirclePack:wr,OrbitDiagram:kr,ChoroplethMap:Rr,ProportionalSymbolMap:Cr,FlowMap:Dr,DistanceCartogram:Ir,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:kl,EventDropChart:Al,UnitPileChart:Sl,CollisionSwarmChart:Ml,ProcessFlowChart:_l,GauntletChart:Pl,CrucibleChart:Ll,PacketFlowChart:$l,ChainReactionChart:{frameType:"physics",layout:{primarySize:{width:920,height:620}},buildProps:Jf,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,l]=n.size??[920,620],c="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=(jf(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 l=(jf(r,s,t.laneAccessor)??"Unassigned")+"";i.has(l)||(i.add(l),n.push(l));const c=jf(r,s,t.dependencyAccessor)??[],u=Array.from(new Set(Array.from(c,t=>t+""))).sort(Yf),d=jf(r,s,t.blockerAccessor),h=jf(r,s,t.statusAccessor)??(d?"blocked":"waiting");o.set(a,{id:a,label:(jf(r,s,t.labelAccessor)??a)+"",lane:l,laneIndex:0,level:0,index:s,datum:r,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:jf(r,s,t.startAccessor),end:jf(r,s,t.endAccessor),progress:Vf(jf(r,s,t.progressAccessor)),status:h,completionTime:jf(r,s,t.completionTimeAccessor),blockerReason:d||void 0,milestone:!!jf(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,l=new Map;for(const t of o.keys())a.set(t,[]),l.set(t,[]);const c=[],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:Xf(n,t.id),sourceID:n,targetID:t.id,sourceIndex:r.index,targetIndex:t.index,socketID:Gf(t.id,i),socketIndex:i};c.push(s),a.get(t.id)?.push(s),l.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)=>Yf(t.sourceID,e.sourceID)),t.forEach((t,e)=>{t.socketIndex=e,t.socketID=Gf(t.targetID,e)});for(const t of l.values())t.sort((t,e)=>Yf(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=(l.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(Yf);let p=0;for(;f.length;){const t=f.shift();p+=1;for(const e of l.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(Yf);e.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${t.join(", ")}.`,taskIDs:t})}let g=0;const y=[...o.values()].sort((t,e)=>t.index-e.index);for(const t of y)t.level=h.get(t.id)??0,g=Math.max(g,t.level);return{nodes:y,edges:c,byID:o,incoming:a,outgoing:l,lanes:r,maxLevel:g,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=De(n.theme),h=Fe(d),f=ff(n),p=f+"-title",g=f+"-description";if(!u.valid){const t=u.diagnostics.map(t=>t.message).join(" "),o=Ff.renderToStaticMarkup(Uf("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:l,role:"img","aria-labelledby":`${p} ${g}`,style:{fontFamily:h.fontFamily},children:[qf("title",{id:p,children:c}),qf("desc",{id:g,children:t}),qf("rect",{width:a,height:l,fill:h.background}),qf("text",{x:24,y:36,fontSize:16,fontWeight:700,fill:h.text,children:c}),u.diagnostics.map((t,e)=>qf("text",{x:24,y:72+22*e,fontSize:12,fill:d.colors.error,children:t.message},`${t.code}-${e}`))]}));return e&&(e.evidence=Uu({frameType:"physics",width:a,height:l,parts:[],title:c,description:t,nodeCount:u.nodes.length,edgeCount:u.edges.length,extraWarnings:["INVALID_DEPENDENCY_GRAPH"]})),o}const y=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,l=Math.max(70,(n-2*r)/Math.max(1,t.lanes.length)),c=Math.max(76,(i-s-a)/Math.max(1,t.maxLevel+1)),u=Math.min(o.taskWidth??112,Math.max(58,.78*l)),d=Math.min(o.taskHeight??58,.64*c),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)=>Yf(t.id,e.id));const g=.86*c,y=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,(g-4*(i-1))/i)):d;var i;return{taskID:t.id,lane:t.lane,laneIndex:t.laneIndex,level:t.level,x:r+l*(t.laneIndex+.5),y:s+c*(t.level+.5)+o*(n+4),width:u,height:n}}),m=new Map(y.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,l=i.y-i.height/2-h-2;x.push({id:e.socketID,edgeID:e.id,taskID:i.taskID,index:e.socketIndex,x:a,y:l,radius:h});const c={x:n.x,y:n.y+n.height/2+3},u=Math.min(l-10,c.y+.48*Math.max(18,l-c.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=[c,{x:c.x,y:u},{x:a,y:u},{x:a,y:l}],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:y,sockets:x,routes:b,taskByID:m,socketByID:v,routeByEdgeID:w}}(u,{width:a,height:l}),m=function(t,e,o){const n=t.nodes.map(Wf).filter(t=>null!=t),i=o,r=new Set,s=new Map;for(const e of t.nodes){const t=Wf(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:Bf(t,a,s,r),blockers:s,previewTaskID:null}}(u,0,Ef(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?Hf(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=Hf(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=Ff.renderToStaticMarkup(qf(zf,{machine:u,layout:y,runtime:m,downstreamSet:k,selectedSet:b,width:a,height:l,seed:A,reduced:!0,onSelectTask:()=>{}})),_=void 0===n.theme?{}:St(d),P=Ff.renderToStaticMarkup(Uf("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:l,role:"img","aria-labelledby":`${p} ${g}`,style:{..._,fontFamily:h.fontFamily},children:[qf("title",{id:p,children:c}),qf("desc",{id:g,children:S}),qf("rect",{width:a,height:l,fill:h.background}),qf("text",{x:a/2,y:22,textAnchor:"middle",fontSize:h.titleFontSize,fontFamily:h.titleFontFamily,fontWeight:h.titleFontWeight,fill:h.text,children:c}),qf("g",{dangerouslySetInnerHTML:{__html:M}})]}));return e&&(e.evidence=Uu({frameType:"physics",width:a,height:l,parts:[],additionalMarkCountByType:{task:u.nodes.length,dependency:u.edges.length},title:c,description:S,categories:u.lanes,nodeCount:u.nodes.length,edgeCount:u.edges.length})),P}},PhysicsCustomChart:Tl};import*as lp from"react";import*as cp from"react-dom/server";import{scaleBand as up,scaleLinear as dp}from"d3-scale";var hp=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:we(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||me,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function fp(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 pp(t){const e=t.getSymbol;return e?x(e,t.config.symbolMap):null}function gp(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 yp(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,l=-Math.PI/2+(n.startAngle||0)*Math.PI/180,c=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=l+u*c,p=l+(u+("number"==typeof o?._pct?o._pct:e.pct))*c,g=i(e.pieceData[0],e.name),y=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:g,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:f&&(x.roundedEnds={start:y,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as mp}from"d3-array";function xp(t,e,o){return{...t[0],...o,category:e,data:t}}function bp(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:mp(t,.25)??o,median:mp(t,.5)??(o+n)/2,q3:mp(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as vp}from"d3-scale";var wp={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h="horizontal"===c,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 c=e.get(r);if(!c)continue;let p=c.total;f&&o>0&&(p/=o);const g=a(c.pieces[0],s?r:t.name),y={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:t.name};if(d){const e=l(0>p?i:n+p),o=0>p?l(i+p)-l(i):l(n)-l(n+p);u.push(hc(t.x,e,t.width,Math.abs(o),g,y,r)),0>p?i+=p:n+=p}else if(h){const e=l(0>p?i+p:n),o=0>p?l(i)-l(i+p):l(n+p)-l(n);u.push(hc(e,t.x,Math.abs(o),t.width,g,y,r)),0>p?i+=p:n+=p}}}const g="vertical"===c;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=g?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(g?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=fp(i.roundedTop,e,g);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(g?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=fp(i.roundedTop,t,g);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:l,projection:c}=o,u=[],d="vertical"===c,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 c=i.get(h[s])||[];for(const i of c){const c=r(i),f=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(hc(r,Math.min(a,d),n,Math.abs(a-d),f,i,h[s]))}else{const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(hc(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=fp(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:l}=o,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,f=pp(t),p=2*Math.PI,g=-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),l=h&&r[o]||a,y=s(e,t.name),m=y.r||5;let x,b;if(d){const e=g+(t.pctStart+t.pct/2)*p,o=l(n);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=l(n)):(x=l(n),b=t.middle);gp(c,f,e,x,b,m,y)}return c},swarm:function(t,e){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="vertical"===a,u=pp(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;gp(l,u,n,c?t.middle+f:s(a),c?s(a):t.middle+f,h,d)}}return l},pie:yp,donut:yp,boxplot:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,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],l=mp(o,.25)??n,h=mp(o,.5)??(n+i)/2,f=mp(o,.75)??i,p=f-l,g=l-1.5*p,y=f+1.5*p,m=o.find(t=>t>=g)??n,x=[...o].reverse().find(t=>y>=t)??i,b={n:o.length,min:m,q1:l,median:h,q3:f,max:x,mean:o.reduce((t,e)=>t+e,0)/o.length},v=s(xp(e.pieceData,e.name,b),e.name),w=[];if(d)for(const t of e.pieceData){const o=r(t);if(g>o||o>y){const n=u?e.middle:a(o),i=u?a(o):e.middle;w.push({px:n,py:i,value:o,datum:t})}}if(c.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(l),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)c.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 c},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,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,l=Array(d).fill(0);for(const t of e)l[Math.min(Math.floor((t-o)/i),d-1)]++;const f=lt(l,1),p=t.width/2*.9;let g;if(u){g=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);g+=` L ${t.middle+l[e]/f*p} ${n}`}g+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);g+=` L ${t.middle-l[e]/f*p} ${n}`}g+=" Z"}else{g=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)g+=` L ${a(o+(e+.5)*i)} ${t.middle-l[e]/f*p}`;g+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)g+=` L ${a(o+(e+.5)*i)} ${t.middle+l[e]/f*p}`;g+=" Z"}const y=bp(e),m=s(xp(t.pieceData,t.name,y),t.name);let x;if(h&&e.length>=4){const i=mp(e,.25)??o,r=mp(e,.5)??(o+n)/2,s=mp(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};c.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:b,iqrLine:x,stats:y,style:m,datum:t.pieceData,category:t.name})}return c},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,l=[],c=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]=ut(e),i=null!=h&&isFinite(h)?h:o,d=null!=f&&isFinite(f)?f:n,p=(d-i)/c||1,g=Array(c).fill(0);for(const t of e)i>t||t>d||g[Math.min(Math.floor((t-i)/p),c-1)]++;const y=e.length,m=lt(g,1);for(let e=0;c>e;e++){if(0===g[e])continue;const o=(u?g[e]/y:g[e]/m)*t.width*.9,n=a(i+e*p),r=a(i+(e+1)*p),c=Math.min(n,r),d=Math.abs(r-n),h=t.x+t.width-o,f={...t.pieceData[0],bin:e,count:g[e],range:[i+e*p,i+(e+1)*p],category:t.name,data:t.pieceData},x=s(f,t.name);l.push(hc(c,h,d,o,x,f,t.name))}}return l},ridgeline:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u=i.bins||20,d="horizontal"===l,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,l=Array(u).fill(0);for(const t of e)o>t||t>n||l[Math.min(Math.floor((t-o)/i),u-1)]++;const f=lt(l,1),p=bp(e),g=s(xp(t.pieceData,t.name,p),t.name),y=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-l[t]/f*y}`;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+l[t]/f*y} ${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))};c.push({type:"violin",pathString:m,translateX:0,translateY:0,bounds:x,stats:p,style:{...g,fillOpacity:g.fillOpacity??.5},datum:t.pieceData,category:t.name})}return c},timeline:function(t,e){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="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(c){const o=s(Math.min(n,a)),i=s(Math.max(n,a));l.push(hc(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));l.push(hc(t.x,o,t.width,i-o,u,e,t.name))}}return l},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,l=!1!==t.config.showLabels,c=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const t of c)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 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}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 g=new Map;for(const t of u){const e=f[0].groups.get(t);g.set(t,e?.total??0)}const y=f[0].stepTotal,m=h?.95*a:.9*e.width,x=vp().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,c=n.width,d=.55*c,p=n.x+(c-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,c=a;for(let h=0;u.length>h;h++){const f=u[h],y=o.groups.get(f);if(!y)continue;const b=x(y.total),v=h%2==0,w=v?e:c-b;v?e+=b:c-=b;const k=r(y.pieces[0],f),A=g.get(f)??y.total,S={...y.pieces[0],__funnelValue:y.total,__funnelPercent:A>0?y.total/A*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:f};l&&(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(hc(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),c=a-e/2,h=u[0],f="_default"!==h,g=o.groups.get(h)?.pieces[0]??n.pieceData[0],b=f?h:n.name,v=r(g,b),w=y>0?t/y*100:0,k={...g,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:f?h:n.name};l&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(hc(c,p,e,d,v,k,b)),m.set(h,{x:c,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 l=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),c={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:l.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:l.cursor},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],l=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),c.push(t))}const d=c.length>1&&"_default"!==c[0],h=[];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}h.push({col:t,groups:e,stepTotal:o})}const f=new Map;for(const t of c){const e=h[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,g=d?c.length:1,y=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/g,l=s*y,u=s-l;for(let t=0;c.length>t;t++){const h=c[t],g=e.groups.get(h);if(!g)continue;const y=g.total,m=f.get(h)??y,x=m>0?y/m*100:0,b=i?.groups.get(h),v=n?0:Math.max(0,(b?.total??y)-y),w=o.x+t*s+l/2,k=p(y),A=p(0)-k,S=r(g.pieces[0],d?h:o.name),M={...g.pieces[0],__barFunnelValue:y,__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(y+v)};if(a.push(hc(w,k,u,A,S,M,d?h:o.name)),v>0){const t=p(y+v),e=k-t,n={...S},i={...g.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(hc(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:l}=o,c=[],u="horizontal"===l,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},g=t.config.trackFill;if(g){const t="string"==typeof g?g:g.color,e="string"==typeof g?1:g.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?hc(r,o.x,s,o.width,n,null,"__track__"):hc(o.x,r,o.width,s,n,null,"__track__"),a=p(o);a>0&&(i.cornerRadii={tl:a,tr:a,br:a,bl:a}),c.push(i)}}for(const t of Object.values(n)){let e=0;const o=c.length,n=p(t);for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const l=r?r(o):t.name,f=s(o,l);let p;if(u){const i=a(e),r=a(e+n);p=hc(i,t.x,r-i,t.width,f,o,l)}else{const i=a(e+n),r=a(e);p=hc(t.x,i,t.width,r-i,f,o,l)}d&&(p.fillGradient=d,p.roundedEdge=h),c.push(p),e+=n}if(n>0&&c.length>o){const t=c.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 c}},kp=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ap=["scene-style","data-paint","accessibility","evidence"],Sp=(t,e)=>({retainedData:t,invalidations:e}),Mp=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],_p=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Pp=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Lp=["scene-geometry","data-paint","accessibility","evidence"],$p=["scene-style","data-paint","accessibility","evidence"],Tp=[],Rp={chartType:Sp("rebuild",Mp),runtimeMode:Sp("rebuild",Mp),categoryAccessor:Sp("rebuild",Mp),valueAccessor:Sp("rebuild",Mp),oAccessor:Sp("rebuild",Mp),rAccessor:Sp("rebuild",Mp),stackBy:Sp("rebuild",Mp),groupBy:Sp("rebuild",Mp),timeAccessor:Sp("rebuild",Mp),accessorRevision:Sp("rebuild",Mp),colorAccessor:Sp("rebuild",$p),symbolAccessor:Sp("rebuild",Lp),connectorAccessor:Sp("rebuild",Lp),dataIdAccessor:Sp("rebuild",Lp),projection:Sp("preserve",_p),extentPadding:Sp("preserve",_p),axisExtent:Sp("preserve",_p),rExtent:Sp("preserve",_p),oExtent:Sp("preserve",_p),multiAxis:Sp("preserve",_p),normalize:Sp("preserve",_p),bins:Sp("preserve",_p),oSort:Sp("preserve",Pp),barPadding:Sp("preserve",Pp),roundedTop:Sp("preserve",Pp),baselinePadding:Sp("preserve",Pp),innerRadius:Sp("preserve",Pp),cornerRadius:Sp("preserve",Pp),startAngle:Sp("preserve",Pp),sweepAngle:Sp("preserve",Pp),trackFill:Sp("preserve",Pp),showOutliers:Sp("preserve",Pp),showIQR:Sp("preserve",Pp),amplitude:Sp("preserve",Pp),connectorOpacity:Sp("preserve",Pp),showLabels:Sp("preserve",Pp),dynamicColumnWidth:Sp("rebuild",Pp),customLayout:Sp("preserve",Pp),layoutConfig:Sp("preserve",Pp),layoutMargin:Sp("preserve",Pp),symbolMap:Sp("preserve",Lp),pieceStyle:Sp("preserve",$p),summaryStyle:Sp("preserve",$p),connectorStyle:Sp("preserve",$p),gradientFill:Sp("preserve",$p),colorScheme:Sp("preserve",$p),themeCategorical:Sp("preserve",$p),themeSemantic:Sp("preserve",$p),themeSequential:Sp("preserve",$p),themeDiverging:Sp("preserve",$p),barColors:Sp("preserve",$p),decay:Sp("preserve",$p),pulse:Sp("preserve",$p),staleness:Sp("preserve",$p),layoutSelection:Sp("preserve",$p),windowSize:Sp("preserve",Tp),windowMode:Sp("preserve",Tp),clock:Sp("preserve",Tp),transition:Sp("preserve",Tp),introAnimation:Sp("preserve",Tp),onLayoutError:Sp("preserve",Tp)},Cp=Sp("preserve",Pp),Ip=class{constructor(){this.tracker=new e}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}},kp)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Ap):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=Rp[n]??Cp;"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 Dp}from"d3-quadtree";var Fp=class{constructor(t){this.rExtent=new E,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Ip,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new hp,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 W(t.windowSize),this.getO=at(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>nt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new E)):(this.getR=nt(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=at(t.stackBy),this.getGroup=at(t.groupBy),this.getColor=at(t.colorAccessor),this.getSymbol=at(t.symbolAccessor),this.getConnector=at(t.connectorAccessor),this.getDataId=at(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new W(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:mc(e,n):null)}currentTime(){return this.config.clock?.()??zl()}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(),yc(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)xc(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=xc(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",l=e.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),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=up().domain(l).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;p=dp().domain(c).range([n,o])}else u?(f=up().domain(l).range([0,t.height]).padding(h),p=dp().domain(c).range([0,t.width])):(f=up().domain(l).range([0,t.width]).padding(h),p=dp().domain(c).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 l=a-s,c=l>0?l*(e.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?dp().domain([s,a]).range([0,t.width]):dp().domain([s,a]).range([t.height,0])}):[];let g=s;this.rAccessors.length>1&&(g=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(g,l,f,a,t),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(g,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=y,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:l,getO:c,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let p=0,g=0;if("bar"===o&&d&&i)p=0,g=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=c(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>g&&(g=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=c(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e),p>e&&(p=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=c(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>g&&(g=e),p>e&&(p=e)}else{const t=h[0],e=h[1];t!==1/0&&(p=t),e!==-1/0&&(g=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(g=r[1]));const y="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(y&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>g&&(g=0)),"bar-funnel"!==o&&"exact"!==l){const t=g-p,e=t>0?t*f:1,n=y&&!a&&0===p,i=y&&!a&&0===g||"swimlane"===o;null!=r?.[0]||n||(p-=e),null!=r?.[1]||i||(g+=e)}return[p,g]}({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:l}=t,c=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(l(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(l(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()),c[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 c}({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=Jl({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 Zl({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=wp[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,l=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)),l.has(o)||l.set(o,[]),l.get(o).push({x:n,y:s,datum:e,category:r(e)})}const c=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 l)if(e.length>=2){e.sort((t,e)=>c.indexOf(t.category)-c.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=cs(o.colorScheme,o.themeCategorical,me),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:us(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?El(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=Wl(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],l=i.get(a);l?l.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:Dp().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 l=!1;for(const c of e){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const e=c.category;if(!e)continue;let n=0;for(const s of i(e)??[]){const e=o.get(s);null!=e&&(n=Math.max(n,Bl(t,e,r)))}l=jl(c,n,s)||l;continue}if(null==c.datum)continue;const e=n.get(c.datum);if(null==e)continue;const u=o.get(e);l=jl(c,null==u?0:Bl(t,u,r),s,a)||l}return l}(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&&Yl(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=Ol(t,this.activeTransition),o=Fl(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=Nl(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Nl(n.x,t._targetX,o),t.y=Nl(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Nl(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Nl(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=Nl(n.x,t._targetX,o),t.y=Nl(n.y,t._targetY,o),void 0!==n.w&&(t.w=Nl(n.w,t._targetW,o),t.h=Nl(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:Nl(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=Nl(n.startAngle,t._targetStartAngle,o),t.endAngle=Nl(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=Dl(t),o=this.getDataId,n=t=>e.has(o(t));bc(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=Dl(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&&!et(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!et(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!et(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)&&(et(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=at(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)=>!et(t,r[e])),i){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>nt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new E)):(this.getR=nt(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!et(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?at(this.config.stackBy):void 0),"groupBy"in t&&!et(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?at(this.config.groupBy):void 0),"colorAccessor"in t&&!et(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?at(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!et(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?at(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!et(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?at(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}};Pc(Fp);import*as Op from"react";import{jsx as Np,jsxs as zp}from"react/jsx-runtime";function Ep(t){return"connector"===t.node.type}function Wp(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=sd(`${e?e+"-":""}connector-${o}-${n}-hatch`),a=G(r)?X(r,s):null,l=[`${i.x1},${i.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return fd(zp(Op.Fragment,{children:[a&&Np("defs",{children:a}),Np("polygon",{points:l,fill:a?`url(#${s})`:rd(r,"#999"),opacity:i.style.fillOpacity??i.style.opacity??.3,"data-semiotic-connector-fill":i.group||"_default"})]}),i,`ordinal-connector-fill-${o}-${n}`)}function Bp(t,e,o){const n=new Map;for(const e of t){if(!Ep(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)=>zp("g",{children:[Wp(t,e,o,n),t.map(t=>t.element)]},`ordinal-connectors-${o}-${n}`)),r=t[0],s=Ep(r)?null:r.element;for(const t of n.values())for(const e of t)e.element=null;r.element=zp(Op.Fragment,{children:[i,s]},"ordinal-connector-run-"+o)}function jp(t){const e=Fd({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>function(t,e,o){return fd(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=sd(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=ld(o.stops,rd(t.style.fill));return a?od("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(G(e.style.fill)){const t=sd(r)+"-hatch";i=X(e.style.fill,t),s=`url(#${t})`}else s=rd(e.style.fill);const a=n||i?_d("defs",{children:[n,i]}):null;if(e.cornerRadii&&Iu(e.cornerRadii)){const t=function(t){const{x:e,y:o,w:n,h:i}=t,{tl:r,tr:s,br:a,bl:l}=Du(t);let c=`M${e+r},${o}`;return c+=` L${e+n-s},${o}`,s>0&&(c+=` A${s},${s} 0 0 1 ${e+n},${o+s}`),c+=` L${e+n},${o+i-a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${e+n-a},${o+i}`),c+=` L${e+l},${o+i}`,l>0&&(c+=` A${l},${l} 0 0 1 ${e},${o+i-l}`),c+=` L${e},${o+r}`,r>0&&(c+=` A${r},${r} 0 0 1 ${e+r},${o}`),c+=" Z",c}(e);return _d(wd.Fragment,{children:[a,Md("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:l}=e;let c;switch(e.roundedEdge){case"right":c=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+l-t} A${t},${t} 0 0 1 ${o+i-t},${n+l} L${o},${n+l} Z`;break;case"left":c=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+l-t} A${t},${t} 0 0 0 ${o+t},${n+l} L${o+i},${n+l} Z`;break;case"bottom":c=`M${o},${n} L${o+i},${n} L${o+i},${n+l-t} A${t},${t} 0 0 1 ${o+i-t},${n+l} L${o+t},${n+l} A${t},${t} 0 0 1 ${o},${n+l-t} Z`;break;default:c=`M${o},${n+l} 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+l} Z`}return _d(wd.Fragment,{children:[a,Md("path",{d:c,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return _d(wd.Fragment,{children:[a,Md("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}),Ld(e,r)]},r)}case"point":{const e=t;return Md("circle",{cx:e.x,cy:e.y,r:e.r,fill:rd(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return cd(t,e,o);case"glyph":return ad(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=sd(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=Sd({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:Sd({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 _d("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[Md("defs",{children:Md("clipPath",{id:t,children:Md("path",{d:i})})}),Md("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>Md("path",{d:t.d,fill:rd(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&Md("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=Sd({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=kd().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(id)||""}return Md("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:rd(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 _d("g","vertical"===e.projection?{children:[Md("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n}),Md("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:rd(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),Md("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*n}),Md("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:n}),Md("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:[Md("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:n}),Md("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:rd(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),Md("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*n}),Md("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n}),Md("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=[Md("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:rd(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(Md("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),Md("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(Md("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),Md("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return Md("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?rd(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return Md("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 Md("polygon",{points:o,fill:rd(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++;Bp(e.slice(n,i),t.idPrefix,o++),n=i}return e}import{jsx as Yp,jsxs as Xp}from"react/jsx-runtime";import{Fragment as Gp,jsx as Vp,jsxs as Hp}from"react/jsx-runtime";var qp=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function Up(t,e){const o=De(t.theme),n=t.size||[500,400],i=yo({...Mf,...t.margin},t.title),r=po(t.title),s=Wt(t.data),a=t.showLegend?Hd(s,t.colorAccessor||t.stackBy||t.groupBy):[],l=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)});xf(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=bf({props:{...t,axisChrome:l},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,g={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:Pe(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},y=new Fp(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Sf(t.backgroundGraphics,n,i,y.scales),x=Sf(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?Yh({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=Qu({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),cp.renderToStaticMarkup(wf(m||x||t.annotations?Hp(Gp,{children:[m,a,x,y.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:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=Fe(o),a=n?n+"-":"",l="vertical"===r.projection,c=ef(r.r,5,i);return uf("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return uf("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:c.map((t,o)=>{const n=r.r(t);return uf("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(y,{width:u,height:d},o,b,t.axisExtent):null;let w=null;if(y.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=ff(t),n=new Set;for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");w=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 Xp("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Yp("rect",{width:a,height:a,fill:o}),Yp("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Yp("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 y.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 k=jp({nodes:y.scene,renderMode:t.renderMode,idPrefix:b}),A=k.map(t=>t.element),S=!1!==t.showAxes?function(t,e,o,n,i,r,s,a=!1){const l=t.scales;if(!l)return null;if("radial"===l.projection)return null;const c=Fe(n),u="vertical"===l.projection,d=t.columns,h=o.categoryFormat||o.oFormat,f=o.valueFormat||o.rFormat,p=o.categoryLabel||o.oLabel,g=o.valueLabel||o.rLabel,y=o.legendPosition??"right",m=wo(o.legendLayout,s?.leftAxis),x=a&&"left"===y&&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=ef(l.r,5,o.axisExtent).map(t=>({pixel:l.r(t),label:(f||vf)(t)}));return Hp("g",u?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Vp("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,o)=>Hp("g",{transform:`translate(${t.pixel},${e.height})`,children:[Vp("line",{y2:5,stroke:c.border,strokeWidth:1}),nf(t.label)?Vp("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):rf({label:t.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oxtick-"+o)),p&&Vp("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:p}),Vp("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,e)=>Hp("g",{transform:`translate(0,${t.pixel})`,children:[Vp("line",{x2:-5,stroke:c.border,strokeWidth:1}),Vp("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oytick-"+e)),g&&Vp("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:g})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Vp("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,o)=>Hp("g",{transform:`translate(${t.pixel},${e.height})`,children:[Vp("line",{y2:5,stroke:c.border,strokeWidth:1}),Vp("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oxtick-"+o)),g&&Vp("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),Vp("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,e)=>Hp("g",{transform:`translate(0,${t.pixel})`,children:[Vp("line",{x2:-5,stroke:c.border,strokeWidth:1}),nf(t.label)?Vp("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):rf({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oytick-"+e)),p&&Vp("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:p})]})}(y,{width:u,height:d},t,o,b,i,l,!!c):null;let M;const _=t.annotations?Yh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.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:b,onRender:t=>{M=t}}):null;if(e){const o=y.scales.o?.domain?.();e.evidence=Qu({frameType:"ordinal",width:n[0],height:n[1],marks:k.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:M,yDomain:Ku(y.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const P=f&&t.centerContent?function(t,e,o){if(!lp.isValidElement(t))return null;if("string"!=typeof t.type||!qp.has(t.type))return null;const n=t,i="text"===n.type?lp.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return Vp("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,L=f&&t.centerContent?P??Vp("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:Vp("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,$=Hp(Gp,{children:[v,A,S,_,x,y.customLayoutOverlays]});return cp.renderToStaticMarkup(wf(Hp(Gp,f?{children:[m?Vp("g",{transform:`translate(${-u/2},${-d/2})`,children:m}):null,$]}:{children:[m,$]}),{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:c,defs:w,outerElements:L,idPrefix:t._idPrefix}))}import*as Zp from"react-dom/server";var Kp=Object.create(null);function Qp(t,e){Kp[t]=e}function Jp(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function tg(t,e){var o,n=[],i=[],r=[],s={},a=[];function l(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&l(e)})}function c(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=c(n));if(d)l(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),l=0;e>l;++l)o[l]=-1,n[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function f(e){var l=[e],c=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;c.length>0;){var f=t[e=c[c.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var g=f[p];if(0>o[g]){o[g]=n[g]=u,i[g]=!0,u+=1,l.push(g),c.push(g);break}i[g]&&(n[e]=0|Math.min(n[e],n[g])),0>s[g]||a[e].push(s[g])}r[e]=p}else{if(n[e]===o[e]){var y=[],m=[],x=0;for(p=l.length-1;p>=0;--p){var b=l[p];if(i[b]=!1,y.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){l.length=p;break}}d.push(y);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)}c.pop()}}}for(l=0;e>l;++l)0>o[l]&&f(l);for(l=0;h.length>l;l++){var p=h[l];if(0!==p.length){p.sort(function(t,e){return t-e}),c=[p[0]];for(var g=1;p.length>g;g++)p[g]!==p[g-1]&&c.push(p[g]);h[l]=c}}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 l=i[o];return!!l&&{leastVertex:r,adjList:t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.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 g=0;a[p].length>g;g++){var y=a[p][g];r[+y]=!1,s[y]={}}c(o),o+=1}else o=h}return e?void 0:n}function eg(t){return t.y0-t.y1>0?"up":"down"}function og(t,e){return e(t.source)==e(t.target)}function ng(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 ig(t){return t.target.x0-t.source.x1}function rg(t,e){var o=ag(t),n=ig(e)/Math.tan(o);return"up"==eg(t)?t.y1-n:t.y1+n}function sg(t,e){var o=ag(t),n=ig(e)/Math.tan(o);return"up"==eg(t)?t.y1+n:t.y1-n}function ag(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function lg(t,e){return e(t)}function cg(t){return dg(t.source)}function ug(t){return dg(t.target)}function dg(t){return(t.y0+t.y1)/2}function hg(t){return t.virtual?0:t.value}function fg(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!og(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!og(t,e)?n+1:n}),o+n}function pg(t){return t.target.depth}function gg(t,e){return t.sourceLinks.length?t.depth:e-1}function yg(t,e){return t.y0-e.y0}function mg(t,e){return e.y0-t.y0}function xg(t,e){return t.y1-e.y1}function bg(t,e){return e.y1-t.y1}function vg(t,e){return kg(t.source,e.source)||t.index-e.index}function wg(t,e){return kg(t.target,e.target)||t.index-e.index}function kg(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function Ag(t,e){return Sg(t)==Sg(e)?"bottom"==t.circularLinkType?mg(t,e):yg(t,e):Sg(e)-Sg(t)}function Sg(t){return t.target.column-t.source.column}function Mg(t,e){return _g(t)==_g(e)}function _g(t){return t.y0-t.y1>0?"up":"down"}import{min as Pg}from"d3-array";function Lg(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=Pg(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var l=r.links.filter(function(t){return t.circular});return l.sort(function(t,e){return e.value-t.value}),l.forEach(function(t,e){t._circularStub=e>=4}),$g(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),$g(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,og(t,e)&&ng(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,l=t.circularLinkType,c=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==l});c.sort("bottom"==t.circularLinkType?mg:yg);var u=0;c.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,(c=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==l})).sort("bottom"==t.circularLinkType?bg:xg),u=0,c.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 $g(t,e,o){t.sort(Ag);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(og(t,e)&&ng(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&&Tg(t,a)){var l=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=l>r?l:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function Tg(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as Rg,max as Cg,sum as Ig,mean as Dg,group as Fg,groups as Og}from"d3-array";function Ng(t){return function(){return t}}function zg(t){return t.index}function Eg(t){return t.nodes}function Wg(t){return t.links}function Bg(t,e,o){var n=Og(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+=dg(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=dg(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?fg(e,o)-fg(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==fg(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 jg(t,e,o,n,i,r){var s=Og(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,l=r;l>0;--l)c(a*=.99,o),u();function c(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&&fg(i,o)>0){var l=Dg(i.sourceLinks,ug),c=Dg(i.targetLinks,cg),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-dg(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=Dg(i.sourceLinks,ug),f=Dg(i.targetLinks,cg),p=((h&&f?(h+f)/2:h||f)-dg(i))*e;i.y0+=p,i.y1+=p}})})}function u(){s.forEach(function(o){var r,s,a,l=t.y0,c=o.length;for(o.sort(e||kg),a=0;c>a;++a)(s=l-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),l=r.y1+n;if((s=l-n-t.y1)>0)for(l=r.y0-=s,r.y1-=s,a=c-2;a>=0;--a)(s=(r=o[a]).y1+i-l)>0&&(r.y0-=s,r.y1-=s),l=r.y0})}}function Yg(t){t.nodes.forEach(function(t){t.sourceLinks.sort(wg),t.targetLinks.sort(vg)}),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 Xg(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=zg,l=gg,c=void 0,u=32,d=2,h=Eg,f=Wg;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 Fg(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=Jp(o,n)),"object"!=typeof i&&(i=t.target=Jp(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 l=tg(n);l.sort(function(t,e){return t.length-e.length});var c={};for(i=0;l.length>i;i++){var u=l[i].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||c[n]&&c[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,c),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){lg(t,e)!=lg(i.source,e)&&lg(t,e)!=lg(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),og(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(Ig(t.sourceLinks,hg),Ig(t.targetLinks,hg)),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,c,l);var f=r;if(null!==s){var p=Og(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),g=Cg(p,function(t){return t.length});g>1&&(f=Math.max(1,(n-e)*s/(g-1)))}(function(t,e,o){var n=Og(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=Rg(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/Ig(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=Cg(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),Bg(h,c,a),jg(h,c,a,f,f,u),Yg(h),Lg(h,a,d,10,8),Bg(h,c,a),jg(h,c,a,f,f,u),Yg(h),Lg(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 lg(o.source,e)==lg(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(!Mg(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=rg(e,t);return t.y1-o}if(e.target.column>t.target.column)return rg(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 lg(o.target,e)==lg(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(!Mg(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=sg(e,t);return t.y0-o}if(e.source.column>t.source.column)return sg(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=Rg(e,function(t){return t.y0}),s=Cg(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),Lg(h,a,d,10,8)}(p),p}return p.update=function(t){return Yg(t),Lg(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:Ng(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:Ng(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:Ng(t),p):a},p.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:Ng(t),p):l},p.nodeSort=function(t){return arguments.length?(c=t,p):c},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 Gg}from"d3-interpolate";import{line as Vg,curveLinearClosed as Hg}from"d3-shape";var qg=t=>{let e,o,n,i,r,s,a,l,c;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=Gg(r,s),l=a(.5),c=a(.5),`M${e},${r}C${e},${l} ${o},${c} ${o},${s}L${n},${s}C${n},${c} ${i},${l} ${i},${r}Z`;const u=t.sankeyWidth/2,d=Gg(t.source.x1,t.target.x0),{pathD:h}=Ki({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 Ug(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))),l=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-l},${s-e}L${r-l},${s+e}L${r},${s+e}Z`}const i=n.sourceX,r=n.sourceY,s=n.targetX,a=n.targetY,l=n.rightFullExtent,c=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${l},${r-d*e}L${l+o},${r-d*e+d*h}L${l+o},${u+d*o-d*h}L${l+o-h},${u+d*o}L${c-o+h},${u+d*o}L${c-o},${u+d*o-d*h}L${c-o},${a-d*e+d*h}L${c-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${c+o},${a+d*e}L${c+o},${u-d*o}L${l-o},${u-d*o}L${l-o},${r+d*e}L${i},${r+d*e}Z`}var Zg=new Set,Kg=new WeakMap;function Qg(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let o=Kg.get(t);if(o){const t=o.get(e);if(t)return t}else o=new Map,Kg.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}`;Zg.has(t)||(Zg.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 Jg={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(pg))-1:0},justify:gg},ty={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,l=o.iterations??100,c=t.map(t=>({...t})),u=e.map(t=>({...t,source:rt(t.source),target:rt(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=Xg().extent(d).links(u).nodes(c).nodeAlign(Jg[r]||gg).nodeId(t=>t.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of c)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],l=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>l)){const e=Math.min(a/r,l/s),n=-t*e+(a-r*e)/2,i=-o*e+(l-s*e)/2;for(const t of c)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 c){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=rt(t.source),o=rt(t.target);p.set(`${e}\0${o}`,t)}for(const t of u){const e=rt(t.source),o=rt(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,l=o.edgeColorBy||"source",c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Gt,u=new Map;t.forEach((t,e)=>{u.set(t.id,c[e%c.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(Qg(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 g=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of g){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 l?l(t)||i:"target"===l?p.get(n.id)||u.get(n.id)||i:p.get(e.id)||u.get(e.id)||i;const r=s?s(Qg(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))),l=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:l,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:l,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 c;(c=t.circular&&t.circularPathData?Ug(t):qg(t),c)&&h.push({type:"bezier",pathD:c,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=it(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,l,c;"down"===i?(a=o.y0+(o.y1-o.y0)/2,l=o.x1+14,c="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,c="end"):(a=o.x1+6,c="start"),l=o.y0+r/2),f.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:f}}};Qp("sankey",ty);import{forceSimulation as ey,forceCenter as oy,forceX as ny,forceY as iy,forceLink as ry,forceManyBody as sy,forceCollide as ay}from"d3-force";var ly={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)),l=Math.min(.5,.06+1.8*(1-a)),c=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=c?.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=cy(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=uy(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=uy(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=C(o.nodeSize,o.nodeSizeRange,t),g=t=>p(t);if(f>0){const c=new Map,u=new Map;for(const e of t)c.set(e.id,0),u.set(e.id,e);for(const t of e){const e=rt(t.source),o=rt(t.target);c.set(e,(c.get(e)??0)+1),c.set(o,(c.get(o)??0)+1)}const d=ry().strength(t=>{const e=t.weight,o=rt(t.source),n=rt(t.target),r=Math.max(1,Math.min(c.get(o)??1,c.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?g(e):0)+(o?g(o):0)+Math.max(6,12*a);return Math.max(16,40*a,n)}).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",sy().strength(t=>{const e=c.get(t.id)??0;return-15*a*g(t)*Math.sqrt(e+1)})).force("collide",ay(t=>g(t)+3*a).strength(.9).iterations(2)).force("center",oy(r,s).strength(.8)).force("x",ny(r).strength(l)).force("y",iy(s).strength(l)).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,l=n.vy??0,c=e(n)+o,u=Math.min(t[0]/2,c),d=Math.max(t[0]/2,t[0]-c),h=Math.min(t[1]/2,c),f=Math.max(t[1]/2,t[1]-c),p=i+a,g=r+l;u>p?n.vx=a+(u-p)*s:p>d&&(n.vx=a+(d-p)*s),h>g?n.vy=l+(h-g)*s:g>f&&(n.vy=l+(f-g)*s)}};return r.initialize=t=>{i=t},r}(n,g)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:rt(t.source),target:rt(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=g(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 y=new Map;for(const e of t)y.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=y.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=y.get(t.target);e&&(t.target=e)}}},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=C(o.nodeSize,o.nodeSizeRange,t),a=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:Gt,l=new Map;t.forEach((t,e)=>{l.set(t.id,a[e%a.length])});const c=[],u=[],d=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(Qg(e,"nodeSize")),n=i?i(Qg(e,"nodeStyle")):{},r={fill:n.fill||l.get(e.id)||o.themeSemantic?.primary||"#007bff",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??2,opacity:n.opacity,cursor:n.cursor};c.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(Qg(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=it(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(Qg(o,"nodeSize"));d.push({x:o.x,y:o.y-n-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};function cy(t,e,o){const n=[];for(const i of e){const e=rt(i.source),r=rt(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 uy(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}Qp("force",ly);import{chord as dy,ribbon as hy}from"d3-chord";import{arc as fy}from"d3-shape";var py=Gt,gy={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,l=a-r,c=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,g=Array.from({length:p},()=>Array.from({length:p},()=>0));for(const t of e){const e=rt(t.source),o=rt(t.target),n=f.get(e),i=f.get(o);if(void 0===n||void 0===i)continue;const r=d(t);g[n][i]=r}const y=dy().padAngle(i);s&&y.sortGroups(s);const m=y(g),x=m.groups,b=fy().innerRadius(l).outerRadius(a);for(const e of x){const o=t[e.index],n=b.centroid({innerRadius:l,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=n[0]+c,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=rt(t.source),o=rt(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=rt(t.source),o=rt(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,l=n[0]/2,c=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:py,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const g=hy().radius(a),y=[],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(Qg(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(Qg(o,"nodeStyle")):{};y.push({type:"arc",cx:l,cy:c,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=g(e);if(!n)continue;const i=yy(n,l,c);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(Qg(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(Qg(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=it(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:l+Math.cos(s)*n,y:c+Math.sin(s)*n,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:y,sceneEdges:m,labels:x}}};function yy(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(" ")}Qp("chord",gy);import{hierarchy as my,tree as xy,cluster as by,treemap as vy,pack as wy,partition as ky,treemapBinary as Ay}from"d3-hierarchy";var Sy=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function My(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 _y(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 Py(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 Ly(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Sy}function $y(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 Ty(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 Ry={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,l="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,c=my(i,s);c.sum(l),c.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=xy();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"cluster":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=by();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"treemap":!function(t,e,o,n){const i=e.padding??4,r=e.paddingTop??0,s=vy().size([o,n]).tile(Ay).padding(i);r>0&&s.paddingTop(r),s(t)}(c,o,u,d);break;case"circlepack":!function(t,e,o,n){const i=e.padding??4;wy().size([o,n]).padding(i)(t)}(c,o,u,d);break;case"partition":!function(t,e,o,n){ky().size([o,n]).padding(e.padding??1)(t)}(c,o,u,d)}const h=c.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:_y(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?Cy(i,n,o):"treemap"===r||"partition"===r?Iy(i,n):"circlepack"===r&&Dy(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=[],l=[],c=o.treeOrientation||"vertical",u="radial"===c,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(Qg(e,"nodeStyle"));let a=r.fill||$y(o);if(o.colorByDepth&&void 0!==e.depth){const t=Ly(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 g=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,l=n.x,f=n.y;u&&(i+=d,s+=h,l+=d,f+=h);const p=Ty(i,s,l,f,c),y=r(Qg(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:y.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??g,cursor:y.cursor},datum:t})}if(!1!==o.showLabels){const e=Py(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"===c?(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");l.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(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(Qg(o,"nodeStyle"));let a=s.fill||$y(e);if(e.colorByDepth&&void 0!==o.depth){const t=Ly(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=Py(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,l=a.y1-a.y0;if(0>=t||0>=l)continue;const c=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!c)continue;if("parent"===i&&c)continue}const u=o?o(a):a.id;if(!u)continue;if((c?30:40)>t||(c?16:14)>l)continue;let d=n(Qg(a,"nodeStyle")).fill||$y(e);if(e.colorByDepth&&void 0!==a.depth){const t=Ly(e);d=t[a.depth%t.length]}const h="string"==typeof d?My(d):e.themeSemantic?.text??"#000";r.push(c?{x:a.x0+t/2,y:a.y0+l/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,l)/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(Qg(o,"nodeStyle"));let s=r.fill||$y(e);if(e.colorByDepth&&void 0!==o.depth){const t=Ly(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=Py(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 l=n(Qg(i,"nodeStyle")).fill||$y(e);if(e.colorByDepth&&void 0!==i.depth){const t=Ly(e);l=t[i.depth%t.length]}if(a){const o="string"==typeof l?My(l):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 Cy(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 Iy(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 Dy(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}Qp("tree",Ry),Qp("cluster",Ry),Qp("treemap",Ry),Qp("circlepack",Ry),Qp("partition",Ry);import{pie as Fy}from"d3-shape";function Oy(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var Ny={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),l=o.orbitSize??2.95,c=o.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=Oy(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 g=e[0]/2,y=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=p(s(t));n.push({id:x,x:g,y:y,x0:g,x1:g,y0:y,y1:y,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,l,c,f,g,y){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:g,data:e,parentId:o},M=y?f/u(S)*A:f*A,_=Fy().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=l+M*Math.sin(r),f=c+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:g,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:g,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,g+1,!0)}k+=v}}(t,x,g,y,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,l=[],c=[],u=[];if(!1!==o.orbitShowRings){const e=Oy(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,l=(i+1)/r*Math.PI*2;c.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(l),y2:e+o*Math.cos(l)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(Qg(e,"nodeSize")),n=i?i(Qg(e,"nodeStyle")):{};l.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(Qg(t,"edgeStyle")):{};c.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(Qg(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:l,sceneEdges:c,labels:u}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=Oy(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 l=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(l),e.y=n.y+t.ring*Math.cos(l)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)};function zy(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function Ey(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=p(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,N(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function Wy(t){if(!t)return;const e=[];for(const o of t){const t=Ey(o);t&&e.push({pointId:zy(o),...t})}return e}Qp("orbit",Ny);import{Fragment as By,jsxs as jy}from"react/jsx-runtime";function Yy(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}Qp("sankey",ty),Qp("force",ly),Qp("chord",gy),Qp("tree",Ry),Qp("cluster",Ry),Qp("treemap",Ry),Qp("circlepack",Ry),Qp("partition",Ry),Qp("orbit",Ny);var Xy=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function Gy(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 Vy(t,e){const o=De(t.theme),n=t.chartType||"force",i=t.size||[500,500],r=function(t){return Lf.has(t)?Pf:_f}(n),s=yo({...r,...t.margin},t.title),a=po(t.title),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const i=Wt(t.nodes||[]);if(i.length>0)return Hd(i,e);if(Xy.has(n)&&t.data)return Hd(yr(t.data,t.childrenAccessor||"children"),e);const r=Array.isArray(t.edges)?Wt(t.edges):[];if(0===r.length)return[];const s=Yy(t.sourceAccessor,"source"),a=Yy(t.targetAccessor,"target");return Hd(Array.from(new Set(r.flatMap(t=>[s(t),a(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];xf(s,{props:t,categories:l,theme:o,size:i,hasTitle:a});const c=bf({props:t,categories:l,theme:o,size:i,margin:s,hasTitle:a}),u=i[0]-s.left-s.right,d=i[1]-s.top-s.bottom,h=Sf(t.backgroundGraphics,i,s,null),f=Sf(t.foregroundGraphics,i,s,null),p=()=>{let n;const r=t=>Number(t),a=t.annotations?Yh({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=>Qu({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)),Zp.renderToStaticMarkup(wf(h||f||t.annotations?jy(By,{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:c,idPrefix:t._idPrefix}))},g=function(t){return Kp[t]}(n);if(!g&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const y={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 m,x;if(Xy.has(n)){const e=t.data||t.edges;if(!e||Array.isArray(e))return p();y.__hierarchyRoot=e,m=[],x=[]}else{const e=Wt(t.nodes||[]),o=Array.isArray(t.edges)?Wt(t.edges):[];if(0===e.length&&0===o.length)return p();if(x=function(t,e){const o=Yy(e.sourceAccessor,"source"),n=Yy(e.targetAccessor,"target"),i=Yy(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,y),0===e.length&&x.length>0){const t=new Set;for(const e of x){const o=hf(e.source),n=hf(e.target);o&&t.add(o),n&&t.add(n)}m=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 m=function(t,e){const o=Yy(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,y)}let b=[],v=[],w=[],k=null,A=null;if(y.customNetworkLayout){const t=y.colorScheme,e=cs(t,o.colors.categorical,Gt),n=us(e,t),i={nodes:m,edges:x,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:y.layoutConfig??{}},r=y.customNetworkLayout(i);b=r.sceneNodes??[],v=r.sceneEdges??[],w=r.labels??[],k=r.backgrounds??null,A=r.overlays??null}else if(g){g.computeLayout(m,x,y,[u,d]);const t=g.buildScene(m,x,y,[u,d]);b=t.sceneNodes,v=t.sceneEdges,w=t.labels}const S=Fe(o);for(const t of w)t.fill||(t.fill=S.text);const M=Fd({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return fd(function(t,e){switch(t.type){case"line":return yd("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=G(o.style.fill)?X(o.style.fill,n):void 0;return md(pd.Fragment,{children:[i&&yd("defs",{children:i}),yd("path",{d:o.pathD,fill:i?`url(#${n})`:rd(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=G(o.style.fill)?X(o.style.fill,n):void 0;return md(pd.Fragment,{children:[i&&yd("defs",{children:i}),yd("path",{d:o.pathD,fill:i?`url(#${n})`:rd(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 yd("path",{d:o.pathD,fill:rd(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)}),_=Fd({nodes:b,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return fd(function(t,e){switch(t.type){case"circle":{const o=t,n=G(o.style.fill)?X(o.style.fill,`net-circle-${e}-hatch`):void 0;return md(pd.Fragment,{children:[n&&yd("defs",{children:n}),yd("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:rd(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=G(o.style.fill)?X(o.style.fill,`net-rect-${e}-hatch`):void 0;return md(pd.Fragment,{children:[n&&yd("defs",{children:n}),yd("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:rd(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=gd().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(id)||"",i=G(o.style.fill)?X(o.style.fill,`net-arc-${e}-hatch`):void 0;return md(pd.Fragment,{children:[i&&yd("defs",{children:i}),yd("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:rd(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=O(o.symbolType,o.size,o.path);return yd("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?rd(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 ad(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),P=M.map(t=>t.element),L=_.map(t=>t.element),$=w.map((t,e)=>function(t,e){return yd("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 T;const R=t=>Number(t),C=t.annotations?Yh({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:R,y:R},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:Gy(b),pointNodes:Wy(b),idPrefix:t._idPrefix,onRender:t=>{T=t}}):null;return e&&(e.evidence=Qu({frameType:"network",width:i[0],height:i[1],marks:[..._.map(({node:t})=>({type:"node:"+(t.type??"node")})),...M.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:T,nodeCount:_.length,edgeCount:M.length,margin:s})),Zp.renderToStaticMarkup(wf(jy(By,{children:[h,k,P,L,$,C,f,A]}),{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:c,idPrefix:t._idPrefix}))}import*as Hy from"react-dom/server";import{geoPath as qy}from"d3-geo";import{quadtree as Uy}from"d3-quadtree";import{geoMercator as Zy,geoEqualEarth as Ky,geoAlbersUsa as Qy,geoOrthographic as Jy,geoNaturalEarth1 as tm,geoEquirectangular as em}from"d3-geo";var om={mercator:Zy,equalEarth:Ky,albersUsa:Qy,orthographic:Jy,naturalEarth:tm,equirectangular:em};function nm(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function im(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function rm(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function sm(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 am(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,l=Math.min(.3*r,80),c=(t[0]+e[0])/2+s*l,u=(t[1]+e[1])/2+a*l,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*t[0]+2*r*i*c+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function lm(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 cm(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 l=s/a,c=-r/a,u=i/2+1;return[[t[0]+l*u,t[1]+c*u],[e[0]+l*u,e[1]+c*u]]}import{scaleLinear as um}from"d3-scale";var dm=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],hm=["scene-style","data-paint","accessibility","evidence"],fm=(t,e)=>({retainedData:t,invalidations:e}),pm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],gm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ym=["scene-geometry","data-paint","accessibility","evidence"],mm=["scene-style","data-paint","accessibility","evidence"],xm=["overlay","accessibility","evidence"],bm=[],vm={xAccessor:fm("rebuild",pm),yAccessor:fm("rebuild",pm),lineDataAccessor:fm("rebuild",pm),pointIdAccessor:fm("rebuild",ym),lineIdAccessor:fm("rebuild",ym),windowSize:fm("rebuild",pm),projection:fm("preserve",gm),projectionExtent:fm("preserve",gm),fitPadding:fm("preserve",gm),lineType:fm("preserve",gm),flowStyle:fm("preserve",gm),graticule:fm("preserve",gm),projectionTransform:fm("preserve",gm),customLayout:fm("preserve",gm),layoutConfig:fm("preserve",gm),layoutMargin:fm("preserve",gm),areaStyle:fm("preserve",mm),pointStyle:fm("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:fm("preserve",mm),colorScheme:fm("preserve",mm),themeCategorical:fm("preserve",mm),themeDiverging:fm("preserve",mm),themeSemantic:fm("preserve",mm),themeSequential:fm("preserve",mm),decay:fm("preserve",mm),pulse:fm("preserve",mm),layoutSelection:fm("preserve",mm),annotations:fm("preserve",xm),autoPlaceAnnotations:fm("preserve",xm),clock:fm("preserve",bm),transition:fm("preserve",bm),introAnimation:fm("preserve",bm),onLayoutError:fm("preserve",bm)},wm=fm("preserve",gm),km=class{constructor(){this.tracker=new e}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}},dm)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},hm):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=vm[n]??wm;"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 Am,geoGraticule as Sm,geoInterpolate as Mm}from"d3-geo";function _m(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 Pm=class t{constructor(t){this.updateResults=new km,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:_m(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??zl()}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 W(t),this.timestampBuffer=new W(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:_m(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 W(e),this.timestampBuffer=new W(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();xc(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)xc(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)+"");bc(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],l=this.scene;this.projection=function(t){if(!t)return Ky();if("string"==typeof t){const e=om[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),Ky())}if("object"==typeof t&&"type"in t){const e=om[t.type],o=e?e():Ky();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=qy(this.projection),this.fitProjection(t),this.geoPath=qy(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(t,e)=>c([t,e]),invertedPoint:(t,e)=>c.invert?c.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&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(t){const e=this.projection,o=this.config,n=[...this.areas],i=nm(o.xAccessor,"lon"),r=nm(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=im(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=qy(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 l=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=l,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=qy(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 l=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=l,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=qy(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=Uy().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=cs(e.colorScheme,e.themeCategorical,me),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:us(n,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null},r=Jl({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 Zl({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=nm(t.xAccessor,"lon"),l=nm(t.yAccessor,"lat"),c=[],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=Sm();e.step&&n.step(e.step);const i=o(n())||"";i&&c.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);c.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:rm(t.areaStyle,e,u),datum:e,interactive:!0})}const f=im(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]),l(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=Am(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Mm(n,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const n=e(l(t/a));null!=n&&i.push(n)}}}else for(let t=0;n.length>t;t++){const o=n[t],r=e([a(o),l(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=rm(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?lm(i,u):cm(i[0],i[i.length-1],0,0,u)):i=am(i[0],i[i.length-1]);const h=sm(i,s.width);if(h.length>1)for(const t of h)2>t.length||c.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else c.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,g=e.clipAngle?e.clipAngle()??0:0,y=g>0?g*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=l(o);if(null!=y&&Am([n,i],b)>y)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};c.push(u)}return c}({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 l=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,c="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=i.find(t=>t.datum&&l(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=i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),h=lt(d,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 f="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,l=um().domain([0,n]).range([0,s]);e.x=r,e.y=a;const c=[];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?l(t):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let t=d+1;for(;c.length>t&&3>Math.abs(c[t].x-c[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)c[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,c,h,o):function(t,e,o,n,i,r){const s=e.x,a=e.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=um().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)),g=isFinite(p)&&p>=0?n>0?d(p):0:f,y=l+Math.cos(h)*g,m=c+Math.sin(h)*g;r.x=t+(y-t)*i,r.y=u+(m-u)*i}return e.x=s+(l-s)*i,e.y=a+(c-a)*i,{cx:e.x,cy:e.y,maxCost:n,availableRadius:u,layout:"radial"}}(i,u,c,h,s,o),p=t.filter(t=>"line"===t.type);if(p.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 p){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 l=a[a.length-1];o.path=o.path.map((t,e)=>{const r=l>0?a[e]/l: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 f}(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=El(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 l=Bl(e,n[a],t);s=jl(o[a],l,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Yl(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=Ol(t,this.activeTransition),o=Fl(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=Nl(t.x,t._targetX,o),t.y=Nl(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}};Pm.QUADTREE_THRESHOLD=500;var Lm=Pm;function $m(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=p(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+n.centerDx,y:t.y+n.centerDy,r:n.radius})}return e}Pc(Lm);import{jsx as Tm,jsxs as Rm}from"react/jsx-runtime";function Cm({bottomMargin:t,costLabel:e,layout:{cx:o,cy:n,maxCost:i,availableRadius:r,layout:s},ringStyle:a,ringValues:l,showNorth:c,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 Rm("g",h?{children:[Tm("line",{x1:o,y1:n,x2:o+r,y2:n,stroke:f.stroke,strokeWidth:f.strokeWidth,strokeLinecap:"round",opacity:.85}),Tm("line",{x1:o,y1:n-3.5,x2:o,y2:n+3.5,stroke:f.stroke,strokeWidth:f.strokeWidth,opacity:.9}),d&&l.map(s=>{const a=o+(i>0?s/i*r:0);return Rm("g",{children:[Tm("line",{x1:a,y1:n-2.5,x2:a,y2:n+2.5,stroke:f.stroke,strokeWidth:.9,opacity:.65}),u&&Rm("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:[l.map(t=>{const s=t/i*r;return Rm("g",{children:[Tm("circle",{cx:o,cy:n,r:s,fill:"none",stroke:f.stroke,strokeWidth:f.strokeWidth,strokeDasharray:f.strokeDasharray,opacity:.5}),u&&Rm("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)}),c&&Rm("g",{transform:"translate(24, 24)",children:[Tm("circle",{r:16,fill:"white",fillOpacity:.85,stroke:"#bbb",strokeWidth:.8}),Tm("path",{d:"M0,-11 L3,-3 L1,-4 L1,7 L-1,7 L-1,-4 L-3,-3 Z",fill:"#555",stroke:"none"}),Tm("text",{y:-12,textAnchor:"middle",fontSize:7,fontWeight:700,fill:"#555",fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:"N"}),Tm("line",{x1:11,y1:0,x2:13,y2:0,stroke:"#bbb",strokeWidth:.8}),Tm("line",{x1:-11,y1:0,x2:-13,y2:0,stroke:"#bbb",strokeWidth:.8}),Tm("line",{x1:0,y1:11,x2:0,y2:13,stroke:"#bbb",strokeWidth:.8})]})]})}import{Fragment as Im,jsx as Dm,jsxs as Fm}from"react/jsx-runtime";function Om(t,e){const o=De(t.theme),n=t.size||[t.width||600,t.height||400],i=yo({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=po(t.title),s=Array.isArray(t.areas)?Wt(t.areas):t.areas,a=Wt(t.points),l=Wt(t.lines),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return Hd(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];xf(i,{props:t,categories:c,theme:o,size:n,hasTitle:r});const u=bf({props:t,categories:c,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 Lm(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(l),p.computeScene({width:d,height:h});const g=Sf(t.backgroundGraphics,n,i,p.scales),y=Sf(t.foregroundGraphics,n,i,p.scales),m=Fd({nodes:p.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return fd(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=G(o.style.fill)?X(o.style.fill,`geoarea-${e}-hatch`):void 0;return vd(xd.Fragment,{children:[n&&bd("defs",{children:n}),bd("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:rd(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=G(o.style.fill)?X(o.style.fill,`geopoint-${e}-hatch`):void 0;return vd(xd.Fragment,{children:[n&&bd("defs",{children:n}),bd("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:rd(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 bd("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 ad(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===m.length){let r;const s=t.annotations?Yh({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:$m(p.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Qu({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),Hy.renderToStaticMarkup(wf(g||y||t.annotations||p.customLayoutOverlays?Fm(Im,{children:[g,s,y,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 x=m.map(t=>t.element),b=t.cartogramChrome,v=p.cartogramLayout&&b?Dm(Cm,{layout:{...p.cartogramLayout,layout:p.cartogramLayout.layout??"radial"},ringValues:Nm(p.cartogramLayout.maxCost,b.showRings),showRings:b.showRings??!0,showNorth:b.showNorth??!0,showRingLabels:b.showRingLabels??!0,costLabel:"string"==typeof b.costLabel?b.costLabel:void 0}):null;let w;const k=t.annotations?Yh({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:$m(p.scene),idPrefix:t._idPrefix,onRender:t=>{w=t}}):null;return e&&(e.evidence=Qu({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:w,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),Hy.renderToStaticMarkup(wf(Fm(Im,{children:[g,x,k,v,y,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 Nm(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 zm from"react-dom/server.browser";function Em(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 Wm={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Bm(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 jm(t,e,o){const n="function"==typeof e?e(t,o):e;return{...Wm,...n??{}}}function Ym(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)??Bm(t)},r={style:jm(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 Xm,jsxs as Gm}from"react/jsx-runtime";var Vm={top:0,right:0,bottom:0,left:0};function Hm(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function qm(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:l,className:c,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:f,renderBodySVG:p,renderChrome:g,...y}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=Ym(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 l=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 l&&!l.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:Em(e.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},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,y),x={...Vm,...h},b=[o,n],v=Hm(a,b,x),w=Hm(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",T=_&&null!=v?Xm("g",{transform:_,children:v}):v;return{element:Gm("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":M,style:f,children:[i&&Xm("title",{id:A,children:i}),r&&Xm("desc",{id:S,children:r}),Xm("defs",{children:Xm("clipPath",{id:$,children:Xm("rect",{width:P,height:L})})}),l&&"transparent"!==l?Xm("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:n,fill:l}):null,!a&&s&&"transparent"!==s?Xm("rect",{x:0,y:0,width:o,height:n,fill:s}):null,T,Xm("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?fd(n,t,e):Cd(t,e,k)})}),w,g?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:zm.renderToStaticMarkup(o),scene:n,evidence:i}}function Um(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function Zm(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,Um(t.thickness)??Um(o)??Um(e.thickness)??4)}function Km(t){return t.sensorId??"stream-region-"+t.id}function Qm(t){const e=Km(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 Jm}from"react/jsx-runtime";function tx({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?Jm("foreignObject",{x:0,y:0,width:e,height:o,children:t}):Jm("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 ex}from"d3-scale";function ox(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}import{jsx as nx,jsxs as ix}from"react/jsx-runtime";var rx={top:0,right:0,bottom:0,left:0};function sx(e,o){const n=e.size??[e.width??600,e.height??400],i=De(e.theme),r=void 0===e.theme?{}:St(i),s=e.bodyStyle,a=!1,l=e.legendPosition??"right",c=go({...rx,...e.margin},a,!!e.legend&&"top"===l);if(e.legend){const t={...c};Lo(c,{legend:e.legend,position:l,size:n,hasTitle:a,legendLayout:e.legendLayout}),mo(c,t,n,l)}let u;const d=function({annotations:t,chartId:e,chartType:o,config:n,onRegionObservation:i,regionEffects:r,seed:s,size:a}){const l=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=Zm(i,e),s=i.colliderId??`${o}${i.id}`;let a;if("x"===t){const t=Um(i.x),o=Um(i.y1)??Um(e.plotBounds?.y)??Um(i.y),n=Um(i.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??Um(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=Um(i.y),o=Um(i.x1)??Um(e.plotBounds?.x)??Um(i.x),n=Um(i.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??Um(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:Um(i.restitution)??Um(e.barrierRestitution)},..."barrier"!==i.physics||null==i.friction&&null==e.barrierFriction?{}:{friction:Um(i.friction)??Um(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]}}),c=void 0===s||void 0!==n?.kernel?.seed?n:{...n,kernel:{...n?.kernel,seed:s}},u=r.flatMap(t=>[{id:Km(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...Qm(t)]),d=Object.fromEntries(r.map(t=>[Km(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,f=r.length>0;return f||u.length>0||l.length>0||null!=e||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{f&&i(t),h?.onObservation?.(t)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:[Math.max(1,n[0]-c.left-c.right),Math.max(1,n[1]-c.top-c.bottom)]}),h=new t(d);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&h.enqueue(e.initialSpawns.map(t=>({...t,spawnAt:void 0})));const f=qm(h,{...e,width:n[0],height:n[1],background:e.background??i.colors.background,bodyStyle:(t,e)=>({fill:i.colors.primary,stroke:i.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof s?s(t,e):s}),style:{...r,fontFamily:i.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:c,renderChrome:t=>{const o=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),l=function(t){const{width:e,height:o,pointNodes:n=[],data:i}=t;return{scales:{x:ex().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:ex().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:(c=t.bodies,c.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,ox(t))})))});var c;const u=l.scales?.x,d=l.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const f=Yh({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:i,frameType:"network",xAccessor:l.xAccessor,yAccessor:l.yAccessor,pointNodes:l.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),p=e.legend?mf(e.legend,{theme:i,position:e.legendPosition,size:[o[0],o[1]],margin:n,hasTitle:!!e.title,legendLayout:e.legendLayout})??Gh(e.legend,o,n,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:ix("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:[nx("g",{transform:`translate(${n.left},${n.top})`,children:f}),nx(tx,{title:e.title,totalWidth:o[0],marginTop:Math.max(n.top,28)}),p]})}}(t,e,n,c,i);return u=o.annotationRender,o.node}});return o&&(o.evidence=Qu({frameType:"physics",width:n[0],height:n[1],marks:f.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:u,extraWarnings:[...0===f.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...f.scene.evidence.warnings]})),f.svg}import*as ax from"react-dom/server";import{jsx as lx,jsxs as cx}from"react/jsx-runtime";var ux={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 dx(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var hx={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",n=ux[o],i=dx(t.width,n.width),r=dx(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,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=De(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),l=Math.round(s-24*a);return 0===l?`${e}${a}d`:`${e}${a}d ${l}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 g=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),y="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)}(g?.level??"neutral",g?.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,g?.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),$=c+("start"===l?Math.max(n.valueSize,f.length*n.valueSize*.55):0),T=ax.renderToStaticMarkup(cx("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:[lx("title",{children:m??f}),"string"==typeof t.description&&lx("desc",{children:t.description}),lx("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&&lx("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:m}),n.showHeader&&x&&lx("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:x}),lx("text",{x:c,y:L,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:f}),b&&void 0!==d&&"start"===l&&lx("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&&lx("text",{x:c,y:Math.min(r-s,L+n.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Qu({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:A})),T}};function fx(t,e,o){return hx[t](e,o)}import*as px from"react-dom/server";import{jsx as gx,jsxs as yx}from"react/jsx-runtime";function mx(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 xx,jsx as bx}from"react/jsx-runtime";function vx(t,e){switch(t){case"xy":return Df(e);case"ordinal":return Up(e);case"network":return Vy(e);case"geo":return Om(e);case"physics":return sx(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function wx(t){return Df(t)}function kx(t){return Up(t)}function Ax(t){return Vy(t)}function Sx(t){return Om(t)}var Mx=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"]),_x=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function Px(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 Lx(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)=>!Mx.has(e)||/\b(?:var|calc|url)\(/i.test(n)?t:` ${e}="${function(t,e){const o=RegExp(_x.source,_x.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+=Px(n[0],e),r=n.index+n[0].length,s=!0}return i+t.slice(r)}(n,o)}"`))}var $x=["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"],Tx=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Rx(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function Cx(t,e,o){return Dx(t,e,o).svg}function Ix(t,e,o){const n={},{svg:i,frameType:r}=Dx(t,e,o,n),s=n.evidence??Qu({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,Ot(s,t,e),{svg:i,evidence:s}}function Dx(t,e,o,n){if(Object.prototype.hasOwnProperty.call(hx,t))return{svg:Lx(fx(t,e,n),o?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(ap,t))throw Error(`Unknown chart component: "${t}". Run \`npx semiotic-ai --list\` for supported chart types.`);const i=ap[t];var r;const s=function(t,e,o){const n=Pt[t||"primary"],i=t&&"primary"!==t||!o?.width?n.width:o.width,r=t&&"primary"!==t||!o?.height?n.height:o.height,s={...e,mode:t},a=Z(s,{width:e.width??i,height:e.height??r}).props,l=a.mode||t||"primary",c=Pt[l],u="context"===l||"sparkline"===l,d="primary"===l&&o?.width?o.width:c.width;return{mode:l,width:a.width??d,height:a.height??("primary"===l&&o?.height?o.height:c.height),showAxes:a.showAxes??c.showAxes,showGrid:a.showGrid??c.showGrid,enableHover:a.enableHover??(!!a.linkedHover||c.enableHover),showLegend:a.showLegend??c.showLegend,showLabels:a.showLabels??c.showLabels,title:u?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:u?void 0:a.xLabel,yLabel:u?void 0:a.yLabel,categoryLabel:u?void 0:a.categoryLabel,valueLabel:u?void 0:a.valueLabel,marginDefaults:Lt(c.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:_t(a.mobileInteraction,{mode:l,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(Pt,r)?e.mode:void 0),{...i.layout?.modeDefaults,...Rx(e,Tx)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:g,...y}=e,{width:m,height:x}=s,b=[m,x],v=y.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,A=void 0!==h?h:v.margin,S=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}(A),M="number"==typeof A?{top:A,right:A,bottom:A,left:A}:{...k,...S},_=Rx(y,$x),P=t=>v[t]??s[t],L={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:b,margin:M,__compactMode:s.compactMode,__autoLegendMargin:!0,...void 0!==f&&{colorScheme:f},...void 0!==g&&{legendPosition:g},_idPrefix:y._idPrefix},$=i.buildProps(a,p,f,L,y);let T;if(i.renderStatic)T=i.renderStatic($,n);else switch(i.frameType){case"xy":T=Df($,n);break;case"ordinal":T=Up($,n);break;case"network":T=Vy($,n);break;case"geo":T=Om($,n);break;case"physics":T=sx($,n)}const R=i.renderOverlay?.($,{theme:De(l)});if(null!=R){const t=Nt.renderToStaticMarkup(bx(xx,{children:R})),e=T.lastIndexOf("</svg>");T=0>e?`${T}${t}`:`${T.slice(0,e)}${t}${T.slice(e)}`}return{svg:Lx(T,o?.precision),frameType:i.frameType}}function Fx(t,e={}){return function(t,e,o){const{title:n,subtitle:i,theme:r,width:s=1200,height:a,layout:l={},background:c}=e,u=Fe(De(r)),d=l.columns||2,h=l.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),g=[];let y=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;y+t>d&&(m+=x+h,y=0,x=0);const s=h/2+y*(p+h),a={...e.props,width:n,height:i,theme:r,_idPrefix:"chart-"+g.length},l=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>`,c=mx(l,{width:n,height:i}),u=Math.max(i,c.height);g.push({x:s,y:m,width:n,height:u,svg:l,svgDimensions:c}),x=Math.max(x,u),y+=t}const b=a||m+x+h,v=g.map((t,e)=>{return gx("g",{transform:`translate(${t.x},${t.y})`,children:gx("foreignObject",{width:t.width,height:t.height,children:gx("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 px.renderToStaticMarkup(yx("svg",{xmlns:"http://www.w3.org/2000/svg",width:s,height:b,role:"img","aria-label":n||"Dashboard",style:{fontFamily:u.fontFamily},children:[n&&gx("title",{children:n}),c&&gx("rect",{x:0,y:0,width:s,height:b,fill:c}),n&&gx("text",{x:s/2,y:24,textAnchor:"middle",fontSize:u.titleFontSize+4,fontWeight:u.titleFontWeight,fill:u.text,fontFamily:u.titleFontFamily,children:n}),i&&gx("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:Cx,frame:vx})}import*as Ox from"react-dom/server";import{Fragment as Nx,jsx as zx,jsxs as Ex}from"react/jsx-runtime";function Wx(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=n,f=o.width||600,p=o.height||400,g=De(o.theme),y={...o,...a&&{xExtent:a},...l&&{yExtent:l}};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=yo({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||g.colors.categorical,...h&&{decay:h}},l=new Fp(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&A.push(Vx(l.scene,f,p,g,y))}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:l,colorScheme:o.colorScheme||g.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},b=new Xc(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(Gx(b.scene,f,p,g,y,v)),c>0&&n>0&&b.activeTransition){const t=c*(1e3/u);for(let e=1;c>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/c*t),A.push(Gx(b.scene,f,p,g,y,v))}}return A}function Bx(t,e,o={}){return e.map(e=>{try{return Cx(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 jx(t,e,o){const n=e.size??[e.width??600,e.height??400],i=De(e.theme),r=Fe(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",l=e.title?`${a}-title-${o}`:void 0,c=e.description?`${a}-desc-${o}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=Ym(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=Ex("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&&zx("title",{id:l,children:e.title}),e.description&&zx("desc",{id:c,children:e.description}),s&&"transparent"!==s?zx("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,zx("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>Cd(t,e,`${a}-${o}`))})]});return Ox.renderToStaticMarkup(h)}function Yx(e,o={}){const{fps:n=12,frameCount:i,durationSeconds:r=2,includeInitialFrame:s=!0,stepDt:a,stepsPerFrame:l,background:c}=o,u=Math.max(.001,a??e.config?.fixedDt??1/120),d=l??Math.max(1,Math.round(1/Math.max(1,n)/u)),h=i??Math.max(1,Math.ceil(r*Math.max(1,n))),f=c?{...e,background:c}:e,p=new t(e.config);e.initialSpawns?.length&&p.enqueue(e.initialSpawns,e.initialSpawnPacing);const g=[];for(s&&(p.tick(0),g.push(jx(p,f,0)));h>g.length;){for(let t=0;d>t;t+=1)p.tick(u);g.push(jx(p,f,g.length))}return g}function Xx(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function Gx(t,e,o,n,i,r){const s=Fe(n),a=yo({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=e-a.left-a.right,c=o-a.top-a.bottom,u=Xx(i,n),d=i.renderMode,h=t.map((t,e)=>Dd({node:t,index:e,renderMode:d,fallback:()=>Cd(t,e)}).element).filter(Boolean),f=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=Fe(n),a=[];for(let n=0;t.length>n;n++){const l=t[n];if("y-threshold"===l.type&&null!=l.value){let t=null;if(r)t=r(l.value);else if(i){const[e,n]=i,r=n-e;if(0===r)continue;t=o-(l.value-e)/r*o}if(null==t)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push(Ex("g",{children:[zx("line",{x1:0,y1:t,x2:e,y2:t,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&zx("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:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+n))}}return a.length>0?zx(Nx,{children:a}):null}(i.annotations,l,c,n,i.yExtent,r?.y),p="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,y=p?"semiotic-title":void 0,m=g?"semiotic-desc":void 0,x=[y,m].filter(Boolean).join(" ")||void 0;return Ox.renderToStaticMarkup(Ex("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[p&&zx("title",{id:y,children:p}),g&&zx("desc",{id:m,children:g}),u&&zx("rect",{x:0,y:0,width:e,height:o,fill:u}),Ex("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&zx("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:p})]}))}function Vx(t,e,o,n,i){const r=Fe(n),s=yo({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(e-s.left-s.right)/2:s.left,c=a?s.top+(o-s.top-s.bottom)/2:s.top,u=Xx(i,n),d=jp({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,g=f?"semiotic-desc":void 0,y=[p,g].filter(Boolean).join(" ")||void 0;return Ox.renderToStaticMarkup(Ex("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":y,style:{fontFamily:r.fontFamily},children:[h&&zx("title",{id:p,children:h}),f&&zx("desc",{id:g,children:f}),u&&zx("rect",{x:0,y:0,width:e,height:o,fill:u}),zx("g",{transform:`translate(${l},${c})`,children:d}),h&&zx("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}qu();export{Wx as generateFrameSVGs,Bx as generateFrameSequence,Yx as generatePhysicsFrameSVGs,Cx as renderChart,Ix as renderChartWithEvidence,Fx as renderDashboard,Sx as renderGeoToStaticSVG,Ax as renderNetworkToStaticSVG,kx as renderOrdinalToStaticSVG,vx as renderToStaticSVG,wx as renderXYToStaticSVG,De as resolveTheme,Lx as serializeSvgPrecision,Fe as themeStyles};