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{DEFAULT_GLYPH_ANCHOR as e,DEFAULT_GLYPH_VIEWBOX as t,SYMBOL_SEQUENCE as n,absorbRegion as o,aggregateRegionCounts as r,annotationLayout as i,bodyGroupSpec as a,capacitatedRegion as s,chargeGateRegion as c,collidersFromPlotBounds as l,collidersFromXScaleBins as u,countPairwiseCrossings as d,forceFieldRegion as h,glyphExtent as f,glyphFractionClipRect as m,glyphPlacement as p,groupCompletionRows as y,matchesPhysicsBodyFilter as g,membraneRegion as x,orderByBarycenter as b,orderExactSmall as w,packBandsBySilhouette as M,placeWithMinGap as v,portalRegion as k,pressureFieldRegion as $,processChrome as A,processLaneWalls as S,processStageLayout as I,processStageRegions as C,refineByAdjacentSwaps as N,regionCountsToProjectionRows as F,routeSurfaceRegion as z,sedimentHeightfield as W,symbolExtent as j,symbolPathString as L,symbolRadius as R,useCustomLayoutSelection as O,valueAtPath as E}from"./c-LIXGXMNS.min.js";import{LayoutCache as P,clamp as T,createSafeDatum as D,datumFromFields as q,diagnoseTokenEncoding as B,dimFor as Y,forceLayout as H,generateTokens as G,groupBy as X,layoutTokenGrid as V,makeShade as K,matchesHighlight as _,mean as U,nonNegativeFinite as Q,normalizeTokenEncoding as Z,readField as J,resolveAccessor as ee,shade as te,signatureKey as ne,stableGlyphId as oe,suggestTokenEncoding as re,tokenTaskIntentToCapabilityIntents as ie,unitize as ae,unitizeRange as se,unwrapDatum as ce,withAlpha as le}from"./c-6FEKTA3U.min.js";import{DEFAULT_AREA_PER_ANNOTATION as ue,annotationBudget as de,annotationDensity as he,isNoteAnnotation as fe,mulberry32 as me}from"./c-SUILCHWU.min.js";import"./c-MT3WBK7M.min.js";import"./c-GGISSW5E.min.js";var pe=e=>{const t=e.config,n=t.rows??10,o=t.columns??10,r=t.gutter??2,i=n*o;if(0>=n||0>=o||0>=i)return{nodes:[]};const{plot:a}=e.dimensions;if(0>=a.width||0>=a.height)return{nodes:[]};const s=(a.width-r*(o-1))/o,c=(a.height-r*(n-1))/n;if(0>=s||0>=c)return{nodes:[]};const l=(null==(u=t.categoryAccessor)?null:"function"==typeof u?u:e=>e[u])??(()=>"_default");var u;const d=function(e){return null==e?null:"function"==typeof e?e:t=>Number(t[e])}(t.valueAccessor)??(()=>1),h=new Map,f=[];for(const t of e.data){const e=l(t)+"",n=Number(d(t)),o=Number.isFinite(n)?Math.max(0,n):0;h.has(e)||f.push(e),h.set(e,(h.get(e)??0)+o)}const m=Array.from(h.values()).reduce((e,t)=>e+t,0);if(0>=m)return{nodes:[]};let p;if(t.categoryOrder&&t.categoryOrder.length>0){const e=new Set,n=[];for(const o of t.categoryOrder)h.has(o)&&!e.has(o)&&(e.add(o),n.push(o));p=[...n,...f.filter(t=>!e.has(t))]}else p=f;if(0===p.length)return{nodes:[]};const y=p.map(e=>({cat:e,exact:(h.get(e)??0)/m*i})).map(e=>({...e,count:Math.floor(e.exact)})),g=y.reduce((e,t)=>e+t.count,0),x=y.map((e,t)=>({i:t,rem:e.exact-e.count})).sort((e,t)=>t.rem-e.rem);for(let e=0;i-g>e;e++)y[x[e%x.length].i].count+=1;const b="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",w="string"==typeof t.valueAccessor?t.valueAccessor:"value",M=(e,t,n)=>D(o=>{o("category",e),o("value",h.get(e)??0),o("share",(h.get(e)??0)/m),"category"!==b&&o(b,e),"value"!==w&&o(w,h.get(e)??0),o("cells",n),o("_waffleCategory",e),o("_waffleIndex",t)}),v=[];let k=0;for(const t of y){const i=e.resolveColor(t.cat);for(let e=0;t.count>e;e++)v.push({type:"rect",x:a.x+k%o*(s+r),y:a.y+(n-1-Math.floor(k/o))*(c+r),w:s,h:c,style:{fill:i,stroke:"none"},datum:M(t.cat,k,t.count),group:t.cat,_transitionKey:`waffle-${t.cat}-${e}`}),k++}return{nodes:v}};function ye(e,t,n){const o=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,r=e=>Number.isFinite(e)?Math.max(0,e):0,i=e.reduce((e,t)=>e+(r(t.weight)>0?1:0),0),a=i>0?Math.min(Math.max(0,Math.floor(n?.minPerCategory??0)),Math.floor(o/i)):0,s=e.reduce((e,t)=>e+r(t.weight),0);if(0>=o||0>=s)return e.map(e=>({...e,exact:0,cells:0,remainder:0}));const c=e.map(e=>{const t=r(e.weight),n=t/s*o;return{...e,exact:n,cells:t>0?Math.max(a,Math.floor(n)):0,remainder:n-Math.floor(n)}});let l=c.reduce((e,t)=>e+t.cells,0);for(;l>o;){const e=c.filter(e=>e.cells>a).sort((e,t)=>t.cells-e.cells||e.remainder-t.remainder||e.key.localeCompare(t.key))[0];if(!e)break;e.cells--,l--}const u=c.filter(e=>r(e.weight)>0).sort((e,t)=>t.remainder-e.remainder||r(t.weight)-r(e.weight)||e.key.localeCompare(t.key));for(let e=0;o>l;e++)u[e%u.length].cells++,l++;return c}function ge(e,t,n,o){const r=new Set;return e.map((e,i)=>{const a=t(e,i)+"",s=Number(n(e,i));if(!a)throw Error(`${o} snapshot contains an empty id at index ${i}.`);if(r.has(a))throw Error(`${o} snapshot contains duplicate id "${a}".`);if(!Number.isFinite(s)||0>s)throw Error(`${o} snapshot value for "${a}" must be a finite non-negative number.`);return r.add(a),{id:a,value:s}})}function xe(e,t,n){const o=n.afterId??n.beforeId,r=n.afterValue??n.beforeValue,i=null==n.epsilon||0>n.epsilon?1e-9:n.epsilon,a=ge(e,n.beforeId,n.beforeValue,"Before"),s=ge(t,o,r,"After"),c=new Map(a.map(e=>[e.id,e.value])),l=new Map(s.map(e=>[e.id,e.value])),u=a.reduce((e,t)=>e+t.value,0),d=s.reduce((e,t)=>e+t.value,0),h=i>=Math.abs(u-d);if(!h&&!n.allowImbalance)throw Error(`Snapshot totals must match (before ${u}, after ${d}). Pass allowImbalance to inspect residuals.`);const f=[],m=[...a.map(e=>e.id),...s.map(e=>e.id).filter(e=>!c.has(e))];for(const e of m){const t=Math.min(c.get(e)??0,l.get(e)??0);t>i&&f.push({sourceId:e,targetId:e,value:t,kind:"stay"})}const p=a.map(e=>({id:e.id,value:e.value-(l.get(e.id)??0)})).filter(e=>e.value>i),y=s.map(e=>({id:e.id,value:e.value-(c.get(e.id)??0)})).filter(e=>e.value>i);let g=0,x=0;for(;p.length>g&&y.length>x;){const e=p[g],t=y[x],n=Math.min(e.value,t.value);n>i&&f.push({sourceId:e.id,targetId:t.id,value:n,kind:"move"}),e.value-=n,t.value-=n,e.value>i||(g+=1),t.value>i||(x+=1)}return{flows:f,beforeTotal:u,afterTotal:d,balanced:h,unmatchedBefore:p.slice(g).filter(e=>e.value>i).map(({id:e,value:t})=>({id:e,value:t})),unmatchedAfter:y.slice(x).filter(e=>e.value>i).map(({id:e,value:t})=>({id:e,value:t}))}}var be="#334155",we="#f8fafc",Me="#cbd5e1",ve={viewBox:[40,40],anchor:[.5,1],parts:[{d:"M8 3h24v34H8z",fill:"color"},{d:"M12 9h16v5H12zM12 18h16v5H12zM12 27h16v5H12z",fill:"accent"},{d:"M23.8 11.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 20.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 29.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",fill:"color"}]},ke={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M10 8h20a2 2 0 0 1 2 2v20a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z",fill:"color"},{d:"M15 15h10v10H15z",fill:"accent"},{d:"M7 2v6M14 2v6M21 2v6M28 2v6M7 32v6M14 32v6M21 32v6M28 32v6M2 7h6M2 14h6M2 21h6M2 28h6M32 7h6M32 14h6M32 21h6M32 28h6",fill:"none",stroke:"color",strokeWidth:3}]},$e={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M23 1L7 23h10l-3 16 19-25H22z",fill:"color"}]},Ae={viewBox:[48,40],anchor:[.5,.78],parts:[{d:"M7 12c0-4 3-7 7-7h20c4 0 7 3 7 7v15H7z",fill:"color"},{d:"M11 15h26v8H11z",fill:"accent",opacity:.9},{d:"M12 27h7v4h-7zM29 27h7v4h-7z",fill:"accent",opacity:.95},{d:"M12 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0M28 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0",fill:"color",stroke:"accent",strokeWidth:1.8},{d:"M5 13h4v8H5zM39 13h4v8h-4z",fill:"color"}]},Se="M 9.12,3.34 C 8.28,3.29 7.44,3.40 6.64,3.69 4.17,3.63 1.97,5.37 0.91,7.51 -1.32,11.80 2.55,17.76 8.19,16.55 11.62,16.13 15.55,14.04 16.17,10.33 16.38,6.53 12.77,3.52 9.12,3.34 Z M 9.35,19.86 C 8.89,19.84 8.41,19.92 7.92,20.11 5.12,21.55 3.72,24.68 2.79,27.54 2.32,29.86 0.87,32.04 1.36,34.49 1.63,37.60 8.04,38.95 8.04,38.95 8.04,38.95 14.67,39.65 16.50,36.33 17.16,31.95 16.34,27.23 14.01,23.42 13.07,21.69 11.36,19.92 9.35,19.86 Z",Ie={viewBox:[18,40],anchor:[.5,1],parts:[{d:Se,fill:"color",stroke:"color",strokeWidth:1.4}]},Ce={server:ve,chip:ke,bolt:$e,bus:Ae,person:Ie},Ne="var(--semiotic-primary, #4e79a7)",Fe="var(--semiotic-border, #d1d5db)";function ze(e){return"object"==typeof e&&null!==e&&"tokens"in e&&"encoding"in e}function We(e,t,n){return"function"==typeof e?e(t)??n:e??n}function je(e,t){return"function"==typeof e?e(t):e}function Le(e){return e.sample??e.value??e.index}var Re=new Set(n);function Oe(e,t){return void 0!==t.datum?We(t.datum,e,null):e.datum??null}function Ee(e,t){return{fill:!1!==e.highlighted?"scenario"===e.range?We(t.rangeColor,e,"var(--semiotic-secondary, #9ca3af)"):We(t.color,e,Ne):We(t.inactiveColor,e,Fe),stroke:"none",...je(t.style,e)??{}}}function Pe(e,t){const n=je(t.pointId,e)??(t.idPrefix?`${t.idPrefix}-${"scenario"===e.range?"range-":""}${e.index}`:void 0);return{datum:Oe(e,t),accessibleDatum:je(t.accessibleDatum,e),accessibility:je(t.accessibility,e),pointId:n,_transitionKey:n}}function Te({input:e,encoding:t,options:n={}}){if(!ze(e)&&!t)throw Error("tokenLayer requires an encoding when input is not a TokenSet.");const o=ze(e)?{...e,encoding:Z(e.encoding)}:G(e,t),r=function(e,t){const n=t.includeRange&&e.rangeTokens?[...e.tokens,...e.rangeTokens]:e.tokens;if(t.positionToken)return function(e,t){const n=t.positionToken;return n?e.map((t,o)=>{const r=n(t,o,e);return{...t,x:r.x,y:r.y,row:r.row??o,column:r.column??0}}):[]}(n,t);const o=t.layout??e.encoding.layout??"grid";if("quantile-strip"===o)return function(e,t){if(0===e.length)return[];const n=t.x??0,o=t.y??0,r=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),i=t.gutter??2,a=Math.max(1,Math.floor(t.rows??1)),s=e.map(Le),c=Math.min(...s),l=Math.max(...s)-c||1;return e.map((s,u)=>{const d=Le(s),h=u%a,f=t.valueToX?t.valueToX(d,s):n+(d-c)/l*(t.width??12*Math.max(1,e.length-1)),m=t.valueToY?t.valueToY(d,s):o+h*(r+i);return{...s,x:f,y:m,row:h,column:u}})}(n,t);if("dotplot"===o)return function(e,t){if(0===e.length)return[];const n=t.x??0,o=t.y??0,r="number"==typeof t.tokenSize?t.tokenSize:12,i=t.gutter??2,a=t.cellWidth??r+i,s=t.cellHeight??r+i,c=e.map(Le),l=Math.min(...c),u=Math.max(...c)-l||1,d=new Map;return e.map(r=>{const i=Le(r),c=t.valueToX?t.valueToX(i,r):n+(i-l)/u*(t.width??Math.max(1,e.length-1)*a),h=Math.round((c-n)/Math.max(1,a)),f=d.get(h)??0;d.set(h,f+1);const m=t.valueToY?t.valueToY(i,r):o+f*s;return{...r,x:n+h*a,y:m,row:f,column:h}})}(n,t);if("bar-segment"===o){if(!t.valueToX)throw Error('tokenLayer layout "bar-segment" requires valueToX and optionally valueToY.');return function(e,t){if(!t.valueToX)return[];const n=t.y??0,o=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),r=t.anchor??[.5,.5];return e.map((e,i)=>{const a=Number.isFinite(e.start)?e.start:Le(e),s=(a+(Number.isFinite(e.end)?e.end:a+e.value))/2,c=t.valueToY?t.valueToY(s,e):n+r[1]*o;return{...e,x:t.valueToX(s,e),y:c,row:0,column:i}})}(n,t)}if("beeswarm"===o||"small-multiple"===o)throw Error(`tokenLayer layout "${o}" is not implemented yet; use row, column, stack, grid, waffle, dotplot, quantile-strip, bar-segment with valueToX, or positionToken.`);const r="number"==typeof t.tokenSize?t.tokenSize:void 0,i=t.cellWidth??r??12,a=t.cellHeight??r??i,s="row"===o?Math.max(1,n.length):"column"===o||"stack"===o?1:"waffle"===o&&"fixed-denominator"===e.encoding.countStrategy&&100===e.denominator?10:function(e,t,n){if(t.columns)return t.columns;if(t.width&&n>0){const e=t.gutter??2;return Math.max(1,Math.floor((t.width+e)/(n+e)))}return e.length>0?Math.ceil(Math.sqrt(e.length)):1}(n,t,i);return V(n,{...t,columns:s,cellWidth:i,cellHeight:a})}(o,n).filter(e=>!n.include||n.include(e));return{tokenSet:o,positionedTokens:r,nodes:r.map(e=>function(e,t,n){if("dot"===n.tokenType)return function(e,t){const n=We(t.tokenSize,e,12);return{type:"point",x:e.x,y:e.y,r:We(t.radius,e,n/2),style:Ee(e,t),...Pe(e,t)}}(e,t);const o=je(t.glyph,e)??function(e){if(e)return Ce[e]}(n.icon);if(o)return function(e,t,n){const o=Ee(e,n),r=We(n.tokenSize,e,12);return{type:"glyph",x:e.x,y:e.y,size:r,glyph:t,color:(o.fill??Ne)+"",accent:We(n.accent,e,"var(--semiotic-bg, #ffffff)"),fraction:1>e.fraction?e.fraction:void 0,fractionStart:e.startFraction>0?e.startFraction:void 0,fractionDirection:We(n.fractionDirection,e,"horizontal"),ghostColor:1>e.fraction?je(n.ghostColor,e)??Fe:void 0,rotation:je(n.rotation,e),style:o,...Pe(e,n)}}(e,o,t);const r=(i=n.icon)&&Re.has(i)?i:void 0;var i;return function(e,t){const n=We(t.tokenSize,e,12);return{type:"symbol",x:e.x,y:e.y,size:Math.PI*Math.max(1,n/2)**2,symbolType:We(t.symbolType,e,"circle"),path:je(t.symbolPath,e),rotation:je(t.rotation,e),style:Ee(e,t),...Pe(e,t)}}(e,r&&null==t.symbolType?{...t,symbolType:r}:t)}(e,n,o.encoding))}}import{interpolateRgb as De}from"d3-interpolate";var qe=864e5,Be=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height)return{nodes:[]};const o=e=>{const n="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];return n instanceof Date?n:new Date(n)},r=e=>{const n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return Number(n)},i=new Map;let a=null;for(const t of e.data){const e=o(t);if(!isFinite(e.getTime()))continue;null==a&&(a=e.getUTCFullYear());const n=Ye(e),s=r(t);i.set(n,(i.get(n)??0)+(Number.isFinite(s)?s:0))}const s=t.year??a??(new Date).getUTCFullYear();let c=1/0,l=-1/0;for(const e of i.values())c>e&&(c=e),e>l&&(l=e);c===1/0&&(c=0,l=0);const[u,d]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],h=e=>{if(l===c)return u;const t=(e-c)/(l-c);return De(u,d)(t)},f=t.gutter??2,m=t.labelInset??0,p=Math.min((n.width-m-53*f)/54,(n.height-6*f)/7);if(0>=p)return{nodes:[]};const y=new Date(Date.UTC(s,0,1)),g=y.getUTCDay(),x=new Date(y.getTime()-g*qe),b=[];for(let e=0;54>e;e++)for(let t=0;7>t;t++){const o=new Date(x.getTime()+(7*e+t)*qe);if(o.getUTCFullYear()!==s)continue;const r=Ye(o),a=i.get(r),c=null==a?u:h(a);b.push({type:"rect",x:n.x+m+e*(p+f),y:n.y+t*(p+f),w:p,h:p,style:{fill:c,stroke:"none"},datum:{date:o,value:a??0}})}return{nodes:b}};function Ye(e){return`${e.getUTCFullYear()}-${He(e.getUTCMonth()+1)}-${He(e.getUTCDate())}`}function He(e){return 10>e?"0"+e:e+""}import{jsx as Ge,jsxs as Xe}from"react/jsx-runtime";var Ve={resource:32,city:64},Ke=["#739b58","#83a964","#668d52","#8baa68"],_e={land:"#78985c",ocean:"#4d8192",forest:"#4f7c4b",grassland:"#8eaa68",cropland:"#a6a568",wetland:"#668f79",urban:"#8d8a72",scrub:"#9b9665",bare:"#aa906a",snow:"#d8ddcf"},Ue={land:"Open land",ocean:"Open ocean",forest:"Forest",grassland:"Grassland",cropland:"Cropland",wetland:"Wetland",urban:"Urban district",scrub:"Scrubland",bare:"Bare ground",snow:"Snow cover"},Qe=new Set(["city","culture","monument","faith","nature","knowledge","defense","arena","transport"]),Ze=new Set(["land","ocean","forest","grassland","cropland","wetland","urban","scrub","bare","snow"]);function Je(e,t){if(null!=e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function et(e,t){const n=Je(e,t);return"string"==typeof n&&n.length>0?n:void 0}function tt(e,t){if(Qe.has(t))return et(e,t)}function nt(e,t){if("function"==typeof e)return e;const n=e??t;return e=>e[n]}function ot(e,t,n){return[111.32*(e-n.lon)*Math.cos((t+n.lat)/2*(Math.PI/180)),110.574*(t-n.lat)]}function rt(e){const t=Math.max(3,Math.round(e??5));return t%2==0?t+1:t}function it(e){return Qe.has(e)?e:"monument"}function at(e,t){const n=rt(t.gridSize),o=Math.max(1,t.gridRadiusKm??75),r=2*o/n,i=Math.floor(n/2),a=nt(t.idAccessor,"id"),s=nt(t.nameAccessor,"name"),c=nt(t.longitudeAccessor,"lon"),l=nt(t.latitudeAccessor,"lat"),u=nt(t.kindAccessor,"kind"),d=t.candidatePriorityAccessor?nt(t.candidatePriorityAccessor,"priority"):()=>0,h=new Map;let f=null;for(const m of e){const e=Number(c(m)),p=Number(l(m));if(!Number.isFinite(e)||!Number.isFinite(p))continue;const y=(a(m)??`${e},${p}`)+"",g=(s(m)??y)+"",x=it(u(m)),[b,w]=ot(e,p,t.center);if(Math.abs(b)>o||Math.abs(w)>o)continue;const M=Math.min(n-1,Math.max(0,Math.floor((b+o)/r))),v=Math.min(n-1,Math.max(0,Math.floor((o-w)/r))),k=(M+.5)*r-o,$=o-(v+.5)*r,A={...m,id:y,name:g,kind:x,lon:e,lat:p,distanceKm:Math.sqrt(b*b+w*w),row:v,column:M,cellDistanceSq:(b-k)**2+(w-$)**2,candidatePriority:Number(d(m))||0};(null!=t.centerId&&y===t.centerId||!f&&"city"===x||!f&&v===i&&M===i)&&(f=A);const S=`${v}:${M}`,I=h.get(S)??[];I.push(A),h.set(S,I)}const m=new Map;f&&m.set("city",1);const p=[];for(let e=0;n>e;e++)for(let t=0;n>t;t++){const n=`tile-${e}-${t}`,a=(t+.5)*r-o,s=o-(e+.5)*r;let c,l;if(e===i&&t===i&&f){c=f;const n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id).sort((e,t)=>e.candidatePriority-t.candidatePriority||e.cellDistanceSq-t.cellDistanceSq||e.name.localeCompare(t.name));l=[f,...n]}else{const n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id);n.sort((e,t)=>{const n=e.candidatePriority-t.candidatePriority;if(0!==n)return n;const o=m.get(e.kind)??0,i=m.get(t.kind)??0,a=r*r*.35;return e.cellDistanceSq+o*a-(t.cellDistanceSq+i*a)||e.name.localeCompare(t.name)}),c=n[0]??null,l=n}c&&m.set(c.kind,(m.get(c.kind)??0)+1),p.push({id:n,row:e,column:t,centerXKm:a,centerYKm:s,terrainIndex:Math.abs((17*e+31*t)%Ke.length),landmark:c,landmarks:l})}return p}var st=e=>{const t=rt(e.config.gridSize),n=Math.max(20,e.config.tileWidth??80),o=Math.max(10,e.config.tileHeight??40),r=e.config.terrainColors?.length?e.config.terrainColors:Ke,i=e.dimensions.width/2,a=(e.dimensions.height-t*o)/2+o/2,s=at(e.points,e.config).map(e=>({...e,x:i+n/2*(e.column-e.row),y:a+(e.column+e.row)*(o/2)}));return{nodes:s.map(t=>{const i=function(e,t){const n=Je(e,t),o=function(e){return Ze.has(e)?e:void 0}("string"==typeof n?n:Je(n,"kind"));if(!o)return;if("string"==typeof n)return{kind:o};const r=Je(n,"coverage"),i="number"==typeof r&&Number.isFinite(r)?Math.max(0,Math.min(1,r)):void 0,a=et(n,"fill");return{kind:o,...null==i?{}:{coverage:i},...a?{fill:a}:{}}}(e.config.terrainByCell,t.id),a="city"===t.landmark?.kind?"urban":i?.kind??"land",s=i?.fill??et(e.config.terrainPalette,a)??et(_e,a)??_e.land,c=t.landmark?{...t.landmark,gridRow:t.row,gridColumn:t.column,cellId:t.id,terrainKind:a,terrainCoverage:i?.coverage,features:t.landmarks,featureCount:t.landmarks.length}:{id:t.id,name:(l=a,et(Ue,l)??Ue.land),kind:"terrain",terrainKind:a,terrainCoverage:i?.coverage,gridRow:t.row,gridColumn:t.column,cellId:t.id,features:[],featureCount:0};var l,u,d,h,f;return{type:"geoarea",pathData:(u=t.x,d=t.y,h=n,f=o,`M${u},${d-f/2}L${u+h/2},${d}L${u},${d+f/2}L${u-h/2},${d}Z`),centroid:[t.x,t.y],bounds:[[t.x-n/2,t.y-o/2],[t.x+n/2,t.y+o/2]],screenArea:n*o/2,style:{fill:i||"urban"===a?s:r[t.terrainIndex%r.length],stroke:"ocean"===a?"#315d6c":e.config.tileStroke??"#314934",strokeWidth:1},datum:c,group:t.landmark?.kind??a,interactive:!0}}),overlays:Ge(ct,{tiles:s,tileWidth:n,tileHeight:o,sprites:e.config.sprites,resourceSize:e.config.resourceSpriteSize??32,citySize:e.config.citySpriteSize??64,showCityLabel:!1!==e.config.showCityLabel}),restyle:(e,t)=>t?.isActive&&e.datum&&"terrain"!==e.datum.kind?{fillOpacity:t.predicate(e.datum)?1:.28}:{fillOpacity:1}}};function ct({tiles:e,tileWidth:t,tileHeight:n,sprites:o,resourceSize:r,citySize:i,showCityLabel:a}){const s=O(),c=e.filter(e=>e.landmark).sort((e,t)=>e.y-t.y||e.x-t.x);return Xe("g",{"aria-hidden":"true",pointerEvents:"none",children:[c.map(e=>{const a=e.landmark,c="city"===a.kind?i:r,l=e.y+n/2,u=s.isActive&&!s.predicate(a)?.28:1;return Xe("g",{opacity:u,children:[Ge("ellipse",{cx:e.x,cy:e.y+.15*n,rx:.28*c,ry:.1*c,fill:"#17251d",opacity:.32}),Ge(ht,{kind:a.kind,href:tt(o,a.kind),x:e.x-c/2,y:l-c,size:c}),e.landmarks.length>1&&Ge(lt,{x:e.x+.3*t,y:e.y-.19*n,count:e.landmarks.length-1,tileHeight:n})]},a.id)}),a&&c.filter(e=>"city"===e.landmark?.kind).map(e=>{const t=e.landmark.name.toUpperCase(),o=Math.max(56,6.4*t.length+14);return Xe("g",{transform:`translate(${e.x},${e.y+.72*n})`,children:[Ge("rect",{x:-o/2,y:-7,width:o,height:14,rx:1,fill:"#17251d",opacity:.92}),Ge("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:9,fontWeight:700,letterSpacing:.8,children:t})]},e.landmark.id+"-label")})]})}function lt({x:e,y:t,count:n,tileHeight:o}){const r=Math.max(10,Math.min(15,.34*o)),i="+"+n,a=Math.max(r,i.length*r*.58);return Xe("g",{transform:`translate(${e},${t})`,children:[Ge("rect",{x:-a/2,y:-r/2,width:a,height:r,rx:1,fill:"#17251d",stroke:"#f0d36d",strokeWidth:1}),Ge("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:Math.max(7,.62*r),fontWeight:700,children:i})]})}var ut={city:["..1111..","..1221..",".111111.",".133331.","11111111","13311331","14411441","11111111"],culture:["..1111..",".122221.","11111111",".133331.",".133331.",".133331.","11111111",".444444."],monument:["...11...","..1221..","..1221..","..1331..",".113311.",".133331.","11111111",".444444."],faith:["...11...","...11...","..1111..","...11...","..1221..",".133331.","11111111",".444444."],nature:["...11...","..1221..",".122221.","12222221",".133331.","...11...","..1441..",".144441."],knowledge:[".111111.","12211221","12211221","13311331","13311331","13311331","11111111",".444444."],defense:["11.11.11","11111111","12222221","12211221","13311331","13333331","11111111",".444444."],arena:["..1111..",".122221.","12333321","12344321","12344321","12333321",".122221.","..1111.."],transport:["...11...","..1221..",".122221.","11111111","..1331..","..1331..",".114411.","11444411"]},dt={city:{1:"#29364a",2:"#d8b45b",3:"#b7693c",4:"#6d9fc5"},culture:{1:"#29364a",2:"#d5c9a3",3:"#9c6fb2",4:"#ece3c4"},monument:{1:"#29364a",2:"#d8cba8",3:"#9c8f79",4:"#ece3c4"},faith:{1:"#29364a",2:"#d9c36d",3:"#a877a5",4:"#ece3c4"},nature:{1:"#29364a",2:"#4f8a4e",3:"#79aa56",4:"#79583a"},knowledge:{1:"#29364a",2:"#d5c9a3",3:"#4f7da0",4:"#ece3c4"},defense:{1:"#29364a",2:"#a6a298",3:"#777b7f",4:"#d5c9a3"},arena:{1:"#29364a",2:"#cb8056",3:"#d8cba8",4:"#6d9fc5"},transport:{1:"#29364a",2:"#d8b45b",3:"#6d9fc5",4:"#ece3c4"}};function ht({kind:e,href:t,x:n,y:o,size:r}){if(t)return Ge("image",{href:t,x:n,y:o,width:r,height:r,preserveAspectRatio:"xMidYMax meet",style:{imageRendering:"pixelated"}});const i=dt[e];return Ge("svg",{x:n,y:o,width:r,height:r,viewBox:"0 0 8 8",shapeRendering:"crispEdges",children:ut[e].flatMap((e,t)=>[...e].map((e,n)=>"."===e?null:Ge("rect",{x:n,y:t,width:1,height:1,fill:i[e]},`${t}-${n}`)))})}import{jsx as ft}from"react/jsx-runtime";function mt(e){if(Number.isFinite(e))return Math.max(1,Math.round(e))}function pt(e,t,n){return Math.max(t,Math.min(n,e))}function yt(e){let t=1/0,n=-1/0;for(const o of e)Number.isFinite(o)&&(t>o&&(t=o),o>n&&(n=o));return t===1/0?[0,0]:[t,n]}function gt(e,t){const n=t[1]-t[0];return 0===n?.5:(e-t[0])/n}function xt(e,t={}){const n=e.map((e,t)=>({...e,index:t})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));if(0===n.length)return[];const o=pt(Number.isFinite(t.occupancy)?Number(t.occupancy):.72,.2,1),r=Number.isFinite(t.aspectRatio)&&Number(t.aspectRatio)>0?Number(t.aspectRatio):1.8;let i=mt(t.columns)??Math.max(1,Math.ceil(Math.sqrt(n.length*r/o))),a=mt(t.rows)??Math.max(1,Math.ceil(n.length/(i*o)));n.length>i*a&&(null!=t.columns&&null==t.rows?a=Math.ceil(n.length/i):null!=t.rows&&null==t.columns?i=Math.ceil(n.length/a):a=Math.ceil(n.length/i));const s=yt(n.map(e=>e.x)),c=yt(n.map(e=>e.y)),l=n.map(e=>({...e,desiredColumn:gt(e.x,s)*Math.max(0,i-1),desiredRow:gt(e.y,c)*Math.max(0,a-1)})),u=(i-1)/2,d=(a-1)/2;l.sort((e,t)=>(t.desiredColumn-u)**2+(t.desiredRow-d)**2-((e.desiredColumn-u)**2+(e.desiredRow-d)**2)||e.desiredRow-t.desiredRow||e.desiredColumn-t.desiredColumn||e.index-t.index);const h=new Set;for(let e=0;a>e;e+=1)for(let t=0;i>t;t+=1)h.add(e*i+t);const f=[];for(const e of l){let t=-1,n=1/0;for(const o of h){const r=(o%i-e.desiredColumn)**2+(Math.floor(o/i)-e.desiredRow)**2;(n>r||r===n&&t>o)&&(t=o,n=r)}0>t||(h.delete(t),f.push({datum:e.datum,x:e.x,y:e.y,row:Math.floor(t/i),column:t%i,index:e.index}))}return f.sort((e,t)=>e.index-t.index),f.map(({index:e,...t})=>t)}function bt(e,t,n=[]){if("function"==typeof t)return t(e);if("string"==typeof t)return e[t];for(const t of n)if(null!=e[t])return e[t]}function wt(e){return e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")+"Z"}var Mt=e=>{const t=e.config,n=t.source??"auto",o="areas"===n||"auto"===n&&e.areas.length>0,r=o?function(e){return e.areas.map((t,n)=>{const o=function(e,t){const n=e.properties&&"object"==typeof e.properties?e.properties:{},o=e.id??n.id??n.name??"area-"+t;return{...n,id:o+""}}(t,n),r=e.scales.geoPath.centroid(t),i=Number.isFinite(r[0])&&Number.isFinite(r[1])?e.scales.invertedPoint(r[0],r[1]):null;return{datum:{...o,gridLongitude:i?.[0],gridLatitude:i?.[1]},x:r[0],y:r[1]}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}(e):e.points.map((e,t)=>({datum:e,x:t,y:t})),i=r.filter((e,n)=>!t.filter||t.filter(e.datum,n)),a=function(e,t){if(!t.rowAccessor||!t.columnAccessor)return null;const n=e.map(e=>({datum:e,x:Number(bt(e,t.columnAccessor)),y:Number(bt(e,t.rowAccessor))})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));return n.length!==e.length?null:n.map(e=>({...e,row:e.y,column:e.x}))}(i.map(e=>e.datum),t),s=o?i:function(e){return e.points.map(t=>{const n=Number(bt(t,e.config.longitudeAccessor,["lon","longitude"])),o=Number(bt(t,e.config.latitudeAccessor,["lat","latitude"])),r=Number.isFinite(n)&&Number.isFinite(o)?e.scales.projectedPoint(n,o):null;return{datum:t,x:r?.[0]??NaN,y:r?.[1]??NaN}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}({...e,points:i.map(e=>e.datum)}),c=a??xt(s,{columns:t.columns,rows:t.rows,occupancy:t.occupancy,aspectRatio:e.dimensions.width/Math.max(1,e.dimensions.height)});if(0===c.length)return{nodes:[]};const l=yt(c.map(e=>e.row)),u=yt(c.map(e=>e.column)),d=Math.max(1,Math.round(l[1]-l[0])+1),h=Math.max(1,Math.round(u[1]-u[0])+1),f=Math.max(0,t.layoutPadding??8),m=Math.max(1,e.dimensions.width-2*f)/h,p=Math.max(1,e.dimensions.height-2*f)/d,y=(e.dimensions.width-m*h)/2,g=(e.dimensions.height-p*d)/2,x=pt(t.cellPadding??.12,0,.8),b=Math.max(1,.5*Math.min(m,p)*(1-x)),w=t.sizeAccessor?c.map(e=>Number(bt(e.datum,t.sizeAccessor))):[],M=t.sizeDomain??yt(w),v=t.sizeRange??[.36,1],k=pt(Math.min(v[0],v[1]),.05,1),$=pt(Math.max(v[0],v[1]),k,1),A=c.map((n,o)=>{const r={...n.datum,gridRow:n.row,gridColumn:n.column},i=(bt(r,t.idAccessor,["id","key","name"])??"grid-"+o)+"",a=(bt(r,t.labelAccessor,["abbr","code","label","name","id"])??i)+"",s=Math.max(1,t.maxLabelLength??4),c=a.length>s?a.slice(0,s):a,d=bt(r,t.categoryAccessor),h=null==d?void 0:d+"",f=bt(r,t.fillAccessor),x=null!=f?f+"":h?e.resolveColor(h):e.theme.categorical[0]??"#4f86c6",w=t.sizeAccessor?Number(bt(r,t.sizeAccessor)):NaN,v=t.sizeAccessor&&Number.isFinite(w)?Math.sqrt(pt(gt(w,M),0,1)):1,A=b*(k+v*($-k)),S="function"==typeof t.markStyle?t.markStyle(r,o):t.markStyle;return{datum:r,id:i,label:c,category:h,row:n.row,column:n.column,x:y+(n.column-u[0]+.5)*m,y:g+(n.row-l[0]+.5)*p,radius:A,style:{fill:x,fillOpacity:.94,stroke:"rgba(255,255,255,0.9)",strokeWidth:1,...S}}}),S=t.shape??"circle";return{nodes:A.map(e=>{return"circle"===S?{type:"point",x:e.x,y:e.y,r:e.radius,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},pointId:e.id,_transitionKey:e.id}:{type:"geoarea",pathData:"hexagon"===S?function(e,t,n){const o=[];for(let r=0;6>r;r+=1){const i=-Math.PI/2+r*(Math.PI/3);o.push([e+Math.cos(i)*n,t+Math.sin(i)*n])}return wt(o)}(e.x,e.y,e.radius):wt([[(t=e.x)-(o=e.radius),(n=e.y)-o],[t+o,n-o],[t+o,n+o],[t-o,n+o]]),centroid:[e.x,e.y],bounds:[[e.x-e.radius,e.y-e.radius],[e.x+e.radius,e.y+e.radius]],screenArea:"hexagon"===S?3*Math.sqrt(3)*e.radius*e.radius/2:(2*e.radius)**2,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},group:e.category,interactive:!0};var t,n,o}),overlays:!1===t.showLabels?null:ft(vt,{marks:A,color:t.labelColor??"#ffffff",fontSize:t.labelFontSize??pt(.23*Math.min(m,p),7,14),fontFamily:t.labelFontFamily,fontWeight:t.labelFontWeight??700}),restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.18}:{opacity:1}}};function vt({marks:e,color:t,fontSize:n,fontFamily:o,fontWeight:r}){const i=O();return ft("g",{"aria-hidden":"true",pointerEvents:"none",children:e.map(e=>{const a=!i.isActive||i.predicate(e.datum);return ft("text",{x:e.x,y:e.y,fill:t,fontFamily:o,fontSize:n,fontWeight:r,opacity:a?1:.18,textAnchor:"middle",dominantBaseline:"central",children:e.label},e.id)})})}import{geoBounds as kt,geoContains as $t}from"d3-geo";import{jsx as At}from"react/jsx-runtime";var St=new WeakMap,It=new WeakMap,Ct=new WeakMap,Nt=1;function Ft(e,t,n){return Math.max(t,Math.min(n,e))}function zt(e){if(Number.isFinite(e)&&Number(e)>0)return Number(e)}function Wt(e,t){return"function"==typeof t?t(e,e.dotIndex):"string"==typeof t?e[t]:void 0}function jt(e){return e.properties&&"object"==typeof e.properties?{...e.properties}:{}}function Lt(e,t){const n=jt(e);return(e.id??n.id??n.name??"feature-"+t)+""}function Rt(e,t,n,o){return[Math.ceil((e-n)/o-.5),Math.floor((t-n)/o-.5)]}function Ot(e){if(!e)return 0;const t=Ct.get(e);if(t)return t;const n=Nt;return Nt+=1,Ct.set(e,n),n}function Et(e,t){return!t||!(t[0][1]>e[1]||e[1]>t[1][1]||(n=e[0],o=t[0][0],r=t[1][0],o>r?o>n&&n>r:o>n||n>r));var n,o,r}function Pt(e,t){for(const n of e){const{feature:e,index:o}=n;if(e.geometry&&Et(t,n.bounds))try{if($t(e,t))return{feature:e,index:o}}catch{}}return null}function Tt(e,t,n,o={}){const r=e.filter((e,t)=>e.geometry&&(!o.featureFilter||o.featureFilter(e,t))),i=function(e,t){if(0===e.length)return null;const n=t.bounds({type:"FeatureCollection",features:e});return Number.isFinite(n[0][0])&&Number.isFinite(n[0][1])&&Number.isFinite(n[1][0])&&Number.isFinite(n[1][1])?n:null}(r,t.geoPath);if(!i)return{dots:[],cellSize:10,features:r};const a=Math.max(0,o.layoutPadding??0),s=[[Ft(i[0][0],a,Math.max(a,n.width-a)),Ft(i[0][1],a,Math.max(a,n.height-a))],[Ft(i[1][0],a,Math.max(a,n.width-a)),Ft(i[1][1],a,Math.max(a,n.height-a))]],c=Math.max(0,s[1][0]-s[0][0]),l=Math.max(0,s[1][1]-s[0][1]);if(0===c||0===l)return{dots:[],cellSize:10,features:r};const u=zt(o.columns);let d=Math.max(2,u?c/u:zt(o.cellSize)??10);const h=Math.max(100,Math.round(zt(o.maxSamples)??25e3)),f=Math.ceil(c/d)*Math.ceil(l/d);f>h&&(d*=Math.sqrt(f/h));const m=o.gridOrigin?.[0]??0,p=o.gridOrigin?.[1]??0,[y,g]=Rt(s[0][0],s[1][0],m,d),[x,b]=Rt(s[0][1],s[1][1],p,d),w=[],M=function(e){return e.map((e,t)=>{if(It.has(e))return{feature:e,index:t,bounds:It.get(e)??null};try{const n=kt(e);return It.set(e,n),{feature:e,index:t,bounds:n}}catch{return It.set(e,null),{feature:e,index:t,bounds:null}}})}(r);for(let e=x;b>=e;e+=1){const n=p+(e+.5)*d;for(let r=y;g>=r;r+=1){const i=t.invertedPoint(m+(r+.5)*d,n);if(!i||!Number.isFinite(i[0])||!Number.isFinite(i[1]))continue;const a=Pt(M,i);if(!a)continue;const s={...jt(a.feature),featureId:Lt(a.feature,a.index),featureIndex:a.index,gridRow:e,gridColumn:r,longitude:i[0],latitude:i[1],dotIndex:w.length};o.dotFilter&&!o.dotFilter(s,w.length)||w.push(s)}}return{dots:w,cellSize:d,features:r}}function Dt(e){return Math.round(1e4*e)/1e4}function qt(e){return Array.isArray(e)&&e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?`${Dt(Number(e[0]))},${Dt(Number(e[1]))}`:"null"}function Bt(e,t){const n=e[t];return"function"==typeof n?n.call(e):void 0}function Yt(e){return"number"==typeof e&&Number.isFinite(e)?Dt(e)+"":null===e?"null":"unavailable"}function Ht(e){const t=e.scales.projection;return[Yt(Bt(t,"scale")),qt(Bt(t,"translate")),qt(Bt(t,"center")),(n=Bt(t,"rotate"),Array.isArray(n)&&n.every(Number.isFinite)?n.map(e=>Dt(Number(e))).join(","):"unavailable"),Yt(Bt(t,"clipAngle")),Yt(Bt(t,"precision")),...[[0,0],[-120,35],[45,45],[120,-30]].map(([t,n])=>qt(e.scales.projectedPoint(t,n)))].join("|");var n}function Gt(e){return e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")+"Z"}var Xt=e=>{const t=function(e){let t=St.get(e.areas);t||(t=new Map,St.set(e.areas,t));const n=function(e){const t=e.config;return[e.areas.length,e.dimensions.width,e.dimensions.height,t.cellSize??"",t.columns??"",t.layoutPadding??"",t.gridOrigin?.join(",")??"",t.maxSamples??"",Ot(t.featureFilter),Ot(t.dotFilter),Ht(e)].join("::")}(e),o=t.get(n);if(o)return o;const r=Tt(e.areas,e.scales,e.dimensions,e.config);if(t.size>=12){const e=t.keys().next().value;void 0!==e&&t.delete(e)}return t.set(n,r),r}(e),n=e.config,o=n.shape??"circle",r=Math.max(.5,zt(n.dotRadius)??t.cellSize*Ft(n.radiusRatio??.24,.05,.5)),i=n.gridOrigin?.[0]??0,a=n.gridOrigin?.[1]??0;return{nodes:t.dots.map((s,c)=>{const l=i+(s.gridColumn+.5)*t.cellSize,u=a+(s.gridRow+.5)*t.cellSize,d=Wt(s,n.categoryAccessor),h=Wt(s,n.fillAccessor),f={fill:null!=h?h+"":null!=d?e.resolveColor(d+""):e.theme.categorical[0]??"#4f86c6",fillOpacity:.92,strokeWidth:0,..."function"==typeof n.markStyle?n.markStyle(s,c):n.markStyle},m=`dot-${s.gridRow}-${s.gridColumn}`;if("circle"===o)return{type:"point",x:l,y:u,r:r,style:f,datum:s,interactive:!1,pointId:m,_transitionKey:m};const p="hexagon"===o?function(e,t,n){return Gt(Array.from({length:6},(o,r)=>{const i=-Math.PI/2+r*(Math.PI/3);return[e+Math.cos(i)*n,t+Math.sin(i)*n]}))}(l,u,r):function(e,t,n){return Gt([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]])}(l,u,r);return{type:"geoarea",pathData:p,centroid:[l,u],bounds:[[l-r,u-r],[l+r,u+r]],screenArea:"hexagon"===o?3*Math.sqrt(3)*r*r/2:(2*r)**2,style:f,datum:s,group:s.featureId,interactive:!1}}),overlays:n.showOutline?At("g",{"aria-hidden":"true",pointerEvents:"none",children:t.features.map((t,o)=>{const r=e.scales.geoPath(t);return r?At("path",{d:r,fill:"none",stroke:n.outlineStyle?.stroke??"currentColor",strokeOpacity:n.outlineStyle?.opacity??n.outlineStyle?.fillOpacity??.22,strokeWidth:n.outlineStyle?.strokeWidth??.7,strokeDasharray:n.outlineStyle?.strokeDasharray,strokeLinecap:n.outlineStyle?.strokeLinecap,vectorEffect:"non-scaling-stroke"},Lt(t,o)):null})}):null,restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.14}:{opacity:1}}},Vt=e=>{const t=e.config,n=t.nodeWidth??80,o=t.nodeHeight??30,r=t.orientation??"vertical",i=t.edgeCurve??"curved",a=!1!==t.showLabels,s=t.labelAccessor??"id",c="function"==typeof s?s:e=>J(e,s,e.id??"")+"",l=new Map,u=[],d=[],h=e=>{const t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??n,h:("number"==typeof t.height?t.height:e.height)??o}};for(const n of e.nodes){const{x:o,y:r,w:i,h:s}=h(n);null!=o&&null!=r&&(l.set(n.id,{x:o,y:r,w:i,h:s}),u.push({type:"rect",x:o-i/2,y:r-s/2,w:i,h:s,style:{fill:t.nodeFill??e.resolveColor(n.id),stroke:`var(--semiotic-surface, ${e.theme.semantic.surface??"#fff"})`,strokeWidth:1.5},datum:n,id:n.id,label:c(n)+""}),a&&d.push({x:o,y:r,text:c(n)+"",anchor:"middle",baseline:"middle",fontSize:11}))}const f=[];for(const t of e.edges){const n="string"==typeof t.target?t.target:t.target.id,o=l.get("string"==typeof t.source?t.source:t.source.id),a=l.get(n);if(!o||!a)continue;const s="vertical"===r?{x:o.x,y:o.y+o.h/2}:{x:o.x+o.w/2,y:o.y},c="vertical"===r?{x:a.x,y:a.y-a.h/2}:{x:a.x-a.w/2,y:a.y};if("line"===i)f.push({type:"line",x1:s.x,y1:s.y,x2:c.x,y2:c.y,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1},datum:t});else{const n=(s.y+c.y)/2,o=(s.x+c.x)/2;f.push({type:"curved",pathD:"vertical"===r?`M${s.x},${s.y} C${s.x},${n} ${c.x},${n} ${c.x},${c.y}`:`M${s.x},${s.y} C${o},${s.y} ${o},${c.y} ${c.x},${c.y}`,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1,fill:"none"},datum:t})}}return{sceneNodes:u,sceneEdges:f,labels:d}},Kt=e=>{const t=e.config,n=t.nodeWidth??100,o=t.nodeHeight??36,r=t.edgeStyle??"polyline",i=!1!==t.showLabels,a=t.labelAccessor??"label",s="function"==typeof a?a:e=>J(e,a,e.id??"")+"",c=new Map,l=[],u=[],d=e=>{const t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??n,h:("number"==typeof t.height?t.height:e.height)??o}};for(const n of e.nodes){const{x:o,y:r,w:a,h:h}=d(n);null!=o&&null!=r&&(c.set(n.id,{x:o,y:r,w:a,h:h}),l.push({type:"rect",x:o-a/2,y:r-h/2,w:a,h:h,style:{fill:t.nodeFill??e.resolveColor(n.id),stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#888"})`,strokeWidth:1.5},datum:n,id:n.id,label:s(n)+""}),i&&u.push({x:o,y:r,text:s(n)+"",anchor:"middle",baseline:"middle",fontSize:11}))}const h=t.edgeStroke??`var(--semiotic-border, ${e.theme.semantic.border??"#666"})`,f=[];for(const t of e.edges){const e="string"==typeof t.target?t.target:t.target.id,n=c.get("string"==typeof t.source?t.source:t.source.id),o=c.get(e);if(!n||!o)continue;const i=t.data??{},a=Array.isArray(i.points)?i.points:t.points;if(a&&a.length>=2)if("smooth"!==r||3>a.length){const e="M"+a.map(e=>`${e.x},${e.y}`).join(" L ");f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else{let e=`M${a[0].x},${a[0].y}`;for(let t=1;a.length-1>t;t++)e+=` Q${a[t].x},${a[t].y} ${(a[t].x+a[t+1].x)/2},${(a[t].y+a[t+1].y)/2}`;const n=a[a.length-1];e+=` T${n.x},${n.y}`,f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else f.push({type:"line",x1:n.x,y1:n.y,x2:o.x,y2:o.y,style:{stroke:h,strokeWidth:1},datum:t})}return{sceneNodes:l,sceneEdges:f,labels:u}};import{jsx as _t,jsxs as Ut}from"react/jsx-runtime";var Qt={"topic-source":"#1f7a8c","topic-sink":"#b4451f","topic-bridge":"#4b5a82",processor:"#34344a",unknown:"#5a5a6a"},Zt={internal:"var(--semiotic-border, #6b6b7d)","cross-subtopology":"var(--semiotic-info, #6a8caf)","topic-bridge":"var(--semiotic-secondary, #8b78c4)",back:"var(--semiotic-danger, #e0556b)"};function Jt(e){return Array.isArray(e)?e.map((e,t)=>"string"==typeof e?{storeName:e,slotIndex:t}:{storeName:(e.storeName??"")+"",slotIndex:e.slotIndex??t}):[]}var en=e=>{const t=e.config||{},n=e.dimensions.plot,o=t.layerAccessor??"x",r=t.rowAccessor??"y",i=t.partitionAccessor??"partition",a=t.semanticAccessor??"semantic",s=t.labelAccessor??"label",c=t.storesAccessor??"stores",l=t.backEdgeAccessor??"isBackEdge",u=t.edgeTypeAccessor??"edgeType",d={...Qt,...t.partitionColors},h={...Zt,...t.edgeColors},f=t.accentColor??"var(--semiotic-focus, #ffcc33)",m=t.borderColor??"var(--semiotic-border, #555)",p=t.dimOpacity??.14,y=t.edgeOpacity??.5,g=t.edgeWidth??1.25,x=t.backEdgeWidth??t.edgeWidth??1.5,b=!1!==t.showStoreChips,w=t.storeChipColor??"var(--semiotic-info, #6a8caf)";let M=t.layerCount,v=t.maxLayerSize;if(null==M||null==v){let t=0;const n=new Map;for(const r of e.nodes){const e=Math.round(Number(J(r,o,0)));t=Math.max(t,e),n.set(e,(n.get(e)??0)+1)}M=M??t+1,v=v??Math.max(1,...n.values())}const k=n.width/Math.max(1,M),$=n.height/Math.max(1,v);let A=Math.min(t.nodeWidth??172,Math.max(8,k-(t.minGapX??26))),S=Math.min(t.nodeHeight??54,Math.max(8,$-(t.minGapY??18)));const I=t.lod&&"auto"!==t.lod?t.lod:16>A?"dot":48>A?"icon":108>A?"compact":"full";if("dot"===I){const e=Math.min(A,S,11);A=e,S=e}const C=Math.max(1,n.width-A),N=Math.max(1,n.height-S),F=Math.max(1,v-1),z=e=>n.x+A/2+(M>1?e/(M-1):.5)*C,W=e=>n.y+S/2+(e+F/2)/F*N,j=t.reachableIds?new Set(t.reachableIds):null,L=t.selectedId??null,R=e.selection,O=new Map,E=new Map,P=[],T=[];for(const t of e.nodes){const e=t.id,n=Number(J(t,o,0)),l=Number(J(t,r,0)),u=J(t,i,"processor")+"",h=J(t,a,"processor")+"",y=J(t,s,e)+"",g=Jt(J(t,c,[])),x=t.data??t,b=z(n),w=W(l);O.set(e,{cx:b,cy:w});const M=j?j.has(e):null,v=R?.isActive?R.predicate(x):null,k=null!==M?!M:null!==v&&!v;E.set(e,k);const $=null!=L&&e===L,C=k&&!$?p:1,N=Object.prototype.hasOwnProperty.call(d,u)?d[u]:d.unknown;"dot"===I?P.push({type:"circle",cx:b,cy:w,r:A/2,style:{fill:N,opacity:C,stroke:$?f:"transparent",strokeWidth:$?2:0},datum:t,id:e,label:y}):(P.push({type:"rect",x:b-A/2,y:w-S/2,w:A,h:S,style:{fill:N,opacity:C,stroke:$?f:m,strokeWidth:$?3:1},datum:t,id:e,label:y}),T.push({id:e,cx:b,cy:w,partition:u,semantic:h,label:y,stores:g,opacity:C,selected:$,node:x}))}const D=[];for(const t of e.edges){const e="string"==typeof t.source?t.source:t.source.id,n="string"==typeof t.target?t.target:t.target.id,o=O.get(e),r=O.get(n);if(!o||!r)continue;const i=!!J(t,l,!1),a=J(t,u,"internal")+"",s=E.get(e)||E.get(n)?Math.min(y,1.4*p):y,c=i?h.back:Object.prototype.hasOwnProperty.call(h,a)?h[a]:h.internal;let d;if(i){const e=o.cx,t=o.cy+S/2,n=r.cx,i=r.cy+S/2,a=Math.max(48,.28*Math.abs(e-n))+S;d=`M${e},${t} C${e},${t+a} ${n},${i+a} ${n},${i}`}else{const e=o.cx+A/2,t=o.cy,n=r.cx-A/2,i=r.cy,a=(e+n)/2;d=`M${e},${t} C${a},${t} ${a},${i} ${n},${i}`}const f={type:"curved",pathD:d,style:{stroke:c,strokeWidth:i?x:g,fill:"none",opacity:s,...i?{strokeDasharray:"5 4",strokeLinecap:"round"}:{}},datum:t};D.push(f)}const q=0===T.length?null:_t("g",{className:"lineage-dag-glyphs",children:T.map(e=>function(e,t){const{w:n,h:o,lod:r}=t,i="icon"===r?Math.min(n,o):Math.min(o-14,26),a=(Object.prototype.hasOwnProperty.call(t.partColors,e.partition)?t.partColors[e.partition]:t.partColors.unknown)??"#5a5a6a",s="icon"===r?0:8+i+8,c=null!=t.renderIcon?t.renderIcon({semantic:e.semantic,partition:e.partition,size:i,color:a,node:e.node}):function(e,t,n){const o=t.startsWith("topic")?"T":{source:"SR",sink:"SK",filter:"FL",map:"MP",aggregate:"AG",reduce:"RD","join-this":"JN","join-other":"JN",merge:"MG",suppress:"SP",select:"SE",tostream:"TS"}[e]??"PR";return Ut("g",{children:[_t("rect",{width:n,height:n,rx:4,fill:"rgba(255,255,255,0.08)",stroke:"rgba(255,255,255,0.18)"}),_t("text",{x:n/2,y:n/2+.5,textAnchor:"middle",dominantBaseline:"middle",fontSize:.42*n,fontWeight:700,fill:"var(--semiotic-text, #fff)",children:o})]})}(e.semantic,e.partition,i),l="full"===r,u="icon"!==r,d="full"===r&&t.showChips&&e.stores.length>0;return Ut("g",{transform:`translate(${e.cx-n/2}, ${e.cy-o/2})`,opacity:e.opacity,style:{pointerEvents:"none"},children:[_t("g",{transform:`translate(${"icon"===r?(n-i)/2:8}, ${(o-i)/2})`,children:c}),u&&_t("foreignObject",{x:s,y:l?o/2-12:o/2-9,width:Math.max(8,n-s-8),height:18,style:{pointerEvents:"none"},children:_t("div",{title:e.label,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, inherit)",fontSize:"full"===r?12.5:11.5,fontWeight:600,color:"var(--semiotic-text, #f4f4f8)",lineHeight:"18px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.label})}),l&&_t("text",{x:s,y:o/2-16,dominantBaseline:"middle",fontSize:9.5,fontWeight:500,fill:"var(--semiotic-text-secondary, #b9b9c8)",style:{textTransform:"uppercase",letterSpacing:"0.04em"},children:t.typeLabel?t.typeLabel({semantic:e.semantic,partition:e.partition,node:e.node}):e.partition.startsWith("topic")?"topic":e.semantic}),d&&e.stores.map((e,n)=>_t("rect",{x:s+15*n,y:o-10,width:12,height:5,rx:1.5,fill:t.chipColor,children:_t("title",{children:e.storeName})},e.storeName+n))]},e.id)}(e,{w:A,h:S,lod:I,partColors:d,chipColor:w,showChips:b,renderIcon:t.renderIcon,typeLabel:t.typeLabel}))});return{sceneNodes:P,sceneEdges:D,overlays:q}};import{jsx as tn,jsxs as nn}from"react/jsx-runtime";function on(e,t){return e.length>t?e.slice(0,Math.max(1,t-1))+"…":e}var rn={rect:"process",round:"process",stadium:"terminal",subroutine:"subprocess",cylinder:"database",circle:"connector",diamond:"decision",hexagon:"preparation",flag:"process"};function an(e,t,n,o,r,i,a,s){const c=t-o/2,l=n-r/2,u={fill:i,stroke:a,strokeWidth:s};switch(e){case"diamond":return tn("polygon",{points:`${t},${l} ${t+o/2},${n} ${t},${n+r/2} ${c},${n}`,...u});case"circle":return tn("circle",{cx:t,cy:n,r:Math.min(o,r)/2,...u});case"stadium":case"round":return tn("rect",{x:c,y:l,width:o,height:r,rx:"stadium"===e?r/2:8,ry:"stadium"===e?r/2:8,...u});case"hexagon":{const e=Math.min(.18*o,16);return tn("polygon",{points:`${c+e},${l} ${t+o/2-e},${l} ${t+o/2},${n} ${t+o/2-e},${n+r/2} ${c+e},${n+r/2} ${c},${n}`,...u})}case"cylinder":{const e=Math.min(.16*r,8),t=`M${c},${l+e} a${o/2},${e} 0 0 1 ${o},0`;return nn("g",{children:[tn("path",{d:`M${c},${l+e} a${o/2},${e} 0 0 0 ${o},0 v${r-2*e} a${o/2},${e} 0 0 1 ${-o},0 z`,...u}),tn("path",{d:t,fill:"none",stroke:a,strokeWidth:s})]})}case"subroutine":{const e=Math.min(8,.08*o);return nn("g",{children:[tn("rect",{x:c,y:l,width:o,height:r,rx:3,...u}),tn("line",{x1:c+e,y1:l,x2:c+e,y2:l+r,stroke:a,strokeWidth:s}),tn("line",{x1:c+o-e,y1:l,x2:c+o-e,y2:l+r,stroke:a,strokeWidth:s})]})}default:return tn("rect",{x:c,y:l,width:o,height:r,rx:4,...u})}}var sn=e=>{const t=e.config||{},n=e.dimensions.plot,o=t.direction??"TD",r="LR"===o||"RL"===o,i="BT"===o||"RL"===o,a=t.layerAccessor??"layer",s=t.rowAccessor??"row",c=t.labelAccessor??"label",l=t.shapeAccessor??"shape",u=t.edgeLabelAccessor??"label",d=t.nodeFill??"var(--semiotic-surface, #20242d)",h=t.nodeStroke??"var(--semiotic-border, #5a6573)",f=t.textColor??"var(--semiotic-text, #e6e6e6)",m=t.edgeColor??"var(--semiotic-text-secondary, #9aa0a6)",p=t.accentColor??"var(--semiotic-warning, #d49a00)";if(0===e.nodes.length)return{sceneNodes:[],overlays:null};const y=new Map;let g=0;for(const t of e.nodes){const e=Math.round(Number(J(t,a,0)));g=Math.max(g,e);const n=y.get(e)||[];n.push(t),y.set(e,n)}const x=g+1;let b=1;for(const e of y.values())e.sort((e,t)=>Number(J(e,s,0))-Number(J(t,s,0))),b=Math.max(b,e.length);const w=r?n.width:n.height,M=r?n.height:n.width,v=w/x,k=M/(b+1),$=Math.max(44,Math.min(t.nodeWidth??150,r?v-36:.92*k)),A=Math.max(26,Math.min(t.nodeHeight??46,r?.7*k:.5*v)),S=(r?$:A)/2+6,I=Math.max(1,w-2*S),C=e=>(r?n.x:n.y)+S+(x>1?(i?x-1-e:e)/(x-1)*I:I/2),N=new Map,F=[],z=[];for(const[e,t]of y)t.forEach((o,i)=>{const a=C(e),s=(r?n.y:n.x)+(i+1)/(t.length+1)*M,u=r?a:s,m=r?s:a,y=J(o,l,"rect")+"",g=J(o,c,o.id)+"";N.set(o.id,{cx:u,cy:m,shape:y}),F.push({type:"rect",x:u-$/2,y:m-A/2,w:$,h:A,style:{fill:"transparent",stroke:"transparent"},datum:{id:o.id,name:g,type:rn[y]??"process",shape:y},id:o.id,label:g}),z.push(nn("g",{children:[an(y,u,m,$,A,d,"diamond"===y?p:h,1.5),tn("text",{x:u,y:m,textAnchor:"middle",dominantBaseline:"central",fontSize:13,fill:f,style:{pointerEvents:"none"},children:on(g,Math.max(4,Math.floor(($-12)/7)))})]},"n-"+o.id))});const W=[];return e.edges.forEach((e,t)=>{const n="string"==typeof e.target?e.target:e.target.id,o=N.get("string"==typeof e.source?e.source:e.source.id),i=N.get(n);if(!o||!i)return;const a=r?o.cx+$/2:o.cx,s=r?o.cy:o.cy+A/2,c=r?i.cx-$/2:i.cx,l=r?i.cy:i.cy-A/2,d=r?`M${a},${s} C${(a+c)/2},${s} ${(a+c)/2},${l} ${c},${l}`:`M${a},${s} C${a},${(s+l)/2} ${c},${(s+l)/2} ${c},${l}`,p=Math.atan2(l-s,c-a),y=c-9*Math.cos(p),g=l-9*Math.sin(p),x=4.5*-Math.sin(p),b=4.5*Math.cos(p),w=`${c},${l} ${y+x},${g+b} ${y-x},${g-b}`,M=J(e,u,void 0),v=(a+c)/2,k=(s+l)/2;W.push(nn("g",{children:[tn("path",{d:d,fill:"none",stroke:m,strokeWidth:1.4}),tn("polygon",{points:w,fill:m}),"string"==typeof M&&M.length>0&&nn("g",{children:[tn("rect",{x:v-6.5*M.length/2-4,y:k-9,width:6.5*M.length+8,height:18,rx:3,fill:"var(--semiotic-bg, #11151c)",stroke:h,strokeWidth:.75}),tn("text",{x:v,y:k,textAnchor:"middle",dominantBaseline:"central",fontSize:11,fill:f,style:{pointerEvents:"none"},children:M})]})]},"e-"+t))}),{sceneNodes:F,overlays:nn("g",{className:"mermaid-dag",children:[W,z]})}};import{jsx as cn,jsxs as ln}from"react/jsx-runtime";function un(e){return cn("rect",{className:e.className,x:e.x,y:e.y,width:Math.max(0,e.width),height:Math.max(0,e.height),rx:e.radius??10,ry:e.radius??10,fill:e.fill??"none",stroke:e.stroke,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray,opacity:e.opacity??.6,style:{pointerEvents:"none"}},e.keyId)}function dn(e,t=0){let n=1/0,o=1/0,r=-1/0,i=-1/0;for(const t of e){const e=t.r??0;n>t.x-e&&(n=t.x-e),t.x+e>r&&(r=t.x+e),o>t.y-e&&(o=t.y-e),t.y+e>i&&(i=t.y+e)}return Number.isFinite(n)?{x:n-t,y:o-t,width:r-n+2*t,height:i-o+2*t}:null}function hn(e,t=0){if(!e.length)return null;const n="number"==typeof t?t:t.x??0,o="number"==typeof t?t:t.y??0;let r=1/0,i=1/0,a=-1/0,s=-1/0;for(const t of e){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))continue;if(!Number.isFinite(t.width)||!Number.isFinite(t.height))continue;const e=Math.max(0,t.width),n=Math.max(0,t.height);r>t.x&&(r=t.x),i>t.y&&(i=t.y),t.x+e>a&&(a=t.x+e),t.y+n>s&&(s=t.y+n)}return Number.isFinite(r)?{x:r-n,y:i-o,width:a-r+2*n,height:s-i+2*o}:null}function fn(e){const t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:cn("text",{className:e.className,x:e.x,y:e.y,textAnchor:e.anchor??"middle",dominantBaseline:e.baseline??"middle",fontSize:t,fontWeight:e.fontWeight,fill:e.color,style:{pointerEvents:"none"},children:e.text},e.keyId)}function mn(e){const t=e.spacing??8;return{def:cn("pattern",{id:e.id,width:t,height:t,patternUnits:"userSpaceOnUse",patternTransform:`rotate(${e.angle??45})`,children:cn("line",{x1:0,y1:0,x2:0,y2:t,stroke:e.color??"currentColor",strokeWidth:e.strokeWidth??1,opacity:e.opacity??.5})},e.id),fill:`url(#${e.id})`}}function pn(e){const t=e.orient??"bottom",n="bottom"===t||"top"===t,o=e.offset??0,r=e.tickLength??6,i=e.gridLength??0,a=e.labelGap??4,s=e.fontSize??11,c=e.color??"var(--semiotic-text-secondary, #888)",l=e.gridColor??c,u=e.format??(e=>e+""),d="top"===t||"left"===t?-1:1,h=e.ticks.length-1,f=e.ticks.map((f,m)=>{const p=e.scale(f),y=o+d*r,g=o-d*i,x=y+d*a;let b;b=e.labelAnchor?e.labelAnchor:n?e.edgeAnchor&&0===m?"start":e.edgeAnchor&&m===h?"end":"middle":"left"===t?"end":"start";const w=n?"top"===t?"auto":"hanging":"middle",M=n?{x:p,y:x}:{x:x,y:p};return ln("g",{children:[(r>0||i>0)&&cn("line",{...n?{x1:p,x2:p,y1:y,y2:g}:{x1:y,x2:g,y1:p,y2:p},stroke:i>0?l:c,strokeWidth:1,strokeDasharray:i>0?e.gridDasharray:void 0,opacity:i>0?.7:1}),cn("text",{x:M.x,y:M.y,textAnchor:b,dominantBaseline:w,fontSize:s,fontWeight:e.fontWeight,fill:c,children:u(f)})]},`tick-${f}-${m}`)});return cn("g",{className:e.className,style:{pointerEvents:"none"},children:f},e.keyId)}function yn(e){const t=e.stroke??"var(--semiotic-text, #f4f4f8)",n=e.strokeWidth??1,o=e.markRadius??0,r=e.labelX-e.markX,i=e.labelY-e.markY,a=Math.hypot(r,i)||1,s=e.markX+r/a*o,c=e.markY+i/a*o;let l;return l="elbow"===e.connector?`M${s},${c} L${s},${e.labelY} L${e.labelX},${e.labelY}`:"curve"===e.connector?`M${s},${c} Q${(s+e.labelX)/2},${c} ${e.labelX},${e.labelY}`:`M${s},${c} L${e.labelX},${e.labelY}`,ln("g",{className:e.className,style:{pointerEvents:"none"},children:[o>0&&cn("circle",{cx:e.markX,cy:e.markY,r:o,fill:"none",stroke:t,strokeWidth:n}),cn("path",{d:l,fill:"none",stroke:t,strokeWidth:n}),cn("text",{x:e.labelX,y:e.labelY,textAnchor:e.labelAnchor??"middle",dominantBaseline:e.labelBaseline??"hanging",fontSize:e.fontSize??11,fontWeight:e.fontWeight,fill:e.color??t,children:e.label})]},e.keyId)}import{jsx as gn,jsxs as xn}from"react/jsx-runtime";function bn(e,t,n={}){const o=n.fingerprintRounds??3,r=[],i=new Set;for(const t of e)null==t.id||i.has(t.id)||(i.add(t.id),r.push(t.id));const{outAdj:a,inAdj:s,undirected:c}=An(r,t),l=Sn(r,a,s,c,o).map(e=>({ids:e.ids,nodeCount:e.nodeCount,edgeCount:e.edgeCount,sinkCount:e.sinkCount,sourceCount:e.sourceCount,directed:e.directed,motif:e.motif,descriptor:$n(e)})),u=new Map;for(const e of l){const t=u.get(e.motif);t?t.count+=1:u.set(e.motif,{motif:e.motif,descriptor:e.descriptor,count:1,directed:e.directed})}return{components:l,motifs:[...u.values()].sort((e,t)=>t.count-e.count),directedCount:l.filter(e=>e.directed).length,branchingCount:l.filter(e=>!e.directed).length}}function wn(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function Mn(e){return"string"==typeof e?e:e?.id}function vn(e,t,n,o,r){const i=new Set(e);let a=new Map;for(const o of e){let e=0,r=0;for(const e of t.get(o)??[])i.has(e)&&(r+=1);for(const t of n.get(o)??[])i.has(t)&&(e+=1);a.set(o,`${e}:${r}`)}for(let o=0;r>o;o+=1){const o=new Map;for(const r of e){const e=[];for(const n of t.get(r)??[])i.has(n)&&e.push(a.get(n));const s=[];for(const e of n.get(r)??[])i.has(e)&&s.push(a.get(e));e.sort(),s.sort(),o.set(r,wn(`${a.get(r)}>${e.join(",")}<${s.join(",")}`))}a=o}const s=e.map(e=>a.get(e)).sort();return wn(`${e.length}#${o}#${s.join(";")}`)}function kn(e,t,n,o,r,i,a){const{layer:s,layerCount:c}=function(e,t){const n=new Set(e),o=new Map,r=new Set,i=e=>{const a=o.get(e);if(void 0!==a)return a;if(r.has(e))return 0;r.add(e);let s=0;for(const o of t.get(e)??[])n.has(o)&&(s=Math.max(s,1+i(o)));return r.delete(e),o.set(e,s),s};let a=0;for(const t of e)a=Math.max(a,i(t));const s=new Map;for(const t of e)s.set(t,a-o.get(t));return{layer:s,layerCount:a+1}}(e.ids,o),l=Array.from({length:c},()=>[]);for(const t of e.ids)l[s.get(t)].push(t);const u=.14*Math.min(i.width,i.height),d=Math.max(1,i.width-2*u),h=Math.max(1,i.height-2*u),f=new Map,m=new Set(e.ids);for(let e=0;c>e;e+=1){let t=l[e];e>0&&(t=[...t].sort((e,t)=>p(e)-p(t)));const n=t.length,o=i.y+u+(1===c?.5:e/(c-1))*h;t.forEach((e,t)=>{f.set(e,{x:i.x+u+(1===n?.5:t/(n-1))*d,y:o})})}function p(e){let t=0,n=0;for(const o of r.get(e)??[]){const e=f.get(o);m.has(o)&&e&&(t+=e.x,n+=1)}return n>0?t/n:i.x+d/2}const y=l.reduce((e,t)=>Math.max(e,t.length),1),g=T(Math.min(a,d/(2.4*y),h/(2.4*c)),1.4,a),x=e.ids.map(e=>{const o=f.get(e);return{id:e,cx:o.x,cy:o.y,r:g,datum:t.get(e)??q({id:e}),category:n.get(e)??""}}),b=[];for(const t of e.ids){const e=f.get(t);for(const n of o.get(t)??[]){if(!m.has(n))continue;const t=f.get(n);b.push({x1:e.x,y1:e.y,x2:t.x,y2:t.y})}}return{nodes:x,edges:b}}function $n(e){const{nodeCount:t,edgeCount:n,sinkCount:o,sourceCount:r}=e;return 1===t?"isolate":2===t&&1===n?"pair":1===r&&1===o&&n===t-1?"chain of "+t:e.directed&&1===r&&n>t-1?"diamond / mesh":e.directed?`converging (${t})`:"branching → "+o}function An(e,t){const n=new Set(e),o=new Map,r=new Map,i=new Map;for(const t of e)o.set(t,new Set),r.set(t,new Set),i.set(t,new Set);for(const e of t){const t=e.source,a=e.target;n.has(t)&&n.has(a)&&t!==a&&(o.get(t).has(a)||(o.get(t).add(a),r.get(a).add(t),i.get(t).add(a),i.get(a).add(t)))}return{outAdj:o,inAdj:r,undirected:i}}function Sn(e,t,n,o,r){const i=new Set,a=[];for(const s of e){if(i.has(s))continue;const e=[s];i.add(s);const c=[];for(;e.length;){const t=e.pop();c.push(t);for(const n of o.get(t)??[])i.has(n)||(i.add(n),e.push(n))}const l=new Set(c);let u=0,d=0,h=0;for(const e of c){let o=0,r=0;for(const n of t.get(e)??[])l.has(n)&&(o+=1);for(const t of n.get(e)??[])l.has(t)&&(r+=1);h+=o,0===o&&(u+=1),0===r&&(d+=1)}a.push({ids:c,nodeCount:c.length,edgeCount:h,sinkCount:u,sourceCount:d,directed:1===u,motif:vn(c,t,n,h,r)})}return a}var In=new P(8),Cn=e=>{const t=e.config||{},n=e.dimensions.plot;if(!e.nodes.length)return{sceneNodes:[]};const o=t.sourceAccessor??"source",r=t.targetAccessor??"target",i=t.labelAccessor??"label",a=t.categoryAccessor??"category",s=t.nodeRadius??4,c=t.cellGap??16,l=t.bandGap??22,u=t.headerHeight??34,d=t.minCellForFull??38,h=t.maxCellSize??120,f=t.minCellSize??12,m=t.fingerprintRounds??3,p=!1!==t.groupByMotif,y=t.sort??"frequency",g=new Map,x=new Map,b=[];for(const t of e.nodes){const e=t.id;null==e||g.has(e)||(b.push(e),g.set(e,t.data??t),x.set(e,J(t,a,"")+""))}const w=[];for(const t of e.edges){const e=Mn(t.source??J(t,o,void 0)),n=Mn(t.target??J(t,r,void 0));null!=e&&null!=n&&w.push({source:e,target:n})}const{outAdj:M,inAdj:v,undirected:k}=An(b,w),$=Sn(b,M,v,k,m),A=new Map;if(p)for(const e of $){const t=A.get(e.motif);t?t.push(e):A.set(e.motif,[e])}else A.set("all",[...$].sort((e,t)=>t.nodeCount-e.nodeCount));const S=[...A.entries()];S.sort((e,t)=>"size"===y?t[1][0].nodeCount-e[1][0].nodeCount:"directedness"===y?Number(t[1][0].directed)-Number(e[1][0].directed):t[1].length-e[1].length);const I=wn(b.join(",")+"|"+[...M.entries()].map(([e,t])=>e+">"+[...t].sort().join(".")).join(";")),C=ne([Math.round(n.x),Math.round(n.y),Math.round(n.width),Math.round(n.height),c,l,u,d,h,f,m,p,y,s,S.map(([e,t])=>e+":"+t.length).join(","),I]),N=In.getOrCompute(C,()=>function(e,t){const{plot:n}=t,o=Math.max(40,n.width),{cell:r,cols:i}=(()=>{for(let r=t.maxCellSize;r>=t.minCellSize;r-=2){const i=Math.max(1,Math.floor((o+t.cellGap)/(r+t.cellGap)));let a=0;for(const[,n]of e)a+=t.headerHeight+Math.ceil(n.length/i)*(r+t.cellGap)+t.bandGap;if(n.height>=a)return{cell:r,cols:i}}return{cell:t.minCellSize,cols:Math.max(1,Math.floor((o+t.cellGap)/(t.minCellSize+t.cellGap)))}})(),a=[],s=[];let c=n.y;for(const[l,u]of e){const e=Math.ceil(u.length/i),d=c,h=d+t.headerHeight,f=r>=t.minCellForFull;u.forEach((e,o)=>{const s=n.x+o%i*(r+t.cellGap),c=h+Math.floor(o/i)*(r+t.cellGap);if(f){const n=kn(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,{x:s,y:c,width:r,height:r},t.nodeRadius);a.push({component:e,lod:"full",cx:s+r/2,cy:c+r/2,glyphR:0,nodes:n.nodes,edges:n.edges})}else a.push({component:e,lod:"glyph",cx:s+r/2,cy:c+r/2,glyphR:Math.max(2.5,.36*r),nodes:[],edges:[]})});const m=Nn(u[0],t,{x:n.x,y:d+2,width:Math.min(t.headerHeight-6,40),height:t.headerHeight-6});s.push({motif:l,descriptor:$n(u[0]),count:u.length,directed:u[0].directed,x:n.x,y:d,width:o,height:t.headerHeight+e*(r+t.cellGap),exemplar:m}),c=h+e*(r+t.cellGap)+t.bandGap}return{cells:a,bands:s}}(S,{plot:n,cellGap:c,bandGap:l,headerHeight:u,minCellForFull:d,maxCellSize:h,minCellSize:f,nodeRadius:s,nodeDatum:g,nodeCategory:x,outAdj:M,inAdj:v})),F=e.theme.semantic||{},z=t.convergeColor??F.info??"#4c78a8",W=t.branchColor??F.warning??"#e8853a",j=t.edgeColor??F.border??"#9aa0aa",L=t.colorMode??"directedness",R={predicate:e.selection?.isActive?e.selection.predicate:null,highlight:t.highlight??null,dimOpacity:.14},O=t=>"motif"===L?e.resolveColor(t.motif):"category"===L||t.directed?z:W,E=[],P=[];for(const t of N.cells){const n=t.component,o=O(n);if("full"===t.lod){for(const e of t.edges)P.push({type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,style:{stroke:j,strokeWidth:1,opacity:.5},datum:null});for(const n of t.nodes){const t="category"===L&&n.category?e.resolveColor(n.category):o,r={type:"symbol",cx:n.cx,cy:n.cy,size:Math.PI*n.r*n.r,symbolType:"circle",style:{fill:t,opacity:Y(n.datum,R)},datum:n.datum,id:n.id,label:J(n.datum,i,n.id)+""};E.push(r)}}else{const e=q({id:`motif-${n.motif}-${t.cx.toFixed(0)}-${t.cy.toFixed(0)}`,motif:n.motif,shape:$n(n),nodes:n.nodeCount,edges:n.edgeCount,sinks:n.sinkCount,sources:n.sourceCount,directedness:n.directed?"converging":"branching"}),r={type:"symbol",cx:t.cx,cy:t.cy,size:Math.PI*t.glyphR*t.glyphR,symbolType:n.directed?"circle":"diamond",style:{fill:o,opacity:Y(e,R),stroke:j,strokeWidth:.75},datum:e,id:e.id+"",label:$n(n)};E.push(r)}}return{sceneNodes:E,sceneEdges:P,overlays:function(e,t){const n=[];for(const o of e){const e=o.directed?t.convergeColor:t.branchColor;if(n.push(un({keyId:"band-"+o.motif,x:o.x-6,y:o.y-4,width:o.width+12,height:o.height+4,radius:8,stroke:e,strokeWidth:1,opacity:.28})),t.showExemplars&&o.exemplar){const r=o.exemplar;n.push(xn("g",{style:{pointerEvents:"none"},children:[r.edges.map((e,n)=>gn("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:t.edgeColor,strokeWidth:.75,opacity:.55},"exe-"+n)),r.nodes.map(t=>gn("circle",{cx:t.cx,cy:t.cy,r:Math.max(1.6,t.r),fill:e},"exn-"+t.id))]},"ex-"+o.motif))}if(t.showBandLabels){const e=o.x+(t.showExemplars?48:4);n.push(gn("text",{x:e,y:o.y+12,fontSize:13,fontWeight:600,fill:t.textColor,style:{pointerEvents:"none"},children:o.descriptor},"bl-"+o.motif)),n.push(gn("text",{x:e,y:o.y+27,fontSize:11,fill:t.subText,style:{pointerEvents:"none"},children:`×${o.count} · ${o.directed?"converges to 1 sink":"branches to ≥2 sinks"}`},"bc-"+o.motif))}}if(t.showLegend){const e=t.plot.x+t.plot.width-168,i=t.plot.y-2;n.push(xn("g",{style:{pointerEvents:"none"},children:[gn("circle",{cx:e,cy:i,r:5,fill:t.convergeColor}),gn("text",{x:e+10,y:i+4,fontSize:11,fill:t.subText,children:"converges (1 sink)"}),gn("path",{d:(o=e,r=i+18,`M${o},${r-5} L${o+5},${r} L${o},${r+5} L${o-5},${r} Z`),fill:t.branchColor}),gn("text",{x:e+10,y:i+22,fontSize:11,fill:t.subText,children:"branches (≥2 sinks)"})]},"net-legend"))}var o,r;return gn("g",{className:"net-ensemble-overlays",children:n})}(N.bands,{convergeColor:z,branchColor:W,edgeColor:j,plot:n,showBandLabels:!1!==t.showBandLabels,showExemplars:!1!==t.showExemplars,showLegend:!1!==t.showLegend&&"directedness"===L,textColor:F.text??"var(--semiotic-text, #1a1a1a)",subText:F.textSecondary??"var(--semiotic-text-secondary, #888)"})}};function Nn(e,t,n){return e?kn(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,n,3):null}import{jsx as Fn,jsxs as zn}from"react/jsx-runtime";var Wn=new P(12);function jn(e){if(null==e)return NaN;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();const t=e+"",n=Number(t);if(!Number.isNaN(n)&&""!==t.trim())return n;const o=Date.parse(t);return Number.isNaN(o)?NaN:o}function Ln(e,t,n){return t>e?t:e>n?n:e}var Rn=e=>{const t=e.config||{},o=e.dimensions.plot,r=t.columnAccessor??"column",i=t.rowAccessor??"row",a=t.sizeAccessor,s=t.colorAccessor,c=t.symbolAccessor,l=t.shadeAccessor,u=t.markerAccessor,d=t.iconAccessor,h=t.defaultSymbol??"circle",[f,m]=t.sizeRange??[2,8],p=t.shadeStrength??.72,y=t.shadeReverse??!1,g=t.rowMode??"banded",x=t.cellSizing??"proportional",b=t.proportionExponent??1,w=t.columnGap??16,M=t.rowGap??12,v=t.packPadding??1,k=t.iterations??12,$=!1!==t.showEnclosures,A=!1!==t.showColumnHeaders,S=!1!==t.showRowLabels,I=A?t.headerHeight??26:0,C=S?t.labelWidth??66:0,N=t.callouts&&t.callouts.length>0?t.footerHeight??30:0,F=o.x+C,z=o.y+I,W=Math.max(1,o.width-C),R=Math.max(1,o.height-I-N),O=[];for(const t of e.nodes){const e=t.data??t;O.push({id:t.id,col:J(t,r,"—")+"",row:J(t,i,"—")+"",sizeVal:a?Number(J(t,a,1)):1,colorKey:s?J(t,s,"")+"":"",symVal:c?J(t,c,"")+"":"",shadeVal:l?jn(J(t,l,null)):NaN,marker:!!u&&!!J(t,u,!1),iconVal:d?J(t,d,"")+"":"",datum:e,size:0,packR:0,baseShape:"circle",iconShape:null})}if(0===O.length)return{sceneNodes:[]};let E=1/0,P=-1/0;if(a)for(const e of O)Number.isFinite(e.sizeVal)&&(E>e.sizeVal&&(E=e.sizeVal),e.sizeVal>P&&(P=e.sizeVal));t.sizeDomain&&([E,P]=t.sizeDomain),Number.isFinite(E)&&Number.isFinite(P)||(E=0,P=1);const T=e=>{if(E>=P)return(f+m)/2;const t=Math.sqrt(Ln((e-E)/(P-E),0,1));return f+t*(m-f)};let D=1/0,q=-1/0;if(l)for(const e of O)Number.isFinite(e.shadeVal)&&(D>e.shadeVal&&(D=e.shadeVal),e.shadeVal>q&&(q=e.shadeVal));t.shadeDomain&&([D,q]=t.shadeDomain);const B=e=>{if(!l||!Number.isFinite(e)||D>=q)return.5;const t=Ln((e-D)/(q-D),0,1);return y?1-t:t},H=t.colorMap,G=new Map,V=(t,n)=>{let o=G.get(t);if(!o){const n=H&&Object.prototype.hasOwnProperty.call(H,t)&&"string"==typeof H[t]&&H[t]?H[t]:e.resolveColor(t);o=K(n,p),G.set(t,o)}return o(n)},_=new Map;if(t.symbolMap)for(const[e,n]of Object.entries(t.symbolMap))_.set(e,n);let U=0;const Q=t.iconMap,Z=e=>d&&Q&&Object.prototype.hasOwnProperty.call(Q,e)?Q[e]??null:null,ee=e=>d?"circle":(e=>{if(!c)return h;let t=_.get(e);return t||(t=n[U%n.length],U++,_.set(e,t)),t})(e.symVal),te=t.maxAreaFraction??.4;let oe=0;const re=Array(O.length),ie=Array(O.length);for(let e=0;O.length>e;e++){const t=O[e],n=T(t.sizeVal);re[e]=n,t.baseShape=ee(t),t.iconShape=Z(t.iconVal);const o=j(t.baseShape,Math.PI*n*n);ie[e]=o,oe+=Math.PI*o*o}const ae=te*W*R,se=oe>ae?Math.sqrt(ae/oe):1;for(let e=0;O.length>e;e++){const t=O[e],n=re[e]*se;t.size=Math.PI*n*n,t.packR=ie[e]*se}const ce=new Map,le=new Map;for(const e of O)ce.set(e.col,(ce.get(e.col)??0)+1),le.set(e.row,(le.get(e.row)??0)+1);const ue=t.columnOrder?.filter(e=>ce.has(e))??[...ce.keys()].sort((e,t)=>(ce.get(t)??0)-(ce.get(e)??0)),de=t.rowOrder?.filter(e=>le.has(e))??[...le.keys()].sort((e,t)=>(le.get(t)??0)-(le.get(e)??0)),he=ne([Math.round(o.x),Math.round(o.y),Math.round(o.width),Math.round(o.height),I,C,N,g,x,b,w,M,v,k,f,m,E,P,te,ue.join(","),de.join(","),O.length,En(O)]),fe=Wn.getOrCompute(he,()=>function(e,t){const n=new Map;for(const t of e){let e=n.get(t.col);e||(e=[],n.set(t.col,e)),e.push(t)}const o=t.columnOrder.filter(e=>n.has(e)),r=Math.max(1,t.innerW-t.columnGap*Math.max(0,o.length-1)),i=t.proportionExponent,a=o.map(e=>Math.pow(n.get(e).length,i)),s=a.reduce((e,t)=>e+t,0)||1,c=e=>"uniform"===t.cellSizing?r/o.length:a[e]/s*r,l=new Map,u=[];let d=t.innerX;for(let e=0;o.length>e;e++)u.push({col:o[e],x:d,w:c(e)}),d+=c(e)+t.columnGap;let h=1;const f=new Map,m=[],p=(e,t,n,o)=>{let r=f.get(e);r||(r={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},f.set(e,r)),r.minX>t-o&&(r.minX=t-o),t+o>r.maxX&&(r.maxX=t+o),r.minY>n-o&&(r.minY=n-o),n+o>r.maxY&&(r.maxY=n+o)},y=(e,n,o,r,i,a)=>{const s=e.map(e=>({id:e.id,r:e.packR})),c=function(e,t,n,o,r,i,a,s){const c=t+o/2,l=n+r/2,u=new Map,d=e.length;if(0===d)return u;if(1===d)return u.set(e[0].id,{px:c,py:l}),u;const h=function(e){let t=e>>>0||1;return()=>(t=Math.imul(t,1664525)+1013904223>>>0,t/4294967296)}(s),f=new Float64Array(d);let m=0;for(let t=0;d>t;t++)f[t]=e[t].r+i,f[t]>m&&(m=f[t]);const p=Math.max(1,Math.round(Math.sqrt(d*o/Math.max(1,r)))),y=new Float64Array(d),g=new Float64Array(d),x=o/p,b=r/Math.ceil(d/p);for(let e=0;d>e;e++){const o=e%p,r=Math.floor(e/p);y[e]=t+(o+.3+.4*h())*x,g[e]=n+(r+.3+.4*h())*b}const w=Math.max(0,Math.min(a,14)),M=Math.max(1,2*m),v=new Map,k=Math.max(1,Math.ceil(o/M)+3),$=(e,t)=>(t+1)*k+(e+1);for(let e=0;w>e;e++){v.clear();for(let e=0;d>e;e++){const o=$(Math.floor((y[e]-t)/M),Math.floor((g[e]-n)/M)),r=v.get(o);r?r.push(e):v.set(o,[e])}for(let e=0;d>e;e++){const o=Math.floor((y[e]-t)/M),r=Math.floor((g[e]-n)/M);for(let t=-1;1>=t;t++)for(let n=-1;1>=n;n++){const i=v.get($(o+t,r+n));if(i)for(let t=0;i.length>t;t++){const n=i[t];if(e>=n)continue;let o=y[n]-y[e],r=g[n]-g[e];const a=f[e]+f[n],s=o*o+r*r;if(a*a>s)if(s>1e-9){const t=Math.sqrt(s),i=(a-t)/2;o/=t,r/=t,y[e]-=o*i,g[e]-=r*i,y[n]+=o*i,g[n]+=r*i}else{const t=2.39996323*e;y[e]+=Math.cos(t)*f[e],g[e]+=Math.sin(t)*f[e]}}}}for(let e=0;d>e;e++){const i=f[e],a=t+i,s=t+o-i,u=n+i,d=n+r-i;y[e]=s>a?Ln(y[e],a,s):c,g[e]=d>u?Ln(g[e],u,d):l}}for(let t=0;d>t;t++)u.set(e[t].id,{px:y[t],py:g[t]});return u}(s,n,o,r,i,t.packPadding,t.iterations,h++);let u=1/0,d=1/0,f=-1/0,m=-1/0;for(const e of s){const t=c.get(e.id);l.set(e.id,{px:t.px,py:t.py}),p(a,t.px,t.py,e.r),u>t.px-e.r&&(u=t.px-e.r),t.px+e.r>f&&(f=t.px+e.r),d>t.py-e.r&&(d=t.py-e.r),t.py+e.r>m&&(m=t.py+e.r)}return Number.isFinite(u)?{x:u-On,y:d-On,w:f-u+2*On,h:m-d+2*On}:null};if("banded"===t.rowMode){const r=new Map;for(const t of e)r.set(t.row,(r.get(t.row)??0)+1);const a=t.rowOrder.filter(e=>r.has(e)),s=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),c=a.map(e=>Math.pow(r.get(e),i)),d=c.reduce((e,t)=>e+t,0)||1,h=new Map;let m=t.innerY+t.innerH;for(let e=0;a.length>e;e++){const n="uniform"===t.cellSizing?s/a.length:c[e]/d*s,o=m-n;h.set(a[e],{y:o,h:n}),m=o-t.rowGap}o.forEach((e,t)=>{const o=X(n.get(e),e=>e.row);for(const e of a){const n=o.get(e),r=h.get(e);n&&r&&y(n,u[t].x,r.y,u[t].w,r.h,e)}});const p=[],g=new Map;for(const e of a){const t=h.get(e);g.set(e,t.y+t.h/2);const n=f.get(e);n&&Number.isFinite(n.minX)&&p.push({x:n.minX-On,y:n.minY-On,w:n.maxX-n.minX+2*On,h:n.maxY-n.minY+2*On})}return{positions:l,enclosures:p,colBands:u,rowLabelY:g}}const g=new Map;o.forEach((e,o)=>{const r=X(n.get(e),e=>e.row),a=t.rowOrder.filter(e=>r.has(e)),s=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),c=a.map(e=>Math.pow(r.get(e).length,i)),l=c.reduce((e,t)=>e+t,0)||1;let d=t.innerY+t.innerH;a.forEach((e,n)=>{const i="uniform"===t.cellSizing?s/a.length:c[n]/l*s,h=d-i,f=y(r.get(e),u[o].x,h,u[o].w,i,e);if(f){m.push(f);const t=g.get(e)??{sum:0,n:0};t.sum+=f.y+f.h/2,t.n+=1,g.set(e,t)}d=h-t.rowGap})});const x=new Map;for(const[e,t]of g)x.set(e,t.sum/t.n);return{positions:l,enclosures:m,colBands:u,rowLabelY:x}}(O,{columnOrder:ue,rowOrder:de,innerX:F,innerY:z,innerW:W,innerH:R,rowMode:g,cellSizing:x,proportionExponent:b,columnGap:w,rowGap:M,packPadding:v,iterations:k})),me=e.selection,pe=me?.isActive?me.predicate:null,ye=t.highlight??null,ge=t.dimOpacity??.16,xe=t.markStroke,be=t.markStrokeWidth??0,we=t.markerColor??"#ffffff",Me=t.iconColor??"rgba(255,255,255,0.92)",ve=t.iconStrokeWidth??1,ke=t.iconScale??.72,$e=[],Ae=[],Se=[];for(const e of O){const t=fe.positions.get(e.id);if(!t)continue;const n=Y(e.datum,{highlight:ye,predicate:pe,dimOpacity:ge}),o={type:"symbol",cx:t.px,cy:t.py,size:e.size,symbolType:e.baseShape,style:{fill:V(e.colorKey,B(e.shadeVal)),opacity:n,...xe?{stroke:xe,strokeWidth:be}:{}},datum:e.datum,id:e.id,label:e.id+""};if($e.push(o),e.iconShape){const o=Math.sqrt(e.size/Math.PI)*ke,r=j(e.iconShape,100);Se.push({x:t.px,y:t.py,size:r>0?o/r*100*(o/r):Math.PI*o*o,shape:e.iconShape,opacity:n})}e.marker&&n>ge+.001&&Ae.push({x:t.px,y:t.py,r:Math.max(1,.4*Math.sqrt(e.size/Math.PI))})}const Ie=[];if(t.callouts&&t.callouts.length>0){const e=t.calloutColor??"var(--semiotic-text, #f4f4f8)",n=o.y+o.height-(N>0?.45*N:9),r=[];for(let e=0;t.callouts.length>e;e++){const n=t.callouts[e],o=O.find(e=>e.datum[n.field]+""==n.value+"");if(!o)continue;const i=fe.positions.get(o.id);i&&r.push({c:n,ci:e,px:i.px,py:i.py,markR:Math.sqrt(o.size/Math.PI)})}const i=r.filter(e=>null==e.c.at).sort((e,t)=>e.px-t.px),a=new Map;i.forEach((e,t)=>{a.set(e.ci,F+(t+.5)/i.length*W)});for(const t of r){const r=t.c;let i=a.get(t.ci)??t.px,s=n;const c=r.connector??(a.has(t.ci)?"elbow":"straight");"object"==typeof r.at&&r.at?(i=r.at.x,s=r.at.y):"number"==typeof r.at&&(s=o.y+r.at*o.height),Ie.push({keyId:"callout-"+t.ci,markX:t.px,markY:t.py,labelX:i,labelY:s,label:r.label,connector:c,markRadius:Math.max(t.markR+3,7),stroke:e,color:e,fontSize:11,labelAnchor:"middle",labelBaseline:"auto"})}}const Ce=function(e,t){const n=t.columnLabel??(e=>e),o=t.rowLabel??(e=>e);return zn("g",{className:"packed-cluster-matrix-chrome",style:{pointerEvents:"none"},children:[t.showEnclosures&&e.enclosures.map((e,n)=>un({keyId:"enc-"+n,x:e.x,y:e.y,width:e.w,height:e.h,radius:t.enclosureRadius,stroke:t.enclosureColor,strokeWidth:t.enclosureWidth,opacity:t.enclosureOpacity})),t.iconMarks.length>0&&Fn("g",{className:"packed-cluster-matrix-icons",children:t.iconMarks.map((e,n)=>Fn("path",{d:L(e.shape,e.size),transform:`translate(${e.x},${e.y})`,fill:"none",stroke:t.iconColor,strokeWidth:t.iconStrokeWidth,opacity:e.opacity},"ic-"+n))}),t.markerDots.length>0&&Fn("g",{className:"packed-cluster-matrix-markers",children:t.markerDots.map((e,n)=>Fn("circle",{cx:e.x,cy:e.y,r:e.r,fill:t.markerColor},"mk-"+n))}),t.showColumnHeaders&&e.colBands.map((e,o)=>fn({keyId:"col-"+o,text:n(e.col),x:e.x+e.w/2,y:t.headerY,anchor:"middle",fontSize:t.headerFontSize,fontWeight:700,color:t.headerColor})),t.showRowLabels&&[...e.rowLabelY].map(([e,n])=>fn({keyId:"row-"+e,text:o(e),x:t.labelX,y:n,anchor:"end",fontSize:t.labelFontSize,fontWeight:600,color:t.labelColor})),t.callouts.map(e=>yn(e))]})}(fe,{markerDots:Ae,markerColor:we,iconMarks:Se,iconColor:Me,iconStrokeWidth:ve,callouts:Ie,plot:o,showEnclosures:$,showColumnHeaders:A,showRowLabels:S,enclosureColor:t.enclosureColor??"var(--semiotic-text, #f4f4f8)",enclosureRadius:t.enclosureRadius??9,enclosureOpacity:t.enclosureOpacity??.5,enclosureWidth:t.enclosureWidth??1.5,headerColor:t.headerColor??"var(--semiotic-text, #f4f4f8)",labelColor:t.labelColor??"var(--semiotic-text-secondary, #b9b9c8)",headerFontSize:t.headerFontSize??13,labelFontSize:t.labelFontSize??11,headerY:o.y+.62*I,labelX:o.x+C-10,columnLabel:t.columnLabel,rowLabel:t.rowLabel});return{sceneNodes:$e,overlays:Ce}},On=4;function En(e){let t=2166136261;const n=e=>{for(let n=0;e.length>n;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)};for(const o of e)n(o.id),n(o.col),n(o.row),t^=Math.round(8*o.packR),t=Math.imul(t,16777619);return(t>>>0).toString(36)}import*as Pn from"react";var Tn=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height)return{nodes:[]};const o=ee(t.categoryAccessor),r=ee(t.stackBy),i=e=>{const n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor],o=Number(n);return Number.isFinite(o)&&o>0?o:0},a=t.gutter??2,s="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",c="string"==typeof t.stackBy?t.stackBy:"stack",l="string"==typeof t.valueAccessor?t.valueAccessor:"value",u=(e,t,n)=>D(o=>{o("category",e),o("stack",t),o("value",n),"category"!==s&&o(s,e),"stack"!==c&&o(c,t),"value"!==l&&o(l,n)}),d=!1!==t.showCategoryLabels,h=Math.max(0,n.height-(t.labelPadding??(d?22:0))),f=[],m=new Map,p=[],y=new Set,g=new Map;for(const t of e.data){const e=o(t)+"",n=r(t)+"",a=i(t);m.has(e)||(f.push(e),m.set(e,0),g.set(e,new Map)),y.has(n)||(y.add(n),p.push(n)),m.set(e,(m.get(e)??0)+a);const s=g.get(e);s.set(n,(s.get(n)??0)+a)}const x=t.categoryOrder?Dn(t.categoryOrder,f,e=>m.has(e)):f,b=t.stackOrder?Dn(t.stackOrder,p,()=>!0):p,w=x.reduce((e,t)=>e+(m.get(t)??0),0);if(0>=w)return{nodes:[]};const M=Math.max(0,n.width-a*Math.max(0,x.length-1)),v=[],k=[];let $=n.x;for(const t of x){const o=m.get(t)??0,r=o/w*M;if(0>=r)continue;k.push({cat:t,x:$,w:r});const i=g.get(t);let s=n.y;for(const n of b){const a=i.get(n)??0;if(0>=a)continue;const c=a/o*h;v.push({type:"rect",x:$,y:s,w:r,h:c,style:{fill:e.resolveColor(n),stroke:"none"},datum:u(t,n,a),group:n}),s+=c}$+=r+a}return{nodes:v,overlays:d&&k.length>0?function(e,t,n){const o=e.map((e,o)=>fn({keyId:"marimekko-label-"+o,text:e.cat,x:e.x+e.w/2,y:t+12,anchor:"middle",baseline:"auto",maxWidth:e.w-4,fontSize:12,color:n}));return Pn.createElement(Pn.Fragment,null,...o)}(k,n.y+h+4,`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`):null}};function Dn(e,t,n){const o=new Set,r=[];for(const t of e)n(t)&&!o.has(t)&&(o.add(t),r.push(t));for(const e of t)o.has(e)||r.push(e);return r}import*as qn from"react";var Bn=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height||0===e.data.length)return{nodes:[]};const o=t.rowHeight??28,r=t.rowGap??12,i=!1!==t.showLabels,a=i?t.labelWidth??120:0,s=!1!==t.showTicks,c=s?14:0,l=t.tickFormat??(e=>e.toLocaleString()),u=n.x+a,d=Math.max(0,n.width-a);if(0>=d)return{nodes:[]};const h=ee(t.categoryAccessor),f=e=>{const t=Number(e);return Number.isFinite(t)&&t>0?t:0},m=e=>f("function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor]),p=e=>f("function"==typeof t.targetAccessor?t.targetAccessor(e):e[t.targetAccessor]),y=e=>{const n="function"==typeof t.rangesAccessor?t.rangesAccessor(e):e[t.rangesAccessor];return Array.isArray(n)?n.map(f).sort((e,t)=>e-t):[]},g="string"==typeof t.categoryAccessor?t.categoryAccessor:"metric",x="string"==typeof t.valueAccessor?t.valueAccessor:"value",b="string"==typeof t.targetAccessor?t.targetAccessor:"target",w=t.actualColor??e.theme.semantic.primary??"#3b6cb1",M=e.theme.semantic.text??"currentColor",v=t.targetColor??`var(--semiotic-text, ${M})`,k=[`var(--semiotic-surface, ${e.theme.semantic.surface??"#e8eaed"})`,`var(--semiotic-grid, ${e.theme.semantic.grid??"#cdd1d6"})`,`var(--semiotic-border, ${e.theme.semantic.border??"#a3a8af"})`],$=`var(--semiotic-text, ${M})`,A=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,S=[],I=[];for(let t=0;e.data.length>t;t++){const i=e.data[t],a=y(i),s=m(i),l=p(i),f=Math.max(s,l,...a.length?a:[0]);if(0>=f)continue;const M=n.y+t*(o+r+c);if(M+o+c>n.y+n.height)break;I.push({yTop:M,label:h(i),actual:s,target:l,maxVal:f});const $=e=>u+e/f*d,A=h(i),C=e=>D(t=>{t("metric",A),"metric"!==g&&t(g,A),e(t)});let N=u;for(let e=0;a.length>e;e++){const t=$(a[e]),n=t-N;n>0&&S.push({type:"rect",x:N,y:M,w:n,h:o,style:{fill:k[Math.min(e,k.length-1)],stroke:"none"},datum:C(t=>{t("range",e),t("rangeValue",a[e]),t("kind","range")}),group:"range-"+e}),N=t}const F=Math.max(6,Math.floor(.45*o));S.push({type:"rect",x:u,y:M+(o-F)/2,w:$(s)-u,h:F,style:{fill:w,stroke:"none"},datum:C(e=>{e("value",s),e("kind","actual"),"value"!==x&&e(x,s)}),group:"actual"});const z=3,W=Math.floor(.8*o);S.push({type:"rect",x:$(l)-z/2,y:M+(o-W)/2,w:z,h:W,style:{fill:v,stroke:"none"},datum:C(e=>{e("target",l),e("kind","target"),"target"!==b&&e(b,l)}),group:"target"})}const C=[];for(let e=0;I.length>e;e++){const t=I[e];if(i&&C.push(fn({keyId:"bullet-label-"+e,text:t.label,x:n.x+a-8,y:t.yTop+o/2,anchor:"end",baseline:"middle",fontSize:13,fontWeight:500,color:$})),s){const n=5,r=t.yTop+o+2;for(let o=0;n>o;o++){const i=t.maxVal*o/(n-1),a=u+i/t.maxVal*d;C.push(qn.createElement("line",{key:`bullet-tick-${e}-${o}`,x1:a,x2:a,y1:r,y2:r+3,stroke:A,strokeWidth:1}),fn({keyId:`bullet-ticktext-${e}-${o}`,text:l(i),x:a,y:r+12,anchor:0===o?"start":o===n-1?"end":"middle",baseline:"auto",fontSize:10,color:A}))}}}return{nodes:S,overlays:C.length>0?qn.createElement(qn.Fragment,null,...C):null}};import*as Yn from"react";import{scaleLinear as Hn}from"d3-scale";var Gn=e=>{const t=e.config,{plot:n}=e.dimensions,o=t.fields??[];if(2>o.length||0>=n.width||0>=n.height)return{nodes:[]};if(0===e.data.length)return{nodes:[]};const r=Object.create(null);for(const n of o){const o=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,n)?t.domains[n]:void 0;if(Array.isArray(o)&&o.length>=2&&"number"==typeof o[0]&&Number.isFinite(o[0])&&"number"==typeof o[1]&&Number.isFinite(o[1])){r[n]=[o[0],o[1]];continue}let i=1/0,a=-1/0;for(const t of e.data){const e=Number(t[n]);Number.isFinite(e)&&(i>e&&(i=e),e>a&&(a=e))}r[n]=Number.isFinite(i)&&Number.isFinite(a)&&i!==a?[i,a]:[0,1]}const i=!1!==t.showAxes,a=i?t.axisLabelPadding??24:8,s=i?18:8,c=o.map(e=>Hn().domain(r[e]).range([n.y+n.height-s,n.y+a])),l=o.map((e,t)=>1===o.length?n.x+n.width/2:n.x+t/(o.length-1)*n.width),u=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>(e[t.colorBy]??"")+"":null,d=t.opacity??.45,h=t.strokeWidth??1.25,f=e.theme.semantic.primary??"#3b6cb1",m=t.dimmedOpacity??.08,p=t.highlightFn,y=[],g=[];for(const n of e.data){const r=u?e.resolveColor(u(n)+""):f,i=!p||p(n),a=Y(n,{predicate:p,baseOpacity:d,dimOpacity:m,brighten:.4}),s=i?g:y;for(let e=0;o.length-1>e;e++){const t=Number(n[o[e]]),u=Number(n[o[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(u))continue;const d={type:"connector",x1:l[e],y1:c[e](t),x2:l[e+1],y2:c[e+1](u),style:{stroke:r,strokeWidth:p&&i?h+.75:h,opacity:a,fill:"none"},datum:n};s.push(d)}if(t.showPoints)for(let e=0;o.length>e;e++){const t=Number(n[o[e]]);if(!Number.isFinite(t))continue;const i={type:"point",x:l[e],y:c[e](t),r:2.5,style:{fill:r,stroke:"none",opacity:Math.min(1,a+.3)},datum:n};s.push(i)}}let x=null;if(i){const i=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,u=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,d=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,h=n.y+a,f=n.y+n.height-s,m=[];for(let e=0;o.length>e;e++){const s=o[e],p=l[e],y=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,s)?t.tickFormat[s]:void 0,g="function"==typeof y?y:e=>e.toLocaleString();m.push(Yn.createElement("line",{key:"pc-axis-line-"+e,x1:p,x2:p,y1:h,y2:f,stroke:i,strokeWidth:1})),m.push(fn({keyId:"pc-axis-label-"+e,text:s,x:p,y:n.y+a-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:u}));const[x,b]=r[s],w=5;for(let t=0;w>t;t++){const n=x+(b-x)*t/(w-1),o=c[e](n);m.push(Yn.createElement("line",{key:`pc-tick-${e}-${t}`,x1:p-3,x2:p+3,y1:o,y2:o,stroke:i,strokeWidth:1}),fn({keyId:`pc-ticktext-${e}-${t}`,text:g(n),x:p+6,y:o+3,anchor:"start",baseline:"auto",fontSize:10,color:d}))}}x=Yn.createElement(Yn.Fragment,null,...m)}return{nodes:y.concat(g),overlays:x}};import{jsx as Xn,jsxs as Vn}from"react/jsx-runtime";var Kn=1.75,_n="#222222";function Un(e,t){return e.topRadius+(t-e.height)/e.height*(e.topRadius-e.bottomRadius)}function Qn(e,t){return function(e,t,n){return Math.PI*n/3*(e*e+e*t+t*t)}(Un(e,t),e.bottomRadius,t)}function Zn(e,t){const n=(e.topRadius+e.bottomRadius)/2,o=Math.PI*n*n;let r=t/o,i=t-Qn(e,r),a=0;for(;100>a&&Math.abs(i)>1e-4;)r+=i/o,i=t-Qn(e,r),a++;return r}function Jn(e,t){const n=43758.5453*Math.sin(12.9898*e+78.233);return 2*(n-Math.floor(n)-.5)*t}function eo(e,t){if(t>e||2*t>e)return[{x:0,y:0}];const n=[],o=e=>{let r=Math.floor(2*Math.PI*e/(2*t));1>r&&(r=1);const i=0*e,a=Math.hypot(1*e-e*Math.cos(2*Math.PI/r),i-e*Math.sin(2*Math.PI/r));2*t>a&&r>1&&r--;for(let t=0;r>t;t++)n.push({x:e*Math.cos(2*t*Math.PI/r),y:e*Math.sin(2*t*Math.PI/r)});const s=e-2*t;t>s?e>2*t&&n.push({x:0,y:0}):o(s)};return o(e-t),n}function to(e,t,n){const o=[];let r=n,i=0;for(;r>0&&60>i;){const n=t*(1+2*i),a=eo(Un(e,n),t),s=a.length-r,c=s>1?a.slice(Math.floor(s/2),Math.floor(s/2)+r):a,l=e.height-n;if(c.forEach((e,t)=>{o.push({x:e.x+Jn(97*i+t,.15),z:l+Jn(31*i+t,.05)})}),r-=c.length,i++,0===c.length)break}return{pearls:o,layers:i}}function no(e,t,n,o){if(0>=o)return[];const r=function(e,t,n){let o=n,r=0;for(;o>0&&60>r;){const n=Un(e,t+.875*(1+2*r));o-=Math.max(1,Math.floor(2*n/Kn)),r++}return r}(e,t,o),i=Math.max(t,n-r*Kn)+.875,a=[];let s=0;for(let t=0;r>t&&o>s;t++){const n=i+Kn*t,r=Un(e,n),c=Math.max(1,Math.floor(2*r/Kn)),l=(2*r-c*Kn)/(c+1),u=-r+l,d=e.height-n-.875-.1;for(let e=0;c>e&&o>s;e++)a.push({cx:u+(l+Kn)*e+.875,cy:d+.875,rotation:Jn(53*t+e,10)}),s++}return a}function oo(e,t){const n=Number(e);return Number.isFinite(n)?n:t}var ro=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height)return{nodes:[]};const o=ee(t.categoryAccessor??"name"),r=ee(t.teaVolumeAccessor??"teaVolume"),i=ee(t.bobaVolumeAccessor??"bobaVolume"),a=ee(t.iceVolumeAccessor??"iceVolume"),s=ee(t.cupHeightAccessor??"cupHeight"),c=ee(t.cupTopRadiusAccessor??"cupTopRadius"),l=ee(t.cupBottomRadiusAccessor??"cupBottomRadius"),u=ee(t.bobaRadiusAccessor??"bobaRadius"),d=t.cupWidthRatio??.82,h=e.scales.o,f=h.bandwidth(),m=Math.max(1,n.height-26-8),p=n.y+8,y=[],g=[];for(const t of e.data){const n=o(t)+"",x=h(n);if(null==x)continue;const b={height:oo(s(t),15.5),topRadius:oo(c(t),4.75),bottomRadius:oo(l(t),3.75)},w=oo(u(t),.6),M=Math.max(0,oo(r(t),450)),v=Math.max(0,oo(i(t),110)),k=Math.max(0,oo(a(t),135)),$=Math.PI*w*w,A=Math.floor(v/$),S=A*$,I=Math.floor(k/5.359375),C=I*Kn*Kn*Kn,N=M+S+C,F=Zn(b,N),z=Math.min(b.height,Math.max(0,F)),W=Un(b,z),{pearls:j,layers:L}=to(b,w,A),R=z,O=no(b,L*w*2,R,I),E=b.height-20.32,P=Math.min(0,E),T=Math.min(f*d/(2*(b.topRadius+1)),m/(b.height-P)),D=x+f/2,B=e=>D+e*T,Y=e=>p+(e-P)*T,H=B(-(b.topRadius+1)),G=B(b.topRadius+1),X=Y(P),V=Y(b.height),K=q({name:n,teaVolume:M,bobaVolume:Math.round(S),iceVolume:Math.round(C),totalVolume:Math.round(N),numBobas:A,numIce:I,kind:"boba cup"});y.push({type:"rect",x:H,y:X,w:Math.max(1,G-H),h:Math.max(1,V-X),style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:K,group:n,_transitionKey:"boba-"+oe(n)});const _=b.height-R,U=oe(n),Q=e.resolveColor(n);g.push(Vn("g",{children:[M>0?Xn("path",{d:`M${B(-W)},${Y(_)} L${B(-b.bottomRadius)},${Y(b.height)} L${B(b.bottomRadius)},${Y(b.height)} L${B(W)},${Y(_)} z`,fill:"#D2B799"}):null,j.map((e,t)=>Xn("circle",{cx:B(e.x),cy:Y(e.z),r:w*T,fill:"#222222",opacity:.5},"p-"+t)),O.map((e,t)=>Xn("rect",{x:B(e.cx)-.95*Kn*T/2,y:Y(e.cy)-.95*Kn*T/2,width:.95*Kn*T,height:.95*Kn*T,rx:2,fill:"#a5f2f3",opacity:.85,transform:`rotate(${e.rotation} ${B(e.cx)} ${Y(e.cy)})`},"i-"+t)),Xn("path",{d:`M${B(-b.topRadius)},${Y(0)} L${B(-b.bottomRadius)},${Y(b.height)} L${B(b.bottomRadius)},${Y(b.height)} L${B(b.topRadius)},${Y(0)}`,fill:"none",stroke:_n,strokeWidth:2.5}),Xn("line",{x1:B(-(b.topRadius+1)),y1:Y(0),x2:B(b.topRadius+1),y2:Y(0),stroke:_n,strokeWidth:3,strokeLinecap:"round"}),M>0?Xn("path",{d:`M${B(-.635)},${Y(E)} L${B(-.635)},${Y(b.height-.4)} L${B(.635)},${Y(b.height-1.27-.4)} L${B(.635)},${Y(E)} z`,fill:"#4F91CB",stroke:_n,strokeWidth:1,opacity:.78}):null,Xn("text",{x:D,y:V+16,textAnchor:"middle",fontSize:12,fontWeight:600,fill:"var(--semiotic-text, #333)",children:n}),Xn("text",{x:D,y:V+30,textAnchor:"middle",fontSize:10,fill:Q,children:`${A} pearls · ${Math.round(N)} cm³`})]},"boba-"+U))}return{nodes:y,overlays:Xn("g",{className:"semiotic-boba",style:{pointerEvents:"none"},children:g})}},io=["naturalGas","coal","nuclear","hydro","wind","solar","other"],ao={naturalGas:"Natural gas",coal:"Coal",nuclear:"Nuclear",hydro:"Hydro",wind:"Wind",solar:"Solar",other:"Other"},so={tight:5,watch:12,comfortable:20};function co(e,t=0){return"number"==typeof e&&Number.isFinite(e)?e:t}function lo(e,t={}){const n=t.fuels??io,o=!0===t.includeZero,r=[];for(const t of e)if(t&&"number"==typeof t.t)for(const e of n){const n=co(t.fuels?.[e]);(o||n>0)&&r.push({t:t.t,fuel:e,fuelLabel:ao[e],mw:n,ba:t.ba})}return r}function uo(e){const t=[];for(const n of e){if(!n||"number"!=typeof n.t)continue;const e=co(n.demandMw),o=n.forecastMw;"number"==typeof o&&Number.isFinite(o)&&t.push({t:n.t,a:e,b:o,demandMw:e,forecastMw:o,errorMw:e-o,ba:n.ba})}return t}function ho(e){const t=co(e.demand);if(0>=t)return 0;const n=co(e.capacityOrNetGen),o=co(e.interchange);return(n+(0>o?-o:0)-t)/t*100}function fo(e){return e.filter(e=>e&&"number"==typeof e.t).map(e=>{const t=co(e.demandMw),n=co(e.netGenMw),o=ho({demand:t,capacityOrNetGen:n,interchange:e.interchangeMw});return{t:e.t,ba:e.ba,reserveMarginPct:o,netLoadMw:t,demandMw:t,netGenMw:n}})}function mo(e={},t={}){const{watch:n,comfortable:o}={...so,...e},r=t.field,i=r?{field:r}:{},a=t.tightHatch??{type:"hatch",background:"var(--semiotic-danger, #c2410c)",stroke:"rgba(255, 240, 200, 0.55)",spacing:5,angle:-35,lineWidth:1.25,lineOpacity:.9};return[{id:"reserve-comfortable",label:`Comfortable (≥ ${o}%)`,when:{...i,gte:o},style:{fill:t.comfortableFill??"var(--semiotic-success, #16a34a)",fillOpacity:.85}},{id:"reserve-watch",label:`Watch (< ${o}%, ≥ ${n}%)`,when:{...i,lt:o,gte:n},style:{fill:t.watchFill??"var(--semiotic-warning, #d97706)",fillOpacity:.9}},{id:"reserve-tight",label:`Tight (< ${n}%)`,when:{...i,lt:n},style:{fill:a,stroke:t.tightFill??"var(--semiotic-danger, #c2410c)",strokeWidth:1,fillOpacity:1}}]}function po(e={}){const{tight:t,watch:n,comfortable:o}={...so,...e};return[{type:"band",y0:-50,y1:t,label:"Tight",color:"var(--semiotic-danger, #c2410c)",fillOpacity:.12,emphasis:"secondary"},{type:"band",y0:t,y1:n,label:"Watch",color:"var(--semiotic-warning, #d97706)",fillOpacity:.1,emphasis:"secondary"},{type:"band",y0:n,y1:Math.max(o+30,40),label:"Headroom",color:"var(--semiotic-success, #16a34a)",fillOpacity:.06,emphasis:"secondary"}]}function yo(e,t){if(!e.length)return null;const n=[...e].filter(e=>e&&"number"==typeof e.t).sort((e,t)=>e.t-t.t);if(!n.length)return null;let o=n[n.length-1];if("number"==typeof t&&Number.isFinite(t)){const e=n.filter(e=>t>=e.t);o=e.length?e[e.length-1]:n[0]}const r=co(o.demandMw),i=co(o.netGenMw),a="number"==typeof o.forecastMw&&Number.isFinite(o.forecastMw)?o.forecastMw:null,s=ho({demand:r,capacityOrNetGen:i,interchange:o.interchangeMw}),c={};let l=null,u=0,d=0;for(const e of io){const t=co(o.fuels?.[e]);t>0&&(d+=t,c[e]=t,t>u&&(u=t,l=e))}if(d>0)for(const e of Object.keys(c))c[e]=c[e]/d;return{t:o.t,ba:o.ba,demandMw:r,forecastMw:a,forecastErrorMw:null==a?null:r-a,netGenMw:i,reserveMarginPct:s,topFuel:l,topFuelShare:d>0?u/d:0,topFuelMw:u,fuelShares:c}}function go(e,t={}){const n=t.now??Date.now(),o=t.author??"system",r=t.source??"authored-scenario";return e.map(e=>{const t=(e.start+e.end)/2,i=new Date(e.start).toISOString();return{type:"x-band",x0:e.start,x1:e.end,label:e.label,color:"outage"===e.kind?"var(--semiotic-danger)":"var(--semiotic-warning)",fillOpacity:.12,emphasis:"secondary",x:t,y:e.y??e.value,note:e.note,provenance:{author:o,authorKind:"system",source:r,basis:"rule",confidence:.85,createdAt:i,stableId:e.id,dataVersion:e.start+""},lifecycle:{status:"accepted",ttlHint:e.ttlHint??"P14D",anchor:"fixed"},_eventKind:e.kind,_createdAtMs:e.start,_nowMs:n}})}function xo(e,t=12){return[...e].filter(e=>Number.isFinite(e.reserveMarginPct)).sort((e,t)=>e.reserveMarginPct-t.reserveMarginPct).slice(0,Math.max(0,t))}function bo(e,t=0){return Number.isFinite(e)?e.toLocaleString(void 0,{maximumFractionDigits:t,minimumFractionDigits:t})+" MW":"—"}function wo(e,t=1){return Number.isFinite(e)?`${e>0?"+":""}${e.toFixed(t)}%`:"—"}import*as Mo from"react";function vo(e,t){if("function"==typeof e)return e;const n=e??t;return e=>Number(e[n])}function ko(e,t={}){const n=vo(t.start,"start"),o=vo(t.end,"end"),r=!1===t.sort?e.slice():e.slice().sort((e,t)=>n(e)-n(t)||o(t)-o(e)),i=[];return{packed:r.map(e=>{const t=n(e);let r=i.findIndex(e=>t>=e);return-1===r&&(r=i.length),i[r]=o(e),{item:e,track:r}}),trackCount:Math.max(1,i.length)}}function $o(e,t){const n=vo(t.start,"start"),o=vo(t.end,"end"),[r,i]=t.domain,a=t.step??1,s="half-open"===t.bounds,c=[];for(let t=r;i>=t;t+=a){let r=0;for(const i of e){const e=n(i),a=o(i);e>t||(s?t>=a:t>a)||r++}c.push({value:t,count:r})}return c}function Ao(e){return"function"==typeof e?e:t=>t[e]}var So=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height||0===e.data.length||!t?.domain)return{nodes:[]};const o=Ao(t.laneAccessor),r=Ao(t.startAccessor),i=Ao(t.endAccessor),a=t.idAccessor?Ao(t.idAccessor):null,s=t.unit??0,c=t.barGap??1.5,l=Math.max(0,t.minBarWidth??2),u=t.minBarHeight??3.5,d=t.maxBarHeight??10,h=t.lanePadding??7,f=t.cornerRadius??2,m=t.bottomInset??0,p=t.color??((t,n)=>e.resolveColor(n)),[y,g]=t.domain,x=g-y||1,b=e=>n.x+(e-y)/x*n.width,w=e.scales?.o?.domain?.()??[],M=t.lanes??(w.length>0?w:[...new Set(e.data.map(o))]),v=Math.max(0,n.height-m)/Math.max(1,M.length),k=e=>b(r(e)),$=e=>Math.max(k(e)+l,b(i(e)+s)),A=[];M.forEach((t,r)=>{const i=n.y+r*v,s=e.data.filter(e=>o(e)===t);if(0===s.length)return;const{packed:l,trackCount:m}=ko(s,{start:k,end:$}),y=new Map,g=new Map;for(const{item:e,track:t}of l){const n=g.get(t);n?n.push(e):g.set(t,[e])}for(const e of g.values()){e.sort((e,t)=>k(e)-k(t));for(let t=0;e.length-1>t;t++)y.set(e[t],k(e[t+1]))}const x=(v-2*h)/m,b=Math.min(d,Math.max(Math.min(u,x),x-c));for(const{item:e,track:n}of l){const o=k(e),r=y.get(e),s=$(e)-o;A.push({type:"rect",x:o,y:i+h+n*x,w:void 0!==r&&o+s>r-1?Math.max(1,r-1-o):s,h:b,cornerRadii:f>0?{tl:f,tr:f,br:f,bl:f}:void 0,style:{fill:p(e,t),stroke:"none"},datum:e,group:t,_transitionKey:a?a(e)+"":void 0})}});const S=`var(--semiotic-text, ${e.theme.semantic.text??"#1a1a1a"})`,I=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,C=`var(--semiotic-border, ${e.theme.semantic.border??"#94a3b8"})`,N=[];(t.periods??[]).forEach((e,t)=>{const o=b(e.start),r=Math.max(1,b(e.end+s)-o);N.push(Mo.createElement("rect",{key:"period-"+t,x:o,y:n.y,width:r,height:n.height,fill:C,opacity:t%2==0?.06:.025,pointerEvents:"none"})),e.name&&N.push(fn({keyId:"period-label-"+t,text:e.name,x:o+4,y:n.y+12,anchor:"start",baseline:"hanging",fontSize:13,fontWeight:700,color:I}))});const F=!1!==t.showLaneLabels,z=t.laneLabelGap??12;if(M.forEach((e,t)=>{const o=n.y+t*v;N.push(Mo.createElement("line",{key:"lane-sep-"+t,x1:n.x,x2:n.x+n.width,y1:o,y2:o,stroke:C,opacity:.45})),F&&N.push(fn({keyId:"lane-label-"+t,text:e,x:n.x-z,y:o+v/2,anchor:"end",baseline:"middle",fontSize:12,fontWeight:600,color:S}))}),!1!==t.showAxis){const e=t.axisTicks??Array.from({length:8},(e,t)=>Math.round(y+t/7*x));N.push(pn({keyId:"interval-axis",scale:b,ticks:e,orient:"top",offset:n.y,tickLength:0,gridLength:n.height,gridDasharray:"3 5",edgeAnchor:!0,format:t.tickFormat,color:I}))}return{nodes:A,overlays:Mo.createElement(Mo.Fragment,null,...N)}};function Io(e,t,n){const o=n?.orientation??"vertical",r=n?.bend??0,i=n?.minAlong??18,a=(e,t)=>(e+t)/2;if("vertical"===o){if(i>Math.abs(t.y-e.y)){const n=e.x>t.x?-1:1,o=a(e.x,t.x)+n*(22+Math.abs(r));return`M${e.x},${e.y} Q${o},${a(e.y,t.y)} ${t.x},${t.y}`}const n=a(e.y,t.y)+r;return`M${e.x},${e.y} C${e.x},${n} ${t.x},${n} ${t.x},${t.y}`}if(i>Math.abs(t.x-e.x)){const n=e.y>t.y?-1:1,o=a(e.y,t.y)+n*(22+Math.abs(r));return`M${e.x},${e.y} Q${a(e.x,t.x)},${o} ${t.x},${t.y}`}const s=a(e.x,t.x)+r;return`M${e.x},${e.y} C${s},${e.y} ${s},${t.y} ${t.x},${t.y}`}function Co(e,t,n){if("vertical"===(n?.orientation??"vertical")){const n=(e.y+t.y)/2;return`M${e.x},${e.y} L${e.x},${n} L${t.x},${n} L${t.x},${t.y}`}const o=(e.x+t.x)/2;return`M${e.x},${e.y} L${o},${e.y} L${o},${t.y} L${t.x},${t.y}`}function No(e,t,n){if("vertical"===(n?.orientation??"vertical")){const n=t.cy>=e.cy;return{from:{x:e.cx,y:e.cy+(n?e.height/2:-e.height/2)},to:{x:t.cx,y:t.cy+(n?-t.height/2:t.height/2)}}}const o=t.cx>=e.cx;return{from:{x:e.cx+(o?e.width/2:-e.width/2),y:e.cy},to:{x:t.cx+(o?-t.width/2:t.width/2),y:t.cy}}}function Fo(e,t){const n=t?.spread??5;return t?.modulo&&t.modulo>0?(e%t.modulo-(t.modulo-1)/2)*n:(e-((t?.count??1)-1)/2)*n}function zo(e,t){const n=1-t,o=n*n*n,r=3*n*n*t,i=3*n*t*t,a=t*t*t;return{x:o*e.p0.x+r*e.p1.x+i*e.p2.x+a*e.p3.x,y:o*e.p0.y+r*e.p1.y+i*e.p2.y+a*e.p3.y}}function Wo(e,t){const n=1-t,o=3*n*n,r=6*n*t,i=3*t*t;return{x:o*(e.p1.x-e.p0.x)+r*(e.p2.x-e.p1.x)+i*(e.p3.x-e.p2.x),y:o*(e.p1.y-e.p0.y)+r*(e.p2.y-e.p1.y)+i*(e.p3.y-e.p2.y)}}function jo(e){return`M${e.p0.x},${e.p0.y} C${e.p1.x},${e.p1.y} ${e.p2.x},${e.p2.y} ${e.p3.x},${e.p3.y}`}function Lo(e,t){const n=t?.axis??"x",o=t?.padding??0,r=t?.strength??.5,i="x"===n?"y":"x",a="x"===n?"width":"height",s="x"===n?"height":"width",c=new Map;for(const t of e)c.set(t.id,0);for(let t=0;e.length>t;t++)for(let l=t+1;e.length>l;l++){const u=e[t],d=e[l];if(Math.abs(u[i]-d[i])>(u[s]+d[s])/2+o)continue;const h=d[n]-u[n]||(d.id>u.id?-.5:.5),f=(u[a]+d[a])/2+o-Math.abs(h);if(0>=f)continue;const m=f*r*Math.sign(h);c.set(u.id,(c.get(u.id)??0)-m),c.set(d.id,(c.get(d.id)??0)+m)}return c}var Ro={width:60,height:34};function Oo(e,t){if("function"==typeof e)return e;const n=e??t;return e=>J(e,n,void 0)}function Eo(e,t,n,o){const r=o.fixedAxis??"y",i=e=>Oo(o.sourceAccessor,"source")(e)+"",a=e=>Oo(o.targetAccessor,"target")(e)+"",s=o.size??(()=>Ro),c=o.iterations??180,l=o.attraction??.012,u=o.anchorStrength??.003,d=o.collisionStrength??.12,h=o.collisionPadding??15,f=o.edgePadding??42,m=o.fixedPadding??16,p=o.damping??.72,y=o.spread??1,[g,x]=o.fixedDomain,b=x-g||1,w=("y"===r?n.y:n.x)+m,M=("y"===r?n.y+n.height:n.x+n.width)-m,v=("y"===r?n.x:n.y)+f,k=("y"===r?n.x+n.width:n.y+n.height)-f,$=Math.max(1,k-v),A=e.map(e=>{const t=ce(e)??e,n=(r=e,Oo(o.idAccessor,"id")(r)+"");var r;const{width:i,height:a}=s(t),c=(e=>Number(Oo(o.fixedAccessor,"fixed")(e)))(e),l=v+function(e){let t=2166136261;for(let n=0;e.length>n;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)/4294967295}(n)*$;return{data:t,id:n,width:i,height:a,fixedValue:c,fixed:(u=c,w+(u-g)/b*(M-w)),free:l,anchor:l};var u}),S=new Map(A.map(e=>[e.id,e])),I=e=>"y"===r?e.width:e.height;for(let e=0;c>e;e++){const e=new Map;for(const t of A)e.set(t.id,0);for(const n of t){const t=S.get(i(n)),o=S.get(a(n));if(!t||!o)continue;const r=(o.free-t.free)*l;e.set(t.id,(e.get(t.id)??0)+r),e.set(o.id,(e.get(o.id)??0)-r)}for(const t of A)e.set(t.id,(e.get(t.id)??0)+(t.anchor-t.free)*u);const n=Lo(A.map(e=>({id:e.id,x:"y"===r?e.free:e.fixed,y:"y"===r?e.fixed:e.free,width:e.width,height:e.height})),{axis:"y"===r?"x":"y",padding:h,strength:d});for(const t of A)e.set(t.id,(e.get(t.id)??0)+(n.get(t.id)??0));for(const t of A){t.free+=(e.get(t.id)??0)*p;const n=I(t)/2;t.free=Math.max(v+n,Math.min(k-n,t.free))}}if(1!==y){const e=(v+k)/2;for(const t of A){const n=I(t)/2;t.free=Math.max(v+n,Math.min(k-n,e+(t.free-e)*y))}}const C=A.map(e=>({data:e.data,id:e.id,x:"y"===r?e.free:e.fixed,y:"y"===r?e.fixed:e.free,width:e.width,height:e.height,fixedValue:e.fixedValue}));return{positioned:C,byId:new Map(C.map(e=>[e.id,e]))}}var Po=e=>{const{plot:t}=e.dimensions;if(0>=t.width||0>=t.height||0===e.nodes.length||!e.config?.fixedDomain)return{sceneNodes:[]};const n=e.config.fixedAxis??"y",{positioned:o,byId:r}=Eo(e.nodes,e.edges,t,e.config),i=o.map(t=>({type:"rect",x:t.x-t.width/2,y:t.y-t.height/2,w:t.width,h:t.height,style:{fill:e.resolveColor(t.id),stroke:"none"},datum:t.data,id:t.id,label:t.id})),a=[];e.edges.forEach((t,o)=>{const i=r.get((s=t,("function"==typeof e.config.sourceAccessor?e.config.sourceAccessor(s):J(s,e.config.sourceAccessor??"source",void 0))+""));var s;const c=r.get((t=>("function"==typeof e.config.targetAccessor?e.config.targetAccessor(t):J(t,e.config.targetAccessor??"target",void 0))+"")(t));if(!i||!c)return;const{from:l,to:u}=No({cx:i.x,cy:i.y,width:i.width,height:i.height},{cx:c.x,cy:c.y,width:c.width,height:c.height},{orientation:"y"===n?"vertical":"horizontal"});a.push({type:"curved",pathD:Io(l,u,{orientation:"y"===n?"vertical":"horizontal",bend:Fo(o,{modulo:5,spread:5})}),style:{stroke:"var(--semiotic-border, #888)",fill:"none",strokeWidth:1.4},datum:ce(t)??t})});const s=o.map(e=>({x:e.x,y:e.y,text:e.id}));return{sceneNodes:i,sceneEdges:a,labels:s}};function To(e){const t=Number(e.segmentDomain?.[0]),n=Number(e.segmentDomain?.[1]),o=Number.isFinite(t)?t:0,r=Number.isFinite(n)?n:o,i=o>r?-1:1,a=Math.abs(r-o),s=Number(e.currentSegment),c=Number.isFinite(s)?T((s-o)*i,0,a):0,l=(e,t)=>{const n=Number(e);return Number.isFinite(n)?T(n,0,1):t},u=l(e.oldestOpacity,.25),d=l(e.currentOpacity,1),h=l(e.futureOpacity,0);return{weightOpacity:!0===e.combineWeightOpacity,wordOpacity:({segment:e})=>{const t=Number(e);if(!Number.isFinite(t))return h;const n=(t-o)*i;if(n>c)return h;if(0===c)return d;const r=T(n/c,0,1);return u+(d-u)*r}}}import{jsx as Do,jsxs as qo}from"react/jsx-runtime";function Bo(e){let t=2166136261;for(let n=0;e.length>n;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)/4294967295}var Yo=1.15,Ho={a:.556,b:.556,c:.5,d:.556,e:.556,f:.278,g:.556,h:.556,i:.222,j:.222,k:.5,l:.222,m:.833,n:.556,o:.556,p:.556,q:.556,r:.333,s:.5,t:.278,u:.556,v:.5,w:.722,x:.5,y:.5,z:.5,"'":.191,"-":.333,".":.278," ":.278};function Go(e){let t=0;for(const n of e)t+=Ho[n]??.6;return t}function Xo(e,t){return Math.max(8,Go(e)*t*1.05+1)}function Vo(e,t,n){for(const o of t)if((e.w+o.w)/2+n>Math.abs(e.x-o.x)&&(e.h+o.h)/2+n>Math.abs(e.y-o.y))return!0;return!1}var Ko=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height||0===e.data.length)return{nodes:[]};const o=ee(t.textAccessor),r=e=>{const n=Number(ee(t.weightAccessor)(e));return Number.isFinite(n)&&n>0?n:0},i=ee(t.columnAccessor),a=e=>Number(ee(t.segmentAccessor)(e)),s=t.minFontSize??11,c=t.maxFontSize??42,l=t.columnGutter??18,u=t.collisionPadding??2,d=!1!==t.showColumnLabels,h=!1!==t.showSegmentAxis,f=t.segmentTickCount??6,m=t.segmentTickFormat??(e=>Math.round(e)+""),p=t.rotate??0,y=!0===t.repeatWords,g=!1!==t.scaleToFit,x=t.packingDensity??.6,b="string"==typeof t.textAccessor?t.textAccessor:"word",w="string"==typeof t.weightAccessor?t.weightAccessor:"weight",M="string"==typeof t.columnAccessor?t.columnAccessor:"column",v="string"==typeof t.segmentAccessor?t.segmentAccessor:"segment",k=[],$=new Map;let A=1/0,S=-1/0;for(let t=0;e.data.length>t;t++){const n=e.data[t],s=i(n)+"",c=o(n)+"",l=r(n),u=a(n);c&&Number.isFinite(u)&&($.has(s)||(k.push(s),$.set(s,[])),$.get(s).push({col:s,text:c,weight:l,segment:u,datum:n,dataIndex:t}),A>u&&(A=u),u>S&&(S=u))}if(0===k.length)return{nodes:[]};if(!y)for(const[e,t]of $){const n=new Map;for(const e of t){const t=n.get(e.text);t&&t.weight>=e.weight||n.set(e.text,e)}$.set(e,[...n.values()])}let I=1/0,C=-1/0;for(const e of $.values())for(const t of e)I>t.weight&&(I=t.weight),t.weight>C&&(C=t.weight);if(!Number.isFinite(I))return{nodes:[]};const N=t.columnOrder?[...t.columnOrder.filter(e=>$.has(e)),...k.filter(e=>!t.columnOrder.includes(e))]:k,F=new Map(N.map(n=>[n,t.columnColor?.(n)||e.resolveColor(n)])),[z,W]=t.segmentDomain??[A,S],j=W-z||1,L=C-I||1,R=d?22:0,O=h?52:0,E=n.x+O,P=n.y+R,q=Math.max(0,n.width-O),B=Math.max(0,n.height-R),Y=N.length,H=Y>0?Math.max(0,q-l*Math.max(0,Y-1))/Y:0,G=P+14,X=P+B-14,V=e=>G+(e-z)/j*(X-G),K=H*B;let _=1/0,U=1/0;const Q=N.map((e,n)=>{const o=F.get(e),r=($.get(e)??[]).map(e=>{const r={word:e.text,column:e.col,weight:e.weight,segment:e.segment,datum:e.datum,dataIndex:e.dataIndex,columnIndex:n,resolvedColumnColor:o},i=t.wordOpacity?Number(t.wordOpacity(r)):1,a=t.wordColor?.(r);return{text:e.text,weight:e.weight,segment:e.segment,baseFont:(l=e.weight,s+Math.sqrt((l-I)/L)*(c-s)),opacity:Number.isFinite(i)?T(i,0,1):0,color:a||o,info:r};var l});if(0===r.length)return null;let i=0;for(const e of r){const t=1.05*Go(e.text);i+=t*Yo*e.baseFont*e.baseFont,U=Math.min(U,(H-8-1)/(t*e.baseFont))}return i>0&&(_=Math.min(_,Math.sqrt(x*K/i))),{col:e,colLeft:E+n*(H+l),center:E+n*(H+l)+H/2,rows:r}}).filter(e=>null!==e),Z=e=>{const t=[];let n=0;for(const o of Q){if(0>=H)continue;const r=o.colLeft+4,i=o.colLeft+H-4,a=o.rows.map((t,n)=>{const r=Math.max(5,e*t.baseFont),i=`${o.col}::${t.text}::${n}`;return{id:i,text:t.text,weight:t.weight,segment:t.segment,font:r,w:Xo(t.text,r),h:r*Yo+2,anchorY:V(t.segment),seed:(Bo(i)-.5)*Math.min(.5*H,80),opacity:t.opacity,color:t.color,info:t.info}}).sort((e,t)=>t.font-e.font||(t.id>e.id?-1:1)),s=[];for(const e of a){const a=e.w/2,c=e.h/2,l=T(o.center+e.seed,r+a,i-a),d=e.anchorY;let h=l,f=T(d,G+c,X-c),m=!1;for(let t=0;2600>t;t++){const n=3.2*Math.sqrt(t),o=2.399963229728653*t,p={x:T(l+n*Math.cos(o),r+a,i-a),y:T(d+n*Math.sin(o),G+c,X-c),w:e.w,h:e.h};if(!Vo(p,s,u)){h=p.x,f=p.y,m=!0;break}}m||n++,s.push({x:h,y:f,w:e.w,h:e.h});const y=Math.sqrt((e.weight-I)/L),g=p>0?2*(Bo(e.id+"r")-.5)*p:0;t.push({id:e.id,text:e.text,x:h,y:f,fontSize:e.font,rotation:g,color:e.color,opacity:e.opacity,datum:D(t=>{for(const n of Object.keys(e.info.datum))t(n,e.info.datum[n]);t("word",e.text),t("weight",e.weight),t("column",o.col),t("segment",e.segment),"word"!==b&&t(b,e.text),"weight"!==w&&t(w,e.weight),"column"!==M&&t(M,o.col),"segment"!==v&&t(v,e.segment),t("__strength",.5+.5*y)})})}}return{placed:t,unplaced:n}};let J=g?Math.min(1,_,U):Math.min(1,U),te=Z(J);if(g)for(let e=0;6>e&&te.unplaced>0&&J>.1;e++)J*=.88,te=Z(J);const ne=te.placed.filter(e=>e.opacity>0);return{nodes:ne.map(e=>{const t=Xo(e.text,e.fontSize)/2,n=e.fontSize*Yo/2;return{type:"rect",x:e.x-t,y:e.y-n,w:2*t,h:2*n,style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:e.datum,group:e.datum.column+"",_transitionKey:e.id}}),overlays:qo("g",{className:"semiotic-word-trails",children:[h&&_o({x:n.x+O-10,yTop:G,yBot:X,segLo:z,segHi:W,segToY:V,tickCount:f,tickFormat:m,color:`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,label:t.segmentAxisLabel,labelX:n.x}),d&&N.map((e,t)=>H>0?Do("text",{x:E+t*(H+l)+H/2,y:n.y+14,textAnchor:"middle",fontSize:13,fontWeight:600,fill:F.get(e),style:{pointerEvents:"none"},children:e},"wt-col-"+t):null),ne.map(e=>Do("text",{x:e.x,y:e.y,textAnchor:"middle",dominantBaseline:"central",fontSize:e.fontSize,fontWeight:600,fill:e.color,opacity:(!1===t.weightOpacity?1:Number(e.datum.__strength))*e.opacity,transform:e.rotation?`rotate(${e.rotation} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},"wt-"+e.id))]})}};function _o(e){const t=[],n=e.segHi-e.segLo||1;for(let o=0;e.tickCount>o;o++)t.push(e.segLo+n*o/Math.max(1,e.tickCount-1));return qo("g",{className:"semiotic-word-trails-axis",style:{pointerEvents:"none"},children:[Do("line",{x1:e.x,y1:e.yTop,x2:e.x,y2:e.yBot,stroke:e.color,strokeWidth:1,opacity:.5}),t.map((t,n)=>{const o=e.segToY(t);return qo("g",{children:[Do("line",{x1:e.x-4,y1:o,x2:e.x,y2:o,stroke:e.color,strokeWidth:1,opacity:.6}),Do("text",{x:e.x-7,y:o,textAnchor:"end",dominantBaseline:"central",fontSize:11,fill:e.color,children:e.tickFormat(t)})]},"wt-tick-"+n)}),e.label&&Do("text",{transform:`rotate(-90 ${e.labelX+10} ${(e.yTop+e.yBot)/2})`,x:e.labelX+10,y:(e.yTop+e.yBot)/2,textAnchor:"middle",fontSize:11,fontWeight:600,fill:e.color,children:e.label})]})}var Uo={fill:"rgba(0,0,0,0)",stroke:"rgba(0,0,0,0)",opacity:0},Qo=8;function Zo(e){return null==e?void 0:e+""}function Jo(e){const t=Zo(e.id);return{type:"point",x:e.x,y:e.y,r:e.r??8,style:{...Uo,cursor:e.cursor},datum:e.datum,pointId:t,_transitionKey:t}}function er(e){return Jo(e)}function tr(e){const[[t,n],[o,r]]=e.bounds;return{type:"geoarea",pathData:e.pathData,centroid:e.centroid,bounds:e.bounds,screenArea:e.screenArea??Math.abs((o-t)*(r-n)),style:{...Uo,cursor:e.cursor},datum:e.datum,group:e.group,interactive:!0}}function nr(e){return{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Uo,cursor:e.cursor},datum:e.datum,group:e.group,_transitionKey:Zo(e.id)}}function or(e){const t=Zo(e.id);return"width"in e&&"height"in e?{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Uo,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}:{type:"circle",cx:e.x,cy:e.y,r:e.r??8,style:{...Uo,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}}function rr(e){const t={style:{...Uo,cursor:e.cursor},datum:e.datum,id:Zo(e.id),label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility,interactive:e.interactive??!0};return"pathD"in e?{type:e.type??"curved",pathD:e.pathD,...t}:{type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,...t}}function ir(e,t,n={}){const{coord:o,step:r=1,equals:i=Object.is,truthyOnly:a=!1}=n,s=[],c=t=>o?o(e[t],t):t,l=(e,t,n)=>{e.endIndex=t,e.count=t-e.startIndex+1,e.end=o?null==n||c(n)-c(t)>r?c(t)+r:c(n):t+1,s.push(e)};let u=null;for(let n=0;e.length>n;n++){const s=t(e[n],n);if(a&&!s){u&&(l(u,u.endIndex,n),u=null);continue}const d=!o||0>=n||c(n)-c(n-1)<=r;u&&d&&i(u.value,s)?u.endIndex=n:(u&&l(u,u.endIndex,n),u={value:s,start:c(n),end:c(n),count:1,startIndex:n,endIndex:n})}return u&&l(u,u.endIndex,null),s}var ar=ir;function sr(e,t,n=0){return t>0?((e-n)%t+t)%t+n:e}function cr(e,t,n){if(0>=n)return t-e;let o=(t-e)%n;return o>n/2?o-=n:-n/2>o&&(o+=n),o}function lr(e,t,n){return t>n?e>=t||n>=e:e>=t&&n>=e}function ur(e,t,n,o){return n>o?[...e.filter(e=>t(e)>=n),...e.filter(e=>t(e)<=o)]:e.filter(e=>lr(t(e),n,o))}function dr(e,t){const n=Math.max(0,t.width),o=t.y,r=Math.min(74,Math.max(34,.08*n)),i=t.paddingLeft??r,a=e.length>1?Math.max(0,n-i-(t.paddingRight??r))/(e.length-1):0,s=new Map;return e.forEach((e,t)=>{s.set(e.id,{id:e.id,x:i+a*t,y:o,index:t})}),s}function hr(e,t){const n=Math.max(0,t.width),o=t.y,r=Math.min(74,Math.max(34,.08*n)),i=t.paddingLeft??r,a=t.paddingRight??r,s=t.gap??8,c=!1!==t.distribute,l=t.estimateWidth??(e=>fr(e.label??e.id)),u=e.map((e,t)=>Math.max(1,l(e,t))),d=u.reduce((e,t)=>e+t,0)+s*Math.max(0,e.length-1),h=Math.max(0,n-i-a),f=c&&e.length>1?Math.max(0,h-d)/(e.length-1):0,m=new Map;let p=i;return c||1!==e.length||(p=i+Math.max(0,(h-u[0])/2)),e.forEach((e,t)=>{const n=u[t];m.set(e.id,{id:e.id,x:p+n/2,y:o,index:t,width:n}),p+=n+s+f}),m}function fr(e,t=38,n=7.4,o=20){return Math.max(t,((e??"")+"").length*n+o)}function mr(e){const t=e.map(e=>{const t=Math.min(e.a,e.b),n=Math.max(e.a,e.b);return{span:e,a:t,b:n,width:n-t}}).sort((e,t)=>e.width-t.width||e.a-t.a),n=[],o=t.map(e=>{let t=n.findIndex(t=>e.a>=t);return 0>t?(t=n.length,n.push(e.b)):n[t]=e.b,{span:e.span,level:t}}),r=o.reduce((e,t)=>Math.max(e,t.level),0);return{packed:o,maxLevel:r,levelCount:o.length?r+1:1}}function pr(e){const t=e.labelRoom??18,n=Math.max(48,e.baselineY-e.ceilingY-28),o=Math.max(1,e.levelCount),r=Math.min(42,Math.max(26,.18*n)),i=Math.max(24,n-r-t);return{arcLift:r,levelStep:Math.min(72,Math.max(28,o>1?i/Math.max(1,o-1):i))}}function yr(e,t,n,o,r={}){const i=n-(r.footLift??26);return`M${e} ${i}Q${(e+t)/2} ${o} ${t} ${i}`}function gr(e,t,n){return e-n.arcLift-t*n.levelStep}function xr(e,t=br){if(!e.length)return{shared:[],exclusive:[]};if(1===e.length)return{shared:[...e[0]],exclusive:[[]]};const n=e.map(e=>new Set(e.map(e=>t(e)))),o=new Set;for(const e of n[0])n.every(t=>t.has(e))&&o.add(e);const r=[],i=new Set;for(const n of e[0]){const e=t(n);o.has(e)&&!i.has(e)&&(r.push(n),i.add(e))}return{shared:r,exclusive:e.map(e=>e.filter(e=>!o.has(t(e))))}}function br(e){return null==e||"object"!=typeof e?e+"":null!=e.id?e.id+"":`${(e.sourceTokenId??e.source)+""}|${(e.targetTokenId??e.target)+""}|${(e.relation??e.label??"")+""}`}var wr=2*Math.PI;function Mr(e,t,n){const o=n?.center?.x??0,r=n?.center?.y??0;return{x:o+Math.sin(e)*t,y:r-Math.cos(e)*t}}function vr(e,t,n){return(Math.atan2(e-(n?.center?.x??0),-(t-(n?.center?.y??0)))+wr)%wr}function kr(e,t){const[n,o]=e,r=o-n||1,i=t?.startAngle??0,a=t?.endAngle??wr;return e=>i+(e-n)/r*(a-i)}function $r(e,t){const[n,o]=e,[r,i]=t,a=o-n||1;return e=>r+(e-n)/a*(i-r)}function Ar(e,t,n,o,r){const i=r?.center,a=(e,t)=>{const{x:n,y:o}=Mr(e,t,{center:i});return`${Sr(n)},${Sr(o)}`},s=Math.max(0,n),c=Math.max(s,o),l=Math.abs(t-e),u=e>t?0:1;if(l>=wr-1e-6){const e=i?.x??0,t=i?.y??0,n=`${Sr(e)},${Sr(t-c)}`,o=`${Sr(e)},${Sr(t+c)}`;let r=`M${n} A${Sr(c)},${Sr(c)} 0 1 1 ${o} A${Sr(c)},${Sr(c)} 0 1 1 ${n} Z`;if(s>0){const n=`${Sr(e)},${Sr(t-s)}`,o=`${Sr(e)},${Sr(t+s)}`;r+=` M${n} A${Sr(s)},${Sr(s)} 0 1 0 ${o} A${Sr(s)},${Sr(s)} 0 1 0 ${n} Z`}return r}const d=l>Math.PI?1:0,h=a(e,c),f=a(t,c);if(0>=s){const e=i?.x??0,t=i?.y??0;return`M${Sr(e)},${Sr(t)} L${h} A${Sr(c)},${Sr(c)} 0 ${d} ${u} ${f} Z`}const m=a(t,s),p=a(e,s);return`M${h} A${Sr(c)},${Sr(c)} 0 ${d} ${u} ${f} L${m} A${Sr(s)},${Sr(s)} 0 ${d} ${1===u?0:1} ${p} Z`}function Sr(e){return Math.round(1e3*e)/1e3}function Ir(e,t){return{x:e.x+t.x,y:e.y+t.y}}function Cr(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Nr(e,t){return{x:e.x*t,y:e.y*t}}function Fr(e){return Math.hypot(e.x,e.y)}function zr(e){const t=Fr(e)||1;return{x:e.x/t,y:e.y/t}}import{jsx as Wr,jsxs as jr}from"react/jsx-runtime";var Lr="var(--semiotic-text, currentColor)";function Rr(e,t){const n=j(e,100);return n>0?t/n*100*(t/n):Math.PI*t*t}function Or(e){const t=[],n=e.colorMap?Object.entries(e.colorMap):e.keys?e.keys.map(t=>[t,e.color?e.color(t):void 0]):[];if(n.length>0){const o=e.colorType??"fill",r=n.map(([e,t])=>({label:e,color:t}));t.push({type:o,label:e.colorLabel??"",items:r,styleFn:"line"===o?e=>({stroke:e.color??Lr,strokeWidth:2,fill:"none"}):e=>({fill:e.color??Lr,stroke:e.color??Lr})})}if(e.symbolMap&&Object.keys(e.symbolMap).length>0){const n=e.symbolColor??Lr,o=Object.entries(e.symbolMap).map(([e,t])=>({label:e,shape:t,color:n}));t.push({label:e.symbolLabel??"",items:o,styleFn:()=>({}),type:e=>{const t=e.shape;return Wr("path",{d:L(t,Rr(t,7)),transform:"translate(8,8)",fill:e.color??n})}})}if(e.sizeStops&&e.sizeStops.length>0&&e.sizeRadius){const n=e.sizeRadius,o=e.sizeFormat??(e=>e+""),r=e.sizeColor??Lr,i=e.sizeStops.map(e=>({label:o(e),r:Math.max(.5,n(e)),color:r}));t.push({label:e.sizeLabel??"",items:i,styleFn:()=>({}),type:e=>Wr("circle",{cx:8,cy:8,r:e.r,fill:e.color??r})})}return t}function Er(e){const t=e.orientation??"vertical",n=e.swatchSize??14,o=e.gap??8,r=e.labelGap??6,i=e.fontSize??12,a=e.color??"var(--semiotic-text-secondary, #888)",s=n+o;let c=0;const l=[];return e.entries.forEach((e,u)=>{l.push(jr("g",{transform:`translate(${"vertical"===t?0:c},${"vertical"===t?c:0})`,children:[Pr(e,n,e.color??e.line??a,a),Wr("text",{x:n+r,y:n/2,dominantBaseline:"middle",fontSize:i,fill:a,children:e.label})]},"legend-"+u)),c+="vertical"===t?s:n+r+e.label.length*i*.58+o+8}),Wr("g",{className:e.className,transform:`translate(${e.x},${e.y})`,style:{pointerEvents:"none"},children:l},e.keyId)}function Pr(e,t,n,o){if(e.shape){const o=Rr(e.shape,t/2-1);return Wr("path",{d:L(e.shape,o),transform:`translate(${t/2},${t/2})`,fill:n})}if(e.hatch){const n=e.color??o;return jr("g",{children:[Wr("svg",{width:t,height:t,style:{overflow:"hidden"},children:[-t,-t/2,0,t/2].map((e,o)=>Wr("line",{x1:e,y1:t,x2:e+t,y2:0,stroke:n,strokeWidth:1,opacity:.7},o))}),Wr("rect",{width:t,height:t,fill:"none",stroke:n,strokeWidth:1,opacity:.5,rx:2})]})}return Wr("rect",e.line?{y:t/2-1.5,width:t,height:3,rx:1.5,fill:e.line}:{width:t,height:t,rx:2,fill:n})}var Tr=new Set(["rows"]);function Dr(e){const t=e,n=[Hr(t,["datum","data"]),Hr(t,["datum"]),Hr(t,["data","data"]),Hr(t,["data"]),Hr(t,["node","datum","data"]),Hr(t,["node","datum"]),e];for(const e of n){if(!Gr(e))continue;const t={};for(const[n,o]of Object.entries(e))n.startsWith("_")||"function"==typeof o||(t[n]=o);if(Object.keys(t).length>0)return t}return null}function qr(e,t={}){const n=Dr(e);if(!n)return[];const o=new Set(Tr);if(t.excludeKeys)for(const e of t.excludeKeys)o.add(e);const r=[];for(const[e,i]of Object.entries(n))if((t.includeInternal||!e.startsWith("_"))&&!o.has(e)&&(t.includeEmpty||null!=i&&""!==i)&&"function"!=typeof i&&(r.push({key:e,label:Yr(e,t.labels),value:i,formatted:t.valueFormat?t.valueFormat(i,e,n):Br(i)}),r.length>=(t.maxEntries??8)))break;return r}function Br(e){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("number"==typeof e)return Number.isInteger(e)?e+"":e.toLocaleString(void 0,{maximumFractionDigits:2});if("boolean"==typeof e)return e?"true":"false";if(Array.isArray(e))return e.length+" items";if("object"==typeof e)try{return JSON.stringify(e)}catch{return e+""}return e+""}function Yr(e,t){if("function"==typeof t)return t(e);if(t&&Object.prototype.hasOwnProperty.call(t,e)){const n=t[e];if("string"==typeof n&&n.length>0)return n}return e}function Hr(e,t){let n=e;for(const e of t){if(!Gr(n))return;n=n[e]}return n}function Gr(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Xr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Vr(e,t){return Xr(e,t)?e[t]:void 0}function Kr(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function _r(){return Object.create(null)}function Ur(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target),n.get(e.target).add(e.source);return n}function Qr(e,t){const n={};for(const t of e)Kr(n,t.id,0);for(const e of t)Kr(n,e.source,(Vr(n,e.source)??0)+1),Kr(n,e.target,(Vr(n,e.target)??0)+1);return n}function Zr(e,t){const n={};Kr(n,t,0);const o=[t];let r=0;for(;o.length>r;){const t=o[r];r+=1;for(const r of e.get(t)||[])Xr(n,r)||(Kr(n,r,n[t]+1),o.push(r))}return n}function Jr(e,t,n,o){if(n===o)return n?[n]:[];const r=Ur(e,t),i=_r();i[n]=null;const a=[n];let s=0;for(;a.length>s;){const e=a[s];if(s+=1,e===o)break;for(const t of r.get(e)||[])Xr(i,t)||(i[t]=e,a.push(t))}if(!Xr(i,o))return[];const c=[];let l=o;for(;null!=l;)c.unshift(l),l=i[l];return c}function ei(e,t,n,o=1){const r=Ur(e,t);if(!r.has(n))return new Set;const i=Zr(r,n),a=new Set;for(const e of Object.keys(i))i[e]>o||a.add(e);return a}function ti(e,t){const n=Ur(e,t),o={};for(const t of e)Kr(o,t.id,0);for(const t of e.map(e=>e.id)){const r=[],i=_r(),a=_r(),s=_r();for(const t of e)i[t.id]=[],a[t.id]=0,s[t.id]=-1;a[t]=1,s[t]=0;const c=[t];let l=0;for(;c.length>l;){const e=c[l];l+=1,r.push(e);for(const t of n.get(e)||[])0>s[t]&&(s[t]=s[e]+1,c.push(t)),s[t]===s[e]+1&&(a[t]+=a[e],i[t].push(e))}const u=_r();for(const t of e)u[t.id]=0;for(;r.length;){const e=r.pop();for(const t of i[e])u[t]+=a[t]/a[e]*(1+u[e]);e!==t&&Kr(o,e,(Vr(o,e)??0)+u[e])}}for(const e of Object.keys(o))Kr(o,e,o[e]/2);return o}function ni(e,t){const n=Ur(e,t),o={};for(const t of e){const e=Zr(n,t.id);let r=0,i=0;for(const t of Object.keys(e))r+=e[t],i+=1;Kr(o,t.id,r>0?(i-1)/r:0)}return o}function oi(e,t){const n=Ur(e,t),o={};for(const t of e){const e=[...n.get(t.id)||[]],r=e.length;if(2>r){Kr(o,t.id,0);continue}let i=0;for(let t=0;e.length>t;t+=1)for(let o=t+1;e.length>o;o+=1)n.get(e[t])?.has(e[o])&&(i+=1);Kr(o,t.id,2*i/(r*(r-1)))}return o}function ri(e){let t=0;for(const n of Object.keys(e))e[n]>t&&(t=e[n]);const n={};for(const o of Object.keys(e))Kr(n,o,t>0?e[o]/t:0);return n}function ii(e,t,n,o={}){const r=Ur(e,t),i=_r();for(const t of e)i[t.id]=Zr(r,t.id);let a=o.minHops??4,s=o.startThreshold??.08;const c=o.maxThreshold??.2,l=new Set;let u=0;for(;0===l.size&&40>u;){for(let t=0;e.length>t;t+=1)for(let o=t+1;e.length>o;o+=1){const r=e[t].id,c=e[o].id,u=Vr(n,r),d=Vr(n,c);if(!u||!d)continue;const h=u.x-d.x,f=u.y-d.y;(void 0===i[r][c]?1/0:i[r][c])>=a&&s>Math.sqrt(h*h+f*f)&&(l.add(r),l.add(c))}0===l.size&&(s+=.02,s>c&&(s=o.startThreshold??.08,a=Math.max(2,a-1))),u+=1}return{problemIds:l,threshold:s,minHops:a}}function ai(e){if("undefined"!=typeof DOMException)return new DOMException(e+" aborted","AbortError");const t=Error(e+" aborted");return t.name="AbortError",t}function si(e){const t=Error(e.message);return t.name=e.name??"Error",e.stack&&(t.stack=e.stack),t}var ci=class{constructor(e){this.nextRequestId=1,this.pending=new Map,this.dead=!1,this.options=e,this.worker=e.createWorker(),this.worker.onmessage=e=>{const t=this.options.parseMessage(e.data),n=t.requestId,o=null!=n?this.pending.get(n):this.pending.values().next().value;if(o){if(null!=n)this.pending.delete(n);else{for(const e of this.pending.values())e!==o&&(e.cleanup(),e.reject(Error(this.options.name+" worker response missing requestId")));this.pending.clear()}o.cleanup(),t.ok?o.resolve(t.payload):o.reject(t.error)}},this.worker.onerror=e=>{this.rejectAll(Error(e.message||this.options.name+" worker failed")),this.terminate()}}get isDead(){return this.dead}request(e,t){if(this.dead)return Promise.reject(Error(this.options.name+" worker session is closed"));if(t?.aborted)return Promise.reject(ai(this.options.name));const n=this.nextRequestId;this.nextRequestId+=1;const o=this.options.encodeRequest?.(n,e)??{requestId:n,request:e};return new Promise((e,r)=>{const i=()=>{const e=1===this.pending.size;this.pending.delete(n),t?.removeEventListener("abort",i),r(ai(this.options.name)),this.options.terminateOnAbort&&e&&this.terminate()},a=()=>t?.removeEventListener("abort",i);this.pending.set(n,{cleanup:a,reject:r,resolve:e}),t?.addEventListener("abort",i,{once:!0});try{this.worker.postMessage(o)}catch(e){this.pending.delete(n),a(),r(e instanceof Error?e:Error(e+""))}})}terminate(){this.dead||(this.dead=!0,this.rejectAll(Error(this.options.name+" worker terminated")),this.worker.terminate())}rejectAll(e){for(const t of this.pending.values())t.cleanup(),t.reject(e);this.pending.clear()}};function li(){return"undefined"!=typeof window&&"undefined"!=typeof Worker}var ui=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./forceLayoutWorker.js",import.meta.url):function(e){if("undefined"!=typeof __filename){const t=__filename.replace(/\\/g,"/"),n=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+n)}throw Error("Cannot resolve module worker asset: "+e)}("forceLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-force-layout"})}()){this.session=new ci({name:"Force layout",createWorker:()=>e,terminateOnAbort:!0,parseMessage:e=>{const t=e,{requestId:n,error:o}=function(e){return e&&"object"==typeof e?{requestId:e.requestId,error:e.error}:{}}(t);return o?{requestId:n,ok:!1,error:si(o)}:{requestId:n,ok:!0,payload:{positions:t.positions??{}}}}})}get isDead(){return this.session.isDead}request(e,t){return this.session.request(e,t)}terminate(){this.session.terminate()}},di=function(){let e=null;return{get:()=>(e&&!e.isDead||(e=new ui),e),resetForTest:()=>{if(e){try{e.terminate()}catch{}e=null}}}}();async function hi(e,t,n={}){const{execution:o="auto",signal:r,workerThreshold:i,nodeRadius:a,...s}=n,c=s.iterations??260,l=li()&&function(e,t,n,o,r=4e4){return"sync"!==e&&("worker"===e||o*(t+n)>=r)}(o,e.length,t.length,c,i);if(!l)return H(e,t,{...s,nodeRadius:a});const u={kind:"normalized",nodes:e.map(e=>({...e})),edges:t.map(e=>({...e})),options:s,nodeRadii:"function"==typeof a?Object.fromEntries(e.map(e=>[e.id,a(e)])):null==a?void 0:Object.fromEntries(e.map(e=>[e.id,a]))};try{const e=await function(e,t){return li()?di.get().request(e,t):Promise.reject(Error("Web Workers are unavailable"))}(u,r);return e.positions}catch(n){if("AbortError"===n?.name)throw n;return H(e,t,{...s,nodeRadius:a})}}function fi(e,t,n){return Math.max(t,Math.min(n,e))}function mi(e,t,n={}){const o=n.random??Math.random,r=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],i=fi(n.along??.5,.05,.95),a=n.jitterX??0,s=n.padY??20,c=r.x0+(r.x1-r.x0)*i+(2*o()-1)*a,l=Math.min(1,r.width/2),u=fi(c,r.x0+l,r.x1-l),d=e.boundaryY(u,"top")+s,h=e.boundaryY(u,"bottom")-s;return{x:u,y:h>d?d+o()*Math.max(1,h-d):e.midY}}function pi(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}var yi=[.1,.5,.9],gi=1e6;function xi(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function bi(e,t,n,o,r){return"function"==typeof o?o(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;if(!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}(e,o??r)}function wi(e){const t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function Mi(e,t,n,o){const r=e.flatMap((e,r)=>{const i=xi(bi(e,r,t,n,"time")),a=xi(bi(e,r,t,o,"value"));return null==i||null==a?[]:[{time:wi(i),value:a,index:r}]});r.sort((e,t)=>e.time-t.time||e.index-t.index);const i=[];for(const e of r){const t=i[i.length-1];t?.time===e.time?t.value=e.value:i.push({time:e.time,value:e.value})}return i}function vi(e,t,n,o){if(!e.length)return null;const r=e[0],i=e[e.length-1];if(r.time>t)return"clamp"===o?r.value:null;if(t>i.time)return"clamp"===o?i.value:null;const a=function(e,t){let n=0,o=e.length;for(;o>n;){const r=n+o>>>1;t>e[r].time?n=r+1:o=r}return n}(e,t),s=e[a];if(s?.time===t)return s.value;const c=e[Math.max(0,a-1)];return"step"!==n&&s&&s.time!==c.time?c.value+(t-c.time)/(s.time-c.time)*(s.value-c.value):c.value}function ki(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,o=Math.floor(n),r=Math.ceil(n);return o===r?e[o]:e[o]+(e[r]-e[o])*(n-o)}function $i(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",o=function(e){const t=(e??yi).map(e=>{const t=xi(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return wi(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),r=function(e){if(Array.isArray(e)){if(e.length>gi)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(xi).filter(e=>null!=e).map(wi))).sort((e,t)=>e-t)}const t=e,n=xi(t.start),o=xi(t.end),r=xi(t.step);if(null==n||null==o||null==r||0>=r||n>o)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const i=Math.floor((o-n)/r)+1;if(i>gi)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");const a=[],s=1e-10*Math.max(1,Math.abs(o),Math.abs(n));for(let e=0;i>e;e+=1){const t=n+e*r;if(t>o+s)break;a.push(wi(Math.min(t,o)))}if(a.length&&s>=Math.abs(a[a.length-1]-o)||a.push(wi(o)),a.length>gi)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(a)).sort((e,t)=>e-t)}(e.sampleAt),i=e.runs.map(t=>Mi(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:r.map(e=>{const r=i.map(o=>vi(o,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),a={};for(const e of o)a[e]=r.length?ki(r,e):null;return{time:e,count:r.length,min:r.length?r[0]:null,max:r.length?r[r.length-1]:null,median:r.length?ki(r,.5):null,quantiles:a}}),quantiles:o,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function Ai(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function Si(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=xi(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const o=wi(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,o))throw Error(`comparePhysicsTrace could not find quantile ${o} in the reference envelope`);return e.quantiles[o]??null}function Ii(e,t,n){return t>e?"below":e>n?"above":"inside"}function Ci(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const o=e.value-e.lower,r=t.value-t.lower,i=e.value-e.upper,a=t.value-t.upper,s=[0,1];for(const[e,t]of[[o,r],[i,a]])(0>e&&t>0||e>0&&0>t)&&s.push(-e/(t-e));s.sort((e,t)=>e-t);let c=0,l=0,u=0;for(let o=0;s.length-1>o;o+=1){const r=s[o],i=s[o+1];if(r>=i)continue;const a=(r+i)/2,d=(i-r)*n,h=Ii(e.value+(t.value-e.value)*a,e.lower+(t.lower-e.lower)*a,e.upper+(t.upper-e.upper)*a);"below"===h?c+=d:"above"===h?u+=d:l+=d}return{below:c,inside:l,above:u,observed:n}}function Ni(e,t,n={}){const o=n.interpolation??t.interpolation,r=n.outsideDomain??t.outsideDomain,i=Mi(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),a=n.lower??Ai(t,"lower"),s=n.upper??Ai(t,"upper"),c=t.points.map(e=>{const t=vi(i,e.time,o,r),n=Si(e,a),c=Si(e,s);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":Ii(t,n,c)}});let l=0,u=0,d=0,h=0,f=null,m=0,p=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?u+=1:"above"===e.status&&(d+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,f=e.time),n>m&&(m=n,p=e.time)}let y=0,g=0,x=0,b=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],r=Math.max(0,n.time-t.time);if(r>0){if("linear"===o){const e=Ci(t,n);y+=e.below,g+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=r,"below"===t.status?y+=r:"above"===t.status?x+=r:g+=r)}}const w=c[0]?.time,M=c[c.length-1]?.time,v=null==w||null==M?0:Math.max(0,M-w);return{points:c,sampleCount:c.length,observedSamples:l+u+d,belowSamples:l,insideSamples:u,aboveSamples:d,totalDuration:v,observedDuration:b,unobservedDuration:Math.max(0,v-b),belowDuration:y,insideDuration:g,aboveDuration:x,peakExcess:h,peakExcessAt:f,peakDeficit:m,peakDeficitAt:p}}function Fi(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function zi(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function Wi(e){return!!zi(e)&&"string"==typeof e.id&&"number"==typeof e.furthestStageIndex&&Number.isFinite(e.furthestStageIndex)&&Array.isArray(e.visitedStageIds)&&e.visitedStageIds.every(e=>"string"==typeof e)&&zi(e.visitsByStage)&&zi(e.firstEnteredAt)&&zi(e.lastEnteredAt)&&"number"==typeof e.regressionCount&&Number.isFinite(e.regressionCount)}function ji(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function Li(e){const t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,ji(e)]))}}function Ri(e,t,n={}){if("region-enter"!==t.type)return e;const o=function(e,t){const n=t.stageId?.(e);if(n)return n;const o=e.region.metadata;if(o&&"object"==typeof o&&Object.prototype.hasOwnProperty.call(o,"stageId")){const e=o.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),r=e.stages.findIndex(e=>e.id===o);if(0>r)return e;const i=n.entityId?.(t)??t.bodyId;if(!i)return e;const a=Fi(e.entities,i),s=Wi(a)?a:ji(i),c=s.currentStageId?e.stages.findIndex(e=>e.id===s.currentStageId):-1,l=!s.visitedStageIds.includes(o),u=Number(t.observation.timestamp),d=Number.isFinite(u)?u:0,h=Fi(s.visitsByStage,o),f="number"==typeof h&&Number.isFinite(h)?h:0,m={...s,currentStageId:o,furthestStageId:r>s.furthestStageIndex?o:s.furthestStageId,furthestStageIndex:Math.max(s.furthestStageIndex,r),visitedStageIds:l?[...s.visitedStageIds,o]:s.visitedStageIds,visitsByStage:{...s.visitsByStage,[o]:f+1},firstEnteredAt:l?{...s.firstEnteredAt,[o]:d}:s.firstEnteredAt,lastEnteredAt:{...s.lastEnteredAt,[o]:d},regressionCount:c>=0&&c>r?s.regressionCount+1:s.regressionCount};return{...e,bodyIds:e.bodyIds.includes(i)?e.bodyIds:[...e.bodyIds,i],entities:{...e.entities,[i]:m}}}function Oi(e){const t=e.bodyIds.map(t=>{const n=Fi(e.entities,t);return Wi(n)?n:ji(t)}),n=t.length;let o=n;return e.stages.map((e,r)=>{const i=t.filter(e=>e.furthestStageIndex>=r).length,a=t.filter(t=>t.visitedStageIds.includes(e.id)).length,s=t.reduce((t,n)=>{const o=Fi(n.visitsByStage,e.id);return t+("number"==typeof o&&Number.isFinite(o)?o:0)},0),c={id:e.id,label:e.label??e.id,reached:i,entered:a,total:n,conversion:n>0?i/n:0,fromPrevious:o>0?i/o:0,dropoff:Math.max(0,o-i),visits:s,repeatVisits:Math.max(0,s-a)};return o=i,c})}function Ei(e,t){if("function"==typeof t){const n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}const n=e.datum;if(t&&n&&"object"==typeof n){const e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}const o=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(o)&&o>0?o:1}function Pi(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=E(e.datum,t),o=E(e,t),r=n??o;if(null!=r&&(r+"").length>0)return r+""}return e.id}function Ti(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];const n=Math.max(0,Math.min(1,t))*(e.length-1),o=Math.floor(n);return e[o]+(e[Math.ceil(n)]-e[o])*(n-o)}function Di(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),o=e.queueLayout??"lane",r=e.queueSlotSpacing??14,i=e.queueStiffness??.35,a=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,s=Math.max(.25,e.metricWindowSeconds??30),c=Math.max(1/60,e.snapshotIntervalSeconds??.25),l=e.releaseImpulse??{x:90,y:0},u=new Map,d=new Map,h=new Map,f=new Map,m=new Map,p=new Map,y=new Map,x=[];let b=0,w=new Map,M=new Map,v=0,k=0,$=0,A=null,S=0,I=0,C=0,N=0,F=0,z=0,W=0,j=0,L=0,R=0,O=0,E=0,P=-1,T=!1;function D(e,n){const o=n(e);return!!o&&o.activeRegionIds.includes(t)}function q(){E+=1}function B(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function Y(n,o,r,i){const a={bodyId:n.id,jobId:o.jobId,visitId:o.visitId,visit:o.visit,remaining:o.work,total:o.work,queuedAt:o.queuedAt,sequence:i};return u.set(o.jobId,a),y.delete(n.id),p.set(n.id,o.jobId),I+=1,C+=o.work,q(),function(n,o,r){const i=B(o);e.onQueued?.(n,i),r.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:o.total,jobId:o.jobId,visitId:o.visitId,visit:o.visit,queuedAt:o.queuedAt,queueDepth:u.size})}(n,a,r),a}function H(e){if(u.size>=a||0===d.size)return;const t=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);for(const n of t){if(u.size>=a)break;const t=m.get(n.jobId);t&&h.has(n.jobId)?(d.delete(n.jobId),y.delete(n.bodyId),Y(t,n,e,n.sequence)):d.delete(n.jobId)}}function G(){let e=0;for(const t of u.values())e+=t.remaining;return e}function X(){L=Math.max(L,u.size),R=Math.max(R,G())}function V(){const e=$-s,t=Math.max(0,Math.min(s,$-(A??$)));let o=0,r=0,i=0,a=0,c=0;for(const t of x){if(e>t.end)continue;o+=t.arrivals,r+=t.arrivalWork,i+=t.completions,a+=t.completedWork;const n=t.end-t.start;c+=n>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/n):t.processedWork}const l=t>0?r/t:0;return{seconds:t,arrivals:o,arrivalWork:r,completions:i,completedWork:a,processedWork:c,arrivalsPerSecond:t>0?o/t:0,throughputPerSecond:t>0?i/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,c/(n*t))):0,pressure:n>0?l/n:0}}return{id:e.id??"capacity-queue:"+t,continuous:!1!==e.continuous,tick:o=>{const r=o.controls.readBodies(),i=new Map,I=new Map;for(const t of r){if(i.set(t.id,t),!D(t.id,o.getRegionState))continue;if(!g(t,e.bodyFilter))continue;const n=Pi(t,e.jobKey),r=I.get(n)??[];r.push(t),I.set(n,r)}const C=Number.isFinite(o.dt)?Math.max(0,o.dt):0;if(!T){const e=Number.isFinite(o.elapsed)?Math.max(0,o.elapsed):C;$=Math.max(0,e-C),T=!0}const L=$,R=L+C;$=R,A=null==A?L:Math.min(A,L);const E={start:L,end:R,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},G=new Map;for(const[e,t]of I){const n=h.get(e)?.bodyId,o=t.find(e=>e.id===n)??t[0];G.set(e,o),m.set(e,o)}for(const[n,r]of h){if(G.has(n))continue;const a=u.get(n),s=i.get(r.bodyId)??m.get(n);if(a){u.delete(n),p.delete(a.bodyId),W+=1,j+=a.remaining,q();const i={...B(a),abandonedAt:$,remainingWork:a.remaining,queueSeconds:Math.max(0,$-a.queuedAt)};s&&e.onAbandoned?.(s,i),o.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:r.bodyId,datum:s?.datum,x:s?.x,y:s?.y,regionId:t,work:a.total,remainingWork:a.remaining,jobId:n,visitId:a.visitId,visit:a.visit,queuedAt:a.queuedAt,abandonedAt:$,queueSeconds:i.queueSeconds,queueDepth:u.size})}d.delete(n),y.delete(r.bodyId),h.delete(n),m.delete(n)}for(const[n,r]of G){if(h.has(n))continue;const i=(f.get(n)??0)+1;f.set(n,i);const s=Ei(r,e.unitAccessor),c={bodyId:r.id,jobId:n,visitId:`${t}:${n}:${i}`,visit:i,regionId:t,work:s,queuedAt:$};h.set(n,c),S+=1,E.arrivals+=1,E.arrivalWork+=s;const l=b++;if(a>u.size)Y(r,c,o,l);else{const a={...c,blockedAt:$,sequence:l};d.set(n,a),y.set(r.id,n),z+=1,q(),e.onBlocked?.(r,a),o.controls.recordObservation({type:"physics-capacity-blocked",bodyId:r.id,datum:r.datum,x:r.x,y:r.y,regionId:t,work:s,jobId:n,visitId:c.visitId,visit:i,queuedAt:$,blockedAt:$,queueDepth:u.size,blockedDepth:d.size})}}H(o),X();const V=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);let K=n*C;for(const n of V){if(0>=K)break;const r=Math.min(n.remaining,K);if(n.remaining-=r,K-=r,N+=r,E.processedWork+=r,n.remaining>1e-6)continue;u.delete(n.jobId),p.delete(n.bodyId),k+=1,F+=n.total,E.completions+=1,E.completedWork+=n.total;const a=Math.max(0,$-n.queuedAt);O+=a,q();const s=i.get(n.bodyId);if(!s)continue;o.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...B(n),completedAt:$,queueSeconds:a};e.onProcessed?.(s,c),o.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:s.datum,x:s.x,y:s.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:$,queueSeconds:a,queueDepth:u.size})}H(o),X(),function(){const e=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);w=new Map(e.map((e,t)=>[e.bodyId,t]));const t=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);M=new Map(t.map((e,t)=>[e.bodyId,t])),v=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&x.push(e);const t=$-s;for(;x.length>0&&t>x[0].end;)x.shift()}(E);const _=Math.floor($/c);_!==P&&(P=_,q())},getSnapshot:()=>{const e=G(),o=function(){let e=0;for(const t of d.values())e+=t.work;return e}(),r=u.size,i=Array.from(u.values()).map(e=>Math.max(0,$-e.queuedAt)).sort((e,t)=>e-t),a=i.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:r,processedCount:k,unitsPerSecond:n,remainingWork:e,meanRemainingWork:r>0?e/r:0,waitingWork:e+o,blockedDepth:d.size,blockedWork:o,arrivalCount:S,admittedCount:I,admittedWork:C,processedWork:N,completedWork:F,blockedCount:z,abandonedCount:W,abandonedWork:j,peakQueueDepth:L,peakRemainingWork:R,queueAge:{count:i.length,meanSeconds:i.length>0?a/i.length:0,p50Seconds:Ti(i,.5),p95Seconds:Ti(i,.95),oldestSeconds:i.at(-1)??0},meanCompletedQueueSeconds:k>0?O/k:0,window:V(),simulatedAt:$,metricRevision:E}},bodyForce:e=>{if("none"===o)return null;const n=p.get(e.body.id),a=y.get(e.body.id),s=n?u.get(n):void 0,c=a?d.get(a):void 0;if(!s&&!c)return null;const l=s?w.get(e.body.id):M.get(e.body.id);if(null==l)return null;let h;const f=e.regions;if(f)for(let e=0;f.length>e;e+=1)if(f[e].id===t){const t=f[e].shape;t&&"aabb"===t.type&&(h=t);break}return h?{x:((c?h.x-.44*h.width:h.x-.22*h.width-l*(.15*r))-e.body.x)*i,y:(h.y-(l-((c?d.size:v)-1)/2)*r/Math.max(1,Math.sqrt(c?d.size:v))-e.body.y)*i*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function qi(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function Bi(e){if(!e?.length)return null;const t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,o)=>{const r={result:e,controls:n,dt:o.dt,elapsed:o.elapsed,getRegionState:o.getRegionState};for(const e of t)e.tick(r)},bodyForce:e=>{let n=null;for(const o of t)o.bodyForce&&(n=qi(n,o.bodyForce(e)));return n}}}function Yi(e){const t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:o=>{const r=o.controls.readBodies();for(const i of r){const r=o.getRegionState(i.id),a=r?.activeRegionIds.includes(e.fromRegionId);a?t.has(i.id)||(t.add(i.id),o.controls.applyImpulse(i.id,n.x??0,n.y??0),e.onPortal?.(i)):t.delete(i.id)}}}}function Hi(e){const t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),o=new Map,r=new Map,i=e.assignmentForce??.45,a=e.returnForce??.35,s=e.caseAttraction??.08,c=e.assignmentOffset??{x:0,y:0};let l=new Map,u=0,d=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{const n=o.get(e);if(n)return n;const i=t.find(e=>!r.has(e.id));if(!i)return null;const a={resourceId:i.id,resourceBodyId:i.bodyId,caseBodyId:e,assignedAt:u};return o.set(e,a),r.set(i.id,a),d+=1,a},release:e=>{const t=o.get(e);return!!t&&(o.delete(e),r.delete(t.resourceId),d+=1,!0)},getAssignment:e=>o.get(e),tick:e=>{u=Math.max(u,e.elapsed),l=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(const[e,t]of o)l.has(e)&&l.has(t.resourceBodyId)||(o.delete(e),r.delete(t.resourceId),d+=1)},getSnapshot:()=>({total:t.length,available:t.length-r.size,assigned:r.size,assignments:Array.from(o.values()),simulatedAt:u,metricRevision:d}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=r.get(t.id),o=n?l.get(n.caseBodyId):void 0,s=n?i:a;return{x:((o?o.x+(c.x??0):t.home.x)-e.body.x)*s,y:((o?o.y+(c.y??0):t.home.y)-e.body.y)*s}}const u=o.get(e.body.id);if(!u||0>=s)return null;const d=l.get(u.resourceBodyId);return d?{x:(d.x-e.body.x)*s,y:(d.y-e.body.y)*s}:null}}}function Gi(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):E(e.datum,t.deadlineAccessor)??E(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function Xi(e){const t=new Map;let n=0,o=0;function r(n){t.set(n.bodyId,n),o+=1,e.onStateChange?.({...n})}function i(e){const o=t.get(e);return!(!o||null!=o.completedAt||(r({...o,completedAt:n,state:"unhappy"===o.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{const o=t.get(e);return!(!o||null!=o.completedAt||"unhappy"===o.state||(r({...o,state:"protected",protectedAt:n}),0))},complete:i,getCase:e=>t.get(e),tick:o=>{n=Math.max(n,o.elapsed);for(const a of o.controls.readBodies()){if(!g(a,e.bodyFilter))continue;if(!t.has(a.id)){const t=Gi(a,e);r({bodyId:a.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}const s=t.get(a.id);s&&null==s.completedAt&&(e.completionRegionId&&o.getRegionState(a.id)?.activeRegionIds.includes(e.completionRegionId)?i(a.id):"waiting"!==s.state||s.deadlineAt>n||r({...s,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),r=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:r("waiting"),protected:r("protected"),unhappy:r("unhappy"),resolved:r("resolved"),resolvedUnhappy:r("resolved-unhappy"),simulatedAt:n,metricRevision:o}}}}function Vi(e){const t=new Set;let n=0,o=0,r=0,i=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:a=>{n=Math.max(n,a.elapsed);const s=i;var c;c=n,i=e.isOpen?e.isOpen(c):null!=e.opensAt&&c>=e.opensAt;const l=a.controls.readBodies(),u=new Map(l.map(e=>[e.id,e]));for(const n of l){const o=a.getRegionState(n.id)?.activeRegionIds.includes(e.regionId);o&&g(n,e.bodyFilter)&&(i||t.has(n.id)||(t.add(n.id),r+=1,e.onHeld?.(n)))}if(i&&!s){for(const n of t){const t=u.get(n);t&&(a.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),o+=1,e.onReleased?.(t))}t.clear(),r+=1}for(const e of t)u.has(e)||(t.delete(e),r+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:i,blocked:t.size,released:o,simulatedAt:n,metricRevision:r}),bodyForce:n=>{if(i||!t.has(n.body.id))return null;const o=n.regions?.find(t=>t.id===e.regionId),r=o?.shape;if(!r||"aabb"!==r.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const a=e.holdForce??.4;return{x:(r.x-n.body.x)*a-.45*n.body.vx,y:(r.y-n.body.y)*a-.45*n.body.vy}}}}function Ki(e){const[t,n]=e.size,o=e.flow??"down",r=null==(M=e.padding)?{top:24,right:24,bottom:24,left:24}:"number"==typeof M?{top:M,right:M,bottom:M,left:M}:{top:M.top??0,right:M.right??0,bottom:M.bottom??0,left:M.left??0},i=Math.max(.05,Math.min(1,e.channelRatio??1)),a={x:r.left,y:r.top,width:Math.max(1,t-r.left-r.right),height:Math.max(1,n-r.top-r.bottom)},s="down"===o?a.height:a.width,c=s*Math.max(0,e.chargeExtent??.12),l=s*Math.max(0,e.projectionExtent??0),u=s*Math.max(0,e.destinationExtent??.55),d=Math.max(0,s-c-u-l),h=function(e){return"number"==typeof e?Array.from({length:Math.max(1,Math.round(e))},(e,t)=>({id:"bin-"+t,label:t+""})):0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??t+""}))}(e.destinations),f=("down"===o?a.width:a.height)/h.length,m="down"===o?(e,t)=>({x:a.x,y:a.y+e,width:a.width,height:t}):(e,t)=>({x:a.x+e,y:a.y,width:t,height:a.height}),p=m(0,c),y=m(c,d),g=c+d,x=m(g,u),b=m(g+u,l),w=h.map((e,t)=>{const n=t*f,r=f*i,s=(f-r)/2;return"down"===o?{id:e.id,label:e.label,order:t,x:a.x+n+s,y:x.y,width:r,height:x.height,centerX:a.x+(t+.5)*f,centerY:x.y+x.height/2}:{id:e.id,label:e.label,order:t,x:x.x,y:a.y+n+s,width:x.width,height:r,centerX:x.x+x.width/2,centerY:a.y+(t+.5)*f}});var M;return{width:t,height:n,flow:o,charge:p,apparatus:y,destinations:w,projection:b}}function _i(e,t){return e.destinations.find(e=>e.id===t)}function Ui(e,t,n){const{charge:o,flow:r}=e,i=Math.max(1,n),a=(t%i+.5)/i;return"down"===r?{x:o.x+o.width*a,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height*a}}function Qi(e,t={}){const n=t.thickness??4,o=t.idPrefix??"stage",{destinations:r,flow:i,width:a,height:s}=e,c=[];if(r.length>0){const t=r[0];if("down"===i){const i=t.y+t.height;c.push({id:o+"-floor",shape:{type:"segment",x1:e.charge.x,y1:i,x2:e.charge.x+e.charge.width,y2:i,thickness:n}});for(let e=1;r.length>e;e+=1){const a=r[e].centerX-(r[e].centerX-r[e-1].centerX)/2;c.push({id:`${o}-divider-${e}`,shape:{type:"segment",x1:a,y1:t.y,x2:a,y2:i,thickness:n}})}}else{const i=t.x+t.width;c.push({id:o+"-floor",shape:{type:"segment",x1:i,y1:e.charge.y,x2:i,y2:e.charge.y+e.charge.height,thickness:n}});for(let e=1;r.length>e;e+=1){const a=r[e].centerY-(r[e].centerY-r[e-1].centerY)/2;c.push({id:`${o}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:a,x2:i,y2:a,thickness:n}})}}}return!1!==t.walls&&c.push({id:o+"-wall-left",shape:{type:"segment",x1:1,y1:0,x2:1,y2:s,thickness:n}},{id:o+"-wall-right",shape:{type:"segment",x1:a-1,y1:0,x2:a-1,y2:s,thickness:n}}),c}function Zi(e,t={}){return`${t.charge??"bodies"} enter at the ${"down"===e.flow?"top":"left"}, travel ${"down"===e.flow?"downward":"left to right"} through ${t.apparatus??"the apparatus"}, and come to rest in ${e.destinations.length} ${t.destination??"destinations"}: ${e.destinations.map(e=>e.label).join(", ")}.`}function Ji(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function ea(e,t,n,o){const r="function"==typeof e?e(t,n):e;return Number.isFinite(r)?Number(r):o}function ta(e,t,n){return Ji(e[t])??n}function na(e,t){return"number"==typeof e?e:e?.[t]??0}function oa(e){const{band:t,idPrefix:n,plot:o,projection:r}=e,{includeBoundaryWalls:i=!0,includeInteriorWalls:a=!0,wallThickness:s=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const o of e.values){const r=e.scale(o);Number.isFinite(r)&&(n.add(Number(r)),n.add(Number(r)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=i?c.length-1:c.length-2,u=[];for(let e=i?0:1;l>=e;e+=1){if(!a&&e>0&&c.length-1>e)continue;const t=c[e];u.push({id:`${n}-wall-${e}`,shape:"x"===r?{type:"aabb",x:t,y:o.y+o.height/2,width:s,height:o.height}:{type:"aabb",x:o.x+o.width/2,y:t,width:o.width,height:s}})}return u}function ra(e){const{plot:t,idPrefix:n="physics-scale",bounds:o={},xBins:r,xBands:i,yBands:a}=e,s=[];if(!1!==o&&s.push(...l(t,{idPrefix:n,...o})),r){const{idPrefix:e,yTop:o,yBottom:i,...a}=r;s.push(...u({...a,idPrefix:e??n+"-xbin",yTop:o??t.y,yBottom:i??t.y+t.height}))}return i&&s.push(...oa({band:i,idPrefix:i.idPrefix??n+"-xband",plot:t,projection:"x"})),a&&s.push(...oa({band:a,idPrefix:a.idPrefix??n+"-yband",plot:t,projection:"y"})),s}function ia(e){const{plot:t,rows:n,columns:o=n+1,pegRadius:r=3,idPrefix:i="galton-peg",yStart:a=t.y+.18*t.height,yEnd:s=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:u=.04}=e,d=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(o));if(0===d)return[];const f=d>1?(s-a)/(d-1):0,m=t.width/h,p=[];for(let e=0;d>e;e+=1){const n=c&&e%2==1?m/2:0;for(let o=0;h>o;o+=1){const s=t.x+m*(o+.5)+n;t.x+r>s||s>t.x+t.width-r||p.push({id:`${i}-${e}-${o}`,shape:{type:"aabb",x:s,y:a+e*f,width:2*r,height:2*r},restitution:l,friction:u})}}return p}function aa(e,t={}){const{idPrefix:n="physics-token",radius:o=5,shape:r,mass:i,vx:a,vy:s,spawnAt:c,seed:l=1,jitter:u,datum:d}=t,h=me(l),f=na(u,"x"),m=na(u,"y");return e.map((e,l)=>{const u=ea(t.x,e,l,ta(e,"x",0)),p=ea(t.y,e,l,ta(e,"y",0)),y=ea(o,e,l,5),g="function"==typeof r?r(e,l):r??{type:"circle",radius:y};return{id:`${n}-${e.index??l}`,x:u+(h()-.5)*f,y:p+(h()-.5)*m,vx:ea(a,e,l,0),vy:ea(s,e,l,0),mass:ea(i,e,l,1),spawnAt:ea(c,e,l,void 0),shape:g,datum:d?d(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function sa(e,t={}){const{idPrefix:n="sediment",collider:o=!0,colliderThickness:r=1,restitution:i=.05,friction:a=.2,...s}=t,c=W(e,s),l=o?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+r/2,width:e.width,height:r},restitution:i,friction:a})):[];return{columns:c,colliders:l}}function ca(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:o=1,startAt:r=0,rebase:i=!0,sort:a=!0}=t,s=e.map((e,t)=>({spawn:e,time:function(e,t,n){return Ji("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=s.length?Math.min(...s.map(e=>e.time)):0;return{initialSpawns:s.map(({spawn:e,time:t})=>({...e,spawnAt:r+(i?t-c:t)})).sort((e,t)=>a?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:r,timeAccessor:"spawnAt",timeScale:o}}}function la(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function ua(e,t,n="group"){const o=Qr(e,t),r=e=>"function"==typeof n?n(e):e[n]??0;return e.slice().sort((e,t)=>{const n=r(e),i=r(t);return i>n?-1:n>i?1:(o[t.id]||0)-(o[e.id]||0)}).map(e=>e.id)}function da(e,t={}){const n=t.baseline??.62,o=t.inset??.06,r={},i=e.length;return e.forEach((e,t)=>{la(r,e,{x:i>1?o+t/(i-1)*(1-2*o):.5,y:n})}),r}function ha(e,t,n=.55){return`M${e.x},${e.y} Q${(e.x+t.x)/2},${e.y-Math.abs(t.x-e.x)*n} ${t.x},${t.y}`}function fa(e,t={}){const n=t.radius??.42,o=t.center?.x??.5,r=t.center?.y??.5,i=t.startAngle??0,a={},s=e.length;return e.forEach((e,t)=>{const c=i+t/s*Math.PI*2-Math.PI/2;la(a,e,{x:o+Math.cos(c)*n,y:r+Math.sin(c)*n})}),a}function ma(e,t,n={}){const o=(n.order??ua(e,t,n.groupAccessor??"group")).slice(),r=new Map(o.map((e,t)=>[e,t])),i=new Map;for(const e of t){if(!r.has(e.source)||!r.has(e.target)||e.source===e.target)continue;const t=e.target>e.source?`${e.source}\0${e.target}`:`${e.target}\0${e.source}`;i.set(t,(i.get(t)||0)+(e.value??1))}const a=[];let s=0;for(const[e,t]of i){const[n,o]=e.split("\0"),i=r.get(n),c=r.get(o);t>s&&(s=t),a.push({row:i,col:c,source:n,target:o,value:t}),a.push({row:c,col:i,source:o,target:n,value:t})}return{order:o,cells:a,size:o.length,maxValue:s}}function pa(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function ya(e){if("string"!=typeof e)return;const t=e.trim();return t.length?t:void 0}function ga(e,t){const n=pa(e.note)?e.note:void 0;return t?ya(e.mobileText)||ya(e.shortText)||ya(e.label)||ya(n?.mobileText)||ya(n?.shortText)||ya(n?.label)||ya(n?.title):ya(e.label)||ya(e.mobileText)||ya(e.shortText)||ya(n?.label)||ya(n?.title)}function xa(e,t,n){const o=function(e,t,n){if(!n)return;const o="function"==typeof n?n(e,t):e[n];return"number"==typeof o&&Number.isFinite(o)?o:void 0}(e,t,n.priorityAccessor);if(void 0!==o)return o;let r=1e3-t;const i=((e.emphasis??"")+"").toLowerCase();"primary"!==i&&"critical"!==i||(r+=1e4),"secondary"===i&&(r-=1e3),"high"===e.priority&&(r+=5e3),"low"===e.priority&&(r-=1500),"number"==typeof e.priority&&(r+=100*e.priority);const a=pa(e.provenance)?e.provenance:void 0;"number"==typeof a?.confidence&&(r+=100*a.confidence);const s=pa(e.lifecycle)?e.lifecycle:void 0,c=((s?.freshness??"")+"").toLowerCase();return"expired"!==c&&"stale"!==c||(r-=3e3),r}function ba(e,t){if(!t)return e;const n=ga(e,!0);return n&&"string"==typeof e.label?{...e,label:n}:e}function wa(e,t={}){const n=Array.isArray(e)?e.filter(pa):[],o=t.active??(null==t.width||(t.breakpoint??480)>=t.width),r=t.strategy??"hybrid",i=!1!==t.preferShortText,a=!1!==t.preservePrimary,s=Math.max(0,t.maxPlotAnnotations??t.maxAnnotations??("callout-list"===r?1:2)),c=Math.max(0,t.minPlotAnnotations??t.minVisible??1);if(!o||"plot"===r)return{active:o,strategy:r,budget:n.length,visible:i?n.map(e=>ba(e,i)):n,deferred:[],calloutList:[],hidden:[]};const l=[],u=n.map((e,n)=>({annotation:e,index:n,priority:xa(e,n,t)})).filter(e=>!!fe(e.annotation)||(l.push(e.annotation),!1)).sort((e,t)=>t.priority-e.priority),d=a?u.filter(e=>"primary"===((e.annotation.emphasis??"")+"").toLowerCase()):[],h=new Set(d.map(e=>e.index)),f=u.filter(e=>!h.has(e.index)),m=[...d,...f].slice(0,Math.max(s,c)),p=new Set(m.map(e=>e.index)),y=u.filter(e=>!p.has(e.index)),g=[...l,...m.sort((e,t)=>e.index-t.index).map(e=>ba(e.annotation,i))],x=y.sort((e,t)=>e.index-t.index).map(e=>e.annotation),b=Math.max(0,t.maxCalloutItems??6),w=y.filter(e=>!t.calloutFilter||t.calloutFilter(e.annotation,e.index)).map(e=>function(e,t,n,o){const r=ga(e,o);if(!r)return null;const i=ya(e.id)||ya(e.key)||ya(e.pointId)||"annotation-"+(t+1),a=pa(e.provenance)?ya(e.provenance.source)||ya(e.provenance.authorKind):void 0;return{id:i,label:r,shortLabel:ya(e.shortText),pointId:e.pointId,emphasis:"string"==typeof e.emphasis?e.emphasis:void 0,source:a,priority:n,annotation:e}}(e.annotation,e.index,e.priority,i)).filter(e=>!!e).slice(0,b),M=new Set(w.map(e=>e.annotation)),v=x.filter(e=>!M.has(e));return{active:o,strategy:r,budget:s,visible:g,deferred:x,calloutList:w,hidden:v}}function Ma(e){return"dense"===e.density?.75:"compact"===e.density?.9:1}function va(e,t){const n=!1!==t.keepAxes,o=!1===t.directLabel?12:28;return"ordinal"===e?{top:12,right:o,bottom:n?44:12,left:n?48:12}:"geo"===e||"network"===e?{top:12,right:12,bottom:12,left:12}:{top:12,right:o,bottom:n?42:14,left:n?44:14}}function ka(e,t,n,o={}){const r={...n},i={mode:!1===t.mode?void 0:"mobile",...r,margin:va(e,t),...o},a=Object.fromEntries(Object.entries(r).filter(([,e])=>void 0!==e)),s=Object.fromEntries(Object.entries(i).filter(([,e])=>void 0!==e)),c=function(e,t){const n=t.targetSize??44,o=[],r=t.standardControls,i=e=>!0===r||"all"===r||r===e||Array.isArray(r)&&r.includes(e);return i("brush")&&o.push("range-inputs","clear-brush"),i("zoom")&&o.push("zoom-buttons","reset-view"),i("legend")&&o.push("legend-chips","show-all-series"),{strategy:`${e}-${t.transformProfile??"overview"}-mobile-recipe`,supportsResponsiveLayout:!0,breakpoints:[320,360,390,430,t.breakpoint??480,768],maxAnnotations:t.maxAnnotations??2,minimumHitTarget:n,summary:t.summary??!0,interaction:{primary:"tap",hoverFallback:"tap-to-lock",targetSize:n,...o.length>0&&{alternatives:o}},labels:{strategy:!1===t.directLabel?"compact":"direct",minFontSize:12}}}(e,t),l=function(e){return{tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:e.targetSize??44,snap:e.snap??"nearestDatum",brushHandleSize:e.targetSize??44,standardControls:e.standardControls??!1}}(t);return{family:e,props:a,responsiveRules:[{id:e+"-mobile",description:`Apply Semiotic's mobile ${e} recipe at phone width.`,when:{maxWidth:t.breakpoint??480},transform:{...s,mobileInteraction:l,mobileSemantics:c}}],mobileInteraction:l,mobileSemantics:c}}function $a(e={}){const t=Ma(e);return ka("line",e,{showLegend:e.showLegend??!1,directLabel:e.directLabel??!0,lineWidth:"inspect"===e.transformProfile?3:Math.max(1.5,2.5*t),showPoints:"inspect"===e.transformProfile,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function Aa(e={}){const t=Ma(e);return ka("area",e,{showLegend:e.showLegend??!1,showPoints:!1,areaOpacity:"compare"===e.transformProfile?.55:.42,lineWidth:Math.max(1.25,2*t),autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function Sa(e={}){return ka("ordinal",e,{showLegend:e.showLegend??!1,showCategoryTicks:e.keepAxes??!0,sort:"compare"===e.transformProfile?"desc":void 0},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function Ia(e={}){const t=Ma(e);return ka("scatter",e,{showLegend:e.showLegend??!1,pointRadius:Math.max(4,Math.round((e.targetSize??44)/8*t)),hoverRadius:Math.ceil((e.targetSize??44)/2),pointOpacity:"dense"===e.density?.42:.68,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??1,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function Ca(e={}){const t=Ma(e);return ka("network",e,{showLegend:e.showLegend??!1,nodeSizeRange:[Math.max(4,Math.round(6*t)),Math.max(12,Math.round((e.targetSize??44)/2*t))],showLabels:"inspect"===e.transformProfile,edgeOpacity:"dense"===e.density?.28:.44})}function Na(e={}){return ka("geo",e,{showLegend:e.showLegend??!1})}function Fa(e={}){return ka("small-multiple",e,{mobileColumns:e.mobileColumns??1,tabletColumns:e.tabletColumns??2,chartHeight:e.chartHeight??180,sharedExtent:!0})}function za(e,t={}){switch(e){case"line":return $a(t);case"area":return Aa(t);case"ordinal":return Sa(t);case"scatter":return Ia(t);case"network":return Ca(t);case"geo":return Na(t);case"small-multiple":return Fa(t)}}function Wa(e={}){const t=e.controls??["range-inputs","chip-filter","clear"];return{mobileInteraction:{enabled:!0,targetSize:e.targetSize??44,tapToSelect:!0,tapToLockTooltip:!0,standardControls:"brush"},mobileSemantics:{interaction:{primary:"filter",alternatives:t,summary:e.summary??"Expose brushable ranges through touch-sized controls in addition to drag gestures."}},controls:t}}export{ue as DEFAULT_AREA_PER_ANNOTATION,e as DEFAULT_GLYPH_ANCHOR,t as DEFAULT_GLYPH_VIEWBOX,Qo as DEFAULT_HIT_RADIUS,Ve as DEFAULT_ISOMETRIC_SPRITE_SIZES,io as GRID_FUEL_KEYS,ao as GRID_FUEL_LABELS,P as LayoutCache,n as SYMBOL_SEQUENCE,wr as TAU,o as absorbRegion,$o as activeCountOverDomain,Ir as addPoints,ma as adjacencyMatrix,r as aggregateRegionCounts,ye as allocateCells,bn as analyzeNetEnsemble,kr as angleScale,de as annotationBudget,he as annotationDensity,i as annotationLayout,da as arcLayout,ha as arcPath,ca as arrivalReplay,Po as axisFixedForceLayout,Eo as axisFixedForcePositions,xe as balanceSnapshotsToFlows,fn as bandLabel,ti as betweenness,Zr as bfsDistances,ro as bobaLayout,a as bodyGroupSpec,dn as boundsOf,No as boxEdgeAnchors,Ur as buildAdjacency,qr as buildTooltipEntries,Bn as bulletLayout,Be as calendarLayout,s as capacitatedRegion,c as chargeGateRegion,fa as circularLayout,T as clamp,ni as closeness,oi as clustering,ra as collidersFromScales,Ni as comparePhysicsTrace,Bi as composePhysicsControllers,d as countPairwiseCrossings,Di as createCapacityQueueController,Vi as createDependencyGateController,Yi as createPortalController,Li as createProcessJourneyLedger,Xi as createServiceLevelController,Hi as createServiceResourcePoolController,jo as cubicPath,zo as cubicPoint,Wo as cubicTangent,Io as curvedEdgePath,lr as cyclicRangeContains,Kt as dagreLayout,Qr as degree,uo as demandForecastRows,Zi as describePhysicsStageGeography,B as diagnoseTokenEncoding,Y as dimFor,ei as egoNetwork,fr as estimateLabelWidth,Dr as extractTooltipDatum,Fo as fanOutBend,Vt as flextreeLayout,h as forceFieldRegion,H as forceLayout,hi as forceLayoutAsync,bo as formatMw,wo as formatReservePct,Br as formatTooltipValue,ia as galtonPegs,G as generateTokens,tr as geoAreaHitTarget,er as geoHitTarget,Xt as geographicDotGridLayout,Mt as geographicGridLayout,f as glyphExtent,m as glyphFractionClipRect,p as glyphPlacement,go as gridEventAnnotations,xt as gridifyGeographicPoints,X as groupBy,y as groupCompletionRows,mn as hatchFill,Jo as hitTargetPoint,nr as hitTargetRect,hn as hullFromBoxes,So as intervalLanesLayout,st as isometricLandmarkLayout,$e as isotypeBoltGlyph,Ae as isotypeBusGlyph,ke as isotypeChipGlyph,Me as isotypeGhost,be as isotypeInk,Ce as isotypeNetworkGlyphs,we as isotypePaper,Ie as isotypePersonGlyph,Se as isotypePersonPath,ve as isotypeServerGlyph,hr as layoutChipStrip,dr as layoutSequence,V as layoutTokenGrid,Or as legendGroupsFrom,Er as legendSwatches,en as lineageDagLayout,pn as linearAxis,K as makeShade,Tn as marimekkoLayout,yn as markCallout,_ as matchesHighlight,U as mean,x as membraneRegion,sn as mermaidDagLayout,wa as mobileAnnotationStrategy,Aa as mobileAreaChartRecipe,Wa as mobileBrushAlternatives,za as mobileChartFamilyRecipe,Na as mobileGeoChartRecipe,$a as mobileLineChartRecipe,Ca as mobileNetworkChartRecipe,Sa as mobileOrdinalChartRecipe,Ia as mobileScatterplotRecipe,Fa as mobileSmallMultipleRecipe,me as mulberry32,Cn as netEnsembleLayout,rr as networkEdgeHitTarget,or as networkHitTarget,Q as nonNegativeFinite,zr as normalizePoint,ri as normalizeScores,Z as normalizeTokenEncoding,b as orderByBarycenter,ua as orderByGroupDegree,w as orderExactSmall,Co as orthogonalEdgePath,M as packBandsBySilhouette,ko as packIntervals,mr as packSpanLevels,Rn as packedClusterMatrix,Gn as parallelCoordinatesLayout,xr as partitionSharedEdges,Ui as physicsChargePoint,_i as physicsDestination,$i as physicsReferenceEnvelope,Qi as physicsStageColliders,Ki as physicsStageGeography,v as placeWithMinGap,Fr as pointMagnitude,Mr as polarToXY,k as portalRegion,$ as pressureFieldRegion,A as processChrome,Oi as processJourneyRows,S as processLaneWalls,I as processStageLayout,C as processStageRegions,pi as processVolumePolygons,ii as proximityProblem,$r as radiusScale,J as readField,Lo as rectCollide,N as refineByAdjacentSwaps,F as regionCountsToProjectionRows,po as reserveAnnotationBands,ho as reserveMarginPct,fo as reserveSeries,Ar as ringArcPath,un as roundedEnclosure,z as routeSurfaceRegion,ar as runLengthEncode,ir as runs,Tt as sampleGeographicDotGrid,pr as scaleArcBand,Nr as scalePoint,sa as sedimentBake,ur as selectCyclicRange,at as selectIsometricLandmarks,te as shade,cr as shortestArcDelta,Jr as shortestPath,ne as signatureKey,yr as spanArcPath,gr as spanArcPeakY,aa as spawnFromTokens,lo as stackFuelSeries,mi as stageTargetInVolume,Cr as subtractPoints,re as suggestTokenEncoding,yo as summarizeOperatingPoint,j as symbolExtent,L as symbolPathString,R as symbolRadius,mo as thresholdBandsForReserve,xo as tightestHours,Te as tokenLayer,ie as tokenTaskIntentToCapabilityIntents,ae as unitize,se as unitizeRange,ce as unwrapDatum,Ri as updateProcessJourney,pe as waffleLayout,le as withAlpha,Ko as wordTrailsLayout,To as wordTrailsProgressiveReveal,sr as wrapValue,vr as xyToAngle};
1
+ import{DEFAULT_GLYPH_ANCHOR as e,DEFAULT_GLYPH_VIEWBOX as t,SYMBOL_SEQUENCE as n,absorbRegion as o,aggregateRegionCounts as r,annotationLayout as i,bandLabel as a,bodyGroupSpec as s,boundsOf as c,calendarLayout as l,capacitatedRegion as u,chargeGateRegion as d,collidersFromPlotBounds as h,collidersFromXScaleBins as f,countPairwiseCrossings as m,forceFieldRegion as p,glyphExtent as g,glyphFractionClipRect as y,glyphPlacement as x,groupCompletionRows as b,hatchFill as w,hullFromBoxes as M,linearAxis as v,markCallout as k,matchesPhysicsBodyFilter as $,membraneRegion as A,orderByBarycenter as S,orderExactSmall as I,packBandsBySilhouette as C,parallelCoordinatesLayout as N,placeWithMinGap as z,portalRegion as F,pressureFieldRegion as j,processChrome as W,processLaneWalls as E,processStageLayout as O,processStageRegions as R,refineByAdjacentSwaps as L,regionCountsToProjectionRows as P,roundedEnclosure as q,routeSurfaceRegion as T,sedimentHeightfield as D,symbolExtent as B,symbolPathString as V,symbolRadius as H,useCustomLayoutSelection as Y,valueAtPath as G}from"./c-DPMVAUAW.min.js";import{diagnoseTokenEncoding as X,forceLayout as _,generateTokens as K,layoutTokenGrid as Q,normalizeTokenEncoding as Z,suggestTokenEncoding as U,tokenTaskIntentToCapabilityIntents as J,unitize as ee,unitizeRange as te}from"./c-6CMMSN6N.min.js";import{DEFAULT_AREA_PER_ANNOTATION as ne,LayoutCache as oe,annotationBudget as re,annotationDensity as ie,clamp as ae,createSafeDatum as se,datumFromFields as ce,dimFor as le,groupBy as ue,makeShade as de,matchesHighlight as he,mean as fe,mulberry32 as me,nonNegativeFinite as pe,readField as ge,resolveAccessor as ye,shade as xe,signatureKey as be,stableGlyphId as we,unwrapDatum as Me,withAlpha as ve}from"./c-Q2IPZ3MU.min.js";import{isNoteAnnotation as ke}from"./c-4ES5367Y.min.js";import"./c-GGISSW5E.min.js";var $e=e=>{const t=e.config,n=t.rows??10,o=t.columns??10,r=t.gutter??2,i=n*o;if(0>=n||0>=o||0>=i)return{nodes:[]};const{plot:a}=e.dimensions;if(0>=a.width||0>=a.height)return{nodes:[]};const s=(a.width-r*(o-1))/o,c=(a.height-r*(n-1))/n;if(0>=s||0>=c)return{nodes:[]};const l=(null==(u=t.categoryAccessor)?null:"function"==typeof u?u:e=>e[u])??(()=>"_default");var u;const d=function(e){return null==e?null:"function"==typeof e?e:t=>Number(t[e])}(t.valueAccessor)??(()=>1),h=new Map,f=[];for(const t of e.data){const e=l(t)+"",n=Number(d(t)),o=Number.isFinite(n)?Math.max(0,n):0;h.has(e)||f.push(e),h.set(e,(h.get(e)??0)+o)}const m=Array.from(h.values()).reduce((e,t)=>e+t,0);if(0>=m)return{nodes:[]};let p;if(t.categoryOrder&&t.categoryOrder.length>0){const e=new Set,n=[];for(const o of t.categoryOrder)h.has(o)&&!e.has(o)&&(e.add(o),n.push(o));p=[...n,...f.filter(t=>!e.has(t))]}else p=f;if(0===p.length)return{nodes:[]};const g=p.map(e=>({cat:e,exact:(h.get(e)??0)/m*i})).map(e=>({...e,count:Math.floor(e.exact)})),y=g.reduce((e,t)=>e+t.count,0),x=g.map((e,t)=>({i:t,rem:e.exact-e.count})).sort((e,t)=>t.rem-e.rem);for(let e=0;i-y>e;e++)g[x[e%x.length].i].count+=1;const b="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",w="string"==typeof t.valueAccessor?t.valueAccessor:"value",M=(e,t,n)=>se(o=>{o("category",e),o("value",h.get(e)??0),o("share",(h.get(e)??0)/m),"category"!==b&&o(b,e),"value"!==w&&o(w,h.get(e)??0),o("cells",n),o("_waffleCategory",e),o("_waffleIndex",t)}),v=[];let k=0;for(const t of g){const i=e.resolveColor(t.cat);for(let e=0;t.count>e;e++)v.push({type:"rect",x:a.x+k%o*(s+r),y:a.y+(n-1-Math.floor(k/o))*(c+r),w:s,h:c,style:{fill:i,stroke:"none"},datum:M(t.cat,k,t.count),group:t.cat,_transitionKey:`waffle-${t.cat}-${e}`}),k++}return{nodes:v}};function Ae(e,t,n){const o=Number.isFinite(t)?Math.max(0,Math.floor(t)):0,r=e=>Number.isFinite(e)?Math.max(0,e):0,i=e.reduce((e,t)=>e+(r(t.weight)>0?1:0),0),a=i>0?Math.min(Math.max(0,Math.floor(n?.minPerCategory??0)),Math.floor(o/i)):0,s=e.reduce((e,t)=>e+r(t.weight),0);if(0>=o||0>=s)return e.map(e=>({...e,exact:0,cells:0,remainder:0}));const c=e.map(e=>{const t=r(e.weight),n=t/s*o;return{...e,exact:n,cells:t>0?Math.max(a,Math.floor(n)):0,remainder:n-Math.floor(n)}});let l=c.reduce((e,t)=>e+t.cells,0);for(;l>o;){const e=c.filter(e=>e.cells>a).sort((e,t)=>t.cells-e.cells||e.remainder-t.remainder||e.key.localeCompare(t.key))[0];if(!e)break;e.cells--,l--}const u=c.filter(e=>r(e.weight)>0).sort((e,t)=>t.remainder-e.remainder||r(t.weight)-r(e.weight)||e.key.localeCompare(t.key));for(let e=0;o>l;e++)u[e%u.length].cells++,l++;return c}function Se(e,t,n,o){const r=new Set;return e.map((e,i)=>{const a=t(e,i)+"",s=Number(n(e,i));if(!a)throw Error(`${o} snapshot contains an empty id at index ${i}.`);if(r.has(a))throw Error(`${o} snapshot contains duplicate id "${a}".`);if(!Number.isFinite(s)||0>s)throw Error(`${o} snapshot value for "${a}" must be a finite non-negative number.`);return r.add(a),{id:a,value:s}})}function Ie(e,t,n){const o=n.afterId??n.beforeId,r=n.afterValue??n.beforeValue,i=null==n.epsilon||0>n.epsilon?1e-9:n.epsilon,a=Se(e,n.beforeId,n.beforeValue,"Before"),s=Se(t,o,r,"After"),c=new Map(a.map(e=>[e.id,e.value])),l=new Map(s.map(e=>[e.id,e.value])),u=a.reduce((e,t)=>e+t.value,0),d=s.reduce((e,t)=>e+t.value,0),h=i>=Math.abs(u-d);if(!h&&!n.allowImbalance)throw Error(`Snapshot totals must match (before ${u}, after ${d}). Pass allowImbalance to inspect residuals.`);const f=[],m=[...a.map(e=>e.id),...s.map(e=>e.id).filter(e=>!c.has(e))];for(const e of m){const t=Math.min(c.get(e)??0,l.get(e)??0);t>i&&f.push({sourceId:e,targetId:e,value:t,kind:"stay"})}const p=a.map(e=>({id:e.id,value:e.value-(l.get(e.id)??0)})).filter(e=>e.value>i),g=s.map(e=>({id:e.id,value:e.value-(c.get(e.id)??0)})).filter(e=>e.value>i);let y=0,x=0;for(;p.length>y&&g.length>x;){const e=p[y],t=g[x],n=Math.min(e.value,t.value);n>i&&f.push({sourceId:e.id,targetId:t.id,value:n,kind:"move"}),e.value-=n,t.value-=n,e.value>i||(y+=1),t.value>i||(x+=1)}return{flows:f,beforeTotal:u,afterTotal:d,balanced:h,unmatchedBefore:p.slice(y).filter(e=>e.value>i).map(({id:e,value:t})=>({id:e,value:t})),unmatchedAfter:g.slice(x).filter(e=>e.value>i).map(({id:e,value:t})=>({id:e,value:t}))}}var Ce="#334155",Ne="#f8fafc",ze="#cbd5e1",Fe={viewBox:[40,40],anchor:[.5,1],parts:[{d:"M8 3h24v34H8z",fill:"color"},{d:"M12 9h16v5H12zM12 18h16v5H12zM12 27h16v5H12z",fill:"accent"},{d:"M23.8 11.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 20.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0M23.8 29.5a1.2 1.2 0 1 0 2.4 0a1.2 1.2 0 1 0-2.4 0",fill:"color"}]},je={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M10 8h20a2 2 0 0 1 2 2v20a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z",fill:"color"},{d:"M15 15h10v10H15z",fill:"accent"},{d:"M7 2v6M14 2v6M21 2v6M28 2v6M7 32v6M14 32v6M21 32v6M28 32v6M2 7h6M2 14h6M2 21h6M2 28h6M32 7h6M32 14h6M32 21h6M32 28h6",fill:"none",stroke:"color",strokeWidth:3}]},We={viewBox:[40,40],anchor:[.5,.5],parts:[{d:"M23 1L7 23h10l-3 16 19-25H22z",fill:"color"}]},Ee={viewBox:[48,40],anchor:[.5,.78],parts:[{d:"M7 12c0-4 3-7 7-7h20c4 0 7 3 7 7v15H7z",fill:"color"},{d:"M11 15h26v8H11z",fill:"accent",opacity:.9},{d:"M12 27h7v4h-7zM29 27h7v4h-7z",fill:"accent",opacity:.95},{d:"M12 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0M28 31a4 4 0 1 0 8 0a4 4 0 1 0-8 0",fill:"color",stroke:"accent",strokeWidth:1.8},{d:"M5 13h4v8H5zM39 13h4v8h-4z",fill:"color"}]},Oe="M 9.12,3.34 C 8.28,3.29 7.44,3.40 6.64,3.69 4.17,3.63 1.97,5.37 0.91,7.51 -1.32,11.80 2.55,17.76 8.19,16.55 11.62,16.13 15.55,14.04 16.17,10.33 16.38,6.53 12.77,3.52 9.12,3.34 Z M 9.35,19.86 C 8.89,19.84 8.41,19.92 7.92,20.11 5.12,21.55 3.72,24.68 2.79,27.54 2.32,29.86 0.87,32.04 1.36,34.49 1.63,37.60 8.04,38.95 8.04,38.95 8.04,38.95 14.67,39.65 16.50,36.33 17.16,31.95 16.34,27.23 14.01,23.42 13.07,21.69 11.36,19.92 9.35,19.86 Z",Re={viewBox:[18,40],anchor:[.5,1],parts:[{d:Oe,fill:"color",stroke:"color",strokeWidth:1.4}]},Le={server:Fe,chip:je,bolt:We,bus:Ee,person:Re},Pe="var(--semiotic-primary, #4e79a7)",qe="var(--semiotic-border, #d1d5db)";function Te(e){return"object"==typeof e&&null!==e&&"tokens"in e&&"encoding"in e}function De(e,t,n){return"function"==typeof e?e(t)??n:e??n}function Be(e,t){return"function"==typeof e?e(t):e}function Ve(e){return e.sample??e.value??e.index}var He=new Set(n);function Ye(e,t){return void 0!==t.datum?De(t.datum,e,null):e.datum??null}function Ge(e,t){return{fill:!1!==e.highlighted?"scenario"===e.range?De(t.rangeColor,e,"var(--semiotic-secondary, #9ca3af)"):De(t.color,e,Pe):De(t.inactiveColor,e,qe),stroke:"none",...Be(t.style,e)??{}}}function Xe(e,t){const n=Be(t.pointId,e)??(t.idPrefix?`${t.idPrefix}-${"scenario"===e.range?"range-":""}${e.index}`:void 0);return{datum:Ye(e,t),accessibleDatum:Be(t.accessibleDatum,e),accessibility:Be(t.accessibility,e),pointId:n,_transitionKey:n}}function _e({input:e,encoding:t,options:n={}}){if(!Te(e)&&!t)throw Error("tokenLayer requires an encoding when input is not a TokenSet.");const o=Te(e)?{...e,encoding:Z(e.encoding)}:K(e,t),r=function(e,t){const n=t.includeRange&&e.rangeTokens?[...e.tokens,...e.rangeTokens]:e.tokens;if(t.positionToken)return function(e,t){const n=t.positionToken;return n?e.map((t,o)=>{const r=n(t,o,e);return{...t,x:r.x,y:r.y,row:r.row??o,column:r.column??0}}):[]}(n,t);const o=t.layout??e.encoding.layout??"grid";if("quantile-strip"===o)return function(e,t){if(0===e.length)return[];const n=t.x??0,o=t.y??0,r=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),i=t.gutter??2,a=Math.max(1,Math.floor(t.rows??1)),s=e.map(Ve),c=Math.min(...s),l=Math.max(...s)-c||1;return e.map((s,u)=>{const d=Ve(s),h=u%a,f=t.valueToX?t.valueToX(d,s):n+(d-c)/l*(t.width??12*Math.max(1,e.length-1)),m=t.valueToY?t.valueToY(d,s):o+h*(r+i);return{...s,x:f,y:m,row:h,column:u}})}(n,t);if("dotplot"===o)return function(e,t){if(0===e.length)return[];const n=t.x??0,o=t.y??0,r="number"==typeof t.tokenSize?t.tokenSize:12,i=t.gutter??2,a=t.cellWidth??r+i,s=t.cellHeight??r+i,c=e.map(Ve),l=Math.min(...c),u=Math.max(...c)-l||1,d=new Map;return e.map(r=>{const i=Ve(r),c=t.valueToX?t.valueToX(i,r):n+(i-l)/u*(t.width??Math.max(1,e.length-1)*a),h=Math.round((c-n)/Math.max(1,a)),f=d.get(h)??0;d.set(h,f+1);const m=t.valueToY?t.valueToY(i,r):o+f*s;return{...r,x:n+h*a,y:m,row:f,column:h}})}(n,t);if("bar-segment"===o){if(!t.valueToX)throw Error('tokenLayer layout "bar-segment" requires valueToX and optionally valueToY.');return function(e,t){if(!t.valueToX)return[];const n=t.y??0,o=t.cellHeight??("number"==typeof t.tokenSize?t.tokenSize:12),r=t.anchor??[.5,.5];return e.map((e,i)=>{const a=Number.isFinite(e.start)?e.start:Ve(e),s=(a+(Number.isFinite(e.end)?e.end:a+e.value))/2,c=t.valueToY?t.valueToY(s,e):n+r[1]*o;return{...e,x:t.valueToX(s,e),y:c,row:0,column:i}})}(n,t)}if("beeswarm"===o||"small-multiple"===o)throw Error(`tokenLayer layout "${o}" is not implemented yet; use row, column, stack, grid, waffle, dotplot, quantile-strip, bar-segment with valueToX, or positionToken.`);const r="number"==typeof t.tokenSize?t.tokenSize:void 0,i=t.cellWidth??r??12,a=t.cellHeight??r??i,s="row"===o?Math.max(1,n.length):"column"===o||"stack"===o?1:"waffle"===o&&"fixed-denominator"===e.encoding.countStrategy&&100===e.denominator?10:function(e,t,n){if(t.columns)return t.columns;if(t.width&&n>0){const e=t.gutter??2;return Math.max(1,Math.floor((t.width+e)/(n+e)))}return e.length>0?Math.ceil(Math.sqrt(e.length)):1}(n,t,i);return Q(n,{...t,columns:s,cellWidth:i,cellHeight:a})}(o,n).filter(e=>!n.include||n.include(e));return{tokenSet:o,positionedTokens:r,nodes:r.map(e=>function(e,t,n){if("dot"===n.tokenType)return function(e,t){const n=De(t.tokenSize,e,12);return{type:"point",x:e.x,y:e.y,r:De(t.radius,e,n/2),style:Ge(e,t),...Xe(e,t)}}(e,t);const o=Be(t.glyph,e)??function(e){if(e)return Le[e]}(n.icon);if(o)return function(e,t,n){const o=Ge(e,n),r=De(n.tokenSize,e,12);return{type:"glyph",x:e.x,y:e.y,size:r,glyph:t,color:(o.fill??Pe)+"",accent:De(n.accent,e,"var(--semiotic-bg, #ffffff)"),fraction:1>e.fraction?e.fraction:void 0,fractionStart:e.startFraction>0?e.startFraction:void 0,fractionDirection:De(n.fractionDirection,e,"horizontal"),ghostColor:1>e.fraction?Be(n.ghostColor,e)??qe:void 0,rotation:Be(n.rotation,e),style:o,...Xe(e,n)}}(e,o,t);const r=(i=n.icon)&&He.has(i)?i:void 0;var i;return function(e,t){const n=De(t.tokenSize,e,12);return{type:"symbol",x:e.x,y:e.y,size:Math.PI*Math.max(1,n/2)**2,symbolType:De(t.symbolType,e,"circle"),path:Be(t.symbolPath,e),rotation:Be(t.rotation,e),style:Ge(e,t),...Xe(e,t)}}(e,r&&null==t.symbolType?{...t,symbolType:r}:t)}(e,n,o.encoding))}}import{jsx as Ke,jsxs as Qe}from"react/jsx-runtime";var Ze={resource:32,city:64},Ue=["#739b58","#83a964","#668d52","#8baa68"],Je={land:"#78985c",ocean:"#4d8192",forest:"#4f7c4b",grassland:"#8eaa68",cropland:"#a6a568",wetland:"#668f79",urban:"#8d8a72",scrub:"#9b9665",bare:"#aa906a",snow:"#d8ddcf"},et={land:"Open land",ocean:"Open ocean",forest:"Forest",grassland:"Grassland",cropland:"Cropland",wetland:"Wetland",urban:"Urban district",scrub:"Scrubland",bare:"Bare ground",snow:"Snow cover"},tt=new Set(["city","culture","monument","faith","nature","knowledge","defense","arena","transport"]),nt=new Set(["land","ocean","forest","grassland","cropland","wetland","urban","scrub","bare","snow"]);function ot(e,t){if(null!=e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function rt(e,t){const n=ot(e,t);return"string"==typeof n&&n.length>0?n:void 0}function it(e,t){if(tt.has(t))return rt(e,t)}function at(e,t){if("function"==typeof e)return e;const n=e??t;return e=>e[n]}function st(e,t,n){return[111.32*(e-n.lon)*Math.cos((t+n.lat)/2*(Math.PI/180)),110.574*(t-n.lat)]}function ct(e){const t=Math.max(3,Math.round(e??5));return t%2==0?t+1:t}function lt(e){return tt.has(e)?e:"monument"}function ut(e,t){const n=ct(t.gridSize),o=Math.max(1,t.gridRadiusKm??75),r=2*o/n,i=Math.floor(n/2),a=at(t.idAccessor,"id"),s=at(t.nameAccessor,"name"),c=at(t.longitudeAccessor,"lon"),l=at(t.latitudeAccessor,"lat"),u=at(t.kindAccessor,"kind"),d=t.candidatePriorityAccessor?at(t.candidatePriorityAccessor,"priority"):()=>0,h=new Map;let f=null;for(const m of e){const e=Number(c(m)),p=Number(l(m));if(!Number.isFinite(e)||!Number.isFinite(p))continue;const g=(a(m)??`${e},${p}`)+"",y=(s(m)??g)+"",x=lt(u(m)),[b,w]=st(e,p,t.center);if(Math.abs(b)>o||Math.abs(w)>o)continue;const M=Math.min(n-1,Math.max(0,Math.floor((b+o)/r))),v=Math.min(n-1,Math.max(0,Math.floor((o-w)/r))),k=(M+.5)*r-o,$=o-(v+.5)*r,A={...m,id:g,name:y,kind:x,lon:e,lat:p,distanceKm:Math.sqrt(b*b+w*w),row:v,column:M,cellDistanceSq:(b-k)**2+(w-$)**2,candidatePriority:Number(d(m))||0};(null!=t.centerId&&g===t.centerId||!f&&"city"===x||!f&&v===i&&M===i)&&(f=A);const S=`${v}:${M}`,I=h.get(S)??[];I.push(A),h.set(S,I)}const m=new Map;f&&m.set("city",1);const p=[];for(let e=0;n>e;e++)for(let t=0;n>t;t++){const n=`tile-${e}-${t}`,a=(t+.5)*r-o,s=o-(e+.5)*r;let c,l;if(e===i&&t===i&&f){c=f;const n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id).sort((e,t)=>e.candidatePriority-t.candidatePriority||e.cellDistanceSq-t.cellDistanceSq||e.name.localeCompare(t.name));l=[f,...n]}else{const n=(h.get(`${e}:${t}`)??[]).filter(e=>e.id!==f?.id);n.sort((e,t)=>{const n=e.candidatePriority-t.candidatePriority;if(0!==n)return n;const o=m.get(e.kind)??0,i=m.get(t.kind)??0,a=r*r*.35;return e.cellDistanceSq+o*a-(t.cellDistanceSq+i*a)||e.name.localeCompare(t.name)}),c=n[0]??null,l=n}c&&m.set(c.kind,(m.get(c.kind)??0)+1),p.push({id:n,row:e,column:t,centerXKm:a,centerYKm:s,terrainIndex:Math.abs((17*e+31*t)%Ue.length),landmark:c,landmarks:l})}return p}var dt=e=>{const t=ct(e.config.gridSize),n=Math.max(20,e.config.tileWidth??80),o=Math.max(10,e.config.tileHeight??40),r=e.config.terrainColors?.length?e.config.terrainColors:Ue,i=e.dimensions.width/2,a=(e.dimensions.height-t*o)/2+o/2,s=ut(e.points,e.config).map(e=>({...e,x:i+n/2*(e.column-e.row),y:a+(e.column+e.row)*(o/2)}));return{nodes:s.map(t=>{const i=function(e,t){const n=ot(e,t),o=function(e){return nt.has(e)?e:void 0}("string"==typeof n?n:ot(n,"kind"));if(!o)return;if("string"==typeof n)return{kind:o};const r=ot(n,"coverage"),i="number"==typeof r&&Number.isFinite(r)?Math.max(0,Math.min(1,r)):void 0,a=rt(n,"fill");return{kind:o,...null==i?{}:{coverage:i},...a?{fill:a}:{}}}(e.config.terrainByCell,t.id),a="city"===t.landmark?.kind?"urban":i?.kind??"land",s=i?.fill??rt(e.config.terrainPalette,a)??rt(Je,a)??Je.land,c=t.landmark?{...t.landmark,gridRow:t.row,gridColumn:t.column,cellId:t.id,terrainKind:a,terrainCoverage:i?.coverage,features:t.landmarks,featureCount:t.landmarks.length}:{id:t.id,name:(l=a,rt(et,l)??et.land),kind:"terrain",terrainKind:a,terrainCoverage:i?.coverage,gridRow:t.row,gridColumn:t.column,cellId:t.id,features:[],featureCount:0};var l,u,d,h,f;return{type:"geoarea",pathData:(u=t.x,d=t.y,h=n,f=o,`M${u},${d-f/2}L${u+h/2},${d}L${u},${d+f/2}L${u-h/2},${d}Z`),centroid:[t.x,t.y],bounds:[[t.x-n/2,t.y-o/2],[t.x+n/2,t.y+o/2]],screenArea:n*o/2,style:{fill:i||"urban"===a?s:r[t.terrainIndex%r.length],stroke:"ocean"===a?"#315d6c":e.config.tileStroke??"#314934",strokeWidth:1},datum:c,group:t.landmark?.kind??a,interactive:!0}}),overlays:Ke(ht,{tiles:s,tileWidth:n,tileHeight:o,sprites:e.config.sprites,resourceSize:e.config.resourceSpriteSize??32,citySize:e.config.citySpriteSize??64,showCityLabel:!1!==e.config.showCityLabel}),restyle:(e,t)=>t?.isActive&&e.datum&&"terrain"!==e.datum.kind?{fillOpacity:t.predicate(e.datum)?1:.28}:{fillOpacity:1}}};function ht({tiles:e,tileWidth:t,tileHeight:n,sprites:o,resourceSize:r,citySize:i,showCityLabel:a}){const s=Y(),c=e.filter(e=>e.landmark).sort((e,t)=>e.y-t.y||e.x-t.x);return Qe("g",{"aria-hidden":"true",pointerEvents:"none",children:[c.map(e=>{const a=e.landmark,c="city"===a.kind?i:r,l=e.y+n/2,u=s.isActive&&!s.predicate(a)?.28:1;return Qe("g",{opacity:u,children:[Ke("ellipse",{cx:e.x,cy:e.y+.15*n,rx:.28*c,ry:.1*c,fill:"#17251d",opacity:.32}),Ke(gt,{kind:a.kind,href:it(o,a.kind),x:e.x-c/2,y:l-c,size:c}),e.landmarks.length>1&&Ke(ft,{x:e.x+.3*t,y:e.y-.19*n,count:e.landmarks.length-1,tileHeight:n})]},a.id)}),a&&c.filter(e=>"city"===e.landmark?.kind).map(e=>{const t=e.landmark.name.toUpperCase(),o=Math.max(56,6.4*t.length+14);return Qe("g",{transform:`translate(${e.x},${e.y+.72*n})`,children:[Ke("rect",{x:-o/2,y:-7,width:o,height:14,rx:1,fill:"#17251d",opacity:.92}),Ke("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:9,fontWeight:700,letterSpacing:.8,children:t})]},e.landmark.id+"-label")})]})}function ft({x:e,y:t,count:n,tileHeight:o}){const r=Math.max(10,Math.min(15,.34*o)),i="+"+n,a=Math.max(r,i.length*r*.58);return Qe("g",{transform:`translate(${e},${t})`,children:[Ke("rect",{x:-a/2,y:-r/2,width:a,height:r,rx:1,fill:"#17251d",stroke:"#f0d36d",strokeWidth:1}),Ke("text",{textAnchor:"middle",dominantBaseline:"central",fill:"#f5edcf",fontFamily:"monospace",fontSize:Math.max(7,.62*r),fontWeight:700,children:i})]})}var mt={city:["..1111..","..1221..",".111111.",".133331.","11111111","13311331","14411441","11111111"],culture:["..1111..",".122221.","11111111",".133331.",".133331.",".133331.","11111111",".444444."],monument:["...11...","..1221..","..1221..","..1331..",".113311.",".133331.","11111111",".444444."],faith:["...11...","...11...","..1111..","...11...","..1221..",".133331.","11111111",".444444."],nature:["...11...","..1221..",".122221.","12222221",".133331.","...11...","..1441..",".144441."],knowledge:[".111111.","12211221","12211221","13311331","13311331","13311331","11111111",".444444."],defense:["11.11.11","11111111","12222221","12211221","13311331","13333331","11111111",".444444."],arena:["..1111..",".122221.","12333321","12344321","12344321","12333321",".122221.","..1111.."],transport:["...11...","..1221..",".122221.","11111111","..1331..","..1331..",".114411.","11444411"]},pt={city:{1:"#29364a",2:"#d8b45b",3:"#b7693c",4:"#6d9fc5"},culture:{1:"#29364a",2:"#d5c9a3",3:"#9c6fb2",4:"#ece3c4"},monument:{1:"#29364a",2:"#d8cba8",3:"#9c8f79",4:"#ece3c4"},faith:{1:"#29364a",2:"#d9c36d",3:"#a877a5",4:"#ece3c4"},nature:{1:"#29364a",2:"#4f8a4e",3:"#79aa56",4:"#79583a"},knowledge:{1:"#29364a",2:"#d5c9a3",3:"#4f7da0",4:"#ece3c4"},defense:{1:"#29364a",2:"#a6a298",3:"#777b7f",4:"#d5c9a3"},arena:{1:"#29364a",2:"#cb8056",3:"#d8cba8",4:"#6d9fc5"},transport:{1:"#29364a",2:"#d8b45b",3:"#6d9fc5",4:"#ece3c4"}};function gt({kind:e,href:t,x:n,y:o,size:r}){if(t)return Ke("image",{href:t,x:n,y:o,width:r,height:r,preserveAspectRatio:"xMidYMax meet",style:{imageRendering:"pixelated"}});const i=pt[e];return Ke("svg",{x:n,y:o,width:r,height:r,viewBox:"0 0 8 8",shapeRendering:"crispEdges",children:mt[e].flatMap((e,t)=>[...e].map((e,n)=>"."===e?null:Ke("rect",{x:n,y:t,width:1,height:1,fill:i[e]},`${t}-${n}`)))})}import{jsx as yt}from"react/jsx-runtime";function xt(e){if(Number.isFinite(e))return Math.max(1,Math.round(e))}function bt(e,t,n){return Math.max(t,Math.min(n,e))}function wt(e){let t=1/0,n=-1/0;for(const o of e)Number.isFinite(o)&&(t>o&&(t=o),o>n&&(n=o));return t===1/0?[0,0]:[t,n]}function Mt(e,t){const n=t[1]-t[0];return 0===n?.5:(e-t[0])/n}function vt(e,t={}){const n=e.map((e,t)=>({...e,index:t})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));if(0===n.length)return[];const o=bt(Number.isFinite(t.occupancy)?Number(t.occupancy):.72,.2,1),r=Number.isFinite(t.aspectRatio)&&Number(t.aspectRatio)>0?Number(t.aspectRatio):1.8;let i=xt(t.columns)??Math.max(1,Math.ceil(Math.sqrt(n.length*r/o))),a=xt(t.rows)??Math.max(1,Math.ceil(n.length/(i*o)));n.length>i*a&&(null!=t.columns&&null==t.rows?a=Math.ceil(n.length/i):null!=t.rows&&null==t.columns?i=Math.ceil(n.length/a):a=Math.ceil(n.length/i));const s=wt(n.map(e=>e.x)),c=wt(n.map(e=>e.y)),l=n.map(e=>({...e,desiredColumn:Mt(e.x,s)*Math.max(0,i-1),desiredRow:Mt(e.y,c)*Math.max(0,a-1)})),u=(i-1)/2,d=(a-1)/2;l.sort((e,t)=>(t.desiredColumn-u)**2+(t.desiredRow-d)**2-((e.desiredColumn-u)**2+(e.desiredRow-d)**2)||e.desiredRow-t.desiredRow||e.desiredColumn-t.desiredColumn||e.index-t.index);const h=new Set;for(let e=0;a>e;e+=1)for(let t=0;i>t;t+=1)h.add(e*i+t);const f=[];for(const e of l){let t=-1,n=1/0;for(const o of h){const r=(o%i-e.desiredColumn)**2+(Math.floor(o/i)-e.desiredRow)**2;(n>r||r===n&&t>o)&&(t=o,n=r)}0>t||(h.delete(t),f.push({datum:e.datum,x:e.x,y:e.y,row:Math.floor(t/i),column:t%i,index:e.index}))}return f.sort((e,t)=>e.index-t.index),f.map(({index:e,...t})=>t)}function kt(e,t,n=[]){if("function"==typeof t)return t(e);if("string"==typeof t)return e[t];for(const t of n)if(null!=e[t])return e[t]}function $t(e){return e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")+"Z"}var At=e=>{const t=e.config,n=t.source??"auto",o="areas"===n||"auto"===n&&e.areas.length>0,r=o?function(e){return e.areas.map((t,n)=>{const o=function(e,t){const n=e.properties&&"object"==typeof e.properties?e.properties:{},o=e.id??n.id??n.name??"area-"+t;return{...n,id:o+""}}(t,n),r=e.scales.geoPath.centroid(t),i=Number.isFinite(r[0])&&Number.isFinite(r[1])?e.scales.invertedPoint(r[0],r[1]):null;return{datum:{...o,gridLongitude:i?.[0],gridLatitude:i?.[1]},x:r[0],y:r[1]}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}(e):e.points.map((e,t)=>({datum:e,x:t,y:t})),i=r.filter((e,n)=>!t.filter||t.filter(e.datum,n)),a=function(e,t){if(!t.rowAccessor||!t.columnAccessor)return null;const n=e.map(e=>({datum:e,x:Number(kt(e,t.columnAccessor)),y:Number(kt(e,t.rowAccessor))})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y));return n.length!==e.length?null:n.map(e=>({...e,row:e.y,column:e.x}))}(i.map(e=>e.datum),t),s=o?i:function(e){return e.points.map(t=>{const n=Number(kt(t,e.config.longitudeAccessor,["lon","longitude"])),o=Number(kt(t,e.config.latitudeAccessor,["lat","latitude"])),r=Number.isFinite(n)&&Number.isFinite(o)?e.scales.projectedPoint(n,o):null;return{datum:t,x:r?.[0]??NaN,y:r?.[1]??NaN}}).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))}({...e,points:i.map(e=>e.datum)}),c=a??vt(s,{columns:t.columns,rows:t.rows,occupancy:t.occupancy,aspectRatio:e.dimensions.width/Math.max(1,e.dimensions.height)});if(0===c.length)return{nodes:[]};const l=wt(c.map(e=>e.row)),u=wt(c.map(e=>e.column)),d=Math.max(1,Math.round(l[1]-l[0])+1),h=Math.max(1,Math.round(u[1]-u[0])+1),f=Math.max(0,t.layoutPadding??8),m=Math.max(1,e.dimensions.width-2*f)/h,p=Math.max(1,e.dimensions.height-2*f)/d,g=(e.dimensions.width-m*h)/2,y=(e.dimensions.height-p*d)/2,x=bt(t.cellPadding??.12,0,.8),b=Math.max(1,.5*Math.min(m,p)*(1-x)),w=t.sizeAccessor?c.map(e=>Number(kt(e.datum,t.sizeAccessor))):[],M=t.sizeDomain??wt(w),v=t.sizeRange??[.36,1],k=bt(Math.min(v[0],v[1]),.05,1),$=bt(Math.max(v[0],v[1]),k,1),A=c.map((n,o)=>{const r={...n.datum,gridRow:n.row,gridColumn:n.column},i=(kt(r,t.idAccessor,["id","key","name"])??"grid-"+o)+"",a=(kt(r,t.labelAccessor,["abbr","code","label","name","id"])??i)+"",s=Math.max(1,t.maxLabelLength??4),c=a.length>s?a.slice(0,s):a,d=kt(r,t.categoryAccessor),h=null==d?void 0:d+"",f=kt(r,t.fillAccessor),x=null!=f?f+"":h?e.resolveColor(h):e.theme.categorical[0]??"#4f86c6",w=t.sizeAccessor?Number(kt(r,t.sizeAccessor)):NaN,v=t.sizeAccessor&&Number.isFinite(w)?Math.sqrt(bt(Mt(w,M),0,1)):1,A=b*(k+v*($-k)),S="function"==typeof t.markStyle?t.markStyle(r,o):t.markStyle;return{datum:r,id:i,label:c,category:h,row:n.row,column:n.column,x:g+(n.column-u[0]+.5)*m,y:y+(n.row-l[0]+.5)*p,radius:A,style:{fill:x,fillOpacity:.94,stroke:"rgba(255,255,255,0.9)",strokeWidth:1,...S}}}),S=t.shape??"circle";return{nodes:A.map(e=>{return"circle"===S?{type:"point",x:e.x,y:e.y,r:e.radius,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},pointId:e.id,_transitionKey:e.id}:{type:"geoarea",pathData:"hexagon"===S?function(e,t,n){const o=[];for(let r=0;6>r;r+=1){const i=-Math.PI/2+r*(Math.PI/3);o.push([e+Math.cos(i)*n,t+Math.sin(i)*n])}return $t(o)}(e.x,e.y,e.radius):$t([[(t=e.x)-(o=e.radius),(n=e.y)-o],[t+o,n-o],[t+o,n+o],[t-o,n+o]]),centroid:[e.x,e.y],bounds:[[e.x-e.radius,e.y-e.radius],[e.x+e.radius,e.y+e.radius]],screenArea:"hexagon"===S?3*Math.sqrt(3)*e.radius*e.radius/2:(2*e.radius)**2,style:e.style,datum:e.datum,accessibleDatum:e.datum,accessibility:{label:e.label,tableFields:{name:e.datum.name??e.label,label:e.label,row:e.row,column:e.column,...e.category?{category:e.category}:{}}},group:e.category,interactive:!0};var t,n,o}),overlays:!1===t.showLabels?null:yt(St,{marks:A,color:t.labelColor??"#ffffff",fontSize:t.labelFontSize??bt(.23*Math.min(m,p),7,14),fontFamily:t.labelFontFamily,fontWeight:t.labelFontWeight??700}),restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.18}:{opacity:1}}};function St({marks:e,color:t,fontSize:n,fontFamily:o,fontWeight:r}){const i=Y();return yt("g",{"aria-hidden":"true",pointerEvents:"none",children:e.map(e=>{const a=!i.isActive||i.predicate(e.datum);return yt("text",{x:e.x,y:e.y,fill:t,fontFamily:o,fontSize:n,fontWeight:r,opacity:a?1:.18,textAnchor:"middle",dominantBaseline:"central",children:e.label},e.id)})})}import{geoBounds as It,geoContains as Ct}from"d3-geo";import{jsx as Nt}from"react/jsx-runtime";var zt=new WeakMap,Ft=new WeakMap,jt=new WeakMap,Wt=1;function Et(e,t,n){return Math.max(t,Math.min(n,e))}function Ot(e){if(Number.isFinite(e)&&Number(e)>0)return Number(e)}function Rt(e,t){return"function"==typeof t?t(e,e.dotIndex):"string"==typeof t?e[t]:void 0}function Lt(e){return e.properties&&"object"==typeof e.properties?{...e.properties}:{}}function Pt(e,t){const n=Lt(e);return(e.id??n.id??n.name??"feature-"+t)+""}function qt(e,t,n,o){return[Math.ceil((e-n)/o-.5),Math.floor((t-n)/o-.5)]}function Tt(e){if(!e)return 0;const t=jt.get(e);if(t)return t;const n=Wt;return Wt+=1,jt.set(e,n),n}function Dt(e,t){return!t||!(t[0][1]>e[1]||e[1]>t[1][1]||(n=e[0],o=t[0][0],r=t[1][0],o>r?o>n&&n>r:o>n||n>r));var n,o,r}function Bt(e,t){for(const n of e){const{feature:e,index:o}=n;if(e.geometry&&Dt(t,n.bounds))try{if(Ct(e,t))return{feature:e,index:o}}catch{}}return null}function Vt(e,t,n,o={}){const r=e.filter((e,t)=>e.geometry&&(!o.featureFilter||o.featureFilter(e,t))),i=function(e,t){if(0===e.length)return null;const n=t.bounds({type:"FeatureCollection",features:e});return Number.isFinite(n[0][0])&&Number.isFinite(n[0][1])&&Number.isFinite(n[1][0])&&Number.isFinite(n[1][1])?n:null}(r,t.geoPath);if(!i)return{dots:[],cellSize:10,features:r};const a=Math.max(0,o.layoutPadding??0),s=[[Et(i[0][0],a,Math.max(a,n.width-a)),Et(i[0][1],a,Math.max(a,n.height-a))],[Et(i[1][0],a,Math.max(a,n.width-a)),Et(i[1][1],a,Math.max(a,n.height-a))]],c=Math.max(0,s[1][0]-s[0][0]),l=Math.max(0,s[1][1]-s[0][1]);if(0===c||0===l)return{dots:[],cellSize:10,features:r};const u=Ot(o.columns);let d=Math.max(2,u?c/u:Ot(o.cellSize)??10);const h=Math.max(100,Math.round(Ot(o.maxSamples)??25e3)),f=Math.ceil(c/d)*Math.ceil(l/d);f>h&&(d*=Math.sqrt(f/h));const m=o.gridOrigin?.[0]??0,p=o.gridOrigin?.[1]??0,[g,y]=qt(s[0][0],s[1][0],m,d),[x,b]=qt(s[0][1],s[1][1],p,d),w=[],M=function(e){return e.map((e,t)=>{if(Ft.has(e))return{feature:e,index:t,bounds:Ft.get(e)??null};try{const n=It(e);return Ft.set(e,n),{feature:e,index:t,bounds:n}}catch{return Ft.set(e,null),{feature:e,index:t,bounds:null}}})}(r);for(let e=x;b>=e;e+=1){const n=p+(e+.5)*d;for(let r=g;y>=r;r+=1){const i=t.invertedPoint(m+(r+.5)*d,n);if(!i||!Number.isFinite(i[0])||!Number.isFinite(i[1]))continue;const a=Bt(M,i);if(!a)continue;const s={...Lt(a.feature),featureId:Pt(a.feature,a.index),featureIndex:a.index,gridRow:e,gridColumn:r,longitude:i[0],latitude:i[1],dotIndex:w.length};o.dotFilter&&!o.dotFilter(s,w.length)||w.push(s)}}return{dots:w,cellSize:d,features:r}}function Ht(e){return Math.round(1e4*e)/1e4}function Yt(e){return Array.isArray(e)&&e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?`${Ht(Number(e[0]))},${Ht(Number(e[1]))}`:"null"}function Gt(e,t){const n=e[t];return"function"==typeof n?n.call(e):void 0}function Xt(e){return"number"==typeof e&&Number.isFinite(e)?Ht(e)+"":null===e?"null":"unavailable"}function _t(e){const t=e.scales.projection;return[Xt(Gt(t,"scale")),Yt(Gt(t,"translate")),Yt(Gt(t,"center")),(n=Gt(t,"rotate"),Array.isArray(n)&&n.every(Number.isFinite)?n.map(e=>Ht(Number(e))).join(","):"unavailable"),Xt(Gt(t,"clipAngle")),Xt(Gt(t,"precision")),...[[0,0],[-120,35],[45,45],[120,-30]].map(([t,n])=>Yt(e.scales.projectedPoint(t,n)))].join("|");var n}function Kt(e){return e.map(([e,t],n)=>`${0===n?"M":"L"}${e},${t}`).join("")+"Z"}var Qt=e=>{const t=function(e){let t=zt.get(e.areas);t||(t=new Map,zt.set(e.areas,t));const n=function(e){const t=e.config;return[e.areas.length,e.dimensions.width,e.dimensions.height,t.cellSize??"",t.columns??"",t.layoutPadding??"",t.gridOrigin?.join(",")??"",t.maxSamples??"",Tt(t.featureFilter),Tt(t.dotFilter),_t(e)].join("::")}(e),o=t.get(n);if(o)return o;const r=Vt(e.areas,e.scales,e.dimensions,e.config);if(t.size>=12){const e=t.keys().next().value;void 0!==e&&t.delete(e)}return t.set(n,r),r}(e),n=e.config,o=n.shape??"circle",r=Math.max(.5,Ot(n.dotRadius)??t.cellSize*Et(n.radiusRatio??.24,.05,.5)),i=n.gridOrigin?.[0]??0,a=n.gridOrigin?.[1]??0;return{nodes:t.dots.map((s,c)=>{const l=i+(s.gridColumn+.5)*t.cellSize,u=a+(s.gridRow+.5)*t.cellSize,d=Rt(s,n.categoryAccessor),h=Rt(s,n.fillAccessor),f={fill:null!=h?h+"":null!=d?e.resolveColor(d+""):e.theme.categorical[0]??"#4f86c6",fillOpacity:.92,strokeWidth:0,..."function"==typeof n.markStyle?n.markStyle(s,c):n.markStyle},m=`dot-${s.gridRow}-${s.gridColumn}`;if("circle"===o)return{type:"point",x:l,y:u,r:r,style:f,datum:s,interactive:!1,pointId:m,_transitionKey:m};const p="hexagon"===o?function(e,t,n){return Kt(Array.from({length:6},(o,r)=>{const i=-Math.PI/2+r*(Math.PI/3);return[e+Math.cos(i)*n,t+Math.sin(i)*n]}))}(l,u,r):function(e,t,n){return Kt([[e-n,t-n],[e+n,t-n],[e+n,t+n],[e-n,t+n]])}(l,u,r);return{type:"geoarea",pathData:p,centroid:[l,u],bounds:[[l-r,u-r],[l+r,u+r]],screenArea:"hexagon"===o?3*Math.sqrt(3)*r*r/2:(2*r)**2,style:f,datum:s,group:s.featureId,interactive:!1}}),overlays:n.showOutline?Nt("g",{"aria-hidden":"true",pointerEvents:"none",children:t.features.map((t,o)=>{const r=e.scales.geoPath(t);return r?Nt("path",{d:r,fill:"none",stroke:n.outlineStyle?.stroke??"currentColor",strokeOpacity:n.outlineStyle?.opacity??n.outlineStyle?.fillOpacity??.22,strokeWidth:n.outlineStyle?.strokeWidth??.7,strokeDasharray:n.outlineStyle?.strokeDasharray,strokeLinecap:n.outlineStyle?.strokeLinecap,vectorEffect:"non-scaling-stroke"},Pt(t,o)):null})}):null,restyle:(e,t)=>t?.isActive&&e.datum?{opacity:t.predicate(e.datum)?1:.14}:{opacity:1}}},Zt=e=>{const t=e.config,n=t.nodeWidth??80,o=t.nodeHeight??30,r=t.orientation??"vertical",i=t.edgeCurve??"curved",a=!1!==t.showLabels,s=t.labelAccessor??"id",c="function"==typeof s?s:e=>ge(e,s,e.id??"")+"",l=new Map,u=[],d=[],h=e=>{const t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??n,h:("number"==typeof t.height?t.height:e.height)??o}};for(const n of e.nodes){const{x:o,y:r,w:i,h:s}=h(n);null!=o&&null!=r&&(l.set(n.id,{x:o,y:r,w:i,h:s}),u.push({type:"rect",x:o-i/2,y:r-s/2,w:i,h:s,style:{fill:t.nodeFill??e.resolveColor(n.id),stroke:`var(--semiotic-surface, ${e.theme.semantic.surface??"#fff"})`,strokeWidth:1.5},datum:n,id:n.id,label:c(n)+""}),a&&d.push({x:o,y:r,text:c(n)+"",anchor:"middle",baseline:"middle",fontSize:11}))}const f=[];for(const t of e.edges){const n="string"==typeof t.target?t.target:t.target.id,o=l.get("string"==typeof t.source?t.source:t.source.id),a=l.get(n);if(!o||!a)continue;const s="vertical"===r?{x:o.x,y:o.y+o.h/2}:{x:o.x+o.w/2,y:o.y},c="vertical"===r?{x:a.x,y:a.y-a.h/2}:{x:a.x-a.w/2,y:a.y};if("line"===i)f.push({type:"line",x1:s.x,y1:s.y,x2:c.x,y2:c.y,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1},datum:t});else{const n=(s.y+c.y)/2,o=(s.x+c.x)/2;f.push({type:"curved",pathD:"vertical"===r?`M${s.x},${s.y} C${s.x},${n} ${c.x},${n} ${c.x},${c.y}`:`M${s.x},${s.y} C${o},${s.y} ${o},${c.y} ${c.x},${c.y}`,style:{stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#999"})`,strokeWidth:1,fill:"none"},datum:t})}}return{sceneNodes:u,sceneEdges:f,labels:d}},Ut=e=>{const t=e.config,n=t.nodeWidth??100,o=t.nodeHeight??36,r=t.edgeStyle??"polyline",i=!1!==t.showLabels,a=t.labelAccessor??"label",s="function"==typeof a?a:e=>ge(e,a,e.id??"")+"",c=new Map,l=[],u=[],d=e=>{const t=e.data??{};return{x:"number"==typeof t.x?t.x:e.x,y:"number"==typeof t.y?t.y:e.y,w:("number"==typeof t.width?t.width:e.width)??n,h:("number"==typeof t.height?t.height:e.height)??o}};for(const n of e.nodes){const{x:o,y:r,w:a,h:h}=d(n);null!=o&&null!=r&&(c.set(n.id,{x:o,y:r,w:a,h:h}),l.push({type:"rect",x:o-a/2,y:r-h/2,w:a,h:h,style:{fill:t.nodeFill??e.resolveColor(n.id),stroke:`var(--semiotic-border, ${e.theme.semantic.border??"#888"})`,strokeWidth:1.5},datum:n,id:n.id,label:s(n)+""}),i&&u.push({x:o,y:r,text:s(n)+"",anchor:"middle",baseline:"middle",fontSize:11}))}const h=t.edgeStroke??`var(--semiotic-border, ${e.theme.semantic.border??"#666"})`,f=[];for(const t of e.edges){const e="string"==typeof t.target?t.target:t.target.id,n=c.get("string"==typeof t.source?t.source:t.source.id),o=c.get(e);if(!n||!o)continue;const i=t.data??{},a=Array.isArray(i.points)?i.points:t.points;if(a&&a.length>=2)if("smooth"!==r||3>a.length){const e="M"+a.map(e=>`${e.x},${e.y}`).join(" L ");f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else{let e=`M${a[0].x},${a[0].y}`;for(let t=1;a.length-1>t;t++)e+=` Q${a[t].x},${a[t].y} ${(a[t].x+a[t+1].x)/2},${(a[t].y+a[t+1].y)/2}`;const n=a[a.length-1];e+=` T${n.x},${n.y}`,f.push({type:"curved",pathD:e,style:{stroke:h,strokeWidth:1,fill:"none"},datum:t})}else f.push({type:"line",x1:n.x,y1:n.y,x2:o.x,y2:o.y,style:{stroke:h,strokeWidth:1},datum:t})}return{sceneNodes:l,sceneEdges:f,labels:u}};import{createElement as Jt}from"react";var en=e=>"number"==typeof e&&Number.isFinite(e);function tn(e,t){const n="function"==typeof t?t(e):e[t];return en(n)?n:void 0}function nn(e){return[...e].sort((e,t)=>e.localeCompare(t))}function on(e,t,n){const o=new Map([[e,0]]),r=[e];for(;r.length>0;){const e=r.shift(),i=o.get(e);for(const a of nn(n.get(e)??[]))t.has(a)&&!o.has(a)&&(o.set(a,i+1),r.push(a))}return o}function rn(e,t,n){return[...on(e,t,n).entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))[0][0]}function an(e,t,n){const o=new Set(e),r=e.filter(e=>1>=(t.get(e)?.size??0))[0]??e[0],i=on(n&&o.has(n)?n:rn(rn(r,o,t),o,t),o,t),a=Math.max(0,...i.values()),s=Array.from({length:a+1},()=>[]);for(const t of e)s[i.get(t)??0].push(t);s.forEach(e=>e.sort((e,t)=>e.localeCompare(t)));const c=(e,n)=>{const o=new Map(s[n].map((e,t)=>[e,t])),r=e=>{const n=[...t.get(e)??[]].map(e=>o.get(e)).filter(e=>null!=e);return 0===n.length?1/0:n.reduce((e,t)=>e+t,0)/n.length};s[e].sort((e,t)=>r(e)-r(t)||e.localeCompare(t))};for(let e=0;4>e;e+=1){for(let e=1;s.length>e;e+=1)c(e,e-1);for(let e=s.length-2;e>=0;e-=1)c(e,e+1)}return s}function sn(e,t,n,o={}){const r=Math.max(0,o.padding??36),i=Math.max(0,o.componentGap??26),a=o.xAccessor??"x",s=o.yAccessor??"y",c=e.map(e=>({...e,authoredX:tn(e.data,a),authoredY:tn(e.data,s)})),l=c.length>0&&c.every(e=>en(e.authoredX)&&en(e.authoredY)),u="authored"===o.layoutMode||"automatic"!==o.layoutMode&&l,d=[];if(u&&!l&&d.push("Authored transit layout requested, but at least one station has no finite x/y position; using automatic topology layout."),!u||!l){l||"automatic"===o.layoutMode||d.push("Complete station positions were not supplied; using the deterministic automatic topology layout.");const a=function(e,t,n,o,r,i){const a=function(e,t){const n=new Map(e.map(e=>[e,new Set]));for(const e of t)n.has(e.source)&&n.has(e.target)&&(n.get(e.source)?.add(e.target),n.get(e.target)?.add(e.source));return n}(e.map(e=>e.id),t),s=function(e){const t=new Set(e.keys()),n=[];for(;t.size>0;){const o=nn(t)[0],r=[o],i=[];for(t.delete(o);r.length>0;){const n=r.shift();i.push(n);for(const o of nn(e.get(n)??[]))t.has(o)&&(t.delete(o),r.push(o))}n.push(i.sort((e,t)=>e.localeCompare(t)))}return n.sort((e,t)=>t.length-e.length||e[0].localeCompare(t[0]))}(a),c=new Map(e.map(e=>[e.id,e.data])),l=new Map,u=Math.max(0,n.width),d=Math.max(0,n.height),h=Math.min(o,u/2),f=Math.min(o,d/2),m=Math.max(0,d-2*f),p=s.length>1?Math.min(r,m/s.length):0,g=Math.max(0,m-p*Math.max(0,s.length-1)),y=s.reduce((e,t)=>e+Math.sqrt(t.length),0);let x=f;for(const e of s){const t=g*(Math.sqrt(e.length)/y),n=an(e,a,i),o=Math.max(0,u-2*h);n.forEach((e,r)=>{const i=1===n.length?u/2:h+r/(n.length-1)*o;e.forEach((n,o)=>{l.set(n,{id:n,x:i,y:1===e.length?x+t/2:x+o/(e.length-1)*t,data:c.get(n)})})}),x+=t+p}return l}(e,t,n,r,i,o.rootId);if("right-to-left"===o.direction)for(const e of a.values())e.x=n.width-e.x;return{positions:a,mode:"automatic",warnings:d,projectAuthoredPoint:e=>e}}const h=c.map(e=>e.authoredX),f=c.map(e=>e.authoredY),m=Math.min(...h),p=Math.max(...h),g=Math.min(...f),y=Math.max(...f),x=Math.max(1,n.width-2*r),b=Math.max(1,n.height-2*r),w=e=>({x:p===m?n.width/2:r+(e.x-m)/(p-m)*x,y:y===g?n.height/2:r+(e.y-g)/(y-g)*b}),M=new Map;for(const e of c){const t=w({x:e.authoredX,y:e.authoredY});M.set(e.id,{id:e.id,...t,data:e.data})}return{positions:M,mode:"authored",warnings:d,projectAuthoredPoint:w}}function cn(e,t){const n=t.x-e.x,o=t.y-e.y,r=Math.abs(n),i=Math.abs(o);if(.001>r||.001>i||.001>Math.abs(r-i))return[e,t];const a=Math.sign(n),s=Math.sign(o);if(r>i){const n=(r-i)/2;return[e,{x:e.x+a*n,y:e.y},{x:t.x-a*n,y:t.y},t]}const c=(i-r)/2;return[e,{x:e.x,y:e.y+s*c},{x:t.x,y:t.y-s*c},t]}function ln(e,t){if(0===t||2>e.length)return e.map(e=>({...e}));const n=(e,t)=>{const n=t.x-e.x,o=t.y-e.y,r=Math.hypot(n,o)||1;return{x:-o/r,y:n/r}};return e.map((o,r)=>{const i=r>0?n(e[r-1],o):null,a=e.length-1>r?n(o,e[r+1]):null;if(!i||!a){const e=a??i??{x:0,y:0};return{x:o.x+e.x*t,y:o.y+e.y*t}}let s=i.x+a.x,c=i.y+a.y;const l=Math.hypot(s,c);if(.001>l)return{x:o.x+a.x*t,y:o.y+a.y*t};s/=l,c/=l;const u=s*a.x+c*a.y;if(.001>Math.abs(u))return{x:o.x+a.x*t,y:o.y+a.y*t};const d=4*Math.abs(t),h=Math.max(-d,Math.min(d,t/u));return{x:o.x+s*h,y:o.y+c*h}})}function un(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;const n=Math.max(0,t);let o=`M${e[0].x},${e[0].y}`;for(let t=1;e.length-1>t;t+=1){const r=e[t-1],i=e[t],a=e[t+1],s=Math.hypot(i.x-r.x,i.y-r.y),c=Math.hypot(a.x-i.x,a.y-i.y),l=Math.min(n,s/2,c/2);if(.001>=l){o+=` L${i.x},${i.y}`;continue}const u={x:i.x+(r.x-i.x)/s*l,y:i.y+(r.y-i.y)/s*l},d={x:i.x+(a.x-i.x)/c*l,y:i.y+(a.y-i.y)/c*l};o+=` L${u.x},${u.y} Q${i.x},${i.y} ${d.x},${d.y}`}const r=e[e.length-1];return`${o} L${r.x},${r.y}`}function dn(e){return Me(e)??e}function hn(e){return"string"==typeof e?e:e.id}function fn(e,t){const n=t.lineAccessor;let o;return o="function"==typeof n?n(e.data):"string"==typeof n?e.data[n]:e.data.lines??e.data.line??e.data.route??e.data.group,function(e){const t=(Array.isArray(e)?e:null==e?[]:[e]).map(e=>"object"==typeof e?{...e,id:e.id+""}:{id:e+""});return t.length>0?t:[{id:"network"}]}(o)}function mn(e,t,n){const o=t.sourceColorAccessor,r="function"==typeof o?o(e.data):"string"==typeof o?e.data[o]:e.data.color;return"string"==typeof r&&r?r:n(e.id)}function pn(e,t,n,o){if(e.color)return e.color;const r=n.lineColors&&Object.prototype.hasOwnProperty.call(n.lineColors,e.id)?n.lineColors[e.id]:void 0;if("string"==typeof r&&r)return r;const i=n.lineColorAccessor,a="function"==typeof i?i(t.data):"string"==typeof i?t.data[i]:t.data.color;return"string"==typeof a?a:o(e.id)}function gn(e,t){const n=new Map((t.lineOrder??[]).map((e,t)=>[e,t]));return[...e].sort((e,t)=>(n.get(e)??1/0)-(n.get(t)??1/0)||e.localeCompare(t))}function yn(e,t){const n=new Map((e.authoredOrder??t.lineOrder??[]).map((e,t)=>[e,t]));return[...e.lines.values()].sort((e,t)=>(n.get(e.descriptor.id)??1/0)-(n.get(t.descriptor.id)??1/0)||e.descriptor.id.localeCompare(t.descriptor.id))}function xn(e,t,n,o){if("authored"!==t.mode)return null;const r=e.data[n.pointsAccessor??"points"];if(!Array.isArray(r))return null;const i=r.map(e=>"number"==typeof e.x&&"number"==typeof e.y?t.projectAuthoredPoint({x:e.x,y:e.y}):null).filter(e=>null!=e);return 0===i.length?null:o?i.reverse():i}function bn(e,t){return se(n=>{for(const[t,o]of Object.entries(e.data))n(t,o);n("source",e.source),n("target",e.target),n("lineId",t.id),n("lineLabel",t.label??t.id)})}function wn(e,t,n,o,r,i){if(!1===i.showLabels)return[];const a=i.labelFontSize??11,s=[],c=[],l=[...e].sort((e,t)=>(n.get(t.id)?.size??0)-(n.get(e.id)?.size??0)||e.id.localeCompare(t.id));for(const e of l){const n=t.get(e.id);if(!n)continue;const l=("function"==typeof i.labelAccessor?i.labelAccessor(e.data):ge(e.data,i.labelAccessor??"label",e.id)+"")||e.id,u=Math.max(2*a,l.length*a*.58),d=1.25*a,h=Math.max(i.interchangeRadius??7,o.get(e.id)??i.stationRadius??4)+5,f=[{x:n.x+h,y:n.y,anchor:"start",left:n.x+h},{x:n.x-h,y:n.y,anchor:"end",left:n.x-h-u},{x:n.x,y:n.y-h,anchor:"middle",left:n.x-u/2},{x:n.x,y:n.y+h,anchor:"middle",left:n.x-u/2}].map((e,t)=>{const n={left:e.left,right:e.left+u,top:e.y-d/2,bottom:e.y+d/2},o=s.filter(e=>{return(o=e).right>(t=n).left&&t.right>o.left&&o.bottom>t.top&&t.bottom>o.top;var t,o}).length;return{candidate:e,box:n,score:1e4*o+10*(Math.max(0,-n.left)+Math.max(0,n.right-r.width)+Math.max(0,-n.top)+Math.max(0,n.bottom-r.height))+t}}).sort((e,t)=>e.score-t.score)[0];s.push(f.box),c.push({x:f.candidate.x,y:f.candidate.y,text:l,anchor:f.candidate.anchor,baseline:"middle",fontSize:a,fill:i.labelColor??"var(--semiotic-text, #222)",stroke:"var(--semiotic-bg, white)",strokeWidth:3,paintOrder:"stroke"})}return c}var Mn=e=>{const t=e.config??{},n=t.mode??"primary",o=t.dimOpacity??.14,r=t=>e.selection?.isActive&&!e.selection.predicate(t)?o:1,i=e.nodes.map(e=>({id:e.id,data:dn(e),wrapper:e})).sort((e,t)=>e.id.localeCompare(t.id)),a=e.edges.map(e=>({source:hn(e.source),target:hn(e.target),data:dn(e),wrapper:e})).sort((e,t)=>e.source.localeCompare(t.source)||e.target.localeCompare(t.target)),s=sn(i,a,e.dimensions.plot,t),c="source-rooted"===t.lineMode?function(e,t,n,o){const r=new Set(e.map(e=>e.id)),i=new Map(e.map(e=>[e.id,0])),a=new Map(e.map(e=>[e.id,[]]));for(const e of t)r.has(e.source)&&r.has(e.target)&&(i.set(e.target,(i.get(e.target)??0)+1),a.get(e.source)?.push(e));for(const e of a.values())e.sort((e,t)=>e.target.localeCompare(t.target)||e.source.localeCompare(t.source));const s=e.filter(e=>0===(i.get(e.id)??0)).sort((e,t)=>e.id.localeCompare(t.id)),c=new Map,l=new Map(e.map(e=>[e.id,new Map]));for(const e of s){const t="function"==typeof n.labelAccessor?n.labelAccessor(e.data):ge(e.data,n.labelAccessor??"label",e.id),r={id:e.id,label:t+"",color:mn(e,n,o)},i=new Set,s=[e.id];for(;s.length>0;){const e=s.shift();if(!i.has(e)){i.add(e),l.get(e)?.set(r.id,r);for(const t of a.get(e)??[]){let e=c.get(t);e||(e=new Map,c.set(t,e)),e.set(r.id,r),i.has(t.target)||s.push(t.target)}}}}const u=e=>[...e].sort((e,t)=>e.id.localeCompare(t.id));return{byEdge:new Map(t.map(e=>[e,u(c.get(e)?.values()??[])])),byNode:new Map(e.map(e=>[e.id,u(l.get(e.id)?.values()??[])]))}}(i,a,t,e.resolveColor):void 0,l=function(e,t,n){const o=new Map;for(const r of e){const e=r.target>r.source?`${r.source}\0${r.target}`:`${r.target}\0${r.source}`;let i=o.get(e);i||(i={key:e,source:r.source,target:r.target,lines:new Map},o.set(e,i));const a=r.data.lineOrder;Array.isArray(a)&&(i.authoredOrder=a.map(String));const s=n?.byEdge.get(r)??fn(r,t);for(const e of s)i.lines.has(e.id)||i.lines.set(e.id,{descriptor:e,edge:r})}return[...o.values()].sort((e,t)=>e.key.localeCompare(t.key))}(a,t,c),u=new Map(i.map(e=>[e.id,new Set])),d=new Map;if(c)for(const[e,t]of c.byNode)for(const n of t)u.get(e)?.add(n.id),n.color&&d.set(n.id,n.color);const h=Math.max(1,t.lineWidth??("primary"===n?6:"compact"===n?3.5:2)),f=Math.max(0,t.lineGap??("primary"===n?2:"compact"===n?1:.5)),m=new Map,p=[];for(const n of l){const o=s.positions.get(n.source),i=s.positions.get(n.target);if(!o||!i)continue;const a=yn(n,t),c=(a.length-1)/2*(h+f)+h/2;for(const e of[n.source,n.target])m.set(e,Math.max(m.get(e)??0,c));a.forEach((c,l)=>{u.get(n.source)?.add(c.descriptor.id),u.get(n.target)?.add(c.descriptor.id);const m=xn(c.edge,s,t,c.edge.source!==n.source),g=ln(m?[o,...m,i]:cn(o,i),(l-(a.length-1)/2)*(h+f)),y=bn(c.edge,c.descriptor),x=pn(c.descriptor,c.edge,t,e.resolveColor);d.has(c.descriptor.id)||d.set(c.descriptor.id,x),p.push({type:"curved",id:`${n.key}:${c.descriptor.id}`,label:`${c.descriptor.label??c.descriptor.id}: ${c.edge.source} to ${c.edge.target}`,pathD:un(g,t.cornerRadius??10),style:{fill:"none",stroke:x,strokeWidth:h,strokeLinecap:"round",opacity:r(y)},datum:y,accessibleDatum:y,accessibility:{label:`${c.descriptor.label??c.descriptor.id}, ${c.edge.source} to ${c.edge.target}`,tableFields:{line:c.descriptor.label??c.descriptor.id,source:c.edge.source,target:c.edge.target}}})})}const g=new Map,y=[],x=[],b=e=>(("function"==typeof t.labelAccessor?t.labelAccessor(e.data):ge(e.data,t.labelAccessor??"label",e.id))||e.id)+"";if("minimap"===n){const n=new Map;for(const e of i){const t=s.positions.get(e.id);if(!t)continue;const o=`${t.x}\0${t.y}`;let r=n.get(o);r||(r={x:t.x,y:t.y,nodes:[],lineIds:new Set,bundleRadius:0},n.set(o,r)),r.nodes.push(e);for(const t of u.get(e.id)??[])r.lineIds.add(t);r.bundleRadius=Math.max(r.bundleRadius,m.get(e.id)??0)}const o=[...n.values()].sort((e,t)=>e.x-t.x||e.y-t.y||e.nodes[0].id.localeCompare(t.nodes[0].id));for(const n of o){const o=gn(n.lineIds,t),i=o.length>1||n.nodes.length>1||n.nodes.some(e=>!0===e.data.interchange||!0===e.data.transfer),a=i?t.interchangeRadius??Math.max(5,n.bundleRadius):t.stationRadius??Math.max(3.5,n.bundleRadius);for(const e of n.nodes)g.set(e.id,a);const s=n.nodes.map(b).join(" / "),c=n.nodes.map(e=>e.id).join("--"),l=1===n.nodes.length?n.nodes[0].data:se(e=>{e("id",c),e("label",s),e("stationIds",n.nodes.map(e=>e.id)),e("stations",n.nodes.map(e=>e.data)),e("lineIds",o),e("interchange",i)}),u={label:`${s}${i?", interchange":""}`,tableFields:{station:s,lines:o.join(", ")}};o.length>1?(o.forEach((t,i)=>{const s={type:"arc",cx:n.x,cy:n.y,innerR:0,outerR:a,startAngle:-Math.PI/2+i/o.length*Math.PI*2,endAngle:-Math.PI/2+(i+1)/o.length*Math.PI*2,style:{fill:d.get(t)??e.resolveColor(t),stroke:"none",opacity:r(l)},datum:null,id:`${c}:${t}`};y.push(s)}),y.push({type:"circle",cx:n.x,cy:n.y,r:a,style:{fill:"transparent",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:r(l)},datum:l,accessibleDatum:l,accessibility:u,id:c,label:s})):y.push({type:"circle",cx:n.x,cy:n.y,r:a,style:{fill:(o[0]&&d.get(o[0]))??t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:1.25,opacity:r(l)},datum:l,accessibleDatum:l,accessibility:u,id:c,label:s})}}else for(const e of i){const o=s.positions.get(e.id);if(!o)continue;const i=gn(u.get(e.id)??[],t),a=i.length>1||!0===e.data.interchange||!0===e.data.transfer,c=a?t.interchangeRadius??Math.max("primary"===n?7:5,m.get(e.id)??0):t.stationRadius??("primary"===n?4:2.75);g.set(e.id,c);const l=b(e);if(y.push({type:"circle",cx:o.x,cy:o.y,r:c,style:null!=t.renderStation?{fill:"transparent",stroke:"transparent"}:{fill:t.stationFill??"var(--semiotic-bg, white)",stroke:t.stationStroke??"var(--semiotic-text, #222)",strokeWidth:a?"primary"===n?3:2:1.5,opacity:r(e.data)},datum:e.data,accessibleDatum:e.data,accessibility:{label:`${l}${a?", interchange":""}`,tableFields:{station:l,lines:i.join(", ")}},id:e.id,label:l}),t.renderStation){const s=t.renderStation({station:e.data,x:o.x,y:o.y,radius:c,lineIds:i,interchange:a,mode:n});null!=s&&x.push(Jt("g",{key:e.id,opacity:r(e.data),style:{pointerEvents:"none"}},s))}}const w=x.length>0?Jt("g",{className:"transit-diagram-stations"},...x):void 0,M={sceneEdges:p,sceneNodes:y,overlays:w,labels:wn(i,s.positions,u,g,e.dimensions.plot,"primary"===n?t:{...t,showLabels:!1})};return x.length>0||"minimap"===n?M:{...M,restyle:(e,t)=>t?.isActive&&!t.predicate(e.datum)?{opacity:o}:{opacity:1},restyleEdge:(e,t)=>t?.isActive&&!t.predicate(e.datum)?{opacity:o}:{opacity:1}}};import{jsx as vn,jsxs as kn}from"react/jsx-runtime";function $n(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)}function An(e){return(1e-12>Math.abs(e)?0:e)+""}import{jsx as Sn,jsxs as In}from"react/jsx-runtime";var Cn={"topic-source":"#1f7a8c","topic-sink":"#b4451f","topic-bridge":"#4b5a82",processor:"#34344a",unknown:"#5a5a6a"},Nn={internal:"var(--semiotic-border, #6b6b7d)","cross-subtopology":"var(--semiotic-info, #6a8caf)","topic-bridge":"var(--semiotic-secondary, #8b78c4)",back:"var(--semiotic-danger, #e0556b)"};function zn(e){return Array.isArray(e)?e.map((e,t)=>"string"==typeof e?{storeName:e,slotIndex:t}:{storeName:(e.storeName??"")+"",slotIndex:e.slotIndex??t}):[]}function Fn(e,t){return Number.isFinite(e)?ae(e,0,1):t}var jn=e=>{const t=e.config||{},n=e.dimensions.plot,o=t.layerAccessor??"x",r=t.rowAccessor??"y",i=t.partitionAccessor??"partition",a=t.semanticAccessor??"semantic",s=t.labelAccessor??"label",c=t.storesAccessor??"stores",l=t.backEdgeAccessor??"isBackEdge",u=t.edgeTypeAccessor??"edgeType",d={...Cn,...t.partitionColors},h={...Nn,...t.edgeColors},f=t.accentColor??"var(--semiotic-focus, #ffcc33)",m=t.borderColor??"var(--semiotic-border, #555)",p=t.dimOpacity??.14,g=t.edgeOpacity??.5,y=t.edgeWidth??1.25,x=t.backEdgeWidth??t.edgeWidth??1.5,b=!1!==t.showStoreChips,w=t.storeChipColor??"var(--semiotic-info, #6a8caf)",M=t.hullGroupAccessor;let v=t.layerCount,k=t.maxLayerSize;if(null==v||null==k){let t=0;const n=new Map;for(const r of e.nodes){const e=Math.round(Number(ge(r,o,0)));t=Math.max(t,e),n.set(e,(n.get(e)??0)+1)}v=v??t+1,k=k??Math.max(1,...n.values())}const $=n.width/Math.max(1,v),A=n.height/Math.max(1,k);let S=Math.min(t.nodeWidth??172,Math.max(8,$-(t.minGapX??26))),I=Math.min(t.nodeHeight??54,Math.max(8,A-(t.minGapY??18)));const C=t.lod&&"auto"!==t.lod?t.lod:16>S?"dot":48>S?"icon":108>S?"compact":"full";if("dot"===C){const e=Math.min(S,I,11);S=e,I=e}const N=Math.max(1,n.width-S),z=Math.max(1,n.height-I),F=Math.max(1,k-1),j=e=>n.x+S/2+(v>1?e/(v-1):.5)*N,W=e=>n.y+I/2+(e+F/2)/F*z,E=t.reachableIds?new Set(t.reachableIds):null,O=t.selectedId??null,R=e.selection,L=new Map,P=new Map,q=[],T=null==M?null:new Map,D=[];for(const t of e.nodes){const e=t.id,n=Number(ge(t,o,0)),l=Number(ge(t,r,0)),u=ge(t,i,"processor")+"",h=ge(t,a,"processor")+"",g=ge(t,s,e)+"",y=zn(ge(t,c,[])),x=t.data??t,b=j(n),w=W(l);L.set(e,{cx:b,cy:w});const v=E?E.has(e):null,k=R?.isActive?R.predicate(x):null,$=null!==v?!v:null!==k&&!k;P.set(e,$);const A=null!=O&&e===O,N=$&&!A?p:1,z=Object.prototype.hasOwnProperty.call(d,u)?d[u]:d.unknown;if("dot"===C?q.push({type:"circle",cx:b,cy:w,r:S/2,style:{fill:z,opacity:N,stroke:A?f:"transparent",strokeWidth:A?2:0},datum:t,id:e,label:g}):(q.push({type:"rect",x:b-S/2,y:w-I/2,w:S,h:I,style:{fill:z,opacity:N,stroke:A?f:m,strokeWidth:A?3:1},datum:t,id:e,label:g}),D.push({id:e,cx:b,cy:w,partition:u,semantic:h,label:g,stores:y,opacity:N,selected:A,node:x})),T&&null!=M){const n=ge(t,M,null);if(null!=n){const t=n+"",o=T.get(t)??[];o.push({id:e,x:b-S/2,y:w-I/2,w:S,h:I}),T.set(t,o)}}}const B=[];for(const t of e.edges){const e="string"==typeof t.source?t.source:t.source.id,n="string"==typeof t.target?t.target:t.target.id,o=L.get(e),r=L.get(n);if(!o||!r)continue;const i=!!ge(t,l,!1),a=ge(t,u,"internal")+"",s=P.get(e)||P.get(n)?Math.min(g,1.4*p):g,c=i?h.back:Object.prototype.hasOwnProperty.call(h,a)?h[a]:h.internal;let d;if(i){const e=o.cx,t=o.cy+I/2,n=r.cx,i=r.cy+I/2,a=Math.max(48,.28*Math.abs(e-n))+I;d=`M${e},${t} C${e},${t+a} ${n},${i+a} ${n},${i}`}else{const e=o.cx+S/2,t=o.cy,n=r.cx-S/2,i=r.cy,a=(e+n)/2;d=`M${e},${t} C${a},${t} ${a},${i} ${n},${i}`}const f={type:"curved",pathD:d,style:{stroke:c,strokeWidth:i?x:y,fill:"none",opacity:s,...i?{strokeDasharray:"5 4",strokeLinecap:"round"}:{}},datum:t};B.push(f)}const V=0===D.length?null:Sn("g",{className:"lineage-dag-glyphs",children:D.map(e=>function(e,t){const{w:n,h:o,lod:r}=t,i="icon"===r?Math.min(n,o):Math.min(o-14,26),a=(Object.prototype.hasOwnProperty.call(t.partColors,e.partition)?t.partColors[e.partition]:t.partColors.unknown)??"#5a5a6a",s="icon"===r?0:8+i+8,c=null!=t.renderIcon?t.renderIcon({semantic:e.semantic,partition:e.partition,size:i,color:a,node:e.node}):function(e,t,n){const o=t.startsWith("topic")?"T":{source:"SR",sink:"SK",filter:"FL",map:"MP",aggregate:"AG",reduce:"RD","join-this":"JN","join-other":"JN",merge:"MG",suppress:"SP",select:"SE",tostream:"TS"}[e]??"PR";return In("g",{children:[Sn("rect",{width:n,height:n,rx:4,fill:"rgba(255,255,255,0.08)",stroke:"rgba(255,255,255,0.18)"}),Sn("text",{x:n/2,y:n/2+.5,textAnchor:"middle",dominantBaseline:"middle",fontSize:.42*n,fontWeight:700,fill:"var(--semiotic-text, #fff)",children:o})]})}(e.semantic,e.partition,i),l="full"===r,u="icon"!==r,d="full"===r&&t.showChips&&e.stores.length>0;return In("g",{transform:`translate(${e.cx-n/2}, ${e.cy-o/2})`,opacity:e.opacity,style:{pointerEvents:"none"},children:[Sn("g",{transform:`translate(${"icon"===r?(n-i)/2:8}, ${(o-i)/2})`,children:c}),u&&Sn("foreignObject",{x:s,y:l?o/2-12:o/2-9,width:Math.max(8,n-s-8),height:18,style:{pointerEvents:"none"},children:Sn("div",{title:e.label,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, inherit)",fontSize:"full"===r?12.5:11.5,fontWeight:600,color:"var(--semiotic-text, #f4f4f8)",lineHeight:"18px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.label})}),l&&Sn("text",{x:s,y:o/2-16,dominantBaseline:"middle",fontSize:9.5,fontWeight:500,fill:"var(--semiotic-text-secondary, #b9b9c8)",style:{textTransform:"uppercase",letterSpacing:"0.04em"},children:t.typeLabel?t.typeLabel({semantic:e.semantic,partition:e.partition,node:e.node}):e.partition.startsWith("topic")?"topic":e.semantic}),d&&e.stores.map((e,n)=>Sn("rect",{x:s+15*n,y:o-10,width:12,height:5,rx:1.5,fill:t.chipColor,children:Sn("title",{children:e.storeName})},e.storeName+n))]},e.id)}(e,{w:S,h:I,lod:C,partColors:d,chipColor:w,showChips:b,renderIcon:t.renderIcon,typeLabel:t.typeLabel}))}),H=T&&T.size>0?function(e,t){const n=Array.from(e.entries()).sort(([e],[t])=>t>e?-1:e>t?1:0);return vn("g",{className:"lineage-dag-hulls","aria-hidden":"true",style:{pointerEvents:"none"},children:n.map(([e,n])=>{const o=function(e,t){if(0===t||3>e.length)return e;const n=0>e.reduce((t,n,o)=>{const r=e[(o+1)%e.length];return t+n.x*r.y-r.x*n.y},0)?-1:1;return e.map((o,r)=>{const i=e[(r-1+e.length)%e.length],a=e[(r+1)%e.length],s=Math.hypot(o.x-i.x,o.y-i.y)||1,c=Math.hypot(a.x-o.x,a.y-o.y)||1,l=n>0?{x:(o.y-i.y)/s,y:-(o.x-i.x)/s}:{x:-(o.y-i.y)/s,y:(o.x-i.x)/s},u=n>0?{x:(a.y-o.y)/c,y:-(a.x-o.x)/c}:{x:-(a.y-o.y)/c,y:(a.x-o.x)/c},d={x:l.x+u.x,y:l.y+u.y},h=Math.hypot(d.x,d.y);if(1e-9>h)return{x:o.x+u.x*t,y:o.y+u.y*t};const f=d.x/h,m=d.y/h,p=t/Math.max(1e-6,f*u.x+m*u.y);return{x:o.x+f*p,y:o.y+m*p}})}(function(e){const t=e.slice().sort((e,t)=>e.x-t.x||e.y-t.y).filter((e,t,n)=>0===t||e.x!==n[t-1].x||e.y!==n[t-1].y);if(2>=t.length)return t;const n=[];for(const e of t){for(;n.length>=2&&0>=$n(n[n.length-2],n[n.length-1],e);)n.pop();n.push(e)}const o=[];for(let e=t.length-1;e>=0;e--){const n=t[e];for(;o.length>=2&&0>=$n(o[o.length-2],o[o.length-1],n);)o.pop();o.push(n)}return n.pop(),o.pop(),n.concat(o)}(n.flatMap(e=>[{x:e.x,y:e.y},{x:e.x+e.w,y:e.y},{x:e.x+e.w,y:e.y+e.h},{x:e.x,y:e.y+e.h}])),t.padding),r=function(e,t){if(0===e.length)return"";if(3>e.length||0===t)return e.map((e,t)=>`${0===t?"M":"L"}${An(e.x)},${An(e.y)}`).join(" ")+" Z";const n=e.map((n,o)=>{const r=e[(o-1+e.length)%e.length],i=e[(o+1)%e.length],a=Math.hypot(r.x-n.x,r.y-n.y)||1,s=Math.hypot(i.x-n.x,i.y-n.y)||1,c=Math.min(t,a/2,s/2);return{point:n,incoming:{x:n.x+(r.x-n.x)/a*c,y:n.y+(r.y-n.y)/a*c},outgoing:{x:n.x+(i.x-n.x)/s*c,y:n.y+(i.y-n.y)/s*c}}}),o=n[0].outgoing;let r=`M${An(o.x)},${An(o.y)}`;for(let e=1;n.length>e;e++){const t=n[e];r+=` L${An(t.incoming.x)},${An(t.incoming.y)}`,r+=` Q${An(t.point.x)},${An(t.point.y)} ${An(t.outgoing.x)},${An(t.outgoing.y)}`}const i=n[0];return r+=` L${An(i.incoming.x)},${An(i.incoming.y)}`,r+=` Q${An(i.point.x)},${An(i.point.y)} ${An(i.outgoing.x)},${An(i.outgoing.y)} Z`,r}(o,t.radius),i=Object.prototype.hasOwnProperty.call(t.colors??{},e)?t.colors?.[e]??t.resolveColor(e):t.resolveColor(e),a=n.every(e=>!0===t.dimById.get(e.id)&&e.id!==t.selectedId),s=Math.min(...o.map(e=>e.x)),c=Math.min(...o.map(e=>e.y)),l=t.label?.(e);return kn("g",{"data-lineage-hull":e,opacity:a?t.dimOpacity:void 0,children:[vn("path",{className:"lineage-dag-hull",d:r,fill:i,fillOpacity:t.fillOpacity,stroke:i,strokeOpacity:t.strokeOpacity,strokeWidth:1,vectorEffect:"non-scaling-stroke",style:{pointerEvents:"none"}}),l?vn("text",{className:"lineage-dag-hull-label",x:s+8,y:c+14,fill:i,fillOpacity:Math.max(t.strokeOpacity,.7),fontSize:11,fontWeight:600,style:{pointerEvents:"none"},children:l}):null]},e)})})}(T,{colors:t.hullColors,padding:null==t.hullPadding?16:pe(t.hullPadding),radius:null==t.hullRadius?12:pe(t.hullRadius),fillOpacity:Fn(t.hullFillOpacity,.08),strokeOpacity:Fn(t.hullStrokeOpacity,.4),label:t.hullLabel,resolveColor:e.resolveColor,dimById:P,selectedId:O,dimOpacity:p}):null;return H?{sceneNodes:q,sceneEdges:B,backgrounds:H,overlays:V}:{sceneNodes:q,sceneEdges:B,overlays:V}};import{jsx as Wn,jsxs as En}from"react/jsx-runtime";function On(e,t){return e.length>t?e.slice(0,Math.max(1,t-1))+"…":e}var Rn={rect:"process",round:"process",stadium:"terminal",subroutine:"subprocess",cylinder:"database",circle:"connector",diamond:"decision",hexagon:"preparation",flag:"process"};function Ln(e,t,n,o,r,i,a,s){const c=t-o/2,l=n-r/2,u={fill:i,stroke:a,strokeWidth:s};switch(e){case"diamond":return Wn("polygon",{points:`${t},${l} ${t+o/2},${n} ${t},${n+r/2} ${c},${n}`,...u});case"circle":return Wn("circle",{cx:t,cy:n,r:Math.min(o,r)/2,...u});case"stadium":case"round":return Wn("rect",{x:c,y:l,width:o,height:r,rx:"stadium"===e?r/2:8,ry:"stadium"===e?r/2:8,...u});case"hexagon":{const e=Math.min(.18*o,16);return Wn("polygon",{points:`${c+e},${l} ${t+o/2-e},${l} ${t+o/2},${n} ${t+o/2-e},${n+r/2} ${c+e},${n+r/2} ${c},${n}`,...u})}case"cylinder":{const e=Math.min(.16*r,8),t=`M${c},${l+e} a${o/2},${e} 0 0 1 ${o},0`;return En("g",{children:[Wn("path",{d:`M${c},${l+e} a${o/2},${e} 0 0 0 ${o},0 v${r-2*e} a${o/2},${e} 0 0 1 ${-o},0 z`,...u}),Wn("path",{d:t,fill:"none",stroke:a,strokeWidth:s})]})}case"subroutine":{const e=Math.min(8,.08*o);return En("g",{children:[Wn("rect",{x:c,y:l,width:o,height:r,rx:3,...u}),Wn("line",{x1:c+e,y1:l,x2:c+e,y2:l+r,stroke:a,strokeWidth:s}),Wn("line",{x1:c+o-e,y1:l,x2:c+o-e,y2:l+r,stroke:a,strokeWidth:s})]})}default:return Wn("rect",{x:c,y:l,width:o,height:r,rx:4,...u})}}var Pn=e=>{const t=e.config||{},n=e.dimensions.plot,o=t.direction??"TD",r="LR"===o||"RL"===o,i="BT"===o||"RL"===o,a=t.layerAccessor??"layer",s=t.rowAccessor??"row",c=t.labelAccessor??"label",l=t.shapeAccessor??"shape",u=t.edgeLabelAccessor??"label",d=t.nodeFill??"var(--semiotic-surface, #20242d)",h=t.nodeStroke??"var(--semiotic-border, #5a6573)",f=t.textColor??"var(--semiotic-text, #e6e6e6)",m=t.edgeColor??"var(--semiotic-text-secondary, #9aa0a6)",p=t.accentColor??"var(--semiotic-warning, #d49a00)";if(0===e.nodes.length)return{sceneNodes:[],overlays:null};const g=new Map;let y=0;for(const t of e.nodes){const e=Math.round(Number(ge(t,a,0)));y=Math.max(y,e);const n=g.get(e)||[];n.push(t),g.set(e,n)}const x=y+1;let b=1;for(const e of g.values())e.sort((e,t)=>Number(ge(e,s,0))-Number(ge(t,s,0))),b=Math.max(b,e.length);const w=r?n.width:n.height,M=r?n.height:n.width,v=w/x,k=M/(b+1),$=Math.max(44,Math.min(t.nodeWidth??150,r?v-36:.92*k)),A=Math.max(26,Math.min(t.nodeHeight??46,r?.7*k:.5*v)),S=(r?$:A)/2+6,I=Math.max(1,w-2*S),C=e=>(r?n.x:n.y)+S+(x>1?(i?x-1-e:e)/(x-1)*I:I/2),N=new Map,z=[],F=[];for(const[e,t]of g)t.forEach((o,i)=>{const a=C(e),s=(r?n.y:n.x)+(i+1)/(t.length+1)*M,u=r?a:s,m=r?s:a,g=ge(o,l,"rect")+"",y=ge(o,c,o.id)+"";N.set(o.id,{cx:u,cy:m,shape:g}),z.push({type:"rect",x:u-$/2,y:m-A/2,w:$,h:A,style:{fill:"transparent",stroke:"transparent"},datum:{id:o.id,name:y,type:Rn[g]??"process",shape:g},id:o.id,label:y}),F.push(En("g",{children:[Ln(g,u,m,$,A,d,"diamond"===g?p:h,1.5),Wn("text",{x:u,y:m,textAnchor:"middle",dominantBaseline:"central",fontSize:13,fill:f,style:{pointerEvents:"none"},children:On(y,Math.max(4,Math.floor(($-12)/7)))})]},"n-"+o.id))});const j=[];return e.edges.forEach((e,t)=>{const n="string"==typeof e.target?e.target:e.target.id,o=N.get("string"==typeof e.source?e.source:e.source.id),i=N.get(n);if(!o||!i)return;const a=r?o.cx+$/2:o.cx,s=r?o.cy:o.cy+A/2,c=r?i.cx-$/2:i.cx,l=r?i.cy:i.cy-A/2,d=r?`M${a},${s} C${(a+c)/2},${s} ${(a+c)/2},${l} ${c},${l}`:`M${a},${s} C${a},${(s+l)/2} ${c},${(s+l)/2} ${c},${l}`,p=Math.atan2(l-s,c-a),g=c-9*Math.cos(p),y=l-9*Math.sin(p),x=4.5*-Math.sin(p),b=4.5*Math.cos(p),w=`${c},${l} ${g+x},${y+b} ${g-x},${y-b}`,M=ge(e,u,void 0),v=(a+c)/2,k=(s+l)/2;j.push(En("g",{children:[Wn("path",{d:d,fill:"none",stroke:m,strokeWidth:1.4}),Wn("polygon",{points:w,fill:m}),"string"==typeof M&&M.length>0&&En("g",{children:[Wn("rect",{x:v-6.5*M.length/2-4,y:k-9,width:6.5*M.length+8,height:18,rx:3,fill:"var(--semiotic-bg, #11151c)",stroke:h,strokeWidth:.75}),Wn("text",{x:v,y:k,textAnchor:"middle",dominantBaseline:"central",fontSize:11,fill:f,style:{pointerEvents:"none"},children:M})]})]},"e-"+t))}),{sceneNodes:z,overlays:En("g",{className:"mermaid-dag",children:[j,F]})}};import{jsx as qn,jsxs as Tn}from"react/jsx-runtime";function Dn(e,t,n={}){const o=n.fingerprintRounds??3,r=[],i=new Set;for(const t of e)null==t.id||i.has(t.id)||(i.add(t.id),r.push(t.id));const{outAdj:a,inAdj:s,undirected:c}=Xn(r,t),l=_n(r,a,s,c,o).map(e=>({ids:e.ids,nodeCount:e.nodeCount,edgeCount:e.edgeCount,sinkCount:e.sinkCount,sourceCount:e.sourceCount,directed:e.directed,motif:e.motif,descriptor:Gn(e)})),u=new Map;for(const e of l){const t=u.get(e.motif);t?t.count+=1:u.set(e.motif,{motif:e.motif,descriptor:e.descriptor,count:1,directed:e.directed})}return{components:l,motifs:[...u.values()].sort((e,t)=>t.count-e.count),directedCount:l.filter(e=>e.directed).length,branchingCount:l.filter(e=>!e.directed).length}}function Bn(e){let t=2166136261;for(let n=0;e.length>n;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function Vn(e){return"string"==typeof e?e:e?.id}function Hn(e,t,n,o,r){const i=new Set(e);let a=new Map;for(const o of e){let e=0,r=0;for(const e of t.get(o)??[])i.has(e)&&(r+=1);for(const t of n.get(o)??[])i.has(t)&&(e+=1);a.set(o,`${e}:${r}`)}for(let o=0;r>o;o+=1){const o=new Map;for(const r of e){const e=[];for(const n of t.get(r)??[])i.has(n)&&e.push(a.get(n));const s=[];for(const e of n.get(r)??[])i.has(e)&&s.push(a.get(e));e.sort(),s.sort(),o.set(r,Bn(`${a.get(r)}>${e.join(",")}<${s.join(",")}`))}a=o}const s=e.map(e=>a.get(e)).sort();return Bn(`${e.length}#${o}#${s.join(";")}`)}function Yn(e,t,n,o,r,i,a){const{layer:s,layerCount:c}=function(e,t){const n=new Set(e),o=new Map,r=new Set,i=e=>{const a=o.get(e);if(void 0!==a)return a;if(r.has(e))return 0;r.add(e);let s=0;for(const o of t.get(e)??[])n.has(o)&&(s=Math.max(s,1+i(o)));return r.delete(e),o.set(e,s),s};let a=0;for(const t of e)a=Math.max(a,i(t));const s=new Map;for(const t of e)s.set(t,a-o.get(t));return{layer:s,layerCount:a+1}}(e.ids,o),l=Array.from({length:c},()=>[]);for(const t of e.ids)l[s.get(t)].push(t);const u=.14*Math.min(i.width,i.height),d=Math.max(1,i.width-2*u),h=Math.max(1,i.height-2*u),f=new Map,m=new Set(e.ids);for(let e=0;c>e;e+=1){let t=l[e];e>0&&(t=[...t].sort((e,t)=>p(e)-p(t)));const n=t.length,o=i.y+u+(1===c?.5:e/(c-1))*h;t.forEach((e,t)=>{f.set(e,{x:i.x+u+(1===n?.5:t/(n-1))*d,y:o})})}function p(e){let t=0,n=0;for(const o of r.get(e)??[]){const e=f.get(o);m.has(o)&&e&&(t+=e.x,n+=1)}return n>0?t/n:i.x+d/2}const g=l.reduce((e,t)=>Math.max(e,t.length),1),y=ae(Math.min(a,d/(2.4*g),h/(2.4*c)),1.4,a),x=e.ids.map(e=>{const o=f.get(e);return{id:e,cx:o.x,cy:o.y,r:y,datum:t.get(e)??ce({id:e}),category:n.get(e)??""}}),b=[];for(const t of e.ids){const e=f.get(t);for(const n of o.get(t)??[]){if(!m.has(n))continue;const t=f.get(n);b.push({x1:e.x,y1:e.y,x2:t.x,y2:t.y})}}return{nodes:x,edges:b}}function Gn(e){const{nodeCount:t,edgeCount:n,sinkCount:o,sourceCount:r}=e;return 1===t?"isolate":2===t&&1===n?"pair":1===r&&1===o&&n===t-1?"chain of "+t:e.directed&&1===r&&n>t-1?"diamond / mesh":e.directed?`converging (${t})`:"branching → "+o}function Xn(e,t){const n=new Set(e),o=new Map,r=new Map,i=new Map;for(const t of e)o.set(t,new Set),r.set(t,new Set),i.set(t,new Set);for(const e of t){const t=e.source,a=e.target;n.has(t)&&n.has(a)&&t!==a&&(o.get(t).has(a)||(o.get(t).add(a),r.get(a).add(t),i.get(t).add(a),i.get(a).add(t)))}return{outAdj:o,inAdj:r,undirected:i}}function _n(e,t,n,o,r){const i=new Set,a=[];for(const s of e){if(i.has(s))continue;const e=[s];i.add(s);const c=[];for(;e.length;){const t=e.pop();c.push(t);for(const n of o.get(t)??[])i.has(n)||(i.add(n),e.push(n))}const l=new Set(c);let u=0,d=0,h=0;for(const e of c){let o=0,r=0;for(const n of t.get(e)??[])l.has(n)&&(o+=1);for(const t of n.get(e)??[])l.has(t)&&(r+=1);h+=o,0===o&&(u+=1),0===r&&(d+=1)}a.push({ids:c,nodeCount:c.length,edgeCount:h,sinkCount:u,sourceCount:d,directed:1===u,motif:Hn(c,t,n,h,r)})}return a}var Kn=new oe(8),Qn=e=>{const t=e.config||{},n=e.dimensions.plot;if(!e.nodes.length)return{sceneNodes:[]};const o=t.sourceAccessor??"source",r=t.targetAccessor??"target",i=t.labelAccessor??"label",a=t.categoryAccessor??"category",s=t.nodeRadius??4,c=t.cellGap??16,l=t.bandGap??22,u=t.headerHeight??34,d=t.minCellForFull??38,h=t.maxCellSize??120,f=t.minCellSize??12,m=t.fingerprintRounds??3,p=!1!==t.groupByMotif,g=t.sort??"frequency",y=new Map,x=new Map,b=[];for(const t of e.nodes){const e=t.id;null==e||y.has(e)||(b.push(e),y.set(e,t.data??t),x.set(e,ge(t,a,"")+""))}const w=[];for(const t of e.edges){const e=Vn(t.source??ge(t,o,void 0)),n=Vn(t.target??ge(t,r,void 0));null!=e&&null!=n&&w.push({source:e,target:n})}const{outAdj:M,inAdj:v,undirected:k}=Xn(b,w),$=_n(b,M,v,k,m),A=new Map;if(p)for(const e of $){const t=A.get(e.motif);t?t.push(e):A.set(e.motif,[e])}else A.set("all",[...$].sort((e,t)=>t.nodeCount-e.nodeCount));const S=[...A.entries()];S.sort((e,t)=>"size"===g?t[1][0].nodeCount-e[1][0].nodeCount:"directedness"===g?Number(t[1][0].directed)-Number(e[1][0].directed):t[1].length-e[1].length);const I=Bn(b.join(",")+"|"+[...M.entries()].map(([e,t])=>e+">"+[...t].sort().join(".")).join(";")),C=be([Math.round(n.x),Math.round(n.y),Math.round(n.width),Math.round(n.height),c,l,u,d,h,f,m,p,g,s,S.map(([e,t])=>e+":"+t.length).join(","),I]),N=Kn.getOrCompute(C,()=>function(e,t){const{plot:n}=t,o=Math.max(40,n.width),{cell:r,cols:i}=(()=>{for(let r=t.maxCellSize;r>=t.minCellSize;r-=2){const i=Math.max(1,Math.floor((o+t.cellGap)/(r+t.cellGap)));let a=0;for(const[,n]of e)a+=t.headerHeight+Math.ceil(n.length/i)*(r+t.cellGap)+t.bandGap;if(n.height>=a)return{cell:r,cols:i}}return{cell:t.minCellSize,cols:Math.max(1,Math.floor((o+t.cellGap)/(t.minCellSize+t.cellGap)))}})(),a=[],s=[];let c=n.y;for(const[l,u]of e){const e=Math.ceil(u.length/i),d=c,h=d+t.headerHeight,f=r>=t.minCellForFull;u.forEach((e,o)=>{const s=n.x+o%i*(r+t.cellGap),c=h+Math.floor(o/i)*(r+t.cellGap);if(f){const n=Yn(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,{x:s,y:c,width:r,height:r},t.nodeRadius);a.push({component:e,lod:"full",cx:s+r/2,cy:c+r/2,glyphR:0,nodes:n.nodes,edges:n.edges})}else a.push({component:e,lod:"glyph",cx:s+r/2,cy:c+r/2,glyphR:Math.max(2.5,.36*r),nodes:[],edges:[]})});const m=Zn(u[0],t,{x:n.x,y:d+2,width:Math.min(t.headerHeight-6,40),height:t.headerHeight-6});s.push({motif:l,descriptor:Gn(u[0]),count:u.length,directed:u[0].directed,x:n.x,y:d,width:o,height:t.headerHeight+e*(r+t.cellGap),exemplar:m}),c=h+e*(r+t.cellGap)+t.bandGap}return{cells:a,bands:s}}(S,{plot:n,cellGap:c,bandGap:l,headerHeight:u,minCellForFull:d,maxCellSize:h,minCellSize:f,nodeRadius:s,nodeDatum:y,nodeCategory:x,outAdj:M,inAdj:v})),z=e.theme.semantic||{},F=t.convergeColor??z.info??"#4c78a8",j=t.branchColor??z.warning??"#e8853a",W=t.edgeColor??z.border??"#9aa0aa",E=t.colorMode??"directedness",O={predicate:e.selection?.isActive?e.selection.predicate:null,highlight:t.highlight??null,dimOpacity:.14},R=t=>"motif"===E?e.resolveColor(t.motif):"category"===E||t.directed?F:j,L=[],P=[];for(const t of N.cells){const n=t.component,o=R(n);if("full"===t.lod){for(const e of t.edges)P.push({type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,style:{stroke:W,strokeWidth:1,opacity:.5},datum:null});for(const n of t.nodes){const t="category"===E&&n.category?e.resolveColor(n.category):o,r={type:"symbol",cx:n.cx,cy:n.cy,size:Math.PI*n.r*n.r,symbolType:"circle",style:{fill:t,opacity:le(n.datum,O)},datum:n.datum,id:n.id,label:ge(n.datum,i,n.id)+""};L.push(r)}}else{const e=ce({id:`motif-${n.motif}-${t.cx.toFixed(0)}-${t.cy.toFixed(0)}`,motif:n.motif,shape:Gn(n),nodes:n.nodeCount,edges:n.edgeCount,sinks:n.sinkCount,sources:n.sourceCount,directedness:n.directed?"converging":"branching"}),r={type:"symbol",cx:t.cx,cy:t.cy,size:Math.PI*t.glyphR*t.glyphR,symbolType:n.directed?"circle":"diamond",style:{fill:o,opacity:le(e,O),stroke:W,strokeWidth:.75},datum:e,id:e.id+"",label:Gn(n)};L.push(r)}}return{sceneNodes:L,sceneEdges:P,overlays:function(e,t){const n=[];for(const o of e){const e=o.directed?t.convergeColor:t.branchColor;if(n.push(q({keyId:"band-"+o.motif,x:o.x-6,y:o.y-4,width:o.width+12,height:o.height+4,radius:8,stroke:e,strokeWidth:1,opacity:.28})),t.showExemplars&&o.exemplar){const r=o.exemplar;n.push(Tn("g",{style:{pointerEvents:"none"},children:[r.edges.map((e,n)=>qn("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:t.edgeColor,strokeWidth:.75,opacity:.55},"exe-"+n)),r.nodes.map(t=>qn("circle",{cx:t.cx,cy:t.cy,r:Math.max(1.6,t.r),fill:e},"exn-"+t.id))]},"ex-"+o.motif))}if(t.showBandLabels){const e=o.x+(t.showExemplars?48:4);n.push(qn("text",{x:e,y:o.y+12,fontSize:13,fontWeight:600,fill:t.textColor,style:{pointerEvents:"none"},children:o.descriptor},"bl-"+o.motif)),n.push(qn("text",{x:e,y:o.y+27,fontSize:11,fill:t.subText,style:{pointerEvents:"none"},children:`×${o.count} · ${o.directed?"converges to 1 sink":"branches to ≥2 sinks"}`},"bc-"+o.motif))}}if(t.showLegend){const e=t.plot.x+t.plot.width-168,i=t.plot.y-2;n.push(Tn("g",{style:{pointerEvents:"none"},children:[qn("circle",{cx:e,cy:i,r:5,fill:t.convergeColor}),qn("text",{x:e+10,y:i+4,fontSize:11,fill:t.subText,children:"converges (1 sink)"}),qn("path",{d:(o=e,r=i+18,`M${o},${r-5} L${o+5},${r} L${o},${r+5} L${o-5},${r} Z`),fill:t.branchColor}),qn("text",{x:e+10,y:i+22,fontSize:11,fill:t.subText,children:"branches (≥2 sinks)"})]},"net-legend"))}var o,r;return qn("g",{className:"net-ensemble-overlays",children:n})}(N.bands,{convergeColor:F,branchColor:j,edgeColor:W,plot:n,showBandLabels:!1!==t.showBandLabels,showExemplars:!1!==t.showExemplars,showLegend:!1!==t.showLegend&&"directedness"===E,textColor:z.text??"var(--semiotic-text, #1a1a1a)",subText:z.textSecondary??"var(--semiotic-text-secondary, #888)"})}};function Zn(e,t,n){return e?Yn(e,t.nodeDatum,t.nodeCategory,t.outAdj,t.inAdj,n,3):null}import*as Un from"react";function Jn(e){return Me(e)??e}function eo(e){return"string"==typeof e?e:e.id}function to(e,t){const n=Number(e);return Number.isFinite(n)&&n>0?n:t}function no(e){return Math.round(100*e)/100+""}function oo(e,t){if(2>e.length)return"";let n=`M${no(e[0][0])},${no(e[0][1])}`;for(let o=1;e.length-1>o;o+=1){const r=e[o-1],i=e[o],a=e[o+1],s=Math.hypot(i[0]-r[0],i[1]-r[1]),c=Math.hypot(a[0]-i[0],a[1]-i[1]),l=Math.min(t,s/2,c/2);if(0>=l){n+=`L${no(i[0])},${no(i[1])}`;continue}const u=[(i[0]-r[0])/s,(i[1]-r[1])/s],d=[(a[0]-i[0])/c,(a[1]-i[1])/c],h=[i[0]-u[0]*l,i[1]-u[1]*l],f=[i[0]+d[0]*l,i[1]+d[1]*l];n+=`L${no(h[0])},${no(h[1])}Q${no(i[0])},${no(i[1])} ${no(f[0])},${no(f[1])}`}const o=e[e.length-1];return`${n}L${no(o[0])},${no(o[1])}`}function ro(e,t,n,o,r=.92*o){const i=Math.cos(n),a=Math.sin(n),s=-a,c=[e+i*o*.56,t+a*o*.56],l=e-i*o*.44,u=t-a*o*.44,d=[l+s*r*.5,u+i*r*.5],h=[l-s*r*.5,u-i*r*.5];return`M${no(c[0])},${no(c[1])}L${no(d[0])},${no(d[1])}L${no(h[0])},${no(h[1])}Z`}function io(e,t){return`${t}\0${e}`}function ao(e,t){return Math.max(1,e-2*Math.max(0,t.portPadding??4))}function so(e,t,n){if(1>=e)return 0;const o=Math.max(0,n.flowGap??.75),r=ao(t,n);return Math.min(o,Math.max(0,(r-Math.min(.1,r))/(e-1)))}var co=e=>{const t=e.config??{},n=e.dimensions.plot,o=e.nodes.map((e,t)=>({id:e.id,datum:Jn(e),inputIndex:t})),r=new Map(o.map(e=>[e.id,e.inputIndex])),i=new Map((t.order??[]).map((e,t)=>[e+"",t]));if(o.sort((e,t)=>{const n=i.get(e.id),o=i.get(t.id);return null!=n&&null!=o?n-o:null!=n?-1:null!=o?1:(r.get(e.id)??0)-(r.get(t.id)??0)}),0===o.length)return{sceneNodes:[],sceneEdges:[],labels:[]};const a=Math.max(0,t.padding??18),s=Math.max(1,Math.min(n.width,n.height)-2*a),c=Math.min(Math.max(1,t.maxCellSize??120),s/o.length),l=c*o.length,u=n.x+(n.width-l)/2,d=n.y+(n.height-l)/2,h=Math.max(4,Math.min(.76*c,t.nodeSize??.56*c)),f=h/2,m=o.map((e,n)=>{const o="function"==typeof t.labelAccessor?t.labelAccessor(e.datum):ge(e.datum,t.labelAccessor??"label",e.id)+"";return{id:e.id,label:o,datum:e.datum,index:n,cx:u+(n+.5)*c,cy:d+(n+.5)*c}}),p=new Map(m.map(e=>[e.id,e])),g=new Map(m.map(e=>[e.id,e.index])),y=function(e,t,n){const o=new Map;for(const r of e){const e=eo(r.source),i=eo(r.target),a=t.get(e),s=t.get(i);if(null==a||null==s)continue;const c=Jn(r),l=to("function"==typeof n.valueAccessor?n.valueAccessor(c):ge(c,n.valueAccessor??"value",r.value??1),0);if(0>=l)continue;let u=o.get(e);u||(u=new Map,o.set(e,u));const d=u.get(i);d?(d.value+=l,d.edgeCount+=1,d.memberEdges.push(c)):u.set(i,{key:`${a}-${s}`,source:e,target:i,sourceIndex:a,targetIndex:s,value:l,edgeCount:1,memberEdges:[c],datum:c,width:1,color:""})}const r=[...o.values()].flatMap(e=>[...e.values()]);for(const e of r)e.datum=se(t=>{for(const[n,o]of Object.entries(e.memberEdges[0]??{}))t(n,o);t("source",e.source),t("target",e.target),t("value",e.value),t("edgeCount",e.edgeCount),t("internal",e.source===e.target),t("memberEdges",e.memberEdges)});return r}(e.edges,g,t),x=function(e,t,n){const o=new Map,r=(e,t)=>{const n=o.get(e);n?n.push(t):o.set(e,[t])};for(const t of e)r(io(t.source,t.sourceIndex>t.targetIndex?"out-left":"out-right"),t),r(io(t.target,t.targetIndex>t.sourceIndex?"in-top":"in-bottom"),t);for(const[e,t]of o){const n=e.startsWith("out-");t.sort((e,t)=>(n?e.targetIndex:e.sourceIndex)-(n?t.targetIndex:t.sourceIndex)||e.key.localeCompare(t.key))}const i=ao(t,n);let a=null==n.flowScale?1/0:Math.max(0,n.flowScale);if(null==n.flowScale){for(const e of o.values()){const o=e.reduce((e,t)=>e+t.value,0),r=so(e.length,t,n);o>0&&(a=Math.min(a,Math.max(.1,i-r*Math.max(0,e.length-1))/o))}Number.isFinite(a)||(a=1)}const s=Math.max(0,n.minFlowWidth??1.25),c=Math.max(s,n.maxFlowWidth??1/0);for(const t of e)t.width=Math.min(c,Math.max(s,t.value*a));let l=1;for(const e of o.values()){const o=e.reduce((e,t)=>e+t.width,0),r=so(e.length,t,n);o>0&&(l=Math.min(l,Math.max(.1,i-r*Math.max(0,e.length-1))/o))}if(1>l)for(const t of e)t.width*=l;return o}(y,h,t),b=function(e,t,n,o){const r=new Map;for(const[i,a]of e){const e=i.slice(i.indexOf("\0")+1),s=t.get(e);if(!s)continue;const c=i.startsWith("out-")?s.cy:s.cx,l=so(a.length,n,o);let u=c-(a.reduce((e,t)=>e+t.width,0)+l*Math.max(0,a.length-1))/2;for(const e of a){const t=u+e.width/2,n=i.startsWith("out-");r.set(`${e.key}:${n?"source":"target"}`,t),u+=e.width+l}}return r}(x,p,h,t),w=e.theme.semantic.info??e.theme.semantic.primary??e.resolveColor("adjacency-flow"),M=e.theme.semantic.text??"var(--semiotic-text, currentColor)",v=e.theme.semantic.surface??"var(--semiotic-bg, white)",k=e.theme.semantic.border??"var(--semiotic-border, currentColor)",$=e.theme.semantic.grid??k,A=e.theme.semantic.primary??e.resolveColor("adjacency-flow-node"),S=t.valueFormat??(e=>Math.round(100*e)/100+""),I=Math.max(0,Math.min(t.cornerRadius??10,.22*c)),C=new Map(m.map(e=>[e.id,0])),N=new Map(m.map(e=>[e.id,0])),z=[],F=[],j=[];for(const n of y){const o=p.get(n.source),r=p.get(n.target);if(!o||!r)continue;C.set(o.id,(C.get(o.id)??0)+n.value),N.set(r.id,(N.get(r.id)??0)+n.value);const i=t.colorMode??"single",a="function"==typeof t.edgeColor?t.edgeColor(n.datum):void 0;n.color=a??("string"==typeof t.edgeColor?t.edgeColor:void 0)??("source"===i?e.resolveColor(n.source):"target"===i?e.resolveColor(n.target):"edge"===i?e.resolveColor(`${n.source}→${n.target}`):w);const s=b.get(n.key+":source")??o.cy,l=b.get(n.key+":target")??r.cx;let h,m,g,y,x,k,$;if(n.targetIndex>n.sourceIndex){const e=[o.cx+f,s],t=[l,r.cy-f];h=[e,[t[0],e[1]],t],m=t[0],g=e[1]+.68*(t[1]-e[1]),y=Math.PI/2,x=t[0]-I-4,k=e[1]-n.width/2-3,$="end"}else if(n.sourceIndex>n.targetIndex){const e=[o.cx-f,s],i=[l,r.cy+f];h=[e,[i[0],e[1]],i],m=i[0],g=e[1]+.68*(i[1]-e[1]),y=-Math.PI/2,x=i[0]+I+4,k=e[1]+n.width/2+(t.valueFontSize??10),$="start"}else{const e=u+(o.index+1)*c,t=d+(o.index+1)*c,i=Math.max(2,Math.min(6,.07*c)),a=Math.max(o.cx+f+2,e-i),p=Math.max(o.cy+f+2,t-i),b=[o.cx+f,s],w=[l,r.cy+f];h=[b,[a,b[1]],[a,p],[w[0],p],w],m=(a+w[0])/2,g=p,y=Math.PI,x=a-3,k=p-n.width/2-3,$="end"}const A=oo(h,I);if(j.push({type:"curved",id:"adjacency-flow-"+n.key,label:`${o.label} to ${r.label}: ${S(n.value,n.datum)}`,pathD:A,style:{fill:"none",stroke:n.color,strokeWidth:n.width,opacity:.82,cursor:"pointer"},datum:n.datum,accessibleDatum:n.datum,accessibility:{label:`${o.label} to ${r.label}, ${S(n.value,n.datum)}`,tableFields:{source:o.label,target:r.label,value:n.value,edges:n.edgeCount}}}),(t.showValues??1)&&F.push({x:x,y:k,text:S(n.value,n.datum),anchor:$,fontSize:t.valueFontSize??Math.max(7,Math.min(10,.14*c)),fontWeight:650,fill:M,stroke:v,strokeWidth:3,paintOrder:"stroke"}),t.showArrows??1){const e=Math.min(Math.max(0,t.arrowSize??14),Math.max(0,n.width-2));if(2>=e)continue;z.push(Un.createElement("path",{key:"arrow-"+n.key,className:"semiotic-adjacency-flow-arrow",d:ro(m,g,y,Math.max(3,1.08*e),e),fill:t.arrowColor??"var(--semiotic-adjacency-flow-arrow-fill, rgba(255, 255, 255, 0.72))",stroke:"none","data-edge-width":n.width,"data-arrow-width":e,"aria-hidden":!0,focusable:!1,pointerEvents:"none",opacity:1}))}}const W=m.map(n=>{const o=("function"==typeof t.nodeColor?t.nodeColor(n.datum,n.index):void 0)??("string"==typeof t.nodeColor?t.nodeColor:"source"===(t.colorMode??"single")?e.resolveColor(n.id):A);return{type:"rect",id:n.id,label:n.label,x:n.cx-f,y:n.cy-f,w:h,h:h,style:{fill:o,stroke:t.nodeStroke??k,strokeWidth:1.25,cursor:"pointer"},datum:n.datum,accessibleDatum:n.datum,accessibility:{label:`${n.label}, step ${n.index+1}`,tableFields:{step:n.index+1,node:n.label,incoming:N.get(n.id)??0,outgoing:C.get(n.id)??0}}}}),E=Math.max(2,t.maxLabelLength??14),O=m.map(e=>{return{x:e.cx,y:e.cy,text:(n=e.label,o=E,n.length>o?n.slice(0,Math.max(1,o-1))+"…":n),anchor:"middle",baseline:"middle",fontSize:t.labelFontSize??Math.max(6,Math.min(15,.34*h,h/Math.max(1.8,.62*e.label.length))),fontWeight:750,fill:t.nodeTextColor??v};var n,o});let R=null;if(t.showGrid??1){const e=[];for(let t=0;m.length>=t;t+=1){const n=u+t*c,o=d+t*c;e.push(Un.createElement("line",{key:"grid-v-"+t,x1:n,y1:d,x2:n,y2:d+l,stroke:$,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}),Un.createElement("line",{key:"grid-h-"+t,x1:u,y1:o,x2:u+l,y2:o,stroke:$,strokeWidth:.75,strokeDasharray:"2 5",opacity:.5,pointerEvents:"none"}))}R=Un.createElement(Un.Fragment,null,...e)}return{sceneEdges:j,sceneNodes:W,labels:[...F,...O],backgrounds:R,overlays:Un.createElement(Un.Fragment,null,...z)}};function lo(e,t,n){const o="function"==typeof t?t(e):ge(e,t,n);return null==o||""===o?n:o+""}function uo(e,t){const n="function"==typeof t?t(e):ge(e,t,void 0);if(null!=n){if("object"==typeof n){const e=n.id;return null==e?void 0:e+""}return n+""}}function ho(e,t){const n="function"==typeof t?t(e):ge(e,t,1);return Number(n)}function fo(e,t){if(!t.has(e))return t.add(e),e;let n=2;for(;t.has(`${e}-${n}`);)n+=1;const o=`${e}-${n}`;return t.add(o),o}function mo(e,t,n={}){const o=n.nodeIdAccessor??"id",r=n.groupAccessor??"group",i=n.labelAccessor??"label",a=n.sourceAccessor??"source",s=n.targetAccessor??"target",c=n.valueAccessor??"value",l=new Set(n.expandedGroups??[]),u=n.includeInternalFlows??!0,d=[],h=new Map,f=new Map;for(const t of e){const e=lo(t,o,d.length+"");if(h.has(e))continue;const n=lo(t,i,e),a=lo(t,r,e),s={id:e,label:n,group:a,datum:t};d.push(s),h.set(e,s);const c=f.get(a);c?c.push(s):f.set(a,[s])}const m=new Set(d.map(e=>e.id)),p=[],g=new Map,y=new Map,x=[];for(const[e,t]of f){if(!l.has(e)&&(!0===n.collapseSingletons||t.length>1)){const o=fo(`${n.groupIdPrefix??"group:"}${e}`,m),r={id:o,label:e,group:e,aggregate:!0,memberIds:t.map(e=>e.id),memberCount:t.length,internalValue:0,incomingValue:0,outgoingValue:0};p.push(r),g.set(o,r);for(const e of t)y.set(e.id,o);x.push({group:e,nodeId:o,label:e,collapsed:!0,memberIds:[...r.memberIds],internalValue:0,incomingValue:0,outgoingValue:0});continue}for(const n of t){const t={...n.datum,id:n.id,label:n.label,group:e,aggregate:!1,memberIds:[n.id],memberCount:1,internalValue:0,incomingValue:0,outgoingValue:0};p.push(t),g.set(t.id,t),y.set(n.id,t.id)}x.push({group:e,nodeId:null,label:e,collapsed:!1,memberIds:t.map(e=>e.id),internalValue:0,incomingValue:0,outgoingValue:0})}const b=new Map(x.map(e=>[e.group,e])),w=new Map;let M=0;for(const e of t){const t=uo(e,a),n=uo(e,s),o=ho(e,c),r=null==t?void 0:y.get(t),i=null==n?void 0:y.get(n);if(!(r&&i&&Number.isFinite(o)&&o>0)){M+=1;continue}const l=h.get(t)?.group,u=h.get(n)?.group;if(l&&u&&l===u){const e=b.get(l);e&&(e.internalValue+=o)}else{if(l){const e=b.get(l);e&&(e.outgoingValue+=o)}if(u){const e=b.get(u);e&&(e.incomingValue+=o)}}let d=w.get(r);d||(d=new Map,w.set(r,d));const f=d.get(i);f?(f.value+=o,f.edgeCount+=1,f.memberEdges.push(e)):d.set(i,{source:r,target:i,value:o,edgeCount:1,internal:r===i,memberEdges:[e]})}const v=[...w.values()].flatMap(e=>[...e.values()]);for(const e of v){const t=g.get(e.source),n=g.get(e.target);e.internal?t&&(t.internalValue+=e.value):(t&&(t.outgoingValue+=e.value),n&&(n.incomingValue+=e.value))}return{nodes:p,edges:u?v:v.filter(e=>!e.internal),groups:x,omittedEdgeCount:M}}import{jsx as po,jsxs as go}from"react/jsx-runtime";var yo=new oe(12);function xo(e){if(null==e)return NaN;if("number"==typeof e)return e;if(e instanceof Date)return e.getTime();const t=e+"",n=Number(t);if(!Number.isNaN(n)&&""!==t.trim())return n;const o=Date.parse(t);return Number.isNaN(o)?NaN:o}function bo(e,t,n){return t>e?t:e>n?n:e}var wo=e=>{const t=e.config||{},o=e.dimensions.plot,r=t.columnAccessor??"column",i=t.rowAccessor??"row",s=t.sizeAccessor,c=t.colorAccessor,l=t.symbolAccessor,u=t.shadeAccessor,d=t.markerAccessor,h=t.iconAccessor,f=t.defaultSymbol??"circle",[m,p]=t.sizeRange??[2,8],g=t.shadeStrength??.72,y=t.shadeReverse??!1,x=t.rowMode??"banded",b=t.cellSizing??"proportional",w=t.proportionExponent??1,M=t.columnGap??16,v=t.rowGap??12,$=t.packPadding??1,A=t.iterations??12,S=!1!==t.showEnclosures,I=!1!==t.showColumnHeaders,C=!1!==t.showRowLabels,N=I?t.headerHeight??26:0,z=C?t.labelWidth??66:0,F=t.callouts&&t.callouts.length>0?t.footerHeight??30:0,j=o.x+z,W=o.y+N,E=Math.max(1,o.width-z),O=Math.max(1,o.height-N-F),R=[];for(const t of e.nodes){const e=t.data??t;R.push({id:t.id,col:ge(t,r,"—")+"",row:ge(t,i,"—")+"",sizeVal:s?Number(ge(t,s,1)):1,colorKey:c?ge(t,c,"")+"":"",symVal:l?ge(t,l,"")+"":"",shadeVal:u?xo(ge(t,u,null)):NaN,marker:!!d&&!!ge(t,d,!1),iconVal:h?ge(t,h,"")+"":"",datum:e,size:0,packR:0,baseShape:"circle",iconShape:null})}if(0===R.length)return{sceneNodes:[]};let L=1/0,P=-1/0;if(s)for(const e of R)Number.isFinite(e.sizeVal)&&(L>e.sizeVal&&(L=e.sizeVal),e.sizeVal>P&&(P=e.sizeVal));t.sizeDomain&&([L,P]=t.sizeDomain),Number.isFinite(L)&&Number.isFinite(P)||(L=0,P=1);const T=e=>{if(L>=P)return(m+p)/2;const t=Math.sqrt(bo((e-L)/(P-L),0,1));return m+t*(p-m)};let D=1/0,H=-1/0;if(u)for(const e of R)Number.isFinite(e.shadeVal)&&(D>e.shadeVal&&(D=e.shadeVal),e.shadeVal>H&&(H=e.shadeVal));t.shadeDomain&&([D,H]=t.shadeDomain);const Y=e=>{if(!u||!Number.isFinite(e)||D>=H)return.5;const t=bo((e-D)/(H-D),0,1);return y?1-t:t},G=t.colorMap,X=new Map,_=(t,n)=>{let o=X.get(t);if(!o){const n=G&&Object.prototype.hasOwnProperty.call(G,t)&&"string"==typeof G[t]&&G[t]?G[t]:e.resolveColor(t);o=de(n,g),X.set(t,o)}return o(n)},K=new Map;if(t.symbolMap)for(const[e,n]of Object.entries(t.symbolMap))K.set(e,n);let Q=0;const Z=t.iconMap,U=e=>h&&Z&&Object.prototype.hasOwnProperty.call(Z,e)?Z[e]??null:null,J=e=>h?"circle":(e=>{if(!l)return f;let t=K.get(e);return t||(t=n[Q%n.length],Q++,K.set(e,t)),t})(e.symVal),ee=t.maxAreaFraction??.4;let te=0;const ne=Array(R.length),oe=Array(R.length);for(let e=0;R.length>e;e++){const t=R[e],n=T(t.sizeVal);ne[e]=n,t.baseShape=J(t),t.iconShape=U(t.iconVal);const o=B(t.baseShape,Math.PI*n*n);oe[e]=o,te+=Math.PI*o*o}const re=ee*E*O,ie=te>re?Math.sqrt(re/te):1;for(let e=0;R.length>e;e++){const t=R[e],n=ne[e]*ie;t.size=Math.PI*n*n,t.packR=oe[e]*ie}const ae=new Map,se=new Map;for(const e of R)ae.set(e.col,(ae.get(e.col)??0)+1),se.set(e.row,(se.get(e.row)??0)+1);const ce=t.columnOrder?.filter(e=>ae.has(e))??[...ae.keys()].sort((e,t)=>(ae.get(t)??0)-(ae.get(e)??0)),he=t.rowOrder?.filter(e=>se.has(e))??[...se.keys()].sort((e,t)=>(se.get(t)??0)-(se.get(e)??0)),fe=be([Math.round(o.x),Math.round(o.y),Math.round(o.width),Math.round(o.height),N,z,F,x,b,w,M,v,$,A,m,p,L,P,ee,ce.join(","),he.join(","),R.length,vo(R)]),me=yo.getOrCompute(fe,()=>function(e,t){const n=new Map;for(const t of e){let e=n.get(t.col);e||(e=[],n.set(t.col,e)),e.push(t)}const o=t.columnOrder.filter(e=>n.has(e)),r=Math.max(1,t.innerW-t.columnGap*Math.max(0,o.length-1)),i=t.proportionExponent,a=o.map(e=>Math.pow(n.get(e).length,i)),s=a.reduce((e,t)=>e+t,0)||1,c=e=>"uniform"===t.cellSizing?r/o.length:a[e]/s*r,l=new Map,u=[];let d=t.innerX;for(let e=0;o.length>e;e++)u.push({col:o[e],x:d,w:c(e)}),d+=c(e)+t.columnGap;let h=1;const f=new Map,m=[],p=(e,t,n,o)=>{let r=f.get(e);r||(r={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0},f.set(e,r)),r.minX>t-o&&(r.minX=t-o),t+o>r.maxX&&(r.maxX=t+o),r.minY>n-o&&(r.minY=n-o),n+o>r.maxY&&(r.maxY=n+o)},g=(e,n,o,r,i,a)=>{const s=e.map(e=>({id:e.id,r:e.packR})),c=function(e,t,n,o,r,i,a,s){const c=t+o/2,l=n+r/2,u=new Map,d=e.length;if(0===d)return u;if(1===d)return u.set(e[0].id,{px:c,py:l}),u;const h=function(e){let t=e>>>0||1;return()=>(t=Math.imul(t,1664525)+1013904223>>>0,t/4294967296)}(s),f=new Float64Array(d);let m=0;for(let t=0;d>t;t++)f[t]=e[t].r+i,f[t]>m&&(m=f[t]);const p=Math.max(1,Math.round(Math.sqrt(d*o/Math.max(1,r)))),g=new Float64Array(d),y=new Float64Array(d),x=o/p,b=r/Math.ceil(d/p);for(let e=0;d>e;e++){const o=e%p,r=Math.floor(e/p);g[e]=t+(o+.3+.4*h())*x,y[e]=n+(r+.3+.4*h())*b}const w=Math.max(0,Math.min(a,14)),M=Math.max(1,2*m),v=new Map,k=Math.max(1,Math.ceil(o/M)+3),$=(e,t)=>(t+1)*k+(e+1);for(let e=0;w>e;e++){v.clear();for(let e=0;d>e;e++){const o=$(Math.floor((g[e]-t)/M),Math.floor((y[e]-n)/M)),r=v.get(o);r?r.push(e):v.set(o,[e])}for(let e=0;d>e;e++){const o=Math.floor((g[e]-t)/M),r=Math.floor((y[e]-n)/M);for(let t=-1;1>=t;t++)for(let n=-1;1>=n;n++){const i=v.get($(o+t,r+n));if(i)for(let t=0;i.length>t;t++){const n=i[t];if(e>=n)continue;let o=g[n]-g[e],r=y[n]-y[e];const a=f[e]+f[n],s=o*o+r*r;if(a*a>s)if(s>1e-9){const t=Math.sqrt(s),i=(a-t)/2;o/=t,r/=t,g[e]-=o*i,y[e]-=r*i,g[n]+=o*i,y[n]+=r*i}else{const t=2.39996323*e;g[e]+=Math.cos(t)*f[e],y[e]+=Math.sin(t)*f[e]}}}}for(let e=0;d>e;e++){const i=f[e],a=t+i,s=t+o-i,u=n+i,d=n+r-i;g[e]=s>a?bo(g[e],a,s):c,y[e]=d>u?bo(y[e],u,d):l}}for(let t=0;d>t;t++)u.set(e[t].id,{px:g[t],py:y[t]});return u}(s,n,o,r,i,t.packPadding,t.iterations,h++);let u=1/0,d=1/0,f=-1/0,m=-1/0;for(const e of s){const t=c.get(e.id);l.set(e.id,{px:t.px,py:t.py}),p(a,t.px,t.py,e.r),u>t.px-e.r&&(u=t.px-e.r),t.px+e.r>f&&(f=t.px+e.r),d>t.py-e.r&&(d=t.py-e.r),t.py+e.r>m&&(m=t.py+e.r)}return Number.isFinite(u)?{x:u-Mo,y:d-Mo,w:f-u+2*Mo,h:m-d+2*Mo}:null};if("banded"===t.rowMode){const r=new Map;for(const t of e)r.set(t.row,(r.get(t.row)??0)+1);const a=t.rowOrder.filter(e=>r.has(e)),s=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),c=a.map(e=>Math.pow(r.get(e),i)),d=c.reduce((e,t)=>e+t,0)||1,h=new Map;let m=t.innerY+t.innerH;for(let e=0;a.length>e;e++){const n="uniform"===t.cellSizing?s/a.length:c[e]/d*s,o=m-n;h.set(a[e],{y:o,h:n}),m=o-t.rowGap}o.forEach((e,t)=>{const o=ue(n.get(e),e=>e.row);for(const e of a){const n=o.get(e),r=h.get(e);n&&r&&g(n,u[t].x,r.y,u[t].w,r.h,e)}});const p=[],y=new Map;for(const e of a){const t=h.get(e);y.set(e,t.y+t.h/2);const n=f.get(e);n&&Number.isFinite(n.minX)&&p.push({x:n.minX-Mo,y:n.minY-Mo,w:n.maxX-n.minX+2*Mo,h:n.maxY-n.minY+2*Mo})}return{positions:l,enclosures:p,colBands:u,rowLabelY:y}}const y=new Map;o.forEach((e,o)=>{const r=ue(n.get(e),e=>e.row),a=t.rowOrder.filter(e=>r.has(e)),s=Math.max(1,t.innerH-t.rowGap*Math.max(0,a.length-1)),c=a.map(e=>Math.pow(r.get(e).length,i)),l=c.reduce((e,t)=>e+t,0)||1;let d=t.innerY+t.innerH;a.forEach((e,n)=>{const i="uniform"===t.cellSizing?s/a.length:c[n]/l*s,h=d-i,f=g(r.get(e),u[o].x,h,u[o].w,i,e);if(f){m.push(f);const t=y.get(e)??{sum:0,n:0};t.sum+=f.y+f.h/2,t.n+=1,y.set(e,t)}d=h-t.rowGap})});const x=new Map;for(const[e,t]of y)x.set(e,t.sum/t.n);return{positions:l,enclosures:m,colBands:u,rowLabelY:x}}(R,{columnOrder:ce,rowOrder:he,innerX:j,innerY:W,innerW:E,innerH:O,rowMode:x,cellSizing:b,proportionExponent:w,columnGap:M,rowGap:v,packPadding:$,iterations:A})),pe=e.selection,ye=pe?.isActive?pe.predicate:null,xe=t.highlight??null,we=t.dimOpacity??.16,Me=t.markStroke,ve=t.markStrokeWidth??0,ke=t.markerColor??"#ffffff",$e=t.iconColor??"rgba(255,255,255,0.92)",Ae=t.iconStrokeWidth??1,Se=t.iconScale??.72,Ie=[],Ce=[],Ne=[];for(const e of R){const t=me.positions.get(e.id);if(!t)continue;const n=le(e.datum,{highlight:xe,predicate:ye,dimOpacity:we}),o={type:"symbol",cx:t.px,cy:t.py,size:e.size,symbolType:e.baseShape,style:{fill:_(e.colorKey,Y(e.shadeVal)),opacity:n,...Me?{stroke:Me,strokeWidth:ve}:{}},datum:e.datum,id:e.id,label:e.id+""};if(Ie.push(o),e.iconShape){const o=Math.sqrt(e.size/Math.PI)*Se,r=B(e.iconShape,100);Ne.push({x:t.px,y:t.py,size:r>0?o/r*100*(o/r):Math.PI*o*o,shape:e.iconShape,opacity:n})}e.marker&&n>we+.001&&Ce.push({x:t.px,y:t.py,r:Math.max(1,.4*Math.sqrt(e.size/Math.PI))})}const ze=[];if(t.callouts&&t.callouts.length>0){const e=t.calloutColor??"var(--semiotic-text, #f4f4f8)",n=o.y+o.height-(F>0?.45*F:9),r=[];for(let e=0;t.callouts.length>e;e++){const n=t.callouts[e],o=R.find(e=>e.datum[n.field]+""==n.value+"");if(!o)continue;const i=me.positions.get(o.id);i&&r.push({c:n,ci:e,px:i.px,py:i.py,markR:Math.sqrt(o.size/Math.PI)})}const i=r.filter(e=>null==e.c.at).sort((e,t)=>e.px-t.px),a=new Map;i.forEach((e,t)=>{a.set(e.ci,j+(t+.5)/i.length*E)});for(const t of r){const r=t.c;let i=a.get(t.ci)??t.px,s=n;const c=r.connector??(a.has(t.ci)?"elbow":"straight");"object"==typeof r.at&&r.at?(i=r.at.x,s=r.at.y):"number"==typeof r.at&&(s=o.y+r.at*o.height),ze.push({keyId:"callout-"+t.ci,markX:t.px,markY:t.py,labelX:i,labelY:s,label:r.label,connector:c,markRadius:Math.max(t.markR+3,7),stroke:e,color:e,fontSize:11,labelAnchor:"middle",labelBaseline:"auto"})}}const Fe=function(e,t){const n=t.columnLabel??(e=>e),o=t.rowLabel??(e=>e);return go("g",{className:"packed-cluster-matrix-chrome",style:{pointerEvents:"none"},children:[t.showEnclosures&&e.enclosures.map((e,n)=>q({keyId:"enc-"+n,x:e.x,y:e.y,width:e.w,height:e.h,radius:t.enclosureRadius,stroke:t.enclosureColor,strokeWidth:t.enclosureWidth,opacity:t.enclosureOpacity})),t.iconMarks.length>0&&po("g",{className:"packed-cluster-matrix-icons",children:t.iconMarks.map((e,n)=>po("path",{d:V(e.shape,e.size),transform:`translate(${e.x},${e.y})`,fill:"none",stroke:t.iconColor,strokeWidth:t.iconStrokeWidth,opacity:e.opacity},"ic-"+n))}),t.markerDots.length>0&&po("g",{className:"packed-cluster-matrix-markers",children:t.markerDots.map((e,n)=>po("circle",{cx:e.x,cy:e.y,r:e.r,fill:t.markerColor},"mk-"+n))}),t.showColumnHeaders&&e.colBands.map((e,o)=>a({keyId:"col-"+o,text:n(e.col),x:e.x+e.w/2,y:t.headerY,anchor:"middle",fontSize:t.headerFontSize,fontWeight:700,color:t.headerColor})),t.showRowLabels&&[...e.rowLabelY].map(([e,n])=>a({keyId:"row-"+e,text:o(e),x:t.labelX,y:n,anchor:"end",fontSize:t.labelFontSize,fontWeight:600,color:t.labelColor})),t.callouts.map(e=>k(e))]})}(me,{markerDots:Ce,markerColor:ke,iconMarks:Ne,iconColor:$e,iconStrokeWidth:Ae,callouts:ze,plot:o,showEnclosures:S,showColumnHeaders:I,showRowLabels:C,enclosureColor:t.enclosureColor??"var(--semiotic-text, #f4f4f8)",enclosureRadius:t.enclosureRadius??9,enclosureOpacity:t.enclosureOpacity??.5,enclosureWidth:t.enclosureWidth??1.5,headerColor:t.headerColor??"var(--semiotic-text, #f4f4f8)",labelColor:t.labelColor??"var(--semiotic-text-secondary, #b9b9c8)",headerFontSize:t.headerFontSize??13,labelFontSize:t.labelFontSize??11,headerY:o.y+.62*N,labelX:o.x+z-10,columnLabel:t.columnLabel,rowLabel:t.rowLabel});return{sceneNodes:Ie,overlays:Fe}},Mo=4;function vo(e){let t=2166136261;const n=e=>{for(let n=0;e.length>n;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)};for(const o of e)n(o.id),n(o.col),n(o.row),t^=Math.round(8*o.packR),t=Math.imul(t,16777619);return(t>>>0).toString(36)}import*as ko from"react";var $o=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height)return{nodes:[]};const o=ye(t.categoryAccessor),r=ye(t.stackBy),i=e=>{const n="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor],o=Number(n);return Number.isFinite(o)&&o>0?o:0},s=t.gutter??2,c="string"==typeof t.categoryAccessor?t.categoryAccessor:"category",l="string"==typeof t.stackBy?t.stackBy:"stack",u="string"==typeof t.valueAccessor?t.valueAccessor:"value",d=(e,t,n)=>se(o=>{o("category",e),o("stack",t),o("value",n),"category"!==c&&o(c,e),"stack"!==l&&o(l,t),"value"!==u&&o(u,n)}),h=!1!==t.showCategoryLabels,f=Math.max(0,n.height-(t.labelPadding??(h?22:0))),m=[],p=new Map,g=[],y=new Set,x=new Map;for(const t of e.data){const e=o(t)+"",n=r(t)+"",a=i(t);p.has(e)||(m.push(e),p.set(e,0),x.set(e,new Map)),y.has(n)||(y.add(n),g.push(n)),p.set(e,(p.get(e)??0)+a);const s=x.get(e);s.set(n,(s.get(n)??0)+a)}const b=t.categoryOrder?Ao(t.categoryOrder,m,e=>p.has(e)):m,w=t.stackOrder?Ao(t.stackOrder,g,()=>!0):g,M=b.reduce((e,t)=>e+(p.get(t)??0),0);if(0>=M)return{nodes:[]};const v=Math.max(0,n.width-s*Math.max(0,b.length-1)),k=[],$=[];let A=n.x;for(const t of b){const o=p.get(t)??0,r=o/M*v;if(0>=r)continue;$.push({cat:t,x:A,w:r});const i=x.get(t);let a=n.y;for(const n of w){const s=i.get(n)??0;if(0>=s)continue;const c=s/o*f;k.push({type:"rect",x:A,y:a,w:r,h:c,style:{fill:e.resolveColor(n),stroke:"none"},datum:d(t,n,s),group:n}),a+=c}A+=r+s}return{nodes:k,overlays:h&&$.length>0?function(e,t,n){const o=e.map((e,o)=>a({keyId:"marimekko-label-"+o,text:e.cat,x:e.x+e.w/2,y:t+12,anchor:"middle",baseline:"auto",maxWidth:e.w-4,fontSize:12,color:n}));return ko.createElement(ko.Fragment,null,...o)}($,n.y+f+4,`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`):null}};function Ao(e,t,n){const o=new Set,r=[];for(const t of e)n(t)&&!o.has(t)&&(o.add(t),r.push(t));for(const e of t)o.has(e)||r.push(e);return r}import*as So from"react";var Io=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height||0===e.data.length)return{nodes:[]};const o=t.rowHeight??28,r=t.rowGap??12,i=!1!==t.showLabels,s=i?t.labelWidth??120:0,c=!1!==t.showTicks,l=c?14:0,u=t.tickFormat??(e=>e.toLocaleString()),d=n.x+s,h=Math.max(0,n.width-s);if(0>=h)return{nodes:[]};const f=ye(t.categoryAccessor),m=e=>{const t=Number(e);return Number.isFinite(t)&&t>0?t:0},p=e=>m("function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor]),g=e=>m("function"==typeof t.targetAccessor?t.targetAccessor(e):e[t.targetAccessor]),y=e=>{const n="function"==typeof t.rangesAccessor?t.rangesAccessor(e):e[t.rangesAccessor];return Array.isArray(n)?n.map(m).sort((e,t)=>e-t):[]},x="string"==typeof t.categoryAccessor?t.categoryAccessor:"metric",b="string"==typeof t.valueAccessor?t.valueAccessor:"value",w="string"==typeof t.targetAccessor?t.targetAccessor:"target",M=t.actualColor??e.theme.semantic.primary??"#3b6cb1",v=e.theme.semantic.text??"currentColor",k=t.targetColor??`var(--semiotic-text, ${v})`,$=[`var(--semiotic-surface, ${e.theme.semantic.surface??"#e8eaed"})`,`var(--semiotic-grid, ${e.theme.semantic.grid??"#cdd1d6"})`,`var(--semiotic-border, ${e.theme.semantic.border??"#a3a8af"})`],A=`var(--semiotic-text, ${v})`,S=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,I=[],C=[];for(let t=0;e.data.length>t;t++){const i=e.data[t],a=y(i),s=p(i),c=g(i),u=Math.max(s,c,...a.length?a:[0]);if(0>=u)continue;const m=n.y+t*(o+r+l);if(m+o+l>n.y+n.height)break;C.push({yTop:m,label:f(i),actual:s,target:c,maxVal:u});const v=e=>d+e/u*h,A=f(i),S=e=>se(t=>{t("metric",A),"metric"!==x&&t(x,A),e(t)});let N=d;for(let e=0;a.length>e;e++){const t=v(a[e]),n=t-N;n>0&&I.push({type:"rect",x:N,y:m,w:n,h:o,style:{fill:$[Math.min(e,$.length-1)],stroke:"none"},datum:S(t=>{t("range",e),t("rangeValue",a[e]),t("kind","range")}),group:"range-"+e}),N=t}const z=Math.max(6,Math.floor(.45*o));I.push({type:"rect",x:d,y:m+(o-z)/2,w:v(s)-d,h:z,style:{fill:M,stroke:"none"},datum:S(e=>{e("value",s),e("kind","actual"),"value"!==b&&e(b,s)}),group:"actual"});const F=3,j=Math.floor(.8*o);I.push({type:"rect",x:v(c)-F/2,y:m+(o-j)/2,w:F,h:j,style:{fill:k,stroke:"none"},datum:S(e=>{e("target",c),e("kind","target"),"target"!==w&&e(w,c)}),group:"target"})}const N=[];for(let e=0;C.length>e;e++){const t=C[e];if(i&&N.push(a({keyId:"bullet-label-"+e,text:t.label,x:n.x+s-8,y:t.yTop+o/2,anchor:"end",baseline:"middle",fontSize:13,fontWeight:500,color:A})),c){const n=5,r=t.yTop+o+2;for(let o=0;n>o;o++){const i=t.maxVal*o/(n-1),s=d+i/t.maxVal*h;N.push(So.createElement("line",{key:`bullet-tick-${e}-${o}`,x1:s,x2:s,y1:r,y2:r+3,stroke:S,strokeWidth:1}),a({keyId:`bullet-ticktext-${e}-${o}`,text:u(i),x:s,y:r+12,anchor:0===o?"start":o===n-1?"end":"middle",baseline:"auto",fontSize:10,color:S}))}}}return{nodes:I,overlays:N.length>0?So.createElement(So.Fragment,null,...N):null}};import{jsx as Co,jsxs as No}from"react/jsx-runtime";var zo=1.75,Fo="#222222";function jo(e,t){return e.topRadius+(t-e.height)/e.height*(e.topRadius-e.bottomRadius)}function Wo(e,t){return function(e,t,n){return Math.PI*n/3*(e*e+e*t+t*t)}(jo(e,t),e.bottomRadius,t)}function Eo(e,t){const n=(e.topRadius+e.bottomRadius)/2,o=Math.PI*n*n;let r=t/o,i=t-Wo(e,r),a=0;for(;100>a&&Math.abs(i)>1e-4;)r+=i/o,i=t-Wo(e,r),a++;return r}function Oo(e,t){const n=43758.5453*Math.sin(12.9898*e+78.233);return 2*(n-Math.floor(n)-.5)*t}function Ro(e,t){if(t>e||2*t>e)return[{x:0,y:0}];const n=[],o=e=>{let r=Math.floor(2*Math.PI*e/(2*t));1>r&&(r=1);const i=0*e,a=Math.hypot(1*e-e*Math.cos(2*Math.PI/r),i-e*Math.sin(2*Math.PI/r));2*t>a&&r>1&&r--;for(let t=0;r>t;t++)n.push({x:e*Math.cos(2*t*Math.PI/r),y:e*Math.sin(2*t*Math.PI/r)});const s=e-2*t;t>s?e>2*t&&n.push({x:0,y:0}):o(s)};return o(e-t),n}function Lo(e,t,n){const o=[];let r=n,i=0;for(;r>0&&60>i;){const n=t*(1+2*i),a=Ro(jo(e,n),t),s=a.length-r,c=s>1?a.slice(Math.floor(s/2),Math.floor(s/2)+r):a,l=e.height-n;if(c.forEach((e,t)=>{o.push({x:e.x+Oo(97*i+t,.15),z:l+Oo(31*i+t,.05)})}),r-=c.length,i++,0===c.length)break}return{pearls:o,layers:i}}function Po(e,t,n,o){if(0>=o)return[];const r=function(e,t,n){let o=n,r=0;for(;o>0&&60>r;){const n=jo(e,t+.875*(1+2*r));o-=Math.max(1,Math.floor(2*n/zo)),r++}return r}(e,t,o),i=Math.max(t,n-r*zo)+.875,a=[];let s=0;for(let t=0;r>t&&o>s;t++){const n=i+zo*t,r=jo(e,n),c=Math.max(1,Math.floor(2*r/zo)),l=(2*r-c*zo)/(c+1),u=-r+l,d=e.height-n-.875-.1;for(let e=0;c>e&&o>s;e++)a.push({cx:u+(l+zo)*e+.875,cy:d+.875,rotation:Oo(53*t+e,10)}),s++}return a}function qo(e,t){const n=Number(e);return Number.isFinite(n)?n:t}var To=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height)return{nodes:[]};const o=ye(t.categoryAccessor??"name"),r=ye(t.teaVolumeAccessor??"teaVolume"),i=ye(t.bobaVolumeAccessor??"bobaVolume"),a=ye(t.iceVolumeAccessor??"iceVolume"),s=ye(t.cupHeightAccessor??"cupHeight"),c=ye(t.cupTopRadiusAccessor??"cupTopRadius"),l=ye(t.cupBottomRadiusAccessor??"cupBottomRadius"),u=ye(t.bobaRadiusAccessor??"bobaRadius"),d=t.cupWidthRatio??.82,h=e.scales.o,f=h.bandwidth(),m=Math.max(1,n.height-26-8),p=n.y+8,g=[],y=[];for(const t of e.data){const n=o(t)+"",x=h(n);if(null==x)continue;const b={height:qo(s(t),15.5),topRadius:qo(c(t),4.75),bottomRadius:qo(l(t),3.75)},w=qo(u(t),.6),M=Math.max(0,qo(r(t),450)),v=Math.max(0,qo(i(t),110)),k=Math.max(0,qo(a(t),135)),$=Math.PI*w*w,A=Math.floor(v/$),S=A*$,I=Math.floor(k/5.359375),C=I*zo*zo*zo,N=M+S+C,z=Eo(b,N),F=Math.min(b.height,Math.max(0,z)),j=jo(b,F),{pearls:W,layers:E}=Lo(b,w,A),O=F,R=Po(b,E*w*2,O,I),L=b.height-20.32,P=Math.min(0,L),q=Math.min(f*d/(2*(b.topRadius+1)),m/(b.height-P)),T=x+f/2,D=e=>T+e*q,B=e=>p+(e-P)*q,V=D(-(b.topRadius+1)),H=D(b.topRadius+1),Y=B(P),G=B(b.height),X=ce({name:n,teaVolume:M,bobaVolume:Math.round(S),iceVolume:Math.round(C),totalVolume:Math.round(N),numBobas:A,numIce:I,kind:"boba cup"});g.push({type:"rect",x:V,y:Y,w:Math.max(1,H-V),h:Math.max(1,G-Y),style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:X,group:n,_transitionKey:"boba-"+we(n)});const _=b.height-O,K=we(n),Q=e.resolveColor(n);y.push(No("g",{children:[M>0?Co("path",{d:`M${D(-j)},${B(_)} L${D(-b.bottomRadius)},${B(b.height)} L${D(b.bottomRadius)},${B(b.height)} L${D(j)},${B(_)} z`,fill:"#D2B799"}):null,W.map((e,t)=>Co("circle",{cx:D(e.x),cy:B(e.z),r:w*q,fill:"#222222",opacity:.5},"p-"+t)),R.map((e,t)=>Co("rect",{x:D(e.cx)-.95*zo*q/2,y:B(e.cy)-.95*zo*q/2,width:.95*zo*q,height:.95*zo*q,rx:2,fill:"#a5f2f3",opacity:.85,transform:`rotate(${e.rotation} ${D(e.cx)} ${B(e.cy)})`},"i-"+t)),Co("path",{d:`M${D(-b.topRadius)},${B(0)} L${D(-b.bottomRadius)},${B(b.height)} L${D(b.bottomRadius)},${B(b.height)} L${D(b.topRadius)},${B(0)}`,fill:"none",stroke:Fo,strokeWidth:2.5}),Co("line",{x1:D(-(b.topRadius+1)),y1:B(0),x2:D(b.topRadius+1),y2:B(0),stroke:Fo,strokeWidth:3,strokeLinecap:"round"}),M>0?Co("path",{d:`M${D(-.635)},${B(L)} L${D(-.635)},${B(b.height-.4)} L${D(.635)},${B(b.height-1.27-.4)} L${D(.635)},${B(L)} z`,fill:"#4F91CB",stroke:Fo,strokeWidth:1,opacity:.78}):null,Co("text",{x:T,y:G+16,textAnchor:"middle",fontSize:12,fontWeight:600,fill:"var(--semiotic-text, #333)",children:n}),Co("text",{x:T,y:G+30,textAnchor:"middle",fontSize:10,fill:Q,children:`${A} pearls · ${Math.round(N)} cm³`})]},"boba-"+K))}return{nodes:g,overlays:Co("g",{className:"semiotic-boba",style:{pointerEvents:"none"},children:y})}},Do=["naturalGas","coal","nuclear","hydro","wind","solar","other"],Bo={naturalGas:"Natural gas",coal:"Coal",nuclear:"Nuclear",hydro:"Hydro",wind:"Wind",solar:"Solar",other:"Other"},Vo={tight:5,watch:12,comfortable:20};function Ho(e,t=0){return"number"==typeof e&&Number.isFinite(e)?e:t}function Yo(e,t={}){const n=t.fuels??Do,o=!0===t.includeZero,r=[];for(const t of e)if(t&&"number"==typeof t.t)for(const e of n){const n=Ho(t.fuels?.[e]);(o||n>0)&&r.push({t:t.t,fuel:e,fuelLabel:Bo[e],mw:n,ba:t.ba})}return r}function Go(e){const t=[];for(const n of e){if(!n||"number"!=typeof n.t)continue;const e=Ho(n.demandMw),o=n.forecastMw;"number"==typeof o&&Number.isFinite(o)&&t.push({t:n.t,a:e,b:o,demandMw:e,forecastMw:o,errorMw:e-o,ba:n.ba})}return t}function Xo(e){const t=Ho(e.demand);if(0>=t)return 0;const n=Ho(e.capacityOrNetGen),o=Ho(e.interchange);return(n+(0>o?-o:0)-t)/t*100}function _o(e){return e.filter(e=>e&&"number"==typeof e.t).map(e=>{const t=Ho(e.demandMw),n=Ho(e.netGenMw),o=Xo({demand:t,capacityOrNetGen:n,interchange:e.interchangeMw});return{t:e.t,ba:e.ba,reserveMarginPct:o,netLoadMw:t,demandMw:t,netGenMw:n}})}function Ko(e={},t={}){const{watch:n,comfortable:o}={...Vo,...e},r=t.field,i=r?{field:r}:{},a=t.tightHatch??{type:"hatch",background:"var(--semiotic-danger, #c2410c)",stroke:"rgba(255, 240, 200, 0.55)",spacing:5,angle:-35,lineWidth:1.25,lineOpacity:.9};return[{id:"reserve-comfortable",label:`Comfortable (≥ ${o}%)`,when:{...i,gte:o},style:{fill:t.comfortableFill??"var(--semiotic-success, #16a34a)",fillOpacity:.85}},{id:"reserve-watch",label:`Watch (< ${o}%, ≥ ${n}%)`,when:{...i,lt:o,gte:n},style:{fill:t.watchFill??"var(--semiotic-warning, #d97706)",fillOpacity:.9}},{id:"reserve-tight",label:`Tight (< ${n}%)`,when:{...i,lt:n},style:{fill:a,stroke:t.tightFill??"var(--semiotic-danger, #c2410c)",strokeWidth:1,fillOpacity:1}}]}function Qo(e={}){const{tight:t,watch:n,comfortable:o}={...Vo,...e};return[{type:"band",y0:-50,y1:t,label:"Tight",color:"var(--semiotic-danger, #c2410c)",fillOpacity:.12,emphasis:"secondary"},{type:"band",y0:t,y1:n,label:"Watch",color:"var(--semiotic-warning, #d97706)",fillOpacity:.1,emphasis:"secondary"},{type:"band",y0:n,y1:Math.max(o+30,40),label:"Headroom",color:"var(--semiotic-success, #16a34a)",fillOpacity:.06,emphasis:"secondary"}]}function Zo(e,t){if(!e.length)return null;const n=[...e].filter(e=>e&&"number"==typeof e.t).sort((e,t)=>e.t-t.t);if(!n.length)return null;let o=n[n.length-1];if("number"==typeof t&&Number.isFinite(t)){const e=n.filter(e=>t>=e.t);o=e.length?e[e.length-1]:n[0]}const r=Ho(o.demandMw),i=Ho(o.netGenMw),a="number"==typeof o.forecastMw&&Number.isFinite(o.forecastMw)?o.forecastMw:null,s=Xo({demand:r,capacityOrNetGen:i,interchange:o.interchangeMw}),c={};let l=null,u=0,d=0;for(const e of Do){const t=Ho(o.fuels?.[e]);t>0&&(d+=t,c[e]=t,t>u&&(u=t,l=e))}if(d>0)for(const e of Object.keys(c))c[e]=c[e]/d;return{t:o.t,ba:o.ba,demandMw:r,forecastMw:a,forecastErrorMw:null==a?null:r-a,netGenMw:i,reserveMarginPct:s,topFuel:l,topFuelShare:d>0?u/d:0,topFuelMw:u,fuelShares:c}}function Uo(e,t={}){const n=t.now??Date.now(),o=t.author??"system",r=t.source??"authored-scenario";return e.map(e=>{const t=(e.start+e.end)/2,i=new Date(e.start).toISOString();return{type:"x-band",x0:e.start,x1:e.end,label:e.label,color:"outage"===e.kind?"var(--semiotic-danger)":"var(--semiotic-warning)",fillOpacity:.12,emphasis:"secondary",x:t,y:e.y??e.value,note:e.note,provenance:{author:o,authorKind:"system",source:r,basis:"rule",confidence:.85,createdAt:i,stableId:e.id,dataVersion:e.start+""},lifecycle:{status:"accepted",ttlHint:e.ttlHint??"P14D",anchor:"fixed"},_eventKind:e.kind,_createdAtMs:e.start,_nowMs:n}})}function Jo(e,t=12){return[...e].filter(e=>Number.isFinite(e.reserveMarginPct)).sort((e,t)=>e.reserveMarginPct-t.reserveMarginPct).slice(0,Math.max(0,t))}function er(e,t=0){return Number.isFinite(e)?e.toLocaleString(void 0,{maximumFractionDigits:t,minimumFractionDigits:t})+" MW":"—"}function tr(e,t=1){return Number.isFinite(e)?`${e>0?"+":""}${e.toFixed(t)}%`:"—"}import*as nr from"react";function or(e,t){if("function"==typeof e)return e;const n=e??t;return e=>Number(e[n])}function rr(e,t={}){const n=or(t.start,"start"),o=or(t.end,"end"),r=!1===t.sort?e.slice():e.slice().sort((e,t)=>n(e)-n(t)||o(t)-o(e)),i=[];return{packed:r.map(e=>{const t=n(e);let r=i.findIndex(e=>t>=e);return-1===r&&(r=i.length),i[r]=o(e),{item:e,track:r}}),trackCount:Math.max(1,i.length)}}function ir(e,t){const n=or(t.start,"start"),o=or(t.end,"end"),[r,i]=t.domain,a=t.step??1,s="half-open"===t.bounds,c=[];for(let t=r;i>=t;t+=a){let r=0;for(const i of e){const e=n(i),a=o(i);e>t||(s?t>=a:t>a)||r++}c.push({value:t,count:r})}return c}function ar(e){return"function"==typeof e?e:t=>t[e]}var sr=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height||0===e.data.length||!t?.domain)return{nodes:[]};const o=ar(t.laneAccessor),r=ar(t.startAccessor),i=ar(t.endAccessor),s=t.idAccessor?ar(t.idAccessor):null,c=t.unit??0,l=t.barGap??1.5,u=Math.max(0,t.minBarWidth??2),d=t.minBarHeight??3.5,h=t.maxBarHeight??10,f=t.lanePadding??7,m=t.cornerRadius??2,p=t.bottomInset??0,g=t.color??((t,n)=>e.resolveColor(n)),[y,x]=t.domain,b=x-y||1,w=e=>n.x+(e-y)/b*n.width,M=e.scales?.o?.domain?.()??[],k=t.lanes??(M.length>0?M:[...new Set(e.data.map(o))]),$=Math.max(0,n.height-p)/Math.max(1,k.length),A=e=>w(r(e)),S=e=>Math.max(A(e)+u,w(i(e)+c)),I=[];k.forEach((t,r)=>{const i=n.y+r*$,a=e.data.filter(e=>o(e)===t);if(0===a.length)return;const{packed:c,trackCount:u}=rr(a,{start:A,end:S}),p=new Map,y=new Map;for(const{item:e,track:t}of c){const n=y.get(t);n?n.push(e):y.set(t,[e])}for(const e of y.values()){e.sort((e,t)=>A(e)-A(t));for(let t=0;e.length-1>t;t++)p.set(e[t],A(e[t+1]))}const x=($-2*f)/u,b=Math.min(h,Math.max(Math.min(d,x),x-l));for(const{item:e,track:n}of c){const o=A(e),r=p.get(e),a=S(e)-o;I.push({type:"rect",x:o,y:i+f+n*x,w:void 0!==r&&o+a>r-1?Math.max(1,r-1-o):a,h:b,cornerRadii:m>0?{tl:m,tr:m,br:m,bl:m}:void 0,style:{fill:g(e,t),stroke:"none"},datum:e,group:t,_transitionKey:s?s(e)+"":void 0})}});const C=`var(--semiotic-text, ${e.theme.semantic.text??"#1a1a1a"})`,N=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,z=`var(--semiotic-border, ${e.theme.semantic.border??"#94a3b8"})`,F=[];(t.periods??[]).forEach((e,t)=>{const o=w(e.start),r=Math.max(1,w(e.end+c)-o);F.push(nr.createElement("rect",{key:"period-"+t,x:o,y:n.y,width:r,height:n.height,fill:z,opacity:t%2==0?.06:.025,pointerEvents:"none"})),e.name&&F.push(a({keyId:"period-label-"+t,text:e.name,x:o+4,y:n.y+12,anchor:"start",baseline:"hanging",fontSize:13,fontWeight:700,color:N}))});const j=!1!==t.showLaneLabels,W=t.laneLabelGap??12;if(k.forEach((e,t)=>{const o=n.y+t*$;F.push(nr.createElement("line",{key:"lane-sep-"+t,x1:n.x,x2:n.x+n.width,y1:o,y2:o,stroke:z,opacity:.45})),j&&F.push(a({keyId:"lane-label-"+t,text:e,x:n.x-W,y:o+$/2,anchor:"end",baseline:"middle",fontSize:12,fontWeight:600,color:C}))}),!1!==t.showAxis){const e=t.axisTicks??Array.from({length:8},(e,t)=>Math.round(y+t/7*b));F.push(v({keyId:"interval-axis",scale:w,ticks:e,orient:"top",offset:n.y,tickLength:0,gridLength:n.height,gridDasharray:"3 5",edgeAnchor:!0,format:t.tickFormat,color:N}))}return{nodes:I,overlays:nr.createElement(nr.Fragment,null,...F)}};function cr(e,t,n){const o=n?.orientation??"vertical",r=n?.bend??0,i=n?.minAlong??18,a=(e,t)=>(e+t)/2;if("vertical"===o){if(i>Math.abs(t.y-e.y)){const n=e.x>t.x?-1:1,o=a(e.x,t.x)+n*(22+Math.abs(r));return`M${e.x},${e.y} Q${o},${a(e.y,t.y)} ${t.x},${t.y}`}const n=a(e.y,t.y)+r;return`M${e.x},${e.y} C${e.x},${n} ${t.x},${n} ${t.x},${t.y}`}if(i>Math.abs(t.x-e.x)){const n=e.y>t.y?-1:1,o=a(e.y,t.y)+n*(22+Math.abs(r));return`M${e.x},${e.y} Q${a(e.x,t.x)},${o} ${t.x},${t.y}`}const s=a(e.x,t.x)+r;return`M${e.x},${e.y} C${s},${e.y} ${s},${t.y} ${t.x},${t.y}`}function lr(e,t,n){if("vertical"===(n?.orientation??"vertical")){const n=(e.y+t.y)/2;return`M${e.x},${e.y} L${e.x},${n} L${t.x},${n} L${t.x},${t.y}`}const o=(e.x+t.x)/2;return`M${e.x},${e.y} L${o},${e.y} L${o},${t.y} L${t.x},${t.y}`}function ur(e,t,n){if("vertical"===(n?.orientation??"vertical")){const n=t.cy>=e.cy;return{from:{x:e.cx,y:e.cy+(n?e.height/2:-e.height/2)},to:{x:t.cx,y:t.cy+(n?-t.height/2:t.height/2)}}}const o=t.cx>=e.cx;return{from:{x:e.cx+(o?e.width/2:-e.width/2),y:e.cy},to:{x:t.cx+(o?-t.width/2:t.width/2),y:t.cy}}}function dr(e,t){const n=t?.spread??5;return t?.modulo&&t.modulo>0?(e%t.modulo-(t.modulo-1)/2)*n:(e-((t?.count??1)-1)/2)*n}function hr(e,t){const n=1-t,o=n*n*n,r=3*n*n*t,i=3*n*t*t,a=t*t*t;return{x:o*e.p0.x+r*e.p1.x+i*e.p2.x+a*e.p3.x,y:o*e.p0.y+r*e.p1.y+i*e.p2.y+a*e.p3.y}}function fr(e,t){const n=1-t,o=3*n*n,r=6*n*t,i=3*t*t;return{x:o*(e.p1.x-e.p0.x)+r*(e.p2.x-e.p1.x)+i*(e.p3.x-e.p2.x),y:o*(e.p1.y-e.p0.y)+r*(e.p2.y-e.p1.y)+i*(e.p3.y-e.p2.y)}}function mr(e){return`M${e.p0.x},${e.p0.y} C${e.p1.x},${e.p1.y} ${e.p2.x},${e.p2.y} ${e.p3.x},${e.p3.y}`}function pr(e,t){const n=t?.axis??"x",o=t?.padding??0,r=t?.strength??.5,i="x"===n?"y":"x",a="x"===n?"width":"height",s="x"===n?"height":"width",c=new Map;for(const t of e)c.set(t.id,0);for(let t=0;e.length>t;t++)for(let l=t+1;e.length>l;l++){const u=e[t],d=e[l];if(Math.abs(u[i]-d[i])>(u[s]+d[s])/2+o)continue;const h=d[n]-u[n]||(d.id>u.id?-.5:.5),f=(u[a]+d[a])/2+o-Math.abs(h);if(0>=f)continue;const m=f*r*Math.sign(h);c.set(u.id,(c.get(u.id)??0)-m),c.set(d.id,(c.get(d.id)??0)+m)}return c}var gr={width:60,height:34};function yr(e,t){if("function"==typeof e)return e;const n=e??t;return e=>ge(e,n,void 0)}function xr(e,t,n,o){const r=o.fixedAxis??"y",i=e=>yr(o.sourceAccessor,"source")(e)+"",a=e=>yr(o.targetAccessor,"target")(e)+"",s=o.size??(()=>gr),c=o.iterations??180,l=o.attraction??.012,u=o.anchorStrength??.003,d=o.collisionStrength??.12,h=o.collisionPadding??15,f=o.edgePadding??42,m=o.fixedPadding??16,p=o.damping??.72,g=o.spread??1,[y,x]=o.fixedDomain,b=x-y||1,w=("y"===r?n.y:n.x)+m,M=("y"===r?n.y+n.height:n.x+n.width)-m,v=("y"===r?n.x:n.y)+f,k=("y"===r?n.x+n.width:n.y+n.height)-f,$=Math.max(1,k-v),A=e.map(e=>{const t=Me(e)??e,n=(r=e,yr(o.idAccessor,"id")(r)+"");var r;const{width:i,height:a}=s(t),c=(e=>Number(yr(o.fixedAccessor,"fixed")(e)))(e),l=v+function(e){let t=2166136261;for(let n=0;e.length>n;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)/4294967295}(n)*$;return{data:t,id:n,width:i,height:a,fixedValue:c,fixed:(u=c,w+(u-y)/b*(M-w)),free:l,anchor:l};var u}),S=new Map(A.map(e=>[e.id,e])),I=e=>"y"===r?e.width:e.height;for(let e=0;c>e;e++){const e=new Map;for(const t of A)e.set(t.id,0);for(const n of t){const t=S.get(i(n)),o=S.get(a(n));if(!t||!o)continue;const r=(o.free-t.free)*l;e.set(t.id,(e.get(t.id)??0)+r),e.set(o.id,(e.get(o.id)??0)-r)}for(const t of A)e.set(t.id,(e.get(t.id)??0)+(t.anchor-t.free)*u);const n=pr(A.map(e=>({id:e.id,x:"y"===r?e.free:e.fixed,y:"y"===r?e.fixed:e.free,width:e.width,height:e.height})),{axis:"y"===r?"x":"y",padding:h,strength:d});for(const t of A)e.set(t.id,(e.get(t.id)??0)+(n.get(t.id)??0));for(const t of A){t.free+=(e.get(t.id)??0)*p;const n=I(t)/2;t.free=Math.max(v+n,Math.min(k-n,t.free))}}if(1!==g){const e=(v+k)/2;for(const t of A){const n=I(t)/2;t.free=Math.max(v+n,Math.min(k-n,e+(t.free-e)*g))}}const C=A.map(e=>({data:e.data,id:e.id,x:"y"===r?e.free:e.fixed,y:"y"===r?e.fixed:e.free,width:e.width,height:e.height,fixedValue:e.fixedValue}));return{positioned:C,byId:new Map(C.map(e=>[e.id,e]))}}var br=e=>{const{plot:t}=e.dimensions;if(0>=t.width||0>=t.height||0===e.nodes.length||!e.config?.fixedDomain)return{sceneNodes:[]};const n=e.config.fixedAxis??"y",{positioned:o,byId:r}=xr(e.nodes,e.edges,t,e.config),i=o.map(t=>({type:"rect",x:t.x-t.width/2,y:t.y-t.height/2,w:t.width,h:t.height,style:{fill:e.resolveColor(t.id),stroke:"none"},datum:t.data,id:t.id,label:t.id})),a=[];e.edges.forEach((t,o)=>{const i=r.get((s=t,("function"==typeof e.config.sourceAccessor?e.config.sourceAccessor(s):ge(s,e.config.sourceAccessor??"source",void 0))+""));var s;const c=r.get((t=>("function"==typeof e.config.targetAccessor?e.config.targetAccessor(t):ge(t,e.config.targetAccessor??"target",void 0))+"")(t));if(!i||!c)return;const{from:l,to:u}=ur({cx:i.x,cy:i.y,width:i.width,height:i.height},{cx:c.x,cy:c.y,width:c.width,height:c.height},{orientation:"y"===n?"vertical":"horizontal"});a.push({type:"curved",pathD:cr(l,u,{orientation:"y"===n?"vertical":"horizontal",bend:dr(o,{modulo:5,spread:5})}),style:{stroke:"var(--semiotic-border, #888)",fill:"none",strokeWidth:1.4},datum:Me(t)??t})});const s=o.map(e=>({x:e.x,y:e.y,text:e.id}));return{sceneNodes:i,sceneEdges:a,labels:s}};function wr(e){const t=Number(e.segmentDomain?.[0]),n=Number(e.segmentDomain?.[1]),o=Number.isFinite(t)?t:0,r=Number.isFinite(n)?n:o,i=o>r?-1:1,a=Math.abs(r-o),s=Number(e.currentSegment),c=Number.isFinite(s)?ae((s-o)*i,0,a):0,l=(e,t)=>{const n=Number(e);return Number.isFinite(n)?ae(n,0,1):t},u=l(e.oldestOpacity,.25),d=l(e.currentOpacity,1),h=l(e.futureOpacity,0);return{weightOpacity:!0===e.combineWeightOpacity,wordOpacity:({segment:e})=>{const t=Number(e);if(!Number.isFinite(t))return h;const n=(t-o)*i;if(n>c)return h;if(0===c)return d;const r=ae(n/c,0,1);return u+(d-u)*r}}}import{jsx as Mr,jsxs as vr}from"react/jsx-runtime";function kr(e){let t=2166136261;for(let n=0;e.length>n;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0)/4294967295}var $r=1.15,Ar={a:.556,b:.556,c:.5,d:.556,e:.556,f:.278,g:.556,h:.556,i:.222,j:.222,k:.5,l:.222,m:.833,n:.556,o:.556,p:.556,q:.556,r:.333,s:.5,t:.278,u:.556,v:.5,w:.722,x:.5,y:.5,z:.5,"'":.191,"-":.333,".":.278," ":.278};function Sr(e){let t=0;for(const n of e)t+=Ar[n]??.6;return t}function Ir(e,t){return Math.max(8,Sr(e)*t*1.05+1)}function Cr(e,t,n){for(const o of t)if((e.w+o.w)/2+n>Math.abs(e.x-o.x)&&(e.h+o.h)/2+n>Math.abs(e.y-o.y))return!0;return!1}var Nr=e=>{const t=e.config,{plot:n}=e.dimensions;if(0>=n.width||0>=n.height||0===e.data.length)return{nodes:[]};const o=ye(t.textAccessor),r=e=>{const n=Number(ye(t.weightAccessor)(e));return Number.isFinite(n)&&n>0?n:0},i=ye(t.columnAccessor),a=e=>Number(ye(t.segmentAccessor)(e)),s=t.minFontSize??11,c=t.maxFontSize??42,l=t.columnGutter??18,u=t.collisionPadding??2,d=!1!==t.showColumnLabels,h=!1!==t.showSegmentAxis,f=t.segmentTickCount??6,m=t.segmentTickFormat??(e=>Math.round(e)+""),p=t.rotate??0,g=!0===t.repeatWords,y=!1!==t.scaleToFit,x=t.packingDensity??.6,b="string"==typeof t.textAccessor?t.textAccessor:"word",w="string"==typeof t.weightAccessor?t.weightAccessor:"weight",M="string"==typeof t.columnAccessor?t.columnAccessor:"column",v="string"==typeof t.segmentAccessor?t.segmentAccessor:"segment",k=[],$=new Map;let A=1/0,S=-1/0;for(let t=0;e.data.length>t;t++){const n=e.data[t],s=i(n)+"",c=o(n)+"",l=r(n),u=a(n);c&&Number.isFinite(u)&&($.has(s)||(k.push(s),$.set(s,[])),$.get(s).push({col:s,text:c,weight:l,segment:u,datum:n,dataIndex:t}),A>u&&(A=u),u>S&&(S=u))}if(0===k.length)return{nodes:[]};if(!g)for(const[e,t]of $){const n=new Map;for(const e of t){const t=n.get(e.text);t&&t.weight>=e.weight||n.set(e.text,e)}$.set(e,[...n.values()])}let I=1/0,C=-1/0;for(const e of $.values())for(const t of e)I>t.weight&&(I=t.weight),t.weight>C&&(C=t.weight);if(!Number.isFinite(I))return{nodes:[]};const N=t.columnOrder?[...t.columnOrder.filter(e=>$.has(e)),...k.filter(e=>!t.columnOrder.includes(e))]:k,z=new Map(N.map(n=>[n,t.columnColor?.(n)||e.resolveColor(n)])),[F,j]=t.segmentDomain??[A,S],W=j-F||1,E=C-I||1,O=d?22:0,R=h?52:0,L=n.x+R,P=n.y+O,q=Math.max(0,n.width-R),T=Math.max(0,n.height-O),D=N.length,B=D>0?Math.max(0,q-l*Math.max(0,D-1))/D:0,V=P+14,H=P+T-14,Y=e=>V+(e-F)/W*(H-V),G=B*T;let X=1/0,_=1/0;const K=N.map((e,n)=>{const o=z.get(e),r=($.get(e)??[]).map(e=>{const r={word:e.text,column:e.col,weight:e.weight,segment:e.segment,datum:e.datum,dataIndex:e.dataIndex,columnIndex:n,resolvedColumnColor:o},i=t.wordOpacity?Number(t.wordOpacity(r)):1,a=t.wordColor?.(r);return{text:e.text,weight:e.weight,segment:e.segment,baseFont:(l=e.weight,s+Math.sqrt((l-I)/E)*(c-s)),opacity:Number.isFinite(i)?ae(i,0,1):0,color:a||o,info:r};var l});if(0===r.length)return null;let i=0;for(const e of r){const t=1.05*Sr(e.text);i+=t*$r*e.baseFont*e.baseFont,_=Math.min(_,(B-8-1)/(t*e.baseFont))}return i>0&&(X=Math.min(X,Math.sqrt(x*G/i))),{col:e,colLeft:L+n*(B+l),center:L+n*(B+l)+B/2,rows:r}}).filter(e=>null!==e),Q=e=>{const t=[];let n=0;for(const o of K){if(0>=B)continue;const r=o.colLeft+4,i=o.colLeft+B-4,a=o.rows.map((t,n)=>{const r=Math.max(5,e*t.baseFont),i=`${o.col}::${t.text}::${n}`;return{id:i,text:t.text,weight:t.weight,segment:t.segment,font:r,w:Ir(t.text,r),h:r*$r+2,anchorY:Y(t.segment),seed:(kr(i)-.5)*Math.min(.5*B,80),opacity:t.opacity,color:t.color,info:t.info}}).sort((e,t)=>t.font-e.font||(t.id>e.id?-1:1)),s=[];for(const e of a){const a=e.w/2,c=e.h/2,l=ae(o.center+e.seed,r+a,i-a),d=e.anchorY;let h=l,f=ae(d,V+c,H-c),m=!1;for(let t=0;2600>t;t++){const n=3.2*Math.sqrt(t),o=2.399963229728653*t,p={x:ae(l+n*Math.cos(o),r+a,i-a),y:ae(d+n*Math.sin(o),V+c,H-c),w:e.w,h:e.h};if(!Cr(p,s,u)){h=p.x,f=p.y,m=!0;break}}m||n++,s.push({x:h,y:f,w:e.w,h:e.h});const g=Math.sqrt((e.weight-I)/E),y=p>0?2*(kr(e.id+"r")-.5)*p:0;t.push({id:e.id,text:e.text,x:h,y:f,fontSize:e.font,rotation:y,color:e.color,opacity:e.opacity,datum:se(t=>{for(const n of Object.keys(e.info.datum))t(n,e.info.datum[n]);t("word",e.text),t("weight",e.weight),t("column",o.col),t("segment",e.segment),"word"!==b&&t(b,e.text),"weight"!==w&&t(w,e.weight),"column"!==M&&t(M,o.col),"segment"!==v&&t(v,e.segment),t("__strength",.5+.5*g)})})}}return{placed:t,unplaced:n}};let Z=y?Math.min(1,X,_):Math.min(1,_),U=Q(Z);if(y)for(let e=0;6>e&&U.unplaced>0&&Z>.1;e++)Z*=.88,U=Q(Z);const J=U.placed.filter(e=>e.opacity>0);return{nodes:J.map(e=>{const t=Ir(e.text,e.fontSize)/2,n=e.fontSize*$r/2;return{type:"rect",x:e.x-t,y:e.y-n,w:2*t,h:2*n,style:{fill:"rgba(0,0,0,0)",stroke:"none"},datum:e.datum,group:e.datum.column+"",_transitionKey:e.id}}),overlays:vr("g",{className:"semiotic-word-trails",children:[h&&zr({x:n.x+R-10,yTop:V,yBot:H,segLo:F,segHi:j,segToY:Y,tickCount:f,tickFormat:m,color:`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,label:t.segmentAxisLabel,labelX:n.x}),d&&N.map((e,t)=>B>0?Mr("text",{x:L+t*(B+l)+B/2,y:n.y+14,textAnchor:"middle",fontSize:13,fontWeight:600,fill:z.get(e),style:{pointerEvents:"none"},children:e},"wt-col-"+t):null),J.map(e=>Mr("text",{x:e.x,y:e.y,textAnchor:"middle",dominantBaseline:"central",fontSize:e.fontSize,fontWeight:600,fill:e.color,opacity:(!1===t.weightOpacity?1:Number(e.datum.__strength))*e.opacity,transform:e.rotation?`rotate(${e.rotation} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},"wt-"+e.id))]})}};function zr(e){const t=[],n=e.segHi-e.segLo||1;for(let o=0;e.tickCount>o;o++)t.push(e.segLo+n*o/Math.max(1,e.tickCount-1));return vr("g",{className:"semiotic-word-trails-axis",style:{pointerEvents:"none"},children:[Mr("line",{x1:e.x,y1:e.yTop,x2:e.x,y2:e.yBot,stroke:e.color,strokeWidth:1,opacity:.5}),t.map((t,n)=>{const o=e.segToY(t);return vr("g",{children:[Mr("line",{x1:e.x-4,y1:o,x2:e.x,y2:o,stroke:e.color,strokeWidth:1,opacity:.6}),Mr("text",{x:e.x-7,y:o,textAnchor:"end",dominantBaseline:"central",fontSize:11,fill:e.color,children:e.tickFormat(t)})]},"wt-tick-"+n)}),e.label&&Mr("text",{transform:`rotate(-90 ${e.labelX+10} ${(e.yTop+e.yBot)/2})`,x:e.labelX+10,y:(e.yTop+e.yBot)/2,textAnchor:"middle",fontSize:11,fontWeight:600,fill:e.color,children:e.label})]})}var Fr={fill:"rgba(0,0,0,0)",stroke:"rgba(0,0,0,0)",opacity:0},jr=8;function Wr(e){return null==e?void 0:e+""}function Er(e){const t=Wr(e.id);return{type:"point",x:e.x,y:e.y,r:e.r??8,style:{...Fr,cursor:e.cursor},datum:e.datum,pointId:t,_transitionKey:t}}function Or(e){return Er(e)}function Rr(e){const[[t,n],[o,r]]=e.bounds;return{type:"geoarea",pathData:e.pathData,centroid:e.centroid,bounds:e.bounds,screenArea:e.screenArea??Math.abs((o-t)*(r-n)),style:{...Fr,cursor:e.cursor},datum:e.datum,group:e.group,interactive:!0}}function Lr(e){return{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Fr,cursor:e.cursor},datum:e.datum,group:e.group,_transitionKey:Wr(e.id)}}function Pr(e){const t=Wr(e.id);return"width"in e&&"height"in e?{type:"rect",x:e.x,y:e.y,w:e.width,h:e.height,style:{...Fr,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}:{type:"circle",cx:e.x,cy:e.y,r:e.r??8,style:{...Fr,cursor:e.cursor},datum:e.datum,id:t,label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility}}function qr(e){const t={style:{...Fr,cursor:e.cursor},datum:e.datum,id:Wr(e.id),label:e.label,accessibleDatum:e.accessibleDatum,accessibility:e.accessibility,interactive:e.interactive??!0};return"pathD"in e?{type:e.type??"curved",pathD:e.pathD,...t}:{type:"line",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,...t}}function Tr(e,t,n={}){const{coord:o,step:r=1,equals:i=Object.is,truthyOnly:a=!1}=n,s=[],c=t=>o?o(e[t],t):t,l=(e,t,n)=>{e.endIndex=t,e.count=t-e.startIndex+1,e.end=o?null==n||c(n)-c(t)>r?c(t)+r:c(n):t+1,s.push(e)};let u=null;for(let n=0;e.length>n;n++){const s=t(e[n],n);if(a&&!s){u&&(l(u,u.endIndex,n),u=null);continue}const d=!o||0>=n||c(n)-c(n-1)<=r;u&&d&&i(u.value,s)?u.endIndex=n:(u&&l(u,u.endIndex,n),u={value:s,start:c(n),end:c(n),count:1,startIndex:n,endIndex:n})}return u&&l(u,u.endIndex,null),s}var Dr=Tr;function Br(e,t,n=0){return t>0?((e-n)%t+t)%t+n:e}function Vr(e,t,n){if(0>=n)return t-e;let o=(t-e)%n;return o>n/2?o-=n:-n/2>o&&(o+=n),o}function Hr(e,t,n){return t>n?e>=t||n>=e:e>=t&&n>=e}function Yr(e,t,n,o){return n>o?[...e.filter(e=>t(e)>=n),...e.filter(e=>t(e)<=o)]:e.filter(e=>Hr(t(e),n,o))}function Gr(e,t){const n=Math.max(0,t.width),o=t.y,r=Math.min(74,Math.max(34,.08*n)),i=t.paddingLeft??r,a=e.length>1?Math.max(0,n-i-(t.paddingRight??r))/(e.length-1):0,s=new Map;return e.forEach((e,t)=>{s.set(e.id,{id:e.id,x:i+a*t,y:o,index:t})}),s}function Xr(e,t){const n=Math.max(0,t.width),o=t.y,r=Math.min(74,Math.max(34,.08*n)),i=t.paddingLeft??r,a=t.paddingRight??r,s=t.gap??8,c=!1!==t.distribute,l=t.estimateWidth??(e=>_r(e.label??e.id)),u=e.map((e,t)=>Math.max(1,l(e,t))),d=u.reduce((e,t)=>e+t,0)+s*Math.max(0,e.length-1),h=Math.max(0,n-i-a),f=c&&e.length>1?Math.max(0,h-d)/(e.length-1):0,m=new Map;let p=i;return c||1!==e.length||(p=i+Math.max(0,(h-u[0])/2)),e.forEach((e,t)=>{const n=u[t];m.set(e.id,{id:e.id,x:p+n/2,y:o,index:t,width:n}),p+=n+s+f}),m}function _r(e,t=38,n=7.4,o=20){return Math.max(t,((e??"")+"").length*n+o)}function Kr(e){const t=e.map(e=>{const t=Math.min(e.a,e.b),n=Math.max(e.a,e.b);return{span:e,a:t,b:n,width:n-t}}).sort((e,t)=>e.width-t.width||e.a-t.a),n=[],o=t.map(e=>{let t=n.findIndex(t=>e.a>=t);return 0>t?(t=n.length,n.push(e.b)):n[t]=e.b,{span:e.span,level:t}}),r=o.reduce((e,t)=>Math.max(e,t.level),0);return{packed:o,maxLevel:r,levelCount:o.length?r+1:1}}function Qr(e){const t=e.labelRoom??18,n=Math.max(48,e.baselineY-e.ceilingY-28),o=Math.max(1,e.levelCount),r=Math.min(42,Math.max(26,.18*n)),i=Math.max(24,n-r-t);return{arcLift:r,levelStep:Math.min(72,Math.max(28,o>1?i/Math.max(1,o-1):i))}}function Zr(e,t,n,o,r={}){const i=n-(r.footLift??26);return`M${e} ${i}Q${(e+t)/2} ${o} ${t} ${i}`}function Ur(e,t,n){return e-n.arcLift-t*n.levelStep}function Jr(e,t=ei){if(!e.length)return{shared:[],exclusive:[]};if(1===e.length)return{shared:[...e[0]],exclusive:[[]]};const n=e.map(e=>new Set(e.map(e=>t(e)))),o=new Set;for(const e of n[0])n.every(t=>t.has(e))&&o.add(e);const r=[],i=new Set;for(const n of e[0]){const e=t(n);o.has(e)&&!i.has(e)&&(r.push(n),i.add(e))}return{shared:r,exclusive:e.map(e=>e.filter(e=>!o.has(t(e))))}}function ei(e){return null==e||"object"!=typeof e?e+"":null!=e.id?e.id+"":`${(e.sourceTokenId??e.source)+""}|${(e.targetTokenId??e.target)+""}|${(e.relation??e.label??"")+""}`}var ti=2*Math.PI;function ni(e,t,n){const o=n?.center?.x??0,r=n?.center?.y??0;return{x:o+Math.sin(e)*t,y:r-Math.cos(e)*t}}function oi(e,t,n){return(Math.atan2(e-(n?.center?.x??0),-(t-(n?.center?.y??0)))+ti)%ti}function ri(e,t){const[n,o]=e,r=o-n||1,i=t?.startAngle??0,a=t?.endAngle??ti;return e=>i+(e-n)/r*(a-i)}function ii(e,t){const[n,o]=e,[r,i]=t,a=o-n||1;return e=>r+(e-n)/a*(i-r)}function ai(e,t,n,o,r){const i=r?.center,a=(e,t)=>{const{x:n,y:o}=ni(e,t,{center:i});return`${si(n)},${si(o)}`},s=Math.max(0,n),c=Math.max(s,o),l=Math.abs(t-e),u=e>t?0:1;if(l>=ti-1e-6){const e=i?.x??0,t=i?.y??0,n=`${si(e)},${si(t-c)}`,o=`${si(e)},${si(t+c)}`;let r=`M${n} A${si(c)},${si(c)} 0 1 1 ${o} A${si(c)},${si(c)} 0 1 1 ${n} Z`;if(s>0){const n=`${si(e)},${si(t-s)}`,o=`${si(e)},${si(t+s)}`;r+=` M${n} A${si(s)},${si(s)} 0 1 0 ${o} A${si(s)},${si(s)} 0 1 0 ${n} Z`}return r}const d=l>Math.PI?1:0,h=a(e,c),f=a(t,c);if(0>=s){const e=i?.x??0,t=i?.y??0;return`M${si(e)},${si(t)} L${h} A${si(c)},${si(c)} 0 ${d} ${u} ${f} Z`}const m=a(t,s),p=a(e,s);return`M${h} A${si(c)},${si(c)} 0 ${d} ${u} ${f} L${m} A${si(s)},${si(s)} 0 ${d} ${1===u?0:1} ${p} Z`}function si(e){return Math.round(1e3*e)/1e3}function ci(e,t){return{x:e.x+t.x,y:e.y+t.y}}function li(e,t){return{x:e.x-t.x,y:e.y-t.y}}function ui(e,t){return{x:e.x*t,y:e.y*t}}function di(e){return Math.hypot(e.x,e.y)}function hi(e){const t=di(e)||1;return{x:e.x/t,y:e.y/t}}import{jsx as fi,jsxs as mi}from"react/jsx-runtime";var pi="var(--semiotic-text, currentColor)";function gi(e,t){const n=B(e,100);return n>0?t/n*100*(t/n):Math.PI*t*t}function yi(e){const t=[],n=e.colorMap?Object.entries(e.colorMap):e.keys?e.keys.map(t=>[t,e.color?e.color(t):void 0]):[];if(n.length>0){const o=e.colorType??"fill",r=n.map(([e,t])=>({label:e,color:t}));t.push({type:o,label:e.colorLabel??"",items:r,styleFn:"line"===o?e=>({stroke:e.color??pi,strokeWidth:2,fill:"none"}):e=>({fill:e.color??pi,stroke:e.color??pi})})}if(e.symbolMap&&Object.keys(e.symbolMap).length>0){const n=e.symbolColor??pi,o=Object.entries(e.symbolMap).map(([e,t])=>({label:e,shape:t,color:n}));t.push({label:e.symbolLabel??"",items:o,styleFn:()=>({}),type:e=>{const t=e.shape;return fi("path",{d:V(t,gi(t,7)),transform:"translate(8,8)",fill:e.color??n})}})}if(e.sizeStops&&e.sizeStops.length>0&&e.sizeRadius){const n=e.sizeRadius,o=e.sizeFormat??(e=>e+""),r=e.sizeColor??pi,i=e.sizeStops.map(e=>({label:o(e),r:Math.max(.5,n(e)),color:r}));t.push({label:e.sizeLabel??"",items:i,styleFn:()=>({}),type:e=>fi("circle",{cx:8,cy:8,r:e.r,fill:e.color??r})})}return t}function xi(e){const t=e.orientation??"vertical",n=e.swatchSize??14,o=e.gap??8,r=e.labelGap??6,i=e.fontSize??12,a=e.color??"var(--semiotic-text-secondary, #888)",s=n+o;let c=0;const l=[];return e.entries.forEach((e,u)=>{l.push(mi("g",{transform:`translate(${"vertical"===t?0:c},${"vertical"===t?c:0})`,children:[bi(e,n,e.color??e.line??a,a),fi("text",{x:n+r,y:n/2,dominantBaseline:"middle",fontSize:i,fill:a,children:e.label})]},"legend-"+u)),c+="vertical"===t?s:n+r+e.label.length*i*.58+o+8}),fi("g",{className:e.className,transform:`translate(${e.x},${e.y})`,style:{pointerEvents:"none"},children:l},e.keyId)}function bi(e,t,n,o){if(e.shape){const o=gi(e.shape,t/2-1);return fi("path",{d:V(e.shape,o),transform:`translate(${t/2},${t/2})`,fill:n})}if(e.hatch){const n=e.color??o;return mi("g",{children:[fi("svg",{width:t,height:t,style:{overflow:"hidden"},children:[-t,-t/2,0,t/2].map((e,o)=>fi("line",{x1:e,y1:t,x2:e+t,y2:0,stroke:n,strokeWidth:1,opacity:.7},o))}),fi("rect",{width:t,height:t,fill:"none",stroke:n,strokeWidth:1,opacity:.5,rx:2})]})}return fi("rect",e.line?{y:t/2-1.5,width:t,height:3,rx:1.5,fill:e.line}:{width:t,height:t,rx:2,fill:n})}var wi=new Set(["rows"]);function Mi(e){const t=e,n=[Ai(t,["datum","data"]),Ai(t,["datum"]),Ai(t,["data","data"]),Ai(t,["data"]),Ai(t,["node","datum","data"]),Ai(t,["node","datum"]),e];for(const e of n){if(!Si(e))continue;const t={};for(const[n,o]of Object.entries(e))n.startsWith("_")||"function"==typeof o||(t[n]=o);if(Object.keys(t).length>0)return t}return null}function vi(e,t={}){const n=Mi(e);if(!n)return[];const o=new Set(wi);if(t.excludeKeys)for(const e of t.excludeKeys)o.add(e);const r=[];for(const[e,i]of Object.entries(n))if((t.includeInternal||!e.startsWith("_"))&&!o.has(e)&&(t.includeEmpty||null!=i&&""!==i)&&"function"!=typeof i&&(r.push({key:e,label:$i(e,t.labels),value:i,formatted:t.valueFormat?t.valueFormat(i,e,n):ki(i)}),r.length>=(t.maxEntries??8)))break;return r}function ki(e){if(null==e)return"";if(e instanceof Date)return e.toISOString();if("number"==typeof e)return Number.isInteger(e)?e+"":e.toLocaleString(void 0,{maximumFractionDigits:2});if("boolean"==typeof e)return e?"true":"false";if(Array.isArray(e))return e.length+" items";if("object"==typeof e)try{return JSON.stringify(e)}catch{return e+""}return e+""}function $i(e,t){if("function"==typeof t)return t(e);if(t&&Object.prototype.hasOwnProperty.call(t,e)){const n=t[e];if("string"==typeof n&&n.length>0)return n}return e}function Ai(e,t){let n=e;for(const e of t){if(!Si(n))return;n=n[e]}return n}function Si(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Ii(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ci(e,t){return Ii(e,t)?e[t]:void 0}function Ni(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function zi(){return Object.create(null)}function Fi(e,t){const n=new Map;for(const t of e)n.set(t.id,new Set);for(const e of t)n.has(e.source)||n.set(e.source,new Set),n.has(e.target)||n.set(e.target,new Set),n.get(e.source).add(e.target),n.get(e.target).add(e.source);return n}function ji(e,t){const n={};for(const t of e)Ni(n,t.id,0);for(const e of t)Ni(n,e.source,(Ci(n,e.source)??0)+1),Ni(n,e.target,(Ci(n,e.target)??0)+1);return n}function Wi(e,t){const n={};Ni(n,t,0);const o=[t];let r=0;for(;o.length>r;){const t=o[r];r+=1;for(const r of e.get(t)||[])Ii(n,r)||(Ni(n,r,n[t]+1),o.push(r))}return n}function Ei(e,t,n,o){if(n===o)return n?[n]:[];const r=Fi(e,t),i=zi();i[n]=null;const a=[n];let s=0;for(;a.length>s;){const e=a[s];if(s+=1,e===o)break;for(const t of r.get(e)||[])Ii(i,t)||(i[t]=e,a.push(t))}if(!Ii(i,o))return[];const c=[];let l=o;for(;null!=l;)c.unshift(l),l=i[l];return c}function Oi(e,t,n,o=1){const r=Fi(e,t);if(!r.has(n))return new Set;const i=Wi(r,n),a=new Set;for(const e of Object.keys(i))i[e]>o||a.add(e);return a}function Ri(e,t){const n=Fi(e,t),o={};for(const t of e)Ni(o,t.id,0);for(const t of e.map(e=>e.id)){const r=[],i=zi(),a=zi(),s=zi();for(const t of e)i[t.id]=[],a[t.id]=0,s[t.id]=-1;a[t]=1,s[t]=0;const c=[t];let l=0;for(;c.length>l;){const e=c[l];l+=1,r.push(e);for(const t of n.get(e)||[])0>s[t]&&(s[t]=s[e]+1,c.push(t)),s[t]===s[e]+1&&(a[t]+=a[e],i[t].push(e))}const u=zi();for(const t of e)u[t.id]=0;for(;r.length;){const e=r.pop();for(const t of i[e])u[t]+=a[t]/a[e]*(1+u[e]);e!==t&&Ni(o,e,(Ci(o,e)??0)+u[e])}}for(const e of Object.keys(o))Ni(o,e,o[e]/2);return o}function Li(e,t){const n=Fi(e,t),o={};for(const t of e){const e=Wi(n,t.id);let r=0,i=0;for(const t of Object.keys(e))r+=e[t],i+=1;Ni(o,t.id,r>0?(i-1)/r:0)}return o}function Pi(e,t){const n=Fi(e,t),o={};for(const t of e){const e=[...n.get(t.id)||[]],r=e.length;if(2>r){Ni(o,t.id,0);continue}let i=0;for(let t=0;e.length>t;t+=1)for(let o=t+1;e.length>o;o+=1)n.get(e[t])?.has(e[o])&&(i+=1);Ni(o,t.id,2*i/(r*(r-1)))}return o}function qi(e){let t=0;for(const n of Object.keys(e))e[n]>t&&(t=e[n]);const n={};for(const o of Object.keys(e))Ni(n,o,t>0?e[o]/t:0);return n}function Ti(e,t,n,o={}){const r=Fi(e,t),i=zi();for(const t of e)i[t.id]=Wi(r,t.id);let a=o.minHops??4,s=o.startThreshold??.08;const c=o.maxThreshold??.2,l=new Set;let u=0;for(;0===l.size&&40>u;){for(let t=0;e.length>t;t+=1)for(let o=t+1;e.length>o;o+=1){const r=e[t].id,c=e[o].id,u=Ci(n,r),d=Ci(n,c);if(!u||!d)continue;const h=u.x-d.x,f=u.y-d.y;(void 0===i[r][c]?1/0:i[r][c])>=a&&s>Math.sqrt(h*h+f*f)&&(l.add(r),l.add(c))}0===l.size&&(s+=.02,s>c&&(s=o.startThreshold??.08,a=Math.max(2,a-1))),u+=1}return{problemIds:l,threshold:s,minHops:a}}function Di(e){if("undefined"!=typeof DOMException)return new DOMException(e+" aborted","AbortError");const t=Error(e+" aborted");return t.name="AbortError",t}function Bi(e){const t=Error(e.message);return t.name=e.name??"Error",e.stack&&(t.stack=e.stack),t}var Vi=class{constructor(e){this.nextRequestId=1,this.pending=new Map,this.dead=!1,this.options=e,this.worker=e.createWorker(),this.worker.onmessage=e=>{const t=this.options.parseMessage(e.data),n=t.requestId,o=null!=n?this.pending.get(n):this.pending.values().next().value;if(o){if(null!=n)this.pending.delete(n);else{for(const e of this.pending.values())e!==o&&(e.cleanup(),e.reject(Error(this.options.name+" worker response missing requestId")));this.pending.clear()}o.cleanup(),t.ok?o.resolve(t.payload):o.reject(t.error)}},this.worker.onerror=e=>{this.rejectAll(Error(e.message||this.options.name+" worker failed")),this.terminate()}}get isDead(){return this.dead}request(e,t){if(this.dead)return Promise.reject(Error(this.options.name+" worker session is closed"));if(t?.aborted)return Promise.reject(Di(this.options.name));const n=this.nextRequestId;this.nextRequestId+=1;const o=this.options.encodeRequest?.(n,e)??{requestId:n,request:e};return new Promise((e,r)=>{const i=()=>{const e=1===this.pending.size;this.pending.delete(n),t?.removeEventListener("abort",i),r(Di(this.options.name)),this.options.terminateOnAbort&&e&&this.terminate()},a=()=>t?.removeEventListener("abort",i);this.pending.set(n,{cleanup:a,reject:r,resolve:e}),t?.addEventListener("abort",i,{once:!0});try{this.worker.postMessage(o)}catch(e){this.pending.delete(n),a(),r(e instanceof Error?e:Error(e+""))}})}terminate(){this.dead||(this.dead=!0,this.rejectAll(Error(this.options.name+" worker terminated")),this.worker.terminate())}rejectAll(e){for(const t of this.pending.values())t.cleanup(),t.reject(e);this.pending.clear()}};function Hi(){return"undefined"!=typeof window&&"undefined"!=typeof Worker}var Yi=class{constructor(e=function(){const e="string"==typeof import.meta.url&&import.meta.url?new URL("./forceLayoutWorker.js",import.meta.url):function(e){if("undefined"!=typeof __filename){const t=__filename.replace(/\\/g,"/"),n=t.startsWith("/")?t:"/"+t;return new URL("./"+e,"file:"+n)}throw Error("Cannot resolve module worker asset: "+e)}("forceLayoutWorker.js");return new Worker(e,{type:"module",name:"semiotic-force-layout"})}()){this.session=new Vi({name:"Force layout",createWorker:()=>e,terminateOnAbort:!0,parseMessage:e=>{const t=e,{requestId:n,error:o}=function(e){return e&&"object"==typeof e?{requestId:e.requestId,error:e.error}:{}}(t);return o?{requestId:n,ok:!1,error:Bi(o)}:{requestId:n,ok:!0,payload:{positions:t.positions??{}}}}})}get isDead(){return this.session.isDead}request(e,t){return this.session.request(e,t)}terminate(){this.session.terminate()}},Gi=function(){let e=null;return{get:()=>(e&&!e.isDead||(e=new Yi),e),resetForTest:()=>{if(e){try{e.terminate()}catch{}e=null}}}}();async function Xi(e,t,n={}){const{execution:o="auto",signal:r,workerThreshold:i,nodeRadius:a,...s}=n,c=s.iterations??260,l=Hi()&&function(e,t,n,o,r=4e4){return"sync"!==e&&("worker"===e||o*(t+n)>=r)}(o,e.length,t.length,c,i);if(!l)return _(e,t,{...s,nodeRadius:a});const u={kind:"normalized",nodes:e.map(e=>({...e})),edges:t.map(e=>({...e})),options:s,nodeRadii:"function"==typeof a?Object.fromEntries(e.map(e=>[e.id,a(e)])):null==a?void 0:Object.fromEntries(e.map(e=>[e.id,a]))};try{const e=await function(e,t){return Hi()?Gi.get().request(e,t):Promise.reject(Error("Web Workers are unavailable"))}(u,r);return e.positions}catch(n){if("AbortError"===n?.name)throw n;return _(e,t,{...s,nodeRadius:a})}}function _i(e,t,n){return Math.max(t,Math.min(n,e))}function Ki(e,t,n={}){const o=n.random??Math.random,r=e.stages.find(e=>e.id===t)??e.stages[e.stages.length-1],i=_i(n.along??.5,.05,.95),a=n.jitterX??0,s=n.padY??20,c=r.x0+(r.x1-r.x0)*i+(2*o()-1)*a,l=Math.min(1,r.width/2),u=_i(c,r.x0+l,r.x1-l),d=e.boundaryY(u,"top")+s,h=e.boundaryY(u,"bottom")-s;return{x:u,y:h>d?d+o()*Math.max(1,h-d):e.midY}}function Qi(e){return"bowtie"===e.shape?[{id:"incoming",role:"incoming",points:[[e.left,e.topY],[e.centerLeft,e.pinchTop],[e.centerLeft,e.pinchBottom],[e.left,e.bottomY]]},{id:"center",role:"center",points:[[e.centerLeft,e.pinchTop],[e.centerRight,e.pinchTop],[e.centerRight,e.pinchBottom],[e.centerLeft,e.pinchBottom]]},{id:"outgoing",role:"outgoing",points:[[e.centerRight,e.pinchTop],[e.right,e.topY],[e.right,e.bottomY],[e.centerRight,e.pinchBottom]]}]:[{id:"volume",role:"volume",points:[[e.left,e.topY],[e.right,"funnel"===e.shape?e.pinchTop:e.topY],[e.right,"funnel"===e.shape?e.pinchBottom:e.bottomY],[e.left,e.bottomY]]}]}var Zi=[.1,.5,.9],Ui=1e6;function Ji(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function ea(e,t,n,o,r){return"function"==typeof o?o(e,t,n):function(e,t){let n=e;for(const e of t.split(".")){if(null==n||"object"!=typeof n)return;if(!Object.prototype.hasOwnProperty.call(n,e))return;n=n[e]}return n}(e,o??r)}function ta(e){const t=Number(e.toFixed(12));return Object.is(t,-0)?0:t}function na(e,t,n,o){const r=e.flatMap((e,r)=>{const i=Ji(ea(e,r,t,n,"time")),a=Ji(ea(e,r,t,o,"value"));return null==i||null==a?[]:[{time:ta(i),value:a,index:r}]});r.sort((e,t)=>e.time-t.time||e.index-t.index);const i=[];for(const e of r){const t=i[i.length-1];t?.time===e.time?t.value=e.value:i.push({time:e.time,value:e.value})}return i}function oa(e,t,n,o){if(!e.length)return null;const r=e[0],i=e[e.length-1];if(r.time>t)return"clamp"===o?r.value:null;if(t>i.time)return"clamp"===o?i.value:null;const a=function(e,t){let n=0,o=e.length;for(;o>n;){const r=n+o>>>1;t>e[r].time?n=r+1:o=r}return n}(e,t),s=e[a];if(s?.time===t)return s.value;const c=e[Math.max(0,a-1)];return"step"!==n&&s&&s.time!==c.time?c.value+(t-c.time)/(s.time-c.time)*(s.value-c.value):c.value}function ra(e,t){if(1===e.length)return e[0];const n=(e.length-1)*t,o=Math.floor(n),r=Math.ceil(n);return o===r?e[o]:e[o]+(e[r]-e[o])*(n-o)}function ia(e){const t=e.interpolation??"step",n=e.outsideDomain??"omit",o=function(e){const t=(e??Zi).map(e=>{const t=Ji(e);if(null==t||0>t||t>1)throw new RangeError("physicsReferenceEnvelope quantiles must be finite values from 0 to 1; received "+e);return ta(t)});return Array.from(new Set(t)).sort((e,t)=>e-t)}(e.quantiles),r=function(e){if(Array.isArray(e)){if(e.length>Ui)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(e.map(Ji).filter(e=>null!=e).map(ta))).sort((e,t)=>e-t)}const t=e,n=Ji(t.start),o=Ji(t.end),r=Ji(t.step);if(null==n||null==o||null==r||0>=r||n>o)throw new RangeError("physicsReferenceEnvelope sampleAt requires finite start/end values with end >= start and step > 0");const i=Math.floor((o-n)/r)+1;if(i>Ui)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");const a=[],s=1e-10*Math.max(1,Math.abs(o),Math.abs(n));for(let e=0;i>e;e+=1){const t=n+e*r;if(t>o+s)break;a.push(ta(Math.min(t,o)))}if(a.length&&s>=Math.abs(a[a.length-1]-o)||a.push(ta(o)),a.length>Ui)throw new RangeError("physicsReferenceEnvelope sampleAt exceeds 1000000 points");return Array.from(new Set(a)).sort((e,t)=>e-t)}(e.sampleAt),i=e.runs.map(t=>na(t.samples,t.id,e.timeAccessor,e.valueAccessor));return{points:r.map(e=>{const r=i.map(o=>oa(o,e,t,n)).filter(e=>null!=e).sort((e,t)=>e-t),a={};for(const e of o)a[e]=r.length?ra(r,e):null;return{time:e,count:r.length,min:r.length?r[0]:null,max:r.length?r[r.length-1]:null,median:r.length?ra(r,.5):null,quantiles:a}}),quantiles:o,interpolation:t,outsideDomain:n,runCount:e.runs.length}}function aa(e,t){return e.quantiles.length?"lower"===t?e.quantiles[0]:e.quantiles[e.quantiles.length-1]:"lower"===t?"min":"max"}function sa(e,t){if("min"===t||"median"===t||"max"===t)return e[t];const n=Ji(t);if(null==n||0>n||n>1)throw new RangeError("comparePhysicsTrace quantile selectors must be from 0 to 1; received "+t);const o=ta(n);if(!Object.prototype.hasOwnProperty.call(e.quantiles,o))throw Error(`comparePhysicsTrace could not find quantile ${o} in the reference envelope`);return e.quantiles[o]??null}function ca(e,t,n){return t>e?"below":e>n?"above":"inside"}function la(e,t){const n=Math.max(0,t.time-e.time);if(0>=n||null==e.value||null==e.lower||null==e.upper||null==t.value||null==t.lower||null==t.upper)return{below:0,inside:0,above:0,observed:0};const o=e.value-e.lower,r=t.value-t.lower,i=e.value-e.upper,a=t.value-t.upper,s=[0,1];for(const[e,t]of[[o,r],[i,a]])(0>e&&t>0||e>0&&0>t)&&s.push(-e/(t-e));s.sort((e,t)=>e-t);let c=0,l=0,u=0;for(let o=0;s.length-1>o;o+=1){const r=s[o],i=s[o+1];if(r>=i)continue;const a=(r+i)/2,d=(i-r)*n,h=ca(e.value+(t.value-e.value)*a,e.lower+(t.lower-e.lower)*a,e.upper+(t.upper-e.upper)*a);"below"===h?c+=d:"above"===h?u+=d:l+=d}return{below:c,inside:l,above:u,observed:n}}function ua(e,t,n={}){const o=n.interpolation??t.interpolation,r=n.outsideDomain??t.outsideDomain,i=na(e,n.traceId??"trace",n.timeAccessor,n.valueAccessor),a=n.lower??aa(t,"lower"),s=n.upper??aa(t,"upper"),c=t.points.map(e=>{const t=oa(i,e.time,o,r),n=sa(e,a),c=sa(e,s);if(null!=n&&null!=c&&n>c)throw new RangeError("comparePhysicsTrace lower band exceeds upper band at time "+e.time);return{time:e.time,value:t,lower:n,upper:c,status:null==t||null==n||null==c?"unobserved":ca(t,n,c)}});let l=0,u=0,d=0,h=0,f=null,m=0,p=null;for(const e of c){if("below"===e.status?l+=1:"inside"===e.status?u+=1:"above"===e.status&&(d+=1),null==e.value||null==e.lower||null==e.upper)continue;const t=Math.max(0,e.value-e.upper),n=Math.max(0,e.lower-e.value);t>h&&(h=t,f=e.time),n>m&&(m=n,p=e.time)}let g=0,y=0,x=0,b=0;for(let e=0;c.length-1>e;e+=1){const t=c[e],n=c[e+1],r=Math.max(0,n.time-t.time);if(r>0){if("linear"===o){const e=la(t,n);g+=e.below,y+=e.inside,x+=e.above,b+=e.observed;continue}"unobserved"!==t.status&&(b+=r,"below"===t.status?g+=r:"above"===t.status?x+=r:y+=r)}}const w=c[0]?.time,M=c[c.length-1]?.time,v=null==w||null==M?0:Math.max(0,M-w);return{points:c,sampleCount:c.length,observedSamples:l+u+d,belowSamples:l,insideSamples:u,aboveSamples:d,totalDuration:v,observedDuration:b,unobservedDuration:Math.max(0,v-b),belowDuration:g,insideDuration:y,aboveDuration:x,peakExcess:h,peakExcessAt:f,peakDeficit:m,peakDeficitAt:p}}function da(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function ha(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function fa(e){return!!ha(e)&&"string"==typeof e.id&&"number"==typeof e.furthestStageIndex&&Number.isFinite(e.furthestStageIndex)&&Array.isArray(e.visitedStageIds)&&e.visitedStageIds.every(e=>"string"==typeof e)&&ha(e.visitsByStage)&&ha(e.firstEnteredAt)&&ha(e.lastEnteredAt)&&"number"==typeof e.regressionCount&&Number.isFinite(e.regressionCount)}function ma(e){return{id:e,furthestStageIndex:-1,visitedStageIds:[],visitsByStage:{},firstEnteredAt:{},lastEnteredAt:{},regressionCount:0}}function pa(e){const t=Array.from(new Set(e.bodyIds??[]));return{stages:e.stages.map(e=>({...e})),bodyIds:t,entities:Object.fromEntries(t.map(e=>[e,ma(e)]))}}function ga(e,t,n={}){if("region-enter"!==t.type)return e;const o=function(e,t){const n=t.stageId?.(e);if(n)return n;const o=e.region.metadata;if(o&&"object"==typeof o&&Object.prototype.hasOwnProperty.call(o,"stageId")){const e=o.stageId;if("string"==typeof e)return e}return e.region.id}(t,n),r=e.stages.findIndex(e=>e.id===o);if(0>r)return e;const i=n.entityId?.(t)??t.bodyId;if(!i)return e;const a=da(e.entities,i),s=fa(a)?a:ma(i),c=s.currentStageId?e.stages.findIndex(e=>e.id===s.currentStageId):-1,l=!s.visitedStageIds.includes(o),u=Number(t.observation.timestamp),d=Number.isFinite(u)?u:0,h=da(s.visitsByStage,o),f="number"==typeof h&&Number.isFinite(h)?h:0,m={...s,currentStageId:o,furthestStageId:r>s.furthestStageIndex?o:s.furthestStageId,furthestStageIndex:Math.max(s.furthestStageIndex,r),visitedStageIds:l?[...s.visitedStageIds,o]:s.visitedStageIds,visitsByStage:{...s.visitsByStage,[o]:f+1},firstEnteredAt:l?{...s.firstEnteredAt,[o]:d}:s.firstEnteredAt,lastEnteredAt:{...s.lastEnteredAt,[o]:d},regressionCount:c>=0&&c>r?s.regressionCount+1:s.regressionCount};return{...e,bodyIds:e.bodyIds.includes(i)?e.bodyIds:[...e.bodyIds,i],entities:{...e.entities,[i]:m}}}function ya(e){const t=e.bodyIds.map(t=>{const n=da(e.entities,t);return fa(n)?n:ma(t)}),n=t.length;let o=n;return e.stages.map((e,r)=>{const i=t.filter(e=>e.furthestStageIndex>=r).length,a=t.filter(t=>t.visitedStageIds.includes(e.id)).length,s=t.reduce((t,n)=>{const o=da(n.visitsByStage,e.id);return t+("number"==typeof o&&Number.isFinite(o)?o:0)},0),c={id:e.id,label:e.label??e.id,reached:i,entered:a,total:n,conversion:n>0?i/n:0,fromPrevious:o>0?i/o:0,dropoff:Math.max(0,o-i),visits:s,repeatVisits:Math.max(0,s-a)};return o=i,c})}function xa(e,t){if("function"==typeof t){const n=t(e);return Number.isFinite(n)&&n>0?Number(n):1}const n=e.datum;if(t&&n&&"object"==typeof n){const e=Number(n[t]);if(Number.isFinite(e)&&e>0)return e}const o=Number(n?.work??n?.reviewWork??n?.value);return Number.isFinite(o)&&o>0?o:1}function ba(e,t){if("function"==typeof t){const n=t(e);if(null!=n&&(n+"").length>0)return n+""}else if(t){const n=G(e.datum,t),o=G(e,t),r=n??o;if(null!=r&&(r+"").length>0)return r+""}return e.id}function wa(e,t){if(0===e.length)return 0;if(1===e.length)return e[0];const n=Math.max(0,Math.min(1,t))*(e.length-1),o=Math.floor(n);return e[o]+(e[Math.ceil(n)]-e[o])*(n-o)}function Ma(e){const t=e.regionId,n=Math.max(0,e.unitsPerSecond),o=e.queueLayout??"lane",r=e.queueSlotSpacing??14,i=e.queueStiffness??.35,a=Number.isFinite(e.maxQueue)?Math.max(0,Math.floor(Number(e.maxQueue))):1/0,s=Math.max(.25,e.metricWindowSeconds??30),c=Math.max(1/60,e.snapshotIntervalSeconds??.25),l=e.releaseImpulse??{x:90,y:0},u=new Map,d=new Map,h=new Map,f=new Map,m=new Map,p=new Map,g=new Map,y=[];let x=0,b=new Map,w=new Map,M=0,v=0,k=0,A=null,S=0,I=0,C=0,N=0,z=0,F=0,j=0,W=0,E=0,O=0,R=0,L=0,P=-1,q=!1;function T(e,n){const o=n(e);return!!o&&o.activeRegionIds.includes(t)}function D(){L+=1}function B(e){return{bodyId:e.bodyId,jobId:e.jobId,visitId:e.visitId,visit:e.visit,regionId:t,work:e.total,queuedAt:e.queuedAt}}function V(n,o,r,i){const a={bodyId:n.id,jobId:o.jobId,visitId:o.visitId,visit:o.visit,remaining:o.work,total:o.work,queuedAt:o.queuedAt,sequence:i};return u.set(o.jobId,a),g.delete(n.id),p.set(n.id,o.jobId),I+=1,C+=o.work,D(),function(n,o,r){const i=B(o);e.onQueued?.(n,i),r.controls.recordObservation({type:"physics-capacity-queued",bodyId:n.id,datum:n.datum,x:n.x,y:n.y,regionId:t,work:o.total,jobId:o.jobId,visitId:o.visitId,visit:o.visit,queuedAt:o.queuedAt,queueDepth:u.size})}(n,a,r),a}function H(e){if(u.size>=a||0===d.size)return;const t=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);for(const n of t){if(u.size>=a)break;const t=m.get(n.jobId);t&&h.has(n.jobId)?(d.delete(n.jobId),g.delete(n.bodyId),V(t,n,e,n.sequence)):d.delete(n.jobId)}}function Y(){let e=0;for(const t of u.values())e+=t.remaining;return e}function G(){E=Math.max(E,u.size),O=Math.max(O,Y())}function X(){const e=k-s,t=Math.max(0,Math.min(s,k-(A??k)));let o=0,r=0,i=0,a=0,c=0;for(const t of y){if(e>t.end)continue;o+=t.arrivals,r+=t.arrivalWork,i+=t.completions,a+=t.completedWork;const n=t.end-t.start;c+=n>0&&e>t.start?t.processedWork*Math.min(1,Math.max(0,t.end-e)/n):t.processedWork}const l=t>0?r/t:0;return{seconds:t,arrivals:o,arrivalWork:r,completions:i,completedWork:a,processedWork:c,arrivalsPerSecond:t>0?o/t:0,throughputPerSecond:t>0?i/t:0,utilization:t>0&&n>0?Math.max(0,Math.min(1,c/(n*t))):0,pressure:n>0?l/n:0}}return{id:e.id??"capacity-queue:"+t,continuous:!1!==e.continuous,tick:o=>{const r=o.controls.readBodies(),i=new Map,I=new Map;for(const t of r){if(i.set(t.id,t),!T(t.id,o.getRegionState))continue;if(!$(t,e.bodyFilter))continue;const n=ba(t,e.jobKey),r=I.get(n)??[];r.push(t),I.set(n,r)}const C=Number.isFinite(o.dt)?Math.max(0,o.dt):0;if(!q){const e=Number.isFinite(o.elapsed)?Math.max(0,o.elapsed):C;k=Math.max(0,e-C),q=!0}const E=k,O=E+C;k=O,A=null==A?E:Math.min(A,E);const L={start:E,end:O,arrivals:0,arrivalWork:0,completions:0,completedWork:0,processedWork:0},Y=new Map;for(const[e,t]of I){const n=h.get(e)?.bodyId,o=t.find(e=>e.id===n)??t[0];Y.set(e,o),m.set(e,o)}for(const[n,r]of h){if(Y.has(n))continue;const a=u.get(n),s=i.get(r.bodyId)??m.get(n);if(a){u.delete(n),p.delete(a.bodyId),j+=1,W+=a.remaining,D();const i={...B(a),abandonedAt:k,remainingWork:a.remaining,queueSeconds:Math.max(0,k-a.queuedAt)};s&&e.onAbandoned?.(s,i),o.controls.recordObservation({type:"physics-capacity-abandoned",bodyId:r.bodyId,datum:s?.datum,x:s?.x,y:s?.y,regionId:t,work:a.total,remainingWork:a.remaining,jobId:n,visitId:a.visitId,visit:a.visit,queuedAt:a.queuedAt,abandonedAt:k,queueSeconds:i.queueSeconds,queueDepth:u.size})}d.delete(n),g.delete(r.bodyId),h.delete(n),m.delete(n)}for(const[n,r]of Y){if(h.has(n))continue;const i=(f.get(n)??0)+1;f.set(n,i);const s=xa(r,e.unitAccessor),c={bodyId:r.id,jobId:n,visitId:`${t}:${n}:${i}`,visit:i,regionId:t,work:s,queuedAt:k};h.set(n,c),S+=1,L.arrivals+=1,L.arrivalWork+=s;const l=x++;if(a>u.size)V(r,c,o,l);else{const a={...c,blockedAt:k,sequence:l};d.set(n,a),g.set(r.id,n),F+=1,D(),e.onBlocked?.(r,a),o.controls.recordObservation({type:"physics-capacity-blocked",bodyId:r.id,datum:r.datum,x:r.x,y:r.y,regionId:t,work:s,jobId:n,visitId:c.visitId,visit:i,queuedAt:k,blockedAt:k,queueDepth:u.size,blockedDepth:d.size})}}H(o),G();const X=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);let _=n*C;for(const n of X){if(0>=_)break;const r=Math.min(n.remaining,_);if(n.remaining-=r,_-=r,N+=r,L.processedWork+=r,n.remaining>1e-6)continue;u.delete(n.jobId),p.delete(n.bodyId),v+=1,z+=n.total,L.completions+=1,L.completedWork+=n.total;const a=Math.max(0,k-n.queuedAt);R+=a,D();const s=i.get(n.bodyId);if(!s)continue;o.controls.applyImpulse(n.bodyId,l.x??0,l.y??0);const c={...B(n),completedAt:k,queueSeconds:a};e.onProcessed?.(s,c),o.controls.recordObservation({type:"physics-capacity-processed",bodyId:n.bodyId,datum:s.datum,x:s.x,y:s.y,regionId:t,work:n.total,jobId:n.jobId,visitId:n.visitId,visit:n.visit,queuedAt:n.queuedAt,completedAt:k,queueSeconds:a,queueDepth:u.size})}H(o),G(),function(){const e=Array.from(u.values()).sort((e,t)=>e.sequence-t.sequence);b=new Map(e.map((e,t)=>[e.bodyId,t]));const t=Array.from(d.values()).sort((e,t)=>e.sequence-t.sequence);w=new Map(t.map((e,t)=>[e.bodyId,t])),M=e.length}(),function(e){(e.end>e.start||e.arrivals>0||e.completions>0||e.processedWork>0)&&y.push(e);const t=k-s;for(;y.length>0&&t>y[0].end;)y.shift()}(L);const K=Math.floor(k/c);K!==P&&(P=K,D())},getSnapshot:()=>{const e=Y(),o=function(){let e=0;for(const t of d.values())e+=t.work;return e}(),r=u.size,i=Array.from(u.values()).map(e=>Math.max(0,k-e.queuedAt)).sort((e,t)=>e-t),a=i.reduce((e,t)=>e+t,0);return{regionId:t,queueDepth:r,processedCount:v,unitsPerSecond:n,remainingWork:e,meanRemainingWork:r>0?e/r:0,waitingWork:e+o,blockedDepth:d.size,blockedWork:o,arrivalCount:S,admittedCount:I,admittedWork:C,processedWork:N,completedWork:z,blockedCount:F,abandonedCount:j,abandonedWork:W,peakQueueDepth:E,peakRemainingWork:O,queueAge:{count:i.length,meanSeconds:i.length>0?a/i.length:0,p50Seconds:wa(i,.5),p95Seconds:wa(i,.95),oldestSeconds:i.at(-1)??0},meanCompletedQueueSeconds:v>0?R/v:0,window:X(),simulatedAt:k,metricRevision:L}},bodyForce:e=>{if("none"===o)return null;const n=p.get(e.body.id),a=g.get(e.body.id),s=n?u.get(n):void 0,c=a?d.get(a):void 0;if(!s&&!c)return null;const l=s?b.get(e.body.id):w.get(e.body.id);if(null==l)return null;let h;const f=e.regions;if(f)for(let e=0;f.length>e;e+=1)if(f[e].id===t){const t=f[e].shape;t&&"aabb"===t.type&&(h=t);break}return h?{x:((c?h.x-.44*h.width:h.x-.22*h.width-l*(.15*r))-e.body.x)*i,y:(h.y-(l-((c?d.size:M)-1)/2)*r/Math.max(1,Math.sqrt(c?d.size:M))-e.body.y)*i*.85}:{x:8*-Math.sign(e.body.vx||1),y:0}}}}function va(e,t){return e||t?{x:(e?.x??0)+(t?.x??0),y:(e?.y??0)+(t?.y??0)}:null}function ka(e){if(!e?.length)return null;const t=e.slice(),n=t.some(e=>!1!==e.continuous);return{controllers:t,continuous:n,onTick:(e,n,o)=>{const r={result:e,controls:n,dt:o.dt,elapsed:o.elapsed,getRegionState:o.getRegionState};for(const e of t)e.tick(r)},bodyForce:e=>{let n=null;for(const o of t)o.bodyForce&&(n=va(n,o.bodyForce(e)));return n}}}function $a(e){const t=new Set,n=e.impulse??{x:-60,y:0};return{id:e.id??"portal:"+e.fromRegionId,continuous:!0===e.continuous,tick:o=>{const r=o.controls.readBodies();for(const i of r){const r=o.getRegionState(i.id),a=r?.activeRegionIds.includes(e.fromRegionId);a?t.has(i.id)||(t.add(i.id),o.controls.applyImpulse(i.id,n.x??0,n.y??0),e.onPortal?.(i)):t.delete(i.id)}}}}function Aa(e){const t=e.resources.map(e=>({...e,bodyId:e.bodyId??e.id})),n=new Map(t.map(e=>[e.bodyId,e])),o=new Map,r=new Map,i=e.assignmentForce??.45,a=e.returnForce??.35,s=e.caseAttraction??.08,c=e.assignmentOffset??{x:0,y:0};let l=new Map,u=0,d=0;return{id:e.id??"service-resource-pool",continuous:!0,assign:e=>{const n=o.get(e);if(n)return n;const i=t.find(e=>!r.has(e.id));if(!i)return null;const a={resourceId:i.id,resourceBodyId:i.bodyId,caseBodyId:e,assignedAt:u};return o.set(e,a),r.set(i.id,a),d+=1,a},release:e=>{const t=o.get(e);return!!t&&(o.delete(e),r.delete(t.resourceId),d+=1,!0)},getAssignment:e=>o.get(e),tick:e=>{u=Math.max(u,e.elapsed),l=new Map(e.controls.readBodies().map(e=>[e.id,e]));for(const[e,t]of o)l.has(e)&&l.has(t.resourceBodyId)||(o.delete(e),r.delete(t.resourceId),d+=1)},getSnapshot:()=>({total:t.length,available:t.length-r.size,assigned:r.size,assignments:Array.from(o.values()),simulatedAt:u,metricRevision:d}),bodyForce:e=>{const t=n.get(e.body.id);if(t){const n=r.get(t.id),o=n?l.get(n.caseBodyId):void 0,s=n?i:a;return{x:((o?o.x+(c.x??0):t.home.x)-e.body.x)*s,y:((o?o.y+(c.y??0):t.home.y)-e.body.y)*s}}const u=o.get(e.body.id);if(!u||0>=s)return null;const d=l.get(u.resourceBodyId);return d?{x:(d.x-e.body.x)*s,y:(d.y-e.body.y)*s}:null}}}function Sa(e,t){const n="function"==typeof t.deadlineAccessor?t.deadlineAccessor(e):G(e.datum,t.deadlineAccessor)??G(e,t.deadlineAccessor);return Number.isFinite(Number(n))?Math.max(0,Number(n)):0}function Ia(e){const t=new Map;let n=0,o=0;function r(n){t.set(n.bodyId,n),o+=1,e.onStateChange?.({...n})}function i(e){const o=t.get(e);return!(!o||null!=o.completedAt||(r({...o,completedAt:n,state:"unhappy"===o.state?"resolved-unhappy":"resolved"}),0))}return{id:e.id??"service-level",continuous:!0,protect:e=>{const o=t.get(e);return!(!o||null!=o.completedAt||"unhappy"===o.state||(r({...o,state:"protected",protectedAt:n}),0))},complete:i,getCase:e=>t.get(e),tick:o=>{n=Math.max(n,o.elapsed);for(const a of o.controls.readBodies()){if(!$(a,e.bodyFilter))continue;if(!t.has(a.id)){const t=Sa(a,e);r({bodyId:a.id,openedAt:n,deadlineAt:n+t,state:"waiting"})}const s=t.get(a.id);s&&null==s.completedAt&&(e.completionRegionId&&o.getRegionState(a.id)?.activeRegionIds.includes(e.completionRegionId)?i(a.id):"waiting"!==s.state||s.deadlineAt>n||r({...s,state:"unhappy"}))}},getSnapshot:()=>{const e=Array.from(t.values()),r=t=>e.filter(e=>e.state===t).length;return{total:e.length,waiting:r("waiting"),protected:r("protected"),unhappy:r("unhappy"),resolved:r("resolved"),resolvedUnhappy:r("resolved-unhappy"),simulatedAt:n,metricRevision:o}}}}function Ca(e){const t=new Set;let n=0,o=0,r=0,i=!1;return{id:e.id??"dependency-gate:"+e.regionId,continuous:!0,tick:a=>{n=Math.max(n,a.elapsed);const s=i;var c;c=n,i=e.isOpen?e.isOpen(c):null!=e.opensAt&&c>=e.opensAt;const l=a.controls.readBodies(),u=new Map(l.map(e=>[e.id,e]));for(const n of l){const o=a.getRegionState(n.id)?.activeRegionIds.includes(e.regionId);o&&$(n,e.bodyFilter)&&(i||t.has(n.id)||(t.add(n.id),r+=1,e.onHeld?.(n)))}if(i&&!s){for(const n of t){const t=u.get(n);t&&(a.controls.applyImpulse(n,e.releaseImpulse?.x??86,e.releaseImpulse?.y??0),o+=1,e.onReleased?.(t))}t.clear(),r+=1}for(const e of t)u.has(e)||(t.delete(e),r+=1)},getSnapshot:()=>({regionId:e.regionId,isOpen:i,blocked:t.size,released:o,simulatedAt:n,metricRevision:r}),bodyForce:n=>{if(i||!t.has(n.body.id))return null;const o=n.regions?.find(t=>t.id===e.regionId),r=o?.shape;if(!r||"aabb"!==r.type)return{x:.8*-n.body.vx,y:.8*-n.body.vy};const a=e.holdForce??.4;return{x:(r.x-n.body.x)*a-.45*n.body.vx,y:(r.y-n.body.y)*a-.45*n.body.vy}}}}function Na(e){const[t,n]=e.size,o=e.flow??"down",r=null==(M=e.padding)?{top:24,right:24,bottom:24,left:24}:"number"==typeof M?{top:M,right:M,bottom:M,left:M}:{top:M.top??0,right:M.right??0,bottom:M.bottom??0,left:M.left??0},i=Math.max(.05,Math.min(1,e.channelRatio??1)),a={x:r.left,y:r.top,width:Math.max(1,t-r.left-r.right),height:Math.max(1,n-r.top-r.bottom)},s="down"===o?a.height:a.width,c=s*Math.max(0,e.chargeExtent??.12),l=s*Math.max(0,e.projectionExtent??0),u=s*Math.max(0,e.destinationExtent??.55),d=Math.max(0,s-c-u-l),h=function(e){return"number"==typeof e?Array.from({length:Math.max(1,Math.round(e))},(e,t)=>({id:"bin-"+t,label:t+""})):0===e.length?[{id:"bin-0",label:"0"}]:e.map((e,t)=>({id:e.id,label:e.label??e.id??t+""}))}(e.destinations),f=("down"===o?a.width:a.height)/h.length,m="down"===o?(e,t)=>({x:a.x,y:a.y+e,width:a.width,height:t}):(e,t)=>({x:a.x+e,y:a.y,width:t,height:a.height}),p=m(0,c),g=m(c,d),y=c+d,x=m(y,u),b=m(y+u,l),w=h.map((e,t)=>{const n=t*f,r=f*i,s=(f-r)/2;return"down"===o?{id:e.id,label:e.label,order:t,x:a.x+n+s,y:x.y,width:r,height:x.height,centerX:a.x+(t+.5)*f,centerY:x.y+x.height/2}:{id:e.id,label:e.label,order:t,x:x.x,y:a.y+n+s,width:x.width,height:r,centerX:x.x+x.width/2,centerY:a.y+(t+.5)*f}});var M;return{width:t,height:n,flow:o,charge:p,apparatus:g,destinations:w,projection:b}}function za(e,t){return e.destinations.find(e=>e.id===t)}function Fa(e,t,n){const{charge:o,flow:r}=e,i=Math.max(1,n),a=(t%i+.5)/i;return"down"===r?{x:o.x+o.width*a,y:o.y+o.height/2}:{x:o.x+o.width/2,y:o.y+o.height*a}}function ja(e,t={}){const n=t.thickness??4,o=t.idPrefix??"stage",{destinations:r,flow:i,width:a,height:s}=e,c=[];if(r.length>0){const t=r[0];if("down"===i){const i=t.y+t.height;c.push({id:o+"-floor",shape:{type:"segment",x1:e.charge.x,y1:i,x2:e.charge.x+e.charge.width,y2:i,thickness:n}});for(let e=1;r.length>e;e+=1){const a=r[e].centerX-(r[e].centerX-r[e-1].centerX)/2;c.push({id:`${o}-divider-${e}`,shape:{type:"segment",x1:a,y1:t.y,x2:a,y2:i,thickness:n}})}}else{const i=t.x+t.width;c.push({id:o+"-floor",shape:{type:"segment",x1:i,y1:e.charge.y,x2:i,y2:e.charge.y+e.charge.height,thickness:n}});for(let e=1;r.length>e;e+=1){const a=r[e].centerY-(r[e].centerY-r[e-1].centerY)/2;c.push({id:`${o}-divider-${e}`,shape:{type:"segment",x1:t.x,y1:a,x2:i,y2:a,thickness:n}})}}}return!1!==t.walls&&c.push({id:o+"-wall-left",shape:{type:"segment",x1:1,y1:0,x2:1,y2:s,thickness:n}},{id:o+"-wall-right",shape:{type:"segment",x1:a-1,y1:0,x2:a-1,y2:s,thickness:n}}),c}function Wa(e,t={}){return`${t.charge??"bodies"} enter at the ${"down"===e.flow?"top":"left"}, travel ${"down"===e.flow?"downward":"left to right"} through ${t.apparatus??"the apparatus"}, and come to rest in ${e.destinations.length} ${t.destination??"destinations"}: ${e.destinations.map(e=>e.label).join(", ")}.`}function Ea(e){const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Oa(e,t,n,o){const r="function"==typeof e?e(t,n):e;return Number.isFinite(r)?Number(r):o}function Ra(e,t,n){return Ea(e[t])??n}function La(e,t){return"number"==typeof e?e:e?.[t]??0}function Pa(e){const{band:t,idPrefix:n,plot:o,projection:r}=e,{includeBoundaryWalls:i=!0,includeInteriorWalls:a=!0,wallThickness:s=4}=t,c=function(e){const t=e.bandwidth??e.scale.bandwidth?.()??0,n=new Set;for(const o of e.values){const r=e.scale(o);Number.isFinite(r)&&(n.add(Number(r)),n.add(Number(r)+t))}return Array.from(n).sort((e,t)=>e-t)}(t);if(2>c.length)return[];const l=i?c.length-1:c.length-2,u=[];for(let e=i?0:1;l>=e;e+=1){if(!a&&e>0&&c.length-1>e)continue;const t=c[e];u.push({id:`${n}-wall-${e}`,shape:"x"===r?{type:"aabb",x:t,y:o.y+o.height/2,width:s,height:o.height}:{type:"aabb",x:o.x+o.width/2,y:t,width:o.width,height:s}})}return u}function qa(e){const{plot:t,idPrefix:n="physics-scale",bounds:o={},xBins:r,xBands:i,yBands:a}=e,s=[];if(!1!==o&&s.push(...h(t,{idPrefix:n,...o})),r){const{idPrefix:e,yTop:o,yBottom:i,...a}=r;s.push(...f({...a,idPrefix:e??n+"-xbin",yTop:o??t.y,yBottom:i??t.y+t.height}))}return i&&s.push(...Pa({band:i,idPrefix:i.idPrefix??n+"-xband",plot:t,projection:"x"})),a&&s.push(...Pa({band:a,idPrefix:a.idPrefix??n+"-yband",plot:t,projection:"y"})),s}function Ta(e){const{plot:t,rows:n,columns:o=n+1,pegRadius:r=3,idPrefix:i="galton-peg",yStart:a=t.y+.18*t.height,yEnd:s=t.y+.58*t.height,stagger:c=!0,restitution:l=.2,friction:u=.04}=e,d=Math.max(0,Math.floor(n)),h=Math.max(1,Math.floor(o));if(0===d)return[];const f=d>1?(s-a)/(d-1):0,m=t.width/h,p=[];for(let e=0;d>e;e+=1){const n=c&&e%2==1?m/2:0;for(let o=0;h>o;o+=1){const s=t.x+m*(o+.5)+n;t.x+r>s||s>t.x+t.width-r||p.push({id:`${i}-${e}-${o}`,shape:{type:"aabb",x:s,y:a+e*f,width:2*r,height:2*r},restitution:l,friction:u})}}return p}function Da(e,t={}){const{idPrefix:n="physics-token",radius:o=5,shape:r,mass:i,vx:a,vy:s,spawnAt:c,seed:l=1,jitter:u,datum:d}=t,h=me(l),f=La(u,"x"),m=La(u,"y");return e.map((e,l)=>{const u=Oa(t.x,e,l,Ra(e,"x",0)),p=Oa(t.y,e,l,Ra(e,"y",0)),g=Oa(o,e,l,5),y="function"==typeof r?r(e,l):r??{type:"circle",radius:g};return{id:`${n}-${e.index??l}`,x:u+(h()-.5)*f,y:p+(h()-.5)*m,vx:Oa(a,e,l,0),vy:Oa(s,e,l,0),mass:Oa(i,e,l,1),spawnAt:Oa(c,e,l,void 0),shape:y,datum:d?d(e,l):e.datum??e}}).map(e=>{if(Number.isFinite(e.spawnAt))return e;const{spawnAt:t,...n}=e;return n})}function Ba(e,t={}){const{idPrefix:n="sediment",collider:o=!0,colliderThickness:r=1,restitution:i=.05,friction:a=.2,...s}=t,c=D(e,s),l=o?c.filter(e=>e.height>0).map(e=>({id:`${n}-${e.binId}`,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+r/2,width:e.width,height:r},restitution:i,friction:a})):[];return{columns:c,colliders:l}}function Va(e,t={}){const{timeAccessor:n="arrivalTime",timeScale:o=1,startAt:r=0,rebase:i=!0,sort:a=!0}=t,s=e.map((e,t)=>({spawn:e,time:function(e,t,n){return Ea("function"==typeof n?n(e,t):e[n]??e.datum?.[n])}(e,t,n)??e.spawnAt??t})),c=s.length?Math.min(...s.map(e=>e.time)):0;return{initialSpawns:s.map(({spawn:e,time:t})=>({...e,spawnAt:r+(i?t-c:t)})).sort((e,t)=>a?(e.spawnAt??0)-(t.spawnAt??0):0),initialSpawnPacing:{pacing:"arrival",startAt:r,timeAccessor:"spawnAt",timeScale:o}}}function Ha(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function Ya(e,t,n="group"){const o=ji(e,t),r=e=>"function"==typeof n?n(e):e[n]??0;return e.slice().sort((e,t)=>{const n=r(e),i=r(t);return i>n?-1:n>i?1:(o[t.id]||0)-(o[e.id]||0)}).map(e=>e.id)}function Ga(e,t={}){const n=t.baseline??.62,o=t.inset??.06,r={},i=e.length;return e.forEach((e,t)=>{Ha(r,e,{x:i>1?o+t/(i-1)*(1-2*o):.5,y:n})}),r}function Xa(e,t,n=.55){return`M${e.x},${e.y} Q${(e.x+t.x)/2},${e.y-Math.abs(t.x-e.x)*n} ${t.x},${t.y}`}function _a(e,t={}){const n=t.radius??.42,o=t.center?.x??.5,r=t.center?.y??.5,i=t.startAngle??0,a={},s=e.length;return e.forEach((e,t)=>{const c=i+t/s*Math.PI*2-Math.PI/2;Ha(a,e,{x:o+Math.cos(c)*n,y:r+Math.sin(c)*n})}),a}function Ka(e,t,n={}){const o=(n.order??Ya(e,t,n.groupAccessor??"group")).slice(),r=new Map(o.map((e,t)=>[e,t])),i=new Map;for(const e of t){if(!r.has(e.source)||!r.has(e.target)||e.source===e.target)continue;const t=e.target>e.source?`${e.source}\0${e.target}`:`${e.target}\0${e.source}`;i.set(t,(i.get(t)||0)+(e.value??1))}const a=[];let s=0;for(const[e,t]of i){const[n,o]=e.split("\0"),i=r.get(n),c=r.get(o);t>s&&(s=t),a.push({row:i,col:c,source:n,target:o,value:t}),a.push({row:c,col:i,source:o,target:n,value:t})}return{order:o,cells:a,size:o.length,maxValue:s}}function Qa(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function Za(e){if("string"!=typeof e)return;const t=e.trim();return t.length?t:void 0}function Ua(e,t){const n=Qa(e.note)?e.note:void 0;return t?Za(e.mobileText)||Za(e.shortText)||Za(e.label)||Za(n?.mobileText)||Za(n?.shortText)||Za(n?.label)||Za(n?.title):Za(e.label)||Za(e.mobileText)||Za(e.shortText)||Za(n?.label)||Za(n?.title)}function Ja(e,t,n){const o=function(e,t,n){if(!n)return;const o="function"==typeof n?n(e,t):e[n];return"number"==typeof o&&Number.isFinite(o)?o:void 0}(e,t,n.priorityAccessor);if(void 0!==o)return o;let r=1e3-t;const i=((e.emphasis??"")+"").toLowerCase();"primary"!==i&&"critical"!==i||(r+=1e4),"secondary"===i&&(r-=1e3),"high"===e.priority&&(r+=5e3),"low"===e.priority&&(r-=1500),"number"==typeof e.priority&&(r+=100*e.priority);const a=Qa(e.provenance)?e.provenance:void 0;"number"==typeof a?.confidence&&(r+=100*a.confidence);const s=Qa(e.lifecycle)?e.lifecycle:void 0,c=((s?.freshness??"")+"").toLowerCase();return"expired"!==c&&"stale"!==c||(r-=3e3),r}function es(e,t){if(!t)return e;const n=Ua(e,!0);return n&&"string"==typeof e.label?{...e,label:n}:e}function ts(e,t={}){const n=Array.isArray(e)?e.filter(Qa):[],o=t.active??(null==t.width||(t.breakpoint??480)>=t.width),r=t.strategy??"hybrid",i=!1!==t.preferShortText,a=!1!==t.preservePrimary,s=Math.max(0,t.maxPlotAnnotations??t.maxAnnotations??("callout-list"===r?1:2)),c=Math.max(0,t.minPlotAnnotations??t.minVisible??1);if(!o||"plot"===r)return{active:o,strategy:r,budget:n.length,visible:i?n.map(e=>es(e,i)):n,deferred:[],calloutList:[],hidden:[]};const l=[],u=n.map((e,n)=>({annotation:e,index:n,priority:Ja(e,n,t)})).filter(e=>!!ke(e.annotation)||(l.push(e.annotation),!1)).sort((e,t)=>t.priority-e.priority),d=a?u.filter(e=>"primary"===((e.annotation.emphasis??"")+"").toLowerCase()):[],h=new Set(d.map(e=>e.index)),f=u.filter(e=>!h.has(e.index)),m=[...d,...f].slice(0,Math.max(s,c)),p=new Set(m.map(e=>e.index)),g=u.filter(e=>!p.has(e.index)),y=[...l,...m.sort((e,t)=>e.index-t.index).map(e=>es(e.annotation,i))],x=g.sort((e,t)=>e.index-t.index).map(e=>e.annotation),b=Math.max(0,t.maxCalloutItems??6),w=g.filter(e=>!t.calloutFilter||t.calloutFilter(e.annotation,e.index)).map(e=>function(e,t,n,o){const r=Ua(e,o);if(!r)return null;const i=Za(e.id)||Za(e.key)||Za(e.pointId)||"annotation-"+(t+1),a=Qa(e.provenance)?Za(e.provenance.source)||Za(e.provenance.authorKind):void 0;return{id:i,label:r,shortLabel:Za(e.shortText),pointId:e.pointId,emphasis:"string"==typeof e.emphasis?e.emphasis:void 0,source:a,priority:n,annotation:e}}(e.annotation,e.index,e.priority,i)).filter(e=>!!e).slice(0,b),M=new Set(w.map(e=>e.annotation)),v=x.filter(e=>!M.has(e));return{active:o,strategy:r,budget:s,visible:y,deferred:x,calloutList:w,hidden:v}}function ns(e){return"dense"===e.density?.75:"compact"===e.density?.9:1}function os(e,t){const n=!1!==t.keepAxes,o=!1===t.directLabel?12:28;return"ordinal"===e?{top:12,right:o,bottom:n?44:12,left:n?48:12}:"geo"===e||"network"===e?{top:12,right:12,bottom:12,left:12}:{top:12,right:o,bottom:n?42:14,left:n?44:14}}function rs(e,t,n,o={}){const r={...n},i={mode:!1===t.mode?void 0:"mobile",...r,margin:os(e,t),...o},a=Object.fromEntries(Object.entries(r).filter(([,e])=>void 0!==e)),s=Object.fromEntries(Object.entries(i).filter(([,e])=>void 0!==e)),c=function(e,t){const n=t.targetSize??44,o=[],r=t.standardControls,i=e=>!0===r||"all"===r||r===e||Array.isArray(r)&&r.includes(e);return i("brush")&&o.push("range-inputs","clear-brush"),i("zoom")&&o.push("zoom-buttons","reset-view"),i("legend")&&o.push("legend-chips","show-all-series"),{strategy:`${e}-${t.transformProfile??"overview"}-mobile-recipe`,supportsResponsiveLayout:!0,breakpoints:[320,360,390,430,t.breakpoint??480,768],maxAnnotations:t.maxAnnotations??2,minimumHitTarget:n,summary:t.summary??!0,interaction:{primary:"tap",hoverFallback:"tap-to-lock",targetSize:n,...o.length>0&&{alternatives:o}},labels:{strategy:!1===t.directLabel?"compact":"direct",minFontSize:12}}}(e,t),l=function(e){return{tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:e.targetSize??44,snap:e.snap??"nearestDatum",brushHandleSize:e.targetSize??44,standardControls:e.standardControls??!1}}(t);return{family:e,props:a,responsiveRules:[{id:e+"-mobile",description:`Apply Semiotic's mobile ${e} recipe at phone width.`,when:{maxWidth:t.breakpoint??480},transform:{...s,mobileInteraction:l,mobileSemantics:c}}],mobileInteraction:l,mobileSemantics:c}}function is(e={}){const t=ns(e);return rs("line",e,{showLegend:e.showLegend??!1,directLabel:e.directLabel??!0,lineWidth:"inspect"===e.transformProfile?3:Math.max(1.5,2.5*t),showPoints:"inspect"===e.transformProfile,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function as(e={}){const t=ns(e);return rs("area",e,{showLegend:e.showLegend??!1,showPoints:!1,areaOpacity:"compare"===e.transformProfile?.55:.42,lineWidth:Math.max(1.25,2*t),autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??2,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function ss(e={}){return rs("ordinal",e,{showLegend:e.showLegend??!1,showCategoryTicks:e.keepAxes??!0,sort:"compare"===e.transformProfile?"desc":void 0},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function cs(e={}){const t=ns(e);return rs("scatter",e,{showLegend:e.showLegend??!1,pointRadius:Math.max(4,Math.round((e.targetSize??44)/8*t)),hoverRadius:Math.ceil((e.targetSize??44)/2),pointOpacity:"dense"===e.density?.42:.68,autoPlaceAnnotations:{mobile:{strategy:"callout-list",maxAnnotations:e.maxAnnotations??1,maxCalloutItems:e.maxCalloutItems??4,progressiveDisclosure:!0,preferShortText:!0}}},{showAxes:e.keepAxes??!0,axisExtent:"exact"})}function ls(e={}){const t=ns(e);return rs("network",e,{showLegend:e.showLegend??!1,nodeSizeRange:[Math.max(4,Math.round(6*t)),Math.max(12,Math.round((e.targetSize??44)/2*t))],showLabels:"inspect"===e.transformProfile,edgeOpacity:"dense"===e.density?.28:.44})}function us(e={}){return rs("geo",e,{showLegend:e.showLegend??!1})}function ds(e={}){return rs("small-multiple",e,{mobileColumns:e.mobileColumns??1,tabletColumns:e.tabletColumns??2,chartHeight:e.chartHeight??180,sharedExtent:!0})}function hs(e,t={}){switch(e){case"line":return is(t);case"area":return as(t);case"ordinal":return ss(t);case"scatter":return cs(t);case"network":return ls(t);case"geo":return us(t);case"small-multiple":return ds(t)}}function fs(e={}){const t=e.controls??["range-inputs","chip-filter","clear"];return{mobileInteraction:{enabled:!0,targetSize:e.targetSize??44,tapToSelect:!0,tapToLockTooltip:!0,standardControls:"brush"},mobileSemantics:{interaction:{primary:"filter",alternatives:t,summary:e.summary??"Expose brushable ranges through touch-sized controls in addition to drag gestures."}},controls:t}}export{ne as DEFAULT_AREA_PER_ANNOTATION,e as DEFAULT_GLYPH_ANCHOR,t as DEFAULT_GLYPH_VIEWBOX,jr as DEFAULT_HIT_RADIUS,Ze as DEFAULT_ISOMETRIC_SPRITE_SIZES,Do as GRID_FUEL_KEYS,Bo as GRID_FUEL_LABELS,oe as LayoutCache,n as SYMBOL_SEQUENCE,ti as TAU,o as absorbRegion,ir as activeCountOverDomain,ci as addPoints,co as adjacencyFlowLayout,Ka as adjacencyMatrix,mo as aggregateAdjacencyFlow,r as aggregateRegionCounts,Ae as allocateCells,Dn as analyzeNetEnsemble,ri as angleScale,re as annotationBudget,ie as annotationDensity,i as annotationLayout,Ga as arcLayout,Xa as arcPath,Va as arrivalReplay,br as axisFixedForceLayout,xr as axisFixedForcePositions,Ie as balanceSnapshotsToFlows,a as bandLabel,Ri as betweenness,Wi as bfsDistances,To as bobaLayout,s as bodyGroupSpec,c as boundsOf,ur as boxEdgeAnchors,Fi as buildAdjacency,vi as buildTooltipEntries,Io as bulletLayout,l as calendarLayout,u as capacitatedRegion,d as chargeGateRegion,_a as circularLayout,ae as clamp,Li as closeness,Pi as clustering,qa as collidersFromScales,ua as comparePhysicsTrace,ka as composePhysicsControllers,sn as computeTransitDiagramPositions,m as countPairwiseCrossings,Ma as createCapacityQueueController,Ca as createDependencyGateController,$a as createPortalController,pa as createProcessJourneyLedger,Ia as createServiceLevelController,Aa as createServiceResourcePoolController,mr as cubicPath,hr as cubicPoint,fr as cubicTangent,cr as curvedEdgePath,Hr as cyclicRangeContains,Ut as dagreLayout,ji as degree,Go as demandForecastRows,Wa as describePhysicsStageGeography,X as diagnoseTokenEncoding,le as dimFor,Oi as egoNetwork,_r as estimateLabelWidth,Mi as extractTooltipDatum,dr as fanOutBend,Zt as flextreeLayout,p as forceFieldRegion,_ as forceLayout,Xi as forceLayoutAsync,er as formatMw,tr as formatReservePct,ki as formatTooltipValue,Ta as galtonPegs,K as generateTokens,Rr as geoAreaHitTarget,Or as geoHitTarget,Qt as geographicDotGridLayout,At as geographicGridLayout,g as glyphExtent,y as glyphFractionClipRect,x as glyphPlacement,Uo as gridEventAnnotations,vt as gridifyGeographicPoints,ue as groupBy,b as groupCompletionRows,w as hatchFill,Er as hitTargetPoint,Lr as hitTargetRect,M as hullFromBoxes,sr as intervalLanesLayout,dt as isometricLandmarkLayout,We as isotypeBoltGlyph,Ee as isotypeBusGlyph,je as isotypeChipGlyph,ze as isotypeGhost,Ce as isotypeInk,Le as isotypeNetworkGlyphs,Ne as isotypePaper,Re as isotypePersonGlyph,Oe as isotypePersonPath,Fe as isotypeServerGlyph,Xr as layoutChipStrip,Gr as layoutSequence,Q as layoutTokenGrid,yi as legendGroupsFrom,xi as legendSwatches,jn as lineageDagLayout,v as linearAxis,de as makeShade,$o as marimekkoLayout,k as markCallout,he as matchesHighlight,fe as mean,A as membraneRegion,Pn as mermaidDagLayout,ts as mobileAnnotationStrategy,as as mobileAreaChartRecipe,fs as mobileBrushAlternatives,hs as mobileChartFamilyRecipe,us as mobileGeoChartRecipe,is as mobileLineChartRecipe,ls as mobileNetworkChartRecipe,ss as mobileOrdinalChartRecipe,cs as mobileScatterplotRecipe,ds as mobileSmallMultipleRecipe,me as mulberry32,Qn as netEnsembleLayout,qr as networkEdgeHitTarget,Pr as networkHitTarget,pe as nonNegativeFinite,hi as normalizePoint,qi as normalizeScores,Z as normalizeTokenEncoding,cn as octilinearRoute,ln as offsetTransitPath,S as orderByBarycenter,Ya as orderByGroupDegree,I as orderExactSmall,lr as orthogonalEdgePath,C as packBandsBySilhouette,rr as packIntervals,Kr as packSpanLevels,wo as packedClusterMatrix,N as parallelCoordinatesLayout,Jr as partitionSharedEdges,Fa as physicsChargePoint,za as physicsDestination,ia as physicsReferenceEnvelope,ja as physicsStageColliders,Na as physicsStageGeography,z as placeWithMinGap,di as pointMagnitude,ni as polarToXY,F as portalRegion,j as pressureFieldRegion,W as processChrome,ya as processJourneyRows,E as processLaneWalls,O as processStageLayout,R as processStageRegions,Qi as processVolumePolygons,Ti as proximityProblem,ii as radiusScale,ge as readField,pr as rectCollide,L as refineByAdjacentSwaps,P as regionCountsToProjectionRows,Qo as reserveAnnotationBands,Xo as reserveMarginPct,_o as reserveSeries,ai as ringArcPath,q as roundedEnclosure,un as roundedTransitPath,T as routeSurfaceRegion,Dr as runLengthEncode,Tr as runs,Vt as sampleGeographicDotGrid,Qr as scaleArcBand,ui as scalePoint,Ba as sedimentBake,Yr as selectCyclicRange,ut as selectIsometricLandmarks,xe as shade,Vr as shortestArcDelta,Ei as shortestPath,be as signatureKey,Zr as spanArcPath,Ur as spanArcPeakY,Da as spawnFromTokens,Yo as stackFuelSeries,Ki as stageTargetInVolume,li as subtractPoints,U as suggestTokenEncoding,Zo as summarizeOperatingPoint,B as symbolExtent,V as symbolPathString,H as symbolRadius,Ko as thresholdBandsForReserve,Jo as tightestHours,_e as tokenLayer,J as tokenTaskIntentToCapabilityIntents,Mn as transitDiagramLayout,ee as unitize,te as unitizeRange,Me as unwrapDatum,ga as updateProcessJourney,$e as waffleLayout,ve as withAlpha,Nr as wordTrailsLayout,wr as wordTrailsProgressiveReveal,Br as wrapValue,oi as xyToAngle};