semiotic 3.8.8 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (501) hide show
  1. package/README.md +82 -66
  2. package/agent-skill/semiotic-charts/SKILL.md +11 -2
  3. package/ai/behaviorContracts.cjs +33 -3
  4. package/ai/cli.js +53 -2
  5. package/ai/componentMetadata.cjs +15 -0
  6. package/ai/dist/mcp-server.js +1530 -611
  7. package/ai/examples.md +48 -42
  8. package/{CLAUDE.md → ai/reference.md} +46 -24
  9. package/ai/schema.json +10704 -825
  10. package/ai/surface-manifest.json +643 -2
  11. package/ai/system-prompt.md +83 -130
  12. package/dist/c-3BLJEQNG.min.js +1 -0
  13. package/dist/c-3KZD6AXJ.min.js +1 -0
  14. package/dist/c-4TWEX5HG.min.js +1 -0
  15. package/dist/c-52TEGIUJ.min.js +1 -0
  16. package/dist/c-5YCIX3VZ.min.js +1 -0
  17. package/dist/c-6FEKTA3U.min.js +1 -0
  18. package/dist/c-6O5EVOPH.min.js +1 -0
  19. package/dist/c-74HEEZGK.min.js +1 -0
  20. package/dist/c-AKAF6JAD.min.js +1 -0
  21. package/dist/c-BBKITSXB.min.js +1 -0
  22. package/dist/c-BWNB6USU.min.js +1 -0
  23. package/dist/c-C25ENHIK.min.js +1 -0
  24. package/dist/c-CDR5AO3R.min.js +1 -0
  25. package/dist/c-COHXCW3Q.min.js +1 -0
  26. package/dist/{chunk-scatterplotMatrixBrushOverlay-SDIZSN66.module.min.js → c-DADXPJXV.min.js} +0 -1
  27. package/dist/c-E3JFRRMI.min.js +1 -0
  28. package/dist/c-EBFPQHHO.min.js +1 -0
  29. package/dist/c-G36WS6LN.min.js +1 -0
  30. package/dist/c-GIKRQI4X.min.js +1 -0
  31. package/dist/c-GPYOFETM.min.js +1 -0
  32. package/dist/c-IDUHYYSI.min.js +1 -0
  33. package/dist/{chunk-chunk-FQPKOAIH.module.min.js → c-IUHFPMHD.min.js} +0 -1
  34. package/dist/c-J5G56TUH.min.js +1 -0
  35. package/dist/c-JAZ73J32.min.js +1 -0
  36. package/dist/c-KG3NXHAL.min.js +1 -0
  37. package/dist/c-KII3PLZE.min.js +1 -0
  38. package/dist/c-LIXGXMNS.min.js +1 -0
  39. package/dist/c-LVEY6D6B.min.js +1 -0
  40. package/dist/c-M4Y3BHFR.min.js +1 -0
  41. package/dist/c-MAIICR2Z.min.js +1 -0
  42. package/dist/c-MG5DM6VE.min.js +1 -0
  43. package/dist/{chunk-minimapBrushOverlay-JU57U7NM.module.min.js → c-MNF2S4AA.min.js} +0 -1
  44. package/dist/c-MT3WBK7M.min.js +1 -0
  45. package/dist/c-NY3JWV2K.min.js +1 -0
  46. package/dist/c-O6U6K4CW.min.js +1 -0
  47. package/dist/c-OCI56QF2.min.js +1 -0
  48. package/dist/c-OQ7M4AGV.min.js +1 -0
  49. package/dist/c-OXYMVK7Q.min.js +1 -0
  50. package/dist/c-PPWDL5ZI.min.js +1 -0
  51. package/dist/c-QHF5YON3.min.js +1 -0
  52. package/dist/c-RR3GO5SW.min.js +1 -0
  53. package/dist/{chunk-chunk-J5QD4RAM.module.min.js → c-RSVIHIQ4.min.js} +0 -1
  54. package/dist/{chunk-chunk-EMO5NUGE.module.min.js → c-S2BXNNJN.min.js} +0 -1
  55. package/dist/{chunk-chunk-YCQYG6J5.module.min.js → c-SLGMUBUL.min.js} +0 -1
  56. package/dist/c-SUILCHWU.min.js +1 -0
  57. package/dist/c-TZW3JGJ5.min.js +1 -0
  58. package/dist/c-US5ZFT6E.min.js +1 -0
  59. package/dist/{chunk-chunk-RZH7VZYS.module.min.js → c-USFMFKIH.min.js} +0 -1
  60. package/dist/c-UUKVD4WB.min.js +1 -0
  61. package/dist/{chunk-chunk-SV4XAZ3Q.module.min.js → c-VGW3VG3I.min.js} +0 -1
  62. package/dist/c-W3CE4A4S.min.js +1 -0
  63. package/dist/{chunk-chunk-2NVFEB7P.module.min.js → c-WJCD5EUY.min.js} +0 -1
  64. package/dist/{chunk-chunk-2JGJ5GUG.module.min.js → c-X5UBGU2V.min.js} +0 -1
  65. package/dist/c-YDAY2WFR.min.js +1 -0
  66. package/dist/c-ZOWWU34K.min.js +1 -0
  67. package/dist/components/AccessibleNavTree.d.ts +1 -1
  68. package/dist/components/CategoryColors.d.ts +1 -1
  69. package/dist/components/GradientLegend.d.ts +14 -0
  70. package/dist/components/Legend.d.ts +2 -7
  71. package/dist/components/LinkedCharts.d.ts +1 -1
  72. package/dist/components/MobileAnnotationCalloutList.d.ts +1 -1
  73. package/dist/components/ObservationReadout.d.ts +45 -0
  74. package/dist/components/ThemeProvider.d.ts +4 -4
  75. package/dist/components/Tooltip/FlippingTooltip.d.ts +5 -7
  76. package/dist/components/Tooltip/Tooltip.d.ts +83 -5
  77. package/dist/components/Tooltip/tooltipChrome.d.ts +43 -0
  78. package/dist/components/ai/chartCapabilityTypes.d.ts +86 -2
  79. package/dist/components/ai/chartClinic.d.ts +2 -0
  80. package/dist/components/ai/deriveProfileFields.d.ts +40 -0
  81. package/dist/components/ai/evaluateChart.d.ts +85 -0
  82. package/dist/components/ai/fieldPolicy.d.ts +7 -0
  83. package/dist/components/ai/fieldRoles.d.ts +24 -0
  84. package/dist/components/ai/generativeChart.d.ts +18 -2
  85. package/dist/components/ai/inferIntent.d.ts +26 -2
  86. package/dist/components/ai/intents.d.ts +35 -0
  87. package/dist/components/ai/navigationTree.d.ts +2 -2
  88. package/dist/components/ai/observedSceneAudit.d.ts +2 -1
  89. package/dist/components/ai/profileData.d.ts +11 -0
  90. package/dist/components/ai/repairChartConfig.d.ts +2 -3
  91. package/dist/components/ai/semanticEvidence.d.ts +4 -0
  92. package/dist/components/ai/semanticViability.d.ts +11 -0
  93. package/dist/components/ai/semanticViabilityRegistry.d.ts +5 -0
  94. package/dist/components/ai/streamingTypes.d.ts +4 -0
  95. package/dist/components/ai/suggestCharts.d.ts +5 -6
  96. package/dist/components/ai/suggestDashboard.d.ts +2 -3
  97. package/dist/components/ai/suggestStreamCharts.d.ts +1 -1
  98. package/dist/components/ai/suggestStretchCharts.d.ts +2 -3
  99. package/dist/components/ai/suggestionPropContracts.d.ts +20 -0
  100. package/dist/components/ai/variantDiscovery.d.ts +3 -1
  101. package/dist/components/charts/custom/NetworkCustomChart.d.ts +3 -0
  102. package/dist/components/charts/custom/OrdinalCustomChart.d.ts +3 -0
  103. package/dist/components/charts/custom/XYCustomChart.d.ts +1 -1
  104. package/dist/components/charts/geo/ChoroplethMap.d.ts +3 -1
  105. package/dist/components/charts/geo/DistanceCartogram.d.ts +2 -7
  106. package/dist/components/charts/geo/cartogramOverlay.d.ts +28 -0
  107. package/dist/components/charts/index.d.ts +4 -3
  108. package/dist/components/charts/network/ProcessSankey.d.ts +2 -136
  109. package/dist/components/charts/network/ProcessSankeyProps.d.ts +139 -0
  110. package/dist/components/charts/network/Treemap.d.ts +2 -1
  111. package/dist/components/charts/network/processSankey/boundaryHubOrdering.d.ts +23 -0
  112. package/dist/components/charts/network/processSankey/layoutGeometry.d.ts +2 -0
  113. package/dist/components/charts/network/processSankey/ordering.d.ts +3 -41
  114. package/dist/components/charts/network/processSankey/orderingTypes.d.ts +32 -0
  115. package/dist/components/charts/network/processSankey/packing.d.ts +1 -1
  116. package/dist/components/charts/network/processSankey/packingCache.d.ts +1 -1
  117. package/dist/components/charts/network/processSankey/packingOptimization.d.ts +72 -0
  118. package/dist/components/charts/ordinal/BarChart.d.ts +4 -3
  119. package/dist/components/charts/ordinal/FunnelChart.d.ts +2 -0
  120. package/dist/components/charts/ordinal/GroupedBarChart.d.ts +3 -2
  121. package/dist/components/charts/ordinal/StackedBarChart.d.ts +4 -3
  122. package/dist/components/charts/ordinal/SwimlaneChart.d.ts +2 -2
  123. package/dist/components/charts/physics/GaltonBoardChart.d.ts +2 -9
  124. package/dist/components/charts/physics/GauntletChart.d.ts +10 -41
  125. package/dist/components/charts/physics/ProcessFlowChart.d.ts +1 -1
  126. package/dist/components/charts/physics/chainReactionAccessibleTable.d.ts +9 -0
  127. package/dist/components/charts/physics/chainReactionRuntime.d.ts +2 -1
  128. package/dist/components/charts/physics/chainReactionTypes.d.ts +6 -1
  129. package/dist/components/charts/physics/crucibleBodyRenderers.d.ts +2 -2
  130. package/dist/components/charts/physics/crucibleClone.d.ts +6 -0
  131. package/dist/components/charts/physics/crucibleEffects.d.ts +1 -2
  132. package/dist/components/charts/physics/crucibleRecord.d.ts +7 -0
  133. package/dist/components/charts/physics/gauntletChrome.d.ts +4 -4
  134. package/dist/components/charts/physics/gauntletPhysics.d.ts +1 -0
  135. package/dist/components/charts/physics/gauntletPublic.d.ts +4 -0
  136. package/dist/components/charts/physics/packetFlowOverlay.d.ts +7 -0
  137. package/dist/components/charts/physics/physicsChartLayout.d.ts +8 -0
  138. package/dist/components/charts/physics/physicsChartShared.d.ts +3 -1
  139. package/dist/components/charts/physics/physicsChartUtils.d.ts +1 -1
  140. package/dist/components/charts/physics/physicsHocUtils.d.ts +26 -13
  141. package/dist/components/charts/physics/physicsProjectionOverlays.d.ts +24 -0
  142. package/dist/components/charts/physics/processFlowOverlays.d.ts +9 -0
  143. package/dist/components/charts/realtime/RealtimeHeatmap.d.ts +17 -12
  144. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +12 -7
  145. package/dist/components/charts/realtime/RealtimeLineChart.d.ts +37 -14
  146. package/dist/components/charts/realtime/RealtimeSwarmChart.d.ts +23 -14
  147. package/dist/components/charts/realtime/RealtimeWaterfallChart.d.ts +22 -13
  148. package/dist/components/charts/realtime/aggregate.d.ts +4 -1
  149. package/dist/components/charts/realtime/eventTime.d.ts +4 -0
  150. package/dist/components/charts/realtime/realtimeChartRuntime.d.ts +27 -0
  151. package/dist/components/charts/realtime/realtimeChartTypes.d.ts +30 -0
  152. package/dist/components/charts/realtime/useRealtimeCategoryColors.d.ts +30 -0
  153. package/dist/components/charts/shared/FrameTextAnnotationSVG.d.ts +10 -0
  154. package/dist/components/charts/shared/annotationActivation.d.ts +3 -7
  155. package/dist/components/charts/shared/annotationBandFill.d.ts +6 -0
  156. package/dist/components/charts/shared/annotationDispatch.d.ts +31 -0
  157. package/dist/components/charts/shared/annotationIdentity.d.ts +8 -0
  158. package/dist/components/charts/shared/annotationRules.d.ts +1 -15
  159. package/dist/components/charts/shared/boundedCategoryRegistry.d.ts +8 -0
  160. package/dist/components/charts/shared/chainReactionChartSpec.d.ts +3 -0
  161. package/dist/components/charts/shared/chartMode.d.ts +3 -2
  162. package/dist/components/charts/shared/chartSpecCore.d.ts +1 -0
  163. package/dist/components/charts/shared/formatUtils.d.ts +40 -9
  164. package/dist/components/charts/shared/frameTextAnnotation.d.ts +63 -0
  165. package/dist/components/charts/shared/gradient.d.ts +16 -0
  166. package/dist/components/charts/shared/hatchFill.d.ts +15 -0
  167. package/dist/components/charts/shared/hooks.d.ts +4 -4
  168. package/dist/components/charts/shared/legendUtils.d.ts +1 -0
  169. package/dist/components/charts/shared/streamPropsHelpers.d.ts +3 -1
  170. package/dist/components/charts/shared/styleRules.d.ts +9 -2
  171. package/dist/components/charts/shared/styleRulesWireSchema.d.ts +353 -0
  172. package/dist/components/charts/shared/types.d.ts +26 -10
  173. package/dist/components/charts/shared/useChartLegend.d.ts +43 -9
  174. package/dist/components/charts/shared/useChartSetup.d.ts +3 -1
  175. package/dist/components/charts/shared/useCustomChartSetup.d.ts +5 -2
  176. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +5 -1
  177. package/dist/components/charts/shared/useOrdinalBrush.d.ts +3 -3
  178. package/dist/components/charts/shared/useStreamingLegend.d.ts +6 -1
  179. package/dist/components/charts/value/types.d.ts +1 -1
  180. package/dist/components/charts/xy/BubbleChart.d.ts +1 -1
  181. package/dist/components/charts/xy/BumpChart.capability.d.ts +14 -1
  182. package/dist/components/charts/xy/BumpChart.d.ts +13 -73
  183. package/dist/components/charts/xy/BumpChart.semanticViability.d.ts +5 -0
  184. package/dist/components/charts/xy/CandlestickChart.d.ts +2 -2
  185. package/dist/components/charts/xy/LineChart.d.ts +2 -2
  186. package/dist/components/charts/xy/Scatterplot.d.ts +1 -1
  187. package/dist/components/charts/xy/bumpData.d.ts +44 -0
  188. package/dist/components/charts/xy/bumpIdentity.d.ts +2 -0
  189. package/dist/components/charts/xy/bumpLayout.d.ts +45 -0
  190. package/dist/components/charts/xy/bumpTooltip.d.ts +20 -0
  191. package/dist/components/legendLayout.d.ts +131 -4
  192. package/dist/components/realtime/ReorderBuffer.d.ts +2 -0
  193. package/dist/components/realtime/types.d.ts +10 -1
  194. package/dist/components/recipes/balanceSnapshotsToFlows.d.ts +42 -0
  195. package/dist/components/recipes/directedReachability.d.ts +14 -0
  196. package/dist/components/recipes/gofishDisplayListFixtures.generated.d.ts +6 -6
  197. package/dist/components/recipes/gridObservatory.d.ts +1 -1
  198. package/dist/components/recipes/networkAnalysis.d.ts +1 -18
  199. package/dist/components/recipes/physics.d.ts +7 -4
  200. package/dist/components/recipes/processPhysics.d.ts +0 -1
  201. package/dist/components/recipes/waffle.d.ts +7 -4
  202. package/dist/components/semiotic-ai-core.d.ts +13 -4
  203. package/dist/components/semiotic-ai-observations.d.ts +3 -0
  204. package/dist/components/semiotic-ai.d.ts +16 -9
  205. package/dist/components/semiotic-client-shared.d.ts +10 -0
  206. package/dist/components/semiotic-experimental.d.ts +1 -1
  207. package/dist/components/semiotic-geo.d.ts +4 -1
  208. package/dist/components/semiotic-network.d.ts +7 -4
  209. package/dist/components/semiotic-ordinal.d.ts +4 -1
  210. package/dist/components/semiotic-physics.d.ts +11 -4
  211. package/dist/components/semiotic-realtime-core.d.ts +11 -4
  212. package/dist/components/semiotic-realtime-react.d.ts +4 -3
  213. package/dist/components/semiotic-realtime.d.ts +3 -1
  214. package/dist/components/semiotic-recipes-core.d.ts +7 -5
  215. package/dist/components/semiotic-server-edge.d.ts +3 -2
  216. package/dist/components/semiotic-server.d.ts +3 -2
  217. package/dist/components/semiotic-themes-core.d.ts +5 -48
  218. package/dist/components/semiotic-utils-core.d.ts +11 -5
  219. package/dist/components/semiotic-utils-react.d.ts +2 -0
  220. package/dist/components/semiotic-xy.d.ts +4 -1
  221. package/dist/components/semiotic.d.ts +68 -25
  222. package/dist/components/server/animatedGif.d.ts +1 -1
  223. package/dist/components/server/renderEvidence.d.ts +25 -2
  224. package/dist/components/server/renderToStaticSVG.d.ts +15 -7
  225. package/dist/components/server/serverChartConfigShared.d.ts +8 -1
  226. package/dist/components/server/serverChartConfigs.d.ts +1 -0
  227. package/dist/components/server/serverChartConfigsNetwork.d.ts +3 -3
  228. package/dist/components/server/serverChartConfigsNetworkChord.d.ts +2 -0
  229. package/dist/components/server/serverChartConfigsNetworkForce.d.ts +2 -0
  230. package/dist/components/server/serverChartConfigsNetworkHierarchy.d.ts +3 -0
  231. package/dist/components/server/serverChartConfigsXY.d.ts +3 -3
  232. package/dist/components/server/serverChartConfigsXYBubble.d.ts +5 -0
  233. package/dist/components/server/serverChartConfigsXYBump.d.ts +7 -0
  234. package/dist/components/server/serverChartConfigsXYScatter.d.ts +5 -0
  235. package/dist/components/server/staticAnnotationFallbacks.d.ts +10 -0
  236. package/dist/components/server/staticAnnotations.d.ts +28 -1
  237. package/dist/components/server/staticAxisTickLabel.d.ts +13 -0
  238. package/dist/components/server/staticLegend.d.ts +1 -1
  239. package/dist/components/server/staticLegendMargin.d.ts +41 -0
  240. package/dist/components/server/staticOrdinal.d.ts +8 -2
  241. package/dist/components/server/staticPhysics.d.ts +13 -1
  242. package/dist/components/server/staticPhysicsChrome.d.ts +20 -0
  243. package/dist/components/server/staticRawLegend.d.ts +15 -0
  244. package/dist/components/server/staticSVGChrome.d.ts +16 -55
  245. package/dist/components/server/staticXYAxes.d.ts +27 -0
  246. package/dist/components/server/staticXYAxisTicks.d.ts +39 -0
  247. package/dist/components/server/staticXYGrid.d.ts +11 -0
  248. package/dist/components/server/themeResolver.d.ts +5 -1
  249. package/dist/components/store/ThemeStore.d.ts +2 -98
  250. package/dist/components/store/designTokens.d.ts +1 -1
  251. package/dist/components/store/themeCSSVariables.d.ts +10 -0
  252. package/dist/components/store/themeCore.d.ts +91 -0
  253. package/dist/components/store/themePresets.d.ts +81 -0
  254. package/dist/components/store/themeSerialization.d.ts +2 -1
  255. package/dist/components/stream/AccessibleDataTable.d.ts +12 -14
  256. package/dist/components/stream/AccessibleTablePortalImpl.d.ts +6 -0
  257. package/dist/components/stream/GeoTileRenderer.d.ts +3 -0
  258. package/dist/components/stream/NetworkCanvasHitTester.d.ts +3 -1
  259. package/dist/components/stream/NetworkSSRFrame.d.ts +2 -1
  260. package/dist/components/stream/NetworkSVGOverlay.d.ts +3 -31
  261. package/dist/components/stream/OrdinalCanvasHitTester.d.ts +2 -0
  262. package/dist/components/stream/SVGChartTitle.d.ts +9 -0
  263. package/dist/components/stream/SVGOverlay.d.ts +1 -21
  264. package/dist/components/stream/SVGUnderlay.d.ts +24 -0
  265. package/dist/components/stream/SceneToSVG.d.ts +1 -1
  266. package/dist/components/stream/StreamGeoFrame.d.ts +1 -1
  267. package/dist/components/stream/StreamOrdinalFrame.d.ts +1 -1
  268. package/dist/components/stream/StreamXYFrame.d.ts +1 -1
  269. package/dist/components/stream/accessibleDataRows.d.ts +11 -0
  270. package/dist/components/stream/accessibleDataTableModel.d.ts +40 -0
  271. package/dist/components/stream/accessibleTableTypes.d.ts +11 -0
  272. package/dist/components/stream/axisTickUtils.d.ts +19 -0
  273. package/dist/components/stream/canvasBackground.d.ts +10 -0
  274. package/dist/components/stream/canvasSetup.d.ts +24 -4
  275. package/dist/components/stream/frameCursorInteraction.d.ts +25 -0
  276. package/dist/components/stream/frameDefaultMargins.d.ts +37 -0
  277. package/dist/components/stream/frameGraphics.d.ts +18 -0
  278. package/dist/components/stream/frameGraphicsSubscription.d.ts +26 -0
  279. package/dist/components/stream/frameLegendOptions.d.ts +18 -0
  280. package/dist/components/stream/geoFrameCursorInteraction.d.ts +9 -0
  281. package/dist/components/stream/geoFrameHelpers.d.ts +29 -1
  282. package/dist/components/stream/geoTypes.d.ts +12 -11
  283. package/dist/components/stream/hitTarget.d.ts +61 -2
  284. package/dist/components/stream/moduleWorkerSession.d.ts +6 -0
  285. package/dist/components/stream/networkAnnotationAnchors.d.ts +37 -0
  286. package/dist/components/stream/networkCustomLayout.d.ts +2 -2
  287. package/dist/components/stream/networkFrameCursorInteraction.d.ts +12 -0
  288. package/dist/components/stream/networkFrameInteraction.d.ts +2 -0
  289. package/dist/components/stream/networkFramePaint.d.ts +15 -0
  290. package/dist/components/stream/networkPipelineConfig.d.ts +1 -1
  291. package/dist/components/stream/networkTypes.d.ts +32 -32
  292. package/dist/components/stream/normalizeXYData.d.ts +7 -0
  293. package/dist/components/stream/ordinalFrameCursorInteraction.d.ts +7 -0
  294. package/dist/components/stream/ordinalFrameInteraction.d.ts +29 -0
  295. package/dist/components/stream/ordinalSceneSVG.d.ts +10 -0
  296. package/dist/components/stream/ordinalTypes.d.ts +12 -4
  297. package/dist/components/stream/physics/PhysicsBodySpatialIndex.d.ts +9 -1
  298. package/dist/components/stream/physics/PhysicsCanvasTheme.d.ts +25 -0
  299. package/dist/components/stream/physics/PhysicsControllers.d.ts +0 -3
  300. package/dist/components/stream/physics/PhysicsPipelineStore.d.ts +4 -1
  301. package/dist/components/stream/physics/PhysicsSVGOverlay.d.ts +3 -24
  302. package/dist/components/stream/physics/PhysicsSettledSVG.d.ts +9 -21
  303. package/dist/components/stream/physics/PhysicsSettledSVGElement.d.ts +37 -0
  304. package/dist/components/stream/physics/PhysicsSettledScene.d.ts +7 -3
  305. package/dist/components/stream/physics/StreamPhysicsFrame.d.ts +1 -1
  306. package/dist/components/stream/physics/StreamPhysicsTypes.d.ts +25 -4
  307. package/dist/components/stream/physics/physicsAnnotationContext.d.ts +19 -0
  308. package/dist/components/stream/physics/physicsBodyCanvas.d.ts +4 -0
  309. package/dist/components/stream/physics/physicsSettledChrome.d.ts +7 -0
  310. package/dist/components/stream/physics/usePhysicsCanvasPointer.d.ts +32 -0
  311. package/dist/components/stream/physics/usePhysicsSemanticNavigation.d.ts +36 -0
  312. package/dist/components/stream/pipelineConfig.d.ts +8 -17
  313. package/dist/components/stream/pipelineDomainResolution.d.ts +2 -2
  314. package/dist/components/stream/renderBackend.d.ts +2 -0
  315. package/dist/components/stream/renderers/canvasRenderHelpers.d.ts +13 -2
  316. package/dist/components/stream/renderers/resolveCSSColor.d.ts +7 -0
  317. package/dist/components/stream/responsiveSize.d.ts +17 -0
  318. package/dist/components/stream/sceneCursor.d.ts +41 -0
  319. package/dist/components/stream/sceneRevisionDiagnostics.d.ts +1 -1
  320. package/dist/components/stream/svgOverlayUtils.d.ts +22 -1
  321. package/dist/components/stream/types.d.ts +33 -13
  322. package/dist/components/stream/useCanvasFrameHost.d.ts +12 -1
  323. package/dist/components/stream/useFrame.d.ts +24 -1
  324. package/dist/components/stream/useResponsiveSize.d.ts +6 -1
  325. package/dist/components/stream/useStalenessCheck.d.ts +1 -1
  326. package/dist/components/stream/xyFrameAxisTypes.d.ts +20 -4
  327. package/dist/components/stream/xyFrameCursorInteraction.d.ts +6 -0
  328. package/dist/components/stream/xySceneBuilders/swarmScene.d.ts +1 -1
  329. package/dist/components/stream/xySceneBuilders/types.d.ts +6 -26
  330. package/dist/components/types/legendTypes.d.ts +6 -0
  331. package/dist/components/types/marginType.d.ts +7 -8
  332. package/dist/controls.min.js +1 -1
  333. package/dist/controls.module.min.js +1 -1
  334. package/dist/forceLayoutWorker.js +1 -1
  335. package/dist/geo.min.js +1 -1
  336. package/dist/geo.module.min.js +1 -1
  337. package/dist/network.min.js +1 -1
  338. package/dist/network.module.min.js +1 -1
  339. package/dist/ordinal.min.js +1 -1
  340. package/dist/ordinal.module.min.js +1 -1
  341. package/dist/physics-matter.module.min.js +1 -1
  342. package/dist/physics-rapier.module.min.js +1 -1
  343. package/dist/physics.min.js +1 -1
  344. package/dist/physics.module.min.js +1 -1
  345. package/dist/physicsWorker.js +1 -1
  346. package/dist/processSankeyLayoutWorker.js +1 -1
  347. package/dist/realtime.min.js +1 -1
  348. package/dist/realtime.module.min.js +1 -1
  349. package/dist/rough.min.js +1 -1
  350. package/dist/rough.module.min.js +1 -1
  351. package/dist/semiotic-ai-core.d.ts +13 -4
  352. package/dist/semiotic-ai-core.min.js +1 -1
  353. package/dist/semiotic-ai-core.module.min.js +1 -1
  354. package/dist/semiotic-ai.d.ts +16 -9
  355. package/dist/semiotic-ai.min.js +1 -1
  356. package/dist/semiotic-ai.module.min.js +1 -1
  357. package/dist/semiotic-client-cjs-shared.min.js +1 -0
  358. package/dist/semiotic-client-glyph.module.min.js +2 -0
  359. package/dist/semiotic-client-responsive.module.min.js +2 -0
  360. package/dist/semiotic-client-shared.module.min.js +2 -0
  361. package/dist/semiotic-custom-layout-selection-cjs-shared.min.js +2 -0
  362. package/dist/semiotic-data.min.js +1 -1
  363. package/dist/semiotic-data.module.min.js +1 -1
  364. package/dist/semiotic-experimental-auxiliary.module.min.js +2 -0
  365. package/dist/semiotic-experimental-node-auxiliary.module.min.js +2 -0
  366. package/dist/semiotic-experimental-node.module.min.js +2 -0
  367. package/dist/semiotic-experimental-react-shared.module.min.js +2 -0
  368. package/dist/semiotic-experimental-vacp.min.js +1 -1
  369. package/dist/semiotic-experimental-vacp.module.min.js +1 -1
  370. package/dist/semiotic-experimental.d.ts +1 -1
  371. package/dist/semiotic-experimental.min.js +1 -1
  372. package/dist/semiotic-experimental.module.min.js +1 -1
  373. package/dist/semiotic-geo.d.ts +4 -1
  374. package/dist/semiotic-network.d.ts +7 -4
  375. package/dist/semiotic-ordinal.d.ts +4 -1
  376. package/dist/semiotic-physics.d.ts +11 -4
  377. package/dist/semiotic-realtime-core.d.ts +11 -4
  378. package/dist/semiotic-realtime-core.min.js +2 -1
  379. package/dist/semiotic-realtime-core.module.min.js +2 -1
  380. package/dist/semiotic-realtime-react.d.ts +4 -3
  381. package/dist/semiotic-realtime-react.min.js +1 -1
  382. package/dist/semiotic-realtime-react.module.min.js +1 -1
  383. package/dist/semiotic-realtime.d.ts +3 -1
  384. package/dist/semiotic-recipes-core-cjs-base.min.js +1 -0
  385. package/dist/semiotic-recipes-core.d.ts +7 -5
  386. package/dist/semiotic-recipes-core.min.js +9 -1
  387. package/dist/semiotic-recipes-core.module.min.js +1 -1
  388. package/dist/semiotic-recipes-geo-cjs.min.js +1 -0
  389. package/dist/semiotic-recipes-react.min.js +1 -1
  390. package/dist/semiotic-recipes-react.module.min.js +1 -1
  391. package/dist/semiotic-recipes.min.js +7 -1
  392. package/dist/semiotic-recipes.module.min.js +2 -1
  393. package/dist/semiotic-server-edge-node.module.min.js +1 -0
  394. package/dist/semiotic-server-edge.d.ts +3 -2
  395. package/dist/semiotic-server-edge.min.js +1 -1
  396. package/dist/semiotic-server-edge.module.min.js +1 -1
  397. package/dist/semiotic-server-node.min.js +1 -1
  398. package/dist/semiotic-server-node.module.min.js +1 -1
  399. package/dist/semiotic-server.d.ts +3 -2
  400. package/dist/semiotic-themes-core.d.ts +5 -48
  401. package/dist/semiotic-themes-core.min.js +1 -1
  402. package/dist/semiotic-themes-core.module.min.js +1 -1
  403. package/dist/semiotic-themes-react.min.js +1 -1
  404. package/dist/semiotic-themes-react.module.min.js +1 -1
  405. package/dist/semiotic-themes.min.js +1 -1
  406. package/dist/semiotic-themes.module.min.js +1 -1
  407. package/dist/semiotic-utils-core.d.ts +11 -5
  408. package/dist/semiotic-utils-core.min.js +1 -1
  409. package/dist/semiotic-utils-core.module.min.js +1 -1
  410. package/dist/semiotic-utils-react.d.ts +2 -0
  411. package/dist/semiotic-utils-react.min.js +1 -1
  412. package/dist/semiotic-utils-react.module.min.js +1 -1
  413. package/dist/semiotic-utils.min.js +2 -1
  414. package/dist/semiotic-utils.module.min.js +2 -1
  415. package/dist/semiotic-value.min.js +1 -1
  416. package/dist/semiotic-value.module.min.js +1 -1
  417. package/dist/semiotic-xy.d.ts +4 -1
  418. package/dist/semiotic.d.ts +68 -25
  419. package/dist/semiotic.min.js +1 -1
  420. package/dist/semiotic.module.min.js +1 -1
  421. package/dist/server.min.js +1 -1
  422. package/dist/server.module.min.js +1 -1
  423. package/dist/xy.min.js +1 -1
  424. package/dist/xy.module.min.js +1 -1
  425. package/package.json +53 -19
  426. package/dist/__tests__/scenarios/mcpProtocolTypes.d.ts +0 -20
  427. package/dist/chunk-OrdinalBrushOverlay-PXHQYDB2.module.min.js +0 -2
  428. package/dist/chunk-XYBrushOverlay-ECZJJLAJ.module.min.js +0 -1
  429. package/dist/chunk-XYBrushOverlay-EP2SV3UI.module.min.js +0 -2
  430. package/dist/chunk-chartContainerDataAudit-IQ3NBN3Q.module.min.js +0 -2
  431. package/dist/chunk-chunk-2B3AIKUZ.module.min.js +0 -2
  432. package/dist/chunk-chunk-2CXCXRB4.module.min.js +0 -1
  433. package/dist/chunk-chunk-3GCILWPB.module.min.js +0 -2
  434. package/dist/chunk-chunk-46KRGJQP.module.min.js +0 -1
  435. package/dist/chunk-chunk-4ITOQRXM.module.min.js +0 -2
  436. package/dist/chunk-chunk-4MLLQUGW.module.min.js +0 -2
  437. package/dist/chunk-chunk-57RBPDBQ.module.min.js +0 -2
  438. package/dist/chunk-chunk-5UKL5W76.module.min.js +0 -2
  439. package/dist/chunk-chunk-5VVNW5AZ.module.min.js +0 -1
  440. package/dist/chunk-chunk-66PCWJUG.module.min.js +0 -1
  441. package/dist/chunk-chunk-6V5VQVCT.module.min.js +0 -2
  442. package/dist/chunk-chunk-7LE56WAE.module.min.js +0 -2
  443. package/dist/chunk-chunk-7T25U75Z.module.min.js +0 -2
  444. package/dist/chunk-chunk-ACLDBMRH.module.min.js +0 -2
  445. package/dist/chunk-chunk-AF53TBSN.module.min.js +0 -2
  446. package/dist/chunk-chunk-BTZYH2IE.module.min.js +0 -1
  447. package/dist/chunk-chunk-BWV55BZK.module.min.js +0 -2
  448. package/dist/chunk-chunk-BZNOAHJV.module.min.js +0 -2
  449. package/dist/chunk-chunk-CD6PVVS3.module.min.js +0 -2
  450. package/dist/chunk-chunk-DTSNLGRK.module.min.js +0 -2
  451. package/dist/chunk-chunk-FC3NZWYR.module.min.js +0 -2
  452. package/dist/chunk-chunk-FEPXDKJP.module.min.js +0 -1
  453. package/dist/chunk-chunk-FJ76HWQZ.module.min.js +0 -1
  454. package/dist/chunk-chunk-FRGBMTZR.module.min.js +0 -1
  455. package/dist/chunk-chunk-G75OPF5N.module.min.js +0 -2
  456. package/dist/chunk-chunk-H5IFO6CU.module.min.js +0 -2
  457. package/dist/chunk-chunk-HADHLMY5.module.min.js +0 -1
  458. package/dist/chunk-chunk-HBFA4NN6.module.min.js +0 -1
  459. package/dist/chunk-chunk-HCNDE26Q.module.min.js +0 -2
  460. package/dist/chunk-chunk-IY7RYD4S.module.min.js +0 -1
  461. package/dist/chunk-chunk-J3QOW4OE.module.min.js +0 -0
  462. package/dist/chunk-chunk-J3XWETBJ.module.min.js +0 -2
  463. package/dist/chunk-chunk-JJ4BSUYL.module.min.js +0 -2
  464. package/dist/chunk-chunk-JRHXQGEV.module.min.js +0 -2
  465. package/dist/chunk-chunk-KTWEBFMX.module.min.js +0 -2
  466. package/dist/chunk-chunk-L6FFYGYS.module.min.js +0 -1
  467. package/dist/chunk-chunk-LJDH3WV3.module.min.js +0 -2
  468. package/dist/chunk-chunk-LSJUXBMF.module.min.js +0 -1
  469. package/dist/chunk-chunk-N3Q33XCB.module.min.js +0 -2
  470. package/dist/chunk-chunk-NWIGA3UK.module.min.js +0 -1
  471. package/dist/chunk-chunk-OG3TTJGJ.module.min.js +0 -2
  472. package/dist/chunk-chunk-OZK46A5U.module.min.js +0 -1
  473. package/dist/chunk-chunk-PMR47KRY.module.min.js +0 -2
  474. package/dist/chunk-chunk-Q2YADC2V.module.min.js +0 -2
  475. package/dist/chunk-chunk-QQJNG23C.module.min.js +0 -2
  476. package/dist/chunk-chunk-RGJ6TKAH.module.min.js +0 -2
  477. package/dist/chunk-chunk-ROP4HI7H.module.min.js +0 -2
  478. package/dist/chunk-chunk-SFLUSZ73.module.min.js +0 -2
  479. package/dist/chunk-chunk-TCMHJWFJ.module.min.js +0 -1
  480. package/dist/chunk-chunk-TSCFL235.module.min.js +0 -1
  481. package/dist/chunk-chunk-U66USBWU.module.min.js +0 -1
  482. package/dist/chunk-chunk-UEZ6SHW5.module.min.js +0 -2
  483. package/dist/chunk-chunk-UOQRPGPK.module.min.js +0 -2
  484. package/dist/chunk-chunk-VUWYT7DY.module.min.js +0 -2
  485. package/dist/chunk-chunk-W5HWGQMD.module.min.js +0 -2
  486. package/dist/chunk-chunk-WFHZHWT7.module.min.js +0 -1
  487. package/dist/chunk-chunk-WGROBM3I.module.min.js +0 -2
  488. package/dist/chunk-chunk-WSDJFBKX.module.min.js +0 -2
  489. package/dist/chunk-chunk-YHNZCPOZ.module.min.js +0 -2
  490. package/dist/chunk-chunk-YWZB3KPI.module.min.js +0 -2
  491. package/dist/chunk-statisticalOverlays-HMYYSGPE.module.min.js +0 -2
  492. package/dist/components/stream/test-utils/frameScheduler.d.ts +0 -12
  493. package/dist/components/stream/test-utils/revisionConsumption.d.ts +0 -13
  494. package/dist/test-utils/canvasMock.d.ts +0 -86
  495. package/dist/test-utils/capturedFrameProps.d.ts +0 -67
  496. package/dist/test-utils/frameMock.d.ts +0 -81
  497. package/dist/test-utils/ordinalFixtures.d.ts +0 -48
  498. /package/dist/{chunk-chunk-JJ2OOIET.module.min.js → c-GGISSW5E.min.js} +0 -0
  499. /package/dist/{chunk-chunk-SIRIJ3DY.module.min.js → c-N4G2L7ID.min.js} +0 -0
  500. /package/dist/{chunk-chunk-CA3YDW6F.module.min.js → c-S6U5CGT5.min.js} +0 -0
  501. /package/dist/components/recipes/{mobileAnnotationStrategy.d.ts → mobileAnnotationBehavior.d.ts} +0 -0
@@ -1 +1 @@
1
- import{scaleTime as t}from"d3-scale";var e={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function n(t="static"){return e[t]??e.static}var o=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function s(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:o.has(t.kind)?"fatal":"warn"}function i(t){const{desired:e,minGaps:n,weights:o}=t,s=e.length;if(0===s)return[];if(n.length!==Math.max(0,s-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const i=new Array(s).fill(0);for(let t=1;t<s;t++)i[t]=i[t-1]+Math.max(0,Number.isFinite(n[t-1])?n[t-1]:0);const a=[];for(let t=0;t<s;t++){const n=Math.max(Number.EPSILON,Number.isFinite(o?.[t])?o[t]:1),s=(Number.isFinite(e[t])?e[t]:0)-i[t];for(a.push({start:t,end:t,weight:n,mean:s});a.length>1;){const t=a[a.length-1],e=a[a.length-2];if(e.mean<=t.mean)break;const n=e.weight+t.weight;a.splice(a.length-2,2,{start:e.start,end:t.end,weight:n,mean:(e.mean*e.weight+t.mean*t.weight)/n})}}const r=Number.isFinite(t.min)?t.min:-1/0,l=Number.isFinite(t.max)?t.max-i[s-1]:1/0,c=l<r?r:l,u=new Array(s);for(const t of a){const e=Math.max(r,Math.min(c,t.mean));for(let n=t.start;n<=t.end;n++)u[n]=e+i[n]}return u}function a(t,e){let n=0,o=t.length-1,s=-1;for(;n<=o;){const i=n+o>>>1;t[i].at<=e?(s=i,n=i+1):o=i-1}return s<0?{at:e,before:0,after:0}:t[s]}function r(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const n=[],o=[0];for(let s=0;s<t.length-1;s++){const i=t[s],r=t[s+1],l=[...new Set([...i.map(t=>t.at),...r.map(t=>t.at)])].sort((t,e)=>t-e);let c=0;for(const t of l){const e=a(i,t),n=a(r,t);c=Math.max(c,e.after+n.before)}n.push(c),o.push(o[o.length-1]+c+e)}return{adjacentClearance:n,positions:o}}function l(t,e,n,o={}){let s=[...t];if(s.length<=1)return s;let i=[...s],a=n(s),r=1;const l=Math.max(0,o.passes??6),c=Math.max(1,o.maxEvaluations??1/0);for(let t=0;t<l&&r<c;t++){const t=new Map(s.map((t,e)=>[t,e])),l=new Map,c=new Map;for(const n of e){const e=t.get(n.source),o=t.get(n.target);if(null==e||null==o)continue;const s=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;l.set(n.source,(l.get(n.source)??0)+o*s),c.set(n.source,(c.get(n.source)??0)+s),l.set(n.target,(l.get(n.target)??0)+e*s),c.set(n.target,(c.get(n.target)??0)+s)}s=s.map((t,e)=>({item:t,index:e,barycenter:(l.get(t)??e)/(c.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(o.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=n(s);if(r++,u<a)a=u,i=[...s];else if(u===a)break}return i}function c(t,e,n={}){const o=[...t],s=o.length;if(s<=1||s>(n.maxItems??8))return o;const i=Math.max(1,n.maxEvaluations??1/0);let a=0,r=[...o],l=1/0;const c=()=>{if(a>=i)return;const t=e(o);a++,t<l&&(l=t,r=[...o])};c();const u=new Array(s).fill(0);let f=0;for(;f<s&&a<i;)if(u[f]<f){const t=f%2==0?0:u[f];[o[t],o[f]]=[o[f],o[t]],c(),u[f]++,f=0}else u[f]=0,f++;return r}function u(t,e){return t<e?-1:t>e?1:0}function f(t){return t.occupants.map(t=>t.id).sort(u).join("\0")}function d(t,e,n=0){return t.slice(0,-1).map((o,s)=>{const i=t[s+1];return null!=o.group&&o.group===i.group?n:e})}function g(t,e){return t.map(t=>{const n=new Map;for(const o of t.occupants){const t=e[o.id];if(t)for(const e of t.samples){const t=n.get(e.t)??{before:0,after:0},o=e.boundaryOffset??0;n.set(e.t,{before:Math.max(t.before,e.topMass-o),after:Math.max(t.after,e.botMass+o)})}}return[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function m(t,e,n){if(0===t.length)return[];const{padding:o,plotH:s,valueScale:i}=n,a=n.stackValueScale??i,r=d(t,o,n.groupPadding??0),l=[o+t[0].peak.topPeak*a];for(let n=1;n<t.length;n++)l.push(l[n-1]+e[n-1]*a+r[n-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*a+o;if(c>s&&c>0){const t=s/c;for(let e=0;e<l.length;e++)l[e]*=t}return l}function p(t,e){const n=(t.boundaryOffset??0)*e,o=t.value*e;if("out"===t.kind){const s=t.sideMassBefore*e;return n+("top"===t.side?o/2-s:s-o/2)}const s=t.sideMassAfter*e;return n+("top"===t.side?o/2-s:s-o/2)}function h(t,e,n,o,s,a){const l=a.adjacentClearance?[...a.adjacentClearance]:r(g(o,n)).adjacentClearance,c=m(o,l,a);let u="hug"===a.lanePlacement?function(t,e,n,o,s,a,r){const l=t.length;if(0===l)return[];const{padding:c,plotH:u,valueScale:f}=r,g=d(t,c,r.groupPadding??0),h=s.map((t,e)=>t*f+g[e]),b=c+t[0].peak.topPeak*f,M=u-c-t[l-1].peak.botPeak*f;if(M-b<=h.reduce((t,e)=>t+e,0)+1e-6)return m(t,s,r);let y=1===l?[(b+M)/2]:[...a];for(let t=0;t<12;t++){const t=new Array(l).fill(0),s=new Array(l).fill(0);for(const i of n){const n=e[i.source],a=e[i.target];if(null==n||null==a||n===a)continue;const r=o[i.source]?.localAttachments.get(i.id),l=o[i.target]?.localAttachments.get(i.id);if(!r||!l)continue;const c=i.value>0&&Number.isFinite(i.value)?i.value:1,u=p(r,f),d=p(l,f);t[n]+=(y[a]+d-u)*c,s[n]+=c,t[a]+=(y[n]+u-d)*c,s[a]+=c}const a=i({desired:y.map((e,n)=>0===s[n]?e:.45*e+t[n]/s[n]*.55),minGaps:h,weights:s.map(t=>Math.max(1,t)),min:b,max:M});let r=0;for(let t=0;t<l;t++)r=Math.max(r,Math.abs(a[t]-y[t]));if(y=a,r<.01)break}return y}(o,s,e,n,l,c,a):[...c];if("hug"===a.lanePlacement){const n=e=>{const n={};for(const o of t)n[o.id]=e[s[o.id]];return n};b(n(u),e)>b(n(c),e)+1e-6&&(u=[...c])}const f={};for(const e of t)f[e.id]=u[s[e.id]];let h=1/0,M=-1/0;for(const e of t){const t=f[e.id],o=n[e.id];Number.isFinite(t)&&o&&(h=Math.min(h,t-o.topPeak*a.valueScale),M=Math.max(M,t+o.botPeak*a.valueScale))}return{adjacentClearance:l,centerlines:f,slotCenter:u,stackCenter:c,verticalUtilization:Number.isFinite(h)&&Number.isFinite(M)&&a.plotH>0?Math.max(0,Math.min(1,(M-h)/a.plotH)):0}}function b(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];Number.isFinite(e)&&Number.isFinite(s)&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}function M(t,e){const n=t?.samples;if(!n||0===n.length||e<n[0].t)return{top:0,bot:0};let o=0,s=n.length-1,i=0;for(;o<=s;){const t=o+s>>>1;n[t].t<=e?(i=t,o=t+1):s=t-1}const a=n[i].boundaryOffset??0;return{top:n[i].topMass-a,bot:n[i].botMass+a}}function y(t,e,n,o,s){const i=1-s;return i*i*i*t+3*i*i*s*e+3*i*s*s*n+s*s*s*o}function x(t,e){let n=0,o=1;for(let s=0;s<28;s++){const s=(n+o)/2;y(0,e,e,1,s)<t?n=s:o=s}return(n+o)/2}function w(t,e,n){const o=e+p(t,n),s=t.value*n/2;return[o-s,o+s]}function v(t,e,n,o){return Math.max(0,Math.min(e,o)-Math.max(t,n))/Math.max(1e-9,e-t)}function k(t,e,n,o,s,i,a){const{valueScale:r,domain:l,mode:c="quality"}=a,u="source"===a.ribbonLane?.85:"target"===a.ribbonLane?.15:.5;let f=0;for(const a of t){const t=o[a.source],d=o[a.target];if(null==t||null==d||Math.abs(t-d)<2)continue;const g=e[a.source]?.localAttachments.get(a.id),m=e[a.target]?.localAttachments.get(a.id);if(!g||!m)continue;const p=Math.max(a.startTime,l?.[0]??-1/0),h=Math.min(a.endTime,l?.[1]??1/0);if(!(h>p))continue;const[b,k]=w(g,s[a.source],r),[T,S]=w(m,s[a.target],r),N=Math.min(t,d)+1,O=Math.max(t,d)-1;for(let t=N;t<=O;t++){const o=n[t];if(!o)continue;const l=[p,h];if("quality"===c)for(const t of o.occupants)for(const n of e[t.id]?.samples??[])n.t>p&&n.t<h&&l.push(n.t);const d=t=>{const n=x((t-p)/(h-p),u),l=y(b,b,T,T,n),c=y(k,k,S,S,n);let f=0;for(const n of o.occupants){if(n.id===a.source||n.id===a.target)continue;const o=i[n.id];if(null!=o?.start&&t<o.start)continue;if(null!=o?.end&&t>o.end)continue;const u=M(e[n.id],t),d=s[n.id];f=Math.max(f,v(l,c,d-u.top*r,d+u.bot*r))}return f},g=[...new Set(l)].sort((t,e)=>t-e);let m=0;for(let t=0;t<g.length-1;t++){const e=g[t],n=g[t+1]-e;m+=(d(e+.25*n)+d(e+.5*n)+d(e+.75*n))/3*n}f+=m/(h-p)*(a.value>0?a.value:1)}}return f}function T(t,e,n,o,s,i,a,r,l,c,u="both",f){return{crossings:t,weightedLength:e,pixelLength:b(a,n),transitOcclusion:k(n,o,s,i,a,r,{valueScale:l,ribbonLane:u,domain:f,mode:"quality"}),verticalUtilization:c}}function S(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function N(t,e){return t.map(t=>({t:S(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function O(t,e,n){const o=e+(t.boundaryOffset??0)*n,s=t.value*n;if("out"===t.kind){const e=t.sideMassBefore*n;if("top"===t.side){const t=o-e;return[t,t+s]}const i=o+e;return[i-s,i]}const i=t.sideMassAfter*n;if("top"===t.side){const t=o-i;return[t,t+s]}const a=o+i;return[a-s,a]}function P(t,e,n,o,s="temporal"){const i=e.incoming[t.id],a=e.outgoing[t.id],r=[];for(const t of i)r.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:n.get(t.id).targetSide});for(const t of a)r.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:n.get(t.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{r.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(!o||!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 n=o.get(t.edge.id)?.target,s=o.get(e.edge.id)?.target;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?n-s:s-n:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const n=o.get(t.edge.id)?.source,s=o.get(e.edge.id)?.source;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?s-n:n-s:0}return 0})(t,e)||u(t.edge?.id??"",e.edge?.id??"")||u(t.side,e.side)||t.delta-e.delta)},f=r.length?function(t,e=1/0){let n=e;for(const e of t)e<n&&(n=e);return n}(r.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,g=null!=d?d-1:null!=f&&Number.isFinite(f)?f-1:null;c();let m=null,p=0;for(const t of r)t.time!==m&&(m=t.time,p=0),t.sequence=p++;const h=t=>({time:t.time,phase:0,sequence:t.sequence??0}),b=[];let M=0,y=0;for(const t of r)if("out"===t.kind){const e=Math.abs(t.delta);let n=e-("top"===t.side?M:y);if(n>0){const e="top"===t.side?"bot":"top",o="top"===e?M:y,s=Math.min(n,o);if(s>0){const o=h(t);b.push({...o,delta:-s,kind:"transfer-out",side:e}),b.push({...o,delta:+s,kind:"transfer-in",side:t.side}),"top"===e?M-=s:y-=s,"top"===t.side?M+=s:y+=s,n-=s}n>0&&null!==g&&(b.push({time:g,delta:+n,kind:"create",side:t.side}),"top"===t.side?M+=n:y+=n)}"top"===t.side?M-=e:y-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?M+=e:y+=e}r.push(...b),c();let x=0,w=0,v=0,k=0,T=0,S=0;const N=[],O=new Map,P=t=>{N.push({t:t,topMass:x,botMass:w,...Math.abs(v)>1e-12&&{boundaryOffset:v}})},F=()=>{k=Math.max(k,x+w),T=Math.max(T,x-v),S=Math.max(S,w+v)};for(const t of r){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?x:w,n=e+t.delta;O.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:n,kind:t.kind,value:Math.abs(t.delta),...Math.abs(v)>1e-12&&{boundaryOffset:v}})}"top"===t.side?x+=t.delta:w+=t.delta,"transfer-in"===t.kind?(v+="top"===t.side?t.delta:-t.delta,F(),P(t.time)):"transfer-out"!==t.kind&&(F(),"out"===t.kind&&x+w<=1e-12&&(v=0),P(t.time))}const A=[];let I=0;for(;I<N.length;){let t=I;for(;t+1<N.length&&N[t+1].t===N[I].t;)t++;A.push(N[I]);for(let e=I+1;e<=t;e++){const t=A[A.length-1];N[e].topMass===t.topMass&&N[e].botMass===t.botMass&&(N[e].boundaryOffset??0)===(t.boundaryOffset??0)||A.push(N[e])}I=t+1}const E=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let $=null;for(const t of a)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime&&(null===$||t.systemInTime<$)&&($=t.systemInTime);let L=null;for(const t of i)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===L||t.systemOutTime>L)&&(L=t.systemOutTime);if(A.length>0){const t=A[A.length-1],e=Math.max(null!=E?E:-1/0,null!=L?L:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&A.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const n=A[0],o=A.find(t=>t.topMass+t.botMass>0);let s,i=1/0;null!=d&&Number.isFinite(d)&&d<n.t&&n.topMass+n.botMass>0&&(i=d,s=n),o&&null!=$&&Number.isFinite($)&&$<o.t&&$<i&&(i=$,s=o),s&&Number.isFinite(i)&&A.unshift({t:i,topMass:s.topMass,botMass:s.botMass,...null!=s.boundaryOffset&&{boundaryOffset:s.boundaryOffset}})}let B=A;if("max"===s&&null!=d&&null!=E&&E>d){let t,e=0;for(const n of A){const o=n.topMass+n.botMass;o>e&&(e=o,t=n)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};B=[...A.filter(t=>t.t<d),{t:d,...e},{t:E,...e},...A.filter(t=>t.t>E)]}}return{samples:B,peak:k,topPeak:T,botPeak:S,localAttachments:O}}function F(t){const e={};return t.forEach((t,n)=>{for(const o of t.occupants)e[o.id]=n}),e}function A(t,e,n){t.splice(0,t.length,...n);const o=F(n);for(const t of Object.keys(e))delete e[t];Object.assign(e,o)}function I(t){const e=new Map,n=[];t.forEach((t,o)=>{if(!t.group)return void n.push({anchor:o,stableId:f(t),slots:[t]});const s=e.get(t.group)??{indexes:[],slots:[]};s.indexes.push(o),s.slots.push(t),e.set(t.group,s)});for(const[t,o]of e)n.push({anchor:o.indexes.reduce((t,e)=>t+e,0)/o.indexes.length,stableId:`${t}\0${o.slots.map(f).join("\0")}`,slots:o.slots});return n.sort((t,e)=>t.anchor-e.anchor||u(t.stableId,e.stableId))}function E(t){return t.some(t=>t.group)?I(t).flatMap(t=>t.slots):[...t]}function $(t){return t.flatMap(t=>t.slots)}function L(t,e,n){const o=new Map;return t.forEach((t,e)=>{for(const n of t.slots)o.set(n,e)}),t.map((t,s)=>{if(t.slots.length<=1)return t;const i=new Map;for(const e of t.slots)i.set(e,0);for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(null==e||null==n)continue;const a=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===s&&n!==s){const e=n>s?1:-1;i.set(t.source,(i.get(t.source)??0)+a*e)}else if(n===s&&e!==s){const n=e>s?1:-1;i.set(t.target,(i.get(t.target)??0)+a*n)}}const a=[...t.slots].sort((t,e)=>(i.get(t)??0)-(i.get(e)??0)||n(t,e));return{...t,slots:a}})}function B(t,e){t.some(t=>t.group)&&A(t,e,E(t))}function z(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.max(t.startTime,e.startTime)<Math.min(t.endTime,e.endTime)}function C(t,e){return function(t,e,n=()=>!0){let o=0;for(let s=0;s<t.length;s++){const[i,a]=e(t[s]);for(let r=s+1;r<t.length;r++){if(!n(t[s],t[r]))continue;const[l,c]=e(t[r]);(i-l)*(a-c)<0&&o++}}return o}(e,e=>[t[e.source],t[e.target]],z)}function X(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];null!=e&&null!=s&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}function H(t,e,n){const[o,s]=n.get(t.first),[i,a]=n.get(t.second);return(e.get(o)-e.get(i))*(e.get(s)-e.get(a))<0?1:0}var D=t=>{let e=1;for(let n=2;n<=t;n++)e*=n;return e},j=828*D(8),Y=3e3;function q(t,e,n,o,s,i,a){const d=[...s],m=new Map(s.map(t=>[t,f(t)])),p=new Map;for(const t of s)for(const e of t.occupants)p.set(e.id,t);const M=new Map,y=[];for(const t of e){const e=p.get(t.source),n=p.get(t.target);e&&n&&(M.set(t,[e,n]),e!==n&&y.push({source:e,target:n,weight:t.value}))}const x=[];for(let t=0;t<e.length;t++)if(M.has(e[t]))for(let n=t+1;n<e.length;n++){if(!M.has(e[n])||!z(e[t],e[n]))continue;const o=new Set([...M.get(e[t]),...M.get(e[n])]);x.push({index:x.length,first:e[t],second:e[n],involvedSlots:o})}const w=new Map;for(const t of s)w.set(t,[]);for(const t of x)for(const e of t.involvedSlots)w.get(e)?.push(t);const v=new Uint32Array(x.length);let T=0;const S=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),N=a.plotH/Math.max(1,s.length),O=s.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),P=Math.max(1,S)*(Math.max(1,a.plotH)+N*Math.max(O,s.length)+1e-6*Math.max(1,s.length-1))+1,B=4*N,C={fullCrossing:0,localCrossing:0},q=new Map,V=(t,e)=>{let o=q.get(t);o||(o=new Map,q.set(t,o));const s=o.get(e);if(null!=s)return s;const i=function(t,e,n){return r(g([t,e],n)).adjacentClearance[0]??0}(t,e,n);return o.set(e,i),i},U=new Map(s.map((t,e)=>[t,e])),W=e.flatMap(t=>{const e=M.get(t);return e?[{source:U.get(e[0]),target:U.get(e[1]),weight:t.value>0?t.value:1}]:[]}),R=new Map;for(const t of e){const e=M.get(t);e&&R.set(t,{source:U.get(e[0]),target:U.get(e[1])})}const _=new Map,G=new Map;for(const t of e)_.has(t.source)||_.set(t.source,new Set),G.has(t.target)||G.set(t.target,new Set),_.get(t.source).add(t.target),G.get(t.target).add(t.source);const Z=e.flatMap(t=>{if(!(t=>{const e=new Set([..._.get(t.source)??[],...G.get(t.source)??[]]),n=new Set([..._.get(t.target)??[],...G.get(t.target)??[]]);return 1===_.get(t.source)?.size&&_.get(t.source).has(t.target)||1===e.size&&e.has(t.target)||1===n.size&&n.has(t.source)})(t))return[];const e=R.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),Q=t=>{let e=0;for(const n of Z)e+=Math.max(0,Math.abs(t[n.source]-t[n.target])-1)*n.weight;return e*B},J=t=>{const e=new Int16Array(s.length);for(let n=0;n<t.length;n++)e[U.get(t[n])]=n;return Q(e)},K=x.map(t=>{const e=R.get(t.first),n=R.get(t.second);return[e.source,e.target,n.source,n.target]}),tt=new Int16Array(s.length),et=new Float64Array(s.length),nt=new Float64Array(s.length+1),ot=t=>{for(let e=0;e<t.length;e++)tt[U.get(t[e])]=e;let e=0;for(const[t,n,o,s]of K)(tt[t]-tt[o])*(tt[n]-tt[s])<0&&e++;if(t.length>0){const e=U.get(t[0]);et[e]=a.padding+t[0].peak.topPeak*a.valueScale;for(let e=1;e<t.length;e++){const n=U.get(t[e-1]),o=U.get(t[e]);et[o]=et[n]+V(t[e-1],t[e])*a.valueScale+a.padding}const n=U.get(t[t.length-1]),o=et[n]+t[t.length-1].peak.botPeak*a.valueScale+a.padding;if(o>a.plotH&&o>0){const t=a.plotH/o;for(let e=0;e<et.length;e++)et[e]*=t}}nt[0]=0;for(let e=0;e<t.length;e++)nt[e+1]=nt[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0,o=0,s=0;for(const t of W){const e=tt[t.source],i=tt[t.target];if(n+=Math.abs(e-i)*t.weight,o+=Math.abs(et[t.source]-et[t.target])*t.weight,Math.abs(e-i)>=2){const n=Math.min(e,i)+1,o=Math.max(e,i);s+=(nt[o]-nt[n])*t.weight}}return e*P+o+s*N+Q(tt)+1e-6*n},st=(t,n)=>{const o=new Array(t.length+1).fill(0);for(let e=0;e<t.length;e++)o[e+1]=o[e]+t[e].peak.topPeak+t[e].peak.botPeak;let s=0;for(const t of e){const e=n[t.source],i=n[t.target];if(null==e||null==i||Math.abs(e-i)<2)continue;const a=Math.min(e,i)+1;s+=(o[Math.max(e,i)]-o[a])*(t.value>0?t.value:1)}return s},it=o=>{const s=F(o),i=o.slice(0,-1).map((t,e)=>V(t,o[e+1])),r=h(t,e,n,o,s,{plotH:a.plotH,padding:a.padding,valueScale:a.valueScale,lanePlacement:a.lanePlacement??"stack",groupPadding:a.groupPadding,adjacentClearance:i});return{map:s,geometry:r,weightedLength:X(s,e),pixelLength:b(r.centerlines,e),transitOcclusion:st(o,s)}},at=(t,e,n)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*P+e.pixelLength+e.transitOcclusion*N+J(n)+1e-6*e.weightedLength}),rt=(t,e)=>{let n=e;if(null==n){const e=new Map(t.map((t,e)=>[t,e]));n=x.reduce((t,n)=>t+H(n,e,M),0),C.fullCrossing++}return at(n,it(t),t)},lt=(t,s,i="quality")=>{let r=s;if(null==r){const e=new Map(t.map((t,e)=>[t,e]));r=x.reduce((t,n)=>t+H(n,e,M),0),C.fullCrossing++}const l=it(t);return at(r,{...l,transitOcclusion:k(e,n,t,l.map,l.geometry.centerlines,o,{valueScale:a.valueScale,ribbonLane:a.ribbonLane,domain:a.domain,mode:i})},t)};let ct=[...d];const ut=(t,e)=>u(m.get(t),m.get(e)),ft=function(t){const e=new Set;for(const n of t)if(n.group){if(e.has(n.group))return!0;e.add(n.group)}return!1}(ct),dt=t=>{const e=(t=>{const e=l(t,y,t=>rt(t).cost,{passes:6,compare:ut,maxEvaluations:Y});let n=rt(e),o=Y;for(let t=0;t<6&&o>0;t++){let s=!1;const i=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&i.reverse();for(const t of i){if(o--<=0)break;const i=e[t],a=e[t+1],r=new Map(e.map((t,e)=>[t,e]));let l=0;const c=[];T++;for(const t of[...w.get(i)??[],...w.get(a)??[]])v[t.index]!==T&&(v[t.index]=T,c.push(t),l+=H(t,r,M));[e[t],e[t+1]]=[a,i];const u=new Map(r);u.set(i,t+1),u.set(a,t);let f=0;for(const t of c)f+=H(t,u,M);C.localCrossing+=c.length;const d=rt(e,n.crossings-l+f);d.cost<n.cost?(n=d,s=!0):[e[t],e[t+1]]=[i,a]}if(!s)break}return e})(t);if((t.length<=8?D(t.length)*(t.length+W.length+K.length):1/0)>j)return e;const n=c(t,ot,{maxItems:8,maxEvaluations:5e4}),o=lt(n),s=lt(e);return o.crossings!==s.crossings&&o.crossings<s.crossings?n:e},gt=t=>{let e=I(t);if(e.length<=1)return $(e);const n=t=>rt($(t)).cost;e=I(dt(t)),e=L(e,y,ut);const o=function(t,e){const n=new Map;for(const e of t)for(const t of e.slots)n.set(t,e);const o=new Map;for(const t of e){const e=n.get(t.source),s=n.get(t.target);if(!e||!s||e===s)continue;const i=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,a=e.stableId<s.stableId?`${e.stableId}\0${s.stableId}`:`${s.stableId}\0${e.stableId}`,r=o.get(a);r?r.weight=(r.weight??0)+i:o.set(a,{source:e,target:s,weight:i})}return[...o.values()]}(e,y);e=l(e,o,n,{passes:6,compare:(t,e)=>u(t.stableId,e.stableId),maxEvaluations:Y}),e=function(t,e,n={}){const o=[...t];if(o.length<=1)return o;let s=e(o),i=1;const a=Math.max(0,n.passes??6),r=Math.max(1,n.maxEvaluations??1/0);for(let t=0;t<a&&i<r;t++){let t=!1;for(let n=0;n<o.length-1&&i<r;n++){[o[n],o[n+1]]=[o[n+1],o[n]];const a=e(o);i++,a<s?(s=a,t=!0):[o[n],o[n+1]]=[o[n+1],o[n]]}if(!t)break}return o}(e,n,{passes:8,maxEvaluations:Y});if((e.length<=8?D(e.length)*(e.length+W.length+K.length):1/0)<=j){const t=c(e,t=>ot($(t)),{maxItems:8,maxEvaluations:5e4}),n=$(t),o=$(e),s=lt(n),i=lt(o);s.crossings!==i.crossings?e=s.crossings<i.crossings?t:e:s.cost<i.cost&&(e=t)}return e=L(e,y,ut),$(e)},mt="geometry-refine"===a.mode;if(mt||"crossing-min"!==a.laneOrder&&"crossing-min+inside-out"!==a.laneOrder){if(!mt&&"inside-out"===a.laneOrder)if(ft){const t=I(ct),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),n=[...t].sort((t,n)=>e(n)-e(t)||u(t.stableId,n.stableId)),o=new Array(n.length);let s=Math.floor((n.length-1)/2)-1,i=Math.floor((n.length-1)/2)+1;n.length>0&&(o[Math.floor((n.length-1)/2)]=n[0]);for(let t=1;t<n.length;t++)t%2==1&&i<n.length?o[i++]=n[t]:s>=0?o[s--]=n[t]:o[i++]=n[t];ct=$(o)}else{const t=[...ct].sort((t,e)=>{const n=t.peak.topPeak+t.peak.botPeak;return e.peak.topPeak+e.peak.botPeak-n||ut(t,e)}),e=new Array(t.length);let n=Math.floor((t.length-1)/2)-1,o=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let s=1;s<t.length;s++)s%2==1&&o<t.length?e[o++]=t[s]:n>=0?e[n--]=t[s]:e[o++]=t[s];ct=e}}else ct=ft?gt(ct):dt(ct);if(!mt&&"crossing-min+inside-out"===a.laneOrder&&ct.length>1)if(ft){const t=I(ct);let e=rt($(t)),n=$(t),o=e;const s=Math.floor((t.length-1)/2),i=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),a=[...t].sort((t,e)=>i(e)-i(t)||u(t.stableId,e.stableId));for(const i of a){const a=t.indexOf(i);if(a===s)continue;t.splice(a,1),t.splice(s,0,i);const r=$(t),l=rt(r);l.cost<=e.cost?(e=l,l.cost<o.cost&&(n=r,o=l)):(t.splice(s,1),t.splice(a,0,i))}ct=n}else{let t=rt(ct),e=[...ct],n=t;const o=Math.floor((ct.length-1)/2),s=[...ct].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||ut(t,e));for(const i of s){const s=ct.indexOf(i);if(s===o)continue;ct.splice(s,1),ct.splice(o,0,i);const a=rt(ct);a.cost<=t.cost?(t=a,a.cost<n.cost&&(e=[...ct],n=a)):(ct.splice(o,1),ct.splice(s,0,i))}ct=e}if((mt||"crossing-min"===a.laneOrder||"crossing-min+inside-out"===a.laneOrder)&&ct.length>1)if(ft){let t=I(ct),e=lt($(t),void 0,"score");for(let n=0;n<6&&t.length>1;n++){let n=!1;for(let o=0;o<t.length-1;o++){[t[o],t[o+1]]=[t[o+1],t[o]];const s=$(t),i=lt(s,void 0,"score");i.cost<e.cost?(ct=s,e=i,n=!0):[t[o],t[o+1]]=[t[o+1],t[o]]}if(!n)break}t=L(I(ct),y,ut),ct=$(t)}else{let t=lt(ct,void 0,"score");for(let e=0;e<ct.length-1;e++){const n=ct[e],o=ct[e+1],s=new Map(ct.map((t,e)=>[t,e]));let i=0;const a=[];T++;for(const t of[...w.get(n)??[],...w.get(o)??[]])v[t.index]!==T&&(v[t.index]=T,a.push(t),i+=H(t,s,M));[ct[e],ct[e+1]]=[o,n];const r=new Map(s);r.set(n,e+1),r.set(o,e);let l=0;for(const t of a)l+=H(t,r,M);C.localCrossing+=a.length;const c=lt(ct,t.crossings-i+l,"score");c.cost<t.cost?t=c:[ct[e],ct[e+1]]=[n,o]}}const pt=E(d);ct=E(ct);let ht=lt(ct);const bt=lt(pt);if(mt){const t=J(pt),e=J(ct);(ht.crossings>bt.crossings||ht.crossings===bt.crossings&&e>t+1e-9||ht.cost>bt.cost)&&(ct=pt,ht=bt)}else ht.cost>bt.cost&&(ct=pt,ht=bt);return A(s,i,ct),{before:bt,after:ht,initialOrder:d.map(t=>m.get(t)),evaluations:C}}function V(t,e,n){const o=t.map(t=>{const o=t.occupants.map(t=>({id:t.id,end:n[t.id]?.end??t.end}));let s=0,i=0;for(const t of o){const n=e[t.id];s=Math.max(s,n?.topPeak||0),i=Math.max(i,n?.botPeak||0)}return{occupants:o,peak:{topPeak:s,botPeak:i},...null!=t.group?{group:t.group}:{}}}),s={};return o.forEach((t,e)=>{for(const n of t.occupants)s[n.id]=e}),{slots:o,slotByNode:s}}var U=new Map;var W=1e-9,R=1e5;function _(t,e){let n=1/0,o=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass<=W||(n=Math.min(n,e.t),o=Math.max(o,e.t));return Number.isFinite(n)&&Number.isFinite(o)?(null!=e.start&&(n=Math.max(n,e.start)),null!=e.end&&(o=Math.min(o,e.end)),o>=n?{start:n,end:o}:{start:null,end:null}):{start:null,end:null}}function G(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(t.end<=e.start||e.end<=t.start)}function Z(t,e){return u(t,e)<=0?`${t}\0${e}`:`${e}\0${t}`}function Q(t){const e=new Map,n=new Map;for(const o of t)n.has(o.source)||n.set(o.source,new Set),e.has(o.target)||e.set(o.target,new Set),n.get(o.source).add(o.target),e.get(o.target).add(o.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...n].map(([t,e])=>[t,e.size]))}}function J(t){const e=new Map,n=new Map,o=(t,e,n,o)=>{let s=t.get(e);s||(s=new Map,t.set(e,s)),s.set(n,(s.get(n)??0)+o)};for(const s of t){const t=s.value>0&&Number.isFinite(s.value)?s.value:1;o(e,s.source,s.target,t),o(n,s.target,s.source,t)}const s=new Map,i=t=>{if(s.has(t))return;const o=e.get(t),i=n.get(t);if(o&&1===o.size&&(!i||0===i.size)){const[e,n]=[...o][0];return void s.set(t,{partner:e,weight:n})}const a=new Map;for(const[t,e]of o??[])a.set(t,(a.get(t)??0)+e);for(const[t,e]of i??[])a.set(t,(a.get(t)??0)+e);if(1===a.size){const[e,n]=[...a][0];s.set(t,{partner:e,weight:n})}};for(const e of t)i(e.source),i(e.target);return s}function K(t,e,n){const o=n.get(t),s=n.get(e);return!o||!s||(o.partner===s.partner||(o.partner===e||s.partner===t))}function tt(t,e,n){return!!n.has(t)&&e.some(e=>!K(t,e,n))}function et(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 nt(t,e,n,o){if(t.length<=12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),i=Array.from({length:t.length},()=>new Map),a=Q(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=et(t,a);i[e].set(n,(i[e].get(n)??0)+o),i[n].set(e,(i[n].get(e)??0)+o)}const r=J(n),l=t.map(t=>r.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let n=0;n<t.length-1&&u<5e4;n++)if(r.has(t[n]))for(let o=n+1;o<t.length;o++){if(!r.has(t[o]))continue;if(e.conflicts(t[n],t[o]))continue;u++;const s=Math.min(l[n],l[o])||Math.max(l[n],l[o]),i=K(t[n],t[o],r)?s:-s;if(!(Math.abs(i)<=W)&&(c[n].set(o,i),c[o].set(n,i),u>=5e4))break}const f=[...o.assignment],d=Array.from({length:o.slotCount},()=>[]);f.forEach((t,e)=>d[t].push(e));const g=(t,e,n)=>{const o=f[e],s=f[n];let i=0;const a=new Set;for(const r of[e,n])for(const[l,c]of t[r]){const t=r<l?`${r}:${l}`:`${l}:${r}`;if(a.has(t))continue;a.add(t);const u=f[r]===f[l],d=(r===e?s:o)===(l===e?s:l===n?o:f[l]);u!==d&&(i+=d?c:-c)}return i},m=(t,e,n)=>{let o=0;for(const[s,i]of t[e]){const t=f[e]===f[s],a=n===f[s];t!==a&&(o+=a?i:-i)}return o},p=(t,e)=>t>W||Math.abs(t)<=W&&e>W,h=(t,e,n,o)=>t>n+W||Math.abs(t-n)<=W&&e>o+W;let b=0;for(let n=0;n<32&&b<R;n++){let n=null,o=-1,s=-1,a=-1,r=-1/0,l=-1/0;for(let u=0;u<t.length;u++){for(let g=0;g<d.length&&!(b++>=R);g++){if(g===f[u])continue;if(!d[g].every(n=>!e.conflicts(t[u],t[n])))continue;const b=m(i,u,g),M=m(c,u,g);p(b,M)&&h(b,M,r,l)&&(n="move",o=u,s=-1,a=g,r=b,l=M)}if(b>=R)break}for(let u=0;u<t.length-1;u++){for(let m=u+1;m<t.length&&!(b++>=R);m++){const b=f[u],M=f[m];if(b===M)continue;if(!d[M].every(n=>n===m||!e.conflicts(t[u],t[n])))continue;if(!d[b].every(n=>n===u||!e.conflicts(t[m],t[n])))continue;const y=g(i,u,m),x=g(c,u,m);p(y,x)&&h(y,x,r,l)&&(n="swap",o=u,s=m,a=-1,r=y,l=x)}if(b>=R)break}if(null==n||-1===o)break;if("move"===n){const t=f[o];d[t].splice(d[t].indexOf(o),1),d[a].push(o),f[o]=a;continue}const u=f[o],M=f[s];d[u].splice(d[u].indexOf(o),1,s),d[M].splice(d[M].indexOf(s),1,o),f[o]=M,f[s]=u}return f}function ot(t,e,n,o){if(0===t.length||t.length>12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),i=Array.from({length:t.length},()=>new Float64Array(t.length)),a=Array.from({length:t.length},()=>new Map),r=Array.from({length:t.length},()=>new Map),l=Q(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=et(t,l);i[e][n]+=o,i[n][e]+=o,r[e].set(n,(r[e].get(n)??0)+o),a[n].set(e,(a[n].get(e)??0)+o)}const c=J(n),u=t.map(t=>c.get(t)?.weight??0),f=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){for(const[t,o]of a[e])f[e][n]+=Math.min(o,a[n].get(t)??0);for(const[t,o]of r[e])f[e][n]+=Math.min(o,r[n].get(t)??0);if(c.has(t[e])&&c.has(t[n])){const o=Math.min(u[e],u[n])||Math.max(u[e],u[n]);f[e][n]+=K(t[e],t[n],c)?o:-o}f[n][e]=f[e][n]}let d=[...o.assignment],g=(e=>{let n=0,o=0;for(let s=0;s<t.length;s++)for(let a=s+1;a<t.length;a++)e[s]===e[a]&&(n+=i[s][a],o+=f[s][a]);return{flow:n,affinity:o}})(d),m=0;const p=new Array(t.length).fill(-1),h=Array.from({length:o.slotCount},()=>[]),b=(n,s,a,r)=>{if(m>=75e3)return;if(n===t.length)return m++,void((a>g.flow||a===g.flow&&r>g.affinity||a===g.flow&&r===g.affinity&&function(t,e){for(let n=0;n<Math.min(t.length,e.length);n++)if(t[n]!==e[n])return t[n]<e[n];return t.length<e.length}(p,d))&&(d=[...p],g={flow:a,affinity:r}));const l=Math.min(s+1,o.slotCount-1);for(let o=0;o<=l;o++){if(h[o].some(o=>e.conflicts(t[n],t[o])))continue;let l=0,c=0;for(const t of h[o])l+=i[n][t],c+=f[n][t];if(p[n]=o,h[o].push(n),b(n+1,Math.max(s,o),a+l,r+c),h[o].pop(),p[n]=-1,m>=75e3)return}};return p[0]=0,h[0].push(0),b(1,0,0,0),d}function st(t,e,n,o){const s=function(t,e,n,o){return`${t.map(t=>{const e=n[t.id],s=o[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,s?.start??"",s?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,n,o),i=(a=s,U.get(a));var a;if(i)return V(i.slots,n,o);const r={};for(const e of t)r[e.id]=_(n[e.id],o[e.id]);const l=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,n)=>e[t.id].start-e[n.id].start||e[t.id].end-e[n.id].end||u(t.id,n.id)).map(t=>t.id)}(t,r),c=new Map(t.map(t=>[t.id,t])),f=new Map(t.map(t=>[t.id,t.group||void 0])),d=function(t,e,n,o,s){const i=new Set,a=new Map(t.map(t=>[t,new Set])),r=new Map(t.map(t=>[t,new Set]));for(const t of o)i.add(Z(t.source,t.target)),a.get(t.target)?.add(t.source),r.get(t.source)?.add(t.target);const l=new Map,c=new Set,u=(t,e)=>{for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const s=Z(t[n],t[o]);e instanceof Map?e.set(s,[t[n],t[o]]):e.add(s)}};for(const t of r.values())u([...t],l);for(const t of a.values())u([...t],c);const f=new Set;for(const[t,[o,s]]of l)c.has(t)&&(G(e[o],e[s])||G(n[o],n[s])&&(f.add(o),f.add(s)));return{conflicts:(t,n)=>{const o=s.get(t),a=s.get(n);return null!=o&&null!=a&&o!==a||null!=o!=(null!=a)&&!i.has(Z(t,n))||!!G(e[t],e[n])||!(!f.has(t)&&!f.has(n))&&!i.has(Z(t,n))}}}(l,r,o,e,f),g=function(t,e,n=new Map){const o=[],s=[];for(const i of t){let t=o.findIndex(t=>t.every(t=>!e.conflicts(i,t))&&!tt(i,t,n));-1!==t||n.has(i)||(t=o.findIndex(t=>t.every(t=>!e.conflicts(i,t)))),-1===t&&(t=o.length,o.push([])),o[t].push(i),s.push(t)}return{assignment:s,slotCount:o.length}}(l,d,J(e)),m=ot(l,d,e,{...g,assignment:nt(l,d,e,g)}),p=new Map,h=m.map(t=>(p.has(t)||p.set(t,p.size),p.get(t))),b=Array.from({length:p.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),M={};l.forEach((t,e)=>{const n=h[e],o=b[n];o.occupants.push({id:t,end:r[t].end??-1/0});const s=c.get(t)?.group;s&&(o.group=s),M[t]=n});for(const e of[...t].sort((t,e)=>u(t.id,e.id)))null==M[e.id]&&(b[0].occupants.push({id:e.id,end:-1/0}),M[e.id]=0);for(const t of b){t.occupants.sort((t,e)=>(r[t.id].start??1/0)-(r[e.id].start??1/0)||u(t.id,e.id));for(const e of t.occupants){const o=n[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,o?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,o?.botPeak||0)}}const y={slots:b,slotByNode:M};return function(t,e){for(U.has(t)&&U.delete(t),U.set(t,{slots:e.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),slotByNode:{...e.slotByNode}});U.size>12;){const t=U.keys().next().value;if(null==t)break;U.delete(t)}}(s,y),y}function it(t){return t.topMass+t.botMass}function at(t,e){const n=t.samples.filter(t=>t.t===e);if(n.length>0)return n.reduce((t,e)=>it(e)>=it(t)?e:t,n[0]);let o=null;for(const n of t.samples){if(n.t>e)break;o=n}return o}function rt(t,e,n,o,s,i,a=0){const r=new Map;for(const n of t){if(!n.group||!e[n.id])continue;const t=r.get(n.group)??[];t.push(n),r.set(n.group,t)}if(0===r.size||!(i>0))return e;const l=(c=e,Object.fromEntries(Object.entries(c).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}])));var c;for(const[t,c]of r){const r=n.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===r.length)continue;const u=r[0].slot,f=r.at(-1).slot,d=s[u.occupants[0]?.id],g=s[f.occupants[0]?.id];if(!Number.isFinite(d)||!Number.isFinite(g))continue;const m=(d-u.peak.topPeak*i+(g+f.peak.botPeak*i))/2,p=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),h=new Map;for(const t of c)h.set(t.id,new Map);for(const t of p){const n=new Map;for(const s of c){const i=at(e[s.id],t);if(!i||it(i)<=1e-9)continue;const a=o[s.id];if(null==a)continue;const r=n.get(a)??[];r.push({node:s,sample:i}),n.set(a,r)}const r=[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>it(t)))}));if(0===r.length)continue;let l=m-(r.reduce((t,e)=>t+e.mass,0)*i+Math.max(0,a)*Math.max(0,r.length-1))/2;for(const e of r){for(const{node:n,sample:o}of e.active){const e=(l-s[n.id])/i+o.topMass-(o.boundaryOffset??0);h.get(n.id).set(t,e)}l+=e.mass*i+Math.max(0,a)}}for(const t of c){const n=e[t.id],o=l[t.id],s=h.get(t.id),i=[];for(const t of p){const e=s.get(t),o=n.samples.filter(e=>e.t===t);if(o.length>0){i.push(...o.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const a=at(n,t);null==e||!a||it(a)<=1e-9||i.push({...a,t:t,boundaryOffset:(a.boundaryOffset??0)+e})}o.samples=i,o.localAttachments=new Map([...n.localAttachments].map(([t,e])=>{const n=s.get(e.time);return[t,{...e,...null!=n?{boundaryOffset:(e.boundaryOffset??0)+n}:{}}]}))}}return l}function lt(t,e,n,o,s){const{plotH:i,padding:a,valueScale:r,packing:l,laneOrder:c,lifetimeMode:d="half",lanePlacement:g="stack",groupPadding:m=0,ribbonLane:p="both",domain:b}=s,M={},y={};for(const e of t)M[e.id]=n[e.id].topPeak||0,y[e.id]=n[e.id].botPeak||0;const x="half"===d,w={};for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,n=Array.isArray(e.xExtent)?e.xExtent[1]:null;let s=null!=t&&Number.isFinite(t)?t:1/0,i=null!=n&&Number.isFinite(n)?n:-1/0;for(const t of o.outgoing[e.id]){t.startTime<s&&(s=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<s&&(s=t.systemInTime);const e=x?(t.startTime+t.endTime)/2:t.endTime;e>i&&(i=e)}for(const t of o.incoming[e.id]){const e=x?(t.startTime+t.endTime)/2:t.startTime;e<s&&(s=e),t.endTime>i&&(i=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>i&&(i=t.systemOutTime)}w[e.id]={start:Number.isFinite(s)?s:null,end:Number.isFinite(i)?i:null}}let v={},k=[],T=[];if(s.frozenSlots){const t=V(s.frozenSlots,n,w);k=t.slots,v=t.slotByNode,T=k.map(f)}else if("reuse"===l){const o=st(t,e,n,w);k=o.slots,v=o.slotByNode}else t.forEach((t,e)=>{k.push({occupants:[{id:t.id,end:w[t.id]?.end??-1/0}],peak:{topPeak:M[t.id],botPeak:y[t.id]},...t.group?{group:t.group}:{}}),v[t.id]=e});B(k,v),0===T.length&&(T=k.map(f));let S=null;s.frozenSlots||(s.fixedSlotOrder?function(t,e,n){const o=new Map(n.map((t,e)=>[t,e]));A(t,e,[...t].sort((t,e)=>(o.get(f(t))??1/0)-(o.get(f(e))??1/0)||u(f(t),f(e))))}(k,v,s.fixedSlotOrder):s.runOrdering&&c&&"insertion"!==c&&(S=q(t,e,n,w,k,v,{plotH:i,padding:a,valueScale:r,groupPadding:m,laneOrder:c,ribbonLane:p,domain:b}))),B(k,v);const N=h(t,e,n,k,v,{plotH:i,padding:a,valueScale:r,stackValueScale:s.stackValueScale,lanePlacement:g,groupPadding:m}),O=0===k.length?0:k[0].peak.topPeak+N.adjacentClearance.reduce((t,e)=>t+e,0)+k[k.length-1].peak.botPeak,P=S?.before.crossings??null,F=S?.after.crossings??null,I=S?.before.weightedLength??null,E=S?.after.weightedLength??null;return{effectiveSlotsHeight:O,centerlines:N.centerlines,laneLifetime:w,slots:k,slotByNode:v,slotCenter:N.slotCenter,stackCenter:N.stackCenter,verticalUtilization:N.verticalUtilization,selectedSlotOrder:k.map(f),initialSlotOrder:T,ordering:S,crossingsBefore:P,crossingsAfter:F,lengthBefore:I,lengthAfter:E}}function ct(t,e,n){const{plotH:o,pairing:s="temporal",packing:i="reuse",laneOrder:a="crossing-min",lifetimeMode:r="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:g="temporal",groupPadding:m=0,ribbonLane:p="both",domain:b}=n,M=Number.isFinite(m)?Math.max(0,m):0,y=function(t,e){const n={},o={};for(const e of t)n[e.id]=[],o[e.id]=[];for(const t of e)o[t.source]&&o[t.source].push(t),n[t.target]&&n[t.target].push(t);return{incoming:n,outgoing:o}}(t,e),x=function(t,e,n,o="temporal"){const s="temporal"===o?(t,e)=>t.endTime-e.endTime||u(t.id,e.id):(t,e)=>e.value-t.value||u(t.id,e.id),i="temporal"===o?(t,e)=>t.startTime-e.startTime||u(t.id,e.id):(t,e)=>e.value-t.value||u(t.id,e.id),a=new Map;for(const t of e)a.set(t.id,{});const r=(t,e)=>{const n=new Map;for(const o of t){const t=o[e];n.has(t)||n.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const s=n.get(t);s.edges.push(o),s.total+=o.value,s.earliestStart=Math.min(s.earliestStart,o.startTime),s.latestEnd=Math.max(s.latestEnd,o.endTime)}const a=[...n.values()];"temporal"===o?a.sort((t,n)=>"target"===e?t.earliestStart-n.earliestStart||u(t.partner,n.partner):t.latestEnd-n.latestEnd||u(t.partner,n.partner)):a.sort((t,e)=>e.total-t.total||u(t.partner,e.partner));for(const t of a)t.edges.sort("target"===e?i:s);return a};for(const e of t){const t=n.outgoing[e.id],o=n.incoming[e.id];if(0===o.length)r(t,"target").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)a.get(e.id).sourceSide=n});else if(0===t.length)r(o,"source").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)a.get(e.id).targetSide=n});else{const e=r(o,"source"),n=r(t,"target"),s=Math.max(e.length,n.length);for(let t=0;t<s;t++){const o=t%2==0?"top":"bot";if(e[t])for(const n of e[t].edges)a.get(n.id).targetSide=o;if(n[t])for(const e of n[t].edges)a.get(e.id).sourceSide=o}}}return a}(t,e,y,s);let w={};for(const e of t)w[e.id]=P(e,y,x,void 0,g);const v=lt(t,e,w,y,{plotH:o,padding:12,valueScale:1,packing:i,laneOrder:a,lifetimeMode:r,runOrdering:!0,lanePlacement:"stack",groupPadding:M,ribbonLane:p,domain:b}),k=v.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),S=new Set;for(const t of e){const e=v.slotByNode[t.source],n=v.slotByNode[t.target];if(void 0===e||void 0===n)continue;const o=x.get(t.id);e!==n?n<e?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(S.add(t.id),o.sourceSide="bot",o.targetSide="bot")}for(const e of t){const t=y.outgoing[e.id],n=y.incoming[e.id],o=new Set(t.map(t=>x.get(t.id).sourceSide)),s=new Set(n.map(t=>x.get(t.id).targetSide));if(1===o.size&&n.length>0){const t=[...o][0];for(const e of n)v.slotByNode[e.source]===v.slotByNode[e.target]&&(x.get(e.id).targetSide=t)}if(1===s.size&&t.length>0){const e=[...s][0];for(const n of t)v.slotByNode[n.source]===v.slotByNode[n.target]&&(x.get(n.id).sourceSide=e)}}!function(t,e,n){const o=new Map,s=[];for(const e of t)s.push({time:e.startTime,kind:"out",edge:e}),s.push({time:e.endTime,kind:"in",edge:e});s.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)||u(t.edge.id,e.edge.id));const i=t=>{let e=o.get(t);return e||(e={top:0,bot:0},o.set(t,e)),e},a=(t,e,n)=>{const o="top"===e?"bot":"top",s=Math.min(n,t[e]);t[e]-=s;const i=n-s;i>0&&(t[o]=Math.max(0,t[o]-i))};for(const t of s){const{edge:o}=t;if("in"===t.kind){const t=e.get(o.id)?.targetSide??"bot";i(o.target)[t]+=o.value;continue}const s=i(o.source),r=e.get(o.id);let l=r.sourceSide??"bot";if(n[o.source]===n[o.target]){const t=s.top>=o.value,e=s.bot>=o.value;t!==e?l=t?"top":"bot":t||e||s.top===s.bot||(l=s.top>s.bot?"top":"bot"),r.sourceSide=l,r.targetSide=l}a(s,l,o.value)}}(e,x,v.slotByNode),function(t,e,n,o){for(const s of t){const t=e.incoming[s.id],i=e.outgoing[s.id];if(0===t.length||0===i.length)continue;const a=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===n.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of i)"top"===n.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},r=(t,e)=>{const s=a(),r="top"===t?s.outTop-s.inTop:s.outBot-s.inBot,l="top"===e?s.inTop-s.outTop:s.inBot-s.outBot;if(r<=0||l<=0)return!1;const c=Math.min(r,l),f=i.filter(e=>!o.has(e.id)&&n.get(e.id).sourceSide===t&&e.value<=c).sort((t,e)=>e.value-t.value||u(t.id,e.id));return 0!==f.length&&(n.get(f[0].id).sourceSide=e,!0)};let l=i.length+1;for(;l-- >0&&(r("top","bot")||r("bot","top")););}}(t,y,x,S),w={};for(const e of t)w[e.id]=P(e,y,x,void 0,g);const N=lt(t,e,w,y,{plotH:o,padding:12,valueScale:1,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:k,lanePlacement:"stack",groupPadding:M,ribbonLane:p,domain:b}),F=N.effectiveSlotsHeight??N.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),A=N.slots.slice(0,-1).reduce((t,e,n)=>t+(null!=e.group&&e.group===N.slots[n+1].group?1:0),0),I=Math.max(1,N.slots.length+1-A),E=Math.min(12,Math.max(0,.35*o-A*M)/I),$=2*E+d(N.slots,E,M).reduce((t,e)=>t+e,0),L=F>0?Math.max(0,(o-$)/F):1,B=Number.isFinite(l)&&l>0?Math.min(L,l):L;let z=lt(t,e,w,y,{plotH:o,padding:E,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:k,lanePlacement:c,groupPadding:M,ribbonLane:p,domain:b,stackValueScale:L});const H=Number.isFinite(l)&&l>0&&l+1e-12<L;if("insertion"!==a&&("hug"===c||H)&&z.slots.length>1&&(q(t,e,w,z.laneLifetime,z.slots,z.slotByNode,{plotH:o,padding:E,valueScale:B,groupPadding:M,laneOrder:a,ribbonLane:p,domain:b,lanePlacement:c,mode:"geometry-refine"}),z=lt(t,e,w,y,{plotH:o,padding:E,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:z.slots,fixedSlotOrder:z.slots.map(f),lanePlacement:c,groupPadding:M,ribbonLane:p,domain:b,stackValueScale:L})),function(t,e){const n=(t,n)=>{for(const o of t){const t=new Map;for(const s of o){const o=`${("out"===n?e.get(s.id)?.sourceSide:e.get(s.id)?.targetSide)??""}\0${"out"===n?s.startTime:s.endTime}`,i="out"===n?`${s.target}\0${s.endTime}`:`${s.source}\0${s.startTime}`,a=t.get(o);if(null!=a&&a!==i)return!0;t.set(o,i)}}return!1};return n(Object.values(t.outgoing),"out")||n(Object.values(t.incoming),"in")}(y,x)){const n=function(t,e,n,o){const s=new Map;for(const i of t){const t=e[i.source]?.localAttachments.get(i.id),a=e[i.target]?.localAttachments.get(i.id),r=n[i.source],l=n[i.target];if(!(t&&a&&Number.isFinite(r)&&Number.isFinite(l)))continue;const c=O(t,r,o),u=O(a,l,o);s.set(i.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return s}(e,w,z.centerlines,B);w={};for(const e of t)w[e.id]=P(e,y,x,n,g);z=lt(t,e,w,y,{plotH:o,padding:E,valueScale:B,packing:i,laneOrder:a,lifetimeMode:r,frozenSlots:z.slots,fixedSlotOrder:z.slots.map(f),lanePlacement:c,groupPadding:M,ribbonLane:p,domain:b,stackValueScale:L})}const D=new Map(v.initialSlotOrder.map((t,e)=>[t,e])),j=[...z.slots].sort((t,e)=>(D.get(f(t))??1/0)-(D.get(f(e))??1/0)||u(f(t),f(e))),Y={};j.forEach((t,e)=>{for(const n of t.occupants)Y[n.id]=e});const V=h(t,e,w,j,Y,{plotH:o,padding:E,valueScale:B,stackValueScale:L,lanePlacement:"stack",groupPadding:M}),U=rt(t,w,j,Y,V.centerlines,B,M),W=T(C(Y,e),X(Y,e),e,U,j,Y,V.centerlines,z.laneLifetime,B,V.verticalUtilization,p,b);w=rt(t,w,z.slots,z.slotByNode,z.centerlines,B,M);const R=T(C(z.slotByNode,e),X(z.slotByNode,e),e,w,z.slots,z.slotByNode,z.centerlines,z.laneLifetime,B,z.verticalUtilization,p,b);return{nodeData:w,sides:x,valueScale:B,padding:E,compressedPadding:E<12,centerlines:z.centerlines,laneLifetime:z.laneLifetime,slots:z.slots,slotByNode:z.slotByNode,crossingsBefore:"insertion"===a?null:W.crossings,crossingsAfter:"insertion"===a?null:R.crossings,lengthBefore:"insertion"===a?null:W.weightedLength,lengthAfter:"insertion"===a?null:R.weightedLength,layoutQualityBefore:W,layoutQuality:R}}function ut(t,e,n,o,s,i,a,r,l={}){const c=s,u=t=>r?Math.max(r[0],Math.min(r[1],t)):t;let f=i(u(t.time));const d=i(u(n.time)),g=t.value*c,m=n.value*c,p=e+(t.boundaryOffset??0)*c,h=o+(n.boundaryOffset??0)*c,b=t.sideMassBefore*c,M=n.sideMassAfter*c;let y,x,w,v;"top"===t.side?(y=p-b,x=y+g):(x=p+b,y=x-g),"top"===n.side?(w=h-M,v=w+m):(v=h+M,w=v-m);const k=l.sourceRunwayStart,T=l.minRun,S=(y+x)/2,N=(w+v)/2,O=Math.abs(N-S),P=d-f,F="number"==typeof k&&Number.isFinite(k),A="number"==typeof T&&Number.isFinite(T)&&T>0;if(F&&O>1e-9&&P>0&&("auto"===T||A)){const e="source"===a?.85:"target"===a?.15:.5,n=1.5*Math.min(e*e,(1-e)*(1-e)),o="auto"===T?Math.min(144,Math.sqrt(8*O/n)):T;if(o>P){const e=i(u(Math.min(k,t.time)));if(Number.isFinite(e)){const t=Math.min(f,e);f=Math.min(f,Math.max(t,d-o))}}}const I="source"===a?f+.85*(d-f):"target"===a?f+.15*(d-f):(f+d)/2;return{sx:f,sTop:y,sBot:x,tx:d,tTop:w,tBot:v,cp1X:I,cp2X:I}}function ft(t){return Math.max(18,11*t.length*.58)}function dt(t){const e=1.22*ft(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 gt(t,e){const n=t.labelX-ft(t.labelText),o=e.labelX-ft(e.labelText);return n<=e.labelX+3&&o<=t.labelX+3}function mt(t,e,n){const o=t.map(t=>({...t})),s=new Map;for(const t of o){const n=e[t.id];if(null==n)continue;const o=s.get(n)??[];o.push(t),s.set(n,o)}const i=t=>{if(t.length<2)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,o=(t.length-1)/2;t.forEach((t,s)=>{t.labelY=Math.max(8,Math.min(n-8,e+16*(s-o)))})};for(const t of s.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],n=-1/0;for(const o of t){const t=o.labelX-ft(o.labelText);e.length>0&&t>n+3&&(i(e),e=[],n=-1/0),e.push(o),n=Math.max(n,o.labelX)}i(e)}return function(t,e){const n=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;t<3;t+=1){for(let t=0;t<n.length;t+=1){let e=8;for(let o=0;o<t;o+=1)gt(n[t],n[o])&&(e=Math.max(e,n[o].labelY+16));n[t].labelY=Math.max(n[t].labelY,e)}for(let t=n.length-1;t>=0;t-=1){let o=e-8;for(let e=t+1;e<n.length;e+=1)gt(n[t],n[e])&&(o=Math.min(o,n[e].labelY-16));n[t].labelY=Math.min(n[t].labelY,o)}}}(o,n),o}var pt=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function ht(t){return t.replace(pt,(t,e,n)=>`${n},${e}`)}function bt(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 Mt(t){return{...t,pathD:ht(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function yt(t,e){const n=function(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>xt(e(t))}(e??"value"),o=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=o?o(t):void 0;return{value:n(t),category:null==e?void 0:String(e)}}}function xt(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function wt(t,e,n){const o=t.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(e,n):function(t,e,n){const o=null!=t.axis?n[t.axis]:null!=t.field?e[t.field]:n.value;if(void 0!==t.eq&&o!==t.eq)return!1;if(void 0!==t.ne&&o===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(o))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const s=xt(o);if(void 0===s)return!1;if(void 0!==t.gt&&!(s>t.gt))return!1;if(void 0!==t.gte&&!(s>=t.gte))return!1;if(void 0!==t.lt&&!(s<t.lt))return!1;if(void 0!==t.lte&&!(s<=t.lte))return!1;if(void 0!==t.within){const[e,n]=t.within;if(!(s>=e&&s<=n))return!1}if(void 0!==t.outside){const[e,n]=t.outside;if(!(s<e||s>n))return!1}return!0}(o,e,n))}import{jsx as vt,jsxs as kt}from"react/jsx-runtime";function Tt(e){const{nodes:o,edges:i,domain:a,plotW:r,plotH:l,ribbonLane:c,ribbonMinRun:u=0,edgeOpacity:f,colorOf:d,layoutOpts:g,orientation:m="horizontal",showLabels:p=!0,labelPriorityAccessor:h,maxLabels:b,selectionDatum:M="raw",styleRules:y,colorBy:x,valueAccessor:w,usageMode:v="static"}=e,k="vertical"===m?l:r,T="vertical"===m?r:l,P=function(t,e,o,s={}){const i=n(s.usageMode??"static"),a=[],r=new Set;for(const e of t)r.has(e.id)&&a.push({kind:"duplicate-node",id:e.id,severity:i.duplicateIds}),r.add(e.id);const l=new Set,c=Array.isArray(o)&&2===o.length,u=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]),f=u&&o[0]<=o[1];c&&u&&f||a.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[0]<=e.xExtent[1]||a.push({kind:"invalid-node-time",id:e.id}));for(const t of e)l.has(t.id)&&a.push({kind:"duplicate-edge",id:t.id,severity:i.duplicateIds}),l.add(t.id),r.has(t.source)||a.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),r.has(t.target)||a.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))&&a.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),(!Number.isFinite(t.value)||t.value<=0)&&a.push({kind:"invalid-value",id:t.id}),t.endTime<t.startTime&&a.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):a.push({kind:"invalid-edge-time",id:t.id});return a}(o,i,a,{usageMode:v}),{fatal:F,warnings:A}=function(t){const e=[],n=[];for(const o of t)"fatal"===s(o)?e.push(o):n.push(o);return{fatal:e,warnings:n}}(P),I=function(t,e,o="static"){if("strip"!==n(o).invalidSystemTime)return t;const s=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===s.size?t:t.map(t=>{if(!s.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})}(i,P,v),E=t().domain(a).range([0,k]);if(F.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==p},issues:F,warnings:A,xScale:E};const $=ct(o,I,{plotH:T,...g,ribbonLane:c,domain:a}),{centerlines:L,nodeData:B,valueScale:z}=$,C=yt(x,w),X=[],H=[],D=0===u?new Map:function(t,e,n){const o=new Set(e.map(t=>t.target)),s=new Map(t.map(t=>[t.id,t])),i=new Map;for(const t of e){if(o.has(t.source))continue;const e=i.get(t.source)??[];e.push(t),i.set(t.source,e)}const a=new Map;for(const e of t){if(!e.group)continue;const t=a.get(e.group)??[];t.push(e),a.set(e.group,t)}const r=new Set;for(const[t,e]of a){const n=e.flatMap(t=>i.get(t.id)??[]),s=new Set(n.map(t=>t.startTime));n.length>0&&1===s.size&&e.every(t=>{const e=t.xExtent?.[0],s=n[0].startTime;return!o.has(t.id)&&(i.get(t.id)?.length??0)>0&&Number.isFinite(e)&&e<s})&&r.add(t)}const l=new Map;for(const[t,e]of i){const o=s.get(t);if(o?.group&&!r.has(o.group))continue;const i=o?.xExtent?.[0],a=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),c=a[0]?.startTime-1;let u=null;for(let t=0;t<a.length;){const e=a[t].startTime;let o=t+1;for(;o<a.length&&a[o].startTime===e;)o++;for(let e=t;e<o;e++){const t=a[e],o=Number.isFinite(i)&&i<t.startTime,s=Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime;if(!o&&!s)continue;let r=n[0];o&&(r=Math.max(r,i)),s&&(r=Math.max(r,t.systemInTime)),!o&&s&&Number.isFinite(c)&&(r=Math.max(r,c)),null!=u&&(r=Math.max(r,u)),r<t.startTime&&l.set(t.id,r)}u=e,t=o}}for(const[t,e]of a){if(!r.has(t))continue;const n=e.flatMap(t=>i.get(t.id)??[]);if(!n.every(t=>l.has(t.id))){for(const t of n)l.delete(t.id);continue}const o=Math.max(...n.map(t=>l.get(t.id)));for(const t of n)l.set(t.id,o)}return l}(o,I,a),j=new Map(o.filter(t=>t.group).map(t=>[t.id,t.group])),Y=new Map;for(const t of I){const e=B[t.source]?.localAttachments.get(t.id),n=B[t.target]?.localAttachments.get(t.id);e&&n&&Y.set(t.id,ut(e,L[t.source],n,L[t.target],z,E,c,a,{minRun:u,sourceRunwayStart:D.get(t.id)}))}const q=function(t,e,n,o,s,i){const a=new Map(e),r=new Map;for(const e of t){const t=i?.get(e.source),n=null==t?`node:${e.source}`:`group:${t}`,o=r.get(n)??new Map,s=o.get(e.startTime)??[];s.push(e),o.set(e.startTime,s),r.set(n,o)}for(const t of r.values())for(const[i,r]of t){if(!r.some(t=>n.has(t.id)))continue;const t=r.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const l=o(i),c=Math.min(...t.map(t=>t.sx));if(!(c<l-1e-9))continue;const u=Math.max(...r.map(t=>{const e=n.get(t.id);return null==e?l:Math.min(l,o(e))})),f=Math.min(l,Math.max(c,u));for(const t of r){const n=e.get(t.id),o="source"===s?.85:"target"===s?.15:.5,i=f+(n.tx-f)*o;a.set(t.id,{...n,sx:f,cp1X:i,cp2X:i})}}return a}(I,Y,D,E,c,j),V=function(t,e,n,o,s){const i=new Map;for(const a of t){if(!n.has(a.id))continue;const t=e.get(a.id);if(!(t&&t.sx<o(a.startTime)-1e-9))continue;const r=s(t.sx);Number.isFinite(r)&&r<a.startTime&&i.set(a.id,r)}return i}(I,q,D,E,t=>a[0]+t/k*(a[1]-a[0])),U=function(t,e,n){const o=new Map,s=new Map;for(const[t,e]of n??[]){const n=s.get(e)??[];n.push(t),s.set(e,n)}for(const i of t){const t=e.get(i.id);if(!(null!=t&&Number.isFinite(t)&&t<i.startTime))continue;const a=n?.get(i.source),r=null==a?[i.source]:s.get(a)??[i.source];for(const e of r){const n=o.get(e)??new Map,s=n.get(i.startTime);n.set(i.startTime,null==s?t:Math.min(s,t)),o.set(e,n)}}return o}(I,V,j);o.forEach((t,e)=>{const n=B[t.id];if(!n||0===n.samples.length)return;const o=(s=n.samples,(i=U.get(t.id))&&0!==i.size?s.map(t=>{const e=i.get(t.t);return null==e?t:{...t,t:e}}):s);var s,i;const r=function(t,e,n,o,s){if(0===t.length)return null;const i=N(t,s),a=t=>e+(i[t].boundaryOffset??0)*n,r=t=>a(t)-i[t].topMass*n,l=t=>a(t)+i[t].botMass*n;let c=`M${o(i[0].t)},${r(0)}`;for(let t=1;t<i.length;t++)c+=` L${o(i[t].t)},${r(t)}`;c+=` L${o(i[i.length-1].t)},${l(i.length-1)}`;for(let t=i.length-2;t>=0;t--)c+=` L${o(i[t].t)},${l(t)}`;return c+" Z"}(o,L[t.id],z,E,a);if(!r)return;const l=N(o,a),c=l.find(t=>t.topMass+t.botMass>0)||l[0],u=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*z/2,f=L[t.id]+u;let g,p,h=d(t.id,e),b=h,M=.5;const x=t.__raw??t;if(y&&y.length>0){const t=function(t,e,n){if(!e||0===e.length)return{};let o={};for(const s of e){if(!wt(s,t,n))continue;const e="function"==typeof s.style?s.style(t,n):s.style;e&&(o={...o,...e})}return o}(x,y,C(x));"string"==typeof t.fill?h=t.fill:null!=t.fill&&("object"==typeof(w=t.fill)&&null!==w&&"hatch"===w.type)&&(p=t.fill,h=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:h),"string"==typeof t.stroke&&(b=t.stroke),"number"==typeof t.strokeWidth&&(M=t.strokeWidth),"number"==typeof t.fillOpacity&&(g=t.fillOpacity),"number"==typeof t.opacity&&null==g&&(g=t.opacity)}var w;const v=function(t,e,n,o,s,i){const a=n.nodeData[t];if(!a||0===a.samples.length)return[];const r=n.valueScale,l=n.centerlines[t],c=N(a.samples,s),u=c.find(t=>t.topMass+t.botMass>0)||c[0],f=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],d=o(u.t),g=o(f.t),m=t=>o(S(t,s)),p=[],h=(t,e,n,o)=>`M${t},${e} L${n},${e} L${n},${o} L${t},${o} Z`;for(const n of e){if(n.source===t&&null!=n.systemInTime&&Number.isFinite(n.systemInTime)){const t=a.localAttachments.get(n.id),e=i?.get(n.id)??n.startTime;if(t&&"out"===t.kind&&n.systemInTime<e){const o=m(n.systemInTime),i=m(e),a=null!=s&&n.systemInTime<s[0],c=a?o:o-20,u=a?Math.min(i,o+20):o,f=Math.max(d,c);if(i>f){const[e,n]=O(t,l,r);p.push({pathD:h(f,e,i,n),x0:c,x1:u,from:0,to:1})}}}if(n.target===t&&null!=n.systemOutTime&&Number.isFinite(n.systemOutTime)){const t=a.localAttachments.get(n.id);if(t&&"in"===t.kind&&n.systemOutTime>n.endTime){const e=m(n.systemOutTime),o=m(n.endTime),s=e+20,i=Math.min(g,s);if(i>o){const[n,a]=O(t,l,r);p.push({pathD:h(o,n,i,a),x0:e,x1:s,from:1,to:0})}}}}return p}(t.id,I,$,E,a,V);X.push({id:t.id,pathD:r,fill:h,stroke:b,strokeWidth:M,...null!=g&&{fillOpacity:g},...p&&{hatchFill:p},...v.length>0&&{gradientStubs:v},rawDatum:x,labelX:E("vertical"===m&&t.xExtent?t.xExtent[0]:c.t)-4,labelY:f,labelText:t.label??t.id})});const W=new Map;o.forEach((t,e)=>W.set(t.id,e)),I.forEach(t=>{const e=q.get(t.id);if(!e)return;const n=W.get(t.source)??0,o=d(t.source,n),{pathD:s,bezier:i}=function(t){const{sx:e,sTop:n,sBot:o,tx:s,tTop:i,tBot:a,cp1X:r,cp2X:l}=t,c=(n+o)/2,u=(i+a)/2;return{pathD:[`M${e},${n}`,`C${r},${n} ${l},${i} ${s},${i}`,`L${s},${a}`,`C${l},${a} ${r},${o} ${e},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:r,y:c},{x:l,y:u},{x:s,y:u}],halfWidth:(o-n)/2}}}(e),a=t.__raw??t,r="function"==typeof f?Number(f(a)):f,l=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.35;H.push({id:t.id,pathD:s,fill:o,opacity:l,rawDatum:a,bezier:i})});const R=mt(X,$.slotByNode,T).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:ht(t.pathD),gradientStubs:t.gradientStubs?.map(Mt),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,m)),_="vertical"===m?function(t,e,n){const o=t.map(t=>({...t}));for(const t of o){const n=1.22*ft(t.labelText)+4;t.labelX=n>=e-4?e/2:Math.max(n/2+2,Math.min(e-n/2-2,t.labelX))}const s=[],i=[...o].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of i){const e=s[s.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?s.push([t]):e.push(t)}for(const t of s){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],o=new Map;for(const n of t){const[t,s]=dt(n);let i=e.findIndex(e=>t>e+8);-1===i&&(i=e.length),e[i]=s,o.set(n,i)}const s=t.reduce((t,e)=>t+e.labelY,0)/t.length,i=s<14*e.length+8;for(const e of t){const t=o.get(e)??0;e.labelY=i?Math.min(n-8,12+14*t):Math.max(8,s-14*t)}}return o}(R,r,l):R,G=new Map;if(null!=h)for(const t of o){const e=t.__raw??t,n="function"==typeof h?h(e):Number(e[h]);Number.isFinite(n)&&G.set(t.id,n)}const Z=function(t,e,n,o,s={}){if(!1===o)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===o)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));const i=Math.max(1,e*n);let a=Math.max(4,Math.min(t.length,Math.floor(i/14e3)));Number.isFinite(s.maxLabels)&&s.maxLabels>=0&&(a=Math.min(a,Math.floor(s.maxLabels)));const r=t.map((t,e)=>{const n=s.priorityById?.get(t.id),o=Math.abs(t.labelY);return{band:t,index:e,score:null!=n&&Number.isFinite(n)?1e6*n+ft(t.labelText):ft(t.labelText)+.01*o}}).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)),l=new Set(r.slice(0,a).map(t=>t.band.id));return t.map(t=>l.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(_,r,l,p,{...G.size>0&&{priorityById:G},...null!=b&&{maxLabels:b}});return{layout:$,layoutConfig:{bands:Z,ribbons:H.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:ht(t.pathD),bezier:bt(t.bezier)}}(t,m)),showLabels:!1!==p,selectionDatum:M},issues:[],warnings:A,xScale:E}}self.onmessage=t=>{const e=t.data,n=e?.requestId,o=e?.request??e;try{const t=o.colorById??{},e=o.fallbackPalette??["#475569"],a=(n,o)=>t[n]??e[o%e.length]??"#475569",r=Tt({...o.input,colorOf:a});self.postMessage({requestId:n,layout:(i=r.layout,i?{...i,sides:i.sides instanceof Map?[...i.sides.entries()]:i.sides}:null),layoutConfig:(s=r.layoutConfig,{bands:(s.bands??[]).map(({rawDatum:t,...e})=>e),ribbons:(s.ribbons??[]).map(({rawDatum:t,...e})=>e),showLabels:s.showLabels}),issues:r.issues,warnings:r.warnings,domain:o.input.domain,timelineExtent:"vertical"===o.input.orientation?o.input.plotH:o.input.plotW})}catch(t){self.postMessage({requestId:n,error:{message:t instanceof Error?t.message:String(t),name:t instanceof Error?t.name:"Error",stack:t instanceof Error?t.stack:void 0}})}var s,i};
1
+ import{scaleTime as t}from"d3-scale";var e={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function n(t="static"){return e[t]??e.static}var o=new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function s(t){return"fatal"===t.severity||"warn"===t.severity?t.severity:o.has(t.kind)?"fatal":"warn"}function a(t){const{desired:e,minGaps:n,weights:o}=t,s=e.length;if(0===s)return[];if(n.length!==Math.max(0,s-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");const a=new Array(s).fill(0);for(let t=1;t<s;t++)a[t]=a[t-1]+Math.max(0,Number.isFinite(n[t-1])?n[t-1]:0);const i=[];for(let t=0;t<s;t++){const n=Math.max(Number.EPSILON,Number.isFinite(o?.[t])?o[t]:1),s=(Number.isFinite(e[t])?e[t]:0)-a[t];for(i.push({start:t,end:t,weight:n,mean:s});i.length>1;){const t=i[i.length-1],e=i[i.length-2];if(e.mean<=t.mean)break;const n=e.weight+t.weight;i.splice(i.length-2,2,{start:e.start,end:t.end,weight:n,mean:(e.mean*e.weight+t.mean*t.weight)/n})}}const r=Number.isFinite(t.min)?t.min:-1/0,l=Number.isFinite(t.max)?t.max-a[s-1]:1/0,c=l<r?r:l,u=new Array(s);for(const t of i){const e=Math.max(r,Math.min(c,t.mean));for(let n=t.start;n<=t.end;n++)u[n]=e+a[n]}return u}function i(t,e){let n=0,o=t.length-1,s=-1;for(;n<=o;){const a=n+o>>>1;t[a].at<=e?(s=a,n=a+1):o=a-1}return s<0?{at:e,before:0,after:0}:t[s]}function r(t,e=0){if(0===t.length)return{adjacentClearance:[],positions:[]};const n=[],o=[0];for(let s=0;s<t.length-1;s++){const a=t[s],r=t[s+1],l=[...new Set([...a.map(t=>t.at),...r.map(t=>t.at)])].sort((t,e)=>t-e);let c=0;for(const t of l){const e=i(a,t),n=i(r,t);c=Math.max(c,e.after+n.before)}n.push(c),o.push(o[o.length-1]+c+e)}return{adjacentClearance:n,positions:o}}function l(t,e,n,o={}){let s=[...t];if(s.length<=1)return s;let a=[...s],i=n(s),r=1;const l=Math.max(0,o.passes??6),c=Math.max(1,o.maxEvaluations??1/0);for(let t=0;t<l&&r<c;t++){const t=new Map(s.map((t,e)=>[t,e])),l=new Map,c=new Map;for(const n of e){const e=t.get(n.source),o=t.get(n.target);if(null==e||null==o)continue;const s=Number.isFinite(n.weight)&&n.weight>0?n.weight:1;l.set(n.source,(l.get(n.source)??0)+o*s),c.set(n.source,(c.get(n.source)??0)+s),l.set(n.target,(l.get(n.target)??0)+e*s),c.set(n.target,(c.get(n.target)??0)+s)}s=s.map((t,e)=>({item:t,index:e,barycenter:(l.get(t)??e)/(c.get(t)??1)})).sort((t,e)=>t.barycenter-e.barycenter||(o.compare?.(t.item,e.item)??t.index-e.index)).map(t=>t.item);const u=n(s);if(r++,u<i)i=u,a=[...s];else if(u===i)break}return a}function c(t,e,n={}){const o=[...t],s=o.length;if(s<=1||s>(n.maxItems??8))return o;const a=Math.max(1,n.maxEvaluations??1/0);let i=0,r=[...o],l=1/0;const c=()=>{if(i>=a)return;const t=e(o);i++,t<l&&(l=t,r=[...o])};c();const u=new Array(s).fill(0);let f=0;for(;f<s&&i<a;)if(u[f]<f){const t=f%2==0?0:u[f];[o[t],o[f]]=[o[f],o[t]],c(),u[f]++,f=0}else u[f]=0,f++;return r}function u(){return Object.create(null)}function f(t,e){return t<e?-1:t>e?1:0}function d(t){return t.occupants.map(t=>t.id).sort(f).join("\0")}function g(t,e,n=0){return t.slice(0,-1).map((o,s)=>{const a=t[s+1];return null!=o.group&&o.group===a.group?n:e})}function m(t,e){return t.map(t=>{const n=new Map;for(const o of t.occupants){const t=e[o.id];if(t)for(const e of t.samples){const t=n.get(e.t)??{before:0,after:0},o=e.boundaryOffset??0;n.set(e.t,{before:Math.max(t.before,e.topMass-o),after:Math.max(t.after,e.botMass+o)})}}return[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({at:t,...e}))})}function p(t,e,n){if(0===t.length)return[];const{padding:o,plotH:s,valueScale:a}=n,i=n.stackValueScale??a,r=g(t,o,n.groupPadding??0),l=[o+t[0].peak.topPeak*i];for(let n=1;n<t.length;n++)l.push(l[n-1]+e[n-1]*i+r[n-1]);const c=l[l.length-1]+t[t.length-1].peak.botPeak*i+o;if(c>s&&c>0){const t=s/c;for(let e=0;e<l.length;e++)l[e]*=t}return l}function h(t,e){const n=(t.boundaryOffset??0)*e,o=t.value*e;if("out"===t.kind){const s=t.sideMassBefore*e;return n+("top"===t.side?o/2-s:s-o/2)}const s=t.sideMassAfter*e;return n+("top"===t.side?o/2-s:s-o/2)}function b(t,e,n,o,s,i){const l=i.adjacentClearance?[...i.adjacentClearance]:r(m(o,n)).adjacentClearance,c=p(o,l,i);let f="hug"===i.lanePlacement?function(t,e,n,o,s,i,r){const l=t.length;if(0===l)return[];const{padding:c,plotH:u,valueScale:f}=r,d=g(t,c,r.groupPadding??0),m=s.map((t,e)=>t*f+d[e]),b=c+t[0].peak.topPeak*f,M=u-c-t[l-1].peak.botPeak*f;if(M-b<=m.reduce((t,e)=>t+e,0)+1e-6)return p(t,s,r);let y=1===l?[(b+M)/2]:[...i];for(let t=0;t<12;t++){const t=new Array(l).fill(0),s=new Array(l).fill(0);for(const a of n){const n=e[a.source],i=e[a.target];if(null==n||null==i||n===i)continue;const r=o[a.source]?.localAttachments.get(a.id),l=o[a.target]?.localAttachments.get(a.id);if(!r||!l)continue;const c=a.value>0&&Number.isFinite(a.value)?a.value:1,u=h(r,f),d=h(l,f);t[n]+=(y[i]+d-u)*c,s[n]+=c,t[i]+=(y[n]+u-d)*c,s[i]+=c}const i=a({desired:y.map((e,n)=>0===s[n]?e:.45*e+t[n]/s[n]*.55),minGaps:m,weights:s.map(t=>Math.max(1,t)),min:b,max:M});let r=0;for(let t=0;t<l;t++)r=Math.max(r,Math.abs(i[t]-y[t]));if(y=i,r<.01)break}return y}(o,s,e,n,l,c,i):[...c];if("hug"===i.lanePlacement){const n=e=>{const n=u();for(const o of t)n[o.id]=e[s[o.id]];return n};M(n(f),e)>M(n(c),e)+1e-6&&(f=[...c])}const d=u();for(const e of t)d[e.id]=f[s[e.id]];let b=1/0,y=-1/0;for(const e of t){const t=d[e.id],o=n[e.id];Number.isFinite(t)&&o&&(b=Math.min(b,t-o.topPeak*i.valueScale),y=Math.max(y,t+o.botPeak*i.valueScale))}return{adjacentClearance:l,centerlines:d,slotCenter:f,stackCenter:c,verticalUtilization:Number.isFinite(b)&&Number.isFinite(y)&&i.plotH>0?Math.max(0,Math.min(1,(y-b)/i.plotH)):0}}function M(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];Number.isFinite(e)&&Number.isFinite(s)&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}function y(t,e){const n=t?.samples;if(!n||0===n.length||e<n[0].t)return{top:0,bot:0};let o=0,s=n.length-1,a=0;for(;o<=s;){const t=o+s>>>1;n[t].t<=e?(a=t,o=t+1):s=t-1}const i=n[a].boundaryOffset??0;return{top:n[a].topMass-i,bot:n[a].botMass+i}}function x(t,e,n,o,s){const a=1-s;return a*a*a*t+3*a*a*s*e+3*a*s*s*n+s*s*s*o}function v(t,e){let n=0,o=1;for(let s=0;s<28;s++){const s=(n+o)/2;x(0,e,e,1,s)<t?n=s:o=s}return(n+o)/2}function w(t,e,n){const o=e+h(t,n),s=t.value*n/2;return[o-s,o+s]}function k(t,e,n,o){return Math.max(0,Math.min(e,o)-Math.max(t,n))/Math.max(1e-9,e-t)}function T(t,e,n,o,s,a,i){const{valueScale:r,domain:l,mode:c="quality"}=i,u="source"===i.ribbonLane?.85:"target"===i.ribbonLane?.15:.5;let f=0;for(const i of t){const t=o[i.source],d=o[i.target];if(null==t||null==d||Math.abs(t-d)<2)continue;const g=e[i.source]?.localAttachments.get(i.id),m=e[i.target]?.localAttachments.get(i.id);if(!g||!m)continue;const p=Math.max(i.startTime,l?.[0]??-1/0),h=Math.min(i.endTime,l?.[1]??1/0);if(!(h>p))continue;const[b,M]=w(g,s[i.source],r),[T,S]=w(m,s[i.target],r),O=Math.min(t,d)+1,N=Math.max(t,d)-1;for(let t=O;t<=N;t++){const o=n[t];if(!o)continue;const l=[p,h];if("quality"===c)for(const t of o.occupants)for(const n of e[t.id]?.samples??[])n.t>p&&n.t<h&&l.push(n.t);const d=t=>{const n=v((t-p)/(h-p),u),l=x(b,b,T,T,n),c=x(M,M,S,S,n);let f=0;for(const n of o.occupants){if(n.id===i.source||n.id===i.target)continue;const o=a[n.id];if(null!=o?.start&&t<o.start)continue;if(null!=o?.end&&t>o.end)continue;const u=y(e[n.id],t),d=s[n.id];f=Math.max(f,k(l,c,d-u.top*r,d+u.bot*r))}return f},g=[...new Set(l)].sort((t,e)=>t-e);let m=0;for(let t=0;t<g.length-1;t++){const e=g[t],n=g[t+1]-e;m+=(d(e+.25*n)+d(e+.5*n)+d(e+.75*n))/3*n}f+=m/(h-p)*(i.value>0?i.value:1)}}return f}function S(t,e,n,o,s,a,i,r,l,c,u="both",f){return{crossings:t,weightedLength:e,pixelLength:M(i,n),transitOcclusion:T(n,o,s,a,i,r,{valueScale:l,ribbonLane:u,domain:f,mode:"quality"}),verticalUtilization:c}}function O(t,e){return e?Math.max(e[0],Math.min(e[1],t)):t}function N(t,e){return t.map(t=>({t:O(t.t,e),topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}}))}function P(t,e,n){const o=e+(t.boundaryOffset??0)*n,s=t.value*n;if("out"===t.kind){const e=t.sideMassBefore*n;if("top"===t.side){const t=o-e;return[t,t+s]}const a=o+e;return[a-s,a]}const a=t.sideMassAfter*n;if("top"===t.side){const t=o-a;return[t,t+s]}const i=o+a;return[i-s,i]}function F(t,e,n,o,s="temporal"){const a=e.incoming[t.id],i=e.outgoing[t.id],r=[];for(const t of a)r.push({time:t.endTime,delta:+t.value,edge:t,kind:"in",side:n.get(t.id).targetSide});for(const t of i)r.push({time:t.startTime,delta:-t.value,edge:t,kind:"out",side:n.get(t.id).sourceSide});const l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=()=>{r.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(!o||!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 n=o.get(t.edge.id)?.target,s=o.get(e.edge.id)?.target;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?n-s:s-n:0}if("in"===t.kind){if(t.edge.source===e.edge.source&&t.edge.startTime===e.edge.startTime)return 0;const n=o.get(t.edge.id)?.source,s=o.get(e.edge.id)?.source;return"number"==typeof n&&Number.isFinite(n)&&"number"==typeof s&&Number.isFinite(s)&&n!==s?"top"===t.side?s-n:n-s:0}return 0})(t,e)||f(t.edge?.id??"",e.edge?.id??"")||f(t.side,e.side)||t.delta-e.delta)},u=r.length?function(t,e=1/0){let n=e;for(const e of t)e<n&&(n=e);return n}(r.map(t=>t.time)):null,d=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[0])?t.xExtent[0]:null,g=null!=d?d-1:null!=u&&Number.isFinite(u)?u-1:null;c();let m=null,p=0;for(const t of r)t.time!==m&&(m=t.time,p=0),t.sequence=p++;const h=t=>({time:t.time,phase:0,sequence:t.sequence??0}),b=[];let M=0,y=0;for(const t of r)if("out"===t.kind){const e=Math.abs(t.delta);let n=e-("top"===t.side?M:y);if(n>0){const e="top"===t.side?"bot":"top",o="top"===e?M:y,s=Math.min(n,o);if(s>0){const o=h(t);b.push({...o,delta:-s,kind:"transfer-out",side:e}),b.push({...o,delta:+s,kind:"transfer-in",side:t.side}),"top"===e?M-=s:y-=s,"top"===t.side?M+=s:y+=s,n-=s}n>0&&null!==g&&(b.push({time:g,delta:+n,kind:"create",side:t.side}),"top"===t.side?M+=n:y+=n)}"top"===t.side?M-=e:y-=e}else if("in"===t.kind){const e=Math.abs(t.delta);"top"===t.side?M+=e:y+=e}r.push(...b),c();let x=0,v=0,w=0,k=0,T=0,S=0;const O=[],N=new Map,P=t=>{O.push({t:t,topMass:x,botMass:v,...Math.abs(w)>1e-12&&{boundaryOffset:w}})},F=()=>{k=Math.max(k,x+v),T=Math.max(T,x-w),S=Math.max(S,v+w)};for(const t of r){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?x:v,n=e+t.delta;N.set(t.edge.id,{side:t.side,time:t.time,sideMassBefore:e,sideMassAfter:n,kind:t.kind,value:Math.abs(t.delta),...Math.abs(w)>1e-12&&{boundaryOffset:w}})}"top"===t.side?x+=t.delta:v+=t.delta,"transfer-in"===t.kind?(w+="top"===t.side?t.delta:-t.delta,F(),P(t.time)):"transfer-out"!==t.kind&&(F(),"out"===t.kind&&x+v<=1e-12&&(w=0),P(t.time))}const A=[];let I=0;for(;I<O.length;){let t=I;for(;t+1<O.length&&O[t+1].t===O[I].t;)t++;A.push(O[I]);for(let e=I+1;e<=t;e++){const t=A[A.length-1];O[e].topMass===t.topMass&&O[e].botMass===t.botMass&&(O[e].boundaryOffset??0)===(t.boundaryOffset??0)||A.push(O[e])}I=t+1}const E=Array.isArray(t.xExtent)&&Number.isFinite(t.xExtent[1])?t.xExtent[1]:null;let $=null;for(const t of i)null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime&&(null===$||t.systemInTime<$)&&($=t.systemInTime);let L=null;for(const t of a)null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>t.endTime&&(null===L||t.systemOutTime>L)&&(L=t.systemOutTime);if(A.length>0){const t=A[A.length-1],e=Math.max(null!=E?E:-1/0,null!=L?L:-1/0);Number.isFinite(e)&&e>t.t&&t.topMass+t.botMass>0&&A.push({t:e,topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}});const n=A[0],o=A.find(t=>t.topMass+t.botMass>0);let s,a=1/0;null!=d&&Number.isFinite(d)&&d<n.t&&n.topMass+n.botMass>0&&(a=d,s=n),o&&null!=$&&Number.isFinite($)&&$<o.t&&$<a&&(a=$,s=o),s&&Number.isFinite(a)&&A.unshift({t:a,topMass:s.topMass,botMass:s.botMass,...null!=s.boundaryOffset&&{boundaryOffset:s.boundaryOffset}})}let B=A;if("max"===s&&null!=d&&null!=E&&E>d){let t,e=0;for(const n of A){const o=n.topMass+n.botMass;o>e&&(e=o,t=n)}if(t){const e={topMass:t.topMass,botMass:t.botMass,...null!=t.boundaryOffset&&{boundaryOffset:t.boundaryOffset}};B=[...A.filter(t=>t.t<d),{t:d,...e},{t:E,...e},...A.filter(t=>t.t>E)]}}return{samples:B,peak:k,topPeak:T,botPeak:S,localAttachments:N}}function A(t){const e=u();return t.forEach((t,n)=>{for(const o of t.occupants)e[o.id]=n}),e}function I(t,e,n){t.splice(0,t.length,...n);const o=A(n);for(const t of Object.keys(e))delete e[t];Object.assign(e,o)}function E(t){const e=new Map,n=[];t.forEach((t,o)=>{if(!t.group)return void n.push({anchor:o,stableId:d(t),slots:[t]});const s=e.get(t.group)??{indexes:[],slots:[]};s.indexes.push(o),s.slots.push(t),e.set(t.group,s)});for(const[t,o]of e)n.push({anchor:o.indexes.reduce((t,e)=>t+e,0)/o.indexes.length,stableId:`${t}\0${o.slots.map(d).join("\0")}`,slots:o.slots});return n.sort((t,e)=>t.anchor-e.anchor||f(t.stableId,e.stableId))}function $(t){return t.some(t=>t.group)?E(t).flatMap(t=>t.slots):[...t]}function L(t){return t.flatMap(t=>t.slots)}function B(t,e,n){const o=new Map;return t.forEach((t,e)=>{for(const n of t.slots)o.set(n,e)}),t.map((t,s)=>{if(t.slots.length<=1)return t;const a=new Map;for(const e of t.slots)a.set(e,0);for(const t of e){const e=o.get(t.source),n=o.get(t.target);if(null==e||null==n)continue;const i=Number.isFinite(t.weight)&&t.weight>0?t.weight:1;if(e===s&&n!==s){const e=n>s?1:-1;a.set(t.source,(a.get(t.source)??0)+i*e)}else if(n===s&&e!==s){const n=e>s?1:-1;a.set(t.target,(a.get(t.target)??0)+i*n)}}const i=[...t.slots].sort((t,e)=>(a.get(t)??0)-(a.get(e)??0)||n(t,e));return{...t,slots:i}})}function z(t,e){t.some(t=>t.group)&&I(t,e,$(t))}function C(t,e){return t.source!==e.source&&t.target!==e.target&&t.source!==e.target&&t.target!==e.source&&Math.max(t.startTime,e.startTime)<Math.min(t.endTime,e.endTime)}function X(t,e){return function(t,e,n=()=>!0){let o=0;for(let s=0;s<t.length;s++){const[a,i]=e(t[s]);for(let r=s+1;r<t.length;r++){if(!n(t[s],t[r]))continue;const[l,c]=e(t[r]);(a-l)*(i-c)<0&&o++}}return o}(e,e=>[t[e.source],t[e.target]],C)}function j(t,e){let n=0;for(const o of e){const e=t[o.source],s=t[o.target];null!=e&&null!=s&&(n+=Math.abs(e-s)*(o.value>0?o.value:1))}return n}function H(t,e,n){const[o,s]=n.get(t.first),[a,i]=n.get(t.second);return(e.get(o)-e.get(a))*(e.get(s)-e.get(i))<0?1:0}var D=t=>{let e=1;for(let n=2;n<=t;n++)e*=n;return e},Y=828*D(8),q=3e3;function V(t,e,n,o,s,a,i){const u=[...s],g=new Map(s.map(t=>[t,d(t)])),p=new Map;for(const t of s)for(const e of t.occupants)p.set(e.id,t);const h=new Map,y=[];for(const t of e){const e=p.get(t.source),n=p.get(t.target);e&&n&&(h.set(t,[e,n]),e!==n&&y.push({source:e,target:n,weight:t.value}))}const x=[];for(let t=0;t<e.length;t++)if(h.has(e[t]))for(let n=t+1;n<e.length;n++){if(!h.has(e[n])||!C(e[t],e[n]))continue;const o=new Set([...h.get(e[t]),...h.get(e[n])]);x.push({index:x.length,first:e[t],second:e[n],involvedSlots:o})}const v=new Map;for(const t of s)v.set(t,[]);for(const t of x)for(const e of t.involvedSlots)v.get(e)?.push(t);const w=new Uint32Array(x.length);let k=0;const S=e.reduce((t,e)=>t+(e.value>0?e.value:1),0),O=i.plotH/Math.max(1,s.length),N=s.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),P=Math.max(1,S)*(Math.max(1,i.plotH)+O*Math.max(N,s.length)+1e-6*Math.max(1,s.length-1))+1,F=4*O,z={fullCrossing:0,localCrossing:0},X=new Map,V=(t,e)=>{let o=X.get(t);o||(o=new Map,X.set(t,o));const s=o.get(e);if(null!=s)return s;const a=function(t,e,n){return r(m([t,e],n)).adjacentClearance[0]??0}(t,e,n);return o.set(e,a),a},U=new Map(s.map((t,e)=>[t,e])),W=e.flatMap(t=>{const e=h.get(t);return e?[{source:U.get(e[0]),target:U.get(e[1]),weight:t.value>0?t.value:1}]:[]}),G=new Map;for(const t of e){const e=h.get(t);e&&G.set(t,{source:U.get(e[0]),target:U.get(e[1])})}const R=new Map,_=new Map,Z=new Map,Q=(t,e,n)=>{t.has(e)||t.set(e,new Set),t.get(e).add(n)};for(const t of e)Q(R,t.source,t.target),Q(_,t.target,t.source),Q(Z,t.source,t.target),Q(Z,t.target,t.source);const J=e.flatMap(t=>{if(!(t=>1===R.get(t.source)?.size&&R.get(t.source).has(t.target)||1===Z.get(t.source)?.size||1===Z.get(t.target)?.size)(t))return[];const e=G.get(t);return e&&e.source!==e.target?[{source:e.source,target:e.target,weight:t.value>0?t.value:1}]:[]}),K=t=>{let e=0;for(const n of J)e+=Math.max(0,Math.abs(t[n.source]-t[n.target])-1)*n.weight;return e*F},tt=t=>{const e=new Int16Array(s.length);for(let n=0;n<t.length;n++)e[U.get(t[n])]=n;return K(e)},et=x.map(t=>{const e=G.get(t.first),n=G.get(t.second);return[e.source,e.target,n.source,n.target]}),nt=new Int16Array(s.length),ot=new Float64Array(s.length),st=new Float64Array(s.length+1),at=t=>{for(let e=0;e<t.length;e++)nt[U.get(t[e])]=e;let e=0;for(const[t,n,o,s]of et)(nt[t]-nt[o])*(nt[n]-nt[s])<0&&e++;if(t.length>0){const e=U.get(t[0]);ot[e]=i.padding+t[0].peak.topPeak*i.valueScale;for(let e=1;e<t.length;e++){const n=U.get(t[e-1]),o=U.get(t[e]);ot[o]=ot[n]+V(t[e-1],t[e])*i.valueScale+i.padding}const n=U.get(t[t.length-1]),o=ot[n]+t[t.length-1].peak.botPeak*i.valueScale+i.padding;if(o>i.plotH&&o>0){const t=i.plotH/o;for(let e=0;e<ot.length;e++)ot[e]*=t}}st[0]=0;for(let e=0;e<t.length;e++)st[e+1]=st[e]+t[e].peak.topPeak+t[e].peak.botPeak;let n=0,o=0,s=0;for(const t of W){const e=nt[t.source],a=nt[t.target];if(n+=Math.abs(e-a)*t.weight,o+=Math.abs(ot[t.source]-ot[t.target])*t.weight,Math.abs(e-a)>=2){const n=Math.min(e,a)+1,o=Math.max(e,a);s+=(st[o]-st[n])*t.weight}}return e*P+o+s*O+K(nt)+1e-6*n},it=(t,n)=>{const o=new Array(t.length+1).fill(0);for(let e=0;e<t.length;e++)o[e+1]=o[e]+t[e].peak.topPeak+t[e].peak.botPeak;let s=0;for(const t of e){const e=n[t.source],a=n[t.target];if(null==e||null==a||Math.abs(e-a)<2)continue;const i=Math.min(e,a)+1;s+=(o[Math.max(e,a)]-o[i])*(t.value>0?t.value:1)}return s},rt=o=>{const s=A(o),a=o.slice(0,-1).map((t,e)=>V(t,o[e+1])),r=b(t,e,n,o,s,{plotH:i.plotH,padding:i.padding,valueScale:i.valueScale,lanePlacement:i.lanePlacement??"stack",groupPadding:i.groupPadding,adjacentClearance:a});return{map:s,geometry:r,weightedLength:j(s,e),pixelLength:M(r.centerlines,e),transitOcclusion:it(o,s)}},lt=(t,e,n)=>({crossings:t,weightedLength:e.weightedLength,pixelLength:e.pixelLength,transitOcclusion:e.transitOcclusion,cost:t*P+e.pixelLength+e.transitOcclusion*O+tt(n)+1e-6*e.weightedLength}),ct=(t,e)=>{let n=e;if(null==n){const e=new Map(t.map((t,e)=>[t,e]));n=x.reduce((t,n)=>t+H(n,e,h),0),z.fullCrossing++}return lt(n,rt(t),t)},ut=(t,s,a="quality")=>{let r=s;if(null==r){const e=new Map(t.map((t,e)=>[t,e]));r=x.reduce((t,n)=>t+H(n,e,h),0),z.fullCrossing++}const l=rt(t);return lt(r,{...l,transitOcclusion:T(e,n,t,l.map,l.geometry.centerlines,o,{valueScale:i.valueScale,ribbonLane:i.ribbonLane,domain:i.domain,mode:a})},t)};let ft=[...u];const dt=(t,e)=>f(g.get(t),g.get(e)),gt=function(t){const e=new Set;for(const n of t)if(n.group){if(e.has(n.group))return!0;e.add(n.group)}return!1}(ft),mt=t=>{const e=(t=>{const e=l(t,y,t=>ct(t).cost,{passes:6,compare:dt,maxEvaluations:q});let n=ct(e),o=q;for(let t=0;t<6&&o>0;t++){let s=!1;const a=Array.from({length:e.length-1},(t,e)=>e);t%2==1&&a.reverse();for(const t of a){if(o--<=0)break;const a=e[t],i=e[t+1],r=new Map(e.map((t,e)=>[t,e]));let l=0;const c=[];k++;for(const t of[...v.get(a)??[],...v.get(i)??[]])w[t.index]!==k&&(w[t.index]=k,c.push(t),l+=H(t,r,h));[e[t],e[t+1]]=[i,a];const u=new Map(r);u.set(a,t+1),u.set(i,t);let f=0;for(const t of c)f+=H(t,u,h);z.localCrossing+=c.length;const d=ct(e,n.crossings-l+f);d.cost<n.cost?(n=d,s=!0):[e[t],e[t+1]]=[a,i]}if(!s)break}return e})(t);if((t.length<=8?D(t.length)*(t.length+W.length+et.length):1/0)>Y)return e;const n=c(t,at,{maxItems:8,maxEvaluations:5e4}),o=ut(n),s=ut(e);return o.crossings!==s.crossings&&o.crossings<s.crossings?n:e},pt=t=>{let e=E(t);if(e.length<=1)return L(e);const n=t=>ct(L(t)).cost;e=E(mt(t)),e=B(e,y,dt);const o=function(t,e){const n=new Map;for(const e of t)for(const t of e.slots)n.set(t,e);const o=new Map;for(const t of e){const e=n.get(t.source),s=n.get(t.target);if(!e||!s||e===s)continue;const a=Number.isFinite(t.weight)&&t.weight>0?t.weight:1,i=e.stableId<s.stableId?`${e.stableId}\0${s.stableId}`:`${s.stableId}\0${e.stableId}`,r=o.get(i);r?r.weight=(r.weight??0)+a:o.set(i,{source:e,target:s,weight:a})}return[...o.values()]}(e,y);e=l(e,o,n,{passes:6,compare:(t,e)=>f(t.stableId,e.stableId),maxEvaluations:q}),e=function(t,e,n={}){const o=[...t];if(o.length<=1)return o;let s=e(o),a=1;const i=Math.max(0,n.passes??6),r=Math.max(1,n.maxEvaluations??1/0);for(let t=0;t<i&&a<r;t++){let t=!1;for(let n=0;n<o.length-1&&a<r;n++){[o[n],o[n+1]]=[o[n+1],o[n]];const i=e(o);a++,i<s?(s=i,t=!0):[o[n],o[n+1]]=[o[n+1],o[n]]}if(!t)break}return o}(e,n,{passes:8,maxEvaluations:q});if((e.length<=8?D(e.length)*(e.length+W.length+et.length):1/0)<=Y){const t=c(e,t=>at(L(t)),{maxItems:8,maxEvaluations:5e4}),n=L(t),o=L(e),s=ut(n),a=ut(o);s.crossings!==a.crossings?e=s.crossings<a.crossings?t:e:s.cost<a.cost&&(e=t)}return e=B(e,y,dt),L(e)},ht="geometry-refine"===i.mode;if(ht||"crossing-min"!==i.laneOrder&&"crossing-min+inside-out"!==i.laneOrder){if(!ht&&"inside-out"===i.laneOrder)if(gt){const t=E(ft),e=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),n=[...t].sort((t,n)=>e(n)-e(t)||f(t.stableId,n.stableId)),o=new Array(n.length);let s=Math.floor((n.length-1)/2)-1,a=Math.floor((n.length-1)/2)+1;n.length>0&&(o[Math.floor((n.length-1)/2)]=n[0]);for(let t=1;t<n.length;t++)t%2==1&&a<n.length?o[a++]=n[t]:s>=0?o[s--]=n[t]:o[a++]=n[t];ft=L(o)}else{const t=[...ft].sort((t,e)=>{const n=t.peak.topPeak+t.peak.botPeak;return e.peak.topPeak+e.peak.botPeak-n||dt(t,e)}),e=new Array(t.length);let n=Math.floor((t.length-1)/2)-1,o=Math.floor((t.length-1)/2)+1;t.length>0&&(e[Math.floor((t.length-1)/2)]=t[0]);for(let s=1;s<t.length;s++)s%2==1&&o<t.length?e[o++]=t[s]:n>=0?e[n--]=t[s]:e[o++]=t[s];ft=e}}else ft=gt?pt(ft):mt(ft);if(!ht&&"crossing-min+inside-out"===i.laneOrder&&ft.length>1)if(gt){const t=E(ft);let e=ct(L(t)),n=L(t),o=e;const s=Math.floor((t.length-1)/2),a=t=>t.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),i=[...t].sort((t,e)=>a(e)-a(t)||f(t.stableId,e.stableId));for(const a of i){const i=t.indexOf(a);if(i===s)continue;t.splice(i,1),t.splice(s,0,a);const r=L(t),l=ct(r);l.cost<=e.cost?(e=l,l.cost<o.cost&&(n=r,o=l)):(t.splice(s,1),t.splice(i,0,a))}ft=n}else{let t=ct(ft),e=[...ft],n=t;const o=Math.floor((ft.length-1)/2),s=[...ft].sort((t,e)=>e.peak.topPeak+e.peak.botPeak-(t.peak.topPeak+t.peak.botPeak)||dt(t,e));for(const a of s){const s=ft.indexOf(a);if(s===o)continue;ft.splice(s,1),ft.splice(o,0,a);const i=ct(ft);i.cost<=t.cost?(t=i,i.cost<n.cost&&(e=[...ft],n=i)):(ft.splice(o,1),ft.splice(s,0,a))}ft=e}if((ht||"crossing-min"===i.laneOrder||"crossing-min+inside-out"===i.laneOrder)&&ft.length>1)if(gt){let t=E(ft),e=ut(L(t),void 0,"score");for(let n=0;n<6&&t.length>1;n++){let n=!1;for(let o=0;o<t.length-1;o++){[t[o],t[o+1]]=[t[o+1],t[o]];const s=L(t),a=ut(s,void 0,"score");a.cost<e.cost?(ft=s,e=a,n=!0):[t[o],t[o+1]]=[t[o+1],t[o]]}if(!n)break}t=B(E(ft),y,dt),ft=L(t)}else{let t=ut(ft,void 0,"score");for(let e=0;e<ft.length-1;e++){const n=ft[e],o=ft[e+1],s=new Map(ft.map((t,e)=>[t,e]));let a=0;const i=[];k++;for(const t of[...v.get(n)??[],...v.get(o)??[]])w[t.index]!==k&&(w[t.index]=k,i.push(t),a+=H(t,s,h));[ft[e],ft[e+1]]=[o,n];const r=new Map(s);r.set(n,e+1),r.set(o,e);let l=0;for(const t of i)l+=H(t,r,h);z.localCrossing+=i.length;const c=ut(ft,t.crossings-a+l,"score");c.cost<t.cost?t=c:[ft[e],ft[e+1]]=[n,o]}}const bt=$(u);ft=$(ft);let Mt=ut(ft);const yt=ut(bt);if(ht){const t=tt(bt),e=tt(ft);(Mt.crossings>yt.crossings||Mt.crossings===yt.crossings&&e>t+1e-9||Mt.cost>yt.cost)&&(ft=bt,Mt=yt)}else Mt.cost>yt.cost&&(ft=bt,Mt=yt);const xt=function({order:t,after:e,nodes:n,edges:o,outgoingPartners:s,incomingPartners:a,slotForNode:i,averageGap:r,evaluate:l}){const c=(n,s)=>{const a=[...new Set(s.map(e=>t.indexOf(e)))].sort((t,e)=>t-e),i=t.indexOf(n),c=a[0],u=a[a.length-1];if(a.length<3||!a.includes(i)||u-c+1!==a.length||Math.abs(2*i-c-u)<=1)return;const f=[...t];f.splice(i,1),f.splice(c+u>>1,0,n);const d=$(f),g=l(d),m=new Set(n.occupants.map(t=>t.id)),p=new Set(s.flatMap(t=>t.occupants.map(t=>t.id))),h=o.reduce((t,e)=>m.has(e.source)&&p.has(e.target)||m.has(e.target)&&p.has(e.source)?t+(e.value>0?e.value:1):t,0),b=Math.abs(2*i-c-u)*r*Math.max(1,h);(function(t,e,n=0){return t.crossings<e.crossings||t.crossings===e.crossings&&t.cost<=e.cost+n})(g,e,b)&&(t=d,e=g)};for(const[t,e]of s)!a.has(t)&&e.size>=3&&c(i.get(t),[...e].map(t=>i.get(t)));for(const t of n){const e=i.get(t.id);!t.group&&e.group&&(a.get(t.id)?.size??0)>=3&&c(e,[...a.get(t.id)??[]].map(t=>i.get(t)).filter(t=>t===e||t.group===e.group).filter((t,e,n)=>n.indexOf(t)===e))}return{order:t,after:e}}({order:ft,after:Mt,nodes:t,edges:e,outgoingPartners:R,incomingPartners:_,slotForNode:p,averageGap:O,evaluate:ut});return ft=xt.order,Mt=xt.after,I(s,a,ft),{before:yt,after:Mt,initialOrder:u.map(t=>g.get(t)),evaluations:z}}function U(t,e,n){const o=t.map(t=>{const o=t.occupants.map(t=>({id:t.id,end:n[t.id]?.end??t.end}));let s=0,a=0;for(const t of o){const n=e[t.id];s=Math.max(s,n?.topPeak||0),a=Math.max(a,n?.botPeak||0)}return{occupants:o,peak:{topPeak:s,botPeak:a},...null!=t.group?{group:t.group}:{}}}),s=u();return o.forEach((t,e)=>{for(const n of t.occupants)s[n.id]=e}),{slots:o,slotByNode:s}}var W=new Map;var G=1e5,R=1e-9;function _(t,e){return null!=t.start&&null!=t.end&&null!=e.start&&null!=e.end&&!(t.end<=e.start||e.end<=t.start)}function Z(t,e){return f(t,e)<=0?`${t}\0${e}`:`${e}\0${t}`}function Q(t){const e=new Map,n=new Map;for(const o of t)n.has(o.source)||n.set(o.source,new Set),e.has(o.target)||e.set(o.target,new Set),n.get(o.source).add(o.target),e.get(o.target).add(o.source);return{incoming:new Map([...e].map(([t,e])=>[t,e.size])),outgoing:new Map([...n].map(([t,e])=>[t,e.size]))}}function J(t){const e=new Map,n=new Map,o=(t,e,n,o)=>{let s=t.get(e);s||(s=new Map,t.set(e,s)),s.set(n,(s.get(n)??0)+o)};for(const s of t){const t=s.value>0&&Number.isFinite(s.value)?s.value:1;o(e,s.source,s.target,t),o(n,s.target,s.source,t)}const s=new Map,a=t=>{if(s.has(t))return;const o=e.get(t),a=n.get(t),i=new Map;for(const[t,e]of o??[])i.set(t,(i.get(t)??0)+e);for(const[t,e]of a??[])i.set(t,(i.get(t)??0)+e);if(1===i.size){const[e,n]=[...i][0];s.set(t,{partner:e,weight:n})}};for(const e of t)a(e.source),a(e.target);return s}function K(t,e,n){const o=n.get(t),s=n.get(e);return!o||!s||o.partner===s.partner||o.partner===e||s.partner===t}function tt(t,e,n){return!!n.has(t)&&e.some(e=>!K(t,e,n))}function et(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 nt(t,e,n,o){if(t.length<=12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),a=Array.from({length:t.length},()=>new Map),i=Q(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=et(t,i);a[e].set(n,(a[e].get(n)??0)+o),a[n].set(e,(a[n].get(e)??0)+o)}const r=J(n),l=t.map(t=>r.get(t)?.weight??0),c=Array.from({length:t.length},()=>new Map);let u=0;for(let n=0;n<t.length-1&&u<5e4;n++)if(r.has(t[n]))for(let o=n+1;o<t.length;o++){if(!r.has(t[o]))continue;if(e.conflicts(t[n],t[o]))continue;u++;const s=Math.min(l[n],l[o])||Math.max(l[n],l[o]),a=K(t[n],t[o],r)?s:-s;if(!(Math.abs(a)<=R)&&(c[n].set(o,a),c[o].set(n,a),u>=5e4))break}const f=[...o.assignment],d=Array.from({length:o.slotCount},()=>[]);f.forEach((t,e)=>d[t].push(e));const g=(t,e,n)=>{const o=f[e],s=f[n];let a=0;const i=new Set;for(const r of[e,n])for(const[l,c]of t[r]){const t=r<l?`${r}:${l}`:`${l}:${r}`;if(i.has(t))continue;i.add(t);const u=f[r]===f[l],d=(r===e?s:o)===(l===e?s:l===n?o:f[l]);u!==d&&(a+=d?c:-c)}return a},m=(t,e,n)=>{let o=0;for(const[s,a]of t[e]){const t=f[e]===f[s],i=n===f[s];t!==i&&(o+=i?a:-a)}return o},p=(t,e)=>t>R||Math.abs(t)<=R&&e>R,h=(t,e,n,o)=>t>n+R||Math.abs(t-n)<=R&&e>o+R;let b=0;for(let n=0;n<32&&b<G;n++){let n=null,o=-1,s=-1,i=-1,r=-1/0,l=-1/0;for(let u=0;u<t.length;u++){for(let g=0;g<d.length&&!(b++>=G);g++){if(g===f[u])continue;if(!d[g].every(n=>!e.conflicts(t[u],t[n])))continue;const b=m(a,u,g),M=m(c,u,g);p(b,M)&&h(b,M,r,l)&&(n="move",o=u,s=-1,i=g,r=b,l=M)}if(b>=G)break}for(let u=0;u<t.length-1;u++){for(let m=u+1;m<t.length&&!(b++>=G);m++){const b=f[u],M=f[m];if(b===M)continue;if(!d[M].every(n=>n===m||!e.conflicts(t[u],t[n])))continue;if(!d[b].every(n=>n===u||!e.conflicts(t[m],t[n])))continue;const y=g(a,u,m),x=g(c,u,m);p(y,x)&&h(y,x,r,l)&&(n="swap",o=u,s=m,i=-1,r=y,l=x)}if(b>=G)break}if(null==n||-1===o)break;if("move"===n){const t=f[o];d[t].splice(d[t].indexOf(o),1),d[i].push(o),f[o]=i;continue}const u=f[o],M=f[s];d[u].splice(d[u].indexOf(o),1,s),d[M].splice(d[M].indexOf(s),1,o),f[o]=M,f[s]=u}return f}function ot(t,e,n,o){if(0===t.length||t.length>12||o.slotCount<=1)return o.assignment;const s=new Map(t.map((t,e)=>[t,e])),a=Array.from({length:t.length},()=>new Float64Array(t.length)),i=Array.from({length:t.length},()=>new Map),r=Array.from({length:t.length},()=>new Map),l=Q(n);for(const t of n){const e=s.get(t.source),n=s.get(t.target);if(null==e||null==n||e===n)continue;const o=et(t,l);a[e][n]+=o,a[n][e]+=o,r[e].set(n,(r[e].get(n)??0)+o),i[n].set(e,(i[n].get(e)??0)+o)}const c=J(n),u=t.map(t=>c.get(t)?.weight??0),f=Array.from({length:t.length},()=>new Float64Array(t.length));for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){for(const[t,o]of i[e])f[e][n]+=Math.min(o,i[n].get(t)??0);for(const[t,o]of r[e])f[e][n]+=Math.min(o,r[n].get(t)??0);if(c.has(t[e])&&c.has(t[n])){const o=Math.min(u[e],u[n])||Math.max(u[e],u[n]);f[e][n]+=K(t[e],t[n],c)?o:-o}f[n][e]=f[e][n]}let d=[...o.assignment],g=(e=>{let n=0,o=0;for(let s=0;s<t.length;s++)for(let i=s+1;i<t.length;i++)e[s]===e[i]&&(n+=a[s][i],o+=f[s][i]);return{flow:n,affinity:o}})(d),m=0;const p=new Array(t.length).fill(-1),h=Array.from({length:o.slotCount},()=>[]),b=(n,s,i,r)=>{if(m>=75e3)return;if(n===t.length)return m++,void((i>g.flow||i===g.flow&&r>g.affinity||i===g.flow&&r===g.affinity&&function(t,e){for(let n=0;n<Math.min(t.length,e.length);n++)if(t[n]!==e[n])return t[n]<e[n];return t.length<e.length}(p,d))&&(d=[...p],g={flow:i,affinity:r}));const l=Math.min(s+1,o.slotCount-1);for(let o=0;o<=l;o++){if(h[o].some(o=>e.conflicts(t[n],t[o])))continue;let l=0,c=0;for(const t of h[o])l+=a[n][t],c+=f[n][t];if(p[n]=o,h[o].push(n),b(n+1,Math.max(s,o),i+l,r+c),h[o].pop(),p[n]=-1,m>=75e3)return}};return p[0]=0,h[0].push(0),b(1,0,0,0),d}function st(t,e){let n=1/0,o=-1/0;for(const e of t?.samples??[])e.topMass+e.botMass<=1e-9||(n=Math.min(n,e.t),o=Math.max(o,e.t));return Number.isFinite(n)&&Number.isFinite(o)?(null!=e.start&&(n=Math.max(n,e.start)),null!=e.end&&(o=Math.min(o,e.end)),o>=n?{start:n,end:o}:{start:null,end:null}):{start:null,end:null}}function at(t,e,n,o){const s=function(t,e,n,o){return`${t.map(t=>{const e=n[t.id],s=o[t.id];return[t.id,t.group??"",t.xExtent?.[0]??"",t.xExtent?.[1]??"",e?.topPeak??0,e?.botPeak??0,s?.start??"",s?.end??""].join(":")}).join("|")}#${e.map(t=>[t.id,t.source,t.target,t.value,t.startTime,t.endTime].join(":")).join("|")}`}(t,e,n,o),a=(i=s,W.get(i));var i;if(a)return U(a.slots,n,o);const r=u();for(const e of t)r[e.id]=st(n[e.id],o[e.id]);const l=function(t,e){return t.filter(t=>null!=e[t.id].start).sort((t,n)=>e[t.id].start-e[n.id].start||e[t.id].end-e[n.id].end||f(t.id,n.id)).map(t=>t.id)}(t,r),c=new Map(t.map(t=>[t.id,t])),d=new Map(t.map(t=>[t.id,t.group||void 0])),g=J(e),m=function(t,e,n,o,s,a){const i=new Set,r=new Map(t.map(t=>[t,new Set])),l=new Map(t.map(t=>[t,new Set]));for(const t of o)i.add(Z(t.source,t.target)),r.get(t.target)?.add(t.source),l.get(t.source)?.add(t.target);const c=new Map,u=new Set,f=(t,e)=>{for(let n=0;n<t.length;n++)for(let o=n+1;o<t.length;o++){const s=Z(t[n],t[o]);e instanceof Map?e.set(s,[t[n],t[o]]):e.add(s)}};for(const t of l.values())f([...t],c);for(const t of r.values())f([...t],u);const d=new Set;for(const[t,[o,s]]of c)u.has(t)&&(_(e[o],e[s])||_(n[o],n[s])&&(d.add(o),d.add(s)));return{conflicts:(t,n)=>{const o=s.get(t),r=s.get(n);return null!=o&&null!=r&&o!==r||!(null!=o==(null!=r)||i.has(Z(t,n))||a.has(t)&&a.has(n)&&K(t,n,a))||!!_(e[t],e[n])||!(!d.has(t)&&!d.has(n))&&!i.has(Z(t,n))}}}(l,r,o,e,d,g),p=function(t,e,n=new Map){const o=[],s=[];for(const a of t){let t=o.findIndex(t=>t.every(t=>!e.conflicts(a,t))&&!tt(a,t,n));-1!==t||n.has(a)||(t=o.findIndex(t=>t.every(t=>!e.conflicts(a,t)))),-1===t&&(t=o.length,o.push([])),o[t].push(a),s.push(t)}return{assignment:s,slotCount:o.length}}(l,m,g),h=ot(l,m,e,{...p,assignment:nt(l,m,e,p)}),b=new Map,M=h.map(t=>(b.has(t)||b.set(t,b.size),b.get(t))),y=Array.from({length:b.size||(t.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),x=u();l.forEach((t,e)=>{const n=M[e],o=y[n];o.occupants.push({id:t,end:r[t].end??-1/0});const s=c.get(t)?.group;s&&(o.group=s),x[t]=n});for(const e of[...t].sort((t,e)=>f(t.id,e.id)))null==x[e.id]&&(y[0].occupants.push({id:e.id,end:-1/0}),x[e.id]=0);for(const t of y){t.occupants.sort((t,e)=>(r[t.id].start??1/0)-(r[e.id].start??1/0)||f(t.id,e.id));for(const e of t.occupants){const o=n[e.id];t.peak.topPeak=Math.max(t.peak.topPeak,o?.topPeak||0),t.peak.botPeak=Math.max(t.peak.botPeak,o?.botPeak||0)}}const v={slots:y,slotByNode:x};return function(t,e){for(W.has(t)&&W.delete(t),W.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(u(),e.slotByNode)});W.size>12;){const t=W.keys().next().value;if(null==t)break;W.delete(t)}}(s,v),v}function it(t){return t.topMass+t.botMass}function rt(t,e){const n=t.samples.filter(t=>t.t===e);if(n.length>0)return n.reduce((t,e)=>it(e)>=it(t)?e:t,n[0]);let o=null;for(const n of t.samples){if(n.t>e)break;o=n}return o}function lt(t,e,n,o,s,a,i=0){const r=new Map;for(const n of t){if(!n.group||!e[n.id])continue;const t=r.get(n.group)??[];t.push(n),r.set(n.group,t)}if(0===r.size||!(a>0))return e;const l=(c=e,Object.fromEntries(Object.entries(c).map(([t,e])=>[t,{...e,samples:e.samples.map(t=>({...t})),localAttachments:new Map([...e.localAttachments].map(([t,e])=>[t,{...e}]))}])));var c;for(const[t,c]of r){const r=n.map((t,e)=>({slot:t,index:e})).filter(({slot:e})=>e.group===t);if(0===r.length)continue;const u=r[0].slot,f=r.at(-1).slot,d=s[u.occupants[0]?.id],g=s[f.occupants[0]?.id];if(!Number.isFinite(d)||!Number.isFinite(g))continue;const m=(d-u.peak.topPeak*a+(g+f.peak.botPeak*a))/2,p=[...new Set(c.flatMap(t=>e[t.id].samples.map(t=>t.t)))].sort((t,e)=>t-e),h=new Map;for(const t of c)h.set(t.id,new Map);for(const t of p){const n=new Map;for(const s of c){const a=rt(e[s.id],t);if(!a||it(a)<=1e-9)continue;const i=o[s.id];if(null==i)continue;const r=n.get(i)??[];r.push({node:s,sample:a}),n.set(i,r)}const r=[...n].sort((t,e)=>t[0]-e[0]).map(([t,e])=>({slot:t,active:e,mass:Math.max(...e.map(({sample:t})=>it(t)))}));if(0===r.length)continue;let l=m-(r.reduce((t,e)=>t+e.mass,0)*a+Math.max(0,i)*Math.max(0,r.length-1))/2;for(const e of r){for(const{node:n,sample:o}of e.active){const e=(l-s[n.id])/a+o.topMass-(o.boundaryOffset??0);h.get(n.id).set(t,e)}l+=e.mass*a+Math.max(0,i)}}for(const t of c){const n=e[t.id],o=l[t.id],s=h.get(t.id),a=[];for(const t of p){const e=s.get(t),o=n.samples.filter(e=>e.t===t);if(o.length>0){a.push(...o.map(t=>({...t,...null!=e?{boundaryOffset:(t.boundaryOffset??0)+e}:{}})));continue}const i=rt(n,t);null==e||!i||it(i)<=1e-9||a.push({...i,t:t,boundaryOffset:(i.boundaryOffset??0)+e})}o.samples=a,o.localAttachments=new Map([...n.localAttachments].map(([t,e])=>{const n=s.get(e.time);return[t,{...e,...null!=n?{boundaryOffset:(e.boundaryOffset??0)+n}:{}}]}))}}return l}function ct(t,e,n,o,s){const{plotH:a,padding:i,valueScale:r,packing:l,laneOrder:c,lifetimeMode:g="half",lanePlacement:m="stack",groupPadding:p=0,ribbonLane:h="both",domain:M}=s,y=u(),x=u();for(const e of t)y[e.id]=n[e.id].topPeak||0,x[e.id]=n[e.id].botPeak||0;const v="half"===g,w=u();for(const e of t){const t=Array.isArray(e.xExtent)?e.xExtent[0]:null,n=Array.isArray(e.xExtent)?e.xExtent[1]:null;let s=null!=t&&Number.isFinite(t)?t:1/0,a=null!=n&&Number.isFinite(n)?n:-1/0;for(const t of o.outgoing[e.id]){t.startTime<s&&(s=t.startTime),null!=t.systemInTime&&Number.isFinite(t.systemInTime)&&t.systemInTime<s&&(s=t.systemInTime);const e=v?(t.startTime+t.endTime)/2:t.endTime;e>a&&(a=e)}for(const t of o.incoming[e.id]){const e=v?(t.startTime+t.endTime)/2:t.startTime;e<s&&(s=e),t.endTime>a&&(a=t.endTime),null!=t.systemOutTime&&Number.isFinite(t.systemOutTime)&&t.systemOutTime>a&&(a=t.systemOutTime)}w[e.id]={start:Number.isFinite(s)?s:null,end:Number.isFinite(a)?a:null}}let k=u(),T=[],S=[];if(s.frozenSlots){const t=U(s.frozenSlots,n,w);T=t.slots,k=t.slotByNode,S=T.map(d)}else if("reuse"===l){const o=at(t,e,n,w);T=o.slots,k=o.slotByNode}else t.forEach((t,e)=>{T.push({occupants:[{id:t.id,end:w[t.id]?.end??-1/0}],peak:{topPeak:y[t.id],botPeak:x[t.id]},...t.group?{group:t.group}:{}}),k[t.id]=e});z(T,k),0===S.length&&(S=T.map(d));let O=null;s.frozenSlots||(s.fixedSlotOrder?function(t,e,n){const o=new Map(n.map((t,e)=>[t,e]));I(t,e,[...t].sort((t,e)=>(o.get(d(t))??1/0)-(o.get(d(e))??1/0)||f(d(t),d(e))))}(T,k,s.fixedSlotOrder):s.runOrdering&&c&&"insertion"!==c&&(O=V(t,e,n,w,T,k,{plotH:a,padding:i,valueScale:r,groupPadding:p,laneOrder:c,ribbonLane:h,domain:M}))),z(T,k);const N=b(t,e,n,T,k,{plotH:a,padding:i,valueScale:r,stackValueScale:s.stackValueScale,lanePlacement:m,groupPadding:p}),P=0===T.length?0:T[0].peak.topPeak+N.adjacentClearance.reduce((t,e)=>t+e,0)+T[T.length-1].peak.botPeak,F=O?.before.crossings??null,A=O?.after.crossings??null,E=O?.before.weightedLength??null,$=O?.after.weightedLength??null;return{effectiveSlotsHeight:P,centerlines:N.centerlines,laneLifetime:w,slots:T,slotByNode:k,slotCenter:N.slotCenter,stackCenter:N.stackCenter,verticalUtilization:N.verticalUtilization,selectedSlotOrder:T.map(d),initialSlotOrder:S,ordering:O,crossingsBefore:F,crossingsAfter:A,lengthBefore:E,lengthAfter:$}}function ut(t,e,n){const{plotH:o,pairing:s="temporal",packing:a="reuse",laneOrder:i="crossing-min",lifetimeMode:r="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:m="temporal",groupPadding:p=0,ribbonLane:h="both",domain:M}=n,y=Number.isFinite(p)?Math.max(0,p):0,x=function(t,e){const n=u(),o=u();for(const e of t)n[e.id]=[],o[e.id]=[];for(const t of e)o[t.source]&&o[t.source].push(t),n[t.target]&&n[t.target].push(t);return{incoming:n,outgoing:o}}(t,e),v=function(t,e,n,o="temporal"){const s="temporal"===o?(t,e)=>t.endTime-e.endTime||f(t.id,e.id):(t,e)=>e.value-t.value||f(t.id,e.id),a="temporal"===o?(t,e)=>t.startTime-e.startTime||f(t.id,e.id):(t,e)=>e.value-t.value||f(t.id,e.id),i=new Map;for(const t of e)i.set(t.id,{});const r=(t,e)=>{const n=new Map;for(const o of t){const t=o[e];n.has(t)||n.set(t,{partner:t,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});const s=n.get(t);s.edges.push(o),s.total+=o.value,s.earliestStart=Math.min(s.earliestStart,o.startTime),s.latestEnd=Math.max(s.latestEnd,o.endTime)}const i=[...n.values()];"temporal"===o?i.sort((t,n)=>"target"===e?t.earliestStart-n.earliestStart||f(t.partner,n.partner):t.latestEnd-n.latestEnd||f(t.partner,n.partner)):i.sort((t,e)=>e.total-t.total||f(t.partner,e.partner));for(const t of i)t.edges.sort("target"===e?a:s);return i};for(const e of t){const t=n.outgoing[e.id],o=n.incoming[e.id];if(0===o.length)r(t,"target").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)i.get(e.id).sourceSide=n});else if(0===t.length)r(o,"source").forEach((t,e)=>{const n=e%2==0?"top":"bot";for(const e of t.edges)i.get(e.id).targetSide=n});else{const e=r(o,"source"),n=r(t,"target"),s=Math.max(e.length,n.length);for(let t=0;t<s;t++){const o=t%2==0?"top":"bot";if(e[t])for(const n of e[t].edges)i.get(n.id).targetSide=o;if(n[t])for(const e of n[t].edges)i.get(e.id).sourceSide=o}}}return i}(t,e,x,s);let w=u();for(const e of t)w[e.id]=F(e,x,v,void 0,m);const k=ct(t,e,w,x,{plotH:o,padding:12,valueScale:1,packing:a,laneOrder:i,lifetimeMode:r,runOrdering:!0,lanePlacement:"stack",groupPadding:y,ribbonLane:h,domain:M}),T=k.slots.map(t=>({occupants:t.occupants.map(t=>({...t})),peak:{...t.peak},...null!=t.group?{group:t.group}:{}})),O=new Set;for(const t of e){const e=k.slotByNode[t.source],n=k.slotByNode[t.target];if(void 0===e||void 0===n)continue;const o=v.get(t.id);e!==n?n<e?(o.sourceSide="top",o.targetSide="bot"):(o.sourceSide="bot",o.targetSide="top"):(O.add(t.id),o.sourceSide="bot",o.targetSide="bot")}for(const e of t){const t=x.outgoing[e.id],n=x.incoming[e.id],o=new Set(t.map(t=>v.get(t.id).sourceSide)),s=new Set(n.map(t=>v.get(t.id).targetSide));if(1===o.size&&n.length>0){const t=[...o][0];for(const e of n)k.slotByNode[e.source]===k.slotByNode[e.target]&&(v.get(e.id).targetSide=t)}if(1===s.size&&t.length>0){const e=[...s][0];for(const n of t)k.slotByNode[n.source]===k.slotByNode[n.target]&&(v.get(n.id).sourceSide=e)}}!function(t,e,n){const o=new Map,s=[];for(const e of t)s.push({time:e.startTime,kind:"out",edge:e}),s.push({time:e.endTime,kind:"in",edge:e});s.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)||f(t.edge.id,e.edge.id));const a=t=>{let e=o.get(t);return e||(e={top:0,bot:0},o.set(t,e)),e},i=(t,e,n)=>{const o="top"===e?"bot":"top",s=Math.min(n,t[e]);t[e]-=s;const a=n-s;a>0&&(t[o]=Math.max(0,t[o]-a))};for(const t of s){const{edge:o}=t;if("in"===t.kind){const t=e.get(o.id)?.targetSide??"bot";a(o.target)[t]+=o.value;continue}const s=a(o.source),r=e.get(o.id);let l=r.sourceSide??"bot";if(n[o.source]===n[o.target]){const t=s.top>=o.value,e=s.bot>=o.value;t!==e?l=t?"top":"bot":t||e||s.top===s.bot||(l=s.top>s.bot?"top":"bot"),r.sourceSide=l,r.targetSide=l}i(s,l,o.value)}}(e,v,k.slotByNode),function(t,e,n,o){for(const s of t){const t=e.incoming[s.id],a=e.outgoing[s.id];if(0===t.length||0===a.length)continue;const i=()=>{const e={inTop:0,inBot:0,outTop:0,outBot:0};for(const o of t)"top"===n.get(o.id).targetSide?e.inTop+=o.value:e.inBot+=o.value;for(const t of a)"top"===n.get(t.id).sourceSide?e.outTop+=t.value:e.outBot+=t.value;return e},r=(t,e)=>{const s=i(),r="top"===t?s.outTop-s.inTop:s.outBot-s.inBot,l="top"===e?s.inTop-s.outTop:s.inBot-s.outBot;if(r<=0||l<=0)return!1;const c=Math.min(r,l),u=a.filter(e=>!o.has(e.id)&&n.get(e.id).sourceSide===t&&e.value<=c).sort((t,e)=>e.value-t.value||f(t.id,e.id));return 0!==u.length&&(n.get(u[0].id).sourceSide=e,!0)};let l=a.length+1;for(;l-- >0&&(r("top","bot")||r("bot","top")););}}(t,x,v,O),w=u();for(const e of t)w[e.id]=F(e,x,v,void 0,m);const N=ct(t,e,w,x,{plotH:o,padding:12,valueScale:1,packing:a,laneOrder:i,lifetimeMode:r,frozenSlots:T,lanePlacement:"stack",groupPadding:y,ribbonLane:h,domain:M}),A=N.effectiveSlotsHeight??N.slots.reduce((t,e)=>t+e.peak.topPeak+e.peak.botPeak,0),I=N.slots.slice(0,-1).reduce((t,e,n)=>t+(null!=e.group&&e.group===N.slots[n+1].group?1:0),0),E=Math.max(1,N.slots.length+1-I),$=Math.min(12,Math.max(0,.35*o-I*y)/E),L=2*$+g(N.slots,$,y).reduce((t,e)=>t+e,0),B=A>0?Math.max(0,(o-L)/A):1,z=Number.isFinite(l)&&l>0?Math.min(B,l):B;let C=ct(t,e,w,x,{plotH:o,padding:$,valueScale:z,packing:a,laneOrder:i,lifetimeMode:r,frozenSlots:T,lanePlacement:c,groupPadding:y,ribbonLane:h,domain:M,stackValueScale:B});const H=Number.isFinite(l)&&l>0&&l+1e-12<B;if("insertion"!==i&&("hug"===c||H)&&C.slots.length>1&&(V(t,e,w,C.laneLifetime,C.slots,C.slotByNode,{plotH:o,padding:$,valueScale:z,groupPadding:y,laneOrder:i,ribbonLane:h,domain:M,lanePlacement:c,mode:"geometry-refine"}),C=ct(t,e,w,x,{plotH:o,padding:$,valueScale:z,packing:a,laneOrder:i,lifetimeMode:r,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(d),lanePlacement:c,groupPadding:y,ribbonLane:h,domain:M,stackValueScale:B})),function(t,e){const n=(t,n)=>{for(const o of t){const t=new Map;for(const s of o){const o=`${("out"===n?e.get(s.id)?.sourceSide:e.get(s.id)?.targetSide)??""}\0${"out"===n?s.startTime:s.endTime}`,a="out"===n?`${s.target}\0${s.endTime}`:`${s.source}\0${s.startTime}`,i=t.get(o);if(null!=i&&i!==a)return!0;t.set(o,a)}}return!1};return n(Object.values(t.outgoing),"out")||n(Object.values(t.incoming),"in")}(x,v)){const n=function(t,e,n,o){const s=new Map;for(const a of t){const t=e[a.source]?.localAttachments.get(a.id),i=e[a.target]?.localAttachments.get(a.id),r=n[a.source],l=n[a.target];if(!(t&&i&&Number.isFinite(r)&&Number.isFinite(l)))continue;const c=P(t,r,o),u=P(i,l,o);s.set(a.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return s}(e,w,C.centerlines,z);w=u();for(const e of t)w[e.id]=F(e,x,v,n,m);C=ct(t,e,w,x,{plotH:o,padding:$,valueScale:z,packing:a,laneOrder:i,lifetimeMode:r,frozenSlots:C.slots,fixedSlotOrder:C.slots.map(d),lanePlacement:c,groupPadding:y,ribbonLane:h,domain:M,stackValueScale:B})}const D=new Map(k.initialSlotOrder.map((t,e)=>[t,e])),Y=[...C.slots].sort((t,e)=>(D.get(d(t))??1/0)-(D.get(d(e))??1/0)||f(d(t),d(e))),q=u();Y.forEach((t,e)=>{for(const n of t.occupants)q[n.id]=e});const U=b(t,e,w,Y,q,{plotH:o,padding:$,valueScale:z,stackValueScale:B,lanePlacement:"stack",groupPadding:y}),W=lt(t,w,Y,q,U.centerlines,z,y),G=S(X(q,e),j(q,e),e,W,Y,q,U.centerlines,C.laneLifetime,z,U.verticalUtilization,h,M);w=lt(t,w,C.slots,C.slotByNode,C.centerlines,z,y);const R=S(X(C.slotByNode,e),j(C.slotByNode,e),e,w,C.slots,C.slotByNode,C.centerlines,C.laneLifetime,z,C.verticalUtilization,h,M);return{nodeData:w,sides:v,valueScale:z,padding:$,compressedPadding:$<12,centerlines:C.centerlines,laneLifetime:C.laneLifetime,slots:C.slots,slotByNode:C.slotByNode,crossingsBefore:"insertion"===i?null:G.crossings,crossingsAfter:"insertion"===i?null:R.crossings,lengthBefore:"insertion"===i?null:G.weightedLength,lengthAfter:"insertion"===i?null:R.weightedLength,layoutQualityBefore:G,layoutQuality:R}}function ft(t,e,n,o,s,a,i,r,l={}){const c=s,u=t=>r?Math.max(r[0],Math.min(r[1],t)):t;let f=a(u(t.time));const d=a(u(n.time)),g=t.value*c,m=n.value*c,p=e+(t.boundaryOffset??0)*c,h=o+(n.boundaryOffset??0)*c,b=t.sideMassBefore*c,M=n.sideMassAfter*c;let y,x,v,w;"top"===t.side?(y=p-b,x=y+g):(x=p+b,y=x-g),"top"===n.side?(v=h-M,w=v+m):(w=h+M,v=w-m);const k=l.sourceRunwayStart,T=l.minRun,S=(y+x)/2,O=(v+w)/2,N=Math.abs(O-S),P=d-f,F="number"==typeof k&&Number.isFinite(k),A="number"==typeof T&&Number.isFinite(T)&&T>0;if(F&&N>1e-9&&P>0&&("auto"===T||A)){const e="source"===i?.85:"target"===i?.15:.5,n=1.5*Math.min(e*e,(1-e)*(1-e)),o="auto"===T?Math.min(144,Math.sqrt(8*N/n)):T;if(o>P){const e=a(u(Math.min(k,t.time)));if(Number.isFinite(e)){const t=Math.min(f,e);f=Math.min(f,Math.max(t,d-o))}}}const I="source"===i?f+.85*(d-f):"target"===i?f+.15*(d-f):(f+d)/2;return{sx:f,sTop:y,sBot:x,tx:d,tTop:v,tBot:w,cp1X:I,cp2X:I}}function dt(t){return Math.max(18,11*t.length*.58)}function gt(t){const e=1.22*dt(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 mt(t,e){const n=t.labelX-dt(t.labelText),o=e.labelX-dt(e.labelText);return n<=e.labelX+3&&o<=t.labelX+3}function pt(t,e,n){const o=t.map(t=>({...t})),s=new Map;for(const t of o){const n=e[t.id];if(null==n)continue;const o=s.get(n)??[];o.push(t),s.set(n,o)}const a=t=>{if(t.length<2)return;const e=t.reduce((t,e)=>t+e.labelY,0)/t.length,o=(t.length-1)/2;t.forEach((t,s)=>{t.labelY=Math.max(8,Math.min(n-8,e+16*(s-o)))})};for(const t of s.values()){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));let e=[],n=-1/0;for(const o of t){const t=o.labelX-dt(o.labelText);e.length>0&&t>n+3&&(a(e),e=[],n=-1/0),e.push(o),n=Math.max(n,o.labelX)}a(e)}return function(t,e){const n=[...t].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX||t.id.localeCompare(e.id));for(let t=0;t<3;t+=1){for(let t=0;t<n.length;t+=1){let e=8;for(let o=0;o<t;o+=1)mt(n[t],n[o])&&(e=Math.max(e,n[o].labelY+16));n[t].labelY=Math.max(n[t].labelY,e)}for(let t=n.length-1;t>=0;t-=1){let o=e-8;for(let e=t+1;e<n.length;e+=1)mt(n[t],n[e])&&(o=Math.min(o,n[e].labelY-16));n[t].labelY=Math.min(n[t].labelY,o)}}}(o,n),o}var ht=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function bt(t){return t.replace(ht,(t,e,n)=>`${n},${e}`)}function Mt(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 yt(t){return{...t,pathD:bt(t.pathD),y0:t.x0,y1:t.x1,x0:0,x1:0}}function xt(t,e){const n=function(t){if(null==t)return()=>{};const e="function"==typeof t?t:e=>e[t];return t=>vt(e(t))}(e??"value"),o=null==t?void 0:"function"==typeof t?t:e=>e[t];return t=>{const e=o?o(t):void 0;return{value:n(t),category:null==e?void 0:String(e)}}}function vt(t){if("number"==typeof t)return Number.isFinite(t)?t:void 0;if("string"==typeof t&&""!==t.trim()){const e=Number(t);return Number.isFinite(e)?e:void 0}}function wt(t,e,n){const o=t.when;return void 0===o||!0===o||!1!==o&&("function"==typeof o?o(e,n):function(t,e,n){const o=null!=t.axis?n[t.axis]:null!=t.field?e[t.field]:n.value;if(void 0!==t.eq&&o!==t.eq)return!1;if(void 0!==t.ne&&o===t.ne)return!1;if(void 0!==t.in&&!t.in.includes(o))return!1;if(void 0===t.gt&&void 0===t.gte&&void 0===t.lt&&void 0===t.lte&&void 0===t.within&&void 0===t.outside)return!0;const s=vt(o);if(void 0===s)return!1;if(void 0!==t.gt&&!(s>t.gt))return!1;if(void 0!==t.gte&&!(s>=t.gte))return!1;if(void 0!==t.lt&&!(s<t.lt))return!1;if(void 0!==t.lte&&!(s<=t.lte))return!1;if(void 0!==t.within){const[e,n]=t.within;if(!(s>=e&&s<=n))return!1}if(void 0!==t.outside){const[e,n]=t.outside;if(!(s<e||s>n))return!1}return!0}(o,e,n))}import{jsx as kt,jsxs as Tt}from"react/jsx-runtime";function St(e){const{nodes:o,edges:a,domain:i,plotW:r,plotH:l,ribbonLane:c,ribbonMinRun:u=0,edgeOpacity:f,colorOf:d,layoutOpts:g,orientation:m="horizontal",showLabels:p=!0,labelPriorityAccessor:h,maxLabels:b,selectionDatum:M="raw",styleRules:y,colorBy:x,valueAccessor:v,usageMode:w="static"}=e,k="vertical"===m?l:r,T="vertical"===m?r:l,S=function(t,e,o,s={}){const a=n(s.usageMode??"static"),i=[],r=new Set;for(const e of t)r.has(e.id)&&i.push({kind:"duplicate-node",id:e.id,severity:a.duplicateIds}),r.add(e.id);const l=new Set,c=Array.isArray(o)&&2===o.length,u=c&&Number.isFinite(o[0])&&Number.isFinite(o[1]),f=u&&o[0]<=o[1];c&&u&&f||i.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[0]<=e.xExtent[1]||i.push({kind:"invalid-node-time",id:e.id}));for(const t of e)l.has(t.id)&&i.push({kind:"duplicate-edge",id:t.id,severity:a.duplicateIds}),l.add(t.id),r.has(t.source)||i.push({kind:"missing-node",id:t.id,endpoint:"source",nodeId:t.source}),r.has(t.target)||i.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))&&i.push({kind:"invalid-system-time",id:t.id,severity:"warn"}),(!Number.isFinite(t.value)||t.value<=0)&&i.push({kind:"invalid-value",id:t.id}),t.endTime<t.startTime&&i.push({kind:"backward-edge",severity:"fatal",id:t.id,source:t.source,target:t.target})):i.push({kind:"invalid-edge-time",id:t.id});return i}(o,a,i,{usageMode:w}),{fatal:F,warnings:A}=function(t){const e=[],n=[];for(const o of t)"fatal"===s(o)?e.push(o):n.push(o);return{fatal:e,warnings:n}}(S),I=function(t,e,o="static"){if("strip"!==n(o).invalidSystemTime)return t;const s=new Set(e.filter(t=>"invalid-system-time"===t.kind).map(t=>t.id));return 0===s.size?t:t.map(t=>{if(!s.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})}(a,S,w),E=t().domain(i).range([0,k]);if(F.length>0)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==p},issues:F,warnings:A,xScale:E};const $=ut(o,I,{plotH:T,...g,ribbonLane:c,domain:i}),{centerlines:L,nodeData:B,valueScale:z}=$,C=xt(x,v),X=[],j=[],H=0===u?new Map:function(t,e,n){const o=new Set(e.map(t=>t.target)),s=new Map(t.map(t=>[t.id,t])),a=new Map;for(const t of e){if(o.has(t.source))continue;const e=a.get(t.source)??[];e.push(t),a.set(t.source,e)}const i=new Map;for(const e of t){if(!e.group)continue;const t=i.get(e.group)??[];t.push(e),i.set(e.group,t)}const r=new Set;for(const[t,e]of i){const n=e.flatMap(t=>a.get(t.id)??[]),s=new Set(n.map(t=>t.startTime));n.length>0&&1===s.size&&e.every(t=>{const e=t.xExtent?.[0],s=n[0].startTime;return!o.has(t.id)&&(a.get(t.id)?.length??0)>0&&Number.isFinite(e)&&e<s})&&r.add(t)}const l=new Map;for(const[t,e]of a){const o=s.get(t);if(o?.group&&!r.has(o.group))continue;const a=o?.xExtent?.[0],i=[...e].sort((t,e)=>t.startTime-e.startTime||t.id.localeCompare(e.id)),c=i[0]?.startTime-1;let u=null;for(let t=0;t<i.length;){const e=i[t].startTime;let o=t+1;for(;o<i.length&&i[o].startTime===e;)o++;for(let e=t;e<o;e++){const t=i[e],o=Number.isFinite(a)&&a<t.startTime,s=Number.isFinite(t.systemInTime)&&t.systemInTime<t.startTime;if(!o&&!s)continue;let r=n[0];o&&(r=Math.max(r,a)),s&&(r=Math.max(r,t.systemInTime)),!o&&s&&Number.isFinite(c)&&(r=Math.max(r,c)),null!=u&&(r=Math.max(r,u)),r<t.startTime&&l.set(t.id,r)}u=e,t=o}}for(const[t,e]of i){if(!r.has(t))continue;const n=e.flatMap(t=>a.get(t.id)??[]);if(!n.every(t=>l.has(t.id))){for(const t of n)l.delete(t.id);continue}const o=Math.max(...n.map(t=>l.get(t.id)));for(const t of n)l.set(t.id,o)}return l}(o,I,i),D=new Map(o.filter(t=>t.group).map(t=>[t.id,t.group])),Y=new Map;for(const t of I){const e=B[t.source]?.localAttachments.get(t.id),n=B[t.target]?.localAttachments.get(t.id);e&&n&&Y.set(t.id,ft(e,L[t.source],n,L[t.target],z,E,c,i,{minRun:u,sourceRunwayStart:H.get(t.id)}))}const q=function(t,e,n,o,s,a){const i=new Map(e),r=new Map;for(const e of t){const t=a?.get(e.source),n=null==t?`node:${e.source}`:`group:${t}`,o=r.get(n)??new Map,s=o.get(e.startTime)??[];s.push(e),o.set(e.startTime,s),r.set(n,o)}for(const t of r.values())for(const[a,r]of t){if(!r.some(t=>n.has(t.id)))continue;const t=r.map(t=>e.get(t.id));if(t.some(t=>null==t))continue;const l=o(a),c=Math.min(...t.map(t=>t.sx));if(!(c<l-1e-9))continue;const u=Math.max(...r.map(t=>{const e=n.get(t.id);return null==e?l:Math.min(l,o(e))})),f=Math.min(l,Math.max(c,u));for(const t of r){const n=e.get(t.id),o="source"===s?.85:"target"===s?.15:.5,a=f+(n.tx-f)*o;i.set(t.id,{...n,sx:f,cp1X:a,cp2X:a})}}return i}(I,Y,H,E,c,D),V=function(t,e,n,o,s){const a=new Map;for(const i of t){if(!n.has(i.id))continue;const t=e.get(i.id);if(!(t&&t.sx<o(i.startTime)-1e-9))continue;const r=s(t.sx);Number.isFinite(r)&&r<i.startTime&&a.set(i.id,r)}return a}(I,q,H,E,t=>i[0]+t/k*(i[1]-i[0])),U=function(t,e,n){const o=new Map,s=new Map;for(const[t,e]of n??[]){const n=s.get(e)??[];n.push(t),s.set(e,n)}for(const a of t){const t=e.get(a.id);if(!(null!=t&&Number.isFinite(t)&&t<a.startTime))continue;const i=n?.get(a.source),r=null==i?[a.source]:s.get(i)??[a.source];for(const e of r){const n=o.get(e)??new Map,s=n.get(a.startTime);n.set(a.startTime,null==s?t:Math.min(s,t)),o.set(e,n)}}return o}(I,V,D);o.forEach((t,e)=>{const n=B[t.id];if(!n||0===n.samples.length)return;const o=(s=n.samples,(a=U.get(t.id))&&0!==a.size?s.map(t=>{const e=a.get(t.t);return null==e?t:{...t,t:e}}):s);var s,a;const r=function(t,e,n,o,s){if(0===t.length)return null;const a=N(t,s),i=t=>e+(a[t].boundaryOffset??0)*n,r=t=>i(t)-a[t].topMass*n,l=t=>i(t)+a[t].botMass*n;let c=`M${o(a[0].t)},${r(0)}`;for(let t=1;t<a.length;t++)c+=` L${o(a[t].t)},${r(t)}`;c+=` L${o(a[a.length-1].t)},${l(a.length-1)}`;for(let t=a.length-2;t>=0;t--)c+=` L${o(a[t].t)},${l(t)}`;return c+" Z"}(o,L[t.id],z,E,i);if(!r)return;const l=N(o,i),c=l.find(t=>t.topMass+t.botMass>0)||l[0],u=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*z/2,f=L[t.id]+u;let g,p,h=d(t.id,e),b=h,M=.5;const x=t.__raw??t;if(y&&y.length>0){const t=function(t,e,n){if(!e||0===e.length)return{};let o={};for(const s of e){if(!wt(s,t,n))continue;const e="function"==typeof s.style?s.style(t,n):s.style;e&&(o={...o,...e})}return o}(x,y,C(x));"string"==typeof t.fill?h=t.fill:null!=t.fill&&("object"==typeof(v=t.fill)&&null!==v&&"hatch"===v.type)&&(p=t.fill,h=t.fill.background&&"transparent"!==t.fill.background?t.fill.background:h),"string"==typeof t.stroke&&(b=t.stroke),"number"==typeof t.strokeWidth&&(M=t.strokeWidth),"number"==typeof t.fillOpacity&&(g=t.fillOpacity),"number"==typeof t.opacity&&null==g&&(g=t.opacity)}var v;const w=function(t,e,n,o,s,a){const i=n.nodeData[t];if(!i||0===i.samples.length)return[];const r=n.valueScale,l=n.centerlines[t],c=N(i.samples,s),u=c.find(t=>t.topMass+t.botMass>0)||c[0],f=[...c].reverse().find(t=>t.topMass+t.botMass>0)||c[c.length-1],d=o(u.t),g=o(f.t),m=t=>o(O(t,s)),p=[],h=(t,e,n,o)=>`M${t},${e} L${n},${e} L${n},${o} L${t},${o} Z`;for(const n of e){if(n.source===t&&null!=n.systemInTime&&Number.isFinite(n.systemInTime)){const t=i.localAttachments.get(n.id),e=a?.get(n.id)??n.startTime;if(t&&"out"===t.kind&&n.systemInTime<e){const o=m(n.systemInTime),a=m(e),i=null!=s&&n.systemInTime<s[0],c=i?o:o-20,u=i?Math.min(a,o+20):o,f=Math.max(d,c);if(a>f){const[e,n]=P(t,l,r);p.push({pathD:h(f,e,a,n),x0:c,x1:u,from:0,to:1})}}}if(n.target===t&&null!=n.systemOutTime&&Number.isFinite(n.systemOutTime)){const t=i.localAttachments.get(n.id);if(t&&"in"===t.kind&&n.systemOutTime>n.endTime){const e=m(n.systemOutTime),o=m(n.endTime),s=e+20,a=Math.min(g,s);if(a>o){const[n,i]=P(t,l,r);p.push({pathD:h(o,n,a,i),x0:e,x1:s,from:1,to:0})}}}}return p}(t.id,I,$,E,i,V);X.push({id:t.id,pathD:r,fill:h,stroke:b,strokeWidth:M,...null!=g&&{fillOpacity:g},...p&&{hatchFill:p},...w.length>0&&{gradientStubs:w},rawDatum:x,labelX:E("vertical"===m&&t.xExtent?t.xExtent[0]:c.t)-4,labelY:f,labelText:t.label??t.id})});const W=new Map;o.forEach((t,e)=>W.set(t.id,e)),I.forEach(t=>{const e=q.get(t.id);if(!e)return;const n=W.get(t.source)??0,o=d(t.source,n),{pathD:s,bezier:a}=function(t){const{sx:e,sTop:n,sBot:o,tx:s,tTop:a,tBot:i,cp1X:r,cp2X:l}=t,c=(n+o)/2,u=(a+i)/2;return{pathD:[`M${e},${n}`,`C${r},${n} ${l},${a} ${s},${a}`,`L${s},${i}`,`C${l},${i} ${r},${o} ${e},${o}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:e,y:c},{x:r,y:c},{x:l,y:u},{x:s,y:u}],halfWidth:(o-n)/2}}}(e),i=t.__raw??t,r="function"==typeof f?Number(f(i)):f,l=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.35;j.push({id:t.id,pathD:s,fill:o,opacity:l,rawDatum:i,bezier:a})});const G=pt(X,$.slotByNode,T).map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:bt(t.pathD),gradientStubs:t.gradientStubs?.map(yt),labelX:t.labelY,labelY:t.labelX,labelAnchor:"middle",labelBaseline:"auto"}}(t,m)),R="vertical"===m?function(t,e,n){const o=t.map(t=>({...t}));for(const t of o){const n=1.22*dt(t.labelText)+4;t.labelX=n>=e-4?e/2:Math.max(n/2+2,Math.min(e-n/2-2,t.labelX))}const s=[],a=[...o].sort((t,e)=>t.labelY-e.labelY||t.labelX-e.labelX);for(const t of a){const e=s[s.length-1];!e||Math.abs(e[0].labelY-t.labelY)>14?s.push([t]):e.push(t)}for(const t of s){t.sort((t,e)=>t.labelX-e.labelX||t.id.localeCompare(e.id));const e=[],o=new Map;for(const n of t){const[t,s]=gt(n);let a=e.findIndex(e=>t>e+8);-1===a&&(a=e.length),e[a]=s,o.set(n,a)}const s=t.reduce((t,e)=>t+e.labelY,0)/t.length,a=s<14*e.length+8;for(const e of t){const t=o.get(e)??0;e.labelY=a?Math.min(n-8,12+14*t):Math.max(8,s-14*t)}}return o}(G,r,l):G,_=new Map;if(null!=h)for(const t of o){const e=t.__raw??t,n="function"==typeof h?h(e):Number(e[h]);Number.isFinite(n)&&_.set(t.id,n)}const Z=function(t,e,n,o,s={}){if(!1===o)return t.map(t=>({...t,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===o)return t.map(t=>({...t,labelDeferred:!1,labelFullText:void 0}));const a=Math.max(1,e*n);let i=Math.max(4,Math.min(t.length,Math.floor(a/14e3)));Number.isFinite(s.maxLabels)&&s.maxLabels>=0&&(i=Math.min(i,Math.floor(s.maxLabels)));const r=t.map((t,e)=>{const n=s.priorityById?.get(t.id),o=Math.abs(t.labelY);return{band:t,index:e,score:null!=n&&Number.isFinite(n)?1e6*n+dt(t.labelText):dt(t.labelText)+.01*o}}).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)),l=new Set(r.slice(0,i).map(t=>t.band.id));return t.map(t=>l.has(t.id)||0===t.labelText.trim().length?{...t,labelDeferred:!1,labelFullText:void 0}:{...t,labelFullText:t.labelText,labelText:"",labelDeferred:!0})}(R,r,l,p,{..._.size>0&&{priorityById:_},...null!=b&&{maxLabels:b}});return{layout:$,layoutConfig:{bands:Z,ribbons:j.map(t=>function(t,e){return"horizontal"===e?t:{...t,pathD:bt(t.pathD),bezier:Mt(t.bezier)}}(t,m)),showLabels:!1!==p,selectionDatum:M},issues:[],warnings:A,xScale:E}}self.onmessage=t=>{const e=t.data,n=e?.requestId,o=e?.request??e;try{const t=o.colorById??{},e=o.fallbackPalette??["#475569"],i=(n,o)=>t[n]??e[o%e.length]??"#475569",r=St({...o.input,colorOf:i});self.postMessage({requestId:n,layout:(a=r.layout,a?{...a,sides:a.sides instanceof Map?[...a.sides.entries()]:a.sides}:null),layoutConfig:(s=r.layoutConfig,{bands:(s.bands??[]).map(({rawDatum:t,...e})=>e),ribbons:(s.ribbons??[]).map(({rawDatum:t,...e})=>e),showLabels:s.showLabels}),issues:r.issues,warnings:r.warnings,domain:o.input.domain,timelineExtent:"vertical"===o.input.orientation?o.input.plotH:o.input.plotW})}catch(t){self.postMessage({requestId:n,error:{message:t instanceof Error?t.message:String(t),name:t instanceof Error?t.name:"Error",stack:t instanceof Error?t.stack:void 0}})}var s,a};