semiotic 3.8.9 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (500) hide show
  1. package/README.md +83 -67
  2. package/agent-skill/semiotic-charts/SKILL.md +11 -2
  3. package/ai/behaviorContracts.cjs +33 -3
  4. package/ai/cli.js +53 -2
  5. package/ai/componentMetadata.cjs +15 -0
  6. package/ai/dist/mcp-server.js +1530 -611
  7. package/ai/examples.md +48 -42
  8. package/{CLAUDE.md → ai/reference.md} +43 -22
  9. package/ai/schema.json +10603 -986
  10. package/ai/surface-manifest.json +643 -2
  11. package/ai/system-prompt.md +83 -130
  12. package/dist/c-3BLJEQNG.min.js +1 -0
  13. package/dist/c-3KZD6AXJ.min.js +1 -0
  14. package/dist/c-4TWEX5HG.min.js +1 -0
  15. package/dist/c-52TEGIUJ.min.js +1 -0
  16. package/dist/c-5YCIX3VZ.min.js +1 -0
  17. package/dist/c-6FEKTA3U.min.js +1 -0
  18. package/dist/c-6O5EVOPH.min.js +1 -0
  19. package/dist/c-74HEEZGK.min.js +1 -0
  20. package/dist/c-AKAF6JAD.min.js +1 -0
  21. package/dist/c-BBKITSXB.min.js +1 -0
  22. package/dist/c-BWNB6USU.min.js +1 -0
  23. package/dist/c-C25ENHIK.min.js +1 -0
  24. package/dist/c-CDR5AO3R.min.js +1 -0
  25. package/dist/c-COHXCW3Q.min.js +1 -0
  26. package/dist/{chunk-scatterplotMatrixBrushOverlay-SDIZSN66.module.min.js → c-DADXPJXV.min.js} +0 -1
  27. package/dist/c-E3JFRRMI.min.js +1 -0
  28. package/dist/c-EBFPQHHO.min.js +1 -0
  29. package/dist/c-G36WS6LN.min.js +1 -0
  30. package/dist/c-GIKRQI4X.min.js +1 -0
  31. package/dist/c-GPYOFETM.min.js +1 -0
  32. package/dist/c-IDUHYYSI.min.js +1 -0
  33. package/dist/{chunk-chunk-FQPKOAIH.module.min.js → c-IUHFPMHD.min.js} +0 -1
  34. package/dist/c-J5G56TUH.min.js +1 -0
  35. package/dist/c-JAZ73J32.min.js +1 -0
  36. package/dist/c-KG3NXHAL.min.js +1 -0
  37. package/dist/c-KII3PLZE.min.js +1 -0
  38. package/dist/c-LIXGXMNS.min.js +1 -0
  39. package/dist/c-LVEY6D6B.min.js +1 -0
  40. package/dist/c-M4Y3BHFR.min.js +1 -0
  41. package/dist/c-MAIICR2Z.min.js +1 -0
  42. package/dist/c-MG5DM6VE.min.js +1 -0
  43. package/dist/{chunk-minimapBrushOverlay-JU57U7NM.module.min.js → c-MNF2S4AA.min.js} +0 -1
  44. package/dist/c-MT3WBK7M.min.js +1 -0
  45. package/dist/c-NY3JWV2K.min.js +1 -0
  46. package/dist/c-O6U6K4CW.min.js +1 -0
  47. package/dist/c-OCI56QF2.min.js +1 -0
  48. package/dist/c-OQ7M4AGV.min.js +1 -0
  49. package/dist/c-OXYMVK7Q.min.js +1 -0
  50. package/dist/c-PPWDL5ZI.min.js +1 -0
  51. package/dist/c-QHF5YON3.min.js +1 -0
  52. package/dist/c-RR3GO5SW.min.js +1 -0
  53. package/dist/{chunk-chunk-J5QD4RAM.module.min.js → c-RSVIHIQ4.min.js} +0 -1
  54. package/dist/{chunk-chunk-EMO5NUGE.module.min.js → c-S2BXNNJN.min.js} +0 -1
  55. package/dist/{chunk-chunk-YCQYG6J5.module.min.js → c-SLGMUBUL.min.js} +0 -1
  56. package/dist/c-SUILCHWU.min.js +1 -0
  57. package/dist/c-TZW3JGJ5.min.js +1 -0
  58. package/dist/c-US5ZFT6E.min.js +1 -0
  59. package/dist/{chunk-chunk-RZH7VZYS.module.min.js → c-USFMFKIH.min.js} +0 -1
  60. package/dist/c-UUKVD4WB.min.js +1 -0
  61. package/dist/{chunk-chunk-SV4XAZ3Q.module.min.js → c-VGW3VG3I.min.js} +0 -1
  62. package/dist/c-W3CE4A4S.min.js +1 -0
  63. package/dist/{chunk-chunk-2NVFEB7P.module.min.js → c-WJCD5EUY.min.js} +0 -1
  64. package/dist/{chunk-chunk-2JGJ5GUG.module.min.js → c-X5UBGU2V.min.js} +0 -1
  65. package/dist/c-YDAY2WFR.min.js +1 -0
  66. package/dist/c-ZOWWU34K.min.js +1 -0
  67. package/dist/components/AccessibleNavTree.d.ts +1 -1
  68. package/dist/components/CategoryColors.d.ts +1 -1
  69. package/dist/components/GradientLegend.d.ts +14 -0
  70. package/dist/components/Legend.d.ts +2 -7
  71. package/dist/components/LinkedCharts.d.ts +1 -1
  72. package/dist/components/MobileAnnotationCalloutList.d.ts +1 -1
  73. package/dist/components/ObservationReadout.d.ts +45 -0
  74. package/dist/components/ThemeProvider.d.ts +4 -4
  75. package/dist/components/Tooltip/FlippingTooltip.d.ts +5 -7
  76. package/dist/components/Tooltip/Tooltip.d.ts +30 -5
  77. package/dist/components/Tooltip/tooltipChrome.d.ts +43 -0
  78. package/dist/components/ai/chartCapabilityTypes.d.ts +86 -2
  79. package/dist/components/ai/chartClinic.d.ts +2 -0
  80. package/dist/components/ai/deriveProfileFields.d.ts +40 -0
  81. package/dist/components/ai/evaluateChart.d.ts +85 -0
  82. package/dist/components/ai/fieldPolicy.d.ts +7 -0
  83. package/dist/components/ai/fieldRoles.d.ts +24 -0
  84. package/dist/components/ai/generativeChart.d.ts +18 -2
  85. package/dist/components/ai/inferIntent.d.ts +26 -2
  86. package/dist/components/ai/intents.d.ts +35 -0
  87. package/dist/components/ai/navigationTree.d.ts +2 -2
  88. package/dist/components/ai/observedSceneAudit.d.ts +2 -1
  89. package/dist/components/ai/profileData.d.ts +11 -0
  90. package/dist/components/ai/repairChartConfig.d.ts +2 -3
  91. package/dist/components/ai/semanticEvidence.d.ts +4 -0
  92. package/dist/components/ai/semanticViability.d.ts +11 -0
  93. package/dist/components/ai/semanticViabilityRegistry.d.ts +5 -0
  94. package/dist/components/ai/streamingTypes.d.ts +4 -0
  95. package/dist/components/ai/suggestCharts.d.ts +5 -6
  96. package/dist/components/ai/suggestDashboard.d.ts +2 -3
  97. package/dist/components/ai/suggestStreamCharts.d.ts +1 -1
  98. package/dist/components/ai/suggestStretchCharts.d.ts +2 -3
  99. package/dist/components/ai/suggestionPropContracts.d.ts +20 -0
  100. package/dist/components/ai/variantDiscovery.d.ts +3 -1
  101. package/dist/components/charts/custom/NetworkCustomChart.d.ts +3 -0
  102. package/dist/components/charts/custom/OrdinalCustomChart.d.ts +3 -0
  103. package/dist/components/charts/custom/XYCustomChart.d.ts +1 -1
  104. package/dist/components/charts/geo/ChoroplethMap.d.ts +3 -1
  105. package/dist/components/charts/geo/DistanceCartogram.d.ts +2 -7
  106. package/dist/components/charts/geo/cartogramOverlay.d.ts +28 -0
  107. package/dist/components/charts/index.d.ts +4 -3
  108. package/dist/components/charts/network/ProcessSankey.d.ts +2 -136
  109. package/dist/components/charts/network/ProcessSankeyProps.d.ts +139 -0
  110. package/dist/components/charts/network/Treemap.d.ts +2 -1
  111. package/dist/components/charts/network/processSankey/boundaryHubOrdering.d.ts +23 -0
  112. package/dist/components/charts/network/processSankey/layoutGeometry.d.ts +2 -0
  113. package/dist/components/charts/network/processSankey/ordering.d.ts +3 -41
  114. package/dist/components/charts/network/processSankey/orderingTypes.d.ts +32 -0
  115. package/dist/components/charts/network/processSankey/packing.d.ts +1 -1
  116. package/dist/components/charts/network/processSankey/packingCache.d.ts +1 -1
  117. package/dist/components/charts/network/processSankey/packingOptimization.d.ts +72 -0
  118. package/dist/components/charts/ordinal/BarChart.d.ts +4 -3
  119. package/dist/components/charts/ordinal/FunnelChart.d.ts +2 -0
  120. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -2
  121. package/dist/components/charts/ordinal/StackedBarChart.d.ts +4 -3
  122. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +2 -2
  123. package/dist/components/charts/physics/GaltonBoardChart.d.ts +2 -9
  124. package/dist/components/charts/physics/GauntletChart.d.ts +10 -41
  125. package/dist/components/charts/physics/ProcessFlowChart.d.ts +1 -1
  126. package/dist/components/charts/physics/chainReactionAccessibleTable.d.ts +9 -0
  127. package/dist/components/charts/physics/chainReactionRuntime.d.ts +2 -1
  128. package/dist/components/charts/physics/chainReactionTypes.d.ts +5 -1
  129. package/dist/components/charts/physics/crucibleBodyRenderers.d.ts +2 -2
  130. package/dist/components/charts/physics/crucibleClone.d.ts +6 -0
  131. package/dist/components/charts/physics/crucibleEffects.d.ts +1 -2
  132. package/dist/components/charts/physics/crucibleRecord.d.ts +7 -0
  133. package/dist/components/charts/physics/gauntletChrome.d.ts +4 -4
  134. package/dist/components/charts/physics/gauntletPhysics.d.ts +1 -0
  135. package/dist/components/charts/physics/gauntletPublic.d.ts +4 -0
  136. package/dist/components/charts/physics/packetFlowOverlay.d.ts +7 -0
  137. package/dist/components/charts/physics/physicsChartLayout.d.ts +8 -0
  138. package/dist/components/charts/physics/physicsChartShared.d.ts +3 -1
  139. package/dist/components/charts/physics/physicsChartUtils.d.ts +1 -1
  140. package/dist/components/charts/physics/physicsHocUtils.d.ts +25 -12
  141. package/dist/components/charts/physics/physicsProjectionOverlays.d.ts +24 -0
  142. package/dist/components/charts/physics/processFlowOverlays.d.ts +9 -0
  143. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +15 -12
  144. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +10 -7
  145. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +35 -14
  146. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +21 -14
  147. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +20 -13
  148. package/dist/components/charts/realtime/aggregate.d.ts +4 -1
  149. package/dist/components/charts/realtime/eventTime.d.ts +4 -0
  150. package/dist/components/charts/realtime/realtimeChartRuntime.d.ts +27 -0
  151. package/dist/components/charts/realtime/realtimeChartTypes.d.ts +30 -0
  152. package/dist/components/charts/realtime/useRealtimeCategoryColors.d.ts +30 -0
  153. package/dist/components/charts/shared/FrameTextAnnotationSVG.d.ts +10 -0
  154. package/dist/components/charts/shared/annotationActivation.d.ts +3 -7
  155. package/dist/components/charts/shared/annotationBandFill.d.ts +6 -0
  156. package/dist/components/charts/shared/annotationDispatch.d.ts +31 -0
  157. package/dist/components/charts/shared/annotationIdentity.d.ts +8 -0
  158. package/dist/components/charts/shared/annotationRules.d.ts +1 -15
  159. package/dist/components/charts/shared/boundedCategoryRegistry.d.ts +8 -0
  160. package/dist/components/charts/shared/chainReactionChartSpec.d.ts +3 -0
  161. package/dist/components/charts/shared/chartMode.d.ts +3 -2
  162. package/dist/components/charts/shared/chartSpecCore.d.ts +1 -0
  163. package/dist/components/charts/shared/frameTextAnnotation.d.ts +63 -0
  164. package/dist/components/charts/shared/gradient.d.ts +16 -0
  165. package/dist/components/charts/shared/hatchFill.d.ts +15 -0
  166. package/dist/components/charts/shared/hooks.d.ts +4 -4
  167. package/dist/components/charts/shared/legendUtils.d.ts +1 -0
  168. package/dist/components/charts/shared/streamPropsHelpers.d.ts +2 -1
  169. package/dist/components/charts/shared/styleRules.d.ts +9 -2
  170. package/dist/components/charts/shared/styleRulesWireSchema.d.ts +353 -0
  171. package/dist/components/charts/shared/types.d.ts +18 -9
  172. package/dist/components/charts/shared/useChartLegend.d.ts +43 -9
  173. package/dist/components/charts/shared/useChartSetup.d.ts +3 -1
  174. package/dist/components/charts/shared/useCustomChartSetup.d.ts +5 -2
  175. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +5 -1
  176. package/dist/components/charts/shared/useOrdinalBrush.d.ts +3 -3
  177. package/dist/components/charts/shared/useStreamingLegend.d.ts +6 -1
  178. package/dist/components/charts/value/types.d.ts +1 -1
  179. package/dist/components/charts/xy/BubbleChart.d.ts +1 -1
  180. package/dist/components/charts/xy/BumpChart.capability.d.ts +14 -1
  181. package/dist/components/charts/xy/BumpChart.d.ts +13 -73
  182. package/dist/components/charts/xy/BumpChart.semanticViability.d.ts +5 -0
  183. package/dist/components/charts/xy/CandlestickChart.d.ts +2 -2
  184. package/dist/components/charts/xy/LineChart.d.ts +2 -2
  185. package/dist/components/charts/xy/Scatterplot.d.ts +1 -1
  186. package/dist/components/charts/xy/bumpData.d.ts +44 -0
  187. package/dist/components/charts/xy/bumpIdentity.d.ts +2 -0
  188. package/dist/components/charts/xy/bumpLayout.d.ts +45 -0
  189. package/dist/components/charts/xy/bumpTooltip.d.ts +20 -0
  190. package/dist/components/legendLayout.d.ts +131 -4
  191. package/dist/components/realtime/ReorderBuffer.d.ts +2 -0
  192. package/dist/components/realtime/types.d.ts +10 -1
  193. package/dist/components/recipes/balanceSnapshotsToFlows.d.ts +42 -0
  194. package/dist/components/recipes/directedReachability.d.ts +14 -0
  195. package/dist/components/recipes/gofishDisplayListFixtures.generated.d.ts +6 -6
  196. package/dist/components/recipes/gridObservatory.d.ts +1 -1
  197. package/dist/components/recipes/networkAnalysis.d.ts +1 -18
  198. package/dist/components/recipes/physics.d.ts +7 -4
  199. package/dist/components/recipes/processPhysics.d.ts +0 -1
  200. package/dist/components/recipes/waffle.d.ts +7 -4
  201. package/dist/components/semiotic-ai-core.d.ts +13 -4
  202. package/dist/components/semiotic-ai-observations.d.ts +3 -0
  203. package/dist/components/semiotic-ai.d.ts +16 -9
  204. package/dist/components/semiotic-client-shared.d.ts +10 -0
  205. package/dist/components/semiotic-experimental.d.ts +1 -1
  206. package/dist/components/semiotic-geo.d.ts +4 -1
  207. package/dist/components/semiotic-network.d.ts +7 -4
  208. package/dist/components/semiotic-ordinal.d.ts +4 -1
  209. package/dist/components/semiotic-physics.d.ts +11 -4
  210. package/dist/components/semiotic-realtime-core.d.ts +11 -4
  211. package/dist/components/semiotic-realtime-react.d.ts +4 -3
  212. package/dist/components/semiotic-realtime.d.ts +3 -1
  213. package/dist/components/semiotic-recipes-core.d.ts +7 -5
  214. package/dist/components/semiotic-server-edge.d.ts +3 -2
  215. package/dist/components/semiotic-server.d.ts +3 -2
  216. package/dist/components/semiotic-themes-core.d.ts +5 -48
  217. package/dist/components/semiotic-utils-core.d.ts +10 -5
  218. package/dist/components/semiotic-utils-react.d.ts +2 -0
  219. package/dist/components/semiotic-xy.d.ts +4 -1
  220. package/dist/components/semiotic.d.ts +68 -26
  221. package/dist/components/server/animatedGif.d.ts +1 -1
  222. package/dist/components/server/renderEvidence.d.ts +25 -2
  223. package/dist/components/server/renderToStaticSVG.d.ts +15 -7
  224. package/dist/components/server/serverChartConfigShared.d.ts +8 -1
  225. package/dist/components/server/serverChartConfigs.d.ts +1 -0
  226. package/dist/components/server/serverChartConfigsNetwork.d.ts +3 -3
  227. package/dist/components/server/serverChartConfigsNetworkChord.d.ts +2 -0
  228. package/dist/components/server/serverChartConfigsNetworkForce.d.ts +2 -0
  229. package/dist/components/server/serverChartConfigsNetworkHierarchy.d.ts +3 -0
  230. package/dist/components/server/serverChartConfigsXY.d.ts +3 -3
  231. package/dist/components/server/serverChartConfigsXYBubble.d.ts +5 -0
  232. package/dist/components/server/serverChartConfigsXYBump.d.ts +7 -0
  233. package/dist/components/server/serverChartConfigsXYScatter.d.ts +5 -0
  234. package/dist/components/server/staticAnnotationFallbacks.d.ts +10 -0
  235. package/dist/components/server/staticAnnotations.d.ts +28 -1
  236. package/dist/components/server/staticAxisTickLabel.d.ts +13 -0
  237. package/dist/components/server/staticLegend.d.ts +1 -1
  238. package/dist/components/server/staticLegendMargin.d.ts +41 -0
  239. package/dist/components/server/staticOrdinal.d.ts +8 -2
  240. package/dist/components/server/staticPhysics.d.ts +13 -1
  241. package/dist/components/server/staticPhysicsChrome.d.ts +20 -0
  242. package/dist/components/server/staticRawLegend.d.ts +15 -0
  243. package/dist/components/server/staticSVGChrome.d.ts +16 -55
  244. package/dist/components/server/staticXYAxes.d.ts +27 -0
  245. package/dist/components/server/staticXYAxisTicks.d.ts +39 -0
  246. package/dist/components/server/staticXYGrid.d.ts +11 -0
  247. package/dist/components/server/themeResolver.d.ts +5 -1
  248. package/dist/components/store/ThemeStore.d.ts +2 -98
  249. package/dist/components/store/designTokens.d.ts +1 -1
  250. package/dist/components/store/themeCSSVariables.d.ts +10 -0
  251. package/dist/components/store/themeCore.d.ts +91 -0
  252. package/dist/components/store/themePresets.d.ts +81 -0
  253. package/dist/components/store/themeSerialization.d.ts +2 -1
  254. package/dist/components/stream/AccessibleDataTable.d.ts +12 -14
  255. package/dist/components/stream/AccessibleTablePortalImpl.d.ts +6 -0
  256. package/dist/components/stream/GeoTileRenderer.d.ts +2 -0
  257. package/dist/components/stream/NetworkCanvasHitTester.d.ts +3 -1
  258. package/dist/components/stream/NetworkSSRFrame.d.ts +2 -1
  259. package/dist/components/stream/NetworkSVGOverlay.d.ts +3 -31
  260. package/dist/components/stream/OrdinalCanvasHitTester.d.ts +2 -0
  261. package/dist/components/stream/SVGChartTitle.d.ts +9 -0
  262. package/dist/components/stream/SVGOverlay.d.ts +1 -21
  263. package/dist/components/stream/SVGUnderlay.d.ts +24 -0
  264. package/dist/components/stream/SceneToSVG.d.ts +1 -1
  265. package/dist/components/stream/StreamGeoFrame.d.ts +1 -1
  266. package/dist/components/stream/StreamOrdinalFrame.d.ts +1 -1
  267. package/dist/components/stream/StreamXYFrame.d.ts +1 -1
  268. package/dist/components/stream/accessibleDataRows.d.ts +11 -0
  269. package/dist/components/stream/accessibleDataTableModel.d.ts +40 -0
  270. package/dist/components/stream/accessibleTableTypes.d.ts +11 -0
  271. package/dist/components/stream/axisTickUtils.d.ts +19 -0
  272. package/dist/components/stream/canvasBackground.d.ts +10 -0
  273. package/dist/components/stream/canvasSetup.d.ts +9 -0
  274. package/dist/components/stream/frameCursorInteraction.d.ts +25 -0
  275. package/dist/components/stream/frameDefaultMargins.d.ts +37 -0
  276. package/dist/components/stream/frameGraphics.d.ts +18 -0
  277. package/dist/components/stream/frameGraphicsSubscription.d.ts +26 -0
  278. package/dist/components/stream/frameLegendOptions.d.ts +18 -0
  279. package/dist/components/stream/geoFrameCursorInteraction.d.ts +9 -0
  280. package/dist/components/stream/geoFrameHelpers.d.ts +29 -1
  281. package/dist/components/stream/geoTypes.d.ts +10 -11
  282. package/dist/components/stream/hitTarget.d.ts +61 -2
  283. package/dist/components/stream/moduleWorkerSession.d.ts +6 -0
  284. package/dist/components/stream/networkAnnotationAnchors.d.ts +37 -0
  285. package/dist/components/stream/networkCustomLayout.d.ts +2 -2
  286. package/dist/components/stream/networkFrameCursorInteraction.d.ts +12 -0
  287. package/dist/components/stream/networkFrameInteraction.d.ts +2 -0
  288. package/dist/components/stream/networkFramePaint.d.ts +7 -0
  289. package/dist/components/stream/networkPipelineConfig.d.ts +1 -1
  290. package/dist/components/stream/networkTypes.d.ts +30 -32
  291. package/dist/components/stream/normalizeXYData.d.ts +7 -0
  292. package/dist/components/stream/ordinalFrameCursorInteraction.d.ts +7 -0
  293. package/dist/components/stream/ordinalFrameInteraction.d.ts +29 -0
  294. package/dist/components/stream/ordinalSceneSVG.d.ts +10 -0
  295. package/dist/components/stream/ordinalTypes.d.ts +10 -4
  296. package/dist/components/stream/physics/PhysicsBodySpatialIndex.d.ts +9 -1
  297. package/dist/components/stream/physics/PhysicsCanvasTheme.d.ts +25 -0
  298. package/dist/components/stream/physics/PhysicsControllers.d.ts +0 -3
  299. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +4 -1
  300. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +3 -24
  301. package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +9 -21
  302. package/dist/components/stream/physics/PhysicsSettledSVGElement.d.ts +37 -0
  303. package/dist/components/stream/physics/PhysicsSettledScene.d.ts +7 -3
  304. package/dist/components/stream/physics/StreamPhysicsFrame.d.ts +1 -1
  305. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +23 -4
  306. package/dist/components/stream/physics/physicsAnnotationContext.d.ts +19 -0
  307. package/dist/components/stream/physics/physicsBodyCanvas.d.ts +4 -0
  308. package/dist/components/stream/physics/physicsSettledChrome.d.ts +7 -0
  309. package/dist/components/stream/physics/usePhysicsCanvasPointer.d.ts +32 -0
  310. package/dist/components/stream/physics/usePhysicsSemanticNavigation.d.ts +36 -0
  311. package/dist/components/stream/pipelineConfig.d.ts +6 -17
  312. package/dist/components/stream/pipelineDomainResolution.d.ts +1 -1
  313. package/dist/components/stream/renderBackend.d.ts +2 -0
  314. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +13 -2
  315. package/dist/components/stream/renderers/resolveCSSColor.d.ts +7 -0
  316. package/dist/components/stream/responsiveSize.d.ts +17 -0
  317. package/dist/components/stream/sceneCursor.d.ts +41 -0
  318. package/dist/components/stream/sceneRevisionDiagnostics.d.ts +1 -1
  319. package/dist/components/stream/svgOverlayUtils.d.ts +22 -1
  320. package/dist/components/stream/types.d.ts +25 -12
  321. package/dist/components/stream/useCanvasFrameHost.d.ts +3 -1
  322. package/dist/components/stream/useFrame.d.ts +24 -1
  323. package/dist/components/stream/useResponsiveSize.d.ts +6 -1
  324. package/dist/components/stream/useStalenessCheck.d.ts +1 -1
  325. package/dist/components/stream/xyFrameAxisTypes.d.ts +15 -4
  326. package/dist/components/stream/xyFrameCursorInteraction.d.ts +6 -0
  327. package/dist/components/stream/xySceneBuilders/swarmScene.d.ts +1 -1
  328. package/dist/components/stream/xySceneBuilders/types.d.ts +6 -26
  329. package/dist/components/types/legendTypes.d.ts +6 -0
  330. package/dist/components/types/marginType.d.ts +7 -8
  331. package/dist/controls.min.js +1 -1
  332. package/dist/controls.module.min.js +1 -1
  333. package/dist/forceLayoutWorker.js +1 -1
  334. package/dist/geo.min.js +1 -1
  335. package/dist/geo.module.min.js +1 -1
  336. package/dist/network.min.js +1 -1
  337. package/dist/network.module.min.js +1 -1
  338. package/dist/ordinal.min.js +1 -1
  339. package/dist/ordinal.module.min.js +1 -1
  340. package/dist/physics-matter.module.min.js +1 -1
  341. package/dist/physics-rapier.module.min.js +1 -1
  342. package/dist/physics.min.js +1 -1
  343. package/dist/physics.module.min.js +1 -1
  344. package/dist/physicsWorker.js +1 -1
  345. package/dist/processSankeyLayoutWorker.js +1 -1
  346. package/dist/realtime.min.js +1 -1
  347. package/dist/realtime.module.min.js +1 -1
  348. package/dist/rough.min.js +1 -1
  349. package/dist/rough.module.min.js +1 -1
  350. package/dist/semiotic-ai-core.d.ts +13 -4
  351. package/dist/semiotic-ai-core.min.js +1 -1
  352. package/dist/semiotic-ai-core.module.min.js +1 -1
  353. package/dist/semiotic-ai.d.ts +16 -9
  354. package/dist/semiotic-ai.min.js +1 -1
  355. package/dist/semiotic-ai.module.min.js +1 -1
  356. package/dist/semiotic-client-cjs-shared.min.js +1 -0
  357. package/dist/semiotic-client-glyph.module.min.js +2 -0
  358. package/dist/semiotic-client-responsive.module.min.js +2 -0
  359. package/dist/semiotic-client-shared.module.min.js +2 -0
  360. package/dist/semiotic-custom-layout-selection-cjs-shared.min.js +2 -0
  361. package/dist/semiotic-data.min.js +1 -1
  362. package/dist/semiotic-data.module.min.js +1 -1
  363. package/dist/semiotic-experimental-auxiliary.module.min.js +2 -0
  364. package/dist/semiotic-experimental-node-auxiliary.module.min.js +2 -0
  365. package/dist/semiotic-experimental-node.module.min.js +2 -0
  366. package/dist/semiotic-experimental-react-shared.module.min.js +2 -0
  367. package/dist/semiotic-experimental-vacp.min.js +1 -1
  368. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  369. package/dist/semiotic-experimental.d.ts +1 -1
  370. package/dist/semiotic-experimental.min.js +1 -1
  371. package/dist/semiotic-experimental.module.min.js +1 -1
  372. package/dist/semiotic-geo.d.ts +4 -1
  373. package/dist/semiotic-network.d.ts +7 -4
  374. package/dist/semiotic-ordinal.d.ts +4 -1
  375. package/dist/semiotic-physics.d.ts +11 -4
  376. package/dist/semiotic-realtime-core.d.ts +11 -4
  377. package/dist/semiotic-realtime-core.min.js +2 -1
  378. package/dist/semiotic-realtime-core.module.min.js +2 -1
  379. package/dist/semiotic-realtime-react.d.ts +4 -3
  380. package/dist/semiotic-realtime-react.min.js +1 -1
  381. package/dist/semiotic-realtime-react.module.min.js +1 -1
  382. package/dist/semiotic-realtime.d.ts +3 -1
  383. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -0
  384. package/dist/semiotic-recipes-core.d.ts +7 -5
  385. package/dist/semiotic-recipes-core.min.js +9 -1
  386. package/dist/semiotic-recipes-core.module.min.js +1 -1
  387. package/dist/semiotic-recipes-geo-cjs.min.js +1 -0
  388. package/dist/semiotic-recipes-react.min.js +1 -1
  389. package/dist/semiotic-recipes-react.module.min.js +1 -1
  390. package/dist/semiotic-recipes.min.js +7 -1
  391. package/dist/semiotic-recipes.module.min.js +2 -1
  392. package/dist/semiotic-server-edge-node.module.min.js +1 -0
  393. package/dist/semiotic-server-edge.d.ts +3 -2
  394. package/dist/semiotic-server-edge.min.js +1 -1
  395. package/dist/semiotic-server-edge.module.min.js +1 -1
  396. package/dist/semiotic-server-node.min.js +1 -1
  397. package/dist/semiotic-server-node.module.min.js +1 -1
  398. package/dist/semiotic-server.d.ts +3 -2
  399. package/dist/semiotic-themes-core.d.ts +5 -48
  400. package/dist/semiotic-themes-core.min.js +1 -1
  401. package/dist/semiotic-themes-core.module.min.js +1 -1
  402. package/dist/semiotic-themes-react.min.js +1 -1
  403. package/dist/semiotic-themes-react.module.min.js +1 -1
  404. package/dist/semiotic-themes.min.js +1 -1
  405. package/dist/semiotic-themes.module.min.js +1 -1
  406. package/dist/semiotic-utils-core.d.ts +10 -5
  407. package/dist/semiotic-utils-core.min.js +1 -1
  408. package/dist/semiotic-utils-core.module.min.js +1 -1
  409. package/dist/semiotic-utils-react.d.ts +2 -0
  410. package/dist/semiotic-utils-react.min.js +1 -1
  411. package/dist/semiotic-utils-react.module.min.js +1 -1
  412. package/dist/semiotic-utils.min.js +2 -1
  413. package/dist/semiotic-utils.module.min.js +2 -1
  414. package/dist/semiotic-value.min.js +1 -1
  415. package/dist/semiotic-value.module.min.js +1 -1
  416. package/dist/semiotic-xy.d.ts +4 -1
  417. package/dist/semiotic.d.ts +68 -26
  418. package/dist/semiotic.min.js +1 -1
  419. package/dist/semiotic.module.min.js +1 -1
  420. package/dist/server.min.js +1 -1
  421. package/dist/server.module.min.js +1 -1
  422. package/dist/xy.min.js +1 -1
  423. package/dist/xy.module.min.js +1 -1
  424. package/package.json +53 -19
  425. package/dist/__tests__/scenarios/mcpProtocolTypes.d.ts +0 -20
  426. package/dist/chunk-OrdinalBrushOverlay-PXHQYDB2.module.min.js +0 -2
  427. package/dist/chunk-XYBrushOverlay-ECZJJLAJ.module.min.js +0 -1
  428. package/dist/chunk-XYBrushOverlay-EP2SV3UI.module.min.js +0 -2
  429. package/dist/chunk-chartContainerDataAudit-IQ3NBN3Q.module.min.js +0 -2
  430. package/dist/chunk-chunk-2B3AIKUZ.module.min.js +0 -2
  431. package/dist/chunk-chunk-2CXCXRB4.module.min.js +0 -1
  432. package/dist/chunk-chunk-2X3FJCME.module.min.js +0 -1
  433. package/dist/chunk-chunk-2ZHHWZQM.module.min.js +0 -2
  434. package/dist/chunk-chunk-4ITOQRXM.module.min.js +0 -2
  435. package/dist/chunk-chunk-5UKL5W76.module.min.js +0 -2
  436. package/dist/chunk-chunk-5VVNW5AZ.module.min.js +0 -1
  437. package/dist/chunk-chunk-5ZON5NMV.module.min.js +0 -2
  438. package/dist/chunk-chunk-66PCWJUG.module.min.js +0 -1
  439. package/dist/chunk-chunk-6S3YGYW7.module.min.js +0 -1
  440. package/dist/chunk-chunk-6V5VQVCT.module.min.js +0 -2
  441. package/dist/chunk-chunk-7C5EDZ3Z.module.min.js +0 -2
  442. package/dist/chunk-chunk-A3I4HBD5.module.min.js +0 -1
  443. package/dist/chunk-chunk-ACLDBMRH.module.min.js +0 -2
  444. package/dist/chunk-chunk-AFQHURLO.module.min.js +0 -2
  445. package/dist/chunk-chunk-DDB4TLQG.module.min.js +0 -2
  446. package/dist/chunk-chunk-DTH3SUOU.module.min.js +0 -2
  447. package/dist/chunk-chunk-DTSNLGRK.module.min.js +0 -2
  448. package/dist/chunk-chunk-DVCWU7MT.module.min.js +0 -2
  449. package/dist/chunk-chunk-FEPXDKJP.module.min.js +0 -1
  450. package/dist/chunk-chunk-FJ76HWQZ.module.min.js +0 -1
  451. package/dist/chunk-chunk-FSIHAW6L.module.min.js +0 -2
  452. package/dist/chunk-chunk-G2RGVEYY.module.min.js +0 -2
  453. package/dist/chunk-chunk-G75OPF5N.module.min.js +0 -2
  454. package/dist/chunk-chunk-HADHLMY5.module.min.js +0 -1
  455. package/dist/chunk-chunk-HAJVODLO.module.min.js +0 -2
  456. package/dist/chunk-chunk-HBFA4NN6.module.min.js +0 -1
  457. package/dist/chunk-chunk-HIV7AW2V.module.min.js +0 -2
  458. package/dist/chunk-chunk-IY7RYD4S.module.min.js +0 -1
  459. package/dist/chunk-chunk-J3QOW4OE.module.min.js +0 -0
  460. package/dist/chunk-chunk-J3XWETBJ.module.min.js +0 -2
  461. package/dist/chunk-chunk-JZAMMSQQ.module.min.js +0 -2
  462. package/dist/chunk-chunk-KTWEBFMX.module.min.js +0 -2
  463. package/dist/chunk-chunk-LSJUXBMF.module.min.js +0 -1
  464. package/dist/chunk-chunk-MXMRXSCI.module.min.js +0 -2
  465. package/dist/chunk-chunk-MXVBXFKW.module.min.js +0 -2
  466. package/dist/chunk-chunk-NWIGA3UK.module.min.js +0 -1
  467. package/dist/chunk-chunk-OFAP623Y.module.min.js +0 -2
  468. package/dist/chunk-chunk-OHLRAEQZ.module.min.js +0 -2
  469. package/dist/chunk-chunk-OZK46A5U.module.min.js +0 -1
  470. package/dist/chunk-chunk-PMR47KRY.module.min.js +0 -2
  471. package/dist/chunk-chunk-PRNXOCYZ.module.min.js +0 -2
  472. package/dist/chunk-chunk-Q2YADC2V.module.min.js +0 -2
  473. package/dist/chunk-chunk-RLKZVJMQ.module.min.js +0 -2
  474. package/dist/chunk-chunk-ROP4HI7H.module.min.js +0 -2
  475. package/dist/chunk-chunk-SK2TQMG4.module.min.js +0 -2
  476. package/dist/chunk-chunk-SKLYXNYW.module.min.js +0 -2
  477. package/dist/chunk-chunk-TCMHJWFJ.module.min.js +0 -1
  478. package/dist/chunk-chunk-TSCFL235.module.min.js +0 -1
  479. package/dist/chunk-chunk-U4NZCU5T.module.min.js +0 -2
  480. package/dist/chunk-chunk-U66USBWU.module.min.js +0 -1
  481. package/dist/chunk-chunk-UOQRPGPK.module.min.js +0 -2
  482. package/dist/chunk-chunk-VKL6DI43.module.min.js +0 -2
  483. package/dist/chunk-chunk-W62673ZE.module.min.js +0 -1
  484. package/dist/chunk-chunk-WFHZHWT7.module.min.js +0 -1
  485. package/dist/chunk-chunk-XCC25CZZ.module.min.js +0 -2
  486. package/dist/chunk-chunk-XECNOUZY.module.min.js +0 -2
  487. package/dist/chunk-chunk-XYZDTYAF.module.min.js +0 -2
  488. package/dist/chunk-chunk-YHNZCPOZ.module.min.js +0 -2
  489. package/dist/chunk-chunk-YWZB3KPI.module.min.js +0 -2
  490. package/dist/chunk-statisticalOverlays-HMYYSGPE.module.min.js +0 -2
  491. package/dist/components/stream/test-utils/frameScheduler.d.ts +0 -12
  492. package/dist/components/stream/test-utils/revisionConsumption.d.ts +0 -13
  493. package/dist/test-utils/canvasMock.d.ts +0 -86
  494. package/dist/test-utils/capturedFrameProps.d.ts +0 -67
  495. package/dist/test-utils/frameMock.d.ts +0 -81
  496. package/dist/test-utils/ordinalFixtures.d.ts +0 -48
  497. /package/dist/{chunk-chunk-JJ2OOIET.module.min.js → c-GGISSW5E.min.js} +0 -0
  498. /package/dist/{chunk-chunk-SIRIJ3DY.module.min.js → c-N4G2L7ID.min.js} +0 -0
  499. /package/dist/{chunk-chunk-CA3YDW6F.module.min.js → c-S6U5CGT5.min.js} +0 -0
  500. /package/dist/components/recipes/{mobileAnnotationStrategy.d.ts → mobileAnnotationBehavior.d.ts} +0 -0
@@ -1 +1 @@
1
- import{composeStyleRules as e,computeArcBoundingBox as t,darkenColor as o,lightenColor as n,makeNodeRuleContext as i,makeRuleValueResolver as r,makeXYRuleContext as s,resolveStyleRules as a,styleRulesToNodeStyle as l,styleRulesToXYStyle as c,sweepToAngles as u}from"./chunk-chunk-HBFA4NN6.module.min.js";import{PhysicsPipelineStore as d,absorbRegion as h,bodyGroupSpec as p,capacitatedRegion as g,collidersFromPlotBounds as m,collidersFromXScaleBins as f,countPairwiseCrossings as y,forceFieldRegion as b,groupCompletionRows as x,orderByBarycenter as v,orderExactSmall as w,packBandsBySilhouette as A,placeWithMinGap as S,portalRegion as k,pressureFieldRegion as M,processStageLayout as _,refineByAdjacentSwaps as P,routeSurfaceRegion as T}from"./chunk-chunk-FEPXDKJP.module.min.js";import"./chunk-chunk-SIRIJ3DY.module.min.js";import{AnnotationLabel as L,DEFAULT_COLOR as R,DEFAULT_LEGEND_ROW_HEIGHT as I,DEPTH_PALETTE_COLORS as C,PipelineStore as z,STREAMING_PALETTE as F,SafeRender as O,SemioticAnnotation as B,StreamXYFrame_default as N,TITLE_BASELINE as E,attachUpdateResultStore as j,buildBaseMetadataProps as $,buildCustomBehaviorProps as D,buildDatumIndexMap as W,buildRectNode as Y,buildResolveColor as V,buildRibbonGeometry as H,compactTimestampBufferForRemoval as G,composeLegendConfigs as X,computeDecayOpacity as q,computeEasing as U,computePulseIntensity as Q,computeRawProgress as Z,confidenceZScore as K,createColorScale as J,createCustomLayoutFailureDiagnostic as ee,createTimestampBufferForData as te,distinctCategories as oe,ensureRingBufferCapacity as ne,filterSparseArray as ie,fitLinearForForecast as re,forecastIntervalStats as se,geoSceneNodeToSVG as ae,getColor as le,getCrosshairProps as ce,getLayoutPlugin as ue,getSize as de,hasActivePulses as he,hasTextTitle as pe,isChartMode as ge,isGradientLegendConfig as me,isLegendConfig as fe,layoutVerticalLegendGroups as ye,lerp as be,networkLabelToSVG as xe,networkSceneEdgeToSVG as ve,networkSceneNodeToSVG as we,normalizeColorGradient as Ae,normalizeGradient as Se,normalizeSemanticGradient as ke,now as Me,ordinalSceneNodeToSVG as _e,pushWithTimestamp as Pe,renderAnnotationPass as Te,renderEmptyState as Le,renderLoadingState as Re,renderSceneListWithBackend as Ie,renderSceneWithBackend as Ce,reserveTitleMargin as ze,resolveAxisChromeGutter as Fe,resolveCategoricalPalette as Oe,resolveChartMode as Be,resolveCustomLayoutPalette as Ne,resolveDefaultFill as Ee,resolveDownwardHistogramExtent as je,resolveExplicitColor as $e,resolveGridDash as De,resolveLegendDistance as We,resolveLegendMetrics as Ye,resolveLegendSideGutter as Ve,resolveMobileInteraction as He,resolveSideLegendMargin as Ge,resolveSideLegendWidth as Xe,reverseGradient as qe,setPulseState as Ue,snapOrdinalIntroTargets as Qe,ticksForMode as Ze,toIdSet as Ke,useCategoryColors as Je,useChartLegendAndMargin as et,useChartMode as tt,useChartSelection as ot,useColorScale as nt,useLegendInteraction as it,useThemeCategorical as rt,warnCustomLayoutDiagnostics as st,xySceneNodeToSVG as at}from"./chunk-chunk-A3I4HBD5.module.min.js";import{useTheme as lt}from"./chunk-chunk-OZK46A5U.module.min.js";import{IncrementalExtent as ct,RingBuffer as ut,defaultTooltipStyle as dt,isHatchFill as ht,normalizeTooltip as pt,resolveSvgFill as gt}from"./chunk-chunk-6S3YGYW7.module.min.js";import{UpdateResultTracker as mt,annotationLayout as ft,getSequentialInterpolator as yt,interpolateBrBG as bt,interpolatePRGn as xt,interpolatePiYG as vt,interpolateRdBu as wt,interpolateRdYlBu as At,interpolateRdYlGn as St,interpolateSpectral as kt,interpolateViridis as Mt,makeSymbolResolver as _t,schemeCategory10 as Pt,useCustomLayoutSelection as Tt}from"./chunk-chunk-LSJUXBMF.module.min.js";import"./chunk-chunk-U66USBWU.module.min.js";import{filterAnnotationsByStatus as Lt}from"./chunk-chunk-5VVNW5AZ.module.min.js";import{accessorsEquivalent as Rt,resolveAccessor as It,resolveStringAccessor as Ct}from"./chunk-chunk-NWIGA3UK.module.min.js";import{getMax as zt,getMin as Ft,getMinMax as Ot}from"./chunk-chunk-JJ2OOIET.module.min.js";import"./chunk-chunk-IY7RYD4S.module.min.js";import"./chunk-chunk-J3QOW4OE.module.min.js";import{DARK_THEME as Bt,HIGH_CONTRAST_THEME as Nt,LIGHT_THEME as Et,THEME_PRESETS as jt,applyThemeAccessibility as $t,resolveThemeSemanticColors as Dt,useThemeSelector as Wt}from"./chunk-chunk-HADHLMY5.module.min.js";function Yt(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};const t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}import*as Vt from"react-dom/server";import*as Ht from"react";function Gt(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}function Xt(e,t){if(!Gt(t))return e??((...e)=>({}));const o={};return void 0!==t.stroke&&(o.stroke=t.stroke),void 0!==t.strokeWidth&&(o.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(o.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...o}):(...e)=>({...o})}function qt(e,t,o){return"function"==typeof e?e(o):o[e||t]}function Ut(e){return e instanceof Date?e.getTime():Number(e)}function Qt(e,t){return Mt(1===t?.5:e/(t-1))}function Zt(e){const t={};return void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.strokeWidth&&(t.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(t.opacity=e.opacity),t}function Kt(e){if(!e)return Et;if("string"==typeof e){if("light"===e)return Et;if("dark"===e)return Bt;if("high-contrast"===e)return Nt;return jt[e]||Et}const t="dark"===e.mode?Bt:Et,o={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return $t(o)}function Jt(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}var eo="__forecastSegment",to="__forecastOpacity";function oo(e,t,o,n){const i=t.uncertaintyOpacity,r=t.confidenceAccessor;if(!i&&!r)return;const s="object"==typeof i?i:{},a=s.min??.15,l=s.max??1;if(r){const t="function"==typeof r?r:e=>e[r];for(const o of e){const e=t(o);null!=e&&Number.isFinite(e)&&(o[to]=a+Math.max(0,Math.min(1,e))*(l-a))}return}const c=e.map(e=>{const t=o(e),i=n(e);return null!=t&&null!=i&&Number.isFinite(t)&&Number.isFinite(i)?Math.abs(t-i):NaN}),u=c.filter(e=>Number.isFinite(e));if(0===u.length)return;const[d,h]=Ot(u),p=h-d;e.forEach((e,t)=>{const o=c[t];Number.isFinite(o)&&(e[to]=l-(p>0?(o-d)/p:0)*(l-a))})}function no(e,t){return"function"==typeof t?t(e):!!e[t]}var io="__semiotic_resolvedX",ro="__semiotic_resolvedY",so="__compoundGroup";function ao(e,t,o){const n=e[t],i=e[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function lo(e){const t=e.xAccessor||"x",i=e.yAccessor||"y",r=e.lineBy,s=e.colorBy||r;let a=Array.isArray(e.data)?ie(e.data).filter(e=>!!e&&"object"==typeof e):[];const l=function(e,t,o){const n="function"==typeof t,i="function"==typeof o,r=n?io:t,s=i?ro:o;return n||i?{xKey:r,yKey:s,rows:e.map(e=>{const r={...e};return n&&(r[io]=t(e)),i&&(r[ro]=o(e)),r})}:{rows:e,xKey:r,yKey:s}}(a,t,i);a=l.rows;const c=l.xKey,u=l.yKey,d=Array.isArray(e.annotations)?[...e.annotations]:[];let h,p="string"==typeof r||"function"==typeof r?r:void 0,g=e.baseLineStyle;if(e.forecast){const t=function(e,t,o,n,i){return(r=n).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(e,t,o,n,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:g}=n,m=e.map(e=>{let t="observed";return s&&no(e,s)?t="forecast":r&&no(e,r)&&(t="training"),{...e,[eo]:t}}),f=n._groupBy,y=[];if(f){const e=new Map;for(const t of m){const o=t[f]??"__default";e.has(o)||e.set(o,[]),e.get(o).push(t)}const t=[];for(const[,o]of e)for(let e=0;o.length-1>e;e++)o[e][eo]!==o[e+1][eo]&&(t.push({...o[e+1],[eo]:o[e][eo]}),t.push({...o[e],[eo]:o[e+1][eo]}));y.push(...m,...t)}else for(let e=0;m.length>e;e++)y.push(m[e]),m.length-1>e&&m[e][eo]!==m[e+1][eo]&&(y.push({...m[e+1],[eo]:m[e][eo]}),y.push({...m[e],[eo]:m[e+1][eo]}));if(n.trainUnderline){const e=[];for(const t of y)"training"===t[eo]&&e.push({...t,[eo]:"training-base"});y.unshift(...e)}const b=[];if(l&&c){const e="string"==typeof l?l:"__envUpper",t="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const o of y)"function"==typeof l&&(o[e]=l(o)),"function"==typeof c&&(o[t]=c(o));b.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:g})}if(n.uncertaintyOpacity||n.confidenceAccessor){const e=l?"function"==typeof l?l:e=>e[l]:()=>{},t=c?"function"==typeof c?c:e=>e[c]:()=>{};oo(y.filter(e=>"forecast"===e[eo]),n,e,t)}if(a){const e=n.anomalyStyle,t={type:"highlight",filter:e=>no(e,a)};e?(t.style=e,t.r=p):"function"==typeof h?(t.style=e=>{const t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=p):(t.color=h,t.r=p,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),b.push(t)}return i&&b.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label}),{processedData:y,annotations:b}}(e,0,0,n,i):function(e,t,o,n,i){const{trainEnd:r,steps:s=10,confidence:a=.95,color:l="#6366f1",bandOpacity:c=.15,label:u}=n;if(null==r)return{processedData:e,annotations:[]};const d=[],h=[];for(const o of e)o[t]>r?h.push({...o,[eo]:"observed"}):d.push({...o,[eo]:"training"});const p=d.map(e=>[e[t],e[o]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]),g=[],m=[];if(p.length>=3){const i=p.length,r=re(p);if(r){const{se:d,meanX:h,ssX:f}=se(p,r),y=K(a),b=e.map(e=>e[t]).filter(e=>null!=e&&isFinite(e)),x=zt(b),v=p.length>1?(p[i-1][0]-p[0][0])/(i-1):1;for(let e=1;s>=e;e++){const n=x+e*v,s=r(n),a=d*Math.sqrt(1+1/i+(f>0?(n-h)**2/f:0))*y;m.push({[t]:n,[o]:s,[eo]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}oo(m,n,e=>e.__forecastUpper,e=>e.__forecastLower),g.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}g.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&g.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const f=[];if(f.push(...d),d.length>0&&h.length>0&&f.push({...d[d.length-1],[eo]:"observed"}),f.push(...h),m.length>0){const e=h.length>0?h[h.length-1]:d[d.length-1];e&&f.push({...e,[eo]:"forecast"}),f.push(...m)}return{processedData:f,annotations:g}}(e,t,o,n,i);var r}(a,c,u,r&&"string"==typeof r&&"object"==typeof e.forecast?{...e.forecast,_groupBy:r}:e.forecast,e.anomaly);if(a=t.processedData,d.push(...t.annotations),h=function(e,t,o){const n=o.upperBounds,i=o.lowerBounds;if(!n&&!i)return;const r="function"==typeof n?n:"string"==typeof n?e=>e[n]:null,s="function"==typeof i?i:"string"==typeof i?e=>e[i]:null;let a=1/0,l=-1/0;for(const o of e){const e=Number(o[t]);if(Number.isFinite(e)&&(a>e&&(a=e),e>l&&(l=e)),r){const e=r(o);null!=e&&Number.isFinite(e)&&(e>l&&(l=e),a>e&&(a=e))}if(s){const e=s(o);null!=e&&Number.isFinite(e)&&(a>e&&(a=e),e>l&&(l=e))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(a,u,e.forecast),r&&"string"==typeof r?(a=a.map(e=>({...e,[so]:`${e[r]}__${e[eo]||"observed"}`})),p=so):p=eo,e.baseLineStyle){const t=function(t,i){const r=i.trainDasharray??"8,4",s=i.forecastDasharray??"4,4",a=i.color||"#6366f1",l=i.trainOpacity,c=i.forecastOpacity,u=i.trainStroke,d=i.trainLinecap,h=i.trainUnderline;return t=>{const i=(t=>e.baseLineStyle(t))(t),p=t[eo];if("training"===p){let e=i.stroke;return"darken"===u?e=o(i.stroke||"#666",.5):u&&(e=u),{...i,stroke:e,strokeDasharray:r,...d&&{strokeLinecap:d},...null!=l&&{strokeOpacity:l}}}if("training-base"===p){let e=i.stroke||"#666";return"lighten"===h&&(e=n(e,.4)),{...i,stroke:e,strokeDasharray:void 0}}if("forecast"===p){const e=t[to],o=null!=e?e:c;return{...i,stroke:a,strokeDasharray:s,...null!=o&&{strokeOpacity:o}}}return i}}(0,e.forecast);g=e=>t(e)}}else e.anomaly&&d.push(...(m=e.anomaly,[{type:"anomaly-band",threshold:m.threshold??2,showBand:!1!==m.showBand,fill:m.bandColor||"#6366f1",fillOpacity:m.bandOpacity??.1,anomalyColor:m.anomalyColor||"#ef4444",anomalyRadius:m.anomalyRadius??6,label:m.label}]));var m;if(e.gapStrategy){if("function"==typeof p){const e=p;a=a.map(t=>({...t,__semiotic_gapGroup:e(t)})),p="__semiotic_gapGroup"}const t=function(e,t,o,n,i){const r=new Map;for(const t of e){const e=i?(t[i]??"")+"":"__single";r.has(e)||r.set(e,[]),r.get(e).push(t)}if("interpolate"===t){const e=[];for(const[,t]of r)for(const i of t)ao(i,o,n)||e.push(i);return{rows:e,groupKey:i}}if("zero"===t){const e=[];for(const[,t]of r)for(const i of t)ao(i,o,n)?e.push({...i,[n]:0}):e.push(i);return{rows:e,groupKey:i}}const s=[],a="_gapSegment";for(const[e,t]of r){let i=0,r=[];const l=()=>{if(0===r.length)return;const t="__single"===e?"__seg"+i:`${e}__seg${i}`;for(const e of r)s.push({...e,[a]:t});r=[],i++};for(const e of t)ao(e,o,n)?l():r.push(e);l()}return{rows:s,groupKey:a}}(a,e.gapStrategy,c,u,"string"==typeof p?p:void 0);a=t.rows,t.groupKey&&(p=t.groupKey)}let f;if(e.directLabel){const t=function(e,t,o,n,i,r,s,a){if(!t||!o)return{annotations:[]};const l="object"==typeof t?t:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof o?o:e=>e[o],h=new Map;for(const t of e){const e=d(t);if(null==e)continue;const o=e+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(t))}const p=new Map;for(const[e,t]of h)t.sort((e,t)=>Number(e[n])-Number(t[n])),p.set(e,"end"===c?t[t.length-1]:t[0]);const g=J(Array.from(p.entries()).map(([e])=>({__lbl:e})),"__lbl",r??s),m=Array.from(p.entries()).map(([e,t])=>({type:"text",label:e,[n]:t[n],[i]:t[i],dx:"end"===c?6:-6,dy:0,color:g?le({__lbl:e},"__lbl",g):a||R,fontSize:u}));m.sort((e,t)=>Number(e[i])-Number(t[i]));for(let e=1;m.length>e;e++){const t=m[e-1],o=m[e],n=Number(t[i])+t.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const f=m.reduce((e,t)=>Math.max(e,(t.label+"").length*(.6*u)),0)+10;return{annotations:m,marginExtra:"end"===c?{right:f}:{left:f}}}(a,e.directLabel,"string"==typeof s||"function"==typeof s?s:void 0,c,u,e.colorScheme,e.themeCategorical,e.color);d.push(...t.annotations),f=t.marginExtra}return{data:a,xAccessor:"function"==typeof t?c:t,yAccessor:"function"==typeof i?u:i,groupAccessor:p,colorAccessor:s,annotations:d,lineStyle:g,yExtent:h,marginExtra:f}}import{forwardRef as co,useCallback as uo,useMemo as ho}from"react";import{forwardRef as po,useMemo as go}from"react";import{useMemo as mo,useRef as fo}from"react";import{useCallback as yo,useMemo as bo,useState as xo}from"react";import{useMemo as vo}from"react";import{useImperativeHandle as wo,useRef as Ao}from"react";function So(e){const t=fo(null);return function(e,t){const{variant:o,frameRef:n,overrides:i}=t,r=Ao(i);r.current=i,wo(e,()=>{const e=function(e,t){if("xy"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.remove(t)??[],update:(t,o)=>e.current?.update(t,o)??[],replace:t=>e.current?.replace?.(t),clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getScales:()=>e.current?.getScales()??null,getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("network"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>{const o=Array.isArray(t)?t:[t],n=e.current?.getTopology()?.nodes??[],i=[];for(const t of o){const o=n.find(e=>e.id===t);o&&i.push({...o.data??{},id:t}),e.current?.removeNode(t)}return i},update:(t,o)=>(Array.isArray(t)?t:[t]).flatMap(t=>{const n=e.current?.updateNode(t,o);return n?[{...n,id:t}]:[]}),clear:()=>e.current?.clear(),getData:()=>e.current?.getTopology()?.nodes?.map(e=>e.data)??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}if("geo-points"===e){const e=t;return{push:t=>e.current?.push(t),pushMany:t=>e.current?.pushMany(t),remove:t=>e.current?.removePoint(t)??[],update:(t,o)=>{const n=e.current?.removePoint(t)??[];for(const t of n)e.current?.push(o(t));return n},clear:()=>e.current?.clear(),getData:()=>e.current?.getData()??[],getCustomLayout:()=>e.current?.getCustomLayout?.()??null,getLayoutFailure:()=>e.current?.getLayoutFailure?.()??null}}const o=t;return{push:e=>o.current?.pushLine(e),pushMany:e=>o.current?.pushManyLines(e),remove:e=>o.current?.removeLine(e)??[],update:(e,t)=>{const n=o.current?.removeLine(e)??[];for(const e of n)o.current?.pushLine(t(e));return n},clear:()=>o.current?.clear(),getData:()=>o.current?.getLines()??[],getCustomLayout:()=>o.current?.getCustomLayout?.()??null,getLayoutFailure:()=>o.current?.getLayoutFailure?.()??null}}(o,n);return new Proxy(e,{get(e,t,o){if("string"==typeof t){const e=r.current?.[t];if("function"==typeof e)return e}return Reflect.get(e,t,o)},has:(e,t)=>!("string"!=typeof t||!r.current||!(t in r.current))||Reflect.has(e,t)})},[])}(e.imperativeRef,{variant:e.imperativeVariant,frameRef:t}),{frameRef:t,resolved:tt(e.mode,{width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,xLabel:e.xLabel,yLabel:e.yLabel,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules}),normalizedMargin:mo(()=>Yt(e.margin),[e.margin])}}import{jsx as ko}from"react/jsx-runtime";var Mo=po(function(e,t){const{data:o,layout:n,layoutConfig:i,onLayoutError:r,xExtent:s,yExtent:a,showAxes:l=!1,margin:c,className:u,annotations:d,onObservation:h,onClick:p,selection:g,linkedHover:m,hoverHighlight:f,chartId:y,loading:b,loadingContent:x,emptyContent:v,colorBy:w,colorScheme:A,legend:S,legendInteraction:k,legendPosition:M,frameProps:_={}}=e,{legend:P,...T}=_,L=go(()=>X(P,S),[P,S]),{frameRef:R,resolved:I,safeData:C,setup:z,earlyReturn:B}=function(e){const t=So(e),{resolved:o,normalizedMargin:n}=t,i=function(e){const{data:t,rawData:o,colorBy:n,colorScheme:i,legendInteraction:r,legendPosition:s,selection:a,linkedHover:l,fallbackFields:c,unwrapData:u=!1,onObservation:d,chartType:h,chartId:p,showLegend:g,legend:m,legendLayout:f,userMargin:y,marginDefaults:b,onClick:x,hoverHighlight:v,mobileInteraction:w,mobileSemantics:A,loading:S,loadingContent:k,emptyContent:M,width:_,height:P,hasTitle:T,axisChrome:L}=e,R=void 0===o,I=bo(()=>ie(t),[t]),[C,z]=xo([]),O=yo(e=>{z(t=>t.length===e.length&&t.every((t,o)=>t===e[o])?t:e)},[]),B="string"==typeof n?n:void 0,N=bo(()=>He(w,{width:_,mobileSemantics:A}),[w,_,A]),{activeSelectionHook:E,hoverSelectionHook:j,customHoverBehavior:$,customClickBehavior:D,crosshairSourceId:W}=ot({selection:a,linkedHover:l,fallbackFields:c,unwrapData:u,onObservation:d,chartType:h,chartId:p,onClick:x,hoverHighlight:v,colorByField:B,mobileInteraction:N}),Y=ce(l,W),V=nt(I,n,i),H=bo(()=>oe(I,n),[I,n]),G=bo(()=>R&&C.length>0?C:H,[R,C,H]),X=it(r,n,G),q=bo(()=>j||(X.legendSelectionHook?X.legendSelectionHook:E),[j,X.legendSelectionHook,E]),U=function(e){const t=Wt(e=>e.theme.colors.selectionOpacity);return vo(()=>{if(void 0!==e||void 0!==t)return{name:e?.name??"",...e,unselectedOpacity:e?.unselectedOpacity??t}},[e,t])}(a),Q=rt(),Z=Je(),K=bo(()=>{if(V)return V;if(!n||0===G.length)return;const e=Array.isArray(i)&&i.length>0||"string"==typeof i&&i.length>0?i:Q&&Q.length>0?Q:F,t="__streamCat",o=G.map(e=>({[t]:e})),r=J(o,t,e);return e=>Z?.[e]||r(e)||"#999"},[V,n,G,i,Q,Z]),{legend:ee,margin:te,legendPosition:ne}=et({data:I,colorBy:n,colorScale:K,showLegend:g,legendPosition:s,userMargin:y,defaults:b,categories:G,additionalLegend:m,chartWidth:_,legendLayout:f,hasTitle:T,axisChrome:L}),re=bo(()=>{const e={};return ee&&(e.legend=ee,e.legendPosition=ne,f&&(e.legendLayout=f)),r&&"none"!==r&&(e.legendHoverBehavior=X.onLegendHover,e.legendClickBehavior=X.onLegendClick,e.legendHighlightedCategory=X.highlightedCategory,e.legendIsolatedCategories=X.isolatedCategories),R&&n&&(e.legendCategoryAccessor=n,e.onCategoriesChange=O),e},[ee,ne,f,r,X.onLegendHover,X.onLegendClick,X.highlightedCategory,X.isolatedCategories,R,n,O]),se=Array.isArray(o)?ie(o):o,ae=Re(S,_,P,k),le=ae?null:Le(se,_,P,M);return{data:I,colorScale:V,allCategories:G,legendState:X,effectiveSelectionHook:q,activeSelectionHook:E,customHoverBehavior:$,customClickBehavior:D,mobileInteraction:N,legend:ee,margin:te,legendPosition:ne,earlyReturn:ae||le||null,legendBehaviorProps:re,crosshairProps:Y,resolvedSelection:U}}({data:e.data??[],rawData:e.data,colorBy:e.colorBy,colorScheme:e.colorScheme,legendInteraction:e.legendInteraction,legendPosition:e.legendPosition,selection:e.selection,linkedHover:e.linkedHover,hoverHighlight:e.hoverHighlight,fallbackFields:"string"==typeof e.colorBy?[e.colorBy]:[],unwrapData:e.unwrapData,onObservation:e.onObservation,onClick:e.onClick,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,chartType:e.chartTypeLabel,chartId:e.chartId,showLegend:o.showLegend,legend:e.legend,userMargin:n,marginDefaults:o.marginDefaults,loading:e.loading,loadingContent:e.loadingContent,emptyContent:e.emptyContent,width:o.width,height:o.height});return{...t,safeData:i.data,setup:i,earlyReturn:i.earlyReturn}}({imperativeRef:t,imperativeVariant:"xy",chartTypeLabel:"XYCustomChart",unwrapData:!1,data:o,colorBy:w,colorScheme:A,legend:L,legendInteraction:k,legendPosition:M,selection:g,linkedHover:m,hoverHighlight:f,onObservation:h,onClick:p,chartId:y,loading:b,loadingContent:x,emptyContent:v,margin:c,width:e.width,height:e.height,showGrid:e.showGrid,enableHover:e.enableHover,showLegend:e.showLegend,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,mode:e.mode,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,responsiveRules:e.responsiveRules,xLabel:e.xLabel,yLabel:e.yLabel}),E=z.effectiveSelectionHook,j=go(()=>E?.isActive?{isActive:!0,predicate:E.predicate}:null,[E?.isActive,E?.predicate]);if(B)return B;const{width:W,height:Y,enableHover:V,showGrid:H,title:G,description:q,summary:U,accessibleTable:Q,xLabel:Z,yLabel:K}=I,ee={chartType:"custom",...null!=o&&{data:C},customLayout:n,layoutConfig:i,onLayoutError:r,...j&&{layoutSelection:j},xExtent:s,yExtent:a,colorAccessor:w,colorScheme:A,size:[W,Y],responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,margin:z.margin,showAxes:l,xLabel:Z,yLabel:K,enableHover:V,showGrid:H,...z.legendBehaviorProps,...$({title:G,description:q,summary:U,accessibleTable:Q,className:u,animate:e.animate,maxDevicePixelRatio:e.maxDevicePixelRatio,axisExtent:e.axisExtent,autoPlaceAnnotations:e.autoPlaceAnnotations}),...null!=e.tooltip&&{tooltipContent:e.tooltip},...D({linkedHover:m,selection:g,onObservation:h,onClick:p,hoverRadius:e.hoverRadius,hoverHighlight:f,mobileInteraction:z.mobileInteraction,customHoverBehavior:z.customHoverBehavior,customClickBehavior:z.customClickBehavior}),...d&&d.length>0&&{annotations:d},...z.crosshairProps,...T};return ko(O,{componentName:"XYCustomChart",width:W,height:Y,children:ko(N,{ref:R,...ee})})});function _o(e,t,o,n,i){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*o+i*i*i*n}function Po(e,t,o,n,i){const r=1-i;return 3*r*r*(t-e)+6*r*i*(o-t)+3*i*i*(n-o)}function To(e,t,o,n,i){const r=[],s=(e.x+t.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===n?(c=e.x+(t.x-e.x)*l,u=e.y+(t.y-e.y)*l,d=t.x-e.x,h=t.y-e.y):(c=_o(e.x,s,s,t.x,l),u=_o(e.y,e.y,t.y,t.y,l),d=Po(e.x,s,s,t.x,l),h=Po(e.y,e.y,t.y,t.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:e.radius+(t.radius-e.radius)*l,datumIndex:.5>l?o:o+1})}return r}function Lo(e,t={}){const o=[],n=[],i=[];if(2>e.length)return{topPath:o,bottomPath:n,datumIndices:i};const r=t.curve??"smooth",s=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;e.length-1>t;t++){const a=To(e[t],e[t+1],t,r,s);for(let e=0===t?0:1;a.length>e;e++){const t=a[e],r=Math.hypot(t.dx,t.dy)||1,s=-t.dy/r,l=t.dx/r,c=Math.max(0,t.radius);o.push([t.x+s*c,t.y+l*c]),n.push([t.x-s*c,t.y-l*c]),i.push(t.datumIndex)}}return{topPath:o,bottomPath:n,datumIndices:i}}Mo.displayName="XYCustomChart";import{jsx as Ro,jsxs as Io}from"react/jsx-runtime";function Co(e,t,o){return"function"==typeof e?e(t,o):t[e]}function zo(e){return e instanceof Date?"date:"+e.getTime():`${typeof e}:${e+""}`}function Fo(e,t){if(!e?.length)return;const o=new Map(t.map((e,t)=>[zo(e),t]));return e.map(e=>{const t={...e},n=n=>{if(!(n in e))return;const i=o.get(zo(e[n]));void 0!==i&&(t[n]=i)};return n("x"),n("x0"),n("x1"),"string"!=typeof e.type||"x-threshold"!==e.type&&"x"!==e.type||n("value"),t})}function Oo(e){const{seriesOrder:t,overallOrder:o,highlightTop:n,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=e;if(null==n&&null==i)return r;const c=new Set(o.slice(0,null==n?o.length:Math.max(0,Math.floor(n)))),u=new Map,d={};for(const e of t)d[e]=i??(c.has(e)?Ee(void 0,a,r,e,u):s??l??"#b8bec8");return d}function Bo(e,t={}){const o=t.xAccessor??"x",n=t.yAccessor??"y",i=t.lineBy??"series",r=t.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;e.forEach((e,t)=>{const r=Co(o,e,t),p=zo(r);let g=a.get(p);null==g&&(g=s.length,a.set(p,g),s.push(r),l.set(g,[]));const m=Co(i,e,t)+"";u.has(m)||(u.set(m,c.length),c.push(m));const f=Number(Co(n,e,t));Number.isFinite(f)&&(d=Math.min(d,f),h=Math.max(h,f),l.get(g)?.push({datum:e,inputIndex:t,series:m,value:f}))});const p=[],g=new Map,m=new Map;for(let e=0;s.length>e;e++){const t=l.get(e)??[];t.sort((e,t)=>("descending"===r?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,o)=>{const n=o+1;p.push({datum:t.datum,xIndex:e,xValue:s[e],series:t.series,value:t.value,rank:n}),g.set(t.series,(g.get(t.series)??0)+n),m.set(t.series,(m.get(t.series)??0)+1)})}const f=c.length+1,y=[...c].sort((e,t)=>{const o=m.get(e)??0,n=m.get(t)??0;return((g.get(e)??0)+(s.length-o)*f)/Math.max(1,s.length)-((g.get(t)??0)+(s.length-n)*f)/Math.max(1,s.length)||(u.get(e)??0)-(u.get(t)??0)}),b=new Set(y.slice(0,null==t.highlightTop?y.length:Math.max(0,Math.floor(t.highlightTop))));return{data:p.map(e=>{const t=b.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:s,seriesOrder:c,overallOrder:y,valueExtent:d===1/0?[0,0]:[d,h]}}function No({datum:e,x:t,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=Tt(),l=a.isActive&&!a.predicate(e),c="function"==typeof s?s(e.__bumpRaw):s;return Ro("text",{className:"semiotic-bump-label",x:t+("end"===n?8:-8),y:o,dy:"0.35em",textAnchor:"end"===n?"start":"end",fill:i,fillOpacity:l?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...c},children:e.__bumpSeries})}function Eo(e,t,o){const[n,i]=t,[r,s]=o;return i===n?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(e-n)/(i-n)))}function jo(e){const t=e instanceof Date?e.getTime():Number(e);return Number.isFinite(t)?t:void 0}function $o(e){return{value:e.__bumpValue,x:jo(e.__bumpXValue),y:e.__bumpValue,category:e.__bumpSeries}}function Do(e){const t=e.config,o=new Map;for(const t of e.data){const e=o.get(t.__bumpSeries)??[];e.push(t),o.set(t.__bumpSeries,e)}const n=t.seriesOrder.filter(e=>o.has(e)).sort((e,n)=>(o.get(e)?.[0]?.__bumpHighlighted?1:0)-(o.get(n)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(n)),i=[],r=[];for(const s of n){const n=(o.get(s)??[]).sort((e,t)=>e.x-t.x);if(2>n.length)continue;const l=n[0].__bumpHighlighted,c=e.resolveColor(n[0].__bumpSeries,n[0]),u=t.color??(l?c:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??c),d=n.map(o=>({x:e.scales.x(o.x),y:e.scales.y(o.y),radius:t.ribbon?Eo(o.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),h=Lo(d,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),p=h.datumIndices.map(e=>n[e]),g={fill:u,fillOpacity:1,opacity:l?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(g,a(n[0].__bumpRaw,t.styleRules,$o(n[0]))),t.areaStyle&&Object.assign(g,t.areaStyle(n[0].__bumpRaw)??{}),void 0!==t.stroke&&(g.stroke=t.stroke),void 0!==t.strokeWidth&&(g.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(g.opacity=t.opacity),i.push({type:"area",topPath:h.topPath,bottomPath:h.bottomPath,style:g,datum:p,accessibleDatum:n.map(e=>e.__bumpRaw),accessibility:{label:s+" ranking trajectory",tableFields:n.map(e=>e.__bumpRaw)},group:s,interactive:!0}),t.showPoints&&n.forEach((e,o)=>{const n={fill:u,stroke:"none",opacity:l?1:.75};t.styleRules?.length&&Object.assign(n,a(e.__bumpRaw,t.styleRules,$o(e))),t.pointStyle&&Object.assign(n,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(n.stroke=t.stroke),void 0!==t.strokeWidth&&(n.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(n.opacity=t.opacity),i.push({type:"point",x:d[o].x,y:d[o].y,r:n.r??t.pointRadius,style:n,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${s}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${s}:${e.x}`})});const m=!0===t.showLabels?"end":t.showLabels,f=(e,o,n)=>{r.push(Ro(No,{datum:e,x:d[o].x,y:d[o].y,side:n,color:"string"==typeof g.fill?g.fill:u,highlighted:l,labelStyle:t.labelStyle},`${s}-${n}`))};"start"!==m&&"both"!==m||f(n[0],0,"start"),"end"!==m&&"both"!==m||f(n.at(-1),n.length-1,"end")}return{nodes:i,overlays:r.length?Ro("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(e,t)=>{const o=function(e){const t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}(e);if(t?.isActive&&o&&!t.predicate(o))return{opacity:.14}}}}function Wo(e,t,o,n,i){const s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],l=Kt(n.theme).colors.categorical,c=o??n.colorScheme??l,u="string"==typeof t?t:"__ssrAreaColorBy",d="function"==typeof t?s.map(e=>({...e,__ssrAreaColorBy:t(e)})):s,h=t?J(d,u,c):void 0,p=!1!==i.showLine,g="number"==typeof i.lineWidth?i.lineWidth:2,m="number"==typeof i.areaOpacity?i.areaOpacity:.7,f=r(i.yAccessor),y=i.styleRules;return(e,o)=>{const n=t&&h?le(e,t,h):"string"==typeof i.color?i.color:R,r={fill:n,fillOpacity:m,stroke:p?n:"none",...p&&{strokeWidth:g}};return y?.length&&Object.assign(r,a(e,y,{value:f(e),category:o})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function Yo(e,t,o,n,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=Kt(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof t?t:"__ssrBubbleColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrBubbleColorBy:t(e)})):r,u=t?J(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],p=d?r.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],g=p.length?Ot(p):void 0;return e=>({fill:t&&u?le(e,t,u):"string"==typeof i.color?i.color:R,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?de(e,d,h,g):h[0],stroke:i.stroke??i.bubbleStrokeColor??"white",strokeWidth:i.strokeWidth??i.bubbleStrokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}})}function Vo(e,t,o,n,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],l=Kt(n.theme).colors.categorical,c=o??n.colorScheme??l,u="string"==typeof t?t:"__ssrScatterColorBy",d="function"==typeof t?r.map(e=>({...e,__ssrScatterColorBy:t(e)})):r,h=t?J(d,u,c):void 0,p=i.sizeBy,g=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],m=p?r.map(e=>"function"==typeof p?p(e):Number(e[p])).filter(Number.isFinite):[],f=m.length?Ot(m):void 0,y=s(i.xAccessor,i.yAccessor),b=i.styleRules;return e=>{const o={fill:t&&h?le(e,t,h):"string"==typeof i.color?i.color:R,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:p?de(e,p,g,f):"number"==typeof i.pointRadius?i.pointRadius:5};return b?.length&&Object.assign(o,a(e,b,y(e))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}co(function(e,t){const o=rt(),n=lt(),{data:i,xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l="descending",ribbon:c=!1,curve:u="smooth",ribbonSizeRange:d=[4,28],samplesPerSegment:h=12,lineWidth:p=3,highlightTop:g,neutralColor:m,styleRules:f,labelStyle:y,colorScheme:b,ribbonOpacity:x=.82,lineOpacity:v=.9,showPoints:w=!1,pointRadius:A=3,showLabels:S=!0,showAxes:k=!0,showGrid:M=!0,showLegend:_=!1,enableHover:P=!0,hoverHighlight:T=!0,tooltip:L,frameProps:R={},xFormat:I,yFormat:C,onClick:z}=e,F=ho(()=>Bo(i,{xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l,highlightTop:g}),[i,r,s,a,l,g]),{axes:O,areaStyle:B,pointStyle:N,...E}=R,j=ho(()=>Oo({seriesOrder:F.seriesOrder,overallOrder:F.overallOrder,highlightTop:g,color:e.color,colorScheme:b,neutralColor:m,themeCategorical:o,themeNeutral:n.colors.textSecondary}),[F.seriesOrder,F.overallOrder,g,e.color,b,m,o,n.colors.textSecondary]),$=ho(()=>({ribbon:c,curve:u,samplesPerSegment:h,ribbonSizeRange:d,valueExtent:F.valueExtent,seriesOrder:F.seriesOrder,lineWidth:p,ribbonOpacity:x,lineOpacity:v,neutralColor:m,color:e.color,stroke:e.stroke,strokeWidth:e.strokeWidth,opacity:e.opacity,styleRules:f,areaStyle:B,pointStyle:N,labelStyle:y,showPoints:w,pointRadius:A,showLabels:S}),[c,u,h,d,F.valueExtent,F.seriesOrder,p,x,v,m,e.color,e.stroke,e.strokeWidth,e.opacity,f,B,N,y,w,A,S]),D=uo((e,t)=>{if(0===F.xValues.length)return"";const o=F.xValues[Math.max(0,Math.min(F.xValues.length-1,Math.round(Number(e))))];return I?I(o,t):(o instanceof Date?o.toLocaleDateString():o)+""},[F.xValues,I]),W=uo(e=>C?C(e):e.toLocaleString(),[C]),Y=ho(()=>"multi"===L?void 0:pt(L),[L]),V=uo(e=>{const t=e?.data??e;return t?!1===L?null:Y?Y({...e,data:t.__bumpRaw,__semioticHoverData:!0}):Io("div",{className:"semiotic-tooltip",style:dt,children:[Ro("div",{style:{fontWeight:700},children:t.__bumpSeries}),Io("div",{children:[D(t.x)," · Rank ",t.__bumpRank]}),Io("div",{children:["Value: ",W(t.__bumpValue)]})]}):null},[W,D,Y,L]),H=ho(()=>{if(z)return(e,t)=>{z(e.__bumpRaw??e,t)}},[z]),G=Math.max(1,F.seriesOrder.length),X=F.xValues.map((e,t)=>t),q=Array.from({length:G},(e,t)=>t+1),U=O??[{orient:"left",tickValues:q,tickFormat:e=>e+"",label:e.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:X,tickFormat:D,label:e.xLabel,tickAnchor:"edges"}],Q=ho(()=>Fo(e.annotations,F.xValues),[e.annotations,F.xValues]);return Ro(Mo,{ref:t,data:F.data,layout:Do,layoutConfig:$,xExtent:[0,Math.max(1,F.xValues.length-1)],yExtent:[G+.5,.5],showAxes:k,showGrid:M,showLegend:_,enableHover:P,hoverHighlight:T,colorBy:"__bumpSeries",colorScheme:j,tooltip:V,onClick:H,hoverRadius:e.hoverRadius,width:e.width,height:e.height,responsiveWidth:e.responsiveWidth,responsiveHeight:e.responsiveHeight,responsiveRules:e.responsiveRules,mobileInteraction:e.mobileInteraction,mobileSemantics:e.mobileSemantics,mode:e.mode,margin:e.margin??{top:20,right:S?110:24,bottom:48,left:48},className:e.className,title:e.title,description:e.description,summary:e.summary,accessibleTable:e.accessibleTable,selection:e.selection,linkedHover:e.linkedHover,legend:e.legend,legendInteraction:e.legendInteraction,legendPosition:e.legendPosition,onObservation:e.onObservation,chartId:e.chartId,loading:e.loading,loadingContent:e.loadingContent,emptyContent:e.emptyContent,animate:e.animate,autoPlaceAnnotations:e.autoPlaceAnnotations,annotations:Q,xLabel:e.xLabel,yLabel:e.yLabel??"Rank",frameProps:{axes:U,axisExtent:"exact",...E}})}).displayName="BumpChart";var Ho={frameType:"xy",buildProps:(e,t,o,n,i)=>({chartType:"scatter",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:o,...n,pointStyle:n.pointStyle||Yo(e,t,o,n,i),showLegend:n.showLegend??!!t})},Go={frameType:"xy",layout:{margin:e=>({top:20,right:!1===e.showLabels?24:110,bottom:48,left:48})},buildProps:(e,t,o,n,i)=>{const r=Bo(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],{xAccessor:i.xAccessor,yAccessor:i.yAccessor,lineBy:i.lineBy,rankDirection:i.rankDirection,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0}),s=Math.max(1,r.seriesOrder.length),a=Kt(n.theme),l=Oo({seriesOrder:r.seriesOrder,overallOrder:r.overallOrder,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0,color:"string"==typeof i.color?i.color:void 0,colorScheme:o,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={ribbon:!0===i.ribbon,curve:"linear"===i.curve?"linear":"smooth",samplesPerSegment:"number"==typeof i.samplesPerSegment?i.samplesPerSegment:12,ribbonSizeRange:Array.isArray(i.ribbonSizeRange)?i.ribbonSizeRange:[4,28],valueExtent:r.valueExtent,seriesOrder:r.seriesOrder,lineWidth:"number"==typeof i.lineWidth?i.lineWidth:3,ribbonOpacity:"number"==typeof i.ribbonOpacity?i.ribbonOpacity:.82,lineOpacity:"number"==typeof i.lineOpacity?i.lineOpacity:.9,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,color:"string"==typeof i.color?i.color:void 0,stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0,styleRules:i.styleRules,areaStyle:n.areaStyle,pointStyle:n.pointStyle,labelStyle:i.labelStyle,showPoints:!0===i.showPoints,pointRadius:"number"==typeof i.pointRadius?i.pointRadius:3,showLabels:i.showLabels??!0},u=n.xFormat,d=(e,t)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(e))))];return u?u(o,t):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((e,t)=>t),p=Array.from({length:s},(e,t)=>t+1),g=n.axes??[{orient:"left",tickValues:p,tickFormat:e=>e+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:Do,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:g,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:Fo(n.annotations,r.xValues)}}};function Xo(e,t,o,n,i){if(!i.showPoints)return;const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=Kt(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof t?t:"__ssrPointColorBy",c="function"==typeof t?r.map(e=>({...e,__ssrPointColorBy:t(e)})):r,u=t?J(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return e=>{const o=t&&u?le(e,t,u):"string"==typeof i.color?i.color:R;return{r:d,fill:o,stroke:"none"}}}var qo={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=t||i.lineBy,l=i.fillArea,c=Array.isArray(l)?"mixed":l?"area":"line",u=Kt(n.theme).colors.categorical,d=function(e,t,o,n,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],l=Kt(n.theme).colors.categorical,c=o??n.colorScheme??l,u="string"==typeof t?t:"__ssrLineColorBy",d="function"==typeof t?r.map(e=>({...e,__ssrLineColorBy:t(e)})):r,h=t?J(d,u,c):void 0,p=s(i.xAccessor,i.yAccessor),g=function(e){const{lineWidth:t=2,colorBy:o,colorScale:n,color:i,resolveStroke:r,fillArea:s,areaOpacity:l=.3,styleRules:c,ruleContext:u}=e;return(e,d)=>{const h={strokeWidth:t},p=!0===s||Array.isArray(s)&&null!=d&&s.includes(d);let g;return r?g=r(e,d):o?n&&(g=le(e,o,n)):g=i||R,void 0!==g&&(h.stroke=g,p&&(h.fill=g,h.fillOpacity=l)),c?.length&&Object.assign(h,a(e,c,u?u(e,d):{value:void 0,category:d})),h}}({lineWidth:"number"==typeof i.lineWidth?i.lineWidth:2,colorBy:t,colorScale:h,color:"string"==typeof i.color?i.color:void 0,fillArea:i.fillArea,areaOpacity:"number"==typeof i.areaOpacity?i.areaOpacity:.3,styleRules:i.styleRules,ruleContext:p});return Xt(g,{stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0})}(e,r,o,n,i),h=lo({data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:n.annotations,themeCategorical:u,baseLineStyle:d}),p=n.pointStyle||Xo(h.data,h.colorAccessor,o,n,i);let g=n.margin;h.marginExtra&&g&&"object"==typeof g?g={...g,...null!=h.marginExtra.right&&{right:Math.max(Number(g.right)||0,h.marginExtra.right)},...null!=h.marginExtra.left&&{left:Math.max(Number(g.left)||0,h.marginExtra.left)}}:h.marginExtra&&null==g&&(g={top:20,right:h.marginExtra.right??20,bottom:30,left:h.marginExtra.left??40});const m=(!i.directLabel||void 0!==n.showLegend)&&(n.showLegend??!!h.colorAccessor);return{chartType:c,data:h.data,xAccessor:h.xAccessor,yAccessor:h.yAccessor,groupAccessor:h.groupAccessor,colorAccessor:h.colorAccessor,colorScheme:o,lineStyle:h.lineStyle||d,...Array.isArray(l)&&{areaGroups:l},...l&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...n,...void 0!==g&&{margin:g},annotations:h.annotations,...h.yExtent&&!n.yExtent&&{yExtent:h.yExtent},...p&&{pointStyle:p},showLegend:m}}},Uo={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=Array.isArray(e)?ie(e):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=i.valueExtent||n.yExtent,u="down"===i.direction?je({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(i.binSize),valueExtent:c,extentPadding:i.extentPadding}):c,d={...void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.gap&&{gap:i.gap}};return{chartType:"bar",data:r,...n,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||n.xExtent,yExtent:u,extentPadding:i.extentPadding??n.extentPadding,binSize:i.binSize,categoryAccessor:l,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,showLegend:n.showLegend??!!l}}},Qo={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=t||i.areaBy,s=function({data:e,safeData:t,areaBy:o,lineDataAccessor:n}){if(null==e)return[];const i=void 0!==t[0]?.[n];if(!i&&!o)return t;let r;if(i)r=t;else{const e=t.reduce((e,t)=>{const i="function"==typeof o?o(t):t[o],r=i+"";if(!e[r]){const t={[n]:[]};"string"==typeof o&&(t[o]=i),e[r]=t}return e[r][n].push(t),e},{});r=Object.values(e)}return r.flatMap(e=>{const t=Array.isArray(e[n])?e[n]:[];return"string"==typeof o?t.map(t=>({...t,[o]:t[o]??e[o]})):t})}({data:e,safeData:Array.isArray(e)?ie(e):[],areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),a=ke(i.semanticGradient),l=a?.stops.length?qe(a):Se(n.gradientFill),c=!1!==i.semanticLine&&a?.stops.length?a.stops.flatMap(({offset:e,color:t})=>t?[{offset:e,color:t}]:[]):void 0,u=n.pointStyle||Xo(s,r,o,n,i);return{chartType:"area",data:s,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",y0Accessor:i.y0Accessor,groupAccessor:i.areaBy||void 0,colorAccessor:r,colorScheme:o,...n,...void 0!==l&&{gradientFill:l},...c&&{semanticLineStops:c},lineStyle:n.lineStyle||Wo(s,r,o,n,i),...u&&{pointStyle:u}}}},Zo={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=e=>Ut(qt(r,"x",e)),c=e=>Ut(qt(s,"a",e)),u=e=>Ut(qt(a,"b",e)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",p=i.areaOpacity??.6,g=i.lineWidth??1.5,m=!1!==i.showLines,f=!1!==n.showLegend,y=i.seriesALabel||"A",b=i.seriesBLabel||"B",x=n.legendPosition||"right",v=function(e,t,o,n){if(!e.length)return[];const i=e.filter(e=>Number.isFinite(t(e))).sort((e,o)=>t(e)-t(o)),r=[];let s=0,a=null,l=null,c=[];const u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${s}-${e}`,h=e=>r.push(e),p=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;i.length>e;e++){const r=i[e],g=t(r),m=o(r),f=n(r);if(!Number.isFinite(g)||!Number.isFinite(m)||!Number.isFinite(f))continue;const y=u(m,f);if(null!==y)if(null!=a){if(l&&l.w!==y){let e,t;if(c.length>0)e=c[0].x,t=c[0].y;else{const o=m-l.a-(f-l.b);if(0!==o){const n=Math.max(0,Math.min(1,(l.b-l.a)/o));e=l.x+n*(g-l.x),t=l.a+n*(m-l.a)}else e=l.x,t=l.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t}),s++,a=y,h({__x:e,__y:t,__y0:t,__diffSegment:d(a),__diffWinner:a,__valA:t,__valB:t});for(let e=1;c.length>e;e++)p(c[e],a)}else for(const e of c)p(e,a);c=[],h({__x:g,__y:f>m?f:m,__y0:f>m?m:f,__diffSegment:d(a),__diffWinner:a,__valA:m,__valB:f,__sourceDatum:r}),l={x:g,a:m,b:f,w:y}}else{a=y;for(const e of c)p(e,a);c=[],h({__x:g,__y:f>m?f:m,__y0:f>m?m:f,__diffSegment:d(a),__diffWinner:a,__valA:m,__valB:f,__sourceDatum:r}),l={x:g,a:m,b:f,w:y}}else c.push({x:g,y:m,datum:r})}for(const e of c)p(e,a??"A");return r}(Array.isArray(e)?e:[],l,c,u),w=[];if(m&&Array.isArray(e)){const t=e.filter(e=>Number.isFinite(l(e))).sort((e,t)=>l(e)-l(t));for(const e of t){const t=l(e),o=c(e),n=u(e);Number.isFinite(o)&&w.push({__x:t,__y:o,__diffSegment:"line-A"}),Number.isFinite(n)&&w.push({__x:t,__y:n,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:e=>{const t=e.__diffSegment;return{fill:"A"==(t?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:p}},lineStyle:e=>({stroke:"A"==("line-A"===e.__diffSegment?"A":"B")?d:h,strokeWidth:g,fill:"none"}),curve:i.curve||"linear",...n,...f&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:y,color:d},{label:b,color:h}]}]},legendPosition:x}}}},Ko={frameType:"xy",buildProps:(e,t,o,n,i)=>{const s=t||i.areaBy,l="string"==typeof s&&Array.isArray(e)?J(e,s,o):void 0,c="number"==typeof i.areaOpacity?i.areaOpacity:.7,u=n.lineStyle||(e=>{const t=null==s?void 0:le(e,s,l),o=i.showLine??!0,n={fill:i.color??t,stroke:o?i.stroke??t:"none",...o?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:c,...null==i.opacity?{}:{opacity:i.opacity}},u=i.styleRules;if(u?.length){const t=r(i.yAccessor),o=s?"function"==typeof s?(s(e)??"")+"":(e[s]??"")+"":void 0;Object.assign(n,a(e,u,{value:t(e),category:o}))}return n}),d=i.normalize?"zero":i.baseline??"zero",h=n.pointStyle||Xo(e,s,o,n,i);return{chartType:"stackedarea",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:s,colorScheme:o,normalize:i.normalize,baseline:d,stackOrder:i.stackOrder,lineStyle:u,...n,...h&&{pointStyle:h},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!s}}},Jo={frameType:"xy",buildProps:(e,t,o,n,i)=>{const[r]=n.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.highAccessor||"high",highAccessor:i.highAccessor||"high",lowAccessor:i.lowAccessor||"low",openAccessor:i.openAccessor,closeAccessor:i.closeAccessor,candlestickStyle:i.candlestickStyle,...n,scalePadding:n.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:n.extentPadding??(r>200?.1:.02)}}},en={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=n.pointStyle||Vo(e,t,o,n,i),s=c(i.styleRules,i.xAccessor||"x",i.yAccessor||"y"),a=s?e=>({..."function"==typeof r?r(e):r,...s(e)}):r;return{chartType:"scatter",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,sizeAccessor:i.sizeBy,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,sizeRange:i.sizeRange||[3,15],pointStyle:a,showLegend:n.showLegend??!!t}}},tn={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,p=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,g=Ht.createElement,m=a?[(e,t,o)=>{if(!t?.x||!t?.y)return null;const n=o.width,i=o.height,l=null!=r?t.x(r):n/2,m=null!=s?t.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(m))return null;const f=Math.max(0,Math.min(n,l)),y=Math.max(0,Math.min(i,m)),b=[{c:a.topLeft,x:0,y:0,w:f,h:y},{c:a.topRight,x:f,y:0,w:n-f,h:y},{c:a.bottomLeft,x:0,y:y,w:f,h:i-y},{c:a.bottomRight,x:f,y:y,w:n-f,h:i-y}],x=c?[g("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),g("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),g("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),g("text",{key:"lbr",x:n-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return g(Ht.Fragment,null,...b.map((e,t)=>e.w>0&&e.h>0?g("rect",{key:"qf-"+t,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),g("line",{key:"vc",x1:f,y1:0,x2:f,y2:i,stroke:d,strokeWidth:h,strokeDasharray:p}),g("line",{key:"hc",x1:0,y1:y,x2:n,y2:y,stroke:d,strokeWidth:h,strokeDasharray:p}),...x)}]:void 0;return{chartType:"scatter",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[3,15],colorScheme:o,pointStyle:n.pointStyle||i.pointStyle||Vo(e,t,o,n,i),...n,showLegend:n.showLegend??!!t,...m&&{svgPreRenderers:m}}}},on={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};const o=t.xAccessor||"x",n=t.yAccessor||"y",i=t.orderAccessor?[...e].sort((e,o)=>null==e||"object"!=typeof e?1:null==o||"object"!=typeof o?-1:Ut(qt(t.orderAccessor,"order",e))-Ut(qt(t.orderAccessor,"order",o))):e,r=new WeakMap;let s=0;for(const e of i){if(null==e||"object"!=typeof e)continue;const t=Ut(qt(o,"x",e)),i=Ut(qt(n,"y",e));Number.isFinite(t)&&Number.isFinite(i)&&s++}let a=0;for(const e of i){if(null==e||"object"!=typeof e)continue;const t=Ut(qt(o,"x",e)),i=Ut(qt(n,"y",e));Number.isFinite(t)&&Number.isFinite(i)&&r.set(e,{idx:a++,total:s})}return{data:i,orderMap:r}}(e,i),s=i.pointRadius??4,a=[e=>{const t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(2>t.length)return null;const o=[];for(let e=0;t.length-1>e;e++){const n=t[e],i=t[e+1],r=Qt(e,t.length);100>t.length&&o.push(Ht.createElement("line",{key:"halo-"+e,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:s+2,strokeLinecap:"round",opacity:.5})),o.push(Ht.createElement("line",{key:"segment-"+e,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:s,strokeLinecap:"round"}))}return Ht.createElement(Ht.Fragment,null,...o)}];return{chartType:"scatter",data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,colorScheme:o,pointStyle:Xt(e=>{const t=r.orderMap.get(e),o=t?.idx??0,n=t?.total??1;return{fill:n>0?Qt(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1}},Zt(i)),...n,svgPreRenderers:a}}},nn={frameType:"xy",buildProps:(e,t,o,n,i)=>{const r=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1;return{chartType:"heatmap",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,colorScheme:o||i.colorScheme||"blues",showValues:i.showValues,heatmapValueFormat:i.valueFormat,areaStyle:()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:r}),...n}}};function rn(e){return Math.max(0,Math.min(1,e))}function sn(e){const t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const o=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const e=[Number(o[1]),Number(o[2]),Number(o[3])];if(e.every(Number.isFinite))return e}return null}function an(e,t,o){const n=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${n(e)}${n(t)}${n(o)}`}function ln(e,t,o){const n=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:rn(e.offset),color:e.color??o,opacity:null==e.opacity?1:rn(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===n.length)return"#999999";const i=e=>{if(1===e.opacity)return e.color;const t=sn(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===n.length)return i(n[0]);const r=rn(t);if(n[0].offset>=r)return i(n[0]);if(r>=n[n.length-1].offset)return i(n[n.length-1]);for(let e=0;n.length-1>e;e++){const t=n[e],o=n[e+1];if(t.offset>r||r>o.offset)continue;const s=o.offset-t.offset,a=s>0?(r-t.offset)/s:0,l=sn(t.color),c=sn(o.color);if(!l||!c)return i(.5>a?t:o);const[u,d,h]=l,[p,g,m]=c,f=u+(p-u)*a,y=d+(g-d)*a,b=h+(m-h)*a,x=t.opacity+(o.opacity-t.opacity)*a;return 1===x?an(f,y,b):`rgba(${Math.round(f)},${Math.round(y)},${Math.round(b)},${x})`}return i(n[n.length-1])}function cn(e,t,o){return null==o?`${e}-${t}`:`${e}-${t}-${o}`}import{Fragment as un,jsx as dn,jsxs as hn}from"react/jsx-runtime";import{useMemo as pn,useCallback as gn,useRef as mn}from"react";var fn={RdBu:wt,PiYG:vt,PRGn:xt,BrBG:bt,RdYlBu:At,RdYlGn:St,Spectral:kt},yn="__likert_neutral_neg",bn="__likert_neutral_pos";function xn(e,t){if("function"==typeof e)return e;const o=e||t;return e=>e[o]}import*as vn from"react";function wn(e){return Se(e)}function An(e,t,o,n,i){const s=Kt(n.theme).colors.categorical,l=o??n.colorScheme,c=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],u="string"==typeof t?t:"__ssrColorBy",d="function"==typeof t?c.map(e=>({...e,__ssrColorBy:t(e)})):c,h=t?J(d,u,l??s):void 0,p=Ee("string"==typeof i.color?i.color:void 0,s,l,void 0,new Map),g=r(i.valueAccessor),m=i.styleRules,f=n.pieceStyle;return(e,o)=>{const n={fill:t&&h?le(e,t,h):p};return m?.length&&Object.assign(n,a(e,m,{value:g(e),category:o})),"function"==typeof f?Object.assign(n,f(e,o)||{}):f&&"object"==typeof f&&Object.assign(n,f),void 0!==i.stroke&&(n.stroke=i.stroke),void 0!==i.strokeWidth&&(n.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(n.opacity=i.opacity),n}}function Sn(e,t,o,n,i){const r=An(e,t,o,n,i);return(e,t)=>{const o=r(e,t);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function kn(e,t,o,n,i){const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s="string"==typeof t?t:"__ssrViolinColorBy",a="function"==typeof t?r.map(e=>({...e,__ssrViolinColorBy:t(e)})):r,l=Kt(n.theme).colors.categorical,c=o??n.colorScheme,u=t?J(a,s,c??l):void 0,d=Ee("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return e=>{const o=t&&u?le(e,t,u):d;return{fill:o,fillOpacity:.6,stroke:i.stroke??o,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function Mn(e,t,o,n,i){const r=An(e,t,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(e,t)=>({r:s,fillOpacity:.8,...r(e,t)})}function _n(e,t,o,n,i){const r=An(e,t,o,n,i),s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(e=>"function"==typeof a?a(e):Number(e[a])).filter(Number.isFinite):[],u=c.length?Ot(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(e,t)=>({r:a?de(e,a,l,u):d,fillOpacity:h,...r(e,t)})}var Pn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>({chartType:"bar",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,colorAccessor:t,colorScheme:o,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:wn(n.gradientFill),pieceStyle:An(e,t,o,n,i)})},Tn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>{const r=t||i.stackBy;return{chartType:"bar",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:wn(n.gradientFill),pieceStyle:An(e,r,o,n,i),showLegend:n.showLegend??!!r}}},Ln={frameType:"ordinal",buildProps:(e,t,o,n,i)=>{const r=t||i.groupBy;return{chartType:"clusterbar",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",groupBy:i.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:wn(n.gradientFill),pieceStyle:An(e,r,o,n,i),showLegend:n.showLegend??!!r}}},Rn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>{const r=t||i.categoryAccessor;return{chartType:"pie",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:An(e,r,o,n,i),showLegend:n.showLegend??!!r}}},In={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,o,n,i)=>{const r=t||i.categoryAccessor;return{chartType:"donut",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:n.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:An(e,r,o,n,i)}}},Cn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>{const r=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=i.valueAccessor||"value",a=r.map(e=>Number("function"==typeof s?s(e):e[s])).filter(Number.isFinite),l=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:e,oAccessor:i.categoryAccessor||(e=>null==e.category?"All":e.category+""),rAccessor:s,projection:"horizontal",bins:i.bins??25,normalize:i.relative??!1,colorAccessor:t,colorScheme:o,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:l?{rExtent:l}:{},...n,summaryStyle:Sn(e,t,o,n,i)}}},zn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>({chartType:"boxplot",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,colorScheme:o,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...n,summaryStyle:n.summaryStyle||Sn(e,t,o,n,i)})},Fn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>({chartType:"violin",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===i.orientation?"horizontal":"vertical",bins:i.bins??25,showIQR:i.showIQR??!0,barPadding:i.categoryPadding??20,colorScheme:o,...n,summaryStyle:n.summaryStyle||kn(e,t,o,n,i),showLegend:n.showLegend??!!t,...i.valueExtent&&{rExtent:i.valueExtent}})},On={frameType:"ordinal",buildProps:(e,t,o,n,i)=>({chartType:"swarm",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,sizeRange:i.sizeRange||[3,8],pieceStyle:n.pieceStyle||_n(e,t,o,n,i),showLegend:n.showLegend??!!t})},Bn={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,o,n,i)=>({chartType:"point",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...n,pieceStyle:Mn(e,t,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!t})},Nn={frameType:"ordinal",buildProps:(e,t,o,n,i)=>{const r=t||i.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.subcategoryAccessor,colorAccessor:r,categoryAccessor:i.categoryAccessor,subcategoryAccessor:i.subcategoryAccessor,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:wn(n.gradientFill),pieceStyle:n.pieceStyle||An(e,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},En={frameType:"ordinal",buildProps:(e,t,o,n,i)=>({chartType:"ridgeline",data:e,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:t,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...n,summaryStyle:n.summaryStyle||((r,s)=>({fillOpacity:.5,...An(e,t,o,n,i)(r,s)})),showLegend:n.showLegend??!!t})},jn={frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,o,n,i)=>{const r=Array.isArray(i.levels)&&i.levels.length>=2?i.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==i.orientation;let a=function(e,t,o,n,i,r){const s=new Map,a=new Set(t);for(const l of e){const e=o(l);s.has(e)||s.set(e,new Map);const c=s.get(e);if(n){const e=n(l);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}const o=e-1;if(0>o||o>=t.length)continue;const i=t[o];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const e=i(l),t=r(l);if(!a.has(e))continue;c.set(e,(c.get(e)||0)+(Number.isFinite(t)?t:0))}}const l=[];for(const[e,o]of s){let n=0;for(const e of t)n+=o.get(e)||0;if(0!==n)for(let i=0;t.length>i;i++){const r=t[i],s=o.get(r)||0;l.push({__likertCategory:e,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/n*100,__likertLevelIndex:i})}}return l}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],r,xn(i.categoryAccessor,"question"),i.levelAccessor?null:xn(i.valueAccessor,"score"),i.levelAccessor?xn(i.levelAccessor,"level"):null,i.levelAccessor?xn(i.countAccessor,"count"):null);s&&(a=function(e,t){const o=t.length,n=o%2!=0,i=Math.floor(o/2),r=new Map;for(const t of e){const e=r.get(t.__likertCategory)||[];e.push(t),r.set(t.__likertCategory,e)}const s=[];for(const[,e]of r){const t=new Map;let r,a;for(const o of e)o.__likertLevel===yn?r=o:o.__likertLevel===bn?a=o:t.set(o.__likertLevelIndex,o);n&&r&&s.push(r);for(let e=i-1;e>=0;e--){const o=t.get(e);o&&s.push(o)}n&&a&&s.push(a);for(let e=n?i+1:i;o>e;e++){const o=t.get(e);o&&s.push(o)}}return s}(function(e,t){const o=t.length,n=o%2!=0,i=Math.floor(o/2),r=[];for(const t of e){const e=t.__likertLevelIndex;if(n&&e===i){const e=t.__likertPct/2;r.push({...t,__likertLevel:yn,__likertPct:-e}),r.push({...t,__likertLevel:bn,__likertPct:e})}else r.push(i>e?{...t,__likertPct:-t.__likertPct}:t)}return r}(a,r),r));const l=Kt(n.theme).colors.diverging,c=Array.isArray(o)&&o.length>=r.length?o:function(e,t){if(0>=e)return[];if(t){const o=fn[t];if(o){if(1===e)return[o(.5)];const t=[];for(let n=0;e>n;n++)t.push(o(n/(e-1)));return t}}const o=["#da1e28","#ff8389","#ffb3b8"],n=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===e)return[i];const r=e%2!=0,s=Math.floor(e/2),a=[];for(let e=0;s>e;e++)a.push(o[Math.min(Math.floor(e*o.length/s),o.length-1)]);r&&a.push(i);for(let e=0;s>e;e++)a.push(n[Math.min(Math.floor(e*n.length/s),n.length-1)]);return a}(r.length,l),u=new Map(r.map((e,t)=>[e,c[t]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:e=>Math.abs(Number(e)).toFixed(0)+"%",p=!1===n.showLegend?void 0:{legendGroups:[{label:"",items:r.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},g=X(p,n.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:n.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...n,pieceStyle:Xt(e=>{const t=e.__likertLevel||e.data?.__likertLevel;return{fill:t===yn||t===bn?d:u.get((e.__likertLevelLabel||e.data?.__likertLevelLabel||t)+"")||"#888"}},Zt(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...g&&{legend:g},__legendIncludesAutomatic:!0}}},$n={frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,n,i)=>{const r="vertical"===i.orientation,s=t||i.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:e,oAccessor:i.stepAccessor||"step",rAccessor:i.valueAccessor||"value",colorAccessor:s,categoryAccessor:i.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,...!r&&null!=i.connectorOpacity&&{connectorOpacity:i.connectorOpacity},barPadding:r?40:0,colorScheme:o,...n,showAxes:r,showGrid:r,pieceStyle:An(e,s,o,n,i),showLabels:i.showLabels??!0}}},Dn={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(e,{theme:t}){const o=e.__gauge;if(!o)return null;const n=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,i=o.needleColor||t.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(e=>e.value>o.gMin&&o.gMax>e.value):[];return hn(un,{children:[o.showNeedle&&hn(un,{children:[dn("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(n),y2:o.centerY+o.needleLength*Math.sin(n),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),dn("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&dn("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:i,children:o.contextValue}),r.map((e,n)=>{const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(e.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,s=o.radius+1,a=o.radius+10,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return hn("g",{children:[dn("line",{x1:o.centerX+Math.cos(i)*r,y1:o.centerY+Math.sin(i)*r,x2:o.centerX+Math.cos(i)*s,y2:o.centerY+Math.sin(i)*s,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),dn("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:c,dominantBaseline:u,fill:t.colors.textSecondary,fontSize:10,children:e.label||e.value+""})]},"gauge-label-"+n)})]})},buildProps:(e,o,n,i,r)=>{const s=r.min??0,a=r.max??100,l=r.sweep??240,c=r.arcWidth??.3,d=!1!==r.showNeedle,h=!1!==r.fillZones,{startAngleDeg:p}=u(l),g=r.thresholds||[{value:a,color:r.color||"#4e79a7"}],m=Ae(i.gradientFill),f=function(e){const{min:t,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=e,d=o-t||1,h=(Math.max(t,Math.min(o,n))-t)/d;let p=i&&i.length>0?[...i].sort((e,t)=>e.value-t.value):[{value:o,color:r||"#007bff"}];p=p.map(e=>({...e,value:Math.max(t,Math.min(o,e.value))})),o>p[p.length-1].value&&p.push({value:o,color:p[p.length-1].color});const g=!!c&&c.stops.length>=2,m=[],f=new Map,y=[];if(g){const e=a?h:1,t=cn("bg",0);if(m.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),f.set(t,{fill:s,opacity:.4}),e>0){const t=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(t,Math.round(e*t))),n=[];for(let t=0;o>t;t++)n.push(ln(c.stops,e*(t+.5)/o,r||p[0]?.color||"#007bff"));const i=cn("fill",0);m.push({category:i,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),f.set(i,{fill:n[0]||s})}}else{let e=t;for(let o=0;p.length>o;o++){const n=p[o],i=(n.value-e)/d,r=(e-t)/d,l=(n.value-t)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const e=cn("fill",o);m.push({category:e,value:c,_zone:n.label||"Zone "+(o+1),_isFill:!0}),f.set(e,{fill:n.color})}if(u>0){const e=cn("bg",o);m.push({category:e,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),f.set(e,{fill:s,opacity:.4})}e=n.value}}if(l&&i&&i.length>0)for(const e of i)e.value>t&&o>e.value&&y.push({type:"gauge-label",value:e.value,label:e.label||e.value+""});return{gaugeData:m,pieceStyle:(e,t)=>f.get(t||e.category)||{fill:s},gaugeAnnotations:y}}({min:s,max:a,value:r.value,thresholds:g,fillColor:r.color,backgroundColor:r.backgroundColor||"#e0e0e0",fillZones:h,showScaleLabels:!1!==r.showScaleLabels,gradientFill:m}),[y,b]=i.size||[300,250],x=t(l),v=Math.min(10,Math.max(1,Math.min(y,b)/12)),w=Math.max(4,Math.min((y-2*v)/x.width,(b-2*v)/x.height)-2),A=Math.max(0,Math.min(w-1.5,w*(1-c))),S=y/2-x.cx*w,k=b/2-x.cy*w,M=2*(w+4),_=Math.max(s,Math.min(a,r.value??s)),P="function"==typeof r.valueFormat?r.valueFormat(_):Math.round(_)+"",T=r.centerContent??i.centerContent,L=null!=T?"function"==typeof T?T(_,s,a):T:"sparkline"===r.mode||"context"===r.mode?void 0:vn.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},vn.createElement("div",{style:{fontSize:Math.max(16,.3*w),fontWeight:700,color:"var(--semiotic-text, #333)"}},P),!1!==r.showScaleLabels&&vn.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${s} – ${a}`));return{chartType:"donut",data:f.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:A,sweepAngle:l,startAngle:p,oSort:!1,pieceStyle:Xt(f.pieceStyle,Zt(r)),...null!=r.cornerRadius&&{cornerRadius:r.cornerRadius},...i,size:[y,b],margin:{top:k-M/2,bottom:b-k-M/2,left:S-M/2,right:y-S-M/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(i.annotations)?i.annotations:[],...f.gaugeAnnotations],__gauge:{gMin:s,gMax:a,sweep:l,arcWidth:c,value:_,startAngleDeg:p,thresholds:g,centerX:S,centerY:k,radius:w,innerRadius:A,showScaleLabels:!1!==r.showScaleLabels,needleLength:A>20?A-8:w-1,showNeedle:d,needleColor:r.needleColor,..."context"===r.mode&&null==T&&{contextValue:P,contextValueY:k-.2*A,valueFontSize:Math.max(12,Math.min(22,.28*w))}}}}};import{scaleTime as Wn}from"d3-scale";var Yn={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function Vn(e="static"){return Yn[e]??Yn.static}var Hn=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function Gn(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:Hn.has(e.kind)?"fatal":"warn"}function Xn(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function qn(e,t){return t>e?-1:e>t?1:0}function Un(e){return e.occupants.map(e=>e.id).sort(qn).join("\0")}function Qn(e,t,o=0){return e.slice(0,-1).map((n,i)=>null!=n.group&&n.group===e[i+1].group?o:t)}function Zn(e,t){return e.map(e=>{const o=new Map;for(const n of e.occupants){const e=t[n.id];if(e)for(const t of e.samples){const e=o.get(t.t)??{before:0,after:0},n=t.boundaryOffset??0;o.set(t.t,{before:Math.max(e.before,t.topMass-n),after:Math.max(e.after,t.botMass+n)})}}return[...o].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function Kn(e,t,o){if(0===e.length)return[];const{padding:n,plotH:i,valueScale:r}=o,s=o.stackValueScale??r,a=Qn(e,n,o.groupPadding??0),l=[n+e[0].peak.topPeak*s];for(let o=1;e.length>o;o++)l.push(l[o-1]+t[o-1]*s+a[o-1]);const c=l[l.length-1]+e[e.length-1].peak.botPeak*s+n;if(c>i&&c>0){const e=i/c;for(let t=0;l.length>t;t++)l[t]*=e}return l}function Jn(e,t){const o=(e.boundaryOffset??0)*t,n=e.value*t;if("out"===e.kind){const i=e.sideMassBefore*t;return o+("top"===e.side?n/2-i:i-n/2)}const i=e.sideMassAfter*t;return o+("top"===e.side?n/2-i:i-n/2)}function ei(e,t,o,n,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:A(Zn(n,o)).adjacentClearance,a=Kn(n,s,r);let l="hug"===r.lanePlacement?function(e,t,o,n,i,r,s){const a=e.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=Qn(e,l,s.groupPadding??0),h=i.map((e,t)=>e*u+d[t]),p=l+e[0].peak.topPeak*u,g=c-l-e[a-1].peak.botPeak*u;if(h.reduce((e,t)=>e+t,0)+1e-6>=g-p)return Kn(e,i,s);let m=1===a?[(p+g)/2]:[...r];for(let e=0;12>e;e++){const e=Array(a).fill(0),i=Array(a).fill(0);for(const r of o){const o=t[r.source],s=t[r.target];if(null==o||null==s||o===s)continue;const a=n[r.source]?.localAttachments.get(r.id),l=n[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=Jn(a,u),h=Jn(l,u);e[o]+=(m[s]+h-d)*c,i[o]+=c,e[s]+=(m[o]+d-h)*c,i[s]+=c}const r=m.map((t,o)=>0===i[o]?t:.45*t+e[o]/i[o]*.55),s=S({desired:r,minGaps:h,weights:i.map(e=>Math.max(1,e)),min:p,max:g});let l=0;for(let e=0;a>e;e++)l=Math.max(l,Math.abs(s[e]-m[e]));if(m=s,.01>l)break}return m}(n,i,t,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=t=>{const o={};for(const n of e)o[n.id]=t[i[n.id]];return o};ti(o(l),t)>ti(o(a),t)+1e-6&&(l=[...a])}const c={};for(const t of e)c[t.id]=l[i[t.id]];let u=1/0,d=-1/0;for(const t of e){const e=c[t.id],n=o[t.id];Number.isFinite(e)&&n&&(u=Math.min(u,e-n.topPeak*r.valueScale),d=Math.max(d,e+n.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function ti(e,t){let o=0;for(const n of t){const t=e[n.source],i=e[n.target];Number.isFinite(t)&&Number.isFinite(i)&&(o+=Math.abs(t-i)*(n.value>0?n.value:1))}return o}function oi(e,t){const o=e?.samples;if(!o||0===o.length||o[0].t>t)return{top:0,bot:0};let n=0,i=o.length-1,r=0;for(;i>=n;){const e=n+i>>>1;o[e].t>t?i=e-1:(r=e,n=e+1)}const s=o[r].boundaryOffset??0;return{top:o[r].topMass-s,bot:o[r].botMass+s}}function ni(e,t,o,n,i){const r=1-i;return r*r*r*e+3*r*r*i*t+3*r*i*i*o+i*i*i*n}function ii(e,t){let o=0,n=1;for(let i=0;28>i;i++){const i=(o+n)/2;e>ni(0,t,t,1,i)?o=i:n=i}return(o+n)/2}function ri(e,t,o){const n=t+Jn(e,o),i=e.value*o/2;return[n-i,n+i]}function si(e,t,o,n){return Math.max(0,Math.min(t,n)-Math.max(e,o))/Math.max(1e-9,t-e)}function ai(e,t,o,n,i,r,s){const{valueScale:a,domain:l,mode:c="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of e){const e=n[s.source],h=n[s.target];if(null==e||null==h||2>Math.abs(e-h))continue;const p=t[s.source]?.localAttachments.get(s.id),g=t[s.target]?.localAttachments.get(s.id);if(!p||!g)continue;const m=Math.max(s.startTime,l?.[0]??-1/0),f=Math.min(s.endTime,l?.[1]??1/0);if(m>=f)continue;const[y,b]=ri(p,i[s.source],a),[x,v]=ri(g,i[s.target],a),w=Math.min(e,h)+1,A=Math.max(e,h)-1;for(let e=w;A>=e;e++){const n=o[e];if(!n)continue;const l=[m,f];if("quality"===c)for(const e of n.occupants)for(const o of t[e.id]?.samples??[])o.t>m&&f>o.t&&l.push(o.t);const h=e=>{const o=ii((e-m)/(f-m),u),l=ni(y,y,x,x,o),c=ni(b,b,v,v,o);let d=0;for(const o of n.occupants){if(o.id===s.source||o.id===s.target)continue;const n=r[o.id];if(null!=n?.start&&n.start>e)continue;if(null!=n?.end&&e>n.end)continue;const u=oi(t[o.id],e),h=i[o.id];d=Math.max(d,si(l,c,h-u.top*a,h+u.bot*a))}return d},p=[...new Set(l)].sort((e,t)=>e-t);let g=0;for(let e=0;p.length-1>e;e++){const t=p[e],o=p[e+1]-t;g+=(h(t+.25*o)+h(t+.5*o)+h(t+.75*o))/3*o}d+=g/(f-m)*(s.value>0?s.value:1)}}return d}function li(e,t,o,n,i,r,s,a,l,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:ti(s,o),transitOcclusion:ai(o,n,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function ci(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function ui(e,t){return e.map(e=>({t:ci(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function di(e,t,o){const n=t+(e.boundaryOffset??0)*o,i=e.value*o;if("out"===e.kind){const t=e.sideMassBefore*o;if("top"===e.side){const e=n-t;return[e,e+i]}const r=n+t;return[r-i,r]}const r=e.sideMassAfter*o;if("top"===e.side){const e=n-r;return[e,e+i]}const s=n+r;return[s-i,s]}function hi(e,t,o,n,i="temporal"){const r=t.incoming[e.id],s=t.outgoing[e.id],a=[];for(const e of r)a.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:o.get(e.id).targetSide});for(const e of s)a.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:o.get(e.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(l[e.kind]??99)-(l[t.kind]??99)||((e,t)=>{if(!n||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;const o=n.get(e.edge.id)?.target,i=n.get(t.edge.id)?.target;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===e.side?o-i:i-o:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;const o=n.get(e.edge.id)?.source,i=n.get(t.edge.id)?.source;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===e.side?i-o:o-i:0}return 0})(e,t)||qn(e.edge?.id??"",t.edge?.id??"")||qn(e.side,t.side)||e.delta-t.delta)},u=a.length?Ft(a.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let p=null,g=0;for(const e of a)e.time!==p&&(p=e.time,g=0),e.sequence=g++;const m=e=>({time:e.time,phase:0,sequence:e.sequence??0}),f=[];let y=0,b=0;for(const e of a)if("out"===e.kind){const t=Math.abs(e.delta);let o=t-("top"===e.side?y:b);if(o>0){const t="top"===e.side?"bot":"top",n=Math.min(o,"top"===t?y:b);if(n>0){const i=m(e);f.push({...i,delta:-n,kind:"transfer-out",side:t}),f.push({...i,delta:+n,kind:"transfer-in",side:e.side}),"top"===t?y-=n:b-=n,"top"===e.side?y+=n:b+=n,o-=n}o>0&&null!==h&&(f.push({time:h,delta:+o,kind:"create",side:e.side}),"top"===e.side?y+=o:b+=o)}"top"===e.side?y-=t:b-=t}else if("in"===e.kind){const t=Math.abs(e.delta);"top"===e.side?y+=t:b+=t}a.push(...f),c();let x=0,v=0,w=0,A=0,S=0,k=0;const M=[],_=new Map,P=e=>{M.push({t:e,topMass:x,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},T=()=>{A=Math.max(A,x+v),S=Math.max(S,x-w),k=Math.max(k,v+w)};for(const e of a){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&P(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){const t="top"===e.side?x:v;_.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===e.side?x+=e.delta:v+=e.delta,"transfer-in"===e.kind?(w+="top"===e.side?e.delta:-e.delta,T(),P(e.time)):"transfer-out"!==e.kind&&(T(),"out"!==e.kind||x+v>1e-12||(w=0),P(e.time))}const L=[];let R=0;for(;M.length>R;){let e=R;for(;M.length>e+1&&M[e+1].t===M[R].t;)e++;L.push(M[R]);for(let t=R+1;e>=t;t++){const e=L[L.length-1];M[t].topMass===e.topMass&&M[t].botMass===e.botMass&&(M[t].boundaryOffset??0)===(e.boundaryOffset??0)||L.push(M[t])}R=e+1}const I=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null;let C=null;for(const e of s)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===C||C>e.systemInTime)&&(C=e.systemInTime);let z=null;for(const e of r)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===z||e.systemOutTime>z)&&(z=e.systemOutTime);if(L.length>0){const e=L[L.length-1],t=Math.max(null!=I?I:-1/0,null!=z?z:-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&L.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});const o=L[0],n=L.find(e=>e.topMass+e.botMass>0);let i,r=1/0;null!=d&&Number.isFinite(d)&&o.t>d&&o.topMass+o.botMass>0&&(r=d,i=o),n&&null!=C&&Number.isFinite(C)&&n.t>C&&r>C&&(r=C,i=n),i&&Number.isFinite(r)&&L.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let F=L;if("max"===i&&null!=d&&null!=I&&I>d){let e,t=0;for(const o of L){const n=o.topMass+o.botMass;n>t&&(t=n,e=o)}if(e){const t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};F=[...L.filter(e=>d>e.t),{t:d,...t},{t:I,...t},...L.filter(e=>e.t>I)]}}return{samples:F,peak:A,topPeak:S,botPeak:k,localAttachments:_}}function pi(e){const t={};return e.forEach((e,o)=>{for(const n of e.occupants)t[n.id]=o}),t}function gi(e,t,o){e.splice(0,e.length,...o);const n=pi(o);for(const e of Object.keys(t))delete t[e];Object.assign(t,n)}function mi(e){const t=new Map,o=[];e.forEach((e,n)=>{if(!e.group)return void o.push({anchor:n,stableId:Un(e),slots:[e]});const i=t.get(e.group)??{indexes:[],slots:[]};i.indexes.push(n),i.slots.push(e),t.set(e.group,i)});for(const[e,n]of t)o.push({anchor:n.indexes.reduce((e,t)=>e+t,0)/n.indexes.length,stableId:`${e}\0${n.slots.map(Un).join("\0")}`,slots:n.slots});return o.sort((e,t)=>e.anchor-t.anchor||qn(e.stableId,t.stableId))}function fi(e){return e.some(e=>e.group)?mi(e).flatMap(e=>e.slots):[...e]}function yi(e){return e.flatMap(e=>e.slots)}function bi(e,t,o){const n=new Map;return e.forEach((e,t)=>{for(const o of e.slots)n.set(o,t)}),e.map((e,i)=>{if(1>=e.slots.length)return e;const r=new Map;for(const t of e.slots)r.set(t,0);for(const e of t){const t=n.get(e.source),o=n.get(e.target);if(null==t||null==o)continue;const s=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===i&&o!==i){const t=o>i?1:-1;r.set(e.source,(r.get(e.source)??0)+s*t)}else if(o===i&&t!==i){const o=t>i?1:-1;r.set(e.target,(r.get(e.target)??0)+s*o)}}const s=[...e.slots].sort((e,t)=>(r.get(e)??0)-(r.get(t)??0)||o(e,t));return{...e,slots:s}})}function xi(e,t){e.some(e=>e.group)&&gi(e,t,fi(e))}function vi(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.min(e.endTime,t.endTime)>Math.max(e.startTime,t.startTime)}function wi(e,t){return y(t,t=>[e[t.source],e[t.target]],vi)}function Ai(e,t){let o=0;for(const n of t){const t=e[n.source],i=e[n.target];null!=t&&null!=i&&(o+=Math.abs(t-i)*(n.value>0?n.value:1))}return o}function Si(e,t,o){const[n,i]=o.get(e.first),[r,s]=o.get(e.second);return 0>(t.get(n)-t.get(r))*(t.get(i)-t.get(s))?1:0}var ki=e=>{let t=1;for(let o=2;e>=o;o++)t*=o;return t},Mi=828*ki(8),_i=3e3;function Pi(e,t,o,n,i,r,s){const a=[...i],l=new Map(i.map(e=>[e,Un(e)])),c=new Map;for(const e of i)for(const t of e.occupants)c.set(t.id,e);const u=new Map,d=[];for(const e of t){const t=c.get(e.source),o=c.get(e.target);t&&o&&(u.set(e,[t,o]),t!==o&&d.push({source:t,target:o,weight:e.value}))}const h=[];for(let e=0;t.length>e;e++)if(u.has(t[e]))for(let o=e+1;t.length>o;o++){if(!u.has(t[o])||!vi(t[e],t[o]))continue;const n=new Set([...u.get(t[e]),...u.get(t[o])]);h.push({index:h.length,first:t[e],second:t[o],involvedSlots:n})}const p=new Map;for(const e of i)p.set(e,[]);for(const e of h)for(const t of e.involvedSlots)p.get(t)?.push(e);const g=new Uint32Array(h.length);let m=0;const f=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),y=s.plotH/Math.max(1,i.length),b=i.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),x=Math.max(1,f)*(Math.max(1,s.plotH)+y*Math.max(b,i.length)+1e-6*Math.max(1,i.length-1))+1,S=4*y,k={fullCrossing:0,localCrossing:0},M=new Map,_=(e,t)=>{let n=M.get(e);n||(n=new Map,M.set(e,n));const i=n.get(t);if(null!=i)return i;const r=function(e,t,o){return A(Zn([e,t],o)).adjacentClearance[0]??0}(e,t,o);return n.set(t,r),r},T=new Map(i.map((e,t)=>[e,t])),L=t.flatMap(e=>{const t=u.get(e);return t?[{source:T.get(t[0]),target:T.get(t[1]),weight:e.value>0?e.value:1}]:[]}),R=new Map;for(const e of t){const t=u.get(e);t&&R.set(e,{source:T.get(t[0]),target:T.get(t[1])})}const I=new Map,C=new Map;for(const e of t)I.has(e.source)||I.set(e.source,new Set),C.has(e.target)||C.set(e.target,new Set),I.get(e.source).add(e.target),C.get(e.target).add(e.source);const z=t.flatMap(e=>{if(!(e=>{const t=new Set([...I.get(e.source)??[],...C.get(e.source)??[]]),o=new Set([...I.get(e.target)??[],...C.get(e.target)??[]]);return 1===I.get(e.source)?.size&&I.get(e.source).has(e.target)||1===t.size&&t.has(e.target)||1===o.size&&o.has(e.source)})(e))return[];const t=R.get(e);return t&&t.source!==t.target?[{source:t.source,target:t.target,weight:e.value>0?e.value:1}]:[]}),F=e=>{let t=0;for(const o of z)t+=Math.max(0,Math.abs(e[o.source]-e[o.target])-1)*o.weight;return t*S},O=e=>{const t=new Int16Array(i.length);for(let o=0;e.length>o;o++)t[T.get(e[o])]=o;return F(t)},B=h.map(e=>{const t=R.get(e.first),o=R.get(e.second);return[t.source,t.target,o.source,o.target]}),N=new Int16Array(i.length),E=new Float64Array(i.length),j=new Float64Array(i.length+1),$=e=>{for(let t=0;e.length>t;t++)N[T.get(e[t])]=t;let t=0;for(const[e,o,n,i]of B)0>(N[e]-N[n])*(N[o]-N[i])&&t++;if(e.length>0){const t=T.get(e[0]);E[t]=s.padding+e[0].peak.topPeak*s.valueScale;for(let t=1;e.length>t;t++){const o=T.get(e[t-1]),n=T.get(e[t]);E[n]=E[o]+_(e[t-1],e[t])*s.valueScale+s.padding}const o=T.get(e[e.length-1]),n=E[o]+e[e.length-1].peak.botPeak*s.valueScale+s.padding;if(n>s.plotH&&n>0){const e=s.plotH/n;for(let t=0;E.length>t;t++)E[t]*=e}}j[0]=0;for(let t=0;e.length>t;t++)j[t+1]=j[t]+e[t].peak.topPeak+e[t].peak.botPeak;let o=0,n=0,i=0;for(const e of L){const t=N[e.source],r=N[e.target];if(o+=Math.abs(t-r)*e.weight,n+=Math.abs(E[e.source]-E[e.target])*e.weight,Math.abs(t-r)>=2){const o=Math.min(t,r)+1;i+=(j[Math.max(t,r)]-j[o])*e.weight}}return t*x+n+i*y+F(N)+1e-6*o},D=(e,o)=>{const n=Array(e.length+1).fill(0);for(let t=0;e.length>t;t++)n[t+1]=n[t]+e[t].peak.topPeak+e[t].peak.botPeak;let i=0;for(const e of t){const t=o[e.source],r=o[e.target];if(null==t||null==r||2>Math.abs(t-r))continue;const s=Math.min(t,r)+1;i+=(n[Math.max(t,r)]-n[s])*(e.value>0?e.value:1)}return i},W=n=>{const i=pi(n),r=n.slice(0,-1).map((e,t)=>_(e,n[t+1])),a=ei(e,t,o,n,i,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:i,geometry:a,weightedLength:Ai(i,t),pixelLength:ti(a.centerlines,t),transitOcclusion:D(n,i)}},Y=(e,t,o)=>({crossings:e,weightedLength:t.weightedLength,pixelLength:t.pixelLength,transitOcclusion:t.transitOcclusion,cost:e*x+t.pixelLength+t.transitOcclusion*y+O(o)+1e-6*t.weightedLength}),V=(e,t)=>{let o=t;if(null==o){const t=new Map(e.map((e,t)=>[e,t]));o=h.reduce((e,o)=>e+Si(o,t,u),0),k.fullCrossing++}return Y(o,W(e),e)},H=(e,i,r="quality")=>{let a=i;if(null==a){const t=new Map(e.map((e,t)=>[e,t]));a=h.reduce((e,o)=>e+Si(o,t,u),0),k.fullCrossing++}const l=W(e);return Y(a,{...l,transitOcclusion:ai(t,o,e,l.map,l.geometry.centerlines,n,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},e)};let G=[...a];const X=(e,t)=>qn(l.get(e),l.get(t)),q=function(e){const t=new Set;for(const o of e)if(o.group){if(t.has(o.group))return!0;t.add(o.group)}return!1}(G),U=e=>{const t=(e=>{const t=v(e,d,e=>V(e).cost,{passes:6,compare:X,maxEvaluations:_i});let o=V(t),n=_i;for(let e=0;6>e&&n>0;e++){let i=!1;const r=Array.from({length:t.length-1},(e,t)=>t);e%2==1&&r.reverse();for(const e of r){if(0>=n--)break;const r=t[e],s=t[e+1],a=new Map(t.map((e,t)=>[e,t]));let l=0;const c=[];m++;for(const e of[...p.get(r)??[],...p.get(s)??[]])g[e.index]!==m&&(g[e.index]=m,c.push(e),l+=Si(e,a,u));[t[e],t[e+1]]=[s,r];const d=new Map(a);d.set(r,e+1),d.set(s,e);let h=0;for(const e of c)h+=Si(e,d,u);k.localCrossing+=c.length;const f=V(t,o.crossings-l+h);o.cost>f.cost?(o=f,i=!0):[t[e],t[e+1]]=[r,s]}if(!i)break}return t})(e);if((e.length>8?1/0:ki(e.length)*(e.length+L.length+B.length))>Mi)return t;const o=w(e,$,{maxItems:8,maxEvaluations:5e4}),n=H(o),i=H(t);return n.crossings!==i.crossings&&i.crossings>n.crossings?o:t},Q="geometry-refine"===s.mode;if(Q||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!Q&&"inside-out"===s.laneOrder)if(q){const e=mi(G),t=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),o=[...e].sort((e,o)=>t(o)-t(e)||qn(e.stableId,o.stableId)),n=Array(o.length);let i=Math.floor((o.length-1)/2)-1,r=Math.floor((o.length-1)/2)+1;o.length>0&&(n[Math.floor((o.length-1)/2)]=o[0]);for(let e=1;o.length>e;e++)e%2==1&&o.length>r||0>i?n[r++]=o[e]:n[i--]=o[e];G=yi(n)}else{const e=[...G].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||X(e,t)),t=Array(e.length);let o=Math.floor((e.length-1)/2)-1,n=Math.floor((e.length-1)/2)+1;e.length>0&&(t[Math.floor((e.length-1)/2)]=e[0]);for(let i=1;e.length>i;i++)i%2==1&&e.length>n||0>o?t[n++]=e[i]:t[o--]=e[i];G=t}}else G=q?(e=>{let t=mi(e);if(1>=t.length)return yi(t);const o=e=>V(yi(e)).cost;t=mi(U(e)),t=bi(t,d,X);const n=function(e,t){const o=new Map;for(const t of e)for(const e of t.slots)o.set(e,t);const n=new Map;for(const e of t){const t=o.get(e.source),i=o.get(e.target);if(!t||!i||t===i)continue;const r=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,s=i.stableId>t.stableId?`${t.stableId}\0${i.stableId}`:`${i.stableId}\0${t.stableId}`,a=n.get(s);a?a.weight=(a.weight??0)+r:n.set(s,{source:t,target:i,weight:r})}return[...n.values()]}(t,d);t=v(t,n,o,{passes:6,compare:(e,t)=>qn(e.stableId,t.stableId),maxEvaluations:_i}),t=P(t,o,{passes:8,maxEvaluations:_i});const i=t.length>8?1/0:ki(t.length)*(t.length+L.length+B.length);if(Mi>=i){const e=w(t,e=>$(yi(e)),{maxItems:8,maxEvaluations:5e4}),o=yi(e),n=yi(t),i=H(o),r=H(n);i.crossings!==r.crossings?t=r.crossings>i.crossings?e:t:r.cost>i.cost&&(t=e)}return t=bi(t,d,X),yi(t)})(G):U(G);if(!Q&&"crossing-min+inside-out"===s.laneOrder&&G.length>1)if(q){const e=mi(G);let t=V(yi(e)),o=yi(e),n=t;const i=Math.floor((e.length-1)/2),r=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),s=[...e].sort((e,t)=>r(t)-r(e)||qn(e.stableId,t.stableId));for(const r of s){const s=e.indexOf(r);if(s===i)continue;e.splice(s,1),e.splice(i,0,r);const a=yi(e),l=V(a);l.cost>t.cost?(e.splice(i,1),e.splice(s,0,r)):(t=l,n.cost>l.cost&&(o=a,n=l))}G=o}else{let e=V(G),t=[...G],o=e;const n=Math.floor((G.length-1)/2),i=[...G].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||X(e,t));for(const r of i){const i=G.indexOf(r);if(i===n)continue;G.splice(i,1),G.splice(n,0,r);const s=V(G);s.cost>e.cost?(G.splice(n,1),G.splice(i,0,r)):(e=s,o.cost>s.cost&&(t=[...G],o=s))}G=t}if((Q||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&G.length>1)if(q){let e=mi(G),t=H(yi(e),void 0,"score");for(let o=0;6>o&&e.length>1;o++){let o=!1;for(let n=0;e.length-1>n;n++){[e[n],e[n+1]]=[e[n+1],e[n]];const i=yi(e),r=H(i,void 0,"score");t.cost>r.cost?(G=i,t=r,o=!0):[e[n],e[n+1]]=[e[n+1],e[n]]}if(!o)break}e=bi(mi(G),d,X),G=yi(e)}else{let e=H(G,void 0,"score");for(let t=0;G.length-1>t;t++){const o=G[t],n=G[t+1],i=new Map(G.map((e,t)=>[e,t]));let r=0;const s=[];m++;for(const e of[...p.get(o)??[],...p.get(n)??[]])g[e.index]!==m&&(g[e.index]=m,s.push(e),r+=Si(e,i,u));[G[t],G[t+1]]=[n,o];const a=new Map(i);a.set(o,t+1),a.set(n,t);let l=0;for(const e of s)l+=Si(e,a,u);k.localCrossing+=s.length;const c=H(G,e.crossings-r+l,"score");e.cost>c.cost?e=c:[G[t],G[t+1]]=[o,n]}}const Z=fi(a);G=fi(G);let K=H(G);const J=H(Z);if(Q){const e=O(Z),t=O(G);(K.crossings>J.crossings||K.crossings===J.crossings&&t>e+1e-9||K.cost>J.cost)&&(G=Z,K=J)}else K.cost>J.cost&&(G=Z,K=J);return gi(i,r,G),{before:J,after:K,initialOrder:a.map(e=>l.get(e)),evaluations:k}}function Ti(e,t,o){const n=e.map(e=>{const n=e.occupants.map(e=>({id:e.id,end:o[e.id]?.end??e.end}));let i=0,r=0;for(const e of n){const o=t[e.id];i=Math.max(i,o?.topPeak||0),r=Math.max(r,o?.botPeak||0)}return{occupants:n,peak:{topPeak:i,botPeak:r},...null!=e.group?{group:e.group}:{}}}),i={};return n.forEach((e,t)=>{for(const o of e.occupants)i[o.id]=t}),{slots:n,slotByNode:i}}var Li=new Map,Ri=1e-9,Ii=1e5;function Ci(e,t){let o=1/0,n=-1/0;for(const t of e?.samples??[])t.topMass+t.botMass>Ri&&(o=Math.min(o,t.t),n=Math.max(n,t.t));return Number.isFinite(o)&&Number.isFinite(n)?(null!=t.start&&(o=Math.max(o,t.start)),null!=t.end&&(n=Math.min(n,t.end)),o>n?{start:null,end:null}:{start:o,end:n}):{start:null,end:null}}function zi(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(t.start>=e.end||e.start>=t.end)}function Fi(e,t){return qn(e,t)>0?`${t}\0${e}`:`${e}\0${t}`}function Oi(e){const t=new Map,o=new Map;for(const n of e)o.has(n.source)||o.set(n.source,new Set),t.has(n.target)||t.set(n.target,new Set),o.get(n.source).add(n.target),t.get(n.target).add(n.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...o].map(([e,t])=>[e,t.size]))}}function Bi(e){const t=new Map,o=new Map,n=(e,t,o,n)=>{let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(o,(i.get(o)??0)+n)};for(const i of e){const e=i.value>0&&Number.isFinite(i.value)?i.value:1;n(t,i.source,i.target,e),n(o,i.target,i.source,e)}const i=new Map,r=e=>{if(i.has(e))return;const n=t.get(e),r=o.get(e);if(n&&1===n.size&&(!r||0===r.size)){const[t,o]=[...n][0];return void i.set(e,{partner:t,weight:o})}const s=new Map;for(const[e,t]of n??[])s.set(e,(s.get(e)??0)+t);for(const[e,t]of r??[])s.set(e,(s.get(e)??0)+t);if(1===s.size){const[t,o]=[...s][0];i.set(e,{partner:t,weight:o})}};for(const t of e)r(t.source),r(t.target);return i}function Ni(e,t,o){const n=o.get(e),i=o.get(t);return!n||!i||n.partner===i.partner||n.partner===t||i.partner===e}function Ei(e,t,o){return!!o.has(e)&&t.some(t=>!Ni(e,t,o))}function ji(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function $i(e,t,o,n){if(12>=e.length||1>=n.slotCount)return n.assignment;const i=new Map(e.map((e,t)=>[e,t])),r=Array.from({length:e.length},()=>new Map),s=Oi(o);for(const e of o){const t=i.get(e.source),o=i.get(e.target);if(null==t||null==o||t===o)continue;const n=ji(e,s);r[t].set(o,(r[t].get(o)??0)+n),r[o].set(t,(r[o].get(t)??0)+n)}const a=Bi(o),l=e.map(e=>a.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map);let u=0;for(let o=0;e.length-1>o&&5e4>u;o++)if(a.has(e[o]))for(let n=o+1;e.length>n;n++){if(!a.has(e[n]))continue;if(t.conflicts(e[o],e[n]))continue;u++;const i=Math.min(l[o],l[n])||Math.max(l[o],l[n]),r=Ni(e[o],e[n],a)?i:-i;if(Math.abs(r)>Ri&&(c[o].set(n,r),c[n].set(o,r),u>=5e4))break}const d=[...n.assignment],h=Array.from({length:n.slotCount},()=>[]);d.forEach((e,t)=>h[e].push(t));const p=(e,t,o)=>{const n=d[t],i=d[o];let r=0;const s=new Set;for(const a of[t,o])for(const[l,c]of e[a]){const e=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(e))continue;s.add(e);const u=(a===t?i:n)===(l===t?i:l===o?n:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}return r},g=(e,t,o)=>{let n=0;for(const[i,r]of e[t]){const e=o===d[i];d[t]===d[i]!==e&&(n+=e?r:-r)}return n},m=(e,t)=>e>Ri||Ri>=Math.abs(e)&&t>Ri,f=(e,t,o,n)=>e>o+Ri||Ri>=Math.abs(e-o)&&t>n+Ri;let y=0;for(let o=0;32>o&&Ii>y;o++){let o=null,n=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;e.length>u;u++){for(let p=0;h.length>p&&y++<Ii;p++){if(p===d[u])continue;if(!h[p].every(o=>!t.conflicts(e[u],e[o])))continue;const y=g(r,u,p),b=g(c,u,p);m(y,b)&&f(y,b,a,l)&&(o="move",n=u,i=-1,s=p,a=y,l=b)}if(y>=Ii)break}for(let u=0;e.length-1>u;u++){for(let g=u+1;e.length>g&&y++<Ii;g++){const y=d[u],b=d[g];if(y===b)continue;if(!h[b].every(o=>o===g||!t.conflicts(e[u],e[o])))continue;if(!h[y].every(o=>o===u||!t.conflicts(e[g],e[o])))continue;const x=p(r,u,g),v=p(c,u,g);m(x,v)&&f(x,v,a,l)&&(o="swap",n=u,i=g,s=-1,a=x,l=v)}if(y>=Ii)break}if(null==o||-1===n)break;if("move"===o){const e=d[n];h[e].splice(h[e].indexOf(n),1),h[s].push(n),d[n]=s;continue}const u=d[n],b=d[i];h[u].splice(h[u].indexOf(n),1,i),h[b].splice(h[b].indexOf(i),1,n),d[n]=b,d[i]=u}return d}function Di(e,t,o,n){const i=function(e,t,o,n){return`${e.map(e=>{const t=o[e.id],i=n[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,i?.start??"",i?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,o,n),r=Li.get(i);if(r)return Ti(r.slots,o,n);const s={};for(const t of e)s[t.id]=Ci(o[t.id],n[t.id]);const a=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,o)=>t[e.id].start-t[o.id].start||t[e.id].end-t[o.id].end||qn(e.id,o.id)).map(e=>e.id)}(e,s),l=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=function(e,t,o,n,i){const r=new Set,s=new Map(e.map(e=>[e,new Set])),a=new Map(e.map(e=>[e,new Set]));for(const e of n)r.add(Fi(e.source,e.target)),s.get(e.target)?.add(e.source),a.get(e.source)?.add(e.target);const l=new Map,c=new Set,u=(e,t)=>{for(let o=0;e.length>o;o++)for(let n=o+1;e.length>n;n++){const i=Fi(e[o],e[n]);t instanceof Map?t.set(i,[e[o],e[n]]):t.add(i)}};for(const e of a.values())u([...e],l);for(const e of s.values())u([...e],c);const d=new Set;for(const[e,[n,i]]of l)c.has(e)&&(zi(t[n],t[i])||zi(o[n],o[i])&&(d.add(n),d.add(i)));return{conflicts:(e,o)=>{const n=i.get(e),s=i.get(o);return null!=n&&null!=s&&n!==s||null!=n!=(null!=s)&&!r.has(Fi(e,o))||!!zi(t[e],t[o])||!(!d.has(e)&&!d.has(o))&&!r.has(Fi(e,o))}}}(a,s,n,t,c),d=function(e,t,o=new Map){const n=[],i=[];for(const r of e){let e=n.findIndex(e=>e.every(e=>!t.conflicts(r,e))&&!Ei(r,e,o));-1!==e||o.has(r)||(e=n.findIndex(e=>e.every(e=>!t.conflicts(r,e)))),-1===e&&(e=n.length,n.push([])),n[e].push(r),i.push(e)}return{assignment:i,slotCount:n.length}}(a,u,Bi(t)),h=function(e,t,o,n){if(0===e.length||e.length>12||1>=n.slotCount)return n.assignment;const i=new Map(e.map((e,t)=>[e,t])),r=Array.from({length:e.length},()=>new Float64Array(e.length)),s=Array.from({length:e.length},()=>new Map),a=Array.from({length:e.length},()=>new Map),l=Oi(o);for(const e of o){const t=i.get(e.source),o=i.get(e.target);if(null==t||null==o||t===o)continue;const n=ji(e,l);r[t][o]+=n,r[o][t]+=n,a[t].set(o,(a[t].get(o)??0)+n),s[o].set(t,(s[o].get(t)??0)+n)}const c=Bi(o),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;e.length>t;t++)for(let o=t+1;e.length>o;o++){for(const[e,n]of s[t])d[t][o]+=Math.min(n,s[o].get(e)??0);for(const[e,n]of a[t])d[t][o]+=Math.min(n,a[o].get(e)??0);if(c.has(e[t])&&c.has(e[o])){const n=Math.min(u[t],u[o])||Math.max(u[t],u[o]);d[t][o]+=Ni(e[t],e[o],c)?n:-n}d[o][t]=d[t][o]}let h=[...n.assignment],p=(t=>{let o=0,n=0;for(let i=0;e.length>i;i++)for(let s=i+1;e.length>s;s++)t[i]===t[s]&&(o+=r[i][s],n+=d[i][s]);return{flow:o,affinity:n}})(h),g=0;const m=Array(e.length).fill(-1),f=Array.from({length:n.slotCount},()=>[]),y=(o,i,s,a)=>{if(g>=75e3)return;if(o===e.length)return g++,void((s>p.flow||s===p.flow&&a>p.affinity||s===p.flow&&a===p.affinity&&function(e,t){for(let o=0;Math.min(e.length,t.length)>o;o++)if(e[o]!==t[o])return t[o]>e[o];return t.length>e.length}(m,h))&&(h=[...m],p={flow:s,affinity:a}));const l=Math.min(i+1,n.slotCount-1);for(let n=0;l>=n;n++){if(f[n].some(n=>t.conflicts(e[o],e[n])))continue;let l=0,c=0;for(const e of f[n])l+=r[o][e],c+=d[o][e];if(m[o]=n,f[n].push(o),y(o+1,Math.max(i,n),s+l,a+c),f[n].pop(),m[o]=-1,g>=75e3)return}};return m[0]=0,f[0].push(0),y(1,0,0,0),h}(a,u,t,{...d,assignment:$i(a,u,t,d)}),p=new Map,g=h.map(e=>(p.has(e)||p.set(e,p.size),p.get(e))),m=Array.from({length:p.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),f={};a.forEach((e,t)=>{const o=g[t],n=m[o];n.occupants.push({id:e,end:s[e].end??-1/0});const i=l.get(e)?.group;i&&(n.group=i),f[e]=o});for(const t of[...e].sort((e,t)=>qn(e.id,t.id)))null==f[t.id]&&(m[0].occupants.push({id:t.id,end:-1/0}),f[t.id]=0);for(const e of m){e.occupants.sort((e,t)=>(s[e.id].start??1/0)-(s[t.id].start??1/0)||qn(e.id,t.id));for(const t of e.occupants){const n=o[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,n?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,n?.botPeak||0)}}const y={slots:m,slotByNode:f};return function(e,t){for(Li.has(e)&&Li.delete(e),Li.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:{...t.slotByNode}});Li.size>12;){const e=Li.keys().next().value;if(null==e)break;Li.delete(e)}}(i,y),y}function Wi(e){return e.topMass+e.botMass}function Yi(e,t){const o=e.samples.filter(e=>e.t===t);if(o.length>0)return o.reduce((e,t)=>Wi(t)<Wi(e)?e:t,o[0]);let n=null;for(const o of e.samples){if(o.t>t)break;n=o}return n}function Vi(e,t,o,n,i,r,s=0){const a=new Map;for(const o of e){if(!o.group||!t[o.id])continue;const e=a.get(o.group)??[];e.push(o),a.set(o.group,e)}if(0===a.size||0>=r)return t;const l=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]));for(const[e,c]of a){const a=o.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=i[u.occupants[0]?.id],p=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(p))continue;const g=(h-u.peak.topPeak*r+(p+d.peak.botPeak*r))/2,m=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),f=new Map;for(const e of c)f.set(e.id,new Map);for(const e of m){const o=new Map;for(const i of c){const r=Yi(t[i.id],e);if(!r||1e-9>=Wi(r))continue;const s=n[i.id];if(null==s)continue;const a=o.get(s)??[];a.push({node:i,sample:r}),o.set(s,a)}const a=[...o].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:Math.max(...t.map(({sample:e})=>Wi(e)))}));if(0===a.length)continue;let l=g-(a.reduce((e,t)=>e+t.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const t of a){for(const{node:o,sample:n}of t.active){const t=(l-i[o.id])/r+n.topMass-(n.boundaryOffset??0);f.get(o.id).set(e,t)}l+=t.mass*r+Math.max(0,s)}}for(const e of c){const o=t[e.id],n=l[e.id],i=f.get(e.id),r=[];for(const e of m){const t=i.get(e),n=o.samples.filter(t=>t.t===e);if(n.length>0){r.push(...n.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}})));continue}const s=Yi(o,e);null!=t&&s&&Wi(s)>1e-9&&r.push({...s,t:e,boundaryOffset:(s.boundaryOffset??0)+t})}n.samples=r,n.localAttachments=new Map([...o.localAttachments].map(([e,t])=>{const o=i.get(t.time);return[e,{...t,...null!=o?{boundaryOffset:(t.boundaryOffset??0)+o}:{}}]}))}}return l}function Hi(e,t,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:p="both",domain:g}=i,m={},f={};for(const t of e)m[t.id]=o[t.id].topPeak||0,f[t.id]=o[t.id].botPeak||0;const y="half"===u,b={};for(const t of e){const e=Array.isArray(t.xExtent)?t.xExtent[0]:null,o=Array.isArray(t.xExtent)?t.xExtent[1]:null;let i=null!=e&&Number.isFinite(e)?e:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const e of n.outgoing[t.id]){i>e.startTime&&(i=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&i>e.systemInTime&&(i=e.systemInTime);const t=y?(e.startTime+e.endTime)/2:e.endTime;t>r&&(r=t)}for(const e of n.incoming[t.id]){const t=y?(e.startTime+e.endTime)/2:e.startTime;i>t&&(i=t),e.endTime>r&&(r=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>r&&(r=e.systemOutTime)}b[t.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}let x={},v=[],w=[];if(i.frozenSlots){const e=Ti(i.frozenSlots,o,b);v=e.slots,x=e.slotByNode,w=v.map(Un)}else if("reuse"===l){const n=Di(e,t,o,b);v=n.slots,x=n.slotByNode}else e.forEach((e,t)=>{v.push({occupants:[{id:e.id,end:b[e.id]?.end??-1/0}],peak:{topPeak:m[e.id],botPeak:f[e.id]},...e.group?{group:e.group}:{}}),x[e.id]=t});xi(v,x),0===w.length&&(w=v.map(Un));let A=null;i.frozenSlots||(i.fixedSlotOrder?function(e,t,o){const n=new Map(o.map((e,t)=>[e,t]));gi(e,t,[...e].sort((e,t)=>(n.get(Un(e))??1/0)-(n.get(Un(t))??1/0)||qn(Un(e),Un(t))))}(v,x,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(A=Pi(e,t,o,b,v,x,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:p,domain:g}))),xi(v,x);const S=ei(e,t,o,v,x,{plotH:r,padding:s,valueScale:a,stackValueScale:i.stackValueScale,lanePlacement:d,groupPadding:h}),k=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((e,t)=>e+t,0)+v[v.length-1].peak.botPeak,M=A?.before.crossings??null,_=A?.after.crossings??null,P=A?.before.weightedLength??null,T=A?.after.weightedLength??null;return{effectiveSlotsHeight:k,centerlines:S.centerlines,laneLifetime:b,slots:v,slotByNode:x,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(Un),initialSlotOrder:w,ordering:A,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:T}}function Gi(e,t,o,n,i,r,s,a,l={}){const c=i,u=e=>a?Math.max(a[0],Math.min(a[1],e)):e;let d=r(u(e.time));const h=r(u(o.time)),p=e.value*c,g=o.value*c,m=t+(e.boundaryOffset??0)*c,f=n+(o.boundaryOffset??0)*c,y=e.sideMassBefore*c,b=o.sideMassAfter*c;let x,v,w,A;"top"===e.side?(x=m-y,v=x+p):(v=m+y,x=v-p),"top"===o.side?(w=f-b,A=w+g):(A=f+b,w=A-g);const S=l.sourceRunwayStart,k=l.minRun,M=Math.abs((w+A)/2-(x+v)/2),_=h-d,P="number"==typeof S&&Number.isFinite(S),T="number"==typeof k&&Number.isFinite(k)&&k>0;if(P&&M>1e-9&&_>0&&("auto"===k||T)){const t="source"===s?.85:"target"===s?.15:.5,o="auto"===k?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(t*t,(1-t)*(1-t))))):k;if(o>_){const t=r(u(Math.min(S,e.time)));Number.isFinite(t)&&(d=Math.min(d,Math.max(Math.min(d,t),h-o)))}}const L="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:x,sBot:v,tx:h,tTop:w,tBot:A,cp1X:L,cp2X:L}}function Xi(e){return Math.max(18,11*e.length*.58)}function qi(e){const t=1.22*Xi(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function Ui(e,t){const o=e.labelX-Xi(e.labelText),n=t.labelX-Xi(t.labelText);return t.labelX+3>=o&&e.labelX+3>=n}var Qi=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function Zi(e){return e.replace(Qi,(e,t,o)=>`${o},${t}`)}function Ki(e){if(!e)return;const t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function Ji(e){return{...e,pathD:Zi(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function er(e){const{nodes:t,edges:o,domain:n,plotW:r,plotH:s,ribbonLane:l,ribbonMinRun:c=0,edgeOpacity:u,colorOf:d,layoutOpts:h,orientation:p="horizontal",showLabels:g=!0,labelPriorityAccessor:m,maxLabels:f,selectionDatum:y="raw",styleRules:b,colorBy:x,valueAccessor:v,usageMode:w="static"}=e,A="vertical"===p?s:r,S="vertical"===p?r:s,k=function(e,t,o,n={}){const i=Vn(n.usageMode??"static"),r=[],s=new Set;for(const t of e)s.has(t.id)&&r.push({kind:"duplicate-node",id:t.id,severity:i.duplicateIds}),s.add(t.id);const a=new Set,l=Array.isArray(o)&&2===o.length,c=l&&Number.isFinite(o[0])&&Number.isFinite(o[1]);l&&c&&c&&o[1]>=o[0]||r.push({kind:"invalid-domain"});for(const t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||r.push({kind:"invalid-node-time",id:t.id}));for(const e of t)a.has(e.id)&&r.push({kind:"duplicate-edge",id:e.id,severity:i.duplicateIds}),a.add(e.id),s.has(e.source)||r.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),s.has(e.target)||r.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&r.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),Number.isFinite(e.value)&&e.value>0||r.push({kind:"invalid-value",id:e.id}),e.startTime>e.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):r.push({kind:"invalid-edge-time",id:e.id});return r}(t,o,n,{usageMode:w}),{fatal:M,warnings:_}=function(e){const t=[],o=[];for(const n of e)"fatal"===Gn(n)?t.push(n):o.push(n);return{fatal:t,warnings:o}}(k),P=function(e,t,o="static"){if("strip"!==Vn(o).invalidSystemTime)return e;const n=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===n.size?e:e.map(e=>{if(!n.has(e.id))return e;const t={...e};return null==t.systemInTime||Number.isFinite(t.systemInTime)||delete t.systemInTime,null==t.systemOutTime||Number.isFinite(t.systemOutTime)||delete t.systemOutTime,t})}(o,k,w),T=Wn().domain(n).range([0,A]);if(M.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==g},issues:M,warnings:_,xScale:T};const L=function(e,t,o){const{plotH:n,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:p}=o,g=Number.isFinite(d)?Math.max(0,d):0,m=function(e,t){const o={},n={};for(const t of e)o[t.id]=[],n[t.id]=[];for(const e of t)n[e.source]&&n[e.source].push(e),o[e.target]&&o[e.target].push(e);return{incoming:o,outgoing:n}}(e,t),f=function(e,t,o,n="temporal"){const i="temporal"===n?(e,t)=>e.endTime-t.endTime||qn(e.id,t.id):(e,t)=>t.value-e.value||qn(e.id,t.id),r="temporal"===n?(e,t)=>e.startTime-t.startTime||qn(e.id,t.id):(e,t)=>t.value-e.value||qn(e.id,t.id),s=new Map;for(const e of t)s.set(e.id,{});const a=(e,t)=>{const o=new Map;for(const n of e){const e=n[t];o.has(e)||o.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=o.get(e);i.edges.push(n),i.total+=n.value,i.earliestStart=Math.min(i.earliestStart,n.startTime),i.latestEnd=Math.max(i.latestEnd,n.endTime)}const s=[...o.values()];s.sort("temporal"===n?(e,o)=>"target"===t?e.earliestStart-o.earliestStart||qn(e.partner,o.partner):e.latestEnd-o.latestEnd||qn(e.partner,o.partner):(e,t)=>t.total-e.total||qn(e.partner,t.partner));for(const e of s)e.edges.sort("target"===t?r:i);return s};for(const t of e){const e=o.outgoing[t.id],n=o.incoming[t.id];if(0===n.length)a(e,"target").forEach((e,t)=>{const o=t%2==0?"top":"bot";for(const t of e.edges)s.get(t.id).sourceSide=o});else if(0===e.length)a(n,"source").forEach((e,t)=>{const o=t%2==0?"top":"bot";for(const t of e.edges)s.get(t.id).targetSide=o});else{const t=a(n,"source"),o=a(e,"target"),i=Math.max(t.length,o.length);for(let e=0;i>e;e++){const n=e%2==0?"top":"bot";if(t[e])for(const o of t[e].edges)s.get(o.id).targetSide=n;if(o[e])for(const t of o[e].edges)s.get(t.id).sourceSide=n}}}return s}(e,t,m,i);let y={};for(const t of e)y[t.id]=hi(t,m,f,void 0,u);const b=Hi(e,t,y,m,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:g,ribbonLane:h,domain:p}),x=b.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),v=new Set;for(const e of t){const t=b.slotByNode[e.source],o=b.slotByNode[e.target];if(void 0===t||void 0===o)continue;const n=f.get(e.id);t!==o?t>o?(n.sourceSide="top",n.targetSide="bot"):(n.sourceSide="bot",n.targetSide="top"):(v.add(e.id),n.sourceSide="bot",n.targetSide="bot")}for(const t of e){const e=m.outgoing[t.id],o=m.incoming[t.id],n=new Set(e.map(e=>f.get(e.id).sourceSide)),i=new Set(o.map(e=>f.get(e.id).targetSide));if(1===n.size&&o.length>0){const e=[...n][0];for(const t of o)b.slotByNode[t.source]===b.slotByNode[t.target]&&(f.get(t.id).targetSide=e)}if(1===i.size&&e.length>0){const t=[...i][0];for(const o of e)b.slotByNode[o.source]===b.slotByNode[o.target]&&(f.get(o.id).sourceSide=t)}}!function(e,t,o){const n=new Map,i=[];for(const t of e)i.push({time:t.startTime,kind:"out",edge:t}),i.push({time:t.endTime,kind:"in",edge:t});i.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||qn(e.edge.id,t.edge.id));const r=e=>{let t=n.get(e);return t||(t={top:0,bot:0},n.set(e,t)),t},s=(e,t,o)=>{const n="top"===t?"bot":"top",i=Math.min(o,e[t]);e[t]-=i;const r=o-i;r>0&&(e[n]=Math.max(0,e[n]-r))};for(const e of i){const{edge:n}=e;if("in"===e.kind){const e=t.get(n.id)?.targetSide??"bot";r(n.target)[e]+=n.value;continue}const i=r(n.source),a=t.get(n.id);let l=a.sourceSide??"bot";if(o[n.source]===o[n.target]){const e=i.top>=n.value,t=i.bot>=n.value;e!==t?l=e?"top":"bot":e||t||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,n.value)}}(t,f,b.slotByNode),function(e,t,o,n){for(const i of e){const e=t.incoming[i.id],r=t.outgoing[i.id];if(0===e.length||0===r.length)continue;const s=()=>{const t={inTop:0,inBot:0,outTop:0,outBot:0};for(const n of e)"top"===o.get(n.id).targetSide?t.inTop+=n.value:t.inBot+=n.value;for(const e of r)"top"===o.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},a=(e,t)=>{const i=s(),a="top"===e?i.outTop-i.inTop:i.outBot-i.inBot,l="top"===t?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(t=>!n.has(t.id)&&o.get(t.id).sourceSide===e&&c>=t.value).sort((e,t)=>t.value-e.value||qn(e.id,t.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=t,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(e,m,f,v),y={};for(const t of e)y[t.id]=hi(t,m,f,void 0,u);const w=Hi(e,t,y,m,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:x,lanePlacement:"stack",groupPadding:g,ribbonLane:h,domain:p}),A=w.effectiveSlotsHeight??w.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((e,t,o)=>e+(null!=t.group&&t.group===w.slots[o+1].group?1:0),0),k=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*n-S*g)/k),_=2*M+Qn(w.slots,M,g).reduce((e,t)=>e+t,0),P=A>0?Math.max(0,(n-_)/A):1,T=Number.isFinite(l)&&l>0?Math.min(P,l):P;let L=Hi(e,t,y,m,{plotH:n,padding:M,valueScale:T,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:x,lanePlacement:c,groupPadding:g,ribbonLane:h,domain:p,stackValueScale:P});const R=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||R)&&L.slots.length>1&&(Pi(e,t,y,L.laneLifetime,L.slots,L.slotByNode,{plotH:n,padding:M,valueScale:T,groupPadding:g,laneOrder:s,ribbonLane:h,domain:p,lanePlacement:c,mode:"geometry-refine"}),L=Hi(e,t,y,m,{plotH:n,padding:M,valueScale:T,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:L.slots,fixedSlotOrder:L.slots.map(Un),lanePlacement:c,groupPadding:g,ribbonLane:h,domain:p,stackValueScale:P})),function(e,t){const o=(e,o)=>{for(const n of e){const e=new Map;for(const i of n){const n=`${("out"===o?t.get(i.id)?.sourceSide:t.get(i.id)?.targetSide)??""}\0${"out"===o?i.startTime:i.endTime}`,r="out"===o?`${i.target}\0${i.endTime}`:`${i.source}\0${i.startTime}`,s=e.get(n);if(null!=s&&s!==r)return!0;e.set(n,r)}}return!1};return o(Object.values(e.outgoing),"out")||o(Object.values(e.incoming),"in")}(m,f)){const o=function(e,t,o,n){const i=new Map;for(const r of e){const e=t[r.source]?.localAttachments.get(r.id),s=t[r.target]?.localAttachments.get(r.id),a=o[r.source],l=o[r.target];if(!(e&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=di(e,a,n),u=di(s,l,n);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(t,y,L.centerlines,T);y={};for(const t of e)y[t.id]=hi(t,m,f,o,u);L=Hi(e,t,y,m,{plotH:n,padding:M,valueScale:T,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:L.slots,fixedSlotOrder:L.slots.map(Un),lanePlacement:c,groupPadding:g,ribbonLane:h,domain:p,stackValueScale:P})}const I=new Map(b.initialSlotOrder.map((e,t)=>[e,t])),C=[...L.slots].sort((e,t)=>(I.get(Un(e))??1/0)-(I.get(Un(t))??1/0)||qn(Un(e),Un(t))),z={};C.forEach((e,t)=>{for(const o of e.occupants)z[o.id]=t});const F=ei(e,t,y,C,z,{plotH:n,padding:M,valueScale:T,stackValueScale:P,lanePlacement:"stack",groupPadding:g}),O=Vi(e,y,C,z,F.centerlines,T,g),B=li(wi(z,t),Ai(z,t),t,O,C,z,F.centerlines,L.laneLifetime,T,F.verticalUtilization,h,p);y=Vi(e,y,L.slots,L.slotByNode,L.centerlines,T,g);const N=li(wi(L.slotByNode,t),Ai(L.slotByNode,t),t,y,L.slots,L.slotByNode,L.centerlines,L.laneLifetime,T,L.verticalUtilization,h,p);return{nodeData:y,sides:f,valueScale:T,padding:M,compressedPadding:12>M,centerlines:L.centerlines,laneLifetime:L.laneLifetime,slots:L.slots,slotByNode:L.slotByNode,crossingsBefore:"insertion"===s?null:B.crossings,crossingsAfter:"insertion"===s?null:N.crossings,lengthBefore:"insertion"===s?null:B.weightedLength,lengthAfter:"insertion"===s?null:N.weightedLength,layoutQualityBefore:B,layoutQuality:N}}(t,P,{plotH:S,...h,ribbonLane:l,domain:n}),{centerlines:R,nodeData:I,valueScale:C}=L,z=i(x,v),F=[],O=[],B=0===c?new Map:function(e,t,o){const n=new Set(t.map(e=>e.target)),i=new Map(e.map(e=>[e.id,e])),r=new Map;for(const e of t){if(n.has(e.source))continue;const t=r.get(e.source)??[];t.push(e),r.set(e.source,t)}const s=new Map;for(const t of e){if(!t.group)continue;const e=s.get(t.group)??[];e.push(t),s.set(t.group,e)}const a=new Set;for(const[e,t]of s){const o=t.flatMap(e=>r.get(e.id)??[]),i=new Set(o.map(e=>e.startTime));o.length>0&&1===i.size&&t.every(e=>{const t=e.xExtent?.[0],i=o[0].startTime;return!n.has(e.id)&&(r.get(e.id)?.length??0)>0&&Number.isFinite(t)&&i>t})&&a.add(e)}const l=new Map;for(const[e,t]of r){const n=i.get(e);if(n?.group&&!a.has(n.group))continue;const r=n?.xExtent?.[0],s=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=s[0]?.startTime-1;let u=null;for(let e=0;s.length>e;){const t=s[e].startTime;let n=e+1;for(;s.length>n&&s[n].startTime===t;)n++;for(let t=e;n>t;t++){const e=s[t],n=Number.isFinite(r)&&e.startTime>r,i=Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime;if(!n&&!i)continue;let a=o[0];n&&(a=Math.max(a,r)),i&&(a=Math.max(a,e.systemInTime)),!n&&i&&Number.isFinite(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),e.startTime>a&&l.set(e.id,a)}u=t,e=n}}for(const[e,t]of s){if(!a.has(e))continue;const o=t.flatMap(e=>r.get(e.id)??[]);if(!o.every(e=>l.has(e.id))){for(const e of o)l.delete(e.id);continue}const n=Math.max(...o.map(e=>l.get(e.id)));for(const e of o)l.set(e.id,n)}return l}(t,P,n),N=new Map(t.filter(e=>e.group).map(e=>[e.id,e.group])),E=new Map;for(const e of P){const t=I[e.source]?.localAttachments.get(e.id),o=I[e.target]?.localAttachments.get(e.id);t&&o&&E.set(e.id,Gi(t,R[e.source],o,R[e.target],C,T,l,n,{minRun:c,sourceRunwayStart:B.get(e.id)}))}const j=function(e,t,o,n,i,r){const s=new Map(t),a=new Map;for(const t of e){const e=r?.get(t.source),o=null==e?"node:"+t.source:"group:"+e,n=a.get(o)??new Map,i=n.get(t.startTime)??[];i.push(t),n.set(t.startTime,i),a.set(o,n)}for(const e of a.values())for(const[r,a]of e){if(!a.some(e=>o.has(e.id)))continue;const e=a.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;const l=n(r),c=Math.min(...e.map(e=>e.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(e=>{const t=o.get(e.id);return null==t?l:Math.min(l,n(t))})),d=Math.min(l,Math.max(c,u));for(const e of a){const o=t.get(e.id),n=d+(o.tx-d)*("source"===i?.85:"target"===i?.15:.5);s.set(e.id,{...o,sx:d,cp1X:n,cp2X:n})}}return s}(P,E,B,T,l,N),$=function(e,t,o,n,i){const r=new Map;for(const s of e){if(!o.has(s.id))continue;const e=t.get(s.id);if(!e||e.sx>=n(s.startTime)-1e-9)continue;const a=i(e.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(P,j,B,T,e=>n[0]+e/A*(n[1]-n[0])),D=function(e,t,o){const n=new Map,i=new Map;for(const[e,t]of o??[]){const o=i.get(t)??[];o.push(e),i.set(t,o)}for(const r of e){const e=t.get(r.id);if(null==e||!Number.isFinite(e)||e>=r.startTime)continue;const s=o?.get(r.source),a=null==s?[r.source]:i.get(s)??[r.source];for(const t of a){const o=n.get(t)??new Map,i=o.get(r.startTime);o.set(r.startTime,null==i?e:Math.min(i,e)),n.set(t,o)}}return n}(P,$,N);t.forEach((e,t)=>{const o=I[e.id];if(!o||0===o.samples.length)return;const i=(r=o.samples,(s=D.get(e.id))&&0!==s.size?r.map(e=>{const t=s.get(e.t);return null==t?e:{...e,t:t}}):r);var r,s;const l=function(e,t,o,n,i){if(0===e.length)return null;const r=ui(e,i),s=e=>t+(r[e].boundaryOffset??0)*o,a=e=>s(e)-r[e].topMass*o,l=e=>s(e)+r[e].botMass*o;let c=`M${n(r[0].t)},${a(0)}`;for(let e=1;r.length>e;e++)c+=` L${n(r[e].t)},${a(e)}`;c+=` L${n(r[r.length-1].t)},${l(r.length-1)}`;for(let e=r.length-2;e>=0;e--)c+=` L${n(r[e].t)},${l(e)}`;return c+" Z"}(i,R[e.id],C,T,n);if(!l)return;const c=ui(i,n),u=c.find(e=>e.topMass+e.botMass>0)||c[0],h=R[e.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*C/2;let g,m,f=d(e.id,t),y=f,x=.5;const v=e.__raw??e;if(b&&b.length>0){const e=a(v,b,z(v));"string"==typeof e.fill?f=e.fill:null!=e.fill&&ht(e.fill)&&(m=e.fill,f=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:f),"string"==typeof e.stroke&&(y=e.stroke),"number"==typeof e.strokeWidth&&(x=e.strokeWidth),"number"==typeof e.fillOpacity&&(g=e.fillOpacity),"number"==typeof e.opacity&&null==g&&(g=e.opacity)}const w=function(e,t,o,n,i,r){const s=o.nodeData[e];if(!s||0===s.samples.length)return[];const a=o.valueScale,l=o.centerlines[e],c=ui(s.samples,i),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=n(u.t),p=n(d.t),g=e=>n(ci(e,i)),m=[],f=(e,t,o,n)=>`M${e},${t} L${o},${t} L${o},${n} L${e},${n} Z`;for(const o of t){if(o.source===e&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const e=s.localAttachments.get(o.id),t=r?.get(o.id)??o.startTime;if(e&&"out"===e.kind&&t>o.systemInTime){const n=g(o.systemInTime),r=g(t),s=null!=i&&i[0]>o.systemInTime,c=s?n:n-20,u=s?Math.min(r,n+20):n,d=Math.max(h,c);if(r>d){const[t,o]=di(e,l,a);m.push({pathD:f(d,t,r,o),x0:c,x1:u,from:0,to:1})}}}if(o.target===e&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const e=s.localAttachments.get(o.id);if(e&&"in"===e.kind&&o.systemOutTime>o.endTime){const t=g(o.systemOutTime),n=g(o.endTime),i=t+20,r=Math.min(p,i);if(r>n){const[o,s]=di(e,l,a);m.push({pathD:f(n,o,r,s),x0:t,x1:i,from:1,to:0})}}}}return m}(e.id,P,L,T,n,$);F.push({id:e.id,pathD:l,fill:f,stroke:y,strokeWidth:x,...null!=g&&{fillOpacity:g},...m&&{hatchFill:m},...w.length>0&&{gradientStubs:w},rawDatum:v,labelX:T("vertical"===p&&e.xExtent?e.xExtent[0]:u.t)-4,labelY:h,labelText:e.label??e.id})});const W=new Map;t.forEach((e,t)=>W.set(e.id,t)),P.forEach(e=>{const t=j.get(e.id);if(!t)return;const o=W.get(e.source)??0,n=d(e.source,o),{pathD:i,bezier:r}=H(t),s=e.__raw??e,a="function"==typeof u?Number(u(s)):u,l=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;O.push({id:e.id,pathD:i,fill:n,opacity:l,rawDatum:s,bezier:r})});const Y=function(e,t,o){const n=e.map(e=>({...e})),i=new Map;for(const e of n){const o=t[e.id];if(null==o)continue;const n=i.get(o)??[];n.push(e),i.set(o,n)}const r=e=>{if(2>e.length)return;const t=e.reduce((e,t)=>e+t.labelY,0)/e.length,n=(e.length-1)/2;e.forEach((e,i)=>{e.labelY=Math.max(8,Math.min(o-8,t+16*(i-n)))})};for(const e of i.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],o=-1/0;for(const n of e){const e=n.labelX-Xi(n.labelText);t.length>0&&e>o+3&&(r(t),t=[],o=-1/0),t.push(n),o=Math.max(o,n.labelX)}r(t)}return function(e,t){const o=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;3>e;e+=1){for(let e=0;o.length>e;e+=1){let t=8;for(let n=0;e>n;n+=1)Ui(o[e],o[n])&&(t=Math.max(t,o[n].labelY+16));o[e].labelY=Math.max(o[e].labelY,t)}for(let e=o.length-1;e>=0;e-=1){let n=t-8;for(let t=e+1;o.length>t;t+=1)Ui(o[e],o[t])&&(n=Math.min(n,o[t].labelY-16));o[e].labelY=Math.min(o[e].labelY,n)}}}(n,o),n}(F,L.slotByNode,S).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:Zi(e.pathD),gradientStubs:e.gradientStubs?.map(Ji),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,p)),V="vertical"===p?function(e,t,o){const n=e.map(e=>({...e}));for(const e of n){const o=1.22*Xi(e.labelText)+4;e.labelX=t-4>o?Math.max(o/2+2,Math.min(t-o/2-2,e.labelX)):t/2}const i=[],r=[...n].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(const e of r){const t=i[i.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?i.push([e]):t.push(e)}for(const e of i){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));const t=[],n=new Map;for(const o of e){const[e,i]=qi(o);let r=t.findIndex(t=>e>t+8);-1===r&&(r=t.length),t[r]=i,n.set(o,r)}const i=e.reduce((e,t)=>e+t.labelY,0)/e.length,r=14*t.length+8>i;for(const t of e){const e=n.get(t)??0;t.labelY=r?Math.min(o-8,12+14*e):Math.max(8,i-14*e)}}return n}(Y,r,s):Y,G=new Map;if(null!=m)for(const e of t){const t=e.__raw??e,o="function"==typeof m?m(t):Number(t[m]);Number.isFinite(o)&&G.set(e.id,o)}const X=function(e,t,o,n,i={}){if(!1===n)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===n)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(e.length,Math.floor(Math.max(1,t*o)/14e3)));Number.isFinite(i.maxLabels)&&i.maxLabels>=0&&(r=Math.min(r,Math.floor(i.maxLabels)));const s=e.map((e,t)=>{const o=i.priorityById?.get(e.id),n=Math.abs(e.labelY);return{band:e,index:t,score:null!=o&&Number.isFinite(o)?1e6*o+Xi(e.labelText):Xi(e.labelText)+.01*n}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),a=new Set(s.slice(0,r).map(e=>e.band.id));return e.map(e=>a.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(V,r,s,g,{...G.size>0&&{priorityById:G},...null!=f&&{maxLabels:f}});return{layout:L,layoutConfig:{bands:X,ribbons:O.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:Zi(e.pathD),bezier:Ki(e.bezier)}}(e,p)),showLabels:!1!==g,selectionDatum:y},issues:[],warnings:_,xScale:T}}import{Fragment as tr,jsx as or,jsxs as nr}from"react/jsx-runtime";var ir="var(--semiotic-grid, #94a3b8)",rr="var(--semiotic-text-secondary, #475569)",sr="var(--semiotic-text-secondary, #94a3b8)",ar=.22;function lr(e,t,o){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,o))}var cr=e=>{const{bands:t=[],ribbons:o=[],showLabels:n=!0,selectionDatum:i="raw"}=e.config,r=e.selection??null,s=[];for(const e of o){const t={__kind:"ribbon",data:e.rawDatum,id:e.id},o=!lr(t,r,i);s.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:o?Math.min(e.opacity,ar):e.opacity,stroke:"none"},datum:t})}for(const e of t){if(!e.gradientStubs)continue;const t=!lr({__kind:"band",data:e.rawDatum,id:e.id},r,i);for(let o=0;e.gradientStubs.length>o;o++){const n=e.gradientStubs[o];s.push({type:"bezier",pathD:n.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?ar:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:n.x0,x1:n.x1,...null!=n.y0&&{y0:n.y0},...null!=n.y1&&{y1:n.y1},from:n.from,to:n.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${o}`}})}}for(const e of t){const t=!(!e.gradientStubs||0>=e.gradientStubs.length),o={__kind:"band",data:e.rawDatum,id:e.id},n=!lr(o,r,i);s.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:e.hatchFill??e.fill,fillOpacity:n?ar:e.fillOpacity??.86},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...n&&t?{opacity:ar}:{}},datum:o})}const a=n?t.flatMap(e=>{const t=e.labelDeferred&&e.labelFullText?.trim(),o=e.labelText.trim().length>0,n=t&&r?.isActive&&lr({__kind:"band",data:e.rawDatum,id:e.id},r,i),s=o?e.labelText:n?e.labelFullText:"";return s.trim()?[{x:e.labelX,y:e.labelY,text:s,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:s,labels:a}};function ur(e,t){if(!e)return[];const o=[],n=e=>{o.push(e);const i="function"==typeof t?t(e):e[t];i&&Array.isArray(i)&&i.forEach(n)};return n(e),o}function dr(e,t,o,n){if(e&&e.length>0)return e;const i=new Set;return t.forEach(e=>{const t="function"==typeof o?o(e):e[o],r="function"==typeof n?n(e):e[n];i.add(t),i.add(r)}),Array.from(i).map(e=>({id:e}))}function hr(e,t,o={}){return Xt(t?"function"==typeof t?o=>({...e(o),...t(o)??{}}):o=>({...e(o),...t}):e,o)}var pr={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,n,i)=>{const r=function(e){if(void 0!==e.edgeStyle)return e.edgeStyle;const{edgeWidth:t,edgeColor:o,edgeOpacity:n}=e,i=e.strokeWidth??1;return void 0!==t||void 0!==o||void 0!==n||void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity?r=>{const s=r?.data||r;let a=i;if("number"==typeof t)a=t;else if("function"==typeof t)a=t(s);else if("string"==typeof t){const e=s?.[t],o="number"==typeof e?e:Number(e);a=Number.isFinite(o)&&o>0?o:i}return{stroke:o??e.stroke??"#999",strokeWidth:a,opacity:n??e.opacity??.6}}:void 0}(i),s=Kt(n.theme).colors.categorical,a=new Map,c=i.nodeStyle??(e=>({fill:t?le(e?.data||e,t,void 0):Ee(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),u=l(i.styleRules,t,"number"==typeof i.nodeSize?void 0:i.nodeSize),d=Xt(u?(e,t)=>({...c(e),...u(e,t)}):c,{stroke:i.nodeStroke??i.stroke,strokeWidth:i.nodeStrokeWidth??i.strokeWidth,opacity:i.opacity});return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:t,colorScheme:o,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:d,edgeStyle:r,...n}}},gr={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(e,t,o,n,i)=>{const r=e=>null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,p=i.systemOutTimeAccessor,g=i.xExtentAccessor||"xExtent",m=i.groupBy,f=i.edgeIdAccessor||"id",y=(e,t)=>"function"==typeof e?e(t):t[e],b=Array.isArray(i.edges)?i.edges:[],x=Array.isArray(i.nodes)?i.nodes:[],v=x.length>0?x:dr([],b,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],A=v.map(e=>{const t=y(c,e)+"",o=y(g,e),n=i.nodeLabel?y(i.nodeLabel,e):t,s={id:t,label:null==n?t:n+"",__raw:e},a=m?y(m,e):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(o)&&2===o.length){const e=r(o[0]),t=r(o[1]);Number.isFinite(e)&&Number.isFinite(t)&&(s.xExtent=[e,t])}return s}),S=b.map((e,t)=>{const o=y(f,e),n={id:null!=o?o+"":`${y(s,e)}-${y(a,e)}-${t}`,source:y(s,e)+"",target:y(a,e)+"",value:Number(y(l,e)),startTime:r(y(u,e)),endTime:r(y(d,e)),__raw:e};if(h){const t=r(y(h,e));Number.isFinite(t)&&(n.systemInTime=t)}if(p){const t=r(y(p,e));Number.isFinite(t)&&(n.systemOutTime=t)}return n}),[k,M]=n.size??[600,400],_=n.margin,P="vertical"===i.orientation?"vertical":"horizontal",T=function(e,t,o,n="horizontal"){return"vertical"===n?{top:e?38:t?28:16,right:24,bottom:24,left:o?72:24}:{top:e?30:t?24:8,right:80,bottom:o?28:8,left:80}}(!!n.title,!!i.showQualityReadout,Array.isArray(i.axisTicks)&&i.axisTicks.length>0,P),L={...T,..._},R=(n.showLegend??!!t)&&!!t,I=n.legendPosition??"right",C=n.__explicitMargin,z=e=>"number"==typeof C||null!=C&&"object"==typeof C&&null!=C[e];R&&("right"!==I||z("right")?"bottom"!==I||z("bottom")||(L.bottom=Math.max(L.bottom,80)):L.right=Math.max(L.right,140));const F=L,O=k-F.left-F.right,B=M-F.top-F.bottom,N=Kt(n.theme),E=Oe(o,N.colors.categorical,Pt),j="function"==typeof t?t:null,$=j?v.map(e=>({_cat:j(e)})):v,D=j?"_cat":"string"==typeof t?t:void 0,W=o??[...E],Y=D?J($,D,W):null,V=new Map;for(const e of A)V.set(e.id,e.__raw);const H=(e,o)=>{if(t&&V.has(e)){const o=V.get(e);return j?le({_cat:j(o)},"_cat",Y??void 0):le(o,"string"==typeof t?t:"id",Y??void 0)}return E[o%E.length]},G=R&&t?(()=>{const e=new Map;v.forEach((o,n)=>{const i=y(t,o),r=null==i?"":i+"";r&&!e.has(r)&&e.set(r,{label:r,color:H(y(c,o)+"",n)})});const o=Array.from(e.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:e=>{const t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,q=X(G,n.legend),U=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:Q,layoutConfig:Z,issues:K,xScale:ee}=er({nodes:A,edges:S,domain:w,plotW:O,plotH:B,orientation:P,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:H,showLabels:U,styleRules:i.styleRules,colorBy:t,valueAccessor:l,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half",maxValueScale:"number"==typeof i.maxValueScale?i.maxValueScale:void 0,lanePlacement:i.lanePlacement||"stack",nodeSizing:i.nodeSizing||"temporal",groupPadding:"number"==typeof i.groupPadding?i.groupPadding:0}});if(K.length>0){const e=K.map(Xn).join("; ");throw Error("ProcessSankey: data invalid — "+e)}const te=Q?function(e){const t=e.layout,o=e.nodes,n=e.orientation,i=e.plotW,r=e.plotH,s=e.timelineExtent,a=e.axisTicks,l=e.showQualityReadout??!1,c=e.showLaneRails??!1,u=(e.warnings??[]).slice(0,3),d=e.timeFormat,h=e.colorOf,p=e.toTime,g=e.xScale,{centerlines:m,laneLifetime:f,nodeData:y,valueScale:b,compressedPadding:x,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:A,layoutQuality:S}=t;let k=null,M=null;for(const e of o){const t=f[e.id];if(!t||null===t.start||null===t.end)continue;const o=g(t.start),n=g(t.end);(null===k||k>o)&&(k=o),(null===M||n>M)&&(M=n)}const _=e=>Math.max(0,Math.min(s,e)),P=_(k??0),T=Math.max(P,_(M??s)),L=a.map((e,t)=>({tick:e,index:t,coordinate:g(p(e.date))})).filter(({coordinate:e})=>e>=P-.5&&T+.5>=e),R=null!==(w??null)&&null!=A&&null!=S,I=l&&(R||u.length>0)?nr("g",{fill:sr,fontSize:10,textAnchor:"end",children:[R&&nr(tr,{children:[nr("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(A.pixelLength)," → ",Math.round(S.pixelLength)]}),nr("text",{x:i,y:-3,children:["transit: ",A.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),u.map((e,t)=>nr("text",{x:i,y:R?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},"warn-"+t))]}):null,C=x?or("text",{x:i,y:"vertical"===n?-3:2,fontSize:10,fill:sr,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,z=(e,t)=>h?h(e,t):ir;return nr("g","vertical"===n?{children:[I,C,L.map(({index:e,coordinate:t})=>or("line",{x1:0,y1:t,x2:i,y2:t,stroke:ir,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&o.map((e,t)=>{const o=f[e.id];if(!o||null===o.start)return null;const n=y[e.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=m[e.id]+(i.botPeak-i.topPeak)*b/2,s=g(o.start),a=g(o.end),l=z(e.id,t);return nr("g",{children:[or("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),or("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),or("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+e.id)}),or("line",{x1:-4,y1:P,x2:-4,y2:T,stroke:ir}),L.map(({tick:e,index:t,coordinate:o})=>{const n=p(e.date),i=null!=e.label?e.label:d?d(new Date(n)):"";return nr("g",{transform:`translate(-4,${o})`,children:[or("line",{x2:-6,stroke:ir}),or("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:rr,children:i})]},t)})]}:{children:[I,C,L.map(({index:e,coordinate:t})=>or("line",{x1:t,y1:0,x2:t,y2:r,stroke:ir,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&o.map((e,t)=>{const o=f[e.id];if(!o||null===o.start)return null;const n=y[e.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=m[e.id]+(i.botPeak-i.topPeak)*b/2,s=g(o.start),a=g(o.end),l=z(e.id,t);return nr("g",{children:[or("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),or("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),or("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+e.id)}),or("line",{x1:P,y1:r+4,x2:T,y2:r+4,stroke:ir}),L.map(({tick:e,index:t,coordinate:o})=>{const n=p(e.date),i=null!=e.label?e.label:d?d(new Date(n)):"";return nr("g",{transform:`translate(${o},${r+4})`,children:[or("line",{y2:6,stroke:ir}),or("text",{y:20,textAnchor:"middle",fontSize:11,fill:rr,children:i})]},t)})]})}({layout:Q,nodes:A,orientation:P,plotW:O,plotH:B,timelineExtent:"vertical"===P?B:O,axisTicks:Array.isArray(i.axisTicks)?i.axisTicks.map(e=>({date:e.date,label:e.label})):[],showQualityReadout:!!i.showQualityReadout,showLaneRails:!!i.showLaneRails,timeFormat:"function"==typeof i.timeFormat?e=>i.timeFormat(e):void 0,colorOf:H,toTime:e=>r(e),xScale:e=>Number(ee(e))}):void 0;return{chartType:"force",nodes:v,edges:b,customNetworkLayout:cr,layoutConfig:Z,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:t,colorScheme:o,...te&&{backgroundGraphics:te},...n,showLegend:R,...q&&{legend:q,legendPosition:I},__legendIncludesAutomatic:!0,margin:F}}},mr={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:dr([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=Kt(n.theme).colors.categorical,a=new Map,c="string"==typeof t?t:"__ssrSankeyColorBy",u="function"==typeof t?r.map(e=>({...e,__ssrSankeyColorBy:t(e)})):r,d=t?J(u,c,o??n.colorScheme??s):void 0,h=e=>({fill:t?le(e?.data||e,t,d):Ee(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),p=l(i.styleRules,t,i.valueAccessor),g=p?(e,t)=>({...h(e),...p(e,t)}):h,m=function({edgeColorBy:e,colorBy:t,colorScale:o,nodeStyleFn:n,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof e)a.fill=e(s);else if("source"===e){const e="object"==typeof s.source?s.source:null;t&&e?a.fill=le(e.data||e,t,o):e&&(a.fill=n(e,e.index).fill)}else if("target"===e){const e="object"==typeof s.target?s.target:null;t&&e?a.fill=le(e.data||e,t,o):e&&(a.fill=n(e,e.index).fill)}else"gradient"===e&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:t,colorScale:d,nodeStyleFn:g,edgeOpacity:i.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,valueAccessor:i.valueAccessor,orientation:i.orientation,nodeAlign:i.nodeAlign,nodeWidth:i.nodeWidth,nodePaddingRatio:i.nodePaddingRatio,showLabels:i.showLabels,nodeLabel:i.nodeLabel,colorBy:t,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:Xt(i.nodeStyle||g,Zt(i)),edgeStyle:Xt(i.edgeStyle||m,Zt(i)),colorScheme:o,...n}}},fr={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,n,i)=>{if(!(t||Array.isArray(i.styleRules)&&i.styleRules.length>0||n.nodeStyle||i.nodeStyle||Gt(Zt(i))))return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:t,edgeColorBy:i.edgeColorBy,colorScheme:o,...n};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:dr([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=Kt(n.theme).colors.categorical,c=Oe(o,a),u="string"==typeof t?t:"__ssrChordColorBy",d="function"==typeof t?s.map(e=>({...e,__ssrChordColorBy:t(e)})):s,h=t?J(d,u,o??n.colorScheme??a):void 0,p=new Map,g=i.nodeIdAccessor||i.nodeIDAccessor||"id",m=(e,o)=>{const n=e?.data||e;let r;if(t)r=le(n,t,h);else{const t=(e.id??n?.[g]??"")+"";p.has(t)||p.set(t,p.size);const i=e.index??o??p.get(t);r=c[i%c.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},f=l(i.styleRules,t,i.valueAccessor,m)??m;return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:t,edgeColorBy:i.edgeColorBy,colorScheme:o,nodeStyle:Xt(i.nodeStyle||f,Zt(i)),...n}}},yr={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,n,i)=>{const r=Kt(n.theme).colors.categorical,s=new Map,a=ur(e??null,i.childrenAccessor),l="function"==typeof t?t:null,c=l?a.map(e=>({__ssrTreeColorBy:l(e)})):a,u=l?"__ssrTreeColorBy":"string"==typeof t?t:void 0,d=t&&u?J(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"cluster"===i.layout?"cluster":"tree",data:e,childrenAccessor:i.childrenAccessor,colorBy:t,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:!1!==i.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:o,...n,nodeStyle:hr(e=>{const n=e?.data||e;return{fill:i.colorByDepth?C[Number(e?.depth||0)%C.length]:t?l?le({__ssrTreeColorBy:l(n)},"__ssrTreeColorBy",d??void 0):le(n,t,d??void 0):Ee(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,Zt(i))}}},br={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,n,i)=>{const r=Kt(n.theme).colors.categorical,s=new Map,a=ur(e??null,i.childrenAccessor),l="function"==typeof t?t:null,c=l?a.map(e=>({__ssrTreemapColorBy:l(e)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof t?t:void 0,d=t&&u?J(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,p=i.labelMode,g=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,m=void 0!==g?g:!h||"parent"!==p&&"all"!==p?void 0:18,f=n.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:e,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:t,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:p,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=m&&{paddingTop:m},colorScheme:o,...n,nodeStyle:hr(e=>{const n=e?.data||e;return{fill:i.colorByDepth?C[Number(e?.depth||0)%C.length]:t?l?le({__ssrTreemapColorBy:l(n)},"__ssrTreemapColorBy",d??void 0):le(n,t,d??void 0):Ee(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},f,Zt(i))}}},xr={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,o,n,i)=>{const r=Kt(n.theme).colors.categorical,s=new Map,a=ur(e??null,i.childrenAccessor),l="function"==typeof t?t:null,c=l?a.map(e=>({__ssrCirclePackColorBy:l(e)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof t?t:void 0,d=t&&u?J(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"circlepack",data:e,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:t,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:i.showLabels??n.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:o,...n,nodeStyle:hr(e=>{const n=e?.data||e;return{fill:i.colorByDepth?C[Number(e?.depth||0)%C.length]:t?l?le({__ssrCirclePackColorBy:l(n)},"__ssrCirclePackColorBy",d??void 0):le(n,t,d??void 0):Ee(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,Zt(i))}}},vr={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as wr}from"d3-scale";function Ar(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}var Sr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,o,n,i,r)=>{const s="string"==typeof n?n:"blues",a=r.areaStyle??function(e,t,o,n){if(!Array.isArray(e))return;const i=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0;let r=1/0,s=-1/0;for(const t of e){const e=i(t);null!=e&&isFinite(e)&&(r>e&&(r=e),e>s&&(s=e))}const a=wr(yt(o)).domain([Number.isFinite(r)?r:0,Number.isFinite(s)?s:1]);return e=>{const t=i(e);return{fill:null!=t&&isFinite(t)?a(t):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:n}}}(r.areas,r.valueAccessor,s,r.areaOpacity??1),l=r.styleRules?e(a,r.styleRules,e=>{return{value:(t=e,"function"==typeof r.valueAccessor?r.valueAccessor(t):null!=r.valueAccessor?t?.properties?.[r.valueAccessor]??t?.[r.valueAccessor]:void 0)};var t},Ar):a;return{areas:r.areas,projection:r.projection||"equalEarth",areaStyle:l,valueAccessor:r.valueAccessor,colorScheme:s,graticule:r.graticule,fitPadding:r.fitPadding,...i}}},kr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,o,n,r,s)=>{const a=t||s.points,l=s.pointStyle??function(e,t,o,n){const i=Array.isArray(e)?e:[];let r,s;if(t){const e="string"==typeof t?t:"__geoColorBy",n="string"==typeof t?i:i.map(e=>({...e,__geoColorBy:t(e)}));r=J(n,e,o)}if(n.sizeBy){const e=i.map("function"==typeof n.sizeBy?n.sizeBy:e=>e?.[n.sizeBy]).filter(e=>null!=e&&isFinite(e));e.length>0&&(s=Ot(e))}return e=>({fill:t&&r?le(e,t,r):R,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?de(e,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}(a,o,n,{sizeBy:s.sizeBy,sizeRange:s.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),c=s.styleRules?e(l,s.styleRules,i(o,s.sizeBy)):l;return{points:a,xAccessor:s.xAccessor||"lon",yAccessor:s.yAccessor||"lat",areas:s.areas,areaStyle:s.areaStyle||vr,pointStyle:c,sizeBy:s.sizeBy,colorBy:o,colorScheme:n,projection:s.projection||"equalEarth",graticule:s.graticule,fitPadding:s.fitPadding,...r}}},Mr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,o,n,i)=>{const r=(Array.isArray(e)?e:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:e=>e[l],d="function"==typeof c?c:e=>e[c],h=(i.nodes||[]).map(e=>({...e,x:u(e),y:d(e)})),p=new Map;for(const e of h)p.set(e[s]+"",e);const g=i.edgeColorBy??t,m="function"==typeof g,f=r.map(e=>{if(!e||null==e.source||null==e.target)return null;const t=p.get(e.source+""),o=p.get(e.target+"");return t&&o?{...e,coordinates:[{x:t.x,y:t.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),y="__flowMapEdgeColor",b=(()=>{if(!g)return null;if(m){const e=f.map(e=>({[y]:g(e)}));return J(e,y,o||"category10")}return J(f,g,o||"category10")})(),x=e=>g&&b?le(e,g,b):"#007bff";let v=1/0,w=-1/0;for(const e of f){const t=Number(e[a]??0);isFinite(t)&&(v>t&&(v=t),t>w&&(w=t))}const A=w>v?w-v:0,[S,k]=i.edgeWidthRange??[1,8],M=k-S,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:f,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||vr,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:o,lineStyle:e=>{const t=Number(e?.[a]),o=Number.isFinite(t)?t:v,n=S+Math.max(0,Math.min(1,A>0?(o-v)/A:0))*M;return{stroke:x(e),strokeWidth:n,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...n}}};import*as _r from"react";function Pr(e){const[t,o]=e,n=160>t||116>o,i=n?Math.min(12,Math.max(2,.08*t)):32,r=n?Math.min(8,Math.max(2,.12*o)):24,s=n?r:34;return{width:t,height:o,plot:{x:i,y:r,width:Math.max(1,t-2*i),height:Math.max(1,o-r-s)}}}function Tr(e){const t=(e??"")+"";if(!t)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let n=0;for(let e=0;t.length>e;e+=1)n=31*n+t.charCodeAt(e)>>>0;return o[n%o.length]}function Lr(e,t="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,s=i?r(o?.valueAccessor):void 0;return o=>{const r=o.datum,l=r&&e?"function"==typeof e?e(r,0):r[e]:void 0,c={fill:null==l?t:Tr(l),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&r&&Object.assign(c,a(r,n,{value:s?s(r):void 0,category:null==l?void 0:l+""})),c}}function Rr(e,t,o,n){return{fixedDt:1/120,maxSubsteps:8,colliders:t,observation:{chartType:o},kernel:{seed:e,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...n}}}function Ir(e,t,o){return"function"==typeof o?o(e,t):e[o]}function Cr(e){if(e instanceof Date){const t=e.getTime();return Number.isFinite(t)?t:null}const t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function zr(e,t,o){return Math.max(t,Math.min(o,e))}function Fr(e,t){const o=Cr(e);return null!=o&&o>0?o:t}function Or(e){return((e??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function Br(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}import{scaleLinear as Nr}from"d3-scale";import{scaleLinear as Er}from"d3-scale";function jr(e){const{count:t,idPrefix:o,wallThickness:n,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=e;return Array.from({length:t+1},(e,t)=>{const l=Math.min(r-1,a?.(t)??s),c=Math.max(1,r-l);return{id:`${o}-wall-${t}`,shape:{type:"aabb",x:i(t),y:l+c/2,width:n,height:c}}})}import{scaleLinear as $r}from"d3-scale";function Dr(e){if(Array.isArray(e)&&e.length>=2){const t=Cr(e[0]),o=Cr(e[1]);return null!=t&&null!=o?{x:t,y:o}:null}if(e&&"object"==typeof e){const t=e,o=Cr(t.x),n=Cr(t.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Wr(e){return Array.isArray(e)?e.map(Dr).filter(e=>null!=e):[]}function Yr(e,t,o){return"normalized"===o?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:zr(e.x,t.plot.x,t.plot.x+t.plot.width),y:zr(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Vr(e){let t=0;for(let o=1;e.length>o;o+=1)t+=Math.hypot(e[o].x-e[o-1].x,e[o].y-e[o-1].y);return t}function Hr(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};const o=zr(t,0,1)*Vr(e);let n=0;for(let t=1;e.length>t;t+=1){const i=e[t-1],r=e[t],s=Math.hypot(r.x-i.x,r.y-i.y);if(s>0){if(n+s>=o){const e=(o-n)/s;return{x:i.x+(r.x-i.x)*e,y:i.y+(r.y-i.y)*e}}n+=s}}return{...e[e.length-1]}}function Gr(e,t){const o=Hr(e,Math.max(0,t-.02)),n=Hr(e,Math.min(1,t+.02)),i=n.x-o.x,r=n.y-o.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function Xr(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}import{scaleLinear as qr}from"d3-scale";function Ur(e,t){const o=t.config??{},n=(t.sensors??[]).map(e=>({...e,sensor:!0})),i=[...t.colliders??[],...n],r=[...e.colliders??[],...o.colliders??[],...i];return{...e,...o,observation:{...e.observation,...o.observation},...r.length>0&&{colliders:r}}}function Qr(e){const t=os(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function Zr(e,t,o,n){return o?"function"==typeof o?o(e,t):e[o]??n:n}function Kr(e){return`gauntlet:${e}:core`}function Jr(e,t){return`gauntlet:${e}:positive:${t}`}function es(e,t,o){return`gauntlet:${e}:negative:${t}:${o}`}var ts={left:28,top:76,rightInset:30,thickness:8};function os(e){const t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return ts;const o=Math.max(1,Math.min(e.width,t)),n=Math.max(2,.04*e.width);return{left:n,top:Math.max(2,.08*t),rightInset:n,thickness:Math.max(1,Math.min(4,.04*o))}}function ns(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function is(e,t,o,n){const i=os(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,l=(e,t,o)=>t>o?(t+o)/2:Math.max(t,Math.min(o,e));return{x:l(e,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:l(t,s,a)}}function rs(e,t,o=1){const n=[...e].sort((e,t)=>e.localeCompare(t)),i=Math.max(0,n.indexOf(t));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*o}}function ss(e,t,o){const n=e.activePositiveIds.reduce((e,o)=>e+(t.get(o)?.value??1),0),i=e.missingPositiveIds.length+e.poppedPositiveIds.length,r=e.negativeIds.reduce((e,t)=>e+(o.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*n-8*r-1.2*e.delay-5*i))}function as(e){const t=function(e,t,o){const[n,i]=e,r=220>n||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,l=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,l.length),u=.22*n,d=c>1?(.78*n-u)/(c-1):0,h=r?Math.max(Math.round(.12*n),.08*n+6):Math.max(Math.round(.14*n),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*i)):o),floorY:a,gates:l.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(r?8:54,Math.round(.07*n))})),graveyardX:Math.round(n*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(n*(r?.82:.92)),startX:h,width:n}}(e.size??[900,520],e.gates,e.crashOffset??30),o=e.positiveProperties??[],n=new Map(o.map(e=>[e.id,e])),i=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),r={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},s=(e.data??[]).map((t,s)=>{const a=function(e,t,o,n,i){const r=Zr(e,t,o.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",s=n.map(e=>e.id),a=[...Zr(e,t,o.positiveAccessor,s)],l=[...Zr(e,t,o.negativeAccessor,[])].filter(e=>i.has(e));return{id:r,activePositiveIds:a,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Zr(e,t,o.metricsAccessor,{})},missingPositiveIds:s.filter(e=>!a.includes(e)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Zr(e,t,o.startTimeAccessor,0))||0),stage:"project filed",viability:Zr(e,t,o.initialViability,100)}}(t,s,r,o,i);return{...a,viability:e.viability?.(a,{negativeProperties:i,positiveProperties:n})??ss(a,n,i)}}),a=s.flatMap((o,r)=>{const s=function(e,t,o,n){const i=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(o),r=n?.(e,t,o)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(o,r,t,e.projectPlacement);return function(e,t,o,n,i,r,s){const a=ns(o),l=Math.max(3,28*a),c=n.startX,u=n.startY+(n.startY===o.routeY?38*t*a:0),d=s?.(e,t,o,n)??{},h=d.x??c,p=d.y??u,g={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},m=[{...d,id:Kr(e.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??e.startedAt,datum:g}],f=is(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,o);m[0].x=f.x,m[0].y=f.y;for(const t of e.activePositiveIds){const n=i.get(t);if(!n)continue;const r=rs(e.activePositiveIds,t,a),s=n.radius??Math.max(2,10*a),l=is(f.x+Math.cos(r.angle)*r.radius,f.y+Math.sin(r.angle)*r.radius,s,o);m.push({id:Jr(e.id,t),x:l.x,y:l.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:n.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:n,sourceDatum:e.datum},springs:!1===n.spring?[]:[{target:{type:"body",bodyId:Kr(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...n.spring??{}}]})}return e.negativeIds.forEach((t,n)=>{const i=r.get(t);i&&m.push(function(e,t,o,n,i,r,s){const a=ns(r),l=t.radius??Math.max(2,7.2*a),c=is(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,l,r);return{id:es(e.id,t.id,o),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Kr(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...t.spring??{}}]}}(e,i,n,f.x,f.y,o,d.spawnAt??e.startedAt))}),m}(o,r,t,s,n,i,e.coreBody)});return{layout:t,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:Qr(t)}}}var ls=1e-9;function cs(e,t){return t>e?-1:e>t?1:0}function us(e){return{...e}}function ds(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function hs(e){const t=Object.fromEntries(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:us(t.initialMetrics),metrics:us(t.metrics),productIds:[...t.productIds],history:ds(t.history)}])),o=Object.fromEntries(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:us(t.metrics),sourceIds:[...t.sourceIds],history:ds(t.history)}])),n=Object.fromEntries(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?us(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:o,relations:n,input:{amount:e.input.amount,metrics:us(e.input.metrics)},metrics:us(e.metrics),loss:{amount:e.loss.amount,metrics:us(e.loss.metrics)},history:ds(e.history)}}function ps(e,t,o,n,i){return{severity:e,code:t,message:o,path:n,ids:i?[...i]:void 0}}function gs(e){const t=new Set,o=new Set;for(const n of e)t.has(n)&&o.add(n),t.add(n);return[...o].sort(cs)}function ms(e,t){return e?Object.entries(e).flatMap(([e,o])=>Number.isFinite(o)?[]:[ps("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function fs(e,t){for(const[o,n]of Object.entries(t))e[o]=Number(e[o]??0)+n}function ys(e,t,o="selector"){const n=[],i=Object.values(e.components),r=new Set(i.map(e=>e.id)),s=(t.ids??[]).filter(e=>!r.has(e));if(s.length&&n.push(ps("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,o+".ids",s)),void 0===t.count||Number.isInteger(t.count)&&t.count>=0||n.push(ps("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),n.some(e=>"error"===e.severity))return{ids:[],diagnostics:n};const a=t.ids?new Set(t.ids):null,l=t.categories?new Set(t.categories):null,c=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null;let d=i.filter(e=>!a||a.has(e.id)).filter(e=>!l||l.has(e.category)).filter(e=>!c||c.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(cs);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||n.push(ps("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function bs(e,t,o={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...o}}function xs(e,t){const o={...t,eventId:e.event.id};e.materializations.push(o),e.observations.push({...o,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function vs(e,t,o){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(ps("error","unknown-outlet",`Unknown outlet "${t}".`,o,[t])),1))}function ws(e,t,o){const n=gs(t);t.length||e.diagnostics.push(ps("error","empty-source-list","A product requires at least one source component.",o)),n.length&&e.diagnostics.push(ps("error","duplicate-source",`Source ids may appear only once: ${n.join(", ")}.`,o,n));const i=t.filter(t=>!e.state.components[t]);i.length&&e.diagnostics.push(ps("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i));const r=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);r.length&&e.diagnostics.push(ps("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,o,r));const s=t.filter(t=>"consumed"===e.state.components[t]?.status&&!r.includes(t));return s.length&&e.diagnostics.push(ps("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,o,s)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function As(e,t,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>t+ls)&&e.diagnostics.push(ps("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),e.diagnostics.push(...ms(n?.metrics,i+".metrics"));for(const[t,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[t]??0)+ls)&&e.diagnostics.push(ps("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${i}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function Ss(e,t,o,n,i,r,s){return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:r&&void 0!==e.amount?e.amount:o,metrics:r&&e.metrics?{...n,...e.metrics}:n,status:r?"complete":"forming",sourceIds:[...t],outletId:r?e.outletId??(i.outletIds.has("product")?"product":void 0):void 0,createdByEventId:i.event.id,createdAt:i.context.appliedAt,completedByEventId:r?i.event.id:void 0,completedAt:r?i.context.appliedAt:void 0,history:[s]}}function ks(e,t,o,n){void 0!==t.amount&&Math.abs(t.amount-o)>ls&&e.diagnostics.push(ps("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${o}.`,n,[t.id]))}function Ms(e,t,o){const n=`events.${e.event.id}.effects.${o}`,i=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(ps("error","invalid-component-state",`set-state cannot assign "${t.state+""}".`,n+".state")),e.diagnostics.push(...ms(t.metricsDelta,n+".metricsDelta")),vs(e,t.outletId,n+".outletId");const o=ys(i,t.select,n+".select");e.diagnostics.push(...o.diagnostics);const r=o.ids.filter(e=>i.components[e].productIds.length);if(r.length&&e.diagnostics.push(ps("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,n+".select",r)),e.diagnostics.some(e=>"error"===e.severity))return;const s=bs(e,t,{sourceIds:o.ids,outletIds:t.outletId?[t.outletId]:void 0});for(const e of o.ids){const o=i.components[e];o.status=t.state,o.outletId=t.outletId,o.reason=t.reason,t.metricsDelta&&fs(o.metrics,t.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&xs(e,{type:"retarget-component",sourceIds:o.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){const{relation:o}=t;o.id&&!i.relations[o.id]||e.diagnostics.push(ps("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,n+".relation.id",[o.id]));const r=function(e,t,o){const n=gs(t),i=t.filter(t=>!e.state.components[t]);return 2>t.length&&e.diagnostics.push(ps("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&e.diagnostics.push(ps("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&e.diagnostics.push(ps("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,o.sourceIds,n+".relation.sourceIds");if(e.diagnostics.push(...ms(o.metrics,n+".relation.metrics")),!r||e.diagnostics.some(e=>"error"===e.severity))return;i.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?{...o.metrics}:void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};const s=bs(e,t,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void xs(e,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===t.type){const o=gs(t.relationIds),r=t.relationIds.filter(e=>!i.relations[e]),s=t.relationIds.filter(e=>"resolved"===i.relations[e]?.status);if(o.length&&e.diagnostics.push(ps("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&e.diagnostics.push(ps("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&e.diagnostics.push(ps("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,n+".relationIds",s)),e.diagnostics.some(e=>"error"===e.severity))return;for(const o of t.relationIds){const n=i.relations[o];n.status="resolved",n.resolution=t.resolution,n.resolvedByEventId=e.event.id,n.resolvedAt=e.context.appliedAt,n.reason=t.reason}const a=bs(e,t,{relationIds:[...t.relationIds]});return i.history.push(a),void xs(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){const o=e.productDefinitions.get(t.productId);o||e.diagnostics.push(ps("error","unknown-product",`Product "${t.productId}" has no declared mold.`,n+".productId",[t.productId]));const r=i.products[t.productId];"combine"===t.type&&r&&e.diagnostics.push(ps("error","duplicate-product",`Product "${t.productId}" has already been formed.`,n+".productId",[t.productId])),"contribute"!==t.type||r&&"forming"===r.status||e.diagnostics.push(ps("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,n+".productId",[t.productId]));const s=ws(e,t.sourceIds,n+".sourceIds"),a="contribute"===t.type&&r?[...r.sourceIds,...t.sourceIds]:t.sourceIds,l=function(e,t,o,n){if(!t?.length)return[];const i=gs(t),r=t.filter(t=>!e.state.relations[t]),s=t.filter(t=>"resolved"===e.state.relations[t]?.status),a=new Set(o),l=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!a.has(e)));return i.length&&e.diagnostics.push(ps("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&e.diagnostics.push(ps("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&e.diagnostics.push(ps("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),l.length&&e.diagnostics.push(ps("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,n,l)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,a,n+".basisRelationIds");if(!s||!l||!o||e.diagnostics.some(e=>"error"===e.severity))return;const c=s.reduce((e,t)=>e+t.amount,0),u=function(e){const t={};for(const o of e)fs(t,o.metrics);return t}(s);if(!As(e,c,u,t.loss,n+".loss"))return;const d=c-(t.loss?.amount??0);!function(e,t,o){e.state.loss.amount+=o?.amount??0;for(const[n,i]of Object.entries(o?.metrics??{}))t[n]=Number(t[n]??0)-i,e.state.loss.metrics[n]=Number(e.state.loss.metrics[n]??0)+i}(e,u,t.loss);const h="combine"===t.type&&!1!==t.complete,p=bs(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});let g;if("combine"===t.type){if(h&&ks(e,o,d,n+".productId"),g=Ss(o,t.sourceIds,d,u,e,h,p),h&&!vs(e,g.outletId,n+".productId"))return;i.products[t.productId]=g}else g=r,g.sourceIds.push(...t.sourceIds),g.amount+=d,fs(g.metrics,u),g.history.push(p);for(const e of s)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(p);return i.history.push(p),function(e,t){if(t.length){for(const o of t)o.status="resolved",o.resolution="combined",o.resolvedByEventId=e.event.id,o.resolvedAt=e.context.appliedAt;xs(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,l),xs(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:g.outletId?[g.outletId]:void 0}),void(h&&xs(e,{type:"complete-product",sourceIds:[...g.sourceIds],productIds:[g.id],outletIds:g.outletId?[g.outletId]:void 0}))}if("complete-product"===t.type){const o=i.products[t.productId];return o?void function(e,t,o,n,i,r){const s=e.productDefinitions.get(t.id),a=o??s?.outletId??(e.outletIds.has("product")?"product":void 0);if(!vs(e,a,r+".outletId"))return;if("complete"===t.status)return void e.diagnostics.push(ps("error","product-already-complete",`Product "${t.id}" is already complete.`,r,[t.id]));s&&(ks(e,s,t.amount,r+".productId"),void 0!==s.amount&&(t.amount=s.amount),s.metrics&&(t.metrics={...t.metrics,...s.metrics})),t.status="complete",t.outletId=a,t.reason=n,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;const l=bs(e,i,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0});t.history.push(l),e.state.history.push(l),xs(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:a?[a]:void 0})}(e,o,t.outletId,t.reason,t,n):void e.diagnostics.push(ps("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,n+".productId",[t.productId]))}if("split"===t.type){const o=ws(e,[t.sourceId],n+".sourceId");t.products.length||e.diagnostics.push(ps("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=t.products.map(e=>e.productId),s=gs(r);s.length&&e.diagnostics.push(ps("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(t=>e.productDefinitions.get(t)),l=r.filter((e,t)=>!a[t]),c=r.filter(e=>i.products[e]);l.length&&e.diagnostics.push(ps("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,n+".products",l)),c.length&&e.diagnostics.push(ps("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,n+".products",c));for(const[o,i]of t.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||e.diagnostics.push(ps("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),e.diagnostics.push(...ms(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||e.diagnostics.some(e=>"error"===e.severity))return;const u=o[0];if(!As(e,u.amount,u.metrics,t.loss,n+".loss"))return;const d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??a[t]?.amount),p=h.filter(e=>void 0!==e).length;if(0!==p&&p!==h.length)return void e.diagnostics.push(ps("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const g=p?h:t.products.map(()=>d/t.products.length),m=g.reduce((e,t)=>e+t,0);if(Math.abs(m-d)>ls)return void e.diagnostics.push(ps("error","split-amount-mismatch",`Split allocations total ${m}, but ${d} remains after loss.`,n+".products"));const f={...u.metrics};for(const[e,o]of Object.entries(t.loss?.metrics??{}))f[e]=Number(f[e]??0)-o;const y=bs(e,t,{sourceIds:[u.id],productIds:r});if(t.products.forEach((o,r)=>{const s=a[r],l=d>ls?g[r]/d:1/t.products.length,c=Object.fromEntries(Object.entries(f).map(([e,t])=>[e,t*l])),h=o.metrics??s.metrics??c,p=Ss({...s,amount:g[r],metrics:h},[u.id],g[r],{...h},e,!0,y);vs(e,p.outletId,`${n}.products.${r}.productId`)&&(i.products[p.id]=p)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(y),i.loss.amount+=t.loss?.amount??0;for(const[e,o]of Object.entries(t.loss?.metrics??{}))i.loss.metrics[e]=Number(i.loss.metrics[e]??0)+o;i.history.push(y),xs(e,{type:"split-source",sourceIds:[u.id],productIds:r});for(const t of r)xs(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:i.products[t].outletId?[i.products[t].outletId]:void 0});return}if("eject"===t.type){vs(e,t.outletId,n+".outletId");const o=ys(i,t.select,n+".select");e.diagnostics.push(...o.diagnostics);const r=o.ids.filter(e=>i.components[e].productIds.length);if(r.length&&e.diagnostics.push(ps("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,n+".select",r)),e.diagnostics.some(e=>"error"===e.severity))return;const s=bs(e,t,{sourceIds:o.ids,outletIds:[t.outletId]});for(const e of o.ids){const o=i.components[e];o.status=t.state??"ejected",o.outletId=t.outletId,o.reason=t.reason,o.history.push(s)}return i.history.push(s),void(o.ids.length&&xs(e,{type:"retarget-component",sourceIds:o.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...ms(t.metricsDelta,n+".metricsDelta")),e.diagnostics.some(e=>"error"===e.severity))return;let o,r;if("run"===t.target)fs(i.metrics,t.metricsDelta);else if("components"in t.target){const r=ys(i,t.target.components,n+".target.components");if(e.diagnostics.push(...r.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;o=r.ids;for(const e of r.ids)fs(i.components[e].metrics,t.metricsDelta)}else{r=[...t.target.productIds];const o=gs(r),s=r.filter(e=>!i.products[e]);if(o.length&&e.diagnostics.push(ps("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&e.diagnostics.push(ps("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,n+".target.productIds",s)),e.diagnostics.some(e=>"error"===e.severity))return;for(const e of r)fs(i.products[e].metrics,t.metricsDelta)}return void i.history.push(bs(e,t,{sourceIds:o,productIds:r}))}t.outcome.trim()?(i.outcome=t.outcome,i.summary=t.summary,i.history.push(bs(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(ps("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function _s(e,t,o){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[ps("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,"events."+t.id,[t.id])]};const n=hs(e),i={state:n,event:t,context:o,productDefinitions:new Map(o.products.map(e=>[e.id,e])),outletIds:new Set(o.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,n]of t.effects.entries())if(Ms(i,n,o),i.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:i.diagnostics};return n.elapsed=Math.max(n.elapsed,o.appliedAt),n.phaseId=o.phaseId,n.eventsApplied.push(t.id),i.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:n,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var Ps=[900,520],Ts=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],Ls=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Rs=1e-9;function Is(e,t){return t>e?-1:e>t?1:0}function Cs(e,t,o,n,i){return{severity:e,code:t,message:o,path:n,ids:i?[...i]:void 0}}function zs(e){const t=new Set,o=new Set;for(const n of e)t.has(n)&&o.add(n),t.add(n);return[...o].sort(Is)}function Fs(e){const t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Os(e,t,o,n,i,r){if(!o)return n;try{return("function"==typeof o?o(e,t):e[o])??n}catch(e){return i.push(Cs("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:e+""}.`,r)),n}}function Bs(e,t,o){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(Cs("error","invalid-metrics","Metrics must be a numeric object.",o)),{};const n={};for(const[i,r]of Object.entries(e)){const e=Fs(r);null!=e?n[i]=e:t.push(Cs("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function Ns(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function Es(e){const{id:t,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=e,u=function(e,t,o){const n=o.map(([o,n])=>[Math.max(e,Math.min(o,n)),Math.min(t,Math.max(o,n))]).filter(([e,t])=>t>e+Rs).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),i=[];let r=e;for(const[e,t]of n)e>r+Rs&&i.push([r,e]),r=Math.max(r,t);return t>r+Rs&&i.push([r,t]),i}(i,r,s);return u.map(([e,i],r)=>({id:1===u.length?t:`${t}:${r}`,friction:l,restitution:c,shape:"horizontal"===o?{type:"segment",x1:e,y1:n,x2:i,y2:n,thickness:a}:{type:"segment",x1:n,y1:e,x2:n,y2:i,thickness:a}}))}function js(e){let t=2166136261;for(let o=0;e.length>o;o+=1)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return t>>>0}function $s(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?js(e):1}function Ds(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:$s(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Ws(e){return"crucible:component:"+encodeURIComponent(e)}function Ys(e,t,o,n){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const i=Math.min(...t,e),r=Math.max(...t,e);return r-i>Rs?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,e-i)/(r-i)):(n[0]+n[1])/2}function Vs(e,t){const o=Math.max(.25,Math.min(1,t.width/900,t.height/520)),n=e?.[0]??7*o,i=e?.[1]??18*o,r=Math.max(1,Math.min(n,i));return[r,Math.max(r,Math.max(n,i))]}function Hs(e,t){if(!e)return[];const o=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),n=Math.max(1,Math.ceil(e/o));return Array.from({length:e},(e,i)=>({x:t.x+t.width/o*(i%o+.5),y:t.y+(Math.floor(i/o)+.5)*(t.height/n)}))}function Gs(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function Xs(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function qs(e,t,o={}){const n=Object.values(e.products).sort((e,t)=>Is(e.id,t.id)),i=Object.values(e.components).sort((e,t)=>Is(e.id,t.id)),r=[...i.map(e=>e.amount),...n.map(e=>e.amount)],s=Vs(o.radiusRange,t),a=function(e,t){const o=new Map;for(const t of e){const e=t.outletId??"__chamber__",n=o.get(e)??[];n.push(t),o.set(e,n)}const n=new Map;for(const[e,i]of o){i.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||Is(e.id,t.id));const o=Hs(i.length,Xs(t,"__chamber__"===e?void 0:e));i.forEach((e,t)=>n.set(e.id,o[t]))}return n}(n,t),l=n.map(e=>{const n=a.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},i=1.28*Ys(e.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:(c=e.id,"crucible:product:"+encodeURIComponent(c)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const e of i.filter(e=>!e.productIds.length)){const t=Gs(e)??"__chamber__",o=c.get(t)??[];o.push(e),c.set(t,o)}const u=new Map;for(const[e,o]of c){const n=Hs(o.length,Xs(t,"__chamber__"===e?void 0:e));o.forEach((e,t)=>u.set(e.id,n[t]))}return[...i.map(e=>{let n=u.get(e.id);if(e.productIds.length){const o=e.productIds.map(e=>a.get(e)).filter(e=>!!e);if(o.length){n={x:o.reduce((e,t)=>e+t.x,0)/o.length,y:o.reduce((e,t)=>e+t.y,0)/o.length};const i=js(e.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*t.width));n={x:n.x+Math.cos(i)*r,y:n.y+Math.sin(i)*r}}}n??(n={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});const i=Ys(e.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Ws(e.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var Us=qs;function Qs(e){return Array.isArray(e)?e.map(Qs):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>Is(e,t)).map(([e,t])=>[e,Qs(t)])):e}function Zs(e,t=e.duration){const o=function(e,t){const o=Fs(t)??0,n=Math.max(0,Math.min(e.duration,o));if(!e.phases.length)return{elapsed:n,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=n>=e.duration-Rs,r=i?e.phases[e.phases.length-1]:e.phases.find(e=>n>=e.start&&e.end>n)??e.phases[0];return{elapsed:n,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,n-r.start),complete:i}}(e,t);let n=hs(e.initialState);const i=[],r=[],s=[];for(const t of e.events){if(t.authoredAt>o.elapsed+Rs)break;const a=_s(n,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});i.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(n=a.state)}return n.elapsed=o.elapsed,n.phaseId=o.phaseId,n.phaseIndex=o.phaseIndex,n.phaseElapsed=o.phaseElapsed,n.complete=o.complete,o.complete&&"in_process"===n.outcome&&(n.outcome="complete"),n.playing=!1,{state:n,diagnostics:i,materializations:r,observations:s}}function Ks(e){const t=function(e){const t=[];e.length||t.push(Cs("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=zs(e.map(e=>e.id));o.length&&t.push(Cs("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:e.map((e,o)=>{const i=Fs(e.duration),r=null!=i&&i>0?i:0;e.id.trim()||t.push(Cs("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||t.push(Cs("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[e.id])),void 0===e.intensity||Number.isFinite(e.intensity)||t.push(Cs("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.intensity`,[e.id]));const s={...e,duration:r,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:o,start:n,end:n+r};return n=s.end,s}),diagnostics:t}}(e.phases),o=t.phases.at(-1)?.end??0,n=Ns(e.outlets??Ts),i=(e.products??[]).map(e=>({...e,metrics:e.metrics?{...e.metrics}:void 0})),r=function(e,t,o){const n=[],i=zs(e.map(e=>e.id));i.length&&n.push(Cs("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return e.forEach((e,i)=>{let s,a,l;if(e.id.trim()||n.push(Cs("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in e.at&&void 0!==e.at.time){const r=Fs(e.at.time);if(null==r||0>r||r>o+Rs)return void n.push(Cs("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${i}.at.time`,[e.id]));s=Math.max(0,Math.min(o,r));const c=function(e,t,o){const n=e.find(e=>Rs>=Math.abs(e.start-o));if(n)return{phase:n,boundaryRank:1};const i=e.find(e=>o>=e.start&&e.end>o);return i?{phase:i,boundaryRank:0}:Rs>=Math.abs(o-t)&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,o,s);a=c.phase,l=c.boundaryRank}else{if(a=t.find(t=>t.id===e.at.phaseId),!a)return void n.push(Cs("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${i}.at.phaseId`,[e.id,e.at.phaseId]));const o=e.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void n.push(Cs("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${i}.at.progress`,[e.id]));s=a.start+a.duration*o,l=0===o?1:0}a?r.push({...e,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):n.push(Cs("error","event-without-phase","Event could not be assigned to a phase.",`events.${i}.at`,[e.id]))}),r.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:r,diagnostics:n}}(e.events??[],t.phases,o),s=function(e){const t=[],o={},n=[];let i=0;const r={};e.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((Os(s,a,e.idAccessor,l,t,`data.${a}.id`)??l)+"").trim();if(!c)return void t.push(Cs("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(c);const u=Fs(Os(s,a,e.amountAccessor,1,t,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&t.push(Cs("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=Bs(Os(s,a,e.metricsAccessor,{},t,`data.${a}.metrics`),t,`data.${a}.metrics`),p=Os(s,a,e.initialStateAccessor,"active",t,`data.${a}.status`),g=Ls.has(p)?p:"active";Ls.has(p)||t.push(Cs("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[c]));const m=Os(s,a,e.labelAccessor,(s.label??s.name??c)+"",t,`data.${a}.label`)+"",f=Os(s,a,e.categoryAccessor,"component",t,`data.${a}.category`)+"";o[c]||(o[c]={id:c,label:m,category:f,datum:s,status:g,initialAmount:d,amount:d,initialMetrics:{...h},metrics:{...h},productIds:[],history:[]},i+=d,function(e,t){for(const[o,n]of Object.entries(t))e[o]=Number(e[o]??0)+n}(r,h))});const s=zs(n);s.length&&t.push(Cs("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=Bs(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:o,products:{},relations:{},input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:t}}(e),a=function(e=Ps,t=Ts){const o=Math.max(1,Fs(e[0])??900),n=Math.max(1,Fs(e[1])??520),i=360>o||260>n,r=i?Math.max(4,.035*Math.min(o,n)):20,s=i?Math.max(10,.075*n):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},l=i?Math.max(16,.14*n):Math.min(78,.16*n),c={x:r,y:n-r-l,width:Math.max(1,o-2*r),height:l},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),p={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},g=Math.max(18,Math.min(.32*p.width,i?84:180)),m={x:p.x+(p.width-g)/2,y:p.y-(i?10:24),width:g,height:i?12:28},f=Ns(t),y={left:f.filter(e=>"left"===(e.side??"bottom")),right:f.filter(e=>"right"===e.side),bottom:f.filter(e=>"bottom"===(e.side??"bottom"))},b=[],x=(e,t)=>{const n=Math.max(8,u-1.5*r),s=p.height/Math.max(1,t.length);t.forEach((t,a)=>{b.push({...t,side:e,x:"left"===e?r:o-r-n,y:p.y+a*s,width:n,height:Math.max(8,s-(i?2:8))})})};x("left",y.left),x("right",y.right);const v=p.width/Math.max(1,y.bottom.length);return y.bottom.forEach((e,t)=>{b.push({...e,side:"bottom",x:p.x+t*v,y:p.y+p.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-p.y-p.height-(i?4:12))})}),b.sort((e,t)=>f.findIndex(t=>t.id===e.id)-f.findIndex(e=>e.id===t.id)),{width:o,height:n,phaseRail:a,chamber:p,mouth:m,projection:c,outlets:b}}(e.size??Ps,n),l=function(e){const{chamber:t,mouth:o}=e,n=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),i=Math.max(t.x,o.x),r=Math.min(t.x+t.width,o.x+o.width),s={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:i,y2:t.y,thickness:n}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:n}}];a.push(...Es({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:s.left.map(e=>[e.y,e.y+e.height]),thickness:n,friction:.46,restitution:.12}),...Es({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:s.right.map(e=>[e.y,e.y+e.height]),thickness:n,friction:.46,restitution:.12}),...Es({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:s.bottom.map(e=>[e.x,e.x+e.width]),thickness:n,friction:.5,restitution:.08}));for(const t of e.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(t.id),sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return a}(a),c=function(e,t){const o=[],n=new Set(t.map(e=>e.id)),i=zs(t.map(e=>e.id)),r=zs(e.map(e=>e.id));return i.length&&o.push(Cs("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(Cs("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),t.forEach((e,t)=>{e.id.trim()||o.push(Cs("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0===e.order||Number.isFinite(e.order)||o.push(Cs("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||o.push(Cs("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0===e.amount||Number.isFinite(e.amount)&&e.amount>=0||o.push(Cs("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0===e.outletId||n.has(e.outletId)||o.push(Cs("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Bs(e.metrics??{},o,`products.${t}.metrics`)}),o}(i,n),u=(d={seed:e.seed??1,components:Object.values(s.state.components).sort((e,t)=>Is(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})=>({id:e,duration:t,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:n,events:r.events.map(({id:e,label:t,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:e,label:t,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(Qs(d)));var d;const h=function(e,t,o={}){const n=Object.values(e.components).sort((e,t)=>Is(e.id,t.id)),i=n.map(e=>e.amount),r=Vs(o.radiusRange,t),s=function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}($s(o.seed)),a=t.mouth.x+t.mouth.width/2,l=t.chamber.y+Math.max(18,.18*t.chamber.height),c=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return n.map((e,t)=>{const d=t/Math.max(1,n.length)*Math.PI*2+.18*(s()-.5),h=Ys(e.amount,i,o.bodyRadius,r),p={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Ws(e.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}(s.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),p=[...t.diagnostics,...r.diagnostics,...s.diagnostics,...c],g={phases:t.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:Ds(e.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:p},m=Zs(g),f=Object.values(m.state.products).filter(e=>"forming"===e.status).map(e=>e.id),y=f.length?[Cs("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${f.join(", ")}.`,"events",f)]:[];return g.terminalState=m.state,g.terminalSpawns=Us(m.state,a,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),g.diagnostics=[...p,...m.diagnostics,...y],g}import*as Js from"react";import{jsx as ea,jsxs as ta}from"react/jsx-runtime";function oa(e){return Number.isFinite(e)?1e3>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):e.toLocaleString():"0"}function na(e,t,o,n){const i=e.datum;if(!i?.__crucible)return;const r="circle"===e.shape.type?e.shape.radius:8,s="string"==typeof t.fill?t.fill:"product"===i.kind?"#b8792d":"#356b63",a="string"==typeof t.stroke?t.stroke:"#26323a",l="number"==typeof t.strokeWidth?t.strokeWidth:1.25,c="number"==typeof t.opacity?t.opacity:.96,u=n?`${n}-crucible-body-${o}`:"crucible-body-"+o;if("product"===i.kind){const t=Array.from({length:6},(t,o)=>{const n=-Math.PI/2+o/6*Math.PI*2;return`${e.x+Math.cos(n)*r},${e.y+Math.sin(n)*r}`}).join(" "),o=u+"-glow";return ta(Js.Fragment,{children:[ea("defs",{children:ea("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:ea("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),ea("polygon",{points:t,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${o})`}),ea("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return ta(Js.Fragment,{children:[ea("circle",{cx:e.x,cy:e.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),ea("circle",{cx:e.x-.25*r,cy:e.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as ia,jsx as ra,jsxs as sa}from"react/jsx-runtime";var aa="var(--semiotic-text, #26323a)",la="var(--semiotic-text-secondary, #6c7377)",ca="var(--semiotic-primary, #b8792d)",ua="var(--semiotic-danger, #9f3d35)",da="var(--semiotic-success, #356b63)";function ha(e){const{x:t,y:o,width:n,height:i}=e.chamber,r=Math.min(.14*n,48),s=o+i;return[`M ${t} ${o}`,`L ${t+r} ${s-.16*i}`,`Q ${t+n/2} ${s+.1*i} ${t+n-r} ${s-.16*i}`,`L ${t+n} ${o}`].join(" ")}function pa({layout:e,phases:t,state:o,compact:n=!1}){const i=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return sa("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[sa("defs",{children:[sa("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[ra("stop",{offset:"0",stopColor:ca,stopOpacity:"0.03"}),ra("stop",{offset:"0.66",stopColor:ca,stopOpacity:"0.1"}),ra("stop",{offset:"1",stopColor:ua,stopOpacity:"0.18"})]}),ra("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:ra("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:aa,strokeOpacity:"0.08",strokeWidth:"1"})})]}),ra("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:aa,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),ra("path",{d:ha(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),ra("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:aa,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:ra("g",{"data-testid":"crucible-phase-rail",children:t.map((n,r)=>{const s=t.slice(0,r).reduce((e,t)=>e+Math.max(0,t.duration),0),a=e.phaseRail.x+s/i*e.phaseRail.width,l=Math.max(0,n.duration)/i*e.phaseRail.width,c=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return sa("g",{children:[ra("rect",{x:a,y:e.phaseRail.y,width:Math.max(1,l-2),height:e.phaseRail.height,rx:2,fill:c?n.color??ca:u?da:aa,fillOpacity:c?.68:u?.28:.09}),46>l?null:ra("text",{x:a+l/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:c?aa:la,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),e.outlets.map(e=>sa("g",{children:[ra("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?ua:da),fillOpacity:"0.1",stroke:e.color??("left"===e.side?ua:da),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:ra("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:la,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function ga({rows:e,layout:t,projection:o,amountLabel:n}){if(!e.length)return null;const i=o.measure??"count",r=e.map(e=>Math.max(0,function(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}(e,i))),s=Math.max(1,...r),a=t.projection.width/Math.max(1,e.length),l=t.projection.height>48?21:4,c=Math.max(5,t.projection.height-l-5);return ra("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,o)=>{const u=r[o],d=Math.max(u>0?2:0,u/s*c),h=t.projection.x+o*a+.18*a;return sa("g",{children:[ra("rect",{x:h,y:t.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?ua:"complete"===e.status?ca:da,fillOpacity:"0.68"}),l>4&&a>=34?sa(ia,{children:[ra("text",{x:h+.32*a,y:t.projection.y+c+10,fill:la,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?e.label.slice(0,12)+"…":e.label}),sa("text",{x:h+.32*a,y:t.projection.y+c+19,fill:aa,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[oa(u),"amount"===i&&n?" "+n:""]})]}):null]},e.key)})})}function ma(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function fa(e){return e.map(e=>({...e,spawnAt:void 0}))}function ya(e,t){return e?t?o=>_r.createElement(_r.Fragment,null,e,"function"==typeof t?t(o):t):e:t}var ba=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function xa(e){let t=2166136261;for(let o=0;e.length>o;o+=1)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return ba[(t>>>0)%ba.length]}var va={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,o,n,i)=>({chartType:"line",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||t,colorAccessor:t,...n,showAxes:!1,margin:n.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:Go,LineChart:qo,AreaChart:Qo,DifferenceChart:Zo,StackedAreaChart:Ko,Scatterplot:en,CandlestickChart:Jo,BubbleChart:Ho,ConnectedScatterplot:on,QuadrantChart:tn,Heatmap:nn,TemporalHistogram:Uo,XYCustomChart:{frameType:"xy",buildProps:(e,t,o,n,i)=>({chartType:"custom",data:e,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:t,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:n.showLegend??!!t})},BarChart:Pn,StackedBarChart:Tn,GroupedBarChart:Ln,PieChart:Rn,DonutChart:In,Histogram:Cn,BoxPlot:zn,ViolinPlot:Fn,SwarmPlot:On,DotPlot:Bn,SwimlaneChart:Nn,RidgelinePlot:En,LikertChart:jn,FunnelChart:$n,GaugeChart:Dn,OrdinalCustomChart:{frameType:"ordinal",buildProps:(e,t,o,n,i)=>({chartType:"custom",data:e,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:t,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},ForceDirectedGraph:pr,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,o,n,i)=>({chartType:"force",nodes:i.nodes||e||[],edges:i.edges||[],nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor||"id",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",valueAccessor:i.valueAccessor||"value",colorBy:t,colorScheme:o,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...n})},SankeyDiagram:mr,ProcessSankey:gr,ChordDiagram:fr,TreeDiagram:yr,Treemap:br,CirclePack:xr,ChoroplethMap:Sr,ProportionalSymbolMap:kr,FlowMap:Mr,GeoCustomChart:{frameType:"geo",buildProps:(e,t,o,n,i)=>({points:i.points||e||[],areas:i.areas||[],lines:i.lines||[],projection:i.projection||"equirectangular",xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",lineDataAccessor:i.lineDataAccessor,colorBy:t,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n})},GaltonBoardChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,a=i.seed??1,l=Math.max(1,Math.round(i.pegRows??s-1)),c="mechanical"===i.mode,u=c?function(e){const t=Math.max(2,Math.round(e.bins)),o=Math.max(1,Math.round(e.pegRows??t-1)),n=Math.max(1,Math.round(e.count??Math.max(64,4*t))),i=zr(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),r=Br(e.seed??1),s=e.idPrefix??"mechanical";return Array.from({length:n},(e,t)=>{let n=0;for(let e=0;o>e;e+=1)r()<i&&(n+=1);const a=o/2;return{id:`${s}-${t}`,value:n,mechanical:!0,pegRows:o,branchProbability:i,pathRights:n,side:a>n?"left":n>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:l,seed:a}):Array.isArray(e)?e:[],d=function(e){const{data:t,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:a}=e,l=Pr(s),c=t.map((e,t)=>Cr(Ir(e,t,o))).filter(e=>null!=e),u=function(e){if(!e)return;const t=Cr(e[0]),o=Cr(e[1]);return null!=t&&null!=o?t>o?[o,t]:[t,o]:void 0}(a),d=u?.[0]??(c.length?Math.min(...c):0),h=u?.[1]??(c.length?Math.max(...c):1),p=h===d?1:h-d,g=Nr().domain([0,n]).range([l.plot.x,l.plot.x+l.plot.width]),y=Array.from({length:n},()=>0),b=[];t.forEach((e,t)=>{const r=Cr(Ir(e,t,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-d)/p*n)));y[s]+=1,b.push({id:(e.id??"galton-"+t)+"",x:g(s+.5),y:l.plot.y+i+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...e,value:r,bin:s}})});const x=l.plot.y+l.plot.height;return{config:Rr(r,[...m({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...f({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:g,yTop:l.plot.y-400,yBottom:x,wallThickness:6})],"GaltonBoardChart"),initialSpawns:b,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:y.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:n,plot:l.plot,valueExtent:[d,h]}}}({data:u,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:a,size:r,valueExtent:c?[0,l]:void 0});return{...n,config:d.config,initialSpawns:fa(d.initialSpawns),projectionRows:d.projectionRows,bodyStyle:Lr(t||i.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[600,400],s=function(e){const{data:t,timeAccessor:o,arrivalAccessor:n,windows:i,watermark:r,ballRadius:s,seed:a,size:l,timeExtent:c,timeScale:u=1}=e,d=Pr(l),h=t.map((e,t)=>Cr(Ir(e,t,o))).filter(e=>null!=e),p=Cr(c?.[0]),g=Cr(c?.[1]),f=h.length?Math.min(...h):0,y=h.length?Math.max(...h):f+i.size,b=Math.min(p??f,f),x=Math.max(g??y,y),v=Math.floor(b/i.size)*i.size,w=Math.max(1,Math.ceil((x-v+i.size)/i.size)),A=h.length?Math.max(...h):0,S="function"==typeof r?r(A):Cr(r?.value)??A-(r?.delay??i.size),k=Math.max(0,Math.min(w,Array.from({length:w},(e,t)=>t).reduce((e,t)=>v+(t+1)*i.size>S?e:e+1,0))),M=function(e,t){const o=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:o,height:e.plot.height},windowPlot:{x:e.plot.x+o,y:e.plot.y,width:Math.max(40,e.plot.width-o),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(d,s),_=v+w*i.size,P=Er().domain([v,_]).range([M.windowPlot.x,M.windowPlot.x+M.windowPlot.width]),T=Array.from({length:w},()=>({value:0,secondary:0})),L=[];t.forEach((e,t)=>{const r=Cr(Ir(e,t,o));if(null==r)return;const a=Cr(Ir(e,t,n))??r,l=Math.max(0,Math.min(w-1,Math.floor((r-v)/i.size))),c=S>=v+(l+1)*i.size;T[l].value+=c?0:1,T[l].secondary+=c?1:0,L.push({id:(e.id??"event-"+t)+"",x:Math.max(M.windowPlot.x+s,Math.min(M.windowPlot.x+M.windowPlot.width-s,P(r))),y:d.plot.y+s+2,vx:8*(t%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...e,eventTime:r,arrivalTime:a,windowIndex:l,late:c}})});const R=d.plot.y+d.plot.height,I=function(e,t){const o=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!o)return[];const n=e.windowStart,i=e.windowStart+e.windowCount*e.windowSize,r=Er().domain([n,i]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),s=r(e.windowStart+o*e.windowSize),a=e.windowPlot.x,l=t+Math.max(18,Math.min(.3*e.windowPlot.height,s-a)),c=e=>s===a?t:l+(e-a)/(s-a)*(t-l),u=[];for(let t=0;o>t;t+=1){const o=e.windowStart+t*e.windowSize,n=o+e.windowSize,i=r(o),s=r(n);u.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:i,y1:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:k,gutter:M.gutter,plot:d.plot,windowCount:w,windowPlot:M.windowPlot,windowSize:i.size,windowStart:v},d.plot.y+.28*d.plot.height);return{config:Rr(a,[...m({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...jr({idPrefix:"eventdrop-window",count:w,xScale:e=>P(v+e*i.size),yTop:M.wallTop,yTopForIndex:e=>{const t=(e=>{if(0>e||e>k)return null;const t=0===e?I[0]?.y1:I[e-1]?.y2??I[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?M.wallTop:t+1.25*s},yBottom:R,wallThickness:6}),...I.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:L,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>e.datum?.arrivalTime,timeScale:u},projectionRows:T.map((e,t)=>({label:`${v+t*i.size}-${v+(t+1)*i.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:k,gutter:M.gutter,lidSegments:I,lateCount:T.reduce((e,t)=>e+t.secondary,0),plot:d.plot,windowPlot:M.windowPlot,watermarkValue:S,windowCount:w,windowSize:i.size,windowStart:v}}}({data:Array.isArray(e)?e:[],timeAccessor:i.timeAccessor||"time",arrivalAccessor:i.arrivalAccessor||"arrivalTime",windows:i.windows||{size:10},watermark:i.watermark,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r,timeExtent:i.timeExtent,timeScale:i.timeScale??1});return{...n,config:s.config,initialSpawns:fa(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:Lr(t||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,a=function(e){const{data:t,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:a}=e,l=Fr(i,1),c=Pr(a),u=[],d=new Map,h=new Map,p=[];function g(e){let t=d.get(e);return null==t&&(t=u.length,u.push(e),d.set(e,t)),t}t.forEach((e,t)=>{g((Ir(e,t,o)??"unknown")+"")});const f=Math.max(1,u.length),y=function(e,t,o){const n=e.width/Math.max(1,t),i=Math.max(2,2*o),r=Math.min(.7*n,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:n,tubeWidth:r,ballDiameter:i,perRow:s,centerX:t=>e.x+(t+.5)*n,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*i}}(c.plot,f,r),b=Math.max(0,y.tubeWidth/2-r-1),x=u.map(()=>[]);t.forEach((e,t)=>{const i=(Ir(e,t,o)??"unknown")+"",s=g(i),a=n?Cr(Ir(e,t,n)):1,u=Math.max(0,Math.round((a??0)/l)),d=y.centerX(s);for(let o=0;u>o;o+=1){const n=h.get(i)??0,a=y.perRow>1?((y.perRow>1?n%y.perRow:0)/(y.perRow-1)*2-1)*b:0;h.set(i,n+1),x[s].push({id:`${(e.id??"pile-"+t)+""}-${o}`,x:d+a,y:c.plot.y+r+2,vx:(o%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...e,category:i,unitIndex:o}})}});const v=x.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;v>e;e+=1)for(const t of x)t.length>e&&p.push(t[e]);const w=c.plot.y+c.plot.height,A=[...m({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],S=c.plot.y-400;for(let e=0;f>e;e+=1){const t=y.centerX(e);for(const o of[-1,1])A.push({id:`pile-tube-${e}-${0>o?"l":"r"}`,shape:{type:"aabb",x:t+o*y.tubeWidth/2,y:(S+w)/2,width:6,height:w-S}})}return{config:Rr(s,A,"UnitPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(e=>({label:e,value:h.get(e)??0}))}}({data:s?function(e={}){const t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>(e+"").trim()).filter(Boolean),o=t.length?t:["Intake"],n=Math.max(o.length,Math.round(e.count??Math.max(48,12*o.length))),i=Fr(e.unitValue,1),r=Br(e.seed??1),s=e.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),l=a.reduce((e,t)=>e+t,0)||1,c=n-o.length,u=a.map(e=>e/l*c),d=u.map(e=>1+Math.floor(e));let h=n-d.reduce((e,t)=>e+t,0);const p=u.map((e,t)=>({index:t,fraction:e-Math.floor(e)})).sort((e,t)=>t.fraction-e.fraction);for(let e=0;h>0;e=(e+1)%p.length)d[p[e].index]+=1,h-=1;return o.map((e,t)=>({id:`${s}-${t}`,category:e,value:d[t]*i,mechanical:!0,unitCount:d[t],unitValue:i,share:d[t]/n}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(e)?e:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...n,config:a.config,initialSpawns:fa(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:Lr(t||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[600,360],s=function(e){const{data:t,xAccessor:o,groupAccessor:n,radiusAccessor:i,pointRadius:r,seed:s,size:a,xExtent:l,collisionIterations:c,settle:u}=e,d=Pr(a),h=Br(s),p=[],g=[],f=new Map;t.forEach((e,t)=>{const s=Cr(Ir(e,t,o));if(null==s)return;const a=n?(Ir(e,t,n)??"All")+"":"All",l=i?Cr(Ir(e,t,i)):null,c=zr(null!=l&&l>0?l:r,2,18);!function(e){let t=f.get(e);null==t&&(t=g.length,g.push(e),f.set(e,t))}(a),p.push({datum:e,index:t,value:s,group:a,radius:c})});const y=p.map(e=>e.value),b=l?Cr(l[0]):null,x=l?Cr(l[1]):null,v=y.length?Math.min(...y):0,w=y.length?Math.max(...y):1;let A=b??v,S=x??w;if(A===S&&(A-=.5,S+=.5),A>S){const e=S;S=A,A=e}const k=Math.max(r,...p.map(e=>e.radius)),M=d.plot.x+k+8,_=d.plot.x+d.plot.width-k-8,P=$r().domain([A,S]).range([M,_]),T=Math.max(1,g.length),L=Math.min(Math.max(28,3*k),d.plot.height/4),R=d.plot.y+L,I=Math.max(0,d.plot.y+d.plot.height-L-R),C=e=>{const t=f.get(e)??0;return 1===T?d.plot.y+.54*d.plot.height:R+t/(T-1)*I},z=new Map,F=p.map((e,t)=>{z.set(e.group,(z.get(e.group)??0)+1);const o=P(e.value),n=C(e.group),i=(h()-.5)*e.radius*1.6,r=(h()-.5)*e.radius*1.6;return{id:(e.datum.id??"collision-swarm-"+t)+"",x:u?o+i:zr(o+(t%9-4)*e.radius*2.5,M,_),y:u?n+r:d.plot.y-18-t%12*e.radius,vx:u?0:22*(h()-.5),vy:u?0:24+18*h(),mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:o,targetY:n},springs:[{target:{type:"point",x:o,y:n},restLength:0,stiffness:34,damping:5.5}]}});return{config:Rr(s,m({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*k),collisionIterations:Math.max(1,Math.round(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:F,projectionRows:g.map(e=>({label:e,value:z.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[A,S],xRange:[M,_],groups:g.map(e=>({label:e,y:C(e),count:z.get(e)??0})),plot:d.plot}}}({data:Array.isArray(e)?e:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...n,config:s.config,initialSpawns:fa(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:Lr(t||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[900,420],s=Array.isArray(i.stages)?i.stages:[],a=function(e){const t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=e.size,n=Pr(o),i=zr(e.ballRadius??6,2,18),r=e.seed??1,s=Br(r),a=e.idAccessor,l=e.stageAccessor??"stage",c=e.groupBy,u=e.groupLabelAccessor,d=e.workAccessor,m=e.radiusAccessor,f=e.groupCompletion??(c?"allAbsorbed":"none"),y=e.springStiffness??.28,v=e.springDamping??.72,w=!0===e.settle,A=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),S=_({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,n.plot.x),padY:Math.max(36,n.plot.y+8),stages:A,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),P=new Map(S.stages.map((e,t)=>[e.id,t])),L=new Map(S.stages.map(e=>[e.id,e])),R=S.stages[0].id,I=S.stages[0],C=new Set(t.filter(e=>e.absorb).map(e=>e.id)),z=t.map(e=>{const t=L.get(e.id)??I;return function(e,t){const o={id:"process-stage-"+e.id,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return h({...o,kind:e.kind??"sink",force:Xr(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(e.portal){const t=e.portal.force??e.force??{x:-40,y:0};return k({...o,kind:e.kind??"force-field",force:Xr(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){const t=Math.max(.1,e.capacity.unitsPerSecond);return g({...o,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Xr(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...o.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){const t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return M({...o,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:Xr(e.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?T({...o,kind:e.kind??"force-field",force:Xr(e.force,14),damping:e.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):b({...o,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(e,{x:t.x,y:S.midY,width:t.width,height:S.bottomY-S.topY})});z.unshift(T({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(S.left+S.right)/2,y:S.midY,width:S.right-S.left,height:S.bottomY-S.topY-12,force:8,damping:.012,semanticItem:!1}));const F=new Map;for(const e of S.stages)F.set(e.id,0);const O=[];e.data.forEach((e,t)=>{const o=(a?Ir(e,t,a)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",n=(Ir(e,t,l)??R)+"",r=P.has(n)?n:R;F.set(r,(F.get(r)??0)+1);const s=c?(Ir(e,t,c)??"")+"":void 0,h=s&&u?(Ir(e,t,u)??s)+"":s,p=d?Cr(Ir(e,t,d))??1:1,g=m?Cr(Ir(e,t,m)):null,f=zr(null!=g&&g>0?g:i,2,18);O.push({datum:e,id:o,stageId:r,groupId:s||void 0,groupLabel:h||void 0,work:p,radius:f,index:t})});const B=new Map,N=new Map;for(const e of O){if(!e.groupId)continue;const t=B.get(e.groupId)??[];t.push(e.id),B.set(e.groupId,t),e.groupLabel&&N.set(e.groupId,e.groupLabel)}const E=zr(e.groupAnchorAlong??.55,.15,.9),j=S.left+(S.right-S.left)*E,$=Array.from(B.keys()),D=$.map((e,o)=>{const n=B.get(e)??[],i=$.length>1?S.topY+28+o/Math.max(1,$.length-1)*(S.bottomY-S.topY-56):S.midY;return p({id:e,label:N.get(e)??e,bodyIds:n,anchor:{x:j,y:i},x:j,y:i,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),W=O.filter(e=>C.has(e.stageId)).map(e=>e.id),Y=x(D,W),V=new Map(D.map(e=>[e.id,e])),H=O.map((e,t)=>{const o=L.get(e.stageId)??I,n=o.x+(s()-.5)*Math.min(24,.2*o.width),i=S.boundaryY(n,"top")+e.radius+10,r=S.boundaryY(n,"bottom")-e.radius-10,a=r>i?i+s()*Math.max(1,r-i):S.midY,l=w?n:S.left+18+t%7*4,c=w?a:S.midY+(s()-.5)*(S.bottomY-S.topY)*.35,u=[{target:{type:"point",x:n,y:a},restLength:.45*e.radius,stiffness:y,damping:v}];if(e.groupId){const t=V.get(e.groupId);t?.anchor&&!C.has(e.stageId)&&u.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:l,y:c,vx:w?0:40+40*s(),vy:w?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:w?0:.03*t,springs:u,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),G={kernel:{seed:r,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:S.colliders,fixedDt:1/60,maxSubsteps:8},X=S.stages.map(e=>({label:e.label??e.id,value:F.get(e.id)??0})),q=t.map(e=>{const t=L.get(e.id)??I;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:F.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:G,initialSpawns:H,initialSpawnPacing:w?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:X,metadata:{kind:"process-flow",plot:n.plot,volume:S,stages:q,groups:D,groupCompletion:Y,regionEffects:z}}}({data:Array.isArray(e)?e:[],stages:s,size:r,idAccessor:i.idAccessor,stageAccessor:i.stageAccessor||"stage",groupBy:i.groupBy,groupLabelAccessor:i.groupLabelAccessor,workAccessor:i.workAccessor,radiusAccessor:i.radiusAccessor,ballRadius:i.ballRadius??6,seed:i.seed??1,groupCompletion:i.groupCompletion,groupAnchorAlong:i.groupAnchorAlong,settle:i.settle??!0,gravityX:i.gravityX,gravityY:i.gravityY}),l=a.metadata;return{...n,config:a.config,initialSpawns:fa(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:l?.regionEffects,bodyStyle:Lr(t||i.colorBy||i.groupBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.workAccessor||i.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[900,520],s=as({data:Array.isArray(e)?e:[],size:r,gates:i.gates,positiveProperties:i.positiveProperties,negativeProperties:i.negativeProperties,crashOffset:i.crashOffset,idAccessor:i.idAccessor,positiveAccessor:i.positiveAccessor,negativeAccessor:i.negativeAccessor,metricsAccessor:i.metricsAccessor,initialViability:i.initialViability,projectPlacement:i.projectPlacement,coreBody:i.coreBody,viability:i.viability});return{...n,config:s.config,initialSpawns:fa(s.initialSpawns),projectionRows:[],bodyStyle:Lr(t||i.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[900,520],s=Ks({data:Array.isArray(e)?e:[],phases:Array.isArray(i.phases)?i.phases:[],products:Array.isArray(i.products)?i.products:void 0,outlets:Array.isArray(i.outlets)?i.outlets:void 0,events:Array.isArray(i.events)?i.events:void 0,idAccessor:i.idAccessor,labelAccessor:i.labelAccessor,categoryAccessor:i.categoryAccessor,amountAccessor:i.amountAccessor,metricsAccessor:i.metricsAccessor,initialStateAccessor:i.initialStateAccessor,metrics:i.metrics,size:r,seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange}),a="snapshot"===i.playback?function(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,Fs(t)??0));const o=e.phases.find(e=>e.id===t.phaseId);if(!o)return e.duration;const n=Math.max(0,Math.min(1,Fs(t.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,l=Zs(s,a).state,c=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(e,t={}){const o=t.groupBy??"outlet",n=new Map,i=e=>{const t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},o),i=n.get(t);if(i)return i.count+=1,i.amount+=e.amount,void fs(i.metrics,e.metrics);n.set(t,{key:t,label:"product"===o&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:{...e.metrics},status:"status"===o?e.status:void 0,outletId:"outlet"===o?e.outletId:void 0,category:"category"===o?e.category:void 0,productId:"product"===o&&"product"===e.kind?e.id:void 0})};for(const t of Object.values(e.components))t.productIds.length||"consumed"===t.status||i({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(const t of Object.values(e.products))i({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});const r=new Map((t.order??[]).map((e,t)=>[e,t]));return[...n.values()].sort((e,t)=>(r.get(e.key)??Number.MAX_SAFE_INTEGER)-(r.get(t.key)??Number.MAX_SAFE_INTEGER)||cs(e.key,t.key))}(l,c),d=c.measure??"count",h=function(e,t={}){const o=t.bodies??[],n=Math.max(0,t.recentBodyLimit??6),i=new Map;for(const e of o){const o=t.getContainerId?.(e);if(!o)continue;const n=i.get(o);n?n.push(e):i.set(o,[e])}const r=e.map(e=>{const o=i.get(e.id)??[],r=Math.max(0,Math.floor(e.count??o.length)),s=o.slice(Math.max(0,o.length-n)).map(e=>({id:e.id,label:t.getBodyLabel?.(e)??ma(e),datum:e.datum}));return{id:e.id,label:e.label,count:r,share:0,secondary:e.secondary,secondaryLabel:e.secondaryLabel,observed:e.observed,bodyIds:o.map(e=>e.id),recentBodies:s,metadata:e.metadata}}),s=r.reduce((e,t)=>e+t.count,0);return r.map(e=>({...e,share:s>0?e.count/s:0}))}(u.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===d||"amount"===d?e.amount:Number(e.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),p={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},g=t??i.colorBy??"category",m=!1===i.showChrome?null:_r.createElement(pa,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),f=!1===i.showProjection?null:_r.createElement(ga,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:fa(qs(l,s.layout,p)),projectionRows:h,bodyStyle:e=>function(e,t,o,n){const i=e.datum,r={stroke:n.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:n.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:n.opacity??.96};if(!i?.__crucible)return{...r,fill:n.color??"#b8792d"};if("product"===i.kind){const e=t.products[i.semanticId];return{...r,fill:n.color??e?.color??xa(e?.id??i.semanticId)}}const s=t.components[i.semanticId];if(!s)return{...r,fill:n.color??"#356b63"};let a;return a="status"===o?s.status:"outlet"===o?s.outletId??"in chamber":"product"===o?s.productIds[0]??"unalloyed":"category"===o||null==o?s.category:"function"==typeof o?(o(s.datum)??"unassigned")+"":(s.datum[o+""]??"unassigned")+"",{...r,fill:n.color??xa(a)}}(e,l,g,i),getBodyLabel:e=>function(e,t){const o=e.datum;if(o?.__crucible)return"product"===o.kind?t.products[o.semanticId]?.label:t.components[o.semanticId]?.label}(e,l),renderBodySVG:na,backgroundGraphics:ya(m,n.backgroundGraphics),foregroundGraphics:ya(f,n.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[760,420],s=function(e){const{coordinateMode:t,flowSpeed:o,links:n,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:p,seed:g,size:f,sourceAccessor:y,targetAccessor:b,throughputAccessor:x}=e,v=Pr(f),w=Br(g),A=new Map,S=new Map,k=[];function M(e){if(e&&"object"==typeof e){const t=e;if("function"==typeof r){const e=r(t,0);if(null!=e)return e+""}if("string"==typeof r&&null!=t[r])return t[r]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}l.forEach((e,t)=>{const o=(Ir(e,t,r)??e.id??t)+"",n=Cr(Ir(e,t,s)),i=Cr(Ir(e,t,a));if(null!=n&&null!=i){const e={x:n,y:i};A.set(o,e),k.push(e)}S.set(o,(e.label??e.name??o)+"")});const _=[];n.forEach((e,t)=>{const o=M(Ir(e,t,y)),n=M(Ir(e,t,b)),i=Math.max(0,Cr(Ir(e,t,x))??0),r=Wr(d?Ir(e,t,d):void 0),s=r.length?r:Wr(e.path??e.points??e.route);s.forEach(e=>k.push(e)),_.push({id:(e.id??`physical-flow-${o}-${n}-${t}`)+"",link:e,index:t,source:o,target:n,throughput:i,rawPath:s})});const P=(L=k,"normalized"===(T=t)||"pixels"===T?T:L.length>0&&L.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels");var T,L;const R=new Map;for(const[e,t]of A)R.set(e,Yr(t,v,P));const I=[];for(const e of _){let t=e.rawPath.map(e=>Yr(e,v,P));if(2>t.length){const o=R.get(e.source),n=R.get(e.target);o&&n&&(t=[o,n])}else R.has(e.source)||R.set(e.source,t[0]),R.has(e.target)||R.set(e.target,t[t.length-1]);t.length>=2&&e.throughput>0&&(S.has(e.source)||S.set(e.source,e.source),S.has(e.target)||S.set(e.target,e.target),I.push({...e,path:t,packetCount:0}))}const C=Fr(u,.12),z=Math.max(1,Math.round(i)),F=I.map(e=>Math.max(1,Math.round(e.throughput*C))),O=F.reduce((e,t)=>e+t,0),B=O>z?z/O:1;I.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(F[t]*B))});let N=I.reduce((e,t)=>e+t.packetCount,0);for(;N>z;){const e=I.reduce((e,t,o)=>t.packetCount>1&&(-1===e||t.packetCount>I[e].packetCount)?o:e,-1);if(-1===e)break;I[e].packetCount-=1,N-=1}const E=new Map,j=new Map,$=[],D=Fr(o,90),W=Fr(c,4);I.forEach((e,t)=>{E.set(e.target,(E.get(e.target)??0)+e.throughput),j.set(e.source,(j.get(e.source)??0)+e.throughput);const o=Vr(e.path);for(let n=0;e.packetCount>n;n+=1){const i=(n+.5)/e.packetCount,r=p?i:zr(.12+.84*i+.04*(w()-.5),.04,.98),s=p?r:Math.max(0,r-(.18+.12*w())),a=Hr(e.path,s),l=Hr(e.path,r),c=Gr(e.path,s),u={x:-c.y,y:c.x},d=(w()-.5)*W*1.5;$.push({id:`${e.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:p?0:c.x*D+10*(w()-.5),vy:p?0:c.y*D+10*(w()-.5),mass:.8,spawnAt:p?0:.04*t+n/32,shape:{type:"circle",radius:W},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:n,packetCount:e.packetCount,routeProgress:r,flowPath:e.path,flowPathLength:o,flowRouteId:e.id,flowSpeed:D,sourceLabel:S.get(e.source)??e.source,targetLabel:S.get(e.target)??e.target},springs:"none"!==h&&p?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const Y=Math.max(18,5*W),V=Array.from(R,([e,t])=>({nodeId:e,label:S.get(e)??e,sensorId:"physical-flow-node-"+Or(e),point:t})),H=V.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:Y,height:Y}})),G=Object.fromEntries(V.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),X=Rr(g,[...m({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...H],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*W),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});X.bodyLimit=z,X.eviction="oldest",X.observation={...X.observation,sensors:G};const q=Array.from(R,([e,t])=>({id:e,label:S.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+Or(e),incoming:E.get(e)??0,outgoing:j.get(e)??0})),U=I.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:S.get(e.source)??e.source,targetLabel:S.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:X,initialSpawns:$,projectionRows:q.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:P,particleCount:$.length,totalThroughput:I.reduce((e,t)=>e+t.throughput,0),plot:v.plot,nodes:q,links:U}}}({nodes:Array.isArray(i.nodes)?i.nodes:[],links:Array.isArray(i.links)?i.links:Array.isArray(i.edges)?i.edges:Array.isArray(e)?e:[],nodeIdAccessor:i.nodeIdAccessor||"id",nodeXAccessor:i.nodeXAccessor||"x",nodeYAccessor:i.nodeYAccessor||"y",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",throughputAccessor:i.throughputAccessor||"value",pathAccessor:i.pathAccessor||"path",coordinateMode:i.coordinateMode||"auto",particleRate:i.particleRate??.16,maxParticles:i.maxParticles??180,particleRadius:i.particleRadius??4,flowSpeed:i.flowSpeed??90,pathConstraint:i.pathConstraint||"path",reducedMotion:!0,seed:i.seed??1,size:r});return{...n,config:s.config,initialSpawns:fa(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:Lr(t||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(e,t,o,n,i)=>{const r=n.size??[700,380],s=function(e){const t=function(e,t,o){const n=e?.observation;return{...e,observation:{...n,chartId:t??n?.chartId??"physics-custom",chartType:n?.chartType??"PhysicsCustomChart",onObservation:o??n?.onObservation}}}(e.config,e.chartId,e.onObservation),o=Ne(e.colorScheme,e.themeCategorical,Pt),n=Pr(e.size),i={data:e.data,scales:{x:qr().domain(e.xExtent??[0,1]).range([n.plot.x,n.plot.x+n.plot.width]),y:qr().domain(e.yExtent??[0,1]).range([n.plot.y+n.plot.height,n.plot.y])},dimensions:n,theme:{semantic:e.semantic,categorical:[...o]},resolveColor:V(o,e.colorScheme),config:e.layoutConfig??{},world:new d(t)},r=e.skipLayout?{}:e.layout(i)??{},s=function(e,t){if(!t?.length)return e;const o=new Map;for(const e of t){const{bodyId:t,...n}=e,i=o.get(t)??[];i.push(n),o.set(t,i)}return e.map(e=>{const t=o.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:Ur(t,r),context:i,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:i.chartId,colorScheme:o,config:i.config,data:Array.isArray(e)?e:[],layout:i.layout,layoutConfig:i.layoutConfig,semantic:Dt(Et)??{},size:r,themeCategorical:Et.colors.categorical,xExtent:i.xExtent,yExtent:i.yExtent});return{...n,config:s.config,initialSpawns:fa(s.initialSpawns),projectionRows:[],bodyStyle:s.result.bodyStyle??Lr(t||i.colorBy)}}}};function wa(e){const t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Aa(e){if(!e||2>e.length)return;const t=wa(e[0]),o=wa(e[e.length-1]);return null!==t&&null!==o?[t,o]:void 0}function Sa(e){const{count:t,byType:o}=function(e){const t={};for(const o of e){const e="string"==typeof o?.type&&o.type.length>0?o.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),n=0===t,i=[...e.extraWarnings??[]];n&&!i.includes("EMPTY_SCENE")&&i.push("EMPTY_SCENE");const r=e.margin,s=r?{x:r.left,y:r.top,width:e.width-r.left-r.right,height:e.height-r.top-r.bottom}:void 0;return{component:"",frameType:e.frameType,status:n?"empty":"ok",empty:n,markCount:t,markCountByType:o,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:Array.isArray(e.annotations)?e.annotations.length:0,ariaLabel:"string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${t} marks`,warnings:i,...r?{margin:r}:{},...s?{plot:s}:{}}}import*as ka from"react";import*as Ma from"react-dom/server";import{scaleOrdinal as _a}from"d3-scale";import{jsx as Pa,jsxs as Ta}from"react/jsx-runtime";var La=I;function Ra(e,t,o){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;return t=>$e(e,t)??"#999"}const n=Array.isArray(t)?t:o.colors.categorical.length>0?o.colors.categorical:Pt;return _a().domain(e).range(n)}function Ia(e,t,o){if(0===e.length)return;const n=Ra(e,t,o);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:n(e.label)})}]}}function Ca(e){return"left"===e?"start":"right"===e?"end":e??"start"}function za(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function Fa(e,t,o,n){const i=za(n);return t+o+Math.ceil(e.length*i*.58)}function Oa(e){const{categories:t,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=e,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=Ye(s),d=a+l,h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right),g=t.map(e=>Fa(e,a,l,o));if(h){const e=Math.max(a,s?.maxWidth??p),o=[];let n=0,i=0;g.forEach((t,r)=>{const s=0===i?t:i+c+t;i>0&&s>e?(o.push({start:n,end:r,width:i}),n=r,i=t):i=s}),t.length>0&&o.push({start:n,end:t.length,width:i});const r=Ca(s?.align),l=[];return o.forEach((o,n)=>{let i="center"===r?Math.max(0,(e-o.width)/2):"end"===r?Math.max(0,e-o.width):0;for(let e=o.start;o.end>e;e++)l.push({category:t[e],width:g[e],x:i,y:n*u}),i+=g[e]+c}),{items:l,width:Math.max(0,...o.map(e=>e.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const m=Math.max(0,...g);return{items:t.map((e,t)=>({category:e,width:g[t],x:0,y:t*u})),width:m,height:t.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function Ba(e){const{legendGroups:t,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=e,{swatchSize:a,labelGap:l,rowHeight:c}=Ye(s),u=a+l,d=Math.max(12,za(o)),h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??p),i=Ca(s?.align);let r=0,l=0;const c=[];for(const i of t){const t=i.items.map(e=>e.label),u=Oa({...e,categories:t,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,p=i.label?Fa(i.label,0,0,o):0,g=h>0?h+8:0,m=g+u.width,f=Math.max(u.height,p);c.push({group:i,x:r,y:0,itemOffsetX:g,itemOffsetY:0,width:m,height:f,items:u.items}),r+=m+12,l=Math.max(l,f)}const h=c.length>0?r-12:0,g=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:c.map(e=>({...e,x:e.x+g})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const g=ye(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),c);let m=0;return{groups:t.map((e,t)=>{const n=e.items.map(e=>Fa(e.label,a,l,o)),i=Math.max(0,...n,e.label?Fa(e.label,0,0,o):0);return m=Math.max(m,i),{group:e,x:0,y:g[t].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:e.items.length*c,items:e.items.map((e,t)=>({category:e.label,width:n[t],x:0,y:t*c}))}}),width:m,height:g.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function Na(e){const t="top"===e.position||"bottom"===e.position,o=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??o,200),height:e.gradient.label?34:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?124:108,swatchSize:14}}function Ea(e,t){if(!t||!e||0===e.length)return[];const o="function"==typeof t?t:e=>e[t],n=new Set;for(const t of e){const e=o(t);null!=e&&n.add(e+"")}return Array.from(n)}import{jsx as ja,jsxs as $a}from"react/jsx-runtime";var Da=16;function Wa(e,t){return e.color||t.colors.annotation||t.colors.text}function Ya(e,t,o){const n=e.labelBackground,i=t.colors.background,r=i&&"transparent"!==i?i:t.colors.surface||i;return void 0===n?"none"===o?"none":{type:"halo",fill:r}:!1===n||"none"===n?"none":!0===n||"halo"===n?{type:"halo",fill:r}:"box"===n?{type:"box",fill:r}:{fill:r,...n}}function Va(e,t,o){return null!=e.x&&t.x?t.x(e.x):o&&null!=e[o]&&t.x?t.x(e[o]):"number"==typeof e.x?e.x:null}function Ha(e,t,o){return null!=e.y&&t.y?t.y(e.y):o&&null!=e[o]&&t.y?t.y(e[o]):"number"==typeof e.y?e.y:null}function Ga(e){const{annotations:t}=e;if(!t||0===t.length)return null;const o=Lt(t),n=e.scales.geoProjection,i=n?o.map(e=>{if(!Array.isArray(e.coordinates)||2>e.coordinates.length)return e;const t=n([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):o,r=!!n&&!e.scales.x&&!e.scales.y,s=e=>Number(e),a=e.scales.x??(r?s:void 0),l=e.scales.y??(r?s:void 0),c=e.projection?"horizontal"===e.projection?"horizontal":"vertical":void 0,u={scales:{x:a,y:l,time:a,value:l,o:e.scales.o,...n?{geoProjection:n}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,frameType:e.projection?"ordinal":n||e.scales.x||e.scales.y?"xy":"network",...c?{projection:c}:{}},d=e.autoPlaceAnnotations?ft({annotations:i,context:u,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):i,h=Te(d,(t,o)=>function(e,t,o){const{scales:n,layout:i,theme:r,xAccessor:s,yAccessor:a}=o;switch(e.type){case"y-threshold":{const s=e.value;if(null==s)return null;const a=Wa(e,r),l=e.label,c=e.labelPosition||"right",u=e.strokeDasharray||"6,4",d=e.strokeWidth??1.5;if("horizontal"===o.projection&&n.r){const o=n.r(s);return null==o?null:$a("g",{opacity:e.opacity,children:[ja("line",{x1:o,y1:0,x2:o,y2:i.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&ja(L,{x:o+4,y:Da,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:Ya(e,r,"halo")})]},"ann-ythresh-"+t)}const h=n.y?n.y(s):n.r?n.r(s):null;return null==h?null:$a("g",{children:[ja("line",{x1:0,y1:h,x2:i.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&ja(L,{x:"left"===c?4:"center"===c?i.width/2:i.width-4,y:20>h?Math.min(i.height-4,h+Da):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:Ya(e,r,"halo")})]},"ann-ythresh-"+t)}case"x-threshold":{const s=e.value;if(null==s)return null;const a="horizontal"===o.projection&&n.r?n.r(s):n.x?n.x(s):null;if(null==a)return null;const l=Wa(e,r),c=e.label,u=e.labelPosition||"top";return $a("g",{opacity:e.opacity,children:[ja("line",{x1:a,y1:0,x2:a,y2:i.height,stroke:l,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||"6,4"}),c&&ja(L,{x:a>.6*i.width?a-4:a+4,y:"bottom"===u?i.height-4:"center"===u?i.height/2:Da,textAnchor:a>.6*i.width?"end":"start",fontSize:r.typography.tickSize,fill:l,fontFamily:r.typography.fontFamily,text:c,background:Ya(e,r,"halo")})]},"ann-xthresh-"+t)}case"band":{const o=n.y?.domain?.(),s=e.y0??o?.[0],a=e.y1??o?.[1],l=null!=s&&n.y?n.y(s):null,c=null!=a&&n.y?n.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=gt(e.fill||Wa(e,r),"ssr-band-"+t),p=e.fillOpacity??.1;return $a("g",{opacity:e.opacity,children:[h.def&&ja("defs",{children:h.def}),ja("rect",{x:0,y:u,width:i.width,height:d,fill:h.fill,fillOpacity:p}),e.label&&ja(L,{x:i.width-4,y:Math.max(u,0)+Da,textAnchor:"end",fontSize:r.typography.tickSize,fill:e.color||Wa(e,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ya(e,r,"halo")})]},"ann-band-"+t)}case"x-band":{const o=n.x?.domain?.(),s=e.x0??o?.[0],a=e.x1??o?.[1],l=null!=s&&n.x?n.x(s):null,c=null!=a&&n.x?n.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=gt(e.fill||Wa(e,r),"ssr-xband-"+t),p=e.fillOpacity??.1;return $a("g",{opacity:e.opacity,children:[h.def&&ja("defs",{children:h.def}),ja("rect",{x:u,y:0,width:d,height:i.height,fill:h.fill,fillOpacity:p}),e.label&&ja(L,{x:u+4,y:Da,textAnchor:"start",fontSize:r.typography.tickSize,fill:e.color||r.colors.primary||Wa(e,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:e.label,background:Ya(e,r,"halo")})]},"ann-xband-"+t)}case"category-highlight":{if(null==e.category||!n.o)return null;const s=n.o(e.category+"");if(null==s)return null;const a=n.o.bandwidth?n.o.bandwidth():40,l=Wa(e,r),c=e.opacity??.1,u=e.label;return $a("g","horizontal"===o.projection?{children:[ja("rect",{x:0,y:s,width:i.width,height:a,fill:l,opacity:c}),u&&ja(L,{x:12,y:s+a/2,dominantBaseline:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Ya(e,r,"none")})]}:{children:[ja("rect",{x:s,y:0,width:a,height:i.height,fill:l,opacity:c}),u&&ja(L,{x:s+a/2,y:Da,textAnchor:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:Ya(e,r,"none")})]},"ann-cathighlight-"+t)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:o,y:i}=function(e,t,o,n){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){const o=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Va(e,t,o),y:Ha(e,t,n)}}(e,n,s,a);if(null==o||null==i)return null;const l="text"===e.type,c=e.dx??(l?0:30),u=e.dy??(l?0:-30),d=e.color||r.colors.text;if(!l){const n="callout"===e.type?"callout-circle":e.type,r="callout-circle"===n?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===n?{width:e.width,height:e.height}:void 0;return ja(B,{noteData:{x:o,y:i,dx:c,dy:u,note:{label:e.label,title:e.title,wrap:e.wrap||120},type:n,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:d,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return ja("g",{children:ja("text",{x:o+c,y:i+u,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||r.typography.labelSize,fill:d,fontFamily:r.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},"ann-label-"+t)}default:return null}}(t,o,e),e.svgAnnotationRules,u);return h.length>0?ja("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:h}):null}import*as Xa from"react";import{jsx as qa,jsxs as Ua}from"react/jsx-runtime";function Qa(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){const t=e.id;return null==t?null:t+""}return null}function Za(e){const t=e._idPrefix||e.chartId;if(t){const e=(t+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(e)?e:"c"+e}const o=`${e.chartType||""}:${e.title||""}:${Array.isArray(e.data)?e.data.length:0}`;let n=0;for(let e=0;o.length>e;e++)n=31*n+o.charCodeAt(e)|0;return"c"+(n>>>0).toString(36)}function Ka(e,t,o){const n=e.showLegend&&!e.__legendIncludesAutomatic?Ia(t,e.colorScheme,o):void 0;return X(n,e.legend)}var Ja={right:110,left:110,top:50,bottom:80};function el(e,t){if(e.__autoLegendMargin&&!tl(e,t))return Ja[t]}function tl(e,t){const o=e.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[t])}function ol(e,t){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=t,a=o.legendPosition||"right",l={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:el(o,a),preserveExplicitMargin:tl(o,a)};if(null!=o.legend){const t=Ka(o,n,i);(fe(t)||me(t))&&function(e,t){if(t.preserveExplicitMargin)return;const o=t.position||"right",n={theme:t.theme,position:o,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout},i=fe(t.legend)?function(e){const{width:t,height:o,swatchSize:n}=Ba(e);return{width:t,height:o,swatchSize:n}}({...n,legendGroups:t.legend.legendGroups}):me(t.legend)?Na({...n,gradient:t.legend.gradient}):null;if(!i)return;const r=We(t.legend),s=Math.max(t.minimumMargin??0,Ge(t.legend,t.legendLayout)),a=Fe(t.axisChrome,t.legendLayout),l=Math.max(t.minimumMargin??0,r+i.height+(t.hasTitle?24:0)),c=Math.max(t.minimumMargin??0,a+r+i.height);"right"===o?e.right=Math.max(e.right,s):"left"===o?e.left=Math.max(e.left,s):"top"===o?e.top=Math.max(e.top,l):e.bottom=Math.max(e.bottom,c)}(e,{...l,legend:t})}else o.showLegend&&n.length>0&&function(e,t){if(0===t.categories.length)return;if(t.preserveExplicitMargin)return;const o=t.position||"right",n=function(e){const{width:t,height:o,swatchSize:n}=Oa(e);return{width:t,height:o,swatchSize:n}}({categories:t.categories,colorScheme:t.colorScheme,theme:t.theme,position:o,totalWidth:t.size[0],totalHeight:t.size[1],margin:e,hasTitle:t.hasTitle,legendLayout:t.legendLayout}),i=Ia(t.categories,t.colorScheme,t.theme),r=We(i),s=Math.max(t.minimumMargin??0,Ge(i,t.legendLayout)),a=Fe(t.axisChrome,t.legendLayout),l=Math.max(t.minimumMargin??0,r+n.height+(t.hasTitle?24:0)),c=Math.max(t.minimumMargin??0,a+r+n.height);"right"===o?e.right=Math.max(e.right,s):"left"===o?e.left=Math.max(e.left,s):"top"===o?e.top=Math.max(e.top,l):e.bottom=Math.max(e.bottom,c)}(e,{...l,categories:n,colorScheme:o.colorScheme});return a}function nl(e){const{props:t,categories:o,theme:n,size:i,margin:r,hasTitle:s}=e,a=t.legendPosition||"right",l={theme:n,position:a,size:i,margin:r,hasTitle:s,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix};if(null!=t.legend){const e=Ka(t,o,n);if(Xa.isValidElement(e))return e;const i=function(e,t){const o={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth,axisChrome:t.axisChrome,legendDistance:fe(e)||me(e)?e.legendDistance:void 0};return fe(e)?function(e){if(0===(t=e.legendGroups,t.flatMap(e=>e.items.map((t,o)=>({group:e,item:t,itemIndex:o,label:t.label})))).length)return null;var t;const o=Ba(e),n="top"===e.position||"bottom"===e.position,i={legendGroups:e.legendGroups,legendDistance:e.legendDistance},r=e.reservedWidth??Xe(i,e.legendLayout),s=We(i),a=Ve(e.legendLayout),l=Fe(e.axisChrome,e.legendLayout),c=Fe(void 0,e.legendLayout),u=e.theme.colors.grid||e.theme.colors.textSecondary;let d,h;if("left"===e.position?(d=e.margin.left-a-r-s,h=e.margin.top):"top"===e.position?(d=e.margin.left,h=e.margin.top-c-s-o.height):"bottom"===e.position?(d=e.margin.left,h=Math.max(e.totalHeight-e.margin.bottom+s,Math.min(e.totalHeight-e.margin.bottom+l+s,e.totalHeight-o.height))):(d=e.totalWidth-e.margin.right+a+s,h=e.margin.top),!n){const t=ye(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(o.swatchSize,e.legendLayout?.rowHeight??La)),n=e.legendGroups.flatMap((n,i)=>{const s=t[i],a=n.type??"fill",l=[Pa("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=s.labelY&&l.push(Pa("text",{y:s.labelY,fontSize:za(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.label},"legend-group-label-"+i)),l.push(Pa("g",{transform:`translate(0,${s.itemsY})`,children:n.items.map((t,r)=>{const s=n.styleFn(t,r),l="function"==typeof a?a(t):"line"===a?Pa("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):Pa("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return Ta("g",{transform:`translate(0,${r*Math.max(o.swatchSize,e.legendLayout?.rowHeight??La)})`,children:[l,Pa("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:za(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:t.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return Pa("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":"vertical",children:n})}const p=o.groups.flatMap((t,i)=>{const{group:r}=t,s=r.type??"fill",a=[];if(r.label&&a.push(Pa("text",n?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:za(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:r.label}:{x:t.x,y:t.y+za(e.theme),fontSize:za(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:r.label},"legend-group-label-"+i)),a.push(...t.items.map((n,a)=>{const l=r.items[a],c=r.styleFn(l,a),u="function"==typeof s?s(l):"line"===s?Pa("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:c}):Pa("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:c});return Ta("g",{transform:`translate(${t.x+t.itemOffsetX+n.x},${t.y+t.itemOffsetY+n.y})`,children:[u,Pa("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:za(e.theme),fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:n.category})]},`legend-${i}-${a}`)})),n&&o.groups.length-1>i){const e=t.x+t.width+6;a.push(Pa("line",{x1:e,y1:0,x2:e,y2:o.height,stroke:u},"legend-group-separator-"+i))}return a});return Pa("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":n?"horizontal":"vertical",children:p})}({...o,legendGroups:e.legendGroups}):me(e)?function(e){const t=Na(e),o="top"===e.position||"bottom"===e.position,n={gradient:e.gradient,legendDistance:e.legendDistance},i=Xe(n),r=We(n),s=Ve(e.legendLayout),a=Fe(e.axisChrome,e.legendLayout),l=Fe(void 0,e.legendLayout),c=(e.idPrefix?e.idPrefix+"-":"")+"semiotic-static-gradient-legend",u=e.gradient.format||(e=>Math.round(100*e)/100+"");let d,h;"left"===e.position?(d=e.margin.left-s-i-r,h=e.margin.top):"top"===e.position?(d=e.margin.left,h=e.margin.top-l-r-t.height):"bottom"===e.position?(d=e.margin.left,h=Math.max(e.totalHeight-e.margin.bottom+r,Math.min(e.totalHeight-e.margin.bottom+a+r,e.totalHeight-t.height))):(d=e.totalWidth-e.margin.right+s+r,h=e.margin.top);const p=Array.from({length:17},(t,n)=>{const i=n/16;return Pa("stop",{offset:100*i+"%",stopColor:e.gradient.colorFn(o?e.gradient.domain[0]+i*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-i*(e.gradient.domain[1]-e.gradient.domain[0]))},n)});if(o){const o=12,n=e.gradient.label?0:void 0,i=e.gradient.label?8:0;return Ta("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,children:[Pa("defs",{children:Pa("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:p})}),e.gradient.label&&Pa("text",{x:t.width/2,y:n,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),Pa("rect",{x:0,y:i,width:t.width,height:o,fill:`url(#${c})`,rx:2}),Pa("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[0])}),Pa("text",{x:t.width,y:i+o+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[1])})]})}const g=e.gradient.label?-6:void 0;return Ta("g",{className:"semiotic-legend",transform:`translate(${d},${h+(e.gradient.label?12:0)})`,children:[Pa("defs",{children:Pa("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:p})}),e.gradient.label&&Pa("text",{x:0,y:g,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:e.theme.typography.fontFamily,children:e.gradient.label}),Pa("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),Pa("text",{x:19,y:10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[1])}),Pa("text",{x:19,y:100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:e.theme.typography.fontFamily,children:u(e.gradient.domain[0])})]})}({...o,gradient:e.gradient}):null}(e,l);return i||(fe(e)||me(e)?null:e??null)}return t.showLegend&&0!==o.length?function(e){const{categories:t,colorScheme:o,theme:n,position:i="right",totalWidth:r,totalHeight:s,margin:a}=e;if(!t||0===t.length)return null;const l=Ra(t,o,n),c="top"===i||"bottom"===i,u=Oa(e),d=Ia(t,o,n),h=e.reservedWidth??Xe(d,e.legendLayout),p="number"==typeof e.legendDistance?Math.max(0,e.legendDistance):We(d),g=Ve(e.legendLayout),m=Fe(e.axisChrome,e.legendLayout),f=Fe(void 0,e.legendLayout);let y,b;if("left"===i?(y=a.left-g-h-p,b=a.top):"top"===i?(y=a.left,b=a.top-f-p-u.height):"bottom"===i?(y=a.left,b=Math.max(s-a.bottom+p,Math.min(s-a.bottom+m+p,s-u.height))):(y=r-a.right+g+p,b=a.top),c){const e=u.items.map((e,t)=>Ta("g",{transform:`translate(${e.x},${e.y})`,children:[Pa("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),Pa("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:za(n),fill:n.colors.text,fontFamily:n.typography.fontFamily,children:e.category})]},"legend-"+t));return Pa("g",{className:"semiotic-legend",transform:`translate(${y},${b})`,children:e})}const x=ye([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??La))[0],v=u.items.map((e,t)=>Ta("g",{transform:`translate(${e.x},${e.y+x.itemsY})`,children:[Pa("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),Pa("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:za(n),fill:n.colors.text,fontFamily:n.typography.fontFamily,children:e.category})]},"legend-"+t));return Ta("g",{className:"semiotic-legend",transform:`translate(${y},${b})`,children:[Pa("line",{x1:0,y1:x.lineY,x2:h,y2:x.lineY,stroke:"gray"}),v]})}({categories:o,colorScheme:t.colorScheme,theme:n,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix}):null}function il(e){return Math.round(100*e)/100+""}function rl(e,t){const o=Jt(t.theme),n=t.background??o.background,i=t.idPrefix?t.idPrefix+"-":"",r="string"==typeof t.title?t.title:void 0,s=r?i+"semiotic-title":void 0,a=t.description?i+"semiotic-desc":void 0,l=[s,a].filter(Boolean).join(" ")||void 0;return Ua("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,role:"img","aria-labelledby":l,style:{fontFamily:o.fontFamily},children:[r&&qa("title",{id:s,children:r}),t.description&&qa("desc",{id:a,children:t.description}),t.defs&&qa("defs",{children:t.defs}),n&&"transparent"!==n&&qa("rect",{x:0,y:0,width:t.width,height:t.height,fill:n}),qa("g",{id:i+"data-area",transform:t.innerTransform,children:e}),r&&qa("text",{id:i+"chart-title",x:t.width/2,y:E,textAnchor:"middle",fontSize:o.titleSize,fontWeight:"bold",fill:o.text,fontFamily:o.fontFamily,children:r}),t.legend&&qa("g",{id:i+"legend",children:t.legend}),t.outerElements]})}import{Fragment as sl,jsx as al,jsxs as ll}from"react/jsx-runtime";function cl(e,t){const o=Kt(e.theme),n=e.size||[500,300],i=ze({top:20,right:20,bottom:30,left:40,...e.margin},e.title),r=pe(e.title),s=ie(e.data),a=e.showLegend?Ea(s,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[],l={hasAxis:!1!==e.showAxes,hasAxisLabel:!!e.xLabel};ol(i,{props:{...e,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=n[0]-i.left-i.right,u=n[1]-i.top-i.bottom,d="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),h=e.colorScheme||o.colors.categorical,p=(e.axes?.find(e=>"left"===e.orient)??e.axes?.find(e=>"right"===e.orient))?.extent??e.axisExtent,g={chartType:e.chartType,windowSize:e.windowSize??200,windowMode:e.windowMode??"sliding",arrowOfTime:d?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:d?void 0:e.xAccessor,yAccessor:d?void 0:e.yAccessor,timeAccessor:d?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor,categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,axisExtent:e.axisExtent,yAxisExtent:p,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:Se(e.gradientFill),lineGradient:Ae(e.lineGradient),semanticLineStops:e.semanticLineStops,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:h,themeCategorical:o.colors.categorical,themeSemantic:Dt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:i,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat},m=new z(g);if(e.data&&m.ingest({inserts:s,bounded:!0}),m.computeScene({width:c,height:u}),!m.scales||0===m.scene.length)return t&&(t.evidence=Sa({frameType:"xy",width:n[0],height:n[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:m.scales?[]:["NO_SCALES"],margin:i})),Ma.renderToStaticMarkup(rl(null,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:u,idPrefix:e._idPrefix}));const f=e._idPrefix,y=Ie({nodes:m.scene,renderMode:e.renderMode,fallback:(e,t)=>at(e,t,f)});t&&(t.evidence=Sa({frameType:"xy",width:n[0],height:n[1],marks:y.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,xDomain:Aa(m.scales.x?.domain?.()),yDomain:Aa(m.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const b=e.showGrid?function(e,t,o,n,i,r){const{grid:s}=Jt(o),a=n?n+"-":"",l=r?.find(e=>"bottom"===e.orient),c=r?.find(e=>"top"===e.orient),u=r?.find(e=>"left"===e.orient),d=r?.find(e=>"right"===e.orient),h=l??c,p=u??d,g=h?.extent??i,m=p?.extent??i,f="exact"===g?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),y="exact"===m?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),b=h?.tickValues??Ze(e.x,h?.ticks??f,g),x=p?.tickValues??Ze(e.y,p?.ticks??y,m),v=!1!==h?.grid,w=!1!==p?.grid,A=De(h?.gridStyle),S=De(p?.gridStyle);return Ua("g",{id:a+"grid",className:"semiotic-grid",opacity:.8,children:[v&&b.map((o,n)=>{const i=e.x(o);return qa("line",{x1:i,y1:0,x2:i,y2:t.height,stroke:s,strokeWidth:.5,strokeDasharray:A},"gx-"+n)}),w&&x.map((o,n)=>{const i=e.y(o);return qa("line",{x1:0,y1:i,x2:t.width,y2:i,stroke:s,strokeWidth:.5,strokeDasharray:S},"gy-"+n)})]})}(m.scales,{width:c,height:u},o,f,e.axisExtent,e.axes):null,x=y.map(e=>e.element),v=Za(e)+"-plot-clip",w=!1!==e.showAxes?function(e,t,o,n,i){const r=Jt(n),s=Ve(o.legendLayout),a=o.legend&&"left"===o.legendPosition&&s>0?s:o.margin?.left??40,l=o.axes?.find(e=>"bottom"===e.orient),c=o.axes?.find(e=>"top"===e.orient),u=o.axes?.find(e=>"left"===e.orient),d=o.axes?.find(e=>"right"===e.orient),h=l??c,p=u??d,g=h?.extent??o.axisExtent,m=p?.extent??o.axisExtent,f="exact"===g?5:Math.min(5,Math.max(2,Math.floor(t.width/70))),y="exact"===m?5:Math.min(5,Math.max(2,Math.floor(t.height/30))),b=h?.tickValues??Ze(e.x,h?.ticks??f,g),x=b.map(e=>e.valueOf()),v=h?.tickFormat||o.xFormat||o.tickFormatTime||il,w=b.map((t,o)=>({pixel:e.x(t),label:v(t,o,x)})),A=p?.tickValues??Ze(e.y,p?.ticks??y,m),S=p?.tickFormat||o.yFormat||o.tickFormatValue||il,k=A.map(t=>({pixel:e.y(t),label:S(t)})),M=h?.label??o.xLabel,_=p?.label??o.yLabel;return Ua("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==h?.baseline&&qa("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:r.border,strokeWidth:1}),w.map((e,o)=>Ua("g",{transform:`translate(${e.pixel},${t.height})`,children:[qa("line",{y2:5,stroke:r.border,strokeWidth:1}),qa("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:e.label})]},"xtick-"+o)),M&&qa("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:M}),!1!==p?.baseline&&qa("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:r.border,strokeWidth:1}),k.map((e,t)=>Ua("g",{transform:`translate(0,${e.pixel})`,children:[qa("line",{x2:-5,stroke:r.border,strokeWidth:1}),qa("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:e.label})]},"ytick-"+t)),_&&qa("text",{x:15-a,y:t.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,transform:`rotate(-90, ${15-a}, ${t.height/2})`,children:_})]})}(m.scales,{width:c,height:u},e,o,f):null,A=e.annotations?Ga({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{x:m.scales.x,y:m.scales.y},layout:{width:c,height:u},theme:o,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:f}):null,S=e.svgPreRenderers&&m.scales?e.svgPreRenderers.map((e,t)=>{try{return al(ka.Fragment,{children:e(m.scene,m.scales,{width:c,height:u})},"pre-"+t)}catch{return null}}).filter(Boolean):null,k=nl({props:{...e,axisChrome:l},categories:a,theme:o,size:n,margin:i,hasTitle:r});return Ma.renderToStaticMarkup(rl(ll(sl,{children:[e.backgroundGraphics,S,b,al("defs",{children:al("clipPath",{id:v,children:al("rect",{x:0,y:0,width:c,height:u})})}),al("g",{clipPath:`url(#${v})`,children:x}),w,A,e.foregroundGraphics,m.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:c,innerHeight:u,legend:k,idPrefix:e._idPrefix}))}import*as ul from"react-dom/server";import{scaleBand as dl,scaleLinear as hl}from"d3-scale";var pl=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,o){if(t&&"function"==typeof e.pieceStyle){const n=e.pieceStyle(t,o);return n&&!n.fill&&o?{...n,fill:this.getColorFromScheme(e,o)}:n}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&o?{fill:e.barColors[o]||"#007bff"}:{fill:o?this.getColorFromScheme(e,o):"#007bff"}}resolveSummaryStyle(e,t,o){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,o):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){const o=this.colorSchemeMap.get(t);if(o)return o;const n=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||F,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,i),i}};function gl(e){const t=e.getSymbol;return t?_t(t,e.config.symbolMap):null}function ml(e,t,o,n,i,r,s){e.push(t?{type:"symbol",x:n,y:i,size:Math.PI*r*r,symbolType:t(o),style:s,datum:o}:{type:"point",x:n,y:i,r:r,style:s,datum:o})}function fl(e,t){const{columns:o,config:n,resolvePieceStyle:i}=e,r=[],s=Math.min(t.width,t.height)/2-4,a="donut"===n.chartType?n.innerRadius||60:0,l=-Math.PI/2+(n.startAngle||0)*Math.PI/180,c=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,u=null!=n.sweepAngle&&360>n.sweepAngle,d=Object.values(o),h=d.some(e=>{const t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),p=u&&!h&&d.length>1&&(n.cornerRadius??0)>0;for(let e=0;d.length>e;e++){const t=d[e],o=t.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:t.pctStart,h=l+u*c,g=l+(u+("number"==typeof o?._pct?o._pct:t.pct))*c,m=i(t.pieceData[0],t.name),f=0===e,y=e===d.length-1,b={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:g,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:m,datum:o?._nonInteractive?null:t.pieceData,category:t.name};o?._roundedEnds?b.roundedEnds=o._roundedEnds:p&&(b.roundedEnds={start:f,end:y}),o?._gradientBand&&(b._gradientBand=o._gradientBand),r.push(b)}return r}import{quantile as yl}from"d3-array";function bl(e){const t=e.length,o=e[0],n=e[t-1];return{n:t,min:o,q1:yl(e,.25)??o,median:yl(e,.5)??(o+n)/2,q3:yl(e,.75)??n,max:n,mean:e.reduce((e,t)=>e+t,0)/t}}import{scaleLinear as xl}from"d3-scale";var vl={bar:function(e,t){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=e,{r:l,projection:c}=o,u=[],d="vertical"===c,h="horizontal"===c,p=i.normalize,g=[];if(s){const e=new Set;for(const t of Object.values(n))for(const o of t.pieceData){const t=s(o);e.has(t)||(e.add(t),g.push(t))}}else g.push("_default");for(const e of Object.values(n)){const t=new Map;for(const o of e.pieceData){const e=s?s(o):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const n=t.get(e);n.total+=r(o),n.pieces.push(o)}let o=0;if(p)for(const e of t.values())o+=Math.abs(e.total);let n=0,i=0;for(const r of g){const c=t.get(r);if(!c)continue;let g=c.total;p&&o>0&&(g/=o);const m=a(c.pieces[0],s?r:e.name),f={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:e.name};if(d){const t=l(0>g?i:n+g),o=0>g?l(i+g)-l(i):l(n)-l(n+g);u.push(Y(e.x,t,e.width,Math.abs(o),m,f,r)),0>g?i+=g:n+=g}else if(h){const t=l(0>g?i+g:n),o=0>g?l(i)-l(i+g):l(n+g)-l(n);u.push(Y(t,e.x,Math.abs(o),e.width,m,f,r)),0>g?i+=g:n+=g}}}const m="vertical"===c,f=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;const t=e.datum?.__aggregateValue??0;e.roundedEdge=m?0>t?"bottom":"top":0>t?"left":"right",i.gradientFill&&(e.fillGradient=i.gradientFill)}if(f>0){const e=new Map;for(const t of u){if("rect"!==t.type)continue;const o=t.datum?.category||"";e.has(o)||e.set(o,[]),e.get(o).push(t)}for(const t of e.values()){if(0===t.length)continue;const e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),o=t.filter(e=>0>(e.datum?.__aggregateValue??0));e.length>0&&(e.reduce(m?(e,t)=>t.y>e.y?e:t:(e,t)=>e.x+e.w>t.x+t.w?e:t).roundedTop=f),o.length>0&&(o.reduce(m?(e,t)=>e.y+e.h>t.y+t.h?e:t:(e,t)=>t.x>e.x?e:t).roundedTop=f)}}return u},clusterbar:function(e,t){const{scales:o,columns:n,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=e,{r:l,projection:c}=o,u=[],d="vertical"===c,h=[],p=new Set;for(const e of Object.values(n))for(const t of e.pieceData){const e=s?s(t):"_default";p.has(e)||(p.add(e),h.push(e))}const g=h.length||1;for(const e of Object.values(n)){const t=e.width/g,o=.2*t,n=t-o,i=new Map;for(const t of e.pieceData){const e=s?s(t):"_default";i.has(e)||i.set(e,[]),i.get(e).push(t)}for(let s=0;h.length>s;s++){const c=i.get(h[s])||[];for(const i of c){const c=r(i),p=a(i,h[s]);if(d){const r=e.x+s*t+o/2,a=l(0),d=l(c);u.push(Y(r,Math.min(a,d),n,Math.abs(a-d),p,i,h[s]))}else{const r=e.x+s*t+o/2,a=l(0),d=l(c);u.push(Y(Math.min(a,d),r,Math.abs(d-a),n,p,i,h[s]))}}}}const m=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const e of u){if("rect"!==e.type)continue;if(null==e.datum)continue;const t=r(e.datum);m>0&&(e.roundedTop=m),e.roundedEdge=d?0>t?"bottom":"top":0>t?"left":"right",i.gradientFill&&(e.fillGradient=i.gradientFill)}return u},point:function(e,t){const{scales:o,columns:n,getR:i,multiScales:r,resolvePieceStyle:s}=e,{r:a,projection:l}=o,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,p=gl(e),g=2*Math.PI,m=-Math.PI/2;for(const e of Object.values(n))for(const t of e.pieceData){const o=t.__rIndex??0,n=t.__rValue??i(t),l=h&&r[o]||a,f=s(t,e.name),y=f.r||5;let b,x;if(d){const t=m+(e.pctStart+e.pct/2)*g,o=l(n);b=Math.cos(t)*o,x=Math.sin(t)*o}else u?(b=e.middle,x=l(n)):(b=l(n),x=e.middle);ml(c,p,t,b,x,y,f)}return c},swarm:function(e,t){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=e,{r:s,projection:a}=o,l=[],c="vertical"===a,u=gl(e);for(const e of Object.values(n)){const t=e.width/2;for(let o=0;e.pieceData.length>o;o++){const n=e.pieceData[o],a=i(n),d=r(n,e.name),h=d.r||4,p=(7919*o%100/100-.5)*t*.8;ml(l,u,n,c?e.middle+p:s(a),c?s(a):e.middle+p,h,d)}}return l},pie:fl,donut:fl,boxplot:function(e,t){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a,projection:l}=o,c=[],u="vertical"===l,d=!1!==i.showOutliers;for(const t of Object.values(n)){const o=t.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===o.length)continue;const n=o[0],i=o[o.length-1],l=yl(o,.25)??n,h=yl(o,.5)??(n+i)/2,p=yl(o,.75)??i,g=p-l,m=l-1.5*g,f=p+1.5*g,y=o.find(e=>e>=m)??n,b=[...o].reverse().find(e=>f>=e)??i,x=s(t.pieceData[0],t.name),v=[];if(d)for(const e of t.pieceData){const o=r(e);if(m>o||o>f){const n=u?t.middle:a(o),i=u?a(o):t.middle;v.push({px:n,py:i,value:o,datum:e})}}if(c.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:a(y),q1Pos:a(l),medianPos:a(h),q3Pos:a(p),maxPos:a(b),stats:{n:o.length,min:y,q1:l,median:h,q3:p,max:b,mean:o.reduce((e,t)=>e+t,0)/o.length},style:x,datum:t.pieceData,category:t.name,outliers:v}),d)for(const t of v)c.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:x.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6},datum:t.datum})}return c},violin:function(e,t){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a,projection:l}=o,c=[],u="vertical"===l,d=i.bins||20,h=!1!==i.showIQR;for(const e of Object.values(n)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],n=t[t.length-1],i=(n-o)/d||1,l=Array(d).fill(0);for(const e of t)l[Math.min(Math.floor((e-o)/i),d-1)]++;const p=zt(l,1),g=e.width/2*.9;let m;if(u){m=`M ${e.middle} ${a(o)}`;for(let t=0;d>t;t++){const n=a(o+(t+.5)*i);m+=` L ${e.middle+l[t]/p*g} ${n}`}m+=` L ${e.middle} ${a(n)}`;for(let t=d-1;t>=0;t--){const n=a(o+(t+.5)*i);m+=` L ${e.middle-l[t]/p*g} ${n}`}m+=" Z"}else{m=`M ${a(o)} ${e.middle}`;for(let t=0;d>t;t++)m+=` L ${a(o+(t+.5)*i)} ${e.middle-l[t]/p*g}`;m+=` L ${a(n)} ${e.middle}`;for(let t=d-1;t>=0;t--)m+=` L ${a(o+(t+.5)*i)} ${e.middle+l[t]/p*g}`;m+=" Z"}const f=s(e.pieceData[0],e.name);let y;if(h&&t.length>=4){const i=yl(t,.25)??o,r=yl(t,.5)??(o+n)/2,s=yl(t,.75)??n;y={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:e.middle,isVertical:u}}const b=u?{x:e.x,y:Math.min(a(n),a(o)),width:e.width,height:Math.abs(a(n)-a(o))}:{x:Math.min(a(o),a(n)),y:e.x,width:Math.abs(a(n)-a(o)),height:e.width};c.push({type:"violin",pathString:m,translateX:0,translateY:0,bounds:b,iqrLine:y,stats:bl(t),style:f,datum:e.pieceData,category:e.name})}return c},histogram:function(e,t){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a}=o,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,p=d?+d[1]:void 0;for(const e of Object.values(n)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;const[o,n]=Ot(t),i=null!=h&&isFinite(h)?h:o,d=null!=p&&isFinite(p)?p:n,g=(d-i)/c||1,m=Array(c).fill(0);for(const e of t)i>e||e>d||m[Math.min(Math.floor((e-i)/g),c-1)]++;const f=t.length,y=zt(m,1),b=s(e.pieceData[0],e.name);for(let t=0;c>t;t++){if(0===m[t])continue;const o=(u?m[t]/f:m[t]/y)*e.width*.9,n=a(i+t*g),r=a(i+(t+1)*g);l.push(Y(Math.min(n,r),e.x+e.width-o,Math.abs(r-n),o,b,{bin:t,count:m[t],range:[i+t*g,i+(t+1)*g],category:e.name},e.name))}}return l},ridgeline:function(e,t){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=e,{r:a,projection:l}=o,c=[],u=i.bins||20,d="horizontal"===l,h=i.amplitude||1.5;for(const e of Object.values(n)){const t=e.pieceData.map(e=>r(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;const o=t[0],n=t[t.length-1],i=(n-o)/u||1,l=Array(u).fill(0);for(const e of t)o>e||e>n||l[Math.min(Math.floor((e-o)/i),u-1)]++;const p=zt(l,1),g=s(e.pieceData[0],e.name),m=e.width*h;let f;if(d){const t=e.x+e.width;f=`M ${a(o)} ${t}`;for(let e=0;u>e;e++)f+=` L ${a(o+(e+.5)*i)} ${t-l[e]/p*m}`;f+=` L ${a(n)} ${t} Z`}else{const t=e.x;f=`M ${t} ${a(o)}`;for(let e=0;u>e;e++){const n=a(o+(e+.5)*i);f+=` L ${t+l[e]/p*m} ${n}`}f+=` L ${t} ${a(n)} Z`}const y=d?{x:Math.min(a(o),a(n)),y:e.x,width:Math.abs(a(n)-a(o)),height:e.width}:{x:e.x,y:Math.min(a(n),a(o)),width:e.width,height:Math.abs(a(n)-a(o))};c.push({type:"violin",pathString:f,translateX:0,translateY:0,bounds:y,stats:bl(t),style:{...g,fillOpacity:g.fillOpacity??.5},datum:e.pieceData,category:e.name})}return c},timeline:function(e,t){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=e,{r:s,projection:a}=o,l=[],c="horizontal"===a;for(const e of Object.values(n))for(const t of e.pieceData){const o=i(t);if(!o)continue;const[n,a]=o,u=r(t,e.name);if(c){const o=s(Math.min(n,a)),i=s(Math.max(n,a));l.push(Y(o,e.x,i-o,e.width,u,t,e.name))}else{const o=s(Math.max(n,a)),i=s(Math.min(n,a));l.push(Y(e.x,o,e.width,i-o,u,t,e.name))}}return l},funnel:function(e,t){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=e,s=[],a=t.width/2,l=!1!==e.config.showLabels,c=e.scales.o.domain().map(e=>o[e]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const e of c)for(const t of e.pieceData){const e=i?i(t):"_default";d.has(e)||(d.add(e),u.push(e))}const h=u.length>1&&"_default"!==u[0],p=[];let g=0;for(const e of c){const t=new Map;let o=0;for(const r of e.pieceData){const e=i?i(r):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const s=t.get(e),a=n(r);s.total+=a,s.pieces.push(r),o+=a}p.push({col:e,groups:t,stepTotal:o}),h||o>g&&(g=o)}if(h)for(const e of p){let t=0,o=0;for(let n=0;u.length>n;n++){const i=e.groups.get(u[n]);i&&(n%2==0?t+=i.total:o+=i.total)}const n=Math.max(t,o);n>g&&(g=n)}if(0===g)return s;const m=new Map;for(const e of u){const t=p[0].groups.get(e);m.set(e,t?.total??0)}const f=p[0].stepTotal,y=h?.95*a:.9*t.width,b=xl().domain([0,g]).range([0,y]),x=e.config.connectorOpacity??.3;let v=new Map;for(let t=0;p.length>t;t++){const o=p[t],n=o.col,i=0===t,c=n.width,d=.55*c,g=n.x+(c-d)/2,y=new Map;if(h){let e=0;for(const t of u){const n=o.groups.get(t);n&&(e+=b(n.total))}let t=a,c=a;for(let h=0;u.length>h;h++){const p=u[h],f=o.groups.get(p);if(!f)continue;const x=b(f.total),v=h%2==0,w=v?t:c-x;v?t+=x:c-=x;const A=r(f.pieces[0],p),S=m.get(p)??f.total,k={...f.pieces[0],__funnelValue:f.total,__funnelPercent:S>0?f.total/S*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:f.total,__pieceCount:f.pieces.length,category:p};l&&(0===h&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=g,k.__funnelRowWidth=e),k.__funnelValueLabelX=w+x/2,k.__funnelValueLabelY=g,k.__funnelBarW=x),s.push(Y(w,g,x,d,A,k,p)),y.set(p,{x:w,y:g,w:x,h:d})}}else{const e=o.stepTotal,t=b(e),c=a-t/2,h=u[0],p="_default"!==h,m=o.groups.get(h)?.pieces[0]??n.pieceData[0],x=p?h:n.name,v=r(m,x),w=f>0?e/f*100:0,A={...m,__funnelValue:e,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:p?h:n.name};l&&(A.__funnelStepLabel=n.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=g,A.__funnelRowWidth=t,A.__funnelValueLabelX=a,A.__funnelValueLabelY=g,A.__funnelBarW=t),s.push(Y(c,g,t,d,v,A,x)),y.set(h,{x:c,y:g,w:t,h:d})}if(t>0&&v.size>0){const t=h?u:[u[0]];for(const i of t){const t=v.get(i),a=y.get(i);if(!t||!a)continue;const l=(()=>{const e=o.groups.get(i);return r(e?e.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),c={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:l.fill||e.config.themeSemantic?.secondary||"#999",opacity:x},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(c)}}v=y}return s},"bar-funnel":function(e,t){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=e,a=[],l=s.o.domain().map(e=>o[e]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const e of l)for(const t of e.pieceData){const e=i?i(t):"_default";u.has(e)||(u.add(e),c.push(e))}const d=c.length>1&&"_default"!==c[0],h=[];for(const e of l){const t=new Map;let o=0;for(const r of e.pieceData){const e=i?i(r):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});const s=t.get(e),a=n(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:e,groups:t,stepTotal:o})}const p=new Map;for(const e of c){const t=h[0]?.groups.get(e);p.set(e,t?.total??0)}const g=s.r,m=d?c.length:1,f=d?.15:0;for(let e=0;h.length>e;e++){const t=h[e],o=t.col,n=0===e,i=e>0?h[e-1]:null,s=o.width/m,l=s*f,u=s-l;for(let e=0;c.length>e;e++){const h=c[e],m=t.groups.get(h);if(!m)continue;const f=m.total,y=p.get(h)??f,b=y>0?f/y*100:0,x=i?.groups.get(h),v=n?0:Math.max(0,(x?.total??f)-f),w=o.x+e*s+l/2,A=g(f),S=g(0)-A,k=r(m.pieces[0],d?h:o.name),M={...m.pieces[0],__barFunnelValue:f,__barFunnelPercent:b,__barFunnelIsFirstStep:n,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:g(f+v)};if(a.push(Y(w,A,u,S,k,M,d?h:o.name)),v>0){const e=g(f+v),t=A-e,n={...k},i={...m.pieces[0],__barFunnelValue:v,__barFunnelPercent:y>0?v/y*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(Y(w,e,u,t,n,i,d?h:o.name))}}}return a},swimlane:function(e,t){const{scales:o,columns:n,getR:i,getStack:r,resolvePieceStyle:s}=e,{r:a,projection:l}=o,c=[],u="horizontal"===l,d=e.config.gradientFill,h=u?"left":"bottom",p=e.config.trackFill;if(p){const e="string"==typeof p?p:p.color,t="string"==typeof p?1:p.opacity??1,[o,i]=a.range(),r=Math.min(o,i),s=Math.abs(i-o);for(const o of Object.values(n)){const n={fill:e,opacity:t},i=u?Y(r,o.x,s,o.width,n,null,"__track__"):Y(o.x,r,o.width,s,n,null,"__track__");c.push(i)}}const g=e.config.roundedTop&&e.config.roundedTop>0?Math.max(0,e.config.roundedTop):0;for(const e of Object.values(n)){let t=0;const o=c.length;for(const o of e.pieceData){const n=Math.abs(i(o));if(0===n)continue;const l=r?r(o):e.name,p=s(o,l);let g;if(u){const i=a(t),r=a(t+n);g=Y(i,e.x,r-i,e.width,p,o,l)}else{const i=a(t+n),r=a(t);g=Y(e.x,i,e.width,r-i,p,o,l)}d&&(g.fillGradient=d,g.roundedEdge=h),c.push(g),t+=n}if(g>0&&c.length>o){const e=c.slice(o),t=e[0],n=e[e.length-1];1===e.length?t.cornerRadii={tl:g,tr:g,br:g,bl:g}:u?(t.cornerRadii={tl:g,bl:g},n.cornerRadii={tr:g,br:g}):(t.cornerRadii={bl:g,br:g},n.cornerRadii={tl:g,tr:g})}}return c}},wl=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Al=["scene-style","data-paint","accessibility","evidence"],Sl=(e,t)=>({retainedData:e,invalidations:t}),kl=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ml=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],_l=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Pl=["scene-geometry","data-paint","accessibility","evidence"],Tl=["scene-style","data-paint","accessibility","evidence"],Ll=[],Rl={chartType:Sl("rebuild",kl),runtimeMode:Sl("rebuild",kl),categoryAccessor:Sl("rebuild",kl),valueAccessor:Sl("rebuild",kl),oAccessor:Sl("rebuild",kl),rAccessor:Sl("rebuild",kl),stackBy:Sl("rebuild",kl),groupBy:Sl("rebuild",kl),timeAccessor:Sl("rebuild",kl),accessorRevision:Sl("rebuild",kl),colorAccessor:Sl("rebuild",Tl),symbolAccessor:Sl("rebuild",Pl),connectorAccessor:Sl("rebuild",Pl),dataIdAccessor:Sl("rebuild",Pl),projection:Sl("preserve",Ml),extentPadding:Sl("preserve",Ml),axisExtent:Sl("preserve",Ml),rExtent:Sl("preserve",Ml),oExtent:Sl("preserve",Ml),multiAxis:Sl("preserve",Ml),normalize:Sl("preserve",Ml),bins:Sl("preserve",Ml),oSort:Sl("preserve",_l),barPadding:Sl("preserve",_l),roundedTop:Sl("preserve",_l),baselinePadding:Sl("preserve",_l),innerRadius:Sl("preserve",_l),cornerRadius:Sl("preserve",_l),startAngle:Sl("preserve",_l),sweepAngle:Sl("preserve",_l),trackFill:Sl("preserve",_l),showOutliers:Sl("preserve",_l),showIQR:Sl("preserve",_l),amplitude:Sl("preserve",_l),connectorOpacity:Sl("preserve",_l),showLabels:Sl("preserve",_l),dynamicColumnWidth:Sl("rebuild",_l),customLayout:Sl("preserve",_l),layoutConfig:Sl("preserve",_l),layoutMargin:Sl("preserve",_l),symbolMap:Sl("preserve",Pl),pieceStyle:Sl("preserve",Tl),summaryStyle:Sl("preserve",Tl),connectorStyle:Sl("preserve",Tl),gradientFill:Sl("preserve",Tl),colorScheme:Sl("preserve",Tl),themeCategorical:Sl("preserve",Tl),themeSemantic:Sl("preserve",Tl),themeSequential:Sl("preserve",Tl),themeDiverging:Sl("preserve",Tl),barColors:Sl("preserve",Tl),decay:Sl("preserve",Tl),pulse:Sl("preserve",Tl),staleness:Sl("preserve",Tl),layoutSelection:Sl("preserve",Tl),windowSize:Sl("preserve",Ll),windowMode:Sl("preserve",Ll),clock:Sl("preserve",Ll),transition:Sl("preserve",Ll),introAnimation:Sl("preserve",Ll),onLayoutError:Sl("preserve",Ll)},Il=Sl("preserve",_l),Cl=class{constructor(){this.tracker=new mt}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},wl)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},Al):this.recordNoop("restyle")}recordConfig(e){const t=function(e){let t="preserve";const o=new Set;for(const n of e){const e=Rl[n]??Il;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)o.add(t)}return{retainedData:t,invalidations:o}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as zl}from"d3-quadtree";var Fl=class{constructor(e){this.rExtent=new ct,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Cl,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new pl,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new ut(e.windowSize),this.getO=Ct(e.categoryAccessor||e.oAccessor,"category");const t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>It(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new ct)):(this.getR=It(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Ct(e.stackBy),this.getGroup=Ct(e.groupBy),this.getColor=Ct(e.colorAccessor),this.getSymbol=Ct(e.symbolAccessor),this.getConnector=Ct(e.connectorAccessor),this.getDataId=Ct(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new ut(e.windowSize))}syncPulseTimestampBuffer(){var e,t,o,n;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,o=this.timestampBuffer,n=this.currentTime(),e?null!=o&&o.capacity===t.capacity&&o.size===t.size?o:te(t,n):null)}currentTime(){return this.config.clock?.()??Me()}ingest(e){const t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),ne(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(const o of e.inserts)Pe(this.buffer,o,this.timestampBuffer,t),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of e.inserts){const e=Pe(this.buffer,o,this.timestampBuffer,t);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){const t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){const t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;const o="function"==typeof t?t(e):e[t];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(e){const{config:t,buffer:o}=this,n=this.scales,i=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const s=this.getBufferArray(),a=t.projection||"vertical",l=t.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=t.barPadding?t.barPadding/("vertical"===a?e.width:e.height):.1));let p,g;if(d){p=dl().domain(l).range([0,1]).padding(0);const o=Math.min(e.width,e.height)/2,n=t.innerRadius||0;g=hl().domain(c).range([n,o])}else u?(p=dl().domain(l).range([0,e.height]).padding(h),g=hl().domain(c).range([0,e.width])):(p=dl().domain(l).range([0,e.width]).padding(h),g=hl().domain(c).range([e.height,0]));this.scales={o:p,r:g,projection:a},this.multiScales=this.rAccessors.length>1&&t.multiAxis?this.rAccessors.map((n,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(o,n);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const l=a-s,c=l>0?l*(t.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?hl().domain([s,a]).range([0,e.width]):hl().domain([s,a]).range([e.height,0])}):[];let m=s;this.rAccessors.length>1&&(m=s.flatMap(e=>this.rAccessors.map((t,o)=>({...e,__rIndex:o,__rValue:t(e),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(m,l,p,a,e),this._customLayoutFailedThisBuild=!1;const f=this.buildSceneNodes(m,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=f,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){const t=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(t)?t[e]:t;return"string"==typeof o?o:"value"+e}resolveCategories(e){const t=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,n="auto"===t?void 0:t;let i=null;if(o){i=new Set;for(const t of e)i.add(this.getO(t))}const r=i?Array.from(this.categories).filter(e=>i.has(e)):Array.from(this.categories);if(o&&void 0===n){const e=Math.max(50,3*i.size);if(this.categories.size>e){let t=this.categories.size-e;for(const e of this.categories){if(0>=t)break;i.has(e)||(this.categories.delete(e),t--)}}return r}if(!1===n)return r;if("function"==typeof n)return r.sort(n);const s=new Map;for(const t of e){const e=this.getO(t);s.set(e,(s.get(e)||0)+Math.abs(this.getR(t)))}return r.sort("asc"===n?(e,t)=>(s.get(e)||0)-(s.get(t)||0):(e,t)=>(s.get(t)||0)-(s.get(e)||0))}computeValueDomain(e,t){return function(e){const{data:t,chartType:o,projection:n,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=e,p=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let g=0,m=0;if("bar"===o&&d&&i)g=0,m=1;else if("bar"===o&&d){const e=new Map,o=new Map;for(const n of t){const t=c(n),i=u(n);0>i?o.set(t,(o.get(t)||0)+i):e.set(t,(e.get(t)||0)+i)}for(const t of e.values())t>m&&(m=t);for(const e of o.values())g>e&&(g=e)}else if("bar"===o){const e=new Map;for(const o of t){const t=c(o),n=u(o);e.set(t,(e.get(t)||0)+n)}for(const t of e.values())t>m&&(m=t),g>t&&(g=t)}else if("swimlane"===o){const e=new Map;for(const o of t){const t=c(o),n=Math.abs(u(o));e.set(t,(e.get(t)||0)+n)}for(const t of e.values())t>m&&(m=t)}else if("clusterbar"===o||"bar-funnel"===o)for(const e of t){const t=u(e);t>m&&(m=t),g>t&&(g=t)}else{const e=h[0],t=h[1];e!==1/0&&(g=e),t!==-1/0&&(m=t)}r&&(null!=r[0]&&(g=r[0]),null!=r[1]&&(m=r[1]));const f="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(f&&null==r?.[0]&&null==r?.[1]&&(g>0&&(g=0),0>m&&(m=0)),"bar-funnel"!==o&&"exact"!==l){const e=m-g,t=e>0?e*p:1,n=f&&!a&&0===g,i=f&&!a&&0===m||"swimlane"===o;null!=r?.[0]||n||(g-=t),null!=r?.[1]||i||(m+=t)}return[g,m]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,o,n,i){return function(e){const{data:t,oExtent:o,oScale:n,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:l}=e,c={},u=new Map;for(const e of t){const t=a(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===i)for(const e of t)d+=Math.abs(l(e));let h=null;if(s&&"radial"!==i){h=new Map;let e=0;for(const t of o){const o=u.get(t)||[];let n;n="string"==typeof s?o.reduce((e,t)=>e+(Number(t[s])||0),0):s(o),h.set(t,n),e+=n}const t=("horizontal"===i?r.height:r.width)-n.padding()*n.step()*o.length;if(e>0)for(const[o,n]of h)h.set(o,n/e*t)}let p=0,g=0;for(const e of o){const t=u.get(e)||[],o=t.reduce((e,t)=>e+Math.abs(l(t)),0),i=d>0?o/d:0;let r,s;h?(r=g,s=h.get(e)||n.bandwidth(),g+=s+n.padding()*n.step()):(r=n(e)??0,s=n.bandwidth()),c[e]={name:e,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:t,pct:i,pctStart:p},p+=i}return c}({data:e,oExtent:t,oScale:o,projection:n,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(e,t);let n;try{n=this.config.customLayout(o)}catch(e){const t=null!==this.lastCustomLayoutResult,o=ee("ordinal",e,t,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",e);try{this.config.onLayoutError?.(o)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return t?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;const i=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const e of i)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(i,this.config.layoutSelection??null)}return st({label:"ordinal customLayout",nodes:i,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),i}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),n=vl[this.config.chartType];let i=n?n(o,t):[];if(this.getConnector&&this.scales){const e=function(e,t){const{scales:o,config:n,getConnector:i,getO:r}=e;if(!i||!o)return[];const s=[],{projection:a}=o,l=new Map;for(const e of t){if("point"!==e.type&&"rect"!==e.type)continue;const t=e.datum;if(!t)continue;const o=i(t);if(!o)continue;let n,s;"point"===e.type?(n=e.x,s=e.y):(n=e.x+e.w/2,s=e.y+("vertical"===a?0:e.h/2)),l.has(o)||l.set(o,[]),l.get(o).push({x:n,y:s,datum:t,category:r(t)})}const c=o.o.domain(),u=n.connectorStyle;for(const[t,o]of l)if(o.length>=2){o.sort((e,t)=>c.indexOf(e.category)-c.indexOf(t.category));for(let n=0;o.length-1>n;n++){const i=o[n],r=o[n+1],a="function"==typeof u?u(i.datum):u||{stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:i.x,y1:i.y,x2:r.x,y2:r.y,style:a,datum:i.datum,group:t})}}return s}(o,i);i=[...e,...i]}return i}buildLayoutContext(e,t){const o=this.config,n=o.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Ne(o.colorScheme,o.themeCategorical,F),r=this.scales;return{data:e,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:t.width,height:t.height,margin:n,plot:"radial"===r.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:[...i]},resolveColor:V(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(e,t){const o=this.config.decay;return o&&t>1?q(o,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const t=W(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const t=function(e,t){const o="function"==typeof t,n=o?null:t||"category",i=new Map;for(let r=0;e.length>r;r++){const s=e[r],a=o?t(s):s[n],l=i.get(a);l?l.push(r):i.set(a,[r])}return i}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){const e=function(e){let t=0,o=0;for(const n of e)"point"===n.type&&(t++,n.r>o&&(o=n.r));if(500>=t)return{quadtree:null,maxRadius:o};const n=Array(t);let i=0;for(const t of e)"point"===t.type&&(n[i++]=t);return{maxRadius:o,quadtree:zl().x(e=>e.x).y(e=>e.y).addAll(n)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;const o=t.length;if(1>=o)return;const n=this.getDatumIndexMap(t);for(const t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type)continue;if(!t.datum)continue;const e=n.get(t.datum);if(null==e)continue;const i=this.computeDecayOpacity(e,o);t.style={...t.style,opacity:(t.style?.opacity??1)*i}}}applyPulse(e,t,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,o,n,i,r){const s=e.color??"rgba(255,255,255,0.6)",a=e.glowRadius??4;let l=!1;for(const c of t){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const t=c.category;if(!t)continue;let n=0;for(const s of i(t)??[]){const t=o.get(s);null!=t&&(n=Math.max(n,Q(e,t,r)))}l=Ue(c,n,s)||l;continue}if(null==c.datum)continue;const t=n.get(c.datum);if(null==t)continue;const u=o.get(t),d=null==u?0:Q(e,u,r);l=Ue(c,d,s,a)||l}return l}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),o)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&he(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const e=new Map,t=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let n;for(let i=0;this.scene.length>i;i++){const r=this.scene[i],s=this.getNodeKey(r,e);s&&("rect"===r.type?this.prevPositionMap.set(s,o?{x:r.x,y:t,w:r.w,h:0,opacity:r.style.opacity??1}:{x:t,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===n&&(n=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:n,endAngle:n,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){const o=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,n=t.get(o)||0;return t.set(o,n+1),`${o}:${n}`}if("rect"===e.type){const o=e.datum?null!=e.datum.category&&""!==e.datum.category?e.datum.category+"":(this.getO(e.datum)??"")+"":"",n=`r:${e.group||""}:${o}`,i=t.get(n)||0;return t.set(n,i+1),0===i?n:`${n}:${i}`}return"wedge"===e.type?"w:"+(e.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const e=new Map;for(let t=0;this.scene.length>t;t++){const o=this.scene[t],n=this.getNodeKey(o,e);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity??o.style.fillOpacity}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity??o.style.fillOpacity}):"wedge"===o.type&&this.prevPositionMap.set(n,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const e=this.config.transition.duration??300;if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1;const o=new Set,n=new Map;for(let e=0;this.scene.length>e;e++){const i=this.scene[e],r=this.getNodeKey(i,n);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,(s.x!==i.x||s.y!==i.y||void 0!==s.r&&s.r!==i.r)&&(i._targetX=i.x,i._targetY=i.y,i._targetR=i.r,i.x=s.x,i.y=s.y,void 0!==s.r&&(i.r=s.r),t=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},t=!0);else if("rect"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.x===i.x&&s.y===i.y&&s.w===i.w&&s.h===i.h||(i._targetX=i.x,i._targetY=i.y,i._targetW=i.w,i._targetH=i.h,i.x=s.x,i.y=s.y,i.w=s.w??i.w,i.h=s.h??i.h,t=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i.style={...i.style,opacity:0},t=!0);else if("wedge"===i.type)if(s)o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.startAngle===i.startAngle&&s.endAngle===i.endAngle||(i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle,i.startAngle=s.startAngle,i.endAngle=s.endAngle,t=!0);else{i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle;const e=i.startAngle;i.startAngle=e,i.endAngle=e,i.style={...i.style,opacity:0},this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:e,endAngle:e,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(const[e,n]of this.prevPositionMap)if(!o.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:n.x,y:n.y,r:n.r??3,style:{opacity:n.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:n.x,y:n.y,w:n.w??0,h:n.h??0,style:{opacity:n.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){const t=((n.startAngle??0)+(n.endAngle??0))/2,o={type:"wedge",cx:n.x,cy:n.y,innerRadius:n.innerRadius??0,outerRadius:n.outerRadius??100,startAngle:n.startAngle??0,endAngle:n.endAngle??0,style:{opacity:n.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(o)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;const t=Z(e,this.activeTransition),o=U(t,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const e of this.scene){const t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){const n=this.prevPositionMap.get(t);e.style.opacity=be(n?n.opacity??1:0,e._targetOpacity,o)}const n=this.prevPositionMap.get(t);void 0!==e._targetX&&n&&(e.x=be(n.x,e._targetX,o),e.y=be(n.y,e._targetY,o)),void 0!==e._targetR&&void 0!==n?.r&&(e.r=be(n.r,e._targetR,o))}else if("rect"===e.type){if(void 0!==e._targetOpacity){const n=this.prevPositionMap.get(t);e.style.opacity=be(n?n.opacity??1:0,e._targetOpacity,o)}if(void 0===e._targetX)continue;const n=this.prevPositionMap.get(t);if(!n)continue;e.x=be(n.x,e._targetX,o),e.y=be(n.y,e._targetY,o),void 0!==n.w&&(e.w=be(n.w,e._targetW,o),e.h=be(n.h,e._targetH,o))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){const n=this.prevPositionMap.get(t);e.style={...e.style,opacity:be(n?n.opacity??1:0,e._targetOpacity,o)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){const n=this.prevPositionMap.get(t);n&&void 0!==n.startAngle&&(e.startAngle=be(n.startAngle,e._targetStartAngle,o),e.endAngle=be(n.endAngle,e._targetEndAngle,o))}}}if(t>=1){for(const e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){const e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,Qe(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const t=Ke(e),o=this.getDataId,n=e=>t.has(o(e));G(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const e of i)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(e,t){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=Ke(e),n=this.getDataId,i=new Set;this.buffer.forEach((e,t)=>{o.has(n(e))&&i.add(t)});const r=this.buffer.update(e=>o.has(n(e)),t);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const e of r)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),i.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){const o=this._customRestyle;if(o)for(const n of e){const e=this._baseStyles.get(n)??n.style??{},i=o(n,t);n.style=i?{...e,...i}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){const t={...this.config},o=Object.keys(e).filter(o=>e[o]!==t[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!Rt(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!Rt(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!Rt(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let n=!1;("categoryAccessor"in e||"oAccessor"in e)&&(Rt(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=Ct(this.config.categoryAccessor||this.config.oAccessor,"category"),n=!0));let i=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,o=t.valueAccessor||t.rAccessor,n=Array.isArray(e)?e:[e],r=Array.isArray(o)?o:[o];if(i=n.length!==r.length||n.some((e,t)=>!Rt(e,r[t])),i){const e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>It(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new ct)):(this.getR=It(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!Rt(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?Ct(this.config.stackBy):void 0),"groupBy"in e&&!Rt(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?Ct(this.config.groupBy):void 0),"colorAccessor"in e&&!Rt(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Ct(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!Rt(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Ct(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!Rt(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Ct(this.config.connectorAccessor):void 0),(n||i||"accessorRevision"in e&&e.accessorRevision!==t.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};j(Fl);import{jsx as Ol,jsxs as Bl}from"react/jsx-runtime";import{Fragment as Nl,jsx as El,jsxs as jl}from"react/jsx-runtime";function $l(e,t){const o=Kt(e.theme),n=e.size||[500,400],i=ze({top:20,right:20,bottom:30,left:40,...e.margin},e.title),r=pe(e.title),s=ie(e.data),a=e.showLegend?Ea(s,e.colorAccessor||e.stackBy||e.groupBy):[],l=e.projection||"vertical",c={hasAxis:!1!==e.showAxes&&"radial"!==l,hasAxisLabel:"horizontal"===l?!(!e.valueLabel&&!e.rLabel):!(!e.categoryLabel&&!e.oLabel)};ol(i,{props:{...e,axisChrome:c},categories:a,theme:o,size:n,hasTitle:r});const u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h=e.projection||"vertical",p="radial"===h,g=e.colorScheme||o.colors.categorical,m={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:h,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:Se(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:g,themeCategorical:o.colors.categorical,themeSemantic:Dt(o),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:i,layoutSelection:e.layoutSelection,barColors:e.barColors},f=new Fl(m);if(e.data&&f.ingest({inserts:s,bounded:!0}),f.computeScene({width:u,height:d}),!f.scales||0===f.scene.length)return t&&(t.evidence=Sa({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,extraWarnings:f.scales?[]:["NO_SCALES"],margin:i})),ul.renderToStaticMarkup(rl(null,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,idPrefix:e._idPrefix}));const y=e._idPrefix,b=e.showGrid?function(e,t,o,n,i){const r=e.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=Jt(o),a=n?n+"-":"",l="vertical"===r.projection,c=Ze(r.r,5,i);return qa("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((e,o)=>{const n=r.r(e);return qa("line",{x1:0,y1:n,x2:t.width,y2:n,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((e,o)=>{const n=r.r(e);return qa("line",{x1:n,y1:0,x2:n,y2:t.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(f,{width:u,height:d},o,y,e.axisExtent):null;let x=null;if(f.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){const t=Za(e),n=new Set;for(const e of f.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&n.add("string"==typeof e.style.fill?e.style.fill:"#666");x=Array.from(n).map((e,n)=>function(e){const{id:t,background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=e,a=Math.max(8,Math.ceil(2*r));return Bl("pattern",{id:t,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Ol("rect",{width:a,height:a,fill:o}),Ol("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Ol("line",{x1:r,y1:0,x2:r,y2:a,stroke:n,strokeWidth:i})]},t)}({id:`funnel-hatch-${t}-${n}`,background:e,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(n).forEach((e,o)=>i.set(e,`funnel-hatch-${t}-${o}`));for(const e of f.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&(e.style={...e.style,fill:`url(#${i.get("string"==typeof e.style.fill?e.style.fill:"#666")})`})}const v=Ie({nodes:f.scene,renderMode:e.renderMode,fallback:(e,t)=>_e(e,t,y)}),w=v.map(e=>e.element);if(t){const o=f.scales.o?.domain?.();t.evidence=Sa({frameType:"ordinal",width:n[0],height:n[1],marks:v.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,yDomain:Aa(f.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const A=!1!==e.showAxes?function(e,t,o,n,i){const r=e.scales;if(!r)return null;if("radial"===r.projection)return null;const s=Jt(n),a="vertical"===r.projection,l=o.categoryFormat||o.oFormat,c=o.valueFormat||o.rFormat,u=o.categoryLabel||o.oLabel,d=o.valueLabel||o.rLabel,h=Object.values(e.columns).map(e=>({pixel:e.middle,label:(l||String)(e.name)})),p=Ze(r.r,5,o.axisExtent).map(e=>({pixel:r.r(e),label:(c||il)(e)}));return jl("g",a?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[El("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),h.map((e,o)=>jl("g",{transform:`translate(${e.pixel},${t.height})`,children:[El("line",{y2:5,stroke:s.border,strokeWidth:1}),El("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oxtick-"+o)),u&&El("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:u}),El("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),p.map((e,t)=>jl("g",{transform:`translate(0,${e.pixel})`,children:[El("line",{x2:-5,stroke:s.border,strokeWidth:1}),El("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oytick-"+t)),d&&El("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:d})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[El("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:s.border,strokeWidth:1}),p.map((e,o)=>jl("g",{transform:`translate(${e.pixel},${t.height})`,children:[El("line",{y2:5,stroke:s.border,strokeWidth:1}),El("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oxtick-"+o)),d&&El("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:d}),El("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:s.border,strokeWidth:1}),h.map((e,t)=>jl("g",{transform:`translate(0,${e.pixel})`,children:[El("line",{x2:-5,stroke:s.border,strokeWidth:1}),El("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:e.label})]},"oytick-"+t)),u&&El("text",{x:15-(o.margin?.left??40),y:t.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${t.height/2})`,children:u})]})}(f,{width:u,height:d},e,o,y):null,S=e.annotations?Ga({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{o:f.scales.o,r:f.scales.r,y:"vertical"===f.scales.projection?f.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,idPrefix:y}):null,k=nl({props:{...e,axisChrome:c},categories:a,theme:o,size:n,margin:i,hasTitle:r}),M=p?i.left+u/2:i.left,_=p?i.top+d/2:i.top,P=p&&e.centerContent?El("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:El("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null;return ul.renderToStaticMarkup(rl(jl(Nl,{children:[e.backgroundGraphics,b,w,A,S,e.foregroundGraphics,f.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${M},${_})`,innerWidth:u,innerHeight:d,legend:k,defs:x,outerElements:P,idPrefix:e._idPrefix}))}import*as Dl from"react-dom/server";import{Fragment as Wl,jsxs as Yl}from"react/jsx-runtime";function Vl(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}var Hl=new Set(["tree","cluster","treemap","circlepack","partition"]);function Gl(e,t){const o=Kt(e.theme),n=e.chartType||"force",i=()=>Sa({frameType:"network",width:r[0],height:r[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,nodeCount:0,edgeCount:0,margin:s}),r=e.size||[500,500],s=ze({top:20,right:20,bottom:20,left:20,...e.margin},e.title),a=pe(e.title),l=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;if(!t)return[];const n=ie(e.nodes||[]);if(n.length>0)return Ea(n,t);const i=Array.isArray(e.edges)?ie(e.edges):[];if(0===i.length)return[];const r=Vl(e.sourceAccessor,"source"),s=Vl(e.targetAccessor,"target");return Ea(Array.from(new Set(i.flatMap(e=>[r(e),s(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];ol(s,{props:e,categories:l,theme:o,size:r,hasTitle:a});const c=r[0]-s.left-s.right,u=r[1]-s.top-s.bottom,d=ue(n);if(!d&&!e.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition.`);const h={chartType:n,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,childrenAccessor:e.childrenAccessor,hierarchySum:e.hierarchySum,orientation:e.orientation,nodeAlign:e.nodeAlign,nodePaddingRatio:e.nodePaddingRatio,nodeWidth:e.nodeWidth,iterations:e.iterations,forceStrength:e.forceStrength,padAngle:e.padAngle,groupWidth:e.groupWidth,sortGroups:e.sortGroups,edgeSort:e.edgeSort,treeOrientation:e.treeOrientation,edgeType:e.edgeType,padding:e.padding,paddingTop:e.paddingTop,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme||o.colors.categorical,edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,customNetworkLayout:e.customNetworkLayout,layoutConfig:e.layoutConfig};let p,g;if(Hl.has(n)){const n=e.data||e.edges;if(!n||Array.isArray(n))return t&&(t.evidence=i()),Dl.renderToStaticMarkup(rl(null,{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,idPrefix:e._idPrefix}));h.__hierarchyRoot=n,p=[],g=[]}else{const n=ie(e.nodes||[]),a=Array.isArray(e.edges)?ie(e.edges):[];if(0===n.length&&0===a.length)return t&&(t.evidence=i()),Dl.renderToStaticMarkup(rl(null,{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,idPrefix:e._idPrefix}));if(g=function(e,t){const o=Vl(t.sourceAccessor,"source"),n=Vl(t.targetAccessor,"target"),i=Vl(t.valueAccessor,"value");return e.map(e=>({source:o(e)+"",target:n(e)+"",value:Number(i(e))||1,y0:0,y1:0,sankeyWidth:0,data:e}))}(a,h),0===n.length&&g.length>0){const e=new Set;for(const t of g){const o=Qa(t.source),n=Qa(t.target);o&&e.add(o),n&&e.add(n)}p=Array.from(e).map(e=>({id:e,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:e}}))}else p=function(e,t){const o=Vl(t.nodeIDAccessor,"id");return e.map(e=>({id:o(e)+"",x:e.x??0,y:e.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:e}))}(n,h)}let m=[],f=[],y=[],b=null;if(h.customNetworkLayout){const e=h.colorScheme,t=Ne(e,o.colors.categorical,Pt),n=V(t,e),i={nodes:p,edges:g,dimensions:{width:c,height:u,plot:{x:0,y:0,width:c,height:u}},theme:{semantic:o.colors,categorical:[...t]},resolveColor:n,config:h.layoutConfig??{}},r=h.customNetworkLayout(i);m=r.sceneNodes??[],f=r.sceneEdges??[],y=r.labels??[],b=r.overlays??null}else if(d){d.computeLayout(p,g,h,[c,u]);const e=d.buildScene(p,g,h,[c,u]);m=e.sceneNodes,f=e.sceneEdges,y=e.labels}const x=Jt(o);for(const e of y)e.fill||(e.fill=x.text);const v=Ie({nodes:f,renderMode:e.renderMode,fallback:(e,t)=>ve(e,t)}),w=Ie({nodes:m,renderMode:e.renderMode,fallback:(e,t)=>we(e,t)});t&&(t.evidence=Sa({frameType:"network",width:r[0],height:r[1],marks:[...w.map(({node:e})=>({type:"node:"+(e.type??"node")})),...v.map(({node:e})=>({type:"edge:"+(e.type??"edge")}))],title:e.title,description:e.description,annotations:e.annotations,nodeCount:w.length,edgeCount:v.length,margin:s}));const A=v.map(e=>e.element),S=w.map(e=>e.element),k=y.map((e,t)=>xe(e,t)).filter(Boolean),M=e.annotations?Ga({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{},layout:{width:c,height:u},theme:o,idPrefix:e._idPrefix}):null,_=nl({props:e,categories:l,theme:o,size:r,margin:s,hasTitle:a});return Dl.renderToStaticMarkup(rl(Yl(Wl,{children:[e.backgroundGraphics,A,S,k,M,e.foregroundGraphics,b]}),{width:r[0],height:r[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:c,innerHeight:u,legend:_,idPrefix:e._idPrefix}))}import*as Xl from"react-dom/server";import{geoPath as ql}from"d3-geo";import{quadtree as Ul}from"d3-quadtree";import{geoMercator as Ql,geoEqualEarth as Zl,geoAlbersUsa as Kl,geoOrthographic as Jl,geoNaturalEarth1 as ec,geoEquirectangular as tc}from"d3-geo";var oc={mercator:Ql,equalEarth:Zl,albersUsa:Kl,orthographic:Jl,naturalEarth:ec,equirectangular:tc};function nc(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function ic(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function rc(e,t,o){return e?"function"==typeof e?{...o,...e(t)}:{...o,...e}:{...o}}function sc(e,t){if(2>e.length)return[e];const o=.4*t,n=[];let i=[e[0]];for(let t=1;e.length>t;t++){const r=e[t];Math.abs(r[0]-e[t-1][0])>o?(2>i.length||n.push(i),i=[r]):i.push(r)}return 2>i.length||n.push(i),n}function ac(e,t,o=24){const n=t[0]-e[0],i=t[1]-e[1],r=Math.sqrt(n*n+i*i);if(0===r)return[e,t];const s=-i/r,a=n/r,l=Math.min(.3*r,80),c=(e[0]+t[0])/2+s*l,u=(e[1]+t[1])/2+a*l,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*e[0]+2*r*i*c+i*i*t[0],r*r*e[1]+2*r*i*u+i*i*t[1]])}return d}function lc(e,t){if(2>e.length)return e;const o=t/2+1,n=[];for(let t=0;e.length>t;t++){const i=e[t];let r,s;0===t?(r=e[1][0]-i[0],s=e[1][1]-i[1]):t===e.length-1?(r=i[0]-e[t-1][0],s=i[1]-e[t-1][1]):(r=e[t+1][0]-e[t-1][0],s=e[t+1][1]-e[t-1][1]);const a=Math.sqrt(r*r+s*s)||1;n.push([i[0]+s/a*o,i[1]+-r/a*o])}return n}function cc(e,t,o,n,i){const r=t[0]-e[0],s=t[1]-e[1],a=Math.sqrt(r*r+s*s);if(0===a)return[e,t];const l=s/a,c=-r/a,u=i/2+1;return[[e[0]+l*u,e[1]+c*u],[t[0]+l*u,t[1]+c*u]]}import{scaleLinear as uc}from"d3-scale";var dc=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],hc=["scene-style","data-paint","accessibility","evidence"],pc=(e,t)=>({retainedData:e,invalidations:t}),gc=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],mc=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],fc=["scene-geometry","data-paint","accessibility","evidence"],yc=["scene-style","data-paint","accessibility","evidence"],bc=["overlay","accessibility","evidence"],xc=[],vc={xAccessor:pc("rebuild",gc),yAccessor:pc("rebuild",gc),lineDataAccessor:pc("rebuild",gc),pointIdAccessor:pc("rebuild",fc),lineIdAccessor:pc("rebuild",fc),windowSize:pc("rebuild",gc),projection:pc("preserve",mc),projectionExtent:pc("preserve",mc),fitPadding:pc("preserve",mc),lineType:pc("preserve",mc),flowStyle:pc("preserve",mc),graticule:pc("preserve",mc),projectionTransform:pc("preserve",mc),customLayout:pc("preserve",mc),layoutConfig:pc("preserve",mc),layoutMargin:pc("preserve",mc),areaStyle:pc("preserve",yc),pointStyle:pc("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:pc("preserve",yc),colorScheme:pc("preserve",yc),themeCategorical:pc("preserve",yc),themeDiverging:pc("preserve",yc),themeSemantic:pc("preserve",yc),themeSequential:pc("preserve",yc),decay:pc("preserve",yc),pulse:pc("preserve",yc),layoutSelection:pc("preserve",yc),annotations:pc("preserve",bc),autoPlaceAnnotations:pc("preserve",bc),clock:pc("preserve",xc),transition:pc("preserve",xc),introAnimation:pc("preserve",xc),onLayoutError:pc("preserve",xc)},wc=pc("preserve",mc),Ac=class{constructor(){this.tracker=new mt}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},dc)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},hc):this.recordNoop("restyle")}recordConfig(e,t={}){const o=function(e){let t="preserve";const o=new Set;for(const n of e){const e=vc[n]??wc;"rebuild"===e.retainedData&&(t="rebuild");for(const t of e.invalidations)o.add(t)}return{retainedData:t,invalidations:o}}(e),n=new Set(o.invalidations);return t.retainedDataChanged&&n.add("data"),this.tracker.record({kind:"config",keys:e},n)}};import{geoDistance as Sc,geoGraticule as kc,geoInterpolate as Mc}from"d3-geo";function _c(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&.5>e)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${e+""}.`)}var Pc=class e{constructor(e){this.updateResults=new Ac,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(e){return{...e,fitPadding:_c(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??Me()}getConfiguredWindowSize(){const e=this.config.windowSize??500;if(!Number.isInteger(e)||1>e)throw Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){const t=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],n=t.slice(-e),i=o.slice(-n.length),r=this.currentTime();this.pointBuffer=new ut(e),this.timestampBuffer=new ut(e),n.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(i[t]??r)})}this.retainNewestLines(e)}updateConfig(e){const t=function(e){return"fitPadding"in e?{...e,fitPadding:_c(e.fitPadding)}:e}(e),o=this.config,n=this.getConfiguredWindowSize(),i=Object.keys(t).filter(e=>t[e]!==o[e]);this.config={...this.config,...t};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==n;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(i,{retainedDataChanged:s})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});const t=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,n=this.timestampBuffer?.toArray()??[],i=o.slice(-t),r=n.slice(-i.length),s=this.currentTime();this.pointBuffer=new ut(t),this.timestampBuffer=new ut(t),i.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(r[t]??s)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();Pe(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();const t=this.currentTime();for(const o of e)Pe(this.pointBuffer,o,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");const t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(const e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){const{lineIdAccessor:t}=this.config;if(!t)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof t?t:e=>e[t],n=new Set(Array.isArray(e)?e:[e]),i=[];return this.lineData=this.lineData.filter(e=>!n.has(o(e)+"")||(i.push(e),!1)),i.length>0?(this.version++,this.updateResults.recordData("remove",i.length)):this.updateResults.recordNoop("remove"),i}getLines(){return this.lineData.slice()}removePoint(e){const{pointIdAccessor:t}=this.config;if(!t)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof t?t:e=>e[t],n=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){const e=e=>n.has(o(e)+"");G(this.pointBuffer,this.timestampBuffer,e);const t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{const e=[];return this.pointData=this.pointData.filter(t=>!n.has(o(t)+"")||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){const t=this._customRestyle;if(t){for(const o of this.scene){const n=this._baseStyles.get(o)??o.style,i=t(o,e);o.style=i?{...n,...i}:n}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){const{config:t}=this,o=this.projection,n=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],l=this.scene;this.projection=function(e){if(!e)return Zl();if("string"==typeof e){const t=oc[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),Zl())}if("object"==typeof e&&"type"in e){const t=oc[e.type],o=t?t():Zl();return e.rotate&&"rotate"in o&&o.rotate(e.rotate),e.center&&"center"in o&&o.center(e.center),o}return e}(t.projection),this.geoPath=ql(this.projection),this.fitProjection(e),this.geoPath=ql(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(e,t)=>c([e,t]),invertedPoint:(e,t)=>c.invert?c.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=n,this.scales=i,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){const t=e.width/2,o=e.height/2,n=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:o}));n.length>0&&this.startTransition(n)}this._hasRenderedOnce=!0,t.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(e){const t=this.projection,o=this.config,n=[...this.areas],i=nc(o.xAccessor,"lon"),r=nc(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const e=s.map(e=>[i(e),r(e)]);n.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}const a=ic(o.lineDataAccessor);for(const e of this.lineData){const t=a(e);if(t&&t.length>0){const e=t.map(e=>[i(e),r(e)]);n.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==n.length){if(o.projectionExtent){const[[n,i],[r,s]]=o.projectionExtent;t.fitExtent([[0,0],[e.width,e.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[n,i],[n,s],[r,s],[r,i],[n,i]]]}})}else if(t.clipAngle&&(t.clipAngle()??0)>0){const n=o.fitPadding??0,i=Math.min(e.width,e.height);t.scale(i/2-i*n),t.translate([e.width/2,e.height/2])}else{const i=o.fitPadding??0,r=e.width*i,s=e.height*i;t.fitExtent([[r,s],[e.width-r,e.height-s]],{type:"FeatureCollection",features:n})}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e.k),o.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=ql(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*e),o.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=ql(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){const o=this.projection;if(!o||!o.rotate)return;const n=this.geoPath,i=this.scales,r=[...o.rotate()];o.rotate(e),this.geoPath=ql(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(e,t)=>o([e,t]),invertedPoint:(e,t)=>o.invert?o.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(r),this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){const t=this.projection;t&&t.rotate&&t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let t=0,o=0;for(const e of this.scene)"point"===e.type&&!1!==e.interactive&&(o++,e.r>t&&(t=e.r));if(this._maxPointRadius=t,e.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const n=Array(o);let i=0;for(const e of this.scene)"point"===e.type&&!1!==e.interactive&&(n[i++]=e);this._quadtree=Ul().x(e=>e.x).y(e=>e.y).addAll(n)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;const{config:t}=this,o=this.projection,n=this.geoPath;if(t.customLayout&&this.scales){const o=t.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Ne(t.colorScheme,t.themeCategorical,F),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:o,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...n]},resolveColor:V(n,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null};let r;try{r=t.customLayout(i)}catch(e){const o=null!==this.lastCustomLayoutResult,n=ee("geo",e,o,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",e);try{t.onLayoutError?.(n)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return o?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const e of s)this._baseStyles.set(e,e.style);this.restyleScene(t.layoutSelection??null)}return st({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:e,projection:t,path:o,areas:n,points:i,lines:r,layout:s}){const a=nc(e.xAccessor,"lon"),l=nc(e.yAccessor,"lat"),c=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),d=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),h=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){const t=!0===e.graticule?{}:e.graticule,n=kc();t.step&&n.step(t.step);const i=o(n())||"";i&&c.push({type:"geoarea",pathData:i,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth||.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const t of n){const n=o(t);if(!n)continue;const i=o.centroid(t),r=o.bounds(t),s=o.area(t);c.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:rc(e.areaStyle,t,u),datum:t,interactive:!0})}const p=ic(e.lineDataAccessor);for(const o of r){const n=p(o);if(!n||2>n.length)continue;let i=[];if("geo"===e.lineType){const e=Array(n.length);for(let t=0;n.length>t;t++)e[t]=[a(n[t]),l(n[t])];for(let o=0;e.length-1>o;o++){const n=e[o],r=e[o+1],s=Sc(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Mc(n,r);for(let e=0;a>=e;e++){if(o>0&&0===e)continue;const n=t(l(e/a));null!=n&&i.push(n)}}}else for(let e=0;n.length>e;e++){const o=n[e],r=t([a(o),l(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=rc(e.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==n.length||2>i.length||"arc"!==e.flowStyle?2!==n.length||2>i.length||"offset"!==e.flowStyle||(i="geo"===e.lineType?lc(i,u):cc(i[0],i[i.length-1],0,0,u)):i=ac(i[0],i[i.length-1]);const h=sc(i,s.width);if(h.length>1)for(const e of h)2>e.length||c.push({type:"line",path:e,style:{...r,_edgeFade:!0},datum:o});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const g=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,m=t.clipAngle?t.clipAngle()??0:0,f=m>0?m*Math.PI/180:null,y=t.rotate?t.rotate():[0,0,0],b="function"==typeof t.center?t.center():[0,0],x=[(b[0]??0)-y[0],(b[1]??0)-y[1]];for(const o of i){const n=a(o),i=l(o);if(null!=f&&Sc([n,i],x)>f)continue;const r=t([n,i]);if(!r)continue;const s=e.pointStyle?e.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:g?g(o)+"":void 0};c.push(u)}return c}({config:t,projection:o,path:n,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){const o=function(e,t,o,n){const i=e.filter(e=>"point"===e.type);if(2>i.length)return null;const r=t.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===t.layout?"strip":"radial";if("radial"===a&&0===s)return null;const l=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=i.find(e=>e.datum&&l(e.datum)+""==t.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;const d=i.map(e=>e.datum?Number(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),h=zt(d,1);n>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){const o=e[t];"geoarea"===o.type&&o.interactive&&e.splice(t,1)}const p="strip"===a?function(e,t,o,n,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,l=uc().domain([0,n]).range([0,s]);t.x=r,t.y=a;const c=[];for(const i of e){if(i===t)continue;if(!i.datum){i.x=r,i.y=a;continue}const e=Number(o(i.datum)),s=r+(isFinite(e)&&e>=0&&n>0?l(e):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((e,t)=>e.x-t.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let e=d+1;for(;c.length>e&&3>Math.abs(c[e].x-c[d].x);)e++;const t=e-d;if(t>1&&u>0)for(let e=0;t>e;e++)c[d+e].node.y=a+(e-(t-1)/2)*Math.min(2.5,2*u/Math.max(1,t-1));d=e}return{cx:r,cy:a,maxCost:n,availableRadius:s,layout:"strip"}}(i,u,c,h,o):function(e,t,o,n,i,r){const s=t.x,a=t.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=uc().domain([0,n]).range([0,u]);for(const r of e){if(r===t)continue;if(!r.datum)continue;const e=r.x,u=r.y,h=Math.atan2(u-a,e-s),p=Math.hypot(e-s,u-a),g=Number(o(r.datum)),m=isFinite(g)&&g>=0?n>0?d(g):0:p,f=l+Math.cos(h)*m,y=c+Math.sin(h)*m;r.x=e+(f-e)*i,r.y=u+(y-u)*i}return t.x=s+(l-s)*i,t.y=a+(c-a)*i,{cx:t.x,cy:t.y,maxCost:n,availableRadius:u,layout:"radial"}}(i,u,c,h,s,o),g=e.filter(e=>"line"===e.type);if(g.length>0){const e=new Map;for(const t of i)null!=t.pointId&&e.set(t.pointId+"",[t.x,t.y]);for(const o of g){const n=o.datum?.source,i=o.datum?.target;if(null!=n&&null!=i){const r=e.get(n+""),s=e.get(i+"");if(r&&s)if("fractional"===t.lineMode&&o.path.length>2){const e=o.path[0],t=o.path[o.path.length-1],n=[r[0]-e[0],r[1]-e[1]],i=[s[0]-t[0],s[1]-t[1]],a=[0];for(let e=1;o.path.length>e;e++)a.push(a[e-1]+Math.hypot(o.path[e][0]-o.path[e-1][0],o.path[e][1]-o.path[e-1][1]));const l=a[a.length-1];o.path=o.path.map((e,t)=>{const r=l>0?a[t]/l:t/(o.path.length-1);return[e[0]+n[0]*(1-r)+i[0]*r,e[1]+n[1]*(1-r)+i[1]*r]})}else o.path=[r,s]}}}return p}(this.scene,e,t,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const e=this.config.decay;if(!e||!this.pointBuffer)return;const t=this.pointBuffer.size;if(0===t)return;const o=this.scene.filter(e=>"point"===e.type);for(let n=0;o.length>n;n++){const i=q(e,n,t);o[n]._decayOpacity=i,o[n].style={...o[n].style,opacity:i}}}applyPulse(e=this.currentTime()){const t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;const o=this.scene.filter(e=>"point"===e.type),n=this.timestampBuffer.toArray(),i=t.color||"rgba(255,255,255,0.6)",r=t.glowRadius??4;let s=!1;for(let a=0;o.length>a&&n.length>a;a++){const l=Q(t,n[a],e);s=Ue(o[a],l,i,r)||s}return s}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&he(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){const t=this.config.transition?.duration??300;if(0>=t)return;const o=new Map;for(const t of e)"point"===t.type&&t.pointId&&o.set(t.pointId,[t.x,t.y]);const n=this.scene.filter(e=>"point"===e.type);let i=!1;for(const e of n)if(e.pointId){const t=o.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(i=!0))}for(const e of n)e.pointId&&!o.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??e.style?.fillOpacity??1,e.style={...e.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null;for(const e of this.scene)"point"===e.type&&(null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0),null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0))}advanceTransition(e){if(!this.activeTransition)return!1;const t=Z(e,this.activeTransition),o=U(t),n=this.scene.filter(e=>"point"===e.type);for(const e of n){if(null!=e._targetX&&null!=e._targetY){const t=e.y;e.x=be(e.x,e._targetX,o),e.y=be(t,e._targetY,o)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*o})}if(t>=1){for(const e of n)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Pc.QUADTREE_THRESHOLD=500;var Tc=Pc;j(Tc);import{Fragment as Lc,jsxs as Rc}from"react/jsx-runtime";function Ic(e,t){const o=Kt(e.theme),n=e.size||[e.width||600,e.height||400],i=ze({top:10,right:10,bottom:10,left:10,...e.margin},e.title),r=pe(e.title),s=Array.isArray(e.areas)?ie(e.areas):e.areas,a=ie(e.points),l=ie(e.lines),c=e.showLegend?(()=>{const t="string"==typeof(o=e.colorBy)||"function"==typeof o?e.colorBy:void 0;var o;return Ea(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof t?s.map(e=>({...e.properties||{},...e})):s:[],t)})():[];ol(i,{props:e,categories:c,theme:o,size:n,hasTitle:r});const u=n[0]-(i.left??0)-(i.right??0),d=n[1]-(i.top??0)-(i.bottom??0),h={projection:e.projection||"equalEarth",xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineType:e.lineType,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:i,themeCategorical:o.colors.categorical,themeSemantic:Dt(o)},p=new Tc(h);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);p.setAreas(s)}e.points&&p.setPoints(a),e.lines&&p.setLines(l),p.computeScene({width:u,height:d});const g=Ie({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>ae(e,t)});if(t&&(t.evidence=Sa({frameType:"geo",width:n[0],height:n[1],marks:g.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,legendItems:c.length>0?c.length:void 0,margin:i})),0===g.length){const t=e.backgroundGraphics||e.foregroundGraphics||e.annotations||p.customLayoutOverlays?Rc(Lc,{children:[e.backgroundGraphics,e.annotations?Ga({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([e,t])=>p.scales.projectedPoint(e,t):void 0},layout:{width:u,height:d},theme:o,idPrefix:e._idPrefix}):null,e.foregroundGraphics,p.customLayoutOverlays]}):null;return Xl.renderToStaticMarkup(rl(t,{width:n[0],height:n[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,idPrefix:e._idPrefix}))}const m=g.map(e=>e.element),f=e.annotations?Ga({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([e,t])=>p.scales.projectedPoint(e,t):void 0},layout:{width:u,height:d},theme:o,idPrefix:e._idPrefix}):null,y=nl({props:e,categories:c,theme:o,size:n,margin:i,hasTitle:r});return Xl.renderToStaticMarkup(rl(Rc(Lc,{children:[e.backgroundGraphics,m,f,e.foregroundGraphics,p.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:u,innerHeight:d,legend:y,idPrefix:e._idPrefix}))}import*as Cc from"react-dom/server";function zc(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}var Fc={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Oc(e){const t=e.datum;if(t&&"object"==typeof t){const e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Bc(e,t){const o="function"==typeof t?t(e):t;return{...Fc,...o??{}}}function Nc(e,t={}){return e.map(e=>function(e,t={}){const o=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),n={label:t.getBodyLabel?.(e)??Oc(e)},i={style:Bc(e,t.bodyStyle),datum:o,accessibleDatum:o,accessibility:n,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...i}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...i}}(e,t))}import{jsx as Ec,jsxs as jc}from"react/jsx-runtime";var $c={top:0,right:0,bottom:0,left:0};function Dc(e,t,o){return"function"==typeof e?e({size:t,margin:o}):e}function Wc(e,t){const o=e.size??[e.width??600,e.height??400],n=new d(e.config);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&n.enqueue(e.initialSpawns.map(e=>({...e,spawnAt:void 0})));const i=function(e,t={}){const{width:o=640,height:n=360,title:i,description:r,background:s,backgroundGraphics:a,className:l,foregroundGraphics:c,idPrefix:u="physics",margin:d,renderBodySVG:h,...p}=t,g=function(e,t={}){const o=e.settle(t.maxSteps),n=e.readBodies(),i=e.snapshot(),r=Nc(n,t),s=function(e,t={}){const o=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),n=o.filter(e=>e.sleeping).length,i=e.queue.length,r=e.sediment.reduce((e,t)=>e+t.count,0),s="settled"===e.simulationState&&0===i&&n===o.length,a=[];i>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const l=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,o,n){const i=e-(t+o+n);return{charge:e,live:t,queued:o,sedimented:n,unaccounted:i,balanced:0===i}}(t.charge,o.length,i,r):void 0;return l&&!l.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:o.length,sleepingCount:n,settled:s,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:zc(t.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},warnings:a}}(i,{bodies:n,projectionRows:t.projectionRows,stepsRun:o,charge:t.charge});return{snapshot:i,bodies:n,sceneNodes:r,evidence:s,stepsRun:o}}(e,p),m={...$c,...d},f=[o,n],y=Dc(a,f,m),b=Dc(c,f,m),x=function(e){const t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(u),v=i?x+"-title":void 0,w=r?x+"-desc":void 0,A=[v,w].filter(Boolean).join(" ")||void 0;return{svg:Cc.renderToStaticMarkup(jc("svg",{xmlns:"http://www.w3.org/2000/svg",className:l??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":A,children:[i&&Ec("title",{id:v,children:i}),r&&Ec("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?Ec("rect",{x:0,y:0,width:o,height:n,fill:s}):null,y,Ec("g",{id:x+"-data-area",children:g.sceneNodes.map((e,t)=>{const o=g.bodies[t];return(o&&h?h(o,e.style??{},t,x):void 0)??at(e,t,x)})}),b]})),scene:g,evidence:g.evidence}}(n,{...e,width:o[0],height:o[1],charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics"});return t&&(t.evidence=Sa({frameType:"physics",width:o[0],height:o[1],marks:i.scene.sceneNodes,title:e.title,description:e.description,annotations:[],extraWarnings:[...0===i.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...i.scene.evidence.warnings]})),i.svg}import*as Yc from"react-dom/server";import{jsx as Vc,jsxs as Hc}from"react/jsx-runtime";var Gc={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function Xc(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}var qc={BigNumber:function(e,t){const o="presentation"===e.mode||"inline"===e.mode||"thumbnail"===e.mode?e.mode:"tile",n=Gc[o],i=Xc(e.width,n.width),r=Xc(e.height,n.height),s="number"==typeof e.padding&&Number.isFinite(e.padding)?Math.max(0,e.padding):n.padding,a="center"===e.align||"end"===e.align||"start"===e.align?e.align:n.align,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=Kt(e.theme),d="number"==typeof e.value&&Number.isFinite(e.value)?e.value:void 0,h=function(e,t={}){if("function"==typeof e)return e;const o=t.locale??"en-US";if("currency"===e){const e=t.precision??2,n=new Intl.NumberFormat(o,{style:"currency",currency:t.currency??"USD",maximumFractionDigits:e,minimumFractionDigits:e});return e=>n.format(e)}if("percent"===e){const e=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("compact"===e){const e=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("duration"===e)return e=>function(e){if(!Number.isFinite(e))return e+"";const t=0>e?"-":"",o=Math.abs(e);if(1e3>o)return`${t}${Math.round(o)}ms`;const n=o/1e3;if(60>n)return`${t}${i=n,Math.round(100*i)/100+""}s`;var i;const r=n/60;if(60>r){const e=Math.floor(r),o=Math.round(n-60*e);return 0===o?`${t}${e}m`:`${t}${e}m ${o}s`}const s=r/60;if(24>s){const e=Math.floor(s),o=Math.round(r-60*e);return 0===o?`${t}${e}h`:`${t}${e}h ${o}m`}const a=Math.floor(s/24),l=Math.round(s-24*a);return 0===l?`${t}${a}d`:`${t}${a}d ${l}h`}(e);const n=new Intl.NumberFormat(o,{notation:t.notation??"standard",maximumFractionDigits:t.precision??0,minimumFractionDigits:0});return e=>n.format(e)}("string"==typeof e.format||"function"==typeof e.format?e.format:"number",{locale:"string"==typeof e.locale?e.locale:void 0,currency:"string"==typeof e.currency?e.currency:void 0,precision:"number"==typeof e.precision?e.precision:void 0}),p=void 0===d?"No value":(g=h(d),`${("string"==typeof e.prefix?e.prefix:void 0)??""}${g}${("string"==typeof e.suffix?e.suffix:void 0)??""}`);var g;const m=void 0===d?void 0:function(e,t){if(!t||0===t.length)return null;if(!Number.isFinite(e))return null;const o=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at);let n=null;for(const t of o){if(t.at>e)break;n=t}return n}(d,e.thresholds),f="string"==typeof e.color?e.color:function(e,t,o){return t||("success"===e?o.colors.success??"#2ca02c":"warning"===e?o.colors.warning??"#b26a00":"danger"===e?o.colors.danger??"#d62728":"info"===e?o.colors.info??o.colors.primary:o.colors.text)}(m?.level??"neutral",m?.color,u),y="string"==typeof e.label?e.label:void 0,b="string"==typeof e.caption?e.caption:void 0,x="string"==typeof e.unit?e.unit:void 0,v=void 0===d?void 0:function(e,t,o){const n=e.comparison&&"object"==typeof e.comparison?e.comparison:void 0,i=n&&"number"==typeof n.value&&Number.isFinite(n.value)?n.value:void 0,r=("number"==typeof e.delta&&Number.isFinite(e.delta)?e.delta:void 0)??(void 0===i?void 0:t-i);if(void 0===r)return;const s=function(e,t){return Number.isFinite(e)?0===e?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}(r,o);return`${s}${n&&"string"==typeof n.label?" "+n.label:""}`}(e,d,h),w=void 0===d?void 0:function(e,t,o){const n=e.target&&"object"==typeof e.target?e.target:void 0;if(!n||"number"!=typeof n.value||!Number.isFinite(n.value))return;const i="string"==typeof n.label?" "+n.label:"";return 0===n.value?`target ${o(n.value)}${i}`:`${new Intl.NumberFormat("string"==typeof e.locale?e.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(t/n.value)} of ${o(n.value)}${i}`}(e,d,h),A=[v,w,m?.label].filter(Boolean).join(" · "),S="string"==typeof e.description&&e.description||[y,p,x,A].filter(Boolean).join(", "),k="string"==typeof e.background?e.background:u.colors.surface??u.colors.background,M="string"==typeof e.borderColor?e.borderColor:u.colors.border,_=s+n.labelSize,P=_+n.captionSize+4,T="presentation"===o?r/2+.32*n.valueSize:"thumbnail"===o?r/2+.34*n.valueSize:Math.min(r-s-(A?26:4),(n.showHeader&&(y||b)?b?P+10:_+14:s)+n.valueSize),L=c+("start"===l?Math.max(n.valueSize,p.length*n.valueSize*.55):0),R=Yc.renderToStaticMarkup(Hc("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-label":S,"data-semiotic-component":"BigNumber",children:[Vc("title",{children:y??p}),"string"==typeof e.description&&Vc("desc",{children:e.description}),Vc("rect",{x:n.border?.5:0,y:n.border?.5:0,width:n.border?i-1:i,height:n.border?r-1:r,rx:n.border?8:0,fill:k,stroke:n.border?M:"none"}),n.showHeader&&y&&Vc("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:y}),n.showHeader&&b&&Vc("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:b}),Vc("text",{x:c,y:T,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:f,"data-mark-type":"value",children:p}),x&&void 0!==d&&"start"===l&&Vc("text",{x:L+6,y:T,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*n.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:x}),n.showDetail&&A&&Vc("text",{x:c,y:Math.min(r-s,T+n.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:A})]}));return t&&(t.evidence=Sa({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:y,description:S})),R}};function Uc(e,t,o){return qc[e](t,o)}import{Fragment as Qc,jsx as Zc,jsxs as Kc}from"react/jsx-runtime";function Jc(e,t){switch(e){case"xy":return cl(t);case"ordinal":return $l(t);case"network":return Gl(t);case"geo":return Ic(t);case"physics":return Wc(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function eu(e){return cl(e)}function tu(e){return $l(e)}function ou(e){return Gl(e)}function nu(e){return Ic(e)}var iu=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],ru=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function su(e,t){const o={};for(const n of t)void 0!==e[n]&&(o[n]=e[n]);return o}function au(e,t,o){return cu(e,t).svg}function lu(e,t,o){const n={},{svg:i,frameType:r}=cu(e,t,0,n),s=n.evidence??Sa({frameType:r,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=e,{svg:i,evidence:s}}function cu(e,t,o,n){if(e in qc)return{svg:Uc(e,t,n),frameType:"value"};const i=va[e];if(!i)throw Error(`Unknown chart component: "${e}". See CLAUDE.md for supported chart types.`);const r=i.layout?.mode??(ge(t.mode)?t.mode:void 0),s=Be(r,{...i.layout?.modeDefaults,...su(t,ru)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:p,colorBy:g,legendPosition:m,...f}=t,{width:y,height:b}=s,x=[y,b],v=f.frameProps||{},w=i.layout?.margin,A="function"==typeof w?w(t,s):w??s.marginDefaults,S=void 0!==h?h:v.margin,k=Yt(S),M="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...A,...k},_=su(f,iu),P=e=>v[e]??s[e],T={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:x,margin:M,__explicitMargin:S,__autoLegendMargin:!0,...void 0!==p&&{colorScheme:p},...void 0!==m&&{legendPosition:m},_idPrefix:f._idPrefix},L=i.buildProps(a,g,p,T,f);let R;switch(i.frameType){case"xy":R=cl(L,n);break;case"ordinal":R=$l(L,n);break;case"network":R=Gl(L,n);break;case"geo":R=Ic(L,n);break;case"physics":R=Wc(L,n)}const I=i.renderOverlay?.(L,{theme:Kt(l)});if(null!=I){const e=Vt.renderToStaticMarkup(Zc(Qc,{children:I}));R=R.replace("</svg>",e+"</svg>")}return{svg:R,frameType:i.frameType}}function uu(e,t={}){const{title:o,subtitle:n,theme:i,width:r=1200,height:s,layout:a={},background:l}=t,c=Jt(Kt(i)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),n&&(h+=20),h>0&&(h+=10);const p=Math.floor((r-d-d*(u-1))/u),g=[];let m=0,f=h+d,y=0;for(const t of e){const e=Math.min(t.colSpan||1,u),o=t.props.height||300;m+e>u&&(f+=y+d,m=0,y=0),g.push({chart:t,x:d/2+m*(p+d),y:f,w:p*e+d*(e-1),h:o}),y=Math.max(y,o),m+=e}const b=s||f+y+d,x=g.map((e,t)=>{const{chart:o,x:n,y:r,w:s,h:a}=e,l={...o.props,width:s,height:a,theme:i,_idPrefix:"chart-"+t};let c;return c=o.component?au(o.component,l):o.frameType?Jc(o.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,Zc("g",{transform:`translate(${n},${r})`,children:Zc("foreignObject",{width:s,height:a,children:Zc("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+t)});return Vt.renderToStaticMarkup(Kc("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:c.fontFamily},children:[o&&Zc("title",{children:o}),l&&Zc("rect",{x:0,y:0,width:r,height:b,fill:l}),o&&Zc("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleSize+4,fontWeight:"bold",fill:c.text,fontFamily:c.fontFamily,children:o}),n&&Zc("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:n}),x]}))}import*as du from"react-dom/server";import{Fragment as hu,jsx as pu,jsxs as gu}from"react/jsx-runtime";function mu(e,t,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=n,p=o.width||600,g=o.height||400,m=Kt(o.theme),f={...o,...a&&{xExtent:a},...l&&{yExtent:l}};if(!t||0===t.length)return[];const y=i||Math.max(1,Math.ceil(t.length/(s||Math.min(60,Math.max(10,t.length))))),b=[];for(let e=y;t.length>=e;e+=y)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);const x=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),v=ze({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=p-v.left-v.right,A=g-v.top-v.bottom,S=[];if(x)for(let n=0;b.length>n;n++){const i=b[n],s=t.slice(r?Math.max(0,i-r):0,i),a={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||m.colors.categorical,...h&&{decay:h}},l=new Fl(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:A}),l.scene.length>0&&S.push(wu(l.scene,p,g,m,f))}else for(let n=0;b.length>n;n++){const i=b[n],s=t.slice(r?Math.max(0,i-r):0,i),y={chartType:e,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:l,colorScheme:o.colorScheme||m.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},x=new z(y);if(x.ingest({inserts:s,bounded:!0}),x.computeScene({width:w,height:A}),0===x.scene.length)continue;const v=x.scales?{y:x.scales.y}:void 0;if(S.push(vu(x.scene,p,g,m,f,v)),c>0&&n>0&&x.activeTransition){const e=c*(1e3/u);for(let t=1;c>=t;t++)x.advanceTransition(x.activeTransition.startTime+t/c*e),S.push(vu(x.scene,p,g,m,f,v))}}return S}function fu(e,t,o={}){return t.map(t=>{try{return au(e,{...o,...t})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||t.width||600}" height="${o.height||t.height||400}"></svg>`}})}function yu(e,t,o){const n=t.size??[t.width??600,t.height??400],i=Kt(t.theme),r=Jt(i),s=t.background||i.colors.background,a=t.idPrefix??"physics-gif",l=t.title?`${a}-title-${o}`:void 0,c=t.description?`${a}-desc-${o}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=Nc(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),h=gu("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[t.title&&pu("title",{id:l,children:t.title}),t.description&&pu("desc",{id:c,children:t.description}),s&&"transparent"!==s?pu("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,pu("g",{id:`${a}-frame-${o}`,children:d.map((e,t)=>at(e,t,`${a}-${o}`))})]});return du.renderToStaticMarkup(h)}function bu(e,t={}){const{fps:o=12,frameCount:n,durationSeconds:i=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:l}=t,c=Math.max(.001,s??e.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/c)),h=n??Math.max(1,Math.ceil(i*Math.max(1,o))),p=l?{...e,background:l}:e,g=new d(e.config);e.initialSpawns?.length&&g.enqueue(e.initialSpawns,e.initialSpawnPacing);const m=[];for(r&&(g.tick(0),m.push(yu(g,p,0)));h>m.length;){for(let e=0;u>e;e+=1)g.tick(c);m.push(yu(g,p,m.length))}return m}function xu(e,t){const o=e.background||t.colors.background;return o&&"transparent"!==o?o:null}function vu(e,t,o,n,i,r){const s=Jt(n),a=ze({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=t-a.left-a.right,c=o-a.top-a.bottom,u=xu(i,n),d=i.renderMode,h=e.map((e,t)=>Ce({node:e,index:t,renderMode:d,fallback:()=>at(e,t)})).filter(Boolean),p=function(e,t,o,n,i,r){if(!e||0===e.length)return null;const s=Jt(n),a=[];for(let n=0;e.length>n;n++){const l=e[n];if("y-threshold"===l.type&&null!=l.value){let e=null;if(r)e=r(l.value);else if(i){const[t,n]=i,r=n-t;if(0===r)continue;e=o-(l.value-t)/r*o}if(null==e)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push(gu("g",{children:[pu("line",{x1:0,y1:e,x2:t,y2:e,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&pu("text",{x:"left"===u?4:"center"===u?t/2:t-4,y:20>e?Math.min(o-4,e+16):e-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+n))}}return a.length>0?pu(hu,{children:a}):null}(i.annotations,l,c,n,i.yExtent,r?.y),g="string"==typeof i.title?i.title:void 0,m="string"==typeof i.description?i.description:void 0,f=g?"semiotic-title":void 0,y=m?"semiotic-desc":void 0,b=[f,y].filter(Boolean).join(" ")||void 0;return du.renderToStaticMarkup(gu("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":b,style:{fontFamily:s.fontFamily},children:[g&&pu("title",{id:f,children:g}),m&&pu("desc",{id:y,children:m}),u&&pu("rect",{x:0,y:0,width:t,height:o,fill:u}),gu("g",{transform:`translate(${a.left},${a.top})`,children:[p,h]}),g&&pu("text",{x:t/2,y:E,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:g})]}))}function wu(e,t,o,n,i){const r=Jt(n),s=ze({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(t-s.left-s.right)/2:s.left,c=a?s.top+(o-s.top-s.bottom)/2:s.top,u=xu(i,n),d=i.renderMode,h=e.map((e,t)=>Ce({node:e,index:t,renderMode:d,fallback:()=>_e(e,t)})).filter(Boolean),p="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,m=p?"semiotic-title":void 0,f=g?"semiotic-desc":void 0,y=[m,f].filter(Boolean).join(" ")||void 0;return du.renderToStaticMarkup(gu("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:o,role:"img","aria-labelledby":y,style:{fontFamily:r.fontFamily},children:[p&&pu("title",{id:m,children:p}),g&&pu("desc",{id:f,children:g}),u&&pu("rect",{x:0,y:0,width:t,height:o,fill:u}),pu("g",{transform:`translate(${l},${c})`,children:h}),p&&pu("text",{x:t/2,y:E,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:p})]}))}export{mu as generateFrameSVGs,fu as generateFrameSequence,bu as generatePhysicsFrameSVGs,au as renderChart,lu as renderChartWithEvidence,uu as renderDashboard,nu as renderGeoToStaticSVG,ou as renderNetworkToStaticSVG,tu as renderOrdinalToStaticSVG,Jc as renderToStaticSVG,eu as renderXYToStaticSVG,Kt as resolveTheme,Jt as themeStyles};
1
+ import{PhysicsPipelineStore as t,SEQUENTIAL_INTERPOLATORS as e,UpdateResultTracker as o,absorbRegion as n,annotationLayout as i,bodyGroupSpec as r,capacitatedRegion as s,collidersFromPlotBounds as a,collidersFromXScaleBins as l,countPairwiseCrossings as c,forceFieldRegion as u,forceLayoutPlugin as d,getSequentialInterpolator as h,glyphFractionClipRect as p,glyphHitGeometry as f,glyphPlacement as g,groupCompletionRows as y,interpolateBrBG as m,interpolatePRGn as x,interpolatePiYG as b,interpolateRdBu as v,interpolateRdYlBu as w,interpolateRdYlGn as k,interpolateSpectral as A,interpolateViridis as S,isInBounds as M,makeSymbolResolver as _,orderByBarycenter as P,orderExactSmall as L,packBandsBySilhouette as $,placeWithMinGap as R,portalRegion as C,pressureFieldRegion as T,processChrome as O,processStageLayout as I,refineByAdjacentSwaps as z,resolveAnchoredPosition as F,resolveGlyphPaint as N,resolveX as E,resolveY as D,routeSurfaceRegion as W,schemeCategory10 as B,schemeSet3 as j,schemeTableau10 as Y,symbolPathString as X,symbolRadius as G,useCustomLayoutSelection as V,wrapWithDataHint as H}from"./c-LIXGXMNS.min.js";import{IncrementalExtent as q,RingBuffer as U,annotationStableId as K,coerceDateLikeValue as Z,composeStyleRules as Q,computeArcBoundingBox as J,darkenColor as tt,hatchPatternDef as et,isHatchFill as ot,isTimeLandmark as nt,lightenColor as it,makeNodeRuleContext as rt,makeRuleValueResolver as st,makeXYRuleContext as at,parseDateLikeString as lt,resolveAnnotationGradient as ct,resolveResponsiveRules as ut,resolveStyleRules as dt,resolveSvgFill as ht,styleRulesToNodeStyle as pt,sweepToAngles as ft}from"./c-4TWEX5HG.min.js";import"./c-SUILCHWU.min.js";import{filterAnnotationsByStatus as gt}from"./c-E3JFRRMI.min.js";import{accessorsEquivalent as yt,resolveAccessor as mt,resolveLabelFn as xt,resolveNodeRefId as bt,resolveRawAccessor as vt,resolveStringAccessor as wt}from"./c-MT3WBK7M.min.js";import{getMax as kt,getMin as At,getMinMax as St}from"./c-GGISSW5E.min.js";import"./c-COHXCW3Q.min.js";import{DARK_THEME as Mt,HIGH_CONTRAST_THEME as _t,LIGHT_THEME as Pt,applyThemeAccessibility as Lt,resolveThemePreset as $t,resolveThemeSemanticColors as Rt,themeToCSSVariables as Ct}from"./c-O6U6K4CW.min.js";var Tt={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function Ot(t,e={}){const o=e.mobileSemantics?.interaction,n="number"==typeof o?.targetSize?o.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,i="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!o||void 0!==n,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!i&&!r)return Tt;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??n??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var It={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function zt(t,e,o){if(!1!==e)return t;const n={...t};return"horizontal"===o?n.left=Math.min(n.left,15):n.bottom=Math.min(n.bottom,15),n}function Ft(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var Nt={kind:"rank-competition"};function Et(t,e,o,n){const i=t??e;return"function"==typeof i?i(o,n):o[i+""]}var Dt=Symbol.for("semiotic.semantic-viability"),Wt=globalThis,Bt=Wt[Dt]??(Wt[Dt]=new Map);function jt(t){return"string"==typeof t?.code&&t.code.length>0&&("warning"===t.severity||"error"===t.severity)&&"string"==typeof t.message&&t.message.length>0}function Yt(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const n=function(t){return function(t){return Bt.has(t)}(t)?function(t){return Bt.get(t)}(t):"BumpChart"===t?Nt:void 0}(e);if(!n)return;let i;try{const e="function"==typeof n?n(o,t):function(t){const e=new Map;(Array.isArray(t.data)?t.data:[]).forEach((o,n)=>{if(!Number.isFinite(Number(Et(t.yAccessor,"y",o,n))))return;const i=Ft(Et(t.xAccessor,"x",o,n)),r=e.get(i)??new Set;r.add(Et(t.lineBy,"series",o,n)+""),e.set(i,r)});const o=Array.from(e.values(),t=>t.size).sort((t,e)=>t-e);if(0===o.length)return[];const n=Math.floor(o.length/2),i={columns:o.length,median:o.length%2?o[n]:(o[n-1]+o[n])/2,max:o[o.length-1],contestedColumns:o.filter(t=>t>=2).length},r=2>i.max;return r||2>i.contestedColumns||2>i.median?[{code:r?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:r?"error":"warning",message:r?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...i}}]:[]}(o);i=Array.from(e).filter(jt)}catch{return void(t.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||t.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}t.semanticDiagnostics=i,t.semanticStatus=i.some(t=>"error"===t.severity)?"degenerate":i.some(t=>"warning"===t.severity)?"degraded":"meaningful";for(const e of i)t.warnings.includes(e.code)||t.warnings.push(e.code)}import*as Xt from"react-dom/server.browser";import*as Gt from"react";var Vt=Object.freeze([]);function Ht(t){if(!t)return Vt;let e=!1;for(let o=0;t.length>o;o++){const n=t[o];if(null==n||"object"!=typeof n){e=!0;break}}if(!e)return t;const o=[];for(const e of t)null!=e&&"object"==typeof e&&o.push(e);return o}import{scaleOrdinal as qt}from"d3-scale";var Ut={category10:B,tableau10:Y,set3:j,...e},Kt=B,Zt="#007bff";function Qt(t,e,o=Kt){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=Object.values(t).filter(t=>"string"==typeof t&&t.length>0);if(e.length>0)return e}if(Array.isArray(t)&&t.length>0)return t;if("string"==typeof t){const e=Object.prototype.hasOwnProperty.call(Ut,t)?Ut[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var Jt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],te=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],ee=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function oe(t,e,o){if("function"==typeof e){const n=e(t);return o&&n&&"string"==typeof n&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||ee.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):Kt[Math.abs(function(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o),e&=e;return Math.abs(e)}(n))%Kt.length]}function ne(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const o=t[e];return"string"==typeof o&&o.length>0?o:void 0}function ie(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>ne(t,e)??"#999"}const n=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),i=n.every(t=>!isNaN(Number(t)));if(Array.isArray(o))return qt().domain(n).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(Ut,o)?Ut[o]:Ut.category10;if(i&&"function"==typeof r){let t=-1/0;for(const e of n){const o=Number(e);o>t&&(t=o)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:Kt;return qt().domain(n).range(t).unknown("#999")}}function re(t,e,o=[3,20],n){let i;if(i="function"==typeof e?e(t):t?.[e],!n)return i;const[r,s]=n,[a,l]=o;if(s===r)return(a+l)/2;let c=(i-r)/(s-r);return 0>c?c=0:c>1&&(c=1),a+c*(l-a)}function se(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function ae(t,e){if(!se(e))return t??((...t)=>({}));const o={};return void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...o}):(...t)=>({...o})}var le={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function ce(t,e=le){if(t)return!0===t?e:"stops"in t?Array.isArray(t.stops)?t:void 0:"colorStops"in t?Array.isArray(t.colorStops)?{stops:t.colorStops.map(({offset:t,color:e})=>({offset:t,color:e}))}:void 0:{stops:[{offset:0,opacity:t.topOpacity??e.stops[0]?.opacity??.8},{offset:1,opacity:t.bottomOpacity??e.stops.at(-1)?.opacity??.05}]}}function ue(t){return t?ce(t):void 0}function de(t,e,o){return"function"==typeof t?t(o):o[t||e]}function he(t){return t instanceof Date?t.getTime():Number(t)}function pe(t,e){return S(1===e?.5:t/(e-1))}function fe(t){const e={};return void 0!==t.stroke&&(e.stroke=t.stroke),void 0!==t.strokeWidth&&(e.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(e.opacity=t.opacity),e}function ge(t,e){const o=function(t){if(!t)return;const e="boolean"==typeof t?{}:"string"==typeof t?{method:t}:t;return{type:"trend",method:e.method??"linear",...null!=e.bandwidth&&{bandwidth:e.bandwidth},...null!=e.order&&{order:e.order},...null!=e.color&&{color:e.color},...null!=e.strokeWidth&&{strokeWidth:e.strokeWidth},...null!=e.strokeDasharray&&{strokeDasharray:e.strokeDasharray},...null!=e.label&&{label:e.label}}}(e),n=Array.isArray(t)?t:void 0;return o?[o,...n??[]]:n}function ye(t){if(!t)return Pt;if("string"==typeof t){if("light"===t)return Pt;if("dark"===t)return Mt;if("high-contrast"===t)return _t;return $t(t)||Pt}const e="dark"===t.mode?Mt:Pt,o={...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}};return Lt(o)}function me(t){return{background:t.colors.background,text:t.colors.text,textSecondary:t.colors.textSecondary,grid:t.colors.grid,border:t.colors.border,primary:t.colors.primary,fontFamily:t.typography.fontFamily,titleSize:t.typography.titleSize,labelSize:t.typography.labelSize,tickSize:t.typography.tickSize,categorical:t.colors.categorical,annotation:t.colors.annotation??t.colors.text,legendSize:t.typography.legendSize??t.typography.labelSize,legendFontFamily:t.typography.legendFontFamily??t.typography.fontFamily,legendFontWeight:t.typography.legendFontWeight,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,titleFontFamily:t.typography.titleFontFamily??t.typography.fontFamily,titleFontWeight:t.typography.titleFontWeight??"bold",tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}function xe(t,e,o){const n="function"==typeof e?e(t):t[e??o];if(null==n)return null;if(n instanceof Date)return n.getTime();if("string"==typeof n&&""===n.trim())return null;const i=Number(n);return Number.isFinite(i)?i:null}function be(t){return Math.round(100*t)/100}function ve(t,e=2){const o=[],n=[],i=e+1;for(let e=0;i>e;e++){let r=0;for(const[o,n]of t)null!==n&&(r+=o**e*n);o.push(r);const s=[];for(let o=0;i>o;o++){let n=0;for(const[i,r]of t)null!==r&&(n+=i**(e+o));s.push(n)}n.push(s)}n.push(o);const r=function(t,e){const o=t,n=t.length-1,i=[e];for(let t=0;n>t;t++){let e=t;for(let i=t+1;n>i;i++)Math.abs(o[t][i])>Math.abs(o[t][e])&&(e=i);for(let i=t;n+1>i;i++){const n=o[i][t];o[i][t]=o[i][e],o[i][e]=n}for(let e=t+1;n>e;e++)for(let i=n;i>=t;i--)o[i][e]-=o[i][t]*o[t][e]/o[t][t]}for(let t=n-1;t>=0;t--){let e=0;for(let r=t+1;n>r;r++)e+=o[r][t]*i[r];i[t]=(o[n][t]-e)/o[t][t]}return i}(n,i).map(be);return{points:t.map(([t])=>[be(t),be(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function we(t){const e=t.length;let o=0,n=0,i=0,r=0;for(const[e,s]of t)o+=e,n+=s,i+=e*e,r+=e*s;const s=e*i-o*o;if(1e-12>Math.abs(s))return null;const a=(e*r-o*n)/s,l=(n-a*o)/e;return t=>l+a*t}function ke(t,e){const o=t.length,n=t.map(([t,o])=>o-e(t)).reduce((t,e)=>t+e*e,0),i=Math.sqrt(n/Math.max(o-2,1)),r=t.reduce((t,e)=>t+e[0],0)/o,s=t.reduce((t,e)=>t+(e[0]-r)**2,0);return{se:i,meanX:r,ssX:s}}function Ae(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Se="__forecastSegment",Me="__forecastOpacity";function _e(t,e,o,n){const i=e.uncertaintyOpacity,r=e.confidenceAccessor;if(!i&&!r)return;const s="object"==typeof i?i:{},a=s.min??.15,l=s.max??1;if(r){const e="function"==typeof r?r:t=>t[r];for(const o of t){const t=e(o);null!=t&&Number.isFinite(t)&&(o[Me]=a+Math.max(0,Math.min(1,t))*(l-a))}return}const c=t.map(t=>{const e=o(t),i=n(t);return null!=e&&null!=i&&Number.isFinite(e)&&Number.isFinite(i)?Math.abs(e-i):NaN}),u=c.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=St(u),p=h-d;t.forEach((t,e)=>{const o=c[e];Number.isFinite(o)&&(t[Me]=l-(p>0?(o-d)/p:0)*(l-a))})}function Pe(t,e){return"function"==typeof e?e(t):!!t[e]}var Le="__semiotic_resolvedX",$e="__semiotic_resolvedY",Re="__compoundGroup";function Ce(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function Te(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?Ht(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,o){const n="function"==typeof e,i="function"==typeof o,r=n?Le:e,s=i?$e:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[Le]=e(t)),i&&(r[$e]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,l=s.yKey,c=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d="string"==typeof n||"function"==typeof n?n:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,o,n,i){return(r=n).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,o,n,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:f}=n,g=t.map(t=>{let e="observed";return s&&Pe(t,s)?e="forecast":r&&Pe(t,r)&&(e="training"),{...t,[Se]:e}}),y=n._groupBy,m=[];if(y){const t=new Map;for(const e of g){const o=e[y]??"__default";t.has(o)||t.set(o,[]),t.get(o).push(e)}const e=[];for(const[,o]of t)for(let t=0;o.length-1>t;t++)o[t][Se]!==o[t+1][Se]&&(e.push({...o[t+1],[Se]:o[t][Se]}),e.push({...o[t],[Se]:o[t+1][Se]}));m.push(...g,...e)}else for(let t=0;g.length>t;t++)m.push(g[t]),g.length-1>t&&g[t][Se]!==g[t+1][Se]&&(m.push({...g[t+1],[Se]:g[t][Se]}),m.push({...g[t],[Se]:g[t+1][Se]}));if(n.trainUnderline){const t=[];for(const e of m)"training"===e[Se]&&t.push({...e,[Se]:"training-base"});m.unshift(...t)}const x=[];if(l&&c){const t="string"==typeof l?l:"__envUpper",e="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const o of m)"function"==typeof l&&(o[t]=l(o)),"function"==typeof c&&(o[e]=c(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:f})}if(n.uncertaintyOpacity||n.confidenceAccessor){const t=l?"function"==typeof l?l:t=>t[l]:()=>{},e=c?"function"==typeof c?c:t=>t[c]:()=>{};_e(m.filter(t=>"forecast"===t[Se]),n,t,e)}if(a){const t=n.anomalyStyle,e={type:"highlight",filter:t=>Pe(t,a)};t?(e.style=t,e.r=p):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=p):(e.color=h,e.r=p,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(e)}return i&&x.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label}),{processedData:m,annotations:x}}(t,0,0,n,i):function(t,e,o,n,i){const{trainEnd:r,steps:s=10,confidence:a=.95,color:l="#6366f1",bandOpacity:c=.15,label:u}=n;if(null==r)return{processedData:t,annotations:[]};const d=[],h=[];for(const o of t)o[e]>r?h.push({...o,[Se]:"observed"}):d.push({...o,[Se]:"training"});const p=d.map(t=>[t[e],t[o]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),f=[],g=[];if(p.length>=3){const i=p.length,r=we(p);if(r){const{se:d,meanX:h,ssX:y}=ke(p,r),m=Ae(a),x=t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t)),b=kt(x),v=p.length>1?(p[i-1][0]-p[0][0])/(i-1):1;for(let t=1;s>=t;t++){const n=b+t*v,s=r(n),a=d*Math.sqrt(1+1/i+(y>0?(n-h)**2/y:0))*m;g.push({[e]:n,[o]:s,[Se]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}_e(g,n,t=>t.__forecastUpper,t=>t.__forecastLower),f.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}f.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&f.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const y=[];if(y.push(...d),d.length>0&&h.length>0&&y.push({...d[d.length-1],[Se]:"observed"}),y.push(...h),g.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&y.push({...t,[Se]:"forecast"}),y.push(...g)}return{processedData:y,annotations:f}}(t,e,o,n,i);var r}(r,a,l,n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,t.anomaly);if(r=e.processedData,c.push(...e.annotations),u=function(t,e,o){const n=o.upperBounds,i=o.lowerBounds;if(!n&&!i)return;const r="function"==typeof n?n:"string"==typeof n?t=>t[n]:null,s="function"==typeof i?i:"string"==typeof i?t=>t[i]:null;let a=1/0,l=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>l&&(l=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[Re]:`${t[n]}__${t[Se]||"observed"}`})),d=Re):d=Se,t.baseLineStyle){const e=function(e,o){const n=o.trainDasharray??"8,4",i=o.forecastDasharray??"4,4",r=o.color||"#6366f1",s=o.trainOpacity,a=o.forecastOpacity,l=o.trainStroke,c=o.trainLinecap,u=o.trainUnderline;return e=>{const o=(e=>t.baseLineStyle(e))(e),d=e[Se];if("training"===d){let t=o.stroke;return"darken"===l?t=tt(o.stroke||"#666",.5):l&&(t=l),{...o,stroke:t,strokeDasharray:n,...c&&{strokeLinecap:c},...null!=s&&{strokeOpacity:s}}}if("training-base"===d){let t=o.stroke||"#666";return"lighten"===u&&(t=it(t,.4)),{...o,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Me],n=null!=t?t:a;return{...o,stroke:r,strokeDasharray:i,...null!=n&&{strokeOpacity:n}}}return o}}(0,t.forecast);h=t=>e(t)}}else t.anomaly&&c.push(...(p=t.anomaly,[{type:"anomaly-band",threshold:p.threshold??2,showBand:!1!==p.showBand,fill:p.bandColor||"#6366f1",fillOpacity:p.bandOpacity??.1,anomalyColor:p.anomalyColor||"#ef4444",anomalyRadius:p.anomalyRadius??6,label:p.label}]));var p;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,o,n,i){const r=new Map;for(const e of t){const t=i?(e[i]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const i of e)Ce(i,o,n)||t.push(i);return{rows:t,groupKey:i}}if("zero"===e){const t=[];for(const[,e]of r)for(const i of e)Ce(i,o,n)?t.push({...i,[n]:0}):t.push(i);return{rows:t,groupKey:i}}const s=[],a="_gapSegment";for(const[t,e]of r){let i=0,r=[];const l=()=>{if(0===r.length)return;const e="__single"===t?"__seg"+i:`${t}__seg${i}`;for(const t of r)s.push({...t,[a]:e});r=[],i++};for(const t of e)Ce(t,o,n)?l():r.push(t);l()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,l,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let f;if(t.directLabel){const e=function(t,e,o,n,i,r,s,a){if(!e||!o)return{annotations:[]};const l="object"==typeof e?e:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof o?o:t=>t[o],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const o=t+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(e))}const p=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[n])-Number(e[n])),p.set(t,"end"===c?e[e.length-1]:e[0]);const f=ie(Array.from(p.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),g=Array.from(p.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===c?6:-6,dy:0,color:f?oe({__lbl:t},"__lbl",f):a||Zt,fontSize:u}));g.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;g.length>t;t++){const e=g[t-1],o=g[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const y=g.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===c?{right:y}:{left:y}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,t.colorScheme,t.themeCategorical,t.color);c.push(...e.annotations),f=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?l:o,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:f}}function Oe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrScatterColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],p=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],f=p.length?St(p):void 0,g=at(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?re(t,d,h,f):"number"==typeof i.pointRadius?i.pointRadius:5};return y?.length&&Object.assign(o,dt(t,y,g(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}var Ie={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Te({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),s=ge(r.annotations,i.regression);return{chartType:"scatter",data:r.data,xAccessor:r.xAccessor,yAccessor:r.yAccessor,colorAccessor:e,sizeAccessor:i.sizeBy,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,...s&&s.length>0&&{annotations:s},...r.yExtent&&!n.yExtent&&{yExtent:r.yExtent},sizeRange:i.sizeRange||[3,15],pointStyle:n.pointStyle||Oe(t,e,o,n,i),showLegend:n.showLegend??!!e}}},ze={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=ge(n.annotations,i.regression);return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:o,...n,...r&&{annotations:r},pointStyle:n.pointStyle||Fe(t,e,o,n,i),showLegend:n.showLegend??!!e}}};function Fe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrBubbleColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],p=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],f=p.length?St(p):void 0,g=at(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?re(t,d,h,f):h[0],stroke:i.bubbleStrokeColor??"white",strokeWidth:i.bubbleStrokeWidth??1};return y?.length&&Object.assign(o,dt(t,y,g(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}import{useMemo as Ne,useCallback as Ee,useState as De,useId as We,useEffect as Be,useRef as je}from"react";function Ye(...t){let e;for(const o of t)o&&(e=Xe(e)&&Xe(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function Xe(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function Ge(t){return"object"==typeof t&&null!==t&&"gradient"in t}function Ve(t){return"string"==typeof t&&t.length>0}function He(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function qe(t,e){return He(t,Ve(e))}function Ue(t,e,o,n,i=8){const r=n,s="left"===n?"right":"right"===n?"left":"top"===n?"bottom":"top",a=Math.max(e[r],Math.max(0,("left"===n||"right"===n?o[0]:o[1])-i)-t[s]);t[r]>a&&(t[r]=a)}function Ke(t){return Math.ceil(7*t.length)}function Ze(t,e){if(Xe(t)){const o=lo(e),n=t.legendGroups.flatMap(t=>[t.label?Ke(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+Ke(t.label))]);return Math.max(100,...n)}if(Ge(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),n=Math.max(Ke(o(e.domain[0])),Ke(o(e.domain[1]))),i=e.label?Ke(e.label):0;return Math.max(100,19+n,i)}return 100}function Qe(t){return(Xe(t)||Ge(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function Je(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?oo:eo:0}function to(t){return Math.max(0,t?.edgeGutter??3)}var eo=34,oo=70;function no(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function io(t,e,o){if(Ge(t))return t.gradient.label?46:26;if(!Xe(t))return 20;const n=lo(o),i=Math.max(1,o?.maxWidth??e);let r=n.rowHeight;for(const e of t.legendGroups){let t=0,o=0;for(const r of e.items){const e=n.swatchSize+n.labelGap+Ke(r.label),s=0===o?e:o+n.itemGap+e;o>0&&s>i?(t+=1,o=e):o=s}e.items.length>0&&(t+=1),r=Math.max(r,t*n.rowHeight,e.label?Ke(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function ro(t,e,o){return Ze(t,e)+Qe(t)+Je(e,o)+to(e)}function so(t,e){const{legend:o}=e;if(!o)return;const n=e.position??"right",i=io(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+Qe(o)+no("bottom"===n?e.axisChrome:"top"===n?e.axisChrome?.topAxis:void 0,e.legendLayout)+("top"===n&&e.hasTitle?24:0),r=Math.max(e.minimumMargin??0,"top"===n?e.hasTitle?58:34:0);"right"===n?t.right=Math.max(t.right,r,ro(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===n?t.left=Math.max(t.left,r,ro(o,e.legendLayout,e.axisChrome?.leftAxis)):"top"===n?t.top=Math.max(t.top,r,i):t.bottom=Math.max(t.bottom,r,i)}function ao(t,e){const o=e.position??"right",n="top"===o||"bottom"===o,i=Math.max(0,e.totalWidth-e.margin.left-e.margin.right),r=Math.max(1,n?e.legendLayout?.maxWidth??i:e.reservedWidth??Ze(t,e.legendLayout)),s=Qe(t),a=Je(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),l=to(e.legendLayout),c=io(t,i,e.legendLayout),u=no(e.axisChrome,e.legendLayout),d=no(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(l,e.margin.left-a-r-s),y:e.margin.top,width:r,height:c};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-c,width:r,height:c};if("bottom"===o){const t=e.totalHeight-e.margin.bottom;return{x:e.margin.left,y:Math.max(t+s,Math.min(t+u+s,e.totalHeight-c)),width:r,height:c}}return{x:Math.min(e.totalWidth-r-l,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:c}}function lo(t){const e=Math.max(1,t?.swatchSize??16),o=Math.max(e,t?.rowHeight??22);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??6),itemGap:Math.max(0,t?.itemGap??10),rowHeight:o,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function co(t,e){let o=24;return t.map(({hasLabel:t,itemCount:n})=>{o+=5;const i=o;let r;o+=8,t&&(o+=16,r=o,o+=8);const s=o;return o+=n*e+8,{lineY:i,labelY:r,itemsY:s,endY:o}})}function uo(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=ne(o,n);if(t)return t}let r;if(Array.isArray(o))r=o;else if(e&&e.length>0)r=e;else if("string"==typeof o){const t=Ut[o];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=n?(i.has(n)||i.set(n,i.size),r[i.get(n)%r.length]):r[0]:Zt}function ho(t,e,o){return"function"==typeof t?t(e,o):e[t]}function po(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[Ft(t),e]));return t.map(t=>{const e={...t},n=n=>{if(!(n in t))return;const i=o.get(Ft(t[n]));void 0!==i&&(e[n]=i)};return n("x"),n("x0"),n("x1"),"string"!=typeof t.type||"x-threshold"!==t.type&&"x"!==t.type||n("value"),e})}function fo(t,e,o,n,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*o+i*i*i*n}function go(t,e,o,n,i){const r=1-i;return 3*r*r*(e-t)+6*r*i*(o-e)+3*i*i*(n-o)}function yo(t,e,o,n,i){const r=[],s=(t.x+e.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===n?(c=t.x+(e.x-t.x)*l,u=t.y+(e.y-t.y)*l,d=e.x-t.x,h=e.y-t.y):(c=fo(t.x,s,s,e.x,l),u=fo(t.y,t.y,e.y,e.y,l),d=go(t.x,s,s,e.x,l),h=go(t.y,t.y,e.y,e.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*l,datumIndex:.5>l?o:o+1})}return r}function mo(t,e={}){const o=[],n=[],i=[];if(2>t.length)return{topPath:o,bottomPath:n,datumIndices:i};const r=e.curve??"smooth",s=Math.max(2,Math.floor(e.samplesPerSegment??12));for(let e=0;t.length-1>e;e++){const a=yo(t[e],t[e+1],e,r,s);for(let t=0===e?0:1;a.length>t;t++){const e=a[t],r=Math.hypot(e.dx,e.dy)||1,s=-e.dy/r,l=e.dx/r,c=Math.max(0,e.radius);o.push([e.x+s*c,e.y+l*c]),n.push([e.x-s*c,e.y-l*c]),i.push(e.datumIndex)}}return{topPath:o,bottomPath:n,datumIndices:i}}import{jsx as xo}from"react/jsx-runtime";function bo({datum:t,x:e,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=V(),l=a.isActive&&!a.predicate(t),c="function"==typeof s?s(t.__bumpRaw):s;return xo("text",{className:"semiotic-bump-label",x:e+("end"===n?8:-8),y:o,dy:"0.35em",textAnchor:"end"===n?"start":"end",fill:i,fillOpacity:l?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...c},children:t.__bumpSeries})}function vo(t,e,o){const[n,i]=e,[r,s]=o;return i===n?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(t-n)/(i-n)))}function wo(t){const e=t.__bumpXValue instanceof Date?t.__bumpXValue.getTime():Number(t.__bumpXValue);return{value:t.__bumpValue,x:Number.isFinite(e)?e:void 0,y:t.__bumpValue,category:t.__bumpSeries}}function ko(t){const e=t.config,o=new Map;for(const e of t.data){const t=o.get(e.__bumpSeries)??[];t.push(e),o.set(e.__bumpSeries,t)}const n=e.seriesOrder.filter(t=>o.has(t)).sort((t,n)=>(o.get(t)?.[0]?.__bumpHighlighted?1:0)-(o.get(n)?.[0]?.__bumpHighlighted?1:0)||e.seriesOrder.indexOf(t)-e.seriesOrder.indexOf(n)),i=[],r=[],s=[];for(const r of n){const n=(o.get(r)??[]).sort((t,e)=>t.x-e.x);if(2>n.length)continue;const a=n[0].__bumpHighlighted,l=(e.colorMap&&ne(e.colorMap,r))??t.resolveColor(n[0].__bumpSeries,n[0]),c=e.color??(a?l:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??l),u=n.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?vo(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=mo(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:c,fillOpacity:1,opacity:a?e.ribbon?e.ribbonOpacity:e.lineOpacity:Math.min(e.ribbon?e.ribbonOpacity:e.lineOpacity,.58)};e.styleRules?.length&&Object.assign(h,dt(n[0].__bumpRaw,e.styleRules,wo(n[0]))),e.areaStyle&&Object.assign(h,e.areaStyle(n[0].__bumpRaw)??{}),void 0!==e.stroke&&(h.stroke=e.stroke),void 0!==e.strokeWidth&&(h.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(h.opacity=e.opacity),i.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:h,datum:d.datumIndices.map(t=>n[t]),accessibleDatum:n.map(t=>t.__bumpRaw),accessibility:{label:r+" ranking trajectory",tableFields:n.map(t=>t.__bumpRaw)},group:r,interactive:!0}),e.showPoints&&n.forEach((t,o)=>{const n={fill:c,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(n,dt(t.__bumpRaw,e.styleRules,wo(t))),e.pointStyle&&Object.assign(n,e.pointStyle(t.__bumpRaw)??{}),void 0!==e.stroke&&(n.stroke=e.stroke),void 0!==e.strokeWidth&&(n.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(n.opacity=e.opacity),i.push({type:"point",x:u[o].x,y:u[o].y,r:n.r??e.pointRadius,style:n,datum:t,accessibleDatum:t.__bumpRaw,accessibility:{label:`${r}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${r}:${t.x}`})});const p=!0===e.showLabels?"end":e.showLabels,f=(t,o,n)=>{const i=null==e.labelPriorityAccessor?void 0:"function"==typeof e.labelPriorityAccessor?e.labelPriorityAccessor(t.__bumpRaw):Number(t.__bumpRaw[e.labelPriorityAccessor]);s.push({id:`${r}\0${n}`,datum:t,x:u[o].x,y:u[o].y,side:n,rank:t.__bumpRank,highlighted:a,priority:Number.isFinite(i)?i:void 0,color:"string"==typeof h.fill?h.fill:c})};"start"!==p&&"both"!==p||f(n[0],0,"start"),"end"!==p&&"both"!==p&&"auto"!==p||f(n.at(-1),n.length-1,"end")}const a=function(t,e,o,n){const i=Math.max(1,Math.floor(e/18)),r="auto"===o?Number.isFinite(n)&&(n??0)>=0?Math.min(i,Math.floor(n)):i:1/0,s=t.map((t,e)=>({candidate:t,index:e})).sort((t,e)=>(e.candidate.priority??0)-(t.candidate.priority??0)||Number(e.candidate.highlighted)-Number(t.candidate.highlighted)||t.candidate.rank-e.candidate.rank||t.index-e.index),a=[];for(const{candidate:t}of s){if(a.length>=r)break;a.some(e=>e.side===t.side&&14>Math.abs(e.y-t.y))||a.push(t)}return new Set(a.map(t=>t.id))}(s,t.dimensions.plot.height,"auto"!==(!0===e.showLabels?"end":e.showLabels)||"auto",e.maxLabels);for(const t of s)a.has(t.id)&&r.push(xo(bo,{datum:t.datum,x:t.x,y:t.y,side:t.side,color:t.color,highlighted:t.highlighted,labelStyle:e.labelStyle},t.id));return{nodes:i,overlays:r.length?xo("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(t,e)=>{const o=function(t){const e=Array.isArray(t.datum)?t.datum[0]:t.datum;return e&&"object"==typeof e&&"__bumpSeries"in e?e:void 0}(t);if(e?.isActive&&o&&!e.predicate(o))return{opacity:.14}}}}var Ao={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,n,i)=>{const r=function(t,e={}){const o=e.xAccessor??"x",n=e.yAccessor??"y",i=e.lineBy??"series",r=e.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;t.forEach((t,e)=>{const r=ho(o,t,e),p=Ft(r);let f=a.get(p);null==f&&(f=s.length,a.set(p,f),s.push(r),l.set(f,[]));const g=ho(i,t,e)+"";u.has(g)||(u.set(g,c.length),c.push(g));const y=Number(ho(n,t,e));Number.isFinite(y)&&(d=Math.min(d,y),h=Math.max(h,y),l.get(f)?.push({datum:t,inputIndex:e,series:g,value:y}))});const p=[],f=new Map,g=new Map;for(let t=0;s.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,o)=>{const n=o+1;p.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:n}),f.set(e.series,(f.get(e.series)??0)+n),g.set(e.series,(g.get(e.series)??0)+1)})}const y=c.length+1,m=[...c].sort((t,e)=>{const o=g.get(t)??0,n=g.get(e)??0;return((f.get(t)??0)+(s.length-o)*y)/Math.max(1,s.length)-((f.get(e)??0)+(s.length-n)*y)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),x=new Set(m.slice(0,null==e.highlightTop?m.length:Math.max(0,Math.floor(e.highlightTop))));return{data:p.map(t=>{const e=x.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],{xAccessor:i.xAccessor,yAccessor:i.yAccessor,lineBy:i.lineBy,rankDirection:i.rankDirection,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0}),s=Math.max(1,r.seriesOrder.length),a=ye(n.theme),l=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:n,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=t;if(null==n&&null==i)return r;const c=new Set(o.slice(0,null==n?o.length:Math.max(0,Math.floor(n)))),u=new Map,d={};for(const t of e)Object.defineProperty(d,t,{configurable:!0,enumerable:!0,writable:!0,value:i??(c.has(t)?uo(void 0,a,r,t,u):s??l??"#b8bec8")});return d}({seriesOrder:r.seriesOrder,overallOrder:r.overallOrder,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0,color:"string"==typeof i.color?i.color:void 0,colorScheme:o,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={ribbon:!0===i.ribbon,curve:"linear"===i.curve?"linear":"smooth",samplesPerSegment:"number"==typeof i.samplesPerSegment?i.samplesPerSegment:12,ribbonSizeRange:Array.isArray(i.ribbonSizeRange)?i.ribbonSizeRange:[4,28],valueExtent:r.valueExtent,seriesOrder:r.seriesOrder,lineWidth:"number"==typeof i.lineWidth?i.lineWidth:3,ribbonOpacity:"number"==typeof i.ribbonOpacity?i.ribbonOpacity:.82,lineOpacity:"number"==typeof i.lineOpacity?i.lineOpacity:.9,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,color:"string"==typeof i.color?i.color:void 0,colorMap:l&&"object"==typeof l&&!Array.isArray(l)?l:void 0,stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0,styleRules:i.styleRules,areaStyle:n.areaStyle,pointStyle:n.pointStyle,labelStyle:i.labelStyle,showPoints:!0===i.showPoints,pointRadius:"number"==typeof i.pointRadius?i.pointRadius:3,showLabels:i.showLabels??!0,labelPriorityAccessor:i.labelPriorityAccessor,maxLabels:"number"==typeof i.maxLabels?i.maxLabels:void 0},u=n.xFormat,d=(t,e)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((t,e)=>e),p=Array.from({length:s},(t,e)=>e+1),f=n.axes??[{orient:"left",tickValues:p,tickFormat:t=>t+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:ko,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:f,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:po(n.annotations,r.xValues)}}};function So(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrAreaColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,p="number"==typeof i.areaOpacity?i.areaOpacity:.7,f=st(i.yAccessor),g=i.styleRules;return(t,o)=>{const n=e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,r={fill:n,fillOpacity:p,stroke:d?n:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(r,dt(t,g,{value:f(t),category:o})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function Mo(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrPointColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt;return{r:d,fill:o,stroke:"none"}}}var _o={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",l=ye(n.theme).colors.categorical,c=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrLineColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=at(i.xAccessor,i.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:n,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:l,ruleContext:c}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let p;return r?p=r(t,u):o?n&&(p=oe(t,o,n)):p=i||Zt,void 0!==p&&(d.stroke=p,h&&(d.fill=p,d.fillOpacity=a)),l?.length&&Object.assign(d,dt(t,l,c?c(t,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof i.lineWidth?i.lineWidth:2,colorBy:e,colorScale:u,color:"string"==typeof i.color?i.color:void 0,fillArea:i.fillArea,areaOpacity:"number"==typeof i.areaOpacity?i.areaOpacity:.3,styleRules:i.styleRules,ruleContext:d});return ae(h,{stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0})}(t,r,o,n,i),u=Te({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:n.annotations,themeCategorical:l,baseLineStyle:c}),d=n.pointStyle||Mo(u.data,u.colorAccessor,o,n,i);let h=n.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const p=(!i.directLabel||void 0!==n.showLegend)&&(n.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||c,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...n,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!n.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:p}}},Po={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?Ht(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=i.valueExtent||n.yExtent,u="down"===i.direction?function({data:t,valueAccessor:e,timeAccessor:o,binSize:n,valueExtent:i,extentPadding:r}){if(i)return[i[1],i[0]];if(!t||0===t.length)return;const s=new Map;for(const i of t){const t=xe(i,o,"time"),r=xe(i,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/n)*n;s.set(a,(s.get(a)??0)+r)}let a=0;for(const t of s.values())a=Math.max(a,t);return[a>0?a+a*(r??.1):1,0]}({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(i.binSize),valueExtent:c,extentPadding:i.extentPadding}):c,d={...void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.cursor&&{cursor:i.cursor},...void 0!==i.gap&&{gap:i.gap}};return{chartType:"bar",data:r,...n,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||n.xExtent,yExtent:u,extentPadding:i.extentPadding??n.extentPadding,binSize:i.binSize,categoryAccessor:l,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,showLegend:n.showLegend??!!l}}},Lo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=Te({data:Array.isArray(t)?Ht(t):[],xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.areaBy,forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),a=function({data:t,safeData:e,areaBy:o,lineDataAccessor:n}){if(null==t)return[];const i=void 0!==e[0]?.[n];if(!i&&!o)return e;let r;if(i)r=e;else{const t=e.reduce((t,e)=>{const i="function"==typeof o?o(e):e[o],r=i+"";if(!t[r]){const e={[n]:[]};"string"==typeof o&&(e[o]=i),t[r]=e}return t[r][n].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[n])?t[n]:[];return"string"==typeof o?e.map(e=>({...e,[o]:e[o]??t[o]})):e})}({data:t,safeData:s.data,areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),l=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:o})=>({offset:t/100,color:e,...null!=o&&{opacity:o}}))}:Array.isArray(t.stops)?t:void 0}(i.semanticGradient),c=l?.stops.length?{stops:l.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:ce(n.gradientFill),u=!1!==i.semanticLine?function(t){const e=t?.stops.filter(t=>"string"==typeof t.color&&Number.isFinite(t.offset)).map(({offset:t,color:e,opacity:o})=>({offset:Math.max(0,Math.min(1,t)),color:e,...Number.isFinite(o)&&{opacity:Math.max(0,Math.min(1,o))}})).sort((t,e)=>t.offset-e.offset);if(!e?.length)return;const o=e[0];return o.offset>0?[{...o,offset:0},...e]:e}(l):void 0,d=n.pointStyle||Mo(a,r,o,n,i);return{chartType:"area",data:a,xAccessor:s.xAccessor,yAccessor:s.yAccessor,y0Accessor:i.y0Accessor,groupAccessor:i.areaBy||void 0,colorAccessor:r,colorScheme:o,...n,...s.annotations.length>0&&{annotations:s.annotations},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},...void 0!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:n.lineStyle||So(a,r,o,n,i),...d&&{pointStyle:d}}}},$o={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=t=>he(de(r,"x",t)),c=t=>he(de(s,"a",t)),u=t=>he(de(a,"b",t)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",p=i.areaOpacity??.6,f=i.lineWidth??1.5,g=!1!==i.showLines,y=!1!==n.showLegend,m=i.seriesALabel||"A",x=i.seriesBLabel||"B",b=n.legendPosition||"right",v=function(t,e,o,n){if(!t.length)return[];const i=t.filter(t=>Number.isFinite(e(t))).sort((t,o)=>e(t)-e(o)),r=[];let s=0,a=null,l=null,c=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),p=(t,e)=>{h({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:d(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;i.length>t;t++){const r=i[t],f=e(r),g=o(r),y=n(r);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(y))continue;const m=u(g,y);if(null!==m)if(null!=a){if(l&&l.w!==m){let t,e;if(c.length>0)t=c[0].x,e=c[0].y;else{const o=g-l.a-(y-l.b);if(0!==o){const n=Math.max(0,Math.min(1,(l.b-l.a)/o));t=l.x+n*(f-l.x),e=l.a+n*(g-l.a)}else t=l.x,e=l.a}h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;c.length>t;t++)p(c[t],a)}else for(const t of c)p(t,a);c=[],h({__x:f,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:f,a:g,b:y,w:m}}else{a=m;for(const t of c)p(t,a);c=[],h({__x:f,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:f,a:g,b:y,w:m}}else c.push({x:f,y:g,datum:r})}for(const t of c)p(t,a??"A");return r}(Array.isArray(t)?t:[],l,c,u),w=[];if(g&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(l(t))).sort((t,e)=>l(t)-l(e));for(const t of e){const e=l(t),o=c(t),n=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(n)&&w.push({__x:e,__y:n,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:p}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:f,fill:"none"}),curve:i.curve||"linear",...n,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},Ro={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?ie(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=n.lineStyle||(t=>{const e=null==r?void 0:oe(t,r,s),o=i.showLine??!0,n={fill:i.color??e,stroke:o?i.stroke??e:"none",...o?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:a,...null==i.opacity?{}:{opacity:i.opacity}},l=i.styleRules;if(l?.length){const e=st(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,dt(t,l,{value:e(t),category:o}))}return n}),c=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Mo(t,r,o,n,i);return{chartType:"stackedarea",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:r,colorScheme:o,normalize:i.normalize,baseline:c,stackOrder:i.stackOrder,lineStyle:l,...n,...u&&{pointStyle:u},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!r}}},Co={frameType:"xy",buildProps:(t,e,o,n,i)=>{const[r]=n.size??[600,400];return{chartType:"candlestick",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.highAccessor||"high",highAccessor:i.highAccessor||"high",lowAccessor:i.lowAccessor||"low",openAccessor:i.openAccessor,closeAccessor:i.closeAccessor,candlestickStyle:i.candlestickStyle,...n,scalePadding:n.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:n.extentPadding??(r>200?.1:.02)}}},To={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,p=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,f=Gt.createElement,g=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const n=o.width,i=o.height,l=null!=r?e.x(r):n/2,g=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(g))return null;const y=Math.max(0,Math.min(n,l)),m=Math.max(0,Math.min(i,g)),x=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:n-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:i-m},{c:a.bottomRight,x:y,y:m,w:n-y,h:i-m}],b=c?[f("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),f("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),f("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),f("text",{key:"lbr",x:n-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return f(Gt.Fragment,null,...x.map((t,e)=>t.w>0&&t.h>0?f("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),f("line",{key:"vc",x1:y,y1:0,x2:y,y2:i,stroke:d,strokeWidth:h,strokeDasharray:p}),f("line",{key:"hc",x1:0,y1:m,x2:n,y2:m,stroke:d,strokeWidth:h,strokeDasharray:p}),...b)}]:void 0;return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[3,15],colorScheme:o,pointStyle:n.pointStyle||i.pointStyle||Oe(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...g&&{svgPreRenderers:g}}}},Oo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const o=e.xAccessor||"x",n=e.yAccessor||"y",i=e.orderAccessor?[...t].sort((t,o)=>null==t||"object"!=typeof t?1:null==o||"object"!=typeof o?-1:he(de(e.orderAccessor,"order",t))-he(de(e.orderAccessor,"order",o))):t,r=new WeakMap;let s=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=he(de(o,"x",t)),i=he(de(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&s++}let a=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=he(de(o,"x",t)),i=he(de(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=Te({data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),a=ge(s.annotations,i.regression),l=i.pointRadius??4,c=at(i.xAccessor,i.yAccessor),u=i.styleRules,d=[t=>{const e=t.filter(t=>"point"===t.type&&"number"==typeof t.x&&"number"==typeof t.y);if(2>e.length)return null;const o=[];for(let t=0;e.length-1>t;t++){const n=e[t],i=e[t+1],r=pe(t,e.length);100>e.length&&o.push(Gt.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),o.push(Gt.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:l,strokeLinecap:"round"}))}return Gt.createElement(Gt.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:ae(t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1,i={fill:n>0?pe(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(i,dt(t,u,c(t))),i},fe(i)),...n,...a&&a.length>0&&{annotations:a},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}},Io={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.frameProps&&"object"==typeof i.frameProps?i.frameProps:void 0,s=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1,a=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,l=null!=r&&Object.hasOwn(r,"heatmapColorScale"),c=r?.heatmapColorScale,u=l?"function"==typeof c?c:void 0:"custom"===a&&"function"==typeof i.customColorScale?i.customColorScale:void 0;return{chartType:"heatmap",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,showValues:i.showValues,heatmapValueFormat:i.valueFormat,areaStyle:()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:s}),...n,...void 0!==a&&{colorScheme:a},...u&&{heatmapColorScale:u}}}};function zo(t){return Math.max(0,Math.min(1,t))}function Fo(t){const e=t.trim();if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t.split("").map(t=>t+t).join("")),6===t.length&&/^[0-9a-f]{6}$/i.test(t))return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const t=[Number(o[1]),Number(o[2]),Number(o[3])];if(t.every(Number.isFinite))return t}return null}function No(t,e,o){const n=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function Eo(t,e,o){const n=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:zo(t.offset),color:t.color??o,opacity:null==t.opacity?1:zo(t.opacity)})).sort((t,e)=>t.offset-e.offset);if(0===n.length)return"#999999";const i=t=>{if(1===t.opacity)return t.color;const e=Fo(t.color);return e?`rgba(${e[0]},${e[1]},${e[2]},${t.opacity})`:t.color};if(1===n.length)return i(n[0]);const r=zo(e);if(n[0].offset>=r)return i(n[0]);if(r>=n[n.length-1].offset)return i(n[n.length-1]);for(let t=0;n.length-1>t;t++){const e=n[t],o=n[t+1];if(e.offset>r||r>o.offset)continue;const s=o.offset-e.offset,a=s>0?(r-e.offset)/s:0,l=Fo(e.color),c=Fo(o.color);if(!l||!c)return i(.5>a?e:o);const[u,d,h]=l,[p,f,g]=c,y=u+(p-u)*a,m=d+(f-d)*a,x=h+(g-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?No(y,m,x):`rgba(${Math.round(y)},${Math.round(m)},${Math.round(x)},${b})`}return i(n[n.length-1])}function Do(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as Wo,jsx as Bo,jsxs as jo}from"react/jsx-runtime";import{useMemo as Yo,useCallback as Xo,useRef as Go}from"react";var Vo={RdBu:v,PiYG:b,PRGn:x,BrBG:m,RdYlBu:w,RdYlGn:k,Spectral:A},Ho="__likert_neutral_neg",qo="__likert_neutral_pos";function Uo(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}import*as Ko from"react";function Zo(t){return ce(t)}function Qo(t,e,o,n,i){const r=ye(n.theme).colors.categorical,s=o??n.colorScheme,a=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],l="string"==typeof e?e:"__ssrColorBy",c="function"==typeof e?a.map(t=>({...t,__ssrColorBy:e(t)})):a,u=e?ie(c,l,s??r):void 0,d=uo("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=st(i.valueAccessor),p=i.styleRules,f=n.pieceStyle;return(t,o)=>{const n={fill:e&&u?oe(t,e,u):d};return p?.length&&Object.assign(n,dt(t,p,{value:h(t),category:o})),"function"==typeof f?Object.assign(n,f(t,o)||{}):f&&"object"==typeof f&&Object.assign(n,f),void 0!==i.stroke&&(n.stroke=i.stroke),void 0!==i.strokeWidth&&(n.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(n.opacity=i.opacity),n}}function Jo(t,e,o,n,i){const r=Qo(t,e,o,n,i);return(t,e)=>{const o=r(t,e);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function tn(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s="string"==typeof e?e:"__ssrViolinColorBy",a="function"==typeof e?r.map(t=>({...t,__ssrViolinColorBy:e(t)})):r,l=ye(n.theme).colors.categorical,c=o??n.colorScheme,u=e?ie(a,s,c??l):void 0,d=uo("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return t=>{const o=e&&u?oe(t,e,u):d;return{fill:o,fillOpacity:.6,stroke:i.stroke??o,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function en(t,e,o,n,i){const r=Qo(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function on(t,e,o,n,i){const r=Qo(t,e,o,n,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=c.length?St(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?re(t,a,l,u):d,fillOpacity:h,...r(t,e)})}var nn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=ge(n.annotations,i.regression);return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,colorAccessor:e,colorScheme:o,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,...r&&{annotations:r},gradientFill:Zo(n.gradientFill),pieceStyle:Qo(t,e,o,n,i)}}},rn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.stackBy;return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Zo(n.gradientFill),pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},sn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.groupBy;return{chartType:"clusterbar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",groupBy:i.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Zo(n.gradientFill),pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},an={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;return{chartType:"pie",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},ln={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;return{chartType:"donut",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:n.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:Qo(t,r,o,n,i)}}},cn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=i.valueAccessor||"value",a=r.map(t=>Number("function"==typeof s?s(t):t[s])).filter(Number.isFinite),l=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:t,oAccessor:i.categoryAccessor||(t=>null==t.category?"All":t.category+""),rAccessor:s,projection:"horizontal",bins:i.bins??25,normalize:i.relative??!1,colorAccessor:e,colorScheme:o,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:l?{rExtent:l}:{},...n,summaryStyle:Jo(t,e,o,n,i)}}},un={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"boxplot",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...n,summaryStyle:n.summaryStyle||Jo(t,e,o,n,i)})},dn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"violin",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,projection:"horizontal"===i.orientation?"horizontal":"vertical",bins:i.bins??25,showIQR:i.showIQR??!0,barPadding:i.categoryPadding??20,colorScheme:o,...n,summaryStyle:n.summaryStyle||tn(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},hn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"swarm",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,sizeRange:i.sizeRange||[3,8],pieceStyle:n.pieceStyle||on(t,e,o,n,i),showLegend:n.showLegend??!!e})},pn={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>{const r=ge(n.annotations,i.regression);return{chartType:"point",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...n,...r&&{annotations:r},pieceStyle:en(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e}}},fn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.subcategoryAccessor;return{chartType:"swimlane",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.subcategoryAccessor,colorAccessor:r,categoryAccessor:i.categoryAccessor,subcategoryAccessor:i.subcategoryAccessor,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Zo(n.gradientFill),pieceStyle:n.pieceStyle||Qo(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},gn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"ridgeline",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...n,summaryStyle:n.summaryStyle||((r,s)=>({fillOpacity:.5,...Qo(t,e,o,n,i)(r,s)})),showLegend:n.showLegend??!!e})},yn={frameType:"ordinal",layout:{margin:(t,e)=>({...e.marginDefaults,left:"vertical"===t.orientation?e.marginDefaults.left:Math.max(100,e.marginDefaults.left)})},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.levels)&&i.levels.length>=2?i.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==i.orientation;let a=function(t,e,o,n,i,r){const s=new Map,a=new Set(e);for(const l of t){const t=o(l);s.has(t)||s.set(t,new Map);const c=s.get(t);if(n){const t=n(l);if(null==t||!Number.isFinite(t))continue;if(!Number.isInteger(t)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",t);continue}const o=t-1;if(0>o||o>=e.length)continue;const i=e[o];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const t=i(l),e=r(l);if(!a.has(t))continue;c.set(t,(c.get(t)||0)+(Number.isFinite(e)?e:0))}}const l=[];for(const[t,o]of s){let n=0;for(const t of e)n+=o.get(t)||0;if(0!==n)for(let i=0;e.length>i;i++){const r=e[i],s=o.get(r)||0;l.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/n*100,__likertLevelIndex:i})}}return l}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,Uo(i.categoryAccessor,"question"),i.levelAccessor?null:Uo(i.valueAccessor,"score"),i.levelAccessor?Uo(i.levelAccessor,"level"):null,i.levelAccessor?Uo(i.countAccessor,"count"):null);s&&(a=function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=new Map;for(const e of t){const t=r.get(e.__likertCategory)||[];t.push(e),r.set(e.__likertCategory,t)}const s=[];for(const[,t]of r){const e=new Map;let r,a;for(const o of t)o.__likertLevel===Ho?r=o:o.__likertLevel===qo?a=o:e.set(o.__likertLevelIndex,o);n&&r&&s.push(r);for(let t=i-1;t>=0;t--){const o=e.get(t);o&&s.push(o)}n&&a&&s.push(a);for(let t=n?i+1:i;o>t;t++){const o=e.get(t);o&&s.push(o)}}return s}(function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(n&&t===i){const t=e.__likertPct/2;r.push({...e,__likertLevel:Ho,__likertPct:-t}),r.push({...e,__likertLevel:qo,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const l=ye(n.theme).colors.diverging,c=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(Vo,e)){const o=Vo[e];if(1===t)return[o(.5)];const n=[];for(let e=0;t>e;e++)n.push(o(e/(t-1)));return n}const o=["#da1e28","#ff8389","#ffb3b8"],n=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===t)return[i];const r=t%2!=0,s=Math.floor(t/2),a=[];for(let t=0;s>t;t++)a.push(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);r&&a.push(i);for(let t=0;s>t;t++)a.push(n[Math.min(Math.floor(t*n.length/s),n.length-1)]);return a}(r.length,l),u=new Map(r.map((t,e)=>[t,c[e]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",p=Ye(!1===n.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},n.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:n.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...n,pieceStyle:ae(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===Ho||e===qo?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},fe(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}},mn={frameType:"ordinal",layout:{margin:(t,e)=>"vertical"===t.orientation?{top:e.title?60:40,right:20,bottom:60,left:60}:{top:e.title?40:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="vertical"===i.orientation,s=e||i.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:i.stepAccessor||"step",rAccessor:i.valueAccessor||"value",colorAccessor:s,categoryAccessor:i.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,...!r&&null!=i.connectorOpacity&&{connectorOpacity:i.connectorOpacity},barPadding:r?40:0,colorScheme:o,...n,showAxes:r&&!1!==n.showAxes,showGrid:r,pieceStyle:Qo(t,s,o,n,i),showLabels:i.showLabels??!0}}},xn={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const o=t.__gauge;if(!o)return null;const n=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,i=o.needleColor||e.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(t=>t.value>o.gMin&&o.gMax>t.value):[];return jo(Wo,{children:[o.showNeedle&&jo(Wo,{children:[Bo("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(n),y2:o.centerY+o.needleLength*Math.sin(n),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),Bo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&Bo("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:i,children:o.contextValue}),r.map((t,n)=>{const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(t.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,s=o.radius+1,a=o.radius+10,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return jo("g",{children:[Bo("line",{x1:o.centerX+Math.cos(i)*r,y1:o.centerY+Math.sin(i)*r,x2:o.centerX+Math.cos(i)*s,y2:o.centerY+Math.sin(i)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),Bo("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:c,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+n)})]})},buildProps:(t,e,o,n,i)=>{const r=i.min??0,s=i.max??100,a=i.sweep??240,l=i.arcWidth??.3,c=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=ft(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],p=ue(n.gradientFill),f=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,n))-e)/d;let p=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];p=p.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>p[p.length-1].value&&p.push({value:o,color:p[p.length-1].color});const f=!!c&&c.stops.length>=2,g=[],y=new Map,m=[];if(f){const t=a?h:1,e=Do("bg",0);if(g.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(e,Math.round(t*e))),n=[];for(let e=0;o>e;e++)n.push(Eo(c.stops,t*(e+.5)/o,r||p[0]?.color||"#007bff"));const i=Do("fill",0);g.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),y.set(i,{fill:n[0]||s})}}else{let t=e;for(let o=0;p.length>o;o++){const n=p[o],i=(n.value-t)/d,r=(t-e)/d,l=(n.value-e)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const t=Do("fill",o);g.push({category:t,value:c,_zone:n.label||"Zone "+(o+1),_isFill:!0}),y.set(t,{fill:n.color})}if(u>0){const t=Do("bg",o);g.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),y.set(t,{fill:s,opacity:.4})}t=n.value}}if(l&&i&&i.length>0)for(const t of i)t.value>e&&o>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:g,pieceStyle:(t,e)=>y.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:p}),[g,y]=n.size||[300,250],m=J(a),x=Math.min(10,Math.max(1,Math.min(g,y)/12)),b=Math.max(4,Math.min((g-2*x)/m.width,(y-2*x)/m.height)-2),v=Math.max(0,Math.min(b-1.5,b*(1-l))),w=g/2-m.cx*b,k=y/2-m.cy*b,A=2*(b+4),S=Math.max(r,Math.min(s,i.value??r)),M="function"==typeof i.valueFormat?i.valueFormat(S):Math.round(S)+"",_=i.centerContent??n.centerContent,P=null!=_?"function"==typeof _?_(S,r,s):_:"sparkline"===i.mode||"context"===i.mode?void 0:Ko.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Ko.createElement("div",{style:{fontSize:Math.max(16,.3*b),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==i.showScaleLabels&&Ko.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:f.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:v,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:ae(f.pieceStyle,fe(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[g,y],margin:{top:k-A/2,bottom:y-k-A/2,left:w-A/2,right:g-w-A/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(n.annotations)?n.annotations:[],...f.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:l,value:S,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:b,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:b-1,showNeedle:c,needleColor:i.needleColor,..."context"===i.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*b))}}}}};import{scaleTime as bn}from"d3-scale";var vn={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function wn(t="static"){return vn[t]??vn.static}var kn=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function An(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:kn.has(t.kind)?"fatal":"warn"}function Sn(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:"duplicate-node"===t.kind?`node id "${t.id}" is duplicated`:"duplicate-edge"===t.kind?`edge id "${t.id}" is duplicated`:"invalid-system-time"===t.kind?`edge ${t.id} has an invalid systemInTime or systemOutTime`:t.kind}function Mn(){return Object.create(null)}function _n(t,e){return e>t?-1:t>e?1:0}function Pn(t){return t.occupants.map(t=>t.id).sort(_n).join("\0")}function Ln(t,e,o=0){return t.slice(0,-1).map((n,i)=>null!=n.group&&n.group===t[i+1].group?o:e)}function $n(t,e){return t.map(t=>{const o=new Map;for(const n of t.occupants){const t=e[n.id];if(t)for(const e of t.samples){const t=o.get(e.t)??{before:0,after:0},n=e.boundaryOffset??0;o.set(e.t,{before:Math.max(t.before,e.topMass-n),after:Math.max(t.after,e.botMass+n)})}}return[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function Rn(t,e,o){if(0===t.length)return[];const{padding:n,plotH:i,valueScale:r}=o,s=o.stackValueScale??r,a=Ln(t,n,o.groupPadding??0),l=[n+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)l.push(l[o-1]+e[o-1]*s+a[o-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*s+n;if(c>i&&c>0){const t=i/c;for(let e=0;l.length>e;e++)l[e]*=t}return l}function Cn(t,e){const o=(t.boundaryOffset??0)*e,n=t.value*e;if("out"===t.kind){const i=t.sideMassBefore*e;return o+("top"===t.side?n/2-i:i-n/2)}const i=t.sideMassAfter*e;return o+("top"===t.side?n/2-i:i-n/2)}function Tn(t,e,o,n,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:$($n(n,o)).adjacentClearance,a=Rn(n,s,r);let l="hug"===r.lanePlacement?function(t,e,o,n,i,r,s){const a=t.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=Ln(t,l,s.groupPadding??0),h=i.map((t,e)=>t*u+d[e]),p=l+t[0].peak.topPeak*u,f=c-l-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=f-p)return Rn(t,i,s);let g=1===a?[(p+f)/2]:[...r];for(let t=0;12>t;t++){const t=Array(a).fill(0),i=Array(a).fill(0);for(const r of o){const o=e[r.source],s=e[r.target];if(null==o||null==s||o===s)continue;const a=n[r.source]?.localAttachments.get(r.id),l=n[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=Cn(a,u),h=Cn(l,u);t[o]+=(g[s]+h-d)*c,i[o]+=c,t[s]+=(g[o]+d-h)*c,i[s]+=c}const r=g.map((e,o)=>0===i[o]?e:.45*e+t[o]/i[o]*.55),s=R({desired:r,minGaps:h,weights:i.map(t=>Math.max(1,t)),min:p,max:f});let l=0;for(let t=0;a>t;t++)l=Math.max(l,Math.abs(s[t]-g[t]));if(g=s,.01>l)break}return g}(n,i,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=Mn();for(const n of t)o[n.id]=e[i[n.id]];return o};On(o(l),e)>On(o(a),e)+1e-6&&(l=[...a])}const c=Mn();for(const e of t)c[e.id]=l[i[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=c[e.id],n=o[e.id];Number.isFinite(t)&&n&&(u=Math.min(u,t-n.topPeak*r.valueScale),d=Math.max(d,t+n.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function On(t,e){let o=0;for(const n of e){const e=t[n.source],i=t[n.target];Number.isFinite(e)&&Number.isFinite(i)&&(o+=Math.abs(e-i)*(n.value>0?n.value:1))}return o}function In(t,e){const o=t?.samples;if(!o||0===o.length||o[0].t>e)return{top:0,bot:0};let n=0,i=o.length-1,r=0;for(;i>=n;){const t=n+i>>>1;o[t].t>e?i=t-1:(r=t,n=t+1)}const s=o[r].boundaryOffset??0;return{top:o[r].topMass-s,bot:o[r].botMass+s}}function zn(t,e,o,n,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*o+i*i*i*n}function Fn(t,e){let o=0,n=1;for(let i=0;28>i;i++){const i=(o+n)/2;t>zn(0,e,e,1,i)?o=i:n=i}return(o+n)/2}function Nn(t,e,o){const n=e+Cn(t,o),i=t.value*o/2;return[n-i,n+i]}function En(t,e,o,n){return Math.max(0,Math.min(e,n)-Math.max(t,o))/Math.max(1e-9,e-t)}function Dn(t,e,o,n,i,r,s){const{valueScale:a,domain:l,mode:c="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of t){const t=n[s.source],h=n[s.target];if(null==t||null==h||2>Math.abs(t-h))continue;const p=e[s.source]?.localAttachments.get(s.id),f=e[s.target]?.localAttachments.get(s.id);if(!p||!f)continue;const g=Math.max(s.startTime,l?.[0]??-1/0),y=Math.min(s.endTime,l?.[1]??1/0);if(g>=y)continue;const[m,x]=Nn(p,i[s.source],a),[b,v]=Nn(f,i[s.target],a),w=Math.min(t,h)+1,k=Math.max(t,h)-1;for(let t=w;k>=t;t++){const n=o[t];if(!n)continue;const l=[g,y];if("quality"===c)for(const t of n.occupants)for(const o of e[t.id]?.samples??[])o.t>g&&y>o.t&&l.push(o.t);const h=t=>{const o=Fn((t-g)/(y-g),u),l=zn(m,m,b,b,o),c=zn(x,x,v,v,o);let d=0;for(const o of n.occupants){if(o.id===s.source||o.id===s.target)continue;const n=r[o.id];if(null!=n?.start&&n.start>t)continue;if(null!=n?.end&&t>n.end)continue;const u=In(e[o.id],t),h=i[o.id];d=Math.max(d,En(l,c,h-u.top*a,h+u.bot*a))}return d},p=[...new Set(l)].sort((t,e)=>t-e);let f=0;for(let t=0;p.length-1>t;t++){const e=p[t],o=p[t+1]-e;f+=(h(e+.25*o)+h(e+.5*o)+h(e+.75*o))/3*o}d+=f/(y-g)*(s.value>0?s.value:1)}}return d}function Wn(t,e,o,n,i,r,s,a,l,c,u="both",d){return{crossings:t,weightedLength:e,pixelLength:On(s,o),transitOcclusion:Dn(o,n,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Bn(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function jn(t,e){return t.map(t=>({t:Bn(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function Yn(t,e,o){const n=e+(t.boundaryOffset??0)*o,i=t.value*o;if("out"===t.kind){const e=t.sideMassBefore*o;if("top"===t.side){const t=n-e;return[t,t+i]}const r=n+e;return[r-i,r]}const r=t.sideMassAfter*o;if("top"===t.side){const t=n-r;return[t,t+i]}const s=n+r;return[s-i,s]}function Xn(t,e,o,n,i="temporal"){const r=e.incoming[t.id],s=e.outgoing[t.id],a=[];for(const t of r)a.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of s)a.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(l[t.kind]??99)-(l[e.kind]??99)||((t,e)=>{if(!n||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const o=n.get(t.edge.id)?.target,i=n.get(e.edge.id)?.target;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===t.side?o-i:i-o:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const o=n.get(t.edge.id)?.source,i=n.get(e.edge.id)?.source;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===t.side?i-o:o-i:0}return 0})(t,e)||_n(t.edge?.id??"",e.edge?.id??"")||_n(t.side,e.side)||t.delta-e.delta)},u=a.length?At(a.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let p=null,f=0;for(const t of a)t.time!==p&&(p=t.time,f=0),t.sequence=f++;const g=t=>({time:t.time,phase:0,sequence:t.sequence??0}),y=[];let m=0,x=0;for(const t of a)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?m:x);if(o>0){const e="top"===t.side?"bot":"top",n=Math.min(o,"top"===e?m:x);if(n>0){const i=g(t);y.push({...i,delta:-n,kind:"transfer-out",side:e}),y.push({...i,delta:+n,kind:"transfer-in",side:t.side}),"top"===e?m-=n:x-=n,"top"===t.side?m+=n:x+=n,o-=n}o>0&&null!==h&&(y.push({time:h,delta:+o,kind:"create",side:t.side}),"top"===t.side?m+=o:x+=o)}"top"===t.side?m-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?m+=e:x+=e}a.push(...y),c();let b=0,v=0,w=0,k=0,A=0,S=0;const M=[],_=new Map,P=t=>{M.push({t:t,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},L=()=>{k=Math.max(k,b+v),A=Math.max(A,b-w),S=Math.max(S,v+w)};for(const t of a){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&P(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?b:v;_.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?b+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,L(),P(t.time)):"transfer-out"!==t.kind&&(L(),"out"!==t.kind||b+v>1e-12||(w=0),P(t.time))}const $=[];let R=0;for(;M.length>R;){let t=R;for(;M.length>t+1&&M[t+1].t===M[R].t;)t++;$.push(M[R]);for(let e=R+1;t>=e;e++){const t=$[$.length-1];M[e].topMass===t.topMass&&M[e].botMass===t.botMass&&(M[e].boundaryOffset??0)===(t.boundaryOffset??0)||$.push(M[e])}R=t+1}const C=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let T=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===T||T>t.systemInTime)&&(T=t.systemInTime);let O=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===O||t.systemOutTime>O)&&(O=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=C?C:-1/0,null!=O?O:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&$.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const o=$[0],n=$.find(t=>t.topMass+t.botMass>0);let i,r=1/0;null!=d&&Number.isFinite(d)&&o.t>d&&o.topMass+o.botMass>0&&(r=d,i=o),n&&null!=T&&Number.isFinite(T)&&n.t>T&&r>T&&(r=T,i=n),i&&Number.isFinite(r)&&$.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let I=$;if("max"===i&&null!=d&&null!=C&&C>d){let t,e=0;for(const o of $){const n=o.topMass+o.botMass;n>e&&(e=n,t=o)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};I=[...$.filter(t=>d>t.t),{t:d,...e},{t:C,...e},...$.filter(t=>t.t>C)]}}return{samples:I,peak:k,topPeak:A,botPeak:S,localAttachments:_}}function Gn(t){const e=Mn();return t.forEach((t,o)=>{for(const n of t.occupants)e[n.id]=o}),e}function Vn(t,e,o){t.splice(0,t.length,...o);const n=Gn(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,n)}function Hn(t){const e=new Map,o=[];t.forEach((t,n)=>{if(!t.group)return void o.push({anchor:n,stableId:Pn(t),slots:[t]});const i=e.get(t.group)??{indexes:[],slots:[]};i.indexes.push(n),i.slots.push(t),e.set(t.group,i)});for(const[t,n]of e)o.push({anchor:n.indexes.reduce((t,e)=>t+e,0)/n.indexes.length,stableId:`${t}\0${n.slots.map(Pn).join("\0")}`,slots:n.slots});return o.sort((t,e)=>t.anchor-e.anchor||_n(t.stableId,e.stableId))}function qn(t){return t.some(t=>t.group)?Hn(t).flatMap(t=>t.slots):[...t]}function Un(t){return t.flatMap(t=>t.slots)}function Kn(t,e,o){const n=new Map;return t.forEach((t,e)=>{for(const o of t.slots)n.set(o,e)}),t.map((t,i)=>{if(1>=t.slots.length)return t;const r=new Map;for(const e of t.slots)r.set(e,0);for(const t of e){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o)continue;const s=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===i&&o!==i){const e=o>i?1:-1;r.set(t.source,(r.get(t.source)??0)+s*e)}else if(o===i&&e!==i){const o=e>i?1:-1;r.set(t.target,(r.get(t.target)??0)+s*o)}}const s=[...t.slots].sort((t,e)=>(r.get(t)??0)-(r.get(e)??0)||o(t,e));return{...t,slots:s}})}function Zn(t,e){t.some(t=>t.group)&&Vn(t,e,qn(t))}function Qn(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.min(t.endTime,e.endTime)>Math.max(t.startTime,e.startTime)}function Jn(t,e){return c(e,e=>[t[e.source],t[e.target]],Qn)}function ti(t,e){let o=0;for(const n of e){const e=t[n.source],i=t[n.target];null!=e&&null!=i&&(o+=Math.abs(e-i)*(n.value>0?n.value:1))}return o}function ei(t,e,o){const[n,i]=o.get(t.first),[r,s]=o.get(t.second);return 0>(e.get(n)-e.get(r))*(e.get(i)-e.get(s))?1:0}var oi=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},ni=828*oi(8),ii=3e3;function ri(t,e,o,n,i,r,s){const a=[...i],l=new Map(i.map(t=>[t,Pn(t)])),c=new Map;for(const t of i)for(const e of t.occupants)c.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=c.get(t.source),o=c.get(t.target);e&&o&&(u.set(t,[e,o]),e!==o&&d.push({source:e,target:o,weight:t.value}))}const h=[];for(let t=0;e.length>t;t++)if(u.has(e[t]))for(let o=t+1;e.length>o;o++){if(!u.has(e[o])||!Qn(e[t],e[o]))continue;const n=new Set([...u.get(e[t]),...u.get(e[o])]);h.push({index:h.length,first:e[t],second:e[o],involvedSlots:n})}const p=new Map;for(const t of i)p.set(t,[]);for(const t of h)for(const e of t.involvedSlots)p.get(e)?.push(t);const f=new Uint32Array(h.length);let g=0;const y=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),m=s.plotH/Math.max(1,i.length),x=i.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),b=Math.max(1,y)*(Math.max(1,s.plotH)+m*Math.max(x,i.length)+1e-6*Math.max(1,i.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,A=(t,e)=>{let n=k.get(t);n||(n=new Map,k.set(t,n));const i=n.get(e);if(null!=i)return i;const r=function(t,e,o){return $($n([t,e],o)).adjacentClearance[0]??0}(t,e,o);return n.set(e,r),r},S=new Map(i.map((t,e)=>[t,e])),M=e.flatMap(t=>{const e=u.get(t);return e?[{source:S.get(e[0]),target:S.get(e[1]),weight:t.value>0?t.value:1}]:[]}),_=new Map;for(const t of e){const e=u.get(t);e&&_.set(t,{source:S.get(e[0]),target:S.get(e[1])})}const R=new Map,C=new Map,T=new Map,O=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)O(R,t.source,t.target),O(C,t.target,t.source),O(T,t.source,t.target),O(T,t.target,t.source);const I=e.flatMap(t=>{if(!(t=>1===R.get(t.source)?.size&&R.get(t.source).has(t.target)||1===T.get(t.source)?.size||1===T.get(t.target)?.size)(t))return[];const e=_.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),F=t=>{let e=0;for(const o of I)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*v},N=t=>{const e=new Int16Array(i.length);for(let o=0;t.length>o;o++)e[S.get(t[o])]=o;return F(e)},E=h.map(t=>{const e=_.get(t.first),o=_.get(t.second);return[e.source,e.target,o.source,o.target]}),D=new Int16Array(i.length),W=new Float64Array(i.length),B=new Float64Array(i.length+1),j=t=>{for(let e=0;t.length>e;e++)D[S.get(t[e])]=e;let e=0;for(const[t,o,n,i]of E)0>(D[t]-D[n])*(D[o]-D[i])&&e++;if(t.length>0){const e=S.get(t[0]);W[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const o=S.get(t[e-1]),n=S.get(t[e]);W[n]=W[o]+A(t[e-1],t[e])*s.valueScale+s.padding}const o=S.get(t[t.length-1]),n=W[o]+t[t.length-1].peak.botPeak*s.valueScale+s.padding;if(n>s.plotH&&n>0){const t=s.plotH/n;for(let e=0;W.length>e;e++)W[e]*=t}}B[0]=0;for(let e=0;t.length>e;e++)B[e+1]=B[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,n=0,i=0;for(const t of M){const e=D[t.source],r=D[t.target];if(o+=Math.abs(e-r)*t.weight,n+=Math.abs(W[t.source]-W[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;i+=(B[Math.max(e,r)]-B[o])*t.weight}}return e*b+n+i*m+F(D)+1e-6*o},Y=(t,o)=>{const n=Array(t.length+1).fill(0);for(let e=0;t.length>e;e++)n[e+1]=n[e]+t[e].peak.topPeak+t[e].peak.botPeak;let i=0;for(const t of e){const e=o[t.source],r=o[t.target];if(null==e||null==r||2>Math.abs(e-r))continue;const s=Math.min(e,r)+1;i+=(n[Math.max(e,r)]-n[s])*(t.value>0?t.value:1)}return i},X=n=>{const i=Gn(n),r=n.slice(0,-1).map((t,e)=>A(t,n[e+1])),a=Tn(t,e,o,n,i,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:i,geometry:a,weightedLength:ti(i,e),pixelLength:On(a.centerlines,e),transitOcclusion:Y(n,i)}},G=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*b+e.pixelLength+e.transitOcclusion*m+N(o)+1e-6*e.weightedLength}),V=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+ei(o,e,u),0),w.fullCrossing++}return G(o,X(t),t)},H=(t,i,r="quality")=>{let a=i;if(null==a){const e=new Map(t.map((t,e)=>[t,e]));a=h.reduce((t,o)=>t+ei(o,e,u),0),w.fullCrossing++}const l=X(t);return G(a,{...l,transitOcclusion:Dn(e,o,t,l.map,l.geometry.centerlines,n,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let q=[...a];const U=(t,e)=>_n(l.get(t),l.get(e)),K=function(t){const e=new Set;for(const o of t)if(o.group){if(e.has(o.group))return!0;e.add(o.group)}return!1}(q),Z=t=>{const e=(t=>{const e=P(t,d,t=>V(t).cost,{passes:6,compare:U,maxEvaluations:ii});let o=V(e),n=ii;for(let t=0;6>t&&n>0;t++){let i=!1;const r=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&r.reverse();for(const t of r){if(0>=n--)break;const r=e[t],s=e[t+1],a=new Map(e.map((t,e)=>[t,e]));let l=0;const c=[];g++;for(const t of[...p.get(r)??[],...p.get(s)??[]])f[t.index]!==g&&(f[t.index]=g,c.push(t),l+=ei(t,a,u));[e[t],e[t+1]]=[s,r];const d=new Map(a);d.set(r,t+1),d.set(s,t);let h=0;for(const t of c)h+=ei(t,d,u);w.localCrossing+=c.length;const y=V(e,o.crossings-l+h);o.cost>y.cost?(o=y,i=!0):[e[t],e[t+1]]=[r,s]}if(!i)break}return e})(t);if((t.length>8?1/0:oi(t.length)*(t.length+M.length+E.length))>ni)return e;const o=L(t,j,{maxItems:8,maxEvaluations:5e4}),n=H(o),i=H(e);return n.crossings!==i.crossings&&i.crossings>n.crossings?o:e},Q="geometry-refine"===s.mode;if(Q||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!Q&&"inside-out"===s.laneOrder)if(K){const t=Hn(q),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||_n(t.stableId,o.stableId)),n=Array(o.length);let i=Math.floor((o.length-1)/2)-1,r=Math.floor((o.length-1)/2)+1;o.length>0&&(n[Math.floor((o.length-1)/2)]=o[0]);for(let t=1;o.length>t;t++)t%2==1&&o.length>r||0>i?n[r++]=o[t]:n[i--]=o[t];q=Un(n)}else{const t=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(t,e)),e=Array(t.length);let o=Math.floor((t.length-1)/2)-1,n=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let i=1;t.length>i;i++)i%2==1&&t.length>n||0>o?e[n++]=t[i]:e[o--]=t[i];q=e}}else q=K?(t=>{let e=Hn(t);if(1>=e.length)return Un(e);const o=t=>V(Un(t)).cost;e=Hn(Z(t)),e=Kn(e,d,U);const n=function(t,e){const o=new Map;for(const e of t)for(const t of e.slots)o.set(t,e);const n=new Map;for(const t of e){const e=o.get(t.source),i=o.get(t.target);if(!e||!i||e===i)continue;const r=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,s=i.stableId>e.stableId?`${e.stableId}\0${i.stableId}`:`${i.stableId}\0${e.stableId}`,a=n.get(s);a?a.weight=(a.weight??0)+r:n.set(s,{source:e,target:i,weight:r})}return[...n.values()]}(e,d);e=P(e,n,o,{passes:6,compare:(t,e)=>_n(t.stableId,e.stableId),maxEvaluations:ii}),e=z(e,o,{passes:8,maxEvaluations:ii});const i=e.length>8?1/0:oi(e.length)*(e.length+M.length+E.length);if(ni>=i){const t=L(e,t=>j(Un(t)),{maxItems:8,maxEvaluations:5e4}),o=Un(t),n=Un(e),i=H(o),r=H(n);i.crossings!==r.crossings?e=r.crossings>i.crossings?t:e:r.cost>i.cost&&(e=t)}return e=Kn(e,d,U),Un(e)})(q):Z(q);if(!Q&&"crossing-min+inside-out"===s.laneOrder&&q.length>1)if(K){const t=Hn(q);let e=V(Un(t)),o=Un(t),n=e;const i=Math.floor((t.length-1)/2),r=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),s=[...t].sort((t,e)=>r(e)-r(t)||_n(t.stableId,e.stableId));for(const r of s){const s=t.indexOf(r);if(s===i)continue;t.splice(s,1),t.splice(i,0,r);const a=Un(t),l=V(a);l.cost>e.cost?(t.splice(i,1),t.splice(s,0,r)):(e=l,n.cost>l.cost&&(o=a,n=l))}q=o}else{let t=V(q),e=[...q],o=t;const n=Math.floor((q.length-1)/2),i=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(t,e));for(const r of i){const i=q.indexOf(r);if(i===n)continue;q.splice(i,1),q.splice(n,0,r);const s=V(q);s.cost>t.cost?(q.splice(n,1),q.splice(i,0,r)):(t=s,o.cost>s.cost&&(e=[...q],o=s))}q=e}if((Q||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&q.length>1)if(K){let t=Hn(q),e=H(Un(t),void 0,"score");for(let o=0;6>o&&t.length>1;o++){let o=!1;for(let n=0;t.length-1>n;n++){[t[n],t[n+1]]=[t[n+1],t[n]];const i=Un(t),r=H(i,void 0,"score");e.cost>r.cost?(q=i,e=r,o=!0):[t[n],t[n+1]]=[t[n+1],t[n]]}if(!o)break}t=Kn(Hn(q),d,U),q=Un(t)}else{let t=H(q,void 0,"score");for(let e=0;q.length-1>e;e++){const o=q[e],n=q[e+1],i=new Map(q.map((t,e)=>[t,e]));let r=0;const s=[];g++;for(const t of[...p.get(o)??[],...p.get(n)??[]])f[t.index]!==g&&(f[t.index]=g,s.push(t),r+=ei(t,i,u));[q[e],q[e+1]]=[n,o];const a=new Map(i);a.set(o,e+1),a.set(n,e);let l=0;for(const t of s)l+=ei(t,a,u);w.localCrossing+=s.length;const c=H(q,t.crossings-r+l,"score");t.cost>c.cost?t=c:[q[e],q[e+1]]=[o,n]}}const J=qn(a);q=qn(q);let tt=H(q);const et=H(J);if(Q){const t=N(J),e=N(q);(tt.crossings>et.crossings||tt.crossings===et.crossings&&e>t+1e-9||tt.cost>et.cost)&&(q=J,tt=et)}else tt.cost>et.cost&&(q=J,tt=et);const ot=function({order:t,after:e,nodes:o,edges:n,outgoingPartners:i,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:l}){const c=(o,i)=>{const r=[...new Set(i.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),c=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-c+1!==r.length||1>=Math.abs(2*s-c-u))return;const d=[...t];d.splice(s,1),d.splice(c+u>>1,0,o);const h=qn(d),p=l(h),f=new Set(o.occupants.map(t=>t.id)),g=new Set(i.flatMap(t=>t.occupants.map(t=>t.id))),y=n.reduce((t,e)=>f.has(e.source)&&g.has(e.target)||f.has(e.target)&&g.has(e.source)?t+(e.value>0?e.value:1):t,0);(function(t,e,o=0){return e.crossings>t.crossings||t.crossings===e.crossings&&e.cost+o>=t.cost})(p,e,Math.abs(2*s-c-u)*a*Math.max(1,y))&&(t=h,e=p)};for(const[t,e]of i)r.has(t)||3>e.size||c(s.get(t),[...e].map(t=>s.get(t)));for(const t of o){const e=s.get(t.id);t.group||!e.group||3>(r.get(t.id)?.size??0)||c(e,[...r.get(t.id)??[]].map(t=>s.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,o)=>o.indexOf(t)===e))}return{order:t,after:e}}({order:q,after:tt,nodes:t,edges:e,outgoingPartners:R,incomingPartners:C,slotForNode:c,averageGap:m,evaluate:H});return q=ot.order,tt=ot.after,Vn(i,r,q),{before:et,after:tt,initialOrder:a.map(t=>l.get(t)),evaluations:w}}function si(t,e,o){const n=t.map(t=>{const n=t.occupants.map(t=>({id:t.id,end:o[t.id]?.end??t.end}));let i=0,r=0;for(const t of n){const o=e[t.id];i=Math.max(i,o?.topPeak||0),r=Math.max(r,o?.botPeak||0)}return{occupants:n,peak:{topPeak:i,botPeak:r},...null!=t.group?{group:t.group}:{}}}),i=Mn();return n.forEach((t,e)=>{for(const o of t.occupants)i[o.id]=e}),{slots:n,slotByNode:i}}var ai=new Map,li=1e5,ci=1e-9;function ui(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function di(t,e){return _n(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function hi(t){const e=new Map,o=new Map;for(const n of t)o.has(n.source)||o.set(n.source,new Set),e.has(n.target)||e.set(n.target,new Set),o.get(n.source).add(n.target),e.get(n.target).add(n.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...o].map(([t,e])=>[t,e.size]))}}function pi(t){const e=new Map,o=new Map,n=(t,e,o,n)=>{let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(o,(i.get(o)??0)+n)};for(const i of t){const t=i.value>0&&Number.isFinite(i.value)?i.value:1;n(e,i.source,i.target,t),n(o,i.target,i.source,t)}const i=new Map,r=t=>{if(i.has(t))return;const n=e.get(t),r=o.get(t),s=new Map;for(const[t,e]of n??[])s.set(t,(s.get(t)??0)+e);for(const[t,e]of r??[])s.set(t,(s.get(t)??0)+e);if(1===s.size){const[e,o]=[...s][0];i.set(t,{partner:e,weight:o})}};for(const e of t)r(e.source),r(e.target);return i}function fi(t,e,o){const n=o.get(t),i=o.get(e);return!n||!i||n.partner===i.partner||n.partner===e||i.partner===t}function gi(t,e,o){return!!o.has(t)&&e.some(e=>!fi(t,e,o))}function yi(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function mi(t,e,o,n){if(12>=t.length||1>=n.slotCount)return n.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Map),s=hi(o);for(const t of o){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o||e===o)continue;const n=yi(t,s);r[e].set(o,(r[e].get(o)??0)+n),r[o].set(e,(r[o].get(e)??0)+n)}const a=pi(o),l=t.map(t=>a.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let o=0;t.length-1>o&&5e4>u;o++)if(a.has(t[o]))for(let n=o+1;t.length>n;n++){if(!a.has(t[n]))continue;if(e.conflicts(t[o],t[n]))continue;u++;const i=Math.min(l[o],l[n])||Math.max(l[o],l[n]),r=fi(t[o],t[n],a)?i:-i;if(Math.abs(r)>ci&&(c[o].set(n,r),c[n].set(o,r),u>=5e4))break}const d=[...n.assignment],h=Array.from({length:n.slotCount},()=>[]);d.forEach((t,e)=>h[t].push(e));const p=(t,e,o)=>{const n=d[e],i=d[o];let r=0;const s=new Set;for(const a of[e,o])for(const[l,c]of t[a]){const t=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?i:n)===(l===e?i:l===o?n:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}return r},f=(t,e,o)=>{let n=0;for(const[i,r]of t[e]){const t=o===d[i];d[e]===d[i]!==t&&(n+=t?r:-r)}return n},g=(t,e)=>t>ci||ci>=Math.abs(t)&&e>ci,y=(t,e,o,n)=>t>o+ci||ci>=Math.abs(t-o)&&e>n+ci;let m=0;for(let o=0;32>o&&li>m;o++){let o=null,n=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;t.length>u;u++){for(let p=0;h.length>p&&m++<li;p++){if(p===d[u])continue;if(!h[p].every(o=>!e.conflicts(t[u],t[o])))continue;const m=f(r,u,p),x=f(c,u,p);g(m,x)&&y(m,x,a,l)&&(o="move",n=u,i=-1,s=p,a=m,l=x)}if(m>=li)break}for(let u=0;t.length-1>u;u++){for(let f=u+1;t.length>f&&m++<li;f++){const m=d[u],x=d[f];if(m===x)continue;if(!h[x].every(o=>o===f||!e.conflicts(t[u],t[o])))continue;if(!h[m].every(o=>o===u||!e.conflicts(t[f],t[o])))continue;const b=p(r,u,f),v=p(c,u,f);g(b,v)&&y(b,v,a,l)&&(o="swap",n=u,i=f,s=-1,a=b,l=v)}if(m>=li)break}if(null==o||-1===n)break;if("move"===o){const t=d[n];h[t].splice(h[t].indexOf(n),1),h[s].push(n),d[n]=s;continue}const u=d[n],x=d[i];h[u].splice(h[u].indexOf(n),1,i),h[x].splice(h[x].indexOf(i),1,n),d[n]=x,d[i]=u}return d}function xi(t,e){let o=1/0,n=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass>1e-9&&(o=Math.min(o,e.t),n=Math.max(n,e.t));return Number.isFinite(o)&&Number.isFinite(n)?(null!=e.start&&(o=Math.max(o,e.start)),null!=e.end&&(n=Math.min(n,e.end)),o>n?{start:null,end:null}:{start:o,end:n}):{start:null,end:null}}function bi(t,e,o,n){const i=function(t,e,o,n){return`${t.map(t=>{const e=o[t.id],i=n[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,i?.start??"",i?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,o,n),r=ai.get(i);if(r)return si(r.slots,o,n);const s=Mn();for(const e of t)s[e.id]=xi(o[e.id],n[e.id]);const a=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,o)=>e[t.id].start-e[o.id].start||e[t.id].end-e[o.id].end||_n(t.id,o.id)).map(t=>t.id)}(t,s),l=new Map(t.map(t=>[t.id,t])),c=new Map(t.map(t=>[t.id,t.group||void 0])),u=pi(e),d=function(t,e,o,n,i,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of n)s.add(di(t.source,t.target)),a.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=new Map,u=new Set,d=(t,e)=>{for(let o=0;t.length>o;o++)for(let n=o+1;t.length>n;n++){const i=di(t[o],t[n]);e instanceof Map?e.set(i,[t[o],t[n]]):e.add(i)}};for(const t of l.values())d([...t],c);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[n,i]]of c)u.has(t)&&(ui(e[n],e[i])||ui(o[n],o[i])&&(h.add(n),h.add(i)));return{conflicts:(t,o)=>{const n=i.get(t),a=i.get(o);return null!=n&&null!=a&&n!==a||!(null!=n==(null!=a)||s.has(di(t,o))||r.has(t)&&r.has(o)&&fi(t,o,r))||!!ui(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(di(t,o))}}}(a,s,n,e,c,u),h=function(t,e,o=new Map){const n=[],i=[];for(const r of t){let t=n.findIndex(t=>t.every(t=>!e.conflicts(r,t))&&!gi(r,t,o));-1!==t||o.has(r)||(t=n.findIndex(t=>t.every(t=>!e.conflicts(r,t)))),-1===t&&(t=n.length,n.push([])),n[t].push(r),i.push(t)}return{assignment:i,slotCount:n.length}}(a,d,u),p=function(t,e,o,n){if(0===t.length||t.length>12||1>=n.slotCount)return n.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Float64Array(t.length)),s=Array.from({length:t.length},()=>new Map),a=Array.from({length:t.length},()=>new Map),l=hi(o);for(const t of o){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o||e===o)continue;const n=yi(t,l);r[e][o]+=n,r[o][e]+=n,a[e].set(o,(a[e].get(o)??0)+n),s[o].set(e,(s[o].get(e)??0)+n)}const c=pi(o),u=t.map(t=>c.get(t)?.weight??0),d=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;t.length>e;e++)for(let o=e+1;t.length>o;o++){for(const[t,n]of s[e])d[e][o]+=Math.min(n,s[o].get(t)??0);for(const[t,n]of a[e])d[e][o]+=Math.min(n,a[o].get(t)??0);if(c.has(t[e])&&c.has(t[o])){const n=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=fi(t[e],t[o],c)?n:-n}d[o][e]=d[e][o]}let h=[...n.assignment],p=(e=>{let o=0,n=0;for(let i=0;t.length>i;i++)for(let s=i+1;t.length>s;s++)e[i]===e[s]&&(o+=r[i][s],n+=d[i][s]);return{flow:o,affinity:n}})(h),f=0;const g=Array(t.length).fill(-1),y=Array.from({length:n.slotCount},()=>[]),m=(o,i,s,a)=>{if(f>=75e3)return;if(o===t.length)return f++,void((s>p.flow||s===p.flow&&a>p.affinity||s===p.flow&&a===p.affinity&&function(t,e){for(let o=0;Math.min(t.length,e.length)>o;o++)if(t[o]!==e[o])return e[o]>t[o];return e.length>t.length}(g,h))&&(h=[...g],p={flow:s,affinity:a}));const l=Math.min(i+1,n.slotCount-1);for(let n=0;l>=n;n++){if(y[n].some(n=>e.conflicts(t[o],t[n])))continue;let l=0,c=0;for(const t of y[n])l+=r[o][t],c+=d[o][t];if(g[o]=n,y[n].push(o),m(o+1,Math.max(i,n),s+l,a+c),y[n].pop(),g[o]=-1,f>=75e3)return}};return g[0]=0,y[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:mi(a,d,e,h)}),f=new Map,g=p.map(t=>(f.has(t)||f.set(t,f.size),f.get(t))),y=Array.from({length:f.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=Mn();a.forEach((t,e)=>{const o=g[e],n=y[o];n.occupants.push({id:t,end:s[t].end??-1/0});const i=l.get(t)?.group;i&&(n.group=i),m[t]=o});for(const e of[...t].sort((t,e)=>_n(t.id,e.id)))null==m[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||_n(t.id,e.id));for(const e of t.occupants){const n=o[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,n?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,n?.botPeak||0)}}const x={slots:y,slotByNode:m};return function(t,e){for(ai.has(t)&&ai.delete(t),ai.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(Mn(),e.slotByNode)});ai.size>12;){const t=ai.keys().next().value;if(null==t)break;ai.delete(t)}}(i,x),x}function vi(t){return t.topMass+t.botMass}function wi(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>vi(e)<vi(t)?t:e,o[0]);let n=null;for(const o of t.samples){if(o.t>e)break;n=o}return n}function ki(t,e,o,n,i,r,s=0){const a=new Map;for(const o of t){if(!o.group||!e[o.id])continue;const t=a.get(o.group)??[];t.push(o),a.set(o.group,t)}if(0===a.size||0>=r)return e;const l=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}]));for(const[t,c]of a){const a=o.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=i[u.occupants[0]?.id],p=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(p))continue;const f=(h-u.peak.topPeak*r+(p+d.peak.botPeak*r))/2,g=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),y=new Map;for(const t of c)y.set(t.id,new Map);for(const t of g){const o=new Map;for(const i of c){const r=wi(e[i.id],t);if(!r||1e-9>=vi(r))continue;const s=n[i.id];if(null==s)continue;const a=o.get(s)??[];a.push({node:i,sample:r}),o.set(s,a)}const a=[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>vi(t)))}));if(0===a.length)continue;let l=f-(a.reduce((t,e)=>t+e.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const e of a){for(const{node:o,sample:n}of e.active){const e=(l-i[o.id])/r+n.topMass-(n.boundaryOffset??0);y.get(o.id).set(t,e)}l+=e.mass*r+Math.max(0,s)}}for(const t of c){const o=e[t.id],n=l[t.id],i=y.get(t.id),r=[];for(const t of g){const e=i.get(t),n=o.samples.filter(e=>e.t===t);if(n.length>0){r.push(...n.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const s=wi(o,t);null!=e&&s&&vi(s)>1e-9&&r.push({...s,t:t,boundaryOffset:(s.boundaryOffset??0)+e})}n.samples=r,n.localAttachments=new Map([...o.localAttachments].map(([t,e])=>{const o=i.get(e.time);return[t,{...e,...null!=o?{boundaryOffset:(e.boundaryOffset??0)+o}:{}}]}))}}return l}function Ai(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:p="both",domain:f}=i,g=Mn(),y=Mn();for(const e of t)g[e.id]=o[e.id].topPeak||0,y[e.id]=o[e.id].botPeak||0;const m="half"===u,x=Mn();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,o=Array.isArray(e.xExtent)?e.xExtent[1]:null;let i=null!=t&&Number.isFinite(t)?t:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const t of n.outgoing[e.id]){i>t.startTime&&(i=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&i>t.systemInTime&&(i=t.systemInTime);const e=m?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of n.incoming[e.id]){const e=m?(t.startTime+t.endTime)/2:t.startTime;i>e&&(i=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}x[e.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}let b=Mn(),v=[],w=[];if(i.frozenSlots){const t=si(i.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(Pn)}else if("reuse"===l){const n=bi(t,e,o,x);v=n.slots,b=n.slotByNode}else t.forEach((t,e)=>{v.push({occupants:[{id:t.id,end:x[t.id]?.end??-1/0}],peak:{topPeak:g[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});Zn(v,b),0===w.length&&(w=v.map(Pn));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(t,e,o){const n=new Map(o.map((t,e)=>[t,e]));Vn(t,e,[...t].sort((t,e)=>(n.get(Pn(t))??1/0)-(n.get(Pn(e))??1/0)||_n(Pn(t),Pn(e))))}(v,b,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(k=ri(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:p,domain:f}))),Zn(v,b);const A=Tn(t,e,o,v,b,{plotH:r,padding:s,valueScale:a,stackValueScale:i.stackValueScale,lanePlacement:d,groupPadding:h}),S=0===v.length?0:v[0].peak.topPeak+A.adjacentClearance.reduce((t,e)=>t+e,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,L=k?.after.weightedLength??null;return{effectiveSlotsHeight:S,centerlines:A.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:A.slotCenter,stackCenter:A.stackCenter,verticalUtilization:A.verticalUtilization,selectedSlotOrder:v.map(Pn),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function Si(t){const{sx:e,sTop:o,sBot:n,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:l}=t,c=(o+n)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${l},${r} ${i},${r}`,`L${i},${s}`,`C${l},${s} ${a},${n} ${e},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:a,y:c},{x:l,y:u},{x:i,y:u}],halfWidth:(n-o)/2}}}function Mi(t,e,o,n,i,r,s,a,l={}){const c=i,u=t=>a?Math.max(a[0],Math.min(a[1],t)):t;let d=r(u(t.time));const h=r(u(o.time)),p=t.value*c,f=o.value*c,g=e+(t.boundaryOffset??0)*c,y=n+(o.boundaryOffset??0)*c,m=t.sideMassBefore*c,x=o.sideMassAfter*c;let b,v,w,k;"top"===t.side?(b=g-m,v=b+p):(v=g+m,b=v-p),"top"===o.side?(w=y-x,k=w+f):(k=y+x,w=k-f);const A=l.sourceRunwayStart,S=l.minRun,M=Math.abs((w+k)/2-(b+v)/2),_=h-d,P="number"==typeof A&&Number.isFinite(A),L="number"==typeof S&&Number.isFinite(S)&&S>0;if(P&&M>1e-9&&_>0&&("auto"===S||L)){const e="source"===s?.85:"target"===s?.15:.5,o="auto"===S?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(e*e,(1-e)*(1-e))))):S;if(o>_){const e=r(u(Math.min(A,t.time)));Number.isFinite(e)&&(d=Math.min(d,Math.max(Math.min(d,e),h-o)))}}const $="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:b,sBot:v,tx:h,tTop:w,tBot:k,cp1X:$,cp2X:$}}function _i(t){return Math.max(18,11*t.length*.58)}function Pi(t){const e=1.22*_i(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function Li(t,e){const o=t.labelX-_i(t.labelText),n=e.labelX-_i(e.labelText);return e.labelX+3>=o&&t.labelX+3>=n}var $i=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function Ri(t){return t.replace($i,(t,e,o)=>`${o},${e}`)}function Ci(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function Ti(t){return{...t,pathD:Ri(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function Oi(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:l,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:p,maxLabels:f,selectionDatum:g="raw",styleRules:y,colorBy:m,valueAccessor:x,usageMode:b="static"}=t,v="vertical"===d?r:i,w="vertical"===d?i:r,k=function(t,e,o,n={}){const i=wn(n.usageMode??"static"),r=[],s=new Set;for(const e of t)s.has(e.id)&&r.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),s.add(e.id);const a=new Set,l=Array.isArray(o)&&2===o.length,c=l&&Number.isFinite(o[0])&&Number.isFinite(o[1]);l&&c&&c&&o[1]>=o[0]||r.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||r.push({kind:"invalid-node-time",id:e.id}));for(const t of e)a.has(t.id)&&r.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),a.add(t.id),s.has(t.source)||r.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),s.has(t.target)||r.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&r.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),Number.isFinite(t.value)&&t.value>0||r.push({kind:"invalid-value",id:t.id}),t.startTime>t.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):r.push({kind:"invalid-edge-time",id:t.id});return r}(e,o,n,{usageMode:b}),{fatal:A,warnings:S}=function(t){const e=[],o=[];for(const n of t)"fatal"===An(n)?e.push(n):o.push(n);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==wn(o).invalidSystemTime)return t;const n=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===n.size?t:t.map(t=>{if(!n.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}(o,k,b),_=bn().domain(n).range([0,v]);if(A.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:A,warnings:S,xScale:_};const P=function(t,e,o){const{plotH:n,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:p}=o,f=Number.isFinite(d)?Math.max(0,d):0,g=function(t,e){const o=Mn(),n=Mn();for(const e of t)o[e.id]=[],n[e.id]=[];for(const t of e)n[t.source]&&n[t.source].push(t),o[t.target]&&o[t.target].push(t);return{incoming:o,outgoing:n}}(t,e),y=function(t,e,o,n="temporal"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime||_n(t.id,e.id):(t,e)=>e.value-t.value||_n(t.id,e.id),r="temporal"===n?(t,e)=>t.startTime-e.startTime||_n(t.id,e.id):(t,e)=>e.value-t.value||_n(t.id,e.id),s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const o=new Map;for(const n of t){const t=n[e];o.has(t)||o.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=o.get(t);i.edges.push(n),i.total+=n.value,i.earliestStart=Math.min(i.earliestStart,n.startTime),i.latestEnd=Math.max(i.latestEnd,n.endTime)}const s=[...o.values()];s.sort("temporal"===n?(t,o)=>"target"===e?t.earliestStart-o.earliestStart||_n(t.partner,o.partner):t.latestEnd-o.latestEnd||_n(t.partner,o.partner):(t,e)=>e.total-t.total||_n(t.partner,e.partner));for(const t of s)t.edges.sort("target"===e?r:i);return s};for(const e of t){const t=o.outgoing[e.id],n=o.incoming[e.id];if(0===n.length)a(t,"target").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=o});else if(0===t.length)a(n,"source").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=o});else{const e=a(n,"source"),o=a(t,"target"),i=Math.max(e.length,o.length);for(let t=0;i>t;t++){const n=t%2==0?"top":"bot";if(e[t])for(const o of e[t].edges)s.get(o.id).targetSide=n;if(o[t])for(const e of o[t].edges)s.get(e.id).sourceSide=n}}}return s}(t,e,g,i);let m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,void 0,u);const x=Ai(t,e,m,g,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),b=x.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),v=new Set;for(const t of e){const e=x.slotByNode[t.source],o=x.slotByNode[t.target];if(void 0===e||void 0===o)continue;const n=y.get(t.id);e!==o?e>o?(n.sourceSide="top",n.targetSide="bot"):(n.sourceSide="bot",n.targetSide="top"):(v.add(t.id),n.sourceSide="bot",n.targetSide="bot")}for(const e of t){const t=g.outgoing[e.id],o=g.incoming[e.id],n=new Set(t.map(t=>y.get(t.id).sourceSide)),i=new Set(o.map(t=>y.get(t.id).targetSide));if(1===n.size&&o.length>0){const t=[...n][0];for(const e of o)x.slotByNode[e.source]===x.slotByNode[e.target]&&(y.get(e.id).targetSide=t)}if(1===i.size&&t.length>0){const e=[...i][0];for(const o of t)x.slotByNode[o.source]===x.slotByNode[o.target]&&(y.get(o.id).sourceSide=e)}}!function(t,e,o){const n=new Map,i=[];for(const e of t)i.push({time:e.startTime,kind:"out",edge:e}),i.push({time:e.endTime,kind:"in",edge:e});i.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||_n(t.edge.id,e.edge.id));const r=t=>{let e=n.get(t);return e||(e={top:0,bot:0},n.set(t,e)),e},s=(t,e,o)=>{const n="top"===e?"bot":"top",i=Math.min(o,t[e]);t[e]-=i;const r=o-i;r>0&&(t[n]=Math.max(0,t[n]-r))};for(const t of i){const{edge:n}=t;if("in"===t.kind){const t=e.get(n.id)?.targetSide??"bot";r(n.target)[t]+=n.value;continue}const i=r(n.source),a=e.get(n.id);let l=a.sourceSide??"bot";if(o[n.source]===o[n.target]){const t=i.top>=n.value,e=i.bot>=n.value;t!==e?l=t?"top":"bot":t||e||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,n.value)}}(e,y,x.slotByNode),function(t,e,o,n){for(const i of t){const t=e.incoming[i.id],r=e.outgoing[i.id];if(0===t.length||0===r.length)continue;const s=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const n of t)"top"===o.get(n.id).targetSide?e.inTop+=n.value:e.inBot+=n.value;for(const t of r)"top"===o.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},a=(t,e)=>{const i=s(),a="top"===t?i.outTop-i.inTop:i.outBot-i.inBot,l="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(e=>!n.has(e.id)&&o.get(e.id).sourceSide===t&&c>=e.value).sort((t,e)=>e.value-t.value||_n(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(t,g,y,v),m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,void 0,u);const w=Ai(t,e,m,g,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),k=w.effectiveSlotsHeight??w.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),A=w.slots.slice(0,-1).reduce((t,e,o)=>t+(null!=e.group&&e.group===w.slots[o+1].group?1:0),0),S=Math.max(1,w.slots.length+1-A),M=Math.min(12,Math.max(0,.35*n-A*f)/S),_=2*M+Ln(w.slots,M,f).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(n-_)/k):1,L=Number.isFinite(l)&&l>0?Math.min(P,l):P;let $=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P});const R=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||R)&&$.slots.length>1&&(ri(t,e,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:n,padding:M,valueScale:L,groupPadding:f,laneOrder:s,ribbonLane:h,domain:p,lanePlacement:c,mode:"geometry-refine"}),$=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Pn),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P})),function(t,e){const o=(t,o)=>{for(const n of t){const t=new Map;for(const i of n){const n=`${("out"===o?e.get(i.id)?.sourceSide:e.get(i.id)?.targetSide)??""}\0${"out"===o?i.startTime:i.endTime}`,r="out"===o?`${i.target}\0${i.endTime}`:`${i.source}\0${i.startTime}`,s=t.get(n);if(null!=s&&s!==r)return!0;t.set(n,r)}}return!1};return o(Object.values(t.outgoing),"out")||o(Object.values(t.incoming),"in")}(g,y)){const o=function(t,e,o,n){const i=new Map;for(const r of t){const t=e[r.source]?.localAttachments.get(r.id),s=e[r.target]?.localAttachments.get(r.id),a=o[r.source],l=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=Yn(t,a,n),u=Yn(s,l,n);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(e,m,$.centerlines,L);m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,o,u);$=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Pn),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P})}const C=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),T=[...$.slots].sort((t,e)=>(C.get(Pn(t))??1/0)-(C.get(Pn(e))??1/0)||_n(Pn(t),Pn(e))),O=Mn();T.forEach((t,e)=>{for(const o of t.occupants)O[o.id]=e});const I=Tn(t,e,m,T,O,{plotH:n,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:f}),z=ki(t,m,T,O,I.centerlines,L,f),F=Wn(Jn(O,e),ti(O,e),e,z,T,O,I.centerlines,$.laneLifetime,L,I.verticalUtilization,h,p);m=ki(t,m,$.slots,$.slotByNode,$.centerlines,L,f);const N=Wn(Jn($.slotByNode,e),ti($.slotByNode,e),e,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,p);return{nodeData:m,sides:y,valueScale:L,padding:M,compressedPadding:12>M,centerlines:$.centerlines,laneLifetime:$.laneLifetime,slots:$.slots,slotByNode:$.slotByNode,crossingsBefore:"insertion"===s?null:F.crossings,crossingsAfter:"insertion"===s?null:N.crossings,lengthBefore:"insertion"===s?null:F.weightedLength,lengthAfter:"insertion"===s?null:N.weightedLength,layoutQualityBefore:F,layoutQuality:N}}(e,M,{plotH:w,...u,ribbonLane:s,domain:n}),{centerlines:L,nodeData:$,valueScale:R}=P,C=rt(m,x),T=[],O=[],I=0===a?new Map:function(t,e,o){const n=new Set(e.map(t=>t.target)),i=new Map(t.map(t=>[t.id,t])),r=new Map;for(const t of e){if(n.has(t.source))continue;const e=r.get(t.source)??[];e.push(t),r.set(t.source,e)}const s=new Map;for(const e of t){if(!e.group)continue;const t=s.get(e.group)??[];t.push(e),s.set(e.group,t)}const a=new Set;for(const[t,e]of s){const o=e.flatMap(t=>r.get(t.id)??[]),i=new Set(o.map(t=>t.startTime));o.length>0&&1===i.size&&e.every(t=>{const e=t.xExtent?.[0],i=o[0].startTime;return!n.has(t.id)&&(r.get(t.id)?.length??0)>0&&Number.isFinite(e)&&i>e})&&a.add(t)}const l=new Map;for(const[t,e]of r){const n=i.get(t);if(n?.group&&!a.has(n.group))continue;const r=n?.xExtent?.[0],s=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),c=s[0]?.startTime-1;let u=null;for(let t=0;s.length>t;){const e=s[t].startTime;let n=t+1;for(;s.length>n&&s[n].startTime===e;)n++;for(let e=t;n>e;e++){const t=s[e],n=Number.isFinite(r)&&t.startTime>r,i=Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime;if(!n&&!i)continue;let a=o[0];n&&(a=Math.max(a,r)),i&&(a=Math.max(a,t.systemInTime)),!n&&i&&Number.isFinite(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&l.set(t.id,a)}u=e,t=n}}for(const[t,e]of s){if(!a.has(t))continue;const o=e.flatMap(t=>r.get(t.id)??[]);if(!o.every(t=>l.has(t.id))){for(const t of o)l.delete(t.id);continue}const n=Math.max(...o.map(t=>l.get(t.id)));for(const t of o)l.set(t.id,n)}return l}(e,M,n),z=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),F=new Map;for(const t of M){const e=$[t.source]?.localAttachments.get(t.id),o=$[t.target]?.localAttachments.get(t.id);e&&o&&F.set(t.id,Mi(e,L[t.source],o,L[t.target],R,_,s,n,{minRun:a,sourceRunwayStart:I.get(t.id)}))}const N=function(t,e,o,n,i,r){const s=new Map(e),a=new Map;for(const e of t){const t=r?.get(e.source),o=null==t?"node:"+e.source:"group:"+t,n=a.get(o)??new Map,i=n.get(e.startTime)??[];i.push(e),n.set(e.startTime,i),a.set(o,n)}for(const t of a.values())for(const[r,a]of t){if(!a.some(t=>o.has(t.id)))continue;const t=a.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const l=n(r),c=Math.min(...t.map(t=>t.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?l:Math.min(l,n(e))})),d=Math.min(l,Math.max(c,u));for(const t of a){const o=e.get(t.id),n=d+(o.tx-d)*("source"===i?.85:"target"===i?.15:.5);s.set(t.id,{...o,sx:d,cp1X:n,cp2X:n})}}return s}(M,F,I,_,s,z),E=function(t,e,o,n,i){const r=new Map;for(const s of t){if(!o.has(s.id))continue;const t=e.get(s.id);if(!t||t.sx>=n(s.startTime)-1e-9)continue;const a=i(t.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,N,I,_,t=>n[0]+t/v*(n[1]-n[0])),D=function(t,e,o){const n=new Map,i=new Map;for(const[t,e]of o??[]){const o=i.get(e)??[];o.push(t),i.set(e,o)}for(const r of t){const t=e.get(r.id);if(null==t||!Number.isFinite(t)||t>=r.startTime)continue;const s=o?.get(r.source),a=null==s?[r.source]:i.get(s)??[r.source];for(const e of a){const o=n.get(e)??new Map,i=o.get(r.startTime);o.set(r.startTime,null==i?t:Math.min(i,t)),n.set(e,o)}}return n}(M,E,z);e.forEach((t,e)=>{const o=$[t.id];if(!o||0===o.samples.length)return;const i=(r=o.samples,(s=D.get(t.id))&&0!==s.size?r.map(t=>{const e=s.get(t.t);return null==e?t:{...t,t:e}}):r);var r,s;const a=function(t,e,o,n,i){if(0===t.length)return null;const r=jn(t,i),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,l=t=>s(t)+r[t].botMass*o;let c=`M${n(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)c+=` L${n(r[t].t)},${a(t)}`;c+=` L${n(r[r.length-1].t)},${l(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${n(r[t].t)},${l(t)}`;return c+" Z"}(i,L[t.id],R,_,n);if(!a)return;const l=jn(i,n),u=l.find(t=>t.topMass+t.botMass>0)||l[0],h=L[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let p,f,g=c(t.id,e),m=g,x=.5;const b=t.__raw??t;if(y&&y.length>0){const t=dt(b,y,C(b));"string"==typeof t.fill?g=t.fill:null!=t.fill&&ot(t.fill)&&(f=t.fill,g=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:g),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(x=t.strokeWidth),"number"==typeof t.fillOpacity&&(p=t.fillOpacity),"number"==typeof t.opacity&&null==p&&(p=t.opacity)}const v=function(t,e,o,n,i,r){const s=o.nodeData[t];if(!s||0===s.samples.length)return[];const a=o.valueScale,l=o.centerlines[t],c=jn(s.samples,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],d=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],h=n(u.t),p=n(d.t),f=t=>n(Bn(t,i)),g=[],y=(t,e,o,n)=>`M${t},${e} L${o},${e} L${o},${n} L${t},${n} Z`;for(const o of e){if(o.source===t&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const t=s.localAttachments.get(o.id),e=r?.get(o.id)??o.startTime;if(t&&"out"===t.kind&&e>o.systemInTime){const n=f(o.systemInTime),r=f(e),s=null!=i&&i[0]>o.systemInTime,c=s?n:n-20,u=s?Math.min(r,n+20):n,d=Math.max(h,c);if(r>d){const[e,o]=Yn(t,l,a);g.push({pathD:y(d,e,r,o),x0:c,x1:u,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=s.localAttachments.get(o.id);if(t&&"in"===t.kind&&o.systemOutTime>o.endTime){const e=f(o.systemOutTime),n=f(o.endTime),i=e+20,r=Math.min(p,i);if(r>n){const[o,s]=Yn(t,l,a);g.push({pathD:y(n,o,r,s),x0:e,x1:i,from:1,to:0})}}}}return g}(t.id,M,P,_,n,E);T.push({id:t.id,pathD:a,fill:g,stroke:m,strokeWidth:x,...null!=p&&{fillOpacity:p},...f&&{hatchFill:f},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&t.xExtent?t.xExtent[0]:u.t)-4,labelY:h,labelText:t.label??t.id})});const W=new Map;e.forEach((t,e)=>W.set(t.id,e)),M.forEach(t=>{const e=N.get(t.id);if(!e)return;const o=W.get(t.source)??0,n=c(t.source,o),{pathD:i,bezier:r}=Si(e),s=t.__raw??t,a="function"==typeof l?Number(l(s)):l,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;O.push({id:t.id,pathD:i,fill:n,opacity:u,rawDatum:s,bezier:r})});const B=function(t,e,o){const n=t.map(t=>({...t})),i=new Map;for(const t of n){const o=e[t.id];if(null==o)continue;const n=i.get(o)??[];n.push(t),i.set(o,n)}const r=t=>{if(2>t.length)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,n=(t.length-1)/2;t.forEach((t,i)=>{t.labelY=Math.max(8,Math.min(o-8,e+16*(i-n)))})};for(const t of i.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],o=-1/0;for(const n of t){const t=n.labelX-_i(n.labelText);e.length>0&&t>o+3&&(r(e),e=[],o=-1/0),e.push(n),o=Math.max(o,n.labelX)}r(e)}return function(t,e){const o=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;3>t;t+=1){for(let t=0;o.length>t;t+=1){let e=8;for(let n=0;t>n;n+=1)Li(o[t],o[n])&&(e=Math.max(e,o[n].labelY+16));o[t].labelY=Math.max(o[t].labelY,e)}for(let t=o.length-1;t>=0;t-=1){let n=e-8;for(let e=t+1;o.length>e;e+=1)Li(o[t],o[e])&&(n=Math.min(n,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,n)}}}(n,o),n}(T,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ri(t.pathD),gradientStubs:t.gradientStubs?.map(Ti),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,d)),j="vertical"===d?function(t,e,o){const n=t.map(t=>({...t}));for(const t of n){const o=1.22*_i(t.labelText)+4;t.labelX=e-4>o?Math.max(o/2+2,Math.min(e-o/2-2,t.labelX)):e/2}const i=[],r=[...n].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of r){const e=i[i.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?i.push([t]):e.push(t)}for(const t of i){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],n=new Map;for(const o of t){const[t,i]=Pi(o);let r=e.findIndex(e=>t>e+8);-1===r&&(r=e.length),e[r]=i,n.set(o,r)}const i=t.reduce((t,e)=>t+e.labelY,0)/t.length,r=14*e.length+8>i;for(const e of t){const t=n.get(e)??0;e.labelY=r?Math.min(o-8,12+14*t):Math.max(8,i-14*t)}}return n}(B,i,r):B,Y=new Map;if(null!=p)for(const t of e){const e=t.__raw??t,o="function"==typeof p?p(e):Number(e[p]);Number.isFinite(o)&&Y.set(t.id,o)}const X=function(t,e,o,n,i={}){if(!1===n)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===n)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(t.length,Math.floor(Math.max(1,e*o)/14e3)));Number.isFinite(i.maxLabels)&&i.maxLabels>=0&&(r=Math.min(r,Math.floor(i.maxLabels)));const s=t.map((t,e)=>{const o=i.priorityById?.get(t.id),n=Math.abs(t.labelY);return{band:t,index:e,score:null!=o&&Number.isFinite(o)?1e6*o+_i(t.labelText):_i(t.labelText)+.01*n}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),a=new Set(s.slice(0,r).map(t=>t.band.id));return t.map(t=>a.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(j,i,r,h,{...Y.size>0&&{priorityById:Y},...null!=f&&{maxLabels:f}});return{layout:P,layoutConfig:{bands:X,ribbons:O.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ri(t.pathD),bezier:Ci(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:S,xScale:_}}import{Fragment as Ii,jsx as zi,jsxs as Fi}from"react/jsx-runtime";var Ni="var(--semiotic-grid, #94a3b8)",Ei="var(--semiotic-text-secondary, #475569)",Di="var(--semiotic-text-secondary, #94a3b8)",Wi=.22;function Bi(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var ji=t=>{const{bands:e=[],ribbons:o=[],showLabels:n=!0,selectionDatum:i="raw"}=t.config,r=t.selection??null,s=[];for(const t of o){const e={__kind:"ribbon",data:t.rawDatum,id:t.id},o=!Bi(e,r,i);s.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:o?Math.min(t.opacity,Wi):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!Bi({__kind:"band",data:t.rawDatum,id:t.id},r,i);for(let o=0;t.gradientStubs.length>o;o++){const n=t.gradientStubs[o];s.push({type:"bezier",pathD:n.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:e?Wi:t.fillOpacity??.86,stroke:"none"},_gradient:{x0:n.x0,x1:n.x1,...null!=n.y0&&{y0:n.y0},...null!=n.y1&&{y1:n.y1},from:n.from,to:n.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${o}`}})}}for(const t of e){const e=!(!t.gradientStubs||0>=t.gradientStubs.length),o={__kind:"band",data:t.rawDatum,id:t.id},n=!Bi(o,r,i);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:n?Wi:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...n&&e?{opacity:Wi}:{}},datum:o})}const a=n?e.flatMap(t=>{const e=t.labelDeferred&&t.labelFullText?.trim(),o=t.labelText.trim().length>0,n=e&&r?.isActive&&Bi({__kind:"band",data:t.rawDatum,id:t.id},r,i),s=o?t.labelText:n?t.labelFullText:"";return s.trim()?[{x:t.labelX,y:t.labelY,text:s,anchor:t.labelAnchor??"end",baseline:t.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:s,labels:a}};function Yi(t,e){if(!t)return[];const o=[],n=t=>{o.push(t);const i="function"==typeof e?e(t):t[e];i&&Array.isArray(i)&&i.forEach(n)};return n(t),o}function Xi(t,e,o,n){if(t&&t.length>0)return t;const i=new Set;return e.forEach(t=>{const e="function"==typeof o?o(t):t[o],r="function"==typeof n?n(t):t[n];i.add(e),i.add(r)}),Array.from(i).map(t=>({id:t}))}function Gi(t,e,o={}){return ae(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var Vi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{if(!(e||Array.isArray(i.styleRules)&&i.styleRules.length>0||n.nodeStyle||i.nodeStyle||se(fe(i))))return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:o,...n};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:Xi([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=ye(n.theme).colors.categorical,l=Qt(o,a),c="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?ie(u,c,o??n.colorScheme??a):void 0,h=new Map,p=i.nodeIdAccessor||i.nodeIDAccessor||"id",f=(t,o)=>{const n=t?.data||t;let r;if(e)r=oe(n,e,d);else{const e=(t.id??n?.[p]??"")+"";h.has(e)||h.set(e,h.size);const i=t.index??o??h.get(e);r=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=pt(i.styleRules,e,i.valueAccessor);return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:o,nodeStyle:ae(i.nodeStyle||(g?(t,e)=>({...f(t,e),...g(t,e)}):f),fe(i)),...n}}},Hi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=function(t){if(void 0!==t.edgeStyle)return t.edgeStyle;const{edgeWidth:e,edgeColor:o,edgeOpacity:n}=t,i=t.strokeWidth??1;return void 0!==e||void 0!==o||void 0!==n||void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity?r=>{const s=r?.data||r;let a=i;if("number"==typeof e)a=e;else if("function"==typeof e)a=e(s);else if("string"==typeof e){const t=s?.[e],o="number"==typeof t?t:Number(t);a=Number.isFinite(o)&&o>0?o:i}return{stroke:o??t.stroke??"#999",strokeWidth:a,opacity:n??t.opacity??.6}}:void 0}(i),s=ye(n.theme).colors.categorical,a=new Map,l=i.nodeStyle??(t=>({fill:e?oe(t?.data||t,e,void 0):uo(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=pt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=ae(c?(t,e)=>({...l(t),...c(t,e)}):l,{stroke:i.nodeStroke??i.stroke,strokeWidth:i.nodeStrokeWidth??i.strokeWidth,opacity:i.opacity});return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:e,colorScheme:o,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:u,edgeStyle:r,...n}}},qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrCirclePackColorBy:l(t)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"circlepack",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:i.showLabels??n.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrCirclePackColorBy:l(n)},"__ssrCirclePackColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,fe(i))}}},Ui={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=t??i.data,s=i.childrenAccessor||"children",a=i.nodeIdAccessor||i.nodeIDAccessor||"name",l=ye(n.theme).colors.categorical,c=o??n.colorScheme??l,u=Qt(c,l),d=Yi(r,s),h="__ssrOrbitColorBy",p="function"==typeof e?e:null,f=e?ie(p?d.map(t=>({[h]:p(t)})):d,p?h:e,c):void 0;return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:c,colorByDepth:i.colorByDepth??!1,nodeSize:i.nodeRadius??6,nodeLabel:i.showLabels?a:void 0,showLabels:i.showLabels??!1,orbitMode:i.orbitMode??"flat",orbitSize:i.orbitSize??2.95,orbitSpeed:i.speed??.25,orbitRevolution:i.revolution,orbitRevolutionStyle:i.revolutionStyle,orbitEccentricity:i.eccentricity??1,orbitShowRings:i.showRings??!0,orbitAnimated:!1,nodeStyle:ae(t=>{const o=t.data||t,n=Number(t.depth??0);return{fill:i.colorByDepth?0===n?u[0]:te[n%te.length]:e?p?oe({[h]:p(o)},h,f):oe(o,e,f):u[0],stroke:"#fff",strokeWidth:1,opacity:0===n?1:.85}},fe(i)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...n}}},Ki={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,n,i)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,p=i.systemOutTimeAccessor,f=i.xExtentAccessor||"xExtent",g=i.groupBy,y=i.edgeIdAccessor||"id",m=(t,e)=>"function"==typeof t?t(e):e[t],x=Array.isArray(i.edges)?i.edges:[],b=Array.isArray(i.nodes)?i.nodes:[],v=b.length>0?b:Xi([],x,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],k=v.map(t=>{const e=m(c,t)+"",o=m(f,t),n=i.nodeLabel?m(i.nodeLabel,t):e,s={id:e,label:null==n?e:n+"",__raw:t},a=g?m(g,t):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(s.xExtent=[t,e])}return s}),A=x.map((t,e)=>{const o=m(y,t),n={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(l,t)),startTime:r(m(u,t)),endTime:r(m(d,t)),__raw:t};if(h){const e=r(m(h,t));Number.isFinite(e)&&(n.systemInTime=e)}if(p){const e=r(m(p,t));Number.isFinite(e)&&(n.systemOutTime=e)}return n}),[S,M]=n.size??[600,400],_=n.margin,P="vertical"===i.orientation?"vertical":"horizontal",L=function(t,e,o,n="horizontal"){return"vertical"===n?{top:t?38:e?28:16,right:24,bottom:24,left:o?72:24}:{top:t?30:e?24:8,right:80,bottom:o?28:8,left:80}}(!!n.title,!!i.showQualityReadout,Array.isArray(i.axisTicks)&&i.axisTicks.length>0,P),$={...L,..._},R=(n.showLegend??!!e)&&!!e,C=n.legendPosition??"right";R&&("right"===C?$.right=Math.max($.right,140):"left"===C?$.left=Math.max($.left,140):"top"===C?$.top=Math.max($.top,50):"bottom"===C&&($.bottom=Math.max($.bottom,80)));const T=$,O=S-T.left-T.right,I=M-T.top-T.bottom,z=Qt(o,ye(n.theme).colors.categorical,B),F="function"==typeof e?e:null,N=F?v.map(t=>({_cat:F(t)})):v,E=F?"_cat":"string"==typeof e?e:void 0,D=o??[...z],W=E?ie(N,E,D):null,j=new Map;for(const t of k)j.set(t.id,t.__raw);const Y=(t,o)=>{if(e&&j.has(t)){const o=j.get(t);return F?oe({_cat:F(o)},"_cat",W??void 0):oe(o,"string"==typeof e?e:"id",W??void 0)}return z[o%z.length]},X=Ye(R&&e?(()=>{const t=new Map;v.forEach((o,n)=>{const i=m(e,o),r=null==i?"":i+"";r&&!t.has(r)&&t.set(r,{label:r,color:Y(m(c,o)+"",n)})});const o=Array.from(t.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:t=>{const e=t.color||"#333";return{fill:e,stroke:e}}}]}:void 0})():void 0,n.legend),G=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:V,layoutConfig:H,issues:q,xScale:U}=Oi({nodes:k,edges:A,domain:w,plotW:O,plotH:I,orientation:P,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:Y,showLabels:G,styleRules:i.styleRules,colorBy:e,valueAccessor:l,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half",maxValueScale:"number"==typeof i.maxValueScale?i.maxValueScale:void 0,lanePlacement:i.lanePlacement||"stack",nodeSizing:i.nodeSizing||"temporal",groupPadding:"number"==typeof i.groupPadding?i.groupPadding:0}});if(q.length>0){const t=q.map(Sn).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const K=V?function(t){const e=t.layout,o=t.nodes,n=t.orientation,i=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,l=t.showQualityReadout??!1,c=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,p=t.toTime,f=t.xScale,{centerlines:g,laneLifetime:y,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:A}=e;let S=null,M=null;for(const t of o){const e=y[t.id];if(!e||null===e.start||null===e.end)continue;const o=f(e.start),n=f(e.end);(null===S||S>o)&&(S=o),(null===M||n>M)&&(M=n)}const _=t=>Math.max(0,Math.min(s,t)),P=_(S??0),L=Math.max(P,_(M??s)),$=a.map((t,e)=>({tick:t,index:e,coordinate:f(p(t.date))})).filter(({coordinate:t})=>t>=P-.5&&L+.5>=t),R=null!==(w??null)&&null!=k&&null!=A,C=l&&(R||u.length>0)?Fi("g",{fill:Di,fontSize:10,textAnchor:"end",children:[R&&Fi(Ii,{children:[Fi("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(A.pixelLength)]}),Fi("text",{x:i,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",A.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*A.verticalUtilization),"%"]})]}),u.map((t,e)=>Fi("text",{x:i,y:R?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,T=b?zi("text",{x:i,y:"vertical"===n?-3:2,fontSize:10,fill:Di,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,O=(t,e)=>h?h(t,e):Ni;return Fi("g","vertical"===n?{children:[C,T,$.map(({index:t,coordinate:e})=>zi("line",{x1:0,y1:e,x2:i,y2:e,stroke:Ni,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[t.id];if(!o||null===o.start)return null;const n=m[t.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=f(o.start),a=f(o.end),l=O(t.id,e);return Fi("g",{children:[zi("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),zi("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),zi("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),zi("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:Ni}),$.map(({tick:t,index:e,coordinate:o})=>{const n=p(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return Fi("g",{transform:`translate(-4,${o})`,children:[zi("line",{x2:-6,stroke:Ni}),zi("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Ei,children:i})]},e)})]}:{children:[C,T,$.map(({index:t,coordinate:e})=>zi("line",{x1:e,y1:0,x2:e,y2:r,stroke:Ni,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[t.id];if(!o||null===o.start)return null;const n=m[t.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=f(o.start),a=f(o.end),l=O(t.id,e);return Fi("g",{children:[zi("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),zi("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),zi("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),zi("line",{x1:P,y1:r+4,x2:L,y2:r+4,stroke:Ni}),$.map(({tick:t,index:e,coordinate:o})=>{const n=p(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return Fi("g",{transform:`translate(${o},${r+4})`,children:[zi("line",{y2:6,stroke:Ni}),zi("text",{y:20,textAnchor:"middle",fontSize:11,fill:Ei,children:i})]},e)})]})}({layout:V,nodes:k,orientation:P,plotW:O,plotH:I,timelineExtent:"vertical"===P?I:O,axisTicks:Array.isArray(i.axisTicks)?i.axisTicks.map(t=>({date:t.date,label:t.label})):[],showQualityReadout:!!i.showQualityReadout,showLaneRails:!!i.showLaneRails,timeFormat:"function"==typeof i.timeFormat?t=>i.timeFormat(t):void 0,colorOf:Y,toTime:t=>r(t),xScale:t=>Number(U(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:ji,layoutConfig:H,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:e,colorScheme:o,...K&&{backgroundGraphics:K},...n,showLegend:R,...X&&{legend:X,legendPosition:C},__legendIncludesAutomatic:!0,margin:T}}},Zi={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:Xi([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=ye(n.theme).colors.categorical,a=new Map,l="string"==typeof e?e:"__ssrSankeyColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?ie(c,l,o??n.colorScheme??s):void 0,d=t=>({fill:e?oe(t?.data||t,e,u):uo(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=pt(i.styleRules,e,i.valueAccessor),p=h?(t,e)=>({...d(t),...h(t,e)}):d,f=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:n,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof t)a.fill=t(s);else if("source"===t){const t="object"==typeof s.source?s.source:null;e&&t?a.fill=oe(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=oe(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:p,edgeOpacity:i.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,valueAccessor:i.valueAccessor,orientation:i.orientation,nodeAlign:i.nodeAlign,nodeWidth:i.nodeWidth,nodePaddingRatio:i.nodePaddingRatio,showLabels:i.showLabels,nodeLabel:i.nodeLabel,colorBy:e,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:ae(i.nodeStyle||p,fe(i)),edgeStyle:ae(i.edgeStyle||f,fe(i)),colorScheme:o,...n}}},Qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreeColorBy:l(t)})):a,u=l?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"cluster"===i.layout?"cluster":"tree",data:t,childrenAccessor:i.childrenAccessor,colorBy:e,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:!1!==i.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrTreeColorBy:l(n)},"__ssrTreeColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,fe(i))}}},Ji={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreemapColorBy:l(t)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,p=i.labelMode,f=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,g=void 0!==f?f:!h||"parent"!==p&&"all"!==p?void 0:18,y=n.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:p,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=g&&{paddingTop:g},colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrTreemapColorBy:l(n)},"__ssrTreemapColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},y,fe(i))}}},tr={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as er}from"d3-scale";function or(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var nr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="string"==typeof o?o:"blues",s=function(t,e,o){if(!Array.isArray(t))return;const n=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let i=1/0,r=-1/0;for(const e of t){const t=n(e);null!=t&&isFinite(t)&&(i>t&&(i=t),t>r&&(r=t))}const s=[Number.isFinite(i)?i:0,Number.isFinite(r)?r:1],a=er(h(o)).domain(s);return{domain:s,colorScale:t=>a(t),valueAccessor:n}}(i.areas,i.valueAccessor,r),a=i.areaStyle??function(t,e){if(t)return o=>{const n=t.valueAccessor(o);return{fill:null!=n&&isFinite(n)?t.colorScale(n):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:e}}}(s,i.areaOpacity??1),l=i.styleRules?Q(a,i.styleRules,t=>{return{value:(e=t,"function"==typeof i.valueAccessor?i.valueAccessor(e):null!=i.valueAccessor?e?.properties?.[i.valueAccessor]??e?.[i.valueAccessor]:void 0)};var e},or):a,c=!1!==n.showLegend&&s?{gradient:{colorFn:s.colorScale,domain:s.domain,label:"string"==typeof i.valueAccessor?i.valueAccessor:"value"}}:void 0;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:l,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n,...void 0===n.legend&&c?{legend:c}:{}}}},ir={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=t||i.points,s=i.pointStyle??function(t,e,o,n){const i=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",n="string"==typeof e?i:i.map(t=>({...t,__geoColorBy:e(t)}));r=ie(n,t,o)}if(n.sizeBy){const t=i.map("function"==typeof n.sizeBy?n.sizeBy:t=>t?.[n.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=St(t))}return t=>({fill:e&&r?oe(t,e,r):Zt,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?re(t,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}(r,e,o,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?Q(s,i.styleRules,rt(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||tr,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},rr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=(Array.isArray(t)?t:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:t=>t[l],d="function"==typeof c?c:t=>t[c],h=(i.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),p=new Map;for(const t of h)p.set(t[s]+"",t);const f=i.edgeColorBy??e,g="function"==typeof f,y=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=p.get(t.source+""),o=p.get(t.target+"");return e&&o?{...t,coordinates:[{x:e.x,y:e.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=f?g?ie(y.map(t=>({[m]:f(t)})),m,o||"category10"):ie(y,f,o||"category10"):null,b=t=>f&&x?oe(t,f,x):"#007bff";let v=1/0,w=-1/0;for(const t of y){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[A,S]=i.edgeWidthRange??[1,8],M=S-A,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:y,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||tr,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:o,lineStyle:t=>{const e=Number(t?.[a]),o=Number.isFinite(e)?e:v,n=A+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:b(t),strokeWidth:n,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...n}}};import*as sr from"react";function ar(t){const[e,o]=t,n=160>e||116>o,i=n?Math.min(12,Math.max(2,.08*e)):32,r=n?Math.min(8,Math.max(2,.12*o)):24,s=n?r:34;return{width:e,height:o,plot:{x:i,y:r,width:Math.max(1,e-2*i),height:Math.max(1,o-r-s)}}}function lr(t){const e=(t??"")+"";if(!e)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return o[n%o.length]}function cr(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?st(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,l={fill:null==a?e:lr(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,dt(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}function ur(t,e,o,n){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:o},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...n}}}function dr(t,e,o){return"function"==typeof o?o(t,e):t[o]}function hr(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:null}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:null}function pr(t,e,o){return Math.max(e,Math.min(o,t))}function fr(t,e){const o=hr(t);return null!=o&&o>0?o:e}function gr(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function yr(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}import{scaleLinear as mr}from"d3-scale";import{scaleLinear as xr}from"d3-scale";function br(t){const{count:e,idPrefix:o,wallThickness:n,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const l=Math.min(r-1,a?.(e)??s),c=Math.max(1,r-l);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:i(e),y:l+c/2,width:n,height:c}}})}function vr(t,e,o){const n=t.width/Math.max(1,e),i=Math.max(2,2*o),r=Math.min(.7*n,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:n,tubeWidth:r,ballDiameter:i,perRow:s,centerX:e=>t.x+(e+.5)*n,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*i}}import{scaleLinear as wr}from"d3-scale";function kr(t){if(Array.isArray(t)&&t.length>=2){const e=hr(t[0]),o=hr(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=hr(e.x),n=hr(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Ar(t){return Array.isArray(t)?t.map(kr).filter(t=>null!=t):[]}function Sr(t,e,o){return"normalized"===o?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:pr(t.x,e.plot.x,e.plot.x+e.plot.width),y:pr(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Mr(t){let e=0;for(let o=1;t.length>o;o+=1)e+=Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y);return e}function _r(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=pr(e,0,1)*Mr(t);let n=0;for(let e=1;t.length>e;e+=1){const i=t[e-1],r=t[e],s=Math.hypot(r.x-i.x,r.y-i.y);if(s>0){if(n+s>=o){const t=(o-n)/s;return{x:i.x+(r.x-i.x)*t,y:i.y+(r.y-i.y)*t}}n+=s}}return{...t[t.length-1]}}function Pr(t,e){const o=_r(t,Math.max(0,e-.02)),n=_r(t,Math.min(1,e+.02)),i=n.x-o.x,r=n.y-o.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function Lr(t,e=12){return"number"==typeof t?{x:t,y:0}:t&&"object"==typeof t?{x:Number.isFinite(t.x)?Number(t.x):e,y:Number.isFinite(t.y)?Number(t.y):0}:{x:e,y:0}}import{scaleLinear as $r}from"d3-scale";function Rr(t,e,o){return Qt(t,e,o)}function Cr(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&ne(o,t)||"#4e79a7":e=>{if(o){const t=ne(o,e);if(t)return t}let n=0;for(let t=0;e.length>t;t++)n=31*n+e.charCodeAt(t)|0;return t[Math.abs(n)%t.length]??"#4e79a7"}}function Tr(t,e){const o=e.config??{},n=(e.sensors??[]).map(t=>({...t,sensor:!0})),i=[...e.colliders??[],...n],r=[...t.colliders??[],...o.colliders??[],...i];return{...t,...o,observation:{...t.observation,...o.observation},...r.length>0&&{colliders:r}}}function Or(t){const e=Dr(t);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:e.left,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:t.width-e.rightInset,y2:e.top,thickness:e.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:t.floorY,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:t.width-e.rightInset,y1:e.top,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}}]}function Ir(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function zr(t){return`gauntlet:${t}:core`}function Fr(t,e){return`gauntlet:${t}:positive:${e}`}function Nr(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var Er={left:28,top:76,rightInset:30,thickness:8};function Dr(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return Er;const o=Math.max(1,Math.min(t.width,e)),n=Math.max(2,.04*t.width);return{left:n,top:Math.max(2,.08*e),rightInset:n,thickness:Math.max(1,Math.min(4,.04*o))}}function Wr(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Br(t,e,o,n){const i=Dr(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,l=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:l(t,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:l(e,s,a)}}function jr(t,e,o=1){const n=[...t].sort((t,e)=>t.localeCompare(e)),i=Math.max(0,n.indexOf(e));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*o}}function Yr(t,e,o){const n=t.activePositiveIds.reduce((t,o)=>t+(e.get(o)?.value??1),0),i=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(o.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*n-8*r-1.2*t.delay-5*i))}function Xr(t){const e=function(t,e,o){const[n,i]=t,r=220>n||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,l=(e??[]).filter(t=>!1!==t.enabled),c=Math.max(1,l.length),u=.22*n,d=c>1?(.78*n-u)/(c-1):0,h=r?Math.max(Math.round(.12*n),.08*n+6):Math.max(Math.round(.14*n),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*i)):o),floorY:a,gates:l.map((t,e)=>({...t,id:t.id,x:t.x??Math.round(u+e*d),width:t.width??Math.max(r?8:54,Math.round(.07*n))})),graveyardX:Math.round(n*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(n*(r?.82:.92)),startX:h,width:n}}(t.size??[900,520],t.gates,t.crashOffset??30),o=t.positiveProperties??[],n=new Map(o.map(t=>[t.id,t])),i=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,o,n,i){const r=Ir(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...Ir(t,e,o.positiveAccessor,s)],l=[...Ir(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ir(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ir(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:Ir(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??Yr(a,n,i)}}),a=s.flatMap((o,r)=>{const s=function(t,e,o,n){const i=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(o),r=n?.(t,e,o)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(o,r,e,t.projectPlacement);return function(t,e,o,n,i,r,s){const a=Wr(o),l=Math.max(3,28*a),c=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??c,p=d.y??u,f={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},g=[{...d,id:zr(t.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??t.startedAt,datum:f}],y=Br(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,o);g[0].x=y.x,g[0].y=y.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=jr(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),l=Br(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,o);g.push({id:Fr(t.id,e),x:l.x,y:l.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:n.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:n,sourceDatum:t.datum},springs:!1===n.spring?[]:[{target:{type:"body",bodyId:zr(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...n.spring??{}}]})}return t.negativeIds.forEach((e,n)=>{const i=r.get(e);i&&g.push(function(t,e,o,n,i,r,s){const a=Wr(r),l=e.radius??Math.max(2,7.2*a),c=Br(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,l,r);return{id:Nr(t.id,e.id,o),x:c.x,y:c.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:zr(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,y.x,y.y,o,d.spawnAt??t.startedAt))}),g}(o,r,e,s,n,i,t.coreBody)});return{layout:e,states:s,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:Or(e)}}}function Gr(t=[]){const e=Object.create(null);for(const[o,n]of t)e[o]=n;return e}function Vr(...t){const e=Gr();for(const o of t)for(const[t,n]of Object.entries(o??{}))e[t]=n;return e}function Hr(t){return Vr(t)}function qr(t){return t.map(t=>({...t,sourceIds:t.sourceIds?[...t.sourceIds]:void 0,productIds:t.productIds?[...t.productIds]:void 0,relationIds:t.relationIds?[...t.relationIds]:void 0,outletIds:t.outletIds?[...t.outletIds]:void 0}))}function Ur(t){const e=Gr(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:Hr(e.initialMetrics),metrics:Hr(e.metrics),productIds:[...e.productIds],history:qr(e.history)}])),o=Gr(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:Hr(e.metrics),sourceIds:[...e.sourceIds],history:qr(e.history)}])),n=Gr(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?Hr(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:Hr(t.input.metrics)},metrics:Hr(t.metrics),loss:{amount:t.loss.amount,metrics:Hr(t.loss.metrics)},history:qr(t.history)}}var Kr=1e-9;function Zr(t,e){return e>t?-1:t>e?1:0}function Qr(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Jr(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(Zr)}function ts(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[Qr("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function es(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function os(t,e,o="selector"){const n=[],i=Object.values(t.components),r=new Set(i.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&n.push(Qr("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,o+".ids",s)),void 0===e.count||Number.isInteger(e.count)&&e.count>=0||n.push(Qr("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),n.some(t=>"error"===t.severity))return{ids:[],diagnostics:n};const a=e.ids?new Set(e.ids):null,l=e.categories?new Set(e.categories):null,c=e.statuses?new Set(e.statuses):null,u=e.outletIds?new Set(e.outletIds):null;let d=i.filter(t=>!a||a.has(t.id)).filter(t=>!l||l.has(t.category)).filter(t=>!c||c.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Zr);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(Qr("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function ns(t,e,o={}){return{eventId:t.event.id,effectType:e.type,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,label:t.event.label,summary:t.event.summary,...o}}function is(t,e){const o={...e,eventId:t.event.id};t.materializations.push(o),t.observations.push({...o,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt})}function rs(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(Qr("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function ss(t,e,o){const n=Jr(e);e.length||t.diagnostics.push(Qr("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(Qr("error","duplicate-source",`Source ids may appear only once: ${n.join(", ")}.`,o,n));const i=e.filter(e=>!t.state.components[e]);i.length&&t.diagnostics.push(Qr("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(Qr("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,o,r));const s=e.filter(e=>"consumed"===t.state.components[e]?.status&&!r.includes(e));return s.length&&t.diagnostics.push(Qr("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,o,s)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}function as(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+Kr)&&t.diagnostics.push(Qr("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...ts(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+Kr)&&t.diagnostics.push(Qr("error","invalid-metric-loss",`Metric loss "${e}" must be non-negative and no greater than its sources.`,`${i}.metrics.${e}`));return!t.diagnostics.some(t=>"error"===t.severity)}function ls(t,e,o,n,i,r,s){return{id:t.id,label:t.label??t.id,description:t.description,category:t.category??"product",color:t.color,order:t.order,declaredAmount:t.amount,amount:r&&void 0!==t.amount?t.amount:o,metrics:r&&t.metrics?Vr(n,t.metrics):Hr(n),status:r?"complete":"forming",sourceIds:[...e],outletId:r?t.outletId??(i.outletIds.has("product")?"product":void 0):void 0,createdByEventId:i.event.id,createdAt:i.context.appliedAt,completedByEventId:r?i.event.id:void 0,completedAt:r?i.context.appliedAt:void 0,history:[s]}}function cs(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>Kr&&t.diagnostics.push(Qr("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function us(t,e,o){const n=`events.${t.event.id}.effects.${o}`,i=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(Qr("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...ts(e.metricsDelta,n+".metricsDelta")),rs(t,e.outletId,n+".outletId");const o=os(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(Qr("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=ns(t,e,{sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of o.ids){const o=i.components[t];o.status=e.state,o.outletId=e.outletId,o.reason=e.reason,e.metricsDelta&&es(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&is(t,{type:"retarget-component",sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0}))}if("set-relation"===e.type){const{relation:o}=e;o.id&&!i.relations[o.id]||t.diagnostics.push(Qr("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,n+".relation.id",[o.id]));const r=function(t,e,o){const n=Jr(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(Qr("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(Qr("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(Qr("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,o.sourceIds,n+".relation.sourceIds");if(t.diagnostics.push(...ts(o.metrics,n+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;i.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?Hr(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=ns(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void is(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Jr(e.relationIds),r=e.relationIds.filter(t=>!i.relations[t]),s=e.relationIds.filter(t=>"resolved"===i.relations[t]?.status);if(o.length&&t.diagnostics.push(Qr("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(Qr("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(Qr("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,n+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const o of e.relationIds){const n=i.relations[o];n.status="resolved",n.resolution=e.resolution,n.resolvedByEventId=t.event.id,n.resolvedAt=t.context.appliedAt,n.reason=e.reason}const a=ns(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void is(t,{type:"resolve-relation",relationIds:[...e.relationIds]})}if("combine"===e.type||"contribute"===e.type){const o=t.productDefinitions.get(e.productId);o||t.diagnostics.push(Qr("error","unknown-product",`Product "${e.productId}" has no declared mold.`,n+".productId",[e.productId]));const r=i.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(Qr("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(Qr("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=ss(t,e.sourceIds,n+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,l=function(t,e,o,n){if(!e?.length)return[];const i=Jr(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),l=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(Qr("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(Qr("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(Qr("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),l.length&&t.diagnostics.push(Qr("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,n,l)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,n+".basisRelationIds");if(!s||!l||!o||t.diagnostics.some(t=>"error"===t.severity))return;const c=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e=Gr();for(const o of t)es(e,o.metrics);return e}(s);if(!as(t,c,u,e.loss,n+".loss"))return;const d=c-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[n,i]of Object.entries(o?.metrics??{}))e[n]=Number(e[n]??0)-i,t.state.loss.metrics[n]=Number(t.state.loss.metrics[n]??0)+i}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,p=ns(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let f;if("combine"===e.type){if(h&&cs(t,o,d,n+".productId"),f=ls(o,e.sourceIds,d,u,t,h,p),h&&!rs(t,f.outletId,n+".productId"))return;i.products[e.productId]=f}else f=r,f.sourceIds.push(...e.sourceIds),f.amount+=d,es(f.metrics,u),f.history.push(p);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(p);return i.history.push(p),function(t,e){if(e.length){for(const o of e)o.status="resolved",o.resolution="combined",o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt;is(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,l),is(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:f.outletId?[f.outletId]:void 0}),void(h&&is(t,{type:"complete-product",sourceIds:[...f.sourceIds],productIds:[f.id],outletIds:f.outletId?[f.outletId]:void 0}))}if("complete-product"===e.type){const o=i.products[e.productId];return o?void function(t,e,o,n,i,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!rs(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(Qr("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(cs(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=Vr(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=n,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const l=ns(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(l),t.state.history.push(l),is(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,o,e.outletId,e.reason,e,n):void t.diagnostics.push(Qr("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=ss(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(Qr("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=Jr(r);s.length&&t.diagnostics.push(Qr("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),l=r.filter((t,e)=>!a[e]),c=r.filter(t=>i.products[t]);l.length&&t.diagnostics.push(Qr("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,n+".products",l)),c.length&&t.diagnostics.push(Qr("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,n+".products",c));for(const[o,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(Qr("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...ts(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!as(t,u.amount,u.metrics,e.loss,n+".loss"))return;const d=u.amount-(e.loss?.amount??0),h=e.products.map((t,e)=>t.amount??a[e]?.amount),p=h.filter(t=>void 0!==t).length;if(0!==p&&p!==h.length)return void t.diagnostics.push(Qr("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const f=p?h:e.products.map(()=>d/e.products.length),g=f.reduce((t,e)=>t+e,0);if(Math.abs(g-d)>Kr)return void t.diagnostics.push(Qr("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,n+".products"));const y=Hr(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))y[t]=Number(y[t]??0)-o;const m=ns(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],l=d>Kr?f[r]/d:1/e.products.length,c=Gr(Object.entries(y).map(([t,e])=>[t,e*l])),h=o.metrics??s.metrics??c,p=ls({...s,amount:f[r],metrics:h},[u.id],f[r],Hr(h),t,!0,m);rs(t,p.outletId,`${n}.products.${r}.productId`)&&(i.products[p.id]=p)}),t.diagnostics.some(t=>"error"===t.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),i.loss.amount+=e.loss?.amount??0;for(const[t,o]of Object.entries(e.loss?.metrics??{}))i.loss.metrics[t]=Number(i.loss.metrics[t]??0)+o;i.history.push(m),is(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)is(t,{type:"complete-product",sourceIds:[u.id],productIds:[e],outletIds:i.products[e].outletId?[i.products[e].outletId]:void 0});return}if("eject"===e.type){rs(t,e.outletId,n+".outletId");const o=os(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(Qr("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=ns(t,e,{sourceIds:o.ids,outletIds:[e.outletId]});for(const t of o.ids){const o=i.components[t];o.status=e.state??"ejected",o.outletId=e.outletId,o.reason=e.reason,o.history.push(s)}return i.history.push(s),void(o.ids.length&&is(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...ts(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)es(i.metrics,e.metricsDelta);else if("components"in e.target){const r=os(i,e.target.components,n+".target.components");if(t.diagnostics.push(...r.diagnostics),t.diagnostics.some(t=>"error"===t.severity))return;o=r.ids;for(const t of r.ids)es(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Jr(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(Qr("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(Qr("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,n+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)es(i.products[t].metrics,e.metricsDelta)}return void i.history.push(ns(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(ns(t,e)),t.observations.push({type:"crucible-outcome",eventId:t.event.id,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,outcome:e.outcome})):t.diagnostics.push(Qr("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function ds(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[Qr("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=Ur(t),i={state:n,event:e,context:o,productDefinitions:new Map(o.products.map(t=>[t.id,t])),outletIds:new Set(o.outlets.map(t=>t.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,n]of e.effects.entries())if(us(i,n,o),i.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:i.diagnostics};return n.elapsed=Math.max(n.elapsed,o.appliedAt),n.phaseId=o.phaseId,n.eventsApplied.push(e.id),i.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:n,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var hs=[900,520],ps=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],fs=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),gs=1e-9;function ys(t,e){return e>t?-1:t>e?1:0}function ms(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function xs(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(ys)}function bs(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function vs(t,e,o,n,i,r){if(!o)return n;try{return("function"==typeof o?o(t,e):t[o])??n}catch(t){return i.push(ms("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function ws(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(ms("error","invalid-metrics","Metrics must be a numeric object.",o)),Gr();const n=Gr();for(const[i,r]of Object.entries(t)){const t=bs(r);null!=t?n[i]=t:e.push(ms("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function ks(t){return t.map((t,e)=>({outlet:t,index:e})).sort((t,e)=>(t.outlet.order??t.index)-(e.outlet.order??e.index)||t.index-e.index).map(({outlet:t})=>({...t}))}function As(t){const{id:e,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=t,u=function(t,e,o){const n=o.map(([o,n])=>[Math.max(t,Math.min(o,n)),Math.min(e,Math.max(o,n))]).filter(([t,e])=>e>t+gs).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+gs&&i.push([r,t]),r=Math.max(r,e);return e>r+gs&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:l,restitution:c,shape:"horizontal"===o?{type:"segment",x1:t,y1:n,x2:i,y2:n,thickness:a}:{type:"segment",x1:n,y1:t,x2:n,y2:i,thickness:a}}))}function Ss(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function Ms(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?Ss(t):1}function _s(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:Ms(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Ps(t){return"crucible:component:"+encodeURIComponent(t)}function Ls(t,e,o,n){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const i=Math.min(...e,t),r=Math.max(...e,t);return r-i>gs?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function $s(t,e){const o=Math.max(.25,Math.min(1,e.width/900,e.height/520)),n=t?.[0]??7*o,i=t?.[1]??18*o,r=Math.max(1,Math.min(n,i));return[r,Math.max(r,Math.max(n,i))]}function Rs(t,e){if(!t)return[];const o=Math.min(t,Math.max(1,Math.ceil(Math.sqrt(t*Math.max(.5,e.width/Math.max(1,e.height)))))),n=Math.max(1,Math.ceil(t/o));return Array.from({length:t},(t,i)=>({x:e.x+e.width/o*(i%o+.5),y:e.y+(Math.floor(i/o)+.5)*(e.height/n)}))}function Cs(t){return t.outletId?t.outletId:"failed"===t.status?"failed":"recovered"===t.status?"recovered":"retained"===t.status?"retained":"ejected"===t.status?"residue":void 0}function Ts(t,e){return t.outlets.find(t=>t.id===e)||{x:t.chamber.x+.18*t.chamber.width,y:t.chamber.y+.2*t.chamber.height,width:.64*t.chamber.width,height:.6*t.chamber.height}}function Os(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>ys(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>ys(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=$s(o.radiusRange,e),a=function(t,e){const o=new Map;for(const e of t){const t=e.outletId??"__chamber__",n=o.get(t)??[];n.push(e),o.set(t,n)}const n=new Map;for(const[t,i]of o){i.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||ys(t.id,e.id));const o=Rs(i.length,Ts(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>n.set(t.id,o[e]))}return n}(n,e),l=n.map(t=>{const n=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},i=1.28*Ls(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(c=t.id,"crucible:product:"+encodeURIComponent(c)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=Cs(t)??"__chamber__",o=c.get(e)??[];o.push(t),c.set(e,o)}const u=new Map;for(const[t,o]of c){const n=Rs(o.length,Ts(e,"__chamber__"===t?void 0:t));o.forEach((t,e)=>u.set(t.id,n[e]))}return[...i.map(t=>{let n=u.get(t.id);if(t.productIds.length){const o=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(o.length){n={x:o.reduce((t,e)=>t+e.x,0)/o.length,y:o.reduce((t,e)=>t+e.y,0)/o.length};const i=Ss(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));n={x:n.x+Math.cos(i)*r,y:n.y+Math.sin(i)*r}}}n??(n={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const i=Ls(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ps(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var Is=Os;function zs(t){return Array.isArray(t)?t.map(zs):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>ys(t,e)).map(([t,e])=>[t,zs(e)])):t}function Fs(t,e=t.duration){const o=function(t,e){const o=bs(e)??0,n=Math.max(0,Math.min(t.duration,o));if(!t.phases.length)return{elapsed:n,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=n>=t.duration-gs,r=i?t.phases[t.phases.length-1]:t.phases.find(t=>n>=t.start&&t.end>n)??t.phases[0];return{elapsed:n,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,n-r.start),complete:i}}(t,e);let n=Ur(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+gs)break;const a=ds(n,e,{phaseId:e.phaseId,authoredAt:e.authoredAt,appliedAt:e.authoredAt,products:t.products,outlets:t.outlets});i.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(n=a.state)}return n.elapsed=o.elapsed,n.phaseId=o.phaseId,n.phaseIndex=o.phaseIndex,n.phaseElapsed=o.phaseElapsed,n.complete=o.complete,o.complete&&"in_process"===n.outcome&&(n.outcome="complete"),n.playing=!1,{state:n,diagnostics:i,materializations:r,observations:s}}function Ns(t){const e=function(t){const e=[];t.length||e.push(ms("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=xs(t.map(t=>t.id));o.length&&e.push(ms("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=bs(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(ms("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(ms("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[t.id])),void 0===t.intensity||Number.isFinite(t.intensity)||e.push(ms("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.intensity`,[t.id]));const s={...t,duration:r,intensity:void 0===t.intensity?.5:Number.isFinite(t.intensity)?Math.max(0,Math.min(1,t.intensity)):.5,motion:t.motion??"hold",index:o,start:n,end:n+r};return n=s.end,s}),diagnostics:e}}(t.phases),o=e.phases.at(-1)?.end??0,n=ks(t.outlets??ps),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?Vr(t.metrics):void 0})),r=function(t,e,o){const n=[],i=xs(t.map(t=>t.id));i.length&&n.push(ms("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,l;if(t.id.trim()||n.push(ms("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=bs(t.at.time);if(null==r||0>r||r>o+gs)return void n.push(ms("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${i}.at.time`,[t.id]));s=Math.max(0,Math.min(o,r));const c=function(t,e,o){const n=t.find(t=>gs>=Math.abs(t.start-o));if(n)return{phase:n,boundaryRank:1};const i=t.find(t=>o>=t.start&&t.end>o);return i?{phase:i,boundaryRank:0}:gs>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=c.phase,l=c.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void n.push(ms("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${i}.at.phaseId`,[t.id,t.at.phaseId]));const o=t.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void n.push(ms("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${i}.at.progress`,[t.id]));s=a.start+a.duration*o,l=0===o?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):n.push(ms("error","event-without-phase","Event could not be assigned to a phase.",`events.${i}.at`,[t.id]))}),r.sort((t,e)=>t.authoredAt-e.authoredAt||t.boundaryRank-e.boundaryRank||t.index-e.index),{events:r,diagnostics:n}}(t.events??[],e.phases,o),s=function(t){const e=[],o=Gr(),n=[];let i=0;const r=Gr();t.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((vs(s,a,t.idAccessor,l,e,`data.${a}.id`)??l)+"").trim();if(!c)return void e.push(ms("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(c);const u=bs(vs(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(ms("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=ws(vs(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),p=vs(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),f=fs.has(p)?p:"active";fs.has(p)||e.push(ms("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[c]));const g=vs(s,a,t.labelAccessor,(s.label??s.name??c)+"",e,`data.${a}.label`)+"",y=vs(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,c)||(o[c]={id:c,label:g,category:y,datum:s,status:f,initialAmount:d,amount:d,initialMetrics:Vr(h),metrics:Vr(h),productIds:[],history:[]},i+=d,function(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}(r,h))});const s=xs(n);s.length&&e.push(ms("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=ws(t.metrics??{},e,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:t.phases[0]?.id??"",phaseIndex:t.phases.length?0:-1,playing:!1,complete:0===t.phases.length,outcome:"in_process",eventsApplied:[],components:o,products:Gr(),relations:Gr(),input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:Gr()},history:[]},diagnostics:e}}(t),a=function(t=hs,e=ps){const o=Math.max(1,bs(t[0])??900),n=Math.max(1,bs(t[1])??520),i=360>o||260>n,r=i?Math.max(4,.035*Math.min(o,n)):20,s=i?Math.max(10,.075*n):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},l=i?Math.max(16,.14*n):Math.min(78,.16*n),c={x:r,y:n-r-l,width:Math.max(1,o-2*r),height:l},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),p={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},f=Math.max(18,Math.min(.32*p.width,i?84:180)),g={x:p.x+(p.width-f)/2,y:p.y-(i?10:24),width:f,height:i?12:28},y=ks(e),m={left:y.filter(t=>"left"===(t.side??"bottom")),right:y.filter(t=>"right"===t.side),bottom:y.filter(t=>"bottom"===(t.side??"bottom"))},x=[],b=(t,e)=>{const n=Math.max(8,u-1.5*r),s=p.height/Math.max(1,e.length);e.forEach((e,a)=>{x.push({...e,side:t,x:"left"===t?r:o-r-n,y:p.y+a*s,width:n,height:Math.max(8,s-(i?2:8))})})};b("left",m.left),b("right",m.right);const v=p.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{x.push({...t,side:"bottom",x:p.x+e*v,y:p.y+p.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-p.y-p.height-(i?4:12))})}),x.sort((t,e)=>y.findIndex(e=>e.id===t.id)-y.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:p,mouth:g,projection:c,outlets:x}}(t.size??hs,n),l=function(t){const{chamber:e,mouth:o}=t,n=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),i=Math.max(e.x,o.x),r=Math.min(e.x+e.width,o.x+o.width),s={left:t.outlets.filter(t=>"left"===t.side),right:t.outlets.filter(t=>"right"===t.side),bottom:t.outlets.filter(t=>"bottom"===t.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:e.x,y1:e.y,x2:i,y2:e.y,thickness:n}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:e.y,x2:e.x+e.width,y2:e.y,thickness:n}}];a.push(...As({id:"crucible:wall:left",orientation:"vertical",fixed:e.x,start:e.y,end:e.y+e.height,openings:s.left.map(t=>[t.y,t.y+t.height]),thickness:n,friction:.46,restitution:.12}),...As({id:"crucible:wall:right",orientation:"vertical",fixed:e.x+e.width,start:e.y,end:e.y+e.height,openings:s.right.map(t=>[t.y,t.y+t.height]),thickness:n,friction:.46,restitution:.12}),...As({id:"crucible:wall:bottom",orientation:"horizontal",fixed:e.y+e.height,start:e.x,end:e.x+e.width,openings:s.bottom.map(t=>[t.x,t.x+t.width]),thickness:n,friction:.5,restitution:.08}));for(const e of t.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(e.id),sensor:!0,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}});return a}(a),c=function(t,e){const o=[],n=new Set(e.map(t=>t.id)),i=xs(e.map(t=>t.id)),r=xs(t.map(t=>t.id));return i.length&&o.push(ms("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(ms("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(ms("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(ms("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(ms("error","invalid-product-id","Product ids may not be empty.",`products.${e}.id`)),void 0===t.amount||Number.isFinite(t.amount)&&t.amount>=0||o.push(ms("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||n.has(t.outletId)||o.push(ms("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),ws(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>ys(t.id,e.id)).map(t=>({id:t.id,label:t.label,category:t.category,amount:t.amount,metrics:t.metrics,status:t.status})),phases:e.phases.map(({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:n,events:r.events.map(({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(zs(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>ys(t.id,e.id)),i=n.map(t=>t.amount),r=$s(o.radiusRange,e),s=function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(Ms(o.seed)),a=e.mouth.x+e.mouth.width/2,l=e.chamber.y+Math.max(18,.18*e.chamber.height),c=Math.max(4,.28*e.chamber.width),u=Math.max(4,.12*e.chamber.height);return n.map((t,e)=>{const d=e/Math.max(1,n.length)*Math.PI*2+.18*(s()-.5),h=Ls(t.amount,i,o.bodyRadius,r),p={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ps(t.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...c],f={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:_s(t.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:p},g=Fs(f),y=Object.values(g.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=y.length?[ms("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];return f.terminalState=g.state,f.terminalSpawns=Is(g.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f.diagnostics=[...p,...g.diagnostics,...m],f}import*as Es from"react";import{curveMonotoneX as Ds,curveMonotoneY as Ws,curveCardinal as Bs,curveCatmullRom as js,curveStep as Ys,curveStepBefore as Xs,curveStepAfter as Gs,curveBasis as Vs,curveNatural as Hs}from"d3-shape";function qs(t){switch(t){case"monotoneX":return Ds;case"monotoneY":return Ws;case"cardinal":return Bs;case"catmullRom":return js;case"step":return Ys;case"stepBefore":return Xs;case"stepAfter":return Gs;case"basis":return Vs;case"natural":return Hs;default:return null}}import{jsx as Us,jsxs as Ks}from"react/jsx-runtime";function Zs(t){return Number.isFinite(t)?1e3>Math.abs(t)?Number.isInteger(t)?t+"":t.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):t.toLocaleString():"0"}function Qs(t,e,o,n){const i=t.datum;if(!i?.__crucible)return;const r="circle"===t.shape.type?t.shape.radius:8,s="string"==typeof e.fill?e.fill:"product"===i.kind?"#b8792d":"#356b63",a="string"==typeof e.stroke?e.stroke:"#26323a",l="number"==typeof e.strokeWidth?e.strokeWidth:1.25,c="number"==typeof e.opacity?e.opacity:.96,u=n?`${n}-crucible-body-${o}`:"crucible-body-"+o;if("product"===i.kind){const e=Array.from({length:6},(e,o)=>{const n=-Math.PI/2+o/6*Math.PI*2;return`${t.x+Math.cos(n)*r},${t.y+Math.sin(n)*r}`}).join(" "),o=u+"-glow";return Ks(Es.Fragment,{children:[Us("defs",{children:Us("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Us("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Us("polygon",{points:e,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${o})`}),Us("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return Ks(Es.Fragment,{children:[Us("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),Us("circle",{cx:t.x-.25*r,cy:t.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as Js,jsx as ta,jsxs as ea}from"react/jsx-runtime";var oa="var(--semiotic-text, #26323a)",na="var(--semiotic-text-secondary, #6c7377)",ia="var(--semiotic-primary, #b8792d)",ra="var(--semiotic-danger, #9f3d35)",sa="var(--semiotic-success, #356b63)";function aa(t){const{x:e,y:o,width:n,height:i}=t.chamber,r=Math.min(.14*n,48),s=o+i;return[`M ${e} ${o}`,`L ${e+r} ${s-.16*i}`,`Q ${e+n/2} ${s+.1*i} ${e+n-r} ${s-.16*i}`,`L ${e+n} ${o}`].join(" ")}function la({layout:t,phases:e,state:o,compact:n=!1}){const i=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return ea("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[ea("defs",{children:[ea("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[ta("stop",{offset:"0",stopColor:ia,stopOpacity:"0.03"}),ta("stop",{offset:"0.66",stopColor:ia,stopOpacity:"0.1"}),ta("stop",{offset:"1",stopColor:ra,stopOpacity:"0.18"})]}),ta("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:ta("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:oa,strokeOpacity:"0.08",strokeWidth:"1"})})]}),ta("rect",{x:t.chamber.x,y:t.chamber.y,width:t.chamber.width,height:t.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:oa,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),ta("path",{d:aa(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),ta("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:oa,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:ta("g",{"data-testid":"crucible-phase-rail",children:e.map((n,r)=>{const s=e.slice(0,r).reduce((t,e)=>t+Math.max(0,e.duration),0),a=t.phaseRail.x+s/i*t.phaseRail.width,l=Math.max(0,n.duration)/i*t.phaseRail.width,c=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return ea("g",{children:[ta("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,l-2),height:t.phaseRail.height,rx:2,fill:c?n.color??ia:u?sa:oa,fillOpacity:c?.68:u?.28:.09}),46>l?null:ta("text",{x:a+l/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:c?oa:na,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),t.outlets.map(t=>ea("g",{children:[ta("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?ra:sa),fillOpacity:"0.1",stroke:t.color??("left"===t.side?ra:sa),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:ta("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:na,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function ca({rows:t,layout:e,projection:o,amountLabel:n}){if(!t.length)return null;const i=o.measure??"count",r=t.map(t=>Math.max(0,function(t,e){return"count"===e?t.count:"amount"===e?t.amount:Number(t.metrics[e]??0)}(t,i))),s=Math.max(1,...r),a=e.projection.width/Math.max(1,t.length),l=e.projection.height>48?21:4,c=Math.max(5,e.projection.height-l-5);return ta("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:t.map((t,o)=>{const u=r[o],d=Math.max(u>0?2:0,u/s*c),h=e.projection.x+o*a+.18*a;return ea("g",{children:[ta("rect",{x:h,y:e.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?ra:"complete"===t.status?ia:sa,fillOpacity:"0.68"}),l>4&&a>=34?ea(Js,{children:[ta("text",{x:h+.32*a,y:e.projection.y+c+10,fill:na,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),ea("text",{x:h+.32*a,y:e.projection.y+c+19,fill:oa,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Zs(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}function ua(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}import{Fragment as da,jsx as ha,jsxs as pa}from"react/jsx-runtime";function fa(t,e,o,n,i){const r=Array.isArray(i)?i:i?[i]:[];if(!1!==o||0!==r.length)return({size:i})=>{const s=[Number(i[0])||700,Number(i[1])||420],a=ar(s),l=Math.max(2,Math.round(e)),c=a.plot.width/l,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[p,f]=n?.valueExtent??[0,l],g=f===p?1:f-p,y=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*c).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return pa("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:s[0],height:s[1],viewBox:`0 0 ${s[0]} ${s[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?pa(da,{children:[Array.from({length:l+1},(t,e)=>{const o=a.plot.x+e*c;return ha("line",{"data-testid":"galton-board-bin-wall",x1:o,x2:o,y1:a.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+e)}),ha("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ha("path",{d:y,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?ha("text",{x:a.plot.x+(e+.5)*c,y:Math.max(a.plot.y+10,u-t.value/d*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.value},`${t.label}-${e}`):null)]}):null,r.map((t,e)=>{const o=Number(t.value);if(!Number.isFinite(o))return null;const n=a.plot.x+Math.max(0,Math.min(1,(o-p)/g))*a.plot.width,i=t.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===t.labelPosition?Math.min(s[1]-8,u+16):a.plot.y+16;return pa("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[ha("line",{x1:n,x2:n,y1:a.plot.y+8,y2:u-4,stroke:i,strokeDasharray:t.strokeDasharray??"6 5",strokeWidth:t.strokeWidth??2}),null==t.label?null:ha("text",{x:Math.min(a.plot.x+a.plot.width-4,n+6),y:r,fill:i,fontSize:10,fontWeight:700,children:t.label})]},`galton-reference-${e}-${o}`)})]})}}function ga(t,e,o){if(!1!==o&&e)return({size:o})=>{const n=[Number(o[0])||760,Number(o[1])||360],i=ar(n),r=Math.max(1,e.windowCount),s=e.plot??i.plot,a=e.gutter??{x:s.x,y:s.y,width:0,height:s.height},l=e.windowPlot??s,c=l.width/r,u=s.y+s.height,d=s.y+.48*s.height,h=e.lidSegments[0]?.y1??d,p=e.windowStart,f=e.windowStart+r*e.windowSize,g=l.x+Math.max(0,Math.min(1,f===p?0:(e.watermarkValue-p)/(f-p)))*l.width;return pa("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[ha("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),a.width>0?pa("g",{children:[ha("rect",{x:a.x,y:h,width:a.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),ha("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(o,i)=>{const r=t[i],s=l.x+i*c,a=e.closedWindowCount>i,h=r?.secondary??0;return pa("g",{children:[ha("rect",{x:s,y:d,width:c,height:u-d,fill:a?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?e.lidSegments.filter(t=>t.windowIndex===i).map(t=>ha("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},t.id)):null,pa("text",{x:s+c/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),ha("text",{x:s+c/2,y:Math.min(n[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+i)}),e.lidSegments.filter(t=>null==t.windowIndex).map(t=>ha("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},t.id)),ha("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ha("line",{"data-testid":"event-drop-watermark",x1:g,x2:g,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),pa("text",{x:Math.min(s.x+s.width-4,g+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*e.watermarkValue)/100]}),e.lateCount>0?pa("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[e.lateCount," late"]}):null]})}}function ya(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const n=[Number(o[0])||700,Number(o[1])||380],i=ar(n),r=vr(i.plot,t.length,e),s=i.plot.y+i.plot.height;return pa("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[ha("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),t.map((t,e)=>{const o=Math.min(i.plot.height,r.pileHeight(t.value)),a=r.tubeWidth,l=r.centerX(e),c=s-o;return pa("g",{children:[ha("rect",{x:l-a/2,y:c,width:a,height:o,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),ha("text",{x:l,y:Math.max(i.plot.y+12,c-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),ha("text",{x:l,y:Math.min(n[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${e}`)})]})}}function ma(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function xa(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],n=ar(o),i=n.plot.y+n.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,l=[{label:ma(r),x:t.xRange[0]},{label:ma(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:ma(s),x:t.xRange[1]}];return pa("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[t.groups.map(t=>pa("g",{children:[ha("line",{x1:n.plot.x,x2:n.plot.x+n.plot.width,y1:t.y,y2:t.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),ha("text",{x:n.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),pa("text",{x:n.plot.x+n.plot.width-4,y:t.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",t.count]})]},t.label)),ha("line",{x1:t.xRange[0],x2:t.xRange[1],y1:i,y2:i,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(t=>pa("g",{children:[ha("line",{x1:t.x,x2:t.x,y1:i,y2:i+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),ha("text",{x:t.x,y:Math.min(o[1]-8,i+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${t.x}`))]})}}import{jsx as ba}from"react/jsx-runtime";function va(t,e,o={},n){if(!1===e||!t)return;const{volume:i,stages:r,groups:s,groupCompletion:a}=t,l=new Map(i.stages.map(t=>[t.id,t])),c=new Map(a.map(t=>[t.id,t]));return({size:t})=>{const e=Number(t[0])||i.width,a=Number(t[1])||i.height,u=r.map(t=>{const e=l.get(t.id),n=o["process-stage-"+t.id];return{id:t.id,label:t.label,x0:e?.x0??t.x-t.width/2,x1:(e?.x0??t.x-t.width/2)+(e?.width??t.width),x:t.x,width:e?.width??t.width,count:t.count,capacity:t.capacity,absorb:t.absorb,portalTarget:t.portalTarget,queueDepth:n?.queueDepth,processed:n?.processedCount}}),d=s.map(t=>{const e=c.get(t.id);return{id:t.id,label:t.label??t.id,x:t.anchor?.x??t.x??0,y:t.anchor?.y??t.y??0,absorbed:e?.absorbed,total:e?.total,complete:e?.complete}});return O({width:e,height:a,left:i.left,right:i.right,topY:i.topY,bottomY:i.bottomY,midY:i.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...n})}}function wa(t,e,o){if(!1===o||!e||0===t.length)return;const n=new Map(e.volume.stages.map(t=>[t.id,t]));return({size:o})=>{const i=[Number(o[0])||e.volume.width,Number(o[1])||e.volume.height],r=ar(i),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),l=r.plot.y+6;return ba("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:e.stages.map((e,o)=>{const i=t[o];if(!i)return null;const r=n.get(e.id);if(!r)return null;const c=Math.max(2,i.value/s*a),u=Math.max(8,.35*r.width);return ba("rect",{x:r.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function ka(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}import{jsx as Aa,jsxs as Sa}from"react/jsx-runtime";function Ma(t,e){const{showNodeLabels:o,showSensors:n,showStaticFlow:i}=e;if(t&&(i||n||o))return({size:e})=>{const r=[Number(e[0])||760,Number(e[1])||420],s=Math.max(1,...t.links.map(t=>t.throughput)),a=new Set(t.nodes.map(t=>t.sensorId));return Sa("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[i?t.links.map(t=>{const e=3+t.throughput/s*16,o=t.path[Math.floor(t.path.length/2)];return Sa("g",{children:[Aa("path",{d:ka(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),Aa("path",{d:ka(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?Aa("text",{x:o.x,y:o.y-e/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:(n=t.throughput,n.toLocaleString(void 0,1e3>Math.abs(n)?{maximumFractionDigits:1}:{maximumFractionDigits:0}))}):null]},t.id);var n}):null,t.nodes.map(t=>Sa("g",{children:[n&&a.has(t.sensorId)?Aa("rect",{"data-testid":"physical-flow-sensor-overlay",x:t.x-12,y:t.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,i?Aa("circle",{cx:t.x,cy:t.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,o?Aa("text",{x:t.x,y:t.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:t.label}):null]},t.id))]})}}import{Fragment as _a,jsx as Pa,jsxs as La}from"react/jsx-runtime";function $a({layout:t,compact:e,showLabels:o}){const n=e?Math.round(.14*t.height):Math.max(80,t.routeY-180),i=e?Math.max(6,Math.round(.72*t.height)):Math.min(360,t.height-170);return Pa(_a,{children:t.gates.map(r=>La("g",{children:[Pa("rect",{x:r.x-r.width/2,y:n,width:r.width,height:i,rx:e?2:12,fill:r.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:r.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),o?Pa("text",{x:r.x,y:Math.max(64,t.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:r.label??r.id}):null]},r.id))})}function Ra({layout:t,states:e,compact:o=!1}){return o?Pa("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:Pa($a,{layout:t,compact:!0,showLabels:!1})}):La("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Pa("path",{d:`M ${t.startX-42} ${t.routeY} C ${.24*t.width} ${t.routeY-70}, ${.42*t.width} ${t.routeY+78}, ${.58*t.width} ${t.routeY} S ${.78*t.width} ${t.routeY-82}, ${t.socketX+36} ${t.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),Pa("line",{x1:Math.round(.06*t.width),x2:Math.round(.94*t.width),y1:t.crashY,y2:t.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),Pa("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),Pa($a,{layout:t,compact:!1,showLabels:!0}),La("g",{children:[Pa("rect",{x:t.socketX-52,y:t.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),Pa("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),La("g",{children:[Pa("rect",{x:t.graveyardX-82,y:t.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),Pa("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),Pa("text",{x:t.graveyardX,y:t.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:e.some(t=>t.killed)?"lift shut off":"too heavy or too small"})]})]})}function Ca({states:t,layout:e}){const o=function(t){return t.map(t=>({label:t.id,value:Math.max(0,Number(t.viability)||0),outcome:t.outcome||t.stage||"in-process"}))}(t);if(!o.length)return null;const n=Math.max(1,...o.map(t=>t.value)),i=Math.max(40,(e.width-80)/o.length);return La("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Pa("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),o.map((t,e)=>{const o=40+e*i,r=Math.max(2,t.value/n*28),s=/kill|crash|block|grave/i.test(t.outcome);return La("g",{children:[Pa("rect",{x:o+.18*i,y:28-r+22,width:Math.max(10,.45*i),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),Pa("text",{x:o+.4*i,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:t.label})]},t.label)})]})}var Ta={margin:(t,e)=>e.compactMode?"sparkline"===t.mode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}};function Oa(t){return t.map(t=>({...t,spawnAt:void 0}))}function Ia(t,e){return t?e?o=>sr.createElement(sr.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function za(t,e,o){const n=e[o];return"boolean"==typeof n?n:!0!==t.__compactMode}var Fa=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Na(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return Fa[(e>>>0)%Fa.length]}var Ea={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,o,n,i)=>({chartType:"line",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||e,colorAccessor:e,...n,showAxes:!1,margin:n.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:Ao,LineChart:_o,AreaChart:Lo,DifferenceChart:$o,StackedAreaChart:Ro,Scatterplot:Ie,CandlestickChart:Co,BubbleChart:ze,ConnectedScatterplot:Oo,QuadrantChart:To,Heatmap:Io,TemporalHistogram:Po,XYCustomChart:{frameType:"xy",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:n.showLegend??!!e})},BarChart:nn,StackedBarChart:rn,GroupedBarChart:sn,PieChart:an,DonutChart:ln,Histogram:cn,BoxPlot:un,ViolinPlot:dn,SwarmPlot:hn,DotPlot:pn,SwimlaneChart:fn,RidgelinePlot:gn,LikertChart:yn,FunnelChart:mn,GaugeChart:xn,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},ForceDirectedGraph:Hi,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,o,n,i)=>({chartType:"force",nodes:i.nodes||t||[],edges:i.edges||[],nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor||"id",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",valueAccessor:i.valueAccessor||"value",colorBy:e,colorScheme:o,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...n})},SankeyDiagram:Zi,ProcessSankey:Ki,ChordDiagram:Vi,TreeDiagram:Qi,Treemap:Ji,CirclePack:qi,OrbitDiagram:Ui,ChoroplethMap:nr,ProportionalSymbolMap:ir,FlowMap:rr,GeoCustomChart:{frameType:"geo",buildProps:(t,e,o,n,i)=>({points:i.points||t||[],areas:i.areas||[],lines:i.lines||[],projection:i.projection||"equirectangular",xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",lineDataAccessor:i.lineDataAccessor,colorBy:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n})},GaltonBoardChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,c=i.seed??1,u=Math.max(1,Math.round(i.pegRows??s-1)),d="mechanical"===i.mode,h=d?function(t){const e=Math.max(2,Math.round(t.bins)),o=Math.max(1,Math.round(t.pegRows??e-1)),n=Math.max(1,Math.round(t.count??Math.max(64,4*e))),i=pr(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=yr(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:n},(t,e)=>{let n=0;for(let t=0;o>t;t+=1)r()<i&&(n+=1);const a=o/2;return{id:`${s}-${e}`,value:n,mechanical:!0,pegRows:o,branchProbability:i,pathRights:n,side:a>n?"left":n>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:u,seed:c}):Array.isArray(t)?t:[],p=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:c}=t,u=ar(s),d=e.map((t,e)=>hr(dr(t,e,o))).filter(t=>null!=t),h=function(t){if(!t)return;const e=hr(t[0]),o=hr(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(c),p=h?.[0]??(d.length?Math.min(...d):0),f=h?.[1]??(d.length?Math.max(...d):1),g=f===p?1:f-p,y=mr().domain([0,n]).range([u.plot.x,u.plot.x+u.plot.width]),m=Array.from({length:n},()=>0),x=[];e.forEach((t,e)=>{const r=hr(dr(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-p)/g*n)));m[s]+=1,x.push({id:(t.id??"galton-"+e)+"",x:y(s+.5),y:u.plot.y+i+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...t,value:r,bin:s}})});const b=u.plot.y+u.plot.height;return{config:ur(r,[...a({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...l({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:y,yTop:u.plot.y-400,yBottom:b,wallThickness:6})],"GaltonBoardChart"),initialSpawns:x,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot:u.plot,valueExtent:[p,f]}}}({data:h,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:c,size:r,valueExtent:d?[0,u]:void 0});return{...n,config:p.config,initialSpawns:Oa(p.initialSpawns),projectionRows:p.projectionRows,foregroundGraphics:Ia(fa(p.projectionRows,s,za(n,i,"showProjection"),p.metadata,i.referenceLines),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||(d?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:n,windows:i,watermark:r,ballRadius:s,seed:l,size:c,timeExtent:u,timeScale:d=1}=t,h=ar(c),p=e.map((t,e)=>hr(dr(t,e,o))).filter(t=>null!=t),f=hr(u?.[0]),g=hr(u?.[1]),y=p.length?Math.min(...p):0,m=p.length?Math.max(...p):y+i.size,x=Math.min(f??y,y),b=Math.max(g??m,m),v=Math.floor(x/i.size)*i.size,w=Math.max(1,Math.ceil((b-v+i.size)/i.size)),k=p.length?Math.max(...p):0,A="function"==typeof r?r(k):hr(r?.value)??k-(r?.delay??i.size),S=Math.max(0,Math.min(w,Array.from({length:w},(t,e)=>e).reduce((t,e)=>v+(e+1)*i.size>A?t:t+1,0))),M=function(t,e){const o=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:o,height:t.plot.height},windowPlot:{x:t.plot.x+o,y:t.plot.y,width:Math.max(40,t.plot.width-o),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(h,s),_=v+w*i.size,P=xr().domain([v,_]).range([M.windowPlot.x,M.windowPlot.x+M.windowPlot.width]),L=Array.from({length:w},()=>({value:0,secondary:0})),$=[];e.forEach((t,e)=>{const r=hr(dr(t,e,o));if(null==r)return;const a=hr(dr(t,e,n))??r,l=Math.max(0,Math.min(w-1,Math.floor((r-v)/i.size))),c=A>=v+(l+1)*i.size;L[l].value+=c?0:1,L[l].secondary+=c?1:0,$.push({id:(t.id??"event-"+e)+"",x:Math.max(M.windowPlot.x+s,Math.min(M.windowPlot.x+M.windowPlot.width-s,P(r))),y:h.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:l,late:c}})});const R=h.plot.y+h.plot.height,C=function(t,e){const o=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!o)return[];const n=t.windowStart,i=t.windowStart+t.windowCount*t.windowSize,r=xr().domain([n,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,l=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),c=t=>s===a?e:l+(t-a)/(s-a)*(e-l),u=[];for(let e=0;o>e;e+=1){const o=t.windowStart+e*t.windowSize,n=o+t.windowSize,i=r(o),s=r(n);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:i,y1:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:S,gutter:M.gutter,plot:h.plot,windowCount:w,windowPlot:M.windowPlot,windowSize:i.size,windowStart:v},h.plot.y+.28*h.plot.height);return{config:ur(l,[...a({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...br({idPrefix:"eventdrop-window",count:w,xScale:t=>P(v+t*i.size),yTop:M.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?C[0]?.y1:C[t-1]?.y2??C[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?M.wallTop:e+1.25*s},yBottom:R,wallThickness:6}),...C.map(t=>({id:t.id,shape:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:$,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:d},projectionRows:L.map((t,e)=>({label:`${v+e*i.size}-${v+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:M.gutter,lidSegments:C,lateCount:L.reduce((t,e)=>t+e.secondary,0),plot:h.plot,windowPlot:M.windowPlot,watermarkValue:A,windowCount:w,windowSize:i.size,windowStart:v}}}({data:Array.isArray(t)?t:[],timeAccessor:i.timeAccessor||"time",arrivalAccessor:i.arrivalAccessor||"arrivalTime",windows:i.windows||{size:10},watermark:i.watermark,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r,timeExtent:i.timeExtent,timeScale:i.timeScale??1});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(ga(s.projectionRows,s.metadata,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,l=function(t){const{data:e,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:l}=t,c=fr(i,1),u=ar(l),d=[],h=new Map,p=new Map,f=[];function g(t){let e=h.get(t);return null==e&&(e=d.length,d.push(t),h.set(t,e)),e}e.forEach((t,e)=>{g((dr(t,e,o)??"unknown")+"")});const y=Math.max(1,d.length),m=vr(u.plot,y,r),x=Math.max(0,m.tubeWidth/2-r-1),b=d.map(()=>[]);e.forEach((t,e)=>{const i=(dr(t,e,o)??"unknown")+"",s=g(i),a=n?hr(dr(t,e,n)):1,l=Math.max(0,Math.round((a??0)/c)),d=m.centerX(s);for(let o=0;l>o;o+=1){const n=p.get(i)??0,a=m.perRow>1?((m.perRow>1?n%m.perRow:0)/(m.perRow-1)*2-1)*x:0;p.set(i,n+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:u.plot.y+r+2,vx:(o%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:i,unitIndex:o}})}});const v=b.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;v>t;t+=1)for(const e of b)e.length>t&&f.push(e[t]);const w=u.plot.y+u.plot.height,k=[...a({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],A=u.plot.y-400;for(let t=0;y>t;t+=1){const e=m.centerX(t);for(const o of[-1,1])k.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*m.tubeWidth/2,y:(A+w)/2,width:6,height:w-A}})}return{config:ur(s,k,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(t=>({label:t,value:p.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),o=e.length?e:["Intake"],n=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),i=fr(t.unitValue,1),r=yr(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),l=a.reduce((t,e)=>t+e,0)||1,c=n-o.length,u=a.map(t=>t/l*c),d=u.map(t=>1+Math.floor(t));let h=n-d.reduce((t,e)=>t+e,0);const p=u.map((t,e)=>({index:e,fraction:t-Math.floor(t)})).sort((t,e)=>e.fraction-t.fraction);for(let t=0;h>0;t=(t+1)%p.length)d[p[t].index]+=1,h-=1;return o.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*i,mechanical:!0,unitCount:d[e],unitValue:i,share:d[e]/n}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...n,config:l.config,initialSpawns:Oa(l.initialSpawns),projectionRows:l.projectionRows,foregroundGraphics:Ia(ya(l.projectionRows,i.ballRadius??5,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:n,radiusAccessor:i,pointRadius:r,seed:s,size:l,xExtent:c,collisionIterations:u,settle:d}=t,h=ar(l),p=yr(s),f=[],g=[],y=new Map;e.forEach((t,e)=>{const s=hr(dr(t,e,o));if(null==s)return;const a=n?(dr(t,e,n)??"All")+"":"All",l=i?hr(dr(t,e,i)):null,c=pr(null!=l&&l>0?l:r,2,18);!function(t){let e=y.get(t);null==e&&(e=g.length,g.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:c})});const m=f.map(t=>t.value),x=c?hr(c[0]):null,b=c?hr(c[1]):null,v=m.length?Math.min(...m):0,w=m.length?Math.max(...m):1;let k=x??v,A=b??w;if(k===A&&(k-=.5,A+=.5),k>A){const t=A;A=k,k=t}const S=Math.max(r,...f.map(t=>t.radius)),M=h.plot.x+S+8,_=h.plot.x+h.plot.width-S-8,P=wr().domain([k,A]).range([M,_]),L=Math.max(1,g.length),$=Math.min(Math.max(28,3*S),h.plot.height/4),R=h.plot.y+$,C=Math.max(0,h.plot.y+h.plot.height-$-R),T=t=>{const e=y.get(t)??0;return 1===L?h.plot.y+.54*h.plot.height:R+e/(L-1)*C},O=new Map,I=f.map((t,e)=>{O.set(t.group,(O.get(t.group)??0)+1);const o=P(t.value),n=T(t.group),i=(p()-.5)*t.radius*1.6,r=(p()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:d?o+i:pr(o+(e%9-4)*t.radius*2.5,M,_),y:d?n+r:h.plot.y-18-e%12*t.radius,vx:d?0:22*(p()-.5),vy:d?0:24+18*p(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:o,targetY:n},springs:[{target:{type:"point",x:o,y:n},restLength:0,stiffness:34,damping:5.5}]}});return{config:ur(s,a({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(u??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:I,projectionRows:g.map(t=>({label:t,value:O.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[k,A],xRange:[M,_],groups:g.map(t=>({label:t,y:T(t),count:O.get(t)??0})),plot:h.plot}}}({data:Array.isArray(t)?t:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(xa(s.metadata,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,i,a)=>{const l=i.size??[900,420],c=Array.isArray(a.stages)?a.stages:[],d=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,i=ar(o),a=pr(t.ballRadius??6,2,18),l=t.seed??1,c=yr(l),d=t.idAccessor,h=t.stageAccessor??"stage",p=t.groupBy,f=t.groupLabelAccessor,g=t.workAccessor,m=t.radiusAccessor,x=t.groupCompletion??(p?"allAbsorbed":"none"),b=t.springStiffness??.28,v=t.springDamping??.72,w=!0===t.settle,k=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),A=I({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:k,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),S=new Map(A.stages.map((t,e)=>[t.id,e])),M=new Map(A.stages.map(t=>[t.id,t])),_=A.stages[0].id,P=A.stages[0],L=new Set(e.filter(t=>t.absorb).map(t=>t.id)),$=e.map(t=>{const e=M.get(t.id)??P;return function(t,e){const o={id:"process-stage-"+t.id,label:t.label??t.id,description:t.description,x:e.x,y:e.y,width:Math.max(12,.92*e.width),height:Math.max(40,.88*e.height),semanticItem:!1,attributes:{stageId:t.id}};if(t.absorb)return n({...o,kind:t.kind??"sink",force:Lr(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return C({...o,kind:t.kind??"force-field",force:Lr(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}})}if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return s({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:Lr(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...o.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return T({...o,kind:t.kind??"membrane",pressure:e.pressure,occupancy:e.occupancy,baseDamping:e.baseDamping??t.damping??.1,dampingPerUnit:e.dampingPerUnit??.1,energyPerUnit:e.energyPerUnit??0,force:Lr(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?W({...o,kind:t.kind??"force-field",force:Lr(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):u({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:A.midY,width:e.width,height:A.bottomY-A.topY})});$.unshift(W({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(A.left+A.right)/2,y:A.midY,width:A.right-A.left,height:A.bottomY-A.topY-12,force:8,damping:.012,semanticItem:!1}));const R=new Map;for(const t of A.stages)R.set(t.id,0);const O=[];t.data.forEach((t,e)=>{const o=(d?dr(t,e,d)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(dr(t,e,h)??_)+"",i=S.has(n)?n:_;R.set(i,(R.get(i)??0)+1);const r=p?(dr(t,e,p)??"")+"":void 0,s=r&&f?(dr(t,e,f)??r)+"":r,l=g?hr(dr(t,e,g))??1:1,c=m?hr(dr(t,e,m)):null,u=pr(null!=c&&c>0?c:a,2,18);O.push({datum:t,id:o,stageId:i,groupId:r||void 0,groupLabel:s||void 0,work:l,radius:u,index:e})});const z=new Map,F=new Map;for(const t of O){if(!t.groupId)continue;const e=z.get(t.groupId)??[];e.push(t.id),z.set(t.groupId,e),t.groupLabel&&F.set(t.groupId,t.groupLabel)}const N=pr(t.groupAnchorAlong??.55,.15,.9),E=A.left+(A.right-A.left)*N,D=Array.from(z.keys()),B=D.map((t,o)=>{const n=z.get(t)??[],i=D.length>1?A.topY+28+o/Math.max(1,D.length-1)*(A.bottomY-A.topY-56):A.midY;return r({id:t,label:F.get(t)??t,bodyIds:n,anchor:{x:E,y:i},x:E,y:i,completion:"allAbsorbed"===x?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),j=O.filter(t=>L.has(t.stageId)).map(t=>t.id),Y=y(B,j),X=new Map(B.map(t=>[t.id,t])),G=O.map((t,e)=>{const o=M.get(t.stageId)??P,n=o.x+(c()-.5)*Math.min(24,.2*o.width),i=A.boundaryY(n,"top")+t.radius+10,r=A.boundaryY(n,"bottom")-t.radius-10,s=r>i?i+c()*Math.max(1,r-i):A.midY,a=w?n:A.left+18+e%7*4,l=w?s:A.midY+(c()-.5)*(A.bottomY-A.topY)*.35,u=[{target:{type:"point",x:n,y:s},restLength:.45*t.radius,stiffness:b,damping:v}];if(t.groupId){const e=X.get(t.groupId);e?.anchor&&!L.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:a,y:l,vx:w?0:40+40*c(),vy:w?0:20*(c()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:w?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),V={kernel:{seed:l,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:A.colliders,fixedDt:1/60,maxSubsteps:8},H=A.stages.map(t=>({label:t.label??t.id,value:R.get(t.id)??0})),q=e.map(t=>{const e=M.get(t.id)??P;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:R.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:V,initialSpawns:G,initialSpawnPacing:w?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:H,metadata:{kind:"process-flow",plot:i.plot,volume:A,stages:q,groups:B,groupCompletion:Y,regionEffects:$}}}({data:Array.isArray(t)?t:[],stages:c,size:l,idAccessor:a.idAccessor,stageAccessor:a.stageAccessor||"stage",groupBy:a.groupBy,groupLabelAccessor:a.groupLabelAccessor,workAccessor:a.workAccessor,radiusAccessor:a.radiusAccessor,ballRadius:a.ballRadius??6,seed:a.seed??1,groupCompletion:a.groupCompletion,groupAnchorAlong:a.groupAnchorAlong,settle:a.settle??!0,gravityX:a.gravityX,gravityY:a.gravityY}),h=d.metadata;return{...i,config:d.config,initialSpawns:Oa(d.initialSpawns),projectionRows:d.projectionRows,regionEffects:h?.regionEffects,backgroundGraphics:Ia(va(d.metadata,za(i,a,"showChrome"),{},a.chromeOptions),i.backgroundGraphics),foregroundGraphics:Ia(wa(d.projectionRows,d.metadata,za(i,a,"showProjection")),i.foregroundGraphics),bodyStyle:cr(e||a.colorBy||a.groupBy,"#4e79a7",{styleRules:a.styleRules,valueAccessor:a.workAccessor||a.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Xr({data:Array.isArray(t)?t:[],size:r,gates:i.gates,positiveProperties:i.positiveProperties,negativeProperties:i.negativeProperties,crashOffset:i.crashOffset,idAccessor:i.idAccessor,positiveAccessor:i.positiveAccessor,negativeAccessor:i.negativeAccessor,metricsAccessor:i.metricsAccessor,initialViability:i.initialViability,projectPlacement:i.projectPlacement,coreBody:i.coreBody,viability:i.viability});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:[],backgroundGraphics:Ia(za(n,i,"showChrome")?sr.createElement(Ra,{layout:s.layout,states:s.states,compact:!0===n.__compactMode}):void 0,n.backgroundGraphics),foregroundGraphics:Ia(za(n,i,"showProjection")?sr.createElement(Ca,{layout:s.layout,states:s.states}):void 0,n.foregroundGraphics),bodyStyle:cr(e||i.colorBy)}}},CrucibleChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Ns({data:Array.isArray(t)?t:[],phases:Array.isArray(i.phases)?i.phases:[],products:Array.isArray(i.products)?i.products:void 0,outlets:Array.isArray(i.outlets)?i.outlets:void 0,events:Array.isArray(i.events)?i.events:void 0,idAccessor:i.idAccessor,labelAccessor:i.labelAccessor,categoryAccessor:i.categoryAccessor,amountAccessor:i.amountAccessor,metricsAccessor:i.metricsAccessor,initialStateAccessor:i.initialStateAccessor,metrics:i.metrics,size:r,seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange}),a="snapshot"===i.playback?function(t,e){if(void 0===e)return t.duration;if("number"==typeof e)return Math.max(0,Math.min(t.duration,bs(e)??0));const o=t.phases.find(t=>t.id===e.phaseId);if(!o)return t.duration;const n=Math.max(0,Math.min(1,bs(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,l=Fs(s,a).state,c=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const o=e.groupBy??"outlet",n=new Map,i=t=>{const e=function(t,e){return"product"===e?"product"===t.kind?t.id:"unassigned":"outlet"===e?t.outletId??"unassigned":"category"===e?t.category:t.status}({...t,status:t.status??"active"},o),i=n.get(e);if(i)return i.count+=1,i.amount+=t.amount,void es(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:Hr(t.metrics),status:"status"===o?t.status:void 0,outletId:"outlet"===o?t.outletId:void 0,category:"category"===o?t.category:void 0,productId:"product"===o&&"product"===t.kind?t.id:void 0})};for(const e of Object.values(t.components))e.productIds.length||"consumed"===e.status||i({kind:"component",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});for(const e of Object.values(t.products))i({kind:"product",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});const r=new Map((e.order??[]).map((t,e)=>[t,e]));return[...n.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||Zr(t.key,e.key))}(l,c),d=c.measure??"count",h=function(t,e={}){const o=e.bodies??[],n=Math.max(0,e.recentBodyLimit??6),i=new Map;for(const t of o){const o=e.getContainerId?.(t);if(!o)continue;const n=i.get(o);n?n.push(t):i.set(o,[t])}const r=t.map(t=>{const o=i.get(t.id)??[],r=Math.max(0,Math.floor(t.count??o.length)),s=o.slice(Math.max(0,o.length-n)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??ua(t),datum:t.datum}));return{id:t.id,label:t.label,count:r,share:0,secondary:t.secondary,secondaryLabel:t.secondaryLabel,observed:t.observed,bodyIds:o.map(t=>t.id),recentBodies:s,metadata:t.metadata}}),s=r.reduce((t,e)=>t+e.count,0);return r.map(t=>({...t,share:s>0?t.count/s:0}))}(u.map(t=>({id:t.key,label:t.label,count:t.count,secondary:"count"===d||"amount"===d?t.amount:Number(t.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),p={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},f=e??i.colorBy??"category",g=!1===i.showChrome?null:sr.createElement(la,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),y=!1===i.showProjection?null:sr.createElement(ca,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:Oa(Os(l,s.layout,p)),projectionRows:h,bodyStyle:t=>function(t,e,o,n){const i=t.datum,r={stroke:n.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:n.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:n.opacity??.96};if(!i?.__crucible)return{...r,fill:n.color??"#b8792d"};if("product"===i.kind){const t=e.products[i.semanticId];return{...r,fill:n.color??t?.color??Na(t?.id??i.semanticId)}}const s=e.components[i.semanticId];if(!s)return{...r,fill:n.color??"#356b63"};let a;return a="status"===o?s.status:"outlet"===o?s.outletId??"in chamber":"product"===o?s.productIds[0]??"unalloyed":"category"===o||null==o?s.category:"function"==typeof o?(o(s.datum)??"unassigned")+"":(s.datum[o+""]??"unassigned")+"",{...r,fill:n.color??Na(a)}}(t,l,f,i),getBodyLabel:t=>function(t,e){const o=t.datum;if(o?.__crucible)return"product"===o.kind?e.products[o.semanticId]?.label:e.components[o.semanticId]?.label}(t,l),renderBodySVG:Qs,backgroundGraphics:Ia(g,n.backgroundGraphics),foregroundGraphics:Ia(y,n.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:n,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:l,nodes:c,particleRadius:u,particleRate:d,pathAccessor:h,pathConstraint:p="path",reducedMotion:f,seed:g,size:y,sourceAccessor:m,targetAccessor:x,throughputAccessor:b}=t,v=ar(y),w=yr(g),k=new Map,A=new Map,S=[];function M(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const o=(dr(t,e,r)??t.id??e)+"",n=hr(dr(t,e,s)),i=hr(dr(t,e,l));if(null!=n&&null!=i){const t={x:n,y:i};k.set(o,t),S.push(t)}A.set(o,(t.label??t.name??o)+"")});const _=[];n.forEach((t,e)=>{const o=M(dr(t,e,m)),n=M(dr(t,e,x)),i=Math.max(0,hr(dr(t,e,b))??0),r=Ar(h?dr(t,e,h):void 0),s=r.length?r:Ar(t.path??t.points??t.route);s.forEach(t=>S.push(t)),_.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const P=($=S,"normalized"===(L=e)||"pixels"===L?L:$.length>0&&$.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var L,$;const R=new Map;for(const[t,e]of k)R.set(t,Sr(e,v,P));const C=[];for(const t of _){let e=t.rawPath.map(t=>Sr(t,v,P));if(2>e.length){const o=R.get(t.source),n=R.get(t.target);o&&n&&(e=[o,n])}else R.has(t.source)||R.set(t.source,e[0]),R.has(t.target)||R.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(A.has(t.source)||A.set(t.source,t.source),A.has(t.target)||A.set(t.target,t.target),C.push({...t,path:e,packetCount:0}))}const T=fr(d,.12),O=Math.max(1,Math.round(i)),I=C.map(t=>Math.max(1,Math.round(t.throughput*T))),z=I.reduce((t,e)=>t+e,0),F=z>O?O/z:1;C.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(I[e]*F))});let N=C.reduce((t,e)=>t+e.packetCount,0);for(;N>O;){const t=C.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>C[t].packetCount)?o:t,-1);if(-1===t)break;C[t].packetCount-=1,N-=1}const E=new Map,D=new Map,W=[],B=fr(o,90),j=fr(u,4);C.forEach((t,e)=>{E.set(t.target,(E.get(t.target)??0)+t.throughput),D.set(t.source,(D.get(t.source)??0)+t.throughput);const o=Mr(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=f?i:pr(.12+.84*i+.04*(w()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*w())),a=_r(t.path,s),l=_r(t.path,r),c=Pr(t.path,s),u={x:-c.y,y:c.x},d=(w()-.5)*j*1.5;W.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:c.x*B+10*(w()-.5),vy:f?0:c.y*B+10*(w()-.5),mass:.8,spawnAt:f?0:.04*e+n/32,shape:{type:"circle",radius:j},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:n,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:B,sourceLabel:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target},springs:"none"!==p&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*j,stiffness:26,damping:4.25}]:void 0})}});const Y=Math.max(18,5*j),X=Array.from(R,([t,e])=>({nodeId:t,label:A.get(t)??t,sensorId:"physical-flow-node-"+gr(t),point:e})),G=X.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:Y,height:Y}})),V=Object.fromEntries(X.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),H=ur(g,[...a({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...G],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*j),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=O,H.eviction="oldest",H.observation={...H.observation,sensors:V};const q=Array.from(R,([t,e])=>({id:t,label:A.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+gr(t),incoming:E.get(t)??0,outgoing:D.get(t)??0})),U=C.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:H,initialSpawns:W,projectionRows:q.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:P,particleCount:W.length,totalThroughput:C.reduce((t,e)=>t+e.throughput,0),plot:v.plot,nodes:q,links:U}}}({nodes:Array.isArray(i.nodes)?i.nodes:[],links:Array.isArray(i.links)?i.links:Array.isArray(i.edges)?i.edges:Array.isArray(t)?t:[],nodeIdAccessor:i.nodeIdAccessor||"id",nodeXAccessor:i.nodeXAccessor||"x",nodeYAccessor:i.nodeYAccessor||"y",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",throughputAccessor:i.throughputAccessor||"value",pathAccessor:i.pathAccessor||"path",coordinateMode:i.coordinateMode||"auto",particleRate:i.particleRate??.16,maxParticles:i.maxParticles??180,particleRadius:i.particleRadius??4,flowSpeed:i.flowSpeed??90,pathConstraint:i.pathConstraint||"path",reducedMotion:!0,seed:i.seed??1,size:r});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(Ma(s.metadata,{showNodeLabels:!1!==i.showNodeLabels,showSensors:!1!==i.showSensors,showStaticFlow:!1!==i.showStaticFlow}),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",layout:Ta,buildProps:(e,o,n,i,r)=>{const s=i.size??[700,380],a=ye(i.theme),l=function(e){const o=function(t,e,o){const n=t?.observation;return{...t,observation:{...n,chartId:e??n?.chartId??"physics-custom",chartType:n?.chartType??"PhysicsCustomChart",onObservation:o??n?.onObservation}}}(e.config,e.chartId,e.onObservation),n=Rr(e.colorScheme,e.themeCategorical,B),i=ar(e.size),r={data:e.data,scales:{x:$r().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:$r().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:Cr(n,e.colorScheme),config:e.layoutConfig??{},world:new t(o)},s=e.skipLayout?{}:e.layout(r)??{},a=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...n}=t,i=o.get(e)??[];i.push(n),o.set(e,i)}return t.map(t=>{const e=o.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...s.initialSpawns??s.bodies??[]],s.constraints);return{config:Tr(o,s),context:r,initialSpawnPacing:s.initialSpawnPacing,initialSpawns:a,result:s}}({chartId:r.chartId,colorScheme:n,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:Rt(a)??{},size:s,themeCategorical:a.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:l.config,initialSpawns:Oa(l.initialSpawns),projectionRows:[],bodyStyle:l.result.bodyStyle??cr(o||r.colorBy),backgroundGraphics:Ia(i.backgroundGraphics,l.result.backgroundOverlays),foregroundGraphics:Ia(i.foregroundGraphics,l.result.overlays)}}}};function Da(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Wa(t){if(!t||2>t.length)return;const e=Da(t[0]),o=Da(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Ba(t){const{count:e,byType:o}=function(t){const e={};for(const o of t){const t="string"==typeof o?.type&&o.type.length>0?o.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),n=0===e,i=[...t.extraWarnings??[]];n&&!i.includes("EMPTY_SCENE")&&i.push("EMPTY_SCENE"),t.annotationRender&&t.annotationRender.unrenderedCount>0&&!i.includes("UNRENDERED_ANNOTATIONS")&&i.push("UNRENDERED_ANNOTATIONS");const r=Array.isArray(t.annotations)?t.annotations.length:0,s=t.margin,a=s?{x:s.left,y:s.top,width:t.width-s.left-s.right,height:t.height-s.top-s.bottom}:void 0;return{component:"",frameType:t.frameType,status:n?"empty":"ok",empty:n,markCount:e,markCountByType:o,width:t.width,height:t.height,...t.xDomain?{xDomain:t.xDomain}:{},...t.yDomain?{yDomain:t.yDomain}:{},...t.categories?{categories:t.categories}:{},...void 0!==t.nodeCount?{nodeCount:t.nodeCount}:{},...void 0!==t.edgeCount?{edgeCount:t.edgeCount}:{},...void 0!==t.legendItems?{legendItems:t.legendItems}:{},annotationCount:t.annotationRender?.renderedCount??r,...t.annotationRender?{annotationInputCount:t.annotationRender.inputCount,unrenderedAnnotationCount:t.annotationRender.unrenderedCount,...t.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:t.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:i,semanticStatus:"not-assessed",semanticDiagnostics:[],...s?{margin:s}:{},...a?{plot:a}:{}}}import*as ja from"react";import*as Ya from"react-dom/server.browser";function Xa(t){return new Set(Array.isArray(t)?t:[t])}function Ga(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Va(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Ha(t,e,o){return t+(e-t)*o}function qa(){return"undefined"!=typeof performance?performance.now():Date.now()}function Ua(t,e,o){if(1>=o)return 1;const n=o-1;return function(t){const e=Math.max(0,Math.min(1,t.minOpacity??.1));if(Number.isNaN(t.age))return 1;if(t.age===1/0)return e;if(!Number.isFinite(t.extent)||0>=t.extent)return 1;const o=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>o?1:e;if("exponential"===t.type){const n=t.halfLife??t.extent/2;return e+Math.pow(.5,o/(n>0?n:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-o/t.extent))*(1-e)}({age:n-e,extent:n,type:t.type,halfLife:t.halfLife??o/2,threshold:t.stepThreshold??.5*o,minOpacity:t.minOpacity??.1})}function Ka(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function Za(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function Qa(t,e,o,n){let i=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,i=!0),t._pulseColor!==o&&(t._pulseColor=o,i=!0),t._pulseGlowRadius!==n&&(t._pulseGlowRadius=n,i=!0),i):(0!==t._pulseIntensity&&(t._pulseIntensity=0,i=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,i=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,i=!0),i)}function Ja(t,e,o=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const n=t.duration??500,i=e.peek();return null!=i&&n>o-i}function tl(t,e,o){if(e._transitionKey)return e._transitionKey;switch(e.type){case"point":if(e.pointId)return"p:"+e.pointId;if("streaming"===t.runtimeMode&&e.datum){const o=t.getX(e.datum),n=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${o}:${n}`;if(null!=o&&null!=n)return`p:${o}:${n}`}return"p:"+o;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+o;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??o}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+o:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function el(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}function ol(t,e,o,n,i,r){const s=[];for(const i of t){const t=o(i),r=n(i);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:i})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),l=Array(s.length),c=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],l[t]=e.rawY,c[t]=e.d}return{type:"line",path:a,rawValues:l,style:i,datum:c,group:r}}function nl(t,e,o,n,i,r,s,a){const l=[];for(const r of t){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const c=e.x(t),u=a?a(r):i;l.push({px:c,topY:e.y(s),botY:e.y(u),rawY:s})}l.sort((t,e)=>t.px-e.px);const c=Array(l.length),u=Array(l.length),d=Array(l.length);for(let t=0;l.length>t;t++){const e=l[t];c[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:c,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function il(t,e,o,n){const i=new Map;if("silhouette"===n)for(const n of t){let t=0;for(const i of e)t+=o(i,n)||0;i.set(n,-t/2)}else if("wiggle"===n){t.length>0&&i.set(t[0],0);for(let n=1;t.length>n;n++){const r=t[n-1],s=t[n];let a=0,l=0,c=0;for(const t of e){const e=o(t,s)||0;a+=(2*c+e)*(e-(o(t,r)||0)),l+=e,c+=e}const u=i.get(r)??0;i.set(s,u-(l>0?a/(2*l):0))}if(t.length>0){let n=0;for(const r of t){let t=0;for(const n of e)t+=o(n,r)||0;n+=(i.get(r)??0)+t/2}const r=n/t.length;for(const e of t)i.set(e,(i.get(e)??0)-r)}}else for(const e of t)i.set(e,0);return i}function rl(t,e,o,n,i,r,s){const a=o(t),l=n(t);if(!Number.isFinite(a)||!Number.isFinite(l))return null;const c={type:"point",x:e.x(a),y:e.y(l),r:i,style:r,datum:t};return void 0!==s&&(c.pointId=s),c}function sl(t,e,o,n,i,r,s,a){const l=o(t),c=n(t);if(!Number.isFinite(l)||!Number.isFinite(c))return null;const u={type:"symbol",x:e.x(l),y:e.y(c),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function al(t,e,o,n,i,r,s){return{type:"rect",x:t,y:e,w:o,h:n,style:i,datum:r,group:s}}function ll(t,e,o,n,i,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:n,fill:i,datum:r};return void 0!==s?.value&&(a.value=s.value),s?.showValues&&(a.showValues=!0,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function cl(t,e,o,n){return"function"==typeof e.style?e.style(n||{},o):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(o,n)}function ul(t,e,o,n){if(!t.scales)return null;const i=[],r=[];for(const o of e){const e=t.getX(o);if(!Number.isFinite(e))continue;const s=n.getTop(o),a=n.getBottom(o);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const l=t.scales.x(e),c=t.scales.y(s),u=t.scales.y(a);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(u)&&(i.push([l,c]),r.push([l,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:cl(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function dl(t){const e=[],o=[];if(!t)return{perSeries:e,aggregate:o};for(const n of t)n.perSeries?e.push(n):o.push(n);return{perSeries:e,aggregate:o}}function hl(t,e,o){const n=[];for(const i of o){const o=ul(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function pl(t,e,o,n){const i=[];for(const r of n){const n=ul(t,e,o,r);n&&i.push(n)}return i}function fl(t,e,o,n){if(!t.config.pointStyle)return;const i=n??t.getY;for(const n of e){const e=t.resolveGroupColor(n.key);for(const r of n.data){let n=t.config.pointStyle(r);!n.fill&&e&&(n={...n,fill:e});const s=n.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,l=rl(r,t.scales,t.getX,i,s,n,a);l&&o.push(l)}}}function gl(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function yl(t){return ce(t)}var ml=new Map;function xl(t){const o=Object.prototype.hasOwnProperty.call(e,t)?t:"blues";let n=ml.get(o);if(n)return n;n=Array(256);const i=h(o);for(let t=0;256>t;t++)n[t]=i(t/255);return ml.set(o,n),n}function bl(t,e,o){const n=o.config.areaStyle?.(e);return n&&("string"==typeof n.fill&&(t.fill=n.fill),t.style=n),t}function vl(t,e,o,n,i){const r=new Map;for(const s of t){const t=e(s),a=o(s);if(null==t||null==a||Number.isNaN(t)||Number.isNaN(a))continue;const l=Math.floor(t/n)*n;let c=r.get(l);if(c||(c={start:l,end:l+n,total:0,categories:new Map},r.set(l,c)),c.total+=a,i){const t=i(s);c.categories.set(t,(c.categories.get(t)||0)+a)}}return r}function wl(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;kl(n)&&0===o.length&&Al(i,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),o.length>0&&o.every(t=>null==t.datum)&&Al(i,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function kl(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(kl))}function Al(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function Sl(t,e,o,n){const i=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${i.message}`,error:i,recovery:o?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:o,affectedRevision:n}}function Ml(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function _l(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=Ml(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=mt(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e+i:e},getBottom:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e-i:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const o=Array.isArray(t.band)?t.band:[t.band];for(const t of o)e.push({kind:"band",getTop:Ml(t.y1Accessor,"y1"),getBottom:Ml(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as Pl,scaleLog as Ll,scaleSymlog as $l,scaleTime as Rl}from"d3-scale";function Cl(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Tl(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return Ll().domain(t).range(o).clamp(!0)}return"symlog"===t?$l().domain(e).range(o):"time"===t?Rl().domain([new Date(e[0]),new Date(e[1])]).range(o):Pl().domain(e).range(o)}function Ol(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Il(t,e){const o=new U(t.capacity);return t.forEach(()=>o.push(e)),o}function zl(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function Fl(t,e,o){if(!e||0===e.size)return;const n=new Set;if(t.forEach((t,e)=>{o(t)&&n.add(e)}),0===n.size)return;const i=e.toArray();e.clear();for(let t=0;i.length>t;t++)n.has(t)||e.push(i[t])}var Nl=new WeakMap;function El(){return this.updateResults.last}function Dl(){return this.updateResults.last}function Wl(t){return this.updateResults.subscribe(t)}function Bl(t){this.config.layoutSelection=t}function jl(){Nl.set(this,!0)}function Yl(){const t=!0===Nl.get(this);return Nl.delete(this),t}function Xl(t){Object.assign(t.prototype,{getLastUpdateResult:El,getUpdateSnapshot:Dl,subscribeUpdateResult:Wl,setLayoutSelection:Bl,markStylePaintPending:jl,consumeStylePaintPending:Yl})}var Gl=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Vl=["scene-style","data-paint","accessibility","evidence"],Hl=(t,e)=>({retainedData:t,invalidations:e}),ql=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ul=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Kl=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zl=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ql=["scene-geometry","data-paint","accessibility","evidence"],Jl=["scene-style","data-paint","accessibility","evidence"],tc=[],ec={chartType:Hl("rebuild",ql),runtimeMode:Hl("rebuild",ql),xAccessor:Hl("rebuild",ql),yAccessor:Hl("rebuild",ql),timeAccessor:Hl("rebuild",ql),valueAccessor:Hl("rebuild",ql),y0Accessor:Hl("rebuild",ql),boundsAccessor:Hl("rebuild",ql),band:Hl("rebuild",ql),openAccessor:Hl("rebuild",ql),highAccessor:Hl("rebuild",ql),lowAccessor:Hl("rebuild",ql),closeAccessor:Hl("rebuild",ql),candlestickRangeMode:Hl("rebuild",ql),accessorRevision:Hl("rebuild",ql),groupAccessor:Hl("rebuild",Ul),categoryAccessor:Hl("rebuild",Ul),lineDataAccessor:Hl("rebuild",Ul),colorAccessor:Hl("rebuild",Jl),sizeAccessor:Hl("rebuild",Ql),symbolAccessor:Hl("rebuild",Ql),pointIdAccessor:Hl("rebuild",Ql),xScaleType:Hl("preserve",Kl),yScaleType:Hl("preserve",Kl),xExtent:Hl("preserve",Kl),yExtent:Hl("preserve",Kl),extentPadding:Hl("preserve",Kl),scalePadding:Hl("preserve",Kl),axisExtent:Hl("preserve",Kl),yAxisExtent:Hl("preserve",Kl),binSize:Hl("preserve",Kl),normalize:Hl("preserve",Kl),heatmapAggregation:Hl("preserve",Kl),heatmapXBins:Hl("preserve",Kl),heatmapYBins:Hl("preserve",Kl),arrowOfTime:Hl("preserve",Zl),baseline:Hl("preserve",Zl),stackOrder:Hl("preserve",Zl),sizeRange:Hl("preserve",Zl),curve:Hl("preserve",Zl),areaGroups:Hl("preserve",Zl),customLayout:Hl("preserve",Zl),layoutConfig:Hl("preserve",Zl),layoutMargin:Hl("preserve",Zl),symbolMap:Hl("preserve",Ql),showValues:Hl("preserve",Ql),heatmapValueFormat:Hl("preserve",Ql),lineStyle:Hl("preserve",Jl),pointStyle:Hl("preserve",Jl),areaStyle:Hl("preserve",Jl),barStyle:Hl("preserve",Jl),swarmStyle:Hl("preserve",Jl),waterfallStyle:Hl("preserve",Jl),candlestickStyle:Hl("preserve",Jl),boundsStyle:Hl("preserve",Jl),gradientFill:Hl("preserve",Jl),lineGradient:Hl("preserve",Jl),semanticLineStops:Hl("preserve",Jl),colorScheme:Hl("preserve",Jl),themeCategorical:Hl("preserve",Jl),themeSemantic:Hl("preserve",Jl),themeSequential:Hl("preserve",Jl),themeDiverging:Hl("preserve",Jl),barColors:Hl("preserve",Jl),decay:Hl("preserve",Jl),pulse:Hl("preserve",Jl),staleness:Hl("preserve",Jl),layoutSelection:Hl("preserve",Jl),annotations:Hl("preserve",["overlay","accessibility","evidence"]),windowSize:Hl("preserve",tc),windowMode:Hl("preserve",tc),maxCapacity:Hl("preserve",tc),clock:Hl("preserve",tc),transition:Hl("preserve",tc),introAnimation:Hl("preserve",tc),onLayoutError:Hl("preserve",tc)},oc=Hl("preserve",Zl),nc=class{constructor(){this.tracker=new o}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Gl)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Vl):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=ec[n]??oc;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as ic}from"d3-quadtree";var rc=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(t,e){if("scatter"!==t&&"bubble"!==t&&"custom"!==t)return void this.clear();let o=0,n=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(o++,t.r>n&&(n=t.r));if(this.maxRadius=n,500>=o)return void(this.tree=null);const i=Array(o);let r=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(i[r++]=t);this.tree=ic().x(t=>t.x).y(t=>t.y).addAll(i)}},sc=class t{constructor(t){if(this.xExtent=new q,this.yExtent=new q,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new nc,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.spatialIndex=new rc,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,o)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let l=!1;const c=i??(()=>{const t=new Map;for(let e=0;o.length>e;e++)t.set(o[e],e);return t})();for(const o of e){if("line"===o.type)continue;if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[o.datum];let i=0,a=!1;for(const o of e){const e=c.get(o);if(null==e)continue;a=!0;const s=n.get(e);if(null==s)continue;const l=Za(t,s,r);l>i&&(i=l)}a&&(l=Qa(o,i,s)||l);continue}const e=c.get(o.datum);if(null==e)continue;const i=n.get(e);l=Qa(o,null==i?0:Za(t,i,r),s,a)||l}return l}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new U(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=mt(t.timeAccessor||t.xAccessor,"time"),this.getY=mt(t.valueAccessor||t.yAccessor,"value")):(this.getX=mt(t.xAccessor,"x"),this.getY=mt(t.yAccessor,"y")),this.getGroup=wt(t.groupAccessor),this.getCategory=wt(t.categoryAccessor),this.getSize=t.sizeAccessor?mt(t.sizeAccessor,"size"):void 0,this.getColor=wt(t.colorAccessor),this.getSymbol=wt(t.symbolAccessor),this.getY0=t.y0Accessor?mt(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=_l(t),this.getPointId=wt(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?mt(t.openAccessor,"open"):void 0,this.getHigh=mt(t.highAccessor,"high"),this.getLow=mt(t.lowAccessor,"low"),this.getClose=o?mt(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new U(t.windowSize))}currentTime(){return this.config.clock?.()??qa()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Il(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(t)),void this.yExtent.push(this.getLow(t));this.yExtent.push(this.getY(t)),this.getY0&&this.yExtent.push(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.push(o),Number.isFinite(n)&&this.yExtent.push(n)}}evictDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(t)),void this.yExtent.evict(this.getLow(t));this.yExtent.evict(this.getY(t)),this.getY0&&this.yExtent.evict(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.evict(o),Number.isFinite(n)&&this.yExtent.evict(n)}}rebuildYExtent(){this.yExtent.clear();for(const t of this.buffer)this.pushDatumYExtent(t)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(const t of this.buffer)this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t)}ingest(t){if(t.bounded&&this._lastBoundedInsertsRef===t.inserts)return this.updateResults.recordNoop("replace"),!1;const e=this.currentTime();if(this.lastIngestTime=e,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,t.bounded){this._lastBoundedInsertsRef=t.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const o=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=o?mt(this.config.timeAccessor||this.config.xAccessor,"time"):mt(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],o=this.config.xAccessor,n="function"==typeof o?o(e):e[o||"x"],i=n instanceof Date,r="string"==typeof n&&Number.isFinite(lt(n));if(this.xIsDate=i||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>Z(e[t]):t=>Z(o(t))}}Ol(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)zl(this.buffer,o,this.timestampBuffer,e),this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o)}else for(const o of t.inserts){if("growing"===this.config.windowMode&&this.buffer.full){const t=this.config.maxCapacity??1e5;t>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,t),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"===process.env.NODE_ENV||this.growingCapacityWarned||5e4>this.growingCap||(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${t}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}const t=zl(this.buffer,o,this.timestampBuffer,e);this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o),null!=t&&(this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t))}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(o,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=Cl(this.xExtent.extent,e.xExtent),l=Cl(s,e.yExtent);const c=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===(e.yAxisExtent??e.axisExtent);if("stackedarea"===e.chartType&&!c&&o.size>0){const t=function(t){const{config:e,groups:o,getX:n,getY:i}=t,r="exact"===(e.yAxisExtent??e.axisExtent);if(e.normalize){const o=[0,r?1:1+e.extentPadding];return{yDomain:o,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:o}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,l=new Set;let c=0;const u=new Map,d=new Map;for(const t of o){const e=new Map;let o=0;for(const r of t.data){const t=n(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),l.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>c&&(c=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",p=(t,e)=>e>t?-1:t>e?1:0;let f,g;if("input"===h)f=o.map(t=>t.key);else if("insideOut"===h){const t=[...o].map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:p(t,e)}),e=[],n=[];let i=0,r=0;for(const o of t)r>i?(e.push(o),i+=d.get(o)??0):(n.push(o),r+=d.get(o)??0);f=[...n.reverse(),...e]}else f="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:p(t,e)}):"desc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:p(t,e)}):o.map(t=>t.key).sort(p);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),o=il(t,f,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let n=1/0,i=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;n>t&&(n=t),t+r>i&&(i=t+r)}Number.isFinite(n)&&Number.isFinite(i)||(n=0,i=0);const s=i-n,c=r?0:s>0?s*e.extentPadding:1;g=[n-c,i+c]}else if("diverging"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),[o,n]=function(t,e,o){let n=0,i=0;for(const r of t){let t=0,s=0;for(const n of e){const e=o(n,r)||0;0>e?s+=e:t+=e}n>s&&(n=s),t>i&&(i=t)}return[n,i]}(t,f,(t,e)=>a.get(t)?.get(e)||0),i=n-o,s=r?0:i>0?i*e.extentPadding:1;g=[o-s,n+s]}else g=[0,c+(r?0:c>0?c*e.extentPadding:1)];return{yDomain:g,stackExtentCache:{key:s,yDomain:g}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:o.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});l=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!c&&o.size>0?l=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=vl(t,e,o,n,i);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,o,n,i);return[0,s?a:a+a*r]}(o,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,d):"waterfall"===e.chartType&&!c&&o.size>0?l=function(t,e,o,n){const[i,r]=function(t,e){let o=0,n=0,i=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(i+=t,o>i&&(o=i),i>n&&(n=i))}return[o,n]}(t,e),s=r-i,a=n?0:s>0?s*o:1;return[Math.min(0,i-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(o,this.getY,e.extentPadding,d):c||l[0]===1/0||(l=function(t,e,o){if(!o.length)return t;let[n,i]=t;for(const t of e)for(const e of o){const o=e.getTop(t),r=e.getBottom(t);Number.isFinite(o)&&(n>o&&(n=o),o>i&&(i=o)),Number.isFinite(r)&&(n>r&&(n=r),r>i&&(i=r))}return[n,i]}(l,r,this.resolvedRibbons),l=function(t,e){const o=t[1]-t[0],n=e.exactMode?0:o>0?o*e.extentPadding:1,i=[null!=e.userMin?t[0]:t[0]-n,null!=e.userMax?t[1]:t[1]+n];return"log"!==e.yScaleType||i[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(i[0]=e.dataYDomain[0]/(1+e.extentPadding)),i}(l,{exactMode:d,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));l=function(t,e,o){if(!e||o)return t;const n=e[0],i=e[1];return null==n&&null==i?t:[null!=n?n:t[0],null!=i?i:t[1]]}(l,e.yExtent,!!c),({xDomain:a,yDomain:l}=function(t,e,o){let n=t,i=e;if(n[0]===1/0||n[1]===-1/0)if("time"===o){const t=Date.now();n=[t-864e5,t]}else n=[0,1];return i[0]!==1/0&&i[1]!==-1/0||(i=[0,1]),{xDomain:n,yDomain:i}}(a,l,e.xScaleType)),this.scales=function(t){const{config:e,layout:o,xDomain:n,yDomain:i}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(o.width,o.height)/2-1));if(r){const t="left"===e.arrowOfTime?[o.width-s,s]:[s,o.width-s];return{x:Pl().domain(n).range(t),y:Tl(e.yScaleType,i,[o.height-s,s])}}return{x:Tl(e.xScaleType,n,[s,o.width-s]),y:Tl(e.yScaleType,i,[o.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:l}),this._customLayoutFailedThisBuild=!1;const h=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.lastLayout=i):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=h,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:t.width,height:t.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(t){const e=t.width/this.lastLayout.width,o=t.height/this.lastLayout.height;for(const t of this.scene)switch(t.type){case"line":for(const n of t.path)n[0]*=e,n[1]*=o;break;case"area":for(const n of t.topPath)n[0]*=e,n[1]*=o;for(const n of t.bottomPath)n[0]*=e,n[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*o,width:t.clipRect.width*e,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(t=>({...t,y:t.y*o,height:t.height*o})));break;case"point":case"glyph":t.x*=e,t.y*=o;break;case"rect":case"heatcell":t.x*=e,t.y*=o,t.w*=e,t.h*=o;break;case"candlestick":t.x*=e,t.openY*=o,t.closeY*=o,t.highY*=o,t.lowY*=o}const n=this.scales.x.domain(),i=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=Tl,l=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),c=s[1]>s[0];this.scales={x:a(this.config.xScaleType,n,r[0]>r[1]?[t.width-l,l]:[l,t.width-l]),y:a(this.config.yScaleType,i,c?[l,t.height-l]:[t.height-l,l])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:o,scales:n}=this;if(!n)return[];if(o.customLayout){const i={data:e,scales:n,dimensions:{width:t.width,height:t.height,margin:o.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:o.themeCategorical??Jt},resolveColor:(t,e)=>{const n=this.resolveGroupColor(t);if(n)return n;const i=this.resolveLineStyle(t,e);return i.stroke?i.stroke:"string"==typeof i.fill?i.fill:o.themeSemantic?.primary??"#4e79a7"},config:o.layoutConfig??{},selection:o.layoutSelection??null};let r;try{r=o.customLayout(i)}catch(t){const e=null!==this.lastCustomLayoutResult,n=Sl("xy",t,e,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{o.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null;const s=r.nodes??[];if(this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of s)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(s,o.layoutSelection??null)}return wl({label:"customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const i={scales:n,config:o,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(t,e)=>this.resolveLineStyle(t,e),resolveAreaStyle:(t,e)=>this.resolveAreaStyle(t,e),resolveBoundsStyle:(t,e)=>this.resolveBoundsStyle(t,e),resolveColorMap:t=>this.resolveColorMap(t),resolveGroupColor:t=>this.resolveGroupColor(t),groupData:t=>this.groupData(t),barCategoryCache:this._barCategoryCache};switch(o.chartType){case"line":return function(t,e){const o=t.groupData(e),n=[],i=t.config.annotations?.filter(gl).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=ol(e.data,t.scales,t.getX,t.getY,o,e.key);i&&i.length>0&&(r.colorThresholds=i),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),n.push(r)}return fl(t,o,n),n}(i,e);case"area":return function(t,e){const o=t.groupData(e),n=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}const i=t.scales.y.domain(),r=i[0],s=t.config.semanticLineStops?.filter(t=>Number.isFinite(t.offset)).map(t=>({value:i[0]+Math.max(0,Math.min(1,t.offset))*(i[1]-i[0]),color:t.color,opacity:t.opacity,thresholdType:"greater"})).sort((t,e)=>t.value-e.value),a=s&&s.length>0?(()=>{const e=s.reduce((t,e)=>(t.at(-1)?.value===e.value?t[t.length-1]=e:t.push(e),t),[]),o=[{from:i[0],to:e[0].value,color:e[0].color,opacity:e[0].opacity}];for(let t=0;e.length>t;t++)o.push({from:e[t].value,to:e[t+1]?.value??i[1],color:e[t].color,opacity:e[t].opacity});return o.map(({from:e,to:o,color:n,opacity:i})=>{const r=t.scales.y(e),s=t.scales.y(o);return{y:Math.min(r,s),height:Math.abs(s-r),color:n,...null!=i&&{opacity:i}}}).filter(t=>t.height>0)})():void 0,l=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o){const o=t.resolveAreaStyle(e.key,e.data[0]),i=nl(e.data,t.scales,t.getX,t.getY,r,o,e.key,l),c=yl(t.config.gradientFill);c&&(i.fillGradient=c),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),s&&s.length>0&&(i.colorThresholds=s,i.strokeColorBands=a),n.push(i)}return fl(t,o,n),n}(i,e);case"mixed":return function(t,e){const o=t.groupData(e),n=[],i=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o)if(i.has(e.key)){const o=t.resolveAreaStyle(e.key,e.data[0]),i=nl(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=yl(t.config.gradientFill);a&&(i.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}else{const o=t.resolveLineStyle(e.key,e.data[0]),i=ol(e.data,t.scales,t.getX,t.getY,o,e.key);t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}return fl(t,o,n),n}(i,e);case"stackedarea":return function(t,e){const o=t.groupData(e),n=t.config.stackOrder??"key",i=()=>o.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===n);else if("key"===n)i();else if("asc"===n||"desc"===n||"insideOut"===n){const e=new Map;for(const n of o){let o=0;for(const e of n.data){const n=t.getX(e),i=t.getY(e);Number.isFinite(n)&&Number.isFinite(i)&&(o+=i)}e.set(n.key,o)}const i=(t,e)=>e>t?-1:t>e?1:0;if("asc"===n)o.sort((t,o)=>{const n=(e.get(t.key)??0)-(e.get(o.key)??0);return 0!==n?n:i(t.key,o.key)});else if("desc"===n)o.sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)});else{const t=[...o].sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)}),n=[],r=[];let s=0,a=0;for(const o of t)a>s?(n.push(o),s+=e.get(o.key)??0):(r.push(o),a+=e.get(o.key)??0);o.length=0,o.push(...r.reverse(),...n)}}else i();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:l}=function(t,e,o,n,i,r,s,a="zero"){const l=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&l.add(e)}const c=Array.from(l).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const i of e.data){const e=o(i),r=n(i);Number.isFinite(e)&&Number.isFinite(r)&&t.set(e,(t.get(e)||0)+r)}u.set(e.key,t)}let d;if(r){d=new Map;for(const e of c){let o=0;for(const n of t)o+=u.get(n.key)?.get(e)||0;d.set(e,o||1)}}const h=il(c,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),p="diverging"===a&&!r,f=[],g=new Map,y=new Map,m=new Map,x=new Map;for(const t of c)y.set(t,h.get(t)??0),m.set(t,0),x.set(t,0);for(const o of t){const t=u.get(o.key),n=new Map;let a=[],l=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:l,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),f.push(t)}a=[],l=[]};for(const o of c){const i=t.has(o);let s,c,u=i?t.get(o):0;if(r&&i&&(u/=d.get(o)),!i||!Number.isFinite(u)||0===u){h();continue}p?u>0?(s=m.get(o),c=s+u,m.set(o,c)):(s=x.get(o),c=s+u,x.set(o,c)):(s=y.get(o),c=s+u,y.set(o,c));const f=e.x(o);l.push([f,e.y(s)]),a.push([f,e.y(c)]),n.set(o,c)}h(),g.set(o.key,n)}return{nodes:f,stackedTops:g}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),c=a;if(t.config.pointStyle){const e=new WeakMap;for(const n of o){const o=l.get(n.key);if(o)for(const i of n.data){const n=t.getX(i),r=t.getY(i);null==n||Number.isNaN(n)||null==r||Number.isNaN(r)||!o.has(n)||e.set(i,o.get(n))}}const n=o=>e.get(o)??t.getY(o);fl(t,o,c,n)}return c}(i,e);case"scatter":case"bubble":return function(t,e){const o=[],n="bubble"===t.config.chartType?10:5,i=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const o=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(o.length>0){let t=1/0,e=-1/0;for(const n of o)t>n&&(t=n),n>e&&(e=n);r=o=>t===e?(i[0]+i[1])/2:i[0]+(o-t)/(e-t)*(i[1]-i[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",l=t.getSymbol,c=l?_(l,t.config.symbolMap):null;for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},l=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(l=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(i);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(i)+"":void 0;if(c){const n=c(i),r=sl(i,t.scales,t.getX,t.getY,Math.PI*l*l,n,e,u);r&&o.push(r)}else{const n=rl(i,t.scales,t.getX,t.getY,l,e,u);n&&o.push(n)}}return o}(i,e);case"heatmap":return function(t,e,o){if(t.config.heatmapAggregation)return function(t,e,o){const n=Math.max(1,Math.floor(t.config.heatmapXBins??20)),i=Math.max(1,Math.floor(t.config.heatmapYBins??20)),r=t.config.heatmapAggregation??"count",s=mt(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,l]=t.scales.x.domain(),[c,u]=t.scales.y.domain(),d=(l-a||1)/n,h=(u-c||1)/i,p=n*i;if(p>1e6)return[];const f=new Int32Array(p),g=new Float64Array(p);for(let o=0;e.length>o;o++){const r=e[o],l=t.getX(r),u=t.getY(r);if(!isFinite(l)||!isFinite(u))continue;const p=Math.min(Math.floor((l-a)/d),n-1),y=Math.min(Math.floor((u-c)/h),i-1);if(0>p||0>y)continue;const m=y*n+p;f[m]++;const x=s(r);g[m]+=isFinite(x)?x:0}let y=1/0,m=-1/0;for(let t=0;p>t;t++){if(0===f[t])continue;let e;switch(r){case"sum":e=g[t];break;case"mean":e=g[t]/f[t];break;default:e=f[t]}y>e&&(y=e),e>m&&(m=e)}if(!isFinite(y))return[];const x=m-y||1,b=t.config.heatmapColorScale,v=b?void 0:xl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),w=255/x,k=o.width/n,A=o.height/i,S=t.config.showValues,M=t.config.heatmapValueFormat,_=[];for(let e=0;i>e;e++){const o=e*n;for(let s=0;n>s;s++){const n=o+s;if(0===f[n])continue;let l;switch(r){case"sum":l=g[n];break;case"mean":l=g[n]/f[n];break;default:l=f[n]}const u=Math.min((l-y)*w+.5|0,255),p=b?b(l):v[u],m={xi:s,yi:e,value:l,count:f[n],sum:g[n],xCenter:a+(s+.5)*d,yCenter:c+(e+.5)*h,agg:r};_.push(bl(ll(s*k,(i-1-e)*A,k,A,p,m,S?{value:l,showValues:!0,valueFormat:M}:{value:l}),m,t))}}return _}(t,e,o);if(0===e.length)return[];const n=mt(t.config.valueAccessor,"value"),i=vt(t.config.xAccessor,"x"),r=vt(t.config.yAccessor,"y"),s=new Map,a=new Map,l=Array(e.length),c=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],n=i(o),u=r(o);l[t]=n,c[t]=u,s.has(n)||s.set(n,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),p=Array.from(a.keys()),f=h.every(t=>"number"==typeof t&&!isNaN(t)),g=p.every(t=>"number"==typeof t&&!isNaN(t));if(f){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(g){p.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;p.length>t;t++)a.set(p[t],t)}const y=new Float64Array(e.length),m=new Float64Array(e.length),x=Array(e.length),b=new Map;let v=0;for(let t=0;e.length>t;t++){const o=e[t],i=s.get(l[t]),r=a.get(c[t]);if(void 0===i||void 0===r)continue;const d=n(o),h=r*u+i,p=b.get(h);let f;void 0!==p?f=p:(f=v++,b.set(h,f)),y[f]=h,m[f]=d,x[f]=o}let w=1/0,k=-1/0;for(let t=0;v>t;t++){const e=m[t];isFinite(e)&&(w>e&&(w=e),e>k&&(k=e))}if(!isFinite(w)||!isFinite(k))return[];const A=t.config.heatmapColorScale,S=A?void 0:xl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),M=255/(k-w||1),_=o.width/u,P=o.height/d,L=t.config.showValues,$=t.config.heatmapValueFormat,R=[];for(let e=0;v>e;e++){const o=m[e];if(!isFinite(o))continue;const n=y[e],i=n%u,r=(n-i)/u,s=Math.min((o-w)*M+.5|0,255),a=A?A(o):S[s],l=x[e];R.push(bl(ll(i*_,(d-1-r)*P,_,P,a,l,L?{value:o,showValues:!0,valueFormat:$}:{value:o}),l,t))}return R}(i,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=vl(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===o.size)return{nodes:[],binBoundaries:[]};let n=null;if(t.getCategory){const e=new Set;for(const t of o.values())for(const o of t.categories.keys())e.add(o);const i=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(i),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=i.filter(t=>e.has(t)),l=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===l?n=t.barCategoryCache.order:(n=[...a,...s],t.barCategoryCache={key:l,order:n})}const i=[],r=t.scales,[s,a]=r.x.domain(),l=t.config.barStyle,c=t.config.themeSemantic?.primary,u=l?.gap,d="number"!=typeof u||0>u?1:u,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.cursor);for(const e of o.values()){const o=Math.max(e.start,s),u=Math.min(e.end,a);if(o>=u)continue;const p=r.x(o),f=r.x(u),g=Math.abs(f-p),y=g>d+1?d:0,m=Math.min(p,f)+y/2,x=Math.max(g-y,1);if(x>0)if(n&&e.categories.size>0){let o=0;for(const s of n){const n=e.categories.get(s)||0;if(0===n)continue;const a=r.y(o),u=r.y(o+n),d=Math.min(a,u),p=Math.abs(a-u),f=(t.config.barColors?ne(t.config.barColors,s):void 0)??l?.fill??c??"#4e79a7",g={binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},y=t.config.areaStyle?.(g)??{};i.push(al(m,d,x,p,{fill:f,...h,...y},g,s)),o+=n}}else{const o=r.y(0),n=r.y(e.total),s=Math.min(o,n),a=Math.abs(o-n),u=l?.fill||c||"#007bff",d={binStart:e.start,binEnd:e.end,total:e.total},p=t.config.areaStyle?.(d)??{};i.push(al(m,s,x,a,{fill:u,...h,...p},d))}}const p=new Set;for(const t of o.values())p.add(t.start),p.add(t.end);return{nodes:i,binBoundaries:Array.from(p).sort((t,e)=>t-e)}}(i,e);return this._barCategoryCache=i.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return function(t,e){const o=[],n=t.config.swarmStyle||{},i=n.radius??3,r=n.fill??t.config.themeSemantic?.primary??"#007bff",s=n.opacity??.7,a=n.stroke,l=n.strokeWidth,c=n.cursor;for(const n of e){const e=t.getX(n),u=t.getY(n);if(null==u||Number.isNaN(u))continue;const d=t.scales.x(e),h=t.scales.y(u);let p=r;if(t.getCategory){const e=t.getCategory(n)+"";p=(t.config.barColors?ne(t.config.barColors,e):void 0)??p}const{r:f,...g}=t.config.pointStyle?.(n)??{},y={type:"point",x:d,y:h,r:f??i,style:{fill:p,opacity:s,stroke:a,strokeWidth:l,cursor:c,...g},datum:n};t.getPointId&&(y.pointId=t.getPointId(n)+""),o.push(y)}return o}(i,e);case"waterfall":return function(t,e,o){const n=[],i=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const o=t.getY(e),n=t.getX(e);return null!=o&&!Number.isNaN(o)&&null!=n&&isFinite(n)});if(0===s.length)return n;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",l=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",c=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let p=0;for(let e=0;s.length>e;e++){const f=s[e],g=t.getX(f),y=t.getY(f),m=p+y;let x;x=s.length-1>e?t.getX(s[e+1])-g:e>0?g-t.getX(s[e-1]):0;const b=i.x(g),v=0!==x?i.x(g+x):b+o.width/10,w=Math.min(b,v)+c/2,k=Math.max(b,v)-c/2-w;if(0>=k){p=m;continue}const A=i.y(p),S=i.y(m),M=Math.min(A,S),_=Math.abs(A-S),P=0>y?l:a,L={...f,baseline:p,cumEnd:m,delta:y,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},$={fill:P,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(L)};n.push(al(w,M,k,_,$,L)),p=m}return n}(i,e,t);case"candlestick":return function(t,e,o){if(!t.getHigh||!t.getLow||!t.scales)return[];const n=t.config.candlestickRangeMode??!1;if(!(n||t.getOpen&&t.getClose))return[];const i=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=n?s:r.upColor||"#28a745",l=n?s:r.downColor||"#dc3545",c=n?s:r.wickColor||"#333",u=r.wickWidth||(n?2:1),d=e.map(e=>t.getX(e)).filter(t=>null!=t&&!Number.isNaN(t)).sort((t,e)=>t-e);let h=r.bodyWidth??0;if(null==r.bodyWidth)if(d.length>1){let e=1/0;for(let o=1;d.length>o;o++){const n=Math.abs(t.scales.x(d[o])-t.scales.x(d[o-1]));n>0&&e>n&&(e=n)}h=e!==1/0?Math.max(2,Math.min(.6*e,20)):6}else h=6;for(const s of e){const e=t.getX(s);if(null==e||Number.isNaN(e))continue;const d=t.getHigh(s),p=t.getLow(s);if(null==d||Number.isNaN(d)||null==p||Number.isNaN(p))continue;const f=n?d:t.getOpen(s),g=n?p:t.getClose(s);if(!n&&[f,g].some(t=>null==t||Number.isNaN(t)))continue;const y=g>=f,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(f),closeY:t.scales.y(g),highY:t.scales.y(d),lowY:t.scales.y(p),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:y,style:{cursor:r.cursor},datum:s};n&&(m.isRange=!0,m.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),i.push(m)}return i}(i,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,o,n){const i=t.boundsStyle;if("function"==typeof i)return i(o||{},e);if(i&&"object"==typeof i)return i;const r=n(e,o);return{fill:r.stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none",cursor:r.cursor}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Ua(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=Ka(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=Ka(o)){const i=o.length;if(i>1)for(const o of e){if("line"===o.type){const e=Array.isArray(o.datum)?o.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let o=0;e.length>o;o++){const a=n.get(e[o]);null!=a?(r[o]=Ua(t,a,i),1>r[o]&&(s=!0)):r[o]=1}s&&(o._decayOpacities=r);continue}if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[],r=o.topPath?o.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let o=0;e.length>o;o++){const r=n.get(e[o]);null!=r?(s[o]=Ua(t,r,i),1>s[o]&&(a=!0)):s[o]=1}a&&(o._decayOpacities=s)}else{let s=1;for(const o of e){const e=n.get(o);if(null!=e){const o=Ua(t,e,i);s>o&&(s=o)}}if(1>s){const t=Array(r);t.fill(s),o._decayOpacities=t}}continue}const e=n.get(o.datum);if(null==e)continue;const r=Ua(t,e,i);"candlestick"===o.type?o._decayOpacity=r:o.style={...o.style,opacity:(o.style?.opacity??1)*r}}}(this.config.decay,t,e,this.getDatumIndexMap(e))}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory}}snapshotPositions(){!function(t,e,o,n){o.clear(),n.clear();for(let i=0;e.length>i;i++){const r=e[i],s=tl(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:el(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:el(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:el(r.style)}):"candlestick"===r.type?o.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:el(r.style)}):"line"===r.type?n.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&n.set(s,{topPath:r.topPath.map(t=>[t[0],t[1]]),bottomPath:r.bottomPath.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();const t=this.scales?.y(0)??0;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=tl(this.transitionContext,o,e);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:0,opacity:0}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:t,w:o.w,h:0,opacity:o.style.opacity??1}):"heatcell"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:0}):"line"===o.type?(o._introClipFraction=0,this.prevPathMap.set(n,{path:o.path.map(t=>[t[0],t[1]]),opacity:o.style.opacity})):"area"===o.type&&(o._introClipFraction=0,this.prevPathMap.set(n,{topPath:o.topPath.map(t=>[t[0],t[1]]),bottomPath:o.bottomPath.map(t=>[t[0],t[1]]),opacity:o.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,o,n,i,r=qa()){if(0===n.size&&0===i.size)return o;const s=e.duration??300;if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}let a=!1;const l=new Set,c=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=tl(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(c.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=n.get(s);if("point"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){l.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=el(r.style),(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!c.has(t))if(t.startsWith("l:")&&e.path){const n={type:"line",path:e.path.map(t=>[t[0],t[1]]),group:t.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(n),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const n={type:"area",topPath:e.topPath.map(t=>[t[0],t[1]]),bottomPath:e.bottomPath.map(t=>[t[0],t[1]]),group:t.slice(2),style:{fill:"#999",opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(n),a=!0}for(const[t,e]of n)if(!l.has(t)){if(t.startsWith("p:"))o.exitNodes.push({type:"point",x:e.x,y:e.y,r:e.r??3,style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("g:")&&e.glyph)o.exitNodes.push({type:"glyph",x:e.x,y:e.y,size:e.r??12,glyph:e.glyph,color:"#999",accent:"#999",style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))o.exitNodes.push({type:"rect",x:e.x,y:e.y,w:e.w??0,h:e.h??0,style:{opacity:e.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("h:"))o.exitNodes.push({type:"heatcell",x:e.x,y:e.y,w:e.w??0,h:e.h??0,fill:"#999",datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t});else if(t.startsWith("c:")){const n=e.openY??e.y;o.exitNodes.push({type:"candlestick",x:e.x,openY:n,closeY:e.closeY??n,highY:e.highY??n,lowY:e.lowY??n,bodyWidth:e.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t})}a=!0}return o.exitNodes.length>0&&(o.scene=[...o.scene,...o.exitNodes]),a&&(o.activeTransition={startTime:r,duration:s}),o}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(t){if(!this.activeTransition||!this.config.transition)return!1;const e={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},o=function(t,e,o,n){if(!o.activeTransition)return!1;const i=Va(t,o.activeTransition),r=Ga(i,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of o.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Ha(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Ha(o.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Ha(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Ha(o.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Ha(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==o.w&&(t.w=Ha(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Ha(o.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Ha(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==o.w&&(t.w=Ha(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Ha(o.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Ha(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Ha(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Ha(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Ha(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Ha(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ha(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,o=t._targetPath;if(e&&o&&e.length===t.path.length)for(let n=0;t.path.length>n;n++)t.path[n][0]=Ha(e[n][0],o[n][0],r),t.path[n][1]=Ha(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ha(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,o=t._prevBottomPath,n=t._targetTopPath,i=t._targetBottomPath;if(e&&n&&e.length===t.topPath.length)for(let o=0;t.topPath.length>o;o++)t.topPath[o][0]=Ha(e[o][0],n[o][0],r),t.topPath[o][1]=Ha(e[o][1],n[o][1],r);if(o&&i&&o.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=Ha(o[e][0],i[e][0],r),t.bottomPath[e][1]=Ha(o[e][1],i[e][1],r)}}if(i>=1){for(const t of o.scene){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style="line"===t.type||"area"===t.type?{...t.style,opacity:0===e?0:e}:{...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("glyph"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("heatcell"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("candlestick"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0}else if("line"===t.type){const e=t._targetPath;if(e)for(let o=0;t.path.length>o;o++)t.path[o]=e[o];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,o=t._targetBottomPath;if(e)for(let o=0;t.topPath.length>o;o++)t.topPath[o]=e[o];if(o)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=o[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}return o.activeTransition=null,!1}return!0}(t,this.config.transition,e,this.prevPositionMap);return this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition,o}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("glyph"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("rect"===e.type||"heatcell"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0);else if("candlestick"===e.type)void 0!==e._targetX&&(e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0);else if("line"===e.type||"area"===e.type){if(e._introClipFraction=void 0,"line"===e.type&&e._targetPath){for(let t=0;e.path.length>t;t++)e.path[t]=e._targetPath[t];e._prevPath=void 0,e._targetPath=void 0}if("area"===e.type){if(e._targetTopPath)for(let t=0;e.topPath.length>t;t++)e.topPath[t]=e._targetTopPath[t];if(e._targetBottomPath)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=e._targetBottomPath[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(t){const{result:e,cache:o}=function(t,e,o,n){if(n&&n.version===o&&n.group===e&&n.data===t)return{result:n.result,cache:n};let i;if(e){const o=new Map;for(const n of t){const t=e(n);o.has(t)||o.set(t,[]),o.get(t).push(n)}i=Array.from(o.entries()).map(([t,e])=>({key:t,data:e}))}else i=[{key:"_default",data:t}];return{result:i,cache:{version:o,group:e,data:t,result:i}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=o,e}resolveColorMap(t){const{map:e,cache:o}=function(t,e,o,n,i){if(i&&i.version===n)return{map:i.map,cache:i};const r=new Set;if(e)for(const o of t){const t=e(o);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(i&&i.key===a){const t={...i,version:n};return{map:t.map,cache:t}}const l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||Jt,c=new Map;for(let t=0;s.length>t;t++)c.set(s[t],l[t%l.length]);return{map:c,cache:{key:a,map:c,version:n}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=o,e}resolveLineStyle(t,e){return function(t,e,o,n){const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.stroke&&e){const o=n(e);if(o)return{...t,stroke:o}}return t}const r=t.themeSemantic?.primary;return i&&"object"==typeof i?{stroke:i.stroke||r||"#007bff",strokeWidth:i.strokeWidth??2,strokeDasharray:i.strokeDasharray,fill:i.fill,fillOpacity:i.fillOpacity,opacity:i.opacity,cursor:i.cursor}:{stroke:n(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,o,n){if(t.areaStyle){const i=t.areaStyle(o||{});if(i&&!i.fill&&e){const t=n(e);if(t)return{...i,fill:t,stroke:i.stroke||t}}return i}const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.fill&&e){const o=n(e);if(o)return{...t,fill:o,stroke:t.stroke||o}}return t}const r=t.themeSemantic?.primary;if(i&&"object"==typeof i)return{fill:i.fill||i.stroke||r||"#4e79a7",fillOpacity:i.fillOpacity??.7,stroke:i.stroke||r||"#4e79a7",strokeWidth:i.strokeWidth??2,cursor:i.cursor};const s=n(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(e){const{color:o,groupColorCounter:n}=function(t){const{group:e,colorMapCache:o,groupColorMap:n,groupColorMapCap:i,config:r}=t;let{groupColorCounter:s}=t;if(o){const t=o.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=n.get(e);if(a)return{color:a,groupColorCounter:s};const l=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||Jt;if(0===l.length)return{color:null,groupColorCounter:s};const c=l[s%l.length];if(s++,n.set(e,c),n.size>i){const t=n.keys().next().value;void 0!==t&&n.delete(t)}return{color:c,groupColorCounter:s}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:t.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=n,o}getBufferArray(){return!this._bufferDirty&&this._bufferArrayCache||(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(t){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Xa(t),o=this.getPointId,n=t=>e.has(o(t));Fl(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const o=Xa(t),n=this.getPointId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.buffer.forEach((t,e)=>{i.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t||"themeCategorical"in t||"colorAccessor"in t)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in t||"colorScheme"in t)&&(this._barCategoryCache=null),("normalize"in t||"extentPadding"in t||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t||"boundsAccessor"in t||"band"in t||"y0Accessor"in t||"openAccessor"in t||"highAccessor"in t||"lowAccessor"in t||"closeAccessor"in t||"groupAccessor"in t||"categoryAccessor"in t||"chartType"in t||"runtimeMode"in t)&&(this._stackExtentCache=null);let n=!1,i=!1;Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();const r="chartType"in t&&t.chartType!==e.chartType||"runtimeMode"in t&&t.runtimeMode!==e.runtimeMode;if(r||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t){const t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,o=t&&this.config.valueAccessor||this.config.yAccessor,s=t&&e.valueAccessor||e.yAccessor,a=r||!yt(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),l=r||!yt(o,s);(a||l)&&(t?(this.getX=mt(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=mt(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=mt(this.config.xAccessor,"x"),this.getY=mt(this.config.yAccessor,"y")),l&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=_l(this.config)),n=!0,i=!0)}if("groupAccessor"in t&&!yt(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?wt(this.config.groupAccessor):void 0,n=!0),"categoryAccessor"in t&&!yt(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?wt(this.config.categoryAccessor):void 0,n=!0),"sizeAccessor"in t&&!yt(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?mt(this.config.sizeAccessor,"size"):void 0,n=!0),"symbolAccessor"in t&&!yt(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?wt(this.config.symbolAccessor):void 0,n=!0),"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?wt(this.config.colorAccessor):void 0,n=!0),"y0Accessor"in t&&!yt(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?mt(this.config.y0Accessor,"y0"):void 0,n=!0,i=!0),("boundsAccessor"in t&&!yt(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=_l(this.config),n=!0,i=!0),"pointIdAccessor"in t&&!yt(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?wt(this.config.pointIdAccessor):void 0,n=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!yt(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!yt(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!yt(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!yt(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?mt(this.config.openAccessor,"open"):void 0,this.getHigh=mt(this.config.highAccessor,"high"),this.getLow=mt(this.config.lowAccessor,"low"),this.getClose=e?mt(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,n=!0,i=!0}if("accessorRevision"in t&&t.accessorRevision!==e.accessorRevision&&(n=!0,i=!0),!n){const o=Object.keys(t).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const i of o)if(t[i]!==e[i]){n=!0;break}}n&&(i&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};sc.GROUP_COLOR_MAP_CAP=1e3;var ac=sc;Xl(ac);import*as lc from"react";import{area as cc,line as uc}from"d3-shape";function dc(t,e,o){let n=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(n=o.color):t>o.value&&(n=o.color);return n}import{jsx as hc,jsxs as pc}from"react/jsx-runtime";var fc={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function gc(t,e="#4e79a7"){return ot(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function yc(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function mc(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=g(i,t.size);if(0>=r.scale)return null;const s=`translate(${e},${o})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),l=p(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),c=l?yc(n+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>i.parts.map((o,n)=>{const i=e?"none"===o.fill?void 0:e:N(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:N(o.stroke??"none",a,t.accent);return i||r?hc("path",{d:o.d,fill:i??"none",stroke:r,strokeWidth:r?o.strokeWidth??1:void 0,strokeLinecap:o.strokeLinecap,strokeLinejoin:o.strokeLinejoin,opacity:o.opacity},n):null});return pc("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&hc("clipPath",{id:c,children:hc("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&t.ghostColor?hc("g",{children:d(t.ghostColor)}):null,l&&c?hc("g",{clipPath:`url(#${c})`,children:d()}):d()]},n)}function xc(t,e){const o=t.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity))).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color??e,opacity:null==t.opacity?void 0:Math.max(0,Math.min(1,t.opacity))}));return 2>o.length?null:o.map((t,e)=>hc("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function bc(t,e,o){const n=X(t.symbolType,t.size,t.path);return hc("path",{d:n,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?gc(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${o??""}symbol-${e}`)}import*as vc from"react";import{jsx as wc}from"react/jsx-runtime";function kc(t){if(!1!==t?.interactive)return t?.style?.cursor}function Ac(t,e,o){const n=kc(e);return n&&null!=t&&!1!==t?wc("g",{style:{cursor:n},"data-semiotic-mark-cursor":n,children:t},o):t}import*as Sc from"react";import{arc as Mc}from"d3-shape";import{jsx as _c,jsxs as Pc}from"react/jsx-runtime";import*as Lc from"react";import{jsx as $c,jsxs as Rc}from"react/jsx-runtime";import*as Cc from"react";import{arc as Tc}from"d3-shape";var Oc=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function Ic(t){const{innerRadius:e,outerRadius:o,startAngle:n,endAngle:i}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=Oc(o,n),e=Oc(o,i);return`M0,0 L${t.x},${t.y} A${o},${o} 0 ${i-n>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=Oc(o,n),s=Oc(o,i),a=Oc(e,i),l=Oc(e,n),c=i-n>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${c} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${c} 0 ${l.x},${l.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return Ic({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),l=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),c=i-n,u=t.roundStart&&t.roundEnd?c/2:c,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return Ic({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const p=n+(d?a:0),f=i-(h?a:0),g=n+(d?l:0),y=i-(h?l:0),m=Oc(o,p),x=Oc(o,f),b=(o-s)*Math.cos(a),v=Oc(b,n),w=Oc(b,i),k=r?null:Oc(e,y),A=r?null:Oc(e,g),S=r?0:(e+s)*Math.cos(l),M=r?null:Oc(S,n),_=r?null:Oc(S,i),P=f-p>Math.PI?1:0,L=r?0:y-g>Math.PI?1:0;let $="";if(d)$+=`M${v.x},${v.y}`,$+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=Oc(o,n);$+=`M${t.x},${t.y}`}if(h)$+=` A${o},${o} 0 ${P} 1 ${x.x},${x.y}`,$+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=Oc(o,i);$+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)$+=" L0,0";else{if(h)$+=` L${_.x},${_.y}`,$+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=Oc(e,i);$+=` L${t.x},${t.y}`}if(d)$+=` A${e},${e} 0 ${L} 0 ${A.x},${A.y}`,$+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=Oc(e,n);$+=` A${e},${e} 0 ${L} 0 ${t.x},${t.y}`}}return $+=" Z",$}import{jsx as zc,jsxs as Fc}from"react/jsx-runtime";function Nc(t){return 1e6>t?1e4>t?1e3>t?t+"":(t/1e3).toFixed(1)+"K":(t/1e3).toFixed(0)+"K":(t/1e6).toFixed(1)+"M"}function Ec(t,e){const o=t.datum;if(!o)return null;const n=[],i=o.__funnelStepLabel,r=Number(o.__funnelStepLabelX),s=Number(o.__funnelStepLabelY),a=Number(o.__funnelRowWidth);"string"!=typeof i||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*i.length+16>a||n.push(zc("text",{x:r,y:s+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-step"));const l=Number(o.__funnelValue),c=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let i=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${Nc(l)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:Nc(l);7.8*i.length+16>d&&(i=Nc(l)),7.8*i.length+16>d||n.push(zc("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-value"))}return n.length?zc("g",{children:n},e+"-funnel-labels"):null}function Dc(t,e,o){return Ac(function(t,e,o){const n=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",i=o=>`ord-${t.type}-${n}-${e}-${o}`,r=`ord-${t.type}-${n}-${e}`;switch(t.type){case"rect":{const e=t,o=yc(r)+"-grad",n=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=t.x,i=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(i=t.y+t.h,s=t.y):"right"===t.roundedEdge?(n=t.x+t.w,i=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(n=t.x,i=t.y,r=t.x+t.w,s=t.y);const a=xc(o.stops,gc(t.style.fill));return a?hc("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:n,y1:i,x2:r,y2:s,children:a}):null}(e,o);let i,a;if(n)a=`url(#${o})`;else if(ot(e.style.fill)){const t=yc(r)+"-hatch";i=et(e.style.fill,t),a=`url(#${t})`}else a=gc(e.style.fill);const l=n||i?Fc("defs",{children:[n,i]}):null;if(e.cornerRadii&&(((s=e.cornerRadii).tl??0)>0||(s.tr??0)>0||(s.br??0)>0||(s.bl??0)>0)){const t=function(t){const{x:e,y:o,w:n,h:i}=t,{tl:r,tr:s,br:a,bl:l}=function(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const o=Math.min(t.w,t.h)/2,n=t=>Math.max(0,Math.min(t??0,o));return{tl:n(e.tl),tr:n(e.tr),br:n(e.br),bl:n(e.bl)}}(t);let c=`M${e+r},${o}`;return c+=` L${e+n-s},${o}`,s>0&&(c+=` A${s},${s} 0 0 1 ${e+n},${o+s}`),c+=` L${e+n},${o+i-a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${e+n-a},${o+i}`),c+=` L${e+l},${o+i}`,l>0&&(c+=` A${l},${l} 0 0 1 ${e},${o+i-l}`),c+=` L${e},${o+r}`,r>0&&(c+=` A${r},${r} 0 0 1 ${e+r},${o}`),c+=" Z",c}(e);return Fc(Cc.Fragment,{children:[l,zc("path",{d:t,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:o,y:n,w:i,h:s}=e;let c;switch(e.roundedEdge){case"right":c=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+s-t} A${t},${t} 0 0 1 ${o+i-t},${n+s} L${o},${n+s} Z`;break;case"left":c=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+s-t} A${t},${t} 0 0 0 ${o+t},${n+s} L${o+i},${n+s} Z`;break;case"bottom":c=`M${o},${n} L${o+i},${n} L${o+i},${n+s-t} A${t},${t} 0 0 1 ${o+i-t},${n+s} L${o+t},${n+s} A${t},${t} 0 0 1 ${o},${n+s-t} Z`;break;default:c=`M${o},${n+s} L${o},${n+t} A${t},${t} 0 0 1 ${o+t},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+s} Z`}return Fc(Cc.Fragment,{children:[l,zc("path",{d:c,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return Fc(Cc.Fragment,{children:[l,zc("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),Ec(e,r)]},r)}case"point":{const e=t;return zc("circle",{cx:e.x,cy:e.y,r:e.r,fill:gc(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return bc(t,e,o);case"glyph":return mc(t,t.x,t.y,`${o??""}ord-glyph-${t.pointId??e}`);case"wedge":{const n=t;if(n._gradientBand&&n._gradientBand.colors.length>0){const t=yc(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=Ic({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),o=[],n=t.colors;if(n.length>0){const e=(t.endAngle-t.startAngle)/n.length;for(let i=0;n.length>i;i++)o.push({d:Ic({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+i*e,endAngle:t.endAngle}),color:n[i]})}return{clipPath:e,slices:o}}({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});return Fc("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[zc("defs",{children:zc("clipPath",{id:t,children:zc("path",{d:i})})}),zc("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>zc("path",{d:t.d,fill:gc(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&zc("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=Ic({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{const t=Tc().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&t.cornerRadius(n.cornerRadius),i=t(fc)||""}return zc("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:gc(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n.style.opacity},r)}case"boxplot":{const e=t,o=e.columnWidth/2,n=e.style.strokeWidth??1;return Fc("g","vertical"===e.projection?{children:[zc("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*n}),zc("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n})]}:{children:[zc("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*n}),zc("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n})]},r)}case"violin":{const e=t,o=[zc("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth??1},i("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,n=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?o.push(zc("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),zc("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(zc("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),zc("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return zc("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?gc(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return zc("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||o,strokeWidth:e.style.strokeWidth??1,opacity:e.style.opacity??.5},r)}case"trapezoid":{const e=t,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return zc("polygon",{points:o,fill:gc(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}var s}(t,e,o),t,"ordinal-cursor-"+e)}import{jsx as Wc,jsxs as Bc}from"react/jsx-runtime";function jc(t,e,o,n){if(!t||2>e.length)return null;const i=xc(t.stops,n);return i?Wc("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function Yc(t,e,o,n=30){const i=function(t,e,o,n=30){switch(t.type){case"line":{const n=t;if(0===n.path.length)return null;const i=qs(n.curve),r=i?uc().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=yc(`${o?o+"-":""}line-${e}-stroke-gradient`),a=jc(n.strokeGradient,n.path,s,n.style.stroke||"#4e79a7");return Bc(lc.Fragment,{children:[a&&Wc("defs",{children:a}),Wc("path",{d:r,fill:"none",stroke:a?`url(#${s})`:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth??2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity})]},"line-"+e)}case"area":{const i=t;if(0===i.topPath.length)return null;const r=qs(i.curve),s=!r||2>i.topPath.length||2>i.bottomPath.length?`M${i.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...i.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:cc().x(([t])=>t).y0((t,e)=>i.bottomPath[e][1]).y1(([,t])=>t).curve(r)(i.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,l=ot(i.style.fill)?et(i.style.fill,a):void 0,c=yc(`${o?o+"-":""}area-${e}-gradient`),u=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=1/0;for(const[,e]of t.topPath)n=Math.min(n,e);let i=-1/0;for(const[,e]of t.bottomPath)i=Math.max(i,e);if(!Number.isFinite(n)||!Number.isFinite(i))return null;const r=xc(o.stops,gc(t.style.fill));return r?Wc("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r}):null}(i,c),d=u?`url(#${c})`:l?`url(#${a})`:gc(i.style.fill),h=u?void 0:i.style.fillOpacity??i.style.opacity??.7,p=r?uc().x(([t])=>t).y(([,t])=>t).curve(r)(i.topPath)??"":"M"+i.topPath.map(([t,e])=>`${t},${e}`).join("L"),f=kc(i),g=f&&n>=0?Wc("path",{d:p,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*n),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:f},"data-semiotic-mark-cursor":f,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${e}-cursor-target`):null,y=yc(`${o?o+"-":""}area-${e}-stroke-gradient`),m=!(!i.colorThresholds?.length||!i.rawValues||i.rawValues.length!==i.topPath.length),x=!!i.strokeColorBands?.length,b=m||x?null:jc(i.strokeGradient,i.topPath,y,i.style.stroke||"#4e79a7"),v=i.style.strokeWidth??2;let w=1/0,k=-1/0;for(const[t]of i.topPath)w>t&&(w=t),t>k&&(k=t);const A=x?i.strokeColorBands.map((t,n)=>yc(`${o?o+"-":""}area-${e}-stroke-band-${n}`)):[],S=x?i.strokeColorBands.map((t,e)=>Wc("clipPath",{id:A[e],children:Wc("rect",{x:w-v,y:t.y,width:k-w+2*v,height:t.height})},A[e])):null,M=i.style.stroke&&"none"!==i.style.stroke?x?i.strokeColorBands.map((t,o)=>Wc("path",{d:p,fill:"none",stroke:t.color??gc(i.style.stroke),strokeWidth:v,opacity:(i.style.opacity??1)*(t.opacity??1),clipPath:`url(#${A[o]})`},`area-${e}-stroke-band-${o}`)):m?function(t,e,o,n){if(2>t.length||e.length!==t.length||0===o.length)return[];const i=[],r=(t,e,o)=>{const n=i[i.length-1];n?.color===t?n.path.push(o):i.push({color:t,path:[e,o]})};for(let i=1;t.length>i;i++){const[s,a]=t[i-1],[l,c]=t[i],u=e[i-1],d=e[i]-u,h=[0,...0===d?[]:o.map(({value:t})=>(t-u)/d).filter(t=>t>0&&1>t&&Number.isFinite(t)).sort((t,e)=>t-e).filter((t,e,o)=>0===e||t!==o[e-1]),1];for(let t=1;h.length>t;t++){const e=h[t-1],i=h[t];r(dc(u+d*((e+i)/2),o,n),[s+(l-s)*e,a+(c-a)*e],[s+(l-s)*i,a+(c-a)*i])}}return i}(i.topPath,i.rawValues,i.colorThresholds,gc(i.style.stroke)).map((t,o)=>Wc("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:v,opacity:i.style.opacity},`area-${e}-threshold-${o}`)):Wc("path",{d:p,fill:"none",stroke:b?`url(#${y})`:gc(i.style.stroke),strokeWidth:v,opacity:i.style.opacity}):null;if(i.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return Bc("g",{children:[Bc("defs",{children:[u,!u&&l,b,S,Wc("clipPath",{id:t,children:Wc("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),Bc("g",{clipPath:`url(#${t})`,children:[Wc("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]})]},"area-"+e)}return Bc(lc.Fragment,{children:[(u||l||b||S)&&Bc("defs",{children:[u,!u&&l,b,S]}),Wc("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=ot(n.style.fill)?et(n.style.fill,i):void 0;return Bc(lc.Fragment,{children:[r&&Wc("defs",{children:r}),Wc("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:gc(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return bc(t,e);case"glyph":return mc(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=ot(n.style.fill)?et(n.style.fill,i):void 0;return Bc(lc.Fragment,{children:[r&&Wc("defs",{children:r}),Wc("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:gc(n.style.fill),opacity:n.style.opacity,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const o=t,n={x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth,...null!=o.style?.opacity&&{opacity:o.style.opacity}};if(o.showValues&&null!=o.value&&o.w>=20&&o.h>=20){const t=o.valueFormat?o.valueFormat(o.value):Number.isInteger(o.value)?o.value+"":100>Math.abs(o.value)?1>Math.abs(o.value)?o.value.toPrecision(3):o.value.toFixed(1):o.value.toFixed(0),[i,r,s]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(o.fill),a=.299*i+.587*r+.114*s>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return Bc("g",{children:[Wc("rect",{...n}),Wc("text",{x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:l+"px",children:t})]},"heatcell-"+e)}return Wc("rect",{...n},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return Bc("g",{children:[Wc("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),Wc("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),Wc("circle",{cx:o.x,cy:o.lowY,r:t,fill:o.wickColor})]},"candle-"+e)}const n=Math.min(o.openY,o.closeY),i=Math.max(Math.abs(o.openY-o.closeY),1),r=o.isUp?o.upColor:o.downColor;return Bc("g",{children:[Wc("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),Wc("rect",{x:o.x-o.bodyWidth/2,y:n,width:o.bodyWidth,height:i,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}(t,e,o,n);return"area"===t.type?i:Ac(i,t,"xy-cursor-"+e)}var Xc=new Set;function Gc(t){const{node:e,index:o,renderMode:n,fallback:i}=t,r=function(t,e){const o="function"==typeof t?t(e.datum??null,e):t;return(n=o)&&"object"==typeof n&&"string"==typeof n.id&&"function"==typeof n.cacheKey&&"function"==typeof n.drawCanvas&&"function"==typeof n.renderStaticSVG?o:void 0;var n}(n,e);if(!r)return{element:i(),renderedByBackend:!1};const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?{element:Ac(s,e,`${r.id}-${o}-cursor`),renderedByBackend:!0}:(function(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;Xc.has(o)||(Xc.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}(r.id,e.type??"unknown"),{element:i(),renderedByBackend:!1})}function Vc(t){const e=[];return t.nodes.forEach((o,n)=>{const i=Gc({node:o,index:n,renderMode:t.renderMode,fallback:()=>t.fallback(o,n)});null!=i.element&&!1!==i.element&&e.push({node:o,index:n,...i})}),e}import{scaleOrdinal as Hc}from"d3-scale";import{jsx as qc,jsxs as Uc}from"react/jsx-runtime";function Kc(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>ne(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:B;return Hc().domain(t).range(n)}function Zc(t,e,o){if(0===t.length)return;const n=Kc(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}function Qc(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Jc(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function tu(t){return t.typography.legendFontFamily??t.typography.fontFamily}function eu(t){return t.typography.legendFontWeight}function ou(t,e,o,n){const i=Jc(n);return e+o+Math.ceil(t.length*i*.58)}function nu(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=lo(s),d=a+l,h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right),f=e.map(t=>ou(t,a,l,o));if(h){const t=Math.max(a,s?.maxWidth??p),o=[];let n=0,i=0;f.forEach((e,r)=>{const s=0===i?e:i+c+e;i>0&&s>t?(o.push({start:n,end:r,width:i}),n=r,i=e):i=s}),e.length>0&&o.push({start:n,end:e.length,width:i});const r=Qc(s?.align),l=[];return o.forEach((o,n)=>{let i="center"===r?Math.max(0,(t-o.width)/2):"end"===r?Math.max(0,t-o.width):0;for(let t=o.start;o.end>t;t++)l.push({category:e[t],width:f[t],x:i,y:n*u}),i+=f[t]+c}),{items:l,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...f);return{items:e.map((t,e)=>({category:t,width:f[e],x:0,y:e*u})),width:g,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function iu(t,e){if(!e||!t||0===t.length)return[];const o="function"==typeof e?e:t=>t[e],n=new Set;for(const e of t){const t=o(e);null!=t&&n.add(t+"")}return Array.from(n)}import{jsx as ru,jsxs as su}from"react/jsx-runtime";function au(t,e=120,o=8){if(!t)return[];const n=Math.max(1,Math.floor(e/o)),i=t.split(/\s+/),r=[];let s="";for(const t of i)s&&s.length+1+t.length>n?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function lu(t,e,o,n){return"curly"===t?n?`M0,0 C${.6*o},0 ${.4*o},${e/2} ${o},${e/2} C${.4*o},${e/2} ${.6*o},${e} 0,${e}`:`M0,0 C0,${.6*o} ${e/2},${.4*o} ${e/2},${o} C${e/2},${.4*o} ${e},${.6*o} ${e},0`:n?`M0,0 L${o},0 L${o},${e} L0,${e}`:`M0,0 L0,${o} L${e},${o} L${e},0`}function cu(t,e,o,n){if(!t)return ru("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=t;if(!i&&!r)return ru("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(o)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>o?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>e?"end":"start";const p=16,f=r?c?[r]:au(r,l):[],g=i?c?[i]:au(i,l):[],y="leftRight"===u?"end"===h?-4:4:0;let m=0;const x=[],b=n||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?x.push(ru("foreignObject",{className:"annotation-note-html",x:"end"===h?y-l:"middle"===h?y-l/2:y,y:-16,width:l,height:Math.max(p,(f.length+g.length)*p+(r&&i?2:0))+p,style:{overflow:"visible"},children:su("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:b,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&ru("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&ru("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(f.length>0&&(x.push(ru("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:f.map((t,e)=>ru("tspan",{x:y,dy:0===e?0:p,children:t},e))},"annotation-note-title")),m=f.length*p),g.length>0&&x.push(ru("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:g.map((t,e)=>ru("tspan",{x:y,dy:0===e?0:p,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(l,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=ru("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(f.length+g.length)*p+(g.length>0?p:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=ru("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,f.length+g.length-1)*p;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+p+(g.length>0&&f.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),su("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[ru("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function uu(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(ru("circle",{r:t,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,n=e?.height||0;(t>0||n>0)&&r.push(ru("rect",{width:t,height:n,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":e?.custom&&r.push(...Array.isArray(e.custom)?e.custom:[e.custom]);break;case"xy-threshold":{const t=n||0,s=i||0;if(void 0!==e?.x){const n=(e.x||0)-t;r.push(ru("line",{x1:n,y1:(e.y1||0)-s,x2:n,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const n=(e.y||0)-s;r.push(ru("line",{x1:(e.x1||0)-t,y1:n,x2:(e.x2||0)-t,y2:n,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(ru("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(ru("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const t=e?.type||"curly",n=e?.width??e?.height;void 0!==n&&r.push(ru("path",{d:lu(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return ru("g",{className:"annotation-subject",children:r})}function du(t,e,o,n,i,r){const s=[];let a=0,l=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const o=r.width||0,n=r.height||0;if(o>0||n>0){const i=o/2,r=n/2,s=t-i,c=e-r;if(0!==s||0!==c){const t=Math.abs(s),e=Math.abs(c),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,l=o):void 0!==e&&(a=o,l=e/2)}}else{const o=(r.radius||0)+(r.radiusPadding||0);if(o>0&&(0!==t||0!==e)){const n=Math.atan2(e,t);a=Math.cos(n)*o,l=Math.sin(n)*o}}const c=Math.sqrt((t-a)**2+(e-l)**2);if(c>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-l,t-a);if(r){const n=(a+t)/2,r=(l+e)/2,d=-(e-l)/c,h=(t-a)/c,p=(o?.curve??.25)*c,f=n+d*p,g=r+h*p;s.push(ru("path",{className:"connector-curve",d:`M${a},${l}Q${f},${g} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(g-l,f-a)}else s.push(ru("line",{x1:a,y1:l,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(ru("path",{d:`M${a},${l}L${a+t*Math.cos(u+e)},${l+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${l+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return ru("g",{className:"annotation-connector",children:s})}function hu(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:p,opacity:f,strokeDasharray:g,events:y={},"data-testid":m}=t,x=Array.isArray(e)?e[0]??0:e,b=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(p)?p:[]);let w=n||0,k=i||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const A="string"==typeof u?u:"label";if("bracket"===A&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;const t=c.depth||30;k=t+(0>t?-5:5)}else if(void 0!==c.height){const t=c.depth||30;w=t+(0>t?-5:5),k=c.height/2}return su("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=f&&{opacity:f},...g&&{strokeDasharray:g},...y,children:[!v.has("connector")&&du(w,k,l,d,A,c),!v.has("subject")&&uu(A,c,d,x,b),!v.has("note")&&cu(a,w,k,d)]})}function pu(t){const{noteData:e}=t,{screenCoordinates:o}=e,n="string"==typeof e.type?e.type:"label",i=e.eventListeners||e.events||{};if(e.coordinates&&o){const t=e.nx||o[0][0]+(e.dx??0),i=e.ny||o[0][1]+(e.dy??0),r=o.map((o,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:o[0],y:o[1],nx:t,ny:i});return ru(hu,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return ru("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return ru(hu,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{jsx as fu}from"react/jsx-runtime";var gu={secondary:0,primary:3};function yu(t){return!0===t?._annotationDeferred}function mu(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function xu(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function bu(t){return Math.max(.72,.95-.06*t)}function vu(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(o=t.annotation,"primary"===o?.emphasis||"secondary"===o?.emphasis?o.emphasis:null),confidence:xu(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>yu(t.annotation)),i=t.some(t=>null!=mu(t.annotation)),r=t.some(t=>"layer"===mu(t.annotation));if(!o&&!n&&!i)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=2-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=gu[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:o,emphasis:n,readingOrder:i}=t,r=yu(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=fu("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:bu(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=mu(e.annotation);return a&&(s=fu("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=fu("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(fu("style",{children:".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}"},"annotation-disclosure-style")),r&&a.unshift(fu("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}import{jsx as wu,jsxs as ku}from"react/jsx-runtime";var Au="var(--semiotic-bg, #ffffff)";function Su(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=t,h=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),p=t=>wu("text",{x:e,y:o,textAnchor:l,dominantBaseline:c,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{style:{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}}:{},children:n});if(!h)return p();if("halo"===h.type)return p({stroke:h.fill??Au,strokeWidth:h.haloWidth??3});const f=h.padding??{x:6,y:3},g="number"==typeof f?f:f.x,y="number"==typeof f?f:f.y,m=function(t,e){return(t+"").length*e*.6}(n,r),x=r+2*y;let b,v;return b="middle"===l?e-m/2-g:"end"===l?e-m-g:e-g,v="middle"===c||"central"===c?o-x/2:"hanging"===c||"text-before-edge"===c?o-y:o-.8*r-y,ku("g",{className:d,children:[wu("rect",{x:b,y:v,width:m+2*g,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??Au,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),p()]})}function Mu(t,e,o,n){const i=ht(t.fill??t.color,e,n);return ct(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:n)??i}var _u=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Pu(t,e,o,n){const i=function(t,e,o){const n=t.position,i="string"==typeof n&&_u.has(n)?n:"bottom-left",r=i.endsWith("left")?"left":i.endsWith("right")?"right":"center",s=i.startsWith("top")?"top":i.startsWith("bottom")?"bottom":"middle",a="top"===s?0:"bottom"===s?o:o/2;return{x:("left"===r?0:"right"===r?e:e/2)+("number"==typeof t.dx&&Number.isFinite(t.dx)?t.dx:0),y:a+("number"==typeof t.dy&&Number.isFinite(t.dy)?t.dy:0),textAnchor:"start"===t.textAnchor||"middle"===t.textAnchor||"end"===t.textAnchor?t.textAnchor:"left"===r?"start":"right"===r?"end":"middle",dominantBaseline:"auto"===t.dominantBaseline||"middle"===t.dominantBaseline||"hanging"===t.dominantBaseline?t.dominantBaseline:"top"===s?"hanging":"bottom"===s?"auto":"middle"}}(t,e,o);return{...i,fill:t.fill??t.color??n.fill,fontSize:t.fontSize??n.fontSize,fontFamily:t.fontFamily??n.fontFamily,fontWeight:t.fontWeight,fontStyle:t.fontStyle,letterSpacing:t.letterSpacing,opacity:t.opacity,className:t.className,style:{pointerEvents:"none"}}}import{jsx as Lu}from"react/jsx-runtime";var $u={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Ru({annotation:t,width:e,height:o,defaults:n=$u}){const i=t.label??t.text;return null==i?null:Lu("text",{...Pu(t,e,o,n),children:i})}import{packEnclose as Cu}from"d3-hierarchy";import{area as Tu,curveBasis as Ou,curveCardinal as Iu,curveCatmullRom as zu,curveLinear as Fu,curveMonotoneX as Nu,curveMonotoneY as Eu,curveStep as Du,curveStepAfter as Wu,curveStepBefore as Bu}from"d3-shape";import*as ju from"react";function Yu(t,e={}){const o=K(t);return{"data-semiotic-annotation-widget":"",...o?{"data-semiotic-annotation-id":o}:{},onClickCapture(n){const i=function(t){const e=t.nativeEvent;return"touch"===e.pointerType?"touch":0===e.detail?"keyboard":"pointer"}(n);e.onAnnotationActivate?.({annotation:t,annotationId:o,chartId:e.chartId,inputType:i}),o&&e.onObservation&&e.onObservation({type:"annotation-activate",annotationId:o,inputType:i,timestamp:Date.now(),chartType:e.chartType??"unknown",chartId:e.chartId})}}}import{jsx as Xu,jsxs as Gu}from"react/jsx-runtime";var Vu={linear:Fu,monotoneX:Nu,monotoneY:Eu,step:Du,stepAfter:Wu,stepBefore:Bu,basis:Ou,cardinal:Iu,catmullRom:zu};import{jsx as Hu,jsxs as qu}from"react/jsx-runtime";var Uu=16;function Ku(t,e){return t.color||e.colors.annotation||e.colors.text}function Zu(t,e,o){const n=t.labelBackground,i=e.colors.background,r=i&&"transparent"!==i?i:e.colors.surface||i;return void 0===n?"none"===o?"none":{type:"halo",fill:r}:!1===n||"none"===n?"none":!0===n||"halo"===n?{type:"halo",fill:r}:"box"===n?{type:"box",fill:r}:{fill:r,...n}}function Qu(t,e,o){return null!=t.x&&e.x?e.x(t.x):o&&null!=t[o]&&e.x?e.x(t[o]):"number"==typeof t.x?t.x:null}function Ju(t,e,o){return null!=t.y&&e.y?e.y(t.y):o&&null!=t[o]&&e.y?e.y(t[o]):"number"==typeof t.y?t.y:null}function td(t){const{annotations:e}=t;if(!e||0===e.length)return t.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;const o=gt(e),n=t.scales.geoProjection,r=n?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=n([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,s=!!n&&!t.scales.x&&!t.scales.y,a=t=>Number(t),l=t.scales.x??(s?a:void 0),c=t.scales.y??(s?a:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{..."vertical"===t.projection?{x:t.scales.o??l,y:t.scales.r??c,time:t.scales.o??l,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??l,y:t.scales.o??c,time:t.scales.r??l,value:t.scales.o??c,o:t.scales.o}:{x:l,y:c,time:l,value:c,o:t.scales.o},...n?{geoProjection:n}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,pointNodes:t.pointNodes,frameType:t.frameType??(t.projection?"ordinal":n||t.scales.x||t.scales.y?"xy":"network"),...u?{projection:u}:{}},h=t.autoPlaceAnnotations?i({annotations:r,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):r,p=function(t,e,o,n){const i=[];return t.forEach((t,r)=>{let s;if(o){const i=o(t,r,n);s=null!=i?i:e(t,r,n)}else s=e(t,r,n);s&&i.push({node:s,annotation:t})}),{nodes:vu(i),renderedAnnotations:i.map(t=>t.annotation)}}(h,(e,o,n)=>function(t,e,o,n){const{scales:i,layout:r,theme:s,xAccessor:a,yAccessor:l}=o;switch(t.type){case"frame-text":return Hu(Ru,{annotation:t,width:r.width,height:r.height,defaults:{fill:s.colors.text,fontSize:11,fontFamily:s.typography.fontFamily}},"ann-frame-text-"+e);case"y-threshold":{const n=t.value??t.y;if(null==n)return null;const a=Ku(t,s),l=t.label,c=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:qu("g",{opacity:t.opacity,children:[Hu("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Hu(Su,{x:o+4,y:Uu,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Zu(t,s,"halo")})]},"ann-ythresh-"+e)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:qu("g",{children:[Hu("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Hu(Su,{x:"left"===c?4:"center"===c?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Uu):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Zu(t,s,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const n=t.value??t.x;if(null==n)return null;const a="horizontal"===o.projection&&i.r?i.r(n):i.x?i.x(n):null;if(null==a)return null;const l=Ku(t,s),c=t.label,u=t.labelPosition||"top";return qu("g",{opacity:t.opacity,children:[Hu("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:l,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&Hu(Su,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Uu,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:l,fontFamily:s.typography.fontFamily,text:c,background:Zu(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=i.y?.domain?.(),n=t.y0??o?.[0],a=t.y1??o?.[1],l=null!=n&&i.y?i.y(n):null,c=null!=a&&i.y?i.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=Mu(t,"ssr-band-"+e,"vertical",Ku(t,s)),p=t.fillOpacity??.1;return qu("g",{opacity:t.opacity,children:[h.def&&Hu("defs",{children:h.def}),Hu("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:p}),t.label&&Hu(Su,{x:r.width-4,y:Math.max(u,0)+Uu,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Ku(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Zu(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=i.x?.domain?.(),n=t.x0??o?.[0],a=t.x1??o?.[1],l=null!=n&&i.x?i.x(n):null,c=null!=a&&i.x?i.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=Mu(t,"ssr-xband-"+e,"horizontal",Ku(t,s)),p=t.fillOpacity??.1;return qu("g",{opacity:t.opacity,children:[h.def&&Hu("defs",{children:h.def}),Hu("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:p}),t.label&&Hu(Su,{x:u+4,y:Uu,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Ku(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Zu(t,s,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!i.o)return null;const n=i.o(t.category+"");if(null==n)return null;const a=i.o.bandwidth?i.o.bandwidth():40,l=Ku(t,s),c=t.opacity??.1,u=t.label;return qu("g","horizontal"===o.projection?{children:[Hu("rect",{x:0,y:n,width:r.width,height:a,fill:l,opacity:c}),u&&Hu(Su,{x:12,y:n+a/2,dominantBaseline:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Zu(t,s,"none")})]}:{children:[Hu("rect",{x:n,y:0,width:a,height:r.height,fill:l,opacity:c}),u&&Hu(Su,{x:n+a/2,y:Uu,textAnchor:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Zu(t,s,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const o=function(t,e,o,n){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const o=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Qu(t,e,o),y:Ju(t,e,n)}}(t,i,a,l),r=null==o.x||null==o.y?F(t,e,n):null,c=o.x??r?.x??null,u=o.y??r?.y??null;if(null==c||null==u)return null;const d="text"===t.type,h=t.dx??(d?0:30),p=t.dy??(d?0:-30),f=t.color||s.colors.text;if(!d){const o="callout"===t.type?"callout-circle":t.type,n="callout-circle"===o?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===o?{width:t.width,height:t.height}:void 0;return Hu(pu,{noteData:{x:c,y:u,dx:h,dy:p,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...n?{subject:n}:{},connector:t.connector||{end:"arrow"},color:f,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return Hu("g",{children:Hu("text",{x:c+h,y:u+p,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||s.typography.labelSize,fill:f,fontFamily:s.typography.fontFamily,fontWeight:t.fontWeight,opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:t.label||t.title})},"ann-label-"+e)}default:return null}}(e,o,t,n)??function(t,e,o){switch(t.type){case"enclose":{const n=(t.coordinates||[]).map(t=>({x:E({...t,type:"point"},o),y:D({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=Cu(n),r=t.padding||10;return Gu("g",{children:[Xu("circle",{cx:i.x,cy:i.y,r:i.r+r,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Xu(Su,{x:i.x,y:i.y-i.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"rect-enclose":{const n=(t.coordinates||[]).map(t=>({x:E({...t,type:"point"},o),y:D({...t,type:"point"},o)})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=t.padding||10,[r,s]=St(n.map(t=>t.x)),[a,l]=St(n.map(t=>t.y)),c=r-i,u=s+i,d=a-i;return Gu("g",{children:[Xu("rect",{x:c,y:d,width:u-c,height:l+i-d,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Xu(Su,{x:(c+u)/2,y:d-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"highlight":{const n=o.data||[],i="function"==typeof t.filter?n.filter(t.filter):t.field&&null!=t.value?n.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return Xu("g",{children:i.map((e,n)=>{const i=E(e,o),s=D(e,o);if(null==i||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,l="function"==typeof t.style?t.style(e):t.style||r;return Xu("circle",{cx:i,cy:s,r:a,...l},"hl-"+n)})},"ann-"+e)}case"bracket":{const n=E(t,o),i=D(t,o);return Xu(pu,{noteData:{x:n??0,y:i??0,dx:t.dx||0,dy:t.dy||0,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:"bracket",subject:{type:t.bracketType||"curly",width:t.width,height:t.height,depth:t.depth||30},color:t.color}},"ann-"+e)}case"trend":{const n=o.data||[];if(2>n.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s="ordinal"===o.frameType,a="horizontal"===o.projection,l=s?i:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const t of n){const e=t[l];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=n.map(t=>{const e=t[l],o=t[c];if(null==e||null==o)return null;const n=h.get(e+"");return null!=n?[n,+o]:null}).filter(t=>null!==t)}else u=n.map(t=>[t[i],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const p=o.scales?.x??o.scales?.time,f=o.scales?.y??o.scales?.value;if(!p||!f)return null;const g=t=>e=>{const o=Math.max(0,Math.floor(e)),n=Math.min(d.length-1,o+1),i=e-o,r=t(d[o]);return r+(t(d[n])-r)*i},y=p,m=f;let x;if(s)if(a){const t=g(m);x=(e,o)=>[y(o),t(e)]}else{const t=g(y);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[y(t),m(e)];const b=t.method||"linear",v="loess"===b?function(t,e=.3){const o=t.length;if(2>o)return t.slice();const n=t.slice().sort((t,e)=>t[0]-e[0]),i=n.map(t=>t[0]),r=n.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=i[t],n=i.map(t=>Math.abs(t-e)),l=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,c=[];for(let t=0;o>t;t++){const e=0===l?0:n[t]/l;c[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,p=0,f=0;for(let t=0;o>t;t++){const e=c[t];0!==e&&(u+=e,d+=e*i[t],h+=e*r[t],p+=e*i[t]*i[t],f+=e*i[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const g=u*p-d*d;if(1e-12>Math.abs(g))a.push([e,h/u]);else{const t=(u*f-d*h)/g;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3):("polynomial"===b?ve(u,t.order||2):function(t){const e=[0,0,0,0];let o=0;for(const[n,i]of t)null!==i&&(o++,e[0]+=n,e[1]+=i,e[2]+=n*n,e[3]+=n*i);const n=o*e[2]-e[0]*e[0],i=0===n?0:be((o*e[3]-e[0]*e[1])/n),r=be(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[be(t),be(i*t+r)]),equation:[i,r]}}(u)).points,w=v.map(([t,e])=>{const[o,n]=x(t,e);return`${o},${n}`}).join(" "),k=t.color||"#6366f1",A=v[v.length-1],[S,M]=x(A[0],A[1]);return Gu("g",{children:[Xu("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Xu("text",{x:S+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+e)}case"envelope":{const n=o.data||[];if(2>n.length)return null;const i=o.xAccessor||"x",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",l=t.lowerAccessor||"lowerBounds",c=t.filter,u=n.filter(t=>null!=t[a]&&null!=t[l]&&(!c||c(t))).sort((t,e)=>t[i]-e[i]);if(2>u.length)return null;const d=Vu[o.curve||"linear"]||Fu,h=Tu().x(t=>r(t[i])).y0(t=>s(t[l])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const p=t.fill||"#6366f1",f=u[u.length-1];return Gu("g",{children:[Xu("path",{d:h,fill:p,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&Xu("text",{x:r(f[i])+4,y:s(f[a])-4,fill:p,fontSize:11,children:t.label})]},"ann-"+e)}case"anomaly-band":{const n=o.data||[];if(2>n.length)return null;const i=o.yAccessor||"y",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=n.map(t=>t[i]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const l=a.reduce((t,e)=>t+e,0)/a.length,c=a.reduce((t,e)=>t+(e-l)**2,0)/a.length,u=Math.sqrt(c),d=t.threshold??2,h=l-d*u,p=s(l+d*u),f=s(h),g=t.fill||"#6366f1",y=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=n.filter(t=>{const e=t[i];return null!=e&&Math.abs(e-l)>d*u});return Gu("g",{children:[!1!==t.showBand&&Xu("rect",{x:0,y:Math.min(p,f),width:o.width||0,height:Math.abs(f-p),fill:g,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const n=E(t,o),i=D(t,o);return null==n||null==i?null:Xu("circle",{cx:n,cy:i,r:m,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Xu("text",{x:(o.width||0)-4,y:Math.min(p,f)-4,textAnchor:"end",fill:g,fontSize:11,children:t.label})]},"ann-"+e)}case"forecast":{const n=o.data||[];if(3>n.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s=o.scales?.x??o.scales?.time,a=o.scales?.y??o.scales?.value;if(!s||!a)return null;const l=n.map(t=>[t[i],t[r]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]);if(3>l.length)return null;let c;if("polynomial"===t.method){const e=ve(l,t.order||2).equation;c=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=we(l);if(!t)return null;c=t}const{se:u,meanX:d,ssX:h}=ke(l,c),p=l.length,f=Ae(t.confidence??.95),g=l[p-1][0],y=(g-l[0][0])/Math.max(p-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=g+(e+1)*y,n=c(o),i=u*Math.sqrt(1+1/p+(h>0?(o-d)**2/h:0))*f;return{x:o,center:n,upper:n+i,lower:n-i}}),x=m.map(t=>`${s(t.x)},${a(t.upper)}`).join(" L"),b=m.slice().reverse().map(t=>`${s(t.x)},${a(t.lower)}`).join(" L"),v=m.map(t=>`${s(t.x)},${a(t.center)}`).join(" "),w=t.strokeColor||"#6366f1",k=m[m.length-1];return Gu("g",{children:[Xu("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Xu("polyline",{points:`${s(g)},${a(c(g))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&Xu("text",{x:s(k.x)+4,y:a(k.center)-4,fill:w,fontSize:11,children:t.label})]},"ann-"+e)}case"widget":{let n,i;if(null!=t.px&&null!=t.py)n=t.px,i=t.py;else{const r=F(t,e,o);if(!r)return null;n=r.x,i=r.y}if(!M(n,i,o))return null;const r=t.width??32,s=t.height??32,a=t.content??Xu("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Xu("foreignObject",{x:n+(t.dx??0)-r/2,y:i+(t.dy??0)-s/2,width:r,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:Xu("div",{...Yu(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,n),t.svgAnnotationRules,d),f=p.nodes,g=new Map;for(const t of p.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";g.set(e,(g.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=g.get(e)??0;o>0?g.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:h.length,renderedCount:p.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?Hu("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}import{jsx as ed}from"react/jsx-runtime";function od(t,e,o,n="right",i,r){if(null==t||!1===t)return null;const{x:s,y:a}=ao(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:n,legendLayout:i,axisChrome:r});return ed("g",{transform:`translate(${s}, ${a})`,children:t})}import*as nd from"react";function id(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function rd(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function sd(t){if(0===t.length)return{min:null,max:null};let e=1/0,o=-1/0;for(const n of t)e>n.pixel&&(e=n.pixel),n.pixel>o&&(o=n.pixel);return{min:e,max:o}}function ad(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function ld(t,e){return t&&"string"!=typeof t?{stroke:t.stroke??e.stroke,strokeWidth:t.strokeWidth??e.strokeWidth,...null!=t.strokeOpacity&&{strokeOpacity:t.strokeOpacity},...t.strokeDasharray&&{strokeDasharray:t.strokeDasharray}}:{...e,..."string"==typeof t&&{strokeDasharray:ad(t)}}}function cd(t,e,o){if("left"===t||"right"===t){const n="left"===t?o:0,i="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+n;for(let t=0;r>t;t++){const o=8*(t+1);s+=`L${Math.min(8*t+4,e)},${n+4*i}`,s+=`L${Math.min(o,e)},${n}`}return s}const n="bottom"===t?0:e,i="bottom"===t?1:-1,r=Math.ceil(o/8);let s=`M${n},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${n+4*i},${Math.min(8*t+4,o)}`,s+=`L${n},${Math.min(e,o)}`}return s}function ud(t,e){return t?.ticks??t?.tickCount??e}function dd(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function hd(t,e,o){return"exact"===o?function(t,e){const o=t.domain(),n=o[0],i=o[o.length-1],r=n instanceof Date,s=n instanceof Date?n.getTime():n,a=i instanceof Date?i.getTime():i;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const l=(a-s)/(e-1),c=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*l;c[t]=r?new Date(o):o}return c}(t,e):t.ticks(e)}import{jsx as pd}from"react/jsx-runtime";function fd(t){return"string"==typeof t||"number"==typeof t}function gd(t){const{label:e,x:o,y:n,textAlign:i,fontSize:r,fontFamily:s,color:a}=t;return pd("foreignObject",{x:o,y:n,width:60,height:24,style:{overflow:"visible"},children:pd("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:i,userSelect:"none"},children:e})})}function yd(t){const{values:e,scale:o,format:n}=t,i=e.map(t=>t.valueOf());return e.map((t,e)=>({value:t,pixel:o(t),label:n(t,e,i)}))}function md(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function xd(t){const{candidates:e,scale:o,minPixelDistance:n,includeMax:i,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:l=!0,format:c}=t;let u=function(t,e){if(2>=t.length)return t;const o=[t[0]];for(let n=1;t.length-1>n;n++)e>Math.abs(t[n].pixel-o[o.length-1].pixel)||o.push(t[n]);const n=t[t.length-1];return e>Math.abs(n.pixel-o[o.length-1].pixel)?o[o.length-1]=n:o.push(n),o}(e,n);if(a&&u.length>1&&(u=u.filter((t,e)=>{return 0===e||(n=u[e-1].label,!!("string"!=typeof(o=t.label)&&"number"!=typeof o||"string"!=typeof n&&"number"!=typeof n||o+""!=n+""));var o,n})),!l||!i||0===u.length||"exact"===r||s)return u;const d=o.domain(),h=d[d.length-1];if(null==h)return u;const p=o(h),f=u[u.length-1].pixel;if(1>=Math.abs(p-f))return u;const g=e.map(t=>t.value.valueOf()),y={value:h,pixel:p,label:c(h,u.length,g)};return n>Math.abs(p-f)&&u.length>1&&(u=u.slice(0,-1)),[...u,y]}function bd(t,e,o,n){return!!t&&("function"==typeof t?t(e.value,o):nt(e.value,o>0?n[o-1].value:void 0))}import{jsx as vd,jsxs as wd}from"react/jsx-runtime";function kd(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function Ad(t){const e=t._idPrefix||t.chartId;if(e){const t=(e+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(t)?t:"c"+t}const o=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let n=0;for(let t=0;o.length>t;t++)n=31*n+o.charCodeAt(t)|0;return"c"+(n>>>0).toString(36)}function Sd(t,e,o){return Ye(t.showLegend&&!t.__legendIncludesAutomatic?Zc(e,t.colorScheme,o):void 0,t.legend)}var Md={right:110,left:110,top:50,bottom:80};function _d(t,e){if(t.__autoLegendMargin)return Md[e]}function Pd(t,e){const o={theme:e.theme,position:e.position||"right",totalWidth:e.size[0],totalHeight:e.size[1],margin:e.margin,hasTitle:e.hasTitle,legendLayout:e.legendLayout,idPrefix:e.idPrefix,reservedWidth:e.reservedWidth,axisChrome:e.axisChrome,legendDistance:Xe(t)||Ge(t)?t.legendDistance:void 0};return Xe(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,o)=>({group:t,item:e,itemIndex:o,label:e.label})))).length)return null;var e;const o=function(t){const{legendGroups:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,rowHeight:c}=lo(s),u=a+l,d=Math.max(12,Jc(o)),h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??p),i=Qc(s?.align);let r=0,l=0;const c=[];for(const i of e){const e=i.items.map(t=>t.label),u=nu({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,p=i.label?ou(i.label,0,0,o):0,f=h>0?h+8:0,g=f+u.width,y=Math.max(u.height,p);c.push({group:i,x:r,y:0,itemOffsetX:f,itemOffsetY:0,width:g,height:y,items:u.items}),r+=g+12,l=Math.max(l,y)}const h=c.length>0?r-12:0,f=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:c.map(t=>({...t,x:t.x+f})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const f=co(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),c);let g=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>ou(t.label,a,l,o)),i=Math.max(0,...n,t.label?ou(t.label,0,0,o):0);return g=Math.max(g,i),{group:t,x:0,y:f[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*c,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*c}))}}),width:g,height:f.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}(t),n="top"===t.position||"bottom"===t.position,i={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??Ze(i,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:l}=ao(i,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:r});if(!n){const e=co(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)),n=t.legendGroups.flatMap((n,i)=>{const s=e[i],a=n.type??"fill",l=[qc("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=s.labelY&&l.push(qc("text",{y:s.labelY,fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:n.label},"legend-group-label-"+i)),l.push(qc("g",{transform:`translate(0,${s.itemsY})`,children:n.items.map((e,r)=>{const s=n.styleFn(e,r),l="function"==typeof a?a(e):"line"===a?qc("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):qc("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return Uc("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[l,qc("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return qc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":"vertical",fontWeight:eu(t.theme),children:n})}const c=o.groups.flatMap((e,i)=>{const{group:r}=e,a=r.type??"fill",l=[];if(r.label&&l.push(qc("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:r.label}:{x:e.x,y:e.y+Jc(t.theme),fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:r.label},"legend-group-label-"+i)),l.push(...e.items.map((n,s)=>{const l=r.items[s],c=r.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?qc("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:c}):qc("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:c});return Uc("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,qc("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:n.category})]},`legend-${i}-${s}`)})),n&&o.groups.length-1>i){const t=e.x+e.width+6;l.push(qc("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+i))}return l});return qc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":n?"horizontal":"vertical",fontWeight:eu(t.theme),children:c})}({...o,legendGroups:t.legendGroups}):Ge(t)?function(t){const e=function(t){const e="top"===t.position||"bottom"===t.position,o=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??o,200),height:t.gradient.label?46:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?126:108,swatchSize:14}}(t),o="top"===t.position||"bottom"===t.position,n={gradient:t.gradient,legendDistance:t.legendDistance},i=Ze(n),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:l}=ao(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:i}),c=Array.from({length:17},(e,n)=>{const i=n/16;return qc("stop",{offset:100*i+"%",stopColor:t.gradient.colorFn(o?t.gradient.domain[0]+i*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-i*(t.gradient.domain[1]-t.gradient.domain[0]))},n)});if(o){const o=12,n=t.gradient.label?12:void 0,i=t.gradient.label?18:0;return Uc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:eu(t.theme),children:[qc("defs",{children:qc("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),t.gradient.label&&qc("text",{x:e.width/2,y:n,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:tu(t.theme),children:t.gradient.label}),qc("rect",{x:0,y:i,width:e.width,height:o,fill:`url(#${r})`,rx:2}),qc("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[0])}),qc("text",{x:e.width,y:i+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?12:void 0,d=t.gradient.label?18:0;return Uc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:eu(t.theme),children:[qc("defs",{children:qc("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),t.gradient.label&&qc("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:tu(t.theme),children:t.gradient.label}),qc("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),qc("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[1])}),qc("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function Ld(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",l={...t},c={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:_d(o,a)};if(null!=o.legend){const e=Sd(o,n,i);null!=e&&!1!==e&&function(t,e){so(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";so(t,{legend:Zc(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,categories:n,colorScheme:o.colorScheme});return Ue(t,l,r,a),a}function $d(t){const{props:e,categories:o,theme:n,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",l={theme:n,position:a,size:i,margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix};if(null!=e.legend){const t=Sd(e,o,n);if(nd.isValidElement(t))return od(t,i,r,a,e.legendLayout,e.axisChrome);return Pd(t,l)||(Xe(t)||Ge(t)?null:od(t??null,i,r,a,e.legendLayout,e.axisChrome))}return e.showLegend&&0!==o.length?function(t){const{categories:e,colorScheme:o,theme:n,position:i="right",totalWidth:r,totalHeight:s,margin:a}=t;if(!e||0===e.length)return null;const l=Kc(e,o,n),c="top"===i||"bottom"===i,u=nu(t),d={...Zc(e,o,n),legendDistance:t.legendDistance},h=t.reservedWidth??Ze(d,t.legendLayout),{x:p,y:f}=ao(d,{totalWidth:r,totalHeight:s,margin:a,position:i,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(c){const t=u.items.map((t,e)=>Uc("g",{transform:`translate(${t.x},${t.y})`,children:[qc("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),qc("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Jc(n),fill:n.colors.text,fontFamily:tu(n),children:t.category})]},"legend-"+e));return qc("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:eu(n),children:t})}const g=co([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],y=u.items.map((t,e)=>Uc("g",{transform:`translate(${t.x},${t.y+g.itemsY})`,children:[qc("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),qc("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Jc(n),fill:n.colors.text,fontFamily:tu(n),children:t.category})]},"legend-"+e));return Uc("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:eu(n),children:[qc("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),y]})}({categories:o,colorScheme:e.colorScheme,theme:n,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix}):null}var Rd=dd;function Cd(t,e){const o=me(e.theme),n=e.background??o.background,i=e.idPrefix?e.idPrefix+"-":"",r="string"==typeof e.title?e.title:void 0,s=r?i+"semiotic-title":void 0,a=e.description?i+"semiotic-desc":void 0,l=[s,a].filter(Boolean).join(" ")||void 0;return wd("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":l,style:{fontFamily:o.fontFamily},children:[r&&vd("title",{id:s,children:r}),e.description&&vd("desc",{id:a,children:e.description}),e.defs&&vd("defs",{children:e.defs}),n&&"transparent"!==n&&vd("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),vd("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&vd("text",{id:i+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:o.titleFontSize,fontWeight:o.titleFontWeight,fill:o.text,fontFamily:o.titleFontFamily,children:r}),e.legend&&vd("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{jsx as Td,jsxs as Od}from"react/jsx-runtime";function Id(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}var zd={top:50,right:40,bottom:60,left:70},Fd={top:20,right:80,bottom:20,left:80},Nd={top:40,right:40,bottom:40,left:40},Ed=new Set(["chord","force","circlepack","orbit"]);import{jsx as Dd,jsxs as Wd}from"react/jsx-runtime";import{Fragment as Bd,jsx as jd,jsxs as Yd}from"react/jsx-runtime";function Xd(t,e){const o=ye(t.theme),n=t.size||[500,300],i=qe({...zd,...t.margin},t.title),r=Ve(t.title),s=function(t,e){if(!e||0===t.length)return t;if(!t.some(t=>null!=t&&"object"==typeof t&&Array.isArray(t[e])))return t;const o=[];for(const n of t){if(null==n||"object"!=typeof n)continue;const t=n[e];if(!Array.isArray(t))continue;const i=n.label??n.id??n.key;for(const e of t)null!=e&&"object"==typeof e&&o.push(null==i?e:{...e,_lineGroup:i})}return o}(Ht(t.data),t.lineDataAccessor),a=t.showLegend?iu(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],l=function(t){const e=t.axes?.find(t=>"bottom"===t.orient),o=t.axes?.find(t=>"top"===t.orient),n=t.axes?.find(t=>"left"===t.orient),i=t.axes?.find(t=>"right"===t.orient),r=!o||!!e,s=!!o&&!e,a=!i||!!n,l=!!i,c=!1!==t.showAxes;return{hasAxis:c&&r,hasAxisLabel:c&&r&&!!(e?.label??t.xLabel),rotatedTicks:c&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(o?.label??t.xLabel),rotatedTicks:c&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??t.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});Ld(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=$d({props:{...t,axisChrome:l},categories:a,theme:o,size:n,margin:i,hasTitle:r}),u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),p=t.colorScheme||o.colors.categorical,f=(t.axes?.find(t=>"left"===t.orient)??t.axes?.find(t=>"right"===t.orient))?.extent??t.axisExtent,g={chartType:t.chartType,runtimeMode:h?"streaming":"bounded",windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:h?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:t.xAccessor,yAccessor:t.yAccessor,timeAccessor:h?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor||(t.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,yAxisExtent:f,sizeRange:t.sizeRange,xScaleType:t.xScaleType,yScaleType:t.yScaleType,scalePadding:t.scalePadding,binSize:t.binSize,normalize:t.normalize,baseline:t.baseline,stackOrder:t.stackOrder,boundsAccessor:t.boundsAccessor,boundsStyle:t.boundsStyle,band:t.band,y0Accessor:t.y0Accessor,areaGroups:t.areaGroups?t.areaGroups instanceof Set?t.areaGroups:new Set(t.areaGroups):void 0,curve:t.curve,gradientFill:ce(t.gradientFill),lineGradient:ue(t.lineGradient),semanticLineStops:t.semanticLineStops,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:p,themeCategorical:o.colors.categorical,themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging,themeSemantic:Rt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat,heatmapColorScale:t.heatmapColorScale,heatmapAggregation:t.heatmapAggregation,heatmapXBins:t.heatmapXBins,heatmapYBins:t.heatmapYBins,pointIdAccessor:t.pointIdAccessor,onLayoutError:t.onLayoutError},y=new ac(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Id(t.backgroundGraphics,n,i,y.scales),x=Id(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Ya.renderToStaticMarkup(Cd(m||x||t.annotations?Yd(Bd,{children:[m,a,x]}):null,{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=Vc({nodes:y.scene,renderMode:t.renderMode,fallback:(e,o)=>Yc(e,o,b,t.hoverRadius??30)}),w=t.showGrid?function(t,e,o,n,i,r,s){const{grid:a}=me(o),l=n?n+"-":"",c=r?.find(t=>"bottom"===t.orient),u=r?.find(t=>"top"===t.orient),d=r?.find(t=>"left"===t.orient),h=r?.find(t=>"right"===t.orient),p=c??u,f=d??h,g=p?.extent??i,y=f?.extent??i,m="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=p?.tickValues??hd(t.x,ud(p,m),g),v=p?.tickFormat||s?.xFormat||s?.tickFormatTime||dd,w=yd({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,md(e.label)),0),A=xd({candidates:w,scale:t.x,minPixelDistance:p?.autoRotate?Math.max(20,Math.min(k+8,55)):Math.max(55,k+8),includeMax:p?.includeMax,extentMode:g,hasExplicitTickValues:!!p?.tickValues,format:v}),S=f?.tickValues??hd(t.y,ud(f,x),y),M=f?.tickFormat||s?.yFormat||s?.tickFormatValue||dd,_=t=>M(t),P=xd({candidates:yd({values:S,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:f?.includeMax,extentMode:y,hasExplicitTickValues:!!f?.tickValues,format:_}),L=!1!==p?.grid,$=!1!==f?.grid,R=ad(p?.gridStyle),C=ad(f?.gridStyle),T=ld(p?.gridStyle,{stroke:a,strokeWidth:.5}),O=ld(f?.gridStyle,{stroke:a,strokeWidth:.5});return Od("g",{id:l+"grid",className:"semiotic-grid",opacity:.8,children:[L&&A.map((t,o)=>Td("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...T,strokeDasharray:R??T.strokeDasharray},"gx-"+o)),$&&P.map((t,o)=>Td("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...O,strokeDasharray:C??O.strokeDasharray},"gy-"+o))]})}(y.scales,{width:u,height:d},o,b,t.axisExtent,t.axes,t):null,k=v.map(t=>t.element),A=Ad(t)+"-plot-clip",S=!1!==t.showAxes,M=S?function(t,e,o,n,i,r,s,a=!1){const l=me(n),c=o.legendPosition??"right",u=Je(o.legendLayout,s?.leftAxis),d=Je(o.legendLayout,s?.rightAxis),h=a&&"left"===c&&u>0?u:r?.left??o.margin?.left??40,p=a&&"right"===c&&d>0?d:r?.right??o.margin?.right??40,f=o.axes?.find(t=>"bottom"===t.orient),g=o.axes?.find(t=>"top"===t.orient),y=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=f??g,b=y??m,v=f?"bottom":g?"top":"bottom",w=y?"left":m?"right":"left",k="top"===v?0:e.height,A="right"===w?e.width:0,S="top"===v?-1:1,M="right"===w?1:-1,_=x?.extent??o.axisExtent,P=b?.extent??o.axisExtent,L="exact"===_?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),$="exact"===P?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),R=x?.tickValues??hd(t.x,ud(x,L),_),C=x?.tickFormat||o.xFormat||o.tickFormatTime||Rd,T=yd({values:R,scale:t.x,format:C}),O=T.reduce((t,e)=>Math.max(t,md(e.label)),0),I=xd({candidates:T,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(O+8,55)):Math.max(55,O+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:C}),z=b?.tickValues??hd(t.y,ud(b,$),P),F=b?.tickFormat||o.yFormat||o.tickFormatValue||Rd,N=t=>F(t),E=xd({candidates:yd({values:z,scale:t.y,format:N}),scale:t.y,minPixelDistance:22,includeMax:b?.includeMax,extentMode:P,hasExplicitTickValues:!!b?.tickValues,format:N}),D=!!(x?.autoRotate&&I.length>1&&e.width/Math.max(I.length-1,1)<I.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),W=sd(I),B=sd(E),j=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),X=ld(x?.axisStyle,{stroke:l.border,strokeWidth:1}),G=ld(b?.axisStyle,{stroke:l.border,strokeWidth:1}),V="right"===w?e.width+p-15:15-h;return wd("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&vd("line",{x1:0,y1:k,x2:e.width,y2:k,...X}),x?.jaggedBase&&vd("path",{d:cd(v,e.width,e.height),fill:"none",...X}),I.map((t,e)=>{const o=bd(x?.landmarkTicks,t,e,I);return wd("g",{transform:`translate(${t.pixel},${k})`,children:[vd("line",{y2:5*S,...X}),fd(t.label)?vd("text",{y:S*(D?12:18),textAnchor:D?"end":id(x?.tickAnchor,t.pixel===W.min,t.pixel===W.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:D?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):gd({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"xtick-"+e)}),j&&vd("text",{x:e.width/2,y:"top"===v?-(D?58:40):e.height+(D?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:j}),!1!==b?.baseline&&!b?.jaggedBase&&vd("line",{x1:A,y1:0,x2:A,y2:e.height,...G}),b?.jaggedBase&&vd("path",{d:cd(w,e.width,e.height),fill:"none",...G}),E.map((t,e)=>{const o=bd(b?.landmarkTicks,t,e,E);return wd("g",{transform:`translate(${A},${t.pixel})`,children:[vd("line",{x2:5*M,...G}),fd(t.label)?vd("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:rd(b?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):gd({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"ytick-"+e)}),Y&&vd("text",{x:V,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${V}, ${e.height/2})`,children:Y})]})}(y.scales,{width:u,height:d},t,o,b,i,l,!!c):null,_=S?function(t){const{scales:e,layout:o,props:n,theme:i,leftAxis:r,rightAxis:s,margin:a,axisChrome:l,hasRenderedLegend:c}=t;if(!r||!s)return null;const u=me(i),d=s.extent??n.axisExtent,h="exact"===d?Math.max(2,ud(s,5)):Math.min(ud(s,5),Math.max(2,Math.floor(o.height/30))),p=s.tickValues??hd(e.y,h,d),f=s.tickFormat||n.yFormat||n.tickFormatValue||dd,g=t=>f(t),y=xd({candidates:yd({values:p,scale:e.y,format:g}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:g}),m=sd(y),x=s.label??n.yLabelRight,b=ld(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=n.legendPosition??"right",w=Je(n.legendLayout,l?.rightAxis),k=o.width+(c&&"right"===v&&w>0?w:a.right)-15;return Wd("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&Dd("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&Dd("path",{d:cd("right",o.width,o.height),fill:"none",...b}),y.map((t,e)=>{const n=bd(s.landmarkTicks,t,e,y);return Wd("g",{transform:`translate(${o.width},${t.pixel})`,children:[Dd("line",{x2:5,...b}),fd(t.label)?Dd("text",{x:8,textAnchor:"start",dominantBaseline:rd(s.tickAnchor,t.pixel===m.min,t.pixel===m.max),fontWeight:n?600:400,fontSize:n?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:t.label}):gd({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&Dd("text",{x:k,y:o.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${k}, ${o.height/2})`,children:x})]})}({scales:y.scales,layout:{width:u,height:d},props:t,theme:o,leftAxis:t.axes?.find(t=>"left"===t.orient),rightAxis:t.axes?.find(t=>"right"===t.orient),margin:i,axisChrome:l,hasRenderedLegend:!!c}):null;let P;const L=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.scales.y},layout:{width:u,height:d},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:b,onRender:t=>{P=t}}):null;e&&(e.evidence=Ba({frameType:"xy",width:n[0],height:n[1],marks:v.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:P,xDomain:Wa(y.scales.x?.domain?.()),yDomain:Wa(y.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const $=t.svgPreRenderers&&y.scales?t.svgPreRenderers.map((t,e)=>{try{return jd(ja.Fragment,{children:t(y.scene,y.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Ya.renderToStaticMarkup(Cd(Yd(Bd,{children:[m,$,w,jd("defs",{children:jd("clipPath",{id:A,children:jd("rect",{x:0,y:0,width:u,height:d})})}),jd("g",{clipPath:`url(#${A})`,children:k}),M,_,L,x,y.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}import*as Gd from"react";import*as Vd from"react-dom/server.browser";import{scaleBand as Hd,scaleLinear as qd}from"d3-scale";var Ud=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,o){if(e&&"function"==typeof t.pieceStyle){const n=t.pieceStyle(e,o);return n&&!n.fill&&o?{...n,fill:this.getColorFromScheme(t,o)}:n}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&o?{fill:ne(t.barColors,o)??"#007bff"}:{fill:o?this.getColorFromScheme(t,o):"#007bff"}}resolveSummaryStyle(t,e,o){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,o):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const o=this.colorSchemeMap.get(e);if(o)return o;const n=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||Jt,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function Kd(t,e,o){const n="function"==typeof t?t(o?e.w:e.h):t;return"number"==typeof n&&Number.isFinite(n)?Math.max(0,n):0}function Zd(t){const e=t.getSymbol;return e?_(e,t.config.symbolMap):null}function Qd(t,e,o,n,i,r,s){t.push(e?{type:"symbol",x:n,y:i,size:Math.PI*r*r,symbolType:e(o),style:s,datum:o}:{type:"point",x:n,y:i,r:r,style:s,datum:o})}function Jd(t,e){const{columns:o,config:n,resolvePieceStyle:i}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===n.chartType?n.innerRadius||60:0,l=-Math.PI/2+(n.startAngle||0)*Math.PI/180,c=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,u=null!=n.sweepAngle&&360>n.sweepAngle,d=Object.values(o),h=d.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),p=u&&!h&&d.length>1&&(n.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],o=e.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:e.pctStart,h=l+u*c,f=l+(u+("number"==typeof o?._pct?o._pct:e.pct))*c,g=i(e.pieceData[0],e.name),y=0===t,m=t===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:f,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:g,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:p&&(x.roundedEnds={start:y,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as th}from"d3-array";function eh(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:th(t,.25)??o,median:th(t,.5)??(o+n)/2,q3:th(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as oh}from"d3-scale";var nh={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h="horizontal"===c,p=i.normalize,f=[];if(s){const t=new Set;for(const e of Object.values(n))for(const o of e.pieceData){const e=s(o);t.has(e)||(t.add(e),f.push(e))}}else f.push("_default");for(const t of Object.values(n)){const e=new Map;for(const o of t.pieceData){const t=s?s(o):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const n=e.get(t);n.total+=r(o),n.pieces.push(o)}let o=0;if(p)for(const t of e.values())o+=Math.abs(t.total);let n=0,i=0;for(const r of f){const c=e.get(r);if(!c)continue;let f=c.total;p&&o>0&&(f/=o);const g=a(c.pieces[0],s?r:t.name),y={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:t.name};if(d){const e=l(0>f?i:n+f),o=0>f?l(i+f)-l(i):l(n)-l(n+f);u.push(al(t.x,e,t.width,Math.abs(o),g,y,r)),0>f?i+=f:n+=f}else if(h){const e=l(0>f?i+f:n),o=0>f?l(i)-l(i+f):l(n+f)-l(n);u.push(al(e,t.x,Math.abs(o),t.width,g,y,r)),0>f?i+=f:n+=f}}}const g="vertical"===c;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=g?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}if(void 0!==i.roundedTop){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const o=e.datum?.category||"";t.has(o)||t.set(o,[]),t.get(o).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),o=e.filter(t=>0>(t.datum?.__aggregateValue??0));if(t.length>0){const e=t.reduce(g?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=Kd(i.roundedTop,e,g);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(g?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=Kd(i.roundedTop,t,g);e>0&&(t.roundedTop=e)}}}return u},clusterbar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h=[],p=new Set;for(const t of Object.values(n))for(const e of t.pieceData){const t=s?s(e):"_default";p.has(t)||(p.add(t),h.push(t))}const f=h.length||1;for(const t of Object.values(n)){const e=t.width/f,o=.2*e,n=e-o,i=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";i.has(t)||i.set(t,[]),i.get(t).push(e)}for(let s=0;h.length>s;s++){const c=i.get(h[s])||[];for(const i of c){const c=r(i),p=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(al(r,Math.min(a,d),n,Math.abs(a-d),p,i,h[s]))}else{const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(al(Math.min(a,d),r,Math.abs(d-a),n,p,i,h[s]))}}}}for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum),o=Kd(i.roundedTop,t,d);o>0&&(t.roundedTop=o),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}return u},point:function(t,e){const{scales:o,columns:n,getR:i,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,p=Zd(t),f=2*Math.PI,g=-Math.PI/2;for(const t of Object.values(n))for(const e of t.pieceData){const o=e.__rIndex??0,n=e.__rValue??i(e),l=h&&r[o]||a,y=s(e,t.name),m=y.r||5;let x,b;if(d){const e=g+(t.pctStart+t.pct/2)*f,o=l(n);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=l(n)):(x=l(n),b=t.middle);Qd(c,p,e,x,b,m,y)}return c},swarm:function(t,e){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="vertical"===a,u=Zd(t);for(const t of Object.values(n)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const n=t.pieceData[o],a=i(n),d=r(n,t.name),h=d.r||4,p=(7919*o%100/100-.5)*e*.8;Qd(l,u,n,c?t.middle+p:s(a),c?s(a):t.middle+p,h,d)}}return l},pie:Jd,donut:Jd,boxplot:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d=!1!==i.showOutliers;for(const e of Object.values(n)){const o=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===o.length)continue;const n=o[0],i=o[o.length-1],l=th(o,.25)??n,h=th(o,.5)??(n+i)/2,p=th(o,.75)??i,f=p-l,g=l-1.5*f,y=p+1.5*f,m=o.find(t=>t>=g)??n,x=[...o].reverse().find(t=>y>=t)??i,b=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const o=r(t);if(g>o||o>y){const n=u?e.middle:a(o),i=u?a(o):e.middle;v.push({px:n,py:i,value:o,datum:t})}}if(c.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(l),medianPos:a(h),q3Pos:a(p),maxPos:a(x),stats:{n:o.length,min:m,q1:l,median:h,q3:p,max:x,mean:o.reduce((t,e)=>t+e,0)/o.length},style:b,datum:e.pieceData,category:e.name,outliers:v}),d)for(const e of v)c.push({type:"point",x:e.px,y:e.py,r:3,style:{fill:b.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:b.cursor},datum:e.datum})}return c},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d=i.bins||20,h=!1!==i.showIQR;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/d||1,l=Array(d).fill(0);for(const t of e)l[Math.min(Math.floor((t-o)/i),d-1)]++;const p=kt(l,1),f=t.width/2*.9;let g;if(u){g=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);g+=` L ${t.middle+l[e]/p*f} ${n}`}g+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);g+=` L ${t.middle-l[e]/p*f} ${n}`}g+=" Z"}else{g=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)g+=` L ${a(o+(e+.5)*i)} ${t.middle-l[e]/p*f}`;g+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)g+=` L ${a(o+(e+.5)*i)} ${t.middle+l[e]/p*f}`;g+=" Z"}const y=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const i=th(e,.25)??o,r=th(e,.5)??(o+n)/2,s=th(e,.75)??n;m={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const x=u?{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))}:{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width};c.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:eh(e),style:y,datum:t.pieceData,category:t.name})}return c},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,p=d?+d[1]:void 0;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,n]=St(e),i=null!=h&&isFinite(h)?h:o,d=null!=p&&isFinite(p)?p:n,f=(d-i)/c||1,g=Array(c).fill(0);for(const t of e)i>t||t>d||g[Math.min(Math.floor((t-i)/f),c-1)]++;const y=e.length,m=kt(g,1),x=s(t.pieceData[0],t.name);for(let e=0;c>e;e++){if(0===g[e])continue;const o=(u?g[e]/y:g[e]/m)*t.width*.9,n=a(i+e*f),r=a(i+(e+1)*f);l.push(al(Math.min(n,r),t.x+t.width-o,Math.abs(r-n),o,x,{bin:e,count:g[e],range:[i+e*f,i+(e+1)*f],category:t.name},t.name))}}return l},ridgeline:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u=i.bins||20,d="horizontal"===l,h=i.amplitude||1.5;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/u||1,l=Array(u).fill(0);for(const t of e)o>t||t>n||l[Math.min(Math.floor((t-o)/i),u-1)]++;const p=kt(l,1),f=s(t.pieceData[0],t.name),g=t.width*h;let y;if(d){const e=t.x+t.width;y=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)y+=` L ${a(o+(t+.5)*i)} ${e-l[t]/p*g}`;y+=` L ${a(n)} ${e} Z`}else{const e=t.x;y=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const n=a(o+(t+.5)*i);y+=` L ${e+l[t]/p*g} ${n}`}y+=` L ${e} ${a(n)} Z`}const m=d?{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width}:{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))};c.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:m,stats:eh(e),style:{...f,fillOpacity:f.fillOpacity??.5},datum:t.pieceData,category:t.name})}return c},timeline:function(t,e){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="horizontal"===a;for(const t of Object.values(n))for(const e of t.pieceData){const o=i(e);if(!o)continue;const[n,a]=o,u=r(e,t.name);if(c){const o=s(Math.min(n,a)),i=s(Math.max(n,a));l.push(al(o,t.x,i-o,t.width,u,e,t.name))}else{const o=s(Math.max(n,a)),i=s(Math.min(n,a));l.push(al(t.x,o,t.width,i-o,u,e,t.name))}}return l},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,l=!1!==t.config.showLabels,c=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const t of c)for(const e of t.pieceData){const t=i?i(e):"_default";d.has(t)||(d.add(t),u.push(t))}const h=u.length>1&&"_default"!==u[0],p=[];let f=0;for(const t of c){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}p.push({col:t,groups:e,stepTotal:o}),h||o>f&&(f=o)}if(h)for(const t of p){let e=0,o=0;for(let n=0;u.length>n;n++){const i=t.groups.get(u[n]);i&&(n%2==0?e+=i.total:o+=i.total)}const n=Math.max(e,o);n>f&&(f=n)}if(0===f)return s;const g=new Map;for(const t of u){const e=p[0].groups.get(t);g.set(t,e?.total??0)}const y=p[0].stepTotal,m=h?.95*a:.9*e.width,x=oh().domain([0,f]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;p.length>e;e++){const o=p[e],n=o.col,i=0===e,c=n.width,d=.55*c,f=n.x+(c-d)/2,m=new Map;if(h){let t=0;for(const e of u){const n=o.groups.get(e);n&&(t+=x(n.total))}let e=a,c=a;for(let h=0;u.length>h;h++){const p=u[h],y=o.groups.get(p);if(!y)continue;const b=x(y.total),v=h%2==0,w=v?e:c-b;v?e+=b:c-=b;const k=r(y.pieces[0],p),A=g.get(p)??y.total,S={...y.pieces[0],__funnelValue:y.total,__funnelPercent:A>0?y.total/A*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:p};l&&(0===h&&(S.__funnelStepLabel=n.name,S.__funnelStepLabelX=a,S.__funnelStepLabelY=f,S.__funnelRowWidth=t),S.__funnelValueLabelX=w+b/2,S.__funnelValueLabelY=f,S.__funnelBarW=b),s.push(al(w,f,b,d,k,S,p)),m.set(p,{x:w,y:f,w:b,h:d})}}else{const t=o.stepTotal,e=x(t),c=a-e/2,h=u[0],p="_default"!==h,g=o.groups.get(h)?.pieces[0]??n.pieceData[0],b=p?h:n.name,v=r(g,b),w=y>0?t/y*100:0,k={...g,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:p?h:n.name};l&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=f,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=f,k.__funnelBarW=e),s.push(al(c,f,e,d,v,k,b)),m.set(h,{x:c,y:f,w:e,h:d})}if(e>0&&v.size>0){const e=h?u:[u[0]];for(const i of e){const e=v.get(i),a=m.get(i);if(!e||!a)continue;const l=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),c={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:l.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:l.cursor},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],l=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),c.push(t))}const d=c.length>1&&"_default"!==c[0],h=[];for(const t of l){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:t,groups:e,stepTotal:o})}const p=new Map;for(const t of c){const e=h[0]?.groups.get(t);p.set(t,e?.total??0)}const f=s.r,g=d?c.length:1,y=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],o=e.col,n=0===t,i=t>0?h[t-1]:null,s=o.width/g,l=s*y,u=s-l;for(let t=0;c.length>t;t++){const h=c[t],g=e.groups.get(h);if(!g)continue;const y=g.total,m=p.get(h)??y,x=m>0?y/m*100:0,b=i?.groups.get(h),v=n?0:Math.max(0,(b?.total??y)-y),w=o.x+t*s+l/2,k=f(y),A=f(0)-k,S=r(g.pieces[0],d?h:o.name),M={...g.pieces[0],__barFunnelValue:y,__barFunnelPercent:x,__barFunnelIsFirstStep:n,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:f(y+v)};if(a.push(al(w,k,u,A,S,M,d?h:o.name)),v>0){const t=f(y+v),e=k-t,n={...S},i={...g.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(al(w,t,u,e,n,i,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:n,getR:i,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:l}=o,c=[],u="horizontal"===l,d=t.config.gradientFill,h=u?"left":"bottom",p=new Map,f=e=>{const o=p.get(e);if(void 0!==o)return o;const n="function"==typeof t.config.roundedTop?t.config.roundedTop(e.width):t.config.roundedTop,i="number"==typeof n&&Number.isFinite(n)?Math.max(0,n):0;return p.set(e,i),i},g=t.config.trackFill;if(g){const t="string"==typeof g?g:g.color,e="string"==typeof g?1:g.opacity??1,[o,i]=a.range(),r=Math.min(o,i),s=Math.abs(i-o);for(const o of Object.values(n)){const n={fill:t,opacity:e},i=u?al(r,o.x,s,o.width,n,null,"__track__"):al(o.x,r,o.width,s,n,null,"__track__"),a=f(o);a>0&&(i.cornerRadii={tl:a,tr:a,br:a,bl:a}),c.push(i)}}for(const t of Object.values(n)){let e=0;const o=c.length,n=f(t);for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const l=r?r(o):t.name,p=s(o,l);let f;if(u){const i=a(e),r=a(e+n);f=al(i,t.x,r-i,t.width,p,o,l)}else{const i=a(e+n),r=a(e);f=al(t.x,i,t.width,r-i,p,o,l)}d&&(f.fillGradient=d,f.roundedEdge=h),c.push(f),e+=n}if(n>0&&c.length>o){const t=c.slice(o),e=t[0],i=t[t.length-1];1===t.length?e.cornerRadii={tl:n,tr:n,br:n,bl:n}:u?(e.cornerRadii={tl:n,bl:n},i.cornerRadii={tr:n,br:n}):(e.cornerRadii={bl:n,br:n},i.cornerRadii={tl:n,tr:n})}}return c}},ih=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],rh=["scene-style","data-paint","accessibility","evidence"],sh=(t,e)=>({retainedData:t,invalidations:e}),ah=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],lh=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ch=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],uh=["scene-geometry","data-paint","accessibility","evidence"],dh=["scene-style","data-paint","accessibility","evidence"],hh=[],ph={chartType:sh("rebuild",ah),runtimeMode:sh("rebuild",ah),categoryAccessor:sh("rebuild",ah),valueAccessor:sh("rebuild",ah),oAccessor:sh("rebuild",ah),rAccessor:sh("rebuild",ah),stackBy:sh("rebuild",ah),groupBy:sh("rebuild",ah),timeAccessor:sh("rebuild",ah),accessorRevision:sh("rebuild",ah),colorAccessor:sh("rebuild",dh),symbolAccessor:sh("rebuild",uh),connectorAccessor:sh("rebuild",uh),dataIdAccessor:sh("rebuild",uh),projection:sh("preserve",lh),extentPadding:sh("preserve",lh),axisExtent:sh("preserve",lh),rExtent:sh("preserve",lh),oExtent:sh("preserve",lh),multiAxis:sh("preserve",lh),normalize:sh("preserve",lh),bins:sh("preserve",lh),oSort:sh("preserve",ch),barPadding:sh("preserve",ch),roundedTop:sh("preserve",ch),baselinePadding:sh("preserve",ch),innerRadius:sh("preserve",ch),cornerRadius:sh("preserve",ch),startAngle:sh("preserve",ch),sweepAngle:sh("preserve",ch),trackFill:sh("preserve",ch),showOutliers:sh("preserve",ch),showIQR:sh("preserve",ch),amplitude:sh("preserve",ch),connectorOpacity:sh("preserve",ch),showLabels:sh("preserve",ch),dynamicColumnWidth:sh("rebuild",ch),customLayout:sh("preserve",ch),layoutConfig:sh("preserve",ch),layoutMargin:sh("preserve",ch),symbolMap:sh("preserve",uh),pieceStyle:sh("preserve",dh),summaryStyle:sh("preserve",dh),connectorStyle:sh("preserve",dh),gradientFill:sh("preserve",dh),colorScheme:sh("preserve",dh),themeCategorical:sh("preserve",dh),themeSemantic:sh("preserve",dh),themeSequential:sh("preserve",dh),themeDiverging:sh("preserve",dh),barColors:sh("preserve",dh),decay:sh("preserve",dh),pulse:sh("preserve",dh),staleness:sh("preserve",dh),layoutSelection:sh("preserve",dh),windowSize:sh("preserve",hh),windowMode:sh("preserve",hh),clock:sh("preserve",hh),transition:sh("preserve",hh),introAnimation:sh("preserve",hh),onLayoutError:sh("preserve",hh)},fh=sh("preserve",ch),gh=class{constructor(){this.tracker=new o}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},ih)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},rh):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=ph[n]??fh;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as yh}from"d3-quadtree";var mh=class{constructor(t){this.rExtent=new q,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new gh,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Ud,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=t,this.buffer=new U(t.windowSize),this.getO=wt(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>mt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new q)):(this.getR=mt(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=wt(t.stackBy),this.getGroup=wt(t.groupBy),this.getColor=wt(t.colorAccessor),this.getSymbol=wt(t.symbolAccessor),this.getConnector=wt(t.connectorAccessor),this.getDataId=wt(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new U(t.windowSize))}syncPulseTimestampBuffer(){var t,e,o,n;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,o=this.timestampBuffer,n=this.currentTime(),t?null!=o&&o.capacity===e.capacity&&o.size===e.size?o:Il(e,n):null)}currentTime(){return this.config.clock?.()??qa()}ingest(t){const e=this.currentTime();if(this.lastIngestTime=e,this._dataVersion++,t.bounded){this.buffer.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();t.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),Ol(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)zl(this.buffer,o,this.timestampBuffer,e),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of t.inserts){const t=zl(this.buffer,o,this.timestampBuffer,e);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=t&&this.evictValueExtent(t)}}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}pushValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.push(e[0]),this.rExtent.push(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].push(this.rAccessors[e](t));this.rExtent.push(this.getR(t))}else this.rExtent.push(this.getR(t))}evictValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.evict(e[0]),this.rExtent.evict(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].evict(this.rAccessors[e](t));this.rExtent.evict(this.getR(t))}else this.rExtent.evict(this.getR(t))}getRawRange(t){const e=this.config.valueAccessor||this.config.rAccessor;if(!e)return null;const o="function"==typeof e?e(t):t[e];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",l=e.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let p,f;if(d){p=Hd().domain(l).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;f=qd().domain(c).range([n,o])}else u?(p=Hd().domain(l).range([0,t.height]).padding(h),f=qd().domain(c).range([0,t.width])):(p=Hd().domain(l).range([0,t.width]).padding(h),f=qd().domain(c).range([t.height,0]));this.scales={o:p,r:f,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((n,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(o,n);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const l=a-s,c=l>0?l*(e.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?qd().domain([s,a]).range([0,t.width]):qd().domain([s,a]).range([t.height,0])}):[];let g=s;this.rAccessors.length>1&&(g=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(g,l,p,a,t),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(g,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=y,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(e)?e[t]:e;return"string"==typeof o?o:"value"+t}resolveCategories(t){const e=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,n="auto"===e?void 0:e;let i=null;if(o){i=new Set;for(const e of t)i.add(this.getO(e))}const r=i?Array.from(this.categories).filter(t=>i.has(t)):Array.from(this.categories);if(o&&void 0===n){const t=Math.max(50,3*i.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;i.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===n)return r;if("function"==typeof n)return r.sort(n);const s=new Map;for(const e of t){const t=this.getO(e);s.set(t,(s.get(t)||0)+Math.abs(this.getR(e)))}return r.sort("asc"===n?(t,e)=>(s.get(t)||0)-(s.get(e)||0):(t,e)=>(s.get(e)||0)-(s.get(t)||0))}computeValueDomain(t,e){return function(t){const{data:e,chartType:o,projection:n,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=t,p=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let f=0,g=0;if("bar"===o&&d&&i)f=0,g=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=c(n),i=u(n);0>i?o.set(e,(o.get(e)||0)+i):t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>g&&(g=e);for(const t of o.values())f>t&&(f=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=c(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e),f>e&&(f=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=c(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>g&&(g=e),f>e&&(f=e)}else{const t=h[0],e=h[1];t!==1/0&&(f=t),e!==-1/0&&(g=e)}r&&(null!=r[0]&&(f=r[0]),null!=r[1]&&(g=r[1]));const y="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(y&&null==r?.[0]&&null==r?.[1]&&(f>0&&(f=0),0>g&&(g=0)),"bar-funnel"!==o&&"exact"!==l){const t=g-f,e=t>0?t*p:1,n=y&&!a&&0===f,i=y&&!a&&0===g||"swimlane"===o;null!=r?.[0]||n||(f-=e),null!=r?.[1]||i||(g+=e)}return[f,g]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,n,i){return function(t){const{data:e,oExtent:o,oScale:n,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:l}=t,c=Object.create(null),u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===i)for(const t of e)d+=Math.abs(l(t));let h=null;if(s&&"radial"!==i){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let n;n="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,n),t+=n}const e=("horizontal"===i?r.height:r.width)-n.padding()*n.step()*o.length;if(t>0)for(const[o,n]of h)h.set(o,n/t*e)}let p=0,f=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(l(e)),0),i=d>0?o/d:0;let r,s;h?(r=f,s=h.get(t)||n.bandwidth(),f+=s+n.padding()*n.step()):(r=n(t)??0,s=n.bandwidth()),c[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:e,pct:i,pctStart:p},p+=i}return c}({data:t,oExtent:e,oScale:o,projection:n,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(t,e);let n;try{n=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=Sl("ordinal",t,e,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",t);try{this.config.onLayoutError?.(o)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;const i=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of i)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(i,this.config.layoutSelection??null)}return wl({label:"ordinal customLayout",nodes:i,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),i}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),n=nh[this.config.chartType];let i=n?n(o,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:o,config:n,getConnector:i,getO:r}=t;if(!i||!o)return[];const s=[],{projection:a}=o,l=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const o=i(e);if(!o)continue;let n,s;"point"===t.type?(n=t.x,s=t.y):(n=t.x+t.w/2,s=t.y+("vertical"===a?0:t.h/2)),l.has(o)||l.set(o,[]),l.get(o).push({x:n,y:s,datum:e,category:r(e)})}const c=o.o.domain(),u=n.connectorStyle;for(const[e,o]of l)if(o.length>=2){o.sort((t,e)=>c.indexOf(t.category)-c.indexOf(e.category));for(let n=0;o.length-1>n;n++){const i=o[n],r=o[n+1],a="function"==typeof u?u(i.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:i.x,y1:i.y,x2:r.x,y2:r.y,style:a,datum:i.datum,group:e})}}return s}(o,i);i=[...t,...i]}return i}buildLayoutContext(t,e){const o=this.config,n=o.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Rr(o.colorScheme,o.themeCategorical,Jt),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:n,plot:"radial"===r.projection?{x:-e.width/2,y:-e.height/2,width:e.width,height:e.height}:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:o.themeSemantic??{},categorical:[...i]},resolveColor:Cr(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Ua(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=Ka(t);return this._datumIndexCache={version:this._dataVersion,map:e},e}getCategoryIndexMap(t){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const e=function(t,e){const o="function"==typeof e,n=o?null:e||"category",i=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=o?e(s):s[n],l=i.get(a);l?l.push(r):i.set(a,[r])}return i}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,o=0;for(const n of t)"point"===n.type&&!1!==n.interactive&&(e++,n.r>o&&(o=n.r));if(500>=e)return{quadtree:null,maxRadius:o};const n=Array(e);let i=0;for(const e of t)"point"===e.type&&!1!==e.interactive&&(n[i++]=e);return{maxRadius:o,quadtree:yh().x(t=>t.x).y(t=>t.y).addAll(n)}}(this.scene);this._pointQuadtree=t.quadtree,this._maxPointRadius=t.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(t,e){if(!this.config.decay)return;const o=e.length;if(1>=o)return;const n=this.getDatumIndexMap(e);for(const e of t){if("connector"===e.type||"violin"===e.type||"boxplot"===e.type||"wedge"===e.type)continue;if(!e.datum)continue;const t=n.get(e.datum);if(null==t)continue;const i=this.computeDecayOpacity(t,o);e.style={...e.style,opacity:(e.style?.opacity??1)*i}}}applyPulse(t,e,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let l=!1;for(const c of e){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const e=c.category;if(!e)continue;let n=0;for(const s of i(e)??[]){const e=o.get(s);null!=e&&(n=Math.max(n,Za(t,e,r)))}l=Qa(c,n,s)||l;continue}if(null==c.datum)continue;const e=n.get(c.datum);if(null==e)continue;const u=o.get(e);l=Qa(c,null==u?0:Za(t,u,r),s,a)||l}return l}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),o)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const t=new Map,e=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let n;for(let i=0;this.scene.length>i;i++){const r=this.scene[i],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,o?{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}:{x:e,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===n&&(n=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:n,endAngle:n,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(t,e){if("point"===t.type){const o=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,n=e.get(o)||0;return e.set(o,n+1),`${o}:${n}`}if("rect"===t.type){const o=t.datum?null!=t.datum.category&&""!==t.datum.category?t.datum.category+"":(this.getO(t.datum)??"")+"":"",n=`r:${t.group||""}:${o}`,i=e.get(n)||0;return e.set(n,i+1),0===i?n:`${n}:${i}`}return"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=this.getNodeKey(o,t);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity??o.style.fillOpacity}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity??o.style.fillOpacity}):"wedge"===o.type&&this.prevPositionMap.set(n,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const t=this.config.transition.duration??300;if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}let e=!1;const o=new Set,n=new Map;for(let t=0;this.scene.length>t;t++){const i=this.scene[t],r=this.getNodeKey(i,n);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,(s.x!==i.x||s.y!==i.y||void 0!==s.r&&s.r!==i.r)&&(i._targetX=i.x,i._targetY=i.y,i._targetR=i.r,i.x=s.x,i.y=s.y,void 0!==s.r&&(i.r=s.r),e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},e=!0);else if("rect"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.x===i.x&&s.y===i.y&&s.w===i.w&&s.h===i.h||(i._targetX=i.x,i._targetY=i.y,i._targetW=i.w,i._targetH=i.h,i.x=s.x,i.y=s.y,i.w=s.w??i.w,i.h=s.h??i.h,e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i.style={...i.style,opacity:0},e=!0);else if("wedge"===i.type)if(s)o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.startAngle===i.startAngle&&s.endAngle===i.endAngle||(i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle,i.startAngle=s.startAngle,i.endAngle=s.endAngle,e=!0);else{i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle;const t=i.startAngle;i.startAngle=t,i.endAngle=t,i.style={...i.style,opacity:0},this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:t,endAngle:t,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,n]of this.prevPositionMap)if(!o.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:n.x,y:n.y,r:n.r??3,style:{opacity:n.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:n.x,y:n.y,w:n.w??0,h:n.h??0,style:{opacity:n.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((n.startAngle??0)+(n.endAngle??0))/2,o={type:"wedge",cx:n.x,cy:n.y,innerRadius:n.innerRadius??0,outerRadius:n.outerRadius??100,startAngle:n.startAngle??0,endAngle:n.endAngle??0,style:{opacity:n.opacity??1},datum:null,category:t.slice(2),_targetStartAngle:e,_targetEndAngle:e,_targetOpacity:0,_transitionKey:t};this.exitNodes.push(o)}e=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),e&&(this.activeTransition={startTime:this.currentTime(),duration:t})}advanceTransition(t){if(!this.activeTransition)return!1;const e=Va(t,this.activeTransition),o=Ga(e,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const t of this.scene){const e=t._transitionKey;if(e)if("point"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Ha(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Ha(n.x,t._targetX,o),t.y=Ha(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Ha(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Ha(n?n.opacity??1:0,t._targetOpacity,o)}if(void 0===t._targetX)continue;const n=this.prevPositionMap.get(e);if(!n)continue;t.x=Ha(n.x,t._targetX,o),t.y=Ha(n.y,t._targetY,o),void 0!==n.w&&(t.w=Ha(n.w,t._targetW,o),t.h=Ha(n.h,t._targetH,o))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style={...t.style,opacity:Ha(n?n.opacity??1:0,t._targetOpacity,o)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const n=this.prevPositionMap.get(e);n&&void 0!==n.startAngle&&(t.startAngle=Ha(n.startAngle,t._targetStartAngle,o),t.endAngle=Ha(n.endAngle,t._targetEndAngle,o))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}"point"===e.type?void 0!==e._targetX?(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0):void 0!==e._targetR&&(e.r=e._targetR,e._targetR=void 0):"rect"===e.type?void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0):"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Xa(t),o=this.getDataId,n=t=>e.has(o(t));Fl(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=Xa(t),n=this.getDataId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach((t,e)=>{this.categories.add(this.getO(t)),i.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();this._categoryIndexCache=null,this.buffer.forEach(t=>{this.categories.add(this.getO(t)),this.pushValueExtent(t)})}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t&&t.colorScheme!==e.colorScheme||"themeCategorical"in t&&t.themeCategorical!==e.themeCategorical||"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!yt(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!yt(t.oAccessor,e.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();let n=!1;("categoryAccessor"in t||"oAccessor"in t)&&(yt(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=wt(this.config.categoryAccessor||this.config.oAccessor,"category"),n=!0));let i=!1;if("valueAccessor"in t||"rAccessor"in t){const t=this.config.valueAccessor||this.config.rAccessor,o=e.valueAccessor||e.rAccessor,n=Array.isArray(t)?t:[t],r=Array.isArray(o)?o:[o];if(i=n.length!==r.length||n.some((t,e)=>!yt(t,r[e])),i){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>mt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new q)):(this.getR=mt(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!yt(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?wt(this.config.stackBy):void 0),"groupBy"in t&&!yt(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?wt(this.config.groupBy):void 0),"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?wt(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!yt(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?wt(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!yt(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?wt(this.config.connectorAccessor):void 0),(n||i||"accessorRevision"in t&&t.accessorRevision!==e.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Xl(mh);import*as xh from"react";import{jsx as bh,jsxs as vh}from"react/jsx-runtime";function wh(t){return"connector"===t.node.type}function kh(t,e,o,n){if(2>t.length)return null;const i=t[0].node,r=i.style.fill;if(!r||"none"===r)return null;const s=yc(`${e?e+"-":""}connector-${o}-${n}-hatch`),a=ot(r)?et(r,s):null,l=[`${i.x1},${i.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return Ac(vh(xh.Fragment,{children:[a&&bh("defs",{children:a}),bh("polygon",{points:l,fill:a?`url(#${s})`:gc(r,"#999"),opacity:i.style.fillOpacity??i.style.opacity??.3,"data-semiotic-connector-fill":i.group||"_default"})]}),i,`ordinal-connector-fill-${o}-${n}`)}function Ah(t,e,o){const n=new Map;for(const e of t){if(!wh(e))continue;const t=e.node.group||"_default",o=n.get(t);o?o.push(e):n.set(t,[e])}if(0===n.size)return;const i=Array.from(n.values()).map((t,n)=>vh("g",{children:[kh(t,e,o,n),t.map(t=>t.element)]},`ordinal-connectors-${o}-${n}`)),r=t[0],s=wh(r)?null:r.element;for(const t of n.values())for(const e of t)e.element=null;r.element=vh(xh.Fragment,{children:[i,s]},"ordinal-connector-run-"+o)}function Sh(t){const e=Vc({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>Dc(e,o,t.idPrefix)});let o=0;for(let n=0;e.length>n;){if(e[n].renderedByBackend){n++;continue}let i=n+1;for(;e.length>i&&!e[i].renderedByBackend;)i++;Ah(e.slice(n,i),t.idPrefix,o++),n=i}return e}import{jsx as Mh,jsxs as _h}from"react/jsx-runtime";import{Fragment as Ph,jsx as Lh,jsxs as $h}from"react/jsx-runtime";var Rh=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function Ch(t,e){const o=ye(t.theme),n=t.size||[500,400],i=qe({...zd,...t.margin},t.title),r=Ve(t.title),s=Ht(t.data),a=t.showLegend?iu(s,t.colorAccessor||t.stackBy||t.groupBy):[],l=function(t){const e=t.projection??"vertical",o=!1!==t.showAxes&&"radial"!==e;return{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasValueLabel:t.hasCategoryLabel),leftAxis:{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasCategoryLabel:t.hasValueLabel)}}}({showAxes:t.showAxes,projection:t.projection,hasCategoryLabel:!(!t.categoryLabel&&!t.oLabel),hasValueLabel:!(!t.valueLabel&&!t.rLabel)});Ld(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=$d({props:{...t,axisChrome:l},categories:a,theme:o,size:n,margin:i,hasTitle:r}),u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h=t.projection||"vertical",p="radial"===h,f=t.colorScheme||o.colors.categorical,g={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:ce(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:f,themeCategorical:o.colors.categorical,themeSemantic:Rt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},y=new mh(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Id(t.backgroundGraphics,n,i,y.scales),x=Id(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,projection:h,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Vd.renderToStaticMarkup(Cd(m||x||t.annotations?$h(Ph,{children:[m,a,x,y.customLayoutOverlays]}):null,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=me(o),a=n?n+"-":"",l="vertical"===r.projection,c=hd(r.r,5,i);return vd("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return vd("line",{x1:0,y1:n,x2:e.width,y2:n,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return vd("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(y,{width:u,height:d},o,b,t.axisExtent):null;let w=null;if(y.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=Ad(t),n=new Set;for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");w=Array.from(n).map((t,n)=>function(t){const{id:e,background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return _h("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Mh("rect",{width:a,height:a,fill:o}),Mh("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Mh("line",{x1:r,y1:0,x2:r,y2:a,stroke:n,strokeWidth:i})]},e)}({id:`funnel-hatch-${e}-${n}`,background:t,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(n).forEach((t,o)=>i.set(t,`funnel-hatch-${e}-${o}`));for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${i.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const k=Sh({nodes:y.scene,renderMode:t.renderMode,idPrefix:b}),A=k.map(t=>t.element),S=!1!==t.showAxes?function(t,e,o,n,i,r,s,a=!1){const l=t.scales;if(!l)return null;if("radial"===l.projection)return null;const c=me(n),u="vertical"===l.projection,d=t.columns,h=o.categoryFormat||o.oFormat,p=o.valueFormat||o.rFormat,f=o.categoryLabel||o.oLabel,g=o.valueLabel||o.rLabel,y=o.legendPosition??"right",m=Je(o.legendLayout,s?.leftAxis),x=a&&"left"===y&&m>0?m:r?.left??o.margin?.left??40,b=Object.values(d).map((t,e)=>({pixel:t.middle,label:h?h(t.name,e):t.name})),v=hd(l.r,5,o.axisExtent).map(t=>({pixel:l.r(t),label:(p||Rd)(t)}));return $h("g",u?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Lh("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,o)=>$h("g",{transform:`translate(${t.pixel},${e.height})`,children:[Lh("line",{y2:5,stroke:c.border,strokeWidth:1}),fd(t.label)?Lh("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):gd({label:t.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oxtick-"+o)),f&&Lh("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:f}),Lh("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,e)=>$h("g",{transform:`translate(0,${t.pixel})`,children:[Lh("line",{x2:-5,stroke:c.border,strokeWidth:1}),Lh("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oytick-"+e)),g&&Lh("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:g})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Lh("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,o)=>$h("g",{transform:`translate(${t.pixel},${e.height})`,children:[Lh("line",{y2:5,stroke:c.border,strokeWidth:1}),Lh("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oxtick-"+o)),g&&Lh("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),Lh("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,e)=>$h("g",{transform:`translate(0,${t.pixel})`,children:[Lh("line",{x2:-5,stroke:c.border,strokeWidth:1}),fd(t.label)?Lh("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):gd({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oytick-"+e)),f&&Lh("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:f})]})}(y,{width:u,height:d},t,o,b,i,l,!!c):null;let M;const _=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,xAccessor:"string"==typeof t.oAccessor?t.oAccessor:void 0,yAccessor:"string"==typeof t.rAccessor?t.rAccessor:void 0,idPrefix:b,onRender:t=>{M=t}}):null;if(e){const o=y.scales.o?.domain?.();e.evidence=Ba({frameType:"ordinal",width:n[0],height:n[1],marks:k.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:M,yDomain:Wa(y.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const P=p&&t.centerContent?function(t,e,o){if(!Gd.isValidElement(t))return null;if("string"!=typeof t.type||!Rh.has(t.type))return null;const n=t,i="text"===n.type?Gd.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return Lh("g",{className:"semiotic-radial-center-content",transform:`translate(${e},${o})`,pointerEvents:"none",children:i})}(t.centerContent,i.left+u/2,i.top+d/2):null,L=p&&t.centerContent?P??Lh("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:Lh("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,$=$h(Ph,{children:[v,A,S,_,x,y.customLayoutOverlays]});return Vd.renderToStaticMarkup(Cd($h(Ph,p?{children:[m?Lh("g",{transform:`translate(${-u/2},${-d/2})`,children:m}):null,$]}:{children:[m,$]}),{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:p?`translate(${i.left+u/2},${i.top+d/2})`:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,defs:w,outerElements:L,idPrefix:t._idPrefix}))}import*as Th from"react-dom/server.browser";function Oh(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function Ih(t,e){var o,n=[],i=[],r=[],s={},a=[];function l(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&l(e)})}function c(t){var e,n,d=!1;for(i.push(t),r[t]=!0,e=0;a[t].length>e;e++)(n=a[t][e])===o?(u(o,i),d=!0):r[n]||(d=c(n));if(d)l(t);else for(e=0;a[t].length>e;e++){var h=s[n=a[t][e]];h||(s[n]=h={}),h[n]=!0}return i.pop(),d}function u(t,o){var i=[].concat(o).concat(t);e?e(i):n.push(i)}function d(e){!function(e){for(var o=0;t.length>o;o++)o>=e&&t[o]||(t[o]=[]),t[o]=t[o].filter(function(t){return t>=e})}(e);for(var o,n=function(t){for(var e=t.length,o=Array(e),n=Array(e),i=Array(e),r=Array(e),s=Array(e),a=Array(e),l=0;e>l;++l)o[l]=-1,n[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function p(e){var l=[e],c=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;c.length>0;){var p=t[e=c[c.length-1]];if(p.length>r[e]){for(var f=r[e];p.length>f;++f){var g=p[f];if(0>o[g]){o[g]=n[g]=u,i[g]=!0,u+=1,l.push(g),c.push(g);break}i[g]&&(n[e]=0|Math.min(n[e],n[g])),0>s[g]||a[e].push(s[g])}r[e]=f}else{if(n[e]===o[e]){var y=[],m=[],x=0;for(f=l.length-1;f>=0;--f){var b=l[f];if(i[b]=!1,y.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){l.length=f;break}}d.push(y);var v=Array(x);for(f=0;m.length>f;f++)for(var w=0;m[f].length>w;w++)v[--x]=m[f][w];h.push(v)}c.pop()}}}for(l=0;e>l;++l)0>o[l]&&p(l);for(l=0;h.length>l;l++){var f=h[l];if(0!==f.length){f.sort(function(t,e){return t-e}),c=[f[0]];for(var g=1;f.length>g;g++)f[g]!==f[g-1]&&c.push(f[g]);h[l]=c}}return{components:d,adjacencyList:h}}(t),i=n.components.filter(function(t){return t.length>1}),r=1/0,s=0;i.length>s;s++)for(var a=0;i[s].length>a;a++)r>i[s][a]&&(r=i[s][a],o=s);var l=i[o];return!!l&&{leastVertex:r,adjList:t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var p=d(o);if(o=p.leastVertex,a=p.adjList){for(var f=0;a.length>f;f++)for(var g=0;a[f].length>g;g++){var y=a[f][g];r[+y]=!1,s[y]={}}c(o),o+=1}else o=h}return e?void 0:n}function zh(t){return t.y0-t.y1>0?"up":"down"}function Fh(t,e){return e(t.source)==e(t.target)}function Nh(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var o=0;return t.target.targetLinks.forEach(function(t){o=t.circular?o+1:o}),1>=e&&1>=o}function Eh(t){return t.target.x0-t.source.x1}function Dh(t,e){var o=Bh(t),n=Eh(e)/Math.tan(o);return"up"==zh(t)?t.y1-n:t.y1+n}function Wh(t,e){var o=Bh(t),n=Eh(e)/Math.tan(o);return"up"==zh(t)?t.y1+n:t.y1-n}function Bh(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function jh(t,e){return e(t)}function Yh(t){return Gh(t.source)}function Xh(t){return Gh(t.target)}function Gh(t){return(t.y0+t.y1)/2}function Vh(t){return t.virtual?0:t.value}function Hh(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!Fh(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!Fh(t,e)?n+1:n}),o+n}function qh(t){return t.target.depth}function Uh(t,e){return t.sourceLinks.length?t.depth:e-1}function Kh(t,e){return t.y0-e.y0}function Zh(t,e){return e.y0-t.y0}function Qh(t,e){return t.y1-e.y1}function Jh(t,e){return e.y1-t.y1}function tp(t,e){return op(t.source,e.source)||t.index-e.index}function ep(t,e){return op(t.target,e.target)||t.index-e.index}function op(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function np(t,e){return ip(t)==ip(e)?"bottom"==t.circularLinkType?Zh(t,e):Kh(t,e):ip(e)-ip(t)}function ip(t){return t.target.column-t.source.column}function rp(t,e){return sp(t)==sp(e)}function sp(t){return t.y0-t.y1>0?"up":"down"}import{min as ap}from"d3-array";function lp(t,e,o,n,i){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=ap(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var l=r.links.filter(function(t){return t.circular});return l.sort(function(t,e){return e.value-t.value}),l.forEach(function(t,e){t._circularStub=e>=4}),cp(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),cp(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,o),r.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+n,t.circularPathData.rightNodeBuffer=5,t.circularPathData.leftNodeBuffer=5,t.circularPathData.sourceWidth=t.source.x1-t.source.x0,t.circularPathData.sourceX=t.source.x0+t.circularPathData.sourceWidth,t.circularPathData.targetX=t.target.x0,t.circularPathData.sourceY=t.y0,t.circularPathData.targetY=t.y1,Fh(t,e)&&Nh(t))t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,l=t.circularLinkType,c=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==l});c.sort("bottom"==t.circularLinkType?Zh:Kh);var u=0;c.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),s=t.target.column,(c=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==l})).sort("bottom"==t.circularLinkType?Jh:Qh),u=0,c.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,o=t.y0,n=t.target.x0,i=t.y1,r=(e+n)/2;return"M"+e+","+o+"C"+r+","+o+" "+r+","+i+" "+n+","+i}(t)}),r}function cp(t,e,o){t.sort(np);var n=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,i){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(Fh(t,e)&&Nh(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;n.length>s;s++){var a=n[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&up(t,a)){var l=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=l>r?l:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function up(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as dp,max as hp,sum as pp,mean as fp,group as gp,groups as yp}from"d3-array";function mp(t){return function(){return t}}function xp(t){return t.index}function bp(t){return t.nodes}function vp(t){return t.links}function wp(t,e,o){var n=yp(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});n.forEach(function(i,r){var s=i.length;if(e)i.sort(e);else if(r>0){var a=new Map;i.forEach(function(t,e){var o,n,i,r=(n=0,i=0,(o=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Gh(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Gh(t.target)*e,n+=e}}),n>0?i/n:NaN);a.set(t,{bc:r,idx:e})}),i.sort(function(t,e){var o=a.get(t),n=a.get(e),i=o.bc,r=n.bc;if(t.circularLinkType!==e.circularLinkType){if("top"==t.circularLinkType&&"bottom"==e.circularLinkType)return-1;if("bottom"==t.circularLinkType&&"top"==e.circularLinkType)return 1;if("top"==t.circularLinkType)return-1;if("top"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return-1}return isNaN(i)||isNaN(r)?isNaN(i)?isNaN(r)?o.idx-n.idx:1:-1:i-r})}else i.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Hh(e,o)-Hh(t,o):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});i.forEach(function(e,i){e.depth==n.length-1&&1==s||0==e.depth&&1==s?(e.y0=t.y1/2-e.value*t.ky,e.y1=e.y0+e.value*t.ky):e.partOfCycle?0==Hh(e,o)?(e.y0=t.y1/2+i,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+i,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-i,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*i,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+i,e.y1=e.y0+e.value*t.ky)})})}function kp(t,e,o,n,i,r){var s=yp(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,l=r;l>0;--l)c(a*=.99,o),u();function c(e,o){var n=s.length;s.forEach(function(i){var r=i.length,s=i[0].depth;i.forEach(function(i){var a;if(i.sourceLinks.length||i.targetLinks.length)if(i.partOfCycle&&Hh(i,o)>0){var l=fp(i.sourceLinks,Xh),c=fp(i.targetLinks,Yh),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-Gh(i))*e*.3;i.y0+=d,i.y1+=d}}else if(0==s&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(s==n-1&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(1==i.targetLinks.length&&1==i.targetLinks[0].source.sourceLinks.length)a=i.y1-i.y0,i.y0=i.targetLinks[0].source.y0,i.y1=i.y0+a;else{var h=fp(i.sourceLinks,Xh),p=fp(i.targetLinks,Yh),f=((h&&p?(h+p)/2:h||p)-Gh(i))*e;i.y0+=f,i.y1+=f}})})}function u(){s.forEach(function(o){var r,s,a,l=t.y0,c=o.length;for(o.sort(e||op),a=0;c>a;++a)(s=l-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),l=r.y1+n;if((s=l-n-t.y1)>0)for(l=r.y0-=s,r.y1-=s,a=c-2;a>=0;--a)(s=(r=o[a]).y1+i-l)>0&&(r.y0-=s,r.y1-=s),l=r.y0})}}function Ap(t){t.nodes.forEach(function(t){t.sourceLinks.sort(ep),t.targetLinks.sort(tp)}),t.nodes.forEach(function(t){var e=t.y0,o=e,n=t.y1,i=n;t.sourceLinks.forEach(function(t){t.circular?(t.y0=n-t.width/2,n-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=i-t.width/2,i-=t.width):(t.y1=o+t.width/2,o+=t.width)})})}function Sp(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=xp,l=Uh,c=void 0,u=32,d=2,h=bp,p=vp;function f(){var f={nodes:h.apply(null,arguments),links:p.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=o,h.y1=n,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var o=function(t,e){var o=new Map;return gp(t,e).forEach(function(t,e){o.set(e,t[0])}),o}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var n=t.source,i=t.target;"object"!=typeof n&&(n=t.source=Oh(o,n)),"object"!=typeof i&&(i=t.target=Oh(o,i)),n.sourceLinks.push(t),i.targetLinks.push(t)})}(h,a),function(t,e){var o=0;if(null==e){for(var n=[],i=0;t.links.length>i;i++){var r=t.links[i],s=r.source.index,a=r.target.index;n[s]||(n[s]=[]),n[a]||(n[a]=[]),-1===n[s].indexOf(a)&&n[s].push(a)}var l=Ih(n);l.sort(function(t,e){return t.length-e.length});var c={};for(i=0;l.length>i;i++){var u=l[i].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||c[n]&&c[n][e]?(t.circular=!0,t.circularLinkID=o++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=o++)})}(h,c),function(t,e){var o=0,n=0;t.links.forEach(function(i){i.circular&&(i.circularLinkType=i.source.circularLinkType||i.target.circularLinkType?i.source.circularLinkType?i.source.circularLinkType:i.target.circularLinkType:n>o?"top":"bottom","top"==i.circularLinkType?o++:n++,t.nodes.forEach(function(t){jh(t,e)!=jh(i.source,e)&&jh(t,e)!=jh(i.target,e)||(t.circularLinkType=i.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),Fh(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(pp(t.sourceLinks,Vh),pp(t.targetLinks,Vh)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,o){var n,i,r;if(null!=e){t.nodes.sort(function(t,o){return e(t)<e(o)?-1:1});var s=0,a=e(t.nodes[0]);t.nodes.forEach(function(t){s=e(t)==a?s:s+1,a=e(t)==a?a:e(t),t.column=s})}for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>i.indexOf(t.target)&&!t.circular&&i.push(t.target)})});for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>i.indexOf(t.source)&&!t.circular&&i.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?o(t,r):t.column})}(h,c,l);var p=r;if(null!==s){var f=yp(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),g=hp(f,function(t){return t.length});g>1&&(p=Math.max(1,(n-e)*s/(g-1)))}(function(t,e,o){var n=yp(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var i=dp(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/pp(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=hp(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-o)/r),e.x1=e.x0+o}:function(e){e.x0=t.x0,e.x1=e.x0+o})})(h,p,i),wp(h,c,a),kp(h,c,a,p,p,u),Ap(h),lp(h,a,d,10,8),wp(h,c,a),kp(h,c,a,p,p,u),Ap(h),lp(h,a,d,10,8),function(t,e){let o=t;o.nodes.forEach(function(t){t.y+(t.y1-t.y0)>o.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-o.y1));var n=o.links.filter(function(o){return jh(o.source,e)==jh(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!rp(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=Dh(e,t);return t.y1-o}if(e.target.column>t.target.column)return Dh(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;n.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let o=t;o.nodes.forEach(function(t){var n=o.links.filter(function(o){return jh(o.target,e)==jh(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!rp(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=Wh(e,t);return t.y0-o}if(e.source.column>t.source.column)return Wh(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;n.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,o=t.links,n=!1,i=!1;if(o.forEach(function(t){"top"==t.circularLinkType?n=!0:"bottom"==t.circularLinkType&&(i=!0)}),0==n||0==i){let n=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=dp(e,function(t){return t.y0}),s=hp(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1)}),o.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,o=n(t.y0)-t.y0;t.y0=n(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+o}),t.targetLinks.forEach(function(t){t.y1=t.y1+o})})}}(h),lp(h,a,d,10,8)}(f),f}return f.update=function(t){return Ap(t),lp(t,a,d,10,8),t},f.nodeWidth=function(t){return arguments.length?(i=+t,f):i},f.nodePadding=function(t){return arguments.length?(r=+t,f):r},f.nodePaddingRatio=function(t){return arguments.length?(s=+t,f):s},f.nodes=function(t){return arguments.length?(h="function"==typeof t?t:mp(t),f):h},f.links=function(t){return arguments.length?(p="function"==typeof t?t:mp(t),f):p},f.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:mp(t),f):a},f.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:mp(t),f):l},f.nodeSort=function(t){return arguments.length?(c=t,f):c},f.iterations=function(t){return arguments.length?(u=+t,f):u},f.circularLinkGap=function(t){return arguments.length?(d=+t,f):d},f.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],o=+i[1][0],n=+i[1][1],f):[[t,e],[o,n]]},f.size=function(i){return arguments.length?(t=e=0,o=+i[0],n=+i[1],f):[o-t,n-e]},f}import{interpolateNumber as Mp}from"d3-interpolate";import{line as _p,curveLinearClosed as Pp}from"d3-shape";var Lp=t=>{let e,o,n,i,r,s,a,l,c;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,o=t.y1-t.sankeyWidth/2,n=t.y1+t.sankeyWidth/2,i=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=Mp(r,s),l=a(.5),c=a(.5),`M${e},${r}C${e},${l} ${o},${c} ${o},${s}L${n},${s}C${n},${c} ${i},${l} ${i},${r}Z`;const u=t.sankeyWidth/2,d=Mp(t.source.x1,t.target.x0),{pathD:h}=Si({sx:t.source.x1,sTop:t.y0-u,sBot:t.y0+u,tx:t.target.x0,tTop:t.y1-u,tBot:t.y1+u,cp1X:d(.5),cp2X:d(.5)});return h};function $p(t){const e=t.sankeyWidth/2,o=(t._circularWidth??t.sankeyWidth)/2,n=t.circularPathData;if(!n)return null;if("down"===t.direction)return null;if(t._circularStub){const o=n.sourceX,i=n.sourceY,r=n.targetX,s=n.targetY;if("object"!=typeof t.source||!t.source||"object"!=typeof t.target||!t.target)return null;const a=Math.max(15,Math.min(40,.33*(n.rightFullExtent-o))),l=Math.max(15,Math.min(40,.33*(r-n.leftFullExtent)));return`M${o},${i-e}L${o+a},${i-e}L${o+a},${i+e}L${o},${i+e}ZM${r},${s-e}L${r-l},${s-e}L${r-l},${s+e}L${r},${s+e}Z`}const i=n.sourceX,r=n.sourceY,s=n.targetX,a=n.targetY,l=n.rightFullExtent,c=n.leftFullExtent,u=n.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(o,15));return`M${i},${r-d*e}L${l},${r-d*e}L${l+o},${r-d*e+d*h}L${l+o},${u+d*o-d*h}L${l+o-h},${u+d*o}L${c-o+h},${u+d*o}L${c-o},${u+d*o-d*h}L${c-o},${a-d*e+d*h}L${c-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${c+o},${a+d*e}L${c+o},${u-d*o}L${l-o},${u-d*o}L${l-o},${r+d*e}L${i},${r+d*e}Z`}var Rp={left:function(t){return t.depth},right:function(t,e){return e-1-t.height},center:function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?Math.min.apply(Math,t.sourceLinks.map(qh))-1:0},justify:Uh},Cp={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i="vertical"===o.orientation?"down":"right",r=o.nodeAlign||"justify",s=o.nodeWidth??15,a=o.nodePaddingRatio??.05,l=o.iterations??100,c=t.map(t=>({...t})),u=e.map(t=>({...t,source:bt(t.source),target:bt(t.target),value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===i?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const h=Sp().extent(d).links(u).nodes(c).nodeAlign(Rp[r]||Uh).nodeId(t=>t.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of c)t>n.x0&&(t=n.x0),n.x1>e&&(e=n.x1),o>n.y0&&(o=n.y0),n.y1>i&&(i=n.y1);for(const n of u){if(!n.circular||!n.circularPathData)continue;const r=n.circularPathData,s=(n._circularWidth??n.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),o>r.verticalFullExtent-s&&(o=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=e-t,s=i-o,a=n[0],l=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>l)){const e=Math.min(a/r,l/s),n=-t*e+(a-r*e)/2,i=-o*e+(l-s*e)/2;for(const t of c)t.x0=t.x0*e+n,t.x1=t.x1*e+n,t.y0=t.y0*e+i,t.y1=t.y1*e+i;for(const t of u)if(t.y0=t.y0*e+i,t.y1=t.y1*e+i,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const o=t.circularPathData;o.sourceX=o.sourceX*e+n,o.targetX=o.targetX*e+n,o.sourceY=o.sourceY*e+i,o.targetY=o.targetY*e+i,o.rightFullExtent=o.rightFullExtent*e+n,o.leftFullExtent=o.leftFullExtent*e+n,o.verticalFullExtent=o.verticalFullExtent*e+i,o.rightInnerExtent=o.rightInnerExtent*e+n,o.leftInnerExtent=o.leftInnerExtent*e+n,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+i,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+i,o.rightSmallArcRadius*=e,o.rightLargeArcRadius*=e,o.leftSmallArcRadius*=e,o.leftLargeArcRadius*=e,o.sourceWidth*=e,o.rightNodeBuffer*=e,o.leftNodeBuffer*=e,o.arcRadius*=e}}}const p=new Map;for(const e of t)p.set(e.id,e);for(const t of c){const e=p.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const f=new Map;for(const t of e)if(t._edgeKey)f.set(t._edgeKey,t);else{const e=bt(t.source),o=bt(t.target);f.set(`${e}\0${o}`,t)}for(const t of u){const e=bt(t.source),o=bt(t.target),n=f.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(n){n.y0=t.y0,n.y1=t.y1,n.sankeyWidth=t.width??0,n.circular=!!t.circular,n.circularPathData=t.circularPathData,n._circularWidth=t._circularWidth,n._circularStub=t._circularStub,n.path=t.path,n.circularLinkType=t.circularLinkType,n.direction=i;const r=p.get(e),s=p.get(o);r&&(n.source=r),s&&(n.target=s)}}},buildScene(t,e,o,n){const i="vertical"===o.orientation?"down":"right",r=o.nodeStyle,s=o.edgeStyle,a=o.edgeOpacity??.5,l=o.edgeColorBy||"source",c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:B,u=new Map;t.forEach((t,e)=>{u.set(t.id,c[e%c.length])});const d=[],h=[],p=[],f=new Map;for(const e of t){const t=e.x1-e.x0,o=e.y1-e.y0;if(0>=t||0>=o)continue;const n=r?r(H(e,"nodeStyle")):{},s={fill:n.fill||u.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity,cursor:n.cursor};f.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===i?{type:"rect",x:e.y0,y:e.x0,w:o,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:o,style:s,datum:e,id:e.id,label:e.id})}const g=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of g){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";i="function"==typeof l?l(t)||i:"target"===l?f.get(n.id)||u.get(n.id)||i:f.get(e.id)||u.get(e.id)||i;const r=s?s(H(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,o=t.sankeyWidth/2,n=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),l=r.fill||i;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-o}L${e.sourceX+n},${e.sourceY-o}L${e.sourceX+n},${e.sourceY+o}L${e.sourceX},${e.sourceY+o}Z`,style:{fill:l,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+n}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-o}L${e.targetX-s},${e.targetY-o}L${e.targetX-s},${e.targetY+o}L${e.targetX},${e.targetY+o}Z`,style:{fill:l,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let c;(c=t.circular&&t.circularPathData?$p(t):Lp(t),c)&&h.push({type:"bezier",pathD:c,bezierCache:t.bezier,style:{fill:r.fill||i,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor},datum:t})}if(!1!==o.showLabels){const e=xt(o.nodeLabel);for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=e?e(o):o.id;if(!s)continue;let a,l,c;"down"===i?(a=o.y0+(o.y1-o.y0)/2,l=o.x1+14,c="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,c="end"):(a=o.x1+6,c="start"),l=o.y0+r/2),p.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:p}}};import{chord as Tp,ribbon as Op}from"d3-chord";import{arc as Ip}from"d3-shape";var zp=B,Fp={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(n[0],n[1])/2,l=a-r,c=n[0]/2,u=n[1]/2,d=(h=o.valueAccessor)?"function"==typeof h?h:t=>t[h]??1:t=>t.value??1;var h;const p=new Map;for(let e=0;t.length>e;e++)p.set(t[e].id,e);const f=t.length,g=Array.from({length:f},()=>Array.from({length:f},()=>0));for(const t of e){const e=bt(t.source),o=bt(t.target),n=p.get(e),i=p.get(o);if(void 0===n||void 0===i)continue;const r=d(t);g[n][i]=r}const y=Tp().padAngle(i);s&&y.sortGroups(s);const m=y(g),x=m.groups,b=Ip().innerRadius(l).outerRadius(a);for(const e of x){const o=t[e.index],n=b.centroid({innerRadius:l,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=n[0]+c,o.y=n[1]+u,o.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const v=new Map;for(const e of t)v.set(e.id,e);for(const t of e){const e=bt(t.source),o=bt(t.target),n=v.get(e),i=v.get(o);n&&(t.source=n),i&&(t.target=i)}const w=new Map;for(const t of e){const e=bt(t.source),o=bt(t.target);w.set(`${e}\0${o}`,t)}for(const e of m){const o=t[e.source.index].id,n=t[e.target.index].id,i=w.get(`${o}\0${n}`)||w.get(`${n}\0${o}`);i&&(i.__chordData=e)}},buildScene(t,e,o,n){const{groupWidth:i=20,edgeOpacity:r=.5}=o,s=Math.min(n[0],n[1])/2,a=s-i,l=n[0]/2,c=n[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",p=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:zp,f=new Map;t.forEach((t,e)=>{f.set(t.id,p[e%p.length])});const g=Op().radius(a),y=[],m=[],x=[];for(let e=0;t.length>e;e++){const o=t[e],n=o.__arcData;if(!n)continue;let i;if(u){const t=u(H(o,"nodeStyle"));i=("string"==typeof t.fill?t.fill:void 0)||f.get(o.id)||p[e%p.length]}else i=f.get(o.id)||p[e%p.length];const r=u?u(H(o,"nodeStyle")):{};y.push({type:"arc",cx:l,cy:c,innerR:a,outerR:s,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:{fill:i,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const n=g(e);if(!n)continue;const i=Np(n,l,c);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(H(t,"edgeStyle"));s=("string"==typeof e.fill?e.fill:void 0)||s}else{const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;"target"===h&&o?s=f.get(o.id)||s:e&&(s=f.get(e.id)||s)}const a=d?d(H(t,"edgeStyle")):{};m.push({type:"ribbon",pathD:i,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor},datum:t})}if(!1!==o.showLabels){const e=xt(o.nodeLabel),n=s+12;for(const o of t){const t=o.__arcData;if(!t)continue;const i=e?e(o):o.id;if(!i)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:l+Math.cos(s)*n,y:c+Math.sin(s)*n,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:y,sceneEdges:m,labels:x}}};function Np(t,e,o){const n=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return t;const i=[];let r=0;for(;n.length>r;){const t=n[r];if("M"===t||"L"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("C"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;3>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("Q"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;2>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("A"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&(i.push(Number(n[r])+e+""),r++),n.length>r&&(i.push(Number(n[r])+o+""),r++);else"Z"===t||"z"===t?(i.push(t),r++):(i.push(n[r]),r++)}return i.join(" ")}import{hierarchy as Ep,tree as Dp,cluster as Wp,treemap as Bp,pack as jp,partition as Yp,treemapBinary as Xp}from"d3-hierarchy";var Gp=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Vp(t){const[e,o,n]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(t);return.299*e+.587*o+.114*n>150?"#222":"#fff"}function Hp(t,e,o){const n=e.nodeIDAccessor;return"function"==typeof n?n(t.data)+"":"string"==typeof n&&void 0!==t.data[n]?t.data[n]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+o}function qp(t){if(!t)return null;if("function"==typeof t){const e=t;return t=>e(t.data??t)}return e=>e.data?.[t]||e[t]||e.id}function Up(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Gp}function Kp(t){return Array.isArray(t.colorScheme)&&t.colorScheme.length>0?t.colorScheme[0]:t.themeSemantic?.primary?t.themeSemantic.primary:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical[0]:"#4d430c"}function Zp(t,e,o,n,i){if("horizontal"===i){const i=(t+o)/2;return`M ${t},${e} C ${i},${e} ${i},${n} ${o},${n}`}if("radial"===i){const i=(t+o)/2;return`M ${t},${e} Q ${i},${e} ${i},${(e+n)/2} T ${o},${n}`}{const i=(e+n)/2;return`M ${t},${e} C ${t},${i} ${o},${i} ${o},${n}`}}var Qp={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;if(!i)return;const r=o.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(o.childrenAccessor),a=o.hierarchySum,l="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,c=Ep(i,s);c.sum(l),c.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=n;switch(r){case"tree":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=Dp();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"cluster":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=Wp();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"treemap":!function(t,e,o,n){const i=e.padding??4,r=e.paddingTop??0,s=Bp().size([o,n]).tile(Xp).padding(i);r>0&&s.paddingTop(r),s(t)}(c,o,u,d);break;case"circlepack":!function(t,e,o,n){const i=e.padding??4;jp().size([o,n]).padding(i)(t)}(c,o,u,d);break;case"partition":!function(t,e,o,n){Yp().size([o,n]).padding(e.padding??1)(t)}(c,o,u,d)}const h=c.descendants();t.length=0,e.length=0;const p=new Map;for(let e=0;h.length>e;e++){const n=h[e],i={id:Hp(n,o,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:n.value??0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===r||"cluster"===r?Jp(i,n,o):"treemap"===r||"partition"===r?tf(i,n):"circlepack"===r&&ef(i,n),i.__hierarchyNode=n,t.push(i),p.set(n,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=p.get(t.parent),n=p.get(t);o&&n&&e.push({source:o,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,n){const i=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,n,i,r){const s=[],a=[],l=[],c=o.treeOrientation||"vertical",u="radial"===c,d=n[0]/2,h=n[1]/2,p="number"==typeof(f=o.nodeSize)?f:5;var f;for(const e of t){let t=e.x,n=e.y;u&&(t+=d,n+=h);const r=i(H(e,"nodeStyle"));let a=r.fill||Kp(o);if(o.colorByDepth&&void 0!==e.depth){const t=Up(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:n,r:p,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const g=o.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=e.x,s=e.y,l=n.x,p=n.y;u&&(i+=d,s+=h,l+=d,p+=h);const f=Zp(i,s,l,p,c),y=r(H(t,"edgeStyle"));a.push({type:"curved",pathD:f,style:{fill:"none",stroke:y.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??g,cursor:y.cursor},datum:t})}if(!1!==o.showLabels){const e=qp(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let n,i,r,s=o.x,a=o.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,o=Math.sqrt(t*t+e*e);o>0?(n=s+t/o*10,i=a+e/o*10,r=0>t?"end":"start"):(n=s,i=a-12,r="middle")}else"horizontal"===c?(o.data?.children&&0!==o.data.children.length?(n=s-p-6,r="end"):(n=s+p+6,r="start"),i=a):(n=s,i=a+p+14,r="middle");l.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(t,e,o,n,i,r);case"treemap":case"partition":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=n(H(o,"nodeStyle"));let a=s.fill||Kp(e);if(e.colorByDepth&&void 0!==o.depth){const t=Up(e);a=t[o.depth%t.length]}i.push({type:"rect",x:o.x0,y:o.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity,cursor:s.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=qp(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,l=a.y1-a.y0;if(0>=t||0>=l)continue;const c=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!c)continue;if("parent"===i&&c)continue}const u=o?o(a):a.id;if(!u)continue;if((c?30:40)>t||(c?16:14)>l)continue;let d=n(H(a,"nodeStyle")).fill||Kp(e);if(e.colorByDepth&&void 0!==a.depth){const t=Up(e);d=t[a.depth%t.length]}const h="string"==typeof d?Vp(d):e.themeSemantic?.text??"#000";r.push(c?{x:a.x0+t/2,y:a.y0+l/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,l)/6)),fill:h}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,o,0,i);case"circlepack":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.__radius??5;if(0>=t)continue;const r=n(H(o,"nodeStyle"));let s=r.fill||Kp(e);if(e.colorByDepth&&void 0!==o.depth){const t=Up(e);s=t[o.depth%t.length]}i.push({type:"circle",cx:o.x,cy:o.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7,cursor:r.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=qp(e.nodeLabel);for(const i of t){const t=i.__radius??5,s=o?o(i):i.id;if(!s)continue;if(15>t)continue;const a=!(i.data?.children&&i.data.children.length>0);let l=n(H(i,"nodeStyle")).fill||Kp(e);if(e.colorByDepth&&void 0!==i.depth){const t=Up(e);l=t[i.depth%t.length]}if(a){const o="string"==typeof l?Vp(l):e.themeSemantic?.text??"#000";r.push({x:i.x,y:i.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:o})}else r.push({x:i.x,y:i.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,o,0,i);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Jp(t,e,o){const n=o.treeOrientation||"vertical";if("radial"===n){const o=e.x,n=e.y;t.x=n*Math.cos(o-Math.PI/2),t.y=n*Math.sin(o-Math.PI/2)}else"horizontal"===n?(t.x=e.y,t.y=e.x):(t.x=e.x,t.y=e.y);t.x0=t.x-5,t.x1=t.x+5,t.y0=t.y-5,t.y1=t.y+5,t.width=10,t.height=10}function tf(t,e){t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.x=(e.x0+e.x1)/2,t.y=(e.y0+e.y1)/2,t.width=e.x1-e.x0,t.height=e.y1-e.y0}function ef(t,e){const o=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-o,t.x1=e.x+o,t.y0=e.y-o,t.y1=e.y+o,t.width=2*o,t.height=2*o,t.__radius=o}import{pie as of}from"d3-shape";function nf(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var rf={sankey:Cp,force:d,chord:Fp,tree:Qp,cluster:Qp,treemap:Qp,circlepack:Qp,partition:Qp,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;i&&function(t,e,o,n,i){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(o.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(o.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(o.orbitMode),l=o.orbitSize??2.95,c=o.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=nf(o);h.metaMap.clear(),n.length=0,i.length=0;const p=new Map;function f(t){const e=p.get(t)??0;return p.set(t,e+1),0===e?t:`${t}__${e}`}const g=e[0]/2,y=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=f(s(t));n.push({id:x,x:g,y:y,x0:g,x1:g,y0:y,y1:y,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,o,l,c,p,g,y){const m=r(e);if(!m?.length)return;const x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const A=(x+1)/b,S={id:o,depth:g,data:e,parentId:o},M=y?p/u(S)*A:p*A,_=of().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(S);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=f(s(a)),d=l+M*Math.sin(r),p=c+M*Math.cos(r)*P;n.push({id:u,x:d,y:p,x0:d,x1:d,y0:p,y1:p,width:0,height:0,value:0,depth:g,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:g,parentId:o,eccentricity:P}),i.push({source:o,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:o,target:u}}),t(a,u,d,p,M,g+1,!0)}k+=v}}(t,x,g,y,m,1,!1)}(i,n,o,t,e)},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=o.nodeSize,a="number"==typeof s?()=>s:"function"==typeof s?s:()=>6,l=[],c=[],u=[];if(!1!==o.orbitShowRings){const e=nf(o),n=new Map;for(const e of t)n.set(e.id,e);const i=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=n.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;i.has(o)||i.set(o,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:t,parentY:e,ring:o,ecc:n}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,l=(i+1)/r*Math.PI*2;c.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(l),y2:e+o*Math.cos(l)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(H(e,"nodeSize")),n=i?i(H(e,"nodeStyle")):{};l.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:n.fill||o.themeSemantic?.primary||"#6366f1",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??1,opacity:n.opacity??(0===(e.depth??0)?1:.85),cursor:n.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const d=new Map;for(const e of t)d.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:d.get(t.source),o="object"==typeof t.target?t.target:d.get(t.target);if(!e||!o)continue;if(null==e.x||null==o.x)continue;const n=r?r(H(t,"edgeStyle")):{};c.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:n.stroke||"rgba(128,128,128,0.35)",strokeWidth:n.strokeWidth??.5,opacity:n.opacity??1,cursor:n.cursor},datum:t})}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=a(H(o,"nodeSize"));if(4>=t)continue;const n="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;u.push({x:o.x,y:o.y+t+12,text:n+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:l,sceneEdges:c,labels:u}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=nf(e),n=e.orbitSpeed??.25,i=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-o.startTime)/1e3,s=n*(Math.PI/6),a=new Map;for(const e of t)a.set(e.id,e);for(const e of t){const t=o.metaMap.get(e.id);if(!t||!t.parentId)continue;const n=a.get(t.parentId);if(!n)continue;const l=t.angle+r*s*i({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=n.x+t.ring*Math.sin(l),e.y=n.y+t.ring*Math.cos(l)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)}};function sf(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function af(t){if("glyph"===t.type&&t.glyph&&"number"==typeof t.size){const e=t.cx??t.x,o=t.cy??t.y;if("number"!=typeof e||"number"!=typeof o)return null;const n=f(t.glyph,t.size);return{x:e+n.centerDx,y:o+n.centerDy,r:Math.max(1,n.radius)}}const e=t.cx??(null!=t.x&&null!=t.w?t.x+t.w/2:t.x),o=t.cy??(null!=t.y&&null!=t.h?t.y+t.h/2:t.y);return"number"!=typeof e||"number"!=typeof o?null:{x:e,y:o,r:"number"==typeof t.r?Math.max(1,t.r):"number"==typeof t.outerR?Math.max(1,t.outerR):"number"==typeof t.size?Math.max(1,G(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function lf(t){if(!t)return;const e=[];for(const o of t){const t=af(o);t&&e.push({pointId:sf(o),...t})}return e}import{Fragment as cf,jsxs as uf}from"react/jsx-runtime";function df(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var hf=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function pf(t){return t.map(t=>{const e=t.datum&&"object"==typeof t.datum?t.datum:{},o=e.data&&"object"==typeof e.data?e.data:e,n="cx"in t?t.cx:t.x+t.w/2,i="cy"in t?t.cy:t.y+t.h/2;return{...o,...null==o.id&&null!=t.id?{id:t.id}:{},x:n,y:i}})}function ff(t,e){const o=ye(t.theme),n=t.chartType||"force",i=t.size||[500,500],r=function(t){return Ed.has(t)?Nd:Fd}(n),s=qe({...r,...t.margin},t.title),a=Ve(t.title),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const n=Ht(t.nodes||[]);if(n.length>0)return iu(n,e);const i=Array.isArray(t.edges)?Ht(t.edges):[];if(0===i.length)return[];const r=df(t.sourceAccessor,"source"),s=df(t.targetAccessor,"target");return iu(Array.from(new Set(i.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];Ld(s,{props:t,categories:l,theme:o,size:i,hasTitle:a});const c=$d({props:t,categories:l,theme:o,size:i,margin:s,hasTitle:a}),u=i[0]-s.left-s.right,d=i[1]-s.top-s.bottom,h=Id(t.backgroundGraphics,i,s,null),p=Id(t.foregroundGraphics,i,s,null),f=()=>{let n;const r=t=>Number(t),a=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:r,y:r},layout:{width:u,height:d},theme:o,frameType:"network",idPrefix:t._idPrefix,onRender:t=>{n=t}}):null;return e&&(e.evidence=(e=>Ba({frameType:"network",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:e,nodeCount:0,edgeCount:0,margin:s}))(n)),Th.renderToStaticMarkup(Cd(h||p||t.annotations?uf(cf,{children:[h,a,p]}):null,{width:i[0],height:i[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))},g=function(t){return rf[t]}(n);if(!g&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const y={chartType:n,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||o.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let m,x;if(hf.has(n)){const e=t.data||t.edges;if(!e||Array.isArray(e))return f();y.__hierarchyRoot=e,m=[],x=[]}else{const e=Ht(t.nodes||[]),o=Array.isArray(t.edges)?Ht(t.edges):[];if(0===e.length&&0===o.length)return f();if(x=function(t,e){const o=df(e.sourceAccessor,"source"),n=df(e.targetAccessor,"target"),i=df(e.valueAccessor,"value");return t.map(t=>{const e=Number(i(t));return{source:o(t)+"",target:n(t)+"",value:Number.isFinite(e)?e:1,y0:0,y1:0,sankeyWidth:0,data:t}})}(o,y),0===e.length&&x.length>0){const t=new Set;for(const e of x){const o=kd(e.source),n=kd(e.target);o&&t.add(o),n&&t.add(n)}m=Array.from(t).map(t=>({id:t,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:t}}))}else m=function(t,e){const o=df(e.nodeIDAccessor,"id");return t.map(t=>({id:o(t)+"",x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t}))}(e,y)}let b=[],v=[],w=[],k=null;if(y.customNetworkLayout){const t=y.colorScheme,e=Rr(t,o.colors.categorical,B),n=Cr(e,t),i={nodes:m,edges:x,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:y.layoutConfig??{}},r=y.customNetworkLayout(i);b=r.sceneNodes??[],v=r.sceneEdges??[],w=r.labels??[],k=r.overlays??null}else if(g){g.computeLayout(m,x,y,[u,d]);const t=g.buildScene(m,x,y,[u,d]);b=t.sceneNodes,v=t.sceneEdges,w=t.labels}const A=me(o);for(const t of w)t.fill||(t.fill=A.text);const S=Vc({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"line":return _c("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||"#999",strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity},"net-edge-"+e);case"bezier":{const o=t,n=`net-bezier-${e}-hatch`,i=ot(o.style.fill)?et(o.style.fill,n):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:o.pathD,fill:i?`url(#${n})`:gc(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"ribbon":{const o=t,n=`net-ribbon-${e}-hatch`,i=ot(o.style.fill)?et(o.style.fill,n):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:o.pathD,fill:i?`url(#${n})`:gc(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"curved":{const o=t;return _c("path",{d:o.pathD,fill:gc(o.style.fill,"none"),stroke:o.style.stroke||"#999",strokeWidth:o.style.strokeWidth??1,opacity:o.style.opacity},"net-edge-"+e)}default:return null}}(t,e),t,"network-edge-cursor-"+e)}(t,e)}),M=Vc({nodes:b,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"circle":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`net-circle-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[n&&_c("defs",{children:n}),_c("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:gc(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`net-rect-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[n&&_c("defs",{children:n}),_c("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:gc(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,n=Mc().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(fc)||"",i=ot(o.style.fill)?et(o.style.fill,`net-arc-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:gc(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,n=X(o.symbolType,o.size,o.path);return _c("path",{d:n,transform:o.rotation?`translate(${o.cx},${o.cy}) rotate(${180*o.rotation/Math.PI})`:`translate(${o.cx},${o.cy})`,fill:o.style.fill?gc(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return mc(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),_=S.map(t=>t.element),P=M.map(t=>t.element),L=w.map((t,e)=>function(t,e){return _c("text",{x:t.x,y:t.y,textAnchor:t.anchor||"middle",dominantBaseline:t.baseline||"auto",fontSize:t.fontSize||11,fontWeight:t.fontWeight,fill:t.fill||"var(--semiotic-text, #333)",stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:t.paintOrder,children:t.text},"net-label-"+e)}(t,e)).filter(Boolean);let $;const R=t=>Number(t),C=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:R,y:R},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:pf(b),pointNodes:lf(b),idPrefix:t._idPrefix,onRender:t=>{$=t}}):null;return e&&(e.evidence=Ba({frameType:"network",width:i[0],height:i[1],marks:[...M.map(({node:t})=>({type:"node:"+(t.type??"node")})),...S.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:$,nodeCount:M.length,edgeCount:S.length,margin:s})),Th.renderToStaticMarkup(Cd(uf(cf,{children:[h,_,P,L,C,p,k]}),{width:i[0],height:i[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}import*as gf from"react-dom/server.browser";import{geoPath as yf}from"d3-geo";import{quadtree as mf}from"d3-quadtree";import{geoMercator as xf,geoEqualEarth as bf,geoAlbersUsa as vf,geoOrthographic as wf,geoNaturalEarth1 as kf,geoEquirectangular as Af}from"d3-geo";var Sf={mercator:xf,equalEarth:bf,albersUsa:vf,orthographic:wf,naturalEarth:kf,equirectangular:Af};function Mf(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function _f(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Pf(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function Lf(t,e){if(2>t.length)return[t];const o=.4*e,n=[];let i=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>o?(2>i.length||n.push(i),i=[r]):i.push(r)}return 2>i.length||n.push(i),n}function $f(t,e,o=24){const n=e[0]-t[0],i=e[1]-t[1],r=Math.sqrt(n*n+i*i);if(0===r)return[t,e];const s=-i/r,a=n/r,l=Math.min(.3*r,80),c=(t[0]+e[0])/2+s*l,u=(t[1]+e[1])/2+a*l,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*t[0]+2*r*i*c+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function Rf(t,e){if(2>t.length)return t;const o=e/2+1,n=[];for(let e=0;t.length>e;e++){const i=t[e];let r,s;0===e?(r=t[1][0]-i[0],s=t[1][1]-i[1]):e===t.length-1?(r=i[0]-t[e-1][0],s=i[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;n.push([i[0]+s/a*o,i[1]+-r/a*o])}return n}function Cf(t,e,o,n,i){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const l=s/a,c=-r/a,u=i/2+1;return[[t[0]+l*u,t[1]+c*u],[e[0]+l*u,e[1]+c*u]]}import{scaleLinear as Tf}from"d3-scale";var Of=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],If=["scene-style","data-paint","accessibility","evidence"],zf=(t,e)=>({retainedData:t,invalidations:e}),Ff=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Nf=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ef=["scene-geometry","data-paint","accessibility","evidence"],Df=["scene-style","data-paint","accessibility","evidence"],Wf=["overlay","accessibility","evidence"],Bf=[],jf={xAccessor:zf("rebuild",Ff),yAccessor:zf("rebuild",Ff),lineDataAccessor:zf("rebuild",Ff),pointIdAccessor:zf("rebuild",Ef),lineIdAccessor:zf("rebuild",Ef),windowSize:zf("rebuild",Ff),projection:zf("preserve",Nf),projectionExtent:zf("preserve",Nf),fitPadding:zf("preserve",Nf),lineType:zf("preserve",Nf),flowStyle:zf("preserve",Nf),graticule:zf("preserve",Nf),projectionTransform:zf("preserve",Nf),customLayout:zf("preserve",Nf),layoutConfig:zf("preserve",Nf),layoutMargin:zf("preserve",Nf),areaStyle:zf("preserve",Df),pointStyle:zf("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:zf("preserve",Df),colorScheme:zf("preserve",Df),themeCategorical:zf("preserve",Df),themeDiverging:zf("preserve",Df),themeSemantic:zf("preserve",Df),themeSequential:zf("preserve",Df),decay:zf("preserve",Df),pulse:zf("preserve",Df),layoutSelection:zf("preserve",Df),annotations:zf("preserve",Wf),autoPlaceAnnotations:zf("preserve",Wf),clock:zf("preserve",Bf),transition:zf("preserve",Bf),introAnimation:zf("preserve",Bf),onLayoutError:zf("preserve",Bf)},Yf=zf("preserve",Nf),Xf=class{constructor(){this.tracker=new o}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Of)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},If):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=jf[n]??Yf;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t),n=new Set(o.invalidations);return e.retainedDataChanged&&n.add("data"),this.tracker.record({kind:"config",keys:t},n)}};import{geoDistance as Gf,geoGraticule as Vf,geoInterpolate as Hf}from"d3-geo";function qf(t){if(null==t)return 0;if("number"==typeof t&&Number.isFinite(t)&&t>=0&&.5>t)return t;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${t+""}.`)}var Uf=class t{constructor(t){this.updateResults=new Xf,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(t){return{...t,fitPadding:qf(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??qa()}getConfiguredWindowSize(){const t=this.config.windowSize??500;if(!Number.isInteger(t)||1>t)throw Error("GeoPipelineStore windowSize must be a positive integer");return t}retainNewestLines(t=this.getConfiguredWindowSize()){this.lineData.length>t&&(this.lineData=this.lineData.slice(-t))}resizeStreamingWindow(t){if(this.pointBuffer){const e=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],n=e.slice(-t),i=o.slice(-n.length),r=this.currentTime();this.pointBuffer=new U(t),this.timestampBuffer=new U(t),n.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(i[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:qf(t.fitPadding)}:t}(t),o=this.config,n=this.getConfiguredWindowSize(),i=Object.keys(e).filter(t=>e[t]!==o[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==n;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(i,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,n=this.timestampBuffer?.toArray()??[],i=o.slice(-e),r=n.slice(-i.length),s=this.currentTime();this.pointBuffer=new U(e),this.timestampBuffer=new U(e),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();zl(this.pointBuffer,t,this.timestampBuffer,e),this.lastIngestTime=e,this.updateResults.recordData("ingest",1)}pushPointWithResult(t){return this.pushPoint(t),this.updateResults.last}pushMany(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();for(const o of t)zl(this.pointBuffer,o,this.timestampBuffer,e);this.lastIngestTime=e,this.updateResults.recordData("ingest",t.length)}pushManyWithResult(t){return this.pushMany(t),this.updateResults.last}pushLine(t){null!=t&&"object"==typeof t?(this.streaming||this.initStreaming(),this.lineData.push(t),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(t){if(!Array.isArray(t)||0===t.length)return void this.updateResults.recordNoop("ingest");const e=t.filter(t=>null!=t&&"object"==typeof t);if(0!==e.length){this.streaming||this.initStreaming();for(const t of e)this.lineData.push(t);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",e.length)}else this.updateResults.recordNoop("ingest")}removeLine(t){const{lineIdAccessor:e}=this.config;if(!e)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]),i=[];return this.lineData=this.lineData.filter(t=>!n.has(o(t)+"")||(i.push(t),!1)),i.length>0?(this.version++,this.updateResults.recordData("remove",i.length)):this.updateResults.recordNoop("remove"),i}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>n.has(o(t)+"");Fl(this.pointBuffer,this.timestampBuffer,t);const e=this.pointBuffer.remove(t);return e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}{const t=[];return this.pointData=this.pointData.filter(e=>!n.has(o(e)+"")||(t.push(e),!1)),t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(t){const e=this._customRestyle;if(e){for(const o of this.scene){const n=this._baseStyles.get(o)??o.style,i=e(o,t);o.style=i?{...n,...i}:n}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,o=this.projection,n=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],l=this.scene;this.projection=function(t){if(!t)return bf();if("string"==typeof t){const e=Sf[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),bf())}if("object"==typeof t&&"type"in t){const e=Sf[t.type],o=e?e():bf();return t.rotate&&"rotate"in o&&o.rotate(t.rotate),t.center&&"center"in o&&o.center(t.center),o}return t}(e.projection),this.geoPath=yf(this.projection),this.fitProjection(t),this.geoPath=yf(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(t,e)=>c([t,e]),invertedPoint:(t,e)=>c.invert?c.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=n,this.scales=i,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,o=t.height/2,n=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:o}));n.length>0&&this.startTransition(n)}this._hasRenderedOnce=!0,e.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(t){const e=this.projection,o=this.config,n=[...this.areas],i=Mf(o.xAccessor,"lon"),r=Mf(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=_f(o.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==n.length){if(o.projectionExtent){const[[n,i],[r,s]]=o.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[n,i],[n,s],[r,s],[r,i],[n,i]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const n=o.fitPadding??0,i=Math.min(t.width,t.height);e.scale(i/2-i*n),e.translate([t.width/2,t.height/2])}else{const i=o.fitPadding??0,r=t.width*i,s=t.height*i;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:n})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t.k),o.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=yf(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t),o.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=yf(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const o=this.projection;if(!o||!o.rotate)return;const n=this.geoPath,i=this.scales,r=[...o.rotate()];o.rotate(t),this.geoPath=yf(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(r),this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,o=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(o++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const n=Array(o);let i=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(n[i++]=t);this._quadtree=mf().x(t=>t.x).y(t=>t.y).addAll(n)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,o=this.projection,n=this.geoPath;if(e.customLayout&&this.scales){const o=e.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Rr(e.colorScheme,e.themeCategorical,Jt),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:o,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...n]},resolveColor:Cr(n,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(i)}catch(t){const o=null!==this.lastCustomLayoutResult,n=Sl("geo",t,o,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return o?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const t of s)this._baseStyles.set(t,t.style);this.restyleScene(e.layoutSelection??null)}return wl({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:t,projection:e,path:o,areas:n,points:i,lines:r,layout:s}){const a=Mf(t.xAccessor,"lon"),l=Mf(t.yAccessor,"lat"),c=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),d=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),h=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,n=Vf();e.step&&n.step(e.step);const i=o(n())||"";i&&c.push({type:"geoarea",pathData:i,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth??.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of n){const n=o(e);if(!n)continue;const i=o.centroid(e),r=o.bounds(e),s=o.area(e);c.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:Pf(t.areaStyle,e,u),datum:e,interactive:!0})}const p=_f(t.lineDataAccessor);for(const o of r){const n=p(o);if(!n||2>n.length)continue;let i=[];if("geo"===t.lineType){const t=Array(n.length);for(let e=0;n.length>e;e++)t[e]=[a(n[e]),l(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=Gf(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Hf(n,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const n=e(l(t/a));null!=n&&i.push(n)}}}else for(let t=0;n.length>t;t++){const o=n[t],r=e([a(o),l(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=Pf(t.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==n.length||2>i.length||"arc"!==t.flowStyle?2!==n.length||2>i.length||"offset"!==t.flowStyle||(i="geo"===t.lineType?Rf(i,u):Cf(i[0],i[i.length-1],0,0,u)):i=$f(i[0],i[i.length-1]);const h=Lf(i,s.width);if(h.length>1)for(const t of h)2>t.length||c.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const f=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,g=e.clipAngle?e.clipAngle()??0:0,y=g>0?g*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],x="function"==typeof e.center?e.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const o of i){const n=a(o),i=l(o);if(null!=y&&Gf([n,i],b)>y)continue;const r=e([n,i]);if(!r)continue;const s=t.pointStyle?t.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:f?f(o)+"":void 0};c.push(u)}return c}({config:e,projection:o,path:n,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const o=function(t,e,o,n){const i=t.filter(t=>"point"===t.type);if(2>i.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const l=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,c="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=i.find(t=>t.datum&&l(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const d=i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),h=kt(d,1);n>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const o=t[e];"geoarea"===o.type&&o.interactive&&t.splice(e,1)}const p="strip"===a?function(t,e,o,n,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,l=Tf().domain([0,n]).range([0,s]);e.x=r,e.y=a;const c=[];for(const i of t){if(i===e)continue;if(!i.datum){i.x=r,i.y=a;continue}const t=Number(o(i.datum)),s=r+(isFinite(t)&&t>=0&&n>0?l(t):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let t=d+1;for(;c.length>t&&3>Math.abs(c[t].x-c[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)c[d+t].node.y=a+(t-(e-1)/2)*Math.min(2.5,2*u/Math.max(1,e-1));d=t}return{cx:r,cy:a,maxCost:n,availableRadius:s,layout:"strip"}}(i,u,c,h,o):function(t,e,o,n,i,r){const s=e.x,a=e.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=Tf().domain([0,n]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),p=Math.hypot(t-s,u-a),f=Number(o(r.datum)),g=isFinite(f)&&f>=0?n>0?d(f):0:p,y=l+Math.cos(h)*g,m=c+Math.sin(h)*g;r.x=t+(y-t)*i,r.y=u+(m-u)*i}return e.x=s+(l-s)*i,e.y=a+(c-a)*i,{cx:e.x,cy:e.y,maxCost:n,availableRadius:u,layout:"radial"}}(i,u,c,h,s,o),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of i)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const o of f){const n=o.datum?.source,i=o.datum?.target;if(null!=n&&null!=i){const r=t.get(n+""),s=t.get(i+"");if(r&&s)if("fractional"===e.lineMode&&o.path.length>2){const t=o.path[0],e=o.path[o.path.length-1],n=[r[0]-t[0],r[1]-t[1]],i=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;o.path.length>t;t++)a.push(a[t-1]+Math.hypot(o.path[t][0]-o.path[t-1][0],o.path[t][1]-o.path[t-1][1]));const l=a[a.length-1];o.path=o.path.map((t,e)=>{const r=l>0?a[e]/l:e/(o.path.length-1);return[t[0]+n[0]*(1-r)+i[0]*r,t[1]+n[1]*(1-r)+i[1]*r]})}else o.path=[r,s]}}}return p}(this.scene,t,e,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const o=this.scene.filter(t=>"point"===t.type);for(let n=0;o.length>n;n++){const i=Ua(t,n,e);o[n]._decayOpacity=i,o[n].style={...o[n].style,opacity:i}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const o=this.scene.filter(t=>"point"===t.type),n=this.timestampBuffer.toArray(),i=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;o.length>a&&n.length>a;a++){const l=Za(e,n[a],t);s=Qa(o[a],l,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(t){const e=this.config.transition?.duration??300;if(0>=e)return;const o=new Map;for(const e of t)"point"===e.type&&e.pointId&&o.set(e.pointId,[e.x,e.y]);const n=this.scene.filter(t=>"point"===t.type);let i=!1;for(const t of n)if(t.pointId){const e=o.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(i=!0))}for(const t of n)t.pointId&&!o.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=Va(t,this.activeTransition),o=Ga(e),n=this.scene.filter(t=>"point"===t.type);for(const t of n){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=Ha(t.x,t._targetX,o),t.y=Ha(e,t._targetY,o)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*o})}if(e>=1){for(const t of n)null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0),null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Uf.QUADTREE_THRESHOLD=500;var Kf=Uf;function Zf(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("glyph"===o.type){const t=o,n=f(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+n.centerDx,y:t.y+n.centerDy,r:n.radius})}return e}Xl(Kf);import{Fragment as Qf,jsxs as Jf}from"react/jsx-runtime";function tg(t,e){const o=ye(t.theme),n=t.size||[t.width||600,t.height||400],i=qe({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Ve(t.title),s=Array.isArray(t.areas)?Ht(t.areas):t.areas,a=Ht(t.points),l=Ht(t.lines),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return iu(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];Ld(i,{props:t,categories:c,theme:o,size:n,hasTitle:r});const u=$d({props:t,categories:c,theme:o,size:n,margin:i,hasTitle:r}),d=n[0]-(i.left??0)-(i.right??0),h=n[1]-(i.top??0)-(i.bottom??0),p={projection:t.projection||"equalEarth",projectionExtent:t.projectionExtent,xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineIdAccessor:t.lineIdAccessor,lineType:t.lineType,flowStyle:t.flowStyle,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,colorScheme:t.colorScheme,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,onLayoutError:t.onLayoutError,themeCategorical:o.colors.categorical,themeSemantic:Rt(o),themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging},f=new Kf(p);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);f.setAreas(s)}t.points&&f.setPoints(a),t.lines&&f.setLines(l),f.computeScene({width:d,height:h});const g=Id(t.backgroundGraphics,n,i,f.scales),y=Id(t.foregroundGraphics,n,i,f.scales),m=Vc({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=ot(o.style.fill)?et(o.style.fill,`geoarea-${e}-hatch`):void 0;return Rc(Lc.Fragment,{children:[n&&$c("defs",{children:n}),$c("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:gc(o.style.fill,"#e0e0e0"),fillOpacity:o.style.fillOpacity??1,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth??.5,strokeDasharray:o.style.strokeDasharray,opacity:o._decayOpacity??1})]},"geoarea-"+e)}case"point":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`geopoint-${e}-hatch`):void 0;return Rc(Lc.Fragment,{children:[n&&$c("defs",{children:n}),$c("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:gc(o.style.fill),fillOpacity:o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o._decayOpacity??o.style.opacity??1})]},"point-"+e)}case"line":{const o=t;if(2>o.path.length)return null;const n="M"+o.path.map(t=>`${t[0]},${t[1]}`).join("L");return $c("path",{d:n,fill:"none",stroke:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth??1.5,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity??1},"line-"+e)}case"glyph":return mc(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===m.length){let r;const s=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Zf(f.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),gf.renderToStaticMarkup(Cd(g||y||t.annotations||f.customLayoutOverlays?Jf(Qf,{children:[g,s,y,f.customLayoutOverlays]}):null,{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}const x=m.map(t=>t.element);let b;const v=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Zf(f.scene),idPrefix:t._idPrefix,onRender:t=>{b=t}}):null;return e&&(e.evidence=Ba({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:b,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),gf.renderToStaticMarkup(Cd(Jf(Qf,{children:[g,x,v,y,f.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}import*as eg from"react-dom/server.browser";function og(t=[]){return t.map(t=>({id:t.id,label:t.label,count:t.count,...null!=t.secondary?{secondary:t.secondary}:{},...t.secondaryLabel?{secondaryLabel:t.secondaryLabel}:{},...null!=t.observed?{observed:t.observed}:{}}))}var ng={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function ig(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}function rg(t,e,o){const n="function"==typeof e?e(t,o):e;return{...ng,...n??{}}}function sg(t,e={},o="settled"){return t.map((t,n)=>function(t,e={},o={index:0,simulationState:"settled"}){const n=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),i={label:e.getBodyLabel?.(t)??ig(t)},r={style:rg(t,e.bodyStyle,o),datum:n,accessibleDatum:n,accessibility:i,_transitionKey:t.id};return"aabb"===t.shape.type?{type:"rect",x:t.x-t.shape.width/2,y:t.y-t.shape.height/2,w:t.shape.width,h:t.shape.height,...r}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...r}}(t,e,{index:n,simulationState:o}))}import{jsx as ag,jsxs as lg}from"react/jsx-runtime";var cg={top:0,right:0,bottom:0,left:0};function ug(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function dg(t,e={}){const{element:o,scene:n,evidence:i}=function(t,e={}){const{width:o=640,height:n=360,title:i,description:r,background:s,backgroundGraphics:a,backgroundGraphicsBackdrop:l,className:c,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:p,renderBodySVG:f,renderChrome:g,...y}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=sg(n,e,i.simulationState),s=function(t,e={}){const o=e.bodies??function(t){return t.world.bodies.map(t=>({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:{...t.shape},sleeping:t.sleeping,datum:t.datum}))}(t),n=o.filter(t=>t.sleeping).length,i=t.queue.length,r=t.sediment.reduce((t,e)=>t+e.count,0),s="settled"===t.simulationState&&0===i&&n===o.length,a=[];i>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const l=null!=e.charge&&Number.isFinite(e.charge)?function(t,e,o,n){const i=t-(e+o+n);return{charge:t,live:e,queued:o,sedimented:n,unaccounted:i,balanced:0===i}}(e.charge,o.length,i,r):void 0;return l&&!l.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:o.length,sleepingCount:n,settled:s,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:og(e.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},warnings:a}}(i,{bodies:n,projectionRows:e.projectionRows,stepsRun:o,charge:e.charge});return{snapshot:i,bodies:n,sceneNodes:r,evidence:s,stepsRun:o}}(t,y),x={...cg,...h},b=[o,n],v=ug(a,b,x),w=ug(u,b,x),k=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(d),A=i?k+"-title":void 0,S=r?k+"-desc":void 0,M=[A,S].filter(Boolean).join(" ")||void 0,_=x.left||x.top?`translate(${x.left},${x.top})`:void 0,P=Math.max(1,o-x.left-x.right),L=Math.max(1,n-x.top-x.bottom),$=k+"-plot-clip",R=_&&null!=v?ag("g",{transform:_,children:v}):v;return{element:lg("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":M,style:p,children:[i&&ag("title",{id:A,children:i}),r&&ag("desc",{id:S,children:r}),ag("defs",{children:ag("clipPath",{id:$,children:ag("rect",{width:P,height:L})})}),l&&"transparent"!==l?ag("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:n,fill:l}):null,!a&&s&&"transparent"!==s?ag("rect",{x:0,y:0,width:o,height:n,fill:s}):null,R,ag("g",{id:k+"-data-area",transform:_,clipPath:`url(#${$})`,children:m.sceneNodes.map((t,e)=>{const o=m.bodies[e],n=o&&f?f(o,t.style??{},e,k):void 0;return null!=n?Ac(n,t,e):Yc(t,e,k)})}),w,g?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:eg.renderToStaticMarkup(o),scene:n,evidence:i}}function hg(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function pg(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,hg(t.thickness)??hg(o)??hg(e.thickness)??4)}function fg(t){return t.sensorId??"stream-region-"+t.id}function gg(t){const e=fg(t),o={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("boundary"===t.collider&&"aabb"===t.shape.type){const n=t.colliderThickness??8,i=t.shape.x-t.shape.width/2,r=t.shape.x+t.shape.width/2,s=t.shape.y-t.shape.height/2,a=t.shape.y+t.shape.height/2;return[{...o,id:e+"-top",shape:{type:"segment",x1:i,y1:s,x2:r,y2:s,thickness:n}},{...o,id:e+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:n}},{...o,id:e+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:i,y2:a,thickness:n}},{...o,id:e+"-left",shape:{type:"segment",x1:i,y1:a,x2:i,y2:s,thickness:n}}]}return t.collider?[{...o,id:e+"-collider",shape:t.shape}]:[]}import{jsx as yg}from"react/jsx-runtime";function mg({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?yg("foreignObject",{x:0,y:0,width:e,height:o,children:t}):yg("text",{x:e/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:t}):null}import{scaleLinear as xg}from"d3-scale";function bg(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}import{jsx as vg,jsxs as wg}from"react/jsx-runtime";var kg={top:0,right:0,bottom:0,left:0};function Ag(e,o){const n=e.size??[e.width??600,e.height??400],i=ye(e.theme),r=void 0===e.theme?{}:Ct(i),s=e.bodyStyle,a=!1,l=e.legendPosition??"right",c=He({...kg,...e.margin},a,!!e.legend&&"top"===l);if(e.legend){const t={...c};so(c,{legend:e.legend,position:l,size:n,hasTitle:a,legendLayout:e.legendLayout}),Ue(c,t,n,l)}let u;const d=function({annotations:t,chartId:e,chartType:o,config:n,onRegionObservation:i,regionEffects:r,seed:s,size:a}){const l=function(t=[],e={}){const o=e.idPrefix?e.idPrefix+"-":"",n=[];for(const i of t){if("barrier"!==i.physics&&"sensor"!==i.physics)continue;const t=i.axis??e.defaultAxis??"x",r=pg(i,e),s=i.colliderId??`${o}${i.id}`;let a;if("x"===t){const t=hg(i.x),o=hg(i.y1)??hg(e.plotBounds?.y)??hg(i.y),n=hg(i.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??hg(i.y);if(null==t||null==o||null==n)continue;a={type:"segment",x1:t,y1:o,x2:t,y2:n,thickness:r}}else{const t=hg(i.y),o=hg(i.x1)??hg(e.plotBounds?.x)??hg(i.x),n=hg(i.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??hg(i.x);if(null==t||null==o||null==n)continue;a={type:"segment",x1:o,y1:t,x2:n,y2:t,thickness:r}}n.push({id:s,shape:a,sensor:"sensor"===i.physics,..."barrier"!==i.physics||null==i.restitution&&null==e.barrierRestitution?{}:{restitution:hg(i.restitution)??hg(e.barrierRestitution)},..."barrier"!==i.physics||null==i.friction&&null==e.barrierFriction?{}:{friction:hg(i.friction)??hg(e.barrierFriction)}})}return n}((t??[]).filter(t=>"barrier"===t.physics||"sensor"===t.physics),{idPrefix:e?e+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),c=void 0===s||void 0!==n?.kernel?.seed?n:{...n,kernel:{...n?.kernel,seed:s}},u=r.flatMap(t=>[{id:fg(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...gg(t)]),d=Object.fromEntries(r.map(t=>[fg(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,p=r.length>0;return p||u.length>0||l.length>0||null!=e||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{p&&i(t),h?.onObservation?.(t)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:[Math.max(1,n[0]-c.left-c.right),Math.max(1,n[1]-c.top-c.bottom)]}),h=new t(d);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&h.enqueue(e.initialSpawns.map(t=>({...t,spawnAt:void 0})));const p=dg(h,{...e,width:n[0],height:n[1],background:e.background??i.colors.background,bodyStyle:(t,e)=>({fill:i.colors.primary,stroke:i.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof s?s(t,e):s}),style:{...r,fontFamily:i.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:c,renderChrome:t=>{const o=function(t,e,o,n,i){const r=Math.max(1,o[0]-n.left-n.right),s=Math.max(1,o[1]-n.top-n.bottom),a=function(t){return t?.length?t.map(t=>null!=t.pointId||null==t.bodyId?t:{...t,pointId:t.bodyId+""}):t}(e.annotations),l=function(t){const{width:e,height:o,pointNodes:n=[],data:i}=t;return{scales:{x:xg().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:xg().domain([0,Math.max(1,o)]).range([0,Math.max(1,o)])},width:e,height:o,frameType:"network",pointNodes:n,data:i,xAccessor:"x",yAccessor:"y"}}({width:r,height:s,pointNodes:(c=t.bodies,c.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,bg(t))})))});var c;const u=l.scales?.x,d=l.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const p=td({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:i,frameType:"network",xAccessor:l.xAccessor,yAccessor:l.yAccessor,pointNodes:l.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),f=e.legend?Pd(e.legend,{theme:i,position:e.legendPosition,size:[o[0],o[1]],margin:n,hasTitle:!!e.title,legendLayout:e.legendLayout})??od(e.legend,o,n,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:wg("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:o[0],height:o[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[vg("g",{transform:`translate(${n.left},${n.top})`,children:p}),vg(mg,{title:e.title,totalWidth:o[0],marginTop:Math.max(n.top,28)}),f]})}}(t,e,n,c,i);return u=o.annotationRender,o.node}});return o&&(o.evidence=Ba({frameType:"physics",width:n[0],height:n[1],marks:p.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:u,extraWarnings:[...0===p.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...p.scene.evidence.warnings]})),p.svg}import*as Sg from"react-dom/server.browser";import{jsx as Mg,jsxs as _g}from"react/jsx-runtime";var Pg={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function Lg(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var $g={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",n=Pg[o],i=Lg(t.width,n.width),r=Lg(t.height,n.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):n.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:n.align,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=ye(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const o=e.locale??"en-US";if("currency"===t){const t=e.precision??2,n=new Intl.NumberFormat(o,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>n.format(t)}if("percent"===t){const t=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",o=Math.abs(t);if(1e3>o)return`${e}${Math.round(o)}ms`;const n=o/1e3;if(60>n)return`${e}${i=n,Math.round(100*i)/100+""}s`;var i;const r=n/60;if(60>r){const t=Math.floor(r),o=Math.round(n-60*t);return 0===o?`${e}${t}m`:`${e}${t}m ${o}s`}const s=r/60;if(24>s){const t=Math.floor(s),o=Math.round(r-60*t);return 0===o?`${e}${t}h`:`${e}${t}h ${o}m`}const a=Math.floor(s/24),l=Math.round(s-24*a);return 0===l?`${e}${a}d`:`${e}${a}d ${l}h`}(t);const n=new Intl.NumberFormat(o,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>n.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),p=void 0===d?"No value":(f=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${f}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var f;const g=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const o=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let n=null;for(const e of o){if(e.at>t)break;n=e}return n}(d,t.thresholds),y="string"==typeof t.color?t.color:function(t,e,o){return e||("success"===t?o.colors.success??"#2ca02c":"warning"===t?o.colors.warning??"#b26a00":"danger"===t?o.colors.danger??"#d62728":"info"===t?o.colors.info??o.colors.primary:o.colors.text)}(g?.level??"neutral",g?.color,u),m="string"==typeof t.label?t.label:void 0,x="string"==typeof t.caption?t.caption:void 0,b="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,o){const n=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,i=n&&"number"==typeof n.value&&Number.isFinite(n.value)?n.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===i?void 0:e-i);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,o);return`${s}${n&&"string"==typeof n.label?" "+n.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,o){const n=t.target&&"object"==typeof t.target?t.target:void 0;if(!n||"number"!=typeof n.value||!Number.isFinite(n.value))return;const i="string"==typeof n.label?" "+n.label:"";return 0===n.value?`target ${o(n.value)}${i}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/n.value)} of ${o(n.value)}${i}`}(t,d,h),k=[v,w,g?.label].filter(Boolean).join(" · "),A="string"==typeof t.description&&t.description||[m,p,b,k].filter(Boolean).join(", "),S="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+n.labelSize,P=_+n.captionSize+4,L="presentation"===o?r/2+.32*n.valueSize:"thumbnail"===o?r/2+.34*n.valueSize:Math.min(r-s-(k?26:4),(n.showHeader&&(m||x)?x?P+10:_+14:s)+n.valueSize),$=c+("start"===l?Math.max(n.valueSize,p.length*n.valueSize*.55):0),R=Sg.renderToStaticMarkup(_g("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-label":A,"data-semiotic-component":"BigNumber",children:[Mg("title",{children:m??p}),"string"==typeof t.description&&Mg("desc",{children:t.description}),Mg("rect",{x:n.border?.5:0,y:n.border?.5:0,width:n.border?i-1:i,height:n.border?r-1:r,rx:n.border?8:0,fill:S,stroke:n.border?M:"none"}),n.showHeader&&m&&Mg("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:m}),n.showHeader&&x&&Mg("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:x}),Mg("text",{x:c,y:L,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:p}),b&&void 0!==d&&"start"===l&&Mg("text",{x:$+6,y:L,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*n.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),n.showDetail&&k&&Mg("text",{x:c,y:Math.min(r-s,L+n.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Ba({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:A})),R}};function Rg(t,e,o){return $g[t](e,o)}import{Fragment as Cg,jsx as Tg,jsxs as Og}from"react/jsx-runtime";function Ig(t,e){switch(t){case"xy":return Xd(e);case"ordinal":return Ch(e);case"network":return ff(e);case"geo":return tg(e);case"physics":return Ag(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function zg(t){return Xd(t)}function Fg(t){return Ch(t)}function Ng(t){return ff(t)}function Eg(t){return tg(t)}var Dg=new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),Wg=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function Bg(t,e){const o=Number(t);if(!Number.isFinite(o))return t;const n=10**e,i=Math.round((o+Number.EPSILON)*n)/n;return Object.is(i,-0)?"0":i+""}function jg(t,e){const o=function(t){if(Number.isFinite(t))return Math.max(0,Math.min(8,Math.floor(t)))}(e);return void 0===o?t:t.replace(/<[^>]+>/g,t=>t.replace(/\s([\w:-]+)="([^"]*)"/g,(t,e,n)=>!Dg.has(e)||/\b(?:var|calc|url)\(/i.test(n)?t:` ${e}="${function(t,e){const o=RegExp(Wg.source,Wg.flags);let n,i="",r=0,s=!1;for(;n=o.exec(t);){const o=t.slice(r,n.index);i+=s&&0===o.length?" ":o,i+=Bg(n[0],e),r=n.index+n[0].length,s=!0}return i+t.slice(r)}(n,o)}"`))}var Yg=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],Xg=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Gg(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function Vg(t,e,o){return qg(t,e,o).svg}function Hg(t,e,o){const n={},{svg:i,frameType:r}=qg(t,e,o,n),s=n.evidence??Ba({frameType:r,width:"number"==typeof e.width?e.width:600,height:"number"==typeof e.height?e.height:400,marks:[],title:"string"==typeof e.title?e.title:void 0,description:"string"==typeof e.description?e.description:void 0,annotations:e.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=t,Yt(s,t,e),{svg:i,evidence:s}}function qg(t,e,o,n){if(Object.prototype.hasOwnProperty.call($g,t))return{svg:jg(Rg(t,e,n),o?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(Ea,t))throw Error(`Unknown chart component: "${t}". Run \`npx semiotic-ai --list\` for supported chart types.`);const i=Ea[t];var r;const s=function(t,e,o){const n=It[t||"primary"],i=t&&"primary"!==t||!o?.width?n.width:o.width,r=t&&"primary"!==t||!o?.height?n.height:o.height,s={...e,mode:t},a=ut(s,{width:e.width??i,height:e.height??r}).props,l=a.mode||t||"primary",c=It[l],u="context"===l||"sparkline"===l,d="primary"===l&&o?.width?o.width:c.width;return{mode:l,width:a.width??d,height:a.height??("primary"===l&&o?.height?o.height:c.height),showAxes:a.showAxes??c.showAxes,showGrid:a.showGrid??c.showGrid,enableHover:a.enableHover??(!!a.linkedHover||c.enableHover),showLegend:a.showLegend??c.showLegend,showLabels:a.showLabels??c.showLabels,title:u?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:u?void 0:a.xLabel,yLabel:u?void 0:a.yLabel,categoryLabel:u?void 0:a.categoryLabel,valueLabel:u?void 0:a.valueLabel,marginDefaults:zt(c.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:Ot(a.mobileInteraction,{mode:l,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(It,r)?e.mode:void 0),{...i.layout?.modeDefaults,...Gg(e,Xg)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:p,colorBy:f,legendPosition:g,...y}=e,{width:m,height:x}=s,b=[m,x],v=y.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,A=void 0!==h?h:v.margin,S=function(t){if(null==t)return;if("number"==typeof t)return{top:t,right:t,bottom:t,left:t};const e={};return"number"==typeof t.top&&(e.top=t.top),"number"==typeof t.right&&(e.right=t.right),"number"==typeof t.bottom&&(e.bottom=t.bottom),"number"==typeof t.left&&(e.left=t.left),e}(A),M="number"==typeof A?{top:A,right:A,bottom:A,left:A}:{...k,...S},_=Gg(y,Yg),P=t=>v[t]??s[t],L={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:b,margin:M,__compactMode:s.compactMode,__autoLegendMargin:!0,...void 0!==p&&{colorScheme:p},...void 0!==g&&{legendPosition:g},_idPrefix:y._idPrefix},$=i.buildProps(a,f,p,L,y);let R;switch(i.frameType){case"xy":R=Xd($,n);break;case"ordinal":R=Ch($,n);break;case"network":R=ff($,n);break;case"geo":R=tg($,n);break;case"physics":R=Ag($,n)}const C=i.renderOverlay?.($,{theme:ye(l)});if(null!=C){const t=Xt.renderToStaticMarkup(Tg(Cg,{children:C})),e=R.lastIndexOf("</svg>");R=0>e?`${R}${t}`:`${R.slice(0,e)}${t}${R.slice(e)}`}return{svg:jg(R,o?.precision),frameType:i.frameType}}function Ug(t,e={}){const{title:o,subtitle:n,theme:i,width:r=1200,height:s,layout:a={},background:l}=e,c=me(ye(i)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),n&&(h+=20),h>0&&(h+=10);const p=Math.floor((r-d-d*(u-1))/u),f=[];let g=0,y=h+d,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),o=e.props.height||300;g+t>u&&(y+=m+d,g=0,m=0),f.push({chart:e,x:d/2+g*(p+d),y:y,w:p*t+d*(t-1),h:o}),m=Math.max(m,o),g+=t}const x=s||y+m+d,b=f.map((t,e)=>{const{chart:o,x:n,y:r,w:s,h:a}=t,l={...o.props,width:s,height:a,theme:i,_idPrefix:"chart-"+e};let c;return c=o.component?Vg(o.component,l):o.frameType?Ig(o.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,Tg("g",{transform:`translate(${n},${r})`,children:Tg("foreignObject",{width:s,height:a,children:Tg("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+e)});return Xt.renderToStaticMarkup(Og("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":o||"Dashboard",style:{fontFamily:c.fontFamily},children:[o&&Tg("title",{children:o}),l&&Tg("rect",{x:0,y:0,width:r,height:x,fill:l}),o&&Tg("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleFontSize+4,fontWeight:c.titleFontWeight,fill:c.text,fontFamily:c.titleFontFamily,children:o}),n&&Tg("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:n}),b]}))}import*as Kg from"react-dom/server.browser";import{Fragment as Zg,jsx as Qg,jsxs as Jg}from"react/jsx-runtime";function ty(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=n,p=o.width||600,f=o.height||400,g=ye(o.theme),y={...o,...a&&{xExtent:a},...l&&{yExtent:l}};if(!e||0===e.length)return[];const m=i||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),x=[];for(let t=m;e.length>=t;t+=m)x.push(t);x[x.length-1]!==e.length&&x.push(e.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=qe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=p-v.left-v.right,k=f-v.top-v.bottom,A=[];if(b)for(let n=0;x.length>n;n++){const i=x[n],s=e.slice(r?Math.max(0,i-r):0,i),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,connectorAccessor:o.connectorAccessor,connectorStyle:o.connectorStyle,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||g.colors.categorical,...h&&{decay:h}},l=new mh(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&A.push(sy(l.scene,p,f,g,y))}else for(let n=0;x.length>n;n++){const i=x[n],s=e.slice(r?Math.max(0,i-r):0,i),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:l,colorScheme:o.colorScheme||g.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},b=new ac(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(A.push(ry(b.scene,p,f,g,y,v)),c>0&&n>0&&b.activeTransition){const t=c*(1e3/u);for(let e=1;c>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/c*t),A.push(ry(b.scene,p,f,g,y,v))}}return A}function ey(t,e,o={}){return e.map(e=>{try{return Vg(t,{...o,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||e.width||600}" height="${o.height||e.height||400}"></svg>`}})}function oy(t,e,o){const n=e.size??[e.width??600,e.height??400],i=ye(e.theme),r=me(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",l=e.title?`${a}-title-${o}`:void 0,c=e.description?`${a}-desc-${o}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=sg(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=Jg("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&Qg("title",{id:l,children:e.title}),e.description&&Qg("desc",{id:c,children:e.description}),s&&"transparent"!==s?Qg("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,Qg("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>Yc(t,e,`${a}-${o}`))})]});return Kg.renderToStaticMarkup(h)}function ny(e,o={}){const{fps:n=12,frameCount:i,durationSeconds:r=2,includeInitialFrame:s=!0,stepDt:a,stepsPerFrame:l,background:c}=o,u=Math.max(.001,a??e.config?.fixedDt??1/120),d=l??Math.max(1,Math.round(1/Math.max(1,n)/u)),h=i??Math.max(1,Math.ceil(r*Math.max(1,n))),p=c?{...e,background:c}:e,f=new t(e.config);e.initialSpawns?.length&&f.enqueue(e.initialSpawns,e.initialSpawnPacing);const g=[];for(s&&(f.tick(0),g.push(oy(f,p,0)));h>g.length;){for(let t=0;d>t;t+=1)f.tick(u);g.push(oy(f,p,g.length))}return g}function iy(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function ry(t,e,o,n,i,r){const s=me(n),a=qe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=e-a.left-a.right,c=o-a.top-a.bottom,u=iy(i,n),d=i.renderMode,h=t.map((t,e)=>Gc({node:t,index:e,renderMode:d,fallback:()=>Yc(t,e)}).element).filter(Boolean),p=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=me(n),a=[];for(let n=0;t.length>n;n++){const l=t[n];if("y-threshold"===l.type&&null!=l.value){let t=null;if(r)t=r(l.value);else if(i){const[e,n]=i,r=n-e;if(0===r)continue;t=o-(l.value-e)/r*o}if(null==t)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push(Jg("g",{children:[Qg("line",{x1:0,y1:t,x2:e,y2:t,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&Qg("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(o-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+n))}}return a.length>0?Qg(Zg,{children:a}):null}(i.annotations,l,c,n,i.yExtent,r?.y),f="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,y=f?"semiotic-title":void 0,m=g?"semiotic-desc":void 0,x=[y,m].filter(Boolean).join(" ")||void 0;return Kg.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[f&&Qg("title",{id:y,children:f}),g&&Qg("desc",{id:m,children:g}),u&&Qg("rect",{x:0,y:0,width:e,height:o,fill:u}),Jg("g",{transform:`translate(${a.left},${a.top})`,children:[p,h]}),f&&Qg("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:f})]}))}function sy(t,e,o,n,i){const r=me(n),s=qe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(e-s.left-s.right)/2:s.left,c=a?s.top+(o-s.top-s.bottom)/2:s.top,u=iy(i,n),d=Sh({nodes:t,renderMode:i.renderMode,idPrefix:i.idPrefix}).map(t=>t.element),h="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,f=h?"semiotic-title":void 0,g=p?"semiotic-desc":void 0,y=[f,g].filter(Boolean).join(" ")||void 0;return Kg.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":y,style:{fontFamily:r.fontFamily},children:[h&&Qg("title",{id:f,children:h}),p&&Qg("desc",{id:g,children:p}),u&&Qg("rect",{x:0,y:0,width:e,height:o,fill:u}),Qg("g",{transform:`translate(${l},${c})`,children:d}),h&&Qg("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}export{ty as generateFrameSVGs,ey as generateFrameSequence,ny as generatePhysicsFrameSVGs,Vg as renderChart,Hg as renderChartWithEvidence,Ug as renderDashboard,Eg as renderGeoToStaticSVG,Ng as renderNetworkToStaticSVG,Fg as renderOrdinalToStaticSVG,Ig as renderToStaticSVG,zg as renderXYToStaticSVG,ye as resolveTheme,jg as serializeSvgPrecision,me as themeStyles};