semiotic 3.8.5 → 3.8.7

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 (277) hide show
  1. package/CLAUDE.md +37 -10
  2. package/README.md +83 -56
  3. package/ai/behaviorContracts.cjs +88 -3
  4. package/ai/componentMetadata.cjs +5 -10
  5. package/ai/dist/mcp-server.js +99 -10
  6. package/ai/examples.md +198 -9
  7. package/ai/schema.json +2002 -165
  8. package/ai/surface-manifest.json +14 -10
  9. package/ai/system-prompt.md +9 -3
  10. package/dist/{chunk-chartContainerDataAudit-74TLKIP6.module.min.js → chunk-chartContainerDataAudit-JDSVSKGM.module.min.js} +1 -1
  11. package/dist/chunk-chunk-2JGJ5GUG.module.min.js +1 -0
  12. package/dist/chunk-chunk-2YAZHXL4.module.min.js +2 -0
  13. package/dist/chunk-chunk-3NGIKFD6.module.min.js +1 -0
  14. package/dist/{chunk-chunk-G7WFWHAD.module.min.js → chunk-chunk-4ITOQRXM.module.min.js} +1 -1
  15. package/dist/chunk-chunk-5SD6BHVW.module.min.js +2 -0
  16. package/dist/chunk-chunk-6V5VQVCT.module.min.js +2 -0
  17. package/dist/chunk-chunk-7TTBHSAG.module.min.js +2 -0
  18. package/dist/chunk-chunk-7ZDJSYKI.module.min.js +2 -0
  19. package/dist/chunk-chunk-BGHPD3RA.module.min.js +1 -0
  20. package/dist/chunk-chunk-BMRZ2SPU.module.min.js +2 -0
  21. package/dist/chunk-chunk-BNGBEY7N.module.min.js +2 -0
  22. package/dist/chunk-chunk-C7APLVQD.module.min.js +2 -0
  23. package/dist/chunk-chunk-DGWFBOGB.module.min.js +1 -0
  24. package/dist/chunk-chunk-DIVE2DRA.module.min.js +2 -0
  25. package/dist/chunk-chunk-FBUNUIPV.module.min.js +2 -0
  26. package/dist/chunk-chunk-FQPKOAIH.module.min.js +2 -0
  27. package/dist/chunk-chunk-FRO4TRXK.module.min.js +2 -0
  28. package/dist/chunk-chunk-G7QVPZUD.module.min.js +2 -0
  29. package/dist/chunk-chunk-GBPYV4FP.module.min.js +2 -0
  30. package/dist/chunk-chunk-GU2EJIDJ.module.min.js +2 -0
  31. package/dist/chunk-chunk-J5QD4RAM.module.min.js +2 -0
  32. package/dist/{chunk-chunk-LJLS6DY7.module.min.js → chunk-chunk-JWXLNZSM.module.min.js} +1 -1
  33. package/dist/chunk-chunk-KXAFCCDB.module.min.js +2 -0
  34. package/dist/chunk-chunk-LG7YKJAK.module.min.js +2 -0
  35. package/dist/{chunk-chunk-I36PJ4OC.module.min.js → chunk-chunk-LVHDZAT3.module.min.js} +1 -1
  36. package/dist/chunk-chunk-LWITSR2O.module.min.js +2 -0
  37. package/dist/chunk-chunk-MX35T6RX.module.min.js +2 -0
  38. package/dist/chunk-chunk-NH4MEAKP.module.min.js +2 -0
  39. package/dist/chunk-chunk-NJETWX42.module.min.js +2 -0
  40. package/dist/chunk-chunk-NW25WGLS.module.min.js +2 -0
  41. package/dist/{chunk-chunk-TMWIZL3K.module.min.js → chunk-chunk-OI7R7EJB.module.min.js} +1 -1
  42. package/dist/chunk-chunk-ONMLEXHR.module.min.js +2 -0
  43. package/dist/chunk-chunk-OY66GCE6.module.min.js +1 -0
  44. package/dist/chunk-chunk-PZFT457G.module.min.js +1 -0
  45. package/dist/chunk-chunk-Q3WW6JGR.module.min.js +1 -0
  46. package/dist/chunk-chunk-Q6XKQTOQ.module.min.js +1 -0
  47. package/dist/chunk-chunk-RJRM2E6P.module.min.js +1 -0
  48. package/dist/chunk-chunk-RPL7WYXI.module.min.js +1 -0
  49. package/dist/chunk-chunk-SV4XAZ3Q.module.min.js +1 -0
  50. package/dist/chunk-chunk-TSCFL235.module.min.js +1 -0
  51. package/dist/chunk-chunk-UOQRPGPK.module.min.js +2 -0
  52. package/dist/chunk-chunk-V3OAKG32.module.min.js +1 -0
  53. package/dist/chunk-chunk-WLOIUMWG.module.min.js +2 -0
  54. package/dist/chunk-chunk-XEGXX4F7.module.min.js +1 -0
  55. package/dist/chunk-chunk-XFRBLXYM.module.min.js +1 -0
  56. package/dist/chunk-chunk-Z2AJERX5.module.min.js +2 -0
  57. package/dist/chunk-chunk-ZXYDYAB7.module.min.js +2 -0
  58. package/dist/components/ai/SemioticVACPBridge.d.ts +22 -0
  59. package/dist/components/ai/chartCapabilities.d.ts +5 -3
  60. package/dist/components/ai/conversationArc.d.ts +2 -176
  61. package/dist/components/ai/conversationArcTypes.d.ts +202 -0
  62. package/dist/components/ai/readerGrounding.d.ts +12 -0
  63. package/dist/components/ai/vacpAdapter.d.ts +13 -0
  64. package/dist/components/ai/vacpAdapterActions.d.ts +2 -0
  65. package/dist/components/ai/vacpAdapterModel.d.ts +7 -0
  66. package/dist/components/ai/vacpAdapterRuntime.d.ts +26 -0
  67. package/dist/components/ai/vacpAdapterState.d.ts +3 -0
  68. package/dist/components/ai/vacpAdapterTypes.d.ts +169 -0
  69. package/dist/components/ai/vacpTypes.d.ts +160 -0
  70. package/dist/components/charts/custom/XYCustomChart.d.ts +3 -0
  71. package/dist/components/charts/geo/DistanceCartogram.d.ts +1 -1
  72. package/dist/components/charts/index.d.ts +7 -4
  73. package/dist/components/charts/ordinal/BarChart.d.ts +7 -14
  74. package/dist/components/charts/ordinal/GaugeChart.d.ts +3 -0
  75. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -0
  76. package/dist/components/charts/ordinal/StackedBarChart.d.ts +3 -0
  77. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +4 -14
  78. package/dist/components/charts/physics/ChainReactionChart.capability.d.ts +9 -0
  79. package/dist/components/charts/physics/ChainReactionChart.d.ts +29 -0
  80. package/dist/components/charts/physics/CollisionSwarmChart.d.ts +1 -1
  81. package/dist/components/charts/physics/EventDropChart.d.ts +7 -2
  82. package/dist/components/charts/physics/GaltonBoardChart.d.ts +1 -1
  83. package/dist/components/charts/physics/{PhysicsPileChart.capability.d.ts → PacketFlowChart.capability.d.ts} +1 -1
  84. package/dist/components/charts/physics/{PhysicalFlowChart.d.ts → PacketFlowChart.d.ts} +22 -6
  85. package/dist/components/charts/physics/PhysicsCustomChart.d.ts +1 -1
  86. package/dist/components/charts/physics/ProcessFlowChart.d.ts +7 -4
  87. package/dist/components/charts/physics/{PhysicalFlowChart.capability.d.ts → UnitPileChart.capability.d.ts} +1 -1
  88. package/dist/components/charts/physics/{PhysicsPileChart.d.ts → UnitPileChart.d.ts} +19 -6
  89. package/dist/components/charts/physics/crucibleChartProps.d.ts +1 -1
  90. package/dist/components/charts/physics/crucibleChartUtils.d.ts +9 -0
  91. package/dist/components/charts/physics/gauntletChartProps.d.ts +6 -1
  92. package/dist/components/charts/physics/gauntletTerminal.d.ts +61 -0
  93. package/dist/components/charts/physics/packetFlowSemantics.d.ts +6 -0
  94. package/dist/components/charts/physics/physicsHocUtils.d.ts +45 -2
  95. package/dist/components/charts/shared/auditAccessibilityStyles.d.ts +9 -0
  96. package/dist/components/charts/shared/chartSpecCore.d.ts +2 -4
  97. package/dist/components/charts/shared/gaugeGradient.d.ts +4 -8
  98. package/dist/components/charts/shared/gradient.d.ts +35 -0
  99. package/dist/components/charts/shared/hatchFill.d.ts +3 -10
  100. package/dist/components/charts/shared/hooks.d.ts +2 -50
  101. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  102. package/dist/components/charts/shared/streamPropsHelpers.d.ts +1 -2
  103. package/dist/components/charts/shared/useChartLegend.d.ts +65 -0
  104. package/dist/components/charts/shared/useChartSetup.d.ts +12 -0
  105. package/dist/components/charts/shared/useCustomChartSetup.d.ts +6 -1
  106. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +1 -0
  107. package/dist/components/charts/shared/useStreamingLegend.d.ts +1 -1
  108. package/dist/components/charts/xy/AreaChart.d.ts +25 -42
  109. package/dist/components/charts/xy/BumpChart.capability.d.ts +11 -0
  110. package/dist/components/charts/xy/BumpChart.d.ts +161 -0
  111. package/dist/components/charts/xy/DifferenceChart.d.ts +3 -10
  112. package/dist/components/charts/xy/Heatmap.d.ts +3 -0
  113. package/dist/components/charts/xy/LineChart.d.ts +6 -8
  114. package/dist/components/data/portability/capabilityBinding.d.ts +41 -0
  115. package/dist/components/data/portability/index.d.ts +2 -0
  116. package/dist/components/geometry/bumpRibbonGeometry.d.ts +36 -0
  117. package/dist/components/legendLayout.d.ts +75 -1
  118. package/dist/components/recipes/geographicDotGrid.d.ts +82 -0
  119. package/dist/components/recipes/geographicGrid.d.ts +100 -0
  120. package/dist/components/recipes/physics.d.ts +2 -0
  121. package/dist/components/recipes/physicsStageGeography.d.ts +137 -0
  122. package/dist/components/semiotic-ai.d.ts +6 -4
  123. package/dist/components/semiotic-experimental-vacp.d.ts +11 -0
  124. package/dist/components/semiotic-experimental.d.ts +6 -3
  125. package/dist/components/semiotic-geo.d.ts +5 -0
  126. package/dist/components/semiotic-network.d.ts +1 -0
  127. package/dist/components/semiotic-ordinal.d.ts +2 -0
  128. package/dist/components/semiotic-physics.d.ts +10 -6
  129. package/dist/components/semiotic-realtime-core.d.ts +1 -0
  130. package/dist/components/semiotic-recipes-core.d.ts +6 -1
  131. package/dist/components/semiotic-server-edge.d.ts +1 -1
  132. package/dist/components/semiotic-server.d.ts +1 -1
  133. package/dist/components/semiotic-xy.d.ts +4 -0
  134. package/dist/components/semiotic.d.ts +4 -4
  135. package/dist/components/server/renderEvidence.d.ts +1 -1
  136. package/dist/components/server/renderToStaticSVG.d.ts +2 -1
  137. package/dist/components/server/serverChartConfigHeatmap.d.ts +6 -0
  138. package/dist/components/server/serverChartConfigNetworkStyles.d.ts +12 -0
  139. package/dist/components/server/serverChartConfigShared.d.ts +16 -0
  140. package/dist/components/server/serverChartConfigs.d.ts +3 -2
  141. package/dist/components/server/serverChartConfigsPhysics.d.ts +2 -2
  142. package/dist/components/server/serverChartConfigsXY.d.ts +1 -1
  143. package/dist/components/server/staticLegend.d.ts +10 -2
  144. package/dist/components/server/staticSVGChrome.d.ts +14 -6
  145. package/dist/components/server/staticValue.d.ts +8 -0
  146. package/dist/components/stream/GeoSVGOverlay.d.ts +4 -10
  147. package/dist/components/stream/NetworkSVGOverlay.d.ts +2 -6
  148. package/dist/components/stream/OrdinalSVGOverlay.d.ts +2 -6
  149. package/dist/components/stream/SVGOverlay.d.ts +2 -6
  150. package/dist/components/stream/StalenessBadge.d.ts +2 -6
  151. package/dist/components/stream/geoPipelineConfig.d.ts +10 -0
  152. package/dist/components/stream/geoTypes.d.ts +3 -6
  153. package/dist/components/stream/legendRenderer.d.ts +10 -6
  154. package/dist/components/stream/ordinalTypes.d.ts +7 -31
  155. package/dist/components/stream/physics/PhysicsEvidence.d.ts +37 -0
  156. package/dist/components/stream/physics/PhysicsKernel.d.ts +1 -0
  157. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +9 -0
  158. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +2 -6
  159. package/dist/components/stream/physics/PhysicsSettledScene.d.ts +5 -0
  160. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +2 -6
  161. package/dist/components/stream/physics/physicsFramePipelineConfig.d.ts +19 -0
  162. package/dist/components/stream/physics/physicsPipelineSettle.d.ts +52 -0
  163. package/dist/components/stream/physics/physicsRegionRuntime.d.ts +23 -0
  164. package/dist/components/stream/pipelineConfig.d.ts +7 -15
  165. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +9 -69
  166. package/dist/components/stream/renderers/cornerRadii.d.ts +2 -9
  167. package/dist/components/stream/renderers/thresholdLineSegments.d.ts +12 -0
  168. package/dist/components/stream/sceneToSVGShared.d.ts +3 -5
  169. package/dist/components/stream/types.d.ts +34 -56
  170. package/dist/components/stream/xySceneBuilders/areaGradient.d.ts +4 -20
  171. package/dist/components/stream/xySceneBuilders/types.d.ts +6 -6
  172. package/dist/components/types/legendTypes.d.ts +31 -6
  173. package/dist/controls.min.js +1 -1
  174. package/dist/controls.module.min.js +1 -1
  175. package/dist/geo.min.js +1 -1
  176. package/dist/geo.module.min.js +1 -1
  177. package/dist/network.min.js +1 -1
  178. package/dist/network.module.min.js +1 -1
  179. package/dist/ordinal.min.js +1 -1
  180. package/dist/ordinal.module.min.js +1 -1
  181. package/dist/physics.min.js +1 -1
  182. package/dist/physics.module.min.js +1 -1
  183. package/dist/physicsWorker.js +1 -1
  184. package/dist/realtime.min.js +1 -1
  185. package/dist/realtime.module.min.js +1 -1
  186. package/dist/semiotic-ai-core.min.js +1 -1
  187. package/dist/semiotic-ai-core.module.min.js +1 -1
  188. package/dist/semiotic-ai.d.ts +6 -4
  189. package/dist/semiotic-ai.min.js +1 -1
  190. package/dist/semiotic-ai.module.min.js +1 -1
  191. package/dist/semiotic-data.module.min.js +1 -1
  192. package/dist/semiotic-experimental-vacp.d.ts +11 -0
  193. package/dist/semiotic-experimental-vacp.min.js +1 -0
  194. package/dist/semiotic-experimental-vacp.module.min.js +1 -0
  195. package/dist/semiotic-experimental.d.ts +6 -3
  196. package/dist/semiotic-experimental.min.js +2 -1
  197. package/dist/semiotic-experimental.module.min.js +2 -1
  198. package/dist/semiotic-geo.d.ts +5 -0
  199. package/dist/semiotic-network.d.ts +1 -0
  200. package/dist/semiotic-ordinal.d.ts +2 -0
  201. package/dist/semiotic-physics.d.ts +10 -6
  202. package/dist/semiotic-realtime-core.d.ts +1 -0
  203. package/dist/semiotic-realtime-core.min.js +1 -1
  204. package/dist/semiotic-realtime-core.module.min.js +1 -1
  205. package/dist/semiotic-recipes-core.d.ts +6 -1
  206. package/dist/semiotic-recipes-core.min.js +1 -1
  207. package/dist/semiotic-recipes-core.module.min.js +1 -1
  208. package/dist/semiotic-recipes.min.js +1 -1
  209. package/dist/semiotic-recipes.module.min.js +1 -1
  210. package/dist/semiotic-server-edge.d.ts +1 -1
  211. package/dist/semiotic-server-edge.min.js +1 -1
  212. package/dist/semiotic-server-edge.module.min.js +1 -1
  213. package/dist/semiotic-server-node.min.js +1 -1
  214. package/dist/semiotic-server-node.module.min.js +1 -1
  215. package/dist/semiotic-server.d.ts +1 -1
  216. package/dist/semiotic-utils-core.min.js +1 -1
  217. package/dist/semiotic-utils-core.module.min.js +1 -1
  218. package/dist/semiotic-utils.min.js +1 -1
  219. package/dist/semiotic-utils.module.min.js +1 -1
  220. package/dist/semiotic-xy.d.ts +4 -0
  221. package/dist/semiotic.d.ts +4 -4
  222. package/dist/semiotic.min.js +1 -1
  223. package/dist/semiotic.module.min.js +1 -1
  224. package/dist/server.min.js +1 -1
  225. package/dist/server.module.min.js +1 -1
  226. package/dist/xy.min.js +1 -1
  227. package/dist/xy.module.min.js +1 -1
  228. package/package.json +18 -2
  229. package/spec/README.md +94 -2
  230. package/spec/bindings/README.md +14 -3
  231. package/spec/v0.1/examples/annotation-provenance-reviewed-revision.json +27 -0
  232. package/spec/v0.1/examples/annotation-provenance-watcher-threshold.json +21 -0
  233. package/spec/v0.1/examples/audience-profile-executive-review.json +24 -0
  234. package/spec/v0.1/examples/audience-profile-incident-operators.json +42 -0
  235. package/spec/v0.1/examples/chart-capability-bar-comparison.json +48 -0
  236. package/spec/v0.1/examples/chart-capability-service-flow.json +54 -0
  237. package/dist/chunk-chunk-4AANPFOX.module.min.js +0 -2
  238. package/dist/chunk-chunk-5I3UZV4Q.module.min.js +0 -2
  239. package/dist/chunk-chunk-5RKXZQ2P.module.min.js +0 -1
  240. package/dist/chunk-chunk-74CCPVXB.module.min.js +0 -1
  241. package/dist/chunk-chunk-7ALTGHK6.module.min.js +0 -1
  242. package/dist/chunk-chunk-ANYDWOZF.module.min.js +0 -1
  243. package/dist/chunk-chunk-AVBI6GDT.module.min.js +0 -1
  244. package/dist/chunk-chunk-BANTPINB.module.min.js +0 -2
  245. package/dist/chunk-chunk-C4YA6TDR.module.min.js +0 -1
  246. package/dist/chunk-chunk-C57LR3YG.module.min.js +0 -1
  247. package/dist/chunk-chunk-CKMD5NV3.module.min.js +0 -2
  248. package/dist/chunk-chunk-CO5KQMGH.module.min.js +0 -1
  249. package/dist/chunk-chunk-CWQ5YIHX.module.min.js +0 -2
  250. package/dist/chunk-chunk-E6TXX6MI.module.min.js +0 -1
  251. package/dist/chunk-chunk-GMQ5AYTD.module.min.js +0 -1
  252. package/dist/chunk-chunk-JCG72SGW.module.min.js +0 -2
  253. package/dist/chunk-chunk-K3DMEW22.module.min.js +0 -1
  254. package/dist/chunk-chunk-KT2VAZMZ.module.min.js +0 -1
  255. package/dist/chunk-chunk-L6EA5V3G.module.min.js +0 -2
  256. package/dist/chunk-chunk-LJPCLYSC.module.min.js +0 -2
  257. package/dist/chunk-chunk-LRIFN2HK.module.min.js +0 -1
  258. package/dist/chunk-chunk-N5DDKCCF.module.min.js +0 -1
  259. package/dist/chunk-chunk-NEVE562N.module.min.js +0 -1
  260. package/dist/chunk-chunk-NLO44TOS.module.min.js +0 -2
  261. package/dist/chunk-chunk-PZJ2SBLL.module.min.js +0 -2
  262. package/dist/chunk-chunk-QSQVBIJA.module.min.js +0 -1
  263. package/dist/chunk-chunk-QUJ6TTLY.module.min.js +0 -1
  264. package/dist/chunk-chunk-RBIDBUT4.module.min.js +0 -2
  265. package/dist/chunk-chunk-RCF52Z42.module.min.js +0 -2
  266. package/dist/chunk-chunk-RFLAG356.module.min.js +0 -1
  267. package/dist/chunk-chunk-RPU4IZAV.module.min.js +0 -2
  268. package/dist/chunk-chunk-SKMBCFIL.module.min.js +0 -2
  269. package/dist/chunk-chunk-TAE7W424.module.min.js +0 -2
  270. package/dist/chunk-chunk-TUBMTZMU.module.min.js +0 -2
  271. package/dist/chunk-chunk-UFFEXJQY.module.min.js +0 -1
  272. package/dist/chunk-chunk-XSCHTS4D.module.min.js +0 -2
  273. package/dist/chunk-chunk-XXWSHGPL.module.min.js +0 -2
  274. package/dist/chunk-chunk-ZOAQDIJO.module.min.js +0 -1
  275. package/dist/chunk-chunk-ZXIXAPRE.module.min.js +0 -2
  276. package/dist/chunk-statisticalOverlays-QGDLRUHX.module.min.js +0 -1
  277. package/dist/chunk-statisticalOverlays-T77OKLDY.module.min.js +0 -1
@@ -0,0 +1 @@
1
+ import{accessorsEquivalent as t,annotationActivationProps as e,annotationBudget as o,annotationDensity as n,bandFromAge as i,coerceDateLikeValue as r,createStore as s,filterAnnotationsByStatus as a,isAnnotationActivationTarget as l,isNoteAnnotation as c,mulberry32 as u,parseDateLikeString as d,resolveAccessor as h,resolveRawAccessor as f,resolveResponsiveRules as p,resolveStringAccessor as y,useAnnotationActivationOptions as g,useObservationSelector as m}from"./chunk-chunk-3NGIKFD6.module.min.js";function b(t){if(!t?.colors)return;const e=t.colors;return{primary:e.primary,secondary:e.secondary||e.primary,surface:e.surface||e.background,success:e.success,danger:e.danger,warning:e.warning,error:e.error,info:e.info,text:e.text,textSecondary:e.textSecondary,border:e.border,grid:e.grid}}function x(t){if(!t.accessibility)return t;let e=t;if(t.accessibility.colorBlindSafe&&(e={...e,colors:{...e.colors,categorical:v}}),t.accessibility.highContrast){const t="dark"===e.mode;e={...e,colors:{...e.colors,text:t?"#ffffff":"#000000",textSecondary:t?"#cccccc":"#333333",grid:t?"#666666":"#999999",border:t?"#888888":"#000000"}}}return e}var v=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],w={mode:"light",colors:{primary:"#00a2ce",secondary:"#6c757d",categorical:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],sequential:"blues",diverging:"RdBu",background:"transparent",surface:"#ffffff",text:"#333",textSecondary:"#666",grid:"#e0e0e0",border:"#ccc",selection:"#00a2ce",selectionOpacity:.15,success:"#2ca02c",danger:"#d62728",warning:"#f0ad4e",error:"#b4181b",info:"#00a2ce"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},k={mode:"dark",colors:{primary:"#4fc3f7",secondary:"#90a4ae",categorical:["#4fc3f7","#ffb74d","#81c784","#ef5350","#ba68c8","#a1887f","#f06292","#90a4ae","#dce775","#4dd0e1"],sequential:"blues",diverging:"RdBu",background:"#1a1a2e",surface:"#252540",text:"#e0e0e0",textSecondary:"#aaa",grid:"#333",border:"#555",selection:"#4fc3f7",selectionOpacity:.15,success:"#81c784",danger:"#ef5350",warning:"#ffb74d",error:"#d84848",info:"#4fc3f7"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},S={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:v,sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#000000",textSecondary:"#333333",grid:"#999999",border:"#000000",focus:"#0000cc",selection:"#0000cc",selectionOpacity:.1,success:"#006400",danger:"#cc0000",warning:"#b15a00",error:"#8b0000",info:"#0000cc"},typography:{fontFamily:"system-ui, sans-serif",titleSize:18,labelSize:14,tickSize:12},tooltip:{background:"#000000",text:"#ffffff",borderRadius:"4px",fontSize:"14px",shadow:"0 2px 8px rgba(0, 0, 0, 0.3)"},borderRadius:"4px"};function A(t,e){if("light"===e)return w;if("dark"===e)return k;if("high-contrast"===e)return S;if("string"==typeof e)return void 0!==console&&console.warn(`[ThemeStore] Unknown theme preset "${e}". Keeping current theme.`),t;if(e.mode&&"auto"!==e.mode){const t="dark"===e.mode?k:w;return x({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}return x({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}}})}var[M,_]=s(t=>({theme:w,setTheme(e){t(t=>({theme:A(t.theme,e)}))}})),P={light:w,dark:k,"high-contrast":S,pastels:{mode:"light",colors:{primary:"#c9a0dc",secondary:"#b8a8c8",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#fdf6f0",surface:"#fff5ee",text:"#4a3728",textSecondary:"#7a644a",grid:"#e8d5c4",border:"#e8d5c4",focus:"#8a5fae",annotation:"#8a5fae",success:"#9ad4a3",danger:"#e8869a",warning:"#f0c888",error:"#c86070",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#fff5ee",text:"#4a3728",borderRadius:"8px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"10px"},"pastels-dark":{mode:"dark",colors:{primary:"#c9a0dc",secondary:"#a899c0",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#1a1525",surface:"#251e35",text:"#e8ddf0",textSecondary:"#a899c0",grid:"#3d3455",border:"#3d3455",focus:"#c9a0dc",annotation:"#c9a0dc",success:"#88d4ab",danger:"#f0a0c0",warning:"#f0c888",error:"#e87690",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#251e35",text:"#e8ddf0",borderRadius:"8px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"10px"},"bi-tool":{mode:"light",colors:{primary:"#2563eb",secondary:"#6b7280",categorical:["#2563eb","#0d9488","#ea580c","#6b7280"],sequential:"blues",background:"#f5f6f8",surface:"#ffffff",text:"#2c3e50",textSecondary:"#64717f",grid:"#d8dce3",border:"#d8dce3",focus:"#2563eb",annotation:"#2563eb",success:"#10b981",danger:"#ef4444",warning:"#f59e0b",error:"#dc2626",info:"#2563eb"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2c3e50",borderRadius:"6px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"8px"},"bi-tool-dark":{mode:"dark",colors:{primary:"#3b82f6",secondary:"#9ca3af",categorical:["#3b82f6","#14b8a6","#f97316","#9ca3af"],sequential:"blues",background:"#111827",surface:"#1f2937",text:"#f3f4f6",textSecondary:"#9ca3af",grid:"#374151",border:"#374151",focus:"#3b82f6",annotation:"#3b82f6",success:"#34d399",danger:"#f87171",warning:"#fbbf24",error:"#ef4444",info:"#60a5fa"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f2937",text:"#f3f4f6",borderRadius:"6px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"8px"},italian:{mode:"light",colors:{primary:"#cc0000",secondary:"#666666",categorical:["#cc0000","#333333","#c8a415","#4682b4"],sequential:"reds",background:"#fafafa",surface:"#ffffff",text:"#1a1a1a",textSecondary:"#666666",grid:"#e0e0e0",border:"#e0e0e0",focus:"#cc0000",annotation:"#cc0000",success:"#556b2f",danger:"#cc0000",warning:"#c8a415",error:"#8b0000",info:"#4682b4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#1a1a1a",borderRadius:"2px",shadow:"0 2px 4px rgba(0, 0, 0, 0.15)"},borderRadius:"2px"},"italian-dark":{mode:"dark",colors:{primary:"#ff3333",secondary:"#aaaaaa",categorical:["#ff3333","#aaaaaa","#d4a843","#6aa4d4"],sequential:"reds",background:"#0a0a0a",surface:"#1a1a1a",text:"#f5f5f5",textSecondary:"#aaaaaa",grid:"#333333",border:"#333333",focus:"#ff3333",annotation:"#ff3333",success:"#7a8b5a",danger:"#ff3333",warning:"#d4a843",error:"#cc0000",info:"#6aa4d4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1a1a1a",text:"#f5f5f5",borderRadius:"2px",shadow:"0 2px 8px rgba(0, 0, 0, 0.5)"},borderRadius:"2px"},tufte:{mode:"light",colors:{primary:"#8b0000",secondary:"#555555",categorical:["#8b4513","#556b2f","#4a5568","#800020"],sequential:"oranges",background:"#fffff8",surface:"#fffff8",text:"#111111",textSecondary:"#555555",grid:"#e0ddd0",border:"#e0ddd0",focus:"#8b0000",annotation:"#8b0000",success:"#556b2f",danger:"#8b0000",warning:"#b88700",error:"#6b0000",info:"#4a5568"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#fffff8",text:"#111111",borderRadius:"2px",shadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},borderRadius:"0px"},"tufte-dark":{mode:"dark",colors:{primary:"#c05050",secondary:"#a09880",categorical:["#c08050","#7a8b5a","#8090a0","#a05060"],sequential:"oranges",background:"#1c1b18",surface:"#262520",text:"#e8e4d8",textSecondary:"#a09880",grid:"#3d3c35",border:"#3d3c35",focus:"#c05050",annotation:"#d06a6a",success:"#7a8b5a",danger:"#c05050",warning:"#c8a060",error:"#a04040",info:"#8090a0"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262520",text:"#e8e4d8",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.4)"},borderRadius:"0px"},journalist:{mode:"light",colors:{primary:"#e45050",secondary:"#666666",categorical:["#3a86c8","#e45050","#d4a843","#888888"],sequential:"blues",background:"#ffffff",surface:"#f8f8f8",text:"#222222",textSecondary:"#666666",grid:"#d4d4d4",border:"#d4d4d4",focus:"#e45050",annotation:"#c63b3b",success:"#2d7a3d",danger:"#c8303a",warning:"#d4a843",error:"#a02028",info:"#3a86c8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:18,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#f8f8f8",text:"#222222",borderRadius:"4px",shadow:"0 2px 6px rgba(0, 0, 0, 0.12)"},borderRadius:"4px"},"journalist-dark":{mode:"dark",colors:{primary:"#ff6b6b",secondary:"#a0a0a0",categorical:["#5a9fd8","#ff6b6b","#e0c060","#aaaaaa"],sequential:"blues",background:"#141414",surface:"#1e1e1e",text:"#ededed",textSecondary:"#a0a0a0",grid:"#383838",border:"#383838",focus:"#ff6b6b",annotation:"#ff6b6b",success:"#6fba78",danger:"#ff6b6b",warning:"#e0c060",error:"#d04040",info:"#5a9fd8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1e1e1e",text:"#ededed",borderRadius:"4px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"4px"},playful:{mode:"light",colors:{primary:"#8b5cf6",secondary:"#7c5a9e",categorical:["#8b5cf6","#ec4899","#06b6d4","#84cc16"],sequential:"viridis",background:"#fdf8ff",surface:"#ffffff",text:"#2d1b4e",textSecondary:"#7c5a9e",grid:"#e8d0f8",border:"#e8d0f8",focus:"#8b5cf6",annotation:"#7a47e8",success:"#10d870",danger:"#ff4b6e",warning:"#ffaa33",error:"#e11d48",info:"#06b6d4"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2d1b4e",borderRadius:"12px",shadow:"0 4px 12px rgba(139, 92, 246, 0.15)"},borderRadius:"12px"},"playful-dark":{mode:"dark",colors:{primary:"#a78bfa",secondary:"#b8a0d8",categorical:["#a78bfa","#f472b6","#22d3ee","#a3e635"],sequential:"viridis",background:"#150a28",surface:"#1f1138",text:"#f0e8ff",textSecondary:"#b8a0d8",grid:"#3a2560",border:"#3a2560",focus:"#a78bfa",annotation:"#a78bfa",success:"#4ade80",danger:"#fb7185",warning:"#fbbf24",error:"#f43f5e",info:"#22d3ee"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f1138",text:"#f0e8ff",borderRadius:"12px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"12px"},carbon:{mode:"light",colors:{primary:"#0f62fe",secondary:"#525252",categorical:["#6929c4","#1192e8","#005d5d","#9f1853"],sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#161616",textSecondary:"#525252",grid:"#e0e0e0",border:"#e0e0e0",focus:"#0f62fe",annotation:"#0f62fe",success:"#24a148",danger:"#da1e28",warning:"#f1c21b",error:"#a2191f",info:"#0043ce"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#161616",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.2)"},borderRadius:"0px"},"carbon-dark":{mode:"dark",colors:{primary:"#4589ff",secondary:"#a8a8a8",categorical:["#a56eff","#33b1ff","#08bdba","#ff7eb6"],sequential:"blues",diverging:"RdBu",background:"#161616",surface:"#262626",text:"#f4f4f4",textSecondary:"#a8a8a8",grid:"#393939",border:"#393939",focus:"#4589ff",annotation:"#4589ff",success:"#42be65",danger:"#fa4d56",warning:"#f1c21b",error:"#da1e28",info:"#4589ff"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262626",text:"#f4f4f4",borderRadius:"2px",shadow:"0 4px 12px rgba(0, 0, 0, 0.5)"},borderRadius:"0px"}};function C(t){if(!t)return w;if("string"==typeof t){if("light"===t)return w;if("dark"===t)return k;if("high-contrast"===t)return S;return P[t]||w}const e="dark"===t.mode?k:w;return x({...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}})}function R(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,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}var L={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function I(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 L;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 T={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 $(t,e,o){const n=T[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=p(s,{width:e.width??i,height:e.height??r}).props,l=a.mode||t||"primary",c=T[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:z(c.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:I(a.mobileInteraction,{mode:l,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}function z(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 D(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}import*as F from"react-dom/server";import*as E from"react";var O=Object.freeze([]);function B(t){if(!t)return O;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 N}from"d3-scale";function W(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)]}function j(t,e,o){const n=t=>t.toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function Y(t){const e=t.map(W),o=e.length-1;return t=>{if(0>=t){const[t,o,n]=e[0];return j(t,o,n)}if(t>=1){const[t,n,i]=e[o];return j(t,n,i)}const n=t*o,i=Math.floor(n),r=n-i,[s,a,l]=e[i],[c,u,d]=e[i+1];return j(Math.round(s+(c-s)*r),Math.round(a+(u-a)*r),Math.round(l+(d-l)*r))}}var G=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],H=Y(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),q=Y(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),V=Y(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),X=Y(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),U=Y(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),K=Y(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),Z=Y(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),Q=Y(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),J=Y(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),tt=Y(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),et=Y(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),ot=Y(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),nt={blues:H,reds:q,greens:V,viridis:Z,oranges:X,purples:U,greys:K,plasma:Q,inferno:J,magma:tt,cividis:et,turbo:ot};function it(t){return t&&nt[t]||H}var rt=Y(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),st=Y(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),at=Y(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),lt=Y(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),ct=Y(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),ut=Y(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),dt=Y(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),ht={category10:G,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...nt},ft=G,pt="#007bff";function yt(t,e,o=ft){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=ht[t];if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var gt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],mt=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],bt=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 xt(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")||bt.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):ft[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))%ft.length]}function vt(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 wt(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>vt(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 N().domain(n).range(o).unknown("#999");const r=ht[o]||ht.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:ft;return N().domain(n).range(t).unknown("#999")}}function kt(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 St(t){let e=1/0,o=-1/0;for(const n of t)e>n&&(e=n),n>o&&(o=n);return[e,o]}function At(t,e=-1/0){let o=e;for(const e of t)e>o&&(o=e);return o}function Mt(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function _t(t,e){if(!Mt(e))return t??((...t)=>({}));const o={};return void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...o}):(...t)=>({...o})}function Pt(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>Lt(e(t))}function Ct(t,e){const o=Pt(t),n=Pt(e);return(t,e)=>{const i=n(t);return{value:i,x:o(t),y:i,category:e}}}function Rt(t,e){const o=Pt(e??"value"),n=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=n?n(t):void 0;return{value:o(t),category:null==e?void 0:e+""}}}function Lt(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function It(t,e,o){const n=t.when;return void 0===n||!0===n||!1!==n&&("function"==typeof n?n(e,o):function(t,e,o){const n=null!=t.axis?o[t.axis]:null!=t.field?e[t.field]:o.value;if(void 0!==t.eq&&n!==t.eq)return!1;if(void 0!==t.ne&&n===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(n))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const i=Lt(n);if(void 0===i)return!1;if(void 0!==t.gt&&t.gt>=i)return!1;if(void 0!==t.gte&&t.gte>i)return!1;if(void 0!==t.lt&&i>=t.lt)return!1;if(void 0!==t.lte&&i>t.lte)return!1;if(void 0!==t.within){const[e,o]=t.within;if(e>i||i>o)return!1}if(void 0!==t.outside){const[e,o]=t.outside;if(i>=e&&o>=i)return!1}return!0}(n,e,o))}function Tt(t,e,o){if(!e||0===e.length)return{};let n={};for(const i of e){if(!It(i,t,o))continue;const e="function"==typeof i.style?i.style(t,o):i.style;e&&(n={...n,...e})}return n}function $t(t,e,o,n=t=>t){const i=t??(()=>({}));return e&&0!==e.length?(t,r)=>{const s=n(t),a={...i(t,r)};return Object.assign(a,Tt(s,e,o(s,r))),a}:i}function zt(t,e,o,n){if(!t||0===t.length)return n;const i=Rt(e,o);return(e,o)=>{const r=e&&e.data||e,s=Tt(r,t,i(r)),a=n?n(e,o):void 0;return a?{...s,...a}:s}}var Dt={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function Ft(t,e=Dt){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 Et(t){return t?Ft(t):void 0}function Ot(t,e,o){return"function"==typeof t?t(o):o[t||e]}function Bt(t){return t instanceof Date?t.getTime():Number(t)}function Nt(t,e){return Z(1===e?.5:t/(e-1))}function Wt(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 jt(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}var Yt="__forecastSegment",Gt="__forecastOpacity";function Ht(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[Gt]=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),f=h-d;t.forEach((t,e)=>{const o=c[e];Number.isFinite(o)&&(t[Gt]=l-(f>0?(o-d)/f:0)*(l-a))})}function qt(t,e){return"function"==typeof e?e(t):!!t[e]}var Vt="__semiotic_resolvedX",Xt="__semiotic_resolvedY",Ut="__compoundGroup";function Kt(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function Zt(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?B(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?Vt:e,s=i?Xt:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[Vt]=e(t)),i&&(r[Xt]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,l=s.yKey,c=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d="string"==typeof n||"function"==typeof n?n:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,o,n,i){return(r=n).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,o,n,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=n,y=t.map(t=>{let e="observed";return s&&qt(t,s)?e="forecast":r&&qt(t,r)&&(e="training"),{...t,[Yt]:e}}),g=n._groupBy,m=[];if(g){const t=new Map;for(const e of y){const o=e[g]??"__default";t.has(o)||t.set(o,[]),t.get(o).push(e)}const e=[];for(const[,o]of t)for(let t=0;o.length-1>t;t++)o[t][Yt]!==o[t+1][Yt]&&(e.push({...o[t+1],[Yt]:o[t][Yt]}),e.push({...o[t],[Yt]:o[t+1][Yt]}));m.push(...y,...e)}else for(let t=0;y.length>t;t++)m.push(y[t]),y.length-1>t&&y[t][Yt]!==y[t+1][Yt]&&(m.push({...y[t+1],[Yt]:y[t][Yt]}),m.push({...y[t],[Yt]:y[t+1][Yt]}));if(n.trainUnderline){const t=[];for(const e of m)"training"===e[Yt]&&t.push({...e,[Yt]:"training-base"});m.unshift(...t)}const b=[];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));b.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:p})}if(n.uncertaintyOpacity||n.confidenceAccessor){const t=l?"function"==typeof l?l:t=>t[l]:()=>{},e=c?"function"==typeof c?c:t=>t[c]:()=>{};Ht(m.filter(t=>"forecast"===t[Yt]),n,t,e)}if(a){const t=n.anomalyStyle,e={type:"highlight",filter:t=>qt(t,a)};t?(e.style=t,e.r=f):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=f):(e.color=h,e.r=f,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),b.push(e)}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:m,annotations:b}}(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,[Yt]:"observed"}):d.push({...o,[Yt]:"training"});const f=d.map(t=>[t[e],t[o]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),p=[],y=[];if(f.length>=3){const i=f.length;let r=0,d=0,h=0,g=0;for(const[t,e]of f)r+=t,d+=e,h+=t*t,g+=t*e;const m=i*h-r*r;if(Math.abs(m)>1e-12){const h=(i*g-r*d)/m,b=(d-h*r)/i,x=t=>b+h*t,v=f.map(([t,e])=>e-x(t)).reduce((t,e)=>t+e*e,0),w=Math.sqrt(v/Math.max(i-2,1)),k=f.reduce((t,e)=>t+e[0],0)/i,S=f.reduce((t,e)=>t+(e[0]-k)**2,0),A=.99>a?.95>a?.9>a?1:1.645:1.96:2.576,M=At(t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t))),_=f.length>1?(f[i-1][0]-f[0][0])/(i-1):1;for(let t=1;s>=t;t++){const n=M+t*_,r=x(n),s=w*Math.sqrt(1+1/i+(S>0?(n-k)**2/S:0))*A;y.push({[e]:n,[o]:r,[Yt]:"forecast",__forecastUpper:r+s,__forecastLower:r-s})}Ht(y,n,t=>t.__forecastUpper,t=>t.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}p.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&p.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const g=[];if(g.push(...d),d.length>0&&h.length>0&&g.push({...d[d.length-1],[Yt]:"observed"}),g.push(...h),y.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&g.push({...t,[Yt]:"forecast"}),g.push(...y)}return{processedData:g,annotations:p}}(t,e,o,n,i);var r}(r,a,l,n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,t.anomaly);if(r=e.processedData,c.push(...e.annotations),u=function(t,e,o){const n=o.upperBounds,i=o.lowerBounds;if(!n&&!i)return;const r="function"==typeof n?n:"string"==typeof n?t=>t[n]:null,s="function"==typeof i?i:"string"==typeof i?t=>t[i]:null;let a=1/0,l=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>l&&(l=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[Ut]:`${t[n]}__${t[Yt]||"observed"}`})),d=Ut):d=Yt,t.baseLineStyle){const e=function(t,e){const o=e.trainDasharray??"8,4",n=e.forecastDasharray??"4,4",i=e.color||"#6366f1",r=e.trainOpacity,s=e.forecastOpacity,a=e.trainStroke,l=e.trainLinecap,c=e.trainUnderline;return e=>{const u=t(e),d=e[Yt];if("training"===d){let t=u.stroke;return"darken"===a?t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const n=Math.round(parseInt(o[1],16)*(1-e)),i=Math.round(parseInt(o[2],16)*(1-e)),r=Math.round(parseInt(o[3],16)*(1-e));return`#${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):a&&(t=a),{...u,stroke:t,strokeDasharray:o,...l&&{strokeLinecap:l},...null!=r&&{strokeOpacity:r}}}if("training-base"===d){let t=u.stroke||"#666";return"lighten"===c&&(t=function(t,e=.5){const o=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(t);if(!o)return t;const n=Math.round(parseInt(o[1],16)+(255-parseInt(o[1],16))*e),i=Math.round(parseInt(o[2],16)+(255-parseInt(o[2],16))*e),r=Math.round(parseInt(o[3],16)+(255-parseInt(o[3],16))*e);return`#${n.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}`}(t,.4)),{...u,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Gt],o=null!=t?t:s;return{...u,stroke:i,strokeDasharray:n,...null!=o&&{strokeOpacity:o}}}return u}}(e=>t.baseLineStyle(e),t.forecast);h=t=>e(t)}}else t.anomaly&&c.push(...(f=t.anomaly,[{type:"anomaly-band",threshold:f.threshold??2,showBand:!1!==f.showBand,fill:f.bandColor||"#6366f1",fillOpacity:f.bandOpacity??.1,anomalyColor:f.anomalyColor||"#ef4444",anomalyRadius:f.anomalyRadius??6,label:f.label}]));var f;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,o,n,i){const r=new Map;for(const e of t){const t=i?(e[i]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const i of e)Kt(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)Kt(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)Kt(t,o,n)?l():r.push(t);l()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,l,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let p;if(t.directLabel){const e=function(t,e,o,n,i,r,s,a){if(!e||!o)return{annotations:[]};const l="object"==typeof e?e:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof o?o:t=>t[o],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const o=t+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(e))}const f=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[n])-Number(e[n])),f.set(t,"end"===c?e[e.length-1]:e[0]);const p=wt(Array.from(f.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),y=Array.from(f.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===c?6:-6,dy:0,color:p?xt({__lbl:t},"__lbl",p):a||pt,fontSize:u}));y.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;y.length>t;t++){const e=y[t-1],o=y[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const g=y.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:y,marginExtra:"end"===c?{right:g}:{left:g}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,t.colorScheme,t.themeCategorical,t.color);c.push(...e.annotations),p=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?l:o,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:p}}import{forwardRef as Qt,useCallback as Jt,useMemo as te}from"react";import*as ee from"react";import{jsx as oe}from"react/jsx-runtime";var ne={isActive:!1,predicate:()=>!0},ie=ee.createContext(null);function re({value:t,children:e}){return oe(ie.Provider,{value:t,children:e})}function se(t,e){return null!=t?oe(re,{value:e,children:t}):t}import{forwardRef as ae,useMemo as le}from"react";import*as ce from"react";import{useRef as ue,useState as de,useEffect as he,useMemo as fe,useCallback as pe,useImperativeHandle as ye,useId as ge,forwardRef as me,memo as be}from"react";import*as xe from"react";import{jsx as ve}from"react/jsx-runtime";var we=null,ke=null;function Se(t){const[e,o]=xe.useState(()=>we);return xe.useEffect(()=>{if(e)return;let t=!1;return(we?Promise.resolve(we):(ke||(ke=import("./chunk-XYBrushOverlay-ECZJJLAJ.module.min.js").then(t=>we=t.XYBrushOverlay).catch(t=>{throw ke=null,t})),ke)).then(e=>{t||o(()=>e)}),()=>{t=!0}},[e]),e?ve(e,{...t}):null}var Ae=class{constructor(t,e){this.lastBoundedData=null,this.chunkTimer=0,this.pushBuffer=[],this.flushScheduled=!1,this.callback=t,this.chunkThreshold=e?.chunkThreshold??5e3,this.chunkSize=e?.chunkSize??5e3}updateChunkOptions(t){null!=t.chunkThreshold&&(this.chunkThreshold=t.chunkThreshold),null!=t.chunkSize&&(this.chunkSize=t.chunkSize)}clearLastData(){this.lastBoundedData=null,this.pushBuffer=[],this.flushScheduled=!1,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0)}setBoundedData(t){if(t=B(t),this.lastBoundedData===t)return;if(this.lastBoundedData=t,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.chunkThreshold>=t.length)return void this.callback({inserts:t,bounded:!0});this.callback({inserts:t.slice(0,this.chunkSize),bounded:!0,totalSize:t.length});let e=this.chunkSize;const o=()=>{if(e>=t.length)return void(this.chunkTimer=0);if(t!==this.lastBoundedData)return void(this.chunkTimer=0);const n=Math.min(e+this.chunkSize,t.length);this.callback({inserts:t.slice(e,n),bounded:!1}),e=n,this.chunkTimer=t.length>e?requestAnimationFrame(o):0};this.chunkTimer=requestAnimationFrame(o)}setReplacementData(t){if(t=B(t),this.lastBoundedData=t,this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.pushBuffer=[],this.flushScheduled=!1,this.chunkThreshold>=t.length)return void this.callback({inserts:t,bounded:!0,preserveCategoryOrder:!0});this.callback({inserts:t.slice(0,this.chunkSize),bounded:!0,preserveCategoryOrder:!0,totalSize:t.length});let e=this.chunkSize;const o=()=>{if(e>=t.length)return void(this.chunkTimer=0);if(t!==this.lastBoundedData)return void(this.chunkTimer=0);const n=Math.min(e+this.chunkSize,t.length);this.callback({inserts:t.slice(e,n),bounded:!1}),e=n,this.chunkTimer=t.length>e?requestAnimationFrame(o):0};this.chunkTimer=requestAnimationFrame(o)}flushPushBuffer(){if(this.flushScheduled=!1,0===this.pushBuffer.length)return;const t=this.pushBuffer;this.pushBuffer=[],this.callback({inserts:t,bounded:!1})}scheduleFlush(){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flushPushBuffer()))}push(t){null!=t&&"object"==typeof t&&(this.pushBuffer.push(t),this.scheduleFlush())}pushMany(t){if(0===t.length)return;let e=0;for(let o=0;t.length>o;o++){const n=t[o];null!=n&&"object"==typeof n&&(this.pushBuffer.push(n),e++)}0!==e&&this.scheduleFlush()}flush(){this.flushPushBuffer()}clear(){this.chunkTimer&&(cancelAnimationFrame(this.chunkTimer),this.chunkTimer=0),this.lastBoundedData=null,this.pushBuffer=[],this.flushScheduled=!1}},Me=class{constructor(t){if(this._capacity=t,this.head=0,this._size=0,1>t)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(t)}push(t){let e;return this._size===this._capacity?e=this.buffer[this.head]:this._size++,this.buffer[this.head]=t,this.head=(this.head+1)%this._capacity,e}pushMany(t){const e=[];for(const o of t){const t=this.push(o);void 0!==t&&e.push(t)}return e}get(t){if(t>=0&&this._size>t)return this.buffer[(this.head-this._size+t+this._capacity)%this._capacity]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let t=0;return{next:()=>this._size>t?{done:!1,value:this.get(t++)}:{done:!0,value:void 0}}}forEach(t){const e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t(this.buffer[(e+o)%this._capacity],o)}toArray(){const t=Array(this._size),e=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++)t[o]=this.buffer[(e+o)%this._capacity];return t}resize(t){if(1>t)throw Error("RingBuffer capacity must be at least 1");const e=this.toArray();let o=0,n=[];e.length>t&&(o=e.length-t,n=e.slice(0,o)),this._capacity=t,this.buffer=Array(t),this.head=0,this._size=0;for(let t=o;e.length>t;t++)this.push(e[t]);return n}update(t,e){const o=[],n=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++){const r=(n+i)%this._capacity,s=this.buffer[r];if(t(s)){let t;t="object"!=typeof s||null===s?s:Array.isArray(s)?[...s]:{...s},o.push(t),this.buffer[r]=e(s)}}return o}remove(t){const e=[],o=[];if(this.forEach(n=>{t(n)?o.push(n):e.push(n)}),0===o.length)return o;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(const t of e)this.push(t);return o}clear(){this.buffer=Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},_e=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(t){Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}evict(t){t!==this._min&&t!==this._max||(this._dirty=!0)}recalculate(t,e){this._min=1/0,this._max=-1/0;for(const o of t){const t=e?e(o):o;Number.isFinite(t)&&(this._min>t&&(this._min=t),t>this._max&&(this._max=t))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function Pe(t){return new Set(Array.isArray(t)?t:[t])}function Ce(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Re(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Le(t,e,o){return t+(e-t)*o}function Ie(){return"undefined"!=typeof performance?performance.now():Date.now()}function Te(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 $e(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function ze(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function De(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 Fe(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 Ee(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 Oe(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 Be(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 Ne(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 We(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 je(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 Ye(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 Ge(t,e,o,n,i,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:n,fill:i,datum:r};return s?.showValues&&(a.showValues=!0,a.value=s.value,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function He(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 qe(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:He(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function Ve(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 Xe(t,e,o){const n=[];for(const i of o){const o=qe(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function Ue(t,e,o,n){const i=[];for(const r of n){const n=qe(t,e,o,r);n&&i.push(n)}return i}function Ke(t,e){if(!t)return{};if(!e||0===e.length)return t;const o=[];for(const n of e){if("band"!==n.kind)continue;const e=n.getTop(t),i=n.getBottom(t);Number.isFinite(i)&&Number.isFinite(e)&&o.push({y0:i,y1:e})}return 0===o.length?t:{...t,band:o[0],bands:o}}function Ze(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=We(r,t.scales,t.getX,i,s,n,a);l&&o.push(l)}}}function Qe(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function Je(t){return Ft(t)}import{symbol as to,symbolCircle as eo,symbolCross as oo,symbolDiamond as no,symbolSquare as io,symbolStar as ro,symbolTriangle as so,symbolWye as ao}from"d3-shape";var lo={circle:eo,square:io,triangle:so,diamond:no,star:ro,cross:oo,wye:ao},co=["circle","triangle","diamond","star","square","chevron","cross","wye"];function uo(t,e,o){if(o)return o;const n=t??"circle";return"chevron"===n?function(t){const e=1.5*ho(t),o=.92*e;return`M0,${-e}L${o},${(.78*e).toFixed(3)}L0,${(.28*e).toFixed(3)}L${-o},${(.78*e).toFixed(3)}Z`}(e):to(lo[n]??eo,Math.max(1,e))()??""}function ho(t){return Math.sqrt(Math.max(1,t)/Math.PI)}var fo=new Map;function po(t,e,o){const n=o.config.areaStyle?.(e);return n&&(t.style=n),t}function yo(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 go(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;mo(n)&&0===o.length&&bo(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)&&bo(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 mo(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(mo))}function bo(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function xo(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 vo(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function wo(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=vo(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=h(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:vo(t.y1Accessor,"y1"),getBottom:vo(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as ko,scaleLog as So,scaleSymlog as Ao,scaleTime as Mo}from"d3-scale";function _o(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Po(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return So().domain(t).range(o).clamp(!0)}return"symlog"===t?Ao().domain(e).range(o):"time"===t?Mo().domain([new Date(e[0]),new Date(e[1])]).range(o):ko().domain(e).range(o)}function Co(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Ro(t,e){const o=new Me(t.capacity);return t.forEach(()=>o.push(e)),o}function Lo(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function Io(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 To=new WeakMap;function $o(){return this.updateResults.last}function zo(){return this.updateResults.last}function Do(t){return this.updateResults.subscribe(t)}function Fo(t){this.config.layoutSelection=t}function Eo(){To.set(this,!0)}function Oo(){const t=!0===To.get(this);return To.delete(this),t}function Bo(t){Object.assign(t.prototype,{getLastUpdateResult:$o,getUpdateSnapshot:zo,subscribeUpdateResult:Do,setLayoutSelection:Fo,markStylePaintPending:Eo,consumeStylePaintPending:Oo})}var No={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function Wo(t,e){const o={...t};for(const t of e)o[No[t]]++;return o}function jo(t,e,o){const n=new Set(e);return{changeSet:{...t,...t.keys?{keys:[...t.keys]}:{}},changed:n,revisions:Wo(o,n)}}var Yo=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=jo({kind:"initialize"},[],this.revisions),this.listeners=new Set}get last(){return this.latest}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}record(t,e){const o=jo(t,e,this.revisions);this.revisions=o.revisions,this.latest=o;for(const t of[...this.listeners])t();return o}},Go=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ho=["scene-style","data-paint","accessibility","evidence"],qo=(t,e)=>({retainedData:t,invalidations:e}),Vo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Xo=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Uo=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ko=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zo=["scene-geometry","data-paint","accessibility","evidence"],Qo=["scene-style","data-paint","accessibility","evidence"],Jo=[],tn={chartType:qo("rebuild",Vo),runtimeMode:qo("rebuild",Vo),xAccessor:qo("rebuild",Vo),yAccessor:qo("rebuild",Vo),timeAccessor:qo("rebuild",Vo),valueAccessor:qo("rebuild",Vo),y0Accessor:qo("rebuild",Vo),boundsAccessor:qo("rebuild",Vo),band:qo("rebuild",Vo),openAccessor:qo("rebuild",Vo),highAccessor:qo("rebuild",Vo),lowAccessor:qo("rebuild",Vo),closeAccessor:qo("rebuild",Vo),candlestickRangeMode:qo("rebuild",Vo),accessorRevision:qo("rebuild",Vo),groupAccessor:qo("rebuild",Xo),categoryAccessor:qo("rebuild",Xo),lineDataAccessor:qo("rebuild",Xo),colorAccessor:qo("rebuild",Qo),sizeAccessor:qo("rebuild",Zo),symbolAccessor:qo("rebuild",Zo),pointIdAccessor:qo("rebuild",Zo),xScaleType:qo("preserve",Uo),yScaleType:qo("preserve",Uo),xExtent:qo("preserve",Uo),yExtent:qo("preserve",Uo),extentPadding:qo("preserve",Uo),scalePadding:qo("preserve",Uo),axisExtent:qo("preserve",Uo),binSize:qo("preserve",Uo),normalize:qo("preserve",Uo),heatmapAggregation:qo("preserve",Uo),heatmapXBins:qo("preserve",Uo),heatmapYBins:qo("preserve",Uo),arrowOfTime:qo("preserve",Ko),baseline:qo("preserve",Ko),stackOrder:qo("preserve",Ko),sizeRange:qo("preserve",Ko),curve:qo("preserve",Ko),areaGroups:qo("preserve",Ko),customLayout:qo("preserve",Ko),layoutConfig:qo("preserve",Ko),layoutMargin:qo("preserve",Ko),symbolMap:qo("preserve",Zo),showValues:qo("preserve",Zo),heatmapValueFormat:qo("preserve",Zo),lineStyle:qo("preserve",Qo),pointStyle:qo("preserve",Qo),areaStyle:qo("preserve",Qo),barStyle:qo("preserve",Qo),swarmStyle:qo("preserve",Qo),waterfallStyle:qo("preserve",Qo),candlestickStyle:qo("preserve",Qo),boundsStyle:qo("preserve",Qo),gradientFill:qo("preserve",Qo),lineGradient:qo("preserve",Qo),semanticLineStops:qo("preserve",Qo),colorScheme:qo("preserve",Qo),themeCategorical:qo("preserve",Qo),themeSemantic:qo("preserve",Qo),themeSequential:qo("preserve",Qo),themeDiverging:qo("preserve",Qo),barColors:qo("preserve",Qo),decay:qo("preserve",Qo),pulse:qo("preserve",Qo),staleness:qo("preserve",Qo),layoutSelection:qo("preserve",Qo),annotations:qo("preserve",["overlay","accessibility","evidence"]),windowSize:qo("preserve",Jo),windowMode:qo("preserve",Jo),maxCapacity:qo("preserve",Jo),clock:qo("preserve",Jo),transition:qo("preserve",Jo),introAnimation:qo("preserve",Jo),onLayoutError:qo("preserve",Jo)},en=qo("preserve",Ko),on=class{constructor(){this.tracker=new Yo}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}},Go)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Ho):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=tn[n]??en;"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 nn}from"d3-quadtree";var rn=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&&(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&&(i[r++]=t);this.tree=nn().x(t=>t.x).y(t=>t.y).addAll(i)}},sn=class e{constructor(t){if(this.xExtent=new _e,this.yExtent=new _e,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new on,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 rn,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=ze(t,s,r);l>i&&(i=l)}a&&(l=De(o,i,s)||l);continue}const e=c.get(o.datum);if(null==e)continue;const i=n.get(e);l=De(o,null==i?0:ze(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 Me(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=h(t.timeAccessor||t.xAccessor,"time"),this.getY=h(t.valueAccessor||t.yAccessor,"value")):(this.getX=h(t.xAccessor,"x"),this.getY=h(t.yAccessor,"y")),this.getGroup=y(t.groupAccessor),this.getCategory=y(t.categoryAccessor),this.getSize=t.sizeAccessor?h(t.sizeAccessor,"size"):void 0,this.getColor=y(t.colorAccessor),this.getSymbol=y(t.symbolAccessor),this.getY0=t.y0Accessor?h(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=wo(t),this.getPointId=y(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?h(t.openAccessor,"open"):void 0,this.getHigh=h(t.highAccessor,"high"),this.getLow=h(t.lowAccessor,"low"),this.getClose=o?h(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new Me(t.windowSize))}currentTime(){return this.config.clock?.()??Ie()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Ro(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?h(this.config.timeAccessor||this.config.xAccessor,"time"):h(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,s="string"==typeof n&&Number.isFinite(d(n));if(this.xIsDate=i||s,s){const t="string"==typeof o?o:void 0;this.getX=t?e=>r(e[t]):t=>r(o(t))}}Co(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Lo(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=Lo(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=_o(this.xExtent.extent,e.xExtent),l=_o(s,e.yExtent);const c=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===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.axisExtent;if(e.normalize){const o=[0,r?1:1+e.extentPadding];return{yDomain:o,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:o}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,l=new Set;let c=0;const u=new Map,d=new Map;for(const t of o){const e=new Map;let o=0;for(const r of t.data){const t=n(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),l.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>c&&(c=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",f=(t,e)=>e>t?-1:t>e?1:0;let p,y;if("input"===h)p=o.map(t=>t.key);else if("insideOut"===h){const t=[...o].map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}),e=[],n=[];let i=0,r=0;for(const o of t)r>i?(e.push(o),i+=d.get(o)??0):(n.push(o),r+=d.get(o)??0);p=[...n.reverse(),...e]}else p="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:f(t,e)}):"desc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:f(t,e)}):o.map(t=>t.key).sort(f);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),o=Ne(t,p,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let n=1/0,i=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;n>t&&(n=t),t+r>i&&(i=t+r)}Number.isFinite(n)&&Number.isFinite(i)||(n=0,i=0);const s=i-n,c=r?0:s>0?s*e.extentPadding:1;y=[n-c,i+c]}else if("diverging"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),[o,n]=function(t,e,o){let n=0,i=0;for(const r of t){let t=0,s=0;for(const n of e){const e=o(n,r)||0;0>e?s+=e:t+=e}n>s&&(n=s),t>i&&(i=t)}return[n,i]}(t,p,(t,e)=>a.get(t)?.get(e)||0),i=n-o,s=r?0:i>0?i*e.extentPadding:1;y=[o-s,n+s]}else y=[0,c+(r?0:c>0?c*e.extentPadding:1)];return{yDomain:y,stackExtentCache:{key:s,yDomain:y}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:o.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});l=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!c&&o.size>0?l=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=yo(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){if("x"==("up"===(a=e.arrowOfTime)||"down"===a?"y":"x")){const t="right"===e.arrowOfTime?[s,o.width-s]:[o.width-s,s];return{x:ko().domain(n).range(t),y:Po(e.yScaleType,i,[o.height-s,s])}}const t="down"===e.arrowOfTime?[s,o.height-s]:[o.height-s,s];return{x:Po(e.yScaleType,i,[s,o.width-s]),y:ko().domain(n).range(t)}}var a;return{x:Po(e.xScaleType,n,[s,o.width-s]),y:Po(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=Po,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??gt},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=xo("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 go({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(Qe).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=Ve(t.ribbons);if(r.length>0&&n.push(...Xe(t,e,r)),i.length>0)for(const e of o)n.push(...Ue(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=Oe(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 Ze(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}=Ve(t.ribbons);if(r.length>0&&n.push(...Xe(t,e,r)),i.length>0)for(const e of o)n.push(...Ue(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,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}];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});return o.map(({from:e,to:o,color:n})=>{const i=t.scales.y(e),r=t.scales.y(o);return{y:Math.min(i,r),height:Math.abs(r-i),color:n}}).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=Be(e.data,t.scales,t.getX,t.getY,r,o,e.key,l),c=Je(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 Ze(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}=Ve(t.ribbons);if(r.length>0&&n.push(...Xe(t,e,r)),i.length>0)for(const e of o)n.push(...Ue(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=Be(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=Je(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=Oe(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 Ze(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=Ne(c,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),f="diverging"===a&&!r,p=[],y=new Map,g=new Map,m=new Map,b=new Map;for(const t of c)g.set(t,h.get(t)??0),m.set(t,0),b.set(t,0);for(const o of t){const t=u.get(o.key),n=new Map;let a=[],l=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:l,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),p.push(t)}a=[],l=[]};for(const o of c){const i=t.has(o);let s,c,u=i?t.get(o):0;if(r&&i&&(u/=d.get(o)),!i||!Number.isFinite(u)||0===u){h();continue}f?u>0?(s=m.get(o),c=s+u,m.set(o,c)):(s=b.get(o),c=s+u,b.set(o,c)):(s=g.get(o),c=s+u,g.set(o,c));const p=e.x(o);l.push([p,e.y(s)]),a.push([p,e.y(c)]),n.set(o,c)}h(),y.set(o.key,n)}return{nodes:p,stackedTops:y}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),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);Ze(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=t.config.symbolMap,u=new Map;let d=0;const h=t=>{const e=c?.[t];if(e)return e;let o=u.get(t);return o||(o=co[d%co.length],d++,u.set(t,o)),o};for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},c=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(c=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(i);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(i)+"":void 0;if(l){const n=h(l(i)+""),r=je(i,t.scales,t.getX,t.getY,Math.PI*c*c,n,e,u);r&&o.push(r)}else{const n=We(i,t.scales,t.getX,t.getY,c,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=h(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,f=(u-c||1)/i,p=n*i;if(p>1e6)return[];const y=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 h=Math.min(Math.floor((l-a)/d),n-1),p=Math.min(Math.floor((u-c)/f),i-1);if(0>h||0>p)continue;const m=p*n+h;y[m]++;const b=s(r);g[m]+=isFinite(b)?b:0}let m=1/0,b=-1/0;for(let t=0;p>t;t++){if(0===y[t])continue;let e;switch(r){case"sum":e=g[t];break;case"mean":e=g[t]/y[t];break;default:e=y[t]}m>e&&(m=e),e>b&&(b=e)}if(!isFinite(m))return[];const x=b-m||1,v=o.width/n,w=o.height/i,k=t.config.showValues,S=t.config.heatmapValueFormat,A=[];for(let e=0;i>e;e++){const o=e*n;for(let s=0;n>s;s++){const n=o+s;if(0===y[n])continue;let l;switch(r){case"sum":l=g[n];break;case"mean":l=g[n]/y[n];break;default:l=y[n]}const u=(l-m)/x,h={xi:s,yi:e,value:l,count:y[n],sum:g[n],xCenter:a+(s+.5)*d,yCenter:c+(e+.5)*f,agg:r};A.push(po(Ge(s*v,(i-1-e)*w,v,w,`rgb(${220-(180*u+.5)|0},${220-(100*u+.5)|0},${255-(50*u+.5)|0})`,h,k?{value:l,showValues:!0,valueFormat:S}:void 0),h,t))}}return A}(t,e,o);if(0===e.length)return[];const n=h(t.config.valueAccessor,"value"),i=f(t.config.xAccessor,"x"),r=f(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 p=Array.from(s.keys()),y=Array.from(a.keys()),g=p.every(t=>"number"==typeof t&&!isNaN(t)),m=y.every(t=>"number"==typeof t&&!isNaN(t));if(g){p.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;p.length>t;t++)s.set(p[t],t)}if(m){y.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;y.length>t;t++)a.set(y[t],t)}const b=new Float64Array(e.length),x=new Float64Array(e.length),v=Array(e.length),w=new Map;let k=0;for(let t=0;e.length>t;t++){const o=e[t],i=s.get(l[t]),r=a.get(c[t]);if(void 0===i||void 0===r)continue;const d=n(o),h=r*u+i,f=w.get(h);let p;void 0!==f?p=f:(p=k++,w.set(h,p)),b[p]=h,x[p]=d,v[p]=o}let S=1/0,A=-1/0;for(let t=0;k>t;t++){const e=x[t];isFinite(e)&&(S>e&&(S=e),e>A&&(A=e))}if(!isFinite(S)||!isFinite(A))return[];const M=function(t){const e=t in nt?t:"blues";let o=fo.get(e);if(o)return o;o=Array(256);const n=it(e);for(let t=0;256>t;t++)o[t]=n(t/255);return fo.set(e,o),o}("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),_=255/(A-S||1),P=o.width/u,C=o.height/d,R=t.config.showValues,L=t.config.heatmapValueFormat,I=[];for(let e=0;k>e;e++){const o=x[e];if(!isFinite(o))continue;const n=b[e],i=n%u,r=v[e];I.push(po(Ge(i*P,(d-1-(n-i)/u)*C,P,C,M[Math.min((o-S)*_+.5|0,255)],r,R?{value:o,showValues:!0,valueFormat:L}:void 0),r,t))}return I}(i,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=yo(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);for(const e of o.values()){const o=Math.max(e.start,s),u=Math.min(e.end,a);if(o>=u)continue;const f=r.x(o),p=r.x(u),y=Math.abs(p-f),g=y>d+1?d:0,m=Math.min(f,p)+g/2,b=Math.max(y-g,1);if(b>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);i.push(Ye(m,Math.min(a,u),b,Math.abs(a-u),{fill:t.config.barColors?.[s]||l?.fill||c||"#4e79a7",...h},{binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},s)),o+=n}}else{const t=r.y(0),o=r.y(e.total);i.push(Ye(m,Math.min(t,o),b,Math.abs(t-o),{fill:l?.fill||c||"#007bff",...h},{binStart:e.start,binEnd:e.end,total:e.total}))}}const f=new Set;for(const t of o.values())f.add(t.start),f.add(t.end);return{nodes:i,binBoundaries:Array.from(f).sort((t,e)=>t-e)}}(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;for(const n of e){const e=t.getX(n),c=t.getY(n);if(null==c||Number.isNaN(c))continue;const u=t.scales.x(e),d=t.scales.y(c);let h=r;if(t.getCategory){const e=t.getCategory(n);h=t.config.barColors?.[e]||h}const{r:f,...p}=t.config.pointStyle?.(n)??{},y={type:"point",x:u,y:d,r:f??i,style:{fill:h,opacity:s,stroke:a,strokeWidth:l,...p},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 f=0;for(let e=0;s.length>e;e++){const p=s[e],y=t.getX(p),g=t.getY(p),m=f+g;let b;b=s.length-1>e?t.getX(s[e+1])-y:e>0?y-t.getX(s[e-1]):0;const x=i.x(y),v=0!==b?i.x(y+b):x+o.width/10,w=Math.min(x,v)+c/2,k=Math.max(x,v)-c/2-w;if(0>=k){f=m;continue}const S=i.y(f),A=i.y(m),M=Math.min(S,A),_=Math.abs(S-A),P={fill:0>g?l:a,stroke:u,strokeWidth:d};null!=h&&(P.opacity=h),n.push(Ye(w,M,k,_,P,{...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth})),f=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 r of e){const e=t.getX(r);if(null==e||Number.isNaN(e))continue;const s=t.getHigh(r),d=t.getLow(r);if(null==s||Number.isNaN(s)||null==d||Number.isNaN(d))continue;const f=n?s:t.getOpen(r),p=n?d:t.getClose(r);if(!n&&[f,p].some(t=>null==t||Number.isNaN(t)))continue;const y=p>=f,g={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(f),closeY:t.scales.y(p),highY:t.scales.y(s),lowY:t.scales.y(d),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:y,datum:r};n&&(g.isRange=!0,g.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),i.push(g)}return i}(i,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,o,n){const i=t.boundsStyle;return"function"==typeof i?i(o||{},e):i&&"object"==typeof i?i:{fill:n(e,o).stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none"}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Te(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=$e(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=$e(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]=Te(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]=Te(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=Te(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=Te(t,e,i);"heatcell"===o.type?o.style={opacity:r}:"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&&Fe(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=Ee(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:r.style.opacity}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:r.style.opacity,glyph:r.glyph}):"rect"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:r.style.opacity}):"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:r.style?.opacity}):"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:r.style?.opacity}):"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=Ee(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=Ie()){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=Ee(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=r.style.opacity??1,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=r.style.opacity??1,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=r.style.opacity??1,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=r.style.opacity??1,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=r.style.opacity??1,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=r.style.opacity??1,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=r.style?.opacity??1,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=r.style?.opacity??1,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=r.style?.opacity??1,(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=r.style?.opacity??1,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=Re(t,o.activeTransition),r=Ce(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=Le(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=Le(o.x,t._targetX,r),t.y=Le(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Le(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=Le(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=Le(o.x,t._targetX,r),t.y=Le(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Le(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=Le(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=Le(o.x,t._targetX,r),t.y=Le(o.y,t._targetY,r),void 0!==o.w&&(t.w=Le(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Le(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:Le(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=Le(o.x,t._targetX,r),t.y=Le(o.y,t._targetY,r),void 0!==o.w&&(t.w=Le(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Le(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:Le(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=Le(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Le(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Le(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Le(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Le(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Le(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]=Le(e[n][0],o[n][0],r),t.path[n][1]=Le(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Le(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]=Le(e[o][0],n[o][0],r),t.topPath[o][1]=Le(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]=Le(o[e][0],i[e][0],r),t.bottomPath[e][1]=Le(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;for(const t of this.scene)"line"!==t.type&&"area"!==t.type||(t._introClipFraction=void 0)}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||gt,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}:{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};const s=n(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(t){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)||gt;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:t,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:e.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=Pe(t),o=this.getPointId,n=t=>e.has(o(t));Io(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=Pe(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(e){const o={...this.config},n=Object.keys(e).filter(t=>e[t]!==o[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==o.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${o.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||"themeCategorical"in e||"colorAccessor"in e)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in e||"colorScheme"in e)&&(this._barCategoryCache=null),("normalize"in e||"extentPadding"in e||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e||"boundsAccessor"in e||"band"in e||"y0Accessor"in e||"openAccessor"in e||"highAccessor"in e||"lowAccessor"in e||"closeAccessor"in e||"groupAccessor"in e||"categoryAccessor"in e||"chartType"in e||"runtimeMode"in e)&&(this._stackExtentCache=null);let i=!1,r=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();const s="chartType"in e&&e.chartType!==o.chartType||"runtimeMode"in e&&e.runtimeMode!==o.runtimeMode;if(s||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e){const e=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,n=e&&this.config.valueAccessor||this.config.yAccessor,a=e&&o.valueAccessor||o.yAccessor,l=s||!t(e&&this.config.timeAccessor||this.config.xAccessor,e&&o.timeAccessor||o.xAccessor),c=s||!t(n,a);(l||c)&&(e?(this.getX=h(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=h(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=h(this.config.xAccessor,"x"),this.getY=h(this.config.yAccessor,"y")),c&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=wo(this.config)),i=!0,r=!0)}if("groupAccessor"in e&&!t(e.groupAccessor,o.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?y(this.config.groupAccessor):void 0,i=!0),"categoryAccessor"in e&&!t(e.categoryAccessor,o.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?y(this.config.categoryAccessor):void 0,i=!0),"sizeAccessor"in e&&!t(e.sizeAccessor,o.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?h(this.config.sizeAccessor,"size"):void 0,i=!0),"symbolAccessor"in e&&!t(e.symbolAccessor,o.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?y(this.config.symbolAccessor):void 0,i=!0),"colorAccessor"in e&&!t(e.colorAccessor,o.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?y(this.config.colorAccessor):void 0,i=!0),"y0Accessor"in e&&!t(e.y0Accessor,o.y0Accessor)&&(this.getY0=this.config.y0Accessor?h(this.config.y0Accessor,"y0"):void 0,i=!0,r=!0),("boundsAccessor"in e&&!t(e.boundsAccessor,o.boundsAccessor)||"band"in e&&e.band!==o.band||"boundsStyle"in e&&e.boundsStyle!==o.boundsStyle)&&(this.resolvedRibbons=wo(this.config),i=!0,r=!0),"pointIdAccessor"in e&&!t(e.pointIdAccessor,o.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?y(this.config.pointIdAccessor):void 0,i=!0),"candlestick"===this.config.chartType&&(s||"openAccessor"in e&&!t(e.openAccessor,o.openAccessor)||"closeAccessor"in e&&!t(e.closeAccessor,o.closeAccessor)||"highAccessor"in e&&!t(e.highAccessor,o.highAccessor)||"lowAccessor"in e&&!t(e.lowAccessor,o.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?h(this.config.openAccessor,"open"):void 0,this.getHigh=h(this.config.highAccessor,"high"),this.getLow=h(this.config.lowAccessor,"low"),this.getClose=e?h(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,i=!0,r=!0}if("accessorRevision"in e&&e.accessorRevision!==o.accessorRevision&&(i=!0,r=!0),!i){const t=Object.keys(e).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const n of t)if(e[n]!==o[n]){i=!0;break}}i&&(r&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(n)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};sn.GROUP_COLOR_MAP_CAP=1e3;var an=sn;Bo(an);import{memo as ln,useEffect as cn,useRef as un}from"react";var dn={sceneGeometry:0,layout:0,domain:0};function hn(t){const{domain:e,layout:o,sceneGeometry:n}=t.revisions;return{domain:e,layout:o,sceneGeometry:n}}function fn(t,e){return{sceneGeometry:Math.max(t.sceneGeometry,e.sceneGeometry),layout:Math.max(t.layout,e.layout),domain:Math.max(t.domain,e.domain)}}var pn="production"!==process.env.NODE_ENV,yn={revisions:dn,signature:"",sawSignals:!1,wasUnconsumed:!1,warnUnconsumed:!1},gn=class{constructor(t="scene host"){this.hostName=t,this.lastConsumed=dn,this.lastObserved=dn,this.lastDuplicateWarning="",this.lastUnconsumedWarning=""}observeUpdateResult(t){pn&&(this.lastObserved=fn(this.lastObserved,hn(t)))}beforeCompute(t,e){if(!pn)return yn;const o=fn(hn(t),this.lastObserved),n=function(t){return`${t.sceneGeometry}|${t.layout}|${t.domain}`}(o),i=!((r=o).sceneGeometry===(s=this.lastConsumed).sceneGeometry&&r.layout===s.layout&&r.domain===s.domain);var r,s;return{revisions:o,signature:n,sawSignals:t.changed.has("scene-geometry")||t.changed.has("layout")||t.changed.has("domain"),wasUnconsumed:i,warnUnconsumed:!e&&i&&this.lastUnconsumedWarning!==n}}afterCompute(t,e,o){if(pn){if(e&&t.wasUnconsumed&&(this.lastConsumed=t.revisions),t.warnUnconsumed&&!e)return console.warn(`[semiotic] ${this.hostName} observed scene-affecting revisions without a scene rebuild: ${t.signature}.`),void(this.lastUnconsumedWarning=t.signature);e&&t.sawSignals&&!t.wasUnconsumed&&!o&&this.lastDuplicateWarning!==t.signature?(console.warn(`[semiotic] ${this.hostName} performed scene rebuild with unchanged scene revisions: ${t.signature}.`),this.lastDuplicateWarning=t.signature):e&&!t.sawSignals&&(this.lastDuplicateWarning="")}}},mn=ln(function({store:t,diagnostics:e}){return cn(()=>{const o=()=>e.observeUpdateResult(t.getUpdateSnapshot());return o(),t.subscribeUpdateResult(o)},[e,t]),null});import*as bn from"react";function xn(...t){const e=t.filter(t=>null!=t);return 0===e.length?null:1===e.length?e[0]:bn.createElement(bn.Fragment,null,...e)}import{useEffect as vn,useRef as wn}from"react";function kn(t,e,o){return o.x>t||t>o.x+o.w||o.y>e||e>o.y+o.h?{hit:!1,cx:0,cy:0}:{hit:!0,cx:o.x+o.w/2,cy:o.y+o.h/2}}function Sn(t,e=30){return Math.max((t??4)+5,12,e)}function An(t){return t instanceof Date?t:"number"==typeof t&&t>1e9?new Date(t):null}function Mn(t,e){const o=An(t);if(!o)return!1;const n=An(e);return!n||o.getFullYear()!==n.getFullYear()||o.getMonth()!==n.getMonth()}var _n=[40,40],Pn=[.5,.5];function Cn(t,e){const[o,n]=t.viewBox??_n,[i,r]=t.anchor??Pn,s=n>0?n:1,a=Math.max(0,e)/s,l=(o>0?o:s)*a,c=s*a;return{width:l,height:c,scale:a,offsetX:-i*l,offsetY:-r*c}}function Rn(t,e,o,n){if("none"!==t)return"color"===t||null==t?e??n:"accent"===t?o:t}var Ln=null;function In(t){if("undefined"==typeof Path2D)return null;Ln||(Ln=new Map);const e=Ln.get(t);if(e)return e;const o=new Path2D(t);return Ln.size>1024&&Ln.clear(),Ln.set(t,o),o}function Tn(t,e,o=0,n="horizontal"){const[i,r]=t.viewBox??_n,s=Math.min(1,Math.max(0,o)),a=Math.min(1,Math.max(0,e));return a>s?s>0||1>a?"vertical"===n?{x:0,y:r*(1-a),width:i,height:r*(a-s)}:{x:i*s,y:0,width:i*(a-s),height:r}:null:{x:0,y:0,width:0,height:0}}function $n(t,e){const o=Cn(t,e);return{centerDx:o.offsetX+o.width/2,centerDy:o.offsetY+o.height/2,halfWidth:o.width/2,halfHeight:o.height/2,radius:Math.hypot(o.width,o.height)/2}}function zn(t,e,o,n,i,r=t=>t){for(const s of e.parts){const e=In(s.d);if(!e)continue;const a=s.opacity??1,l=t.globalAlpha;1!==a&&(t.globalAlpha=l*a);const c=i?"none"===s.fill?void 0:i:Rn(s.fill,o,n);c&&(t.fillStyle=r(c),t.fill(e));const u=i?s.stroke&&"none"!==s.stroke?i:void 0:Rn(s.stroke??"none",o,n);u&&(t.strokeStyle=r(u),t.lineWidth=s.strokeWidth??1,t.lineCap=s.strokeLinecap??"butt",t.lineJoin=s.strokeLinejoin??"miter",t.stroke(e)),1!==a&&(t.globalAlpha=l)}}var Dn=new WeakMap,Fn=0,En=!1,On=null,Bn=null;function Nn(t,e){if(!e)return e;const o=function(t){const e=t.trim();if(!e.startsWith("var(")||!e.endsWith(")"))return null;const o=e.slice(4,-1),n=o.indexOf(",");if(-1===n){const t=o.trim();return t.startsWith("--")?{name:t}:null}const i=o.slice(0,n).trim(),r=o.slice(n+1).trim();return i.startsWith("--")?{name:i,fallback:r||void 0}:null}(e);if(!o)return e;const n=()=>o.fallback?Nn(t,o.fallback):e,i=t.canvas;if(!i)return n();!function(){if(En)return;if("undefined"==typeof window||"undefined"==typeof document)return;En=!0;const t=()=>{Fn++};if("undefined"!=typeof MutationObserver&&document.documentElement&&new MutationObserver(t).observe(document.documentElement,{attributes:!0,attributeFilter:["class","style","data-theme","data-semiotic-theme"],subtree:!0}),"function"==typeof window.matchMedia)try{On=window.matchMedia("(prefers-color-scheme: dark)"),Bn=t,"function"==typeof On.addEventListener?On.addEventListener("change",Bn):"function"==typeof On.addListener&&On.addListener(Bn)}catch{}}();let r=Dn.get(i);r&&r.version===Fn||(r={version:Fn,map:new Map},Dn.set(i,r));const s=r.map.get(e);if(void 0!==s)return s;const a=getComputedStyle(i).getPropertyValue(o.name).trim()||n()||e;return r.map.set(e,a),a}function Wn(t){return{type:"hatch",background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle}}var jn=null;import{jsx as Yn,jsxs as Gn}from"react/jsx-runtime";function Hn(t){return"object"==typeof t&&null!==t&&"hatch"===t.type}function qn(t){return["hatch",t.background??"transparent",t.stroke??"#000",t.lineWidth??1.5,t.spacing??6,t.angle??45,t.lineOpacity??1].join("|")}var Vn=new Map;function Xn(t,e){const{background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45,lineOpacity:a=1}=t,l=Math.max(8,Math.ceil(2*r));return Gn("pattern",{id:e,width:l,height:l,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Yn("rect",{width:l,height:l,fill:o}),Yn("line",{x1:0,y1:0,x2:0,y2:l,stroke:n,strokeWidth:i,strokeOpacity:a}),Yn("line",{x1:r,y1:0,x2:r,y2:l,stroke:n,strokeWidth:i,strokeOpacity:a})]},e)}function Un(t,e,o="#4e79a7"){if(Hn(t)){const o=function(t,e){let o=2166136261;const n=qn(e);for(let t=0;n.length>t;t++)o^=n.charCodeAt(t),o=Math.imul(o,16777619);return`${t}-hatch-${(o>>>0).toString(36)}`}(e,t);return{fill:`url(#${o})`,def:Xn(t,o)}}return t&&"string"==typeof t?{fill:t}:{fill:o}}import{curveMonotoneX as Kn,curveMonotoneY as Zn,curveCardinal as Qn,curveCatmullRom as Jn,curveStep as ti,curveStepBefore as ei,curveStepAfter as oi,curveBasis as ni,curveNatural as ii}from"d3-shape";function ri(t){switch(t){case"monotoneX":return Kn;case"monotoneY":return Zn;case"cardinal":return Qn;case"catmullRom":return Jn;case"step":return ti;case"stepBefore":return ei;case"stepAfter":return oi;case"basis":return ni;case"natural":return ii;default:return null}}function si(t,e,o){if(null==e)return o;if(Hn(e)){const n=function(t,e){const o="undefined"!=typeof window&&window.devicePixelRatio||1,n=`${qn(t)}@${o}`,i=Vn.get(n);if(void 0!==i)return i;const r=function(t={},e){const{background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a={background:o,stroke:n,lineWidth:i,spacing:r,angle:s},l=Math.max(8,Math.ceil(2*r));let c;try{c=function(t){return"undefined"!=typeof OffscreenCanvas?new OffscreenCanvas(t,t):(jn||(jn=document.createElement("canvas")),jn.width=t,jn.height=t,jn)}(l)}catch{return Wn(a)}const u=c.getContext("2d");if(!u)return Wn(a);o&&"transparent"!==o?(u.fillStyle=o,u.fillRect(0,0,l,l)):u.clearRect(0,0,l,l),u.strokeStyle=n,u.lineWidth=i,u.lineCap="square";const d=s*Math.PI/180;if(45===s||-45===s){const t=s>0?1:-1;for(let e=-l;2*l>=e;e+=r)u.beginPath(),u.moveTo(e,0),u.lineTo(e+t*l,l),u.stroke()}else{u.save(),u.translate(l/2,l/2),u.rotate(d);const t=2*l;for(let e=-t;t>=e;e+=r)u.beginPath(),u.moveTo(-t,e),u.lineTo(t,e),u.stroke();u.restore()}return(e||u).createPattern(c,"repeat")}({background:t.background,stroke:t.stroke,lineWidth:t.lineWidth,spacing:t.spacing,angle:t.angle},e),s=Hn(r)?null:r;return Vn.set(n,s),s}(e,t);return n||e.background&&Nn(t,e.background)||o}return"string"!=typeof e?e:Nn(t,e)||o}function ai(t,e,o,n,i,r,s){const a=e.stops.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity)));if(2>a.length)return null;const l=t.createLinearGradient(n,i,r,s);for(const e of a)l.addColorStop(Math.max(0,Math.min(1,e.offset)),li(t,e,o));return l}function li(t,e,o){const n=e.color??o,i=Nn(t,n)||n;if(null==e.opacity)return i;const r=Math.max(0,Math.min(1,e.opacity)),[s,a,l]=function(t,e){const o=t.fillStyle,n="#010203";try{t.fillStyle=n,t.fillStyle=e}catch{return t.fillStyle=o,[78,121,167]}const i=t.fillStyle;if(t.fillStyle=o,"string"!=typeof i)return[78,121,167];if(i.toLowerCase()===n&&e.trim().toLowerCase()!==n)return[78,121,167];if(i.startsWith("#"))return[parseInt(i.slice(1,3),16),parseInt(i.slice(3,5),16),parseInt(i.slice(5,7),16)];const r=i.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return r?[+r[1],+r[2],+r[3]]:[78,121,167]}(t,i);return`rgba(${s},${a},${l},${r})`}function ci(t,e,o,n,i,r,s){const a=e.stops.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity)));if(2>a.length)return null;const l=t.createLinearGradient(n,i,r,s);for(const e of a)l.addColorStop(Math.max(0,Math.min(1,e.offset)),li(t,e,o));return l}import{line as ui}from"d3-shape";var di=new WeakMap;function hi(t,e){const o=ri(e);if(!o)return t;const n=di.get(t);if(n)return n;const i=function(t,e,o=8){if(!e||2>t.length)return t.map(([t,e])=>[t,e]);const n=[];let i=null;const r={moveTo(t,e){i=[t,e],n.push([t,e])},lineTo(t,e){i=[t,e],n.push([t,e])},bezierCurveTo(t,e,r,s,a,l){if(!i)return i=[a,l],void n.push([a,l]);const[c,u]=i;for(let i=1;o>=i;i++){const d=i/o,h=1-d;n.push([h*h*h*c+3*h*h*d*t+3*h*d*d*r+d*d*d*a,h*h*h*u+3*h*h*d*e+3*h*d*d*s+d*d*d*l])}i=[a,l]},closePath(){},arc(){},rect(){},arcTo(){},quadraticCurveTo(t,e,o,r){i=[o,r],n.push([o,r])}};return ui().x(t=>t[0]).y(t=>t[1]).curve(e).context(r)(t),n}(t,o);return di.set(t,i),i}function fi(t,e,o,n=30,i,r=0){let s=null;if(i){const t=function(t,e,o,n,i,r=t=>t.x,s=t=>t.y,a=t=>t.r){const l=Math.max(n,i+5,12),c=e-l,u=e+l,d=o-l,h=o+l;let f=null,p=1/0;return t.visit((t,i,l,y,g)=>{if(i>u||c>y||l>h||d>g)return!0;if(!t.length){let i=t;do{const t=i.data,l=r(t)-e,c=s(t)-o,u=Math.sqrt(l*l+c*c);Sn(a(t),n)>=u&&p>u&&(f=t,p=u),i=i.next}while(i)}return!1}),f?{node:f,distance:p}:null}(i,e,o,n,r);t&&(s={node:t.node,datum:t.node.datum,x:t.node.x,y:t.node.y,distance:t.distance})}for(const r of t){let t=null;switch(r.type){case"point":if(i)break;t=yi(r,e,o,n);break;case"symbol":t=gi(r,e,o,n);break;case"glyph":t=mi(r,e,o,n);break;case"line":t=bi(r,e,o,n);break;case"rect":if(null==r.datum)break;t=vi(r,e,o);break;case"heatcell":t=wi(r,e,o);break;case"area":if(!1===r.interactive)break;t=Si(r,e,o);break;case"candlestick":t=ki(r,e,o)}t&&n>t.distance&&(s&&t.distance>=s.distance||(s=t))}return s}function pi(t,e,o){if(0===t.length)return null;if(t[0][0]>e||e>t[t.length-1][0])return null;const n=Ai(t,e);if(0>n)return null;if(Math.abs(t[n][0]-e)>o)return null;let i=n,r=n;n>0&&t[n][0]>=e?(i=n-1,r=n):t.length-1>n&&(i=n,r=n+1);const[s,a]=t[i],[l,c]=t[r];return l===s?a:a+Math.max(0,Math.min(1,(e-s)/(l-s)))*(c-a)}function yi(t,e,o,n=30){const i=e-t.x,r=o-t.y,s=Math.sqrt(i*i+r*r);return s>Sn(t.r,n)?null:{node:t,datum:t.datum,x:t.x,y:t.y,distance:s}}function gi(t,e,o,n=30){const i=e-t.x,r=o-t.y,s=Math.sqrt(i*i+r*r);return s>Sn(ho(t.size),n)?null:{node:t,datum:t.datum,x:t.x,y:t.y,distance:s}}function mi(t,e,o,n=30){if(null==t.datum)return null;const i=$n(t.glyph,t.size),r=t.x+i.centerDx,s=t.y+i.centerDy,a=e-r,l=o-s,c=Math.sqrt(a*a+l*l);return c>Sn(i.radius,n)?null:{node:t,datum:t.datum,x:r,y:s,distance:c}}function bi(t,e,o,n=30){if(0===t.path.length)return null;const i=Ai(t.path,e);if(0>i)return null;const[r,s]=t.path[i];let a;if(t.path.length>1){let n=1/0;const r=Math.max(0,i-1),s=Math.min(t.path.length-2,i);for(let i=r;s>=i;i++){const[r,s]=t.path[i],[a,l]=t.path[i+1],c=xi(e,o,r,s,a,l);n>c&&(n=c)}a=n}else{const t=e-r,n=o-s;a=Math.sqrt(t*t+n*n)}const l=t.style;return a>Math.max(5,(l.strokeWidth??l.lineWidth??1)/2+2,n)?null:{node:t,datum:Array.isArray(t.datum)&&t.datum[i]?t.datum[i]:t.datum,x:r,y:s,distance:a}}function xi(t,e,o,n,i,r){const s=i-o,a=r-n,l=s*s+a*a;if(0===l)return Math.sqrt((t-o)**2+(e-n)**2);let c=((t-o)*s+(e-n)*a)/l;return c=Math.max(0,Math.min(1,c)),Math.sqrt((t-(o+c*s))**2+(e-(n+c*a))**2)}function vi(t,e,o){const n=kn(e,o,t);return n.hit?{node:t,datum:t.datum,x:n.cx,y:n.cy,distance:0}:null}function wi(t,e,o){const n=kn(e,o,t);return n.hit?{node:t,datum:t.datum,x:n.cx,y:n.cy,distance:0}:null}function ki(t,e,o){const n=t.bodyWidth/2,i=Math.min(t.openY,t.closeY);if(!(t.x-n-3>e||e>t.x+n+3||t.highY-3>o||o>t.lowY+3)){const n=i+Math.max(Math.max(t.openY,t.closeY)-i,1)/2,r=e-t.x,s=o-n;return{node:t,datum:t.datum,x:t.x,y:n,distance:Math.sqrt(r*r+s*s)}}return null}function Si(t,e,o){if(0===t.topPath.length)return null;const n=Ai(t.topPath,e);if(0>n)return null;const[i,r]=t.topPath[n],s=e-i,a=o-r,l=Math.sqrt(s*s+a*a);return{node:t,datum:Array.isArray(t.datum)&&t.datum[n]?t.datum[n]:t.datum,x:i,y:r,distance:l}}function Ai(t,e){if(0===t.length)return-1;let o=0,n=t.length-1;for(;n>o;){const i=o+n>>1;e>t[i][0]?o=i+1:n=i}return o>0&&Math.abs(t[o][0]-e)>=Math.abs(t[o-1][0]-e)?o-1:o}import{useEffect as Mi,useRef as _i}from"react";var Pi={fresh:1,aging:.7,stale:.45,expired:.25},Ci={alpha:1,band:"fresh",isStale:!1};function Ri(t,e){if(!t||0>=e)return Ci;const o=null!=t.threshold&&t.threshold>0?t.threshold:5e3,n=t.graded;if(n){const t="object"==typeof n?n:{},r=i(e,o,t.thresholds);return{alpha:{...Pi,...t.opacities??{}}[r],band:r,isStale:"fresh"!==r}}return e>o?{alpha:t.dimOpacity??.5,band:"stale",isStale:!0}:Ci}import{jsx as Li}from"react/jsx-runtime";function Ii({isStale:t,position:e}){return Li("div",{className:"stream-staleness-badge",style:{position:"absolute",..."top-left"===e?{top:4,left:4}:"bottom-left"===e?{bottom:4,left:4}:"bottom-right"===e?{bottom:4,right:4}:{top:4,right:4},padding:"2px 8px",borderRadius:4,fontSize:11,fontWeight:600,pointerEvents:"none",zIndex:3,background:t?"#dc3545":"#28a745",color:"white"},children:t?"STALE":"LIVE"})}import{useMemo as Ti,useRef as $i,useEffect as zi}from"react";import*as Di from"react";function Fi(...t){let e;for(const o of t)o&&(e=Ei(e)&&Ei(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function Ei(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function Oi(t){return"object"==typeof t&&null!==t&&"gradient"in t}function Bi(t){return Math.ceil(7*t.length)}function Ni(t,e){if(Ei(t)){const o=qi(e),n=t.legendGroups.flatMap(t=>[t.label?Bi(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+Bi(t.label))]);return Math.max(100,...n)}if(Oi(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),n=Math.max(Bi(o(e.domain[0])),Bi(o(e.domain[1]))),i=e.label?Bi(e.label):0;return Math.max(100,19+n,i)}return 100}function Wi(t){return(Ei(t)||Oi(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function ji(t){return Math.max(0,t?.sideGutter??0)}function Yi(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function Gi(t,e,o){if(Oi(t))return t.gradient.label?34:26;if(!Ei(t))return 20;const n=qi(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+Bi(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?Bi(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function Hi(t,e){return Ni(t,e)+Wi(t)+ji(e)}function qi(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 Vi(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}})}import{jsx as Xi,jsxs as Ui}from"react/jsx-runtime";var Ki={fill:(t,e)=>Xi("rect",{style:t,width:e,height:e}),line:(t,e)=>Xi("line",{style:t,x1:0,y1:0,x2:e,y2:e})};function Zi(t,e,o,n,i){let r;return r="function"==typeof o?o(t):(0,Ki[o])(n(t,e),i),r}function Qi({swatchSize:t}){return Xi("path",{d:`M${.25*t},${.55*t} L${.45*t},${.75*t} L${.8*t},${.3*t}`,fill:"none",stroke:"white",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"})}function Ji(t,e,o){return o&&o.size>0?o.has(t.label)?1:.3:null!=e?t.label===e?1:.3:1}var tr=(t,e,o,n,i,r,s,a,l,c,u)=>{const{type:d="fill",styleFn:h,items:f}=t,p=[];let y=0;const g=!(!e&&!o),m="isolate"===c||void 0===c&&null!=i,{swatchSize:b,labelGap:x,rowHeight:v}=u;return f.forEach((t,c)=>{const u=Zi(t,c,d,h,b),w=Ji(t,n,i),k=i&&i.size>0&&i.has(t.label);p.push(Ui("g",{transform:`translate(0,${y})`,onClick:e?()=>e(t):void 0,onMouseEnter:o?()=>o(t):void 0,onMouseLeave:o?()=>o(null):void 0,tabIndex:g?a===r&&c===s?0:-1:void 0,role:g?"option":void 0,"aria-selected":g&&m?k||!1:void 0,"aria-current":g&&!m&&null!=n&&t.label===n||void 0,"aria-label":t.label,onKeyDown:g?o=>{if("Enter"!==o.key&&" "!==o.key||(o.preventDefault(),e&&e(t)),"ArrowDown"===o.key||"ArrowUp"===o.key){o.preventDefault();const t=(c+("ArrowDown"===o.key?1:-1)+f.length)%f.length;l(a,t);const e=o.currentTarget.parentElement?.children[t];e instanceof SVGElement&&e.focus()}}:void 0,onFocus:g?e=>{l(a,c),o&&o(t);const n=e.currentTarget.querySelector(".semiotic-legend-focus-ring");n&&n.setAttribute("visibility","visible")}:void 0,onBlur:g?t=>{o&&o(null);const e=t.currentTarget.querySelector(".semiotic-legend-focus-ring");e&&e.setAttribute("visibility","hidden")}:void 0,style:{cursor:g?"pointer":"default",opacity:w,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[g&&Xi("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:b+x+2+7*t.label.length,height:b+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),u,k&&Xi(Qi,{swatchSize:b}),Xi("text",{y:b/2,x:b+x,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label})]},"legend-item-"+c)),y+=v}),p};function er({config:t,orientation:e="vertical",width:o=100}){const{colorFn:n,domain:i,label:r,format:s}=t,a=s||(t=>Math.round(100*t)/100+""),l="grad-legend-"+Di.useId();if("horizontal"===e){const t=12,e=Math.min(o,200),s=Math.max(0,(o-e)/2),c=[];for(let t=0;64>=t;t++){const e=t/64;c.push(Xi("stop",{offset:100*e+"%",stopColor:n(i[0]+e*(i[1]-i[0]))},t))}return Ui("g",{"aria-label":r||"Gradient legend",children:[Xi("defs",{children:Xi("linearGradient",{id:l,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),r&&Xi("text",{x:s+e/2,y:-4,textAnchor:"middle",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),Xi("rect",{x:s,y:0,width:e,height:t,fill:`url(#${l})`,rx:2}),Xi("text",{x:s,y:t+12,textAnchor:"start",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])}),Xi("text",{x:s+e,y:t+12,textAnchor:"end",fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])})]})}const c=[];for(let t=0;64>=t;t++){const e=t/64;c.push(Xi("stop",{offset:100*e+"%",stopColor:n(i[1]-e*(i[1]-i[0]))},t))}return Ui("g",{"aria-label":r||"Gradient legend",children:[r&&Xi("text",{x:0,y:-6,textAnchor:"start",fontSize:11,fill:"var(--semiotic-text, #333)",children:r}),Xi("defs",{children:Xi("linearGradient",{id:l,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),Xi("rect",{x:0,y:0,width:14,height:100,fill:`url(#${l})`,rx:2}),Xi("text",{x:19,y:10,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[1])}),Xi("text",{x:19,y:100,fontSize:10,fill:"var(--semiotic-text-secondary, #666)",children:a(i[0])})]})}function or(t){const{legendGroups:e,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,legendInteraction:s,title:a="Legend",width:l=100,height:c=20,orientation:u="vertical",legendLayout:d}=t,h=qi(d),[f,p]=Di.useState(0),[y,g]=Di.useState(0),m=Di.useCallback((t,e)=>{p(t),g(e)},[]),b="vertical"===u?(({legendGroups:t,width:e,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:s,focusedItemIndex:a,onFocusedIndexChange:l,legendInteraction:c,metrics:u})=>{const d=[],h=Vi(t.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),u.rowHeight);return t.forEach((t,f)=>{const p=h[f];d.push(Xi("line",{stroke:"gray",x1:0,y1:p.lineY,x2:e,y2:p.lineY},"legend-top-line legend-symbol-"+f)),t.label&&null!=p.labelY&&d.push(Xi("text",{y:p.labelY,className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label},"legend-text-"+f)),d.push(Xi("g",{className:"legend-item",transform:`translate(0,${p.itemsY})`,children:tr(t,o,n,i,r,s,a,f,l,c,u)},"legend-group-"+f))}),d})({legendGroups:e||[],width:l,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:y,onFocusedIndexChange:m,legendInteraction:s,metrics:h}):(({legendGroups:t,height:e,width:o,customClickBehavior:n,customHoverBehavior:i,highlightedCategory:r,isolatedCategories:s,focusedGroupIndex:a,focusedItemIndex:l,onFocusedIndexChange:c,legendInteraction:u,metrics:d})=>{let h=0;const f=[];t.forEach((t,e)=>{let p=0;t.label&&(p+=16);const y=((t,e,o,n,i,r,s,a,l,c,u,d)=>{const{type:h="fill",styleFn:f,items:p}=t,y=[],{swatchSize:g,labelGap:m,itemGap:b,rowHeight:x,align:v}=u,w=!(!e&&!o),k="isolate"===c||void 0===c&&null!=i,S=p.map(t=>g+m+7*t.label.length),A=[];let M=0,_=0;S.forEach((t,e)=>{const o=0===_?t:_+b+t;d&&d>0&&_>0&&o>d?(A.push({start:M,end:e,width:_}),M=e,_=t):_=o}),p.length>0&&A.push({start:M,end:p.length,width:_}),A.forEach((t,c)=>{let u="center"===v?Math.max(0,((d??t.width)-t.width)/2):"end"===v?Math.max(0,(d??t.width)-t.width):0;for(let d=t.start;t.end>d;d++){const t=p[d],v=Zi(t,d,h,f,g),A=Ji(t,n,i),M=i&&i.size>0&&i.has(t.label);y.push(Ui("g",{transform:`translate(${u},${c*x})`,onClick:e?()=>e(t):void 0,onMouseEnter:o?()=>o(t):void 0,onMouseLeave:o?()=>o(null):void 0,tabIndex:w?a===r&&d===s?0:-1:void 0,role:w?"option":void 0,"aria-selected":w&&k?M||!1:void 0,"aria-current":w&&!k&&null!=n&&t.label===n||void 0,"aria-label":t.label,onKeyDown:w?o=>{if("Enter"!==o.key&&" "!==o.key||(o.preventDefault(),e&&e(t)),"ArrowRight"===o.key||"ArrowLeft"===o.key){o.preventDefault();const t=(d+("ArrowRight"===o.key?1:-1)+p.length)%p.length;l(a,t);const e=o.currentTarget.parentElement?.children[t];e instanceof SVGElement&&e.focus()}}:void 0,onFocus:w?e=>{l(a,d),o&&o(t);const n=e.currentTarget.querySelector(".semiotic-legend-focus-ring");n&&n.setAttribute("visibility","visible")}:void 0,onBlur:w?t=>{o&&o(null);const e=t.currentTarget.querySelector(".semiotic-legend-focus-ring");e&&e.setAttribute("visibility","hidden")}:void 0,style:{cursor:w?"pointer":"default",opacity:A,transition:"opacity 150ms ease",pointerEvents:"all",outline:"none"},children:[w&&Xi("rect",{className:"semiotic-legend-focus-ring",x:-2,y:-2,width:g+m+2+7*t.label.length,height:g+4,fill:"none",stroke:"var(--semiotic-focus, #005fcc)",strokeWidth:2,rx:3,visibility:"hidden"}),v,M&&Xi(Qi,{swatchSize:g}),Xi("text",{y:g/2,x:g+m,dominantBaseline:"central",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:t.label})]},"legend-item-"+d)),u+=S[d]+b}});const P=Math.max(0,...A.map(t=>t.width)),C=A.length;return{items:y,offset:P,totalRows:C,totalHeight:C*x}})(t,n,i,r,s,a,l,e,c,u,d,d.maxWidth??o);p+=y.offset+5,f.push({label:t.label,...y,offset:p,totalRows:y.totalRows,totalHeight:y.totalHeight}),h+=p+12});const p=d.maxWidth??o;let y=h>p?0:"center"===d.align?Math.max(0,(p-h)/2):"end"===d.align?Math.max(0,p-h):0;const g=[];return f.forEach((o,n)=>{const i=t[n];i.label&&(g.push(Xi("text",{transform:`translate(${y},0) rotate(90)`,textAnchor:"start",className:"legend-group-label",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:i.label},"legend-text-"+n)),y+=16),g.push(Xi("g",{className:"legend-item",transform:`translate(${y},0)`,children:o.items},"legend-group-"+n)),y+=o.offset+5,t[n+1]&&g.push(Xi("line",{stroke:"gray",x1:y,y1:-8,x2:y,y2:(o.totalHeight||e)+0+8},"legend-top-line legend-symbol-"+n)),y+=12}),Xi("g",{children:g})})({legendGroups:e||[],title:a,height:c,width:l,customClickBehavior:o,customHoverBehavior:n,highlightedCategory:i,isolatedCategories:r,focusedGroupIndex:f,focusedItemIndex:y,onFocusedIndexChange:m,legendInteraction:s,metrics:h}),x=!(!o&&!n);return Ui("g",{role:x?"listbox":void 0,"aria-multiselectable":!(!x||"isolate"!==s&&(void 0!==s||null==r))||void 0,"aria-label":"Chart legend",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[void 0!==a&&""!==a&&"vertical"===u&&Xi("text",{className:"legend-title",y:16,x:l/2,textAnchor:"middle",style:{fontSize:"var(--semiotic-legend-font-size, 12px)"},fill:"var(--semiotic-text, #333)",children:a}),b]})}import{jsx as nr}from"react/jsx-runtime";function ir(t){const{legend:e,totalWidth:o,totalHeight:n,margin:i,legendPosition:r="right",legendLayout:s,legendHoverBehavior:a,legendClickBehavior:l,legendHighlightedCategory:c,legendIsolatedCategories:u,legendInteraction:d}=t;if(!e)return null;const h="top"===r||"bottom"===r,f=Math.max(0,o-i.left-i.right),p=Math.max(1,h?s?.maxWidth??f:Ni(e,s)),y=Wi(e),g=ji(s),m=Yi(t.axisChrome,s),b=Yi(void 0,s),x=Gi(e,f,s);let v,w;if("left"===r)v=i.left-g-p-y,w=i.top;else if("top"===r)v=i.left,w=i.top-b-y-x;else if("bottom"===r){v=i.left;const t=n-i.bottom;w=Math.max(t+y,Math.min(t+m+y,n-x))}else v=o-i.right+g+y,w=i.top;return nr("g",{transform:`translate(${v}, ${w})`,children:Oi(e)?nr(er,{config:e.gradient,orientation:h?"horizontal":"vertical",width:p}):Ei(e)?nr(or,{legendGroups:e.legendGroups,title:"",width:p,orientation:h?"horizontal":"vertical",legendLayout:s,customHoverBehavior:a,customClickBehavior:l,highlightedCategory:c,isolatedCategories:u,legendInteraction:d}):e})}import{useMemo as rr}from"react";import{bin as sr}from"d3-array";import{jsx as ar,jsxs as lr}from"react/jsx-runtime";function cr(t){return"string"==typeof t?{type:t}:t}function ur({orient:t,config:e,values:o,scale:n,size:i,length:r}){const s=function(t){return{type:t.type,bins:t.bins??20,fill:t.fill??"#4e79a7",fillOpacity:t.fillOpacity??.5,stroke:t.stroke??"none",strokeWidth:t.strokeWidth??1}}(e),a="top"===t||"bottom"===t,l=rr(()=>{if(0===o.length)return null;const e=n.domain(),l=i-8;if("boxplot"===s.type){const e=function(t){const e=[...t].sort((t,e)=>t-e),o=e.length;if(0===o)return null;const n=e[Math.floor(.25*o)],i=e[Math.floor(.5*o)],r=e[Math.floor(.75*o)],s=r-n;return{q1:n,median:i,q3:r,whiskerLow:Math.max(e[0],n-1.5*s),whiskerHigh:Math.min(e[o-1],r+1.5*s)}}(o);if(!e)return null;const{q1:i,median:r,q3:c,whiskerLow:u,whiskerHigh:d}=e,h=Math.min(.5*l,20),f=(l-h)/2+4;if(a){const e=n(i),o=n(c),a=n(r),l=n(u),p=n(d),y="top"===t?-1:1,g=0;return lr("g",{"data-testid":"marginal-boxplot-"+t,children:[ar("line",{x1:l,y1:g+y*(f+h/2),x2:p,y2:g+y*(f+h/2),stroke:s.fill,strokeWidth:s.strokeWidth}),ar("line",{x1:l,y1:g+y*f,x2:l,y2:g+y*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),ar("line",{x1:p,y1:g+y*f,x2:p,y2:g+y*(f+h),stroke:s.fill,strokeWidth:s.strokeWidth}),ar("rect",{x:Math.min(e,o),y:"top"===t?g-f-h:g+f,width:Math.abs(o-e),height:h,fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),ar("line",{x1:a,y1:"top"===t?g-f-h:g+f,x2:a,y2:"top"===t?g-f:g+f+h,stroke:s.fill,strokeWidth:2})]})}{const e=n(i),o=n(c),a=n(r),l=n(u),p=n(d),y="left"===t?-1:1,g=0;return lr("g",{"data-testid":"marginal-boxplot-"+t,children:[ar("line",{x1:g+y*(f+h/2),y1:l,x2:g+y*(f+h/2),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),ar("line",{x1:g+y*f,y1:l,x2:g+y*(f+h),y2:l,stroke:s.fill,strokeWidth:s.strokeWidth}),ar("line",{x1:g+y*f,y1:p,x2:g+y*(f+h),y2:p,stroke:s.fill,strokeWidth:s.strokeWidth}),ar("rect",{x:"left"===t?g-f-h:g+f,y:Math.min(e,o),width:h,height:Math.abs(o-e),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth}),ar("line",{x1:"left"===t?g-f-h:g+f,y1:a,x2:"left"===t?g-f:g+f+h,y2:a,stroke:s.fill,strokeWidth:2})]})}}const c=sr().domain(e).thresholds(s.bins)(o);if(0===c.length)return null;const u=At(c.map(t=>t.length));if(0===u)return null;if("histogram"===s.type)return ar("g",{"data-testid":"marginal-histogram-"+t,children:c.map((e,o)=>{if(null==e.x0||null==e.x1)return null;const i=e.length/u*l;if(a){const r=n(e.x0),a=n(e.x1)-n(e.x0);return ar("rect",{x:r,y:"top"===t?-4-i:4,width:Math.max(a,.5),height:i,fill:s.fill,fillOpacity:s.fillOpacity,stroke:s.stroke,strokeWidth:s.strokeWidth},o)}{const r=n(e.x0),a=n(e.x1)-n(e.x0);return ar("rect",{x:"left"===t?-4-i:4,y:Math.min(r,r+a),width:i,height:Math.abs(a),fill:s.fill,fillOpacity:s.fillOpacity,stroke:s.stroke,strokeWidth:s.strokeWidth},o)}})});if("violin"===s.type){const e=l/2+4,o=[];for(const i of c){if(null==i.x0||null==i.x1)continue;const r=i.length/u*(l/2),s=n((i.x0+i.x1)/2);o.push(a?`${s},${"top"===t?-(e-r):e-r}`:`${"left"===t?-(e-r):e-r},${s}`)}for(let i=c.length-1;i>=0;i--){const r=c[i];if(null==r.x0||null==r.x1)continue;const s=r.length/u*(l/2),d=n((r.x0+r.x1)/2);o.push(a?`${d},${"top"===t?-(e+s):e+s}`:`${"left"===t?-(e+s):e+s},${d}`)}return ar("g",{"data-testid":"marginal-violin-"+t,children:ar("polygon",{points:o.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}if("ridgeline"===s.type){const e=[];if(a){const o=0,i=null!=c[0].x0?n(c[0].x0):0;e.push(`M${i},${o}`);for(const o of c){if(null==o.x0||null==o.x1)continue;const i=o.length/u*l,r=n((o.x0+o.x1)/2);e.push(`L${r},${"top"===t?-i-4:i+4}`)}const s=null!=c[c.length-1].x1?n(c[c.length-1].x1):r;e.push(`L${s},${o}`),e.push("Z")}else{const o=0,i=null!=c[0].x0?n(c[0].x0):0;e.push(`M${o},${i}`);for(const o of c){if(null==o.x0||null==o.x1)continue;const i=o.length/u*l,r=n((o.x0+o.x1)/2);e.push(`L${"left"===t?-i-4:i+4},${r}`)}const s=null!=c[c.length-1].x1?n(c[c.length-1].x1):r;e.push(`L${o},${s}`),e.push("Z")}return ar("g",{"data-testid":"marginal-ridgeline-"+t,children:ar("path",{d:e.join(" "),fill:s.fill,fillOpacity:s.fillOpacity,stroke:"none"===s.stroke?s.fill:s.stroke,strokeWidth:s.strokeWidth})})}return null},[o,n,s,i,r,t,a,4]);return l?ar("g",{className:"marginal-"+t,"data-testid":"marginal-"+t,children:l}):null}import*as dr from"react";import{jsx as hr,jsxs as fr}from"react/jsx-runtime";function pr(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 yr(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 gr(t,e,o,n){if(!t)return hr("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=t;if(!i&&!r)return hr("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(o)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>o?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>e?"end":"start";const f=16,p=r?c?[r]:pr(r,l):[],y=i?c?[i]:pr(i,l):[],g="leftRight"===u?"end"===h?-4:4:0;let m=0;const b=[],x=n||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?b.push(hr("foreignObject",{className:"annotation-note-html",x:"end"===h?g-l:"middle"===h?g-l/2:g,y:-16,width:l,height:Math.max(f,(p.length+y.length)*f+(r&&i?2:0))+f,style:{overflow:"visible"},children:fr("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:x,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&hr("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&hr("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(p.length>0&&(b.push(hr("text",{className:"annotation-note-title",fill:x,textAnchor:h,fontWeight:"bold",children:p.map((t,e)=>hr("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-title")),m=p.length*f),y.length>0&&b.push(hr("text",{className:"annotation-note-label",fill:x,textAnchor:h,y:m,children:y.map((t,e)=>hr("tspan",{x:g,dy:0===e?0:f,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(l,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=hr("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(p.length+y.length)*f+(y.length>0?f:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=hr("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,p.length+y.length-1)*f;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+f+(y.length>0&&p.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),fr("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[hr("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:b}),v]})}function mr(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(hr("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(hr("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(hr("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(hr("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(hr("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(hr("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(hr("path",{d:yr(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return hr("g",{className:"annotation-subject",children:r})}function br(t,e,o,n,i,r){const s=[];let a=0,l=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const o=r.width||0,n=r.height||0;if(o>0||n>0){const i=o/2,r=n/2,s=t-i,c=e-r;if(0!==s||0!==c){const t=Math.abs(s),e=Math.abs(c),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,l=o):void 0!==e&&(a=o,l=e/2)}}else{const o=(r.radius||0)+(r.radiusPadding||0);if(o>0&&(0!==t||0!==e)){const n=Math.atan2(e,t);a=Math.cos(n)*o,l=Math.sin(n)*o}}const c=Math.sqrt((t-a)**2+(e-l)**2);if(c>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-l,t-a);if(r){const n=(a+t)/2,r=(l+e)/2,d=-(e-l)/c,h=(t-a)/c,f=(o?.curve??.25)*c,p=n+d*f,y=r+h*f;s.push(hr("path",{className:"connector-curve",d:`M${a},${l}Q${p},${y} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(y-l,p-a)}else s.push(hr("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(hr("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 hr("g",{className:"annotation-connector",children:s})}function xr(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:y,events:g={},"data-testid":m}=t,b=Array.isArray(e)?e[0]??0:e,x=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(f)?f:[]);let w=n||0,k=i||0;null!=r&&(w=r-b),null!=s&&(k=s-x);const S="string"==typeof u?u:"label";if("bracket"===S&&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 fr("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${b},${x})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.has("connector")&&br(w,k,l,d,S,c),!v.has("subject")&&mr(S,c,d,b,x),!v.has("note")&&gr(a,w,k,d)]})}function vr(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 hr(xr,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return hr("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return hr(xr,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{packEnclose as wr}from"d3-hierarchy";import{area as kr,curveLinear as Sr,curveMonotoneX as Ar,curveMonotoneY as Mr,curveStep as _r,curveStepAfter as Pr,curveStepBefore as Cr,curveBasis as Rr,curveCardinal as Lr,curveCatmullRom as Ir}from"d3-shape";function Tr(t){return Math.round(100*t)/100}function $r(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(Tr);return{points:t.map(([t])=>[Tr(t),Tr(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function zr(t,e){const o=e.scales?.x??e.scales?.time;return o?null!=t.x?o(t.x):e.xAccessor&&null!=t[e.xAccessor]?o(t[e.xAccessor]):null:null}function Dr(t,e){const o=e.scales?.y??e.scales?.value;return o?null!=t.y?o(t.y):e.yAccessor&&null!=t[e.yAccessor]?o(t[e.yAccessor]):null:null}function Fr(t){return null==t?null:t+""}function Er(t,e,o){return e.stickyPositionCache?.set(t,o),o}function Or(t,e,o){const n=t.anchor||t.lifecycle?.anchor||"fixed";if("latest"===n){if(null!=t.pointId&&o.pointNodes&&o.pointNodes.length>0)for(let n=o.pointNodes.length-1;n>=0;n--){const i=o.pointNodes[n];if(i.pointId===t.pointId)return Er(e,o,{x:i.x,y:i.y})}const n=function(t){const e=t.data;if(!e||0===e.length)return null;const o=e[e.length-1],n=t.scales?.x??t.scales?.time,i=t.scales?.y??t.scales?.value;if(!n||!i)return null;const r=o[t.xAccessor||"x"],s=o[t.yAccessor||"y"];return null==r||null==s?null:{x:n(r),y:i(s)}}(o);return n?Er(e,o,n):null}if("semantic"===n){const n=function(t,e,o){const n=function(t){return Fr(t.provenance?.stableId??t.stableId)}(t);if(!n)return null;const i=o.pointNodes?.find(t=>Fr(t.pointId)===n);if(i)return Er(e,o,{x:i.x,y:i.y});const r=o.data?.find(t=>function(t){return Fr(t.stableId??t.id??t.provenance?.stableId)}(t)===n);if(!r)return null;const s=zr(r,o),a=Dr(r,o);return null==s||null==a?null:Er(e,o,{x:s,y:a})}(t,e,o);if(n)return n}let i=null,r=null;if(null!=t.pointId&&o.pointNodes){const e=o.pointNodes.find(e=>e.pointId===t.pointId);e&&(i=e.x,r=e.y)}if(null!=i&&null!=r||(i=zr(t,o),r=Dr(t,o)),null!=i&&null!=r)return Er(e,o,{x:i,y:r});if("sticky"===n){const t=o.stickyPositionCache?.get(e);if(t)return t}return null}function Br(t,e,o,n=50){return!(-n>t||t>(o.width||0)+n||-n>e||e>(o.height||0)+n)}import{jsx as Nr}from"react/jsx-runtime";var Wr={secondary:0,primary:3};function jr(t){return!0===t?._annotationDeferred}function Yr(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function Gr(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function Hr(t){return Math.max(.72,.95-.06*t)}import{jsx as qr,jsxs as Vr}from"react/jsx-runtime";var Xr="var(--semiotic-bg, #ffffff)";function Ur(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=t,h=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),f=t=>qr("text",{x:e,y:o,textAnchor:l,dominantBaseline:c,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}:{},children:n});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??Xr,strokeWidth:h.haloWidth??3});const p=h.padding??{x:6,y:3},y="number"==typeof p?p:p.x,g="number"==typeof p?p:p.y,m=function(t,e){return(t+"").length*e*.6}(n,r),b=r+2*g;let x,v;return x="middle"===l?e-m/2-y:"end"===l?e-m-y:e-y,v="middle"===c||"central"===c?o-b/2:"hanging"===c||"text-before-edge"===c?o-g:o-.8*r-g,Vr("g",{className:d,children:[qr("rect",{x:x,y:v,width:m+2*y,height:b,rx:h.radius??3,ry:h.radius??3,fill:h.fill??Xr,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}import{jsx as Kr,jsxs as Zr}from"react/jsx-runtime";var Qr={linear:Sr,monotoneX:Ar,monotoneY:Mr,step:_r,stepAfter:Pr,stepBefore:Cr,basis:Rr,cardinal:Lr,catmullRom:Ir};function Jr(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})}),function(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:Gr(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>jr(t.annotation)),i=t.some(t=>null!=Yr(t.annotation)),r=t.some(t=>"layer"===Yr(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=Wr[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=jr(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=Nr("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:Hr(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=Yr(e.annotation);return a&&(s=Nr("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=Nr("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(Nr("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(Nr("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}(i)}var ts=32,es=6,os=4,ns=8,is=72;var rs={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function ss(t){if(!as(t))return t;const e=("string"==typeof t.mobileText?t.mobileText:void 0)??("string"==typeof t.shortText?t.shortText:void 0);return!e||"string"!=typeof t.label&&null!=t.label?t:{...t,label:e}}function as(t){return c(t)}function ls(t,e){if(!t)return[];const o=Math.max(1,Math.floor(e/7)),n=t.split(/\s+/).filter(Boolean),i=[];let r="";for(const t of n)r&&r.length+t.length+1>o?(i.push(r),r=t):r=r?`${r} ${t}`:t;return r&&i.push(r),i}function cs(t,e,o,n,i){const r=t+o,s=e+n;return Math.abs(o)>Math.abs(n)?{x:0>o?r-i.width-4:r+4,y:0>n?s-i.height:s,width:i.width,height:i.height}:{x:0>o?r-i.width:r,y:0>n?s-i.height-4:s+4,width:i.width,height:i.height}}function us(t,e){return{x:t.x-e,y:t.y-e,width:t.width+2*e,height:t.height+2*e}}function ds(t,e){return Math.max(0,Math.min(t.x+t.width,e.x+e.width)-Math.max(t.x,e.x))*Math.max(0,Math.min(t.y+t.height,e.y+e.height)-Math.max(t.y,e.y))}function hs(t,e,o,n,i,r,s,a){const l=us(t,s);let c=.4*Math.hypot(e.dx,e.dy)+80*function(t,e,o,n){const i=Math.max(0,n-t.x),r=Math.max(0,n-t.y);return(i+Math.max(0,t.x+t.width-(e-n)))*t.height+(r+Math.max(0,t.y+t.height-(o-n)))*t.width}(l,i,r,a);for(const t of o)c+=12*ds(l,t);for(const t of n)c+=4*ds(l,t);return c}function fs(t){const{annotations:e,context:i,defaultOffset:r=ts,notePadding:s=es,markPadding:a=os,edgePadding:l=ns,preserveManualOffsets:c=!0,routeLongConnectors:u=!0,connectorThreshold:d=is,density:h,progressiveDisclosure:f=!1,redundantCues:p=!1,responsive:y,mobile:g,cohesion:m,audience:b}=t,x=i.width||0,v=i.height||0,w="object"==typeof g?g:{},k=w.breakpoint??480,S=!!g&&k>=x,A=S&&!1!==w.preferShortText?e.map(ss):e,M=S&&!h?{maxAnnotations:w.maxAnnotations??("callout-list"===w.strategy?1:2),minVisible:w.minVisible??1}:h,_=f||S&&(!1!==w.progressiveDisclosure||"callout-list"===w.strategy),P=S&&!y?w.responsive??{minWidth:k}:y,C=S&&!m?w.cohesion:m;if(0===A.length||0>=x||0>=v)return A.slice();const R=[],L=function(t,e){return(t.pointNodes||[]).map(t=>{const o=Math.max(1,t.r||1)+e;return{x:t.x-o,y:t.y-o,width:2*o,height:2*o}})}(i,a);let I=!1;const T=A.map((t,e)=>{if(!as(t))return t;const o=function(t,e,o){if("widget"===t.type&&"number"==typeof t.px&&"number"==typeof t.py)return{x:t.px,y:t.py};const n=t.pointId??t.nodeId;if(null!=n&&o.pointNodes){const t=o.pointNodes.find(t=>t.pointId===n);if(t)return{x:t.x,y:t.y}}const i=t.coordinates,r=o.scales?.geoProjection;if(Array.isArray(i)&&i.length>=2&&r){const t=i[0],e=i[1];if("number"==typeof t&&"number"==typeof e){const o=r([t,e]);if(o&&"number"==typeof o[0]&&"number"==typeof o[1])return{x:o[0],y:o[1]}}}return o.scales||"number"!=typeof t.x||"number"!=typeof t.y?Or(t,e,o):{x:t.x,y:t.y}}(t,e,i);if(!o)return t;const n=function(t){if("widget"===t.type)return{width:"number"==typeof t.width?t.width:32,height:"number"==typeof t.height?t.height:32};const e="number"==typeof t.wrap?t.wrap:120,o=[...ls("string"==typeof t.title?t.title:void 0,e),...ls("string"==typeof t.label?t.label:void 0,e)],n=o.reduce((t,e)=>Math.max(t,e.length),0);return{width:Math.max(24,Math.min(e,7*n)+10),height:Math.max(18,16*o.length+6)}}(t);if(c&&("number"==typeof(a=t).dx||"number"==typeof a.dy)){const e=function(t){return"text"===t.type||"widget"===t.type?{dx:0,dy:0}:{dx:30,dy:-30}}(t);return R.push(us(cs(o.x,o.y,"number"==typeof t.dx?t.dx:e.dx,"number"==typeof t.dy?t.dy:e.dy,n),s)),t}var a;let h=null,f=1/0;for(const t of function(t){const e=1.6*t;return[{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t},{dx:t,dy:0},{dx:-t,dy:0},{dx:0,dy:-t},{dx:0,dy:t},{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e}]}(r)){const e=hs(cs(o.x,o.y,t.dx,t.dy,n),t,R,L,x,v,s,l);f>e&&(h=t,f=e)}if(!h)return t;const p=us(cs(o.x,o.y,h.dx,h.dy,n),s);R.push(p);const y=Math.hypot(h.dx,h.dy),g=u&&y>=d&&"text"!==t.type&&"widget"!==t.type?{...t.connector||{end:"arrow"},type:"curve"}:t.connector;return I=!0,{...t,dx:h.dx,dy:h.dy,...g?{connector:g}:{}}}),$=I?T:A.slice();let z=$;if(p){let t=!1;const e=$.map(e=>{const o=function(t){return"text"!==t.type||"string"!=typeof t.color||8>Math.hypot("number"==typeof t.dx?t.dx:0,"number"==typeof t.dy?t.dy:0)?t:{...t,_redundantConnector:!0}}(e);return o!==e&&(t=!0),o});z=t?e:$}{let t=!1;const e=z.map(e=>{if(!0!==e?.defensive)return e;const o=function(t){const e=t?.provenance;if(!e||"object"!=typeof e)return t;const o="string"==typeof e.source?rs[e.source]??e.source:null,n="number"==typeof e.confidence&&Number.isFinite(e.confidence)?Math.round(100*Math.max(0,Math.min(1,e.confidence)))+"%":null;if(!o&&!n)return t;if(null!=t.label&&"string"!=typeof t.label)return t;const i=[o,n].filter(Boolean).join(" · "),r="string"==typeof t.label?t.label:"";return r.includes(`(${i})`)?t:{...t,label:r?`${r} (${i})`:`(${i})`}}(e);return o!==e&&(t=!0),o});z=t?e:z}const D=new Set;if(M){const t="object"==typeof M?M:{},e=function(t){if(!t)return 1;const e=function(t){const e=t?.familiarity;if(!e)return 3;const o=Object.values(e).filter(t=>"number"==typeof t&&Number.isFinite(t));return 0===o.length?3:o.reduce((t,e)=>t+e,0)/o.length}(t);return e>2?4>e?1:.6:1.5}(b),i=1===e?t:{...t,maxAnnotations:Math.max(0,Math.round((t.maxAnnotations??o(x,v,t))*e))},{deferred:r}=n({annotations:z,width:x,height:v,...i});for(const t of r)D.add(t)}if(P&&("object"==typeof P&&"number"==typeof P.minWidth?P.minWidth:480)>=x)for(const t of z)as(t)&&"secondary"===t.emphasis&&D.add(t);if(D.size>0)for(const t of z)!0===t?.defensive&&D.delete(t);let F;return F=0===D.size?z:_?z.map(t=>D.has(t)?{...t,_annotationDeferred:!0}:t):z.filter(t=>!D.has(t)),C?function(t,e){let o=!1;const n=t.map(t=>as(t)?"blended"===t.cohesion||"layer"===t.cohesion?t:(o=!0,{...t,cohesion:e}):t);return o?n:t}(F,C):F}import{useSyncExternalStore as ps}from"react";var ys={positions:new Map},gs=new Set;function ms(){for(const t of gs)t()}function bs(t,e){const o=ys.positions.get(t);if(o?.locked)return;if(!o||o.sourceId!==e)return;const n=new Map(ys.positions);n.delete(t),ys={positions:n},ms()}function xs(t,e){const o=ys.positions.get(t);if(!o?.locked)return;if(e&&o.sourceId!==e)return;const n=new Map(ys.positions);n.delete(t),ys={positions:n},ms()}function vs(){return ys}function ws(t){return gs.add(t),()=>gs.delete(t)}var ks={positions:new Map};function Ss(){return()=>{}}function As(){return ks}function Ms(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)}function _s(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function Ps(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function Cs(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 Rs(t){if(t)return"dashed"===t?"6,4":"dotted"===t?"2,4":t}function Ls(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 Is(t){return"string"==typeof t&&t.length>0}function Ts(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function $s(t,e){return Ts(t,Is(e))}import{Fragment as zs,jsx as Ds,jsxs as Fs}from"react/jsx-runtime";function Es(t){const{width:e,height:o,totalWidth:n,totalHeight:i,margin:r,scales:s,showAxes:a,axes:l,showGrid:c,xFormat:u,yFormat:d,axisExtent:h}=t,f=Ti(()=>{if(!s)return[];const t=l?.find(t=>"bottom"===t.orient),o=t?.tickFormat||u||Os,n=Math.max(2,Math.floor(e/70)),i=t?.ticks??5,r="exact"===h?Math.max(2,i):Math.min(i,n),a=t?.tickValues??Ms(s.x,r,h),c=a.map(t=>t.valueOf()),d=a.map((t,e)=>({value:t,pixel:s.x(t),label:o(t,e,c)})),f=d.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:"number"==typeof e.label?6.5*(e.label+"").length:60),0);return Bs(d,Math.max(55,f+8))},[s,l,u,e,h]),p=Ti(()=>{if(!s)return[];const t=l?.find(t=>"left"===t.orient),e=t?.tickFormat||d||Os,n=Math.max(2,Math.floor(o/30)),i=t?.ticks??5,r="exact"===h?Math.max(2,i):Math.min(i,n);return Bs((t?.tickValues??Ms(s.y,r,h)).map(t=>({value:t,pixel:s.y(t),label:e(t)})),22)},[s,l,d,o,h]),y=c&&s,g=a&&s;if(!y&&!g)return null;const m=l?.find(t=>"bottom"===t.orient),b=l?.find(t=>"left"===t.orient),x=g&&(!m||!1!==m.baseline),v=g&&(!b||!1!==b.baseline),w=m?.jaggedBase||!1,k=b?.jaggedBase||!1,S="var(--semiotic-border, #ccc)";return Ds("svg",{width:n,height:i,style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:Fs("g",{transform:`translate(${r.left},${r.top})`,children:[y&&(()=>{const t=Rs(l?.find(t=>"bottom"===t.orient)?.gridStyle),n=Rs(l?.find(t=>"left"===t.orient)?.gridStyle);return Fs("g",{className:"stream-grid",children:[f.map((e,n)=>Ds("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:o,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:t},"xgrid-"+n)),p.map((t,o)=>Ds("line",{x1:0,y1:t.pixel,x2:e,y2:t.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:n},"ygrid-"+o))]})})(),x&&!w&&Ds("line",{x1:0,y1:o,x2:e,y2:o,stroke:S,strokeWidth:1}),w&&Ds("path",{d:Ls("bottom",e,o),fill:"none",stroke:S,strokeWidth:1}),v&&!k&&Ds("line",{x1:0,y1:0,x2:0,y2:o,stroke:S,strokeWidth:1}),k&&Ds("path",{d:Ls("left",e,o),fill:"none",stroke:S,strokeWidth:1})]})})}function Os(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function Bs(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}function Ns(t){const{width:o,height:n,totalWidth:i,totalHeight:r,margin:s,scales:l,showAxes:c,axes:u,xLabel:d,yLabel:h,yLabelRight:f,xFormat:p,yFormat:y,axisExtent:m,showGrid:b,title:x,legend:v,legendHoverBehavior:w,legendClickBehavior:k,legendHighlightedCategory:S,legendIsolatedCategories:A,legendPosition:M="right",legendLayout:_,foregroundGraphics:P,marginalGraphics:C,xValues:R,yValues:L,annotations:I,onAnnotationActivate:T,onObservation:$,chartId:z,chartType:D,autoPlaceAnnotations:F,svgAnnotationRules:E,xAccessor:O,yAccessor:B,annotationData:N,pointNodes:W,curve:j,underlayRendered:Y,canvasObscuresUnderlay:G=!0,linkedCrosshairName:H,linkedCrosshairSourceId:q,children:V}=t,X=g({onAnnotationActivate:T,onObservation:$,chartId:z,chartType:D}),U=ji(_),K=v&&"left"===M&&U>0?U:s.left,Z=v&&"right"===M&&U>0?U:s.right,Q=Ti(()=>{if(!c||!l)return[];const t=u?.find(t=>"bottom"===t.orient),e=t?.tickFormat||p||Os,n=Math.max(2,Math.floor(o/70)),i=t?.ticks??5,r="exact"===m?Math.max(2,i):Math.min(i,n),s=t?.tickValues??Ms(l.x,r,m),a=s.map(t=>t.valueOf()),d=s.map((t,o)=>({value:t,pixel:l.x(t),label:e(t,o,a)})),h=d.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:"number"==typeof e.label?6.5*(e.label+"").length:60),0),f=t?.autoRotate?Math.max(20,Math.min(h+8,55)):Math.max(55,h+8);let y=Bs(d,f);if(y.length>1&&(y=y.filter((t,e)=>0===e||t.label+""!=y[e-1].label+"")),t?.includeMax&&y.length>0&&"exact"!==m&&!t?.tickValues){const t=l.x.domain()[1],o=l.x(t),n=y[y.length-1].pixel;if(Math.abs(o-n)>1){const i=e(t,y.length,a);f>o-n&&y.length>1&&(y=y.slice(0,-1)),y.push({value:t,pixel:o,label:i})}}return y},[c,l,u,p,o,m]),J=Ti(()=>{const t=u?.find(t=>"bottom"===t.orient);if(!t?.autoRotate||1>=Q.length)return!1;const e=o/Math.max(Q.length-1,1);return Q.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8>e},[u,Q,o]),tt=Ti(()=>{if(!c||!l)return[];const t=u?.find(t=>"left"===t.orient),e=t?.tickFormat||y||Os,o=Math.max(2,Math.floor(n/30)),i=t?.ticks??5,r="exact"===m?Math.max(2,i):Math.min(i,o);let s=Bs((t?.tickValues??Ms(l.y,r,m)).map(t=>({value:t,pixel:l.y(t),label:e(t)})),22);if(s.length>1&&(s=s.filter((t,e)=>0===e||t.label+""!=s[e-1].label+"")),t?.includeMax&&s.length>0&&"exact"!==m&&!t?.tickValues){const t=l.y.domain()[1],o=l.y(t),n=s[s.length-1].pixel;if(Math.abs(o-n)>1){const i=e(t);22>Math.abs(o-n)&&s.length>1&&(s=s.slice(0,-1)),s.push({value:t,pixel:o,label:i})}}return s},[c,l,u,y,n,m]),et=Ti(()=>{if(!c||!l)return[];const t=u?.find(t=>"right"===t.orient);if(!t)return[];const e=t.tickFormat||y||Os,o=Math.max(2,Math.floor(n/30)),i=t.ticks??5;return Bs((t.tickValues??Ms(l.y,"exact"===m?Math.max(2,i):Math.min(i,o),m)).map(t=>({value:t,pixel:l.y(t),label:e(t)})),22)},[c,l,u,y,n,m]),ot=$i(new Map),nt=$i(I?.length??0),it=I?.length??0;nt.current!==it&&(nt.current=it,ot.current=new Map);const rt=Ti(()=>{if(!I||0===I.length)return null;const t=a(I),i=function(t,o={}){return function(t,n,i){switch(t.type){case"label":case"callout":case"callout-circle":case"callout-rect":{const e=Or(t,n,i);if(!e)return null;const{x:o,y:r}=e;if(!Br(o,r,i))return null;const s="callout"===t.type?"callout-circle":t.type,a="callout-circle"===s?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===s?{width:t.width,height:t.height}:void 0;return Kr(vr,{noteData:{x:o,y:r,dx:t.dx??30,dy:t.dy??-30,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:s,...a?{subject:a}:{},connector:t.connector||{end:"arrow"},color:t.color,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-"+n)}case"x-threshold":{const e=zr(null!=t.value?{...t,x:t.value}:t,i);if(null==e)return null;const o=t.color||"#f97316",r=t.labelPosition||"top";let s;s="bottom"===r?(i.height||0)-4:"center"===r?(i.height||0)/2:16;const a=e>.6*(i.width||0),l=a?e-4:e+4,c=a?"end":"start";return Zr("g",{opacity:t.opacity,children:[Kr("line",{x1:e,y1:0,x2:e,y2:i.height||0,stroke:o,strokeWidth:t.strokeWidth||1.5,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Kr(Ur,{x:l,y:s,text:t.label,textAnchor:c,fill:o,fontSize:12,fontWeight:"bold",background:t.labelBackground??"halo"})]},"ann-"+n)}case"y-threshold":{const e=Dr(null!=t.value?{...t,y:t.value}:t,i);if(null==e)return null;const o=t.color||"#f97316",r=t.labelPosition||"right";let s,l;"left"===r?(s=4,l="start"):"center"===r?(s=(i.width||0)/2,l="middle"):(s=(i.width||0)-4,l="end");const c=20>(a=e)?Math.min((i.height||0)-4,a+16):a-4;return Zr("g",{opacity:t.opacity,children:[Kr("line",{x1:0,y1:e,x2:i.width||0,y2:e,stroke:o,strokeWidth:t.strokeWidth||1.5,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Kr(Ur,{x:s,y:c,text:t.label,textAnchor:l,fill:o,fontSize:12,fontWeight:"bold",background:t.labelBackground??"halo"})]},"ann-"+n)}case"enclose":{const e=(t.coordinates||[]).map(t=>({x:zr({...t,type:"point"},i),y:Dr({...t,type:"point"},i),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>e.length)return null;const o=wr(e),r=t.padding||10;return Zr("g",{children:[Kr("circle",{cx:o.x,cy:o.y,r:o.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&&Kr(Ur,{x:o.x,y:o.y-o.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+n)}case"rect-enclose":{const e=(t.coordinates||[]).map(t=>({x:zr({...t,type:"point"},i),y:Dr({...t,type:"point"},i)})).filter(t=>null!=t.x&&null!=t.y);if(2>e.length)return null;const o=t.padding||10,r=e.map(t=>t.x),s=e.map(t=>t.y),[a,l]=St(r),[c,u]=St(s),d=a-o,h=l+o,f=c-o;return Zr("g",{children:[Kr("rect",{x:d,y:f,width:h-d,height:u+o-f,fill:t.fill||"none",fillOpacity:t.fillOpacity||.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Kr(Ur,{x:(d+h)/2,y:f-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+n)}case"highlight":{const e=i.data||[],o="function"==typeof t.filter?e.filter(t.filter):t.field&&null!=t.value?e.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return Kr("g",{children:o.map((e,o)=>{const n=zr(e,i),s=Dr(e,i);if(null==n||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 Kr("circle",{cx:n,cy:s,r:a,...l},"hl-"+o)})},"ann-"+n)}case"bracket":{const e=zr(t,i),o=Dr(t,i);return Kr(vr,{noteData:{x:e??0,y:o??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-"+n)}case"trend":{const e=i.data||[];if(2>e.length)return null;const o=i.xAccessor||"x",r=i.yAccessor||"y",s="ordinal"===i.frameType,a="horizontal"===i.projection,l=s?o:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const t of e){const e=t[l];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=e.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=e.map(t=>[t[o],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const f=i.scales?.x??i.scales?.time,p=i.scales?.y??i.scales?.value;if(!f||!p)return null;const y=t=>e=>{const o=Math.max(0,Math.floor(e)),n=Math.min(d.length-1,o+1),i=e-o,r=t(d[o]);return r+(t(d[n])-r)*i},g=f,m=p;let b;if(s)if(a){const t=y(m);b=(e,o)=>[g(o),t(e)]}else{const t=y(g);b=(e,o)=>[t(e),m(o)]}else b=(t,e)=>[g(t),m(e)];const x=t.method||"linear";let v;if("loess"===x)v=function(t,e=.3){const o=t.length;if(2>o)return t.slice();const n=t.slice().sort((t,e)=>t[0]-e[0]),i=n.map(t=>t[0]),r=n.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=i[t],n=i.map(t=>Math.abs(t-e)),l=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,c=[];for(let t=0;o>t;t++){const e=0===l?0:n[t]/l;c[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,f=0,p=0;for(let t=0;o>t;t++){const e=c[t];0!==e&&(u+=e,d+=e*i[t],h+=e*r[t],f+=e*i[t]*i[t],p+=e*i[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const y=u*f-d*d;if(1e-12>Math.abs(y))a.push([e,h/u]);else{const t=(u*p-d*h)/y;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3);else{const e="polynomial"===x?$r(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:Tr((o*e[3]-e[0]*e[1])/n),r=Tr(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[Tr(t),Tr(i*t+r)]),equation:[i,r]}}(u);v=e.points}const w=v.map(([t,e])=>{const[o,n]=b(t,e);return`${o},${n}`}).join(" "),k=t.color||"#6366f1",S=v[v.length-1],[A,M]=b(S[0],S[1]);return Zr("g",{children:[Kr("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth||2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Kr("text",{x:A+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+n)}case"band":{const e=i.scales?.y??i.scales?.value,o=e?.domain?.(),a=t.y0??o?.[0],l=t.y1??o?.[1],c=null!=a&&e?e(a):0,u=null!=l&&e?e(l):i.height||0,d=Un(t.fill,"ann-"+n,"var(--semiotic-primary, #6366f1)");return Zr("g",{opacity:t.opacity,children:[d.def&&Kr("defs",{children:d.def}),Kr("rect",{x:0,y:Math.min(c,u),width:i.width||0,height:Math.abs(u-c),fill:d.fill,fillOpacity:t.fillOpacity||.1}),t.label&&Kr(Ur,{x:(i.width||0)-4,y:(r=c,s=u,Math.max(Math.min(r,s),0)+16),textAnchor:"end",fill:t.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:t.label,background:t.labelBackground??"halo"})]},"ann-"+n)}case"x-band":{const e=i.scales?.x??i.scales?.time,o=e?.domain?.(),r=t.x0??o?.[0],s=t.x1??o?.[1],a=null!=r&&e?e(r):null,l=null!=s&&e?e(s):null;if(null==a||null==l)return null;const c=Un(t.fill||t.color,"ann-"+n,"var(--semiotic-primary, #6366f1)");return Zr("g",{opacity:t.opacity,children:[c.def&&Kr("defs",{children:c.def}),Kr("rect",{x:Math.min(a,l),y:0,width:Math.abs(l-a),height:i.height||0,fill:c.fill,fillOpacity:t.fillOpacity??.1}),t.label&&Kr(Ur,{x:Math.min(a,l)+4,y:16,textAnchor:"start",fill:t.color||"var(--semiotic-primary, #6366f1)",fontSize:11,fontWeight:"bold",text:t.label,background:t.labelBackground??"halo"})]},"ann-"+n)}case"envelope":{const e=i.data||[];if(2>e.length)return null;const o=i.xAccessor||"x",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",l=t.lowerAccessor||"lowerBounds",c=t.filter,u=e.filter(t=>null!=t[a]&&null!=t[l]&&!(c&&!c(t))).sort((t,e)=>t[o]-e[o]);if(2>u.length)return null;const d=Qr[i.curve||"linear"]||Sr,h=kr().x(t=>r(t[o])).y0(t=>s(t[l])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const f=t.fill||"#6366f1";return Zr("g",{children:[Kr("path",{d:h,fill:f,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&u.length>0&&Kr("text",{x:r(u[u.length-1][o])+4,y:s(u[u.length-1][a])-4,fill:f,fontSize:11,children:t.label})]},"ann-"+n)}case"anomaly-band":{const e=i.data||[];if(2>e.length)return null;const o=i.yAccessor||"y",r=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!r||!s)return null;const a=e.map(t=>t[o]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const l=a.reduce((t,e)=>t+e,0)/a.length,c=a.reduce((t,e)=>t+(e-l)**2,0)/a.length,u=Math.sqrt(c),d=t.threshold??2,h=l-d*u,f=!1!==t.showBand,p=t.fill||"#6366f1",y=t.fillOpacity??.1,g=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,b=s(l+d*u),x=s(h),v=e.filter(t=>{const e=t[o];return null!=e&&Math.abs(e-l)>d*u});return Zr("g",{children:[f&&Kr("rect",{x:0,y:Math.min(b,x),width:i.width||0,height:Math.abs(x-b),fill:p,fillOpacity:y}),v.map((t,e)=>{const o=zr(t,i),n=Dr(t,i);return null==o||null==n?null:Kr("circle",{cx:o,cy:n,r:m,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Kr("text",{x:(i.width||0)-4,y:Math.min(b,x)-4,textAnchor:"end",fill:p,fontSize:11,children:t.label})]},"ann-"+n)}case"forecast":{const e=i.data||[];if(3>e.length)return null;const o=i.xAccessor||"x",r=i.yAccessor||"y",s=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!s||!a)return null;const l=e.map(t=>[t[o],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||"linear")){const e=$r(l,t.order||2).equation;c=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=l.length;let e=0,o=0,n=0,i=0;for(const[t,r]of l)e+=t,o+=r,n+=t*t,i+=t*r;const r=t*n-e*e;if(1e-12>Math.abs(r))return null;const s=(t*i-e*o)/r,a=(o-s*e)/t;c=t=>a+s*t}const u=l.length,d=l.map(([t,e])=>e-c(t)),h=d.reduce((t,e)=>t+e*e,0),f=Math.sqrt(h/Math.max(u-2,1)),p=l.reduce((t,e)=>t+e[0],0)/u,y=l.reduce((t,e)=>t+(e[0]-p)**2,0),g=t.confidence??.95,m=.99>g?.95>g?.9>g?1:1.645:1.96:2.576,b=t.steps??5,x=l[u-1][0],v=(x-l[0][0])/Math.max(u-1,1),w=[];for(let t=1;b>=t;t++)w.push(x+t*v);const k=[];for(const t of w){const e=c(t),o=f*Math.sqrt(1+1/u+(y>0?(t-p)**2/y:0))*m;k.push({x:t,yCenter:e,yUpper:e+o,yLower:e-o})}const S=`M${k.map(t=>`${s(t.x)},${a(t.yUpper)}`).join(" L")} L${k.slice().reverse().map(t=>`${s(t.x)},${a(t.yLower)}`).join(" L")} Z`,A=k.map(t=>`${s(t.x)},${a(t.yCenter)}`).join(" "),M=`${s(x)},${a(c(x))}`,_=t.strokeColor||"#6366f1";return Zr("g",{children:[Kr("path",{d:S,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Kr("polyline",{points:`${M} ${A}`,fill:"none",stroke:_,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k.length>0&&Kr("text",{x:s(k[k.length-1].x)+4,y:a(k[k.length-1].yCenter)-4,fill:_,fontSize:11,children:t.label})]},"ann-"+n)}case"widget":{let r,s;if(null!=t.px&&null!=t.py)r=t.px,s=t.py;else{const e=Or(t,n,i);if(!e)return null;r=e.x,s=e.y}if(!Br(r,s,i))return null;const a=t.dx??0,l=t.dy??0,c=t.width??32,u=t.height??32,d=t.content??Kr("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Kr("foreignObject",{x:r+a-c/2,y:s+l-u/2,width:c,height:u,style:{overflow:"visible",pointerEvents:"auto"},children:Kr("div",{...e(t,o),style:{width:c,height:u,display:"flex",alignItems:"center",justifyContent:"center"},children:d})},"ann-"+n)}case"text":{const e=Or(t,n,i);if(!e)return null;const{x:o,y:r}=e,s=o+(t.dx||0),a=r+(t.dy||0),l=t.color||"var(--semiotic-text, #333)",c=Kr("text",{x:s,y:a,fill:l,fontSize:t.fontSize||11,opacity:t.opacity,strokeDasharray:t.strokeDasharray,dominantBaseline:"middle",style:{fontFamily:"inherit"},children:t.label});return!0!==t._redundantConnector?dr.cloneElement(c,{key:"ann-text-"+n}):Zr("g",{opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:[Kr("line",{x1:o,y1:r,x2:s,y2:a,stroke:l,strokeWidth:1,strokeOpacity:.5,style:{pointerEvents:"none"}}),dr.cloneElement(c,{opacity:void 0,strokeDasharray:void 0})]},"ann-text-"+n)}case"category-highlight":{const e=t.category;if(null==e)return null;const o=t=>"function"==typeof t&&"function"==typeof t.bandwidth,r=i.scales?.o,s=i.scales?.x,a=i.scales?.y,l=o(r)?r:o(s)?s:o(a)?a:null;if(!l)return null;const c=l(e+"");if(null==c)return null;const u=l.bandwidth(),d=t.color||"var(--semiotic-primary, #4589ff)",h=t.opacity??.15,f=t.label;return Zr("g",(i.projection?"vertical"===i.projection:l===s)?{children:[Kr("rect",{x:c,y:0,width:u,height:i.height||0,fill:d,fillOpacity:h}),f&&Kr(Ur,{x:c+u/2,y:16,textAnchor:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:t.labelBackground??"none"})]}:{children:[Kr("rect",{x:0,y:c,width:i.width||0,height:u,fill:d,fillOpacity:h}),f&&Kr(Ur,{x:12,y:c+u/2,dominantBaseline:"middle",fill:d,fontSize:12,fontWeight:"bold",text:f,background:t.labelBackground??"none"})]},"ann-"+n)}default:return null}var r,s,a}}(0,X),r={scales:l?{x:l.x,y:l.y,time:l.x,value:l.y}:null,timeAxis:"x",xAccessor:O,yAccessor:B,width:o,height:n,data:N,frameType:"xy",pointNodes:W,curve:j,stickyPositionCache:ot.current};return Jr(F?fs({annotations:t,context:r,..."object"==typeof F?F:{}}):t,i,E,r)},[I,F,E,o,n,O,B,N,l,W,j,X]),st=function(t){const e=ps(t?ws:Ss,t?vs:As,t?vs:As);return t?e.positions.get(t)??null:null}(H);return zi(()=>{if(!st?.locked||!H)return;const t=t=>{"Escape"===t.key&&xs(H)};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[st?.locked,H]),c||x||v||P||C||rt&&rt.length>0||b||V||st?Fs("svg",{role:"img",width:i,height:r,overflow:"visible",style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Ds("title",{children:"string"==typeof x?x:"XY Chart"}),Ds("desc",{children:"string"==typeof x?x+" (XY data visualization)":"XY data visualization"}),Fs("g",{transform:`translate(${s.left},${s.top})`,children:[b&&l&&(!Y||G)&&(()=>{const t=Rs(u?.find(t=>"bottom"===t.orient)?.gridStyle),e=Rs(u?.find(t=>"left"===t.orient)?.gridStyle);return Fs("g",{className:"stream-grid",children:[Q.map((e,o)=>Ds("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:n,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:t},"xgrid-"+o)),tt.map((t,n)=>Ds("line",{x1:0,y1:t.pixel,x2:o,y2:t.pixel,stroke:"var(--semiotic-grid, #e0e0e0)",strokeWidth:1,strokeDasharray:e},"ygrid-"+n))]})})(),c&&l&&(()=>{const t=u?.find(t=>"left"===t.orient),e=u?.find(t=>"bottom"===t.orient),i=!t||!1!==t.baseline,r=!e||!1!==e.baseline,s=t?.jaggedBase||!1,a=e?.jaggedBase||!1,l=e?.landmarkTicks,c=t?.landmarkTicks,p="var(--semiotic-border, #ccc)",y="var(--semiotic-text-secondary, var(--semiotic-text, #666))",g="var(--semiotic-text, #333)",m=J,b=m?12:18,x=n+(m?58:40),v={fontSize:"var(--semiotic-tick-font-size, 12px)"},w={fontSize:"calc(var(--semiotic-tick-font-size, 12px) + 1px)"},k={fontSize:"var(--semiotic-axis-label-font-size, 12px)"},S=e?.tickAnchor,A=t?.tickAnchor,M=Cs(Q),_=Cs(tt);return Fs("g",{className:"stream-axes",style:{fontFamily:"var(--semiotic-font-family, sans-serif)"},children:[Fs("g",{className:"semiotic-axis semiotic-axis-bottom","data-orient":"bottom",children:[(!Y||G)&&r&&!a&&Ds("line",{x1:0,y1:n,x2:o,y2:n,stroke:p,strokeWidth:1}),(!Y||G)&&a&&Ds("path",{d:Ls("bottom",o,n),fill:"none",stroke:p,strokeWidth:1}),Q.map((t,e)=>{const o=!!l&&("function"==typeof l?l(t.value,e):Mn(t.value,e>0?Q[e-1].value:void 0));return Fs("g",{transform:`translate(${t.pixel},${n})`,children:[Ds("line",{y2:5,stroke:p,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?Ds("text",{y:b,textAnchor:m?"end":_s(S,t.pixel===M.min,t.pixel===M.max),fontWeight:o?600:400,fill:y,className:"semiotic-axis-tick",style:{userSelect:"none",...o?w:v},transform:m?"rotate(-45)":void 0,children:t.label}):Ds("foreignObject",{x:-30,y:6,width:60,height:24,style:{overflow:"visible"},children:Ds("div",{style:{textAlign:"center",userSelect:"none",...v},children:t.label})})]},"xtick-"+e)}),d&&Ds("text",{x:o/2,y:x,textAnchor:"middle",fill:g,className:"semiotic-axis-label",style:{userSelect:"none",...k},children:d})]}),Fs("g",{className:"semiotic-axis semiotic-axis-left","data-orient":"left",children:[(!Y||G)&&i&&!s&&Ds("line",{x1:0,y1:0,x2:0,y2:n,stroke:p,strokeWidth:1}),(!Y||G)&&s&&Ds("path",{d:Ls("left",o,n),fill:"none",stroke:p,strokeWidth:1}),tt.map((t,e)=>{const o=!!c&&("function"==typeof c?c(t.value,e):Mn(t.value,e>0?tt[e-1].value:void 0));return Fs("g",{transform:`translate(0,${t.pixel})`,children:[Ds("line",{x2:-5,stroke:p,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?Ds("text",{x:-8,textAnchor:"end",dominantBaseline:Ps(A,t.pixel===_.min,t.pixel===_.max),fontWeight:o?600:400,fill:y,className:"semiotic-axis-tick",style:{userSelect:"none",...o?w:v},children:t.label}):Ds("foreignObject",{x:-68,y:-12,width:60,height:24,style:{overflow:"visible"},children:Ds("div",{style:{textAlign:"right",userSelect:"none",...v},children:t.label})})]},"ytick-"+e)}),(()=>{const e=t?.label||h;return e?Ds("text",{x:15-K,y:n/2,textAnchor:"middle",fill:g,transform:`rotate(-90, ${15-K}, ${n/2})`,className:"semiotic-axis-label",style:{userSelect:"none",...k},children:e}):null})()]}),(()=>{const t=u?.find(t=>"right"===t.orient);if(!t||0===et.length)return null;const e=!1!==t.baseline,i=t.landmarkTicks,r=t.label||f,s=t.tickAnchor,a=Cs(et);return Fs("g",{className:"semiotic-axis semiotic-axis-right","data-orient":"right",children:[e&&Ds("line",{x1:o,y1:0,x2:o,y2:n,stroke:p,strokeWidth:1}),et.map((t,e)=>{const n=!!i&&("function"==typeof i?i(t.value,e):Mn(t.value,e>0?et[e-1].value:void 0));return Fs("g",{transform:`translate(${o},${t.pixel})`,children:[Ds("line",{x2:5,stroke:p,strokeWidth:1}),"string"==typeof t.label||"number"==typeof t.label?Ds("text",{x:8,textAnchor:"start",dominantBaseline:Ps(s,t.pixel===a.min,t.pixel===a.max),fontWeight:n?600:400,fill:y,className:"semiotic-axis-tick",style:{userSelect:"none",...n?w:v},children:t.label}):Ds("foreignObject",{x:8,y:-12,width:60,height:24,style:{overflow:"visible"},children:Ds("div",{style:{textAlign:"left",userSelect:"none",...v},children:t.label})})]},"ytick-r-"+e)}),r&&Ds("text",{x:o+Z-15,y:n/2,textAnchor:"middle",fill:g,transform:`rotate(90, ${o+Z-15}, ${n/2})`,className:"semiotic-axis-label",style:{userSelect:"none",...k},children:r})]})})()]})})(),rt,C&&l&&R&&L&&Fs(zs,{children:[C.top&&Ds("g",{transform:"translate(0, 0)",children:Ds(ur,{orient:"top",config:cr(C.top),values:R,scale:l.x,size:s.top,length:o})}),C.bottom&&Ds("g",{transform:`translate(0, ${n})`,children:Ds(ur,{orient:"bottom",config:cr(C.bottom),values:R,scale:l.x,size:s.bottom,length:o})}),C.left&&Ds("g",{transform:"translate(0, 0)",children:Ds(ur,{orient:"left",config:cr(C.left),values:L,scale:l.y,size:s.left,length:n})}),C.right&&Ds("g",{transform:`translate(${o}, 0)`,children:Ds(ur,{orient:"right",config:cr(C.right),values:L,scale:l.y,size:s.right,length:n})})]}),P,st&&st.sourceId!==q&&l?.x&&(()=>{const t=l.x(st.xValue);if(null==t||0>t||t>o)return null;const e=st.locked;return Ds("line",{x1:t,y1:0,x2:t,y2:n,stroke:e?"white":"var(--semiotic-text-secondary, rgba(0,0,0,0.25))",strokeWidth:e?1.5:1,strokeDasharray:e?"6,3":"4,4",pointerEvents:"none"})})(),V]}),x&&"string"==typeof x?Ds("text",{x:i/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)"},children:x}):x?Ds("foreignObject",{x:0,y:0,width:i,height:s.top,children:x}):null,ir({legend:v,totalWidth:i,totalHeight:r,margin:s,legendPosition:M,title:x,legendLayout:_,axisChrome:{hasAxis:!!c,hasAxisLabel:!!d,rotatedTicks:J},legendHoverBehavior:w,legendClickBehavior:k,legendHighlightedCategory:S,legendIsolatedCategories:A})]}):null}import*as Ws from"react";import{area as js,line as Ys}from"d3-shape";function Gs(t,e,o){let n=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(n=o.color):t>o.value&&(n=o.color);return n}function Hs(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(Gs(u+d*((e+i)/2),o,n),[s+(l-s)*e,a+(c-a)*e],[s+(l-s)*i,a+(c-a)*i])}}return i}function qs(t){return(t.tl??0)>0||(t.tr??0)>0||(t.br??0)>0||(t.bl??0)>0}function Vs(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)}}import{jsx as Xs,jsxs as Us}from"react/jsx-runtime";var Ks={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function Zs(t,e="#4e79a7"){return Hn(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function Qs(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function Js(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=Cn(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=Tn(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),c=l?Qs(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:Rn(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:Rn(o.stroke??"none",a,t.accent);return i||r?Xs("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 Us("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&Xs("clipPath",{id:c,children:Xs("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&t.ghostColor?Xs("g",{children:d(t.ghostColor)}):null,l&&c?Xs("g",{clipPath:`url(#${c})`,children:d()}):d()]},n)}function ta(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)=>Xs("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function ea(t,e,o){const n=uo(t.symbolType,t.size,t.path);return Xs("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?Zs(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 oa from"react";import{arc as na}from"d3-shape";import{jsx as ia,jsxs as ra}from"react/jsx-runtime";import*as sa from"react";import{jsx as aa,jsxs as la}from"react/jsx-runtime";import*as ca from"react";import{arc as ua}from"d3-shape";var da=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function ha(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=da(o,n),e=da(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=da(o,n),s=da(o,i),a=da(e,i),l=da(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 ha({...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 ha({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const f=n+(d?a:0),p=i-(h?a:0),y=n+(d?l:0),g=i-(h?l:0),m=da(o,f),b=da(o,p),x=(o-s)*Math.cos(a),v=da(x,n),w=da(x,i),k=r?null:da(e,g),S=r?null:da(e,y),A=r?0:(e+s)*Math.cos(l),M=r?null:da(A,n),_=r?null:da(A,i),P=p-f>Math.PI?1:0,C=r?0:g-y>Math.PI?1:0;let R="";if(d)R+=`M${v.x},${v.y}`,R+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=da(o,n);R+=`M${t.x},${t.y}`}if(h)R+=` A${o},${o} 0 ${P} 1 ${b.x},${b.y}`,R+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=da(o,i);R+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)R+=" L0,0";else{if(h)R+=` L${_.x},${_.y}`,R+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=da(e,i);R+=` L${t.x},${t.y}`}if(d)R+=` A${e},${e} 0 ${C} 0 ${S.x},${S.y}`,R+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=da(e,n);R+=` A${e},${e} 0 ${C} 0 ${t.x},${t.y}`}}return R+=" Z",R}import{jsx as fa,jsxs as pa}from"react/jsx-runtime";function ya(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 ga(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(fa("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)?`${ya(l)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:ya(l);7.8*i.length+16>d&&(i=ya(l)),7.8*i.length+16>d||n.push(fa("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?fa("g",{children:n},e+"-funnel-labels"):null}function ma(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=Qs(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=ta(o.stops,Zs(t.style.fill));return a?Xs("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:n,y1:i,x2:r,y2:s,children:a}):null}(e,o);let i,s;if(n)s=`url(#${o})`;else if(Hn(e.style.fill)){const t=Qs(r)+"-hatch";i=Xn(e.style.fill,t),s=`url(#${t})`}else s=Zs(e.style.fill);const a=n||i?pa("defs",{children:[n,i]}):null;if(e.cornerRadii&&qs(e.cornerRadii)){const t=function(t){const{x:e,y:o,w:n,h:i}=t,{tl:r,tr:s,br:a,bl:l}=Vs(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 pa(ca.Fragment,{children:[a,fa("path",{d:t,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:o,y:n,w:i,h:l}=e;let c;switch(e.roundedEdge){case"right":c=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+l-t} A${t},${t} 0 0 1 ${o+i-t},${n+l} L${o},${n+l} Z`;break;case"left":c=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+l-t} A${t},${t} 0 0 0 ${o+t},${n+l} L${o+i},${n+l} Z`;break;case"bottom":c=`M${o},${n} L${o+i},${n} L${o+i},${n+l-t} A${t},${t} 0 0 1 ${o+i-t},${n+l} L${o+t},${n+l} A${t},${t} 0 0 1 ${o},${n+l-t} Z`;break;default:c=`M${o},${n+l} L${o},${n+t} A${t},${t} 0 0 1 ${o+t},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+l} Z`}return pa(ca.Fragment,{children:[a,fa("path",{d:c,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return pa(ca.Fragment,{children:[a,fa("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:s,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),ga(e,r)]},r)}case"point":{const e=t;return fa("circle",{cx:e.x,cy:e.y,r:e.r,fill:Zs(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return ea(t,e,o);case"glyph":return Js(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=Qs(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=ha({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:ha({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 pa("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[fa("defs",{children:fa("clipPath",{id:t,children:fa("path",{d:i})})}),fa("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>fa("path",{d:t.d,fill:Zs(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&fa("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=ha({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=ua().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(Ks)||""}return fa("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:Zs(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;return pa("g","vertical"===e.projection?{children:[fa("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1}),fa("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:Zs(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),fa("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2}),fa("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:1}),fa("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:1})]}:{children:[fa("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:1}),fa("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:Zs(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:1}),fa("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2}),fa("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:1}),fa("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:1})]},r)}case"violin":{const e=t,o=[fa("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:Zs(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(fa("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),fa("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(fa("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),fa("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return fa("g",{children:o},r)}case"connector":return fa("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??.5},r);case"trapezoid":{const e=t,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return fa("polygon",{points:o,fill:Zs(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}}import{jsx as ba,jsxs as xa}from"react/jsx-runtime";function va(t,e,o,n){if(!t||2>e.length)return null;const i=ta(t.stops,n);return i?ba("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function wa(t,e,o){switch(t.type){case"line":{const n=t;if(0===n.path.length)return null;const i=ri(n.curve),r=i?Ys().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=Qs(`${o?o+"-":""}line-${e}-stroke-gradient`),a=va(n.strokeGradient,n.path,s,n.style.stroke||"#4e79a7");return xa(Ws.Fragment,{children:[a&&ba("defs",{children:a}),ba("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 n=t;if(0===n.topPath.length)return null;const i=ri(n.curve),r=!i||2>n.topPath.length||2>n.bottomPath.length?`M${n.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...n.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:js().x(([t])=>t).y0((t,e)=>n.bottomPath[e][1]).y1(([,t])=>t).curve(i)(n.topPath)??"",s=`${o?o+"-":""}area-${e}-hatch`,a=Hn(n.style.fill)?Xn(n.style.fill,s):void 0,l=Qs(`${o?o+"-":""}area-${e}-gradient`),c=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=ta(o.stops,Zs(t.style.fill));return r?ba("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r}):null}(n,l),u=c?`url(#${l})`:a?`url(#${s})`:Zs(n.style.fill),d=c?void 0:n.style.fillOpacity??n.style.opacity??.7,h=i?Ys().x(([t])=>t).y(([,t])=>t).curve(i)(n.topPath)??"":"M"+n.topPath.map(([t,e])=>`${t},${e}`).join("L"),f=Qs(`${o?o+"-":""}area-${e}-stroke-gradient`),p=!(!n.colorThresholds?.length||!n.rawValues||n.rawValues.length!==n.topPath.length),y=!!n.strokeColorBands?.length,g=p||y?null:va(n.strokeGradient,n.topPath,f,n.style.stroke||"#4e79a7"),m=n.style.strokeWidth||2;let b=1/0,x=-1/0;for(const[t]of n.topPath)b>t&&(b=t),t>x&&(x=t);const v=y?n.strokeColorBands.map((t,n)=>Qs(`${o?o+"-":""}area-${e}-stroke-band-${n}`)):[],w=y?n.strokeColorBands.map((t,e)=>ba("clipPath",{id:v[e],children:ba("rect",{x:b-m,y:t.y,width:x-b+2*m,height:t.height})},v[e])):null,k=n.style.stroke&&"none"!==n.style.stroke?y?n.strokeColorBands.map((t,o)=>ba("path",{d:h,fill:"none",stroke:t.color??Zs(n.style.stroke),strokeWidth:m,opacity:n.style.opacity,clipPath:`url(#${v[o]})`},`area-${e}-stroke-band-${o}`)):p?Hs(n.topPath,n.rawValues,n.colorThresholds,Zs(n.style.stroke)).map((t,o)=>ba("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:m,opacity:n.style.opacity},`area-${e}-threshold-${o}`)):ba("path",{d:h,fill:"none",stroke:g?`url(#${f})`:Zs(n.style.stroke),strokeWidth:m,opacity:n.style.opacity}):null;if(n.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return xa("g",{children:[xa("defs",{children:[c,!c&&a,g,w,ba("clipPath",{id:t,children:ba("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),xa("g",{clipPath:`url(#${t})`,children:[ba("path",{d:r,fill:u,fillOpacity:d,opacity:c?n.style.opacity:void 0,stroke:"none"}),k]})]},"area-"+e)}return xa(Ws.Fragment,{children:[(c||a||g||w)&&xa("defs",{children:[c,!c&&a,g,w]}),ba("path",{d:r,fill:u,fillOpacity:d,opacity:c?n.style.opacity:void 0,stroke:"none"}),k]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=Hn(n.style.fill)?Xn(n.style.fill,i):void 0;return xa(Ws.Fragment,{children:[r&&ba("defs",{children:r}),ba("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:Zs(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return ea(t,e);case"glyph":return Js(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=Hn(n.style.fill)?Xn(n.style.fill,i):void 0;return xa(Ws.Fragment,{children:[r&&ba("defs",{children:r}),ba("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:Zs(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 xa("g",{children:[ba("rect",{...n}),ba("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 ba("rect",{...n},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return xa("g",{children:[ba("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),ba("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),ba("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 xa("g",{children:[ba("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),ba("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}}var ka="undefined"==typeof window||"undefined"==typeof document;import{useEffect as Sa,useLayoutEffect as Aa,useRef as Ma,useState as _a,useSyncExternalStore as Pa}from"react";var Ca="undefined"!=typeof window?Aa:Sa,Ra=()=>()=>{},La=()=>!1,Ia=()=>!0;import{useRef as Ta}from"react";function $a(t,e){const o=Object.keys(t),n=Object.keys(e);if(o.length!==n.length)return!1;for(const n of o){if(!Object.prototype.hasOwnProperty.call(e,n))return!1;if(!Object.is(t[n],e[n]))return!1}return!0}function za(t,e){if(t.length!==e.length)return!1;for(let o=0;t.length>o;o++)if(!Object.is(t[o],e[o]))return!1;return!0}function Da(t){if(null===t||"object"!=typeof t)return!1;if(Array.isArray(t))return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function Fa(t){const{background:e,hasBackgroundGraphics:o=!1,themeBackground:n=""}=t;return"transparent"===e||o?null:e||(n&&"transparent"!==n?n:"")||null}var Ea={axisStroke:"#ccc",tickText:"#666",crosshair:"rgba(0, 0, 0, 0.25)",hoverFill:"rgba(255, 255, 255, 0.3)",hoverStroke:"rgba(0, 0, 0, 0.4)",pointRing:"white",primary:"#007bff",background:""};function Oa(t,e){const o=t.trim();if(/^#[0-9a-f]{3}$/i.test(o)){const t=o[1],n=o[2],i=o[3];return`#${t}${t}${n}${n}${i}${i}${e}`}if(/^#[0-9a-f]{6}$/i.test(o))return`${o}${e}`;const n=o.match(/^rgb\s*\(\s*([^)]+?)\s*\)$/i);return n?`rgba(${n[1]}, ${(parseInt(e,16)/255).toFixed(3)})`:o}import*as Ba from"react";import*as Na from"react";import{jsx as Wa}from"react/jsx-runtime";var ja=Na.createContext(null);import{jsx as Ya}from"react/jsx-runtime";var Ga={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};function Ha({hoverPoint:t}){let e="";if(t){const o=t.data||t;e="object"==typeof o?"Data point: "+Object.entries(o).filter(([,t])=>"object"!=typeof t&&"function"!=typeof t).map(([t,e])=>`${t}: ${e}`).join(", "):"Data point: "+o}return Ya("div",{"aria-live":"polite","aria-atomic":"true",style:Ga,children:e})}function qa(t){const e={};if(null==t||"object"!=typeof t)return e;for(const[o,n]of Object.entries(t))o.startsWith("_")||null!=n&&""!==n&&("number"==typeof n?Number.isFinite(n)&&(e[o]=n):"string"==typeof n?e[o]=n:"boolean"==typeof n?e[o]=n+"":n instanceof Date&&(e[o]=n.toISOString().slice(0,10)));return e}function Va(t){return t&&"object"==typeof t?t:{}}function Xa(t){return Va(t.accessibility).tableFields??t.accessibleDatum??t.datum}import{jsx as Ua,jsxs as Ka}from"react/jsx-runtime";function Za(t,e){if(!t||0===t.length)return e+", empty";const o={};for(const e of t){if(null===e?.datum)continue;const t=e.type+"";o[t]=(o[t]||0)+1}if(0===Object.keys(o).length)return e+", empty";const n=[],i={point:"points",line:"lines",area:"areas",rect:"bars",heatcell:"cells",circle:"nodes",candlestick:"candlesticks",wedge:"wedges",arc:"arcs",geoarea:"regions"},r=["point","line","area","rect","heatcell","circle","candlestick","wedge","arc","geoarea"],s=Object.keys(o).sort((t,e)=>{const o=r.indexOf(t),n=r.indexOf(e);return(-1===o?999:o)-(-1===n?999:n)});for(const t of s)n.push(`${o[t]} ${i[t]||t}`);return`${e}, ${n.join(", ")}`}var Qa=t=>{if(null==t)return"";const e=Math.round(100*t)/100;return Number.isNaN(e)?"":e+""},Ja="semiotic-accessible-data-table",tl=Ja+" semiotic-accessible-data-table-hidden",el=Ja+" semiotic-accessible-data-table-visible",ol={position:"absolute",top:0,left:0,right:0,zIndex:"var(--semiotic-data-table-z-index, var(--semiotic-overlay-z-index, 20))",padding:"14px 16px 12px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontFamily:"var(--semiotic-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif)",fontSize:13,lineHeight:1.5,color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",borderRadius:"var(--semiotic-border-radius, 0px) var(--semiotic-border-radius, 0px) 0 0"},nl={marginBottom:8,paddingRight:28,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:12,letterSpacing:"0.01em"},il={position:"absolute",top:10,right:10,width:22,height:22,display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",cursor:"pointer",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",fontSize:13,lineHeight:1,padding:0,borderRadius:"var(--semiotic-border-radius, 4px)"},rl={width:"100%",borderCollapse:"collapse",fontSize:12,marginTop:4,fontVariantNumeric:"tabular-nums"},sl={textAlign:"left",padding:"5px 10px",borderBottom:"2px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))"},al={padding:"4px 10px",borderBottom:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))"},ll={textAlign:"left",fontSize:11,color:"var(--semiotic-data-table-muted-text, var(--semiotic-text-secondary, #666))",marginBottom:4,fontStyle:"italic"},cl={marginTop:8,padding:"4px 10px",fontSize:12,cursor:"pointer",border:"1px solid var(--semiotic-data-table-border, var(--semiotic-border, #e0e0e0))",borderRadius:"var(--semiotic-border-radius, 4px)",background:"var(--semiotic-data-table-bg, var(--semiotic-surface, var(--semiotic-bg, #fff)))",color:"var(--semiotic-data-table-text, var(--semiotic-text, #333))",fontFamily:"inherit"};function ul({scene:t,chartType:e,tableId:o,chartTitle:n}){const[i,r]=Ba.useState(!1),[s,a]=Ba.useState(5),l=Na.useContext(ja),c=l?.visible??!1,u=i||c,d=Ba.useRef(null),h=n?"Data summary for "+n:o?`Data summary for ${e} ${o}`:"Data summary for "+e;Ba.useEffect(()=>{u||a(5)},[u]);const f=Ba.useCallback(t=>{t.target===t.currentTarget&&(i||c||r(!0))},[i,c]),p=Ba.useCallback(t=>{c||d.current?.contains(t.relatedTarget)||r(!1)},[c]);if(!t||0===t.length)return o?Ua("span",{id:o,tabIndex:-1,style:Ga}):null;if(!u)return Ua("div",{id:o,className:tl,tabIndex:-1,onFocus:f,style:Ga,role:"region","aria-label":h,children:Ka("button",{type:"button",onClick:()=>r(!0),children:["View data summary (",t.length," elements)"]})});const y=function(t){const e=[];if(!Array.isArray(t))return e;const o=t.some(t=>t&&("line"===t.type||"area"===t.type));for(const n of t)if(n&&"object"==typeof n&&null!==n.datum)try{switch(n.type){case"point":if(o)break;e.push({label:"Point",values:qa(Xa(n))});break;case"line":case"area":{const t=Xa(n),o=Array.isArray(t)?t:[],i="line"===n.type?"Line point":"Area point";for(const t of o)e.push({label:i,values:qa(t)});break}case"rect":{const t=Xa(n),o=null!=t&&"object"==typeof t?t:{},i=o.category??n.group??"",r=o.value??o.__aggregateValue??o.total,s=qa(o);null==s.category&&""!==i&&(s.category=i+""),null==s.value&&null!=r&&(s.value="number"==typeof r||"string"==typeof r?r:r+""),e.push({label:"Bar",values:s});break}case"heatcell":{const t=qa(Xa(n));null==t.value&&"number"==typeof n.value&&Number.isFinite(n.value)&&(t.value=n.value),e.push({label:"Cell",values:t});break}case"wedge":{const t=Xa(n),o=qa(t);if(null==o.category){const e=Va(t),n=e.category??e.label;null!=n&&(o.category=n+"")}e.push({label:"Wedge",values:o});break}case"circle":e.push({label:"Node",values:qa(Xa(n))});break;case"arc":e.push({label:"Arc",values:qa(Xa(n))});break;case"candlestick":e.push({label:"Candlestick",values:qa(Xa(n))});break;case"geoarea":{const t=Va(Xa(n)),o=qa(t);if(null==o.name){const e=Va(t.properties).name??t.name;null!=e&&(o.name=e+"")}e.push({label:"Region",values:o});break}}}catch{}return e}(t),g=function(t){if(!t||0===t.length)return[];const e=new Set;for(const o of t)if(o&&o.values)for(const t of Object.keys(o.values))e.add(t);const o=[];for(const n of e){const e=[],i=new Set;for(const o of t){if(!o||!o.values)continue;const t=o.values[n];null!=t&&""!==t&&("number"==typeof t&&!Number.isNaN(t)&&Number.isFinite(t)?e.push(t):"number"==typeof t||"object"!=typeof t&&"function"!=typeof t&&i.add(t+""))}if(e.length>0){let t=e[0],i=e[0],r=0;for(const o of e)t>o&&(t=o),o>i&&(i=o),r+=o;o.push({name:n,count:e.length,numeric:!0,min:t,max:i,mean:r/e.length})}else if(i.size>0){const t=Array.from(i);o.push({name:n,count:t.length,numeric:!1,uniqueValues:t.slice(0,5)})}}return o}(y),m=function(t,e){const o=[t+" data points."];for(const t of e)if(t.numeric)o.push(`${t.name}: ${Qa(t.min)} to ${Qa(t.max)}, mean ${Qa(t.mean)}.`);else{const e=t.uniqueValues,n=e.length>3?`${e.slice(0,3).join(", ")}… (${t.count} unique)`:e.join(", ");o.push(`${t.name}: ${n}.`)}return o.join(" ")}(y.length,g),b=Math.min(s,y.length),x=y.slice(0,b),v=y.length-b,w=new Set;for(const t of x)for(const e of Object.keys(t.values))w.add(e);const k=Array.from(w);return Ka("div",{ref:d,id:o,className:el,tabIndex:-1,onBlur:p,style:ol,role:"region","aria-label":h,children:[Ua("button",{type:"button",className:"semiotic-accessible-data-table-close",onClick:()=>{c&&l&&l.setVisible(!1),r(!1)},"aria-label":"Close data summary",style:il,children:"×"}),Ua("div",{className:"semiotic-accessible-data-table-summary",role:"note",style:nl,children:m}),Ka("table",{className:"semiotic-accessible-data-table-table",role:"table","aria-label":"Sample data for "+e,style:rl,children:[Ua("caption",{className:"semiotic-accessible-data-table-caption",style:ll,children:v>0?`First ${b} of ${y.length} data points`:`All ${y.length} data points`}),Ua("thead",{children:Ka("tr",{children:[Ua("th",{style:sl,children:"type"}),k.map(t=>Ua("th",{style:sl,children:t},t))]})}),Ua("tbody",{children:x.map((t,e)=>Ka("tr",{children:[Ua("td",{style:al,children:t.label}),k.map(e=>{return Ua("td",{style:al,children:(o=t.values[e],null==o||""===o?"—":"number"==typeof o?Number.isNaN(o)?"—":Qa(o):"boolean"==typeof o?o?"true":"false":"object"==typeof o?"—":o+"")},e);var o})]},e))})]}),v>0&&Ka("button",{type:"button",className:"semiotic-accessible-data-table-show-more",onClick:()=>a(t=>t+25),style:cl,children:["Show ",Math.min(25,v)," more"," ",1===v?"row":"rows"," (",v," remaining)"]})]})}function dl({summary:t}){return t?Ua("div",{role:"note",style:Ga,children:t}):null}function hl({tableId:t}){return Ua("a",{href:"#"+t,style:Ga,onClick:e=>{e.preventDefault();const o=document.getElementById(t);o&&requestAnimationFrame(()=>o.focus())},onFocus:t=>{Object.assign(t.currentTarget.style,{position:"absolute",width:"auto",height:"auto",overflow:"visible",clip:"auto",whiteSpace:"normal",padding:"4px 8px",background:"var(--semiotic-bg, #fff)",color:"var(--semiotic-text, #000)",border:"2px solid var(--semiotic-focus, #005fcc)",borderRadius:"4px",zIndex:"10",fontSize:"12px",top:"4px",left:"4px"})},onBlur:t=>{const e=t.currentTarget;e.removeAttribute("style"),Object.assign(e.style,Ga)},children:"Skip to data table"})}import{jsx as fl}from"react/jsx-runtime";var pl="var(--semiotic-focus, #005fcc)";function yl({active:t,hoverPoint:e,margin:o,size:n,shape:i="circle",width:r,height:s,pathData:a}){if(!t||!e)return null;const l=e.x+o.left,c=e.y+o.top;let u;if("geoarea"!==i&&"path"!==i||!a)if("rect"===i&&null!=r&&null!=s){const t=Math.max(r,4),e=Math.max(s,4);u=fl("rect",{x:l-t/2-3,y:c-e/2-3,width:t+6,height:e+6,rx:3,fill:"none",stroke:pl,strokeWidth:2,strokeDasharray:"4,2"})}else u=fl("circle","wedge"===i?{cx:l,cy:c,r:12,fill:"none",stroke:pl,strokeWidth:2.5,strokeDasharray:"6,3"}:{cx:l,cy:c,r:8,fill:"none",stroke:pl,strokeWidth:2,strokeDasharray:"4,2"});else u=fl("g",{transform:`translate(${o.left},${o.top})`,children:fl("path",{d:a,fill:"none",stroke:pl,strokeWidth:2.5,strokeDasharray:"6,3"})});return fl("svg",{style:{position:"absolute",left:0,top:0,width:n[0],height:n[1],pointerEvents:"none",zIndex:2},"aria-hidden":"true",children:u})}import*as gl from"react";function ml(t,e){return"touch"===e?Math.max(t,24):t}function bl(t){return Array.isArray(t)?t[0]:t}function xl(t,e,o,n){return{data:bl(t),x:e,y:o,__semioticHoverData:!0,...n}}var vl=["name","label","title"],wl=["type","kind","category","group","class","status","role","shape"],kl=["value","amount","total","count","weight","score"],Sl=new Set(["x","y","z","x0","x1","y0","y1","r","cx","cy","radius","layer","row","rowindex","col","column","depth","index","order","sankeywidth","coincidentpoints","sourcelinks","targetlinks","parent","children","fx","fy","vx","vy"]);function Al(t,e){for(const o of e){const e=t.find(t=>t.lower===o);if(e)return e}}function Ml(t,e={}){if(!t||"object"!=typeof t)return{entries:[]};const o=e.maxEntries??6,n=!1!==e.skipPositional,i=[];for(const[e,o]of Object.entries(t)){if(e.startsWith("_"))continue;if("data"===e)continue;if(n&&Sl.has(e.toLowerCase()))continue;if(null==o)continue;const t=typeof o;("string"===t||"number"===t||"boolean"===t||o instanceof Date)&&i.push({key:e,lower:e.toLowerCase(),value:o})}if(0===i.length)return{entries:[]};let r=i.findIndex(t=>vl.includes(t.lower));const s=r>=0;0>r&&(r=i.findIndex(t=>"id"===t.lower)),0>r&&(r=i.findIndex(t=>"string"==typeof t.value));const a=0>r?void 0:i[r];let l=i.filter((t,e)=>e!==r);s&&(l=l.filter(t=>"id"!==t.lower));const c=Al(l,wl),u=Al(l,kl),d=new Set(wl),h=new Set(kl),f=[];c&&f.push({key:c.key,value:c.value}),u&&f.push({key:u.key,value:u.value});for(const t of l){if(f.length>=o)break;t!==c&&t!==u&&(d.has(t.lower)||h.has(t.lower)||f.push({key:t.key,value:t.value}))}return{titleKey:a?.key,title:a?.value,entries:f}}import{jsx as _l,jsxs as Pl}from"react/jsx-runtime";var Cl={background:"var(--semiotic-tooltip-bg, rgba(0, 0, 0, 0.85))",color:"var(--semiotic-tooltip-text, white)",padding:"8px 12px",borderRadius:"var(--semiotic-tooltip-radius, 6px)",fontSize:"var(--semiotic-tooltip-font-size, 14px)",fontFamily:"var(--semiotic-font-family, inherit)",lineHeight:"1.5",boxShadow:"var(--semiotic-tooltip-shadow, 0 2px 8px rgba(0, 0, 0, 0.15))",pointerEvents:"none",maxWidth:"300px",wordWrap:"break-word"};function Rl(t,e){return"function"==typeof e?e(t):t[e]}function Ll(t,e){if(e)return e(t);if(null==t)return"";if("number"==typeof t){if(!Number.isFinite(t))return t+"";const e=Number.isInteger(t)?t:parseFloat(t.toPrecision(6));return Math.abs(e)>9999?e.toLocaleString():e+""}return t instanceof Date?t.toLocaleDateString():"object"==typeof t&&null!==t?void 0!==t.id?t.id+"":void 0!==t.name?t.name+"":JSON.stringify(t):t+""}function Il(t={}){const{fields:e,title:o,format:n,style:i={},className:r=""}=t;return t=>{if(!t||"object"!=typeof t)return null;let s;const a=[];if(o){const e=Rl(t,o);s=Ll(e,n)}if(e&&e.length>0)e.forEach(e=>{let o,i,r;"string"==typeof e?(o=e,i=e,r=n):(o=e.label,i=e.accessor||e.key||"",r=e.format||n);const s=Rl(t,i);a.push({label:o,value:Ll(s,r)})});else if(!o){const e=["value","y","name","id","label"];for(const o of e)if(void 0!==t[o]){s=Ll(t[o],n);break}if(!s){const e=Object.keys(t).filter(t=>!t.startsWith("_"));e.length>0&&(s=Ll(t[e[0]],n))}}const l={...Cl,...i};return Pl("div",{className:("semiotic-tooltip "+r).trim(),style:l,children:[s&&_l("div",{style:{fontWeight:a.length>0?"bold":"normal"},children:s}),a.map((t,e)=>Pl("div",{style:{marginTop:0===e&&s?"4px":0},children:[t.label&&Pl("span",{children:[t.label,": "]}),t.value]},e))]})}}import{jsx as Tl}from"react/jsx-runtime";function $l({x:t,y:e,containerWidth:o,containerHeight:n,margin:i,children:r,className:s="stream-frame-tooltip",zIndex:a=1}){const l=Number.isFinite(t)&&Number.isFinite(e),c=gl.useRef(null),[u,d]=gl.useState(null);gl.useLayoutEffect(()=>{const t=c.current;if(!t)return;const e=()=>{const e=t.getBoundingClientRect();Number.isFinite(e.width)&&Number.isFinite(e.height)&&d(t=>t&&.5>Math.abs(t.width-e.width)&&.5>Math.abs(t.height-e.height)?t:{width:e.width,height:e.height})};if(e(),"undefined"==typeof ResizeObserver)return;const o=new ResizeObserver(e);return o.observe(t),()=>o.disconnect()},[s,o,n,l]);let h;h=u?`translate(${u.width+12>o-t?"calc(-100% - 12px)":"12px"}, ${u.height+12>n-e?"calc(-100% - 4px)":"4px"})`:`translate(${t>.7*o?"calc(-100% - 12px)":"12px"}, ${.3*n>e?"4px":"calc(-100% - 4px)"})`;const f=function(t){if(!gl.isValidElement(t))return!1;const e=t.type;if("string"!=typeof e&&e&&!0===e.ownsChrome)return!0;const o=t.props;if(!0===o["data-semiotic-tooltip-chrome"])return!0;if("true"===o["data-semiotic-tooltip-chrome"])return!0;const n=o.style;if(n&&"object"==typeof n){if(null!=n.background&&""!==n.background&&"transparent"!==n.background)return!0;if(null!=n.backgroundColor&&""!==n.backgroundColor&&"transparent"!==n.backgroundColor)return!0}return!1}(r),p=f?null:Cl;return l?Tl("div",{ref:c,className:f?s:(s+" semiotic-tooltip").trim(),style:{...p||{},position:"absolute",left:i.left+t,top:i.top+e,transform:h,pointerEvents:"none",zIndex:a,width:"max-content"},children:r}):null}import*as zl from"react";import{useCallback as Dl,useEffect as Fl,useLayoutEffect as El,useMemo as Ol,useRef as Bl}from"react";import{useState as Nl,useEffect as Wl}from"react";import{useRef as jl,useState as Yl,useEffect as Gl}from"react";var Hl=()=>"undefined"!=typeof performance?performance.now():Date.now();function ql(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}}function Vl(t,e){const o=t();return Number.isFinite(o)?o:e}var Xl=class{constructor(t={}){this.randomSource=Math.random,this.subscribers=new Set,this.now=()=>this.advance(),this.random=()=>this.randomSource(),this.clock=t.clock??Hl,this.lastWallTime=Vl(this.clock,0),this.logicalTime=this.lastWallTime,this.pausedValue=!0===t.paused,this.visibleValue=!1!==t.visible,this.setRandomSource(t.random,t.seed)}get isActive(){return!this.pausedValue&&this.visibleValue}get paused(){return this.pausedValue}get seed(){return this.seedValue}get visible(){return this.visibleValue}configure(t){this.setClock(t.clock),this.setRandomSource(t.random,t.seed)}setPaused(t){this.pausedValue!==t&&(this.advance(),this.pausedValue=t,this.emit())}setVisible(t){this.visibleValue!==t&&(this.advance(),this.visibleValue=t,this.emit())}snapshot(){return{now:this.now(),paused:this.pausedValue,seed:this.seedValue,visible:this.visibleValue}}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}advance(){const t=Vl(this.clock,this.lastWallTime),e=Math.max(0,t-this.lastWallTime);return this.lastWallTime=t,this.isActive&&(this.logicalTime+=e),this.logicalTime}emit(){for(const t of this.subscribers)t()}setClock(t){const e=t??Hl;e!==this.clock&&(this.advance(),this.clock=e,this.lastWallTime=Vl(e,this.lastWallTime))}setRandomSource(t,e){const o=function(t){return"number"==typeof t&&Number.isFinite(t)?Math.trunc(t):void 0}(e);t===this.randomInput&&o===this.seedValue||(this.randomInput=t,this.seedValue=o,this.randomSource=t??(void 0===o?Math.random:ql(o)))}},Ul="undefined"==typeof window?Fl:El,Kl={requestAnimationFrame:t=>("undefined"==typeof window?globalThis:window).requestAnimationFrame(t),cancelAnimationFrame:t=>("undefined"==typeof window?globalThis:window).cancelAnimationFrame(t)};function Zl(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function Ql(t){const e=function(){const[t,e]=Nl(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches);return Wl(()=>{if("undefined"==typeof window||!window.matchMedia)return;const t=window.matchMedia("(prefers-reduced-motion: reduce)");return e(t.matches),function(t,e){if("function"==typeof t.addEventListener)return t.addEventListener("change",e),()=>t.removeEventListener("change",e);const o=t;return o.addListener(e),()=>o.removeListener(e)}(t,t=>e(t.matches))},[]),t}(),o=Bl(e);o.current=e;const[n,i]=function(t,e,o){const n=jl(null),[i,r]=Yl(null);return Gl(()=>{if(!e&&!o)return;const t=n.current;if(!t)return;const i=new ResizeObserver(t=>{for(const e of t){const{width:t,height:o}=e.contentRect;r(e=>e&&e.w===t&&e.h===o?e:{w:t,h:o})}});return i.observe(t),()=>i.disconnect()},[e,o]),[n,[e&&i?i.w:t[0],o&&i?i.h:t[1]]]}(t.sizeProp,t.responsiveWidth,t.responsiveHeight),r=!!t.title,s=!!t.legend&&"top"===t.legendPosition,a=Ol(()=>Ts({...t.marginDefault,...t.userMargin},r,s),[t.marginDefault,t.userMargin,r,s]),l=i[0]-a.left-a.right,c=i[1]-a.top-a.bottom,u=Zl(t.foregroundGraphics,i,a),d=Zl(t.backgroundGraphics,i,a),h=_(t=>t.theme),{transition:f,introEnabled:p}=function(t,e){if(!1===t)return{transition:void 0,introEnabled:!1};const o="undefined"!=typeof window&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;return{transition:t?!0===t?{duration:300}:{duration:t.duration??300,easing:"linear"===t.easing?"linear":"ease-out"}:e,introEnabled:!(o||!t||!0!==t&&!1===t.intro)}}(t.animate,t.transitionProp),y="semiotic-table-"+zl.useId(),g=Bl(null);if(!g.current){const e=!t.suspendWhenHidden||"undefined"==typeof document||!document.hidden;g.current=new Xl({clock:t.clock,random:t.random,seed:t.seed,paused:t.paused,visible:e})}const m=g.current;m.configure({clock:t.clock,random:t.random,seed:t.seed});const b=Bl(null),x=Bl(t.frameScheduler??Kl);x.current=t.frameScheduler??Kl;const v=Bl(null),w=Bl(!1),k=Bl(()=>{}),S=Dl(()=>{if(null!==b.current||w.current)return;const t=x.current;let e=!1,o=!1;const n=t.requestAnimationFrame(()=>{e=!0;const t=!o;t&&(w.current=!0),b.current=null,v.current=null;try{k.current()}finally{t&&(w.current=!1)}});o=!0,e||(b.current=n,v.current=t)},[]),A=Dl(()=>{null!==b.current&&((v.current??x.current).cancelAnimationFrame(b.current),b.current=null,v.current=null)},[]);Ul(()=>{m.setPaused(!0===t.paused)},[m,t.paused]),Fl(()=>{if(!t.suspendWhenHidden||"undefined"==typeof document)return void m.setVisible(!0);const e=()=>m.setVisible(!document.hidden);return e(),document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[m,t.suspendWhenHidden]),Fl(()=>()=>{A()},[A]);const M=Bl(()=>{}),P=Bl(()=>{}),C=Bl(null),R=Bl(null),L=Bl(null),I=Dl(()=>{const t=C.current;C.current=null,t&&M.current(t)},[]),T=Dl(t=>{if(C.current={clientX:t.clientX,clientY:t.clientY,pointerType:t.pointerType},null===R.current){const t=x.current;let e=!1;const o=t.requestAnimationFrame(()=>{e=!0,R.current=null,L.current=null,I()});e||(R.current=o,L.current=t)}},[I]),$=Dl(()=>{C.current=null,null!==R.current&&((L.current??x.current).cancelAnimationFrame(R.current),R.current=null,L.current=null),P.current()},[]);Fl(()=>()=>{C.current=null,null!==R.current&&((L.current??x.current).cancelAnimationFrame(R.current),R.current=null,L.current=null)},[]);const z=t.themeDirtyRef;return Ul(()=>{z&&(Fn++,z.current=!0,S())},[h,S,z]),{reducedMotion:e,reducedMotionRef:o,responsiveRef:n,size:i,margin:a,adjustedWidth:l,adjustedHeight:c,resolvedForeground:u,resolvedBackground:d,currentTheme:h,transition:f,introEnabled:p,tableId:y,frameRuntime:m,rafRef:b,renderFnRef:k,scheduleRender:S,cancelRender:A,hoverHandlerRef:M,hoverLeaveRef:P,onPointerMove:T,onPointerLeave:$}}import{useEffect as Jl,useRef as tc}from"react";import{jsx as ec}from"react/jsx-runtime";function oc({children:t,size:e,margin:o,overflowVisible:n=!1}){return t?ec("svg",{style:{position:"absolute",left:0,top:0,width:e[0],height:e[1],pointerEvents:"none",overflow:n?"visible":void 0},children:ec("g",{transform:`translate(${o.left},${o.top})`,children:t})}):null}function nc(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}function ic(t,e,o,n){const i=t.getContext("2d");if(!i)return null;const r=Math.round(e[0]*n),s=Math.round(e[1]*n),a=r/e[0],l=s/e[1],c=e[0]+"px",u=e[1]+"px";return t.style.width!==c&&(t.style.width=c),t.style.height!==u&&(t.style.height=u),t.width===r&&t.height===s||(t.width=r,t.height=s),i.setTransform(a,0,0,l,0,0),i.translate(o.left,o.top),i}import{useCallback as rc,useRef as sc}from"react";function ac(t,e,o,n){return"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:o,fn:t}:"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:n,fn:e}:{key:void 0,fn:null}}var lc=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],cc=3156e7;function uc(t){const e=t[1]-t[0];return 864e5>e?t=>{const e=new Date(t);return`${(e.getUTCHours()+"").padStart(2,"0")}:${(e.getUTCMinutes()+"").padStart(2,"0")}`}:cc>e?t=>{const e=new Date(t);return`${lc[e.getUTCMonth()]} ${e.getUTCDate()}`}:5*cc>e?t=>{const e=new Date(t);return`${lc[e.getUTCMonth()]} ${e.getUTCFullYear()}`}:t=>new Date(t).getUTCFullYear()+""}function dc(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("symbol"===o.type)e.push({pointId:o.pointId,x:o.x,y:o.y,r:ho(o.size)});else if("glyph"===o.type){const t=$n(o.glyph,o.size);e.push({pointId:o.pointId,x:o.x+t.centerDx,y:o.y+t.centerDy,r:t.radius})}return e}import{line as hc}from"d3-shape";function fc(t,e,o,n,i,r){if(2>e.length)return;const s=[0];for(let t=1;e.length>t;t++){const o=e[t][0]-e[t-1][0],n=e[t][1]-e[t-1][1];s.push(s[t-1]+Math.sqrt(o*o+n*n))}const a=s[s.length-1];if(0===a)return;const l=Math.min(.2*a,40);t.strokeStyle=o,t.lineWidth=n,t.lineCap=r;for(let o=0;e.length-1>o;o++){const n=(s[o]+s[o+1])/2;let r=i;l>n&&(r*=n/l),l>a-n&&(r*=(a-n)/l),t.globalAlpha=Math.max(0,r),t.beginPath(),t.moveTo(e[o][0],e[o][1]),t.lineTo(e[o+1][0],e[o+1][1]),t.stroke()}}var pc=(t,e,o,n)=>{const i=e.filter(t=>"line"===t.type);for(const e of i){if(2>e.path.length)continue;const o=e._introClipFraction;void 0!==o&&1>o&&(t.save(),t.beginPath(),t.rect(0,0,n.width*o,n.height),t.clip());const i=e.style.stroke||"#007bff",r=Nn(t,i)||i,s=e.style.strokeWidth||2,a=e.colorThresholds,l=e.rawValues;if(t.setLineDash(e.style.strokeDasharray?e.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=e.style.opacity&&(t.globalAlpha=e.style.opacity),t.lineWidth=s,t.lineCap=e.style.strokeLinecap||"butt",e.style._edgeFade){fc(t,e.path,r,s,e.style.opacity??1,e.style.strokeLinecap||"butt"),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt";continue}const c=ri(e.curve),u=a&&a.length>0&&l&&l.length===e.path.length,d=e._decayOpacities;if(d&&d.length===e.path.length&&!u){t.strokeStyle=r;const o=e.style.opacity??1;for(let n=0;e.path.length-1>n;n++)t.globalAlpha=.5*(d[n]+d[n+1])*o,t.beginPath(),t.moveTo(e.path[n][0],e.path[n][1]),t.lineTo(e.path[n+1][0],e.path[n+1][1]),t.stroke()}else if(u){const o=Hs(e.path,l,a,r);for(const e of o){t.beginPath(),t.strokeStyle=Nn(t,e.color)||e.color,t.moveTo(e.path[0][0],e.path[0][1]);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1]);t.stroke()}}else{t.beginPath();const o=e.strokeGradient&&e.path.length>=2?ci(t,e.strokeGradient,r,e.path[0][0],0,e.path[e.path.length-1][0],0):null;if(t.strokeStyle=o||r,c)hc().x(t=>t[0]).y(t=>t[1]).curve(c).context(t)(e.path);else{const[o,n]=e.path[0];t.moveTo(o,n);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1])}t.stroke()}if(e.style.fill&&e.style.fillOpacity&&e.style.fillOpacity>0){if(t.beginPath(),t.globalAlpha=e.style.fillOpacity,t.fillStyle=si(t,e.style.fill,e.style.fill),c&&!u)hc().x(t=>t[0]).y(t=>t[1]).curve(c).context(t)(e.path);else{const[o,n]=e.path[0];t.moveTo(o,n);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1])}const o=e.path[0][0];t.lineTo(e.path[e.path.length-1][0],n.height),t.lineTo(o,n.height),t.closePath(),t.fill()}void 0!==o&&1>o&&t.restore(),t.globalAlpha=1,t.setLineDash([]),t.lineCap="butt"}};function yc(t){return!(!t._pulseIntensity||0>=t._pulseIntensity)}function gc(t,e,o=.3){yc(e)&&(t.globalAlpha=e._pulseIntensity*o,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.fillRect(e.x,e.y,e.w,e.h))}function mc(t,e,o=.6){if(!yc(e))return;const n=e.r+(e._pulseGlowRadius??4)*e._pulseIntensity,i=e.cx??e.x??0,r=e.cy??e.y??0;t.beginPath(),t.arc(i,r,n,0,2*Math.PI),t.strokeStyle=e._pulseColor||"rgba(255,255,255,0.6)",t.lineWidth=2*e._pulseIntensity,t.globalAlpha=e._pulseIntensity*o,t.stroke()}function bc(t,e,o,n=.35){yc(e)&&(t.globalAlpha=e._pulseIntensity*n,t.fillStyle=e._pulseColor||"rgba(255,255,255,0.6)",o?t.fill(o):t.fill())}import{area as xc,line as vc}from"d3-shape";function wc(t,e){const o=ri(e.curve);if(!o||2>e.topPath.length||2>e.bottomPath.length){t.beginPath(),t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let o=1;e.topPath.length>o;o++)t.lineTo(e.topPath[o][0],e.topPath[o][1]);for(let o=e.bottomPath.length-1;o>=0;o--)t.lineTo(e.bottomPath[o][0],e.bottomPath[o][1]);t.closePath()}else{const n=xc().x(t=>t[0]).y0((t,o)=>e.bottomPath[o][1]).y1(t=>t[1]).curve(o).context(t);t.beginPath(),n(e.topPath)}}function kc(t,e){const o=ri(e.curve);if(t.beginPath(),o)vc().x(t=>t[0]).y(t=>t[1]).curve(o).context(t)(e.topPath);else{t.moveTo(e.topPath[0][0],e.topPath[0][1]);for(let o=1;e.topPath.length>o;o++)t.lineTo(e.topPath[o][0],e.topPath[o][1])}}var Sc=(t,e,o,n)=>{const i=e.filter(t=>"area"===t.type);for(const e of i){if(2>e.topPath.length)continue;let o=!1;e.clipRect&&(t.save(),t.beginPath(),t.rect(e.clipRect.x,e.clipRect.y,e.clipRect.width,e.clipRect.height),t.clip(),o=!0);const i=e._introClipFraction;void 0!==i&&1>i&&(t.save(),t.beginPath(),t.rect(0,0,n.width*i,n.height),t.clip());const r=si(t,e.style.fill,"#4e79a7"),s=e._decayOpacities,a=!(!e.colorThresholds?.length||!e.rawValues||e.rawValues.length!==e.topPath.length),l=!!e.strokeColorBands?.length;if(s&&s.length===e.topPath.length&&!a&&!l){const o=e.style.fillOpacity??.7;t.fillStyle=r;for(let n=0;e.topPath.length-1>n;n++)t.globalAlpha=.5*(s[n]+s[n+1])*o,t.beginPath(),t.moveTo(e.topPath[n][0],e.topPath[n][1]),t.lineTo(e.topPath[n+1][0],e.topPath[n+1][1]),t.lineTo(e.bottomPath[n+1][0],e.bottomPath[n+1][1]),t.lineTo(e.bottomPath[n][0],e.bottomPath[n][1]),t.closePath(),t.fill();if(e.style.stroke&&"none"!==e.style.stroke){t.strokeStyle=Nn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||2,t.setLineDash([]);for(let o=0;e.topPath.length-1>o;o++)t.globalAlpha=.5*(s[o]+s[o+1]),t.beginPath(),t.moveTo(e.topPath[o][0],e.topPath[o][1]),t.lineTo(e.topPath[o+1][0],e.topPath[o+1][1]),t.stroke()}t.globalAlpha=1;continue}const c=e.style.opacity??1;if(wc(t,e),e.fillGradient&&e.fillGradient.stops.length>=2&&e.fillGradient){let o=1/0;for(const t of e.topPath)o>t[1]&&(o=t[1]);let n=-1/0;for(const t of e.bottomPath)t[1]>n&&(n=t[1]);const i=ai(t,e.fillGradient,"string"==typeof r?r:"#4e79a7",0,o,0,n);t.fillStyle=i||r,t.globalAlpha=c}else t.globalAlpha=(e.style.fillOpacity??.7)*c,t.fillStyle=r;if(t.fill(),e._pulseIntensity&&e._pulseIntensity>0&&(wc(t,e),bc(t,e)),e.style.stroke&&"none"!==e.style.stroke){t.globalAlpha=c;const o=Nn(t,e.style.stroke)||e.style.stroke,n=a||l||!e.strokeGradient||2>e.topPath.length?null:ci(t,e.strokeGradient,o,e.topPath[0][0],0,e.topPath[e.topPath.length-1][0],0);if(t.lineWidth=e.style.strokeWidth||2,t.setLineDash([]),l){let n=1/0,i=-1/0;for(const[t]of e.topPath)n=Math.min(n,t),i=Math.max(i,t);const r=t.lineWidth;for(const s of e.strokeColorBands){t.save(),t.beginPath(),t.rect(n-r,s.y,i-n+2*r,s.height),t.clip();const a=s.color??o;t.strokeStyle=Nn(t,a)||a,kc(t,e),t.stroke(),t.restore()}}else if(a){const n=Hs(e.topPath,e.rawValues,e.colorThresholds,o);for(const e of n){t.beginPath(),t.strokeStyle=Nn(t,e.color)||e.color,t.moveTo(e.path[0][0],e.path[0][1]);for(let o=1;e.path.length>o;o++)t.lineTo(e.path[o][0],e.path[o][1]);t.stroke()}}else t.strokeStyle=n||o,kc(t,e),t.stroke()}void 0!==i&&1>i&&t.restore(),o&&t.restore(),t.globalAlpha=1}},Ac=(t,e,o,n)=>{const i=e.filter(t=>"point"===t.type);if(0!==i.length){t.save();try{const e=t.globalAlpha;for(const o of i)t.beginPath(),t.arc(o.x,o.y,o.r,0,2*Math.PI),t.globalAlpha=e*(o.style.opacity??o.style.fillOpacity??1),t.fillStyle=si(t,o.style.fill,"#4e79a7"),t.fill(),o.style.stroke&&"none"!==o.style.stroke&&(t.strokeStyle=si(t,o.style.stroke,o.style.stroke),t.lineWidth=o.style.strokeWidth||1,t.stroke()),mc(t,o)}finally{t.restore()}}},Mc=new Map;function _c(t){try{if(t.path)return new Path2D(t.path);const e=`${t.symbolType??"circle"}:${Math.round(t.size)}`;let o=Mc.get(e);return o||(o=new Path2D(uo(t.symbolType,t.size)),Mc.size>256&&Mc.clear(),Mc.set(e,o)),o}catch{return null}}var Pc=(t,e)=>{const o=t.globalAlpha;for(const n of e){if("symbol"!==n.type)continue;const e=n;if(0>=e.size)continue;const i=_c(e);if(!i)continue;t.save(),t.translate(e.x,e.y),e.rotation&&t.rotate(e.rotation);const r=(e.style.opacity??1)*(e._decayOpacity??1);e.style.fill&&(t.globalAlpha=o*r*(e.style.fillOpacity??1),t.fillStyle=si(t,e.style.fill,"#4e79a7"),t.fill(i)),e.style.stroke&&"none"!==e.style.stroke&&(t.globalAlpha=o*r,t.strokeStyle=si(t,e.style.stroke,e.style.stroke),t.lineWidth=e.style.strokeWidth??1,t.stroke(i)),t.restore()}t.globalAlpha=o};function Cc(t,e,o,n,i){if(0>=e.size)return;const r=e.glyph;if(!r||!r.parts?.length)return;const s=Cn(r,e.size);if(0>=s.scale)return;const a=(e.style.opacity??1)*(e._decayOpacity??1);if(0>=a)return;const l=e=>{const o=si(t,e,e);return"string"==typeof o?o:e},c=e.color??("string"==typeof e.style.fill?e.style.fill:void 0);t.save(),t.translate(o,n),e.rotation&&t.rotate(e.rotation),t.translate(s.offsetX,s.offsetY),t.scale(s.scale,s.scale),t.globalAlpha=i*a*(e.style.fillOpacity??1);const u=Tn(r,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal");u&&e.ghostColor&&zn(t,r,c,e.accent,e.ghostColor,l),u&&(t.beginPath(),t.rect(u.x,u.y,u.width,u.height),t.clip()),zn(t,r,c,e.accent,void 0,l),t.restore()}function Rc(t,e){const{x:o,y:n,w:i,h:r}=e,{tl:s,tr:a,br:l,bl:c}=Vs(e);t.beginPath(),t.moveTo(o+s,n),t.lineTo(o+i-a,n),a>0&&t.arcTo(o+i,n,o+i,n+a,a),t.lineTo(o+i,n+r-l),l>0&&t.arcTo(o+i,n+r,o+i-l,n+r,l),t.lineTo(o+c,n+r),c>0&&t.arcTo(o,n+r,o,n+r-c,c),t.lineTo(o,n+s),s>0&&t.arcTo(o,n,o+s,n,s),t.closePath()}function Lc(t){switch(t.roundedEdge){case"bottom":return{x0:t.x,y0:t.y+t.h,x1:t.x,y1:t.y};case"right":return{x0:t.x+t.w,y0:t.y,x1:t.x,y1:t.y};case"left":return{x0:t.x,y0:t.y,x1:t.x+t.w,y1:t.y};default:return{x0:t.x,y0:t.y,x1:t.x,y1:t.y+t.h}}}var Ic=(t,e,o,n)=>{const i=e.filter(t=>"rect"===t.type);for(const e of i){if(null!=e.style.opacity&&(t.globalAlpha=e.style.opacity),e.style.icon)Tc(t,e);else if(e.cornerRadii&&qs(e.cornerRadii)){const o=si(t,e.style.fill,Nn(t,"var(--semiotic-primary, #007bff)")),n=Lc(e),i=e.fillGradient&&"string"==typeof o?ai(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null;t.fillStyle=i||o,Rc(t,e),t.fill(),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=Nn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,t.stroke())}else if(e.roundedTop&&e.roundedTop>0){const o=si(t,e.style.fill,Nn(t,"var(--semiotic-primary, #007bff)")),n=Lc(e),i=e.fillGradient&&"string"==typeof o?ai(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null;t.fillStyle=i||o;const r=Math.min(e.roundedTop,e.w/2,e.h/2);t.beginPath();const{x:s,y:a,w:l,h:c}=e;switch(e.roundedEdge){case"right":t.moveTo(s,a),t.lineTo(s+l-r,a),t.arcTo(s+l,a,s+l,a+r,r),t.lineTo(s+l,a+c-r),t.arcTo(s+l,a+c,s+l-r,a+c,r),t.lineTo(s,a+c);break;case"left":t.moveTo(s+l,a),t.lineTo(s+r,a),t.arcTo(s,a,s,a+r,r),t.lineTo(s,a+c-r),t.arcTo(s,a+c,s+r,a+c,r),t.lineTo(s+l,a+c);break;case"bottom":t.moveTo(s,a),t.lineTo(s+l,a),t.lineTo(s+l,a+c-r),t.arcTo(s+l,a+c,s+l-r,a+c,r),t.lineTo(s+r,a+c),t.arcTo(s,a+c,s,a+c-r,r);break;default:t.moveTo(s,a+c),t.lineTo(s,a+r),t.arcTo(s,a,s+r,a,r),t.lineTo(s+l-r,a),t.arcTo(s+l,a,s+l,a+r,r),t.lineTo(s+l,a+c)}t.closePath(),t.fill(),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=Nn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,t.stroke())}else{const o=si(t,e.style.fill,Nn(t,"var(--semiotic-primary, #007bff)")),n=Lc(e),i=e.fillGradient&&"string"==typeof o?ai(t,e.fillGradient,o,n.x0,n.y0,n.x1,n.y1):null;t.fillStyle=i||o,t.fillRect(e.x,e.y,e.w,e.h),e.style.stroke&&"none"!==e.style.stroke&&(t.strokeStyle=Nn(t,e.style.stroke)||e.style.stroke,t.lineWidth=e.style.strokeWidth||1,t.strokeRect(e.x,e.y,e.w,e.h))}gc(t,e),t.globalAlpha=1}};function Tc(t,e){const o=e.style.icon,n=e.style.iconPadding||2,i=Math.min(e.w,e.h)-n;if(0>=i)return;const r=e.h>e.w;if(t.save(),t.beginPath(),t.rect(e.x,e.y,e.w,e.h),t.clip(),r){const r=i+n,s=e.x+(e.w-i)/2;for(let n=e.y+e.h-i;n>=e.y-i;n-=r)t.drawImage(o,s,n,i,i)}else{const r=i+n,s=e.y+(e.h-i)/2;for(let n=e.x;e.x+e.w>n;n+=r)t.drawImage(o,n,s,i,i)}t.restore()}function $c(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>128?"#000":"#fff"}function zc(t){return Number.isInteger(t)?t+"":100>Math.abs(t)?1>Math.abs(t)?t.toPrecision(3):t.toFixed(1):t.toFixed(0)}var Dc=(t,e,o,n)=>{const i=e.filter(t=>"heatcell"===t.type);t.save();try{for(const e of i){const o=e.style;null!=o?.opacity&&(t.globalAlpha=o.opacity),t.fillStyle=e.fill,t.fillRect(e.x,e.y,e.w,e.h);const n=Math.max(0,o?.strokeWidth??1);if(n>0&&(t.strokeStyle=Nn(t,o?.stroke??"var(--semiotic-surface, #fff)"),t.lineWidth=n,t.strokeRect(e.x,e.y,e.w,e.h)),gc(t,e),t.globalAlpha=1,e.showValues&&null!=e.value){if(20>e.w||20>e.h)continue;const o=e.valueFormat?e.valueFormat(e.value):zc(e.value),n=Math.max(10,Math.min(16,.3*Math.min(e.w,e.h))),i=e.x+e.w/2,r=e.y+e.h/2;t.fillStyle=$c(e.fill),t.font=n+"px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(o,i,r)}}}finally{t.restore()}},Fc=(t,e,o,n)=>{for(const o of e){if("candlestick"!==o.type)continue;const e=o;t.save();const i=(e._decayOpacity??1)*(e.style?.opacity??1);1!==i&&(t.globalAlpha=i);const r=Nn(t,e.wickColor)||e.wickColor,s=60>n.height,a=s?Math.max(e.wickWidth,2):e.wickWidth,l=()=>{t.beginPath(),t.moveTo(e.x,e.highY),t.lineTo(e.x,e.lowY),t.strokeStyle=r,t.lineWidth=a,t.stroke()};if(s||l(),e.isRange){const o=e.dotRadius??Math.max(2,Math.min(e.bodyWidth/2,.12*n.height));t.fillStyle=r,t.beginPath(),t.arc(e.x,e.highY,o,0,2*Math.PI),t.fill(),t.beginPath(),t.arc(e.x,e.lowY,o,0,2*Math.PI),t.fill()}else if(e.bodyWidth>0){const o=Math.min(e.openY,e.closeY),n=Math.abs(e.openY-e.closeY),i=e.isUp?e.upColor:e.downColor,r=Nn(t,i)||i;t.fillStyle=r,t.fillRect(e.x-e.bodyWidth/2,o,e.bodyWidth,Math.max(n,1)),t.strokeStyle=r,t.lineWidth=1,t.strokeRect(e.x-e.bodyWidth/2,o,e.bodyWidth,Math.max(n,1))}s&&l(),t.restore()}},Ec={line:[Sc,pc,Ac],area:[Sc,Ac],stackedarea:[Sc,Ac],scatter:[Ac,Pc],bubble:[Ac,Pc],heatmap:[Dc],bar:[Ic],swarm:[Ac],waterfall:[(t,e,o,n)=>{Ic(t,e);const i=e.filter(t=>"rect"===t.type);if(2>i.length)return;const r=i[0].datum,s=r?._connectorStroke;if(s){t.save(),t.strokeStyle=Nn(t,s)||s,t.lineWidth=r?._connectorWidth??1,t.setLineDash([]);for(let e=0;i.length-1>e;e++){const n=i[e],r=i[e+1],s=n.datum,a=r.datum;if(null==s?.cumEnd||null==a?.baseline)continue;const l=o.y(s.cumEnd),c=n.x+n.w,u=r.x;t.beginPath(),t.moveTo(c,l),t.lineTo(u,l),t.stroke()}t.restore()}}],candlestick:[Fc],mixed:[Sc,pc,Ac],custom:[Sc,Ic,Dc,pc,Ac,Pc,(t,e)=>{const o=t.globalAlpha;for(const n of e)"glyph"===n.type&&Cc(t,n,n.x,n.y,o);t.globalAlpha=o},Fc]},Oc=new Set;function Bc(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}function Nc(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;Oc.has(o)||(Oc.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}function Wc(t){const{node:e,index:o,renderMode:n,fallback:i}=t,r=Bc(n,e);if(!r)return i();const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?s:(Nc(r.id,e.type??"unknown"),i())}function jc(t){const e=[];return t.nodes.forEach((o,n)=>{const i=Wc({node:o,index:n,renderMode:t.renderMode,fallback:()=>t.fallback(o,n)});null!=i&&!1!==i&&e.push({node:o,element:i})}),e}import{jsx as Yc,jsxs as Gc}from"react/jsx-runtime";import{jsx as Hc,jsxs as qc}from"react/jsx-runtime";function Vc(t){return null==t?"":"number"==typeof t?Number.isInteger(t)?t+"":t.toFixed(2):t instanceof Date?t.toLocaleString():t+""}function Xc({hover:t}){const e=t.data??{},o=e.y??e.value,n=e.x??e.time;if(void 0===o&&void 0===n){const t=Ml(e);if(null!=t.title||t.entries.length>0)return qc("div",{className:"semiotic-tooltip",style:Cl,children:[null!=t.title&&Hc("div",{style:{fontWeight:600,marginBottom:t.entries.length?2:0},children:t.title+""}),t.entries.map(t=>qc("div",{style:{opacity:.7,fontSize:11},children:[t.key,":"," ",Hc("span",{style:{fontWeight:600},children:Vc(t.value)})]},t.key))]})}return qc("div",{className:"semiotic-tooltip",style:Cl,children:[Hc("div",{style:{fontWeight:600,marginBottom:2},children:Vc(o)}),Hc("div",{style:{opacity:.7,fontSize:11},children:Vc(n)})]})}function Uc(t){const{onObservation:e,datum:o,x:n=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:l=Date.now()}=t;e&&(o?(e({type:"hover",datum:o,x:n,y:i,timestamp:l,chartType:r,chartId:s}),"focus"===a?.type&&e({type:"focus",datum:o,inputType:"touch"===a.inputType?"pointer":a.inputType,timestamp:l,chartType:r,chartId:s})):e({type:"hover-end",timestamp:l,chartType:r,chartId:s}))}function Kc(t){const{onObservation:e,datum:o,x:n=0,y:i=0,chartType:r,chartId:s,context:a,timestamp:l=Date.now()}=t;e&&(o?(e({type:"click",datum:o,x:n,y:i,timestamp:l,chartType:r,chartId:s}),"activate"===a?.type&&e({type:"activate",datum:o,inputType:a.inputType,timestamp:l,chartType:r,chartId:s})):e({type:"click-end",timestamp:l,chartType:r,chartId:s}))}Xc.ownsChrome=!0;import{useCallback as Zc}from"react";import{useCallback as Qc,useRef as Jc}from"react";function tu(t,e,o){const n=t.byGroup.get(e);let i=0,r=Math.abs(n[0].x-o.x);for(let t=1;n.length>t;t++){const e=Math.abs(n[t].x-o.x);r>e&&(r=e,i=t)}return n[i]._flatIndex}function eu(t){const e=[];for(const o of t)switch(o.type){case"point":e.push({x:o.x,y:o.y,datum:o.datum,shape:"circle",group:"_default"});break;case"symbol":if(0>=o.size)break;e.push({x:o.x,y:o.y,datum:o.datum,shape:"circle",group:"_default"});break;case"glyph":{if(0>=o.size||null==o.datum)break;const t=$n(o.glyph,o.size);e.push({x:o.x+t.centerDx,y:o.y+t.centerDy,datum:o.datum,shape:"rect",w:2*t.halfWidth,h:2*t.halfHeight,group:"_default"});break}case"line":{const t=o,n=Array.isArray(t.datum)?t.datum:[],i=t.group??"_default";for(let o=0;t.path.length>o&&n.length>o;o++)e.push({x:t.path[o][0],y:t.path[o][1],datum:n[o],shape:"circle",group:i});break}case"area":{const t=o,n=Array.isArray(t.datum)?t.datum:[],i=t.group??"_default";for(let o=0;t.topPath.length>o&&n.length>o;o++)e.push({x:t.topPath[o][0],y:t.topPath[o][1],datum:n[o],shape:"circle",group:i});break}case"rect":e.push({x:o.x+o.w/2,y:o.y+o.h/2,datum:o.datum,shape:"rect",w:o.w,h:o.h,group:o.group??"_default"});break;case"heatcell":e.push({x:o.x+o.w/2,y:o.y+o.h/2,datum:o.datum,shape:"rect",w:o.w,h:o.h,group:"_default"})}return e.sort((t,e)=>t.x-e.x||t.y-e.y),e}import{jsx as ou,jsxs as nu}from"react/jsx-runtime";var iu={top:20,right:20,bottom:30,left:40},ru=Ea;function su(t){if(t)return"x"===t.dimension?"pan-y":"y"===t.dimension?"pan-x":"none"}var au=be(me(function(t,e){const{chartType:o,runtimeMode:n,data:i,chunkThreshold:r,chunkSize:s,xAccessor:a,yAccessor:c,accessorRevision:u,colorAccessor:d,sizeAccessor:h,symbolAccessor:f,symbolMap:p,groupAccessor:y,lineDataAccessor:g,curve:m,normalize:x,baseline:v,stackOrder:w,binSize:k,valueAccessor:S,arrowOfTime:A="right",windowMode:M="sliding",windowSize:_=200,timeAccessor:P,xExtent:C,yExtent:R,extentPadding:L=.1,scalePadding:I,sizeRange:T,size:$=[500,300],responsiveWidth:z,responsiveHeight:D,margin:F,className:E,background:O,renderMode:N,lineStyle:W,pointStyle:j,areaStyle:Y,barStyle:G,waterfallStyle:H,swarmStyle:q,barColors:V,colorScheme:X,boundsAccessor:U,boundsStyle:K,y0Accessor:Z,band:Q,gradientFill:J,lineGradient:tt,semanticLineStops:et,areaGroups:ot,openAccessor:nt,highAccessor:it,lowAccessor:rt,closeAccessor:st,candlestickStyle:at,showAxes:lt=!0,axes:ct,xLabel:ut,yLabel:dt,yLabelRight:ht,xFormat:ft,yFormat:pt,axisExtent:yt,tickFormatTime:gt,tickFormatValue:mt,hoverAnnotation:bt,tooltipContent:xt,customHoverBehavior:vt,customClickBehavior:wt,onObservation:kt,annotationObservationCallback:St,chartId:At,enableHover:Mt,hoverRadius:_t=30,tooltipMode:Pt,annotations:Ct,onAnnotationActivate:Rt,autoPlaceAnnotations:Lt,svgAnnotationRules:It,showGrid:Tt,legend:$t,legendHoverBehavior:zt,legendClickBehavior:Dt,legendHighlightedCategory:Ot,legendIsolatedCategories:Bt,legendPosition:Nt,legendLayout:Wt,legendCategoryAccessor:jt,onCategoriesChange:Yt,backgroundGraphics:Gt,foregroundGraphics:Ht,canvasPreRenderers:qt,svgPreRenderers:Vt,title:Xt,categoryAccessor:Ut,brush:Kt,onBrush:Zt,decay:Qt,pulse:Jt,transition:te,animate:ee,staleness:oe,frameScheduler:ne,clock:ie,random:re,seed:ae,paused:le=!1,suspendWhenHidden:me=!0,heatmapAggregation:be,heatmapXBins:xe,heatmapYBins:ve,showValues:we,heatmapValueFormat:ke,marginalGraphics:Me,pointIdAccessor:_e,xScaleType:Pe,yScaleType:Ce,accessibleTable:Re=!0,description:Le,summary:Ie,linkedCrosshairName:Te,linkedCrosshairSourceId:$e,customLayout:ze,onLayoutError:De,layoutConfig:Fe,layoutSelection:Ee}=t,{customHoverBehavior:Oe,customClickBehavior:Be,hasClickBehavior:Ne}=function({customHoverBehavior:t,customClickBehavior:e,onObservation:o,chartId:n,chartType:i}){return{customHoverBehavior:Zc((e,r)=>{t?.(e,r),Uc({onObservation:o,datum:e?e.data||e:null,x:e?.x,y:e?.y,chartType:i,chartId:n,context:r})},[n,i,t,o]),customClickBehavior:Zc((t,r)=>{e?.(t,r),Kc({onObservation:o,datum:t?t.data||t:null,x:t?.x,y:t?.y,chartType:i,chartId:n,context:r})},[n,i,e,o]),hasClickBehavior:!(!e&&!o)}}({customHoverBehavior:vt,customClickBehavior:wt,onObservation:kt,chartId:At,chartType:"StreamXYFrame"}),We=ge().replace(/:/g,""),je=ue(!1),Ye=ue({w:-1,h:-1}),Ge=ue(!1),He=Ql({sizeProp:$,responsiveWidth:z,responsiveHeight:D,userMargin:F,marginDefault:iu,title:Xt,legend:$t,legendPosition:Nt,animate:ee,transitionProp:te,frameScheduler:ne,clock:ie,random:re,seed:ae,paused:le,suspendWhenHidden:me,themeDirtyRef:je}),qe=function(){const[t,e]=_a(!1);return Ca(()=>{e(!0)},[]),t}(),Ve=function(){const t=Pa(Ra,La,Ia);return Ma(t).current}(),{reducedMotionRef:Xe,responsiveRef:Ue,size:Ze,currentTheme:Qe,transition:Je,introEnabled:to,tableId:eo,rafRef:oo,renderFnRef:no,scheduleRender:io,frameRuntime:ro}=He;let so=He.margin;if(Me){const t=60,e={...He.margin};Me.top&&t>e.top&&(e.top=t),Me.bottom&&t>e.bottom&&(e.bottom=t),Me.left&&t>e.left&&(e.left=t),Me.right&&t>e.right&&(e.right=t),so=e}const ao=Ze[0]-so.left-so.right,lo=Ze[1]-so.top-so.bottom,co=fe(()=>B(i),[i]),uo=bt??Mt,[ho,fo]=de(0),po=ue(0),[yo,go]=de(null),mo=nc(Ht,Ze,so,yo),bo=nc(Gt,Ze,so,yo),xo=ue(null),vo=ue(null),wo=ue(void 0),[ko,So]=de(null),Ao=ue(ru.primary),Mo=ue(function(){let t=-1,e=Ea;return{resolve(o){if(!o)return Ea;const n=Fn;return n===t||(e=function(t){if(!t)return Ea;const e=getComputedStyle(t),o=e.getPropertyValue("--semiotic-border").trim(),n=e.getPropertyValue("--semiotic-text-secondary").trim(),i=e.getPropertyValue("--semiotic-bg").trim(),r=e.getPropertyValue("--semiotic-primary").trim(),s=n||e.getPropertyValue("--text-secondary").trim(),a=e.getPropertyValue("--text-primary").trim(),l=o||e.getPropertyValue("--surface-3").trim(),c=i||e.getPropertyValue("--surface-0").trim();return s||a||o||r?{axisStroke:l||Ea.axisStroke,tickText:s||Ea.tickText,crosshair:s?Oa(s,"66"):Ea.crosshair,hoverFill:c?Oa(c,"4D"):Ea.hoverFill,hoverStroke:s?Oa(s,"99"):Ea.hoverStroke,pointRing:c||Ea.pointRing,primary:r||Ea.primary,background:c||Ea.background}:Ea}(o),t=n),e},invalidate(){t=-1}}}()),_o=ue(!1),Po=un(new gn("StreamXYFrame")),[Co,Ro]=de(!1),[Lo,Io]=de([]),[To,$o]=de([]),zo="streaming"===n||["bar","swarm","waterfall"].includes(o),Do=function(t){const e=Ta(t);return function(t,e){if(Object.is(t,e))return!0;if(Array.isArray(t)&&Array.isArray(e))return za(t,e);if(!Da(t)||!Da(e))return!1;const o=Object.keys(t),n=Object.keys(e);if(o.length!==n.length)return!1;for(const n of o){if(!Object.prototype.hasOwnProperty.call(e,n))return!1;const o=t[n],i=e[n];if(!Object.is(o,i))if(Array.isArray(o)&&Array.isArray(i)){if(!za(o,i))return!1}else{if(!Da(o)||!Da(i))return!1;if(!$a(o,i))return!1}}return!0}(e.current,t)||(e.current=t),e.current}(fe(()=>({chartType:o,runtimeMode:zo?"streaming":"bounded",windowSize:_,windowMode:M,arrowOfTime:zo?A:"right",extentPadding:L,scalePadding:I,axisExtent:yt,xAccessor:a,yAccessor:c,accessorRevision:u,timeAccessor:zo?P:void 0,valueAccessor:S,colorAccessor:d,sizeAccessor:h,symbolAccessor:f,symbolMap:p,groupAccessor:y||(g?"_lineGroup":void 0),categoryAccessor:Ut,lineDataAccessor:g,xScaleType:Pe,yScaleType:Ce,xExtent:C,yExtent:R,sizeRange:T,binSize:k,normalize:x,baseline:v,stackOrder:w,boundsAccessor:U,boundsStyle:K,y0Accessor:Z,band:Q,gradientFill:Ft(J),areaGroups:ot?new Set(ot):void 0,lineGradient:Et(tt),semanticLineStops:et,openAccessor:nt,highAccessor:it,lowAccessor:rt,closeAccessor:st,candlestickStyle:at,lineStyle:W,pointStyle:j,areaStyle:Y,swarmStyle:q,waterfallStyle:H,colorScheme:X,barColors:V,barStyle:G,annotations:Ct,decay:Qt,pulse:Jt,transition:Je,introAnimation:to,staleness:oe,clock:ro.now,heatmapAggregation:be,heatmapXBins:xe,heatmapYBins:ve,showValues:we,heatmapValueFormat:ke,pointIdAccessor:_e,curve:m,themeCategorical:Qe?.colors?.categorical,themeSemantic:b(Qe),themeSequential:Qe?.colors?.sequential,themeDiverging:Qe?.colors?.diverging,customLayout:ze,onLayoutError:De,layoutConfig:Fe,layoutMargin:so}),[o,zo,_,M,A,L,I,yt,a,c,u,P,S,d,h,f,p,y,g,Ut,Pe,Ce,C,R,T,k,x,v,w,U,K,Z,Q,J,ot,tt,et,nt,it,rt,st,at,W,j,Y,q,H,X,V,G,Ct,Qt,Jt,Je,to,oe,ro.now,be,xe,ve,we,ke,_e,m,Qe,ze,De,Fe,so])),Fo=ue(null);Fo.current||(Fo.current=new an(Do));const Eo=function(t,e,o,n){const i=sc({accessor:e,onChange:o,readData:n}),r=sc([]);return i.current={accessor:e,onChange:o,readData:n},rc(()=>{const{accessor:e,onChange:o,readData:n}=i.current;if(!o||!e)return;const s=function(t,e){if(!e)return[];const o=new Set,n=[];for(const i of t){if(!i||"object"!=typeof i)continue;const t="function"==typeof e?e(i):i[e];if(null==t)continue;const r=t+"";o.has(r)||(o.add(r),n.push(r))}return n}(t.current?n(t.current):[],e);(function(t,e){if(t.length!==e.length)return!1;for(let o=0;t.length>o;o++)if(t[o]!==e[o])return!1;return!0})(s,r.current)||(r.current=s,o(s))},[t])}(Fo,jt,Yt,t=>t.getData());!function(t,e,o,n){vn(()=>{t.current?.updateConfig(e),o.current=!0,n()},[e,n,t,o])}(Fo,Do,je,io),function(t,e,o,n){const i=wn(null);vn(()=>{const r=t.current;if(!r)return;const s=e??null;i.current!==s&&(i.current=s,r.setLayoutSelection(s),r.hasCustomRestyle?r.restyleScene(s):o.current=!0,n())},[e,n,t,o])}(Fo,Ee,je,io);const Oo=ue(null);Oo.current||(Oo.current=new Ae(t=>{const e=Fo.current;e&&e.ingest(t)&&(je.current=!0,io())},{chunkThreshold:r,chunkSize:s})),he(()=>{Oo.current?.updateChunkOptions({chunkThreshold:r,chunkSize:s})},[r,s]);const Bo=pe(t=>{Oo.current?.push(t)},[]),No=pe(t=>{Oo.current?.pushMany(t)},[]),Wo=pe(()=>{Oo.current?.clear(),Fo.current?.clear(),je.current=!0,io()},[io]);ye(e,()=>({push:Bo,pushMany:No,remove:t=>{Oo.current?.flush();const e=Fo.current?.remove(t)??[];return e.length>0&&(xo.current&&e.some(t=>t===xo.current?.data)&&(xo.current=null,So(null)),je.current=!0,io()),e},update:(t,e)=>{Oo.current?.flush();const o=Fo.current?.update(t,e)??[];return o.length>0&&(je.current=!0,io()),o},clear:Wo,getData:()=>(Oo.current?.flush(),Fo.current?.getData()??[]),getScales:()=>Fo.current?.scales??null,getExtents:()=>Fo.current?.getExtents()??null,getCustomLayout:()=>Fo.current?.lastCustomLayoutResult??null,getLayoutFailure:()=>Fo.current?.lastCustomLayoutFailure??null}),[Bo,No,Wo,io]),he(()=>{if(i){if(g&&co.length>0&&"object"==typeof co[0]&&null!==co[0]){const t="string"==typeof g?g:"coordinates";if(Array.isArray(co[0][t])){const e=[];for(const o of co){const n=o[t];if(Array.isArray(n)){const t=o.label||o.id||o.key;if(null!=t)for(const o of n)e.push({...o,_lineGroup:t});else for(const t of n)e.push(t)}}return void Oo.current?.setBoundedData(e)}}Oo.current?.setBoundedData(co)}},[i,co,g]);const{canvasRef:jo,interactionCanvasRef:Yo}=function(t,e){return function(t){const{cancelRender:e,dirtyRef:o,frameRuntime:n,manageFrameRuntime:i,scheduleRender:r}=t,s=tc(null),a=tc(null),l=tc(!1);return function(t){const{hydrated:e,wasHydratingFromSSR:o,storeRef:n,dirtyRef:i,renderFnRef:r,cancelRender:s,cleanup:a}=t;Ca(()=>{const t=n.current;e&&o&&t?.cancelIntroAnimation?.(),!o&&t?.sceneNodes&&t.sceneNodes.length>0&&t?.markStylePaintPending?t.markStylePaintPending():i.current=!0,s?.(),r.current()},[e,o]);const l=Ma(a);l.current=a,Sa(()=>()=>l.current?.(),[])}({hydrated:t.hydrated,wasHydratingFromSSR:t.wasHydratingFromSSR,storeRef:t.storeRef,dirtyRef:t.dirtyRef,renderFnRef:t.renderFnRef,cancelRender:t.cancelRender,cleanup:t.cleanup}),Jl(()=>{if(!1!==i)return n.subscribe(()=>{n.isActive?(o.current=!0,r()):e()})},[e,o,n,i,r]),Jl(()=>{!l.current&&(l.current=!0,t.skipInitialCanvasPaintInvalidation)||(t.dirtyRef.current=!0,t.scheduleRender())},t.canvasPaintDependencies),{canvasRef:s,interactionCanvasRef:a}}({...e,renderFnRef:t.renderFnRef,scheduleRender:t.scheduleRender,cancelRender:t.cancelRender,frameRuntime:t.frameRuntime})}(He,{storeRef:Fo,dirtyRef:je,hydrated:qe,wasHydratingFromSSR:Ve,cleanup:()=>Oo.current?.clear(),canvasPaintDependencies:[o,ao,lo,lt,O,Gt,W,N,qt,io]}),{hoverHandlerRef:Go,hoverLeaveRef:Ho,onPointerMove:qo,onPointerLeave:Vo}=He;Go.current=t=>{if(!uo)return;const e=jo.current;if(!e)return;const n=e.getBoundingClientRect(),i=t.clientX-n.left-so.left,r=t.clientY-n.top-so.top;if(0>i||i>ao||0>r||r>lo)return void(xo.current&&(xo.current=null,vo.current=null,So(null),Oe&&(Oe(null),je.current=!0),io()));const s=Fo.current;if(!s||0===s.scene.length)return;const l=ml(_t,t.pointerType),c=fi(s.scene,i,r,l,s.quadtree,s.maxPointRadius),u="multi"===Pt,d=()=>{xo.current&&(xo.current=null,vo.current=null,So(null),Oe&&Oe(null),io())};if(!c&&!u)return void d();const h=u||!c?i:c.x,f=u||!c?r:c.y,p=c?.datum?Ke(c.datum,s.resolvedRibbons):{},y=s.scales?.x?.invert,g="function"==typeof y?y(h):void 0;let m=xl(p,h,f,null!=g?{xValue:g,xPx:h}:void 0);if(u&&s.scene.length>0&&s.scales){const t=function(t,e,o=30){const n=[];for(const i of t)if("line"===i.type){const t=i;if(2>t.path.length)continue;const r=pi(hi(t.path,t.curve),e,o);if(null===r)continue;const s=Ai(t.path,e);n.push({node:i,datum:Array.isArray(t.datum)&&t.datum[s]?t.datum[s]:t.datum,x:t.path[s][0],y:r,group:t.group,color:t.style.stroke})}else if("area"===i.type){const t=i;if(!1===t.interactive)continue;if(2>t.topPath.length)continue;const r=hi(t.topPath,t.curve),s=hi(t.bottomPath,t.curve),a=pi(r,e,o);if(null===a)continue;const l=pi(s,e,o),c=Ai(t.topPath,e);n.push({node:i,datum:Array.isArray(t.datum)&&t.datum[c]?t.datum[c]:t.datum,x:t.topPath[c][0],y:a,y0:l??void 0,group:t.group,color:"string"==typeof t.style.stroke?t.style.stroke:"string"==typeof t.style.fill?t.style.fill:void 0})}return n}(s.scene,h,Math.max(l,ao));if(t.length>0){const e=s.scales.y.invert,n=Ao.current,i=y?y(h):h;if(c)m.xValue=i,m.xPx=h;else{const t={xValue:i};"string"==typeof a&&(t[a]=i),m=xl(t,h,f,{xValue:i,xPx:h})}m.allSeries=t.map(t=>{const i=e?e(t.y):t.y,r=null!=t.y0?e?e(t.y0):t.y0:void 0;return{group:t.group||"",value:"stackedarea"===o&&null!=r?i-r:i,valuePx:t.y,color:t.color||n,datum:Ke(t.datum,s.resolvedRibbons)}})}}c||m.allSeries?.length?(xo.current=m,vo.current=c?.node??null,So(m),Oe&&(Oe(m),je.current=!0),io()):d()},Ho.current=()=>{xo.current&&(xo.current=null,vo.current=null,So(null),Oe&&(Oe(null),je.current=!0),io())};const Xo=ue(()=>{});Xo.current=t=>{if(l(t.target))return;if(!Be)return;const e=jo.current;if(!e)return;const o=e.getBoundingClientRect(),n=t.clientX-o.left-so.left,i=t.clientY-o.top-so.top;if(0>n||n>ao||0>i||i>lo)return void Be(null);const r=Fo.current;if(!r||0===r.scene.length)return void Be(null);const s=ml(_t,wo.current),a=fi(r.scene,n,i,s,r.quadtree,r.maxPointRadius);if(!a)return void Be(null);const c=a.datum||{},u=r.scales?.x?.invert,d="function"==typeof u?u(a.x):void 0;var h;Be(xl(c,a.x,a.y,null!=d?{xValue:d,xPx:a.x}:void 0),{type:"activate",inputType:(h=wo.current,"touch"===h?"touch":"pointer")})};const Uo=pe(t=>Xo.current(t),[]),{kbFocusIndexRef:Ko,focusedNavPointRef:Zo,onKeyDown:Qo}=(Jo={storeRef:Fo,hoverRef:xo,hoveredNodeRef:vo,setHoverPoint:So,customHoverBehavior:Oe,customClickBehavior:Be,scheduleRender:io},function({storeRef:t,hoverRef:e,hoveredNodeRef:o,setHoverPoint:n,customHoverBehavior:i,customClickBehavior:r,scheduleRender:s,extractPoints:a,toHover:l}){const c=Jc(-1),u=Jc(null),d=Jc(null),h=Qc(h=>{if(function(t){const e=t.target;return e instanceof Element&&e!==t.currentTarget&&null!=e.closest("button, a[href], input, select, textarea, summary, [contenteditable='true'], [role='button'], [role='link'], [role='checkbox'], [role='radio'], [role='switch']")}(h))return;const f=t.current;if(!f)return;const p=()=>{c.current=-1,u.current=null,e.current=null,o&&(o.current=null),n(null),i(null),s()};if(0===f.scene.length)return void(0>c.current||p());let y;if(d.current?.version===f.version)y=d.current.graph;else{const t=a(f.scene);if(0===t.length)return void(0>c.current||p());y=function(t){const e=new Map;for(const o of t){const t=o.group??"_default";let n=e.get(t);n||(n=[],e.set(t,n)),n.push(o)}for(const t of e.values()){t.sort((t,e)=>t.x-e.x||t.y-e.y);for(let e=0;t.length>e;e++)t[e]._groupIndex=e}const o=Array.from(e.keys()).sort((t,o)=>{const n=e.get(t),i=e.get(o);return(n.length>0?n[0].y:0)-(i.length>0?i[0].y:0)}),n=Array.from(e.values()).flat();n.sort((t,e)=>t.x-e.x||t.y-e.y);const i=new Map;for(let t=0;n.length>t;t++){n[t]._flatIndex=t;const e=n[t].datum?.id;null!=e&&i.set(e+"",t)}return{flat:n,groups:o,byGroup:e,idToIdx:i}}(t),d.current={version:f.version,graph:y}}let g=c.current;if(y.flat.length>g||(p(),g=-1),("Enter"===h.key||" "===h.key)&&g>=0)return h.preventDefault(),void r(l(y.flat[g],f),{type:"activate",inputType:"keyboard"});if(0>g){if("Escape"===h.key)return;if(!["ArrowRight","ArrowLeft","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(h.key))return;h.preventDefault(),c.current=0;const t=y.flat[0];u.current=t;const o=l(t,f);return e.current=o,n(o),i(o,{type:"focus",inputType:"keyboard"}),void s()}const m=function(t,e,o){const{group:n,indexInGroup:i}=e,r=o.byGroup.get(n);switch(t){case"ArrowRight":return r.length-1>i?r[i+1]._flatIndex:e.flatIndex;case"ArrowLeft":return i>0?r[i-1]._flatIndex:e.flatIndex;case"ArrowDown":{const t=o.groups.indexOf(n);return o.groups.length-1>t?tu(o,o.groups[t+1],r[i]):e.flatIndex}case"ArrowUp":{const t=o.groups.indexOf(n);return t>0?tu(o,o.groups[t-1],r[i]):e.flatIndex}case"PageDown":return Math.min(e.flatIndex+Math.max(1,Math.floor(.1*o.flat.length)),o.flat.length-1);case"PageUp":return Math.max(e.flatIndex-Math.max(1,Math.floor(.1*o.flat.length)),0);case"Home":return 0;case"End":return o.flat.length-1;case"Escape":return-1;default:return null}}(h.key,function(t,e){if(0===t.flat.length)return{flatIndex:-1,group:"_default",indexInGroup:-1};const o=Math.max(0,Math.min(e,t.flat.length-1)),n=t.flat[o];return{flatIndex:o,group:n.group??"_default",indexInGroup:n._groupIndex??0}}(y,g),y);if(null===m)return;if(h.preventDefault(),0>m)return void p();c.current=m;const b=y.flat[m];u.current=b;const x=l(b,f);e.current=x,n(x),i(x,{type:"focus",inputType:"keyboard"}),s()},[r,i,a,e,o,s,n,t,l]);return{kbFocusIndexRef:c,focusedNavPointRef:u,onKeyDown:h}}({...Jo,extractPoints:eu,toHover:(t,e)=>function(t){return{data:t.datum||{},x:t.x,y:t.y,__semioticHoverData:!0}}({...t,datum:Ke(t.datum,e.resolvedRibbons)})}));var Jo;const tn=pe(t=>{wo.current=t.pointerType,Ko.current=-1,Zo.current=null,qo(t)},[Zo,Ko,qo]),en=pe(t=>{wo.current="mouse",Ko.current=-1,Zo.current=null,qo({clientX:t.clientX,clientY:t.clientY,pointerType:"mouse"})},[Zo,Ko,qo]),on=pe(t=>{wo.current=t.pointerType},[]);no.current=()=>{if(oo.current=null,!ro.isActive)return;const t=jo.current,e=Yo.current;if(!t||!e)return;const n=Fo.current;if(!n)return;const i=ro.now(),r=n.advanceTransition(Xe.current?i+1e6:i),s=!Xe.current&&r,l=Ye.current.w!==ao||Ye.current.h!==lo,u=je.current||r||l,d=n.consumeStylePaintPending();let h=!1;const f=n.getLastUpdateResult(),p=Po.current.beforeCompute(f,s);!u||s&&!l||(n.computeScene({width:ao,height:lo}),Ye.current={w:ao,h:lo},h=!0,Eo()),Po.current.afterCompute(p,h,l);const y=function(t,e,o,n){const i=n.current,r=!0===t.lastCustomLayoutFailure?.preservedLastGoodScene,s=!r&&t.hasActivePulsesAt(e),a=!(o||r||!s&&!i)&&t.refreshPulse(e);return n.current=s,{changed:a,pending:s}}(n,i,h,Ge),g=function(){if("undefined"==typeof window)return 1;const t=window.devicePixelRatio||1,e=function(){if("undefined"==typeof window)return!1;const t="function"==typeof window.matchMedia&&window.matchMedia("(pointer: coarse)").matches,e=768>Math.min(window.innerWidth||1/0,window.innerHeight||1/0);return t||e}()?2:3;return Math.max(1,Math.min(t,e))}(),m=Mo.current.resolve(t);Ao.current=m.primary;const b=Ri(oe,n.lastIngestTime>0?i-n.lastIngestTime:0),x=oe&&b.isStale;if(u||d||y.changed){const e=ic(t,Ze,so,g);if(e){if(e.clearRect(-so.left,-so.top,Ze[0],Ze[1]),oe&&1>b.alpha&&(e.globalAlpha=b.alpha),function(t,e){const{background:o,hasBackgroundGraphics:n=!1,themeBackground:i="",x:r=0,y:s=0,width:a,height:l}=e,c=Fa({background:o,hasBackgroundGraphics:n,themeBackground:i});if(!c)return!1;const u=Nn(t,c);u&&(t.fillStyle=u,t.fillRect(r,s,a,l))}(e,{background:O,hasBackgroundGraphics:!!Gt,themeBackground:m.background,x:-so.left,y:-so.top,width:Ze[0],height:Ze[1]}),e.save(),"function"==typeof e.rect&&(e.beginPath(),e.rect(0,0,ao,lo),e.clip()),qt&&n.scales)for(const t of qt)e.save(),t(e,n.scene,n.scales,{width:ao,height:lo}),e.restore();const t=ze?Ec.custom:Ec[o];!function(t){const{context:e,nodes:o,renderMode:n,pixelRatio:i,paintBuiltIn:r}=t;if(!n||"sketchy"===n)return void r(o);let s=[];const a=()=>{s.length&&(r(s),s=[])};for(const t of o){const o=Bc(n,t);if(!o){s.push(t);continue}let l;a(),e.save();try{l=o.drawCanvas({context:e,node:t,style:t.style??{},pixelRatio:i})}finally{e.restore()}l||(Nc(o.id,t.type??"unknown"),r([t]))}a()}({context:e,nodes:n.scene,renderMode:N,pixelRatio:g,paintBuiltIn:o=>{if(t&&n.scales)for(const i of t)i(e,o,n.scales,{width:ao,height:lo})}}),e.restore(),oe&&1>b.alpha&&(e.globalAlpha=1)}}const v=!!(uo&&xo.current&&n.scales),w=!!(vo.current&&Array.isArray(bt)&&bt.some(t=>t&&"object"==typeof t&&"highlight"===t.type)),k=v||w;if(k||_o.current){const t=ic(e,Ze,so,g);if(t&&(t.clearRect(-so.left,-so.top,Ze[0],Ze[1]),v&&xo.current&&function(t,e,o,n,i,r,s){if(!1===i.crosshair)return;const a=e.allSeries,l=a&&a.length>0,c=e.xPx??e.x;t.save();const u="object"==typeof i.crosshair?i.crosshair:{};if(t.strokeStyle=u.stroke||s.crosshair,t.lineWidth=u.strokeWidth||1,t.setLineDash(u.strokeDasharray?u.strokeDasharray.split(/[\s,]+/).map(Number):[4,4]),t.beginPath(),t.moveTo(l?c:e.x,0),t.lineTo(l?c:e.x,n),t.stroke(),l||(t.beginPath(),t.moveTo(0,e.y),t.lineTo(o,e.y),t.stroke()),t.restore(),l){t.lineWidth=2,t.strokeStyle=s.pointRing;for(const e of a)null!=e.valuePx&&(t.beginPath(),t.arc(c,e.valuePx,4,0,2*Math.PI),t.fillStyle=e.color||s.primary,t.fill(),t.stroke())}else{const o=i.pointColor||function(t){if(!t)return null;if("heatcell"===t.type)return t.fill||null;if("candlestick"===t.type)return t.isUp?t.upColor:t.downColor;const{style:e}=t;if(!e)return null;const o="string"==typeof e.fill?e.fill:null;return"line"===t.type||"area"===t.type?e.stroke||o||null:o||e.stroke||null}(r)||s.primary;t.beginPath(),t.arc(e.x,e.y,4,0,2*Math.PI),t.fillStyle=o,t.fill(),t.strokeStyle=s.pointRing,t.lineWidth=2,t.stroke()}}(t,xo.current,ao,lo,"object"==typeof uo?uo:{},vo.current,m),w&&vo.current&&Array.isArray(bt))){const e=bt.find(t=>t&&"object"==typeof t&&"highlight"===t.type);e&&function(t,e,o,n,i){if(!o)return;const r="group"in o?o.group:void 0;if(void 0!==r)for(const o of e){if("line"!==o.type)continue;if(o.group!==r)continue;if(2>o.path.length)continue;const e="function"==typeof n.style?o.datum?n.style(o.datum):{}:n.style||{};t.save(),t.beginPath(),t.moveTo(o.path[0][0],o.path[0][1]);for(let e=1;o.path.length>e;e++)t.lineTo(o.path[e][0],o.path[e][1]);t.strokeStyle=e.stroke||o.style.stroke||i.primary,t.lineWidth=e.strokeWidth||(o.style.strokeWidth||2)+2,t.globalAlpha=e.opacity??1,t.stroke(),t.restore()}}(t,n.scene,vo.current,e,m)}_o.current=k}u&&t&&t.setAttribute("aria-label",Za(n.scene,o+" chart"));const S=je.current;if(je.current=S&&s&&!h,S&&n.scales){const t=t=>"object"==typeof t&&null!==t&&"function"==typeof t.valueOf?t.valueOf():t;if((!yo||t(yo.x.domain()[0])!==t(n.scales.x.domain()[0])||t(yo.x.domain()[1])!==t(n.scales.x.domain()[1])||t(yo.y.domain()[0])!==t(n.scales.y.domain()[0])||t(yo.y.domain()[1])!==t(n.scales.y.domain()[1])||yo.x.range()[0]!==n.scales.x.range()[0]||yo.x.range()[1]!==n.scales.x.range()[1]||yo.y.range()[0]!==n.scales.y.range()[0]||yo.y.range()[1]!==n.scales.y.range()[1])&&go(n.scales),Me){const t=n.getData(),e="function"==typeof a?a:t=>t[a||"x"],o="function"==typeof c?c:t=>t[c||"y"];Io(t.map(t=>e(t)).filter(t=>"number"==typeof t&&isFinite(t))),$o(t.map(t=>o(t)).filter(t=>"number"==typeof t&&isFinite(t)))}}!((Ct&&Ct.length>0||ze)&&(h||s))||!h&&33>i-po.current||(fo(t=>t+1),po.current=i),oe?.showBadge&&Ro(!!x),(s||null!=n.activeTransition||y.pending)&&io()},function(t,e,o,n,i,r){const s=_i("fresh");Mi(()=>{if(!t)return;const a=setInterval(()=>{const a=e.current;if(!a||0===a.lastIngestTime)return;const l="undefined"!=typeof performance?performance.now():Date.now(),c=Ri(t,l-a.lastIngestTime);c.band===s.current&&c.isStale===i||(s.current=c.band,c.isStale!==i&&r(c.isStale),o.current=!0,n())},1e3);return()=>clearInterval(a)},[t,i,n,e,r,o])}(oe,Fo,je,io,Co,Ro);const nn=fe(()=>{if(ft||gt)return;const t=Fo.current;return t?.xIsDate&&yo?uc(yo.x.domain()):void 0},[ft,gt,yo]),rn=ft||gt||nn,sn=uo&&ko?xt?xt(ko):ou(Xc,{hover:ko}):null,ln=sn?ou($l,{x:ko.x,y:ko.y,containerWidth:ao,containerHeight:lo,margin:so,className:"stream-frame-tooltip",children:sn}):null,cn=Zo.current,dn=ou(yl,{active:Ko.current>=0,hoverPoint:ko,margin:so,size:Ze,shape:cn?.shape,width:cn?.w,height:cn?.h}),hn=ac(a,P,"__semiotic_resolvedX","__semiotic_resolvedTime"),fn=ac(c,S,"__semiotic_resolvedY","__semiotic_resolvedValue"),pn=hn.key,yn=fn.key,bn=function(t,e,o){return n=>{if(!n||!o||!t.fn&&!e.fn)return n;let i=!1;const r=n.map(o=>{const n=t.fn&&t.key&&!(t.key in o),r=e.fn&&e.key&&!(e.key in o);if(!n&&!r)return o;i=!0;const s={...o};return n&&(s[t.key]=t.fn(o)),r&&(s[e.key]=e.fn(o)),s});return i?r:n}}(hn,fn,Ct&&Ct.length>0||!1);if(ka||!qe&&Ve){const t=Fo.current;t&&i&&(t.ingest({inserts:co,bounded:!0}),t.computeScene({width:ao,height:lo}));const e=t?.scene??[],o=t?.scales??null,n=nc(Ht,Ze,so,o),r=nc(Gt,Ze,so,o),s=rn||(()=>{if(t?.xIsDate&&o)return uc(o.x.domain())})();return nu("div",{ref:Ue,className:"stream-xy-frame"+(E?" "+E:""),role:"img","aria-label":Le||("string"==typeof Xt?Xt:"XY chart"),style:{position:"relative",width:z?"100%":Ze[0],height:D?"100%":Ze[1]},children:[ou(dl,{summary:Ie}),nu("svg",{xmlns:"http://www.w3.org/2000/svg",width:Ze[0],height:Ze[1],style:{position:"absolute",left:0,top:0},children:[ou("g",{transform:`translate(${so.left},${so.top})`,children:r}),nu("g",{transform:`translate(${so.left},${so.top})`,children:[O&&ou("rect",{x:0,y:0,width:ao,height:lo,fill:O}),Vt&&o&&Vt.map((t,n)=>ou(ce.Fragment,{children:t(e,o,{width:ao,height:lo})},"svgpre-"+n)),e.map((t,e)=>Wc({node:t,index:e,renderMode:N,fallback:()=>wa(t,e,We)})).filter(Boolean)]})]}),ou(Ns,{width:ao,height:lo,totalWidth:Ze[0],totalHeight:Ze[1],margin:so,scales:o,showAxes:lt,axes:ct,xLabel:ut,yLabel:dt,yLabelRight:ht,xFormat:s,yFormat:pt||mt,axisExtent:yt,showGrid:Tt,title:Xt,legend:$t,legendHoverBehavior:zt,legendClickBehavior:Dt,legendHighlightedCategory:Ot,legendIsolatedCategories:Bt,legendPosition:Nt,legendLayout:Wt,foregroundGraphics:xn(n,se(Fo.current?.customLayoutOverlays,Ee??null)),marginalGraphics:Me,xValues:[],yValues:[],annotations:Ct,onAnnotationActivate:Rt,onObservation:St??kt,chartId:At,chartType:"StreamXYFrame",autoPlaceAnnotations:Lt,svgAnnotationRules:It,annotationFrame:0,xAccessor:pn,yAccessor:yn,annotationData:bn(Fo.current?.getData()),pointNodes:dc(Fo.current?.scene),curve:"string"==typeof m?m:void 0,linkedCrosshairName:Te,linkedCrosshairSourceId:$e})]})}return nu("div",{ref:Ue,className:"stream-xy-frame"+(E?" "+E:""),role:"group","aria-label":Le||("string"==typeof Xt?Xt:"XY chart"),tabIndex:0,style:{position:"relative",width:z?"100%":Ze[0],height:D?"100%":Ze[1],overflow:"visible",touchAction:su(Kt)},onKeyDown:Qo,children:["production"!==process.env.NODE_ENV&&Fo.current&&ou(mn,{store:Fo.current,diagnostics:Po.current}),Re&&ou(hl,{tableId:eo}),Re&&ou(ul,{scene:Fo.current?.scene??[],chartType:o+" chart",tableId:eo,chartTitle:"string"==typeof Xt?Xt:void 0}),ou(dl,{summary:Ie}),ou(Ha,{hoverPoint:ko}),nu("div",{role:"img","aria-label":Le||("string"==typeof Xt?Xt:"XY chart"),style:{position:"relative",width:"100%",height:"100%"},onPointerMove:uo?tn:void 0,onMouseMove:uo?en:void 0,onPointerLeave:uo?Vo:void 0,onMouseLeave:uo?Vo:void 0,onPointerDown:uo||Ne?on:void 0,onClick:Ne?Uo:void 0,children:[ou(oc,{size:Ze,margin:so,children:bo}),ou(Es,{width:ao,height:lo,totalWidth:Ze[0],totalHeight:Ze[1],margin:so,scales:yo,showAxes:lt,axes:ct,showGrid:Tt,xFormat:rn,yFormat:pt||mt,axisExtent:yt}),ou("canvas",{ref:jo,"aria-label":Za(Fo.current?.scene??[],o+" chart"),style:{position:"absolute",left:0,top:0}}),ou("canvas",{ref:Yo,style:{position:"absolute",left:0,top:0,pointerEvents:"none"}}),ou(Ns,{width:ao,height:lo,totalWidth:Ze[0],totalHeight:Ze[1],margin:so,scales:yo,showAxes:lt,axes:ct,xLabel:ut,yLabel:dt,yLabelRight:ht,xFormat:rn,yFormat:pt||mt,axisExtent:yt,showGrid:Tt,title:Xt,legend:$t,legendHoverBehavior:zt,legendClickBehavior:Dt,legendHighlightedCategory:Ot,legendIsolatedCategories:Bt,legendPosition:Nt,legendLayout:Wt,foregroundGraphics:xn(mo,se(Fo.current?.customLayoutOverlays,Ee??null)),marginalGraphics:Me,xValues:Lo,yValues:To,annotations:Ct,onAnnotationActivate:Rt,onObservation:St??kt,chartId:At,chartType:"StreamXYFrame",autoPlaceAnnotations:Lt,svgAnnotationRules:It,annotationFrame:ho,xAccessor:pn,yAccessor:yn,annotationData:bn(Fo.current?.getData()),pointNodes:dc(Fo.current?.scene),curve:"string"==typeof m?m:void 0,underlayRendered:!0,canvasObscuresUnderlay:!!Fa({background:O,hasBackgroundGraphics:!!Gt,themeBackground:Qe?.colors.background}),linkedCrosshairName:Te,linkedCrosshairSourceId:$e}),(Kt||Zt)&&ou(Se,{width:ao,height:lo,totalWidth:Ze[0],totalHeight:Ze[1],margin:so,dimension:Kt?.dimension??"xy",scales:yo,onBrush:Zt??(()=>{}),binSize:k,snap:Kt?.snap,binBoundaries:Kt?.binBoundaries??("bar"===o?Fo.current?.getBinBoundaries():void 0),snapDuring:Kt?.snapDuring,streaming:"streaming"===n}),oe?.showBadge&&ou(Ii,{isStale:Co,position:oe.badgePosition}),dn,ln]})]})}));au.displayName="StreamXYFrame";var lu=au;import*as cu from"react";import{jsx as uu,jsxs as du}from"react/jsx-runtime";function hu({componentName:t,message:e,diagnosticHint:o,width:n,height:i}){return uu("div",{role:"alert",style:{width:n,height:Math.max(i,120),display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed rgba(128, 128, 128, 0.4)",borderRadius:8,background:"rgba(128, 128, 128, 0.04)",padding:24,boxSizing:"border-box"},children:du("div",{style:{textAlign:"center",maxWidth:400},children:[uu("div",{style:{fontSize:13,fontWeight:600,color:"rgba(128, 128, 128, 0.7)",marginBottom:6,fontFamily:"monospace"},children:t}),uu("div",{style:{fontSize:14,color:"rgba(128, 128, 128, 0.9)",lineHeight:1.5},children:e}),o&&uu("div",{"data-testid":"semiotic-diagnostic-hint",style:{marginTop:10,padding:"8px 12px",background:"rgba(128, 128, 128, 0.06)",borderRadius:4,fontSize:12,color:"rgba(128, 128, 128, 0.8)",fontFamily:"monospace",textAlign:"left",whiteSpace:"pre-wrap",lineHeight:1.6},children:o})]})})}import{jsx as fu}from"react/jsx-runtime";var pu=class extends cu.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t,e){this.props.onError?.(t,e)}render(){if(this.state.error){const{fallback:t}=this.props,e=this.state.error;return"function"==typeof t?t(e):void 0!==t?t:fu(hu,{componentName:"ChartErrorBoundary",message:e.message||"An unexpected error occurred while rendering this chart.",width:600,height:400})}return this.props.children}};import{jsx as yu}from"react/jsx-runtime";function gu({componentName:t,width:e,height:o,children:n}){return yu(pu,{fallback:n=>yu(hu,{componentName:t,message:n.message,width:e,height:o}),children:n})}"undefined"!=typeof process&&process;var mu={display:"flex",alignItems:"center",justifyContent:"center",color:"var(--semiotic-text-secondary, #666)",fontSize:13,fontFamily:"inherit",border:"1px dashed var(--semiotic-border, #ddd)",borderRadius:4,boxSizing:"border-box"},bu={background:"var(--semiotic-border, #e0e0e0)",borderRadius:2};import{useMemo as xu,useRef as vu}from"react";import{useMemo as wu,useCallback as ku,useState as Su,useId as Au,useEffect as Mu,useRef as _u}from"react";import{createContext as Pu,useContext as Cu,useMemo as Ru}from"react";import{jsx as Lu}from"react/jsx-runtime";var Iu=Pu(null);function Tu(){return Cu(Iu)}import{useId as $u,useMemo as zu,useCallback as Du}from"react";function Fu(t){const e=[];for(const[o,n]of Object.entries(t.fields))if("point"===n.type)e.push(t=>n.values.has(t[o]));else{const[t,i]=n.range;e.push(e=>{const n=e[o];return n>=t&&i>=n})}return t=>e.every(e=>e(t))}function Eu(t,e){let o=t.get(e);return o||(o={name:e,resolution:"union",clauses:new Map},t.set(e,o)),o}function Ou(t,e){if(t.type!==e.type)return!1;if("interval"===t.type&&"interval"===e.type)return t.range[0]===e.range[0]&&t.range[1]===e.range[1];if("point"===t.type&&"point"===e.type){if(t.values.size!==e.values.size)return!1;for(const o of t.values)if(!e.values.has(o))return!1;return!0}return!1}var[Bu,Nu]=s(t=>({selections:new Map,setClause(e,o){t(t=>{const n=t.selections.get(e),i=n?.clauses.get(o.clientId);if(i&&function(t,e){if(t.clientId!==e.clientId||t.type!==e.type)return!1;const o=Object.entries(t.fields);if(o.length!==function(t){let e=0;for(const o in t)e++;return e}(e.fields))return!1;for(const[t,n]of o){const o=e.fields[t];if(!o||!Ou(n,o))return!1}return!0}(i,o))return{};const r=new Map(t.selections),s=Eu(r,e),a=new Map(s.clauses);return a.set(o.clientId,o),r.set(e,{...s,clauses:a}),{selections:r}})},clearClause(e,o){t(t=>{const n=t.selections.get(e);if(!n||!n.clauses.has(o))return{};const i=new Map(t.selections),r=new Map(n.clauses);return r.delete(o),i.set(e,{...n,clauses:r}),{selections:i}})},setResolution(e,o){t(t=>{const n=t.selections.get(e);if(n?.resolution===o)return{};const i=new Map(t.selections),r=Eu(i,e);return i.set(e,{...r,resolution:o}),{selections:i}})},clearSelection(e){t(t=>{const o=t.selections.get(e);if(!o||0===o.clauses.size)return{};const n=new Map(t.selections);return n.set(e,{...o,clauses:new Map}),{selections:n}})}}));function Wu(t){const e=$u(),o=t.clientId||e,{name:n}=t,i=Nu(t=>t.selections.get(n)),r=Nu(t=>t.setClause),s=Nu(t=>t.clearClause),a=zu(()=>!!i&&i.clauses.size>0,[i]);return{predicate:zu(()=>i&&0!==i.clauses.size?function(t,e){const o=[];for(const[n,i]of t.clauses)"crossfilter"===t.resolution&&n===e||o.push(Fu(i));return 0===o.length?()=>!0:"intersect"===t.resolution?t=>o.every(e=>e(t)):t=>o.some(e=>e(t))}(i,o):()=>!0,[i,o]),isActive:a,selectPoints:Du(t=>{const e={};let i=!1;for(const[o,n]of Object.entries(t))e[o]={type:"point",values:new Set(n)},i=!0;i&&r(n,{clientId:o,type:"point",fields:e})},[o,n,r]),selectInterval:Du(t=>{const e={};let i=!1;for(const[o,n]of Object.entries(t))e[o]={type:"interval",range:n},i=!0;i&&r(n,{clientId:o,type:"interval",fields:e})},[o,n,r]),clear:Du(()=>{s(n,o)},[s,n,o]),clientId:o}}import*as ju from"react";import{jsx as Yu,jsxs as Gu}from"react/jsx-runtime";function Hu(){return _(t=>t.theme)}function qu(t,e,o){const n=t.xValue??e?.[o];if(null==n)return null;const i=Number(n);return Number.isFinite(i)?i:null}function Vu(t){let e=t.data||t.datum||t;return Array.isArray(e)&&(e=e[0]),null!=t.xValue&&e&&"object"==typeof e&&!Array.isArray(e)&&null==e.xValue?{...e,xValue:t.xValue}:e||{}}function Xu(t){if(!t)return!1;for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1}ju.createContext(void 0);import{useMemo as Uu,useCallback as Ku,useState as Zu}from"react";import{createContext as Qu,useContext as Ju,useEffect as td,useId as ed,useLayoutEffect as od,useMemo as nd,useRef as id,useState as rd,useCallback as sd}from"react";import{jsx as ad,jsxs as ld}from"react/jsx-runtime";var cd=Qu(!1);Qu(!1);var ud=Qu(null),dd="undefined"==typeof window?td:od;function hd({data:t,colorBy:e,colorScale:o,showLegend:n,legendPosition:i="right",userMargin:r,defaults:s={top:50,bottom:60,left:70,right:40},categories:a,additionalLegend:l,chartWidth:c,legendLayout:u,hasTitle:d=!1,axisChrome:h}){const f=Ju(cd),p=null!==Ju(ud),y=void 0!==n?n:!f&&!!e,g=!!e&&(y||p),m=Uu(()=>{if(!g)return[];if(void 0!==a)return a;const o=new Set;for(const n of t){const t="function"==typeof e?e(n):n[e];null!=t&&o.add(t+"")}return Array.from(o)},[a,e,t,g]);!function(t){const e=Ju(ud),o=ed(),n=function(t){const e=new Set,o=[];for(const n of t)e.has(n)||(e.add(n),o.push(n));return o}(t),i=id([]);(function(t,e){if(t.length!==e.length)return!1;for(let o=0;t.length>o;o++)if(t[o]!==e[o])return!1;return!0})(i.current,n)||(i.current=n);const r=i.current;dd(()=>{if(e)return()=>e.unregisterCategories(o)},[e,o]),dd(()=>{e&&e.registerCategories(o,r)},[e,o,r])}(p&&e?m:[]);const b=Uu(()=>{if(!y||!e)return;const n=function({data:t,colorBy:e,colorScale:o,getColor:n,strokeColor:i,strokeWidth:r,categories:s}){return{legendGroups:[{styleFn:t=>{const e=t.color||"#333",o={fill:e,stroke:e};return void 0!==i&&(o.stroke=i),void 0!==r&&(o.strokeWidth=r),o},type:"fill",items:(s&&s.length>0?s:Array.from(new Set(t.map(t=>"function"==typeof e?e(t):t[e])))).map((i,r)=>{const s=t.find("function"==typeof e?t=>e(t)===i:t=>t[e]===i),a=s?n(s,e,o):o?o(i):gt[r%gt.length];return{label:i+"",color:a}}),label:""}]}}({data:t,colorBy:e,colorScale:o,getColor:xt,categories:m});return 0!==n.legendGroups.reduce((t,e)=>t+e.items.length,0)?n:void 0},[y,e,t,o,m]),x=Uu(()=>Fi(b,l),[b,l]),{hasAxis:v,hasAxisLabel:w,rotatedTicks:k}=h??{},S=Uu(()=>{const t="number"==typeof r?{top:r,bottom:r,left:r,right:r}:r??{},e=e=>{const o=t[e];return"number"==typeof o?o:s[e]},o={top:e("top"),right:e("right"),bottom:e("bottom"),left:e("left")},n=e=>"number"==typeof t[e];if(x){const t=Hi(x,u),e=void 0===v?{hasAxis:!0,hasAxisLabel:!0}:{hasAxis:v,hasAxisLabel:w,rotatedTicks:k},r=Gi(x,Math.max(1,(c??600)-o.left-o.right),u)+Wi(x)+Yi("bottom"===i?e:void 0,u)+("top"===i&&d?24:0);"right"===i&&!n("right")&&t>o.right?o.right=t:"left"===i&&!n("left")&&t>o.left?o.left=t:"top"!==i||n("top")?"bottom"!==i||n("bottom")||(o.bottom=Math.max(o.bottom,80,r)):o.top=Math.max(o.top,50,r)}return o},[s,r,x,i,c,u,d,v,w,k]);return{legend:x,margin:S,legendPosition:i}}var fd=[];function pd(){const t=Hu(),e=t?.colors?.categorical;return e&&e.length>0?e:void 0}function yd(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=vt(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=ht[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]:pt}function gd({selection:t,linkedHover:e,fallbackFields:o=fd,unwrapData:n=!1,onObservation:i,chartType:r,chartId:s,onClick:a,hoverHighlight:l,colorByField:c,mobileInteraction:u}){const d=Au(),h=wu(()=>function(t,e){return t?!0===t?{name:"hover",fields:e||[]}:"string"==typeof t?{name:t,fields:e||[]}:{name:t.name||"hover",fields:t.fields||e||[],mode:t.mode,xField:t.xField,seriesField:t.seriesField}:null}(e,o),[e,o]),f=wu(()=>"series"===h?.mode?[h.seriesField||c||o[0]].filter(t=>!!t):h?.fields||o,[h,c,o]),p=Wu({name:t?.name||"__unused__",fields:f}),y=function(t){const e=t.name||"hover",{fields:o}=t,{predicate:n,isActive:i,selectPoints:r,clear:s}=Wu({name:e,fields:o});return{onHover:Du(t=>{if(!t)return void s();const e={};for(const n of o){const o=t[n];void 0!==o&&(e[n]=[o])}(function(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!0;return!1})(e)&&r(e)},[o,r,s]),predicate:n,isActive:i}}({name:h?.name||"hover",fields:f}),g=m(t=>t.pushObservation),b=ku(t=>{i?.(t),g?.(t)},[i,g]),x=t?{isActive:p.isActive,predicate:p.predicate}:null,[v,w]=Su(null),k=_u(!1),S=c||o[0],A=wu(()=>{if(!l||null==v||!S)return null;const t=v,e=S;return{isActive:!0,predicate:o=>("string"==typeof o[e]?o[e]:(o[e]??"")+"")===t}},[l,v,S]),M=ku((t,o)=>{const n=!t&&k.current&&!!u?.enabled&&u.tapToLockTooltip;if(e)if(t){let e=t.data||t.datum||t;if(Array.isArray(e)&&(e=e[0]),"x-position"===h?.mode&&h.xField){const o=qu(t,e,h.xField);null!=o&&function(t,e,o){const n=ys.positions.get(t);n?.locked||n&&n.xValue===e&&n.sourceId===o||(ys={positions:new Map(ys.positions).set(t,{xValue:e,sourceId:o})},ms())}(h.name||"hover",o,d)}"x-position"!==h?.mode&&y.onHover(e)}else"x-position"!==h?.mode||n||bs(h.name||"hover",d),"x-position"===h?.mode||n||y.onHover(null);if(l&&S)if(t){let e=t.data||t.datum||t;Array.isArray(e)&&(e=e[0]);const o=e?.[S];w(null!=o?o+"":null)}else n||w(null);(i||g)&&Uc({onObservation:b,datum:t?Vu(t):null,x:t?.x,y:t?.y,chartType:r||"unknown",chartId:s,context:o})},[e,y,h,d,i,r,s,g,b,l,S,u]),_=ku((o=!0)=>{k.current=!1,e&&"x-position"!==h?.mode&&y.onHover(null),t&&u?.tapToSelect&&p.clear(),o&&l&&w(null),"x-position"===h?.mode&&(xs(h.name||"hover",d),bs(h.name||"hover",d))},[e,h,y,t,u,p,l,d]),P=ku((o,n)=>{const c=!!u?.enabled&&(u.tapToLockTooltip||u.tapToSelect),m=!!u?.enabled&&"backgroundTap"===u.clearSelection;if("x-position"===h?.mode&&h.xField&&o){let t=o.data||o.datum||o;Array.isArray(t)&&(t=t[0]);const e=qu(o,t,h.xField);null!=e&&function(t,e,o){const n=ys.positions.get(t);if(n?.locked){const e=new Map(ys.positions);return e.delete(t),ys={positions:e},ms(),!1}ys={positions:new Map(ys.positions).set(t,{xValue:e,sourceId:o,locked:!0})},ms()}(h.name||"hover",e,d)}if(c)if(o){k.current=!0;const n=Vu(o);if(e&&"x-position"!==h?.mode&&y.onHover(n),t&&u?.tapToSelect&&f.length>0){const t={};for(const e of f){const o=n[e];void 0!==o&&(t[e]=[o])}Xu(t)&&p.selectPoints(t)}if(l&&S){const t=n?.[S];w(null!=t?t+"":null)}}else m&&_();if(o||m){if(o&&a){let t=o.data||o.datum||o;Array.isArray(t)&&(t=t[0]),a(t,{x:o.x??0,y:o.y??0})}(i||g)&&Kc({onObservation:b,datum:o?Vu(o):null,x:o?.x,y:o?.y,chartType:r||"unknown",chartId:s,context:n})}},[a,i,g,b,r,s,h,d,u,e,y,t,p,f,l,S,_]);return Mu(()=>{if(!u?.enabled||"undefined"==typeof document)return;const t=t=>{"Escape"===t.key&&k.current&&_()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[u?.enabled,_]),Mu(()=>()=>{k.current&&_(!1)},[_]),Mu(()=>{if("x-position"!==h?.mode)return;const t=h.name||"hover";return()=>{xs(t,d),bs(t,d)}},[h?.mode,h?.name,d]),{activeSelectionHook:x,hoverSelectionHook:A,customHoverBehavior:M,customClickBehavior:P,crosshairSourceId:d}}import{useCallback as md,useMemo as bd,useState as xd}from"react";import{useMemo as vd}from"react";import{useImperativeHandle as wd,useRef as kd}from"react";function Sd(t){const e=vu(null);return function(t,e){const{variant:o,frameRef:n,overrides:i}=e,r=kd(i);r.current=i,wd(t,()=>{const t=function(t,e){if("xy"===t){const t=e;return{push:e=>t.current?.push(e),pushMany:e=>t.current?.pushMany(e),remove:e=>t.current?.remove(e)??[],update:(e,o)=>t.current?.update(e,o)??[],replace:e=>t.current?.replace?.(e),clear:()=>t.current?.clear(),getData:()=>t.current?.getData()??[],getScales:()=>t.current?.getScales()??null,getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}if("network"===t){const t=e;return{push:e=>t.current?.push(e),pushMany:e=>t.current?.pushMany(e),remove:e=>{const o=Array.isArray(e)?e:[e],n=t.current?.getTopology()?.nodes??[],i=[];for(const e of o){const o=n.find(t=>t.id===e);o&&i.push({...o.data??{},id:e}),t.current?.removeNode(e)}return i},update:(e,o)=>(Array.isArray(e)?e:[e]).flatMap(e=>{const n=t.current?.updateNode(e,o);return n?[{...n,id:e}]:[]}),clear:()=>t.current?.clear(),getData:()=>t.current?.getTopology()?.nodes?.map(t=>t.data)??[],getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}if("geo-points"===t){const t=e;return{push:e=>t.current?.push(e),pushMany:e=>t.current?.pushMany(e),remove:e=>t.current?.removePoint(e)??[],update:(e,o)=>{const n=t.current?.removePoint(e)??[];for(const e of n)t.current?.push(o(e));return n},clear:()=>t.current?.clear(),getData:()=>t.current?.getData()??[],getCustomLayout:()=>t.current?.getCustomLayout?.()??null,getLayoutFailure:()=>t.current?.getLayoutFailure?.()??null}}const o=e;return{push:t=>o.current?.pushLine(t),pushMany:t=>o.current?.pushManyLines(t),remove:t=>o.current?.removeLine(t)??[],update:(t,e)=>{const n=o.current?.removeLine(t)??[];for(const t of n)o.current?.pushLine(e(t));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(t,{get(t,e,o){if("string"==typeof e){const t=r.current?.[e];if("function"==typeof t)return t}return Reflect.get(t,e,o)},has:(t,e)=>!("string"!=typeof e||!r.current||!(e in r.current))||Reflect.has(t,e)})},[])}(t.imperativeRef,{variant:t.imperativeVariant,frameRef:e}),{frameRef:e,resolved:$(t.mode,{width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,description:t.description,summary:t.summary,accessibleTable:t.accessibleTable,xLabel:t.xLabel,yLabel:t.yLabel,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,responsiveRules:t.responsiveRules},void 0),normalizedMargin:xu(()=>D(t.margin),[t.margin])}}function Ad(t){const{title:e,description:o,summary:n,accessibleTable:i,className:r,animate:s,axisExtent:a,autoPlaceAnnotations:l}=t,c={};return e&&(c.title=e),o&&(c.description=o),n&&(c.summary=n),void 0!==i&&(c.accessibleTable=i),r&&(c.className=r),null!=s&&(c.animate=s),void 0!==a&&(c.axisExtent=a),void 0!==l&&(c.autoPlaceAnnotations=l),c}function Md(t){const{linkedHover:e,selection:o,onObservation:n,onClick:i,hoverRadius:r,hoverHighlight:s,forceHoverBehavior:a,forceClickBehavior:l,mobileInteraction:c,customHoverBehavior:u,customClickBehavior:d,linkedHoverInClickPredicate:h=!0}=t,f={};n&&(f.annotationObservationCallback=n);const p=c?.enabled?Math.max(r??30,Math.ceil((c.targetSize||44)/2),24):r;return(a||e||n||i||s)&&(f.customHoverBehavior=u),d&&(l||(h?n||i||e:n||i)||c?.enabled&&(c.tapToSelect||c.tapToLockTooltip)&&(e||s||o))&&(f.customClickBehavior=d),null!=p&&(f.hoverRadius=p),f}import{jsx as _d}from"react/jsx-runtime";var Pd=ae(function(t,e){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:f,selection:p,linkedHover:y,hoverHighlight:g,chartId:m,loading:b,loadingContent:x,emptyContent:v,colorBy:w,colorScheme:k,legend:S,legendInteraction:A,legendPosition:M,frameProps:P={}}=t,{legend:C,...R}=P,L=le(()=>Fi(C,S),[C,S]),{frameRef:T,resolved:$,safeData:z,setup:D,earlyReturn:F}=function(t){const e=Sd(t),{resolved:o,normalizedMargin:n}=e,i=function(t){const{data:e,rawData:o,colorBy:n,colorScheme:i,legendInteraction:r,legendPosition:s,selection:a,linkedHover:l,fallbackFields:c,unwrapData:u=!1,onObservation:d,chartType:h,chartId:f,showLegend:p,legend:y,legendLayout:g,userMargin:m,marginDefaults:b,onClick:x,hoverHighlight:v,mobileInteraction:w,mobileSemantics:k,loading:S,loadingContent:A,emptyContent:M,width:P,height:C,hasTitle:R,axisChrome:L}=t,T=void 0===o,$=bd(()=>B(e),[e]),[z,D]=xd([]),F=md(t=>{D(e=>e.length===t.length&&e.every((e,o)=>e===t[o])?e:t)},[]),E="string"==typeof t.colorBy?t.colorBy:void 0,O=bd(()=>I(w,{width:P,mobileSemantics:k}),[w,P,k]),{activeSelectionHook:N,hoverSelectionHook:W,customHoverBehavior:j,customClickBehavior:Y,crosshairSourceId:G}=gd({selection:a,linkedHover:l,fallbackFields:c,unwrapData:u,onObservation:d,chartType:h,chartId:f,onClick:x,hoverHighlight:v,colorByField:E,mobileInteraction:O}),H=function(t,e){const o="object"==typeof t&&null!==t?t:void 0;if("x-position"===o?.mode)return{linkedCrosshairName:o.name||"hover",linkedCrosshairSourceId:e}}(l,G),q=function(t,e,o){const n=Tu(),i=pd();return wu(()=>{if(!e)return;const r=n??void 0,s=o??(i&&i.length>0?i:void 0)??"category10";if(0!==t.length){if("function"==typeof e){const o=Array.from(new Set(t.map(t=>e(t)+"")));if(r&&Xu(r)){const t=wt(o.map(t=>({_cat:t})),"_cat",s);return e=>r[e]||t(e)}return wt(o.map(t=>({_cat:t})),"_cat",s)}if(r&&Xu(r)){const o=wt(t,e,s);return t=>r[t]||o(t)}return wt(t,e,s)}if(r&&Xu(r)){const t=wt([{_:"a"}],"_",s);return e=>r[e]||t(e)}},[t,e,o,n,i])}($,n,i),V=bd(()=>{if(!n)return[];const t=new Set;for(const e of $){const o="function"==typeof n?n(e):e[n];null!=o&&t.add(o+"")}return Array.from(t)},[$,n]),X=bd(()=>T&&z.length>0?z:V,[T,z,V]),U=function(t,e,o){const[n,i]=Zu(null),[r,s]=Zu(new Set),a=Uu(()=>new Set,[]),l=Ku(e=>{"highlight"===t&&i(e?e.label:null)},[t]),c=Ku(e=>{"isolate"===t&&s(t=>{const n=new Set(t);return n.has(e.label)?n.delete(e.label):n.add(e.label),n.size===o.length?new Set:n})},[t,o.length]),u=Uu(()=>{if(!t||"none"===t||!e)return null;const o="string"==typeof e?e:null;return"highlight"===t&&null!=n?{isActive:!0,predicate:t=>(o?t[o]:"function"==typeof e?e(t):null)===n}:"isolate"===t&&r.size>0?{isActive:!0,predicate:t=>{const n=o?t[o]:"function"==typeof e?e(t):null;return r.has(n)}}:null},[t,e,n,r]);return{highlightedCategory:"highlight"===t?n:null,isolatedCategories:"isolate"===t?r:a,onLegendHover:l,onLegendClick:c,legendSelectionHook:u}}(r,n,X),K=bd(()=>W||(U.legendSelectionHook?U.legendSelectionHook:N),[W,U.legendSelectionHook,N]),Z=function(t){const e=_(t=>t.theme.colors.selectionOpacity);return vd(()=>{if(void 0!==t||void 0!==e)return{name:t?.name??"",...t,unselectedOpacity:t?.unselectedOpacity??e}},[t,e])}(a),Q=pd(),J=Tu(),tt=bd(()=>{if(q)return q;if(!n||0===X.length)return;const t=Array.isArray(i)&&i.length>0||"string"==typeof i&&i.length>0?i:Q&&Q.length>0?Q:gt,e="__streamCat",o=wt(X.map(t=>({[e]:t})),e,t);return t=>J?.[t]||o(t)||"#999"},[q,n,X,i,Q,J]),{legend:et,margin:ot,legendPosition:nt}=hd({data:$,colorBy:n,colorScale:tt,showLegend:p,legendPosition:s,userMargin:m,defaults:b,categories:X,additionalLegend:y,chartWidth:P,legendLayout:g,hasTitle:R,axisChrome:L}),it=bd(()=>{const t={};return et&&(t.legend=et,t.legendPosition=nt,g&&(t.legendLayout=g)),r&&"none"!==r&&(t.legendHoverBehavior=U.onLegendHover,t.legendClickBehavior=U.onLegendClick,t.legendHighlightedCategory=U.highlightedCategory,t.legendIsolatedCategories=U.isolatedCategories),T&&n&&(t.legendCategoryAccessor=n,t.onCategoriesChange=F),t},[et,nt,g,r,U.onLegendHover,U.onLegendClick,U.highlightedCategory,U.isolatedCategories,T,n,F]),rt=Array.isArray(o)?B(o):o,st=function(t,e,o,n){if(!t)return null;if(!1===n)return null;if(null!=n)return yu("div",{style:{width:e,height:o,display:"flex",alignItems:"center",justifyContent:"center",boxSizing:"border-box"},children:n});const i=Math.min(5,Math.floor(o/40)),r=Math.max(8,Math.floor(o/(3*i))),s=Math.max(6,Math.floor(o/(2.5*i))),a=Math.floor((o-(i*(r+s)-s))/2);return yu("div",{style:{width:e,height:o,position:"relative",overflow:"hidden",border:"1px solid var(--semiotic-border, #e0e0e0)",borderRadius:4,boxSizing:"border-box"},children:Array.from({length:i},(t,o)=>yu("div",{className:"semiotic-loading-bar",style:{...bu,position:"absolute",top:a+o*(r+s),left:Math.floor(.1*e),width:30+(37*o+13)%50+"%",height:r,opacity:.5+o%2*.2}},o))})}(S,P,C,A),at=st?null:function(t,e,o,n){return!1===n||null==t||Array.isArray(t)&&t.length>0?null:Array.isArray(t)?yu("div",{style:{...mu,width:e,height:o},children:n||"No data available"}):null}(rt,P,C,M);return{data:$,colorScale:q,allCategories:X,legendState:U,effectiveSelectionHook:K,activeSelectionHook:N,customHoverBehavior:j,customClickBehavior:Y,mobileInteraction:O,legend:et,margin:ot,legendPosition:nt,earlyReturn:st||at||null,legendBehaviorProps:it,crosshairProps:H,resolvedSelection:Z}}({data:t.data??[],rawData:t.data,colorBy:t.colorBy,colorScheme:t.colorScheme,legendInteraction:t.legendInteraction,legendPosition:t.legendPosition,selection:t.selection,linkedHover:t.linkedHover,hoverHighlight:t.hoverHighlight,fallbackFields:"string"==typeof t.colorBy?[t.colorBy]:[],unwrapData:t.unwrapData,onObservation:t.onObservation,onClick:t.onClick,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,chartType:t.chartTypeLabel,chartId:t.chartId,showLegend:o.showLegend,legend:t.legend,userMargin:n,marginDefaults:o.marginDefaults,loading:t.loading,loadingContent:t.loadingContent,emptyContent:t.emptyContent,width:o.width,height:o.height});return{...e,safeData:i.data,setup:i,earlyReturn:i.earlyReturn}}({imperativeRef:e,imperativeVariant:"xy",chartTypeLabel:"XYCustomChart",unwrapData:!1,data:o,colorBy:w,colorScheme:k,legend:L,legendInteraction:A,legendPosition:M,selection:p,linkedHover:y,hoverHighlight:g,onObservation:h,onClick:f,chartId:m,loading:b,loadingContent:x,emptyContent:v,margin:c,width:t.width,height:t.height,showGrid:t.showGrid,enableHover:t.enableHover,showLegend:t.showLegend,title:t.title,description:t.description,summary:t.summary,accessibleTable:t.accessibleTable,mode:t.mode,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,responsiveRules:t.responsiveRules,xLabel:t.xLabel,yLabel:t.yLabel}),E=D.effectiveSelectionHook,O=le(()=>E?.isActive?{isActive:!0,predicate:E.predicate}:null,[E?.isActive,E?.predicate]);if(F)return F;const{width:N,height:W,enableHover:j,showGrid:Y,title:G,description:H,summary:q,accessibleTable:V,xLabel:X,yLabel:U}=$,K={chartType:"custom",...null!=o&&{data:z},customLayout:n,layoutConfig:i,onLayoutError:r,...O&&{layoutSelection:O},xExtent:s,yExtent:a,colorAccessor:w,colorScheme:k,size:[N,W],responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,margin:D.margin,showAxes:l,xLabel:X,yLabel:U,enableHover:j,showGrid:Y,...D.legendBehaviorProps,...Ad({title:G,description:H,summary:q,accessibleTable:V,className:u,animate:t.animate,axisExtent:t.axisExtent,autoPlaceAnnotations:t.autoPlaceAnnotations}),...null!=t.tooltip&&{tooltipContent:t.tooltip},...Md({linkedHover:y,selection:p,onObservation:h,onClick:f,hoverRadius:t.hoverRadius,hoverHighlight:g,mobileInteraction:D.mobileInteraction,customHoverBehavior:D.customHoverBehavior,customClickBehavior:D.customClickBehavior}),...d&&d.length>0&&{annotations:d},...D.crosshairProps,...R};return _d(gu,{componentName:"XYCustomChart",width:N,height:W,children:_d(lu,{ref:T,...K})})});function Cd(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 Rd(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 Ld(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=Cd(t.x,s,s,e.x,l),u=Cd(t.y,t.y,e.y,e.y,l),d=Rd(t.x,s,s,e.x,l),h=Rd(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 Id(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=Ld(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}}Pd.displayName="XYCustomChart";import{jsx as Td,jsxs as $d}from"react/jsx-runtime";function zd(t,e,o){return"function"==typeof t?t(e,o):e[t]}function Dd(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}function Fd(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[Dd(t),e]));return t.map(t=>{const e={...t},n=n=>{if(!(n in t))return;const i=o.get(Dd(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 Ed(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)d[t]=i??(c.has(t)?yd(void 0,a,r,t,u):s??l??"#b8bec8");return d}function Od(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=zd(o,t,e),f=Dd(r);let p=a.get(f);null==p&&(p=s.length,a.set(f,p),s.push(r),l.set(p,[]));const y=zd(i,t,e)+"";u.has(y)||(u.set(y,c.length),c.push(y));const g=Number(zd(n,t,e));Number.isFinite(g)&&(d=Math.min(d,g),h=Math.max(h,g),l.get(p)?.push({datum:t,inputIndex:e,series:y,value:g}))});const f=[],p=new Map,y=new Map;for(let t=0;s.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,o)=>{const n=o+1;f.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:n}),p.set(e.series,(p.get(e.series)??0)+n),y.set(e.series,(y.get(e.series)??0)+1)})}const g=c.length+1,m=[...c].sort((t,e)=>{const o=y.get(t)??0,n=y.get(e)??0;return((p.get(t)??0)+(s.length-o)*g)/Math.max(1,s.length)-((p.get(e)??0)+(s.length-n)*g)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),b=new Set(m.slice(0,null==e.highlightTop?m.length:Math.max(0,Math.floor(e.highlightTop))));return{data:f.map(t=>{const e=b.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}function Bd({datum:t,x:e,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=ee.useContext(ie)??ne,l=a.isActive&&!a.predicate(t),c="function"==typeof s?s(t.__bumpRaw):s;return Td("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,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 11px)",...c},children:t.__bumpSeries})}function Nd(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 Wd(t){const e=t instanceof Date?t.getTime():Number(t);return Number.isFinite(e)?e:void 0}function jd(t){return{value:t.__bumpValue,x:Wd(t.__bumpXValue),y:t.__bumpValue,category:t.__bumpSeries}}function Yd(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=[];for(const s of n){const n=(o.get(s)??[]).sort((t,e)=>t.x-e.x);if(2>n.length)continue;const a=n[0].__bumpHighlighted,l=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?Nd(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=Id(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h=d.datumIndices.map(t=>n[t]),f={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(f,Tt(n[0].__bumpRaw,e.styleRules,jd(n[0]))),e.areaStyle&&Object.assign(f,e.areaStyle(n[0].__bumpRaw)??{}),void 0!==e.stroke&&(f.stroke=e.stroke),void 0!==e.strokeWidth&&(f.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(f.opacity=e.opacity),i.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:f,datum:h,accessibleDatum:n.map(t=>t.__bumpRaw),accessibility:{label:s+" ranking trajectory",tableFields:n.map(t=>t.__bumpRaw)},group:s,interactive:!0}),e.showPoints&&n.forEach((t,o)=>{const n={fill:c,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(n,Tt(t.__bumpRaw,e.styleRules,jd(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:`${s}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${s}:${t.x}`})});const p=!0===e.showLabels?"end":e.showLabels,y=(t,o,n)=>{r.push(Td(Bd,{datum:t,x:u[o].x,y:u[o].y,side:n,color:"string"==typeof f.fill?f.fill:c,highlighted:a,labelStyle:e.labelStyle},`${s}-${n}`))};"start"!==p&&"both"!==p||y(n[0],0,"start"),"end"!==p&&"both"!==p||y(n.at(-1),n.length-1,"end")}return{nodes:i,overlays:r.length?Td("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}}}}function Gd(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=C(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?wt(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,f="number"==typeof i.areaOpacity?i.areaOpacity:.7,p=Pt(i.yAccessor),y=i.styleRules;return(t,o)=>{const n=e&&u?xt(t,e,u):"string"==typeof i.color?i.color:pt,r={fill:n,fillOpacity:f,stroke:d?n:"none",...d&&{strokeWidth:h}};return y?.length&&Object.assign(r,Tt(t,y,{value:p(t),category:o})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function Hd(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=C(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?wt(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?St(f):void 0;return t=>({fill:e&&u?xt(t,e,u):"string"==typeof i.color?i.color:pt,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?kt(t,d,h,p):h[0],stroke:i.stroke??i.bubbleStrokeColor??"white",strokeWidth:i.strokeWidth??i.bubbleStrokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}})}function qd(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=C(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?wt(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],f=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],p=f.length?St(f):void 0,y=Ct(i.xAccessor,i.yAccessor),g=i.styleRules;return t=>{const o={fill:e&&u?xt(t,e,u):"string"==typeof i.color?i.color:pt,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?kt(t,d,h,p):"number"==typeof i.pointRadius?i.pointRadius:5};return g?.length&&Object.assign(o,Tt(t,g,y(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}Qt(function(t,e){const o=pd(),n=Hu(),{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:f=3,highlightTop:p,neutralColor:y,styleRules:g,labelStyle:m,colorScheme:b,ribbonOpacity:x=.82,lineOpacity:v=.9,showPoints:w=!1,pointRadius:k=3,showLabels:S=!0,showAxes:A=!0,showGrid:M=!0,showLegend:_=!1,enableHover:P=!0,hoverHighlight:C=!0,tooltip:R,frameProps:L={},xFormat:I,yFormat:T,onClick:$}=t,z=te(()=>Od(i,{xAccessor:r,yAccessor:s,lineBy:a,rankDirection:l,highlightTop:p}),[i,r,s,a,l,p]),{axes:D,areaStyle:F,pointStyle:E,...O}=L,B=te(()=>Ed({seriesOrder:z.seriesOrder,overallOrder:z.overallOrder,highlightTop:p,color:t.color,colorScheme:b,neutralColor:y,themeCategorical:o,themeNeutral:n.colors.textSecondary}),[z.seriesOrder,z.overallOrder,p,t.color,b,y,o,n.colors.textSecondary]),N=te(()=>({ribbon:c,curve:u,samplesPerSegment:h,ribbonSizeRange:d,valueExtent:z.valueExtent,seriesOrder:z.seriesOrder,lineWidth:f,ribbonOpacity:x,lineOpacity:v,neutralColor:y,color:t.color,stroke:t.stroke,strokeWidth:t.strokeWidth,opacity:t.opacity,styleRules:g,areaStyle:F,pointStyle:E,labelStyle:m,showPoints:w,pointRadius:k,showLabels:S}),[c,u,h,d,z.valueExtent,z.seriesOrder,f,x,v,y,t.color,t.stroke,t.strokeWidth,t.opacity,g,F,E,m,w,k,S]),W=Jt((t,e)=>{if(0===z.xValues.length)return"";const o=z.xValues[Math.max(0,Math.min(z.xValues.length-1,Math.round(Number(t))))];return I?I(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},[z.xValues,I]),j=Jt(t=>T?T(t):t.toLocaleString(),[T]),Y=te(()=>"multi"===R?void 0:function(t){if(!0!==t){if("function"==typeof t){const e=t;return t=>{let o=bl(!0===t?.__semioticHoverData||t&&void 0!==t.data&&"number"==typeof t.x&&"number"==typeof t.y&&t&&("node"===t.type||"edge"===t.type||void 0!==t.nodeOrEdge||void 0!==t.allSeries||void 0!==t.stats||void 0!==t.__chartType)?t.data??{}:t);if(!o)return null;if(("node"===t?.nodeOrEdge&&"number"==typeof o?.x0&&"number"==typeof o?.x1||"edge"===t?.nodeOrEdge&&"number"==typeof o?.sankeyWidth)&&o.data&&"object"==typeof o.data&&(o=o.data),!o)return null;const n=e(o);return null==n?null:_l("div",{className:"semiotic-tooltip",style:Cl,children:n})}}return!1!==t&&void 0!==t&&("object"==typeof t&&null!==t&&("fields"in t||"title"in t)?Il(t):"multi"===t?("undefined"!=typeof process&&"production"!==process.env?.NODE_ENV&&console.warn('[semiotic] tooltip="multi" reached normalizeTooltip — prefer charts that set tooltipMode (LineChart, AreaChart, StackedAreaChart, DifferenceChart). Rendering MultiLineTooltip content as a fallback.'),function(t={}){const{fields:e=[],title:o,format:n,style:i={},className:r="",showLabels:s=!0,separator:a=": "}=t;return t=>{if(!t||"object"!=typeof t)return null;const l=[];if(o){const e=Rl(t,o);l.push({value:Ll(e,n)})}if(e&&Array.isArray(e)&&e.length>0)e.forEach(e=>{let o,i,r;"string"==typeof e?(o=e,i=e,r=n):(o=e.label,i=e.accessor||e.key||"",r=e.format||n);const a=Ll(Rl(t,i),r);l.push({label:s?o:void 0,value:a})});else{const e=Ml(t,{skipPositional:!1});null!=e.title&&l.push({label:void 0,value:Ll(e.title,n),bold:!0}),e.entries.forEach(t=>{l.push({label:s?t.key:void 0,value:Ll(t.value,n)})})}const c={...Cl,...i};return Array.isArray(l)&&0!==l.length?_l("div",{className:("semiotic-tooltip semiotic-tooltip-multiline "+r).trim(),style:c,children:l.map((t,e)=>Pl("div",{style:{marginBottom:l.length-1>e?"4px":0,fontWeight:t.bold?"bold":void 0},children:[t.label&&Pl("strong",{children:[t.label,a]}),t.value]},e))}):null}}()):Il())}}(R),[R]),G=Jt(t=>{const e=t?.data??t;return e?!1===R?null:Y?Y({...t,data:e.__bumpRaw,__semioticHoverData:!0}):$d("div",{className:"semiotic-tooltip",style:Cl,children:[Td("div",{style:{fontWeight:700},children:e.__bumpSeries}),$d("div",{children:[W(e.x)," · Rank ",e.__bumpRank]}),$d("div",{children:["Value: ",j(e.__bumpValue)]})]}):null},[j,W,Y,R]),H=te(()=>{if($)return(t,e)=>{$(t.__bumpRaw??t,e)}},[$]),q=Math.max(1,z.seriesOrder.length),V=z.xValues.map((t,e)=>e),X=Array.from({length:q},(t,e)=>e+1),U=D??[{orient:"left",tickValues:X,tickFormat:t=>t+"",label:t.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:V,tickFormat:W,label:t.xLabel,tickAnchor:"edges"}],K=te(()=>Fd(t.annotations,z.xValues),[t.annotations,z.xValues]);return Td(Pd,{ref:e,data:z.data,layout:Yd,layoutConfig:N,xExtent:[0,Math.max(1,z.xValues.length-1)],yExtent:[q+.5,.5],showAxes:A,showGrid:M,showLegend:_,enableHover:P,hoverHighlight:C,colorBy:"__bumpSeries",colorScheme:B,tooltip:G,onClick:H,hoverRadius:t.hoverRadius,width:t.width,height:t.height,responsiveWidth:t.responsiveWidth,responsiveHeight:t.responsiveHeight,responsiveRules:t.responsiveRules,mobileInteraction:t.mobileInteraction,mobileSemantics:t.mobileSemantics,mode:t.mode,margin:t.margin??{top:20,right:S?110:24,bottom:48,left:48},className:t.className,title:t.title,description:t.description,summary:t.summary,accessibleTable:t.accessibleTable,selection:t.selection,linkedHover:t.linkedHover,legend:t.legend,legendInteraction:t.legendInteraction,legendPosition:t.legendPosition,onObservation:t.onObservation,chartId:t.chartId,loading:t.loading,loadingContent:t.loadingContent,emptyContent:t.emptyContent,animate:t.animate,autoPlaceAnnotations:t.autoPlaceAnnotations,annotations:K,xLabel:t.xLabel,yLabel:t.yLabel??"Rank",frameProps:{axes:U,axisExtent:"exact",...O}})}).displayName="BumpChart";var Vd={frameType:"xy",buildProps:(t,e,o,n,i)=>({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,pointStyle:n.pointStyle||Hd(t,e,o,n,i),showLegend:n.showLegend??!!e})},Xd={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=Od(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=C(n.theme),l=Ed({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=(t,e)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((t,e)=>e),f=Array.from({length:s},(t,e)=>e+1),p=n.axes??[{orient:"left",tickValues:f,tickFormat:t=>t+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:Yd,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:p,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:Fd(n.annotations,r.xValues)}}};function Ud(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=C(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?wt(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?xt(t,e,u):"string"==typeof i.color?i.color:pt;return{r:d,fill:o,stroke:"none"}}}var Kd={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=C(n.theme).colors.categorical,c=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=C(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?wt(c,l,a):void 0,d=Ct(i.xAccessor,i.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:n,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:l,ruleContext:c}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let f;return r?f=r(t,u):o?n&&(f=xt(t,o,n)):f=i||pt,void 0!==f&&(d.stroke=f,h&&(d.fill=f,d.fillOpacity=a)),l?.length&&Object.assign(d,Tt(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 _t(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=Zt({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||Ud(u.data,u.colorAccessor,o,n,i);let h=n.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const f=(!i.directLabel||void 0!==n.showLegend)&&(n.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||c,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...n,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!n.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},Zd={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?B(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=jt(i,o,"time"),r=jt(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.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}}},Qd={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=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:Array.isArray(t)?B(t):[],areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),a=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:o})=>({offset:t/100,color:e,...null!=o&&{opacity:o}}))}:Array.isArray(t.stops)?t:void 0}(i.semanticGradient),l=a?.stops.length?{stops:a.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:Ft(n.gradientFill),c=!1!==i.semanticLine&&a?.stops.length?a.stops.flatMap(({offset:t,color:e})=>e?[{offset:t,color:e}]:[]):void 0,u=n.pointStyle||Ud(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||Gd(s,r,o,n,i),...u&&{pointStyle:u}}}},Jd={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=t=>Bt(Ot(r,"x",t)),c=t=>Bt(Ot(s,"a",t)),u=t=>Bt(Ot(a,"b",t)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",f=i.areaOpacity??.6,p=i.lineWidth??1.5,y=!1!==i.showLines,g=!1!==n.showLegend,m=i.seriesALabel||"A",b=i.seriesBLabel||"B",x=n.legendPosition||"right",v=function(t,e,o,n){if(!t.length)return[];const i=t.filter(t=>Number.isFinite(e(t))).sort((t,o)=>e(t)-e(o)),r=[];let s=0,a=null,l=null,c=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),f=(t,e)=>{h({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:d(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;i.length>t;t++){const r=i[t],p=e(r),y=o(r),g=n(r);if(!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g))continue;const m=u(y,g);if(null!==m)if(null!=a){if(l&&l.w!==m){let t,e;if(c.length>0)t=c[0].x,e=c[0].y;else{const o=y-l.a-(g-l.b);if(0!==o){const n=Math.max(0,Math.min(1,(l.b-l.a)/o));t=l.x+n*(p-l.x),e=l.a+n*(y-l.a)}else t=l.x,e=l.a}h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;c.length>t;t++)f(c[t],a)}else for(const t of c)f(t,a);c=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),l={x:p,a:y,b:g,w:m}}else{a=m;for(const t of c)f(t,a);c=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(a),__diffWinner:a,__valA:y,__valB:g,__sourceDatum:r}),l={x:p,a:y,b:g,w:m}}else c.push({x:p,y:y,datum:r})}for(const t of c)f(t,a??"A");return r}(Array.isArray(t)?t:[],l,c,u),w=[];if(y&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(l(t))).sort((t,e)=>l(t)-l(e));for(const t of e){const e=l(t),o=c(t),n=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(n)&&w.push({__x:e,__y:n,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:f}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:p,fill:"none"}),curve:i.curve||"linear",...n,...g&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:b,color:h}]}]},legendPosition:x}}}},th={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?wt(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=n.lineStyle||(t=>{const e=null==r?void 0:xt(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=Pt(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,Tt(t,l,{value:e(t),category:o}))}return n}),c=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Ud(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}}},eh={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)}}},oh={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=n.pointStyle||qd(t,e,o,n,i),s=function(t,e,o){return t&&0!==t.length?(n,i)=>{const r=Tt(n,t,e(n,i)),s=o?o(n,i):void 0;return s?{...r,...s}:r}:o}(i.styleRules,Ct(i.xAccessor||"x",i.yAccessor||"y"),l),a=s?t=>({..."function"==typeof r?r(t):r,...s(t)}):r;var l;return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,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??!!e}}},nh={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,f=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,p=E.createElement,y=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,y=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(y))return null;const g=Math.max(0,Math.min(n,l)),m=Math.max(0,Math.min(i,y)),b=[{c:a.topLeft,x:0,y:0,w:g,h:m},{c:a.topRight,x:g,y:0,w:n-g,h:m},{c:a.bottomLeft,x:0,y:m,w:g,h:i-m},{c:a.bottomRight,x:g,y:m,w:n-g,h:i-m}],x=c?[p("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),p("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),p("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),p("text",{key:"lbr",x:n-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return p(E.Fragment,null,...b.map((t,e)=>t.w>0&&t.h>0?p("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),p("line",{key:"vc",x1:g,y1:0,x2:g,y2:i,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:n,y2:m,stroke:d,strokeWidth:h,strokeDasharray:f}),...x)}]: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||qd(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...y&&{svgPreRenderers:y}}}},ih={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:Bt(Ot(e.orderAccessor,"order",t))-Bt(Ot(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=Bt(Ot(o,"x",t)),i=Bt(Ot(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=Bt(Ot(o,"x",t)),i=Bt(Ot(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=i.pointRadius??4,a=[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=Nt(t,e.length);100>e.length&&o.push(E.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:s+2,strokeLinecap:"round",opacity:.5})),o.push(E.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:s,strokeLinecap:"round"}))}return E.createElement(E.Fragment,null,...o)}];return{chartType:"scatter",data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:o,pointStyle:_t(t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1;return{fill:n>0?Nt(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1}},Wt(i)),...n,svgPreRenderers:a}}},rh={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1;return{chartType:"heatmap",data:t,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 sh(t){return Math.max(0,Math.min(1,t))}function ah(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 lh(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 ch(t,e,o){const n=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:sh(t.offset),color:t.color??o,opacity:null==t.opacity?1:sh(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=ah(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=sh(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=ah(e.color),c=ah(o.color);if(!l||!c)return i(.5>a?e:o);const[u,d,h]=l,[f,p,y]=c,g=u+(f-u)*a,m=d+(p-d)*a,b=h+(y-h)*a,x=e.opacity+(o.opacity-e.opacity)*a;return 1===x?lh(g,m,b):`rgba(${Math.round(g)},${Math.round(m)},${Math.round(b)},${x})`}return i(n[n.length-1])}function uh(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as dh,jsx as hh,jsxs as fh}from"react/jsx-runtime";function ph(t=240){const e=360-t,o=180+e/2,n=o*Math.PI/180;return{sweepRad:t*Math.PI/180,gapDeg:e,startAngleDeg:o,startAngleRad:n,offsetRad:-Math.PI/2+n}}import{useMemo as yh,useCallback as gh,useRef as mh}from"react";var bh={RdBu:rt,PiYG:st,PRGn:at,BrBG:lt,RdYlBu:ct,RdYlGn:ut,Spectral:dt},xh="__likert_neutral_neg",vh="__likert_neutral_pos";function wh(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}import*as kh from"react";function Sh(t){return Ft(t)}function Ah(t,e,o,n,i){const r=C(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?wt(c,l,s??r):void 0,d=yd("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=Pt(i.valueAccessor),f=i.styleRules,p=n.pieceStyle;return(t,o)=>{const n={fill:e&&u?xt(t,e,u):d};return f?.length&&Object.assign(n,Tt(t,f,{value:h(t),category:o})),"function"==typeof p?Object.assign(n,p(t,o)||{}):p&&"object"==typeof p&&Object.assign(n,p),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 Mh(t,e,o,n,i){const r=Ah(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 _h(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=C(n.theme).colors.categorical,c=o??n.colorScheme,u=e?wt(a,s,c??l):void 0,d=yd("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return t=>{const o=e&&u?xt(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 Ph(t,e,o,n,i){const r=Ah(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function Ch(t,e,o,n,i){const r=Ah(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?kt(t,a,l,u):d,fillOpacity:h,...r(t,e)})}var Rh={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({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,gradientFill:Sh(n.gradientFill),pieceStyle:Ah(t,e,o,n,i)})},Lh={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:Sh(n.gradientFill),pieceStyle:Ah(t,r,o,n,i),showLegend:n.showLegend??!!r}}},Ih={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:Sh(n.gradientFill),pieceStyle:Ah(t,r,o,n,i),showLegend:n.showLegend??!!r}}},Th={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:Ah(t,r,o,n,i),showLegend:n.showLegend??!!r}}},$h={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:Ah(t,r,o,n,i)}}},zh={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:Mh(t,e,o,n,i)}}},Dh={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||Mh(t,e,o,n,i)})},Fh={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||_h(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},Eh={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||Ch(t,e,o,n,i),showLegend:n.showLegend??!!e})},Oh={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>({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,pieceStyle:Ph(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e})},Bh={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:Sh(n.gradientFill),pieceStyle:n.pieceStyle||Ah(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},Nh={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,...Ah(t,e,o,n,i)(r,s)})),showLegend:n.showLegend??!!e})},Wh={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,wh(i.categoryAccessor,"question"),i.levelAccessor?null:wh(i.valueAccessor,"score"),i.levelAccessor?wh(i.levelAccessor,"level"):null,i.levelAccessor?wh(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===xh?r=o:o.__likertLevel===vh?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:xh,__likertPct:-t}),r.push({...e,__likertLevel:vh,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const l=C(n.theme).colors.diverging,c=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e){const o=bh[e];if(o){if(1===t)return[o(.5)];const e=[];for(let n=0;t>n;n++)e.push(o(n/(t-1)));return e}}const o=["#da1e28","#ff8389","#ffb3b8"],n=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===t)return[i];const r=t%2!=0,s=Math.floor(t/2),a=[];for(let t=0;s>t;t++)a.push(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);r&&a.push(i);for(let t=0;s>t;t++)a.push(n[Math.min(Math.floor(t*n.length/s),n.length-1)]);return a}(r.length,l),u=new Map(r.map((t,e)=>[t,c[e]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",f=Fi(!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:_t(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===xh||e===vh?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},Wt(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}},jh={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,showGrid:r,pieceStyle:Ah(t,s,o,n,i),showLabels:i.showLabels??!0}}},Yh={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 fh(dh,{children:[o.showNeedle&&fh(dh,{children:[hh("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"}),hh("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&hh("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 fh("g",{children:[hh("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"}),hh("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}=ph(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],f=Et(n.gradientFill),p=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,n))-e)/d;let f=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];f=f.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>f[f.length-1].value&&f.push({value:o,color:f[f.length-1].color});const p=!!c&&c.stops.length>=2,y=[],g=new Map,m=[];if(p){const t=a?h:1,e=uh("bg",0);if(y.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),g.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(e,Math.round(t*e))),n=[];for(let e=0;o>e;e++)n.push(ch(c.stops,t*(e+.5)/o,r||f[0]?.color||"#007bff"));const i=uh("fill",0);y.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),g.set(i,{fill:n[0]||s})}}else{let t=e;for(let o=0;f.length>o;o++){const n=f[o],i=(n.value-t)/d,r=(t-e)/d,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=uh("fill",o);y.push({category:t,value:c,_zone:n.label||"Zone "+(o+1),_isFill:!0}),g.set(t,{fill:n.color})}if(u>0){const t=uh("bg",o);y.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),g.set(t,{fill:s,opacity:.4})}t=n.value}}if(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:y,pieceStyle:(t,e)=>g.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:f}),[y,g]=n.size||[300,250],m=function(t=240){const{sweepRad:e,offsetRad:o}=ph(t),n=[[Math.cos(o),Math.sin(o)],[Math.cos(o+e),Math.sin(o+e)],[0,0]];for(let t=0;2*Math.PI>t;t+=Math.PI/2)((t-o)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)>e+.001||n.push([Math.cos(t),Math.sin(t)]);const i=n.map(t=>t[0]),r=n.map(t=>t[1]),[s,a]=St(i),[l,c]=St(r);return{minX:s,maxX:a,minY:l,maxY:c,width:a-s,height:c-l,cx:(s+a)/2,cy:(l+c)/2}}(a),b=Math.min(10,Math.max(1,Math.min(y,g)/12)),x=Math.max(4,Math.min((y-2*b)/m.width,(g-2*b)/m.height)-2),v=Math.max(0,Math.min(x-1.5,x*(1-l))),w=y/2-m.cx*x,k=g/2-m.cy*x,S=2*(x+4),A=Math.max(r,Math.min(s,i.value??r)),M="function"==typeof i.valueFormat?i.valueFormat(A):Math.round(A)+"",_=i.centerContent??n.centerContent,P=null!=_?"function"==typeof _?_(A,r,s):_:"sparkline"===i.mode||"context"===i.mode?void 0:kh.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},kh.createElement("div",{style:{fontSize:Math.max(16,.3*x),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==i.showScaleLabels&&kh.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:p.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:v,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:_t(p.pieceStyle,Wt(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[y,g],margin:{top:k-S/2,bottom:g-k-S/2,left:w-S/2,right:y-w-S/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(n.annotations)?n.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:l,value:A,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:x,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:x-1,showNeedle:c,needleColor:i.needleColor,..."context"===i.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*x))}}}}};import{scaleTime as Gh}from"d3-scale";function Hh(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`:t.kind}function qh(t,e,o){const n=e.incoming[t.id],i=e.outgoing[t.id],r=[];for(const t of n)r.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of i)r.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const s={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},a=()=>{r.sort((t,e)=>t.time-e.time||(s[t.kind]??99)-(s[e.kind]??99))},l=r.length?function(t,e=1/0){let o=e;for(const e of t)o>e&&(o=e);return o}(r.map(t=>t.time)):null,c=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,u=null!=c?c-1:null!=l&&Number.isFinite(l)?l-1:null,d=[...new Set(r.map(t=>t.time))].sort((t,e)=>t-e),h=new Map;for(let t=1;d.length>t;t++)h.set(d[t],d[t-1]);const f=t=>{const e=h.get(t);return null!=e?(e+t)/2:null!=u?u:t};a();const p=[];let y=0,g=0;for(const t of r)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?y:g);if(o>0){const e="top"===t.side?"bot":"top",n=Math.min(o,"top"===e?y:g);if(n>0){const i=f(t.time);p.push({time:i,delta:-n,kind:"transfer-out",side:e}),p.push({time:i,delta:+n,kind:"transfer-in",side:t.side}),"top"===e?y-=n:g-=n,"top"===t.side?y+=n:g+=n,o-=n}o>0&&null!==u&&(p.push({time:u,delta:+o,kind:"create",side:t.side}),"top"===t.side?y+=o:g+=o)}"top"===t.side?y-=e:g-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?y+=e:g+=e}r.push(...p),a();let m=0,b=0,x=0,v=0,w=0;const k=[],S=new Map;for(const t of r){if(k.push({t:t.time,topMass:m,botMass:b}),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?m:b;S.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta)})}"top"===t.side?m+=t.delta:b+=t.delta,m+b>x&&(x=m+b),m>v&&(v=m),b>w&&(w=b),k.push({t:t.time,topMass:m,botMass:b})}const A=[];let M=0;for(;k.length>M;){let t=M;for(;k.length>t+1&&k[t+1].t===k[M].t;)t++;A.push(k[M]);for(let e=M+1;t>=e;e++){const t=A[A.length-1];k[e].topMass===t.topMass&&k[e].botMass===t.botMass||A.push(k[e])}M=t+1}const _=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let P=null;for(const t of i)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===P||P>t.systemInTime)&&(P=t.systemInTime);let C=null;for(const t of n)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===C||t.systemOutTime>C)&&(C=t.systemOutTime);if(A.length>0){const t=A[A.length-1],e=Math.max(null!=_?_:-1/0,null!=C?C:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&A.push({t:e,topMass:t.topMass,botMass:t.botMass});const o=A[0],n=Math.min(null!=c?c:1/0,null!=P?P:1/0);Number.isFinite(n)&&o.t>n&&o.topMass+o.botMass>0&&A.unshift({t:n,topMass:o.topMass,botMass:o.botMass})}return{samples:A,peak:x,topPeak:v,botPeak:w,localAttachments:S}}function Vh(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function Xh(t,e){return t.map(t=>({t:Vh(t.t,e),topMass:t.topMass,botMass:t.botMass}))}function Uh(t,e,o){const n=t.value*o;if("out"===t.kind){const i=t.sideMassBefore*o;if("top"===t.side){const t=e-i;return[t,t+n]}const r=e+i;return[r-n,r]}const i=t.sideMassAfter*o;if("top"===t.side){const t=e-i;return[t,t+n]}const r=e+i;return[r-n,r]}function Kh(t,e){let o=0;for(let n=0;e.length>n;n++)for(let i=n+1;e.length>i;i++){const r=e[n],s=e[i];r.source!==s.source&&r.target!==s.target&&r.source!==s.target&&r.target!==s.source&&(Math.min(r.endTime,s.endTime)>Math.max(r.startTime,s.startTime)&&t[s.source]>t[r.source]!=t[s.target]>t[r.target]&&o++)}return o}function Zh(t,e){let o=0;for(const n of e)o+=Math.abs(t[n.source]-t[n.target])*(n.value||1);return o}function Qh(t,e){return 1e3*Kh(t,e)+Zh(t,e)}function Jh(t,e){return{slots:t.map(t=>({peak:{...t.peak},occupants:t.occupants.slice()})),map:{...e}}}function tf(t,e,o){t.length>8||o.length>40?(function(t,e,o,n=6){const i=t.length;if(1>=i)return;let r=Jh(t,e),s=Qh(e,o);for(let a=0;n>a;a++){const n=Array(i).fill(0),a=Array(i).fill(0);for(const t of o){const o=e[t.source],i=e[t.target];n[o]+=i*(t.value||1),a[o]+=t.value||1,n[i]+=o*(t.value||1),a[i]+=t.value||1}const l=Array.from({length:i},(t,e)=>e).sort((t,e)=>(a[t]>0?n[t]/a[t]:t)-(a[e]>0?n[e]/a[e]:e)),c=l.map(e=>t[e]),u=new Map;l.forEach((t,e)=>u.set(t,e));for(const t of Object.keys(e))e[t]=u.get(e[t]);t.length=0;for(const e of c)t.push(e);const d=Qh(e,o);if(s>d)s=d,r=Jh(t,e);else if(d===s)break}!function(t,e,o){t.length=0;for(const e of o.slots)t.push(e);for(const t of Object.keys(e))delete e[t];for(const t of Object.keys(o.map))e[t]=o.map[t]}(t,e,r)}(t,e,o,6),function(t,e,o,n=6){const i=t.length;if(1>=i)return;let r=Qh(e,o);for(let s=0;n>s;s++){let n=!1;for(let s=0;i-1>s;s++){const i=t[s];t[s]=t[s+1],t[s+1]=i;for(const t of Object.keys(e))e[t]===s?e[t]=s+1:e[t]===s+1&&(e[t]=s);const a=Qh(e,o);if(r>a)r=a,n=!0;else{const o=t[s];t[s]=t[s+1],t[s+1]=o;for(const t of Object.keys(e))e[t]===s?e[t]=s+1:e[t]===s+1&&(e[t]=s)}}if(!n)break}}(t,e,o,6)):function(t,e,o){const n=t.length;if(1>=n)return;const i={...e},r=Object.keys(i),s=Array.from({length:n},(t,e)=>e),a=s.slice(),l={...i};let c=s.slice(),u=1/0;const d=()=>{for(const t of r)l[t]=a[i[t]];const t=Qh(l,o);u>t&&(u=t,c=s.slice())},h=(t,e)=>{const o=s[t],n=s[e];s[t]=n,s[e]=o,a[o]=e,a[n]=t};d();const f=Array(n).fill(0);let p=0;for(;n>p;)p>f[p]?(h(p%2==0?0:f[p],p),d(),f[p]++,p=0):(f[p]=0,p++);const y=c.map(e=>t[e]),g=new Map;c.forEach((t,e)=>g.set(t,e));for(const t of Object.keys(e))e[t]=g.get(e[t]);t.length=0;for(const e of y)t.push(e)}(t,e,o)}function ef(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="full"}=i,d={},h={};for(const e of t)d[e.id]=o[e.id].topPeak||0,h[e.id]=o[e.id].botPeak||0;const f="half"===u,p={};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=f?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of n.incoming[e.id]){const e=f?(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)}p[e.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}const y={},g=[];if("reuse"===l){const o=new Map;for(const e of t)o.set(e.id,0);const i=new Map;for(const e of t)i.set(e.id,0);for(const t of e)i.set(t.target,(i.get(t.target)??0)+1);const r=[];for(const e of t)0===(i.get(e.id)??0)&&r.push(e.id);for(;r.length;){const t=r.shift();for(const e of n.outgoing[t]??[]){const n=(o.get(t)??0)+1;n>(o.get(e.target)??0)&&o.set(e.target,n),i.set(e.target,i.get(e.target)-1),0===i.get(e.target)&&r.push(e.target)}}const s=[...t].filter(t=>null!==p[t.id].start).sort((t,e)=>{const n=o.get(t.id)??0,i=o.get(e.id)??0;return n!==i?n-i:p[t.id].start-p[e.id].start}),a=t.filter(t=>null===p[t.id].start);for(const t of[...s,...a]){const e=p[t.id];let o=-1;for(let t=0;g.length>t;t++){const n=g[t].occupants[g[t].occupants.length-1];if(null===e.start||void 0===n||e.start>=n.end){o=t;break}}-1===o&&(g.push({occupants:[],peak:{topPeak:0,botPeak:0}}),o=g.length-1),g[o].occupants.push({id:t.id,end:e?.end??-1/0}),g[o].peak.topPeak=Math.max(g[o].peak.topPeak,d[t.id]),g[o].peak.botPeak=Math.max(g[o].peak.botPeak,h[t.id]),y[t.id]=o}}else t.forEach((t,e)=>{g.push({occupants:[{id:t.id,end:p[t.id]?.end??-1/0}],peak:{topPeak:d[t.id],botPeak:h[t.id]}}),y[t.id]=e});let m=null,b=null,x=null,v=null;const w=()=>{m=Kh(y,e),x=Zh(y,e)},k=()=>{b=Kh(y,e),v=Zh(y,e)};"crossing-min"===c?(w(),tf(g,y,e),k()):"inside-out"===c?(w(),function(t,e){const o=t.length;if(1>=o)return;const n=t=>t.peak.topPeak+t.peak.botPeak,i=t.map((t,e)=>({slot:t,idx:e})).sort((t,e)=>n(e.slot)-n(t.slot)),r=Array(o),s=Math.floor((o-1)/2);r[s]=i[0].idx;let a=s-1,l=s+1;for(let t=1;i.length>t;t++)t%2==1&&o>l||0>a?r[l++]=i[t].idx:r[a--]=i[t].idx;const c=r.map(e=>t[e]),u=new Map;r.forEach((t,e)=>u.set(t,e));for(const t of Object.keys(e))e[t]=u.get(e[t]);t.length=0;for(const e of c)t.push(e)}(g,y),k()):"crossing-min+inside-out"===c&&(w(),tf(g,y,e),function(t,e,o){const n=t.length;if(1>=n)return;const i=t.map(t=>{return{slot:t,size:(e=t,e.peak.topPeak+e.peak.botPeak)};var e}).sort((t,e)=>e.size-t.size),r=Math.floor((n-1)/2);let s=Qh(e,o);for(const{slot:a}of i){const i=t.indexOf(a);if(0>i)continue;const l=r;if(i===l)continue;const c=t[i];t.splice(i,1),t.splice(l,0,c);const u=new Map;for(let t=0;n>t;t++)u.set(t,t);if(l>i){for(let t=i+1;l>=t;t++)u.set(t,t-1);u.set(i,l)}else{for(let t=l;i>t;t++)u.set(t,t+1);u.set(i,l)}for(const t of Object.keys(e))e[t]=u.get(e[t]);const d=Qh(e,o);if(d>s){const o=t[l];t.splice(l,1),t.splice(i,0,o);const r=new Map;for(let t=0;n>t;t++)r.set(t,t);if(i>l){for(let t=l+1;i>=t;t++)r.set(t,t-1);r.set(l,i)}else{for(let t=i;l>t;t++)r.set(t,t+1);r.set(l,i)}for(const t of Object.keys(e))e[t]=r.get(e[t])}else s=d}}(g,y,e),k());const S=g.map(t=>{const e=new Map;for(const n of t.occupants){const t=o[n.id];if(t)for(const o of t.samples){const t=e.get(o.t)||{top:0,bot:0};e.set(o.t,{top:Math.max(t.top,o.topMass),bot:Math.max(t.bot,o.botMass)})}}return[...e.entries()].sort((t,e)=>t[0]-e[0])}),A=(t,e)=>{let o={top:0,bot:0};for(const[n,i]of t){if(n>e)break;o=i}return o},M=[];for(let t=0;g.length-1>t;t++){const e=S[t],o=S[t+1],n=new Set([...e.map(t=>t[0]),...o.map(t=>t[0])]);let i=0;for(const t of n){const n=A(e,t),r=A(o,t);n.bot+r.top>i&&(i=n.bot+r.top)}M.push(i)}const _=[];let P=s+(g[0]?.peak.topPeak??0)*a;g.length>0&&_.push(P);for(let t=1;g.length>t;t++)P+=M[t-1]*a+s,_.push(P);if(g.length>0&&(P+=g[g.length-1].peak.botPeak*a+s),P>r){const t=r/P;for(let e=0;_.length>e;e++)_[e]*=t}const C=0===g.length?0:g[0].peak.topPeak+M.reduce((t,e)=>t+e,0)+g[g.length-1].peak.botPeak,R={};for(const e of t)R[e.id]=_[y[e.id]];return{effectiveSlotsHeight:C,centerlines:R,laneLifetime:p,slots:g,slotByNode:y,slotCenter:_,crossingsBefore:m,crossingsAfter:b,lengthBefore:x,lengthAfter:v}}function of(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 nf(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,edgeOpacity:a,colorOf:l,layoutOpts:c}=t,u=function(t,e,o){const n=[],i=new Set(t.map(t=>t.id)),r=Array.isArray(o)&&2===o.length,s=r&&Number.isFinite(o[0])&&Number.isFinite(o[1]);r&&s&&s&&o[1]>=o[0]||n.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]||n.push({kind:"invalid-node-time",id:e.id}));for(const t of e)i.has(t.source)||n.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),i.has(t.target)||n.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?(Number.isFinite(t.value)&&t.value>0||n.push({kind:"invalid-value",id:t.id}),t.endTime>t.startTime||n.push({kind:"backward-edge",id:t.id,source:t.source,target:t.target})):n.push({kind:"invalid-edge-time",id:t.id});return n}(e,o,n),d=Gh().domain(n).range([0,i]);if(u.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!0},issues:u,xScale:d};const h=function(t,e,o){const{plotH:n,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half"}=o,l=function(t,e){const o={},n={};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),c=function(t,e,o,n="value"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime:(t,e)=>e.value-t.value,r="temporal"===n?(t,e)=>t.startTime-e.startTime:(t,e)=>e.value-t.value,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:t.latestEnd-o.latestEnd:(t,e)=>e.total-t.total);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,l,i);let u={};for(const e of t)u[e.id]=qh(e,l,c);const d=ef(t,e,u,l,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a}),h=new Set;for(const t of e){const e=d.slotByNode[t.source],o=d.slotByNode[t.target];if(void 0===e||void 0===o)continue;const n=c.get(t.id);e!==o?e>o?(n.sourceSide="top",n.targetSide="bot"):(n.sourceSide="bot",n.targetSide="top"):(h.add(t.id),n.sourceSide="bot",n.targetSide="bot")}for(const e of t){const t=l.outgoing[e.id],o=l.incoming[e.id],n=new Set(t.map(t=>c.get(t.id).sourceSide)),i=new Set(o.map(t=>c.get(t.id).targetSide));if(1===n.size&&o.length>0){const t=[...n][0];for(const e of o)d.slotByNode[e.source]===d.slotByNode[e.target]&&(c.get(e.id).targetSide=t)}if(1===i.size&&t.length>0){const e=[...i][0];for(const o of t)d.slotByNode[o.source]===d.slotByNode[o.target]&&(c.get(o.id).sourceSide=e)}}for(const e of t){const t=l.incoming[e.id],o=l.outgoing[e.id];if(0===t.length||0===o.length)continue;const n=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===c.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of o)"top"===c.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},i=(t,e)=>{const i=n(),r="top"===t?i.outTop-i.inTop:i.outBot-i.inBot,s="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=r||0>=s)return!1;const a=Math.min(r,s),l=o.filter(e=>!h.has(e.id)&&c.get(e.id).sourceSide===t&&a>=e.value).sort((t,e)=>e.value-t.value);return 0!==l.length&&(c.get(l[0].id).sourceSide=e,!0)};let r=o.length+1;for(;r-- >0&&(i("top","bot")||i("bot","top")););}u={};for(const e of t)u[e.id]=qh(e,l,c);const f=ef(t,e,u,l,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a}),p=f.effectiveSlotsHeight??f.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),y=Math.min(12,.35*n/Math.max(f.slots.length+1,1)),g=p>0?Math.max(0,(n-y*(f.slots.length+1))/p):1,m=ef(t,e,u,l,{plotH:n,padding:y,valueScale:g,packing:r,laneOrder:s,lifetimeMode:a});return{nodeData:u,sides:c,valueScale:g,padding:y,compressedPadding:12>y,centerlines:m.centerlines,laneLifetime:m.laneLifetime,slots:m.slots,slotByNode:m.slotByNode,crossingsBefore:m.crossingsBefore,crossingsAfter:m.crossingsAfter,lengthBefore:m.lengthBefore,lengthAfter:m.lengthAfter}}(e,o,{plotH:r,...c}),{centerlines:f,nodeData:p,valueScale:y}=h,g=[],m=[];e.forEach((t,e)=>{const i=p[t.id];if(!i||0===i.samples.length)return;const r=function(t,e,o,n,i){if(0===t.length)return null;const r=Xh(t,i),s=t=>e-r[t].topMass*o,a=t=>e+r[t].botMass*o;let l=`M${n(r[0].t)},${s(0)}`;for(let t=1;r.length>t;t++)l+=` L${n(r[t].t)},${s(t)}`;l+=` L${n(r[r.length-1].t)},${a(r.length-1)}`;for(let t=r.length-2;t>=0;t--)l+=` L${n(r[t].t)},${a(t)}`;return l+" Z"}(i.samples,f[t.id],y,d,n);if(!r)return;const s=Xh(i.samples,n),a=s.find(t=>t.topMass+t.botMass>0)||s[0],c=f[t.id]+(a.botMass-a.topMass)*y/2,u=l(t.id,e),m=function(t,e,o,n,i){const r=o.nodeData[t];if(!r||0===r.samples.length)return[];const s=o.valueScale,a=o.centerlines[t],l=Xh(r.samples,i),c=l.find(t=>t.topMass+t.botMass>0)||l[0],u=[...l].reverse().find(t=>t.topMass+t.botMass>0)||l[l.length-1],d=n(c.t),h=n(u.t),f=t=>n(Vh(t,i)),p=[],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=r.localAttachments.get(o.id);if(t&&"out"===t.kind&&o.startTime>o.systemInTime){const e=f(o.systemInTime),n=f(o.startTime),i=e-20,r=Math.max(d,i);if(n>r){const[o,l]=Uh(t,a,s);p.push({pathD:y(r,o,n,l),x0:i,x1:e,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=r.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(h,i);if(r>n){const[o,l]=Uh(t,a,s);p.push({pathD:y(n,o,r,l),x0:e,x1:i,from:1,to:0})}}}}return p}(t.id,o,h,d,n);g.push({id:t.id,pathD:r,fill:u,stroke:u,strokeWidth:.5,...m.length>0&&{gradientStubs:m},rawDatum:t.__raw??t,labelX:d(a.t)-4,labelY:c,labelText:t.id})});const b=new Map;return e.forEach((t,e)=>b.set(t.id,e)),o.forEach(t=>{const e=p[t.source]?.localAttachments.get(t.id),o=p[t.target]?.localAttachments.get(t.id);if(!e||!o)return;const i=b.get(t.source)??0,r=l(t.source,i),c=function(t,e,o,n,i,r,s,a){const l=i,c=t=>a?Math.max(a[0],Math.min(a[1],t)):t,u=r(c(t.time)),d=r(c(o.time)),h=t.value*l,f=o.value*l,p=t.sideMassBefore*l,y=o.sideMassAfter*l;let g,m,b,x;"top"===t.side?(g=e-p,m=g+h):(m=e+p,g=m-h),"top"===o.side?(b=n-y,x=b+f):(x=n+y,b=x-f);const v="source"===s?u+.85*(d-u):"target"===s?u+.15*(d-u):(u+d)/2;return{sx:u,sTop:g,sBot:m,tx:d,tTop:b,tBot:x,cp1X:v,cp2X:v}}(e,f[t.source],o,f[t.target],y,d,s,n),{pathD:u,bezier:h}=of(c);m.push({id:t.id,pathD:u,fill:r,opacity:a,rawDatum:t.__raw??t,bezier:h})}),{layout:h,layoutConfig:{bands:g,ribbons:m,showLabels:!0},issues:[],xScale:d}}var rf=t=>{const{bands:e=[],ribbons:o=[],showLabels:n=!0}=t.config,i=[];for(const t of o)i.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:t.opacity,stroke:"none"},datum:{__kind:"ribbon",data:t.rawDatum,id:t.id}});for(const t of e)if(t.gradientStubs)for(let e=0;t.gradientStubs.length>e;e++){const o=t.gradientStubs[e];i.push({type:"bezier",pathD:o.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:.86,stroke:"none"},_gradient:{x0:o.x0,x1:o.x1,from:o.from,to:o.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${e}`}})}for(const t of e)i.push({type:"bezier",pathD:t.pathD,style:{...t.gradientStubs&&t.gradientStubs.length>0?{fill:"none"}:{fill:t.fill,fillOpacity:.86},stroke:t.stroke??t.fill,strokeWidth:t.strokeWidth??.5},datum:{__kind:"band",data:t.rawDatum,id:t.id}});const r=n?e.map(t=>({x:t.labelX,y:t.labelY,text:t.labelText,anchor:"end",baseline:"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:i,labels:r}};function sf(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 af(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 lf(t,e,o={}){return _t(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}import*as cf from"react";var uf={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=C(n.theme).colors.categorical,a=new Map,l=i.nodeStyle??(t=>({fill:e?xt(t?.data||t,e,void 0):yd(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=zt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=_t(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}}},df={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,n,i)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,f=i.systemOutTimeAccessor,p=i.xExtentAccessor||"xExtent",y=i.edgeIdAccessor||"id",g=(t,e)=>"function"==typeof t?t(e):e[t],m=Array.isArray(i.edges)?i.edges:[],b=Array.isArray(i.nodes)?i.nodes:[],x=b.length>0?b:af([],m,s,a),v=[r(i.domain?.[0]),r(i.domain?.[1])],w=x.map(t=>{const e=g(c,t)+"",o=g(p,t),n={id:e,__raw:t};if(Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(n.xExtent=[t,e])}return n}),k=m.map((t,e)=>{const o=g(y,t),n={id:null!=o?o+"":`${g(s,t)}-${g(a,t)}-${e}`,source:g(s,t)+"",target:g(a,t)+"",value:Number(g(l,t)),startTime:r(g(u,t)),endTime:r(g(d,t)),__raw:t};if(h){const e=r(g(h,t));Number.isFinite(e)&&(n.systemInTime=e)}if(f){const e=r(g(f,t));Number.isFinite(e)&&(n.systemOutTime=e)}return n}),[S,A]=n.size??[600,400],M={top:20,right:20,bottom:20,left:20,...n.margin},_=(n.showLegend??!!e)&&!!e,P=n.legendPosition??"right",R=n.__explicitMargin,L=t=>"number"==typeof R||null!=R&&"object"==typeof R&&null!=R[t];_&&("right"!==P||L("right")?"bottom"!==P||L("bottom")||(M.bottom=Math.max(M.bottom,80)):M.right=Math.max(M.right,140));const I=M,T=S-I.left-I.right,$=A-I.top-I.bottom,z=yt(o,C(n.theme).colors.categorical,G),D="function"==typeof e?e:null,F=D?x.map(t=>({_cat:D(t)})):x,E=D?"_cat":"string"==typeof e?e:void 0,O=o??[...z],B=E?wt(F,E,O):null,N=new Map;for(const t of w)N.set(t.id,t.__raw);const W=(t,o)=>{if(e&&N.has(t)){const o=N.get(t);return D?xt({_cat:D(o)},"_cat",B??void 0):xt(o,"string"==typeof e?e:"id",B??void 0)}return z[o%z.length]},j=Fi(_&&e?(()=>{const t=new Map;x.forEach((o,n)=>{const i=g(e,o),r=null==i?"":i+"";r&&!t.has(r)&&t.set(r,{label:r,color:W(g(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),{layout:Y,layoutConfig:H,issues:q,xScale:V}=nf({nodes:w,edges:k,domain:v,plotW:T,plotH:$,ribbonLane:i.ribbonLane||"both",edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:W,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half"}});if(q.length>0){const t=q.map(Hh).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const X=Array.isArray(i.axisTicks)?i.axisTicks:[],U=Y?(()=>{let t=null,e=null;for(const o of w){const n=Y.laneLifetime[o.id];if(!n||null==n.start||null==n.end)continue;const i=Number(V(n.start)),r=Number(V(n.end));t=null==t?i:Math.min(t,i),e=null==e?r:Math.max(e,r)}const o=t=>Math.max(0,Math.min(T,t)),n=o(t??0),s=Math.max(n,o(e??T)),a=X.map((t,e)=>({tick:t,index:e,x:Number(V(r(t.date)))})).filter(({x:t})=>t>=n-.5&&s+.5>=t);return cf.createElement("g",null,...a.map(({index:t,x:e})=>cf.createElement("line",{key:"grid-"+t,x1:e,y1:0,x2:e,y2:$,stroke:"#94a3b8",strokeOpacity:.15,strokeDasharray:"2 4"})),cf.createElement("line",{key:"axis",x1:n,y1:$+4,x2:s,y2:$+4,stroke:"#94a3b8"}),...a.map(({tick:t,index:e,x:o})=>{const n=r(t.date),s=null!=t.label?t.label:"function"==typeof i.timeFormat?i.timeFormat(new Date(n)):"";return cf.createElement("g",{key:"tick-"+e,transform:`translate(${o},${$+4})`},cf.createElement("line",{y2:6,stroke:"#94a3b8"}),cf.createElement("text",{y:20,textAnchor:"middle",fontSize:11,fill:"#475569"},s))}))})():void 0;return{chartType:"force",nodes:x,edges:m,customNetworkLayout:rf,layoutConfig:H,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:e,colorScheme:o,...U&&{backgroundGraphics:U},...n,showLegend:_,...j&&{legend:j,legendPosition:P},__legendIncludesAutomatic:!0,margin:I}}},hf={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:af([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=C(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?wt(c,l,o??n.colorScheme??s):void 0,d=t=>({fill:e?xt(t?.data||t,e,u):yd(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=zt(i.styleRules,e,i.valueAccessor),f=h?(t,e)=>({...d(t),...h(t,e)}):d,p=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:n,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof t)a.fill=t(s);else if("source"===t){const t="object"==typeof s.source?s.source:null;e&&t?a.fill=xt(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=xt(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:f,edgeOpacity:i.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,valueAccessor:i.valueAccessor,orientation:i.orientation,nodeAlign:i.nodeAlign,nodeWidth:i.nodeWidth,nodePaddingRatio:i.nodePaddingRatio,showLabels:i.showLabels,nodeLabel:i.nodeLabel,colorBy:e,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:_t(i.nodeStyle||f,Wt(i)),edgeStyle:_t(i.edgeStyle||p,Wt(i)),colorScheme:o,...n}}},ff={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||Mt(Wt(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:af([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=C(n.theme).colors.categorical,l=yt(o,a),c="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?wt(u,c,o??n.colorScheme??a):void 0,h=new Map,f=i.nodeIdAccessor||i.nodeIDAccessor||"id",p=(t,o)=>{const n=t?.data||t;let r;if(e)r=xt(n,e,d);else{const e=(t.id??n?.[f]??"")+"";h.has(e)||h.set(e,h.size);const i=t.index??o??h.get(e);r=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},y=zt(i.styleRules,e,i.valueAccessor,p)??p;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:_t(i.nodeStyle||y,Wt(i)),...n}}},pf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=C(n.theme).colors.categorical,s=new Map,a=sf(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?wt(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:lf(t=>{const n=t?.data||t;return{fill:i.colorByDepth?mt[Number(t?.depth||0)%mt.length]:e?l?xt({__ssrTreeColorBy:l(n)},"__ssrTreeColorBy",d??void 0):xt(n,e,d??void 0):yd(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,Wt(i))}}},yf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=C(n.theme).colors.categorical,s=new Map,a=sf(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?wt(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,f=i.labelMode,p=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,y=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,g=n.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:f,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=y&&{paddingTop:y},colorScheme:o,...n,nodeStyle:lf(t=>{const n=t?.data||t;return{fill:i.colorByDepth?mt[Number(t?.depth||0)%mt.length]:e?l?xt({__ssrTreemapColorBy:l(n)},"__ssrTreemapColorBy",d??void 0):xt(n,e,d??void 0):yd(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},g,Wt(i))}}},gf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=C(n.theme).colors.categorical,s=new Map,a=sf(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?wt(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:lf(t=>{const n=t?.data||t;return{fill:i.colorByDepth?mt[Number(t?.depth||0)%mt.length]:e?l?xt({__ssrCirclePackColorBy:l(n)},"__ssrCirclePackColorBy",d??void 0):xt(n,e,d??void 0):yd(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,Wt(i))}}},mf={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as bf}from"d3-scale";function xf(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var vf={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=i.areaStyle??function(t,e,o,n){if(!Array.isArray(t))return;const i=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let r=1/0,s=-1/0;for(const e of t){const t=i(e);null!=t&&isFinite(t)&&(r>t&&(r=t),t>s&&(s=t))}const a=bf(it(o)).domain([Number.isFinite(r)?r:0,Number.isFinite(s)?s:1]);return t=>{const e=i(t);return{fill:null!=e&&isFinite(e)?a(e):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:n}}}(i.areas,i.valueAccessor,r,i.areaOpacity??1),a=i.styleRules?$t(s,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},xf):s;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:a,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n}}},wf={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=wt(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?xt(t,e,r):pt,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?kt(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?$t(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||mf,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},kf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=(Array.isArray(t)?t:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:t=>t[l],d="function"==typeof c?c:t=>t[c],h=(i.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),f=new Map;for(const t of h)f.set(t[s]+"",t);const p=i.edgeColorBy??e,y="function"==typeof p,g=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=f.get(t.source+""),o=f.get(t.target+"");return e&&o?{...t,coordinates:[{x:e.x,y:e.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",b=p?y?wt(g.map(t=>({[m]:p(t)})),m,o||"category10"):wt(g,p,o||"category10"):null,x=t=>p&&b?xt(t,p,b):"#007bff";let v=1/0,w=-1/0;for(const t of g){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[S,A]=i.edgeWidthRange??[1,8],M=A-S,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:g,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||mf,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=S+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:x(t),strokeWidth:n,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...n}}};import*as Sf from"react";function Af(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 Mf(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 _f(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?Pt(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:Mf(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,Tt(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}function Pf(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 Cf(t,e,o){return"function"==typeof o?o(t,e):t[o]}function Rf(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 Lf(t,e,o){return Math.max(e,Math.min(o,t))}function If(t,e){const o=Rf(t);return null!=o&&o>0?o:e}function Tf(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function $f(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 zf}from"d3-scale";var Df={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},Ff=1e-9,Ef=.005;function Of(t){return"circle"===t.type?{type:"circle",radius:t.radius}:{type:"aabb",width:t.width,height:t.height}}function Bf(t){return"aabb"===t.type?{type:"aabb",x:t.x,y:t.y,width:t.width,height:t.height}:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:t.thickness}}function Nf(t,e,o){return Math.max(e,Math.min(o,t))}function Wf(t){return 0>t?-1:1}function jf(t){if("circle"===t.shape.type){const e=t.shape.radius;return{minX:t.x-e,minY:t.y-e,maxX:t.x+e,maxY:t.y+e}}const e=t.shape.width/2,o=t.shape.height/2;return{minX:t.x-e,minY:t.y-o,maxX:t.x+e,maxY:t.y+o}}function Yf(t){const e=t.shape;if("aabb"===e.type){const t=e.width/2,o=e.height/2;return{minX:e.x-t,minY:e.y-o,maxX:e.x+t,maxY:e.y+o}}const o=(e.thickness??0)/2;return{minX:Math.min(e.x1,e.x2)-o,minY:Math.min(e.y1,e.y2)-o,maxX:Math.max(e.x1,e.x2)+o,maxY:Math.max(e.y1,e.y2)+o}}function Gf(t,e){return!(t.minX>e.maxX||e.minX>t.maxX||t.minY>e.maxY||e.minY>t.maxY)}function Hf(t,e,o,n,i,r,s,a){const l=i-t,c=(o+s)/2-Math.abs(l);if(0>=c)return null;const u=r-e,d=(n+a)/2-Math.abs(u);return d>0?d>c?{nx:Wf(l),ny:0,penetration:c}:{nx:0,ny:Wf(u),penetration:d}:null}function qf(t,e,o,n,i,r,s){const a=r/2,l=s/2;let c=t-Nf(t,n-a,n+a),u=e-Nf(e,i-l,i+l);const d=c*c+u*u;if(d>o*o)return null;if(Ff>=d){const r=Math.abs(t-(n-a)),s=Math.abs(t-(n+a)),d=Math.abs(e-(i-l)),h=Math.abs(e-(i+l)),f=Math.min(r,s,d,h);return f===r?(c=-1,u=0,{nx:c,ny:u,penetration:o+r}):f===s?(c=1,u=0,{nx:c,ny:u,penetration:o+s}):f===d?(c=0,u=-1,{nx:c,ny:u,penetration:o+d}):(c=0,u=1,{nx:c,ny:u,penetration:o+h})}const h=Math.sqrt(d);return{nx:c/h,ny:u/h,penetration:o-h}}function Vf(t,e){if("circle"===t.shape.type&&"circle"===e.shape.type)return function(t,e,o,n,i,r){const s=n-t,a=i-e,l=o+r,c=s*s+a*a;if(c>=l*l)return null;if(Ff>=c)return{nx:1,ny:0,penetration:l};const u=Math.sqrt(c);return{nx:s/u,ny:a/u,penetration:l-u}}(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.radius);if("aabb"===t.shape.type&&"aabb"===e.shape.type)return Hf(t.x,t.y,t.shape.width,t.shape.height,e.x,e.y,e.shape.width,e.shape.height);if("circle"===t.shape.type&&"aabb"===e.shape.type){const o=qf(t.x,t.y,t.shape.radius,e.x,e.y,e.shape.width,e.shape.height);return o?{nx:-o.nx,ny:-o.ny,penetration:o.penetration}:null}return"aabb"===t.shape.type&&"circle"===e.shape.type?qf(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.width,t.shape.height):null}function Xf(t,e){const o=e.shape;return"aabb"===o.type?"circle"===t.shape.type?qf(t.x,t.y,t.shape.radius,o.x,o.y,o.width,o.height):Hf(o.x,o.y,o.width,o.height,t.x,t.y,t.shape.width,t.shape.height):function(t,e,o,n,i,r,s,a=0){const l=r-n,c=s-i,u=l*l+c*c,d=u>Ff?Nf(((t-n)*l+(e-i)*c)/u,0,1):0,h=o+a/2,f=t-(n+l*d),p=e-(i+c*d),y=f*f+p*p;if(y>=h*h)return null;if(Ff>=y){const t=Math.sqrt(u);return t>Ff?{nx:-c/t,ny:l/t,penetration:h}:{nx:1,ny:0,penetration:h}}const g=Math.sqrt(y);return{nx:f/g,ny:p/g,penetration:h-g}}(t.x,t.y,"circle"===t.shape.type?t.shape.radius:Math.sqrt(t.shape.width*t.shape.width+t.shape.height*t.shape.height)/2,o.x1,o.y1,o.x2,o.y2,o.thickness??0)}function Uf(t,e){return`${t}\0${e}`}function Kf(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Zf(t){return{id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,bodyCollisions:t.bodyCollisions,shape:Of(t.shape),sleeping:t.sleeping,datum:t.datum,index:t.index,sleepTime:t.sleepTime,restitution:t.restitution,friction:t.friction}}function Qf(t){return t&&"function"!=typeof t?{property:t.property,equals:t.equals,notEquals:t.notEquals,oneOf:t.oneOf?.slice(),notOneOf:t.notOneOf?.slice()}:t}function Jf(t){return{id:t.id,shape:Bf(t.shape),sensor:t.sensor,restitution:t.restitution,friction:t.friction,bodyFilter:Qf(t.bodyFilter),index:t.index}}function tp(t,e){return!!e?.some(e=>Object.is(t,e))}function ep(t,e){const o=t.bodyFilter;if(!o)return!0;if("function"==typeof o)return o(e);const n=function(t,e){if(!e)return;let o=t;for(const t of e.split(".")){if(null==o||"object"!=typeof o)return;o=o[t]}return o}(e,o.property);return!("equals"in o&&!Object.is(n,o.equals)||"notEquals"in o&&Object.is(n,o.notEquals)||o.oneOf&&!tp(n,o.oneOf)||o.notOneOf&&tp(n,o.notOneOf))}var op=class{constructor(t={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=new Map,this.colliders=new Map,this.springs=new Map,this.activeSensors=new Set,this.supportedThisStep=new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...Df,...t},this.random=u(this.options.seed)}init(t={}){this.options={...Df,...t},this.random=u(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(t){const e={id:t.id,x:t.x,y:t.y,prevX:t.x,prevY:t.y,vx:t.vx??0,vy:t.vy??0,angle:t.angle??0,mass:Math.max(Ff,t.mass??1),bodyCollisions:t.bodyCollisions??!0,shape:Of(t.shape),sleeping:!1,datum:t.datum,restitution:t.restitution,friction:t.friction,index:this.nextBodyIndex,sleepTime:0};this.nextBodyIndex+=1,this.bodies.set(t.id,e)}remove(t){for(const e of t){this.bodies.delete(e);for(const t of Array.from(this.activeSensors))Kf(t).bodyId===e&&this.activeSensors.delete(t)}}setColliders(t){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(const e of t)this.colliders.set(e.id,{...e,shape:Bf(e.shape),bodyFilter:Qf(e.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(t){const e=t.id??"spring-"+this.nextSpringIndex;return this.springs.set(e,{id:e,bodyId:t.bodyId,target:t.target,restLength:t.restLength??0,stiffness:t.stiffness??40,damping:t.damping??3}),this.nextSpringIndex+=1,e}removeConstraint(t){this.springs.delete(t)}applyImpulse(t,e,o){const n=this.bodies.get(t);n&&(n.vx+=e/n.mass,n.vy+=o/n.mass,this.wake(n))}step(t=this.options.fixedDt){const e=Math.max(0,t);if(this.lastEvents=[],0===e)return;const o=this.sortedBodies();for(const t of o)t.prevX=t.x,t.prevY=t.y;this.applySprings(e);const n=this.options.maxVelocity;for(const t of o)if(!t.sleeping){if(t.vx+=this.options.gravity.x*e,t.vy+=this.options.gravity.y*e,t.vx*=this.options.velocityDamping,t.vy*=this.options.velocityDamping,n>0){const e=Math.sqrt(t.vx*t.vx+t.vy*t.vy);if(e>n){const o=n/e;t.vx*=o,t.vy*=o}}t.x+=t.vx*e,t.y+=t.vy*e}this.supportedThisStep.clear();const i=this.bodyPairKeys(o),r=this.sortedColliders().filter(t=>!t.sensor);for(let t=0;this.options.collisionIterations>t;t+=1)this.resolveBodyPairs(o,i,0===t),this.resolveColliders(o,r,0===t);this.updateSensors(o),this.updateSleeping(o,e)}settle(t=1200,e=this.options.fixedDt){let o=0;for(;t>o&&!this.allSleeping();)this.step(e),o+=1;return o}readState(t=[]){t.length=0;for(const e of this.sortedBodies())t.push({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:Of(e.shape),sleeping:e.sleeping,datum:e.datum});return t}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(Kf)}allSleeping(){for(const t of this.bodies.values())if(!t.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(Zf),colliders:this.sortedColliders().map(Jf),springs:Array.from(this.springs.values()).map(t=>({...t,target:{...t.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(t){this.options={...t.options,gravity:{...t.options.gravity}},this.random=u(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(t.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(const e of t.bodies){const t=Zf(e);this.bodies.set(t.id,t),this.nextBodyIndex=Math.max(this.nextBodyIndex,t.index+1)}this.nextColliderIndex=0;for(const e of t.colliders){const t=Jf(e);this.colliders.set(t.id,t),this.nextColliderIndex=Math.max(this.nextColliderIndex,t.index+1)}this.nextSpringIndex=0;for(const e of t.springs){this.springs.set(e.id,{...e,target:{...e.target}});const t=/^spring-(\d+)$/.exec(e.id);t&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(t[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((t,e)=>t.index-e.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((t,e)=>t.index-e.index)}applySprings(t){for(const e of Array.from(this.springs.values()).sort((t,e)=>t.id.localeCompare(e.id))){const o=this.bodies.get(e.bodyId);if(!o||o.sleeping)continue;const n="point"===e.target.type?e.target:this.bodies.get(e.target.bodyId);if(!n)continue;const i=n.x-o.x,r=n.y-o.y,s=Math.sqrt(i*i+r*r);if(Ff>=s)continue;const a=i/s,l=r/s,c=(s-e.restLength)*e.stiffness+((("vx"in n?n.vx:0)-o.vx)*a+(("vy"in n?n.vy:0)-o.vy)*l)*e.damping;o.vx+=c*a*t/o.mass,o.vy+=c*l*t/o.mass}}resolveBodyPairs(t,e,o){for(const n of e){const[e,i]=n.split(":").map(Number),r=t[e],s=t[i];if(!r||!s)continue;const a=Vf(r,s);a&&(this.resolveDynamicCollision(r,s,a),o&&this.lastEvents.push({type:"contact",bodyId:r.id,otherId:s.id,sensor:!1}))}}bodyPairKeys(t){const e=Math.max(1,this.options.cellSize),o=new Map;for(let n=0;t.length>n;n+=1){if(!1===t[n].bodyCollisions)continue;const i=jf(t[n]),r=Math.floor(i.minX/e),s=Math.floor(i.maxX/e),a=Math.floor(i.minY/e),l=Math.floor(i.maxY/e);for(let t=r;s>=t;t+=1)for(let e=a;l>=e;e+=1){const i=`${t}:${e}`,r=o.get(i);r?r.push(n):o.set(i,[n])}}const n=new Set;for(const e of Array.from(o.keys()).sort()){const i=o.get(e)??[];i.sort((t,e)=>t-e);for(let e=0;i.length>e;e+=1)for(let o=e+1;i.length>o;o+=1){const r=i[e],s=i[o];!1!==t[r].bodyCollisions&&!1!==t[s].bodyCollisions&&Gf(jf(t[r]),jf(t[s]))&&n.add(`${r}:${s}`)}}return Array.from(n).sort((t,e)=>{const[o,n]=t.split(":").map(Number),[i,r]=e.split(":").map(Number);return o===i?n-r:o-i})}resolveDynamicCollision(t,e,o){t.sleeping&&this.contactOpposesGravity(o.nx,o.ny)&&this.supportedThisStep.add(e.id),e.sleeping&&this.contactOpposesGravity(-o.nx,-o.ny)&&this.supportedThisStep.add(t.id);const n=t.sleeping?0:1/t.mass,i=e.sleeping?0:1/e.mass,r=n+i;if(Ff>=r)return;const s=Math.max(0,o.penetration-Ef)/r;t.x-=o.nx*s*n,t.y-=o.ny*s*n,e.x+=o.nx*s*i,e.y+=o.ny*s*i;const a=(e.vx-t.vx)*o.nx+(e.vy-t.vy)*o.ny;if(a>0)return;const l=Math.abs(a),c=-(1+Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution))*a/r,u=c*o.nx,d=c*o.ny;t.vx-=u*n,t.vy-=d*n,e.vx+=u*i,e.vy+=d*i,this.applyFriction(t,e,o,c,n,i),l>this.options.contactWakeSpeed&&(this.wake(t),this.wake(e))}applyFriction(t,e,o,n,i,r){const s=-o.ny,a=o.nx,l=(e.vx-t.vx)*s+(e.vy-t.vy)*a,c=i+r;if(Ff>=Math.abs(l)||Ff>=c)return;const u=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction))),d=Nf(-l/c,-n*u,n*u),h=d*s,f=d*a;t.vx-=h*i,t.vy-=f*i,e.vx+=h*r,e.vy+=f*r}resolveColliders(t,e,o){for(const n of t)for(const t of e){if(!ep(t,n))continue;if(!Gf(jf(n),Yf(t)))continue;const e=Xf(n,t);e&&(this.resolveStaticCollision(n,t,e),this.contactOpposesGravity(e.nx,e.ny)&&this.supportedThisStep.add(n.id),o&&this.lastEvents.push({type:"contact",bodyId:n.id,otherId:t.id,sensor:!1}))}}resolveStaticCollision(t,e,o){t.x+=o.nx*Math.max(0,o.penetration-Ef),t.y+=o.ny*Math.max(0,o.penetration-Ef);const n=t.vx*o.nx+t.vy*o.ny;if(0>n){const i=Math.min(t.restitution??this.options.restitution,e.restitution??this.options.restitution);t.vx-=(1+i)*n*o.nx,t.vy-=(1+i)*n*o.ny;const r=-o.ny,s=o.nx,a=t.vx*r+t.vy*s,l=Math.max(0,Math.min(1,Math.max(t.friction??this.options.friction,e.friction??this.options.friction)));t.vx-=a*r*l,t.vy-=a*s*l}}updateSensors(t){const e=new Set,o=this.sortedColliders().filter(t=>t.sensor);for(const n of t){const t=jf(n);for(const i of o){if(!ep(i,n))continue;if(!Gf(t,Yf(i)))continue;if(!Xf(n,i))continue;const o=Uf(i.id,n.id);e.add(o),this.activeSensors.has(o)||this.lastEvents.push({type:"sensor-enter",bodyId:n.id,sensorId:i.id})}}for(const t of Array.from(this.activeSensors).sort()){if(e.has(t))continue;const{sensorId:o,bodyId:n}=Kf(t);this.lastEvents.push({type:"sensor-exit",bodyId:n,sensorId:o})}this.activeSensors=e}updateSleeping(t,e){const o=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(const n of t)Math.sqrt(n.vx*n.vx+n.vy*n.vy)>=this.options.sleepSpeed||Math.sqrt((n.x-n.prevX)*(n.x-n.prevX)+(n.y-n.prevY)*(n.y-n.prevY))>=this.options.sleepSpeed*e||o&&!this.supportedThisStep.has(n.id)?n.sleeping?this.wake(n):n.sleepTime=0:(n.sleepTime+=e,n.sleeping||this.options.sleepAfter>n.sleepTime||(n.sleeping=!0,n.vx=0,n.vy=0,this.lastEvents.push({type:"sleep",bodyId:n.id})))}contactOpposesGravity(t,e){const{x:o,y:n}=this.options.gravity,i=Math.hypot(o,n);return 1e-9>=i||-.2>(t*o+e*n)/i}wake(t){t.sleeping&&this.lastEvents.push({type:"wake",bodyId:t.id}),t.sleeping=!1,t.sleepTime=0}nextRandom(){return this.random()}},np=class{constructor(t={}){this.id="builtin",this.capabilities={...(new op).capabilities,engine:"builtin"},this.world=new op(t)}init(t={}){this.world.init(t)}spawn(t){this.world.spawn(t)}remove(t){this.world.remove(t)}setColliders(t){this.world.setColliders(t)}setConstraint(t){return this.world.setConstraint(t)}removeConstraint(t){this.world.removeConstraint(t)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o)}step(t){this.world.step(t)}settle(t,e){return this.world.settle(t,e)}readState(t){return this.world.readState(t)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(t){this.world.restore(t)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function ip(t,e={}){return t?"function"==typeof t?t(e):(t.init(e),t):function(t={}){return new np(t)}(e)}var rp=["binId","targetBin","category","windowIndex","lane","group"];function sp(t,e){if(!Number.isFinite(e))return;t.count+=1,t.total+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e);const o=e-t.mean;t.mean+=o/t.count,t.m2+=o*(e-t.mean)}function ap(t){return{count:t.count,total:t.total,mean:t.count>0?t.mean:0,min:t.count>0?t.min:0,max:t.count>0?t.max:0,variance:t.count>1?t.m2/(t.count-1):0}}function lp(t){return{count:t.count,total:t.total,mean:t.mean,m2:t.variance*Math.max(0,t.count-1),min:t.count>0?t.min:1/0,max:t.count>0?t.max:-1/0}}function cp(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function up(t,e,o){return"function"==typeof t?t(e,o):"string"==typeof t?cp(e,t):void 0}function dp(t){if(null==t)return;const e=t+"";return e.trim()?e:void 0}function hp(t){const e=ap(t.value);return{id:t.id,label:t.label,count:e.count,total:e.total,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:ap(t.x),y:ap(t.y),value:e}}var fp=class{constructor(t=!1){this.bins=new Map,this.nextIndex=0,this.config=t}updateConfig(t){void 0!==t&&(this.config=t,!1===t&&this.clear())}isEnabled(){return!1!==this.config}add(t){if(!1===this.config)return null;const e=this.nextIndex;this.nextIndex+=1;const o=dp(up(this.config.binAccessor,t,e))??function(t){for(const e of rp){const o=dp(cp(t,e));if(o)return o}return"sediment"}(t),n=dp(up(this.config.labelAccessor,t,e))??o,i=function(t,e,o){if("number"==typeof t)return t;const n="function"==typeof t?t(e,o):"string"==typeof t?cp(e,t):1,i="number"==typeof n?n:Number(n);return Number.isFinite(i)?i:1}(this.config.valueAccessor,t,e),r=Math.max(0,Math.floor(this.config.retainBodyIds??12));let s=this.bins.get(o);return s||(s={id:o,label:n,bodyIds:[],x:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},y:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0},value:{count:0,total:0,mean:0,m2:0,min:1/0,max:-1/0}},this.bins.set(o,s)),s.label=n,s.lastBodyId=t.id,s.lastDatum=t.datum,sp(s.x,t.x),sp(s.y,t.y),sp(s.value,i),r>0&&(s.bodyIds.push(t.id),s.bodyIds.length>r&&(s.bodyIds=s.bodyIds.slice(s.bodyIds.length-r))),hp(s)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(hp)}restore(t=[]){this.bins.clear();for(const e of t)this.bins.set(e.id,{id:e.id,label:e.label,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:lp(e.x),y:lp(e.y),value:lp(e.value)});this.nextIndex=t.reduce((t,e)=>t+e.count,0)}totals(){const t=this.snapshot();return{bins:t.length,count:t.reduce((t,e)=>t+e.count,0),total:t.reduce((t,e)=>t+e.total,0)}}};function pp(t){const e=Number(t);if(Number.isFinite(e)&&e>0)return Math.floor(e)}var yp={bodyLimit:1/0,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},gp={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function mp(t={},e=gp){return{chartId:t.chartId??e.chartId,chartType:t.chartType??e.chartType,sensors:t.sensors??e.sensors,onObservation:t.onObservation??e.onObservation,onSimulationStateChange:t.onSimulationStateChange??e.onSimulationStateChange}}function bp(t){return{...t,shape:{...t.shape},datum:t.datum,springs:t.springs?.map(t=>({...t,target:{...t.target}}))}}function xp(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:void 0}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:void 0}function vp(t,e){if(null!=t[e])return t[e];const o=t.datum;return o&&"object"==typeof o?o[e]:void 0}function wp(t){return{...bp(t),sequence:t.sequence,spawnAt:t.spawnAt}}function kp(t){return t.map(t=>({...t,shape:{...t.shape},bodyFilter:t.bodyFilter&&"function"!=typeof t.bodyFilter?{...t.bodyFilter,oneOf:t.bodyFilter.oneOf?.slice(),notOneOf:t.bodyFilter.notOneOf?.slice()}:t.bodyFilter}))}function Sp(t){return!1!==t&&{...t}}function Ap(t,e){return t.spawnAt===e.spawnAt?t.sequence-e.sequence:t.spawnAt-e.spawnAt}function Mp(t){return{...t,gravity:{...t.gravity}}}function _p(t,e,o,n){if("circle"===t.shape.type){const i=t.x-e,r=t.y-o,s=t.shape.radius+n,a=i*i+r*r;return a>s*s?null:a}const i=Math.max(Math.abs(e-t.x)-t.shape.width/2,0),r=Math.max(Math.abs(o-t.y)-t.shape.height/2,0),s=i*i+r*r;return s>n*n?null:s}function Pp(t){const e=t.indexOf("\0");return{sensorId:t.slice(0,e),bodyId:t.slice(e+1)}}function Cp(t,e={}){const{idPrefix:o="plot",includeFloor:n=!0,includeCeiling:i=!1,includeLeftWall:r=!0,includeRightWall:s=!0,wallThickness:a=20,floorThickness:l=a}=e,c=[],u=t.x+t.width/2,d=t.y+t.height/2;return n&&c.push({id:o+"-floor",shape:{type:"aabb",x:u,y:t.y+t.height+l/2,width:t.width+2*a,height:l}}),i&&c.push({id:o+"-ceiling",shape:{type:"aabb",x:u,y:t.y-l/2,width:t.width+2*a,height:l}}),r&&c.push({id:o+"-left-wall",shape:{type:"aabb",x:t.x-a/2,y:d,width:a,height:t.height+2*l}}),s&&c.push({id:o+"-right-wall",shape:{type:"aabb",x:t.x+t.width+a/2,y:d,width:a,height:t.height+2*l}}),c}function Rp(t){const{idPrefix:e="bin",count:o,domainStart:n,domainStep:i,xScale:r,yTop:s,yBottom:a,wallThickness:l=4,includeBoundaryWalls:c=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=s,lidThickness:f=Math.max(2,l)}=t,p=[],y=s+(a-s)/2,g=Math.abs(a-s),m=c?o:o-1;if(u||c)for(let t=c?0:1;m>=t;t+=1){if(!u&&t>0&&o>t)continue;const s=r(n+t*i);p.push({id:`${e}-wall-${t}`,shape:{type:"aabb",x:s,y:y,width:l,height:g}})}if(null!=d)for(let t=0;o>t;t+=1){const o=n+t*i,s=o+i;if(s>=d)continue;const a=r(o),c=r(s);p.push({id:`${e}-lid-${t}`,shape:{type:"segment",x1:Math.min(a,c)+l/2,y1:h,x2:Math.max(a,c)-l/2,y2:h,thickness:f}})}return p}import{quadtree as Lp}from"d3-quadtree";var Ip=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(t,e,o,n,i,r=0){const s=this.ensure(t,e);if(!s)return null;let a=null,l=1/0;const c=Math.max(0,r)+this.maxSearchRadius,u=n-c,d=n+c,h=i-c,f=i+c;return s.visit((t,e,s,c,p)=>{if(u>c||e>d||h>p||s>f)return!0;if(t.length)return!1;let y=t;for(;y;){const t=y.data;if(t){const e=_p(t,n,i,Math.max(0,r));null!=e&&(l>e||e===l&&o.indexOf(t.id)>o.indexOf(a?.id??""))&&(a=t,l=e)}y=y.next}return!1}),a}ensure(t,e){if(this.tree&&this.revision===e)return this.tree;const o=t.readState();return 0===o.length?(this.tree=null,this.maxSearchRadius=0,this.revision=e,null):(this.maxSearchRadius=o.reduce((t,e)=>Math.max(t,function(t){return"circle"===t.shape.type?t.shape.radius:Math.hypot(t.shape.width,t.shape.height)/2}(e)),0),this.tree=Lp().x(t=>t.x).y(t=>t.y).addAll(o),this.revision=e,this.tree)}},Tp=["data","scene-geometry","data-paint","accessibility","evidence"],$p=["scene-geometry","data-paint","accessibility","evidence"],zp=["overlay","accessibility","evidence"],Dp=(t,e)=>({retainedData:t,invalidations:e}),Fp=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ep=["scene-geometry","data-paint","accessibility","evidence"],Op=[],Bp={engine:Dp("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:Dp("preserve",Ep),colliders:Dp("preserve",Ep),sediment:Dp("preserve",Ep),bodyBudget:Dp("preserve",Fp),bodyLimit:Dp("preserve",Fp),eviction:Dp("preserve",Fp),fixedDt:Dp("preserve",Op),maxDeltaSeconds:Dp("preserve",Op),maxSubsteps:Dp("preserve",Op),settleStepLimit:Dp("preserve",Op),timeScale:Dp("preserve",Op),observation:Dp("preserve",Op)},Np=Dp("preserve",Fp);function Wp(t){let e="preserve";const o=new Set;for(const n of t){const t=Bp[n]??Np;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}var jp=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function Yp(t,e){return t===e||!(!t||!e)&&t.gravity?.x===e.gravity?.x&&t.gravity?.y===e.gravity?.y&&jp.every(o=>t[o]===e[o])}function Gp(t,e,o,n){return t||!e?"paused":o||!n?"running":"settled"}var Hp=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(t){this.speed=function(t){const e=t?.sleepSpeed;return"number"==typeof e&&Number.isFinite(e)&&e>0?e:8}(t)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(t,e,o){if(o>0)return void(this.seconds=0);const n=t.readState(this.scratch),i=this.speed*this.speed;let r=!0;for(const t of n)if(!t.sleeping&&t.vx*t.vx+t.vy*t.vy>=i){r=!1;break}this.seconds=r?this.seconds+Math.max(0,e):0}},qp=class{constructor(t={}){this.activeSensorPairs=new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new Ip,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.updateResults=new Yo,this.simulationState="settled",this.visible=!0,this.quiescence=new Hp;const{bodyBudget:e,colliders:o,engine:n,kernel:i,observation:r,sediment:s,...a}=t;this.config={...yp,...a},this.configInput={...t},this.bodyBudget=e??{},this.engineInput=n,this.observation=mp(r),this.sediment=new fp(s??!1),this.world=ip(n,{fixedDt:this.config.fixedDt,...i}),this.quiescence.setKernelOptions(i),o&&this.world.setColliders(kp(o))}updateConfig(t){const e=function(t,e){return Object.keys(t).filter(o=>"kernel"===o?!Yp(t.kernel,e.kernel):t[o]!==e[o])}(t,this.configInput),{colliders:o,bodyBudget:n,engine:i,kernel:r,observation:s,sediment:a,...l}=t;if(this.config={...this.config,...l},void 0!==n&&(this.bodyBudget=n,!1===n&&(this.bodyBudgetObservationKey="ok")),i&&i!==this.engineInput){const t=this.world.snapshot();this.world.dispose(),this.engineInput=i,this.world=ip(i,t.options),this.world.restore(t),this.revision+=1}if(r&&!Yp(r,this.configInput.kernel)){const t=this.world.snapshot(),e={...t.options,...r,gravity:{...t.options.gravity,...r.gravity}};this.world.restore({...t,options:e}),this.quiescence.setKernelOptions(e),this.revision+=1}s&&(this.observation=mp(s,this.observation)),this.sediment.updateConfig(a),o&&(this.world.setColliders(kp(o)),this.revision+=1),this.configInput={...this.configInput,...t};const c=Wp(e);this.updateResults.record({kind:"config",keys:e},c.invalidations)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setColliders(t){this.world.setColliders(kp(t)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},Wp(["colliders"]).invalidations)}enqueue(t,e){const o=Array.isArray(t)?t:[t],n=e?function(t,e={}){const o=xp(e.startAt)??0,n=e.pacing??"immediate";if("arrival"===n){const n=t.map((t,o)=>function(t,e,o){return"function"==typeof o?xp(o(t,e)):"string"==typeof o?xp(vp(t,o)):xp(t.spawnAt)??xp(vp(t,"arrivalTime"))??xp(vp(t,"timestamp"))??xp(vp(t,"time"))??xp(vp(t,"eventTime"))}(t,o,e.timeAccessor)),i=n.filter(t=>null!=t),r=i.length>0?Math.min(...i):0,s=xp(e.timeScale)??1,a=s>0?s:1;return t.map((t,e)=>{const i=n[e],s=null==i?0:Math.max(0,i-r);return{...bp(t),spawnAt:o+s/a}})}if("object"==typeof n){const e=xp(n.ratePerSec);if(e&&e>0)return t.map((t,n)=>({...bp(t),spawnAt:o+n/e}))}return t.map(t=>({...bp(t),spawnAt:o}))}(o,{...e,startAt:e.startAt??this.elapsedSeconds}):o;for(const t of n)this.queue.push({...bp(t),sequence:this.nextSequence,spawnAt:t.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(Ap),n.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:n.length},n.length?Tp:[])}enqueueWithResult(t,e){return this.enqueue(t,e),this.updateResults.last}spawnNow(t){this.spawnOne(bp(t)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},Tp)}materializeDueSpawns(){const t=this.revision,e=[],o=[];return this.spawnDue(e,o),0===e.length||(this.observeBodyBudget(o),this.evictOverflow(o),this.syncSimulationState(o),this.revision+=1,this.updateResults.record({kind:"enqueue",count:e.length},this.revision!==t?Tp:[])),e}clear(){const t=this.world.snapshot().options;this.world.init({...t,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},Tp)}tick(t){const e=this.revision,o=[],n=[],i=[],r=[],s=[];if(this.paused||!this.visible){const t=this.result(0,o,n,i,r,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),t}const a=Math.max(0,Math.min(t,this.config.maxDeltaSeconds))*this.config.timeScale;this.elapsedSeconds+=a,this.spawnDue(o,s);const l=this.observeBodyBudget(s),c=this.evictOverflow(s);n.push(...c.evicted),i.push(...c.sedimented),this.syncSimulationState(s),this.accumulator+=a;let u=0;for(;this.accumulator>=this.config.fixedDt&&this.config.maxSubsteps>u;){this.world.step(this.config.fixedDt);const t=this.world.events();r.push(...t),this.observeKernelEvents(t,s),this.observeSensorTransitions(s),this.accumulator-=this.config.fixedDt,u+=1}u===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),this.quiescence.refresh(this.world,a,o.length),(u>0||o.length>0||n.length>0||i.length>0||r.length>0)&&(this.revision+=1);const d=this.result(u,o,n,i,r,s,void 0,l);return this.updateResults.record({kind:"tick",count:u},this.revision!==e?o.length||n.length||i.length?Tp:$p:[]),d}settle(t=this.config.settleStepLimit){return this.runSettle(t,!1).steps}settleWithObservations(t=this.config.settleStepLimit){return this.runSettle(t,!0)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),advanceTime:t=>{this.elapsedSeconds+=t},spawnDue:(t,e)=>this.spawnDue(t,e),observeBodyBudget:t=>this.observeBodyBudget(t),evictOverflow:t=>this.evictOverflow(t),step:t=>this.world.step(t),drainEvents:()=>this.world.events(),observeKernelEvents:(t,e)=>this.observeKernelEvents(t,e),observeSensorTransitions:t=>this.observeSensorTransitions(t),refreshQuiescence:(t,e)=>this.quiescence.refresh(this.world,t,e)}}runSettle(t,e){const o=this.revision,n=[],i=[],r=[],s=[],a=e?[]:void 0;if(e&&(this.paused||!this.visible)){const t=this.result(0,n,i,r,s,a??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),t}this.spawnDue(n,a);const l=this.observeBodyBudget(a),c=this.evictOverflow(a);i.push(...c.evicted),r.push(...c.sedimented),this.syncSimulationState(a),n.length>0&&this.quiescence.reset();const u=e?{spawned:n,evicted:i,sedimented:r,events:s,observations:a}:{spawned:n},{steps:d,budget:h}=function(t,e,o){let n,i=0;for(;e>i&&(t.queueSize()>0||!t.atRest());){t.advanceTime(t.fixedDt);const e=[];if(t.spawnDue(e,o.observations),e.length>0){o.spawned.push(...e),n=t.observeBodyBudget(o.observations);const i=t.evictOverflow(o.observations);o.evicted?.push(...i.evicted),o.sedimented?.push(...i.sedimented)}t.step(t.fixedDt);const r=t.drainEvents();o.events&&(o.events.push(...r),t.observeKernelEvents(r,o.observations),t.observeSensorTransitions(o.observations)),i+=1,t.refreshQuiescence(t.fixedDt,e.length)}return{steps:i,budget:n}}(this.settleHost(),t,u),f=n.length+i.length+r.length>0;(d>0||f||s.length>0)&&(this.revision+=1);const p=this.result(d,n,i,r,s,a??[],void 0,h??l);return this.updateResults.record({kind:"settle",count:d},this.revision===o?[]:f?Tp:$p),p}readBodies(t=[]){return this.world.readState(t)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(t={}){return function(t,e={}){const{baselineY:o=0,binWidth:n=24,gap:i=2,maxHeight:r=80,value:s="count",x:a}=e,l=Math.max(1,...t.map(t=>t[s]));return t.map((t,e)=>{const c=Math.max(0,t[s]/l*r),u=a?.(t,e)??e*(n+i);return{binId:t.id,label:t.label,index:e,count:t.count,total:t.total,x:u,y:o-c,width:n,height:c,meanX:t.x.mean,meanY:t.y.mean}})}(this.readSediment(),t)}hitTest(t,e,o=0){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,t,e,o)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(t){const{timestamp:e,chartType:o,chartId:n,...i}=t,r={...i,timestamp:e??this.elapsedSeconds,chartType:o??this.observation.chartType,chartId:n??this.observation.chartId};return this.emitObservation(r),this.updateResults.record({kind:"update",count:1},["evidence"]),r}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(t){return this.updateResults.subscribe(t)}version(){return this.revision}setPaused(t){const e=this.paused!==t;this.paused=t,this.syncSimulationState(),this.updateResults.record({kind:"pause"},e?zp:[])}setVisible(t){const e=this.visible!==t;this.visible=t,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},e?zp:[])}remove(t){const e=new Set(t),o=new Set(this.liveBodyOrder),n=new Set(this.queue.map(t=>t.id));this.queue=this.queue.filter(t=>!e.has(t.id)),this.liveBodyOrder=this.liveBodyOrder.filter(t=>!e.has(t)),this.world.remove(t),this.removeActiveSensorPairsForBodies(e);const i=t.filter(t=>o.has(t)||n.has(t));return i.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:i,count:i.length},i.length?Tp:[]),i}setConstraint(t){const e=this.world.setConstraint(t);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},$p),e}removeConstraint(t){this.world.removeConstraint(t),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},$p)}applyImpulse(t,e,o){this.world.applyImpulse(t,e,o),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[t]},$p)}nextRandom(){return this.world.nextRandom()}controls(){return t=this,{applyImpulse:(e,o,n)=>t.applyImpulse(e,o,n),clear:()=>t.clear(),hitTest:(e,o,n)=>t.hitTest(e,o,n),pause:()=>t.setPaused(!0),push:(e,o)=>t.enqueue(e,o),pushMany:(e,o)=>t.enqueue(e,o),bodyBudgetStatus:()=>t.bodyBudgetStatus(),readBodies:e=>t.readBodies(e),readSediment:()=>t.readSediment(),recordObservation:e=>t.recordObservation(e),remove:e=>t.remove(e),restore:e=>t.restore(e),resume:()=>t.setPaused(!1),settle:e=>t.settle(e),settleWithObservations:e=>t.settleWithObservations(e),snapshot:()=>t.snapshot(),sedimentHeightfield:e=>t.sedimentHeightfield(e),sedimentTotals:()=>t.sedimentTotals(),step:e=>t.tick(e)};var t}snapshot(){const t=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:Sp(this.bodyBudget),config:{...this.config,kernel:Mp(t.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(wp),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:t}}restore(t){this.config={bodyLimit:t.config.bodyLimit,eviction:t.config.eviction,fixedDt:t.config.fixedDt,maxDeltaSeconds:t.config.maxDeltaSeconds,maxSubsteps:t.config.maxSubsteps,settleStepLimit:t.config.settleStepLimit,timeScale:t.config.timeScale},this.configInput={...t.config,bodyBudget:Sp(t.bodyBudget??{}),kernel:Mp(t.world.options)},this.bodyBudget=Sp(t.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(t.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(t.activeSensorPairs),this.accumulator=t.accumulator,this.elapsedSeconds=t.elapsedSeconds,this.paused=t.paused,this.queue=t.queue.map(wp).sort(Ap),this.revision=t.revision,this.sediment.restore(t.sediment??[]),this.simulationState=t.simulationState??Gp(t.paused,t.visible,t.queue.length>0,t.world.bodies.every(t=>t.sleeping)),this.liveBodyOrder=t.liveBodyOrder.slice(),this.visible=t.visible,this.nextSequence=this.queue.reduce((t,e)=>Math.max(t,e.sequence),-1)+1,this.world.restore(t.world),this.updateResults.record({kind:"restore"},Tp)}spawnDue(t,e){for(;this.queue.length>0&&this.elapsedSeconds>=this.queue[0].spawnAt;){const o=this.queue.shift();if(!o)return;this.spawnOne(o,e),t.push(o.id)}}spawnOne(t,e){this.liveBodyOrder=this.liveBodyOrder.filter(e=>e!==t.id),this.removeActiveSensorPairsForBodies(new Set([t.id])),this.world.spawn(t),this.liveBodyOrder.push(t.id);for(const e of t.springs??[])this.world.setConstraint({...e,bodyId:t.id});const o=this.world.readState().find(e=>e.id===t.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:t.id,datum:o?.datum??t.datum,x:o?.x??t.x,y:o?.y??t.y},e)}result(t,e,o,n,i,r,s,a=this.evaluateBodyBudget()){this.syncSimulationState(r);const l=this.world.allSleeping();return{budget:a,elapsedSeconds:this.elapsedSeconds,evicted:o,events:i,observations:r,queueSize:this.queue.length,revision:this.revision,shouldContinue:s??(this.queue.length>0||!this.atRest()),sleeping:l,sedimented:n,spawned:e,steps:t}}observeKernelEvents(t,e){!function(t,e,o){if(0===e.length)return;const n=new Map(t.readState().map(t=>[t.id,t]));for(const t of e){if("sleep"!==t.type)continue;const e=n.get(t.bodyId);o.emit({type:"physics-settle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:t.bodyId,datum:e?.datum,x:e?.x,y:e?.y})}}(this.world,t,this.observationContext(e))}observeSensorTransitions(t){this.activeSensorPairs=function(t,e,o){const n=new Set(t.activeSensorPairs().map(t=>`${t.sensorId}\0${t.bodyId}`));if(0===n.size&&0===e.size)return n;const i=new Map(t.readState().map(t=>[t.id,t])),r=(t,e)=>{const{sensorId:n,bodyId:r}=Pp(e),s=o.observation.sensors[n],a=i.get(r);o.emit({type:"enter"===t?s?.enterType??"physics-bin-enter":s?.exitType??"physics-bin-exit",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,bodyId:r,datum:a?.datum,x:a?.x,y:a?.y,sensorId:n,binId:s?.binId??n})};for(const t of Array.from(n).sort())e.has(t)||r("enter",t);for(const t of Array.from(e).sort())n.has(t)||r("exit",t);return n}(this.world,this.activeSensorPairs,this.observationContext(t))}removeActiveSensorPairsForBodies(t){!function(t,e){for(const o of t)e.has(Pp(o).bodyId)&&t.delete(o)}(this.activeSensorPairs,t)}observationContext(t){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:e=>this.emitObservation(e,t)}}emitObservation(t,e){e?.push(t),this.observation.onObservation?.(t)}evaluateBodyBudget(){return function(t){const e=Math.max(0,Math.floor(t.liveBodies)),o=Math.max(0,Math.floor(t.queuedBodies??0)),n=e+o,i=pp(t.bodyLimit),r=pp(t.engineMaxBodiesHint),s=function(t,e,o){if(!1===o)return;const n=pp(o?.warnAt);return null!=n?n:null!=t?Math.max(1,Math.floor(.8*t)):null!=e?Math.max(1,Math.floor(.8*e)):void 0}(i,r,t.options),a=null==i?0:Math.max(0,e-i),l=a>0?"overflow":null==s||s>n?"ok":"warning";return{action:"overflow"!==l?"continue":t.sedimentEnabled?"sediment":t.evictionEnabled?"evict":"retain",bodyLimit:i,engineMaxBodiesHint:r,liveBodies:e,overflow:a,projectedBodies:n,queuedBodies:o,state:l,warnAt:s}}({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(t){const e=this.evaluateBodyBudget();if("ok"===e.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",e;const o=`${e.state}:${e.action}`;return o===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=o,this.emitObservation({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt},t)),e}syncSimulationState(t){const e=Gp(this.paused,this.visible,this.queue.length>0,this.atRest());if(e===this.simulationState)return;const o=this.simulationState;this.simulationState=e,function(t,e,o){o.observation.onSimulationStateChange?.(e,t),"running"!==e&&"settled"!==e||o.emit({type:"running"===e?"sim-active":"sim-idle",timestamp:o.elapsedSeconds,chartType:o.observation.chartType,chartId:o.observation.chartId,simulationState:e,previousSimulationState:t})}(o,e,this.observationContext(t))}evictOverflow(t){const{evicted:e,sedimented:o,liveBodyOrder:n}=function(t,e,o,n,i,r){const s={evicted:[],sedimented:[],liveBodyOrder:i};if(!1===o)return s;const a=Math.max(0,Math.floor(n));if(!Number.isFinite(a))return s;const l=i.length-a;if(0>=l)return s;const c=function(t,e,o){if("sleeping-first"!==e)return o.slice();const n=new Map(t.readState().map(t=>[t.id,t.sleeping])),i=[],r=[];for(const t of o)n.get(t)?i.push(t):r.push(t);return[...i,...r]}(t,o,i),u=c.slice(0,l);if(0===u.length)return s;const d=function(t,e,o,n){const i=new Map(t.readState().map(t=>[t.id,t])),r=[];for(const t of o){const o=i.get(t);if(!o)continue;const s=e.add(o);s&&(r.push(t),n.emit({type:"physics-sediment",timestamp:n.elapsedSeconds,chartType:n.observation.chartType,chartId:n.observation.chartId,bodyId:t,datum:o.datum,x:o.x,y:o.y,binId:s.id,count:s.count,total:s.total}))}return r}(t,e,u,r);t.remove(u);const h=new Set(u);return{evicted:u,sedimented:d,liveBodyOrder:i.filter(t=>!h.has(t))}}(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(t));return e.length>0&&(this.liveBodyOrder=n,this.removeActiveSensorPairsForBodies(new Set(e))),{evicted:e,sedimented:o}}};import{scaleLinear as Vp}from"d3-scale";function Xp(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}}})}import{scaleLinear as Up}from"d3-scale";function Kp(t){if(Array.isArray(t)&&t.length>=2){const e=Rf(t[0]),o=Rf(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=Rf(e.x),n=Rf(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Zp(t){return Array.isArray(t)?t.map(Kp).filter(t=>null!=t):[]}function Qp(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:Lf(t.x,e.plot.x,e.plot.x+e.plot.width),y:Lf(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Jp(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 ty(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=Lf(e,0,1)*Jp(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 ey(t,e){const o=ty(t,Math.max(0,e-.02)),n=ty(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 oy(t,e,o){return Math.max(e,Math.min(o,t))}function ny(t,e,o,n,i,r={}){return{id:t,friction:r.friction,restitution:r.restitution,bodyFilter:r.bodyFilter,shape:{type:"segment",x1:e,y1:o,x2:n,y2:i,thickness:r.thickness??8}}}function iy(t){return{id:t.id,label:t.label,description:t.description,kind:t.kind,shape:(e=t.x,o=t.y,n=t.width,i=t.height,{type:"aabb",x:e,y:o,width:n,height:i}),bodyFilter:t.bodyFilter,collider:t.collider,colliderThickness:t.colliderThickness,friction:t.friction,restitution:t.restitution,semanticItem:t.semanticItem,metadata:t.metadata,bodyStyle:t.bodyStyle,attributes:t.attributes,onEnter:t.onEnter,onExit:t.onExit};var e,o,n,i}function ry(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:12,y:0};return{...iy({...t,kind:t.kind??"force-field",attributes:{primitive:"routeSurface",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.015}}function sy(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}}function ay(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,n=Af(o),i=Lf(t.ballRadius??6,2,18),r=t.seed??1,s=$f(r),a=t.idAccessor,l=t.stageAccessor??"stage",c=t.groupBy,u=t.groupLabelAccessor,d=t.workAccessor,h=t.radiusAccessor,f=t.groupCompletion??(c?"allAbsorbed":"none"),p=t.springStiffness??.28,y=t.springDamping??.72,g=!0===t.settle,m=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),b=function(t){const e=t.shape??"lane",o=Math.max(1,Math.round(t.width)),n=Math.max(1,Math.round(t.height)),i=t.padX??46,r=t.padY??72,s=i,a=o-i,l=r,c=n-Math.max(24,Math.round(.45*r)),u=(l+c)/2,d=Math.max(1,c-l),h=oy(t.pinchRatio??.18,.06,.5),f=Number(t.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,y=oy(d*h+p,.06*d,.5*d),g=y/2,m=u-g,b=u+g,x=t.idPrefix??"process",v=t.friction??.58,w=t.restitution??.18,k=t.wallThickness??8,S=t.stages;if(!S.length)throw Error("processStageLayout requires at least one stage");const A=oy(t.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=function(t){const e=t.reduce((t,e)=>t+(e.share??1),0);return e>0?e:t.length}(S),_=a-s;let P=s;const C=S.map((t,e)=>{const o=P,n=e===S.length-1?a:P+(t.share??1)/M*_;return P=n,{id:t.id,label:t.label,description:t.description,kind:t.kind??"stage",index:e,x0:o,x1:n,x:(o+n)/2,width:n-o,y:u,height:d}}),R=C[A],L=R.x0,I=R.x1,T=(t,o)=>{if("lane"===e)return"top"===o?l:c;if("funnel"===e){const e=oy((t-s)/Math.max(1,a-s),0,1);return"top"===o?l+(m-l)*e:c+(b-c)*e}if(L>=t){const e=oy((t-s)/Math.max(1,L-s),0,1);return"top"===o?l+(m-l)*e:c+(b-c)*e}if(I>=t)return"top"===o?m:b;const n=oy((t-I)/Math.max(1,a-I),0,1);return"top"===o?m+(l-m)*n:b+(c-b)*n},$=C.map(t=>{const e=Math.min(T(t.x0,"top"),T(t.x1,"top")),o=Math.max(T(t.x0,"bottom"),T(t.x1,"bottom"));return{...t,y:(e+o)/2,height:Math.max(1,o-e)}}),z={thickness:k,friction:v,restitution:w},D=[];"lane"===e?D.push(ny(x+"-top",s,l,a,l,z),ny(x+"-bottom",s,c,a,c,z),ny(x+"-left",s,l,s,c,{...z,thickness:Math.max(6,k-2)}),ny(x+"-right",a,l,a,c,{...z,thickness:Math.max(6,k)})):"funnel"===e?D.push(ny(x+"-top",s,l,a,m,z),ny(x+"-bottom",s,c,a,b,z),ny(x+"-left",s,l,s,c,{...z,thickness:Math.max(6,k-2)}),ny(x+"-right",a,m,a,b,{...z,thickness:Math.max(6,k)})):D.push(ny(x+"-left-top",s,l,L,m,z),ny(x+"-left-bottom",s,c,L,b,z),ny(x+"-center-top",L,m,I,m,z),ny(x+"-center-bottom",L,b,I,b,z),ny(x+"-right-top",I,m,a,l,z),ny(x+"-right-bottom",I,b,a,c,z),ny(x+"-left",s,l,s,c,{...z,thickness:Math.max(6,k-2)}),ny(x+"-right",a,l,a,c,{...z,thickness:Math.max(6,k)}));const F=t.membraneDampingScale??.5,E=s,O=Math.max(1,("bowtie"===e?L:a)-E),B=(t.membranes??[]).map(t=>{const e=E+oy(t.offset,0,1)*O,o=t.width??18+18*t.cost,n=d-16,i=u+.25*(t.wobble??0);return{...t,x:e,y:i,width:o,height:n}}),N=!1===t.includeMembraneRegions?[]:B.map(t=>function(t){const e=t.dampingScale??.5,o=t.energyScale??1,n=oy(t.cost,0,2);return{...iy({...t,kind:t.kind??"membrane",attributes:{primitive:"membrane",membraneCost:n,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:n*e,energyDelta:-n*o}}({id:t.id,label:t.label??t.id,description:t.description??(t.label??t.id)+" is a permeable region. It taxes energy and damps velocity while bodies overlap it.",x:t.x,y:t.y,width:t.width,height:t.height,cost:t.cost,dampingScale:t.dampingScale??F,bodyStyle:t.bodyStyle,metadata:t.metadata,semanticItem:t.semanticItem,color:t.color}));return{shape:e,width:o,height:n,padX:i,padY:r,left:s,right:a,topY:l,bottomY:c,midY:u,centerLeft:L,centerRight:I,pinchHeight:y,pinchTop:m,pinchBottom:b,stages:$,membranes:B,colliders:D,regionEffects:N,boundaryY:T}}({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,n.plot.x),padY:Math.max(36,n.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),x=new Map(b.stages.map((t,e)=>[t.id,e])),v=new Map(b.stages.map(t=>[t.id,t])),w=b.stages[0].id,k=b.stages[0],S=new Set(e.filter(t=>t.absorb).map(t=>t.id)),A=e.map(t=>{const e=v.get(t.id)??k;return function(t,e){const o={id:"process-stage-"+t.id,label:t.label??t.id,description:t.description,x:e.x,y:e.y,width:Math.max(12,.92*e.width),height:Math.max(40,.88*e.height),semanticItem:!1,attributes:{stageId:t.id}};if(t.absorb)return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force??{x:24,y:0};return{...iy({...t,kind:t.kind??"sink",attributes:{primitive:"absorb",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping??.02,charge:t.charge??"absorbed"}}({...o,kind:t.kind??"sink",force:sy(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return n={...o,kind:t.kind??"force-field",force:sy(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}},{...iy({...n,kind:n.kind??"force-field",attributes:{primitive:"portal",targetStage:n.targetStage,..."object"==typeof n.attributes&&n.attributes?n.attributes:{}}}),force:n.force,impulseOnEnter:n.impulseOnEnter,damping:n.damping??.08}}var n;if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return function(t){const e="number"==typeof t.force?{x:t.force,y:0}:t.force;return{...iy({...t,kind:t.kind??"force-field",attributes:{primitive:"capacitatedSensor",capacity:t.capacity,unitsPerSecond:t.unitsPerSecond??t.capacity,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:e,damping:t.damping,charge:t.charge??t.capacity}}({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:sy(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...o.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return function(t){const e=t.pressure??t.occupancy??0,o=t.baseDamping??.08,n=t.dampingPerUnit??.12,i=t.energyPerUnit??0;return{...iy({...t,kind:t.kind??"membrane",attributes:{primitive:"pressureField",pressure:e,..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),damping:o+e*n,energyDelta:i?-e*i:void 0,force:t.force}}({...o,kind:t.kind??"membrane",pressure:e.pressure,occupancy:e.occupancy,baseDamping:e.baseDamping??t.damping??.1,dampingPerUnit:e.dampingPerUnit??.1,energyPerUnit:e.energyPerUnit??0,force:sy(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?ry({...o,kind:t.kind??"force-field",force:sy(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):function(t){return{...iy({...t,kind:t.kind??"force-field",attributes:{primitive:"forceField",..."object"==typeof t.attributes&&t.attributes?t.attributes:{}}}),force:t.force,damping:t.damping,energyDelta:t.energyDelta}}({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:b.midY,width:e.width,height:b.bottomY-b.topY})});A.unshift(ry({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(b.left+b.right)/2,y:b.midY,width:b.right-b.left,height:b.bottomY-b.topY-12,force:8,damping:.012,semanticItem:!1}));const M=new Map;for(const t of b.stages)M.set(t.id,0);const _=[];t.data.forEach((t,e)=>{const o=(a?Cf(t,e,a)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(Cf(t,e,l)??w)+"",r=x.has(n)?n:w;M.set(r,(M.get(r)??0)+1);const s=c?(Cf(t,e,c)??"")+"":void 0,f=s&&u?(Cf(t,e,u)??s)+"":s,p=d?Rf(Cf(t,e,d))??1:1,y=h?Rf(Cf(t,e,h)):null,g=Lf(null!=y&&y>0?y:i,2,18);_.push({datum:t,id:o,stageId:r,groupId:s||void 0,groupLabel:f||void 0,work:p,radius:g,index:e})});const P=new Map,C=new Map;for(const t of _){if(!t.groupId)continue;const e=P.get(t.groupId)??[];e.push(t.id),P.set(t.groupId,e),t.groupLabel&&C.set(t.groupId,t.groupLabel)}const R=Lf(t.groupAnchorAlong??.55,.15,.9),L=b.left+(b.right-b.left)*R,I=Array.from(P.keys()),T=I.map((t,o)=>{const n=P.get(t)??[],i=I.length>1?b.topY+28+o/Math.max(1,I.length-1)*(b.bottomY-b.topY-56):b.midY;return function(t){const e=t.x??t.anchor?.x??0,o=t.y??t.anchor?.y??0;return{id:t.id,label:t.label,description:t.description,group:t.group,bodyIds:t.bodyIds,datum:t.datum,state:t.state,x:e,y:o,width:t.width,height:t.height,anchor:t.anchor??{x:e,y:o},completion:t.completion,tether:t.tether,semanticItem:t.semanticItem}}({id:t,label:C.get(t)??t,bodyIds:n,anchor:{x:L,y:i},x:L,y:i,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),$=function(t,e){const o=e instanceof Set?e:new Set(e);return t.map(t=>{const e=t.bodyIds??[],n=e.filter(t=>!o.has(t)),i=e.length-n.length,r=t.completion?.mode??"allMembersAbsorbed",s=t.completion?.valueByBodyId,a=t=>{const e=s?.[t];return Number.isFinite(e)&&Number(e)>=0?Number(e):1},l=e.reduce((t,e)=>t+a(e),0),c=e.reduce((t,e)=>t+(o.has(e)?a(e):0),0),u=t.completion?.threshold,d="threshold"===r?Number.isFinite(u)&&Number(u)>=0?Number(u):l:void 0;return{id:t.id,label:t.label??t.id,mode:r,complete:e.length>0&&("anyAbsorbed"===r?i>0:"threshold"===r?c>=(d??l):0===n.length),absorbed:i,total:e.length,absorbedValue:c,totalValue:l,threshold:d,missing:n}})}(T,_.filter(t=>S.has(t.stageId)).map(t=>t.id)),z=new Map(T.map(t=>[t.id,t])),D=_.map((t,e)=>{const o=v.get(t.stageId)??k,n=o.x+(s()-.5)*Math.min(24,.2*o.width),i=b.boundaryY(n,"top")+t.radius+10,r=b.boundaryY(n,"bottom")-t.radius-10,a=r>i?i+s()*Math.max(1,r-i):b.midY,l=g?n:b.left+18+e%7*4,c=g?a:b.midY+(s()-.5)*(b.bottomY-b.topY)*.35,u=[{target:{type:"point",x:n,y:a},restLength:.45*t.radius,stiffness:p,damping:y}];if(t.groupId){const e=z.get(t.groupId);e?.anchor&&!S.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:l,y:c,vx:g?0:40+40*s(),vy:g?0:20*(s()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:g?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),F={kernel:{seed:r,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:b.colliders,fixedDt:1/60,maxSubsteps:8},E=b.stages.map(t=>({label:t.label??t.id,value:M.get(t.id)??0})),O=e.map(t=>{const e=v.get(t.id)??k;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:M.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:F,initialSpawns:D,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:E,metadata:{kind:"process-flow",plot:n.plot,volume:b,stages:O,groups:T,groupCompletion:$,regionEffects:A}}}import{scaleLinear as ly}from"d3-scale";function cy(t,e,o){return yt(t,e,o)}function uy(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&vt(o,t)||"#4e79a7":e=>{if(o){const t=vt(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 dy(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 hy(t){const e=by(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 fy(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function py(t){return`gauntlet:${t}:core`}function yy(t,e){return`gauntlet:${t}:positive:${e}`}function gy(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var my={left:28,top:76,rightInset:30,thickness:8};function by(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return my;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 xy(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function vy(t,e,o,n){const i=by(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 wy(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 ky(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 Sy(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=fy(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...fy(t,e,o.positiveAccessor,s)],l=[...fy(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...fy(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(fy(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:fy(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??ky(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=xy(o),l=Math.max(3,28*a),c=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??c,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},y=[{...d,id:py(t.id),x:h,y:f,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??t.startedAt,datum:p}],g=vy(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,o);y[0].x=g.x,y[0].y=g.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=wy(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),l=vy(g.x+Math.cos(r.angle)*r.radius,g.y+Math.sin(r.angle)*r.radius,s,o);y.push({id:yy(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:py(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...n.spring??{}}]})}return t.negativeIds.forEach((e,n)=>{const i=r.get(e);i&&y.push(function(t,e,o,n,i,r,s){const a=xy(r),l=e.radius??Math.max(2,7.2*a),c=vy(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,l,r);return{id:gy(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:py(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,g.x,g.y,o,d.spawnAt??t.startedAt))}),y}(o,r,e,s,n,i,t.coreBody)});return{layout:e,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:hy(e)}}}var Ay=1e-9;function My(t,e){return e>t?-1:t>e?1:0}function _y(t){return{...t}}function Py(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 Cy(t){const e=Object.fromEntries(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:_y(e.initialMetrics),metrics:_y(e.metrics),productIds:[...e.productIds],history:Py(e.history)}])),o=Object.fromEntries(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:_y(e.metrics),sourceIds:[...e.sourceIds],history:Py(e.history)}])),n=Object.fromEntries(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?_y(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:_y(t.input.metrics)},metrics:_y(t.metrics),loss:{amount:t.loss.amount,metrics:_y(t.loss.metrics)},history:Py(t.history)}}function Ry(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Ly(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(My)}function Iy(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[Ry("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function Ty(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function $y(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(Ry("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(Ry("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(My);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(Ry("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function zy(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 Dy(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 Fy(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(Ry("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function Ey(t,e,o){const n=Ly(e);e.length||t.diagnostics.push(Ry("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(Ry("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(Ry("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(Ry("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(Ry("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 Oy(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+Ay)&&t.diagnostics.push(Ry("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...Iy(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+Ay)&&t.diagnostics.push(Ry("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 By(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?{...n,...t.metrics}: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 Ny(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>Ay&&t.diagnostics.push(Ry("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function Wy(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(Ry("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...Iy(e.metricsDelta,n+".metricsDelta")),Fy(t,e.outletId,n+".outletId");const o=$y(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(Ry("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=zy(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&&Ty(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&Dy(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(Ry("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=Ly(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(Ry("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(Ry("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(Ry("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(...Iy(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?{...o.metrics}:void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=zy(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void Dy(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Ly(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(Ry("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(Ry("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(Ry("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=zy(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void Dy(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(Ry("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(Ry("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(Ry("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=Ey(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=Ly(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(Ry("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(Ry("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(Ry("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),l.length&&t.diagnostics.push(Ry("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={};for(const o of t)Ty(e,o.metrics);return e}(s);if(!Oy(t,c,u,e.loss,n+".loss"))return;const d=c-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[n,i]of Object.entries(o?.metrics??{}))e[n]=Number(e[n]??0)-i,t.state.loss.metrics[n]=Number(t.state.loss.metrics[n]??0)+i}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,f=zy(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let p;if("combine"===e.type){if(h&&Ny(t,o,d,n+".productId"),p=By(o,e.sourceIds,d,u,t,h,f),h&&!Fy(t,p.outletId,n+".productId"))return;i.products[e.productId]=p}else p=r,p.sourceIds.push(...e.sourceIds),p.amount+=d,Ty(p.metrics,u),p.history.push(f);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(f);return i.history.push(f),function(t,e){if(e.length){for(const o of e)o.status="resolved",o.resolution="combined",o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt;Dy(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,l),Dy(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:p.outletId?[p.outletId]:void 0}),void(h&&Dy(t,{type:"complete-product",sourceIds:[...p.sourceIds],productIds:[p.id],outletIds:p.outletId?[p.outletId]:void 0}))}if("complete-product"===e.type){const o=i.products[e.productId];return o?void function(t,e,o,n,i,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!Fy(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(Ry("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(Ny(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics={...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=zy(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(l),t.state.history.push(l),Dy(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(Ry("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=Ey(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(Ry("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=Ly(r);s.length&&t.diagnostics.push(Ry("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(Ry("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,n+".products",l)),c.length&&t.diagnostics.push(Ry("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(Ry("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...Iy(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!Oy(t,u.amount,u.metrics,e.loss,n+".loss"))return;const d=u.amount-(e.loss?.amount??0),h=e.products.map((t,e)=>t.amount??a[e]?.amount),f=h.filter(t=>void 0!==t).length;if(0!==f&&f!==h.length)return void t.diagnostics.push(Ry("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const p=f?h:e.products.map(()=>d/e.products.length),y=p.reduce((t,e)=>t+e,0);if(Math.abs(y-d)>Ay)return void t.diagnostics.push(Ry("error","split-amount-mismatch",`Split allocations total ${y}, but ${d} remains after loss.`,n+".products"));const g={...u.metrics};for(const[t,o]of Object.entries(e.loss?.metrics??{}))g[t]=Number(g[t]??0)-o;const m=zy(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],l=d>Ay?p[r]/d:1/e.products.length,c=Object.fromEntries(Object.entries(g).map(([t,e])=>[t,e*l])),h=o.metrics??s.metrics??c,f=By({...s,amount:p[r],metrics:h},[u.id],p[r],{...h},t,!0,m);Fy(t,f.outletId,`${n}.products.${r}.productId`)&&(i.products[f.id]=f)}),t.diagnostics.some(t=>"error"===t.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),i.loss.amount+=e.loss?.amount??0;for(const[t,o]of Object.entries(e.loss?.metrics??{}))i.loss.metrics[t]=Number(i.loss.metrics[t]??0)+o;i.history.push(m),Dy(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)Dy(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){Fy(t,e.outletId,n+".outletId");const o=$y(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(Ry("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=zy(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&&Dy(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...Iy(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)Ty(i.metrics,e.metricsDelta);else if("components"in e.target){const r=$y(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)Ty(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Ly(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(Ry("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(Ry("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)Ty(i.products[t].metrics,e.metricsDelta)}return void i.history.push(zy(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(zy(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(Ry("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function jy(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[Ry("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=Cy(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(Wy(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 Yy=[900,520],Gy=[{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}],Hy=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),qy=1e-9;function Vy(t,e){return e>t?-1:t>e?1:0}function Xy(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Uy(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(Vy)}function Ky(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Zy(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(Xy("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function Qy(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(Xy("error","invalid-metrics","Metrics must be a numeric object.",o)),{};const n={};for(const[i,r]of Object.entries(t)){const t=Ky(r);null!=t?n[i]=t:e.push(Xy("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function Jy(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 tg(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+qy).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+qy&&i.push([r,t]),r=Math.max(r,e);return e>r+qy&&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 eg(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 og(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?eg(t):1}function ng(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:og(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function ig(t){return"crucible:component:"+encodeURIComponent(t)}function rg(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>qy?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function sg(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 ag(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 lg(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 cg(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 ug(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>Vy(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>Vy(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=sg(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)||Vy(t.id,e.id));const o=ag(i.length,cg(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*rg(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=lg(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=ag(o.length,cg(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=eg(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=rg(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:ig(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var dg=ug;function hg(t){return Array.isArray(t)?t.map(hg):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>Vy(t,e)).map(([t,e])=>[t,hg(e)])):t}function fg(t,e=t.duration){const o=function(t,e){const o=Ky(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-qy,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=Cy(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+qy)break;const a=jy(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 pg(t){const e=function(t){const e=[];t.length||e.push(Xy("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=Uy(t.map(t=>t.id));o.length&&e.push(Xy("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=Ky(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(Xy("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(Xy("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(Xy("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=Jy(t.outlets??Gy),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?{...t.metrics}:void 0})),r=function(t,e,o){const n=[],i=Uy(t.map(t=>t.id));i.length&&n.push(Xy("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(Xy("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=Ky(t.at.time);if(null==r||0>r||r>o+qy)return void n.push(Xy("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=>qy>=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}:qy>=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(Xy("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(Xy("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(Xy("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={},n=[];let i=0;const r={};t.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((Zy(s,a,t.idAccessor,l,e,`data.${a}.id`)??l)+"").trim();if(!c)return void e.push(Xy("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(c);const u=Ky(Zy(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(Xy("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=Qy(Zy(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),f=Zy(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),p=Hy.has(f)?f:"active";Hy.has(f)||e.push(Xy("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${a}.status`,[c]));const y=Zy(s,a,t.labelAccessor,(s.label??s.name??c)+"",e,`data.${a}.label`)+"",g=Zy(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";o[c]||(o[c]={id:c,label:y,category:g,datum:s,status:p,initialAmount:d,amount:d,initialMetrics:{...h},metrics:{...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=Uy(n);s.length&&e.push(Xy("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=Qy(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:{},relations:{},input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:{}},history:[]},diagnostics:e}}(t),a=function(t=Yy,e=Gy){const o=Math.max(1,Ky(t[0])??900),n=Math.max(1,Ky(t[1])??520),i=360>o||260>n,r=i?Math.max(4,.035*Math.min(o,n)):20,s=i?Math.max(10,.075*n):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},l=i?Math.max(16,.14*n):Math.min(78,.16*n),c={x:r,y:n-r-l,width:Math.max(1,o-2*r),height:l},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),f={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,i?84:180)),y={x:f.x+(f.width-p)/2,y:f.y-(i?10:24),width:p,height:i?12:28},g=Jy(e),m={left:g.filter(t=>"left"===(t.side??"bottom")),right:g.filter(t=>"right"===t.side),bottom:g.filter(t=>"bottom"===(t.side??"bottom"))},b=[],x=(t,e)=>{const n=Math.max(8,u-1.5*r),s=f.height/Math.max(1,e.length);e.forEach((e,a)=>{b.push({...e,side:t,x:"left"===t?r:o-r-n,y:f.y+a*s,width:n,height:Math.max(8,s-(i?2:8))})})};x("left",m.left),x("right",m.right);const v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{b.push({...t,side:"bottom",x:f.x+e*v,y:f.y+f.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-f.y-f.height-(i?4:12))})}),b.sort((t,e)=>g.findIndex(e=>e.id===t.id)-g.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:f,mouth:y,projection:c,outlets:b}}(t.size??Yy,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(...tg({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}),...tg({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}),...tg({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=Uy(e.map(t=>t.id)),r=Uy(t.map(t=>t.id));return i.length&&o.push(Xy("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(Xy("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(Xy("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(Xy("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(Xy("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(Xy("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(Xy("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),Qy(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>Vy(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(hg(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>Vy(t.id,e.id)),i=n.map(t=>t.amount),r=sg(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}}(og(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=rg(t.amount,i,o.bodyRadius,r),f={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:ig(t.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...c],p={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:ng(t.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:f},y=fg(p),g=Object.values(y.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=g.length?[Xy("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return p.terminalState=y.state,p.terminalSpawns=dg(y.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p.diagnostics=[...f,...y.diagnostics,...m],p}import*as yg from"react";import{jsx as gg,jsxs as mg}from"react/jsx-runtime";function bg(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 xg(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 mg(yg.Fragment,{children:[gg("defs",{children:gg("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:gg("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),gg("polygon",{points:e,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${o})`}),gg("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 mg(yg.Fragment,{children:[gg("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),gg("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 vg,jsx as wg,jsxs as kg}from"react/jsx-runtime";var Sg="var(--semiotic-text, #26323a)",Ag="var(--semiotic-text-secondary, #6c7377)",Mg="var(--semiotic-primary, #b8792d)",_g="var(--semiotic-danger, #9f3d35)",Pg="var(--semiotic-success, #356b63)";function Cg(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 Rg({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 kg("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[kg("defs",{children:[kg("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[wg("stop",{offset:"0",stopColor:Mg,stopOpacity:"0.03"}),wg("stop",{offset:"0.66",stopColor:Mg,stopOpacity:"0.1"}),wg("stop",{offset:"1",stopColor:_g,stopOpacity:"0.18"})]}),wg("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:wg("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:Sg,strokeOpacity:"0.08",strokeWidth:"1"})})]}),wg("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:Sg,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),wg("path",{d:Cg(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),wg("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:Sg,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:wg("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 kg("g",{children:[wg("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,l-2),height:t.phaseRail.height,rx:2,fill:c?n.color??Mg:u?Pg:Sg,fillOpacity:c?.68:u?.28:.09}),46>l?null:wg("text",{x:a+l/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:c?Sg:Ag,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=>kg("g",{children:[wg("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?_g:Pg),fillOpacity:"0.1",stroke:t.color??("left"===t.side?_g:Pg),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:wg("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:Ag,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function Lg({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 wg("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 kg("g",{children:[wg("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?_g:"complete"===t.status?Mg:Pg,fillOpacity:"0.68"}),l>4&&a>=34?kg(vg,{children:[wg("text",{x:h+.32*a,y:e.projection.y+c+10,fill:Ag,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),kg("text",{x:h+.32*a,y:e.projection.y+c+19,fill:Sg,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[bg(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}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 Tg(t){return t.map(t=>({...t,spawnAt:void 0}))}function $g(t,e){return t?e?o=>Sf.createElement(Sf.Fragment,null,t,"function"==typeof e?e(o):e):t:e}var zg=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Dg(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return zg[(e>>>0)%zg.length]}var Fg={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:Xd,LineChart:Kd,AreaChart:Qd,DifferenceChart:Jd,StackedAreaChart:th,Scatterplot:oh,CandlestickChart:eh,BubbleChart:Vd,ConnectedScatterplot:ih,QuadrantChart:nh,Heatmap:rh,TemporalHistogram:Zd,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:Rh,StackedBarChart:Lh,GroupedBarChart:Ih,PieChart:Th,DonutChart:$h,Histogram:zh,BoxPlot:Dh,ViolinPlot:Fh,SwarmPlot:Eh,DotPlot:Oh,SwimlaneChart:Bh,RidgelinePlot:Nh,LikertChart:Wh,FunnelChart:jh,GaugeChart:Yh,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:uf,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:hf,ProcessSankey:df,ChordDiagram:ff,TreeDiagram:pf,Treemap:yf,CirclePack:gf,ChoroplethMap:vf,ProportionalSymbolMap:wf,FlowMap:kf,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",buildProps:(t,e,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(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=Lf(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=$f(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:l,seed:a}):Array.isArray(t)?t:[],d=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:a}=t,l=Af(s),c=e.map((t,e)=>Rf(Cf(t,e,o))).filter(t=>null!=t),u=function(t){if(!t)return;const e=Rf(t[0]),o=Rf(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(a),d=u?.[0]??(c.length?Math.min(...c):0),h=u?.[1]??(c.length?Math.max(...c):1),f=h===d?1:h-d,p=zf().domain([0,n]).range([l.plot.x,l.plot.x+l.plot.width]),y=Array.from({length:n},()=>0),g=[];e.forEach((t,e)=>{const r=Rf(Cf(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-d)/f*n)));y[s]+=1,g.push({id:(t.id??"galton-"+e)+"",x:p(s+.5),y:l.plot.y+i+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...t,value:r,bin:s}})});const m=l.plot.y+l.plot.height;return{config:Pf(r,[...Cp({x:l.plot.x,y:l.plot.y,width:l.plot.width,height:l.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...Rp({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:p,yTop:l.plot.y-400,yBottom:m,wallThickness:6})],"GaltonBoardChart"),initialSpawns:g,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:y.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot: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:Tg(d.initialSpawns),projectionRows:d.projectionRows,bodyStyle:_f(e||i.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:n,windows:i,watermark:r,ballRadius:s,seed:a,size:l,timeExtent:c,timeScale:u=1}=t,d=Af(l),h=e.map((t,e)=>Rf(Cf(t,e,o))).filter(t=>null!=t),f=Rf(c?.[0]),p=Rf(c?.[1]),y=h.length?Math.min(...h):0,g=h.length?Math.max(...h):y+i.size,m=Math.min(f??y,y),b=Math.max(p??g,g),x=Math.floor(m/i.size)*i.size,v=Math.max(1,Math.ceil((b-x+i.size)/i.size)),w=h.length?Math.max(...h):0,k="function"==typeof r?r(w):Rf(r?.value)??w-(r?.delay??i.size),S=Math.max(0,Math.min(v,Array.from({length:v},(t,e)=>e).reduce((t,e)=>x+(e+1)*i.size>k?t:t+1,0))),A=function(t,e){const o=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:o,height:t.plot.height},windowPlot:{x:t.plot.x+o,y:t.plot.y,width:Math.max(40,t.plot.width-o),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(d,s),M=x+v*i.size,_=Vp().domain([x,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),P=Array.from({length:v},()=>({value:0,secondary:0})),C=[];e.forEach((t,e)=>{const r=Rf(Cf(t,e,o));if(null==r)return;const a=Rf(Cf(t,e,n))??r,l=Math.max(0,Math.min(v-1,Math.floor((r-x)/i.size))),c=k>=x+(l+1)*i.size;P[l].value+=c?0:1,P[l].secondary+=c?1:0,C.push({id:(t.id??"event-"+e)+"",x:Math.max(A.windowPlot.x+s,Math.min(A.windowPlot.x+A.windowPlot.width-s,_(r))),y:d.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:l,late:c}})});const R=d.plot.y+d.plot.height,L=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=Vp().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:A.gutter,plot:d.plot,windowCount:v,windowPlot:A.windowPlot,windowSize:i.size,windowStart:x},d.plot.y+.28*d.plot.height);return{config:Pf(a,[...Cp({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...Xp({idPrefix:"eventdrop-window",count:v,xScale:t=>_(x+t*i.size),yTop:A.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?L[0]?.y1:L[t-1]?.y2??L[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?A.wallTop:e+1.25*s},yBottom:R,wallThickness:6}),...L.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:C,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:u},projectionRows:P.map((t,e)=>({label:`${x+e*i.size}-${x+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:A.gutter,lidSegments:L,lateCount:P.reduce((t,e)=>t+e.secondary,0),plot:d.plot,windowPlot:A.windowPlot,watermarkValue:k,windowCount:v,windowSize:i.size,windowStart:x}}}({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:Tg(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:_f(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,a=function(t){const{data:e,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:a}=t,l=If(i,1),c=Af(a),u=[],d=new Map,h=new Map,f=[];function p(t){let e=d.get(t);return null==e&&(e=u.length,u.push(t),d.set(t,e)),e}e.forEach((t,e)=>{p((Cf(t,e,o)??"unknown")+"")});const y=Math.max(1,u.length),g=function(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}}(c.plot,y,r),m=Math.max(0,g.tubeWidth/2-r-1),b=u.map(()=>[]);e.forEach((t,e)=>{const i=(Cf(t,e,o)??"unknown")+"",s=p(i),a=n?Rf(Cf(t,e,n)):1,u=Math.max(0,Math.round((a??0)/l)),d=g.centerX(s);for(let o=0;u>o;o+=1){const n=h.get(i)??0,a=g.perRow>1?((g.perRow>1?n%g.perRow:0)/(g.perRow-1)*2-1)*m:0;h.set(i,n+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${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:{...t,category:i,unitIndex:o}})}});const x=b.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;x>t;t+=1)for(const e of b)e.length>t&&f.push(e[t]);const v=c.plot.y+c.plot.height,w=[...Cp({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],k=c.plot.y-400;for(let t=0;y>t;t+=1){const e=g.centerX(t);for(const o of[-1,1])w.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*g.tubeWidth/2,y:(k+v)/2,width:6,height:v-k}})}return{config:Pf(s,w,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:u.map(t=>({label:t,value:h.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),o=e.length?e:["Intake"],n=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),i=If(t.unitValue,1),r=$f(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),l=a.reduce((t,e)=>t+e,0)||1,c=n-o.length,u=a.map(t=>t/l*c),d=u.map(t=>1+Math.floor(t));let h=n-d.reduce((t,e)=>t+e,0);const f=u.map((t,e)=>({index:e,fraction:t-Math.floor(t)})).sort((t,e)=>e.fraction-t.fraction);for(let t=0;h>0;t=(t+1)%f.length)d[f[t].index]+=1,h-=1;return o.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*i,mechanical:!0,unitCount:d[e],unitValue:i,share:d[e]/n}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...n,config:a.config,initialSpawns:Tg(a.initialSpawns),projectionRows:a.projectionRows,bodyStyle:_f(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:n,radiusAccessor:i,pointRadius:r,seed:s,size:a,xExtent:l,collisionIterations:c,settle:u}=t,d=Af(a),h=$f(s),f=[],p=[],y=new Map;e.forEach((t,e)=>{const s=Rf(Cf(t,e,o));if(null==s)return;const a=n?(Cf(t,e,n)??"All")+"":"All",l=i?Rf(Cf(t,e,i)):null,c=Lf(null!=l&&l>0?l:r,2,18);!function(t){let e=y.get(t);null==e&&(e=p.length,p.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:c})});const g=f.map(t=>t.value),m=l?Rf(l[0]):null,b=l?Rf(l[1]):null,x=g.length?Math.min(...g):0,v=g.length?Math.max(...g):1;let w=m??x,k=b??v;if(w===k&&(w-=.5,k+=.5),w>k){const t=k;k=w,w=t}const S=Math.max(r,...f.map(t=>t.radius)),A=d.plot.x+S+8,M=d.plot.x+d.plot.width-S-8,_=Up().domain([w,k]).range([A,M]),P=Math.max(1,p.length),C=Math.min(Math.max(28,3*S),d.plot.height/4),R=d.plot.y+C,L=Math.max(0,d.plot.y+d.plot.height-C-R),I=t=>{const e=y.get(t)??0;return 1===P?d.plot.y+.54*d.plot.height:R+e/(P-1)*L},T=new Map,$=f.map((t,e)=>{T.set(t.group,(T.get(t.group)??0)+1);const o=_(t.value),n=I(t.group),i=(h()-.5)*t.radius*1.6,r=(h()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:u?o+i:Lf(o+(e%9-4)*t.radius*2.5,A,M),y:u?n+r:d.plot.y-18-e%12*t.radius,vx:u?0:22*(h()-.5),vy:u?0:24+18*h(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:o,targetY:n},springs:[{target:{type:"point",x:o,y:n},restLength:0,stiffness:34,damping:5.5}]}});return{config:Pf(s,Cp({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:$,projectionRows:p.map(t=>({label:t,value:T.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[w,k],xRange:[A,M],groups:p.map(t=>({label:t,y:I(t),count:T.get(t)??0})),plot:d.plot}}}({data:Array.isArray(t)?t:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...n,config:s.config,initialSpawns:Tg(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:_f(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[900,420],s=Array.isArray(i.stages)?i.stages:[],a=ay({data:Array.isArray(t)?t:[],stages:s,size:r,idAccessor:i.idAccessor,stageAccessor:i.stageAccessor||"stage",groupBy:i.groupBy,groupLabelAccessor:i.groupLabelAccessor,workAccessor:i.workAccessor,radiusAccessor:i.radiusAccessor,ballRadius:i.ballRadius??6,seed:i.seed??1,groupCompletion:i.groupCompletion,groupAnchorAlong:i.groupAnchorAlong,settle:i.settle??!0,gravityX:i.gravityX,gravityY:i.gravityY}),l=a.metadata;return{...n,config:a.config,initialSpawns:Tg(a.initialSpawns),projectionRows:a.projectionRows,regionEffects:l?.regionEffects,bodyStyle:_f(e||i.colorBy||i.groupBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.workAccessor||i.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Sy({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:Tg(s.initialSpawns),projectionRows:[],bodyStyle:_f(e||i.colorBy)}}},CrucibleChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=pg({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,Ky(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,Ky(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,l=fg(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 Ty(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:{...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)||My(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)??Ig(t),datum:t.datum}));return{id:t.id,label:t.label,count:r,share:0,secondary:t.secondary,secondaryLabel:t.secondaryLabel,observed:t.observed,bodyIds:o.map(t=>t.id),recentBodies:s,metadata:t.metadata}}),s=r.reduce((t,e)=>t+e.count,0);return r.map(t=>({...t,share:s>0?t.count/s:0}))}(u.map(t=>({id:t.key,label:t.label,count:t.count,secondary:"count"===d||"amount"===d?t.amount:Number(t.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),f={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},p=e??i.colorBy??"category",y=!1===i.showChrome?null:Sf.createElement(Rg,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),g=!1===i.showProjection?null:Sf.createElement(Lg,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:Tg(ug(l,s.layout,f)),projectionRows:h,bodyStyle:t=>function(t,e,o,n){const i=t.datum,r={stroke:n.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:n.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:n.opacity??.96};if(!i?.__crucible)return{...r,fill:n.color??"#b8792d"};if("product"===i.kind){const t=e.products[i.semanticId];return{...r,fill:n.color??t?.color??Dg(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??Dg(a)}}(t,l,p,i),getBodyLabel:t=>function(t,e){const o=t.datum;if(o?.__crucible)return"product"===o.kind?e.products[o.semanticId]?.label:e.components[o.semanticId]?.label}(t,l),renderBodySVG:xg,backgroundGraphics:$g(y,n.backgroundGraphics),foregroundGraphics:$g(g,n.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:n,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:a,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:y,sourceAccessor:g,targetAccessor:m,throughputAccessor:b}=t,x=Af(y),v=$f(p),w=new Map,k=new Map,S=[];function A(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}l.forEach((t,e)=>{const o=(Cf(t,e,r)??t.id??e)+"",n=Rf(Cf(t,e,s)),i=Rf(Cf(t,e,a));if(null!=n&&null!=i){const t={x:n,y:i};w.set(o,t),S.push(t)}k.set(o,(t.label??t.name??o)+"")});const M=[];n.forEach((t,e)=>{const o=A(Cf(t,e,g)),n=A(Cf(t,e,m)),i=Math.max(0,Rf(Cf(t,e,b))??0),r=Zp(d?Cf(t,e,d):void 0),s=r.length?r:Zp(t.path??t.points??t.route);s.forEach(t=>S.push(t)),M.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const _=(C=S,"normalized"===(P=e)||"pixels"===P?P:C.length>0&&C.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var P,C;const R=new Map;for(const[t,e]of w)R.set(t,Qp(e,x,_));const L=[];for(const t of M){let e=t.rawPath.map(t=>Qp(t,x,_));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&&(k.has(t.source)||k.set(t.source,t.source),k.has(t.target)||k.set(t.target,t.target),L.push({...t,path:e,packetCount:0}))}const I=If(u,.12),T=Math.max(1,Math.round(i)),$=L.map(t=>Math.max(1,Math.round(t.throughput*I))),z=$.reduce((t,e)=>t+e,0),D=z>T?T/z:1;L.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor($[e]*D))});let F=L.reduce((t,e)=>t+e.packetCount,0);for(;F>T;){const t=L.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>L[t].packetCount)?o:t,-1);if(-1===t)break;L[t].packetCount-=1,F-=1}const E=new Map,O=new Map,B=[],N=If(o,90),W=If(c,4);L.forEach((t,e)=>{E.set(t.target,(E.get(t.target)??0)+t.throughput),O.set(t.source,(O.get(t.source)??0)+t.throughput);const o=Jp(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=f?i:Lf(.12+.84*i+.04*(v()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*v())),a=ty(t.path,s),l=ty(t.path,r),c=ey(t.path,s),u={x:-c.y,y:c.x},d=(v()-.5)*W*1.5;B.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:c.x*N+10*(v()-.5),vy:f?0:c.y*N+10*(v()-.5),mass:.8,spawnAt:f?0:.04*e+n/32,shape:{type:"circle",radius:W},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:n,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:N,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target},springs:"none"!==h&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*W,stiffness:26,damping:4.25}]:void 0})}});const j=Math.max(18,5*W),Y=Array.from(R,([t,e])=>({nodeId:t,label:k.get(t)??t,sensorId:"physical-flow-node-"+Tf(t),point:e})),G=Y.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:j,height:j}})),H=Object.fromEntries(Y.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),q=Pf(p,[...Cp({x:x.plot.x,y:x.plot.y,width:x.plot.width,height:x.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...G],"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});q.bodyLimit=T,q.eviction="oldest",q.observation={...q.observation,sensors:H};const V=Array.from(R,([t,e])=>({id:t,label:k.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+Tf(t),incoming:E.get(t)??0,outgoing:O.get(t)??0})),X=L.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:k.get(t.source)??t.source,targetLabel:k.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:q,initialSpawns:B,projectionRows:V.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:B.length,totalThroughput:L.reduce((t,e)=>t+e.throughput,0),plot:x.plot,nodes:V,links:X}}}({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:Tg(s.initialSpawns),projectionRows:s.projectionRows,bodyStyle:_f(e||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",buildProps:(t,e,o,n,i)=>{const r=n.size??[700,380],s=function(t){const e=function(t,e,o){const n=t?.observation;return{...t,observation:{...n,chartId:e??n?.chartId??"physics-custom",chartType:n?.chartType??"PhysicsCustomChart",onObservation:o??n?.onObservation}}}(t.config,t.chartId,t.onObservation),o=cy(t.colorScheme,t.themeCategorical,G),n=Af(t.size),i={data:t.data,scales:{x:ly().domain(t.xExtent??[0,1]).range([n.plot.x,n.plot.x+n.plot.width]),y:ly().domain(t.yExtent??[0,1]).range([n.plot.y+n.plot.height,n.plot.y])},dimensions:n,theme:{semantic:t.semantic,categorical:[...o]},resolveColor:uy(o,t.colorScheme),config:t.layoutConfig??{},world:new qp(e)},r=t.skipLayout?{}:t.layout(i)??{},s=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...n}=t,i=o.get(e)??[];i.push(n),o.set(e,i)}return t.map(t=>{const e=o.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...r.initialSpawns??r.bodies??[]],r.constraints);return{config:dy(e,r),context:i,initialSpawnPacing:r.initialSpawnPacing,initialSpawns:s,result:r}}({chartId:i.chartId,colorScheme:o,config:i.config,data:Array.isArray(t)?t:[],layout:i.layout,layoutConfig:i.layoutConfig,semantic:b(w)??{},size:r,themeCategorical:w.colors.categorical,xExtent:i.xExtent,yExtent:i.yExtent});return{...n,config:s.config,initialSpawns:Tg(s.initialSpawns),projectionRows:[],bodyStyle:s.result.bodyStyle??_f(e||i.colorBy)}}}};function Eg(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Og(t){if(!t||2>t.length)return;const e=Eg(t[0]),o=Eg(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Bg(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");const r=t.margin,s=r?{x:r.left,y:r.top,width:t.width-r.left-r.right,height:t.height-r.top-r.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:Array.isArray(t.annotations)?t.annotations.length:0,ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:i,...r?{margin:r}:{},...s?{plot:s}:{}}}import*as Ng from"react";import*as Wg from"react-dom/server";import{scaleOrdinal as jg}from"d3-scale";import{jsx as Yg,jsxs as Gg}from"react/jsx-runtime";function Hg(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>vt(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:G;return jg().domain(t).range(n)}function qg(t,e,o){if(0===t.length)return;const n=Hg(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}function Vg(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Xg(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function Ug(t,e,o,n){const i=Xg(n);return e+o+Math.ceil(t.length*i*.58)}function Kg(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=qi(s),d=a+l,h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right),p=e.map(t=>Ug(t,a,l,o));if(h){const t=Math.max(a,s?.maxWidth??f),o=[];let n=0,i=0;p.forEach((e,r)=>{const s=0===i?e:i+c+e;i>0&&s>t?(o.push({start:n,end:r,width:i}),n=r,i=e):i=s}),e.length>0&&o.push({start:n,end:e.length,width:i});const r=Vg(s?.align),l=[];return o.forEach((o,n)=>{let i="center"===r?Math.max(0,(t-o.width)/2):"end"===r?Math.max(0,t-o.width):0;for(let t=o.start;o.end>t;t++)l.push({category:e[t],width:p[t],x:i,y:n*u}),i+=p[t]+c}),{items:l,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const y=Math.max(0,...p);return{items:e.map((t,e)=>({category:t,width:p[e],x:0,y:e*u})),width:y,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function Zg(t){const{legendGroups:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,rowHeight:c}=qi(s),u=a+l,d=Math.max(12,Xg(o)),h="top"===n||"bottom"===n,f=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??f),i=Vg(s?.align);let r=0,l=0;const c=[];for(const i of e){const e=i.items.map(t=>t.label),u=Kg({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,f=i.label?Ug(i.label,0,0,o):0,p=h>0?h+8:0,y=p+u.width,g=Math.max(u.height,f);c.push({group:i,x:r,y:0,itemOffsetX:p,itemOffsetY:0,width:y,height:g,items:u.items}),r+=y+12,l=Math.max(l,g)}const h=c.length>0?r-12:0,p=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:c.map(t=>({...t,x:t.x+p})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const p=Vi(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),c);let y=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>Ug(t.label,a,l,o)),i=Math.max(0,...n,t.label?Ug(t.label,0,0,o):0);return y=Math.max(y,i),{group:t,x:0,y:p[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*c,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*c}))}}),width:y,height:p.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}function Qg(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?34:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?124:108,swatchSize:14}}function Jg(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 tm,jsxs as em}from"react/jsx-runtime";var om=16;function nm(t,e){return t.color||e.colors.annotation||e.colors.text}function im(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 rm(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 sm(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 am(t){const{annotations:e}=t;if(!e||0===e.length)return null;const o=a(e),n=t.scales.geoProjection,i=n?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=n([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,r=!!n&&!t.scales.x&&!t.scales.y,s=t=>Number(t),l=t.scales.x??(r?s:void 0),c=t.scales.y??(r?s:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{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,frameType:t.projection?"ordinal":n||t.scales.x||t.scales.y?"xy":"network",...u?{projection:u}:{}},h=Jr(t.autoPlaceAnnotations?fs({annotations:i,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):i,(e,o)=>function(t,e,o){const{scales:n,layout:i,theme:r,xAccessor:s,yAccessor:a}=o;switch(t.type){case"y-threshold":{const s=t.value;if(null==s)return null;const a=nm(t,r),l=t.label,c=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===o.projection&&n.r){const o=n.r(s);return null==o?null:em("g",{opacity:t.opacity,children:[tm("line",{x1:o,y1:0,x2:o,y2:i.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&tm(Ur,{x:o+4,y:om,textAnchor:"start",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:im(t,r,"halo")})]},"ann-ythresh-"+e)}const h=n.y?n.y(s):n.r?n.r(s):null;return null==h?null:em("g",{children:[tm("line",{x1:0,y1:h,x2:i.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&tm(Ur,{x:"left"===c?4:"center"===c?i.width/2:i.width-4,y:20>h?Math.min(i.height-4,h+om):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:r.typography.tickSize,fill:a,fontFamily:r.typography.fontFamily,text:l,background:im(t,r,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const s=t.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=nm(t,r),c=t.label,u=t.labelPosition||"top";return em("g",{opacity:t.opacity,children:[tm("line",{x1:a,y1:0,x2:a,y2:i.height,stroke:l,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&tm(Ur,{x:a>.6*i.width?a-4:a+4,y:"bottom"===u?i.height-4:"center"===u?i.height/2:om,textAnchor:a>.6*i.width?"end":"start",fontSize:r.typography.tickSize,fill:l,fontFamily:r.typography.fontFamily,text:c,background:im(t,r,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=n.y?.domain?.(),s=t.y0??o?.[0],a=t.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=Un(t.fill||nm(t,r),"ssr-band-"+e),f=t.fillOpacity??.1;return em("g",{opacity:t.opacity,children:[h.def&&tm("defs",{children:h.def}),tm("rect",{x:0,y:u,width:i.width,height:d,fill:h.fill,fillOpacity:f}),t.label&&tm(Ur,{x:i.width-4,y:Math.max(u,0)+om,textAnchor:"end",fontSize:r.typography.tickSize,fill:t.color||nm(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:im(t,r,"halo")})]},"ann-band-"+e)}case"x-band":{const o=n.x?.domain?.(),s=t.x0??o?.[0],a=t.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=Un(t.fill||nm(t,r),"ssr-xband-"+e),f=t.fillOpacity??.1;return em("g",{opacity:t.opacity,children:[h.def&&tm("defs",{children:h.def}),tm("rect",{x:u,y:0,width:d,height:i.height,fill:h.fill,fillOpacity:f}),t.label&&tm(Ur,{x:u+4,y:om,textAnchor:"start",fontSize:r.typography.tickSize,fill:t.color||r.colors.primary||nm(t,r),fontFamily:r.typography.fontFamily,fontWeight:"bold",text:t.label,background:im(t,r,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!n.o)return null;const s=n.o(t.category+"");if(null==s)return null;const a=n.o.bandwidth?n.o.bandwidth():40,l=nm(t,r),c=t.opacity??.1,u=t.label;return em("g","horizontal"===o.projection?{children:[tm("rect",{x:0,y:s,width:i.width,height:a,fill:l,opacity:c}),u&&tm(Ur,{x:12,y:s+a/2,dominantBaseline:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:im(t,r,"none")})]}:{children:[tm("rect",{x:s,y:0,width:a,height:i.height,fill:l,opacity:c}),u&&tm(Ur,{x:s+a/2,y:om,textAnchor:"middle",fill:l,fontSize:r.typography.tickSize,fontWeight:"bold",fontFamily:r.typography.fontFamily,text:u,background:im(t,r,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const{x:o,y:i}=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:rm(t,e,o),y:sm(t,e,n)}}(t,n,s,a);if(null==o||null==i)return null;const l="text"===t.type,c=t.dx??(l?0:30),u=t.dy??(l?0:-30),d=t.color||r.colors.text;if(!l){const n="callout"===t.type?"callout-circle":t.type,r="callout-circle"===n?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===n?{width:t.width,height:t.height}:void 0;return tm(vr,{noteData:{x:o,y:i,dx:c,dy:u,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:n,...r?{subject:r}:{},connector:t.connector||{end:"arrow"},color:d,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return tm("g",{children:tm("text",{x:o+c,y:i+u,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||r.typography.labelSize,fill:d,fontFamily:r.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),t.svgAnnotationRules,d);return h.length>0?tm("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:h}):null}import*as lm from"react";import{jsx as cm,jsxs as um}from"react/jsx-runtime";function dm(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function hm(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 fm(t,e,o){return Fi(t.showLegend&&!t.__legendIncludesAutomatic?qg(e,t.colorScheme,o):void 0,t.legend)}var pm={right:110,left:110,top:50,bottom:80};function ym(t,e){if(t.__autoLegendMargin&&!gm(t,e))return pm[e]}function gm(t,e){const o=t.__explicitMargin;return"number"==typeof o||!(!o||"object"!=typeof o||"number"!=typeof o[e])}function mm(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",l={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:ym(o,a),preserveExplicitMargin:gm(o,a)};if(null!=o.legend){const e=fm(o,n,i);(Ei(e)||Oi(e))&&function(t,e){if(e.preserveExplicitMargin)return;const o=e.position||"right",n={theme:e.theme,position:o,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout},i=Ei(e.legend)?function(t){const{width:e,height:o,swatchSize:n}=Zg(t);return{width:e,height:o,swatchSize:n}}({...n,legendGroups:e.legend.legendGroups}):Oi(e.legend)?Qg({...n,gradient:e.legend.gradient}):null;if(!i)return;const r=Wi(e.legend),s=Math.max(e.minimumMargin??0,Hi(e.legend,e.legendLayout)),a=Yi(e.axisChrome,e.legendLayout),l=Math.max(e.minimumMargin??0,r+i.height+(e.hasTitle?24:0)),c=Math.max(e.minimumMargin??0,a+r+i.height);"right"===o?t.right=Math.max(t.right,s):"left"===o?t.left=Math.max(t.left,s):"top"===o?t.top=Math.max(t.top,l):t.bottom=Math.max(t.bottom,c)}(t,{...l,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;if(e.preserveExplicitMargin)return;const o=e.position||"right",n=function(t){const{width:e,height:o,swatchSize:n}=Kg(t);return{width:e,height:o,swatchSize:n}}({categories:e.categories,colorScheme:e.colorScheme,theme:e.theme,position:o,totalWidth:e.size[0],totalHeight:e.size[1],margin:t,hasTitle:e.hasTitle,legendLayout:e.legendLayout}),i=qg(e.categories,e.colorScheme,e.theme),r=Wi(i),s=Math.max(e.minimumMargin??0,Hi(i,e.legendLayout)),a=Yi(e.axisChrome,e.legendLayout),l=Math.max(e.minimumMargin??0,r+n.height+(e.hasTitle?24:0)),c=Math.max(e.minimumMargin??0,a+r+n.height);"right"===o?t.right=Math.max(t.right,s):"left"===o?t.left=Math.max(t.left,s):"top"===o?t.top=Math.max(t.top,l):t.bottom=Math.max(t.bottom,c)}(t,{...l,categories:n,colorScheme:o.colorScheme});return a}function bm(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=fm(e,o,n);if(lm.isValidElement(t))return t;const i=function(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:Ei(t)||Oi(t)?t.legendDistance:void 0};return Ei(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=Zg(t),n="top"===t.position||"bottom"===t.position,i={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??Ni(i,t.legendLayout),s=Wi(i),a=ji(t.legendLayout),l=Yi(t.axisChrome,t.legendLayout),c=Yi(void 0,t.legendLayout),u=t.theme.colors.grid||t.theme.colors.textSecondary;let d,h;if("left"===t.position?(d=t.margin.left-a-r-s,h=t.margin.top):"top"===t.position?(d=t.margin.left,h=t.margin.top-c-s-o.height):"bottom"===t.position?(d=t.margin.left,h=Math.max(t.totalHeight-t.margin.bottom+s,Math.min(t.totalHeight-t.margin.bottom+l+s,t.totalHeight-o.height))):(d=t.totalWidth-t.margin.right+a+s,h=t.margin.top),!n){const e=Vi(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=[Yg("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(Yg("text",{y:s.labelY,fontSize:Xg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:n.label},"legend-group-label-"+i)),l.push(Yg("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?Yg("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):Yg("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return Gg("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[l,Yg("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Xg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return Yg("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":"vertical",children:n})}const f=o.groups.flatMap((e,i)=>{const{group:r}=e,s=r.type??"fill",a=[];if(r.label&&a.push(Yg("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Xg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:r.label}:{x:e.x,y:e.y+Xg(t.theme),fontSize:Xg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:r.label},"legend-group-label-"+i)),a.push(...e.items.map((n,a)=>{const l=r.items[a],c=r.styleFn(l,a),u="function"==typeof s?s(l):"line"===s?Yg("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:c}):Yg("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:c});return Gg("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,Yg("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Xg(t.theme),fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:n.category})]},`legend-${i}-${a}`)})),n&&o.groups.length-1>i){const t=e.x+e.width+6;a.push(Yg("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:u},"legend-group-separator-"+i))}return a});return Yg("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,"data-orientation":n?"horizontal":"vertical",children:f})}({...o,legendGroups:t.legendGroups}):Oi(t)?function(t){const e=Qg(t),o="top"===t.position||"bottom"===t.position,n={gradient:t.gradient,legendDistance:t.legendDistance},i=Ni(n),r=Wi(n),s=ji(t.legendLayout),a=Yi(t.axisChrome,t.legendLayout),l=Yi(void 0,t.legendLayout),c=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",u=t.gradient.format||(t=>Math.round(100*t)/100+"");let d,h;"left"===t.position?(d=t.margin.left-s-i-r,h=t.margin.top):"top"===t.position?(d=t.margin.left,h=t.margin.top-l-r-e.height):"bottom"===t.position?(d=t.margin.left,h=Math.max(t.totalHeight-t.margin.bottom+r,Math.min(t.totalHeight-t.margin.bottom+a+r,t.totalHeight-e.height))):(d=t.totalWidth-t.margin.right+s+r,h=t.margin.top);const f=Array.from({length:17},(e,n)=>{const i=n/16;return Yg("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?0:void 0,i=t.gradient.label?8:0;return Gg("g",{className:"semiotic-legend",transform:`translate(${d},${h})`,children:[Yg("defs",{children:Yg("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:f})}),t.gradient.label&&Yg("text",{x:e.width/2,y:n,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),Yg("rect",{x:0,y:i,width:e.width,height:o,fill:`url(#${c})`,rx:2}),Yg("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[0])}),Yg("text",{x:e.width,y:i+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[1])})]})}const p=t.gradient.label?-6:void 0;return Gg("g",{className:"semiotic-legend",transform:`translate(${d},${h+(t.gradient.label?12:0)})`,children:[Yg("defs",{children:Yg("linearGradient",{id:c,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:f})}),t.gradient.label&&Yg("text",{x:0,y:p,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:t.theme.typography.fontFamily,children:t.gradient.label}),Yg("rect",{x:0,y:0,width:14,height:100,fill:`url(#${c})`,rx:2}),Yg("text",{x:19,y:10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[1])}),Yg("text",{x:19,y:100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:t.theme.typography.fontFamily,children:u(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}(t,l);return i||(Ei(t)||Oi(t)?null:t??null)}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=Hg(e,o,n),c="top"===i||"bottom"===i,u=Kg(t),d=qg(e,o,n),h=t.reservedWidth??Ni(d,t.legendLayout),f="number"==typeof t.legendDistance?Math.max(0,t.legendDistance):Wi(d),p=ji(t.legendLayout),y=Yi(t.axisChrome,t.legendLayout),g=Yi(void 0,t.legendLayout);let m,b;if("left"===i?(m=a.left-p-h-f,b=a.top):"top"===i?(m=a.left,b=a.top-g-f-u.height):"bottom"===i?(m=a.left,b=Math.max(s-a.bottom+f,Math.min(s-a.bottom+y+f,s-u.height))):(m=r-a.right+p+f,b=a.top),c){const t=u.items.map((t,e)=>Gg("g",{transform:`translate(${t.x},${t.y})`,children:[Yg("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),Yg("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Xg(n),fill:n.colors.text,fontFamily:n.typography.fontFamily,children:t.category})]},"legend-"+e));return Yg("g",{className:"semiotic-legend",transform:`translate(${m},${b})`,children:t})}const x=Vi([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],v=u.items.map((t,e)=>Gg("g",{transform:`translate(${t.x},${t.y+x.itemsY})`,children:[Yg("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),Yg("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Xg(n),fill:n.colors.text,fontFamily:n.typography.fontFamily,children:t.category})]},"legend-"+e));return Gg("g",{className:"semiotic-legend",transform:`translate(${m},${b})`,children:[Yg("line",{x1:0,y1:x.lineY,x2:h,y2:x.lineY,stroke:"gray"}),v]})}({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}function xm(t){return Math.round(100*t)/100+""}function vm(t,e){const o=R(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 um("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&&cm("title",{id:s,children:r}),e.description&&cm("desc",{id:a,children:e.description}),e.defs&&cm("defs",{children:e.defs}),n&&"transparent"!==n&&cm("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),cm("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&cm("text",{id:i+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:o.titleSize,fontWeight:"bold",fill:o.text,fontFamily:o.fontFamily,children:r}),e.legend&&cm("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{Fragment as wm,jsx as km,jsxs as Sm}from"react/jsx-runtime";function Am(t,e){const o=C(t.theme),n=t.size||[500,300],i=$s({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Is(t.title),s=B(t.data),a=t.showLegend?Jg(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],l={hasAxis:!1!==t.showAxes,hasAxisLabel:!!t.xLabel};mm(i,{props:{...t,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"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),h=t.colorScheme||o.colors.categorical,f={chartType:t.chartType,windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:d?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:d?void 0:t.xAccessor,yAccessor:d?void 0:t.yAccessor,timeAccessor:d?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor,categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,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:Ft(t.gradientFill),lineGradient:Et(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:h,themeCategorical:o.colors.categorical,themeSemantic:b(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat},p=new an(f);if(t.data&&p.ingest({inserts:s,bounded:!0}),p.computeScene({width:c,height:u}),!p.scales||0===p.scene.length)return e&&(e.evidence=Bg({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:p.scales?[]:["NO_SCALES"],margin:i})),Wg.renderToStaticMarkup(vm(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:c,innerHeight:u,idPrefix:t._idPrefix}));const y=t._idPrefix,g=jc({nodes:p.scene,renderMode:t.renderMode,fallback:(t,e)=>wa(t,e,y)});e&&(e.evidence=Bg({frameType:"xy",width:n[0],height:n[1],marks:g.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,xDomain:Og(p.scales.x?.domain?.()),yDomain:Og(p.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const m=t.showGrid?function(t,e,o,n,i){const{grid:r}=R(o),s=n?n+"-":"",a="exact"===i?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),l="exact"===i?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),c=Ms(t.x,a,i),u=Ms(t.y,l,i);return um("g",{id:s+"grid",className:"semiotic-grid",opacity:.8,children:[c.map((o,n)=>{const i=t.x(o);return cm("line",{x1:i,y1:0,x2:i,y2:e.height,stroke:r,strokeWidth:.5},"gx-"+n)}),u.map((o,n)=>{const i=t.y(o);return cm("line",{x1:0,y1:i,x2:e.width,y2:i,stroke:r,strokeWidth:.5},"gy-"+n)})]})}(p.scales,{width:c,height:u},o,y,t.axisExtent):null,x=g.map(t=>t.element),v=hm(t)+"-plot-clip",w=!1!==t.showAxes?function(t,e,o,n,i){const r=R(n),s=ji(o.legendLayout),a=o.legend&&"left"===o.legendPosition&&s>0?s:o.margin?.left??40,l="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),c="exact"===o.axisExtent?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),u=o.axes?.find(t=>"bottom"===t.orient),d=o.axes?.find(t=>"left"===t.orient),h=u?.tickValues??Ms(t.x,u?.ticks??l,o.axisExtent),f=h.map(t=>t.valueOf()),p=u?.tickFormat||o.xFormat||o.tickFormatTime||xm,y=h.map((e,o)=>({pixel:t.x(e),label:p(e,o,f)})),g=d?.tickValues??Ms(t.y,d?.ticks??c,o.axisExtent),m=d?.tickFormat||o.yFormat||o.tickFormatValue||xm,b=g.map(e=>({pixel:t.y(e),label:m(e)})),x=u?.label??o.xLabel,v=d?.label??o.yLabel;return um("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==u?.baseline&&cm("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:r.border,strokeWidth:1}),y.map((t,o)=>um("g",{transform:`translate(${t.pixel},${e.height})`,children:[cm("line",{y2:5,stroke:r.border,strokeWidth:1}),cm("text",{y:18,textAnchor:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"xtick-"+o)),x&&cm("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,children:x}),!1!==d?.baseline&&cm("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:r.border,strokeWidth:1}),b.map((t,e)=>um("g",{transform:`translate(0,${t.pixel})`,children:[cm("line",{x2:-5,stroke:r.border,strokeWidth:1}),cm("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:r.tickSize,fill:r.textSecondary,fontFamily:r.fontFamily,children:t.label})]},"ytick-"+e)),v&&cm("text",{x:15-a,y:e.height/2,textAnchor:"middle",fontSize:r.labelSize,fill:r.text,fontFamily:r.fontFamily,transform:`rotate(-90, ${15-a}, ${e.height/2})`,children:v})]})}(p.scales,{width:c,height:u},t,o,y):null,k=t.annotations?am({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:p.scales.x,y:p.scales.y},layout:{width:c,height:u},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:y}):null,S=t.svgPreRenderers&&p.scales?t.svgPreRenderers.map((t,e)=>{try{return km(Ng.Fragment,{children:t(p.scene,p.scales,{width:c,height:u})},"pre-"+e)}catch{return null}}).filter(Boolean):null,A=bm({props:{...t,axisChrome:l},categories:a,theme:o,size:n,margin:i,hasTitle:r});return Wg.renderToStaticMarkup(vm(Sm(wm,{children:[t.backgroundGraphics,S,m,km("defs",{children:km("clipPath",{id:v,children:km("rect",{x:0,y:0,width:c,height:u})})}),km("g",{clipPath:`url(#${v})`,children:x}),w,k,t.foregroundGraphics,p.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:c,innerHeight:u,legend:A,idPrefix:t._idPrefix}))}import*as Mm from"react-dom/server";import{scaleBand as _m,scaleLinear as Pm}from"d3-scale";var Cm=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: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||gt,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function Rm(t){const e=t.getSymbol;if(!e)return null;const o=t.config.symbolMap,n=new Map;let i=0;return t=>{const r=e(t)+"",s=o?.[r];if(s)return s;let a=n.get(r);return a||(a=co[i%co.length],i++,n.set(r,a)),a}}function Lm(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 Im(t,e){const{columns:o,config:n,resolvePieceStyle:i}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===n.chartType?n.innerRadius||60:0,l=-Math.PI/2+(n.startAngle||0)*Math.PI/180,c=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,u=null!=n.sweepAngle&&360>n.sweepAngle,d=Object.values(o),h=d.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),f=u&&!h&&d.length>1&&(n.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],o=e.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:e.pctStart,h=l+u*c,p=l+(u+("number"==typeof o?._pct?o._pct:e.pct))*c,y=i(e.pieceData[0],e.name),g=0===t,m=t===d.length-1,b={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:p,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:y,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?b.roundedEnds=o._roundedEnds:f&&(b.roundedEnds={start:g,end:m}),o?._gradientBand&&(b._gradientBand=o._gradientBand),r.push(b)}return r}import{quantile as Tm}from"d3-array";function $m(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:Tm(t,.25)??o,median:Tm(t,.5)??(o+n)/2,q3:Tm(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as zm}from"d3-scale";var Dm={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h="horizontal"===c,f=i.normalize,p=[];if(s){const t=new Set;for(const e of Object.values(n))for(const o of e.pieceData){const e=s(o);t.has(e)||(t.add(e),p.push(e))}}else p.push("_default");for(const t of Object.values(n)){const e=new Map;for(const o of t.pieceData){const t=s?s(o):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const n=e.get(t);n.total+=r(o),n.pieces.push(o)}let o=0;if(f)for(const t of e.values())o+=Math.abs(t.total);let n=0,i=0;for(const r of p){const c=e.get(r);if(!c)continue;let p=c.total;f&&o>0&&(p/=o);const y=a(c.pieces[0],s?r:t.name),g={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:t.name};if(d){const e=l(0>p?i:n+p),o=0>p?l(i+p)-l(i):l(n)-l(n+p);u.push(Ye(t.x,e,t.width,Math.abs(o),y,g,r)),0>p?i+=p:n+=p}else if(h){const e=l(0>p?i+p:n),o=0>p?l(i)-l(i+p):l(n+p)-l(n);u.push(Ye(e,t.x,Math.abs(o),t.width,y,g,r)),0>p?i+=p:n+=p}}}const y="vertical"===c,g=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=y?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}if(g>0){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));t.length>0&&(t.reduce(y?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e).roundedTop=g),o.length>0&&(o.reduce(y?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e).roundedTop=g)}}return u},clusterbar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h=[],f=new Set;for(const t of Object.values(n))for(const e of t.pieceData){const t=s?s(e):"_default";f.has(t)||(f.add(t),h.push(t))}const p=h.length||1;for(const t of Object.values(n)){const e=t.width/p,o=.2*e,n=e-o,i=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";i.has(t)||i.set(t,[]),i.get(t).push(e)}for(let s=0;h.length>s;s++){const c=i.get(h[s])||[];for(const i of c){const c=r(i),f=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(Ye(r,Math.min(a,d),n,Math.abs(a-d),f,i,h[s]))}else{const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(Ye(Math.min(a,d),r,Math.abs(d-a),n,f,i,h[s]))}}}}const y=i.roundedTop&&i.roundedTop>0?Math.max(0,i.roundedTop):0;for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum);y>0&&(t.roundedTop=y),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}return u},point:function(t,e){const{scales:o,columns:n,getR:i,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,f=Rm(t),p=2*Math.PI,y=-Math.PI/2;for(const t of Object.values(n))for(const e of t.pieceData){const o=e.__rIndex??0,n=e.__rValue??i(e),l=h&&r[o]||a,g=s(e,t.name),m=g.r||5;let b,x;if(d){const e=y+(t.pctStart+t.pct/2)*p,o=l(n);b=Math.cos(e)*o,x=Math.sin(e)*o}else u?(b=t.middle,x=l(n)):(b=l(n),x=t.middle);Lm(c,f,e,b,x,m,g)}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=Rm(t);for(const t of Object.values(n)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const n=t.pieceData[o],a=i(n),d=r(n,t.name),h=d.r||4,f=(7919*o%100/100-.5)*e*.8;Lm(l,u,n,c?t.middle+f:s(a),c?s(a):t.middle+f,h,d)}}return l},pie:Im,donut:Im,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=Tm(o,.25)??n,h=Tm(o,.5)??(n+i)/2,f=Tm(o,.75)??i,p=f-l,y=l-1.5*p,g=f+1.5*p,m=o.find(t=>t>=y)??n,b=[...o].reverse().find(t=>g>=t)??i,x=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const o=r(t);if(y>o||o>g){const 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(f),maxPos:a(b),stats:{n:o.length,min:m,q1:l,median:h,q3:f,max:b,mean:o.reduce((t,e)=>t+e,0)/o.length},style:x,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:x.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6},datum:e.datum})}return c},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d=i.bins||20,h=!1!==i.showIQR;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/d||1,l=Array(d).fill(0);for(const t of e)l[Math.min(Math.floor((t-o)/i),d-1)]++;const f=At(l,1),p=t.width/2*.9;let y;if(u){y=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);y+=` L ${t.middle+l[e]/f*p} ${n}`}y+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);y+=` L ${t.middle-l[e]/f*p} ${n}`}y+=" Z"}else{y=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)y+=` L ${a(o+(e+.5)*i)} ${t.middle-l[e]/f*p}`;y+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)y+=` L ${a(o+(e+.5)*i)} ${t.middle+l[e]/f*p}`;y+=" Z"}const g=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const i=Tm(e,.25)??o,r=Tm(e,.5)??(o+n)/2,s=Tm(e,.75)??n;m={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const b=u?{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))}:{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width};c.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:$m(e),style:g,datum:t.pieceData,category:t.name})}return c},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,n]=St(e),i=null!=h&&isFinite(h)?h:o,d=null!=f&&isFinite(f)?f:n,p=(d-i)/c||1,y=Array(c).fill(0);for(const t of e)i>t||t>d||y[Math.min(Math.floor((t-i)/p),c-1)]++;const g=e.length,m=At(y,1),b=s(t.pieceData[0],t.name);for(let e=0;c>e;e++){if(0===y[e])continue;const o=(u?y[e]/g:y[e]/m)*t.width*.9,n=a(i+e*p),r=a(i+(e+1)*p);l.push(Ye(Math.min(n,r),t.x+t.width-o,Math.abs(r-n),o,b,{bin:e,count:y[e],range:[i+e*p,i+(e+1)*p],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 f=At(l,1),p=s(t.pieceData[0],t.name),y=t.width*h;let g;if(d){const e=t.x+t.width;g=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)g+=` L ${a(o+(t+.5)*i)} ${e-l[t]/f*y}`;g+=` L ${a(n)} ${e} Z`}else{const e=t.x;g=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const n=a(o+(t+.5)*i);g+=` L ${e+l[t]/f*y} ${n}`}g+=` 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:g,translateX:0,translateY:0,bounds:m,stats:$m(e),style:{...p,fillOpacity:p.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(Ye(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(Ye(t.x,o,t.width,i-o,u,e,t.name))}}return l},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,l=!1!==t.config.showLabels,c=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const t of c)for(const e of t.pieceData){const t=i?i(e):"_default";d.has(t)||(d.add(t),u.push(t))}const h=u.length>1&&"_default"!==u[0],f=[];let p=0;for(const t of c){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}f.push({col:t,groups:e,stepTotal:o}),h||o>p&&(p=o)}if(h)for(const t of f){let e=0,o=0;for(let n=0;u.length>n;n++){const i=t.groups.get(u[n]);i&&(n%2==0?e+=i.total:o+=i.total)}const n=Math.max(e,o);n>p&&(p=n)}if(0===p)return s;const y=new Map;for(const t of u){const e=f[0].groups.get(t);y.set(t,e?.total??0)}const g=f[0].stepTotal,m=h?.95*a:.9*e.width,b=zm().domain([0,p]).range([0,m]),x=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;f.length>e;e++){const o=f[e],n=o.col,i=0===e,c=n.width,d=.55*c,p=n.x+(c-d)/2,m=new Map;if(h){let t=0;for(const e of u){const n=o.groups.get(e);n&&(t+=b(n.total))}let e=a,c=a;for(let h=0;u.length>h;h++){const f=u[h],g=o.groups.get(f);if(!g)continue;const x=b(g.total),v=h%2==0,w=v?e:c-x;v?e+=x:c-=x;const k=r(g.pieces[0],f),S=y.get(f)??g.total,A={...g.pieces[0],__funnelValue:g.total,__funnelPercent:S>0?g.total/S*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};l&&(0===h&&(A.__funnelStepLabel=n.name,A.__funnelStepLabelX=a,A.__funnelStepLabelY=p,A.__funnelRowWidth=t),A.__funnelValueLabelX=w+x/2,A.__funnelValueLabelY=p,A.__funnelBarW=x),s.push(Ye(w,p,x,d,k,A,f)),m.set(f,{x:w,y:p,w:x,h:d})}}else{const t=o.stepTotal,e=b(t),c=a-e/2,h=u[0],f="_default"!==h,y=o.groups.get(h)?.pieces[0]??n.pieceData[0],x=f?h:n.name,v=r(y,x),w=g>0?t/g*100:0,k={...y,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:f?h:n.name};l&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=p,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=p,k.__funnelBarW=e),s.push(Ye(c,p,e,d,v,k,x)),m.set(h,{x:c,y:p,w:e,h:d})}if(e>0&&v.size>0){const e=h?u:[u[0]];for(const i of e){const e=v.get(i),a=m.get(i);if(!e||!a)continue;const l=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),c={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:l.fill||t.config.themeSemantic?.secondary||"#999",opacity:x},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],l=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),c.push(t))}const d=c.length>1&&"_default"!==c[0],h=[];for(const t of l){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:t,groups:e,stepTotal:o})}const f=new Map;for(const t of c){const e=h[0]?.groups.get(t);f.set(t,e?.total??0)}const p=s.r,y=d?c.length:1,g=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],o=e.col,n=0===t,i=t>0?h[t-1]:null,s=o.width/y,l=s*g,u=s-l;for(let t=0;c.length>t;t++){const h=c[t],y=e.groups.get(h);if(!y)continue;const g=y.total,m=f.get(h)??g,b=m>0?g/m*100:0,x=i?.groups.get(h),v=n?0:Math.max(0,(x?.total??g)-g),w=o.x+t*s+l/2,k=p(g),S=p(0)-k,A=r(y.pieces[0],d?h:o.name),M={...y.pieces[0],__barFunnelValue:g,__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:p(g+v)};if(a.push(Ye(w,k,u,S,A,M,d?h:o.name)),v>0){const t=p(g+v),e=k-t,n={...A},i={...y.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(Ye(w,t,u,e,n,i,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:n,getR:i,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:l}=o,c=[],u="horizontal"===l,d=t.config.gradientFill,h=u?"left":"bottom",f=t.config.trackFill;if(f){const t="string"==typeof f?f:f.color,e="string"==typeof f?1:f.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?Ye(r,o.x,s,o.width,n,null,"__track__"):Ye(o.x,r,o.width,s,n,null,"__track__");c.push(i)}}const p=t.config.roundedTop&&t.config.roundedTop>0?Math.max(0,t.config.roundedTop):0;for(const t of Object.values(n)){let e=0;const o=c.length;for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const l=r?r(o):t.name,f=s(o,l);let p;if(u){const i=a(e),r=a(e+n);p=Ye(i,t.x,r-i,t.width,f,o,l)}else{const i=a(e+n),r=a(e);p=Ye(t.x,i,t.width,r-i,f,o,l)}d&&(p.fillGradient=d,p.roundedEdge=h),c.push(p),e+=n}if(p>0&&c.length>o){const t=c.slice(o),e=t[0],n=t[t.length-1];1===t.length?e.cornerRadii={tl:p,tr:p,br:p,bl:p}:u?(e.cornerRadii={tl:p,bl:p},n.cornerRadii={tr:p,br:p}):(e.cornerRadii={bl:p,br:p},n.cornerRadii={tl:p,tr:p})}}return c}},Fm=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Em=["scene-style","data-paint","accessibility","evidence"],Om=(t,e)=>({retainedData:t,invalidations:e}),Bm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Nm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Wm=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],jm=["scene-geometry","data-paint","accessibility","evidence"],Ym=["scene-style","data-paint","accessibility","evidence"],Gm=[],Hm={chartType:Om("rebuild",Bm),runtimeMode:Om("rebuild",Bm),categoryAccessor:Om("rebuild",Bm),valueAccessor:Om("rebuild",Bm),oAccessor:Om("rebuild",Bm),rAccessor:Om("rebuild",Bm),stackBy:Om("rebuild",Bm),groupBy:Om("rebuild",Bm),timeAccessor:Om("rebuild",Bm),accessorRevision:Om("rebuild",Bm),colorAccessor:Om("rebuild",Ym),symbolAccessor:Om("rebuild",jm),connectorAccessor:Om("rebuild",jm),dataIdAccessor:Om("rebuild",jm),projection:Om("preserve",Nm),extentPadding:Om("preserve",Nm),axisExtent:Om("preserve",Nm),rExtent:Om("preserve",Nm),oExtent:Om("preserve",Nm),multiAxis:Om("preserve",Nm),normalize:Om("preserve",Nm),bins:Om("preserve",Nm),oSort:Om("preserve",Wm),barPadding:Om("preserve",Wm),roundedTop:Om("preserve",Wm),baselinePadding:Om("preserve",Wm),innerRadius:Om("preserve",Wm),cornerRadius:Om("preserve",Wm),startAngle:Om("preserve",Wm),sweepAngle:Om("preserve",Wm),trackFill:Om("preserve",Wm),showOutliers:Om("preserve",Wm),showIQR:Om("preserve",Wm),amplitude:Om("preserve",Wm),connectorOpacity:Om("preserve",Wm),showLabels:Om("preserve",Wm),dynamicColumnWidth:Om("rebuild",Wm),customLayout:Om("preserve",Wm),layoutConfig:Om("preserve",Wm),layoutMargin:Om("preserve",Wm),symbolMap:Om("preserve",jm),pieceStyle:Om("preserve",Ym),summaryStyle:Om("preserve",Ym),connectorStyle:Om("preserve",Ym),gradientFill:Om("preserve",Ym),colorScheme:Om("preserve",Ym),themeCategorical:Om("preserve",Ym),themeSemantic:Om("preserve",Ym),themeSequential:Om("preserve",Ym),themeDiverging:Om("preserve",Ym),barColors:Om("preserve",Ym),decay:Om("preserve",Ym),pulse:Om("preserve",Ym),staleness:Om("preserve",Ym),layoutSelection:Om("preserve",Ym),windowSize:Om("preserve",Gm),windowMode:Om("preserve",Gm),clock:Om("preserve",Gm),transition:Om("preserve",Gm),introAnimation:Om("preserve",Gm),onLayoutError:Om("preserve",Gm)},qm=Om("preserve",Wm),Vm=class{constructor(){this.tracker=new Yo}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}},Fm)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Em):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=Hm[n]??qm;"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 Xm}from"d3-quadtree";var Um=class{constructor(t){this.rExtent=new _e,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new Vm,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Cm,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 Me(t.windowSize),this.getO=y(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>h(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new _e)):(this.getR=h(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=y(t.stackBy),this.getGroup=y(t.groupBy),this.getColor=y(t.colorAccessor),this.getSymbol=y(t.symbolAccessor),this.getConnector=y(t.connectorAccessor),this.getDataId=y(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new Me(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:Ro(e,n):null)}currentTime(){return this.config.clock?.()??Ie()}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(),Co(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)Lo(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=Lo(this.buffer,o,this.timestampBuffer,e);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=t&&this.evictValueExtent(t)}}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}pushValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.push(e[0]),this.rExtent.push(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].push(this.rAccessors[e](t));this.rExtent.push(this.getR(t))}else this.rExtent.push(this.getR(t))}evictValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.evict(e[0]),this.rExtent.evict(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].evict(this.rAccessors[e](t));this.rExtent.evict(this.getR(t))}else this.rExtent.evict(this.getR(t))}getRawRange(t){const e=this.config.valueAccessor||this.config.rAccessor;if(!e)return null;const o="function"==typeof e?e(t):t[e];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",l=e.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let f,p;if(d){f=_m().domain(l).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;p=Pm().domain(c).range([n,o])}else u?(f=_m().domain(l).range([0,t.height]).padding(h),p=Pm().domain(c).range([0,t.width])):(f=_m().domain(l).range([0,t.width]).padding(h),p=Pm().domain(c).range([t.height,0]));this.scales={o:f,r:p,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((n,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(o,n);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const l=a-s,c=l>0?l*(e.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?Pm().domain([s,a]).range([0,t.width]):Pm().domain([s,a]).range([t.height,0])}):[];let y=s;this.rAccessors.length>1&&(y=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(y,l,f,a,t),this._customLayoutFailedThisBuild=!1;const g=this.buildSceneNodes(y,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=g,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(e)?e[t]:e;return"string"==typeof o?o:"value"+t}resolveCategories(t){const e=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,n="auto"===e?void 0:e;let i=null;if(o){i=new Set;for(const e of t)i.add(this.getO(e))}const r=i?Array.from(this.categories).filter(t=>i.has(t)):Array.from(this.categories);if(o&&void 0===n){const t=Math.max(50,3*i.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;i.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===n)return r;if("function"==typeof n)return r.sort(n);const s=new Map;for(const e of t){const t=this.getO(e);s.set(t,(s.get(t)||0)+Math.abs(this.getR(e)))}return r.sort("asc"===n?(t,e)=>(s.get(t)||0)-(s.get(e)||0):(t,e)=>(s.get(e)||0)-(s.get(t)||0))}computeValueDomain(t,e){return function(t){const{data:e,chartType:o,projection:n,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=t,f=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let p=0,y=0;if("bar"===o&&d&&i)p=0,y=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=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>y&&(y=e);for(const t of o.values())p>t&&(p=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=c(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e),p>e&&(p=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=c(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>y&&(y=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>y&&(y=e),p>e&&(p=e)}else{const t=h[0],e=h[1];t!==1/0&&(p=t),e!==-1/0&&(y=e)}r&&(null!=r[0]&&(p=r[0]),null!=r[1]&&(y=r[1]));const g="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(g&&null==r?.[0]&&null==r?.[1]&&(p>0&&(p=0),0>y&&(y=0)),"bar-funnel"!==o&&"exact"!==l){const t=y-p,e=t>0?t*f:1,n=g&&!a&&0===p,i=g&&!a&&0===y||"swimlane"===o;null!=r?.[0]||n||(p-=e),null!=r?.[1]||i||(y+=e)}return[p,y]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,n,i){return function(t){const{data:e,oExtent:o,oScale:n,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:l}=t,c={},u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===i)for(const t of e)d+=Math.abs(l(t));let h=null;if(s&&"radial"!==i){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let n;n="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,n),t+=n}const e=("horizontal"===i?r.height:r.width)-n.padding()*n.step()*o.length;if(t>0)for(const[o,n]of h)h.set(o,n/t*e)}let f=0,p=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(l(e)),0),i=d>0?o/d:0;let r,s;h?(r=p,s=h.get(t)||n.bandwidth(),p+=s+n.padding()*n.step()):(r=n(t)??0,s=n.bandwidth()),c[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:e,pct:i,pctStart:f},f+=i}return c}({data:t,oExtent:e,oScale:o,projection:n,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(t,e);let n;try{n=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=xo("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 go({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=Dm[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=cy(o.colorScheme,o.themeCategorical,gt),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:uy(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Te(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=$e(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&&(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&&(n[i++]=e);return{maxRadius:o,quadtree:Xm().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,ze(t,e,r)))}l=De(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=De(c,null==u?0:ze(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&&Fe(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}`}return"rect"===t.type?`r:${t.group||""}:${t.datum?.category??""}`:"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}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity}):"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??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??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??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??1,i.style={...i.style,opacity:0},e=!0);else if("wedge"===i.type)if(s)o.add(r),i._targetOpacity=i.style.opacity??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??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=Re(t,this.activeTransition),o=Ce(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=Le(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Le(n.x,t._targetX,o),t.y=Le(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Le(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Le(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=Le(n.x,t._targetX,o),t.y=Le(n.y,t._targetY,o),void 0!==n.w&&(t.w=Le(n.w,t._targetW,o),t.h=Le(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:Le(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=Le(n.startAngle,t._targetStartAngle,o),t.endAngle=Le(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}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=Pe(t),o=this.getDataId,n=t=>e.has(o(t));Io(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=Pe(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.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(e){const o={...this.config},n=Object.keys(e).filter(t=>e[t]!==o[t]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==o.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${o.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!==o.colorScheme||"themeCategorical"in e&&e.themeCategorical!==o.themeCategorical||"colorAccessor"in e&&!t(e.colorAccessor,o.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!t(e.categoryAccessor,o.categoryAccessor)||"oAccessor"in e&&!t(e.oAccessor,o.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let i=!1;("categoryAccessor"in e||"oAccessor"in e)&&(t(this.config.categoryAccessor||this.config.oAccessor,o.categoryAccessor||o.oAccessor)||(this.getO=y(this.config.categoryAccessor||this.config.oAccessor,"category"),i=!0));let r=!1;if("valueAccessor"in e||"rAccessor"in e){const e=this.config.valueAccessor||this.config.rAccessor,n=o.valueAccessor||o.rAccessor,i=Array.isArray(e)?e:[e],s=Array.isArray(n)?n:[n];if(r=i.length!==s.length||i.some((e,o)=>!t(e,s[o])),r){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>h(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new _e)):(this.getR=h(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!t(e.stackBy,o.stackBy)&&(this.getStack=null!=this.config.stackBy?y(this.config.stackBy):void 0),"groupBy"in e&&!t(e.groupBy,o.groupBy)&&(this.getGroup=null!=this.config.groupBy?y(this.config.groupBy):void 0),"colorAccessor"in e&&!t(e.colorAccessor,o.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?y(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!t(e.symbolAccessor,o.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?y(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!t(e.connectorAccessor,o.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?y(this.config.connectorAccessor):void 0),(i||r||"accessorRevision"in e&&e.accessorRevision!==o.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(n)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Bo(Um);import{jsx as Km,jsxs as Zm}from"react/jsx-runtime";import{Fragment as Qm,jsx as Jm,jsxs as tb}from"react/jsx-runtime";function eb(t,e){const o=C(t.theme),n=t.size||[500,400],i=$s({top:20,right:20,bottom:30,left:40,...t.margin},t.title),r=Is(t.title),s=B(t.data),a=t.showLegend?Jg(s,t.colorAccessor||t.stackBy||t.groupBy):[],l=t.projection||"vertical",c={hasAxis:!1!==t.showAxes&&"radial"!==l,hasAxisLabel:"horizontal"===l?!(!t.valueLabel&&!t.rLabel):!(!t.categoryLabel&&!t.oLabel)};mm(i,{props:{...t,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=t.projection||"vertical",f="radial"===h,p=t.colorScheme||o.colors.categorical,y={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:Ft(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:p,themeCategorical:o.colors.categorical,themeSemantic:b(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},g=new Um(y);if(t.data&&g.ingest({inserts:s,bounded:!0}),g.computeScene({width:u,height:d}),!g.scales||0===g.scene.length)return e&&(e.evidence=Bg({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,extraWarnings:g.scales?[]:["NO_SCALES"],margin:i})),Mm.renderToStaticMarkup(vm(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,idPrefix:t._idPrefix}));const m=t._idPrefix,x=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=R(o),a=n?n+"-":"",l="vertical"===r.projection,c=Ms(r.r,5,i);return cm("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return cm("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 cm("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(g,{width:u,height:d},o,m,t.axisExtent):null;let v=null;if(g.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=hm(t),n=new Set;for(const t of g.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");v=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 Zm("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Km("rect",{width:a,height:a,fill:o}),Km("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Km("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 g.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 w=jc({nodes:g.scene,renderMode:t.renderMode,fallback:(t,e)=>ma(t,e,m)}),k=w.map(t=>t.element);if(e){const o=g.scales.o?.domain?.();e.evidence=Bg({frameType:"ordinal",width:n[0],height:n[1],marks:w.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,yDomain:Og(g.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const S=!1!==t.showAxes?function(t,e,o,n,i){const r=t.scales;if(!r)return null;if("radial"===r.projection)return null;const s=R(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(t.columns).map(t=>({pixel:t.middle,label:(l||String)(t.name)})),f=Ms(r.r,5,o.axisExtent).map(t=>({pixel:r.r(t),label:(c||xm)(t)}));return tb("g",a?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Jm("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),h.map((t,o)=>tb("g",{transform:`translate(${t.pixel},${e.height})`,children:[Jm("line",{y2:5,stroke:s.border,strokeWidth:1}),Jm("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+o)),u&&Jm("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:u}),Jm("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,e)=>tb("g",{transform:`translate(0,${t.pixel})`,children:[Jm("line",{x2:-5,stroke:s.border,strokeWidth:1}),Jm("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),d&&Jm("text",{x:15-(o.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${e.height/2})`,children:d})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Jm("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:s.border,strokeWidth:1}),f.map((t,o)=>tb("g",{transform:`translate(${t.pixel},${e.height})`,children:[Jm("line",{y2:5,stroke:s.border,strokeWidth:1}),Jm("text",{y:18,textAnchor:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oxtick-"+o)),d&&Jm("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,children:d}),Jm("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:s.border,strokeWidth:1}),h.map((t,e)=>tb("g",{transform:`translate(0,${t.pixel})`,children:[Jm("line",{x2:-5,stroke:s.border,strokeWidth:1}),Jm("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:s.tickSize,fill:s.textSecondary,fontFamily:s.fontFamily,children:t.label})]},"oytick-"+e)),u&&Jm("text",{x:15-(o.margin?.left??40),y:e.height/2,textAnchor:"middle",fontSize:s.labelSize,fill:s.text,fontFamily:s.fontFamily,transform:`rotate(-90, ${15-(o.margin?.left??40)}, ${e.height/2})`,children:u})]})}(g,{width:u,height:d},t,o,m):null,A=t.annotations?am({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:g.scales.o,r:g.scales.r,y:"vertical"===g.scales.projection?g.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,idPrefix:m}):null,M=bm({props:{...t,axisChrome:c},categories:a,theme:o,size:n,margin:i,hasTitle:r}),_=f?i.left+u/2:i.left,P=f?i.top+d/2:i.top,L=f&&t.centerContent?Jm("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:Jm("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null;return Mm.renderToStaticMarkup(vm(tb(Qm,{children:[t.backgroundGraphics,x,k,S,A,t.foregroundGraphics,g.customLayoutOverlays]}),{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(${_},${P})`,innerWidth:u,innerHeight:d,legend:M,defs:v,outerElements:L,idPrefix:t._idPrefix}))}import*as ob from"react-dom/server";function nb(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function ib(t,e){var o,n=[],i=[],r=[],s={},a=[];function l(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&l(e)})}function c(t){var e,n,d=!1;for(i.push(t),r[t]=!0,e=0;a[t].length>e;e++)(n=a[t][e])===o?(u(o,i),d=!0):r[n]||(d=c(n));if(d)l(t);else for(e=0;a[t].length>e;e++){var h=s[n=a[t][e]];h||(s[n]=h={}),h[n]=!0}return i.pop(),d}function u(t,o){var i=[].concat(o).concat(t);e?e(i):n.push(i)}function d(e){!function(e){for(var o=0;t.length>o;o++)o>=e&&t[o]||(t[o]=[]),t[o]=t[o].filter(function(t){return t>=e})}(e);for(var o,n=function(t){for(var e=t.length,o=Array(e),n=Array(e),i=Array(e),r=Array(e),s=Array(e),a=Array(e),l=0;e>l;++l)o[l]=-1,n[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function f(e){var l=[e],c=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;c.length>0;){var f=t[e=c[c.length-1]];if(f.length>r[e]){for(var p=r[e];f.length>p;++p){var y=f[p];if(0>o[y]){o[y]=n[y]=u,i[y]=!0,u+=1,l.push(y),c.push(y);break}i[y]&&(n[e]=0|Math.min(n[e],n[y])),0>s[y]||a[e].push(s[y])}r[e]=p}else{if(n[e]===o[e]){var g=[],m=[],b=0;for(p=l.length-1;p>=0;--p){var x=l[p];if(i[x]=!1,g.push(x),m.push(a[x]),b+=a[x].length,s[x]=d.length,x===e){l.length=p;break}}d.push(g);var v=Array(b);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--b]=m[p][w];h.push(v)}c.pop()}}}for(l=0;e>l;++l)0>o[l]&&f(l);for(l=0;h.length>l;l++){var p=h[l];if(0!==p.length){p.sort(function(t,e){return t-e}),c=[p[0]];for(var y=1;p.length>y;y++)p[y]!==p[y-1]&&c.push(p[y]);h[l]=c}}return{components:d,adjacencyList:h}}(t),i=n.components.filter(function(t){return t.length>1}),r=1/0,s=0;i.length>s;s++)for(var a=0;i[s].length>a;a++)r>i[s][a]&&(r=i[s][a],o=s);var l=i[o];return!!l&&{leastVertex:r,adjList:t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var f=d(o);if(o=f.leastVertex,a=f.adjList){for(var p=0;a.length>p;p++)for(var y=0;a[p].length>y;y++){var g=a[p][y];r[+g]=!1,s[g]={}}c(o),o+=1}else o=h}return e?void 0:n}function rb(t){return t.y0-t.y1>0?"up":"down"}function sb(t,e){return e(t.source)==e(t.target)}function ab(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 lb(t){return t.target.x0-t.source.x1}function cb(t,e){var o=db(t),n=lb(e)/Math.tan(o);return"up"==rb(t)?t.y1-n:t.y1+n}function ub(t,e){var o=db(t),n=lb(e)/Math.tan(o);return"up"==rb(t)?t.y1+n:t.y1-n}function db(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function hb(t,e){return e(t)}function fb(t){return yb(t.source)}function pb(t){return yb(t.target)}function yb(t){return(t.y0+t.y1)/2}function gb(t){return t.virtual?0:t.value}function mb(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!sb(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!sb(t,e)?n+1:n}),o+n}function bb(t){return t.target.depth}function xb(t,e){return t.sourceLinks.length?t.depth:e-1}function vb(t,e){return t.y0-e.y0}function wb(t,e){return e.y0-t.y0}function kb(t,e){return t.y1-e.y1}function Sb(t,e){return e.y1-t.y1}function Ab(t,e){return _b(t.source,e.source)||t.index-e.index}function Mb(t,e){return _b(t.target,e.target)||t.index-e.index}function _b(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function Pb(t,e){return Cb(t)==Cb(e)?"bottom"==t.circularLinkType?wb(t,e):vb(t,e):Cb(e)-Cb(t)}function Cb(t){return t.target.column-t.source.column}function Rb(t,e){return Lb(t)==Lb(e)}function Lb(t){return t.y0-t.y1>0?"up":"down"}import{min as Ib}from"d3-array";function Tb(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=Ib(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}),$b(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),$b(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,sb(t,e)&&ab(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?wb:vb);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?Sb:kb),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 $b(t,e,o){t.sort(Pb);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(sb(t,e)&&ab(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&&zb(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 zb(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as Db,max as Fb,sum as Eb,mean as Ob,group as Bb,groups as Nb}from"d3-array";function Wb(t){return function(){return t}}function jb(t){return t.index}function Yb(t){return t.nodes}function Gb(t){return t.links}function Hb(t,e,o){var n=Nb(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+=yb(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=yb(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?mb(e,o)-mb(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==mb(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 qb(t,e,o,n,i,r){var s=Nb(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&&mb(i,o)>0){var l=Ob(i.sourceLinks,pb),c=Ob(i.targetLinks,fb),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-yb(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=Ob(i.sourceLinks,pb),f=Ob(i.targetLinks,fb),p=((h&&f?(h+f)/2:h||f)-yb(i))*e;i.y0+=p,i.y1+=p}})})}function u(){s.forEach(function(o){var r,s,a,l=t.y0,c=o.length;for(o.sort(e||_b),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 Vb(t){t.nodes.forEach(function(t){t.sourceLinks.sort(Mb),t.targetLinks.sort(Ab)}),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 Xb(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=jb,l=xb,c=void 0,u=32,d=2,h=Yb,f=Gb;function p(){var p={nodes:h.apply(null,arguments),links:f.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=o,h.y1=n,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var o=function(t,e){var o=new Map;return Bb(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=nb(o,n)),"object"!=typeof i&&(i=t.target=nb(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=ib(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){hb(t,e)!=hb(i.source,e)&&hb(t,e)!=hb(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),sb(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(Eb(t.sourceLinks,gb),Eb(t.targetLinks,gb)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,o){var n,i,r;if(null!=e){t.nodes.sort(function(t,o){return e(t)<e(o)?-1:1});var s=0,a=e(t.nodes[0]);t.nodes.forEach(function(t){s=e(t)==a?s:s+1,a=e(t)==a?a:e(t),t.column=s})}for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>i.indexOf(t.target)&&!t.circular&&i.push(t.target)})});for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>i.indexOf(t.source)&&!t.circular&&i.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?o(t,r):t.column})}(h,c,l);var f=r;if(null!==s){var p=Nb(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),y=Fb(p,function(t){return t.length});y>1&&(f=Math.max(1,(n-e)*s/(y-1)))}(function(t,e,o){var n=Nb(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=Db(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/Eb(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=Fb(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-o)/r),e.x1=e.x0+o}:function(e){e.x0=t.x0,e.x1=e.x0+o})})(h,f,i),Hb(h,c,a),qb(h,c,a,f,f,u),Vb(h),Tb(h,a,d,10,8),Hb(h,c,a),qb(h,c,a,f,f,u),Vb(h),Tb(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 hb(o.source,e)==hb(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(!Rb(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=cb(e,t);return t.y1-o}if(e.target.column>t.target.column)return cb(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 hb(o.target,e)==hb(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(!Rb(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=ub(e,t);return t.y0-o}if(e.source.column>t.source.column)return ub(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=Db(e,function(t){return t.y0}),s=Fb(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),Tb(h,a,d,10,8)}(p),p}return p.update=function(t){return Vb(t),Tb(t,a,d,10,8),t},p.nodeWidth=function(t){return arguments.length?(i=+t,p):i},p.nodePadding=function(t){return arguments.length?(r=+t,p):r},p.nodePaddingRatio=function(t){return arguments.length?(s=+t,p):s},p.nodes=function(t){return arguments.length?(h="function"==typeof t?t:Wb(t),p):h},p.links=function(t){return arguments.length?(f="function"==typeof t?t:Wb(t),p):f},p.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:Wb(t),p):a},p.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:Wb(t),p):l},p.nodeSort=function(t){return arguments.length?(c=t,p):c},p.iterations=function(t){return arguments.length?(u=+t,p):u},p.circularLinkGap=function(t){return arguments.length?(d=+t,p):d},p.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],o=+i[1][0],n=+i[1][1],p):[[t,e],[o,n]]},p.size=function(i){return arguments.length?(t=e=0,o=+i[0],n=+i[1],p):[o-t,n-e]},p}import{interpolateNumber as Ub}from"d3-interpolate";import{line as Kb,curveLinearClosed as Zb}from"d3-shape";var Qb=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=Ub(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=Ub(t.source.x1,t.target.x0),{pathD:h}=of({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 Jb(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 tx=new Set,ex=new WeakMap;function ox(t,e){if("production"===process.env.NODE_ENV)return t;if(!t||!t.data||"object"!=typeof t.data)return t;let o=ex.get(t);if(o){const t=o.get(e);if(t)return t}else o=new Map,ex.set(t,o);const n=new Proxy(t,{get(t,o,n){if("string"==typeof o&&!(o in t)&&t.data&&o in t.data){const t=`${e}:${o}`;tx.has(t)||(tx.add(t),console.warn(`[Semiotic] "${e}" callback accessed "${o}" on the wrapper object, but it only exists on ".data". Use d.data.${o} (or d.data?.${o}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(t,o,n)}});return o.set(e,n),n}var nx={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(bb))-1:0},justify:xb};function ix(t){return"string"==typeof t?t:t.id}var rx={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:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id,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=Xb().extent(d).links(u).nodes(c).nodeAlign(nx[r]||xb).nodeId(t=>t.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of c)t>n.x0&&(t=n.x0),n.x1>e&&(e=n.x1),o>n.y0&&(o=n.y0),n.y1>i&&(i=n.y1);for(const n of u){if(!n.circular||!n.circularPathData)continue;const r=n.circularPathData,s=(n._circularWidth??n.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),o>r.verticalFullExtent-s&&(o=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=e-t,s=i-o,a=n[0],l=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>l)){const e=Math.min(a/r,l/s),n=-t*e+(a-r*e)/2,i=-o*e+(l-s*e)/2;for(const t of c)t.x0=t.x0*e+n,t.x1=t.x1*e+n,t.y0=t.y0*e+i,t.y1=t.y1*e+i;for(const t of u)if(t.y0=t.y0*e+i,t.y1=t.y1*e+i,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const o=t.circularPathData;o.sourceX=o.sourceX*e+n,o.targetX=o.targetX*e+n,o.sourceY=o.sourceY*e+i,o.targetY=o.targetY*e+i,o.rightFullExtent=o.rightFullExtent*e+n,o.leftFullExtent=o.leftFullExtent*e+n,o.verticalFullExtent=o.verticalFullExtent*e+i,o.rightInnerExtent=o.rightInnerExtent*e+n,o.leftInnerExtent=o.leftInnerExtent*e+n,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+i,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+i,o.rightSmallArcRadius*=e,o.rightLargeArcRadius*=e,o.leftSmallArcRadius*=e,o.leftLargeArcRadius*=e,o.sourceWidth*=e,o.rightNodeBuffer*=e,o.leftNodeBuffer*=e,o.arcRadius*=e}}}const f=new Map;for(const e of t)f.set(e.id,e);for(const t of c){const e=f.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const p=new Map;for(const t of e)p.set(t._edgeKey?t._edgeKey:`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const t of u){const e=ix(t.source),o=ix(t.target),n=p.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(n){n.y0=t.y0,n.y1=t.y1,n.sankeyWidth=t.width??0,n.circular=!!t.circular,n.circularPathData=t.circularPathData,n._circularWidth=t._circularWidth,n._circularStub=t._circularStub,n.path=t.path,n.circularLinkType=t.circularLinkType,n.direction=i;const r=f.get(e),s=f.get(o);r&&(n.source=r),s&&(n.target=s)}}},buildScene(t,e,o,n){const i="vertical"===o.orientation?"down":"right",r=o.nodeStyle,s=o.edgeStyle,a=o.edgeOpacity??.5,l=o.edgeColorBy||"source",c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:G,u=new Map;t.forEach((t,e)=>{u.set(t.id,c[e%c.length])});const d=[],h=[],f=[],p=new Map;for(const e of t){const t=e.x1-e.x0,o=e.y1-e.y0;if(0>=t||0>=o)continue;const n=r?r(ox(e,"nodeStyle")):{},s={fill:n.fill||u.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity};p.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===i?{type:"rect",x:e.y0,y:e.x0,w:o,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:o,style:s,datum:e,id:e.id,label:e.id})}const y=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of y){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";i="function"==typeof l?l(t)||i:"target"===l?p.get(n.id)||u.get(n.id)||i:p.get(e.id)||u.get(e.id)||i;const r=s?s(ox(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},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},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let c;(c=t.circular&&t.circularPathData?Jb(t):Qb(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},datum:t})}if(!1!==o.showLabels){const e=(g=o.nodeLabel)?"function"==typeof g?g:t=>t[g]||t.id:null;for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=e?e(o):o.id;if(!s)continue;let a,l,c;"down"===i?(a=o.y0+(o.y1-o.y0)/2,l=o.x1+14,c="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,c="end"):(a=o.x1+6,c="start"),l=o.y0+r/2),f.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}var g;return{sceneNodes:d,sceneEdges:h,labels:f}}};import{forceSimulation as sx,forceCenter as ax,forceX as lx,forceY as cx,forceLink as ux,forceManyBody as dx,forceCollide as hx}from"d3-force";import{scaleLinear as fx}from"d3-scale";var px={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i=o.forceStrength??.1,r=n[0]/2,s=n[1]/2,a=Math.max(.1,Math.min(1,Math.min(n[0],n[1])/200)),l=Math.min(.5,.06+1.8*(1-a)),c=o.__previousPositions;let u=0;const d=[];for(const e of t){const t=null!=e.x&&null!=e.y&&(0!==e.x||0!==e.y),o=c?.get(e.id);t?u++:o?(e.x=o.x,e.y=o.y,u++):d.push(e)}const h=u>0&&.3>=(t.length>0?d.length/t.length:1);if(h){const o=new Map;for(const e of t)o.set(e.id,e);for(const t of d){const n=yx(t.id,e,o);if(n.length>0){let e=0,o=0;for(const t of n)e+=t.x,o+=t.y;const i=gx(t.id),r=i%360*(Math.PI/180),s=(10+i%20)*a;t.x=e/n.length+s*Math.cos(r),t.y=o/n.length+s*Math.sin(r)}else{const e=gx(t.id),o=e%360*(Math.PI/180),n=(15+e%30)*a;t.x=r+n*Math.cos(o),t.y=s+n*Math.sin(o)}}}else{const e=2.399963229728653;for(let o=0;t.length>o;o++){const n=t[o];if(null==n.x||null==n.y||0===n.x&&0===n.y){const t=10*Math.sqrt(o+.5)*a,i=o*e;n.x=r+t*Math.cos(i),n.y=s+t*Math.sin(i)}}}const f=o.__skipForceSimulation||0===o.iterations?0:h?40:o.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(t.length-30)))),p=mx(o.nodeSize,o.nodeSizeRange,t),y=t=>p(t);if(f>0){const c=new Map,u=new Map;for(const e of t)c.set(e.id,0),u.set(e.id,e);for(const t of e){const e="string"==typeof t.source?t.source:t.source.id,o="string"==typeof t.target?t.target:t.target.id;c.set(e,(c.get(e)??0)+1),c.set(o,(c.get(o)??0)+1)}const d=ux().strength(t=>{const e=t.weight,o="string"==typeof t.target?t.target:t.target.id,n=Math.max(1,Math.min(c.get("string"==typeof t.source?t.source:t.source.id)??1,c.get(o)??1));return Math.min(2.5,(e&&e>0?Math.sqrt(e):1)*i/(.1*n))}).distance(t=>{const e="string"==typeof t.source?u.get(t.source):t.source,o="string"==typeof t.target?u.get(t.target):t.target,n=(e?y(e):0)+(o?y(o):0)+Math.max(6,12*a);return Math.max(16,40*a,n)}).id(t=>t.id),p=sx();if(void 0===o.random&&void 0===o.seed||p.randomSource(o.random??ql(o.seed)),p.force("charge",dx().strength(t=>{const e=c.get(t.id)??0;return-15*a*y(t)*Math.sqrt(e+1)})).force("collide",hx(t=>y(t)+3*a).strength(.9).iterations(2)).force("center",ax(r,s).strength(.8)).force("x",lx(r).strength(l)).force("y",cx(s).strength(l)).force("bounds",function(t,e,o=2,n=.6){let i=[];const r=r=>{const s=n*Math.max(r,.2);for(const n of i){const i=n.x??t[0]/2,r=n.y??t[1]/2,a=n.vx??0,l=n.vy??0,c=e(n)+o,u=Math.min(t[0]/2,c),d=Math.max(t[0]/2,t[0]-c),h=Math.min(t[1]/2,c),f=Math.max(t[1]/2,t[1]-c),p=i+a,y=r+l;u>p?n.vx=a+(u-p)*s:p>d&&(n.vx=a+(d-p)*s),h>y?n.vy=l+(h-y)*s:y>f&&(n.vy=l+(f-y)*s)}};return r.initialize=t=>{i=t},r}(n,y)),p.nodes(t),e.length>0){const t=e.map(t=>({...t,source:"string"==typeof t.source?t.source:t.source.id,target:"string"==typeof t.target?t.target:t.target.id}));d.links(t),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let t=0;f>t;++t)p.tick()}for(const e of t){if(null==e.x||null==e.y)continue;const t=y(e),o=f>0?2:0,i=Math.min(n[0]/2,t+o),r=Math.min(n[1]/2,t+o);e.x=Math.max(i,Math.min(n[0]-i,e.x)),e.y=Math.max(r,Math.min(n[1]-r,e.y)),e.x0=0,e.x1=0,e.y0=0,e.y1=0}const g=new Map;for(const e of t)g.set(e.id,e);for(const t of e){if("string"==typeof t.source){const e=g.get(t.source);e&&(t.source=e)}if("string"==typeof t.target){const e=g.get(t.target);e&&(t.target=e)}}},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=mx(o.nodeSize,o.nodeSizeRange,t),a=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:G,l=new Map;t.forEach((t,e)=>{l.set(t.id,a[e%a.length])});const c=[],u=[],d=[];for(const e of t){if(null==e.x||null==e.y)continue;const t=s(ox(e,"nodeSize")),n=i?i(ox(e,"nodeStyle")):{},r={fill:n.fill||l.get(e.id)||o.themeSemantic?.primary||"#007bff",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??2,opacity:n.opacity};c.push({type:"circle",cx:e.x,cy:e.y,r:t,style:r,datum:e,id:e.id,label:e.id})}const h=new Map;for(const e of t)h.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:h.get(t.source),n="object"==typeof t.target?t.target:h.get(t.target);if(!e||!n)continue;if(null==e.x||null==e.y)continue;if(null==n.x||null==n.y)continue;const i=r?r(ox(t,"edgeStyle")):{};u.push({type:"line",x1:e.x,y1:e.y,x2:n.x,y2:n.y,style:{stroke:i.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:i.strokeWidth??1,opacity:i.opacity??.6},datum:t})}if(!1!==o.showLabels){const e=(f=o.nodeLabel)?"function"==typeof f?f:t=>t[f]||t.id:null;for(const o of t){if(null==o.x||null==o.y)continue;const t=e?e(o):o.id;if(!t)continue;const n=s(ox(o,"nodeSize"));d.push({x:o.x,y:o.y-n-4,text:t+"",anchor:"middle",baseline:"auto",fontSize:11})}}var f;return{sceneNodes:c,sceneEdges:u,labels:d}}};function yx(t,e,o){const n=[];for(const i of e){const e="string"==typeof i.source?i.source:i.source.id,r="string"==typeof i.target?i.target:i.target.id;let s=null;if(e===t?s=r:r===t&&(s=e),s){const t=o.get(s);!t||0===t.x&&0===t.y||n.push({x:t.x,y:t.y})}}return n}function gx(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o)|0;return Math.abs(e)}function mx(t,e,o){if(o.some(t=>null!=t.__forceRadius))return t=>t.__forceRadius??8;if(null==t)return()=>8;if("number"==typeof t)return()=>t;if("function"==typeof t)return e=>t(e)||8;const n=e||[5,20],i=[];for(const e of o){const o=e.data?.[t];"number"==typeof o&&i.push(o)}if(0===i.length)return()=>n[0];const[r,s]=St(i);if(r===s)return()=>(n[0]+n[1])/2;const a=fx().domain([r,s]).range(n).clamp(!0);return e=>{const o=e.data?.[t];return null==o||"number"!=typeof o?n[0]:a(o)}}import{chord as bx,ribbon as xx}from"d3-chord";import{arc as vx}from"d3-shape";var wx=G,kx={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(n[0],n[1])/2,l=a-r,c=n[0]/2,u=n[1]/2,d=(h=o.valueAccessor)?"function"==typeof h?h:t=>t[h]??1:t=>t.value??1;var h;const f=new Map;for(let e=0;t.length>e;e++)f.set(t[e].id,e);const p=t.length,y=Array.from({length:p},()=>Array.from({length:p},()=>0));for(const t of e){const e="string"==typeof t.target?t.target:t.target.id,o=f.get("string"==typeof t.source?t.source:t.source.id),n=f.get(e);if(void 0===o||void 0===n)continue;const i=d(t);y[o][n]=i}const g=bx().padAngle(i);s&&g.sortGroups(s);const m=g(y),b=m.groups,x=vx().innerRadius(l).outerRadius(a);for(const e of b){const o=t[e.index],n=x.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="string"==typeof t.target?t.target:t.target.id,o=v.get("string"==typeof t.source?t.source:t.source.id),n=v.get(e);o&&(t.source=o),n&&(t.target=n)}const w=new Map;for(const t of e)w.set(`${"string"==typeof t.source?t.source:t.source.id}\0${"string"==typeof t.target?t.target:t.target.id}`,t);for(const e of m){const o=t[e.source.index].id,n=t[e.target.index].id,i=w.get(`${o}\0${n}`)||w.get(`${n}\0${o}`);i&&(i.__chordData=e)}},buildScene(t,e,o,n){const{groupWidth:i=20,edgeOpacity:r=.5}=o,s=Math.min(n[0],n[1])/2,a=s-i,l=n[0]/2,c=n[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",f=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:wx,p=new Map;t.forEach((t,e)=>{p.set(t.id,f[e%f.length])});const y=xx().radius(a),g=[],m=[],b=[];for(let e=0;t.length>e;e++){const o=t[e],n=o.__arcData;if(!n)continue;let i;i=u?u(ox(o,"nodeStyle")).fill||p.get(o.id)||f[e%f.length]:p.get(o.id)||f[e%f.length];const r=u?u(ox(o,"nodeStyle")):{};g.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},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const n=y(e);if(!n)continue;const i=Sx(n,l,c);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d)s=d(ox(t,"edgeStyle")).fill||s;else{const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;"target"===h&&o?s=p.get(o.id)||s:e&&(s=p.get(e.id)||s)}const a=d?d(ox(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},datum:t})}if(!1!==o.showLabels){const e=(x=o.nodeLabel)?"function"==typeof x?x:t=>t[x]||t.id:null,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;b.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})}}var x;return{sceneNodes:g,sceneEdges:m,labels:b}}};function Sx(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 Ax,tree as Mx,cluster as _x,treemap as Px,pack as Cx,partition as Rx,treemapBinary as Lx}from"d3-hierarchy";var Ix=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Tx(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 $x(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 zx(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 Dx(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Ix}function Fx(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 Ex(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 Ox={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=Ax(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=Mx();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=_x();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=Px().size([o,n]).tile(Lx).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;Cx().size([o,n]).padding(i)(t)}(c,o,u,d);break;case"partition":!function(t,e,o,n){Rx().size([o,n]).padding(e.padding??1)(t)}(c,o,u,d)}const h=c.descendants();t.length=0,e.length=0;const f=new Map;for(let e=0;h.length>e;e++){const n=h[e],i={id:$x(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?Bx(i,n,o):"treemap"===r||"partition"===r?Nx(i,n):"circlepack"===r&&Wx(i,n),i.__hierarchyNode=n,t.push(i),f.set(n,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=f.get(t.parent),n=f.get(t);o&&n&&e.push({source:o,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,n){const i=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,n,i,r){const s=[],a=[],l=[],c=o.treeOrientation||"vertical",u="radial"===c,d=n[0]/2,h=n[1]/2,f="number"==typeof(p=o.nodeSize)?p:5;var p;for(const e of t){let t=e.x,n=e.y;u&&(t+=d,n+=h);const r=i(ox(e,"nodeStyle"));let a=r.fill||Fx(o);if(o.colorByDepth&&void 0!==e.depth){const t=Dx(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:n,r:f,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity},datum:e,id:e.id,label:e.id,depth:e.depth})}const y=o.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=e.x,s=e.y,l=n.x,f=n.y;u&&(i+=d,s+=h,l+=d,f+=h);const p=Ex(i,s,l,f,c),g=r(ox(t,"edgeStyle"));a.push({type:"curved",pathD:p,style:{fill:"none",stroke:g.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:g.strokeWidth??1.5,opacity:g.opacity??y},datum:t})}if(!1!==o.showLabels){const e=zx(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let n,i,r,s=o.x,a=o.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,o=Math.sqrt(t*t+e*e);o>0?(n=s+t/o*10,i=a+e/o*10,r=0>t?"end":"start"):(n=s,i=a-12,r="middle")}else"horizontal"===c?(o.data?.children&&0!==o.data.children.length?(n=s-f-6,r="end"):(n=s+f+6,r="start"),i=a):(n=s,i=a+f+14,r="middle");l.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(t,e,o,n,i,r);case"treemap":case"partition":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=n(ox(o,"nodeStyle"));let a=s.fill||Fx(e);if(e.colorByDepth&&void 0!==o.depth){const t=Dx(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},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=zx(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(ox(a,"nodeStyle")).fill||Fx(e);if(e.colorByDepth&&void 0!==a.depth){const t=Dx(e);d=t[a.depth%t.length]}const h="string"==typeof d?Tx(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(ox(o,"nodeStyle"));let s=r.fill||Fx(e);if(e.colorByDepth&&void 0!==o.depth){const t=Dx(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},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=zx(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(ox(i,"nodeStyle")).fill||Fx(e);if(e.colorByDepth&&void 0!==i.depth){const t=Dx(e);l=t[i.depth%t.length]}if(a){const o="string"==typeof l?Tx(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 Bx(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 Nx(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 Wx(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 jx}from"d3-shape";function Yx(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var Gx={sankey:rx,force:px,chord:kx,tree:Ox,cluster:Ox,treemap:Ox,circlepack:Ox,partition:Ox,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=Yx(o);h.metaMap.clear(),n.length=0,i.length=0;const f=new Map;function p(t){const e=f.get(t)??0;return f.set(t,e+1),0===e?t:`${t}__${e}`}const y=e[0]/2,g=e[1]/2,m=Math.min(e[0],e[1])/2*.85,b=p(s(t));n.push({id:b,x:y,y:g,x0:y,x1:y,y0:g,y1:g,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(b,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,o,l,c,f,y,g){const m=r(e);if(!m?.length)return;const b=m.length;let x=0,v=0,w=0;for(;b>v;)v+=a[Math.min(w,a.length-1)],w++,x++;let k=0;for(let b=0;x>b;b++){const v=a[Math.min(b,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const S=(b+1)/x,A={id:o,depth:y,data:e,parentId:o},M=g?f/u(A)*S:f*S,_=jx().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(A);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=p(s(a)),d=l+M*Math.sin(r),f=c+M*Math.cos(r)*P;n.push({id:u,x:d,y:f,x0:d,x1:d,y0:f,y1:f,width:0,height:0,value:0,depth:y,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:y,parentId:o,eccentricity:P}),i.push({source:o,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:o,target:u}}),t(a,u,d,f,M,y+1,!0)}k+=v}}(t,b,y,g,m,1,!1)}(i,n,o,t,e)},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.nodeSize,s="number"==typeof r?()=>r:"function"==typeof r?r:()=>6,a=[],l=[],c=[];if(!1!==o.orbitShowRings){const e=Yx(o),n=new Map;for(const e of t)n.set(e.id,e);const i=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=n.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;i.has(o)||i.set(o,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:t,parentY:e,ring:o,ecc:n}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,c=(i+1)/r*Math.PI*2;l.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(c),y2:e+o*Math.cos(c)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=s(ox(e,"nodeSize")),n=i?i(ox(e,"nodeStyle")):{};a.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)},datum:e,id:e.id,label:e.id,depth:e.depth})}const u=new Map;for(const e of t)u.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:u.get(t.source),o="object"==typeof t.target?t.target:u.get(t.target);e&&o&&(null!=e.x&&null!=o.x&&l.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1},datum:t}))}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=s(ox(o,"nodeSize"));if(4>=t)continue;const n="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;c.push({x:o.x,y:o.y+t+12,text:n+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:a,sceneEdges:l,labels:c}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=Yx(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)}};import{Fragment as Hx,jsxs as qx}from"react/jsx-runtime";function Vx(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var Xx=new Set(["tree","cluster","treemap","circlepack","partition"]);function Ux(t,e){const o=C(t.theme),n=t.chartType||"force",i=()=>Bg({frameType:"network",width:r[0],height:r[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,nodeCount:0,edgeCount:0,margin:s}),r=t.size||[500,500],s=$s({top:20,right:20,bottom:20,left:20,...t.margin},t.title),a=Is(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=B(t.nodes||[]);if(n.length>0)return Jg(n,e);const i=Array.isArray(t.edges)?B(t.edges):[];if(0===i.length)return[];const r=Vx(t.sourceAccessor,"source"),s=Vx(t.targetAccessor,"target");return Jg(Array.from(new Set(i.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];mm(s,{props:t,categories:l,theme:o,size:r,hasTitle:a});const c=r[0]-s.left-s.right,u=r[1]-s.top-s.bottom,d=function(t){return Gx[t]}(n);if(!d&&!t.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: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,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let f,p;if(Xx.has(n)){const n=t.data||t.edges;if(!n||Array.isArray(n))return e&&(e.evidence=i()),ob.renderToStaticMarkup(vm(null,{width:r[0],height:r[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:c,innerHeight:u,idPrefix:t._idPrefix}));h.__hierarchyRoot=n,f=[],p=[]}else{const n=B(t.nodes||[]),a=Array.isArray(t.edges)?B(t.edges):[];if(0===n.length&&0===a.length)return e&&(e.evidence=i()),ob.renderToStaticMarkup(vm(null,{width:r[0],height:r[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:c,innerHeight:u,idPrefix:t._idPrefix}));if(p=function(t,e){const o=Vx(e.sourceAccessor,"source"),n=Vx(e.targetAccessor,"target"),i=Vx(e.valueAccessor,"value");return t.map(t=>({source:o(t)+"",target:n(t)+"",value:Number(i(t))||1,y0:0,y1:0,sankeyWidth:0,data:t}))}(a,h),0===n.length&&p.length>0){const t=new Set;for(const e of p){const o=dm(e.source),n=dm(e.target);o&&t.add(o),n&&t.add(n)}f=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 f=function(t,e){const o=Vx(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}))}(n,h)}let y=[],g=[],m=[],b=null;if(h.customNetworkLayout){const t=h.colorScheme,e=cy(t,o.colors.categorical,G),n=uy(e,t),i={nodes:f,edges:p,dimensions:{width:c,height:u,plot:{x:0,y:0,width:c,height:u}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:h.layoutConfig??{}},r=h.customNetworkLayout(i);y=r.sceneNodes??[],g=r.sceneEdges??[],m=r.labels??[],b=r.overlays??null}else if(d){d.computeLayout(f,p,h,[c,u]);const t=d.buildScene(f,p,h,[c,u]);y=t.sceneNodes,g=t.sceneEdges,m=t.labels}const x=R(o);for(const t of m)t.fill||(t.fill=x.text);const v=jc({nodes:g,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"line":return ia("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;return ia("path",{d:o.pathD,fill:Zs(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;return ia("path",{d:o.pathD,fill:Zs(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 ia("path",{d:o.pathD,fill:Zs(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)}),w=jc({nodes:y,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"circle":{const o=t,n=Hn(o.style.fill)?Xn(o.style.fill,`net-circle-${e}-hatch`):void 0;return ra(oa.Fragment,{children:[n&&ia("defs",{children:n}),ia("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:Zs(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,n=Hn(o.style.fill)?Xn(o.style.fill,`net-rect-${e}-hatch`):void 0;return ra(oa.Fragment,{children:[n&&ia("defs",{children:n}),ia("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:Zs(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,n=na().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(Ks)||"",i=Hn(o.style.fill)?Xn(o.style.fill,`net-arc-${e}-hatch`):void 0;return ra(oa.Fragment,{children:[i&&ia("defs",{children:i}),ia("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:Zs(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,n=uo(o.symbolType,o.size,o.path);return ia("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?Zs(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return Js(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e)});e&&(e.evidence=Bg({frameType:"network",width:r[0],height:r[1],marks:[...w.map(({node:t})=>({type:"node:"+(t.type??"node")})),...v.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,nodeCount:w.length,edgeCount:v.length,margin:s}));const k=v.map(t=>t.element),S=w.map(t=>t.element),A=m.map((t,e)=>function(t,e){return ia("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),M=t.annotations?am({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{},layout:{width:c,height:u},theme:o,idPrefix:t._idPrefix}):null,_=bm({props:t,categories:l,theme:o,size:r,margin:s,hasTitle:a});return ob.renderToStaticMarkup(vm(qx(Hx,{children:[t.backgroundGraphics,k,S,A,M,t.foregroundGraphics,b]}),{width:r[0],height:r[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:c,innerHeight:u,legend:_,idPrefix:t._idPrefix}))}import*as Kx from"react-dom/server";import{geoPath as Zx}from"d3-geo";import{quadtree as Qx}from"d3-quadtree";import{geoMercator as Jx,geoEqualEarth as tv,geoAlbersUsa as ev,geoOrthographic as ov,geoNaturalEarth1 as nv,geoEquirectangular as iv}from"d3-geo";var rv={mercator:Jx,equalEarth:tv,albersUsa:ev,orthographic:ov,naturalEarth:nv,equirectangular:iv};function sv(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function av(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function lv(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function cv(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 uv(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 dv(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 hv(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 fv}from"d3-scale";var pv=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],yv=["scene-style","data-paint","accessibility","evidence"],gv=(t,e)=>({retainedData:t,invalidations:e}),mv=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],bv=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],xv=["scene-geometry","data-paint","accessibility","evidence"],vv=["scene-style","data-paint","accessibility","evidence"],wv=["overlay","accessibility","evidence"],kv=[],Sv={xAccessor:gv("rebuild",mv),yAccessor:gv("rebuild",mv),lineDataAccessor:gv("rebuild",mv),pointIdAccessor:gv("rebuild",xv),lineIdAccessor:gv("rebuild",xv),windowSize:gv("rebuild",mv),projection:gv("preserve",bv),projectionExtent:gv("preserve",bv),fitPadding:gv("preserve",bv),lineType:gv("preserve",bv),flowStyle:gv("preserve",bv),graticule:gv("preserve",bv),projectionTransform:gv("preserve",bv),customLayout:gv("preserve",bv),layoutConfig:gv("preserve",bv),layoutMargin:gv("preserve",bv),areaStyle:gv("preserve",vv),pointStyle:gv("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:gv("preserve",vv),colorScheme:gv("preserve",vv),themeCategorical:gv("preserve",vv),themeDiverging:gv("preserve",vv),themeSemantic:gv("preserve",vv),themeSequential:gv("preserve",vv),decay:gv("preserve",vv),pulse:gv("preserve",vv),layoutSelection:gv("preserve",vv),annotations:gv("preserve",wv),autoPlaceAnnotations:gv("preserve",wv),clock:gv("preserve",kv),transition:gv("preserve",kv),introAnimation:gv("preserve",kv),onLayoutError:gv("preserve",kv)},Av=gv("preserve",bv),Mv=class{constructor(){this.tracker=new Yo}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}},pv)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},yv):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=Sv[n]??Av;"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 _v,geoGraticule as Pv,geoInterpolate as Cv}from"d3-geo";function Rv(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 Lv=class t{constructor(t){this.updateResults=new Mv,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:Rv(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??Ie()}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 Me(t),this.timestampBuffer=new Me(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:Rv(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 Me(e),this.timestampBuffer=new Me(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();Lo(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)Lo(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)+"");Io(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 tv();if("string"==typeof t){const e=rv[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),tv())}if("object"==typeof t&&"type"in t){const e=rv[t.type],o=e?e():tv();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=Zx(this.projection),this.fitProjection(t),this.geoPath=Zx(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=sv(o.xAccessor,"lon"),r=sv(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=av(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=Zx(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=Zx(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=Zx(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=Qx().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=cy(e.colorScheme,e.themeCategorical,gt),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:uy(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=xo("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 go({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=sv(t.xAccessor,"lon"),l=sv(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=Pv();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:lv(t.areaStyle,e,u),datum:e,interactive:!0})}const f=av(t.lineDataAccessor);for(const o of r){const n=f(o);if(!n||2>n.length)continue;let i=[];if("geo"===t.lineType){const t=Array(n.length);for(let e=0;n.length>e;e++)t[e]=[a(n[e]),l(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=_v(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Cv(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=lv(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?dv(i,u):hv(i[0],i[i.length-1],0,0,u)):i=uv(i[0],i[i.length-1]);const h=cv(i,s.width);if(h.length>1)for(const t of h)2>t.length||c.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const p=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,y=e.clipAngle?e.clipAngle()??0:0,g=y>0?y*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],b="function"==typeof e.center?e.center():[0,0],x=[(b[0]??0)-m[0],(b[1]??0)-m[1]];for(const o of i){const n=a(o),i=l(o);if(null!=g&&_v([n,i],x)>g)continue;const r=e([n,i]);if(!r)continue;const s=t.pointStyle?t.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:p?p(o)+"":void 0};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=At(i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),1);n>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const o=t[e];"geoarea"===o.type&&o.interactive&&t.splice(e,1)}const h="strip"===a?function(t,e,o,n,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,l=fv().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,d,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=fv().domain([0,n]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),f=Math.hypot(t-s,u-a),p=Number(o(r.datum)),y=isFinite(p)&&p>=0?n>0?d(p):0:f,g=l+Math.cos(h)*y,m=c+Math.sin(h)*y;r.x=t+(g-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,d,s,o),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of i)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const o of f){const n=o.datum?.source,i=o.datum?.target;if(null!=n&&null!=i){const r=t.get(n+""),s=t.get(i+"");if(r&&s)if("fractional"===e.lineMode&&o.path.length>2){const t=o.path[0],e=o.path[o.path.length-1],n=[r[0]-t[0],r[1]-t[1]],i=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;o.path.length>t;t++)a.push(a[t-1]+Math.hypot(o.path[t][0]-o.path[t-1][0],o.path[t][1]-o.path[t-1][1]));const 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 h}(this.scene,t,e,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const o=this.scene.filter(t=>"point"===t.type);for(let n=0;o.length>n;n++){const i=Te(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=ze(e,n[a],t);s=De(o[a],l,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Fe(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??1,t.style={...t.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null}advanceTransition(t){if(!this.activeTransition)return!1;const e=Re(t,this.activeTransition),o=Ce(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=Le(t.x,t._targetX,o),t.y=Le(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}};Lv.QUADTREE_THRESHOLD=500;var Iv=Lv;Bo(Iv);import{Fragment as Tv,jsxs as $v}from"react/jsx-runtime";function zv(t,e){const o=C(t.theme),n=t.size||[t.width||600,t.height||400],i=$s({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Is(t.title),s=Array.isArray(t.areas)?B(t.areas):t.areas,a=B(t.points),l=B(t.lines),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return Jg(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];mm(i,{props:t,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:t.projection||"equalEarth",xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineType:t.lineType,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,themeCategorical:o.colors.categorical,themeSemantic:b(o)},f=new Iv(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.`);f.setAreas(s)}t.points&&f.setPoints(a),t.lines&&f.setLines(l),f.computeScene({width:u,height:d});const p=jc({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=Hn(o.style.fill)?Xn(o.style.fill,`geoarea-${e}-hatch`):void 0;return la(sa.Fragment,{children:[n&&aa("defs",{children:n}),aa("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:Zs(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=Hn(o.style.fill)?Xn(o.style.fill,`geopoint-${e}-hatch`):void 0;return la(sa.Fragment,{children:[n&&aa("defs",{children:n}),aa("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:Zs(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 aa("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 Js(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e)});if(e&&(e.evidence=Bg({frameType:"geo",width:n[0],height:n[1],marks:p.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,legendItems:c.length>0?c.length:void 0,margin:i})),0===p.length){const e=t.backgroundGraphics||t.foregroundGraphics||t.annotations||f.customLayoutOverlays?$v(Tv,{children:[t.backgroundGraphics,t.annotations?am({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:u,height:d},theme:o,idPrefix:t._idPrefix}):null,t.foregroundGraphics,f.customLayoutOverlays]}):null;return Kx.renderToStaticMarkup(vm(e,{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:u,innerHeight:d,idPrefix:t._idPrefix}))}const y=p.map(t=>t.element),g=t.annotations?am({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:u,height:d},theme:o,idPrefix:t._idPrefix}):null,m=bm({props:t,categories:c,theme:o,size:n,margin:i,hasTitle:r});return Kx.renderToStaticMarkup(vm($v(Tv,{children:[t.backgroundGraphics,y,g,t.foregroundGraphics,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:u,innerHeight:d,legend:m,idPrefix:t._idPrefix}))}import*as Dv from"react-dom/server";function Fv(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 Ev={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function Ov(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 Bv(t,e){const o="function"==typeof e?e(t):e;return{...Ev,...o??{}}}function Nv(t,e={}){return t.map(t=>function(t,e={}){const o=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),n={label:e.getBodyLabel?.(t)??Ov(t)},i={style:Bv(t,e.bodyStyle),datum:o,accessibleDatum:o,accessibility:n,_transitionKey:t.id};return"aabb"===t.shape.type?{type:"rect",x:t.x-t.shape.width/2,y:t.y-t.shape.height/2,w:t.shape.width,h:t.shape.height,...i}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...i}}(t,e))}import{jsx as Wv,jsxs as jv}from"react/jsx-runtime";var Yv={top:0,right:0,bottom:0,left:0};function Gv(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function Hv(t,e){const o=t.size??[t.width??600,t.height??400],n=new qp(t.config);Array.isArray(t.initialSpawns)&&t.initialSpawns.length>0&&n.enqueue(t.initialSpawns.map(t=>({...t,spawnAt:void 0})));const i=function(t,e={}){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,...f}=e,p=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=Nv(n,e),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:Fv(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,f),y={...Yv,...d},g=[o,n],m=Gv(a,g,y),b=Gv(c,g,y),x=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(u),v=i?x+"-title":void 0,w=r?x+"-desc":void 0,k=[v,w].filter(Boolean).join(" ")||void 0;return{svg:Dv.renderToStaticMarkup(jv("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":k,children:[i&&Wv("title",{id:v,children:i}),r&&Wv("desc",{id:w,children:r}),!a&&s&&"transparent"!==s?Wv("rect",{x:0,y:0,width:o,height:n,fill:s}):null,m,Wv("g",{id:x+"-data-area",children:p.sceneNodes.map((t,e)=>{const o=p.bodies[e];return(o&&h?h(o,t.style??{},e,x):void 0)??wa(t,e,x)})}),b]})),scene:p,evidence:p.evidence}}(n,{...t,width:o[0],height:o[1],charge:t.charge,idPrefix:t.idPrefix??t._idPrefix??"physics"});return e&&(e.evidence=Bg({frameType:"physics",width:o[0],height:o[1],marks:i.scene.sceneNodes,title:t.title,description:t.description,annotations:[],extraWarnings:[...0===i.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...i.scene.evidence.warnings]})),i.svg}import*as qv from"react-dom/server";import{jsx as Vv,jsxs as Xv}from"react/jsx-runtime";var Uv={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function Kv(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var Zv={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",n=Uv[o],i=Kv(t.width,n.width),r=Kv(t.height,n.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):n.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:n.align,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=C(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const o=e.locale??"en-US";if("currency"===t){const t=e.precision??2,n=new Intl.NumberFormat(o,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>n.format(t)}if("percent"===t){const t=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",o=Math.abs(t);if(1e3>o)return`${e}${Math.round(o)}ms`;const n=o/1e3;if(60>n)return`${e}${i=n,Math.round(100*i)/100+""}s`;var i;const r=n/60;if(60>r){const t=Math.floor(r),o=Math.round(n-60*t);return 0===o?`${e}${t}m`:`${e}${t}m ${o}s`}const s=r/60;if(24>s){const t=Math.floor(s),o=Math.round(r-60*t);return 0===o?`${e}${t}h`:`${e}${t}h ${o}m`}const a=Math.floor(s/24),l=Math.round(s-24*a);return 0===l?`${e}${a}d`:`${e}${a}d ${l}h`}(t);const n=new Intl.NumberFormat(o,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>n.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),f=void 0===d?"No value":(p=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${p}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var p;const y=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const o=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let n=null;for(const e of o){if(e.at>t)break;n=e}return n}(d,t.thresholds),g="string"==typeof t.color?t.color:function(t,e,o){return e||("success"===t?o.colors.success??"#2ca02c":"warning"===t?o.colors.warning??"#b26a00":"danger"===t?o.colors.danger??"#d62728":"info"===t?o.colors.info??o.colors.primary:o.colors.text)}(y?.level??"neutral",y?.color,u),m="string"==typeof t.label?t.label:void 0,b="string"==typeof t.caption?t.caption:void 0,x="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,o){const n=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,i=n&&"number"==typeof n.value&&Number.isFinite(n.value)?n.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===i?void 0:e-i);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,o);return`${s}${n&&"string"==typeof n.label?" "+n.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,o){const n=t.target&&"object"==typeof t.target?t.target:void 0;if(!n||"number"!=typeof n.value||!Number.isFinite(n.value))return;const i="string"==typeof n.label?" "+n.label:"";return 0===n.value?`target ${o(n.value)}${i}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/n.value)} of ${o(n.value)}${i}`}(t,d,h),k=[v,w,y?.label].filter(Boolean).join(" · "),S="string"==typeof t.description&&t.description||[m,f,x,k].filter(Boolean).join(", "),A="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+n.labelSize,P=_+n.captionSize+4,R="presentation"===o?r/2+.32*n.valueSize:"thumbnail"===o?r/2+.34*n.valueSize:Math.min(r-s-(k?26:4),(n.showHeader&&(m||b)?b?P+10:_+14:s)+n.valueSize),L=c+("start"===l?Math.max(n.valueSize,f.length*n.valueSize*.55):0),I=qv.renderToStaticMarkup(Xv("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:[Vv("title",{children:m??f}),"string"==typeof t.description&&Vv("desc",{children:t.description}),Vv("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:A,stroke:n.border?M:"none"}),n.showHeader&&m&&Vv("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:m}),n.showHeader&&b&&Vv("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:b}),Vv("text",{x:c,y:R,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:g,"data-mark-type":"value",children:f}),x&&void 0!==d&&"start"===l&&Vv("text",{x:L+6,y:R,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&&k&&Vv("text",{x:c,y:Math.min(r-s,R+n.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Bg({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:S})),I}};function Qv(t,e,o){return Zv[t](e,o)}import{Fragment as Jv,jsx as tw,jsxs as ew}from"react/jsx-runtime";function ow(t,e){switch(t){case"xy":return Am(e);case"ordinal":return eb(e);case"network":return Ux(e);case"geo":return zv(e);case"physics":return Hv(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function nw(t){return Am(t)}function iw(t){return eb(t)}function rw(t){return Ux(t)}function sw(t){return zv(t)}var aw=["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"],lw=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function cw(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function uw(t,e,o){return hw(t,e).svg}function dw(t,e,o){const n={},{svg:i,frameType:r}=hw(t,e,0,n),s=n.evidence??Bg({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,{svg:i,evidence:s}}function hw(t,e,o,n){if(t in Zv)return{svg:Qv(t,e,n),frameType:"value"};const i=Fg[t];if(!i)throw Error(`Unknown chart component: "${t}". See CLAUDE.md for supported chart types.`);var r;const s=$(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(T,r)?e.mode:void 0),{...i.layout?.modeDefaults,...cw(e,lw)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:y,...g}=e,{width:m,height:b}=s,x=[m,b],v=g.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,S=void 0!==h?h:v.margin,A=D(S),M="number"==typeof S?{top:S,right:S,bottom:S,left:S}:{...k,...A},_=cw(g,aw),P=t=>v[t]??s[t],R={...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!==f&&{colorScheme:f},...void 0!==y&&{legendPosition:y},_idPrefix:g._idPrefix},L=i.buildProps(a,p,f,R,g);let I;switch(i.frameType){case"xy":I=Am(L,n);break;case"ordinal":I=eb(L,n);break;case"network":I=Ux(L,n);break;case"geo":I=zv(L,n);break;case"physics":I=Hv(L,n)}const z=i.renderOverlay?.(L,{theme:C(l)});if(null!=z){const t=F.renderToStaticMarkup(tw(Jv,{children:z}));I=I.replace("</svg>",t+"</svg>")}return{svg:I,frameType:i.frameType}}async function fw(t,e,o={}){const{format:n="png",scale:i=1,background:r}=o;let s,a;s=["xy","ordinal","network","geo","physics"].includes(t)?ow(t,e):uw(t,e),r&&(s=s.replace(/<svg /,`<svg style="background:${r}" `));try{const t="sharp",e=await import(t);a=e.default??e}catch{throw Error('Image export requires the "sharp" package and a Node.js runtime. Install it:\n npm install sharp\nsharp is listed as an optional dependency of semiotic.')}const l=e.width||e.size?.[0]||600,c=e.height||e.size?.[1]||400,u=a(void 0!==globalThis.Buffer?globalThis.Buffer.from(s):(new TextEncoder).encode(s),{density:72*i}).resize(Math.round(l*i),Math.round(c*i));return"jpeg"===n?u.jpeg({quality:90}).toBuffer():u.png().toBuffer()}function pw(t,e={}){const{title:o,subtitle:n,theme:i,width:r=1200,height:s,layout:a={},background:l}=e,c=R(C(i)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),n&&(h+=20),h>0&&(h+=10);const f=Math.floor((r-d-d*(u-1))/u),p=[];let y=0,g=h+d,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),o=e.props.height||300;y+t>u&&(g+=m+d,y=0,m=0),p.push({chart:e,x:d/2+y*(f+d),y:g,w:f*t+d*(t-1),h:o}),m=Math.max(m,o),y+=t}const b=s||g+m+d,x=p.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?uw(o.component,l):o.frameType?ow(o.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,tw("g",{transform:`translate(${n},${r})`,children:tw("foreignObject",{width:s,height:a,children:tw("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+e)});return F.renderToStaticMarkup(ew("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:b,role:"img","aria-label":o||"Dashboard",style:{fontFamily:c.fontFamily},children:[o&&tw("title",{children:o}),l&&tw("rect",{x:0,y:0,width:r,height:b,fill:l}),o&&tw("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleSize+4,fontWeight:"bold",fill:c.text,fontFamily:c.fontFamily,children:o}),n&&tw("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:n}),x]}))}import*as yw from"react-dom/server";import{Fragment as gw,jsx as mw,jsxs as bw}from"react/jsx-runtime";function xw(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=n,f=o.width||600,p=o.height||400,y=C(o.theme),g={...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))))),b=[];for(let t=m;e.length>=t;t+=m)b.push(t);b[b.length-1]!==e.length&&b.push(e.length);const x=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=$s({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=f-v.left-v.right,k=p-v.top-v.bottom,S=[];if(x)for(let n=0;b.length>n;n++){const i=b[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,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||y.colors.categorical,...h&&{decay:h}},l=new Um(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&S.push(Mw(l.scene,f,p,y,g))}else for(let n=0;b.length>n;n++){const i=b[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||y.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 an(m);if(x.ingest({inserts:s,bounded:!0}),x.computeScene({width:w,height:k}),0===x.scene.length)continue;const v=x.scales?{y:x.scales.y}:void 0;if(S.push(Aw(x.scene,f,p,y,g,v)),c>0&&n>0&&x.activeTransition){const t=c*(1e3/u);for(let e=1;c>=e;e++)x.advanceTransition(x.activeTransition.startTime+e/c*t),S.push(Aw(x.scene,f,p,y,g,v))}}return S}function vw(t,e,o={}){return e.map(e=>{try{return uw(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 ww(t,e,o){const n=e.size??[e.width??600,e.height??400],i=C(e.theme),r=R(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=Nv(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=bw("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&&mw("title",{id:l,children:e.title}),e.description&&mw("desc",{id:c,children:e.description}),s&&"transparent"!==s?mw("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,mw("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>wa(t,e,`${a}-${o}`))})]});return yw.renderToStaticMarkup(h)}function kw(t,e={}){const{fps:o=12,frameCount:n,durationSeconds:i=2,includeInitialFrame:r=!0,stepDt:s,stepsPerFrame:a,background:l}=e,c=Math.max(.001,s??t.config?.fixedDt??1/120),u=a??Math.max(1,Math.round(1/Math.max(1,o)/c)),d=n??Math.max(1,Math.ceil(i*Math.max(1,o))),h=l?{...t,background:l}:t,f=new qp(t.config);t.initialSpawns?.length&&f.enqueue(t.initialSpawns,t.initialSpawnPacing);const p=[];for(r&&(f.tick(0),p.push(ww(f,h,0)));d>p.length;){for(let t=0;u>t;t+=1)f.tick(c);p.push(ww(f,h,p.length))}return p}function Sw(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function Aw(t,e,o,n,i,r){const s=R(n),a=$s({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=Sw(i,n),d=i.renderMode,h=t.map((t,e)=>Wc({node:t,index:e,renderMode:d,fallback:()=>wa(t,e)})).filter(Boolean),f=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=R(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(bw("g",{children:[mw("line",{x1:0,y1:t,x2:e,y2:t,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&mw("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?mw(gw,{children:a}):null}(i.annotations,l,c,n,i.yExtent,r?.y),p="string"==typeof i.title?i.title:void 0,y="string"==typeof i.description?i.description:void 0,g=p?"semiotic-title":void 0,m=y?"semiotic-desc":void 0,b=[g,m].filter(Boolean).join(" ")||void 0;return yw.renderToStaticMarkup(bw("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":b,style:{fontFamily:s.fontFamily},children:[p&&mw("title",{id:g,children:p}),y&&mw("desc",{id:m,children:y}),u&&mw("rect",{x:0,y:0,width:e,height:o,fill:u}),bw("g",{transform:`translate(${a.left},${a.top})`,children:[f,h]}),p&&mw("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleSize,fontWeight:"bold",fill:s.text,fontFamily:s.fontFamily,children:p})]}))}function Mw(t,e,o,n,i){const r=R(n),s=$s({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=Sw(i,n),d=i.renderMode,h=t.map((t,e)=>Wc({node:t,index:e,renderMode:d,fallback:()=>ma(t,e)})).filter(Boolean),f="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,y=f?"semiotic-title":void 0,g=p?"semiotic-desc":void 0,m=[y,g].filter(Boolean).join(" ")||void 0;return yw.renderToStaticMarkup(bw("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":m,style:{fontFamily:r.fontFamily},children:[f&&mw("title",{id:y,children:f}),p&&mw("desc",{id:g,children:p}),u&&mw("rect",{x:0,y:0,width:e,height:o,fill:u}),mw("g",{transform:`translate(${l},${c})`,children:h}),f&&mw("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleSize,fontWeight:"bold",fill:r.text,fontFamily:r.fontFamily,children:f})]}))}async function _w(t,e,o,n={}){const{fps:i=12,loop:r=!0,scale:s=1,background:a}=n,l=o.width||600,c=o.height||400,u=xw(t,e,a?{...o,background:a}:o,n);if(0===u.length)throw Error("No frames generated — check that data is not empty");return Cw(u,l,c,{fps:i,loop:r,scale:s})}async function Pw(t,e={}){const{fps:o=12,loop:n=!0,scale:i=1}=e,r=t.size??[t.width??600,t.height??400],s=kw(t,e);if(0===s.length)throw Error("No physics frames generated");return Cw(s,r[0],r[1],{fps:o,loop:n,scale:i})}async function Cw(t,e,o,n={}){const{fps:i=12,loop:r=!0,scale:s=1}=n,a=Math.round(e*s),l=Math.round(o*s);let c,u,d,h;try{const t="sharp",e=await import(t);c=e.default??e}catch{throw Error('Animated GIF export requires "sharp". Install it:\n npm install sharp')}try{const t="gifenc",e=await import(t),o=[e,e.default].find(t=>"function"==typeof t?.GIFEncoder&&"function"==typeof t.quantize&&"function"==typeof t.applyPalette);if(!o)throw Error("gifenc did not expose its encoder functions");u=o.GIFEncoder,d=o.quantize,h=o.applyPalette}catch(t){throw Error('Animated GIF export requires "gifenc". Install it:\n npm install gifenc',{cause:t})}const f=Math.round(1e3/i),p=u();for(let e=0;t.length>e;e++){const o=t[e],n=await c(Buffer.from(o),{density:72*s}).resize(a,l).ensureAlpha().raw().toBuffer(),i=new Uint8Array(n),u=d(i,256),y=h(i,u);p.writeFrame(y,a,l,{palette:u,delay:f,repeat:r?0:-1})}return p.finish(),Buffer.from(p.bytes())}export{C as resolveTheme,R as themeStyles,ow as renderToStaticSVG,nw as renderXYToStaticSVG,iw as renderOrdinalToStaticSVG,rw as renderNetworkToStaticSVG,sw as renderGeoToStaticSVG,uw as renderChart,dw as renderChartWithEvidence,fw as renderToImage,pw as renderDashboard,xw as generateFrameSVGs,vw as generateFrameSequence,kw as generatePhysicsFrameSVGs,_w as renderToAnimatedGif,Pw as renderPhysicsToAnimatedGif};