semiotic 3.9.1 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. package/README.md +137 -58
  2. package/agent-skill/semiotic-charts/SKILL.md +27 -17
  3. package/ai/artifact-contract-reference.md +408 -0
  4. package/ai/artifact-surface-inventory.json +5586 -0
  5. package/ai/behaviorContracts.cjs +24 -2
  6. package/ai/cli.js +480 -56
  7. package/ai/componentMetadata.cjs +13 -3
  8. package/ai/dist/mcp-server.js +140 -36407
  9. package/ai/examples.md +110 -7
  10. package/ai/reference.md +82 -28
  11. package/ai/schema.json +7675 -1471
  12. package/ai/surface-manifest.json +60 -9
  13. package/ai/system-prompt.md +18 -3
  14. package/ai/task-packets/compare-category-totals.json +301 -0
  15. package/ai/task-packets/compare-category-totals.md +188 -0
  16. package/ai/task-packets/correct-published-chart.json +271 -0
  17. package/ai/task-packets/correct-published-chart.md +597 -0
  18. package/ai/task-packets/index.json +40 -0
  19. package/ai/task-packets/update-live-chart.json +289 -0
  20. package/ai/task-packets/update-live-chart.md +424 -0
  21. package/dist/c-2N7IU2NY.min.js +1 -0
  22. package/dist/c-2WK7YJLL.min.js +1 -0
  23. package/dist/c-33QOXEUG.min.js +1 -0
  24. package/dist/c-42PLDTX7.min.js +1 -0
  25. package/dist/c-447VIMRO.min.js +1 -0
  26. package/dist/c-4FN7Q6VQ.min.js +1 -0
  27. package/dist/c-553QUDKA.min.js +1 -0
  28. package/dist/c-55BAJ333.min.js +1 -0
  29. package/dist/c-7242NXSG.min.js +1 -0
  30. package/dist/c-7EGHJU2F.min.js +1 -0
  31. package/dist/c-7HP7MB2I.min.js +1 -0
  32. package/dist/c-7NBU5ZKS.min.js +1 -0
  33. package/dist/c-AFBSWT77.min.js +1 -0
  34. package/dist/c-AJ7EC32V.min.js +1 -0
  35. package/dist/c-AQADQNY7.min.js +1 -0
  36. package/dist/c-ATM475SA.min.js +1 -0
  37. package/dist/c-AVO3Q7T7.min.js +1 -0
  38. package/dist/c-AZKPVBOC.min.js +1 -0
  39. package/dist/c-BNFJMDHN.min.js +1 -0
  40. package/dist/c-BNG5ECK5.min.js +1 -0
  41. package/dist/c-BOHCQILI.min.js +1 -0
  42. package/dist/c-CCTGN5CK.min.js +1 -0
  43. package/dist/c-CPSPZH6A.min.js +1 -0
  44. package/dist/c-CPV4N35K.min.js +1 -0
  45. package/dist/c-D6HAAPTX.min.js +1 -0
  46. package/dist/c-DE5Q3U2X.min.js +1 -0
  47. package/dist/c-DK662R77.min.js +1 -0
  48. package/dist/c-DY2676CR.min.js +1 -0
  49. package/dist/c-E32M6XW5.min.js +1 -0
  50. package/dist/c-E4JDJH4I.min.js +1 -0
  51. package/dist/c-E7I2L7CU.min.js +1 -0
  52. package/dist/c-EBOQ7ER7.min.js +1 -0
  53. package/dist/c-ELDWAO2V.min.js +1 -0
  54. package/dist/c-EUBTECGM.min.js +1 -0
  55. package/dist/c-GNTXRXRN.min.js +1 -0
  56. package/dist/c-GSZRZRD6.min.js +1 -0
  57. package/dist/c-GWX7JGMF.min.js +1 -0
  58. package/dist/c-GXV3C3MO.min.js +1 -0
  59. package/dist/c-HHTK2R75.min.js +1 -0
  60. package/dist/c-HLLFJYTY.min.js +1 -0
  61. package/dist/c-HPOYKCCG.min.js +1 -0
  62. package/dist/c-HXDKPIKR.min.js +1 -0
  63. package/dist/c-I4QJ6YLM.min.js +1 -0
  64. package/dist/c-IDJV3CZK.min.js +1 -0
  65. package/dist/c-ITKX3RC5.min.js +1 -0
  66. package/dist/c-JG2JCQLP.min.js +1 -0
  67. package/dist/c-JLGRHXGZ.min.js +1 -0
  68. package/dist/c-JO2UGTCP.min.js +1 -0
  69. package/dist/c-JUKIWTBJ.min.js +1 -0
  70. package/dist/c-KCRJGUHP.min.js +1 -0
  71. package/dist/c-LMGSSD2E.min.js +1 -0
  72. package/dist/c-LYQMZMZQ.min.js +1 -0
  73. package/dist/c-LYVKDBQJ.min.js +1 -0
  74. package/dist/c-MVR3RWF3.min.js +1 -0
  75. package/dist/c-MXCP7GNZ.min.js +1 -0
  76. package/dist/c-NG7BLZTR.min.js +1 -0
  77. package/dist/c-NYZ2QNAM.min.js +1 -0
  78. package/dist/c-OO5QLMJC.min.js +1 -0
  79. package/dist/c-OOVX2JPQ.min.js +1 -0
  80. package/dist/c-ORLEBW72.min.js +1 -0
  81. package/dist/c-P65V6HLO.min.js +1 -0
  82. package/dist/c-PP6VY3QU.min.js +1 -0
  83. package/dist/c-PRIKOLTE.min.js +1 -0
  84. package/dist/c-PSNI6KAZ.min.js +1 -0
  85. package/dist/c-PYNW54D2.min.js +1 -0
  86. package/dist/c-QA3HMQJP.min.js +1 -0
  87. package/dist/c-QAVFOEUY.min.js +1 -0
  88. package/dist/c-ROEHCIGV.min.js +1 -0
  89. package/dist/c-S3AZX5PP.min.js +1 -0
  90. package/dist/c-T2V7O2LO.min.js +1 -0
  91. package/dist/c-TIXX5CAU.min.js +1 -0
  92. package/dist/c-TKG2NP7G.min.js +1 -0
  93. package/dist/c-VJTDST2R.min.js +1 -0
  94. package/dist/c-VXLOLYTO.min.js +1 -0
  95. package/dist/c-W4ZUKSEQ.min.js +1 -0
  96. package/dist/c-WH2O53VI.min.js +1 -0
  97. package/dist/c-WNGH47HF.min.js +1 -0
  98. package/dist/c-WUWXGQYA.min.js +1 -0
  99. package/dist/c-XDQKXPX4.min.js +1 -0
  100. package/dist/c-XSB27XPS.min.js +1 -0
  101. package/dist/c-YDECTEUW.min.js +1 -0
  102. package/dist/c-YF3YKVQI.min.js +1 -0
  103. package/dist/c-YLZIV3VS.min.js +1 -0
  104. package/dist/c-ZYPXQF7B.min.js +1 -0
  105. package/dist/components/Annotation.d.ts +3 -2
  106. package/dist/components/access/chartAccessCapabilities.generated.d.ts +14 -0
  107. package/dist/components/access/chartAccessContract.d.ts +90 -0
  108. package/dist/components/access/chartAccessContractFixtures.d.ts +11 -0
  109. package/dist/components/ai/aestheticProfileTypes.d.ts +35 -0
  110. package/dist/components/ai/annotationProvenance.d.ts +2 -7
  111. package/dist/components/ai/auditVisualHierarchy.d.ts +49 -0
  112. package/dist/components/ai/builtInChartRecipeLayouts.d.ts +2 -0
  113. package/dist/components/ai/builtInChartRecipePublic.d.ts +4 -0
  114. package/dist/components/ai/builtInChartRecipes.d.ts +26 -0
  115. package/dist/components/ai/chartCapabilities.d.ts +3 -1
  116. package/dist/components/ai/chartRecipeRegistry.d.ts +7 -1
  117. package/dist/components/ai/chartRecipes.d.ts +10 -0
  118. package/dist/components/ai/colorEvidence.d.ts +12 -0
  119. package/dist/components/ai/describePhysicsProjection.d.ts +18 -0
  120. package/dist/components/ai/describePhysicsSource.d.ts +13 -0
  121. package/dist/components/ai/evaluateAesthetics.d.ts +47 -0
  122. package/dist/components/ai/geoNavigation.d.ts +4 -0
  123. package/dist/components/ai/hierarchyNavigation.d.ts +4 -0
  124. package/dist/components/ai/navigationTree.d.ts +7 -1
  125. package/dist/components/ai/qualityFixtures.d.ts +8 -0
  126. package/dist/components/ai/suggestionPropContracts.d.ts +1 -1
  127. package/dist/components/ai/useNavigationSync.d.ts +3 -3
  128. package/dist/components/artifact/ArtifactInspector.d.ts +26 -0
  129. package/dist/components/artifact/ArtifactInspectorContextSections.d.ts +18 -0
  130. package/dist/components/artifact/artifactContractDiff.d.ts +8 -0
  131. package/dist/components/artifact/artifactInspectorSummary.d.ts +53 -0
  132. package/dist/components/artifact/artifactRevision.d.ts +54 -0
  133. package/dist/components/artifact/artifactTestFixtures.d.ts +17 -0
  134. package/dist/components/artifact/attachmentAudit.d.ts +13 -0
  135. package/dist/components/artifact/claimCorrections.d.ts +3 -0
  136. package/dist/components/artifact/claimGraph.d.ts +5 -0
  137. package/dist/components/artifact/claimLifecycle.d.ts +32 -0
  138. package/dist/components/artifact/claims.d.ts +24 -0
  139. package/dist/components/artifact/collection.d.ts +10 -0
  140. package/dist/components/artifact/collectionCorrectionScope.d.ts +4 -0
  141. package/dist/components/artifact/collectionImpact.d.ts +11 -0
  142. package/dist/components/artifact/collectionLineage.d.ts +3 -0
  143. package/dist/components/artifact/collectionOperations.d.ts +8 -0
  144. package/dist/components/artifact/collectionPolicy.d.ts +22 -0
  145. package/dist/components/artifact/collectionTypes.d.ts +117 -0
  146. package/dist/components/artifact/configurationRepair.d.ts +8 -0
  147. package/dist/components/artifact/contract.d.ts +30 -0
  148. package/dist/components/artifact/evaluateArtifact.d.ts +12 -0
  149. package/dist/components/artifact/evaluateArtifactTypes.d.ts +78 -0
  150. package/dist/components/artifact/evaluationPresentation.d.ts +9 -0
  151. package/dist/components/artifact/evidenceSample.d.ts +8 -0
  152. package/dist/components/artifact/exportPaths.d.ts +8 -0
  153. package/dist/components/artifact/fieldPolicies.d.ts +12 -0
  154. package/dist/components/artifact/fingerprint.d.ts +36 -0
  155. package/dist/components/artifact/grounding.d.ts +51 -0
  156. package/dist/components/artifact/groundingBudget.d.ts +38 -0
  157. package/dist/components/artifact/hostTransfer.d.ts +13 -0
  158. package/dist/components/artifact/identity.d.ts +19 -0
  159. package/dist/components/artifact/inheritance.d.ts +48 -0
  160. package/dist/components/artifact/inheritanceIntegrity.d.ts +3 -0
  161. package/dist/components/artifact/jsonCompatibility.d.ts +2 -0
  162. package/dist/components/artifact/obligations.d.ts +3 -0
  163. package/dist/components/artifact/policies.d.ts +45 -0
  164. package/dist/components/artifact/policyRelations.d.ts +3 -0
  165. package/dist/components/artifact/recordProjection.d.ts +7 -0
  166. package/dist/components/artifact/representation.d.ts +50 -0
  167. package/dist/components/artifact/serialization.d.ts +40 -0
  168. package/dist/components/artifact/temporal.d.ts +32 -0
  169. package/dist/components/artifact/temporalAdapters.d.ts +75 -0
  170. package/dist/components/artifact/temporalAuditHelpers.d.ts +12 -0
  171. package/dist/components/artifact/temporalPresentation.d.ts +8 -0
  172. package/dist/components/artifact/types.d.ts +341 -0
  173. package/dist/components/artifact/validation.d.ts +13 -0
  174. package/dist/components/artifact/validationFieldStatus.d.ts +7 -0
  175. package/dist/components/artifact/validationPrimitives.d.ts +24 -0
  176. package/dist/components/artifact/validationSurfaces.d.ts +7 -0
  177. package/dist/components/artifact/validationTemporal.d.ts +3 -0
  178. package/dist/components/charts/geo/FlowMap.d.ts +7 -0
  179. package/dist/components/charts/geo/flowMapLineStyle.d.ts +18 -0
  180. package/dist/components/charts/index.d.ts +4 -0
  181. package/dist/components/charts/network/ChordDiagram.d.ts +5 -1
  182. package/dist/components/charts/network/CirclePack.d.ts +8 -1
  183. package/dist/components/charts/network/OrbitDiagram.d.ts +9 -0
  184. package/dist/components/charts/network/TreeDiagram.d.ts +8 -1
  185. package/dist/components/charts/network/Treemap.d.ts +8 -1
  186. package/dist/components/charts/ordinal/BarChart.d.ts +6 -0
  187. package/dist/components/charts/ordinal/BoxPlot.d.ts +3 -0
  188. package/dist/components/charts/ordinal/DonutChart.d.ts +5 -0
  189. package/dist/components/charts/ordinal/DotPlot.d.ts +3 -0
  190. package/dist/components/charts/ordinal/FunnelChart.d.ts +5 -0
  191. package/dist/components/charts/ordinal/GaugeChart.d.ts +3 -0
  192. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +6 -0
  193. package/dist/components/charts/ordinal/Histogram.d.ts +3 -0
  194. package/dist/components/charts/ordinal/LikertChart.d.ts +3 -0
  195. package/dist/components/charts/ordinal/PieChart.d.ts +5 -0
  196. package/dist/components/charts/ordinal/RadarChart.capability.d.ts +2 -0
  197. package/dist/components/charts/ordinal/RadarChart.d.ts +77 -0
  198. package/dist/components/charts/ordinal/RidgelinePlot.d.ts +3 -0
  199. package/dist/components/charts/ordinal/StackedBarChart.d.ts +6 -0
  200. package/dist/components/charts/ordinal/SwarmPlot.d.ts +3 -0
  201. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +3 -0
  202. package/dist/components/charts/ordinal/ViolinPlot.d.ts +3 -0
  203. package/dist/components/charts/physics/CollisionSwarmChart.d.ts +1 -1
  204. package/dist/components/charts/physics/EventDropChart.d.ts +3 -1
  205. package/dist/components/charts/physics/GaltonBoardChart.d.ts +4 -2
  206. package/dist/components/charts/physics/GauntletChart.d.ts +1 -5
  207. package/dist/components/charts/physics/ProcessFlowChart.d.ts +6 -0
  208. package/dist/components/charts/physics/UnitPileChart.d.ts +2 -1
  209. package/dist/components/charts/physics/chainReactionTypes.d.ts +3 -0
  210. package/dist/components/charts/physics/collisionSwarmPacking.d.ts +14 -0
  211. package/dist/components/charts/physics/collisionSwarmPhysics.d.ts +1 -0
  212. package/dist/components/charts/physics/eventDropAdmission.d.ts +32 -0
  213. package/dist/components/charts/physics/eventDropPhysics.d.ts +22 -1
  214. package/dist/components/charts/physics/galtonBoardPhysics.d.ts +2 -9
  215. package/dist/components/charts/physics/gauntletPhysics.d.ts +1 -0
  216. package/dist/components/charts/physics/physicsChartReconcile.d.ts +4 -0
  217. package/dist/components/charts/physics/physicsChartUtils.d.ts +1 -1
  218. package/dist/components/charts/physics/physicsGaltonData.d.ts +10 -0
  219. package/dist/components/charts/physics/physicsHocHandle.d.ts +2 -0
  220. package/dist/components/charts/physics/physicsHocUtils.d.ts +7 -1
  221. package/dist/components/charts/physics/physicsPileData.d.ts +11 -0
  222. package/dist/components/charts/physics/physicsPilePhysics.d.ts +5 -12
  223. package/dist/components/charts/physics/physicsProjectionOverlays.d.ts +1 -1
  224. package/dist/components/charts/physics/physicsSourceRows.d.ts +8 -0
  225. package/dist/components/charts/physics/usePhysicsChartData.d.ts +19 -0
  226. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +14 -1
  227. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +25 -7
  228. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +18 -5
  229. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +11 -1
  230. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +11 -1
  231. package/dist/components/charts/realtime/aggregate.d.ts +12 -1
  232. package/dist/components/charts/realtime/realtimeAccessors.d.ts +4 -0
  233. package/dist/components/charts/realtime/realtimeChartRuntime.d.ts +8 -5
  234. package/dist/components/charts/realtime/realtimeChartTypes.d.ts +7 -0
  235. package/dist/components/charts/realtime/realtimeStyleRules.d.ts +4 -0
  236. package/dist/components/charts/realtime/temporalHistogramConfig.d.ts +17 -11
  237. package/dist/components/charts/shared/GaugeReadout.d.ts +9 -0
  238. package/dist/components/charts/shared/ThresholdAnnotation.d.ts +18 -0
  239. package/dist/components/charts/shared/ThresholdEndCap.d.ts +7 -0
  240. package/dist/components/charts/shared/annotationStatusFilter.d.ts +18 -0
  241. package/dist/components/charts/shared/auditAccessibilityText.d.ts +4 -2
  242. package/dist/components/charts/shared/chartDefinitionPilot.d.ts +5 -4
  243. package/dist/components/charts/shared/chartSpecCore.d.ts +2 -2
  244. package/dist/components/charts/shared/heatmapStyleRules.d.ts +13 -0
  245. package/dist/components/charts/shared/knownChartComponents.d.ts +1 -1
  246. package/dist/components/charts/shared/networkUtils.d.ts +14 -0
  247. package/dist/components/charts/shared/numericTickFormatter.d.ts +2 -0
  248. package/dist/components/charts/shared/radialCenterContent.d.ts +10 -0
  249. package/dist/components/charts/shared/selectionUtils.d.ts +3 -1
  250. package/dist/components/charts/shared/tooltipUtils.d.ts +1 -1
  251. package/dist/components/charts/shared/types.d.ts +4 -2
  252. package/dist/components/charts/shared/useChartLegend.d.ts +6 -1
  253. package/dist/components/charts/shared/useLikertAggregation.d.ts +8 -2
  254. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +9 -5
  255. package/dist/components/charts/shared/useOrdinalPieceStyle.d.ts +1 -1
  256. package/dist/components/charts/shared/useXYBrush.d.ts +24 -0
  257. package/dist/components/charts/shared/useXYPointStyle.d.ts +2 -0
  258. package/dist/components/charts/xy/BubbleChart.d.ts +7 -0
  259. package/dist/components/charts/xy/CandlestickChart.d.ts +7 -0
  260. package/dist/components/charts/xy/DifferenceChart.d.ts +7 -0
  261. package/dist/components/charts/xy/Heatmap.d.ts +16 -0
  262. package/dist/components/charts/xy/LineChart.d.ts +9 -0
  263. package/dist/components/charts/xy/MinimapChart.d.ts +7 -0
  264. package/dist/components/charts/xy/MultiAxisLineChart.d.ts +7 -0
  265. package/dist/components/charts/xy/Scatterplot.d.ts +7 -0
  266. package/dist/components/charts/xy/ScatterplotMatrix.d.ts +6 -0
  267. package/dist/components/charts/xy/WaterfallChart.capability.d.ts +2 -0
  268. package/dist/components/charts/xy/WaterfallChart.d.ts +76 -0
  269. package/dist/components/charts/xy/differenceMarkStyle.d.ts +28 -0
  270. package/dist/components/charts/xy/multiAxisFields.d.ts +23 -0
  271. package/dist/components/charts/xy/scatterplotMatrixCells.d.ts +50 -0
  272. package/dist/components/evidence/chartEvidenceEnvelope.d.ts +154 -0
  273. package/dist/components/evidence/evidenceEnvelopeInput.d.ts +8 -0
  274. package/dist/components/evidence/evidenceEnvelopeValidation.d.ts +11 -0
  275. package/dist/components/evidence/evidenceGate.d.ts +30 -0
  276. package/dist/components/evidence/renderedSceneHash.d.ts +23 -0
  277. package/dist/components/evidence/stableJsonHash.d.ts +4 -0
  278. package/dist/components/export/chartConfig.d.ts +40 -5
  279. package/dist/components/export/chartConfigArtifact.d.ts +6 -0
  280. package/dist/components/legendLayout.d.ts +18 -0
  281. package/dist/components/legendStyles.d.ts +4 -0
  282. package/dist/components/realtime/BinAccumulator.d.ts +5 -1
  283. package/dist/components/realtime/types.d.ts +16 -7
  284. package/dist/components/recipes/adjacencyFlow.d.ts +12 -0
  285. package/dist/components/recipes/adjacencyFlowAggregation.d.ts +72 -0
  286. package/dist/components/recipes/adjacencyFlowGeometry.d.ts +79 -0
  287. package/dist/components/recipes/firstAvailableTrack.d.ts +17 -0
  288. package/dist/components/recipes/intervals.d.ts +1 -1
  289. package/dist/components/recipes/lineageDag.d.ts +17 -0
  290. package/dist/components/recipes/lineageDagHulls.d.ts +22 -0
  291. package/dist/components/recipes/transitDiagram.d.ts +75 -0
  292. package/dist/components/recipes/transitDiagramGeometry.d.ts +47 -0
  293. package/dist/components/semiotic-access.d.ts +9 -0
  294. package/dist/components/semiotic-ai-audits.d.ts +17 -0
  295. package/dist/components/semiotic-ai-core.d.ts +38 -18
  296. package/dist/components/semiotic-ai.d.ts +20 -20
  297. package/dist/components/semiotic-artifact-react.d.ts +10 -0
  298. package/dist/components/semiotic-artifact.d.ts +23 -0
  299. package/dist/components/semiotic-evidence.d.ts +10 -0
  300. package/dist/components/semiotic-experimental.d.ts +1 -1
  301. package/dist/components/semiotic-line.d.ts +9 -0
  302. package/dist/components/semiotic-network.d.ts +3 -0
  303. package/dist/components/semiotic-ordinal.d.ts +2 -0
  304. package/dist/components/semiotic-physics.d.ts +4 -4
  305. package/dist/components/semiotic-realtime-core.d.ts +3 -2
  306. package/dist/components/semiotic-recipes-core.d.ts +6 -0
  307. package/dist/components/semiotic-text.d.ts +2 -0
  308. package/dist/components/semiotic-themes-core.d.ts +3 -0
  309. package/dist/components/semiotic-utils-core.d.ts +19 -14
  310. package/dist/components/semiotic-xy.d.ts +3 -0
  311. package/dist/components/semiotic.d.ts +11 -5
  312. package/dist/components/server/renderDashboard.d.ts +37 -0
  313. package/dist/components/server/renderEvidence.d.ts +39 -0
  314. package/dist/components/server/renderToStaticSVG.d.ts +5 -30
  315. package/dist/components/server/serverChartConfigShared.d.ts +13 -0
  316. package/dist/components/server/serverChartConfigs.d.ts +9 -0
  317. package/dist/components/server/serverChartConfigsComposite.d.ts +4 -0
  318. package/dist/components/server/serverChartConfigsCustom.d.ts +2 -0
  319. package/dist/components/server/serverChartConfigsGeo.d.ts +1 -0
  320. package/dist/components/server/serverChartConfigsOrdinal.d.ts +3 -2
  321. package/dist/components/server/serverChartConfigsXY.d.ts +1 -0
  322. package/dist/components/server/serverChartConfigsXYExtra.d.ts +3 -0
  323. package/dist/components/server/serverCompositeChainReaction.d.ts +3 -0
  324. package/dist/components/server/serverOrdinalGauge.d.ts +3 -0
  325. package/dist/components/server/serverOrdinalLikert.d.ts +2 -0
  326. package/dist/components/server/staticSVGChrome.d.ts +1 -4
  327. package/dist/components/server/staticXYAxisTicks.d.ts +2 -38
  328. package/dist/components/server/staticXYGrid.d.ts +1 -1
  329. package/dist/components/server/svgSizing.d.ts +6 -0
  330. package/dist/components/shared/svgRoot.d.ts +17 -0
  331. package/dist/components/store/selectionProvenance.d.ts +14 -0
  332. package/dist/components/store/themeCore.d.ts +5 -1
  333. package/dist/components/stream/GeoPipelineStore.d.ts +1 -1
  334. package/dist/components/stream/GeoSVGOverlay.d.ts +4 -0
  335. package/dist/components/stream/MarginalGraphics.d.ts +3 -3
  336. package/dist/components/stream/MarginalGraphicsLazy.d.ts +22 -0
  337. package/dist/components/stream/NetworkPipelineStore.d.ts +2 -0
  338. package/dist/components/stream/NetworkSVGOverlay.d.ts +4 -0
  339. package/dist/components/stream/OrdinalPipelineStore.d.ts +1 -1
  340. package/dist/components/stream/OrdinalSVGOverlay.d.ts +4 -0
  341. package/dist/components/stream/PipelineStore.d.ts +1 -1
  342. package/dist/components/stream/SVGOverlay.d.ts +4 -0
  343. package/dist/components/stream/SceneToSVG.d.ts +4 -19
  344. package/dist/components/stream/SceneToSVGXY.d.ts +13 -0
  345. package/dist/components/stream/StreamGeoFrame.d.ts +1 -2
  346. package/dist/components/stream/StreamOrdinalFrame.d.ts +1 -2
  347. package/dist/components/stream/XYGrid.d.ts +11 -0
  348. package/dist/components/stream/axisTickUtils.d.ts +0 -1
  349. package/dist/components/stream/canvasSetup.d.ts +8 -2
  350. package/dist/components/stream/customLayoutAttempt.d.ts +21 -0
  351. package/dist/components/stream/geoTypes.d.ts +1 -1
  352. package/dist/components/stream/hitTestUtils.d.ts +2 -0
  353. package/dist/components/stream/isServerEnvironment.d.ts +6 -0
  354. package/dist/components/stream/layouts/forceLayoutNodeSize.d.ts +12 -0
  355. package/dist/components/stream/layouts/forceLayoutPlugin.d.ts +2 -9
  356. package/dist/components/stream/layouts/forceLayoutWorkerClient.d.ts +2 -21
  357. package/dist/components/stream/layouts/forceLayoutWorkerPolicy.d.ts +21 -0
  358. package/dist/components/stream/layouts/index.d.ts +6 -12
  359. package/dist/components/stream/layouts/missingPlugin.d.ts +7 -0
  360. package/dist/components/stream/layouts/registerBuiltIn.d.ts +1 -0
  361. package/dist/components/stream/layouts/registry.d.ts +12 -0
  362. package/dist/components/stream/marginalConfig.d.ts +3 -0
  363. package/dist/components/stream/networkCustomLayout.d.ts +7 -0
  364. package/dist/components/stream/networkCustomLayoutOutput.d.ts +13 -0
  365. package/dist/components/stream/networkCustomLayoutRunner.d.ts +1 -1
  366. package/dist/components/stream/networkTypes.d.ts +5 -1
  367. package/dist/components/stream/ordinalTypes.d.ts +1 -1
  368. package/dist/components/stream/overlayAccessibleText.d.ts +18 -0
  369. package/dist/components/stream/physics/PhysicsControllers.d.ts +1 -1
  370. package/dist/components/stream/physics/PhysicsKernel.d.ts +9 -0
  371. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +5 -4
  372. package/dist/components/stream/physics/PhysicsPipelineTypes.d.ts +9 -0
  373. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +4 -1
  374. package/dist/components/stream/physics/physicsCanvasCoordinates.d.ts +5 -0
  375. package/dist/components/stream/physics/physicsFixedPosition.d.ts +16 -0
  376. package/dist/components/stream/physics/physicsKernelCloning.d.ts +6 -0
  377. package/dist/components/stream/physics/physicsPipelineObservations.d.ts +2 -0
  378. package/dist/components/stream/physics/physicsPipelineSettle.d.ts +15 -9
  379. package/dist/components/stream/physics/physicsRegionRuntime.d.ts +8 -17
  380. package/dist/components/stream/physics/physicsSemanticUI.d.ts +9 -0
  381. package/dist/components/stream/pipelineConfig.d.ts +4 -0
  382. package/dist/components/stream/pipelineDomainResolution.d.ts +6 -0
  383. package/dist/components/stream/pipelineStoreUpdateResults.d.ts +1 -1
  384. package/dist/components/stream/renderers/pointCanvasRenderer.d.ts +4 -0
  385. package/dist/components/stream/renderers/resolveCSSColor.d.ts +4 -4
  386. package/dist/components/stream/resolveXYAxes.d.ts +13 -0
  387. package/dist/components/stream/sceneToSVGShared.d.ts +2 -1
  388. package/dist/components/stream/seriesGeometry.d.ts +13 -0
  389. package/dist/components/stream/streamEncodingTypes.d.ts +53 -0
  390. package/dist/components/stream/types.d.ts +12 -54
  391. package/dist/components/stream/useEnsureCustomXYRenderers.d.ts +18 -0
  392. package/dist/components/stream/useGeoFrameHandle.d.ts +16 -0
  393. package/dist/components/stream/useMarginalValues.d.ts +13 -0
  394. package/dist/components/stream/useOrdinalFrameHandle.d.ts +15 -0
  395. package/dist/components/stream/useXYFrameHandle.d.ts +15 -0
  396. package/dist/components/stream/xyAxisTicks.d.ts +25 -0
  397. package/dist/components/stream/xyCanvasRenderers.d.ts +4 -4
  398. package/dist/components/stream/xyDateTicks.d.ts +3 -2
  399. package/dist/components/stream/xyFrameAxisTypes.d.ts +2 -0
  400. package/dist/components/stream/xyPlugins/areaPlugin.d.ts +2 -0
  401. package/dist/components/stream/xyPlugins/barPlugin.d.ts +2 -0
  402. package/dist/components/stream/xyPlugins/candlestickPlugin.d.ts +2 -0
  403. package/dist/components/stream/xyPlugins/customPlugin.d.ts +6 -0
  404. package/dist/components/stream/xyPlugins/heatmapPlugin.d.ts +2 -0
  405. package/dist/components/stream/xyPlugins/lineFamily.d.ts +5 -0
  406. package/dist/components/stream/xyPlugins/linePlugin.d.ts +2 -0
  407. package/dist/components/stream/xyPlugins/missingPlugin.d.ts +7 -0
  408. package/dist/components/stream/xyPlugins/mixedPlugin.d.ts +2 -0
  409. package/dist/components/stream/xyPlugins/pointPlugin.d.ts +3 -0
  410. package/dist/components/stream/xyPlugins/registerBuiltIn.d.ts +1 -0
  411. package/dist/components/stream/xyPlugins/registry.d.ts +31 -0
  412. package/dist/components/stream/xyPlugins/stackedAreaPlugin.d.ts +2 -0
  413. package/dist/components/stream/xyPlugins/swarmPlugin.d.ts +2 -0
  414. package/dist/components/stream/xyPlugins/waterfallPlugin.d.ts +2 -0
  415. package/dist/components/stream/xySceneBuilders/ribbonScene.d.ts +1 -1
  416. package/dist/components/stream/xySceneBuilders/types.d.ts +1 -0
  417. package/dist/components/text/annotationTextLayout.d.ts +28 -0
  418. package/dist/components/text/pretextAnnotationLayout.d.ts +29 -0
  419. package/dist/components/text/usePretextAnnotations.d.ts +12 -0
  420. package/dist/controls.module.min.js +1 -1
  421. package/dist/forceLayoutWorker.js +1 -1
  422. package/dist/geo.min.js +1 -1
  423. package/dist/geo.module.min.js +1 -1
  424. package/dist/network.module.min.js +1 -1
  425. package/dist/ordinal.module.min.js +1 -1
  426. package/dist/physics-matter.min.js +1 -1
  427. package/dist/physics-matter.module.min.js +1 -1
  428. package/dist/physics-rapier.min.js +1 -1
  429. package/dist/physics-rapier.module.min.js +1 -1
  430. package/dist/physics.module.min.js +1 -1
  431. package/dist/physicsWorker.js +1 -1
  432. package/dist/processSankeyLayoutWorker.js +1 -1
  433. package/dist/rough.min.js +1 -1
  434. package/dist/rough.module.min.js +1 -1
  435. package/dist/semiotic-access.d.ts +9 -0
  436. package/dist/semiotic-access.min.js +2 -0
  437. package/dist/semiotic-access.module.min.js +2 -0
  438. package/dist/semiotic-ai-artifact-policy-constants.module.min.js +2 -0
  439. package/dist/semiotic-ai-core.d.ts +38 -18
  440. package/dist/semiotic-ai-core.min.js +1 -1
  441. package/dist/semiotic-ai-core.module.min.js +1 -1
  442. package/dist/semiotic-ai-hash-primitives.module.min.js +2 -0
  443. package/dist/semiotic-ai.d.ts +20 -20
  444. package/dist/semiotic-ai.module.min.js +1 -1
  445. package/dist/semiotic-artifact-react.d.ts +10 -0
  446. package/dist/semiotic-artifact-react.min.js +2 -0
  447. package/dist/semiotic-artifact-react.module.min.js +2 -0
  448. package/dist/semiotic-artifact.d.ts +23 -0
  449. package/dist/semiotic-artifact.min.js +1 -0
  450. package/dist/semiotic-artifact.module.min.js +1 -0
  451. package/dist/semiotic-client-cjs-shared.min.js +1 -1
  452. package/dist/semiotic-client-glyph.module.min.js +1 -1
  453. package/dist/semiotic-client-responsive.module.min.js +1 -1
  454. package/dist/semiotic-client-shared.module.min.js +1 -1
  455. package/dist/semiotic-custom-layout-selection-cjs-shared.min.js +1 -1
  456. package/dist/semiotic-data.min.js +1 -1
  457. package/dist/semiotic-data.module.min.js +1 -1
  458. package/dist/semiotic-evidence.d.ts +10 -0
  459. package/dist/semiotic-evidence.min.js +1 -0
  460. package/dist/semiotic-evidence.module.min.js +1 -0
  461. package/dist/semiotic-experimental-auxiliary.module.min.js +1 -1
  462. package/dist/semiotic-experimental-node-auxiliary.module.min.js +1 -1
  463. package/dist/semiotic-experimental-react-shared.module.min.js +1 -1
  464. package/dist/semiotic-experimental-vacp.min.js +1 -1
  465. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  466. package/dist/semiotic-experimental.d.ts +1 -1
  467. package/dist/semiotic-line.d.ts +9 -0
  468. package/dist/semiotic-line.min.js +2 -0
  469. package/dist/semiotic-line.module.min.js +2 -0
  470. package/dist/semiotic-network.d.ts +3 -0
  471. package/dist/semiotic-ordinal.d.ts +2 -0
  472. package/dist/semiotic-physics.d.ts +4 -4
  473. package/dist/semiotic-realtime-core.d.ts +3 -2
  474. package/dist/semiotic-realtime-core.module.min.js +1 -1
  475. package/dist/semiotic-realtime-react.module.min.js +1 -1
  476. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -1
  477. package/dist/semiotic-recipes-core.d.ts +6 -0
  478. package/dist/semiotic-recipes-core.module.min.js +1 -1
  479. package/dist/semiotic-recipes-geo-cjs.min.js +1 -1
  480. package/dist/semiotic-recipes-react.min.js +1 -1
  481. package/dist/semiotic-server-edge-node.module.min.js +1 -1
  482. package/dist/semiotic-server-edge.min.js +1 -1
  483. package/dist/semiotic-server-edge.module.min.js +1 -1
  484. package/dist/semiotic-server-node.min.js +1 -1
  485. package/dist/semiotic-server-node.module.min.js +1 -1
  486. package/dist/semiotic-text.d.ts +2 -0
  487. package/dist/semiotic-text.min.js +2 -0
  488. package/dist/semiotic-text.module.min.js +2 -0
  489. package/dist/semiotic-themes-core.d.ts +3 -0
  490. package/dist/semiotic-themes-core.min.js +1 -1
  491. package/dist/semiotic-themes-core.module.min.js +1 -1
  492. package/dist/semiotic-themes.min.js +1 -1
  493. package/dist/semiotic-themes.module.min.js +1 -1
  494. package/dist/semiotic-utils-core.d.ts +19 -14
  495. package/dist/semiotic-utils-core.min.js +1 -1
  496. package/dist/semiotic-utils-core.module.min.js +1 -1
  497. package/dist/semiotic-value.module.min.js +1 -1
  498. package/dist/semiotic-xy.d.ts +3 -0
  499. package/dist/semiotic.d.ts +11 -5
  500. package/dist/semiotic.module.min.js +1 -1
  501. package/dist/server.min.js +1 -1
  502. package/dist/server.module.min.js +1 -1
  503. package/dist/xy.module.min.js +1 -1
  504. package/package.json +91 -71
  505. package/spec/README.md +8 -3
  506. package/spec/v0.1/artifact-contract.schema.json +2299 -0
  507. package/spec/v0.1/examples/artifact-contract-full.json +369 -0
  508. package/spec/v0.1/examples/artifact-contract-unknown-state.json +46 -0
  509. package/dist/c-3BLJEQNG.min.js +0 -1
  510. package/dist/c-3KZD6AXJ.min.js +0 -1
  511. package/dist/c-4TWEX5HG.min.js +0 -1
  512. package/dist/c-52TEGIUJ.min.js +0 -1
  513. package/dist/c-5YCIX3VZ.min.js +0 -1
  514. package/dist/c-6FEKTA3U.min.js +0 -1
  515. package/dist/c-6O5EVOPH.min.js +0 -1
  516. package/dist/c-74HEEZGK.min.js +0 -1
  517. package/dist/c-AKAF6JAD.min.js +0 -1
  518. package/dist/c-BBKITSXB.min.js +0 -1
  519. package/dist/c-BWNB6USU.min.js +0 -1
  520. package/dist/c-C25ENHIK.min.js +0 -1
  521. package/dist/c-CDR5AO3R.min.js +0 -1
  522. package/dist/c-COHXCW3Q.min.js +0 -1
  523. package/dist/c-DADXPJXV.min.js +0 -1
  524. package/dist/c-E3JFRRMI.min.js +0 -1
  525. package/dist/c-EBFPQHHO.min.js +0 -1
  526. package/dist/c-G36WS6LN.min.js +0 -1
  527. package/dist/c-GGISSW5E.min.js +0 -1
  528. package/dist/c-GIKRQI4X.min.js +0 -1
  529. package/dist/c-GPYOFETM.min.js +0 -1
  530. package/dist/c-IDUHYYSI.min.js +0 -1
  531. package/dist/c-IUHFPMHD.min.js +0 -1
  532. package/dist/c-J5G56TUH.min.js +0 -1
  533. package/dist/c-JAZ73J32.min.js +0 -1
  534. package/dist/c-KG3NXHAL.min.js +0 -1
  535. package/dist/c-KII3PLZE.min.js +0 -1
  536. package/dist/c-LIXGXMNS.min.js +0 -1
  537. package/dist/c-LVEY6D6B.min.js +0 -1
  538. package/dist/c-M4Y3BHFR.min.js +0 -1
  539. package/dist/c-MAIICR2Z.min.js +0 -1
  540. package/dist/c-MG5DM6VE.min.js +0 -1
  541. package/dist/c-MNF2S4AA.min.js +0 -1
  542. package/dist/c-MT3WBK7M.min.js +0 -1
  543. package/dist/c-NY3JWV2K.min.js +0 -1
  544. package/dist/c-O6U6K4CW.min.js +0 -1
  545. package/dist/c-OQ7M4AGV.min.js +0 -1
  546. package/dist/c-OXYMVK7Q.min.js +0 -1
  547. package/dist/c-PPWDL5ZI.min.js +0 -1
  548. package/dist/c-QHF5YON3.min.js +0 -1
  549. package/dist/c-RR3GO5SW.min.js +0 -1
  550. package/dist/c-RSVIHIQ4.min.js +0 -1
  551. package/dist/c-S2BXNNJN.min.js +0 -1
  552. package/dist/c-S6U5CGT5.min.js +0 -1
  553. package/dist/c-SLGMUBUL.min.js +0 -1
  554. package/dist/c-SUILCHWU.min.js +0 -1
  555. package/dist/c-TZW3JGJ5.min.js +0 -1
  556. package/dist/c-US5ZFT6E.min.js +0 -1
  557. package/dist/c-USFMFKIH.min.js +0 -1
  558. package/dist/c-UUKVD4WB.min.js +0 -1
  559. package/dist/c-VGW3VG3I.min.js +0 -1
  560. package/dist/c-W3CE4A4S.min.js +0 -1
  561. package/dist/c-WJCD5EUY.min.js +0 -1
  562. package/dist/c-X5UBGU2V.min.js +0 -1
  563. package/dist/c-YDAY2WFR.min.js +0 -1
  564. package/dist/c-ZOWWU34K.min.js +0 -1
  565. /package/dist/{c-N4G2L7ID.min.js → c-HYW2XA4Q.min.js} +0 -0
  566. /package/dist/{c-OCI56QF2.min.js → c-V4XMSLC3.min.js} +0 -0
@@ -1 +1 @@
1
- import{PhysicsPipelineStore as t,SEQUENTIAL_INTERPOLATORS as e,UpdateResultTracker as o,absorbRegion as n,annotationLayout as i,bodyGroupSpec as r,capacitatedRegion as s,collidersFromPlotBounds as a,collidersFromXScaleBins as l,countPairwiseCrossings as c,forceFieldRegion as u,forceLayoutPlugin as d,getSequentialInterpolator as h,glyphFractionClipRect as p,glyphHitGeometry as f,glyphPlacement as g,groupCompletionRows as y,interpolateBrBG as m,interpolatePRGn as x,interpolatePiYG as b,interpolateRdBu as v,interpolateRdYlBu as w,interpolateRdYlGn as k,interpolateSpectral as A,interpolateViridis as S,isInBounds as M,makeSymbolResolver as _,orderByBarycenter as P,orderExactSmall as L,packBandsBySilhouette as $,placeWithMinGap as R,portalRegion as C,pressureFieldRegion as T,processChrome as O,processStageLayout as I,refineByAdjacentSwaps as z,resolveAnchoredPosition as F,resolveGlyphPaint as N,resolveX as E,resolveY as D,routeSurfaceRegion as W,schemeCategory10 as B,schemeSet3 as j,schemeTableau10 as Y,symbolPathString as X,symbolRadius as G,useCustomLayoutSelection as V,wrapWithDataHint as H}from"./c-LIXGXMNS.min.js";import{IncrementalExtent as q,RingBuffer as U,annotationStableId as K,coerceDateLikeValue as Z,composeStyleRules as Q,computeArcBoundingBox as J,darkenColor as tt,hatchPatternDef as et,isHatchFill as ot,isTimeLandmark as nt,lightenColor as it,makeNodeRuleContext as rt,makeRuleValueResolver as st,makeXYRuleContext as at,parseDateLikeString as lt,resolveAnnotationGradient as ct,resolveResponsiveRules as ut,resolveStyleRules as dt,resolveSvgFill as ht,styleRulesToNodeStyle as pt,sweepToAngles as ft}from"./c-4TWEX5HG.min.js";import"./c-SUILCHWU.min.js";import{filterAnnotationsByStatus as gt}from"./c-E3JFRRMI.min.js";import{accessorsEquivalent as yt,resolveAccessor as mt,resolveLabelFn as xt,resolveNodeRefId as bt,resolveRawAccessor as vt,resolveStringAccessor as wt}from"./c-MT3WBK7M.min.js";import{getMax as kt,getMin as At,getMinMax as St}from"./c-GGISSW5E.min.js";import"./c-COHXCW3Q.min.js";import{DARK_THEME as Mt,HIGH_CONTRAST_THEME as _t,LIGHT_THEME as Pt,applyThemeAccessibility as Lt,resolveThemePreset as $t,resolveThemeSemanticColors as Rt,themeToCSSVariables as Ct}from"./c-O6U6K4CW.min.js";var Tt={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function Ot(t,e={}){const o=e.mobileSemantics?.interaction,n="number"==typeof o?.targetSize?o.targetSize:"number"==typeof e.mobileSemantics?.minimumHitTarget?e.mobileSemantics.minimumHitTarget:void 0,i="mobile"===e.mode||"number"==typeof e.width&&480>=e.width,r=!!o||void 0!==n,s=t&&"object"==typeof t?t:void 0;if(!1===t||!1===s?.enabled||void 0===t&&!i&&!r)return Tt;const a=s??{};return{enabled:!0,tapToSelect:a.tapToSelect??!0,tapToLockTooltip:a.tapToLockTooltip??!0,clearSelection:a.clearSelection??"backgroundTap",targetSize:a.targetSize??n??44,snap:a.snap??"nearestDatum",brushHandleSize:a.brushHandleSize??44,standardControls:a.standardControls??!1}}var It={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function zt(t,e,o){if(!1!==e)return t;const n={...t};return"horizontal"===o?n.left=Math.min(n.left,15):n.bottom=Math.min(n.bottom,15),n}function Ft(t){return t instanceof Date?"date:"+t.getTime():`${typeof t}:${t+""}`}var Nt={kind:"rank-competition"};function Et(t,e,o,n){const i=t??e;return"function"==typeof i?i(o,n):o[i+""]}var Dt=Symbol.for("semiotic.semantic-viability"),Wt=globalThis,Bt=Wt[Dt]??(Wt[Dt]=new Map);function jt(t){return"string"==typeof t?.code&&t.code.length>0&&("warning"===t.severity||"error"===t.severity)&&"string"==typeof t.message&&t.message.length>0}function Yt(t,e,o){if(t.semanticDiagnostics=[],t.semanticStatus="not-assessed",t.empty)return;const n=function(t){return function(t){return Bt.has(t)}(t)?function(t){return Bt.get(t)}(t):"BumpChart"===t?Nt:void 0}(e);if(!n)return;let i;try{const e="function"==typeof n?n(o,t):function(t){const e=new Map;(Array.isArray(t.data)?t.data:[]).forEach((o,n)=>{if(!Number.isFinite(Number(Et(t.yAccessor,"y",o,n))))return;const i=Ft(Et(t.xAccessor,"x",o,n)),r=e.get(i)??new Set;r.add(Et(t.lineBy,"series",o,n)+""),e.set(i,r)});const o=Array.from(e.values(),t=>t.size).sort((t,e)=>t-e);if(0===o.length)return[];const n=Math.floor(o.length/2),i={columns:o.length,median:o.length%2?o[n]:(o[n-1]+o[n])/2,max:o[o.length-1],contestedColumns:o.filter(t=>t>=2).length},r=2>i.max;return r||2>i.contestedColumns||2>i.median?[{code:r?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:r?"error":"warning",message:r?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...i}}]:[]}(o);i=Array.from(e).filter(jt)}catch{return void(t.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||t.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}t.semanticDiagnostics=i,t.semanticStatus=i.some(t=>"error"===t.severity)?"degenerate":i.some(t=>"warning"===t.severity)?"degraded":"meaningful";for(const e of i)t.warnings.includes(e.code)||t.warnings.push(e.code)}import*as Xt from"react-dom/server.browser";import*as Gt from"react";var Vt=Object.freeze([]);function Ht(t){if(!t)return Vt;let e=!1;for(let o=0;t.length>o;o++){const n=t[o];if(null==n||"object"!=typeof n){e=!0;break}}if(!e)return t;const o=[];for(const e of t)null!=e&&"object"==typeof e&&o.push(e);return o}import{scaleOrdinal as qt}from"d3-scale";var Ut={category10:B,tableau10:Y,set3:j,...e},Kt=B,Zt="#007bff";function Qt(t,e,o=Kt){if(t&&"object"==typeof t&&!Array.isArray(t)){const e=Object.values(t).filter(t=>"string"==typeof t&&t.length>0);if(e.length>0)return e}if(Array.isArray(t)&&t.length>0)return t;if("string"==typeof t){const e=Object.prototype.hasOwnProperty.call(Ut,t)?Ut[t]:void 0;if(Array.isArray(e)&&e.length>0)return e}return e&&e.length>0?e:o}var Jt=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],te=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],ee=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function oe(t,e,o){if("function"==typeof e){const n=e(t);return o&&n&&"string"==typeof n&&!function(t){const e=t.toLowerCase();return e.startsWith("#")||e.startsWith("rgb")||e.startsWith("hsl")||ee.has(e)}(n)?o(n):n}const n=t?.[e]+"";return o?o(n):Kt[Math.abs(function(t){let e=0;for(let o=0;t.length>o;o++)e=(e<<5)-e+t.charCodeAt(o),e&=e;return Math.abs(e)}(n))%Kt.length]}function ne(t,e){if(null==e||!Object.prototype.hasOwnProperty.call(t,e))return;const o=t[e];return"string"==typeof o&&o.length>0?o:void 0}function ie(t,e,o="category10"){if(o&&"object"==typeof o&&!Array.isArray(o)){const t=o;return e=>ne(t,e)??"#999"}const n=Array.from(new Set(t.map(t=>t?.[e]).filter(t=>null!=t).map(t=>t+""))),i=n.every(t=>!isNaN(Number(t)));if(Array.isArray(o))return qt().domain(n).range(o).unknown("#999");const r=Object.prototype.hasOwnProperty.call(Ut,o)?Ut[o]:Ut.category10;if(i&&"function"==typeof r){let t=-1/0;for(const e of n){const o=Number(e);o>t&&(t=o)}return e=>r(Number(e)/t)}{const t=Array.isArray(r)?r:Kt;return qt().domain(n).range(t).unknown("#999")}}function re(t,e,o=[3,20],n){let i;if(i="function"==typeof e?e(t):t?.[e],!n)return i;const[r,s]=n,[a,l]=o;if(s===r)return(a+l)/2;let c=(i-r)/(s-r);return 0>c?c=0:c>1&&(c=1),a+c*(l-a)}function se(t){return void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity}function ae(t,e){if(!se(e))return t??((...t)=>({}));const o={};return void 0!==e.stroke&&(o.stroke=e.stroke),void 0!==e.strokeWidth&&(o.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(o.opacity=e.opacity),t?(...e)=>({...t(...e)||{},...o}):(...t)=>({...o})}var le={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function ce(t,e=le){if(t)return!0===t?e:"stops"in t?Array.isArray(t.stops)?t:void 0:"colorStops"in t?Array.isArray(t.colorStops)?{stops:t.colorStops.map(({offset:t,color:e})=>({offset:t,color:e}))}:void 0:{stops:[{offset:0,opacity:t.topOpacity??e.stops[0]?.opacity??.8},{offset:1,opacity:t.bottomOpacity??e.stops.at(-1)?.opacity??.05}]}}function ue(t){return t?ce(t):void 0}function de(t,e,o){return"function"==typeof t?t(o):o[t||e]}function he(t){return t instanceof Date?t.getTime():Number(t)}function pe(t,e){return S(1===e?.5:t/(e-1))}function fe(t){const e={};return void 0!==t.stroke&&(e.stroke=t.stroke),void 0!==t.strokeWidth&&(e.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(e.opacity=t.opacity),e}function ge(t,e){const o=function(t){if(!t)return;const e="boolean"==typeof t?{}:"string"==typeof t?{method:t}:t;return{type:"trend",method:e.method??"linear",...null!=e.bandwidth&&{bandwidth:e.bandwidth},...null!=e.order&&{order:e.order},...null!=e.color&&{color:e.color},...null!=e.strokeWidth&&{strokeWidth:e.strokeWidth},...null!=e.strokeDasharray&&{strokeDasharray:e.strokeDasharray},...null!=e.label&&{label:e.label}}}(e),n=Array.isArray(t)?t:void 0;return o?[o,...n??[]]:n}function ye(t){if(!t)return Pt;if("string"==typeof t){if("light"===t)return Pt;if("dark"===t)return Mt;if("high-contrast"===t)return _t;return $t(t)||Pt}const e="dark"===t.mode?Mt:Pt,o={...e,...t,colors:{...e.colors,...t.colors||{}},typography:{...e.typography,...t.typography||{}},tooltip:{...e.tooltip,...t.tooltip||{}}};return Lt(o)}function me(t){return{background:t.colors.background,text:t.colors.text,textSecondary:t.colors.textSecondary,grid:t.colors.grid,border:t.colors.border,primary:t.colors.primary,fontFamily:t.typography.fontFamily,titleSize:t.typography.titleSize,labelSize:t.typography.labelSize,tickSize:t.typography.tickSize,categorical:t.colors.categorical,annotation:t.colors.annotation??t.colors.text,legendSize:t.typography.legendSize??t.typography.labelSize,legendFontFamily:t.typography.legendFontFamily??t.typography.fontFamily,legendFontWeight:t.typography.legendFontWeight,titleFontSize:t.typography.titleFontSize??t.typography.titleSize,titleFontFamily:t.typography.titleFontFamily??t.typography.fontFamily,titleFontWeight:t.typography.titleFontWeight??"bold",tickFontFamily:t.typography.tickFontFamily??t.typography.fontFamily}}function xe(t,e,o){const n="function"==typeof e?e(t):t[e??o];if(null==n)return null;if(n instanceof Date)return n.getTime();if("string"==typeof n&&""===n.trim())return null;const i=Number(n);return Number.isFinite(i)?i:null}function be(t){return Math.round(100*t)/100}function ve(t,e=2){const o=[],n=[],i=e+1;for(let e=0;i>e;e++){let r=0;for(const[o,n]of t)null!==n&&(r+=o**e*n);o.push(r);const s=[];for(let o=0;i>o;o++){let n=0;for(const[i,r]of t)null!==r&&(n+=i**(e+o));s.push(n)}n.push(s)}n.push(o);const r=function(t,e){const o=t,n=t.length-1,i=[e];for(let t=0;n>t;t++){let e=t;for(let i=t+1;n>i;i++)Math.abs(o[t][i])>Math.abs(o[t][e])&&(e=i);for(let i=t;n+1>i;i++){const n=o[i][t];o[i][t]=o[i][e],o[i][e]=n}for(let e=t+1;n>e;e++)for(let i=n;i>=t;i--)o[i][e]-=o[i][t]*o[t][e]/o[t][t]}for(let t=n-1;t>=0;t--){let e=0;for(let r=t+1;n>r;r++)e+=o[r][t]*i[r];i[t]=(o[n][t]-e)/o[t][t]}return i}(n,i).map(be);return{points:t.map(([t])=>[be(t),be(r.reduce((e,o,n)=>e+o*t**n,0))]),equation:[...r].reverse()}}function we(t){const e=t.length;let o=0,n=0,i=0,r=0;for(const[e,s]of t)o+=e,n+=s,i+=e*e,r+=e*s;const s=e*i-o*o;if(1e-12>Math.abs(s))return null;const a=(e*r-o*n)/s,l=(n-a*o)/e;return t=>l+a*t}function ke(t,e){const o=t.length,n=t.map(([t,o])=>o-e(t)).reduce((t,e)=>t+e*e,0),i=Math.sqrt(n/Math.max(o-2,1)),r=t.reduce((t,e)=>t+e[0],0)/o,s=t.reduce((t,e)=>t+(e[0]-r)**2,0);return{se:i,meanX:r,ssX:s}}function Ae(t){return.99>t?.95>t?.9>t?1:1.645:1.96:2.576}var Se="__forecastSegment",Me="__forecastOpacity";function _e(t,e,o,n){const i=e.uncertaintyOpacity,r=e.confidenceAccessor;if(!i&&!r)return;const s="object"==typeof i?i:{},a=s.min??.15,l=s.max??1;if(r){const e="function"==typeof r?r:t=>t[r];for(const o of t){const t=e(o);null!=t&&Number.isFinite(t)&&(o[Me]=a+Math.max(0,Math.min(1,t))*(l-a))}return}const c=t.map(t=>{const e=o(t),i=n(t);return null!=e&&null!=i&&Number.isFinite(e)&&Number.isFinite(i)?Math.abs(e-i):NaN}),u=c.filter(t=>Number.isFinite(t));if(0===u.length)return;const[d,h]=St(u),p=h-d;t.forEach((t,e)=>{const o=c[e];Number.isFinite(o)&&(t[Me]=l-(p>0?(o-d)/p:0)*(l-a))})}function Pe(t,e){return"function"==typeof e?e(t):!!t[e]}var Le="__semiotic_resolvedX",$e="__semiotic_resolvedY",Re="__compoundGroup";function Ce(t,e,o){const n=t[e],i=t[o];return null==n||null==i||Number.isNaN(n)||Number.isNaN(i)}function Te(t){const e=t.xAccessor||"x",o=t.yAccessor||"y",n=t.lineBy,i=t.colorBy||n;let r=Array.isArray(t.data)?Ht(t.data).filter(t=>!!t&&"object"==typeof t):[];const s=function(t,e,o){const n="function"==typeof e,i="function"==typeof o,r=n?Le:e,s=i?$e:o;return n||i?{xKey:r,yKey:s,rows:t.map(t=>{const r={...t};return n&&(r[Le]=e(t)),i&&(r[$e]=o(t)),r})}:{rows:t,xKey:r,yKey:s}}(r,e,o);r=s.rows;const a=s.xKey,l=s.yKey,c=Array.isArray(t.annotations)?[...t.annotations]:[];let u,d="string"==typeof n||"function"==typeof n?n:void 0,h=t.baseLineStyle;if(t.forecast){const e=function(t,e,o,n,i){return(r=n).isTraining||r.isForecast||r.isAnomaly||r.upperBounds||r.lowerBounds?function(t,e,o,n,i){const{isTraining:r,isForecast:s,isAnomaly:a,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:p=6,label:f}=n,g=t.map(t=>{let e="observed";return s&&Pe(t,s)?e="forecast":r&&Pe(t,r)&&(e="training"),{...t,[Se]:e}}),y=n._groupBy,m=[];if(y){const t=new Map;for(const e of g){const o=e[y]??"__default";t.has(o)||t.set(o,[]),t.get(o).push(e)}const e=[];for(const[,o]of t)for(let t=0;o.length-1>t;t++)o[t][Se]!==o[t+1][Se]&&(e.push({...o[t+1],[Se]:o[t][Se]}),e.push({...o[t],[Se]:o[t+1][Se]}));m.push(...g,...e)}else for(let t=0;g.length>t;t++)m.push(g[t]),g.length-1>t&&g[t][Se]!==g[t+1][Se]&&(m.push({...g[t+1],[Se]:g[t][Se]}),m.push({...g[t],[Se]:g[t+1][Se]}));if(n.trainUnderline){const t=[];for(const e of m)"training"===e[Se]&&t.push({...e,[Se]:"training-base"});m.unshift(...t)}const x=[];if(l&&c){const t="string"==typeof l?l:"__envUpper",e="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(const o of m)"function"==typeof l&&(o[t]=l(o)),"function"==typeof c&&(o[e]=c(o));x.push({type:"envelope",upperAccessor:t,lowerAccessor:e,fill:u,fillOpacity:d,label:f})}if(n.uncertaintyOpacity||n.confidenceAccessor){const t=l?"function"==typeof l?l:t=>t[l]:()=>{},e=c?"function"==typeof c?c:t=>t[c]:()=>{};_e(m.filter(t=>"forecast"===t[Se]),n,t,e)}if(a){const t=n.anomalyStyle,e={type:"highlight",filter:t=>Pe(t,a)};t?(e.style=t,e.r=p):"function"==typeof h?(e.style=t=>{const e=h(t);return{stroke:e,strokeWidth:1.5,fill:e,fillOpacity:.7}},e.r=p):(e.color=h,e.r=p,e.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(e)}return i&&x.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label}),{processedData:m,annotations:x}}(t,0,0,n,i):function(t,e,o,n,i){const{trainEnd:r,steps:s=10,confidence:a=.95,color:l="#6366f1",bandOpacity:c=.15,label:u}=n;if(null==r)return{processedData:t,annotations:[]};const d=[],h=[];for(const o of t)o[e]>r?h.push({...o,[Se]:"observed"}):d.push({...o,[Se]:"training"});const p=d.map(t=>[t[e],t[o]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]),f=[],g=[];if(p.length>=3){const i=p.length,r=we(p);if(r){const{se:d,meanX:h,ssX:y}=ke(p,r),m=Ae(a),x=t.map(t=>t[e]).filter(t=>null!=t&&isFinite(t)),b=kt(x),v=p.length>1?(p[i-1][0]-p[0][0])/(i-1):1;for(let t=1;s>=t;t++){const n=b+t*v,s=r(n),a=d*Math.sqrt(1+1/i+(y>0?(n-h)**2/y:0))*m;g.push({[e]:n,[o]:s,[Se]:"forecast",__forecastUpper:s+a,__forecastLower:s-a})}_e(g,n,t=>t.__forecastUpper,t=>t.__forecastLower),f.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:l,fillOpacity:c,label:u})}}f.push({type:"x-threshold",x:r,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),i&&f.push({type:"anomaly-band",threshold:i.threshold??2,showBand:!1!==i.showBand,fill:i.bandColor||"#6366f1",fillOpacity:i.bandOpacity??.1,anomalyColor:i.anomalyColor||"#ef4444",anomalyRadius:i.anomalyRadius??6,label:i.label});const y=[];if(y.push(...d),d.length>0&&h.length>0&&y.push({...d[d.length-1],[Se]:"observed"}),y.push(...h),g.length>0){const t=h.length>0?h[h.length-1]:d[d.length-1];t&&y.push({...t,[Se]:"forecast"}),y.push(...g)}return{processedData:y,annotations:f}}(t,e,o,n,i);var r}(r,a,l,n&&"string"==typeof n&&"object"==typeof t.forecast?{...t.forecast,_groupBy:n}:t.forecast,t.anomaly);if(r=e.processedData,c.push(...e.annotations),u=function(t,e,o){const n=o.upperBounds,i=o.lowerBounds;if(!n&&!i)return;const r="function"==typeof n?n:"string"==typeof n?t=>t[n]:null,s="function"==typeof i?i:"string"==typeof i?t=>t[i]:null;let a=1/0,l=-1/0;for(const o of t){const t=Number(o[e]);if(Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t)),r){const t=r(o);null!=t&&Number.isFinite(t)&&(t>l&&(l=t),a>t&&(a=t))}if(s){const t=s(o);null!=t&&Number.isFinite(t)&&(a>t&&(a=t),t>l&&(l=t))}}return Number.isFinite(a)&&Number.isFinite(l)?[a,l]:void 0}(r,l,t.forecast),n&&"string"==typeof n?(r=r.map(t=>({...t,[Re]:`${t[n]}__${t[Se]||"observed"}`})),d=Re):d=Se,t.baseLineStyle){const e=function(e,o){const n=o.trainDasharray??"8,4",i=o.forecastDasharray??"4,4",r=o.color||"#6366f1",s=o.trainOpacity,a=o.forecastOpacity,l=o.trainStroke,c=o.trainLinecap,u=o.trainUnderline;return e=>{const o=(e=>t.baseLineStyle(e))(e),d=e[Se];if("training"===d){let t=o.stroke;return"darken"===l?t=tt(o.stroke||"#666",.5):l&&(t=l),{...o,stroke:t,strokeDasharray:n,...c&&{strokeLinecap:c},...null!=s&&{strokeOpacity:s}}}if("training-base"===d){let t=o.stroke||"#666";return"lighten"===u&&(t=it(t,.4)),{...o,stroke:t,strokeDasharray:void 0}}if("forecast"===d){const t=e[Me],n=null!=t?t:a;return{...o,stroke:r,strokeDasharray:i,...null!=n&&{strokeOpacity:n}}}return o}}(0,t.forecast);h=t=>e(t)}}else t.anomaly&&c.push(...(p=t.anomaly,[{type:"anomaly-band",threshold:p.threshold??2,showBand:!1!==p.showBand,fill:p.bandColor||"#6366f1",fillOpacity:p.bandOpacity??.1,anomalyColor:p.anomalyColor||"#ef4444",anomalyRadius:p.anomalyRadius??6,label:p.label}]));var p;if(t.gapStrategy){if("function"==typeof d){const t=d;r=r.map(e=>({...e,__semiotic_gapGroup:t(e)})),d="__semiotic_gapGroup"}const e=function(t,e,o,n,i){const r=new Map;for(const e of t){const t=i?(e[i]??"")+"":"__single";r.has(t)||r.set(t,[]),r.get(t).push(e)}if("interpolate"===e){const t=[];for(const[,e]of r)for(const i of e)Ce(i,o,n)||t.push(i);return{rows:t,groupKey:i}}if("zero"===e){const t=[];for(const[,e]of r)for(const i of e)Ce(i,o,n)?t.push({...i,[n]:0}):t.push(i);return{rows:t,groupKey:i}}const s=[],a="_gapSegment";for(const[t,e]of r){let i=0,r=[];const l=()=>{if(0===r.length)return;const e="__single"===t?"__seg"+i:`${t}__seg${i}`;for(const t of r)s.push({...t,[a]:e});r=[],i++};for(const t of e)Ce(t,o,n)?l():r.push(t);l()}return{rows:s,groupKey:a}}(r,t.gapStrategy,a,l,"string"==typeof d?d:void 0);r=e.rows,e.groupKey&&(d=e.groupKey)}let f;if(t.directLabel){const e=function(t,e,o,n,i,r,s,a){if(!e||!o)return{annotations:[]};const l="object"==typeof e?e:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof o?o:t=>t[o],h=new Map;for(const e of t){const t=d(e);if(null==t)continue;const o=t+"";""!==o&&(h.has(o)||h.set(o,[]),h.get(o).push(e))}const p=new Map;for(const[t,e]of h)e.sort((t,e)=>Number(t[n])-Number(e[n])),p.set(t,"end"===c?e[e.length-1]:e[0]);const f=ie(Array.from(p.entries()).map(([t])=>({__lbl:t})),"__lbl",r??s),g=Array.from(p.entries()).map(([t,e])=>({type:"text",label:t,[n]:e[n],[i]:e[i],dx:"end"===c?6:-6,dy:0,color:f?oe({__lbl:t},"__lbl",f):a||Zt,fontSize:u}));g.sort((t,e)=>Number(t[i])-Number(e[i]));for(let t=1;g.length>t;t++){const e=g[t-1],o=g[t],n=Number(e[i])+e.dy;u+2>Math.abs(Number(o[i])+o.dy-n)&&(o.dy+=u+2)}const y=g.reduce((t,e)=>Math.max(t,(e.label+"").length*(.6*u)),0)+10;return{annotations:g,marginExtra:"end"===c?{right:y}:{left:y}}}(r,t.directLabel,"string"==typeof i||"function"==typeof i?i:void 0,a,l,t.colorScheme,t.themeCategorical,t.color);c.push(...e.annotations),f=e.marginExtra}return{data:r,xAccessor:"function"==typeof e?a:e,yAccessor:"function"==typeof o?l:o,groupAccessor:d,colorAccessor:i,annotations:c,lineStyle:h,yExtent:u,marginExtra:f}}function Oe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrScatterColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrScatterColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[3,15],p=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],f=p.length?St(p):void 0,g=at(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,fillOpacity:"number"==typeof i.pointOpacity?i.pointOpacity:.8,r:d?re(t,d,h,f):"number"==typeof i.pointRadius?i.pointRadius:5};return y?.length&&Object.assign(o,dt(t,y,g(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}var Ie={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Te({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),s=ge(r.annotations,i.regression);return{chartType:"scatter",data:r.data,xAccessor:r.xAccessor,yAccessor:r.yAccessor,colorAccessor:e,sizeAccessor:i.sizeBy,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,...s&&s.length>0&&{annotations:s},...r.yExtent&&!n.yExtent&&{yExtent:r.yExtent},sizeRange:i.sizeRange||[3,15],pointStyle:n.pointStyle||Oe(t,e,o,n,i),showLegend:n.showLegend??!!e}}},ze={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=ge(n.annotations,i.regression);return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[5,40],colorScheme:o,...n,...r&&{annotations:r},pointStyle:n.pointStyle||Fe(t,e,o,n,i),showLegend:n.showLegend??!!e}}};function Fe(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrBubbleColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrBubbleColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=i.sizeBy,h=Array.isArray(i.sizeRange)?i.sizeRange:[5,40],p=d?r.map(t=>"function"==typeof d?d(t):Number(t[d])).filter(Number.isFinite):[],f=p.length?St(p):void 0,g=at(i.xAccessor,i.yAccessor),y=i.styleRules;return t=>{const o={fill:e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,fillOpacity:"number"==typeof i.bubbleOpacity?i.bubbleOpacity:.6,r:d?re(t,d,h,f):h[0],stroke:i.bubbleStrokeColor??"white",strokeWidth:i.bubbleStrokeWidth??1};return y?.length&&Object.assign(o,dt(t,y,g(t))),void 0!==i.stroke&&(o.stroke=i.stroke),void 0!==i.strokeWidth&&(o.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(o.opacity=i.opacity),o}}import{useMemo as Ne,useCallback as Ee,useState as De,useId as We,useEffect as Be,useRef as je}from"react";function Ye(...t){let e;for(const o of t)o&&(e=Xe(e)&&Xe(o)?{legendGroups:[...e.legendGroups,...o.legendGroups],legendDistance:o.legendDistance??e.legendDistance}:o);return e}function Xe(t){return"object"==typeof t&&null!==t&&"legendGroups"in t&&Array.isArray(t.legendGroups)}function Ge(t){return"object"==typeof t&&null!==t&&"gradient"in t}function Ve(t){return"string"==typeof t&&t.length>0}function He(t,e,o=!1){const n=o?e?58:34:e?36:0;return n>t.top?{...t,top:n}:t}function qe(t,e){return He(t,Ve(e))}function Ue(t,e,o,n,i=8){const r=n,s="left"===n?"right":"right"===n?"left":"top"===n?"bottom":"top",a=Math.max(e[r],Math.max(0,("left"===n||"right"===n?o[0]:o[1])-i)-t[s]);t[r]>a&&(t[r]=a)}function Ke(t){return Math.ceil(7*t.length)}function Ze(t,e){if(Xe(t)){const o=lo(e),n=t.legendGroups.flatMap(t=>[t.label?Ke(t.label):0,...t.items.map(t=>o.swatchSize+o.labelGap+Ke(t.label))]);return Math.max(100,...n)}if(Ge(t)){const{gradient:e}=t,o=e.format||(t=>Math.round(100*t)/100+""),n=Math.max(Ke(o(e.domain[0])),Ke(o(e.domain[1]))),i=e.label?Ke(e.label):0;return Math.max(100,19+n,i)}return 100}function Qe(t){return(Xe(t)||Ge(t))&&Number.isFinite(t.legendDistance)?Math.max(0,t.legendDistance):10}function Je(t,e){return null!=t?.sideGutter?Math.max(0,t.sideGutter):e?.hasAxis?e.hasAxisLabel?oo:eo:0}function to(t){return Math.max(0,t?.edgeGutter??3)}var eo=34,oo=70;function no(t,e){return null!=e?.axisGutter?Math.max(0,e.axisGutter):t?.hasAxis?t.hasAxisLabel?t.rotatedTicks?64:46:22:0}function io(t,e,o){if(Ge(t))return t.gradient.label?46:26;if(!Xe(t))return 20;const n=lo(o),i=Math.max(1,o?.maxWidth??e);let r=n.rowHeight;for(const e of t.legendGroups){let t=0,o=0;for(const r of e.items){const e=n.swatchSize+n.labelGap+Ke(r.label),s=0===o?e:o+n.itemGap+e;o>0&&s>i?(t+=1,o=e):o=s}e.items.length>0&&(t+=1),r=Math.max(r,t*n.rowHeight,e.label?Ke(e.label):0)}return r+(t.legendGroups.length>1?16:0)}function ro(t,e,o){return Ze(t,e)+Qe(t)+Je(e,o)+to(e)}function so(t,e){const{legend:o}=e;if(!o)return;const n=e.position??"right",i=io(o,Math.max(1,e.size[0]-t.left-t.right),e.legendLayout)+Qe(o)+no("bottom"===n?e.axisChrome:"top"===n?e.axisChrome?.topAxis:void 0,e.legendLayout)+("top"===n&&e.hasTitle?24:0),r=Math.max(e.minimumMargin??0,"top"===n?e.hasTitle?58:34:0);"right"===n?t.right=Math.max(t.right,r,ro(o,e.legendLayout,e.axisChrome?.rightAxis)):"left"===n?t.left=Math.max(t.left,r,ro(o,e.legendLayout,e.axisChrome?.leftAxis)):"top"===n?t.top=Math.max(t.top,r,i):t.bottom=Math.max(t.bottom,r,i)}function ao(t,e){const o=e.position??"right",n="top"===o||"bottom"===o,i=Math.max(0,e.totalWidth-e.margin.left-e.margin.right),r=Math.max(1,n?e.legendLayout?.maxWidth??i:e.reservedWidth??Ze(t,e.legendLayout)),s=Qe(t),a=Je(e.legendLayout,"left"===o?e.axisChrome?.leftAxis:e.axisChrome?.rightAxis),l=to(e.legendLayout),c=io(t,i,e.legendLayout),u=no(e.axisChrome,e.legendLayout),d=no(e.axisChrome?.topAxis,e.legendLayout);if("left"===o)return{x:Math.max(l,e.margin.left-a-r-s),y:e.margin.top,width:r,height:c};if("top"===o)return{x:e.margin.left,y:e.margin.top-d-s-c,width:r,height:c};if("bottom"===o){const t=e.totalHeight-e.margin.bottom;return{x:e.margin.left,y:Math.max(t+s,Math.min(t+u+s,e.totalHeight-c)),width:r,height:c}}return{x:Math.min(e.totalWidth-r-l,e.totalWidth-e.margin.right+a+s),y:e.margin.top,width:r,height:c}}function lo(t){const e=Math.max(1,t?.swatchSize??16),o=Math.max(e,t?.rowHeight??22);return{swatchSize:e,labelGap:Math.max(0,t?.labelGap??6),itemGap:Math.max(0,t?.itemGap??10),rowHeight:o,align:"left"===t?.align?"start":"right"===t?.align?"end":t?.align??"start",maxWidth:t?.maxWidth}}function co(t,e){let o=24;return t.map(({hasLabel:t,itemCount:n})=>{o+=5;const i=o;let r;o+=8,t&&(o+=16,r=o,o+=8);const s=o;return o+=n*e+8,{lineY:i,labelY:r,itemsY:s,endY:o}})}function uo(t,e,o,n,i){if(t)return t;if(o&&"object"==typeof o&&!Array.isArray(o)){const t=ne(o,n);if(t)return t}let r;if(Array.isArray(o))r=o;else if(e&&e.length>0)r=e;else if("string"==typeof o){const t=Ut[o];Array.isArray(t)&&(r=t)}return r&&0!==r.length?null!=n?(i.has(n)||i.set(n,i.size),r[i.get(n)%r.length]):r[0]:Zt}function ho(t,e,o){return"function"==typeof t?t(e,o):e[t]}function po(t,e){if(!t?.length)return;const o=new Map(e.map((t,e)=>[Ft(t),e]));return t.map(t=>{const e={...t},n=n=>{if(!(n in t))return;const i=o.get(Ft(t[n]));void 0!==i&&(e[n]=i)};return n("x"),n("x0"),n("x1"),"string"!=typeof t.type||"x-threshold"!==t.type&&"x"!==t.type||n("value"),e})}function fo(t,e,o,n,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*o+i*i*i*n}function go(t,e,o,n,i){const r=1-i;return 3*r*r*(e-t)+6*r*i*(o-e)+3*i*i*(n-o)}function yo(t,e,o,n,i){const r=[],s=(t.x+e.x)/2;for(let a=0;i>=a;a++){const l=a/i;let c,u,d,h;"linear"===n?(c=t.x+(e.x-t.x)*l,u=t.y+(e.y-t.y)*l,d=e.x-t.x,h=e.y-t.y):(c=fo(t.x,s,s,e.x,l),u=fo(t.y,t.y,e.y,e.y,l),d=go(t.x,s,s,e.x,l),h=go(t.y,t.y,e.y,e.y,l)),r.push({x:c,y:u,dx:d,dy:h,radius:t.radius+(e.radius-t.radius)*l,datumIndex:.5>l?o:o+1})}return r}function mo(t,e={}){const o=[],n=[],i=[];if(2>t.length)return{topPath:o,bottomPath:n,datumIndices:i};const r=e.curve??"smooth",s=Math.max(2,Math.floor(e.samplesPerSegment??12));for(let e=0;t.length-1>e;e++){const a=yo(t[e],t[e+1],e,r,s);for(let t=0===e?0:1;a.length>t;t++){const e=a[t],r=Math.hypot(e.dx,e.dy)||1,s=-e.dy/r,l=e.dx/r,c=Math.max(0,e.radius);o.push([e.x+s*c,e.y+l*c]),n.push([e.x-s*c,e.y-l*c]),i.push(e.datumIndex)}}return{topPath:o,bottomPath:n,datumIndices:i}}import{jsx as xo}from"react/jsx-runtime";function bo({datum:t,x:e,y:o,side:n,color:i,highlighted:r,labelStyle:s}){const a=V(),l=a.isActive&&!a.predicate(t),c="function"==typeof s?s(t.__bumpRaw):s;return xo("text",{className:"semiotic-bump-label",x:e+("end"===n?8:-8),y:o,dy:"0.35em",textAnchor:"end"===n?"start":"end",fill:i,fillOpacity:l?.16:1,fontWeight:r?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...c},children:t.__bumpSeries})}function vo(t,e,o){const[n,i]=e,[r,s]=o;return i===n?(r+s)/2:r+(s-r)*Math.max(0,Math.min(1,(t-n)/(i-n)))}function wo(t){const e=t.__bumpXValue instanceof Date?t.__bumpXValue.getTime():Number(t.__bumpXValue);return{value:t.__bumpValue,x:Number.isFinite(e)?e:void 0,y:t.__bumpValue,category:t.__bumpSeries}}function ko(t){const e=t.config,o=new Map;for(const e of t.data){const t=o.get(e.__bumpSeries)??[];t.push(e),o.set(e.__bumpSeries,t)}const n=e.seriesOrder.filter(t=>o.has(t)).sort((t,n)=>(o.get(t)?.[0]?.__bumpHighlighted?1:0)-(o.get(n)?.[0]?.__bumpHighlighted?1:0)||e.seriesOrder.indexOf(t)-e.seriesOrder.indexOf(n)),i=[],r=[],s=[];for(const r of n){const n=(o.get(r)??[]).sort((t,e)=>t.x-e.x);if(2>n.length)continue;const a=n[0].__bumpHighlighted,l=(e.colorMap&&ne(e.colorMap,r))??t.resolveColor(n[0].__bumpSeries,n[0]),c=e.color??(a?l:e.neutralColor??t.theme.semantic.textSecondary??t.theme.semantic.border??l),u=n.map(o=>({x:t.scales.x(o.x),y:t.scales.y(o.y),radius:e.ribbon?vo(o.__bumpValue,e.valueExtent,e.ribbonSizeRange)/2:Math.max(.5,e.lineWidth/2)})),d=mo(u,{curve:e.curve,samplesPerSegment:e.samplesPerSegment}),h={fill:c,fillOpacity:1,opacity:a?e.ribbon?e.ribbonOpacity:e.lineOpacity:Math.min(e.ribbon?e.ribbonOpacity:e.lineOpacity,.58)};e.styleRules?.length&&Object.assign(h,dt(n[0].__bumpRaw,e.styleRules,wo(n[0]))),e.areaStyle&&Object.assign(h,e.areaStyle(n[0].__bumpRaw)??{}),void 0!==e.stroke&&(h.stroke=e.stroke),void 0!==e.strokeWidth&&(h.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(h.opacity=e.opacity),i.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:h,datum:d.datumIndices.map(t=>n[t]),accessibleDatum:n.map(t=>t.__bumpRaw),accessibility:{label:r+" ranking trajectory",tableFields:n.map(t=>t.__bumpRaw)},group:r,interactive:!0}),e.showPoints&&n.forEach((t,o)=>{const n={fill:c,stroke:"none",opacity:a?1:.75};e.styleRules?.length&&Object.assign(n,dt(t.__bumpRaw,e.styleRules,wo(t))),e.pointStyle&&Object.assign(n,e.pointStyle(t.__bumpRaw)??{}),void 0!==e.stroke&&(n.stroke=e.stroke),void 0!==e.strokeWidth&&(n.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(n.opacity=e.opacity),i.push({type:"point",x:u[o].x,y:u[o].y,r:n.r??e.pointRadius,style:n,datum:t,accessibleDatum:t.__bumpRaw,accessibility:{label:`${r}, rank ${t.__bumpRank}, value ${t.__bumpValue}`},pointId:`${r}:${t.x}`})});const p=!0===e.showLabels?"end":e.showLabels,f=(t,o,n)=>{const i=null==e.labelPriorityAccessor?void 0:"function"==typeof e.labelPriorityAccessor?e.labelPriorityAccessor(t.__bumpRaw):Number(t.__bumpRaw[e.labelPriorityAccessor]);s.push({id:`${r}\0${n}`,datum:t,x:u[o].x,y:u[o].y,side:n,rank:t.__bumpRank,highlighted:a,priority:Number.isFinite(i)?i:void 0,color:"string"==typeof h.fill?h.fill:c})};"start"!==p&&"both"!==p||f(n[0],0,"start"),"end"!==p&&"both"!==p&&"auto"!==p||f(n.at(-1),n.length-1,"end")}const a=function(t,e,o,n){const i=Math.max(1,Math.floor(e/18)),r="auto"===o?Number.isFinite(n)&&(n??0)>=0?Math.min(i,Math.floor(n)):i:1/0,s=t.map((t,e)=>({candidate:t,index:e})).sort((t,e)=>(e.candidate.priority??0)-(t.candidate.priority??0)||Number(e.candidate.highlighted)-Number(t.candidate.highlighted)||t.candidate.rank-e.candidate.rank||t.index-e.index),a=[];for(const{candidate:t}of s){if(a.length>=r)break;a.some(e=>e.side===t.side&&14>Math.abs(e.y-t.y))||a.push(t)}return new Set(a.map(t=>t.id))}(s,t.dimensions.plot.height,"auto"!==(!0===e.showLabels?"end":e.showLabels)||"auto",e.maxLabels);for(const t of s)a.has(t.id)&&r.push(xo(bo,{datum:t.datum,x:t.x,y:t.y,side:t.side,color:t.color,highlighted:t.highlighted,labelStyle:e.labelStyle},t.id));return{nodes:i,overlays:r.length?xo("g",{className:"semiotic-bump-labels",children:r}):void 0,restyle:(t,e)=>{const o=function(t){const e=Array.isArray(t.datum)?t.datum[0]:t.datum;return e&&"object"==typeof e&&"__bumpSeries"in e?e:void 0}(t);if(e?.isActive&&o&&!e.predicate(o))return{opacity:.14}}}}var Ao={frameType:"xy",layout:{margin:t=>({top:20,right:!1===t.showLabels?24:110,bottom:48,left:48})},buildProps:(t,e,o,n,i)=>{const r=function(t,e={}){const o=e.xAccessor??"x",n=e.yAccessor??"y",i=e.lineBy??"series",r=e.rankDirection??"descending",s=[],a=new Map,l=new Map,c=[],u=new Map;let d=1/0,h=-1/0;t.forEach((t,e)=>{const r=ho(o,t,e),p=Ft(r);let f=a.get(p);null==f&&(f=s.length,a.set(p,f),s.push(r),l.set(f,[]));const g=ho(i,t,e)+"";u.has(g)||(u.set(g,c.length),c.push(g));const y=Number(ho(n,t,e));Number.isFinite(y)&&(d=Math.min(d,y),h=Math.max(h,y),l.get(f)?.push({datum:t,inputIndex:e,series:g,value:y}))});const p=[],f=new Map,g=new Map;for(let t=0;s.length>t;t++){const e=l.get(t)??[];e.sort((t,e)=>("descending"===r?e.value-t.value:t.value-e.value)||(u.get(t.series)??0)-(u.get(e.series)??0)),e.forEach((e,o)=>{const n=o+1;p.push({datum:e.datum,xIndex:t,xValue:s[t],series:e.series,value:e.value,rank:n}),f.set(e.series,(f.get(e.series)??0)+n),g.set(e.series,(g.get(e.series)??0)+1)})}const y=c.length+1,m=[...c].sort((t,e)=>{const o=g.get(t)??0,n=g.get(e)??0;return((f.get(t)??0)+(s.length-o)*y)/Math.max(1,s.length)-((f.get(e)??0)+(s.length-n)*y)/Math.max(1,s.length)||(u.get(t)??0)-(u.get(e)??0)}),x=new Set(m.slice(0,null==e.highlightTop?m.length:Math.max(0,Math.floor(e.highlightTop))));return{data:p.map(t=>{const e=x.has(t.series);return{...t.datum,x:t.xIndex,y:t.rank,__bumpRaw:t.datum,__bumpSeries:t.series,__bumpColorGroup:e?t.series:"Other",__bumpValue:t.value,__bumpRank:t.rank,__bumpXValue:t.xValue,__bumpHighlighted:e}}),xValues:s,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],{xAccessor:i.xAccessor,yAccessor:i.yAccessor,lineBy:i.lineBy,rankDirection:i.rankDirection,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0}),s=Math.max(1,r.seriesOrder.length),a=ye(n.theme),l=function(t){const{seriesOrder:e,overallOrder:o,highlightTop:n,color:i,colorScheme:r,neutralColor:s,themeCategorical:a,themeNeutral:l}=t;if(null==n&&null==i)return r;const c=new Set(o.slice(0,null==n?o.length:Math.max(0,Math.floor(n)))),u=new Map,d={};for(const t of e)Object.defineProperty(d,t,{configurable:!0,enumerable:!0,writable:!0,value:i??(c.has(t)?uo(void 0,a,r,t,u):s??l??"#b8bec8")});return d}({seriesOrder:r.seriesOrder,overallOrder:r.overallOrder,highlightTop:"number"==typeof i.highlightTop?i.highlightTop:void 0,color:"string"==typeof i.color?i.color:void 0,colorScheme:o,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,themeCategorical:a.colors.categorical,themeNeutral:a.colors.textSecondary}),c={ribbon:!0===i.ribbon,curve:"linear"===i.curve?"linear":"smooth",samplesPerSegment:"number"==typeof i.samplesPerSegment?i.samplesPerSegment:12,ribbonSizeRange:Array.isArray(i.ribbonSizeRange)?i.ribbonSizeRange:[4,28],valueExtent:r.valueExtent,seriesOrder:r.seriesOrder,lineWidth:"number"==typeof i.lineWidth?i.lineWidth:3,ribbonOpacity:"number"==typeof i.ribbonOpacity?i.ribbonOpacity:.82,lineOpacity:"number"==typeof i.lineOpacity?i.lineOpacity:.9,neutralColor:"string"==typeof i.neutralColor?i.neutralColor:void 0,color:"string"==typeof i.color?i.color:void 0,colorMap:l&&"object"==typeof l&&!Array.isArray(l)?l:void 0,stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0,styleRules:i.styleRules,areaStyle:n.areaStyle,pointStyle:n.pointStyle,labelStyle:i.labelStyle,showPoints:!0===i.showPoints,pointRadius:"number"==typeof i.pointRadius?i.pointRadius:3,showLabels:i.showLabels??!0,labelPriorityAccessor:i.labelPriorityAccessor,maxLabels:"number"==typeof i.maxLabels?i.maxLabels:void 0},u=n.xFormat,d=(t,e)=>{if(0===r.xValues.length)return"";const o=r.xValues[Math.max(0,Math.min(r.xValues.length-1,Math.round(Number(t))))];return u?u(o,e):(o instanceof Date?o.toLocaleDateString():o)+""},h=r.xValues.map((t,e)=>e),p=Array.from({length:s},(t,e)=>e+1),f=n.axes??[{orient:"left",tickValues:p,tickFormat:t=>t+"",label:n.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:n.xLabel,tickAnchor:"edges"}];return{...n,chartType:"custom",data:r.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,r.xValues.length-1)],yExtent:[s+.5,.5],customLayout:ko,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:l,xFormat:d,axes:f,axisExtent:"exact",showAxes:n.showAxes??!0,showLegend:n.showLegend??!1,annotations:po(n.annotations,r.xValues)}}};function So(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrAreaColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrAreaColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=!1!==i.showLine,h="number"==typeof i.lineWidth?i.lineWidth:2,p="number"==typeof i.areaOpacity?i.areaOpacity:.7,f=st(i.yAccessor),g=i.styleRules;return(t,o)=>{const n=e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt,r={fill:n,fillOpacity:p,stroke:d?n:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(r,dt(t,g,{value:f(t),category:o})),void 0!==i.stroke&&(r.stroke=i.stroke),void 0!==i.strokeWidth&&(r.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(r.opacity=i.opacity),r}}function Mo(t,e,o,n,i){if(!i.showPoints)return;const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrPointColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrPointColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d="number"==typeof i.pointRadius?i.pointRadius:3;return t=>{const o=e&&u?oe(t,e,u):"string"==typeof i.color?i.color:Zt;return{r:d,fill:o,stroke:"none"}}}var _o={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.lineBy,s=i.fillArea,a=Array.isArray(s)?"mixed":s?"area":"line",l=ye(n.theme).colors.categorical,c=function(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=ye(n.theme).colors.categorical,a=o??n.colorScheme??s,l="string"==typeof e?e:"__ssrLineColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrLineColorBy:e(t)})):r,u=e?ie(c,l,a):void 0,d=at(i.xAccessor,i.yAccessor),h=function(t){const{lineWidth:e=2,colorBy:o,colorScale:n,color:i,resolveStroke:r,fillArea:s,areaOpacity:a=.3,styleRules:l,ruleContext:c}=t;return(t,u)=>{const d={strokeWidth:e},h=!0===s||Array.isArray(s)&&null!=u&&s.includes(u);let p;return r?p=r(t,u):o?n&&(p=oe(t,o,n)):p=i||Zt,void 0!==p&&(d.stroke=p,h&&(d.fill=p,d.fillOpacity=a)),l?.length&&Object.assign(d,dt(t,l,c?c(t,u):{value:void 0,category:u})),d}}({lineWidth:"number"==typeof i.lineWidth?i.lineWidth:2,colorBy:e,colorScale:u,color:"string"==typeof i.color?i.color:void 0,fillArea:i.fillArea,areaOpacity:"number"==typeof i.areaOpacity?i.areaOpacity:.3,styleRules:i.styleRules,ruleContext:d});return ae(h,{stroke:"string"==typeof i.stroke?i.stroke:void 0,strokeWidth:"number"==typeof i.strokeWidth?i.strokeWidth:void 0,opacity:"number"==typeof i.opacity?i.opacity:void 0})}(t,r,o,n,i),u=Te({data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.lineBy,colorBy:r,colorScheme:o,color:"string"==typeof i.color?i.color:void 0,forecast:i.forecast,anomaly:i.anomaly,gapStrategy:i.gapStrategy,directLabel:i.directLabel,annotations:n.annotations,themeCategorical:l,baseLineStyle:c}),d=n.pointStyle||Mo(u.data,u.colorAccessor,o,n,i);let h=n.margin;u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});const p=(!i.directLabel||void 0!==n.showLegend)&&(n.showLegend??!!u.colorAccessor);return{chartType:a,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:o,lineStyle:u.lineStyle||c,...Array.isArray(s)&&{areaGroups:s},...s&&null!=i.areaOpacity&&{areaOpacity:i.areaOpacity},...null!=i.band&&{band:i.band},...n,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!n.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:p}}},Po={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?Ht(t):[],s=i.timeAccessor||"time",a=i.valueAccessor||"value",l=i.categoryAccessor,c=i.valueExtent||n.yExtent,u="down"===i.direction?function({data:t,valueAccessor:e,timeAccessor:o,binSize:n,valueExtent:i,extentPadding:r}){if(i)return[i[1],i[0]];if(!t||0===t.length)return;const s=new Map;for(const i of t){const t=xe(i,o,"time"),r=xe(i,e,"value");if(null==t||null==r)continue;const a=Math.floor(t/n)*n;s.set(a,(s.get(a)??0)+r)}let a=0;for(const t of s.values())a=Math.max(a,t);return[a>0?a+a*(r??.1):1,0]}({data:r,timeAccessor:s,valueAccessor:a,binSize:Number(i.binSize),valueExtent:c,extentPadding:i.extentPadding}):c,d={...void 0!==i.fill&&{fill:i.fill},...void 0!==i.stroke&&{stroke:i.stroke},...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity},...void 0!==i.cursor&&{cursor:i.cursor},...void 0!==i.gap&&{gap:i.gap}};return{chartType:"bar",data:r,...n,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,r.length),arrowOfTime:i.arrowOfTime||"right",timeAccessor:s,valueAccessor:a,xExtent:i.timeExtent||n.xExtent,yExtent:u,extentPadding:i.extentPadding??n.extentPadding,binSize:i.binSize,categoryAccessor:l,barColors:i.colors||n.barColors,colorScheme:i.colors||n.colorScheme,barStyle:n.barStyle||d,showLegend:n.showLegend??!!l}}},Lo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s=Te({data:Array.isArray(t)?Ht(t):[],xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",lineBy:i.areaBy,forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),a=function({data:t,safeData:e,areaBy:o,lineDataAccessor:n}){if(null==t)return[];const i=void 0!==e[0]?.[n];if(!i&&!o)return e;let r;if(i)r=e;else{const t=e.reduce((t,e)=>{const i="function"==typeof o?o(e):e[o],r=i+"";if(!t[r]){const e={[n]:[]};"string"==typeof o&&(e[o]=i),t[r]=e}return t[r][n].push(e),t},{});r=Object.values(t)}return r.flatMap(t=>{const e=Array.isArray(t[n])?t[n]:[];return"string"==typeof o?e.map(e=>({...e,[o]:e[o]??t[o]})):e})}({data:t,safeData:s.data,areaBy:i.areaBy,lineDataAccessor:i.lineDataAccessor||"coordinates"}),l=function(t){if(t)return Array.isArray(t)?{stops:t.map(({at:t,color:e,opacity:o})=>({offset:t/100,color:e,...null!=o&&{opacity:o}}))}:Array.isArray(t.stops)?t:void 0}(i.semanticGradient),c=l?.stops.length?{stops:l.stops.map(t=>({...t,offset:1-t.offset})).sort((t,e)=>t.offset-e.offset)}:ce(n.gradientFill),u=!1!==i.semanticLine?function(t){const e=t?.stops.filter(t=>"string"==typeof t.color&&Number.isFinite(t.offset)).map(({offset:t,color:e,opacity:o})=>({offset:Math.max(0,Math.min(1,t)),color:e,...Number.isFinite(o)&&{opacity:Math.max(0,Math.min(1,o))}})).sort((t,e)=>t.offset-e.offset);if(!e?.length)return;const o=e[0];return o.offset>0?[{...o,offset:0},...e]:e}(l):void 0,d=n.pointStyle||Mo(a,r,o,n,i);return{chartType:"area",data:a,xAccessor:s.xAccessor,yAccessor:s.yAccessor,y0Accessor:i.y0Accessor,groupAccessor:i.areaBy||void 0,colorAccessor:r,colorScheme:o,...n,...s.annotations.length>0&&{annotations:s.annotations},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},...void 0!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:n.lineStyle||So(a,r,o,n,i),...d&&{pointStyle:d}}}},$o={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xAccessor||"x",s=i.seriesAAccessor||"a",a=i.seriesBAccessor||"b",l=t=>he(de(r,"x",t)),c=t=>he(de(s,"a",t)),u=t=>he(de(a,"b",t)),d=i.seriesAColor||"var(--semiotic-danger, #dc2626)",h=i.seriesBColor||"var(--semiotic-info, #2563eb)",p=i.areaOpacity??.6,f=i.lineWidth??1.5,g=!1!==i.showLines,y=!1!==n.showLegend,m=i.seriesALabel||"A",x=i.seriesBLabel||"B",b=n.legendPosition||"right",v=function(t,e,o,n){if(!t.length)return[];const i=t.filter(t=>Number.isFinite(e(t))).sort((t,o)=>e(t)-e(o)),r=[];let s=0,a=null,l=null,c=[];const u=(t,e)=>t>e?"A":e>t?"B":null,d=t=>`seg-${s}-${t}`,h=t=>r.push(t),p=(t,e)=>{h({__x:t.x,__y:t.y,__y0:t.y,__diffSegment:d(e),__diffWinner:e,__valA:t.y,__valB:t.y,__sourceDatum:t.datum})};for(let t=0;i.length>t;t++){const r=i[t],f=e(r),g=o(r),y=n(r);if(!Number.isFinite(f)||!Number.isFinite(g)||!Number.isFinite(y))continue;const m=u(g,y);if(null!==m)if(null!=a){if(l&&l.w!==m){let t,e;if(c.length>0)t=c[0].x,e=c[0].y;else{const o=g-l.a-(y-l.b);if(0!==o){const n=Math.max(0,Math.min(1,(l.b-l.a)/o));t=l.x+n*(f-l.x),e=l.a+n*(g-l.a)}else t=l.x,e=l.a}h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e}),s++,a=m,h({__x:t,__y:e,__y0:e,__diffSegment:d(a),__diffWinner:a,__valA:e,__valB:e});for(let t=1;c.length>t;t++)p(c[t],a)}else for(const t of c)p(t,a);c=[],h({__x:f,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:f,a:g,b:y,w:m}}else{a=m;for(const t of c)p(t,a);c=[],h({__x:f,__y:y>g?y:g,__y0:y>g?g:y,__diffSegment:d(a),__diffWinner:a,__valA:g,__valB:y,__sourceDatum:r}),l={x:f,a:g,b:y,w:m}}else c.push({x:f,y:g,datum:r})}for(const t of c)p(t,a??"A");return r}(Array.isArray(t)?t:[],l,c,u),w=[];if(g&&Array.isArray(t)){const e=t.filter(t=>Number.isFinite(l(t))).sort((t,e)=>l(t)-l(e));for(const t of e){const e=l(t),o=c(t),n=u(t);Number.isFinite(o)&&w.push({__x:e,__y:o,__diffSegment:"line-A"}),Number.isFinite(n)&&w.push({__x:e,__y:n,__diffSegment:"line-B"})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(t=>t.__diffSegment))),areaStyle:t=>{const e=t.__diffSegment;return{fill:"A"==(e?.endsWith("-A")?"A":"B")?d:h,stroke:"none",fillOpacity:p}},lineStyle:t=>({stroke:"A"==("line-A"===t.__diffSegment?"A":"B")?d:h,strokeWidth:f,fill:"none"}),curve:i.curve||"linear",...n,...y&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:t=>({fill:t.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},Ro={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=e||i.areaBy,s="string"==typeof r&&Array.isArray(t)?ie(t,r,o):void 0,a="number"==typeof i.areaOpacity?i.areaOpacity:.7,l=n.lineStyle||(t=>{const e=null==r?void 0:oe(t,r,s),o=i.showLine??!0,n={fill:i.color??e,stroke:o?i.stroke??e:"none",...o?{strokeWidth:i.strokeWidth??i.lineWidth??2}:{},fillOpacity:a,...null==i.opacity?{}:{opacity:i.opacity}},l=i.styleRules;if(l?.length){const e=st(i.yAccessor),o=r?"function"==typeof r?(r(t)??"")+"":(t[r]??"")+"":void 0;Object.assign(n,dt(t,l,{value:e(t),category:o}))}return n}),c=i.normalize?"zero":i.baseline??"zero",u=n.pointStyle||Mo(t,r,o,n,i);return{chartType:"stackedarea",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.areaBy,colorAccessor:r,colorScheme:o,normalize:i.normalize,baseline:c,stackOrder:i.stackOrder,lineStyle:l,...n,...u&&{pointStyle:u},curve:n.curve??i.curve??"monotoneX",showLegend:n.showLegend??!!r}}},Co={frameType:"xy",buildProps:(t,e,o,n,i)=>{const[r]=n.size??[600,400];return{chartType:"candlestick",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.highAccessor||"high",highAccessor:i.highAccessor||"high",lowAccessor:i.lowAccessor||"low",openAccessor:i.openAccessor,closeAccessor:i.closeAccessor,candlestickStyle:i.candlestickStyle,...n,scalePadding:n.scalePadding??Math.max(2,Math.min(12,Math.round(r/40))),extentPadding:n.extentPadding??(r>200?.1:.02)}}},To={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.xCenter,s=i.yCenter,a=i.quadrants,l=i.centerlineStyle||{},c=!1!==i.showQuadrantLabels,u=i.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,p=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,f=Gt.createElement,g=a?[(t,e,o)=>{if(!e?.x||!e?.y)return null;const n=o.width,i=o.height,l=null!=r?e.x(r):n/2,g=null!=s?e.y(s):i/2;if(null!=r&&!Number.isFinite(l))return null;if(null!=s&&!Number.isFinite(g))return null;const y=Math.max(0,Math.min(n,l)),m=Math.max(0,Math.min(i,g)),x=[{c:a.topLeft,x:0,y:0,w:y,h:m},{c:a.topRight,x:y,y:0,w:n-y,h:m},{c:a.bottomLeft,x:0,y:m,w:y,h:i-m},{c:a.bottomRight,x:y,y:m,w:n-y,h:i-m}],b=c?[f("text",{key:"ltl",x:8,y:8+u,fill:a.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.topLeft.label),f("text",{key:"ltr",x:n-8,y:8+u,fill:a.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.topRight.label),f("text",{key:"lbl",x:8,y:i-8,fill:a.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},a.bottomLeft.label),f("text",{key:"lbr",x:n-8,y:i-8,fill:a.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},a.bottomRight.label)]:[];return f(Gt.Fragment,null,...x.map((t,e)=>t.w>0&&t.h>0?f("rect",{key:"qf-"+e,x:t.x,y:t.y,width:t.w,height:t.h,fill:t.c.color,opacity:t.c.opacity??.08}):null),f("line",{key:"vc",x1:y,y1:0,x2:y,y2:i,stroke:d,strokeWidth:h,strokeDasharray:p}),f("line",{key:"hc",x1:0,y1:m,x2:n,y2:m,stroke:d,strokeWidth:h,strokeDasharray:p}),...b)}]:void 0;return{chartType:"scatter",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,sizeAccessor:i.sizeBy,sizeRange:i.sizeRange||[3,15],colorScheme:o,pointStyle:n.pointStyle||i.pointStyle||Oe(t,e,o,n,i),...n,showLegend:n.showLegend??!!e,...g&&{svgPreRenderers:g}}}},Oo={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=function(t,e){if(!Array.isArray(t))return{data:t,orderMap:new WeakMap};const o=e.xAccessor||"x",n=e.yAccessor||"y",i=e.orderAccessor?[...t].sort((t,o)=>null==t||"object"!=typeof t?1:null==o||"object"!=typeof o?-1:he(de(e.orderAccessor,"order",t))-he(de(e.orderAccessor,"order",o))):t,r=new WeakMap;let s=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=he(de(o,"x",t)),i=he(de(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&s++}let a=0;for(const t of i){if(null==t||"object"!=typeof t)continue;const e=he(de(o,"x",t)),i=he(de(n,"y",t));Number.isFinite(e)&&Number.isFinite(i)&&r.set(t,{idx:a++,total:s})}return{data:i,orderMap:r}}(t,i),s=Te({data:r.data,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",forecast:i.forecast,anomaly:i.anomaly,annotations:n.annotations,themeCategorical:ye(n.theme).colors.categorical}),a=ge(s.annotations,i.regression),l=i.pointRadius??4,c=at(i.xAccessor,i.yAccessor),u=i.styleRules,d=[t=>{const e=t.filter(t=>"point"===t.type&&"number"==typeof t.x&&"number"==typeof t.y);if(2>e.length)return null;const o=[];for(let t=0;e.length-1>t;t++){const n=e[t],i=e[t+1],r=pe(t,e.length);100>e.length&&o.push(Gt.createElement("line",{key:"halo-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),o.push(Gt.createElement("line",{key:"segment-"+t,x1:n.x,y1:n.y,x2:i.x,y2:i.y,stroke:r,strokeWidth:l,strokeLinecap:"round"}))}return Gt.createElement(Gt.Fragment,null,...o)}];return{chartType:"scatter",data:s.data,xAccessor:s.xAccessor,yAccessor:s.yAccessor,colorAccessor:e,colorScheme:o,pointStyle:ae(t=>{const e=r.orderMap.get(t),o=e?.idx??0,n=e?.total??1,i={fill:n>0?pe(o,n):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(i,dt(t,u,c(t))),i},fe(i)),...n,...a&&a.length>0&&{annotations:a},...s.yExtent&&!n.yExtent&&{yExtent:s.yExtent},svgPreRenderers:d}}},Io={frameType:"xy",buildProps:(t,e,o,n,i)=>{const r=i.frameProps&&"object"==typeof i.frameProps?i.frameProps:void 0,s=Number.isFinite(i.cellBorderWidth)?Math.max(0,i.cellBorderWidth):1,a=("string"==typeof r?.colorScheme?r.colorScheme:void 0)??o,l=null!=r&&Object.hasOwn(r,"heatmapColorScale"),c=r?.heatmapColorScale,u=l?"function"==typeof c?c:void 0:"custom"===a&&"function"==typeof i.customColorScale?i.customColorScale:void 0;return{chartType:"heatmap",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",valueAccessor:i.valueAccessor,showValues:i.showValues,heatmapValueFormat:i.valueFormat,areaStyle:()=>({stroke:i.cellBorderColor??"#fff",strokeWidth:s}),...n,...void 0!==a&&{colorScheme:a},...u&&{heatmapColorScale:u}}}};function zo(t){return Math.max(0,Math.min(1,t))}function Fo(t){const e=t.trim();if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t.split("").map(t=>t+t).join("")),6===t.length&&/^[0-9a-f]{6}$/i.test(t))return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}const o=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(o){const t=[Number(o[1]),Number(o[2]),Number(o[3])];if(t.every(Number.isFinite))return t}return null}function No(t,e,o){const n=t=>Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0");return`#${n(t)}${n(e)}${n(o)}`}function Eo(t,e,o){const n=t.filter(t=>Number.isFinite(t.offset)).map(t=>({offset:zo(t.offset),color:t.color??o,opacity:null==t.opacity?1:zo(t.opacity)})).sort((t,e)=>t.offset-e.offset);if(0===n.length)return"#999999";const i=t=>{if(1===t.opacity)return t.color;const e=Fo(t.color);return e?`rgba(${e[0]},${e[1]},${e[2]},${t.opacity})`:t.color};if(1===n.length)return i(n[0]);const r=zo(e);if(n[0].offset>=r)return i(n[0]);if(r>=n[n.length-1].offset)return i(n[n.length-1]);for(let t=0;n.length-1>t;t++){const e=n[t],o=n[t+1];if(e.offset>r||r>o.offset)continue;const s=o.offset-e.offset,a=s>0?(r-e.offset)/s:0,l=Fo(e.color),c=Fo(o.color);if(!l||!c)return i(.5>a?e:o);const[u,d,h]=l,[p,f,g]=c,y=u+(p-u)*a,m=d+(f-d)*a,x=h+(g-h)*a,b=e.opacity+(o.opacity-e.opacity)*a;return 1===b?No(y,m,x):`rgba(${Math.round(y)},${Math.round(m)},${Math.round(x)},${b})`}return i(n[n.length-1])}function Do(t,e,o){return null==o?`${t}-${e}`:`${t}-${e}-${o}`}import{Fragment as Wo,jsx as Bo,jsxs as jo}from"react/jsx-runtime";import{useMemo as Yo,useCallback as Xo,useRef as Go}from"react";var Vo={RdBu:v,PiYG:b,PRGn:x,BrBG:m,RdYlBu:w,RdYlGn:k,Spectral:A},Ho="__likert_neutral_neg",qo="__likert_neutral_pos";function Uo(t,e){if("function"==typeof t)return t;const o=t||e;return t=>t[o]}import*as Ko from"react";function Zo(t){return ce(t)}function Qo(t,e,o,n,i){const r=ye(n.theme).colors.categorical,s=o??n.colorScheme,a=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],l="string"==typeof e?e:"__ssrColorBy",c="function"==typeof e?a.map(t=>({...t,__ssrColorBy:e(t)})):a,u=e?ie(c,l,s??r):void 0,d=uo("string"==typeof i.color?i.color:void 0,r,s,void 0,new Map),h=st(i.valueAccessor),p=i.styleRules,f=n.pieceStyle;return(t,o)=>{const n={fill:e&&u?oe(t,e,u):d};return p?.length&&Object.assign(n,dt(t,p,{value:h(t),category:o})),"function"==typeof f?Object.assign(n,f(t,o)||{}):f&&"object"==typeof f&&Object.assign(n,f),void 0!==i.stroke&&(n.stroke=i.stroke),void 0!==i.strokeWidth&&(n.strokeWidth=i.strokeWidth),void 0!==i.opacity&&(n.opacity=i.opacity),n}}function Jo(t,e,o,n,i){const r=Qo(t,e,o,n,i);return(t,e)=>{const o=r(t,e);return void 0===o.fillOpacity&&(o.fillOpacity=.8),void 0===o.stroke&&(o.stroke=o.fill),o}}function tn(t,e,o,n,i){const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s="string"==typeof e?e:"__ssrViolinColorBy",a="function"==typeof e?r.map(t=>({...t,__ssrViolinColorBy:e(t)})):r,l=ye(n.theme).colors.categorical,c=o??n.colorScheme,u=e?ie(a,s,c??l):void 0,d=uo("string"==typeof i.color?i.color:void 0,l,c,void 0,new Map);return t=>{const o=e&&u?oe(t,e,u):d;return{fill:o,fillOpacity:.6,stroke:i.stroke??o,...void 0!==i.strokeWidth&&{strokeWidth:i.strokeWidth},...void 0!==i.opacity&&{opacity:i.opacity}}}}function en(t,e,o,n,i){const r=Qo(t,e,o,n,i),s="number"==typeof i.dotRadius?i.dotRadius:5;return(t,e)=>({r:s,fillOpacity:.8,...r(t,e)})}function on(t,e,o,n,i){const r=Qo(t,e,o,n,i),s=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],a=i.sizeBy,l=Array.isArray(i.sizeRange)?i.sizeRange:[3,8],c=a?s.map(t=>"function"==typeof a?a(t):Number(t[a])).filter(Number.isFinite):[],u=c.length?St(c):void 0,d="number"==typeof i.pointRadius?i.pointRadius:4,h="number"==typeof i.pointOpacity?i.pointOpacity:.7;return(t,e)=>({r:a?re(t,a,l,u):d,fillOpacity:h,...r(t,e)})}var nn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=ge(n.annotations,i.regression);return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,colorAccessor:e,colorScheme:o,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,...r&&{annotations:r},gradientFill:Zo(n.gradientFill),pieceStyle:Qo(t,e,o,n,i)}}},rn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.stackBy;return{chartType:"bar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.stackBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",normalize:i.normalize,oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Zo(n.gradientFill),pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},sn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.groupBy;return{chartType:"clusterbar",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",groupBy:i.groupBy,colorAccessor:r,colorScheme:o,projection:"horizontal"===i.orientation?"horizontal":"vertical",oSort:i.sort??!1,barPadding:i.barPadding,...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Zo(n.gradientFill),pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},an={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;return{chartType:"pie",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:Qo(t,r,o,n,i),showLegend:n.showLegend??!!r}}},ln={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(t,e,o,n,i)=>{const r=e||i.categoryAccessor;return{chartType:"donut",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",projection:"radial",margin:n.margin??{top:50,right:40,bottom:60,left:70},innerRadius:i.innerRadius??60,colorAccessor:r,colorScheme:o,...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...null!=i.startAngle&&{startAngle:i.startAngle},...n,pieceStyle:Qo(t,r,o,n,i)}}},cn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],s=i.valueAccessor||"value",a=r.map(t=>Number("function"==typeof s?s(t):t[s])).filter(Number.isFinite),l=a.length?[Math.min(...a),Math.max(...a)]:void 0;return{chartType:"histogram",data:t,oAccessor:i.categoryAccessor||(t=>null==t.category?"All":t.category+""),rAccessor:s,projection:"horizontal",bins:i.bins??25,normalize:i.relative??!1,colorAccessor:e,colorScheme:o,barPadding:i.categoryPadding??20,...i.valueExtent?{rExtent:i.valueExtent}:l?{rExtent:l}:{},...n,summaryStyle:Jo(t,e,o,n,i)}}},un={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"boxplot",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,...null!=i.showOutliers&&{showOutliers:i.showOutliers},...null!=i.outlierRadius&&{outlierRadius:i.outlierRadius},...n,summaryStyle:n.summaryStyle||Jo(t,e,o,n,i)})},dn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"violin",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,projection:"horizontal"===i.orientation?"horizontal":"vertical",bins:i.bins??25,showIQR:i.showIQR??!0,barPadding:i.categoryPadding??20,colorScheme:o,...n,summaryStyle:n.summaryStyle||tn(t,e,o,n,i),showLegend:n.showLegend??!!e,...i.valueExtent&&{rExtent:i.valueExtent}})},hn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"swarm",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,...i.symbolBy&&{symbolAccessor:i.symbolBy},...i.symbolMap&&{symbolMap:i.symbolMap},colorScheme:o,...n,sizeRange:i.sizeRange||[3,8],pieceStyle:n.pieceStyle||on(t,e,o,n,i),showLegend:n.showLegend??!!e})},pn={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(t,e,o,n,i)=>{const r=ge(n.annotations,i.regression);return{chartType:"point",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",oSort:i.sort??"auto",barPadding:i.categoryPadding??10,...n,...r&&{annotations:r},pieceStyle:en(t,e,o,n,i),showGrid:n.showGrid??!0,showLegend:n.showLegend??!!e}}},fn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>{const r=e||i.subcategoryAccessor;return{chartType:"swimlane",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",stackBy:i.subcategoryAccessor,colorAccessor:r,categoryAccessor:i.categoryAccessor,subcategoryAccessor:i.subcategoryAccessor,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",...null!=i.trackFill&&{trackFill:i.trackFill},...i.valueExtent&&{rExtent:i.valueExtent},...null!=i.roundedTop&&{roundedTop:i.roundedTop},...n,gradientFill:Zo(n.gradientFill),pieceStyle:n.pieceStyle||Qo(t,r,o,n,i),showLegend:n.showLegend??!!r,barPadding:i.barPadding??40}}},gn={frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"ridgeline",data:t,oAccessor:i.categoryAccessor||"category",rAccessor:i.valueAccessor||"value",colorAccessor:e,colorScheme:o,projection:"vertical"===i.orientation?"vertical":"horizontal",bins:i.bins??20,amplitude:i.amplitude??1.5,barPadding:i.categoryPadding??5,oSort:i.oSort??!1,...n,summaryStyle:n.summaryStyle||((r,s)=>({fillOpacity:.5,...Qo(t,e,o,n,i)(r,s)})),showLegend:n.showLegend??!!e})},yn={frameType:"ordinal",layout:{margin:(t,e)=>({...e.marginDefaults,left:"vertical"===t.orientation?e.marginDefaults.left:Math.max(100,e.marginDefaults.left)})},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.levels)&&i.levels.length>=2?i.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],s="vertical"!==i.orientation;let a=function(t,e,o,n,i,r){const s=new Map,a=new Set(e);for(const l of t){const t=o(l);s.has(t)||s.set(t,new Map);const c=s.get(t);if(n){const t=n(l);if(null==t||!Number.isFinite(t))continue;if(!Number.isInteger(t)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",t);continue}const o=t-1;if(0>o||o>=e.length)continue;const i=e[o];c.set(i,(c.get(i)||0)+1)}else if(i&&r){const t=i(l),e=r(l);if(!a.has(t))continue;c.set(t,(c.get(t)||0)+(Number.isFinite(e)?e:0))}}const l=[];for(const[t,o]of s){let n=0;for(const t of e)n+=o.get(t)||0;if(0!==n)for(let i=0;e.length>i;i++){const r=e[i],s=o.get(r)||0;l.push({__likertCategory:t,__likertLevel:r,__likertLevelLabel:r,__likertCount:s,__likertPct:s/n*100,__likertLevelIndex:i})}}return l}(Array.isArray(t)?t.filter(t=>!!t&&"object"==typeof t):[],r,Uo(i.categoryAccessor,"question"),i.levelAccessor?null:Uo(i.valueAccessor,"score"),i.levelAccessor?Uo(i.levelAccessor,"level"):null,i.levelAccessor?Uo(i.countAccessor,"count"):null);s&&(a=function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=new Map;for(const e of t){const t=r.get(e.__likertCategory)||[];t.push(e),r.set(e.__likertCategory,t)}const s=[];for(const[,t]of r){const e=new Map;let r,a;for(const o of t)o.__likertLevel===Ho?r=o:o.__likertLevel===qo?a=o:e.set(o.__likertLevelIndex,o);n&&r&&s.push(r);for(let t=i-1;t>=0;t--){const o=e.get(t);o&&s.push(o)}n&&a&&s.push(a);for(let t=n?i+1:i;o>t;t++){const o=e.get(t);o&&s.push(o)}}return s}(function(t,e){const o=e.length,n=o%2!=0,i=Math.floor(o/2),r=[];for(const e of t){const t=e.__likertLevelIndex;if(n&&t===i){const t=e.__likertPct/2;r.push({...e,__likertLevel:Ho,__likertPct:-t}),r.push({...e,__likertLevel:qo,__likertPct:t})}else r.push(i>t?{...e,__likertPct:-e.__likertPct}:e)}return r}(a,r),r));const l=ye(n.theme).colors.diverging,c=Array.isArray(o)&&o.length>=r.length?o:function(t,e){if(0>=t)return[];if(e&&Object.prototype.hasOwnProperty.call(Vo,e)){const o=Vo[e];if(1===t)return[o(.5)];const n=[];for(let e=0;t>e;e++)n.push(o(e/(t-1)));return n}const o=["#da1e28","#ff8389","#ffb3b8"],n=["#a6c8ff","#4589ff","#0043ce"],i="#a8a8a8";if(1===t)return[i];const r=t%2!=0,s=Math.floor(t/2),a=[];for(let t=0;s>t;t++)a.push(o[Math.min(Math.floor(t*o.length/s),o.length-1)]);r&&a.push(i);for(let t=0;s>t;t++)a.push(n[Math.min(Math.floor(t*n.length/s),n.length-1)]);return a}(r.length,l),u=new Map(r.map((t,e)=>[t,c[e]||"#888"])),d=r.length%2&&u.get(r[Math.floor(r.length/2)])||"#888",h="function"==typeof i.valueFormat?i.valueFormat:t=>Math.abs(Number(t)).toFixed(0)+"%",p=Ye(!1===n.showLegend?void 0:{legendGroups:[{label:"",items:r.map(t=>({label:t})),styleFn:t=>({fill:u.get(t.label)||"#888"})}]},n.legend);return{chartType:"bar",data:a,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:s?"horizontal":"vertical",barPadding:i.barPadding,showGrid:n.showGrid,oLabel:i.categoryLabel,rLabel:i.valueLabel||(s?void 0:"Percentage"),rFormat:h,...i.categoryFormat&&{oFormat:i.categoryFormat},...i.valueExtent&&{rExtent:i.valueExtent},...n,pieceStyle:ae(t=>{const e=t.__likertLevel||t.data?.__likertLevel;return{fill:e===Ho||e===qo?d:u.get((t.__likertLevelLabel||t.data?.__likertLevelLabel||e)+"")||"#888"}},fe(i)),showLegend:n.showLegend??!0,legendPosition:n.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}},mn={frameType:"ordinal",layout:{margin:(t,e)=>"vertical"===t.orientation?{top:e.title?60:40,right:20,bottom:60,left:60}:{top:e.title?40:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="vertical"===i.orientation,s=e||i.categoryAccessor;return{chartType:r?"bar-funnel":"funnel",data:t,oAccessor:i.stepAccessor||"step",rAccessor:i.valueAccessor||"value",colorAccessor:s,categoryAccessor:i.categoryAccessor,projection:r?"vertical":"horizontal",connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,...!r&&null!=i.connectorOpacity&&{connectorOpacity:i.connectorOpacity},barPadding:r?40:0,colorScheme:o,...n,showAxes:r&&!1!==n.showAxes,showGrid:r,pieceStyle:Qo(t,s,o,n,i),showLabels:i.showLabels??!0}}},xn={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(t,{theme:e}){const o=t.__gauge;if(!o)return null;const n=(o.startAngleDeg+(o.gMax===o.gMin?0:(Math.max(o.gMin,Math.min(o.gMax,o.value??o.gMin))-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,i=o.needleColor||e.colors.text,r=o.showScaleLabels?(o.thresholds||[]).filter(t=>t.value>o.gMin&&o.gMax>t.value):[];return jo(Wo,{children:[o.showNeedle&&jo(Wo,{children:[Bo("line",{x1:o.centerX,y1:o.centerY,x2:o.centerX+o.needleLength*Math.cos(n),y2:o.centerY+o.needleLength*Math.sin(n),stroke:i,strokeWidth:2.5,strokeLinecap:"round"}),Bo("circle",{cx:o.centerX,cy:o.centerY,r:4,fill:i})]}),null!=o.contextValue&&Bo("text",{x:o.centerX,y:o.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:o.valueFontSize,fontWeight:700,fill:i,children:o.contextValue}),r.map((t,n)=>{const i=(o.startAngleDeg+(o.gMax===o.gMin?0:(t.value-o.gMin)/(o.gMax-o.gMin))*o.sweep-90)*Math.PI/180,r=o.innerRadius-1,s=o.radius+1,a=o.radius+10,l=((i+Math.PI/2)/(2*Math.PI)*12+12)%12,c=l>=11||1>l?"middle":5>l?"start":7>l?"middle":"end",u=l>=11||1>l?"auto":5>l?"middle":7>l?"hanging":"middle";return jo("g",{children:[Bo("line",{x1:o.centerX+Math.cos(i)*r,y1:o.centerY+Math.sin(i)*r,x2:o.centerX+Math.cos(i)*s,y2:o.centerY+Math.sin(i)*s,stroke:e.colors.border,strokeWidth:2,strokeLinecap:"round"}),Bo("text",{x:o.centerX+Math.cos(i)*a,y:o.centerY+Math.sin(i)*a,textAnchor:c,dominantBaseline:u,fill:e.colors.textSecondary,fontSize:10,children:t.label||t.value+""})]},"gauge-label-"+n)})]})},buildProps:(t,e,o,n,i)=>{const r=i.min??0,s=i.max??100,a=i.sweep??240,l=i.arcWidth??.3,c=!1!==i.showNeedle,u=!1!==i.fillZones,{startAngleDeg:d}=ft(a),h=i.thresholds||[{value:s,color:i.color||"#4e79a7"}],p=ue(n.gradientFill),f=function(t){const{min:e,max:o,value:n,thresholds:i,fillColor:r,backgroundColor:s,fillZones:a,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=t,d=o-e||1,h=(Math.max(e,Math.min(o,n))-e)/d;let p=i&&i.length>0?[...i].sort((t,e)=>t.value-e.value):[{value:o,color:r||"#007bff"}];p=p.map(t=>({...t,value:Math.max(e,Math.min(o,t.value))})),o>p[p.length-1].value&&p.push({value:o,color:p[p.length-1].color});const f=!!c&&c.stops.length>=2,g=[],y=new Map,m=[];if(f){const t=a?h:1,e=Do("bg",0);if(g.push({category:e,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(e,{fill:s,opacity:.4}),t>0){const e=Math.max(1,Math.floor(u)),o=Math.max(1,Math.min(e,Math.round(t*e))),n=[];for(let e=0;o>e;e++)n.push(Eo(c.stops,t*(e+.5)/o,r||p[0]?.color||"#007bff"));const i=Do("fill",0);g.push({category:i,value:t,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:t,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:n}}),y.set(i,{fill:n[0]||s})}}else{let t=e;for(let o=0;p.length>o;o++){const n=p[o],i=(n.value-t)/d,r=(t-e)/d,l=(n.value-e)/d,c=Math.max(0,(a?Math.min(h,l):l)-r),u=a?Math.max(0,i-c):0;if(c>0){const t=Do("fill",o);g.push({category:t,value:c,_zone:n.label||"Zone "+(o+1),_isFill:!0}),y.set(t,{fill:n.color})}if(u>0){const t=Do("bg",o);g.push({category:t,value:u,_zone:n.label||"Zone "+(o+1),_isFill:!1}),y.set(t,{fill:s,opacity:.4})}t=n.value}}if(l&&i&&i.length>0)for(const t of i)t.value>e&&o>t.value&&m.push({type:"gauge-label",value:t.value,label:t.label||t.value+""});return{gaugeData:g,pieceStyle:(t,e)=>y.get(e||t.category)||{fill:s},gaugeAnnotations:m}}({min:r,max:s,value:i.value,thresholds:h,fillColor:i.color,backgroundColor:i.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==i.showScaleLabels,gradientFill:p}),[g,y]=n.size||[300,250],m=J(a),x=Math.min(10,Math.max(1,Math.min(g,y)/12)),b=Math.max(4,Math.min((g-2*x)/m.width,(y-2*x)/m.height)-2),v=Math.max(0,Math.min(b-1.5,b*(1-l))),w=g/2-m.cx*b,k=y/2-m.cy*b,A=2*(b+4),S=Math.max(r,Math.min(s,i.value??r)),M="function"==typeof i.valueFormat?i.valueFormat(S):Math.round(S)+"",_=i.centerContent??n.centerContent,P=null!=_?"function"==typeof _?_(S,r,s):_:"sparkline"===i.mode||"context"===i.mode?void 0:Ko.createElement("div",{style:{textAlign:"center",lineHeight:1.2}},Ko.createElement("div",{style:{fontSize:Math.max(16,.3*b),fontWeight:700,color:"var(--semiotic-text, #333)"}},M),!1!==i.showScaleLabels&&Ko.createElement("div",{style:{fontSize:11,color:"var(--semiotic-text-secondary, #666)"}},`${r} – ${s}`));return{chartType:"donut",data:f.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:v,sweepAngle:a,startAngle:d,oSort:!1,pieceStyle:ae(f.pieceStyle,fe(i)),...null!=i.cornerRadius&&{cornerRadius:i.cornerRadius},...n,size:[g,y],margin:{top:k-A/2,bottom:y-k-A/2,left:w-A/2,right:g-w-A/2},...null!=P&&{centerContent:P},showAxes:!1,annotations:[...Array.isArray(n.annotations)?n.annotations:[],...f.gaugeAnnotations],__gauge:{gMin:r,gMax:s,sweep:a,arcWidth:l,value:S,startAngleDeg:d,thresholds:h,centerX:w,centerY:k,radius:b,innerRadius:v,showScaleLabels:!1!==i.showScaleLabels,needleLength:v>20?v-8:b-1,showNeedle:c,needleColor:i.needleColor,..."context"===i.mode&&null==_&&{contextValue:M,contextValueY:k-.2*v,valueFontSize:Math.max(12,Math.min(22,.28*b))}}}}};import{scaleTime as bn}from"d3-scale";var vn={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function wn(t="static"){return vn[t]??vn.static}var kn=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function An(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:kn.has(t.kind)?"fatal":"warn"}function Sn(t){return"invalid-node-time"===t.kind?`node ${t.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===t.kind?`edge ${t.id} has an invalid startTime or endTime`:"invalid-domain"===t.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===t.kind?`edge ${t.id} must have a positive finite value`:"missing-node"===t.kind?`edge ${t.id} references missing ${t.endpoint} node "${t.nodeId}"`:"backward-edge"===t.kind?`edge ${t.id} (${t.source}->${t.target}) ends before it starts`:"duplicate-node"===t.kind?`node id "${t.id}" is duplicated`:"duplicate-edge"===t.kind?`edge id "${t.id}" is duplicated`:"invalid-system-time"===t.kind?`edge ${t.id} has an invalid systemInTime or systemOutTime`:t.kind}function Mn(){return Object.create(null)}function _n(t,e){return e>t?-1:t>e?1:0}function Pn(t){return t.occupants.map(t=>t.id).sort(_n).join("\0")}function Ln(t,e,o=0){return t.slice(0,-1).map((n,i)=>null!=n.group&&n.group===t[i+1].group?o:e)}function $n(t,e){return t.map(t=>{const o=new Map;for(const n of t.occupants){const t=e[n.id];if(t)for(const e of t.samples){const t=o.get(e.t)??{before:0,after:0},n=e.boundaryOffset??0;o.set(e.t,{before:Math.max(t.before,e.topMass-n),after:Math.max(t.after,e.botMass+n)})}}return[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function Rn(t,e,o){if(0===t.length)return[];const{padding:n,plotH:i,valueScale:r}=o,s=o.stackValueScale??r,a=Ln(t,n,o.groupPadding??0),l=[n+t[0].peak.topPeak*s];for(let o=1;t.length>o;o++)l.push(l[o-1]+e[o-1]*s+a[o-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*s+n;if(c>i&&c>0){const t=i/c;for(let e=0;l.length>e;e++)l[e]*=t}return l}function Cn(t,e){const o=(t.boundaryOffset??0)*e,n=t.value*e;if("out"===t.kind){const i=t.sideMassBefore*e;return o+("top"===t.side?n/2-i:i-n/2)}const i=t.sideMassAfter*e;return o+("top"===t.side?n/2-i:i-n/2)}function Tn(t,e,o,n,i,r){const s=r.adjacentClearance?[...r.adjacentClearance]:$($n(n,o)).adjacentClearance,a=Rn(n,s,r);let l="hug"===r.lanePlacement?function(t,e,o,n,i,r,s){const a=t.length;if(0===a)return[];const{padding:l,plotH:c,valueScale:u}=s,d=Ln(t,l,s.groupPadding??0),h=i.map((t,e)=>t*u+d[e]),p=l+t[0].peak.topPeak*u,f=c-l-t[a-1].peak.botPeak*u;if(h.reduce((t,e)=>t+e,0)+1e-6>=f-p)return Rn(t,i,s);let g=1===a?[(p+f)/2]:[...r];for(let t=0;12>t;t++){const t=Array(a).fill(0),i=Array(a).fill(0);for(const r of o){const o=e[r.source],s=e[r.target];if(null==o||null==s||o===s)continue;const a=n[r.source]?.localAttachments.get(r.id),l=n[r.target]?.localAttachments.get(r.id);if(!a||!l)continue;const c=r.value>0&&Number.isFinite(r.value)?r.value:1,d=Cn(a,u),h=Cn(l,u);t[o]+=(g[s]+h-d)*c,i[o]+=c,t[s]+=(g[o]+d-h)*c,i[s]+=c}const r=g.map((e,o)=>0===i[o]?e:.45*e+t[o]/i[o]*.55),s=R({desired:r,minGaps:h,weights:i.map(t=>Math.max(1,t)),min:p,max:f});let l=0;for(let t=0;a>t;t++)l=Math.max(l,Math.abs(s[t]-g[t]));if(g=s,.01>l)break}return g}(n,i,e,o,s,a,r):[...a];if("hug"===r.lanePlacement){const o=e=>{const o=Mn();for(const n of t)o[n.id]=e[i[n.id]];return o};On(o(l),e)>On(o(a),e)+1e-6&&(l=[...a])}const c=Mn();for(const e of t)c[e.id]=l[i[e.id]];let u=1/0,d=-1/0;for(const e of t){const t=c[e.id],n=o[e.id];Number.isFinite(t)&&n&&(u=Math.min(u,t-n.topPeak*r.valueScale),d=Math.max(d,t+n.botPeak*r.valueScale))}return{adjacentClearance:s,centerlines:c,slotCenter:l,stackCenter:a,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&r.plotH>0?Math.max(0,Math.min(1,(d-u)/r.plotH)):0}}function On(t,e){let o=0;for(const n of e){const e=t[n.source],i=t[n.target];Number.isFinite(e)&&Number.isFinite(i)&&(o+=Math.abs(e-i)*(n.value>0?n.value:1))}return o}function In(t,e){const o=t?.samples;if(!o||0===o.length||o[0].t>e)return{top:0,bot:0};let n=0,i=o.length-1,r=0;for(;i>=n;){const t=n+i>>>1;o[t].t>e?i=t-1:(r=t,n=t+1)}const s=o[r].boundaryOffset??0;return{top:o[r].topMass-s,bot:o[r].botMass+s}}function zn(t,e,o,n,i){const r=1-i;return r*r*r*t+3*r*r*i*e+3*r*i*i*o+i*i*i*n}function Fn(t,e){let o=0,n=1;for(let i=0;28>i;i++){const i=(o+n)/2;t>zn(0,e,e,1,i)?o=i:n=i}return(o+n)/2}function Nn(t,e,o){const n=e+Cn(t,o),i=t.value*o/2;return[n-i,n+i]}function En(t,e,o,n){return Math.max(0,Math.min(e,n)-Math.max(t,o))/Math.max(1e-9,e-t)}function Dn(t,e,o,n,i,r,s){const{valueScale:a,domain:l,mode:c="quality"}=s,u="source"===s.ribbonLane?.85:"target"===s.ribbonLane?.15:.5;let d=0;for(const s of t){const t=n[s.source],h=n[s.target];if(null==t||null==h||2>Math.abs(t-h))continue;const p=e[s.source]?.localAttachments.get(s.id),f=e[s.target]?.localAttachments.get(s.id);if(!p||!f)continue;const g=Math.max(s.startTime,l?.[0]??-1/0),y=Math.min(s.endTime,l?.[1]??1/0);if(g>=y)continue;const[m,x]=Nn(p,i[s.source],a),[b,v]=Nn(f,i[s.target],a),w=Math.min(t,h)+1,k=Math.max(t,h)-1;for(let t=w;k>=t;t++){const n=o[t];if(!n)continue;const l=[g,y];if("quality"===c)for(const t of n.occupants)for(const o of e[t.id]?.samples??[])o.t>g&&y>o.t&&l.push(o.t);const h=t=>{const o=Fn((t-g)/(y-g),u),l=zn(m,m,b,b,o),c=zn(x,x,v,v,o);let d=0;for(const o of n.occupants){if(o.id===s.source||o.id===s.target)continue;const n=r[o.id];if(null!=n?.start&&n.start>t)continue;if(null!=n?.end&&t>n.end)continue;const u=In(e[o.id],t),h=i[o.id];d=Math.max(d,En(l,c,h-u.top*a,h+u.bot*a))}return d},p=[...new Set(l)].sort((t,e)=>t-e);let f=0;for(let t=0;p.length-1>t;t++){const e=p[t],o=p[t+1]-e;f+=(h(e+.25*o)+h(e+.5*o)+h(e+.75*o))/3*o}d+=f/(y-g)*(s.value>0?s.value:1)}}return d}function Wn(t,e,o,n,i,r,s,a,l,c,u="both",d){return{crossings:t,weightedLength:e,pixelLength:On(s,o),transitOcclusion:Dn(o,n,i,r,s,a,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function Bn(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function jn(t,e){return t.map(t=>({t:Bn(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function Yn(t,e,o){const n=e+(t.boundaryOffset??0)*o,i=t.value*o;if("out"===t.kind){const e=t.sideMassBefore*o;if("top"===t.side){const t=n-e;return[t,t+i]}const r=n+e;return[r-i,r]}const r=t.sideMassAfter*o;if("top"===t.side){const t=n-r;return[t,t+i]}const s=n+r;return[s-i,s]}function Xn(t,e,o,n,i="temporal"){const r=e.incoming[t.id],s=e.outgoing[t.id],a=[];for(const t of r)a.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:o.get(t.id).targetSide});for(const t of s)a.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:o.get(t.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{a.sort((t,e)=>t.time-e.time||(t.phase??0)-(e.phase??0)||(t.sequence??0)-(e.sequence??0)||(l[t.kind]??99)-(l[e.kind]??99)||((t,e)=>{if(!n||!t.edge||!e.edge||t.kind!==e.kind||t.side!==e.side)return 0;if("out"===t.kind){if(t.edge.target===e.edge.target&&t.edge.endTime===e.edge.endTime)return 0;const o=n.get(t.edge.id)?.target,i=n.get(e.edge.id)?.target;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===t.side?o-i:i-o:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const o=n.get(t.edge.id)?.source,i=n.get(e.edge.id)?.source;return"number"==typeof o&&Number.isFinite(o)&&"number"==typeof i&&Number.isFinite(i)&&o!==i?"top"===t.side?i-o:o-i:0}return 0})(t,e)||_n(t.edge?.id??"",e.edge?.id??"")||_n(t.side,e.side)||t.delta-e.delta)},u=a.length?At(a.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let p=null,f=0;for(const t of a)t.time!==p&&(p=t.time,f=0),t.sequence=f++;const g=t=>({time:t.time,phase:0,sequence:t.sequence??0}),y=[];let m=0,x=0;for(const t of a)if("out"===t.kind){const e=Math.abs(t.delta);let o=e-("top"===t.side?m:x);if(o>0){const e="top"===t.side?"bot":"top",n=Math.min(o,"top"===e?m:x);if(n>0){const i=g(t);y.push({...i,delta:-n,kind:"transfer-out",side:e}),y.push({...i,delta:+n,kind:"transfer-in",side:t.side}),"top"===e?m-=n:x-=n,"top"===t.side?m+=n:x+=n,o-=n}o>0&&null!==h&&(y.push({time:h,delta:+o,kind:"create",side:t.side}),"top"===t.side?m+=o:x+=o)}"top"===t.side?m-=e:x-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?m+=e:x+=e}a.push(...y),c();let b=0,v=0,w=0,k=0,A=0,S=0;const M=[],_=new Map,P=t=>{M.push({t:t,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},L=()=>{k=Math.max(k,b+v),A=Math.max(A,b-w),S=Math.max(S,v+w)};for(const t of a){if("transfer-out"!==t.kind&&"transfer-in"!==t.kind&&P(t.time),("in"===t.kind||"out"===t.kind)&&t.edge){const e="top"===t.side?b:v;_.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:e+t.delta,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?b+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,L(),P(t.time)):"transfer-out"!==t.kind&&(L(),"out"!==t.kind||b+v>1e-12||(w=0),P(t.time))}const $=[];let R=0;for(;M.length>R;){let t=R;for(;M.length>t+1&&M[t+1].t===M[R].t;)t++;$.push(M[R]);for(let e=R+1;t>=e;e++){const t=$[$.length-1];M[e].topMass===t.topMass&&M[e].botMass===t.botMass&&(M[e].boundaryOffset??0)===(t.boundaryOffset??0)||$.push(M[e])}R=t+1}const C=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let T=null;for(const t of s)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime&&(null===T||T>t.systemInTime)&&(T=t.systemInTime);let O=null;for(const t of r)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===O||t.systemOutTime>O)&&(O=t.systemOutTime);if($.length>0){const t=$[$.length-1],e=Math.max(null!=C?C:-1/0,null!=O?O:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&$.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const o=$[0],n=$.find(t=>t.topMass+t.botMass>0);let i,r=1/0;null!=d&&Number.isFinite(d)&&o.t>d&&o.topMass+o.botMass>0&&(r=d,i=o),n&&null!=T&&Number.isFinite(T)&&n.t>T&&r>T&&(r=T,i=n),i&&Number.isFinite(r)&&$.unshift({t:r,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let I=$;if("max"===i&&null!=d&&null!=C&&C>d){let t,e=0;for(const o of $){const n=o.topMass+o.botMass;n>e&&(e=n,t=o)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};I=[...$.filter(t=>d>t.t),{t:d,...e},{t:C,...e},...$.filter(t=>t.t>C)]}}return{samples:I,peak:k,topPeak:A,botPeak:S,localAttachments:_}}function Gn(t){const e=Mn();return t.forEach((t,o)=>{for(const n of t.occupants)e[n.id]=o}),e}function Vn(t,e,o){t.splice(0,t.length,...o);const n=Gn(o);for(const t of Object.keys(e))delete e[t];Object.assign(e,n)}function Hn(t){const e=new Map,o=[];t.forEach((t,n)=>{if(!t.group)return void o.push({anchor:n,stableId:Pn(t),slots:[t]});const i=e.get(t.group)??{indexes:[],slots:[]};i.indexes.push(n),i.slots.push(t),e.set(t.group,i)});for(const[t,n]of e)o.push({anchor:n.indexes.reduce((t,e)=>t+e,0)/n.indexes.length,stableId:`${t}\0${n.slots.map(Pn).join("\0")}`,slots:n.slots});return o.sort((t,e)=>t.anchor-e.anchor||_n(t.stableId,e.stableId))}function qn(t){return t.some(t=>t.group)?Hn(t).flatMap(t=>t.slots):[...t]}function Un(t){return t.flatMap(t=>t.slots)}function Kn(t,e,o){const n=new Map;return t.forEach((t,e)=>{for(const o of t.slots)n.set(o,e)}),t.map((t,i)=>{if(1>=t.slots.length)return t;const r=new Map;for(const e of t.slots)r.set(e,0);for(const t of e){const e=n.get(t.source),o=n.get(t.target);if(null==e||null==o)continue;const s=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===i&&o!==i){const e=o>i?1:-1;r.set(t.source,(r.get(t.source)??0)+s*e)}else if(o===i&&e!==i){const o=e>i?1:-1;r.set(t.target,(r.get(t.target)??0)+s*o)}}const s=[...t.slots].sort((t,e)=>(r.get(t)??0)-(r.get(e)??0)||o(t,e));return{...t,slots:s}})}function Zn(t,e){t.some(t=>t.group)&&Vn(t,e,qn(t))}function Qn(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.min(t.endTime,e.endTime)>Math.max(t.startTime,e.startTime)}function Jn(t,e){return c(e,e=>[t[e.source],t[e.target]],Qn)}function ti(t,e){let o=0;for(const n of e){const e=t[n.source],i=t[n.target];null!=e&&null!=i&&(o+=Math.abs(e-i)*(n.value>0?n.value:1))}return o}function ei(t,e,o){const[n,i]=o.get(t.first),[r,s]=o.get(t.second);return 0>(e.get(n)-e.get(r))*(e.get(i)-e.get(s))?1:0}var oi=t=>{let e=1;for(let o=2;t>=o;o++)e*=o;return e},ni=828*oi(8),ii=3e3;function ri(t,e,o,n,i,r,s){const a=[...i],l=new Map(i.map(t=>[t,Pn(t)])),c=new Map;for(const t of i)for(const e of t.occupants)c.set(e.id,t);const u=new Map,d=[];for(const t of e){const e=c.get(t.source),o=c.get(t.target);e&&o&&(u.set(t,[e,o]),e!==o&&d.push({source:e,target:o,weight:t.value}))}const h=[];for(let t=0;e.length>t;t++)if(u.has(e[t]))for(let o=t+1;e.length>o;o++){if(!u.has(e[o])||!Qn(e[t],e[o]))continue;const n=new Set([...u.get(e[t]),...u.get(e[o])]);h.push({index:h.length,first:e[t],second:e[o],involvedSlots:n})}const p=new Map;for(const t of i)p.set(t,[]);for(const t of h)for(const e of t.involvedSlots)p.get(e)?.push(t);const f=new Uint32Array(h.length);let g=0;const y=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),m=s.plotH/Math.max(1,i.length),x=i.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),b=Math.max(1,y)*(Math.max(1,s.plotH)+m*Math.max(x,i.length)+1e-6*Math.max(1,i.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,A=(t,e)=>{let n=k.get(t);n||(n=new Map,k.set(t,n));const i=n.get(e);if(null!=i)return i;const r=function(t,e,o){return $($n([t,e],o)).adjacentClearance[0]??0}(t,e,o);return n.set(e,r),r},S=new Map(i.map((t,e)=>[t,e])),M=e.flatMap(t=>{const e=u.get(t);return e?[{source:S.get(e[0]),target:S.get(e[1]),weight:t.value>0?t.value:1}]:[]}),_=new Map;for(const t of e){const e=u.get(t);e&&_.set(t,{source:S.get(e[0]),target:S.get(e[1])})}const R=new Map,C=new Map,T=new Map,O=(t,e,o)=>{t.has(e)||t.set(e,new Set),t.get(e).add(o)};for(const t of e)O(R,t.source,t.target),O(C,t.target,t.source),O(T,t.source,t.target),O(T,t.target,t.source);const I=e.flatMap(t=>{if(!(t=>1===R.get(t.source)?.size&&R.get(t.source).has(t.target)||1===T.get(t.source)?.size||1===T.get(t.target)?.size)(t))return[];const e=_.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),F=t=>{let e=0;for(const o of I)e+=Math.max(0,Math.abs(t[o.source]-t[o.target])-1)*o.weight;return e*v},N=t=>{const e=new Int16Array(i.length);for(let o=0;t.length>o;o++)e[S.get(t[o])]=o;return F(e)},E=h.map(t=>{const e=_.get(t.first),o=_.get(t.second);return[e.source,e.target,o.source,o.target]}),D=new Int16Array(i.length),W=new Float64Array(i.length),B=new Float64Array(i.length+1),j=t=>{for(let e=0;t.length>e;e++)D[S.get(t[e])]=e;let e=0;for(const[t,o,n,i]of E)0>(D[t]-D[n])*(D[o]-D[i])&&e++;if(t.length>0){const e=S.get(t[0]);W[e]=s.padding+t[0].peak.topPeak*s.valueScale;for(let e=1;t.length>e;e++){const o=S.get(t[e-1]),n=S.get(t[e]);W[n]=W[o]+A(t[e-1],t[e])*s.valueScale+s.padding}const o=S.get(t[t.length-1]),n=W[o]+t[t.length-1].peak.botPeak*s.valueScale+s.padding;if(n>s.plotH&&n>0){const t=s.plotH/n;for(let e=0;W.length>e;e++)W[e]*=t}}B[0]=0;for(let e=0;t.length>e;e++)B[e+1]=B[e]+t[e].peak.topPeak+t[e].peak.botPeak;let o=0,n=0,i=0;for(const t of M){const e=D[t.source],r=D[t.target];if(o+=Math.abs(e-r)*t.weight,n+=Math.abs(W[t.source]-W[t.target])*t.weight,Math.abs(e-r)>=2){const o=Math.min(e,r)+1;i+=(B[Math.max(e,r)]-B[o])*t.weight}}return e*b+n+i*m+F(D)+1e-6*o},Y=(t,o)=>{const n=Array(t.length+1).fill(0);for(let e=0;t.length>e;e++)n[e+1]=n[e]+t[e].peak.topPeak+t[e].peak.botPeak;let i=0;for(const t of e){const e=o[t.source],r=o[t.target];if(null==e||null==r||2>Math.abs(e-r))continue;const s=Math.min(e,r)+1;i+=(n[Math.max(e,r)]-n[s])*(t.value>0?t.value:1)}return i},X=n=>{const i=Gn(n),r=n.slice(0,-1).map((t,e)=>A(t,n[e+1])),a=Tn(t,e,o,n,i,{plotH:s.plotH,padding:s.padding,valueScale:s.valueScale,lanePlacement:s.lanePlacement??"stack",groupPadding:s.groupPadding,adjacentClearance:r});return{map:i,geometry:a,weightedLength:ti(i,e),pixelLength:On(a.centerlines,e),transitOcclusion:Y(n,i)}},G=(t,e,o)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*b+e.pixelLength+e.transitOcclusion*m+N(o)+1e-6*e.weightedLength}),V=(t,e)=>{let o=e;if(null==o){const e=new Map(t.map((t,e)=>[t,e]));o=h.reduce((t,o)=>t+ei(o,e,u),0),w.fullCrossing++}return G(o,X(t),t)},H=(t,i,r="quality")=>{let a=i;if(null==a){const e=new Map(t.map((t,e)=>[t,e]));a=h.reduce((t,o)=>t+ei(o,e,u),0),w.fullCrossing++}const l=X(t);return G(a,{...l,transitOcclusion:Dn(e,o,t,l.map,l.geometry.centerlines,n,{valueScale:s.valueScale,ribbonLane:s.ribbonLane,domain:s.domain,mode:r})},t)};let q=[...a];const U=(t,e)=>_n(l.get(t),l.get(e)),K=function(t){const e=new Set;for(const o of t)if(o.group){if(e.has(o.group))return!0;e.add(o.group)}return!1}(q),Z=t=>{const e=(t=>{const e=P(t,d,t=>V(t).cost,{passes:6,compare:U,maxEvaluations:ii});let o=V(e),n=ii;for(let t=0;6>t&&n>0;t++){let i=!1;const r=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&r.reverse();for(const t of r){if(0>=n--)break;const r=e[t],s=e[t+1],a=new Map(e.map((t,e)=>[t,e]));let l=0;const c=[];g++;for(const t of[...p.get(r)??[],...p.get(s)??[]])f[t.index]!==g&&(f[t.index]=g,c.push(t),l+=ei(t,a,u));[e[t],e[t+1]]=[s,r];const d=new Map(a);d.set(r,t+1),d.set(s,t);let h=0;for(const t of c)h+=ei(t,d,u);w.localCrossing+=c.length;const y=V(e,o.crossings-l+h);o.cost>y.cost?(o=y,i=!0):[e[t],e[t+1]]=[r,s]}if(!i)break}return e})(t);if((t.length>8?1/0:oi(t.length)*(t.length+M.length+E.length))>ni)return e;const o=L(t,j,{maxItems:8,maxEvaluations:5e4}),n=H(o),i=H(e);return n.crossings!==i.crossings&&i.crossings>n.crossings?o:e},Q="geometry-refine"===s.mode;if(Q||"crossing-min"!==s.laneOrder&&"crossing-min+inside-out"!==s.laneOrder){if(!Q&&"inside-out"===s.laneOrder)if(K){const t=Hn(q),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),o=[...t].sort((t,o)=>e(o)-e(t)||_n(t.stableId,o.stableId)),n=Array(o.length);let i=Math.floor((o.length-1)/2)-1,r=Math.floor((o.length-1)/2)+1;o.length>0&&(n[Math.floor((o.length-1)/2)]=o[0]);for(let t=1;o.length>t;t++)t%2==1&&o.length>r||0>i?n[r++]=o[t]:n[i--]=o[t];q=Un(n)}else{const t=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(t,e)),e=Array(t.length);let o=Math.floor((t.length-1)/2)-1,n=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let i=1;t.length>i;i++)i%2==1&&t.length>n||0>o?e[n++]=t[i]:e[o--]=t[i];q=e}}else q=K?(t=>{let e=Hn(t);if(1>=e.length)return Un(e);const o=t=>V(Un(t)).cost;e=Hn(Z(t)),e=Kn(e,d,U);const n=function(t,e){const o=new Map;for(const e of t)for(const t of e.slots)o.set(t,e);const n=new Map;for(const t of e){const e=o.get(t.source),i=o.get(t.target);if(!e||!i||e===i)continue;const r=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,s=i.stableId>e.stableId?`${e.stableId}\0${i.stableId}`:`${i.stableId}\0${e.stableId}`,a=n.get(s);a?a.weight=(a.weight??0)+r:n.set(s,{source:e,target:i,weight:r})}return[...n.values()]}(e,d);e=P(e,n,o,{passes:6,compare:(t,e)=>_n(t.stableId,e.stableId),maxEvaluations:ii}),e=z(e,o,{passes:8,maxEvaluations:ii});const i=e.length>8?1/0:oi(e.length)*(e.length+M.length+E.length);if(ni>=i){const t=L(e,t=>j(Un(t)),{maxItems:8,maxEvaluations:5e4}),o=Un(t),n=Un(e),i=H(o),r=H(n);i.crossings!==r.crossings?e=r.crossings>i.crossings?t:e:r.cost>i.cost&&(e=t)}return e=Kn(e,d,U),Un(e)})(q):Z(q);if(!Q&&"crossing-min+inside-out"===s.laneOrder&&q.length>1)if(K){const t=Hn(q);let e=V(Un(t)),o=Un(t),n=e;const i=Math.floor((t.length-1)/2),r=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),s=[...t].sort((t,e)=>r(e)-r(t)||_n(t.stableId,e.stableId));for(const r of s){const s=t.indexOf(r);if(s===i)continue;t.splice(s,1),t.splice(i,0,r);const a=Un(t),l=V(a);l.cost>e.cost?(t.splice(i,1),t.splice(s,0,r)):(e=l,n.cost>l.cost&&(o=a,n=l))}q=o}else{let t=V(q),e=[...q],o=t;const n=Math.floor((q.length-1)/2),i=[...q].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||U(t,e));for(const r of i){const i=q.indexOf(r);if(i===n)continue;q.splice(i,1),q.splice(n,0,r);const s=V(q);s.cost>t.cost?(q.splice(n,1),q.splice(i,0,r)):(t=s,o.cost>s.cost&&(e=[...q],o=s))}q=e}if((Q||"crossing-min"===s.laneOrder||"crossing-min+inside-out"===s.laneOrder)&&q.length>1)if(K){let t=Hn(q),e=H(Un(t),void 0,"score");for(let o=0;6>o&&t.length>1;o++){let o=!1;for(let n=0;t.length-1>n;n++){[t[n],t[n+1]]=[t[n+1],t[n]];const i=Un(t),r=H(i,void 0,"score");e.cost>r.cost?(q=i,e=r,o=!0):[t[n],t[n+1]]=[t[n+1],t[n]]}if(!o)break}t=Kn(Hn(q),d,U),q=Un(t)}else{let t=H(q,void 0,"score");for(let e=0;q.length-1>e;e++){const o=q[e],n=q[e+1],i=new Map(q.map((t,e)=>[t,e]));let r=0;const s=[];g++;for(const t of[...p.get(o)??[],...p.get(n)??[]])f[t.index]!==g&&(f[t.index]=g,s.push(t),r+=ei(t,i,u));[q[e],q[e+1]]=[n,o];const a=new Map(i);a.set(o,e+1),a.set(n,e);let l=0;for(const t of s)l+=ei(t,a,u);w.localCrossing+=s.length;const c=H(q,t.crossings-r+l,"score");t.cost>c.cost?t=c:[q[e],q[e+1]]=[o,n]}}const J=qn(a);q=qn(q);let tt=H(q);const et=H(J);if(Q){const t=N(J),e=N(q);(tt.crossings>et.crossings||tt.crossings===et.crossings&&e>t+1e-9||tt.cost>et.cost)&&(q=J,tt=et)}else tt.cost>et.cost&&(q=J,tt=et);const ot=function({order:t,after:e,nodes:o,edges:n,outgoingPartners:i,incomingPartners:r,slotForNode:s,averageGap:a,evaluate:l}){const c=(o,i)=>{const r=[...new Set(i.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),s=t.indexOf(o),c=r[0],u=r[r.length-1];if(3>r.length||!r.includes(s)||u-c+1!==r.length||1>=Math.abs(2*s-c-u))return;const d=[...t];d.splice(s,1),d.splice(c+u>>1,0,o);const h=qn(d),p=l(h),f=new Set(o.occupants.map(t=>t.id)),g=new Set(i.flatMap(t=>t.occupants.map(t=>t.id))),y=n.reduce((t,e)=>f.has(e.source)&&g.has(e.target)||f.has(e.target)&&g.has(e.source)?t+(e.value>0?e.value:1):t,0);(function(t,e,o=0){return e.crossings>t.crossings||t.crossings===e.crossings&&e.cost+o>=t.cost})(p,e,Math.abs(2*s-c-u)*a*Math.max(1,y))&&(t=h,e=p)};for(const[t,e]of i)r.has(t)||3>e.size||c(s.get(t),[...e].map(t=>s.get(t)));for(const t of o){const e=s.get(t.id);t.group||!e.group||3>(r.get(t.id)?.size??0)||c(e,[...r.get(t.id)??[]].map(t=>s.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,o)=>o.indexOf(t)===e))}return{order:t,after:e}}({order:q,after:tt,nodes:t,edges:e,outgoingPartners:R,incomingPartners:C,slotForNode:c,averageGap:m,evaluate:H});return q=ot.order,tt=ot.after,Vn(i,r,q),{before:et,after:tt,initialOrder:a.map(t=>l.get(t)),evaluations:w}}function si(t,e,o){const n=t.map(t=>{const n=t.occupants.map(t=>({id:t.id,end:o[t.id]?.end??t.end}));let i=0,r=0;for(const t of n){const o=e[t.id];i=Math.max(i,o?.topPeak||0),r=Math.max(r,o?.botPeak||0)}return{occupants:n,peak:{topPeak:i,botPeak:r},...null!=t.group?{group:t.group}:{}}}),i=Mn();return n.forEach((t,e)=>{for(const o of t.occupants)i[o.id]=e}),{slots:n,slotByNode:i}}var ai=new Map,li=1e5,ci=1e-9;function ui(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(e.start>=t.end||t.start>=e.end)}function di(t,e){return _n(t,e)>0?`${e}\0${t}`:`${t}\0${e}`}function hi(t){const e=new Map,o=new Map;for(const n of t)o.has(n.source)||o.set(n.source,new Set),e.has(n.target)||e.set(n.target,new Set),o.get(n.source).add(n.target),e.get(n.target).add(n.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...o].map(([t,e])=>[t,e.size]))}}function pi(t){const e=new Map,o=new Map,n=(t,e,o,n)=>{let i=t.get(e);i||(i=new Map,t.set(e,i)),i.set(o,(i.get(o)??0)+n)};for(const i of t){const t=i.value>0&&Number.isFinite(i.value)?i.value:1;n(e,i.source,i.target,t),n(o,i.target,i.source,t)}const i=new Map,r=t=>{if(i.has(t))return;const n=e.get(t),r=o.get(t),s=new Map;for(const[t,e]of n??[])s.set(t,(s.get(t)??0)+e);for(const[t,e]of r??[])s.set(t,(s.get(t)??0)+e);if(1===s.size){const[e,o]=[...s][0];i.set(t,{partner:e,weight:o})}};for(const e of t)r(e.source),r(e.target);return i}function fi(t,e,o){const n=o.get(t),i=o.get(e);return!n||!i||n.partner===i.partner||n.partner===e||i.partner===t}function gi(t,e,o){return!!o.has(t)&&e.some(e=>!fi(t,e,o))}function yi(t,e){return(t.value>0&&Number.isFinite(t.value)?t.value:1)*(1+(1===e.outgoing.get(t.source)?1:0)+(1===e.incoming.get(t.target)?1:0))}function mi(t,e,o,n){if(12>=t.length||1>=n.slotCount)return n.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Map),s=hi(o);for(const t of o){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o||e===o)continue;const n=yi(t,s);r[e].set(o,(r[e].get(o)??0)+n),r[o].set(e,(r[o].get(e)??0)+n)}const a=pi(o),l=t.map(t=>a.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let o=0;t.length-1>o&&5e4>u;o++)if(a.has(t[o]))for(let n=o+1;t.length>n;n++){if(!a.has(t[n]))continue;if(e.conflicts(t[o],t[n]))continue;u++;const i=Math.min(l[o],l[n])||Math.max(l[o],l[n]),r=fi(t[o],t[n],a)?i:-i;if(Math.abs(r)>ci&&(c[o].set(n,r),c[n].set(o,r),u>=5e4))break}const d=[...n.assignment],h=Array.from({length:n.slotCount},()=>[]);d.forEach((t,e)=>h[t].push(e));const p=(t,e,o)=>{const n=d[e],i=d[o];let r=0;const s=new Set;for(const a of[e,o])for(const[l,c]of t[a]){const t=l>a?`${a}:${l}`:`${l}:${a}`;if(s.has(t))continue;s.add(t);const u=(a===e?i:n)===(l===e?i:l===o?n:d[l]);d[a]===d[l]!==u&&(r+=u?c:-c)}return r},f=(t,e,o)=>{let n=0;for(const[i,r]of t[e]){const t=o===d[i];d[e]===d[i]!==t&&(n+=t?r:-r)}return n},g=(t,e)=>t>ci||ci>=Math.abs(t)&&e>ci,y=(t,e,o,n)=>t>o+ci||ci>=Math.abs(t-o)&&e>n+ci;let m=0;for(let o=0;32>o&&li>m;o++){let o=null,n=-1,i=-1,s=-1,a=-1/0,l=-1/0;for(let u=0;t.length>u;u++){for(let p=0;h.length>p&&m++<li;p++){if(p===d[u])continue;if(!h[p].every(o=>!e.conflicts(t[u],t[o])))continue;const m=f(r,u,p),x=f(c,u,p);g(m,x)&&y(m,x,a,l)&&(o="move",n=u,i=-1,s=p,a=m,l=x)}if(m>=li)break}for(let u=0;t.length-1>u;u++){for(let f=u+1;t.length>f&&m++<li;f++){const m=d[u],x=d[f];if(m===x)continue;if(!h[x].every(o=>o===f||!e.conflicts(t[u],t[o])))continue;if(!h[m].every(o=>o===u||!e.conflicts(t[f],t[o])))continue;const b=p(r,u,f),v=p(c,u,f);g(b,v)&&y(b,v,a,l)&&(o="swap",n=u,i=f,s=-1,a=b,l=v)}if(m>=li)break}if(null==o||-1===n)break;if("move"===o){const t=d[n];h[t].splice(h[t].indexOf(n),1),h[s].push(n),d[n]=s;continue}const u=d[n],x=d[i];h[u].splice(h[u].indexOf(n),1,i),h[x].splice(h[x].indexOf(i),1,n),d[n]=x,d[i]=u}return d}function xi(t,e){let o=1/0,n=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass>1e-9&&(o=Math.min(o,e.t),n=Math.max(n,e.t));return Number.isFinite(o)&&Number.isFinite(n)?(null!=e.start&&(o=Math.max(o,e.start)),null!=e.end&&(n=Math.min(n,e.end)),o>n?{start:null,end:null}:{start:o,end:n}):{start:null,end:null}}function bi(t,e,o,n){const i=function(t,e,o,n){return`${t.map(t=>{const e=o[t.id],i=n[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,i?.start??"",i?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,o,n),r=ai.get(i);if(r)return si(r.slots,o,n);const s=Mn();for(const e of t)s[e.id]=xi(o[e.id],n[e.id]);const a=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,o)=>e[t.id].start-e[o.id].start||e[t.id].end-e[o.id].end||_n(t.id,o.id)).map(t=>t.id)}(t,s),l=new Map(t.map(t=>[t.id,t])),c=new Map(t.map(t=>[t.id,t.group||void 0])),u=pi(e),d=function(t,e,o,n,i,r){const s=new Set,a=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of n)s.add(di(t.source,t.target)),a.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=new Map,u=new Set,d=(t,e)=>{for(let o=0;t.length>o;o++)for(let n=o+1;t.length>n;n++){const i=di(t[o],t[n]);e instanceof Map?e.set(i,[t[o],t[n]]):e.add(i)}};for(const t of l.values())d([...t],c);for(const t of a.values())d([...t],u);const h=new Set;for(const[t,[n,i]]of c)u.has(t)&&(ui(e[n],e[i])||ui(o[n],o[i])&&(h.add(n),h.add(i)));return{conflicts:(t,o)=>{const n=i.get(t),a=i.get(o);return null!=n&&null!=a&&n!==a||!(null!=n==(null!=a)||s.has(di(t,o))||r.has(t)&&r.has(o)&&fi(t,o,r))||!!ui(e[t],e[o])||!(!h.has(t)&&!h.has(o))&&!s.has(di(t,o))}}}(a,s,n,e,c,u),h=function(t,e,o=new Map){const n=[],i=[];for(const r of t){let t=n.findIndex(t=>t.every(t=>!e.conflicts(r,t))&&!gi(r,t,o));-1!==t||o.has(r)||(t=n.findIndex(t=>t.every(t=>!e.conflicts(r,t)))),-1===t&&(t=n.length,n.push([])),n[t].push(r),i.push(t)}return{assignment:i,slotCount:n.length}}(a,d,u),p=function(t,e,o,n){if(0===t.length||t.length>12||1>=n.slotCount)return n.assignment;const i=new Map(t.map((t,e)=>[t,e])),r=Array.from({length:t.length},()=>new Float64Array(t.length)),s=Array.from({length:t.length},()=>new Map),a=Array.from({length:t.length},()=>new Map),l=hi(o);for(const t of o){const e=i.get(t.source),o=i.get(t.target);if(null==e||null==o||e===o)continue;const n=yi(t,l);r[e][o]+=n,r[o][e]+=n,a[e].set(o,(a[e].get(o)??0)+n),s[o].set(e,(s[o].get(e)??0)+n)}const c=pi(o),u=t.map(t=>c.get(t)?.weight??0),d=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;t.length>e;e++)for(let o=e+1;t.length>o;o++){for(const[t,n]of s[e])d[e][o]+=Math.min(n,s[o].get(t)??0);for(const[t,n]of a[e])d[e][o]+=Math.min(n,a[o].get(t)??0);if(c.has(t[e])&&c.has(t[o])){const n=Math.min(u[e],u[o])||Math.max(u[e],u[o]);d[e][o]+=fi(t[e],t[o],c)?n:-n}d[o][e]=d[e][o]}let h=[...n.assignment],p=(e=>{let o=0,n=0;for(let i=0;t.length>i;i++)for(let s=i+1;t.length>s;s++)e[i]===e[s]&&(o+=r[i][s],n+=d[i][s]);return{flow:o,affinity:n}})(h),f=0;const g=Array(t.length).fill(-1),y=Array.from({length:n.slotCount},()=>[]),m=(o,i,s,a)=>{if(f>=75e3)return;if(o===t.length)return f++,void((s>p.flow||s===p.flow&&a>p.affinity||s===p.flow&&a===p.affinity&&function(t,e){for(let o=0;Math.min(t.length,e.length)>o;o++)if(t[o]!==e[o])return e[o]>t[o];return e.length>t.length}(g,h))&&(h=[...g],p={flow:s,affinity:a}));const l=Math.min(i+1,n.slotCount-1);for(let n=0;l>=n;n++){if(y[n].some(n=>e.conflicts(t[o],t[n])))continue;let l=0,c=0;for(const t of y[n])l+=r[o][t],c+=d[o][t];if(g[o]=n,y[n].push(o),m(o+1,Math.max(i,n),s+l,a+c),y[n].pop(),g[o]=-1,f>=75e3)return}};return g[0]=0,y[0].push(0),m(1,0,0,0),h}(a,d,e,{...h,assignment:mi(a,d,e,h)}),f=new Map,g=p.map(t=>(f.has(t)||f.set(t,f.size),f.get(t))),y=Array.from({length:f.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=Mn();a.forEach((t,e)=>{const o=g[e],n=y[o];n.occupants.push({id:t,end:s[t].end??-1/0});const i=l.get(t)?.group;i&&(n.group=i),m[t]=o});for(const e of[...t].sort((t,e)=>_n(t.id,e.id)))null==m[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),m[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(s[t.id].start??1/0)-(s[e.id].start??1/0)||_n(t.id,e.id));for(const e of t.occupants){const n=o[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,n?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,n?.botPeak||0)}}const x={slots:y,slotByNode:m};return function(t,e){for(ai.has(t)&&ai.delete(t),ai.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:Object.assign(Mn(),e.slotByNode)});ai.size>12;){const t=ai.keys().next().value;if(null==t)break;ai.delete(t)}}(i,x),x}function vi(t){return t.topMass+t.botMass}function wi(t,e){const o=t.samples.filter(t=>t.t===e);if(o.length>0)return o.reduce((t,e)=>vi(e)<vi(t)?t:e,o[0]);let n=null;for(const o of t.samples){if(o.t>e)break;n=o}return n}function ki(t,e,o,n,i,r,s=0){const a=new Map;for(const o of t){if(!o.group||!e[o.id])continue;const t=a.get(o.group)??[];t.push(o),a.set(o.group,t)}if(0===a.size||0>=r)return e;const l=Object.fromEntries(Object.entries(e).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}]));for(const[t,c]of a){const a=o.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===a.length)continue;const u=a[0].slot,d=a.at(-1).slot,h=i[u.occupants[0]?.id],p=i[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(p))continue;const f=(h-u.peak.topPeak*r+(p+d.peak.botPeak*r))/2,g=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),y=new Map;for(const t of c)y.set(t.id,new Map);for(const t of g){const o=new Map;for(const i of c){const r=wi(e[i.id],t);if(!r||1e-9>=vi(r))continue;const s=n[i.id];if(null==s)continue;const a=o.get(s)??[];a.push({node:i,sample:r}),o.set(s,a)}const a=[...o].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>vi(t)))}));if(0===a.length)continue;let l=f-(a.reduce((t,e)=>t+e.mass,0)*r+Math.max(0,s)*Math.max(0,a.length-1))/2;for(const e of a){for(const{node:o,sample:n}of e.active){const e=(l-i[o.id])/r+n.topMass-(n.boundaryOffset??0);y.get(o.id).set(t,e)}l+=e.mass*r+Math.max(0,s)}}for(const t of c){const o=e[t.id],n=l[t.id],i=y.get(t.id),r=[];for(const t of g){const e=i.get(t),n=o.samples.filter(e=>e.t===t);if(n.length>0){r.push(...n.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const s=wi(o,t);null!=e&&s&&vi(s)>1e-9&&r.push({...s,t:t,boundaryOffset:(s.boundaryOffset??0)+e})}n.samples=r,n.localAttachments=new Map([...o.localAttachments].map(([t,e])=>{const o=i.get(e.time);return[t,{...e,...null!=o?{boundaryOffset:(e.boundaryOffset??0)+o}:{}}]}))}}return l}function Ai(t,e,o,n,i){const{plotH:r,padding:s,valueScale:a,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:p="both",domain:f}=i,g=Mn(),y=Mn();for(const e of t)g[e.id]=o[e.id].topPeak||0,y[e.id]=o[e.id].botPeak||0;const m="half"===u,x=Mn();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,o=Array.isArray(e.xExtent)?e.xExtent[1]:null;let i=null!=t&&Number.isFinite(t)?t:1/0,r=null!=o&&Number.isFinite(o)?o:-1/0;for(const t of n.outgoing[e.id]){i>t.startTime&&(i=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&i>t.systemInTime&&(i=t.systemInTime);const e=m?(t.startTime+t.endTime)/2:t.endTime;e>r&&(r=e)}for(const t of n.incoming[e.id]){const e=m?(t.startTime+t.endTime)/2:t.startTime;i>e&&(i=e),t.endTime>r&&(r=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>r&&(r=t.systemOutTime)}x[e.id]={start:Number.isFinite(i)?i:null,end:Number.isFinite(r)?r:null}}let b=Mn(),v=[],w=[];if(i.frozenSlots){const t=si(i.frozenSlots,o,x);v=t.slots,b=t.slotByNode,w=v.map(Pn)}else if("reuse"===l){const n=bi(t,e,o,x);v=n.slots,b=n.slotByNode}else t.forEach((t,e)=>{v.push({occupants:[{id:t.id,end:x[t.id]?.end??-1/0}],peak:{topPeak:g[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),b[t.id]=e});Zn(v,b),0===w.length&&(w=v.map(Pn));let k=null;i.frozenSlots||(i.fixedSlotOrder?function(t,e,o){const n=new Map(o.map((t,e)=>[t,e]));Vn(t,e,[...t].sort((t,e)=>(n.get(Pn(t))??1/0)-(n.get(Pn(e))??1/0)||_n(Pn(t),Pn(e))))}(v,b,i.fixedSlotOrder):i.runOrdering&&c&&"insertion"!==c&&(k=ri(t,e,o,x,v,b,{plotH:r,padding:s,valueScale:a,groupPadding:h,laneOrder:c,ribbonLane:p,domain:f}))),Zn(v,b);const A=Tn(t,e,o,v,b,{plotH:r,padding:s,valueScale:a,stackValueScale:i.stackValueScale,lanePlacement:d,groupPadding:h}),S=0===v.length?0:v[0].peak.topPeak+A.adjacentClearance.reduce((t,e)=>t+e,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,L=k?.after.weightedLength??null;return{effectiveSlotsHeight:S,centerlines:A.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:A.slotCenter,stackCenter:A.stackCenter,verticalUtilization:A.verticalUtilization,selectedSlotOrder:v.map(Pn),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function Si(t){const{sx:e,sTop:o,sBot:n,tx:i,tTop:r,tBot:s,cp1X:a,cp2X:l}=t,c=(o+n)/2,u=(r+s)/2;return{pathD:[`M${e},${o}`,`C${a},${o} ${l},${r} ${i},${r}`,`L${i},${s}`,`C${l},${s} ${a},${n} ${e},${n}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:a,y:c},{x:l,y:u},{x:i,y:u}],halfWidth:(n-o)/2}}}function Mi(t,e,o,n,i,r,s,a,l={}){const c=i,u=t=>a?Math.max(a[0],Math.min(a[1],t)):t;let d=r(u(t.time));const h=r(u(o.time)),p=t.value*c,f=o.value*c,g=e+(t.boundaryOffset??0)*c,y=n+(o.boundaryOffset??0)*c,m=t.sideMassBefore*c,x=o.sideMassAfter*c;let b,v,w,k;"top"===t.side?(b=g-m,v=b+p):(v=g+m,b=v-p),"top"===o.side?(w=y-x,k=w+f):(k=y+x,w=k-f);const A=l.sourceRunwayStart,S=l.minRun,M=Math.abs((w+k)/2-(b+v)/2),_=h-d,P="number"==typeof A&&Number.isFinite(A),L="number"==typeof S&&Number.isFinite(S)&&S>0;if(P&&M>1e-9&&_>0&&("auto"===S||L)){const e="source"===s?.85:"target"===s?.15:.5,o="auto"===S?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(e*e,(1-e)*(1-e))))):S;if(o>_){const e=r(u(Math.min(A,t.time)));Number.isFinite(e)&&(d=Math.min(d,Math.max(Math.min(d,e),h-o)))}}const $="source"===s?d+.85*(h-d):"target"===s?d+.15*(h-d):(d+h)/2;return{sx:d,sTop:b,sBot:v,tx:h,tTop:w,tBot:k,cp1X:$,cp2X:$}}function _i(t){return Math.max(18,11*t.length*.58)}function Pi(t){const e=1.22*_i(t.labelText)+4;return"start"===t.labelAnchor?[t.labelX,t.labelX+e]:"middle"===t.labelAnchor?[t.labelX-e/2,t.labelX+e/2]:[t.labelX-e,t.labelX]}function Li(t,e){const o=t.labelX-_i(t.labelText),n=e.labelX-_i(e.labelText);return e.labelX+3>=o&&t.labelX+3>=n}var $i=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function Ri(t){return t.replace($i,(t,e,o)=>`${o},${e}`)}function Ci(t){if(!t)return;const e=t=>({x:t.y,y:t.x});return{...t,...t.points&&{points:t.points.map(e)},...t.segments&&{segments:t.segments.map(t=>t.map(e))}}}function Ti(t){return{...t,pathD:Ri(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function Oi(t){const{nodes:e,edges:o,domain:n,plotW:i,plotH:r,ribbonLane:s,ribbonMinRun:a=0,edgeOpacity:l,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:p,maxLabels:f,selectionDatum:g="raw",styleRules:y,colorBy:m,valueAccessor:x,usageMode:b="static"}=t,v="vertical"===d?r:i,w="vertical"===d?i:r,k=function(t,e,o,n={}){const i=wn(n.usageMode??"static"),r=[],s=new Set;for(const e of t)s.has(e.id)&&r.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),s.add(e.id);const a=new Set,l=Array.isArray(o)&&2===o.length,c=l&&Number.isFinite(o[0])&&Number.isFinite(o[1]);l&&c&&c&&o[1]>=o[0]||r.push({kind:"invalid-domain"});for(const e of t)null!=e.xExtent&&(Array.isArray(e.xExtent)&&2===e.xExtent.length&&Number.isFinite(e.xExtent[0])&&Number.isFinite(e.xExtent[1])&&e.xExtent[1]>=e.xExtent[0]||r.push({kind:"invalid-node-time",id:e.id}));for(const t of e)a.has(t.id)&&r.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),a.add(t.id),s.has(t.source)||r.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),s.has(t.target)||r.push({kind:"missing-node",id:t.id,endpoint:"target",nodeId:t.target}),Number.isFinite(t.startTime)&&Number.isFinite(t.endTime)?((null!=t.systemInTime&&!Number.isFinite(t.systemInTime)||null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime))&&r.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),Number.isFinite(t.value)&&t.value>0||r.push({kind:"invalid-value",id:t.id}),t.startTime>t.endTime&&r.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):r.push({kind:"invalid-edge-time",id:t.id});return r}(e,o,n,{usageMode:b}),{fatal:A,warnings:S}=function(t){const e=[],o=[];for(const n of t)"fatal"===An(n)?e.push(n):o.push(n);return{fatal:e,warnings:o}}(k),M=function(t,e,o="static"){if("strip"!==wn(o).invalidSystemTime)return t;const n=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===n.size?t:t.map(t=>{if(!n.has(t.id))return t;const e={...t};return null==e.systemInTime||Number.isFinite(e.systemInTime)||delete e.systemInTime,null==e.systemOutTime||Number.isFinite(e.systemOutTime)||delete e.systemOutTime,e})}(o,k,b),_=bn().domain(n).range([0,v]);if(A.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:A,warnings:S,xScale:_};const P=function(t,e,o){const{plotH:n,pairing:i="temporal",packing:r="reuse",laneOrder:s="crossing-min",lifetimeMode:a="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:p}=o,f=Number.isFinite(d)?Math.max(0,d):0,g=function(t,e){const o=Mn(),n=Mn();for(const e of t)o[e.id]=[],n[e.id]=[];for(const t of e)n[t.source]&&n[t.source].push(t),o[t.target]&&o[t.target].push(t);return{incoming:o,outgoing:n}}(t,e),y=function(t,e,o,n="temporal"){const i="temporal"===n?(t,e)=>t.endTime-e.endTime||_n(t.id,e.id):(t,e)=>e.value-t.value||_n(t.id,e.id),r="temporal"===n?(t,e)=>t.startTime-e.startTime||_n(t.id,e.id):(t,e)=>e.value-t.value||_n(t.id,e.id),s=new Map;for(const t of e)s.set(t.id,{});const a=(t,e)=>{const o=new Map;for(const n of t){const t=n[e];o.has(t)||o.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const i=o.get(t);i.edges.push(n),i.total+=n.value,i.earliestStart=Math.min(i.earliestStart,n.startTime),i.latestEnd=Math.max(i.latestEnd,n.endTime)}const s=[...o.values()];s.sort("temporal"===n?(t,o)=>"target"===e?t.earliestStart-o.earliestStart||_n(t.partner,o.partner):t.latestEnd-o.latestEnd||_n(t.partner,o.partner):(t,e)=>e.total-t.total||_n(t.partner,e.partner));for(const t of s)t.edges.sort("target"===e?r:i);return s};for(const e of t){const t=o.outgoing[e.id],n=o.incoming[e.id];if(0===n.length)a(t,"target").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).sourceSide=o});else if(0===t.length)a(n,"source").forEach((t,e)=>{const o=e%2==0?"top":"bot";for(const e of t.edges)s.get(e.id).targetSide=o});else{const e=a(n,"source"),o=a(t,"target"),i=Math.max(e.length,o.length);for(let t=0;i>t;t++){const n=t%2==0?"top":"bot";if(e[t])for(const o of e[t].edges)s.get(o.id).targetSide=n;if(o[t])for(const e of o[t].edges)s.get(e.id).sourceSide=n}}}return s}(t,e,g,i);let m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,void 0,u);const x=Ai(t,e,m,g,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,runOrdering:!0,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),b=x.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),v=new Set;for(const t of e){const e=x.slotByNode[t.source],o=x.slotByNode[t.target];if(void 0===e||void 0===o)continue;const n=y.get(t.id);e!==o?e>o?(n.sourceSide="top",n.targetSide="bot"):(n.sourceSide="bot",n.targetSide="top"):(v.add(t.id),n.sourceSide="bot",n.targetSide="bot")}for(const e of t){const t=g.outgoing[e.id],o=g.incoming[e.id],n=new Set(t.map(t=>y.get(t.id).sourceSide)),i=new Set(o.map(t=>y.get(t.id).targetSide));if(1===n.size&&o.length>0){const t=[...n][0];for(const e of o)x.slotByNode[e.source]===x.slotByNode[e.target]&&(y.get(e.id).targetSide=t)}if(1===i.size&&t.length>0){const e=[...i][0];for(const o of t)x.slotByNode[o.source]===x.slotByNode[o.target]&&(y.get(o.id).sourceSide=e)}}!function(t,e,o){const n=new Map,i=[];for(const e of t)i.push({time:e.startTime,kind:"out",edge:e}),i.push({time:e.endTime,kind:"in",edge:e});i.sort((t,e)=>t.time-e.time||(t.kind===e.kind?0:"in"===t.kind?-1:1)||("out"===t.kind?e.edge.value-t.edge.value:0)||_n(t.edge.id,e.edge.id));const r=t=>{let e=n.get(t);return e||(e={top:0,bot:0},n.set(t,e)),e},s=(t,e,o)=>{const n="top"===e?"bot":"top",i=Math.min(o,t[e]);t[e]-=i;const r=o-i;r>0&&(t[n]=Math.max(0,t[n]-r))};for(const t of i){const{edge:n}=t;if("in"===t.kind){const t=e.get(n.id)?.targetSide??"bot";r(n.target)[t]+=n.value;continue}const i=r(n.source),a=e.get(n.id);let l=a.sourceSide??"bot";if(o[n.source]===o[n.target]){const t=i.top>=n.value,e=i.bot>=n.value;t!==e?l=t?"top":"bot":t||e||i.top===i.bot||(l=i.top>i.bot?"top":"bot"),a.sourceSide=l,a.targetSide=l}s(i,l,n.value)}}(e,y,x.slotByNode),function(t,e,o,n){for(const i of t){const t=e.incoming[i.id],r=e.outgoing[i.id];if(0===t.length||0===r.length)continue;const s=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const n of t)"top"===o.get(n.id).targetSide?e.inTop+=n.value:e.inBot+=n.value;for(const t of r)"top"===o.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},a=(t,e)=>{const i=s(),a="top"===t?i.outTop-i.inTop:i.outBot-i.inBot,l="top"===e?i.inTop-i.outTop:i.inBot-i.outBot;if(0>=a||0>=l)return!1;const c=Math.min(a,l),u=r.filter(e=>!n.has(e.id)&&o.get(e.id).sourceSide===t&&c>=e.value).sort((t,e)=>e.value-t.value||_n(t.id,e.id));return 0!==u.length&&(o.get(u[0].id).sourceSide=e,!0)};let l=r.length+1;for(;l-- >0&&(a("top","bot")||a("bot","top")););}}(t,g,y,v),m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,void 0,u);const w=Ai(t,e,m,g,{plotH:n,padding:12,valueScale:1,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:"stack",groupPadding:f,ribbonLane:h,domain:p}),k=w.effectiveSlotsHeight??w.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),A=w.slots.slice(0,-1).reduce((t,e,o)=>t+(null!=e.group&&e.group===w.slots[o+1].group?1:0),0),S=Math.max(1,w.slots.length+1-A),M=Math.min(12,Math.max(0,.35*n-A*f)/S),_=2*M+Ln(w.slots,M,f).reduce((t,e)=>t+e,0),P=k>0?Math.max(0,(n-_)/k):1,L=Number.isFinite(l)&&l>0?Math.min(P,l):P;let $=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:b,lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P});const R=Number.isFinite(l)&&l>0&&P>l+1e-12;if("insertion"!==s&&("hug"===c||R)&&$.slots.length>1&&(ri(t,e,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:n,padding:M,valueScale:L,groupPadding:f,laneOrder:s,ribbonLane:h,domain:p,lanePlacement:c,mode:"geometry-refine"}),$=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Pn),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P})),function(t,e){const o=(t,o)=>{for(const n of t){const t=new Map;for(const i of n){const n=`${("out"===o?e.get(i.id)?.sourceSide:e.get(i.id)?.targetSide)??""}\0${"out"===o?i.startTime:i.endTime}`,r="out"===o?`${i.target}\0${i.endTime}`:`${i.source}\0${i.startTime}`,s=t.get(n);if(null!=s&&s!==r)return!0;t.set(n,r)}}return!1};return o(Object.values(t.outgoing),"out")||o(Object.values(t.incoming),"in")}(g,y)){const o=function(t,e,o,n){const i=new Map;for(const r of t){const t=e[r.source]?.localAttachments.get(r.id),s=e[r.target]?.localAttachments.get(r.id),a=o[r.source],l=o[r.target];if(!(t&&s&&Number.isFinite(a)&&Number.isFinite(l)))continue;const c=Yn(t,a,n),u=Yn(s,l,n);i.set(r.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return i}(e,m,$.centerlines,L);m=Mn();for(const e of t)m[e.id]=Xn(e,g,y,o,u);$=Ai(t,e,m,g,{plotH:n,padding:M,valueScale:L,packing:r,laneOrder:s,lifetimeMode:a,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(Pn),lanePlacement:c,groupPadding:f,ribbonLane:h,domain:p,stackValueScale:P})}const C=new Map(x.initialSlotOrder.map((t,e)=>[t,e])),T=[...$.slots].sort((t,e)=>(C.get(Pn(t))??1/0)-(C.get(Pn(e))??1/0)||_n(Pn(t),Pn(e))),O=Mn();T.forEach((t,e)=>{for(const o of t.occupants)O[o.id]=e});const I=Tn(t,e,m,T,O,{plotH:n,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:f}),z=ki(t,m,T,O,I.centerlines,L,f),F=Wn(Jn(O,e),ti(O,e),e,z,T,O,I.centerlines,$.laneLifetime,L,I.verticalUtilization,h,p);m=ki(t,m,$.slots,$.slotByNode,$.centerlines,L,f);const N=Wn(Jn($.slotByNode,e),ti($.slotByNode,e),e,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,p);return{nodeData:m,sides:y,valueScale:L,padding:M,compressedPadding:12>M,centerlines:$.centerlines,laneLifetime:$.laneLifetime,slots:$.slots,slotByNode:$.slotByNode,crossingsBefore:"insertion"===s?null:F.crossings,crossingsAfter:"insertion"===s?null:N.crossings,lengthBefore:"insertion"===s?null:F.weightedLength,lengthAfter:"insertion"===s?null:N.weightedLength,layoutQualityBefore:F,layoutQuality:N}}(e,M,{plotH:w,...u,ribbonLane:s,domain:n}),{centerlines:L,nodeData:$,valueScale:R}=P,C=rt(m,x),T=[],O=[],I=0===a?new Map:function(t,e,o){const n=new Set(e.map(t=>t.target)),i=new Map(t.map(t=>[t.id,t])),r=new Map;for(const t of e){if(n.has(t.source))continue;const e=r.get(t.source)??[];e.push(t),r.set(t.source,e)}const s=new Map;for(const e of t){if(!e.group)continue;const t=s.get(e.group)??[];t.push(e),s.set(e.group,t)}const a=new Set;for(const[t,e]of s){const o=e.flatMap(t=>r.get(t.id)??[]),i=new Set(o.map(t=>t.startTime));o.length>0&&1===i.size&&e.every(t=>{const e=t.xExtent?.[0],i=o[0].startTime;return!n.has(t.id)&&(r.get(t.id)?.length??0)>0&&Number.isFinite(e)&&i>e})&&a.add(t)}const l=new Map;for(const[t,e]of r){const n=i.get(t);if(n?.group&&!a.has(n.group))continue;const r=n?.xExtent?.[0],s=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),c=s[0]?.startTime-1;let u=null;for(let t=0;s.length>t;){const e=s[t].startTime;let n=t+1;for(;s.length>n&&s[n].startTime===e;)n++;for(let e=t;n>e;e++){const t=s[e],n=Number.isFinite(r)&&t.startTime>r,i=Number.isFinite(t.systemInTime)&&t.startTime>t.systemInTime;if(!n&&!i)continue;let a=o[0];n&&(a=Math.max(a,r)),i&&(a=Math.max(a,t.systemInTime)),!n&&i&&Number.isFinite(c)&&(a=Math.max(a,c)),null!=u&&(a=Math.max(a,u)),t.startTime>a&&l.set(t.id,a)}u=e,t=n}}for(const[t,e]of s){if(!a.has(t))continue;const o=e.flatMap(t=>r.get(t.id)??[]);if(!o.every(t=>l.has(t.id))){for(const t of o)l.delete(t.id);continue}const n=Math.max(...o.map(t=>l.get(t.id)));for(const t of o)l.set(t.id,n)}return l}(e,M,n),z=new Map(e.filter(t=>t.group).map(t=>[t.id,t.group])),F=new Map;for(const t of M){const e=$[t.source]?.localAttachments.get(t.id),o=$[t.target]?.localAttachments.get(t.id);e&&o&&F.set(t.id,Mi(e,L[t.source],o,L[t.target],R,_,s,n,{minRun:a,sourceRunwayStart:I.get(t.id)}))}const N=function(t,e,o,n,i,r){const s=new Map(e),a=new Map;for(const e of t){const t=r?.get(e.source),o=null==t?"node:"+e.source:"group:"+t,n=a.get(o)??new Map,i=n.get(e.startTime)??[];i.push(e),n.set(e.startTime,i),a.set(o,n)}for(const t of a.values())for(const[r,a]of t){if(!a.some(t=>o.has(t.id)))continue;const t=a.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const l=n(r),c=Math.min(...t.map(t=>t.sx));if(c>=l-1e-9)continue;const u=Math.max(...a.map(t=>{const e=o.get(t.id);return null==e?l:Math.min(l,n(e))})),d=Math.min(l,Math.max(c,u));for(const t of a){const o=e.get(t.id),n=d+(o.tx-d)*("source"===i?.85:"target"===i?.15:.5);s.set(t.id,{...o,sx:d,cp1X:n,cp2X:n})}}return s}(M,F,I,_,s,z),E=function(t,e,o,n,i){const r=new Map;for(const s of t){if(!o.has(s.id))continue;const t=e.get(s.id);if(!t||t.sx>=n(s.startTime)-1e-9)continue;const a=i(t.sx);Number.isFinite(a)&&s.startTime>a&&r.set(s.id,a)}return r}(M,N,I,_,t=>n[0]+t/v*(n[1]-n[0])),D=function(t,e,o){const n=new Map,i=new Map;for(const[t,e]of o??[]){const o=i.get(e)??[];o.push(t),i.set(e,o)}for(const r of t){const t=e.get(r.id);if(null==t||!Number.isFinite(t)||t>=r.startTime)continue;const s=o?.get(r.source),a=null==s?[r.source]:i.get(s)??[r.source];for(const e of a){const o=n.get(e)??new Map,i=o.get(r.startTime);o.set(r.startTime,null==i?t:Math.min(i,t)),n.set(e,o)}}return n}(M,E,z);e.forEach((t,e)=>{const o=$[t.id];if(!o||0===o.samples.length)return;const i=(r=o.samples,(s=D.get(t.id))&&0!==s.size?r.map(t=>{const e=s.get(t.t);return null==e?t:{...t,t:e}}):r);var r,s;const a=function(t,e,o,n,i){if(0===t.length)return null;const r=jn(t,i),s=t=>e+(r[t].boundaryOffset??0)*o,a=t=>s(t)-r[t].topMass*o,l=t=>s(t)+r[t].botMass*o;let c=`M${n(r[0].t)},${a(0)}`;for(let t=1;r.length>t;t++)c+=` L${n(r[t].t)},${a(t)}`;c+=` L${n(r[r.length-1].t)},${l(r.length-1)}`;for(let t=r.length-2;t>=0;t--)c+=` L${n(r[t].t)},${l(t)}`;return c+" Z"}(i,L[t.id],R,_,n);if(!a)return;const l=jn(i,n),u=l.find(t=>t.topMass+t.botMass>0)||l[0],h=L[t.id]+(u.botMass-u.topMass+2*(u.boundaryOffset??0))*R/2;let p,f,g=c(t.id,e),m=g,x=.5;const b=t.__raw??t;if(y&&y.length>0){const t=dt(b,y,C(b));"string"==typeof t.fill?g=t.fill:null!=t.fill&&ot(t.fill)&&(f=t.fill,g=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:g),"string"==typeof t.stroke&&(m=t.stroke),"number"==typeof t.strokeWidth&&(x=t.strokeWidth),"number"==typeof t.fillOpacity&&(p=t.fillOpacity),"number"==typeof t.opacity&&null==p&&(p=t.opacity)}const v=function(t,e,o,n,i,r){const s=o.nodeData[t];if(!s||0===s.samples.length)return[];const a=o.valueScale,l=o.centerlines[t],c=jn(s.samples,i),u=c.find(t=>t.topMass+t.botMass>0)||c[0],d=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],h=n(u.t),p=n(d.t),f=t=>n(Bn(t,i)),g=[],y=(t,e,o,n)=>`M${t},${e} L${o},${e} L${o},${n} L${t},${n} Z`;for(const o of e){if(o.source===t&&null!=o.systemInTime&&Number.isFinite(o.systemInTime)){const t=s.localAttachments.get(o.id),e=r?.get(o.id)??o.startTime;if(t&&"out"===t.kind&&e>o.systemInTime){const n=f(o.systemInTime),r=f(e),s=null!=i&&i[0]>o.systemInTime,c=s?n:n-20,u=s?Math.min(r,n+20):n,d=Math.max(h,c);if(r>d){const[e,o]=Yn(t,l,a);g.push({pathD:y(d,e,r,o),x0:c,x1:u,from:0,to:1})}}}if(o.target===t&&null!=o.systemOutTime&&Number.isFinite(o.systemOutTime)){const t=s.localAttachments.get(o.id);if(t&&"in"===t.kind&&o.systemOutTime>o.endTime){const e=f(o.systemOutTime),n=f(o.endTime),i=e+20,r=Math.min(p,i);if(r>n){const[o,s]=Yn(t,l,a);g.push({pathD:y(n,o,r,s),x0:e,x1:i,from:1,to:0})}}}}return g}(t.id,M,P,_,n,E);T.push({id:t.id,pathD:a,fill:g,stroke:m,strokeWidth:x,...null!=p&&{fillOpacity:p},...f&&{hatchFill:f},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&t.xExtent?t.xExtent[0]:u.t)-4,labelY:h,labelText:t.label??t.id})});const W=new Map;e.forEach((t,e)=>W.set(t.id,e)),M.forEach(t=>{const e=N.get(t.id);if(!e)return;const o=W.get(t.source)??0,n=c(t.source,o),{pathD:i,bezier:r}=Si(e),s=t.__raw??t,a="function"==typeof l?Number(l(s)):l,u=Number.isFinite(a)?Math.max(0,Math.min(1,a)):.35;O.push({id:t.id,pathD:i,fill:n,opacity:u,rawDatum:s,bezier:r})});const B=function(t,e,o){const n=t.map(t=>({...t})),i=new Map;for(const t of n){const o=e[t.id];if(null==o)continue;const n=i.get(o)??[];n.push(t),i.set(o,n)}const r=t=>{if(2>t.length)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,n=(t.length-1)/2;t.forEach((t,i)=>{t.labelY=Math.max(8,Math.min(o-8,e+16*(i-n)))})};for(const t of i.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],o=-1/0;for(const n of t){const t=n.labelX-_i(n.labelText);e.length>0&&t>o+3&&(r(e),e=[],o=-1/0),e.push(n),o=Math.max(o,n.labelX)}r(e)}return function(t,e){const o=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;3>t;t+=1){for(let t=0;o.length>t;t+=1){let e=8;for(let n=0;t>n;n+=1)Li(o[t],o[n])&&(e=Math.max(e,o[n].labelY+16));o[t].labelY=Math.max(o[t].labelY,e)}for(let t=o.length-1;t>=0;t-=1){let n=e-8;for(let e=t+1;o.length>e;e+=1)Li(o[t],o[e])&&(n=Math.min(n,o[e].labelY-16));o[t].labelY=Math.min(o[t].labelY,n)}}}(n,o),n}(T,P.slotByNode,w).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ri(t.pathD),gradientStubs:t.gradientStubs?.map(Ti),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,d)),j="vertical"===d?function(t,e,o){const n=t.map(t=>({...t}));for(const t of n){const o=1.22*_i(t.labelText)+4;t.labelX=e-4>o?Math.max(o/2+2,Math.min(e-o/2-2,t.labelX)):e/2}const i=[],r=[...n].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of r){const e=i[i.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?i.push([t]):e.push(t)}for(const t of i){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],n=new Map;for(const o of t){const[t,i]=Pi(o);let r=e.findIndex(e=>t>e+8);-1===r&&(r=e.length),e[r]=i,n.set(o,r)}const i=t.reduce((t,e)=>t+e.labelY,0)/t.length,r=14*e.length+8>i;for(const e of t){const t=n.get(e)??0;e.labelY=r?Math.min(o-8,12+14*t):Math.max(8,i-14*t)}}return n}(B,i,r):B,Y=new Map;if(null!=p)for(const t of e){const e=t.__raw??t,o="function"==typeof p?p(e):Number(e[p]);Number.isFinite(o)&&Y.set(t.id,o)}const X=function(t,e,o,n,i={}){if(!1===n)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===n)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));let r=Math.max(4,Math.min(t.length,Math.floor(Math.max(1,e*o)/14e3)));Number.isFinite(i.maxLabels)&&i.maxLabels>=0&&(r=Math.min(r,Math.floor(i.maxLabels)));const s=t.map((t,e)=>{const o=i.priorityById?.get(t.id),n=Math.abs(t.labelY);return{band:t,index:e,score:null!=o&&Number.isFinite(o)?1e6*o+_i(t.labelText):_i(t.labelText)+.01*n}}).filter(t=>t.band.labelText.trim().length>0).sort((t,e)=>e.score-t.score||t.index-e.index||t.band.id.localeCompare(e.band.id)),a=new Set(s.slice(0,r).map(t=>t.band.id));return t.map(t=>a.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(j,i,r,h,{...Y.size>0&&{priorityById:Y},...null!=f&&{maxLabels:f}});return{layout:P,layoutConfig:{bands:X,ribbons:O.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:Ri(t.pathD),bezier:Ci(t.bezier)}}(t,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:S,xScale:_}}import{Fragment as Ii,jsx as zi,jsxs as Fi}from"react/jsx-runtime";var Ni="var(--semiotic-grid, #94a3b8)",Ei="var(--semiotic-text-secondary, #475569)",Di="var(--semiotic-text-secondary, #94a3b8)",Wi=.22;function Bi(t,e,o){return!e?.isActive||e.predicate(function(t,e){return"scene"===e?t:t.data}(t,o))}var ji=t=>{const{bands:e=[],ribbons:o=[],showLabels:n=!0,selectionDatum:i="raw"}=t.config,r=t.selection??null,s=[];for(const t of o){const e={__kind:"ribbon",data:t.rawDatum,id:t.id},o=!Bi(e,r,i);s.push({type:"bezier",pathD:t.pathD,...t.bezier&&{bezierCache:t.bezier},style:{fill:t.fill,opacity:o?Math.min(t.opacity,Wi):t.opacity,stroke:"none"},datum:e})}for(const t of e){if(!t.gradientStubs)continue;const e=!Bi({__kind:"band",data:t.rawDatum,id:t.id},r,i);for(let o=0;t.gradientStubs.length>o;o++){const n=t.gradientStubs[o];s.push({type:"bezier",pathD:n.pathD,interactive:!1,style:{fill:t.fill,fillOpacity:e?Wi:t.fillOpacity??.86,stroke:"none"},_gradient:{x0:n.x0,x1:n.x1,...null!=n.y0&&{y0:n.y0},...null!=n.y1&&{y1:n.y1},from:n.from,to:n.to},datum:{__kind:"band",data:t.rawDatum,id:`${t.id}__stub${o}`}})}}for(const t of e){const e=!(!t.gradientStubs||0>=t.gradientStubs.length),o={__kind:"band",data:t.rawDatum,id:t.id},n=!Bi(o,r,i);s.push({type:"bezier",pathD:t.pathD,style:{...e?{fill:"none"}:{fill:t.hatchFill??t.fill,fillOpacity:n?Wi:t.fillOpacity??.86},stroke:t.stroke??("string"==typeof t.fill?t.fill:"#666"),strokeWidth:t.strokeWidth??.5,...n&&e?{opacity:Wi}:{}},datum:o})}const a=n?e.flatMap(t=>{const e=t.labelDeferred&&t.labelFullText?.trim(),o=t.labelText.trim().length>0,n=e&&r?.isActive&&Bi({__kind:"band",data:t.rawDatum,id:t.id},r,i),s=o?t.labelText:n?t.labelFullText:"";return s.trim()?[{x:t.labelX,y:t.labelY,text:s,anchor:t.labelAnchor??"end",baseline:t.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:e.map(t=>({type:"circle",id:t.id,cx:-1e4,cy:-1e4,r:0,style:{fill:t.fill},datum:{__kind:"band",data:t.rawDatum,id:t.id}})),sceneEdges:s,labels:a}};function Yi(t,e){if(!t)return[];const o=[],n=t=>{o.push(t);const i="function"==typeof e?e(t):t[e];i&&Array.isArray(i)&&i.forEach(n)};return n(t),o}function Xi(t,e,o,n){if(t&&t.length>0)return t;const i=new Set;return e.forEach(t=>{const e="function"==typeof o?o(t):t[o],r="function"==typeof n?n(t):t[n];i.add(e),i.add(r)}),Array.from(i).map(t=>({id:t}))}function Gi(t,e,o={}){return ae(e?"function"==typeof e?o=>({...t(o),...e(o)??{}}):o=>({...t(o),...e}):t,o)}var Vi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{if(!(e||Array.isArray(i.styleRules)&&i.styleRules.length>0||n.nodeStyle||i.nodeStyle||se(fe(i))))return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:o,...n};const r=Array.isArray(i.edges)?i.edges:[],s=Array.isArray(i.nodes)&&i.nodes.length>0?i.nodes:Xi([],r,i.sourceAccessor||"source",i.targetAccessor||"target"),a=ye(n.theme).colors.categorical,l=Qt(o,a),c="string"==typeof e?e:"__ssrChordColorBy",u="function"==typeof e?s.map(t=>({...t,__ssrChordColorBy:e(t)})):s,d=e?ie(u,c,o??n.colorScheme??a):void 0,h=new Map,p=i.nodeIdAccessor||i.nodeIDAccessor||"id",f=(t,o)=>{const n=t?.data||t;let r;if(e)r=oe(n,e,d);else{const e=(t.id??n?.[p]??"")+"";h.has(e)||h.set(e,h.size);const i=t.index??o??h.get(e);r=l[i%l.length]}return{fill:r,stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},g=pt(i.styleRules,e,i.valueAccessor);return{chartType:"chord",nodes:i.nodes,edges:i.edges,valueAccessor:i.valueAccessor,padAngle:i.padAngle,groupWidth:i.groupWidth,showLabels:i.showLabels,colorBy:e,edgeColorBy:i.edgeColorBy,colorScheme:o,nodeStyle:ae(i.nodeStyle||(g?(t,e)=>({...f(t,e),...g(t,e)}):f),fe(i)),...n}}},Hi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=function(t){if(void 0!==t.edgeStyle)return t.edgeStyle;const{edgeWidth:e,edgeColor:o,edgeOpacity:n}=t,i=t.strokeWidth??1;return void 0!==e||void 0!==o||void 0!==n||void 0!==t.stroke||void 0!==t.strokeWidth||void 0!==t.opacity?r=>{const s=r?.data||r;let a=i;if("number"==typeof e)a=e;else if("function"==typeof e)a=e(s);else if("string"==typeof e){const t=s?.[e],o="number"==typeof t?t:Number(t);a=Number.isFinite(o)&&o>0?o:i}return{stroke:o??t.stroke??"#999",strokeWidth:a,opacity:n??t.opacity??.6}}:void 0}(i),s=ye(n.theme).colors.categorical,a=new Map,l=i.nodeStyle??(t=>({fill:e?oe(t?.data||t,e,void 0):uo(void 0,s,o,void 0,a),..."number"==typeof i.nodeSize&&{r:i.nodeSize}})),c=pt(i.styleRules,e,"number"==typeof i.nodeSize?void 0:i.nodeSize),u=ae(c?(t,e)=>({...l(t),...c(t,e)}):l,{stroke:i.nodeStroke??i.stroke,strokeWidth:i.nodeStrokeWidth??i.strokeWidth,opacity:i.opacity});return{chartType:"force",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,colorBy:e,colorScheme:o,iterations:i.iterations,forceStrength:i.forceStrength,showLabels:i.showLabels??!1,nodeLabel:i.nodeLabel,nodeSize:i.nodeSize??8,nodeSizeRange:i.nodeSizeRange,nodeStyle:u,edgeStyle:r,...n}}},qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrCirclePackColorBy:l(t)})):a,u=l?"__ssrCirclePackColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"circlepack",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,nodeLabel:i.showLabels??n.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrCirclePackColorBy:l(n)},"__ssrCirclePackColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),fillOpacity:i.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},h,fe(i))}}},Ui={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=t??i.data,s=i.childrenAccessor||"children",a=i.nodeIdAccessor||i.nodeIDAccessor||"name",l=ye(n.theme).colors.categorical,c=o??n.colorScheme??l,u=Qt(c,l),d=Yi(r,s),h="__ssrOrbitColorBy",p="function"==typeof e?e:null,f=e?ie(p?d.map(t=>({[h]:p(t)})):d,p?h:e,c):void 0;return{chartType:"orbit",data:r,childrenAccessor:s,nodeIDAccessor:a,colorBy:e,colorScheme:c,colorByDepth:i.colorByDepth??!1,nodeSize:i.nodeRadius??6,nodeLabel:i.showLabels?a:void 0,showLabels:i.showLabels??!1,orbitMode:i.orbitMode??"flat",orbitSize:i.orbitSize??2.95,orbitSpeed:i.speed??.25,orbitRevolution:i.revolution,orbitRevolutionStyle:i.revolutionStyle,orbitEccentricity:i.eccentricity??1,orbitShowRings:i.showRings??!0,orbitAnimated:!1,nodeStyle:ae(t=>{const o=t.data||t,n=Number(t.depth??0);return{fill:i.colorByDepth?0===n?u[0]:te[n%te.length]:e?p?oe({[h]:p(o)},h,f):oe(o,e,f):u[0],stroke:"#fff",strokeWidth:1,opacity:0===n?1:.85}},fe(i)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...n}}},Ki={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(t,e,o,n,i)=>{const r=t=>null==t?NaN:t instanceof Date?t.getTime():"number"==typeof t?t:new Date(t).getTime(),s=i.sourceAccessor||"source",a=i.targetAccessor||"target",l=i.valueAccessor||"value",c=i.nodeIdAccessor||"id",u=i.startTimeAccessor||"startTime",d=i.endTimeAccessor||"endTime",h=i.systemInTimeAccessor,p=i.systemOutTimeAccessor,f=i.xExtentAccessor||"xExtent",g=i.groupBy,y=i.edgeIdAccessor||"id",m=(t,e)=>"function"==typeof t?t(e):e[t],x=Array.isArray(i.edges)?i.edges:[],b=Array.isArray(i.nodes)?i.nodes:[],v=b.length>0?b:Xi([],x,s,a),w=[r(i.domain?.[0]),r(i.domain?.[1])],k=v.map(t=>{const e=m(c,t)+"",o=m(f,t),n=i.nodeLabel?m(i.nodeLabel,t):e,s={id:e,label:null==n?e:n+"",__raw:t},a=g?m(g,t):null;if(null!=a&&a+""!=""&&(s.group=a+""),Array.isArray(o)&&2===o.length){const t=r(o[0]),e=r(o[1]);Number.isFinite(t)&&Number.isFinite(e)&&(s.xExtent=[t,e])}return s}),A=x.map((t,e)=>{const o=m(y,t),n={id:null!=o?o+"":`${m(s,t)}-${m(a,t)}-${e}`,source:m(s,t)+"",target:m(a,t)+"",value:Number(m(l,t)),startTime:r(m(u,t)),endTime:r(m(d,t)),__raw:t};if(h){const e=r(m(h,t));Number.isFinite(e)&&(n.systemInTime=e)}if(p){const e=r(m(p,t));Number.isFinite(e)&&(n.systemOutTime=e)}return n}),[S,M]=n.size??[600,400],_=n.margin,P="vertical"===i.orientation?"vertical":"horizontal",L=function(t,e,o,n="horizontal"){return"vertical"===n?{top:t?38:e?28:16,right:24,bottom:24,left:o?72:24}:{top:t?30:e?24:8,right:80,bottom:o?28:8,left:80}}(!!n.title,!!i.showQualityReadout,Array.isArray(i.axisTicks)&&i.axisTicks.length>0,P),$={...L,..._},R=(n.showLegend??!!e)&&!!e,C=n.legendPosition??"right";R&&("right"===C?$.right=Math.max($.right,140):"left"===C?$.left=Math.max($.left,140):"top"===C?$.top=Math.max($.top,50):"bottom"===C&&($.bottom=Math.max($.bottom,80)));const T=$,O=S-T.left-T.right,I=M-T.top-T.bottom,z=Qt(o,ye(n.theme).colors.categorical,B),F="function"==typeof e?e:null,N=F?v.map(t=>({_cat:F(t)})):v,E=F?"_cat":"string"==typeof e?e:void 0,D=o??[...z],W=E?ie(N,E,D):null,j=new Map;for(const t of k)j.set(t.id,t.__raw);const Y=(t,o)=>{if(e&&j.has(t)){const o=j.get(t);return F?oe({_cat:F(o)},"_cat",W??void 0):oe(o,"string"==typeof e?e:"id",W??void 0)}return z[o%z.length]},X=Ye(R&&e?(()=>{const t=new Map;v.forEach((o,n)=>{const i=m(e,o),r=null==i?"":i+"";r&&!t.has(r)&&t.set(r,{label:r,color:Y(m(c,o)+"",n)})});const o=Array.from(t.values());return o.length>0?{legendGroups:[{type:"fill",label:"",items:o,styleFn:t=>{const e=t.color||"#333";return{fill:e,stroke:e}}}]}:void 0})():void 0,n.legend),G=!1!==i.showLabels&&("auto"!==i.showLabels||"auto"),{layout:V,layoutConfig:H,issues:q,xScale:U}=Oi({nodes:k,edges:A,domain:w,plotW:O,plotH:I,orientation:P,ribbonLane:i.ribbonLane||"both",ribbonMinRun:"auto"===i.ribbonMinRun||"number"==typeof i.ribbonMinRun?i.ribbonMinRun:0,edgeOpacity:"number"==typeof i.edgeOpacity?i.edgeOpacity:.35,colorOf:Y,showLabels:G,styleRules:i.styleRules,colorBy:e,valueAccessor:l,layoutOpts:{pairing:i.pairing||"temporal",packing:i.packing||"reuse",laneOrder:i.laneOrder||"crossing-min",lifetimeMode:i.lifetimeMode||"half",maxValueScale:"number"==typeof i.maxValueScale?i.maxValueScale:void 0,lanePlacement:i.lanePlacement||"stack",nodeSizing:i.nodeSizing||"temporal",groupPadding:"number"==typeof i.groupPadding?i.groupPadding:0}});if(q.length>0){const t=q.map(Sn).join("; ");throw Error("ProcessSankey: data invalid — "+t)}const K=V?function(t){const e=t.layout,o=t.nodes,n=t.orientation,i=t.plotW,r=t.plotH,s=t.timelineExtent,a=t.axisTicks,l=t.showQualityReadout??!1,c=t.showLaneRails??!1,u=(t.warnings??[]).slice(0,3),d=t.timeFormat,h=t.colorOf,p=t.toTime,f=t.xScale,{centerlines:g,laneLifetime:y,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:A}=e;let S=null,M=null;for(const t of o){const e=y[t.id];if(!e||null===e.start||null===e.end)continue;const o=f(e.start),n=f(e.end);(null===S||S>o)&&(S=o),(null===M||n>M)&&(M=n)}const _=t=>Math.max(0,Math.min(s,t)),P=_(S??0),L=Math.max(P,_(M??s)),$=a.map((t,e)=>({tick:t,index:e,coordinate:f(p(t.date))})).filter(({coordinate:t})=>t>=P-.5&&L+.5>=t),R=null!==(w??null)&&null!=k&&null!=A,C=l&&(R||u.length>0)?Fi("g",{fill:Di,fontSize:10,textAnchor:"end",children:[R&&Fi(Ii,{children:[Fi("text",{x:i,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(A.pixelLength)]}),Fi("text",{x:i,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",A.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*A.verticalUtilization),"%"]})]}),u.map((t,e)=>Fi("text",{x:i,y:R?10+11*e:11*e-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",t]},"warn-"+e))]}):null,T=b?zi("text",{x:i,y:"vertical"===n?-3:2,fontSize:10,fill:Di,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,O=(t,e)=>h?h(t,e):Ni;return Fi("g","vertical"===n?{children:[C,T,$.map(({index:t,coordinate:e})=>zi("line",{x1:0,y1:e,x2:i,y2:e,stroke:Ni,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[t.id];if(!o||null===o.start)return null;const n=m[t.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=f(o.start),a=f(o.end),l=O(t.id,e);return Fi("g",{children:[zi("line",{x1:r,y1:s,x2:r,y2:a,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),zi("line",{x1:r-4,y1:s,x2:r+4,y2:s,stroke:l,strokeOpacity:.5}),zi("line",{x1:r-4,y1:a,x2:r+4,y2:a,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),zi("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:Ni}),$.map(({tick:t,index:e,coordinate:o})=>{const n=p(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return Fi("g",{transform:`translate(-4,${o})`,children:[zi("line",{x2:-6,stroke:Ni}),zi("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:Ei,children:i})]},e)})]}:{children:[C,T,$.map(({index:t,coordinate:e})=>zi("line",{x1:e,y1:0,x2:e,y2:r,stroke:Ni,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+t)),c&&o.map((t,e)=>{const o=y[t.id];if(!o||null===o.start)return null;const n=m[t.id],i=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},r=g[t.id]+(i.botPeak-i.topPeak)*x/2,s=f(o.start),a=f(o.end),l=O(t.id,e);return Fi("g",{children:[zi("line",{x1:s,y1:r,x2:a,y2:r,stroke:l,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),zi("line",{x1:s,y1:r-4,x2:s,y2:r+4,stroke:l,strokeOpacity:.5}),zi("line",{x1:a,y1:r-4,x2:a,y2:r+4,stroke:l,strokeOpacity:.5})]},"lane-"+t.id)}),zi("line",{x1:P,y1:r+4,x2:L,y2:r+4,stroke:Ni}),$.map(({tick:t,index:e,coordinate:o})=>{const n=p(t.date),i=null!=t.label?t.label:d?d(new Date(n)):"";return Fi("g",{transform:`translate(${o},${r+4})`,children:[zi("line",{y2:6,stroke:Ni}),zi("text",{y:20,textAnchor:"middle",fontSize:11,fill:Ei,children:i})]},e)})]})}({layout:V,nodes:k,orientation:P,plotW:O,plotH:I,timelineExtent:"vertical"===P?I:O,axisTicks:Array.isArray(i.axisTicks)?i.axisTicks.map(t=>({date:t.date,label:t.label})):[],showQualityReadout:!!i.showQualityReadout,showLaneRails:!!i.showLaneRails,timeFormat:"function"==typeof i.timeFormat?t=>i.timeFormat(t):void 0,colorOf:Y,toTime:t=>r(t),xScale:t=>Number(U(t))}):void 0;return{chartType:"force",nodes:v,edges:x,customNetworkLayout:ji,layoutConfig:H,sourceAccessor:s,targetAccessor:a,valueAccessor:l,nodeIDAccessor:c,colorBy:e,colorScheme:o,...K&&{backgroundGraphics:K},...n,showLegend:R,...X&&{legend:X,legendPosition:C},__legendIncludesAutomatic:!0,margin:T}}},Zi={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(t,e,o,n,i)=>{const r=Array.isArray(i.nodes)?i.nodes:Xi([],Array.isArray(i.edges)?i.edges:[],i.sourceAccessor||"source",i.targetAccessor||"target"),s=ye(n.theme).colors.categorical,a=new Map,l="string"==typeof e?e:"__ssrSankeyColorBy",c="function"==typeof e?r.map(t=>({...t,__ssrSankeyColorBy:e(t)})):r,u=e?ie(c,l,o??n.colorScheme??s):void 0,d=t=>({fill:e?oe(t?.data||t,e,u):uo(void 0,s,o,void 0,a),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}),h=pt(i.styleRules,e,i.valueAccessor),p=h?(t,e)=>({...d(t),...h(t,e)}):d,f=function({edgeColorBy:t,colorBy:e,colorScale:o,nodeStyleFn:n,edgeOpacity:i,baseStyle:r={}}){return s=>{const a={fillOpacity:i,...r};if("function"==typeof t)a.fill=t(s);else if("source"===t){const t="object"==typeof s.source?s.source:null;e&&t?a.fill=oe(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else if("target"===t){const t="object"==typeof s.target?s.target:null;e&&t?a.fill=oe(t.data||t,e,o):t&&(a.fill=n(t,t.index).fill)}else"gradient"===t&&(a.fill="#999",a.fillOpacity=.7*i);return a}}({edgeColorBy:i.edgeColorBy??"source",colorBy:e,colorScale:u,nodeStyleFn:p,edgeOpacity:i.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:i.nodes,edges:i.edges,nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor,sourceAccessor:i.sourceAccessor,targetAccessor:i.targetAccessor,valueAccessor:i.valueAccessor,orientation:i.orientation,nodeAlign:i.nodeAlign,nodeWidth:i.nodeWidth,nodePaddingRatio:i.nodePaddingRatio,showLabels:i.showLabels,nodeLabel:i.nodeLabel,colorBy:e,edgeColorBy:i.edgeColorBy,edgeOpacity:i.edgeOpacity,nodeStyle:ae(i.nodeStyle||p,fe(i)),edgeStyle:ae(i.edgeStyle||f,fe(i)),colorScheme:o,...n}}},Qi={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreeColorBy:l(t)})):a,u=l?"__ssrTreeColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=n.nodeStyle||i.nodeStyle;return{chartType:"cluster"===i.layout?"cluster":"tree",data:t,childrenAccessor:i.childrenAccessor,colorBy:e,colorByDepth:i.colorByDepth,orientation:i.orientation,showLabels:i.showLabels,nodeLabel:!1!==i.showLabels?i.nodeLabel||i.nodeIdAccessor:void 0,colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrTreeColorBy:l(n)},"__ssrTreeColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),stroke:i.stroke??"black",strokeWidth:i.strokeWidth??1,...void 0!==i.opacity&&{opacity:i.opacity}}},h,fe(i))}}},Ji={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(t,e,o,n,i)=>{const r=ye(n.theme).colors.categorical,s=new Map,a=Yi(t??null,i.childrenAccessor),l="function"==typeof e?e:null,c=l?a.map(t=>({__ssrTreemapColorBy:l(t)})):a,u=l?"__ssrTreemapColorBy":"string"==typeof e?e:void 0,d=e&&u?ie(c,u,o??n.colorScheme??r):void 0,h=i.showLabels??n.showLabels,p=i.labelMode,f=void 0!==i.paddingTop?i.paddingTop:n.paddingTop,g=void 0!==f?f:!h||"parent"!==p&&"all"!==p?void 0:18,y=n.nodeStyle||i.nodeStyle;return{chartType:"treemap",data:t,childrenAccessor:i.childrenAccessor,hierarchySum:i.valueAccessor,colorBy:e,colorByDepth:i.colorByDepth,showLabels:i.showLabels,labelMode:p,nodeLabel:h?i.nodeLabel||i.nodeIdAccessor:void 0,...null!=i.padding&&{padding:i.padding},...null!=g&&{paddingTop:g},colorScheme:o,...n,nodeStyle:Gi(t=>{const n=t?.data||t;return{fill:i.colorByDepth?te[Number(t?.depth||0)%te.length]:e?l?oe({__ssrTreemapColorBy:l(n)},"__ssrTreemapColorBy",d??void 0):oe(n,e,d??void 0):uo(void 0,r,o,void 0,s),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},y,fe(i))}}},tr={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as er}from"d3-scale";function or(t){return t&&"object"==typeof t&&t.properties?{...t.properties,...t}:t}var nr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r="string"==typeof o?o:"blues",s=function(t,e,o){if(!Array.isArray(t))return;const n=t=>"function"==typeof e?e(t):null!=e?t?.properties?.[e]??t?.[e]:void 0;let i=1/0,r=-1/0;for(const e of t){const t=n(e);null!=t&&isFinite(t)&&(i>t&&(i=t),t>r&&(r=t))}const s=[Number.isFinite(i)?i:0,Number.isFinite(r)?r:1],a=er(h(o)).domain(s);return{domain:s,colorScale:t=>a(t),valueAccessor:n}}(i.areas,i.valueAccessor,r),a=i.areaStyle??function(t,e){if(t)return o=>{const n=t.valueAccessor(o);return{fill:null!=n&&isFinite(n)?t.colorScale(n):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:e}}}(s,i.areaOpacity??1),l=i.styleRules?Q(a,i.styleRules,t=>{return{value:(e=t,"function"==typeof i.valueAccessor?i.valueAccessor(e):null!=i.valueAccessor?e?.properties?.[i.valueAccessor]??e?.[i.valueAccessor]:void 0)};var e},or):a,c=!1!==n.showLegend&&s?{gradient:{colorFn:s.colorScale,domain:s.domain,label:"string"==typeof i.valueAccessor?i.valueAccessor:"value"}}:void 0;return{areas:i.areas,projection:i.projection||"equalEarth",areaStyle:l,valueAccessor:i.valueAccessor,colorScheme:r,graticule:i.graticule,fitPadding:i.fitPadding,...n,...void 0===n.legend&&c?{legend:c}:{}}}},ir={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=t||i.points,s=i.pointStyle??function(t,e,o,n){const i=Array.isArray(t)?t:[];let r,s;if(e){const t="string"==typeof e?e:"__geoColorBy",n="string"==typeof e?i:i.map(t=>({...t,__geoColorBy:e(t)}));r=ie(n,t,o)}if(n.sizeBy){const t=i.map("function"==typeof n.sizeBy?n.sizeBy:t=>t?.[n.sizeBy]).filter(t=>null!=t&&isFinite(t));t.length>0&&(s=St(t))}return t=>({fill:e&&r?oe(t,e,r):Zt,fillOpacity:n.fillOpacity,stroke:"#fff",strokeWidth:n.strokeWidth,r:n.sizeBy?re(t,n.sizeBy,n.sizeRange,s):n.pointRadius??6})}(r,e,o,{sizeBy:i.sizeBy,sizeRange:i.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),a=i.styleRules?Q(s,i.styleRules,rt(e,i.sizeBy)):s;return{points:r,xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",areas:i.areas,areaStyle:i.areaStyle||tr,pointStyle:a,sizeBy:i.sizeBy,colorBy:e,colorScheme:o,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,...n}}},rr={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(t,e,o,n,i)=>{const r=(Array.isArray(t)?t:null)||i.flows||[],s=i.nodeIdAccessor||"id",a=i.valueAccessor||"value",l=i.xAccessor||"lon",c=i.yAccessor||"lat",u="function"==typeof l?l:t=>t[l],d="function"==typeof c?c:t=>t[c],h=(i.nodes||[]).map(t=>({...t,x:u(t),y:d(t)})),p=new Map;for(const t of h)p.set(t[s]+"",t);const f=i.edgeColorBy??e,g="function"==typeof f,y=r.map(t=>{if(!t||null==t.source||null==t.target)return null;const e=p.get(t.source+""),o=p.get(t.target+"");return e&&o?{...t,coordinates:[{x:e.x,y:e.y},{x:o.x,y:o.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=f?g?ie(y.map(t=>({[m]:f(t)})),m,o||"category10"):ie(y,f,o||"category10"):null,b=t=>f&&x?oe(t,f,x):"#007bff";let v=1/0,w=-1/0;for(const t of y){const e=Number(t[a]??0);isFinite(e)&&(v>e&&(v=e),e>w&&(w=e))}const k=w>v?w-v:0,[A,S]=i.edgeWidthRange??[1,8],M=S-A,_=i.edgeOpacity??.6,P=i.edgeLinecap??"round";return{lines:y,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:i.lineType||"geo",flowStyle:i.flowStyle||"basic",areas:i.areas,areaStyle:i.areaStyle||tr,projection:i.projection||"equalEarth",graticule:i.graticule,fitPadding:i.fitPadding,colorScheme:o,lineStyle:t=>{const e=Number(t?.[a]),o=Number.isFinite(e)?e:v,n=A+Math.max(0,Math.min(1,k>0?(o-v)/k:0))*M;return{stroke:b(t),strokeWidth:n,strokeLinecap:P,opacity:_,fillOpacity:0}},pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...n}}};import*as sr from"react";function ar(t){const[e,o]=t,n=160>e||116>o,i=n?Math.min(12,Math.max(2,.08*e)):32,r=n?Math.min(8,Math.max(2,.12*o)):24,s=n?r:34;return{width:e,height:o,plot:{x:i,y:r,width:Math.max(1,e-2*i),height:Math.max(1,o-r-s)}}}function lr(t){const e=(t??"")+"";if(!e)return"#4e79a7";const o=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"];let n=0;for(let t=0;e.length>t;t+=1)n=31*n+e.charCodeAt(t)>>>0;return o[n%o.length]}function cr(t,e="#4e79a7",o){const n=o?.styleRules,i=!!n&&n.length>0,r=i?st(o?.valueAccessor):void 0;return o=>{const s=o.datum,a=s&&t?"function"==typeof t?t(s,0):s[t]:void 0,l={fill:null==a?e:lr(a),stroke:"#111827",strokeWidth:1,opacity:.9};return i&&s&&Object.assign(l,dt(s,n,{value:r?r(s):void 0,category:null==a?void 0:a+""})),l}}function ur(t,e,o,n){return{fixedDt:1/120,maxSubsteps:8,colliders:e,observation:{chartType:o},kernel:{seed:t,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...n}}}function dr(t,e,o){return"function"==typeof o?o(t,e):t[o]}function hr(t){if(t instanceof Date){const e=t.getTime();return Number.isFinite(e)?e:null}const e="number"==typeof t?t:"string"==typeof t&&t.trim()?Number(t):NaN;return Number.isFinite(e)?e:null}function pr(t,e,o){return Math.max(e,Math.min(o,t))}function fr(t,e){const o=hr(t);return null!=o&&o>0?o:e}function gr(t){return((t??"unknown")+"").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function yr(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}import{scaleLinear as mr}from"d3-scale";import{scaleLinear as xr}from"d3-scale";function br(t){const{count:e,idPrefix:o,wallThickness:n,xScale:i,yBottom:r,yTop:s,yTopForIndex:a}=t;return Array.from({length:e+1},(t,e)=>{const l=Math.min(r-1,a?.(e)??s),c=Math.max(1,r-l);return{id:`${o}-wall-${e}`,shape:{type:"aabb",x:i(e),y:l+c/2,width:n,height:c}}})}function vr(t,e,o){const n=t.width/Math.max(1,e),i=Math.max(2,2*o),r=Math.min(.7*n,Math.max(3.2*i,i+8)),s=Math.max(1,Math.floor(r/i));return{laneWidth:n,tubeWidth:r,ballDiameter:i,perRow:s,centerX:e=>t.x+(e+.5)*n,pileHeight:t=>Math.ceil(Math.max(0,t)/s)*i}}import{scaleLinear as wr}from"d3-scale";function kr(t){if(Array.isArray(t)&&t.length>=2){const e=hr(t[0]),o=hr(t[1]);return null!=e&&null!=o?{x:e,y:o}:null}if(t&&"object"==typeof t){const e=t,o=hr(e.x),n=hr(e.y);return null!=o&&null!=n?{x:o,y:n}:null}return null}function Ar(t){return Array.isArray(t)?t.map(kr).filter(t=>null!=t):[]}function Sr(t,e,o){return"normalized"===o?{x:e.plot.x+t.x*e.plot.width,y:e.plot.y+t.y*e.plot.height}:{x:pr(t.x,e.plot.x,e.plot.x+e.plot.width),y:pr(t.y,e.plot.y,e.plot.y+e.plot.height)}}function Mr(t){let e=0;for(let o=1;t.length>o;o+=1)e+=Math.hypot(t[o].x-t[o-1].x,t[o].y-t[o-1].y);return e}function _r(t,e){if(0===t.length)return{x:0,y:0};if(1===t.length)return{...t[0]};const o=pr(e,0,1)*Mr(t);let n=0;for(let e=1;t.length>e;e+=1){const i=t[e-1],r=t[e],s=Math.hypot(r.x-i.x,r.y-i.y);if(s>0){if(n+s>=o){const t=(o-n)/s;return{x:i.x+(r.x-i.x)*t,y:i.y+(r.y-i.y)*t}}n+=s}}return{...t[t.length-1]}}function Pr(t,e){const o=_r(t,Math.max(0,e-.02)),n=_r(t,Math.min(1,e+.02)),i=n.x-o.x,r=n.y-o.y,s=Math.hypot(i,r)||1;return{x:i/s,y:r/s}}function Lr(t,e=12){return"number"==typeof t?{x:t,y:0}:t&&"object"==typeof t?{x:Number.isFinite(t.x)?Number(t.x):e,y:Number.isFinite(t.y)?Number(t.y):0}:{x:e,y:0}}import{scaleLinear as $r}from"d3-scale";function Rr(t,e,o){return Qt(t,e,o)}function Cr(t,e){const o=e&&"object"==typeof e&&!Array.isArray(e)?e:void 0;return 0===t.length?t=>o&&ne(o,t)||"#4e79a7":e=>{if(o){const t=ne(o,e);if(t)return t}let n=0;for(let t=0;e.length>t;t++)n=31*n+e.charCodeAt(t)|0;return t[Math.abs(n)%t.length]??"#4e79a7"}}function Tr(t,e){const o=e.config??{},n=(e.sensors??[]).map(t=>({...t,sensor:!0})),i=[...e.colliders??[],...n],r=[...t.colliders??[],...o.colliders??[],...i];return{...t,...o,observation:{...t.observation,...o.observation},...r.length>0&&{colliders:r}}}function Or(t){const e=Dr(t);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:e.left,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:e.top,x2:t.width-e.rightInset,y2:e.top,thickness:e.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:e.left,y1:t.floorY,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:t.width-e.rightInset,y1:e.top,x2:t.width-e.rightInset,y2:t.floorY,thickness:e.thickness}}]}function Ir(t,e,o,n){return o?"function"==typeof o?o(t,e):t[o]??n:n}function zr(t){return`gauntlet:${t}:core`}function Fr(t,e){return`gauntlet:${t}:positive:${e}`}function Nr(t,e,o){return`gauntlet:${t}:negative:${e}:${o}`}var Er={left:28,top:76,rightInset:30,thickness:8};function Dr(t){const e=t.height??t.floorY+36;if(t.width>=220&&e>=160)return Er;const o=Math.max(1,Math.min(t.width,e)),n=Math.max(2,.04*t.width);return{left:n,top:Math.max(2,.08*e),rightInset:n,thickness:Math.max(1,Math.min(4,.04*o))}}function Wr(t){return Math.max(.12,Math.min(1,t.width/500,(t.height??t.floorY+36)/260))}function Br(t,e,o,n){const i=Dr(n),r=Math.max(2,o+2),s=i.top+i.thickness/2+r,a=n.floorY-r,l=(t,e,o)=>e>o?(e+o)/2:Math.max(e,Math.min(o,t));return{x:l(t,i.left+i.thickness/2+r,n.width-i.rightInset-i.thickness/2-r),y:l(e,s,a)}}function jr(t,e,o=1){const n=[...t].sort((t,e)=>t.localeCompare(e)),i=Math.max(0,n.indexOf(e));return{angle:.82*-Math.PI+(n.length>1?i/(n.length-1):.5)*Math.PI*.64,index:i,radius:(48+i%2*6)*o}}function Yr(t,e,o){const n=t.activePositiveIds.reduce((t,o)=>t+(e.get(o)?.value??1),0),i=t.missingPositiveIds.length+t.poppedPositiveIds.length,r=t.negativeIds.reduce((t,e)=>t+(o.get(e)?.load??1),0);return Math.max(0,Math.min(100,75+3*n-8*r-1.2*t.delay-5*i))}function Xr(t){const e=function(t,e,o){const[n,i]=t,r=220>n||160>i,s=Math.round(.48*i),a=r?i-Math.max(3,Math.min(12,.1*i)):i-36,l=(e??[]).filter(t=>!1!==t.enabled),c=Math.max(1,l.length),u=.22*n,d=c>1?(.78*n-u)/(c-1):0,h=r?Math.max(Math.round(.12*n),.08*n+6):Math.max(Math.round(.14*n),110);return{crashY:a-(r?Math.min(o,Math.max(3,.22*i)):o),floorY:a,gates:l.map((t,e)=>({...t,id:t.id,x:t.x??Math.round(u+e*d),width:t.width??Math.max(r?8:54,Math.round(.07*n))})),graveyardX:Math.round(n*(r?.72:.84)),graveyardY:a-4,height:i,routeY:s,socketX:Math.round(n*(r?.82:.92)),startX:h,width:n}}(t.size??[900,520],t.gates,t.crashOffset??30),o=t.positiveProperties??[],n=new Map(o.map(t=>[t.id,t])),i=new Map((t.negativeProperties??[]).map(t=>[t.id,t])),r={idAccessor:t.idAccessor,initialViability:t.initialViability,metricsAccessor:t.metricsAccessor,negativeAccessor:t.negativeAccessor,positiveAccessor:t.positiveAccessor,startTimeAccessor:t.startTimeAccessor},s=(t.data??[]).map((e,s)=>{const a=function(t,e,o,n,i){const r=Ir(t,e,o.idAccessor,null!=t.id?t.id+"":"project-"+e)+"",s=n.map(t=>t.id),a=[...Ir(t,e,o.positiveAccessor,s)],l=[...Ir(t,e,o.negativeAccessor,[])].filter(t=>i.has(t));return{id:r,activePositiveIds:a,datum:t,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ir(t,e,o.metricsAccessor,{})},missingPositiveIds:s.filter(t=>!a.includes(t)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ir(t,e,o.startTimeAccessor,0))||0),stage:"project filed",viability:Ir(t,e,o.initialViability,100)}}(e,s,r,o,i);return{...a,viability:t.viability?.(a,{negativeProperties:i,positiveProperties:n})??Yr(a,n,i)}}),a=s.flatMap((o,r)=>{const s=function(t,e,o,n){const i=function(t){return{graveyardX:t.graveyardX,graveyardY:t.graveyardY,routeY:t.routeY,socketX:t.socketX,socketY:t.routeY-4,startX:t.startX,startY:t.routeY}}(o),r=n?.(t,e,o)??{};return{...i,...r,startY:r.startY??r.routeY??i.startY,socketY:r.socketY??r.routeY??i.socketY,graveyardY:r.graveyardY??i.graveyardY}}(o,r,e,t.projectPlacement);return function(t,e,o,n,i,r,s){const a=Wr(o),l=Math.max(3,28*a),c=n.startX,u=n.startY+(n.startY===o.routeY?38*e*a:0),d=s?.(t,e,o,n)??{},h=d.x??c,p=d.y??u,f={__gauntlet:!0,kind:"gauntlet-core",projectId:t.id,sourceDatum:t.datum},g=[{...d,id:zr(t.id),x:h,y:p,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??t.startedAt,datum:f}],y=Br(h,p,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,o);g[0].x=y.x,g[0].y=y.y;for(const e of t.activePositiveIds){const n=i.get(e);if(!n)continue;const r=jr(t.activePositiveIds,e,a),s=n.radius??Math.max(2,10*a),l=Br(y.x+Math.cos(r.angle)*r.radius,y.y+Math.sin(r.angle)*r.radius,s,o);g.push({id:Fr(t.id,e),x:l.x,y:l.y,vx:18*Math.cos(r.angle),vy:18*Math.sin(r.angle),mass:n.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:d.spawnAt??t.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:t.id,property:n,sourceDatum:t.datum},springs:!1===n.spring?[]:[{target:{type:"body",bodyId:zr(t.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+r.index%2*4)*a),...n.spring??{}}]})}return t.negativeIds.forEach((e,n)=>{const i=r.get(e);i&&g.push(function(t,e,o,n,i,r,s){const a=Wr(r),l=e.radius??Math.max(2,7.2*a),c=Br(n+(o%4*12-12)*a,i+(54+12*Math.floor(o/4))*a,l,r);return{id:Nr(t.id,e.id,o),x:c.x,y:c.y,vx:10,vy:6,mass:e.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:s,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:t.id,property:e,sourceDatum:t.datum},springs:!1===e.spring?[]:[{target:{type:"body",bodyId:zr(t.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+o%4*3)*a),...e.spring??{}}]}}(t,i,n,y.x,y.y,o,d.spawnAt??t.startedAt))}),g}(o,r,e,s,n,i,t.coreBody)});return{layout:e,states:s,initialSpawns:a,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:Or(e)}}}function Gr(t=[]){const e=Object.create(null);for(const[o,n]of t)e[o]=n;return e}function Vr(...t){const e=Gr();for(const o of t)for(const[t,n]of Object.entries(o??{}))e[t]=n;return e}function Hr(t){return Vr(t)}function qr(t){return t.map(t=>({...t,sourceIds:t.sourceIds?[...t.sourceIds]:void 0,productIds:t.productIds?[...t.productIds]:void 0,relationIds:t.relationIds?[...t.relationIds]:void 0,outletIds:t.outletIds?[...t.outletIds]:void 0}))}function Ur(t){const e=Gr(Object.entries(t.components).map(([t,e])=>[t,{...e,initialMetrics:Hr(e.initialMetrics),metrics:Hr(e.metrics),productIds:[...e.productIds],history:qr(e.history)}])),o=Gr(Object.entries(t.products).map(([t,e])=>[t,{...e,metrics:Hr(e.metrics),sourceIds:[...e.sourceIds],history:qr(e.history)}])),n=Gr(Object.entries(t.relations).map(([t,e])=>[t,{...e,sourceIds:[...e.sourceIds],metrics:e.metrics?Hr(e.metrics):void 0}]));return{...t,eventsApplied:[...t.eventsApplied],components:e,products:o,relations:n,input:{amount:t.input.amount,metrics:Hr(t.input.metrics)},metrics:Hr(t.metrics),loss:{amount:t.loss.amount,metrics:Hr(t.loss.metrics)},history:qr(t.history)}}var Kr=1e-9;function Zr(t,e){return e>t?-1:t>e?1:0}function Qr(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function Jr(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(Zr)}function ts(t,e){return t?Object.entries(t).flatMap(([t,o])=>Number.isFinite(o)?[]:[Qr("error","invalid-metric",`Metric "${t}" must be a finite number.`,`${e}.${t}`)]):[]}function es(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}function os(t,e,o="selector"){const n=[],i=Object.values(t.components),r=new Set(i.map(t=>t.id)),s=(e.ids??[]).filter(t=>!r.has(t));if(s.length&&n.push(Qr("error","unknown-component",`Selector references unknown component id${1===s.length?"":"s"}: ${s.join(", ")}.`,o+".ids",s)),void 0===e.count||Number.isInteger(e.count)&&e.count>=0||n.push(Qr("error","invalid-selector-count","Selector count must be a non-negative integer.",o+".count")),n.some(t=>"error"===t.severity))return{ids:[],diagnostics:n};const a=e.ids?new Set(e.ids):null,l=e.categories?new Set(e.categories):null,c=e.statuses?new Set(e.statuses):null,u=e.outletIds?new Set(e.outletIds):null;let d=i.filter(t=>!a||a.has(t.id)).filter(t=>!l||l.has(t.category)).filter(t=>!c||c.has(t.status)).filter(t=>!u||void 0!==t.outletId&&u.has(t.outletId)).map(t=>t.id).sort(Zr);return void 0!==e.count&&(d=d.slice(0,e.count)),d.length||n.push(Qr("warning","empty-selector","Selector matched no source components.",o)),{ids:d,diagnostics:n}}function ns(t,e,o={}){return{eventId:t.event.id,effectType:e.type,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,label:t.event.label,summary:t.event.summary,...o}}function is(t,e){const o={...e,eventId:t.event.id};t.materializations.push(o),t.observations.push({...o,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt})}function rs(t,e,o){return!(void 0!==e&&!t.outletIds.has(e)&&(t.diagnostics.push(Qr("error","unknown-outlet",`Unknown outlet "${e}".`,o,[e])),1))}function ss(t,e,o){const n=Jr(e);e.length||t.diagnostics.push(Qr("error","empty-source-list","A product requires at least one source component.",o)),n.length&&t.diagnostics.push(Qr("error","duplicate-source",`Source ids may appear only once: ${n.join(", ")}.`,o,n));const i=e.filter(e=>!t.state.components[e]);i.length&&t.diagnostics.push(Qr("error","unknown-component",`Unknown source component id${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i));const r=e.filter(e=>(t.state.components[e]?.productIds.length??0)>0);r.length&&t.diagnostics.push(Qr("error","source-already-assigned",`Source component${1===r.length?" is":"s are"} already assigned: ${r.join(", ")}.`,o,r));const s=e.filter(e=>"consumed"===t.state.components[e]?.status&&!r.includes(e));return s.length&&t.diagnostics.push(Qr("error","source-unavailable",`Consumed source component${1===s.length?" is":"s are"} unavailable: ${s.join(", ")}.`,o,s)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}function as(t,e,o,n,i){const r=n?.amount??0;(!Number.isFinite(r)||0>r||r>e+Kr)&&t.diagnostics.push(Qr("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",i+".amount")),t.diagnostics.push(...ts(n?.metrics,i+".metrics"));for(const[e,r]of Object.entries(n?.metrics??{}))(0>r||r>Number(o[e]??0)+Kr)&&t.diagnostics.push(Qr("error","invalid-metric-loss",`Metric loss "${e}" must be non-negative and no greater than its sources.`,`${i}.metrics.${e}`));return!t.diagnostics.some(t=>"error"===t.severity)}function ls(t,e,o,n,i,r,s){return{id:t.id,label:t.label??t.id,description:t.description,category:t.category??"product",color:t.color,order:t.order,declaredAmount:t.amount,amount:r&&void 0!==t.amount?t.amount:o,metrics:r&&t.metrics?Vr(n,t.metrics):Hr(n),status:r?"complete":"forming",sourceIds:[...e],outletId:r?t.outletId??(i.outletIds.has("product")?"product":void 0):void 0,createdByEventId:i.event.id,createdAt:i.context.appliedAt,completedByEventId:r?i.event.id:void 0,completedAt:r?i.context.appliedAt:void 0,history:[s]}}function cs(t,e,o,n){void 0!==e.amount&&Math.abs(e.amount-o)>Kr&&t.diagnostics.push(Qr("warning","declared-product-amount-mismatch",`Product "${e.id}" declares ${e.amount}, while its sources yield ${o}.`,n,[e.id]))}function us(t,e,o){const n=`events.${t.event.id}.effects.${o}`,i=t.state;if("set-state"===e.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(e.state)||t.diagnostics.push(Qr("error","invalid-component-state",`set-state cannot assign "${e.state+""}".`,n+".state")),t.diagnostics.push(...ts(e.metricsDelta,n+".metricsDelta")),rs(t,e.outletId,n+".outletId");const o=os(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(Qr("error","source-already-assigned",`Assigned source components cannot be retargeted: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=ns(t,e,{sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0});for(const t of o.ids){const o=i.components[t];o.status=e.state,o.outletId=e.outletId,o.reason=e.reason,e.metricsDelta&&es(o.metrics,e.metricsDelta),o.history.push(s)}return i.history.push(s),void(o.ids.length&&is(t,{type:"retarget-component",sourceIds:o.ids,outletIds:e.outletId?[e.outletId]:void 0}))}if("set-relation"===e.type){const{relation:o}=e;o.id&&!i.relations[o.id]||t.diagnostics.push(Qr("error","duplicate-relation",`Relation id "${o.id}" is missing or already active.`,n+".relation.id",[o.id]));const r=function(t,e,o){const n=Jr(e),i=e.filter(e=>!t.state.components[e]);return 2>e.length&&t.diagnostics.push(Qr("error","insufficient-relation-sources","A relation requires at least two source components.",o)),n.length&&t.diagnostics.push(Qr("error","duplicate-source",`Relation source ids must be unique: ${n.join(", ")}.`,o,n)),i.length&&t.diagnostics.push(Qr("error","unknown-component",`Relation references unknown source component${1===i.length?"":"s"}: ${i.join(", ")}.`,o,i)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.components[e])}(t,o.sourceIds,n+".relation.sourceIds");if(t.diagnostics.push(...ts(o.metrics,n+".relation.metrics")),!r||t.diagnostics.some(t=>"error"===t.severity))return;i.relations[o.id]={...o,sourceIds:[...o.sourceIds],metrics:o.metrics?Hr(o.metrics):void 0,status:"active",createdByEventId:t.event.id,createdAt:t.context.appliedAt};const s=ns(t,e,{sourceIds:[...o.sourceIds],relationIds:[o.id]});return i.history.push(s),void is(t,{type:"activate-relation",sourceIds:[...o.sourceIds],relationIds:[o.id]})}if("resolve-relation"===e.type){const o=Jr(e.relationIds),r=e.relationIds.filter(t=>!i.relations[t]),s=e.relationIds.filter(t=>"resolved"===i.relations[t]?.status);if(o.length&&t.diagnostics.push(Qr("error","duplicate-relation","Relation ids must be unique.",n+".relationIds",o)),r.length&&t.diagnostics.push(Qr("error","unknown-relation",`Unknown relation: ${r.join(", ")}.`,n+".relationIds",r)),s.length&&t.diagnostics.push(Qr("error","resolved-relation",`Relation is already resolved: ${s.join(", ")}.`,n+".relationIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const o of e.relationIds){const n=i.relations[o];n.status="resolved",n.resolution=e.resolution,n.resolvedByEventId=t.event.id,n.resolvedAt=t.context.appliedAt,n.reason=e.reason}const a=ns(t,e,{relationIds:[...e.relationIds]});return i.history.push(a),void is(t,{type:"resolve-relation",relationIds:[...e.relationIds]})}if("combine"===e.type||"contribute"===e.type){const o=t.productDefinitions.get(e.productId);o||t.diagnostics.push(Qr("error","unknown-product",`Product "${e.productId}" has no declared mold.`,n+".productId",[e.productId]));const r=i.products[e.productId];"combine"===e.type&&r&&t.diagnostics.push(Qr("error","duplicate-product",`Product "${e.productId}" has already been formed.`,n+".productId",[e.productId])),"contribute"!==e.type||r&&"forming"===r.status||t.diagnostics.push(Qr("error","product-not-forming",`Contributions require an existing forming product "${e.productId}".`,n+".productId",[e.productId]));const s=ss(t,e.sourceIds,n+".sourceIds"),a="contribute"===e.type&&r?[...r.sourceIds,...e.sourceIds]:e.sourceIds,l=function(t,e,o,n){if(!e?.length)return[];const i=Jr(e),r=e.filter(e=>!t.state.relations[e]),s=e.filter(e=>"resolved"===t.state.relations[e]?.status),a=new Set(o),l=e.filter(e=>(t.state.relations[e]?.sourceIds??[]).some(t=>!a.has(t)));return i.length&&t.diagnostics.push(Qr("error","duplicate-relation","Basis relations must be unique.",n,i)),r.length&&t.diagnostics.push(Qr("error","unknown-relation",`Unknown basis relation: ${r.join(", ")}.`,n,r)),s.length&&t.diagnostics.push(Qr("error","resolved-relation",`Basis relation is already resolved: ${s.join(", ")}.`,n,s)),l.length&&t.diagnostics.push(Qr("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,n,l)),t.diagnostics.some(t=>"error"===t.severity)?null:e.map(e=>t.state.relations[e])}(t,e.basisRelationIds,a,n+".basisRelationIds");if(!s||!l||!o||t.diagnostics.some(t=>"error"===t.severity))return;const c=s.reduce((t,e)=>t+e.amount,0),u=function(t){const e=Gr();for(const o of t)es(e,o.metrics);return e}(s);if(!as(t,c,u,e.loss,n+".loss"))return;const d=c-(e.loss?.amount??0);!function(t,e,o){t.state.loss.amount+=o?.amount??0;for(const[n,i]of Object.entries(o?.metrics??{}))e[n]=Number(e[n]??0)-i,t.state.loss.metrics[n]=Number(t.state.loss.metrics[n]??0)+i}(t,u,e.loss);const h="combine"===e.type&&!1!==e.complete,p=ns(t,e,{sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0});let f;if("combine"===e.type){if(h&&cs(t,o,d,n+".productId"),f=ls(o,e.sourceIds,d,u,t,h,p),h&&!rs(t,f.outletId,n+".productId"))return;i.products[e.productId]=f}else f=r,f.sourceIds.push(...e.sourceIds),f.amount+=d,es(f.metrics,u),f.history.push(p);for(const t of s)t.productIds=[e.productId],t.status="consumed",t.outletId=void 0,t.history.push(p);return i.history.push(p),function(t,e){if(e.length){for(const o of e)o.status="resolved",o.resolution="combined",o.resolvedByEventId=t.event.id,o.resolvedAt=t.context.appliedAt;is(t,{type:"resolve-relation",relationIds:e.map(t=>t.id)})}}(t,l),is(t,{type:"combine"===e.type?"form-product":"update-product",sourceIds:[...e.sourceIds],productIds:[e.productId],relationIds:e.basisRelationIds?[...e.basisRelationIds]:void 0,outletIds:f.outletId?[f.outletId]:void 0}),void(h&&is(t,{type:"complete-product",sourceIds:[...f.sourceIds],productIds:[f.id],outletIds:f.outletId?[f.outletId]:void 0}))}if("complete-product"===e.type){const o=i.products[e.productId];return o?void function(t,e,o,n,i,r){const s=t.productDefinitions.get(e.id),a=o??s?.outletId??(t.outletIds.has("product")?"product":void 0);if(!rs(t,a,r+".outletId"))return;if("complete"===e.status)return void t.diagnostics.push(Qr("error","product-already-complete",`Product "${e.id}" is already complete.`,r,[e.id]));s&&(cs(t,s,e.amount,r+".productId"),void 0!==s.amount&&(e.amount=s.amount),s.metrics&&(e.metrics=Vr(e.metrics,s.metrics))),e.status="complete",e.outletId=a,e.reason=n,e.completedByEventId=t.event.id,e.completedAt=t.context.appliedAt;const l=ns(t,i,{sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0});e.history.push(l),t.state.history.push(l),is(t,{type:"complete-product",sourceIds:[...e.sourceIds],productIds:[e.id],outletIds:a?[a]:void 0})}(t,o,e.outletId,e.reason,e,n):void t.diagnostics.push(Qr("error","unknown-product-state",`Product "${e.productId}" has not been formed.`,n+".productId",[e.productId]))}if("split"===e.type){const o=ss(t,[e.sourceId],n+".sourceId");e.products.length||t.diagnostics.push(Qr("error","empty-split","A split requires at least one product allocation.",n+".products"));const r=e.products.map(t=>t.productId),s=Jr(r);s.length&&t.diagnostics.push(Qr("error","duplicate-product","Split product ids must be unique.",n+".products",s));const a=r.map(e=>t.productDefinitions.get(e)),l=r.filter((t,e)=>!a[e]),c=r.filter(t=>i.products[t]);l.length&&t.diagnostics.push(Qr("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,n+".products",l)),c.length&&t.diagnostics.push(Qr("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,n+".products",c));for(const[o,i]of e.products.entries())void 0===i.amount||Number.isFinite(i.amount)&&i.amount>=0||t.diagnostics.push(Qr("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${n}.products.${o}.amount`)),t.diagnostics.push(...ts(i.metrics,`${n}.products.${o}.metrics`));if(!o?.length||t.diagnostics.some(t=>"error"===t.severity))return;const u=o[0];if(!as(t,u.amount,u.metrics,e.loss,n+".loss"))return;const d=u.amount-(e.loss?.amount??0),h=e.products.map((t,e)=>t.amount??a[e]?.amount),p=h.filter(t=>void 0!==t).length;if(0!==p&&p!==h.length)return void t.diagnostics.push(Qr("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",n+".products"));const f=p?h:e.products.map(()=>d/e.products.length),g=f.reduce((t,e)=>t+e,0);if(Math.abs(g-d)>Kr)return void t.diagnostics.push(Qr("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,n+".products"));const y=Hr(u.metrics);for(const[t,o]of Object.entries(e.loss?.metrics??{}))y[t]=Number(y[t]??0)-o;const m=ns(t,e,{sourceIds:[u.id],productIds:r});if(e.products.forEach((o,r)=>{const s=a[r],l=d>Kr?f[r]/d:1/e.products.length,c=Gr(Object.entries(y).map(([t,e])=>[t,e*l])),h=o.metrics??s.metrics??c,p=ls({...s,amount:f[r],metrics:h},[u.id],f[r],Hr(h),t,!0,m);rs(t,p.outletId,`${n}.products.${r}.productId`)&&(i.products[p.id]=p)}),t.diagnostics.some(t=>"error"===t.severity))return;u.productIds=r,u.status="consumed",u.outletId=void 0,u.history.push(m),i.loss.amount+=e.loss?.amount??0;for(const[t,o]of Object.entries(e.loss?.metrics??{}))i.loss.metrics[t]=Number(i.loss.metrics[t]??0)+o;i.history.push(m),is(t,{type:"split-source",sourceIds:[u.id],productIds:r});for(const e of r)is(t,{type:"complete-product",sourceIds:[u.id],productIds:[e],outletIds:i.products[e].outletId?[i.products[e].outletId]:void 0});return}if("eject"===e.type){rs(t,e.outletId,n+".outletId");const o=os(i,e.select,n+".select");t.diagnostics.push(...o.diagnostics);const r=o.ids.filter(t=>i.components[t].productIds.length);if(r.length&&t.diagnostics.push(Qr("error","source-already-assigned",`Assigned source components cannot be ejected: ${r.join(", ")}.`,n+".select",r)),t.diagnostics.some(t=>"error"===t.severity))return;const s=ns(t,e,{sourceIds:o.ids,outletIds:[e.outletId]});for(const t of o.ids){const o=i.components[t];o.status=e.state??"ejected",o.outletId=e.outletId,o.reason=e.reason,o.history.push(s)}return i.history.push(s),void(o.ids.length&&is(t,{type:"retarget-component",sourceIds:o.ids,outletIds:[e.outletId]}))}if("set-metric"===e.type){if(t.diagnostics.push(...ts(e.metricsDelta,n+".metricsDelta")),t.diagnostics.some(t=>"error"===t.severity))return;let o,r;if("run"===e.target)es(i.metrics,e.metricsDelta);else if("components"in e.target){const r=os(i,e.target.components,n+".target.components");if(t.diagnostics.push(...r.diagnostics),t.diagnostics.some(t=>"error"===t.severity))return;o=r.ids;for(const t of r.ids)es(i.components[t].metrics,e.metricsDelta)}else{r=[...e.target.productIds];const o=Jr(r),s=r.filter(t=>!i.products[t]);if(o.length&&t.diagnostics.push(Qr("error","duplicate-product","Metric target product ids must be unique.",n+".target.productIds",o)),s.length&&t.diagnostics.push(Qr("error","unknown-product-state",`Metric target product has not formed: ${s.join(", ")}.`,n+".target.productIds",s)),t.diagnostics.some(t=>"error"===t.severity))return;for(const t of r)es(i.products[t].metrics,e.metricsDelta)}return void i.history.push(ns(t,e,{sourceIds:o,productIds:r}))}e.outcome.trim()?(i.outcome=e.outcome,i.summary=e.summary,i.history.push(ns(t,e)),t.observations.push({type:"crucible-outcome",eventId:t.event.id,phaseId:t.context.phaseId,authoredAt:t.context.authoredAt,appliedAt:t.context.appliedAt,outcome:e.outcome})):t.diagnostics.push(Qr("error","invalid-outcome","Outcome must be a non-empty string.",n+".outcome"))}function ds(t,e,o){if(t.eventsApplied.includes(e.id))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:[Qr("warning","duplicate-event-application",`Event "${e.id}" has already been applied.`,"events."+e.id,[e.id])]};const n=Ur(t),i={state:n,event:e,context:o,productDefinitions:new Map(o.products.map(t=>[t.id,t])),outletIds:new Set(o.outlets.map(t=>t.id)),diagnostics:[],materializations:[],observations:[]};for(const[o,n]of e.effects.entries())if(us(i,n,o),i.diagnostics.some(t=>"error"===t.severity))return{applied:!1,state:t,materializations:[],observations:[],diagnostics:i.diagnostics};return n.elapsed=Math.max(n.elapsed,o.appliedAt),n.phaseId=o.phaseId,n.eventsApplied.push(e.id),i.observations.unshift({type:"crucible-event",eventId:e.id,phaseId:o.phaseId,authoredAt:o.authoredAt,appliedAt:o.appliedAt}),{applied:!0,state:n,materializations:i.materializations,observations:i.observations,diagnostics:i.diagnostics}}var hs=[900,520],ps=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],fs=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),gs=1e-9;function ys(t,e){return e>t?-1:t>e?1:0}function ms(t,e,o,n,i){return{severity:t,code:e,message:o,path:n,ids:i?[...i]:void 0}}function xs(t){const e=new Set,o=new Set;for(const n of t)e.has(n)&&o.add(n),e.add(n);return[...o].sort(ys)}function bs(t){const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function vs(t,e,o,n,i,r){if(!o)return n;try{return("function"==typeof o?o(t,e):t[o])??n}catch(t){return i.push(ms("error","accessor-error",`Accessor threw: ${t instanceof Error?t.message:t+""}.`,r)),n}}function ws(t,e,o){if(!t||"object"!=typeof t||Array.isArray(t))return null!=t&&e.push(ms("error","invalid-metrics","Metrics must be a numeric object.",o)),Gr();const n=Gr();for(const[i,r]of Object.entries(t)){const t=bs(r);null!=t?n[i]=t:e.push(ms("error","invalid-metric",`Metric "${i}" must be finite.`,`${o}.${i}`))}return n}function ks(t){return t.map((t,e)=>({outlet:t,index:e})).sort((t,e)=>(t.outlet.order??t.index)-(e.outlet.order??e.index)||t.index-e.index).map(({outlet:t})=>({...t}))}function As(t){const{id:e,orientation:o,fixed:n,start:i,end:r,openings:s,thickness:a,friction:l,restitution:c}=t,u=function(t,e,o){const n=o.map(([o,n])=>[Math.max(t,Math.min(o,n)),Math.min(e,Math.max(o,n))]).filter(([t,e])=>e>t+gs).sort((t,e)=>t[0]-e[0]||t[1]-e[1]),i=[];let r=t;for(const[t,e]of n)t>r+gs&&i.push([r,t]),r=Math.max(r,e);return e>r+gs&&i.push([r,e]),i}(i,r,s);return u.map(([t,i],r)=>({id:1===u.length?e:`${e}:${r}`,friction:l,restitution:c,shape:"horizontal"===o?{type:"segment",x1:t,y1:n,x2:i,y2:n,thickness:a}:{type:"segment",x1:n,y1:t,x2:n,y2:i,thickness:a}}))}function Ss(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function Ms(t){return"number"==typeof t&&Number.isFinite(t)?t>>>0:"string"==typeof t?Ss(t):1}function _s(t,e){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:e.map(t=>({...t,shape:{...t.shape}})),observation:{chartType:"crucible"},kernel:{seed:Ms(t),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Ps(t){return"crucible:component:"+encodeURIComponent(t)}function Ls(t,e,o,n){if(void 0!==o&&Number.isFinite(o)&&o>0)return o;const i=Math.min(...e,t),r=Math.max(...e,t);return r-i>gs?n[0]+(n[1]-n[0])*Math.sqrt(Math.max(0,t-i)/(r-i)):(n[0]+n[1])/2}function $s(t,e){const o=Math.max(.25,Math.min(1,e.width/900,e.height/520)),n=t?.[0]??7*o,i=t?.[1]??18*o,r=Math.max(1,Math.min(n,i));return[r,Math.max(r,Math.max(n,i))]}function Rs(t,e){if(!t)return[];const o=Math.min(t,Math.max(1,Math.ceil(Math.sqrt(t*Math.max(.5,e.width/Math.max(1,e.height)))))),n=Math.max(1,Math.ceil(t/o));return Array.from({length:t},(t,i)=>({x:e.x+e.width/o*(i%o+.5),y:e.y+(Math.floor(i/o)+.5)*(e.height/n)}))}function Cs(t){return t.outletId?t.outletId:"failed"===t.status?"failed":"recovered"===t.status?"recovered":"retained"===t.status?"retained":"ejected"===t.status?"residue":void 0}function Ts(t,e){return t.outlets.find(t=>t.id===e)||{x:t.chamber.x+.18*t.chamber.width,y:t.chamber.y+.2*t.chamber.height,width:.64*t.chamber.width,height:.6*t.chamber.height}}function Os(t,e,o={}){const n=Object.values(t.products).sort((t,e)=>ys(t.id,e.id)),i=Object.values(t.components).sort((t,e)=>ys(t.id,e.id)),r=[...i.map(t=>t.amount),...n.map(t=>t.amount)],s=$s(o.radiusRange,e),a=function(t,e){const o=new Map;for(const e of t){const t=e.outletId??"__chamber__",n=o.get(t)??[];n.push(e),o.set(t,n)}const n=new Map;for(const[t,i]of o){i.sort((t,e)=>(t.order??Number.MAX_SAFE_INTEGER)-(e.order??Number.MAX_SAFE_INTEGER)||ys(t.id,e.id));const o=Rs(i.length,Ts(e,"__chamber__"===t?void 0:t));i.forEach((t,e)=>n.set(t.id,o[e]))}return n}(n,e),l=n.map(t=>{const n=a.get(t.id)??{x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2},i=1.28*Ls(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"product",semanticId:t.id,product:t};return{id:(c=t.id,"crucible:product:"+encodeURIComponent(c)),x:n.x,y:n.y,mass:Math.max(.25,i*i*.018),bodyCollisions:!1,shape:{type:"circle",radius:i},datum:l};var c}),c=new Map;for(const t of i.filter(t=>!t.productIds.length)){const e=Cs(t)??"__chamber__",o=c.get(e)??[];o.push(t),c.set(e,o)}const u=new Map;for(const[t,o]of c){const n=Rs(o.length,Ts(e,"__chamber__"===t?void 0:t));o.forEach((t,e)=>u.set(t.id,n[e]))}return[...i.map(t=>{let n=u.get(t.id);if(t.productIds.length){const o=t.productIds.map(t=>a.get(t)).filter(t=>!!t);if(o.length){n={x:o.reduce((t,e)=>t+e.x,0)/o.length,y:o.reduce((t,e)=>t+e.y,0)/o.length};const i=Ss(t.id)/4294967295*Math.PI*2,r=Math.min(20,Math.max(4,.012*e.width));n={x:n.x+Math.cos(i)*r,y:n.y+Math.sin(i)*r}}}n??(n={x:e.chamber.x+e.chamber.width/2,y:e.chamber.y+e.chamber.height/2});const i=Ls(t.amount,r,o.bodyRadius,s),l={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ps(t.id),x:n.x,y:n.y,mass:Math.max(.25,i*i*.015),shape:{type:"circle",radius:i},datum:l}}),...l]}var Is=Os;function zs(t){return Array.isArray(t)?t.map(zs):t&&"object"==typeof t?Object.fromEntries(Object.entries(t).filter(([,t])=>void 0!==t&&"function"!=typeof t).sort(([t],[e])=>ys(t,e)).map(([t,e])=>[t,zs(e)])):t}function Fs(t,e=t.duration){const o=function(t,e){const o=bs(e)??0,n=Math.max(0,Math.min(t.duration,o));if(!t.phases.length)return{elapsed:n,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};const i=n>=t.duration-gs,r=i?t.phases[t.phases.length-1]:t.phases.find(t=>n>=t.start&&t.end>n)??t.phases[0];return{elapsed:n,phaseId:r.id,phaseIndex:r.index,phaseElapsed:i?r.duration:Math.max(0,n-r.start),complete:i}}(t,e);let n=Ur(t.initialState);const i=[],r=[],s=[];for(const e of t.events){if(e.authoredAt>o.elapsed+gs)break;const a=ds(n,e,{phaseId:e.phaseId,authoredAt:e.authoredAt,appliedAt:e.authoredAt,products:t.products,outlets:t.outlets});i.push(...a.diagnostics),r.push(...a.materializations),s.push(...a.observations),a.applied&&(n=a.state)}return n.elapsed=o.elapsed,n.phaseId=o.phaseId,n.phaseIndex=o.phaseIndex,n.phaseElapsed=o.phaseElapsed,n.complete=o.complete,o.complete&&"in_process"===n.outcome&&(n.outcome="complete"),n.playing=!1,{state:n,diagnostics:i,materializations:r,observations:s}}function Ns(t){const e=function(t){const e=[];t.length||e.push(ms("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));const o=xs(t.map(t=>t.id));o.length&&e.push(ms("error","duplicate-phase-id",`Phase ids must be unique: ${o.join(", ")}.`,"phases",o));let n=0;return{phases:t.map((t,o)=>{const i=bs(t.duration),r=null!=i&&i>0?i:0;t.id.trim()||e.push(ms("error","invalid-phase-id","Phase ids may not be empty.",`phases.${o}.id`)),null!=i&&i>0||e.push(ms("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${o}.duration`,[t.id])),void 0===t.intensity||Number.isFinite(t.intensity)||e.push(ms("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${o}.intensity`,[t.id]));const s={...t,duration:r,intensity:void 0===t.intensity?.5:Number.isFinite(t.intensity)?Math.max(0,Math.min(1,t.intensity)):.5,motion:t.motion??"hold",index:o,start:n,end:n+r};return n=s.end,s}),diagnostics:e}}(t.phases),o=e.phases.at(-1)?.end??0,n=ks(t.outlets??ps),i=(t.products??[]).map(t=>({...t,metrics:t.metrics?Vr(t.metrics):void 0})),r=function(t,e,o){const n=[],i=xs(t.map(t=>t.id));i.length&&n.push(ms("error","duplicate-event-id",`Event ids must be unique: ${i.join(", ")}.`,"events",i));const r=[];return t.forEach((t,i)=>{let s,a,l;if(t.id.trim()||n.push(ms("error","invalid-event-id","Event ids may not be empty.",`events.${i}.id`)),"time"in t.at&&void 0!==t.at.time){const r=bs(t.at.time);if(null==r||0>r||r>o+gs)return void n.push(ms("error","event-time-out-of-range",`Event time must fall between 0 and ${o}.`,`events.${i}.at.time`,[t.id]));s=Math.max(0,Math.min(o,r));const c=function(t,e,o){const n=t.find(t=>gs>=Math.abs(t.start-o));if(n)return{phase:n,boundaryRank:1};const i=t.find(t=>o>=t.start&&t.end>o);return i?{phase:i,boundaryRank:0}:gs>=Math.abs(o-e)&&t.length?{phase:t[t.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(e,o,s);a=c.phase,l=c.boundaryRank}else{if(a=e.find(e=>e.id===t.at.phaseId),!a)return void n.push(ms("error","unknown-event-phase",`Event references unknown phase "${t.at.phaseId}".`,`events.${i}.at.phaseId`,[t.id,t.at.phaseId]));const o=t.at.progress??0;if(!Number.isFinite(o)||0>o||o>1)return void n.push(ms("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${i}.at.progress`,[t.id]));s=a.start+a.duration*o,l=0===o?1:0}a?r.push({...t,index:i,authoredAt:s,phaseId:a.id,phaseIndex:a.index,boundaryRank:l}):n.push(ms("error","event-without-phase","Event could not be assigned to a phase.",`events.${i}.at`,[t.id]))}),r.sort((t,e)=>t.authoredAt-e.authoredAt||t.boundaryRank-e.boundaryRank||t.index-e.index),{events:r,diagnostics:n}}(t.events??[],e.phases,o),s=function(t){const e=[],o=Gr(),n=[];let i=0;const r=Gr();t.data.forEach((s,a)=>{const l=(s.id??"component-"+a)+"",c=((vs(s,a,t.idAccessor,l,e,`data.${a}.id`)??l)+"").trim();if(!c)return void e.push(ms("error","invalid-component-id","Component ids may not be empty.",`data.${a}.id`));n.push(c);const u=bs(vs(s,a,t.amountAccessor,1,e,`data.${a}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&e.push(ms("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${a}.amount`,[c]));const h=ws(vs(s,a,t.metricsAccessor,{},e,`data.${a}.metrics`),e,`data.${a}.metrics`),p=vs(s,a,t.initialStateAccessor,"active",e,`data.${a}.status`),f=fs.has(p)?p:"active";fs.has(p)||e.push(ms("error","invalid-component-status",`Unknown component status "${p+""}".`,`data.${a}.status`,[c]));const g=vs(s,a,t.labelAccessor,(s.label??s.name??c)+"",e,`data.${a}.label`)+"",y=vs(s,a,t.categoryAccessor,"component",e,`data.${a}.category`)+"";Object.hasOwn(o,c)||(o[c]={id:c,label:g,category:y,datum:s,status:f,initialAmount:d,amount:d,initialMetrics:Vr(h),metrics:Vr(h),productIds:[],history:[]},i+=d,function(t,e){for(const[o,n]of Object.entries(e))t[o]=Number(t[o]??0)+n}(r,h))});const s=xs(n);s.length&&e.push(ms("error","duplicate-component-id",`Component ids must be unique: ${s.join(", ")}.`,"data",s));const a=ws(t.metrics??{},e,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:t.phases[0]?.id??"",phaseIndex:t.phases.length?0:-1,playing:!1,complete:0===t.phases.length,outcome:"in_process",eventsApplied:[],components:o,products:Gr(),relations:Gr(),input:{amount:i,metrics:r},metrics:a,loss:{amount:0,metrics:Gr()},history:[]},diagnostics:e}}(t),a=function(t=hs,e=ps){const o=Math.max(1,bs(t[0])??900),n=Math.max(1,bs(t[1])??520),i=360>o||260>n,r=i?Math.max(4,.035*Math.min(o,n)):20,s=i?Math.max(10,.075*n):34,a={x:r,y:r,width:Math.max(1,o-2*r),height:s},l=i?Math.max(16,.14*n):Math.min(78,.16*n),c={x:r,y:n-r-l,width:Math.max(1,o-2*r),height:l},u=i?Math.max(12,.08*o):Math.min(150,.17*o),d=a.y+a.height+(i?12:38),h=c.y-(i?10:34),p={x:u,y:d,width:Math.max(24,o-2*u),height:Math.max(24,h-d)},f=Math.max(18,Math.min(.32*p.width,i?84:180)),g={x:p.x+(p.width-f)/2,y:p.y-(i?10:24),width:f,height:i?12:28},y=ks(e),m={left:y.filter(t=>"left"===(t.side??"bottom")),right:y.filter(t=>"right"===t.side),bottom:y.filter(t=>"bottom"===(t.side??"bottom"))},x=[],b=(t,e)=>{const n=Math.max(8,u-1.5*r),s=p.height/Math.max(1,e.length);e.forEach((e,a)=>{x.push({...e,side:t,x:"left"===t?r:o-r-n,y:p.y+a*s,width:n,height:Math.max(8,s-(i?2:8))})})};b("left",m.left),b("right",m.right);const v=p.width/Math.max(1,m.bottom.length);return m.bottom.forEach((t,e)=>{x.push({...t,side:"bottom",x:p.x+e*v,y:p.y+p.height+(i?2:7),width:Math.max(8,v-(i?2:8)),height:Math.max(8,c.y-p.y-p.height-(i?4:12))})}),x.sort((t,e)=>y.findIndex(e=>e.id===t.id)-y.findIndex(t=>t.id===e.id)),{width:o,height:n,phaseRail:a,chamber:p,mouth:g,projection:c,outlets:x}}(t.size??hs,n),l=function(t){const{chamber:e,mouth:o}=t,n=Math.max(2,Math.min(10,.018*Math.min(t.width,t.height))),i=Math.max(e.x,o.x),r=Math.min(e.x+e.width,o.x+o.width),s={left:t.outlets.filter(t=>"left"===t.side),right:t.outlets.filter(t=>"right"===t.side),bottom:t.outlets.filter(t=>"bottom"===t.side)},a=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:e.x,y1:e.y,x2:i,y2:e.y,thickness:n}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:r,y1:e.y,x2:e.x+e.width,y2:e.y,thickness:n}}];a.push(...As({id:"crucible:wall:left",orientation:"vertical",fixed:e.x,start:e.y,end:e.y+e.height,openings:s.left.map(t=>[t.y,t.y+t.height]),thickness:n,friction:.46,restitution:.12}),...As({id:"crucible:wall:right",orientation:"vertical",fixed:e.x+e.width,start:e.y,end:e.y+e.height,openings:s.right.map(t=>[t.y,t.y+t.height]),thickness:n,friction:.46,restitution:.12}),...As({id:"crucible:wall:bottom",orientation:"horizontal",fixed:e.y+e.height,start:e.x,end:e.x+e.width,openings:s.bottom.map(t=>[t.x,t.x+t.width]),thickness:n,friction:.5,restitution:.08}));for(const e of t.outlets)a.push({id:"crucible:outlet:"+encodeURIComponent(e.id),sensor:!0,shape:{type:"aabb",x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}});return a}(a),c=function(t,e){const o=[],n=new Set(e.map(t=>t.id)),i=xs(e.map(t=>t.id)),r=xs(t.map(t=>t.id));return i.length&&o.push(ms("error","duplicate-outlet-id",`Outlet ids must be unique: ${i.join(", ")}.`,"outlets",i)),r.length&&o.push(ms("error","duplicate-product-id",`Product ids must be unique: ${r.join(", ")}.`,"products",r)),e.forEach((t,e)=>{t.id.trim()||o.push(ms("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${e}.id`)),void 0===t.order||Number.isFinite(t.order)||o.push(ms("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${e}.order`,[t.id]))}),t.forEach((t,e)=>{t.id.trim()||o.push(ms("error","invalid-product-id","Product ids may not be empty.",`products.${e}.id`)),void 0===t.amount||Number.isFinite(t.amount)&&t.amount>=0||o.push(ms("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${e}.amount`,[t.id])),void 0===t.outletId||n.has(t.outletId)||o.push(ms("error","unknown-outlet",`Product "${t.id}" references unknown outlet "${t.outletId}".`,`products.${e}.outletId`,[t.outletId])),ws(t.metrics??{},o,`products.${e}.metrics`)}),o}(i,n),u=(d={seed:t.seed??1,components:Object.values(s.state.components).sort((t,e)=>ys(t.id,e.id)).map(t=>({id:t.id,label:t.label,category:t.category,amount:t.amount,metrics:t.metrics,status:t.status})),phases:e.phases.map(({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})=>({id:t,duration:e,label:o,description:n,intensity:i,motion:r,color:s,metrics:a})),products:i,outlets:n,events:r.events.map(({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a})=>({id:t,label:e,description:o,summary:n,authoredAt:i,phaseId:r,boundaryRank:s,effects:a}))},JSON.stringify(zs(d)));var d;const h=function(t,e,o={}){const n=Object.values(t.components).sort((t,e)=>ys(t.id,e.id)),i=n.map(t=>t.amount),r=$s(o.radiusRange,e),s=function(t){let e=t>>>0;return()=>{e+=1831565813;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}(Ms(o.seed)),a=e.mouth.x+e.mouth.width/2,l=e.chamber.y+Math.max(18,.18*e.chamber.height),c=Math.max(4,.28*e.chamber.width),u=Math.max(4,.12*e.chamber.height);return n.map((t,e)=>{const d=e/Math.max(1,n.length)*Math.PI*2+.18*(s()-.5),h=Ls(t.amount,i,o.bodyRadius,r),p={__crucible:!0,kind:"component",semanticId:t.id,sourceDatum:t.datum};return{id:Ps(t.id),x:a+Math.cos(d)*c*(.45+.45*s()),y:l+Math.sin(d)*u*(.45+.45*s()),vx:24*(s()-.5),vy:18*(s()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:p}})}(s.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),p=[...e.diagnostics,...r.diagnostics,...s.diagnostics,...c],f={phases:e.phases,events:r.events,products:i,outlets:n,duration:o,initialState:s.state,terminalState:s.state,layout:a,colliders:l,config:_s(t.seed,l),initialSpawns:h,terminalSpawns:[],semanticKey:u,diagnostics:p},g=Fs(f),y=Object.values(g.state.products).filter(t=>"forming"===t.status).map(t=>t.id),m=y.length?[ms("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];return f.terminalState=g.state,f.terminalSpawns=Is(g.state,a,{seed:t.seed,bodyRadius:t.bodyRadius,radiusRange:t.radiusRange}),f.diagnostics=[...p,...g.diagnostics,...m],f}import*as Es from"react";import{curveMonotoneX as Ds,curveMonotoneY as Ws,curveCardinal as Bs,curveCatmullRom as js,curveStep as Ys,curveStepBefore as Xs,curveStepAfter as Gs,curveBasis as Vs,curveNatural as Hs}from"d3-shape";function qs(t){switch(t){case"monotoneX":return Ds;case"monotoneY":return Ws;case"cardinal":return Bs;case"catmullRom":return js;case"step":return Ys;case"stepBefore":return Xs;case"stepAfter":return Gs;case"basis":return Vs;case"natural":return Hs;default:return null}}import{jsx as Us,jsxs as Ks}from"react/jsx-runtime";function Zs(t){return Number.isFinite(t)?1e3>Math.abs(t)?Number.isInteger(t)?t+"":t.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):t.toLocaleString():"0"}function Qs(t,e,o,n){const i=t.datum;if(!i?.__crucible)return;const r="circle"===t.shape.type?t.shape.radius:8,s="string"==typeof e.fill?e.fill:"product"===i.kind?"#b8792d":"#356b63",a="string"==typeof e.stroke?e.stroke:"#26323a",l="number"==typeof e.strokeWidth?e.strokeWidth:1.25,c="number"==typeof e.opacity?e.opacity:.96,u=n?`${n}-crucible-body-${o}`:"crucible-body-"+o;if("product"===i.kind){const e=Array.from({length:6},(e,o)=>{const n=-Math.PI/2+o/6*Math.PI*2;return`${t.x+Math.cos(n)*r},${t.y+Math.sin(n)*r}`}).join(" "),o=u+"-glow";return Ks(Es.Fragment,{children:[Us("defs",{children:Us("filter",{id:o,x:"-60%",y:"-60%",width:"220%",height:"220%",children:Us("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:s,floodOpacity:"0.8"})})}),Us("polygon",{points:e,fill:s,stroke:a,strokeWidth:l,opacity:c,filter:`url(#${o})`}),Us("circle",{cx:t.x,cy:t.y,r:Math.max(2,.36*r),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}return Ks(Es.Fragment,{children:[Us("circle",{cx:t.x,cy:t.y,r:r,fill:s,stroke:a,strokeWidth:l,opacity:c}),Us("circle",{cx:t.x-.25*r,cy:t.y-.28*r,r:Math.max(1,.18*r),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as Js,jsx as ta,jsxs as ea}from"react/jsx-runtime";var oa="var(--semiotic-text, #26323a)",na="var(--semiotic-text-secondary, #6c7377)",ia="var(--semiotic-primary, #b8792d)",ra="var(--semiotic-danger, #9f3d35)",sa="var(--semiotic-success, #356b63)";function aa(t){const{x:e,y:o,width:n,height:i}=t.chamber,r=Math.min(.14*n,48),s=o+i;return[`M ${e} ${o}`,`L ${e+r} ${s-.16*i}`,`Q ${e+n/2} ${s+.1*i} ${e+n-r} ${s-.16*i}`,`L ${e+n} ${o}`].join(" ")}function la({layout:t,phases:e,state:o,compact:n=!1}){const i=Math.max(1,e.reduce((t,e)=>t+Math.max(0,e.duration),0));return ea("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[ea("defs",{children:[ea("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[ta("stop",{offset:"0",stopColor:ia,stopOpacity:"0.03"}),ta("stop",{offset:"0.66",stopColor:ia,stopOpacity:"0.1"}),ta("stop",{offset:"1",stopColor:ra,stopOpacity:"0.18"})]}),ta("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:ta("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:oa,strokeOpacity:"0.08",strokeWidth:"1"})})]}),ta("rect",{x:t.chamber.x,y:t.chamber.y,width:t.chamber.width,height:t.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:oa,strokeOpacity:"0.52",strokeWidth:n?1:2.2}),ta("path",{d:aa(t),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),ta("line",{x1:t.mouth.x,x2:t.mouth.x+t.mouth.width,y1:t.mouth.y,y2:t.mouth.y,stroke:oa,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:n?2:5}),n?null:ta("g",{"data-testid":"crucible-phase-rail",children:e.map((n,r)=>{const s=e.slice(0,r).reduce((t,e)=>t+Math.max(0,e.duration),0),a=t.phaseRail.x+s/i*t.phaseRail.width,l=Math.max(0,n.duration)/i*t.phaseRail.width,c=n.id===o.phaseId,u=o.phaseIndex>r||o.complete;return ea("g",{children:[ta("rect",{x:a,y:t.phaseRail.y,width:Math.max(1,l-2),height:t.phaseRail.height,rx:2,fill:c?n.color??ia:u?sa:oa,fillOpacity:c?.68:u?.28:.09}),46>l?null:ta("text",{x:a+l/2,y:t.phaseRail.y+t.phaseRail.height+13,fill:c?oa:na,fontFamily:"system-ui, sans-serif",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(n.label??n.id).toUpperCase()})]},n.id)})}),t.outlets.map(t=>ea("g",{children:[ta("rect",{x:t.x,y:t.y,width:t.width,height:t.height,rx:3,fill:t.color??("left"===t.side?ra:sa),fillOpacity:"0.1",stroke:t.color??("left"===t.side?ra:sa),strokeDasharray:"3 3",strokeOpacity:"0.62"}),n?null:ta("text",{x:t.x+t.width/2,y:t.y+Math.min(13,t.height/2+3),fill:na,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(t.label??t.id).toUpperCase()})]},t.id))]})}function ca({rows:t,layout:e,projection:o,amountLabel:n}){if(!t.length)return null;const i=o.measure??"count",r=t.map(t=>Math.max(0,function(t,e){return"count"===e?t.count:"amount"===e?t.amount:Number(t.metrics[e]??0)}(t,i))),s=Math.max(1,...r),a=e.projection.width/Math.max(1,t.length),l=e.projection.height>48?21:4,c=Math.max(5,e.projection.height-l-5);return ta("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:t.map((t,o)=>{const u=r[o],d=Math.max(u>0?2:0,u/s*c),h=e.projection.x+o*a+.18*a;return ea("g",{children:[ta("rect",{x:h,y:e.projection.y+c-d,width:Math.max(3,.64*a),height:d,rx:2,fill:"failed"===t.status||"ejected"===t.status?ra:"complete"===t.status?ia:sa,fillOpacity:"0.68"}),l>4&&a>=34?ea(Js,{children:[ta("text",{x:h+.32*a,y:e.projection.y+c+10,fill:na,fontFamily:"system-ui, sans-serif",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:t.label.length>13?t.label.slice(0,12)+"…":t.label}),ea("text",{x:h+.32*a,y:e.projection.y+c+19,fill:oa,fontFamily:"system-ui, sans-serif",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Zs(u),"amount"===i&&n?" "+n:""]})]}):null]},t.key)})})}function ua(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}import{Fragment as da,jsx as ha,jsxs as pa}from"react/jsx-runtime";function fa(t,e,o,n,i){const r=Array.isArray(i)?i:i?[i]:[];if(!1!==o||0!==r.length)return({size:i})=>{const s=[Number(i[0])||700,Number(i[1])||420],a=ar(s),l=Math.max(2,Math.round(e)),c=a.plot.width/l,u=a.plot.y+a.plot.height,d=Math.max(1,...t.map(t=>t.value)),h=!1!==o,[p,f]=n?.valueExtent??[0,l],g=f===p?1:f-p,y=t.map((t,e)=>{const o=u-t.value/d*a.plot.height*.9;return`${0===e?"M":"L"} ${(a.plot.x+(e+.5)*c).toFixed(1)} ${o.toFixed(1)}`}).join(" ");return pa("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:s[0],height:s[1],viewBox:`0 0 ${s[0]} ${s[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?pa(da,{children:[Array.from({length:l+1},(t,e)=>{const o=a.plot.x+e*c;return ha("line",{"data-testid":"galton-board-bin-wall",x1:o,x2:o,y1:a.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+e)}),ha("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ha("path",{d:y,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),t.map((t,e)=>t.value>0?ha("text",{x:a.plot.x+(e+.5)*c,y:Math.max(a.plot.y+10,u-t.value/d*a.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.value},`${t.label}-${e}`):null)]}):null,r.map((t,e)=>{const o=Number(t.value);if(!Number.isFinite(o))return null;const n=a.plot.x+Math.max(0,Math.min(1,(o-p)/g))*a.plot.width,i=t.color??"var(--semiotic-warning, #f28e2b)",r="bottom"===t.labelPosition?Math.min(s[1]-8,u+16):a.plot.y+16;return pa("g",{className:t.className,"data-testid":"galton-board-reference-line",children:[ha("line",{x1:n,x2:n,y1:a.plot.y+8,y2:u-4,stroke:i,strokeDasharray:t.strokeDasharray??"6 5",strokeWidth:t.strokeWidth??2}),null==t.label?null:ha("text",{x:Math.min(a.plot.x+a.plot.width-4,n+6),y:r,fill:i,fontSize:10,fontWeight:700,children:t.label})]},`galton-reference-${e}-${o}`)})]})}}function ga(t,e,o){if(!1!==o&&e)return({size:o})=>{const n=[Number(o[0])||760,Number(o[1])||360],i=ar(n),r=Math.max(1,e.windowCount),s=e.plot??i.plot,a=e.gutter??{x:s.x,y:s.y,width:0,height:s.height},l=e.windowPlot??s,c=l.width/r,u=s.y+s.height,d=s.y+.48*s.height,h=e.lidSegments[0]?.y1??d,p=e.windowStart,f=e.windowStart+r*e.windowSize,g=l.x+Math.max(0,Math.min(1,f===p?0:(e.watermarkValue-p)/(f-p)))*l.width;return pa("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[ha("rect",{x:s.x,y:s.y,width:s.width,height:s.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),a.width>0?pa("g",{children:[ha("rect",{x:a.x,y:h,width:a.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.55,strokeWidth:1}),ha("text",{x:a.x+a.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:"gutter"})]}):null,Array.from({length:r},(o,i)=>{const r=t[i],s=l.x+i*c,a=e.closedWindowCount>i,h=r?.secondary??0;return pa("g",{children:[ha("rect",{x:s,y:d,width:c,height:u-d,fill:a?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:a?.08:.06,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.68,strokeWidth:1}),a?e.lidSegments.filter(t=>t.windowIndex===i).map(t=>ha("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},t.id)):null,pa("text",{x:s+c/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:[r?.value??0,h?` / ${h} late`:""]}),ha("text",{x:s+c/2,y:Math.min(n[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:r?.label??""})]},"window-"+i)}),e.lidSegments.filter(t=>null==t.windowIndex).map(t=>ha("line",{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},t.id)),ha("line",{x1:s.x,x2:s.x+s.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),ha("line",{"data-testid":"event-drop-watermark",x1:g,x2:g,y1:s.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),pa("text",{x:Math.min(s.x+s.width-4,g+6),y:s.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*e.watermarkValue)/100]}),e.lateCount>0?pa("text",{x:a.x+a.width/2,y:s.y+32,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[e.lateCount," late"]}):null]})}}function ya(t,e,o){if(!1!==o&&0!==t.length)return({size:o})=>{const n=[Number(o[0])||700,Number(o[1])||380],i=ar(n),r=vr(i.plot,t.length,e),s=i.plot.y+i.plot.height;return pa("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[ha("line",{x1:i.plot.x,x2:i.plot.x+i.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),t.map((t,e)=>{const o=Math.min(i.plot.height,r.pileHeight(t.value)),a=r.tubeWidth,l=r.centerX(e),c=s-o;return pa("g",{children:[ha("rect",{x:l-a/2,y:c,width:a,height:o,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),ha("text",{x:l,y:Math.max(i.plot.y+12,c-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:t.value}),ha("text",{x:l,y:Math.min(n[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${e}`)})]})}}function ma(t){return t.toLocaleString(void 0,Math.abs(t)>=1e3||.01>Math.abs(t)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function xa(t,e){if(!1!==e&&t)return({size:e})=>{const o=[Number(e[0])||700,Number(e[1])||360],n=ar(o),i=n.plot.y+n.plot.height,[r,s]=t.xExtent,a=r+(s-r)/2,l=[{label:ma(r),x:t.xRange[0]},{label:ma(a),x:t.xRange[0]+(t.xRange[1]-t.xRange[0])/2},{label:ma(s),x:t.xRange[1]}];return pa("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[t.groups.map(t=>pa("g",{children:[ha("line",{x1:n.plot.x,x2:n.plot.x+n.plot.width,y1:t.y,y2:t.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),ha("text",{x:n.plot.x+4,y:t.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:t.label}),pa("text",{x:n.plot.x+n.plot.width-4,y:t.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",t.count]})]},t.label)),ha("line",{x1:t.xRange[0],x2:t.xRange[1],y1:i,y2:i,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(t=>pa("g",{children:[ha("line",{x1:t.x,x2:t.x,y1:i,y2:i+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),ha("text",{x:t.x,y:Math.min(o[1]-8,i+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:t.label})]},`${t.label}-${t.x}`))]})}}import{jsx as ba}from"react/jsx-runtime";function va(t,e,o={},n){if(!1===e||!t)return;const{volume:i,stages:r,groups:s,groupCompletion:a}=t,l=new Map(i.stages.map(t=>[t.id,t])),c=new Map(a.map(t=>[t.id,t]));return({size:t})=>{const e=Number(t[0])||i.width,a=Number(t[1])||i.height,u=r.map(t=>{const e=l.get(t.id),n=o["process-stage-"+t.id];return{id:t.id,label:t.label,x0:e?.x0??t.x-t.width/2,x1:(e?.x0??t.x-t.width/2)+(e?.width??t.width),x:t.x,width:e?.width??t.width,count:t.count,capacity:t.capacity,absorb:t.absorb,portalTarget:t.portalTarget,queueDepth:n?.queueDepth,processed:n?.processedCount}}),d=s.map(t=>{const e=c.get(t.id);return{id:t.id,label:t.label??t.id,x:t.anchor?.x??t.x??0,y:t.anchor?.y??t.y??0,absorbed:e?.absorbed,total:e?.total,complete:e?.complete}});return O({width:e,height:a,left:i.left,right:i.right,topY:i.topY,bottomY:i.bottomY,midY:i.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...n})}}function wa(t,e,o){if(!1===o||!e||0===t.length)return;const n=new Map(e.volume.stages.map(t=>[t.id,t]));return({size:o})=>{const i=[Number(o[0])||e.volume.width,Number(o[1])||e.volume.height],r=ar(i),s=Math.max(1,...t.map(t=>t.value)),a=Math.min(48,.18*r.plot.height),l=r.plot.y+6;return ba("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:e.stages.map((e,o)=>{const i=t[o];if(!i)return null;const r=n.get(e.id);if(!r)return null;const c=Math.max(2,i.value/s*a),u=Math.max(8,.35*r.width);return ba("rect",{x:r.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},e.id)})})}}function ka(t){return t.map((t,e)=>`${0===e?"M":"L"} ${t.x} ${t.y}`).join(" ")}import{jsx as Aa,jsxs as Sa}from"react/jsx-runtime";function Ma(t,e){const{showNodeLabels:o,showSensors:n,showStaticFlow:i}=e;if(t&&(i||n||o))return({size:e})=>{const r=[Number(e[0])||760,Number(e[1])||420],s=Math.max(1,...t.links.map(t=>t.throughput)),a=new Set(t.nodes.map(t=>t.sensorId));return Sa("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[i?t.links.map(t=>{const e=3+t.throughput/s*16,o=t.path[Math.floor(t.path.length/2)];return Sa("g",{children:[Aa("path",{d:ka(t.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:e+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),Aa("path",{d:ka(t.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),o?Aa("text",{x:o.x,y:o.y-e/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:(n=t.throughput,n.toLocaleString(void 0,1e3>Math.abs(n)?{maximumFractionDigits:1}:{maximumFractionDigits:0}))}):null]},t.id);var n}):null,t.nodes.map(t=>Sa("g",{children:[n&&a.has(t.sensorId)?Aa("rect",{"data-testid":"physical-flow-sensor-overlay",x:t.x-12,y:t.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,i?Aa("circle",{cx:t.x,cy:t.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,o?Aa("text",{x:t.x,y:t.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:t.label}):null]},t.id))]})}}import{Fragment as _a,jsx as Pa,jsxs as La}from"react/jsx-runtime";function $a({layout:t,compact:e,showLabels:o}){const n=e?Math.round(.14*t.height):Math.max(80,t.routeY-180),i=e?Math.max(6,Math.round(.72*t.height)):Math.min(360,t.height-170);return Pa(_a,{children:t.gates.map(r=>La("g",{children:[Pa("rect",{x:r.x-r.width/2,y:n,width:r.width,height:i,rx:e?2:12,fill:r.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:r.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),o?Pa("text",{x:r.x,y:Math.max(64,t.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:r.label??r.id}):null]},r.id))})}function Ra({layout:t,states:e,compact:o=!1}){return o?Pa("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:Pa($a,{layout:t,compact:!0,showLabels:!1})}):La("svg",{"aria-hidden":"true",viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Pa("path",{d:`M ${t.startX-42} ${t.routeY} C ${.24*t.width} ${t.routeY-70}, ${.42*t.width} ${t.routeY+78}, ${.58*t.width} ${t.routeY} S ${.78*t.width} ${t.routeY-82}, ${t.socketX+36} ${t.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),Pa("line",{x1:Math.round(.06*t.width),x2:Math.round(.94*t.width),y1:t.crashY,y2:t.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),Pa("text",{x:Math.round(.07*t.width),y:t.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),Pa($a,{layout:t,compact:!1,showLabels:!0}),La("g",{children:[Pa("rect",{x:t.socketX-52,y:t.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),Pa("text",{x:t.socketX,y:t.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),La("g",{children:[Pa("rect",{x:t.graveyardX-82,y:t.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),Pa("text",{x:t.graveyardX,y:t.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),Pa("text",{x:t.graveyardX,y:t.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:e.some(t=>t.killed)?"lift shut off":"too heavy or too small"})]})]})}function Ca({states:t,layout:e}){const o=function(t){return t.map(t=>({label:t.id,value:Math.max(0,Number(t.viability)||0),outcome:t.outcome||t.stage||"in-process"}))}(t);if(!o.length)return null;const n=Math.max(1,...o.map(t=>t.value)),i=Math.max(40,(e.width-80)/o.length);return La("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:e.width,height:e.height,viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[Pa("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),o.map((t,e)=>{const o=40+e*i,r=Math.max(2,t.value/n*28),s=/kill|crash|block|grave/i.test(t.outcome);return La("g",{children:[Pa("rect",{x:o+.18*i,y:28-r+22,width:Math.max(10,.45*i),height:r,rx:2,fill:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:s?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),Pa("text",{x:o+.4*i,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:t.label})]},t.label)})]})}var Ta={margin:(t,e)=>e.compactMode?"sparkline"===t.mode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}};function Oa(t){return t.map(t=>({...t,spawnAt:void 0}))}function Ia(t,e){return t?e?o=>sr.createElement(sr.Fragment,null,"function"==typeof t?t(o):t,"function"==typeof e?e(o):e):t:e}function za(t,e,o){const n=e[o];return"boolean"==typeof n?n:!0!==t.__compactMode}var Fa=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function Na(t){let e=2166136261;for(let o=0;t.length>o;o+=1)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return Fa[(e>>>0)%Fa.length]}var Ea={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(t,e,o,n,i)=>({chartType:"line",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",groupAccessor:i.lineBy||e,colorAccessor:e,...n,showAxes:!1,margin:n.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:Ao,LineChart:_o,AreaChart:Lo,DifferenceChart:$o,StackedAreaChart:Ro,Scatterplot:Ie,CandlestickChart:Co,BubbleChart:ze,ConnectedScatterplot:Oo,QuadrantChart:To,Heatmap:Io,TemporalHistogram:Po,XYCustomChart:{frameType:"xy",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1,showLegend:n.showLegend??!!e})},BarChart:nn,StackedBarChart:rn,GroupedBarChart:sn,PieChart:an,DonutChart:ln,Histogram:cn,BoxPlot:un,ViolinPlot:dn,SwarmPlot:hn,DotPlot:pn,SwimlaneChart:fn,RidgelinePlot:gn,LikertChart:yn,FunnelChart:mn,GaugeChart:xn,OrdinalCustomChart:{frameType:"ordinal",buildProps:(t,e,o,n,i)=>({chartType:"custom",data:t,oAccessor:i.categoryAccessor||i.oAccessor||"category",rAccessor:i.valueAccessor||i.rAccessor||"value",projection:i.projection||"vertical",colorAccessor:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n,showAxes:i.frameProps?.showAxes??i.showAxes??!1})},ForceDirectedGraph:Hi,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(t,e,o,n,i)=>({chartType:"force",nodes:i.nodes||t||[],edges:i.edges||[],nodeIDAccessor:i.nodeIdAccessor||i.nodeIDAccessor||"id",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",valueAccessor:i.valueAccessor||"value",colorBy:e,colorScheme:o,customNetworkLayout:i.layout||i.customNetworkLayout,layoutConfig:i.layoutConfig,...n})},SankeyDiagram:Zi,ProcessSankey:Ki,ChordDiagram:Vi,TreeDiagram:Qi,Treemap:Ji,CirclePack:qi,OrbitDiagram:Ui,ChoroplethMap:nr,ProportionalSymbolMap:ir,FlowMap:rr,GeoCustomChart:{frameType:"geo",buildProps:(t,e,o,n,i)=>({points:i.points||t||[],areas:i.areas||[],lines:i.lines||[],projection:i.projection||"equirectangular",xAccessor:i.xAccessor||"lon",yAccessor:i.yAccessor||"lat",lineDataAccessor:i.lineDataAccessor,colorBy:e,colorScheme:o,customLayout:i.layout||i.customLayout,layoutConfig:i.layoutConfig,...n})},GaltonBoardChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=i.bins??21,c=i.seed??1,u=Math.max(1,Math.round(i.pegRows??s-1)),d="mechanical"===i.mode,h=d?function(t){const e=Math.max(2,Math.round(t.bins)),o=Math.max(1,Math.round(t.pegRows??e-1)),n=Math.max(1,Math.round(t.count??Math.max(64,4*e))),i=pr(Number.isFinite(t.branchProbability)?t.branchProbability??.5:.5,0,1),r=yr(t.seed??1),s=t.idPrefix??"mechanical";return Array.from({length:n},(t,e)=>{let n=0;for(let t=0;o>t;t+=1)r()<i&&(n+=1);const a=o/2;return{id:`${s}-${e}`,value:n,mechanical:!0,pegRows:o,branchProbability:i,pathRights:n,side:a>n?"left":n>a?"right":"center"}})}({bins:s,branchProbability:i.branchProbability,count:i.mechanicalCount,pegRows:u,seed:c}):Array.isArray(t)?t:[],p=function(t){const{data:e,valueAccessor:o,bins:n,ballRadius:i,seed:r,size:s,valueExtent:c}=t,u=ar(s),d=e.map((t,e)=>hr(dr(t,e,o))).filter(t=>null!=t),h=function(t){if(!t)return;const e=hr(t[0]),o=hr(t[1]);return null!=e&&null!=o?e>o?[o,e]:[e,o]:void 0}(c),p=h?.[0]??(d.length?Math.min(...d):0),f=h?.[1]??(d.length?Math.max(...d):1),g=f===p?1:f-p,y=mr().domain([0,n]).range([u.plot.x,u.plot.x+u.plot.width]),m=Array.from({length:n},()=>0),x=[];e.forEach((t,e)=>{const r=hr(dr(t,e,o));if(null==r)return;const s=Math.max(0,Math.min(n-1,Math.floor((r-p)/g*n)));m[s]+=1,x.push({id:(t.id??"galton-"+e)+"",x:y(s+.5),y:u.plot.y+i+2,vx:8*(e%5-2),vy:0,mass:1,shape:{type:"circle",radius:i},datum:{...t,value:r,bin:s}})});const b=u.plot.y+u.plot.height;return{config:ur(r,[...a({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...l({idPrefix:"galton-bin",count:n,domainStart:0,domainStep:1,xScale:y,yTop:u.plot.y-400,yBottom:b,wallThickness:6})],"GaltonBoardChart"),initialSpawns:x,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((t,e)=>({label:e+1+"",value:t})),metadata:{kind:"galton-board",bins:n,plot:u.plot,valueExtent:[p,f]}}}({data:h,valueAccessor:i.valueAccessor||"value",bins:s,ballRadius:i.ballRadius??4,seed:c,size:r,valueExtent:d?[0,u]:void 0});return{...n,config:p.config,initialSpawns:Oa(p.initialSpawns),projectionRows:p.projectionRows,foregroundGraphics:Ia(fa(p.projectionRows,s,za(n,i,"showProjection"),p.metadata,i.referenceLines),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||(d?"side":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},EventDropChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s=function(t){const{data:e,timeAccessor:o,arrivalAccessor:n,windows:i,watermark:r,ballRadius:s,seed:l,size:c,timeExtent:u,timeScale:d=1}=t,h=ar(c),p=e.map((t,e)=>hr(dr(t,e,o))).filter(t=>null!=t),f=hr(u?.[0]),g=hr(u?.[1]),y=p.length?Math.min(...p):0,m=p.length?Math.max(...p):y+i.size,x=Math.min(f??y,y),b=Math.max(g??m,m),v=Math.floor(x/i.size)*i.size,w=Math.max(1,Math.ceil((b-v+i.size)/i.size)),k=p.length?Math.max(...p):0,A="function"==typeof r?r(k):hr(r?.value)??k-(r?.delay??i.size),S=Math.max(0,Math.min(w,Array.from({length:w},(t,e)=>e).reduce((t,e)=>v+(e+1)*i.size>A?t:t+1,0))),M=function(t,e){const o=Math.max(5*e,Math.min(92,.13*t.plot.width));return{gutter:{x:t.plot.x,y:t.plot.y,width:o,height:t.plot.height},windowPlot:{x:t.plot.x+o,y:t.plot.y,width:Math.max(40,t.plot.width-o),height:t.plot.height},wallTop:t.plot.y+.48*t.plot.height}}(h,s),_=v+w*i.size,P=xr().domain([v,_]).range([M.windowPlot.x,M.windowPlot.x+M.windowPlot.width]),L=Array.from({length:w},()=>({value:0,secondary:0})),$=[];e.forEach((t,e)=>{const r=hr(dr(t,e,o));if(null==r)return;const a=hr(dr(t,e,n))??r,l=Math.max(0,Math.min(w-1,Math.floor((r-v)/i.size))),c=A>=v+(l+1)*i.size;L[l].value+=c?0:1,L[l].secondary+=c?1:0,$.push({id:(t.id??"event-"+e)+"",x:Math.max(M.windowPlot.x+s,Math.min(M.windowPlot.x+M.windowPlot.width-s,P(r))),y:h.plot.y+s+2,vx:8*(e%3-1),vy:0,mass:1,friction:.02,spawnAt:a,shape:{type:"circle",radius:s},datum:{...t,eventTime:r,arrivalTime:a,windowIndex:l,late:c}})});const R=h.plot.y+h.plot.height,C=function(t,e){const o=Math.max(0,Math.min(t.windowCount,t.closedWindowCount));if(!o)return[];const n=t.windowStart,i=t.windowStart+t.windowCount*t.windowSize,r=xr().domain([n,i]).range([t.windowPlot.x,t.windowPlot.x+t.windowPlot.width]),s=r(t.windowStart+o*t.windowSize),a=t.windowPlot.x,l=e+Math.max(18,Math.min(.3*t.windowPlot.height,s-a)),c=t=>s===a?e:l+(t-a)/(s-a)*(e-l),u=[];for(let e=0;o>e;e+=1){const o=t.windowStart+e*t.windowSize,n=o+t.windowSize,i=r(o),s=r(n);u.push({id:"eventdrop-lid-"+e,windowIndex:e,x1:i,y1:c(i),x2:s,y2:c(s)})}return u}({closedWindowCount:S,gutter:M.gutter,plot:h.plot,windowCount:w,windowPlot:M.windowPlot,windowSize:i.size,windowStart:v},h.plot.y+.28*h.plot.height);return{config:ur(l,[...a({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...br({idPrefix:"eventdrop-window",count:w,xScale:t=>P(v+t*i.size),yTop:M.wallTop,yTopForIndex:t=>{const e=(t=>{if(0>t||t>S)return null;const e=0===t?C[0]?.y1:C[t-1]?.y2??C[t]?.y1;return"number"==typeof e&&Number.isFinite(e)?e:null})(t);return null==e?M.wallTop:e+1.25*s},yBottom:R,wallThickness:6}),...C.map(t=>({id:t.id,shape:{type:"segment",x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:$,initialSpawnPacing:{pacing:"arrival",timeAccessor:t=>t.datum?.arrivalTime,timeScale:d},projectionRows:L.map((t,e)=>({label:`${v+e*i.size}-${v+(e+1)*i.size}`,value:t.value,secondary:t.secondary})),metadata:{kind:"event-drop",closedWindowCount:S,gutter:M.gutter,lidSegments:C,lateCount:L.reduce((t,e)=>t+e.secondary,0),plot:h.plot,windowPlot:M.windowPlot,watermarkValue:A,windowCount:w,windowSize:i.size,windowStart:v}}}({data:Array.isArray(t)?t:[],timeAccessor:i.timeAccessor||"time",arrivalAccessor:i.arrivalAccessor||"arrivalTime",windows:i.windows||{size:10},watermark:i.watermark,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r,timeExtent:i.timeExtent,timeScale:i.timeScale??1});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(ga(s.projectionRows,s.metadata,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||i.timeAccessor||"time"})}}},UnitPileChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,400],s="mechanical"===i.mode,l=function(t){const{data:e,categoryAccessor:o,valueAccessor:n,unitValue:i,ballRadius:r,seed:s,size:l}=t,c=fr(i,1),u=ar(l),d=[],h=new Map,p=new Map,f=[];function g(t){let e=h.get(t);return null==e&&(e=d.length,d.push(t),h.set(t,e)),e}e.forEach((t,e)=>{g((dr(t,e,o)??"unknown")+"")});const y=Math.max(1,d.length),m=vr(u.plot,y,r),x=Math.max(0,m.tubeWidth/2-r-1),b=d.map(()=>[]);e.forEach((t,e)=>{const i=(dr(t,e,o)??"unknown")+"",s=g(i),a=n?hr(dr(t,e,n)):1,l=Math.max(0,Math.round((a??0)/c)),d=m.centerX(s);for(let o=0;l>o;o+=1){const n=p.get(i)??0,a=m.perRow>1?((m.perRow>1?n%m.perRow:0)/(m.perRow-1)*2-1)*x:0;p.set(i,n+1),b[s].push({id:`${(t.id??"pile-"+e)+""}-${o}`,x:d+a,y:u.plot.y+r+2,vx:(o%3-1)*r/2,vy:0,mass:1,shape:{type:"circle",radius:r},datum:{...t,category:i,unitIndex:o}})}});const v=b.reduce((t,e)=>Math.max(t,e.length),0);for(let t=0;v>t;t+=1)for(const e of b)e.length>t&&f.push(e[t]);const w=u.plot.y+u.plot.height,k=[...a({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],A=u.plot.y-400;for(let t=0;y>t;t+=1){const e=m.centerX(t);for(const o of[-1,1])k.push({id:`pile-tube-${t}-${0>o?"l":"r"}`,shape:{type:"aabb",x:e+o*m.tubeWidth/2,y:(A+w)/2,width:6,height:w-A}})}return{config:ur(s,k,"UnitPileChart"),initialSpawns:f,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(t=>({label:t,value:p.get(t)??0}))}}({data:s?function(t={}){const e=(t.categories?.length?t.categories:["Intake","Review","Build","Ship"]).map(t=>(t+"").trim()).filter(Boolean),o=e.length?e:["Intake"],n=Math.max(o.length,Math.round(t.count??Math.max(48,12*o.length))),i=fr(t.unitValue,1),r=yr(t.seed??1),s=t.idPrefix??"mechanical-pile",a=o.map(()=>.65+.9*r()),l=a.reduce((t,e)=>t+e,0)||1,c=n-o.length,u=a.map(t=>t/l*c),d=u.map(t=>1+Math.floor(t));let h=n-d.reduce((t,e)=>t+e,0);const p=u.map((t,e)=>({index:e,fraction:t-Math.floor(t)})).sort((t,e)=>e.fraction-t.fraction);for(let t=0;h>0;t=(t+1)%p.length)d[p[t].index]+=1,h-=1;return o.map((t,e)=>({id:`${s}-${e}`,category:t,value:d[e]*i,mechanical:!0,unitCount:d[e],unitValue:i,share:d[e]/n}))}({categories:i.mechanicalCategories,count:i.mechanicalCount,seed:i.seed??1,unitValue:i.unitValue??1}):Array.isArray(t)?t:[],categoryAccessor:i.categoryAccessor||"category",valueAccessor:i.valueAccessor||(s?"value":void 0),unitValue:i.unitValue??1,ballRadius:i.ballRadius??5,seed:i.seed??1,size:r});return{...n,config:l.config,initialSpawns:Oa(l.initialSpawns),projectionRows:l.projectionRows,foregroundGraphics:Ia(ya(l.projectionRows,i.ballRadius??5,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||(s?"category":void 0),"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.valueAccessor||"value"})}}},CollisionSwarmChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[600,360],s=function(t){const{data:e,xAccessor:o,groupAccessor:n,radiusAccessor:i,pointRadius:r,seed:s,size:l,xExtent:c,collisionIterations:u,settle:d}=t,h=ar(l),p=yr(s),f=[],g=[],y=new Map;e.forEach((t,e)=>{const s=hr(dr(t,e,o));if(null==s)return;const a=n?(dr(t,e,n)??"All")+"":"All",l=i?hr(dr(t,e,i)):null,c=pr(null!=l&&l>0?l:r,2,18);!function(t){let e=y.get(t);null==e&&(e=g.length,g.push(t),y.set(t,e))}(a),f.push({datum:t,index:e,value:s,group:a,radius:c})});const m=f.map(t=>t.value),x=c?hr(c[0]):null,b=c?hr(c[1]):null,v=m.length?Math.min(...m):0,w=m.length?Math.max(...m):1;let k=x??v,A=b??w;if(k===A&&(k-=.5,A+=.5),k>A){const t=A;A=k,k=t}const S=Math.max(r,...f.map(t=>t.radius)),M=h.plot.x+S+8,_=h.plot.x+h.plot.width-S-8,P=wr().domain([k,A]).range([M,_]),L=Math.max(1,g.length),$=Math.min(Math.max(28,3*S),h.plot.height/4),R=h.plot.y+$,C=Math.max(0,h.plot.y+h.plot.height-$-R),T=t=>{const e=y.get(t)??0;return 1===L?h.plot.y+.54*h.plot.height:R+e/(L-1)*C},O=new Map,I=f.map((t,e)=>{O.set(t.group,(O.get(t.group)??0)+1);const o=P(t.value),n=T(t.group),i=(p()-.5)*t.radius*1.6,r=(p()-.5)*t.radius*1.6;return{id:(t.datum.id??"collision-swarm-"+e)+"",x:d?o+i:pr(o+(e%9-4)*t.radius*2.5,M,_),y:d?n+r:h.plot.y-18-e%12*t.radius,vx:d?0:22*(p()-.5),vy:d?0:24+18*p(),mass:1,shape:{type:"circle",radius:t.radius},datum:{...t.datum,xValue:t.value,group:t.group,radius:t.radius,targetX:o,targetY:n},springs:[{target:{type:"point",x:o,y:n},restLength:0,stiffness:34,damping:5.5}]}});return{config:ur(s,a({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*S),collisionIterations:Math.max(1,Math.round(u??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:I,projectionRows:g.map(t=>({label:t,value:O.get(t)??0})),metadata:{kind:"collision-swarm",xExtent:[k,A],xRange:[M,_],groups:g.map(t=>({label:t,y:T(t),count:O.get(t)??0})),plot:h.plot}}}({data:Array.isArray(t)?t:[],xAccessor:i.xAccessor||"x",groupAccessor:i.groupAccessor,radiusAccessor:i.radiusAccessor,pointRadius:i.pointRadius??5,seed:i.seed??1,size:r,xExtent:i.xExtent,collisionIterations:i.collisionIterations,settle:i.settle});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(xa(s.metadata,za(n,i,"showProjection")),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||i.groupAccessor,"#4e79a7",{styleRules:i.styleRules,valueAccessor:i.xAccessor||"x"})}}},ProcessFlowChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,i,a)=>{const l=i.size??[900,420],c=Array.isArray(a.stages)?a.stages:[],d=function(t){const e=t.stages;if(!e.length)throw Error("buildProcessFlowPhysics requires at least one stage");const o=t.size,i=ar(o),a=pr(t.ballRadius??6,2,18),l=t.seed??1,c=yr(l),d=t.idAccessor,h=t.stageAccessor??"stage",p=t.groupBy,f=t.groupLabelAccessor,g=t.workAccessor,m=t.radiusAccessor,x=t.groupCompletion??(p?"allAbsorbed":"none"),b=t.springStiffness??.28,v=t.springDamping??.72,w=!0===t.settle,k=e.map(t=>({id:t.id,label:t.label??t.id,description:t.description,share:t.share})),A=I({width:o[0],height:o[1],shape:"lane",padX:Math.max(28,i.plot.x),padY:Math.max(36,i.plot.y+8),stages:k,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),S=new Map(A.stages.map((t,e)=>[t.id,e])),M=new Map(A.stages.map(t=>[t.id,t])),_=A.stages[0].id,P=A.stages[0],L=new Set(e.filter(t=>t.absorb).map(t=>t.id)),$=e.map(t=>{const e=M.get(t.id)??P;return function(t,e){const o={id:"process-stage-"+t.id,label:t.label??t.id,description:t.description,x:e.x,y:e.y,width:Math.max(12,.92*e.width),height:Math.max(40,.88*e.height),semanticItem:!1,attributes:{stageId:t.id}};if(t.absorb)return n({...o,kind:t.kind??"sink",force:Lr(t.force,28),damping:t.damping??.04,charge:"absorbed",attributes:{...o.attributes,primitive:"absorb"}});if(t.portal){const e=t.portal.force??t.force??{x:-40,y:0};return C({...o,kind:t.kind??"force-field",force:Lr(e,-40),damping:t.damping??.1,targetStage:t.portal.targetStageId,attributes:{...o.attributes,primitive:"portal",targetStage:t.portal.targetStageId}})}if(t.capacity){const e=Math.max(.1,t.capacity.unitsPerSecond);return s({...o,kind:t.kind??"force-field",capacity:e,unitsPerSecond:e,force:Lr(t.force,10+.8*e),damping:t.damping??Math.max(.04,.32-.01*e),attributes:{...o.attributes,unitAccessor:t.capacity.unitAccessor,reviewerCapacity:e}})}if(t.pressure){const e="object"==typeof t.pressure&&t.pressure?t.pressure:{};return T({...o,kind:t.kind??"membrane",pressure:e.pressure,occupancy:e.occupancy,baseDamping:e.baseDamping??t.damping??.1,dampingPerUnit:e.dampingPerUnit??.1,energyPerUnit:e.energyPerUnit??0,force:Lr(t.force,8),attributes:{...o.attributes,primitive:"pressureField"}})}return null!=t.force||null!=t.damping?W({...o,kind:t.kind??"force-field",force:Lr(t.force,14),damping:t.damping??.02,attributes:{...o.attributes,primitive:"routeSurface"}}):u({...o,kind:t.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...o.attributes,primitive:"forceField"}})}(t,{x:e.x,y:A.midY,width:e.width,height:A.bottomY-A.topY})});$.unshift(W({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(A.left+A.right)/2,y:A.midY,width:A.right-A.left,height:A.bottomY-A.topY-12,force:8,damping:.012,semanticItem:!1}));const R=new Map;for(const t of A.stages)R.set(t.id,0);const O=[];t.data.forEach((t,e)=>{const o=(d?dr(t,e,d)??t.id??"process-flow-"+e:t.id??"process-flow-"+e)+"",n=(dr(t,e,h)??_)+"",i=S.has(n)?n:_;R.set(i,(R.get(i)??0)+1);const r=p?(dr(t,e,p)??"")+"":void 0,s=r&&f?(dr(t,e,f)??r)+"":r,l=g?hr(dr(t,e,g))??1:1,c=m?hr(dr(t,e,m)):null,u=pr(null!=c&&c>0?c:a,2,18);O.push({datum:t,id:o,stageId:i,groupId:r||void 0,groupLabel:s||void 0,work:l,radius:u,index:e})});const z=new Map,F=new Map;for(const t of O){if(!t.groupId)continue;const e=z.get(t.groupId)??[];e.push(t.id),z.set(t.groupId,e),t.groupLabel&&F.set(t.groupId,t.groupLabel)}const N=pr(t.groupAnchorAlong??.55,.15,.9),E=A.left+(A.right-A.left)*N,D=Array.from(z.keys()),B=D.map((t,o)=>{const n=z.get(t)??[],i=D.length>1?A.topY+28+o/Math.max(1,D.length-1)*(A.bottomY-A.topY-56):A.midY;return r({id:t,label:F.get(t)??t,bodyIds:n,anchor:{x:E,y:i},x:E,y:i,completion:"allAbsorbed"===x?{mode:"allMembersAbsorbed",targetZone:e.find(t=>t.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),j=O.filter(t=>L.has(t.stageId)).map(t=>t.id),Y=y(B,j),X=new Map(B.map(t=>[t.id,t])),G=O.map((t,e)=>{const o=M.get(t.stageId)??P,n=o.x+(c()-.5)*Math.min(24,.2*o.width),i=A.boundaryY(n,"top")+t.radius+10,r=A.boundaryY(n,"bottom")-t.radius-10,s=r>i?i+c()*Math.max(1,r-i):A.midY,a=w?n:A.left+18+e%7*4,l=w?s:A.midY+(c()-.5)*(A.bottomY-A.topY)*.35,u=[{target:{type:"point",x:n,y:s},restLength:.45*t.radius,stiffness:b,damping:v}];if(t.groupId){const e=X.get(t.groupId);e?.anchor&&!L.has(t.stageId)&&u.push({target:{type:"point",x:e.anchor.x,y:e.anchor.y},restLength:e.tether?.restLength??22,stiffness:e.tether?.stiffness??.05,damping:.8})}return{id:t.id,x:a,y:l,vx:w?0:40+40*c(),vy:w?0:20*(c()-.5),mass:1,shape:{type:"circle",radius:t.radius},spawnAt:w?0:.03*e,springs:u,datum:{...t.datum,id:t.id,stage:t.stageId,groupId:t.groupId,groupLabel:t.groupLabel,work:t.work,__processFlow:!0}}}),V={kernel:{seed:l,gravity:{x:t.gravityX??22,y:t.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:A.colliders,fixedDt:1/60,maxSubsteps:8},H=A.stages.map(t=>({label:t.label??t.id,value:R.get(t.id)??0})),q=e.map(t=>{const e=M.get(t.id)??P;return{id:t.id,label:t.label??t.id,x:e.x,width:e.width,count:R.get(t.id)??0,capacity:t.capacity?.unitsPerSecond,absorb:!0===t.absorb,portalTarget:t.portal?.targetStageId}});return{config:V,initialSpawns:G,initialSpawnPacing:w?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:H,metadata:{kind:"process-flow",plot:i.plot,volume:A,stages:q,groups:B,groupCompletion:Y,regionEffects:$}}}({data:Array.isArray(t)?t:[],stages:c,size:l,idAccessor:a.idAccessor,stageAccessor:a.stageAccessor||"stage",groupBy:a.groupBy,groupLabelAccessor:a.groupLabelAccessor,workAccessor:a.workAccessor,radiusAccessor:a.radiusAccessor,ballRadius:a.ballRadius??6,seed:a.seed??1,groupCompletion:a.groupCompletion,groupAnchorAlong:a.groupAnchorAlong,settle:a.settle??!0,gravityX:a.gravityX,gravityY:a.gravityY}),h=d.metadata;return{...i,config:d.config,initialSpawns:Oa(d.initialSpawns),projectionRows:d.projectionRows,regionEffects:h?.regionEffects,backgroundGraphics:Ia(va(d.metadata,za(i,a,"showChrome"),{},a.chromeOptions),i.backgroundGraphics),foregroundGraphics:Ia(wa(d.projectionRows,d.metadata,za(i,a,"showProjection")),i.foregroundGraphics),bodyStyle:cr(e||a.colorBy||a.groupBy,"#4e79a7",{styleRules:a.styleRules,valueAccessor:a.workAccessor||a.stageAccessor||"stage"})}}},GauntletChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Xr({data:Array.isArray(t)?t:[],size:r,gates:i.gates,positiveProperties:i.positiveProperties,negativeProperties:i.negativeProperties,crashOffset:i.crashOffset,idAccessor:i.idAccessor,positiveAccessor:i.positiveAccessor,negativeAccessor:i.negativeAccessor,metricsAccessor:i.metricsAccessor,initialViability:i.initialViability,projectPlacement:i.projectPlacement,coreBody:i.coreBody,viability:i.viability});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:[],backgroundGraphics:Ia(za(n,i,"showChrome")?sr.createElement(Ra,{layout:s.layout,states:s.states,compact:!0===n.__compactMode}):void 0,n.backgroundGraphics),foregroundGraphics:Ia(za(n,i,"showProjection")?sr.createElement(Ca,{layout:s.layout,states:s.states}):void 0,n.foregroundGraphics),bodyStyle:cr(e||i.colorBy)}}},CrucibleChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[900,520],s=Ns({data:Array.isArray(t)?t:[],phases:Array.isArray(i.phases)?i.phases:[],products:Array.isArray(i.products)?i.products:void 0,outlets:Array.isArray(i.outlets)?i.outlets:void 0,events:Array.isArray(i.events)?i.events:void 0,idAccessor:i.idAccessor,labelAccessor:i.labelAccessor,categoryAccessor:i.categoryAccessor,amountAccessor:i.amountAccessor,metricsAccessor:i.metricsAccessor,initialStateAccessor:i.initialStateAccessor,metrics:i.metrics,size:r,seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange}),a="snapshot"===i.playback?function(t,e){if(void 0===e)return t.duration;if("number"==typeof e)return Math.max(0,Math.min(t.duration,bs(e)??0));const o=t.phases.find(t=>t.id===e.phaseId);if(!o)return t.duration;const n=Math.max(0,Math.min(1,bs(e.progress??0)??0));return o.start+o.duration*n}(s,i.snapshotAt):s.duration,l=Fs(s,a).state,c=i.projection&&"object"==typeof i.projection?i.projection:{groupBy:"outlet",measure:"count"},u=function(t,e={}){const o=e.groupBy??"outlet",n=new Map,i=t=>{const e=function(t,e){return"product"===e?"product"===t.kind?t.id:"unassigned":"outlet"===e?t.outletId??"unassigned":"category"===e?t.category:t.status}({...t,status:t.status??"active"},o),i=n.get(e);if(i)return i.count+=1,i.amount+=t.amount,void es(i.metrics,t.metrics);n.set(e,{key:e,label:"product"===o&&"product"===t.kind?t.label:e,count:1,amount:t.amount,metrics:Hr(t.metrics),status:"status"===o?t.status:void 0,outletId:"outlet"===o?t.outletId:void 0,category:"category"===o?t.category:void 0,productId:"product"===o&&"product"===t.kind?t.id:void 0})};for(const e of Object.values(t.components))e.productIds.length||"consumed"===e.status||i({kind:"component",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});for(const e of Object.values(t.products))i({kind:"product",id:e.id,label:e.label,status:e.status,outletId:e.outletId,category:e.category,amount:e.amount,metrics:e.metrics});const r=new Map((e.order??[]).map((t,e)=>[t,e]));return[...n.values()].sort((t,e)=>(r.get(t.key)??Number.MAX_SAFE_INTEGER)-(r.get(e.key)??Number.MAX_SAFE_INTEGER)||Zr(t.key,e.key))}(l,c),d=c.measure??"count",h=function(t,e={}){const o=e.bodies??[],n=Math.max(0,e.recentBodyLimit??6),i=new Map;for(const t of o){const o=e.getContainerId?.(t);if(!o)continue;const n=i.get(o);n?n.push(t):i.set(o,[t])}const r=t.map(t=>{const o=i.get(t.id)??[],r=Math.max(0,Math.floor(t.count??o.length)),s=o.slice(Math.max(0,o.length-n)).map(t=>({id:t.id,label:e.getBodyLabel?.(t)??ua(t),datum:t.datum}));return{id:t.id,label:t.label,count:r,share:0,secondary:t.secondary,secondaryLabel:t.secondaryLabel,observed:t.observed,bodyIds:o.map(t=>t.id),recentBodies:s,metadata:t.metadata}}),s=r.reduce((t,e)=>t+e.count,0);return r.map(t=>({...t,share:s>0?t.count/s:0}))}(u.map(t=>({id:t.key,label:t.label,count:t.count,secondary:"count"===d||"amount"===d?t.amount:Number(t.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?i.amountLabel??"amount":d,metadata:{amount:t.amount,metrics:t.metrics,status:t.status,outletId:t.outletId,category:t.category,productId:t.productId}}))),p={seed:i.seed,bodyRadius:"number"==typeof i.bodyRadius?i.bodyRadius:void 0,radiusRange:i.radiusRange},f=e??i.colorBy??"category",g=!1===i.showChrome?null:sr.createElement(la,{layout:s.layout,phases:s.phases,state:l,compact:520>r[0]||360>r[1]}),y=!1===i.showProjection?null:sr.createElement(ca,{rows:u,layout:s.layout,projection:c,amountLabel:i.amountLabel});return{...n,config:s.config,initialSpawns:Oa(Os(l,s.layout,p)),projectionRows:h,bodyStyle:t=>function(t,e,o,n){const i=t.datum,r={stroke:n.stroke??("product"===i?.kind?"#fffaf0":"#26323a"),strokeWidth:n.strokeWidth??("product"===i?.kind?1.8:1.1),opacity:n.opacity??.96};if(!i?.__crucible)return{...r,fill:n.color??"#b8792d"};if("product"===i.kind){const t=e.products[i.semanticId];return{...r,fill:n.color??t?.color??Na(t?.id??i.semanticId)}}const s=e.components[i.semanticId];if(!s)return{...r,fill:n.color??"#356b63"};let a;return a="status"===o?s.status:"outlet"===o?s.outletId??"in chamber":"product"===o?s.productIds[0]??"unalloyed":"category"===o||null==o?s.category:"function"==typeof o?(o(s.datum)??"unassigned")+"":(s.datum[o+""]??"unassigned")+"",{...r,fill:n.color??Na(a)}}(t,l,f,i),getBodyLabel:t=>function(t,e){const o=t.datum;if(o?.__crucible)return"product"===o.kind?e.products[o.semanticId]?.label:e.components[o.semanticId]?.label}(t,l),renderBodySVG:Qs,backgroundGraphics:Ia(g,n.backgroundGraphics),foregroundGraphics:Ia(y,n.foregroundGraphics)}}},PacketFlowChart:{frameType:"physics",layout:Ta,buildProps:(t,e,o,n,i)=>{const r=n.size??[760,420],s=function(t){const{coordinateMode:e,flowSpeed:o,links:n,maxParticles:i,nodeIdAccessor:r,nodeXAccessor:s,nodeYAccessor:l,nodes:c,particleRadius:u,particleRate:d,pathAccessor:h,pathConstraint:p="path",reducedMotion:f,seed:g,size:y,sourceAccessor:m,targetAccessor:x,throughputAccessor:b}=t,v=ar(y),w=yr(g),k=new Map,A=new Map,S=[];function M(t){if(t&&"object"==typeof t){const e=t;if("function"==typeof r){const t=r(e,0);if(null!=t)return t+""}if("string"==typeof r&&null!=e[r])return e[r]+"";if(null!=e.id)return e.id+""}return(t??"unknown")+""}c.forEach((t,e)=>{const o=(dr(t,e,r)??t.id??e)+"",n=hr(dr(t,e,s)),i=hr(dr(t,e,l));if(null!=n&&null!=i){const t={x:n,y:i};k.set(o,t),S.push(t)}A.set(o,(t.label??t.name??o)+"")});const _=[];n.forEach((t,e)=>{const o=M(dr(t,e,m)),n=M(dr(t,e,x)),i=Math.max(0,hr(dr(t,e,b))??0),r=Ar(h?dr(t,e,h):void 0),s=r.length?r:Ar(t.path??t.points??t.route);s.forEach(t=>S.push(t)),_.push({id:(t.id??`physical-flow-${o}-${n}-${e}`)+"",link:t,index:e,source:o,target:n,throughput:i,rawPath:s})});const P=($=S,"normalized"===(L=e)||"pixels"===L?L:$.length>0&&$.every(t=>!(0>t.x||t.x>1||0>t.y||t.y>1))?"normalized":"pixels");var L,$;const R=new Map;for(const[t,e]of k)R.set(t,Sr(e,v,P));const C=[];for(const t of _){let e=t.rawPath.map(t=>Sr(t,v,P));if(2>e.length){const o=R.get(t.source),n=R.get(t.target);o&&n&&(e=[o,n])}else R.has(t.source)||R.set(t.source,e[0]),R.has(t.target)||R.set(t.target,e[e.length-1]);e.length>=2&&t.throughput>0&&(A.has(t.source)||A.set(t.source,t.source),A.has(t.target)||A.set(t.target,t.target),C.push({...t,path:e,packetCount:0}))}const T=fr(d,.12),O=Math.max(1,Math.round(i)),I=C.map(t=>Math.max(1,Math.round(t.throughput*T))),z=I.reduce((t,e)=>t+e,0),F=z>O?O/z:1;C.forEach((t,e)=>{t.packetCount=Math.max(1,Math.floor(I[e]*F))});let N=C.reduce((t,e)=>t+e.packetCount,0);for(;N>O;){const t=C.reduce((t,e,o)=>e.packetCount>1&&(-1===t||e.packetCount>C[t].packetCount)?o:t,-1);if(-1===t)break;C[t].packetCount-=1,N-=1}const E=new Map,D=new Map,W=[],B=fr(o,90),j=fr(u,4);C.forEach((t,e)=>{E.set(t.target,(E.get(t.target)??0)+t.throughput),D.set(t.source,(D.get(t.source)??0)+t.throughput);const o=Mr(t.path);for(let n=0;t.packetCount>n;n+=1){const i=(n+.5)/t.packetCount,r=f?i:pr(.12+.84*i+.04*(w()-.5),.04,.98),s=f?r:Math.max(0,r-(.18+.12*w())),a=_r(t.path,s),l=_r(t.path,r),c=Pr(t.path,s),u={x:-c.y,y:c.x},d=(w()-.5)*j*1.5;W.push({id:`${t.id}-packet-${n}`,x:a.x+u.x*d,y:a.y+u.y*d,vx:f?0:c.x*B+10*(w()-.5),vy:f?0:c.y*B+10*(w()-.5),mass:.8,spawnAt:f?0:.04*e+n/32,shape:{type:"circle",radius:j},datum:{...t.link,source:t.source,target:t.target,throughput:t.throughput,packetIndex:n,packetCount:t.packetCount,routeProgress:r,flowPath:t.path,flowPathLength:o,flowRouteId:t.id,flowSpeed:B,sourceLabel:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target},springs:"none"!==p&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*j,stiffness:26,damping:4.25}]:void 0})}});const Y=Math.max(18,5*j),X=Array.from(R,([t,e])=>({nodeId:t,label:A.get(t)??t,sensorId:"physical-flow-node-"+gr(t),point:e})),G=X.map(t=>({id:t.sensorId,sensor:!0,shape:{type:"aabb",x:t.point.x,y:t.point.y,width:Y,height:Y}})),V=Object.fromEntries(X.map(t=>[t.sensorId,{binId:t.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),H=ur(g,[...a({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...G],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*j),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=O,H.eviction="oldest",H.observation={...H.observation,sensors:V};const q=Array.from(R,([t,e])=>({id:t,label:A.get(t)??t,x:e.x,y:e.y,sensorId:"physical-flow-node-"+gr(t),incoming:E.get(t)??0,outgoing:D.get(t)??0})),U=C.map(t=>({id:t.id,source:t.source,target:t.target,sourceLabel:A.get(t.source)??t.source,targetLabel:A.get(t.target)??t.target,throughput:t.throughput,packetCount:t.packetCount,path:t.path}));return{config:H,initialSpawns:W,projectionRows:q.filter(t=>t.incoming>0||t.outgoing>0).map(t=>({label:t.label,value:t.incoming,secondary:t.outgoing})),metadata:{kind:"physical-flow",coordinateMode:P,particleCount:W.length,totalThroughput:C.reduce((t,e)=>t+e.throughput,0),plot:v.plot,nodes:q,links:U}}}({nodes:Array.isArray(i.nodes)?i.nodes:[],links:Array.isArray(i.links)?i.links:Array.isArray(i.edges)?i.edges:Array.isArray(t)?t:[],nodeIdAccessor:i.nodeIdAccessor||"id",nodeXAccessor:i.nodeXAccessor||"x",nodeYAccessor:i.nodeYAccessor||"y",sourceAccessor:i.sourceAccessor||"source",targetAccessor:i.targetAccessor||"target",throughputAccessor:i.throughputAccessor||"value",pathAccessor:i.pathAccessor||"path",coordinateMode:i.coordinateMode||"auto",particleRate:i.particleRate??.16,maxParticles:i.maxParticles??180,particleRadius:i.particleRadius??4,flowSpeed:i.flowSpeed??90,pathConstraint:i.pathConstraint||"path",reducedMotion:!0,seed:i.seed??1,size:r});return{...n,config:s.config,initialSpawns:Oa(s.initialSpawns),projectionRows:s.projectionRows,foregroundGraphics:Ia(Ma(s.metadata,{showNodeLabels:!1!==i.showNodeLabels,showSensors:!1!==i.showSensors,showStaticFlow:!1!==i.showStaticFlow}),n.foregroundGraphics),bodyStyle:cr(e||i.colorBy||"source")}}},PhysicsCustomChart:{frameType:"physics",layout:Ta,buildProps:(e,o,n,i,r)=>{const s=i.size??[700,380],a=ye(i.theme),l=function(e){const o=function(t,e,o){const n=t?.observation;return{...t,observation:{...n,chartId:e??n?.chartId??"physics-custom",chartType:n?.chartType??"PhysicsCustomChart",onObservation:o??n?.onObservation}}}(e.config,e.chartId,e.onObservation),n=Rr(e.colorScheme,e.themeCategorical,B),i=ar(e.size),r={data:e.data,scales:{x:$r().domain(e.xExtent??[0,1]).range([i.plot.x,i.plot.x+i.plot.width]),y:$r().domain(e.yExtent??[0,1]).range([i.plot.y+i.plot.height,i.plot.y])},dimensions:i,theme:{semantic:e.semantic,categorical:[...n]},resolveColor:Cr(n,e.colorScheme),config:e.layoutConfig??{},world:new t(o)},s=e.skipLayout?{}:e.layout(r)??{},a=function(t,e){if(!e?.length)return t;const o=new Map;for(const t of e){const{bodyId:e,...n}=t,i=o.get(e)??[];i.push(n),o.set(e,i)}return t.map(t=>{const e=o.get(t.id);return e?.length?{...t,springs:[...t.springs??[],...e]}:t})}([...s.initialSpawns??s.bodies??[]],s.constraints);return{config:Tr(o,s),context:r,initialSpawnPacing:s.initialSpawnPacing,initialSpawns:a,result:s}}({chartId:r.chartId,colorScheme:n,config:r.config,data:Array.isArray(e)?e:[],layout:r.layout,layoutConfig:r.layoutConfig,semantic:Rt(a)??{},size:s,themeCategorical:a.colors.categorical,xExtent:r.xExtent,yExtent:r.yExtent});return{...i,config:l.config,initialSpawns:Oa(l.initialSpawns),projectionRows:[],bodyStyle:l.result.bodyStyle??cr(o||r.colorBy),backgroundGraphics:Ia(i.backgroundGraphics,l.result.backgroundOverlays),foregroundGraphics:Ia(i.foregroundGraphics,l.result.overlays)}}}};function Da(t){const e=t instanceof Date?t.getTime():"number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null}function Wa(t){if(!t||2>t.length)return;const e=Da(t[0]),o=Da(t[t.length-1]);return null!==e&&null!==o?[e,o]:void 0}function Ba(t){const{count:e,byType:o}=function(t){const e={};for(const o of t){const t="string"==typeof o?.type&&o.type.length>0?o.type:"node";e[t]=(e[t]??0)+1}return{count:t.length,byType:e}}(t.marks),n=0===e,i=[...t.extraWarnings??[]];n&&!i.includes("EMPTY_SCENE")&&i.push("EMPTY_SCENE"),t.annotationRender&&t.annotationRender.unrenderedCount>0&&!i.includes("UNRENDERED_ANNOTATIONS")&&i.push("UNRENDERED_ANNOTATIONS");const r=Array.isArray(t.annotations)?t.annotations.length:0,s=t.margin,a=s?{x:s.left,y:s.top,width:t.width-s.left-s.right,height:t.height-s.top-s.bottom}:void 0;return{component:"",frameType:t.frameType,status:n?"empty":"ok",empty:n,markCount:e,markCountByType:o,width:t.width,height:t.height,...t.xDomain?{xDomain:t.xDomain}:{},...t.yDomain?{yDomain:t.yDomain}:{},...t.categories?{categories:t.categories}:{},...void 0!==t.nodeCount?{nodeCount:t.nodeCount}:{},...void 0!==t.edgeCount?{edgeCount:t.edgeCount}:{},...void 0!==t.legendItems?{legendItems:t.legendItems}:{},annotationCount:t.annotationRender?.renderedCount??r,...t.annotationRender?{annotationInputCount:t.annotationRender.inputCount,unrenderedAnnotationCount:t.annotationRender.unrenderedCount,...t.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:t.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:"string"==typeof t.description&&t.description||"string"==typeof t.title&&t.title||`${t.frameType} chart, ${e} marks`,warnings:i,semanticStatus:"not-assessed",semanticDiagnostics:[],...s?{margin:s}:{},...a?{plot:a}:{}}}import*as ja from"react";import*as Ya from"react-dom/server.browser";function Xa(t){return new Set(Array.isArray(t)?t:[t])}function Ga(t,e="ease-out-cubic"){return"linear"===e?t:1-Math.pow(1-t,3)}function Va(t,e){return Math.min((t-e.startTime)/e.duration,1)}function Ha(t,e,o){return t+(e-t)*o}function qa(){return"undefined"!=typeof performance?performance.now():Date.now()}function Ua(t,e,o){if(1>=o)return 1;const n=o-1;return function(t){const e=Math.max(0,Math.min(1,t.minOpacity??.1));if(Number.isNaN(t.age))return 1;if(t.age===1/0)return e;if(!Number.isFinite(t.extent)||0>=t.extent)return 1;const o=Math.max(0,t.age);if("step"===t.type)return(t.threshold??.5*t.extent)>o?1:e;if("exponential"===t.type){const n=t.halfLife??t.extent/2;return e+Math.pow(.5,o/(n>0?n:t.extent/2))*(1-e)}return e+Math.max(0,Math.min(1,1-o/t.extent))*(1-e)}({age:n-e,extent:n,type:t.type,halfLife:t.halfLife??o/2,threshold:t.stepThreshold??.5*o,minOpacity:t.minOpacity??.1})}function Ka(t){const e=new Map;for(let o=0;t.length>o;o++)e.set(t[o],o);return e}function Za(t,e,o){const n=t.duration??500,i=o-e;return n>i?1-i/n:0}function Qa(t,e,o,n){let i=!1;return e>0?(t._pulseIntensity!==e&&(t._pulseIntensity=e,i=!0),t._pulseColor!==o&&(t._pulseColor=o,i=!0),t._pulseGlowRadius!==n&&(t._pulseGlowRadius=n,i=!0),i):(0!==t._pulseIntensity&&(t._pulseIntensity=0,i=!0),void 0!==t._pulseColor&&(t._pulseColor=void 0,i=!0),void 0!==t._pulseGlowRadius&&(t._pulseGlowRadius=void 0,i=!0),i)}function Ja(t,e,o=("undefined"!=typeof performance?performance.now():Date.now())){if(!e||0===e.size)return!1;const n=t.duration??500,i=e.peek();return null!=i&&n>o-i}function tl(t,e,o){if(e._transitionKey)return e._transitionKey;switch(e.type){case"point":if(e.pointId)return"p:"+e.pointId;if("streaming"===t.runtimeMode&&e.datum){const o=t.getX(e.datum),n=t.getY(e.datum);if(t.getCategory)return`p:${t.getCategory(e.datum)}:${o}:${n}`;if(null!=o&&null!=n)return`p:${o}:${n}`}return"p:"+o;case"glyph":return e.pointId?"g:"+e.pointId:"g:"+o;case"rect":return`r:${e.group||""}:${e.datum?.binStart??e.datum?.category??o}`;case"heatcell":return`h:${e.x}_${e.y}`;case"candlestick":return null==e.datum?"c:"+o:"c:"+t.getX(e.datum);case"line":return"l:"+(e.group||"_default");case"area":return"a:"+(e.group||"_default");default:return null}}function el(t){return t?null!=t.opacity?t.opacity:null!=t.fillOpacity?t.fillOpacity:1:1}function ol(t,e,o,n,i,r){const s=[];for(const i of t){const t=o(i),r=n(i);Number.isFinite(t)&&Number.isFinite(r)&&s.push({px:e.x(t),py:e.y(r),rawY:r,d:i})}s.sort((t,e)=>t.px-e.px);const a=Array(s.length),l=Array(s.length),c=Array(s.length);for(let t=0;s.length>t;t++){const e=s[t];a[t]=[e.px,e.py],l[t]=e.rawY,c[t]=e.d}return{type:"line",path:a,rawValues:l,style:i,datum:c,group:r}}function nl(t,e,o,n,i,r,s,a){const l=[];for(const r of t){const t=o(r),s=n(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;const c=e.x(t),u=a?a(r):i;l.push({px:c,topY:e.y(s),botY:e.y(u),rawY:s})}l.sort((t,e)=>t.px-e.px);const c=Array(l.length),u=Array(l.length),d=Array(l.length);for(let t=0;l.length>t;t++){const e=l[t];c[t]=[e.px,e.topY],u[t]=[e.px,e.botY],d[t]=e.rawY}return{type:"area",topPath:c,bottomPath:u,rawValues:d,style:r,datum:t,group:s}}function il(t,e,o,n){const i=new Map;if("silhouette"===n)for(const n of t){let t=0;for(const i of e)t+=o(i,n)||0;i.set(n,-t/2)}else if("wiggle"===n){t.length>0&&i.set(t[0],0);for(let n=1;t.length>n;n++){const r=t[n-1],s=t[n];let a=0,l=0,c=0;for(const t of e){const e=o(t,s)||0;a+=(2*c+e)*(e-(o(t,r)||0)),l+=e,c+=e}const u=i.get(r)??0;i.set(s,u-(l>0?a/(2*l):0))}if(t.length>0){let n=0;for(const r of t){let t=0;for(const n of e)t+=o(n,r)||0;n+=(i.get(r)??0)+t/2}const r=n/t.length;for(const e of t)i.set(e,(i.get(e)??0)-r)}}else for(const e of t)i.set(e,0);return i}function rl(t,e,o,n,i,r,s){const a=o(t),l=n(t);if(!Number.isFinite(a)||!Number.isFinite(l))return null;const c={type:"point",x:e.x(a),y:e.y(l),r:i,style:r,datum:t};return void 0!==s&&(c.pointId=s),c}function sl(t,e,o,n,i,r,s,a){const l=o(t),c=n(t);if(!Number.isFinite(l)||!Number.isFinite(c))return null;const u={type:"symbol",x:e.x(l),y:e.y(c),size:i,symbolType:r,style:s,datum:t};return void 0!==a&&(u.pointId=a),u}function al(t,e,o,n,i,r,s){return{type:"rect",x:t,y:e,w:o,h:n,style:i,datum:r,group:s}}function ll(t,e,o,n,i,r,s){const a={type:"heatcell",x:t,y:e,w:o,h:n,fill:i,datum:r};return void 0!==s?.value&&(a.value=s.value),s?.showValues&&(a.showValues=!0,s.valueFormat&&(a.valueFormat=s.valueFormat)),a}function cl(t,e,o,n){return"function"==typeof e.style?e.style(n||{},o):e.style&&"object"==typeof e.style?e.style:t.resolveBoundsStyle(o,n)}function ul(t,e,o,n){if(!t.scales)return null;const i=[],r=[];for(const o of e){const e=t.getX(o);if(!Number.isFinite(e))continue;const s=n.getTop(o),a=n.getBottom(o);if(!Number.isFinite(s)||!Number.isFinite(a))continue;const l=t.scales.x(e),c=t.scales.y(s),u=t.scales.y(a);Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(u)&&(i.push([l,c]),r.push([l,u]))}return 2>i.length?null:{type:"area",topPath:i,bottomPath:r,...t.config.curve&&"linear"!==t.config.curve&&{curve:t.config.curve},style:cl(t,n,o,e[0]),datum:e,group:o,interactive:n.interactive}}function dl(t){const e=[],o=[];if(!t)return{perSeries:e,aggregate:o};for(const n of t)n.perSeries?e.push(n):o.push(n);return{perSeries:e,aggregate:o}}function hl(t,e,o){const n=[];for(const i of o){const o=ul(t,e,"__ribbon_aggregate",i);o&&n.push(o)}return n}function pl(t,e,o,n){const i=[];for(const r of n){const n=ul(t,e,o,r);n&&i.push(n)}return i}function fl(t,e,o,n){if(!t.config.pointStyle)return;const i=n??t.getY;for(const n of e){const e=t.resolveGroupColor(n.key);for(const r of n.data){let n=t.config.pointStyle(r);!n.fill&&e&&(n={...n,fill:e});const s=n.r??3,a=t.getPointId?t.getPointId(r)+"":void 0,l=rl(r,t.scales,t.getX,i,s,n,a);l&&o.push(l)}}}function gl(t){return"threshold"===t.type&&"string"==typeof t.color&&"number"==typeof t.value}function yl(t){return ce(t)}var ml=new Map;function xl(t){const o=Object.prototype.hasOwnProperty.call(e,t)?t:"blues";let n=ml.get(o);if(n)return n;n=Array(256);const i=h(o);for(let t=0;256>t;t++)n[t]=i(t/255);return ml.set(o,n),n}function bl(t,e,o){const n=o.config.areaStyle?.(e);return n&&("string"==typeof n.fill&&(t.fill=n.fill),t.style=n),t}function vl(t,e,o,n,i){const r=new Map;for(const s of t){const t=e(s),a=o(s);if(null==t||null==a||Number.isNaN(t)||Number.isNaN(a))continue;const l=Math.floor(t/n)*n;let c=r.get(l);if(c||(c={start:l,end:l+n,total:0,categories:new Map},r.set(l,c)),c.total+=a,i){const t=i(s);c.categories.set(t,(c.categories.get(t)||0)+a)}}return r}function wl(t){if("production"===process.env.NODE_ENV)return;const{label:e,nodes:o,overlays:n,warned:i}=t;kl(n)&&0===o.length&&Al(i,"overlay-only",`[semiotic] ${e} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),o.length>0&&o.every(t=>null==t.datum)&&Al(i,"null-datums",`[semiotic] ${e} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function kl(t){return null!=t&&!1!==t&&""!==t&&(!Array.isArray(t)||t.some(kl))}function Al(t,e,o){t.has(e)||(t.add(e),console.warn(o))}function Sl(t,e,o,n){const i=function(t){if(t instanceof Error)return{name:t.name||"Error",message:t.message||"Custom layout threw."};if("string"==typeof t)return{name:"Error",message:t};if(null==t)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:t+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(e),r="network"===t?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:t,source:r,message:`Semiotic ${t} ${r} failed: ${i.message}`,error:i,recovery:o?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:o,affectedRevision:n}}function Ml(t,e){const o="function"==typeof t?t:o=>o[t||e];return t=>{const e=o(t);return null==e?NaN:+e}}function _l(t){const e=[],o=["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode,n=Ml(o&&t.valueAccessor||t.yAccessor,o?"value":"y");if(t.boundsAccessor){const o=mt(t.boundsAccessor,"bounds");e.push({kind:"bounds",getTop:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e+i:e},getBottom:t=>{const e=n(t);if(!Number.isFinite(e))return NaN;const i=o(t);return Number.isFinite(i)&&0!==i?e-i:e},style:t.boundsStyle,perSeries:!0,interactive:!1})}if(t.band){const o=Array.isArray(t.band)?t.band:[t.band];for(const t of o)e.push({kind:"band",getTop:Ml(t.y1Accessor,"y1"),getBottom:Ml(t.y0Accessor,"y0"),style:t.style,perSeries:!1!==t.perSeries,interactive:!0===t.interactive})}return e}import{scaleLinear as Pl,scaleLog as Ll,scaleSymlog as $l,scaleTime as Rl}from"d3-scale";function Cl(t,e){return e?[e[0]??t[0],e[1]??t[1]]:t}function Tl(t,e,o){if("log"===t){const t=[Math.max(e[0],1e-6),Math.max(e[1],1e-6)];return Ll().domain(t).range(o).clamp(!0)}return"symlog"===t?$l().domain(e).range(o):"time"===t?Rl().domain([new Date(e[0]),new Date(e[1])]).range(o):Pl().domain(e).range(o)}function Ol(t,e,o){e>t.capacity&&(t.resize(e),o&&e>o.capacity&&o.resize(e))}function Il(t,e){const o=new U(t.capacity);return t.forEach(()=>o.push(e)),o}function zl(t,e,o,n){const i=t.push(e);return o&&o.push(n),i}function Fl(t,e,o){if(!e||0===e.size)return;const n=new Set;if(t.forEach((t,e)=>{o(t)&&n.add(e)}),0===n.size)return;const i=e.toArray();e.clear();for(let t=0;i.length>t;t++)n.has(t)||e.push(i[t])}var Nl=new WeakMap;function El(){return this.updateResults.last}function Dl(){return this.updateResults.last}function Wl(t){return this.updateResults.subscribe(t)}function Bl(t){this.config.layoutSelection=t}function jl(){Nl.set(this,!0)}function Yl(){const t=!0===Nl.get(this);return Nl.delete(this),t}function Xl(t){Object.assign(t.prototype,{getLastUpdateResult:El,getUpdateSnapshot:Dl,subscribeUpdateResult:Wl,setLayoutSelection:Bl,markStylePaintPending:jl,consumeStylePaintPending:Yl})}var Gl=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Vl=["scene-style","data-paint","accessibility","evidence"],Hl=(t,e)=>({retainedData:t,invalidations:e}),ql=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ul=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Kl=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zl=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ql=["scene-geometry","data-paint","accessibility","evidence"],Jl=["scene-style","data-paint","accessibility","evidence"],tc=[],ec={chartType:Hl("rebuild",ql),runtimeMode:Hl("rebuild",ql),xAccessor:Hl("rebuild",ql),yAccessor:Hl("rebuild",ql),timeAccessor:Hl("rebuild",ql),valueAccessor:Hl("rebuild",ql),y0Accessor:Hl("rebuild",ql),boundsAccessor:Hl("rebuild",ql),band:Hl("rebuild",ql),openAccessor:Hl("rebuild",ql),highAccessor:Hl("rebuild",ql),lowAccessor:Hl("rebuild",ql),closeAccessor:Hl("rebuild",ql),candlestickRangeMode:Hl("rebuild",ql),accessorRevision:Hl("rebuild",ql),groupAccessor:Hl("rebuild",Ul),categoryAccessor:Hl("rebuild",Ul),lineDataAccessor:Hl("rebuild",Ul),colorAccessor:Hl("rebuild",Jl),sizeAccessor:Hl("rebuild",Ql),symbolAccessor:Hl("rebuild",Ql),pointIdAccessor:Hl("rebuild",Ql),xScaleType:Hl("preserve",Kl),yScaleType:Hl("preserve",Kl),xExtent:Hl("preserve",Kl),yExtent:Hl("preserve",Kl),extentPadding:Hl("preserve",Kl),scalePadding:Hl("preserve",Kl),axisExtent:Hl("preserve",Kl),yAxisExtent:Hl("preserve",Kl),binSize:Hl("preserve",Kl),normalize:Hl("preserve",Kl),heatmapAggregation:Hl("preserve",Kl),heatmapXBins:Hl("preserve",Kl),heatmapYBins:Hl("preserve",Kl),arrowOfTime:Hl("preserve",Zl),baseline:Hl("preserve",Zl),stackOrder:Hl("preserve",Zl),sizeRange:Hl("preserve",Zl),curve:Hl("preserve",Zl),areaGroups:Hl("preserve",Zl),customLayout:Hl("preserve",Zl),layoutConfig:Hl("preserve",Zl),layoutMargin:Hl("preserve",Zl),symbolMap:Hl("preserve",Ql),showValues:Hl("preserve",Ql),heatmapValueFormat:Hl("preserve",Ql),lineStyle:Hl("preserve",Jl),pointStyle:Hl("preserve",Jl),areaStyle:Hl("preserve",Jl),barStyle:Hl("preserve",Jl),swarmStyle:Hl("preserve",Jl),waterfallStyle:Hl("preserve",Jl),candlestickStyle:Hl("preserve",Jl),boundsStyle:Hl("preserve",Jl),gradientFill:Hl("preserve",Jl),lineGradient:Hl("preserve",Jl),semanticLineStops:Hl("preserve",Jl),colorScheme:Hl("preserve",Jl),themeCategorical:Hl("preserve",Jl),themeSemantic:Hl("preserve",Jl),themeSequential:Hl("preserve",Jl),themeDiverging:Hl("preserve",Jl),barColors:Hl("preserve",Jl),decay:Hl("preserve",Jl),pulse:Hl("preserve",Jl),staleness:Hl("preserve",Jl),layoutSelection:Hl("preserve",Jl),annotations:Hl("preserve",["overlay","accessibility","evidence"]),windowSize:Hl("preserve",tc),windowMode:Hl("preserve",tc),maxCapacity:Hl("preserve",tc),clock:Hl("preserve",tc),transition:Hl("preserve",tc),introAnimation:Hl("preserve",tc),onLayoutError:Hl("preserve",tc)},oc=Hl("preserve",Zl),nc=class{constructor(){this.tracker=new o}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Gl)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},Vl):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=ec[n]??oc;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as ic}from"d3-quadtree";var rc=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(t,e){if("scatter"!==t&&"bubble"!==t&&"custom"!==t)return void this.clear();let o=0,n=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(o++,t.r>n&&(n=t.r));if(this.maxRadius=n,500>=o)return void(this.tree=null);const i=Array(o);let r=0;for(const t of e)"point"===t.type&&!1!==t.interactive&&(i[r++]=t);this.tree=ic().x(t=>t.x).y(t=>t.y).addAll(i)}},sc=class t{constructor(t){if(this.xExtent=new q,this.yExtent=new q,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=new Map,this.prevPathMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new nc,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.xIsDate=!1,this.spatialIndex=new rc,this._lastBoundedInsertsRef=null,this.applyPulse=(t,e,o)=>!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r=("undefined"!=typeof performance?performance.now():Date.now())){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let l=!1;const c=i??(()=>{const t=new Map;for(let e=0;o.length>e;e++)t.set(o[e],e);return t})();for(const o of e){if("line"===o.type)continue;if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[o.datum];let i=0,a=!1;for(const o of e){const e=c.get(o);if(null==e)continue;a=!0;const s=n.get(e);if(null==s)continue;const l=Za(t,s,r);l>i&&(i=l)}a&&(l=Qa(o,i,s)||l);continue}const e=c.get(o.datum);if(null==e)continue;const i=n.get(e);l=Qa(o,null==i?0:Za(t,i,r),s,a)||l}return l}(this.config.pulse,t,e,this.timestampBuffer,this.getDatumIndexMap(e),o),this.config=t,this.buffer=new U(t.windowSize),this.growingCap=t.windowSize,["bar","swarm","waterfall"].includes(t.chartType)||"streaming"===t.runtimeMode?(this.getX=mt(t.timeAccessor||t.xAccessor,"time"),this.getY=mt(t.valueAccessor||t.yAccessor,"value")):(this.getX=mt(t.xAccessor,"x"),this.getY=mt(t.yAccessor,"y")),this.getGroup=wt(t.groupAccessor),this.getCategory=wt(t.categoryAccessor),this.getSize=t.sizeAccessor?mt(t.sizeAccessor,"size"):void 0,this.getColor=wt(t.colorAccessor),this.getSymbol=wt(t.symbolAccessor),this.getY0=t.y0Accessor?mt(t.y0Accessor,"y0"):void 0,this.resolvedRibbons=_l(t),this.getPointId=wt(t.pointIdAccessor),"candlestick"===t.chartType){const e=null!=t.openAccessor,o=null!=t.closeAccessor;this.getOpen=e?mt(t.openAccessor,"open"):void 0,this.getHigh=mt(t.highAccessor,"high"),this.getLow=mt(t.lowAccessor,"low"),this.getClose=o?mt(t.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!o}t.pulse&&(this.timestampBuffer=new U(t.windowSize))}currentTime(){return this.config.clock?.()??qa()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Il(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(t)),void this.yExtent.push(this.getLow(t));this.yExtent.push(this.getY(t)),this.getY0&&this.yExtent.push(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.push(o),Number.isFinite(n)&&this.yExtent.push(n)}}evictDatumYExtent(t){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(t)),void this.yExtent.evict(this.getLow(t));this.yExtent.evict(this.getY(t)),this.getY0&&this.yExtent.evict(this.getY0(t));for(const e of this.resolvedRibbons){const o=e.getTop(t),n=e.getBottom(t);Number.isFinite(o)&&this.yExtent.evict(o),Number.isFinite(n)&&this.yExtent.evict(n)}}rebuildYExtent(){this.yExtent.clear();for(const t of this.buffer)this.pushDatumYExtent(t)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(const t of this.buffer)this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t)}ingest(t){if(t.bounded&&this._lastBoundedInsertsRef===t.inserts)return this.updateResults.recordNoop("replace"),!1;const e=this.currentTime();if(this.lastIngestTime=e,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,t.bounded){this._lastBoundedInsertsRef=t.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();const o=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=o?mt(this.config.timeAccessor||this.config.xAccessor,"time"):mt(this.config.xAccessor,"x"),this.xIsDate=!1,t.inserts.length>0){const e=t.inserts[0],o=this.config.xAccessor,n="function"==typeof o?o(e):e[o||"x"],i=n instanceof Date,r="string"==typeof n&&Number.isFinite(lt(n));if(this.xIsDate=i||r,r){const t="string"==typeof o?o:void 0;this.getX=t?e=>Z(e[t]):t=>Z(o(t))}}Ol(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)zl(this.buffer,o,this.timestampBuffer,e),this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o)}else for(const o of t.inserts){if("growing"===this.config.windowMode&&this.buffer.full){const t=this.config.maxCapacity??1e5;t>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,t),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"===process.env.NODE_ENV||this.growingCapacityWarned||5e4>this.growingCap||(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${t}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}const t=zl(this.buffer,o,this.timestampBuffer,e);this.xExtent.push(this.getX(o)),this.pushDatumYExtent(o),null!=t&&(this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t))}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.lastLayout;if(!this.needsFullRebuild&&!e.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==t.width||this.lastLayout.height!==t.height))return void this.remapScene(t);this.xExtent.dirty&&this.xExtent.recalculate(o,this.getX),this.yExtent.dirty&&this.rebuildYExtent();const r=this.getBufferArray(),s=this.yExtent.extent;let a=Cl(this.xExtent.extent,e.xExtent),l=Cl(s,e.yExtent);const c=!(!(u=e.yExtent)||null==u[0]||null==u[1]);var u;const d="exact"===(e.yAxisExtent??e.axisExtent);if("stackedarea"===e.chartType&&!c&&o.size>0){const t=function(t){const{config:e,groups:o,getX:n,getY:i}=t,r="exact"===(e.yAxisExtent??e.axisExtent);if(e.normalize){const o=[0,r?1:1+e.extentPadding];return{yDomain:o,stackExtentCache:{key:`${t.bufferSize}:${t.ingestVersion}:norm`,yDomain:o}}}const s=`${t.bufferSize}:${t.ingestVersion}:${e.baseline??"zero"}:${e.stackOrder??"key"}`;if(t.stackExtentCache&&t.stackExtentCache.key===s)return{yDomain:t.stackExtentCache.yDomain,stackExtentCache:t.stackExtentCache};const a=new Map,l=new Set;let c=0;const u=new Map,d=new Map;for(const t of o){const e=new Map;let o=0;for(const r of t.data){const t=n(r),s=i(r);if(!Number.isFinite(t)||!Number.isFinite(s))continue;e.set(t,(e.get(t)||0)+s),l.add(t),o+=s;const a=(u.get(t)||0)+s;u.set(t,a),a>c&&(c=a)}a.set(t.key,e),d.set(t.key,o)}const h=e.stackOrder??"key",p=(t,e)=>e>t?-1:t>e?1:0;let f,g;if("input"===h)f=o.map(t=>t.key);else if("insideOut"===h){const t=[...o].map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:p(t,e)}),e=[],n=[];let i=0,r=0;for(const o of t)r>i?(e.push(o),i+=d.get(o)??0):(n.push(o),r+=d.get(o)??0);f=[...n.reverse(),...e]}else f="asc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(t)??0)-(d.get(e)??0);return 0!==o?o:p(t,e)}):"desc"===h?o.map(t=>t.key).sort((t,e)=>{const o=(d.get(e)??0)-(d.get(t)??0);return 0!==o?o:p(t,e)}):o.map(t=>t.key).sort(p);if("wiggle"===e.baseline||"silhouette"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),o=il(t,f,(t,e)=>a.get(t)?.get(e)||0,e.baseline);let n=1/0,i=-1/0;for(const e of t){const t=o.get(e)??0,r=u.get(e)??0;n>t&&(n=t),t+r>i&&(i=t+r)}Number.isFinite(n)&&Number.isFinite(i)||(n=0,i=0);const s=i-n,c=r?0:s>0?s*e.extentPadding:1;g=[n-c,i+c]}else if("diverging"===e.baseline){const t=Array.from(l).sort((t,e)=>t-e),[o,n]=function(t,e,o){let n=0,i=0;for(const r of t){let t=0,s=0;for(const n of e){const e=o(n,r)||0;0>e?s+=e:t+=e}n>s&&(n=s),t>i&&(i=t)}return[n,i]}(t,f,(t,e)=>a.get(t)?.get(e)||0),i=n-o,s=r?0:i>0?i*e.extentPadding:1;g=[o-s,n+s]}else g=[0,c+(r?0:c>0?c*e.extentPadding:1)];return{yDomain:g,stackExtentCache:{key:s,yDomain:g}}}({config:e,groups:this.groupData(r),getX:this.getX,getY:this.getY,bufferSize:o.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});l=t.yDomain,this._stackExtentCache=t.stackExtentCache}else"bar"===e.chartType&&e.binSize&&!c&&o.size>0?l=function(t,e,o,n,i,r,s){const[,a]=function(t,e,o,n,i){const r=vl(t,e,o,n,i);if(0===r.size)return[0,0];let s=0;for(const t of r.values())t.total>s&&(s=t.total);return[0,s]}(t,e,o,n,i);return[0,s?a:a+a*r]}(o,this.getX,this.getY,e.binSize,this.getCategory,e.extentPadding,d):"waterfall"===e.chartType&&!c&&o.size>0?l=function(t,e,o,n){const[i,r]=function(t,e){let o=0,n=0,i=0;for(const r of t){const t=e(r);null==t||Number.isNaN(t)||(i+=t,o>i&&(o=i),i>n&&(n=i))}return[o,n]}(t,e),s=r-i,a=n?0:s>0?s*o:1;return[Math.min(0,i-Math.abs(a)),Math.max(0,r+Math.abs(a))]}(o,this.getY,e.extentPadding,d):c||l[0]===1/0||(l=function(t,e,o){if(!o.length)return t;let[n,i]=t;for(const t of e)for(const e of o){const o=e.getTop(t),r=e.getBottom(t);Number.isFinite(o)&&(n>o&&(n=o),o>i&&(i=o)),Number.isFinite(r)&&(n>r&&(n=r),r>i&&(i=r))}return[n,i]}(l,r,this.resolvedRibbons),l=function(t,e){const o=t[1]-t[0],n=e.exactMode?0:o>0?o*e.extentPadding:1,i=[null!=e.userMin?t[0]:t[0]-n,null!=e.userMax?t[1]:t[1]+n];return"log"!==e.yScaleType||i[0]>0||0>=e.dataYDomain[0]||e.exactMode||null==e.userMin&&(i[0]=e.dataYDomain[0]/(1+e.extentPadding)),i}(l,{exactMode:d,extentPadding:e.extentPadding,userMin:e.yExtent?.[0],userMax:e.yExtent?.[1],yScaleType:e.yScaleType,dataYDomain:s}));l=function(t,e,o){if(!e||o)return t;const n=e[0],i=e[1];return null==n&&null==i?t:[null!=n?n:t[0],null!=i?i:t[1]]}(l,e.yExtent,!!c),({xDomain:a,yDomain:l}=function(t,e,o){let n=t,i=e;if(n[0]===1/0||n[1]===-1/0)if("time"===o){const t=Date.now();n=[t-864e5,t]}else n=[0,1];return i[0]!==1/0&&i[1]!==-1/0||(i=[0,1]),{xDomain:n,yDomain:i}}(a,l,e.xScaleType)),this.scales=function(t){const{config:e,layout:o,xDomain:n,yDomain:i}=t,r="streaming"===e.runtimeMode,s=Math.max(0,Math.min(e.scalePadding||0,Math.min(o.width,o.height)/2-1));if(r){const t="left"===e.arrowOfTime?[o.width-s,s]:[s,o.width-s];return{x:Pl().domain(n).range(t),y:Tl(e.yScaleType,i,[o.height-s,s])}}return{x:Tl(e.xScaleType,n,[s,o.width-s]),y:Tl(e.yScaleType,i,[o.height-s,s])}}({config:e,layout:t,xDomain:a,yDomain:l}),this._customLayoutFailedThisBuild=!1;const h=this.buildSceneNodes(t,r);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.lastLayout=i):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=h,this.config.decay&&this.applyDecay(this.scene,r),this.config.pulse&&this.applyPulse(this.scene,r,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:t.width,height:t.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(t){const e=t.width/this.lastLayout.width,o=t.height/this.lastLayout.height;for(const t of this.scene)switch(t.type){case"line":for(const n of t.path)n[0]*=e,n[1]*=o;break;case"area":for(const n of t.topPath)n[0]*=e,n[1]*=o;for(const n of t.bottomPath)n[0]*=e,n[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*e,y:t.clipRect.y*o,width:t.clipRect.width*e,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(t=>({...t,y:t.y*o,height:t.height*o})));break;case"point":case"glyph":t.x*=e,t.y*=o;break;case"rect":case"heatcell":t.x*=e,t.y*=o,t.w*=e,t.h*=o;break;case"candlestick":t.x*=e,t.openY*=o,t.closeY*=o,t.highY*=o,t.lowY*=o}const n=this.scales.x.domain(),i=this.scales.y.domain(),r=this.scales.x.range(),s=this.scales.y.range(),a=Tl,l=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(t.width,t.height)/2-1)),c=s[1]>s[0];this.scales={x:a(this.config.xScaleType,n,r[0]>r[1]?[t.width-l,l]:[l,t.width-l]),y:a(this.config.yScaleType,i,c?[l,t.height-l]:[t.height-l,l])},this.lastLayout={width:t.width,height:t.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(t,e){const{config:o,scales:n}=this;if(!n)return[];if(o.customLayout){const i={data:e,scales:n,dimensions:{width:t.width,height:t.height,margin:o.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:o.themeSemantic??{},categorical:o.themeCategorical??Jt},resolveColor:(t,e)=>{const n=this.resolveGroupColor(t);if(n)return n;const i=this.resolveLineStyle(t,e);return i.stroke?i.stroke:"string"==typeof i.fill?i.fill:o.themeSemantic?.primary??"#4e79a7"},config:o.layoutConfig??{},selection:o.layoutSelection??null};let r;try{r=o.customLayout(i)}catch(t){const e=null!==this.lastCustomLayoutResult,n=Sl("xy",t,e,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] customLayout threw:",t);try{o.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null;const s=r.nodes??[];if(this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of s)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(s,o.layoutSelection??null)}return wl({label:"customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===e.length)return[];const i={scales:n,config:o,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(t,e)=>this.resolveLineStyle(t,e),resolveAreaStyle:(t,e)=>this.resolveAreaStyle(t,e),resolveBoundsStyle:(t,e)=>this.resolveBoundsStyle(t,e),resolveColorMap:t=>this.resolveColorMap(t),resolveGroupColor:t=>this.resolveGroupColor(t),groupData:t=>this.groupData(t),barCategoryCache:this._barCategoryCache};switch(o.chartType){case"line":return function(t,e){const o=t.groupData(e),n=[],i=t.config.annotations?.filter(gl).map(t=>({value:t.value,color:t.color,thresholdType:t.thresholdType||"greater"}));if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}for(const e of o){const o=t.resolveLineStyle(e.key,e.data[0]),r=ol(e.data,t.scales,t.getX,t.getY,o,e.key);i&&i.length>0&&(r.colorThresholds=i),t.config.curve&&"linear"!==t.config.curve&&(r.curve=t.config.curve),t.config.lineGradient&&(r.strokeGradient=t.config.lineGradient),n.push(r)}return fl(t,o,n),n}(i,e);case"area":return function(t,e){const o=t.groupData(e),n=[];if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}const i=t.scales.y.domain(),r=i[0],s=t.config.semanticLineStops?.filter(t=>Number.isFinite(t.offset)).map(t=>({value:i[0]+Math.max(0,Math.min(1,t.offset))*(i[1]-i[0]),color:t.color,opacity:t.opacity,thresholdType:"greater"})).sort((t,e)=>t.value-e.value),a=s&&s.length>0?(()=>{const e=s.reduce((t,e)=>(t.at(-1)?.value===e.value?t[t.length-1]=e:t.push(e),t),[]),o=[{from:i[0],to:e[0].value,color:e[0].color,opacity:e[0].opacity}];for(let t=0;e.length>t;t++)o.push({from:e[t].value,to:e[t+1]?.value??i[1],color:e[t].color,opacity:e[t].opacity});return o.map(({from:e,to:o,color:n,opacity:i})=>{const r=t.scales.y(e),s=t.scales.y(o);return{y:Math.min(r,s),height:Math.abs(s-r),color:n,...null!=i&&{opacity:i}}}).filter(t=>t.height>0)})():void 0,l=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o){const o=t.resolveAreaStyle(e.key,e.data[0]),i=nl(e.data,t.scales,t.getX,t.getY,r,o,e.key,l),c=yl(t.config.gradientFill);c&&(i.fillGradient=c),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),s&&s.length>0&&(i.colorThresholds=s,i.strokeColorBands=a),n.push(i)}return fl(t,o,n),n}(i,e);case"mixed":return function(t,e){const o=t.groupData(e),n=[],i=t.config.areaGroups||new Set;if(t.ribbons&&t.ribbons.length>0){const{perSeries:i,aggregate:r}=dl(t.ribbons);if(r.length>0&&n.push(...hl(t,e,r)),i.length>0)for(const e of o)n.push(...pl(t,e.data,e.key,i))}const r=t.scales.y.domain()[0],s=t.getY0?e=>{const o=t.getY0(e);return null==o?r:o}:void 0;for(const e of o)if(i.has(e.key)){const o=t.resolveAreaStyle(e.key,e.data[0]),i=nl(e.data,t.scales,t.getX,t.getY,r,o,e.key,s),a=yl(t.config.gradientFill);a&&(i.fillGradient=a),t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}else{const o=t.resolveLineStyle(e.key,e.data[0]),i=ol(e.data,t.scales,t.getX,t.getY,o,e.key);t.config.curve&&"linear"!==t.config.curve&&(i.curve=t.config.curve),t.config.lineGradient&&(i.strokeGradient=t.config.lineGradient),n.push(i)}return fl(t,o,n),n}(i,e);case"stackedarea":return function(t,e){const o=t.groupData(e),n=t.config.stackOrder??"key",i=()=>o.sort((t,e)=>e.key>t.key?-1:t.key>e.key?1:0);if("input"===n);else if("key"===n)i();else if("asc"===n||"desc"===n||"insideOut"===n){const e=new Map;for(const n of o){let o=0;for(const e of n.data){const n=t.getX(e),i=t.getY(e);Number.isFinite(n)&&Number.isFinite(i)&&(o+=i)}e.set(n.key,o)}const i=(t,e)=>e>t?-1:t>e?1:0;if("asc"===n)o.sort((t,o)=>{const n=(e.get(t.key)??0)-(e.get(o.key)??0);return 0!==n?n:i(t.key,o.key)});else if("desc"===n)o.sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)});else{const t=[...o].sort((t,o)=>{const n=(e.get(o.key)??0)-(e.get(t.key)??0);return 0!==n?n:i(t.key,o.key)}),n=[],r=[];let s=0,a=0;for(const o of t)a>s?(n.push(o),s+=e.get(o.key)??0):(r.push(o),a+=e.get(o.key)??0);o.length=0,o.push(...r.reverse(),...n)}}else i();const r=t.config.curve&&"linear"!==t.config.curve?t.config.curve:void 0,s=t.config.normalize?"zero":t.config.baseline??"zero",{nodes:a,stackedTops:l}=function(t,e,o,n,i,r,s,a="zero"){const l=new Set;for(const e of t)for(const t of e.data){const e=o(t);Number.isFinite(e)&&l.add(e)}const c=Array.from(l).sort((t,e)=>t-e),u=new Map;for(const e of t){const t=new Map;for(const i of e.data){const e=o(i),r=n(i);Number.isFinite(e)&&Number.isFinite(r)&&t.set(e,(t.get(e)||0)+r)}u.set(e.key,t)}let d;if(r){d=new Map;for(const e of c){let o=0;for(const n of t)o+=u.get(n.key)?.get(e)||0;d.set(e,o||1)}}const h=il(c,t.map(t=>t.key),(t,e)=>u.get(t)?.get(e)||0,a),p="diverging"===a&&!r,f=[],g=new Map,y=new Map,m=new Map,x=new Map;for(const t of c)y.set(t,h.get(t)??0),m.set(t,0),x.set(t,0);for(const o of t){const t=u.get(o.key),n=new Map;let a=[],l=[];const h=()=>{if(a.length>=2){const t={type:"area",topPath:a,bottomPath:l,style:i(o.key,o.data[0]),datum:o.data,group:o.key};s&&(t.curve=s),f.push(t)}a=[],l=[]};for(const o of c){const i=t.has(o);let s,c,u=i?t.get(o):0;if(r&&i&&(u/=d.get(o)),!i||!Number.isFinite(u)||0===u){h();continue}p?u>0?(s=m.get(o),c=s+u,m.set(o,c)):(s=x.get(o),c=s+u,x.set(o,c)):(s=y.get(o),c=s+u,y.set(o,c));const f=e.x(o);l.push([f,e.y(s)]),a.push([f,e.y(c)]),n.set(o,c)}h(),g.set(o.key,n)}return{nodes:f,stackedTops:g}}(o,t.scales,t.getX,t.getY,(e,o)=>t.resolveAreaStyle(e,o),t.config.normalize,r,s),c=a;if(t.config.pointStyle){const e=new WeakMap;for(const n of o){const o=l.get(n.key);if(o)for(const i of n.data){const n=t.getX(i),r=t.getY(i);null==n||Number.isNaN(n)||null==r||Number.isNaN(r)||!o.has(n)||e.set(i,o.get(n))}}const n=o=>e.get(o)??t.getY(o);fl(t,o,c,n)}return c}(i,e);case"scatter":case"bubble":return function(t,e){const o=[],n="bubble"===t.config.chartType?10:5,i=t.config.sizeRange||[3,15];let r=null;if(t.getSize&&!t.config.pointStyle){const o=e.map(e=>t.getSize(e)).filter(t=>null!=t&&!Number.isNaN(t));if(o.length>0){let t=1/0,e=-1/0;for(const n of o)t>n&&(t=n),n>e&&(e=n);r=o=>t===e?(i[0]+i[1])/2:i[0]+(o-t)/(e-t)*(i[1]-i[0])}}const s=t.getColor?t.resolveColorMap(e):null,a=t.config.themeSemantic?.primary||"#4e79a7",l=t.getSymbol,c=l?_(l,t.config.symbolMap):null;for(const i of e){let e=t.config.pointStyle?t.config.pointStyle(i):{fill:a,opacity:.8},l=e.r||n;if(r&&t.getSize){const e=t.getSize(i);null==e||Number.isNaN(e)||(l=r(e))}if(s&&t.getColor&&!e.fill){const o=t.getColor(i);o&&s.has(o)&&(e={...e,fill:s.get(o)})}const u=t.getPointId?t.getPointId(i)+"":void 0;if(c){const n=c(i),r=sl(i,t.scales,t.getX,t.getY,Math.PI*l*l,n,e,u);r&&o.push(r)}else{const n=rl(i,t.scales,t.getX,t.getY,l,e,u);n&&o.push(n)}}return o}(i,e);case"heatmap":return function(t,e,o){if(t.config.heatmapAggregation)return function(t,e,o){const n=Math.max(1,Math.floor(t.config.heatmapXBins??20)),i=Math.max(1,Math.floor(t.config.heatmapYBins??20)),r=t.config.heatmapAggregation??"count",s=mt(t.config.valueAccessor,"value");if(!t.scales||0===e.length)return[];const[a,l]=t.scales.x.domain(),[c,u]=t.scales.y.domain(),d=(l-a||1)/n,h=(u-c||1)/i,p=n*i;if(p>1e6)return[];const f=new Int32Array(p),g=new Float64Array(p);for(let o=0;e.length>o;o++){const r=e[o],l=t.getX(r),u=t.getY(r);if(!isFinite(l)||!isFinite(u))continue;const p=Math.min(Math.floor((l-a)/d),n-1),y=Math.min(Math.floor((u-c)/h),i-1);if(0>p||0>y)continue;const m=y*n+p;f[m]++;const x=s(r);g[m]+=isFinite(x)?x:0}let y=1/0,m=-1/0;for(let t=0;p>t;t++){if(0===f[t])continue;let e;switch(r){case"sum":e=g[t];break;case"mean":e=g[t]/f[t];break;default:e=f[t]}y>e&&(y=e),e>m&&(m=e)}if(!isFinite(y))return[];const x=m-y||1,b=t.config.heatmapColorScale,v=b?void 0:xl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),w=255/x,k=o.width/n,A=o.height/i,S=t.config.showValues,M=t.config.heatmapValueFormat,_=[];for(let e=0;i>e;e++){const o=e*n;for(let s=0;n>s;s++){const n=o+s;if(0===f[n])continue;let l;switch(r){case"sum":l=g[n];break;case"mean":l=g[n]/f[n];break;default:l=f[n]}const u=Math.min((l-y)*w+.5|0,255),p=b?b(l):v[u],m={xi:s,yi:e,value:l,count:f[n],sum:g[n],xCenter:a+(s+.5)*d,yCenter:c+(e+.5)*h,agg:r};_.push(bl(ll(s*k,(i-1-e)*A,k,A,p,m,S?{value:l,showValues:!0,valueFormat:M}:{value:l}),m,t))}}return _}(t,e,o);if(0===e.length)return[];const n=mt(t.config.valueAccessor,"value"),i=vt(t.config.xAccessor,"x"),r=vt(t.config.yAccessor,"y"),s=new Map,a=new Map,l=Array(e.length),c=Array(e.length);for(let t=0;e.length>t;t++){const o=e[t],n=i(o),u=r(o);l[t]=n,c[t]=u,s.has(n)||s.set(n,s.size),a.has(u)||a.set(u,a.size)}const u=s.size,d=a.size;if(0===u||0===d)return[];const h=Array.from(s.keys()),p=Array.from(a.keys()),f=h.every(t=>"number"==typeof t&&!isNaN(t)),g=p.every(t=>"number"==typeof t&&!isNaN(t));if(f){h.sort((t,e)=>Number(t)-Number(e)),s.clear();for(let t=0;h.length>t;t++)s.set(h[t],t)}if(g){p.sort((t,e)=>Number(t)-Number(e)),a.clear();for(let t=0;p.length>t;t++)a.set(p[t],t)}const y=new Float64Array(e.length),m=new Float64Array(e.length),x=Array(e.length),b=new Map;let v=0;for(let t=0;e.length>t;t++){const o=e[t],i=s.get(l[t]),r=a.get(c[t]);if(void 0===i||void 0===r)continue;const d=n(o),h=r*u+i,p=b.get(h);let f;void 0!==p?f=p:(f=v++,b.set(h,f)),y[f]=h,m[f]=d,x[f]=o}let w=1/0,k=-1/0;for(let t=0;v>t;t++){const e=m[t];isFinite(e)&&(w>e&&(w=e),e>k&&(k=e))}if(!isFinite(w)||!isFinite(k))return[];const A=t.config.heatmapColorScale,S=A?void 0:xl("string"==typeof t.config.colorScheme?t.config.colorScheme:t.config.themeSequential||"blues"),M=255/(k-w||1),_=o.width/u,P=o.height/d,L=t.config.showValues,$=t.config.heatmapValueFormat,R=[];for(let e=0;v>e;e++){const o=m[e];if(!isFinite(o))continue;const n=y[e],i=n%u,r=(n-i)/u,s=Math.min((o-w)*M+.5|0,255),a=A?A(o):S[s],l=x[e];R.push(bl(ll(i*_,(d-1-r)*P,_,P,a,l,L?{value:o,showValues:!0,valueFormat:$}:{value:o}),l,t))}return R}(i,e,t);case"bar":{const t=function(t,e){if(!t.config.binSize)return{nodes:[],binBoundaries:[]};const o=vl(e,t.getX,t.getY,t.config.binSize,t.getCategory);if(0===o.size)return{nodes:[],binBoundaries:[]};let n=null;if(t.getCategory){const e=new Set;for(const t of o.values())for(const o of t.categories.keys())e.add(o);const i=t.config.barColors?Object.keys(t.config.barColors):[],r=new Set(i),s=Array.from(e).filter(t=>!r.has(t)).sort(),a=i.filter(t=>e.has(t)),l=a.join("\0")+""+s.join("\0");t.barCategoryCache&&t.barCategoryCache.key===l?n=t.barCategoryCache.order:(n=[...a,...s],t.barCategoryCache={key:l,order:n})}const i=[],r=t.scales,[s,a]=r.x.domain(),l=t.config.barStyle,c=t.config.themeSemantic?.primary,u=l?.gap,d="number"!=typeof u||0>u?1:u,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.cursor);for(const e of o.values()){const o=Math.max(e.start,s),u=Math.min(e.end,a);if(o>=u)continue;const p=r.x(o),f=r.x(u),g=Math.abs(f-p),y=g>d+1?d:0,m=Math.min(p,f)+y/2,x=Math.max(g-y,1);if(x>0)if(n&&e.categories.size>0){let o=0;for(const s of n){const n=e.categories.get(s)||0;if(0===n)continue;const a=r.y(o),u=r.y(o+n),d=Math.min(a,u),p=Math.abs(a-u),f=(t.config.barColors?ne(t.config.barColors,s):void 0)??l?.fill??c??"#4e79a7",g={binStart:e.start,binEnd:e.end,total:e.total,category:s,categoryValue:n},y=t.config.areaStyle?.(g)??{};i.push(al(m,d,x,p,{fill:f,...h,...y},g,s)),o+=n}}else{const o=r.y(0),n=r.y(e.total),s=Math.min(o,n),a=Math.abs(o-n),u=l?.fill||c||"#007bff",d={binStart:e.start,binEnd:e.end,total:e.total},p=t.config.areaStyle?.(d)??{};i.push(al(m,s,x,a,{fill:u,...h,...p},d))}}const p=new Set;for(const t of o.values())p.add(t.start),p.add(t.end);return{nodes:i,binBoundaries:Array.from(p).sort((t,e)=>t-e)}}(i,e);return this._barCategoryCache=i.barCategoryCache??null,this._binBoundaries=t.binBoundaries,t.nodes}case"swarm":return function(t,e){const o=[],n=t.config.swarmStyle||{},i=n.radius??3,r=n.fill??t.config.themeSemantic?.primary??"#007bff",s=n.opacity??.7,a=n.stroke,l=n.strokeWidth,c=n.cursor;for(const n of e){const e=t.getX(n),u=t.getY(n);if(null==u||Number.isNaN(u))continue;const d=t.scales.x(e),h=t.scales.y(u);let p=r;if(t.getCategory){const e=t.getCategory(n)+"";p=(t.config.barColors?ne(t.config.barColors,e):void 0)??p}const{r:f,...g}=t.config.pointStyle?.(n)??{},y={type:"point",x:d,y:h,r:f??i,style:{fill:p,opacity:s,stroke:a,strokeWidth:l,cursor:c,...g},datum:n};t.getPointId&&(y.pointId=t.getPointId(n)+""),o.push(y)}return o}(i,e);case"waterfall":return function(t,e,o){const n=[],i=t.scales,r=t.config.waterfallStyle,s=e.filter(e=>{const o=t.getY(e),n=t.getX(e);return null!=o&&!Number.isNaN(o)&&null!=n&&isFinite(n)});if(0===s.length)return n;const a=r?.positiveColor??t.config.themeSemantic?.success??"#28a745",l=r?.negativeColor??t.config.themeSemantic?.danger??"#dc3545",c=r?.gap??1,u=r?.stroke,d=r?.strokeWidth,h=r?.opacity;let p=0;for(let e=0;s.length>e;e++){const f=s[e],g=t.getX(f),y=t.getY(f),m=p+y;let x;x=s.length-1>e?t.getX(s[e+1])-g:e>0?g-t.getX(s[e-1]):0;const b=i.x(g),v=0!==x?i.x(g+x):b+o.width/10,w=Math.min(b,v)+c/2,k=Math.max(b,v)-c/2-w;if(0>=k){p=m;continue}const A=i.y(p),S=i.y(m),M=Math.min(A,S),_=Math.abs(A-S),P=0>y?l:a,L={...f,baseline:p,cumEnd:m,delta:y,_connectorStroke:r?.connectorStroke,_connectorWidth:r?.connectorWidth},$={fill:P,stroke:u,strokeWidth:d,opacity:h,cursor:r?.cursor,...t.config.areaStyle?.(L)};n.push(al(w,M,k,_,$,L)),p=m}return n}(i,e,t);case"candlestick":return function(t,e,o){if(!t.getHigh||!t.getLow||!t.scales)return[];const n=t.config.candlestickRangeMode??!1;if(!(n||t.getOpen&&t.getClose))return[];const i=[],r=t.config.candlestickStyle||{},s=r.rangeColor||"#6366f1",a=n?s:r.upColor||"#28a745",l=n?s:r.downColor||"#dc3545",c=n?s:r.wickColor||"#333",u=r.wickWidth||(n?2:1),d=e.map(e=>t.getX(e)).filter(t=>null!=t&&!Number.isNaN(t)).sort((t,e)=>t-e);let h=r.bodyWidth??0;if(null==r.bodyWidth)if(d.length>1){let e=1/0;for(let o=1;d.length>o;o++){const n=Math.abs(t.scales.x(d[o])-t.scales.x(d[o-1]));n>0&&e>n&&(e=n)}h=e!==1/0?Math.max(2,Math.min(.6*e,20)):6}else h=6;for(const s of e){const e=t.getX(s);if(null==e||Number.isNaN(e))continue;const d=t.getHigh(s),p=t.getLow(s);if(null==d||Number.isNaN(d)||null==p||Number.isNaN(p))continue;const f=n?d:t.getOpen(s),g=n?p:t.getClose(s);if(!n&&[f,g].some(t=>null==t||Number.isNaN(t)))continue;const y=g>=f,m={type:"candlestick",x:t.scales.x(e),openY:t.scales.y(f),closeY:t.scales.y(g),highY:t.scales.y(d),lowY:t.scales.y(p),bodyWidth:h,upColor:a,downColor:l,wickColor:c,wickWidth:u,isUp:y,style:{cursor:r.cursor},datum:s};n&&(m.isRange=!0,m.dotRadius=Math.max(2,Math.min(h/2,.12*o.height))),i.push(m)}return i}(i,e,t);default:return[]}}resolveBoundsStyle(t,e){return function(t,e,o,n){const i=t.boundsStyle;if("function"==typeof i)return i(o||{},e);if(i&&"object"==typeof i)return i;const r=n(e,o);return{fill:r.stroke||t.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,stroke:"none",cursor:r.cursor}}(this.config,t,e,(t,e)=>this.resolveLineStyle(t,e))}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Ua(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;const e=Ka(t);return this._datumIndexCache={version:this._ingestVersion,map:e},e}applyDecay(t,e){this.config.decay&&function(t,e,o,n=Ka(o)){const i=o.length;if(i>1)for(const o of e){if("line"===o.type){const e=Array.isArray(o.datum)?o.datum:[];if(2>e.length)continue;const r=Array(e.length);let s=!1;for(let o=0;e.length>o;o++){const a=n.get(e[o]);null!=a?(r[o]=Ua(t,a,i),1>r[o]&&(s=!0)):r[o]=1}s&&(o._decayOpacities=r);continue}if("area"===o.type){const e=Array.isArray(o.datum)?o.datum:[],r=o.topPath?o.topPath.length:e.length;if(2>r)continue;if(e.length===r){const s=Array(r);let a=!1;for(let o=0;e.length>o;o++){const r=n.get(e[o]);null!=r?(s[o]=Ua(t,r,i),1>s[o]&&(a=!0)):s[o]=1}a&&(o._decayOpacities=s)}else{let s=1;for(const o of e){const e=n.get(o);if(null!=e){const o=Ua(t,e,i);s>o&&(s=o)}}if(1>s){const t=Array(r);t.fill(s),o._decayOpacities=t}}continue}const e=n.get(o.datum);if(null==e)continue;const r=Ua(t,e,i);"candlestick"===o.type?o._decayOpacity=r:o.style={...o.style,opacity:(o.style?.opacity??1)*r}}}(this.config.decay,t,e,this.getDatumIndexMap(e))}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory}}snapshotPositions(){!function(t,e,o,n){o.clear(),n.clear();for(let i=0;e.length>i;i++){const r=e[i],s=tl(t,r,i);s&&("point"===r.type?o.set(s,{x:r.x,y:r.y,r:r.r,opacity:el(r.style)}):"glyph"===r.type?o.set(s,{x:r.x,y:r.y,r:r.size,opacity:el(r.style),glyph:r.glyph}):"rect"===r.type||"heatcell"===r.type?o.set(s,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:el(r.style)}):"candlestick"===r.type?o.set(s,{x:r.x,y:r.openY,w:r.bodyWidth,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY,opacity:el(r.style)}):"line"===r.type?n.set(s,{path:r.path.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}):"area"===r.type&&n.set(s,{topPath:r.topPath.map(t=>[t[0],t[1]]),bottomPath:r.bottomPath.map(t=>[t[0],t[1]]),opacity:r.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();const t=this.scales?.y(0)??0;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=tl(this.transitionContext,o,e);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:0,opacity:0}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:t,w:o.w,h:0,opacity:o.style.opacity??1}):"heatcell"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:0}):"line"===o.type?(o._introClipFraction=0,this.prevPathMap.set(n,{path:o.path.map(t=>[t[0],t[1]]),opacity:o.style.opacity})):"area"===o.type&&(o._introClipFraction=0,this.prevPathMap.set(n,{topPath:o.topPath.map(t=>[t[0],t[1]]),bottomPath:o.bottomPath.map(t=>[t[0],t[1]]),opacity:o.style.opacity})))}}startTransition(){if(!this.config.transition)return;const t=function(t,e,o,n,i,r=qa()){if(0===n.size&&0===i.size)return o;const s=e.duration??300;if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}let a=!1;const l=new Set,c=new Set;for(let e=0;o.scene.length>e;e++){const r=o.scene[e],s=tl(t,r,e);if(!s)continue;if(r._transitionKey=s,"line"===r.type||"area"===r.type){const t=i.get(s);if(t){if(c.add(s),"line"===r.type&&t.path&&t.path.length===r.path.length){r._targetPath=r.path.map(t=>[t[0],t[1]]),r._prevPath=t.path;for(let e=0;r.path.length>e;e++)r.path[e]=[t.path[e][0],t.path[e][1]];a=!0}else if("area"===r.type&&t.topPath&&t.bottomPath&&t.topPath.length===r.topPath.length&&t.bottomPath.length===r.bottomPath.length){r._targetTopPath=r.topPath.map(t=>[t[0],t[1]]),r._targetBottomPath=r.bottomPath.map(t=>[t[0],t[1]]),r._prevTopPath=t.topPath,r._prevBottomPath=t.bottomPath;for(let e=0;r.topPath.length>e;e++)r.topPath[e]=[t.topPath[e][0],t.topPath[e][1]];for(let e=0;r.bottomPath.length>e;e++)r.bottomPath[e]=[t.bottomPath[e][0],t.bottomPath[e][1]];a=!0}r._targetOpacity=r.style.opacity??1,r._startOpacity=t.opacity??r.style.opacity??1}else r._targetOpacity=r.style.opacity??1,r._startOpacity=0,r.style={...r.style,opacity:0},a=!0;continue}const u=n.get(s);if("point"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,r:r.r};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.r===t.r||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.r,r.x=u.x,r.y=u.y,r.r=u.r??r.r,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("glyph"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,size:r.size};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.r===t.size||(r._targetX=t.x,r._targetY=t.y,r._targetR=t.size,r.x=u.x,r.y=u.y,r.size=u.r??r.size,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("rect"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style,opacity:0},a=!0;else if("heatcell"===r.type)if(u){l.add(s);const t={x:r.x,y:r.y,w:r.w,h:r.h};r._targetOpacity=el(r.style),u.x===t.x&&u.y===t.y&&u.w===t.w&&u.h===t.h||(r._targetX=t.x,r._targetY=t.y,r._targetW=t.w,r._targetH=t.h,r.x=u.x,r.y=u.y,r.w=u.w??r.w,r.h=u.h??r.h,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style||{},opacity:0},a=!0;else if("candlestick"===r.type)if(u&&null!=u.openY){l.add(s);const t={x:r.x,openY:r.openY,closeY:r.closeY,highY:r.highY,lowY:r.lowY};r._targetOpacity=el(r.style),(u.x!==t.x||u.openY!==t.openY||u.closeY!==t.closeY||u.highY!==t.highY||u.lowY!==t.lowY)&&(r._targetX=t.x,r._targetOpenY=t.openY,r._targetCloseY=t.closeY,r._targetHighY=t.highY,r._targetLowY=t.lowY,r.x=u.x,r.openY=u.openY,r.closeY=u.closeY??r.closeY,r.highY=u.highY??r.highY,r.lowY=u.lowY??r.lowY,a=!0)}else r._targetOpacity=el(r.style),r.style={...r.style||{},opacity:0},a=!0}for(const[t,e]of i)if(!c.has(t))if(t.startsWith("l:")&&e.path){const n={type:"line",path:e.path.map(t=>[t[0],t[1]]),group:t.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(n),a=!0}else if(t.startsWith("a:")&&e.topPath&&e.bottomPath){const n={type:"area",topPath:e.topPath.map(t=>[t[0],t[1]]),bottomPath:e.bottomPath.map(t=>[t[0],t[1]]),group:t.slice(2),style:{fill:"#999",opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t,datum:null};o.exitNodes.push(n),a=!0}for(const[t,e]of n)if(!l.has(t)){if(t.startsWith("p:"))o.exitNodes.push({type:"point",x:e.x,y:e.y,r:e.r??3,style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("g:")&&e.glyph)o.exitNodes.push({type:"glyph",x:e.x,y:e.y,size:e.r??12,glyph:e.glyph,color:"#999",accent:"#999",style:{opacity:e.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))o.exitNodes.push({type:"rect",x:e.x,y:e.y,w:e.w??0,h:e.h??0,style:{opacity:e.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("h:"))o.exitNodes.push({type:"heatcell",x:e.x,y:e.y,w:e.w??0,h:e.h??0,fill:"#999",datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t});else if(t.startsWith("c:")){const n=e.openY??e.y;o.exitNodes.push({type:"candlestick",x:e.x,openY:n,closeY:e.closeY??n,highY:e.highY??n,lowY:e.lowY??n,bodyWidth:e.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:e.opacity??1},_targetOpacity:0,_transitionKey:t})}a=!0}return o.exitNodes.length>0&&(o.scene=[...o.scene,...o.exitNodes]),a&&(o.activeTransition={startTime:r,duration:s}),o}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(t){if(!this.activeTransition||!this.config.transition)return!1;const e={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},o=function(t,e,o,n){if(!o.activeTransition)return!1;const i=Va(t,o.activeTransition),r=Ga(i,"linear"===e.easing?"linear":"ease-out-cubic");for(const t of o.scene){const e=t._transitionKey;if("point"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Ha(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.r=Ha(o.r,t._targetR,r))}else if("glyph"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Ha(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==t._targetR&&void 0!==o.r&&(t.size=Ha(o.r,t._targetR,r))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style.opacity=Ha(o?o.opacity??1:0,t._targetOpacity,r)}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==o.w&&(t.w=Ha(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Ha(o.h,t._targetH,r))}else if("heatcell"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Ha(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),t.y=Ha(o.y,t._targetY,r),void 0!==o.w&&(t.w=Ha(o.w,t._targetW,r)),void 0!==o.h&&(t.h=Ha(o.h,t._targetH,r))}else if("candlestick"===t.type){if(void 0!==t._targetOpacity){const o=e?n.get(e):void 0;t.style={...t.style||{},opacity:Ha(o?o.opacity??1:0,t._targetOpacity,r)}}if(void 0===t._targetX)continue;if(!e)continue;const o=n.get(e);if(!o)continue;t.x=Ha(o.x,t._targetX,r),void 0!==o.openY&&(t.openY=Ha(o.openY,t._targetOpenY,r)),void 0!==o.closeY&&(t.closeY=Ha(o.closeY,t._targetCloseY,r)),void 0!==o.highY&&(t.highY=Ha(o.highY,t._targetHighY,r)),void 0!==o.lowY&&(t.lowY=Ha(o.lowY,t._targetLowY,r))}else if("line"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ha(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevPath,o=t._targetPath;if(e&&o&&e.length===t.path.length)for(let n=0;t.path.length>n;n++)t.path[n][0]=Ha(e[n][0],o[n][0],r),t.path[n][1]=Ha(e[n][1],o[n][1],r)}else if("area"===t.type){void 0!==t._targetOpacity&&(t.style={...t.style,opacity:Ha(t._startOpacity??0,t._targetOpacity,r)}),void 0!==t._introClipFraction&&(t._introClipFraction=r);const e=t._prevTopPath,o=t._prevBottomPath,n=t._targetTopPath,i=t._targetBottomPath;if(e&&n&&e.length===t.topPath.length)for(let o=0;t.topPath.length>o;o++)t.topPath[o][0]=Ha(e[o][0],n[o][0],r),t.topPath[o][1]=Ha(e[o][1],n[o][1],r);if(o&&i&&o.length===t.bottomPath.length)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e][0]=Ha(o[e][0],i[e][0],r),t.bottomPath[e][1]=Ha(o[e][1],i[e][1],r)}}if(i>=1){for(const t of o.scene){if(void 0!==t._targetOpacity){const e=t._targetOpacity;t.style="line"===t.type||"area"===t.type?{...t.style,opacity:0===e?0:e}:{...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("glyph"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("heatcell"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else if("candlestick"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0}else if("line"===t.type){const e=t._targetPath;if(e)for(let o=0;t.path.length>o;o++)t.path[o]=e[o];t._prevPath=void 0,t._targetPath=void 0,t._introClipFraction=void 0}else if("area"===t.type){const e=t._targetTopPath,o=t._targetBottomPath;if(e)for(let o=0;t.topPath.length>o;o++)t.topPath[o]=e[o];if(o)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=o[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0,t._introClipFraction=void 0}}if(o.exitNodes.length>0){const t=new Set(o.exitNodes);o.scene=o.scene.filter(e=>!t.has(e)),o.exitNodes=[]}return o.activeTransition=null,!1}return!0}(t,this.config.transition,e,this.prevPositionMap);return this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition,o}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("glyph"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0);else if("rect"===e.type||"heatcell"===e.type)void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0);else if("candlestick"===e.type)void 0!==e._targetX&&(e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0);else if("line"===e.type||"area"===e.type){if(e._introClipFraction=void 0,"line"===e.type&&e._targetPath){for(let t=0;e.path.length>t;t++)e.path[t]=e._targetPath[t];e._prevPath=void 0,e._targetPath=void 0}if("area"===e.type){if(e._targetTopPath)for(let t=0;e.topPath.length>t;t++)e.topPath[t]=e._targetTopPath[t];if(e._targetBottomPath)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=e._targetBottomPath[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(t){const{result:e,cache:o}=function(t,e,o,n){if(n&&n.version===o&&n.group===e&&n.data===t)return{result:n.result,cache:n};let i;if(e){const o=new Map;for(const n of t){const t=e(n);o.has(t)||o.set(t,[]),o.get(t).push(n)}i=Array.from(o.entries()).map(([t,e])=>({key:t,data:e}))}else i=[{key:"_default",data:t}];return{result:i,cache:{version:o,group:e,data:t,result:i}}}(t,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=o,e}resolveColorMap(t){const{map:e,cache:o}=function(t,e,o,n,i){if(i&&i.version===n)return{map:i.map,cache:i};const r=new Set;if(e)for(const o of t){const t=e(o);t&&r.add(t)}const s=Array.from(r).sort(),a=s.join("\0");if(i&&i.key===a){const t={...i,version:n};return{map:t.map,cache:t}}const l=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical||Jt,c=new Map;for(let t=0;s.length>t;t++)c.set(s[t],l[t%l.length]);return{map:c,cache:{key:a,map:c,version:n}}}(t,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=o,e}resolveLineStyle(t,e){return function(t,e,o,n){const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.stroke&&e){const o=n(e);if(o)return{...t,stroke:o}}return t}const r=t.themeSemantic?.primary;return i&&"object"==typeof i?{stroke:i.stroke||r||"#007bff",strokeWidth:i.strokeWidth??2,strokeDasharray:i.strokeDasharray,fill:i.fill,fillOpacity:i.fillOpacity,opacity:i.opacity,cursor:i.cursor}:{stroke:n(e)||r||"#007bff",strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveAreaStyle(t,e){return function(t,e,o,n){if(t.areaStyle){const i=t.areaStyle(o||{});if(i&&!i.fill&&e){const t=n(e);if(t)return{...i,fill:t,stroke:i.stroke||t}}return i}const i=t.lineStyle;if("function"==typeof i){const t=i(o||{},e);if(t&&!t.fill&&e){const o=n(e);if(o)return{...t,fill:o,stroke:t.stroke||o}}return t}const r=t.themeSemantic?.primary;if(i&&"object"==typeof i)return{fill:i.fill||i.stroke||r||"#4e79a7",fillOpacity:i.fillOpacity??.7,stroke:i.stroke||r||"#4e79a7",strokeWidth:i.strokeWidth??2,cursor:i.cursor};const s=n(e)||r||"#4e79a7";return{fill:s,fillOpacity:.7,stroke:s,strokeWidth:2}}(this.config,t,e,t=>this.resolveGroupColor(t))}resolveGroupColor(e){const{color:o,groupColorCounter:n}=function(t){const{group:e,colorMapCache:o,groupColorMap:n,groupColorMapCap:i,config:r}=t;let{groupColorCounter:s}=t;if(o){const t=o.map.get(e);if(t)return{color:t,groupColorCounter:s}}const a=n.get(e);if(a)return{color:a,groupColorCounter:s};const l=(Array.isArray(r.colorScheme)&&r.colorScheme.length>0?r.colorScheme:null)||(Array.isArray(r.themeCategorical)&&r.themeCategorical.length>0?r.themeCategorical:null)||Jt;if(0===l.length)return{color:null,groupColorCounter:s};const c=l[s%l.length];if(s++,n.set(e,c),n.size>i){const t=n.keys().next().value;void 0!==t&&n.delete(t)}return{color:c,groupColorCounter:s}}({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:t.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=n,o}getBufferArray(){return!this._bufferDirty&&this._bufferArrayCache||(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(t){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Xa(t),o=this.getPointId,n=t=>e.has(o(t));Fl(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");const o=Xa(t),n=this.getPointId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.xExtent.evict(this.getX(t)),this.evictDatumYExtent(t);return this.buffer.forEach((t,e)=>{i.has(e)&&(this.xExtent.push(this.getX(t)),this.pushDatumYExtent(t))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t||"themeCategorical"in t||"colorAccessor"in t)&&(this._colorMapCache=null,this._groupColorMap=new Map,this._groupColorCounter=0),("barColors"in t||"colorScheme"in t)&&(this._barCategoryCache=null),("normalize"in t||"extentPadding"in t||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t||"boundsAccessor"in t||"band"in t||"y0Accessor"in t||"openAccessor"in t||"highAccessor"in t||"lowAccessor"in t||"closeAccessor"in t||"groupAccessor"in t||"categoryAccessor"in t||"chartType"in t||"runtimeMode"in t)&&(this._stackExtentCache=null);let n=!1,i=!1;Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();const r="chartType"in t&&t.chartType!==e.chartType||"runtimeMode"in t&&t.runtimeMode!==e.runtimeMode;if(r||"xAccessor"in t||"yAccessor"in t||"timeAccessor"in t||"valueAccessor"in t){const t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,o=t&&this.config.valueAccessor||this.config.yAccessor,s=t&&e.valueAccessor||e.yAccessor,a=r||!yt(t&&this.config.timeAccessor||this.config.xAccessor,t&&e.timeAccessor||e.xAccessor),l=r||!yt(o,s);(a||l)&&(t?(this.getX=mt(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=mt(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=mt(this.config.xAccessor,"x"),this.getY=mt(this.config.yAccessor,"y")),l&&this.resolvedRibbons.some(t=>"bounds"===t.kind)&&(this.resolvedRibbons=_l(this.config)),n=!0,i=!0)}if("groupAccessor"in t&&!yt(t.groupAccessor,e.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?wt(this.config.groupAccessor):void 0,n=!0),"categoryAccessor"in t&&!yt(t.categoryAccessor,e.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?wt(this.config.categoryAccessor):void 0,n=!0),"sizeAccessor"in t&&!yt(t.sizeAccessor,e.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?mt(this.config.sizeAccessor,"size"):void 0,n=!0),"symbolAccessor"in t&&!yt(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?wt(this.config.symbolAccessor):void 0,n=!0),"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?wt(this.config.colorAccessor):void 0,n=!0),"y0Accessor"in t&&!yt(t.y0Accessor,e.y0Accessor)&&(this.getY0=this.config.y0Accessor?mt(this.config.y0Accessor,"y0"):void 0,n=!0,i=!0),("boundsAccessor"in t&&!yt(t.boundsAccessor,e.boundsAccessor)||"band"in t&&t.band!==e.band||"boundsStyle"in t&&t.boundsStyle!==e.boundsStyle)&&(this.resolvedRibbons=_l(this.config),n=!0,i=!0),"pointIdAccessor"in t&&!yt(t.pointIdAccessor,e.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?wt(this.config.pointIdAccessor):void 0,n=!0),"candlestick"===this.config.chartType&&(r||"openAccessor"in t&&!yt(t.openAccessor,e.openAccessor)||"closeAccessor"in t&&!yt(t.closeAccessor,e.closeAccessor)||"highAccessor"in t&&!yt(t.highAccessor,e.highAccessor)||"lowAccessor"in t&&!yt(t.lowAccessor,e.lowAccessor))){const t=null!=this.config.openAccessor,e=null!=this.config.closeAccessor;this.getOpen=t?mt(this.config.openAccessor,"open"):void 0,this.getHigh=mt(this.config.highAccessor,"high"),this.getLow=mt(this.config.lowAccessor,"low"),this.getClose=e?mt(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!e,n=!0,i=!0}if("accessorRevision"in t&&t.accessorRevision!==e.accessorRevision&&(n=!0,i=!0),!n){const o=Object.keys(t).filter(t=>!t.endsWith("Accessor")&&"timeAccessor"!==t&&"valueAccessor"!==t);for(const i of o)if(t[i]!==e[i]){n=!0;break}}n&&(i&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};sc.GROUP_COLOR_MAP_CAP=1e3;var ac=sc;Xl(ac);import*as lc from"react";import{area as cc,line as uc}from"d3-shape";function dc(t,e,o){let n=o;for(const o of e)"lesser"===o.thresholdType?o.value>t&&(n=o.color):t>o.value&&(n=o.color);return n}import{jsx as hc,jsxs as pc}from"react/jsx-runtime";var fc={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function gc(t,e="#4e79a7"){return ot(t)?t.background&&"transparent"!==t.background?t.background:e:t&&"string"==typeof t?t:e}function yc(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"s_"+e:e}function mc(t,e,o,n){const i=t.glyph;if(!i?.parts?.length||0>=t.size)return null;const r=g(i,t.size);if(0>=r.scale)return null;const s=`translate(${e},${o})${t.rotation?` rotate(${180*t.rotation/Math.PI})`:""} translate(${r.offsetX},${r.offsetY}) scale(${r.scale})`,a=t.color??("string"==typeof t.style.fill?t.style.fill:void 0),l=p(i,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal"),c=l?yc(n+"-clip"):void 0,u=(t.style.opacity??1)*(t._decayOpacity??1)*(t.style.fillOpacity??1),d=e=>i.parts.map((o,n)=>{const i=e?"none"===o.fill?void 0:e:N(o.fill,a,t.accent),r=e?o.stroke&&"none"!==o.stroke?e:void 0:N(o.stroke??"none",a,t.accent);return i||r?hc("path",{d:o.d,fill:i??"none",stroke:r,strokeWidth:r?o.strokeWidth??1:void 0,strokeLinecap:o.strokeLinecap,strokeLinejoin:o.strokeLinejoin,opacity:o.opacity},n):null});return pc("g",{transform:s,opacity:1===u?void 0:u,children:[l&&c&&hc("clipPath",{id:c,children:hc("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&t.ghostColor?hc("g",{children:d(t.ghostColor)}):null,l&&c?hc("g",{clipPath:`url(#${c})`,children:d()}):d()]},n)}function xc(t,e){const o=t.filter(t=>Number.isFinite(t.offset)&&(null==t.opacity||Number.isFinite(t.opacity))).map(t=>({offset:Math.max(0,Math.min(1,t.offset)),color:t.color??e,opacity:null==t.opacity?void 0:Math.max(0,Math.min(1,t.opacity))}));return 2>o.length?null:o.map((t,e)=>hc("stop",{offset:t.offset,stopColor:t.color,stopOpacity:t.opacity},e))}function bc(t,e,o){const n=X(t.symbolType,t.size,t.path);return hc("path",{d:n,transform:t.rotation?`translate(${t.x},${t.y}) rotate(${180*t.rotation/Math.PI})`:`translate(${t.x},${t.y})`,fill:t.style.fill?gc(t.style.fill):"none",fillOpacity:t.style.fillOpacity,opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},`${o??""}symbol-${e}`)}import*as vc from"react";import{jsx as wc}from"react/jsx-runtime";function kc(t){if(!1!==t?.interactive)return t?.style?.cursor}function Ac(t,e,o){const n=kc(e);return n&&null!=t&&!1!==t?wc("g",{style:{cursor:n},"data-semiotic-mark-cursor":n,children:t},o):t}import*as Sc from"react";import{arc as Mc}from"d3-shape";import{jsx as _c,jsxs as Pc}from"react/jsx-runtime";import*as Lc from"react";import{jsx as $c,jsxs as Rc}from"react/jsx-runtime";import*as Cc from"react";import{arc as Tc}from"d3-shape";var Oc=(t,e)=>({x:t*Math.cos(e),y:t*Math.sin(e)});function Ic(t){const{innerRadius:e,outerRadius:o,startAngle:n,endAngle:i}=t,r=0>=e;if(0>=(t.cornerRadius??0)||!t.roundStart&&!t.roundEnd){if(r){const t=Oc(o,n),e=Oc(o,i);return`M0,0 L${t.x},${t.y} A${o},${o} 0 ${i-n>Math.PI?1:0} 1 ${e.x},${e.y} Z`}const t=Oc(o,n),s=Oc(o,i),a=Oc(e,i),l=Oc(e,n),c=i-n>Math.PI?1:0;return`M${t.x},${t.y} A${o},${o} 0 ${c} 1 ${s.x},${s.y} L${a.x},${a.y} A${e},${e} 0 ${c} 0 ${l.x},${l.y} Z`}const s=Math.max(0,Math.min(t.cornerRadius??0,(o-e)/2));if(0===s)return Ic({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const a=Math.asin(Math.min(1,s/Math.max(1e-9,o-s))),l=r?0:Math.asin(Math.min(1,s/Math.max(1e-9,e+s))),c=i-n,u=t.roundStart&&t.roundEnd?c/2:c,d=!!t.roundStart&&u>a,h=!!t.roundEnd&&u>a;if(!d&&!h)return Ic({...t,cornerRadius:0,roundStart:!1,roundEnd:!1});const p=n+(d?a:0),f=i-(h?a:0),g=n+(d?l:0),y=i-(h?l:0),m=Oc(o,p),x=Oc(o,f),b=(o-s)*Math.cos(a),v=Oc(b,n),w=Oc(b,i),k=r?null:Oc(e,y),A=r?null:Oc(e,g),S=r?0:(e+s)*Math.cos(l),M=r?null:Oc(S,n),_=r?null:Oc(S,i),P=f-p>Math.PI?1:0,L=r?0:y-g>Math.PI?1:0;let $="";if(d)$+=`M${v.x},${v.y}`,$+=` A${s},${s} 0 0 1 ${m.x},${m.y}`;else{const t=Oc(o,n);$+=`M${t.x},${t.y}`}if(h)$+=` A${o},${o} 0 ${P} 1 ${x.x},${x.y}`,$+=` A${s},${s} 0 0 1 ${w.x},${w.y}`;else{const t=Oc(o,i);$+=` A${o},${o} 0 ${P} 1 ${t.x},${t.y}`}if(r)$+=" L0,0";else{if(h)$+=` L${_.x},${_.y}`,$+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{const t=Oc(e,i);$+=` L${t.x},${t.y}`}if(d)$+=` A${e},${e} 0 ${L} 0 ${A.x},${A.y}`,$+=` A${s},${s} 0 0 1 ${M.x},${M.y}`;else{const t=Oc(e,n);$+=` A${e},${e} 0 ${L} 0 ${t.x},${t.y}`}}return $+=" Z",$}import{jsx as zc,jsxs as Fc}from"react/jsx-runtime";function Nc(t){return 1e6>t?1e4>t?1e3>t?t+"":(t/1e3).toFixed(1)+"K":(t/1e3).toFixed(0)+"K":(t/1e6).toFixed(1)+"M"}function Ec(t,e){const o=t.datum;if(!o)return null;const n=[],i=o.__funnelStepLabel,r=Number(o.__funnelStepLabelX),s=Number(o.__funnelStepLabelY),a=Number(o.__funnelRowWidth);"string"!=typeof i||!Number.isFinite(r)||!Number.isFinite(s)||Number.isFinite(a)&&8.4*i.length+16>a||n.push(zc("text",{x:r,y:s+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-step"));const l=Number(o.__funnelValue),c=Number(o.__funnelValueLabelX),u=Number(o.__funnelValueLabelY),d=Number(o.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){const t=Number(o.__funnelPercent);let i=!0!==o.__funnelIsFirstStep&&Number.isFinite(t)?`${Nc(l)} (${.05>Math.abs(t-Math.round(t))?Math.round(t):t.toFixed(1)}%)`:Nc(l);7.8*i.length+16>d&&(i=Nc(l)),7.8*i.length+16>d||n.push(zc("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:i},e+"-funnel-value"))}return n.length?zc("g",{children:n},e+"-funnel-labels"):null}function Dc(t,e,o){return Ac(function(t,e,o){const n=("category"in t?t.category:void 0)||("group"in t?t.group:void 0)||"",i=o=>`ord-${t.type}-${n}-${e}-${o}`,r=`ord-${t.type}-${n}-${e}`;switch(t.type){case"rect":{const e=t,o=yc(r)+"-grad",n=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=t.x,i=t.y,r=t.x,s=t.y+t.h;"bottom"===t.roundedEdge?(i=t.y+t.h,s=t.y):"right"===t.roundedEdge?(n=t.x+t.w,i=t.y,r=t.x,s=t.y):"left"===t.roundedEdge&&(n=t.x,i=t.y,r=t.x+t.w,s=t.y);const a=xc(o.stops,gc(t.style.fill));return a?hc("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:n,y1:i,x2:r,y2:s,children:a}):null}(e,o);let i,a;if(n)a=`url(#${o})`;else if(ot(e.style.fill)){const t=yc(r)+"-hatch";i=et(e.style.fill,t),a=`url(#${t})`}else a=gc(e.style.fill);const l=n||i?Fc("defs",{children:[n,i]}):null;if(e.cornerRadii&&(((s=e.cornerRadii).tl??0)>0||(s.tr??0)>0||(s.br??0)>0||(s.bl??0)>0)){const t=function(t){const{x:e,y:o,w:n,h:i}=t,{tl:r,tr:s,br:a,bl:l}=function(t){const e=t.cornerRadii;if(!e)return{tl:0,tr:0,br:0,bl:0};const o=Math.min(t.w,t.h)/2,n=t=>Math.max(0,Math.min(t??0,o));return{tl:n(e.tl),tr:n(e.tr),br:n(e.br),bl:n(e.bl)}}(t);let c=`M${e+r},${o}`;return c+=` L${e+n-s},${o}`,s>0&&(c+=` A${s},${s} 0 0 1 ${e+n},${o+s}`),c+=` L${e+n},${o+i-a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${e+n-a},${o+i}`),c+=` L${e+l},${o+i}`,l>0&&(c+=` A${l},${l} 0 0 1 ${e},${o+i-l}`),c+=` L${e},${o+r}`,r>0&&(c+=` A${r},${r} 0 0 1 ${e+r},${o}`),c+=" Z",c}(e);return Fc(Cc.Fragment,{children:[l,zc("path",{d:t,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}if(e.roundedTop&&e.roundedTop>0){const t=Math.min(e.roundedTop,e.w/2,e.h/2),{x:o,y:n,w:i,h:s}=e;let c;switch(e.roundedEdge){case"right":c=`M${o},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+s-t} A${t},${t} 0 0 1 ${o+i-t},${n+s} L${o},${n+s} Z`;break;case"left":c=`M${o+i},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+s-t} A${t},${t} 0 0 0 ${o+t},${n+s} L${o+i},${n+s} Z`;break;case"bottom":c=`M${o},${n} L${o+i},${n} L${o+i},${n+s-t} A${t},${t} 0 0 1 ${o+i-t},${n+s} L${o+t},${n+s} A${t},${t} 0 0 1 ${o},${n+s-t} Z`;break;default:c=`M${o},${n+s} L${o},${n+t} A${t},${t} 0 0 1 ${o+t},${n} L${o+i-t},${n} A${t},${t} 0 0 1 ${o+i},${n+t} L${o+i},${n+s} Z`}return Fc(Cc.Fragment,{children:[l,zc("path",{d:c,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},r)}return Fc(Cc.Fragment,{children:[l,zc("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:a,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth}),Ec(e,r)]},r)}case"point":{const e=t;return zc("circle",{cx:e.x,cy:e.y,r:e.r,fill:gc(e.style.fill),opacity:e.style.opacity??e.style.fillOpacity??.8,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}case"symbol":return bc(t,e,o);case"glyph":return mc(t,t.x,t.y,`${o??""}ord-glyph-${t.pointId??e}`);case"wedge":{const n=t;if(n._gradientBand&&n._gradientBand.colors.length>0){const t=yc(`${o?o+"-":""}gauge-grad-${n.category||r}-${e}`),{clipPath:i,slices:s}=function(t){const e=Ic({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle,endAngle:t.endAngle,cornerRadius:t.cornerRadius,roundStart:t.roundStart,roundEnd:t.roundEnd}),o=[],n=t.colors;if(n.length>0){const e=(t.endAngle-t.startAngle)/n.length;for(let i=0;n.length>i;i++)o.push({d:Ic({innerRadius:t.innerRadius,outerRadius:t.outerRadius,startAngle:t.startAngle+i*e,endAngle:t.endAngle}),color:n[i]})}return{clipPath:e,slices:o}}({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});return Fc("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[zc("defs",{children:zc("clipPath",{id:t,children:zc("path",{d:i})})}),zc("g",{clipPath:`url(#${t})`,children:s.map((t,e)=>zc("path",{d:t.d,fill:gc(t.color)},e))}),n.style.stroke&&"none"!==n.style.stroke&&zc("path",{d:i,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},r)}let i;if(n.roundedEnds)i=Ic({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{const t=Tc().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&t.cornerRadius(n.cornerRadius),i=t(fc)||""}return zc("path",{d:i,transform:`translate(${n.cx},${n.cy})`,fill:gc(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n.style.opacity},r)}case"boxplot":{const e=t,o=e.columnWidth/2,n=e.style.strokeWidth??1;return Fc("g","vertical"===e.projection?{children:[zc("line",{x1:e.x,y1:e.minPos,x2:e.x,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("rect",{x:e.x-o,y:Math.min(e.q1Pos,e.q3Pos),width:e.columnWidth,height:Math.abs(e.q3Pos-e.q1Pos),fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.x-o,y1:e.medianPos,x2:e.x+o,y2:e.medianPos,stroke:e.style.stroke||"#333",strokeWidth:2*n}),zc("line",{x1:e.x-.5*o,y1:e.minPos,x2:e.x+.5*o,y2:e.minPos,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.x-.5*o,y1:e.maxPos,x2:e.x+.5*o,y2:e.maxPos,stroke:e.style.stroke||"#333",strokeWidth:n})]}:{children:[zc("line",{x1:e.minPos,y1:e.y,x2:e.maxPos,y2:e.y,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("rect",{x:Math.min(e.q1Pos,e.q3Pos),y:e.y-o,width:Math.abs(e.q3Pos-e.q1Pos),height:e.columnWidth,fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.medianPos,y1:e.y-o,x2:e.medianPos,y2:e.y+o,stroke:e.style.stroke||"#333",strokeWidth:2*n}),zc("line",{x1:e.minPos,y1:e.y-.5*o,x2:e.minPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n}),zc("line",{x1:e.maxPos,y1:e.y-.5*o,x2:e.maxPos,y2:e.y+.5*o,stroke:e.style.stroke||"#333",strokeWidth:n})]},r)}case"violin":{const e=t,o=[zc("path",{d:e.pathString,transform:e.translateX||e.translateY?`translate(${e.translateX},${e.translateY})`:void 0,fill:gc(e.style.fill),fillOpacity:e.style.fillOpacity??.6,stroke:e.style.stroke||"#333",strokeWidth:e.style.strokeWidth??1},i("path"))];if(e.iqrLine&&e.bounds){const t=e.bounds,n=t.x+t.width/2,r=t.y+t.height/2;e.iqrLine.isVertical?o.push(zc("line",{x1:n,y1:e.iqrLine.q1Pos,x2:n,y2:e.iqrLine.q3Pos,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),zc("circle",{cx:n,cy:e.iqrLine.medianPos,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med"))):o.push(zc("line",{x1:e.iqrLine.q1Pos,y1:r,x2:e.iqrLine.q3Pos,y2:r,stroke:e.style.stroke||"#333",strokeWidth:2},i("iqr")),zc("circle",{cx:e.iqrLine.medianPos,cy:r,r:3,fill:"white",stroke:e.style.stroke||"#333",strokeWidth:1},i("med")))}return zc("g",{children:o},r)}case"connector":{const e=t,o=e.style.fill&&"none"!==e.style.fill?gc(e.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return zc("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||o,strokeWidth:e.style.strokeWidth??1,opacity:e.style.opacity??.5},r)}case"trapezoid":{const e=t,o=e.points.map(t=>`${t[0]},${t[1]}`).join(" ");return zc("polygon",{points:o,fill:gc(e.style.fill,"#999"),opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},r)}default:return null}var s}(t,e,o),t,"ordinal-cursor-"+e)}import{jsx as Wc,jsxs as Bc}from"react/jsx-runtime";function jc(t,e,o,n){if(!t||2>e.length)return null;const i=xc(t.stops,n);return i?Wc("linearGradient",{id:o,gradientUnits:"userSpaceOnUse",x1:e[0][0],y1:0,x2:e[e.length-1][0],y2:0,children:i}):null}function Yc(t,e,o,n=30){const i=function(t,e,o,n=30){switch(t.type){case"line":{const n=t;if(0===n.path.length)return null;const i=qs(n.curve),r=i?uc().x(([t])=>t).y(([,t])=>t).curve(i)(n.path)??"":"M"+n.path.map(([t,e])=>`${t},${e}`).join("L"),s=yc(`${o?o+"-":""}line-${e}-stroke-gradient`),a=jc(n.strokeGradient,n.path,s,n.style.stroke||"#4e79a7");return Bc(lc.Fragment,{children:[a&&Wc("defs",{children:a}),Wc("path",{d:r,fill:"none",stroke:a?`url(#${s})`:n.style.stroke||"#4e79a7",strokeWidth:n.style.strokeWidth??2,strokeDasharray:n.style.strokeDasharray,opacity:n.style.opacity})]},"line-"+e)}case"area":{const i=t;if(0===i.topPath.length)return null;const r=qs(i.curve),s=!r||2>i.topPath.length||2>i.bottomPath.length?`M${i.topPath.map(([t,e])=>`${t},${e}`).join("L")}L${[...i.bottomPath].reverse().map(([t,e])=>`${t},${e}`).join("L")}Z`:cc().x(([t])=>t).y0((t,e)=>i.bottomPath[e][1]).y1(([,t])=>t).curve(r)(i.topPath)??"",a=`${o?o+"-":""}area-${e}-hatch`,l=ot(i.style.fill)?et(i.style.fill,a):void 0,c=yc(`${o?o+"-":""}area-${e}-gradient`),u=function(t,e){const o=t.fillGradient;if(!o||"object"!=typeof o)return null;let n=1/0;for(const[,e]of t.topPath)n=Math.min(n,e);let i=-1/0;for(const[,e]of t.bottomPath)i=Math.max(i,e);if(!Number.isFinite(n)||!Number.isFinite(i))return null;const r=xc(o.stops,gc(t.style.fill));return r?Wc("linearGradient",{id:e,gradientUnits:"userSpaceOnUse",x1:0,y1:n,x2:0,y2:i,children:r}):null}(i,c),d=u?`url(#${c})`:l?`url(#${a})`:gc(i.style.fill),h=u?void 0:i.style.fillOpacity??i.style.opacity??.7,p=r?uc().x(([t])=>t).y(([,t])=>t).curve(r)(i.topPath)??"":"M"+i.topPath.map(([t,e])=>`${t},${e}`).join("L"),f=kc(i),g=f&&n>=0?Wc("path",{d:p,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*n),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:f},"data-semiotic-mark-cursor":f,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${e}-cursor-target`):null,y=yc(`${o?o+"-":""}area-${e}-stroke-gradient`),m=!(!i.colorThresholds?.length||!i.rawValues||i.rawValues.length!==i.topPath.length),x=!!i.strokeColorBands?.length,b=m||x?null:jc(i.strokeGradient,i.topPath,y,i.style.stroke||"#4e79a7"),v=i.style.strokeWidth??2;let w=1/0,k=-1/0;for(const[t]of i.topPath)w>t&&(w=t),t>k&&(k=t);const A=x?i.strokeColorBands.map((t,n)=>yc(`${o?o+"-":""}area-${e}-stroke-band-${n}`)):[],S=x?i.strokeColorBands.map((t,e)=>Wc("clipPath",{id:A[e],children:Wc("rect",{x:w-v,y:t.y,width:k-w+2*v,height:t.height})},A[e])):null,M=i.style.stroke&&"none"!==i.style.stroke?x?i.strokeColorBands.map((t,o)=>Wc("path",{d:p,fill:"none",stroke:t.color??gc(i.style.stroke),strokeWidth:v,opacity:(i.style.opacity??1)*(t.opacity??1),clipPath:`url(#${A[o]})`},`area-${e}-stroke-band-${o}`)):m?function(t,e,o,n){if(2>t.length||e.length!==t.length||0===o.length)return[];const i=[],r=(t,e,o)=>{const n=i[i.length-1];n?.color===t?n.path.push(o):i.push({color:t,path:[e,o]})};for(let i=1;t.length>i;i++){const[s,a]=t[i-1],[l,c]=t[i],u=e[i-1],d=e[i]-u,h=[0,...0===d?[]:o.map(({value:t})=>(t-u)/d).filter(t=>t>0&&1>t&&Number.isFinite(t)).sort((t,e)=>t-e).filter((t,e,o)=>0===e||t!==o[e-1]),1];for(let t=1;h.length>t;t++){const e=h[t-1],i=h[t];r(dc(u+d*((e+i)/2),o,n),[s+(l-s)*e,a+(c-a)*e],[s+(l-s)*i,a+(c-a)*i])}}return i}(i.topPath,i.rawValues,i.colorThresholds,gc(i.style.stroke)).map((t,o)=>Wc("path",{d:"M"+t.path.map(([t,e])=>`${t},${e}`).join("L"),fill:"none",stroke:t.color,strokeWidth:v,opacity:i.style.opacity},`area-${e}-threshold-${o}`)):Wc("path",{d:p,fill:"none",stroke:b?`url(#${y})`:gc(i.style.stroke),strokeWidth:v,opacity:i.style.opacity}):null;if(i.clipRect){const t=`${o?o+"-":""}area-clip-${e}`;return Bc("g",{children:[Bc("defs",{children:[u,!u&&l,b,S,Wc("clipPath",{id:t,children:Wc("rect",{x:i.clipRect.x,y:i.clipRect.y,width:i.clipRect.width,height:i.clipRect.height})})]}),Bc("g",{clipPath:`url(#${t})`,children:[Wc("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]})]},"area-"+e)}return Bc(lc.Fragment,{children:[(u||l||b||S)&&Bc("defs",{children:[u,!u&&l,b,S]}),Wc("path",{d:s,fill:d,fillOpacity:h,opacity:u?i.style.opacity:void 0,stroke:"none"}),M,g]},"area-"+e)}case"point":{const n=t,i=`${o?o+"-":""}point-${e}-hatch`,r=ot(n.style.fill)?et(n.style.fill,i):void 0;return Bc(lc.Fragment,{children:[r&&Wc("defs",{children:r}),Wc("circle",{cx:n.x,cy:n.y,r:n.r,fill:r?`url(#${i})`:gc(n.style.fill),opacity:n.style.opacity??n.style.fillOpacity??.8,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"point-"+e)}case"symbol":return bc(t,e);case"glyph":return mc(t,t.x,t.y,`${o??""}glyph-${t.pointId??e}`);case"rect":{const n=t,i=`${o?o+"-":""}xyrect-${e}-hatch`,r=ot(n.style.fill)?et(n.style.fill,i):void 0;return Bc(lc.Fragment,{children:[r&&Wc("defs",{children:r}),Wc("rect",{x:n.x,y:n.y,width:n.w,height:n.h,fill:r?`url(#${i})`:gc(n.style.fill),opacity:n.style.opacity,stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},"rect-"+e)}case"heatcell":{const o=t,n={x:o.x,y:o.y,width:o.w,height:o.h,fill:o.fill,stroke:o.style?.stroke,strokeWidth:o.style?.strokeWidth,...null!=o.style?.opacity&&{opacity:o.style.opacity}};if(o.showValues&&null!=o.value&&o.w>=20&&o.h>=20){const t=o.valueFormat?o.valueFormat(o.value):Number.isInteger(o.value)?o.value+"":100>Math.abs(o.value)?1>Math.abs(o.value)?o.value.toPrecision(3):o.value.toFixed(1):o.value.toFixed(0),[i,r,s]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(o.fill),a=.299*i+.587*r+.114*s>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(o.w,o.h)));return Bc("g",{children:[Wc("rect",{...n}),Wc("text",{x:o.x+o.w/2,y:o.y+o.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:a,fontSize:l+"px",children:t})]},"heatcell-"+e)}return Wc("rect",{...n},"heatcell-"+e)}case"candlestick":{const o=t;if(o.isRange){const t=o.dotRadius??Math.max(2,o.bodyWidth/2);return Bc("g",{children:[Wc("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),Wc("circle",{cx:o.x,cy:o.highY,r:t,fill:o.wickColor}),Wc("circle",{cx:o.x,cy:o.lowY,r:t,fill:o.wickColor})]},"candle-"+e)}const n=Math.min(o.openY,o.closeY),i=Math.max(Math.abs(o.openY-o.closeY),1),r=o.isUp?o.upColor:o.downColor;return Bc("g",{children:[Wc("line",{x1:o.x,y1:o.highY,x2:o.x,y2:o.lowY,stroke:o.wickColor,strokeWidth:o.wickWidth}),Wc("rect",{x:o.x-o.bodyWidth/2,y:n,width:o.bodyWidth,height:i,fill:r,stroke:r,strokeWidth:1})]},"candle-"+e)}default:return null}}(t,e,o,n);return"area"===t.type?i:Ac(i,t,"xy-cursor-"+e)}var Xc=new Set;function Gc(t){const{node:e,index:o,renderMode:n,fallback:i}=t,r=function(t,e){const o="function"==typeof t?t(e.datum??null,e):t;return(n=o)&&"object"==typeof n&&"string"==typeof n.id&&"function"==typeof n.cacheKey&&"function"==typeof n.drawCanvas&&"function"==typeof n.renderStaticSVG?o:void 0;var n}(n,e);if(!r)return{element:i(),renderedByBackend:!1};const s=r.renderStaticSVG({node:e,style:e.style??{},key:`${r.id}-${o}`});return null!=s?{element:Ac(s,e,`${r.id}-${o}-cursor`),renderedByBackend:!0}:(function(t,e){if("undefined"!=typeof process&&"production"===process.env?.NODE_ENV)return;const o=`${t}:${e}`;Xc.has(o)||(Xc.add(o),console.warn(`[Semiotic] Render backend "${t}" does not support scene node "${e}"; using the built-in renderer.`))}(r.id,e.type??"unknown"),{element:i(),renderedByBackend:!1})}function Vc(t){const e=[];return t.nodes.forEach((o,n)=>{const i=Gc({node:o,index:n,renderMode:t.renderMode,fallback:()=>t.fallback(o,n)});null!=i.element&&!1!==i.element&&e.push({node:o,index:n,...i})}),e}import{scaleOrdinal as Hc}from"d3-scale";import{jsx as qc,jsxs as Uc}from"react/jsx-runtime";function Kc(t,e,o){if(e&&"object"==typeof e&&!Array.isArray(e)){const t=e;return e=>ne(t,e)??"#999"}const n=Array.isArray(e)?e:o.colors.categorical.length>0?o.colors.categorical:B;return Hc().domain(t).range(n)}function Zc(t,e,o){if(0===t.length)return;const n=Kc(t,e,o);return{legendGroups:[{label:"",type:"fill",items:t.map(t=>({label:t})),styleFn:t=>({fill:n(t.label)})}]}}function Qc(t){return"left"===t?"start":"right"===t?"end":t??"start"}function Jc(t){return Number(t.typography.legendSize??t.typography.labelSize??t.typography.tickSize)||11}function tu(t){return t.typography.legendFontFamily??t.typography.fontFamily}function eu(t){return t.typography.legendFontWeight}function ou(t,e,o,n){const i=Jc(n);return e+o+Math.ceil(t.length*i*.58)}function nu(t){const{categories:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,itemGap:c,rowHeight:u}=lo(s),d=a+l,h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right),f=e.map(t=>ou(t,a,l,o));if(h){const t=Math.max(a,s?.maxWidth??p),o=[];let n=0,i=0;f.forEach((e,r)=>{const s=0===i?e:i+c+e;i>0&&s>t?(o.push({start:n,end:r,width:i}),n=r,i=e):i=s}),e.length>0&&o.push({start:n,end:e.length,width:i});const r=Qc(s?.align),l=[];return o.forEach((o,n)=>{let i="center"===r?Math.max(0,(t-o.width)/2):"end"===r?Math.max(0,t-o.width):0;for(let t=o.start;o.end>t;t++)l.push({category:e[t],width:f[t],x:i,y:n*u}),i+=f[t]+c}),{items:l,width:Math.max(0,...o.map(t=>t.width)),height:o.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}const g=Math.max(0,...f);return{items:e.map((t,e)=>({category:t,width:f[e],x:0,y:e*u})),width:g,height:e.length*u,swatchSize:a,labelOffset:d,swatchRadius:0}}function iu(t,e){if(!e||!t||0===t.length)return[];const o="function"==typeof e?e:t=>t[e],n=new Set;for(const e of t){const t=o(e);null!=t&&n.add(t+"")}return Array.from(n)}import{jsx as ru,jsxs as su}from"react/jsx-runtime";function au(t,e=120,o=8){if(!t)return[];const n=Math.max(1,Math.floor(e/o)),i=t.split(/\s+/),r=[];let s="";for(const t of i)s&&s.length+1+t.length>n?(r.push(s),s=t):s=s?`${s} ${t}`:t;return s&&r.push(s),r}function lu(t,e,o,n){return"curly"===t?n?`M0,0 C${.6*o},0 ${.4*o},${e/2} ${o},${e/2} C${.4*o},${e/2} ${.6*o},${e} 0,${e}`:`M0,0 C0,${.6*o} ${e/2},${.4*o} ${e/2},${o} C${e/2},${.4*o} ${e},${.6*o} ${e},0`:n?`M0,0 L${o},0 L${o},${e} L0,${e}`:`M0,0 L0,${o} L${e},${o} L${e},0`}function cu(t,e,o,n){if(!t)return ru("g",{className:"annotation-note"});const{label:i,title:r,orientation:s,align:a,wrap:l=120,noWrap:c}=t;if(!i&&!r)return ru("g",{className:"annotation-note"});let u=s;u||(u=Math.abs(e)>Math.abs(o)?"leftRight":"topBottom");let d=a;d&&"dynamic"!==d||(d="topBottom"===u?0>e?"right":"left":0>o?"bottom":"top");let h="start";"topBottom"===u?"right"===d?h="end":"middle"===d&&(h="middle"):h=0>e?"end":"start";const p=16,f=r?c?[r]:au(r,l):[],g=i?c?[i]:au(i,l):[],y="leftRight"===u?"end"===h?-4:4:0;let m=0;const x=[],b=n||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";t.useHTML||t.html?x.push(ru("foreignObject",{className:"annotation-note-html",x:"end"===h?y-l:"middle"===h?y-l/2:y,y:-16,width:l,height:Math.max(p,(f.length+g.length)*p+(r&&i?2:0))+p,style:{overflow:"visible"},children:su("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:b,fontSize:"12px",lineHeight:"16px",overflow:"visible",textAlign:"end"===h?"right":"middle"===h?"center":"left",whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[r&&ru("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:r}),i&&ru("div",{className:"annotation-note-label",children:i})]})},"annotation-note-html")):(f.length>0&&(x.push(ru("text",{className:"annotation-note-title",fill:b,textAnchor:h,fontWeight:"bold",children:f.map((t,e)=>ru("tspan",{x:y,dy:0===e?0:p,children:t},e))},"annotation-note-title")),m=f.length*p),g.length>0&&x.push(ru("text",{className:"annotation-note-label",fill:b,textAnchor:h,y:m,children:g.map((t,e)=>ru("tspan",{x:y,dy:0===e?0:p,children:t},e))},"annotation-note-label")));let v=null;if((r||i)&&(0!==e||0!==o))if("topBottom"===u){const t=Math.min(l,120);let e=0,o=t;"end"===h?(e=-t,o=0):"middle"===h&&(e=-t/2,o=t/2),v=ru("line",{className:"note-line",x1:e,x2:o,y1:0,y2:0,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}else{const t=(f.length+g.length)*p+(g.length>0?p:0);let e=0,o=t;"bottom"===d?(e=-t,o=0):"middle"===d&&(e=-t/2,o=t/2),v=ru("line",{className:"note-line",x1:0,x2:0,y1:e,y2:o,stroke:n||"var(--semiotic-text-secondary, currentColor)"})}const w=Math.max(0,f.length+g.length-1)*p;let k=0;return"topBottom"===u?k=0>o?-(w+2):18:"leftRight"===u&&(k="middle"===d?-(w+p+(g.length>0&&f.length>0?2:0))/2+8:"bottom"===d||0>o?-(w+2):18),su("g",{className:"annotation-note",transform:`translate(${e},${o})`,children:[ru("g",{className:"annotation-note-content",transform:0!==k?`translate(0,${k})`:void 0,children:x}),v]})}function uu(t,e,o,n,i){const r=[];switch(t){case"callout-circle":{const t=(e?.radius||0)+(e?.radiusPadding||0);t>0&&r.push(ru("circle",{r:t,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-circle"));break}case"callout-rect":{const t=e?.width||0,n=e?.height||0;(t>0||n>0)&&r.push(ru("rect",{width:t,height:n,fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"subject-rect"));break}case"callout-custom":e?.custom&&r.push(...Array.isArray(e.custom)?e.custom:[e.custom]);break;case"xy-threshold":{const t=n||0,s=i||0;if(void 0!==e?.x){const n=(e.x||0)-t;r.push(ru("line",{x1:n,y1:(e.y1||0)-s,x2:n,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else if(void 0!==e?.y){const n=(e.y||0)-s;r.push(ru("line",{x1:(e.x1||0)-t,y1:n,x2:(e.x2||0)-t,y2:n,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"))}else void 0!==e?.x1||void 0!==e?.x2?r.push(ru("line",{x1:(e.x1||0)-t,y1:0,x2:(e.x2||0)-t,y2:0,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line")):void 0===e?.y1&&void 0===e?.y2||r.push(ru("line",{x1:0,y1:(e.y1||0)-s,x2:0,y2:(e.y2||0)-s,stroke:o||"var(--semiotic-text-secondary, currentColor)",strokeDasharray:"5,5"},"threshold-line"));break}case"bracket":{const t=e?.type||"curly",n=e?.width??e?.height;void 0!==n&&r.push(ru("path",{d:lu(t,n,e?.depth||30,void 0===e?.width),fill:"none",stroke:o||"var(--semiotic-text-secondary, currentColor)"},"bracket-path"));break}}return ru("g",{className:"annotation-subject",children:r})}function du(t,e,o,n,i,r){const s=[];let a=0,l=0;if("callout-circle"!==i&&"label"!==i||!r?.radius){if("callout-rect"===i&&r){const o=r.width||0,n=r.height||0;if(o>0||n>0){const i=o/2,r=n/2,s=t-i,c=e-r;if(0!==s||0!==c){const t=Math.abs(s),e=Math.abs(c),u=o/2,d=n/2,h=t*d>e*u?u/t:d/e;a=i+s*h,l=r+c*h}}}else if("bracket"===i&&r){const t=r.width,e=r.height,o=r.depth||30;void 0!==t?(a=t/2,l=o):void 0!==e&&(a=o,l=e/2)}}else{const o=(r.radius||0)+(r.radiusPadding||0);if(o>0&&(0!==t||0!==e)){const n=Math.atan2(e,t);a=Math.cos(n)*o,l=Math.sin(n)*o}}const c=Math.sqrt((t-a)**2+(e-l)**2);if(c>.5){const i=n||"var(--semiotic-text-secondary, currentColor)",r="curve"===o?.type;let u=Math.atan2(e-l,t-a);if(r){const n=(a+t)/2,r=(l+e)/2,d=-(e-l)/c,h=(t-a)/c,p=(o?.curve??.25)*c,f=n+d*p,g=r+h*p;s.push(ru("path",{className:"connector-curve",d:`M${a},${l}Q${f},${g} ${t},${e}`,fill:"none",stroke:i},"connector-line")),u=Math.atan2(g-l,f-a)}else s.push(ru("line",{x1:a,y1:l,x2:t,y2:e,stroke:i},"connector-line"));if("arrow"===o?.end){const t=10,e=16/180*Math.PI;s.push(ru("path",{d:`M${a},${l}L${a+t*Math.cos(u+e)},${l+t*Math.sin(u+e)}L${a+t*Math.cos(u-e)},${l+t*Math.sin(u-e)}Z`,fill:i,stroke:"none"},"connector-arrow"))}}return ru("g",{className:"annotation-connector",children:s})}function hu(t){const{x:e=0,y:o=0,dx:n,dy:i,nx:r,ny:s,note:a,connector:l,subject:c,type:u,color:d,className:h,disable:p,opacity:f,strokeDasharray:g,events:y={},"data-testid":m}=t,x=Array.isArray(e)?e[0]??0:e,b=Array.isArray(o)?o[0]??0:o,v=new Set(Array.isArray(p)?p:[]);let w=n||0,k=i||0;null!=r&&(w=r-x),null!=s&&(k=s-b);const A="string"==typeof u?u:"label";if("bracket"===A&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;const t=c.depth||30;k=t+(0>t?-5:5)}else if(void 0!==c.height){const t=c.depth||30;w=t+(0>t?-5:5),k=c.height/2}return su("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=f&&{opacity:f},...g&&{strokeDasharray:g},...y,children:[!v.has("connector")&&du(w,k,l,d,A,c),!v.has("subject")&&uu(A,c,d,x,b),!v.has("note")&&cu(a,w,k,d)]})}function pu(t){const{noteData:e}=t,{screenCoordinates:o}=e,n="string"==typeof e.type?e.type:"label",i=e.eventListeners||e.events||{};if(e.coordinates&&o){const t=e.nx||o[0][0]+(e.dx??0),i=e.ny||o[0][1]+(e.dy??0),r=o.map((o,r)=>{const s=Object.assign({},e,{note:0===r?e.note:{label:""},x:o[0],y:o[1],nx:t,ny:i});return ru(hu,{"data-testid":"semiotic-annotation",...s,type:n},"multi-annotation-"+r)});return ru("g",{children:r})}const r=e.note||{title:"none",label:e.label},s=`${r.label}-${r.title}-${e.i}`;return ru(hu,{"data-testid":"semiotic-annotation",events:i,...e,type:n},s)}import{jsx as fu}from"react/jsx-runtime";var gu={secondary:0,primary:3};function yu(t){return!0===t?._annotationDeferred}function mu(t){return"blended"===t?.cohesion||"layer"===t?.cohesion?t.cohesion:null}function xu(t){const e=t?.provenance?.confidence;return"number"==typeof e&&Number.isFinite(e)?Math.max(0,Math.min(1,e)):null}function bu(t){return Math.max(.72,.95-.06*t)}function vu(t){const e=t.map((t,e)=>{return{p:t,i:e,emphasis:(o=t.annotation,"primary"===o?.emphasis||"secondary"===o?.emphasis?o.emphasis:null),confidence:xu(t.annotation),readingOrder:null,rank:1};var o}),o=e.some(t=>null!=t.emphasis||null!=t.confidence),n=t.some(t=>yu(t.annotation)),i=t.some(t=>null!=mu(t.annotation)),r=t.some(t=>"layer"===mu(t.annotation));if(!o&&!n&&!i)return t.map(t=>t.node);const s=e.filter(t=>null==t.emphasis&&null!=t.confidence).slice().sort((t,e)=>(e.confidence??0)-(t.confidence??0)||t.i-e.i);s.forEach((t,e)=>{t.readingOrder=e,t.rank=2-e/Math.max(1,s.length)});for(const t of e)t.emphasis&&(t.rank=gu[t.emphasis]);const a=e.sort((t,e)=>t.rank-e.rank||t.i-e.i).map(t=>{const{p:e,i:o,emphasis:n,readingOrder:i}=t,r=yu(e.annotation);let s=e.node;if("primary"===n||"secondary"===n||null!=i){const t=null==n&&null!=i;s=fu("g",{className:t?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+n,..."secondary"===n?{opacity:.6,fontSize:"0.88em"}:{},...t?{opacity:bu(i),"data-annotation-reading-order":i}:{},children:e.node},"annotation-emphasis-"+o)}const a=mu(e.annotation);return a&&(s=fu("g",{className:"annotation-cohesion--"+a,children:s},"annotation-cohesion-"+o)),r&&(s=fu("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:s},"annotation-deferred-"+o)),s});return n&&a.unshift(fu("style",{children:".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}"},"annotation-disclosure-style")),r&&a.unshift(fu("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),a}import{jsx as wu,jsxs as ku}from"react/jsx-runtime";var Au="var(--semiotic-bg, #ffffff)";function Su(t){const{x:e,y:o,text:n,fill:i,fontSize:r=12,fontWeight:s,fontFamily:a,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=t,h=function(t){return void 0===t||!0===t||"halo"===t?{type:"halo"}:!1===t||"none"===t?null:"box"===t?{type:"box"}:{type:t.type??"halo",...t}}(u),p=t=>wu("text",{x:e,y:o,textAnchor:l,dominantBaseline:c,fill:i,fontSize:r,fontWeight:s,fontFamily:a,className:d,...t?{style:{stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:"stroke"}}:{},children:n});if(!h)return p();if("halo"===h.type)return p({stroke:h.fill??Au,strokeWidth:h.haloWidth??3});const f=h.padding??{x:6,y:3},g="number"==typeof f?f:f.x,y="number"==typeof f?f:f.y,m=function(t,e){return(t+"").length*e*.6}(n,r),x=r+2*y;let b,v;return b="middle"===l?e-m/2-g:"end"===l?e-m-g:e-g,v="middle"===c||"central"===c?o-x/2:"hanging"===c||"text-before-edge"===c?o-y:o-.8*r-y,ku("g",{className:d,children:[wu("rect",{x:b,y:v,width:m+2*g,height:x,rx:h.radius??3,ry:h.radius??3,fill:h.fill??Au,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),p()]})}function Mu(t,e,o,n){const i=ht(t.fill??t.color,e,n);return ct(t.gradient,e,o,"string"==typeof t.fill&&t.fill?t.fill:"string"==typeof t.color&&t.color?t.color:n)??i}var _u=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Pu(t,e,o,n){const i=function(t,e,o){const n=t.position,i="string"==typeof n&&_u.has(n)?n:"bottom-left",r=i.endsWith("left")?"left":i.endsWith("right")?"right":"center",s=i.startsWith("top")?"top":i.startsWith("bottom")?"bottom":"middle",a="top"===s?0:"bottom"===s?o:o/2;return{x:("left"===r?0:"right"===r?e:e/2)+("number"==typeof t.dx&&Number.isFinite(t.dx)?t.dx:0),y:a+("number"==typeof t.dy&&Number.isFinite(t.dy)?t.dy:0),textAnchor:"start"===t.textAnchor||"middle"===t.textAnchor||"end"===t.textAnchor?t.textAnchor:"left"===r?"start":"right"===r?"end":"middle",dominantBaseline:"auto"===t.dominantBaseline||"middle"===t.dominantBaseline||"hanging"===t.dominantBaseline?t.dominantBaseline:"top"===s?"hanging":"bottom"===s?"auto":"middle"}}(t,e,o);return{...i,fill:t.fill??t.color??n.fill,fontSize:t.fontSize??n.fontSize,fontFamily:t.fontFamily??n.fontFamily,fontWeight:t.fontWeight,fontStyle:t.fontStyle,letterSpacing:t.letterSpacing,opacity:t.opacity,className:t.className,style:{pointerEvents:"none"}}}import{jsx as Lu}from"react/jsx-runtime";var $u={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Ru({annotation:t,width:e,height:o,defaults:n=$u}){const i=t.label??t.text;return null==i?null:Lu("text",{...Pu(t,e,o,n),children:i})}import{packEnclose as Cu}from"d3-hierarchy";import{area as Tu,curveBasis as Ou,curveCardinal as Iu,curveCatmullRom as zu,curveLinear as Fu,curveMonotoneX as Nu,curveMonotoneY as Eu,curveStep as Du,curveStepAfter as Wu,curveStepBefore as Bu}from"d3-shape";import*as ju from"react";function Yu(t,e={}){const o=K(t);return{"data-semiotic-annotation-widget":"",...o?{"data-semiotic-annotation-id":o}:{},onClickCapture(n){const i=function(t){const e=t.nativeEvent;return"touch"===e.pointerType?"touch":0===e.detail?"keyboard":"pointer"}(n);e.onAnnotationActivate?.({annotation:t,annotationId:o,chartId:e.chartId,inputType:i}),o&&e.onObservation&&e.onObservation({type:"annotation-activate",annotationId:o,inputType:i,timestamp:Date.now(),chartType:e.chartType??"unknown",chartId:e.chartId})}}}import{jsx as Xu,jsxs as Gu}from"react/jsx-runtime";var Vu={linear:Fu,monotoneX:Nu,monotoneY:Eu,step:Du,stepAfter:Wu,stepBefore:Bu,basis:Ou,cardinal:Iu,catmullRom:zu};import{jsx as Hu,jsxs as qu}from"react/jsx-runtime";var Uu=16;function Ku(t,e){return t.color||e.colors.annotation||e.colors.text}function Zu(t,e,o){const n=t.labelBackground,i=e.colors.background,r=i&&"transparent"!==i?i:e.colors.surface||i;return void 0===n?"none"===o?"none":{type:"halo",fill:r}:!1===n||"none"===n?"none":!0===n||"halo"===n?{type:"halo",fill:r}:"box"===n?{type:"box",fill:r}:{fill:r,...n}}function Qu(t,e,o){return null!=t.x&&e.x?e.x(t.x):o&&null!=t[o]&&e.x?e.x(t[o]):"number"==typeof t.x?t.x:null}function Ju(t,e,o){return null!=t.y&&e.y?e.y(t.y):o&&null!=t[o]&&e.y?e.y(t[o]):"number"==typeof t.y?t.y:null}function td(t){const{annotations:e}=t;if(!e||0===e.length)return t.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;const o=gt(e),n=t.scales.geoProjection,r=n?o.map(t=>{if(!Array.isArray(t.coordinates)||2>t.coordinates.length)return t;const e=n([Number(t.coordinates[0]),Number(t.coordinates[1])]);return e?{...t,x:e[0],y:e[1]}:t}):o,s=!!n&&!t.scales.x&&!t.scales.y,a=t=>Number(t),l=t.scales.x??(s?a:void 0),c=t.scales.y??(s?a:void 0),u=t.projection?"horizontal"===t.projection?"horizontal":"vertical":void 0,d={scales:{..."vertical"===t.projection?{x:t.scales.o??l,y:t.scales.r??c,time:t.scales.o??l,value:t.scales.r??c,o:t.scales.o}:"horizontal"===t.projection?{x:t.scales.r??l,y:t.scales.o??c,time:t.scales.r??l,value:t.scales.o??c,o:t.scales.o}:{x:l,y:c,time:l,value:c,o:t.scales.o},...n?{geoProjection:n}:{}},width:t.layout.width,height:t.layout.height,xAccessor:t.xAccessor,yAccessor:t.yAccessor,data:t.annotationData,pointNodes:t.pointNodes,frameType:t.frameType??(t.projection?"ordinal":n||t.scales.x||t.scales.y?"xy":"network"),...u?{projection:u}:{}},h=t.autoPlaceAnnotations?i({annotations:r,context:d,..."object"==typeof t.autoPlaceAnnotations?t.autoPlaceAnnotations:{}}):r,p=function(t,e,o,n){const i=[];return t.forEach((t,r)=>{let s;if(o){const i=o(t,r,n);s=null!=i?i:e(t,r,n)}else s=e(t,r,n);s&&i.push({node:s,annotation:t})}),{nodes:vu(i),renderedAnnotations:i.map(t=>t.annotation)}}(h,(e,o,n)=>function(t,e,o,n){const{scales:i,layout:r,theme:s,xAccessor:a,yAccessor:l}=o;switch(t.type){case"frame-text":return Hu(Ru,{annotation:t,width:r.width,height:r.height,defaults:{fill:s.colors.text,fontSize:11,fontFamily:s.typography.fontFamily}},"ann-frame-text-"+e);case"y-threshold":{const n=t.value??t.y;if(null==n)return null;const a=Ku(t,s),l=t.label,c=t.labelPosition||"right",u=t.strokeDasharray||"6,4",d=t.strokeWidth??1.5;if("horizontal"===o.projection&&i.r){const o=i.r(n);return null==o?null:qu("g",{opacity:t.opacity,children:[Hu("line",{x1:o,y1:0,x2:o,y2:r.height,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Hu(Su,{x:o+4,y:Uu,textAnchor:"start",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Zu(t,s,"halo")})]},"ann-ythresh-"+e)}const h=i.y?i.y(n):i.r?i.r(n):null;return null==h?null:qu("g",{children:[Hu("line",{x1:0,y1:h,x2:r.width,y2:h,stroke:a,strokeWidth:d,strokeDasharray:u}),l&&Hu(Su,{x:"left"===c?4:"center"===c?r.width/2:r.width-4,y:20>h?Math.min(r.height-4,h+Uu):h-6,textAnchor:"left"===c?"start":"center"===c?"middle":"end",fontSize:s.typography.tickSize,fill:a,fontFamily:s.typography.fontFamily,text:l,background:Zu(t,s,"halo")})]},"ann-ythresh-"+e)}case"x-threshold":{const n=t.value??t.x;if(null==n)return null;const a="horizontal"===o.projection&&i.r?i.r(n):i.x?i.x(n):null;if(null==a)return null;const l=Ku(t,s),c=t.label,u=t.labelPosition||"top";return qu("g",{opacity:t.opacity,children:[Hu("line",{x1:a,y1:0,x2:a,y2:r.height,stroke:l,strokeWidth:t.strokeWidth??1.5,strokeDasharray:t.strokeDasharray||"6,4"}),c&&Hu(Su,{x:a>.6*r.width?a-4:a+4,y:"bottom"===u?r.height-4:"center"===u?r.height/2:Uu,textAnchor:a>.6*r.width?"end":"start",fontSize:s.typography.tickSize,fill:l,fontFamily:s.typography.fontFamily,text:c,background:Zu(t,s,"halo")})]},"ann-xthresh-"+e)}case"band":{const o=i.y?.domain?.(),n=t.y0??o?.[0],a=t.y1??o?.[1],l=null!=n&&i.y?i.y(n):null,c=null!=a&&i.y?i.y(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=Mu(t,"ssr-band-"+e,"vertical",Ku(t,s)),p=t.fillOpacity??.1;return qu("g",{opacity:t.opacity,children:[h.def&&Hu("defs",{children:h.def}),Hu("rect",{x:0,y:u,width:r.width,height:d,fill:h.fill,fillOpacity:p}),t.label&&Hu(Su,{x:r.width-4,y:Math.max(u,0)+Uu,textAnchor:"end",fontSize:s.typography.tickSize,fill:t.color||Ku(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Zu(t,s,"halo")})]},"ann-band-"+e)}case"x-band":{const o=i.x?.domain?.(),n=t.x0??o?.[0],a=t.x1??o?.[1],l=null!=n&&i.x?i.x(n):null,c=null!=a&&i.x?i.x(a):null;if(null==l||null==c)return null;const u=Math.min(l,c),d=Math.abs(c-l),h=Mu(t,"ssr-xband-"+e,"horizontal",Ku(t,s)),p=t.fillOpacity??.1;return qu("g",{opacity:t.opacity,children:[h.def&&Hu("defs",{children:h.def}),Hu("rect",{x:u,y:0,width:d,height:r.height,fill:h.fill,fillOpacity:p}),t.label&&Hu(Su,{x:u+4,y:Uu,textAnchor:"start",fontSize:s.typography.tickSize,fill:t.color||s.colors.primary||Ku(t,s),fontFamily:s.typography.fontFamily,fontWeight:"bold",text:t.label,background:Zu(t,s,"halo")})]},"ann-xband-"+e)}case"category-highlight":{if(null==t.category||!i.o)return null;const n=i.o(t.category+"");if(null==n)return null;const a=i.o.bandwidth?i.o.bandwidth():40,l=Ku(t,s),c=t.opacity??.1,u=t.label;return qu("g","horizontal"===o.projection?{children:[Hu("rect",{x:0,y:n,width:r.width,height:a,fill:l,opacity:c}),u&&Hu(Su,{x:12,y:n+a/2,dominantBaseline:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Zu(t,s,"none")})]}:{children:[Hu("rect",{x:n,y:0,width:a,height:r.height,fill:l,opacity:c}),u&&Hu(Su,{x:n+a/2,y:Uu,textAnchor:"middle",fill:l,fontSize:s.typography.tickSize,fontWeight:"bold",fontFamily:s.typography.fontFamily,text:u,background:Zu(t,s,"none")})]},"ann-cathighlight-"+e)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{const o=function(t,e,o,n){if(Array.isArray(t.coordinates)&&t.coordinates.length>=2&&e.geoProjection){const o=e.geoProjection([t.coordinates[0],t.coordinates[1]]);if(o)return{x:o[0],y:o[1]}}return{x:Qu(t,e,o),y:Ju(t,e,n)}}(t,i,a,l),r=null==o.x||null==o.y?F(t,e,n):null,c=o.x??r?.x??null,u=o.y??r?.y??null;if(null==c||null==u)return null;const d="text"===t.type,h=t.dx??(d?0:30),p=t.dy??(d?0:-30),f=t.color||s.colors.text;if(!d){const o="callout"===t.type?"callout-circle":t.type,n="callout-circle"===o?{radius:t.radius??12,radiusPadding:t.radiusPadding}:"callout-rect"===o?{width:t.width,height:t.height}:void 0;return Hu(pu,{noteData:{x:c,y:u,dx:h,dy:p,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:o,...n?{subject:n}:{},connector:t.connector||{end:"arrow"},color:f,disable:t.disable,opacity:t.opacity,strokeDasharray:t.strokeDasharray,className:t.className}},"ann-label-"+e)}return Hu("g",{children:Hu("text",{x:c+h,y:u+p,textAnchor:t.textAnchor||"start",fontSize:t.fontSize||s.typography.labelSize,fill:f,fontFamily:s.typography.fontFamily,fontWeight:t.fontWeight,opacity:t.opacity,strokeDasharray:t.strokeDasharray,children:t.label||t.title})},"ann-label-"+e)}default:return null}}(e,o,t,n)??function(t,e,o){switch(t.type){case"enclose":{const n=(t.coordinates||[]).map(t=>({x:E({...t,type:"point"},o),y:D({...t,type:"point"},o),r:1})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=Cu(n),r=t.padding||10;return Gu("g",{children:[Xu("circle",{cx:i.x,cy:i.y,r:i.r+r,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Xu(Su,{x:i.x,y:i.y-i.r-r-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"rect-enclose":{const n=(t.coordinates||[]).map(t=>({x:E({...t,type:"point"},o),y:D({...t,type:"point"},o)})).filter(t=>null!=t.x&&null!=t.y);if(2>n.length)return null;const i=t.padding||10,[r,s]=St(n.map(t=>t.x)),[a,l]=St(n.map(t=>t.y)),c=r-i,u=s+i,d=a-i;return Gu("g",{children:[Xu("rect",{x:c,y:d,width:u-c,height:l+i-d,fill:t.fill||"none",fillOpacity:t.fillOpacity??.1,stroke:t.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),t.label&&Xu(Su,{x:(c+u)/2,y:d-4,textAnchor:"middle",fill:t.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:t.label,background:t.labelBackground??"none"})]},"ann-"+e)}case"highlight":{const n=o.data||[],i="function"==typeof t.filter?n.filter(t.filter):t.field&&null!=t.value?n.filter(e=>e[t.field]===t.value):[],r={stroke:t.color||"#f97316",strokeWidth:2,fill:"none"};return Xu("g",{children:i.map((e,n)=>{const i=E(e,o),s=D(e,o);if(null==i||null==s)return null;const a="function"==typeof t.r?t.r(e):t.r||6,l="function"==typeof t.style?t.style(e):t.style||r;return Xu("circle",{cx:i,cy:s,r:a,...l},"hl-"+n)})},"ann-"+e)}case"bracket":{const n=E(t,o),i=D(t,o);return Xu(pu,{noteData:{x:n??0,y:i??0,dx:t.dx||0,dy:t.dy||0,note:{label:t.label,title:t.title,wrap:t.wrap||120},type:"bracket",subject:{type:t.bracketType||"curly",width:t.width,height:t.height,depth:t.depth||30},color:t.color}},"ann-"+e)}case"trend":{const n=o.data||[];if(2>n.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s="ordinal"===o.frameType,a="horizontal"===o.projection,l=s?i:null,c=s?r:null;let u;const d=[],h=new Map;if(s&&l&&c){for(const t of n){const e=t[l];if(null==e)continue;const o=e+"";h.has(o)||(h.set(o,d.length),d.push(o))}u=n.map(t=>{const e=t[l],o=t[c];if(null==e||null==o)return null;const n=h.get(e+"");return null!=n?[n,+o]:null}).filter(t=>null!==t)}else u=n.map(t=>[t[i],t[r]]).filter(t=>null!=t[0]&&null!=t[1]);if(2>u.length)return null;const p=o.scales?.x??o.scales?.time,f=o.scales?.y??o.scales?.value;if(!p||!f)return null;const g=t=>e=>{const o=Math.max(0,Math.floor(e)),n=Math.min(d.length-1,o+1),i=e-o,r=t(d[o]);return r+(t(d[n])-r)*i},y=p,m=f;let x;if(s)if(a){const t=g(m);x=(e,o)=>[y(o),t(e)]}else{const t=g(y);x=(e,o)=>[t(e),m(o)]}else x=(t,e)=>[y(t),m(e)];const b=t.method||"linear",v="loess"===b?function(t,e=.3){const o=t.length;if(2>o)return t.slice();const n=t.slice().sort((t,e)=>t[0]-e[0]),i=n.map(t=>t[0]),r=n.map(t=>t[1]),s=Math.max(2,Math.ceil(e*o)),a=[];for(let t=0;o>t;t++){const e=i[t],n=i.map(t=>Math.abs(t-e)),l=n.slice().sort((t,e)=>t-e)[Math.min(s-1,o-1)]||1,c=[];for(let t=0;o>t;t++){const e=0===l?0:n[t]/l;c[t]=1>e?Math.pow(1-Math.pow(e,3),3):0}let u=0,d=0,h=0,p=0,f=0;for(let t=0;o>t;t++){const e=c[t];0!==e&&(u+=e,d+=e*i[t],h+=e*r[t],p+=e*i[t]*i[t],f+=e*i[t]*r[t])}if(0===u){a.push([e,r[t]]);continue}const g=u*p-d*d;if(1e-12>Math.abs(g))a.push([e,h/u]);else{const t=(u*f-d*h)/g;a.push([e,(h-t*d)/u+t*e])}}return a}(u,t.bandwidth??.3):("polynomial"===b?ve(u,t.order||2):function(t){const e=[0,0,0,0];let o=0;for(const[n,i]of t)null!==i&&(o++,e[0]+=n,e[1]+=i,e[2]+=n*n,e[3]+=n*i);const n=o*e[2]-e[0]*e[0],i=0===n?0:be((o*e[3]-e[0]*e[1])/n),r=be(e[1]/o-i*e[0]/o);return{points:t.map(([t])=>[be(t),be(i*t+r)]),equation:[i,r]}}(u)).points,w=v.map(([t,e])=>{const[o,n]=x(t,e);return`${o},${n}`}).join(" "),k=t.color||"#6366f1",A=v[v.length-1],[S,M]=x(A[0],A[1]);return Gu("g",{children:[Xu("polyline",{points:w,fill:"none",stroke:k,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray||"6,3"}),t.label&&Xu("text",{x:S+4,y:M-4,fill:k,fontSize:11,children:t.label})]},"ann-"+e)}case"envelope":{const n=o.data||[];if(2>n.length)return null;const i=o.xAccessor||"x",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=t.upperAccessor||"upperBounds",l=t.lowerAccessor||"lowerBounds",c=t.filter,u=n.filter(t=>null!=t[a]&&null!=t[l]&&(!c||c(t))).sort((t,e)=>t[i]-e[i]);if(2>u.length)return null;const d=Vu[o.curve||"linear"]||Fu,h=Tu().x(t=>r(t[i])).y0(t=>s(t[l])).y1(t=>s(t[a])).curve(d)(u);if(!h)return null;const p=t.fill||"#6366f1",f=u[u.length-1];return Gu("g",{children:[Xu("path",{d:h,fill:p,fillOpacity:t.fillOpacity??.15,stroke:"none"}),t.label&&Xu("text",{x:r(f[i])+4,y:s(f[a])-4,fill:p,fontSize:11,children:t.label})]},"ann-"+e)}case"anomaly-band":{const n=o.data||[];if(2>n.length)return null;const i=o.yAccessor||"y",r=o.scales?.x??o.scales?.time,s=o.scales?.y??o.scales?.value;if(!r||!s)return null;const a=n.map(t=>t[i]).filter(t=>null!=t&&isFinite(t));if(2>a.length)return null;const l=a.reduce((t,e)=>t+e,0)/a.length,c=a.reduce((t,e)=>t+(e-l)**2,0)/a.length,u=Math.sqrt(c),d=t.threshold??2,h=l-d*u,p=s(l+d*u),f=s(h),g=t.fill||"#6366f1",y=t.anomalyColor||"#ef4444",m=t.anomalyRadius??6,x=n.filter(t=>{const e=t[i];return null!=e&&Math.abs(e-l)>d*u});return Gu("g",{children:[!1!==t.showBand&&Xu("rect",{x:0,y:Math.min(p,f),width:o.width||0,height:Math.abs(f-p),fill:g,fillOpacity:t.fillOpacity??.1}),x.map((t,e)=>{const n=E(t,o),i=D(t,o);return null==n||null==i?null:Xu("circle",{cx:n,cy:i,r:m,fill:y,fillOpacity:.7,stroke:y,strokeWidth:1.5},"anomaly-"+e)}),t.label&&Xu("text",{x:(o.width||0)-4,y:Math.min(p,f)-4,textAnchor:"end",fill:g,fontSize:11,children:t.label})]},"ann-"+e)}case"forecast":{const n=o.data||[];if(3>n.length)return null;const i=o.xAccessor||"x",r=o.yAccessor||"y",s=o.scales?.x??o.scales?.time,a=o.scales?.y??o.scales?.value;if(!s||!a)return null;const l=n.map(t=>[t[i],t[r]]).filter(t=>null!=t[0]&&null!=t[1]&&isFinite(t[0])&&isFinite(t[1])).sort((t,e)=>t[0]-e[0]);if(3>l.length)return null;let c;if("polynomial"===t.method){const e=ve(l,t.order||2).equation;c=t=>e.reduce((e,o,n)=>e+o*Math.pow(t,n),0)}else{const t=we(l);if(!t)return null;c=t}const{se:u,meanX:d,ssX:h}=ke(l,c),p=l.length,f=Ae(t.confidence??.95),g=l[p-1][0],y=(g-l[0][0])/Math.max(p-1,1),m=Array.from({length:t.steps??5},(t,e)=>{const o=g+(e+1)*y,n=c(o),i=u*Math.sqrt(1+1/p+(h>0?(o-d)**2/h:0))*f;return{x:o,center:n,upper:n+i,lower:n-i}}),x=m.map(t=>`${s(t.x)},${a(t.upper)}`).join(" L"),b=m.slice().reverse().map(t=>`${s(t.x)},${a(t.lower)}`).join(" L"),v=m.map(t=>`${s(t.x)},${a(t.center)}`).join(" "),w=t.strokeColor||"#6366f1",k=m[m.length-1];return Gu("g",{children:[Xu("path",{d:`M${x} L${b} Z`,fill:t.fill||"#6366f1",fillOpacity:t.fillOpacity??.15,stroke:"none"}),Xu("polyline",{points:`${s(g)},${a(c(g))} ${v}`,fill:"none",stroke:w,strokeWidth:t.strokeWidth??2,strokeDasharray:t.strokeDasharray??"6,3"}),t.label&&k&&Xu("text",{x:s(k.x)+4,y:a(k.center)-4,fill:w,fontSize:11,children:t.label})]},"ann-"+e)}case"widget":{let n,i;if(null!=t.px&&null!=t.py)n=t.px,i=t.py;else{const r=F(t,e,o);if(!r)return null;n=r.x,i=r.y}if(!M(n,i,o))return null;const r=t.width??32,s=t.height??32,a=t.content??Xu("span",{style:{fontSize:18,cursor:"default"},title:t.label||"Info",children:"ℹ️"});return Xu("foreignObject",{x:n+(t.dx??0)-r/2,y:i+(t.dy??0)-s/2,width:r,height:s,style:{overflow:"visible",pointerEvents:"auto"},children:Xu("div",{...Yu(t),style:{width:r,height:s,display:"flex",alignItems:"center",justifyContent:"center"},children:a})},"ann-"+e)}default:return null}}(e,o,n),t.svgAnnotationRules,d),f=p.nodes,g=new Map;for(const t of p.renderedAnnotations){const e="string"==typeof t.type?t.type:"unknown";g.set(e,(g.get(e)??0)+1)}const y=[];for(const t of e){const e="string"==typeof t.type?t.type:"unknown",o=g.get(e)??0;o>0?g.set(e,o-1):y.push(e)}return t.onRender?.({inputCount:e.length,eligibleCount:h.length,renderedCount:p.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?Hu("g",{id:(t.idPrefix?t.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}import{jsx as ed}from"react/jsx-runtime";function od(t,e,o,n="right",i,r){if(null==t||!1===t)return null;const{x:s,y:a}=ao(t,{totalWidth:e[0],totalHeight:e[1],margin:o,position:n,legendLayout:i,axisChrome:r});return ed("g",{transform:`translate(${s}, ${a})`,children:t})}import*as nd from"react";function id(t,e,o){if("edges"===t){if(e)return"start";if(o)return"end"}return"middle"}function rd(t,e,o){if("edges"===t){if(e)return"hanging";if(o)return"auto"}return"middle"}function sd(t){if(0===t.length)return{min:null,max:null};let e=1/0,o=-1/0;for(const n of t)e>n.pixel&&(e=n.pixel),n.pixel>o&&(o=n.pixel);return{min:e,max:o}}function ad(t){if(t)return"object"==typeof t?t.strokeDasharray:"dashed"===t?"6,4":"dotted"===t?"2,4":t}function ld(t,e){return t&&"string"!=typeof t?{stroke:t.stroke??e.stroke,strokeWidth:t.strokeWidth??e.strokeWidth,...null!=t.strokeOpacity&&{strokeOpacity:t.strokeOpacity},...t.strokeDasharray&&{strokeDasharray:t.strokeDasharray}}:{...e,..."string"==typeof t&&{strokeDasharray:ad(t)}}}function cd(t,e,o){if("left"===t||"right"===t){const n="left"===t?o:0,i="left"===t?-1:1,r=Math.ceil(e/8);let s="M0,"+n;for(let t=0;r>t;t++){const o=8*(t+1);s+=`L${Math.min(8*t+4,e)},${n+4*i}`,s+=`L${Math.min(o,e)},${n}`}return s}const n="bottom"===t?0:e,i="bottom"===t?1:-1,r=Math.ceil(o/8);let s=`M${n},0`;for(let t=0;r>t;t++){const e=8*(t+1);s+=`L${n+4*i},${Math.min(8*t+4,o)}`,s+=`L${n},${Math.min(e,o)}`}return s}function ud(t,e){return t?.ticks??t?.tickCount??e}function dd(t,e,o){return t instanceof Date?`${t.toLocaleString("en",{month:"short"})} ${t.getDate()}`:"number"==typeof t?Math.round(100*t)/100+"":t+""}function hd(t,e,o){return"exact"===o?function(t,e){const o=t.domain(),n=o[0],i=o[o.length-1],r=n instanceof Date,s=n instanceof Date?n.getTime():n,a=i instanceof Date?i.getTime():i;if(2>e||s===a)return r?[new Date(s),new Date(a)]:[s,a];const l=(a-s)/(e-1),c=Array(e);for(let t=0;e>t;t++){const o=t===e-1?a:s+t*l;c[t]=r?new Date(o):o}return c}(t,e):t.ticks(e)}import{jsx as pd}from"react/jsx-runtime";function fd(t){return"string"==typeof t||"number"==typeof t}function gd(t){const{label:e,x:o,y:n,textAlign:i,fontSize:r,fontFamily:s,color:a}=t;return pd("foreignObject",{x:o,y:n,width:60,height:24,style:{overflow:"visible"},children:pd("div",{style:{color:a,fontFamily:s,fontSize:r,textAlign:i,userSelect:"none"},children:e})})}function yd(t){const{values:e,scale:o,format:n}=t,i=e.map(t=>t.valueOf());return e.map((t,e)=>({value:t,pixel:o(t),label:n(t,e,i)}))}function md(t){return"string"==typeof t?6.5*t.length:"number"==typeof t?6.5*(t+"").length:60}function xd(t){const{candidates:e,scale:o,minPixelDistance:n,includeMax:i,extentMode:r,hasExplicitTickValues:s,dedupeLabels:a=!0,includeDomainMax:l=!0,format:c}=t;let u=function(t,e){if(2>=t.length)return t;const o=[t[0]];for(let n=1;t.length-1>n;n++)e>Math.abs(t[n].pixel-o[o.length-1].pixel)||o.push(t[n]);const n=t[t.length-1];return e>Math.abs(n.pixel-o[o.length-1].pixel)?o[o.length-1]=n:o.push(n),o}(e,n);if(a&&u.length>1&&(u=u.filter((t,e)=>{return 0===e||(n=u[e-1].label,!!("string"!=typeof(o=t.label)&&"number"!=typeof o||"string"!=typeof n&&"number"!=typeof n||o+""!=n+""));var o,n})),!l||!i||0===u.length||"exact"===r||s)return u;const d=o.domain(),h=d[d.length-1];if(null==h)return u;const p=o(h),f=u[u.length-1].pixel;if(1>=Math.abs(p-f))return u;const g=e.map(t=>t.value.valueOf()),y={value:h,pixel:p,label:c(h,u.length,g)};return n>Math.abs(p-f)&&u.length>1&&(u=u.slice(0,-1)),[...u,y]}function bd(t,e,o,n){return!!t&&("function"==typeof t?t(e.value,o):nt(e.value,o>0?n[o-1].value:void 0))}import{jsx as vd,jsxs as wd}from"react/jsx-runtime";function kd(t){if("string"==typeof t)return t;if(t&&"object"==typeof t){const e=t.id;return null==e?null:e+""}return null}function Ad(t){const e=t._idPrefix||t.chartId;if(e){const t=(e+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(t)?t:"c"+t}const o=`${t.chartType||""}:${t.title||""}:${Array.isArray(t.data)?t.data.length:0}`;let n=0;for(let t=0;o.length>t;t++)n=31*n+o.charCodeAt(t)|0;return"c"+(n>>>0).toString(36)}function Sd(t,e,o){return Ye(t.showLegend&&!t.__legendIncludesAutomatic?Zc(e,t.colorScheme,o):void 0,t.legend)}var Md={right:110,left:110,top:50,bottom:80};function _d(t,e){if(t.__autoLegendMargin)return Md[e]}function Pd(t,e){const o={theme:e.theme,position:e.position||"right",totalWidth:e.size[0],totalHeight:e.size[1],margin:e.margin,hasTitle:e.hasTitle,legendLayout:e.legendLayout,idPrefix:e.idPrefix,reservedWidth:e.reservedWidth,axisChrome:e.axisChrome,legendDistance:Xe(t)||Ge(t)?t.legendDistance:void 0};return Xe(t)?function(t){if(0===(e=t.legendGroups,e.flatMap(t=>t.items.map((e,o)=>({group:t,item:e,itemIndex:o,label:e.label})))).length)return null;var e;const o=function(t){const{legendGroups:e,theme:o,position:n="right",totalWidth:i,margin:r,legendLayout:s}=t,{swatchSize:a,labelGap:l,rowHeight:c}=lo(s),u=a+l,d=Math.max(12,Jc(o)),h="top"===n||"bottom"===n,p=Math.max(a,i-r.left-r.right);if(h){const n=Math.max(a,s?.maxWidth??p),i=Qc(s?.align);let r=0,l=0;const c=[];for(const i of e){const e=i.items.map(t=>t.label),u=nu({...t,categories:e,legendLayout:{...s,maxWidth:Math.max(a,n-d-8),align:"start"}}),h=i.label?d:0,p=i.label?ou(i.label,0,0,o):0,f=h>0?h+8:0,g=f+u.width,y=Math.max(u.height,p);c.push({group:i,x:r,y:0,itemOffsetX:f,itemOffsetY:0,width:g,height:y,items:u.items}),r+=g+12,l=Math.max(l,y)}const h=c.length>0?r-12:0,f=h>n?0:"center"===i?Math.max(0,(n-h)/2):"end"===i?Math.max(0,n-h):0;return{groups:c.map(t=>({...t,x:t.x+f})),width:h,height:l,swatchSize:a,labelOffset:u,swatchRadius:0}}const f=co(e.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),c);let g=0;return{groups:e.map((t,e)=>{const n=t.items.map(t=>ou(t.label,a,l,o)),i=Math.max(0,...n,t.label?ou(t.label,0,0,o):0);return g=Math.max(g,i),{group:t,x:0,y:f[e].itemsY,itemOffsetX:0,itemOffsetY:0,width:i,height:t.items.length*c,items:t.items.map((t,e)=>({category:t.label,width:n[e],x:0,y:e*c}))}}),width:g,height:f.at(-1)?.endY??0,swatchSize:a,labelOffset:u,swatchRadius:0}}(t),n="top"===t.position||"bottom"===t.position,i={legendGroups:t.legendGroups,legendDistance:t.legendDistance},r=t.reservedWidth??Ze(i,t.legendLayout),s=t.theme.colors.grid||t.theme.colors.textSecondary,{x:a,y:l}=ao(i,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:r});if(!n){const e=co(t.legendGroups.map(t=>({hasLabel:!!t.label,itemCount:t.items.length})),Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)),n=t.legendGroups.flatMap((n,i)=>{const s=e[i],a=n.type??"fill",l=[qc("line",{x1:0,y1:s.lineY,x2:r,y2:s.lineY,stroke:"gray"},"legend-group-neatline-"+i)];return n.label&&null!=s.labelY&&l.push(qc("text",{y:s.labelY,fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:n.label},"legend-group-label-"+i)),l.push(qc("g",{transform:`translate(0,${s.itemsY})`,children:n.items.map((e,r)=>{const s=n.styleFn(e,r),l="function"==typeof a?a(e):"line"===a?qc("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:s}):qc("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:s});return Uc("g",{transform:`translate(0,${r*Math.max(o.swatchSize,t.legendLayout?.rowHeight??22)})`,children:[l,qc("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:e.label})]},`legend-${i}-${r}`)})},"legend-group-"+i)),l});return qc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":"vertical",fontWeight:eu(t.theme),children:n})}const c=o.groups.flatMap((e,i)=>{const{group:r}=e,a=r.type??"fill",l=[];if(r.label&&l.push(qc("text",n?{transform:`translate(${e.x},${e.y}) rotate(90)`,textAnchor:"start",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:r.label}:{x:e.x,y:e.y+Jc(t.theme),fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:r.label},"legend-group-label-"+i)),l.push(...e.items.map((n,s)=>{const l=r.items[s],c=r.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?qc("line",{x1:0,y1:0,x2:o.swatchSize,y2:o.swatchSize,style:c}):qc("rect",{width:o.swatchSize,height:o.swatchSize,rx:o.swatchRadius,style:c});return Uc("g",{transform:`translate(${e.x+e.itemOffsetX+n.x},${e.y+e.itemOffsetY+n.y})`,children:[u,qc("text",{x:o.labelOffset,y:o.swatchSize/2,dominantBaseline:"central",fontSize:Jc(t.theme),fill:t.theme.colors.text,fontFamily:tu(t.theme),children:n.category})]},`legend-${i}-${s}`)})),n&&o.groups.length-1>i){const t=e.x+e.width+6;l.push(qc("line",{x1:t,y1:0,x2:t,y2:o.height,stroke:s},"legend-group-separator-"+i))}return l});return qc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,"data-orientation":n?"horizontal":"vertical",fontWeight:eu(t.theme),children:c})}({...o,legendGroups:t.legendGroups}):Ge(t)?function(t){const e=function(t){const e="top"===t.position||"bottom"===t.position,o=Math.max(1,t.totalWidth-t.margin.left-t.margin.right);return e?{width:Math.min(t.legendLayout?.maxWidth??o,200),height:t.gradient.label?46:26,swatchSize:12}:{width:t.gradient.label?86:72,height:t.gradient.label?126:108,swatchSize:14}}(t),o="top"===t.position||"bottom"===t.position,n={gradient:t.gradient,legendDistance:t.legendDistance},i=Ze(n),r=(t.idPrefix?t.idPrefix+"-":"")+"semiotic-static-gradient-legend",s=t.gradient.format||(t=>Math.round(100*t)/100+""),{x:a,y:l}=ao(n,{totalWidth:t.totalWidth,totalHeight:t.totalHeight,margin:t.margin,position:t.position,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:i}),c=Array.from({length:17},(e,n)=>{const i=n/16;return qc("stop",{offset:100*i+"%",stopColor:t.gradient.colorFn(o?t.gradient.domain[0]+i*(t.gradient.domain[1]-t.gradient.domain[0]):t.gradient.domain[1]-i*(t.gradient.domain[1]-t.gradient.domain[0]))},n)});if(o){const o=12,n=t.gradient.label?12:void 0,i=t.gradient.label?18:0;return Uc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:eu(t.theme),children:[qc("defs",{children:qc("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),t.gradient.label&&qc("text",{x:e.width/2,y:n,textAnchor:"middle",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:tu(t.theme),children:t.gradient.label}),qc("rect",{x:0,y:i,width:e.width,height:o,fill:`url(#${r})`,rx:2}),qc("text",{x:0,y:i+o+12,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[0])}),qc("text",{x:e.width,y:i+o+12,textAnchor:"end",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[1])})]})}const u=t.gradient.label?12:void 0,d=t.gradient.label?18:0;return Uc("g",{className:"semiotic-legend",transform:`translate(${a},${l})`,fontWeight:eu(t.theme),children:[qc("defs",{children:qc("linearGradient",{id:r,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),t.gradient.label&&qc("text",{x:0,y:u,textAnchor:"start",fontSize:t.theme.typography.tickSize,fill:t.theme.colors.text,fontFamily:tu(t.theme),children:t.gradient.label}),qc("rect",{x:0,y:d,width:14,height:100,fill:`url(#${r})`,rx:2}),qc("text",{x:19,y:d+10,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[1])}),qc("text",{x:19,y:d+100,fontSize:t.theme.typography.tickSize,fill:t.theme.colors.textSecondary,fontFamily:tu(t.theme),children:s(t.gradient.domain[0])})]})}({...o,gradient:t.gradient}):null}function Ld(t,e){const{props:o,categories:n,theme:i,size:r,hasTitle:s}=e,a=o.legendPosition||"right",l={...t},c={theme:i,position:a,size:r,hasTitle:s,legendLayout:o.legendLayout,axisChrome:o.axisChrome,minimumMargin:_d(o,a)};if(null!=o.legend){const e=Sd(o,n,i);null!=e&&!1!==e&&function(t,e){so(t,{legend:e.legend,position:e.position||"right",size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,legend:e})}else o.showLegend&&n.length>0&&function(t,e){if(0===e.categories.length)return;const o=e.position||"right";so(t,{legend:Zc(e.categories,e.colorScheme,e.theme),position:o,size:e.size,hasTitle:e.hasTitle,legendLayout:e.legendLayout,minimumMargin:e.minimumMargin,axisChrome:e.axisChrome})}(t,{...c,categories:n,colorScheme:o.colorScheme});return Ue(t,l,r,a),a}function $d(t){const{props:e,categories:o,theme:n,size:i,margin:r,hasTitle:s}=t,a=e.legendPosition||"right",l={theme:n,position:a,size:i,margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix};if(null!=e.legend){const t=Sd(e,o,n);if(nd.isValidElement(t))return od(t,i,r,a,e.legendLayout,e.axisChrome);return Pd(t,l)||(Xe(t)||Ge(t)?null:od(t??null,i,r,a,e.legendLayout,e.axisChrome))}return e.showLegend&&0!==o.length?function(t){const{categories:e,colorScheme:o,theme:n,position:i="right",totalWidth:r,totalHeight:s,margin:a}=t;if(!e||0===e.length)return null;const l=Kc(e,o,n),c="top"===i||"bottom"===i,u=nu(t),d={...Zc(e,o,n),legendDistance:t.legendDistance},h=t.reservedWidth??Ze(d,t.legendLayout),{x:p,y:f}=ao(d,{totalWidth:r,totalHeight:s,margin:a,position:i,legendLayout:t.legendLayout,axisChrome:t.axisChrome,reservedWidth:h});if(c){const t=u.items.map((t,e)=>Uc("g",{transform:`translate(${t.x},${t.y})`,children:[qc("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),qc("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Jc(n),fill:n.colors.text,fontFamily:tu(n),children:t.category})]},"legend-"+e));return qc("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:eu(n),children:t})}const g=co([{hasLabel:!1,itemCount:e.length}],Math.max(u.swatchSize,t.legendLayout?.rowHeight??22))[0],y=u.items.map((t,e)=>Uc("g",{transform:`translate(${t.x},${t.y+g.itemsY})`,children:[qc("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(t.category),rx:u.swatchRadius}),qc("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:Jc(n),fill:n.colors.text,fontFamily:tu(n),children:t.category})]},"legend-"+e));return Uc("g",{className:"semiotic-legend",transform:`translate(${p},${f})`,fontWeight:eu(n),children:[qc("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),y]})}({categories:o,colorScheme:e.colorScheme,theme:n,position:a,totalWidth:i[0],totalHeight:i[1],margin:r,hasTitle:s,legendLayout:e.legendLayout,axisChrome:e.axisChrome,idPrefix:e._idPrefix}):null}var Rd=dd;function Cd(t,e){const o=me(e.theme),n=e.background??o.background,i=e.idPrefix?e.idPrefix+"-":"",r="string"==typeof e.title?e.title:void 0,s=r?i+"semiotic-title":void 0,a=e.description?i+"semiotic-desc":void 0,l=[s,a].filter(Boolean).join(" ")||void 0;return wd("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className,width:e.width,height:e.height,role:"img","aria-labelledby":l,style:{fontFamily:o.fontFamily},children:[r&&vd("title",{id:s,children:r}),e.description&&vd("desc",{id:a,children:e.description}),e.defs&&vd("defs",{children:e.defs}),n&&"transparent"!==n&&vd("rect",{x:0,y:0,width:e.width,height:e.height,fill:n}),vd("g",{id:i+"data-area",transform:e.innerTransform,children:t}),r&&vd("text",{id:i+"chart-title",x:e.width/2,y:22,textAnchor:"middle",fontSize:o.titleFontSize,fontWeight:o.titleFontWeight,fill:o.text,fontFamily:o.titleFontFamily,children:r}),e.legend&&vd("g",{id:i+"legend",children:e.legend}),e.outerElements]})}import{jsx as Td,jsxs as Od}from"react/jsx-runtime";function Id(t,e,o,n){return"function"==typeof t?t({size:e,margin:o,scales:n}):t}var zd={top:50,right:40,bottom:60,left:70},Fd={top:20,right:80,bottom:20,left:80},Nd={top:40,right:40,bottom:40,left:40},Ed=new Set(["chord","force","circlepack","orbit"]);import{jsx as Dd,jsxs as Wd}from"react/jsx-runtime";import{Fragment as Bd,jsx as jd,jsxs as Yd}from"react/jsx-runtime";function Xd(t,e){const o=ye(t.theme),n=t.size||[500,300],i=qe({...zd,...t.margin},t.title),r=Ve(t.title),s=function(t,e){if(!e||0===t.length)return t;if(!t.some(t=>null!=t&&"object"==typeof t&&Array.isArray(t[e])))return t;const o=[];for(const n of t){if(null==n||"object"!=typeof n)continue;const t=n[e];if(!Array.isArray(t))continue;const i=n.label??n.id??n.key;for(const e of t)null!=e&&"object"==typeof e&&o.push(null==i?e:{...e,_lineGroup:i})}return o}(Ht(t.data),t.lineDataAccessor),a=t.showLegend?iu(s,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],l=function(t){const e=t.axes?.find(t=>"bottom"===t.orient),o=t.axes?.find(t=>"top"===t.orient),n=t.axes?.find(t=>"left"===t.orient),i=t.axes?.find(t=>"right"===t.orient),r=!o||!!e,s=!!o&&!e,a=!i||!!n,l=!!i,c=!1!==t.showAxes;return{hasAxis:c&&r,hasAxisLabel:c&&r&&!!(e?.label??t.xLabel),rotatedTicks:c&&r&&(t.rotatedTicks??!!e?.autoRotate),topAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(o?.label??t.xLabel),rotatedTicks:c&&(t.rotatedTicks??!!o?.autoRotate)}:void 0,leftAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??t.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??t.yLabelRight??t.yLabel)}:void 0}}({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});Ld(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=$d({props:{...t,axisChrome:l},categories:a,theme:o,size:n,margin:i,hasTitle:r}),u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),p=t.colorScheme||o.colors.categorical,f=(t.axes?.find(t=>"left"===t.orient)??t.axes?.find(t=>"right"===t.orient))?.extent??t.axisExtent,g={chartType:t.chartType,runtimeMode:h?"streaming":"bounded",windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:h?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:t.xAccessor,yAccessor:t.yAccessor,timeAccessor:h?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor||(t.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,axisExtent:t.axisExtent,yAxisExtent:f,sizeRange:t.sizeRange,xScaleType:t.xScaleType,yScaleType:t.yScaleType,scalePadding:t.scalePadding,binSize:t.binSize,normalize:t.normalize,baseline:t.baseline,stackOrder:t.stackOrder,boundsAccessor:t.boundsAccessor,boundsStyle:t.boundsStyle,band:t.band,y0Accessor:t.y0Accessor,areaGroups:t.areaGroups?t.areaGroups instanceof Set?t.areaGroups:new Set(t.areaGroups):void 0,curve:t.curve,gradientFill:ce(t.gradientFill),lineGradient:ue(t.lineGradient),semanticLineStops:t.semanticLineStops,openAccessor:t.openAccessor,highAccessor:t.highAccessor,lowAccessor:t.lowAccessor,closeAccessor:t.closeAccessor,candlestickStyle:t.candlestickStyle,lineStyle:t.lineStyle,pointStyle:t.pointStyle,areaStyle:t.areaStyle,barStyle:t.barStyle,waterfallStyle:t.waterfallStyle,swarmStyle:t.swarmStyle,colorScheme:p,themeCategorical:o.colors.categorical,themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging,themeSemantic:Rt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat,heatmapColorScale:t.heatmapColorScale,heatmapAggregation:t.heatmapAggregation,heatmapXBins:t.heatmapXBins,heatmapYBins:t.heatmapYBins,pointIdAccessor:t.pointIdAccessor,onLayoutError:t.onLayoutError},y=new ac(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Id(t.backgroundGraphics,n,i,y.scales),x=Id(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"xy",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Ya.renderToStaticMarkup(Cd(m||x||t.annotations?Yd(Bd,{children:[m,a,x]}):null,{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=Vc({nodes:y.scene,renderMode:t.renderMode,fallback:(e,o)=>Yc(e,o,b,t.hoverRadius??30)}),w=t.showGrid?function(t,e,o,n,i,r,s){const{grid:a}=me(o),l=n?n+"-":"",c=r?.find(t=>"bottom"===t.orient),u=r?.find(t=>"top"===t.orient),d=r?.find(t=>"left"===t.orient),h=r?.find(t=>"right"===t.orient),p=c??u,f=d??h,g=p?.extent??i,y=f?.extent??i,m="exact"===g?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),x="exact"===y?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),b=p?.tickValues??hd(t.x,ud(p,m),g),v=p?.tickFormat||s?.xFormat||s?.tickFormatTime||dd,w=yd({values:b,scale:t.x,format:v}),k=w.reduce((t,e)=>Math.max(t,md(e.label)),0),A=xd({candidates:w,scale:t.x,minPixelDistance:p?.autoRotate?Math.max(20,Math.min(k+8,55)):Math.max(55,k+8),includeMax:p?.includeMax,extentMode:g,hasExplicitTickValues:!!p?.tickValues,format:v}),S=f?.tickValues??hd(t.y,ud(f,x),y),M=f?.tickFormat||s?.yFormat||s?.tickFormatValue||dd,_=t=>M(t),P=xd({candidates:yd({values:S,scale:t.y,format:_}),scale:t.y,minPixelDistance:22,includeMax:f?.includeMax,extentMode:y,hasExplicitTickValues:!!f?.tickValues,format:_}),L=!1!==p?.grid,$=!1!==f?.grid,R=ad(p?.gridStyle),C=ad(f?.gridStyle),T=ld(p?.gridStyle,{stroke:a,strokeWidth:.5}),O=ld(f?.gridStyle,{stroke:a,strokeWidth:.5});return Od("g",{id:l+"grid",className:"semiotic-grid",opacity:.8,children:[L&&A.map((t,o)=>Td("line",{x1:t.pixel,y1:0,x2:t.pixel,y2:e.height,...T,strokeDasharray:R??T.strokeDasharray},"gx-"+o)),$&&P.map((t,o)=>Td("line",{x1:0,y1:t.pixel,x2:e.width,y2:t.pixel,...O,strokeDasharray:C??O.strokeDasharray},"gy-"+o))]})}(y.scales,{width:u,height:d},o,b,t.axisExtent,t.axes,t):null,k=v.map(t=>t.element),A=Ad(t)+"-plot-clip",S=!1!==t.showAxes,M=S?function(t,e,o,n,i,r,s,a=!1){const l=me(n),c=o.legendPosition??"right",u=Je(o.legendLayout,s?.leftAxis),d=Je(o.legendLayout,s?.rightAxis),h=a&&"left"===c&&u>0?u:r?.left??o.margin?.left??40,p=a&&"right"===c&&d>0?d:r?.right??o.margin?.right??40,f=o.axes?.find(t=>"bottom"===t.orient),g=o.axes?.find(t=>"top"===t.orient),y=o.axes?.find(t=>"left"===t.orient),m=o.axes?.find(t=>"right"===t.orient),x=f??g,b=y??m,v=f?"bottom":g?"top":"bottom",w=y?"left":m?"right":"left",k="top"===v?0:e.height,A="right"===w?e.width:0,S="top"===v?-1:1,M="right"===w?1:-1,_=x?.extent??o.axisExtent,P=b?.extent??o.axisExtent,L="exact"===_?5:Math.min(5,Math.max(2,Math.floor(e.width/70))),$="exact"===P?5:Math.min(5,Math.max(2,Math.floor(e.height/30))),R=x?.tickValues??hd(t.x,ud(x,L),_),C=x?.tickFormat||o.xFormat||o.tickFormatTime||Rd,T=yd({values:R,scale:t.x,format:C}),O=T.reduce((t,e)=>Math.max(t,md(e.label)),0),I=xd({candidates:T,scale:t.x,minPixelDistance:x?.autoRotate?Math.max(20,Math.min(O+8,55)):Math.max(55,O+8),includeMax:x?.includeMax,extentMode:_,hasExplicitTickValues:!!x?.tickValues,format:C}),z=b?.tickValues??hd(t.y,ud(b,$),P),F=b?.tickFormat||o.yFormat||o.tickFormatValue||Rd,N=t=>F(t),E=xd({candidates:yd({values:z,scale:t.y,format:N}),scale:t.y,minPixelDistance:22,includeMax:b?.includeMax,extentMode:P,hasExplicitTickValues:!!b?.tickValues,format:N}),D=!!(x?.autoRotate&&I.length>1&&e.width/Math.max(I.length-1,1)<I.reduce((t,e)=>Math.max(t,"string"==typeof e.label?6.5*e.label.length:60),0)+8),W=sd(I),B=sd(E),j=x?.label??o.xLabel,Y=b?.label??("right"===w?o.yLabelRight??o.yLabel:o.yLabel),X=ld(x?.axisStyle,{stroke:l.border,strokeWidth:1}),G=ld(b?.axisStyle,{stroke:l.border,strokeWidth:1}),V="right"===w?e.width+p-15:15-h;return wd("g",{id:(i?i+"-":"")+"axes",className:"stream-axes",children:[!1!==x?.baseline&&!x?.jaggedBase&&vd("line",{x1:0,y1:k,x2:e.width,y2:k,...X}),x?.jaggedBase&&vd("path",{d:cd(v,e.width,e.height),fill:"none",...X}),I.map((t,e)=>{const o=bd(x?.landmarkTicks,t,e,I);return wd("g",{transform:`translate(${t.pixel},${k})`,children:[vd("line",{y2:5*S,...X}),fd(t.label)?vd("text",{y:S*(D?12:18),textAnchor:D?"end":id(x?.tickAnchor,t.pixel===W.min,t.pixel===W.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:D?"top"===v?"rotate(45)":"rotate(-45)":void 0,children:t.label}):gd({label:t.label,x:-30,y:"top"===v?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"xtick-"+e)}),j&&vd("text",{x:e.width/2,y:"top"===v?-(D?58:40):e.height+(D?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:j}),!1!==b?.baseline&&!b?.jaggedBase&&vd("line",{x1:A,y1:0,x2:A,y2:e.height,...G}),b?.jaggedBase&&vd("path",{d:cd(w,e.width,e.height),fill:"none",...G}),E.map((t,e)=>{const o=bd(b?.landmarkTicks,t,e,E);return wd("g",{transform:`translate(${A},${t.pixel})`,children:[vd("line",{x2:5*M,...G}),fd(t.label)?vd("text",{x:8*M,textAnchor:"right"===w?"start":"end",dominantBaseline:rd(b?.tickAnchor,t.pixel===B.min,t.pixel===B.max),fontWeight:o?600:400,fontSize:o?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:t.label}):gd({label:t.label,x:"right"===w?8:-68,y:-12,textAlign:"right"===w?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},"ytick-"+e)}),Y&&vd("text",{x:V,y:e.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===w?90:-90}, ${V}, ${e.height/2})`,children:Y})]})}(y.scales,{width:u,height:d},t,o,b,i,l,!!c):null,_=S?function(t){const{scales:e,layout:o,props:n,theme:i,leftAxis:r,rightAxis:s,margin:a,axisChrome:l,hasRenderedLegend:c}=t;if(!r||!s)return null;const u=me(i),d=s.extent??n.axisExtent,h="exact"===d?Math.max(2,ud(s,5)):Math.min(ud(s,5),Math.max(2,Math.floor(o.height/30))),p=s.tickValues??hd(e.y,h,d),f=s.tickFormat||n.yFormat||n.tickFormatValue||dd,g=t=>f(t),y=xd({candidates:yd({values:p,scale:e.y,format:g}),scale:e.y,minPixelDistance:22,includeMax:s.includeMax,extentMode:d,hasExplicitTickValues:!!s.tickValues,format:g}),m=sd(y),x=s.label??n.yLabelRight,b=ld(s.axisStyle,{stroke:u.border,strokeWidth:1}),v=n.legendPosition??"right",w=Je(n.legendLayout,l?.rightAxis),k=o.width+(c&&"right"===v&&w>0?w:a.right)-15;return Wd("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==s.baseline&&!s.jaggedBase&&Dd("line",{x1:o.width,y1:0,x2:o.width,y2:o.height,...b}),s.jaggedBase&&Dd("path",{d:cd("right",o.width,o.height),fill:"none",...b}),y.map((t,e)=>{const n=bd(s.landmarkTicks,t,e,y);return Wd("g",{transform:`translate(${o.width},${t.pixel})`,children:[Dd("line",{x2:5,...b}),fd(t.label)?Dd("text",{x:8,textAnchor:"start",dominantBaseline:rd(s.tickAnchor,t.pixel===m.min,t.pixel===m.max),fontWeight:n?600:400,fontSize:n?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:t.label}):gd({label:t.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+e)}),x&&Dd("text",{x:k,y:o.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${k}, ${o.height/2})`,children:x})]})}({scales:y.scales,layout:{width:u,height:d},props:t,theme:o,leftAxis:t.axes?.find(t=>"left"===t.orient),rightAxis:t.axes?.find(t=>"right"===t.orient),margin:i,axisChrome:l,hasRenderedLegend:!!c}):null;let P;const L=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.scales.y},layout:{width:u,height:d},theme:o,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:b,onRender:t=>{P=t}}):null;e&&(e.evidence=Ba({frameType:"xy",width:n[0],height:n[1],marks:v.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:P,xDomain:Wa(y.scales.x?.domain?.()),yDomain:Wa(y.scales.y?.domain?.()),legendItems:a.length>0?a.length:void 0,margin:i}));const $=t.svgPreRenderers&&y.scales?t.svgPreRenderers.map((t,e)=>{try{return jd(ja.Fragment,{children:t(y.scene,y.scales,{width:u,height:d})},"pre-"+e)}catch{return null}}).filter(Boolean):null;return Ya.renderToStaticMarkup(Cd(Yd(Bd,{children:[m,$,w,jd("defs",{children:jd("clipPath",{id:A,children:jd("rect",{x:0,y:0,width:u,height:d})})}),jd("g",{clipPath:`url(#${A})`,children:k}),M,_,L,x,y.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}import*as Gd from"react";import*as Vd from"react-dom/server.browser";import{scaleBand as Hd,scaleLinear as qd}from"d3-scale";var Ud=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(t,e,o){if(e&&"function"==typeof t.pieceStyle){const n=t.pieceStyle(e,o);return n&&!n.fill&&o?{...n,fill:this.getColorFromScheme(t,o)}:n}return t.pieceStyle&&"object"==typeof t.pieceStyle?t.pieceStyle:t.barColors&&o?{fill:ne(t.barColors,o)??"#007bff"}:{fill:o?this.getColorFromScheme(t,o):"#007bff"}}resolveSummaryStyle(t,e,o){return e&&"function"==typeof t.summaryStyle?t.summaryStyle(e,o):t.summaryStyle&&"object"==typeof t.summaryStyle?t.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(t,e){const o=this.colorSchemeMap.get(e);if(o)return o;const n=Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical||Jt,i=n[this.colorSchemeIndex%n.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(e,i),i}};function Kd(t,e,o){const n="function"==typeof t?t(o?e.w:e.h):t;return"number"==typeof n&&Number.isFinite(n)?Math.max(0,n):0}function Zd(t){const e=t.getSymbol;return e?_(e,t.config.symbolMap):null}function Qd(t,e,o,n,i,r,s){t.push(e?{type:"symbol",x:n,y:i,size:Math.PI*r*r,symbolType:e(o),style:s,datum:o}:{type:"point",x:n,y:i,r:r,style:s,datum:o})}function Jd(t,e){const{columns:o,config:n,resolvePieceStyle:i}=t,r=[],s=Math.min(e.width,e.height)/2-4,a="donut"===n.chartType?n.innerRadius||60:0,l=-Math.PI/2+(n.startAngle||0)*Math.PI/180,c=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,u=null!=n.sweepAngle&&360>n.sweepAngle,d=Object.values(o),h=d.some(t=>{const e=t.pieceData[0];return e&&("number"==typeof e._pct||"number"==typeof e._pctStart||null!=e._roundedEnds)}),p=u&&!h&&d.length>1&&(n.cornerRadius??0)>0;for(let t=0;d.length>t;t++){const e=d[t],o=e.pieceData[0],u="number"==typeof o?._pctStart?o._pctStart:e.pctStart,h=l+u*c,f=l+(u+("number"==typeof o?._pct?o._pct:e.pct))*c,g=i(e.pieceData[0],e.name),y=0===t,m=t===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:a,outerRadius:s,startAngle:h,endAngle:f,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:g,datum:o?._nonInteractive?null:e.pieceData,category:e.name};o?._roundedEnds?x.roundedEnds=o._roundedEnds:p&&(x.roundedEnds={start:y,end:m}),o?._gradientBand&&(x._gradientBand=o._gradientBand),r.push(x)}return r}import{quantile as th}from"d3-array";function eh(t){const e=t.length,o=t[0],n=t[e-1];return{n:e,min:o,q1:th(t,.25)??o,median:th(t,.5)??(o+n)/2,q3:th(t,.75)??n,max:n,mean:t.reduce((t,e)=>t+e,0)/e}}import{scaleLinear as oh}from"d3-scale";var nh={bar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getStack:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h="horizontal"===c,p=i.normalize,f=[];if(s){const t=new Set;for(const e of Object.values(n))for(const o of e.pieceData){const e=s(o);t.has(e)||(t.add(e),f.push(e))}}else f.push("_default");for(const t of Object.values(n)){const e=new Map;for(const o of t.pieceData){const t=s?s(o):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const n=e.get(t);n.total+=r(o),n.pieces.push(o)}let o=0;if(p)for(const t of e.values())o+=Math.abs(t.total);let n=0,i=0;for(const r of f){const c=e.get(r);if(!c)continue;let f=c.total;p&&o>0&&(f/=o);const g=a(c.pieces[0],s?r:t.name),y={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:t.name};if(d){const e=l(0>f?i:n+f),o=0>f?l(i+f)-l(i):l(n)-l(n+f);u.push(al(t.x,e,t.width,Math.abs(o),g,y,r)),0>f?i+=f:n+=f}else if(h){const e=l(0>f?i+f:n),o=0>f?l(i)-l(i+f):l(n+f)-l(n);u.push(al(e,t.x,Math.abs(o),t.width,g,y,r)),0>f?i+=f:n+=f}}}const g="vertical"===c;for(const t of u){if("rect"!==t.type)continue;const e=t.datum?.__aggregateValue??0;t.roundedEdge=g?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}if(void 0!==i.roundedTop){const t=new Map;for(const e of u){if("rect"!==e.type)continue;const o=e.datum?.category||"";t.has(o)||t.set(o,[]),t.get(o).push(e)}for(const e of t.values()){if(0===e.length)continue;const t=e.filter(t=>(t.datum?.__aggregateValue??0)>=0),o=e.filter(t=>0>(t.datum?.__aggregateValue??0));if(t.length>0){const e=t.reduce(g?(t,e)=>e.y>t.y?t:e:(t,e)=>t.x+t.w>e.x+e.w?t:e),o=Kd(i.roundedTop,e,g);o>0&&(e.roundedTop=o)}if(o.length>0){const t=o.reduce(g?(t,e)=>t.y+t.h>e.y+e.h?t:e:(t,e)=>e.x>t.x?t:e),e=Kd(i.roundedTop,t,g);e>0&&(t.roundedTop=e)}}}return u},clusterbar:function(t,e){const{scales:o,columns:n,config:i,getR:r,getGroup:s,resolvePieceStyle:a}=t,{r:l,projection:c}=o,u=[],d="vertical"===c,h=[],p=new Set;for(const t of Object.values(n))for(const e of t.pieceData){const t=s?s(e):"_default";p.has(t)||(p.add(t),h.push(t))}const f=h.length||1;for(const t of Object.values(n)){const e=t.width/f,o=.2*e,n=e-o,i=new Map;for(const e of t.pieceData){const t=s?s(e):"_default";i.has(t)||i.set(t,[]),i.get(t).push(e)}for(let s=0;h.length>s;s++){const c=i.get(h[s])||[];for(const i of c){const c=r(i),p=a(i,h[s]);if(d){const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(al(r,Math.min(a,d),n,Math.abs(a-d),p,i,h[s]))}else{const r=t.x+s*e+o/2,a=l(0),d=l(c);u.push(al(Math.min(a,d),r,Math.abs(d-a),n,p,i,h[s]))}}}}for(const t of u){if("rect"!==t.type)continue;if(null==t.datum)continue;const e=r(t.datum),o=Kd(i.roundedTop,t,d);o>0&&(t.roundedTop=o),t.roundedEdge=d?0>e?"bottom":"top":0>e?"left":"right",i.gradientFill&&(t.fillGradient=i.gradientFill)}return u},point:function(t,e){const{scales:o,columns:n,getR:i,multiScales:r,resolvePieceStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d="radial"===l,h=r.length>0,p=Zd(t),f=2*Math.PI,g=-Math.PI/2;for(const t of Object.values(n))for(const e of t.pieceData){const o=e.__rIndex??0,n=e.__rValue??i(e),l=h&&r[o]||a,y=s(e,t.name),m=y.r||5;let x,b;if(d){const e=g+(t.pctStart+t.pct/2)*f,o=l(n);x=Math.cos(e)*o,b=Math.sin(e)*o}else u?(x=t.middle,b=l(n)):(x=l(n),b=t.middle);Qd(c,p,e,x,b,m,y)}return c},swarm:function(t,e){const{scales:o,columns:n,getR:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="vertical"===a,u=Zd(t);for(const t of Object.values(n)){const e=t.width/2;for(let o=0;t.pieceData.length>o;o++){const n=t.pieceData[o],a=i(n),d=r(n,t.name),h=d.r||4,p=(7919*o%100/100-.5)*e*.8;Qd(l,u,n,c?t.middle+p:s(a),c?s(a):t.middle+p,h,d)}}return l},pie:Jd,donut:Jd,boxplot:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d=!1!==i.showOutliers;for(const e of Object.values(n)){const o=e.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(0===o.length)continue;const n=o[0],i=o[o.length-1],l=th(o,.25)??n,h=th(o,.5)??(n+i)/2,p=th(o,.75)??i,f=p-l,g=l-1.5*f,y=p+1.5*f,m=o.find(t=>t>=g)??n,x=[...o].reverse().find(t=>y>=t)??i,b=s(e.pieceData[0],e.name),v=[];if(d)for(const t of e.pieceData){const o=r(t);if(g>o||o>y){const n=u?e.middle:a(o),i=u?a(o):e.middle;v.push({px:n,py:i,value:o,datum:t})}}if(c.push({type:"boxplot",x:u?e.middle:0,y:u?0:e.middle,projection:u?"vertical":"horizontal",columnWidth:.6*e.width,minPos:a(m),q1Pos:a(l),medianPos:a(h),q3Pos:a(p),maxPos:a(x),stats:{n:o.length,min:m,q1:l,median:h,q3:p,max:x,mean:o.reduce((t,e)=>t+e,0)/o.length},style:b,datum:e.pieceData,category:e.name,outliers:v}),d)for(const e of v)c.push({type:"point",x:e.px,y:e.py,r:3,style:{fill:b.fill||t.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:b.cursor},datum:e.datum})}return c},violin:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u="vertical"===l,d=i.bins||20,h=!1!==i.showIQR;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/d||1,l=Array(d).fill(0);for(const t of e)l[Math.min(Math.floor((t-o)/i),d-1)]++;const p=kt(l,1),f=t.width/2*.9;let g;if(u){g=`M ${t.middle} ${a(o)}`;for(let e=0;d>e;e++){const n=a(o+(e+.5)*i);g+=` L ${t.middle+l[e]/p*f} ${n}`}g+=` L ${t.middle} ${a(n)}`;for(let e=d-1;e>=0;e--){const n=a(o+(e+.5)*i);g+=` L ${t.middle-l[e]/p*f} ${n}`}g+=" Z"}else{g=`M ${a(o)} ${t.middle}`;for(let e=0;d>e;e++)g+=` L ${a(o+(e+.5)*i)} ${t.middle-l[e]/p*f}`;g+=` L ${a(n)} ${t.middle}`;for(let e=d-1;e>=0;e--)g+=` L ${a(o+(e+.5)*i)} ${t.middle+l[e]/p*f}`;g+=" Z"}const y=s(t.pieceData[0],t.name);let m;if(h&&e.length>=4){const i=th(e,.25)??o,r=th(e,.5)??(o+n)/2,s=th(e,.75)??n;m={q1Pos:a(i),medianPos:a(r),q3Pos:a(s),centerPos:t.middle,isVertical:u}}const x=u?{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))}:{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width};c.push({type:"violin",pathString:g,translateX:0,translateY:0,bounds:x,iqrLine:m,stats:eh(e),style:y,datum:t.pieceData,category:t.name})}return c},histogram:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a}=o,l=[],c=i.bins||25,u=i.normalize,d=a.domain?.(),h=d?+d[0]:void 0,p=d?+d[1]:void 0;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t));if(0===e.length)continue;const[o,n]=St(e),i=null!=h&&isFinite(h)?h:o,d=null!=p&&isFinite(p)?p:n,f=(d-i)/c||1,g=Array(c).fill(0);for(const t of e)i>t||t>d||g[Math.min(Math.floor((t-i)/f),c-1)]++;const y=e.length,m=kt(g,1),x=s(t.pieceData[0],t.name);for(let e=0;c>e;e++){if(0===g[e])continue;const o=(u?g[e]/y:g[e]/m)*t.width*.9,n=a(i+e*f),r=a(i+(e+1)*f);l.push(al(Math.min(n,r),t.x+t.width-o,Math.abs(r-n),o,x,{bin:e,count:g[e],range:[i+e*f,i+(e+1)*f],category:t.name},t.name))}}return l},ridgeline:function(t,e){const{scales:o,columns:n,config:i,getR:r,resolveSummaryStyle:s}=t,{r:a,projection:l}=o,c=[],u=i.bins||20,d="horizontal"===l,h=i.amplitude||1.5;for(const t of Object.values(n)){const e=t.pieceData.map(t=>r(t)).filter(t=>null!=t&&!isNaN(t)).sort((t,e)=>t-e);if(2>e.length)continue;const o=e[0],n=e[e.length-1],i=(n-o)/u||1,l=Array(u).fill(0);for(const t of e)o>t||t>n||l[Math.min(Math.floor((t-o)/i),u-1)]++;const p=kt(l,1),f=s(t.pieceData[0],t.name),g=t.width*h;let y;if(d){const e=t.x+t.width;y=`M ${a(o)} ${e}`;for(let t=0;u>t;t++)y+=` L ${a(o+(t+.5)*i)} ${e-l[t]/p*g}`;y+=` L ${a(n)} ${e} Z`}else{const e=t.x;y=`M ${e} ${a(o)}`;for(let t=0;u>t;t++){const n=a(o+(t+.5)*i);y+=` L ${e+l[t]/p*g} ${n}`}y+=` L ${e} ${a(n)} Z`}const m=d?{x:Math.min(a(o),a(n)),y:t.x,width:Math.abs(a(n)-a(o)),height:t.width}:{x:t.x,y:Math.min(a(n),a(o)),width:t.width,height:Math.abs(a(n)-a(o))};c.push({type:"violin",pathString:y,translateX:0,translateY:0,bounds:m,stats:eh(e),style:{...f,fillOpacity:f.fillOpacity??.5},datum:t.pieceData,category:t.name})}return c},timeline:function(t,e){const{scales:o,columns:n,getRawRange:i,resolvePieceStyle:r}=t,{r:s,projection:a}=o,l=[],c="horizontal"===a;for(const t of Object.values(n))for(const e of t.pieceData){const o=i(e);if(!o)continue;const[n,a]=o,u=r(e,t.name);if(c){const o=s(Math.min(n,a)),i=s(Math.max(n,a));l.push(al(o,t.x,i-o,t.width,u,e,t.name))}else{const o=s(Math.max(n,a)),i=s(Math.min(n,a));l.push(al(t.x,o,t.width,i-o,u,e,t.name))}}return l},funnel:function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r}=t,s=[],a=e.width/2,l=!1!==t.config.showLabels,c=t.scales.o.domain().map(t=>o[t]).filter(Boolean);if(0===c.length)return s;const u=[],d=new Set;for(const t of c)for(const e of t.pieceData){const t=i?i(e):"_default";d.has(t)||(d.add(t),u.push(t))}const h=u.length>1&&"_default"!==u[0],p=[];let f=0;for(const t of c){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}p.push({col:t,groups:e,stepTotal:o}),h||o>f&&(f=o)}if(h)for(const t of p){let e=0,o=0;for(let n=0;u.length>n;n++){const i=t.groups.get(u[n]);i&&(n%2==0?e+=i.total:o+=i.total)}const n=Math.max(e,o);n>f&&(f=n)}if(0===f)return s;const g=new Map;for(const t of u){const e=p[0].groups.get(t);g.set(t,e?.total??0)}const y=p[0].stepTotal,m=h?.95*a:.9*e.width,x=oh().domain([0,f]).range([0,m]),b=t.config.connectorOpacity??.3;let v=new Map;for(let e=0;p.length>e;e++){const o=p[e],n=o.col,i=0===e,c=n.width,d=.55*c,f=n.x+(c-d)/2,m=new Map;if(h){let t=0;for(const e of u){const n=o.groups.get(e);n&&(t+=x(n.total))}let e=a,c=a;for(let h=0;u.length>h;h++){const p=u[h],y=o.groups.get(p);if(!y)continue;const b=x(y.total),v=h%2==0,w=v?e:c-b;v?e+=b:c-=b;const k=r(y.pieces[0],p),A=g.get(p)??y.total,S={...y.pieces[0],__funnelValue:y.total,__funnelPercent:A>0?y.total/A*100:0,__funnelStep:n.name,__funnelIsFirstStep:i,__aggregateValue:y.total,__pieceCount:y.pieces.length,category:p};l&&(0===h&&(S.__funnelStepLabel=n.name,S.__funnelStepLabelX=a,S.__funnelStepLabelY=f,S.__funnelRowWidth=t),S.__funnelValueLabelX=w+b/2,S.__funnelValueLabelY=f,S.__funnelBarW=b),s.push(al(w,f,b,d,k,S,p)),m.set(p,{x:w,y:f,w:b,h:d})}}else{const t=o.stepTotal,e=x(t),c=a-e/2,h=u[0],p="_default"!==h,g=o.groups.get(h)?.pieces[0]??n.pieceData[0],b=p?h:n.name,v=r(g,b),w=y>0?t/y*100:0,k={...g,__funnelValue:t,__funnelPercent:w,__funnelStep:n.name,__funnelIsFirstStep:i,category:p?h:n.name};l&&(k.__funnelStepLabel=n.name,k.__funnelStepLabelX=a,k.__funnelStepLabelY=f,k.__funnelRowWidth=e,k.__funnelValueLabelX=a,k.__funnelValueLabelY=f,k.__funnelBarW=e),s.push(al(c,f,e,d,v,k,b)),m.set(h,{x:c,y:f,w:e,h:d})}if(e>0&&v.size>0){const e=h?u:[u[0]];for(const i of e){const e=v.get(i),a=m.get(i);if(!e||!a)continue;const l=(()=>{const t=o.groups.get(i);return r(t?t.pieces[0]:n.pieceData[0],"_default"===i?n.name:i)})(),c={type:"trapezoid",points:[[e.x,e.y+e.h],[e.x+e.w,e.y+e.h],[a.x+a.w,a.y],[a.x,a.y]],style:{fill:l.fill||t.config.themeSemantic?.secondary||"#999",opacity:b,cursor:l.cursor},datum:o.groups.get(i)?.pieces[0]??n.pieceData[0],category:"_default"===i?n.name:i};s.push(c)}}v=m}return s},"bar-funnel":function(t,e){const{columns:o,getR:n,getStack:i,resolvePieceStyle:r,scales:s}=t,a=[],l=s.o.domain().map(t=>o[t]).filter(Boolean);if(0===l.length)return a;const c=[],u=new Set;for(const t of l)for(const e of t.pieceData){const t=i?i(e):"_default";u.has(t)||(u.add(t),c.push(t))}const d=c.length>1&&"_default"!==c[0],h=[];for(const t of l){const e=new Map;let o=0;for(const r of t.pieceData){const t=i?i(r):"_default";e.has(t)||e.set(t,{total:0,pieces:[]});const s=e.get(t),a=n(r);s.total+=a,s.pieces.push(r),o+=a}h.push({col:t,groups:e,stepTotal:o})}const p=new Map;for(const t of c){const e=h[0]?.groups.get(t);p.set(t,e?.total??0)}const f=s.r,g=d?c.length:1,y=d?.15:0;for(let t=0;h.length>t;t++){const e=h[t],o=e.col,n=0===t,i=t>0?h[t-1]:null,s=o.width/g,l=s*y,u=s-l;for(let t=0;c.length>t;t++){const h=c[t],g=e.groups.get(h);if(!g)continue;const y=g.total,m=p.get(h)??y,x=m>0?y/m*100:0,b=i?.groups.get(h),v=n?0:Math.max(0,(b?.total??y)-y),w=o.x+t*s+l/2,k=f(y),A=f(0)-k,S=r(g.pieces[0],d?h:o.name),M={...g.pieces[0],__barFunnelValue:y,__barFunnelPercent:x,__barFunnelIsFirstStep:n,__barFunnelIsDropoff:!1,__barFunnelStep:o.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:f(y+v)};if(a.push(al(w,k,u,A,S,M,d?h:o.name)),v>0){const t=f(y+v),e=k-t,n={...S},i={...g.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:o.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:o.name};a.push(al(w,t,u,e,n,i,d?h:o.name))}}}return a},swimlane:function(t,e){const{scales:o,columns:n,getR:i,getStack:r,resolvePieceStyle:s}=t,{r:a,projection:l}=o,c=[],u="horizontal"===l,d=t.config.gradientFill,h=u?"left":"bottom",p=new Map,f=e=>{const o=p.get(e);if(void 0!==o)return o;const n="function"==typeof t.config.roundedTop?t.config.roundedTop(e.width):t.config.roundedTop,i="number"==typeof n&&Number.isFinite(n)?Math.max(0,n):0;return p.set(e,i),i},g=t.config.trackFill;if(g){const t="string"==typeof g?g:g.color,e="string"==typeof g?1:g.opacity??1,[o,i]=a.range(),r=Math.min(o,i),s=Math.abs(i-o);for(const o of Object.values(n)){const n={fill:t,opacity:e},i=u?al(r,o.x,s,o.width,n,null,"__track__"):al(o.x,r,o.width,s,n,null,"__track__"),a=f(o);a>0&&(i.cornerRadii={tl:a,tr:a,br:a,bl:a}),c.push(i)}}for(const t of Object.values(n)){let e=0;const o=c.length,n=f(t);for(const o of t.pieceData){const n=Math.abs(i(o));if(0===n)continue;const l=r?r(o):t.name,p=s(o,l);let f;if(u){const i=a(e),r=a(e+n);f=al(i,t.x,r-i,t.width,p,o,l)}else{const i=a(e+n),r=a(e);f=al(t.x,i,t.width,r-i,p,o,l)}d&&(f.fillGradient=d,f.roundedEdge=h),c.push(f),e+=n}if(n>0&&c.length>o){const t=c.slice(o),e=t[0],i=t[t.length-1];1===t.length?e.cornerRadii={tl:n,tr:n,br:n,bl:n}:u?(e.cornerRadii={tl:n,bl:n},i.cornerRadii={tr:n,br:n}):(e.cornerRadii={bl:n,br:n},i.cornerRadii={tl:n,tr:n})}}return c}},ih=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],rh=["scene-style","data-paint","accessibility","evidence"],sh=(t,e)=>({retainedData:t,invalidations:e}),ah=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],lh=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ch=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],uh=["scene-geometry","data-paint","accessibility","evidence"],dh=["scene-style","data-paint","accessibility","evidence"],hh=[],ph={chartType:sh("rebuild",ah),runtimeMode:sh("rebuild",ah),categoryAccessor:sh("rebuild",ah),valueAccessor:sh("rebuild",ah),oAccessor:sh("rebuild",ah),rAccessor:sh("rebuild",ah),stackBy:sh("rebuild",ah),groupBy:sh("rebuild",ah),timeAccessor:sh("rebuild",ah),accessorRevision:sh("rebuild",ah),colorAccessor:sh("rebuild",dh),symbolAccessor:sh("rebuild",uh),connectorAccessor:sh("rebuild",uh),dataIdAccessor:sh("rebuild",uh),projection:sh("preserve",lh),extentPadding:sh("preserve",lh),axisExtent:sh("preserve",lh),rExtent:sh("preserve",lh),oExtent:sh("preserve",lh),multiAxis:sh("preserve",lh),normalize:sh("preserve",lh),bins:sh("preserve",lh),oSort:sh("preserve",ch),barPadding:sh("preserve",ch),roundedTop:sh("preserve",ch),baselinePadding:sh("preserve",ch),innerRadius:sh("preserve",ch),cornerRadius:sh("preserve",ch),startAngle:sh("preserve",ch),sweepAngle:sh("preserve",ch),trackFill:sh("preserve",ch),showOutliers:sh("preserve",ch),showIQR:sh("preserve",ch),amplitude:sh("preserve",ch),connectorOpacity:sh("preserve",ch),showLabels:sh("preserve",ch),dynamicColumnWidth:sh("rebuild",ch),customLayout:sh("preserve",ch),layoutConfig:sh("preserve",ch),layoutMargin:sh("preserve",ch),symbolMap:sh("preserve",uh),pieceStyle:sh("preserve",dh),summaryStyle:sh("preserve",dh),connectorStyle:sh("preserve",dh),gradientFill:sh("preserve",dh),colorScheme:sh("preserve",dh),themeCategorical:sh("preserve",dh),themeSemantic:sh("preserve",dh),themeSequential:sh("preserve",dh),themeDiverging:sh("preserve",dh),barColors:sh("preserve",dh),decay:sh("preserve",dh),pulse:sh("preserve",dh),staleness:sh("preserve",dh),layoutSelection:sh("preserve",dh),windowSize:sh("preserve",hh),windowMode:sh("preserve",hh),clock:sh("preserve",hh),transition:sh("preserve",hh),introAnimation:sh("preserve",hh),onLayoutError:sh("preserve",hh)},fh=sh("preserve",ch),gh=class{constructor(){this.tracker=new o}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},ih)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},rh):this.recordNoop("restyle")}recordConfig(t){const e=function(t){let e="preserve";const o=new Set;for(const n of t){const t=ph[n]??fh;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t);return this.tracker.record({kind:"config",keys:t},e.invalidations)}};import{quadtree as yh}from"d3-quadtree";var mh=class{constructor(t){this.rExtent=new q,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new gh,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new Ud,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=t,this.buffer=new U(t.windowSize),this.getO=wt(t.categoryAccessor||t.oAccessor,"category");const e=t.valueAccessor||t.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(t=>mt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new q)):(this.getR=mt(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=wt(t.stackBy),this.getGroup=wt(t.groupBy),this.getColor=wt(t.colorAccessor),this.getSymbol=wt(t.symbolAccessor),this.getConnector=wt(t.connectorAccessor),this.getDataId=wt(t.dataIdAccessor),t.pulse&&(this.timestampBuffer=new U(t.windowSize))}syncPulseTimestampBuffer(){var t,e,o,n;this.timestampBuffer=(t=!!this.config.pulse,e=this.buffer,o=this.timestampBuffer,n=this.currentTime(),t?null!=o&&o.capacity===e.capacity&&o.size===e.size?o:Il(e,n):null)}currentTime(){return this.config.clock?.()??qa()}ingest(t){const e=this.currentTime();if(this.lastIngestTime=e,this._dataVersion++,t.bounded){this.buffer.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();t.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),Ol(this.buffer,t.totalSize||t.inserts.length,this.timestampBuffer);for(const o of t.inserts)zl(this.buffer,o,this.timestampBuffer,e),this.categories.add(this.getO(o)),this.pushValueExtent(o)}else{this._hasStreamingData=!0;for(const o of t.inserts){const t=zl(this.buffer,o,this.timestampBuffer,e);this.categories.add(this.getO(o)),this.pushValueExtent(o),null!=t&&this.evictValueExtent(t)}}return this.updateResults.recordData(t.bounded?"replace":"ingest",t.inserts.length),!0}ingestWithResult(t){return this.ingest(t),this.updateResults.last}pushValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.push(e[0]),this.rExtent.push(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].push(this.rAccessors[e](t));this.rExtent.push(this.getR(t))}else this.rExtent.push(this.getR(t))}evictValueExtent(t){if("timeline"===this.config.chartType){const e=this.getRawRange(t);e&&(this.rExtent.evict(e[0]),this.rExtent.evict(e[1]))}else if(this.rAccessors.length>1){for(let e=0;this.rAccessors.length>e;e++)this.rExtents[e].evict(this.rAccessors[e](t));this.rExtent.evict(this.getR(t))}else this.rExtent.evict(this.getR(t))}getRawRange(t){const e=this.config.valueAccessor||this.config.rAccessor;if(!e)return null;const o="function"==typeof e?e(t):t[e];return Array.isArray(o)&&o.length>=2?[+o[0],+o[1]]:null}computeScene(t){const{config:e,buffer:o}=this,n=this.scales,i=this.multiScales,r=this.columns;if(0===o.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,void this.version++;this.rExtent.dirty&&this.rExtent.recalculate(o,this.getR);const s=this.getBufferArray(),a=e.projection||"vertical",l=e.oExtent||this.resolveCategories(s),c=this.computeValueDomain(s,l),u="horizontal"===a,d="radial"===a,h=Math.min(.9,Math.max(0,null!=e.barPadding?e.barPadding/("vertical"===a?t.width:t.height):.1));let p,f;if(d){p=Hd().domain(l).range([0,1]).padding(0);const o=Math.min(t.width,t.height)/2,n=e.innerRadius||0;f=qd().domain(c).range([n,o])}else u?(p=Hd().domain(l).range([0,t.height]).padding(h),f=qd().domain(c).range([0,t.width])):(p=Hd().domain(l).range([0,t.width]).padding(h),f=qd().domain(c).range([t.height,0]));this.scales={o:p,r:f,projection:a},this.multiScales=this.rAccessors.length>1&&e.multiAxis?this.rAccessors.map((n,i)=>{const r=this.rExtents[i];r.dirty&&r.recalculate(o,n);let[s,a]=r.extent;s===1/0&&(s=0,a=1);const l=a-s,c=l>0?l*(e.extentPadding??.05):1;return s-=c,a+=c,s>0&&(s=0),u?qd().domain([s,a]).range([0,t.width]):qd().domain([s,a]).range([t.height,0])}):[];let g=s;this.rAccessors.length>1&&(g=s.flatMap(t=>this.rAccessors.map((e,o)=>({...t,__rIndex:o,__rValue:e(t),__rName:this.resolveRAccessorName(o)})))),this.columns=this.buildColumns(g,l,p,a,t),this._customLayoutFailedThisBuild=!1;const y=this.buildSceneNodes(g,t);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=n,this.multiScales=i,this.columns=r):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=y,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,s),this.config.pulse&&this.applyPulse(this.scene,s),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(t){const e=this.config.valueAccessor||this.config.rAccessor,o=Array.isArray(e)?e[t]:e;return"string"==typeof o?o:"value"+t}resolveCategories(t){const e=this.config.oSort,o="streaming"===this.config.runtimeMode||this._hasStreamingData,n="auto"===e?void 0:e;let i=null;if(o){i=new Set;for(const e of t)i.add(this.getO(e))}const r=i?Array.from(this.categories).filter(t=>i.has(t)):Array.from(this.categories);if(o&&void 0===n){const t=Math.max(50,3*i.size);if(this.categories.size>t){let e=this.categories.size-t;for(const t of this.categories){if(0>=e)break;i.has(t)||(this.categories.delete(t),e--)}}return r}if(!1===n)return r;if("function"==typeof n)return r.sort(n);const s=new Map;for(const e of t){const t=this.getO(e);s.set(t,(s.get(t)||0)+Math.abs(this.getR(e)))}return r.sort("asc"===n?(t,e)=>(s.get(t)||0)-(s.get(e)||0):(t,e)=>(s.get(e)||0)-(s.get(t)||0))}computeValueDomain(t,e){return function(t){const{data:e,chartType:o,projection:n,normalize:i,rExtent:r,extentPadding:s=.05,baselinePadding:a,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=t,p=s;if("radial"===n&&("pie"===o||"donut"===o))return[0,1];let f=0,g=0;if("bar"===o&&d&&i)f=0,g=1;else if("bar"===o&&d){const t=new Map,o=new Map;for(const n of e){const e=c(n),i=u(n);0>i?o.set(e,(o.get(e)||0)+i):t.set(e,(t.get(e)||0)+i)}for(const e of t.values())e>g&&(g=e);for(const t of o.values())f>t&&(f=t)}else if("bar"===o){const t=new Map;for(const o of e){const e=c(o),n=u(o);t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e),f>e&&(f=e)}else if("swimlane"===o){const t=new Map;for(const o of e){const e=c(o),n=Math.abs(u(o));t.set(e,(t.get(e)||0)+n)}for(const e of t.values())e>g&&(g=e)}else if("clusterbar"===o||"bar-funnel"===o)for(const t of e){const e=u(t);e>g&&(g=e),f>e&&(f=e)}else{const t=h[0],e=h[1];t!==1/0&&(f=t),e!==-1/0&&(g=e)}r&&(null!=r[0]&&(f=r[0]),null!=r[1]&&(g=r[1]));const y="bar"===o||"clusterbar"===o||"bar-funnel"===o||"swimlane"===o;if(y&&null==r?.[0]&&null==r?.[1]&&(f>0&&(f=0),0>g&&(g=0)),"bar-funnel"!==o&&"exact"!==l){const t=g-f,e=t>0?t*p:1,n=y&&!a&&0===f,i=y&&!a&&0===g||"swimlane"===o;null!=r?.[0]||n||(f-=e),null!=r?.[1]||i||(g+=e)}return[f,g]}({data:t,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(t,e,o,n,i){return function(t){const{data:e,oExtent:o,oScale:n,projection:i,layout:r,dynamicColumnWidth:s,getO:a,getR:l}=t,c=Object.create(null),u=new Map;for(const t of e){const e=a(t);u.has(e)||u.set(e,[]),u.get(e).push(t)}let d=0;if("radial"===i)for(const t of e)d+=Math.abs(l(t));let h=null;if(s&&"radial"!==i){h=new Map;let t=0;for(const e of o){const o=u.get(e)||[];let n;n="string"==typeof s?o.reduce((t,e)=>t+(Number(e[s])||0),0):s(o),h.set(e,n),t+=n}const e=("horizontal"===i?r.height:r.width)-n.padding()*n.step()*o.length;if(t>0)for(const[o,n]of h)h.set(o,n/t*e)}let p=0,f=0;for(const t of o){const e=u.get(t)||[],o=e.reduce((t,e)=>t+Math.abs(l(e)),0),i=d>0?o/d:0;let r,s;h?(r=f,s=h.get(t)||n.bandwidth(),f+=s+n.padding()*n.step()):(r=n(t)??0,s=n.bandwidth()),c[t]={name:t,x:r,y:0,width:s,middle:r+s/2,padding:n.padding()*n.step(),pieceData:e,pct:i,pctStart:p},p+=i}return c}({data:t,oExtent:e,oScale:o,projection:n,layout:i,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(t,e)=>this.styleResolver.resolvePieceStyle(this.config,t,e),resolveSummaryStyle:(t,e)=>this.styleResolver.resolveSummaryStyle(this.config,t,e),getRawRange:t=>this.getRawRange(t)}}buildSceneNodes(t,e){if(!this.scales)return[];if(this.config.customLayout){const o=this.buildLayoutContext(t,e);let n;try{n=this.config.customLayout(o)}catch(t){const e=null!==this.lastCustomLayoutResult,o=Sl("ordinal",t,e,this.version);this.lastCustomLayoutFailure=o,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] ordinal customLayout threw:",t);try{this.config.onLayoutError?.(o)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return e?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;const i=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(const t of i)t.style&&this._baseStyles.set(t,t.style);this.applyCustomRestyle(i,this.config.layoutSelection??null)}return wl({label:"ordinal customLayout",nodes:i,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),i}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;const o=this.getSceneContext(),n=nh[this.config.chartType];let i=n?n(o,e):[];if(this.getConnector&&this.scales){const t=function(t,e){const{scales:o,config:n,getConnector:i,getO:r}=t;if(!i||!o)return[];const s=[],{projection:a}=o,l=new Map;for(const t of e){if("point"!==t.type&&"rect"!==t.type)continue;const e=t.datum;if(!e)continue;const o=i(e);if(!o)continue;let n,s;"point"===t.type?(n=t.x,s=t.y):(n=t.x+t.w/2,s=t.y+("vertical"===a?0:t.h/2)),l.has(o)||l.set(o,[]),l.get(o).push({x:n,y:s,datum:e,category:r(e)})}const c=o.o.domain(),u=n.connectorStyle;for(const[e,o]of l)if(o.length>=2){o.sort((t,e)=>c.indexOf(t.category)-c.indexOf(e.category));for(let n=0;o.length-1>n;n++){const i=o[n],r=o[n+1],a="function"==typeof u?u(i.datum):u||{stroke:t.config.themeSemantic?.border||t.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5};s.push({type:"connector",x1:i.x,y1:i.y,x2:r.x,y2:r.y,style:a,datum:i.datum,group:e})}}return s}(o,i);i=[...t,...i]}return i}buildLayoutContext(t,e){const o=this.config,n=o.layoutMargin??{top:0,right:0,bottom:0,left:0},i=Rr(o.colorScheme,o.themeCategorical,Jt),r=this.scales;return{data:t,scales:{o:r.o,r:r.r,projection:r.projection},dimensions:{width:e.width,height:e.height,margin:n,plot:"radial"===r.projection?{x:-e.width/2,y:-e.height/2,width:e.width,height:e.height}:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:o.themeSemantic??{},categorical:[...i]},resolveColor:Cr(i,o.colorScheme),config:o.layoutConfig??{},selection:o.layoutSelection??null}}computeDecayOpacity(t,e){const o=this.config.decay;return o&&e>1?Ua(o,t,e):1}getDatumIndexMap(t){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;const e=Ka(t);return this._datumIndexCache={version:this._dataVersion,map:e},e}getCategoryIndexMap(t){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;const e=function(t,e){const o="function"==typeof e,n=o?null:e||"category",i=new Map;for(let r=0;t.length>r;r++){const s=t[r],a=o?e(s):s[n],l=i.get(a);l?l.push(r):i.set(a,[r])}return i}(t,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:e},e}rebuildPointQuadtree(){const t=function(t){let e=0,o=0;for(const n of t)"point"===n.type&&!1!==n.interactive&&(e++,n.r>o&&(o=n.r));if(500>=e)return{quadtree:null,maxRadius:o};const n=Array(e);let i=0;for(const e of t)"point"===e.type&&!1!==e.interactive&&(n[i++]=e);return{maxRadius:o,quadtree:yh().x(t=>t.x).y(t=>t.y).addAll(n)}}(this.scene);this._pointQuadtree=t.quadtree,this._maxPointRadius=t.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(t,e){if(!this.config.decay)return;const o=e.length;if(1>=o)return;const n=this.getDatumIndexMap(e);for(const e of t){if("connector"===e.type||"violin"===e.type||"boxplot"===e.type||"wedge"===e.type)continue;if(!e.datum)continue;const t=n.get(e.datum);if(null==t)continue;const i=this.computeDecayOpacity(t,o);e.style={...e.style,opacity:(e.style?.opacity??1)*i}}}applyPulse(t,e,o=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(t,e,o,n,i,r){const s=t.color??"rgba(255,255,255,0.6)",a=t.glowRadius??4;let l=!1;for(const c of e){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){const e=c.category;if(!e)continue;let n=0;for(const s of i(e)??[]){const e=o.get(s);null!=e&&(n=Math.max(n,Za(t,e,r)))}l=Qa(c,n,s)||l;continue}if(null==c.datum)continue;const e=n.get(c.datum);if(null==e)continue;const u=o.get(e);l=Qa(c,null==u?0:Za(t,u,r),s,a)||l}return l}(this.config.pulse,t,this.timestampBuffer,this.getDatumIndexMap(e),t=>this.getCategoryIndexMap(e).get(t),o)}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();const t=new Map,e=this.scales?.r(0)??0,o="horizontal"!==this.scales?.projection;let n;for(let i=0;this.scene.length>i;i++){const r=this.scene[i],s=this.getNodeKey(r,t);s&&("rect"===r.type?this.prevPositionMap.set(s,o?{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}:{x:e,y:r.y,w:0,h:r.h,opacity:r.style.opacity??1}):"point"===r.type?this.prevPositionMap.set(s,{x:r.x,y:r.y,r:0,opacity:0}):"wedge"===r.type&&(void 0===n&&(n=r.startAngle),this.prevPositionMap.set(s,{x:r.cx,y:r.cy,startAngle:n,endAngle:n,innerRadius:r.innerRadius,outerRadius:r.outerRadius,opacity:0})))}}getNodeKey(t,e){if("point"===t.type){const o=`p:${t.datum?this.getO(t.datum):""}:${t.datum?this.getR(t.datum):0}`,n=e.get(o)||0;return e.set(o,n+1),`${o}:${n}`}if("rect"===t.type){const o=t.datum?null!=t.datum.category&&""!==t.datum.category?t.datum.category+"":(this.getO(t.datum)??"")+"":"",n=`r:${t.group||""}:${o}`,i=e.get(n)||0;return e.set(n,i+1),0===i?n:`${n}:${i}`}return"wedge"===t.type?"w:"+(t.category??""):null}snapshotPositions(){this.prevPositionMap.clear();const t=new Map;for(let e=0;this.scene.length>e;e++){const o=this.scene[e],n=this.getNodeKey(o,t);n&&("point"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,r:o.r,opacity:o.style.opacity??o.style.fillOpacity}):"rect"===o.type?this.prevPositionMap.set(n,{x:o.x,y:o.y,w:o.w,h:o.h,opacity:o.style.opacity??o.style.fillOpacity}):"wedge"===o.type&&this.prevPositionMap.set(n,{x:o.cx,y:o.cy,startAngle:o.startAngle,endAngle:o.endAngle,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:o.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;const t=this.config.transition.duration??300;if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}let e=!1;const o=new Set,n=new Map;for(let t=0;this.scene.length>t;t++){const i=this.scene[t],r=this.getNodeKey(i,n);if(!r)continue;i._transitionKey=r;const s=this.prevPositionMap.get(r);if("point"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,(s.x!==i.x||s.y!==i.y||void 0!==s.r&&s.r!==i.r)&&(i._targetX=i.x,i._targetY=i.y,i._targetR=i.r,i.x=s.x,i.y=s.y,void 0!==s.r&&(i.r=s.r),e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetR=i.r,i.r=0,i.style={...i.style,opacity:0},e=!0);else if("rect"===i.type)s?(o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.x===i.x&&s.y===i.y&&s.w===i.w&&s.h===i.h||(i._targetX=i.x,i._targetY=i.y,i._targetW=i.w,i._targetH=i.h,i.x=s.x,i.y=s.y,i.w=s.w??i.w,i.h=s.h??i.h,e=!0)):(i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i.style={...i.style,opacity:0},e=!0);else if("wedge"===i.type)if(s)o.add(r),i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,s.startAngle===i.startAngle&&s.endAngle===i.endAngle||(i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle,i.startAngle=s.startAngle,i.endAngle=s.endAngle,e=!0);else{i._targetOpacity=i.style.opacity??i.style.fillOpacity??1,i._targetStartAngle=i.startAngle,i._targetEndAngle=i.endAngle;const t=i.startAngle;i.startAngle=t,i.endAngle=t,i.style={...i.style,opacity:0},this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:t,endAngle:t,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:0}),e=!0}}this.exitNodes=[];for(const[t,n]of this.prevPositionMap)if(!o.has(t)){if(t.startsWith("p:"))this.exitNodes.push({type:"point",x:n.x,y:n.y,r:n.r??3,style:{opacity:n.opacity??1},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("r:"))this.exitNodes.push({type:"rect",x:n.x,y:n.y,w:n.w??0,h:n.h??0,style:{opacity:n.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:t});else if(t.startsWith("w:")){const e=((n.startAngle??0)+(n.endAngle??0))/2,o={type:"wedge",cx:n.x,cy:n.y,innerRadius:n.innerRadius??0,outerRadius:n.outerRadius??100,startAngle:n.startAngle??0,endAngle:n.endAngle??0,style:{opacity:n.opacity??1},datum:null,category:t.slice(2),_targetStartAngle:e,_targetEndAngle:e,_targetOpacity:0,_transitionKey:t};this.exitNodes.push(o)}e=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),e&&(this.activeTransition={startTime:this.currentTime(),duration:t})}advanceTransition(t){if(!this.activeTransition)return!1;const e=Va(t,this.activeTransition),o=Ga(e,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(const t of this.scene){const e=t._transitionKey;if(e)if("point"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Ha(n?n.opacity??1:0,t._targetOpacity,o)}const n=this.prevPositionMap.get(e);void 0!==t._targetX&&n&&(t.x=Ha(n.x,t._targetX,o),t.y=Ha(n.y,t._targetY,o)),void 0!==t._targetR&&void 0!==n?.r&&(t.r=Ha(n.r,t._targetR,o))}else if("rect"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style.opacity=Ha(n?n.opacity??1:0,t._targetOpacity,o)}if(void 0===t._targetX)continue;const n=this.prevPositionMap.get(e);if(!n)continue;t.x=Ha(n.x,t._targetX,o),t.y=Ha(n.y,t._targetY,o),void 0!==n.w&&(t.w=Ha(n.w,t._targetW,o),t.h=Ha(n.h,t._targetH,o))}else if("wedge"===t.type){if(void 0!==t._targetOpacity){const n=this.prevPositionMap.get(e);t.style={...t.style,opacity:Ha(n?n.opacity??1:0,t._targetOpacity,o)}}if(void 0!==t._targetStartAngle&&void 0!==t._targetEndAngle){const n=this.prevPositionMap.get(e);n&&void 0!==n.startAngle&&(t.startAngle=Ha(n.startAngle,t._targetStartAngle,o),t.endAngle=Ha(n.endAngle,t._targetEndAngle,o))}}}if(e>=1){for(const t of this.scene)if(void 0!==t._targetOpacity&&(t.style={...t.style||{},opacity:0===t._targetOpacity?0:t._targetOpacity},t._targetOpacity=void 0),"point"===t.type){if(void 0===t._targetX&&void 0===t._targetR)continue;void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY),void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0}else if("rect"===t.type){if(void 0===t._targetX)continue;t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0}else"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0);if(this.exitNodes.length>0){const t=new Set(this.exitNodes);this.scene=this.scene.filter(e=>!t.has(e)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(t){for(const e of t){if(void 0!==e._targetOpacity){const t=e._targetOpacity;e.style={...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}"point"===e.type?void 0!==e._targetX?(e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0):void 0!==e._targetR&&(e.r=e._targetR,e._targetR=void 0):"rect"===e.type?void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0):"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(t){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();const e=Xa(t),o=this.getDataId,n=t=>e.has(o(t));Fl(this.buffer,this.timestampBuffer,n);const i=this.buffer.remove(n);if(0===i.length)return this.updateResults.recordNoop("remove"),i;for(const t of i)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach(t=>this.categories.add(this.getO(t))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",i.length),i}update(t,e){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");const o=Xa(t),n=this.getDataId,i=new Set;this.buffer.forEach((t,e)=>{o.has(n(t))&&i.add(e)});const r=this.buffer.update(t=>o.has(n(t)),e);if(0===r.length)return this.updateResults.recordNoop("update"),r;for(const t of r)this.evictValueExtent(t);return this.categories.clear(),this.buffer.forEach((t,e)=>{this.categories.add(this.getO(t)),i.has(e)&&this.pushValueExtent(t)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",r.length),r}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(t,e){const o=this._customRestyle;if(o)for(const n of t){const t=this._baseStyles.get(n)??n.style??{},i=o(n,e);n.style=i?{...t,...i}:t}}restyleScene(t){this._customRestyle?(this.applyCustomRestyle(this.scene,t),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(const t of this.rExtents)t.clear();this._categoryIndexCache=null,this.buffer.forEach(t=>{this.categories.add(this.getO(t)),this.pushValueExtent(t)})}updateConfig(t){const e={...this.config},o=Object.keys(t).filter(o=>t[o]!==e[o]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in t&&t.windowSize!==e.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${e.windowSize} → ${t.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in t&&t.colorScheme!==e.colorScheme||"themeCategorical"in t&&t.themeCategorical!==e.themeCategorical||"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in t&&!yt(t.categoryAccessor,e.categoryAccessor)||"oAccessor"in t&&!yt(t.oAccessor,e.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,t),"pulse"in t&&this.syncPulseTimestampBuffer();let n=!1;("categoryAccessor"in t||"oAccessor"in t)&&(yt(this.config.categoryAccessor||this.config.oAccessor,e.categoryAccessor||e.oAccessor)||(this.getO=wt(this.config.categoryAccessor||this.config.oAccessor,"category"),n=!0));let i=!1;if("valueAccessor"in t||"rAccessor"in t){const t=this.config.valueAccessor||this.config.rAccessor,o=e.valueAccessor||e.rAccessor,n=Array.isArray(t)?t:[t],r=Array.isArray(o)?o:[o];if(i=n.length!==r.length||n.some((t,e)=>!yt(t,r[e])),i){const t=this.config.valueAccessor||this.config.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(t=>mt(t,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new q)):(this.getR=mt(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in t&&!yt(t.stackBy,e.stackBy)&&(this.getStack=null!=this.config.stackBy?wt(this.config.stackBy):void 0),"groupBy"in t&&!yt(t.groupBy,e.groupBy)&&(this.getGroup=null!=this.config.groupBy?wt(this.config.groupBy):void 0),"colorAccessor"in t&&!yt(t.colorAccessor,e.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?wt(this.config.colorAccessor):void 0),"symbolAccessor"in t&&!yt(t.symbolAccessor,e.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?wt(this.config.symbolAccessor):void 0),"connectorAccessor"in t&&!yt(t.connectorAccessor,e.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?wt(this.config.connectorAccessor):void 0),(n||i||"accessorRevision"in t&&t.accessorRevision!==e.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(o)}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}};Xl(mh);import*as xh from"react";import{jsx as bh,jsxs as vh}from"react/jsx-runtime";function wh(t){return"connector"===t.node.type}function kh(t,e,o,n){if(2>t.length)return null;const i=t[0].node,r=i.style.fill;if(!r||"none"===r)return null;const s=yc(`${e?e+"-":""}connector-${o}-${n}-hatch`),a=ot(r)?et(r,s):null,l=[`${i.x1},${i.y1}`,...t.map(({node:t})=>`${t.x2},${t.y2}`)].join(" ");return Ac(vh(xh.Fragment,{children:[a&&bh("defs",{children:a}),bh("polygon",{points:l,fill:a?`url(#${s})`:gc(r,"#999"),opacity:i.style.fillOpacity??i.style.opacity??.3,"data-semiotic-connector-fill":i.group||"_default"})]}),i,`ordinal-connector-fill-${o}-${n}`)}function Ah(t,e,o){const n=new Map;for(const e of t){if(!wh(e))continue;const t=e.node.group||"_default",o=n.get(t);o?o.push(e):n.set(t,[e])}if(0===n.size)return;const i=Array.from(n.values()).map((t,n)=>vh("g",{children:[kh(t,e,o,n),t.map(t=>t.element)]},`ordinal-connectors-${o}-${n}`)),r=t[0],s=wh(r)?null:r.element;for(const t of n.values())for(const e of t)e.element=null;r.element=vh(xh.Fragment,{children:[i,s]},"ordinal-connector-run-"+o)}function Sh(t){const e=Vc({nodes:t.nodes,renderMode:t.renderMode,fallback:(e,o)=>Dc(e,o,t.idPrefix)});let o=0;for(let n=0;e.length>n;){if(e[n].renderedByBackend){n++;continue}let i=n+1;for(;e.length>i&&!e[i].renderedByBackend;)i++;Ah(e.slice(n,i),t.idPrefix,o++),n=i}return e}import{jsx as Mh,jsxs as _h}from"react/jsx-runtime";import{Fragment as Ph,jsx as Lh,jsxs as $h}from"react/jsx-runtime";var Rh=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function Ch(t,e){const o=ye(t.theme),n=t.size||[500,400],i=qe({...zd,...t.margin},t.title),r=Ve(t.title),s=Ht(t.data),a=t.showLegend?iu(s,t.colorAccessor||t.stackBy||t.groupBy):[],l=function(t){const e=t.projection??"vertical",o=!1!==t.showAxes&&"radial"!==e;return{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasValueLabel:t.hasCategoryLabel),leftAxis:{hasAxis:o,hasAxisLabel:o&&("horizontal"===e?t.hasCategoryLabel:t.hasValueLabel)}}}({showAxes:t.showAxes,projection:t.projection,hasCategoryLabel:!(!t.categoryLabel&&!t.oLabel),hasValueLabel:!(!t.valueLabel&&!t.rLabel)});Ld(i,{props:{...t,axisChrome:l},categories:a,theme:o,size:n,hasTitle:r});const c=$d({props:{...t,axisChrome:l},categories:a,theme:o,size:n,margin:i,hasTitle:r}),u=n[0]-i.left-i.right,d=n[1]-i.top-i.bottom,h=t.projection||"vertical",p="radial"===h,f=t.colorScheme||o.colors.categorical,g={chartType:t.chartType,windowSize:t.windowSize??1e4,windowMode:t.windowMode??"sliding",extentPadding:t.extentPadding??.05,projection:h,oAccessor:t.oAccessor,rAccessor:t.rAccessor,colorAccessor:t.colorAccessor,stackBy:t.stackBy,groupBy:t.groupBy,categoryAccessor:t.categoryAccessor,valueAccessor:t.valueAccessor,timeAccessor:t.timeAccessor,rExtent:t.rExtent,oExtent:t.oExtent,axisExtent:t.axisExtent,barPadding:t.barPadding,roundedTop:t.roundedTop,innerRadius:t.innerRadius,cornerRadius:t.cornerRadius,normalize:t.normalize,startAngle:t.startAngle,sweepAngle:t.sweepAngle,bins:t.bins,showOutliers:t.showOutliers,showIQR:t.showIQR,amplitude:t.amplitude,oSort:t.oSort,connectorAccessor:t.connectorAccessor,connectorStyle:t.connectorStyle,dynamicColumnWidth:t.dynamicColumnWidth,pieceStyle:t.pieceStyle,summaryStyle:t.summaryStyle,gradientFill:ce(t.gradientFill),symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,multiAxis:t.multiAxis,baselinePadding:t.baselinePadding,trackFill:t.trackFill,connectorOpacity:t.connectorOpacity,showLabels:t.showLabels,colorScheme:f,themeCategorical:o.colors.categorical,themeSemantic:Rt(o),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,layoutSelection:t.layoutSelection,barColors:t.barColors},y=new mh(g);t.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:u,height:d});const m=Id(t.backgroundGraphics,n,i,y.scales),x=Id(t.foregroundGraphics,n,i,y.scales);if(!y.scales){let r;const a=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{},layout:{width:u,height:d},theme:o,projection:h,idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:i})),Vd.renderToStaticMarkup(Cd(m||x||t.annotations?$h(Ph,{children:[m,a,x,y.customLayoutOverlays]}):null,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}const b=t._idPrefix,v=t.showGrid?function(t,e,o,n,i){const r=t.scales;if(!r||"radial"===r.projection)return null;const{grid:s}=me(o),a=n?n+"-":"",l="vertical"===r.projection,c=hd(r.r,5,i);return vd("g",l?{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return vd("line",{x1:0,y1:n,x2:e.width,y2:n,stroke:s,strokeWidth:.5},"gr-"+o)})}:{id:a+"grid",className:"semiotic-grid",opacity:.8,children:c.map((t,o)=>{const n=r.r(t);return vd("line",{x1:n,y1:0,x2:n,y2:e.height,stroke:s,strokeWidth:.5},"gr-"+o)})})}(y,{width:u,height:d},o,b,t.axisExtent):null;let w=null;if(y.scene.some(t=>"rect"===t.type&&t.datum?.__barFunnelIsDropoff)){const e=Ad(t),n=new Set;for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&n.add("string"==typeof t.style.fill?t.style.fill:"#666");w=Array.from(n).map((t,n)=>function(t){const{id:e,background:o="transparent",stroke:n="#000",lineWidth:i=1.5,spacing:r=6,angle:s=45}=t,a=Math.max(8,Math.ceil(2*r));return _h("pattern",{id:e,width:a,height:a,patternUnits:"userSpaceOnUse",patternTransform:0!==s?`rotate(${s})`:void 0,children:[o&&"transparent"!==o&&Mh("rect",{width:a,height:a,fill:o}),Mh("line",{x1:0,y1:0,x2:0,y2:a,stroke:n,strokeWidth:i}),Mh("line",{x1:r,y1:0,x2:r,y2:a,stroke:n,strokeWidth:i})]},e)}({id:`funnel-hatch-${e}-${n}`,background:t,stroke:"transparent"===o.colors.background?"#fff":o.colors.background,lineWidth:1.5,spacing:5,angle:45}));const i=new Map;Array.from(n).forEach((t,o)=>i.set(t,`funnel-hatch-${e}-${o}`));for(const t of y.scene)"rect"===t.type&&t.datum?.__barFunnelIsDropoff&&(t.style={...t.style,fill:`url(#${i.get("string"==typeof t.style.fill?t.style.fill:"#666")})`})}const k=Sh({nodes:y.scene,renderMode:t.renderMode,idPrefix:b}),A=k.map(t=>t.element),S=!1!==t.showAxes?function(t,e,o,n,i,r,s,a=!1){const l=t.scales;if(!l)return null;if("radial"===l.projection)return null;const c=me(n),u="vertical"===l.projection,d=t.columns,h=o.categoryFormat||o.oFormat,p=o.valueFormat||o.rFormat,f=o.categoryLabel||o.oLabel,g=o.valueLabel||o.rLabel,y=o.legendPosition??"right",m=Je(o.legendLayout,s?.leftAxis),x=a&&"left"===y&&m>0?m:r?.left??o.margin?.left??40,b=Object.values(d).map((t,e)=>({pixel:t.middle,label:h?h(t.name,e):t.name})),v=hd(l.r,5,o.axisExtent).map(t=>({pixel:l.r(t),label:(p||Rd)(t)}));return $h("g",u?{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Lh("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,o)=>$h("g",{transform:`translate(${t.pixel},${e.height})`,children:[Lh("line",{y2:5,stroke:c.border,strokeWidth:1}),fd(t.label)?Lh("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):gd({label:t.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oxtick-"+o)),f&&Lh("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:f}),Lh("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,e)=>$h("g",{transform:`translate(0,${t.pixel})`,children:[Lh("line",{x2:-5,stroke:c.border,strokeWidth:1}),Lh("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oytick-"+e)),g&&Lh("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:g})]}:{id:(i?i+"-":"")+"axes",className:"ordinal-axes",children:[Lh("line",{x1:0,y1:e.height,x2:e.width,y2:e.height,stroke:c.border,strokeWidth:1}),v.map((t,o)=>$h("g",{transform:`translate(${t.pixel},${e.height})`,children:[Lh("line",{y2:5,stroke:c.border,strokeWidth:1}),Lh("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label})]},"oxtick-"+o)),g&&Lh("text",{x:e.width/2,y:e.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),Lh("line",{x1:0,y1:0,x2:0,y2:e.height,stroke:c.border,strokeWidth:1}),b.map((t,e)=>$h("g",{transform:`translate(0,${t.pixel})`,children:[Lh("line",{x2:-5,stroke:c.border,strokeWidth:1}),fd(t.label)?Lh("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:t.label}):gd({label:t.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"oytick-"+e)),f&&Lh("text",{x:15-x,y:e.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${e.height/2})`,children:f})]})}(y,{width:u,height:d},t,o,b,i,l,!!c):null;let M;const _=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:s,scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:u,height:d},theme:o,projection:h,xAccessor:"string"==typeof t.oAccessor?t.oAccessor:void 0,yAccessor:"string"==typeof t.rAccessor?t.rAccessor:void 0,idPrefix:b,onRender:t=>{M=t}}):null;if(e){const o=y.scales.o?.domain?.();e.evidence=Ba({frameType:"ordinal",width:n[0],height:n[1],marks:k.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:M,yDomain:Wa(y.scales.r?.domain?.()),categories:Array.isArray(o)?o.map(String):void 0,margin:i})}const P=p&&t.centerContent?function(t,e,o){if(!Gd.isValidElement(t))return null;if("string"!=typeof t.type||!Rh.has(t.type))return null;const n=t,i="text"===n.type?Gd.cloneElement(n,{x:n.props.x??0,y:n.props.y??0,textAnchor:n.props.textAnchor??"middle",dominantBaseline:n.props.dominantBaseline??"middle"}):n;return Lh("g",{className:"semiotic-radial-center-content",transform:`translate(${e},${o})`,pointerEvents:"none",children:i})}(t.centerContent,i.left+u/2,i.top+d/2):null,L=p&&t.centerContent?P??Lh("foreignObject",{x:i.left,y:i.top,width:u,height:d,pointerEvents:"none",children:Lh("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:t.centerContent})}):null,$=$h(Ph,{children:[v,A,S,_,x,y.customLayoutOverlays]});return Vd.renderToStaticMarkup(Cd($h(Ph,p?{children:[m?Lh("g",{transform:`translate(${-u/2},${-d/2})`,children:m}):null,$]}:{children:[m,$]}),{width:n[0],height:n[1],className:"stream-ordinal-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:p?`translate(${i.left+u/2},${i.top+d/2})`:`translate(${i.left},${i.top})`,innerWidth:u,innerHeight:d,legend:c,defs:w,outerElements:L,idPrefix:t._idPrefix}))}import*as Th from"react-dom/server.browser";function Oh(t,e){var o=t.get(e);if(!o)throw Error("missing: "+e);return o}function Ih(t,e){var o,n=[],i=[],r=[],s={},a=[];function l(t){r[t]=!1,s.hasOwnProperty(t)&&Object.keys(s[t]).forEach(function(e){delete s[t][e],r[e]&&l(e)})}function c(t){var e,n,d=!1;for(i.push(t),r[t]=!0,e=0;a[t].length>e;e++)(n=a[t][e])===o?(u(o,i),d=!0):r[n]||(d=c(n));if(d)l(t);else for(e=0;a[t].length>e;e++){var h=s[n=a[t][e]];h||(s[n]=h={}),h[n]=!0}return i.pop(),d}function u(t,o){var i=[].concat(o).concat(t);e?e(i):n.push(i)}function d(e){!function(e){for(var o=0;t.length>o;o++)o>=e&&t[o]||(t[o]=[]),t[o]=t[o].filter(function(t){return t>=e})}(e);for(var o,n=function(t){for(var e=t.length,o=Array(e),n=Array(e),i=Array(e),r=Array(e),s=Array(e),a=Array(e),l=0;e>l;++l)o[l]=-1,n[l]=0,i[l]=!1,r[l]=0,s[l]=-1,a[l]=[];var c,u=0,d=[],h=[];function p(e){var l=[e],c=[e];for(o[e]=n[e]=u,i[e]=!0,u+=1;c.length>0;){var p=t[e=c[c.length-1]];if(p.length>r[e]){for(var f=r[e];p.length>f;++f){var g=p[f];if(0>o[g]){o[g]=n[g]=u,i[g]=!0,u+=1,l.push(g),c.push(g);break}i[g]&&(n[e]=0|Math.min(n[e],n[g])),0>s[g]||a[e].push(s[g])}r[e]=f}else{if(n[e]===o[e]){var y=[],m=[],x=0;for(f=l.length-1;f>=0;--f){var b=l[f];if(i[b]=!1,y.push(b),m.push(a[b]),x+=a[b].length,s[b]=d.length,b===e){l.length=f;break}}d.push(y);var v=Array(x);for(f=0;m.length>f;f++)for(var w=0;m[f].length>w;w++)v[--x]=m[f][w];h.push(v)}c.pop()}}}for(l=0;e>l;++l)0>o[l]&&p(l);for(l=0;h.length>l;l++){var f=h[l];if(0!==f.length){f.sort(function(t,e){return t-e}),c=[f[0]];for(var g=1;f.length>g;g++)f[g]!==f[g-1]&&c.push(f[g]);h[l]=c}}return{components:d,adjacencyList:h}}(t),i=n.components.filter(function(t){return t.length>1}),r=1/0,s=0;i.length>s;s++)for(var a=0;i[s].length>a;a++)r>i[s][a]&&(r=i[s][a],o=s);var l=i[o];return!!l&&{leastVertex:r,adjList:t.map(function(t,e){return-1===l.indexOf(e)?[]:t.filter(function(t){return-1!==l.indexOf(t)})})}}o=0;for(var h=t.length;h>o;){var p=d(o);if(o=p.leastVertex,a=p.adjList){for(var f=0;a.length>f;f++)for(var g=0;a[f].length>g;g++){var y=a[f][g];r[+y]=!1,s[y]={}}c(o),o+=1}else o=h}return e?void 0:n}function zh(t){return t.y0-t.y1>0?"up":"down"}function Fh(t,e){return e(t.source)==e(t.target)}function Nh(t){var e=0;t.source.sourceLinks.forEach(function(t){e=t.circular?e+1:e});var o=0;return t.target.targetLinks.forEach(function(t){o=t.circular?o+1:o}),1>=e&&1>=o}function Eh(t){return t.target.x0-t.source.x1}function Dh(t,e){var o=Bh(t),n=Eh(e)/Math.tan(o);return"up"==zh(t)?t.y1-n:t.y1+n}function Wh(t,e){var o=Bh(t),n=Eh(e)/Math.tan(o);return"up"==zh(t)?t.y1+n:t.y1-n}function Bh(t){var e=Math.abs(t.y1-t.y0);return Math.atan(Math.abs(t.target.x0-t.source.x1)/e)}function jh(t,e){return e(t)}function Yh(t){return Gh(t.source)}function Xh(t){return Gh(t.target)}function Gh(t){return(t.y0+t.y1)/2}function Vh(t){return t.virtual?0:t.value}function Hh(t,e){var o=0;t.sourceLinks.forEach(function(t){o=t.circular&&!Fh(t,e)?o+1:o});var n=0;return t.targetLinks.forEach(function(t){n=t.circular&&!Fh(t,e)?n+1:n}),o+n}function qh(t){return t.target.depth}function Uh(t,e){return t.sourceLinks.length?t.depth:e-1}function Kh(t,e){return t.y0-e.y0}function Zh(t,e){return e.y0-t.y0}function Qh(t,e){return t.y1-e.y1}function Jh(t,e){return e.y1-t.y1}function tp(t,e){return op(t.source,e.source)||t.index-e.index}function ep(t,e){return op(t.target,e.target)||t.index-e.index}function op(t,e){return t.partOfCycle===e.partOfCycle?t.y0-e.y0:"top"===t.circularLinkType||"bottom"===e.circularLinkType?-1:1}function np(t,e){return ip(t)==ip(e)?"bottom"==t.circularLinkType?Zh(t,e):Kh(t,e):ip(e)-ip(t)}function ip(t){return t.target.column-t.source.column}function rp(t,e){return sp(t)==sp(e)}function sp(t){return t.y0-t.y1>0?"up":"down"}import{min as ap}from"d3-array";function lp(t,e,o,n,i){let r=t;var s=Math.max(8,.15*(r.y1-r.y0));r.links.forEach(function(t){t.circular&&(t._circularWidth=Math.min(t.width,s))});var a=ap(r.links,function(t){return t.source.y0});r.links.forEach(function(t){t.circular&&(t.circularPathData={})});var l=r.links.filter(function(t){return t.circular});return l.sort(function(t,e){return e.value-t.value}),l.forEach(function(t,e){t._circularStub=e>=4}),cp(r.links.filter(function(t){return"top"==t.circularLinkType}),e,o),cp(r.links.filter(function(t){return"bottom"==t.circularLinkType}),e,o),r.links.forEach(function(t){if(t.circular){if(t.circularPathData.arcRadius=t._circularWidth+n,t.circularPathData.rightNodeBuffer=5,t.circularPathData.leftNodeBuffer=5,t.circularPathData.sourceWidth=t.source.x1-t.source.x0,t.circularPathData.sourceX=t.source.x0+t.circularPathData.sourceWidth,t.circularPathData.targetX=t.target.x0,t.circularPathData.sourceY=t.y0,t.circularPathData.targetY=t.y1,Fh(t,e)&&Nh(t))t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2,t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2,"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=t.source.y1+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=t.source.y0-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius);else{var s=t.source.column,l=t.circularLinkType,c=r.links.filter(function(t){return t.source.column==s&&t.circularLinkType==l});c.sort("bottom"==t.circularLinkType?Zh:Kh);var u=0;c.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.rightSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.rightLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),s=t.target.column,(c=r.links.filter(function(t){return t.target.column==s&&t.circularLinkType==l})).sort("bottom"==t.circularLinkType?Jh:Qh),u=0,c.forEach(function(e,i){e.circularLinkID==t.circularLinkID&&(t.circularPathData.leftSmallArcRadius=n+t._circularWidth/2+u,t.circularPathData.leftLargeArcRadius=n+t._circularWidth/2+i*o+u),u+=e._circularWidth||e.width}),"bottom"==t.circularLinkType?(t.circularPathData.verticalFullExtent=Math.max(r.y1,t.source.y1,t.target.y1)+i+t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent-t.circularPathData.leftLargeArcRadius):(t.circularPathData.verticalFullExtent=a-i-t.circularPathData.verticalBuffer,t.circularPathData.verticalRightInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.rightLargeArcRadius,t.circularPathData.verticalLeftInnerExtent=t.circularPathData.verticalFullExtent+t.circularPathData.leftLargeArcRadius)}t.circularPathData.rightInnerExtent=t.circularPathData.sourceX+t.circularPathData.rightNodeBuffer,t.circularPathData.leftInnerExtent=t.circularPathData.targetX-t.circularPathData.leftNodeBuffer,t.circularPathData.rightFullExtent=t.circularPathData.sourceX+t.circularPathData.rightLargeArcRadius+t.circularPathData.rightNodeBuffer,t.circularPathData.leftFullExtent=t.circularPathData.targetX-t.circularPathData.leftLargeArcRadius-t.circularPathData.leftNodeBuffer}t.path=t.circular?function(t){return"top"==t.circularLinkType?"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 0 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY-t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 0 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 0 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY-t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 0 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY:"M"+t.circularPathData.sourceX+" "+t.circularPathData.sourceY+" L"+t.circularPathData.rightInnerExtent+" "+t.circularPathData.sourceY+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightSmallArcRadius+" 0 0 1 "+t.circularPathData.rightFullExtent+" "+(t.circularPathData.sourceY+t.circularPathData.rightSmallArcRadius)+" L"+t.circularPathData.rightFullExtent+" "+t.circularPathData.verticalRightInnerExtent+" A"+t.circularPathData.rightLargeArcRadius+" "+t.circularPathData.rightLargeArcRadius+" 0 0 1 "+t.circularPathData.rightInnerExtent+" "+t.circularPathData.verticalFullExtent+" L"+t.circularPathData.leftInnerExtent+" "+t.circularPathData.verticalFullExtent+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftLargeArcRadius+" 0 0 1 "+t.circularPathData.leftFullExtent+" "+t.circularPathData.verticalLeftInnerExtent+" L"+t.circularPathData.leftFullExtent+" "+(t.circularPathData.targetY+t.circularPathData.leftSmallArcRadius)+" A"+t.circularPathData.leftLargeArcRadius+" "+t.circularPathData.leftSmallArcRadius+" 0 0 1 "+t.circularPathData.leftInnerExtent+" "+t.circularPathData.targetY+" L"+t.circularPathData.targetX+" "+t.circularPathData.targetY}(t):function(t){var e=t.source.x1,o=t.y0,n=t.target.x0,i=t.y1,r=(e+n)/2;return"M"+e+","+o+"C"+r+","+o+" "+r+","+i+" "+n+","+i}(t)}),r}function cp(t,e,o){t.sort(np);var n=t.filter(function(t){return!t._circularStub});return t.forEach(function(t,i){var r=0;if(t._circularStub)t.circularPathData.verticalBuffer=0;else if(Fh(t,e)&&Nh(t))t.circularPathData.verticalBuffer=r+t._circularWidth/2;else{for(var s=0;n.length>s;s++){var a=n[s];if(a!==t&&a.circularPathData&&void 0!==a.circularPathData.verticalBuffer&&up(t,a)){var l=a.circularPathData.verticalBuffer+(a._circularWidth||a.width)/2+o;r=l>r?l:r}}t.circularPathData.verticalBuffer=r+t._circularWidth/2}}),t}function up(t,e){return t.source.column>=e.target.column&&e.source.column>=t.target.column}import{min as dp,max as hp,sum as pp,mean as fp,group as gp,groups as yp}from"d3-array";function mp(t){return function(){return t}}function xp(t){return t.index}function bp(t){return t.nodes}function vp(t){return t.links}function wp(t,e,o){var n=yp(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});n.forEach(function(i,r){var s=i.length;if(e)i.sort(e);else if(r>0){var a=new Map;i.forEach(function(t,e){var o,n,i,r=(n=0,i=0,(o=t).targetLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Gh(t.source)*e,n+=e}}),o.sourceLinks.forEach(function(t){if(!t.circular){var e=t.value||1;i+=Gh(t.target)*e,n+=e}}),n>0?i/n:NaN);a.set(t,{bc:r,idx:e})}),i.sort(function(t,e){var o=a.get(t),n=a.get(e),i=o.bc,r=n.bc;if(t.circularLinkType!==e.circularLinkType){if("top"==t.circularLinkType&&"bottom"==e.circularLinkType)return-1;if("bottom"==t.circularLinkType&&"top"==e.circularLinkType)return 1;if("top"==t.circularLinkType)return-1;if("top"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return 1;if("bottom"==e.circularLinkType)return-1}return isNaN(i)||isNaN(r)?isNaN(i)?isNaN(r)?o.idx-n.idx:1:-1:i-r})}else i.sort(function(t,e){return t.circularLinkType==e.circularLinkType?Hh(e,o)-Hh(t,o):"top"==t.circularLinkType&&"bottom"==e.circularLinkType||"top"==t.circularLinkType&&0==e.partOfCycle||0==t.partOfCycle&&"bottom"==e.circularLinkType?-1:0});i.forEach(function(e,i){e.depth==n.length-1&&1==s||0==e.depth&&1==s?(e.y0=t.y1/2-e.value*t.ky,e.y1=e.y0+e.value*t.ky):e.partOfCycle?0==Hh(e,o)?(e.y0=t.y1/2+i,e.y1=e.y0+e.value*t.ky):"top"==e.circularLinkType?(e.y0=t.y0+i,e.y1=e.y0+e.value*t.ky):(e.y0=t.y1-e.value*t.ky-i,e.y1=e.y0+e.value*t.ky):0==t.y0||0==t.y1?(e.y0=(t.y1-t.y0)/s*i,e.y1=e.y0+e.value*t.ky):(e.y0=(t.y1-t.y0)/2-s/2+i,e.y1=e.y0+e.value*t.ky)})})}function kp(t,e,o,n,i,r){var s=yp(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});u();for(var a=1,l=r;l>0;--l)c(a*=.99,o),u();function c(e,o){var n=s.length;s.forEach(function(i){var r=i.length,s=i[0].depth;i.forEach(function(i){var a;if(i.sourceLinks.length||i.targetLinks.length)if(i.partOfCycle&&Hh(i,o)>0){var l=fp(i.sourceLinks,Xh),c=fp(i.targetLinks,Yh),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-Gh(i))*e*.3;i.y0+=d,i.y1+=d}}else if(0==s&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(s==n-1&&1==r)i.y0=t.y1/2-(a=i.y1-i.y0)/2,i.y1=t.y1/2+a/2;else if(1==i.targetLinks.length&&1==i.targetLinks[0].source.sourceLinks.length)a=i.y1-i.y0,i.y0=i.targetLinks[0].source.y0,i.y1=i.y0+a;else{var h=fp(i.sourceLinks,Xh),p=fp(i.targetLinks,Yh),f=((h&&p?(h+p)/2:h||p)-Gh(i))*e;i.y0+=f,i.y1+=f}})})}function u(){s.forEach(function(o){var r,s,a,l=t.y0,c=o.length;for(o.sort(e||op),a=0;c>a;++a)(s=l-(r=o[a]).y0)>0&&(r.y0+=s,r.y1+=s),l=r.y1+n;if((s=l-n-t.y1)>0)for(l=r.y0-=s,r.y1-=s,a=c-2;a>=0;--a)(s=(r=o[a]).y1+i-l)>0&&(r.y0-=s,r.y1-=s),l=r.y0})}}function Ap(t){t.nodes.forEach(function(t){t.sourceLinks.sort(ep),t.targetLinks.sort(tp)}),t.nodes.forEach(function(t){var e=t.y0,o=e,n=t.y1,i=n;t.sourceLinks.forEach(function(t){t.circular?(t.y0=n-t.width/2,n-=t.width):(t.y0=e+t.width/2,e+=t.width)}),t.targetLinks.forEach(function(t){t.circular?(t.y1=i-t.width/2,i-=t.width):(t.y1=o+t.width/2,o+=t.width)})})}function Sp(){var t=0,e=0,o=1,n=1,i=24,r=8,s=null,a=xp,l=Uh,c=void 0,u=32,d=2,h=bp,p=vp;function f(){var f={nodes:h.apply(null,arguments),links:p.apply(null,arguments)};return function(h){h.x0=t,h.y0=e,h.x1=o,h.y1=n,h.py=0,function(t,e){t.nodes.forEach(function(t,e){t.index=e,t.sourceLinks=[],t.targetLinks=[]});var o=function(t,e){var o=new Map;return gp(t,e).forEach(function(t,e){o.set(e,t[0])}),o}(t.nodes,e);t.links.forEach(function(t,e){t.index=e;var n=t.source,i=t.target;"object"!=typeof n&&(n=t.source=Oh(o,n)),"object"!=typeof i&&(i=t.target=Oh(o,i)),n.sourceLinks.push(t),i.targetLinks.push(t)})}(h,a),function(t,e){var o=0;if(null==e){for(var n=[],i=0;t.links.length>i;i++){var r=t.links[i],s=r.source.index,a=r.target.index;n[s]||(n[s]=[]),n[a]||(n[a]=[]),-1===n[s].indexOf(a)&&n[s].push(a)}var l=Ih(n);l.sort(function(t,e){return t.length-e.length});var c={};for(i=0;l.length>i;i++){var u=l[i].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}t.links.forEach(function(t){var e=t.target.index,n=t.source.index;e===n||c[n]&&c[n][e]?(t.circular=!0,t.circularLinkID=o++):t.circular=!1})}else t.links.forEach(function(t){e(t.source)<e(t.target)?t.circular=!1:(t.circular=!0,t.circularLinkID=o++)})}(h,c),function(t,e){var o=0,n=0;t.links.forEach(function(i){i.circular&&(i.circularLinkType=i.source.circularLinkType||i.target.circularLinkType?i.source.circularLinkType?i.source.circularLinkType:i.target.circularLinkType:n>o?"top":"bottom","top"==i.circularLinkType?o++:n++,t.nodes.forEach(function(t){jh(t,e)!=jh(i.source,e)&&jh(t,e)!=jh(i.target,e)||(t.circularLinkType=i.circularLinkType)}))}),t.links.forEach(function(t){t.circular&&(t.source.circularLinkType==t.target.circularLinkType&&(t.circularLinkType=t.source.circularLinkType),Fh(t,e)&&(t.circularLinkType=t.source.circularLinkType))})}(h,a),function(t){t.nodes.forEach(function(t){t.partOfCycle=!1,t.value=Math.max(pp(t.sourceLinks,Vh),pp(t.targetLinks,Vh)),t.sourceLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)}),t.targetLinks.forEach(function(e){e.circular&&(t.partOfCycle=!0,t.circularLinkType=e.circularLinkType)})})}(h),function(t,e,o){var n,i,r;if(null!=e){t.nodes.sort(function(t,o){return e(t)<e(o)?-1:1});var s=0,a=e(t.nodes[0]);t.nodes.forEach(function(t){s=e(t)==a?s:s+1,a=e(t)==a?a:e(t),t.column=s})}for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.depth=r,t.sourceLinks.forEach(function(t){0>i.indexOf(t.target)&&!t.circular&&i.push(t.target)})});for(n=t.nodes,i=[],r=0;n.length;++r,n=i,i=[])n.forEach(function(t){t.height=r,t.targetLinks.forEach(function(t){0>i.indexOf(t.source)&&!t.circular&&i.push(t.source)})});t.nodes.forEach(function(t){t.column=null==e?o(t,r):t.column})}(h,c,l);var p=r;if(null!==s){var f=yp(h.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]}),g=hp(f,function(t){return t.length});g>1&&(p=Math.max(1,(n-e)*s/(g-1)))}(function(t,e,o){var n=yp(t.nodes,function(t){return t.column}).sort(function(t,e){return t[0]-e[0]}).map(function(t){return t[1]});t.py=e;var i=dp(n,function(e){return(t.y1-t.y0-(e.length-1)*t.py)/pp(e,function(t){return t.value})});t.ky=i,t.links.forEach(function(e){e.width=e.value*t.ky});var r=hp(t.nodes,function(t){return t.column});t.nodes.forEach(r>0?function(e){e.x0=t.x0+e.column*((t.x1-t.x0-o)/r),e.x1=e.x0+o}:function(e){e.x0=t.x0,e.x1=e.x0+o})})(h,p,i),wp(h,c,a),kp(h,c,a,p,p,u),Ap(h),lp(h,a,d,10,8),wp(h,c,a),kp(h,c,a,p,p,u),Ap(h),lp(h,a,d,10,8),function(t,e){let o=t;o.nodes.forEach(function(t){t.y+(t.y1-t.y0)>o.y1&&(t.y=t.y-(t.y+(t.y1-t.y0)-o.y1));var n=o.links.filter(function(o){return jh(o.source,e)==jh(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.target.column==e.target.column)return t.y1-e.y1;if(!rp(t,e))return t.y1-e.y1;if(t.target.column>e.target.column){var o=Dh(e,t);return t.y1-o}if(e.target.column>t.target.column)return Dh(t,e)-e.y1}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.target.column===e.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.target.column===e.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;n.forEach(function(t){t.y0=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y0=t.y1-s-e.width/2}})})}(h,a),function(t,e){let o=t;o.nodes.forEach(function(t){var n=o.links.filter(function(o){return jh(o.target,e)==jh(t,e)}),i=n.length;i>1&&n.sort(function(t,e){if(!t.circular&&!e.circular){if(t.source.column==e.source.column)return t.y0-e.y0;if(!rp(t,e))return t.y0-e.y0;if(t.source.column>e.source.column){var o=Wh(e,t);return t.y0-o}if(e.source.column>t.source.column)return Wh(t,e)-e.y0}return t.circular&&!e.circular?"top"==t.circularLinkType?-1:1:e.circular&&!t.circular?"top"==e.circularLinkType?1:-1:t.circular&&e.circular?t.circularLinkType===e.circularLinkType&&"top"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:t.source.column-e.source.column:t.circularLinkType===e.circularLinkType&&"bottom"==t.circularLinkType?t.source.column===e.source.column?t.source.y1-e.source.y1:e.source.column-t.source.column:"top"==t.circularLinkType?-1:1:void 0});var r=t.y0;n.forEach(function(t){t.y1=r+t.width/2,r+=t.width}),n.forEach(function(e,o){if("bottom"==e.circularLinkType){for(var r=o+1,s=0;i>r;r++)s+=n[r].width;e.y1=t.y1-s-e.width/2}})})}(h,a),function(t){var e=t.nodes,o=t.links,n=!1,i=!1;if(o.forEach(function(t){"top"==t.circularLinkType?n=!0:"bottom"==t.circularLinkType&&(i=!0)}),0==n||0==i){let n=function(e){return(e-r)/(s-r)*(t.y1-t.y0)+t.y0};var r=dp(e,function(t){return t.y0}),s=hp(e,function(t){return t.y1}),a=(t.y1-t.y0)/(s-r);1>a?(e.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1)}),o.forEach(function(t){t.y0=n(t.y0),t.y1=n(t.y1),t.width=t.width*a})):e.forEach(function(t){var e=t.y1-t.y0,o=n(t.y0)-t.y0;t.y0=n(t.y0),t.y1=t.y0+e,t.sourceLinks.forEach(function(t){t.y0=t.y0+o}),t.targetLinks.forEach(function(t){t.y1=t.y1+o})})}}(h),lp(h,a,d,10,8)}(f),f}return f.update=function(t){return Ap(t),lp(t,a,d,10,8),t},f.nodeWidth=function(t){return arguments.length?(i=+t,f):i},f.nodePadding=function(t){return arguments.length?(r=+t,f):r},f.nodePaddingRatio=function(t){return arguments.length?(s=+t,f):s},f.nodes=function(t){return arguments.length?(h="function"==typeof t?t:mp(t),f):h},f.links=function(t){return arguments.length?(p="function"==typeof t?t:mp(t),f):p},f.nodeId=function(t){return arguments.length?(a="function"==typeof t?t:mp(t),f):a},f.nodeAlign=function(t){return arguments.length?(l="function"==typeof t?t:mp(t),f):l},f.nodeSort=function(t){return arguments.length?(c=t,f):c},f.iterations=function(t){return arguments.length?(u=+t,f):u},f.circularLinkGap=function(t){return arguments.length?(d=+t,f):d},f.extent=function(i){return arguments.length?(t=+i[0][0],e=+i[0][1],o=+i[1][0],n=+i[1][1],f):[[t,e],[o,n]]},f.size=function(i){return arguments.length?(t=e=0,o=+i[0],n=+i[1],f):[o-t,n-e]},f}import{interpolateNumber as Mp}from"d3-interpolate";import{line as _p,curveLinearClosed as Pp}from"d3-shape";var Lp=t=>{let e,o,n,i,r,s,a,l,c;if("down"===t.direction)return e=t.y0-t.sankeyWidth/2,o=t.y1-t.sankeyWidth/2,n=t.y1+t.sankeyWidth/2,i=t.y0+t.sankeyWidth/2,r=t.source.x1,s=t.target.x0,a=Mp(r,s),l=a(.5),c=a(.5),`M${e},${r}C${e},${l} ${o},${c} ${o},${s}L${n},${s}C${n},${c} ${i},${l} ${i},${r}Z`;const u=t.sankeyWidth/2,d=Mp(t.source.x1,t.target.x0),{pathD:h}=Si({sx:t.source.x1,sTop:t.y0-u,sBot:t.y0+u,tx:t.target.x0,tTop:t.y1-u,tBot:t.y1+u,cp1X:d(.5),cp2X:d(.5)});return h};function $p(t){const e=t.sankeyWidth/2,o=(t._circularWidth??t.sankeyWidth)/2,n=t.circularPathData;if(!n)return null;if("down"===t.direction)return null;if(t._circularStub){const o=n.sourceX,i=n.sourceY,r=n.targetX,s=n.targetY;if("object"!=typeof t.source||!t.source||"object"!=typeof t.target||!t.target)return null;const a=Math.max(15,Math.min(40,.33*(n.rightFullExtent-o))),l=Math.max(15,Math.min(40,.33*(r-n.leftFullExtent)));return`M${o},${i-e}L${o+a},${i-e}L${o+a},${i+e}L${o},${i+e}ZM${r},${s-e}L${r-l},${s-e}L${r-l},${s+e}L${r},${s+e}Z`}const i=n.sourceX,r=n.sourceY,s=n.targetX,a=n.targetY,l=n.rightFullExtent,c=n.leftFullExtent,u=n.verticalFullExtent,d="bottom"===t.circularLinkType?1:-1,h=Math.max(4,Math.min(o,15));return`M${i},${r-d*e}L${l},${r-d*e}L${l+o},${r-d*e+d*h}L${l+o},${u+d*o-d*h}L${l+o-h},${u+d*o}L${c-o+h},${u+d*o}L${c-o},${u+d*o-d*h}L${c-o},${a-d*e+d*h}L${c-o+h},${a-d*e}L${s},${a-d*e}L${s},${a+d*e}L${c+o},${a+d*e}L${c+o},${u-d*o}L${l-o},${u-d*o}L${l-o},${r+d*e}L${i},${r+d*e}Z`}var Rp={left:function(t){return t.depth},right:function(t,e){return e-1-t.height},center:function(t){return t.targetLinks.length?t.depth:t.sourceLinks.length?Math.min.apply(Math,t.sourceLinks.map(qh))-1:0},justify:Uh},Cp={supportsStreaming:!0,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const i="vertical"===o.orientation?"down":"right",r=o.nodeAlign||"justify",s=o.nodeWidth??15,a=o.nodePaddingRatio??.05,l=o.iterations??100,c=t.map(t=>({...t})),u=e.map(t=>({...t,source:bt(t.source),target:bt(t.target),value:Math.sqrt(Math.max(1,t.value||1))}));let d;d="down"===i?[[0,0],[n[1],n[0]]]:[[0,0],[n[0],n[1]]];const h=Sp().extent(d).links(u).nodes(c).nodeAlign(Rp[r]||Uh).nodeId(t=>t.id).nodeWidth(s).iterations(l);h.nodePaddingRatio&&h.nodePaddingRatio(a),h();{let t=1/0,e=-1/0,o=1/0,i=-1/0;for(const n of c)t>n.x0&&(t=n.x0),n.x1>e&&(e=n.x1),o>n.y0&&(o=n.y0),n.y1>i&&(i=n.y1);for(const n of u){if(!n.circular||!n.circularPathData)continue;const r=n.circularPathData,s=(n._circularWidth??n.width??0)/2;t>r.leftFullExtent-s&&(t=r.leftFullExtent-s),r.rightFullExtent+s>e&&(e=r.rightFullExtent+s),o>r.verticalFullExtent-s&&(o=r.verticalFullExtent-s),r.verticalFullExtent+s>i&&(i=r.verticalFullExtent+s)}const r=e-t,s=i-o,a=n[0],l=n[1];if(r>0&&s>0&&(0>t||0>o||e>a||i>l)){const e=Math.min(a/r,l/s),n=-t*e+(a-r*e)/2,i=-o*e+(l-s*e)/2;for(const t of c)t.x0=t.x0*e+n,t.x1=t.x1*e+n,t.y0=t.y0*e+i,t.y1=t.y1*e+i;for(const t of u)if(t.y0=t.y0*e+i,t.y1=t.y1*e+i,t.width=(t.width??0)*e,t._circularWidth&&(t._circularWidth*=e),t.circular&&t.circularPathData){const o=t.circularPathData;o.sourceX=o.sourceX*e+n,o.targetX=o.targetX*e+n,o.sourceY=o.sourceY*e+i,o.targetY=o.targetY*e+i,o.rightFullExtent=o.rightFullExtent*e+n,o.leftFullExtent=o.leftFullExtent*e+n,o.verticalFullExtent=o.verticalFullExtent*e+i,o.rightInnerExtent=o.rightInnerExtent*e+n,o.leftInnerExtent=o.leftInnerExtent*e+n,o.verticalRightInnerExtent=o.verticalRightInnerExtent*e+i,o.verticalLeftInnerExtent=o.verticalLeftInnerExtent*e+i,o.rightSmallArcRadius*=e,o.rightLargeArcRadius*=e,o.leftSmallArcRadius*=e,o.leftLargeArcRadius*=e,o.sourceWidth*=e,o.rightNodeBuffer*=e,o.leftNodeBuffer*=e,o.arcRadius*=e}}}const p=new Map;for(const e of t)p.set(e.id,e);for(const t of c){const e=p.get(t.id);e&&(e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.value=t.value,e.depth=t.depth,e.sourceLinks=t.sourceLinks,e.targetLinks=t.targetLinks,e.width=t.x1-t.x0,e.height=t.y1-t.y0,e.x=t.x0+(t.x1-t.x0)/2,e.y=t.y0+(t.y1-t.y0)/2)}const f=new Map;for(const t of e)if(t._edgeKey)f.set(t._edgeKey,t);else{const e=bt(t.source),o=bt(t.target);f.set(`${e}\0${o}`,t)}for(const t of u){const e=bt(t.source),o=bt(t.target),n=f.get(t._edgeKey?t._edgeKey:`${e}\0${o}`);if(n){n.y0=t.y0,n.y1=t.y1,n.sankeyWidth=t.width??0,n.circular=!!t.circular,n.circularPathData=t.circularPathData,n._circularWidth=t._circularWidth,n._circularStub=t._circularStub,n.path=t.path,n.circularLinkType=t.circularLinkType,n.direction=i;const r=p.get(e),s=p.get(o);r&&(n.source=r),s&&(n.target=s)}}},buildScene(t,e,o,n){const i="vertical"===o.orientation?"down":"right",r=o.nodeStyle,s=o.edgeStyle,a=o.edgeOpacity??.5,l=o.edgeColorBy||"source",c=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:B,u=new Map;t.forEach((t,e)=>{u.set(t.id,c[e%c.length])});const d=[],h=[],p=[],f=new Map;for(const e of t){const t=e.x1-e.x0,o=e.y1-e.y0;if(0>=t||0>=o)continue;const n=r?r(H(e,"nodeStyle")):{},s={fill:n.fill||u.get(e.id)||"#4d430c",stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity,cursor:n.cursor};f.set(e.id,("string"==typeof s.fill?s.fill:null)||u.get(e.id)||"#4d430c"),d.push("down"===i?{type:"rect",x:e.y0,y:e.x0,w:o,h:t,style:s,datum:e,id:e.id,label:e.id}:{type:"rect",x:e.x0,y:e.y0,w:t,h:o,style:s,datum:e,id:e.id,label:e.id})}const g=[...e].sort((t,e)=>(e.sankeyWidth||0)-(t.sankeyWidth||0));for(const t of g){if(!t.sankeyWidth||0>=t.sankeyWidth)continue;const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";i="function"==typeof l?l(t)||i:"target"===l?f.get(n.id)||u.get(n.id)||i:f.get(e.id)||u.get(e.id)||i;const r=s?s(H(t,"edgeStyle")):{};if(t._circularStub&&t.circular&&t.circularPathData){const e=t.circularPathData,o=t.sankeyWidth/2,n=Math.max(15,Math.min(40,.33*(e.rightFullExtent-e.sourceX))),s=Math.max(15,Math.min(40,.33*(e.targetX-e.leftFullExtent))),l=r.fill||i;h.push({type:"bezier",pathD:`M${e.sourceX},${e.sourceY-o}L${e.sourceX+n},${e.sourceY-o}L${e.sourceX+n},${e.sourceY+o}L${e.sourceX},${e.sourceY+o}Z`,style:{fill:l,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"right",from:1,to:0,x0:e.sourceX,x1:e.sourceX+n}}),h.push({type:"bezier",pathD:`M${e.targetX},${e.targetY-o}L${e.targetX-s},${e.targetY-o}L${e.targetX-s},${e.targetY+o}L${e.targetX},${e.targetY+o}Z`,style:{fill:l,fillOpacity:r.fillOpacity??a,stroke:"none",opacity:r.opacity,cursor:r.cursor},datum:t,_gradient:{direction:"left",from:0,to:1,x0:e.targetX-s,x1:e.targetX}});continue}let c;(c=t.circular&&t.circularPathData?$p(t):Lp(t),c)&&h.push({type:"bezier",pathD:c,bezierCache:t.bezier,style:{fill:r.fill||i,fillOpacity:r.fillOpacity??a,stroke:r.stroke||"none",strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor},datum:t})}if(!1!==o.showLabels){const e=xt(o.nodeLabel);for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=e?e(o):o.id;if(!s)continue;let a,l,c;"down"===i?(a=o.y0+(o.y1-o.y0)/2,l=o.x1+14,c="start"):(n[0]/2>o.x0+t/2?(a=o.x0-6,c="end"):(a=o.x1+6,c="start"),l=o.y0+r/2),p.push({x:a,y:l,text:s+"",anchor:"down"===i?"middle":c,baseline:"middle",fontSize:11})}}return{sceneNodes:d,sceneEdges:h,labels:p}}};import{chord as Tp,ribbon as Op}from"d3-chord";import{arc as Ip}from"d3-shape";var zp=B,Fp={supportsStreaming:!1,hierarchical:!1,computeLayout(t,e,o,n){if(0===t.length)return;const{padAngle:i=.01,groupWidth:r=20,sortGroups:s}=o,a=Math.min(n[0],n[1])/2,l=a-r,c=n[0]/2,u=n[1]/2,d=(h=o.valueAccessor)?"function"==typeof h?h:t=>t[h]??1:t=>t.value??1;var h;const p=new Map;for(let e=0;t.length>e;e++)p.set(t[e].id,e);const f=t.length,g=Array.from({length:f},()=>Array.from({length:f},()=>0));for(const t of e){const e=bt(t.source),o=bt(t.target),n=p.get(e),i=p.get(o);if(void 0===n||void 0===i)continue;const r=d(t);g[n][i]=r}const y=Tp().padAngle(i);s&&y.sortGroups(s);const m=y(g),x=m.groups,b=Ip().innerRadius(l).outerRadius(a);for(const e of x){const o=t[e.index],n=b.centroid({innerRadius:l,outerRadius:a,startAngle:e.startAngle,endAngle:e.endAngle});o.x=n[0]+c,o.y=n[1]+u,o.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}const v=new Map;for(const e of t)v.set(e.id,e);for(const t of e){const e=bt(t.source),o=bt(t.target),n=v.get(e),i=v.get(o);n&&(t.source=n),i&&(t.target=i)}const w=new Map;for(const t of e){const e=bt(t.source),o=bt(t.target);w.set(`${e}\0${o}`,t)}for(const e of m){const o=t[e.source.index].id,n=t[e.target.index].id,i=w.get(`${o}\0${n}`)||w.get(`${n}\0${o}`);i&&(i.__chordData=e)}},buildScene(t,e,o,n){const{groupWidth:i=20,edgeOpacity:r=.5}=o,s=Math.min(n[0],n[1])/2,a=s-i,l=n[0]/2,c=n[1]/2,u=o.nodeStyle,d=o.edgeStyle,h=o.edgeColorBy||"source",p=Array.isArray(o.colorScheme)?o.colorScheme:o.themeCategorical&&o.themeCategorical.length>0?o.themeCategorical:zp,f=new Map;t.forEach((t,e)=>{f.set(t.id,p[e%p.length])});const g=Op().radius(a),y=[],m=[],x=[];for(let e=0;t.length>e;e++){const o=t[e],n=o.__arcData;if(!n)continue;let i;if(u){const t=u(H(o,"nodeStyle"));i=("string"==typeof t.fill?t.fill:void 0)||f.get(o.id)||p[e%p.length]}else i=f.get(o.id)||p[e%p.length];const r=u?u(H(o,"nodeStyle")):{};y.push({type:"arc",cx:l,cy:c,innerR:a,outerR:s,startAngle:n.startAngle-Math.PI/2,endAngle:n.endAngle-Math.PI/2,style:{fill:i,stroke:r.stroke||"black",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:o,id:o.id,label:o.id})}for(const t of e){const e=t.__chordData;if(!e)continue;const n=g(e);if(!n)continue;const i=Np(n,l,c);let s=o.themeSemantic?.border||o.themeSemantic?.secondary||"#999";if(d){const e=d(H(t,"edgeStyle"));s=("string"==typeof e.fill?e.fill:void 0)||s}else{const e="object"==typeof t.source?t.source:null,o="object"==typeof t.target?t.target:null;"target"===h&&o?s=f.get(o.id)||s:e&&(s=f.get(e.id)||s)}const a=d?d(H(t,"edgeStyle")):{};m.push({type:"ribbon",pathD:i,style:{fill:s,fillOpacity:a.fillOpacity??r,stroke:a.stroke||"none",strokeWidth:a.strokeWidth,opacity:a.opacity,cursor:a.cursor},datum:t})}if(!1!==o.showLabels){const e=xt(o.nodeLabel),n=s+12;for(const o of t){const t=o.__arcData;if(!t)continue;const i=e?e(o):o.id;if(!i)continue;const r=(t.startAngle+t.endAngle)/2,s=r-Math.PI/2;x.push({x:l+Math.cos(s)*n,y:c+Math.sin(s)*n,text:i+"",anchor:r>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:y,sceneEdges:m,labels:x}}};function Np(t,e,o){const n=t.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!n)return t;const i=[];let r=0;for(;n.length>r;){const t=n[r];if("M"===t||"L"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("C"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;3>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("Q"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)for(let t=0;2>t&&n.length>r&&!isNaN(Number(n[r]));t++)i.push(Number(n[r])+e+""),r++,n.length>r&&!isNaN(Number(n[r]))&&(i.push(Number(n[r])+o+""),r++);else if("A"===t)for(i.push(t),r++;n.length>r&&!isNaN(Number(n[r]));)i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&i.push(n[r++]),n.length>r&&(i.push(Number(n[r])+e+""),r++),n.length>r&&(i.push(Number(n[r])+o+""),r++);else"Z"===t||"z"===t?(i.push(t),r++):(i.push(n[r]),r++)}return i.join(" ")}import{hierarchy as Ep,tree as Dp,cluster as Wp,treemap as Bp,pack as jp,partition as Yp,treemapBinary as Xp}from"d3-hierarchy";var Gp=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function Vp(t){const[e,o,n]=function(t){if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6===e.length)return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}const e=t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return e?[+e[1],+e[2],+e[3]]:[128,128,128]}(t);return.299*e+.587*o+.114*n>150?"#222":"#fff"}function Hp(t,e,o){const n=e.nodeIDAccessor;return"function"==typeof n?n(t.data)+"":"string"==typeof n&&void 0!==t.data[n]?t.data[n]+"":void 0!==t.data.name?t.data.name+"":void 0!==t.data.id?t.data.id+"":"node-"+o}function qp(t){if(!t)return null;if("function"==typeof t){const e=t;return t=>e(t.data??t)}return e=>e.data?.[t]||e[t]||e.id}function Up(t){return Array.isArray(t.colorScheme)?t.colorScheme:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical:Gp}function Kp(t){return Array.isArray(t.colorScheme)&&t.colorScheme.length>0?t.colorScheme[0]:t.themeSemantic?.primary?t.themeSemantic.primary:t.themeCategorical&&t.themeCategorical.length>0?t.themeCategorical[0]:"#4d430c"}function Zp(t,e,o,n,i){if("horizontal"===i){const i=(t+o)/2;return`M ${t},${e} C ${i},${e} ${i},${n} ${o},${n}`}if("radial"===i){const i=(t+o)/2;return`M ${t},${e} Q ${i},${e} ${i},${(e+n)/2} T ${o},${n}`}{const i=(e+n)/2;return`M ${t},${e} C ${t},${i} ${o},${i} ${o},${n}`}}var Qp={supportsStreaming:!1,hierarchical:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;if(!i)return;const r=o.chartType,s=function(t){if(t)return"function"==typeof t?t:e=>e[t]}(o.childrenAccessor),a=o.hierarchySum,l="function"==typeof a?a:"string"==typeof a?t=>Number(t[a])||0:t=>Number(t.value)||0,c=Ep(i,s);c.sum(l),c.sort((t,e)=>(e.value??0)-(t.value??0));const[u,d]=n;switch(r){case"tree":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=Dp();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"cluster":!function(t,e,o,n){const i=e.treeOrientation||"vertical",r=Wp();r.size("horizontal"===i?[n,o]:"radial"===i?[2*Math.PI,Math.min(o,n)/2*.8]:[o,n]),r(t)}(c,o,u,d);break;case"treemap":!function(t,e,o,n){const i=e.padding??4,r=e.paddingTop??0,s=Bp().size([o,n]).tile(Xp).padding(i);r>0&&s.paddingTop(r),s(t)}(c,o,u,d);break;case"circlepack":!function(t,e,o,n){const i=e.padding??4;jp().size([o,n]).padding(i)(t)}(c,o,u,d);break;case"partition":!function(t,e,o,n){Yp().size([o,n]).padding(e.padding??1)(t)}(c,o,u,d)}const h=c.descendants();t.length=0,e.length=0;const p=new Map;for(let e=0;h.length>e;e++){const n=h[e],i={id:Hp(n,o,e),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:n.value??0,depth:n.depth,data:n.data,createdByFrame:!0};"tree"===r||"cluster"===r?Jp(i,n,o):"treemap"===r||"partition"===r?tf(i,n):"circlepack"===r&&ef(i,n),i.__hierarchyNode=n,t.push(i),p.set(n,i)}if("tree"===r||"cluster"===r)for(const t of h)if(t.parent){const o=p.get(t.parent),n=p.get(t);o&&n&&e.push({source:o,target:n,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:t.depth}})}},buildScene(t,e,o,n){const i=o.nodeStyle||(()=>({})),r=o.edgeStyle||(()=>({}));switch(o.chartType){case"tree":case"cluster":return function(t,e,o,n,i,r){const s=[],a=[],l=[],c=o.treeOrientation||"vertical",u="radial"===c,d=n[0]/2,h=n[1]/2,p="number"==typeof(f=o.nodeSize)?f:5;var f;for(const e of t){let t=e.x,n=e.y;u&&(t+=d,n+=h);const r=i(H(e,"nodeStyle"));let a=r.fill||Kp(o);if(o.colorByDepth&&void 0!==e.depth){const t=Up(o);a=t[e.depth%t.length]}s.push({type:"circle",cx:t,cy:n,r:p,style:{fill:a,stroke:r.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity,cursor:r.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const g=o.edgeOpacity??.5;for(const t of e){const e="object"==typeof t.source?t.source:null,n="object"==typeof t.target?t.target:null;if(!e||!n)continue;let i=e.x,s=e.y,l=n.x,p=n.y;u&&(i+=d,s+=h,l+=d,p+=h);const f=Zp(i,s,l,p,c),y=r(H(t,"edgeStyle"));a.push({type:"curved",pathD:f,style:{fill:"none",stroke:y.stroke||o.themeSemantic?.border||o.themeSemantic?.secondary||"#999",strokeWidth:y.strokeWidth??1.5,opacity:y.opacity??g,cursor:y.cursor},datum:t})}if(!1!==o.showLabels){const e=qp(o.nodeLabel);for(const o of t){const t=e?e(o):o.id;if(!t)continue;let n,i,r,s=o.x,a=o.y;if(u&&(s+=d,a+=h),u){const t=s-d,e=a-h,o=Math.sqrt(t*t+e*e);o>0?(n=s+t/o*10,i=a+e/o*10,r=0>t?"end":"start"):(n=s,i=a-12,r="middle")}else"horizontal"===c?(o.data?.children&&0!==o.data.children.length?(n=s-p-6,r="end"):(n=s+p+6,r="start"),i=a):(n=s,i=a+p+14,r="middle");l.push({x:n,y:i,text:t+"",anchor:r,baseline:"middle",fontSize:11})}}return{sceneNodes:s,sceneEdges:a,labels:l}}(t,e,o,n,i,r);case"treemap":case"partition":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.x1-o.x0,r=o.y1-o.y0;if(0>=t||0>=r)continue;const s=n(H(o,"nodeStyle"));let a=s.fill||Kp(e);if(e.colorByDepth&&void 0!==o.depth){const t=Up(e);a=t[o.depth%t.length]}i.push({type:"rect",x:o.x0,y:o.y0,w:t,h:r,style:{fill:a,stroke:s.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:s.strokeWidth??1,opacity:s.opacity,fillOpacity:s.fillOpacity,strokeOpacity:s.strokeOpacity,cursor:s.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=qp(e.nodeLabel),i=e.labelMode||"leaf",s="partition"===e.chartType;for(const a of t){const t=a.x1-a.x0,l=a.y1-a.y0;if(0>=t||0>=l)continue;const c=!(a.data?.children&&a.data.children.length>0);if(!s){if("leaf"===i&&!c)continue;if("parent"===i&&c)continue}const u=o?o(a):a.id;if(!u)continue;if((c?30:40)>t||(c?16:14)>l)continue;let d=n(H(a,"nodeStyle")).fill||Kp(e);if(e.colorByDepth&&void 0!==a.depth){const t=Up(e);d=t[a.depth%t.length]}const h="string"==typeof d?Vp(d):e.themeSemantic?.text??"#000";r.push(c?{x:a.x0+t/2,y:a.y0+l/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(t,l)/6)),fill:h}:{x:a.x0+4,y:a.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,o,0,i);case"circlepack":return function(t,e,o,n){const i=[],r=[];for(const o of t){const t=o.__radius??5;if(0>=t)continue;const r=n(H(o,"nodeStyle"));let s=r.fill||Kp(e);if(e.colorByDepth&&void 0!==o.depth){const t=Up(e);s=t[o.depth%t.length]}i.push({type:"circle",cx:o.x,cy:o.y,r:t,style:{fill:s,stroke:r.stroke||e.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??.7,cursor:r.cursor},datum:o,id:o.id,label:o.id,depth:o.depth})}if(!1!==e.showLabels){const o=qp(e.nodeLabel);for(const i of t){const t=i.__radius??5,s=o?o(i):i.id;if(!s)continue;if(15>t)continue;const a=!(i.data?.children&&i.data.children.length>0);let l=n(H(i,"nodeStyle")).fill||Kp(e);if(e.colorByDepth&&void 0!==i.depth){const t=Up(e);l=t[i.depth%t.length]}if(a){const o="string"==typeof l?Vp(l):e.themeSemantic?.text??"#000";r.push({x:i.x,y:i.y,text:s+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,t/3)),fill:o})}else r.push({x:i.x,y:i.y-t+14,text:s+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,t/3)),fill:e.themeSemantic?.text||"#000",stroke:e.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:i,sceneEdges:[],labels:r}}(t,o,0,i);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function Jp(t,e,o){const n=o.treeOrientation||"vertical";if("radial"===n){const o=e.x,n=e.y;t.x=n*Math.cos(o-Math.PI/2),t.y=n*Math.sin(o-Math.PI/2)}else"horizontal"===n?(t.x=e.y,t.y=e.x):(t.x=e.x,t.y=e.y);t.x0=t.x-5,t.x1=t.x+5,t.y0=t.y-5,t.y1=t.y+5,t.width=10,t.height=10}function tf(t,e){t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.x=(e.x0+e.x1)/2,t.y=(e.y0+e.y1)/2,t.width=e.x1-e.x0,t.height=e.y1-e.y0}function ef(t,e){const o=e.r??0;t.x=e.x,t.y=e.y,t.x0=e.x-o,t.x1=e.x+o,t.y0=e.y-o,t.y1=e.y+o,t.width=2*o,t.height=2*o,t.__radius=o}import{pie as of}from"d3-shape";function nf(t){let e=t.__orbitState;return e||(e={metaMap:new Map,startTime:"undefined"!=typeof performance?performance.now():Date.now()},t.__orbitState=e),e}var rf={sankey:Cp,force:d,chord:Fp,tree:Qp,cluster:Qp,treemap:Qp,circlepack:Qp,partition:Qp,orbit:{supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(t,e,o,n){const i=o.__hierarchyRoot;i&&function(t,e,o,n,i){const r=function(t){if("function"==typeof t)return t;const e=t||"children";return t=>t[e]||null}(o.childrenAccessor),s=function(t){if("function"==typeof t)return t;const e=t||"name";return t=>(t[e]??"")+""}(o.nodeIDAccessor),a=function(t){if(Array.isArray(t))return t;switch(t){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(o.orbitMode),l=o.orbitSize??2.95,c=o.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=nf(o);h.metaMap.clear(),n.length=0,i.length=0;const p=new Map;function f(t){const e=p.get(t)??0;return p.set(t,e+1),0===e?t:`${t}__${e}`}const g=e[0]/2,y=e[1]/2,m=Math.min(e[0],e[1])/2*.85,x=f(s(t));n.push({id:x,x:g,y:y,x0:g,x1:g,y0:y,y1:y,width:0,height:0,value:0,depth:0,data:t}),h.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function t(e,o,l,c,p,g,y){const m=r(e);if(!m?.length)return;const x=m.length;let b=0,v=0,w=0;for(;x>v;)v+=a[Math.min(w,a.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){const v=a[Math.min(x,a.length-1)],w=m.slice(k,k+v);if(!w.length)break;const A=(x+1)/b,S={id:o,depth:g,data:e,parentId:o},M=y?p/u(S)*A:p*A,_=of().value(t=>{const e=r(t)?.length;return e?4:1}).sort(null)(w),P=d(S);for(let e=0;w.length>e;e++){const r=(_[e].startAngle+_[e].endAngle)/2,a=w[e],u=f(s(a)),d=l+M*Math.sin(r),p=c+M*Math.cos(r)*P;n.push({id:u,x:d,y:p,x0:d,x1:d,y0:p,y1:p,width:0,height:0,value:0,depth:g,data:a}),h.metaMap.set(u,{ring:M,angle:r,depth:g,parentId:o,eccentricity:P}),i.push({source:o,target:u,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:o,target:u}}),t(a,u,d,p,M,g+1,!0)}k+=v}}(t,x,g,y,m,1,!1)}(i,n,o,t,e)},buildScene(t,e,o,n){const i=o.nodeStyle,r=o.edgeStyle,s=o.nodeSize,a="number"==typeof s?()=>s:"function"==typeof s?s:()=>6,l=[],c=[],u=[];if(!1!==o.orbitShowRings){const e=nf(o),n=new Map;for(const e of t)n.set(e.id,e);const i=new Map;for(const[,t]of e.metaMap){if(!t.parentId)continue;const e=n.get(t.parentId);if(!e)continue;const o=`${t.parentId}:${t.ring}`;i.has(o)||i.set(o,{parentX:e.x,parentY:e.y,ring:t.ring,ecc:t.eccentricity})}const r=48,s={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(const[,{parentX:t,parentY:e,ring:o,ecc:n}]of i)for(let i=0;r>i;i++){const a=i/r*Math.PI*2,l=(i+1)/r*Math.PI*2;c.push({type:"line",x1:t+o*Math.sin(a),y1:e+o*Math.cos(a)*n,x2:t+o*Math.sin(l),y2:e+o*Math.cos(l)*n,style:s,datum:null})}}for(const e of t){if(null==e.x||null==e.y)continue;const t=a(H(e,"nodeSize")),n=i?i(H(e,"nodeStyle")):{};l.push({type:"circle",cx:e.x,cy:e.y,r:t,style:{fill:n.fill||o.themeSemantic?.primary||"#6366f1",stroke:n.stroke||o.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??1,opacity:n.opacity??(0===(e.depth??0)?1:.85),cursor:n.cursor},datum:e,id:e.id,label:e.id,depth:e.depth})}const d=new Map;for(const e of t)d.set(e.id,e);for(const t of e){const e="object"==typeof t.source?t.source:d.get(t.source),o="object"==typeof t.target?t.target:d.get(t.target);if(!e||!o)continue;if(null==e.x||null==o.x)continue;const n=r?r(H(t,"edgeStyle")):{};c.push({type:"line",x1:e.x,y1:e.y,x2:o.x,y2:o.y,style:{stroke:n.stroke||"rgba(128,128,128,0.35)",strokeWidth:n.strokeWidth??.5,opacity:n.opacity??1,cursor:n.cursor},datum:t})}if(o.showLabels){const e=o.nodeLabel;for(const o of t){const t=a(H(o,"nodeSize"));if(4>=t)continue;const n="function"==typeof e?e(o):e?o.data?.[e]??o.id:o.id;u.push({x:o.x,y:o.y+t+12,text:n+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:l,sceneEdges:c,labels:u}},tick:(t,e,o,n,i)=>!1!==o.orbitAnimated&&(function(t,e){const o=nf(e),n=e.orbitSpeed??.25,i=e.orbitRevolution??function(t){switch(t){case"decay":return t=>Math.pow(.6,t.depth??0);case"alternate":return t=>{const e=t.depth??0;return(e%2==0?1:-1)/(e+1)};default:return t=>1/((t.depth??0)+1)}}(e.orbitRevolutionStyle),r=(("undefined"!=typeof performance?performance.now():Date.now())-o.startTime)/1e3,s=n*(Math.PI/6),a=new Map;for(const e of t)a.set(e.id,e);for(const e of t){const t=o.metaMap.get(e.id);if(!t||!t.parentId)continue;const n=a.get(t.parentId);if(!n)continue;const l=t.angle+r*s*i({id:e.id,depth:t.depth,data:e.data,parentId:t.parentId});e.x=n.x+t.ring*Math.sin(l),e.y=n.y+t.ring*Math.cos(l)*t.eccentricity,e.x0=e.x,e.x1=e.x,e.y0=e.y,e.y1=e.y}}(t,o),!0)}};function sf(t){const e=t.id??t.datum?.id??t.datum?.data?.id??t.datum?.data?.name;return null==e?void 0:e+""}function af(t){if("glyph"===t.type&&t.glyph&&"number"==typeof t.size){const e=t.cx??t.x,o=t.cy??t.y;if("number"!=typeof e||"number"!=typeof o)return null;const n=f(t.glyph,t.size);return{x:e+n.centerDx,y:o+n.centerDy,r:Math.max(1,n.radius)}}const e=t.cx??(null!=t.x&&null!=t.w?t.x+t.w/2:t.x),o=t.cy??(null!=t.y&&null!=t.h?t.y+t.h/2:t.y);return"number"!=typeof e||"number"!=typeof o?null:{x:e,y:o,r:"number"==typeof t.r?Math.max(1,t.r):"number"==typeof t.outerR?Math.max(1,t.outerR):"number"==typeof t.size?Math.max(1,G(t.size)):Math.max(1,t.w??0,t.h??0)/2}}function lf(t){if(!t)return;const e=[];for(const o of t){const t=af(o);t&&e.push({pointId:sf(o),...t})}return e}import{Fragment as cf,jsxs as uf}from"react/jsx-runtime";function df(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}var hf=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function pf(t){return t.map(t=>{const e=t.datum&&"object"==typeof t.datum?t.datum:{},o=e.data&&"object"==typeof e.data?e.data:e,n="cx"in t?t.cx:t.x+t.w/2,i="cy"in t?t.cy:t.y+t.h/2;return{...o,...null==o.id&&null!=t.id?{id:t.id}:{},x:n,y:i}})}function ff(t,e){const o=ye(t.theme),n=t.chartType||"force",i=t.size||[500,500],r=function(t){return Ed.has(t)?Nd:Fd}(n),s=qe({...r,...t.margin},t.title),a=Ve(t.title),l=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;if(!e)return[];const n=Ht(t.nodes||[]);if(n.length>0)return iu(n,e);const i=Array.isArray(t.edges)?Ht(t.edges):[];if(0===i.length)return[];const r=df(t.sourceAccessor,"source"),s=df(t.targetAccessor,"target");return iu(Array.from(new Set(i.flatMap(t=>[r(t),s(t)]).filter(t=>null!=t).map(String))).map(t=>({id:t})),e)})():[];Ld(s,{props:t,categories:l,theme:o,size:i,hasTitle:a});const c=$d({props:t,categories:l,theme:o,size:i,margin:s,hasTitle:a}),u=i[0]-s.left-s.right,d=i[1]-s.top-s.bottom,h=Id(t.backgroundGraphics,i,s,null),p=Id(t.foregroundGraphics,i,s,null),f=()=>{let n;const r=t=>Number(t),a=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:r,y:r},layout:{width:u,height:d},theme:o,frameType:"network",idPrefix:t._idPrefix,onRender:t=>{n=t}}):null;return e&&(e.evidence=(e=>Ba({frameType:"network",width:i[0],height:i[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:e,nodeCount:0,edgeCount:0,margin:s}))(n)),Th.renderToStaticMarkup(Cd(h||p||t.annotations?uf(cf,{children:[h,a,p]}):null,{width:i[0],height:i[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))},g=function(t){return rf[t]}(n);if(!g&&!t.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${n}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);const y={chartType:n,nodeIDAccessor:t.nodeIDAccessor,sourceAccessor:t.sourceAccessor,targetAccessor:t.targetAccessor,valueAccessor:t.valueAccessor,childrenAccessor:t.childrenAccessor,hierarchySum:t.hierarchySum,orientation:t.orientation,nodeAlign:t.nodeAlign,nodePaddingRatio:t.nodePaddingRatio,nodeWidth:t.nodeWidth,iterations:t.iterations,forceStrength:t.forceStrength,padAngle:t.padAngle,groupWidth:t.groupWidth,sortGroups:t.sortGroups,edgeSort:t.edgeSort,treeOrientation:t.treeOrientation,edgeType:t.edgeType,padding:t.padding,paddingTop:t.paddingTop,nodeStyle:t.nodeStyle,edgeStyle:t.edgeStyle,nodeLabel:t.nodeLabel,showLabels:t.showLabels,labelMode:t.labelMode,colorBy:t.colorBy,colorScheme:t.colorScheme||o.colors.categorical,edgeColorBy:t.edgeColorBy,edgeOpacity:t.edgeOpacity,colorByDepth:t.colorByDepth,nodeSize:t.nodeSize,nodeSizeRange:t.nodeSizeRange,orbitMode:t.orbitMode,orbitSize:t.orbitSize,orbitSpeed:t.orbitSpeed,orbitRevolution:t.orbitRevolution,orbitRevolutionStyle:t.orbitRevolutionStyle,orbitEccentricity:t.orbitEccentricity,orbitShowRings:t.orbitShowRings,orbitAnimated:!1,customNetworkLayout:t.customNetworkLayout,layoutConfig:t.layoutConfig};let m,x;if(hf.has(n)){const e=t.data||t.edges;if(!e||Array.isArray(e))return f();y.__hierarchyRoot=e,m=[],x=[]}else{const e=Ht(t.nodes||[]),o=Array.isArray(t.edges)?Ht(t.edges):[];if(0===e.length&&0===o.length)return f();if(x=function(t,e){const o=df(e.sourceAccessor,"source"),n=df(e.targetAccessor,"target"),i=df(e.valueAccessor,"value");return t.map(t=>{const e=Number(i(t));return{source:o(t)+"",target:n(t)+"",value:Number.isFinite(e)?e:1,y0:0,y1:0,sankeyWidth:0,data:t}})}(o,y),0===e.length&&x.length>0){const t=new Set;for(const e of x){const o=kd(e.source),n=kd(e.target);o&&t.add(o),n&&t.add(n)}m=Array.from(t).map(t=>({id:t,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:t}}))}else m=function(t,e){const o=df(e.nodeIDAccessor,"id");return t.map(t=>({id:o(t)+"",x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t}))}(e,y)}let b=[],v=[],w=[],k=null;if(y.customNetworkLayout){const t=y.colorScheme,e=Rr(t,o.colors.categorical,B),n=Cr(e,t),i={nodes:m,edges:x,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:o.colors,categorical:[...e]},resolveColor:n,config:y.layoutConfig??{}},r=y.customNetworkLayout(i);b=r.sceneNodes??[],v=r.sceneEdges??[],w=r.labels??[],k=r.overlays??null}else if(g){g.computeLayout(m,x,y,[u,d]);const t=g.buildScene(m,x,y,[u,d]);b=t.sceneNodes,v=t.sceneEdges,w=t.labels}const A=me(o);for(const t of w)t.fill||(t.fill=A.text);const S=Vc({nodes:v,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"line":return _c("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||"#999",strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity},"net-edge-"+e);case"bezier":{const o=t,n=`net-bezier-${e}-hatch`,i=ot(o.style.fill)?et(o.style.fill,n):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:o.pathD,fill:i?`url(#${n})`:gc(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"ribbon":{const o=t,n=`net-ribbon-${e}-hatch`,i=ot(o.style.fill)?et(o.style.fill,n):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:o.pathD,fill:i?`url(#${n})`:gc(o.style.fill,"#999"),fillOpacity:o.style.fillOpacity,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth,opacity:o.style.opacity})]},"net-edge-"+e)}case"curved":{const o=t;return _c("path",{d:o.pathD,fill:gc(o.style.fill,"none"),stroke:o.style.stroke||"#999",strokeWidth:o.style.strokeWidth??1,opacity:o.style.opacity},"net-edge-"+e)}default:return null}}(t,e),t,"network-edge-cursor-"+e)}(t,e)}),M=Vc({nodes:b,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"circle":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`net-circle-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[n&&_c("defs",{children:n}),_c("circle",{cx:o.cx,cy:o.cy,r:o.r,fill:n?`url(#net-circle-${e}-hatch)`:gc(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-circle-"+e)}case"rect":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`net-rect-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[n&&_c("defs",{children:n}),_c("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:n?`url(#net-rect-${e}-hatch)`:gc(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-rect-"+e)}case"arc":{const o=t,n=Mc().innerRadius(o.innerR).outerRadius(o.outerR).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2)(fc)||"",i=ot(o.style.fill)?et(o.style.fill,`net-arc-${e}-hatch`):void 0;return Pc(Sc.Fragment,{children:[i&&_c("defs",{children:i}),_c("path",{d:n,transform:`translate(${o.cx},${o.cy})`,fill:i?`url(#net-arc-${e}-hatch)`:gc(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity})]},"net-arc-"+e)}case"symbol":{const o=t,n=X(o.symbolType,o.size,o.path);return _c("path",{d:n,transform:o.rotation?`translate(${o.cx},${o.cy}) rotate(${180*o.rotation/Math.PI})`:`translate(${o.cx},${o.cy})`,fill:o.style.fill?gc(o.style.fill):"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,fillOpacity:o.style.fillOpacity,strokeOpacity:o.style.strokeOpacity,opacity:o.style.opacity},"net-symbol-"+e)}case"glyph":return mc(t,t.cx,t.cy,"net-glyph-"+(t.id??e));default:return null}}(t,e),t,"network-node-cursor-"+e)}(t,e)}),_=S.map(t=>t.element),P=M.map(t=>t.element),L=w.map((t,e)=>function(t,e){return _c("text",{x:t.x,y:t.y,textAnchor:t.anchor||"middle",dominantBaseline:t.baseline||"auto",fontSize:t.fontSize||11,fontWeight:t.fontWeight,fill:t.fill||"var(--semiotic-text, #333)",stroke:t.stroke,strokeWidth:t.strokeWidth,paintOrder:t.paintOrder,children:t.text},"net-label-"+e)}(t,e)).filter(Boolean);let $;const R=t=>Number(t),C=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{x:R,y:R},layout:{width:u,height:d},theme:o,frameType:"network",annotationData:pf(b),pointNodes:lf(b),idPrefix:t._idPrefix,onRender:t=>{$=t}}):null;return e&&(e.evidence=Ba({frameType:"network",width:i[0],height:i[1],marks:[...M.map(({node:t})=>({type:"node:"+(t.type??"node")})),...S.map(({node:t})=>({type:"edge:"+(t.type??"edge")}))],title:t.title,description:t.description,annotations:t.annotations,annotationRender:$,nodeCount:M.length,edgeCount:S.length,margin:s})),Th.renderToStaticMarkup(Cd(uf(cf,{children:[h,_,P,L,C,p,k]}),{width:i[0],height:i[1],className:"stream-network-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${s.left},${s.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:t._idPrefix}))}import*as gf from"react-dom/server.browser";import{geoPath as yf}from"d3-geo";import{quadtree as mf}from"d3-quadtree";import{geoMercator as xf,geoEqualEarth as bf,geoAlbersUsa as vf,geoOrthographic as wf,geoNaturalEarth1 as kf,geoEquirectangular as Af}from"d3-geo";var Sf={mercator:xf,equalEarth:bf,albersUsa:vf,orthographic:wf,naturalEarth:kf,equirectangular:Af};function Mf(t,e){return t?"function"==typeof t?t:e=>e[t]:t=>t[e]}function _f(t){return t?"function"==typeof t?t:e=>e[t]:t=>t.coordinates||t.data||[]}function Pf(t,e,o){return t?"function"==typeof t?{...o,...t(e)}:{...o,...t}:{...o}}function Lf(t,e){if(2>t.length)return[t];const o=.4*e,n=[];let i=[t[0]];for(let e=1;t.length>e;e++){const r=t[e];Math.abs(r[0]-t[e-1][0])>o?(2>i.length||n.push(i),i=[r]):i.push(r)}return 2>i.length||n.push(i),n}function $f(t,e,o=24){const n=e[0]-t[0],i=e[1]-t[1],r=Math.sqrt(n*n+i*i);if(0===r)return[t,e];const s=-i/r,a=n/r,l=Math.min(.3*r,80),c=(t[0]+e[0])/2+s*l,u=(t[1]+e[1])/2+a*l,d=[];for(let n=0;o>=n;n++){const i=n/o,r=1-i;d.push([r*r*t[0]+2*r*i*c+i*i*e[0],r*r*t[1]+2*r*i*u+i*i*e[1]])}return d}function Rf(t,e){if(2>t.length)return t;const o=e/2+1,n=[];for(let e=0;t.length>e;e++){const i=t[e];let r,s;0===e?(r=t[1][0]-i[0],s=t[1][1]-i[1]):e===t.length-1?(r=i[0]-t[e-1][0],s=i[1]-t[e-1][1]):(r=t[e+1][0]-t[e-1][0],s=t[e+1][1]-t[e-1][1]);const a=Math.sqrt(r*r+s*s)||1;n.push([i[0]+s/a*o,i[1]+-r/a*o])}return n}function Cf(t,e,o,n,i){const r=e[0]-t[0],s=e[1]-t[1],a=Math.sqrt(r*r+s*s);if(0===a)return[t,e];const l=s/a,c=-r/a,u=i/2+1;return[[t[0]+l*u,t[1]+c*u],[e[0]+l*u,e[1]+c*u]]}import{scaleLinear as Tf}from"d3-scale";var Of=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],If=["scene-style","data-paint","accessibility","evidence"],zf=(t,e)=>({retainedData:t,invalidations:e}),Ff=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Nf=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Ef=["scene-geometry","data-paint","accessibility","evidence"],Df=["scene-style","data-paint","accessibility","evidence"],Wf=["overlay","accessibility","evidence"],Bf=[],jf={xAccessor:zf("rebuild",Ff),yAccessor:zf("rebuild",Ff),lineDataAccessor:zf("rebuild",Ff),pointIdAccessor:zf("rebuild",Ef),lineIdAccessor:zf("rebuild",Ef),windowSize:zf("rebuild",Ff),projection:zf("preserve",Nf),projectionExtent:zf("preserve",Nf),fitPadding:zf("preserve",Nf),lineType:zf("preserve",Nf),flowStyle:zf("preserve",Nf),graticule:zf("preserve",Nf),projectionTransform:zf("preserve",Nf),customLayout:zf("preserve",Nf),layoutConfig:zf("preserve",Nf),layoutMargin:zf("preserve",Nf),areaStyle:zf("preserve",Df),pointStyle:zf("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:zf("preserve",Df),colorScheme:zf("preserve",Df),themeCategorical:zf("preserve",Df),themeDiverging:zf("preserve",Df),themeSemantic:zf("preserve",Df),themeSequential:zf("preserve",Df),decay:zf("preserve",Df),pulse:zf("preserve",Df),layoutSelection:zf("preserve",Df),annotations:zf("preserve",Wf),autoPlaceAnnotations:zf("preserve",Wf),clock:zf("preserve",Bf),transition:zf("preserve",Bf),introAnimation:zf("preserve",Bf),onLayoutError:zf("preserve",Bf)},Yf=zf("preserve",Nf),Xf=class{constructor(){this.tracker=new o}get last(){return this.tracker.last}subscribe(t){return this.tracker.subscribe(t)}recordData(t,e){return this.tracker.record({kind:t,...void 0===e?{}:{count:e}},Of)}recordNoop(t){return this.tracker.record({kind:t,..."restyle"===t?{}:{count:0}},[])}recordRestyle(t){return t?this.tracker.record({kind:"restyle"},If):this.recordNoop("restyle")}recordConfig(t,e={}){const o=function(t){let e="preserve";const o=new Set;for(const n of t){const t=jf[n]??Yf;"rebuild"===t.retainedData&&(e="rebuild");for(const e of t.invalidations)o.add(e)}return{retainedData:e,invalidations:o}}(t),n=new Set(o.invalidations);return e.retainedDataChanged&&n.add("data"),this.tracker.record({kind:"config",keys:t},n)}};import{geoDistance as Gf,geoGraticule as Vf,geoInterpolate as Hf}from"d3-geo";function qf(t){if(null==t)return 0;if("number"==typeof t&&Number.isFinite(t)&&t>=0&&.5>t)return t;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${t+""}.`)}var Uf=class t{constructor(t){this.updateResults=new Xf,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(t){return{...t,fitPadding:qf(t.fitPadding)}}(t)}currentTime(){return this.config.clock?.()??qa()}getConfiguredWindowSize(){const t=this.config.windowSize??500;if(!Number.isInteger(t)||1>t)throw Error("GeoPipelineStore windowSize must be a positive integer");return t}retainNewestLines(t=this.getConfiguredWindowSize()){this.lineData.length>t&&(this.lineData=this.lineData.slice(-t))}resizeStreamingWindow(t){if(this.pointBuffer){const e=this.pointBuffer.toArray(),o=this.timestampBuffer?.toArray()??[],n=e.slice(-t),i=o.slice(-n.length),r=this.currentTime();this.pointBuffer=new U(t),this.timestampBuffer=new U(t),n.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(i[e]??r)})}this.retainNewestLines(t)}updateConfig(t){const e=function(t){return"fitPadding"in t?{...t,fitPadding:qf(t.fitPadding)}:t}(t),o=this.config,n=this.getConfiguredWindowSize(),i=Object.keys(e).filter(t=>e[t]!==o[t]);this.config={...this.config,...e};const r=this.getConfiguredWindowSize(),s=this.streaming&&r!==n;s&&(this.resizeStreamingWindow(r),this.version++),"customLayout"in e&&!e.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(i,{retainedDataChanged:s})}updateConfigWithResult(t){return this.updateConfig(t),this.updateResults.last}setAreas(t){this.areas=t,this.updateResults.recordData("replace",t.length)}setAreasWithResult(t){return this.setAreas(t),this.updateResults.last}setPoints(t){this.pointData=t.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",t.length)}setPointsWithResult(t){return this.setPoints(t),this.updateResults.last}setLines(t){this.lineData=t.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",t.length)}setLinesWithResult(t){return this.setLines(t),this.updateResults.last}initStreaming(t){void 0!==t&&t!==this.config.windowSize&&(this.config={...this.config,windowSize:t});const e=this.getConfiguredWindowSize(),o=this.pointBuffer?this.pointBuffer.toArray():this.pointData,n=this.timestampBuffer?.toArray()??[],i=o.slice(-e),r=n.slice(-i.length),s=this.currentTime();this.pointBuffer=new U(e),this.timestampBuffer=new U(e),i.forEach((t,e)=>{this.pointBuffer.push(t),this.timestampBuffer.push(r[e]??s)}),this.pointData=[],this.retainNewestLines(e),this.streaming=!0}pushPoint(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();zl(this.pointBuffer,t,this.timestampBuffer,e),this.lastIngestTime=e,this.updateResults.recordData("ingest",1)}pushPointWithResult(t){return this.pushPoint(t),this.updateResults.last}pushMany(t){this.pointBuffer||this.initStreaming();const e=this.currentTime();for(const o of t)zl(this.pointBuffer,o,this.timestampBuffer,e);this.lastIngestTime=e,this.updateResults.recordData("ingest",t.length)}pushManyWithResult(t){return this.pushMany(t),this.updateResults.last}pushLine(t){null!=t&&"object"==typeof t?(this.streaming||this.initStreaming(),this.lineData.push(t),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(t){if(!Array.isArray(t)||0===t.length)return void this.updateResults.recordNoop("ingest");const e=t.filter(t=>null!=t&&"object"==typeof t);if(0!==e.length){this.streaming||this.initStreaming();for(const t of e)this.lineData.push(t);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",e.length)}else this.updateResults.recordNoop("ingest")}removeLine(t){const{lineIdAccessor:e}=this.config;if(!e)throw Error("removeLine() requires lineIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]),i=[];return this.lineData=this.lineData.filter(t=>!n.has(o(t)+"")||(i.push(t),!1)),i.length>0?(this.version++,this.updateResults.recordData("remove",i.length)):this.updateResults.recordNoop("remove"),i}getLines(){return this.lineData.slice()}removePoint(t){const{pointIdAccessor:e}=this.config;if(!e)throw Error("removePoint() requires pointIdAccessor to be configured");const o="function"==typeof e?e:t=>t[e],n=new Set(Array.isArray(t)?t:[t]);if(this.streaming&&this.pointBuffer){const t=t=>n.has(o(t)+"");Fl(this.pointBuffer,this.timestampBuffer,t);const e=this.pointBuffer.remove(t);return e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}{const t=[];return this.pointData=this.pointData.filter(e=>!n.has(o(e)+"")||(t.push(e),!1)),t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(t){const e=this._customRestyle;if(e){for(const o of this.scene){const n=this._baseStyles.get(o)??o.style,i=e(o,t);o.style=i?{...n,...i}:n}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(t){const{config:e}=this,o=this.projection,n=this.geoPath,i=this.scales,r=this.baseScale,s=[...this.baseTranslate],a=[...this.baseRotation],l=this.scene;this.projection=function(t){if(!t)return bf();if("string"==typeof t){const e=Sf[t];return e?e():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${t}", falling back to equalEarth`),bf())}if("object"==typeof t&&"type"in t){const e=Sf[t.type],o=e?e():bf();return t.rotate&&"rotate"in o&&o.rotate(t.rotate),t.center&&"center"in o&&o.center(t.center),o}return t}(e.projection),this.geoPath=yf(this.projection),this.fitProjection(t),this.geoPath=yf(this.projection);const c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(t,e)=>c([t,e]),invertedPoint:(t,e)=>c.invert?c.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const u=this.buildSceneNodes(t);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=o,this.geoPath=n,this.scales=i,this.baseScale=r,this.baseTranslate=s,this.baseRotation=a):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),e.projectionTransform&&this.applyCartogramTransform(e.projectionTransform,t),e.decay&&this.streaming&&this.applyDecay(),e.pulse&&this.streaming&&this.applyPulse(),e.transition&&!this._hasRenderedOnce&&this.scene.length>0&&e.introAnimation){const e=t.width/2,o=t.height/2,n=this.scene.filter(t=>"point"===t.type).map(t=>({...t,x:e,y:o}));n.length>0&&this.startTransition(n)}this._hasRenderedOnce=!0,e.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(t){const e=this.projection,o=this.config,n=[...this.areas],i=Mf(o.xAccessor,"lon"),r=Mf(o.yAccessor,"lat"),s=this.getPoints();if(s.length>0){const t=s.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:t}})}const a=_f(o.lineDataAccessor);for(const t of this.lineData){const e=a(t);if(e&&e.length>0){const t=e.map(t=>[i(t),r(t)]);n.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}})}}if(0!==n.length){if(o.projectionExtent){const[[n,i],[r,s]]=o.projectionExtent;e.fitExtent([[0,0],[t.width,t.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[n,i],[n,s],[r,s],[r,i],[n,i]]]}})}else if(e.clipAngle&&(e.clipAngle()??0)>0){const n=o.fitPadding??0,i=Math.min(t.width,t.height);e.scale(i/2-i*n),e.translate([t.width/2,t.height/2])}else{const i=o.fitPadding??0,r=t.width*i,s=t.height*i;e.fitExtent([[r,s],[t.width-r,t.height-s]],{type:"FeatureCollection",features:n})}this.baseScale=e.scale(),this.baseTranslate=e.translate(),this.baseRotation=e.rotate?.()??[0,0,0]}}applyZoomTransform(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t.k),o.translate([this.baseTranslate[0]*t.k+t.x,this.baseTranslate[1]*t.k+t.y]),this.currentZoom=t.k,this.geoPath=yf(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyZoomScale(t,e){const o=this.projection;if(!o)return;const n=this.geoPath,i=this.scales,r=o.scale(),s=[...o.translate()],a=this.currentZoom;o.scale(this.baseScale*t),o.translate(this.baseTranslate),this.currentZoom=t,this.geoPath=yf(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const l=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.scale(r),o.translate(s),this.currentZoom=a,this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}applyRotation(t,e){const o=this.projection;if(!o||!o.rotate)return;const n=this.geoPath,i=this.scales,r=[...o.rotate()];o.rotate(t),this.geoPath=yf(o),this.scales={projection:o,geoPath:this.geoPath,projectedPoint:(t,e)=>o([t,e]),invertedPoint:(t,e)=>o.invert?o.invert([t,e]):null},this._customLayoutFailedThisBuild=!1;const s=this.buildSceneNodes(e);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(o.rotate(r),this.geoPath=n,this.scales=i):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,e),this.version++)}setRotation(t){const e=this.projection;e&&e.rotate&&e.rotate(t)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,o=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(o++,t.r>e&&(e=t.r));if(this._maxPointRadius=e,t.QUADTREE_THRESHOLD>=o)return void(this._quadtree=null);const n=Array(o);let i=0;for(const t of this.scene)"point"===t.type&&!1!==t.interactive&&(n[i++]=t);this._quadtree=mf().x(t=>t.x).y(t=>t.y).addAll(n)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(t){this._customLayoutFailedThisBuild=!1;const{config:e}=this,o=this.projection,n=this.geoPath;if(e.customLayout&&this.scales){const o=e.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Rr(e.colorScheme,e.themeCategorical,Jt),i={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:t.width,height:t.height,margin:o,plot:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:e.themeSemantic??{},categorical:[...n]},resolveColor:Cr(n,e.colorScheme),config:e.layoutConfig??{},selection:e.layoutSelection??null};let r;try{r=e.customLayout(i)}catch(t){const o=null!==this.lastCustomLayoutResult,n=Sl("geo",t,o,this.version);this.lastCustomLayoutFailure=n,this._customLayoutFailedThisBuild=!0,"production"!==process.env.NODE_ENV&&console.error("[semiotic] geo customLayout threw:",t);try{e.onLayoutError?.(n)}catch(t){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",t)}return o?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[])}const s=r.nodes??[];if(this.customLayoutOverlays=r.overlays??null,this.lastCustomLayoutResult=r,this.lastCustomLayoutFailure=null,this._customRestyle=r.restyle,this.hasCustomRestyle=!!r.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(const t of s)this._baseStyles.set(t,t.style);this.restyleScene(e.layoutSelection??null)}return wl({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:t,projection:e,path:o,areas:n,points:i,lines:r,layout:s}){const a=Mf(t.xAccessor,"lon"),l=Mf(t.yAccessor,"lat"),c=[],u=function(t){return{fill:t.themeSemantic?.surface||"#e0e0e0",stroke:t.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(t),d=function(t){return{stroke:t.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(t),h=function(t){return{fill:t.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(t);if(t.graticule){const e=!0===t.graticule?{}:t.graticule,n=Vf();e.step&&n.step(e.step);const i=o(n())||"";i&&c.push({type:"geoarea",pathData:i,centroid:[s.width/2,s.height/2],bounds:[[0,0],[s.width,s.height]],screenArea:0,style:{fill:"none",stroke:e.stroke||"#e0e0e0",strokeWidth:e.strokeWidth??.5,strokeDasharray:e.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(const e of n){const n=o(e);if(!n)continue;const i=o.centroid(e),r=o.bounds(e),s=o.area(e);c.push({type:"geoarea",pathData:n,centroid:i,bounds:r,screenArea:s,style:Pf(t.areaStyle,e,u),datum:e,interactive:!0})}const p=_f(t.lineDataAccessor);for(const o of r){const n=p(o);if(!n||2>n.length)continue;let i=[];if("geo"===t.lineType){const t=Array(n.length);for(let e=0;n.length>e;e++)t[e]=[a(n[e]),l(n[e])];for(let o=0;t.length-1>o;o++){const n=t[o],r=t[o+1],s=Gf(n,r)||0,a=Math.max(2,Math.ceil(s/(Math.PI/180))),l=Hf(n,r);for(let t=0;a>=t;t++){if(o>0&&0===t)continue;const n=e(l(t/a));null!=n&&i.push(n)}}}else for(let t=0;n.length>t;t++){const o=n[t],r=e([a(o),l(o)]);null!=r&&i.push(r)}if(2>i.length)continue;const r=Pf(t.lineStyle,o,d),u="number"==typeof r.strokeWidth?r.strokeWidth:1;2!==n.length||2>i.length||"arc"!==t.flowStyle?2!==n.length||2>i.length||"offset"!==t.flowStyle||(i="geo"===t.lineType?Rf(i,u):Cf(i[0],i[i.length-1],0,0,u)):i=$f(i[0],i[i.length-1]);const h=Lf(i,s.width);if(h.length>1)for(const t of h)2>t.length||c.push({type:"line",path:t,style:{...r,_edgeFade:!0},datum:o});else c.push({type:"line",path:2>i.length&&h[0]||i,style:r,datum:o})}const f=t.pointIdAccessor?"function"==typeof t.pointIdAccessor?t.pointIdAccessor:e=>e[t.pointIdAccessor]:null,g=e.clipAngle?e.clipAngle()??0:0,y=g>0?g*Math.PI/180:null,m=e.rotate?e.rotate():[0,0,0],x="function"==typeof e.center?e.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(const o of i){const n=a(o),i=l(o);if(null!=y&&Gf([n,i],b)>y)continue;const r=e([n,i]);if(!r)continue;const s=t.pointStyle?t.pointStyle(o):{...h},u={type:"point",x:r[0],y:r[1],r:s.r||4,style:s,datum:o,pointId:f?f(o)+"":void 0};c.push(u)}return c}({config:e,projection:o,path:n,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:t})}applyCartogramTransform(t,e){const o=function(t,e,o,n){const i=t.filter(t=>"point"===t.type);if(2>i.length)return null;const r=e.strength??1,s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1,a="strip"===e.layout?"strip":"radial";if("radial"===a&&0===s)return null;const l=e.centerAccessor?"function"==typeof e.centerAccessor?e.centerAccessor:t=>t[e.centerAccessor]:t=>t.id,c="function"==typeof e.costAccessor?e.costAccessor:t=>t[e.costAccessor],u=i.find(t=>t.datum&&l(t.datum)+""==e.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${e.center}" not found in point data`),null;const d=i.map(t=>t.datum?Number(c(t.datum)):NaN).filter(t=>isFinite(t)&&t>=0),h=kt(d,1);n>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let e=t.length-1;e>=0;e--){const o=t[e];"geoarea"===o.type&&o.interactive&&t.splice(e,1)}const p="strip"===a?function(t,e,o,n,i){const r=Math.max(3,Math.min(8,.35*i.height)),s=Math.max(1,i.width-2*r),a=i.height/2,l=Tf().domain([0,n]).range([0,s]);e.x=r,e.y=a;const c=[];for(const i of t){if(i===e)continue;if(!i.datum){i.x=r,i.y=a;continue}const t=Number(o(i.datum)),s=r+(isFinite(t)&&t>=0&&n>0?l(t):0);i.x=s,i.y=a,c.push({node:i,x:s})}c.sort((t,e)=>t.x-e.x);const u=Math.max(0,Math.min(i.height/2-1,6));let d=0;for(;c.length>d;){let t=d+1;for(;c.length>t&&3>Math.abs(c[t].x-c[d].x);)t++;const e=t-d;if(e>1&&u>0)for(let t=0;e>t;t++)c[d+t].node.y=a+(t-(e-1)/2)*Math.min(2.5,2*u/Math.max(1,e-1));d=t}return{cx:r,cy:a,maxCost:n,availableRadius:s,layout:"strip"}}(i,u,c,h,o):function(t,e,o,n,i,r){const s=e.x,a=e.y,l=r.width/2,c=r.height/2,u=Math.min(r.width,r.height)/2,d=Tf().domain([0,n]).range([0,u]);for(const r of t){if(r===e)continue;if(!r.datum)continue;const t=r.x,u=r.y,h=Math.atan2(u-a,t-s),p=Math.hypot(t-s,u-a),f=Number(o(r.datum)),g=isFinite(f)&&f>=0?n>0?d(f):0:p,y=l+Math.cos(h)*g,m=c+Math.sin(h)*g;r.x=t+(y-t)*i,r.y=u+(m-u)*i}return e.x=s+(l-s)*i,e.y=a+(c-a)*i,{cx:e.x,cy:e.y,maxCost:n,availableRadius:u,layout:"radial"}}(i,u,c,h,s,o),f=t.filter(t=>"line"===t.type);if(f.length>0){const t=new Map;for(const e of i)null!=e.pointId&&t.set(e.pointId+"",[e.x,e.y]);for(const o of f){const n=o.datum?.source,i=o.datum?.target;if(null!=n&&null!=i){const r=t.get(n+""),s=t.get(i+"");if(r&&s)if("fractional"===e.lineMode&&o.path.length>2){const t=o.path[0],e=o.path[o.path.length-1],n=[r[0]-t[0],r[1]-t[1]],i=[s[0]-e[0],s[1]-e[1]],a=[0];for(let t=1;o.path.length>t;t++)a.push(a[t-1]+Math.hypot(o.path[t][0]-o.path[t-1][0],o.path[t][1]-o.path[t-1][1]));const l=a[a.length-1];o.path=o.path.map((t,e)=>{const r=l>0?a[e]/l:e/(o.path.length-1);return[t[0]+n[0]*(1-r)+i[0]*r,t[1]+n[1]*(1-r)+i[1]*r]})}else o.path=[r,s]}}}return p}(this.scene,t,e,this.areas.length);o&&(this.cartogramLayout=o)}applyDecay(){const t=this.config.decay;if(!t||!this.pointBuffer)return;const e=this.pointBuffer.size;if(0===e)return;const o=this.scene.filter(t=>"point"===t.type);for(let n=0;o.length>n;n++){const i=Ua(t,n,e);o[n]._decayOpacity=i,o[n].style={...o[n].style,opacity:i}}}applyPulse(t=this.currentTime()){const e=this.config.pulse;if(!e||!this.timestampBuffer)return!1;const o=this.scene.filter(t=>"point"===t.type),n=this.timestampBuffer.toArray(),i=e.color||"rgba(255,255,255,0.6)",r=e.glowRadius??4;let s=!1;for(let a=0;o.length>a&&n.length>a;a++){const l=Za(e,n[a],t);s=Qa(o[a],l,i,r)||s}return s}refreshPulse(t){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(t)}hasActivePulsesAt(t){return!!this.config.pulse&&Ja(this.config.pulse,this.timestampBuffer,t)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(t){const e=this.config.transition?.duration??300;if(0>=e)return;const o=new Map;for(const e of t)"point"===e.type&&e.pointId&&o.set(e.pointId,[e.x,e.y]);const n=this.scene.filter(t=>"point"===t.type);let i=!1;for(const t of n)if(t.pointId){const e=o.get(t.pointId);e&&(t._targetX=t.x,t._targetY=t.y,t.x=e[0],t.y=e[1],(Math.abs(e[0]-t._targetX)>.5||Math.abs(e[1]-t._targetY)>.5)&&(i=!0))}for(const t of n)t.pointId&&!o.has(t.pointId)&&(t._targetOpacity=t.style?.opacity??t.style?.fillOpacity??1,t.style={...t.style,opacity:0},i=!0);i&&(this.activeTransition={startTime:this.currentTime(),duration:e})}cancelIntroAnimation(){this.activeTransition=null;for(const t of this.scene)"point"===t.type&&(null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0),null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0))}advanceTransition(t){if(!this.activeTransition)return!1;const e=Va(t,this.activeTransition),o=Ga(e),n=this.scene.filter(t=>"point"===t.type);for(const t of n){if(null!=t._targetX&&null!=t._targetY){const e=t.y;t.x=Ha(t.x,t._targetX,o),t.y=Ha(e,t._targetY,o)}null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity*o})}if(e>=1){for(const t of n)null!=t._targetX&&(t.x=t._targetX,t.y=t._targetY,t._targetX=void 0,t._targetY=void 0),null!=t._targetOpacity&&(t.style={...t.style,opacity:t._targetOpacity},t._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};Uf.QUADTREE_THRESHOLD=500;var Kf=Uf;function Zf(t){if(!t)return;const e=[];for(const o of t)if("point"===o.type)e.push(o);else if("glyph"===o.type){const t=o,n=f(t.glyph,t.size);e.push({pointId:t.pointId,x:t.x+n.centerDx,y:t.y+n.centerDy,r:n.radius})}return e}Xl(Kf);import{Fragment as Qf,jsxs as Jf}from"react/jsx-runtime";function tg(t,e){const o=ye(t.theme),n=t.size||[t.width||600,t.height||400],i=qe({top:10,right:10,bottom:10,left:10,...t.margin},t.title),r=Ve(t.title),s=Array.isArray(t.areas)?Ht(t.areas):t.areas,a=Ht(t.points),l=Ht(t.lines),c=t.showLegend?(()=>{const e="string"==typeof(o=t.colorBy)||"function"==typeof o?t.colorBy:void 0;var o;return iu(a.length>0?a:Array.isArray(s)&&s.length>0?"string"==typeof e?s.map(t=>({...t.properties||{},...t})):s:[],e)})():[];Ld(i,{props:t,categories:c,theme:o,size:n,hasTitle:r});const u=$d({props:t,categories:c,theme:o,size:n,margin:i,hasTitle:r}),d=n[0]-(i.left??0)-(i.right??0),h=n[1]-(i.top??0)-(i.bottom??0),p={projection:t.projection||"equalEarth",projectionExtent:t.projectionExtent,xAccessor:t.xAccessor,yAccessor:t.yAccessor,lineDataAccessor:t.lineDataAccessor,pointIdAccessor:t.pointIdAccessor,lineIdAccessor:t.lineIdAccessor,lineType:t.lineType,flowStyle:t.flowStyle,areaStyle:t.areaStyle,pointStyle:t.pointStyle,lineStyle:t.lineStyle,colorScheme:t.colorScheme,graticule:t.graticule,fitPadding:t.fitPadding,projectionTransform:t.projectionTransform,customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:i,onLayoutError:t.onLayoutError,themeCategorical:o.colors.categorical,themeSemantic:Rt(o),themeSequential:o.colors.sequential,themeDiverging:o.colors.diverging},f=new Kf(p);if(s){if("string"==typeof s)throw Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${s}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${s}')\` before calling renderGeoToStaticSVG.`);f.setAreas(s)}t.points&&f.setPoints(a),t.lines&&f.setLines(l),f.computeScene({width:d,height:h});const g=Id(t.backgroundGraphics,n,i,f.scales),y=Id(t.foregroundGraphics,n,i,f.scales),m=Vc({nodes:f.scene,renderMode:t.renderMode,fallback:(t,e)=>function(t,e){return Ac(function(t,e){switch(t.type){case"geoarea":{const o=t;if(!o.pathData)return null;const n=ot(o.style.fill)?et(o.style.fill,`geoarea-${e}-hatch`):void 0;return Rc(Lc.Fragment,{children:[n&&$c("defs",{children:n}),$c("path",{d:o.pathData,fill:n?`url(#geoarea-${e}-hatch)`:gc(o.style.fill,"#e0e0e0"),fillOpacity:o.style.fillOpacity??1,stroke:o.style.stroke||"none",strokeWidth:o.style.strokeWidth??.5,strokeDasharray:o.style.strokeDasharray,opacity:o._decayOpacity??1})]},"geoarea-"+e)}case"point":{const o=t,n=ot(o.style.fill)?et(o.style.fill,`geopoint-${e}-hatch`):void 0;return Rc(Lc.Fragment,{children:[n&&$c("defs",{children:n}),$c("circle",{cx:o.x,cy:o.y,r:o.r,fill:n?`url(#geopoint-${e}-hatch)`:gc(o.style.fill),fillOpacity:o.style.fillOpacity??.8,stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o._decayOpacity??o.style.opacity??1})]},"point-"+e)}case"line":{const o=t;if(2>o.path.length)return null;const n="M"+o.path.map(t=>`${t[0]},${t[1]}`).join("L");return $c("path",{d:n,fill:"none",stroke:o.style.stroke||"#4e79a7",strokeWidth:o.style.strokeWidth??1.5,strokeDasharray:o.style.strokeDasharray,opacity:o.style.opacity??1},"line-"+e)}case"glyph":return mc(t,t.x,t.y,"geo-glyph-"+(t.pointId??e));default:return null}}(t,e),t,"geo-cursor-"+e)}(t,e)});if(0===m.length){let r;const s=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Zf(f.scene),idPrefix:t._idPrefix,onRender:t=>{r=t}}):null;return e&&(e.evidence=Ba({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:r,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),gf.renderToStaticMarkup(Cd(g||y||t.annotations||f.customLayoutOverlays?Jf(Qf,{children:[g,s,y,f.customLayoutOverlays]}):null,{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}const x=m.map(t=>t.element);let b;const v=t.annotations?td({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,scales:{geoProjection:f.scales?.projectedPoint?([t,e])=>f.scales.projectedPoint(t,e):void 0},layout:{width:d,height:h},theme:o,pointNodes:Zf(f.scene),idPrefix:t._idPrefix,onRender:t=>{b=t}}):null;return e&&(e.evidence=Ba({frameType:"geo",width:n[0],height:n[1],marks:m.map(t=>t.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:b,legendItems:c.length>0?c.length:null!=t.legend?1:void 0,margin:i})),gf.renderToStaticMarkup(Cd(Jf(Qf,{children:[g,x,v,y,f.customLayoutOverlays]}),{width:n[0],height:n[1],className:"stream-geo-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:o,innerTransform:`translate(${i.left??0},${i.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:t._idPrefix}))}import*as eg from"react-dom/server.browser";function og(t=[]){return t.map(t=>({id:t.id,label:t.label,count:t.count,...null!=t.secondary?{secondary:t.secondary}:{},...t.secondaryLabel?{secondaryLabel:t.secondaryLabel}:{},...null!=t.observed?{observed:t.observed}:{}}))}var ng={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function ig(t){const e=t.datum;if(e&&"object"==typeof e){const t=e.label??e.name??e.id;if(null!=t&&""!==t)return t+""}return t.id}function rg(t,e,o){const n="function"==typeof e?e(t,o):e;return{...ng,...n??{}}}function sg(t,e={},o="settled"){return t.map((t,n)=>function(t,e={},o={index:0,simulationState:"settled"}){const n=function(t){return t.datum&&"object"==typeof t.datum?t.datum:null}(t),i={label:e.getBodyLabel?.(t)??ig(t)},r={style:rg(t,e.bodyStyle,o),datum:n,accessibleDatum:n,accessibility:i,_transitionKey:t.id};return"aabb"===t.shape.type?{type:"rect",x:t.x-t.shape.width/2,y:t.y-t.shape.height/2,w:t.shape.width,h:t.shape.height,...r}:{type:"point",x:t.x,y:t.y,r:t.shape.radius,pointId:t.id,...r}}(t,e,{index:n,simulationState:o}))}import{jsx as ag,jsxs as lg}from"react/jsx-runtime";var cg={top:0,right:0,bottom:0,left:0};function ug(t,e,o){return"function"==typeof t?t({size:e,margin:o}):t}function dg(t,e={}){const{element:o,scene:n,evidence:i}=function(t,e={}){const{width:o=640,height:n=360,title:i,description:r,background:s,backgroundGraphics:a,backgroundGraphicsBackdrop:l,className:c,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:p,renderBodySVG:f,renderChrome:g,...y}=e,m=function(t,e={}){const o=t.settle(e.maxSteps),n=t.readBodies(),i=t.snapshot(),r=sg(n,e,i.simulationState),s=function(t,e={}){const o=e.bodies??function(t){return t.world.bodies.map(t=>({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,shape:{...t.shape},sleeping:t.sleeping,datum:t.datum}))}(t),n=o.filter(t=>t.sleeping).length,i=t.queue.length,r=t.sediment.reduce((t,e)=>t+e.count,0),s="settled"===t.simulationState&&0===i&&n===o.length,a=[];i>0&&a.push("PHYSICS_QUEUE_UNDRAINED");const l=null!=e.charge&&Number.isFinite(e.charge)?function(t,e,o,n){const i=t-(e+o+n);return{charge:t,live:e,queued:o,sedimented:n,unaccounted:i,balanced:0===i}}(e.charge,o.length,i,r):void 0;return l&&!l.balanced&&a.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:o.length,sleepingCount:n,settled:s,stepsRun:Math.max(0,Math.floor(e.stepsRun??0)),seed:t.world.options.seed,binCounts:og(e.projectionRows),queuedCount:i,sedimentedCount:r,...l?{ledger:l}:{},warnings:a}}(i,{bodies:n,projectionRows:e.projectionRows,stepsRun:o,charge:e.charge});return{snapshot:i,bodies:n,sceneNodes:r,evidence:s,stepsRun:o}}(t,y),x={...cg,...h},b=[o,n],v=ug(a,b,x),w=ug(u,b,x),k=function(t){const e=t.replace(/[^A-Za-z0-9_-]/g,"_");return!e||/^\d/.test(e)?"physics-"+e:e}(d),A=i?k+"-title":void 0,S=r?k+"-desc":void 0,M=[A,S].filter(Boolean).join(" ")||void 0,_=x.left||x.top?`translate(${x.left},${x.top})`:void 0,P=Math.max(1,o-x.left-x.right),L=Math.max(1,n-x.top-x.bottom),$=k+"-plot-clip",R=_&&null!=v?ag("g",{transform:_,children:v}):v;return{element:lg("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:o,height:n,viewBox:`0 0 ${o} ${n}`,role:"img","aria-labelledby":M,style:p,children:[i&&ag("title",{id:A,children:i}),r&&ag("desc",{id:S,children:r}),ag("defs",{children:ag("clipPath",{id:$,children:ag("rect",{width:P,height:L})})}),l&&"transparent"!==l?ag("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:o,height:n,fill:l}):null,!a&&s&&"transparent"!==s?ag("rect",{x:0,y:0,width:o,height:n,fill:s}):null,R,ag("g",{id:k+"-data-area",transform:_,clipPath:`url(#${$})`,children:m.sceneNodes.map((t,e)=>{const o=m.bodies[e],n=o&&f?f(o,t.style??{},e,k):void 0;return null!=n?Ac(n,t,e):Yc(t,e,k)})}),w,g?.(m)]}),scene:m,evidence:m.evidence}}(t,e);return{svg:eg.renderToStaticMarkup(o),scene:n,evidence:i}}function hg(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function pg(t,e){const o="sensor"===t.physics?e.sensorThickness:e.barrierThickness;return Math.max(0,hg(t.thickness)??hg(o)??hg(e.thickness)??4)}function fg(t){return t.sensorId??"stream-region-"+t.id}function gg(t){const e=fg(t),o={bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution};if("boundary"===t.collider&&"aabb"===t.shape.type){const n=t.colliderThickness??8,i=t.shape.x-t.shape.width/2,r=t.shape.x+t.shape.width/2,s=t.shape.y-t.shape.height/2,a=t.shape.y+t.shape.height/2;return[{...o,id:e+"-top",shape:{type:"segment",x1:i,y1:s,x2:r,y2:s,thickness:n}},{...o,id:e+"-right",shape:{type:"segment",x1:r,y1:s,x2:r,y2:a,thickness:n}},{...o,id:e+"-bottom",shape:{type:"segment",x1:r,y1:a,x2:i,y2:a,thickness:n}},{...o,id:e+"-left",shape:{type:"segment",x1:i,y1:a,x2:i,y2:s,thickness:n}}]}return t.collider?[{...o,id:e+"-collider",shape:t.shape}]:[]}import{jsx as yg}from"react/jsx-runtime";function mg({title:t,totalWidth:e,marginTop:o}){return t?"string"!=typeof t?yg("foreignObject",{x:0,y:0,width:e,height:o,children:t}):yg("text",{x:e/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:t}):null}import{scaleLinear as xg}from"d3-scale";function bg(t){return"circle"===t.shape.type?t.shape.radius:Math.max(t.shape.width,t.shape.height)/2}import{jsx as vg,jsxs as wg}from"react/jsx-runtime";var kg={top:0,right:0,bottom:0,left:0};function Ag(e,o){const n=e.size??[e.width??600,e.height??400],i=ye(e.theme),r=void 0===e.theme?{}:Ct(i),s=e.bodyStyle,a=!1,l=e.legendPosition??"right",c=He({...kg,...e.margin},a,!!e.legend&&"top"===l);if(e.legend){const t={...c};so(c,{legend:e.legend,position:l,size:n,hasTitle:a,legendLayout:e.legendLayout}),Ue(c,t,n,l)}let u;const d=function({annotations:t,chartId:e,chartType:o,config:n,onRegionObservation:i,regionEffects:r,seed:s,size:a}){const l=function(t=[],e={}){const o=e.idPrefix?e.idPrefix+"-":"",n=[];for(const i of t){if("barrier"!==i.physics&&"sensor"!==i.physics)continue;const t=i.axis??e.defaultAxis??"x",r=pg(i,e),s=i.colliderId??`${o}${i.id}`;let a;if("x"===t){const t=hg(i.x),o=hg(i.y1)??hg(e.plotBounds?.y)??hg(i.y),n=hg(i.y2)??(e.plotBounds?e.plotBounds.y+e.plotBounds.height:void 0)??hg(i.y);if(null==t||null==o||null==n)continue;a={type:"segment",x1:t,y1:o,x2:t,y2:n,thickness:r}}else{const t=hg(i.y),o=hg(i.x1)??hg(e.plotBounds?.x)??hg(i.x),n=hg(i.x2)??(e.plotBounds?e.plotBounds.x+e.plotBounds.width:void 0)??hg(i.x);if(null==t||null==o||null==n)continue;a={type:"segment",x1:o,y1:t,x2:n,y2:t,thickness:r}}n.push({id:s,shape:a,sensor:"sensor"===i.physics,..."barrier"!==i.physics||null==i.restitution&&null==e.barrierRestitution?{}:{restitution:hg(i.restitution)??hg(e.barrierRestitution)},..."barrier"!==i.physics||null==i.friction&&null==e.barrierFriction?{}:{friction:hg(i.friction)??hg(e.barrierFriction)}})}return n}((t??[]).filter(t=>"barrier"===t.physics||"sensor"===t.physics),{idPrefix:e?e+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:a[0],height:a[1]}}),c=void 0===s||void 0!==n?.kernel?.seed?n:{...n,kernel:{...n?.kernel,seed:s}},u=r.flatMap(t=>[{id:fg(t),sensor:!0,shape:t.shape,bodyFilter:t.bodyFilter,friction:t.friction,restitution:t.restitution},...gg(t)]),d=Object.fromEntries(r.map(t=>[fg(t),{binId:t.binId??t.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,p=r.length>0;return p||u.length>0||l.length>0||null!=e||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:e??h?.chartId,chartType:h?.chartType??o,sensors:{...h?.sensors??{},...d},onObservation:t=>{p&&i(t),h?.onObservation?.(t)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:[Math.max(1,n[0]-c.left-c.right),Math.max(1,n[1]-c.top-c.bottom)]}),h=new t(d);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&h.enqueue(e.initialSpawns.map(t=>({...t,spawnAt:void 0})));const p=dg(h,{...e,width:n[0],height:n[1],background:e.background??i.colors.background,bodyStyle:(t,e)=>({fill:i.colors.primary,stroke:i.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof s?s(t,e):s}),style:{...r,fontFamily:i.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:c,renderChrome:t=>{const o=function(t,e,o,n,i){const r=Math.max(1,o[0]-n.left-n.right),s=Math.max(1,o[1]-n.top-n.bottom),a=function(t){return t?.length?t.map(t=>null!=t.pointId||null==t.bodyId?t:{...t,pointId:t.bodyId+""}):t}(e.annotations),l=function(t){const{width:e,height:o,pointNodes:n=[],data:i}=t;return{scales:{x:xg().domain([0,Math.max(1,e)]).range([0,Math.max(1,e)]),y:xg().domain([0,Math.max(1,o)]).range([0,Math.max(1,o)])},width:e,height:o,frameType:"network",pointNodes:n,data:i,xAccessor:"x",yAccessor:"y"}}({width:r,height:s,pointNodes:(c=t.bodies,c.map(t=>({pointId:t.id,x:t.x,y:t.y,r:Math.max(1,bg(t))})))});var c;const u=l.scales?.x,d=l.scales?.y;if(!u||!d)throw Error("Physics annotation context requires pixel scales");let h;const p=td({annotations:a,autoPlaceAnnotations:e.autoPlaceAnnotations,scales:{x:u,y:d},layout:{width:r,height:s},theme:i,frameType:"network",xAccessor:l.xAccessor,yAccessor:l.yAccessor,pointNodes:l.pointNodes,svgAnnotationRules:e.svgAnnotationRules,onRender:t=>{h=t}}),f=e.legend?Pd(e.legend,{theme:i,position:e.legendPosition,size:[o[0],o[1]],margin:n,hasTitle:!!e.title,legendLayout:e.legendLayout})??od(e.legend,o,n,e.legendPosition,e.legendLayout):null;return{annotationRender:h,node:wg("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:o[0],height:o[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[vg("g",{transform:`translate(${n.left},${n.top})`,children:p}),vg(mg,{title:e.title,totalWidth:o[0],marginTop:Math.max(n.top,28)}),f]})}}(t,e,n,c,i);return u=o.annotationRender,o.node}});return o&&(o.evidence=Ba({frameType:"physics",width:n[0],height:n[1],marks:p.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:u,extraWarnings:[...0===p.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...p.scene.evidence.warnings]})),p.svg}import*as Sg from"react-dom/server.browser";import{jsx as Mg,jsxs as _g}from"react/jsx-runtime";var Pg={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function Lg(t,e){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:e}var $g={BigNumber:function(t,e){const o="presentation"===t.mode||"inline"===t.mode||"thumbnail"===t.mode?t.mode:"tile",n=Pg[o],i=Lg(t.width,n.width),r=Lg(t.height,n.height),s="number"==typeof t.padding&&Number.isFinite(t.padding)?Math.max(0,t.padding):n.padding,a="center"===t.align||"end"===t.align||"start"===t.align?t.align:n.align,l="center"===a?"middle":"end"===a?"end":"start",c="center"===a?i/2:"end"===a?i-s:s,u=ye(t.theme),d="number"==typeof t.value&&Number.isFinite(t.value)?t.value:void 0,h=function(t,e={}){if("function"==typeof t)return t;const o=e.locale??"en-US";if("currency"===t){const t=e.precision??2,n=new Intl.NumberFormat(o,{style:"currency",currency:e.currency??"USD",maximumFractionDigits:t,minimumFractionDigits:t});return t=>n.format(t)}if("percent"===t){const t=new Intl.NumberFormat(o,{style:"percent",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("compact"===t){const t=new Intl.NumberFormat(o,{notation:"compact",maximumFractionDigits:e.precision??1,minimumFractionDigits:0});return e=>t.format(e)}if("duration"===t)return t=>function(t){if(!Number.isFinite(t))return t+"";const e=0>t?"-":"",o=Math.abs(t);if(1e3>o)return`${e}${Math.round(o)}ms`;const n=o/1e3;if(60>n)return`${e}${i=n,Math.round(100*i)/100+""}s`;var i;const r=n/60;if(60>r){const t=Math.floor(r),o=Math.round(n-60*t);return 0===o?`${e}${t}m`:`${e}${t}m ${o}s`}const s=r/60;if(24>s){const t=Math.floor(s),o=Math.round(r-60*t);return 0===o?`${e}${t}h`:`${e}${t}h ${o}m`}const a=Math.floor(s/24),l=Math.round(s-24*a);return 0===l?`${e}${a}d`:`${e}${a}d ${l}h`}(t);const n=new Intl.NumberFormat(o,{notation:e.notation??"standard",maximumFractionDigits:e.precision??0,minimumFractionDigits:0});return t=>n.format(t)}("string"==typeof t.format||"function"==typeof t.format?t.format:"number",{locale:"string"==typeof t.locale?t.locale:void 0,currency:"string"==typeof t.currency?t.currency:void 0,precision:"number"==typeof t.precision?t.precision:void 0}),p=void 0===d?"No value":(f=h(d),`${("string"==typeof t.prefix?t.prefix:void 0)??""}${f}${("string"==typeof t.suffix?t.suffix:void 0)??""}`);var f;const g=void 0===d?void 0:function(t,e){if(!e||0===e.length)return null;if(!Number.isFinite(t))return null;const o=e.filter(t=>Number.isFinite(t.at)||t.at===-1/0).slice().sort((t,e)=>t.at-e.at);let n=null;for(const e of o){if(e.at>t)break;n=e}return n}(d,t.thresholds),y="string"==typeof t.color?t.color:function(t,e,o){return e||("success"===t?o.colors.success??"#2ca02c":"warning"===t?o.colors.warning??"#b26a00":"danger"===t?o.colors.danger??"#d62728":"info"===t?o.colors.info??o.colors.primary:o.colors.text)}(g?.level??"neutral",g?.color,u),m="string"==typeof t.label?t.label:void 0,x="string"==typeof t.caption?t.caption:void 0,b="string"==typeof t.unit?t.unit:void 0,v=void 0===d?void 0:function(t,e,o){const n=t.comparison&&"object"==typeof t.comparison?t.comparison:void 0,i=n&&"number"==typeof n.value&&Number.isFinite(n.value)?n.value:void 0,r=("number"==typeof t.delta&&Number.isFinite(t.delta)?t.delta:void 0)??(void 0===i?void 0:e-i);if(void 0===r)return;const s=function(t,e){return Number.isFinite(t)?0===t?e(0):`${t>0?"+":"−"}${e(Math.abs(t))}`:""}(r,o);return`${s}${n&&"string"==typeof n.label?" "+n.label:""}`}(t,d,h),w=void 0===d?void 0:function(t,e,o){const n=t.target&&"object"==typeof t.target?t.target:void 0;if(!n||"number"!=typeof n.value||!Number.isFinite(n.value))return;const i="string"==typeof n.label?" "+n.label:"";return 0===n.value?`target ${o(n.value)}${i}`:`${new Intl.NumberFormat("string"==typeof t.locale?t.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(e/n.value)} of ${o(n.value)}${i}`}(t,d,h),k=[v,w,g?.label].filter(Boolean).join(" · "),A="string"==typeof t.description&&t.description||[m,p,b,k].filter(Boolean).join(", "),S="string"==typeof t.background?t.background:u.colors.surface??u.colors.background,M="string"==typeof t.borderColor?t.borderColor:u.colors.border,_=s+n.labelSize,P=_+n.captionSize+4,L="presentation"===o?r/2+.32*n.valueSize:"thumbnail"===o?r/2+.34*n.valueSize:Math.min(r-s-(k?26:4),(n.showHeader&&(m||x)?x?P+10:_+14:s)+n.valueSize),$=c+("start"===l?Math.max(n.valueSize,p.length*n.valueSize*.55):0),R=Sg.renderToStaticMarkup(_g("svg",{xmlns:"http://www.w3.org/2000/svg",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-label":A,"data-semiotic-component":"BigNumber",children:[Mg("title",{children:m??p}),"string"==typeof t.description&&Mg("desc",{children:t.description}),Mg("rect",{x:n.border?.5:0,y:n.border?.5:0,width:n.border?i-1:i,height:n.border?r-1:r,rx:n.border?8:0,fill:S,stroke:n.border?M:"none"}),n.showHeader&&m&&Mg("text",{x:c,y:_,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.labelSize,fontWeight:600,fill:u.colors.text,children:m}),n.showHeader&&x&&Mg("text",{x:c,y:P,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.captionSize,fill:u.colors.textSecondary,children:x}),Mg("text",{x:c,y:L,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:p}),b&&void 0!==d&&"start"===l&&Mg("text",{x:$+6,y:L,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*n.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),n.showDetail&&k&&Mg("text",{x:c,y:Math.min(r-s,L+n.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:n.detailSize,fill:u.colors.textSecondary,children:k})]}));return e&&(e.evidence=Ba({frameType:"value",width:i,height:r,marks:void 0===d?[]:[{type:"value"}],title:m,description:A})),R}};function Rg(t,e,o){return $g[t](e,o)}import{Fragment as Cg,jsx as Tg,jsxs as Og}from"react/jsx-runtime";function Ig(t,e){switch(t){case"xy":return Xd(e);case"ordinal":return Ch(e);case"network":return ff(e);case"geo":return tg(e);case"physics":return Ag(e);default:throw Error(`Unknown frame type: ${t}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function zg(t){return Xd(t)}function Fg(t){return Ch(t)}function Ng(t){return ff(t)}function Eg(t){return tg(t)}var Dg=new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),Wg=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function Bg(t,e){const o=Number(t);if(!Number.isFinite(o))return t;const n=10**e,i=Math.round((o+Number.EPSILON)*n)/n;return Object.is(i,-0)?"0":i+""}function jg(t,e){const o=function(t){if(Number.isFinite(t))return Math.max(0,Math.min(8,Math.floor(t)))}(e);return void 0===o?t:t.replace(/<[^>]+>/g,t=>t.replace(/\s([\w:-]+)="([^"]*)"/g,(t,e,n)=>!Dg.has(e)||/\b(?:var|calc|url)\(/i.test(n)?t:` ${e}="${function(t,e){const o=RegExp(Wg.source,Wg.flags);let n,i="",r=0,s=!1;for(;n=o.exec(t);){const o=t.slice(r,n.index);i+=s&&0===o.length?" ":o,i+=Bg(n[0],e),r=n.index+n[0].length,s=!0}return i+t.slice(r)}(n,o)}"`))}var Yg=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],Xg=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function Gg(t,e){const o={};for(const n of e)void 0!==t[n]&&(o[n]=t[n]);return o}function Vg(t,e,o){return qg(t,e,o).svg}function Hg(t,e,o){const n={},{svg:i,frameType:r}=qg(t,e,o,n),s=n.evidence??Ba({frameType:r,width:"number"==typeof e.width?e.width:600,height:"number"==typeof e.height?e.height:400,marks:[],title:"string"==typeof e.title?e.title:void 0,description:"string"==typeof e.description?e.description:void 0,annotations:e.annotations,extraWarnings:["NO_EVIDENCE"]});return s.component=t,Yt(s,t,e),{svg:i,evidence:s}}function qg(t,e,o,n){if(Object.prototype.hasOwnProperty.call($g,t))return{svg:jg(Rg(t,e,n),o?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(Ea,t))throw Error(`Unknown chart component: "${t}". Run \`npx semiotic-ai --list\` for supported chart types.`);const i=Ea[t];var r;const s=function(t,e,o){const n=It[t||"primary"],i=t&&"primary"!==t||!o?.width?n.width:o.width,r=t&&"primary"!==t||!o?.height?n.height:o.height,s={...e,mode:t},a=ut(s,{width:e.width??i,height:e.height??r}).props,l=a.mode||t||"primary",c=It[l],u="context"===l||"sparkline"===l,d="primary"===l&&o?.width?o.width:c.width;return{mode:l,width:a.width??d,height:a.height??("primary"===l&&o?.height?o.height:c.height),showAxes:a.showAxes??c.showAxes,showGrid:a.showGrid??c.showGrid,enableHover:a.enableHover??(!!a.linkedHover||c.enableHover),showLegend:a.showLegend??c.showLegend,showLabels:a.showLabels??c.showLabels,title:u?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:u?void 0:a.xLabel,yLabel:u?void 0:a.yLabel,categoryLabel:u?void 0:a.categoryLabel,valueLabel:u?void 0:a.valueLabel,marginDefaults:zt(c.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:u,mobileInteraction:Ot(a.mobileInteraction,{mode:l,width:a.width??d,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}(i.layout?.mode??("string"==typeof(r=e.mode)&&Object.prototype.hasOwnProperty.call(It,r)?e.mode:void 0),{...i.layout?.modeDefaults,...Gg(e,Xg)},i.layout?.primarySize),{data:a,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:p,colorBy:f,legendPosition:g,...y}=e,{width:m,height:x}=s,b=[m,x],v=y.frameProps||{},w=i.layout?.margin,k="function"==typeof w?w(e,s):w??s.marginDefaults,A=void 0!==h?h:v.margin,S=function(t){if(null==t)return;if("number"==typeof t)return{top:t,right:t,bottom:t,left:t};const e={};return"number"==typeof t.top&&(e.top=t.top),"number"==typeof t.right&&(e.right=t.right),"number"==typeof t.bottom&&(e.bottom=t.bottom),"number"==typeof t.left&&(e.left=t.left),e}(A),M="number"==typeof A?{top:A,right:A,bottom:A,left:A}:{...k,...S},_=Gg(y,Yg),P=t=>v[t]??s[t],L={...v,..._,theme:l,title:s.title,description:s.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c,className:u,annotations:d,size:b,margin:M,__compactMode:s.compactMode,__autoLegendMargin:!0,...void 0!==p&&{colorScheme:p},...void 0!==g&&{legendPosition:g},_idPrefix:y._idPrefix},$=i.buildProps(a,f,p,L,y);let R;switch(i.frameType){case"xy":R=Xd($,n);break;case"ordinal":R=Ch($,n);break;case"network":R=ff($,n);break;case"geo":R=tg($,n);break;case"physics":R=Ag($,n)}const C=i.renderOverlay?.($,{theme:ye(l)});if(null!=C){const t=Xt.renderToStaticMarkup(Tg(Cg,{children:C})),e=R.lastIndexOf("</svg>");R=0>e?`${R}${t}`:`${R.slice(0,e)}${t}${R.slice(e)}`}return{svg:jg(R,o?.precision),frameType:i.frameType}}function Ug(t,e={}){const{title:o,subtitle:n,theme:i,width:r=1200,height:s,layout:a={},background:l}=e,c=me(ye(i)),u=a.columns||2,d=a.gap??16;let h=0;o&&(h+=30),n&&(h+=20),h>0&&(h+=10);const p=Math.floor((r-d-d*(u-1))/u),f=[];let g=0,y=h+d,m=0;for(const e of t){const t=Math.min(e.colSpan||1,u),o=e.props.height||300;g+t>u&&(y+=m+d,g=0,m=0),f.push({chart:e,x:d/2+g*(p+d),y:y,w:p*t+d*(t-1),h:o}),m=Math.max(m,o),g+=t}const x=s||y+m+d,b=f.map((t,e)=>{const{chart:o,x:n,y:r,w:s,h:a}=t,l={...o.props,width:s,height:a,theme:i,_idPrefix:"chart-"+e};let c;return c=o.component?Vg(o.component,l):o.frameType?Ig(o.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${a}"></svg>`,Tg("g",{transform:`translate(${n},${r})`,children:Tg("foreignObject",{width:s,height:a,children:Tg("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:c}})})},"dashboard-chart-"+e)});return Xt.renderToStaticMarkup(Og("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:x,role:"img","aria-label":o||"Dashboard",style:{fontFamily:c.fontFamily},children:[o&&Tg("title",{children:o}),l&&Tg("rect",{x:0,y:0,width:r,height:x,fill:l}),o&&Tg("text",{x:r/2,y:24,textAnchor:"middle",fontSize:c.titleFontSize+4,fontWeight:c.titleFontWeight,fill:c.text,fontFamily:c.titleFontFamily,children:o}),n&&Tg("text",{x:r/2,y:o?46:20,textAnchor:"middle",fontSize:c.labelSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:n}),b]}))}import*as Kg from"react-dom/server.browser";import{Fragment as Zg,jsx as Qg,jsxs as Jg}from"react/jsx-runtime";function ty(t,e,o,n={}){const{stepSize:i,windowSize:r,frameCount:s,xExtent:a,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=n,p=o.width||600,f=o.height||400,g=ye(o.theme),y={...o,...a&&{xExtent:a},...l&&{yExtent:l}};if(!e||0===e.length)return[];const m=i||Math.max(1,Math.ceil(e.length/(s||Math.min(60,Math.max(10,e.length))))),x=[];for(let t=m;e.length>=t;t+=m)x.push(t);x[x.length-1]!==e.length&&x.push(e.length);const b=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(t),v=qe({top:20,right:20,bottom:30,left:40,...o.margin},o.title),w=p-v.left-v.right,k=f-v.top-v.bottom,A=[];if(b)for(let n=0;x.length>n;n++){const i=x[n],s=e.slice(r?Math.max(0,i-r):0,i),a={chartType:t,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:o.projection||"vertical",oAccessor:o.oAccessor||o.categoryAccessor||"category",rAccessor:o.rAccessor||o.valueAccessor||"value",colorAccessor:o.colorAccessor||o.colorBy,stackBy:o.stackBy,groupBy:o.groupBy,connectorAccessor:o.connectorAccessor,connectorStyle:o.connectorStyle,barPadding:o.barPadding,innerRadius:o.innerRadius,normalize:o.normalize,bins:o.bins,colorScheme:o.colorScheme||g.colors.categorical,...h&&{decay:h}},l=new mh(a);l.ingest({inserts:s,bounded:!0}),l.computeScene({width:w,height:k}),l.scene.length>0&&A.push(sy(l.scene,p,f,g,y))}else for(let n=0;x.length>n;n++){const i=x[n],s=e.slice(r?Math.max(0,i-r):0,i),m={chartType:t,windowSize:s.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:o.colorAccessor||o.colorBy,groupAccessor:o.groupAccessor||o.lineBy,lineDataAccessor:o.lineDataAccessor,xExtent:a,yExtent:l,colorScheme:o.colorScheme||g.colors.categorical,lineStyle:o.lineStyle,pointStyle:o.pointStyle,areaStyle:o.areaStyle,sizeAccessor:o.sizeAccessor||o.sizeBy,sizeRange:o.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},b=new ac(m);if(b.ingest({inserts:s,bounded:!0}),b.computeScene({width:w,height:k}),0===b.scene.length)continue;const v=b.scales?{y:b.scales.y}:void 0;if(A.push(ry(b.scene,p,f,g,y,v)),c>0&&n>0&&b.activeTransition){const t=c*(1e3/u);for(let e=1;c>=e;e++)b.advanceTransition(b.activeTransition.startTime+e/c*t),A.push(ry(b.scene,p,f,g,y,v))}}return A}function ey(t,e,o={}){return e.map(e=>{try{return Vg(t,{...o,...e})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${o.width||e.width||600}" height="${o.height||e.height||400}"></svg>`}})}function oy(t,e,o){const n=e.size??[e.width??600,e.height??400],i=ye(e.theme),r=me(i),s=e.background||i.colors.background,a=e.idPrefix??"physics-gif",l=e.title?`${a}-title-${o}`:void 0,c=e.description?`${a}-desc-${o}`:void 0,u=[l,c].filter(Boolean).join(" ")||void 0,d=sg(t.readBodies(),{bodyStyle:e.bodyStyle,getBodyLabel:e.getBodyLabel}),h=Jg("svg",{xmlns:"http://www.w3.org/2000/svg",className:e.className??"stream-physics-frame",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,role:"img","aria-labelledby":u,style:{fontFamily:r.fontFamily},children:[e.title&&Qg("title",{id:l,children:e.title}),e.description&&Qg("desc",{id:c,children:e.description}),s&&"transparent"!==s?Qg("rect",{x:0,y:0,width:n[0],height:n[1],fill:s}):null,Qg("g",{id:`${a}-frame-${o}`,children:d.map((t,e)=>Yc(t,e,`${a}-${o}`))})]});return Kg.renderToStaticMarkup(h)}function ny(e,o={}){const{fps:n=12,frameCount:i,durationSeconds:r=2,includeInitialFrame:s=!0,stepDt:a,stepsPerFrame:l,background:c}=o,u=Math.max(.001,a??e.config?.fixedDt??1/120),d=l??Math.max(1,Math.round(1/Math.max(1,n)/u)),h=i??Math.max(1,Math.ceil(r*Math.max(1,n))),p=c?{...e,background:c}:e,f=new t(e.config);e.initialSpawns?.length&&f.enqueue(e.initialSpawns,e.initialSpawnPacing);const g=[];for(s&&(f.tick(0),g.push(oy(f,p,0)));h>g.length;){for(let t=0;d>t;t+=1)f.tick(u);g.push(oy(f,p,g.length))}return g}function iy(t,e){const o=t.background||e.colors.background;return o&&"transparent"!==o?o:null}function ry(t,e,o,n,i,r){const s=me(n),a=qe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),l=e-a.left-a.right,c=o-a.top-a.bottom,u=iy(i,n),d=i.renderMode,h=t.map((t,e)=>Gc({node:t,index:e,renderMode:d,fallback:()=>Yc(t,e)}).element).filter(Boolean),p=function(t,e,o,n,i,r){if(!t||0===t.length)return null;const s=me(n),a=[];for(let n=0;t.length>n;n++){const l=t[n];if("y-threshold"===l.type&&null!=l.value){let t=null;if(r)t=r(l.value);else if(i){const[e,n]=i,r=n-e;if(0===r)continue;t=o-(l.value-e)/r*o}if(null==t)continue;const c=l.color||s.primary,u=l.labelPosition||"right";a.push(Jg("g",{children:[Qg("line",{x1:0,y1:t,x2:e,y2:t,stroke:c,strokeWidth:l.strokeWidth??1.5,strokeDasharray:l.strokeDasharray||"6,4"}),l.label&&Qg("text",{x:"left"===u?4:"center"===u?e/2:e-4,y:20>t?Math.min(o-4,t+16):t-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:s.tickSize,fill:c,fontFamily:s.fontFamily,children:l.label})]},"ann-"+n))}}return a.length>0?Qg(Zg,{children:a}):null}(i.annotations,l,c,n,i.yExtent,r?.y),f="string"==typeof i.title?i.title:void 0,g="string"==typeof i.description?i.description:void 0,y=f?"semiotic-title":void 0,m=g?"semiotic-desc":void 0,x=[y,m].filter(Boolean).join(" ")||void 0;return Kg.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":x,style:{fontFamily:s.fontFamily},children:[f&&Qg("title",{id:y,children:f}),g&&Qg("desc",{id:m,children:g}),u&&Qg("rect",{x:0,y:0,width:e,height:o,fill:u}),Jg("g",{transform:`translate(${a.left},${a.top})`,children:[p,h]}),f&&Qg("text",{x:e/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:f})]}))}function sy(t,e,o,n,i){const r=me(n),s=qe({top:20,right:20,bottom:30,left:40,...i.margin},i.title),a="radial"===i.projection,l=a?s.left+(e-s.left-s.right)/2:s.left,c=a?s.top+(o-s.top-s.bottom)/2:s.top,u=iy(i,n),d=Sh({nodes:t,renderMode:i.renderMode,idPrefix:i.idPrefix}).map(t=>t.element),h="string"==typeof i.title?i.title:void 0,p="string"==typeof i.description?i.description:void 0,f=h?"semiotic-title":void 0,g=p?"semiotic-desc":void 0,y=[f,g].filter(Boolean).join(" ")||void 0;return Kg.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:o,role:"img","aria-labelledby":y,style:{fontFamily:r.fontFamily},children:[h&&Qg("title",{id:f,children:h}),p&&Qg("desc",{id:g,children:p}),u&&Qg("rect",{x:0,y:0,width:e,height:o,fill:u}),Qg("g",{transform:`translate(${l},${c})`,children:d}),h&&Qg("text",{x:e/2,y:22,textAnchor:"middle",fontSize:r.titleFontSize,fontWeight:r.titleFontWeight,fill:r.text,fontFamily:r.titleFontFamily,children:h})]}))}export{ty as generateFrameSVGs,ey as generateFrameSequence,ny as generatePhysicsFrameSVGs,Vg as renderChart,Hg as renderChartWithEvidence,Ug as renderDashboard,Eg as renderGeoToStaticSVG,Ng as renderNetworkToStaticSVG,Fg as renderOrdinalToStaticSVG,Ig as renderToStaticSVG,zg as renderXYToStaticSVG,ye as resolveTheme,jg as serializeSvgPrecision,me as themeStyles};
1
+ function e(e){let t=e?.find(e=>"bottom"===e.orient),i=e?.find(e=>"top"===e.orient),r=e?.find(e=>"left"===e.orient),o=e?.find(e=>"right"===e.orient);return{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:o,xAxis:t??i,yAxis:r??o,xOrient:t||!i?"bottom":"top",yOrient:r||!o?"left":"right"}}function t(e){let t=6;for(let i=1;e.length>i;i++){let r=Math.abs(e[i]-e[i-1]);r>0&&Number.isFinite(r)&&(t=Math.max(t,Math.ceil(Math.log10(Math.max(Math.abs(e[i]),Math.abs(e[i-1]))/r))+1))}let i=Math.min(17,t);return e=>Number.isInteger(e)?e+"":Number(e.toPrecision(i))+""}function i(...e){let t;for(let i of e)i&&(t=r(t)&&r(i)?{legendGroups:[...t.legendGroups,...i.legendGroups],legendDistance:i.legendDistance??t.legendDistance}:i);return t}function r(e){return"object"==typeof e&&null!==e&&"legendGroups"in e&&Array.isArray(e.legendGroups)}function o(e){return"object"==typeof e&&null!==e&&"gradient"in e}function a(e){return"string"==typeof e&&e.length>0}function n(e,t,i=!1){let r=i?t?58:34:t?36:0;return r>e.top?{...e,top:r}:e}function l(e,t){return n(e,a(t))}function s(e,t,i,r,o=8){let a=r,n="left"===r?"right":"right"===r?"left":"top"===r?"bottom":"top",l=Math.max(t[a],Math.max(0,("left"===r||"right"===r?i[0]:i[1])-o)-e[n]);e[a]>l&&(e[a]=l)}function c(e){return Math.ceil(7*e.length)}function u(e,i){if(r(e)){let t=v(i),r=100;for(let i of e.legendGroups){i.label&&(r=Math.max(r,c(i.label)));for(let e of i.items)r=Math.max(r,t.swatchSize+t.labelGap+c(e.label))}return r}if(o(e)){let{gradient:i}=e,r=i.format||t(i.domain),o=Math.max(c(r(i.domain[0])),c(r(i.domain[1]))),a=i.label?c(i.label):0;return Math.max(100,19+o,a)}return 100}function d(e){return(r(e)||o(e))&&Number.isFinite(e.legendDistance)?Math.max(0,e.legendDistance):10}function h(e,t){return null!=e?.sideGutter?Math.max(0,e.sideGutter):t?.hasAxis?t.hasAxisLabel?sd:ld:0}function f(e){return Math.max(0,e?.edgeGutter??3)}function p(e,t){return null!=t?.axisGutter?Math.max(0,t.axisGutter):e?.hasAxis?e.hasAxisLabel?e.rotatedTicks?64:46:22:0}function y(t){let{bottomAxis:i,topAxis:r,leftAxis:o,rightAxis:a}=e(t.axes),n=!(r&&!i||!1===i?.visible),l=!!r&&!i&&!1!==r.visible,s=!(a&&!o||!1===o?.visible),c=!!a&&!1!==a.visible,u=!1!==t.showAxes;return{hasAxis:u&&n,hasAxisLabel:u&&n&&!!(i?.label??t.xLabel),rotatedTicks:u&&n&&(t.rotatedTicks??!!i?.autoRotate),topAxis:l?{hasAxis:u,hasAxisLabel:u&&!!(r?.label??t.xLabel),rotatedTicks:u&&(t.rotatedTicks??!!r?.autoRotate)}:void 0,leftAxis:s?{hasAxis:u,hasAxisLabel:u&&!!(o?.label??t.yLabel)}:void 0,rightAxis:c?{hasAxis:u,hasAxisLabel:u&&!!(a?.label??t.yLabelRight??t.yLabel)}:void 0}}function g(e,t,i){if(o(e))return e.gradient.label?46:26;if(!r(e))return 20;let a=v(i),n=Math.max(1,i?.maxWidth??t),l=a.rowHeight;for(let t of e.legendGroups){let e=0,i=0;for(let r of t.items){let t=a.swatchSize+a.labelGap+c(r.label),o=0===i?t:i+a.itemGap+t;i>0&&o>n?(e+=1,i=t):i=o}t.items.length>0&&(e+=1),l=Math.max(l,e*a.rowHeight,t.label?c(t.label):0)}return l+(e.legendGroups.length>1?16:0)}function m(e,t,i){return u(e,t)+d(e)+h(t,i)+f(t)}function x(e,t){let{legend:i}=t;if(!i)return;let r=t.position??"right",o=g(i,Math.max(1,t.size[0]-e.left-e.right),t.legendLayout)+d(i)+p("bottom"===r?t.axisChrome:"top"===r?t.axisChrome?.topAxis:void 0,t.legendLayout)+("top"===r&&t.hasTitle?24:0),a=Math.max(t.minimumMargin??0,"top"===r?t.hasTitle?58:34:0);"right"===r?e.right=Math.max(e.right,a,m(i,t.legendLayout,t.axisChrome?.rightAxis)):"left"===r?e.left=Math.max(e.left,a,m(i,t.legendLayout,t.axisChrome?.leftAxis)):"top"===r?e.top=Math.max(e.top,a,o):e.bottom=Math.max(e.bottom,a,o)}function b(e,t){let i=t.position??"right",r="top"===i||"bottom"===i,o=Math.max(0,t.totalWidth-t.margin.left-t.margin.right),a=Math.max(1,r?t.legendLayout?.maxWidth??o:t.reservedWidth??u(e,t.legendLayout)),n=d(e),l=h(t.legendLayout,"left"===i?t.axisChrome?.leftAxis:t.axisChrome?.rightAxis),s=f(t.legendLayout),c=g(e,o,t.legendLayout),y=p(t.axisChrome,t.legendLayout),m=p(t.axisChrome?.topAxis,t.legendLayout);if("left"===i)return{x:Math.max(s,t.margin.left-l-a-n),y:t.margin.top,width:a,height:c};if("top"===i)return{x:t.margin.left,y:t.margin.top-m-n-c,width:a,height:c};if("bottom"===i){let e=t.totalHeight-t.margin.bottom;return{x:t.margin.left,y:Math.max(e+n,Math.min(e+y+n,t.totalHeight-c)),width:a,height:c}}return{x:Math.min(t.totalWidth-a-s,t.totalWidth-t.margin.right+l+n),y:t.margin.top,width:a,height:c}}function v(e){let t=Math.max(1,e?.swatchSize??16),i=Math.max(t,e?.rowHeight??22);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??6),itemGap:Math.max(0,e?.itemGap??10),rowHeight:i,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}function w(e,t){let i=24;return e.map(({hasLabel:e,itemCount:r})=>{i+=5;let o,a=i;i+=8,e&&(i+=16,o=i,i+=8);let n=i;return i+=r*t+8,{lineY:a,labelY:o,itemsY:n,endY:i}})}function k(e,t,i=!1){let r={...e};for(let e of t??[])!1===e.visible&&("top"!==e.orient||!i)&&(r[e.orient]=0);return r}function A(e){let t=0;for(;e.length>t;){let i=/^\s+/.exec(e.slice(t));i&&(t+=i[0].length);let r=e.startsWith("\x3c!--",t)?"--\x3e":e.startsWith("<?",t)?"?>":void 0;if(r){let i=e.indexOf(r,t+2);if(0>i)return;t=i+r.length;continue}if(/^<!DOCTYPE\s/i.test(e.slice(t))){let i="",r=0,o=t+9;for(;e.length>o;o+=1){let t=e[o];if(i)t===i&&(i="");else if(e.startsWith("\x3c!--",o)){let t=e.indexOf("--\x3e",o+4);if(0>t)return;o=t+2}else if('"'===t||"'"===t)i=t;else if("["===t)r+=1;else if("]"===t)r-=1;else if(">"===t&&0===r)break}if(o===e.length)return;t=o+1;continue}break}let i=/^<((?:[A-Za-z_][\w.-]*:)?svg)(?=[\s/>])((?:[^<>"']|"[^"]*"|'[^']*')*)>/i.exec(e.slice(t));if(!i)return;let r=i[2].endsWith("/"),o=r?i[2].slice(0,-1):i[2];return o.replace(cd,"").trim()?void 0:{start:t,end:t+i[0].length,name:i[1],attributes:o,selfClosing:r}}function S(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g,"&#9;").replace(/\n/g,"&#10;").replace(/\r/g,"&#13;")}function M(e){return e.replace(/\r\n|[\t\r\n]/g," ").replace(/&(amp|quot|apos|lt|gt|#\d+|#x[\da-fA-F]+);/g,(e,t)=>{if(!t.startsWith("#"))return{amp:"&",quot:'"',apos:"'",lt:"<",gt:">"}[t];let i=t.startsWith("#x")?parseInt(t.slice(2),16):Number(t.slice(1));return i>0&&1114111>=i?String.fromCodePoint(i):e})}function _(e,t){for(let i of e.attributes.matchAll(cd))if(i[1]===t)return M(i[2]??i[3])}function P(e,t){let i=A(e);if(!i)return t;let r=e=>{let r=_(i,e),o=r&&/^[0-9]+(?:\.[0-9]+)?$/.test(r)?Number(r):NaN;return Number.isFinite(o)&&o>0?o:t[e]};return{width:r("width"),height:r("height")}}function L(e,t){let i=A(e);return i?function(e,t){let i=A(e);if(!i)return e;let r=new Map(Object.entries(t)),o=i.attributes.replace(cd,(e,t)=>{let i=r.get(t);return void 0===i?e:(r.delete(t),` ${t}="${S(i)}"`)});for(let[e,t]of r)o+=` ${e}="${S(t)}"`;return`${e.slice(0,i.start)}<${i.name}${o}${i.selfClosing?"/":""}>${e.slice(i.end)}`}(e,{width:"100%",height:"100%",...void 0===_(i,"viewBox")?{viewBox:`0 0 ${t.width} ${t.height}`}:{},...void 0===_(i,"preserveAspectRatio")?{preserveAspectRatio:"xMidYMid meet"}:{}}):e}function $(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function T(e,t={}){let i=t.mobileSemantics?.interaction,r="number"==typeof i?.targetSize?i.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,o="mobile"===t.mode||"number"==typeof t.width&&480>=t.width,a=!!i||void 0!==r,n=e&&"object"==typeof e?e:void 0;if(!1===e||!1===n?.enabled||void 0===e&&!o&&!a)return ud;let l=n??{};return{enabled:!0,tapToSelect:l.tapToSelect??!0,tapToLockTooltip:l.tapToLockTooltip??!0,clearSelection:l.clearSelection??"backgroundTap",targetSize:l.targetSize??r??44,snap:l.snap??"nearestDatum",brushHandleSize:l.brushHandleSize??44,standardControls:l.standardControls??!1}}function R(e,t,i){if(!1!==t)return e;let r={...e};return"horizontal"===i?r.left=Math.min(r.left,15):r.bottom=Math.min(r.bottom,15),r}function C(e){return e instanceof Date?"date:"+e.getTime():`${typeof e}:${e+""}`}function I(e,t,i,r){let o=e??t;return"function"==typeof o?o(i,r):i[o+""]}function D(e){return"string"==typeof e?.code&&e.code.length>0&&("warning"===e.severity||"error"===e.severity)&&"string"==typeof e.message&&e.message.length>0}function z(e,t,i){if(e.semanticDiagnostics=[],e.semanticStatus="not-assessed",e.empty)return;let r,o=function(e){return function(e){return yd.has(e)}(e)?function(e){return yd.get(e)}(e):"BumpChart"===e?hd:void 0}(t);if(o){try{let t="function"==typeof o?o(i,e):function(e){let t=new Map;(Array.isArray(e.data)?e.data:[]).forEach((i,r)=>{if(!Number.isFinite(Number(I(e.yAccessor,"y",i,r))))return;let o=C(I(e.xAccessor,"x",i,r)),a=t.get(o)??new Set;a.add(I(e.lineBy,"series",i,r)+""),t.set(o,a)});let i=Array.from(t.values(),e=>e.size).sort((e,t)=>e-t);if(0===i.length)return[];let r=Math.floor(i.length/2),o={columns:i.length,median:i.length%2?i[r]:(i[r-1]+i[r])/2,max:i[i.length-1],contestedColumns:i.filter(e=>e>=2).length},a=2>o.max;return a||2>o.contestedColumns||2>o.median?[{code:a?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:a?"error":"warning",message:a?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...o}}]:[]}(i);r=Array.from(t).filter(D)}catch{return void(e.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||e.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}e.semanticDiagnostics=r,e.semanticStatus=r.some(e=>"error"===e.severity)?"degenerate":r.some(e=>"warning"===e.severity)?"degraded":"meaningful";for(let t of r)e.warnings.includes(t.code)||e.warnings.push(t.code)}}function O(e,t,i){let r="function"==typeof t?t(e):e[(t??i)+""];if(null==r||"string"==typeof r&&""===r.trim())return null;let o=Number(r);return Number.isFinite(o)?o:null}function F(e){if(!e)return xd;let t=!1;for(let i=0;e.length>i;i++){let r=e[i];if(null==r||"object"!=typeof r){t=!0;break}}if(!t)return e;let i=[];for(let t of e)null!=t&&"object"==typeof t&&i.push(t);return i}function N(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function E(e,t,i){let r=e=>e.toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function W(e){let t=e.map(N),i=t.length-1;return e=>{if(Number.isNaN(e)&&(e=0),0>=e){let[e,i,r]=t[0];return E(e,i,r)}if(e>=1){let[e,r,o]=t[i];return E(e,r,o)}let r=e*i,o=Math.floor(r),a=r-o,[n,l,s]=t[o],[c,u,d]=t[o+1];return E(Math.round(n+(c-n)*a),Math.round(l+(u-l)*a),Math.round(s+(d-s)*a))}}function j(e){return e&&Object.prototype.hasOwnProperty.call(Id,e)?Id[e]:wd}function B(e,t,i=Bd){if(e&&"object"==typeof e&&!Array.isArray(e)){let t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){let t=Object.prototype.hasOwnProperty.call(jd,e)?jd[e]:void 0;if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:i}function Y(e,t,i){if("function"==typeof t){let r=t(e);return i&&r&&"string"==typeof r&&!function(e){let t=e.toLowerCase();return t.startsWith("#")||t.startsWith("rgb")||t.startsWith("hsl")||Vd.has(t)}(r)?i(r):r}let r=e?.[t]+"";return i?i(r):Bd[Math.abs(function(e){let t=0;for(let i=0;e.length>i;i++)t=(t<<5)-t+e.charCodeAt(i),t&=t;return Math.abs(t)}(r))%Bd.length]}function X(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;let i=e[t];return"string"==typeof i&&i.length>0?i:void 0}function G(e,t,i="category10"){if(i&&"object"==typeof i&&!Array.isArray(i)){let e=i;return t=>X(e,t)??"#999"}let r=Array.from(new Set(e.map(e=>e?.[t]).filter(e=>null!=e).map(e=>e+""))),o=r.every(e=>!isNaN(Number(e)));if(Array.isArray(i))return bd().domain(r).range(i).unknown("#999");let a=Object.prototype.hasOwnProperty.call(jd,i)?jd[i]:jd.category10;if(o&&"function"==typeof a){let e=-1/0;for(let t of r){let i=Number(t);i>e&&(e=i)}return t=>a(0===e?0:Number(t)/e)}{let e=Array.isArray(a)?a:Bd;return bd().domain(r).range(e).unknown("#999")}}function V(e,t,i=[3,20],r){let o;if(o="function"==typeof t?t(e):e?.[t],!r)return o;let[a,n]=r,[l,s]=i;if(n===a)return(l+s)/2;let c=(o-a)/(n-a);return 0>c?c=0:c>1&&(c=1),l+c*(s-l)}function H(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}function q(e,t){if(!H(t))return e??((...e)=>({}));let i={};return void 0!==t.stroke&&(i.stroke=t.stroke),void 0!==t.strokeWidth&&(i.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(i.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...i}):(...e)=>({...i})}function U(e){let{lineWidth:t=2,colorBy:i,colorScale:r,color:o,resolveStroke:a,fillArea:n,areaOpacity:l=.3,styleRules:s,ruleContext:c}=e;return(e,u)=>{let d,h={strokeWidth:t},f=!0===n||Array.isArray(n)&&null!=u&&n.includes(u);return a?d=a(e,u):i?r&&(d=Y(e,i,r)):d=o||Yd,void 0!==d&&(h.stroke=d,f&&(h.fill=d,h.fillOpacity=l)),s?.length&&Object.assign(h,fu(e,s,c?c(e,u):{value:void 0,category:u})),h}}function Z(e){if("A"===e.__diffWinner||"B"===e.__diffWinner)return e.__diffWinner;let t=(e.__diffSegment??"")+"";return"line-A"===t||t.endsWith("-A")?"A":"B"}function K(e,t){return cu(e,t,e=>{let t=Number(e.__x),i=Number(e.__y);return{value:Number.isFinite(i)?i:void 0,x:Number.isFinite(t)?t:void 0,y:Number.isFinite(i)?i:void 0,category:Z(e)}},e=>e.__sourceDatum?{...e.__sourceDatum,...e}:e)}function Q(e){let{seriesAColor:t,seriesBColor:i,areaOpacity:r,styleRules:o}=e;return K(e=>({fill:"A"===Z(e)?t:i,stroke:"none",fillOpacity:r}),o)}function J(e){let{seriesAColor:t,seriesBColor:i,lineWidth:r,styleRules:o}=e;return K(e=>({stroke:"A"===Z(e)?t:i,strokeWidth:r,fill:"none"}),o)}function ee(e,t=Hd){if(e)return!0===e?t:"stops"in e?Array.isArray(e.stops)?e:void 0:"colorStops"in e?Array.isArray(e.colorStops)?{stops:e.colorStops.map(({offset:e,color:t})=>({offset:e,color:t}))}:void 0:{stops:[{offset:0,opacity:e.topOpacity??t.stops[0]?.opacity??.8},{offset:1,opacity:e.bottomOpacity??t.stops.at(-1)?.opacity??.05}]}}function te(e){return e?ee(e):void 0}function ie(e,t,i){return"function"==typeof e?e(i):i[e||t]}function re(e){return e instanceof Date?e.getTime():Number(e)}function oe(e,t){return Pd(1===t?.5:e/(t-1))}function ae(e){let t={};return void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.strokeWidth&&(t.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(t.opacity=e.opacity),t}function ne(e,t){let i=function(e){if(!e)return;let t="boolean"==typeof e?{}:"string"==typeof e?{method:e}:e;return{type:"trend",method:t.method??"linear",...null!=t.bandwidth&&{bandwidth:t.bandwidth},...null!=t.order&&{order:t.order},...null!=t.color&&{color:t.color},...null!=t.strokeWidth&&{strokeWidth:t.strokeWidth},...null!=t.strokeDasharray&&{strokeDasharray:t.strokeDasharray},...null!=t.label&&{label:t.label}}}(t),r=Array.isArray(e)?e:void 0;return i?[i,...r??[]]:r}function le(e){if(!e)return ou;if("string"==typeof e)return"light"===e?ou:"dark"===e?iu:"high-contrast"===e?ru:nu(e)||ou;let t="dark"===e.mode?iu:ou,i={...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}};return au(i)}function se(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,legendFontFamily:e.typography.legendFontFamily??e.typography.fontFamily,legendFontWeight:e.typography.legendFontWeight,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,titleFontFamily:e.typography.titleFontFamily??e.typography.fontFamily,titleFontWeight:e.typography.titleFontWeight??"bold",tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}function ce(e){return e.axes??[{orient:"bottom",visible:!1!==e.showTimeAxis},{orient:"left",visible:!1!==e.showValueAxis}]}function ue(e){return Math.round(100*e)/100}function de(e,t=2){let i=[],r=[],o=t+1;for(let t=0;o>t;t++){let a=0;for(let[i,r]of e)null!==r&&(a+=i**t*r);i.push(a);let n=[];for(let i=0;o>i;i++){let r=0;for(let[o,a]of e)null!==a&&(r+=o**(t+i));n.push(r)}r.push(n)}r.push(i);let a=function(e,t){let i=e,r=e.length-1,o=[t];for(let e=0;r>e;e++){let t=e;for(let o=e+1;r>o;o++)Math.abs(i[e][o])>Math.abs(i[e][t])&&(t=o);for(let o=e;r+1>o;o++){let r=i[o][e];i[o][e]=i[o][t],i[o][t]=r}for(let t=e+1;r>t;t++)for(let o=r;o>=e;o--)i[o][t]-=i[o][e]*i[e][t]/i[e][e]}for(let e=r-1;e>=0;e--){let t=0;for(let a=e+1;r>a;a++)t+=i[a][e]*o[a];o[e]=(i[r][e]-t)/i[e][e]}return o}(r,o).map(ue);return{points:e.map(([e])=>[ue(e),ue(a.reduce((t,i,r)=>t+i*e**r,0))]),equation:[...a].reverse()}}function he(e){let t=e.length,i=0,r=0,o=0,a=0;for(let[t,n]of e)i+=t,r+=n,o+=t*t,a+=t*n;let n=t*o-i*i;if(1e-12>Math.abs(n))return null;let l=(t*a-i*r)/n,s=(r-l*i)/t;return e=>s+l*e}function fe(e,t){let i=e.length,r=e.map(([e,i])=>i-t(e)).reduce((e,t)=>e+t*t,0),o=Math.sqrt(r/Math.max(i-2,1)),a=e.reduce((e,t)=>e+t[0],0)/i,n=e.reduce((e,t)=>e+(t[0]-a)**2,0);return{se:o,meanX:a,ssX:n}}function pe(e){return.99>e?.95>e?.9>e?1:1.645:1.96:2.576}function ye(e,t,i,r){let o=t.uncertaintyOpacity,a=t.confidenceAccessor;if(!o&&!a)return;let n="object"==typeof o?o:{},l=n.min??.15,s=n.max??1;if(a){let t="function"==typeof a?a:e=>e[a];for(let i of e){let e=t(i);null!=e&&Number.isFinite(e)&&(i[Ud]=l+Math.max(0,Math.min(1,e))*(s-l))}return}let c=e.map(e=>{let t=i(e),o=r(e);return null!=t&&null!=o&&Number.isFinite(t)&&Number.isFinite(o)?Math.abs(t-o):NaN}),u=c.filter(e=>Number.isFinite(e));if(0===u.length)return;let[d,h]=nd(u),f=h-d;e.forEach((e,t)=>{let i=c[t];Number.isFinite(i)&&(e[Ud]=s-(f>0?(i-d)/f:0)*(s-l))})}function ge(e,t){return"function"==typeof t?t(e):!!e[t]}function me(e,t,i){let r=e[t],o=e[i];return null==r||null==o||Number.isNaN(r)||Number.isNaN(o)}function xe(e){let t=e.xAccessor||"x",i=e.yAccessor||"y",r=e.lineBy,o=e.colorBy||r,a=Array.isArray(e.data)?F(e.data).filter(e=>!!e&&"object"==typeof e):[],n=function(e,t,i){let r="function"==typeof t,o="function"==typeof i,a=r?Zd:t,n=o?Kd:i;return r||o?{xKey:a,yKey:n,rows:e.map(e=>{let a={...e};return r&&(a[Zd]=t(e)),o&&(a[Kd]=i(e)),a})}:{rows:e,xKey:a,yKey:n}}(a,t,i);a=n.rows;let l,s=n.xKey,c=n.yKey,u=Array.isArray(e.annotations)?[...e.annotations]:[],d="string"==typeof r||"function"==typeof r?r:void 0,h=e.baseLineStyle;if(e.forecast){let t=function(e,t,i,r,o){return(a=r).isTraining||a.isForecast||a.isAnomaly||a.upperBounds||a.lowerBounds?function(e,t,i,r,o){let{isTraining:a,isForecast:n,isAnomaly:l,upperBounds:s,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=r,y=e.map(e=>{let t="observed";return n&&ge(e,n)?t="forecast":a&&ge(e,a)&&(t="training"),{...e,[qd]:t}}),g=r._groupBy,m=[];if(g){let e=new Map;for(let t of y){let i=t[g]??"__default";e.has(i)||e.set(i,[]),e.get(i).push(t)}let t=[];for(let[,i]of e)for(let e=0;i.length-1>e;e++)i[e][qd]!==i[e+1][qd]&&(t.push({...i[e+1],[qd]:i[e][qd]}),t.push({...i[e],[qd]:i[e+1][qd]}));m.push(...y,...t)}else for(let e=0;y.length>e;e++)m.push(y[e]),y.length-1>e&&y[e][qd]!==y[e+1][qd]&&(m.push({...y[e+1],[qd]:y[e][qd]}),m.push({...y[e],[qd]:y[e+1][qd]}));if(r.trainUnderline){let e=[];for(let t of m)"training"===t[qd]&&e.push({...t,[qd]:"training-base"});m.unshift(...e)}let x=[];if(s&&c){let e="string"==typeof s?s:"__envUpper",t="string"==typeof c?c:"__envLower";if("function"==typeof s||"function"==typeof c)for(let i of m)"function"==typeof s&&(i[e]=s(i)),"function"==typeof c&&(i[t]=c(i));x.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:p})}if(r.uncertaintyOpacity||r.confidenceAccessor){let e=s?"function"==typeof s?s:e=>e[s]:()=>{},t=c?"function"==typeof c?c:e=>e[c]:()=>{};ye(m.filter(e=>"forecast"===e[qd]),r,e,t)}if(l){let e=r.anomalyStyle,t={type:"highlight",filter:e=>ge(e,l)};e?(t.style=e,t.r=f):"function"==typeof h?(t.style=e=>{let t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=f):(t.color=h,t.r=f,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),x.push(t)}return o&&x.push({type:"anomaly-band",threshold:o.threshold??2,showBand:!1!==o.showBand,fill:o.bandColor||"#6366f1",fillOpacity:o.bandOpacity??.1,anomalyColor:o.anomalyColor||"#ef4444",anomalyRadius:o.anomalyRadius??6,label:o.label}),{processedData:m,annotations:x}}(e,0,0,r,o):function(e,t,i,r,o){let{trainEnd:a,steps:n=10,confidence:l=.95,color:s="#6366f1",bandOpacity:c=.15,label:u}=r;if(null==a)return{processedData:e,annotations:[]};let d=[],h=[];for(let i of e)i[t]>a?h.push({...i,[qd]:"observed"}):d.push({...i,[qd]:"training"});let f=d.map(e=>[e[t],e[i]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]),p=[],y=[];if(f.length>=3){let o=f.length,a=he(f);if(a){let{se:d,meanX:h,ssX:g}=fe(f,a),m=pe(l),x=e.map(e=>e[t]).filter(e=>null!=e&&isFinite(e)),b=od(x),v=f.length>1?(f[o-1][0]-f[0][0])/(o-1):1;for(let e=1;n>=e;e++){let r=b+e*v,n=a(r),l=d*Math.sqrt(1+1/o+(g>0?(r-h)**2/g:0))*m;y.push({[t]:r,[i]:n,[qd]:"forecast",__forecastUpper:n+l,__forecastLower:n-l})}ye(y,r,e=>e.__forecastUpper,e=>e.__forecastLower),p.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:s,fillOpacity:c,label:u})}}p.push({type:"x-threshold",x:a,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),o&&p.push({type:"anomaly-band",threshold:o.threshold??2,showBand:!1!==o.showBand,fill:o.bandColor||"#6366f1",fillOpacity:o.bandOpacity??.1,anomalyColor:o.anomalyColor||"#ef4444",anomalyRadius:o.anomalyRadius??6,label:o.label});let g=[];if(g.push(...d),d.length>0&&h.length>0&&g.push({...d[d.length-1],[qd]:"observed"}),g.push(...h),y.length>0){let e=h.length>0?h[h.length-1]:d[d.length-1];e&&g.push({...e,[qd]:"forecast"}),g.push(...y)}return{processedData:g,annotations:p}}(e,t,i,r,o);var a}(a,s,c,r&&"string"==typeof r&&"object"==typeof e.forecast?{...e.forecast,_groupBy:r}:e.forecast,e.anomaly);if(a=t.processedData,u.push(...t.annotations),l=function(e,t,i){let r=i.upperBounds,o=i.lowerBounds;if(!r&&!o)return;let a="function"==typeof r?r:"string"==typeof r?e=>e[r]:null,n="function"==typeof o?o:"string"==typeof o?e=>e[o]:null,l=1/0,s=-1/0;for(let i of e){let e=Number(i[t]);if(Number.isFinite(e)&&(l>e&&(l=e),e>s&&(s=e)),a){let e=a(i);null!=e&&Number.isFinite(e)&&(e>s&&(s=e),l>e&&(l=e))}if(n){let e=n(i);null!=e&&Number.isFinite(e)&&(l>e&&(l=e),e>s&&(s=e))}}return Number.isFinite(l)&&Number.isFinite(s)?[l,s]:void 0}(a,c,e.forecast),r&&"string"==typeof r?(a=a.map(e=>({...e,[Qd]:`${e[r]}__${e[qd]||"observed"}`})),d=Qd):d=qd,e.baseLineStyle){let t=function(e,t){let i=t.trainDasharray??"8,4",r=t.forecastDasharray??"4,4",o=t.color||"#6366f1",a=t.trainOpacity,n=t.forecastOpacity,l=t.trainStroke,s=t.trainLinecap,c=t.trainUnderline;return t=>{let u=e(t),d=t[qd];if("training"===d){let e=u.stroke;return"darken"===l?e=function(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)*(1-t)),o=Math.round(parseInt(i[2],16)*(1-t)),a=Math.round(parseInt(i[3],16)*(1-t));return`#${r.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}(u.stroke||"#666",.5):l&&(e=l),{...u,stroke:e,strokeDasharray:i,...s&&{strokeLinecap:s},...null!=a&&{strokeOpacity:a}}}if("training-base"===d){let e=u.stroke||"#666";return"lighten"===c&&(e=function(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)+(255-parseInt(i[1],16))*t),o=Math.round(parseInt(i[2],16)+(255-parseInt(i[2],16))*t),a=Math.round(parseInt(i[3],16)+(255-parseInt(i[3],16))*t);return`#${r.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}(e,.4)),{...u,stroke:e,strokeDasharray:void 0}}if("forecast"===d){let e=t[Ud]??n;return{...u,stroke:o,strokeDasharray:r,...null!=e&&{strokeOpacity:e}}}return u}}(t=>e.baseLineStyle(t),e.forecast);h=e=>t(e)}}else e.anomaly&&u.push(...(f=e.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(e.gapStrategy){if("function"==typeof d){let e=d;a=a.map(t=>({...t,__semiotic_gapGroup:e(t)})),d="__semiotic_gapGroup"}let t=function(e,t,i,r,o){let a=new Map;for(let t of e){let e=o?(t[o]??"")+"":"__single";a.has(e)||a.set(e,[]),a.get(e).push(t)}if("interpolate"===t){let e=[];for(let[,t]of a)for(let o of t)me(o,i,r)||e.push(o);return{rows:e,groupKey:o}}if("zero"===t){let e=[];for(let[,t]of a)for(let o of t)me(o,i,r)?e.push({...o,[r]:0}):e.push(o);return{rows:e,groupKey:o}}let n=[],l="_gapSegment";for(let[e,t]of a){let o=0,a=[],s=()=>{if(0===a.length)return;let t="__single"===e?"__seg"+o:`${e}__seg${o}`;for(let e of a)n.push({...e,[l]:t});a=[],o++};for(let e of t)me(e,i,r)?s():a.push(e);s()}return{rows:n,groupKey:l}}(a,e.gapStrategy,s,c,"string"==typeof d?d:void 0);a=t.rows,t.groupKey&&(d=t.groupKey)}let p;if(e.directLabel){let t=function(e,t,i,r,o,a,n,l){if(!t||!i)return{annotations:[]};let s="object"==typeof t?t:{},c=s.position||"end",u=s.fontSize||11,d="function"==typeof i?i:e=>e[i],h=new Map;for(let t of e){let e=d(t);if(null==e)continue;let i=e+"";""!==i&&(h.has(i)||h.set(i,[]),h.get(i).push(t))}let f=new Map;for(let[e,t]of h)t.sort((e,t)=>Number(e[r])-Number(t[r])),f.set(e,"end"===c?t[t.length-1]:t[0]);let p=G(Array.from(f.entries()).map(([e])=>({__lbl:e})),"__lbl",a??n),y=Array.from(f.entries()).map(([e,t])=>({type:"text",label:e,[r]:t[r],[o]:t[o],dx:"end"===c?6:-6,dy:0,color:p?Y({__lbl:e},"__lbl",p):l||Yd,fontSize:u}));y.sort((e,t)=>Number(e[o])-Number(t[o]));for(let e=1;y.length>e;e++){let t=y[e-1],i=y[e],r=Number(t[o])+t.dy;u+2>Math.abs(Number(i[o])+i.dy-r)&&(i.dy+=u+2)}let g=y.reduce((e,t)=>Math.max(e,(t.label+"").length*(.6*u)),0)+10;return{annotations:y,marginExtra:"end"===c?{right:g}:{left:g}}}(a,e.directLabel,"string"==typeof o||"function"==typeof o?o:void 0,s,c,e.colorScheme,e.themeCategorical,e.color);u.push(...t.annotations),p=t.marginExtra}return{data:a,xAccessor:"function"==typeof t?s:t,yAccessor:"function"==typeof i?c:i,groupAccessor:d,colorAccessor:o,annotations:u,lineStyle:h,yExtent:l,marginExtra:p}}function be(e,t,i,r,o){let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=le(r.theme).colors.categorical,l=i??r.colorScheme??n,s="string"==typeof t?t:"__ssrScatterColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrScatterColorBy:t(e)})):a,u=t?G(c,s,l):void 0,d=o.sizeBy,h=Array.isArray(o.sizeRange)?o.sizeRange:[3,15],f=d?a.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=f.length?nd(f):void 0,y=hu(o.xAccessor,o.yAccessor),g=o.styleRules;return e=>{let i={fill:t&&u?Y(e,t,u):"string"==typeof o.color?o.color:Yd,fillOpacity:"number"==typeof o.pointOpacity?o.pointOpacity:.8,r:d?V(e,d,h,p):"number"==typeof o.pointRadius?o.pointRadius:5};return g?.length&&Object.assign(i,fu(e,g,y(e))),void 0!==o.stroke&&(i.stroke=o.stroke),void 0!==o.strokeWidth&&(i.strokeWidth=o.strokeWidth),void 0!==o.opacity&&(i.opacity=o.opacity),i}}function ve(e,t,i,r,o){let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=le(r.theme).colors.categorical,l=i??r.colorScheme??n,s="string"==typeof t?t:"__ssrBubbleColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrBubbleColorBy:t(e)})):a,u=t?G(c,s,l):void 0,d=o.sizeBy,h=Array.isArray(o.sizeRange)?o.sizeRange:[5,40],f=d?a.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=f.length?nd(f):void 0,y=hu(o.xAccessor,o.yAccessor),g=o.styleRules;return e=>{let i={fill:t&&u?Y(e,t,u):"string"==typeof o.color?o.color:Yd,fillOpacity:"number"==typeof o.bubbleOpacity?o.bubbleOpacity:.6,r:d?V(e,d,h,p):h[0],stroke:o.bubbleStrokeColor??"white",strokeWidth:o.bubbleStrokeWidth??1};return g?.length&&Object.assign(i,fu(e,g,y(e))),void 0!==o.stroke&&(i.stroke=o.stroke),void 0!==o.strokeWidth&&(i.strokeWidth=o.strokeWidth),void 0!==o.opacity&&(i.opacity=o.opacity),i}}function we(e,t){return t?.length&&Object.defineProperty(e,lh,{configurable:!0,enumerable:!1,value:t}),e}function ke(e){return e?.[lh]}function Ae(e){return e.parentLine?we({...e.parentLine,...e},ke(e)):e}function Se(e){return we({...e[0]},e.map(Ae))}function Me(e){return!!e&&ke(e)?.[0]===e}function _e(e,t,i,r,o){if(e)return e;if(i&&"object"==typeof i&&!Array.isArray(i)){let e=X(i,r);if(e)return e}let a;if(Array.isArray(i))a=i;else if(t&&t.length>0)a=t;else if("string"==typeof i){let e=jd[i];Array.isArray(e)&&(a=e)}return a&&0!==a.length?null!=r?(o.has(r)||o.set(r,o.size),a[o.get(r)%a.length]):a[0]:Yd}function Pe(e,t,i){return"function"==typeof e?e(t,i):t[e]}function Le(e,t){if(!e?.length)return;let i=new Map(t.map((e,t)=>[C(e),t]));return e.map(e=>{let t={...e},r=r=>{if(!(r in e))return;let o=i.get(C(e[r]));void 0!==o&&(t[r]=o)};return r("x"),r("x0"),r("x1"),"string"==typeof e.type&&("x-threshold"===e.type||"x"===e.type)&&r("value"),t})}function $e(e,t,i,r,o){let a=1-o;return a*a*a*e+3*a*a*o*t+3*a*o*o*i+o*o*o*r}function Te(e,t,i,r,o){let a=1-o;return 3*a*a*(t-e)+6*a*o*(i-t)+3*o*o*(r-i)}function Re(e,t,i,r,o){let a=[],n=(e.x+t.x)/2;for(let l=0;o>=l;l++){let s,c,u,d,h=l/o;"linear"===r?(s=e.x+(t.x-e.x)*h,c=e.y+(t.y-e.y)*h,u=t.x-e.x,d=t.y-e.y):(s=$e(e.x,n,n,t.x,h),c=$e(e.y,e.y,t.y,t.y,h),u=Te(e.x,n,n,t.x,h),d=Te(e.y,e.y,t.y,t.y,h)),a.push({x:s,y:c,dx:u,dy:d,radius:e.radius+(t.radius-e.radius)*h,datumIndex:.5>h?i:i+1})}return a}function Ce(e,t={}){let i=[],r=[],o=[];if(2>e.length)return{topPath:i,bottomPath:r,datumIndices:o};let a=t.curve??"smooth",n=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;e.length-1>t;t++){let l=Re(e[t],e[t+1],t,a,n);for(let e=0===t?0:1;l.length>e;e++){let t=l[e],a=Math.hypot(t.dx,t.dy)||1,n=-t.dy/a,s=t.dx/a,c=Math.max(0,t.radius);i.push([t.x+n*c,t.y+s*c]),r.push([t.x-n*c,t.y-s*c]),o.push(t.datumIndex)}}return{topPath:i,bottomPath:r,datumIndices:o}}function Ie({datum:e,x:t,y:i,side:r,color:o,highlighted:a,labelStyle:n}){let l=id(),s=l.isActive&&!l.predicate(e),c="function"==typeof n?n(e.__bumpRaw):n;return sh("text",{className:"semiotic-bump-label",x:t+("end"===r?8:-8),y:i,dy:"0.35em",textAnchor:"end"===r?"start":"end",fill:o,fillOpacity:s?.16:1,fontWeight:a?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...c},children:e.__bumpSeries})}function De(e,t,i){let[r,o]=t,[a,n]=i;return o===r?(a+n)/2:a+(n-a)*Math.max(0,Math.min(1,(e-r)/(o-r)))}function ze(e){let t=e.__bumpXValue instanceof Date?e.__bumpXValue.getTime():Number(e.__bumpXValue);return{value:e.__bumpValue,x:Number.isFinite(t)?t:void 0,y:e.__bumpValue,category:e.__bumpSeries}}function Oe(e){let t=e.config,i=new Map;for(let t of e.data){let e=i.get(t.__bumpSeries)??[];e.push(t),i.set(t.__bumpSeries,e)}let r=t.seriesOrder.filter(e=>i.has(e)).sort((e,r)=>(i.get(e)?.[0]?.__bumpHighlighted?1:0)-(i.get(r)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(r)),o=[],a=[],n=[];for(let a of r){let r=(i.get(a)??[]).sort((e,t)=>e.x-t.x);if(2>r.length)continue;let l=r[0].__bumpHighlighted,s=(t.colorMap&&X(t.colorMap,a))??e.resolveColor(r[0].__bumpSeries,r[0]),c=t.color??(l?s:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??s),u=r.map(i=>({x:e.scales.x(i.x),y:e.scales.y(i.y),radius:t.ribbon?De(i.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),d=Ce(u,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),h={fill:c,fillOpacity:1,opacity:l?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(h,fu(r[0].__bumpRaw,t.styleRules,ze(r[0]))),t.areaStyle&&Object.assign(h,t.areaStyle(r[0].__bumpRaw)??{}),void 0!==t.stroke&&(h.stroke=t.stroke),void 0!==t.strokeWidth&&(h.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(h.opacity=t.opacity),o.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,style:h,datum:d.datumIndices.map(e=>r[e]),accessibleDatum:r.map(e=>e.__bumpRaw),accessibility:{label:a+" ranking trajectory",tableFields:r.map(e=>e.__bumpRaw)},group:a,interactive:!0}),t.showPoints&&r.forEach((e,i)=>{let r={fill:c,stroke:"none",opacity:l?1:.75};t.styleRules?.length&&Object.assign(r,fu(e.__bumpRaw,t.styleRules,ze(e))),t.pointStyle&&Object.assign(r,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(r.stroke=t.stroke),void 0!==t.strokeWidth&&(r.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(r.opacity=t.opacity),o.push({type:"point",x:u[i].x,y:u[i].y,r:r.r??t.pointRadius,style:r,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${a}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${a}:${e.x}`})});let f=!0===t.showLabels?"end":t.showLabels,p=(e,i,r)=>{let o=null==t.labelPriorityAccessor?void 0:"function"==typeof t.labelPriorityAccessor?t.labelPriorityAccessor(e.__bumpRaw):Number(e.__bumpRaw[t.labelPriorityAccessor]);n.push({id:`${a}\0${r}`,datum:e,x:u[i].x,y:u[i].y,side:r,rank:e.__bumpRank,highlighted:l,priority:Number.isFinite(o)?o:void 0,color:"string"==typeof h.fill?h.fill:c})};("start"===f||"both"===f)&&p(r[0],0,"start"),("end"===f||"both"===f||"auto"===f)&&p(r.at(-1),r.length-1,"end")}let l=function(e,t,i,r){let o=Math.max(1,Math.floor(t/18)),a="auto"===i?Number.isFinite(r)&&(r??0)>=0?Math.min(o,Math.floor(r)):o:1/0,n=e.map((e,t)=>({candidate:e,index:t})).sort((e,t)=>(t.candidate.priority??0)-(e.candidate.priority??0)||Number(t.candidate.highlighted)-Number(e.candidate.highlighted)||e.candidate.rank-t.candidate.rank||e.index-t.index),l=[];for(let{candidate:e}of n){if(l.length>=a)break;l.some(t=>t.side===e.side&&14>Math.abs(t.y-e.y))||l.push(e)}return new Set(l.map(e=>e.id))}(n,e.dimensions.plot.height,"auto"!==(!0===t.showLabels?"end":t.showLabels)||"auto",t.maxLabels);for(let e of n)l.has(e.id)&&a.push(sh(Ie,{datum:e.datum,x:e.x,y:e.y,side:e.side,color:e.color,highlighted:e.highlighted,labelStyle:t.labelStyle},e.id));return{nodes:o,overlays:a.length?sh("g",{className:"semiotic-bump-labels",children:a}):void 0,restyle:(e,t)=>{let i=function(e){let t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}(e);if(t?.isActive&&i&&!t.predicate(i))return{opacity:.14}}}}function Fe(e,t){let i=du(e),r=t.map((e,t)=>({label:e.label||"Series "+(t+1),readY:du(e.yAccessor)}));return(e,t)=>{let o=(e[dh]??t??"")+"",a=(r.find(e=>e.label===o)??r[0])?.readY(e);return{value:a,x:i(e),y:a,category:o||void 0}}}function Ne(e,t,i,r,o){let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=le(r.theme).colors.categorical,l=i??r.colorScheme??n,s="string"==typeof t?t:"__ssrAreaColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrAreaColorBy:t(e)})):a,u=t?G(c,s,l):void 0,d=!1!==o.showLine,h="number"==typeof o.lineWidth?o.lineWidth:2,f="number"==typeof o.areaOpacity?o.areaOpacity:.7,p=du(o.yAccessor),y=o.styleRules;return(e,i)=>{let r=t&&u?Y(e,t,u):"string"==typeof o.color?o.color:Yd,a={fill:r,fillOpacity:f,stroke:d?r:"none",...d&&{strokeWidth:h}};return y?.length&&Object.assign(a,fu(e,y,{value:p(e),category:i})),void 0!==o.stroke&&(a.stroke=o.stroke),void 0!==o.strokeWidth&&(a.strokeWidth=o.strokeWidth),void 0!==o.opacity&&(a.opacity=o.opacity),a}}function Ee(e,t,i,r,o){if(!o.showPoints)return;let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=le(r.theme).colors.categorical,l=i??r.colorScheme??n,s="string"==typeof t?t:"__ssrPointColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrPointColorBy:t(e)})):a,u=t?G(c,s,l):void 0,d="number"==typeof o.pointRadius?o.pointRadius:3;return e=>{let i=t&&u?Y(e,t,u):"string"==typeof o.color?o.color:Yd;return{r:d,fill:i,stroke:"none"}}}function We(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function je(e,t){if("function"==typeof e)return e;let i=e||t;return e=>e[i]}function Be(e){return Math.max(0,Math.min(1,e))}function Ye(e){let t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let i=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(i){let e=[Number(i[1]),Number(i[2]),Number(i[3])];if(e.every(Number.isFinite))return e}return null}function Xe(e,t,i){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function Ge(e,t,i){let r=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:Be(e.offset),color:e.color??i,opacity:null==e.opacity?1:Be(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===r.length)return"#999999";let o=e=>{if(1===e.opacity)return e.color;let t=Ye(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===r.length)return o(r[0]);let a=Be(t);if(r[0].offset>=a)return o(r[0]);if(a>=r[r.length-1].offset)return o(r[r.length-1]);for(let e=0;r.length-1>e;e++){let t=r[e],i=r[e+1];if(t.offset>a||a>i.offset)continue;let n=i.offset-t.offset,l=n>0?(a-t.offset)/n:0,s=Ye(t.color),c=Ye(i.color);if(!s||!c)return o(.5>l?t:i);let[u,d,h]=s,[f,p,y]=c,g=u+(f-u)*l,m=d+(p-d)*l,x=h+(y-h)*l,b=t.opacity+(i.opacity-t.opacity)*l;return 1===b?Xe(g,m,x):`rgba(${Math.round(g)},${Math.round(m)},${Math.round(x)},${b})`}return o(r[r.length-1])}function Ve(e,t,i){return null==i?`${e}-${t}`:`${e}-${t}-${i}`}function He(e=240){let t=360-e,i=180+t/2,r=i*Math.PI/180;return{sweepRad:e*Math.PI/180,gapDeg:t,startAngleDeg:i,startAngleRad:r,offsetRad:-Math.PI/2+r}}function qe(e){return ee(e)}function Ue(e,t,i,r,o,a){let n=le(r.theme).colors.categorical,l=i??r.colorScheme,s=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],c="string"==typeof t?t:"__ssrColorBy",u="function"==typeof t?s.map(e=>({...e,__ssrColorBy:t(e)})):s,d=t?G(u,c,l??n):void 0,h=_e("string"==typeof o.color?o.color:void 0,n,l,void 0,new Map),f=a??du(o.valueAccessor??"value"),p=o.styleRules,y=r.pieceStyle;return(e,i)=>{let r={fill:t&&d?Y(e,t,d):h};return p?.length&&Object.assign(r,fu(e,p,{value:f(e,i),category:i})),"function"==typeof y?Object.assign(r,y(e,i)||{}):y&&"object"==typeof y&&Object.assign(r,y),void 0!==o.stroke&&(r.stroke=o.stroke),void 0!==o.strokeWidth&&(r.strokeWidth=o.strokeWidth),void 0!==o.opacity&&(r.opacity=o.opacity),r}}function Ze(e,t,i,r,o,a="median",n=.8){let l=du(o.valueAccessor??"value"),s=Ue(e,t,i,r,o,e=>"number"==typeof e[a]?e[a]:l(e));return(e,t)=>{let i=s(e,t);return void 0===i.fillOpacity&&(i.fillOpacity=n),void 0===i.stroke&&(i.stroke=i.fill),i}}function Ke(e,t,i,r,o){return Ze(e,t,i,r,o,"median",.6)}function Qe(e,t,i,r,o){let a=Ue(e,t,i,r,o),n="number"==typeof o.dotRadius?o.dotRadius:5;return(e,t)=>({r:n,fillOpacity:.8,...a(e,t)})}function Je(e,t,i,r,o){let a=Ue(e,t,i,r,o),n=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],l=o.sizeBy,s=Array.isArray(o.sizeRange)?o.sizeRange:[3,8],c=l?n.map(e=>"function"==typeof l?l(e):Number(e[l])).filter(Number.isFinite):[],u=c.length?nd(c):void 0,d="number"==typeof o.pointRadius?o.pointRadius:4,h="number"==typeof o.pointOpacity?o.pointOpacity:.7;return(e,t)=>({r:l?V(e,l,s,u):d,fillOpacity:h,...a(e,t)})}function et(e="static"){return Kh[e]??Kh.static}function tt(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:Qh.has(e.kind)?"fatal":"warn"}function it(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function rt(){return Object.create(null)}function ot(e,t){return t>e?-1:e>t?1:0}function at(e){return e.occupants.map(e=>e.id).sort(ot).join("\0")}function nt(e,t,i=0){return e.slice(0,-1).map((r,o)=>null!=r.group&&r.group===e[o+1].group?i:t)}function lt(e,t){return e.map(e=>{let i=new Map;for(let r of e.occupants){let e=t[r.id];if(e)for(let t of e.samples){let e=i.get(t.t)??{before:0,after:0},r=t.boundaryOffset??0;i.set(t.t,{before:Math.max(e.before,t.topMass-r),after:Math.max(e.after,t.botMass+r)})}}return[...i].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function st(e,t,i){if(0===e.length)return[];let{padding:r,plotH:o,valueScale:a}=i,n=i.stackValueScale??a,l=nt(e,r,i.groupPadding??0),s=[r+e[0].peak.topPeak*n];for(let i=1;e.length>i;i++)s.push(s[i-1]+t[i-1]*n+l[i-1]);let c=s[s.length-1]+e[e.length-1].peak.botPeak*n+r;if(c>o&&c>0){let e=o/c;for(let t=0;s.length>t;t++)s[t]*=e}return s}function ct(e,t){let i=(e.boundaryOffset??0)*t,r=e.value*t;if("out"===e.kind){let o=e.sideMassBefore*t;return i+("top"===e.side?r/2-o:o-r/2)}let o=e.sideMassAfter*t;return i+("top"===e.side?r/2-o:o-r/2)}function ut(e,t,i,r,o,a){let n=a.adjacentClearance?[...a.adjacentClearance]:Eu(lt(r,i)).adjacentClearance,l=st(r,n,a),s="hug"===a.lanePlacement?function(e,t,i,r,o,a,n){let l=e.length;if(0===l)return[];let{padding:s,plotH:c,valueScale:u}=n,d=nt(e,s,n.groupPadding??0),h=o.map((e,t)=>e*u+d[t]),f=s+e[0].peak.topPeak*u,p=c-s-e[l-1].peak.botPeak*u;if(h.reduce((e,t)=>e+t,0)+1e-6>=p-f)return st(e,o,n);let y=1===l?[(f+p)/2]:[...a];for(let e=0;12>e;e++){let e=Array(l).fill(0),o=Array(l).fill(0);for(let a of i){let i=t[a.source],n=t[a.target];if(null==i||null==n||i===n)continue;let l=r[a.source]?.localAttachments.get(a.id),s=r[a.target]?.localAttachments.get(a.id);if(!l||!s)continue;let c=a.value>0&&Number.isFinite(a.value)?a.value:1,d=ct(l,u),h=ct(s,u);e[i]+=(y[n]+h-d)*c,o[i]+=c,e[n]+=(y[i]+d-h)*c,o[n]+=c}let a=y.map((t,i)=>0===o[i]?t:.45*t+e[i]/o[i]*.55),n=ju({desired:a,minGaps:h,weights:o.map(e=>Math.max(1,e)),min:f,max:p}),s=0;for(let e=0;l>e;e++)s=Math.max(s,Math.abs(n[e]-y[e]));if(y=n,.01>s)break}return y}(r,o,t,i,n,l,a):[...l];if("hug"===a.lanePlacement){let i=t=>{let i=rt();for(let r of e)i[r.id]=t[o[r.id]];return i};dt(i(s),t)>dt(i(l),t)+1e-6&&(s=[...l])}let c=rt();for(let t of e)c[t.id]=s[o[t.id]];let u=1/0,d=-1/0;for(let t of e){let e=c[t.id],r=i[t.id];!Number.isFinite(e)||!r||(u=Math.min(u,e-r.topPeak*a.valueScale),d=Math.max(d,e+r.botPeak*a.valueScale))}return{adjacentClearance:n,centerlines:c,slotCenter:s,stackCenter:l,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&a.plotH>0?Math.max(0,Math.min(1,(d-u)/a.plotH)):0}}function dt(e,t){let i=0;for(let r of t){let t=e[r.source],o=e[r.target];Number.isFinite(t)&&Number.isFinite(o)&&(i+=Math.abs(t-o)*(r.value>0?r.value:1))}return i}function ht(e,t){let i=e?.samples;if(!i||0===i.length||i[0].t>t)return{top:0,bot:0};let r=0,o=i.length-1,a=0;for(;o>=r;){let e=r+o>>>1;i[e].t>t?o=e-1:(a=e,r=e+1)}let n=i[a].boundaryOffset??0;return{top:i[a].topMass-n,bot:i[a].botMass+n}}function ft(e,t,i,r,o){let a=1-o;return a*a*a*e+3*a*a*o*t+3*a*o*o*i+o*o*o*r}function pt(e,t){let i=0,r=1;for(let o=0;28>o;o++){let o=(i+r)/2;ft(0,t,t,1,o)<e?i=o:r=o}return(i+r)/2}function yt(e,t,i){let r=t+ct(e,i),o=e.value*i/2;return[r-o,r+o]}function gt(e,t,i,r){return Math.max(0,Math.min(t,r)-Math.max(e,i))/Math.max(1e-9,t-e)}function mt(e,t,i,r,o,a,n){let{valueScale:l,domain:s,mode:c="quality"}=n,u="source"===n.ribbonLane?.85:"target"===n.ribbonLane?.15:.5,d=0;for(let n of e){let e=r[n.source],h=r[n.target];if(null==e||null==h||2>Math.abs(e-h))continue;let f=t[n.source]?.localAttachments.get(n.id),p=t[n.target]?.localAttachments.get(n.id);if(!f||!p)continue;let y=Math.max(n.startTime,s?.[0]??-1/0),g=Math.min(n.endTime,s?.[1]??1/0);if(y>=g)continue;let[m,x]=yt(f,o[n.source],l),[b,v]=yt(p,o[n.target],l),w=Math.min(e,h)+1,k=Math.max(e,h)-1;for(let e=w;k>=e;e++){let r=i[e];if(!r)continue;let s=[y,g];if("quality"===c)for(let e of r.occupants)for(let i of t[e.id]?.samples??[])i.t>y&&g>i.t&&s.push(i.t);let h=e=>{let i=pt((e-y)/(g-y),u),s=ft(m,m,b,b,i),c=ft(x,x,v,v,i),d=0;for(let i of r.occupants){if(i.id===n.source||i.id===n.target)continue;let r=a[i.id];if(null!=r?.start&&r.start>e||null!=r?.end&&e>r.end)continue;let u=ht(t[i.id],e),h=o[i.id];d=Math.max(d,gt(s,c,h-u.top*l,h+u.bot*l))}return d},f=[...new Set(s)].sort((e,t)=>e-t),p=0;for(let e=0;f.length-1>e;e++){let t=f[e],i=f[e+1]-t;p+=(h(t+.25*i)+h(t+.5*i)+h(t+.75*i))/3*i}d+=p/(g-y)*(n.value>0?n.value:1)}}return d}function xt(e,t,i,r,o,a,n,l,s,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:dt(n,i),transitOcclusion:mt(i,r,o,a,n,l,{valueScale:s,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function bt(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function vt(e,t){return e.map(e=>({t:bt(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function wt(e,t,i){let r=t+(e.boundaryOffset??0)*i,o=e.value*i;if("out"===e.kind){let t=e.sideMassBefore*i;if("top"===e.side){let e=r-t;return[e,e+o]}let a=r+t;return[a-o,a]}let a=e.sideMassAfter*i;if("top"===e.side){let e=r-a;return[e,e+o]}let n=r+a;return[n-o,n]}function kt(e,t,i,r,o="temporal"){let a=t.incoming[e.id],n=t.outgoing[e.id],l=[];for(let e of a)l.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:i.get(e.id).targetSide});for(let e of n)l.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:i.get(e.id).sourceSide});let s={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{l.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(s[e.kind]??99)-(s[t.kind]??99)||((e,t)=>{if(!r||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;let i=r.get(e.edge.id)?.target,o=r.get(t.edge.id)?.target;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof o&&Number.isFinite(o)&&i!==o?"top"===e.side?i-o:o-i:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;let i=r.get(e.edge.id)?.source,o=r.get(t.edge.id)?.source;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof o&&Number.isFinite(o)&&i!==o?"top"===e.side?o-i:i-o:0}return 0})(e,t)||ot(e.edge?.id??"",t.edge?.id??"")||ot(e.side,t.side)||e.delta-t.delta)},u=l.length?ad(l.map(e=>e.time)):null,d=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,h=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let f=null,p=0;for(let e of l)e.time!==f&&(f=e.time,p=0),e.sequence=p++;let y=e=>({time:e.time,phase:0,sequence:e.sequence??0}),g=[],m=0,x=0;for(let e of l)if("out"===e.kind){let t=Math.abs(e.delta),i=t-("top"===e.side?m:x);if(i>0){let t="top"===e.side?"bot":"top",r=Math.min(i,"top"===t?m:x);if(r>0){let o=y(e);g.push({...o,delta:-r,kind:"transfer-out",side:t}),g.push({...o,delta:+r,kind:"transfer-in",side:e.side}),"top"===t?m-=r:x-=r,"top"===e.side?m+=r:x+=r,i-=r}i>0&&null!==h&&(g.push({time:h,delta:+i,kind:"create",side:e.side}),"top"===e.side?m+=i:x+=i)}"top"===e.side?m-=t:x-=t}else if("in"===e.kind){let t=Math.abs(e.delta);"top"===e.side?m+=t:x+=t}l.push(...g),c();let b=0,v=0,w=0,k=0,A=0,S=0,M=[],_=new Map,P=e=>{M.push({t:e,topMass:b,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},L=()=>{k=Math.max(k,b+v),A=Math.max(A,b-w),S=Math.max(S,v+w)};for(let e of l){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&P(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){let t="top"===e.side?b:v;_.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:t+e.delta,kind:e.kind,value:Math.abs(e.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===e.side?b+=e.delta:v+=e.delta,"transfer-in"===e.kind?(w+="top"===e.side?e.delta:-e.delta,L(),P(e.time)):"transfer-out"!==e.kind&&(L(),"out"===e.kind&&1e-12>=b+v&&(w=0),P(e.time))}let $=[],T=0;for(;M.length>T;){let e=T;for(;M.length>e+1&&M[e+1].t===M[T].t;)e++;$.push(M[T]);for(let t=T+1;e>=t;t++){let e=$[$.length-1];(M[t].topMass!==e.topMass||M[t].botMass!==e.botMass||(M[t].boundaryOffset??0)!==(e.boundaryOffset??0))&&$.push(M[t])}T=e+1}let R=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null,C=null;for(let e of n)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime&&(null===C||C>e.systemInTime)&&(C=e.systemInTime);let I=null;for(let e of a)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===I||e.systemOutTime>I)&&(I=e.systemOutTime);if($.length>0){let e=$[$.length-1],t=Math.max(R??-1/0,I??-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&$.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});let i,r=$[0],o=$.find(e=>e.topMass+e.botMass>0),a=1/0;null!=d&&Number.isFinite(d)&&r.t>d&&r.topMass+r.botMass>0&&(a=d,i=r),o&&null!=C&&Number.isFinite(C)&&o.t>C&&a>C&&(a=C,i=o),i&&Number.isFinite(a)&&$.unshift({t:a,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let D=$;if("max"===o&&null!=d&&null!=R&&R>d){let e,t=0;for(let i of $){let r=i.topMass+i.botMass;r>t&&(t=r,e=i)}if(e){let t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};D=[...$.filter(e=>d>e.t),{t:d,...t},{t:R,...t},...$.filter(e=>e.t>R)]}}return{samples:D,peak:k,topPeak:A,botPeak:S,localAttachments:_}}function At(e){let t=rt();return e.forEach((e,i)=>{for(let r of e.occupants)t[r.id]=i}),t}function St(e,t,i){e.splice(0,e.length,...i);let r=At(i);for(let e of Object.keys(t))delete t[e];Object.assign(t,r)}function Mt(e){let t=new Map,i=[];e.forEach((e,r)=>{if(!e.group)return void i.push({anchor:r,stableId:at(e),slots:[e]});let o=t.get(e.group)??{indexes:[],slots:[]};o.indexes.push(r),o.slots.push(e),t.set(e.group,o)});for(let[e,r]of t)i.push({anchor:r.indexes.reduce((e,t)=>e+t,0)/r.indexes.length,stableId:`${e}\0${r.slots.map(at).join("\0")}`,slots:r.slots});return i.sort((e,t)=>e.anchor-t.anchor||ot(e.stableId,t.stableId))}function _t(e){return e.some(e=>e.group)?Mt(e).flatMap(e=>e.slots):[...e]}function Pt(e){return e.flatMap(e=>e.slots)}function Lt(e,t,i){let r=new Map;return e.forEach((e,t)=>{for(let i of e.slots)r.set(i,t)}),e.map((e,o)=>{if(1>=e.slots.length)return e;let a=new Map;for(let t of e.slots)a.set(t,0);for(let e of t){let t=r.get(e.source),i=r.get(e.target);if(null==t||null==i)continue;let n=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===o&&i!==o){let t=i>o?1:-1;a.set(e.source,(a.get(e.source)??0)+n*t)}else if(i===o&&t!==o){let i=t>o?1:-1;a.set(e.target,(a.get(e.target)??0)+n*i)}}let n=[...e.slots].sort((e,t)=>(a.get(e)??0)-(a.get(t)??0)||i(e,t));return{...e,slots:n}})}function $t(e,t){e.some(e=>e.group)&&St(e,t,_t(e))}function Tt(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.min(e.endTime,t.endTime)>Math.max(e.startTime,t.startTime)}function Rt(e,t){return _u(t,t=>[e[t.source],e[t.target]],Tt)}function Ct(e,t){let i=0;for(let r of t){let t=e[r.source],o=e[r.target];null==t||null==o||(i+=Math.abs(t-o)*(r.value>0?r.value:1))}return i}function It(e,t,i){let[r,o]=i.get(e.first),[a,n]=i.get(e.second);return 0>(t.get(r)-t.get(a))*(t.get(o)-t.get(n))?1:0}function Dt(e,t,i,r,o,a,n){let l=[...o],s=new Map(o.map(e=>[e,at(e)])),c=new Map;for(let e of o)for(let t of e.occupants)c.set(t.id,e);let u=new Map,d=[];for(let e of t){let t=c.get(e.source),i=c.get(e.target);!t||!i||(u.set(e,[t,i]),t!==i&&d.push({source:t,target:i,weight:e.value}))}let h=[];for(let e=0;t.length>e;e++)if(u.has(t[e]))for(let i=e+1;t.length>i;i++){if(!u.has(t[i])||!Tt(t[e],t[i]))continue;let r=new Set([...u.get(t[e]),...u.get(t[i])]);h.push({index:h.length,first:t[e],second:t[i],involvedSlots:r})}let f=new Map;for(let e of o)f.set(e,[]);for(let e of h)for(let t of e.involvedSlots)f.get(t)?.push(e);let p=new Uint32Array(h.length),y=0,g=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),m=n.plotH/Math.max(1,o.length),x=o.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),b=Math.max(1,g)*(Math.max(1,n.plotH)+m*Math.max(x,o.length)+1e-6*Math.max(1,o.length-1))+1,v=4*m,w={fullCrossing:0,localCrossing:0},k=new Map,A=(e,t)=>{let r=k.get(e);r||(r=new Map,k.set(e,r));let o=r.get(t);if(null!=o)return o;let a=function(e,t,i){return Eu(lt([e,t],i)).adjacentClearance[0]??0}(e,t,i);return r.set(t,a),a},S=new Map(o.map((e,t)=>[e,t])),M=t.flatMap(e=>{let t=u.get(e);return t?[{source:S.get(t[0]),target:S.get(t[1]),weight:e.value>0?e.value:1}]:[]}),_=new Map;for(let e of t){let t=u.get(e);t&&_.set(e,{source:S.get(t[0]),target:S.get(t[1])})}let P=new Map,L=new Map,$=new Map,T=(e,t,i)=>{e.has(t)||e.set(t,new Set),e.get(t).add(i)};for(let e of t)T(P,e.source,e.target),T(L,e.target,e.source),T($,e.source,e.target),T($,e.target,e.source);let R=t.flatMap(e=>{if(!(e=>1===P.get(e.source)?.size&&P.get(e.source).has(e.target)||1===$.get(e.source)?.size||1===$.get(e.target)?.size)(e))return[];let t=_.get(e);return t&&t.source!==t.target?[{source:t.source,target:t.target,weight:e.value>0?e.value:1}]:[]}),C=e=>{let t=0;for(let i of R)t+=Math.max(0,Math.abs(e[i.source]-e[i.target])-1)*i.weight;return t*v},I=e=>{let t=new Int16Array(o.length);for(let i=0;e.length>i;i++)t[S.get(e[i])]=i;return C(t)},D=h.map(e=>{let t=_.get(e.first),i=_.get(e.second);return[t.source,t.target,i.source,i.target]}),z=new Int16Array(o.length),O=new Float64Array(o.length),F=new Float64Array(o.length+1),N=e=>{for(let t=0;e.length>t;t++)z[S.get(e[t])]=t;let t=0;for(let[e,i,r,o]of D)0>(z[e]-z[r])*(z[i]-z[o])&&t++;if(e.length>0){let t=S.get(e[0]);O[t]=n.padding+e[0].peak.topPeak*n.valueScale;for(let t=1;e.length>t;t++){let i=S.get(e[t-1]),r=S.get(e[t]);O[r]=O[i]+A(e[t-1],e[t])*n.valueScale+n.padding}let i=S.get(e[e.length-1]),r=O[i]+e[e.length-1].peak.botPeak*n.valueScale+n.padding;if(r>n.plotH&&r>0){let e=n.plotH/r;for(let t=0;O.length>t;t++)O[t]*=e}}F[0]=0;for(let t=0;e.length>t;t++)F[t+1]=F[t]+e[t].peak.topPeak+e[t].peak.botPeak;let i=0,r=0,o=0;for(let e of M){let t=z[e.source],a=z[e.target];if(i+=Math.abs(t-a)*e.weight,r+=Math.abs(O[e.source]-O[e.target])*e.weight,Math.abs(t-a)>=2){let i=Math.min(t,a)+1;o+=(F[Math.max(t,a)]-F[i])*e.weight}}return t*b+r+o*m+C(z)+1e-6*i},E=(e,i)=>{let r=Array(e.length+1).fill(0);for(let t=0;e.length>t;t++)r[t+1]=r[t]+e[t].peak.topPeak+e[t].peak.botPeak;let o=0;for(let e of t){let t=i[e.source],a=i[e.target];if(null==t||null==a||2>Math.abs(t-a))continue;let n=Math.min(t,a)+1;o+=(r[Math.max(t,a)]-r[n])*(e.value>0?e.value:1)}return o},W=r=>{let o=At(r),a=r.slice(0,-1).map((e,t)=>A(e,r[t+1])),l=ut(e,t,i,r,o,{plotH:n.plotH,padding:n.padding,valueScale:n.valueScale,lanePlacement:n.lanePlacement??"stack",groupPadding:n.groupPadding,adjacentClearance:a});return{map:o,geometry:l,weightedLength:Ct(o,t),pixelLength:dt(l.centerlines,t),transitOcclusion:E(r,o)}},j=(e,t,i)=>({crossings:e,weightedLength:t.weightedLength,pixelLength:t.pixelLength,transitOcclusion:t.transitOcclusion,cost:e*b+t.pixelLength+t.transitOcclusion*m+I(i)+1e-6*t.weightedLength}),B=(e,t)=>{let i=t;if(null==i){let t=new Map(e.map((e,t)=>[e,t]));i=h.reduce((e,i)=>e+It(i,t,u),0),w.fullCrossing++}return j(i,W(e),e)},Y=(e,o,a="quality")=>{let l=o;if(null==l){let t=new Map(e.map((e,t)=>[e,t]));l=h.reduce((e,i)=>e+It(i,t,u),0),w.fullCrossing++}let s=W(e);return j(l,{...s,transitOcclusion:mt(t,i,e,s.map,s.geometry.centerlines,r,{valueScale:n.valueScale,ribbonLane:n.ribbonLane,domain:n.domain,mode:a})},e)},X=[...l],G=(e,t)=>ot(s.get(e),s.get(t)),V=function(e){let t=new Set;for(let i of e)if(i.group){if(t.has(i.group))return!0;t.add(i.group)}return!1}(X),H=e=>{let t=(e=>{let t=Fu(e,d,e=>B(e).cost,{passes:6,compare:G,maxEvaluations:tf}),i=B(t),r=tf;for(let e=0;6>e&&r>0;e++){let o=!1,a=Array.from({length:t.length-1},(e,t)=>t);e%2==1&&a.reverse();for(let e of a){if(0>=r--)break;let a=t[e],n=t[e+1],l=new Map(t.map((e,t)=>[e,t])),s=0,c=[];y++;for(let e of[...f.get(a)??[],...f.get(n)??[]])p[e.index]!==y&&(p[e.index]=y,c.push(e),s+=It(e,l,u));[t[e],t[e+1]]=[n,a];let d=new Map(l);d.set(a,e+1),d.set(n,e);let h=0;for(let e of c)h+=It(e,d,u);w.localCrossing+=c.length;let g=B(t,i.crossings-s+h);i.cost>g.cost?(i=g,o=!0):[t[e],t[e+1]]=[a,n]}if(!o)break}return t})(e);if((e.length>8?1/0:Jh(e.length)*(e.length+M.length+D.length))>ef)return t;let i=Nu(e,N,{maxItems:8,maxEvaluations:5e4}),r=Y(i),o=Y(t);return r.crossings!==o.crossings&&o.crossings>r.crossings?i:t},q="geometry-refine"===n.mode;if(q||"crossing-min"!==n.laneOrder&&"crossing-min+inside-out"!==n.laneOrder){if(!q&&"inside-out"===n.laneOrder)if(V){let e=Mt(X),t=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),i=[...e].sort((e,i)=>t(i)-t(e)||ot(e.stableId,i.stableId)),r=Array(i.length),o=Math.floor((i.length-1)/2)-1,a=Math.floor((i.length-1)/2)+1;i.length>0&&(r[Math.floor((i.length-1)/2)]=i[0]);for(let e=1;i.length>e;e++)e%2==1&&i.length>a||0>o?r[a++]=i[e]:r[o--]=i[e];X=Pt(r)}else{let e=[...X].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||G(e,t)),t=Array(e.length),i=Math.floor((e.length-1)/2)-1,r=Math.floor((e.length-1)/2)+1;e.length>0&&(t[Math.floor((e.length-1)/2)]=e[0]);for(let o=1;e.length>o;o++)o%2==1&&e.length>r||0>i?t[r++]=e[o]:t[i--]=e[o];X=t}}else X=V?(e=>{let t=Mt(e);if(1>=t.length)return Pt(t);let i=e=>B(Pt(e)).cost;t=Mt(H(e)),t=Lt(t,d,G);let r=function(e,t){let i=new Map;for(let t of e)for(let e of t.slots)i.set(e,t);let r=new Map;for(let e of t){let t=i.get(e.source),o=i.get(e.target);if(!t||!o||t===o)continue;let a=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,n=o.stableId>t.stableId?`${t.stableId}\0${o.stableId}`:`${o.stableId}\0${t.stableId}`,l=r.get(n);l?l.weight=(l.weight??0)+a:r.set(n,{source:t,target:o,weight:a})}return[...r.values()]}(t,d);if(t=Fu(t,r,i,{passes:6,compare:(e,t)=>ot(e.stableId,t.stableId),maxEvaluations:tf}),t=Hu(t,i,{passes:8,maxEvaluations:tf}),(t.length>8?1/0:Jh(t.length)*(t.length+M.length+D.length))<=ef){let e=Nu(t,e=>N(Pt(e)),{maxItems:8,maxEvaluations:5e4}),i=Pt(e),r=Pt(t),o=Y(i),a=Y(r);o.crossings!==a.crossings?t=a.crossings>o.crossings?e:t:a.cost>o.cost&&(t=e)}return t=Lt(t,d,G),Pt(t)})(X):H(X);if(!q&&"crossing-min+inside-out"===n.laneOrder&&X.length>1)if(V){let e=Mt(X),t=B(Pt(e)),i=Pt(e),r=t,o=Math.floor((e.length-1)/2),a=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),n=[...e].sort((e,t)=>a(t)-a(e)||ot(e.stableId,t.stableId));for(let a of n){let n=e.indexOf(a);if(n===o)continue;e.splice(n,1),e.splice(o,0,a);let l=Pt(e),s=B(l);s.cost>t.cost?(e.splice(o,1),e.splice(n,0,a)):(t=s,r.cost>s.cost&&(i=l,r=s))}X=i}else{let e=B(X),t=[...X],i=e,r=Math.floor((X.length-1)/2),o=[...X].sort((e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||G(e,t));for(let a of o){let o=X.indexOf(a);if(o===r)continue;X.splice(o,1),X.splice(r,0,a);let n=B(X);n.cost>e.cost?(X.splice(r,1),X.splice(o,0,a)):(e=n,i.cost>n.cost&&(t=[...X],i=n))}X=t}if((q||"crossing-min"===n.laneOrder||"crossing-min+inside-out"===n.laneOrder)&&X.length>1)if(V){let e=Mt(X),t=Y(Pt(e),void 0,"score");for(let i=0;6>i&&e.length>1;i++){let i=!1;for(let r=0;e.length-1>r;r++){[e[r],e[r+1]]=[e[r+1],e[r]];let o=Pt(e),a=Y(o,void 0,"score");t.cost>a.cost?(X=o,t=a,i=!0):[e[r],e[r+1]]=[e[r+1],e[r]]}if(!i)break}e=Lt(Mt(X),d,G),X=Pt(e)}else{let e=Y(X,void 0,"score");for(let t=0;X.length-1>t;t++){let i=X[t],r=X[t+1],o=new Map(X.map((e,t)=>[e,t])),a=0,n=[];y++;for(let e of[...f.get(i)??[],...f.get(r)??[]])p[e.index]!==y&&(p[e.index]=y,n.push(e),a+=It(e,o,u));[X[t],X[t+1]]=[r,i];let l=new Map(o);l.set(i,t+1),l.set(r,t);let s=0;for(let e of n)s+=It(e,l,u);w.localCrossing+=n.length;let c=Y(X,e.crossings-a+s,"score");e.cost>c.cost?e=c:[X[t],X[t+1]]=[i,r]}}let U=_t(l);X=_t(X);let Z=Y(X),K=Y(U);if(q){let e=I(U),t=I(X);(Z.crossings>K.crossings||Z.crossings===K.crossings&&t>e+1e-9||Z.cost>K.cost)&&(X=U,Z=K)}else Z.cost>K.cost&&(X=U,Z=K);let Q=function({order:e,after:t,nodes:i,edges:r,outgoingPartners:o,incomingPartners:a,slotForNode:n,averageGap:l,evaluate:s}){let c=(i,o)=>{let a=[...new Set(o.map(t=>e.indexOf(t)))].sort((e,t)=>e-t),n=e.indexOf(i),c=a[0],u=a[a.length-1];if(3>a.length||!a.includes(n)||u-c+1!==a.length||1>=Math.abs(2*n-c-u))return;let d=[...e];d.splice(n,1),d.splice(c+u>>1,0,i);let h=_t(d),f=s(h),p=new Set(i.occupants.map(e=>e.id)),y=new Set(o.flatMap(e=>e.occupants.map(e=>e.id))),g=r.reduce((e,t)=>p.has(t.source)&&y.has(t.target)||p.has(t.target)&&y.has(t.source)?e+(t.value>0?t.value:1):e,0);(function(e,t,i=0){return t.crossings>e.crossings||e.crossings===t.crossings&&t.cost+i>=e.cost})(f,t,Math.abs(2*n-c-u)*l*Math.max(1,g))&&(e=h,t=f)};for(let[e,t]of o)!a.has(e)&&t.size>=3&&c(n.get(e),[...t].map(e=>n.get(e)));for(let e of i){let t=n.get(e.id);!e.group&&t.group&&(a.get(e.id)?.size??0)>=3&&c(t,[...a.get(e.id)??[]].map(e=>n.get(e)).filter(e=>e===t||e.group===t.group).filter((e,t,i)=>i.indexOf(e)===t))}return{order:e,after:t}}({order:X,after:Z,nodes:e,edges:t,outgoingPartners:P,incomingPartners:L,slotForNode:c,averageGap:m,evaluate:Y});return X=Q.order,Z=Q.after,St(o,a,X),{before:K,after:Z,initialOrder:l.map(e=>s.get(e)),evaluations:w}}function zt(e,t,i){let r=e.map(e=>{let r=e.occupants.map(e=>({id:e.id,end:i[e.id]?.end??e.end})),o=0,a=0;for(let e of r){let i=t[e.id];o=Math.max(o,i?.topPeak||0),a=Math.max(a,i?.botPeak||0)}return{occupants:r,peak:{topPeak:o,botPeak:a},...null!=e.group?{group:e.group}:{}}}),o=rt();return r.forEach((e,t)=>{for(let i of e.occupants)o[i.id]=t}),{slots:r,slotByNode:o}}function Ot(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(t.start>=e.end||e.start>=t.end)}function Ft(e,t){return ot(e,t)>0?`${t}\0${e}`:`${e}\0${t}`}function Nt(e){let t=new Map,i=new Map;for(let r of e)i.has(r.source)||i.set(r.source,new Set),t.has(r.target)||t.set(r.target,new Set),i.get(r.source).add(r.target),t.get(r.target).add(r.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...i].map(([e,t])=>[e,t.size]))}}function Et(e){let t=new Map,i=new Map,r=(e,t,i,r)=>{let o=e.get(t);o||(o=new Map,e.set(t,o)),o.set(i,(o.get(i)??0)+r)};for(let o of e){let e=o.value>0&&Number.isFinite(o.value)?o.value:1;r(t,o.source,o.target,e),r(i,o.target,o.source,e)}let o=new Map,a=e=>{if(o.has(e))return;let r=t.get(e),a=i.get(e),n=new Map;for(let[e,t]of r??[])n.set(e,(n.get(e)??0)+t);for(let[e,t]of a??[])n.set(e,(n.get(e)??0)+t);if(1===n.size){let[t,i]=[...n][0];o.set(e,{partner:t,weight:i})}};for(let t of e)a(t.source),a(t.target);return o}function Wt(e,t,i){let r=i.get(e),o=i.get(t);return!r||!o||r.partner===o.partner||r.partner===t||o.partner===e}function jt(e,t,i){return!!i.has(e)&&t.some(t=>!Wt(e,t,i))}function Bt(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function Yt(e,t,i,r){if(12>=e.length||1>=r.slotCount)return r.assignment;let o=new Map(e.map((e,t)=>[e,t])),a=Array.from({length:e.length},()=>new Map),n=Nt(i);for(let e of i){let t=o.get(e.source),i=o.get(e.target);if(null==t||null==i||t===i)continue;let r=Bt(e,n);a[t].set(i,(a[t].get(i)??0)+r),a[i].set(t,(a[i].get(t)??0)+r)}let l=Et(i),s=e.map(e=>l.get(e)?.weight??0),c=Array.from({length:e.length},()=>new Map),u=0;for(let i=0;e.length-1>i&&5e4>u;i++)if(l.has(e[i]))for(let r=i+1;e.length>r;r++){if(!l.has(e[r])||t.conflicts(e[i],e[r]))continue;u++;let o=Math.min(s[i],s[r])||Math.max(s[i],s[r]),a=Wt(e[i],e[r],l)?o:-o;if(Math.abs(a)>af&&(c[i].set(r,a),c[r].set(i,a),u>=5e4))break}let d=[...r.assignment],h=Array.from({length:r.slotCount},()=>[]);d.forEach((e,t)=>h[e].push(t));let f=(e,t,i)=>{let r=d[t],o=d[i],a=0,n=new Set;for(let l of[t,i])for(let[s,c]of e[l]){let e=s>l?`${l}:${s}`:`${s}:${l}`;if(n.has(e))continue;n.add(e);let u=(l===t?o:r)===(s===t?o:s===i?r:d[s]);d[l]===d[s]!==u&&(a+=u?c:-c)}return a},p=(e,t,i)=>{let r=0;for(let[o,a]of e[t]){let e=i===d[o];d[t]===d[o]!==e&&(r+=e?a:-a)}return r},y=(e,t)=>e>af||af>=Math.abs(e)&&t>af,g=(e,t,i,r)=>e>i+af||af>=Math.abs(e-i)&&t>r+af,m=0;for(let i=0;32>i&&of>m;i++){let i=null,r=-1,o=-1,n=-1,l=-1/0,s=-1/0;for(let u=0;e.length>u;u++){for(let f=0;h.length>f&&m++<of;f++){if(f===d[u]||!h[f].every(i=>!t.conflicts(e[u],e[i])))continue;let m=p(a,u,f),x=p(c,u,f);y(m,x)&&g(m,x,l,s)&&(i="move",r=u,o=-1,n=f,l=m,s=x)}if(m>=of)break}for(let u=0;e.length-1>u;u++){for(let p=u+1;e.length>p&&m++<of;p++){let m=d[u],x=d[p];if(m===x||!h[x].every(i=>i===p||!t.conflicts(e[u],e[i]))||!h[m].every(i=>i===u||!t.conflicts(e[p],e[i])))continue;let b=f(a,u,p),v=f(c,u,p);y(b,v)&&g(b,v,l,s)&&(i="swap",r=u,o=p,n=-1,l=b,s=v)}if(m>=of)break}if(null==i||-1===r)break;if("move"===i){let e=d[r];h[e].splice(h[e].indexOf(r),1),h[n].push(r),d[r]=n;continue}let u=d[r],x=d[o];h[u].splice(h[u].indexOf(r),1,o),h[x].splice(h[x].indexOf(o),1,r),d[r]=x,d[o]=u}return d}function Xt(e,t){let i=1/0,r=-1/0;for(let t of e?.samples??[])1e-9>=t.topMass+t.botMass||(i=Math.min(i,t.t),r=Math.max(r,t.t));return Number.isFinite(i)&&Number.isFinite(r)?(null!=t.start&&(i=Math.max(i,t.start)),null!=t.end&&(r=Math.min(r,t.end)),i>r?{start:null,end:null}:{start:i,end:r}):{start:null,end:null}}function Gt(e,t,i,r){let o=function(e,t,i,r){return`${e.map(e=>{let t=i[e.id],o=r[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,o?.start??"",o?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}(e,t,i,r),a=rf.get(o);if(a)return zt(a.slots,i,r);let n=rt();for(let t of e)n[t.id]=Xt(i[t.id],r[t.id]);let l=function(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,i)=>t[e.id].start-t[i.id].start||t[e.id].end-t[i.id].end||ot(e.id,i.id)).map(e=>e.id)}(e,n),s=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=Et(t),d=function(e,t,i,r,o,a){let n=new Set,l=new Map(e.map(e=>[e,new Set])),s=new Map(e.map(e=>[e,new Set]));for(let e of r)n.add(Ft(e.source,e.target)),l.get(e.target)?.add(e.source),s.get(e.source)?.add(e.target);let c=new Map,u=new Set,d=(e,t)=>{for(let i=0;e.length>i;i++)for(let r=i+1;e.length>r;r++){let o=Ft(e[i],e[r]);t instanceof Map?t.set(o,[e[i],e[r]]):t.add(o)}};for(let e of s.values())d([...e],c);for(let e of l.values())d([...e],u);let h=new Set;for(let[e,[r,o]]of c)u.has(e)&&(Ot(t[r],t[o])||Ot(i[r],i[o])&&(h.add(r),h.add(o)));return{conflicts:(e,i)=>{let r=o.get(e),l=o.get(i);return!((null==r||null==l||r===l)&&(null!=r==(null!=l)||n.has(Ft(e,i))||a.has(e)&&a.has(i)&&Wt(e,i,a))&&!Ot(t[e],t[i])&&(!h.has(e)&&!h.has(i)||n.has(Ft(e,i))))}}}(l,n,r,t,c,u),h=function(e,t,i=new Map){let r=[],o=[];for(let a of e){let e=r.findIndex(e=>e.every(e=>!t.conflicts(a,e))&&!jt(a,e,i));-1===e&&!i.has(a)&&(e=r.findIndex(e=>e.every(e=>!t.conflicts(a,e)))),-1===e&&(e=r.length,r.push([])),r[e].push(a),o.push(e)}return{assignment:o,slotCount:r.length}}(l,d,u),f=function(e,t,i,r){if(0===e.length||e.length>12||1>=r.slotCount)return r.assignment;let o=new Map(e.map((e,t)=>[e,t])),a=Array.from({length:e.length},()=>new Float64Array(e.length)),n=Array.from({length:e.length},()=>new Map),l=Array.from({length:e.length},()=>new Map),s=Nt(i);for(let e of i){let t=o.get(e.source),i=o.get(e.target);if(null==t||null==i||t===i)continue;let r=Bt(e,s);a[t][i]+=r,a[i][t]+=r,l[t].set(i,(l[t].get(i)??0)+r),n[i].set(t,(n[i].get(t)??0)+r)}let c=Et(i),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;e.length>t;t++)for(let i=t+1;e.length>i;i++){for(let[e,r]of n[t])d[t][i]+=Math.min(r,n[i].get(e)??0);for(let[e,r]of l[t])d[t][i]+=Math.min(r,l[i].get(e)??0);if(c.has(e[t])&&c.has(e[i])){let r=Math.min(u[t],u[i])||Math.max(u[t],u[i]);d[t][i]+=Wt(e[t],e[i],c)?r:-r}d[i][t]=d[t][i]}let h=[...r.assignment],f=(t=>{let i=0,r=0;for(let o=0;e.length>o;o++)for(let n=o+1;e.length>n;n++)t[o]===t[n]&&(i+=a[o][n],r+=d[o][n]);return{flow:i,affinity:r}})(h),p=0,y=Array(e.length).fill(-1),g=Array.from({length:r.slotCount},()=>[]),m=(i,o,n,l)=>{if(p>=75e3)return;if(i===e.length)return p++,void((n>f.flow||n===f.flow&&l>f.affinity||n===f.flow&&l===f.affinity&&function(e,t){for(let i=0;Math.min(e.length,t.length)>i;i++)if(e[i]!==t[i])return t[i]>e[i];return t.length>e.length}(y,h))&&(h=[...y],f={flow:n,affinity:l}));let s=Math.min(o+1,r.slotCount-1);for(let r=0;s>=r;r++){if(g[r].some(r=>t.conflicts(e[i],e[r])))continue;let s=0,c=0;for(let e of g[r])s+=a[i][e],c+=d[i][e];if(y[i]=r,g[r].push(i),m(i+1,Math.max(o,r),n+s,l+c),g[r].pop(),y[i]=-1,p>=75e3)return}};return y[0]=0,g[0].push(0),m(1,0,0,0),h}(l,d,t,{...h,assignment:Yt(l,d,t,h)}),p=new Map,y=f.map(e=>(p.has(e)||p.set(e,p.size),p.get(e))),g=Array.from({length:p.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),m=rt();l.forEach((e,t)=>{let i=y[t],r=g[i];r.occupants.push({id:e,end:n[e].end??-1/0});let o=s.get(e)?.group;o&&(r.group=o),m[e]=i});for(let t of[...e].sort((e,t)=>ot(e.id,t.id)))null==m[t.id]&&(g[0].occupants.push({id:t.id,end:-1/0}),m[t.id]=0);for(let e of g){e.occupants.sort((e,t)=>(n[e.id].start??1/0)-(n[t.id].start??1/0)||ot(e.id,t.id));for(let t of e.occupants){let r=i[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,r?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,r?.botPeak||0)}}let x={slots:g,slotByNode:m};return function(e,t){for(rf.has(e)&&rf.delete(e),rf.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:Object.assign(rt(),t.slotByNode)});rf.size>12;){let e=rf.keys().next().value;if(null==e)break;rf.delete(e)}}(o,x),x}function Vt(e){return e.topMass+e.botMass}function Ht(e){let t=new Map;for(let i of e.samples){if(Number.isNaN(i.t))continue;let e=t.get(i.t);e||(e=[],t.set(i.t,e)),e.push(i)}let i=0,r=-1/0;return o=>{o>=r||(i=0),r=o;let a=t.get(o);if(a){let e=a.reduce((e,t)=>Vt(t)<Vt(e)?e:t,a[0]);return{exact:a,sample:e}}for(;e.samples.length>i&&o>=e.samples[i].t;)i++;return{exact:a,sample:e.samples[i-1]??null}}}function qt(e,t,i,r,o,a,n=0){let l=new Map;for(let i of e){if(!i.group||!t[i.id])continue;let e=l.get(i.group)??[];e.push(i),l.set(i.group,e)}if(0===l.size||0>=a)return t;let s=Object.fromEntries(Object.entries(t).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]));for(let[e,c]of l){let l=i.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===l.length)continue;let u=l[0].slot,d=l.at(-1).slot,h=o[u.occupants[0]?.id],f=o[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;let p=(h-u.peak.topPeak*a+(f+d.peak.botPeak*a))/2,y=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),g=new Map;for(let e of c)g.set(e.id,new Map);let m=new Map(c.map(e=>[e.id,Ht(t[e.id])]));for(let e of y){let t=new Map;for(let i of c){let{sample:o}=m.get(i.id)(e);if(!o||1e-9>=Vt(o))continue;let a=r[i.id];if(null==a)continue;let n=t.get(a)??[];n.push({node:i,sample:o}),t.set(a,n)}let i=[...t].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:Math.max(...t.map(({sample:e})=>Vt(e)))}));if(0===i.length)continue;let l=p-(i.reduce((e,t)=>e+t.mass,0)*a+Math.max(0,n)*Math.max(0,i.length-1))/2;for(let t of i){for(let{node:i,sample:r}of t.active){let t=(l-o[i.id])/a+r.topMass-(r.boundaryOffset??0);g.get(i.id).set(e,t)}l+=t.mass*a+Math.max(0,n)}}for(let e of c){let i=t[e.id],r=s[e.id],o=g.get(e.id),a=m.get(e.id),n=[];for(let e of y){let t=o.get(e),{exact:i,sample:r}=a(e);i?n.push(...i.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}}))):null==t||!r||1e-9>=Vt(r)||n.push({...r,t:e,boundaryOffset:(r.boundaryOffset??0)+t})}r.samples=n,r.localAttachments=new Map([...i.localAttachments].map(([e,t])=>{let i=o.get(t.time);return[e,{...t,...null!=i?{boundaryOffset:(t.boundaryOffset??0)+i}:{}}]}))}}return s}function Ut(e,t,i,r,o){let{plotH:a,padding:n,valueScale:l,packing:s,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=o,y=rt(),g=rt();for(let t of e)y[t.id]=i[t.id].topPeak||0,g[t.id]=i[t.id].botPeak||0;let m="half"===u,x=rt();for(let t of e){let e=Array.isArray(t.xExtent)?t.xExtent[0]:null,i=Array.isArray(t.xExtent)?t.xExtent[1]:null,o=null!=e&&Number.isFinite(e)?e:1/0,a=null!=i&&Number.isFinite(i)?i:-1/0;for(let e of r.outgoing[t.id]){o>e.startTime&&(o=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&o>e.systemInTime&&(o=e.systemInTime);let t=m?(e.startTime+e.endTime)/2:e.endTime;t>a&&(a=t)}for(let e of r.incoming[t.id]){let t=m?(e.startTime+e.endTime)/2:e.startTime;o>t&&(o=t),e.endTime>a&&(a=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>a&&(a=e.systemOutTime)}x[t.id]={start:Number.isFinite(o)?o:null,end:Number.isFinite(a)?a:null}}let b=rt(),v=[],w=[];if(o.frozenSlots){let e=zt(o.frozenSlots,i,x);v=e.slots,b=e.slotByNode,w=v.map(at)}else if("reuse"===s){let r=Gt(e,t,i,x);v=r.slots,b=r.slotByNode}else e.forEach((e,t)=>{v.push({occupants:[{id:e.id,end:x[e.id]?.end??-1/0}],peak:{topPeak:y[e.id],botPeak:g[e.id]},...e.group?{group:e.group}:{}}),b[e.id]=t});$t(v,b),0===w.length&&(w=v.map(at));let k=null;o.frozenSlots||(o.fixedSlotOrder?function(e,t,i){let r=new Map(i.map((e,t)=>[e,t]));St(e,t,[...e].sort((e,t)=>(r.get(at(e))??1/0)-(r.get(at(t))??1/0)||ot(at(e),at(t))))}(v,b,o.fixedSlotOrder):o.runOrdering&&c&&"insertion"!==c&&(k=Dt(e,t,i,x,v,b,{plotH:a,padding:n,valueScale:l,groupPadding:h,laneOrder:c,ribbonLane:f,domain:p}))),$t(v,b);let A=ut(e,t,i,v,b,{plotH:a,padding:n,valueScale:l,stackValueScale:o.stackValueScale,lanePlacement:d,groupPadding:h}),S=0===v.length?0:v[0].peak.topPeak+A.adjacentClearance.reduce((e,t)=>e+t,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,_=k?.after.crossings??null,P=k?.before.weightedLength??null,L=k?.after.weightedLength??null;return{effectiveSlotsHeight:S,centerlines:A.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:A.slotCenter,stackCenter:A.stackCenter,verticalUtilization:A.verticalUtilization,selectedSlotOrder:v.map(at),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:_,lengthBefore:P,lengthAfter:L}}function Zt(e){let{sx:t,sTop:i,sBot:r,tx:o,tTop:a,tBot:n,cp1X:l,cp2X:s}=e,c=(i+r)/2,u=(a+n)/2;return{pathD:[`M${t},${i}`,`C${l},${i} ${s},${a} ${o},${a}`,`L${o},${n}`,`C${s},${n} ${l},${r} ${t},${r}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:l,y:c},{x:s,y:u},{x:o,y:u}],halfWidth:(r-i)/2}}}function Kt(e,t,i,r,o,a,n,l,s={}){let c,u,d,h,f=o,p=e=>l?Math.max(l[0],Math.min(l[1],e)):e,y=a(p(e.time)),g=a(p(i.time)),m=e.value*f,x=i.value*f,b=t+(e.boundaryOffset??0)*f,v=r+(i.boundaryOffset??0)*f,w=e.sideMassBefore*f,k=i.sideMassAfter*f;"top"===e.side?(c=b-w,u=c+m):(u=b+w,c=u-m),"top"===i.side?(d=v-k,h=d+x):(h=v+k,d=h-x);let A=s.sourceRunwayStart,S=s.minRun,M=Math.abs((d+h)/2-(c+u)/2),_=g-y,P="number"==typeof A&&Number.isFinite(A),L="number"==typeof S&&Number.isFinite(S)&&S>0;if(P&&M>1e-9&&_>0&&("auto"===S||L)){let t="source"===n?.85:"target"===n?.15:.5,i="auto"===S?Math.min(144,Math.sqrt(8*M/(1.5*Math.min(t*t,(1-t)*(1-t))))):S;if(i>_){let t=a(p(Math.min(A,e.time)));Number.isFinite(t)&&(y=Math.min(y,Math.max(Math.min(y,t),g-i)))}}let $="source"===n?y+.85*(g-y):"target"===n?y+.15*(g-y):(y+g)/2;return{sx:y,sTop:c,sBot:u,tx:g,tTop:d,tBot:h,cp1X:$,cp2X:$}}function Qt(e){return Math.max(18,11*e.length*.58)}function Jt(e){let t=1.22*Qt(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function ei(e,t){let i=e.labelX-Qt(e.labelText),r=t.labelX-Qt(t.labelText);return t.labelX+3>=i&&e.labelX+3>=r}function ti(e){return e.replace(nf,(e,t,i)=>`${i},${t}`)}function ii(e){if(!e)return;let t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function ri(e){return{...e,pathD:ti(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function oi(e){return{type:"hatch",background:e.background,stroke:e.stroke,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle}}function ai(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function ni(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}function li(e,t){let{background:i="transparent",stroke:r="#000",lineWidth:o=1.5,spacing:a=6,angle:n=45,lineOpacity:l=1}=e,s=Math.max(8,Math.ceil(2*a));return cf("pattern",{id:t,width:s,height:s,patternUnits:"userSpaceOnUse",patternTransform:0!==n?`rotate(${n})`:void 0,children:[i&&"transparent"!==i&&sf("rect",{width:s,height:s,fill:i}),sf("line",{x1:0,y1:0,x2:0,y2:s,stroke:r,strokeWidth:o,strokeOpacity:l}),sf("line",{x1:a,y1:0,x2:a,y2:s,stroke:r,strokeWidth:o,strokeOpacity:l})]},t)}function si(e){let{nodes:t,edges:i,domain:r,plotW:o,plotH:a,ribbonLane:n,ribbonMinRun:l=0,edgeOpacity:s,colorOf:c,layoutOpts:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:y="raw",styleRules:g,colorBy:m,valueAccessor:x,usageMode:b="static"}=e,v="vertical"===d?a:o,w="vertical"===d?o:a,k=function(e,t,i,r={}){let o=et(r.usageMode??"static"),a=[],n=new Set;for(let t of e)n.has(t.id)&&a.push({kind:"duplicate-node",id:t.id,severity:o.duplicateIds}),n.add(t.id);let l=new Set,s=Array.isArray(i)&&2===i.length,c=s&&Number.isFinite(i[0])&&Number.isFinite(i[1]);(!s||!c||!c||i[0]>i[1])&&a.push({kind:"invalid-domain"});for(let t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[1]>=t.xExtent[0]||a.push({kind:"invalid-node-time",id:t.id}));for(let e of t)l.has(e.id)&&a.push({kind:"duplicate-edge",id:e.id,severity:o.duplicateIds}),l.add(e.id),n.has(e.source)||a.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),n.has(e.target)||a.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&a.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),(!Number.isFinite(e.value)||0>=e.value)&&a.push({kind:"invalid-value",id:e.id}),e.startTime>e.endTime&&a.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):a.push({kind:"invalid-edge-time",id:e.id});return a}(t,i,r,{usageMode:b}),{fatal:A,warnings:S}=function(e){let t=[],i=[];for(let r of e)"fatal"===tt(r)?t.push(r):i.push(r);return{fatal:t,warnings:i}}(k),M=function(e,t,i="static"){if("strip"!==et(i).invalidSystemTime)return e;let r=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===r.size?e:e.map(e=>{if(!r.has(e.id))return e;let t={...e};return null!=t.systemInTime&&!Number.isFinite(t.systemInTime)&&delete t.systemInTime,null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime)&&delete t.systemOutTime,t})}(i,k,b),_=Zh().domain(r).range([0,v]);if(A.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:A,warnings:S,xScale:_};let P=function(e,t,i){let{plotH:r,pairing:o="temporal",packing:a="reuse",laneOrder:n="crossing-min",lifetimeMode:l="half",maxValueScale:s,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=i,p=Number.isFinite(d)?Math.max(0,d):0,y=function(e,t){let i=rt(),r=rt();for(let t of e)i[t.id]=[],r[t.id]=[];for(let e of t)r[e.source]&&r[e.source].push(e),i[e.target]&&i[e.target].push(e);return{incoming:i,outgoing:r}}(e,t),g=function(e,t,i,r="temporal"){let o="temporal"===r?(e,t)=>e.endTime-t.endTime||ot(e.id,t.id):(e,t)=>t.value-e.value||ot(e.id,t.id),a="temporal"===r?(e,t)=>e.startTime-t.startTime||ot(e.id,t.id):(e,t)=>t.value-e.value||ot(e.id,t.id),n=new Map;for(let e of t)n.set(e.id,{});let l=(e,t)=>{let i=new Map;for(let r of e){let e=r[t];i.has(e)||i.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});let o=i.get(e);o.edges.push(r),o.total+=r.value,o.earliestStart=Math.min(o.earliestStart,r.startTime),o.latestEnd=Math.max(o.latestEnd,r.endTime)}let n=[...i.values()];n.sort("temporal"===r?(e,i)=>"target"===t?e.earliestStart-i.earliestStart||ot(e.partner,i.partner):e.latestEnd-i.latestEnd||ot(e.partner,i.partner):(e,t)=>t.total-e.total||ot(e.partner,t.partner));for(let e of n)e.edges.sort("target"===t?a:o);return n};for(let t of e){let e=i.outgoing[t.id],r=i.incoming[t.id];if(0===r.length)l(e,"target").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)n.get(t.id).sourceSide=i});else if(0===e.length)l(r,"source").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)n.get(t.id).targetSide=i});else{let t=l(r,"source"),i=l(e,"target"),o=Math.max(t.length,i.length);for(let e=0;o>e;e++){let r=e%2==0?"top":"bot";if(t[e])for(let i of t[e].edges)n.get(i.id).targetSide=r;if(i[e])for(let t of i[e].edges)n.get(t.id).sourceSide=r}}}return n}(e,t,y,o),m=rt();for(let t of e)m[t.id]=kt(t,y,g,void 0,u);let x=Ut(e,t,m,y,{plotH:r,padding:12,valueScale:1,packing:a,laneOrder:n,lifetimeMode:l,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),b=x.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),v=new Set;for(let e of t){let t=x.slotByNode[e.source],i=x.slotByNode[e.target];if(void 0===t||void 0===i)continue;let r=g.get(e.id);t!==i?t>i?(r.sourceSide="top",r.targetSide="bot"):(r.sourceSide="bot",r.targetSide="top"):(v.add(e.id),r.sourceSide="bot",r.targetSide="bot")}for(let t of e){let e=y.outgoing[t.id],i=y.incoming[t.id],r=new Set(e.map(e=>g.get(e.id).sourceSide)),o=new Set(i.map(e=>g.get(e.id).targetSide));if(1===r.size&&i.length>0){let e=[...r][0];for(let t of i)x.slotByNode[t.source]===x.slotByNode[t.target]&&(g.get(t.id).targetSide=e)}if(1===o.size&&e.length>0){let t=[...o][0];for(let i of e)x.slotByNode[i.source]===x.slotByNode[i.target]&&(g.get(i.id).sourceSide=t)}}(function(e,t,i){let r=new Map,o=[];for(let t of e)o.push({time:t.startTime,kind:"out",edge:t}),o.push({time:t.endTime,kind:"in",edge:t});o.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||ot(e.edge.id,t.edge.id));let a=e=>{let t=r.get(e);return t||(t={top:0,bot:0},r.set(e,t)),t},n=(e,t,i)=>{let r="top"===t?"bot":"top",o=Math.min(i,e[t]);e[t]-=o;let a=i-o;a>0&&(e[r]=Math.max(0,e[r]-a))};for(let e of o){let{edge:r}=e;if("in"===e.kind){let e=t.get(r.id)?.targetSide??"bot";a(r.target)[e]+=r.value;continue}let o=a(r.source),l=t.get(r.id),s=l.sourceSide??"bot";if(i[r.source]===i[r.target]){let e=o.top>=r.value,t=o.bot>=r.value;e!==t?s=e?"top":"bot":!e&&!t&&o.top!==o.bot&&(s=o.top>o.bot?"top":"bot"),l.sourceSide=s,l.targetSide=s}n(o,s,r.value)}})(t,g,x.slotByNode),function(e,t,i,r){for(let o of e){let e=t.incoming[o.id],a=t.outgoing[o.id];if(0===e.length||0===a.length)continue;let n=()=>{let t={inTop:0,inBot:0,outTop:0,outBot:0};for(let r of e)"top"===i.get(r.id).targetSide?t.inTop+=r.value:t.inBot+=r.value;for(let e of a)"top"===i.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},l=(e,t)=>{let o=n(),l="top"===e?o.outTop-o.inTop:o.outBot-o.inBot,s="top"===t?o.inTop-o.outTop:o.inBot-o.outBot;if(0>=l||0>=s)return!1;let c=Math.min(l,s),u=a.filter(t=>!r.has(t.id)&&i.get(t.id).sourceSide===e&&c>=t.value).sort((e,t)=>t.value-e.value||ot(e.id,t.id));return 0!==u.length&&(i.get(u[0].id).sourceSide=t,!0)},s=a.length+1;for(;s-- >0&&(l("top","bot")||l("bot","top")););}}(e,y,g,v),m=rt();for(let t of e)m[t.id]=kt(t,y,g,void 0,u);let w=Ut(e,t,m,y,{plotH:r,padding:12,valueScale:1,packing:a,laneOrder:n,lifetimeMode:l,frozenSlots:b,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),A=w.slots.slice(0,-1).reduce((e,t,i)=>e+(null!=t.group&&t.group===w.slots[i+1].group?1:0),0),S=Math.max(1,w.slots.length+1-A),M=Math.min(12,Math.max(0,.35*r-A*p)/S),_=2*M+nt(w.slots,M,p).reduce((e,t)=>e+t,0),P=k>0?Math.max(0,(r-_)/k):1,L=Number.isFinite(s)&&s>0?Math.min(P,s):P,$=Ut(e,t,m,y,{plotH:r,padding:M,valueScale:L,packing:a,laneOrder:n,lifetimeMode:l,frozenSlots:b,lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P}),T=Number.isFinite(s)&&s>0&&P>s+1e-12;if("insertion"!==n&&("hug"===c||T)&&$.slots.length>1&&(Dt(e,t,m,$.laneLifetime,$.slots,$.slotByNode,{plotH:r,padding:M,valueScale:L,groupPadding:p,laneOrder:n,ribbonLane:h,domain:f,lanePlacement:c,mode:"geometry-refine"}),$=Ut(e,t,m,y,{plotH:r,padding:M,valueScale:L,packing:a,laneOrder:n,lifetimeMode:l,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(at),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})),function(e,t){let i=(e,i)=>{for(let r of e){let e=new Map;for(let o of r){let r=`${("out"===i?t.get(o.id)?.sourceSide:t.get(o.id)?.targetSide)??""}\0${"out"===i?o.startTime:o.endTime}`,a="out"===i?`${o.target}\0${o.endTime}`:`${o.source}\0${o.startTime}`,n=e.get(r);if(null!=n&&n!==a)return!0;e.set(r,a)}}return!1};return i(Object.values(e.outgoing),"out")||i(Object.values(e.incoming),"in")}(y,g)){let i=function(e,t,i,r){let o=new Map;for(let a of e){let e=t[a.source]?.localAttachments.get(a.id),n=t[a.target]?.localAttachments.get(a.id),l=i[a.source],s=i[a.target];if(!(e&&n&&Number.isFinite(l)&&Number.isFinite(s)))continue;let c=wt(e,l,r),u=wt(n,s,r);o.set(a.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return o}(t,m,$.centerlines,L);m=rt();for(let t of e)m[t.id]=kt(t,y,g,i,u);$=Ut(e,t,m,y,{plotH:r,padding:M,valueScale:L,packing:a,laneOrder:n,lifetimeMode:l,frozenSlots:$.slots,fixedSlotOrder:$.slots.map(at),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:P})}let R=new Map(x.initialSlotOrder.map((e,t)=>[e,t])),C=[...$.slots].sort((e,t)=>(R.get(at(e))??1/0)-(R.get(at(t))??1/0)||ot(at(e),at(t))),I=rt();C.forEach((e,t)=>{for(let i of e.occupants)I[i.id]=t});let D=ut(e,t,m,C,I,{plotH:r,padding:M,valueScale:L,stackValueScale:P,lanePlacement:"stack",groupPadding:p}),z=qt(e,m,C,I,D.centerlines,L,p),O=xt(Rt(I,t),Ct(I,t),t,z,C,I,D.centerlines,$.laneLifetime,L,D.verticalUtilization,h,f);m=qt(e,m,$.slots,$.slotByNode,$.centerlines,L,p);let F=xt(Rt($.slotByNode,t),Ct($.slotByNode,t),t,m,$.slots,$.slotByNode,$.centerlines,$.laneLifetime,L,$.verticalUtilization,h,f);return{nodeData:m,sides:g,valueScale:L,padding:M,compressedPadding:12>M,centerlines:$.centerlines,laneLifetime:$.laneLifetime,slots:$.slots,slotByNode:$.slotByNode,crossingsBefore:"insertion"===n?null:O.crossings,crossingsAfter:"insertion"===n?null:F.crossings,lengthBefore:"insertion"===n?null:O.weightedLength,lengthAfter:"insertion"===n?null:F.weightedLength,layoutQualityBefore:O,layoutQuality:F}}(t,M,{plotH:w,...u,ribbonLane:n,domain:r}),{centerlines:L,nodeData:$,valueScale:T}=P,R=uu(m,x),C=[],I=[],D=0===l?new Map:function(e,t,i){let r=new Set(t.map(e=>e.target)),o=new Map(e.map(e=>[e.id,e])),a=new Map;for(let e of t){if(r.has(e.source))continue;let t=a.get(e.source)??[];t.push(e),a.set(e.source,t)}let n=new Map;for(let t of e){if(!t.group)continue;let e=n.get(t.group)??[];e.push(t),n.set(t.group,e)}let l=new Set;for(let[e,t]of n){let i=t.flatMap(e=>a.get(e.id)??[]),o=new Set(i.map(e=>e.startTime));i.length>0&&1===o.size&&t.every(e=>{let t=e.xExtent?.[0],o=i[0].startTime;return!r.has(e.id)&&(a.get(e.id)?.length??0)>0&&Number.isFinite(t)&&o>t})&&l.add(e)}let s=new Map;for(let[e,t]of a){let r=o.get(e);if(r?.group&&!l.has(r.group))continue;let a=r?.xExtent?.[0],n=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=n[0]?.startTime-1,u=null;for(let e=0;n.length>e;){let t=n[e].startTime,r=e+1;for(;n.length>r&&n[r].startTime===t;)r++;for(let t=e;r>t;t++){let e=n[t],r=Number.isFinite(a)&&e.startTime>a,o=Number.isFinite(e.systemInTime)&&e.startTime>e.systemInTime;if(!r&&!o)continue;let l=i[0];r&&(l=Math.max(l,a)),o&&(l=Math.max(l,e.systemInTime)),!r&&o&&Number.isFinite(c)&&(l=Math.max(l,c)),null!=u&&(l=Math.max(l,u)),e.startTime>l&&s.set(e.id,l)}u=t,e=r}}for(let[e,t]of n){if(!l.has(e))continue;let i=t.flatMap(e=>a.get(e.id)??[]);if(!i.every(e=>s.has(e.id))){for(let e of i)s.delete(e.id);continue}let r=Math.max(...i.map(e=>s.get(e.id)));for(let e of i)s.set(e.id,r)}return s}(t,M,r),z=new Map(t.filter(e=>e.group).map(e=>[e.id,e.group])),O=new Map;for(let e of M){let t=$[e.source]?.localAttachments.get(e.id),i=$[e.target]?.localAttachments.get(e.id);!t||!i||O.set(e.id,Kt(t,L[e.source],i,L[e.target],T,_,n,r,{minRun:l,sourceRunwayStart:D.get(e.id)}))}let F=function(e,t,i,r,o,a){let n=new Map(t),l=new Map;for(let t of e){let e=a?.get(t.source),i=null==e?"node:"+t.source:"group:"+e,r=l.get(i)??new Map,o=r.get(t.startTime)??[];o.push(t),r.set(t.startTime,o),l.set(i,r)}for(let e of l.values())for(let[a,l]of e){if(!l.some(e=>i.has(e.id)))continue;let e=l.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;let s=r(a),c=Math.min(...e.map(e=>e.sx));if(c>=s-1e-9)continue;let u=Math.max(...l.map(e=>{let t=i.get(e.id);return null==t?s:Math.min(s,r(t))})),d=Math.min(s,Math.max(c,u));for(let e of l){let i=t.get(e.id),r=d+(i.tx-d)*("source"===o?.85:"target"===o?.15:.5);n.set(e.id,{...i,sx:d,cp1X:r,cp2X:r})}}return n}(M,O,D,_,n,z),N=function(e,t,i,r,o){let a=new Map;for(let n of e){if(!i.has(n.id))continue;let e=t.get(n.id);if(!e||e.sx>=r(n.startTime)-1e-9)continue;let l=o(e.sx);Number.isFinite(l)&&n.startTime>l&&a.set(n.id,l)}return a}(M,F,D,_,e=>r[0]+e/v*(r[1]-r[0])),E=function(e,t,i){let r=new Map,o=new Map;for(let[e,t]of i??[]){let i=o.get(t)??[];i.push(e),o.set(t,i)}for(let a of e){let e=t.get(a.id);if(null==e||!Number.isFinite(e)||e>=a.startTime)continue;let n=i?.get(a.source),l=null==n?[a.source]:o.get(n)??[a.source];for(let t of l){let i=r.get(t)??new Map,o=i.get(a.startTime);i.set(a.startTime,null==o?e:Math.min(o,e)),r.set(t,i)}}return r}(M,N,z);t.forEach((e,t)=>{let i=$[e.id];if(!i||0===i.samples.length)return;let o=(n=i.samples,(l=E.get(e.id))&&0!==l.size?n.map(e=>{let t=l.get(e.t);return null==t?e:{...e,t:t}}):n),a=function(e,t,i,r,o){if(0===e.length)return null;let a=vt(e,o),n=e=>t+(a[e].boundaryOffset??0)*i,l=e=>n(e)-a[e].topMass*i,s=e=>n(e)+a[e].botMass*i,c=`M${r(a[0].t)},${l(0)}`;for(let e=1;a.length>e;e++)c+=` L${r(a[e].t)},${l(e)}`;c+=` L${r(a[a.length-1].t)},${s(a.length-1)}`;for(let e=a.length-2;e>=0;e--)c+=` L${r(a[e].t)},${s(e)}`;return c+" Z"}(o,L[e.id],T,_,r);var n,l;if(!a)return;let s,u,h=vt(o,r),f=h.find(e=>e.topMass+e.botMass>0)||h[0],p=L[e.id]+(f.botMass-f.topMass+2*(f.boundaryOffset??0))*T/2,y=c(e.id,t),m=y,x=.5,b=e.__raw??e;if(g&&g.length>0){let e=fu(b,g,R(b));"string"==typeof e.fill?y=e.fill:null!=e.fill&&ai(e.fill)&&(u=e.fill,y=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:y),"string"==typeof e.stroke&&(m=e.stroke),"number"==typeof e.strokeWidth&&(x=e.strokeWidth),"number"==typeof e.fillOpacity&&(s=e.fillOpacity),"number"==typeof e.opacity&&null==s&&(s=e.opacity)}let v=function(e,t,i,r,o,a){let n=i.nodeData[e];if(!n||0===n.samples.length)return[];let l=i.valueScale,s=i.centerlines[e],c=vt(n.samples,o),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=r(u.t),f=r(d.t),p=e=>r(bt(e,o)),y=[],g=(e,t,i,r)=>`M${e},${t} L${i},${t} L${i},${r} L${e},${r} Z`;for(let i of t){if(i.source===e&&null!=i.systemInTime&&Number.isFinite(i.systemInTime)){let e=n.localAttachments.get(i.id),t=a?.get(i.id)??i.startTime;if(e&&"out"===e.kind&&t>i.systemInTime){let r=p(i.systemInTime),a=p(t),n=null!=o&&o[0]>i.systemInTime,c=n?r:r-20,u=n?Math.min(a,r+20):r,d=Math.max(h,c);if(a>d){let[t,i]=wt(e,s,l);y.push({pathD:g(d,t,a,i),x0:c,x1:u,from:0,to:1})}}}if(i.target===e&&null!=i.systemOutTime&&Number.isFinite(i.systemOutTime)){let e=n.localAttachments.get(i.id);if(e&&"in"===e.kind&&i.systemOutTime>i.endTime){let t=p(i.systemOutTime),r=p(i.endTime),o=t+20,a=Math.min(f,o);if(a>r){let[i,n]=wt(e,s,l);y.push({pathD:g(r,i,a,n),x0:t,x1:o,from:1,to:0})}}}}return y}(e.id,M,P,_,r,N);C.push({id:e.id,pathD:a,fill:y,stroke:m,strokeWidth:x,...null!=s&&{fillOpacity:s},...u&&{hatchFill:u},...v.length>0&&{gradientStubs:v},rawDatum:b,labelX:_("vertical"===d&&e.xExtent?e.xExtent[0]:f.t)-4,labelY:p,labelText:e.label??e.id})});let W=new Map;t.forEach((e,t)=>W.set(e.id,t)),M.forEach(e=>{let t=F.get(e.id);if(!t)return;let i=W.get(e.source)??0,r=c(e.source,i),{pathD:o,bezier:a}=Zt(t),n=e.__raw??e,l="function"==typeof s?Number(s(n)):s,u=Number.isFinite(l)?Math.max(0,Math.min(1,l)):.35;I.push({id:e.id,pathD:o,fill:r,opacity:u,rawDatum:n,bezier:a})});let j=function(e,t,i){let r=e.map(e=>({...e})),o=new Map;for(let e of r){let i=t[e.id];if(null==i)continue;let r=o.get(i)??[];r.push(e),o.set(i,r)}let a=e=>{if(2>e.length)return;let t=e.reduce((e,t)=>e+t.labelY,0)/e.length,r=(e.length-1)/2;e.forEach((e,o)=>{e.labelY=Math.max(8,Math.min(i-8,t+16*(o-r)))})};for(let e of o.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],i=-1/0;for(let r of e){let e=r.labelX-Qt(r.labelText);t.length>0&&e>i+3&&(a(t),t=[],i=-1/0),t.push(r),i=Math.max(i,r.labelX)}a(t)}return function(e,t){let i=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;3>e;e+=1){for(let e=0;i.length>e;e+=1){let t=8;for(let r=0;e>r;r+=1)ei(i[e],i[r])&&(t=Math.max(t,i[r].labelY+16));i[e].labelY=Math.max(i[e].labelY,t)}for(let e=i.length-1;e>=0;e-=1){let r=t-8;for(let t=e+1;i.length>t;t+=1)ei(i[e],i[t])&&(r=Math.min(r,i[t].labelY-16));i[e].labelY=Math.min(i[e].labelY,r)}}}(r,i),r}(C,P.slotByNode,w).map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:ti(e.pathD),gradientStubs:e.gradientStubs?.map(ri),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(e,d)),B="vertical"===d?function(e,t,i){let r=e.map(e=>({...e}));for(let e of r){let i=1.22*Qt(e.labelText)+4;e.labelX=t-4>i?Math.max(i/2+2,Math.min(t-i/2-2,e.labelX)):t/2}let o=[],a=[...r].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(let e of a){let t=o[o.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?o.push([e]):t.push(e)}for(let e of o){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],r=new Map;for(let i of e){let[e,o]=Jt(i),a=t.findIndex(t=>e>t+8);-1===a&&(a=t.length),t[a]=o,r.set(i,a)}let o=e.reduce((e,t)=>e+t.labelY,0)/e.length,a=14*t.length+8>o;for(let t of e){let e=r.get(t)??0;t.labelY=a?Math.min(i-8,12+14*e):Math.max(8,o-14*e)}}return r}(j,o,a):j,Y=new Map;if(null!=f)for(let e of t){let t=e.__raw??e,i="function"==typeof f?f(t):Number(t[f]);Number.isFinite(i)&&Y.set(e.id,i)}let X=function(e,t,i,r,o={}){if(!1===r)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===r)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let a=Math.max(4,Math.min(e.length,Math.floor(Math.max(1,t*i)/14e3)));Number.isFinite(o.maxLabels)&&o.maxLabels>=0&&(a=Math.min(a,Math.floor(o.maxLabels)));let n=e.map((e,t)=>{let i=o.priorityById?.get(e.id),r=Math.abs(e.labelY);return{band:e,index:t,score:null!=i&&Number.isFinite(i)?1e6*i+Qt(e.labelText):Qt(e.labelText)+.01*r}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),l=new Set(n.slice(0,a).map(e=>e.band.id));return e.map(e=>l.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}(B,o,a,h,{...Y.size>0&&{priorityById:Y},...null!=p&&{maxLabels:p}});return{layout:P,layoutConfig:{bands:X,ribbons:I.map(e=>function(e,t){return"horizontal"===t?e:{...e,pathD:ti(e.pathD),bezier:ii(e.bezier)}}(e,d)),showLabels:!1!==h,selectionDatum:y},issues:[],warnings:S,xScale:_}}function ci(e,t,i,r="horizontal"){return"vertical"===r?{top:e?38:t?28:16,right:24,bottom:24,left:i?72:24}:{top:e?30:t?24:8,right:80,bottom:i?28:8,left:80}}function ui(e,t,i){return!t?.isActive||t.predicate(function(e,t){return"scene"===t?e:e.data}(e,i))}function di(e,t){if(!e)return[];let i=[],r=e=>{i.push(e);let o="function"==typeof t?t(e):e[t];o&&Array.isArray(o)&&o.forEach(r)};return r(e),i}function hi(e,t,i,r){if(e&&e.length>0)return e;let o=new Set;return t.forEach(e=>{let t="function"==typeof i?i(e):e[i],a="function"==typeof r?r(e):e[r];o.add(t),o.add(a)}),Array.from(o).map(e=>({id:e}))}function fi(e,t,i={}){return q(t?"function"==typeof t?i=>({...e(i),...t(i)??{}}):i=>({...e(i),...t}):e,i)}function pi(e,t,i){let[r,o]=i;if(!t)return r;let[a,n]=t,l=n>a?n-a:0,s=Number(e),c=Number.isFinite(s)?s:a;return r+Math.max(0,Math.min(1,l>0?(c-a)/l:0))*(o-r)}function yi(e){let{valueAccessor:t,valueDomain:i,edgeWidthRange:r,resolveStroke:o,edgeOpacity:a,edgeLinecap:n,styleRules:l}=e,s=du(t);return cu(e=>({stroke:o(e),strokeWidth:pi(e[t],i,r),strokeLinecap:n,opacity:a,fillOpacity:0}),l,e=>({value:s(e)}))}function gi(e,t,i,r){let o,a,n=Array.isArray(e)?e:[];if(t){let e="string"==typeof t?t:"__geoColorBy",r="string"==typeof t?n:n.map(e=>({...e,__geoColorBy:t(e)}));o=G(r,e,i)}if(r.sizeBy){let e=n.map("function"==typeof r.sizeBy?r.sizeBy:e=>e?.[r.sizeBy]).filter(e=>null!=e&&isFinite(e));e.length>0&&(a=nd(e))}return e=>({fill:t&&o?Y(e,t,o):Yd,fillOpacity:r.fillOpacity,stroke:"#fff",strokeWidth:r.strokeWidth,r:r.sizeBy?V(e,r.sizeBy,r.sizeRange,a):r.pointRadius??6})}function mi(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}function xi(e,t,i,r){let{windowPlot:o,lidSegments:a}=e,n=a[t];return i&&!n?Math.min(o.y+o.height-r,o.y+.48*o.height+2*r+4):!i&&n?Math.min(o.y+o.height-r,Math.max(n.y1,n.y2)+2*r+4):o.y+r+2}function bi(e,t,i,r,o){let{windowPlot:a,windowCount:n,windowStart:l,windowSize:s}=r;if(i&&t>=r.closedWindowCount)return r.gutter.x+r.gutter.width/2;let c=a.width/n,u=i?a.x:a.x+t*c,d=i?a.x+a.width:u+c,h=Math.min((d-u)/2,o+(i?0:3));return Math.max(u+h,Math.min(d-h,a.x+(e-l)/s*c))}function vi(e,t,i){let r=e.width/Math.max(1,t),o=Math.max(2,2*i),a=Math.min(.7*r,Math.max(3.2*o,o+8)),n=Math.max(1,Math.floor(a/o));return{laneWidth:r,tubeWidth:a,ballDiameter:o,perRow:n,centerX:t=>e.x+(t+.5)*r,pileHeight:e=>Math.ceil(Math.max(0,e)/n)*o}}function wi(e,t,i,r){let o=(t+i)/2,a=[];for(let n of e){let l=a.filter(e=>n.radius+e.radius+.5>Math.abs(n.x-e.x)),s=[o];for(let e of l){let t=Math.sqrt((n.radius+e.radius+.5)**2-(n.x-e.x)**2);s.push(e.y-t,e.y+t)}let c=.5>r()?-1:1;s.sort((e,t)=>Math.abs(e-o)-Math.abs(t-o)||c*(e-t));let u=s.find(e=>e-n.radius>=t&&i>=e+n.radius&&l.every(t=>(n.x-t.x)**2+(e-t.y)**2>=(n.radius+t.radius+.5)**2-1e-6));if(null==u){let r=Math.max(...e.map(e=>e.radius)),a=Math.max(0,i-t-2*r);return{positions:e.map((t,i)=>o+(1===e.length?0:i/(e.length-1)-.5)*a),overlapping:!0,entryOffset:0}}a.push({...n,y:u})}return{positions:a.map(e=>e.y),overlapping:!1,entryOffset:Math.max(0,Math.min(36,...a.map(e=>e.y-e.radius-t)))}}function ki(e){if(Array.isArray(e)&&e.length>=2){let t=Oc(e[0]),i=Oc(e[1]);return null!=t&&null!=i?{x:t,y:i}:null}if(e&&"object"==typeof e){let t=e,i=Oc(t.x),r=Oc(t.y);return null!=i&&null!=r?{x:i,y:r}:null}return null}function Ai(e){return Array.isArray(e)?e.map(ki).filter(e=>null!=e):[]}function Si(e,t,i){return"normalized"===i?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:Cc(e.x,t.plot.x,t.plot.x+t.plot.width),y:Cc(e.y,t.plot.y,t.plot.y+t.plot.height)}}function Mi(e){let t=0;for(let i=1;e.length>i;i+=1)t+=Math.hypot(e[i].x-e[i-1].x,e[i].y-e[i-1].y);return t}function _i(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};let i=Cc(t,0,1)*Mi(e),r=0;for(let t=1;e.length>t;t+=1){let o=e[t-1],a=e[t],n=Math.hypot(a.x-o.x,a.y-o.y);if(n>0){if(r+n>=i){let e=(i-r)/n;return{x:o.x+(a.x-o.x)*e,y:o.y+(a.y-o.y)*e}}r+=n}}return{...e[e.length-1]}}function Pi(e,t){let i=_i(e,Math.max(0,t-.02)),r=_i(e,Math.min(1,t+.02)),o=r.x-i.x,a=r.y-i.y,n=Math.hypot(o,a)||1;return{x:o/n,y:a/n}}function Li(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}function $i(e,t,i){return B(e,t,i)}function Ti(e,t){let i=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>i&&X(i,e)||"#4e79a7":t=>{if(i){let e=X(i,t);if(e)return e}let r=0;for(let e=0;t.length>e;e++)r=31*r+t.charCodeAt(e)|0;return e[Math.abs(r)%e.length]??"#4e79a7"}}function Ri(e,t){let i=t.config??{},r=(t.sensors??[]).map(e=>({...e,sensor:!0})),o=[...t.colliders??[],...r],a=[...e.colliders??[],...i.colliders??[],...o];return{...e,...i,observation:{...e.observation,...i.observation},...a.length>0&&{colliders:a}}}function Ci(e){let t=Fi(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function Ii(e,t,i,r){return i?"function"==typeof i?i(e,t):e[i]??r:r}function Di(e){return`gauntlet:${e}:core`}function zi(e,t){return`gauntlet:${e}:positive:${t}`}function Oi(e,t,i){return`gauntlet:${e}:negative:${t}:${i}`}function Fi(e){let t=e.height??e.floorY+36;if(e.width>=220&&t>=160)return Bf;let i=Math.max(1,Math.min(e.width,t)),r=Math.max(2,.04*e.width);return{left:r,top:Math.max(2,.08*t),rightInset:r,thickness:Math.max(1,Math.min(4,.04*i))}}function Ni(e){return Math.max(.12,Math.min(1,e.width/500,(e.height??e.floorY+36)/260))}function Ei(e,t,i,r){let o=Fi(r),a=Math.max(2,i+2),n=o.top+o.thickness/2+a,l=r.floorY-a,s=(e,t,i)=>t>i?(t+i)/2:Math.max(t,Math.min(i,e));return{x:s(e,o.left+o.thickness/2+a,r.width-o.rightInset-o.thickness/2-a),y:s(t,n,l)}}function Wi(e,t,i=1){let r=[...e].sort((e,t)=>e.localeCompare(t)),o=Math.max(0,r.indexOf(t));return{angle:.82*-Math.PI+(r.length>1?o/(r.length-1):.5)*Math.PI*.64,index:o,radius:(48+o%2*6)*i}}function ji(e,t,i){let r=e.activePositiveIds.reduce((e,i)=>e+(t.get(i)?.value??1),0),o=e.missingPositiveIds.length+e.poppedPositiveIds.length,a=e.negativeIds.reduce((e,t)=>e+(i.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*r-8*a-1.2*e.delay-5*o))}function Bi(e){let t=function(e,t,i){let[r,o]=e,a=220>r||160>o,n=Math.round(.48*o),l=a?o-Math.max(3,Math.min(12,.1*o)):o-36,s=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,s.length),u=.22*r,d=c>1?(.78*r-u)/(c-1):0,h=a?Math.max(Math.round(.12*r),.08*r+6):Math.max(Math.round(.14*r),110);return{crashY:l-(a?Math.min(i,Math.max(3,.22*o)):i),floorY:l,gates:s.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(a?8:54,Math.round(.07*r))})),graveyardX:Math.round(r*(a?.72:.84)),graveyardY:l-4,height:o,routeY:n,socketX:Math.round(r*(a?.82:.92)),startX:h,width:r}}(e.size??[900,520],e.gates,e.crashOffset??30),i=e.positiveProperties??[],r=new Map(i.map(e=>[e.id,e])),o=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),a={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},n=(e.data??[]).map((t,n)=>{let l=function(e,t,i,r,o){let a=Ii(e,t,i.idAccessor,null!=e.id?e.id+"":"project-"+t)+"",n=r.map(e=>e.id),l=[...Ii(e,t,i.positiveAccessor,n)],s=[...Ii(e,t,i.negativeAccessor,[])].filter(e=>o.has(e));return{id:a,activePositiveIds:l,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Ii(e,t,i.metricsAccessor,{})},missingPositiveIds:n.filter(e=>!l.includes(e)),negativeIds:s,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Ii(e,t,i.startTimeAccessor,0))||0),stage:"project filed",viability:Ii(e,t,i.initialViability,100)}}(t,n,a,i,o);return{...l,viability:e.viability?.(l,{negativeProperties:o,positiveProperties:r})??ji(l,r,o)}}),l=n.flatMap((i,a)=>{let n=function(e,t,i,r){let o=function(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}(i),a=r?.(e,t,i)??{};return{...o,...a,startY:a.startY??a.routeY??o.startY,socketY:a.socketY??a.routeY??o.socketY,graveyardY:a.graveyardY??o.graveyardY}}(i,a,t,e.projectPlacement);return function(e,t,i,r,o,a,n){let l=Ni(i),s=Math.max(3,28*l),c=r.startX,u=r.startY+(r.startY===i.routeY?38*t*l:0),d=n?.(e,t,i,r)??{},h=d.x??c,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},y=[{...d,id:Di(e.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:s},spawnAt:d.spawnAt??e.startedAt,datum:p}],g=Ei(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||s,i);y[0].x=g.x,y[0].y=g.y;for(let t of e.activePositiveIds){let r=o.get(t);if(!r)continue;let a=Wi(e.activePositiveIds,t,l),n=r.radius??Math.max(2,10*l),s=Ei(g.x+Math.cos(a.angle)*a.radius,g.y+Math.sin(a.angle)*a.radius,n,i);y.push({id:zi(e.id,t),x:s.x,y:s.y,vx:18*Math.cos(a.angle),vy:18*Math.sin(a.angle),mass:r.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:n},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:r,sourceDatum:e.datum},springs:!1===r.spring?[]:[{target:{type:"body",bodyId:Di(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+a.index%2*4)*l),...r.spring??{}}]})}return e.negativeIds.forEach((t,r)=>{let o=a.get(t);o&&y.push(function(e,t,i,r,o,a,n){let l=Ni(a),s=t.radius??Math.max(2,7.2*l),c=Ei(r+(i%4*12-12)*l,o+(54+12*Math.floor(i/4))*l,s,a);return{id:Oi(e.id,t.id,i),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:s},spawnAt:n,datum:{__gauntlet:!0,kind:jf,projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Di(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+i%4*3)*l),...t.spring??{}}]}}(e,o,r,g.x,g.y,i,d.spawnAt??e.startedAt))}),y}(i,a,t,n,r,o,e.coreBody)});return{layout:t,states:n,initialSpawns:l,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:Ci(t)}}}function Yi(e=[]){let t=Object.create(null);for(let[i,r]of e)t[i]=r;return t}function Xi(...e){let t=Yi();for(let i of e)for(let[e,r]of Object.entries(i??{}))t[e]=r;return t}function Gi(e){return Xi(e)}function Vi(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function Hi(e){let t=Yi(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:Gi(t.initialMetrics),metrics:Gi(t.metrics),productIds:[...t.productIds],history:Vi(t.history)}])),i=Yi(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:Gi(t.metrics),sourceIds:[...t.sourceIds],history:Vi(t.history)}])),r=Yi(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?Gi(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:i,relations:r,input:{amount:e.input.amount,metrics:Gi(e.input.metrics)},metrics:Gi(e.metrics),loss:{amount:e.loss.amount,metrics:Gi(e.loss.metrics)},history:Vi(e.history)}}function qi(e,t){return t>e?-1:e>t?1:0}function Ui(e,t,i,r,o){return{severity:e,code:t,message:i,path:r,ids:o?[...o]:void 0}}function Zi(e){let t=new Set,i=new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(qi)}function Ki(e,t){return e?Object.entries(e).flatMap(([e,i])=>Number.isFinite(i)?[]:[Ui("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function Qi(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}function Ji(e,t,i="selector"){let r=[],o=Object.values(e.components),a=new Set(o.map(e=>e.id)),n=(t.ids??[]).filter(e=>!a.has(e));if(n.length&&r.push(Ui("error","unknown-component",`Selector references unknown component id${1===n.length?"":"s"}: ${n.join(", ")}.`,i+".ids",n)),void 0!==t.count&&(!Number.isInteger(t.count)||0>t.count)&&r.push(Ui("error","invalid-selector-count","Selector count must be a non-negative integer.",i+".count")),r.some(e=>"error"===e.severity))return{ids:[],diagnostics:r};let l=t.ids?new Set(t.ids):null,s=t.categories?new Set(t.categories):null,c=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null,d=o.filter(e=>!l||l.has(e.id)).filter(e=>!s||s.has(e.category)).filter(e=>!c||c.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(qi);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||r.push(Ui("warning","empty-selector","Selector matched no source components.",i)),{ids:d,diagnostics:r}}function er(e,t,i={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...i}}function tr(e,t){let i={...t,eventId:e.event.id};e.materializations.push(i),e.observations.push({...i,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function ir(e,t,i){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(Ui("error","unknown-outlet",`Unknown outlet "${t}".`,i,[t])),1))}function rr(e,t,i){let r=Zi(t);t.length||e.diagnostics.push(Ui("error","empty-source-list","A product requires at least one source component.",i)),r.length&&e.diagnostics.push(Ui("error","duplicate-source",`Source ids may appear only once: ${r.join(", ")}.`,i,r));let o=t.filter(t=>!e.state.components[t]);o.length&&e.diagnostics.push(Ui("error","unknown-component",`Unknown source component id${1===o.length?"":"s"}: ${o.join(", ")}.`,i,o));let a=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);a.length&&e.diagnostics.push(Ui("error","source-already-assigned",`Source component${1===a.length?" is":"s are"} already assigned: ${a.join(", ")}.`,i,a));let n=t.filter(t=>"consumed"===e.state.components[t]?.status&&!a.includes(t));return n.length&&e.diagnostics.push(Ui("error","source-unavailable",`Consumed source component${1===n.length?" is":"s are"} unavailable: ${n.join(", ")}.`,i,n)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function or(e,t,i,r,o){let a=r?.amount??0;(!Number.isFinite(a)||0>a||a>t+Yf)&&e.diagnostics.push(Ui("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",o+".amount")),e.diagnostics.push(...Ki(r?.metrics,o+".metrics"));for(let[t,a]of Object.entries(r?.metrics??{}))(0>a||a>Number(i[t]??0)+Yf)&&e.diagnostics.push(Ui("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${o}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function ar(e,t,i,r,o,a,n){return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:a&&void 0!==e.amount?e.amount:i,metrics:a&&e.metrics?Xi(r,e.metrics):Gi(r),status:a?"complete":"forming",sourceIds:[...t],outletId:a?e.outletId??(o.outletIds.has("product")?"product":void 0):void 0,createdByEventId:o.event.id,createdAt:o.context.appliedAt,completedByEventId:a?o.event.id:void 0,completedAt:a?o.context.appliedAt:void 0,history:[n]}}function nr(e,t,i,r){void 0!==t.amount&&Math.abs(t.amount-i)>Yf&&e.diagnostics.push(Ui("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${i}.`,r,[t.id]))}function lr(e,t,i){let r=`events.${e.event.id}.effects.${i}`,o=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(Ui("error","invalid-component-state",`set-state cannot assign "${t.state+""}".`,r+".state")),e.diagnostics.push(...Ki(t.metricsDelta,r+".metricsDelta")),ir(e,t.outletId,r+".outletId");let i=Ji(o,t.select,r+".select");e.diagnostics.push(...i.diagnostics);let a=i.ids.filter(e=>o.components[e].productIds.length);if(a.length&&e.diagnostics.push(Ui("error","source-already-assigned",`Assigned source components cannot be retargeted: ${a.join(", ")}.`,r+".select",a)),e.diagnostics.some(e=>"error"===e.severity))return;let n=er(e,t,{sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0});for(let e of i.ids){let i=o.components[e];i.status=t.state,i.outletId=t.outletId,i.reason=t.reason,t.metricsDelta&&Qi(i.metrics,t.metricsDelta),i.history.push(n)}return o.history.push(n),void(i.ids.length&&tr(e,{type:"retarget-component",sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){let{relation:i}=t;(!i.id||o.relations[i.id])&&e.diagnostics.push(Ui("error","duplicate-relation",`Relation id "${i.id}" is missing or already active.`,r+".relation.id",[i.id]));let a=function(e,t,i){let r=Zi(t),o=t.filter(t=>!e.state.components[t]);return 2>t.length&&e.diagnostics.push(Ui("error","insufficient-relation-sources","A relation requires at least two source components.",i)),r.length&&e.diagnostics.push(Ui("error","duplicate-source",`Relation source ids must be unique: ${r.join(", ")}.`,i,r)),o.length&&e.diagnostics.push(Ui("error","unknown-component",`Relation references unknown source component${1===o.length?"":"s"}: ${o.join(", ")}.`,i,o)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}(e,i.sourceIds,r+".relation.sourceIds");if(e.diagnostics.push(...Ki(i.metrics,r+".relation.metrics")),!a||e.diagnostics.some(e=>"error"===e.severity))return;o.relations[i.id]={...i,sourceIds:[...i.sourceIds],metrics:i.metrics?Gi(i.metrics):void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};let n=er(e,t,{sourceIds:[...i.sourceIds],relationIds:[i.id]});return o.history.push(n),void tr(e,{type:"activate-relation",sourceIds:[...i.sourceIds],relationIds:[i.id]})}if("resolve-relation"===t.type){let i=Zi(t.relationIds),a=t.relationIds.filter(e=>!o.relations[e]),n=t.relationIds.filter(e=>"resolved"===o.relations[e]?.status);if(i.length&&e.diagnostics.push(Ui("error","duplicate-relation","Relation ids must be unique.",r+".relationIds",i)),a.length&&e.diagnostics.push(Ui("error","unknown-relation",`Unknown relation: ${a.join(", ")}.`,r+".relationIds",a)),n.length&&e.diagnostics.push(Ui("error","resolved-relation",`Relation is already resolved: ${n.join(", ")}.`,r+".relationIds",n)),e.diagnostics.some(e=>"error"===e.severity))return;for(let i of t.relationIds){let r=o.relations[i];r.status="resolved",r.resolution=t.resolution,r.resolvedByEventId=e.event.id,r.resolvedAt=e.context.appliedAt,r.reason=t.reason}let l=er(e,t,{relationIds:[...t.relationIds]});return o.history.push(l),void tr(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){let i=e.productDefinitions.get(t.productId);i||e.diagnostics.push(Ui("error","unknown-product",`Product "${t.productId}" has no declared mold.`,r+".productId",[t.productId]));let a=o.products[t.productId];"combine"===t.type&&a&&e.diagnostics.push(Ui("error","duplicate-product",`Product "${t.productId}" has already been formed.`,r+".productId",[t.productId])),"contribute"===t.type&&(!a||"forming"!==a.status)&&e.diagnostics.push(Ui("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,r+".productId",[t.productId]));let n=rr(e,t.sourceIds,r+".sourceIds"),l="contribute"===t.type&&a?[...a.sourceIds,...t.sourceIds]:t.sourceIds,s=function(e,t,i,r){if(!t?.length)return[];let o=Zi(t),a=t.filter(t=>!e.state.relations[t]),n=t.filter(t=>"resolved"===e.state.relations[t]?.status),l=new Set(i),s=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!l.has(e)));return o.length&&e.diagnostics.push(Ui("error","duplicate-relation","Basis relations must be unique.",r,o)),a.length&&e.diagnostics.push(Ui("error","unknown-relation",`Unknown basis relation: ${a.join(", ")}.`,r,a)),n.length&&e.diagnostics.push(Ui("error","resolved-relation",`Basis relation is already resolved: ${n.join(", ")}.`,r,n)),s.length&&e.diagnostics.push(Ui("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${s.join(", ")}.`,r,s)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}(e,t.basisRelationIds,l,r+".basisRelationIds");if(!n||!s||!i||e.diagnostics.some(e=>"error"===e.severity))return;let c=n.reduce((e,t)=>e+t.amount,0),u=function(e){let t=Yi();for(let i of e)Qi(t,i.metrics);return t}(n);if(!or(e,c,u,t.loss,r+".loss"))return;let d=c-(t.loss?.amount??0);!function(e,t,i){e.state.loss.amount+=i?.amount??0;for(let[r,o]of Object.entries(i?.metrics??{}))t[r]=Number(t[r]??0)-o,e.state.loss.metrics[r]=Number(e.state.loss.metrics[r]??0)+o}(e,u,t.loss);let h,f="combine"===t.type&&!1!==t.complete,p=er(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});if("combine"===t.type){if(f&&nr(e,i,d,r+".productId"),h=ar(i,t.sourceIds,d,u,e,f,p),f&&!ir(e,h.outletId,r+".productId"))return;o.products[t.productId]=h}else h=a,h.sourceIds.push(...t.sourceIds),h.amount+=d,Qi(h.metrics,u),h.history.push(p);for(let e of n)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(p);return o.history.push(p),function(e,t){if(t.length){for(let i of t)i.status="resolved",i.resolution="combined",i.resolvedByEventId=e.event.id,i.resolvedAt=e.context.appliedAt;tr(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}(e,s),tr(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:h.outletId?[h.outletId]:void 0}),void(f&&tr(e,{type:"complete-product",sourceIds:[...h.sourceIds],productIds:[h.id],outletIds:h.outletId?[h.outletId]:void 0}))}if("complete-product"===t.type){let i=o.products[t.productId];return i?void function(e,t,i,r,o,a){let n=e.productDefinitions.get(t.id),l=i??n?.outletId??(e.outletIds.has("product")?"product":void 0);if(!ir(e,l,a+".outletId"))return;if("complete"===t.status)return void e.diagnostics.push(Ui("error","product-already-complete",`Product "${t.id}" is already complete.`,a,[t.id]));n&&(nr(e,n,t.amount,a+".productId"),void 0!==n.amount&&(t.amount=n.amount),n.metrics&&(t.metrics=Xi(t.metrics,n.metrics))),t.status="complete",t.outletId=l,t.reason=r,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;let s=er(e,o,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:l?[l]:void 0});t.history.push(s),e.state.history.push(s),tr(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:l?[l]:void 0})}(e,i,t.outletId,t.reason,t,r):void e.diagnostics.push(Ui("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,r+".productId",[t.productId]))}if("split"===t.type){let i=rr(e,[t.sourceId],r+".sourceId");t.products.length||e.diagnostics.push(Ui("error","empty-split","A split requires at least one product allocation.",r+".products"));let a=t.products.map(e=>e.productId),n=Zi(a);n.length&&e.diagnostics.push(Ui("error","duplicate-product","Split product ids must be unique.",r+".products",n));let l=a.map(t=>e.productDefinitions.get(t)),s=a.filter((e,t)=>!l[t]),c=a.filter(e=>o.products[e]);s.length&&e.diagnostics.push(Ui("error","unknown-product",`Split references undeclared product molds: ${s.join(", ")}.`,r+".products",s)),c.length&&e.diagnostics.push(Ui("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,r+".products",c));for(let[i,o]of t.products.entries())void 0!==o.amount&&(!Number.isFinite(o.amount)||0>o.amount)&&e.diagnostics.push(Ui("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${r}.products.${i}.amount`)),e.diagnostics.push(...Ki(o.metrics,`${r}.products.${i}.metrics`));if(!i?.length||e.diagnostics.some(e=>"error"===e.severity))return;let u=i[0];if(!or(e,u.amount,u.metrics,t.loss,r+".loss"))return;let d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??l[t]?.amount),f=h.filter(e=>void 0!==e).length;if(0!==f&&f!==h.length)return void e.diagnostics.push(Ui("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",r+".products"));let p=f?h:t.products.map(()=>d/t.products.length),y=p.reduce((e,t)=>e+t,0);if(Math.abs(y-d)>Yf)return void e.diagnostics.push(Ui("error","split-amount-mismatch",`Split allocations total ${y}, but ${d} remains after loss.`,r+".products"));let g=Gi(u.metrics);for(let[e,i]of Object.entries(t.loss?.metrics??{}))g[e]=Number(g[e]??0)-i;let m=er(e,t,{sourceIds:[u.id],productIds:a});if(t.products.forEach((i,a)=>{let n=l[a],s=d>Yf?p[a]/d:1/t.products.length,c=Yi(Object.entries(g).map(([e,t])=>[e,t*s])),h=i.metrics??n.metrics??c,f=ar({...n,amount:p[a],metrics:h},[u.id],p[a],Gi(h),e,!0,m);ir(e,f.outletId,`${r}.products.${a}.productId`)&&(o.products[f.id]=f)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=a,u.status="consumed",u.outletId=void 0,u.history.push(m),o.loss.amount+=t.loss?.amount??0;for(let[e,i]of Object.entries(t.loss?.metrics??{}))o.loss.metrics[e]=Number(o.loss.metrics[e]??0)+i;o.history.push(m),tr(e,{type:"split-source",sourceIds:[u.id],productIds:a});for(let t of a)tr(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:o.products[t].outletId?[o.products[t].outletId]:void 0});return}if("eject"===t.type){ir(e,t.outletId,r+".outletId");let i=Ji(o,t.select,r+".select");e.diagnostics.push(...i.diagnostics);let a=i.ids.filter(e=>o.components[e].productIds.length);if(a.length&&e.diagnostics.push(Ui("error","source-already-assigned",`Assigned source components cannot be ejected: ${a.join(", ")}.`,r+".select",a)),e.diagnostics.some(e=>"error"===e.severity))return;let n=er(e,t,{sourceIds:i.ids,outletIds:[t.outletId]});for(let e of i.ids){let i=o.components[e];i.status=t.state??"ejected",i.outletId=t.outletId,i.reason=t.reason,i.history.push(n)}return o.history.push(n),void(i.ids.length&&tr(e,{type:"retarget-component",sourceIds:i.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...Ki(t.metricsDelta,r+".metricsDelta")),e.diagnostics.some(e=>"error"===e.severity))return;let i,a;if("run"===t.target)Qi(o.metrics,t.metricsDelta);else if("components"in t.target){let a=Ji(o,t.target.components,r+".target.components");if(e.diagnostics.push(...a.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;i=a.ids;for(let e of a.ids)Qi(o.components[e].metrics,t.metricsDelta)}else{a=[...t.target.productIds];let i=Zi(a),n=a.filter(e=>!o.products[e]);if(i.length&&e.diagnostics.push(Ui("error","duplicate-product","Metric target product ids must be unique.",r+".target.productIds",i)),n.length&&e.diagnostics.push(Ui("error","unknown-product-state",`Metric target product has not formed: ${n.join(", ")}.`,r+".target.productIds",n)),e.diagnostics.some(e=>"error"===e.severity))return;for(let e of a)Qi(o.products[e].metrics,t.metricsDelta)}return void o.history.push(er(e,t,{sourceIds:i,productIds:a}))}t.outcome.trim()?(o.outcome=t.outcome,o.summary=t.summary,o.history.push(er(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(Ui("error","invalid-outcome","Outcome must be a non-empty string.",r+".outcome"))}function sr(e,t,i){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[Ui("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,"events."+t.id,[t.id])]};let r=Hi(e),o={state:r,event:t,context:i,productDefinitions:new Map(i.products.map(e=>[e.id,e])),outletIds:new Set(i.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(let[i,r]of t.effects.entries())if(lr(o,r,i),o.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:o.diagnostics};return r.elapsed=Math.max(r.elapsed,i.appliedAt),r.phaseId=i.phaseId,r.eventsApplied.push(t.id),o.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:i.phaseId,authoredAt:i.authoredAt,appliedAt:i.appliedAt}),{applied:!0,state:r,materializations:o.materializations,observations:o.observations,diagnostics:o.diagnostics}}function cr(e,t){return t>e?-1:e>t?1:0}function ur(e,t,i,r,o){return{severity:e,code:t,message:i,path:r,ids:o?[...o]:void 0}}function dr(e){let t=new Set,i=new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(cr)}function hr(e){let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function fr(e,t,i,r,o,a){if(!i)return r;try{return("function"==typeof i?i(e,t):e[i])??r}catch(e){return o.push(ur("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:e+""}.`,a)),r}}function pr(e,t,i){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(ur("error","invalid-metrics","Metrics must be a numeric object.",i)),Yi();let r=Yi();for(let[o,a]of Object.entries(e)){let e=hr(a);null!=e?r[o]=e:t.push(ur("error","invalid-metric",`Metric "${o}" must be finite.`,`${i}.${o}`))}return r}function yr(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function gr(e){let{id:t,orientation:i,fixed:r,start:o,end:a,openings:n,thickness:l,friction:s,restitution:c}=e,u=function(e,t,i){let r=i.map(([i,r])=>[Math.max(e,Math.min(i,r)),Math.min(t,Math.max(i,r))]).filter(([e,t])=>t>e+Hf).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),o=[],a=e;for(let[e,t]of r)e>a+Hf&&o.push([a,e]),a=Math.max(a,t);return t>a+Hf&&o.push([a,t]),o}(o,a,n);return u.map(([e,o],a)=>({id:1===u.length?t:`${t}:${a}`,friction:s,restitution:c,shape:"horizontal"===i?{type:"segment",x1:e,y1:r,x2:o,y2:r,thickness:l}:{type:"segment",x1:r,y1:e,x2:r,y2:o,thickness:l}}))}function mr(e){let t=2166136261;for(let i=0;e.length>i;i+=1)t^=e.charCodeAt(i),t=Math.imul(t,16777619);return t>>>0}function xr(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?mr(e):1}function br(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:xr(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function vr(e){return"crucible:component:"+encodeURIComponent(e)}function wr(e,t,i,r){if(void 0!==i&&Number.isFinite(i)&&i>0)return i;let o=Math.min(...t,e),a=Math.max(...t,e);return a-o>Hf?r[0]+(r[1]-r[0])*Math.sqrt(Math.max(0,e-o)/(a-o)):(r[0]+r[1])/2}function kr(e,t){let i=Math.max(.25,Math.min(1,t.width/900,t.height/520)),r=e?.[0]??7*i,o=e?.[1]??18*i,a=Math.max(1,Math.min(r,o));return[a,Math.max(a,Math.max(r,o))]}function Ar(e,t){if(!e)return[];let i=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),r=Math.max(1,Math.ceil(e/i));return Array.from({length:e},(e,o)=>({x:t.x+t.width/i*(o%i+.5),y:t.y+(Math.floor(o/i)+.5)*(t.height/r)}))}function Sr(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function Mr(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function _r(e,t,i={}){let r=Object.values(e.products).sort((e,t)=>cr(e.id,t.id)),o=Object.values(e.components).sort((e,t)=>cr(e.id,t.id)),a=[...o.map(e=>e.amount),...r.map(e=>e.amount)],n=kr(i.radiusRange,t),l=function(e,t){let i=new Map;for(let t of e){let e=t.outletId??"__chamber__",r=i.get(e)??[];r.push(t),i.set(e,r)}let r=new Map;for(let[e,o]of i){o.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||cr(e.id,t.id));let i=Ar(o.length,Mr(t,"__chamber__"===e?void 0:e));o.forEach((e,t)=>r.set(e.id,i[t]))}return r}(r,t),s=r.map(e=>{let r=l.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},o=1.28*wr(e.amount,a,i.bodyRadius,n),s={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:(c=e.id,"crucible:product:"+encodeURIComponent(c)),x:r.x,y:r.y,mass:Math.max(.25,o*o*.018),bodyCollisions:!1,shape:{type:"circle",radius:o},datum:s};var c}),c=new Map;for(let e of o.filter(e=>!e.productIds.length)){let t=Sr(e)??"__chamber__",i=c.get(t)??[];i.push(e),c.set(t,i)}let u=new Map;for(let[e,i]of c){let r=Ar(i.length,Mr(t,"__chamber__"===e?void 0:e));i.forEach((e,t)=>u.set(e.id,r[t]))}return[...o.map(e=>{let r=u.get(e.id);if(e.productIds.length){let i=e.productIds.map(e=>l.get(e)).filter(e=>!!e);if(i.length){r={x:i.reduce((e,t)=>e+t.x,0)/i.length,y:i.reduce((e,t)=>e+t.y,0)/i.length};let o=mr(e.id)/4294967295*Math.PI*2,a=Math.min(20,Math.max(4,.012*t.width));r={x:r.x+Math.cos(o)*a,y:r.y+Math.sin(o)*a}}}r??(r={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});let o=wr(e.amount,a,i.bodyRadius,n),s={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:vr(e.id),x:r.x,y:r.y,mass:Math.max(.25,o*o*.015),shape:{type:"circle",radius:o},datum:s}}),...s]}function Pr(e){return Array.isArray(e)?e.map(Pr):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>cr(e,t)).map(([e,t])=>[e,Pr(t)])):e}function Lr(e,t=e.duration){let i=function(e,t){let i=hr(t)??0,r=Math.max(0,Math.min(e.duration,i));if(!e.phases.length)return{elapsed:r,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};let o=r>=e.duration-Hf,a=o?e.phases[e.phases.length-1]:e.phases.find(e=>r>=e.start&&e.end>r)??e.phases[0];return{elapsed:r,phaseId:a.id,phaseIndex:a.index,phaseElapsed:o?a.duration:Math.max(0,r-a.start),complete:o}}(e,t),r=Hi(e.initialState),o=[],a=[],n=[];for(let t of e.events){if(t.authoredAt>i.elapsed+Hf)break;let l=sr(r,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});o.push(...l.diagnostics),a.push(...l.materializations),n.push(...l.observations),l.applied&&(r=l.state)}return r.elapsed=i.elapsed,r.phaseId=i.phaseId,r.phaseIndex=i.phaseIndex,r.phaseElapsed=i.phaseElapsed,r.complete=i.complete,i.complete&&"in_process"===r.outcome&&(r.outcome="complete"),r.playing=!1,{state:r,diagnostics:o,materializations:a,observations:n}}function $r(e){let t=function(e){let t=[];e.length||t.push(ur("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));let i=dr(e.map(e=>e.id));i.length&&t.push(ur("error","duplicate-phase-id",`Phase ids must be unique: ${i.join(", ")}.`,"phases",i));let r=0;return{phases:e.map((e,i)=>{let o=hr(e.duration),a=null!=o&&o>0?o:0;e.id.trim()||t.push(ur("error","invalid-phase-id","Phase ids may not be empty.",`phases.${i}.id`)),(null==o||0>=o)&&t.push(ur("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${i}.duration`,[e.id])),void 0!==e.intensity&&!Number.isFinite(e.intensity)&&t.push(ur("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${i}.intensity`,[e.id]));let n={...e,duration:a,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:i,start:r,end:r+a};return r=n.end,n}),diagnostics:t}}(e.phases),i=t.phases.at(-1)?.end??0,r=yr(e.outlets??Gf),o=(e.products??[]).map(e=>({...e,metrics:e.metrics?Xi(e.metrics):void 0})),a=function(e,t,i){let r=[],o=dr(e.map(e=>e.id));o.length&&r.push(ur("error","duplicate-event-id",`Event ids must be unique: ${o.join(", ")}.`,"events",o));let a=[];return e.forEach((e,o)=>{let n,l,s;if(e.id.trim()||r.push(ur("error","invalid-event-id","Event ids may not be empty.",`events.${o}.id`)),"time"in e.at&&void 0!==e.at.time){let a=hr(e.at.time);if(null==a||0>a||a>i+Hf)return void r.push(ur("error","event-time-out-of-range",`Event time must fall between 0 and ${i}.`,`events.${o}.at.time`,[e.id]));n=Math.max(0,Math.min(i,a));let c=function(e,t,i){let r=e.find(e=>Hf>=Math.abs(e.start-i));if(r)return{phase:r,boundaryRank:1};let o=e.find(e=>i>=e.start&&e.end>i);return o?{phase:o,boundaryRank:0}:Hf>=Math.abs(i-t)&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}(t,i,n);l=c.phase,s=c.boundaryRank}else{if(l=t.find(t=>t.id===e.at.phaseId),!l)return void r.push(ur("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${o}.at.phaseId`,[e.id,e.at.phaseId]));let i=e.at.progress??0;if(!Number.isFinite(i)||0>i||i>1)return void r.push(ur("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${o}.at.progress`,[e.id]));n=l.start+l.duration*i,s=0===i?1:0}l?a.push({...e,index:o,authoredAt:n,phaseId:l.id,phaseIndex:l.index,boundaryRank:s}):r.push(ur("error","event-without-phase","Event could not be assigned to a phase.",`events.${o}.at`,[e.id]))}),a.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:a,diagnostics:r}}(e.events??[],t.phases,i),n=function(e){let t=[],i=Yi(),r=[],o=0,a=Yi();e.data.forEach((n,l)=>{let s=(n.id??"component-"+l)+"",c=((fr(n,l,e.idAccessor,s,t,`data.${l}.id`)??s)+"").trim();if(!c)return void t.push(ur("error","invalid-component-id","Component ids may not be empty.",`data.${l}.id`));r.push(c);let u=hr(fr(n,l,e.amountAccessor,1,t,`data.${l}.amount`)),d=null==u||0>u?0:u;(null==u||0>u)&&t.push(ur("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${l}.amount`,[c]));let h=pr(fr(n,l,e.metricsAccessor,{},t,`data.${l}.metrics`),t,`data.${l}.metrics`),f=fr(n,l,e.initialStateAccessor,"active",t,`data.${l}.status`),p=Vf.has(f)?f:"active";Vf.has(f)||t.push(ur("error","invalid-component-status",`Unknown component status "${f+""}".`,`data.${l}.status`,[c]));let y=fr(n,l,e.labelAccessor,(n.label??n.name??c)+"",t,`data.${l}.label`)+"",g=fr(n,l,e.categoryAccessor,"component",t,`data.${l}.category`)+"";Object.hasOwn(i,c)||(i[c]={id:c,label:y,category:g,datum:n,status:p,initialAmount:d,amount:d,initialMetrics:Xi(h),metrics:Xi(h),productIds:[],history:[]},o+=d,function(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}(a,h))});let n=dr(r);n.length&&t.push(ur("error","duplicate-component-id",`Component ids must be unique: ${n.join(", ")}.`,"data",n));let l=pr(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:i,products:Yi(),relations:Yi(),input:{amount:o,metrics:a},metrics:l,loss:{amount:0,metrics:Yi()},history:[]},diagnostics:t}}(e),l=function(e=Xf,t=Gf){let i=Math.max(1,hr(e[0])??900),r=Math.max(1,hr(e[1])??520),o=360>i||260>r,a=o?Math.max(4,.035*Math.min(i,r)):20,n=o?Math.max(10,.075*r):34,l={x:a,y:a,width:Math.max(1,i-2*a),height:n},s=o?Math.max(16,.14*r):Math.min(78,.16*r),c={x:a,y:r-a-s,width:Math.max(1,i-2*a),height:s},u=o?Math.max(12,.08*i):Math.min(150,.17*i),d=l.y+l.height+(o?12:38),h=c.y-(o?10:34),f={x:u,y:d,width:Math.max(24,i-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,o?84:180)),y={x:f.x+(f.width-p)/2,y:f.y-(o?10:24),width:p,height:o?12:28},g=yr(t),m={left:g.filter(e=>"left"===(e.side??"bottom")),right:g.filter(e=>"right"===e.side),bottom:g.filter(e=>"bottom"===(e.side??"bottom"))},x=[],b=(e,t)=>{let r=Math.max(8,u-1.5*a),n=f.height/Math.max(1,t.length);t.forEach((t,l)=>{x.push({...t,side:e,x:"left"===e?a:i-a-r,y:f.y+l*n,width:r,height:Math.max(8,n-(o?2:8))})})};b("left",m.left),b("right",m.right);let v=f.width/Math.max(1,m.bottom.length);return m.bottom.forEach((e,t)=>{x.push({...e,side:"bottom",x:f.x+t*v,y:f.y+f.height+(o?2:7),width:Math.max(8,v-(o?2:8)),height:Math.max(8,c.y-f.y-f.height-(o?4:12))})}),x.sort((e,t)=>g.findIndex(t=>t.id===e.id)-g.findIndex(e=>e.id===t.id)),{width:i,height:r,phaseRail:l,chamber:f,mouth:y,projection:c,outlets:x}}(e.size??Xf,r),s=function(e){let{chamber:t,mouth:i}=e,r=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),o=Math.max(t.x,i.x),a=Math.min(t.x+t.width,i.x+i.width),n={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},l=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:o,y2:t.y,thickness:r}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:a,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:r}}];l.push(...gr({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:n.left.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...gr({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:n.right.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...gr({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:n.bottom.map(e=>[e.x,e.x+e.width]),thickness:r,friction:.5,restitution:.08}));for(let t of e.outlets)l.push({id:"crucible:outlet:"+encodeURIComponent(t.id),sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return l}(l),c=function(e,t){let i=[],r=new Set(t.map(e=>e.id)),o=dr(t.map(e=>e.id)),a=dr(e.map(e=>e.id));return o.length&&i.push(ur("error","duplicate-outlet-id",`Outlet ids must be unique: ${o.join(", ")}.`,"outlets",o)),a.length&&i.push(ur("error","duplicate-product-id",`Product ids must be unique: ${a.join(", ")}.`,"products",a)),t.forEach((e,t)=>{e.id.trim()||i.push(ur("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0!==e.order&&!Number.isFinite(e.order)&&i.push(ur("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||i.push(ur("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0!==e.amount&&(!Number.isFinite(e.amount)||0>e.amount)&&i.push(ur("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0!==e.outletId&&!r.has(e.outletId)&&i.push(ur("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),pr(e.metrics??{},i,`products.${t}.metrics`)}),i}(o,r),u=(m={seed:e.seed??1,components:Object.values(n.state.components).sort((e,t)=>cr(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:i,description:r,intensity:o,motion:a,color:n,metrics:l})=>({id:e,duration:t,label:i,description:r,intensity:o,motion:a,color:n,metrics:l})),products:o,outlets:r,events:a.events.map(({id:e,label:t,description:i,summary:r,authoredAt:o,phaseId:a,boundaryRank:n,effects:l})=>({id:e,label:t,description:i,summary:r,authoredAt:o,phaseId:a,boundaryRank:n,effects:l}))},JSON.stringify(Pr(m))),d=function(e,t,i={}){let r=Object.values(e.components).sort((e,t)=>cr(e.id,t.id)),o=r.map(e=>e.amount),a=kr(i.radiusRange,t),n=function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(xr(i.seed)),l=t.mouth.x+t.mouth.width/2,s=t.chamber.y+Math.max(18,.18*t.chamber.height),c=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return r.map((e,t)=>{let d=t/Math.max(1,r.length)*Math.PI*2+.18*(n()-.5),h=wr(e.amount,o,i.bodyRadius,a),f={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:vr(e.id),x:l+Math.cos(d)*c*(.45+.45*n()),y:s+Math.sin(d)*u*(.45+.45*n()),vx:24*(n()-.5),vy:18*(n()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}(n.state,l,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),h=[...t.diagnostics,...a.diagnostics,...n.diagnostics,...c],f={phases:t.phases,events:a.events,products:o,outlets:r,duration:i,initialState:n.state,terminalState:n.state,layout:l,colliders:s,config:br(e.seed,s),initialSpawns:d,terminalSpawns:[],semanticKey:u,diagnostics:h},p=Lr(f),y=Object.values(p.state.products).filter(e=>"forming"===e.status).map(e=>e.id),g=y.length?[ur("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${y.join(", ")}.`,"events",y)]:[];var m;return f.terminalState=p.state,f.terminalSpawns=qf(p.state,l,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),f.diagnostics=[...h,...p.diagnostics,...g],f}function Tr(e,t){let i=e.fillStyle,r="#010203";try{e.fillStyle=r,e.fillStyle=t}catch{return e.fillStyle=i,[78,121,167]}let o=e.fillStyle;if(e.fillStyle=i,"string"!=typeof o)return[78,121,167];if(o.toLowerCase()===r&&t.trim().toLowerCase()!==r)return[78,121,167];if(o.startsWith("#"))return[parseInt(o.slice(1,3),16),parseInt(o.slice(3,5),16),parseInt(o.slice(5,7),16)];let a=o.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return a?[+a[1],+a[2],+a[3]]:[78,121,167]}function Rr(e){switch(e){case"monotoneX":return Zf;case"monotoneY":return Kf;case"cardinal":return Qf;case"catmullRom":return Jf;case"step":return ep;case"stepBefore":return tp;case"stepAfter":return ip;case"basis":return rp;case"natural":return op;default:return null}}function Cr(e,t,i){if(null==t)return i;if(ai(t)){let r=function(e,t){let i=e.background??"transparent",r=e.stroke??"#000",o="transparent"===i||"none"===i?i:tu(t,i)||i,a=tu(t,r)||r||"#000",n="u">typeof window&&window.devicePixelRatio||1,l=`${ni(e)}|${o}|${a}@${n}`,s=uf.get(l);if(void 0!==s)return s;let c=function(e={},t){let i,{background:r="transparent",stroke:o="#000",lineWidth:a=1.5,spacing:n=6,angle:l=45}=e,s={background:r,stroke:o,lineWidth:a,spacing:n,angle:l},c=Math.max(8,Math.ceil(2*n));try{i=function(e){return"u">typeof OffscreenCanvas?new OffscreenCanvas(e,e):(lf||(lf=document.createElement("canvas")),lf.width=e,lf.height=e,lf)}(c)}catch{return oi(s)}let u=i.getContext("2d");if(!u)return oi(s);r&&"transparent"!==r?(u.fillStyle=r,u.fillRect(0,0,c,c)):u.clearRect(0,0,c,c),u.strokeStyle=o,u.lineWidth=a,u.lineCap="square";let d=l*Math.PI/180;if(45===l||-45===l){let e=l>0?1:-1;for(let t=-c;2*c>=t;t+=n)u.beginPath(),u.moveTo(t,0),u.lineTo(t+e*c,c),u.stroke()}else{u.save(),u.translate(c/2,c/2),u.rotate(d);let e=2*c;for(let t=-e;e>=t;t+=n)u.beginPath(),u.moveTo(-e,t),u.lineTo(e,t),u.stroke();u.restore()}return(t||u).createPattern(i,"repeat")}({background:o,stroke:a,lineWidth:e.lineWidth,spacing:e.spacing,angle:e.angle},t),u=ai(c)?null:c;return uf.set(l,u),u}(t,e);return r||t.background&&tu(e,t.background)||i}return"string"!=typeof t?t:tu(e,t)||i}function Ir(e,t,i){let r=Cr(e,t,i);if("string"==typeof r&&r.trim().startsWith("var(")){let t=tu(e,i);return t&&!t.trim().startsWith("var(")?t:i}return r}function Dr(e,t,i,r,o,a,n){let l=t.stops.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity)));if(2>l.length)return null;let s=e.createLinearGradient(r,o,a,n);for(let t of l)s.addColorStop(Math.max(0,Math.min(1,t.offset)),zr(e,t,i));return s}function zr(e,t,i){let r=t.color??i,o=tu(e,r)||r;if(null==t.opacity)return o;let a=Math.max(0,Math.min(1,t.opacity)),[n,l,s]=Tr(e,o);return`rgba(${n},${l},${s},${a})`}function Or(e){return Number.isFinite(e)?1e3>Math.abs(e)?Number.isInteger(e)?e+"":e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):e.toLocaleString():"0"}function Fr(e,t,i,r){let o=e.datum;if(!o?.__crucible)return;let a="circle"===e.shape.type?e.shape.radius:8,n="string"==typeof t.fill?t.fill:"product"===o.kind?"#b8792d":"#356b63",l="string"==typeof t.stroke?t.stroke:"#26323a",s="number"==typeof t.strokeWidth?t.strokeWidth:1.25,c="number"==typeof t.opacity?t.opacity:.96,u=r?`${r}-crucible-body-${i}`:"crucible-body-"+i;if("product"===o.kind){let t=Array.from({length:6},(t,i)=>{let r=-Math.PI/2+i/6*Math.PI*2;return`${e.x+Math.cos(r)*a},${e.y+Math.sin(r)*a}`}).join(" "),i=u+"-glow";return np(Uf.Fragment,{children:[ap("defs",{children:ap("filter",{id:i,x:"-60%",y:"-60%",width:"220%",height:"220%",children:ap("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:n,floodOpacity:"0.8"})})}),ap("polygon",{points:t,fill:n,stroke:l,strokeWidth:s,opacity:c,filter:`url(#${i})`}),ap("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*a),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:s,opacity:.72*c})]},u)}return np(Uf.Fragment,{children:[ap("circle",{cx:e.x,cy:e.y,r:a,fill:n,stroke:l,strokeWidth:s,opacity:c}),ap("circle",{cx:e.x-.25*a,cy:e.y-.28*a,r:Math.max(1,.18*a),fill:"rgba(255,255,255,0.34)"})]},u)}function Nr(e){let{x:t,y:i,width:r,height:o}=e.chamber,a=Math.min(.14*r,48),n=i+o;return[`M ${t} ${i}`,`L ${t+a} ${n-.16*o}`,`Q ${t+r/2} ${n+.1*o} ${t+r-a} ${n-.16*o}`,`L ${t+r} ${i}`].join(" ")}function Er({layout:e,phases:t,state:i,compact:r=!1}){let o=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));return cp("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[cp("defs",{children:[cp("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[sp("stop",{offset:"0",stopColor:hp,stopOpacity:"0.03"}),sp("stop",{offset:"0.66",stopColor:hp,stopOpacity:"0.1"}),sp("stop",{offset:"1",stopColor:fp,stopOpacity:"0.18"})]}),sp("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:sp("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:up,strokeOpacity:"0.08",strokeWidth:"1"})})]}),sp("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:up,strokeOpacity:"0.52",strokeWidth:r?1:2.2}),sp("path",{d:Nr(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),sp("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:up,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:r?2:5}),r?null:sp("g",{"data-testid":"crucible-phase-rail",children:t.map((r,a)=>{let n=t.slice(0,a).reduce((e,t)=>e+Math.max(0,t.duration),0),l=e.phaseRail.x+n/o*e.phaseRail.width,s=Math.max(0,r.duration)/o*e.phaseRail.width,c=r.id===i.phaseId,u=i.phaseIndex>a||i.complete;return cp("g",{children:[sp("rect",{x:l,y:e.phaseRail.y,width:Math.max(1,s-2),height:e.phaseRail.height,rx:2,fill:c?r.color??hp:u?pp:up,fillOpacity:c?.68:u?.28:.09}),46>s?null:sp("text",{x:l+s/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:c?up:dp,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(r.label??r.id).toUpperCase()})]},r.id)})}),e.outlets.map(e=>cp("g",{children:[sp("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?fp:pp),fillOpacity:"0.1",stroke:e.color??("left"===e.side?fp:pp),strokeDasharray:"3 3",strokeOpacity:"0.62"}),r?null:sp("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:dp,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function Wr({rows:e,layout:t,projection:i,amountLabel:r}){if(!e.length)return null;let o=i.measure??"count",a=e.map(e=>Math.max(0,function(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}(e,o))),n=Math.max(1,...a),l=t.projection.width/Math.max(1,e.length),s=t.projection.height>48?21:4,c=Math.max(5,t.projection.height-s-5);return sp("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,i)=>{let u=a[i],d=Math.max(u>0?2:0,u/n*c),h=t.projection.x+i*l+.18*l;return cp("g",{children:[sp("rect",{x:h,y:t.projection.y+c-d,width:Math.max(3,.64*l),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?fp:"complete"===e.status?hp:pp,fillOpacity:"0.68"}),s>4&&l>=34?cp(lp,{children:[sp("text",{x:h+.32*l,y:t.projection.y+c+10,fill:dp,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?e.label.slice(0,12)+"…":e.label}),cp("text",{x:h+.32*l,y:t.projection.y+c+19,fill:up,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:850,textAnchor:"middle",children:[Or(u),"amount"===o&&r?" "+r:""]})]}):null]},e.key)})})}function jr(e){let t=e.datum;if(t&&"object"==typeof t){let e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Br(e,t,i,r,o){let a=Array.isArray(o)?o:o?[o]:[];if(!1!==i||0!==a.length)return({size:o})=>{let n=[Number(o[0])||700,Number(o[1])||420],l=Wc(n),s=Math.max(2,Math.round(t)),c=l.plot.width/s,u=l.plot.y+l.plot.height,d=Math.max(1,...e.map(e=>e.value)),h=!1!==i,[f,p]=r?.valueExtent??[0,s],y=p===f?1:p-f,g=e.map((e,t)=>{let i=u-e.value/d*l.plot.height*.9;return`${0===t?"M":"L"} ${(l.plot.x+(t+.5)*c).toFixed(1)} ${i.toFixed(1)}`}).join(" ");return mp("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?mp(yp,{children:[Array.from({length:s+1},(e,t)=>{let i=l.plot.x+t*c;return gp("line",{"data-testid":"galton-board-bin-wall",x1:i,x2:i,y1:l.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},"bin-wall-"+t)}),gp("line",{x1:l.plot.x,x2:l.plot.x+l.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),gp("path",{d:g,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>e.value>0?gp("text",{x:l.plot.x+(t+.5)*c,y:Math.max(l.plot.y+10,u-e.value/d*l.plot.height*.9-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`):null)]}):null,a.map((e,t)=>{let i=Number(e.value);if(!Number.isFinite(i))return null;let r=l.plot.x+Math.max(0,Math.min(1,(i-f)/y))*l.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",a="bottom"===e.labelPosition?Math.min(n[1]-8,u+16):l.plot.y+16;return mp("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[gp("line",{x1:r,x2:r,y1:l.plot.y+8,y2:u-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:gp("text",{x:Math.min(l.plot.x+l.plot.width-4,r+6),y:a,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${i}`)})]})}}function Yr(e,t,i){if(!1!==i&&t)return({size:i})=>{let r=[Number(i[0])||760,Number(i[1])||360],o=Wc(r),a=Math.max(1,t.windowCount),n=t.plot??o.plot,l=t.gutter??{x:n.x,y:n.y,width:0,height:n.height},s=t.windowPlot??n,c=s.width/a,u=n.y+n.height,d=n.y+.48*n.height,h=t.lidSegments[0]?.y1??d,f=t.windowStart,p=t.windowStart+a*t.windowSize,y=s.x+Math.max(0,Math.min(1,p===f?0:(t.watermarkValue-f)/(p-f)))*s.width;return mp("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[gp("rect",{x:n.x,y:n.y,width:n.width,height:n.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),l.width>0?mp("g",{children:[gp("rect",{x:l.x,y:h,width:l.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07}),mp("text",{x:l.x+l.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[t.lateCount," late"]})]}):null,Array.from({length:a},(i,o)=>{let a=e[o],n=s.x+o*c,l=t.closedWindowCount>o;return mp("g",{children:[gp("rect",{x:n,y:d,width:c,height:u-d,fill:l?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:l?.08:.06}),l?t.lidSegments.filter(e=>e.windowIndex===o).map(e=>gp("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,gp("text",{x:n+c/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:a?.value??0}),gp("text",{x:n+c/2,y:Math.min(r[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:a?.label??""})]},"window-"+o)}),t.windowWalls?.map(({id:e,...t})=>gp("rect",{...t,fill:"var(--semiotic-border, #d1d5db)",fillOpacity:.68},e)),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>gp("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),gp("line",{x1:n.x,x2:n.x+n.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),gp("line",{"data-testid":"event-drop-watermark",x1:y,x2:y,y1:n.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),mp("text",{x:Math.min(n.x+n.width-4,y+6),y:n.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]})]})}}function Xr(e,t,i,r=1){if(!1!==i&&0!==e.length)return({size:i})=>{let o=[Number(i[0])||700,Number(i[1])||380],a=Wc(o),n=vi(a.plot,e.length,t),l=a.plot.y+a.plot.height;return mp("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[gp("line",{x1:a.plot.x,x2:a.plot.x+a.plot.width,y1:l,y2:l,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{let i=Math.min(a.plot.height,n.pileHeight(e.value/r)),s=n.tubeWidth,c=n.centerX(t),u=l-i;return mp("g",{children:[gp("rect",{x:c-s/2,y:u,width:s,height:i,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),gp("text",{x:c,y:Math.max(a.plot.y+12,u-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),gp("text",{x:c,y:Math.min(o[1]-8,l+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)}),gp("text",{x:o[0]/2,y:o[1]-2,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:`Full circle = ${r}; partial circles scaled by area`})]})}}function Gr(e){return e.toLocaleString(void 0,Math.abs(e)>=1e3||.01>Math.abs(e)?{maximumFractionDigits:0}:{maximumFractionDigits:2})}function Vr(e,t){if(!1!==t&&e)return({size:t})=>{let i=[Number(t[0])||700,Number(t[1])||360],r=Wc(i),o=r.plot.y+r.plot.height,[a,n]=e.xExtent,l=a+(n-a)/2,s=[{label:Gr(a),x:e.xRange[0]},{label:Gr(l),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:Gr(n),x:e.xRange[1]}];return mp("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.some(e=>e.overlapping)?gp("text",{"data-testid":"collision-swarm-overlap-warning",x:r.plot.x,y:Math.max(10,r.plot.y-9),fill:"var(--semiotic-warning, #b45309)",fontSize:10,children:360>i[0]?"Points overlap":"Points overlap. Reduce radius or increase height."}):null,e.groups.map(e=>mp("g",{children:[gp("line",{x1:r.plot.x,x2:r.plot.x+r.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),gp("text",{x:r.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),mp("text",{x:r.plot.x+r.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count,e.overlapping?" · overlaps":""]})]},e.label)),gp("line",{x1:e.xRange[0],x2:e.xRange[1],y1:o,y2:o,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),s.map(e=>mp("g",{children:[gp("line",{x1:e.x,x2:e.x,y1:o,y2:o+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),gp("text",{x:e.x,y:Math.min(i[1]-8,o+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}function Hr(e,t,i={},r){if(!1===t||!e)return;let{volume:o,stages:a,groups:n,groupCompletion:l}=e,s=new Map(o.stages.map(e=>[e.id,e])),c=new Map(l.map(e=>[e.id,e]));return({size:e})=>{let t=Number(e[0])||o.width,l=Number(e[1])||o.height,u=a.map(e=>{let t=s.get(e.id),r=i["process-stage-"+e.id];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:r?.queueDepth,processed:r?.processedCount}}),d=n.map(e=>{let t=c.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return Xu({width:t,height:l,left:o.left,right:o.right,topY:o.topY,bottomY:o.bottomY,midY:o.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...r})}}function qr(e,t,i){if(!1===i||!t||0===e.length)return;let r=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:i})=>{let o=[Number(i[0])||t.volume.width,Number(i[1])||t.volume.height],a=Wc(o),n=Math.max(1,...e.map(e=>e.value)),l=Math.min(48,.18*a.plot.height),s=a.plot.y+6;return xp("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,i)=>{let o=e[i];if(!o)return null;let a=r.get(t.id);if(!a)return null;let c=Math.max(2,o.value/n*l),u=Math.max(8,.35*a.width);return xp("rect",{x:a.x-u/2,y:s,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}function Ur(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}function Zr(e,t){let{showNodeLabels:i,showSensors:r,showStaticFlow:o}=t;if(e&&(o||r||i))return({size:t})=>{let a=[Number(t[0])||760,Number(t[1])||420],n=Math.max(1,...e.links.map(e=>e.throughput)),l=new Set(e.nodes.map(e=>e.sensorId));return vp("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:a[0],height:a[1],viewBox:`0 0 ${a[0]} ${a[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[o?e.links.map(e=>{let t=3+e.throughput/n*16,i=e.path[Math.floor(e.path.length/2)];return vp("g",{children:[bp("path",{d:Ur(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),bp("path",{d:Ur(e.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),i?bp("text",{x:i.x,y:i.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:(r=e.throughput,r.toLocaleString(void 0,1e3>Math.abs(r)?{maximumFractionDigits:1}:{maximumFractionDigits:0}))}):null]},e.id);var r}):null,e.nodes.map(e=>vp("g",{children:[r&&l.has(e.sensorId)?bp("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,o?bp("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,i?bp("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}function Kr({layout:e,compact:t,showLabels:i}){let r=t?Math.round(.14*e.height):Math.max(80,e.routeY-180),o=t?Math.max(6,Math.round(.72*e.height)):Math.min(360,e.height-170);return kp(wp,{children:e.gates.map(a=>Ap("g",{children:[kp("rect",{x:a.x-a.width/2,y:r,width:a.width,height:o,rx:t?2:12,fill:a.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:a.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),i?kp("text",{x:a.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:a.label??a.id}):null]},a.id))})}function Qr({layout:e,states:t,compact:i=!1}){return i?kp("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:kp(Kr,{layout:e,compact:!0,showLabels:!1})}):Ap("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[kp("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),kp("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),kp("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),kp(Kr,{layout:e,compact:!1,showLabels:!0}),Ap("g",{children:[kp("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),kp("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),Ap("g",{children:[kp("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),kp("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),kp("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function Jr({states:e,layout:t}){let i=function(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}(e);if(!i.length)return null;let r=Math.max(1,...i.map(e=>e.value)),o=Math.max(40,(t.width-80)/i.length);return Ap("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[kp("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),i.map((e,t)=>{let i=40+t*o,a=Math.max(2,e.value/r*28),n=/kill|crash|block|grave/i.test(e.outcome);return Ap("g",{children:[kp("rect",{x:i+.18*o,y:28-a+22,width:Math.max(10,.45*o),height:a,rx:2,fill:n?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:n?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),kp("text",{x:i+.4*o,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}function eo(e){return e.map(e=>({...e,spawnAt:void 0}))}function to(e,t){return e?t?i=>Of.createElement(Of.Fragment,null,"function"==typeof e?e(i):e,"function"==typeof t?t(i):t):e:t}function io(e,t,i){let r=t[i];return"boolean"==typeof r?r:!0!==e.__compactMode}function ro(e){let t=2166136261;for(let i=0;e.length>i;i+=1)t^=e.charCodeAt(i),t=Math.imul(t,16777619);return Mp[(t>>>0)%Mp.length]}function oo(e){let t=e.trim();if(!t||!Number.isNaN(Number(t)))return NaN;let i=Wp.test(t)?t+"-01":t;if(i===t&&10>t.length)return NaN;let r=Date.parse(i);return Number.isFinite(r)?r:NaN}function ao(e){return e instanceof Date?e.getTime():"string"==typeof e?oo(e):+e}function no(e){return new Set(Array.isArray(e)?e:[e])}function lo(e,t="ease-out-cubic"){return"linear"===t?e:1-Math.pow(1-e,3)}function so(e,t){return Math.min((e-t.startTime)/t.duration,1)}function co(e,t,i){return e+(t-e)*i}function uo(){return"u">typeof performance?performance.now():Date.now()}function ho(e,t,i){if(1>=i)return 1;let r=i-1;return function(e){let t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||0>=e.extent)return 1;let i=Math.max(0,e.age);if("step"===e.type)return(e.threshold??.5*e.extent)>i?1:t;if("exponential"===e.type){let r=e.halfLife??e.extent/2;return t+Math.pow(.5,i/(r>0?r:e.extent/2))*(1-t)}return t+Math.max(0,Math.min(1,1-i/e.extent))*(1-t)}({age:r-t,extent:r,type:e.type,halfLife:e.halfLife??i/2,threshold:e.stepThreshold??.5*i,minOpacity:e.minOpacity??.1})}function fo(e){let t=new Map;for(let i=0;e.length>i;i++)t.set(e[i],i);return t}function po(e,t,i){let r=e.duration??500,o=i-t;return r>o?1-o/r:0}function yo(e,t,i,r){let o=!1;return t>0?(e._pulseIntensity!==t&&(e._pulseIntensity=t,o=!0),e._pulseColor!==i&&(e._pulseColor=i,o=!0),e._pulseGlowRadius!==r&&(e._pulseGlowRadius=r,o=!0),o):(0!==e._pulseIntensity&&(e._pulseIntensity=0,o=!0),void 0!==e._pulseColor&&(e._pulseColor=void 0,o=!0),void 0!==e._pulseGlowRadius&&(e._pulseGlowRadius=void 0,o=!0),o)}function go(e,t,i=("u">typeof performance?performance.now():Date.now())){if(!t||0===t.size)return!1;let r=e.duration??500,o=t.peek();return null!=o&&r>i-o}function mo(e,t,i){if(t._transitionKey)return t._transitionKey;switch(t.type){case"point":if(t.pointId)return"p:"+t.pointId;if("streaming"===e.runtimeMode&&t.datum){let i=e.getX(t.datum),r=e.getY(t.datum);if(e.getCategory)return`p:${e.getCategory(t.datum)}:${i}:${r}`;if(null!=i&&null!=r)return`p:${i}:${r}`}return"p:"+i;case"glyph":return t.pointId?"g:"+t.pointId:"g:"+i;case"rect":return`r:${t.group||""}:${t.datum?.binStart??t.datum?.category??i}`;case"heatcell":return`h:${t.x}_${t.y}`;case"candlestick":return null==t.datum?"c:"+i:"c:"+e.getX(t.datum);case"line":return"l:"+(t.group||"_default");case"area":return"a:"+(t.group||"_default");default:return null}}function xo(e){return e?null!=e.opacity?e.opacity:null!=e.fillOpacity?e.fillOpacity:1:1}function bo(e){jp[e.chartType]=e}function vo(e){if("production"===process.env.NODE_ENV)return;let{label:t,nodes:i,overlays:r,warned:o}=e;wo(r)&&0===i.length&&ko(o,"overlay-only",`[semiotic] ${t} 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.`),i.length>0&&i.every(e=>null==e.datum)&&ko(o,"null-datums",`[semiotic] ${t} 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 wo(e){return null!=e&&!1!==e&&""!==e&&(!Array.isArray(e)||e.some(wo))}function ko(e,t,i){e.has(t)||(e.add(t),console.warn(i))}function Ao(e){try{return{kind:"success",result:e.run()}}catch(t){let i=e.hasPreviousResult,r=function(e,t,i,r){let o=function(e){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Custom layout threw."};if("string"==typeof e)return{name:"Error",message:e};if(null==e)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:e+""}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}(t),a="network"===e?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:e,source:a,message:`Semiotic ${e} ${a} failed: ${o.message}`,error:o,recovery:i?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:i,affectedRevision:r}}(e.family,t,i,e.revision);"production"!==process.env.NODE_ENV&&console.error(`[semiotic] ${e.logLabel} threw:`,t);try{e.onLayoutError?.(r)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return{kind:"failure",diagnostic:r,preservedLastGoodScene:i}}}function So(e,t){let i="function"==typeof e?e:i=>i[e||t];return e=>{let t=i(e);return null==t?NaN:+t}}function Mo(e){let t=[],i=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode,r=So(i&&e.valueAccessor||e.yAccessor,i?"value":"y");if(e.boundsAccessor){let i=Xc(e.boundsAccessor,"bounds");t.push({kind:"bounds",getTop:e=>{let t=r(e);if(!Number.isFinite(t))return NaN;let o=i(e);return Number.isFinite(o)&&0!==o?t+o:t},getBottom:e=>{let t=r(e);if(!Number.isFinite(t))return NaN;let o=i(e);return Number.isFinite(o)&&0!==o?t-o:t},style:e.boundsStyle,perSeries:!0,interactive:!1})}if(e.band){let i=Array.isArray(e.band)?e.band:[e.band];for(let e of i)t.push({kind:"band",getTop:So(e.y1Accessor,"y1"),getBottom:So(e.y0Accessor,"y0"),style:e.style,perSeries:!1!==e.perSeries,interactive:!0===e.interactive})}return t}function _o(e,t,i,r,o,a=!1){let n=new Map;for(let l of e){let e=t(l),s=i(l);if(null==e||null==s||Number.isNaN(e)||Number.isNaN(s))continue;let c=Math.floor(e/r)*r,u=n.get(c);if(u||(u={start:c,end:c+r,total:0,categories:new Map,...a?{rows:[],categoryRows:new Map}:{}},n.set(c,u)),u.total+=s,u.rows?.push(l),o){let e=o(l);if(u.categories.set(e,(u.categories.get(e)||0)+s),u.categoryRows){let t=u.categoryRows.get(e);t||(t=[],u.categoryRows.set(e,t)),t.push(l)}}}return n}function Po(e,t,i,r,o){let a=[];for(let n of e){let e=i(n),l=r(n),s=o?o(n):0;if(!Number.isFinite(e)||!Number.isFinite(l)||!Number.isFinite(s))continue;let c=t.x(e),u=t.y(l),d=o?t.y(s):0;!Number.isFinite(c)||!Number.isFinite(u)||!Number.isFinite(d)||a.push({x:c,y:u,bottom:d,raw:l,datum:n})}a.sort((e,t)=>e.x-t.x);let n=Array(a.length),l=o?Array(a.length):[],s=Array(a.length),c=Array(a.length);for(let e=0;a.length>e;e++){let t=a[e];n[e]=[t.x,t.y],o&&(l[e]=[t.x,t.bottom]),s[e]=t.raw,c[e]=t.datum}return{topPath:n,bottomPath:l,rawValues:s,datum:c}}function Lo(e,t,i,r,o,a){let{topPath:n,rawValues:l,datum:s}=Po(e,t,i,r);return{type:"line",path:n,rawValues:l,style:o,datum:s,group:a}}function $o(e,t,i,r,o,a,n,l){return{type:"area",...Po(e,t,i,r,l??(()=>o)),style:a,group:n}}function To(e,t,i,r){let o=new Map;if("silhouette"===r)for(let r of e){let e=0;for(let o of t)e+=i(o,r)||0;o.set(r,-e/2)}else if("wiggle"===r){e.length>0&&o.set(e[0],0);for(let r=1;e.length>r;r++){let a=e[r-1],n=e[r],l=0,s=0,c=0;for(let e of t){let t=i(e,n)||0;l+=(2*c+t)*(t-(i(e,a)||0)),s+=t,c+=t}let u=o.get(a)??0;o.set(n,u-(s>0?l/(2*s):0))}if(e.length>0){let r=0;for(let a of e){let e=0;for(let r of t)e+=i(r,a)||0;r+=(o.get(a)??0)+e/2}let a=r/e.length;for(let t of e)o.set(t,(o.get(t)??0)-a)}}else for(let t of e)o.set(t,0);return o}function Ro(e,t,i,r,o,a,n){let l=i(e),s=r(e);if(!Number.isFinite(l)||!Number.isFinite(s))return null;let c={type:"point",x:t.x(l),y:t.y(s),r:o,style:a,datum:e};return void 0!==n&&(c.pointId=n),c}function Co(e,t,i,r,o,a,n,l){let s=i(e),c=r(e);if(!Number.isFinite(s)||!Number.isFinite(c))return null;let u={type:"symbol",x:t.x(s),y:t.y(c),size:o,symbolType:a,style:n,datum:e};return void 0!==l&&(u.pointId=l),u}function Io(e,t,i,r,o,a,n){return{type:"rect",x:e,y:t,w:i,h:r,style:o,datum:a,group:n}}function Do(e,t,i,r,o,a,n){let l={type:"heatcell",x:e,y:t,w:i,h:r,fill:o,datum:a};return void 0!==n?.value&&(l.value=n.value),n?.showValues&&(l.showValues=!0,n.valueFormat&&(l.valueFormat=n.valueFormat)),l}function zo(e,t){return t?[t[0]??e[0],t[1]??e[1]]:e}function Oo(e,t,i){if("log"===e){let e=[Math.max(t[0],1e-6),Math.max(t[1],1e-6)];return Gp().domain(e).range(i).clamp(!0)}return"symlog"===e?Vp().domain(t).range(i):"time"===e?Hp().domain([new Date(t[0]),new Date(t[1])]).range(i):Xp().domain(t).range(i)}function Fo(e,t){return e&&"object"==typeof e&&!Array.isArray(e)?X(e,t):void 0}function No(e,t,i){e.capacity>=t||(e.resize(t),i&&t>i.capacity&&i.resize(t))}function Eo(e,t){let i=new Np(e.capacity);return e.forEach(()=>i.push(t)),i}function Wo(e,t,i,r){let o=e.push(t);return i&&i.push(r),o}function jo(e,t,i){if(!t||0===t.size)return;let r=new Set;if(e.forEach((e,t)=>{i(e)&&r.add(t)}),0===r.size)return;let o=t.toArray();t.clear();for(let e=0;o.length>e;e++)r.has(e)||t.push(o[e])}function Bo(){return this.updateResults.last}function Yo(){return this.updateResults.last}function Xo(e){return this.updateResults.subscribe(e)}function Go(e){this.config.layoutSelection=e}function Vo(){qp.set(this,!0)}function Ho(){let e=!0===qp.get(this);return qp.delete(this),e}function qo(e){Object.assign(e.prototype,{getLastUpdateResult:Bo,getUpdateSnapshot:Yo,subscribeUpdateResult:Xo,setLayoutSelection:Go,markStylePaintPending:Vo,consumeStylePaintPending:Ho})}function Uo(e,t,i,r){return"function"==typeof t.style?t.style(r||{},i):t.style&&"object"==typeof t.style?t.style:e.resolveBoundsStyle(i,r)}function Zo(e,t,i,r){if(!e.scales)return null;let{topPath:o,bottomPath:a,datum:n}=Po(t,e.scales,e.getX,r.getTop,r.getBottom);return 2>o.length?null:{type:"area",topPath:o,bottomPath:a,...e.config.curve&&"linear"!==e.config.curve&&{curve:e.config.curve},style:Uo(e,r,i,Se(t)),datum:n,group:i,interactive:r.interactive}}function Ko(e){let t=[],i=[];if(!e)return{perSeries:t,aggregate:i};for(let r of e)r.perSeries?t.push(r):i.push(r);return{perSeries:t,aggregate:i}}function Qo(e,t,i){let r=[];for(let o of i){let i=Zo(e,t,"__ribbon_aggregate",o);i&&r.push(i)}return r}function Jo(e,t,i,r){let o=[];for(let a of r){let r=Zo(e,t,i,a);r&&o.push(r)}return o}function ea(e,t,i,r){if(!e.config.pointStyle)return;let o=r??e.getY;for(let r of t){let t=e.resolveGroupColor(r.key);for(let a of r.data){let r=e.config.pointStyle(a);!r.fill&&t&&(r={...r,fill:t});let n=r.r??3,l=e.getPointId?e.getPointId(a)+"":void 0,s=Ro(a,e.scales,e.getX,o,n,r,l);s&&i.push(s)}}}function ta(e){return"threshold"===e.type&&"string"==typeof e.color&&"number"==typeof e.value}function ia(e){return!(!e._pulseIntensity||0>=e._pulseIntensity)}function ra(e,t,i=.3){ia(t)&&(e.globalAlpha=t._pulseIntensity*i,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.fillRect(t.x,t.y,t.w,t.h))}function oa(e,t,i,r=.35){ia(t)&&(e.globalAlpha=t._pulseIntensity*r,e.fillStyle=t._pulseColor||"rgba(255,255,255,0.6)",i?e.fill(i):e.fill())}function aa(e,t,i){let r=i;for(let i of t)"lesser"===i.thresholdType?i.value>e&&(r=i.color):e>i.value&&(r=i.color);return r}function na(e,t,i,r){if(2>e.length||t.length!==e.length||0===i.length)return[];let o=[],a=(e,t,i)=>{let r=o[o.length-1];r?.color===e?r.path.push(i):o.push({color:e,path:[t,i]})};for(let o=1;e.length>o;o++){let[n,l]=e[o-1],[s,c]=e[o],u=t[o-1],d=t[o]-u,h=[0,...0===d?[]:i.map(({value:e})=>(e-u)/d).filter(e=>e>0&&1>e&&Number.isFinite(e)).sort((e,t)=>e-t).filter((e,t,i)=>0===t||e!==i[t-1]),1];for(let e=1;h.length>e;e++){let t=h[e-1],o=h[e];a(aa(u+d*((t+o)/2),i,r),[n+(s-n)*t,l+(c-l)*t],[n+(s-n)*o,l+(c-l)*o])}}return o}function la(e,t){let i=Rr(t.curve);if(!i||2>t.topPath.length||2>t.bottomPath.length){e.beginPath(),e.moveTo(t.topPath[0][0],t.topPath[0][1]);for(let i=1;t.topPath.length>i;i++)e.lineTo(t.topPath[i][0],t.topPath[i][1]);for(let i=t.bottomPath.length-1;i>=0;i--)e.lineTo(t.bottomPath[i][0],t.bottomPath[i][1]);e.closePath()}else{let r=hy().x(e=>e[0]).y0((e,i)=>t.bottomPath[i][1]).y1(e=>e[1]).curve(i).context(e);e.beginPath(),r(t.topPath)}}function sa(e,t){let i=Rr(t.curve);if(e.beginPath(),i)fy().x(e=>e[0]).y(e=>e[1]).curve(i).context(e)(t.topPath);else{e.moveTo(t.topPath[0][0],t.topPath[0][1]);for(let i=1;t.topPath.length>i;i++)e.lineTo(t.topPath[i][0],t.topPath[i][1])}}function ca(e,t,i,r,o,a){if(2>t.length)return;let n=[0];for(let e=1;t.length>e;e++){let i=t[e][0]-t[e-1][0],r=t[e][1]-t[e-1][1];n.push(n[e-1]+Math.sqrt(i*i+r*r))}let l=n[n.length-1];if(0===l)return;let s=Math.min(.2*l,40);e.strokeStyle=i,e.lineWidth=r,e.lineCap=a;for(let i=0;t.length-1>i;i++){let r=(n[i]+n[i+1])/2,a=o;s>r&&(a*=r/s),s>l-r&&(a*=(l-r)/s),e.globalAlpha=Math.max(0,a),e.beginPath(),e.moveTo(t[i][0],t[i][1]),e.lineTo(t[i+1][0],t[i+1][1]),e.stroke()}}function ua(e){return ee(e)}function da(e,t){let i=[],r="bubble"===e.config.chartType?10:5,o=e.config.sizeRange||[3,15],a=null;if(e.getSize&&!e.config.pointStyle){let i=t.map(t=>e.getSize(t)).filter(e=>null!=e&&!Number.isNaN(e));if(i.length>0){let e=1/0,t=-1/0;for(let r of i)e>r&&(e=r),r>t&&(t=r);a=i=>e===t?(o[0]+o[1])/2:o[0]+(i-e)/(t-e)*(o[1]-o[0])}}let n=e.getColor?e.resolveColorMap(t):null,l=e.config.themeSemantic?.primary||"#4e79a7",s=e.getSymbol,c=s?zu(s,e.config.symbolMap):null;for(let o of t){let t=e.config.pointStyle?e.config.pointStyle(o):{fill:l,opacity:.8},s=t.r||r;if(a&&e.getSize){let t=e.getSize(o);null!=t&&!Number.isNaN(t)&&(s=a(t))}if(n&&e.getColor&&!t.fill){let i=e.getColor(o);i&&n.has(i)&&(t={...t,fill:n.get(i)})}let u=e.getPointId?e.getPointId(o)+"":void 0;if(c){let r=c(o),a=Co(o,e.scales,e.getX,e.getY,Math.PI*s*s,r,t,u);a&&i.push(a)}else{let r=Ro(o,e.scales,e.getX,e.getY,s,t,u);r&&i.push(r)}}return i}function ha(e,t,i,r,o,a){if(0>=t.size)return;let n=function(e,t,i){try{if(i)return $u(i);let r=`${e??"circle"}:${t}`,o=ky.get(r);return o||(o=new Path2D(ed(e,t)),ky.size>256&&ky.clear(),ky.set(r,o)),o}catch{return null}}(t.symbolType,t.size,t.path);if(!n)return;e.save(),e.translate(i,r),t.rotation&&e.rotate(t.rotation);let l=(t.style.opacity??1)*(t._decayOpacity??1);t.style.fill&&(e.globalAlpha=o*l*(t.style.fillOpacity??1),e.fillStyle=Cr(e,t.style.fill,a),e.fill(n)),t.style.stroke&&"none"!==t.style.stroke&&(e.globalAlpha=o*l,e.strokeStyle=tu(e,t.style.stroke)||t.style.stroke,e.lineWidth=t.style.strokeWidth??1,e.stroke(n)),e.restore()}function fa(e,t,i){return t===i?128:Math.min(Math.floor(255*(e-t)/(i-t)+.5),255)}function pa(e){let t=Object.prototype.hasOwnProperty.call(Id,e)?e:"blues",i=Ly.get(t);if(i)return i;i=Array(Py);let r=j(t);for(let e=0;Py>e;e++)i[e]=r(e/255);return Ly.set(t,i),i}function ya(e,t,i){let r=i.config.areaStyle?.(t);return r&&("string"==typeof r.fill&&(e.fill=r.fill),e.style=r),e}function ga(e,t,i){let r=Math.max(1,Math.floor(e.config.heatmapXBins??20)),o=Math.max(1,Math.floor(e.config.heatmapYBins??20)),a=e.config.heatmapAggregation??"count",n=Xc(e.config.valueAccessor,"value");if(!e.scales||0===t.length)return[];let[l,s]=e.scales.x.domain(),[c,u]=e.scales.y.domain(),d=(s-l||1)/r,h=(u-c||1)/o,f=r*o;if(f>1e6)return[];let p=new Int32Array(f),y=new Float64Array(f),g=e.config.trackHoverRows||Me(e.config.areaStyle)?new Map:void 0;for(let i=0;t.length>i;i++){let a=t[i],s=e.getX(a),u=e.getY(a);if(!isFinite(s)||!isFinite(u))continue;let f=Math.min(Math.floor((s-l)/d),r-1),m=Math.min(Math.floor((u-c)/h),o-1);if(0>f||0>m)continue;let x=m*r+f;p[x]++;let b=n(a);if(y[x]+=isFinite(b)?b:0,g){let e=g.get(x);e||(e=[],g.set(x,e)),e.push(a)}}let m=1/0,x=-1/0;for(let e=0;f>e;e++){if(0===p[e])continue;let t;switch(a){case"sum":t=y[e];break;case"mean":t=y[e]/p[e];break;default:t=p[e]}m>t&&(m=t),t>x&&(x=t)}if(!isFinite(m))return[];let b=e.config.heatmapColorScale,v=b?void 0:pa("string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues"),w=i.width/r,k=i.height/o,A=e.config.showValues,S=e.config.heatmapValueFormat,M=[];for(let t=0;o>t;t++){let i=t*r;for(let n=0;r>n;n++){let r,s=i+n;if(0===p[s])continue;switch(a){case"sum":r=y[s];break;case"mean":r=y[s]/p[s];break;default:r=p[s]}let u=fa(r,m,x),f=b?b(r):v[u],_=A?{value:r,showValues:!0,valueFormat:S}:{value:r},P=we({xi:n,yi:t,value:r,count:p[s],sum:y[s],xCenter:l+(n+.5)*d,yCenter:c+(t+.5)*h,agg:a},g?.get(s));M.push(ya(Do(n*w,(o-1-t)*k,w,k,f,P,_),P,e))}}return M}function ma(e,t){let[i,r,o]=Tr(e,t);return.299*i+.587*r+.114*o>128?"#000":"#fff"}function xa(e){return Number.isInteger(e)?e+"":100>Math.abs(e)?1>Math.abs(e)?e.toPrecision(3):e.toFixed(1):e.toFixed(0)}function ba(e){return(e.tl??0)>0||(e.tr??0)>0||(e.br??0)>0||(e.bl??0)>0}function va(e){let t=e.cornerRadii;if(!t)return{tl:0,tr:0,br:0,bl:0};let i=Math.min(e.w,e.h)/2,r=e=>Math.max(0,Math.min(e??0,i));return{tl:r(t.tl),tr:r(t.tr),br:r(t.br),bl:r(t.bl)}}function wa(e,t){let{x:i,y:r,w:o,h:a}=t,{tl:n,tr:l,br:s,bl:c}=va(t);e.beginPath(),e.moveTo(i+n,r),e.lineTo(i+o-l,r),l>0&&e.arcTo(i+o,r,i+o,r+l,l),e.lineTo(i+o,r+a-s),s>0&&e.arcTo(i+o,r+a,i+o-s,r+a,s),e.lineTo(i+c,r+a),c>0&&e.arcTo(i,r+a,i,r+a-c,c),e.lineTo(i,r+n),n>0&&e.arcTo(i,r,i+n,r,n),e.closePath()}function ka(e,t){let i=Cr(e,t.style.fill,tu(e,"var(--semiotic-primary, #007bff)")),r=function(e){switch(e.roundedEdge){case"bottom":return{x0:e.x,y0:e.y+e.h,x1:e.x,y1:e.y};case"right":return{x0:e.x+e.w,y0:e.y,x1:e.x,y1:e.y};case"left":return{x0:e.x,y0:e.y,x1:e.x+e.w,y1:e.y};default:return{x0:e.x,y0:e.y,x1:e.x,y1:e.y+e.h}}}(t);return(t.fillGradient&&"string"==typeof i?Dr(e,t.fillGradient,i,r.x0,r.y0,r.x1,r.y1):null)||i}function Aa(e,t){if(!t.style.stroke||"none"===t.style.stroke)return!1;let i=t.style.strokeWidth??1;return i>0&&(e.strokeStyle=tu(e,t.style.stroke)||t.style.stroke,e.lineWidth=i,!0)}function Sa(e,t){let i=t.style.icon,r=t.style.iconPadding||2,o=Math.min(t.w,t.h)-r;if(0>=o)return;let a=t.h>t.w;if(e.save(),e.beginPath(),e.rect(t.x,t.y,t.w,t.h),e.clip(),a){let a=o+r,n=t.x+(t.w-o)/2;for(let r=t.y+t.h-o;r>=t.y-o;r-=a)e.drawImage(i,n,r,o,o)}else{let a=o+r,n=t.y+(t.h-o)/2;for(let r=t.x;t.x+t.w>r;r+=a)e.drawImage(i,r,n,o,o)}e.restore()}function Ma(e,t,i,r,o){if(0>=t.size)return;let a=t.glyph;if(!a||!a.parts?.length)return;let n=Cu(a,t.size);if(0>=n.scale)return;let l=(t.style.opacity??1)*(t._decayOpacity??1);if(0>=l)return;let s=t=>{let i=Cr(e,t,t);return"string"==typeof i?i:t},c=t.color??("string"==typeof t.style.fill?t.style.fill:void 0);e.save(),e.translate(i,r),t.rotation&&e.rotate(t.rotation),e.translate(n.offsetX,n.offsetY),e.scale(n.scale,n.scale),e.globalAlpha=o*l*(t.style.fillOpacity??1);let u=Tu(a,t.fraction??1,t.fractionStart??0,t.fractionDirection??"horizontal");u&&t.ghostColor&&Pu(e,a,c,t.accent,t.ghostColor,s),u&&(e.beginPath(),e.rect(u.x,u.y,u.width,u.height),e.clip()),Pu(e,a,c,t.accent,void 0,s),e.restore()}function _a(){bo(xy),bo(by),bo(vy),bo(wy),bo(My),bo(_y),bo(Ty),bo(Cy),bo(Iy),bo(zy),bo(Fy),bo(Ny)}function Pa(e){let t=e.parts.filter(e=>null!=e),i={};for(let e of t)for(let[t,r]of Object.entries(e.markCountByType))i[t]=(i[t]??0)+r;for(let[t,r]of Object.entries(e.additionalMarkCountByType??{}))r>0&&(i[t]=(i[t]??0)+r);let r=Object.values(i).reduce((e,t)=>e+t,0),o=0===r,a=Array.from(new Set([...t.flatMap(e=>e.warnings),...e.extraWarnings??[],...o?["EMPTY_SCENE"]:[]])),n="string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${r} marks`;return{component:"",frameType:e.frameType,status:o?"empty":"ok",empty:o,markCount:r,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:t.reduce((e,t)=>e+t.annotationCount,0),ariaLabel:n,warnings:a,semanticStatus:"not-assessed",semanticDiagnostics:[]}}function La(e){let t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function $a(e){if(!e||2>e.length)return;let t=La(e[0]),i=La(e[e.length-1]);return null!==t&&null!==i?[t,i]:void 0}function Ta(e){let{count:t,byType:i}=function(e){let t={};for(let i of e){let e="string"==typeof i?.type&&i.type.length>0?i.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}(e.marks),r=0===t,o=[...e.extraWarnings??[]];r&&!o.includes("EMPTY_SCENE")&&o.push("EMPTY_SCENE"),e.annotationRender&&e.annotationRender.unrenderedCount>0&&!o.includes("UNRENDERED_ANNOTATIONS")&&o.push("UNRENDERED_ANNOTATIONS");let a=Array.isArray(e.annotations)?e.annotations.length:0,n=e.margin,l=n?{x:n.left,y:n.top,width:e.width-n.left-n.right,height:e.height-n.top-n.bottom}:void 0;return{component:"",frameType:e.frameType,status:r?"empty":"ok",empty:r,markCount:t,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:e.annotationRender?.renderedCount??a,...e.annotationRender?{annotationInputCount:e.annotationRender.inputCount,unrenderedAnnotationCount:e.annotationRender.unrenderedCount,...e.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:e.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:"string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${t} marks`,warnings:o,semanticStatus:"not-assessed",semanticDiagnostics:[],...n?{margin:n}:{},...l?{plot:l}:{}}}function Ra(e,t="#4e79a7"){return ai(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function Ca(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"s_"+t:t}function Ia(e,t,i,r){let o=e.glyph;if(!o?.parts?.length||0>=e.size)return null;let a=Cu(o,e.size);if(0>=a.scale)return null;let n=`translate(${t},${i})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${a.offsetX},${a.offsetY}) scale(${a.scale})`,l=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),s=Tu(o,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),c=s?Ca(r+"-clip"):void 0,u=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),d=t=>o.parts.map((i,r)=>{let o=t?"none"===i.fill?void 0:t:Uu(i.fill,l,e.accent),a=t?i.stroke&&"none"!==i.stroke?t:void 0:Uu(i.stroke??"none",l,e.accent);return o||a?Yy("path",{d:i.d,fill:o??"none",stroke:a,strokeWidth:a?i.strokeWidth??1:void 0,strokeLinecap:i.strokeLinecap,strokeLinejoin:i.strokeLinejoin,opacity:i.opacity},r):null});return Xy("g",{transform:n,opacity:1===u?void 0:u,children:[s&&c&&Yy("clipPath",{id:c,children:Yy("rect",{x:s.x,y:s.y,width:s.width,height:s.height})}),s&&e.ghostColor?Yy("g",{children:d(e.ghostColor)}):null,s&&c?Yy("g",{clipPath:`url(#${c})`,children:d()}):d()]},r)}function Da(e,t){let i=e.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity))).map(e=>({offset:Math.max(0,Math.min(1,e.offset)),color:e.color??t,opacity:null==e.opacity?void 0:Math.max(0,Math.min(1,e.opacity))}));return 2>i.length?null:i.map((e,t)=>Yy("stop",{offset:e.offset,stopColor:e.color,stopOpacity:e.opacity},t))}function za(e,t,i){let r=ed(e.symbolType,e.size,e.path);return Yy("path",{d:r,transform:e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`,fill:e.style.fill?Ra(e.style.fill):"none",fillOpacity:e.style.fillOpacity,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},`${i??""}symbol-${t}`)}function Oa(e,t,i){let r="point"===e.type,o=r?"circle":"rect",a=r?{cx:e.x,cy:e.y,r:e.r}:{x:e.x,y:e.y,width:e.w,height:e.h},n=`${i?i+"-":""}${r?"point":"xyrect"}-${t}-hatch`,l=ai(e.style.fill)?li(e.style.fill,n):void 0;return Xy(By.Fragment,{children:[l&&Yy("defs",{children:l}),By.createElement(o,{...a,fill:l?`url(#${n})`:Ra(e.style.fill),opacity:r?e.style.opacity??e.style.fillOpacity??.8:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},`${e.type}-${t}`)}function Fa(e){if(!1!==e?.interactive)return e?.style?.cursor}function Na(e,t,i){let r=Fa(t);return r&&null!=e&&!1!==e?Hy("g",{style:{cursor:r},"data-semiotic-mark-cursor":r,children:e},i):e}function Ea(e,t,i,r){if(!e||2>t.length)return null;let o=Da(e.stops,r);return o?qy("linearGradient",{id:i,gradientUnits:"userSpaceOnUse",x1:t[0][0],y1:0,x2:t[t.length-1][0],y2:0,children:o}):null}function Wa(e,t,i,r=30){let o=function(e,t,i,r=30){switch(e.type){case"line":{let r=e;if(0===r.path.length)return null;let o=Rr(r.curve),a=o?jy().x(([e])=>e).y(([,e])=>e).curve(o)(r.path)??"":"M"+r.path.map(([e,t])=>`${e},${t}`).join("L"),n=Ca(`${i?i+"-":""}line-${t}-stroke-gradient`),l=Ea(r.strokeGradient,r.path,n,r.style.stroke||"#4e79a7");return Uy(Ey.Fragment,{children:[l&&qy("defs",{children:l}),qy("path",{d:a,fill:"none",stroke:l?`url(#${n})`:r.style.stroke||"#4e79a7",strokeWidth:r.style.strokeWidth??2,strokeDasharray:r.style.strokeDasharray,opacity:r.style.opacity})]},"line-"+t)}case"area":{let o=e;if(0===o.topPath.length)return null;let a=Rr(o.curve),n=!a||2>o.topPath.length||2>o.bottomPath.length?`M${o.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...o.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`:Wy().x(([e])=>e).y0((e,t)=>o.bottomPath[t][1]).y1(([,e])=>e).curve(a)(o.topPath)??"",l=`${i?i+"-":""}area-${t}-hatch`,s=ai(o.style.fill)?li(o.style.fill,l):void 0,c=Ca(`${i?i+"-":""}area-${t}-gradient`),u=function(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=1/0;for(let[,t]of e.topPath)r=Math.min(r,t);let o=-1/0;for(let[,t]of e.bottomPath)o=Math.max(o,t);if(!Number.isFinite(r)||!Number.isFinite(o))return null;let a=Da(i.stops,Ra(e.style.fill));return a?qy("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:0,y1:r,x2:0,y2:o,children:a}):null}(o,c),d=u?`url(#${c})`:s?`url(#${l})`:Ra(o.style.fill),h=u?void 0:o.style.fillOpacity??o.style.opacity??.7,f=a?jy().x(([e])=>e).y(([,e])=>e).curve(a)(o.topPath)??"":"M"+o.topPath.map(([e,t])=>`${e},${t}`).join("L"),p=Fa(o),y=p&&r>=0?qy("path",{d:f,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*r),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:p},"data-semiotic-mark-cursor":p,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${t}-cursor-target`):null,g=Ca(`${i?i+"-":""}area-${t}-stroke-gradient`),m=!(!o.colorThresholds?.length||!o.rawValues||o.rawValues.length!==o.topPath.length),x=!!o.strokeColorBands?.length,b=m||x?null:Ea(o.strokeGradient,o.topPath,g,o.style.stroke||"#4e79a7"),v=o.style.strokeWidth??2,w=1/0,k=-1/0;for(let[e]of o.topPath)w>e&&(w=e),e>k&&(k=e);let A=x?o.strokeColorBands.map((e,r)=>Ca(`${i?i+"-":""}area-${t}-stroke-band-${r}`)):[],S=x?o.strokeColorBands.map((e,t)=>qy("clipPath",{id:A[t],children:qy("rect",{x:w-v,y:e.y,width:k-w+2*v,height:e.height})},A[t])):null,M=o.style.stroke&&"none"!==o.style.stroke?x?o.strokeColorBands.map((e,i)=>qy("path",{d:f,fill:"none",stroke:e.color??Ra(o.style.stroke),strokeWidth:v,opacity:(o.style.opacity??1)*(e.opacity??1),clipPath:`url(#${A[i]})`},`area-${t}-stroke-band-${i}`)):m?na(o.topPath,o.rawValues,o.colorThresholds,Ra(o.style.stroke)).map((e,i)=>qy("path",{d:"M"+e.path.map(([e,t])=>`${e},${t}`).join("L"),fill:"none",stroke:e.color,strokeWidth:v,opacity:o.style.opacity},`area-${t}-threshold-${i}`)):qy("path",{d:f,fill:"none",stroke:b?`url(#${g})`:Ra(o.style.stroke),strokeWidth:v,opacity:o.style.opacity}):null;if(o.clipRect){let e=`${i?i+"-":""}area-clip-${t}`;return Uy("g",{children:[Uy("defs",{children:[u,!u&&s,b,S,qy("clipPath",{id:e,children:qy("rect",{x:o.clipRect.x,y:o.clipRect.y,width:o.clipRect.width,height:o.clipRect.height})})]}),Uy("g",{clipPath:`url(#${e})`,children:[qy("path",{d:n,fill:d,fillOpacity:h,opacity:u?o.style.opacity:void 0,stroke:"none"}),M,y]})]},"area-"+t)}return Uy(Ey.Fragment,{children:[(u||s||b||S)&&Uy("defs",{children:[u,!u&&s,b,S]}),qy("path",{d:n,fill:d,fillOpacity:h,opacity:u?o.style.opacity:void 0,stroke:"none"}),M,y]},"area-"+t)}case"point":case"rect":return Oa(e,t,i);case"symbol":return za(e,t);case"glyph":return Ia(e,e.x,e.y,`${i??""}glyph-${e.pointId??t}`);case"heatcell":{let i=e,r={x:i.x,y:i.y,width:i.w,height:i.h,fill:i.fill,stroke:i.style?.stroke,strokeWidth:i.style?.strokeWidth,...null!=i.style?.opacity&&{opacity:i.style.opacity}};if(i.showValues&&null!=i.value&&i.w>=20&&i.h>=20){let e=i.valueFormat?i.valueFormat(i.value):Number.isInteger(i.value)?i.value+"":100>Math.abs(i.value)?1>Math.abs(i.value)?i.value.toPrecision(3):i.value.toFixed(1):i.value.toFixed(0),[o,a,n]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(i.fill),l=.299*o+.587*a+.114*n>128?"#000":"#fff",s=Math.max(10,Math.min(16,.3*Math.min(i.w,i.h)));return Uy("g",{children:[qy("rect",{...r}),qy("text",{className:"semiotic-heatmap-value",x:i.x+i.w/2,y:i.y+i.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:l,fontSize:s+"px",fontFamily:"var(--semiotic-font-family, sans-serif)",children:e})]},"heatcell-"+t)}return qy("rect",{...r},"heatcell-"+t)}case"candlestick":{let r=e,o=`${i?i+"-":""}candle-${t}-hatch`,a=ai(r.style?.fill)?li(r.style.fill,o):void 0,n=a?`url(#${o})`:void 0,{fill:l,...s}=r.style??{};if(r.isRange){let e=r.dotRadius??Math.max(2,r.bodyWidth/2),i=n??r.wickColor;return Uy(Ey.Fragment,{children:[a&&qy("defs",{children:a}),Uy("g",{style:s,children:[qy("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth,opacity:r.style?.opacity}),qy("circle",{cx:r.x,cy:r.highY,r:e,fill:i,opacity:r.style?.opacity}),qy("circle",{cx:r.x,cy:r.lowY,r:e,fill:i,opacity:r.style?.opacity})]})]},"candle-"+t)}let c=Math.min(r.openY,r.closeY),u=Math.max(Math.abs(r.openY-r.closeY),1),d=r.isUp?r.upColor:r.downColor,h=n??d;return Uy(Ey.Fragment,{children:[a&&qy("defs",{children:a}),Uy("g",{style:s,children:[qy("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth,opacity:r.style?.opacity}),qy("rect",{x:r.x-r.bodyWidth/2,y:c,width:r.bodyWidth,height:u,fill:h,stroke:n?r.wickColor:d,strokeWidth:1,opacity:r.style?.opacity})]})]},"candle-"+t)}default:return null}}(e,t,i,r);return"area"===e.type?o:Na(o,e,"xy-cursor-"+t)}function ja(e){let{node:t,index:i,renderMode:r,fallback:o}=e,a=function(e,t){let i="function"==typeof e?e(t.datum??null,t):e;return(r=i)&&"object"==typeof r&&"string"==typeof r.id&&"function"==typeof r.cacheKey&&"function"==typeof r.drawCanvas&&"function"==typeof r.renderStaticSVG?i:void 0;var r}(r,t);if(!a)return{element:o(),renderedByBackend:!1};let n=a.renderStaticSVG({node:t,style:t.style??{},key:`${a.id}-${i}`});return null!=n?{element:Na(n,t,`${a.id}-${i}-cursor`),renderedByBackend:!0}:(function(e,t){if("u">typeof process&&"production"===process.env?.NODE_ENV)return;let i=`${e}:${t}`;Zy.has(i)||(Zy.add(i),console.warn(`[Semiotic] Render backend "${e}" does not support scene node "${t}"; using the built-in renderer.`))}(a.id,t.type??"unknown"),{element:o(),renderedByBackend:!1})}function Ba(e){let t=[];return e.nodes.forEach((i,r)=>{let o=ja({node:i,index:r,renderMode:e.renderMode,fallback:()=>e.fallback(i,r)});null!=o.element&&!1!==o.element&&t.push({node:i,index:r,...o})}),t}function Ya(e,t,i){if(t&&"object"==typeof t&&!Array.isArray(t)){let e=t;return t=>X(e,t)??"#999"}let r=Array.isArray(t)?t:i.colors.categorical.length>0?i.colors.categorical:vd;return Ky().domain(e).range(r)}function Xa(e,t,i){if(0===e.length)return;let r=Ya(e,t,i);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:r(e.label)})}]}}function Ga(e){return"left"===e?"start":"right"===e?"end":e??"start"}function Va(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function Ha(e){return e.typography.legendFontFamily??e.typography.fontFamily}function qa(e){return e.typography.legendFontWeight}function Ua(e,t,i,r){let o=Va(r);return t+i+Math.ceil(e.length*o*.58)}function Za(e){let{categories:t,theme:i,position:r="right",totalWidth:o,margin:a,legendLayout:n}=e,{swatchSize:l,labelGap:s,itemGap:c,rowHeight:u}=v(n),d=l+s,h="top"===r||"bottom"===r,f=Math.max(l,o-a.left-a.right),p=t.map(e=>Ua(e,l,s,i));if(h){let e=Math.max(l,n?.maxWidth??f),i=[],r=0,o=0;p.forEach((t,a)=>{let n=0===o?t:o+c+t;o>0&&n>e?(i.push({start:r,end:a,width:o}),r=a,o=t):o=n}),t.length>0&&i.push({start:r,end:t.length,width:o});let a=Ga(n?.align),s=[];return i.forEach((i,r)=>{let o="center"===a?Math.max(0,(e-i.width)/2):"end"===a?Math.max(0,e-i.width):0;for(let e=i.start;i.end>e;e++)s.push({category:t[e],width:p[e],x:o,y:r*u}),o+=p[e]+c}),{items:s,width:i.reduce((e,t)=>Math.max(e,t.width),0),height:i.length*u,swatchSize:l,labelOffset:d,swatchRadius:0}}let y=p.reduce((e,t)=>Math.max(e,t),0);return{items:t.map((e,t)=>({category:e,width:p[t],x:0,y:t*u})),width:y,height:t.length*u,swatchSize:l,labelOffset:d,swatchRadius:0}}function Ka(e,t){if(!t||!e||0===e.length)return[];let i="function"==typeof t?t:e=>e[t],r=new Set;for(let t of e){let e=i(t);null!=e&&r.add(e+"")}return Array.from(r)}function Qa(e){let{x:t,y:i,text:r,fill:o,fontSize:a=12,fontWeight:n,fontFamily:l,textAnchor:s="start",dominantBaseline:c,background:u,className:d}=e,h=function(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{...e,type:e.type??"halo"}}(u),f=e=>eg("text",{x:t,y:i,textAnchor:s,dominantBaseline:c,fill:o,fontSize:a,fontWeight:n,fontFamily:l,className:d,...e?{style:{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}}:{},children:r});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??ig,strokeWidth:h.haloWidth??3});let p,y,g=h.padding??{x:6,y:3},m="number"==typeof g?g:g.x,x="number"==typeof g?g:g.y,b=function(e,t){return(e+"").length*t*.6}(r,a),v=a+2*x;return p="middle"===s?t-b/2-m:"end"===s?t-b-m:t-m,y="middle"===c||"central"===c?i-v/2:"hanging"===c||"text-before-edge"===c?i-x:i-.8*a-x,tg("g",{className:d,children:[eg("rect",{x:p,y:y,width:b+2*m,height:v,rx:h.radius??3,ry:h.radius??3,fill:h.fill??ig,fillOpacity:h.opacity??.85,stroke:h.stroke,strokeWidth:h.strokeWidth}),f()]})}function Ja(e,t,i){if(!e)return null;let r="object"==typeof e?e:{};return rg("circle",{className:"semiotic-threshold-end-cap",cx:t[0],cy:t[1],r:Math.max(0,r.radius??4),fill:r.fill??i})}function en({ann:e,position:t,vertical:i,width:r,height:o,color:a,fontSize:n=12,fontFamily:l,bold:s,background:c,dash:u="6,3",labelGap:d=4}){let h=e.labelPosition,f=t>.6*r,p=i?t+(f?-4:4):"left"===h?4:"center"===h?r/2:r-4,y=i?"bottom"===h?o-4:"center"===h?o/2:16:20>t?Math.min(o-4,t+16):t-d,g=i?f?"end":"start":"left"===h?"start":"center"===h?"middle":"end",m=i?[t,0]:[0,t],x=i?[t,o]:[r,t];return ag("g",{opacity:e.opacity,children:[og("line",{x1:m[0],y1:m[1],x2:x[0],y2:x[1],stroke:a,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||u}),Ja(e.endCap,m,a),e.label&&og(Qa,{x:p,y:y,text:e.label,textAnchor:g,fill:a,fontSize:n,fontFamily:l,fontWeight:s?"bold":void 0,background:c??e.labelBackground??"halo"})]})}function tn(e,t,i,r){return"curly"===e?r?`M0,0 C${.6*i},0 ${.4*i},${t/2} ${i},${t/2} C${.4*i},${t/2} ${.6*i},${t} 0,${t}`:`M0,0 C0,${.6*i} ${t/2},${.4*i} ${t/2},${i} C${t/2},${.4*i} ${t},${.6*i} ${t},0`:r?`M0,0 L${i},0 L${i},${t} L0,${t}`:`M0,0 L0,${i} L${t},${i} L${t},0`}function rn(e,t,i,r){if(!e)return ng("g",{className:"annotation-note"});let{label:o,title:a,orientation:n,align:l,wrap:s=120,noWrap:c}=e;if(!o&&!a)return ng("g",{className:"annotation-note"});let u=n;u||(u=Math.abs(t)>Math.abs(i)?"leftRight":"topBottom");let d="topBottom"===u,h="leftRight"===u,f=l;(!f||"dynamic"===f)&&(f=d?0>t?"right":"left":0>i?"bottom":"top");let p="start";d?"right"===f?p="end":"middle"===f&&(p="middle"):p=0>t?"end":"start";let y=e.useHTML||e.html,g=y?void 0:Ou(e),m=g?.lineHeight??16,x=g?.titleLines??(a?c?[a]:rd(a,s,8):[]),b=g?.labelLines??(o?c?[o]:rd(o,s,8):[]),v=x.length+b.length,w=h?"end"===p?-4:4:0,k=[],A=r||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";if(y)k.push(ng("foreignObject",{className:"annotation-note-html",x:"end"===p?w-s:"middle"===p?w-s/2:w,y:-m,width:s,height:Math.max(m,v*m+(a&&o?2:0))+m,style:{overflow:"visible"},children:lg("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:A,fontSize:"12px",lineHeight:m+"px",overflow:"visible",textAlign:"end"===p?"right":"middle"===p?"center":"left",whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[a&&ng("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:a}),o&&ng("div",{className:"annotation-note-label",children:o})]})},"annotation-note-html"));else for(let e of[!0,!1]){let t=e?x:b;if(0===t.length)continue;let i="annotation-note-"+(e?"title":"label");k.push(ng("text",{className:i,fill:A,textAnchor:p,fontWeight:e?g?.titleFontWeight??"bold":void 0,y:e?void 0:x.length*m,children:t.map((e,t)=>ng("tspan",{x:w,dy:0===t?0:m,children:e},t))},i))}let S=null;if((a||o)&&(0!==t||0!==i)){let e=d?g?g.width:Math.min(s,120):(x.length+b.length+(b.length>0?1:0))*m,t=d?p:f,i="end"===t||"bottom"===t?-e:"middle"===t?-e/2:0;S=ng("line",{className:"note-line",x1:d?i:0,x2:d?i+e:0,y1:d?0:i,y2:d?0:i+e,stroke:r||"var(--semiotic-text-secondary, currentColor)"})}let M=Math.max(0,v-1)*m,_=0;(d||h)&&(_=h&&"middle"===f?-(M+m+(b.length>0&&x.length>0?2:0))/2+m/2:0>i||h&&"bottom"===f?-(M+2):2+m);let P=0!==_?`translate(0,${_})`:void 0;return lg("g",{className:"annotation-note",transform:`translate(${t},${i})`,...g?.textProps,children:[ng("g",{className:"annotation-note-content",transform:P,children:k}),S]})}function on(e,t,i,r,o){let a=null,n=i||"var(--semiotic-text-secondary, currentColor)";switch(e){case"callout-circle":{let e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&(a=ng("circle",{r:e,fill:"none",stroke:n},"subject-circle"));break}case"callout-rect":{let e=t?.width||0,i=t?.height||0;(e>0||i>0)&&(a=ng("rect",{width:e,height:i,fill:"none",stroke:n},"subject-rect"));break}case"callout-custom":a=t?.custom;break;case"xy-threshold":{let e=r||0,i=o||0,l=0,s=0,c=0,u=0;if(void 0!==t?.x)l=s=(t.x||0)-e,c=(t.y1||0)-i,u=(t.y2||0)-i;else if(void 0!==t?.y)c=u=(t.y||0)-i,l=(t.x1||0)-e,s=(t.x2||0)-e;else if(void 0!==t?.x1||void 0!==t?.x2)l=(t.x1||0)-e,s=(t.x2||0)-e;else{if(void 0===t?.y1&&void 0===t?.y2)break;c=(t.y1||0)-i,u=(t.y2||0)-i}a=ng("line",{x1:l,y1:c,x2:s,y2:u,stroke:n,strokeDasharray:"5,5"},"threshold-line");break}case"bracket":{let e=t?.type||"curly",i=t?.width??t?.height;void 0!==i&&(a=ng("path",{d:tn(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:n},"bracket-path"));break}}return ng("g",{className:"annotation-subject",children:a})}function an(e,t,i,r,o,a){let n,l,s=0,c=0;if("callout-circle"!==o&&"label"!==o||!a?.radius){if("callout-rect"===o&&a){let i=a.width||0,r=a.height||0;if(i>0||r>0){let o=i/2,a=r/2,n=e-o,l=t-a;if(0!==n||0!==l){let e=Math.abs(n),t=Math.abs(l),u=i/2,d=r/2,h=e*d>t*u?u/e:d/t;s=o+n*h,c=a+l*h}}}else if("bracket"===o&&a){let e=a.width,t=a.height,i=a.depth||30;void 0!==e?(s=e/2,c=i):void 0!==t&&(s=i,c=t/2)}}else{let i=(a.radius||0)+(a.radiusPadding||0);if(i>0&&(0!==e||0!==t)){let r=Math.atan2(t,e);s=Math.cos(r)*i,c=Math.sin(r)*i}}let u=e-s,d=t-c,h=Math.hypot(u,d);if(h>.5){let o=r||"var(--semiotic-text-secondary, currentColor)",a="curve"===i?.type,f=Math.atan2(d,u);if(a){let r=(s+e)/2,a=(c+t)/2,l=-d/h,p=u/h,y=(i?.curve??.25)*h,g=r+l*y,m=a+p*y;n=ng("path",{className:"connector-curve",d:`M${s},${c}Q${g},${m} ${e},${t}`,fill:"none",stroke:o},"connector-line"),f=Math.atan2(m-c,g-s)}else n=ng("line",{x1:s,y1:c,x2:e,y2:t,stroke:o},"connector-line");if("arrow"===i?.end){let e=.2792526803190927;l=ng("path",{d:`M${s},${c}L${s+10*Math.cos(f+e)},${c+10*Math.sin(f+e)}L${s+10*Math.cos(f-e)},${c+10*Math.sin(f-e)}Z`,fill:o,stroke:"none"},"connector-arrow")}}return lg("g",{className:"annotation-connector",children:[n,l]})}function nn(e){let{x:t=0,y:i=0,dx:r,dy:o,nx:a,ny:n,note:l,connector:s,subject:c,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:y,events:g={},"data-testid":m}=e,x=Array.isArray(t)?t[0]??0:t,b=Array.isArray(i)?i[0]??0:i,v=Array.isArray(f)?f:[],w=r||0,k=o||0;null!=a&&(w=a-x),null!=n&&(k=n-b);let A="string"==typeof u?u:"label";if("bracket"===A&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;let e=c.depth||30;k=e+(0>e?-5:5)}else if(void 0!==c.height){let e=c.depth||30;w=e+(0>e?-5:5),k=c.height/2}return lg("g",{className:("annotation "+(h||"")).trim(),transform:`translate(${x},${b})`,"data-testid":m,...null!=p&&{opacity:p},...y&&{strokeDasharray:y},...g,children:[!v.includes("connector")&&an(w,k,s,d,A,c),!v.includes("subject")&&on(A,c,d,x,b),!v.includes("note")&&rn(l,w,k,d)]})}function ln(e){let{noteData:t}=e,{screenCoordinates:i}=t,r="string"==typeof t.type?t.type:"label",o=t.eventListeners||t.events||{};if(t.coordinates&&i){let e=t.nx||i[0][0]+(t.dx??0),o=t.ny||i[0][1]+(t.dy??0),a=i.map((i,a)=>{let n=Object.assign({},t,{note:0===a?t.note:{label:""},x:i[0],y:i[1],nx:e,ny:o});return ng(nn,{"data-testid":"semiotic-annotation",...n,type:r},"multi-annotation-"+a)});return ng("g",{children:a})}let a=t.note||{title:"none",label:t.label},n=`${a.label}-${a.title}-${t.i}`;return ng(nn,{"data-testid":"semiotic-annotation",events:o,...t,type:r},n)}function sn(e){return!0===e?._annotationDeferred}function cn(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function un(e){let t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function dn(e){return Math.max(.72,.95-.06*e)}function hn(e){let t=e.map((e,t)=>{return{p:e,i:t,emphasis:(i=e.annotation,"primary"===i?.emphasis||"secondary"===i?.emphasis?i.emphasis:null),confidence:un(e.annotation),readingOrder:null,rank:1};var i}),i=t.some(e=>null!=e.emphasis||null!=e.confidence),r=e.some(e=>sn(e.annotation)),o=e.some(e=>null!=cn(e.annotation)),a=e.some(e=>"layer"===cn(e.annotation));if(!i&&!r&&!o)return e.map(e=>e.node);let n=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);n.forEach((e,t)=>{e.readingOrder=t,e.rank=2-t/Math.max(1,n.length)});for(let e of t)e.emphasis&&(e.rank=cg[e.emphasis]);let l=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{let{p:t,i:i,emphasis:r,readingOrder:o}=e,a=sn(t.annotation),n=t.node;if("primary"===r||"secondary"===r||null!=o){let e=null==r&&null!=o;n=sg("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":"annotation-emphasis annotation-emphasis--"+r,..."secondary"===r?{opacity:.6,fontSize:"0.88em"}:{},...e?{opacity:dn(o),"data-annotation-reading-order":o}:{},children:t.node},"annotation-emphasis-"+i)}let l=cn(t.annotation);return l&&(n=sg("g",{className:"annotation-cohesion--"+l,children:n},"annotation-cohesion-"+i)),a&&(n=sg("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:n},"annotation-deferred-"+i)),n});return r&&l.unshift(sg("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")),a&&l.unshift(sg("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")),l}function fn(e,t,i,r){let o=function(e,t,i="#4e79a7"){if(ai(e)){let i=function(e,t){let i=2166136261,r=ni(t);for(let e=0;r.length>e;e++)i^=r.charCodeAt(e),i=Math.imul(i,16777619);return`${e}-hatch-${(i>>>0).toString(36)}`}(t,e);return{fill:`url(#${i})`,def:li(e,i)}}return e&&"string"==typeof e?{fill:e}:{fill:i}}(e.fill??e.color,t,r);return function(e,t,i,r){if(!e||"object"!=typeof e)return;let o=e;if(!Array.isArray(o.stops))return;let a=o.stops.flatMap(e=>{if(!e||"object"!=typeof e)return[];let{offset:t,color:i,opacity:o}=e;return"number"==typeof t&&Number.isFinite(t)?[{offset:Math.max(0,Math.min(1,t)),color:"string"==typeof i&&i?i:r,opacity:"number"==typeof o&&Number.isFinite(o)?Math.max(0,Math.min(1,o)):void 0}]:[]}).sort((e,t)=>e.offset-t.offset);if(!a.length)return;let n="horizontal"===o.direction?"horizontal":"vertical"===o.direction?"vertical":i,l=t+"-gradient";return{fill:`url(#${l})`,def:sf("linearGradient",{id:l,x1:0,y1:0,x2:"horizontal"===n?"100%":0,y2:"vertical"===n?"100%":0,children:a.map((e,t)=>sf("stop",{offset:100*e.offset+"%",stopColor:e.color,stopOpacity:e.opacity},`${e.offset}-${t}`))},l)}}(e.gradient,t,i,"string"==typeof e.fill&&e.fill?e.fill:"string"==typeof e.color&&e.color?e.color:r)??o}function pn(e,t,i){let r=e.position,o="string"==typeof r&&ug.has(r)?r:"bottom-left",a=o.endsWith("left")?"left":o.endsWith("right")?"right":"center",n=o.startsWith("top")?"top":o.startsWith("bottom")?"bottom":"middle",l="top"===n?0:"bottom"===n?i:i/2;return{x:("left"===a?0:"right"===a?t:t/2)+("number"==typeof e.dx&&Number.isFinite(e.dx)?e.dx:0),y:l+("number"==typeof e.dy&&Number.isFinite(e.dy)?e.dy:0),textAnchor:"start"===e.textAnchor||"middle"===e.textAnchor||"end"===e.textAnchor?e.textAnchor:"left"===a?"start":"right"===a?"end":"middle",dominantBaseline:"auto"===e.dominantBaseline||"middle"===e.dominantBaseline||"hanging"===e.dominantBaseline?e.dominantBaseline:"top"===n?"hanging":"bottom"===n?"auto":"middle"}}function yn(e,t,i,r){return{...pn(e,t,i),fill:e.fill??e.color??r.fill,fontSize:e.fontSize??r.fontSize,fontFamily:e.fontFamily??r.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,letterSpacing:e.letterSpacing,opacity:e.opacity,className:e.className,style:{pointerEvents:"none"}}}function gn({annotation:e,width:t,height:i,defaults:r=hg}){let o=e.label??e.text;return null==o?null:dg("text",{...yn(e,t,i,r),children:o})}function mn(e,t={}){let i=function(e){let t=e.provenance,i=e.id??e.stableId??t?.stableId;return null==i||""===i?void 0:i+""}(e);return{"data-semiotic-annotation-widget":"",...i?{"data-semiotic-annotation-id":i}:{},onClickCapture(r){let o=function(e){let t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}(r);t.onAnnotationActivate?.({annotation:e,annotationId:i,chartId:t.chartId,inputType:o}),i&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:i,inputType:o,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}function xn(e,t){return e.color||t.colors.annotation||t.colors.text}function bn(e,t,i){let r=e.labelBackground,o=t.colors.background,a=o&&"transparent"!==o?o:t.colors.surface||o;return void 0===r?"none"===i?"none":{type:"halo",fill:a}:!1===r||"none"===r?"none":!0===r||"halo"===r?{type:"halo",fill:a}:"box"===r?{type:"box",fill:a}:{fill:a,...r}}function vn(e,t,i){return null!=e.x&&t.x?t.x(e.x):i&&null!=e[i]&&t.x?t.x(e[i]):"number"==typeof e.x?e.x:null}function wn(e,t,i){return null!=e.y&&t.y?t.y(e.y):i&&null!=e[i]&&t.y?t.y(e[i]):"number"==typeof e.y?e.y:null}function kn(e){let{annotations:t}=e;if(!t||0===t.length)return e.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;let i=zc(t),r=e.scales.geoProjection,o=r?i.map(e=>{if(!Array.isArray(e.coordinates)||2>e.coordinates.length)return e;let t=r([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):i,a=!!r&&!e.scales.x&&!e.scales.y,n=e=>Number(e),l=e.scales.x??(a?n:void 0),s=e.scales.y??(a?n:void 0),c=e.projection?"horizontal"===e.projection?"horizontal":"vertical":void 0,u={scales:{..."vertical"===e.projection?{x:e.scales.o??l,y:e.scales.r??s,time:e.scales.o??l,value:e.scales.r??s,o:e.scales.o}:"horizontal"===e.projection?{x:e.scales.r??l,y:e.scales.o??s,time:e.scales.r??l,value:e.scales.o??s,o:e.scales.o}:{x:l,y:s,time:l,value:s,o:e.scales.o},...r?{geoProjection:r}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,pointNodes:e.pointNodes,frameType:e.frameType??(e.projection?"ordinal":r||e.scales.x||e.scales.y?"xy":"network"),...c?{projection:c}:{}},d=e.autoPlaceAnnotations?xu({annotations:o,context:u,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):o,h=function(e,t,i,r){let o=[];return e.forEach((e,a)=>{let n;n=i?i(e,a,r)??t(e,a,r):t(e,a,r),n&&o.push({node:n,annotation:e})}),{nodes:hn(o),renderedAnnotations:o.map(e=>e.annotation)}}(d,(t,i,r)=>function(e,t,i,r){let{scales:o,layout:a,theme:n,xAccessor:l,yAccessor:s}=i;switch(e.type){case"frame-text":return Lg(gn,{annotation:e,width:a.width,height:a.height,defaults:{fill:n.colors.text,fontSize:11,fontFamily:n.typography.fontFamily}},"ann-frame-text-"+t);case"y-threshold":{let r=e.value??e.y;if(null==r)return null;let l=xn(e,n),s=e.label,c=e.strokeDasharray||"6,4",u=e.strokeWidth??1.5;if("horizontal"===i.projection&&o.r){let i=o.r(r);return null==i?null:$g("g",{opacity:e.opacity,children:[Lg("line",{x1:i,y1:0,x2:i,y2:a.height,stroke:l,strokeWidth:u,strokeDasharray:c}),Ja(e.endCap,[i,0],l),s&&Lg(Qa,{x:i+4,y:Tg,textAnchor:"start",fontSize:n.typography.tickSize,fill:l,fontFamily:n.typography.fontFamily,text:s,background:bn(e,n,"halo")})]},"ann-ythresh-"+t)}let d=o.y?o.y(r):o.r?o.r(r):null;return null==d?null:Lg(en,{ann:e,position:d,vertical:!1,width:a.width,height:a.height,color:l,fontSize:n.typography.tickSize,fontFamily:n.typography.fontFamily,background:bn(e,n,"halo"),dash:"6,4",labelGap:6},"ann-ythresh-"+t)}case"x-threshold":{let r=e.value??e.x;if(null==r)return null;let l="horizontal"===i.projection&&o.r?o.r(r):o.x?o.x(r):null;if(null==l)return null;let s=xn(e,n);return Lg(en,{ann:e,position:l,vertical:!0,width:a.width,height:a.height,color:s,fontSize:n.typography.tickSize,fontFamily:n.typography.fontFamily,background:bn(e,n,"halo"),dash:"6,4"},"ann-xthresh-"+t)}case"band":{let i=o.y?.domain?.(),r=e.y0??i?.[0],l=e.y1??i?.[1],s=null!=r&&o.y?o.y(r):null,c=null!=l&&o.y?o.y(l):null;if(null==s||null==c)return null;let u=Math.min(s,c),d=Math.abs(c-s),h=fn(e,"ssr-band-"+t,"vertical",xn(e,n)),f=e.fillOpacity??.1;return $g("g",{opacity:e.opacity,children:[h.def&&Lg("defs",{children:h.def}),Lg("rect",{x:0,y:u,width:a.width,height:d,fill:h.fill,fillOpacity:f}),e.label&&Lg(Qa,{x:a.width-4,y:Math.max(u,0)+Tg,textAnchor:"end",fontSize:n.typography.tickSize,fill:e.color||xn(e,n),fontFamily:n.typography.fontFamily,fontWeight:"bold",text:e.label,background:bn(e,n,"halo")})]},"ann-band-"+t)}case"x-band":{let i=o.x?.domain?.(),r=e.x0??i?.[0],l=e.x1??i?.[1],s=null!=r&&o.x?o.x(r):null,c=null!=l&&o.x?o.x(l):null;if(null==s||null==c)return null;let u=Math.min(s,c),d=Math.abs(c-s),h=fn(e,"ssr-xband-"+t,"horizontal",xn(e,n)),f=e.fillOpacity??.1;return $g("g",{opacity:e.opacity,children:[h.def&&Lg("defs",{children:h.def}),Lg("rect",{x:u,y:0,width:d,height:a.height,fill:h.fill,fillOpacity:f}),e.label&&Lg(Qa,{x:u+4,y:Tg,textAnchor:"start",fontSize:n.typography.tickSize,fill:e.color||n.colors.primary||xn(e,n),fontFamily:n.typography.fontFamily,fontWeight:"bold",text:e.label,background:bn(e,n,"halo")})]},"ann-xband-"+t)}case"category-highlight":{if(null==e.category||!o.o)return null;let r=o.o(e.category+"");if(null==r)return null;let l=o.o.bandwidth?o.o.bandwidth():40,s=xn(e,n),c=e.opacity??.1,u=e.label;return $g("g","horizontal"===i.projection?{children:[Lg("rect",{x:0,y:r,width:a.width,height:l,fill:s,opacity:c}),u&&Lg(Qa,{x:12,y:r+l/2,dominantBaseline:"middle",fill:s,fontSize:n.typography.tickSize,fontWeight:"bold",fontFamily:n.typography.fontFamily,text:u,background:bn(e,n,"none")})]}:{children:[Lg("rect",{x:r,y:0,width:l,height:a.height,fill:s,opacity:c}),u&&Lg(Qa,{x:r+l/2,y:Tg,textAnchor:"middle",fill:s,fontSize:n.typography.tickSize,fontWeight:"bold",fontFamily:n.typography.fontFamily,text:u,background:bn(e,n,"none")})]},"ann-cathighlight-"+t)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{let i=function(e,t,i,r){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){let i=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(i)return{x:i[0],y:i[1]}}return{x:vn(e,t,i),y:wn(e,t,r)}}(e,o,l,s),a=null==i.x||null==i.y?qu(e,t,r):null,c=i.x??a?.x??null,u=i.y??a?.y??null;if(null==c||null==u)return null;let d="text"===e.type,h=e.dx??(d?0:30),f=e.dy??(d?0:-30),p=e.color||n.colors.text;if(!d){let i="callout"===e.type?"callout-circle":e.type,r="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;return Lg(ln,{noteData:{x:c,y:u,dx:h,dy:f,note:bu(e),type:i,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:p,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},"ann-label-"+t)}return Lg("g",{children:Lg("text",{x:c+h,y:u+f,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||n.typography.labelSize,fill:p,fontFamily:n.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},"ann-label-"+t)}default:return null}}(t,i,e,r)??function(e,t,i){switch(e.type){case"enclose":{let r=(e.coordinates||[]).map(e=>({x:Ku({...e,type:"point"},i),y:Qu({...e,type:"point"},i),r:1})).filter(e=>null!=e.x&&null!=e.y);if(2>r.length)return null;let o=fg(r),a=e.padding||10;return _g("g",{children:[Mg("circle",{cx:o.x,cy:o.y,r:o.r+a,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Mg(Qa,{x:o.x,y:o.y-o.r-a-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+t)}case"rect-enclose":{let r=(e.coordinates||[]).map(e=>({x:Ku({...e,type:"point"},i),y:Qu({...e,type:"point"},i)})).filter(e=>null!=e.x&&null!=e.y);if(2>r.length)return null;let o=e.padding||10,[a,n]=nd(r.map(e=>e.x)),[l,s]=nd(r.map(e=>e.y)),c=a-o,u=n+o,d=l-o;return _g("g",{children:[Mg("rect",{x:c,y:d,width:u-c,height:s+o-d,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:e.color||"var(--semiotic-text-secondary, #666)",strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&Mg(Qa,{x:(c+u)/2,y:d-4,textAnchor:"middle",fill:e.color||"var(--semiotic-text-secondary, #666)",fontSize:12,text:e.label,background:e.labelBackground??"none"})]},"ann-"+t)}case"highlight":{let r=i.data||[],o="function"==typeof e.filter?r.filter(e.filter):e.field&&null!=e.value?r.filter(t=>t[e.field]===e.value):[],a={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};return Mg("g",{children:o.map((t,r)=>{let o=Ku(t,i),n=Qu(t,i);if(null==o||null==n)return null;let l="function"==typeof e.r?e.r(t):e.r||6,s="function"==typeof e.style?e.style(t):e.style||a;return Mg("circle",{cx:o,cy:n,r:l,...s},"hl-"+r)})},"ann-"+t)}case"bracket":{let r=Ku(e,i),o=Qu(e,i);return Mg(ln,{noteData:{x:r??0,y:o??0,dx:e.dx||0,dy:e.dy||0,note:bu(e),type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},"ann-"+t)}case"trend":{let r=i.data||[];if(2>r.length)return null;let o,a=i.xAccessor||"x",n=i.yAccessor||"y",l="ordinal"===i.frameType,s="horizontal"===i.projection,c=l?a:null,u=l?n:null,d=[],h=new Map;if(l&&c&&u){for(let e of r){let t=e[c];if(null==t)continue;let i=t+"";h.has(i)||(h.set(i,d.length),d.push(i))}o=r.map(e=>{let t=e[c],i=e[u];if(null==t||null==i)return null;let r=h.get(t+"");return null!=r?[r,+i]:null}).filter(e=>null!==e)}else o=r.map(e=>[e[a],e[n]]).filter(e=>null!=e[0]&&null!=e[1]);if(2>o.length)return null;let f=i.scales?.x??i.scales?.time,p=i.scales?.y??i.scales?.value;if(!f||!p)return null;let y,g=e=>t=>{let i=Math.max(0,Math.floor(t)),r=Math.min(d.length-1,i+1),o=t-i,a=e(d[i]);return a+(e(d[r])-a)*o},m=f,x=p;if(l)if(s){let e=g(x);y=(t,i)=>[m(i),e(t)]}else{let e=g(m);y=(t,i)=>[e(t),x(i)]}else y=(e,t)=>[m(e),x(t)];let b=e.method||"linear",v="loess"===b?function(e,t=.3){let i=e.length;if(2>i)return e.slice();let r=e.slice().sort((e,t)=>e[0]-t[0]),o=r.map(e=>e[0]),a=r.map(e=>e[1]),n=Math.min(i,Math.max(2,Math.ceil(t*i))),l=Number.isFinite(n)&&o.every(Number.isFinite),s=0,c=n-1,u=[];for(let e=0;i>e;e++){let t,r=o[e],d=0,h=i-1;if(l){for(;i-1>c&&Math.abs(o[s]-r)>=Math.abs(o[c+1]-r);)s++,c++;let e=Math.max(Math.abs(o[s]-r),Math.abs(o[c]-r));t=e||1,e>0&&(d=s,h=c)}else t=o.map(e=>Math.abs(e-r)).sort((e,t)=>e-t)[n-1]||1;let f=0,p=0,y=0,g=0,m=0;for(let e=d;h>=e;e++){let i=Math.abs(o[e]-r)/t,n=1>i?Math.pow(1-Math.pow(i,3),3):0;0!==n&&(f+=n,p+=n*o[e],y+=n*a[e],g+=n*o[e]*o[e],m+=n*o[e]*a[e])}if(0===f){u.push([r,a[e]]);continue}let x=f*g-p*p;if(1e-12>Math.abs(x))u.push([r,y/f]);else{let e=(f*m-p*y)/x;u.push([r,(y-e*p)/f+e*r])}}return u}(o,e.bandwidth??.3):("polynomial"===b?de(o,e.order||2):function(e){let t=[0,0,0,0],i=0;for(let[r,o]of e)null!==o&&(i++,t[0]+=r,t[1]+=o,t[2]+=r*r,t[3]+=r*o);let r=i*t[2]-t[0]*t[0],o=0===r?0:ue((i*t[3]-t[0]*t[1])/r),a=ue(t[1]/i-o*t[0]/i);return{points:e.map(([e])=>[ue(e),ue(o*e+a)]),equation:[o,a]}}(o)).points,w=v.map(([e,t])=>{let[i,r]=y(e,t);return`${i},${r}`}).join(" "),k=e.color||"#6366f1",A=v[v.length-1],[S,M]=y(A[0],A[1]);return _g("g",{children:[Mg("polyline",{points:w,fill:"none",stroke:k,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&Mg("text",{x:S+4,y:M-4,fill:k,fontSize:11,children:e.label})]},"ann-"+t)}case"envelope":{let r=i.data||[];if(2>r.length)return null;let o=i.xAccessor||"x",a=i.scales?.x??i.scales?.time,n=i.scales?.y??i.scales?.value;if(!a||!n)return null;let l=e.upperAccessor||"upperBounds",s=e.lowerAccessor||"lowerBounds",c=e.filter,u=r.filter(e=>null!=e[l]&&null!=e[s]&&(!c||c(e))).sort((e,t)=>e[o]-t[o]);if(2>u.length)return null;let d=Pg[i.curve||"linear"]||xg,h=pg().x(e=>a(e[o])).y0(e=>n(e[s])).y1(e=>n(e[l])).curve(d)(u);if(!h)return null;let f=e.fill||"#6366f1",p=u[u.length-1];return _g("g",{children:[Mg("path",{d:h,fill:f,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&Mg("text",{x:a(p[o])+4,y:n(p[l])-4,fill:f,fontSize:11,children:e.label})]},"ann-"+t)}case"anomaly-band":{let r=i.data||[];if(2>r.length)return null;let o=i.yAccessor||"y",a=i.scales?.x??i.scales?.time,n=i.scales?.y??i.scales?.value;if(!a||!n)return null;let l=r.map(e=>e[o]).filter(e=>null!=e&&isFinite(e));if(2>l.length)return null;let s=l.reduce((e,t)=>e+t,0)/l.length,c=l.reduce((e,t)=>e+(t-s)**2,0)/l.length,u=Math.sqrt(c),d=e.threshold??2,h=s-d*u,f=n(s+d*u),p=n(h),y=e.fill||"#6366f1",g=e.anomalyColor||"#ef4444",m=e.anomalyRadius??6,x=r.filter(e=>{let t=e[o];return null!=t&&Math.abs(t-s)>d*u});return _g("g",{children:[!1!==e.showBand&&Mg("rect",{x:0,y:Math.min(f,p),width:i.width||0,height:Math.abs(p-f),fill:y,fillOpacity:e.fillOpacity??.1}),x.map((e,t)=>{let r=Ku(e,i),o=Qu(e,i);return null==r||null==o?null:Mg("circle",{cx:r,cy:o,r:m,fill:g,fillOpacity:.7,stroke:g,strokeWidth:1.5},"anomaly-"+t)}),e.label&&Mg("text",{x:(i.width||0)-4,y:Math.min(f,p)-4,textAnchor:"end",fill:y,fontSize:11,children:e.label})]},"ann-"+t)}case"forecast":{let r=i.data||[];if(3>r.length)return null;let o=i.xAccessor||"x",a=i.yAccessor||"y",n=i.scales?.x??i.scales?.time,l=i.scales?.y??i.scales?.value;if(!n||!l)return null;let s,c=r.map(e=>[e[o],e[a]]).filter(e=>null!=e[0]&&null!=e[1]&&isFinite(e[0])&&isFinite(e[1])).sort((e,t)=>e[0]-t[0]);if(3>c.length)return null;if("polynomial"===e.method){let t=de(c,e.order||2).equation;s=e=>t.reduce((t,i,r)=>t+i*Math.pow(e,r),0)}else{let e=he(c);if(!e)return null;s=e}let{se:u,meanX:d,ssX:h}=fe(c,s),f=c.length,p=pe(e.confidence??.95),y=c[f-1][0],g=(y-c[0][0])/Math.max(f-1,1),m=Array.from({length:e.steps??5},(e,t)=>{let i=y+(t+1)*g,r=s(i),o=u*Math.sqrt(1+1/f+(h>0?(i-d)**2/h:0))*p;return{x:i,center:r,upper:r+o,lower:r-o}}),x=m.map(e=>`${n(e.x)},${l(e.upper)}`).join(" L"),b=m.slice().reverse().map(e=>`${n(e.x)},${l(e.lower)}`).join(" L"),v=m.map(e=>`${n(e.x)},${l(e.center)}`).join(" "),w=e.strokeColor||"#6366f1",k=m[m.length-1];return _g("g",{children:[Mg("path",{d:`M${x} L${b} Z`,fill:e.fill||"#6366f1",fillOpacity:e.fillOpacity??.15,stroke:"none"}),Mg("polyline",{points:`${n(y)},${l(s(y))} ${v}`,fill:"none",stroke:w,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&k&&Mg("text",{x:n(k.x)+4,y:l(k.center)-4,fill:w,fontSize:11,children:e.label})]},"ann-"+t)}case"widget":{let r,o;if(null!=e.px&&null!=e.py)r=e.px,o=e.py;else{let a=qu(e,t,i);if(!a)return null;r=a.x,o=a.y}if(!Du(r,o,i))return null;let a=e.width??32,n=e.height??32,l=e.content??Mg("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});return Mg("foreignObject",{x:r+(e.dx??0)-a/2,y:o+(e.dy??0)-n/2,width:a,height:n,style:{overflow:"visible",pointerEvents:"auto"},children:Mg("div",{...mn(e),style:{width:a,height:n,display:"flex",alignItems:"center",justifyContent:"center"},children:l})},"ann-"+t)}default:return null}}(t,i,r),e.svgAnnotationRules,u),f=h.nodes,p=new Map;for(let e of h.renderedAnnotations){let t="string"==typeof e.type?e.type:"unknown";p.set(t,(p.get(t)??0)+1)}let y=[];for(let e of t){let t="string"==typeof e.type?e.type:"unknown",i=p.get(t)??0;i>0?p.set(t,i-1):y.push(t)}return e.onRender?.({inputCount:t.length,eligibleCount:d.length,renderedCount:h.renderedAnnotations.length,unrenderedCount:y.length,unrenderedTypes:y}),f.length>0?Lg("g",{id:(e.idPrefix?e.idPrefix+"-":"")+"annotations",className:"semiotic-annotations",children:f}):null}function An(e,t,i,r="right",o,a){if(null==e||!1===e)return null;let{x:n,y:l}=b(e,{totalWidth:t[0],totalHeight:t[1],margin:i,position:r,legendLayout:o,axisChrome:a});return Rg("g",{transform:`translate(${n}, ${l})`,children:e})}function Sn(e){let t=(e+"").replace(/[^a-zA-Z0-9_-]/g,"_"),i=/^[A-Za-z_]/.test(t)?t:"c"+t,r=i+"-semiotic-title",o=i+"-semiotic-desc";return{titleId:r,descId:o,labelledBy:`${r} ${o}`}}function Mn(e,t,i){if("edges"===e){if(t)return"start";if(i)return"end"}return"middle"}function _n(e,t,i){if("edges"===e){if(t)return"hanging";if(i)return"auto"}return"middle"}function Pn(e){if(0===e.length)return{min:null,max:null};let t=1/0,i=-1/0;for(let r of e)t>r.pixel&&(t=r.pixel),r.pixel>i&&(i=r.pixel);return{min:t,max:i}}function Ln(e){if(e)return"object"==typeof e?e.strokeDasharray:"dashed"===e?"6,4":"dotted"===e?"2,4":e}function $n(e,t){return e&&"string"!=typeof e?{stroke:e.stroke??t.stroke,strokeWidth:e.strokeWidth??t.strokeWidth,...null!=e.strokeOpacity&&{strokeOpacity:e.strokeOpacity},...e.strokeDasharray&&{strokeDasharray:e.strokeDasharray}}:{...t,..."string"==typeof e&&{strokeDasharray:Ln(e)}}}function Tn(e,t,i){if("left"===e||"right"===e){let r="left"===e?i:0,o="left"===e?-1:1,a=Math.ceil(t/8),n="M0,"+r;for(let e=0;a>e;e++){let i=8*(e+1);n+=`L${Math.min(8*e+4,t)},${r+4*o}`,n+=`L${Math.min(i,t)},${r}`}return n}let r="bottom"===e?0:t,o="bottom"===e?1:-1,a=Math.ceil(i/8),n=`M${r},0`;for(let e=0;a>e;e++){let t=8*(e+1);n+=`L${r+4*o},${Math.min(8*e+4,i)}`,n+=`L${r},${Math.min(t,i)}`}return n}function Rn(e,t,i){return"exact"===i?function(e,t){let i=e.domain(),r=i[0],o=i[i.length-1],a=r instanceof Date,n=r instanceof Date?r.getTime():r,l=o instanceof Date?o.getTime():o;if(2>t||n===l)return a?[new Date(n),new Date(l)]:[n,l];let s=(l-n)/(t-1),c=Array(t);for(let e=0;t>e;e++){let i=e===t-1?l:n+e*s;c[e]=a?new Date(i):i}return c}(e,t):e.ticks(t)}function Cn(e){return"string"==typeof e||"number"==typeof e}function In(e){let{label:t,x:i,y:r,textAlign:o,fontSize:a,fontFamily:n,color:l}=e;return Ig("foreignObject",{x:i,y:r,width:60,height:24,style:{overflow:"visible"},children:Ig("div",{style:{color:l,fontFamily:n,fontSize:a,textAlign:o,userSelect:"none"},children:t})})}function Dn(e){return e instanceof Date?e:"number"==typeof e&&e>1e9?new Date(e):null}function zn(e,t,i,r){return!!e&&("function"==typeof e?e(t.value,i):function(e,t){let i=Dn(e);if(!i)return!1;let r=Dn(t);return!r||i.getFullYear()!==r.getFullYear()||i.getMonth()!==r.getMonth()}(t.value,i>0?r[i-1].value:void 0))}function On(e){let t=new Date(e instanceof Date?e.valueOf():e);return`${Dg[t.getUTCMonth()]} ${t.getUTCDate()}`}function Fn(e){let t=Math.abs(e[1]-e[0]);return 864e5>t?e=>{let i=new Date(e instanceof Date?e.valueOf():e),r=`${(i.getUTCHours()+"").padStart(2,"0")}:${(i.getUTCMinutes()+"").padStart(2,"0")}`;return 3e5>t&&(r+=":"+(i.getUTCSeconds()+"").padStart(2,"0")),1e4>t&&(r+="."+(i.getUTCMilliseconds()+"").padStart(3,"0")),r}:3156e7>t?On:1578e8>t?e=>{let t=new Date(e instanceof Date?e.valueOf():e);return`${Dg[t.getUTCMonth()]} ${t.getUTCFullYear()}`}:e=>new Date(e instanceof Date?e.valueOf():e).getUTCFullYear()+""}function Nn(e){return"string"==typeof e||"number"==typeof e?6.5*(e+"").length:60}function En(e){let{scale:i,axis:r,size:o,horizontal:a=!1,axisExtent:n}=e,l=r?.extent??n,s=i.domain(),c=function(e){return e?.ticks??e?.tickCount??5}(r),u=Math.max(2,Math.floor(o/(a?70:30))),d="exact"===l?Math.max(2,c):Math.min(c,u),h=r?.tickValues??Rn(i,d,l),f=h.map(e=>e.valueOf()),p=r?.tickFormat||e.format||(s[0]instanceof Date||h[0]instanceof Date?Fn([s[0].valueOf(),s[s.length-1].valueOf()]):t(f)),y=(e,t)=>a?p(e,t,f):p(e),g=h.map((e,t)=>({value:e,pixel:i(e),label:y(e,t)})),m=22;if(a){let e=g.reduce((e,t)=>Math.max(e,Nn(t.label)),0);m=r?.autoRotate?Math.max(20,Math.min(e+8,55)):Math.max(55,e+8)}let x=function(e,t){if(2>=e.length)return e;let i=[e[0]];for(let r=1;e.length-1>r;r++)Math.abs(e[r].pixel-i[i.length-1].pixel)>=t&&i.push(e[r]);let r=e[e.length-1];return t>Math.abs(r.pixel-i[i.length-1].pixel)?i[i.length-1]=r:i.push(r),i}(g,m);if(x.length>1&&(x=x.filter((e,t)=>{return 0===t||(r=x[t-1].label,!!("string"!=typeof(i=e.label)&&"number"!=typeof i||"string"!=typeof r&&"number"!=typeof r||i+""!=r+""));var i,r})),r?.includeMax&&x.length>0&&"exact"!==l&&!r.tickValues){let e=s[s.length-1];if(null!=e){let t=i(e),r=Math.abs(t-x[x.length-1].pixel);if(r>1){let i=y(e,x.length);m>r&&x.length>1&&(x=x.slice(0,-1)),x=[...x,{value:e,pixel:t,label:i}]}}}return x}function Wn(e){if("string"==typeof e)return e;if(e&&"object"==typeof e){let t=e.id;return null==t?null:t+""}return null}function jn(e){let t=e._idPrefix||e.chartId;if(t){let e=(t+"").replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(e)?e:"c"+e}let i=`${e.chartType||""}:${e.title||""}:${Array.isArray(e.data)?e.data.length:0}`,r=0;for(let e=0;i.length>e;e++)r=31*r+i.charCodeAt(e)|0;return"c"+(r>>>0).toString(36)}function Bn(e,t,r){return i(e.showLegend&&!e.__legendIncludesAutomatic?Xa(t,e.colorScheme,r):void 0,e.legend)}function Yn(e,t){if(e.__autoLegendMargin)return Fg[t]}function Xn(e,i){let a={theme:i.theme,position:i.position||"right",totalWidth:i.size[0],totalHeight:i.size[1],margin:i.margin,hasTitle:i.hasTitle,legendLayout:i.legendLayout,idPrefix:i.idPrefix,reservedWidth:i.reservedWidth,axisChrome:i.axisChrome,legendDistance:r(e)||o(e)?e.legendDistance:void 0};return r(e)?function(e){if(0===(t=e.legendGroups,t.flatMap(e=>e.items.map((t,i)=>({group:e,item:t,itemIndex:i,label:t.label})))).length)return null;var t;let i=function(e){let{legendGroups:t,theme:i,position:r="right",totalWidth:o,margin:a,legendLayout:n}=e,{swatchSize:l,labelGap:s,rowHeight:c}=v(n),u=l+s,d=Math.max(12,Va(i)),h="top"===r||"bottom"===r,f=Math.max(l,o-a.left-a.right);if(h){let r=Math.max(l,n?.maxWidth??f),o=Ga(n?.align),a=0,s=0,c=[];for(let o of t){let t=o.items.map(e=>e.label),u=Za({...e,categories:t,legendLayout:{...n,maxWidth:Math.max(l,r-d-8),align:"start"}}),h=o.label?d:0,f=o.label?Ua(o.label,0,0,i):0,p=h>0?h+8:0,y=p+u.width,g=Math.max(u.height,f);c.push({group:o,x:a,y:0,itemOffsetX:p,itemOffsetY:0,width:y,height:g,items:u.items}),a+=y+12,s=Math.max(s,g)}let h=c.length>0?a-12:0,p=h>r?0:"center"===o?Math.max(0,(r-h)/2):"end"===o?Math.max(0,r-h):0;return{groups:c.map(e=>({...e,x:e.x+p})),width:h,height:s,swatchSize:l,labelOffset:u,swatchRadius:0}}let p=w(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),c),y=0;return{groups:t.map((e,t)=>{let r=e.items.map(e=>Ua(e.label,l,s,i)),o=Math.max(0,...r,e.label?Ua(e.label,0,0,i):0);return y=Math.max(y,o),{group:e,x:0,y:p[t].itemsY,itemOffsetX:0,itemOffsetY:0,width:o,height:e.items.length*c,items:e.items.map((e,t)=>({category:e.label,width:r[t],x:0,y:t*c}))}}),width:y,height:p.at(-1)?.endY??0,swatchSize:l,labelOffset:u,swatchRadius:0}}(e),r="top"===e.position||"bottom"===e.position,o={legendGroups:e.legendGroups,legendDistance:e.legendDistance},a=e.reservedWidth??u(o,e.legendLayout),n=e.theme.colors.grid||e.theme.colors.textSecondary,{x:l,y:s}=b(o,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:a});if(!r){let t=w(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(i.swatchSize,e.legendLayout?.rowHeight??22)),r=e.legendGroups.flatMap((r,o)=>{let n=t[o],l=r.type??"fill",s=[Qy("line",{x1:0,y1:n.lineY,x2:a,y2:n.lineY,stroke:"gray"},"legend-group-neatline-"+o)];return r.label&&null!=n.labelY&&s.push(Qy("text",{y:n.labelY,fontSize:Va(e.theme),fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:r.label},"legend-group-label-"+o)),s.push(Qy("g",{transform:`translate(0,${n.itemsY})`,children:r.items.map((t,a)=>{let n=r.styleFn(t,a),s="function"==typeof l?l(t):"line"===l?Qy("line",{x1:0,y1:0,x2:i.swatchSize,y2:i.swatchSize,style:n}):Qy("rect",{width:i.swatchSize,height:i.swatchSize,rx:i.swatchRadius,style:n});return Jy("g",{transform:`translate(0,${a*Math.max(i.swatchSize,e.legendLayout?.rowHeight??22)})`,children:[s,Qy("text",{x:i.labelOffset,y:i.swatchSize/2,dominantBaseline:"central",fontSize:Va(e.theme),fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:t.label})]},`legend-${o}-${a}`)})},"legend-group-"+o)),s});return Qy("g",{className:"semiotic-legend",transform:`translate(${l},${s})`,"data-orientation":"vertical",fontWeight:qa(e.theme),children:r})}let c=i.groups.flatMap((t,o)=>{let{group:a}=t,l=a.type??"fill",s=[];if(a.label&&s.push(Qy("text",r?{transform:`translate(${t.x},${t.y}) rotate(90)`,textAnchor:"start",fontSize:Va(e.theme),fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:a.label}:{x:t.x,y:t.y+Va(e.theme),fontSize:Va(e.theme),fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:a.label},"legend-group-label-"+o)),s.push(...t.items.map((r,n)=>{let s=a.items[n],c=a.styleFn(s,n),u="function"==typeof l?l(s):"line"===l?Qy("line",{x1:0,y1:0,x2:i.swatchSize,y2:i.swatchSize,style:c}):Qy("rect",{width:i.swatchSize,height:i.swatchSize,rx:i.swatchRadius,style:c});return Jy("g",{transform:`translate(${t.x+t.itemOffsetX+r.x},${t.y+t.itemOffsetY+r.y})`,children:[u,Qy("text",{x:i.labelOffset,y:i.swatchSize/2,dominantBaseline:"central",fontSize:Va(e.theme),fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:r.category})]},`legend-${o}-${n}`)})),r&&i.groups.length-1>o){let e=t.x+t.width+6;s.push(Qy("line",{x1:e,y1:0,x2:e,y2:i.height,stroke:n},"legend-group-separator-"+o))}return s});return Qy("g",{className:"semiotic-legend",transform:`translate(${l},${s})`,"data-orientation":r?"horizontal":"vertical",fontWeight:qa(e.theme),children:c})}({...a,legendGroups:e.legendGroups}):o(e)?function(e){let i=function(e){let t="top"===e.position||"bottom"===e.position,i=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??i,200),height:e.gradient.label?46:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?126:108,swatchSize:14}}(e),r="top"===e.position||"bottom"===e.position,o={gradient:e.gradient,legendDistance:e.legendDistance},a=u(o),n=(e.idPrefix?e.idPrefix+"-":"")+"semiotic-static-gradient-legend",l=e.gradient.format||t(e.gradient.domain),{x:s,y:c}=b(o,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:a}),d=Array.from({length:17},(t,i)=>{let o=i/16;return Qy("stop",{offset:o,stopColor:e.gradient.colorFn(r?e.gradient.domain[0]+o*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-o*(e.gradient.domain[1]-e.gradient.domain[0]))},i)});if(r){let t=e.gradient.label?12:void 0,r=e.gradient.label?18:0;return Jy("g",{className:"semiotic-legend",transform:`translate(${s},${c})`,fontWeight:qa(e.theme),children:[Qy("defs",{children:Qy("linearGradient",{id:n,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:d})}),e.gradient.label&&Qy("text",{x:i.width/2,y:t,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:e.gradient.label}),Qy("rect",{x:0,y:r,width:i.width,height:12,fill:`url(#${n})`,rx:2}),Qy("text",{x:0,y:r+12+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:Ha(e.theme),children:l(e.gradient.domain[0])}),Qy("text",{x:i.width,y:r+12+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:Ha(e.theme),children:l(e.gradient.domain[1])})]})}let h=e.gradient.label?12:void 0,f=e.gradient.label?18:0;return Jy("g",{className:"semiotic-legend",transform:`translate(${s},${c})`,fontWeight:qa(e.theme),children:[Qy("defs",{children:Qy("linearGradient",{id:n,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:d})}),e.gradient.label&&Qy("text",{x:0,y:h,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:Ha(e.theme),children:e.gradient.label}),Qy("rect",{x:0,y:f,width:14,height:100,fill:`url(#${n})`,rx:2}),Qy("text",{x:19,y:f+10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:Ha(e.theme),children:l(e.gradient.domain[1])}),Qy("text",{x:19,y:f+100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:Ha(e.theme),children:l(e.gradient.domain[0])})]})}({...a,gradient:e.gradient}):null}function Gn(e,t){let{props:i,categories:r,theme:o,size:a,hasTitle:n}=t,l=i.legendPosition||"right",c={...e},u={theme:o,position:l,size:a,hasTitle:n,legendLayout:i.legendLayout,axisChrome:i.axisChrome,minimumMargin:Yn(i,l)};if(null!=i.legend){let t=Bn(i,r,o);null!=t&&!1!==t&&function(e,t){x(e,{legend:t.legend,position:t.position||"right",size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}(e,{...u,legend:t})}else i.showLegend&&r.length>0&&function(e,t){if(0===t.categories.length)return;let i=t.position||"right";x(e,{legend:Xa(t.categories,t.colorScheme,t.theme),position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}(e,{...u,categories:r,colorScheme:i.colorScheme});return s(e,c,a,l),l}function Vn(e){let{props:t,categories:i,theme:a,size:n,margin:l,hasTitle:s}=e,c=t.legendPosition||"right",d={theme:a,position:c,size:n,margin:l,hasTitle:s,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix};if(null!=t.legend){let e=Bn(t,i,a);return Cg.isValidElement(e)?An(e,n,l,c,t.legendLayout,t.axisChrome):Xn(e,d)||(r(e)||o(e)?null:An(e??null,n,l,c,t.legendLayout,t.axisChrome))}return t.showLegend&&0!==i.length?function(e){let{categories:t,colorScheme:i,theme:r,position:o="right",totalWidth:a,totalHeight:n,margin:l}=e;if(!t||0===t.length)return null;let s=Ya(t,i,r),c="top"===o||"bottom"===o,d=Za(e),h={...Xa(t,i,r),legendDistance:e.legendDistance},f=e.reservedWidth??u(h,e.legendLayout),{x:p,y:y}=b(h,{totalWidth:a,totalHeight:n,margin:l,position:o,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:f});if(c){let e=d.items.map((e,t)=>Jy("g",{transform:`translate(${e.x},${e.y})`,children:[Qy("rect",{width:d.swatchSize,height:d.swatchSize,fill:s(e.category),rx:d.swatchRadius}),Qy("text",{x:d.labelOffset,y:d.swatchSize/2,dominantBaseline:"central",fontSize:Va(r),fill:r.colors.text,fontFamily:Ha(r),children:e.category})]},"legend-"+t));return Qy("g",{className:"semiotic-legend",transform:`translate(${p},${y})`,fontWeight:qa(r),children:e})}let g=w([{hasLabel:!1,itemCount:t.length}],Math.max(d.swatchSize,e.legendLayout?.rowHeight??22))[0],m=d.items.map((e,t)=>Jy("g",{transform:`translate(${e.x},${e.y+g.itemsY})`,children:[Qy("rect",{width:d.swatchSize,height:d.swatchSize,fill:s(e.category),rx:d.swatchRadius}),Qy("text",{x:d.labelOffset,y:d.swatchSize/2,dominantBaseline:"central",fontSize:Va(r),fill:r.colors.text,fontFamily:Ha(r),children:e.category})]},"legend-"+t));return Jy("g",{className:"semiotic-legend",transform:`translate(${p},${y})`,fontWeight:qa(r),children:[Qy("line",{x1:0,y1:g.lineY,x2:f,y2:g.lineY,stroke:"gray"}),m]})}({categories:i,colorScheme:t.colorScheme,theme:a,position:c,totalWidth:n[0],totalHeight:n[1],margin:l,hasTitle:s,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix}):null}function Hn(e,t){let i=se(t.theme),r=t.background??i.background,o=t.idPrefix?t.idPrefix+"-":"",a="string"==typeof t.title?t.title:void 0,n=t.idPrefix?Sn(t.idPrefix):{titleId:"semiotic-title",descId:"semiotic-desc"},l=a?n.titleId:void 0,s=t.description?n.descId:void 0,c=[l,s].filter(Boolean).join(" ")||void 0;return Og("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,role:"img","aria-labelledby":c,style:{fontFamily:i.fontFamily},children:[a&&zg("title",{id:l,children:a}),t.description&&zg("desc",{id:s,children:t.description}),t.defs&&zg("defs",{children:t.defs}),r&&"transparent"!==r&&zg("rect",{x:0,y:0,width:t.width,height:t.height,fill:r}),zg("g",{id:o+"data-area",transform:t.innerTransform,children:e}),a&&zg("text",{id:o+"chart-title",x:t.width/2,y:22,textAnchor:"middle",fontSize:i.titleFontSize,fontWeight:i.titleFontWeight,fill:i.text,fontFamily:i.titleFontFamily,children:a}),t.legend&&zg("g",{id:o+"legend",children:t.legend}),t.outerElements]})}function qn(e,t,i,r){return"function"==typeof e?e({size:t,margin:i,scales:r}):e}function Un(t,i){let r=le(t.theme),o=t.size||[500,300],n=l({...Wg,...t.margin},t.title),s=a(t.title),c=function(e,t){if(!t||0===e.length||!e.some(e=>null!=e&&"object"==typeof e&&Array.isArray(e[t])))return e;let i=[];for(let r of e){if(null==r||"object"!=typeof r)continue;let e=r[t];if(!Array.isArray(e))continue;let o=r.label??r.id??r.key;for(let t of e)null==t||"object"!=typeof t||i.push(null==o?t:{...t,_lineGroup:o})}return i}(F(t.data),t.lineDataAccessor),u=t.showLegend?Ka(c,t.colorAccessor||t.groupAccessor||t.categoryAccessor):[],d=y({showAxes:t.showAxes,xLabel:t.xLabel,yLabel:t.yLabel,yLabelRight:t.yLabelRight,axes:t.axes});Gn(n,{props:{...t,axisChrome:d},categories:u,theme:r,size:o,hasTitle:s});let f=Vn({props:{...t,axisChrome:d},categories:u,theme:r,size:o,margin:n,hasTitle:s}),p=o[0]-n.left-n.right,g=o[1]-n.top-n.bottom,m="streaming"===t.runtimeMode||["bar","swarm","waterfall"].includes(t.chartType),x=t.colorScheme||r.colors.categorical,b=(t.axes?.find(e=>"left"===e.orient)??t.axes?.find(e=>"right"===e.orient))?.extent??t.axisExtent,v={chartType:t.chartType,runtimeMode:m?"streaming":"bounded",windowSize:t.windowSize??200,windowMode:t.windowMode??"sliding",arrowOfTime:m?t.arrowOfTime??"right":"right",extentPadding:t.extentPadding??.1,xAccessor:t.xAccessor,yAccessor:t.yAccessor,timeAccessor:m?t.timeAccessor:void 0,valueAccessor:t.valueAccessor,colorAccessor:t.colorAccessor,sizeAccessor:t.sizeAccessor,symbolAccessor:t.symbolAccessor,symbolMap:t.symbolMap,groupAccessor:t.groupAccessor||(t.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:t.categoryAccessor,lineDataAccessor:t.lineDataAccessor,xExtent:t.xExtent,yExtent:t.yExtent,invertY:t.invertY,axisExtent:t.axisExtent,yAxisExtent:b,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:ee(t.gradientFill),lineGradient:te(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:x,themeCategorical:r.colors.categorical,themeSequential:r.colors.sequential,themeDiverging:r.colors.diverging,themeSemantic:lu(r),customLayout:t.customLayout,layoutConfig:t.layoutConfig,layoutMargin:n,layoutSelection:t.layoutSelection,barColors:t.barColors,showValues:t.showValues,heatmapValueFormat:t.heatmapValueFormat,heatmapColorScale:t.heatmapColorScale,heatmapAggregation:t.heatmapAggregation,heatmapXBins:t.heatmapXBins,heatmapYBins:t.heatmapYBins,pointIdAccessor:t.pointIdAccessor,onLayoutError:t.onLayoutError},w=new dy(v);t.data&&w.ingest({inserts:c,bounded:!0}),w.computeScene({width:p,height:g});let k=qn(t.backgroundGraphics,o,n,w.scales),A=qn(t.foregroundGraphics,o,n,w.scales);if(!w.scales){let e,a=t.annotations?kn({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:c,scales:{},layout:{width:p,height:g},theme:r,idPrefix:t._idPrefix,onRender:t=>{e=t}}):null;return i&&(i.evidence=Ta({frameType:"xy",width:o[0],height:o[1],marks:[],title:t.title,description:t.description,annotations:t.annotations,annotationRender:e,extraWarnings:w.scales?[]:["NO_SCALES"],margin:n})),Fp.renderToStaticMarkup(Hn(k||A||t.annotations?qg(Vg,{children:[k,a,A]}):null,{width:o[0],height:o[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:r,innerTransform:`translate(${n.left},${n.top})`,innerWidth:p,innerHeight:g,legend:f,idPrefix:t._idPrefix}))}let S,M=t._idPrefix,_=Ba({nodes:w.scene,renderMode:t.renderMode,fallback:(e,i)=>Wa(e,i,M,t.hoverRadius??30)}),P=!w.xIsDate||t.xFormat||t.tickFormatTime?t:{...t,xFormat:Fn(w.scales.x.domain().map(e=>e.valueOf()))},L=t.showGrid?function(e,t,i,r,o,a,n){let{grid:l}=se(i),s=r?r+"-":"",c=a?.find(e=>"bottom"===e.orient),u=a?.find(e=>"top"===e.orient),d=a?.find(e=>"left"===e.orient),h=a?.find(e=>"right"===e.orient),f=c??u,p=d??h,y=En({scale:e.x,axis:f,size:t.width,horizontal:!0,format:n?.xFormat||n?.tickFormatTime,axisExtent:o}),g=En({scale:e.y,axis:p,size:t.height,format:n?.yFormat||n?.tickFormatValue,axisExtent:o}),m=!1!==f?.grid,x=!1!==p?.grid,b=Ln(f?.gridStyle),v=Ln(p?.gridStyle),w=$n(f?.gridStyle,{stroke:l,strokeWidth:.5}),k=$n(p?.gridStyle,{stroke:l,strokeWidth:.5});return Eg("g",{id:s+"grid",className:"semiotic-grid",opacity:.8,children:[m&&y.map((e,i)=>Ng("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:t.height,...w,strokeDasharray:b??w.strokeDasharray},"gx-"+i)),x&&g.map((e,i)=>Ng("line",{x1:0,y1:e.pixel,x2:t.width,y2:e.pixel,...k,strokeDasharray:v??k.strokeDasharray},"gy-"+i))]})}(w.scales,{width:p,height:g},r,M,t.axisExtent,t.axes,P):null,$=_.map(e=>e.element),T=jn(t)+"-plot-clip",R=!1!==t.showAxes,C=R?function(t,i,r,o,a,n,l,s=!1){let c=se(o),u=r.legendPosition??"right",d=h(r.legendLayout,l?.leftAxis),f=h(r.legendLayout,l?.rightAxis),p=s&&"left"===u&&d>0?d:n?.left??r.margin?.left??40,y=s&&"right"===u&&f>0?f:n?.right??r.margin?.right??40,{xAxis:g,yAxis:m,xOrient:x,yOrient:b}=e(r.axes),v="top"===x?0:i.height,w="right"===b?i.width:0,k="top"===x?-1:1,A="right"===b?1:-1,S=En({scale:t.x,axis:g,size:i.width,horizontal:!0,format:r.xFormat||r.tickFormatTime,axisExtent:r.axisExtent}),M=En({scale:t.y,axis:m,size:i.height,format:r.yFormat||r.tickFormatValue,axisExtent:r.axisExtent}),_=!(!g?.autoRotate||!function(e){for(let t=1;e.length>t;t++){let i=e[t-1],r=e[t];if(Math.abs(r.pixel-i.pixel)<(Nn(i.label)+Nn(r.label))/2+8)return!0}return!1}(S)),P=Pn(S),L=Pn(M),$=g?.label??r.xLabel,T=m?.label??("right"===b?r.yLabelRight??r.yLabel:r.yLabel),R=$n(g?.axisStyle,{stroke:c.border,strokeWidth:1}),C=$n(m?.axisStyle,{stroke:c.border,strokeWidth:1}),I="right"===b?i.width+y-15:15-p;return Og("g",{id:(a?a+"-":"")+"axes",className:"stream-axes",children:[!1!==g?.visible&&Og("g",{className:"semiotic-axis semiotic-axis-"+x,"data-orient":x,children:[!1!==g?.baseline&&!g?.jaggedBase&&zg("line",{x1:0,y1:v,x2:i.width,y2:v,...R}),g?.jaggedBase&&zg("path",{d:Tn(x,i.width,i.height),fill:"none",...R}),S.map((e,t)=>{let i=zn(g?.landmarkTicks,e,t,S);return Og("g",{transform:`translate(${e.pixel},${v})`,children:[zg("line",{y2:5*k,...R}),Cn(e.label)?zg("text",{y:k*(_?12:18),textAnchor:_?"end":Mn(g?.tickAnchor,e.pixel===P.min,e.pixel===P.max),fontWeight:i?600:400,fontSize:i?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,transform:_?"top"===x?"rotate(45)":"rotate(-45)":void 0,children:e.label}):In({label:e.label,x:-30,y:"top"===x?-30:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"xtick-"+t)}),$&&zg("text",{x:i.width/2,y:"top"===x?-(_?58:40):i.height+(_?58:40),textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:$})]}),!1!==m?.visible&&Og("g",{className:"semiotic-axis semiotic-axis-"+b,"data-orient":b,children:[!1!==m?.baseline&&!m?.jaggedBase&&zg("line",{x1:w,y1:0,x2:w,y2:i.height,...C}),m?.jaggedBase&&zg("path",{d:Tn(b,i.width,i.height),fill:"none",...C}),M.map((e,t)=>{let i=zn(m?.landmarkTicks,e,t,M);return Og("g",{transform:`translate(${w},${e.pixel})`,children:[zg("line",{x2:5*A,...C}),Cn(e.label)?zg("text",{x:8*A,textAnchor:"right"===b?"start":"end",dominantBaseline:_n(m?.tickAnchor,e.pixel===L.min,e.pixel===L.max),fontWeight:i?600:400,fontSize:i?c.tickSize+1:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):In({label:e.label,x:"right"===b?8:-68,y:-12,textAlign:"right"===b?"left":"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},"ytick-"+t)}),T&&zg("text",{x:I,y:i.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(${"right"===b?90:-90}, ${I}, ${i.height/2})`,children:T})]})]})}(w.scales,{width:p,height:g},P,r,M,n,d,!!f):null,I=R?function(e){let{scales:t,layout:i,props:r,theme:o,leftAxis:a,rightAxis:n,margin:l,axisChrome:s,hasRenderedLegend:c}=e;if(!a||!n||!1===n.visible)return null;let u=se(o),d=En({scale:t.y,axis:n,size:i.height,format:r.yFormat||r.tickFormatValue,axisExtent:r.axisExtent}),f=Pn(d),p=n.label??r.yLabelRight,y=$n(n.axisStyle,{stroke:u.border,strokeWidth:1}),g=r.legendPosition??"right",m=h(r.legendLayout,s?.rightAxis),x=i.width+(c&&"right"===g&&m>0?m:l.right)-15;return Gg("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==n.baseline&&!n.jaggedBase&&Xg("line",{x1:i.width,y1:0,x2:i.width,y2:i.height,...y}),n.jaggedBase&&Xg("path",{d:Tn("right",i.width,i.height),fill:"none",...y}),d.map((e,t)=>{let r=zn(n.landmarkTicks,e,t,d);return Gg("g",{transform:`translate(${i.width},${e.pixel})`,children:[Xg("line",{x2:5,...y}),Cn(e.label)?Xg("text",{x:8,textAnchor:"start",dominantBaseline:_n(n.tickAnchor,e.pixel===f.min,e.pixel===f.max),fontWeight:r?600:400,fontSize:r?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label}):In({label:e.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"ytick-r-"+t)}),p&&Xg("text",{x:x,y:i.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${x}, ${i.height/2})`,children:p})]})}({scales:w.scales,layout:{width:p,height:g},props:t,theme:r,leftAxis:t.axes?.find(e=>"left"===e.orient),rightAxis:t.axes?.find(e=>"right"===e.orient),margin:n,axisChrome:d,hasRenderedLegend:!!f}):null,D=t.annotations?kn({annotations:t.annotations,autoPlaceAnnotations:t.autoPlaceAnnotations,svgAnnotationRules:t.svgAnnotationRules,annotationData:c,scales:{x:w.scales.x,y:w.scales.y},layout:{width:p,height:g},theme:r,xAccessor:"string"==typeof t.xAccessor?t.xAccessor:void 0,yAccessor:"string"==typeof t.yAccessor?t.yAccessor:void 0,idPrefix:M,onRender:e=>{S=e}}):null;i&&(i.evidence=Ta({frameType:"xy",width:o[0],height:o[1],marks:_.map(e=>e.node),title:t.title,description:t.description,annotations:t.annotations,annotationRender:S,xDomain:$a(w.scales.x?.domain?.()),yDomain:$a(w.scales.y?.domain?.()),legendItems:u.length>0?u.length:void 0,margin:n}));let z=t.svgPreRenderers&&w.scales?t.svgPreRenderers.map((e,t)=>{try{return Hg(Op.Fragment,{children:e(w.scene,w.scales,{width:p,height:g})},"pre-"+t)}catch{return null}}).filter(Boolean):null;return Fp.renderToStaticMarkup(Hn(qg(Vg,{children:[k,z,L,Hg("defs",{children:Hg("clipPath",{id:T,children:Hg("rect",{x:0,y:0,width:p,height:g})})}),Hg("g",{clipPath:`url(#${T})`,children:$}),C,I,D,A,w.customLayoutOverlays]}),{width:o[0],height:o[1],className:"stream-xy-frame"+(t.className?" "+t.className:""),title:t.title,description:t.description,background:t.background,theme:r,innerTransform:`translate(${n.left},${n.top})`,innerWidth:p,innerHeight:g,legend:f,idPrefix:t._idPrefix}))}function Zn({machine:e,layout:t,runtime:i,downstreamSet:r,selectedSet:o,width:a,height:n,seed:l,reduced:s,onSelectTask:c}){let u=t.tasks.length?Math.min(...t.tasks.map(e=>e.y-e.height/2)):60,d=Math.max(20,u-12),h=Math.max(26,u-6);return Kg("svg",{"aria-hidden":"true",width:a,height:n,viewBox:`0 0 ${a} ${n}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[Zg("defs",{children:Zg("filter",{id:"chain-shadow-"+l,x:"-20%",y:"-20%",width:"140%",height:"150%",children:Zg("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,i)=>{let r=t.tasks.filter(e=>e.laneIndex===i)[0]?.x??0;return Kg("g",{children:[Zg("line",{x1:r,x2:r,y1:h,y2:n-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),Zg("text",{x:r,y:d,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{let t=i.delivered.has(e.edgeID),o=i.inFlight.has(e.edgeID),a=r.has(e.targetID)||r.has(e.sourceID),n=e.points.map(e=>`${e.x},${e.y}`).join(" ");return Zg("polyline",{points:n,fill:"none",stroke:a?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:a?4:o?3:2,strokeOpacity:t||o||a?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{let t=i.delivered.has(e.edgeID);return Kg("g",{children:[Zg("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&Zg("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{let a=t.taskByID.get(e.id);if(!a)return null;let n=i.completed.has(e.id),u=i.blockers.has(e.id),d=i.previewTaskID===e.id,h=o.has(e.id)||d,f=r.has(e.id),p=function(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}(e,i),y=a.x-a.width/2,g=a.y-a.height/2,m=Math.max(2,a.height*e.progress);return Kg("g",{children:[Kg("g",{style:{transform:`rotate(${n?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:s?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+l+")"},children:[Zg("rect",{x:y,y:g,width:a.width,height:a.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:h||f?"var(--semiotic-selection-color, #e08a1e)":p,strokeWidth:h?4:f?3:2}),Zg("rect",{x:y+3,y:g+a.height-m+1,width:a.width-6,height:Math.max(0,m-4),rx:2,fill:p,opacity:n?.86:.46})]}),u&&Kg("g",{opacity:d?.28:1,children:[Zg("line",{x1:y-8,x2:y+14,y1:a.y+9,y2:a.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),Zg("circle",{cx:y-8,cy:a.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),Kg("g",{onPointerDown:()=>c(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[Zg("rect",{x:y,y:g,width:a.width,height:a.height,fill:"transparent"}),Zg("text",{x:a.x,y:a.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?e.label.slice(0,22)+"…":e.label}),Kg("text",{x:a.x,y:a.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% · ",n?"done":u?"blocked":i.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}function Kn(e,t=0){if(e instanceof Date)return e.getTime();let i=Number(e);return Number.isFinite(i)?i:t}function Qn(e){if(null==e.completionTime)return null;let t=Kn(e.completionTime,NaN);return Number.isFinite(t)?t:null}function Jn(e,t,i,r){let o=new Set;for(let a of e.nodes){let n=e.incoming.get(a.id)??[];(r.has(a.id)||!i.has(a.id)&&n.every(e=>t.has(e.id)))&&o.add(a.id)}return o}function el(e,t,i){return function(e,t,i){if(null!=e)return"function"==typeof e?e(t,i):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}(i,e,t)}function tl(e,t){return t>e?-1:e>t?1:0}function il(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function rl(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function ol(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function al(e,t,i={}){let r=new Set(i.completedTaskIDs??[]),o=wu(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),a=[...Vu(o,t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(i.isComplete?i.isComplete(e):r.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),n=Array.from(new Set(a.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:a.length,affectedLaneCount:n.length,downstreamTaskIDs:a.map(e=>e.id),affectedLanes:n}}function nl(e,t,i,r,o){return{__composite:{data:e,colorBy:t,colorScheme:i,common:r,rest:o}}}function ll(e){return e.__composite}function sl(e,t){return"number"==typeof e&&Number.isFinite(e)?e:t}function cl(e,t){return Math.max(1,Math.floor(sl(e,t)))}function ul(e,t,i,r){return e.replace(/^<svg\b/,`<svg x="${t}" y="${i}" data-semiotic-composite-part="${r}"`)}function dl(e,t){for(let i of e){let e=i?.[t];if(Array.isArray(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1])return e}}function hl(e,t){return("function"==typeof t?t(e):e[t])+""}function fl(e,t,i){let{scales:r,config:o,getConnector:a,getO:n}=e;if(!a||!r)return[];let l=[],{projection:s}=r,c=new Map;for(let e of t){if("point"!==e.type&&"rect"!==e.type)continue;let t=e.datum;if(!t)continue;let i,r,o=a(t);o&&("point"===e.type?(i=e.x,r=e.y):(i=e.x+e.w/2,r=e.y+("vertical"===s?0:e.h/2)),c.has(o)||c.set(o,[]),c.get(o).push({x:i,y:r,datum:t,category:n(t)}))}let u=new Map(r.o.domain().map((e,t)=>[e,t])),d=o.connectorStyle,h={stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5},f=(e,t,i)=>{var r;l.push({type:"connector",x1:e.x,y1:e.y,x2:t.x,y2:t.y,style:(r=e.datum,"function"==typeof d?d(r):d||h),datum:e.datum,group:i})};for(let[e,t]of c)if(t.length>=2){t.sort((e,t)=>(u.get(e.category)??-1)-(u.get(t.category)??-1));for(let i=0;t.length-1>i;i++)f(t[i],t[i+1],e);"radial"===s&&t.length>=3&&f(t[t.length-1],t[0],e)}return l}function pl(e,t,i){let r="function"==typeof e?e(i?t.w:t.h):e;return"number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0}function yl(e){let t=e.getSymbol;return t?zu(t,e.config.symbolMap):null}function gl(e,t,i,r,o,a,n){e.push(t?{type:"symbol",x:r,y:o,size:Math.PI*a*a,symbolType:t(i),style:n,datum:i}:{type:"point",x:r,y:o,r:a,style:n,datum:i})}function ml(e,t){let{columns:i,config:r,resolvePieceStyle:o}=e,a=[],n=Math.min(t.width,t.height)/2-4,l="donut"===r.chartType?r.innerRadius||60:0,s=-Math.PI/2+(r.startAngle||0)*Math.PI/180,c=null!=r.sweepAngle?r.sweepAngle*Math.PI/180:2*Math.PI,u=null!=r.sweepAngle&&360>r.sweepAngle,d=Object.values(i),h=d.some(e=>{let t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),f=u&&!h&&d.length>1&&(r.cornerRadius??0)>0;for(let e=0;d.length>e;e++){let t=d[e],i=t.pieceData[0],u="number"==typeof i?._pctStart?i._pctStart:t.pctStart,h=s+u*c,p=s+(u+("number"==typeof i?._pct?i._pct:t.pct))*c,y=o(t.pieceData[0],t.name),g=0===e,m=e===d.length-1,x={type:"wedge",cx:0,cy:0,innerRadius:l,outerRadius:n,startAngle:h,endAngle:p,...r.cornerRadius&&{cornerRadius:r.cornerRadius},style:y,datum:i?._nonInteractive?null:t.pieceData,category:t.name};i?._roundedEnds?x.roundedEnds=i._roundedEnds:f&&(x.roundedEnds={start:g,end:m}),i?._gradientBand&&(x._gradientBand=i._gradientBand),a.push(x)}return a}function xl(e,t,i){return{...e[0],...i,category:t,data:e}}function bl(e){let t=e.length,i=e[0],r=e[t-1];return{n:t,min:i,q1:hm(e,.25)??i,median:hm(e,.5)??(i+r)/2,q3:hm(e,.75)??r,max:r,mean:e.reduce((e,t)=>e+t,0)/t}}function vl(e,t,i,r,o){let a=Array(o).fill(0);for(let n of e)t>n||n>i||a[Math.min(Math.floor((n-t)/r),o-1)]++;return a}function wl(e){let{innerRadius:t,outerRadius:i,startAngle:r,endAngle:o}=e,a=0>=t;if(0>=(e.cornerRadius??0)||!e.roundStart&&!e.roundEnd){if(a){let e=Cm(i,r),t=Cm(i,o);return`M0,0 L${e.x},${e.y} A${i},${i} 0 ${o-r>Math.PI?1:0} 1 ${t.x},${t.y} Z`}let e=Cm(i,r),n=Cm(i,o),l=Cm(t,o),s=Cm(t,r),c=o-r>Math.PI?1:0;return`M${e.x},${e.y} A${i},${i} 0 ${c} 1 ${n.x},${n.y} L${l.x},${l.y} A${t},${t} 0 ${c} 0 ${s.x},${s.y} Z`}let n=Math.max(0,Math.min(e.cornerRadius??0,(i-t)/2));if(0===n)return wl({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let l=Math.asin(Math.min(1,n/Math.max(1e-9,i-n))),s=a?0:Math.asin(Math.min(1,n/Math.max(1e-9,t+n))),c=o-r,u=e.roundStart&&e.roundEnd?c/2:c,d=!!e.roundStart&&u>l,h=!!e.roundEnd&&u>l;if(!d&&!h)return wl({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let f=r+(d?l:0),p=o-(h?l:0),y=r+(d?s:0),g=o-(h?s:0),m=Cm(i,f),x=Cm(i,p),b=(i-n)*Math.cos(l),v=Cm(b,r),w=Cm(b,o),k=a?null:Cm(t,g),A=a?null:Cm(t,y),S=a?0:(t+n)*Math.cos(s),M=a?null:Cm(S,r),_=a?null:Cm(S,o),P=p-f>Math.PI?1:0,L=a?0:g-y>Math.PI?1:0,$="";if(d)$+=`M${v.x},${v.y}`,$+=` A${n},${n} 0 0 1 ${m.x},${m.y}`;else{let e=Cm(i,r);$+=`M${e.x},${e.y}`}if(h)$+=` A${i},${i} 0 ${P} 1 ${x.x},${x.y}`,$+=` A${n},${n} 0 0 1 ${w.x},${w.y}`;else{let e=Cm(i,o);$+=` A${i},${i} 0 ${P} 1 ${e.x},${e.y}`}if(a)$+=" L0,0";else{if(h)$+=` L${_.x},${_.y}`,$+=` A${n},${n} 0 0 1 ${k.x},${k.y}`;else{let e=Cm(t,o);$+=` L${e.x},${e.y}`}if(d)$+=` A${t},${t} 0 ${L} 0 ${A.x},${A.y}`,$+=` A${n},${n} 0 0 1 ${M.x},${M.y}`;else{let e=Cm(t,r);$+=` A${t},${t} 0 ${L} 0 ${e.x},${e.y}`}}return $+=" Z",$}function kl(e){return 1e6>e?1e4>e?1e3>e?e+"":(e/1e3).toFixed(1)+"K":(e/1e3).toFixed(0)+"K":(e/1e6).toFixed(1)+"M"}function Al(e,t){let i=e.datum;if(!i)return null;let r=[],o=i.__funnelStepLabel,a=Number(i.__funnelStepLabelX),n=Number(i.__funnelStepLabelY),l=Number(i.__funnelRowWidth);"string"==typeof o&&Number.isFinite(a)&&Number.isFinite(n)&&(!Number.isFinite(l)||l>=8.4*o.length+16)&&r.push(Im("text",{x:a,y:n+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:o},t+"-funnel-step"));let s=Number(i.__funnelValue),c=Number(i.__funnelValueLabelX),u=Number(i.__funnelValueLabelY),d=Number(i.__funnelBarW);if(Number.isFinite(s)&&0!==s&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){let e=Number(i.__funnelPercent),o=!0!==i.__funnelIsFirstStep&&Number.isFinite(e)?`${kl(s)} (${.05>Math.abs(e-Math.round(e))?Math.round(e):e.toFixed(1)}%)`:kl(s);7.8*o.length+16>d&&(o=kl(s)),d>=7.8*o.length+16&&r.push(Im("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:o},t+"-funnel-value"))}return r.length?Im("g",{children:r},t+"-funnel-labels"):null}function Sl(e){return"connector"===e.node.type}function Ml(e,t,i,r){if(2>e.length)return null;let o=e[0].node,a=o.style.fill;if(!a||"none"===a)return null;let n=Ca(`${t?t+"-":""}connector-${i}-${r}-hatch`),l=ai(a)?li(a,n):null,s=[`${o.x1},${o.y1}`,...e.map(({node:e})=>`${e.x2},${e.y2}`)].join(" ");return Na(Om($m.Fragment,{children:[l&&zm("defs",{children:l}),zm("polygon",{points:s,fill:l?`url(#${n})`:Ra(a,"#999"),opacity:o.style.fillOpacity??o.style.opacity??.3,"data-semiotic-connector-fill":o.group||"_default"})]}),o,`ordinal-connector-fill-${i}-${r}`)}function _l(e,t,i){let r=new Map;for(let t of e){if(!Sl(t))continue;let e=t.node.group||"_default",i=r.get(e);i?i.push(t):r.set(e,[t])}if(0===r.size)return;let o=Array.from(r.values()).map((e,r)=>Om("g",{children:[Ml(e,t,i,r),e.map(e=>e.element)]},`ordinal-connectors-${i}-${r}`)),a=e[0],n=Sl(a)?null:a.element;for(let e of r.values())for(let t of e)t.element=null;a.element=Om($m.Fragment,{children:[o,n]},"ordinal-connector-run-"+i)}function Pl(e){let t=Ba({nodes:e.nodes,renderMode:e.renderMode,fallback:(t,i)=>function(e,t,i){return Na(function(e,t,i){let r=("category"in e?e.category:void 0)||("group"in e?e.group:void 0)||"",o=i=>`ord-${e.type}-${r}-${t}-${i}`,a=`ord-${e.type}-${r}-${t}`;switch(e.type){case"rect":{let t,i,r=e,o=Ca(a)+"-grad",n=function(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=e.x,o=e.y,a=e.x,n=e.y+e.h;"bottom"===e.roundedEdge?(o=e.y+e.h,n=e.y):"right"===e.roundedEdge?(r=e.x+e.w,o=e.y,a=e.x,n=e.y):"left"===e.roundedEdge&&(r=e.x,o=e.y,a=e.x+e.w,n=e.y);let l=Da(i.stops,Ra(e.style.fill));return l?Yy("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:r,y1:o,x2:a,y2:n,children:l}):null}(r,o);if(n)i=`url(#${o})`;else if(ai(r.style.fill)){let e=Ca(a)+"-hatch";t=li(r.style.fill,e),i=`url(#${e})`}else i=Ra(r.style.fill);let l=n||t?Dm("defs",{children:[n,t]}):null;if(r.cornerRadii&&ba(r.cornerRadii)){let e=function(e){let{x:t,y:i,w:r,h:o}=e,{tl:a,tr:n,br:l,bl:s}=va(e),c=`M${t+a},${i}`;return c+=` L${t+r-n},${i}`,n>0&&(c+=` A${n},${n} 0 0 1 ${t+r},${i+n}`),c+=` L${t+r},${i+o-l}`,l>0&&(c+=` A${l},${l} 0 0 1 ${t+r-l},${i+o}`),c+=` L${t+s},${i+o}`,s>0&&(c+=` A${s},${s} 0 0 1 ${t},${i+o-s}`),c+=` L${t},${i+a}`,a>0&&(c+=` A${a},${a} 0 0 1 ${t+a},${i}`),c+=" Z",c}(r);return Dm(Tm.Fragment,{children:[l,Im("path",{d:e,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth})]},a)}if(r.roundedTop&&r.roundedTop>0){let e,t=Math.min(r.roundedTop,r.w/2,r.h/2),{x:o,y:n,w:s,h:c}=r;switch(r.roundedEdge){case"right":e=`M${o},${n} L${o+s-t},${n} A${t},${t} 0 0 1 ${o+s},${n+t} L${o+s},${n+c-t} A${t},${t} 0 0 1 ${o+s-t},${n+c} L${o},${n+c} Z`;break;case"left":e=`M${o+s},${n} L${o+t},${n} A${t},${t} 0 0 0 ${o},${n+t} L${o},${n+c-t} A${t},${t} 0 0 0 ${o+t},${n+c} L${o+s},${n+c} Z`;break;case"bottom":e=`M${o},${n} L${o+s},${n} L${o+s},${n+c-t} A${t},${t} 0 0 1 ${o+s-t},${n+c} L${o+t},${n+c} A${t},${t} 0 0 1 ${o},${n+c-t} Z`;break;default:e=`M${o},${n+c} L${o},${n+t} A${t},${t} 0 0 1 ${o+t},${n} L${o+s-t},${n} A${t},${t} 0 0 1 ${o+s},${n+t} L${o+s},${n+c} Z`}return Dm(Tm.Fragment,{children:[l,Im("path",{d:e,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth})]},a)}return Dm(Tm.Fragment,{children:[l,Im("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth}),Al(r,a)]},a)}case"point":{let t=e;return Im("circle",{cx:t.x,cy:t.y,r:t.r,fill:Ra(t.style.fill),opacity:t.style.opacity??t.style.fillOpacity??.8,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},a)}case"symbol":return za(e,t,i);case"glyph":return Ia(e,e.x,e.y,`${i??""}ord-glyph-${e.pointId??t}`);case"wedge":{let r,o=e;if(o._gradientBand&&o._gradientBand.colors.length>0){let e=Ca(`${i?i+"-":""}gauge-grad-${o.category||a}-${t}`),{clipPath:r,slices:n}=function(e){let t=wl({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,cornerRadius:e.cornerRadius,roundStart:e.roundStart,roundEnd:e.roundEnd}),i=[],r=e.colors;if(r.length>0){let t=(e.endAngle-e.startAngle)/r.length;for(let o=0;r.length>o;o++)i.push({d:wl({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle+o*t,endAngle:e.endAngle}),color:r[o]})}return{clipPath:t,slices:i}}({innerRadius:o.innerRadius,outerRadius:o.outerRadius,startAngle:o.startAngle,endAngle:o.endAngle,cornerRadius:o.cornerRadius,roundStart:o.roundedEnds?.start??!0,roundEnd:o.roundedEnds?.end??!0,colors:o._gradientBand.colors});return Dm("g",{transform:`translate(${o.cx},${o.cy})`,opacity:o.style.opacity,fillOpacity:o.style.fillOpacity,children:[Im("defs",{children:Im("clipPath",{id:e,children:Im("path",{d:r})})}),Im("g",{clipPath:`url(#${e})`,children:n.map((e,t)=>Im("path",{d:e.d,fill:Ra(e.color)},t))}),o.style.stroke&&"none"!==o.style.stroke&&Im("path",{d:r,fill:"none",stroke:o.style.stroke,strokeWidth:o.style.strokeWidth})]},a)}if(o.roundedEnds)r=wl({innerRadius:o.innerRadius,outerRadius:o.outerRadius,startAngle:o.startAngle,endAngle:o.endAngle,cornerRadius:o.cornerRadius,roundStart:o.roundedEnds.start,roundEnd:o.roundedEnds.end});else{let e=Rm().innerRadius(o.innerRadius).outerRadius(o.outerRadius).startAngle(o.startAngle+Math.PI/2).endAngle(o.endAngle+Math.PI/2);o.cornerRadius&&e.cornerRadius(o.cornerRadius),r=e(Gy)||""}return Im("path",{d:r,transform:`translate(${o.cx},${o.cy})`,fill:Ra(o.style.fill),stroke:o.style.stroke,strokeWidth:o.style.strokeWidth,opacity:o.style.opacity},a)}case"boxplot":{let t=e,i=t.columnWidth/2,r=t.style.strokeWidth??1;return Dm("g","vertical"===t.projection?{children:[Im("line",{x1:t.x,y1:t.minPos,x2:t.x,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r}),Im("rect",{x:t.x-i,y:Math.min(t.q1Pos,t.q3Pos),width:t.columnWidth,height:Math.abs(t.q3Pos-t.q1Pos),fill:Ra(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),Im("line",{x1:t.x-i,y1:t.medianPos,x2:t.x+i,y2:t.medianPos,stroke:t.style.stroke||"#333",strokeWidth:2*r}),Im("line",{x1:t.x-.5*i,y1:t.minPos,x2:t.x+.5*i,y2:t.minPos,stroke:t.style.stroke||"#333",strokeWidth:r}),Im("line",{x1:t.x-.5*i,y1:t.maxPos,x2:t.x+.5*i,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r})]}:{children:[Im("line",{x1:t.minPos,y1:t.y,x2:t.maxPos,y2:t.y,stroke:t.style.stroke||"#333",strokeWidth:r}),Im("rect",{x:Math.min(t.q1Pos,t.q3Pos),y:t.y-i,width:Math.abs(t.q3Pos-t.q1Pos),height:t.columnWidth,fill:Ra(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),Im("line",{x1:t.medianPos,y1:t.y-i,x2:t.medianPos,y2:t.y+i,stroke:t.style.stroke||"#333",strokeWidth:2*r}),Im("line",{x1:t.minPos,y1:t.y-.5*i,x2:t.minPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r}),Im("line",{x1:t.maxPos,y1:t.y-.5*i,x2:t.maxPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r})]},a)}case"violin":{let t=e,i=[Im("path",{d:t.pathString,transform:t.translateX||t.translateY?`translate(${t.translateX},${t.translateY})`:void 0,fill:Ra(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:t.style.strokeWidth??1},o("path"))];if(t.iqrLine&&t.bounds){let e=t.bounds,r=e.x+e.width/2,a=e.y+e.height/2;t.iqrLine.isVertical?i.push(Im("line",{x1:r,y1:t.iqrLine.q1Pos,x2:r,y2:t.iqrLine.q3Pos,stroke:t.style.stroke||"#333",strokeWidth:2},o("iqr")),Im("circle",{cx:r,cy:t.iqrLine.medianPos,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},o("med"))):i.push(Im("line",{x1:t.iqrLine.q1Pos,y1:a,x2:t.iqrLine.q3Pos,y2:a,stroke:t.style.stroke||"#333",strokeWidth:2},o("iqr")),Im("circle",{cx:t.iqrLine.medianPos,cy:a,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},o("med")))}return Im("g",{children:i},a)}case"connector":{let t=e,i=t.style.fill&&"none"!==t.style.fill?Ra(t.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";return Im("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||i,strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity??.5},a)}case"trapezoid":{let t=e,i=t.points.map(e=>`${e[0]},${e[1]}`).join(" ");return Im("polygon",{points:i,fill:Ra(t.style.fill,"#999"),opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},a)}default:return null}}(e,t,i),e,"ordinal-cursor-"+t)}(t,i,e.idPrefix)}),i=0;for(let r=0;t.length>r;){if(t[r].renderedByBackend){r++;continue}let o=r+1;for(;t.length>o&&!t[o].renderedByBackend;)o++;_l(t.slice(r,o),e.idPrefix,i++),r=o}return t}function Ll(e,i){let r=le(e.theme),o=e.size||[500,400],n=l({...Wg,...e.margin},e.title),s=a(e.title),c=F(e.data),u=e.showLegend?Ka(c,e.colorAccessor||e.stackBy||e.groupBy):[],d=function(e){let t=e.projection??"vertical",i=!1!==e.showAxes&&"radial"!==t;return{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasValueLabel:e.hasCategoryLabel),leftAxis:{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasCategoryLabel:e.hasValueLabel)}}}({showAxes:e.showAxes,projection:e.projection,hasCategoryLabel:!(!e.categoryLabel&&!e.oLabel),hasValueLabel:!(!e.valueLabel&&!e.rLabel)});Gn(n,{props:{...e,axisChrome:d},categories:u,theme:r,size:o,hasTitle:s});let f=Vn({props:{...e,axisChrome:d},categories:u,theme:r,size:o,margin:n,hasTitle:s}),p=o[0]-n.left-n.right,y=o[1]-n.top-n.bottom,g=e.projection||"vertical",m="radial"===g,x=e.colorScheme||r.colors.categorical,b={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:g,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:ee(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:x,themeCategorical:r.colors.categorical,themeSemantic:lu(r),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:n,layoutSelection:e.layoutSelection,barColors:e.barColors},v=new Lm(b);e.data&&v.ingest({inserts:c,bounded:!0}),v.computeScene({width:p,height:y});let w=qn(e.backgroundGraphics,o,n,v.scales),k=qn(e.foregroundGraphics,o,n,v.scales);if(!v.scales){let t,a=e.annotations?kn({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:c,scales:{},layout:{width:p,height:y},theme:r,projection:g,idPrefix:e._idPrefix,onRender:e=>{t=e}}):null;return i&&(i.evidence=Ta({frameType:"ordinal",width:o[0],height:o[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,annotationRender:t,extraWarnings:v.scales?[]:["NO_SCALES"],margin:n})),sm.renderToStaticMarkup(Hn(w||k||e.annotations?jm(Em,{children:[w,a,k,v.customLayoutOverlays]}):null,{width:o[0],height:o[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:r,innerTransform:`translate(${n.left},${n.top})`,innerWidth:p,innerHeight:y,legend:f,idPrefix:e._idPrefix}))}let A=e._idPrefix,S=e.showGrid?function(e,t,i,r,o,a){let n=e.scales;if(!n||"radial"===n.projection)return null;let{grid:l}=se(i),s=r?r+"-":"",c="vertical"===n.projection,u=a??Rn(n.r,5,o);return zg("g",c?{id:s+"grid",className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=n.r(e);return zg("line",{x1:0,y1:r,x2:t.width,y2:r,stroke:l,strokeWidth:.5},"gr-"+i)})}:{id:s+"grid",className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=n.r(e);return zg("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:l,strokeWidth:.5},"gr-"+i)})})}(v,{width:p,height:y},r,A,e.axisExtent,e.rTickValues):null,M=null;if(v.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){let t=jn(e),i=new Set;for(let e of v.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&i.add("string"==typeof e.style.fill?e.style.fill:"#666");M=Array.from(i).map((e,i)=>function(e){let{id:t,background:i="transparent",stroke:r="#000",lineWidth:o=1.5,spacing:a=6,angle:n=45}=e,l=Math.max(8,Math.ceil(2*a));return Nm("pattern",{id:t,width:l,height:l,patternUnits:"userSpaceOnUse",patternTransform:0!==n?`rotate(${n})`:void 0,children:[i&&"transparent"!==i&&Fm("rect",{width:l,height:l,fill:i}),Fm("line",{x1:0,y1:0,x2:0,y2:l,stroke:r,strokeWidth:o}),Fm("line",{x1:a,y1:0,x2:a,y2:l,stroke:r,strokeWidth:o})]},t)}({id:`funnel-hatch-${t}-${i}`,background:e,stroke:"transparent"===r.colors.background?"#fff":r.colors.background,lineWidth:1.5,spacing:5,angle:45}));let o=new Map;Array.from(i).forEach((e,i)=>o.set(e,`funnel-hatch-${t}-${i}`));for(let e of v.scene)"rect"===e.type&&e.datum?.__barFunnelIsDropoff&&(e.style={...e.style,fill:`url(#${o.get("string"==typeof e.style.fill?e.style.fill:"#666")})`})}let _,P=Pl({nodes:v.scene,renderMode:e.renderMode,idPrefix:A}),L=P.map(e=>e.element),$=!1!==e.showAxes?function(e,i,r,o,a,n,l,s=!1){let c=e.scales;if(!c||"radial"===c.projection)return null;let u=se(o),d="vertical"===c.projection,f=e.columns,p=r.categoryFormat||r.oFormat,y=r.valueFormat||r.rFormat,g=r.categoryLabel||r.oLabel,m=r.valueLabel||r.rLabel,x=r.legendPosition??"right",b=h(r.legendLayout,l?.leftAxis),v=s&&"left"===x&&b>0?b:n?.left??r.margin?.left??40,w=Object.values(f).map((e,t)=>({pixel:e.middle,label:p?p(e.name,t):e.name})),k=r.rTickValues??Rn(c.r,5,r.axisExtent),A=y||t(k),S=k.map(e=>({pixel:c.r(e),label:A(e)}));return jm("g",d?{id:(a?a+"-":"")+"axes",className:"ordinal-axes",children:[Wm("line",{x1:0,y1:i.height,x2:i.width,y2:i.height,stroke:u.border,strokeWidth:1}),w.map((e,t)=>jm("g",{transform:`translate(${e.pixel},${i.height})`,children:[Wm("line",{y2:5,stroke:u.border,strokeWidth:1}),Cn(e.label)?Wm("text",{y:18,textAnchor:"middle",fontSize:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label}):In({label:e.label,x:-30,y:6,textAlign:"center",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"oxtick-"+t)),g&&Wm("text",{x:i.width/2,y:i.height+40,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,children:g}),Wm("line",{x1:0,y1:0,x2:0,y2:i.height,stroke:u.border,strokeWidth:1}),S.map((e,t)=>jm("g",{transform:`translate(0,${e.pixel})`,children:[Wm("line",{x2:-5,stroke:u.border,strokeWidth:1}),Wm("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label})]},"oytick-"+t)),m&&Wm("text",{x:15-v,y:i.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(-90, ${15-v}, ${i.height/2})`,children:m})]}:{id:(a?a+"-":"")+"axes",className:"ordinal-axes",children:[Wm("line",{x1:0,y1:i.height,x2:i.width,y2:i.height,stroke:u.border,strokeWidth:1}),S.map((e,t)=>jm("g",{transform:`translate(${e.pixel},${i.height})`,children:[Wm("line",{y2:5,stroke:u.border,strokeWidth:1}),Wm("text",{y:18,textAnchor:"middle",fontSize:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label})]},"oxtick-"+t)),m&&Wm("text",{x:i.width/2,y:i.height+40,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,children:m}),Wm("line",{x1:0,y1:0,x2:0,y2:i.height,stroke:u.border,strokeWidth:1}),w.map((e,t)=>jm("g",{transform:`translate(0,${e.pixel})`,children:[Wm("line",{x2:-5,stroke:u.border,strokeWidth:1}),Cn(e.label)?Wm("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label}):In({label:e.label,x:-68,y:-12,textAlign:"right",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},"oytick-"+t)),g&&Wm("text",{x:15-v,y:i.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(-90, ${15-v}, ${i.height/2})`,children:g})]})}(v,{width:p,height:y},e,r,A,n,d,!!f):null,T=e.annotations?kn({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:c,scales:{o:v.scales.o,r:v.scales.r,y:"vertical"===v.scales.projection?v.scales.r:void 0},layout:{width:p,height:y},theme:r,projection:g,xAccessor:"string"==typeof e.oAccessor?e.oAccessor:void 0,yAccessor:"string"==typeof e.rAccessor?e.rAccessor:void 0,idPrefix:A,onRender:e=>{_=e}}):null;if(i){let t=v.scales.o?.domain?.();i.evidence=Ta({frameType:"ordinal",width:o[0],height:o[1],marks:P.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:_,yDomain:$a(v.scales.r?.domain?.()),categories:Array.isArray(t)?t.map(String):void 0,margin:n})}let R=m&&e.centerContent?function(e,t,i){if(!am.isValidElement(e)||!lm.has(e.type))return null;let r=e,o="text"===r.type?am.cloneElement(r,{x:r.props.x??0,y:r.props.y??0,textAnchor:r.props.textAnchor??"middle",dominantBaseline:r.props.dominantBaseline??"middle"}):r;return nm("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:o})}(e.centerContent,n.left+p/2,n.top+y/2):null,C=m&&e.centerContent?R??Wm("foreignObject",{x:n.left,y:n.top,width:p,height:y,pointerEvents:"none",children:Wm("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null,I=jm(Em,{children:[S,L,$,T,k,v.customLayoutOverlays]});return sm.renderToStaticMarkup(Hn(jm(Em,m?{children:[w?Wm("g",{transform:`translate(${-p/2},${-y/2})`,children:w}):null,I]}:{children:[w,I]}),{width:o[0],height:o[1],className:"stream-ordinal-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:r,innerTransform:m?`translate(${n.left+p/2},${n.top+y/2})`:`translate(${n.left},${n.top})`,innerWidth:p,innerHeight:y,legend:f,defs:M,outerElements:C,idPrefix:e._idPrefix}))}function $l(e,t){Ym[e]=t}function Tl(e,t){var i=e.get(t);if(!i)throw Error("missing: "+t);return i}function Rl(e,t){function i(e){c[e]=!1,u.hasOwnProperty(e)&&Object.keys(u[e]).forEach(function(t){delete u[e][t],c[t]&&i(t)})}function r(e){var t,a,l=!1;for(s.push(e),c[e]=!0,t=0;d[e].length>t;t++)(a=d[e][t])===n?(o(n,s),l=!0):c[a]||(l=r(a));if(l)i(e);else for(t=0;d[e].length>t;t++){var h=u[a=d[e][t]];h||(u[a]=h={}),h[a]=!0}return s.pop(),l}function o(e,i){var r=[].concat(i).concat(e);t?t(r):l.push(r)}function a(t){!function(t){for(var i=0;e.length>i;i++)(t>i||!e[i])&&(e[i]=[]),e[i]=e[i].filter(function(e){return e>=t})}(t);for(var i,r=function(e){function t(t){var i=[t],c=[t];for(r[t]=o[t]=d,a[t]=!0,d+=1;c.length>0;){var u=e[t=c[c.length-1]];if(u.length>n[t]){for(var p=n[t];u.length>p;++p){var y=u[p];if(0>r[y]){r[y]=o[y]=d,a[y]=!0,d+=1,i.push(y),c.push(y);break}a[y]&&(o[t]=0|Math.min(o[t],o[y])),l[y]>=0&&s[t].push(l[y])}n[t]=p}else{if(o[t]===r[t]){var g=[],m=[],x=0;for(p=i.length-1;p>=0;--p){var b=i[p];if(a[b]=!1,g.push(b),m.push(s[b]),x+=s[b].length,l[b]=h.length,b===t){i.length=p;break}}h.push(g);var v=Array(x);for(p=0;m.length>p;p++)for(var w=0;m[p].length>w;w++)v[--x]=m[p][w];f.push(v)}c.pop()}}}for(var i=e.length,r=Array(i),o=Array(i),a=Array(i),n=Array(i),l=Array(i),s=Array(i),c=0;i>c;++c)r[c]=-1,o[c]=0,a[c]=!1,n[c]=0,l[c]=-1,s[c]=[];var u,d=0,h=[],f=[];for(c=0;i>c;++c)0>r[c]&&t(c);for(c=0;f.length>c;c++){var p=f[c];if(0!==p.length){p.sort(function(e,t){return e-t}),u=[p[0]];for(var y=1;p.length>y;y++)p[y]!==p[y-1]&&u.push(p[y]);f[c]=u}}return{components:h,adjacencyList:f}}(e),o=r.components.filter(function(e){return e.length>1}),a=1/0,n=0;o.length>n;n++)for(var l=0;o[n].length>l;l++)a>o[n][l]&&(a=o[n][l],i=n);var s=o[i];return!!s&&{leastVertex:a,adjList:e.map(function(e,t){return-1===s.indexOf(t)?[]:e.filter(function(e){return-1!==s.indexOf(e)})})}}var n,l=[],s=[],c=[],u={},d=[];n=0;for(var h=e.length;h>n;){var f=a(n);if(n=f.leastVertex,d=f.adjList){for(var p=0;d.length>p;p++)for(var y=0;d[p].length>y;y++){var g=d[p][y];c[+g]=!1,u[g]={}}r(n),n+=1}else n=h}if(!t)return l}function Cl(e){return e.y0-e.y1>0?"up":"down"}function Il(e,t){return t(e.source)==t(e.target)}function Dl(e){var t=0;e.source.sourceLinks.forEach(function(e){t=e.circular?t+1:t});var i=0;return e.target.targetLinks.forEach(function(e){i=e.circular?i+1:i}),!(t>1||i>1)}function zl(e){return e.target.x0-e.source.x1}function Ol(e,t){var i=Nl(e),r=zl(t)/Math.tan(i);return"up"==Cl(e)?e.y1-r:e.y1+r}function Fl(e,t){var i=Nl(e),r=zl(t)/Math.tan(i);return"up"==Cl(e)?e.y1+r:e.y1-r}function Nl(e){var t=Math.abs(e.y1-e.y0);return Math.atan(Math.abs(e.target.x0-e.source.x1)/t)}function El(e,t){return t(e)}function Wl(e){return Bl(e.source)}function jl(e){return Bl(e.target)}function Bl(e){return(e.y0+e.y1)/2}function Yl(e){return e.virtual?0:e.value}function Xl(e,t){var i=0;e.sourceLinks.forEach(function(e){i=e.circular&&!Il(e,t)?i+1:i});var r=0;return e.targetLinks.forEach(function(e){r=e.circular&&!Il(e,t)?r+1:r}),i+r}function Gl(e){return e.target.depth}function Vl(e,t){return e.sourceLinks.length?e.depth:t-1}function Hl(e,t){return e.y0-t.y0}function ql(e,t){return t.y0-e.y0}function Ul(e,t){return e.y1-t.y1}function Zl(e,t){return t.y1-e.y1}function Kl(e,t){return Jl(e.source,t.source)||e.index-t.index}function Ql(e,t){return Jl(e.target,t.target)||e.index-t.index}function Jl(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function es(e,t){return ts(e)==ts(t)?"bottom"==e.circularLinkType?ql(e,t):Hl(e,t):ts(t)-ts(e)}function ts(e){return e.target.column-e.source.column}function is(e,t){return rs(e)==rs(t)}function rs(e){return e.y0-e.y1>0?"up":"down"}function os(e,t,i,r,o){let a=e;var n=Math.max(8,.15*(a.y1-a.y0));a.links.forEach(function(e){e.circular&&(e._circularWidth=Math.min(e.width,n))});var l=Xm(a.links,function(e){return e.source.y0});a.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=a.links.filter(function(e){return e.circular});return s.sort(function(e,t){return t.value-e.value}),s.forEach(function(e,t){e._circularStub=t>=4}),as(a.links.filter(function(e){return"top"==e.circularLinkType}),t,i),as(a.links.filter(function(e){return"bottom"==e.circularLinkType}),t,i),a.links.forEach(function(e){if(e.circular){if(e.circularPathData.arcRadius=e._circularWidth+r,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,Il(e,t)&&Dl(e))e.circularPathData.rightSmallArcRadius=r+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=r+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=r+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=r+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+o+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-o-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius);else{var n=e.source.column,s=e.circularLinkType,c=a.links.filter(function(e){return e.source.column==n&&e.circularLinkType==s});c.sort("bottom"==e.circularLinkType?ql:Hl);var u=0;c.forEach(function(t,o){t.circularLinkID==e.circularLinkID&&(e.circularPathData.rightSmallArcRadius=r+e._circularWidth/2+u,e.circularPathData.rightLargeArcRadius=r+e._circularWidth/2+o*i+u),u+=t._circularWidth||t.width}),n=e.target.column,(c=a.links.filter(function(e){return e.target.column==n&&e.circularLinkType==s})).sort("bottom"==e.circularLinkType?Zl:Ul),u=0,c.forEach(function(t,o){t.circularLinkID==e.circularLinkID&&(e.circularPathData.leftSmallArcRadius=r+e._circularWidth/2+u,e.circularPathData.leftLargeArcRadius=r+e._circularWidth/2+o*i+u),u+=t._circularWidth||t.width}),"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(a.y1,e.source.y1,e.target.y1)+o+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=l-o-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)}e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer}e.path=e.circular?function(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}(e):function(e){var t=e.source.x1,i=e.y0,r=e.target.x0,o=e.y1,a=(t+r)/2;return"M"+t+","+i+"C"+a+","+i+" "+a+","+o+" "+r+","+o}(e)}),a}function as(e,t,i){e.sort(es);var r=e.filter(function(e){return!e._circularStub});return e.forEach(function(e,o){var a=0;if(e._circularStub)e.circularPathData.verticalBuffer=0;else if(Il(e,t)&&Dl(e))e.circularPathData.verticalBuffer=a+e._circularWidth/2;else{for(var n=0;r.length>n;n++){var l=r[n];if(l!==e&&l.circularPathData&&void 0!==l.circularPathData.verticalBuffer&&ns(e,l)){var s=l.circularPathData.verticalBuffer+(l._circularWidth||l.width)/2+i;a=s>a?s:a}}e.circularPathData.verticalBuffer=a+e._circularWidth/2}}),e}function ns(e,t){return!(t.target.column>e.source.column||e.target.column>t.source.column)}function ls(e){return function(){return e}}function ss(e){return e.index}function cs(e){return e.nodes}function us(e){return e.links}function ds(e,t,i){var r=Zm(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});r.forEach(function(o,a){var n=o.length;if(t)o.sort(t);else if(a>0){var l=new Map;o.forEach(function(e,t){var i,r,o,a=(r=0,o=0,(i=e).targetLinks.forEach(function(e){if(!e.circular){var t=e.value||1;o+=Bl(e.source)*t,r+=t}}),i.sourceLinks.forEach(function(e){if(!e.circular){var t=e.value||1;o+=Bl(e.target)*t,r+=t}}),r>0?o/r:NaN);l.set(e,{bc:a,idx:t})}),o.sort(function(e,t){var i=l.get(e),r=l.get(t),o=i.bc,a=r.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType||"bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(o)||isNaN(a)?isNaN(o)?isNaN(a)?i.idx-r.idx:1:-1:o-a})}else o.sort(function(e,t){return e.circularLinkType==t.circularLinkType?Xl(t,i)-Xl(e,i):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});o.forEach(function(t,o){t.depth==r.length-1&&1==n||0==t.depth&&1==n?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==Xl(t,i)?(t.y0=e.y1/2+o,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+o,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-o,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/n*o,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-n/2+o,t.y1=t.y0+t.value*e.ky)})})}function hs(e,t,i,r,o,a){function n(t,i){var r=s.length;s.forEach(function(o){var a=o.length,n=o[0].depth;o.forEach(function(o){var l;if(o.sourceLinks.length||o.targetLinks.length)if(o.partOfCycle&&Xl(o,i)>0){var s=qm(o.sourceLinks,jl),c=qm(o.targetLinks,Wl),u=s&&c?(s+c)/2:s||c;if(u){var d=(u-Bl(o))*t*.3;o.y0+=d,o.y1+=d}}else if(0==n&&1==a)o.y0=e.y1/2-(l=o.y1-o.y0)/2,o.y1=e.y1/2+l/2;else if(n==r-1&&1==a)o.y0=e.y1/2-(l=o.y1-o.y0)/2,o.y1=e.y1/2+l/2;else if(1==o.targetLinks.length&&1==o.targetLinks[0].source.sourceLinks.length)l=o.y1-o.y0,o.y0=o.targetLinks[0].source.y0,o.y1=o.y0+l;else{var h=qm(o.sourceLinks,jl),f=qm(o.targetLinks,Wl),p=((h&&f?(h+f)/2:h||f)-Bl(o))*t;o.y0+=p,o.y1+=p}})})}function l(){s.forEach(function(i){var a,n,l,s=e.y0,c=i.length;for(i.sort(t||Jl),l=0;c>l;++l)(n=s-(a=i[l]).y0)>0&&(a.y0+=n,a.y1+=n),s=a.y1+r;if((n=s-r-e.y1)>0)for(s=a.y0-=n,a.y1-=n,l=c-2;l>=0;--l)(n=(a=i[l]).y1+o-s)>0&&(a.y0-=n,a.y1-=n),s=a.y0})}var s=Zm(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});l();for(var c=1,u=a;u>0;--u)n(c*=.99,i),l()}function fs(e){e.nodes.forEach(function(e){e.sourceLinks.sort(Ql),e.targetLinks.sort(Kl)}),e.nodes.forEach(function(e){var t=e.y0,i=t,r=e.y1,o=r;e.sourceLinks.forEach(function(e){e.circular?(e.y0=r-e.width/2,r-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=o-e.width/2,o-=e.width):(e.y1=i+e.width/2,i+=e.width)})})}function ps(){function e(){var e={nodes:p.apply(null,arguments),links:y.apply(null,arguments)};return function(e){e.x0=t,e.y0=i,e.x1=r,e.y1=o,e.py=0,function(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var i=function(e,t){var i=new Map;return Um(e,t).forEach(function(e,t){i.set(t,e[0])}),i}(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var r=e.source,o=e.target;"object"!=typeof r&&(r=e.source=Tl(i,r)),"object"!=typeof o&&(o=e.target=Tl(i,o)),r.sourceLinks.push(e),o.targetLinks.push(e)})}(e,s),function(e,t){var i=0;if(null==t){for(var r=[],o=0;e.links.length>o;o++){var a=e.links[o],n=a.source.index,l=a.target.index;r[n]||(r[n]=[]),r[l]||(r[l]=[]),-1===r[n].indexOf(l)&&r[n].push(l)}var s=Rl(r);s.sort(function(e,t){return e.length-t.length});var c={};for(o=0;s.length>o;o++){var u=s[o].slice(-2);c[u[0]]||(c[u[0]]={}),c[u[0]][u[1]]=!0}e.links.forEach(function(e){var t=e.target.index,r=e.source.index;t===r||c[r]&&c[r][t]?(e.circular=!0,e.circularLinkID=i++):e.circular=!1})}else e.links.forEach(function(e){t(e.source)<t(e.target)?e.circular=!1:(e.circular=!0,e.circularLinkID=i++)})}(e,u),function(e,t){var i=0,r=0;e.links.forEach(function(o){o.circular&&(o.circularLinkType=o.source.circularLinkType||o.target.circularLinkType?o.source.circularLinkType?o.source.circularLinkType:o.target.circularLinkType:r>i?"top":"bottom","top"==o.circularLinkType?i++:r++,e.nodes.forEach(function(e){(El(e,t)==El(o.source,t)||El(e,t)==El(o.target,t))&&(e.circularLinkType=o.circularLinkType)}))}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),Il(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}(e,s),function(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(Hm(e.sourceLinks,Yl),Hm(e.targetLinks,Yl)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}(e),function(e,t,i){var r,o,a;if(null!=t){e.nodes.sort(function(e,i){return t(e)<t(i)?-1:1});var n=0,l=t(e.nodes[0]);e.nodes.forEach(function(e){n=t(e)==l?n:n+1,l=t(e)==l?l:t(e),e.column=n})}for(r=e.nodes,o=[],a=0;r.length;++a,r=o,o=[])r.forEach(function(e){e.depth=a,e.sourceLinks.forEach(function(e){0>o.indexOf(e.target)&&!e.circular&&o.push(e.target)})});for(r=e.nodes,o=[],a=0;r.length;++a,r=o,o=[])r.forEach(function(e){e.height=a,e.targetLinks.forEach(function(e){0>o.indexOf(e.source)&&!e.circular&&o.push(e.source)})});e.nodes.forEach(function(e){e.column=null==t?i(e,a):e.column})}(e,u,c);var p=n;if(null!==l){var y=Zm(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),g=Vm(y,function(e){return e.length});g>1&&(p=Math.max(1,(o-i)*l/(g-1)))}(function(e,t,i){var r=Zm(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var o=Gm(r,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/Hm(t,function(e){return e.value})});e.ky=o,e.links.forEach(function(t){t.width=t.value*e.ky});var a=Vm(e.nodes,function(e){return e.column});e.nodes.forEach(a>0?function(t){t.x0=e.x0+t.column*((e.x1-e.x0-i)/a),t.x1=t.x0+i}:function(t){t.x0=e.x0,t.x1=t.x0+i})})(e,p,a),ds(e,u,s),hs(e,u,s,p,p,d),fs(e),os(e,s,h,f,8),ds(e,u,s),hs(e,u,s,p,p,d),fs(e),os(e,s,h,f,8),function(e,t){let i=e;i.nodes.forEach(function(e){e.y+(e.y1-e.y0)>i.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-i.y1));var r=i.links.filter(function(i){return El(i.source,t)==El(e,t)}),o=r.length;o>1&&r.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!is(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var i=Ol(t,e);return e.y1-i}if(t.target.column>e.target.column)return Ol(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var a=e.y0;r.forEach(function(e){e.y0=a+e.width/2,a+=e.width}),r.forEach(function(t,i){if("bottom"==t.circularLinkType){for(var a=i+1,n=0;o>a;a++)n+=r[a].width;t.y0=e.y1-n-t.width/2}})})}(e,s),function(e,t){let i=e;i.nodes.forEach(function(e){var r=i.links.filter(function(i){return El(i.target,t)==El(e,t)}),o=r.length;o>1&&r.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!is(e,t))return e.y0-t.y0;if(e.source.column>t.source.column){var i=Fl(t,e);return e.y0-i}if(t.source.column>e.source.column)return Fl(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var a=e.y0;r.forEach(function(e){e.y1=a+e.width/2,a+=e.width}),r.forEach(function(t,i){if("bottom"==t.circularLinkType){for(var a=i+1,n=0;o>a;a++)n+=r[a].width;t.y1=e.y1-n-t.width/2}})})}(e,s),function(e){var t=e.nodes,i=e.links,r=!1,o=!1;if(i.forEach(function(e){"top"==e.circularLinkType?r=!0:"bottom"==e.circularLinkType&&(o=!0)}),0==r||0==o){let r=function(t){return(t-a)/(n-a)*(e.y1-e.y0)+e.y0};var a=Gm(t,function(e){return e.y0}),n=Vm(t,function(e){return e.y1}),l=(e.y1-e.y0)/(n-a);1>l?(t.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1)}),i.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1),e.width=e.width*l})):t.forEach(function(e){var t=e.y1-e.y0,i=r(e.y0)-e.y0;e.y0=r(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+i}),e.targetLinks.forEach(function(e){e.y1=e.y1+i})})}}(e),os(e,s,h,f,8)}(e),e}var t=0,i=0,r=1,o=1,a=24,n=8,l=null,s=ss,c=Vl,u=void 0,d=32,h=2,f=10,p=cs,y=us;return e.update=function(e){return fs(e),os(e,s,h,f,8),e},e.nodeWidth=function(t){return arguments.length?(a=+t,e):a},e.nodePadding=function(t){return arguments.length?(n=+t,e):n},e.nodePaddingRatio=function(t){return arguments.length?(l=+t,e):l},e.nodes=function(t){return arguments.length?(p="function"==typeof t?t:ls(t),e):p},e.links=function(t){return arguments.length?(y="function"==typeof t?t:ls(t),e):y},e.nodeId=function(t){return arguments.length?(s="function"==typeof t?t:ls(t),e):s},e.nodeAlign=function(t){return arguments.length?(c="function"==typeof t?t:ls(t),e):c},e.nodeSort=function(t){return arguments.length?(u=t,e):u},e.iterations=function(t){return arguments.length?(d=+t,e):d},e.circularLinkGap=function(t){return arguments.length?(h=+t,e):h},e.extent=function(a){return arguments.length?(t=+a[0][0],i=+a[0][1],r=+a[1][0],o=+a[1][1],e):[[t,i],[r,o]]},e.size=function(a){return arguments.length?(t=i=0,r=+a[0],o=+a[1],e):[r-t,o-i]},e}function ys(e){let t=e.sankeyWidth/2,i=(e._circularWidth??e.sankeyWidth)/2,r=e.circularPathData;if(!r||"down"===e.direction)return null;if(e._circularStub){let i=r.sourceX,o=r.sourceY,a=r.targetX,n=r.targetY;if("object"!=typeof e.source||!e.source||"object"!=typeof e.target||!e.target)return null;let l=Math.max(15,Math.min(40,.33*(r.rightFullExtent-i))),s=Math.max(15,Math.min(40,.33*(a-r.leftFullExtent)));return`M${i},${o-t}L${i+l},${o-t}L${i+l},${o+t}L${i},${o+t}ZM${a},${n-t}L${a-s},${n-t}L${a-s},${n+t}L${a},${n+t}Z`}let o=r.sourceX,a=r.sourceY,n=r.targetX,l=r.targetY,s=r.rightFullExtent,c=r.leftFullExtent,u=r.verticalFullExtent,d="bottom"===e.circularLinkType?1:-1,h=Math.max(4,Math.min(i,15));return`M${o},${a-d*t}L${s},${a-d*t}L${s+i},${a-d*t+d*h}L${s+i},${u+d*i-d*h}L${s+i-h},${u+d*i}L${c-i+h},${u+d*i}L${c-i},${u+d*i-d*h}L${c-i},${l-d*t+d*h}L${c-i+h},${l-d*t}L${n},${l-d*t}L${n},${l+d*t}L${c+i},${l+d*t}L${c+i},${u-d*i}L${s-i},${u-d*i}L${s-i},${a+d*t}L${o},${a+d*t}Z`}function gs(e,t){if("production"===process.env.NODE_ENV||!e||!e.data||"object"!=typeof e.data)return e;let i=ix.get(e);if(i){let e=i.get(t);if(e)return e}else i=new Map,ix.set(e,i);let r=new Proxy(e,{get(e,i,r){if("string"==typeof i&&!(i in e)&&e.data&&i in e.data){let e=`${t}:${i}`;tx.has(e)||(tx.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${i}" on the wrapper object, but it only exists on ".data". Use d.data.${i} (or d.data?.${i}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,i,r)}});return i.set(t,r),r}function ms(e,t,i){let r=[];for(let o of t){let t=Hc(o.source),a=Hc(o.target),n=null;if(t===e?n=a:a===e&&(n=t),n){let e=i.get(n);e&&(0!==e.x||0!==e.y)&&r.push({x:e.x,y:e.y})}}return r}function xs(e){let t=0;for(let i=0;e.length>i;i++)t=(t<<5)-t+e.charCodeAt(i)|0;return Math.abs(t)}function bs(e,t,i){let r=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!r)return e;let o=[],a=0;for(;r.length>a;){let e=r[a];if("M"===e||"L"===e||"C"===e||"Q"===e)for(o.push(e),a++;r.length>a&&!isNaN(Number(r[a]));)o.push(Number(r[a])+t+""),a++,r.length>a&&!isNaN(Number(r[a]))&&(o.push(Number(r[a])+i+""),a++);else if("A"===e)for(o.push(e),a++;r.length>a&&!isNaN(Number(r[a]));)o.push(r[a++]),r.length>a&&o.push(r[a++]),r.length>a&&o.push(r[a++]),r.length>a&&o.push(r[a++]),r.length>a&&o.push(r[a++]),r.length>a&&(o.push(Number(r[a])+t+""),a++),r.length>a&&(o.push(Number(r[a])+i+""),a++);else"Z"===e||"z"===e?(o.push(e),a++):(o.push(r[a]),a++)}return o.join(" ")}function vs(e){let[t,i,r]=function(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}(e);return.299*t+.587*i+.114*r>150?"#222":"#fff"}function ws(e,t,i){let r=t.nodeIDAccessor;return"function"==typeof r?r(e.data)+"":"string"==typeof r&&void 0!==e.data[r]?e.data[r]+"":void 0!==e.data.name?e.data.name+"":void 0!==e.data.id?e.data.id+"":"node-"+i}function ks(e){if(!e)return null;if("function"==typeof e){let t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function As(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:Mx}function Ss(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}function Ms(e,t,i,r,o){if("horizontal"===o){let o=(e+i)/2;return`M ${e},${t} C ${o},${t} ${o},${r} ${i},${r}`}if("radial"===o){let o=(e+i)/2;return`M ${e},${t} Q ${o},${t} ${o},${(t+r)/2} T ${i},${r}`}{let o=(t+r)/2;return`M ${e},${t} C ${e},${o} ${i},${o} ${i},${r}`}}function _s(e,t,i){let r=i.treeOrientation||"vertical";if("radial"===r){let i=t.x,r=t.y;e.x=r*Math.cos(i-Math.PI/2),e.y=r*Math.sin(i-Math.PI/2)}else"horizontal"===r?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);e.x0=e.x-5,e.x1=e.x+5,e.y0=e.y-5,e.y1=e.y+5,e.width=10,e.height=10}function Ps(e,t){e.x0=t.x0,e.x1=t.x1,e.y0=t.y0,e.y1=t.y1,e.x=(t.x0+t.x1)/2,e.y=(t.y0+t.y1)/2,e.width=t.x1-t.x0,e.height=t.y1-t.y0}function Ls(e,t){let i=t.r??0;e.x=t.x,e.y=t.y,e.x0=t.x-i,e.x1=t.x+i,e.y0=t.y-i,e.y1=t.y+i,e.width=2*i,e.height=2*i,e.__radius=i}function $s(e){let t=e.__orbitState;return t||(t={metaMap:new Map,startTime:"u">typeof performance?performance.now():Date.now()},e.__orbitState=t),t}function Ts(e){let t=e.id??e.datum?.id??e.datum?.data?.id??e.datum?.data?.name;return null==t?void 0:t+""}function Rs(e){if("glyph"===e.type&&e.glyph&&"number"==typeof e.size){let t=e.cx??e.x,i=e.cy??e.y;if("number"!=typeof t||"number"!=typeof i)return null;let r=Ru(e.glyph,e.size);return{x:t+r.centerDx,y:i+r.centerDy,r:Math.max(1,r.radius)}}let t=e.cx??(null!=e.x&&null!=e.w?e.x+e.w/2:e.x),i=e.cy??(null!=e.y&&null!=e.h?e.y+e.h/2:e.y);return"number"!=typeof t||"number"!=typeof i?null:{x:t,y:i,r:"number"==typeof e.r?Math.max(1,e.r):"number"==typeof e.outerR?Math.max(1,e.outerR):"number"==typeof e.size?Math.max(1,td(e.size)):Math.max(1,e.w??0,e.h??0)/2}}function Cs(e){if(!e)return;let t=[];for(let i of e){let e=Rs(i);e&&t.push({pointId:Ts(i),...e})}return t}function Is(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Ds(e){return e.map(e=>{let t=e.datum&&"object"==typeof e.datum?e.datum:{},i=t.data&&"object"==typeof t.data?t.data:t,r="cx"in e?e.cx:e.x+e.w/2,o="cy"in e?e.cy:e.y+e.h/2;return{...i,...null==i.id&&null!=e.id?{id:e.id}:{},x:r,y:o}})}function zs(e,t){let i=le(e.theme),r=e.chartType||"force",o=e.size||[500,500],n=function(e){return Yg.has(e)?Bg:jg}(r),s=l({...n,...e.margin},e.title),c=a(e.title),u=e.showLegend?(()=>{let t="string"==typeof(i=e.colorBy)||"function"==typeof i?e.colorBy:void 0;var i;if(!t)return[];let o=F(e.nodes||[]);if(o.length>0)return Ka(o,t);if(zx.has(r)&&e.data)return Ka(di(e.data,e.childrenAccessor||"children"),t);let a=Array.isArray(e.edges)?F(e.edges):[];if(0===a.length)return[];let n=Is(e.sourceAccessor,"source"),l=Is(e.targetAccessor,"target");return Ka(Array.from(new Set(a.flatMap(e=>[n(e),l(e)]).filter(e=>null!=e).map(String))).map(e=>({id:e})),t)})():[];Gn(s,{props:e,categories:u,theme:i,size:o,hasTitle:c});let d=Vn({props:e,categories:u,theme:i,size:o,margin:s,hasTitle:c}),h=o[0]-s.left-s.right,f=o[1]-s.top-s.bottom,p=qn(e.backgroundGraphics,o,s,null),y=qn(e.foregroundGraphics,o,s,null),g=()=>{let r,a=e=>Number(e),n=e.annotations?kn({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{x:a,y:a},layout:{width:h,height:f},theme:i,frameType:"network",idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;return t&&(t.evidence=(t=>Ta({frameType:"network",width:o[0],height:o[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,annotationRender:t,nodeCount:0,edgeCount:0,margin:s}))(r)),Bm.renderToStaticMarkup(Hn(p||y||e.annotations?Dx(Ix,{children:[p,n,y]}):null,{width:o[0],height:o[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${s.left},${s.top})`,innerWidth:h,innerHeight:f,legend:d,idPrefix:e._idPrefix}))},m=function(e){return Ym[e]}(r);if(!m&&!e.customNetworkLayout)throw Error(`No layout plugin found for chart type: "${r}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);let x,b,v={chartType:r,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,childrenAccessor:e.childrenAccessor,hierarchySum:e.hierarchySum,orientation:e.orientation,nodeAlign:e.nodeAlign,nodePaddingRatio:e.nodePaddingRatio,nodeWidth:e.nodeWidth,iterations:e.iterations,forceStrength:e.forceStrength,padAngle:e.padAngle,groupWidth:e.groupWidth,sortGroups:e.sortGroups,edgeSort:e.edgeSort,treeOrientation:e.treeOrientation,edgeType:e.edgeType,padding:e.padding,paddingTop:e.paddingTop,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme||i.colors.categorical,edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,orbitMode:e.orbitMode,orbitSize:e.orbitSize,orbitSpeed:e.orbitSpeed,orbitRevolution:e.orbitRevolution,orbitRevolutionStyle:e.orbitRevolutionStyle,orbitEccentricity:e.orbitEccentricity,orbitShowRings:e.orbitShowRings,orbitAnimated:!1,customNetworkLayout:e.customNetworkLayout,layoutConfig:e.layoutConfig};if(zx.has(r)){let t=e.data||e.edges;if(!t||Array.isArray(t))return g();v.__hierarchyRoot=t,x=[],b=[]}else{let t=F(e.nodes||[]),i=Array.isArray(e.edges)?F(e.edges):[];if(0===t.length&&0===i.length)return g();if(b=function(e,t){let i=Is(t.sourceAccessor,"source"),r=Is(t.targetAccessor,"target"),o=Is(t.valueAccessor,"value");return e.map((e,t)=>{let a=Number(o(e)),n=i(e)+"",l=r(e)+"";return{source:n,target:l,value:Number.isFinite(a)?a:1,y0:0,y1:0,sankeyWidth:0,data:e,_edgeKey:`${n}\0${l}\0${t}`}})}(i,v),0===t.length&&b.length>0){let e=new Set;for(let t of b){let i=Wn(t.source),r=Wn(t.target);i&&e.add(i),r&&e.add(r)}x=Array.from(e).map(e=>({id:e,x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:{id:e}}))}else x=function(e,t){let i=Is(t.nodeIDAccessor,"id");return e.map(e=>({id:i(e)+"",x:e.x??0,y:e.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:e}))}(t,v)}let w=[],k=[],A=[],S=null,M=null;if(v.customNetworkLayout){let e=v.colorScheme,t=$i(e,i.colors.categorical,vd),r=Ti(t,e),o={nodes:x,edges:b,dimensions:{width:h,height:f,plot:{x:0,y:0,width:h,height:f}},theme:{semantic:i.colors,categorical:[...t]},resolveColor:r,config:v.layoutConfig??{}},a=v.customNetworkLayout(o);w=a.sceneNodes??[],k=a.sceneEdges??[],A=a.labels??[],S=a.backgrounds??null,M=a.overlays??null}else if(m){m.computeLayout(x,b,v,[h,f]);let e=m.buildScene(x,b,v,[h,f]);w=e.sceneNodes,k=e.sceneEdges,A=e.labels}let _=se(i);for(let e of A)e.fill||(e.fill=_.text);let P,L=Ba({nodes:k,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){return Na(function(e,t){switch(e.type){case"line":return Rx("line",{x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,stroke:e.style.stroke||"#999",strokeWidth:e.style.strokeWidth??1,opacity:e.style.opacity},"net-edge-"+t);case"bezier":{let i=e,r=`net-bezier-${t}-hatch`,o=ai(i.style.fill)?li(i.style.fill,r):void 0;return Cx($x.Fragment,{children:[o&&Rx("defs",{children:o}),Rx("path",{d:i.pathD,fill:o?`url(#${r})`:Ra(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth,opacity:i.style.opacity})]},"net-edge-"+t)}case"ribbon":{let i=e,r=`net-ribbon-${t}-hatch`,o=ai(i.style.fill)?li(i.style.fill,r):void 0;return Cx($x.Fragment,{children:[o&&Rx("defs",{children:o}),Rx("path",{d:i.pathD,fill:o?`url(#${r})`:Ra(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth,opacity:i.style.opacity})]},"net-edge-"+t)}case"curved":{let i=e;return Rx("path",{d:i.pathD,fill:Ra(i.style.fill,"none"),stroke:i.style.stroke||"#999",strokeWidth:i.style.strokeWidth??1,opacity:i.style.opacity},"net-edge-"+t)}default:return null}}(e,t),e,"network-edge-cursor-"+t)}(e,t)}),$=Ba({nodes:w,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){return Na(function(e,t){switch(e.type){case"circle":{let i=e,r=ai(i.style.fill)?li(i.style.fill,`net-circle-${t}-hatch`):void 0;return Cx($x.Fragment,{children:[r&&Rx("defs",{children:r}),Rx("circle",{cx:i.cx,cy:i.cy,r:i.r,fill:r?`url(#net-circle-${t}-hatch)`:Ra(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity})]},"net-circle-"+t)}case"rect":{let i=e,r=ai(i.style.fill)?li(i.style.fill,`net-rect-${t}-hatch`):void 0;return Cx($x.Fragment,{children:[r&&Rx("defs",{children:r}),Rx("rect",{x:i.x,y:i.y,width:i.w,height:i.h,fill:r?`url(#net-rect-${t}-hatch)`:Ra(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity})]},"net-rect-"+t)}case"arc":{let i=e,r=Tx().innerRadius(i.innerR).outerRadius(i.outerR).startAngle(i.startAngle+Math.PI/2).endAngle(i.endAngle+Math.PI/2)(Gy)||"",o=ai(i.style.fill)?li(i.style.fill,`net-arc-${t}-hatch`):void 0;return Cx($x.Fragment,{children:[o&&Rx("defs",{children:o}),Rx("path",{d:r,transform:`translate(${i.cx},${i.cy})`,fill:o?`url(#net-arc-${t}-hatch)`:Ra(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity})]},"net-arc-"+t)}case"symbol":{let i=e,r=ed(i.symbolType,i.size,i.path);return Rx("path",{d:r,transform:i.rotation?`translate(${i.cx},${i.cy}) rotate(${180*i.rotation/Math.PI})`:`translate(${i.cx},${i.cy})`,fill:i.style.fill?Ra(i.style.fill):"none",stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity},"net-symbol-"+t)}case"glyph":return Ia(e,e.cx,e.cy,"net-glyph-"+(e.id??t));default:return null}}(e,t),e,"network-node-cursor-"+t)}(e,t)}),T=L.map(e=>e.element),R=$.map(e=>e.element),C=A.map((e,t)=>function(e,t){return Rx("text",{x:e.x,y:e.y,textAnchor:e.anchor||"middle",dominantBaseline:e.baseline||"auto",fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"var(--semiotic-text, #333)",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,children:e.text},"net-label-"+t)}(e,t)).filter(Boolean),I=e=>Number(e),D=e.annotations?kn({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{x:I,y:I},layout:{width:h,height:f},theme:i,frameType:"network",annotationData:Ds(w),pointNodes:Cs(w),idPrefix:e._idPrefix,onRender:e=>{P=e}}):null;return t&&(t.evidence=Ta({frameType:"network",width:o[0],height:o[1],marks:[...$.map(({node:e})=>({type:"node:"+(e.type??"node")})),...L.map(({node:e})=>({type:"edge:"+(e.type??"edge")}))],title:e.title,description:e.description,annotations:e.annotations,annotationRender:P,nodeCount:$.length,edgeCount:L.length,margin:s})),Bm.renderToStaticMarkup(Hn(Dx(Ix,{children:[p,S,T,R,C,D,y,M]}),{width:o[0],height:o[1],className:"stream-network-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${s.left},${s.top})`,innerWidth:h,innerHeight:f,legend:d,idPrefix:e._idPrefix}))}function Os(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function Fs(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function Ns(e,t,i){return e?"function"==typeof e?{...i,...e(t)}:{...i,...e}:{...i}}function Es(e,t){if(2>e.length)return[e];let i=.4*t,r=[],o=[e[0]];for(let t=1;e.length>t;t++){let a=e[t];Math.abs(a[0]-e[t-1][0])>i?(o.length>=2&&r.push(o),o=[a]):o.push(a)}return o.length>=2&&r.push(o),r}function Ws(e,t,i=24){let r=t[0]-e[0],o=t[1]-e[1],a=Math.sqrt(r*r+o*o);if(0===a)return[e,t];let n=-o/a,l=r/a,s=Math.min(.3*a,80),c=(e[0]+t[0])/2+n*s,u=(e[1]+t[1])/2+l*s,d=[];for(let r=0;i>=r;r++){let o=r/i,a=1-o;d.push([a*a*e[0]+2*a*o*c+o*o*t[0],a*a*e[1]+2*a*o*u+o*o*t[1]])}return d}function js(e,t){if(2>e.length)return e;let i=t/2+1,r=[];for(let t=0;e.length>t;t++){let o,a,n=e[t];0===t?(o=e[1][0]-n[0],a=e[1][1]-n[1]):t===e.length-1?(o=n[0]-e[t-1][0],a=n[1]-e[t-1][1]):(o=e[t+1][0]-e[t-1][0],a=e[t+1][1]-e[t-1][1]);let l=Math.sqrt(o*o+a*a)||1;r.push([n[0]+a/l*i,n[1]+-o/l*i])}return r}function Bs(e,t,i,r,o){let a=t[0]-e[0],n=t[1]-e[1],l=Math.sqrt(a*a+n*n);if(0===l)return[e,t];let s=n/l,c=-a/l,u=o/2+1;return[[e[0]+s*u,e[1]+c*u],[t[0]+s*u,t[1]+c*u]]}function Ys(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&.5>e)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${e+""}.`)}function Xs(e){if(!e)return;let t=[];for(let i of e)if("point"===i.type)t.push(i);else if("glyph"===i.type){let e=i,r=Ru(e.glyph,e.size);t.push({pointId:e.pointId,x:e.x+r.centerDx,y:e.y+r.centerDy,r:r.radius})}return t}function Gs({bottomMargin:e,costLabel:t,layout:{cx:i,cy:r,maxCost:o,availableRadius:a,layout:n},ringStyle:l,ringValues:s,showNorth:c,showRingLabels:u,showRings:d}){let h="strip"===n,f={stroke:h?"var(--semiotic-border, #999)":"#999",strokeWidth:h?1:.8,strokeDasharray:h?"none":"4,3",labelColor:"var(--semiotic-text-secondary, #777)",labelSize:h?8:10,...l};return pb("g",h?{children:[fb("line",{x1:i,y1:r,x2:i+a,y2:r,stroke:f.stroke,strokeWidth:f.strokeWidth,strokeLinecap:"round",opacity:.85}),fb("line",{x1:i,y1:r-3.5,x2:i,y2:r+3.5,stroke:f.stroke,strokeWidth:f.strokeWidth,opacity:.9}),d&&s.map(n=>{let l=i+(o>0?n/o*a:0);return pb("g",{children:[fb("line",{x1:l,y1:r-2.5,x2:l,y2:r+2.5,stroke:f.stroke,strokeWidth:.9,opacity:.65}),u&&pb("text",{x:l,y:r+Math.min(10,(e??2)+8),textAnchor:"middle",fontSize:f.labelSize,fill:f.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[n,t?" "+t:""]})]},n)})]}:{children:[s.map(e=>{let n=e/o*a;return pb("g",{children:[fb("circle",{cx:i,cy:r,r:n,fill:"none",stroke:f.stroke,strokeWidth:f.strokeWidth,strokeDasharray:f.strokeDasharray,opacity:.5}),u&&pb("text",{x:i+n+3,y:r-2,fontSize:f.labelSize,fill:f.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[e,t?" "+t:""]})]},e)}),c&&pb("g",{transform:"translate(24, 24)",children:[fb("circle",{r:16,fill:"white",fillOpacity:.85,stroke:"#bbb",strokeWidth:.8}),fb("path",{d:"M0,-11 L3,-3 L1,-4 L1,7 L-1,7 L-1,-4 L-3,-3 Z",fill:"#555",stroke:"none"}),fb("text",{y:-12,textAnchor:"middle",fontSize:7,fontWeight:700,fill:"#555",fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:"N"}),fb("line",{x1:11,y1:0,x2:13,y2:0,stroke:"#bbb",strokeWidth:.8}),fb("line",{x1:-11,y1:0,x2:-13,y2:0,stroke:"#bbb",strokeWidth:.8}),fb("line",{x1:0,y1:11,x2:0,y2:13,stroke:"#bbb",strokeWidth:.8})]})]})}function Vs(e,t){let i=le(e.theme),r=e.size||[e.width||600,e.height||400],o=l({top:10,right:10,bottom:10,left:10,...e.margin},e.title),n=a(e.title),s=Array.isArray(e.areas)?F(e.areas):e.areas,c=F(e.points),u=F(e.lines),d=e.showLegend?(()=>{let t="string"==typeof(i=e.colorBy)||"function"==typeof i?e.colorBy:void 0;var i;return Ka(c.length>0?c:Array.isArray(s)&&s.length>0?"string"==typeof t?s.map(e=>({...e.properties||{},...e})):s:[],t)})():[];Gn(o,{props:e,categories:d,theme:i,size:r,hasTitle:n});let h=Vn({props:e,categories:d,theme:i,size:r,margin:o,hasTitle:n}),f=r[0]-(o.left??0)-(o.right??0),p=r[1]-(o.top??0)-(o.bottom??0),y={projection:e.projection||"equalEarth",projectionExtent:e.projectionExtent,xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineIdAccessor:e.lineIdAccessor,lineType:e.lineType,flowStyle:e.flowStyle,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,colorScheme:e.colorScheme,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,onLayoutError:e.onLayoutError,themeCategorical:i.colors.categorical,themeSemantic:lu(i),themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging},g=new cb(y);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.`);g.setAreas(s)}e.points&&g.setPoints(c),e.lines&&g.setLines(u),g.computeScene({width:f,height:p});let m=qn(e.backgroundGraphics,r,o,g.scales),x=qn(e.foregroundGraphics,r,o,g.scales),b=Ba({nodes:g.scene,renderMode:e.renderMode,fallback:(e,t)=>function(e,t){return Na(function(e,t){switch(e.type){case"geoarea":{let i=e;if(!i.pathData)return null;let r=ai(i.style.fill)?li(i.style.fill,`geoarea-${t}-hatch`):void 0;return hb(ub.Fragment,{children:[r&&db("defs",{children:r}),db("path",{d:i.pathData,fill:r?`url(#geoarea-${t}-hatch)`:Ra(i.style.fill,"#e0e0e0"),fillOpacity:i.style.fillOpacity??1,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth??.5,strokeDasharray:i.style.strokeDasharray,opacity:i._decayOpacity??1})]},"geoarea-"+t)}case"point":{let i=e,r=ai(i.style.fill)?li(i.style.fill,`geopoint-${t}-hatch`):void 0;return hb(ub.Fragment,{children:[r&&db("defs",{children:r}),db("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#geopoint-${t}-hatch)`:Ra(i.style.fill),fillOpacity:i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i._decayOpacity??i.style.opacity??1})]},"point-"+t)}case"line":{let i=e;if(2>i.path.length)return null;let r="M"+i.path.map(e=>`${e[0]},${e[1]}`).join("L");return db("path",{d:r,fill:"none",stroke:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth??1.5,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity??1},"line-"+t)}case"glyph":return Ia(e,e.x,e.y,"geo-glyph-"+(e.pointId??t));default:return null}}(e,t),e,"geo-cursor-"+t)}(e,t)});if(0===b.length){let a,n=e.annotations?kn({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:g.scales?.projectedPoint?([e,t])=>g.scales.projectedPoint(e,t):void 0},layout:{width:f,height:p},theme:i,pointNodes:Xs(g.scene),idPrefix:e._idPrefix,onRender:e=>{a=e}}):null;return t&&(t.evidence=Ta({frameType:"geo",width:r[0],height:r[1],marks:b.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:a,legendItems:d.length>0?d.length:null!=e.legend?1:void 0,margin:o})),Ox.renderToStaticMarkup(Hn(m||x||e.annotations||g.customLayoutOverlays?mb(yb,{children:[m,n,x,g.customLayoutOverlays]}):null,{width:r[0],height:r[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${o.left??0},${o.top??0})`,innerWidth:f,innerHeight:p,legend:h,idPrefix:e._idPrefix}))}let v,w=b.map(e=>e.element),k=e.cartogramChrome,A=g.cartogramLayout&&k?gb(Gs,{layout:{...g.cartogramLayout,layout:g.cartogramLayout.layout??"radial"},ringValues:Hs(g.cartogramLayout.maxCost,k.showRings),showRings:k.showRings??!0,showNorth:k.showNorth??!0,showRingLabels:k.showRingLabels??!0,costLabel:"string"==typeof k.costLabel?k.costLabel:void 0}):null,S=e.annotations?kn({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:g.scales?.projectedPoint?([e,t])=>g.scales.projectedPoint(e,t):void 0},layout:{width:f,height:p},theme:i,pointNodes:Xs(g.scene),idPrefix:e._idPrefix,onRender:e=>{v=e}}):null;return t&&(t.evidence=Ta({frameType:"geo",width:r[0],height:r[1],marks:b.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:v,legendItems:d.length>0?d.length:null!=e.legend?1:void 0,margin:o})),Ox.renderToStaticMarkup(Hn(mb(yb,{children:[m,w,S,A,x,g.customLayoutOverlays]}),{width:r[0],height:r[1],className:"stream-geo-frame"+(e.className?" "+e.className:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${o.left??0},${o.top??0})`,innerWidth:f,innerHeight:p,legend:h,idPrefix:e._idPrefix}))}function Hs(e,t){if(!1===t||0>=e)return[];if(Array.isArray(t))return t.filter(t=>t>0&&e>=t);let i="number"==typeof t?t:Math.min(5,Math.max(2,Math.ceil(e/5))),r=e/i,o=[];for(let e=1;i>=e;e++)o.push(Math.round(r*e*10)/10);return o}function qs(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}function Us(e){let t=e.datum;if(t&&"object"==typeof t){let e=t.label??t.name??t.id;if(null!=e&&""!==e)return e+""}return e.id}function Zs(e,t,i){let r="function"==typeof t?t(e,i):t;return{...bb,...r??{}}}function Ks(e,t={},i="settled"){return e.map((e,r)=>function(e,t={},i={index:0,simulationState:"settled"}){let r=function(e){return e.datum&&"object"==typeof e.datum?e.datum:null}(e),o={label:t.getBodyLabel?.(e)??Us(e)},a={style:Zs(e,t.bodyStyle,i),datum:r,accessibleDatum:r,accessibility:o,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...a}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...a}}(e,t,{index:r,simulationState:i}))}function Qs(e,t,i){return"function"==typeof e?e({size:t,margin:i}):e}function Js(e,t={}){let{element:i,scene:r,evidence:o}=function(e,t={}){let{width:i=640,height:r=360,title:o,description:a,background:n,backgroundGraphics:l,backgroundGraphicsBackdrop:s,className:c,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:f,renderBodySVG:p,renderChrome:y,...g}=t,m=function(e,t={}){let i=e.settle(t.maxSteps),r=e.readBodies(),o=e.snapshot(),a=Ks(r,t,o.simulationState),n=function(e,t={}){let i=t.bodies??function(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}(e),r=i.filter(e=>e.sleeping).length,o=e.queue.length,a=e.sediment.reduce((e,t)=>e+t.count,0),n="settled"===e.simulationState&&0===o&&r===i.length,l=[];n||l.push("PHYSICS_NOT_SETTLED"),o>0&&l.push("PHYSICS_QUEUE_UNDRAINED");let s=null!=t.charge&&Number.isFinite(t.charge)?function(e,t,i,r){let o=e-(t+i+r);return{charge:e,live:t,queued:i,sedimented:r,unaccounted:o,balanced:0===o}}(t.charge,i.length,o,a):void 0;return s&&!s.balanced&&l.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:i.length,sleepingCount:r,settled:n,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:qs(t.projectionRows),queuedCount:o,sedimentedCount:a,...s?{ledger:s}:{},warnings:l}}(o,{bodies:r,projectionRows:t.projectionRows,stepsRun:i,charge:t.charge});return{snapshot:o,bodies:r,sceneNodes:a,evidence:n,stepsRun:i}}(e,g),x={...kb,...h},b=[i,r],v=Qs(l,b,x),w=Qs(u,b,x),k=function(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?"physics-"+t:t}(d),A=o?k+"-title":void 0,S=a?k+"-desc":void 0,M=[A,S].filter(Boolean).join(" ")||void 0,_=x.left||x.top?`translate(${x.left},${x.top})`:void 0,P=Math.max(1,i-x.left-x.right),L=Math.max(1,r-x.top-x.bottom),$=k+"-plot-clip",T=_&&null!=v?vb("g",{transform:_,children:v}):v;return{element:wb("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-labelledby":M,style:f,children:[o&&vb("title",{id:A,children:o}),a&&vb("desc",{id:S,children:a}),vb("defs",{children:vb("clipPath",{id:$,children:vb("rect",{width:P,height:L})})}),s&&"transparent"!==s?vb("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:i,height:r,fill:s}):null,!l&&n&&"transparent"!==n?vb("rect",{x:0,y:0,width:i,height:r,fill:n}):null,T,vb("g",{id:k+"-data-area",transform:_,clipPath:`url(#${$})`,children:m.sceneNodes.map((e,t)=>{let i=m.bodies[t],r=i&&p?p(i,e.style??{},t,k):void 0;return null!=r?Na(r,e,t):Na("point"===e.type||"rect"===e.type?Oa(e,t,k):null,e,"xy-cursor-"+t)})}),w,y?.(m)]}),scene:m,evidence:m.evidence}}(e,t);return{svg:xb.renderToStaticMarkup(i),scene:r,evidence:o}}function ec(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function tc(e,t){let i="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,ec(e.thickness)??ec(i)??ec(t.thickness)??4)}function ic(e){return e.sensorId??"stream-region-"+e.id}function rc(e){let t=ic(e),i={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){let r=e.colliderThickness??8,o=e.shape.x-e.shape.width/2,a=e.shape.x+e.shape.width/2,n=e.shape.y-e.shape.height/2,l=e.shape.y+e.shape.height/2;return[{...i,id:t+"-top",shape:{type:"segment",x1:o,y1:n,x2:a,y2:n,thickness:r}},{...i,id:t+"-right",shape:{type:"segment",x1:a,y1:n,x2:a,y2:l,thickness:r}},{...i,id:t+"-bottom",shape:{type:"segment",x1:a,y1:l,x2:o,y2:l,thickness:r}},{...i,id:t+"-left",shape:{type:"segment",x1:o,y1:l,x2:o,y2:n,thickness:r}}]}return e.collider?[{...i,id:t+"-collider",shape:e.shape}]:[]}function oc({title:e,totalWidth:t,marginTop:i}){return e?"string"!=typeof e?Ab("foreignObject",{x:0,y:0,width:t,height:i,children:e}):Ab("text",{x:t/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:e}):null}function ac(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function nc(e,t){let i=e.size??[e.width??600,e.height??400],r=le(e.theme),o=void 0===e.theme?{}:su(r),a=e.bodyStyle,l=!1,c=e.legendPosition??"right",u=n({...Pb,...e.margin},l,!!e.legend&&"top"===c);if(e.legend){let t={...u};x(u,{legend:e.legend,position:c,size:i,hasTitle:l,legendLayout:e.legendLayout}),s(u,t,i,c)}let d,h=function({annotations:e,chartId:t,chartType:i,config:r,onRegionObservation:o,regionEffects:a,seed:n,size:l}){let s=function(e=[],t={}){let i=t.idPrefix?t.idPrefix+"-":"",r=[];for(let o of e){if("barrier"!==o.physics&&"sensor"!==o.physics)continue;let e,a=o.axis??t.defaultAxis??"x",n=tc(o,t),l=o.colliderId??`${i}${o.id}`;if("x"===a){let i=ec(o.x),r=ec(o.y1)??ec(t.plotBounds?.y)??ec(o.y),a=ec(o.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??ec(o.y);if(null==i||null==r||null==a)continue;e={type:"segment",x1:i,y1:r,x2:i,y2:a,thickness:n}}else{let i=ec(o.y),r=ec(o.x1)??ec(t.plotBounds?.x)??ec(o.x),a=ec(o.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??ec(o.x);if(null==i||null==r||null==a)continue;e={type:"segment",x1:r,y1:i,x2:a,y2:i,thickness:n}}r.push({id:l,shape:e,sensor:"sensor"===o.physics,..."barrier"!==o.physics||null==o.restitution&&null==t.barrierRestitution?{}:{restitution:ec(o.restitution)??ec(t.barrierRestitution)},..."barrier"!==o.physics||null==o.friction&&null==t.barrierFriction?{}:{friction:ec(o.friction)??ec(t.barrierFriction)}})}return r}((e??[]).filter(e=>"barrier"===e.physics||"sensor"===e.physics),{idPrefix:t?t+"-ann":"physics-ann",plotBounds:{x:0,y:0,width:l[0],height:l[1]}}),c=void 0===n||void 0!==r?.kernel?.seed?r:{...r,kernel:{...r?.kernel,seed:n}},u=a.flatMap(e=>[{id:ic(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...rc(e)]),d=Object.fromEntries(a.map(e=>[ic(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,f=a.length>0;return f||u.length>0||s.length>0||null!=t||h?{...c,colliders:[...c?.colliders??[],...u,...s],observation:{...h,chartId:t??h?.chartId,chartType:h?.chartType??i,sensors:{...h?.sensors??{},...d},onObservation:e=>{f&&o(e),h?.onObservation?.(e)}}}:c}({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:[Math.max(1,i[0]-u.left-u.right),Math.max(1,i[1]-u.top-u.bottom)]}),f=new yu(h);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&f.enqueue(e.initialSpawns.map(e=>({...e,spawnAt:void 0})));let p=Js(f,{...e,width:i[0],height:i[1],background:e.background??r.colors.background,bodyStyle:(e,t)=>({fill:r.colors.primary,stroke:r.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof a?a(e,t):a}),style:{...o,fontFamily:r.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:u,renderChrome:t=>{let o=function(e,t,i,r,o){let a=Math.max(1,i[0]-r.left-r.right),n=Math.max(1,i[1]-r.top-r.bottom),l=function(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:e.bodyId+""}):e}(t.annotations),s=function(e){let{width:t,height:i,pointNodes:r=[],data:o}=e;return{scales:{x:Sb().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:Sb().domain([0,Math.max(1,i)]).range([0,Math.max(1,i)])},width:t,height:i,frameType:"network",pointNodes:r,data:o,xAccessor:"x",yAccessor:"y"}}({width:a,height:n,pointNodes:(d=e.bodies,d.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,ac(e))})))}),c=s.scales?.x,u=s.scales?.y;var d;if(!c||!u)throw Error("Physics annotation context requires pixel scales");let h,f=kn({annotations:l,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{x:c,y:u},layout:{width:a,height:n},theme:o,frameType:"network",xAccessor:s.xAccessor,yAccessor:s.yAccessor,pointNodes:s.pointNodes,svgAnnotationRules:t.svgAnnotationRules,onRender:e=>{h=e}}),p=t.legend?Xn(t.legend,{theme:o,position:t.legendPosition,size:[i[0],i[1]],margin:r,hasTitle:!!t.title,legendLayout:t.legendLayout})??An(t.legend,i,r,t.legendPosition,t.legendLayout):null;return{annotationRender:h,node:_b("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i[0],height:i[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[Mb("g",{transform:`translate(${r.left},${r.top})`,children:f}),Mb(oc,{title:t.title,totalWidth:i[0],marginTop:Math.max(r.top,28)}),p]})}}(t,e,i,u,r);return d=o.annotationRender,o.node}});return t&&(t.evidence=Ta({frameType:"physics",width:i[0],height:i[1],marks:p.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:d,extraWarnings:[...0===p.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...p.scene.evidence.warnings]})),p.svg}function lc(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}function sc(e,t,i){return Cb[e](t,i)}function cc(e,t){switch(e){case"xy":return Un(t);case"ordinal":return Ll(t);case"network":return zs(t);case"geo":return Vs(t);case"physics":return nc(t);default:throw Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function uc(e){return Un(e)}function dc(e){return Ll(e)}function hc(e){return zs(e)}function fc(e){return Vs(e)}function pc(e,t){let i=Number(e);if(!Number.isFinite(i))return e;let r=10**t,o=Math.round((i+Number.EPSILON)*r)/r;return Object.is(o,-0)?"0":o+""}function yc(e,t){let i=function(e){if(Number.isFinite(e))return Math.max(0,Math.min(8,Math.floor(e)))}(t);return void 0===i?e:function(e){let t=A(e)?.start??0;return e.slice(0,t)+e.slice(t).replace(/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<([A-Za-z_][\w.:-]*)(?=[\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>/g,(e,t)=>t?e.replace(cd,(e,t,r,o)=>{let a=((e,t)=>{if(Nb.has(e)&&!/\b(?:var|calc|url)\(/i.test(t))return function(e,t){let i,r=RegExp(Eb.source,Eb.flags),o="",a=0,n=!1;for(;i=r.exec(e);){let r=e.slice(a,i.index);o+=n&&0===r.length?" ":r,o+=pc(i[0],t),a=i.index+i[0].length,n=!0}return o+e.slice(a)}(t,i)})(t,M(r??o));return void 0===a?e:` ${t}="${S(a)}"`}):e)}(e)}function gc(e,t){let i={};for(let r of t)void 0!==e[r]&&(i[r]=e[r]);return i}function mc(e,t,i){return bc(e,t,i).svg}function xc(e,t,i){let r={},{svg:o,frameType:a}=bc(e,t,i,r),n=r.evidence??Ta({frameType:a,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});if(n.component=e,n.sceneHashVersion=2,n.sceneHash=function(e,t){return Jc({kind:"semiotic.rendered-svg-scene",version:2,svg:e,frameType:t.frameType,width:t.width,height:t.height,margin:t.margin,plot:t.plot,xDomain:t.xDomain,yDomain:t.yDomain,categories:t.categories})}(o,n),z(n,e,t),i?.artifactContract){let r=Qc(i.artifactContract,{excludeEvidenceSamples:!0});r.contract&&(n.artifactContract=r.contract),n.artifactTransfer=r.transfer,n.artifactBinding="0.1"===r.contract?.contractVersion&&"invalid"!==r.transfer.status?Ic(r.contract,t,e):{status:"unknown",mismatchPaths:[],unknownPaths:["artifactContract"]}}return{svg:o,evidence:n}}function bc(e,t,i,r){if(Object.prototype.hasOwnProperty.call(Cb,e))return{svg:yc(sc(e,t,r),i?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(om,e))throw Error(`Unknown chart component: "${e}". Run \`npx semiotic-ai --list\` for supported chart types.`);let o,a=om[e],n=function(e,t,i){let r=dd[e||"primary"],o=e&&"primary"!==e||!i?.width?r.width:i.width,a=e&&"primary"!==e||!i?.height?r.height:i.height,n=function(e,t,i=e.responsiveRules){if(!Array.isArray(i)||0===i.length)return{props:e,matches:[]};let r=i.map((e,t)=>({rule:e,index:t})).filter(e=>function(e,t){let{when:i}=e,r=t.width,o=t.height,a=function(e){if("number"==typeof e.height&&e.height>0)return e.width/e.height}(t),n=function(e){if("number"==typeof e.height&&e.height>0)return e.height>e.width?"portrait":"landscape"}(t);return!("number"==typeof i.minWidth&&i.minWidth>r||"number"==typeof i.maxWidth&&r>i.maxWidth||"number"==typeof i.minHeight&&("number"!=typeof o||i.minHeight>o)||"number"==typeof i.maxHeight&&("number"!=typeof o||o>i.maxHeight)||"number"==typeof i.minAspectRatio&&("number"!=typeof a||i.minAspectRatio>a)||"number"==typeof i.maxAspectRatio&&("number"!=typeof a||a>i.maxAspectRatio)||i.orientation&&n!==i.orientation)}(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:r.reduce((e,t)=>function(e,t){let i={...e,...t};for(let r of["margin","frameProps","mobileSemantics","style"])$(e[r])&&$(t[r])&&(i[r]={...e[r],...t[r]});return"string"==typeof e.className&&"string"==typeof t.className&&(i.className=`${e.className} ${t.className}`),i}(e,t.rule.transform),e),matches:r}}({...t,mode:e},{width:t.width??o,height:t.height??a}).props,l=n.mode||e||"primary",s=dd[l],c="context"===l||"sparkline"===l,u="primary"===l&&i?.width?i.width:s.width;return{mode:l,width:n.width??u,height:n.height??("primary"===l&&i?.height?i.height:s.height),showAxes:n.showAxes??s.showAxes,showGrid:n.showGrid??s.showGrid,enableHover:n.enableHover??(!!n.linkedHover||s.enableHover),showLegend:n.showLegend??s.showLegend,showLabels:n.showLabels??s.showLabels,title:c?void 0:n.title,description:n.description,summary:n.summary,accessibleTable:n.accessibleTable,xLabel:c?void 0:n.xLabel,yLabel:c?void 0:n.yLabel,categoryLabel:c?void 0:n.categoryLabel,valueLabel:c?void 0:n.valueLabel,marginDefaults:R(s.marginDefaults,n.showCategoryTicks,n.orientation),compactMode:c,mobileInteraction:T(n.mobileInteraction,{mode:l,width:n.width??u,mobileSemantics:n.mobileSemantics}),mobileSemantics:n.mobileSemantics}}(a.layout?.mode??("string"==typeof(z=t.mode)&&Object.prototype.hasOwnProperty.call(dd,z)?t.mode:void 0),{...a.layout?.modeDefaults,...gc(t,jb)},a.layout?.primarySize),{data:l,theme:s,background:c,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:y,...g}=t,{width:m,height:x}=n,b=[m,x],v=g.frameProps||{},w=a.layout?.margin,A="function"==typeof w?w(t,n):w??n.marginDefaults,S="xy"===a.frameType?k(A,g.axes??v.axes,!!n.title):A,M=void 0!==h?h:v.margin,_=function(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};let t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}(M),P="number"==typeof M?{top:M,right:M,bottom:M,left:M}:{...S,..._},L=gc(g,Wb),C=e=>v[e]??n[e],I={...v,...L,theme:s,title:n.title,description:n.description,showAxes:C("showAxes"),showLegend:C("showLegend"),showLabels:C("showLabels"),showGrid:C("showGrid"),xLabel:C("xLabel"),yLabel:C("yLabel"),categoryLabel:C("categoryLabel"),valueLabel:C("valueLabel"),background:c,className:u,annotations:d,size:b,margin:P,__compactMode:n.compactMode,__autoLegendMargin:!0,...void 0!==f&&{colorScheme:f},...void 0!==y&&{legendPosition:y},_idPrefix:g._idPrefix},D=a.buildProps(l,p,f,I,g);var z;if(a.renderStatic)o=a.renderStatic(D,r);else switch(a.frameType){case"xy":o=Un(D,r);break;case"ordinal":o=Ll(D,r);break;case"network":o=zs(D,r);break;case"geo":o=Vs(D,r);break;case"physics":o=nc(D,r)}let O=a.renderOverlay?.(D,{theme:le(s)});if(null!=O){let e=gd.renderToStaticMarkup(Fb(Ob,{children:O})),t=o.lastIndexOf("</svg>");o=0>t?`${o}${e}`:`${o.slice(0,t)}${e}${o.slice(t)}`}return{svg:yc(o,i?.precision),frameType:a.frameType}}function vc(e,t={}){return function(e,t,i){let{title:r,subtitle:o,theme:a,width:n=1200,height:l,layout:s={},background:c}=t,u=se(le(a)),d=s.columns||2,h=s.gap??16,f=0;r&&(f+=30),o&&(f+=20),f>0&&(f+=10);let p=Math.floor((n-h-h*(d-1))/d),y=[],g=0,m=f+h,x=0;for(let t of e){let e=Math.min(t.colSpan||1,d),r=p*e+h*(e-1),o=t.props.height||300;g+e>d&&(m+=x+h,g=0,x=0);let n=h/2+g*(p+h),l={...t.props,width:r,height:o,theme:a,_idPrefix:"chart-"+y.length},s=t.component?i.chart(t.component,l):t.frameType?i.frame(t.frameType,l):`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${o}"></svg>`,c=P(s,{width:r,height:o}),u=Math.max(o,c.height);y.push({x:n,y:m,width:r,height:u,svg:s,svgDimensions:c}),x=Math.max(x,u),g+=e}let b=l||m+x+h,v=y.map((e,t)=>Db("g",{transform:`translate(${e.x},${e.y})`,children:Db("foreignObject",{width:e.width,height:e.height,children:Db("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:L(e.svg,e.svgDimensions)}})})},"dashboard-chart-"+t));return Ib.renderToStaticMarkup(zb("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:b,role:"img","aria-label":r||"Dashboard",style:{fontFamily:u.fontFamily},children:[r&&Db("title",{children:r}),c&&Db("rect",{x:0,y:0,width:n,height:b,fill:c}),r&&Db("text",{x:n/2,y:24,textAnchor:"middle",fontSize:u.titleFontSize+4,fontWeight:u.titleFontWeight,fill:u.text,fontFamily:u.titleFontFamily,children:r}),o&&Db("text",{x:n/2,y:r?46:20,textAnchor:"middle",fontSize:u.labelSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:o}),v]}))}(e,t,{chart:mc,frame:cc})}function wc(e,t,i,r={}){let{stepSize:o,windowSize:a,frameCount:n,xExtent:s,yExtent:c,transitionFrames:u=4,fps:d=12,easing:h="ease-out",decay:f}=r,p=i.width||600,y=i.height||400,g=le(i.theme),m={...i,...s&&{xExtent:s},...c&&{yExtent:c}};if(!t||0===t.length)return[];let x=o||Math.max(1,Math.ceil(t.length/(n||Math.min(60,Math.max(10,t.length))))),b=[];for(let e=x;t.length>=e;e+=x)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);let v=new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),w=l({top:20,right:20,bottom:30,left:40,...i.margin},i.title),k=p-w.left-w.right,A=y-w.top-w.bottom,S=[];if(v)for(let r=0;b.length>r;r++){let o=b[r],n=t.slice(a?Math.max(0,o-a):0,o),l={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:i.projection||"vertical",oAccessor:i.oAccessor||i.categoryAccessor||"category",rAccessor:i.rAccessor||i.valueAccessor||"value",colorAccessor:i.colorAccessor||i.colorBy,stackBy:i.stackBy,groupBy:i.groupBy,connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,barPadding:i.barPadding,innerRadius:i.innerRadius,normalize:i.normalize,bins:i.bins,colorScheme:i.colorScheme||g.colors.categorical,...f&&{decay:f}},s=new Lm(l);s.ingest({inserts:n,bounded:!0}),s.computeScene({width:k,height:A}),s.scene.length>0&&S.push($c(s.scene,p,y,g,m,S.length))}else for(let r=0;b.length>r;r++){let o=b[r],n=t.slice(a?Math.max(0,o-a):0,o),l={chartType:e,windowSize:n.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:i.colorAccessor||i.colorBy,groupAccessor:i.groupAccessor||i.lineBy,lineDataAccessor:i.lineDataAccessor,xExtent:s,yExtent:c,colorScheme:i.colorScheme||g.colors.categorical,lineStyle:i.lineStyle,pointStyle:i.pointStyle,areaStyle:i.areaStyle,sizeAccessor:i.sizeAccessor||i.sizeBy,sizeRange:i.sizeRange,...f&&{decay:f},...u>0&&{transition:{duration:u*(1e3/d),easing:h}}},x=new dy(l);if(x.ingest({inserts:n,bounded:!0}),x.computeScene({width:k,height:A}),0===x.scene.length)continue;let v=x.scales?{y:x.scales.y}:void 0;if(S.push(Lc(x.scene,p,y,g,m,v,S.length)),u>0&&r>0&&x.activeTransition){let e=u*(1e3/d);for(let t=1;u>=t;t++)x.advanceTransition(x.activeTransition.startTime+t/u*e),S.push(Lc(x.scene,p,y,g,m,v,S.length))}}return S}function kc(e,t,i={}){return t.map(t=>{try{return mc(e,{...i,...t})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${i.width||t.width||600}" height="${i.height||t.height||400}"></svg>`}})}function Ac(e,t,i,r){let o=Sn(`${e}-${t}`),a="string"==typeof i&&i.length>0?i:void 0,n="string"==typeof r&&r.length>0?r:void 0,l=a?o.titleId:void 0,s=n?o.descId:void 0;return{titleText:a,descText:n,titleId:l,descId:s,labelledBy:[l,s].filter(Boolean).join(" ")||void 0}}function Sc(e,t){return"string"==typeof e.idPrefix&&e.idPrefix.length>0?e.idPrefix:jn(e)||t}function Mc(e,t,i){let r=t.size??[t.width??600,t.height??400],o=le(t.theme),a=se(o),n=t.background||o.colors.background,l=t.idPrefix??"physics-gif",s=Ac(l,i,t.title,t.description),{titleId:c,descId:u,labelledBy:d}=s,h=Ks(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),f=Gb("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,role:"img","aria-labelledby":d,style:{fontFamily:a.fontFamily},children:[t.title&&Xb("title",{id:c,children:t.title}),t.description&&Xb("desc",{id:u,children:t.description}),n&&"transparent"!==n?Xb("rect",{x:0,y:0,width:r[0],height:r[1],fill:n}):null,Xb("g",{id:`${l}-frame-${i}`,children:h.map((e,t)=>Wa(e,t,`${l}-${i}`))})]});return Bb.renderToStaticMarkup(f)}function _c(e,t={}){let{fps:i=12,frameCount:r,durationSeconds:o=2,includeInitialFrame:a=!0,stepDt:n,stepsPerFrame:l,background:s}=t,c=Math.max(.001,n??e.config?.fixedDt??1/120),u=l??Math.max(1,Math.round(1/Math.max(1,i)/c)),d=r??Math.max(1,Math.ceil(o*Math.max(1,i))),h=s?{...e,background:s}:e,f=new yu(e.config);e.initialSpawns?.length&&f.enqueue(e.initialSpawns,e.initialSpawnPacing);let p=[];for(a&&(f.tick(0),p.push(Mc(f,h,0)));d>p.length;){for(let e=0;u>e;e+=1)f.tick(c);p.push(Mc(f,h,p.length))}return p}function Pc(e,t){let i=e.background||t.colors.background;return i&&"transparent"!==i?i:null}function Lc(e,t,i,r,o,a,n=0){let s=se(r),c=l({top:20,right:20,bottom:30,left:40,...o.margin},o.title),u=t-c.left-c.right,d=i-c.top-c.bottom,h=Pc(o,r),f=o.renderMode,p=e.map((e,t)=>ja({node:e,index:t,renderMode:f,fallback:()=>Wa(e,t)}).element).filter(Boolean),y=function(e,t,i,r,o,a){if(!e||0===e.length)return null;let n=se(r),l=[];for(let r=0;e.length>r;r++){let s=e[r];if("y-threshold"===s.type&&null!=s.value){let e=null;if(a)e=a(s.value);else if(o){let[t,r]=o,a=r-t;if(0===a)continue;e=i-(s.value-t)/a*i}if(null==e)continue;let c=s.color||n.primary,u=s.labelPosition||"right";l.push(Gb("g",{children:[Xb("line",{x1:0,y1:e,x2:t,y2:e,stroke:c,strokeWidth:s.strokeWidth??1.5,strokeDasharray:s.strokeDasharray||"6,4"}),s.label&&Xb("text",{x:"left"===u?4:"center"===u?t/2:t-4,y:20>e?Math.min(i-4,e+16):e-5,textAnchor:"left"===u?"start":"center"===u?"middle":"end",fontSize:n.tickSize,fill:c,fontFamily:n.fontFamily,children:s.label})]},"ann-"+r))}}return l.length>0?Xb(Yb,{children:l}):null}(o.annotations,u,d,r,o.yExtent,a?.y),{titleText:g,descText:m,titleId:x,descId:b,labelledBy:v}=Ac(Sc(o,"xy-gif"),n,o.title,o.description);return Bb.renderToStaticMarkup(Gb("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:i,role:"img","aria-labelledby":v,style:{fontFamily:s.fontFamily},children:[g&&Xb("title",{id:x,children:g}),m&&Xb("desc",{id:b,children:m}),h&&Xb("rect",{x:0,y:0,width:t,height:i,fill:h}),Gb("g",{transform:`translate(${c.left},${c.top})`,children:[y,p]}),g&&Xb("text",{x:t/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:g})]}))}function $c(e,t,i,r,o,a=0){let n=se(r),s=l({top:20,right:20,bottom:30,left:40,...o.margin},o.title),c="radial"===o.projection,u=c?s.left+(t-s.left-s.right)/2:s.left,d=c?s.top+(i-s.top-s.bottom)/2:s.top,h=Pc(o,r),f=Pl({nodes:e,renderMode:o.renderMode,idPrefix:o.idPrefix}).map(e=>e.element),{titleText:p,descText:y,titleId:g,descId:m,labelledBy:x}=Ac(Sc(o,"ordinal-gif"),a,o.title,o.description);return Bb.renderToStaticMarkup(Gb("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:i,role:"img","aria-labelledby":x,style:{fontFamily:n.fontFamily},children:[p&&Xb("title",{id:g,children:p}),y&&Xb("desc",{id:m,children:y}),h&&Xb("rect",{x:0,y:0,width:t,height:i,fill:h}),Xb("g",{transform:`translate(${u},${d})`,children:f}),p&&Xb("text",{x:t/2,y:22,textAnchor:"middle",fontSize:n.titleFontSize,fontWeight:n.titleFontWeight,fill:n.text,fontFamily:n.titleFontFamily,children:p})]}))}import{accessorsEquivalent as Tc,baseConfig as Rc,clampNumber as Cc,compareArtifactIdentity as Ic,createPhysicsSourceState as Dc,filterAnnotationsByStatus as zc,finiteNumber as Oc,generateGaltonMechanicalSamples as Fc,generatePhysicsPileMechanicalSamples as Nc,normalizedFiniteExtent as Ec,physicsChartArea as Wc,physicsPileUnitCount as jc,positiveNumber as Bc,readAccessor as Yc,resolveAccessor as Xc,resolveEventDropAdmissions as Gc,resolveLabelFn as Vc,resolveNodeRefId as Hc,resolveRawAccessor as qc,resolveStringAccessor as Uc,safeIdPart as Zc,seededRandom as Kc,serializeArtifactContract as Qc,stableEvidenceHash as Jc,styleFromColorAccessor as eu}from"./c-E32M6XW5.min.js";import{resolveCSSColor as tu}from"./c-OOVX2JPQ.min.js";import{DARK_THEME as iu,HIGH_CONTRAST_THEME as ru,LIGHT_THEME as ou,applyThemeAccessibility as au,resolveThemePreset as nu,resolveThemeSemanticColors as lu,themeToCSSVariables as su}from"./c-42PLDTX7.min.js";import{composeStyleRules as cu,makeNodeRuleContext as uu,makeRuleValueResolver as du,makeXYRuleContext as hu,resolveStyleRules as fu,styleRulesToNodeStyle as pu}from"./c-I4QJ6YLM.min.js";import{PhysicsPipelineStore as yu,UpdateResultTracker as gu,absorbRegion as mu,annotationLayout as xu,annotationNote as bu,bodyGroupSpec as vu,buildDirectedAdjacency as wu,calendarLayout as ku,capacitatedRegion as Au,collidersFromPlotBounds as Su,collidersFromXScaleBins as Mu,countPairwiseCrossings as _u,drawGlyphParts as Pu,forceFieldRegion as Lu,getGlyphPath2D as $u,glyphFractionClipRect as Tu,glyphHitGeometry as Ru,glyphPlacement as Cu,groupCompletionRows as Iu,isInBounds as Du,makeSymbolResolver as zu,measureAnnotationNote as Ou,orderByBarycenter as Fu,orderExactSmall as Nu,packBandsBySilhouette as Eu,parallelCoordinatesLayout as Wu,placeWithMinGap as ju,portalRegion as Bu,pressureFieldRegion as Yu,processChrome as Xu,processStageLayout as Gu,reachableFrom as Vu,refineByAdjacentSwaps as Hu,resolveAnchoredPosition as qu,resolveGlyphPaint as Uu,resolveNodeSizeFn as Zu,resolveX as Ku,resolveY as Qu,routeSurfaceRegion as Ju,symbolPathString as ed,symbolRadius as td,useCustomLayoutSelection as id,wrapAnnotationText as rd}from"./c-JG2JCQLP.min.js";import{getMax as od,getMin as ad,getMinMax as nd}from"./c-QA3HMQJP.min.js";var ld=34,sd=70,cd=/\s+([^\s=<>/'"]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,ud={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1},dd={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}}},hd={kind:"rank-competition"},fd=Symbol.for("semiotic.semantic-viability"),pd=globalThis,yd=pd[fd]??(pd[fd]=new Map);import*as gd from"react-dom/server";import*as md from"react";var xd=Object.freeze([]);import{scaleOrdinal as bd}from"d3-scale";var vd=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],wd=W(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),kd=W(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),Ad=W(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),Sd=W(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),Md=W(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),_d=W(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),Pd=W(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),Ld=W(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),$d=W(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),Td=W(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),Rd=W(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),Cd=W(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"]),Id={blues:wd,reds:kd,greens:Ad,viridis:Pd,oranges:Sd,purples:Md,greys:_d,plasma:Ld,inferno:$d,magma:Td,cividis:Rd,turbo:Cd},Dd=W(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),zd=W(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),Od=W(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),Fd=W(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),Nd=W(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),Ed=W(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),Wd=W(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),jd={category10:vd,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...Id},Bd=vd,Yd="#007bff",Xd=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],Gd=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],Vd=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"]),Hd={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]},qd="__forecastSegment",Ud="__forecastOpacity",Zd="__semiotic_resolvedX",Kd="__semiotic_resolvedY",Qd="__compoundGroup",Jd={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=xe({data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",forecast:o.forecast,anomaly:o.anomaly,annotations:r.annotations,themeCategorical:le(r.theme).colors.categorical}),n=ne(a.annotations,o.regression);return{chartType:"scatter",data:a.data,xAccessor:a.xAccessor,yAccessor:a.yAccessor,colorAccessor:t,sizeAccessor:o.sizeBy,...o.symbolBy&&{symbolAccessor:o.symbolBy},...o.symbolMap&&{symbolMap:o.symbolMap},colorScheme:i,...r,...n&&n.length>0&&{annotations:n},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},sizeRange:o.sizeRange||[3,15],pointStyle:r.pointStyle||be(e,t,i,r,o),showLegend:r.showLegend??!!t}}},eh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=ne(r.annotations,o.regression);return{chartType:"scatter",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:t,sizeAccessor:o.sizeBy,sizeRange:o.sizeRange||[5,40],colorScheme:i,...r,...a&&{annotations:a},pointStyle:r.pointStyle||ve(e,t,i,r,o),showLegend:r.showLegend??!!t}}};import{useMemo as th,useCallback as ih,useState as rh,useId as oh,useEffect as ah,useRef as nh}from"react";var lh="__semioticSelectionData";import{jsx as sh}from"react/jsx-runtime";var ch={frameType:"xy",layout:{margin:e=>({top:20,right:!1===e.showLabels?24:110,bottom:48,left:48})},buildProps:(e,t,i,r,o)=>{let a=function(e,t={}){let i=t.xAccessor??"x",r=t.yAccessor??"y",o=t.lineBy??"series",a=t.rankDirection??"descending",n=[],l=new Map,s=new Map,c=[],u=new Map,d=1/0,h=-1/0;e.forEach((e,t)=>{let a=Pe(i,e,t),f=C(a),p=l.get(f);null==p&&(p=n.length,l.set(f,p),n.push(a),s.set(p,[]));let y=Pe(o,e,t)+"";u.has(y)||(u.set(y,c.length),c.push(y));let g=Number(Pe(r,e,t));Number.isFinite(g)&&(d=Math.min(d,g),h=Math.max(h,g),s.get(p)?.push({datum:e,inputIndex:t,series:y,value:g}))});let f=[],p=new Map,y=new Map;for(let e=0;n.length>e;e++){let t=s.get(e)??[];t.sort((e,t)=>("descending"===a?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,i)=>{let r=i+1;f.push({datum:t.datum,xIndex:e,xValue:n[e],series:t.series,value:t.value,rank:r}),p.set(t.series,(p.get(t.series)??0)+r),y.set(t.series,(y.get(t.series)??0)+1)})}let g=c.length+1,m=[...c].sort((e,t)=>{let i=y.get(e)??0,r=y.get(t)??0;return((p.get(e)??0)+(n.length-i)*g)/Math.max(1,n.length)-((p.get(t)??0)+(n.length-r)*g)/Math.max(1,n.length)||(u.get(e)??0)-(u.get(t)??0)}),x=new Set(m.slice(0,null==t.highlightTop?m.length:Math.max(0,Math.floor(t.highlightTop))));return{data:f.map(e=>{let t=x.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:n,seriesOrder:c,overallOrder:m,valueExtent:d===1/0?[0,0]:[d,h]}}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],{xAccessor:o.xAccessor,yAccessor:o.yAccessor,lineBy:o.lineBy,rankDirection:o.rankDirection,highlightTop:"number"==typeof o.highlightTop?o.highlightTop:void 0}),n=Math.max(1,a.seriesOrder.length),l=le(r.theme),s=function(e){let{seriesOrder:t,overallOrder:i,highlightTop:r,color:o,colorScheme:a,neutralColor:n,themeCategorical:l,themeNeutral:s}=e;if(null==r&&null==o)return a;let c=new Set(i.slice(0,null==r?i.length:Math.max(0,Math.floor(r)))),u=new Map,d={};for(let e of t)Object.defineProperty(d,e,{configurable:!0,enumerable:!0,writable:!0,value:o??(c.has(e)?_e(void 0,l,a,e,u):n??s??"#b8bec8")});return d}({seriesOrder:a.seriesOrder,overallOrder:a.overallOrder,highlightTop:"number"==typeof o.highlightTop?o.highlightTop:void 0,color:"string"==typeof o.color?o.color:void 0,colorScheme:i,neutralColor:"string"==typeof o.neutralColor?o.neutralColor:void 0,themeCategorical:l.colors.categorical,themeNeutral:l.colors.textSecondary}),c={ribbon:!0===o.ribbon,curve:"linear"===o.curve?"linear":"smooth",samplesPerSegment:"number"==typeof o.samplesPerSegment?o.samplesPerSegment:12,ribbonSizeRange:Array.isArray(o.ribbonSizeRange)?o.ribbonSizeRange:[4,28],valueExtent:a.valueExtent,seriesOrder:a.seriesOrder,lineWidth:"number"==typeof o.lineWidth?o.lineWidth:3,ribbonOpacity:"number"==typeof o.ribbonOpacity?o.ribbonOpacity:.82,lineOpacity:"number"==typeof o.lineOpacity?o.lineOpacity:.9,neutralColor:"string"==typeof o.neutralColor?o.neutralColor:void 0,color:"string"==typeof o.color?o.color:void 0,colorMap:s&&"object"==typeof s&&!Array.isArray(s)?s:void 0,stroke:"string"==typeof o.stroke?o.stroke:void 0,strokeWidth:"number"==typeof o.strokeWidth?o.strokeWidth:void 0,opacity:"number"==typeof o.opacity?o.opacity:void 0,styleRules:o.styleRules,areaStyle:r.areaStyle,pointStyle:r.pointStyle,labelStyle:o.labelStyle,showPoints:!0===o.showPoints,pointRadius:"number"==typeof o.pointRadius?o.pointRadius:3,showLabels:o.showLabels??!0,labelPriorityAccessor:o.labelPriorityAccessor,maxLabels:"number"==typeof o.maxLabels?o.maxLabels:void 0},u=r.xFormat,d=(e,t)=>{if(0===a.xValues.length)return"";let i=a.xValues[Math.max(0,Math.min(a.xValues.length-1,Math.round(Number(e))))];return u?u(i,t):(i instanceof Date?i.toLocaleDateString():i)+""},h=a.xValues.map((e,t)=>t),f=Array.from({length:n},(e,t)=>t+1),p=r.axes??[{orient:"left",tickValues:f,tickFormat:e=>e+"",label:r.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:h,tickFormat:d,label:r.xLabel,tickAnchor:"edges"}];return{...r,chartType:"custom",data:a.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,a.xValues.length-1)],yExtent:[n+.5,.5],customLayout:Oe,layoutConfig:c,colorAccessor:"__bumpSeries",colorScheme:s,xFormat:d,axes:p,axisExtent:"exact",showAxes:r.showAxes??!0,showLegend:r.showLegend??!1,annotations:Le(r.annotations,a.xValues)}}},uh="__ma_unitized",dh="__ma_series",hh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=Array.isArray(o.series)?o.series:[],l=function(e,t,i){let r=B(t,i,Bd),o=t&&"object"==typeof t&&!Array.isArray(t)?t:null;return e.map((e,t)=>{if("string"==typeof e.color&&e.color.length>0)return e.color;let i=e.label||"Series "+(t+1),a=o?.[i];return"string"==typeof a&&a.length>0?a:r[t%r.length]})}(n,i,le(r.theme).colors.categorical),s=2===n.length,c=n.map(e=>e.extent||function(e,t){let i="function"==typeof t?t:e=>Number(e[t||"y"]),r=1/0,o=-1/0;for(let t of e){let e=i(t);"number"==typeof e&&Number.isFinite(e)&&(r>e&&(r=e),e>o&&(o=e))}if(!Number.isFinite(r)||!Number.isFinite(o))return[0,1];if(r===o){let e=0===r?1:.1*Math.abs(r);return[r-e,o+e]}return[r,o]}(a,e.yAccessor)),u=[];for(let e of a)n.forEach((t,i)=>{let r=("function"==typeof t.yAccessor?t.yAccessor:e=>e[t.yAccessor])(e);if(null==r||!Number.isFinite(Number(r)))return;let o=Number(r),a=c[i],n=a[1]-a[0]||1;u.push({...e,[uh]:s?(o-a[0])/n:o,[dh]:t.label||"Series "+(i+1)})});let d=(e,t)=>i=>{let r=e[0]+i*(e[1]-e[0]);return"function"==typeof t?t(r):Number.isInteger(r)?r+"":r.toFixed(1)},h=s?[{orient:"left",label:n[0].label,tickFormat:d(c[0],n[0].format)},{orient:"right",label:n[1].label,tickFormat:d(c[1],n[1].format)},{orient:"bottom"}]:void 0,f=new Map;n.forEach((e,t)=>{f.set(e.label||"Series "+(t+1),l[t])});let p=q(U({lineWidth:"number"==typeof o.lineWidth?o.lineWidth:2,resolveStroke:e=>f.get((e[dh]??"")+"")||l[0],styleRules:o.styleRules,ruleContext:Fe(o.xAccessor,n)}),{stroke:"string"==typeof o.stroke?o.stroke:void 0,strokeWidth:"number"==typeof o.strokeWidth?o.strokeWidth:void 0,opacity:"number"==typeof o.opacity?o.opacity:void 0});return{chartType:"line",data:u,xAccessor:o.xAccessor||"x",yAccessor:uh,groupAccessor:dh,colorAccessor:dh,...h&&{axes:h},...s&&{yExtent:[0,1]},...r,curve:o.curve||r.curve||"monotoneX",showLegend:r.showLegend??!0,colorScheme:l,lineStyle:p}}},fh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=o.xAccessor||"x",l="function"==typeof n?n:e=>e[n],s=a.some(e=>{let t=l(e);return!("number"==typeof t&&Number.isFinite(t)||t instanceof Date)}),c=s?a.map((e,t)=>({...e,__waterfallX:t,__waterfallTick:(l(e)??t)+""})):a,u=o.styleRules?cu(void 0,o.styleRules,hu(o.xAccessor,o.yAccessor)):void 0,d=u?e=>{let t=u(e),i="function"==typeof r.areaStyle?r.areaStyle(e):r.areaStyle;return i?{...t,...i}:t}:void 0;return{chartType:"waterfall",data:c,xAccessor:s?"__waterfallX":n,yAccessor:o.yAccessor||"y",waterfallStyle:{positiveColor:o.positiveColor,negativeColor:o.negativeColor,connectorStroke:o.connectorStroke,connectorWidth:o.connectorWidth,gap:o.gap,stroke:o.stroke,strokeWidth:o.strokeWidth,opacity:o.opacity},...r,...d&&{areaStyle:d},...s&&{axes:r.axes??[{orient:"bottom",tickValues:c.map((e,t)=>t)}],xFormat:e=>{let t=a[Number(e)]?l(a[Number(e)]):e,i=o.xFormat??r.xFormat;return"function"==typeof i?i(t):(t??e)+""}}}}},ph={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=t||o.lineBy,n=o.fillArea,l=Array.isArray(n)?"mixed":n?"area":"line",s=le(r.theme).colors.categorical,c=function(e,t,i,r,o){let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=le(r.theme).colors.categorical,l=i??r.colorScheme??n,s="string"==typeof t?t:"__ssrLineColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrLineColorBy:t(e)})):a,u=t?G(c,s,l):void 0,d=hu(o.xAccessor,o.yAccessor);return q(U({lineWidth:"number"==typeof o.lineWidth?o.lineWidth:2,colorBy:t,colorScale:u,color:"string"==typeof o.color?o.color:void 0,fillArea:o.fillArea,areaOpacity:"number"==typeof o.areaOpacity?o.areaOpacity:.3,styleRules:o.styleRules,ruleContext:d}),{stroke:"string"==typeof o.stroke?o.stroke:void 0,strokeWidth:"number"==typeof o.strokeWidth?o.strokeWidth:void 0,opacity:"number"==typeof o.opacity?o.opacity:void 0})}(e,a,i,r,o),u=xe({data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",lineBy:o.lineBy,colorBy:a,colorScheme:i,color:"string"==typeof o.color?o.color:void 0,forecast:o.forecast,anomaly:o.anomaly,gapStrategy:o.gapStrategy,directLabel:o.directLabel,annotations:r.annotations,themeCategorical:s,baseLineStyle:c}),d=r.pointStyle||Ee(u.data,u.colorAccessor,i,r,o),h=r.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});let f=(!o.directLabel||void 0!==r.showLegend)&&(r.showLegend??!!u.colorAccessor);return{chartType:l,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:i,lineStyle:u.lineStyle||c,...Array.isArray(n)&&{areaGroups:n},...n&&null!=o.areaOpacity&&{areaOpacity:o.areaOpacity},...null!=o.band&&{band:o.band},...r,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!r.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:f}}},yh={frameType:"xy",layout:{margin:(e,t)=>function(e,t,i,r=!1){let o=y({axes:t,showAxes:i});return{...k(e,t,r),...!o.hasAxis&&{bottom:0},...!o.leftAxis?.hasAxis&&{left:0}}}(t.marginDefaults,ce(e),t.showAxes,!!t.title)},buildProps:(e,t,i,r,o)=>{let a=Array.isArray(e)?F(e):[],n=o.timeAccessor||"time",l=o.valueAccessor||"value",s=o.categoryAccessor,c=o.valueExtent||r.yExtent,u={...ae(o),...void 0!==o.cursor&&{cursor:o.cursor}},d={...u,...void 0!==o.fill&&{fill:o.fill},...void 0!==o.gap&&{gap:o.gap}},h=cu(void 0,o.styleRules,e=>{let t=e.categoryValue??e.total,i="number"==typeof t&&Number.isFinite(t)?t:void 0,r=Number(e.binStart),o=Number(e.binEnd);return{value:i,x:Number.isFinite(r)&&Number.isFinite(o)?(r+o)/2:void 0,y:i,category:null==e.category?void 0:e.category+""}});return{chartType:"bar",data:a,...r,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,a.length),arrowOfTime:o.arrowOfTime||"right",timeAccessor:e=>O(e,n,"time")??NaN,valueAccessor:e=>O(e,l,"value")??NaN,xExtent:o.timeExtent||r.xExtent,yExtent:c,invertY:"down"===o.direction,axes:ce({...o,axes:r.axes??o.axes}),extentPadding:o.extentPadding??r.extentPadding,binSize:o.binSize,categoryAccessor:s,barColors:o.colors||r.barColors,colorScheme:o.colors||r.colorScheme,barStyle:r.barStyle||d,areaStyle:r.areaStyle||(e=>({...h(e),...!s&&void 0!==o.fill&&{fill:o.fill},...u})),showLegend:r.showLegend??!!s}}},gh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=t||o.areaBy,n=xe({data:Array.isArray(e)?F(e):[],xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",lineBy:o.areaBy,forecast:o.forecast,anomaly:o.anomaly,annotations:r.annotations,themeCategorical:le(r.theme).colors.categorical}),l=function({data:e,safeData:t,areaBy:i,lineDataAccessor:r}){if(null==e)return[];let o,a=void 0!==t[0]?.[r];if(!a&&!i)return t;if(a)o=t;else{let e=t.reduce((e,t)=>{let o="function"==typeof i?i(t):t[i],a=o+"";if(!e[a]){let t={[r]:[]};"string"==typeof i&&(t[i]=o),e[a]=t}return e[a][r].push(t),e},{});o=Object.values(e)}return o.flatMap(e=>{let t=Array.isArray(e[r])?e[r]:[];return"string"==typeof i?t.map(t=>({...t,[i]:t[i]??e[i]})):t})}({data:e,safeData:n.data,areaBy:o.areaBy,lineDataAccessor:o.lineDataAccessor||"coordinates"}),s=function(e){if(e)return Array.isArray(e)?{stops:e.map(({at:e,color:t,opacity:i})=>({offset:e/100,color:t,...null!=i&&{opacity:i}}))}:Array.isArray(e.stops)?e:void 0}(o.semanticGradient),c=s?.stops.length?{stops:s.stops.map(e=>({...e,offset:1-e.offset})).sort((e,t)=>e.offset-t.offset)}:ee(r.gradientFill),u=!1!==o.semanticLine?function(e){let t=e?.stops.filter(e=>"string"==typeof e.color&&Number.isFinite(e.offset)).map(({offset:e,color:t,opacity:i})=>({offset:Math.max(0,Math.min(1,e)),color:t,...Number.isFinite(i)&&{opacity:Math.max(0,Math.min(1,i))}})).sort((e,t)=>e.offset-t.offset);if(!t?.length)return;let i=t[0];return i.offset>0?[{...i,offset:0},...t]:t}(s):void 0,d=r.pointStyle||Ee(l,a,i,r,o);return{chartType:"area",data:l,xAccessor:n.xAccessor,yAccessor:n.yAccessor,y0Accessor:o.y0Accessor,groupAccessor:o.areaBy||void 0,colorAccessor:a,colorScheme:i,...r,...n.annotations.length>0&&{annotations:n.annotations},...n.yExtent&&!r.yExtent&&{yExtent:n.yExtent},...void 0!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:r.lineStyle||Ne(l,a,i,r,o),...d&&{pointStyle:d}}}},mh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=o.xAccessor||"x",n=o.seriesAAccessor||"a",l=o.seriesBAccessor||"b",s=e=>re(ie(a,"x",e)),c=e=>re(ie(n,"a",e)),u=e=>re(ie(l,"b",e)),d=o.seriesAColor||"var(--semiotic-danger, #dc2626)",h=o.seriesBColor||"var(--semiotic-info, #2563eb)",f=o.areaOpacity??.6,p=o.lineWidth??1.5,y=!1!==o.showLines,g=!1!==r.showLegend,m=o.seriesALabel||"A",x=o.seriesBLabel||"B",b=r.legendPosition||"right",v=function(e,t,i,r){if(!e.length)return[];let o=e.filter(e=>Number.isFinite(t(e))).sort((e,i)=>t(e)-t(i)),a=[],n=0,l=null,s=null,c=[],u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${n}-${e}`,h=e=>a.push(e),f=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;o.length>e;e++){let a=o[e],p=t(a),y=i(a),g=r(a);if(!Number.isFinite(p)||!Number.isFinite(y)||!Number.isFinite(g))continue;let m=u(y,g);if(null!==m){if(null==l){l=m;for(let e of c)f(e,l);c=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(l),__diffWinner:l,__valA:y,__valB:g,__sourceDatum:a}),s={x:p,a:y,b:g,w:m};continue}if(s&&s.w!==m){let e,t;if(c.length>0)e=c[0].x,t=c[0].y;else{let i=y-s.a-(g-s.b);if(0!==i){let r=Math.max(0,Math.min(1,(s.b-s.a)/i));e=s.x+r*(p-s.x),t=s.a+r*(y-s.a)}else e=s.x,t=s.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(l),__diffWinner:l,__valA:t,__valB:t}),n++,l=m,h({__x:e,__y:t,__y0:t,__diffSegment:d(l),__diffWinner:l,__valA:t,__valB:t});for(let e=1;c.length>e;e++)f(c[e],l)}else for(let e of c)f(e,l);c=[],h({__x:p,__y:g>y?g:y,__y0:g>y?y:g,__diffSegment:d(l),__diffWinner:l,__valA:y,__valB:g,__sourceDatum:a}),s={x:p,a:y,b:g,w:m}}else c.push({x:p,y:y,datum:a})}for(let e of c)f(e,l??"A");return a}(Array.isArray(e)?e:[],s,c,u),w=[];if(y&&Array.isArray(e)){let t=e.filter(e=>Number.isFinite(s(e))).sort((e,t)=>s(e)-s(t));for(let e of t){let t=s(e),i=c(e),r=u(e);Number.isFinite(i)&&w.push({__x:t,__y:i,__diffSegment:"line-A",__diffWinner:"A",__sourceDatum:e}),Number.isFinite(r)&&w.push({__x:t,__y:r,__diffSegment:"line-B",__diffWinner:"B",__sourceDatum:e})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:Q({seriesAColor:d,seriesBColor:h,areaOpacity:f,styleRules:o.styleRules}),lineStyle:J({seriesAColor:d,seriesBColor:h,lineWidth:p,styleRules:o.styleRules}),curve:o.curve||"linear",...r,...g&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:m,color:d},{label:x,color:h}]}]},legendPosition:b}}}},xh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=t||o.areaBy,n="string"==typeof a&&Array.isArray(e)?G(e,a,i):void 0,l="number"==typeof o.areaOpacity?o.areaOpacity:.7,s=r.lineStyle||(e=>{let t=null==a?void 0:Y(e,a,n),i=o.showLine??!0,r={fill:o.color??t,stroke:i?o.stroke??t:"none",...i?{strokeWidth:o.strokeWidth??o.lineWidth??2}:{},fillOpacity:l,...null==o.opacity?{}:{opacity:o.opacity}},s=o.styleRules;if(s?.length){let t=du(o.yAccessor),i=a?("function"==typeof a?a(e)??"":e[a]??"")+"":void 0;Object.assign(r,fu(e,s,{value:t(e),category:i}))}return r}),c=o.normalize?"zero":o.baseline??"zero",u=r.pointStyle||Ee(e,a,i,r,o);return{chartType:"stackedarea",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",groupAccessor:o.areaBy,colorAccessor:a,colorScheme:i,normalize:o.normalize,baseline:c,stackOrder:o.stackOrder,lineStyle:s,...r,...u&&{pointStyle:u},curve:r.curve??o.curve??"monotoneX",showLegend:r.showLegend??!!a}}},bh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let[a]=r.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.highAccessor||"high",highAccessor:o.highAccessor||"high",lowAccessor:o.lowAccessor||"low",openAccessor:o.openAccessor,closeAccessor:o.closeAccessor,candlestickStyle:o.candlestickStyle,...r,...!r.pointStyle&&Array.isArray(o.styleRules)&&o.styleRules.length>0&&{pointStyle:cu(void 0,o.styleRules,hu(o.xAccessor||"x",o.closeAccessor||o.highAccessor||"high"))},scalePadding:r.scalePadding??Math.max(2,Math.min(12,Math.round(a/40))),extentPadding:r.extentPadding??(a>200?.1:.02)}}},vh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=o.xCenter,n=o.yCenter,l=o.quadrants,s=o.centerlineStyle||{},c=!1!==o.showQuadrantLabels,u=o.quadrantLabelSize??12,d=s.stroke||"#999",h=s.strokeWidth??1,f=Array.isArray(s.strokeDasharray)?s.strokeDasharray.join(","):s.strokeDasharray,p=md.createElement,y=l?[(e,t,i)=>{if(!t?.x||!t?.y)return null;let r=i.width,o=i.height,s=null!=a?t.x(a):r/2,y=null!=n?t.y(n):o/2;if(null!=a&&!Number.isFinite(s)||null!=n&&!Number.isFinite(y))return null;let g=Math.max(0,Math.min(r,s)),m=Math.max(0,Math.min(o,y)),x=[{c:l.topLeft,x:0,y:0,w:g,h:m},{c:l.topRight,x:g,y:0,w:r-g,h:m},{c:l.bottomLeft,x:0,y:m,w:g,h:o-m},{c:l.bottomRight,x:g,y:m,w:r-g,h:o-m}],b=c?[p("text",{key:"ltl",x:8,y:8+u,fill:l.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},l.topLeft.label),p("text",{key:"ltr",x:r-8,y:8+u,fill:l.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},l.topRight.label),p("text",{key:"lbl",x:8,y:o-8,fill:l.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},l.bottomLeft.label),p("text",{key:"lbr",x:r-8,y:o-8,fill:l.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},l.bottomRight.label)]:[];return p(md.Fragment,null,...x.map((e,t)=>e.w>0&&e.h>0?p("rect",{key:"qf-"+t,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),p("line",{key:"vc",x1:g,y1:0,x2:g,y2:o,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:m,x2:r,y2:m,stroke:d,strokeWidth:h,strokeDasharray:f}),...b)}]:void 0;return{chartType:"scatter",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:t,sizeAccessor:o.sizeBy,sizeRange:o.sizeRange||[3,15],colorScheme:i,pointStyle:r.pointStyle||o.pointStyle||be(e,t,i,r,o),...r,showLegend:r.showLegend??!!t,...y&&{svgPreRenderers:y}}}},wh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=function(e,t){if(!Array.isArray(e))return{data:e,orderMap:new WeakMap};let i=t.xAccessor||"x",r=t.yAccessor||"y",o=t.orderAccessor?[...e].sort((e,i)=>null==e||"object"!=typeof e?1:null==i||"object"!=typeof i?-1:re(ie(t.orderAccessor,"order",e))-re(ie(t.orderAccessor,"order",i))):e,a=new WeakMap,n=0;for(let e of o){if(null==e||"object"!=typeof e)continue;let t=re(ie(i,"x",e)),o=re(ie(r,"y",e));Number.isFinite(t)&&Number.isFinite(o)&&n++}let l=0;for(let e of o){if(null==e||"object"!=typeof e)continue;let t=re(ie(i,"x",e)),o=re(ie(r,"y",e));Number.isFinite(t)&&Number.isFinite(o)&&a.set(e,{idx:l++,total:n})}return{data:o,orderMap:a}}(e,o),n=xe({data:a.data,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",forecast:o.forecast,anomaly:o.anomaly,annotations:r.annotations,themeCategorical:le(r.theme).colors.categorical}),l=ne(n.annotations,o.regression),s=o.pointRadius??4,c=hu(o.xAccessor,o.yAccessor),u=o.styleRules,d=[e=>{let t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(2>t.length)return null;let i=[];for(let e=0;t.length-1>e;e++){let r=t[e],o=t[e+1],a=oe(e,t.length);100>t.length&&i.push(md.createElement("line",{key:"halo-"+e,x1:r.x,y1:r.y,x2:o.x,y2:o.y,stroke:"white",strokeWidth:s+2,strokeLinecap:"round",opacity:.5})),i.push(md.createElement("line",{key:"segment-"+e,x1:r.x,y1:r.y,x2:o.x,y2:o.y,stroke:a,strokeWidth:s,strokeLinecap:"round"}))}return md.createElement(md.Fragment,null,...i)}];return{chartType:"scatter",data:n.data,xAccessor:n.xAccessor,yAccessor:n.yAccessor,colorAccessor:t,colorScheme:i,pointStyle:q(e=>{let t=a.orderMap.get(e),i=t?.idx??0,r=t?.total??1,o={fill:r>0?oe(i,r):"#6366f1",stroke:"white",strokeWidth:1,r:s,fillOpacity:1};return u?.length&&Object.assign(o,fu(e,u,c(e))),o},ae(o)),...r,...l&&l.length>0&&{annotations:l},...n.yExtent&&!r.yExtent&&{yExtent:n.yExtent},svgPreRenderers:d}}},kh={frameType:"xy",buildProps:(e,t,i,r,o)=>{let a=o.frameProps&&"object"==typeof o.frameProps?o.frameProps:void 0,n=Number.isFinite(o.cellBorderWidth)?Math.max(0,o.cellBorderWidth):1,l=cu(()=>({stroke:o.cellBorderColor??"#fff",strokeWidth:n}),o.styleRules,function(e,t,i){let r=du(e),o=du(t),a=du(i);return e=>{let t="string"==typeof e.agg&&"number"==typeof e.count&&"number"==typeof e.xCenter&&"number"==typeof e.yCenter;return{value:t?We(e.value):a(e),x:t?We(e.xCenter):r(e),y:t?We(e.yCenter):o(e)}}}(o.xAccessor,o.yAccessor,o.valueAccessor)),s=("string"==typeof a?.colorScheme?a.colorScheme:void 0)??i,c=null!=a&&Object.hasOwn(a,"heatmapColorScale"),u=a?.heatmapColorScale,d=c?"function"==typeof u?u:void 0:"custom"===s&&"function"==typeof o.customColorScale?o.customColorScale:void 0;return{chartType:"heatmap",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",valueAccessor:o.valueAccessor,showValues:o.showValues,heatmapValueFormat:o.valueFormat,...o.heatmapAggregation&&{heatmapAggregation:o.heatmapAggregation},...null!=o.heatmapXBins&&{heatmapXBins:o.heatmapXBins},...null!=o.heatmapYBins&&{heatmapYBins:o.heatmapYBins},areaStyle:l,...r,...void 0!==s&&{colorScheme:s},...d&&{heatmapColorScale:d}}}};import{useMemo as Ah,useCallback as Sh,useRef as Mh}from"react";var _h={RdBu:Dd,PiYG:zd,PRGn:Od,BrBG:Fd,RdYlBu:Nd,RdYlGn:Ed,Spectral:Wd},Ph="__likert_neutral_neg",Lh="__likert_neutral_pos",$h={frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,r,o,a)=>{let n=Array.isArray(a.levels)&&a.levels.length>=2?a.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],l="vertical"!==a.orientation,s=function(e,t,i,r,o,a,n={}){let l=new Map,s=new Set(t);for(let n of e){let e=i(n);l.has(e)||l.set(e,new Map);let c=l.get(e);if(r){let e=r(n);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}let i=e-1;if(0>i||i>=t.length)continue;let o=t[i];c.set(o,(c.get(o)||0)+1)}else if(o&&a){let e=o(n),t=a(n);if(!s.has(e))continue;c.set(e,(c.get(e)||0)+(Number.isFinite(t)?t:0))}}let c=[];for(let[e,i]of l){let r=0;for(let e of t)r+=i.get(e)||0;if(0!==r)for(let o=0;t.length>o;o++){let a=t[o],l=i.get(a)||0,s={};n.category&&(s[n.category]=e),n.level&&(s[n.level]=a),n.count&&(s[n.count]=l),n.score&&(s[n.score]=o+1),c.push({...s,__likertCategory:e,__likertLevel:a,__likertLevelLabel:a,__likertCount:l,__likertPct:l/r*100,__likertLevelIndex:o})}}return c}(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n,je(a.categoryAccessor,"question"),a.levelAccessor?null:je(a.valueAccessor,"score"),a.levelAccessor?je(a.levelAccessor,"level"):null,a.levelAccessor?je(a.countAccessor,"count"):null,{category:"string"==typeof a.categoryAccessor?a.categoryAccessor:void 0,level:"string"==typeof a.levelAccessor?a.levelAccessor:void 0,count:"string"==typeof a.countAccessor?a.countAccessor:void 0,score:a.levelAccessor||"string"!=typeof a.valueAccessor?void 0:a.valueAccessor});l&&(s=function(e,t){let i=t.length,r=i%2!=0,o=Math.floor(i/2),a=new Map;for(let t of e){let e=a.get(t.__likertCategory)||[];e.push(t),a.set(t.__likertCategory,e)}let n=[];for(let[,e]of a){let t,a,l=new Map;for(let i of e)i.__likertLevel===Ph?t=i:i.__likertLevel===Lh?a=i:l.set(i.__likertLevelIndex,i);r&&t&&n.push(t);for(let e=o-1;e>=0;e--){let t=l.get(e);t&&n.push(t)}r&&a&&n.push(a);for(let e=r?o+1:o;i>e;e++){let t=l.get(e);t&&n.push(t)}}return n}(function(e,t){let i=t.length,r=i%2!=0,o=Math.floor(i/2),a=[];for(let t of e){let e=t.__likertLevelIndex;if(r&&e===o){let e=t.__likertPct/2;a.push({...t,__likertLevel:Ph,__likertPct:-e}),a.push({...t,__likertLevel:Lh,__likertPct:e})}else a.push(o>e?{...t,__likertPct:-t.__likertPct}:t)}return a}(s,n),n));let c=le(o.theme).colors.diverging,u=Array.isArray(r)&&r.length>=n.length?r:function(e,t){if(0>=e)return[];if(t&&Object.prototype.hasOwnProperty.call(_h,t)){let i=_h[t];if(1===e)return[i(.5)];let r=[];for(let t=0;e>t;t++)r.push(i(t/(e-1)));return r}let i=["#da1e28","#ff8389","#ffb3b8"],r=["#a6c8ff","#4589ff","#0043ce"],o="#a8a8a8";if(1===e)return[o];let a=e%2!=0,n=Math.floor(e/2),l=[];for(let e=0;n>e;e++)l.push(i[Math.min(Math.floor(e*i.length/n),i.length-1)]);a&&l.push(o);for(let e=0;n>e;e++)l.push(r[Math.min(Math.floor(e*r.length/n),r.length-1)]);return l}(n.length,c),d=new Map(n.map((e,t)=>[e,u[t]||"#888"])),h=n.length%2&&d.get(n[Math.floor(n.length/2)])||"#888",f="function"==typeof a.valueFormat?a.valueFormat:e=>Math.abs(Number(e)).toFixed(0)+"%",p=i(!1===o.showLegend?void 0:{legendGroups:[{label:"",items:n.map(e=>({label:e})),styleFn:e=>({fill:d.get(e.label)||"#888"})}]},o.legend),y=a.styleRules,g=o.pieceStyle;return{chartType:"bar",data:s,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:l?"horizontal":"vertical",barPadding:a.barPadding,showGrid:o.showGrid,oLabel:a.categoryLabel,rLabel:a.valueLabel||(l?void 0:"Percentage"),rFormat:f,...a.categoryFormat&&{oFormat:a.categoryFormat},...a.valueExtent&&{rExtent:a.valueExtent},...o,pieceStyle:q((e,t)=>{let i=e.__likertLevel||e.data?.__likertLevel,r=e.__likertLevelLabel||e.data?.__likertLevelLabel,o=e.__likertPct??e.data?.__likertPct,a={fill:i===Ph||i===Lh?h:d.get((r||i)+"")||"#888"};return y?.length&&Object.assign(a,fu(e,y,{value:"number"==typeof o?o:void 0,category:t??(null==r?void 0:r+"")})),"function"==typeof g?Object.assign(a,g(e,t)||{}):g&&"object"==typeof g&&Object.assign(a,g),a},ae(a)),showLegend:o.showLegend??!0,legendPosition:o.legendPosition||"right",...p&&{legend:p},__legendIncludesAutomatic:!0}}};import{jsx as Th,jsxs as Rh}from"react/jsx-runtime";import{Fragment as Ch,jsx as Ih,jsxs as Dh}from"react/jsx-runtime";var zh={frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(e,{theme:t}){let i=e.__gauge;if(!i)return null;let r=(i.startAngleDeg+(i.gMax===i.gMin?0:(Math.max(i.gMin,Math.min(i.gMax,i.value??i.gMin))-i.gMin)/(i.gMax-i.gMin))*i.sweep-90)*Math.PI/180,o=i.needleColor||t.colors.text,a=i.showScaleLabels?(i.thresholds||[]).filter(e=>e.value>i.gMin&&i.gMax>e.value):[];return Dh(Ch,{children:[i.showNeedle&&Dh(Ch,{children:[Ih("line",{x1:i.centerX,y1:i.centerY,x2:i.centerX+i.needleLength*Math.cos(r),y2:i.centerY+i.needleLength*Math.sin(r),stroke:o,strokeWidth:2.5,strokeLinecap:"round"}),Ih("circle",{cx:i.centerX,cy:i.centerY,r:4,fill:o})]}),null!=i.contextValue&&Ih("text",{x:i.centerX,y:i.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:i.valueFontSize,fontWeight:700,fill:o,children:i.contextValue}),a.map((e,r)=>{let o=(i.startAngleDeg+(i.gMax===i.gMin?0:(e.value-i.gMin)/(i.gMax-i.gMin))*i.sweep-90)*Math.PI/180,a=i.innerRadius-1,n=i.radius+1,l=i.radius+10,s=((o+Math.PI/2)/(2*Math.PI)*12+12)%12,c=s>=11||1>s?"middle":5>s?"start":7>s?"middle":"end",u=s>=11||1>s?"auto":5>s?"middle":7>s?"hanging":"middle";return Dh("g",{children:[Ih("line",{x1:i.centerX+Math.cos(o)*a,y1:i.centerY+Math.sin(o)*a,x2:i.centerX+Math.cos(o)*n,y2:i.centerY+Math.sin(o)*n,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),Ih("text",{x:i.centerX+Math.cos(o)*l,y:i.centerY+Math.sin(o)*l,textAnchor:c,dominantBaseline:u,fill:t.colors.textSecondary,fontSize:10,children:e.label||e.value+""})]},"gauge-label-"+r)})]})},buildProps:(e,t,i,r,o)=>{let a=o.min??0,n=o.max??100,l=o.sweep??240,s=o.arcWidth??.3,c=!1!==o.showNeedle,u=!1!==o.fillZones,{startAngleDeg:d}=He(l),h=o.thresholds,f=te(r.gradientFill),p=function(e){let{min:t,max:i,value:r,thresholds:o,fillColor:a,backgroundColor:n,fillZones:l,showScaleLabels:s,gradientFill:c,gradientSteps:u=240}=e,d=i-t||1,h=(Math.max(t,Math.min(i,r))-t)/d,f=o&&o.length>0?[...o].sort((e,t)=>e.value-t.value):[{value:i,color:a||"#007bff"}];f=f.map(e=>({...e,value:Math.max(t,Math.min(i,e.value))})),i>f[f.length-1].value&&f.push({value:i,color:f[f.length-1].color});let p=!!c&&c.stops.length>=2,y=[],g=new Map,m=[];if(p){let e=l?h:1,t=Ve("bg",0);if(y.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),g.set(t,{fill:n,opacity:.4}),e>0){let t=Math.max(1,Math.floor(u)),i=Math.max(1,Math.min(t,Math.round(e*t))),r=[];for(let t=0;i>t;t++)r.push(Ge(c.stops,e*(t+.5)/i,a||f[0]?.color||"#007bff"));let o=Ve("fill",0);y.push({category:o,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:r}}),g.set(o,{fill:r[0]||n})}}else{let e=t;for(let i=0;f.length>i;i++){let r=f[i],o=(r.value-e)/d,a=(e-t)/d,s=(r.value-t)/d,c=Math.max(0,(l?Math.min(h,s):s)-a),u=l?Math.max(0,o-c):0;if(c>0){let e=Ve("fill",i);y.push({category:e,value:c,_zone:r.label||"Zone "+(i+1),_isFill:!0}),g.set(e,{fill:r.color})}if(u>0){let e=Ve("bg",i);y.push({category:e,value:u,_zone:r.label||"Zone "+(i+1),_isFill:!1}),g.set(e,{fill:n,opacity:.4})}e=r.value}}if(s&&o&&o.length>0)for(let e of o)e.value>t&&i>e.value&&m.push({type:"gauge-label",value:e.value,label:e.label||e.value+""});return{gaugeData:y,pieceStyle:(e,t)=>g.get(t||e.category)||{fill:n},gaugeAnnotations:m}}({min:a,max:n,value:o.value,thresholds:h,fillColor:o.color,backgroundColor:o.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:!1!==o.showScaleLabels,gradientFill:f}),y=o.styleRules,[g,m]=r.size||[300,250],x=function(e=240){let{sweepRad:t,offsetRad:i}=He(e),r=[[Math.cos(i),Math.sin(i)],[Math.cos(i+t),Math.sin(i+t)],[0,0]];for(let e=0;2*Math.PI>e;e+=Math.PI/2)t+.001>=((e-i)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)&&r.push([Math.cos(e),Math.sin(e)]);let o=r.map(e=>e[0]),a=r.map(e=>e[1]),[n,l]=nd(o),[s,c]=nd(a);return{minX:n,maxX:l,minY:s,maxY:c,width:l-n,height:c-s,cx:(n+l)/2,cy:(s+c)/2}}(l),b=Math.min(10,Math.max(1,Math.min(g,m)/12)),v=Math.max(4,Math.min((g-2*b)/x.width,(m-2*b)/x.height)-2),w=Math.max(0,Math.min(v-1.5,v*(1-s))),k=g/2-x.cx*v,A=m/2-x.cy*v,S=2*(v+4),M=Math.max(a,Math.min(n,o.value??a)),_="function"==typeof o.valueFormat?o.valueFormat(M):Math.round(M)+"",P=o.centerContent??r.centerContent,L=null!=P?"function"==typeof P?P(M,a,n):P:"sparkline"===o.mode||"context"===o.mode?void 0:function({value:e,min:t,max:i,radius:r,showScaleLabels:o}){let a=Math.max(16,.3*r);return Rh("g",{textAnchor:"middle",children:[Th("text",{y:0,dominantBaseline:"central",fontSize:a,fontWeight:700,fill:"var(--semiotic-text, #333)",children:e}),o&&Rh("text",{y:.7*a+11,fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:[t," – ",i]})]})}({value:_,min:a,max:n,radius:v,showScaleLabels:!1!==o.showScaleLabels});return{chartType:"donut",data:p.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:w,sweepAngle:l,startAngle:d,oSort:!1,pieceStyle:q((e,t)=>{let i={...p.pieceStyle(e,t)};return y?.length&&Object.assign(i,fu(e,y,{value:"number"==typeof e.value?e.value:void 0,category:t??(null==e.category?void 0:e.category+"")})),i},ae(o)),...null!=o.cornerRadius&&{cornerRadius:o.cornerRadius},...r,size:[g,m],margin:{top:A-S/2,bottom:m-A-S/2,left:k-S/2,right:g-k-S/2},...null!=L&&{centerContent:L},showAxes:!1,annotations:[...Array.isArray(r.annotations)?r.annotations:[],...p.gaugeAnnotations],__gauge:{gMin:a,gMax:n,sweep:l,arcWidth:s,value:M,startAngleDeg:d,thresholds:h,centerX:k,centerY:A,radius:v,innerRadius:w,showScaleLabels:!1!==o.showScaleLabels,needleLength:w>20?w-8:v-1,showNeedle:c,needleColor:o.needleColor,..."context"===o.mode&&null==P&&{contextValue:_,contextValueY:A-.2*w,valueFontSize:Math.max(12,Math.min(22,.28*v))}}}}},Oh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=ne(r.annotations,o.regression);return{chartType:"bar",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",projection:"horizontal"===o.orientation?"horizontal":"vertical",...o.valueExtent&&{rExtent:o.valueExtent},oSort:o.sort??!1,colorAccessor:t,colorScheme:i,barPadding:o.barPadding,...null!=o.roundedTop&&{roundedTop:o.roundedTop},...r,...a&&{annotations:a},gradientFill:qe(r.gradientFill),pieceStyle:Ue(e,t,i,r,o)}}},Fh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=t||o.stackBy;return{chartType:"bar",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",stackBy:o.stackBy,colorAccessor:a,colorScheme:i,projection:"horizontal"===o.orientation?"horizontal":"vertical",...o.valueExtent&&{rExtent:o.valueExtent},normalize:o.normalize,oSort:o.sort??!1,barPadding:o.barPadding,...null!=o.roundedTop&&{roundedTop:o.roundedTop},...r,gradientFill:qe(r.gradientFill),pieceStyle:Ue(e,a,i,r,o),showLegend:r.showLegend??!!a}}},Nh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=t||o.groupBy;return{chartType:"clusterbar",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",groupBy:o.groupBy,colorAccessor:a,colorScheme:i,projection:"horizontal"===o.orientation?"horizontal":"vertical",...o.valueExtent&&{rExtent:o.valueExtent},oSort:o.sort??!1,barPadding:o.barPadding,...null!=o.roundedTop&&{roundedTop:o.roundedTop},...r,gradientFill:qe(r.gradientFill),pieceStyle:Ue(e,a,i,r,o),showLegend:r.showLegend??!!a}}},Eh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=t||o.categoryAccessor,n=du(o.valueAccessor??"value");return{chartType:"pie",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",projection:"radial",colorAccessor:a,colorScheme:i,...null!=o.cornerRadius&&{cornerRadius:o.cornerRadius},...null!=o.startAngle&&{startAngle:o.startAngle},...r,pieceStyle:Ue(e,a,i,r,o,e=>{let t=n(e);return null==t?void 0:Math.abs(t)}),showLegend:r.showLegend??!!a}}},Wh={frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,i,r,o)=>{let a=t||o.categoryAccessor,n=du(o.valueAccessor??"value");return{chartType:"donut",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",projection:"radial",margin:r.margin??{top:50,right:40,bottom:60,left:70},innerRadius:o.innerRadius??60,colorAccessor:a,colorScheme:i,...null!=o.cornerRadius&&{cornerRadius:o.cornerRadius},...null!=o.startAngle&&{startAngle:o.startAngle},...r,pieceStyle:Ue(e,a,i,r,o,e=>{let t=n(e);return null==t?void 0:Math.abs(t)})}}},jh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],n=o.valueAccessor||"value",l=a.map(e=>Number("function"==typeof n?n(e):e[n])).filter(Number.isFinite),s=l.length?[Math.min(...l),Math.max(...l)]:void 0;return{chartType:"histogram",data:e,oAccessor:o.categoryAccessor||(e=>null==e.category?"All":e.category+""),rAccessor:n,projection:"horizontal",bins:o.bins??25,normalize:o.relative??!1,colorAccessor:t,colorScheme:i,barPadding:o.categoryPadding??20,...o.valueExtent?{rExtent:o.valueExtent}:s?{rExtent:s}:{},...r,summaryStyle:Ze(e,t,i,r,o,"count")}}},Bh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>({chartType:"boxplot",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",projection:"horizontal"===o.orientation?"horizontal":"vertical",...o.valueExtent&&{rExtent:o.valueExtent},colorAccessor:t,colorScheme:i,...null!=o.showOutliers&&{showOutliers:o.showOutliers},...null!=o.outlierRadius&&{outlierRadius:o.outlierRadius},...r,summaryStyle:Ze(e,t,i,r,o)})},Yh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>({chartType:"violin",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===o.orientation?"horizontal":"vertical",bins:o.bins??25,showIQR:o.showIQR??!0,barPadding:o.categoryPadding??20,colorScheme:i,...r,summaryStyle:Ke(e,t,i,r,o),showLegend:r.showLegend??!!t,...o.valueExtent&&{rExtent:o.valueExtent}})},Xh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>({chartType:"swarm",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",projection:"horizontal"===o.orientation?"horizontal":"vertical",...o.valueExtent&&{rExtent:o.valueExtent},barPadding:o.categoryPadding??20,colorAccessor:t,...o.symbolBy&&{symbolAccessor:o.symbolBy},...o.symbolMap&&{symbolMap:o.symbolMap},colorScheme:i,...r,sizeRange:o.sizeRange||[3,8],pieceStyle:Je(e,t,i,r,o),showLegend:r.showLegend??!!t})},Gh={frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,i,r,o)=>{let a=ne(r.annotations,o.regression);return{chartType:"point",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===o.orientation?"vertical":"horizontal",...o.valueExtent&&{rExtent:o.valueExtent},oSort:o.sort??"auto",barPadding:o.categoryPadding??10,...r,...a&&{annotations:a},pieceStyle:Qe(e,t,i,r,o),showGrid:r.showGrid??!0,showLegend:r.showLegend??!!t}}},Vh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=o.seriesAccessor||t||"__radar",n=t||("__radar"===a?void 0:a),l=Qe(e,n,i,r,{...o,dotRadius:o.pointRadius??4});return{chartType:"point",projection:"radial",data:e,oAccessor:o.categoryAccessor||"attribute",rAccessor:o.valueAccessor||"value",colorAccessor:n,colorScheme:i,connectorAccessor:a,connectorStyle:e=>{let t=l(e),i="string"==typeof t.fill?t.fill:void 0;return{fill:i,fillOpacity:.15,stroke:i,strokeWidth:2,opacity:.7}},pieceStyle:l,rExtent:o.valueExtent||[0],oLabel:"",...r,...o.categoryFormat&&{oFormat:o.categoryFormat},showLegend:r.showLegend??!!n}}},Hh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>{let a=t||o.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",stackBy:o.subcategoryAccessor,colorAccessor:a,categoryAccessor:o.categoryAccessor,subcategoryAccessor:o.subcategoryAccessor,colorScheme:i,projection:"vertical"===o.orientation?"vertical":"horizontal",...null!=o.trackFill&&{trackFill:o.trackFill},...o.valueExtent&&{rExtent:o.valueExtent},...null!=o.roundedTop&&{roundedTop:o.roundedTop},...r,gradientFill:qe(r.gradientFill),pieceStyle:Ue(e,a,i,r,o),showLegend:r.showLegend??!!a,barPadding:o.barPadding??40}}},qh={frameType:"ordinal",buildProps:(e,t,i,r,o)=>({chartType:"ridgeline",data:e,oAccessor:o.categoryAccessor||"category",rAccessor:o.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===o.orientation?"vertical":"horizontal",...o.valueExtent&&{rExtent:o.valueExtent},bins:o.bins??20,amplitude:o.amplitude??1.5,barPadding:o.categoryPadding??5,oSort:o.oSort??!1,...r,summaryStyle:Ze(e,t,i,r,o,"median",.5),showLegend:r.showLegend??!!t})},Uh={frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,o)=>{let a="vertical"===o.orientation,n=t||o.categoryAccessor;return{chartType:a?"bar-funnel":"funnel",data:e,oAccessor:o.stepAccessor||"step",rAccessor:o.valueAccessor||"value",colorAccessor:n,categoryAccessor:o.categoryAccessor,projection:a?"vertical":"horizontal",connectorAccessor:o.connectorAccessor,connectorStyle:o.connectorStyle,...!a&&null!=o.connectorOpacity&&{connectorOpacity:o.connectorOpacity},barPadding:a?40:0,colorScheme:i,...r,showAxes:a&&!1!==r.showAxes,showGrid:a,pieceStyle:Ue(e,n,i,r,o),showLabels:o.showLabels??!0}}};import{scaleTime as Zh}from"d3-scale";var Kh={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}},Qh=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]),Jh=e=>{let t=1;for(let i=2;e>=i;i++)t*=i;return t},ef=828*Jh(8),tf=3e3,rf=new Map,of=1e5,af=1e-9,nf=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi,lf=null;import{jsx as sf,jsxs as cf}from"react/jsx-runtime";var uf=new Map;import{Fragment as df,jsx as hf,jsxs as ff}from"react/jsx-runtime";var pf="var(--semiotic-grid, #94a3b8)",yf="var(--semiotic-text-secondary, #475569)",gf="var(--semiotic-text-secondary, #94a3b8)",mf=e=>{let{bands:t=[],ribbons:i=[],showLabels:r=!0,selectionDatum:o="raw"}=e.config,a=e.selection??null,n=[];for(let e of i){let t={__kind:"ribbon",data:e.rawDatum,id:e.id},i=!ui(t,a,o);n.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:i?Math.min(e.opacity,.22):e.opacity,stroke:"none"},datum:t})}for(let e of t){if(!e.gradientStubs)continue;let t=!ui({__kind:"band",data:e.rawDatum,id:e.id},a,o);for(let i=0;e.gradientStubs.length>i;i++){let r=e.gradientStubs[i];n.push({type:"bezier",pathD:r.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?.22:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:r.x0,x1:r.x1,...null!=r.y0&&{y0:r.y0},...null!=r.y1&&{y1:r.y1},from:r.from,to:r.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${i}`}})}}for(let e of t){let t=!(!e.gradientStubs||0>=e.gradientStubs.length),i={__kind:"band",data:e.rawDatum,id:e.id},r=!ui(i,a,o);n.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:e.hatchFill??e.fill,fillOpacity:r?.22:e.fillOpacity??.86},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...r&&t?{opacity:.22}:{}},datum:i})}let l=r?t.flatMap(e=>{let t=e.labelDeferred&&e.labelFullText?.trim(),i=e.labelText.trim().length>0,r=t&&a?.isActive&&ui({__kind:"band",data:e.rawDatum,id:e.id},a,o),n=i?e.labelText:r?e.labelFullText:"";return n.trim()?[{x:e.labelX,y:e.labelY,text:n,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:n,labels:l}},xf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,o)=>{if(!(t||Array.isArray(o.styleRules)&&o.styleRules.length>0||r.nodeStyle||o.nodeStyle||H(ae(o))))return{chartType:"chord",nodes:o.nodes,edges:o.edges,valueAccessor:o.valueAccessor,padAngle:o.padAngle,groupWidth:o.groupWidth,showLabels:o.showLabels,colorBy:t,edgeColorBy:o.edgeColorBy,colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t};let a=Array.isArray(o.edges)?o.edges:[],n=Array.isArray(o.nodes)&&o.nodes.length>0?o.nodes:hi([],a,o.sourceAccessor||"source",o.targetAccessor||"target"),l=le(r.theme).colors.categorical,s=B(i,l),c="string"==typeof t?t:"__ssrChordColorBy",u="function"==typeof t?n.map(e=>({...e,__ssrChordColorBy:t(e)})):n,d=t?G(u,c,i??r.colorScheme??l):void 0,h=new Map,f=o.nodeIdAccessor||o.nodeIDAccessor||"id",p=(e,i)=>{let r,a=e?.data||e;if(t)r=Y(a,t,d);else{let t=(e.id??a?.[f]??"")+"";h.has(t)||h.set(t,h.size);let o=e.index??i??h.get(t);r=s[o%s.length]}return{fill:r,stroke:o.stroke??"black",strokeWidth:o.strokeWidth??1,...void 0!==o.opacity&&{opacity:o.opacity}}},y=pu(o.styleRules,t,o.valueAccessor);return{chartType:"chord",nodes:o.nodes,edges:o.edges,valueAccessor:o.valueAccessor,padAngle:o.padAngle,groupWidth:o.groupWidth,showLabels:o.showLabels,colorBy:t,edgeColorBy:o.edgeColorBy,colorScheme:i,nodeStyle:q(o.nodeStyle||(y?(e,t)=>({...p(e,t),...y(e,t)}):p),ae(o)),...r,showLegend:(r.showLegend??!!t)&&!!t}}},bf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,o)=>{let a=function(e){if(void 0!==e.edgeStyle)return e.edgeStyle;let{edgeWidth:t,edgeColor:i,edgeOpacity:r}=e,o=e.strokeWidth??1;return void 0!==t||void 0!==i||void 0!==r||void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity?a=>{let n=a?.data||a,l=o;if("number"==typeof t)l=t;else if("function"==typeof t)l=t(n);else if("string"==typeof t){let e=n?.[t],i="number"==typeof e?e:Number(e);l=Number.isFinite(i)&&i>0?i:o}return{stroke:i??e.stroke??"#999",strokeWidth:l,opacity:r??e.opacity??.6}}:void 0}(o),n=le(r.theme).colors.categorical,l=new Map,s=o.nodeStyle??(e=>({fill:t?Y(e?.data||e,t,void 0):_e(void 0,n,i,void 0,l),..."number"==typeof o.nodeSize&&{r:o.nodeSize}})),c=pu(o.styleRules,t,"number"==typeof o.nodeSize?void 0:o.nodeSize),u=q(c?(e,t)=>({...s(e),...c(e,t)}):s,{stroke:o.nodeStroke??o.stroke,strokeWidth:o.nodeStrokeWidth??o.strokeWidth,opacity:o.opacity});return{chartType:"force",nodes:o.nodes,edges:o.edges,nodeIDAccessor:o.nodeIdAccessor||o.nodeIDAccessor,sourceAccessor:o.sourceAccessor,targetAccessor:o.targetAccessor,colorBy:t,colorScheme:i,iterations:o.iterations,forceStrength:o.forceStrength,showLabels:o.showLabels??!1,nodeLabel:o.nodeLabel,nodeSize:o.nodeSize??8,nodeSizeRange:o.nodeSizeRange,nodeStyle:u,edgeStyle:a,...r,showLegend:(r.showLegend??!!t)&&!!t}}},vf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,o)=>{let a=le(r.theme).colors.categorical,n=new Map,l=di(e??null,o.childrenAccessor),s="function"==typeof t?t:null,c=s?l.map(e=>({__ssrCirclePackColorBy:s(e)})):l,u=s?"__ssrCirclePackColorBy":"string"==typeof t?t:void 0,d=t&&u?G(c,u,i??r.colorScheme??a):void 0,h=o.showLabels??r.showLabels,f=r.nodeStyle||o.nodeStyle,p=cu(e=>{let r=e?.data||e;return{fill:o.colorByDepth?Gd[Number(e?.depth||0)%Gd.length]:t?s?Y({__ssrCirclePackColorBy:s(r)},"__ssrCirclePackColorBy",d??void 0):Y(r,t,d??void 0):_e(void 0,a,i,void 0,n),fillOpacity:o.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}},o.styleRules,uu(t,o.valueAccessor),e=>e?.data||e);return{chartType:"circlepack",data:e,childrenAccessor:o.childrenAccessor,hierarchySum:o.valueAccessor,colorBy:t,colorByDepth:o.colorByDepth,showLabels:o.showLabels,nodeLabel:h?o.nodeLabel||o.nodeIdAccessor:void 0,...null!=o.padding&&{padding:o.padding},colorScheme:i,...r,showLegend:(r.showLegend??!(!t||o.colorByDepth))&&!(!t||o.colorByDepth),nodeStyle:fi(p,f,ae(o))}}},wf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,o)=>{let a=e??o.data,n=o.childrenAccessor||"children",l=o.nodeIdAccessor||o.nodeIDAccessor||"name",s=le(r.theme).colors.categorical,c=i??r.colorScheme??s,u=B(c,s),d=di(a,n),h="__ssrOrbitColorBy",f="function"==typeof t?t:null,p=t?G(f?d.map(e=>({[h]:f(e)})):d,f?h:t,c):void 0,y=cu(e=>{let i=e.data||e,r=Number(e.depth??0);return{fill:o.colorByDepth?0===r?u[0]:Gd[r%Gd.length]:t?f?Y({[h]:f(i)},h,p):Y(i,t,p):u[0],stroke:"#fff",strokeWidth:1,opacity:0===r?1:.85}},o.styleRules,uu(t,"value"),e=>e?.data||e);return{chartType:"orbit",data:a,childrenAccessor:n,nodeIDAccessor:l,colorBy:t,colorScheme:c,colorByDepth:o.colorByDepth??!1,nodeSize:o.nodeRadius??6,nodeLabel:o.showLabels?l:void 0,showLabels:o.showLabels??!1,orbitMode:o.orbitMode??"flat",orbitSize:o.orbitSize??2.95,orbitSpeed:o.speed??.25,orbitRevolution:o.revolution,orbitRevolutionStyle:o.revolutionStyle,orbitEccentricity:o.eccentricity??1,orbitShowRings:o.showRings??!0,orbitAnimated:!1,nodeStyle:q(y,ae(o)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...r,showLegend:(r.showLegend??!(!t||o.colorByDepth))&&!(!t||o.colorByDepth)}}},kf={frameType:"network",layout:{margin:{top:30,right:80,bottom:40,left:80}},buildProps:(e,t,r,o,a)=>{let n=e=>null==e?NaN:e instanceof Date?e.getTime():"number"==typeof e?e:new Date(e).getTime(),l=a.sourceAccessor||"source",s=a.targetAccessor||"target",c=a.valueAccessor||"value",u=a.nodeIdAccessor||"id",d=a.startTimeAccessor||"startTime",h=a.endTimeAccessor||"endTime",f=a.systemInTimeAccessor,p=a.systemOutTimeAccessor,y=a.xExtentAccessor||"xExtent",g=a.groupBy,m=a.edgeIdAccessor||"id",x=(e,t)=>"function"==typeof e?e(t):t[e],b=Array.isArray(a.edges)?a.edges:[],v=Array.isArray(a.nodes)?a.nodes:[],w=v.length>0?v:hi([],b,l,s),k=[n(a.domain?.[0]),n(a.domain?.[1])],A=w.map(e=>{let t=x(u,e)+"",i=x(y,e),r=a.nodeLabel?x(a.nodeLabel,e):t,o={id:t,label:null==r?t:r+"",__raw:e},l=g?x(g,e):null;if(null!=l&&l+""!=""&&(o.group=l+""),Array.isArray(i)&&2===i.length){let e=n(i[0]),t=n(i[1]);Number.isFinite(e)&&Number.isFinite(t)&&(o.xExtent=[e,t])}return o}),S=b.map((e,t)=>{let i=x(m,e),r={id:null!=i?i+"":`${x(l,e)}-${x(s,e)}-${t}`,source:x(l,e)+"",target:x(s,e)+"",value:Number(x(c,e)),startTime:n(x(d,e)),endTime:n(x(h,e)),__raw:e};if(f){let t=n(x(f,e));Number.isFinite(t)&&(r.systemInTime=t)}if(p){let t=n(x(p,e));Number.isFinite(t)&&(r.systemOutTime=t)}return r}),[M,_]=o.size??[600,400],P=o.margin,L="vertical"===a.orientation?"vertical":"horizontal",$={...ci(!!o.title,!!a.showQualityReadout,Array.isArray(a.axisTicks)&&a.axisTicks.length>0,L),...P},T=(o.showLegend??!!t)&&!!t,R=o.legendPosition??"right";T&&("right"===R?$.right=Math.max($.right,140):"left"===R?$.left=Math.max($.left,140):"top"===R?$.top=Math.max($.top,50):"bottom"===R&&($.bottom=Math.max($.bottom,80)));let C=$,I=M-C.left-C.right,D=_-C.top-C.bottom,z=B(r,le(o.theme).colors.categorical,vd),O="function"==typeof t?t:null,F=O?w.map(e=>({_cat:O(e)})):w,N=O?"_cat":"string"==typeof t?t:void 0,E=r??[...z],W=N?G(F,N,E):null,j=new Map;for(let e of A)j.set(e.id,e.__raw);let X=(e,i)=>{if(t&&j.has(e)){let i=j.get(e);return O?Y({_cat:O(i)},"_cat",W??void 0):Y(i,"string"==typeof t?t:"id",W??void 0)}return z[i%z.length]},V=i(T&&t?(()=>{let e=new Map;w.forEach((i,r)=>{let o=x(t,i),a=null==o?"":o+"";!a||e.has(a)||e.set(a,{label:a,color:X(x(u,i)+"",r)})});let i=Array.from(e.values());return i.length>0?{legendGroups:[{type:"fill",label:"",items:i,styleFn:e=>{let t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,o.legend),H=!1!==a.showLabels&&("auto"!==a.showLabels||"auto"),{layout:q,layoutConfig:U,issues:Z,xScale:K}=si({nodes:A,edges:S,domain:k,plotW:I,plotH:D,orientation:L,ribbonLane:a.ribbonLane||"both",ribbonMinRun:"auto"===a.ribbonMinRun||"number"==typeof a.ribbonMinRun?a.ribbonMinRun:0,edgeOpacity:"number"==typeof a.edgeOpacity?a.edgeOpacity:.35,colorOf:X,showLabels:H,styleRules:a.styleRules,colorBy:t,valueAccessor:c,layoutOpts:{pairing:a.pairing||"temporal",packing:a.packing||"reuse",laneOrder:a.laneOrder||"crossing-min",lifetimeMode:a.lifetimeMode||"half",maxValueScale:"number"==typeof a.maxValueScale?a.maxValueScale:void 0,lanePlacement:a.lanePlacement||"stack",nodeSizing:a.nodeSizing||"temporal",groupPadding:"number"==typeof a.groupPadding?a.groupPadding:0}});if(Z.length>0){let e=Z.map(it).join("; ");throw Error("ProcessSankey: data invalid — "+e)}let Q=q?function(e){let t=e.layout,i=e.nodes,r=e.orientation,o=e.plotW,a=e.plotH,n=e.timelineExtent,l=e.axisTicks,s=e.showQualityReadout??!1,c=e.showLaneRails??!1,u=(e.warnings??[]).slice(0,3),d=e.timeFormat,h=e.colorOf,f=e.toTime,p=e.xScale,{centerlines:y,laneLifetime:g,nodeData:m,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:A}=t,S=null,M=null;for(let e of i){let t=g[e.id];if(!t||null===t.start||null===t.end)continue;let i=p(t.start),r=p(t.end);(null===S||S>i)&&(S=i),(null===M||r>M)&&(M=r)}let _=e=>Math.max(0,Math.min(n,e)),P=_(S??0),L=Math.max(P,_(M??n)),$=l.map((e,t)=>({tick:e,index:t,coordinate:p(f(e.date))})).filter(({coordinate:e})=>e>=P-.5&&L+.5>=e),T=null!==(w??null)&&null!=k&&null!=A,R=s&&(T||u.length>0)?ff("g",{fill:gf,fontSize:10,textAnchor:"end",children:[T&&ff(df,{children:[ff("text",{x:o,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(A.pixelLength)]}),ff("text",{x:o,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",A.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*A.verticalUtilization),"%"]})]}),u.map((e,t)=>ff("text",{x:o,y:T?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},"warn-"+t))]}):null,C=b?hf("text",{x:o,y:"vertical"===r?-3:2,fontSize:10,fill:gf,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,I=(e,t)=>h?h(e,t):pf;return ff("g","vertical"===r?{children:[R,C,$.map(({index:e,coordinate:t})=>hf("line",{x1:0,y1:t,x2:o,y2:t,stroke:pf,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&i.map((e,t)=>{let i=g[e.id];if(!i||null===i.start)return null;let r=m[e.id],o=r?{topPeak:r.topPeak,botPeak:r.botPeak}:{topPeak:0,botPeak:0},a=y[e.id]+(o.botPeak-o.topPeak)*x/2,n=p(i.start),l=p(i.end),s=I(e.id,t);return ff("g",{children:[hf("line",{x1:a,y1:n,x2:a,y2:l,stroke:s,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),hf("line",{x1:a-4,y1:n,x2:a+4,y2:n,stroke:s,strokeOpacity:.5}),hf("line",{x1:a-4,y1:l,x2:a+4,y2:l,stroke:s,strokeOpacity:.5})]},"lane-"+e.id)}),hf("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:pf}),$.map(({tick:e,index:t,coordinate:i})=>{let r=f(e.date),o=null!=e.label?e.label:d?d(new Date(r)):"";return ff("g",{transform:`translate(-4,${i})`,children:[hf("line",{x2:-6,stroke:pf}),hf("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:yf,children:o})]},t)})]}:{children:[R,C,$.map(({index:e,coordinate:t})=>hf("line",{x1:t,y1:0,x2:t,y2:a,stroke:pf,strokeOpacity:.15,strokeDasharray:"2 4"},"grid-"+e)),c&&i.map((e,t)=>{let i=g[e.id];if(!i||null===i.start)return null;let r=m[e.id],o=r?{topPeak:r.topPeak,botPeak:r.botPeak}:{topPeak:0,botPeak:0},a=y[e.id]+(o.botPeak-o.topPeak)*x/2,n=p(i.start),l=p(i.end),s=I(e.id,t);return ff("g",{children:[hf("line",{x1:n,y1:a,x2:l,y2:a,stroke:s,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),hf("line",{x1:n,y1:a-4,x2:n,y2:a+4,stroke:s,strokeOpacity:.5}),hf("line",{x1:l,y1:a-4,x2:l,y2:a+4,stroke:s,strokeOpacity:.5})]},"lane-"+e.id)}),hf("line",{x1:P,y1:a+4,x2:L,y2:a+4,stroke:pf}),$.map(({tick:e,index:t,coordinate:i})=>{let r=f(e.date),o=null!=e.label?e.label:d?d(new Date(r)):"";return ff("g",{transform:`translate(${i},${a+4})`,children:[hf("line",{y2:6,stroke:pf}),hf("text",{y:20,textAnchor:"middle",fontSize:11,fill:yf,children:o})]},t)})]})}({layout:q,nodes:A,orientation:L,plotW:I,plotH:D,timelineExtent:"vertical"===L?D:I,axisTicks:Array.isArray(a.axisTicks)?a.axisTicks.map(e=>({date:e.date,label:e.label})):[],showQualityReadout:!!a.showQualityReadout,showLaneRails:!!a.showLaneRails,timeFormat:"function"==typeof a.timeFormat?e=>a.timeFormat(e):void 0,colorOf:X,toTime:e=>n(e),xScale:e=>Number(K(e))}):void 0;return{chartType:"force",nodes:w,edges:b,customNetworkLayout:mf,layoutConfig:U,sourceAccessor:l,targetAccessor:s,valueAccessor:c,nodeIDAccessor:u,colorBy:t,colorScheme:r,...Q&&{backgroundGraphics:Q},...o,showLegend:T,...V&&{legend:V,legendPosition:R},__legendIncludesAutomatic:!0,margin:C}}},Af={frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,i,r,o)=>{let a=Array.isArray(o.nodes)?o.nodes:hi([],Array.isArray(o.edges)?o.edges:[],o.sourceAccessor||"source",o.targetAccessor||"target"),n=le(r.theme).colors.categorical,l=new Map,s="string"==typeof t?t:"__ssrSankeyColorBy",c="function"==typeof t?a.map(e=>({...e,__ssrSankeyColorBy:t(e)})):a,u=t?G(c,s,i??r.colorScheme??n):void 0,d=e=>({fill:t?Y(e?.data||e,t,u):_e(void 0,n,i,void 0,l),stroke:o.stroke??"black",strokeWidth:o.strokeWidth??1,...void 0!==o.opacity&&{opacity:o.opacity}}),h=pu(o.styleRules,t,o.valueAccessor),f=h?(e,t)=>({...d(e),...h(e,t)}):d,p=function({edgeColorBy:e,colorBy:t,colorScale:i,nodeStyleFn:r,edgeOpacity:o,baseStyle:a={}}){return n=>{let l={fillOpacity:o,...a};if("function"==typeof e)l.fill=e(n);else if("source"===e){let e="object"==typeof n.source?n.source:null;t&&e?l.fill=Y(e.data||e,t,i):e&&(l.fill=r(e,e.index).fill)}else if("target"===e){let e="object"==typeof n.target?n.target:null;t&&e?l.fill=Y(e.data||e,t,i):e&&(l.fill=r(e,e.index).fill)}else"gradient"===e&&(l.fill="#999",l.fillOpacity=.7*o);return l}}({edgeColorBy:o.edgeColorBy??"source",colorBy:t,colorScale:u,nodeStyleFn:f,edgeOpacity:o.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:o.nodes,edges:o.edges,nodeIDAccessor:o.nodeIdAccessor||o.nodeIDAccessor,sourceAccessor:o.sourceAccessor,targetAccessor:o.targetAccessor,valueAccessor:o.valueAccessor,orientation:o.orientation,nodeAlign:o.nodeAlign,nodeWidth:o.nodeWidth,nodePaddingRatio:o.nodePaddingRatio,showLabels:o.showLabels,nodeLabel:o.nodeLabel,colorBy:t,edgeColorBy:o.edgeColorBy,edgeOpacity:o.edgeOpacity,nodeStyle:q(o.nodeStyle||f,ae(o)),edgeStyle:q(o.edgeStyle||p,ae(o)),colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t}}},Sf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,o)=>{let a=le(r.theme).colors.categorical,n=new Map,l=di(e??null,o.childrenAccessor),s="function"==typeof t?t:null,c=s?l.map(e=>({__ssrTreeColorBy:s(e)})):l,u=s?"__ssrTreeColorBy":"string"==typeof t?t:void 0,d=t&&u?G(c,u,i??r.colorScheme??a):void 0,h=!1!==o.showLabels,f=r.nodeStyle||o.nodeStyle,p=cu(e=>{let r=e?.data||e;return{fill:o.colorByDepth?Gd[Number(e?.depth||0)%Gd.length]:t?s?Y({__ssrTreeColorBy:s(r)},"__ssrTreeColorBy",d??void 0):Y(r,t,d??void 0):_e(void 0,a,i,void 0,n),stroke:o.stroke??"black",strokeWidth:o.strokeWidth??1,...void 0!==o.opacity&&{opacity:o.opacity}}},o.styleRules,uu(t,o.valueAccessor),e=>e?.data||e);return{chartType:"cluster"===o.layout?"cluster":"tree",data:e,childrenAccessor:o.childrenAccessor,colorBy:t,colorByDepth:o.colorByDepth,orientation:o.orientation,showLabels:o.showLabels,nodeLabel:h?o.nodeLabel||o.nodeIdAccessor:void 0,colorScheme:i,...r,showLegend:(r.showLegend??!(!t||o.colorByDepth))&&!(!t||o.colorByDepth),nodeStyle:fi(p,f,ae(o))}}},Mf={frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,o)=>{let a=le(r.theme).colors.categorical,n=new Map,l=di(e??null,o.childrenAccessor),s="function"==typeof t?t:null,c=s?l.map(e=>({__ssrTreemapColorBy:s(e)})):l,u=s?"__ssrTreemapColorBy":"string"==typeof t?t:void 0,d=t&&u?G(c,u,i??r.colorScheme??a):void 0,h=o.showLabels??r.showLabels,f=o.labelMode,p=void 0!==o.paddingTop?o.paddingTop:r.paddingTop,y=void 0!==p?p:!h||"parent"!==f&&"all"!==f?void 0:18,g=r.nodeStyle||o.nodeStyle,m=cu(e=>{let r=e?.data||e;return{fill:o.colorByDepth?Gd[Number(e?.depth||0)%Gd.length]:t?s?Y({__ssrTreemapColorBy:s(r)},"__ssrTreemapColorBy",d??void 0):Y(r,t,d??void 0):_e(void 0,a,i,void 0,n),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}},o.styleRules,uu(t,o.valueAccessor),e=>e?.data||e);return{chartType:"treemap",data:e,childrenAccessor:o.childrenAccessor,hierarchySum:o.valueAccessor,colorBy:t,colorByDepth:o.colorByDepth,showLabels:o.showLabels,labelMode:f,nodeLabel:h?o.nodeLabel||o.nodeIdAccessor:void 0,...null!=o.padding&&{padding:o.padding},...null!=y&&{paddingTop:y},colorScheme:i,...r,showLegend:(r.showLegend??!(!t||o.colorByDepth))&&!(!t||o.colorByDepth),nodeStyle:fi(m,g,ae(o))}}},_f={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};import{scaleSequential as Pf}from"d3-scale";var Lf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,o)=>{let a="string"==typeof i?i:"blues",n=function(e,t,i){if(!Array.isArray(e))return;let r=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0,o=1/0,a=-1/0;for(let t of e){let e=r(t);null==e||!isFinite(e)||(o>e&&(o=e),e>a&&(a=e))}let n=[Number.isFinite(o)?o:0,Number.isFinite(a)?a:1],l=Pf(j(i)).domain(n);return{domain:n,colorScale:e=>l(e),valueAccessor:r}}(o.areas,o.valueAccessor,a),l=o.areaStyle??function(e,t){if(e)return i=>{let r=e.valueAccessor(i);return{fill:null!=r&&isFinite(r)?e.colorScale(r):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:t}}}(n,o.areaOpacity??1),s=o.styleRules?cu(l,o.styleRules,e=>{return{value:(t=e,"function"==typeof o.valueAccessor?o.valueAccessor(t):null!=o.valueAccessor?t?.properties?.[o.valueAccessor]??t?.[o.valueAccessor]:void 0)};var t},mi):l,c=!1!==r.showLegend&&n?{gradient:{colorFn:n.colorScale,domain:n.domain,label:"string"==typeof o.valueAccessor?o.valueAccessor:"value"}}:void 0;return{areas:o.areas,projection:o.projection||"equalEarth",areaStyle:s,valueAccessor:o.valueAccessor,colorScheme:a,graticule:o.graticule,fitPadding:o.fitPadding,...r,...void 0===r.legend&&c?{legend:c}:{}}}},$f={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,o)=>{let a=e||o.points,n=o.pointStyle??gi(a,t,i,{sizeBy:o.sizeBy,sizeRange:o.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),l=o.styleRules?cu(n,o.styleRules,uu(t,o.sizeBy)):n;return{points:a,xAccessor:o.xAccessor||"lon",yAccessor:o.yAccessor||"lat",areas:o.areas,areaStyle:o.areaStyle||_f,pointStyle:l,sizeBy:o.sizeBy,colorBy:t,colorScheme:i,projection:o.projection||"equalEarth",graticule:o.graticule,fitPadding:o.fitPadding,...r}}},Tf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,o)=>{let a=e||o.points,n=o.pointStyle??gi(a,t,i,{pointRadius:"number"==typeof o.pointRadius?o.pointRadius:5,fillOpacity:.85,strokeWidth:1}),l=o.nodeIdAccessor||"id",s=o.cartogramLayout||("sparkline"===o.mode?"strip":"radial"),c="sparkline"===o.mode,u="strip"===s,d=o.styleRules?cu(n,o.styleRules,uu(t)):n;return{points:a,lines:o.lines,xAccessor:o.xAccessor||"lon",yAccessor:o.yAccessor||"lat",pointStyle:e=>{let t="function"==typeof d?d(e):d,i="function"==typeof l?l(e):e[l],r=null!=i&&i+""==o.center+"",a="number"==typeof t.r?t.r:5;return{...t,fillOpacity:r?1:t.fillOpacity??.8,stroke:r?"var(--semiotic-text, #222)":t.stroke??"#fff",strokeWidth:r?1.25:t.strokeWidth??1,r:r?1.35*a:a}},colorBy:t,colorScheme:i,projection:o.projection||"mercator",graticule:o.graticule,fitPadding:o.fitPadding,projectionTransform:{center:o.center,centerAccessor:l,costAccessor:o.costAccessor,strength:o.strength??1,lineMode:o.lineMode||"straight",layout:s},...r,cartogramChrome:{showRings:o.showRings??!0,showNorth:o.showNorth??(!u&&!c),showRingLabels:o.showRingLabels??!u,costLabel:o.costLabel}}}},Rf={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,o)=>{let a=(Array.isArray(e)?e:null)||o.flows||[],n=o.nodeIdAccessor||"id",l=o.valueAccessor||"value",s=o.xAccessor||"lon",c=o.yAccessor||"lat",u="function"==typeof s?s:e=>e[s],d="function"==typeof c?c:e=>e[c],h=(o.nodes||[]).map(e=>({...e,x:u(e),y:d(e)})),f=new Map;for(let e of h)f.set(e[n]+"",e);let p=o.edgeColorBy??t,y="function"==typeof p,g=a.map(e=>{if(!e||null==e.source||null==e.target)return null;let t=f.get(e.source+""),i=f.get(e.target+"");return t&&i?{...e,coordinates:[{x:t.x,y:t.y},{x:i.x,y:i.y}]}:null}).filter(Boolean),m="__flowMapEdgeColor",x=p?y?G(g.map(e=>({[m]:p(e)})),m,i||"category10"):G(g,p,i||"category10"):null,b=g.map(e=>Number(e[l]??0)).filter(e=>Number.isFinite(e)),v=b.length>0?nd(b):void 0,[w,k]=o.edgeWidthRange??[1,8];return{lines:g,points:h,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:o.lineType||"geo",flowStyle:o.flowStyle||"basic",areas:o.areas,areaStyle:o.areaStyle||_f,projection:o.projection||"equalEarth",graticule:o.graticule,fitPadding:o.fitPadding,colorScheme:i,lineStyle:yi({valueAccessor:l,valueDomain:v,edgeWidthRange:[w,k],resolveStroke:e=>p&&x?Y(e,p,x):"#007bff",edgeOpacity:o.edgeOpacity??.6,edgeLinecap:o.edgeLinecap??"round",styleRules:o.styleRules}),pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...r}}},Cf={frameType:"xy",buildProps:(e,t,i,r,o)=>({chartType:"custom",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",colorAccessor:t,colorScheme:i,customLayout:o.layout||o.customLayout,layoutConfig:o.layoutConfig,...r,showAxes:o.frameProps?.showAxes??o.showAxes??!1,showLegend:r.showLegend??!!t})},If={frameType:"ordinal",buildProps:(e,t,i,r,o)=>({chartType:"custom",data:e,oAccessor:o.categoryAccessor||o.oAccessor||"category",rAccessor:o.valueAccessor||o.rAccessor||"value",projection:o.projection||"vertical",colorAccessor:t,colorScheme:i,customLayout:o.layout||o.customLayout,layoutConfig:o.layoutConfig,...r,showAxes:o.frameProps?.showAxes??o.showAxes??!1})},Df={frameType:"ordinal",buildProps:(e,t,i,r,o)=>({...If.buildProps(e,t,i,r,o),customLayout:Wu,showAxes:!1})},zf={frameType:"xy",buildProps:(e,t,i,r,o)=>({...Cf.buildProps(e,t,i,r,o),customLayout:ku,showAxes:!1})};import*as Of from"react";import{scaleLinear as Ff}from"d3-scale";import{scaleLinear as Nf}from"d3-scale";import{scaleLinear as Ef}from"d3-scale";import{scaleLinear as Wf}from"d3-scale";var jf="gauntlet-negative",Bf={left:28,top:76,rightInset:30,thickness:8},Yf=1e-9,Xf=[900,520],Gf=[{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}],Vf=new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Hf=1e-9,qf=_r;import*as Uf from"react";import{curveMonotoneX as Zf,curveMonotoneY as Kf,curveCardinal as Qf,curveCatmullRom as Jf,curveStep as ep,curveStepBefore as tp,curveStepAfter as ip,curveBasis as rp,curveNatural as op}from"d3-shape";import{jsx as ap,jsxs as np}from"react/jsx-runtime";import{Fragment as lp,jsx as sp,jsxs as cp}from"react/jsx-runtime";var up="var(--semiotic-text, #26323a)",dp="var(--semiotic-text-secondary, #6c7377)",hp="var(--semiotic-primary, #b8792d)",fp="var(--semiotic-danger, #9f3d35)",pp="var(--semiotic-success, #356b63)";import{Fragment as yp,jsx as gp,jsxs as mp}from"react/jsx-runtime";import{jsx as xp}from"react/jsx-runtime";import{jsx as bp,jsxs as vp}from"react/jsx-runtime";import{Fragment as wp,jsx as kp,jsxs as Ap}from"react/jsx-runtime";var Sp={margin:(e,t)=>t.compactMode?"sparkline"===e.mode?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}},Mp=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"],_p={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[600,400],n=o.bins??21,l=o.seed??1,s=Math.max(1,Math.round(o.pegRows??n-1)),c="mechanical"===(o.simulationMode??o.mode),u=function(e){let{data:t,valueAccessor:i,bins:r,ballRadius:o,seed:a,size:n,valueExtent:l}=e,{rows:s}=Dc(t,"galton"),c=Wc(n),u=s.map((e,t)=>Oc(Yc(e,t,i))).filter(e=>null!=e),d=Ec(l),h=d?.[0]??(u.length?Math.min(...u):0),f=d?.[1]??(u.length?Math.max(...u):1),p=f===h?1:f-h,y=Ff().domain([0,r]).range([c.plot.x,c.plot.x+c.plot.width]),g=Array.from({length:r},()=>0),m=[];s.forEach((e,t)=>{let a=Oc(Yc(e,t,i));if(null==a)return;let n=Math.max(0,Math.min(r-1,Math.floor((a-h)/p*r)));g[n]+=1,m.push({id:(e.id??"galton-"+t)+"",x:y(n+.5),y:c.plot.y+o+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:o},datum:{...e,value:a,bin:n}})});let x=c.plot.y+c.plot.height,b=[...Su({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...Mu({idPrefix:"galton-bin",count:r,domainStart:0,domainStep:1,xScale:y,yTop:c.plot.y-400,yBottom:x,wallThickness:6})];return{config:Rc(a,b,"GaltonBoardChart"),initialSpawns:m,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:g.map((e,t)=>({label:t+1+"",value:e})),metadata:{kind:"galton-board",bins:r,plot:c.plot,valueExtent:[h,f]}}}({data:c?Fc({bins:n,branchProbability:o.branchProbability,count:o.mechanicalCount,pegRows:s,seed:l}):Array.isArray(e)?e:[],valueAccessor:o.valueAccessor||"value",bins:n,ballRadius:o.ballRadius??("sparkline"===o.mode?1.5:"context"===o.mode?4:6),seed:l,size:a,valueExtent:c?[0,s]:o.valueExtent});return{...r,config:u.config,initialSpawns:eo(u.initialSpawns),projectionRows:u.projectionRows,foregroundGraphics:to(Br(u.projectionRows,n,io(r,o,"showProjection"),u.metadata,o.referenceLines),r.foregroundGraphics),bodyStyle:eu(t||o.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:o.styleRules,valueAccessor:o.valueAccessor||"value"})}}},Pp={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[600,400],n=function(e){let{data:t,timeAccessor:i,arrivalAccessor:r,windows:o,watermark:a,watermarkAtArrivalAccessor:n,ballRadius:l,seed:s,size:c,timeExtent:u,timeScale:d=1}=e,{events:h,watermarkValue:f}=Gc({data:t,timeAccessor:i,arrivalAccessor:r,watermark:a,watermarkAtArrivalAccessor:n,windowSize:o.size}),p=Wc(c),y=h.map(e=>e.eventTime),g=h.length?Math.min(...h.map(e=>e.arrivalTime)):0,m=Oc(u?.[0]),x=Oc(u?.[1]),b=y.length?Math.min(...y):0,v=y.length?Math.max(...y):b+o.size,w=Math.min(m??b,b),k=Math.max(x??v,v),A=Math.floor(w/o.size)*o.size,S=Math.max(1,Math.ceil((k-A+o.size)/o.size)),M=Math.max(0,Math.min(S,Array.from({length:S},(e,t)=>t).reduce((e,t)=>A+(t+1)*o.size>f?e:e+1,0))),_=function(e,t){let i=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:i,height:e.plot.height},windowPlot:{x:e.plot.x+i,y:e.plot.y,width:Math.max(40,e.plot.width-i),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}(p,l),P=A+S*o.size,L=Nf().domain([A,P]).range([_.windowPlot.x,_.windowPlot.x+_.windowPlot.width]),$=Array.from({length:S},()=>({value:0,secondary:0})),T=[];h.forEach(({datum:e,index:t,eventTime:i,arrivalTime:r,watermarkAtArrival:a,late:n})=>{let s=Math.max(0,Math.min(S-1,Math.floor((i-A)/o.size)));$[s].value+=n?0:1,$[s].secondary+=n?1:0,T.push({id:(e.id??"event-"+t)+"",x:bi(i,s,n,{windowStart:A,windowSize:o.size,gutter:_.gutter,closedWindowCount:M,windowPlot:_.windowPlot,windowCount:S},l),y:p.plot.y+l+2,vx:0,vy:0,mass:1,friction:.02,spawnAt:r,shape:{type:"circle",radius:l},datum:{...e,eventTime:i,arrivalTime:r,windowIndex:s,watermarkAtArrival:a,late:n}})});let R=p.plot.y+p.plot.height,C={closedWindowCount:M,gutter:_.gutter,plot:p.plot,windowCount:S,windowPlot:_.windowPlot,windowSize:o.size,windowStart:A},I=function(e,t){let i=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!i)return[];let r=e.windowStart,o=e.windowStart+e.windowCount*e.windowSize,a=Nf().domain([r,o]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),n=a(e.windowStart+i*e.windowSize),l=e.windowPlot.x,s=t+Math.max(18,Math.min(.3*e.windowPlot.height,n-l)),c=e=>n===l?t:s+(e-l)/(n-l)*(t-s),u=[];for(let t=0;i>t;t+=1){let i=e.windowStart+t*e.windowSize,r=i+e.windowSize,o=a(i),n=a(r);u.push({id:"eventdrop-lid-"+t,windowIndex:t,x1:o,y1:c(o),x2:n,y2:c(n)})}return u}(C,p.plot.y+.28*p.plot.height);for(let e of T){let t=e.datum;e.y=xi({...C,lidSegments:I},t.windowIndex,t.late,l)}let D=function(e){let{count:t,idPrefix:i,wallThickness:r,xScale:o,yBottom:a,yTop:n,yTopForIndex:l}=e;return Array.from({length:t+1},(e,t)=>{let s=Math.min(a-1,l?.(t)??n),c=Math.max(1,a-s);return{id:`${i}-wall-${t}`,shape:{type:"aabb",x:o(t),y:s+c/2,width:r,height:c}}})}({idPrefix:"eventdrop-window",count:S,xScale:e=>L(A+e*o.size),yTop:_.wallTop,yTopForIndex:e=>{let t=(e=>{if(0>e||e>M)return null;let t=0===e?I[0]?.y1:I[e-1]?.y2??I[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null})(e);return null==t?_.wallTop:t+1.25*l},yBottom:R,wallThickness:6}),z=[...Su({x:p.plot.x,y:p.plot.y,width:p.plot.width,height:p.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...D,...I.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*l)},friction:.02,restitution:.01}))];return{config:Rc(s,z,"EventDropChart",{friction:.08}),initialSpawns:T,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>{let t=e.datum,i=M>t.windowIndex;return i&&!t.late||!i&&t.late?g:t.arrivalTime},timeScale:d},projectionRows:$.map((e,t)=>({label:`${A+t*o.size}-${A+(t+1)*o.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:M,gutter:_.gutter,lidSegments:I,lateCount:$.reduce((e,t)=>e+t.secondary,0),plot:p.plot,windowPlot:_.windowPlot,windowWalls:D.map(({id:e,shape:t})=>({id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height})),watermarkValue:f,windowCount:S,windowSize:o.size,windowStart:A}}}({data:Array.isArray(e)?e:[],timeAccessor:o.timeAccessor||"time",arrivalAccessor:o.arrivalAccessor||"arrivalTime",watermarkAtArrivalAccessor:o.watermarkAtArrivalAccessor,windows:o.windows||{size:10},watermark:o.watermark,ballRadius:o.ballRadius??7,seed:o.seed??1,size:a,timeExtent:o.timeExtent,timeScale:o.timeScale??1});return{...r,config:n.config,initialSpawns:eo(n.initialSpawns),projectionRows:n.projectionRows,foregroundGraphics:to(Yr(n.projectionRows,n.metadata,io(r,o,"showProjection")),r.foregroundGraphics),bodyStyle:eu(t||o.colorBy,"#4e79a7",{styleRules:o.styleRules,valueAccessor:o.valueAccessor||o.timeAccessor||"time"})}}},Lp={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[600,400],n="mechanical"===(o.simulationMode??o.mode),l=function(e){function t(e){let t=f.get(e);return null==t&&(t=h.length,h.push(e),f.set(e,t)),t}let{data:i,categoryAccessor:r,valueAccessor:o,unitValue:a,ballRadius:n,seed:l,size:s}=e,c=Bc(a,1),{rows:u}=Dc(i,"pile"),d=Wc(s),h=[],f=new Map,p=new Map,y=[];u.forEach((e,i)=>{t((Yc(e,i,r)??"unknown")+"")});let g=Math.max(1,h.length),m=vi(d.plot,g,n),x=Math.max(0,m.tubeWidth/2-n-1),b=h.map(()=>[]);u.forEach((e,i)=>{let a=(Yc(e,i,r)??"unknown")+"",l=t(a),s=o?Oc(Yc(e,i,o)):1,u=Math.max(0,s??0);p.set(a,(p.get(a)??0)+u);let h=jc(u,c),f=m.centerX(l);for(let t=0;h>t;t+=1){let r=b[l].length,o=t===h-1?u-t*c:c,s=Math.min(1,o/c);b[l].push({id:`${(e.id??"pile-"+i)+""}-${t}`,x:f+(m.perRow>1?((m.perRow>1?r%m.perRow:0)/(m.perRow-1)*2-1)*x:0),y:d.plot.y+n+2,vx:(t%3-1)*n/2,vy:0,mass:1,shape:{type:"circle",radius:n*Math.sqrt(s)},datum:{...e,category:a,unitIndex:t,unitValue:c,representedValue:o,unitFraction:s}})}});let v=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;v>e;e+=1)for(let t of b)t.length>e&&y.push(t[e]);let w=d.plot.y+d.plot.height,k=[...Su({x:d.plot.x,y:d.plot.y,width:d.plot.width,height:d.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],A=d.plot.y-400;for(let e=0;g>e;e+=1){let t=m.centerX(e);for(let i of[-1,1])k.push({id:`pile-tube-${e}-${0>i?"l":"r"}`,shape:{type:"aabb",x:t+i*m.tubeWidth/2,y:(A+w)/2,width:6,height:w-A}})}return{config:Rc(l,k,"UnitPileChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:h.map(e=>({label:e,value:p.get(e)??0}))}}({data:n?Nc({categories:o.mechanicalCategories,count:o.mechanicalCount,seed:o.seed??1,unitValue:o.unitValue??1}):Array.isArray(e)?e:[],categoryAccessor:o.categoryAccessor||"category",valueAccessor:o.valueAccessor||(n?"value":void 0),unitValue:o.unitValue??1,ballRadius:o.ballRadius??8,seed:o.seed??1,size:a});return{...r,config:l.config,initialSpawns:eo(l.initialSpawns),projectionRows:l.projectionRows,foregroundGraphics:to(Xr(l.projectionRows,o.ballRadius??8,io(r,o,"showProjection"),Number.isFinite(o.unitValue)&&o.unitValue>0?o.unitValue:1),r.foregroundGraphics),bodyStyle:eu(t||o.colorBy||(n?"category":void 0),"#4e79a7",{styleRules:o.styleRules,valueAccessor:o.valueAccessor||"value"})}}},$p={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[600,360],n=function(e){let{data:t,xAccessor:i,groupAccessor:r,radiusAccessor:o,pointRadius:a,seed:n,size:l,xExtent:s,collisionIterations:c,settle:u}=e,{rows:d}=Dc(t,"collision-swarm"),h=Wc(l),f=Kc(n),p=[],y=[],g=new Map;d.forEach((e,t)=>{let n=Oc(Yc(e,t,i));if(null==n)return;let l=r?(Yc(e,t,r)??"All")+"":"All",s=o?Oc(Yc(e,t,o)):null,c=Cc(null!=s&&s>0?s:a,2,18);(function(e){let t=g.get(e);null==t&&(t=y.length,y.push(e),g.set(e,t))})(l),p.push({datum:e,index:t,value:n,group:l,radius:c})});let m=p.map(e=>e.value),x=s?Oc(s[0]):null,b=s?Oc(s[1]):null,v=m.length?Math.min(...m):0,w=m.length?Math.max(...m):1,k=x??v,A=b??w;if(k===A&&(k-=.5,A+=.5),k>A){let e=A;A=k,k=e}let S=Math.max(a,...p.map(e=>e.radius)),M=h.plot.x+S+8,_=h.plot.x+h.plot.width-S-8,P=Ef().domain([k,A]).range([M,_]),L=h.plot.height/Math.max(1,y.length),$=Math.min(6,.05*L),T=e=>h.plot.y+((g.get(e)??0)+.5)*L,R=new Map,C=new Set,I=new Map;for(let e of y){let t=p.filter(t=>t.group===e),i=T(e),r=t.map(e=>({x:P(e.value),radius:e.radius})),o=wi(r,i-L/2+$,i+L/2-$,f);R.set(e,t.length),o.overlapping&&C.add(e),t.forEach((e,t)=>I.set(e.index,{x:r[t].x,y:o.positions[t],entryOffset:o.entryOffset}))}let D=p.map((e,t)=>{let i=I.get(e.index),r=i.x,o=i.y,a=C.has(e.group);return{id:(e.datum.id??"collision-swarm-"+t)+"",x:r,y:o-(u?0:i.entryOffset),vx:0,vy:0,fixedPosition:{x:r},bodyCollisions:!a,mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:r,targetY:o,overlapping:a},springs:[{target:{type:"point",x:r,y:o},restLength:0,stiffness:34,damping:12}]}}),z=Su({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20});return{config:Rc(n,z,"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:D,projectionRows:y.map(e=>({label:e,value:R.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[k,A],xRange:[M,_],groups:y.map(e=>({label:e,y:T(e),count:R.get(e)??0,overlapping:C.has(e)})),plot:h.plot}}}({data:Array.isArray(e)?e:[],xAccessor:o.xAccessor||"x",groupAccessor:o.groupAccessor,radiusAccessor:o.radiusAccessor,pointRadius:o.pointRadius??5,seed:o.seed??1,size:a,xExtent:o.xExtent,collisionIterations:o.collisionIterations,settle:o.settle});return{...r,config:n.config,initialSpawns:eo(n.initialSpawns),projectionRows:n.projectionRows,foregroundGraphics:to(Vr(n.metadata,io(r,o,"showProjection")),r.foregroundGraphics),bodyStyle:eu(t||o.colorBy||o.groupAccessor,"#4e79a7",{styleRules:o.styleRules,valueAccessor:o.xAccessor||"x"})}}},Tp={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[900,420],n=Array.isArray(o.stages)?o.stages:[],l=function(e){let t=e.stages;if(!t.length)throw Error("buildProcessFlowPhysics requires at least one stage");let i=e.size,r=Wc(i),o=Cc(e.ballRadius??6,2,18),a=e.seed??1,n=Kc(a),l=e.idAccessor,s=e.stageAccessor??"stage",c=e.groupBy,u=e.groupLabelAccessor,d=e.workAccessor,h=e.radiusAccessor,f=e.groupCompletion??(c?"allAbsorbed":"none"),p=e.springStiffness??.28,y=e.springDamping??.72,g=!0===e.settle,m=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),x=Gu({width:i[0],height:i[1],shape:"lane",padX:Math.max(28,r.plot.x),padY:Math.max(36,r.plot.y+8),stages:m,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((e,t)=>[e.id,t])),v=new Map(x.stages.map(e=>[e.id,e])),w=x.stages[0].id,k=x.stages[0],A=new Set(t.filter(e=>e.absorb).map(e=>e.id)),S=t.map(e=>{let t=v.get(e.id)??k;return function(e,t){let i={id:"process-stage-"+e.id,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return mu({...i,kind:e.kind??"sink",force:Li(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...i.attributes,primitive:"absorb"}});if(e.portal){let t=e.portal.force??e.force??{x:-40,y:0};return Bu({...i,kind:e.kind??"force-field",force:Li(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...i.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){let t=Math.max(.1,e.capacity.unitsPerSecond);return Au({...i,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Li(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...i.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){let t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return Yu({...i,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:Li(e.force,8),attributes:{...i.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?Ju({...i,kind:e.kind??"force-field",force:Li(e.force,14),damping:e.damping??.02,attributes:{...i.attributes,primitive:"routeSurface"}}):Lu({...i,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...i.attributes,primitive:"forceField"}})}(e,{x:t.x,y:x.midY,width:t.width,height:x.bottomY-x.topY})});S.unshift(Ju({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));let M=new Map;for(let e of x.stages)M.set(e.id,0);let _=[];e.data.forEach((e,t)=>{let i=(l?Yc(e,t,l)??e.id??"process-flow-"+t:e.id??"process-flow-"+t)+"",r=(Yc(e,t,s)??w)+"",a=b.has(r)?r:w;M.set(a,(M.get(a)??0)+1);let n=c?(Yc(e,t,c)??"")+"":void 0,f=n&&u?(Yc(e,t,u)??n)+"":n,p=d?Oc(Yc(e,t,d))??1:1,y=h?Oc(Yc(e,t,h)):null,g=Cc(null!=y&&y>0?y:o,2,18);_.push({datum:e,id:i,stageId:a,groupId:n||void 0,groupLabel:f||void 0,work:p,radius:g,index:t})});let P=new Map,L=new Map;for(let e of _){if(!e.groupId)continue;let t=P.get(e.groupId)??[];t.push(e.id),P.set(e.groupId,t),e.groupLabel&&L.set(e.groupId,e.groupLabel)}let $=Cc(e.groupAnchorAlong??.55,.15,.9),T=x.left+(x.right-x.left)*$,R=Array.from(P.keys()),C=R.map((e,i)=>{let r=P.get(e)??[],o=R.length>1?x.topY+28+i/Math.max(1,R.length-1)*(x.bottomY-x.topY-56):x.midY;return vu({id:e,label:L.get(e)??e,bodyIds:r,anchor:{x:T,y:o},x:T,y:o,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),I=_.filter(e=>A.has(e.stageId)).map(e=>e.id),D=Iu(C,I),z=new Map(C.map(e=>[e.id,e])),O=_.map((e,t)=>{let i=v.get(e.stageId)??k,r=i.x+(n()-.5)*Math.min(24,.2*i.width),o=x.boundaryY(r,"top")+e.radius+10,a=x.boundaryY(r,"bottom")-e.radius-10,l=a>o?o+n()*Math.max(1,a-o):x.midY,s=g?r:x.left+18+t%7*4,c=g?l:x.midY+(n()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:r,y:l},restLength:.45*e.radius,stiffness:p,damping:y}];if(e.groupId){let t=z.get(e.groupId);t?.anchor&&!A.has(e.stageId)&&u.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:s,y:c,vx:g?0:40+40*n(),vy:g?0:20*(n()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:g?0:.03*t,springs:u,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),F={kernel:{seed:a,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},N=x.stages.map(e=>({label:e.label??e.id,value:M.get(e.id)??0})),E=t.map(e=>{let t=v.get(e.id)??k;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:M.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:F,initialSpawns:O,initialSpawnPacing:g?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:N,metadata:{kind:"process-flow",plot:r.plot,volume:x,stages:E,groups:C,groupCompletion:D,regionEffects:S}}}({data:Array.isArray(e)?e:[],stages:n,size:a,idAccessor:o.idAccessor,stageAccessor:o.stageAccessor||"stage",groupBy:o.groupBy,groupLabelAccessor:o.groupLabelAccessor,workAccessor:o.workAccessor,radiusAccessor:o.radiusAccessor,ballRadius:o.ballRadius??6,seed:o.seed??1,groupCompletion:o.groupCompletion,groupAnchorAlong:o.groupAnchorAlong,settle:o.settle??!0,gravityX:o.gravityX,gravityY:o.gravityY}),s=l.metadata;return{...r,config:l.config,initialSpawns:eo(l.initialSpawns),projectionRows:l.projectionRows,regionEffects:s?.regionEffects,backgroundGraphics:to(Hr(l.metadata,io(r,o,"showChrome"),{},o.chromeOptions),r.backgroundGraphics),foregroundGraphics:to(qr(l.projectionRows,l.metadata,io(r,o,"showProjection")),r.foregroundGraphics),bodyStyle:eu(t||o.colorBy||o.groupBy,"#4e79a7",{styleRules:o.styleRules,valueAccessor:o.workAccessor||o.stageAccessor||"stage"})}}},Rp={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[900,520],n=Bi({data:Array.isArray(e)?e:[],size:a,gates:o.gates,positiveProperties:o.positiveProperties,negativeProperties:o.negativeProperties,crashOffset:o.crashOffset,idAccessor:o.idAccessor,positiveAccessor:o.positiveAccessor,negativeAccessor:o.negativeAccessor,metricsAccessor:o.metricsAccessor,initialViability:o.initialViability,projectPlacement:o.projectPlacement,coreBody:o.coreBody,viability:o.viability});return{...r,config:n.config,initialSpawns:eo(n.initialSpawns),projectionRows:[],backgroundGraphics:to(io(r,o,"showChrome")?Of.createElement(Qr,{layout:n.layout,states:n.states,compact:!0===r.__compactMode}):void 0,r.backgroundGraphics),foregroundGraphics:to(io(r,o,"showProjection")?Of.createElement(Jr,{layout:n.layout,states:n.states}):void 0,r.foregroundGraphics),bodyStyle:eu(t||o.colorBy)}}},Cp={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[900,520],n=$r({data:Array.isArray(e)?e:[],phases:Array.isArray(o.phases)?o.phases:[],products:Array.isArray(o.products)?o.products:void 0,outlets:Array.isArray(o.outlets)?o.outlets:void 0,events:Array.isArray(o.events)?o.events:void 0,idAccessor:o.idAccessor,labelAccessor:o.labelAccessor,categoryAccessor:o.categoryAccessor,amountAccessor:o.amountAccessor,metricsAccessor:o.metricsAccessor,initialStateAccessor:o.initialStateAccessor,metrics:o.metrics,size:a,seed:o.seed,bodyRadius:"number"==typeof o.bodyRadius?o.bodyRadius:void 0,radiusRange:o.radiusRange}),l="snapshot"===o.playback?function(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,hr(t)??0));let i=e.phases.find(e=>e.id===t.phaseId);if(!i)return e.duration;let r=Math.max(0,Math.min(1,hr(t.progress??0)??0));return i.start+i.duration*r}(n,o.snapshotAt):n.duration,s=Lr(n,l).state,c=o.projection&&"object"==typeof o.projection?o.projection:{groupBy:"outlet",measure:"count"},u=function(e,t={}){let i=t.groupBy??"outlet",r=new Map,o=e=>{let t=function(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}({...e,status:e.status??"active"},i),o=r.get(t);if(o)return o.count+=1,o.amount+=e.amount,void Qi(o.metrics,e.metrics);r.set(t,{key:t,label:"product"===i&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:Gi(e.metrics),status:"status"===i?e.status:void 0,outletId:"outlet"===i?e.outletId:void 0,category:"category"===i?e.category:void 0,productId:"product"===i&&"product"===e.kind?e.id:void 0})};for(let t of Object.values(e.components))t.productIds.length||"consumed"===t.status||o({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(let t of Object.values(e.products))o({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});let a=new Map((t.order??[]).map((e,t)=>[e,t]));return[...r.values()].sort((e,t)=>(a.get(e.key)??Number.MAX_SAFE_INTEGER)-(a.get(t.key)??Number.MAX_SAFE_INTEGER)||qi(e.key,t.key))}(s,c),d=c.measure??"count",h=function(e,t={}){let i=t.bodies??[],r=Math.max(0,t.recentBodyLimit??6),o=new Map;for(let e of i){let i=t.getContainerId?.(e);if(!i)continue;let r=o.get(i);r?r.push(e):o.set(i,[e])}let a=e.map(e=>{let i=o.get(e.id)??[],a=Math.max(0,Math.floor(e.count??i.length)),n=i.slice(Math.max(0,i.length-r)).map(e=>({id:e.id,label:t.getBodyLabel?.(e)??jr(e),datum:e.datum}));return{id:e.id,label:e.label,count:a,share:0,secondary:e.secondary,secondaryLabel:e.secondaryLabel,observed:e.observed,bodyIds:i.map(e=>e.id),recentBodies:n,metadata:e.metadata}}),n=a.reduce((e,t)=>e+t.count,0);return a.map(e=>({...e,share:n>0?e.count/n:0}))}(u.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===d||"amount"===d?e.amount:Number(e.metrics[d]??0),secondaryLabel:"count"===d||"amount"===d?o.amountLabel??"amount":d,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),f={seed:o.seed,bodyRadius:"number"==typeof o.bodyRadius?o.bodyRadius:void 0,radiusRange:o.radiusRange},p=t??o.colorBy??"category",y=!1===o.showChrome?null:Of.createElement(Er,{layout:n.layout,phases:n.phases,state:s,compact:520>a[0]||360>a[1]}),g=!1===o.showProjection?null:Of.createElement(Wr,{rows:u,layout:n.layout,projection:c,amountLabel:o.amountLabel});return{...r,config:n.config,initialSpawns:eo(_r(s,n.layout,f)),projectionRows:h,bodyStyle:e=>function(e,t,i,r){let o=e.datum,a={stroke:r.stroke??("product"===o?.kind?"#fffaf0":"#26323a"),strokeWidth:r.strokeWidth??("product"===o?.kind?1.8:1.1),opacity:r.opacity??.96};if(!o?.__crucible)return{...a,fill:r.color??"#b8792d"};if("product"===o.kind){let e=t.products[o.semanticId];return{...a,fill:r.color??e?.color??ro(e?.id??o.semanticId)}}let n,l=t.components[o.semanticId];return l?(n="status"===i?l.status:"outlet"===i?l.outletId??"in chamber":"product"===i?l.productIds[0]??"unalloyed":"category"===i||null==i?l.category:"function"==typeof i?(i(l.datum)??"unassigned")+"":(l.datum[i+""]??"unassigned")+"",{...a,fill:r.color??ro(n)}):{...a,fill:r.color??"#356b63"}}(e,s,p,o),getBodyLabel:e=>function(e,t){let i=e.datum;if(i?.__crucible)return"product"===i.kind?t.products[i.semanticId]?.label:t.components[i.semanticId]?.label}(e,s),renderBodySVG:Fr,backgroundGraphics:to(y,r.backgroundGraphics),foregroundGraphics:to(g,r.foregroundGraphics)}}},Ip={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[760,420],n=function(e){function t(e){if(e&&"object"==typeof e){let t=e;if("function"==typeof n){let e=n(t,0);if(null!=e)return e+""}if("string"==typeof n&&null!=t[n])return t[n]+"";if(null!=t.id)return t.id+""}return(e??"unknown")+""}let{coordinateMode:i,flowSpeed:r,links:o,maxParticles:a,nodeIdAccessor:n,nodeXAccessor:l,nodeYAccessor:s,nodes:c,particleRadius:u,particleRate:d,pathAccessor:h,pathConstraint:f="path",reducedMotion:p,seed:y,size:g,sourceAccessor:m,targetAccessor:x,throughputAccessor:b}=e,v=Wc(g),w=Kc(y),k=new Map,A=new Map,S=[];c.forEach((e,t)=>{let i=(Yc(e,t,n)??e.id??t)+"",r=Oc(Yc(e,t,l)),o=Oc(Yc(e,t,s));if(null!=r&&null!=o){let e={x:r,y:o};k.set(i,e),S.push(e)}A.set(i,(e.label??e.name??i)+"")});let M=[];o.forEach((e,i)=>{let r=t(Yc(e,i,m)),o=t(Yc(e,i,x)),a=Math.max(0,Oc(Yc(e,i,b))??0),n=Ai(h?Yc(e,i,h):void 0),l=n.length?n:Ai(e.path??e.points??e.route);l.forEach(e=>S.push(e)),M.push({id:(e.id??`physical-flow-${r}-${o}-${i}`)+"",link:e,index:i,source:r,target:o,throughput:a,rawPath:l})});let _=($=S,"normalized"===(L=i)||"pixels"===L?L:$.length>0&&$.every(e=>!(0>e.x||e.x>1||0>e.y||e.y>1))?"normalized":"pixels"),P=new Map;var L,$;for(let[e,t]of k)P.set(e,Si(t,v,_));let T=[];for(let e of M){let t=e.rawPath.map(e=>Si(e,v,_));if(2>t.length){let i=P.get(e.source),r=P.get(e.target);i&&r&&(t=[i,r])}else P.has(e.source)||P.set(e.source,t[0]),P.has(e.target)||P.set(e.target,t[t.length-1]);2>t.length||0>=e.throughput||(A.has(e.source)||A.set(e.source,e.source),A.has(e.target)||A.set(e.target,e.target),T.push({...e,path:t,packetCount:0}))}let R=Bc(d,.12),C=Math.max(1,Math.round(a)),I=T.map(e=>Math.max(1,Math.round(e.throughput*R))),D=I.reduce((e,t)=>e+t,0),z=D>C?C/D:1;T.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(I[t]*z))});let O=T.reduce((e,t)=>e+t.packetCount,0);for(;O>C;){let e=T.reduce((e,t,i)=>t.packetCount>1&&(-1===e||t.packetCount>T[e].packetCount)?i:e,-1);if(-1===e)break;T[e].packetCount-=1,O-=1}let F=new Map,N=new Map,E=[],W=Bc(r,90),j=Bc(u,4);T.forEach((e,t)=>{F.set(e.target,(F.get(e.target)??0)+e.throughput),N.set(e.source,(N.get(e.source)??0)+e.throughput);let i=Mi(e.path);for(let r=0;e.packetCount>r;r+=1){let o=(r+.5)/e.packetCount,a=p?o:Cc(.12+.84*o+.04*(w()-.5),.04,.98),n=p?a:Math.max(0,a-(.18+.12*w())),l=_i(e.path,n),s=_i(e.path,a),c=Pi(e.path,n),u={x:-c.y,y:c.x},d=(w()-.5)*j*1.5;E.push({id:`${e.id}-packet-${r}`,x:l.x+u.x*d,y:l.y+u.y*d,vx:p?0:c.x*W+10*(w()-.5),vy:p?0:c.y*W+10*(w()-.5),mass:.8,spawnAt:p?0:.04*t+r/32,shape:{type:"circle",radius:j},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:r,packetCount:e.packetCount,routeProgress:a,flowPath:e.path,flowPathLength:i,flowRouteId:e.id,flowSpeed:W,sourceLabel:A.get(e.source)??e.source,targetLabel:A.get(e.target)??e.target},springs:"none"!==f&&p?[{target:{type:"point",x:s.x,y:s.y},restLength:.7*j,stiffness:26,damping:4.25}]:void 0})}});let B=Math.max(18,5*j),Y=Array.from(P,([e,t])=>({nodeId:e,label:A.get(e)??e,sensorId:"physical-flow-node-"+Zc(e),point:t})),X=Y.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:B,height:B}})),G=Object.fromEntries(Y.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),V=[...Su({x:v.plot.x,y:v.plot.y,width:v.plot.width,height:v.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...X],H=Rc(y,V,"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*j),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});H.bodyLimit=C,H.eviction="oldest",H.observation={...H.observation,sensors:G};let q=Array.from(P,([e,t])=>({id:e,label:A.get(e)??e,x:t.x,y:t.y,sensorId:"physical-flow-node-"+Zc(e),incoming:F.get(e)??0,outgoing:N.get(e)??0})),U=T.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:A.get(e.source)??e.source,targetLabel:A.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:H,initialSpawns:E,projectionRows:q.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:_,particleCount:E.length,totalThroughput:T.reduce((e,t)=>e+t.throughput,0),plot:v.plot,nodes:q,links:U}}}({nodes:Array.isArray(o.nodes)?o.nodes:[],links:Array.isArray(o.links)?o.links:Array.isArray(o.edges)?o.edges:Array.isArray(e)?e:[],nodeIdAccessor:o.nodeIdAccessor||"id",nodeXAccessor:o.nodeXAccessor||"x",nodeYAccessor:o.nodeYAccessor||"y",sourceAccessor:o.sourceAccessor||"source",targetAccessor:o.targetAccessor||"target",throughputAccessor:o.throughputAccessor||"value",pathAccessor:o.pathAccessor||"path",coordinateMode:o.coordinateMode||"auto",particleRate:o.particleRate??.16,maxParticles:o.maxParticles??180,particleRadius:o.particleRadius??4,flowSpeed:o.flowSpeed??90,pathConstraint:o.pathConstraint||"path",reducedMotion:!0,seed:o.seed??1,size:a});return{...r,config:n.config,initialSpawns:eo(n.initialSpawns),projectionRows:n.projectionRows,foregroundGraphics:to(Zr(n.metadata,{showNodeLabels:!1!==o.showNodeLabels,showSensors:!1!==o.showSensors,showStaticFlow:!1!==o.showStaticFlow}),r.foregroundGraphics),bodyStyle:eu(t||o.colorBy||"source")}}},Dp={frameType:"physics",layout:Sp,buildProps:(e,t,i,r,o)=>{let a=r.size??[700,380],n=le(r.theme),l=function(e){let t=function(e,t,i){let r=e?.observation;return{...e,observation:{...r,chartId:t??r?.chartId??"physics-custom",chartType:r?.chartType??"PhysicsCustomChart",onObservation:i??r?.onObservation}}}(e.config,e.chartId,e.onObservation),i=$i(e.colorScheme,e.themeCategorical,vd),r=Wc(e.size),o={data:e.data,scales:{x:Wf().domain(e.xExtent??[0,1]).range([r.plot.x,r.plot.x+r.plot.width]),y:Wf().domain(e.yExtent??[0,1]).range([r.plot.y+r.plot.height,r.plot.y])},dimensions:r,theme:{semantic:e.semantic,categorical:[...i]},resolveColor:Ti(i,e.colorScheme),config:e.layoutConfig??{},world:new yu(t)},a=e.skipLayout?{}:e.layout(o)??{},n=function(e,t){if(!t?.length)return e;let i=new Map;for(let e of t){let{bodyId:t,...r}=e,o=i.get(t)??[];o.push(r),i.set(t,o)}return e.map(e=>{let t=i.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}([...a.initialSpawns??a.bodies??[]],a.constraints);return{config:Ri(t,a),context:o,initialSpawnPacing:a.initialSpawnPacing,initialSpawns:n,result:a}}({chartId:o.chartId,colorScheme:i,config:o.config,data:Array.isArray(e)?e:[],layout:o.layout,layoutConfig:o.layoutConfig,semantic:lu(n)??{},size:a,themeCategorical:n.colors.categorical,xExtent:o.xExtent,yExtent:o.yExtent});return{...r,config:l.config,initialSpawns:eo(l.initialSpawns),projectionRows:[],bodyStyle:l.result.bodyStyle??eu(t||o.colorBy),backgroundGraphics:to(r.backgroundGraphics,l.result.backgroundOverlays),foregroundGraphics:to(r.foregroundGraphics,l.result.overlays)}}};import*as zp from"react-dom/server";import*as Op from"react";import*as Fp from"react-dom/server";var Np=class{constructor(e){if(this._capacity=e,this.head=0,this._size=0,1>e)throw Error("RingBuffer capacity must be at least 1");this.buffer=Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){let t=[];for(let i of e){let e=this.push(i);void 0!==e&&t.push(e)}return t}get(e){if(e>=0&&this._size>e)return this.buffer[(this.head-this._size+e+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 e=0;return{next:()=>this._size>e?{done:!1,value:this.get(e++)}:{done:!0,value:void 0}}}forEach(e){let t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++)e(this.buffer[(t+i)%this._capacity],i)}toArray(){let e=Array(this._size),t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;this._size>i;i++)e[i]=this.buffer[(t+i)%this._capacity];return e}resize(e){if(1>e)throw Error("RingBuffer capacity must be at least 1");let t=this.toArray(),i=0,r=[];t.length>e&&(i=t.length-e,r=t.slice(0,i)),this._capacity=e,this.buffer=Array(e),this.head=0,this._size=0;for(let e=i;t.length>e;e++)this.push(t[e]);return r}update(e,t){let i=[],r=(this.head-this._size+this._capacity)%this._capacity;for(let o=0;this._size>o;o++){let a=(r+o)%this._capacity,n=this.buffer[a];if(e(n)){let e;e="object"!=typeof n||null===n?n:Array.isArray(n)?[...n]:{...n},i.push(e),this.buffer[a]=t(n)}}return i}remove(e){let t=[],i=[];if(this.forEach(r=>{e(r)?i.push(r):t.push(r)}),0===i.length)return i;this.buffer=Array(this._capacity),this.head=0,this._size=0;for(let e of t)this.push(e);return i}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}},Ep=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isFinite(e)&&(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}evict(e){(e===this._min||e===this._max)&&(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(let i of e){let e=t?t(i):i;Number.isFinite(e)&&(this._min>e&&(this._min=e),e>this._max&&(this._max=e))}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}},Wp=/^\d{4}-\d{1,2}$/,jp=Object.create(null),Bp=typeof window>"u"||typeof document>"u",Yp=new Set;import{scaleLinear as Xp,scaleLog as Gp,scaleSymlog as Vp,scaleTime as Hp}from"d3-scale";var qp=new WeakMap,Up=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Zp=["scene-style","data-paint","accessibility","evidence"],Kp=(e,t)=>({retainedData:e,invalidations:t}),Qp=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Jp=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ey=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ty=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],iy=["scene-geometry","data-paint","accessibility","evidence"],ry=["scene-style","data-paint","accessibility","evidence"],oy=[],ay={chartType:Kp("rebuild",Qp),runtimeMode:Kp("rebuild",Qp),xAccessor:Kp("rebuild",Qp),yAccessor:Kp("rebuild",Qp),timeAccessor:Kp("rebuild",Qp),valueAccessor:Kp("rebuild",Qp),y0Accessor:Kp("rebuild",Qp),boundsAccessor:Kp("rebuild",Qp),band:Kp("rebuild",Qp),openAccessor:Kp("rebuild",Qp),highAccessor:Kp("rebuild",Qp),lowAccessor:Kp("rebuild",Qp),closeAccessor:Kp("rebuild",Qp),candlestickRangeMode:Kp("rebuild",Qp),accessorRevision:Kp("rebuild",Qp),groupAccessor:Kp("rebuild",Jp),categoryAccessor:Kp("rebuild",Jp),lineDataAccessor:Kp("rebuild",Jp),colorAccessor:Kp("rebuild",ry),sizeAccessor:Kp("rebuild",iy),symbolAccessor:Kp("rebuild",iy),pointIdAccessor:Kp("rebuild",iy),xScaleType:Kp("preserve",ey),yScaleType:Kp("preserve",ey),xExtent:Kp("preserve",ey),invertY:Kp("preserve",ey),yExtent:Kp("preserve",ey),extentPadding:Kp("preserve",ey),scalePadding:Kp("preserve",ey),axisExtent:Kp("preserve",ey),yAxisExtent:Kp("preserve",ey),binSize:Kp("preserve",ey),normalize:Kp("preserve",ey),heatmapAggregation:Kp("preserve",ey),heatmapXBins:Kp("preserve",ey),heatmapYBins:Kp("preserve",ey),arrowOfTime:Kp("preserve",ty),baseline:Kp("preserve",ty),stackOrder:Kp("preserve",ty),sizeRange:Kp("preserve",ty),curve:Kp("preserve",ty),areaGroups:Kp("preserve",ty),customLayout:Kp("preserve",ty),layoutConfig:Kp("preserve",ty),layoutMargin:Kp("preserve",ty),symbolMap:Kp("preserve",iy),showValues:Kp("preserve",iy),heatmapValueFormat:Kp("preserve",iy),trackHoverRows:Kp("preserve",iy),lineStyle:Kp("preserve",ry),pointStyle:Kp("preserve",ry),areaStyle:Kp("preserve",ry),barStyle:Kp("preserve",ry),swarmStyle:Kp("preserve",ry),waterfallStyle:Kp("preserve",ry),candlestickStyle:Kp("preserve",ry),boundsStyle:Kp("preserve",ry),gradientFill:Kp("preserve",ry),lineGradient:Kp("preserve",ry),semanticLineStops:Kp("preserve",ry),colorScheme:Kp("preserve",ry),themeCategorical:Kp("preserve",ry),themeSemantic:Kp("preserve",ry),themeSequential:Kp("preserve",ry),themeDiverging:Kp("preserve",ry),barColors:Kp("preserve",ry),decay:Kp("preserve",ry),pulse:Kp("preserve",ry),staleness:Kp("preserve",ry),layoutSelection:Kp("preserve",ry),annotations:Kp("preserve",["overlay","accessibility","evidence"]),windowSize:Kp("preserve",oy),windowMode:Kp("preserve",oy),maxCapacity:Kp("preserve",oy),clock:Kp("preserve",oy),transition:Kp("preserve",oy),introAnimation:Kp("preserve",oy),onLayoutError:Kp("preserve",oy)},ny=Kp("preserve",ty),ly=class{constructor(){this.tracker=new gu}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},Up)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},Zp):this.recordNoop("restyle")}recordConfig(e,t=!1){let i=function(e){let t="preserve",i=new Set;for(let r of e){let e=ay[r]??ny;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e);return this.tracker.record({kind:"config",keys:e},t?new Set([...i.invalidations,...iy]):i.invalidations)}};import{quadtree as sy}from"d3-quadtree";var cy=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(e,t){if("scatter"!==e&&"bubble"!==e&&"custom"!==e)return void this.clear();let i=0,r=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(i++,e.r>r&&(r=e.r));if(this.maxRadius=r,500>=i)return void(this.tree=null);let o=Array(i),a=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(o[a++]=e);this.tree=sy().x(e=>e.x).y(e=>e.y).addAll(o)}},uy=class e{constructor(e){if(this.xExtent=new Ep,this.yExtent=new Ep,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 ly,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 cy,this._lastBoundedInsertsRef=null,this.applyPulse=(e,t,i)=>!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,i,r,o,a=("u">typeof performance?performance.now():Date.now())){let n=e.color??"rgba(255,255,255,0.6)",l=e.glowRadius??4,s=!1,c=o??(()=>{let e=new Map;for(let t=0;i.length>t;t++)e.set(i[t],t);return e})();for(let i of t){if("line"===i.type)continue;if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[i.datum],o=0,l=!1;for(let i of t){let t=c.get(i);if(null==t)continue;l=!0;let n=r.get(t);if(null==n)continue;let s=po(e,n,a);s>o&&(o=s)}l&&(s=yo(i,o,n)||s);continue}let t=c.get(i.datum);if(null==t)continue;let o=r.get(t);s=yo(i,null==o?0:po(e,o,a),n,l)||s}return s}(this.config.pulse,e,t,this.timestampBuffer,this.getDatumIndexMap(t),i),this.config=e,this.buffer=new Np(e.windowSize),this.growingCap=e.windowSize,["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode?(this.getX=Xc(e.timeAccessor||e.xAccessor,"time"),this.getY=Xc(e.valueAccessor||e.yAccessor,"value")):(this.getX=Xc(e.xAccessor,"x"),this.getY=Xc(e.yAccessor,"y")),this.getGroup=Uc(e.groupAccessor),this.getCategory=Uc(e.categoryAccessor),this.getSize=e.sizeAccessor?Xc(e.sizeAccessor,"size"):void 0,this.getColor=Uc(e.colorAccessor),this.getSymbol=Uc(e.symbolAccessor),this.getY0=e.y0Accessor?Xc(e.y0Accessor,"y0"):void 0,this.resolvedRibbons=Mo(e),this.getPointId=Uc(e.pointIdAccessor),"candlestick"===e.chartType){let t=null!=e.openAccessor,i=null!=e.closeAccessor;this.getOpen=t?Xc(e.openAccessor,"open"):void 0,this.getHigh=Xc(e.highAccessor,"high"),this.getLow=Xc(e.lowAccessor,"low"),this.getClose=i?Xc(e.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!i}e.pulse&&(this.timestampBuffer=new Np(e.windowSize))}currentTime(){return this.config.clock?.()??uo()}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Eo(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(e)),void this.yExtent.push(this.getLow(e));this.yExtent.push(this.getY(e)),this.getY0&&this.yExtent.push(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.push(i),Number.isFinite(r)&&this.yExtent.push(r)}}evictDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(e)),void this.yExtent.evict(this.getLow(e));this.yExtent.evict(this.getY(e)),this.getY0&&this.yExtent.evict(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.evict(i),Number.isFinite(r)&&this.yExtent.evict(r)}}rebuildYExtent(){this.yExtent.clear();for(let e of this.buffer)this.pushDatumYExtent(e)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(let e of this.buffer)this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e)}ingest(e){if(e.bounded&&this._lastBoundedInsertsRef===e.inserts)return this.updateResults.recordNoop("replace"),!1;let t=this.currentTime();if(this.lastIngestTime=t,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,e.bounded){this._lastBoundedInsertsRef=e.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear();let i=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode;if(this.getX=i?Xc(this.config.timeAccessor||this.config.xAccessor,"time"):Xc(this.config.xAccessor,"x"),this.xIsDate=!1,e.inserts.length>0){let t=e.inserts[0],i=this.config.xAccessor,r="function"==typeof i?i(t):t[i||"x"],o=r instanceof Date,a="string"==typeof r&&Number.isFinite(oo(r));if(this.xIsDate=o||a,a){let e="string"==typeof i?i:void 0;this.getX=e?t=>ao(t[e]):e=>ao(i(e))}}No(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(let i of e.inserts)Wo(this.buffer,i,this.timestampBuffer,t),this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i)}else for(let i of e.inserts){if("growing"===this.config.windowMode&&this.buffer.full){let e=this.config.maxCapacity??1e5;e>this.growingCap&&(this.growingCap=Math.min(2*this.growingCap,e),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"!==process.env.NODE_ENV&&!this.growingCapacityWarned&&this.growingCap>=5e4&&(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${e}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}let e=Wo(this.buffer,i,this.timestampBuffer,t);this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i),null!=e&&(this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e))}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,o=this.lastLayout;if(!this.needsFullRebuild&&!t.customLayout&&this.lastLayout&&this.scene.length>0&&this.scales&&0>=(this.config.scalePadding??0)&&(this.lastLayout.width!==e.width||this.lastLayout.height!==e.height))return void this.remapScene(e);this.xExtent.dirty&&this.xExtent.recalculate(i,this.getX),this.yExtent.dirty&&this.rebuildYExtent();let a=this.getBufferArray(),n=this.xExtent.extent,l=this.yExtent.extent,s="waterfall"===t.chartType&&i.size>0?function(e,t,i,r,o){let a=Array.from(new Set(e.map(t).filter(e=>Number.isFinite(e)))).sort((e,t)=>e-t);if(2>a.length)return zo(i,r);let n=a[0],l=a[1],s=a[a.length-1],c=a[a.length-2];return zo("log"===o&&n>0?[n/Math.sqrt(l/n),s*Math.sqrt(s/c)]:[n-(l-n)/2,s+(s-c)/2],r)}(a,this.getX,n,t.xExtent,t.xScaleType):zo(n,t.xExtent),c=zo(l,t.yExtent),u=!(!(h=t.yExtent)||null==h[0]||null==h[1]),d="exact"===(t.yAxisExtent??t.axisExtent);var h;if("stackedarea"===t.chartType&&!u&&i.size>0){let e=function(e){let{config:t,groups:i,getX:r,getY:o}=e,a="exact"===(t.yAxisExtent??t.axisExtent);if(t.normalize){let i=[0,a?1:1+t.extentPadding];return{yDomain:i,stackExtentCache:{key:`${e.bufferSize}:${e.ingestVersion}:norm`,yDomain:i}}}let n=`${e.bufferSize}:${e.ingestVersion}:${t.baseline??"zero"}:${t.stackOrder??"key"}`;if(e.stackExtentCache&&e.stackExtentCache.key===n)return{yDomain:e.stackExtentCache.yDomain,stackExtentCache:e.stackExtentCache};let l=new Map,s=new Set,c=0,u=new Map,d=new Map;for(let e of i){let t=new Map,i=0;for(let a of e.data){let e=r(a),n=o(a);if(!Number.isFinite(e)||!Number.isFinite(n))continue;t.set(e,(t.get(e)||0)+n),s.add(e),i+=n;let l=(u.get(e)||0)+n;u.set(e,l),l>c&&(c=l)}l.set(e.key,t),d.set(e.key,i)}let h,f,p=t.stackOrder??"key",y=(e,t)=>t>e?-1:e>t?1:0;if("input"===p)h=i.map(e=>e.key);else if("insideOut"===p){let e=[...i].map(e=>e.key).sort((e,t)=>{let i=(d.get(t)??0)-(d.get(e)??0);return 0!==i?i:y(e,t)}),t=[],r=[],o=0,a=0;for(let i of e)a>o?(t.push(i),o+=d.get(i)??0):(r.push(i),a+=d.get(i)??0);h=[...r.reverse(),...t]}else h="asc"===p?i.map(e=>e.key).sort((e,t)=>{let i=(d.get(e)??0)-(d.get(t)??0);return 0!==i?i:y(e,t)}):"desc"===p?i.map(e=>e.key).sort((e,t)=>{let i=(d.get(t)??0)-(d.get(e)??0);return 0!==i?i:y(e,t)}):i.map(e=>e.key).sort(y);if("wiggle"===t.baseline||"silhouette"===t.baseline){let e=Array.from(s).sort((e,t)=>e-t),i=To(e,h,(e,t)=>l.get(e)?.get(t)||0,t.baseline),r=1/0,o=-1/0;for(let t of e){let e=i.get(t)??0,a=u.get(t)??0;r>e&&(r=e),e+a>o&&(o=e+a)}(!Number.isFinite(r)||!Number.isFinite(o))&&(r=0,o=0);let n=o-r,c=a?0:n>0?n*t.extentPadding:1;f=[r-c,o+c]}else if("diverging"===t.baseline){let e=Array.from(s).sort((e,t)=>e-t),[i,r]=function(e,t,i){let r=0,o=0;for(let a of e){let e=0,n=0;for(let r of t){let t=i(r,a)||0;0>t?n+=t:e+=t}r>n&&(r=n),e>o&&(o=e)}return[r,o]}(e,h,(e,t)=>l.get(e)?.get(t)||0),o=r-i,n=a?0:o>0?o*t.extentPadding:1;f=[i-n,r+n]}else f=[0,c+(a?0:c>0?c*t.extentPadding:1)];return{yDomain:f,stackExtentCache:{key:n,yDomain:f}}}({config:t,groups:this.groupData(a),getX:this.getX,getY:this.getY,bufferSize:i.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=e.yDomain,this._stackExtentCache=e.stackExtentCache}else"bar"===t.chartType&&t.binSize&&!u&&i.size>0?c=function(e,t,i,r,o,a,n){let[,l]=function(e,t,i,r,o){let a=_o(e,t,i,r,o);if(0===a.size)return[0,0];let n=0;for(let e of a.values())e.total>n&&(n=e.total);return[0,n]}(e,t,i,r,o);return[0,n?l:l+l*a]}(i,this.getX,this.getY,t.binSize,this.getCategory,t.extentPadding,d):"waterfall"===t.chartType&&!u&&i.size>0?c=function(e,t,i,r){let[o,a]=function(e,t){let i=0,r=0,o=0;for(let a of e){let e=t(a);null==e||Number.isNaN(e)||(o+=e,i>o&&(i=o),o>r&&(r=o))}return[i,r]}(e,t),n=a-o,l=r?0:n>0?n*i:1;return[Math.min(0,o-Math.abs(l)),Math.max(0,a+Math.abs(l))]}(i,this.getY,t.extentPadding,d):!u&&c[0]!==1/0&&(c=function(e,t,i){if(!i.length)return e;let[r,o]=e;for(let e of t)for(let t of i){let i=t.getTop(e),a=t.getBottom(e);Number.isFinite(i)&&(r>i&&(r=i),i>o&&(o=i)),Number.isFinite(a)&&(r>a&&(r=a),a>o&&(o=a))}return[r,o]}(c,a,this.resolvedRibbons),c=function(e,t){let i=e[1]-e[0],r=t.exactMode?0:i>0?i*t.extentPadding:1,o=[null!=t.userMin?e[0]:e[0]-r,null!=t.userMax?e[1]:e[1]+r];return"log"!==t.yScaleType||o[0]>0||0>=t.dataYDomain[0]||t.exactMode||null==t.userMin&&(o[0]=t.dataYDomain[0]/(1+t.extentPadding)),o}(c,{exactMode:d,extentPadding:t.extentPadding,userMin:t.yExtent?.[0],userMax:t.yExtent?.[1],yScaleType:t.yScaleType,dataYDomain:l}));c=function(e,t,i){if(!t||i)return e;let r=t[0],o=t[1];return null==r&&null==o?e:[r??e[0],o??e[1]]}(c,t.yExtent,!!u),({xDomain:s,yDomain:c}=function(e,t,i){let r=e,o=t;if(r[0]===1/0||r[1]===-1/0)if("time"===i){let e=Date.now();r=[e-864e5,e]}else r=[0,1];return(o[0]===1/0||o[1]===-1/0)&&(o=[0,1]),{xDomain:r,yDomain:o}}(s,c,t.xScaleType)),this.scales=function(e){let{config:t,layout:i,xDomain:r}=e,o=t.invertY?[e.yDomain[1],e.yDomain[0]]:e.yDomain,a="streaming"===t.runtimeMode,n=Math.max(0,Math.min(t.scalePadding||0,Math.min(i.width,i.height)/2-1));if(a){let e="left"===t.arrowOfTime?[i.width-n,n]:[n,i.width-n];return{x:Xp().domain(r).range(e),y:Oo(t.yScaleType,o,[i.height-n,n])}}return{x:Oo(t.xScaleType,r,[n,i.width-n]),y:Oo(t.yScaleType,o,[i.height-n,n])}}({config:t,layout:e,xDomain:s,yDomain:c}),this._customLayoutFailedThisBuild=!1;let f=this.buildSceneNodes(e,a);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.lastLayout=o):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=f,this.config.decay&&this.applyDecay(this.scene,a),this.config.pulse&&this.applyPulse(this.scene,a,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:e.width,height:e.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}remapScene(e){let t=e.width/this.lastLayout.width,i=e.height/this.lastLayout.height;for(let e of this.scene)switch(e.type){case"line":for(let r of e.path)r[0]*=t,r[1]*=i;break;case"area":for(let r of e.topPath)r[0]*=t,r[1]*=i;for(let r of e.bottomPath)r[0]*=t,r[1]*=i;e.clipRect&&(e.clipRect={x:e.clipRect.x*t,y:e.clipRect.y*i,width:e.clipRect.width*t,height:e.clipRect.height*i}),e.strokeColorBands&&(e.strokeColorBands=e.strokeColorBands.map(e=>({...e,y:e.y*i,height:e.height*i})));break;case"point":case"glyph":e.x*=t,e.y*=i;break;case"rect":case"heatcell":e.x*=t,e.y*=i,e.w*=t,e.h*=i;break;case"candlestick":e.x*=t,e.openY*=i,e.closeY*=i,e.highY*=i,e.lowY*=i}let r=this.scales.x.domain(),o=this.scales.y.domain(),a=this.scales.x.range(),n=this.scales.y.range(),l=Oo,s=Math.max(0,Math.min(this.config.scalePadding||0,Math.min(e.width,e.height)/2-1)),c=n[1]>n[0];this.scales={x:l(this.config.xScaleType,r,a[0]>a[1]?[e.width-s,s]:[s,e.width-s]),y:l(this.config.yScaleType,o,c?[s,e.height-s]:[e.height-s,s])},this.lastLayout={width:e.width,height:e.height},this.spatialIndex.rebuild(this.config.chartType,this.scene),this.version++}buildSceneNodes(e,t){let{config:i,scales:r}=this;if(!r)return[];if(i.customLayout){let o={data:t,scales:r,dimensions:{width:e.width,height:e.height,margin:i.layoutMargin??{top:0,right:0,bottom:0,left:0},plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:i.themeSemantic??{},categorical:i.themeCategorical??Xd},resolveColor:(e,t)=>{let r=this.resolveGroupColor(e);if(r)return r;let o=this.resolveLineStyle(e,t);return o.stroke?o.stroke:"string"==typeof o.fill?o.fill:i.themeSemantic?.primary??"#4e79a7"},config:i.layoutConfig??{},selection:i.layoutSelection??null},a=Ao({family:"xy",logLabel:"customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:i.onLayoutError,run:()=>i.customLayout(o)});if("failure"===a.kind)return this.lastCustomLayoutFailure=a.diagnostic,this._customLayoutFailedThisBuild=!0,a.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let n=a.result;this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;let l=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(let e of l)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(l,i.layoutSelection??null)}return vo({label:"customLayout",nodes:l,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),l}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===t.length)return[];let o={scales:r,config:i,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:(e,t)=>this.resolveLineStyle(e,t),resolveAreaStyle:(e,t)=>this.resolveAreaStyle(e,t),resolveBoundsStyle:(e,t)=>this.resolveBoundsStyle(e,t),resolveColorMap:e=>this.resolveColorMap(e),resolveGroupColor:e=>this.resolveGroupColor(e),groupData:e=>this.groupData(e),barCategoryCache:this._barCategoryCache},a=(n=i.chartType,jp[n]?.buildScene);var n;if(!a)return function(e){(function(e){return jp[e]})(e)||Bp&&(Yp.has(e)||(Yp.add(e),console.warn(`[semiotic] StreamXYFrame: no XY plugin registered for "${e}" during SSR. Import a chart HOC, or call registerBuiltInXYPlugins() from "semiotic/xy" or "semiotic/realtime/core" before render.`)))}(i.chartType),[];let l=(s=a(o,t,e),Array.isArray(s)?{nodes:s,binBoundaries:[]}:{nodes:s.nodes,binBoundaries:s.binBoundaries});var s;return"bar"===i.chartType&&(this._barCategoryCache=o.barCategoryCache??null,this._binBoundaries=l.binBoundaries),l.nodes}resolveBoundsStyle(e,t){return function(e,t,i,r){let o=e.boundsStyle;if("function"==typeof o)return o(i||{},t);if(o&&"object"==typeof o)return o;let a=r(t,i);return{fill:a.stroke||e.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,...null!=a.opacity&&{opacity:a.opacity},stroke:"none",cursor:a.cursor}}(this.config,e,t,(e,t)=>this.resolveLineStyle(e,t))}computeDecayOpacity(e,t){let i=this.config.decay;return i&&t>1?ho(i,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;let t=fo(e);return this._datumIndexCache={version:this._ingestVersion,map:t},t}applyDecay(e,t){this.config.decay&&function(e,t,i,r=fo(i)){let o=i.length;if(o>1)for(let i of t){if("line"===i.type){let t=Array.isArray(i.datum)?i.datum:[];if(2>t.length)continue;let a=Array(t.length),n=!1;for(let i=0;t.length>i;i++){let l=r.get(t[i]);null!=l?(a[i]=ho(e,l,o),1>a[i]&&(n=!0)):a[i]=1}n&&(i._decayOpacities=a);continue}if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[],a=i.topPath?i.topPath.length:t.length;if(2>a)continue;if(t.length===a){let n=Array(a),l=!1;for(let i=0;t.length>i;i++){let a=r.get(t[i]);null!=a?(n[i]=ho(e,a,o),1>n[i]&&(l=!0)):n[i]=1}l&&(i._decayOpacities=n)}else{let n=1;for(let i of t){let t=r.get(i);if(null!=t){let i=ho(e,t,o);n>i&&(n=i)}}if(1>n){let e=Array(a);e.fill(n),i._decayOpacities=e}}continue}let t=r.get(i.datum);if(null==t)continue;let a=ho(e,t,o);"candlestick"===i.type?i._decayOpacity=a:i.style={...i.style,opacity:(i.style?.opacity??1)*a}}}(this.config.decay,e,t,this.getDatumIndexMap(t))}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&go(this.config.pulse,this.timestampBuffer,e)}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(e,t,i,r){i.clear(),r.clear();for(let o=0;t.length>o;o++){let a=t[o],n=mo(e,a,o);n&&("point"===a.type?i.set(n,{x:a.x,y:a.y,r:a.r,opacity:xo(a.style)}):"glyph"===a.type?i.set(n,{x:a.x,y:a.y,r:a.size,opacity:xo(a.style),glyph:a.glyph}):"rect"===a.type||"heatcell"===a.type?i.set(n,{x:a.x,y:a.y,w:a.w,h:a.h,opacity:xo(a.style)}):"candlestick"===a.type?i.set(n,{x:a.x,y:a.openY,w:a.bodyWidth,openY:a.openY,closeY:a.closeY,highY:a.highY,lowY:a.lowY,opacity:xo(a.style)}):"line"===a.type?r.set(n,{path:a.path.map(e=>[e[0],e[1]]),opacity:a.style?.opacity}):"area"===a.type&&r.set(n,{topPath:a.topPath.map(e=>[e[0],e[1]]),bottomPath:a.bottomPath.map(e=>[e[0],e[1]]),opacity:a.style?.opacity}))}}(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();let e=this.scales?.y(0)??0;for(let t=0;this.scene.length>t;t++){let i=this.scene[t],r=mo(this.transitionContext,i,t);r&&("point"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,r:0,opacity:0}):"rect"===i.type?this.prevPositionMap.set(r,{x:i.x,y:e,w:i.w,h:0,opacity:i.style.opacity??1}):"heatcell"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,w:i.w,h:i.h,opacity:0}):"line"===i.type?(i._introClipFraction=0,this.prevPathMap.set(r,{path:i.path.map(e=>[e[0],e[1]]),opacity:i.style.opacity})):"area"===i.type&&(i._introClipFraction=0,this.prevPathMap.set(r,{topPath:i.topPath.map(e=>[e[0],e[1]]),bottomPath:i.bottomPath.map(e=>[e[0],e[1]]),opacity:i.style.opacity})))}}startTransition(){if(!this.config.transition)return;let e=function(e,t,i,r,o,a=uo()){if(0===r.size&&0===o.size)return i;let n=t.duration??300;if(i.exitNodes.length>0){let e=new Set(i.exitNodes);i.scene=i.scene.filter(t=>!e.has(t)),i.exitNodes=[]}let l=!1,s=new Set,c=new Set;for(let t=0;i.scene.length>t;t++){let a=i.scene[t],n=mo(e,a,t);if(!n)continue;if(a._transitionKey=n,"line"===a.type||"area"===a.type){let e=o.get(n);if(e){if(c.add(n),"line"===a.type&&e.path&&e.path.length===a.path.length){a._targetPath=a.path.map(e=>[e[0],e[1]]),a._prevPath=e.path;for(let t=0;a.path.length>t;t++)a.path[t]=[e.path[t][0],e.path[t][1]];l=!0}else if("area"===a.type&&e.topPath&&e.bottomPath&&e.topPath.length===a.topPath.length&&e.bottomPath.length===a.bottomPath.length){a._targetTopPath=a.topPath.map(e=>[e[0],e[1]]),a._targetBottomPath=a.bottomPath.map(e=>[e[0],e[1]]),a._prevTopPath=e.topPath,a._prevBottomPath=e.bottomPath;for(let t=0;a.topPath.length>t;t++)a.topPath[t]=[e.topPath[t][0],e.topPath[t][1]];for(let t=0;a.bottomPath.length>t;t++)a.bottomPath[t]=[e.bottomPath[t][0],e.bottomPath[t][1]];l=!0}a._targetOpacity=a.style.opacity??1,a._startOpacity=e.opacity??a.style.opacity??1}else a._targetOpacity=a.style.opacity??1,a._startOpacity=0,a.style={...a.style,opacity:0},l=!0;continue}let u=r.get(n);if("point"===a.type)if(u){s.add(n);let e={x:a.x,y:a.y,r:a.r};a._targetOpacity=xo(a.style),(u.x!==e.x||u.y!==e.y||u.r!==e.r)&&(a._targetX=e.x,a._targetY=e.y,a._targetR=e.r,a.x=u.x,a.y=u.y,a.r=u.r??a.r,l=!0)}else a._targetOpacity=xo(a.style),a.style={...a.style,opacity:0},l=!0;else if("glyph"===a.type)if(u){s.add(n);let e={x:a.x,y:a.y,size:a.size};a._targetOpacity=xo(a.style),(u.x!==e.x||u.y!==e.y||u.r!==e.size)&&(a._targetX=e.x,a._targetY=e.y,a._targetR=e.size,a.x=u.x,a.y=u.y,a.size=u.r??a.size,l=!0)}else a._targetOpacity=xo(a.style),a.style={...a.style,opacity:0},l=!0;else if("rect"===a.type)if(u){s.add(n);let e={x:a.x,y:a.y,w:a.w,h:a.h};a._targetOpacity=xo(a.style),(u.x!==e.x||u.y!==e.y||u.w!==e.w||u.h!==e.h)&&(a._targetX=e.x,a._targetY=e.y,a._targetW=e.w,a._targetH=e.h,a.x=u.x,a.y=u.y,a.w=u.w??a.w,a.h=u.h??a.h,l=!0)}else a._targetOpacity=xo(a.style),a.style={...a.style,opacity:0},l=!0;else if("heatcell"===a.type)if(u){s.add(n);let e={x:a.x,y:a.y,w:a.w,h:a.h};a._targetOpacity=xo(a.style),(u.x!==e.x||u.y!==e.y||u.w!==e.w||u.h!==e.h)&&(a._targetX=e.x,a._targetY=e.y,a._targetW=e.w,a._targetH=e.h,a.x=u.x,a.y=u.y,a.w=u.w??a.w,a.h=u.h??a.h,l=!0)}else a._targetOpacity=xo(a.style),a.style={...a.style||{},opacity:0},l=!0;else if("candlestick"===a.type)if(u&&null!=u.openY){s.add(n);let e={x:a.x,openY:a.openY,closeY:a.closeY,highY:a.highY,lowY:a.lowY};a._targetOpacity=xo(a.style),(u.x!==e.x||u.openY!==e.openY||u.closeY!==e.closeY||u.highY!==e.highY||u.lowY!==e.lowY)&&(a._targetX=e.x,a._targetOpenY=e.openY,a._targetCloseY=e.closeY,a._targetHighY=e.highY,a._targetLowY=e.lowY,a.x=u.x,a.openY=u.openY,a.closeY=u.closeY??a.closeY,a.highY=u.highY??a.highY,a.lowY=u.lowY??a.lowY,l=!0)}else a._targetOpacity=xo(a.style),a.style={...a.style||{},opacity:0},l=!0}for(let[e,t]of o)if(!c.has(e))if(e.startsWith("l:")&&t.path){let r={type:"line",path:t.path.map(e=>[e[0],e[1]]),group:e.slice(2),style:{stroke:"#999",strokeWidth:1,opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e,datum:null};i.exitNodes.push(r),l=!0}else if(e.startsWith("a:")&&t.topPath&&t.bottomPath){let r={type:"area",topPath:t.topPath.map(e=>[e[0],e[1]]),bottomPath:t.bottomPath.map(e=>[e[0],e[1]]),group:e.slice(2),style:{fill:"#999",opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e,datum:null};i.exitNodes.push(r),l=!0}for(let[e,t]of r)if(!s.has(e)){if(e.startsWith("p:"))i.exitNodes.push({type:"point",x:t.x,y:t.y,r:t.r??3,style:{opacity:t.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("g:")&&t.glyph)i.exitNodes.push({type:"glyph",x:t.x,y:t.y,size:t.r??12,glyph:t.glyph,color:"#999",accent:"#999",style:{opacity:t.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))i.exitNodes.push({type:"rect",x:t.x,y:t.y,w:t.w??0,h:t.h??0,style:{opacity:t.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("h:"))i.exitNodes.push({type:"heatcell",x:t.x,y:t.y,w:t.w??0,h:t.h??0,fill:"#999",datum:null,style:{opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e});else if(e.startsWith("c:")){let r=t.openY??t.y;i.exitNodes.push({type:"candlestick",x:t.x,openY:r,closeY:t.closeY??r,highY:t.highY??r,lowY:t.lowY??r,bodyWidth:t.w??6,upColor:"#999",downColor:"#999",wickColor:"#999",wickWidth:1,isUp:!0,datum:null,style:{opacity:t.opacity??1},_targetOpacity:0,_transitionKey:e})}l=!0}return i.exitNodes.length>0&&(i.scene=[...i.scene,...i.exitNodes]),l&&(i.activeTransition={startTime:a,duration:n}),i}(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=e.scene,this.exitNodes=e.exitNodes,this.activeTransition=e.activeTransition}advanceTransition(e){if(!this.activeTransition||!this.config.transition)return!1;let t={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},i=function(e,t,i,r){if(!i.activeTransition)return!1;let o=so(e,i.activeTransition),a=lo(o,"linear"===t.easing?"linear":"ease-out-cubic");for(let e of i.scene){let t=e._transitionKey;if("point"===e.type){if(void 0!==e._targetOpacity){let i=t?r.get(t):void 0;e.style.opacity=co(i?i.opacity??1:0,e._targetOpacity,a)}if(void 0===e._targetX||!t)continue;let i=r.get(t);if(!i)continue;e.x=co(i.x,e._targetX,a),e.y=co(i.y,e._targetY,a),void 0!==e._targetR&&void 0!==i.r&&(e.r=co(i.r,e._targetR,a))}else if("glyph"===e.type){if(void 0!==e._targetOpacity){let i=t?r.get(t):void 0;e.style.opacity=co(i?i.opacity??1:0,e._targetOpacity,a)}if(void 0===e._targetX||!t)continue;let i=r.get(t);if(!i)continue;e.x=co(i.x,e._targetX,a),e.y=co(i.y,e._targetY,a),void 0!==e._targetR&&void 0!==i.r&&(e.size=co(i.r,e._targetR,a))}else if("rect"===e.type){if(void 0!==e._targetOpacity){let i=t?r.get(t):void 0;e.style.opacity=co(i?i.opacity??1:0,e._targetOpacity,a)}if(void 0===e._targetX||!t)continue;let i=r.get(t);if(!i)continue;e.x=co(i.x,e._targetX,a),e.y=co(i.y,e._targetY,a),void 0!==i.w&&(e.w=co(i.w,e._targetW,a)),void 0!==i.h&&(e.h=co(i.h,e._targetH,a))}else if("heatcell"===e.type){if(void 0!==e._targetOpacity){let i=t?r.get(t):void 0;e.style={...e.style||{},opacity:co(i?i.opacity??1:0,e._targetOpacity,a)}}if(void 0===e._targetX||!t)continue;let i=r.get(t);if(!i)continue;e.x=co(i.x,e._targetX,a),e.y=co(i.y,e._targetY,a),void 0!==i.w&&(e.w=co(i.w,e._targetW,a)),void 0!==i.h&&(e.h=co(i.h,e._targetH,a))}else if("candlestick"===e.type){if(void 0!==e._targetOpacity){let i=t?r.get(t):void 0;e.style={...e.style||{},opacity:co(i?i.opacity??1:0,e._targetOpacity,a)}}if(void 0===e._targetX||!t)continue;let i=r.get(t);if(!i)continue;e.x=co(i.x,e._targetX,a),void 0!==i.openY&&(e.openY=co(i.openY,e._targetOpenY,a)),void 0!==i.closeY&&(e.closeY=co(i.closeY,e._targetCloseY,a)),void 0!==i.highY&&(e.highY=co(i.highY,e._targetHighY,a)),void 0!==i.lowY&&(e.lowY=co(i.lowY,e._targetLowY,a))}else if("line"===e.type){void 0!==e._targetOpacity&&(e.style={...e.style,opacity:co(e._startOpacity??0,e._targetOpacity,a)}),void 0!==e._introClipFraction&&(e._introClipFraction=a);let t=e._prevPath,i=e._targetPath;if(t&&i&&t.length===e.path.length)for(let r=0;e.path.length>r;r++)e.path[r][0]=co(t[r][0],i[r][0],a),e.path[r][1]=co(t[r][1],i[r][1],a)}else if("area"===e.type){void 0!==e._targetOpacity&&(e.style={...e.style,opacity:co(e._startOpacity??0,e._targetOpacity,a)}),void 0!==e._introClipFraction&&(e._introClipFraction=a);let t=e._prevTopPath,i=e._prevBottomPath,r=e._targetTopPath,o=e._targetBottomPath;if(t&&r&&t.length===e.topPath.length)for(let i=0;e.topPath.length>i;i++)e.topPath[i][0]=co(t[i][0],r[i][0],a),e.topPath[i][1]=co(t[i][1],r[i][1],a);if(i&&o&&i.length===e.bottomPath.length)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t][0]=co(i[t][0],o[t][0],a),e.bottomPath[t][1]=co(i[t][1],o[t][1],a)}}if(o>=1){for(let e of i.scene){if(void 0!==e._targetOpacity){let t=e._targetOpacity;e.style="line"===e.type||"area"===e.type?{...e.style,opacity:0===t?0:t}:{...e.style||{},opacity:0===t?0:t},e._targetOpacity=void 0}if("point"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("glyph"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,void 0!==e._targetR&&(e.size=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else if("heatcell"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else if("candlestick"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,void 0!==e._targetOpenY&&(e.openY=e._targetOpenY),void 0!==e._targetCloseY&&(e.closeY=e._targetCloseY),void 0!==e._targetHighY&&(e.highY=e._targetHighY),void 0!==e._targetLowY&&(e.lowY=e._targetLowY),e._targetX=void 0,e._targetOpenY=void 0,e._targetCloseY=void 0,e._targetHighY=void 0,e._targetLowY=void 0}else if("line"===e.type){let t=e._targetPath;if(t)for(let i=0;e.path.length>i;i++)e.path[i]=t[i];e._prevPath=void 0,e._targetPath=void 0,e._introClipFraction=void 0}else if("area"===e.type){let t=e._targetTopPath,i=e._targetBottomPath;if(t)for(let i=0;e.topPath.length>i;i++)e.topPath[i]=t[i];if(i)for(let t=0;e.bottomPath.length>t;t++)e.bottomPath[t]=i[t];e._prevTopPath=void 0,e._prevBottomPath=void 0,e._targetTopPath=void 0,e._targetBottomPath=void 0,e._introClipFraction=void 0}}if(i.exitNodes.length>0){let e=new Set(i.exitNodes);i.scene=i.scene.filter(t=>!e.has(t)),i.exitNodes=[]}return i.activeTransition=null,!1}return!0}(e,this.config.transition,t,this.prevPositionMap);return this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition,i}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,function(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type)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("glyph"===t.type)void 0!==t._targetX&&(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||"heatcell"===t.type)void 0!==t._targetX&&(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)void 0!==t._targetX&&(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||"area"===t.type){if(t._introClipFraction=void 0,"line"===t.type&&t._targetPath){for(let e=0;t.path.length>e;e++)t.path[e]=t._targetPath[e];t._prevPath=void 0,t._targetPath=void 0}if("area"===t.type){if(t._targetTopPath)for(let e=0;t.topPath.length>e;e++)t.topPath[e]=t._targetTopPath[e];if(t._targetBottomPath)for(let e=0;t.bottomPath.length>e;e++)t.bottomPath[e]=t._targetBottomPath[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0}}}}(this.scene),this.exitNodes=[]}groupData(e){let{result:t,cache:i}=function(e,t,i,r){if(r&&r.version===i&&r.group===t&&r.data===e)return{result:r.result,cache:r};let o;if(t){let i=new Map;for(let r of e){let e=t(r);i.has(e)||i.set(e,[]),i.get(e).push(r)}o=Array.from(i.entries()).map(([e,t])=>({key:e,data:t}))}else o=[{key:"_default",data:e}];return{result:o,cache:{version:i,group:t,data:e,result:o}}}(e,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=i,t}resolveColorMap(e){let{map:t,cache:i}=function(e,t,i,r,o){if(o&&o.version===r)return{map:o.map,cache:o};let a=new Set;if(t)for(let i of e){let e=t(i);e&&a.add(e)}let n=Array.from(a).sort(),l=n.join("\0");if(o&&o.key===l){let e={...o,version:r};return{map:e.map,cache:e}}let s=B(i.colorScheme,i.themeCategorical,Xd),c=new Map;for(let e=0;n.length>e;e++)c.set(n[e],Fo(i.colorScheme,n[e])??s[e%s.length]);return{map:c,cache:{key:l,map:c,version:r}}}(e,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=i,t}resolveLineStyle(e,t){return function(e,t,i,r){let o=e.lineStyle;if("function"==typeof o){let e=o(i||{},t);if(e&&!e.stroke&&t){let i=r(t);if(i)return{...e,stroke:i}}return e}let a=e.themeSemantic?.primary;return o&&"object"==typeof o?{stroke:o.stroke||a||"#007bff",strokeWidth:o.strokeWidth??2,strokeDasharray:o.strokeDasharray,fill:o.fill,fillOpacity:o.fillOpacity,opacity:o.opacity,cursor:o.cursor}:{stroke:r(t)||a||"#007bff",strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveAreaStyle(e,t){return function(e,t,i,r){if(e.areaStyle){let o=e.areaStyle(i||{});if(o&&!o.fill&&t){let e=r(t);if(e)return{...o,fill:e,stroke:o.stroke||e}}return o}let o=e.lineStyle;if("function"==typeof o){let e=o(i||{},t);if(e&&!e.fill&&t){let i=r(t);if(i)return{...e,fill:i,stroke:e.stroke||i}}return e}let a=e.themeSemantic?.primary;if(o&&"object"==typeof o)return{fill:o.fill||o.stroke||a||"#4e79a7",fillOpacity:o.fillOpacity??.7,stroke:o.stroke||a||"#4e79a7",strokeWidth:o.strokeWidth??2,cursor:o.cursor};let n=r(t)||a||"#4e79a7";return{fill:n,fillOpacity:.7,stroke:n,strokeWidth:2}}(this.config,e,t,e=>this.resolveGroupColor(e))}resolveGroupColor(t){let{color:i,groupColorCounter:r}=function(e){let{group:t,colorMapCache:i,groupColorMap:r,groupColorMapCap:o,config:a}=e,{groupColorCounter:n}=e,l=Fo(a.colorScheme,t);if(l)return{color:l,groupColorCounter:n};if(i){let e=i.map.get(t);if(e)return{color:e,groupColorCounter:n}}let s=r.get(t);if(s)return{color:s,groupColorCounter:n};let c=B(a.colorScheme,a.themeCategorical,Xd);if(0===c.length)return{color:null,groupColorCounter:n};let u=c[n%c.length];if(n++,r.set(t,u),r.size>o){let e=r.keys().next().value;void 0!==e&&r.delete(e)}return{color:u,groupColorCounter:n}}({group:t,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:e.GROUP_COLOR_MAP_CAP,config:this.config});return this._groupColorCounter=r,i}getBufferArray(){return(this._bufferDirty||!this._bufferArrayCache)&&(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(e){if(!this.getPointId)throw Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();let t=no(e),i=this.getPointId,r=e=>t.has(i(e));jo(this.buffer,this.timestampBuffer,r);let o=this.buffer.remove(r);if(0===o.length)return this.updateResults.recordNoop("remove"),o;for(let e of o)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",o.length),o}update(e,t){if(!this.getPointId)throw Error("update() requires pointIdAccessor to be configured");let i=no(e),r=this.getPointId,o=new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&o.add(t)});let a=this.buffer.update(e=>i.has(r(e)),t);if(0===a.length)return this.updateResults.recordNoop("update"),a;for(let e of a)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.buffer.forEach((e,t)=>{o.has(t)&&(this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",a.length),a}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(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},o=i(r,t);r.style=o?{...e,...o}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e||"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 r=!1,o=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let a="chartType"in e&&e.chartType!==t.chartType||"runtimeMode"in e&&e.runtimeMode!==t.runtimeMode;if(a||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e){let e=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=e&&this.config.valueAccessor||this.config.yAccessor,n=e&&t.valueAccessor||t.yAccessor,l=a||!Tc(e&&this.config.timeAccessor||this.config.xAccessor,e&&t.timeAccessor||t.xAccessor),s=a||!Tc(i,n);(l||s)&&(e?(this.getX=Xc(this.config.timeAccessor||this.config.xAccessor,"time"),this.getY=Xc(this.config.valueAccessor||this.config.yAccessor,"value")):(this.getX=Xc(this.config.xAccessor,"x"),this.getY=Xc(this.config.yAccessor,"y")),s&&this.resolvedRibbons.some(e=>"bounds"===e.kind)&&(this.resolvedRibbons=Mo(this.config)),r=!0,o=!0)}if("groupAccessor"in e&&!Tc(e.groupAccessor,t.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?Uc(this.config.groupAccessor):void 0,r=!0),"categoryAccessor"in e&&!Tc(e.categoryAccessor,t.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?Uc(this.config.categoryAccessor):void 0,r=!0),"sizeAccessor"in e&&!Tc(e.sizeAccessor,t.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?Xc(this.config.sizeAccessor,"size"):void 0,r=!0),"symbolAccessor"in e&&!Tc(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Uc(this.config.symbolAccessor):void 0,r=!0),"colorAccessor"in e&&!Tc(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Uc(this.config.colorAccessor):void 0,r=!0),"y0Accessor"in e&&!Tc(e.y0Accessor,t.y0Accessor)&&(this.getY0=this.config.y0Accessor?Xc(this.config.y0Accessor,"y0"):void 0,r=!0,o=!0),("boundsAccessor"in e&&!Tc(e.boundsAccessor,t.boundsAccessor)||"band"in e&&e.band!==t.band||"boundsStyle"in e&&e.boundsStyle!==t.boundsStyle)&&(this.resolvedRibbons=Mo(this.config),r=!0,o=!0),"pointIdAccessor"in e&&!Tc(e.pointIdAccessor,t.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?Uc(this.config.pointIdAccessor):void 0,r=!0),"candlestick"===this.config.chartType&&(a||"openAccessor"in e&&!Tc(e.openAccessor,t.openAccessor)||"closeAccessor"in e&&!Tc(e.closeAccessor,t.closeAccessor)||"highAccessor"in e&&!Tc(e.highAccessor,t.highAccessor)||"lowAccessor"in e&&!Tc(e.lowAccessor,t.lowAccessor))){let e=null!=this.config.openAccessor,t=null!=this.config.closeAccessor;this.getOpen=e?Xc(this.config.openAccessor,"open"):void 0,this.getHigh=Xc(this.config.highAccessor,"high"),this.getLow=Xc(this.config.lowAccessor,"low"),this.getClose=t?Xc(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!t,r=!0,o=!0}if("accessorRevision"in e&&e.accessorRevision!==t.accessorRevision&&(r=!0,o=!0),!r){let i=Object.keys(e).filter(e=>!e.endsWith("Accessor")&&"timeAccessor"!==e&&"valueAccessor"!==e);for(let o of i)if(e[o]!==t[o]){r=!0;break}}r&&(o&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(i,("bar"===this.config.chartType||"heatmap"===this.config.chartType)&&!this.config.trackHoverRows&&Me(t.areaStyle)!==Me(this.config.areaStyle))}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};uy.GROUP_COLOR_MAP_CAP=1e3;var dy=uy;qo(dy);import{area as hy,line as fy}from"d3-shape";var py=(e,t,i,r)=>{let o=t.filter(e=>"area"===e.type);for(let t of o){if(2>t.topPath.length)continue;let i=!1;t.clipRect&&(e.save(),e.beginPath(),e.rect(t.clipRect.x,t.clipRect.y,t.clipRect.width,t.clipRect.height),e.clip(),i=!0);let o=t._introClipFraction;void 0!==o&&1>o&&(e.save(),e.beginPath(),e.rect(0,0,r.width*o,r.height),e.clip());let a=Cr(e,t.style.fill,"#4e79a7"),n=t._decayOpacities,l=!(!t.colorThresholds?.length||!t.rawValues||t.rawValues.length!==t.topPath.length),s=!!t.strokeColorBands?.length;if(n&&n.length===t.topPath.length&&!l&&!s){let i=t.style.fillOpacity??.7;e.fillStyle=a;for(let r=0;t.topPath.length-1>r;r++)e.globalAlpha=.5*(n[r]+n[r+1])*i,e.beginPath(),e.moveTo(t.topPath[r][0],t.topPath[r][1]),e.lineTo(t.topPath[r+1][0],t.topPath[r+1][1]),e.lineTo(t.bottomPath[r+1][0],t.bottomPath[r+1][1]),e.lineTo(t.bottomPath[r][0],t.bottomPath[r][1]),e.closePath(),e.fill();let r=t.style.strokeWidth??2;if(t.style.stroke&&"none"!==t.style.stroke&&r>0){e.strokeStyle=tu(e,t.style.stroke)||t.style.stroke,e.lineWidth=r,e.setLineDash([]);for(let i=0;t.topPath.length-1>i;i++)e.globalAlpha=.5*(n[i]+n[i+1]),e.beginPath(),e.moveTo(t.topPath[i][0],t.topPath[i][1]),e.lineTo(t.topPath[i+1][0],t.topPath[i+1][1]),e.stroke()}e.globalAlpha=1;continue}let c=t.style.opacity??1;if(la(e,t),t.fillGradient&&t.fillGradient.stops.length>=2&&t.fillGradient){let i=1/0;for(let e of t.topPath)i>e[1]&&(i=e[1]);let r=-1/0;for(let e of t.bottomPath)e[1]>r&&(r=e[1]);let o=Dr(e,t.fillGradient,"string"==typeof a?a:"#4e79a7",0,i,0,r);e.fillStyle=o||a,e.globalAlpha=c}else e.globalAlpha=(t.style.fillOpacity??.7)*c,e.fillStyle=a;e.fill(),t._pulseIntensity&&t._pulseIntensity>0&&(la(e,t),oa(e,t));let u=t.style.strokeWidth??2;if(t.style.stroke&&"none"!==t.style.stroke&&u>0){e.globalAlpha=c;let i=tu(e,t.style.stroke)||t.style.stroke,r=l||s||!t.strokeGradient||2>t.topPath.length?null:Dr(e,t.strokeGradient,i,t.topPath[0][0],0,t.topPath[t.topPath.length-1][0],0);if(e.lineWidth=u,e.setLineDash([]),s){let r=1/0,o=-1/0;for(let[e]of t.topPath)r=Math.min(r,e),o=Math.max(o,e);let a=e.lineWidth;for(let n of t.strokeColorBands){e.save(),e.beginPath(),e.rect(r-a,n.y,o-r+2*a,n.height),e.clip();let l=n.color??i;e.strokeStyle=tu(e,l)||l,e.globalAlpha=c*(n.opacity??1),sa(e,t),e.stroke(),e.restore()}}else if(l){let r=na(t.topPath,t.rawValues,t.colorThresholds,i);for(let t of r){e.beginPath(),e.strokeStyle=tu(e,t.color)||t.color,e.moveTo(t.path[0][0],t.path[0][1]);for(let i=1;t.path.length>i;i++)e.lineTo(t.path[i][0],t.path[i][1]);e.stroke()}}else e.strokeStyle=r||i,sa(e,t),e.stroke()}void 0!==o&&1>o&&e.restore(),i&&e.restore(),e.globalAlpha=1}};import{line as yy}from"d3-shape";var gy=(e,t,i,r)=>{let o=t.filter(e=>"line"===e.type);for(let t of o){if(2>t.path.length)continue;let i=t._introClipFraction;void 0!==i&&1>i&&(e.save(),e.beginPath(),e.rect(0,0,r.width*i,r.height),e.clip());let o=t.style.stroke||"#007bff",a=tu(e,o)||o,n=t.style.strokeWidth??2,l=t.colorThresholds,s=t.rawValues;if(e.setLineDash(t.style.strokeDasharray?t.style.strokeDasharray.split(/[\s,]+/).map(Number):[]),null!=t.style.opacity&&(e.globalAlpha=t.style.opacity),n>0&&(e.lineWidth=n),e.lineCap=t.style.strokeLinecap||"butt",t.style._edgeFade&&n>0){ca(e,t.path,a,n,t.style.opacity??1,t.style.strokeLinecap||"butt"),e.globalAlpha=1,e.setLineDash([]),e.lineCap="butt";continue}let c=Rr(t.curve),u=l&&l.length>0&&s&&s.length===t.path.length,d=t._decayOpacities;if(n>0&&d&&d.length===t.path.length&&!u){e.strokeStyle=a;let i=t.style.opacity??1;for(let r=0;t.path.length-1>r;r++)e.globalAlpha=.5*(d[r]+d[r+1])*i,e.beginPath(),e.moveTo(t.path[r][0],t.path[r][1]),e.lineTo(t.path[r+1][0],t.path[r+1][1]),e.stroke()}else if(n>0&&!u){e.beginPath();let i=t.strokeGradient&&t.path.length>=2?Dr(e,t.strokeGradient,a,t.path[0][0],0,t.path[t.path.length-1][0],0):null;if(e.strokeStyle=i||a,c)yy().x(e=>e[0]).y(e=>e[1]).curve(c).context(e)(t.path);else{let[i,r]=t.path[0];e.moveTo(i,r);for(let i=1;t.path.length>i;i++)e.lineTo(t.path[i][0],t.path[i][1])}e.stroke()}else if(n>0){let i=na(t.path,s,l,a);for(let t of i){e.beginPath(),e.strokeStyle=tu(e,t.color)||t.color,e.moveTo(t.path[0][0],t.path[0][1]);for(let i=1;t.path.length>i;i++)e.lineTo(t.path[i][0],t.path[i][1]);e.stroke()}}if(t.style.fill&&t.style.fillOpacity&&t.style.fillOpacity>0){if(e.beginPath(),e.globalAlpha=t.style.fillOpacity,e.fillStyle=Cr(e,t.style.fill,t.style.fill),c&&!u)yy().x(e=>e[0]).y(e=>e[1]).curve(c).context(e)(t.path);else{let[i,r]=t.path[0];e.moveTo(i,r);for(let i=1;t.path.length>i;i++)e.lineTo(t.path[i][0],t.path[i][1])}let i=t.path[0][0];e.lineTo(t.path[t.path.length-1][0],r.height),e.lineTo(i,r.height),e.closePath(),e.fill()}void 0!==i&&1>i&&e.restore(),e.globalAlpha=1,e.setLineDash([]),e.lineCap="butt"}},my=(e,t,i,r)=>{let o=t.filter(e=>"point"===e.type);if(0!==o.length){e.save();try{let t=e.globalAlpha,i=[],r="",a=i=>{e.beginPath(),e.arc(i.x,i.y,i.r,0,2*Math.PI),e.globalAlpha=t*(i.style.opacity??i.style.fillOpacity??1),e.fillStyle=Cr(e,i.style.fill,"#4e79a7"),e.fill();let r=i.style.strokeWidth??1;i.style.stroke&&"none"!==i.style.stroke&&r>0&&(e.strokeStyle=Cr(e,i.style.stroke,i.style.stroke),e.lineWidth=r,e.stroke()),function(e,t,i=.6){if(!ia(t))return;let r=t.r+(t._pulseGlowRadius??4)*t._pulseIntensity,o=t.cx??t.x??0,a=t.cy??t.y??0;e.beginPath(),e.arc(o,a,r,0,2*Math.PI),e.strokeStyle=t._pulseColor||"rgba(255,255,255,0.6)",e.lineWidth=2*t._pulseIntensity,e.globalAlpha=t._pulseIntensity*i,e.stroke()}(e,i)},n=()=>{if(0===i.length)return;if(1===i.length)return a(i[0]),i=[],void(r="");let o=i[0];e.globalAlpha=t*(o.style.opacity??o.style.fillOpacity??1),e.beginPath();for(let t of i)e.moveTo(t.x+t.r,t.y),e.arc(t.x,t.y,t.r,0,2*Math.PI);e.fillStyle=Cr(e,o.style.fill,"#4e79a7"),e.fill();let n=o.style.strokeWidth??1;o.style.stroke&&"none"!==o.style.stroke&&n>0&&(e.strokeStyle=Cr(e,o.style.stroke,o.style.stroke),e.lineWidth=n,e.stroke()),i=[],r=""};for(let e of o){let t=e.style.opacity??e.style.fillOpacity??1,o=e.style.fill;if(ia(e)||null!=o&&"string"!=typeof o||1>t){n(),a(e);continue}let l=e.style.strokeWidth??1,s=`${o??"#4e79a7"}\0${e.style.stroke&&"none"!==e.style.stroke&&l>0?e.style.stroke+"":""}\0${l}\0${e.r}\0${t}`;i.length>0&&s!==r&&n(),r=s,i.push(e),i.length>=2048&&n()}n()}finally{e.restore()}}},xy={chartType:"line",buildScene:(e,t)=>function(e,t){let i=e.groupData(t),r=[],o=e.config.annotations?.filter(ta).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(e.ribbons&&e.ribbons.length>0){let{perSeries:o,aggregate:a}=Ko(e.ribbons);if(a.length>0&&r.push(...Qo(e,t,a)),o.length>0)for(let t of i)r.push(...Jo(e,t.data,t.key,o))}for(let t of i){let i=e.resolveLineStyle(t.key,Se(t.data)),a=Lo(t.data,e.scales,e.getX,e.getY,i,t.key);o&&o.length>0&&(a.colorThresholds=o),e.config.curve&&"linear"!==e.config.curve&&(a.curve=e.config.curve),e.config.lineGradient&&(a.strokeGradient=e.config.lineGradient),r.push(a)}return ea(e,i,r),r}(e,t),canvasRenderers:[py,gy,my]},by={chartType:"area",buildScene:(e,t)=>function(e,t){let i=e.groupData(t),r=[];if(e.ribbons&&e.ribbons.length>0){let{perSeries:o,aggregate:a}=Ko(e.ribbons);if(a.length>0&&r.push(...Qo(e,t,a)),o.length>0)for(let t of i)r.push(...Jo(e,t.data,t.key,o))}let o=e.scales.y.domain(),a=o[0],n=e.config.semanticLineStops?.filter(e=>Number.isFinite(e.offset)).map(e=>({value:o[0]+Math.max(0,Math.min(1,e.offset))*(o[1]-o[0]),color:e.color,opacity:e.opacity,thresholdType:"greater"})).sort((e,t)=>e.value-t.value),l=n&&n.length>0?(()=>{let t=n.reduce((e,t)=>(e.at(-1)?.value===t.value?e[e.length-1]=t:e.push(t),e),[]),i=[{from:o[0],to:t[0].value,color:t[0].color,opacity:t[0].opacity}];for(let e=0;t.length>e;e++)i.push({from:t[e].value,to:t[e+1]?.value??o[1],color:t[e].color,opacity:t[e].opacity});return i.map(({from:t,to:i,color:r,opacity:o})=>{let a=e.scales.y(t),n=e.scales.y(i);return{y:Math.min(a,n),height:Math.abs(n-a),color:r,...null!=o&&{opacity:o}}}).filter(e=>e.height>0)})():void 0,s=e.getY0?t=>e.getY0(t)??a:void 0;for(let t of i){let i=e.resolveAreaStyle(t.key,Se(t.data)),o=$o(t.data,e.scales,e.getX,e.getY,a,i,t.key,s),c=ua(e.config.gradientFill);c&&(o.fillGradient=c),e.config.curve&&"linear"!==e.config.curve&&(o.curve=e.config.curve),e.config.lineGradient&&(o.strokeGradient=e.config.lineGradient),n&&n.length>0&&(o.colorThresholds=n,o.strokeColorBands=l),r.push(o)}return ea(e,i,r),r}(e,t),canvasRenderers:[py,my]},vy={chartType:"stackedarea",buildScene:(e,t)=>function(e,t){let i=e.groupData(t),r=e.config.stackOrder??"key",o=()=>i.sort((e,t)=>t.key>e.key?-1:e.key>t.key?1:0);if("input"!==r)if("key"===r)o();else if("asc"===r||"desc"===r||"insideOut"===r){let t=new Map;for(let r of i){let i=0;for(let t of r.data){let r=e.getX(t),o=e.getY(t);Number.isFinite(r)&&Number.isFinite(o)&&(i+=o)}t.set(r.key,i)}let o=(e,t)=>t>e?-1:e>t?1:0;if("asc"===r)i.sort((e,i)=>{let r=(t.get(e.key)??0)-(t.get(i.key)??0);return 0!==r?r:o(e.key,i.key)});else if("desc"===r)i.sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:o(e.key,i.key)});else{let e=[...i].sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:o(e.key,i.key)}),r=[],a=[],n=0,l=0;for(let i of e)l>n?(r.push(i),n+=t.get(i.key)??0):(a.push(i),l+=t.get(i.key)??0);i.length=0,i.push(...a.reverse(),...r)}}else o();let a=e.config.curve&&"linear"!==e.config.curve?e.config.curve:void 0,n=e.config.normalize?"zero":e.config.baseline??"zero",{nodes:l,stackedTops:s}=function(e,t,i,r,o,a,n,l="zero"){let s=new Set,c=new Map;for(let t of e){let e=new Map;for(let o of t.data){let t=i(o),a=r(o);if(!Number.isFinite(t)||(s.add(t),!Number.isFinite(a)))continue;let n=e.get(t);n?(n.value+=a,n.sources?n.sources.push(o):n.sources=[n.datum,o]):e.set(t,{value:a,datum:o})}c.set(t.key,e)}let u,d=Array.from(s).sort((e,t)=>e-t);if(a){u=new Map;for(let t of d){let i=0;for(let r of e)i+=c.get(r.key)?.get(t)?.value||0;u.set(t,i||1)}}let h=To(d,e.map(e=>e.key),(e,t)=>c.get(e)?.get(t)?.value||0,l),f="diverging"===l&&!a,p=[],y=new Map,g=new Map,m=new Map,x=new Map;for(let e of d)g.set(e,h.get(e)??0),m.set(e,0),x.set(e,0);for(let i of e){let e=c.get(i.key),r=new Map,l=[],s=[],h=[],b=[],v=[],w=!1,k=()=>{if(0!==l.length){if(l.length>=2){let e=w?l.map((e,t)=>t).sort((e,t)=>l[e][0]-l[t][0]):void 0,t={type:"area",topPath:e?e.map(e=>l[e]):l,bottomPath:e?e.map(e=>s[e]):s,rawValues:e?e.map(e=>h[e]):h,style:o(i.key,Se(i.data)),datum:e?e.map(e=>b[e]):b,accessibleDatum:e?e.map(e=>v[e]):v,group:i.key};n&&(t.curve=n),p.push(t)}l=[],s=[],h=[],b=[],v=[],w=!1}};for(let o of d){let n,c,d=e.get(o),p=void 0!==d,y=d?.value??0;if(a&&p&&(y/=u.get(o)),!p||!Number.isFinite(y)||0===y){k();continue}f?y>0?(n=m.get(o),c=n+y,m.set(o,c)):(n=x.get(o),c=n+y,x.set(o,c)):(n=g.get(o),c=n+y,g.set(o,c));let A=t.x(o),S=t.y(n),M=t.y(c);if(!Number.isFinite(A)||!Number.isFinite(S)||!Number.isFinite(M)){k();continue}let _=d.sources,P=d.value,L=_?{..._[0],__aggregateValue:P,__aggregateCount:_.length,__aggregateRows:_}:d.datum;l.length>0&&l[l.length-1][0]>A&&(w=!0),l.push([A,M]),s.push([A,S]),b.push(L),h.push(P),v.push(_?{x:o,value:P,group:i.key,observations:_.length}:L),r.set(o,c)}k(),y.set(i.key,r)}return{nodes:p,stackedTops:y}}(i,e.scales,e.getX,e.getY,(t,i)=>e.resolveAreaStyle(t,i),e.config.normalize,a,n),c=l;if(e.config.pointStyle){let t=new WeakMap;for(let r of i){let i=s.get(r.key);if(i)for(let o of r.data){let r=e.getX(o),a=e.getY(o);null!=r&&!Number.isNaN(r)&&null!=a&&!Number.isNaN(a)&&i.has(r)&&t.set(o,i.get(r))}}ea(e,i,c,i=>t.get(i)??e.getY(i))}return c}(e,t),canvasRenderers:[py,my]},wy={chartType:"mixed",buildScene:(e,t)=>function(e,t){let i=e.groupData(t),r=[],o=e.config.areaGroups||new Set;if(e.ribbons&&e.ribbons.length>0){let{perSeries:o,aggregate:a}=Ko(e.ribbons);if(a.length>0&&r.push(...Qo(e,t,a)),o.length>0)for(let t of i)r.push(...Jo(e,t.data,t.key,o))}let a=e.scales.y.domain()[0],n=e.getY0?t=>e.getY0(t)??a:void 0;for(let t of i)if(o.has(t.key)){let i=e.resolveAreaStyle(t.key,Se(t.data)),o=$o(t.data,e.scales,e.getX,e.getY,a,i,t.key,n),l=ua(e.config.gradientFill);l&&(o.fillGradient=l),e.config.curve&&"linear"!==e.config.curve&&(o.curve=e.config.curve),e.config.lineGradient&&(o.strokeGradient=e.config.lineGradient),r.push(o)}else{let i=e.resolveLineStyle(t.key,Se(t.data)),o=Lo(t.data,e.scales,e.getX,e.getY,i,t.key);e.config.curve&&"linear"!==e.config.curve&&(o.curve=e.config.curve),e.config.lineGradient&&(o.strokeGradient=e.config.lineGradient),r.push(o)}return ea(e,i,r),r}(e,t),canvasRenderers:[py,gy,my]},ky=new Map,Ay=(e,t)=>{let i=e.globalAlpha;for(let r of t)"symbol"===r.type&&ha(e,r,r.x,r.y,i,"#4e79a7");e.globalAlpha=i},Sy=[my,Ay],My={chartType:"scatter",buildScene:(e,t)=>da(e,t),canvasRenderers:Sy},_y={chartType:"bubble",buildScene:(e,t)=>da(e,t),canvasRenderers:Sy},Py=256,Ly=new Map,$y=(e,t,i,r)=>{let o=t.filter(e=>"heatcell"===e.type);e.save();try{let t=tu(e,"var(--semiotic-font-family, sans-serif)")||"sans-serif";for(let i of o){let r=i.style;null!=r?.opacity&&(e.globalAlpha=r.opacity);let o=Ir(e,i.fill,"#4e79a7");e.fillStyle=o,e.fillRect(i.x,i.y,i.w,i.h);let a=Math.max(0,r?.strokeWidth??1);if(a>0&&(e.strokeStyle=tu(e,r?.stroke??"var(--semiotic-surface, #fff)"),e.lineWidth=a,e.strokeRect(i.x,i.y,i.w,i.h)),ra(e,i),e.globalAlpha=1,i.showValues&&null!=i.value){if(20>i.w||20>i.h)continue;let r=i.valueFormat?i.valueFormat(i.value):xa(i.value),a=Math.max(10,Math.min(16,.3*Math.min(i.w,i.h))),n=i.x+i.w/2,l=i.y+i.h/2;e.fillStyle=ma(e,"string"==typeof o?o:"#4e79a7"),e.font=`${a}px ${t}`,e.textAlign="center",e.textBaseline="middle",e.fillText(r,n,l)}}}finally{e.restore()}},Ty={chartType:"heatmap",buildScene:(e,t,i)=>function(e,t,i){if(e.config.heatmapAggregation)return ga(e,t,i);if(0===t.length)return[];let r=Xc(e.config.valueAccessor,"value"),o=qc(e.config.xAccessor,"x"),a=qc(e.config.yAccessor,"y"),n=new Map,l=new Map,s=Array(t.length),c=Array(t.length);for(let e=0;t.length>e;e++){let i=t[e],r=o(i),u=a(i);s[e]=r,c[e]=u,n.has(r)||n.set(r,n.size),l.has(u)||l.set(u,l.size)}let u=n.size,d=l.size;if(0===u||0===d)return[];let h=Array.from(n.keys()),f=Array.from(l.keys()),p=h.every(e=>"number"==typeof e&&!isNaN(e)),y=f.every(e=>"number"==typeof e&&!isNaN(e)),g=4096;if(p&&y&&u*d>g&&t.length>g){let r=new Set;for(let o=0;t.length>o;o++){let a=n.get(s[o]),d=l.get(c[o]);if(void 0!==a&&void 0!==d&&(r.add(d*u+a),r.size>g))return ga({...e,config:{...e.config,heatmapAggregation:e.config.valueAccessor?"mean":"count"}},t,i)}}if(p){h.sort((e,t)=>Number(e)-Number(t)),n.clear();for(let e=0;h.length>e;e++)n.set(h[e],e)}if(y){f.sort((e,t)=>Number(e)-Number(t)),l.clear();for(let e=0;f.length>e;e++)l.set(f[e],e)}let m=new Float64Array(t.length),x=new Float64Array(t.length),b=Array(t.length),v=new Map,w=0;for(let e=0;t.length>e;e++){let i=t[e],o=n.get(s[e]),a=l.get(c[e]);if(void 0===o||void 0===a)continue;let d,h=r(i),f=a*u+o,p=v.get(f);void 0!==p?d=p:(d=w++,v.set(f,d)),m[d]=f,x[d]=h,b[d]=i}let k=1/0,A=-1/0;for(let e=0;w>e;e++){let t=x[e];isFinite(t)&&(k>t&&(k=t),t>A&&(A=t))}if(!isFinite(k)||!isFinite(A))return[];let S=e.config.heatmapColorScale,M=S?void 0:pa("string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues"),_=i.width/u,P=i.height/d,L=e.config.showValues,$=e.config.heatmapValueFormat,T=[];for(let t=0;w>t;t++){let i=x[t];if(!isFinite(i))continue;let r=m[t],o=r%u,a=(r-o)/u,n=fa(i,k,A),l=S?S(i):M[n],s=b[t];T.push(ya(Do(o*_,(d-1-a)*P,_,P,l,s,L?{value:i,showValues:!0,valueFormat:$}:{value:i}),s,e))}return T}(e,t,i),canvasRenderers:[$y]},Ry=(e,t,i,r)=>{let o=t.filter(e=>"rect"===e.type);for(let t of o){if(null!=t.style.opacity&&(e.globalAlpha=t.style.opacity),t.style.icon)Sa(e,t);else if(t.cornerRadii&&ba(t.cornerRadii))e.fillStyle=ka(e,t),wa(e,t),e.fill(),Aa(e,t)&&e.stroke();else if(t.roundedTop&&t.roundedTop>0){e.fillStyle=ka(e,t);let i=Math.min(t.roundedTop,t.w/2,t.h/2);e.beginPath();let{x:r,y:o,w:a,h:n}=t;switch(t.roundedEdge){case"right":e.moveTo(r,o),e.lineTo(r+a-i,o),e.arcTo(r+a,o,r+a,o+i,i),e.lineTo(r+a,o+n-i),e.arcTo(r+a,o+n,r+a-i,o+n,i),e.lineTo(r,o+n);break;case"left":e.moveTo(r+a,o),e.lineTo(r+i,o),e.arcTo(r,o,r,o+i,i),e.lineTo(r,o+n-i),e.arcTo(r,o+n,r+i,o+n,i),e.lineTo(r+a,o+n);break;case"bottom":e.moveTo(r,o),e.lineTo(r+a,o),e.lineTo(r+a,o+n-i),e.arcTo(r+a,o+n,r+a-i,o+n,i),e.lineTo(r+i,o+n),e.arcTo(r,o+n,r,o+n-i,i);break;default:e.moveTo(r,o+n),e.lineTo(r,o+i),e.arcTo(r,o,r+i,o,i),e.lineTo(r+a-i,o),e.arcTo(r+a,o,r+a,o+i,i),e.lineTo(r+a,o+n)}e.closePath(),e.fill(),Aa(e,t)&&e.stroke()}else e.fillStyle=ka(e,t),e.fillRect(t.x,t.y,t.w,t.h),Aa(e,t)&&e.strokeRect(t.x,t.y,t.w,t.h);ra(e,t),e.globalAlpha=1}},Cy={chartType:"bar",buildScene:(e,t)=>function(e,t){if(!e.config.binSize)return{nodes:[],binBoundaries:[]};let i=_o(t,e.getX,e.getY,e.config.binSize,e.getCategory,!!e.config.trackHoverRows||Me(e.config.areaStyle));if(0===i.size)return{nodes:[],binBoundaries:[]};let r=null;if(e.getCategory){let t=new Set;for(let e of i.values())for(let i of e.categories.keys())t.add(i);let o=e.config.barColors?Object.keys(e.config.barColors):[],a=new Set(o),n=Array.from(t).filter(e=>!a.has(e)).sort(),l=o.filter(e=>t.has(e)),s=l.join("\0")+""+n.join("\0");e.barCategoryCache&&e.barCategoryCache.key===s?r=e.barCategoryCache.order:(r=[...l,...n],e.barCategoryCache={key:s,order:r})}let o=[],a=e.scales,[n,l]=a.x.domain(),s=e.config.barStyle,c=e.config.themeSemantic?.primary,u=s?.gap,d="number"!=typeof u||0>u?1:u,h={};s?.stroke&&(h.stroke=s.stroke),"number"==typeof s?.strokeWidth&&(h.strokeWidth=s.strokeWidth),"number"==typeof s?.opacity&&(h.opacity=s.opacity),s?.cursor&&(h.cursor=s.cursor);for(let t of i.values()){let i=Math.max(t.start,n),u=Math.min(t.end,l);if(i>=u)continue;let f=a.x(i),p=a.x(u),y=Math.abs(p-f),g=y>d+1?d:0,m=Math.min(f,p)+g/2,x=Math.max(y-g,1);if(x>0)if(r&&t.categories.size>0){let i=0;for(let n of r){let r=t.categories.get(n)||0;if(0===r)continue;let l=a.y(i),u=a.y(i+r),d=Math.min(l,u),f=Math.abs(l-u),p=(e.config.barColors?X(e.config.barColors,n):void 0)??s?.fill??c??"#4e79a7",y=we({binStart:t.start,binEnd:t.end,total:t.total,category:n,categoryValue:r},t.categoryRows?.get(n)),g=e.config.areaStyle?.(y)??{};o.push(Io(m,d,x,f,{fill:p,...h,...g},y,n)),i+=r}}else{let i=a.y(0),r=a.y(t.total),n=Math.min(i,r),l=Math.abs(i-r),u=s?.fill||c||"#007bff",d=we({binStart:t.start,binEnd:t.end,total:t.total},t.rows),f=e.config.areaStyle?.(d)??{};o.push(Io(m,n,x,l,{fill:u,...h,...f},d))}}let f=new Set;for(let e of i.values())f.add(e.start),f.add(e.end);return{nodes:o,binBoundaries:Array.from(f).sort((e,t)=>e-t)}}(e,t),canvasRenderers:[Ry]},Iy={chartType:"swarm",buildScene:(e,t)=>function(e,t){let i=[],r=e.config.swarmStyle||{},o=r.radius??3,a=r.fill??e.config.themeSemantic?.primary??"#007bff",n=r.opacity??.7,l=r.stroke,s=r.strokeWidth,c=r.cursor;for(let r of t){let t=e.getX(r),u=e.getY(r);if(null==u||Number.isNaN(u))continue;let d=e.scales.x(t),h=e.scales.y(u),f=a;if(e.getCategory){let t=e.getCategory(r)+"";f=(e.config.barColors?X(e.config.barColors,t):void 0)??f}let{r:p,...y}=e.config.pointStyle?.(r)??{},g={type:"point",x:d,y:h,r:p??o,style:{fill:f,opacity:n,stroke:l,strokeWidth:s,cursor:c,...y},datum:r};e.getPointId&&(g.pointId=e.getPointId(r)+""),i.push(g)}return i}(e,t),canvasRenderers:[my]},Dy=(e,t,i,r)=>{Ry(e,t);let o=t.filter(e=>"rect"===e.type);if(2>o.length)return;let a=o[0].datum,n=a?._connectorStroke;if(n){e.save(),e.strokeStyle=tu(e,n)||n,e.lineWidth=a?._connectorWidth??1,e.setLineDash([]);for(let t=0;o.length-1>t;t++){let r=o[t],a=o[t+1],n=r.datum,l=a.datum;if(null==n?.cumEnd||null==l?.baseline)continue;let s=i.y(n.cumEnd),c=r.x+r.w,u=a.x;e.beginPath(),e.moveTo(c,s),e.lineTo(u,s),e.stroke()}e.restore()}},zy={chartType:"waterfall",buildScene:(e,t,i)=>function(e,t,i){let r=[],o=e.scales,a=e.config.waterfallStyle,n=t.filter(t=>{let i=e.getY(t),r=e.getX(t);return null!=i&&!Number.isNaN(i)&&null!=r&&isFinite(r)});if(0===n.length)return r;let l=a?.positiveColor??e.config.themeSemantic?.success??"#28a745",s=a?.negativeColor??e.config.themeSemantic?.danger??"#dc3545",c=a?.gap??1,u=a?.stroke,d=a?.strokeWidth,h=a?.opacity,f=0;for(let t=0;n.length>t;t++){let p=n[t],y=e.getX(p),g=e.getY(p),m=f+g,x=o.x(y),b=t>0?o.x(e.getX(n[t-1])):void 0,v=n.length-1>t?o.x(e.getX(n[t+1])):void 0,w=null!=b?(b+x)/2:null!=v?x-(v-x)/2:x-i.width/20,k=null!=v?(x+v)/2:null!=b?x+(x-b)/2:x+i.width/20,A=Math.min(w,k)+c/2,S=Math.max(w,k)-c/2-A;if(0>=S){f=m;continue}let M=o.y(f),_=o.y(m),P=Math.min(M,_),L=Math.abs(M-_),$=0>g?s:l,T={...p,baseline:f,cumEnd:m,delta:g,_connectorStroke:a?.connectorStroke,_connectorWidth:a?.connectorWidth},R={fill:$,stroke:u,strokeWidth:d,opacity:h,cursor:a?.cursor,...e.config.areaStyle?.(T)};r.push(Io(A,P,S,L,R,T)),f=m}return r}(e,t,i),canvasRenderers:[Dy]},Oy=(e,t,i,r)=>{for(let i of t){if("candlestick"!==i.type)continue;let t=i;e.save();let o=(t._decayOpacity??1)*(t.style?.opacity??1);1!==o&&(e.globalAlpha=o);let a=tu(e,t.wickColor)||t.wickColor,n=60>r.height,l=n?Math.max(t.wickWidth,2):t.wickWidth,s=()=>{e.beginPath(),e.moveTo(t.x,t.highY),e.lineTo(t.x,t.lowY),e.strokeStyle=a,e.lineWidth=l,e.stroke()};if(n||s(),t.isRange){let i=t.dotRadius??Math.max(2,Math.min(t.bodyWidth/2,.12*r.height)),o=Ir(e,ai(t.style?.fill)?t.style.fill:t.wickColor,t.wickColor);e.fillStyle=o,e.beginPath(),e.arc(t.x,t.highY,i,0,2*Math.PI),e.fill(),e.beginPath(),e.arc(t.x,t.lowY,i,0,2*Math.PI),e.fill()}else if(t.bodyWidth>0){let i=Math.min(t.openY,t.closeY),r=Math.abs(t.openY-t.closeY),o=t.isUp?t.upColor:t.downColor,a=Ir(e,ai(t.style?.fill)?t.style.fill:o,o),n="string"==typeof a?a:tu(e,t.wickColor)||t.wickColor;e.fillStyle=a,e.fillRect(t.x-t.bodyWidth/2,i,t.bodyWidth,Math.max(r,1)),e.strokeStyle=n,e.lineWidth=1,e.strokeRect(t.x-t.bodyWidth/2,i,t.bodyWidth,Math.max(r,1))}n&&s(),e.restore()}},Fy={chartType:"candlestick",buildScene:(e,t,i)=>function(e,t,i){if(!e.getHigh||!e.getLow||!e.scales)return[];let r=e.config.candlestickRangeMode??!1;if(!(r||e.getOpen&&e.getClose))return[];let o=[],a=e.config.candlestickStyle||{},n=a.rangeColor||"#6366f1",l=r?n:a.upColor||"#28a745",s=r?n:a.downColor||"#dc3545",c=r?n:a.wickColor||"#333",u=a.wickWidth||(r?2:1),d=a.bodyWidth??0;if(null==a.bodyWidth){let i=t.map(t=>e.getX(t)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);if(i.length>1){let t=1/0,r=e.scales.x(i[0]);for(let o=1;i.length>o;o++){let a=e.scales.x(i[o]),n=Math.abs(a-r);n>0&&t>n&&(t=n),r=a}d=t!==1/0?Math.max(2,Math.min(.6*t,20)):6}else d=6}for(let n of t){let t=e.getX(n);if(null==t||Number.isNaN(t))continue;let h=e.getHigh(n),f=e.getLow(n);if(null==h||Number.isNaN(h)||null==f||Number.isNaN(f))continue;let p=r?h:e.getOpen(n),y=r?f:e.getClose(n);if(!r&&(null==p||Number.isNaN(p)||null==y||Number.isNaN(y)))continue;let g=y>=p,m=e.config.pointStyle?.(n)??{},x="string"==typeof m.fill?m.fill:void 0,b="string"==typeof m.stroke?m.stroke:void 0,v="number"==typeof m.strokeWidth?m.strokeWidth:void 0,w="number"==typeof m.opacity?m.opacity:"number"==typeof m.fillOpacity?m.fillOpacity:void 0,k={type:"candlestick",x:e.scales.x(t),openY:e.scales.y(p),closeY:e.scales.y(y),highY:e.scales.y(h),lowY:e.scales.y(f),bodyWidth:d,upColor:x&&g?x:l,downColor:x&&!g?x:s,wickColor:b??(r&&x?x:c),wickWidth:v??u,isUp:g,style:{cursor:a.cursor,...m,...void 0!==w&&{opacity:w}},datum:n};r&&(k.isRange=!0,k.dotRadius=Math.max(2,Math.min(d/2,.12*i.height))),o.push(k)}return o}(e,t,i),canvasRenderers:[Oy]},Ny={chartType:"custom",buildScene:()=>[],canvasRenderers:[py,Ry,$y,gy,my,Ay,(e,t)=>{let i=e.globalAlpha;for(let r of t)"glyph"===r.type&&Ma(e,r,r.x,r.y,i);e.globalAlpha=i},Oy,my,Dy]};import*as Ey from"react";import{area as Wy,line as jy}from"d3-shape";import*as By from"react";import{jsx as Yy,jsxs as Xy}from"react/jsx-runtime";var Gy={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};import*as Vy from"react";import{jsx as Hy}from"react/jsx-runtime";import{jsx as qy,jsxs as Uy}from"react/jsx-runtime";var Zy=new Set;import{scaleOrdinal as Ky}from"d3-scale";import{jsx as Qy,jsxs as Jy}from"react/jsx-runtime";import{jsx as eg,jsxs as tg}from"react/jsx-runtime";var ig="var(--semiotic-bg, #ffffff)";import{jsx as rg}from"react/jsx-runtime";import{jsx as og,jsxs as ag}from"react/jsx-runtime";import{jsx as ng,jsxs as lg}from"react/jsx-runtime";import{jsx as sg}from"react/jsx-runtime";var cg={secondary:0,primary:3},ug=new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);import{jsx as dg}from"react/jsx-runtime";var hg={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};import{packEnclose as fg}from"d3-hierarchy";import{area as pg,curveBasis as yg,curveCardinal as gg,curveCatmullRom as mg,curveLinear as xg,curveMonotoneX as bg,curveMonotoneY as vg,curveStep as wg,curveStepAfter as kg,curveStepBefore as Ag}from"d3-shape";import*as Sg from"react";import{jsx as Mg,jsxs as _g}from"react/jsx-runtime";var Pg={linear:xg,monotoneX:bg,monotoneY:vg,step:wg,stepAfter:kg,stepBefore:Ag,basis:yg,cardinal:gg,catmullRom:mg};import{jsx as Lg,jsxs as $g}from"react/jsx-runtime";var Tg=16;import{jsx as Rg}from"react/jsx-runtime";import*as Cg from"react";import{jsx as Ig}from"react/jsx-runtime";var Dg=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];import{jsx as zg,jsxs as Og}from"react/jsx-runtime";var Fg={right:110,left:110,top:50,bottom:80};import{jsx as Ng,jsxs as Eg}from"react/jsx-runtime";var Wg={top:50,right:40,bottom:60,left:70},jg={top:20,right:80,bottom:20,left:80},Bg={top:40,right:40,bottom:40,left:40},Yg=new Set(["chord","force","circlepack","orbit"]);import{jsx as Xg,jsxs as Gg}from"react/jsx-runtime";import{Fragment as Vg,jsx as Hg,jsxs as qg}from"react/jsx-runtime";_a();import*as Ug from"react-dom/server";import{jsx as Zg,jsxs as Kg}from"react/jsx-runtime";import{jsx as Qg,jsxs as Jg}from"react/jsx-runtime";import{jsx as em,jsxs as tm}from"react/jsx-runtime";var im={top:4,bottom:4,left:4,right:4},rm={frameType:"xy",buildProps:nl,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:o,common:a,rest:n}=ll(e),[l,s]=a.size??[600,400],c=n.minimap&&"object"==typeof n.minimap?n.minimap:{},u=sl(c.height,60),d=a.margin,h=c.margin&&"object"==typeof c.margin?c.margin:{},f={top:sl(h.top,0),right:sl(h.right,sl(d?.right,20)),bottom:sl(h.bottom,20),left:sl(h.left,sl(d?.left,40))},p=u+f.top+f.bottom,y=n.frameProps&&"object"==typeof n.frameProps?n.frameProps:{},g={...n,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y"},m={...a,size:[l,s],xExtent:y.xExtent??n.brushExtent??a.xExtent,yExtent:y.yExtent??n.yExtent??a.yExtent,_idPrefix:(a._idPrefix??"minimap")+"-detail"},x=ph.buildProps(i,r,o,m,g);Object.assign(x,y);let b={...a,size:[l,p],margin:f,title:void 0,description:(a.description??a.title??"Chart")+" overview minimap",showAxes:c.showAxes??!1,showLegend:!1,showGrid:!1,accessibleTable:!1,background:c.background,xExtent:void 0,yExtent:n.yExtent??a.yExtent,_idPrefix:(a._idPrefix??"minimap")+"-overview"};delete b.lineStyle,delete b.pointStyle;let v={...g,fillArea:!1,lineWidth:1,showPoints:!1,directLabel:!1,forecast:void 0,anomaly:void 0,band:void 0},w=ph.buildProps(i,r,o,b,v);w.chartType=n.fillArea?"area":"line","function"==typeof c.lineStyle&&(w.lineStyle=c.lineStyle);let k={},A={},S=Un(x,k),M=Un(w,A),_=!0===n.renderBefore,P=_?0:s,L=""+ul(S,0,_?p:0,"detail")+ul(M,0,P,"overview"),$=s+p,T=se(le(a.theme)),R="string"==typeof a.title?a.title:void 0,C="string"==typeof a.description?a.description:R||"Chart with overview minimap",I=jn(a),D=R?I+"-title":void 0,z=I+"-description",O="y"===c.brushDirection?"y":"x",F=Array.isArray(n.brushExtent)&&n.brushExtent.length>=2?[Number(n.brushExtent[0]),Number(n.brushExtent[1])]:null,N=A.evidence,E=null;if(F&&F.every(Number.isFinite)&&N){let e="x"===O?N.xDomain:N.yDomain;if(e&&e[0]!==e[1]){let t=Math.max(0,l-f.left-f.right),i=u,r=t=>(t-e[0])/(e[1]-e[0]);if("x"===O){let e=r(Math.min(...F))*t,o=r(Math.max(...F))*t;E=em("rect",{className:"selection",x:f.left+e,y:P+f.top,width:o-e,height:i,fill:"steelblue",fillOpacity:.2,stroke:"steelblue",strokeWidth:1})}else{let e=(1-r(Math.max(...F)))*i,o=(1-r(Math.min(...F)))*i;E=em("rect",{className:"selection",x:f.left,y:P+f.top+e,width:t,height:o-e,fill:"steelblue",fillOpacity:.2,stroke:"steelblue",strokeWidth:1})}}}let W=zp.renderToStaticMarkup(tm("svg",{xmlns:"http://www.w3.org/2000/svg",className:"minimap-chart",width:l,height:$,role:"img","aria-labelledby":[D,z].filter(Boolean).join(" "),style:{fontFamily:T.fontFamily},children:[R&&em("title",{id:D,children:R}),em("desc",{id:z,children:C}),em("g",{dangerouslySetInnerHTML:{__html:L}}),E]}));if(t){let e=[k.evidence,A.evidence];t.evidence=Pa({frameType:"xy",width:l,height:$,parts:e,title:R,description:C,xDomain:dl(e,"xDomain"),yDomain:dl(e,"yDomain")})}return W}},om={Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,i,r,o)=>({chartType:"line",data:e,xAccessor:o.xAccessor||"x",yAccessor:o.yAccessor||"y",groupAccessor:o.lineBy||t,colorAccessor:t,...r,showAxes:!1,margin:r.margin,showLegend:!1,showGrid:!1,title:void 0})},BumpChart:ch,LineChart:ph,AreaChart:gh,DifferenceChart:mh,StackedAreaChart:xh,Scatterplot:Jd,CandlestickChart:bh,BubbleChart:eh,ConnectedScatterplot:wh,QuadrantChart:vh,Heatmap:kh,WaterfallChart:fh,MultiAxisLineChart:hh,MinimapChart:rm,ScatterplotMatrix:{frameType:"xy",buildProps:nl,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:o,common:a,rest:n}=ll(e),l=Array.isArray(I=i)?I.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[],s=Array.isArray(n.fields)?n.fields.filter(e=>"string"==typeof e):[],c=n.fieldLabels&&"object"==typeof n.fieldLabels?n.fieldLabels:{},u=cl(n.cellSize,150),d=Math.max(0,sl(n.cellGap,4)),h=Math.max(0,sl(n.pointRadius,2)),f=Math.max(0,Math.min(1,sl(n.pointOpacity,.5))),p=cl(n.histogramBins,20),y="string"==typeof n.diagonal?n.diagonal:"histogram",g=40+s.length*u+s.length*d,m=s.length*u+40+s.length*d,x=le(a.theme),b=se(x),v=function(e,t,i,r){if(!t)return{categories:[],color:()=>Yd};let o=Array.from(new Set(e.map(e=>hl(e,t)))),a="string"==typeof t?t:"__semioticSplomColor",n=G("function"==typeof t?e.map(e=>({...e,[a]:hl(e,t)})):e,a,i??r.colors.categorical);return{categories:o,color:e=>Y(e,t,n)}}(l,r,o,x),w="string"==typeof a.title?a.title:void 0,k="string"==typeof a.description?a.description:`Scatterplot matrix comparing ${s.length} fields`,A=w?28:0,S=n.showLegend??!!r?v.categories:[],M=0,_=0,P=S.map(e=>{let t=(e=>Math.max(72,30+7*e.length))(e);M>0&&M+t>g&&(_+=1,M=0);let i={label:e,x:M,y:24*_};return M+=t,i}),L=A+(S.length?24*(_+1)+4:0),$=L+m,T=[],R=[],C=0;var I;s.forEach((e,t)=>{s.forEach((i,o)=>{let s=40+d+o*(u+d),g=L+t*(u+d);if(t===o){let t=function(e){let{data:t,field:i,label:r,cellSize:o,bins:a,diagonal:n,colorBy:l,color:s,x:c,y:u}=e;if("label"===n)return{visibleBars:0,svg:zp.renderToStaticMarkup(em("svg",{x:c,y:u,width:o,height:o,"data-semiotic-composite-part":"diagonal-"+i,children:em("text",{x:o/2,y:o/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333",children:r})}))};let d=t.map(e=>Number(e[i])).filter(Number.isFinite),h=d.length?Math.min(...d):0,f=((d.length?Math.max(...d):0)-h)/a||1,p=Array.from({length:a},()=>new Map);for(let e of t){let t=Number(e[i]);if(!Number.isFinite(t))continue;let r=Math.max(0,Math.min(a-1,Math.floor((t-h)/f))),o=l?hl(e,l):"__all",n=p[r];n.set(o,[...n.get(o)??[],e])}let y=p.map(e=>Array.from(e.values()).reduce((e,t)=>e+t.length,0)),g=Math.max(1,...y),m=0,x=p.flatMap((e,t)=>{let i=0;return Array.from(e.entries()).flatMap(([e,r])=>{if(0===r.length)return[];m+=1;let n=r.length/g*(o-24),c=i;return i+=n,em("rect",{x:t/a*o,y:o-c-n,width:Math.max(o/a-1,1),height:n,fill:l?s(r[0]):Yd,opacity:.6},`${t}-${e}`)})});return{visibleBars:m,svg:zp.renderToStaticMarkup(tm("svg",{x:c,y:u,width:o,height:o,"data-semiotic-composite-part":"diagonal-"+i,children:[em("text",{x:o/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333",children:r}),x]}))}}({data:l,field:e,label:X(c,e)??e,cellSize:u,bins:p,diagonal:y,colorBy:r,color:v.color,x:s,y:g});return C+=t.visibleBars,void R.push(t.svg)}let m={},x=Un({chartType:"scatter",data:l,size:[u,u],xAccessor:i,yAccessor:e,pointStyle:cu(e=>({r:h,opacity:f,fill:v.color(e)}),n.styleRules,hu(i,e)),margin:im,showAxes:!1,showGrid:!1,enableHover:!1,accessibleTable:!1,description:`${X(c,i)??i} versus ${X(c,e)??e} scatterplot`,theme:a.theme,_idPrefix:`${(a._idPrefix??"splom")+""}-${t}-${o}`},m);T.push(m.evidence),R.push(ul(x,s,g,`cell-${e}-${i}`))})});let D=jn(a),z=w?D+"-title":void 0,O=D+"-description",F=zp.renderToStaticMarkup(tm("svg",{xmlns:"http://www.w3.org/2000/svg",className:"scatterplot-matrix",width:g,height:$,role:"img","aria-labelledby":[z,O].filter(Boolean).join(" "),style:{fontFamily:b.fontFamily},children:[w&&em("title",{id:z,children:w}),em("desc",{id:O,children:k}),em("rect",{width:g,height:$,fill:b.background}),w&&em("text",{x:0,y:18,fontSize:14,fontWeight:600,fill:b.text,children:w}),P.map(e=>{let t=l.find(t=>r&&hl(t,r)===e.label),i=t?v.color(t):Yd;return tm("g",{transform:`translate(${e.x},${A+e.y})`,children:[em("circle",{cx:5,cy:8,r:5,fill:i}),em("text",{x:14,y:12,fontSize:11,fill:b.text,children:e.label})]},e.label)}),s.map((e,t)=>{let i=L+t*(u+d)+u/2;return em("text",{x:20,y:i,transform:`rotate(-90 20 ${i})`,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:X(c,e)??e},"row-"+e)}),s.map((e,t)=>em("text",{x:40+d+t*(u+d)+u/2,y:L+s.length*(u+d)+20,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:X(c,e)??e},"column-"+e)),em("g",{dangerouslySetInnerHTML:{__html:R.join("")}})]}));return t&&(t.evidence=Pa({frameType:"xy",width:g,height:$,parts:T,additionalMarkCountByType:C>0?{histogram:C}:void 0,title:w,description:k,categories:v.categories.length?v.categories:void 0,legendItems:S.length||void 0})),F}},TemporalHistogram:yh,XYCustomChart:Cf,BarChart:Oh,StackedBarChart:Fh,GroupedBarChart:Nh,PieChart:Eh,DonutChart:Wh,Histogram:jh,BoxPlot:Bh,ViolinPlot:Yh,SwarmPlot:Xh,DotPlot:Gh,SwimlaneChart:Hh,RidgelinePlot:qh,LikertChart:$h,FunnelChart:Uh,RadarChart:Vh,GaugeChart:zh,OrdinalCustomChart:If,ParallelCoordinatesRecipe:Df,CalendarHeatmapRecipe:zf,ForceDirectedGraph:bf,NetworkCustomChart:{frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,i,r,o)=>({chartType:"force",nodes:o.nodes||e||[],edges:o.edges||[],nodeIDAccessor:o.nodeIdAccessor||o.nodeIDAccessor||"id",sourceAccessor:o.sourceAccessor||"source",targetAccessor:o.targetAccessor||"target",valueAccessor:o.valueAccessor||"value",colorBy:t,colorScheme:i,customNetworkLayout:o.layout||o.customNetworkLayout,layoutConfig:o.layoutConfig,...r})},SankeyDiagram:Af,ProcessSankey:kf,ChordDiagram:xf,TreeDiagram:Sf,Treemap:Mf,CirclePack:vf,OrbitDiagram:wf,ChoroplethMap:Lf,ProportionalSymbolMap:$f,FlowMap:Rf,DistanceCartogram:Tf,GeoCustomChart:{frameType:"geo",buildProps:(e,t,i,r,o)=>({points:o.points||e||[],areas:o.areas||[],lines:o.lines||[],projection:o.projection||"equirectangular",xAccessor:o.xAccessor||"lon",yAccessor:o.yAccessor||"lat",lineDataAccessor:o.lineDataAccessor,colorBy:t,colorScheme:i,customLayout:o.layout||o.customLayout,layoutConfig:o.layoutConfig,...r})},GaltonBoardChart:_p,EventDropChart:Pp,UnitPileChart:Lp,CollisionSwarmChart:$p,ProcessFlowChart:Tp,GauntletChart:Rp,CrucibleChart:Cp,PacketFlowChart:Ip,ChainReactionChart:{frameType:"physics",layout:{primarySize:{width:920,height:620}},buildProps:nl,renderStatic:function(e,t){let{data:i,common:r,rest:o}=function(e){return e.__composite}(e),a=Array.isArray(y=i)?y.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[],[n,l]=r.size??[920,620],s="string"==typeof r.title?r.title:"Dependency chain reaction",c=function(e){let t=[],i=new Map,r=[],o=new Set;e.data.forEach((a,n)=>{let l=(el(a,n,e.taskIDAccessor)??"")+"";if(!l)return void t.push({code:"duplicate-task-id",message:`Task row ${n} has an empty id.`,taskIDs:[]});if(i.has(l))return void t.push({code:"duplicate-task-id",message:`Task id "${l}" occurs more than once.`,taskIDs:[l]});let s=(el(a,n,e.laneAccessor)??"Unassigned")+"";o.has(s)||(o.add(s),r.push(s));let c=el(a,n,e.dependencyAccessor)??[],u=Array.from(new Set(Array.from(c,e=>e+""))).sort(tl),d=el(a,n,e.blockerAccessor),h=el(a,n,e.statusAccessor)??(d?"blocked":"waiting");i.set(l,{id:l,label:(el(a,n,e.labelAccessor)??l)+"",lane:s,laneIndex:0,level:0,index:n,datum:a,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:el(a,n,e.startAccessor),end:el(a,n,e.endAccessor),progress:ol(el(a,n,e.progressAccessor)),status:h,completionTime:el(a,n,e.completionTimeAccessor),blockerReason:d||void 0,milestone:!!el(a,n,e.milestoneAccessor)})});let a=e.laneOrder?[...e.laneOrder,...r.filter(t=>!e.laneOrder?.includes(t))]:r,n=new Map(a.map((e,t)=>[e,t]));for(let e of i.values())e.laneIndex=n.get(e.lane)??0;let l=new Map,s=new Map;for(let e of i.keys())l.set(e,[]),s.set(e,[]);let c=[],u=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of u)e.dependencyIDs.forEach((r,o)=>{let a=i.get(r);if(!a)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${r}".`,taskIDs:[e.id,r]});let n={id:il(r,e.id),sourceID:r,targetID:e.id,sourceIndex:a.index,targetIndex:e.index,socketID:rl(e.id,o),socketIndex:o};c.push(n),l.get(e.id)?.push(n),s.get(r)?.push(n),e.incomingEdgeIDs.push(n.id),e.socketIDs.push(n.socketID),a.outgoingEdgeIDs.push(n.id)});for(let e of l.values())e.sort((e,t)=>tl(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=rl(e.targetID,t)});for(let e of s.values())e.sort((e,t)=>tl(e.targetID,t.targetID));for(let e of i.values()){let t=l.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(s.get(e.id)??[]).map(e=>e.id)}let d=new Map,h=new Map;for(let e of i.keys())d.set(e,l.get(e)?.length??0),h.set(e,0);let f=[...i.keys()].filter(e=>0===d.get(e)).sort(tl),p=0;for(;f.length;){let e=f.shift();p+=1;for(let t of s.get(e)??[]){let i=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,i);let r=(d.get(t.targetID)??0)-1;if(d.set(t.targetID,r),0===r){let e=f.findIndex(e=>e>t.targetID);0>e?f.push(t.targetID):f.splice(e,0,t.targetID)}}}if(p!==i.size){let e=[...i.keys()].filter(e=>(d.get(e)??0)>0).sort(tl);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let y=0,g=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of g)e.level=h.get(e.id)??0,y=Math.max(y,e.level);return{nodes:g,edges:c,byID:i,incoming:l,outgoing:s,lanes:a,maxLevel:y,diagnostics:t,valid:0===t.length}}({data:a,taskIDAccessor:o.taskIDAccessor,labelAccessor:o.labelAccessor,laneAccessor:o.laneAccessor,dependencyAccessor:o.dependencyAccessor,startAccessor:o.startAccessor,endAccessor:o.endAccessor,progressAccessor:o.progressAccessor,statusAccessor:o.statusAccessor,completionTimeAccessor:o.completionTimeAccessor,blockerAccessor:o.blockerAccessor,milestoneAccessor:o.milestoneAccessor}),u=le(r.theme),d=se(u),h=jn(r),f=h+"-title",p=h+"-description";var y;if(!c.valid){let e=c.diagnostics.map(e=>e.message).join(" "),i=Ug.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:n,height:l,role:"img","aria-labelledby":`${f} ${p}`,style:{fontFamily:d.fontFamily},children:[Qg("title",{id:f,children:s}),Qg("desc",{id:p,children:e}),Qg("rect",{width:n,height:l,fill:d.background}),Qg("text",{x:24,y:36,fontSize:16,fontWeight:700,fill:d.text,children:s}),c.diagnostics.map((e,t)=>Qg("text",{x:24,y:72+22*t,fontSize:12,fill:u.colors.error,children:e.message},`${e.code}-${t}`))]}));return t&&(t.evidence=Pa({frameType:"physics",width:n,height:l,parts:[],title:s,description:e,nodeCount:c.nodes.length,edgeCount:c.edges.length,extraWarnings:["INVALID_DEPENDENCY_GRAPH"]})),i}let g=function(e,t,i={}){let r=Math.max(240,t.width),o=Math.max(220,t.height),a=t.paddingX??48,n=t.paddingTop??48,l=t.paddingBottom??44,s=Math.max(70,(r-2*a)/Math.max(1,e.lanes.length)),c=Math.max(76,(o-n-l)/Math.max(1,e.maxLevel+1)),u=Math.min(i.taskWidth??112,Math.max(58,.78*s)),d=Math.min(i.taskHeight??58,.64*c),h=i.socketRadius??5,f=Math.max(1,Math.round(i.gutterCount??3)),p=new Map;for(let t of e.nodes){let e=`${t.laneIndex}:${t.level}`,i=p.get(e)??[];i.push(t),p.set(e,i)}for(let e of p.values())e.sort((e,t)=>tl(e.id,t.id));let y=.86*c,g=e.nodes.map(e=>{let t=p.get(`${e.laneIndex}:${e.level}`)??[e],i=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,r=(o=t.length)>1?Math.max(22,Math.min(d,(y-4*(o-1))/o)):d;var o;return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:a+s*(e.laneIndex+.5),y:n+c*(e.level+.5)+i*(r+4),width:u,height:r}}),m=new Map(g.map(e=>[e.taskID,e])),x=[],b=[];e.edges.forEach((t,i)=>{let r=m.get(t.sourceID),o=m.get(t.targetID);if(!r||!o)return;let a=e.incoming.get(t.targetID)??[],n=Math.min(.72*o.width,14*Math.max(1,a.length-1)),l=a.length>1?o.x-n/2+n*t.socketIndex/(a.length-1):o.x,s=o.y-o.height/2-h-2;x.push({id:t.socketID,edgeID:t.id,taskID:o.taskID,index:t.socketIndex,x:l,y:s,radius:h});let c={x:r.x,y:r.y+r.height/2+3},u=Math.min(s-10,c.y+.48*Math.max(18,s-c.y)+7*(i%f-(f-1)/2));var d;b.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:(d=[c,{x:c.x,y:u},{x:l,y:u},{x:l,y:s}],d.filter((e,t)=>{let i=d[t-1];return!i||i.x!==e.x||i.y!==e.y}))})});let v=new Map(x.map(e=>[e.id,e])),w=new Map(b.map(e=>[e.edgeID,e]));return{tasks:g,sockets:x,routes:b,taskByID:m,socketByID:v,routeByEdgeID:w}}(c,{width:n,height:l}),m=function(e,t,i){let r=e.nodes.map(Qn).filter(e=>null!=e),o=i,a=new Set,n=new Map;for(let t of e.nodes){let e=Qn(t);(null!=e&&o>=e||"done"===t.status&&!0)&&a.add(t.id),t.blockerReason&&!a.has(t.id)&&n.set(t.id,t.blockerReason)}let l=new Set;for(let t of e.edges)a.has(t.sourceID)&&l.add(t.id);return{currentTime:o,playing:!1,completed:a,delivered:l,inFlight:new Set,armed:Jn(e,l,n,a),blockers:n,previewTaskID:null}}(c,0,Kn(o.currentTime,1/0)),x=Array.isArray(o.selectedTaskIDs)?o.selectedTaskIDs.map(String):[],b=new Set(x),v=x[0]??null,w=v&&"none"!==o.insight?al(c,v,{completedTaskIDs:m.completed}):null,k=new Set(w?.downstreamTaskIDs??[]),A=function(e){return"number"==typeof e&&Number.isFinite(e)?e:31}(o.seed),S=function(e,t,i){let r="string"==typeof i?i:"Tasks are arranged by workstream and dependency depth. Completed tasks deliver their authored prerequisites; task completion remains an explicit data event.",o=[...t.blockers.keys()].map(i=>{let r=al(e,i,{completedTaskIDs:t.completed});return`${e.byID.get(i)?.label??i} affects ${r.downstreamTaskCount} unfinished tasks across ${r.affectedLaneCount} lanes.`}).join(" ");return o?`${r} ${o}`:r+" No explicit blockers are active."}(c,m,r.description),M=Ug.renderToStaticMarkup(Qg(Zn,{machine:c,layout:g,runtime:m,downstreamSet:k,selectedSet:b,width:n,height:l,seed:A,reduced:!0,onSelectTask:()=>{}})),_=void 0===r.theme?{}:su(u),P=Ug.renderToStaticMarkup(Jg("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:n,height:l,role:"img","aria-labelledby":`${f} ${p}`,style:{..._,fontFamily:d.fontFamily},children:[Qg("title",{id:f,children:s}),Qg("desc",{id:p,children:S}),Qg("rect",{width:n,height:l,fill:d.background}),Qg("text",{x:n/2,y:22,textAnchor:"middle",fontSize:d.titleFontSize,fontFamily:d.titleFontFamily,fontWeight:d.titleFontWeight,fill:d.text,children:s}),Qg("g",{dangerouslySetInnerHTML:{__html:M}})]}));return t&&(t.evidence=Pa({frameType:"physics",width:n,height:l,parts:[],additionalMarkCountByType:{task:c.nodes.length,dependency:c.edges.length},title:s,description:S,categories:c.lanes,nodeCount:c.nodes.length,edgeCount:c.edges.length})),P}},PhysicsCustomChart:Dp};import*as am from"react";import{jsx as nm}from"react/jsx-runtime";var lm=new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);import*as sm from"react-dom/server";import{scaleBand as cm,scaleLinear as um}from"d3-scale";var dm=class{constructor(){this.colorSchemeMap=new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,i){if(t&&"function"==typeof e.pieceStyle){let r=e.pieceStyle(t,i);return r&&!r.fill&&i?{...r,fill:this.getColorFromScheme(e,i)}:r}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&i?{fill:X(e.barColors,i)??"#007bff"}:{fill:i?this.getColorFromScheme(e,i):"#007bff"}}resolveSummaryStyle(e,t,i){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,i):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){let i=this.colorSchemeMap.get(t);if(i)return i;let r=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||Xd,o=r[this.colorSchemeIndex%r.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,o),o}};import{quantileSorted as hm}from"d3-array";import{scaleLinear as fm}from"d3-scale";var pm={bar:function(e,t){let{scales:i,columns:r,config:o,getR:a,getStack:n,resolvePieceStyle:l}=e,{r:s,projection:c}=i,u=[],d="vertical"===c,h="horizontal"===c,f=o.normalize,p=[];if(n){let e=new Set;for(let t of Object.values(r))for(let i of t.pieceData){let t=n(i);e.has(t)||(e.add(t),p.push(t))}}else p.push("_default");for(let e of Object.values(r)){let t=new Map;for(let i of e.pieceData){let e=n?n(i):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});let r=t.get(e);r.total+=a(i),r.pieces.push(i)}let i=0;if(f)for(let e of t.values())i+=Math.abs(e.total);let r=0,o=0;for(let a of p){let c=t.get(a);if(!c)continue;let p=c.total;f&&i>0&&(p/=i);let y=l(c.pieces[0],n?a:e.name),g={...c.pieces[0],__aggregateValue:c.total,__pieceCount:c.pieces.length,category:e.name};if(d){let t=s(0>p?o:r+p),i=0>p?s(o+p)-s(o):s(r)-s(r+p);u.push(Io(e.x,t,e.width,Math.abs(i),y,g,a)),0>p?o+=p:r+=p}else if(h){let t=s(0>p?o+p:r),i=0>p?s(o)-s(o+p):s(r+p)-s(r);u.push(Io(t,e.x,Math.abs(i),e.width,y,g,a)),0>p?o+=p:r+=p}}}let y="vertical"===c;for(let e of u){if("rect"!==e.type)continue;let t=e.datum?.__aggregateValue??0;e.roundedEdge=y?0>t?"bottom":"top":0>t?"left":"right",o.gradientFill&&(e.fillGradient=o.gradientFill)}if(void 0!==o.roundedTop){let e=new Map;for(let t of u){if("rect"!==t.type)continue;let i=t.datum?.category||"";e.has(i)||e.set(i,[]),e.get(i).push(t)}for(let t of e.values()){if(0===t.length)continue;let e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),i=t.filter(e=>0>(e.datum?.__aggregateValue??0));if(e.length>0){let t=e.reduce(y?(e,t)=>t.y>e.y?e:t:(e,t)=>e.x+e.w>t.x+t.w?e:t),i=pl(o.roundedTop,t,y);i>0&&(t.roundedTop=i)}if(i.length>0){let e=i.reduce(y?(e,t)=>e.y+e.h>t.y+t.h?e:t:(e,t)=>t.x>e.x?e:t),t=pl(o.roundedTop,e,y);t>0&&(e.roundedTop=t)}}}return u},clusterbar:function(e,t){let{scales:i,columns:r,config:o,getR:a,getGroup:n,resolvePieceStyle:l}=e,{r:s,projection:c}=i,u=[],d="vertical"===c,h=[],f=new Set;for(let e of Object.values(r))for(let t of e.pieceData){let e=n?n(t):"_default";f.has(e)||(f.add(e),h.push(e))}let p=h.length||1;for(let e of Object.values(r)){let t=e.width/p,i=.2*t,r=t-i,o=new Map;for(let t of e.pieceData){let e=n?n(t):"_default";o.has(e)||o.set(e,[]),o.get(e).push(t)}for(let n=0;h.length>n;n++){let c=o.get(h[n])||[];for(let o of c){let c=a(o),f=l(o,h[n]);if(d){let a=e.x+n*t+i/2,l=s(0),d=s(c);u.push(Io(a,Math.min(l,d),r,Math.abs(l-d),f,o,h[n]))}else{let a=e.x+n*t+i/2,l=s(0),d=s(c);u.push(Io(Math.min(l,d),a,Math.abs(d-l),r,f,o,h[n]))}}}}for(let e of u){if("rect"!==e.type||null==e.datum)continue;let t=a(e.datum),i=pl(o.roundedTop,e,d);i>0&&(e.roundedTop=i),e.roundedEdge=d?0>t?"bottom":"top":0>t?"left":"right",o.gradientFill&&(e.fillGradient=o.gradientFill)}return u},point:function(e,t){let{scales:i,columns:r,getR:o,multiScales:a,resolvePieceStyle:n}=e,{r:l,projection:s}=i,c=[],u="vertical"===s,d="radial"===s,h=a.length>0,f=yl(e),p=2*Math.PI,y=-Math.PI/2;for(let e of Object.values(r))for(let t of e.pieceData){let i,r,s=t.__rIndex??0,g=t.__rValue??o(t),m=h&&a[s]||l,x=n(t,e.name),b=x.r||5;if(d){let t=y+(e.pctStart+e.pct/2)*p,o=m(g);i=Math.cos(t)*o,r=Math.sin(t)*o}else u?(i=e.middle,r=m(g)):(i=m(g),r=e.middle);gl(c,f,t,i,r,b,x)}return c},swarm:function(e,t){let{scales:i,columns:r,getR:o,resolvePieceStyle:a}=e,{r:n,projection:l}=i,s=[],c="vertical"===l,u=yl(e);for(let e of Object.values(r)){let t=e.width/2;for(let i=0;e.pieceData.length>i;i++){let r=e.pieceData[i],l=o(r),d=a(r,e.name),h=d.r||4,f=(7919*i%100/100-.5)*t*.8;gl(s,u,r,c?e.middle+f:n(l),c?n(l):e.middle+f,h,d)}}return s},pie:ml,donut:ml,boxplot:function(e,t){let{scales:i,columns:r,config:o,getR:a,resolveSummaryStyle:n}=e,{r:l,projection:s}=i,c=[],u="vertical"===s,d=!1!==o.showOutliers;for(let t of Object.values(r)){let i=t.pieceData.map(e=>a(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===i.length)continue;let r=bl(i),{min:o,max:s,q1:h,median:f,q3:p}=r,y=p-h,g=h-1.5*y,m=p+1.5*y,x=i.find(e=>e>=g)??o,b=s;for(let e=i.length-1;e>=0;e--)if(m>=i[e]){b=i[e];break}r.min=x,r.max=b;let v=n(xl(t.pieceData,t.name,r),t.name),w=[];if(d)for(let e of t.pieceData){let i=a(e);if(g>i||i>m){let r=u?t.middle:l(i),o=u?l(i):t.middle;w.push({px:r,py:o,value:i,datum:e})}}if(c.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:l(x),q1Pos:l(h),medianPos:l(f),q3Pos:l(p),maxPos:l(b),stats:r,style:v,datum:t.pieceData,category:t.name,outliers:w}),d)for(let t of w)c.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:v.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:v.cursor},datum:t.datum})}return c},violin:function(e,t){let{scales:i,columns:r,config:o,getR:a,resolveSummaryStyle:n}=e,{r:l,projection:s}=i,c=[],u="vertical"===s,d=o.bins||20,h=!1!==o.showIQR;for(let e of Object.values(r)){let t=e.pieceData.map(e=>a(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;let i,r=t[0],o=t[t.length-1],s=(o-r)/d||1,f=vl(t,r,o,s,d),p=od(f,1),y=e.width/2*.9;if(u){i=`M ${e.middle} ${l(r)}`;for(let t=0;d>t;t++){let o=l(r+(t+.5)*s);i+=` L ${e.middle+f[t]/p*y} ${o}`}i+=` L ${e.middle} ${l(o)}`;for(let t=d-1;t>=0;t--){let o=l(r+(t+.5)*s);i+=` L ${e.middle-f[t]/p*y} ${o}`}i+=" Z"}else{i=`M ${l(r)} ${e.middle}`;for(let t=0;d>t;t++)i+=` L ${l(r+(t+.5)*s)} ${e.middle-f[t]/p*y}`;i+=` L ${l(o)} ${e.middle}`;for(let t=d-1;t>=0;t--)i+=` L ${l(r+(t+.5)*s)} ${e.middle+f[t]/p*y}`;i+=" Z"}let g,m=bl(t),x=n(xl(e.pieceData,e.name,m),e.name);h&&t.length>=4&&(g={q1Pos:l(m.q1),medianPos:l(m.median),q3Pos:l(m.q3),centerPos:e.middle,isVertical:u});let b=u?{x:e.x,y:Math.min(l(o),l(r)),width:e.width,height:Math.abs(l(o)-l(r))}:{x:Math.min(l(r),l(o)),y:e.x,width:Math.abs(l(o)-l(r)),height:e.width};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:b,iqrLine:g,stats:m,style:x,datum:e.pieceData,category:e.name})}return c},histogram:function(e,t){let{scales:i,columns:r,config:o,getR:a,resolveSummaryStyle:n}=e,{r:l}=i,s=[],c=o.bins||25,u=o.normalize,d=l.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(let e of Object.values(r)){let t=e.pieceData.map(e=>a(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;let[i,r]=nd(t),o=null!=h&&isFinite(h)?h:i,d=null!=f&&isFinite(f)?f:r,p=(d-o)/c||1,y=vl(t,o,d,p,c),g=t.length,m=od(y,1);for(let t=0;c>t;t++){if(0===y[t])continue;let i=(u?y[t]/g:y[t]/m)*e.width*.9,r=l(o+t*p),a=l(o+(t+1)*p),c=Math.min(r,a),d=Math.abs(a-r),h=e.x+e.width-i,f={...e.pieceData[0],bin:t,count:y[t],range:[o+t*p,o+(t+1)*p],category:e.name,data:e.pieceData},x=n(f,e.name);s.push(Io(c,h,d,i,x,f,e.name))}}return s},ridgeline:function(e,t){let{scales:i,columns:r,config:o,getR:a,resolveSummaryStyle:n}=e,{r:l,projection:s}=i,c=[],u=o.bins||20,d="horizontal"===s,h=o.amplitude||1.5;for(let e of Object.values(r)){let t=e.pieceData.map(e=>a(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(2>t.length)continue;let i,r=t[0],o=t[t.length-1],s=(o-r)/u||1,f=vl(t,r,o,s,u),p=od(f,1),y=bl(t),g=n(xl(e.pieceData,e.name,y),e.name),m=e.width*h;if(d){let t=e.x+e.width;i=`M ${l(r)} ${t}`;for(let e=0;u>e;e++)i+=` L ${l(r+(e+.5)*s)} ${t-f[e]/p*m}`;i+=` L ${l(o)} ${t} Z`}else{let t=e.x;i=`M ${t} ${l(r)}`;for(let e=0;u>e;e++){let o=l(r+(e+.5)*s);i+=` L ${t+f[e]/p*m} ${o}`}i+=` L ${t} ${l(o)} Z`}let x=d?{x:Math.min(l(r),l(o)),y:e.x,width:Math.abs(l(o)-l(r)),height:e.width}:{x:e.x,y:Math.min(l(o),l(r)),width:e.width,height:Math.abs(l(o)-l(r))};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:x,stats:y,style:{...g,fillOpacity:g.fillOpacity??.5},datum:e.pieceData,category:e.name})}return c},timeline:function(e,t){let{scales:i,columns:r,getRawRange:o,resolvePieceStyle:a}=e,{r:n,projection:l}=i,s=[],c="horizontal"===l;for(let e of Object.values(r))for(let t of e.pieceData){let i=o(t);if(!i)continue;let[r,l]=i,u=a(t,e.name);if(c){let i=n(Math.min(r,l)),o=n(Math.max(r,l));s.push(Io(i,e.x,o-i,e.width,u,t,e.name))}else{let i=n(Math.max(r,l)),o=n(Math.min(r,l));s.push(Io(e.x,i,e.width,o-i,u,t,e.name))}}return s},funnel:function(e,t){let{columns:i,getR:r,getStack:o,resolvePieceStyle:a}=e,n=[],l=t.width/2,s=!1!==e.config.showLabels,c=e.scales.o.domain().map(e=>i[e]).filter(Boolean);if(0===c.length)return n;let u=[],d=new Set;for(let e of c)for(let t of e.pieceData){let e=o?o(t):"_default";d.has(e)||(d.add(e),u.push(e))}let h=u.length>1&&"_default"!==u[0],f=[],p=0;for(let e of c){let t=new Map,i=0;for(let a of e.pieceData){let e=o?o(a):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});let n=t.get(e),l=r(a);n.total+=l,n.pieces.push(a),i+=l}f.push({col:e,groups:t,stepTotal:i}),h||i>p&&(p=i)}if(h)for(let e of f){let t=0,i=0;for(let r=0;u.length>r;r++){let o=e.groups.get(u[r]);o&&(r%2==0?t+=o.total:i+=o.total)}let r=Math.max(t,i);r>p&&(p=r)}if(0===p)return n;let y=new Map;for(let e of u){let t=f[0].groups.get(e);y.set(e,t?.total??0)}let g=f[0].stepTotal,m=h?.95*l:.9*t.width,x=fm().domain([0,p]).range([0,m]),b=e.config.connectorOpacity??.3,v=new Map;for(let t=0;f.length>t;t++){let i=f[t],r=i.col,o=0===t,c=r.width,d=.55*c,p=r.x+(c-d)/2,m=new Map;if(h){let e=0;for(let t of u){let r=i.groups.get(t);r&&(e+=x(r.total))}let t=l,c=l;for(let h=0;u.length>h;h++){let f=u[h],g=i.groups.get(f);if(!g)continue;let b=x(g.total),v=h%2==0,w=v?t:c-b;v?t+=b:c-=b;let k=a(g.pieces[0],f),A=y.get(f)??g.total,S={...g.pieces[0],__funnelValue:g.total,__funnelPercent:A>0?g.total/A*100:0,__funnelStep:r.name,__funnelIsFirstStep:o,__aggregateValue:g.total,__pieceCount:g.pieces.length,category:f};s&&(0===h&&(S.__funnelStepLabel=r.name,S.__funnelStepLabelX=l,S.__funnelStepLabelY=p,S.__funnelRowWidth=e),S.__funnelValueLabelX=w+b/2,S.__funnelValueLabelY=p,S.__funnelBarW=b),n.push(Io(w,p,b,d,k,S,f)),m.set(f,{x:w,y:p,w:b,h:d})}}else{let e=i.stepTotal,t=x(e),c=l-t/2,h=u[0],f="_default"!==h,y=i.groups.get(h)?.pieces[0]??r.pieceData[0],b=f?h:r.name,v=a(y,b),w=g>0?e/g*100:0,k={...y,__funnelValue:e,__funnelPercent:w,__funnelStep:r.name,__funnelIsFirstStep:o,category:f?h:r.name};s&&(k.__funnelStepLabel=r.name,k.__funnelStepLabelX=l,k.__funnelStepLabelY=p,k.__funnelRowWidth=t,k.__funnelValueLabelX=l,k.__funnelValueLabelY=p,k.__funnelBarW=t),n.push(Io(c,p,t,d,v,k,b)),m.set(h,{x:c,y:p,w:t,h:d})}if(t>0&&v.size>0){let t=h?u:[u[0]];for(let o of t){let t=v.get(o),l=m.get(o);if(!t||!l)continue;let s=(()=>{let e=i.groups.get(o);return a(e?e.pieces[0]:r.pieceData[0],"_default"===o?r.name:o)})(),c={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[l.x+l.w,l.y],[l.x,l.y]],style:{fill:s.fill||e.config.themeSemantic?.secondary||"#999",opacity:b,cursor:s.cursor},datum:i.groups.get(o)?.pieces[0]??r.pieceData[0],category:"_default"===o?r.name:o};n.push(c)}}v=m}return n},"bar-funnel":function(e,t){let{columns:i,getR:r,getStack:o,resolvePieceStyle:a,scales:n}=e,l=[],s=n.o.domain().map(e=>i[e]).filter(Boolean);if(0===s.length)return l;let c=[],u=new Set;for(let e of s)for(let t of e.pieceData){let e=o?o(t):"_default";u.has(e)||(u.add(e),c.push(e))}let d=c.length>1&&"_default"!==c[0],h=[];for(let e of s){let t=new Map,i=0;for(let a of e.pieceData){let e=o?o(a):"_default";t.has(e)||t.set(e,{total:0,pieces:[]});let n=t.get(e),l=r(a);n.total+=l,n.pieces.push(a),i+=l}h.push({col:e,groups:t,stepTotal:i})}let f=new Map;for(let e of c){let t=h[0]?.groups.get(e);f.set(e,t?.total??0)}let p=n.r,y=d?c.length:1,g=d?.15:0;for(let e=0;h.length>e;e++){let t=h[e],i=t.col,r=0===e,o=e>0?h[e-1]:null,n=i.width/y,s=n*g,u=n-s;for(let e=0;c.length>e;e++){let h=c[e],y=t.groups.get(h);if(!y)continue;let g=y.total,m=f.get(h)??g,x=m>0?g/m*100:0,b=o?.groups.get(h)?.total??g,v=r?0:Math.max(0,b-g),w=i.x+e*n+s/2,k=p(g),A=p(0)-k,S=a(y.pieces[0],d?h:i.name),M={...y.pieces[0],__barFunnelValue:g,__barFunnelPercent:x,__barFunnelIsFirstStep:r,__barFunnelIsDropoff:!1,__barFunnelStep:i.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:i.name,__barFunnelLabelX:w+u/2,__barFunnelLabelY:p(g+v)};if(l.push(Io(w,k,u,A,S,M,d?h:i.name)),v>0){let e=p(g+v),t=k-e,r={...S},o={...y.pieces[0],__barFunnelValue:v,__barFunnelPercent:m>0?v/m*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:i.name,__barFunnelCategory:"_default"===h?void 0:h,category:d?h:i.name};l.push(Io(w,e,u,t,r,o,d?h:i.name))}}}return l},swimlane:function(e,t){let{scales:i,columns:r,getR:o,getStack:a,resolvePieceStyle:n}=e,{r:l,projection:s}=i,c=[],u="horizontal"===s,d=e.config.gradientFill,h=u?"left":"bottom",f=new Map,p=t=>{let i=f.get(t);if(void 0!==i)return i;let r="function"==typeof e.config.roundedTop?e.config.roundedTop(t.width):e.config.roundedTop,o="number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0;return f.set(t,o),o},y=e.config.trackFill;if(y){let e="string"==typeof y?y:y.color,t="string"==typeof y?1:y.opacity??1,[i,o]=l.range(),a=Math.min(i,o),n=Math.abs(o-i);for(let i of Object.values(r)){let r={fill:e,opacity:t},o=u?Io(a,i.x,n,i.width,r,null,"__track__"):Io(i.x,a,i.width,n,r,null,"__track__"),l=p(i);l>0&&(o.cornerRadii={tl:l,tr:l,br:l,bl:l}),c.push(o)}}for(let e of Object.values(r)){let t=0,i=c.length,r=p(e);for(let i of e.pieceData){let r=Math.abs(o(i));if(0===r)continue;let s,f=a?a(i):e.name,p=n(i,f);if(u){let o=l(t),a=l(t+r);s=Io(o,e.x,a-o,e.width,p,i,f)}else{let o=l(t+r),a=l(t);s=Io(e.x,o,e.width,a-o,p,i,f)}d&&(s.fillGradient=d,s.roundedEdge=h),c.push(s),t+=r}if(r>0&&c.length>i){let e=c.slice(i),t=e[0],o=e[e.length-1];1===e.length?t.cornerRadii={tl:r,tr:r,br:r,bl:r}:u?(t.cornerRadii={tl:r,bl:r},o.cornerRadii={tr:r,br:r}):(t.cornerRadii={bl:r,br:r},o.cornerRadii={tl:r,tr:r})}}return c}},ym=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],gm=["scene-style","data-paint","accessibility","evidence"],mm=(e,t)=>({retainedData:e,invalidations:t}),xm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],bm=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],vm=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],wm=["scene-geometry","data-paint","accessibility","evidence"],km=["scene-style","data-paint","accessibility","evidence"],Am=[],Sm={chartType:mm("rebuild",xm),runtimeMode:mm("rebuild",xm),categoryAccessor:mm("rebuild",xm),valueAccessor:mm("rebuild",xm),oAccessor:mm("rebuild",xm),rAccessor:mm("rebuild",xm),stackBy:mm("rebuild",xm),groupBy:mm("rebuild",xm),timeAccessor:mm("rebuild",xm),accessorRevision:mm("rebuild",xm),colorAccessor:mm("rebuild",km),symbolAccessor:mm("rebuild",wm),connectorAccessor:mm("rebuild",wm),dataIdAccessor:mm("rebuild",wm),projection:mm("preserve",bm),extentPadding:mm("preserve",bm),axisExtent:mm("preserve",bm),rExtent:mm("preserve",bm),oExtent:mm("preserve",bm),multiAxis:mm("preserve",bm),normalize:mm("preserve",bm),bins:mm("preserve",bm),oSort:mm("preserve",vm),barPadding:mm("preserve",vm),roundedTop:mm("preserve",vm),baselinePadding:mm("preserve",vm),innerRadius:mm("preserve",vm),cornerRadius:mm("preserve",vm),startAngle:mm("preserve",vm),sweepAngle:mm("preserve",vm),trackFill:mm("preserve",vm),showOutliers:mm("preserve",vm),showIQR:mm("preserve",vm),amplitude:mm("preserve",vm),connectorOpacity:mm("preserve",vm),showLabels:mm("preserve",vm),dynamicColumnWidth:mm("rebuild",vm),customLayout:mm("preserve",vm),layoutConfig:mm("preserve",vm),layoutMargin:mm("preserve",vm),symbolMap:mm("preserve",wm),pieceStyle:mm("preserve",km),summaryStyle:mm("preserve",km),connectorStyle:mm("preserve",km),gradientFill:mm("preserve",km),colorScheme:mm("preserve",km),themeCategorical:mm("preserve",km),themeSemantic:mm("preserve",km),themeSequential:mm("preserve",km),themeDiverging:mm("preserve",km),barColors:mm("preserve",km),decay:mm("preserve",km),pulse:mm("preserve",km),staleness:mm("preserve",km),layoutSelection:mm("preserve",km),windowSize:mm("preserve",Am),windowMode:mm("preserve",Am),clock:mm("preserve",Am),transition:mm("preserve",Am),introAnimation:mm("preserve",Am),onLayoutError:mm("preserve",Am)},Mm=mm("preserve",vm),_m=class{constructor(){this.tracker=new gu}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},ym)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},gm):this.recordNoop("restyle")}recordConfig(e){let t=function(e){let t="preserve",i=new Set;for(let r of e){let e=Sm[r]??Mm;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as Pm}from"d3-quadtree";var Lm=class{constructor(e){this.rExtent=new Ep,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new _m,this.rAccessors=[],this.categories=new Set,this._hasStreamingData=!1,this.styleResolver=new dm,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new Np(e.windowSize),this.getO=Uc(e.categoryAccessor||e.oAccessor,"category");let t=e.valueAccessor||e.rAccessor;Array.isArray(t)?(this.rAccessors=t.map(e=>Xc(e,"value")),this.getR=this.rAccessors[0],this.rExtents=t.map(()=>new Ep)):(this.getR=Xc(t,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Uc(e.stackBy),this.getGroup=Uc(e.groupBy),this.getColor=Uc(e.colorAccessor),this.getSymbol=Uc(e.symbolAccessor),this.getConnector=Uc(e.connectorAccessor),this.getDataId=Uc(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new Np(e.windowSize))}syncPulseTimestampBuffer(){var e,t,i,r;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,i=this.timestampBuffer,r=this.currentTime(),e?null!=i&&i.capacity===t.capacity&&i.size===t.size?i:Eo(t,r):null)}currentTime(){return this.config.clock?.()??uo()}ingest(e){let t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),No(this.buffer,e.totalSize||e.inserts.length,this.timestampBuffer);for(let i of e.inserts)Wo(this.buffer,i,this.timestampBuffer,t),this.categories.add(this.getO(i)),this.pushValueExtent(i)}else{this._hasStreamingData=!0;for(let i of e.inserts){let e=Wo(this.buffer,i,this.timestampBuffer,t);this.categories.add(this.getO(i)),this.pushValueExtent(i),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;this.rAccessors.length>t;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){let t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;let i="function"==typeof t?t(e):e[t];return Array.isArray(i)&&i.length>=2?[+i[0],+i[1]]:null}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,o=this.multiScales,a=this.columns;if(0===i.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(i,this.getR);let n,l,s=this.getBufferArray(),c=t.projection||"vertical",u=t.oExtent||this.resolveCategories(s),d=this.computeValueDomain(s,u),h="horizontal"===c,f="radial"===c,p=Math.min(.9,Math.max(0,null!=t.barPadding?t.barPadding/("vertical"===c?e.width:e.height):.1));if(f){n=cm().domain(u).range([0,1]).padding(0);let i=Math.min(e.width,e.height)/2,r=t.innerRadius||0;l=um().domain(d).range([r,i])}else h?(n=cm().domain(u).range([0,e.height]).padding(p),l=um().domain(d).range([0,e.width])):(n=cm().domain(u).range([0,e.width]).padding(p),l=um().domain(d).range([e.height,0]));this.scales={o:n,r:l,projection:c},this.multiScales=this.rAccessors.length>1&&t.multiAxis?this.rAccessors.map((r,o)=>{let a=this.rExtents[o];a.dirty&&a.recalculate(i,r);let[n,l]=a.extent;n===1/0&&(n=0,l=1);let s=l-n,c=s>0?s*(t.extentPadding??.05):1;return n-=c,l+=c,n>0&&(n=0),h?um().domain([n,l]).range([0,e.width]):um().domain([n,l]).range([e.height,0])}):[];let y=s;this.rAccessors.length>1&&(y=s.flatMap(e=>this.rAccessors.map((t,i)=>({...e,__rIndex:i,__rValue:t(e),__rName:this.resolveRAccessorName(i)})))),this.columns=this.buildColumns(y,u,n,c,e),this._customLayoutFailedThisBuild=!1;let g=this.buildSceneNodes(y,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.multiScales=o,this.columns=a):(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(e){let t=this.config.valueAccessor||this.config.rAccessor,i=Array.isArray(t)?t[e]:t;return"string"==typeof i?i:"value"+e}resolveCategories(e){let t=this.config.oSort,i="streaming"===this.config.runtimeMode||this._hasStreamingData,r="auto"===t?void 0:t,o=null;if(i){o=new Set;for(let t of e)o.add(this.getO(t))}let a=o?Array.from(this.categories).filter(e=>o.has(e)):Array.from(this.categories);if(i&&void 0===r){let e=Math.max(50,3*o.size);if(this.categories.size>e){let t=this.categories.size-e;for(let e of this.categories){if(0>=t)break;o.has(e)||(this.categories.delete(e),t--)}}return a}if(!1===r)return a;if("function"==typeof r)return a.sort(r);let n=new Map;for(let t of e){let e=this.getO(t);n.set(e,(n.get(e)||0)+Math.abs(this.getR(t)))}return a.sort("asc"===r?(e,t)=>(n.get(e)||0)-(n.get(t)||0):(e,t)=>(n.get(t)||0)-(n.get(e)||0))}computeValueDomain(e,t){return function(e){let{data:t,chartType:i,projection:r,normalize:o,rExtent:a,extentPadding:n=.05,baselinePadding:l,axisExtent:s,getO:c,getR:u,getStack:d,rawRExtent:h}=e,f=n;if("radial"===r&&("pie"===i||"donut"===i))return[0,1];let p=0,y=0;if("bar"===i&&d&&o)p=0,y=1;else if("bar"===i&&d){let e=new Map,i=new Map;for(let r of t){let t=c(r),o=u(r);0>o?i.set(t,(i.get(t)||0)+o):e.set(t,(e.get(t)||0)+o)}for(let t of e.values())t>y&&(y=t);for(let e of i.values())p>e&&(p=e)}else if("bar"===i){let e=new Map;for(let i of t){let t=c(i),r=u(i);e.set(t,(e.get(t)||0)+r)}for(let t of e.values())t>y&&(y=t),p>t&&(p=t)}else if("swimlane"===i){let e=new Map;for(let i of t){let t=c(i),r=Math.abs(u(i));e.set(t,(e.get(t)||0)+r)}for(let t of e.values())t>y&&(y=t)}else if("clusterbar"===i||"bar-funnel"===i)for(let e of t){let t=u(e);t>y&&(y=t),p>t&&(p=t)}else{let e=h[0],t=h[1];e!==1/0&&(p=e),t!==-1/0&&(y=t)}a&&(null!=a[0]&&(p=a[0]),null!=a[1]&&(y=a[1]));let g="bar"===i||"clusterbar"===i||"bar-funnel"===i||"swimlane"===i;if(g&&(null!=a?.[0]||null!=a?.[1]||(p>0&&(p=0),0>y&&(y=0))),"bar-funnel"!==i&&"exact"!==s){let e=y-p,t=e>0?e*f:1,r=g&&!l&&0===p,o=g&&!l&&0===y||"swimlane"===i;null==a?.[0]&&!r&&(p-=t),null==a?.[1]&&!o&&(y+=t)}return[p,y]}({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,i,r,o){return function(e){let{data:t,oExtent:i,oScale:r,projection:o,layout:a,dynamicColumnWidth:n,getO:l,getR:s}=e,c=Object.create(null),u=new Map;for(let e of t){let t=l(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===o)for(let e of t)d+=Math.abs(s(e));let h=null;if(n&&"radial"!==o){h=new Map;let e=0;for(let t of i){let i,r=u.get(t)||[];i="string"==typeof n?r.reduce((e,t)=>e+(Number(t[n])||0),0):n(r),h.set(t,i),e+=i}let t=("horizontal"===o?a.height:a.width)-r.padding()*r.step()*i.length;if(e>0)for(let[i,r]of h)h.set(i,r/e*t)}let f=0,p=0;for(let e of i){let t,i,o=u.get(e)||[],a=o.reduce((e,t)=>e+Math.abs(s(t)),0),n=d>0?a/d:0;h?(t=p,i=h.get(e)||r.bandwidth(),p+=i+r.padding()*r.step()):(t=r(e)??0,i=r.bandwidth()),c[e]={name:e,x:t,y:0,width:i,middle:t+i/2,padding:r.padding()*r.step(),pieceData:o,pct:n,pctStart:f},f+=n}return c}({data:e,oExtent:t,oScale:i,projection:r,layout:o,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){let i=this.buildLayoutContext(e,t),r=Ao({family:"ordinal",logLabel:"ordinal customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:this.config.onLayoutError,run:()=>this.config.customLayout(i)});if("failure"===r.kind)return this.lastCustomLayoutFailure=r.diagnostic,this._customLayoutFailedThisBuild=!0,r.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let o=r.result;this.customLayoutOverlays=o.overlays??null,this.lastCustomLayoutResult=o,this.lastCustomLayoutFailure=null;let a=o.nodes??[];if(this._customRestyle=o.restyle,this.hasCustomRestyle=!!o.restyle,this.hasCustomRestyle){this._baseStyles=new WeakMap;for(let e of a)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(a,this.config.layoutSelection??null)}return vo({label:"ordinal customLayout",nodes:a,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),a}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;let i=this.getSceneContext(),r=pm[this.config.chartType],o=r?r(i,t):[];return this.getConnector&&this.scales&&(o=[...fl(i,o),...o]),o}buildLayoutContext(e,t){let i=this.config,r=i.layoutMargin??{top:0,right:0,bottom:0,left:0},o=$i(i.colorScheme,i.themeCategorical,Xd),a=this.scales;return{data:e,scales:{o:a.o,r:a.r,projection:a.projection},dimensions:{width:t.width,height:t.height,margin:r,plot:"radial"===a.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height}},theme:{semantic:i.themeSemantic??{},categorical:[...o]},resolveColor:Ti(o,i.colorScheme),config:i.layoutConfig??{},selection:i.layoutSelection??null}}computeDecayOpacity(e,t){let i=this.config.decay;return i&&t>1?ho(i,e,t):1}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;let t=fo(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;let t=function(e,t){let i="function"==typeof t,r=i?null:t||"category",o=new Map;for(let a=0;e.length>a;a++){let n=e[a],l=i?t(n):n[r],s=o.get(l);s?s.push(a):o.set(l,[a])}return o}(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){let e=function(e){let t=0,i=0;for(let r of e)"point"===r.type&&!1!==r.interactive&&(t++,r.r>i&&(i=r.r));if(500>=t)return{quadtree:null,maxRadius:i};let r=Array(t),o=0;for(let t of e)"point"===t.type&&!1!==t.interactive&&(r[o++]=t);return{maxRadius:i,quadtree:Pm().x(e=>e.x).y(e=>e.y).addAll(r)}}(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;let i=t.length;if(1>=i)return;let r=this.getDatumIndexMap(t);for(let t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type||!t.datum)continue;let e=r.get(t.datum);if(null==e)continue;let o=this.computeDecayOpacity(e,i);t.style={...t.style,opacity:(t.style?.opacity??1)*o}}}applyPulse(e,t,i=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&function(e,t,i,r,o,a){let n=e.color??"rgba(255,255,255,0.6)",l=e.glowRadius??4,s=!1;for(let c of t){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){let t=c.category;if(!t)continue;let r=0;for(let n of o(t)??[]){let t=i.get(n);null!=t&&(r=Math.max(r,po(e,t,a)))}s=yo(c,r,n)||s;continue}if(null==c.datum)continue;let t=r.get(c.datum);if(null==t)continue;let u=i.get(t);s=yo(c,null==u?0:po(e,u,a),n,l)||s}return s}(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),i)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&go(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();let e,t=new Map,i=this.scales?.r(0)??0,r="horizontal"!==this.scales?.projection;for(let o=0;this.scene.length>o;o++){let a=this.scene[o],n=this.getNodeKey(a,t);n&&("rect"===a.type?this.prevPositionMap.set(n,r?{x:a.x,y:i,w:a.w,h:0,opacity:a.style.opacity??1}:{x:i,y:a.y,w:0,h:a.h,opacity:a.style.opacity??1}):"point"===a.type?this.prevPositionMap.set(n,{x:a.x,y:a.y,r:0,opacity:0}):"wedge"===a.type&&(void 0===e&&(e=a.startAngle),this.prevPositionMap.set(n,{x:a.cx,y:a.cy,startAngle:e,endAngle:e,innerRadius:a.innerRadius,outerRadius:a.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){let i=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,r=t.get(i)||0;return t.set(i,r+1),`${i}:${r}`}if("rect"===e.type){let i=e.datum?null!=e.datum.category&&""!==e.datum.category?e.datum.category+"":(this.getO(e.datum)??"")+"":"",r=`r:${e.group||""}:${i}`,o=t.get(r)||0;return t.set(r,o+1),0===o?r:`${r}:${o}`}return"wedge"===e.type?"w:"+(e.category??""):null}snapshotPositions(){this.prevPositionMap.clear();let e=new Map;for(let t=0;this.scene.length>t;t++){let i=this.scene[t],r=this.getNodeKey(i,e);r&&("point"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,r:i.r,opacity:i.style.opacity??i.style.fillOpacity}):"rect"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,w:i.w,h:i.h,opacity:i.style.opacity??i.style.fillOpacity}):"wedge"===i.type&&this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:i.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;let e=this.config.transition.duration??300;if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1,i=new Set,r=new Map;for(let e=0;this.scene.length>e;e++){let o=this.scene[e],a=this.getNodeKey(o,r);if(!a)continue;o._transitionKey=a;let n=this.prevPositionMap.get(a);if("point"===o.type)n?(i.add(a),o._targetOpacity=o.style.opacity??o.style.fillOpacity??1,(n.x!==o.x||n.y!==o.y||void 0!==n.r&&n.r!==o.r)&&(o._targetX=o.x,o._targetY=o.y,o._targetR=o.r,o.x=n.x,o.y=n.y,void 0!==n.r&&(o.r=n.r),t=!0)):(o._targetOpacity=o.style.opacity??o.style.fillOpacity??1,o._targetR=o.r,o.r=0,o.style={...o.style,opacity:0},t=!0);else if("rect"===o.type)n?(i.add(a),o._targetOpacity=o.style.opacity??o.style.fillOpacity??1,(n.x!==o.x||n.y!==o.y||n.w!==o.w||n.h!==o.h)&&(o._targetX=o.x,o._targetY=o.y,o._targetW=o.w,o._targetH=o.h,o.x=n.x,o.y=n.y,o.w=n.w??o.w,o.h=n.h??o.h,t=!0)):(o._targetOpacity=o.style.opacity??o.style.fillOpacity??1,o.style={...o.style,opacity:0},t=!0);else if("wedge"===o.type)if(n)i.add(a),o._targetOpacity=o.style.opacity??o.style.fillOpacity??1,(n.startAngle!==o.startAngle||n.endAngle!==o.endAngle)&&(o._targetStartAngle=o.startAngle,o._targetEndAngle=o.endAngle,o.startAngle=n.startAngle,o.endAngle=n.endAngle,t=!0);else{o._targetOpacity=o.style.opacity??o.style.fillOpacity??1,o._targetStartAngle=o.startAngle,o._targetEndAngle=o.endAngle;let e=o.startAngle;o.startAngle=e,o.endAngle=e,o.style={...o.style,opacity:0},this.prevPositionMap.set(a,{x:o.cx,y:o.cy,startAngle:e,endAngle:e,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(let[e,r]of this.prevPositionMap)if(!i.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:r.x,y:r.y,r:r.r??3,style:{opacity:r.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:r.x,y:r.y,w:r.w??0,h:r.h??0,style:{opacity:r.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){let t=((r.startAngle??0)+(r.endAngle??0))/2,i={type:"wedge",cx:r.x,cy:r.y,innerRadius:r.innerRadius??0,outerRadius:r.outerRadius??100,startAngle:r.startAngle??0,endAngle:r.endAngle??0,style:{opacity:r.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(i)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(e){if(!this.activeTransition)return!1;let t=so(e,this.activeTransition),i=lo(t,"linear"===this.config.transition?.easing?"linear":"ease-out-cubic");for(let e of this.scene){let t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){let r=this.prevPositionMap.get(t);e.style.opacity=co(r?r.opacity??1:0,e._targetOpacity,i)}let r=this.prevPositionMap.get(t);void 0!==e._targetX&&r&&(e.x=co(r.x,e._targetX,i),e.y=co(r.y,e._targetY,i)),void 0!==e._targetR&&void 0!==r?.r&&(e.r=co(r.r,e._targetR,i))}else if("rect"===e.type){if(void 0!==e._targetOpacity){let r=this.prevPositionMap.get(t);e.style.opacity=co(r?r.opacity??1:0,e._targetOpacity,i)}if(void 0===e._targetX)continue;let r=this.prevPositionMap.get(t);if(!r)continue;e.x=co(r.x,e._targetX,i),e.y=co(r.y,e._targetY,i),void 0!==r.w&&(e.w=co(r.w,e._targetW,i),e.h=co(r.h,e._targetH,i))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){let r=this.prevPositionMap.get(t);e.style={...e.style,opacity:co(r?r.opacity??1:0,e._targetOpacity,i)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){let r=this.prevPositionMap.get(t);r&&void 0!==r.startAngle&&(e.startAngle=co(r.startAngle,e._targetStartAngle,i),e.endAngle=co(r.endAngle,e._targetEndAngle,i))}}}if(t>=1){for(let e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,function(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}"point"===t.type?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):void 0!==t._targetR&&(t.r=t._targetR,t._targetR=void 0):"rect"===t.type?void 0!==t._targetX&&(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):"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0)}}(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();let t=no(e),i=this.getDataId,r=e=>t.has(i(e));jo(this.buffer,this.timestampBuffer,r);let o=this.buffer.remove(r);if(0===o.length)return this.updateResults.recordNoop("remove"),o;for(let e of o)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",o.length),o}update(e,t){if(!this.getDataId)throw Error("update() requires dataIdAccessor to be configured");let i=no(e),r=this.getDataId,o=new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&o.add(t)});let a=this.buffer.update(e=>i.has(r(e)),t);if(0===a.length)return this.updateResults.recordNoop("update"),a;for(let e of a)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),o.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",a.length),a}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},o=i(r,t);r.style=o?{...e,...o}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!Tc(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!Tc(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!Tc(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let r=!1;("categoryAccessor"in e||"oAccessor"in e)&&(Tc(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=Uc(this.config.categoryAccessor||this.config.oAccessor,"category"),r=!0));let o=!1;if("valueAccessor"in e||"rAccessor"in e){let e=this.config.valueAccessor||this.config.rAccessor,i=t.valueAccessor||t.rAccessor,r=Array.isArray(e)?e:[e],a=Array.isArray(i)?i:[i];if(o=r.length!==a.length||r.some((e,t)=>!Tc(e,a[t])),o){let e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>Xc(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Ep)):(this.getR=Xc(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!Tc(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?Uc(this.config.stackBy):void 0),"groupBy"in e&&!Tc(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?Uc(this.config.groupBy):void 0),"colorAccessor"in e&&!Tc(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Uc(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!Tc(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Uc(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!Tc(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Uc(this.config.connectorAccessor):void 0),(r||o||"accessorRevision"in e&&e.accessorRevision!==t.accessorRevision)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(i)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};qo(Lm);import*as $m from"react";import*as Tm from"react";import{arc as Rm}from"d3-shape";var Cm=(e,t)=>({x:e*Math.cos(t),y:e*Math.sin(t)});import{jsx as Im,jsxs as Dm}from"react/jsx-runtime";import{jsx as zm,jsxs as Om}from"react/jsx-runtime";import{jsx as Fm,jsxs as Nm}from"react/jsx-runtime";import{Fragment as Em,jsx as Wm,jsxs as jm}from"react/jsx-runtime";import*as Bm from"react-dom/server";var Ym=Object.create(null);import{min as Xm}from"d3-array";import{min as Gm,max as Vm,sum as Hm,mean as qm,group as Um,groups as Zm}from"d3-array";import{interpolateNumber as Km}from"d3-interpolate";import{line as Qm,curveLinearClosed as Jm}from"d3-shape";var ex=e=>{let t,i,r,o,a,n,l,s,c;if("down"===e.direction)return t=e.y0-e.sankeyWidth/2,i=e.y1-e.sankeyWidth/2,r=e.y1+e.sankeyWidth/2,o=e.y0+e.sankeyWidth/2,a=e.source.x1,n=e.target.x0,l=Km(a,n),s=l(.5),c=l(.5),`M${t},${a}C${t},${s} ${i},${c} ${i},${n}L${r},${n}C${r},${c} ${o},${s} ${o},${a}Z`;let u=e.sankeyWidth/2,d=Km(e.source.x1,e.target.x0),{pathD:h}=Zt({sx:e.source.x1,sTop:e.y0-u,sBot:e.y0+u,tx:e.target.x0,tTop:e.y1-u,tBot:e.y1+u,cp1X:d(.5),cp2X:d(.5)});return h},tx=new Set,ix=new WeakMap,rx={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(Gl))-1:0},justify:Vl},ox={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){if(0===e.length)return;let o,a="vertical"===i.orientation?"down":"right",n=i.nodeAlign||"justify",l=i.nodeWidth??15,s=i.nodePaddingRatio??.05,c=i.iterations??100,u=e.map(e=>({...e})),d=t.map(e=>({...e,source:Hc(e.source),target:Hc(e.target),value:Math.sqrt(Math.max(1,e.value||1))}));o="down"===a?[[0,0],[r[1],r[0]]]:[[0,0],[r[0],r[1]]];let h=ps().extent(o).links(d).nodes(u).nodeAlign(rx[n]||Vl).nodeId(e=>e.id).nodeWidth(l).iterations(c);h.nodePaddingRatio&&h.nodePaddingRatio(s),h();{let e=1/0,t=-1/0,i=1/0,o=-1/0;for(let r of u)e>r.x0&&(e=r.x0),r.x1>t&&(t=r.x1),i>r.y0&&(i=r.y0),r.y1>o&&(o=r.y1);for(let r of d){if(!r.circular||!r.circularPathData)continue;let a=r.circularPathData,n=(r._circularWidth??r.width??0)/2;e>a.leftFullExtent-n&&(e=a.leftFullExtent-n),a.rightFullExtent+n>t&&(t=a.rightFullExtent+n),i>a.verticalFullExtent-n&&(i=a.verticalFullExtent-n),a.verticalFullExtent+n>o&&(o=a.verticalFullExtent+n)}let a=t-e,n=o-i,l=r[0],s=r[1];if(a>0&&n>0&&(0>e||0>i||t>l||o>s)){let t=Math.min(l/a,s/n),r=-e*t+(l-a*t)/2,o=-i*t+(s-n*t)/2;for(let e of u)e.x0=e.x0*t+r,e.x1=e.x1*t+r,e.y0=e.y0*t+o,e.y1=e.y1*t+o;for(let e of d)if(e.y0=e.y0*t+o,e.y1=e.y1*t+o,e.width=(e.width??0)*t,e._circularWidth&&(e._circularWidth*=t),e.circular&&e.circularPathData){let i=e.circularPathData;i.sourceX=i.sourceX*t+r,i.targetX=i.targetX*t+r,i.sourceY=i.sourceY*t+o,i.targetY=i.targetY*t+o,i.rightFullExtent=i.rightFullExtent*t+r,i.leftFullExtent=i.leftFullExtent*t+r,i.verticalFullExtent=i.verticalFullExtent*t+o,i.rightInnerExtent=i.rightInnerExtent*t+r,i.leftInnerExtent=i.leftInnerExtent*t+r,i.verticalRightInnerExtent=i.verticalRightInnerExtent*t+o,i.verticalLeftInnerExtent=i.verticalLeftInnerExtent*t+o,i.rightSmallArcRadius*=t,i.rightLargeArcRadius*=t,i.leftSmallArcRadius*=t,i.leftLargeArcRadius*=t,i.sourceWidth*=t,i.rightNodeBuffer*=t,i.leftNodeBuffer*=t,i.arcRadius*=t}}}let f=new Map;for(let t of e)f.set(t.id,t);for(let e of u){let t=f.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}let p=new Map;for(let e of t)if(e._edgeKey)p.set(e._edgeKey,e);else{let t=Hc(e.source),i=Hc(e.target);p.set(`${t}\0${i}`,e)}for(let e of d){let t=Hc(e.source),i=Hc(e.target),r=p.get(e._edgeKey?e._edgeKey:`${t}\0${i}`);if(r){r.y0=e.y0,r.y1=e.y1,r.sankeyWidth=e.width??0,r.circular=!!e.circular,r.circularPathData=e.circularPathData,r._circularWidth=e._circularWidth,r._circularStub=e._circularStub,r.path=e.path,r.circularLinkType=e.circularLinkType,r.direction=a;let o=f.get(t),n=f.get(i);o&&(r.source=o),n&&(r.target=n)}}},buildScene(e,t,i,r){let o="vertical"===i.orientation?"down":"right",a=i.nodeStyle,n=i.edgeStyle,l=i.edgeOpacity??.5,s=i.edgeColorBy||"source",c=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:vd,u=new Map;e.forEach((e,t)=>{u.set(e.id,c[t%c.length])});let d=[],h=[],f=[],p=new Map;for(let t of e){let e=t.x1-t.x0,i=t.y1-t.y0;if(0>=e||0>=i)continue;let r=a?a(gs(t,"nodeStyle")):{},n={fill:r.fill||u.get(t.id)||"#4d430c",stroke:r.stroke,strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor};p.set(t.id,("string"==typeof n.fill?n.fill:null)||u.get(t.id)||"#4d430c"),d.push("down"===o?{type:"rect",x:t.y0,y:t.x0,w:i,h:e,style:n,datum:t,id:t.id,label:t.id}:{type:"rect",x:t.x0,y:t.y0,w:e,h:i,style:n,datum:t,id:t.id,label:t.id})}let y=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(let e of y){if(!e.sankeyWidth||0>=e.sankeyWidth)continue;let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let o=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";o="function"==typeof s?s(e)||o:"target"===s?p.get(r.id)||u.get(r.id)||o:p.get(t.id)||u.get(t.id)||o;let a,c=n?n(gs(e,"edgeStyle")):{};if(e._circularStub&&e.circular&&e.circularPathData){let t=e.circularPathData,i=e.sankeyWidth/2,r=Math.max(15,Math.min(40,.33*(t.rightFullExtent-t.sourceX))),a=Math.max(15,Math.min(40,.33*(t.targetX-t.leftFullExtent))),n=c.fill||o;h.push({type:"bezier",pathD:`M${t.sourceX},${t.sourceY-i}L${t.sourceX+r},${t.sourceY-i}L${t.sourceX+r},${t.sourceY+i}L${t.sourceX},${t.sourceY+i}Z`,style:{fill:n,fillOpacity:c.fillOpacity??l,stroke:"none",opacity:c.opacity,cursor:c.cursor},datum:e,_gradient:{direction:"right",from:1,to:0,x0:t.sourceX,x1:t.sourceX+r}}),h.push({type:"bezier",pathD:`M${t.targetX},${t.targetY-i}L${t.targetX-a},${t.targetY-i}L${t.targetX-a},${t.targetY+i}L${t.targetX},${t.targetY+i}Z`,style:{fill:n,fillOpacity:c.fillOpacity??l,stroke:"none",opacity:c.opacity,cursor:c.cursor},datum:e,_gradient:{direction:"left",from:0,to:1,x0:t.targetX-a,x1:t.targetX}});continue}a=e.circular&&e.circularPathData?ys(e):ex(e),a&&h.push({type:"bezier",pathD:a,bezierCache:e.bezier,style:{fill:c.fill||o,fillOpacity:c.fillOpacity??l,stroke:c.stroke||"none",strokeWidth:c.strokeWidth,opacity:c.opacity,cursor:c.cursor},datum:e})}if(!1!==i.showLabels){let t=Vc(i.nodeLabel);for(let i of e){let e=i.x1-i.x0,a=i.y1-i.y0;if(0>=e||0>=a)continue;let n,l,s,c=t?t(i):i.id;c&&("down"===o?(n=i.y0+(i.y1-i.y0)/2,l=i.x1+14,s="start"):(r[0]/2>i.x0+e/2?(n=i.x0-6,s="end"):(n=i.x1+6,s="start"),l=i.y0+a/2),f.push({x:n,y:l,text:c+"",anchor:"down"===o?"middle":s,baseline:"middle",fontSize:11}))}}return{sceneNodes:d,sceneEdges:h,labels:f}}};$l("sankey",ox);import{forceSimulation as ax,forceCenter as nx,forceX as lx,forceY as sx,forceLink as cx,forceManyBody as ux,forceCollide as dx}from"d3-force";var hx={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){if(0===e.length)return;let o=i.forceStrength??.1,a=r[0]/2,n=r[1]/2,l=Math.max(.1,Math.min(1,Math.min(r[0],r[1])/200)),s=Math.min(.5,.06+1.8*(1-l)),c=i.__previousPositions,u=0,d=[];for(let t of e){let e=null!=t.x&&null!=t.y&&(0!==t.x||0!==t.y),i=c?.get(t.id);e?u++:i?(t.x=i.x,t.y=i.y,u++):d.push(t)}let h=u>0&&.3>=(e.length>0?d.length/e.length:1);if(h){let i=new Map;for(let t of e)i.set(t.id,t);for(let e of d){let r=ms(e.id,t,i);if(r.length>0){let t=0,i=0;for(let e of r)t+=e.x,i+=e.y;let o=xs(e.id),a=o%360*(Math.PI/180),n=(10+o%20)*l;e.x=t/r.length+n*Math.cos(a),e.y=i/r.length+n*Math.sin(a)}else{let t=xs(e.id),i=t%360*(Math.PI/180),r=(15+t%30)*l;e.x=a+r*Math.cos(i),e.y=n+r*Math.sin(i)}}}else{let t=2.399963229728653;for(let i=0;e.length>i;i++){let r=e[i];if(null==r.x||null==r.y||0===r.x&&0===r.y){let e=10*Math.sqrt(i+.5)*l,o=i*t;r.x=a+e*Math.cos(o),r.y=n+e*Math.sin(o)}}}let f=i.__skipForceSimulation||0===i.iterations?0:h?40:i.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(e.length-30)))),p=Zu(i.nodeSize,i.nodeSizeRange,e),y=e=>p(e);if(f>0){let c=new Map,u=new Map;for(let t of e)c.set(t.id,0),u.set(t.id,t);for(let e of t){let t=Hc(e.source),i=Hc(e.target);c.set(t,(c.get(t)??0)+1),c.set(i,(c.get(i)??0)+1)}let d=cx().strength(e=>{let t=e.weight,i=Hc(e.source),r=Hc(e.target),a=Math.max(1,Math.min(c.get(i)??1,c.get(r)??1));return Math.min(2.5,(t&&t>0?Math.sqrt(t):1)*o/(.1*a))}).distance(e=>{let t="string"==typeof e.source?u.get(e.source):e.source,i="string"==typeof e.target?u.get(e.target):e.target,r=(t?y(t):0)+(i?y(i):0)+Math.max(6,12*l);return Math.max(16,40*l,r)}).id(e=>e.id),p=ax();if((void 0!==i.random||void 0!==i.seed)&&p.randomSource(i.random??function(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}(i.seed)),p.force("charge",ux().strength(e=>{let t=c.get(e.id)??0;return-15*l*y(e)*Math.sqrt(t+1)})).force("collide",dx(e=>y(e)+3*l).strength(.9).iterations(2)).force("center",nx(a,n).strength(.8)).force("x",lx(a).strength(s)).force("y",sx(n).strength(s)).force("bounds",function(e,t,i=2,r=.6){let o=[],a=a=>{let n=r*Math.max(a,.2);for(let r of o){let o=r.x??e[0]/2,a=r.y??e[1]/2,l=r.vx??0,s=r.vy??0,c=t(r)+i,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),h=Math.min(e[1]/2,c),f=Math.max(e[1]/2,e[1]-c),p=o+l,y=a+s;u>p?r.vx=l+(u-p)*n:p>d&&(r.vx=l+(d-p)*n),h>y?r.vy=s+(h-y)*n:y>f&&(r.vy=s+(f-y)*n)}};return a.initialize=e=>{o=e},a}(r,y)),p.nodes(e),t.length>0){let e=t.map(e=>({...e,source:Hc(e.source),target:Hc(e.target)}));d.links(e),p.force("link",d)}h?p.alpha(.3):.1>p.alpha()&&p.alpha(1),p.stop();for(let e=0;f>e;++e)p.tick()}for(let t of e){if(null==t.x||null==t.y)continue;let e=y(t),i=f>0?2:0,o=Math.min(r[0]/2,e+i),a=Math.min(r[1]/2,e+i);t.x=Math.max(o,Math.min(r[0]-o,t.x)),t.y=Math.max(a,Math.min(r[1]-a,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}let g=new Map;for(let t of e)g.set(t.id,t);for(let e of t){if("string"==typeof e.source){let t=g.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){let t=g.get(e.target);t&&(e.target=t)}}},buildScene(e,t,i,r){let o=i.nodeStyle,a=i.edgeStyle,n=Zu(i.nodeSize,i.nodeSizeRange,e),l=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:vd,s=new Map;e.forEach((e,t)=>{s.set(e.id,l[t%l.length])});let c=[],u=[],d=[];for(let t of e){if(null==t.x||null==t.y)continue;let e=n(gs(t,"nodeSize")),r=o?o(gs(t,"nodeStyle")):{},a={fill:r.fill||s.get(t.id)||i.themeSemantic?.primary||"#007bff",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??2,opacity:r.opacity,cursor:r.cursor};c.push({type:"circle",cx:t.x,cy:t.y,r:e,style:a,datum:t,id:t.id,label:t.id})}let h=new Map;for(let t of e)h.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:h.get(e.source),r="object"==typeof e.target?e.target:h.get(e.target);if(!t||!r||null==t.x||null==t.y||null==r.x||null==r.y)continue;let o=a?a(gs(e,"edgeStyle")):{};u.push({type:"line",x1:t.x,y1:t.y,x2:r.x,y2:r.y,style:{stroke:o.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:o.strokeWidth??1,opacity:o.opacity??.6,cursor:o.cursor},datum:e})}if(!1!==i.showLabels){let t=Vc(i.nodeLabel);for(let i of e){if(null==i.x||null==i.y)continue;let e=t?t(i):i.id;if(!e)continue;let r=n(gs(i,"nodeSize"));d.push({x:i.x,y:i.y-r-4,text:e+"",anchor:"middle",baseline:"auto",fontSize:11})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};$l("force",hx);import{chord as fx,ribbon as px}from"d3-chord";import{arc as yx}from"d3-shape";var gx=vd,mx={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,i,r){if(0===e.length)return;let{padAngle:o=.01,groupWidth:a=20,sortGroups:n}=i,l=Math.min(r[0],r[1])/2,s=l-a,c=r[0]/2,u=r[1]/2,d=(f=i.valueAccessor)?"function"==typeof f?f:e=>e[f]??1:e=>e.value??1,h=new Map;var f;for(let t=0;e.length>t;t++)h.set(e[t].id,t);let p=e.length,y=Array.from({length:p},()=>Array(p).fill(0));for(let e of t){let t=Hc(e.source),i=Hc(e.target),r=h.get(t),o=h.get(i);if(void 0===r||void 0===o)continue;let a=d(e);y[r][o]=a}let g=fx().padAngle(o);n&&g.sortGroups(n);let m=g(y),x=m.groups,b=yx().innerRadius(s).outerRadius(l);for(let t of x){let i=e[t.index],r=b.centroid({innerRadius:s,outerRadius:l,startAngle:t.startAngle,endAngle:t.endAngle});i.x=r[0]+c,i.y=r[1]+u,i.__arcData={startAngle:t.startAngle,endAngle:t.endAngle}}let v=new Map;for(let t of e)v.set(t.id,t);for(let e of t){let t=Hc(e.source),i=Hc(e.target),r=v.get(t),o=v.get(i);r&&(e.source=r),o&&(e.target=o)}let w=new Map;for(let e of t){let t=Hc(e.source),i=Hc(e.target);w.set(`${t}\0${i}`,e)}for(let t of m){let i=e[t.source.index].id,r=e[t.target.index].id,o=w.get(`${i}\0${r}`)||w.get(`${r}\0${i}`);o&&(o.__chordData=t)}},buildScene(e,t,i,r){let{groupWidth:o=20,edgeOpacity:a=.5}=i,n=Math.min(r[0],r[1])/2,l=n-o,s=r[0]/2,c=r[1]/2,u=i.nodeStyle,d=i.edgeStyle,h=i.edgeColorBy||"source",f=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:gx,p=new Map;e.forEach((e,t)=>{p.set(e.id,f[t%f.length])});let y=px().radius(l),g=[],m=[],x=[];for(let t=0;e.length>t;t++){let i=e[t],r=i.__arcData;if(!r)continue;let o=u?u(gs(i,"nodeStyle")):{},a={fill:("string"==typeof o.fill?o.fill:void 0)||p.get(i.id)||f[t%f.length],stroke:o.stroke||"black",strokeWidth:o.strokeWidth??1,opacity:o.opacity,cursor:o.cursor};g.push({type:"arc",cx:s,cy:c,innerR:l,outerR:n,startAngle:r.startAngle-Math.PI/2,endAngle:r.endAngle-Math.PI/2,style:a,datum:i,id:i.id,label:i.id})}for(let e of t){let t=e.__chordData;if(!t)continue;let r=y(t);if(!r)continue;let o=bs(r,s,c),n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",l=d?d(gs(e,"edgeStyle")):{};if(d)n=("string"==typeof l.fill?l.fill:void 0)||n;else{let t="object"==typeof e.source?e.source:null,i="object"==typeof e.target?e.target:null;"target"===h&&i?n=p.get(i.id)||n:t&&(n=p.get(t.id)||n)}m.push({type:"ribbon",pathD:o,style:{fill:n,fillOpacity:l.fillOpacity??a,stroke:l.stroke||"none",strokeWidth:l.strokeWidth,opacity:l.opacity,cursor:l.cursor},datum:e})}if(!1!==i.showLabels){let t=Vc(i.nodeLabel),r=n+12;for(let i of e){let e=i.__arcData;if(!e)continue;let o=t?t(i):i.id;if(!o)continue;let a=(e.startAngle+e.endAngle)/2,n=a-Math.PI/2;x.push({x:s+Math.cos(n)*r,y:c+Math.sin(n)*r,text:o+"",anchor:a>Math.PI?"end":"start",baseline:"middle",fontSize:11})}}return{sceneNodes:g,sceneEdges:m,labels:x}}};$l("chord",mx);import{hierarchy as xx,tree as bx,cluster as vx,treemap as wx,pack as kx,partition as Ax,treemapBinary as Sx}from"d3-hierarchy";var Mx=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"],_x={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,i,r){let o=i.__hierarchyRoot;if(!o)return;let a=i.chartType,n=function(e){if(e)return"function"==typeof e?e:t=>t[e]}(i.childrenAccessor),l=i.hierarchySum,s="function"==typeof l?l:"string"==typeof l?e=>Number(e[l])||0:e=>Number(e.value)||0,c=xx(o,n);c.sum(s),c.sort((e,t)=>(t.value??0)-(e.value??0));let[u,d]=r;switch(a){case"tree":!function(e,t,i,r){let o=t.treeOrientation||"vertical",a=bx();a.size("horizontal"===o?[r,i]:"radial"===o?[2*Math.PI,Math.min(i,r)/2*.8]:[i,r]),a(e)}(c,i,u,d);break;case"cluster":!function(e,t,i,r){let o=t.treeOrientation||"vertical",a=vx();a.size("horizontal"===o?[r,i]:"radial"===o?[2*Math.PI,Math.min(i,r)/2*.8]:[i,r]),a(e)}(c,i,u,d);break;case"treemap":!function(e,t,i,r){let o=t.padding??4,a=t.paddingTop??0,n=wx().size([i,r]).tile(Sx).padding(o);a>0&&n.paddingTop(a),n(e)}(c,i,u,d);break;case"circlepack":!function(e,t,i,r){let o=t.padding??4;kx().size([i,r]).padding(o)(e)}(c,i,u,d);break;case"partition":!function(e,t,i,r){Ax().size([i,r]).padding(t.padding??1)(e)}(c,i,u,d)}let h=c.descendants();e.length=0,t.length=0;let f=new Map;for(let t=0;h.length>t;t++){let r=h[t],o={id:ws(r,i,t),x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:r.value??0,depth:r.depth,data:r.data,createdByFrame:!0};"tree"===a||"cluster"===a?_s(o,r,i):"treemap"===a||"partition"===a?Ps(o,r):"circlepack"===a&&Ls(o,r),o.__hierarchyNode=r,e.push(o),f.set(r,o)}if("tree"===a||"cluster"===a)for(let e of h)if(e.parent){let i=f.get(e.parent),r=f.get(e);i&&r&&t.push({source:i,target:r,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,i,r){let o=i.nodeStyle||(()=>({})),a=i.edgeStyle||(()=>({}));switch(i.chartType){case"tree":case"cluster":return function(e,t,i,r,o,a){let n=[],l=[],s=[],c=i.treeOrientation||"vertical",u="radial"===c,d=r[0]/2,h=r[1]/2,f="number"==typeof(p=i.nodeSize)?p:5;var p;for(let t of e){let e=t.x,r=t.y;u&&(e+=d,r+=h);let a=o(gs(t,"nodeStyle")),l=a.fill||Ss(i);if(i.colorByDepth&&void 0!==t.depth){let e=As(i);l=e[t.depth%e.length]}n.push({type:"circle",cx:e,cy:r,r:f,style:{fill:l,stroke:a.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??1,opacity:a.opacity,cursor:a.cursor},datum:t,id:t.id,label:t.id,depth:t.depth})}let y=i.edgeOpacity??.5;for(let e of t){let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let o=t.x,n=t.y,s=r.x,f=r.y;u&&(o+=d,n+=h,s+=d,f+=h);let p=Ms(o,n,s,f,c),g=a(gs(e,"edgeStyle"));l.push({type:"curved",pathD:p,style:{fill:"none",stroke:g.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:g.strokeWidth??1.5,opacity:g.opacity??y,cursor:g.cursor},datum:e})}if(!1!==i.showLabels){let t=ks(i.nodeLabel);for(let i of e){let e=t?t(i):i.id;if(!e)continue;let r,o,a,n=i.x,l=i.y;if(u&&(n+=d,l+=h),u){let e=n-d,t=l-h,i=Math.sqrt(e*e+t*t);i>0?(r=n+e/i*10,o=l+t/i*10,a=0>e?"end":"start"):(r=n,o=l-12,a="middle")}else"horizontal"===c?(i.data?.children&&0!==i.data.children.length?(r=n-f-6,a="end"):(r=n+f+6,a="start"),o=l):(r=n,o=l+f+14,a="middle");s.push({x:r,y:o,text:e+"",anchor:a,baseline:"middle",fontSize:11})}}return{sceneNodes:n,sceneEdges:l,labels:s}}(e,t,i,r,o,a);case"treemap":case"partition":return function(e,t,i,r){let o=[],a=[];for(let i of e){let e=i.x1-i.x0,a=i.y1-i.y0;if(0>=e||0>=a)continue;let n=r(gs(i,"nodeStyle")),l=n.fill||Ss(t);if(t.colorByDepth&&void 0!==i.depth){let e=As(t);l=e[i.depth%e.length]}o.push({type:"rect",x:i.x0,y:i.y0,w:e,h:a,style:{fill:l,stroke:n.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:n.strokeWidth??1,opacity:n.opacity,fillOpacity:n.fillOpacity,strokeOpacity:n.strokeOpacity,cursor:n.cursor},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==t.showLabels){let i=ks(t.nodeLabel),o=t.labelMode||"leaf",n="partition"===t.chartType;for(let l of e){let e=l.x1-l.x0,s=l.y1-l.y0;if(0>=e||0>=s)continue;let c=!(l.data?.children&&l.data.children.length>0);if(!n&&("leaf"===o&&!c||"parent"===o&&c))continue;let u=i?i(l):l.id;if(!u)continue;if((c?30:40)>e||(c?16:14)>s)continue;let d=r(gs(l,"nodeStyle")).fill||Ss(t);if(t.colorByDepth&&void 0!==l.depth){let e=As(t);d=e[l.depth%e.length]}let h="string"==typeof d?vs(d):t.themeSemantic?.text??"#000";a.push(c?{x:l.x0+e/2,y:l.y0+s/2,text:u+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,s)/6)),fill:h}:{x:l.x0+4,y:l.y0+12,text:u+"",anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:o,sceneEdges:[],labels:a}}(e,i,0,o);case"circlepack":return function(e,t,i,r){let o=[],a=[];for(let i of e){let e=i.__radius??5;if(0>=e)continue;let a=r(gs(i,"nodeStyle")),n=a.fill||Ss(t);if(t.colorByDepth&&void 0!==i.depth){let e=As(t);n=e[i.depth%e.length]}o.push({type:"circle",cx:i.x,cy:i.y,r:e,style:{fill:n,stroke:a.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:a.strokeWidth??1,opacity:a.opacity??.7,cursor:a.cursor},datum:i,id:i.id,label:i.id,depth:i.depth})}if(!1!==t.showLabels){let i=ks(t.nodeLabel);for(let o of e){let e=o.__radius??5,n=i?i(o):o.id;if(!n||15>e)continue;let l=!(o.data?.children&&o.data.children.length>0),s=r(gs(o,"nodeStyle")).fill||Ss(t);if(t.colorByDepth&&void 0!==o.depth){let e=As(t);s=e[o.depth%e.length]}if(l){let i="string"==typeof s?vs(s):t.themeSemantic?.text??"#000";a.push({x:o.x,y:o.y,text:n+"",anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,e/3)),fill:i})}else a.push({x:o.x,y:o.y-e+14,text:n+"",anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:t.themeSemantic?.text||"#000",stroke:t.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:o,sceneEdges:[],labels:a}}(e,i,0,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};$l("tree",_x),$l("cluster",_x),$l("treemap",_x),$l("circlepack",_x),$l("partition",_x);import{pie as Px}from"d3-shape";var Lx={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,i,r){let o=i.__hierarchyRoot;o&&function(e,t,i,r,o){function a(e){let t=p.get(e)??0;return p.set(e,t+1),0===t?e:`${e}__${t}`}let n=function(e){if("function"==typeof e)return e;let t=e||"children";return e=>e[t]||null}(i.childrenAccessor),l=function(e){if("function"==typeof e)return e;let t=e||"name";return e=>(e[t]??"")+""}(i.nodeIDAccessor),s=function(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}(i.orbitMode),c=i.orbitSize??2.95,u=i.orbitEccentricity??1,d="number"==typeof c?()=>c:c,h="number"==typeof u?()=>u:u,f=$s(i);f.metaMap.clear(),r.length=0,o.length=0;let p=new Map,y=t[0]/2,g=t[1]/2,m=Math.min(t[0],t[1])/2*.85,x=a(l(e));r.push({id:x,x:y,y:g,x0:y,x1:y,y0:g,y1:g,width:0,height:0,value:0,depth:0,data:e}),f.metaMap.set(x,{ring:m,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,i,c,u,p,y,g){let m=n(t);if(!m?.length)return;let x=m.length,b=0,v=0,w=0;for(;x>v;)v+=s[Math.min(w,s.length-1)],w++,b++;let k=0;for(let x=0;b>x;x++){let v=s[Math.min(x,s.length-1)],w=m.slice(k,k+v);if(!w.length)break;let A=(x+1)/b,S={id:i,depth:y,data:t,parentId:i},M=g?p/d(S)*A:p*A,_=Px().value(e=>n(e)?.length?4:1).sort(null)(w),P=h(S);for(let t=0;w.length>t;t++){let n=(_[t].startAngle+_[t].endAngle)/2,s=w[t],d=a(l(s)),h=c+M*Math.sin(n),p=u+M*Math.cos(n)*P;r.push({id:d,x:h,y:p,x0:h,x1:h,y0:p,y1:p,width:0,height:0,value:0,depth:y,data:s}),f.metaMap.set(d,{ring:M,angle:n,depth:y,parentId:i,eccentricity:P}),o.push({source:i,target:d,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:i,target:d}}),e(s,d,h,p,M,y+1,!0)}k+=v}}(e,x,y,g,m,1,!1)}(o,r,i,e,t)},buildScene(e,t,i,r){let o=i.nodeStyle,a=i.edgeStyle,n=i.nodeSize,l="number"==typeof n?()=>n:"function"==typeof n?n:()=>6,s=[],c=[],u=[];if(!1!==i.orbitShowRings){let t=$s(i),r=new Map;for(let t of e)r.set(t.id,t);let o=new Map;for(let[,e]of t.metaMap){if(!e.parentId)continue;let t=r.get(e.parentId);if(!t)continue;let i=`${e.parentId}:${e.ring}`;o.has(i)||o.set(i,{parentX:t.x,parentY:t.y,ring:e.ring,ecc:e.eccentricity})}let a=48,n={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(let[,{parentX:e,parentY:t,ring:i,ecc:r}]of o)for(let o=0;a>o;o++){let l=o/a*Math.PI*2,s=(o+1)/a*Math.PI*2;c.push({type:"line",x1:e+i*Math.sin(l),y1:t+i*Math.cos(l)*r,x2:e+i*Math.sin(s),y2:t+i*Math.cos(s)*r,style:n,datum:null})}}for(let t of e){if(null==t.x||null==t.y)continue;let e=l(gs(t,"nodeSize")),r=o?o(gs(t,"nodeStyle")):{};s.push({type:"circle",cx:t.x,cy:t.y,r:e,style:{fill:r.fill||i.themeSemantic?.primary||"#6366f1",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??(0===(t.depth??0)?1:.85),cursor:r.cursor},datum:t,id:t.id,label:t.id,depth:t.depth})}let d=new Map;for(let t of e)d.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:d.get(e.source),i="object"==typeof e.target?e.target:d.get(e.target);if(!t||!i||null==t.x||null==i.x)continue;let r=a?a(gs(e,"edgeStyle")):{};c.push({type:"line",x1:t.x,y1:t.y,x2:i.x,y2:i.y,style:{stroke:r.stroke||"rgba(128,128,128,0.35)",strokeWidth:r.strokeWidth??.5,opacity:r.opacity??1,cursor:r.cursor},datum:e})}if(i.showLabels){let t=i.nodeLabel;for(let i of e){let e=l(gs(i,"nodeSize"));if(4>=e)continue;let r="function"==typeof t?t(i):t?i.data?.[t]??i.id:i.id;u.push({x:i.x,y:i.y+e+12,text:r+"",anchor:"middle",fontSize:10,fill:"currentColor"})}}return{sceneNodes:s,sceneEdges:c,labels:u}},tick:(e,t,i,r,o)=>!1!==i.orbitAnimated&&(function(e,t){let i=$s(t),r=t.orbitSpeed??.25,o=t.orbitRevolution??function(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{let t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}(t.orbitRevolutionStyle),a=(("u">typeof performance?performance.now():Date.now())-i.startTime)/1e3,n=r*(Math.PI/6),l=new Map;for(let t of e)l.set(t.id,t);for(let t of e){let e=i.metaMap.get(t.id);if(!e||!e.parentId)continue;let r=l.get(e.parentId);if(!r)continue;let s=e.angle+a*n*o({id:t.id,depth:e.depth,data:t.data,parentId:e.parentId});t.x=r.x+e.ring*Math.sin(s),t.y=r.y+e.ring*Math.cos(s)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}(e,i),!0)};$l("orbit",Lx);import*as $x from"react";import{arc as Tx}from"d3-shape";import{jsx as Rx,jsxs as Cx}from"react/jsx-runtime";import{Fragment as Ix,jsxs as Dx}from"react/jsx-runtime";$l("sankey",ox),$l("force",hx),$l("chord",mx),$l("tree",_x),$l("cluster",_x),$l("treemap",_x),$l("circlepack",_x),$l("partition",_x),$l("orbit",Lx);var zx=new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);import*as Ox from"react-dom/server";import{geoPath as Fx}from"d3-geo";import{quadtree as Nx}from"d3-quadtree";import{geoMercator as Ex,geoEqualEarth as Wx,geoAlbersUsa as jx,geoOrthographic as Bx,geoNaturalEarth1 as Yx,geoEquirectangular as Xx}from"d3-geo";var Gx={mercator:Ex,equalEarth:Wx,albersUsa:jx,orthographic:Bx,naturalEarth:Yx,equirectangular:Xx};import{scaleLinear as Vx}from"d3-scale";var Hx=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],qx=["scene-style","data-paint","accessibility","evidence"],Ux=(e,t)=>({retainedData:e,invalidations:t}),Zx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Kx=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],Qx=["scene-geometry","data-paint","accessibility","evidence"],Jx=["scene-style","data-paint","accessibility","evidence"],eb=["overlay","accessibility","evidence"],tb=[],ib={xAccessor:Ux("rebuild",Zx),yAccessor:Ux("rebuild",Zx),lineDataAccessor:Ux("rebuild",Zx),pointIdAccessor:Ux("rebuild",Qx),lineIdAccessor:Ux("rebuild",Qx),windowSize:Ux("rebuild",Zx),projection:Ux("preserve",Kx),projectionExtent:Ux("preserve",Kx),fitPadding:Ux("preserve",Kx),lineType:Ux("preserve",Kx),flowStyle:Ux("preserve",Kx),graticule:Ux("preserve",Kx),projectionTransform:Ux("preserve",Kx),customLayout:Ux("preserve",Kx),layoutConfig:Ux("preserve",Kx),layoutMargin:Ux("preserve",Kx),areaStyle:Ux("preserve",Jx),pointStyle:Ux("preserve",["scene-geometry","scene-style","data-paint","accessibility","evidence"]),lineStyle:Ux("preserve",Jx),colorScheme:Ux("preserve",Jx),themeCategorical:Ux("preserve",Jx),themeDiverging:Ux("preserve",Jx),themeSemantic:Ux("preserve",Jx),themeSequential:Ux("preserve",Jx),decay:Ux("preserve",Jx),pulse:Ux("preserve",Jx),layoutSelection:Ux("preserve",Jx),annotations:Ux("preserve",eb),autoPlaceAnnotations:Ux("preserve",eb),clock:Ux("preserve",tb),transition:Ux("preserve",tb),introAnimation:Ux("preserve",tb),onLayoutError:Ux("preserve",tb)},rb=Ux("preserve",Kx),ob=class{constructor(){this.tracker=new gu}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},Hx)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},qx):this.recordNoop("restyle")}recordConfig(e,t={}){let i=function(e){let t="preserve",i=new Set;for(let r of e){let e=ib[r]??rb;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}(e),r=new Set(i.invalidations);return t.retainedDataChanged&&r.add("data"),this.tracker.record({kind:"config",keys:e},r)}};import{geoDistance as ab,geoGraticule as nb,geoInterpolate as lb}from"d3-geo";var sb=class e{constructor(e){this.updateResults=new ob,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=function(e){return{...e,fitPadding:Ys(e.fitPadding)}}(e)}currentTime(){return this.config.clock?.()??uo()}getConfiguredWindowSize(){let e=this.config.windowSize??500;if(!Number.isInteger(e)||1>e)throw Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){let t=this.pointBuffer.toArray(),i=this.timestampBuffer?.toArray()??[],r=t.slice(-e),o=i.slice(-r.length),a=this.currentTime();this.pointBuffer=new Np(e),this.timestampBuffer=new Np(e),r.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(o[t]??a)})}this.retainNewestLines(e)}updateConfig(e){let t=function(e){return"fitPadding"in e?{...e,fitPadding:Ys(e.fitPadding)}:e}(e),i=this.config,r=this.getConfiguredWindowSize(),o=Object.keys(t).filter(e=>t[e]!==i[e]);this.config={...this.config,...t};let a=this.getConfiguredWindowSize(),n=this.streaming&&a!==r;n&&(this.resizeStreamingWindow(a),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(o,{retainedDataChanged:n})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});let t=this.getConfiguredWindowSize(),i=this.pointBuffer?this.pointBuffer.toArray():this.pointData,r=this.timestampBuffer?.toArray()??[],o=i.slice(-t),a=r.slice(-o.length),n=this.currentTime();this.pointBuffer=new Np(t),this.timestampBuffer=new Np(t),o.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(a[t]??n)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();Wo(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();for(let i of e)Wo(this.pointBuffer,i,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");let t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(let e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){let{lineIdAccessor:t}=this.config;if(!t)throw Error("removeLine() requires lineIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]),o=[];return this.lineData=this.lineData.filter(e=>!r.has(i(e)+"")||(o.push(e),!1)),o.length>0?(this.version++,this.updateResults.recordData("remove",o.length)):this.updateResults.recordNoop("remove"),o}getLines(){return this.lineData.slice()}removePoint(e){let{pointIdAccessor:t}=this.config;if(!t)throw Error("removePoint() requires pointIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){let e=e=>r.has(i(e)+"");jo(this.pointBuffer,this.timestampBuffer,e);let t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{let e=[];return this.pointData=this.pointData.filter(t=>!r.has(i(t)+"")||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){let t=this._customRestyle;if(t){for(let i of this.scene){let r=this._baseStyles.get(i)??i.style,o=t(i,e);i.style=o?{...r,...o}:r}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){let{config:t}=this,i=this.projection,r=this.geoPath,o=this.scales,a=this.baseScale,n=[...this.baseTranslate],l=[...this.baseRotation],s=this.scene;this.projection=function(e){if(!e)return Wx();if("string"==typeof e){let t=Gx[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),Wx())}if("object"==typeof e&&"type"in e){let t=Gx[e.type],i=t?t():Wx();return e.rotate&&"rotate"in i&&i.rotate(e.rotate),e.center&&"center"in i&&i.center(e.center),i}return e}(t.projection),this.geoPath=Fx(this.projection),this.fitProjection(e),this.geoPath=Fx(this.projection);let c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(e,t)=>c([e,t]),invertedPoint:(e,t)=>c.invert?c.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let u=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=i,this.geoPath=r,this.scales=o,this.baseScale=a,this.baseTranslate=n,this.baseRotation=l):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){let t=e.width/2,i=e.height/2,r=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:i}));r.length>0&&this.startTransition(r)}this._hasRenderedOnce=!0,t.transition&&s.length>0&&this.startTransition(s),this.version++}}fitProjection(e){let t=this.projection,i=this.config,r=[...this.areas],o=Os(i.xAccessor,"lon"),a=Os(i.yAccessor,"lat"),n=this.getPoints();if(n.length>0){let e=n.map(e=>[o(e),a(e)]);r.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}let l=Fs(i.lineDataAccessor);for(let e of this.lineData){let t=l(e);if(t&&t.length>0){let e=t.map(e=>[o(e),a(e)]);r.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==r.length){if(i.projectionExtent){let[[r,o],[a,n]]=i.projectionExtent;t.fitExtent([[0,0],[e.width,e.height]],{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[r,o],[r,n],[a,n],[a,o],[r,o]]]}})}else if(t.clipAngle&&(t.clipAngle()??0)>0){let r=i.fitPadding??0,o=Math.min(e.width,e.height);t.scale(o/2-o*r),t.translate([e.width/2,e.height/2])}else{let o=i.fitPadding??0,a=e.width*o,n=e.height*o;t.fitExtent([[a,n],[e.width-a,e.height-n]],{type:"FeatureCollection",features:r})}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,o=this.scales,a=i.scale(),n=[...i.translate()],l=this.currentZoom;i.scale(this.baseScale*e.k),i.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=Fx(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(e,t)=>i([e,t]),invertedPoint:(e,t)=>i.invert?i.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let s=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.scale(a),i.translate(n),this.currentZoom=l,this.geoPath=r,this.scales=o):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,o=this.scales,a=i.scale(),n=[...i.translate()],l=this.currentZoom;i.scale(this.baseScale*e),i.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=Fx(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(e,t)=>i([e,t]),invertedPoint:(e,t)=>i.invert?i.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let s=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.scale(a),i.translate(n),this.currentZoom=l,this.geoPath=r,this.scales=o):(this.scene=[],this.rebuildQuadtree()):(this.scene=s,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){let i=this.projection;if(!i||!i.rotate)return;let r=this.geoPath,o=this.scales,a=[...i.rotate()];i.rotate(e),this.geoPath=Fx(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(e,t)=>i([e,t]),invertedPoint:(e,t)=>i.invert?i.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let n=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.rotate(a),this.geoPath=r,this.scales=o):(this.scene=[],this.rebuildQuadtree()):(this.scene=n,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){let t=this.projection;!t||!t.rotate||t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let t=0,i=0;for(let e of this.scene)"point"===e.type&&!1!==e.interactive&&(i++,e.r>t&&(t=e.r));if(this._maxPointRadius=t,e.QUADTREE_THRESHOLD>=i)return void(this._quadtree=null);let r=Array(i),o=0;for(let e of this.scene)"point"===e.type&&!1!==e.interactive&&(r[o++]=e);this._quadtree=Nx().x(e=>e.x).y(e=>e.y).addAll(r)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;let{config:t}=this,i=this.projection,r=this.geoPath;if(t.customLayout&&this.scales){let i=t.layoutMargin??{top:0,right:0,bottom:0,left:0},r=$i(t.colorScheme,t.themeCategorical,Xd),o={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:i,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...r]},resolveColor:Ti(r,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null},a=Ao({family:"geo",logLabel:"geo customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:t.onLayoutError,run:()=>t.customLayout(o)});if("failure"===a.kind)return this.lastCustomLayoutFailure=a.diagnostic,this._customLayoutFailedThisBuild=!0,a.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,[]);let n=a.result,l=n.nodes??[];if(this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null,this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this._baseStyles=new WeakMap,this.hasCustomRestyle){for(let e of l)this._baseStyles.set(e,e.style);this.restyleScene(t.layoutSelection??null)}return vo({label:"geo customLayout",nodes:l,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),l}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=new WeakMap,function({config:e,projection:t,path:i,areas:r,points:o,lines:a,layout:n}){let l=Os(e.xAccessor,"lon"),s=Os(e.yAccessor,"lat"),c=[],u=function(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}(e),d=function(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}(e),h=function(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}(e);if(e.graticule){let t=!0===e.graticule?{}:e.graticule,r=nb();t.step&&r.step(t.step);let o=i(r())||"";o&&c.push({type:"geoarea",pathData:o,centroid:[n.width/2,n.height/2],bounds:[[0,0],[n.width,n.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth??.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(let t of r){let r=i(t);if(!r)continue;let o=i.centroid(t),a=i.bounds(t),n=i.area(t);c.push({type:"geoarea",pathData:r,centroid:o,bounds:a,screenArea:n,style:Ns(e.areaStyle,t,u),datum:t,interactive:!0})}let f=Fs(e.lineDataAccessor);for(let i of a){let r=f(i);if(!r||2>r.length)continue;let o=[];if("geo"===e.lineType){let e=Array(r.length);for(let t=0;r.length>t;t++)e[t]=[l(r[t]),s(r[t])];for(let i=0;e.length-1>i;i++){let r=e[i],a=e[i+1],n=ab(r,a)||0,l=Math.max(2,Math.ceil(n/(Math.PI/180))),s=lb(r,a);for(let e=0;l>=e;e++){if(i>0&&0===e)continue;let r=t(s(e/l));null!=r&&o.push(r)}}}else for(let e=0;r.length>e;e++){let i=r[e],a=t([l(i),s(i)]);null!=a&&o.push(a)}if(2>o.length)continue;let a=Ns(e.lineStyle,i,d),u="number"==typeof a.strokeWidth?a.strokeWidth:1;2!==r.length||2>o.length||"arc"!==e.flowStyle?2===r.length&&o.length>=2&&"offset"===e.flowStyle&&(o="geo"===e.lineType?js(o,u):Bs(o[0],o[o.length-1],0,0,u)):o=Ws(o[0],o[o.length-1]);let h=Es(o,n.width);if(h.length>1)for(let e of h)2>e.length||c.push({type:"line",path:e,style:{...a,_edgeFade:!0},datum:i});else c.push({type:"line",path:2>o.length&&h[0]||o,style:a,datum:i})}let p=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,y=t.clipAngle?t.clipAngle()??0:0,g=y>0?y*Math.PI/180:null,m=t.rotate?t.rotate():[0,0,0],x="function"==typeof t.center?t.center():[0,0],b=[(x[0]??0)-m[0],(x[1]??0)-m[1]];for(let i of o){let r=l(i),o=s(i);if(null!=g&&ab([r,o],b)>g)continue;let a=t([r,o]);if(!a)continue;let n=e.pointStyle?e.pointStyle(i):{...h},u={type:"point",x:a[0],y:a[1],r:n.r||4,style:n,datum:i,pointId:p?p(i)+"":void 0};c.push(u)}return c}({config:t,projection:i,path:r,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){let i=function(e,t,i,r){let o=e.filter(e=>"point"===e.type);if(2>o.length)return null;let a=t.strength??1,n=Number.isFinite(a)?Math.max(0,Math.min(1,a)):1,l="strip"===t.layout?"strip":"radial";if("radial"===l&&0===n)return null;let s=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=o.find(e=>e.datum&&s(e.datum)+""==t.center+"");if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;let d=o.map(e=>e.datum?Number(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),h=od(d,1);r>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){let i=e[t];"geoarea"===i.type&&i.interactive&&e.splice(t,1)}let f="strip"===l?function(e,t,i,r,o){let a=Math.max(3,Math.min(8,.35*o.height)),n=Math.max(1,o.width-2*a),l=o.height/2,s=Vx().domain([0,r]).range([0,n]);t.x=a,t.y=l;let c=[];for(let o of e){if(o===t)continue;if(!o.datum){o.x=a,o.y=l;continue}let e=Number(i(o.datum)),n=a+(isFinite(e)&&e>=0&&r>0?s(e):0);o.x=n,o.y=l,c.push({node:o,x:n})}c.sort((e,t)=>e.x-t.x);let u=Math.max(0,Math.min(o.height/2-1,6)),d=0;for(;c.length>d;){let e=d+1;for(;c.length>e&&3>Math.abs(c[e].x-c[d].x);)e++;let t=e-d;if(t>1&&u>0)for(let e=0;t>e;e++)c[d+e].node.y=l+(e-(t-1)/2)*Math.min(2.5,2*u/Math.max(1,t-1));d=e}return{cx:a,cy:l,maxCost:r,availableRadius:n,layout:"strip"}}(o,u,c,h,i):function(e,t,i,r,o,a){let n=t.x,l=t.y,s=a.width/2,c=a.height/2,u=Math.min(a.width,a.height)/2,d=Vx().domain([0,r]).range([0,u]);for(let a of e){if(a===t||!a.datum)continue;let e=a.x,u=a.y,h=Math.atan2(u-l,e-n),f=Math.hypot(e-n,u-l),p=Number(i(a.datum)),y=isFinite(p)&&p>=0?r>0?d(p):0:f,g=s+Math.cos(h)*y,m=c+Math.sin(h)*y;a.x=e+(g-e)*o,a.y=u+(m-u)*o}return t.x=n+(s-n)*o,t.y=l+(c-l)*o,{cx:t.x,cy:t.y,maxCost:r,availableRadius:u,layout:"radial"}}(o,u,c,h,n,i),p=e.filter(e=>"line"===e.type);if(p.length>0){let e=new Map;for(let t of o)null!=t.pointId&&e.set(t.pointId+"",[t.x,t.y]);for(let i of p){let r=i.datum?.source,o=i.datum?.target;if(null!=r&&null!=o){let a=e.get(r+""),n=e.get(o+"");if(a&&n)if("fractional"===t.lineMode&&i.path.length>2){let e=i.path[0],t=i.path[i.path.length-1],r=[a[0]-e[0],a[1]-e[1]],o=[n[0]-t[0],n[1]-t[1]],l=[0];for(let e=1;i.path.length>e;e++)l.push(l[e-1]+Math.hypot(i.path[e][0]-i.path[e-1][0],i.path[e][1]-i.path[e-1][1]));let s=l[l.length-1];i.path=i.path.map((e,t)=>{let a=s>0?l[t]/s:t/(i.path.length-1);return[e[0]+r[0]*(1-a)+o[0]*a,e[1]+r[1]*(1-a)+o[1]*a]})}else i.path=[a,n]}}}return f}(this.scene,e,t,this.areas.length);i&&(this.cartogramLayout=i)}applyDecay(){let e=this.config.decay;if(!e||!this.pointBuffer)return;let t=this.pointBuffer.size;if(0===t)return;let i=this.scene.filter(e=>"point"===e.type);for(let r=0;i.length>r;r++){let o=ho(e,r,t);i[r]._decayOpacity=o,i[r].style={...i[r].style,opacity:o}}}applyPulse(e=this.currentTime()){let t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;let i=this.scene.filter(e=>"point"===e.type),r=this.timestampBuffer.toArray(),o=t.color||"rgba(255,255,255,0.6)",a=t.glowRadius??4,n=!1;for(let l=0;i.length>l&&r.length>l;l++){let s=po(t,r[l],e);n=yo(i[l],s,o,a)||n}return n}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&go(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){let t=this.config.transition?.duration??300;if(0>=t)return;let i=new Map;for(let t of e)"point"===t.type&&t.pointId&&i.set(t.pointId,[t.x,t.y]);let r=this.scene.filter(e=>"point"===e.type),o=!1;for(let e of r)if(e.pointId){let t=i.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(o=!0))}for(let e of r)e.pointId&&!i.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??e.style?.fillOpacity??1,e.style={...e.style,opacity:0},o=!0);o&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null;for(let e of this.scene)"point"===e.type&&(null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0),null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0))}advanceTransition(e){if(!this.activeTransition)return!1;let t=so(e,this.activeTransition),i=lo(t),r=this.scene.filter(e=>"point"===e.type);for(let e of r){if(null!=e._targetX&&null!=e._targetY){let t=e.y;e.x=co(e.x,e._targetX,i),e.y=co(t,e._targetY,i)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*i})}if(t>=1){for(let e of r)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};sb.QUADTREE_THRESHOLD=500;var cb=sb;qo(cb);import*as ub from"react";import{jsx as db,jsxs as hb}from"react/jsx-runtime";import{jsx as fb,jsxs as pb}from"react/jsx-runtime";import{Fragment as yb,jsx as gb,jsxs as mb}from"react/jsx-runtime";import*as xb from"react-dom/server.browser";var bb={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};import{jsx as vb,jsxs as wb}from"react/jsx-runtime";var kb={top:0,right:0,bottom:0,left:0};import{jsx as Ab}from"react/jsx-runtime";import{scaleLinear as Sb}from"d3-scale";import{jsx as Mb,jsxs as _b}from"react/jsx-runtime";var Pb={top:0,right:0,bottom:0,left:0};import*as Lb from"react-dom/server";import{jsx as $b,jsxs as Tb}from"react/jsx-runtime";var Rb={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}},Cb={BigNumber:function(e,t){let i="presentation"===e.mode||"inline"===e.mode||"thumbnail"===e.mode?e.mode:"tile",r=Rb[i],o=lc(e.width,r.width),a=lc(e.height,r.height),n="number"==typeof e.padding&&Number.isFinite(e.padding)?Math.max(0,e.padding):r.padding,l="center"===e.align||"end"===e.align||"start"===e.align?e.align:r.align,s="center"===l?"middle":"end"===l?"end":"start",c="center"===l?o/2:"end"===l?o-n:n,u=le(e.theme),d="number"==typeof e.value&&Number.isFinite(e.value)?e.value:void 0,h=function(e,t={}){if("function"==typeof e)return e;let i=t.locale??"en-US";if("currency"===e){let e=t.precision??2,r=new Intl.NumberFormat(i,{style:"currency",currency:t.currency??"USD",maximumFractionDigits:e,minimumFractionDigits:e});return e=>r.format(e)}if("percent"===e){let e=new Intl.NumberFormat(i,{style:"percent",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("compact"===e){let e=new Intl.NumberFormat(i,{notation:"compact",maximumFractionDigits:t.precision??1,minimumFractionDigits:0});return t=>e.format(t)}if("duration"===e)return e=>function(e){if(!Number.isFinite(e))return e+"";let t=0>e?"-":"",i=Math.abs(e);if(1e3>i)return`${t}${Math.round(i)}ms`;let r=i/1e3;if(60>r)return`${t}${o=r,Math.round(100*o)/100+""}s`;var o;let a=r/60;if(60>a){let e=Math.floor(a),i=Math.round(r-60*e);return 0===i?`${t}${e}m`:`${t}${e}m ${i}s`}let n=a/60;if(24>n){let e=Math.floor(n),i=Math.round(a-60*e);return 0===i?`${t}${e}h`:`${t}${e}h ${i}m`}let l=Math.floor(n/24),s=Math.round(n-24*l);return 0===s?`${t}${l}d`:`${t}${l}d ${s}h`}(e);let r=new Intl.NumberFormat(i,{notation:t.notation??"standard",maximumFractionDigits:t.precision??0,minimumFractionDigits:0});return e=>r.format(e)}("string"==typeof e.format||"function"==typeof e.format?e.format:"number",{locale:"string"==typeof e.locale?e.locale:void 0,currency:"string"==typeof e.currency?e.currency:void 0,precision:"number"==typeof e.precision?e.precision:void 0}),f=void 0===d?"No value":(T=h(d),`${("string"==typeof e.prefix?e.prefix:void 0)??""}${T}${("string"==typeof e.suffix?e.suffix:void 0)??""}`),p=void 0===d?void 0:function(e,t){if(!t||0===t.length||!Number.isFinite(e))return null;let i=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at),r=null;for(let t of i){if(t.at>e)break;r=t}return r}(d,e.thresholds),y="string"==typeof e.color?e.color:function(e,t,i){return t||("success"===e?i.colors.success??"#2ca02c":"warning"===e?i.colors.warning??"#b26a00":"danger"===e?i.colors.danger??"#d62728":"info"===e?i.colors.info??i.colors.primary:i.colors.text)}(p?.level??"neutral",p?.color,u),g="string"==typeof e.label?e.label:void 0,m="string"==typeof e.caption?e.caption:void 0,x="string"==typeof e.unit?e.unit:void 0,b=void 0===d?void 0:function(e,t,i){let r=e.comparison&&"object"==typeof e.comparison?e.comparison:void 0,o=r&&"number"==typeof r.value&&Number.isFinite(r.value)?r.value:void 0,a=("number"==typeof e.delta&&Number.isFinite(e.delta)?e.delta:void 0)??(void 0===o?void 0:t-o);if(void 0===a)return;let n=function(e,t){return Number.isFinite(e)?0===e?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}(a,i);return`${n}${r&&"string"==typeof r.label?" "+r.label:""}`}(e,d,h),v=void 0===d?void 0:function(e,t,i){let r=e.target&&"object"==typeof e.target?e.target:void 0;if(!r||"number"!=typeof r.value||!Number.isFinite(r.value))return;let o="string"==typeof r.label?" "+r.label:"";return 0===r.value?`target ${i(r.value)}${o}`:`${new Intl.NumberFormat("string"==typeof e.locale?e.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(t/r.value)} of ${i(r.value)}${o}`}(e,d,h),w=[b,v,p?.label].filter(Boolean).join(" · "),k="string"==typeof e.description&&e.description||[g,f,x,w].filter(Boolean).join(", "),A="string"==typeof e.background?e.background:u.colors.surface??u.colors.background,S="string"==typeof e.borderColor?e.borderColor:u.colors.border,M=n+r.labelSize,_=M+r.captionSize+4,P="presentation"===i?a/2+.32*r.valueSize:"thumbnail"===i?a/2+.34*r.valueSize:Math.min(a-n-(w?26:4),(r.showHeader&&(g||m)?m?_+10:M+14:n)+r.valueSize),L=c+("start"===s?Math.max(r.valueSize,f.length*r.valueSize*.55):0),$=Lb.renderToStaticMarkup(Tb("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:a,viewBox:`0 0 ${o} ${a}`,role:"img","aria-label":k,"data-semiotic-component":"BigNumber",children:[$b("title",{children:g??f}),"string"==typeof e.description&&$b("desc",{children:e.description}),$b("rect",{x:r.border?.5:0,y:r.border?.5:0,width:r.border?o-1:o,height:r.border?a-1:a,rx:r.border?8:0,fill:A,stroke:r.border?S:"none"}),r.showHeader&&g&&$b("text",{x:c,y:M,textAnchor:s,fontFamily:u.typography.fontFamily,fontSize:r.labelSize,fontWeight:600,fill:u.colors.text,children:g}),r.showHeader&&m&&$b("text",{x:c,y:_,textAnchor:s,fontFamily:u.typography.fontFamily,fontSize:r.captionSize,fill:u.colors.textSecondary,children:m}),$b("text",{x:c,y:P,textAnchor:s,fontFamily:u.typography.fontFamily,fontSize:r.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:y,"data-mark-type":"value",children:f}),x&&void 0!==d&&"start"===s&&$b("text",{x:L+6,y:P,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*r.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:x}),r.showDetail&&w&&$b("text",{x:c,y:Math.min(a-n,P+r.detailSize+10),textAnchor:s,fontFamily:u.typography.fontFamily,fontSize:r.detailSize,fill:u.colors.textSecondary,children:w})]}));var T;return t&&(t.evidence=Ta({frameType:"value",width:o,height:a,marks:void 0===d?[]:[{type:"value"}],title:g,description:k})),$}};import*as Ib from"react-dom/server";import{jsx as Db,jsxs as zb}from"react/jsx-runtime";import{Fragment as Ob,jsx as Fb}from"react/jsx-runtime";var Nb=new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),Eb=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi,Wb=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations"],jb=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];import*as Bb from"react-dom/server";import{Fragment as Yb,jsx as Xb,jsxs as Gb}from"react/jsx-runtime";_a();export{wc as generateFrameSVGs,kc as generateFrameSequence,_c as generatePhysicsFrameSVGs,mc as renderChart,xc as renderChartWithEvidence,vc as renderDashboard,fc as renderGeoToStaticSVG,hc as renderNetworkToStaticSVG,dc as renderOrdinalToStaticSVG,cc as renderToStaticSVG,uc as renderXYToStaticSVG,le as resolveTheme,yc as serializeSvgPrecision,se as themeStyles};