semiotic 3.12.0 → 3.12.1

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 (256) hide show
  1. package/README.md +50 -46
  2. package/ai/artifact-surface-inventory.json +1 -1
  3. package/ai/behaviorContracts.cjs +1 -1
  4. package/ai/dist/diagnose-operation.js +3 -3
  5. package/ai/dist/mcp-server.js +1 -1
  6. package/ai/reference.md +15 -3
  7. package/ai/schema.json +908 -96
  8. package/ai/surface-manifest.json +1 -1
  9. package/ai/task-packets/compare-category-totals.json +5 -5
  10. package/ai/task-packets/compare-category-totals.md +2 -2
  11. package/ai/task-packets/correct-published-chart.json +5 -5
  12. package/ai/task-packets/correct-published-chart.md +2 -2
  13. package/ai/task-packets/index.json +6 -6
  14. package/ai/task-packets/update-live-chart.json +5 -5
  15. package/ai/task-packets/update-live-chart.md +2 -2
  16. package/dist/c-27DCB5T6.min.js +7 -7
  17. package/dist/c-2CKIGFD2.min.js +1 -1
  18. package/dist/c-3FATLOH4.min.js +1 -0
  19. package/dist/{c-STVM6CBI.min.js → c-4SCJKAWZ.min.js} +200 -200
  20. package/dist/c-5FUOKMH6.min.js +7 -0
  21. package/dist/c-AAIPWVQ5.min.js +6 -6
  22. package/dist/{c-2RG4WOVX.min.js → c-ALLF3Y77.min.js} +1 -1
  23. package/dist/{c-QMKQVCCZ.min.js → c-C5GXUHUO.min.js} +6 -6
  24. package/dist/c-C67QDKTU.min.js +34 -0
  25. package/dist/c-F76M77YC.min.js +1 -0
  26. package/dist/c-FEVXPKQH.min.js +1 -1
  27. package/dist/c-G42WVQO2.min.js +1 -0
  28. package/dist/c-G5A3YWTN.min.js +66 -0
  29. package/dist/c-H4HVKBU3.min.js +1 -0
  30. package/dist/c-HU3ASFKT.min.js +1 -0
  31. package/dist/c-I4FYCVJB.min.js +391 -0
  32. package/dist/{c-5L7JGWQW.min.js → c-IATPZOL7.min.js} +28 -28
  33. package/dist/c-IE5EBBP6.min.js +110 -0
  34. package/dist/c-IGONIKZL.min.js +1 -0
  35. package/dist/c-IKPM53JH.min.js +1 -0
  36. package/dist/c-IU4QZ7Y5.min.js +1 -1
  37. package/dist/{c-2ACLVPKF.min.js → c-K5VE57OI.min.js} +1 -1
  38. package/dist/c-KWJIBJ4R.min.js +1 -0
  39. package/dist/c-LIMFU6RD.min.js +1 -0
  40. package/dist/c-M4T43G76.min.js +1 -0
  41. package/dist/c-M7QUZZCE.min.js +1 -1
  42. package/dist/c-NVSINXE5.min.js +1 -0
  43. package/dist/{c-FAF6EV4E.min.js → c-NWRYV6ZF.min.js} +1 -1
  44. package/dist/c-O5GU2R5W.min.js +1 -0
  45. package/dist/c-OC7GNXGZ.min.js +1 -0
  46. package/dist/c-OV5F3DQP.min.js +1 -0
  47. package/dist/{c-5TAXHW7I.min.js → c-PJ5CAYAW.min.js} +1 -1
  48. package/dist/c-Q5LZRQGD.min.js +1 -0
  49. package/dist/c-QP3PXK3N.min.js +1 -0
  50. package/dist/c-SGZ7ZD2I.min.js +51 -0
  51. package/dist/c-SSKV5JPW.min.js +1 -1
  52. package/dist/c-THWTHWXU.min.js +37 -0
  53. package/dist/c-TRMNDRC4.min.js +41 -0
  54. package/dist/c-UP656CST.min.js +1 -1
  55. package/dist/c-USYOK5OX.min.js +1 -0
  56. package/dist/c-VI753KBO.min.js +1 -0
  57. package/dist/{c-TT4CTEBR.min.js → c-VLAAAFST.min.js} +1 -1
  58. package/dist/c-VSOQPII4.min.js +5 -5
  59. package/dist/c-WGDM4ZRP.min.js +26 -0
  60. package/dist/c-XCV7VUU3.min.js +87 -0
  61. package/dist/c-XGDZPYBI.min.js +1 -0
  62. package/dist/c-XI6CLZII.min.js +1 -0
  63. package/dist/{c-L4Q2YMXO.min.js → c-XLC7PKM7.min.js} +1 -1
  64. package/dist/{c-3YAGKCPU.min.js → c-YEB6Z35F.min.js} +1 -1
  65. package/dist/c-YWZBFG63.min.js +1 -0
  66. package/dist/c-ZMYO3NZU.min.js +2 -0
  67. package/dist/c-ZO36H5VH.min.js +48 -0
  68. package/dist/components/LinkedCharts.d.ts +6 -1
  69. package/dist/components/Tooltip/Tooltip.d.ts +11 -1
  70. package/dist/components/Tooltip/tooltipChrome.d.ts +8 -2
  71. package/dist/components/bundling/semioticVite.d.ts +24 -0
  72. package/dist/components/charts/physics/cruciblePhysics.d.ts +2 -2
  73. package/dist/components/charts/physics/gauntletPhysics.d.ts +2 -6
  74. package/dist/components/charts/physics/physicsHocUtils.d.ts +8 -1
  75. package/dist/components/charts/realtime/RealtimeHistogram.d.ts +2 -0
  76. package/dist/components/charts/shared/chartSize.d.ts +58 -0
  77. package/dist/components/charts/shared/chartSizeDefaults.d.ts +189 -0
  78. package/dist/components/charts/shared/chartSizeDefaultsAtlas.d.ts +9 -0
  79. package/dist/components/charts/shared/chartSizeDefaultsNetwork.d.ts +29 -0
  80. package/dist/components/charts/shared/chartSizeDefaultsOrdinal.d.ts +13 -0
  81. package/dist/components/charts/shared/chartSizeDefaultsPhysics.d.ts +41 -0
  82. package/dist/components/charts/shared/chartSizeDefaultsValue.d.ts +19 -0
  83. package/dist/components/charts/shared/chartSizeDefaultsXY.d.ts +10 -0
  84. package/dist/components/charts/shared/networkPerspectiveWireSchema.d.ts +3 -0
  85. package/dist/components/charts/shared/useChartSetup.d.ts +3 -0
  86. package/dist/components/charts/shared/useCustomChartSetup.d.ts +4 -0
  87. package/dist/components/charts/shared/useNetworkChartSetup.d.ts +2 -0
  88. package/dist/components/charts/shared/withChartWrapper.d.ts +6 -2
  89. package/dist/components/charts/value/BigNumber.d.ts +0 -8
  90. package/dist/components/charts/xy/minimapLayout.d.ts +10 -0
  91. package/dist/components/realtime/BinAccumulator.d.ts +5 -2
  92. package/dist/components/recipes/atlas/dependencyForestChartProps.d.ts +4 -4
  93. package/dist/components/recipes/atlas/flowCircuitChartProps.d.ts +177 -1
  94. package/dist/components/recipes/atlas/flowCircuitLayout.d.ts +3 -0
  95. package/dist/components/recipes/atlas/motifBraidChartProps.d.ts +2 -0
  96. package/dist/components/recipes/atlas/resolution/BoundaryLoomChart.d.ts +3 -0
  97. package/dist/components/recipes/atlas/resolution/ComponentCutaway.d.ts +16 -0
  98. package/dist/components/recipes/atlas/resolution/ResolutionAtlasChart.d.ts +3 -0
  99. package/dist/components/recipes/atlas/resolution/ResolutionGlyphs.d.ts +15 -0
  100. package/dist/components/recipes/atlas/resolution/ResolutionReader.d.ts +5 -0
  101. package/dist/components/recipes/atlas/resolution/appearance.d.ts +58 -0
  102. package/dist/components/recipes/atlas/resolution/boundaryLoomLayout.d.ts +4 -0
  103. package/dist/components/recipes/atlas/resolution/chartProps.d.ts +75 -0
  104. package/dist/components/recipes/atlas/resolution/componentCutawayLayout.d.ts +12 -0
  105. package/dist/components/recipes/atlas/resolution/cutawayContext.d.ts +23 -0
  106. package/dist/components/recipes/atlas/resolution/cutawayGraph.d.ts +4 -0
  107. package/dist/components/recipes/atlas/resolution/cycles.d.ts +7 -0
  108. package/dist/components/recipes/atlas/resolution/evidence.d.ts +43 -0
  109. package/dist/components/recipes/atlas/resolution/glyphs.d.ts +40 -0
  110. package/dist/components/recipes/atlas/resolution/identity.d.ts +4 -0
  111. package/dist/components/recipes/atlas/resolution/indexGraph.d.ts +32 -0
  112. package/dist/components/recipes/atlas/resolution/ownership.d.ts +25 -0
  113. package/dist/components/recipes/atlas/resolution/plan.d.ts +12 -0
  114. package/dist/components/recipes/atlas/resolution/ports.d.ts +44 -0
  115. package/dist/components/recipes/atlas/resolution/prepare.d.ts +4 -0
  116. package/dist/components/recipes/atlas/resolution/project.d.ts +70 -0
  117. package/dist/components/recipes/atlas/resolution/queries.d.ts +23 -0
  118. package/dist/components/recipes/atlas/resolution/resolutionAtlasLayout.d.ts +9 -0
  119. package/dist/components/recipes/atlas/resolution/rules.d.ts +14 -0
  120. package/dist/components/recipes/atlas/resolution/scene.d.ts +52 -0
  121. package/dist/components/recipes/atlas/resolution/selection.d.ts +3 -0
  122. package/dist/components/recipes/atlas/resolution/sets.d.ts +10 -0
  123. package/dist/components/recipes/atlas/resolution/types.d.ts +401 -0
  124. package/dist/components/recipes/atlas/resolution/validate.d.ts +4 -0
  125. package/dist/components/recipes/atlas/resolution/witnesses.d.ts +18 -0
  126. package/dist/components/recipes/atlas/resolution/worker.d.ts +34 -0
  127. package/dist/components/recipes/lineageDag.d.ts +4 -0
  128. package/dist/components/recipes/recipeUtils.d.ts +2 -0
  129. package/dist/components/recipes/transitDiagram.d.ts +2 -61
  130. package/dist/components/recipes/transitDiagramTypes.d.ts +65 -0
  131. package/dist/components/semiotic-ai.d.ts +2 -0
  132. package/dist/components/semiotic-experimental-network-resolution-react.d.ts +12 -0
  133. package/dist/components/semiotic-experimental-network-resolution.d.ts +13 -0
  134. package/dist/components/semiotic-geo.d.ts +1 -1
  135. package/dist/components/semiotic-network-perspective-core.d.ts +6 -0
  136. package/dist/components/semiotic-network.d.ts +1 -1
  137. package/dist/components/semiotic-ordinal.d.ts +1 -1
  138. package/dist/components/semiotic-physics.d.ts +1 -1
  139. package/dist/components/semiotic-realtime-core.d.ts +1 -1
  140. package/dist/components/semiotic-realtime-react.d.ts +2 -0
  141. package/dist/components/semiotic-utils-core.d.ts +3 -1
  142. package/dist/components/semiotic-vite.d.ts +2 -0
  143. package/dist/components/semiotic-xy.d.ts +3 -1
  144. package/dist/components/semiotic.d.ts +3 -1
  145. package/dist/components/server/renderToStaticSVG.d.ts +2 -1
  146. package/dist/components/server/serverChartConfigShared.d.ts +2 -0
  147. package/dist/components/store/LinkedCrosshairStore.d.ts +43 -11
  148. package/dist/components/store/themeCore.d.ts +2 -0
  149. package/dist/components/stream/frameKeyboardNavigation.d.ts +3 -1
  150. package/dist/components/stream/hoverUtils.d.ts +5 -0
  151. package/dist/components/stream/networkCustomLayout.d.ts +3 -0
  152. package/dist/components/stream/networkPerspective.d.ts +2 -0
  153. package/dist/components/stream/networkPerspectiveFit.d.ts +12 -1
  154. package/dist/components/stream/networkPerspectiveSolid.d.ts +1 -1
  155. package/dist/components/stream/networkSceneTypes.d.ts +4 -0
  156. package/dist/components/stream/networkTypes.d.ts +2 -0
  157. package/dist/components/stream/pipelineConfig.d.ts +2 -0
  158. package/dist/components/stream/pipelineDomainResolution.d.ts +4 -1
  159. package/dist/components/stream/types.d.ts +2 -0
  160. package/dist/components/stream/useFrame.d.ts +2 -0
  161. package/dist/components/stream/xySceneBuilders/types.d.ts +2 -0
  162. package/dist/controls.module.min.js +31 -31
  163. package/dist/geo.min.js +150 -150
  164. package/dist/geo.module.min.js +31 -31
  165. package/dist/network.module.min.js +1 -1
  166. package/dist/ordinal.module.min.js +1 -1
  167. package/dist/physics.module.min.js +1 -1
  168. package/dist/rough.module.min.js +1 -1
  169. package/dist/semiotic-ai-core.min.js +1 -1
  170. package/dist/semiotic-ai-core.module.min.js +1 -1
  171. package/dist/semiotic-ai.d.ts +2 -0
  172. package/dist/semiotic-ai.module.min.js +13 -13
  173. package/dist/semiotic-artifact-react.module.min.js +4 -4
  174. package/dist/semiotic-artifact.min.js +1 -1
  175. package/dist/semiotic-artifact.module.min.js +1 -1
  176. package/dist/semiotic-atlas-selection.module.min.js +1 -1
  177. package/dist/semiotic-atlas.module.min.js +10 -12
  178. package/dist/semiotic-client-cjs-shared.min.js +1078 -925
  179. package/dist/semiotic-client-glyph.module.min.js +2 -2
  180. package/dist/semiotic-client-shared.module.min.js +1 -1
  181. package/dist/semiotic-experimental-auxiliary.module.min.js +8 -9
  182. package/dist/semiotic-experimental-network-resolution-react.d.ts +12 -0
  183. package/dist/semiotic-experimental-network-resolution-react.min.js +2 -0
  184. package/dist/semiotic-experimental-network-resolution-react.module.min.js +89 -0
  185. package/dist/semiotic-experimental-network-resolution.d.ts +13 -0
  186. package/dist/semiotic-experimental-network-resolution.min.js +2 -0
  187. package/dist/semiotic-experimental-network-resolution.module.min.js +2 -0
  188. package/dist/semiotic-experimental-node-auxiliary.module.min.js +9 -10
  189. package/dist/semiotic-geo.d.ts +1 -1
  190. package/dist/semiotic-line.module.min.js +1 -1
  191. package/dist/semiotic-network-perspective-core.d.ts +6 -0
  192. package/dist/semiotic-network-perspective-core.min.js +1 -0
  193. package/dist/semiotic-network-perspective-core.module.min.js +1 -0
  194. package/dist/semiotic-network-perspective.module.min.js +1 -1
  195. package/dist/semiotic-network-placement.min.js +4 -0
  196. package/dist/semiotic-network-placement.module.min.js +4 -0
  197. package/dist/semiotic-network-zoom.module.min.js +1 -1
  198. package/dist/semiotic-network.d.ts +1 -1
  199. package/dist/semiotic-ordinal.d.ts +1 -1
  200. package/dist/semiotic-physics.d.ts +1 -1
  201. package/dist/semiotic-realtime-core.d.ts +1 -1
  202. package/dist/semiotic-realtime-core.module.min.js +1 -1
  203. package/dist/semiotic-realtime-react.d.ts +2 -0
  204. package/dist/semiotic-realtime-react.module.min.js +1 -1
  205. package/dist/semiotic-recipes-core-cjs-base.min.js +101 -106
  206. package/dist/semiotic-recipes-core.module.min.js +75 -76
  207. package/dist/semiotic-server-edge-node.module.min.js +391 -392
  208. package/dist/semiotic-server-edge.min.js +387 -388
  209. package/dist/semiotic-server-edge.module.min.js +371 -371
  210. package/dist/semiotic-server-node.min.js +387 -388
  211. package/dist/semiotic-server-node.module.min.js +1 -1
  212. package/dist/semiotic-utils-core.d.ts +3 -1
  213. package/dist/semiotic-utils-core.min.js +12 -11
  214. package/dist/semiotic-utils-core.module.min.js +12 -11
  215. package/dist/semiotic-value.module.min.js +4 -4
  216. package/dist/semiotic-vite.d.ts +2 -0
  217. package/dist/semiotic-vite.min.js +1 -0
  218. package/dist/semiotic-vite.module.min.js +1 -0
  219. package/dist/semiotic-xy.d.ts +3 -1
  220. package/dist/semiotic.d.ts +3 -1
  221. package/dist/semiotic.module.min.js +12 -12
  222. package/dist/server.min.js +387 -388
  223. package/dist/server.module.min.js +1 -1
  224. package/dist/xy.module.min.js +1 -1
  225. package/package.json +42 -13
  226. package/dist/c-2AB65V3L.min.js +0 -1
  227. package/dist/c-2U5JMOPN.min.js +0 -88
  228. package/dist/c-3DCTIRW4.min.js +0 -1
  229. package/dist/c-3OKFRTYM.min.js +0 -1
  230. package/dist/c-3VZHOPFW.min.js +0 -1
  231. package/dist/c-4ZSQIBC7.min.js +0 -1
  232. package/dist/c-5M4RUS7V.min.js +0 -34
  233. package/dist/c-6O5WWP7F.min.js +0 -1
  234. package/dist/c-73TOIYIW.min.js +0 -48
  235. package/dist/c-AE4M7BWH.min.js +0 -1
  236. package/dist/c-AEIK2NFW.min.js +0 -30
  237. package/dist/c-AFQSEIZ4.min.js +0 -4
  238. package/dist/c-BBX7DVVB.min.js +0 -51
  239. package/dist/c-CNYFCSG4.min.js +0 -5
  240. package/dist/c-E6QH2WYE.min.js +0 -1
  241. package/dist/c-GOMQWQJR.min.js +0 -1
  242. package/dist/c-GTYG4PDT.min.js +0 -1
  243. package/dist/c-H23GIKTK.min.js +0 -1
  244. package/dist/c-HQLUUSRJ.min.js +0 -1
  245. package/dist/c-HXUOFDSD.min.js +0 -64
  246. package/dist/c-L3LKYOLK.min.js +0 -1
  247. package/dist/c-MIKDFGKH.min.js +0 -1
  248. package/dist/c-OYSPTIAG.min.js +0 -1
  249. package/dist/c-PWPJNYQP.min.js +0 -1
  250. package/dist/c-QZ5SWKHC.min.js +0 -392
  251. package/dist/c-RXJH4IRX.min.js +0 -41
  252. package/dist/c-SN2D6QMH.min.js +0 -1
  253. package/dist/c-U5YGK6HL.min.js +0 -1
  254. package/dist/c-VIN5ASK2.min.js +0 -37
  255. package/dist/c-XZ3GASUJ.min.js +0 -1
  256. package/dist/c-ZLZZTH4I.min.js +0 -118
@@ -1,392 +0,0 @@
1
- import{a as e,b as t,c as i,d as r,k as n}from"./c-QIVKWHDL.min.js";import{a as o,b as a}from"./c-H23GIKTK.min.js";import{a as s,b as l,c,d as u,e as d,f as h,g as f,h as p,s as g,u as m}from"./c-U5YGK6HL.min.js";var y=["#0072B2","#E69F00","#009E73","#CC79A7","#56B4E9","#D55E00","#F0E442","#000000"],x={mode:"light",colors:{primary:"#00a2ce",secondary:"#6c757d",categorical:["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],sequential:"blues",diverging:"RdBu",background:"transparent",surface:"#ffffff",text:"#333",textSecondary:"#666",grid:"#e0e0e0",border:"#ccc",selection:"#00a2ce",selectionOpacity:.15,success:"#2ca02c",danger:"#d62728",warning:"#f0ad4e",error:"#b4181b",info:"#00a2ce"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},b={mode:"dark",colors:{primary:"#4fc3f7",secondary:"#90a4ae",categorical:["#4fc3f7","#ffb74d","#81c784","#ef5350","#ba68c8","#a1887f","#f06292","#90a4ae","#dce775","#4dd0e1"],sequential:"blues",diverging:"RdBu",background:"#1a1a2e",surface:"#252540",text:"#e0e0e0",textSecondary:"#aaa",grid:"#333",border:"#555",selection:"#4fc3f7",selectionOpacity:.15,success:"#81c784",danger:"#ef5350",warning:"#ffb74d",error:"#d84848",info:"#4fc3f7"},typography:{fontFamily:"sans-serif",titleSize:16,labelSize:12,tickSize:12}},v={mode:"light",colors:{primary:"#0000cc",secondary:"#333333",categorical:y,sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#000000",textSecondary:"#333333",grid:"#999999",border:"#000000",focus:"#0000cc",selection:"#0000cc",selectionOpacity:.1,success:"#006400",danger:"#cc0000",warning:"#b15a00",error:"#8b0000",info:"#0000cc"},typography:{fontFamily:"system-ui, sans-serif",titleSize:18,labelSize:14,tickSize:12},tooltip:{background:"#000000",text:"#ffffff",borderRadius:"4px",fontSize:"14px",shadow:"0 2px 8px rgba(0, 0, 0, 0.3)"},borderRadius:"4px"};function w(e){if(!e?.colors)return;let t=e.colors;return{primary:t.primary,secondary:t.secondary||t.primary,surface:t.surface||t.background,success:t.success,danger:t.danger,warning:t.warning,error:t.error,info:t.info,text:t.text,textSecondary:t.textSecondary,border:t.border,grid:t.grid}}function k(e){if(!e.accessibility)return e;let t=e;if(e.accessibility.colorBlindSafe&&(t={...t,colors:{...t.colors,categorical:y}}),e.accessibility.highContrast){let e="dark"===t.mode;t={...t,colors:{...t.colors,text:e?"#ffffff":"#000000",textSecondary:e?"#cccccc":"#333333",grid:e?"#666666":"#999999",border:e?"#888888":"#000000"}}}return t}var S={light:x,dark:b,"high-contrast":v,pastels:{mode:"light",colors:{primary:"#c9a0dc",secondary:"#b8a8c8",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#fdf6f0",surface:"#fff5ee",text:"#4a3728",textSecondary:"#7a644a",grid:"#e8d5c4",border:"#e8d5c4",focus:"#8a5fae",annotation:"#8a5fae",success:"#9ad4a3",danger:"#e8869a",warning:"#f0c888",error:"#c86070",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#fff5ee",text:"#4a3728",borderRadius:"8px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"10px"},"pastels-dark":{mode:"dark",colors:{primary:"#c9a0dc",secondary:"#a899c0",categorical:["#f0a0c0","#88d4ab","#b0a0e8","#f0c888"],sequential:"purples",background:"#1a1525",surface:"#251e35",text:"#e8ddf0",textSecondary:"#a899c0",grid:"#3d3455",border:"#3d3455",focus:"#c9a0dc",annotation:"#c9a0dc",success:"#88d4ab",danger:"#f0a0c0",warning:"#f0c888",error:"#e87690",info:"#9cb8e0"},typography:{fontFamily:"Inter, system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#251e35",text:"#e8ddf0",borderRadius:"8px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"10px"},"bi-tool":{mode:"light",colors:{primary:"#2563eb",secondary:"#6b7280",categorical:["#2563eb","#0d9488","#ea580c","#6b7280"],sequential:"blues",background:"#f5f6f8",surface:"#ffffff",text:"#2c3e50",textSecondary:"#64717f",grid:"#d8dce3",border:"#d8dce3",focus:"#2563eb",annotation:"#2563eb",success:"#10b981",danger:"#ef4444",warning:"#f59e0b",error:"#dc2626",info:"#2563eb"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2c3e50",borderRadius:"6px",shadow:"0 2px 8px rgba(0, 0, 0, 0.12)"},borderRadius:"8px"},"bi-tool-dark":{mode:"dark",colors:{primary:"#3b82f6",secondary:"#9ca3af",categorical:["#3b82f6","#14b8a6","#f97316","#9ca3af"],sequential:"blues",background:"#111827",surface:"#1f2937",text:"#f3f4f6",textSecondary:"#9ca3af",grid:"#374151",border:"#374151",focus:"#3b82f6",annotation:"#3b82f6",success:"#34d399",danger:"#f87171",warning:"#fbbf24",error:"#ef4444",info:"#60a5fa"},typography:{fontFamily:"'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f2937",text:"#f3f4f6",borderRadius:"6px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"8px"},italian:{mode:"light",colors:{primary:"#cc0000",secondary:"#666666",categorical:["#cc0000","#333333","#c8a415","#4682b4"],sequential:"reds",background:"#fafafa",surface:"#ffffff",text:"#1a1a1a",textSecondary:"#666666",grid:"#e0e0e0",border:"#e0e0e0",focus:"#cc0000",annotation:"#cc0000",success:"#556b2f",danger:"#cc0000",warning:"#c8a415",error:"#8b0000",info:"#4682b4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#1a1a1a",borderRadius:"2px",shadow:"0 2px 4px rgba(0, 0, 0, 0.15)"},borderRadius:"2px"},"italian-dark":{mode:"dark",colors:{primary:"#ff3333",secondary:"#aaaaaa",categorical:["#ff3333","#aaaaaa","#d4a843","#6aa4d4"],sequential:"reds",background:"#0a0a0a",surface:"#1a1a1a",text:"#f5f5f5",textSecondary:"#aaaaaa",grid:"#333333",border:"#333333",focus:"#ff3333",annotation:"#ff3333",success:"#7a8b5a",danger:"#ff3333",warning:"#d4a843",error:"#cc0000",info:"#6aa4d4"},typography:{fontFamily:"'Helvetica Neue', Helvetica, Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1a1a1a",text:"#f5f5f5",borderRadius:"2px",shadow:"0 2px 8px rgba(0, 0, 0, 0.5)"},borderRadius:"2px"},tufte:{mode:"light",colors:{primary:"#8b0000",secondary:"#555555",categorical:["#8b4513","#556b2f","#4a5568","#800020"],sequential:"oranges",background:"#fffff8",surface:"#fffff8",text:"#111111",textSecondary:"#555555",grid:"#e0ddd0",border:"#e0ddd0",focus:"#8b0000",annotation:"#8b0000",success:"#556b2f",danger:"#8b0000",warning:"#b88700",error:"#6b0000",info:"#4a5568"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#fffff8",text:"#111111",borderRadius:"2px",shadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},borderRadius:"0px"},"tufte-dark":{mode:"dark",colors:{primary:"#c05050",secondary:"#a09880",categorical:["#c08050","#7a8b5a","#8090a0","#a05060"],sequential:"oranges",background:"#1c1b18",surface:"#262520",text:"#e8e4d8",textSecondary:"#a09880",grid:"#3d3c35",border:"#3d3c35",focus:"#c05050",annotation:"#d06a6a",success:"#7a8b5a",danger:"#c05050",warning:"#c8a060",error:"#a04040",info:"#8090a0"},typography:{fontFamily:"Georgia, 'Times New Roman', serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262520",text:"#e8e4d8",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.4)"},borderRadius:"0px"},journalist:{mode:"light",colors:{primary:"#e45050",secondary:"#666666",categorical:["#3a86c8","#e45050","#d4a843","#888888"],sequential:"blues",background:"#ffffff",surface:"#f8f8f8",text:"#222222",textSecondary:"#666666",grid:"#d4d4d4",border:"#d4d4d4",focus:"#e45050",annotation:"#c63b3b",success:"#2d7a3d",danger:"#c8303a",warning:"#d4a843",error:"#a02028",info:"#3a86c8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:18,labelSize:12,tickSize:12,tickFontFamily:"'Courier New', Courier, monospace",legendSize:11},tooltip:{background:"#f8f8f8",text:"#222222",borderRadius:"4px",shadow:"0 2px 6px rgba(0, 0, 0, 0.12)"},borderRadius:"4px"},"journalist-dark":{mode:"dark",colors:{primary:"#ff6b6b",secondary:"#a0a0a0",categorical:["#5a9fd8","#ff6b6b","#e0c060","#aaaaaa"],sequential:"blues",background:"#141414",surface:"#1e1e1e",text:"#ededed",textSecondary:"#a0a0a0",grid:"#383838",border:"#383838",focus:"#ff6b6b",annotation:"#ff6b6b",success:"#6fba78",danger:"#ff6b6b",warning:"#e0c060",error:"#d04040",info:"#5a9fd8"},typography:{fontFamily:"'Franklin Gothic Medium', 'Libre Franklin', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1e1e1e",text:"#ededed",borderRadius:"4px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"4px"},playful:{mode:"light",colors:{primary:"#8b5cf6",secondary:"#7c5a9e",categorical:["#8b5cf6","#ec4899","#06b6d4","#84cc16"],sequential:"viridis",background:"#fdf8ff",surface:"#ffffff",text:"#2d1b4e",textSecondary:"#7c5a9e",grid:"#e8d0f8",border:"#e8d0f8",focus:"#8b5cf6",annotation:"#7a47e8",success:"#10d870",danger:"#ff4b6e",warning:"#ffaa33",error:"#e11d48",info:"#06b6d4"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#2d1b4e",borderRadius:"12px",shadow:"0 4px 12px rgba(139, 92, 246, 0.15)"},borderRadius:"12px"},"playful-dark":{mode:"dark",colors:{primary:"#a78bfa",secondary:"#b8a0d8",categorical:["#a78bfa","#f472b6","#22d3ee","#a3e635"],sequential:"viridis",background:"#150a28",surface:"#1f1138",text:"#f0e8ff",textSecondary:"#b8a0d8",grid:"#3a2560",border:"#3a2560",focus:"#a78bfa",annotation:"#a78bfa",success:"#4ade80",danger:"#fb7185",warning:"#fbbf24",error:"#f43f5e",info:"#22d3ee"},typography:{fontFamily:"'Nunito', 'Poppins', system-ui, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#1f1138",text:"#f0e8ff",borderRadius:"12px",shadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},borderRadius:"12px"},carbon:{mode:"light",colors:{primary:"#0f62fe",secondary:"#525252",categorical:["#6929c4","#1192e8","#005d5d","#9f1853"],sequential:"blues",diverging:"RdBu",background:"#ffffff",surface:"#ffffff",text:"#161616",textSecondary:"#525252",grid:"#e0e0e0",border:"#e0e0e0",focus:"#0f62fe",annotation:"#0f62fe",success:"#24a148",danger:"#da1e28",warning:"#f1c21b",error:"#a2191f",info:"#0043ce"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#ffffff",text:"#161616",borderRadius:"2px",shadow:"0 2px 6px rgba(0, 0, 0, 0.2)"},borderRadius:"0px"},"carbon-dark":{mode:"dark",colors:{primary:"#4589ff",secondary:"#a8a8a8",categorical:["#a56eff","#33b1ff","#08bdba","#ff7eb6"],sequential:"blues",diverging:"RdBu",background:"#161616",surface:"#262626",text:"#f4f4f4",textSecondary:"#a8a8a8",grid:"#393939",border:"#393939",focus:"#4589ff",annotation:"#4589ff",success:"#42be65",danger:"#fa4d56",warning:"#f1c21b",error:"#da1e28",info:"#4589ff"},typography:{fontFamily:"'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif",titleSize:16,labelSize:12,tickSize:12},tooltip:{background:"#262626",text:"#f4f4f4",borderRadius:"2px",shadow:"0 4px 12px rgba(0, 0, 0, 0.5)"},borderRadius:"0px"}};function A(e){return Object.prototype.hasOwnProperty.call(S,e)?S[e]:void 0}function M(e){if(!e)return x;if("string"==typeof e)return"light"===e?x:"dark"===e?b:"high-contrast"===e?v:A(e)||x;let t="dark"===e.mode?b:x;return k({...t,...e,colors:{...t.colors,...e.colors||{}},typography:{...t.typography,...e.typography||{}},tooltip:{...t.tooltip,...e.tooltip||{}}})}function $(e){return{background:e.colors.background,text:e.colors.text,textSecondary:e.colors.textSecondary,grid:e.colors.grid,border:e.colors.border,primary:e.colors.primary,fontFamily:e.typography.fontFamily,titleSize:e.typography.titleSize,labelSize:e.typography.labelSize,tickSize:e.typography.tickSize,categorical:e.colors.categorical,annotation:e.colors.annotation??e.colors.text,legendSize:e.typography.legendSize??e.typography.labelSize,legendFontFamily:e.typography.legendFontFamily??e.typography.fontFamily,legendFontWeight:e.typography.legendFontWeight,titleFontSize:e.typography.titleFontSize??e.typography.titleSize,titleFontFamily:e.typography.titleFontFamily??e.typography.fontFamily,titleFontWeight:e.typography.titleFontWeight??"bold",tickFontFamily:e.typography.tickFontFamily??e.typography.fontFamily}}function _(e){let t=e?.find(e=>"bottom"===e.orient),i=e?.find(e=>"top"===e.orient),r=e?.find(e=>"left"===e.orient),n=e?.find(e=>"right"===e.orient);return{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:n,xAxis:t??i,yAxis:r??n,xOrient:t||!i?"bottom":"top",yOrient:r||!n?"left":"right"}}function I(e){let t=6;for(let i=1;i<e.length;i++){let r=Math.abs(e[i]-e[i-1]);if(r>0&&Number.isFinite(r)){let n=Math.max(Math.abs(e[i]),Math.abs(e[i-1]));t=Math.max(t,Math.ceil(Math.log10(n/r))+1)}}let i=Math.min(17,t);return e=>Number.isInteger(e)?String(e):String(Number(e.toPrecision(i)))}function P(...e){let t;for(let i of e)i&&(t=L(t)&&L(i)?{legendGroups:[...t.legendGroups,...i.legendGroups],legendDistance:i.legendDistance??t.legendDistance}:i);return t}function L(e){return"object"==typeof e&&null!==e&&"legendGroups"in e&&Array.isArray(e.legendGroups)}function R(e){return"object"==typeof e&&null!==e&&"gradient"in e}function C(e){return"string"==typeof e&&e.length>0}function T(e,t){let i=t?36:0;return e.top>=i?e:{...e,top:i}}function N(e,t){return T(e,C(t))}function F(e,t,i,r,n=8){let o="left"===r||"right"===r,a=r,s="left"===r?"right":"right"===r?"left":"top"===r?"bottom":"top",l=Math.max(0,(o?i[0]:i[1])-n),c=Math.max(t[a],l-e[s]);e[a]>c&&(e[a]=c)}function E(e){return Math.ceil(7*e.length)}function O(e,t){if(L(e)){let i=K(t),r=100;for(let t of e.legendGroups){t.label&&(r=Math.max(r,E(t.label)));for(let e of t.items)r=Math.max(r,i.swatchSize+i.labelGap+E(e.label))}return r}if(R(e)){let{gradient:t}=e,i=t.format||I(t.domain),r=Math.max(E(i(t.domain[0])),E(i(t.domain[1]))),n=t.label?E(t.label):0;return Math.max(100,19+r,n)}return 100}function z(e){return(L(e)||R(e))&&Number.isFinite(e.legendDistance)?Math.max(0,e.legendDistance):10}function D(e,t){return null!=e?.sideGutter?Math.max(0,e.sideGutter):t?.hasAxis?t.hasAxisLabel?W:j:0}function B(e){return Math.max(0,e?.edgeGutter??3)}var j=34,W=70;function Y(e,t){return null!=t?.axisGutter?Math.max(0,t.axisGutter):e?.hasAxis?e.hasAxisLabel?e.rotatedTicks?64:46:22:0}function q(e){let{bottomAxis:t,topAxis:i,leftAxis:r,rightAxis:n}=_(e.axes),o=!(i&&!t||!1===t?.visible),a=!!i&&!t&&!1!==i.visible,s=!(n&&!r||!1===r?.visible),l=!!n&&!1!==n.visible,c=!1!==e.showAxes;return{hasAxis:c&&o,hasAxisLabel:c&&o&&!!(t?.label??e.xLabel),rotatedTicks:c&&o&&(e.rotatedTicks??!!t?.autoRotate),topAxis:a?{hasAxis:c,hasAxisLabel:c&&!!(i?.label??e.xLabel),rotatedTicks:c&&(e.rotatedTicks??!!i?.autoRotate)}:void 0,leftAxis:s?{hasAxis:c,hasAxisLabel:c&&!!(r?.label??e.yLabel)}:void 0,rightAxis:l?{hasAxis:c,hasAxisLabel:c&&!!(n?.label??e.yLabelRight??e.yLabel)}:void 0}}function X(e){let t=e.projection??"vertical",i=!1!==e.showAxes&&"radial"!==t;return{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasValueLabel:e.hasCategoryLabel),leftAxis:{hasAxis:i,hasAxisLabel:i&&("horizontal"===t?e.hasCategoryLabel:e.hasValueLabel)}}}function G(e,t,i){if(R(e))return e.gradient.label?46:26;if(!L(e))return 20;let r=K(i),n=Math.max(1,i?.maxWidth??t),o=r.rowHeight;for(let t of e.legendGroups){let e=0,i=0;for(let o of t.items){let t=r.swatchSize+r.labelGap+E(o.label),a=0===i?t:i+r.itemGap+t;i>0&&a>n?(e+=1,i=t):i=a}t.items.length>0&&(e+=1),o=Math.max(o,e*r.rowHeight,t.label?E(t.label):0)}return o+(e.legendGroups.length>1?16:0)}function V(e,t,i){return O(e,t)+z(e)+D(t,i)+B(t)}function H(e,t){let{legend:i}=t;if(!i)return;let r=t.position??"right",n=G(i,Math.max(1,t.size[0]-e.left-e.right),t.legendLayout)+z(i)+Y("bottom"===r?t.axisChrome:"top"===r?t.axisChrome?.topAxis:void 0,t.legendLayout)+("top"===r&&t.hasTitle?24:0),o=Math.max(t.minimumMargin??0,"top"===r?t.hasTitle?58:34:0);"right"===r?e.right=Math.max(e.right,o,V(i,t.legendLayout,t.axisChrome?.rightAxis)):"left"===r?e.left=Math.max(e.left,o,V(i,t.legendLayout,t.axisChrome?.leftAxis)):"top"===r?e.top=Math.max(e.top,o,n):e.bottom=Math.max(e.bottom,o,n)}function U(e,t){let i=t.position??"right",r="top"===i||"bottom"===i,n=Math.max(0,t.totalWidth-t.margin.left-t.margin.right),o=Math.max(1,r?t.legendLayout?.maxWidth??n:t.reservedWidth??O(e,t.legendLayout)),a=z(e),s=D(t.legendLayout,"left"===i?t.axisChrome?.leftAxis:t.axisChrome?.rightAxis),l=B(t.legendLayout),c=G(e,n,t.legendLayout),u=Y(t.axisChrome,t.legendLayout),d=Y(t.axisChrome?.topAxis,t.legendLayout);if("left"===i)return{x:Math.max(l,t.margin.left-s-o-a),y:t.margin.top,width:o,height:c};if("top"===i)return{x:t.margin.left,y:t.margin.top-d-a-c,width:o,height:c};if("bottom"===i){let e=t.totalHeight-t.margin.bottom;return{x:t.margin.left,y:Math.max(e+a,Math.min(e+u+a,t.totalHeight-c)),width:o,height:c}}return{x:Math.min(t.totalWidth-o-l,t.totalWidth-t.margin.right+s+a),y:t.margin.top,width:o,height:c}}function K(e){let t=Math.max(1,e?.swatchSize??16),i=Math.max(t,e?.rowHeight??22);return{swatchSize:t,labelGap:Math.max(0,e?.labelGap??6),itemGap:Math.max(0,e?.itemGap??10),rowHeight:i,align:"left"===e?.align?"start":"right"===e?.align?"end":e?.align??"start",maxWidth:e?.maxWidth}}function Z(e,t){let i=24;return e.map(({hasLabel:e,itemCount:r})=>{i+=5;let n,o=i;i+=8,e&&(i+=16,n=i,i+=8);let a=i;return i+=r*t+8,{lineY:o,labelY:n,itemsY:a,endY:i}})}function Q(e,t,i=!1){let r={...e};for(let e of t??[])!1===e.visible&&("top"!==e.orient||!i)&&(r[e.orient]=0);return r}var J=/\s+([^\s=<>/'"]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function ee(e){let t=0;for(;t<e.length;){let i=/^\s+/.exec(e.slice(t));i&&(t+=i[0].length);let r=e.startsWith("\x3c!--",t)?"--\x3e":e.startsWith("<?",t)?"?>":void 0;if(r){let i=e.indexOf(r,t+2);if(i<0)return;t=i+r.length;continue}if(/^<!DOCTYPE\s/i.test(e.slice(t))){let i="",r=0,n=t+9;for(;n<e.length;n+=1){let t=e[n];if(i)t===i&&(i="");else if(e.startsWith("\x3c!--",n)){let t=e.indexOf("--\x3e",n+4);if(t<0)return;n=t+2}else if('"'===t||"'"===t)i=t;else if("["===t)r+=1;else if("]"===t)r-=1;else if(">"===t&&0===r)break}if(n===e.length)return;t=n+1;continue}break}let i=/^<((?:[A-Za-z_][\w.-]*:)?svg)(?=[\s/>])((?:[^<>"']|"[^"]*"|'[^']*')*)>/i.exec(e.slice(t));if(!i)return;let r=i[2].endsWith("/"),n=r?i[2].slice(0,-1):i[2];return n.replace(J,"").trim()?void 0:{start:t,end:t+i[0].length,name:i[1],attributes:n,selfClosing:r}}function te(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g,"&#9;").replace(/\n/g,"&#10;").replace(/\r/g,"&#13;")}function ie(e){return e.replace(/\r\n|[\t\r\n]/g," ").replace(/&(amp|quot|apos|lt|gt|#\d+|#x[\da-fA-F]+);/g,(e,t)=>{if(!t.startsWith("#"))return{amp:"&",quot:'"',apos:"'",lt:"<",gt:">"}[t];let i=t.startsWith("#x")?parseInt(t.slice(2),16):Number(t.slice(1));return i>0&&i<=1114111?String.fromCodePoint(i):e})}function re(e,t){for(let i of e.attributes.matchAll(J))if(i[1]===t)return ie(i[2]??i[3])}function ne(e,t){let i=ee(e)?.start??0;return e.slice(0,i)+e.slice(i).replace(/<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?(?:\]\]>|$)|<\?[\s\S]*?(?:\?>|$)|<([A-Za-z_][\w.:-]*)(?=[\s/>])(?:[^<>"']|"[^"]*"|'[^']*')*>/g,(e,i)=>i?e.replace(J,(e,i,r,n)=>{let o=t(i,ie(r??n));return void 0===o?e:` ${i}="${te(o)}"`}):e)}function oe(e,t){let i=ee(e);if(!i)return e;let r=new Map(Object.entries(t)),n=i.attributes.replace(J,(e,t)=>{let i=r.get(t);return void 0===i?e:(r.delete(t),` ${t}="${te(i)}"`)});for(let[e,t]of r)n+=` ${e}="${te(t)}"`;return`${e.slice(0,i.start)}<${i.name}${n}${i.selfClosing?"/":""}>${e.slice(i.end)}`}function ae(e,t){let i=ee(e);if(!i)return t;let r=e=>{let r=re(i,e),n=r&&/^[0-9]+(?:\.[0-9]+)?$/.test(r)?Number(r):NaN;return Number.isFinite(n)&&n>0?n:t[e]};return{width:r("width"),height:r("height")}}function se(e,t){let i=ee(e);return i?oe(e,{width:"100%",height:"100%",...void 0===re(i,"viewBox")?{viewBox:`0 0 ${t.width} ${t.height}`}:{},...void 0===re(i,"preserveAspectRatio")?{preserveAspectRatio:"xMidYMid meet"}:{}}):e}function le(e){return null==e?"null":Array.isArray(e)?`[${e.map(le).join(",")}]`:e instanceof Date?JSON.stringify(e):"object"==typeof e?`{${Object.entries(e).filter(([,e])=>void 0!==e).sort(([e],[t])=>e<t?-1:e>t?1:0).map(([e,t])=>`${JSON.stringify(e)}:${le(t)}`).join(",")}}`:JSON.stringify(e)}function ce(e){return ue(le(e))}function ue(e){let t=[...fe],i=Array.from((new TextEncoder).encode(e)),r=8*i.length;for(i.push(128);i.length%64!=56;)i.push(0);let n=Math.floor(r/4294967296),o=r>>>0;i.push(n>>>24&255,n>>>16&255,n>>>8&255,255&n,o>>>24&255,o>>>16&255,o>>>8&255,255&o);let a=[];for(let e=0;e<i.length;e+=4)a.push((i[e]<<24|i[e+1]<<16|i[e+2]<<8|i[e+3])>>>0);for(let e=0;e<a.length;e+=16){let i=[...a.slice(e,e+16)];for(let e=16;e<64;e+=1){let t=de(i[e-15],7)^de(i[e-15],18)^i[e-15]>>>3,r=de(i[e-2],17)^de(i[e-2],19)^i[e-2]>>>10;i[e]=i[e-16]+t+i[e-7]+r>>>0}let[r,n,o,s,l,c,u,d]=t;for(let e=0;e<64;e+=1){let t=d+(de(l,6)^de(l,11)^de(l,25))+(l&c^~l&u)+pe[e]+i[e]>>>0,a=r&n^r&o^n&o;d=u,u=c,c=l,l=s+t>>>0,s=o,o=n,n=r,r=t+((de(r,2)^de(r,13)^de(r,22))+a>>>0)>>>0}let h=[r,n,o,s,l,c,u,d];for(let e=0;e<8;e+=1)t[e]=t[e]+h[e]>>>0}return t.map(e=>e.toString(16).padStart(8,"0")).join("")}var de=(e,t)=>(e>>>t|e<<32-t)>>>0,he=e=>Math.floor(4294967296*(e-Math.floor(e)))>>>0,[fe,pe]=/* @__PURE__ */(()=>{let e=[],t=[];for(let i=2;t.length<64;i+=1){let r=!0;for(let e=2;e*e<=i;e+=1)if(i%e===0){r=!1;break}r&&(e.length<8&&e.push(he(Math.sqrt(i))),t.push(he(Math.cbrt(i))))}return[e,t]})();function ge(e,t){return`${e}[Symbol(${t.description??""})]`}function me(e,t){if(!/^(0|[1-9][0-9]*)$/.test(e))return!1;let i=Number(e);return Number.isSafeInteger(i)&&i>=0&&i<t}function ye(e,t){return"number"==typeof t?`${e}[${t}]`:e?`${e}.${t}`:t}function xe(e){return e.sort((e,t)=>{let i=JSON.stringify(e),r=JSON.stringify(t);return i<r?-1:i>r?1:0})}function be(e,t,i){if(null===e)return null;if(e instanceof Date){let r=e.getTime();return Number.isFinite(r)?{$type:"date",value:e.toISOString()}:void i.excluded.push(t)}switch(typeof e){case"string":case"boolean":return e;case"number":return Number.isNaN(e)?{$type:"number",value:"NaN"}:e===1/0?{$type:"number",value:"Infinity"}:e===-1/0?{$type:"number",value:"-Infinity"}:Object.is(e,-0)?{$type:"number",value:"-0"}:e;case"bigint":return{$type:"bigint",value:e.toString()};case"undefined":case"function":case"symbol":return void i.excluded.push(t);case"object":{let r=e;if(i.ancestors.has(r))return void i.excluded.push(t);i.ancestors.add(r);try{if(Array.isArray(e)){for(let r of Reflect.ownKeys(e))"length"===r||"string"==typeof r&&me(r,e.length)||i.excluded.push("symbol"==typeof r?ge(t,r):ye(t,r));return Array.from({length:e.length},(r,n)=>{let o=ye(t,n),a=Object.getOwnPropertyDescriptor(e,String(n));if(!a||!("value"in a)||!a.enumerable)return i.excluded.push(o),null;let s=be(a.value,o,i);return void 0===s?null:s})}let r={},n=Object.getPrototypeOf(e);if(n!==Object.prototype&&null!==n)return void i.excluded.push(t);let o=[];for(let r of Reflect.ownKeys(e)){if("symbol"==typeof r){i.excluded.push(ge(t,r));continue}let n=Object.getOwnPropertyDescriptor(e,r);n&&"value"in n&&n.enumerable?o.push(r):i.excluded.push(ye(t,r))}for(let n of o.sort()){let o=Object.getOwnPropertyDescriptor(e,n),a=be(o&&"value"in o?o.value:void 0,ye(t,n),i);void 0!==a&&Object.defineProperty(r,n,{value:a,enumerable:!0,configurable:!0,writable:!0})}return r}finally{i.ancestors.delete(r)}}default:return void i.excluded.push(t)}}function ve(e,t=/* @__PURE__ */new Set){if(null===e)return["null"];if(e instanceof Date)return Number.isFinite(e.getTime())?["date",e.toISOString()]:["excluded"];switch(typeof e){case"string":return["string",e];case"boolean":return["boolean",e];case"number":return["number",Number.isNaN(e)?"NaN":e===1/0?"Infinity":e===-1/0?"-Infinity":Object.is(e,-0)?"-0":String(e)];case"bigint":return["bigint",e.toString()];case"undefined":case"function":case"symbol":return["excluded"];case"object":if(t.has(e))return["excluded"];t.add(e);try{let i=i=>{let r="symbol"==typeof i?["symbol-key",i.description??""]:["string-key",i],n=Object.getOwnPropertyDescriptor(e,i);return n?"value"in n?[r,"data",!!n.enumerable,ve(n.value,t)]:[r,"accessor",!!n.enumerable,!!n.get,!!n.set]:[r,"missing"]};if(Array.isArray(e))return["array",Array.from({length:e.length},(t,r)=>{let n=String(r);return Object.prototype.hasOwnProperty.call(e,n)?i(n):["hole"]}),xe(Reflect.ownKeys(e).filter(t=>"length"!==t&&!("string"==typeof t&&me(t,e.length))).map(i))];let r=Object.getPrototypeOf(e);return[r!==Object.prototype&&null!==r?"non-json-object":"object",xe(Reflect.ownKeys(e).map(i))]}finally{t.delete(e)}default:return["excluded"]}}function we(e){let t={excluded:[],ancestors:/* @__PURE__ */new Set},i=be(e,"$",t)??null;return{value:i,text:JSON.stringify(i),excludedPaths:t.excluded}}function ke(e){let t=we(e),i=ue(JSON.stringify(["semiotic-value-fingerprint","v2",ve(e)]));return{...t,algorithm:"sha256",digest:i,fingerprint:`sha256:${i}`}}function Se(e,t){return"number"==typeof t?`${e}[${t}]`:`${e}.${t}`}function Ae(e,t){return`${e}[Symbol(${t.description??""})]`}function Me(e,t){if(!/^(0|[1-9][0-9]*)$/.test(e))return!1;let i=Number(e);return Number.isSafeInteger(i)&&i>=0&&i<t}function $e(e,t){try{return Object.getOwnPropertyDescriptor(e,t)}catch{return}}function _e(e,t,i,r){let n=$e(e,t);return n&&"value"in n&&n.enumerable?Ie(n.value,i,r):[i]}function Ie(e,t="$",i=/* @__PURE__ */new Set){if(null===e||"string"==typeof e||"boolean"==typeof e)return[];if("number"==typeof e)return Number.isFinite(e)&&!Object.is(e,-0)?[]:[t];if("object"!=typeof e)return[t];if(i.has(e))return[t];let r,n,o;try{o=Array.isArray(e),r=Object.getPrototypeOf(e),n=Reflect.ownKeys(e)}catch{return[t]}if(r!==(o?Array.prototype:Object.prototype)&&null!==r)return[t];i.add(e);let a=[];try{if(o){let r=$e(e,"length")?.value;if(!Number.isSafeInteger(r)||r<0)return[Se(t,"length")];for(let e of n)"length"===e||"string"==typeof e&&Me(e,r)||a.push("symbol"==typeof e?Ae(t,e):Se(t,e));for(let n=0;n<r;n+=1)a.push(..._e(e,String(n),Se(t,n),i))}else for(let r of n)"symbol"!=typeof r?a.push(..._e(e,r,Se(t,r),i)):a.push(Ae(t,r));return a}catch{return[t]}finally{i.delete(e)}}function Pe(e,t,i,r){Ee(e,Object.keys(t),i,r);for(let[n,o]of Object.entries(t))o.values?(o.required||void 0!==e[n])&&ze(e,n,i,o.values,r):o.required?Oe(e,n,i,r):Ye(e,n,i,r)}function Le(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function Re(e,t,i,r){void 0!==e[t]&&("number"!=typeof e[t]||!Number.isFinite(e[t]))&&r.push({path:`${i}.${t}`,message:"Expected a finite number."})}function Ce(e,t,i,r){void 0!==e[t]&&"boolean"!=typeof e[t]&&r.push({path:`${i}.${t}`,message:"Expected a boolean."})}function Te(e){return null===e||"string"==typeof e||"boolean"==typeof e||("number"==typeof e?Number.isFinite(e):Array.isArray(e)?e.every(Te):Le(e)&&Object.values(e).every(Te))}function Ne(e,t,i,r){void 0!==e[t]&&(!Le(e[t])||!Te(e[t]))&&r.push({path:`${i}.${t}`,message:"Expected a JSON object."})}function Fe(e){return e.every(Te)}function Ee(e,t,i,r){let n=new Set(t);for(let t of Object.keys(e))n.has(t)||r.push({path:`${i}.${t}`,message:"Unexpected property."})}function Oe(e,t,i,r){("string"!=typeof e[t]||!e[t])&&r.push({path:`${i}.${t}`,message:"Expected a non-empty string."})}function ze(e,t,i,r,n){("string"!=typeof e[t]||!r.includes(e[t]))&&n.push({path:`${i}.${t}`,message:`Expected one of: ${r.join(", ")}.`})}function De(e,t,i,r){let n=e[t];if(void 0!==n)return Le(n)?n:void r.push({path:`${i}.${t}`,message:"Expected an object."})}function Be(e,t,i,r){let n=e[t];if(void 0!==n)return Array.isArray(n)?n:void r.push({path:`${i}.${t}`,message:"Expected an array."})}function je(e,t,i){e?.some(e=>"string"!=typeof e||!e)&&i.push({path:t,message:"Expected non-empty string values."})}function We(e,t,i,r,n){void 0!==e[t]&&ze(e,t,i,r,n)}function Ye(e,t,i,r){void 0!==e[t]&&"string"!=typeof e[t]&&r.push({path:`${i}.${t}`,message:"Expected a string."})}function qe(e,t,i){Le(e)?(Ee(e,["id","name","kind"],t,i),Oe(e,"kind",t,i),Ye(e,"id",t,i),Ye(e,"name",t,i)):i.push({path:t,message:"Expected an actor object."})}function Xe(e,t){let i=De(e,"reception","$",t);if(!i)return;Ee(i,["channels","audience","strengths","risks","scaffolds","description","dataFallback","manualChecks"],"$.reception",t);let r=Be(i,"channels","$.reception",t);r||t.push({path:"$.reception.channels",message:"Expected a reception-channel array."}),r?.forEach((e,i)=>{let r=`$.reception.channels[${i}]`;Le(e)?(Ee(e,["channel","disclosure","navigation","interactionInstructions","rawData","tokenBudget","privacyNotes"],r,t),ze(e,"channel",r,["visual","screen-reader","sonified","agent","print","low-bandwidth"],t),We(e,"disclosure",r,["summary","standard","detailed"],t),We(e,"rawData",r,["deny","bounded","allow"],t),Ce(e,"navigation",r,t),Ce(e,"interactionInstructions",r,t),Re(e,"tokenBudget",r,t),je(Be(e,"privacyNotes",r,t),`${r}.privacyNotes`,t)):t.push({path:r,message:"Expected a channel object."})});for(let e of["strengths","risks","scaffolds","manualChecks"])je(Be(i,e,"$.reception",t),`$.reception.${e}`,t);Ye(i,"audience","$.reception",t),Ye(i,"description","$.reception",t),Ce(i,"dataFallback","$.reception",t)}function Ge(e,t){let i=De(e,"form","$",t);i&&(Ee(i,["chartFamily","whyThisForm","rejectedAlternatives","risks","misuse"],"$.form",t),Ye(i,"chartFamily","$.form",t),Ye(i,"whyThisForm","$.form",t),je(Be(i,"risks","$.form",t),"$.form.risks",t),je(Be(i,"misuse","$.form",t),"$.form.misuse",t),Be(i,"rejectedAlternatives","$.form",t)?.forEach((e,i)=>{let r=`$.form.rejectedAlternatives[${i}]`;Le(e)?(Ee(e,["representation","reason"],r,t),Oe(e,"representation",r,t),Oe(e,"reason",r,t)):t.push({path:r,message:"Expected an alternative object."})}))}function Ve(e,t){let i=De(e,"contestability","$",t);i&&(Ee(i,["sourceRequestsAllowed","alternativeViews","challenges","corrections","editorialExceptions"],"$.contestability",t),Ce(i,"sourceRequestsAllowed","$.contestability",t),Be(i,"challenges","$.contestability",t)?.forEach((e,i)=>{let r=`$.contestability.challenges[${i}]`;if(Le(e)){Ee(e,["id","claimId","status","reason","raisedBy","raisedAt","counterclaimId","resolution"],r,t),Oe(e,"id",r,t),Oe(e,"claimId",r,t),Oe(e,"reason",r,t),ze(e,"status",r,["open","accepted","declined","resolved"],t),void 0!==e.raisedBy&&qe(e.raisedBy,`${r}.raisedBy`,t);for(let i of["raisedAt","counterclaimId","resolution"])Ye(e,i,r,t)}else t.push({path:r,message:"Expected a challenge object."})}),Be(i,"corrections","$.contestability",t)?.forEach((e,i)=>{let r=`$.contestability.corrections[${i}]`;if(!Le(e))return void t.push({path:r,message:"Expected a correction object."});Ee(e,["id","affectedClaimIds","replacementClaimIds","reason","createdAt","createdBy"],r,t),Oe(e,"id",r,t),Oe(e,"reason",r,t);let n=Be(e,"affectedClaimIds",r,t);n||t.push({path:`${r}.affectedClaimIds`,message:"Expected an affected-claim array."}),je(n,`${r}.affectedClaimIds`,t),je(Be(e,"replacementClaimIds",r,t),`${r}.replacementClaimIds`,t),Ye(e,"createdAt",r,t),void 0!==e.createdBy&&qe(e.createdBy,`${r}.createdBy`,t)}),Be(i,"alternativeViews","$.contestability",t)?.forEach((e,i)=>{let r=`$.contestability.alternativeViews[${i}]`;Le(e)?(Ee(e,["id","label","rationale"],r,t),Oe(e,"id",r,t),Oe(e,"label",r,t),Ye(e,"rationale",r,t)):t.push({path:r,message:"Expected an alternative-view object."})}),Be(i,"editorialExceptions","$.contestability",t)?.forEach((e,i)=>{let r=`$.contestability.editorialExceptions[${i}]`;Le(e)?(Ee(e,["ruleId","rationale","owner","reviewAt"],r,t),Oe(e,"ruleId",r,t),Oe(e,"rationale",r,t),Ye(e,"owner",r,t),Ye(e,"reviewAt",r,t)):t.push({path:r,message:"Expected an editorial-exception object."})}))}function He(e,t){let i=De(e,"accountability","$",t);i&&(Ee(i,["authors","generatedBy","dataSources","codeRef","reviews","actions"],"$.accountability",t),Be(i,"authors","$.accountability",t)?.forEach((e,i)=>qe(e,`$.accountability.authors[${i}]`,t)),je(Be(i,"dataSources","$.accountability",t),"$.accountability.dataSources",t),Ye(i,"generatedBy","$.accountability",t),Ye(i,"codeRef","$.accountability",t),Be(i,"reviews","$.accountability",t)?.forEach((e,i)=>{let r=`$.accountability.reviews[${i}]`;if(Le(e)){Ee(e,["id","status","reviewer","reviewedAt","rationale","policyId"],r,t),Oe(e,"id",r,t),ze(e,"status",r,["pending","approved","changes-requested","rejected"],t),void 0!==e.reviewer&&qe(e.reviewer,`${r}.reviewer`,t);for(let i of["reviewedAt","rationale","policyId"])Ye(e,i,r,t)}else t.push({path:r,message:"Expected a review object."})}),Be(i,"actions","$.accountability",t)?.forEach((e,i)=>{let r=`$.accountability.actions[${i}]`;if(!Le(e))return void t.push({path:r,message:"Expected an action object."});Ee(e,["id","action","actor","actedAt","claimIds","artifactId","artifactRevision","policyId","status","invalidatedByClaimId"],r,t),Oe(e,"id",r,t),Oe(e,"action",r,t);let n=Be(e,"claimIds",r,t);n||t.push({path:`${r}.claimIds`,message:"Expected a claim identifier array."}),je(n,`${r}.claimIds`,t),void 0!==e.actor&&qe(e.actor,`${r}.actor`,t);for(let i of["actedAt","artifactId","artifactRevision","policyId","invalidatedByClaimId"])Ye(e,i,r,t);We(e,"status",r,["proposed","taken","reversed","invalidated"],t)}))}function Ue(e,t){let i=De(e,"inheritance","$",t);if(i){Ee(i,["requiredPaths","prohibitedExports","privacy","rawDataDefault","preservation","sourceArtifactIds"],"$.inheritance",t);for(let e of["requiredPaths","prohibitedExports","sourceArtifactIds"])je(Be(i,e,"$.inheritance",t),`$.inheritance.${e}`,t);We(i,"privacy","$.inheritance",["public","restricted","confidential","unknown"],t),We(i,"rawDataDefault","$.inheritance",["exclude","bounded","include"],t),We(i,"preservation","$.inheritance",["full-fidelity","claim-evidence-preserved","visual-only","lossy","unknown"],t)}}function Ke(e,t){Xe(e,t),Ge(e,t),Ve(e,t),He(e,t),Ue(e,t)}function Ze(e){for(let t of Object.values(e))Object.freeze(t.suppliedBy),Object.freeze(t);return Object.freeze(e)}var Qe=/* @__PURE__ */Ze({"artifact.id":{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"never"},"artifact.createdAt":{suppliedBy:["author","system","import"],derivable:!1,modelMayPropose:!1,humanReview:"never"},"artifact.configFingerprint":{suppliedBy:["system"],derivable:!0,modelMayPropose:!1,humanReview:"never"},"artifact.dataFingerprint":{suppliedBy:["system"],derivable:!0,modelMayPropose:!1,humanReview:"never"},"purpose.intents":{suppliedBy:["author","system","model-proposal","import"],derivable:!0,modelMayPropose:!0,humanReview:"policy-dependent"},"purpose.communicativeAct":{suppliedBy:["author","system","model-proposal","import"],derivable:!0,modelMayPropose:!0,humanReview:"policy-dependent"},"purpose.stakes":{suppliedBy:["author","import"],derivable:!1,modelMayPropose:!0,humanReview:"required"},claims:{suppliedBy:["author","system","model-proposal","import"],derivable:!0,modelMayPropose:!0,humanReview:"policy-dependent"},"claims.status":{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"policy-dependent"},evidence:{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"policy-dependent"},"evidence.source":{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"policy-dependent"},"evidence.fingerprint":{suppliedBy:["system"],derivable:!0,modelMayPropose:!1,humanReview:"never"},time:{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"policy-dependent"},"time.completeness":{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"policy-dependent"},reception:{suppliedBy:["author","system","model-proposal","import"],derivable:!0,modelMayPropose:!0,humanReview:"policy-dependent"},form:{suppliedBy:["author","system","model-proposal","import"],derivable:!0,modelMayPropose:!0,humanReview:"policy-dependent"},contestability:{suppliedBy:["author","system","import"],derivable:!1,modelMayPropose:!1,humanReview:"required"},accountability:{suppliedBy:["author","system","import"],derivable:!1,modelMayPropose:!1,humanReview:"policy-dependent"},inheritance:{suppliedBy:["author","system","import"],derivable:!0,modelMayPropose:!1,humanReview:"policy-dependent"}});function Je(e,t){if(void 0===e||Le(e)){if(Le(e))for(let[i,r]of Object.entries(e)){let e=`$.fieldStatus.${i}`;if(!Le(r)||"string"!=typeof r.status){t.push({path:e,message:"Expected a field state with a status."});continue}Ee(r,["status","reason","suppliedBy","derived","reviewedBy"],e,t),["known","unknown","manual","not-applicable"].includes(r.status)||t.push({path:`${e}.status`,message:"Expected one of: known, unknown, manual, not-applicable."}),void 0!==r.suppliedBy&&("string"!=typeof r.suppliedBy||!["author","system","model-proposal","import"].includes(r.suppliedBy))&&t.push({path:`${e}.suppliedBy`,message:"Expected one of: author, system, model-proposal, import."}),Ye(r,"reason",e,t),Ye(r,"reviewedBy",e,t),Ce(r,"derived",e,t);let n=Object.prototype.hasOwnProperty.call(Qe,i)?Qe[i]:void 0,o="model-proposal"===r.suppliedBy,a=o&&!0===n?.modelMayPropose&&"known"!==r.status;n&&"known"===r.status&&"string"!=typeof r.suppliedBy&&t.push({path:`${e}.suppliedBy`,message:`Known field "${i}" must identify an allowed supplier.`}),n&&"string"==typeof r.suppliedBy&&!a&&!n.suppliedBy.includes(r.suppliedBy)&&t.push({path:`${e}.suppliedBy`,message:`Field "${i}" cannot be supplied by ${r.suppliedBy}.`}),n&&!0===r.derived&&!n.derivable&&t.push({path:`${e}.derived`,message:`Field "${i}" cannot be marked as derived.`}),n&&o&&(!n.modelMayPropose||"known"===r.status)&&t.push({path:`${e}.suppliedBy`,message:"known"===r.status?`A model proposal cannot finalize field "${i}" as known.`:`Field "${i}" does not accept model proposals.`}),"required"===n?.humanReview&&"known"===r.status&&("string"!=typeof r.reviewedBy||!r.reviewedBy.trim())&&t.push({path:`${e}.reviewedBy`,message:`Known field "${i}" requires an attributable human review.`})}}else t.push({path:"$.fieldStatus",message:"Expected a field-state object."})}var et=["fresh","stale","unknown"],tt=["partial","provisional","settled","unknown"],it=["observedAt","ingestedAt","processedAt","publishedAt","snapshotAt"],rt={eventTime:{field:{},value:{},timezone:{},granularity:{}},presentation:{state:{values:["live","historical","mixed"]},label:{}},freshness:{status:{required:!0,values:et},checkedAt:{},heartbeatAt:{},expiresAt:{},basis:{}},watermark:{value:{required:!0},policy:{},allowedLateness:{}},window:{start:{required:!0},end:{required:!0},status:{required:!0,values:["open","provisional","settled","reopened","corrected"]}},completeness:{status:{required:!0,values:tt},basis:{}},revision:{status:{required:!0,values:["original","backfilled","corrected","superseded"]},previousArtifactId:{},correctionId:{},reason:{}},snapshot:{id:{},format:{values:["iceberg","delta","other"]},schemaVersion:{},catalogRef:{}}},nt={id:{required:!0},kind:{required:!0,values:["stream","processing-job","quality-check","snapshot","publication"]},label:{},observedAt:{},version:{},timezone:{},granularity:{},freshness:{values:et},completeness:{values:tt}};function ot(e,t){let i="$.time";Ee(e,[...it,...Object.keys(rt),"sources"],i,t);for(let r of it)Ye(e,r,i,t);for(let[r,n]of Object.entries(rt)){let o=De(e,r,i,t);o&&Pe(o,n,`${i}.${r}`,t)}Be(e,"sources",i,t)?.forEach((e,r)=>{let n=`${i}.sources[${r}]`;Le(e)?Pe(e,nt,n,t):t.push({path:n,message:"Expected a source object."})})}function at(e){try{return st(e)}catch{return{valid:!1,errors:[{path:"$",message:"Artifact contract could not be inspected safely."}],warnings:[]}}}function st(e){let t=[],i=[];if(!Le(e))return{valid:!1,errors:[{path:"$",message:"Expected an object."}],warnings:i};let r=Ie(e);if(r.length>0)return{valid:!1,errors:r.map(e=>({path:e,message:"Expected a JSON-compatible value that survives serialization unchanged."})),warnings:i};if(Ee(e,["contractVersion","artifact","purpose","claims","evidence","time","reception","form","contestability","accountability","inheritance","fieldStatus","extensions"],"$",t),"0.1"!==e.contractVersion&&t.push({path:"$.contractVersion",message:"Expected contract version 0.1."}),Le(e.artifact)){Ee(e.artifact,["id","kind","component","title","createdAt","configFingerprint","dataFingerprint","revision"],"$.artifact",t),Oe(e.artifact,"id","$.artifact",t),ze(e.artifact,"kind","$.artifact",["chart","dashboard","story","alert","agent-answer"],t);for(let i of["component","title","createdAt","configFingerprint","dataFingerprint","revision"])Ye(e.artifact,i,"$.artifact",t)}else t.push({path:"$.artifact",message:"Expected an artifact identity object."});if(Le(e.purpose))if(Array.isArray(e.purpose.intents)){Ee(e.purpose,["intents","communicativeAct","decisionContext","stakes","allowedUses","prohibitedUses"],"$.purpose",t),e.purpose.intents.forEach((e,i)=>{(!Le(e)||"string"!=typeof e.id||!e.id)&&t.push({path:`$.purpose.intents[${i}].id`,message:"Expected a non-empty intent identifier."}),Le(e)&&Ee(e,["id","strength","source","rationale"],`$.purpose.intents[${i}]`,t),Le(e)&&void 0!==e.strength&&ze(e,"strength",`$.purpose.intents[${i}]`,["primary","secondary"],t),Le(e)&&(We(e,"source",`$.purpose.intents[${i}]`,["author","derived","model-proposal","import"],t),Ye(e,"rationale",`$.purpose.intents[${i}]`,t))});for(let i of["allowedUses","prohibitedUses"])je(Be(e.purpose,i,"$.purpose",t),`$.purpose.${i}`,t);We(e.purpose,"stakes","$.purpose",["exploratory","informational","operational","high"],t),Ye(e.purpose,"communicativeAct","$.purpose",t),Ye(e.purpose,"decisionContext","$.purpose",t)}else t.push({path:"$.purpose.intents",message:"Expected an intent array."});else t.push({path:"$.purpose",message:"Expected a purpose object."});Array.isArray(e.claims)?e.claims.forEach((e,i)=>{if(!Le(e))return void t.push({path:`$.claims[${i}]`,message:"Expected a claim object."});Ee(e,["id","text","kind","status","evidenceIds","scope","uncertainty","asOf","supersedes","authoredBy","review","tags"],`$.claims[${i}]`,t),Oe(e,"id",`$.claims[${i}]`,t),ze(e,"kind",`$.claims[${i}]`,["description","observation","aggregation","inference","forecast","simulation","alert","recommendation","normative"],t),ze(e,"status",`$.claims[${i}]`,["supported","provisional","disputed","superseded","retracted","unsupported","unknown"],t),Array.isArray(e.evidenceIds)?e.evidenceIds.some(e=>"string"!=typeof e||!e)&&t.push({path:`$.claims[${i}].evidenceIds`,message:"Expected non-empty string evidence identifiers."}):t.push({path:`$.claims[${i}].evidenceIds`,message:"Expected an evidence identifier array."}),je(Be(e,"supersedes",`$.claims[${i}]`,t),`$.claims[${i}].supersedes`,t),Ye(e,"text",`$.claims[${i}]`,t),Ye(e,"asOf",`$.claims[${i}]`,t),Ne(e,"scope",`$.claims[${i}]`,t),je(Be(e,"tags",`$.claims[${i}]`,t),`$.claims[${i}].tags`,t),void 0!==e.authoredBy&&qe(e.authoredBy,`$.claims[${i}].authoredBy`,t);let r=De(e,"review",`$.claims[${i}]`,t);r&&(Ee(r,["status","reviewer","reviewedAt","rationale"],`$.claims[${i}].review`,t),ze(r,"status",`$.claims[${i}].review`,["proposed","reviewed","approved","rejected"],t),void 0!==r.reviewer&&qe(r.reviewer,`$.claims[${i}].review.reviewer`,t),Ye(r,"reviewedAt",`$.claims[${i}].review`,t),Ye(r,"rationale",`$.claims[${i}].review`,t));let n=De(e,"uncertainty",`$.claims[${i}]`,t);if(n){Ee(n,["kind","lower","upper","confidence","unit","description"],`$.claims[${i}].uncertainty`,t),ze(n,"kind",`$.claims[${i}].uncertainty`,["interval","distribution","qualitative","unknown"],t);for(let e of["lower","upper","confidence"])Re(n,e,`$.claims[${i}].uncertainty`,t);Ye(n,"unit",`$.claims[${i}].uncertainty`,t),Ye(n,"description",`$.claims[${i}].uncertainty`,t)}}):t.push({path:"$.claims",message:"Expected a claim array."}),Array.isArray(e.evidence)?e.evidence.forEach((e,i)=>{if(!Le(e))return void t.push({path:`$.evidence[${i}]`,message:"Expected an evidence object."});Ee(e,["id","role","label","source","fingerprint","dataVersion","observedAt","scope","sample","transformation","generatedClaimId","relationship"],`$.evidence[${i}]`,t),Oe(e,"id",`$.evidence[${i}]`,t),ze(e,"role",`$.evidence[${i}]`,["source-data","external-source","transformation","statistical-test","model-output","human-observation","policy-rule","quality-check"],t);for(let r of["label","fingerprint","dataVersion","observedAt","generatedClaimId"])Ye(e,r,`$.evidence[${i}]`,t);Ne(e,"scope",`$.evidence[${i}]`,t);let r=De(e,"source",`$.evidence[${i}]`,t);if(r){Ee(r,["name","uri","version","retrievedAt","publisher"],`$.evidence[${i}].source`,t);for(let e of["name","uri","version","retrievedAt","publisher"])Ye(r,e,`$.evidence[${i}].source`,t)}let n=De(e,"transformation",`$.evidence[${i}]`,t);if(n){Ee(n,["id","kind","description","inputEvidenceIds","parameters","assumptions","implementation","performedAt","performedBy"],`$.evidence[${i}].transformation`,t),Oe(n,"id",`$.evidence[${i}].transformation`,t),ze(n,"kind",`$.evidence[${i}].transformation`,["aggregation","filter","normalization","binning","join","smoothing","forecasting","simulation","other"],t);let e=Be(n,"inputEvidenceIds",`$.evidence[${i}].transformation`,t);e?je(e,`$.evidence[${i}].transformation.inputEvidenceIds`,t):t.push({path:`$.evidence[${i}].transformation.inputEvidenceIds`,message:"Expected an evidence identifier array."}),je(Be(n,"assumptions",`$.evidence[${i}].transformation`,t),`$.evidence[${i}].transformation.assumptions`,t),Ye(n,"description",`$.evidence[${i}].transformation`,t),Ye(n,"implementation",`$.evidence[${i}].transformation`,t),Ye(n,"performedAt",`$.evidence[${i}].transformation`,t),Ne(n,"parameters",`$.evidence[${i}].transformation`,t),void 0!==n.performedBy&&qe(n.performedBy,`$.evidence[${i}].transformation.performedBy`,t)}let o=De(e,"sample",`$.evidence[${i}]`,t);if(o){Ee(o,["rowCount","fields","values","truncated"],`$.evidence[${i}].sample`,t),je(Be(o,"fields",`$.evidence[${i}].sample`,t),`$.evidence[${i}].sample.fields`,t);let e=Be(o,"values",`$.evidence[${i}].sample`,t);e&&!Fe(e)&&t.push({path:`$.evidence[${i}].sample.values`,message:"Expected JSON values."}),Re(o,"rowCount",`$.evidence[${i}].sample`,t),Ce(o,"truncated",`$.evidence[${i}].sample`,t)}We(e,"relationship",`$.evidence[${i}]`,["descriptive","correlational","causal","unknown"],t)}):t.push({path:"$.evidence",message:"Expected an evidence array."}),Je(e.fieldStatus,t);let n=De(e,"time","$",t);return n&&ot(n,t),Ke(e,t),Ne(e,"extensions","$",t),Array.isArray(e.claims)&&0===e.claims.length&&i.push({path:"$.claims",message:"The contract declares no claims."}),Array.isArray(e.evidence)&&0===e.evidence.length&&i.push({path:"$.evidence",message:"The contract declares no evidence."}),{valid:0===t.length,errors:t,warnings:i}}function lt(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function ct(e,t){if(!t||!lt(e)||!Array.isArray(e.evidence))return[];let i=[];return e.evidence.forEach((e,t)=>{lt(e)&&Object.prototype.hasOwnProperty.call(e,"sample")&&(delete e.sample,i.push(`$.evidence[${t}].sample`))}),i}function ut(e,t={}){try{return dt(e,t)}catch{let t=Ie(e);return{transfer:{status:"invalid",omittedPaths:t.length?t:["$"],warnings:["Artifact contract could not be inspected safely."]}}}}function dt(e,t){if(!lt(e))return{transfer:{status:"invalid",omittedPaths:["artifactContract"],warnings:["Artifact contract must be a JSON object."]}};let i=we(e),r=[.../* @__PURE__ */new Set([...i.excludedPaths,...Ie(e)])].sort(),n=i.value,o=ct(n,t.excludeEvidenceSamples),a=o.length?["Bounded evidence samples were excluded by the transfer policy."]:[],s=n?.contractVersion;if("string"!=typeof s||!s)return{contract:n,transfer:{status:"invalid",omittedPaths:[...r,...o],warnings:["Artifact contract is missing a string contractVersion.",...a]}};if("0.1"!==s)return{contract:n,transfer:{status:r.length>0?"invalid":"unsupported-version",omittedPaths:[...r,...o],warnings:[`Contract version ${s} is not interpreted by this runtime.`,...r.length>0?[`Non-JSON values could not be preserved at: ${r.join(", ")}.`]:[],...a]}};let l=at(n),c=[...l.errors.map(({path:e,message:t})=>`${e}: ${t}`),...l.warnings.map(({path:e,message:t})=>`${e}: ${t}`),...r.length?[`Non-JSON values could not be preserved at: ${r.join(", ")}.`]:[],...a];return{contract:n,transfer:{status:!l.valid||r.length>0?"invalid":o.length>0?"excluded":"preserved",omittedPaths:[...r,...o],warnings:c}}}var ht=/* @__PURE__ */new Set(["data","nodes","edges","points","areas","lines","flows","atlas","forest","circuit","edition","reading"]);function ft(e,t){return ht.has(e)&&!("reading"===e&&"string"==typeof t)}function pt(e){let t=Object.entries(e).filter(([e,t])=>ft(e,t)&&void 0!==t);if(0!==t.length)return 1===t.length&&"data"===t[0][0]?t[0][1]:Object.fromEntries(t)}function gt(e,t=[]){if(void 0===e)return;let i=t.filter(e=>!!e.transformation).map(({id:e,transformation:t})=>({evidenceId:e,transformation:t})).sort(({evidenceId:e},{evidenceId:t})=>e<t?-1:e>t?1:0);return ke(i.length>0?{data:e,transformations:i}:e).fingerprint}function mt(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>!ft(e,t)&&"recipeId"!==e))}function yt(e,t,i,r=pt(t)){let n=mt(t),o=0===Ie(n).length?ke(n).fingerprint:void 0,a=void 0!==r&&0===Ie(r).length?gt(r,e.evidence):void 0,s="ChartRecipe"===i&&"string"==typeof t.recipeId?t.recipeId:i,l=[],c=[];return void 0!==s&&(void 0===e.artifact.component?c.push("artifact.component"):e.artifact.component!==s&&l.push("artifact.component")),void 0===e.artifact.configFingerprint||void 0===o?c.push("artifact.configFingerprint"):e.artifact.configFingerprint!==o&&l.push("artifact.configFingerprint"),void 0!==e.artifact.dataFingerprint&&a?e.artifact.dataFingerprint!==a&&l.push("artifact.dataFingerprint"):c.push("artifact.dataFingerprint"),{status:l.length>0?"mismatch":c.length>0?"unknown":"match",mismatchPaths:l,unknownPaths:c}}function xt(e,t){return ce({kind:"semiotic.rendered-svg-scene",version:2,svg:e,frameType:t.frameType,width:t.width,height:t.height,margin:t.margin,plot:t.plot,xDomain:t.xDomain,yDomain:t.yDomain,categories:t.categories})}function bt(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function vt(e){if(!("number"!=typeof e.height||e.height<=0))return e.width>=e.height?"landscape":"portrait"}function wt(e){if(!("number"!=typeof e.height||e.height<=0))return e.width/e.height}function kt(e,t){let{when:i}=e,r=t.width,n=t.height,o=wt(t),a=vt(t);return!("number"==typeof i.minWidth&&r<i.minWidth||"number"==typeof i.maxWidth&&r>i.maxWidth||"number"==typeof i.minHeight&&("number"!=typeof n||n<i.minHeight)||"number"==typeof i.maxHeight&&("number"!=typeof n||n>i.maxHeight)||"number"==typeof i.minAspectRatio&&("number"!=typeof o||o<i.minAspectRatio)||"number"==typeof i.maxAspectRatio&&("number"!=typeof o||o>i.maxAspectRatio)||i.orientation&&a!==i.orientation)}function St(e,t){let i={...e,...t};for(let r of["margin","frameProps","mobileSemantics","style"])bt(e[r])&&bt(t[r])&&(i[r]={...e[r],...t[r]});return"string"==typeof e.className&&"string"==typeof t.className&&(i.className=`${e.className} ${t.className}`),i}function At(e,t,i=e.responsiveRules){if(!Array.isArray(i)||0===i.length)return{props:e,matches:[]};let r=i.map((e,t)=>({rule:e,index:t})).filter(e=>kt(e.rule,t)).sort((e,t)=>("number"==typeof e.rule.priority?e.rule.priority:e.index)-("number"==typeof t.rule.priority?t.rule.priority:t.index));return{props:r.reduce((e,t)=>St(e,t.rule.transform),e),matches:r}}var Mt={enabled:!0,tapToSelect:!0,tapToLockTooltip:!0,clearSelection:"backgroundTap",targetSize:44,snap:"nearestDatum",brushHandleSize:44,standardControls:!1,enabled:!1,tapToSelect:!1,tapToLockTooltip:!1};function $t(e,t={}){let i=t.mobileSemantics?.interaction,r="number"==typeof i?.targetSize?i.targetSize:"number"==typeof t.mobileSemantics?.minimumHitTarget?t.mobileSemantics.minimumHitTarget:void 0,n="mobile"===t.mode||"number"==typeof t.width&&t.width<=480,o=!!i||void 0!==r,a=e&&"object"==typeof e?e:void 0;if(!1===e||!1===a?.enabled||void 0===e&&!n&&!o)return Mt;let s=a??{};return{enabled:!0,tapToSelect:s.tapToSelect??!0,tapToLockTooltip:s.tapToLockTooltip??!0,clearSelection:s.clearSelection??"backgroundTap",targetSize:s.targetSize??r??44,snap:s.snap??"nearestDatum",brushHandleSize:s.brushHandleSize??44,standardControls:s.standardControls??!1}}var _t={primary:{width:600,height:400,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:void 0,showLabels:void 0,marginDefaults:{top:50,bottom:60,left:70,right:40}},context:{width:400,height:250,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:10,bottom:10,left:10,right:10}},sparkline:{width:120,height:24,showAxes:!1,showGrid:!1,enableHover:!1,showLegend:!1,showLabels:!1,marginDefaults:{top:2,bottom:2,left:0,right:0}},mobile:{width:390,height:300,showAxes:!0,showGrid:!1,enableHover:!0,showLegend:!1,showLabels:!0,marginDefaults:{top:28,bottom:42,left:44,right:16}}};function It(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(_t,e)}function Pt(e,t,i){let r=_t[e||"primary"],n=e&&"primary"!==e||!i?.width?r.width:i.width,o=e&&"primary"!==e||!i?.height?r.height:i.height,a=At({...t,mode:e},{width:t.width??n,height:t.height??o}).props,s=a.mode||e||"primary",l=_t[s],c="context"===s||"sparkline"===s,u="primary"===s&&i?.width?i.width:l.width,d="primary"===s&&i?.height?i.height:l.height;return{mode:s,width:a.width??u,height:a.height??d,showAxes:a.showAxes??l.showAxes,showGrid:a.showGrid??l.showGrid,enableHover:a.enableHover??(!!a.linkedHover||l.enableHover),showLegend:a.showLegend??l.showLegend,showLabels:a.showLabels??l.showLabels,title:c?void 0:a.title,description:a.description,summary:a.summary,accessibleTable:a.accessibleTable,xLabel:c?void 0:a.xLabel,yLabel:c?void 0:a.yLabel,categoryLabel:c?void 0:a.categoryLabel,valueLabel:c?void 0:a.valueLabel,marginDefaults:Lt(l.marginDefaults,a.showCategoryTicks,a.orientation),compactMode:c,mobileInteraction:$t(a.mobileInteraction,{mode:s,width:a.width??u,mobileSemantics:a.mobileSemantics}),mobileSemantics:a.mobileSemantics}}function Lt(e,t,i){if(!1!==t)return e;let r={...e};return"horizontal"===i?r.left=Math.min(r.left,15):r.bottom=Math.min(r.bottom,15),r}function Rt(e){return e instanceof Date?`date:${e.getTime()}`:`${typeof e}:${String(e)}`}var Ct={kind:"rank-competition"};function Tt(e,t,i,r){let n=e??t;return"function"==typeof n?n(i,r):i[String(n)]}function Nt(e){let t=/* @__PURE__ */new Map;(Array.isArray(e.data)?e.data:[]).forEach((i,r)=>{if(!Number.isFinite(Number(Tt(e.yAccessor,"y",i,r))))return;let n=Rt(Tt(e.xAccessor,"x",i,r)),o=t.get(n)??/* @__PURE__ */new Set;o.add(String(Tt(e.lineBy,"series",i,r))),t.set(n,o)});let i=Array.from(t.values(),e=>e.size).sort((e,t)=>e-t);if(0===i.length)return[];let r=Math.floor(i.length/2),n={columns:i.length,median:i.length%2?i[r]:(i[r-1]+i[r])/2,max:i[i.length-1],contestedColumns:i.filter(e=>e>=2).length},o=n.max<2;return!o&&n.contestedColumns>=2&&n.median>=2?[]:[{code:o?"BUMP_NO_RANK_COMPETITION":"BUMP_SPARSE_RANK_COMPETITION",severity:o?"error":"warning",message:o?"Every ranking column contains one series, so every trajectory remains at rank 1.":"Too few ranking columns contain competing series for reliable rank movement.",fix:"Use a lineBy field with repeated series across shared x columns, or choose a value-based chart.",metrics:{...n}}]}var Ft=/* @__PURE__ */Symbol.for("semiotic.semantic-viability"),Et=globalThis;function Ot(){return Et[Ft]}function zt(e){return Ot()?.has(e)??!1}function Dt(e){return Ot()?.get(e)}function Bt(e){return zt(e)?Dt(e):"BumpChart"===e?Ct:void 0}function jt(e){return"string"==typeof e?.code&&e.code.length>0&&("warning"===e.severity||"error"===e.severity)&&"string"==typeof e.message&&e.message.length>0}function Wt(e,t,i){if(e.semanticDiagnostics=[],e.semanticStatus="not-assessed",e.empty)return;let r,n=Bt(t);if(n){try{let t="function"==typeof n?n(i,e):Nt(i);r=Array.from(t).filter(jt)}catch{return void(e.warnings.includes("SEMANTIC_VIABILITY_CHECK_FAILED")||e.warnings.push("SEMANTIC_VIABILITY_CHECK_FAILED"))}e.semanticDiagnostics=r,e.semanticStatus=r.some(e=>"error"===e.severity)?"degenerate":r.some(e=>"warning"===e.severity)?"degraded":"meaningful";for(let t of r)e.warnings.includes(t.code)||e.warnings.push(t.code)}}function Yt(e){if(null==e)return;if("number"==typeof e)return{top:e,right:e,bottom:e,left:e};let t={};return"number"==typeof e.top&&(t.top=e.top),"number"==typeof e.right&&(t.right=e.right),"number"==typeof e.bottom&&(t.bottom=e.bottom),"number"==typeof e.left&&(t.left=e.left),t}import*as qt from"react-dom/server";var Xt=/^(\d{4})-(\d{1,2})(?:-(\d{1,2}))?$/;function Gt(e){let t=e.trim();if(!t||!Number.isNaN(Number(t)))return NaN;let i=Xt.exec(t);if(i){let e=Number(i[1]),t=Number(i[2])-1,r=Number(i[3]??1),n=/* @__PURE__ */new Date(0);return n.setUTCFullYear(e,t,r),n.getUTCFullYear()===e&&n.getUTCMonth()===t&&n.getUTCDate()===r?n.getTime():NaN}if(t.length<10)return NaN;let r=Date.parse(t);return Number.isFinite(r)?r:NaN}function Vt(e){if(e instanceof Date)return e.getTime();if("number"==typeof e)return Number.isFinite(e)?e:NaN;if("string"!=typeof e||!e.trim())return NaN;let t=e.trim(),i=Number(t);if(!Number.isNaN(i))return Number.isFinite(i)?i:NaN;if(/^\d{4}-\d{1,2}(?:-\d{1,2})?$/.test(t))return Gt(t);let r=/^(\d{4}-\d{2}-\d{2})[Tt ](\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)([Zz]|[+-]\d{2}:?\d{2})?$/.exec(t);return r&&Number.isFinite(Gt(r[1]))?Date.parse(`${r[1]}T${r[2]}${r[3]||"Z"}`):NaN}function Ht(e){return e.some(e=>(e instanceof Date||"string"==typeof e&&Number.isNaN(Number(e)))&&Number.isFinite(Vt(e)))}function Ut(e,t,i){let r="function"==typeof t?t(e):e[String(t??i)];if(null==r||"string"==typeof r&&""===r.trim())return null;let n=Number(r);return Number.isFinite(n)?n:null}function Kt(e,t,i){let r="function"==typeof t?t(e):e[String(t??i)];if(null==r||"string"==typeof r&&""===r.trim())return null;if(r instanceof Date)return Number.isFinite(r.getTime())?r:null;if("string"==typeof r){let e=Gt(r);if(Number.isFinite(e))return new Date(e)}let n=Number(r);return Number.isFinite(n)?n:null}import*as Zt from"react";function Qt({data:e,safeData:t,areaBy:i,lineDataAccessor:r}){if(null==e)return[];let n,o=void 0!==t[0]?.[r];if(!o&&!i)return t;if(o)n=t;else{let e=t.reduce((e,t)=>{let n="function"==typeof i?i(t):t[i],o=String(n);if(!e[o]){let t={[r]:[]};"string"==typeof i&&(t[i]=n),e[o]=t}return e[o][r].push(t),e},{});n=Object.values(e)}return n.flatMap(e=>{let t=Array.isArray(e[r])?e[r]:[];return"string"==typeof i?t.map(t=>({...t,[i]:t[i]??e[i]})):t})}var Jt=Object.freeze([]);function ei(e){if(!e)return Jt;let t=!1;for(let i=0;i<e.length;i++){let r=e[i];if(null==r||"object"!=typeof r){t=!0;break}}if(!t)return e;let i=[];for(let t of e)null!=t&&"object"==typeof t&&i.push(t);return i}import{scaleOrdinal as ti}from"d3-scale";function ii(e){return[parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16)]}function ri(e,t,i){let r=e=>e.toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function ni(e){let t=e.map(ii),i=t.length-1;return e=>{if(Number.isNaN(e)&&(e=0),e<=0){let[e,i,r]=t[0];return ri(e,i,r)}if(e>=1){let[e,r,n]=t[i];return ri(e,r,n)}let r=e*i,n=Math.floor(r),o=r-n,[a,s,l]=t[n],[c,u,d]=t[n+1];return ri(Math.round(a+(c-a)*o),Math.round(s+(u-s)*o),Math.round(l+(d-l)*o))}}var oi=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],ai=/* @__PURE__ */ni(["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]),si=/* @__PURE__ */ni(["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]),li=/* @__PURE__ */ni(["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]),ci=/* @__PURE__ */ni(["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]),ui=/* @__PURE__ */ni(["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]),di=/* @__PURE__ */ni(["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]),hi=/* @__PURE__ */ni(["#440154","#482878","#3e4989","#31688e","#26828e","#1f9e89","#35b779","#6ece58","#b5de2b","#fde725"]),fi={blues:ai,reds:si,greens:li,viridis:hi,oranges:ci,purples:ui,greys:di,plasma:/* @__PURE__ */ni(["#0d0887","#41049d","#6a00a8","#8f0da4","#b12a90","#cb4679","#e16462","#f1844b","#fca636","#fcce25","#f0f921"]),inferno:/* @__PURE__ */ni(["#000004","#160b39","#420a68","#6a176e","#932667","#bc3754","#dd513a","#f3771a","#fca50a","#f6d746","#fcffa4"]),magma:/* @__PURE__ */ni(["#000004","#140e36","#3b0f70","#641a80","#8c2981","#b73779","#de4968","#f7705c","#fe9f6d","#fecf92","#fcfdbf"]),cividis:/* @__PURE__ */ni(["#00224e","#123570","#3b496c","#575d6d","#707173","#8a8678","#a59c74","#c3b369","#e1cc55","#fee838","#ffea46"]),turbo:/* @__PURE__ */ni(["#23171b","#4a58dd","#3f9ee9","#46c7af","#7eed5a","#cdf134","#fbb91f","#f56918","#c52f06","#7a0403"])};function pi(e){return e&&Object.prototype.hasOwnProperty.call(fi,e)?fi[e]:ai}var gi=/* @__PURE__ */ni(["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]),mi=/* @__PURE__ */ni(["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]),yi=/* @__PURE__ */ni(["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]),xi=/* @__PURE__ */ni(["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]),bi=/* @__PURE__ */ni(["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]),vi=/* @__PURE__ */ni(["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]),wi=/* @__PURE__ */ni(["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]),ki={category10:oi,tableau10:["#4e79a7","#f28e2c","#e15759","#76b7b2","#59a14f","#edc949","#af7aa1","#ff9da7","#9c755f","#bab0ab"],set3:["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"],...fi},Si=oi,Ai="#007bff";function Mi(e,t,i=Si){if(e&&"object"==typeof e&&!Array.isArray(e)){let t=Object.values(e).filter(e=>"string"==typeof e&&e.length>0);if(t.length>0)return t}if(Array.isArray(e)&&e.length>0)return e;if("string"==typeof e){let t=Object.prototype.hasOwnProperty.call(ki,e)?ki[e]:void 0;if(Array.isArray(t)&&t.length>0)return t}return t&&t.length>0?t:i}var $i=["#4e79a7","#f28e2b","#e15759","#76b7b2","#59a14f","#edc948","#b07aa1","#ff9da7","#9c755f","#bab0ac"],_i=["#f0f0f0","#b5d4ea","#f4c2a1","#b8dab2","#d4b5e0","#f9e0a2","#a8d8d8"],Ii=/* @__PURE__ */new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","transparent","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);function Pi(e){let t=e.toLowerCase();return t.startsWith("#")||t.startsWith("rgb")||t.startsWith("hsl")||Ii.has(t)}function Li(e,t,i){if("function"==typeof t){let r=t(e);return i&&r&&"string"==typeof r&&!Pi(r)?i(r):r}let r=String(e?.[t]);return i?i(r):Si[Math.abs(Ti(r))%Si.length]}function Ri(e,t){if(null==t||!Object.prototype.hasOwnProperty.call(e,t))return;let i=e[t];return"string"==typeof i&&i.length>0?i:void 0}function Ci(e,t,i="category10"){if(i&&"object"==typeof i&&!Array.isArray(i)){let e=i;return t=>Ri(e,t)??"#999"}let r=Array.from(new Set(e.map(e=>e?.[t]).filter(e=>null!=e).map(e=>String(e)))),n=r.every(e=>!isNaN(Number(e)));if(Array.isArray(i))return ti().domain(r).range(i).unknown("#999");let o=Object.prototype.hasOwnProperty.call(ki,i)?ki[i]:ki.category10;if(n&&"function"==typeof o){let e=-1/0;for(let t of r){let i=Number(t);i>e&&(e=i)}return t=>o(0===e?0:Number(t)/e)}{let e=Array.isArray(o)?o:Si;return ti().domain(r).range(e).unknown("#999")}}function Ti(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i),t&=t;return Math.abs(t)}function Ni(e,t,i=[3,20],r){let n;if(n="function"==typeof t?t(e):e?.[t],!r)return n;let[o,a]=r,[s,l]=i;if(a===o)return(s+l)/2;let c=(n-o)/(a-o);return c<0?c=0:c>1&&(c=1),s+c*(l-s)}function Fi(e,t,i,r,n){if(e)return e;if(i&&"object"==typeof i&&!Array.isArray(i)){let e=Ri(i,r);if(e)return e}let o;if(Array.isArray(i))o=i;else if(t&&t.length>0)o=t;else if("string"==typeof i){let e=ki[i];Array.isArray(e)&&(o=e)}return o&&0!==o.length?null!=r?(n.has(r)||n.set(r,n.size),o[n.get(r)%o.length]):o[0]:Ai}function Ei(e){return void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity}function Oi(e,t){if(!Ei(t))return e??((...e)=>({}));let i={};return void 0!==t.stroke&&(i.stroke=t.stroke),void 0!==t.strokeWidth&&(i.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(i.opacity=t.opacity),e?(...t)=>({...e(...t)||{},...i}):(...e)=>({...i})}function zi(e){if(null==e)return()=>{};let t="function"==typeof e?e:t=>t[e];return e=>ji(t(e))}function Di(e,t){let i=zi(e),r=zi(t);return(e,t)=>{let n=r(e);return{value:n,x:i(e),y:n,category:t}}}function Bi(e,t){let i=zi(t??"value"),r=null==e?void 0:"function"==typeof e?e:t=>t[e];return e=>{let t=r?r(e):void 0;return{value:i(e),category:null==t?void 0:String(t)}}}function ji(e){if("number"==typeof e)return Number.isFinite(e)?e:void 0;if("string"==typeof e&&""!==e.trim()){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Wi(e,t,i){let r=null!=e.axis?i[e.axis]:null!=e.field?t[e.field]:i.value;if(void 0!==e.eq&&r!==e.eq||void 0!==e.ne&&r===e.ne||void 0!==e.in&&!e.in.includes(r))return!1;if(void 0===e.gt&&void 0===e.gte&&void 0===e.lt&&void 0===e.lte&&void 0===e.within&&void 0===e.outside)return!0;let n=ji(r);if(!(void 0!==n&&(void 0===e.gt||n>e.gt)&&(void 0===e.gte||n>=e.gte)&&(void 0===e.lt||n<e.lt)&&(void 0===e.lte||n<=e.lte)))return!1;if(void 0!==e.within){let[t,i]=e.within;if(!(n>=t&&n<=i))return!1}if(void 0!==e.outside){let[t,i]=e.outside;if(!(n<t||n>i))return!1}return!0}function Yi(e,t,i){let r=e.when;return void 0===r||!0===r||!1!==r&&("function"==typeof r?r(t,i):Wi(r,t,i))}function qi(e,t,i){if(!t||0===t.length)return{};let r={};for(let n of t){if(!Yi(n,e,i))continue;let t="function"==typeof n.style?n.style(e,i):n.style;t&&(r={...r,...t})}return r}function Xi(e,t,i,r=e=>e){let n=e??(()=>({}));return t&&0!==t.length?(e,o)=>{let a=r(e),s={...n(e,o)};return Object.assign(s,qi(a,t,i(a,o))),s}:n}function Gi(e,t,i,r){if(!e||0===e.length)return r;let n=Bi(t,i);return(t,i)=>{let o=t&&t.data||t,a=qi(o,e,n(o)),s=r?r(t,i):void 0;return s?{...a,...s}:a}}function Vi(e){let{lineWidth:t=2,colorBy:i,colorScale:r,color:n,resolveStroke:o,fillArea:a,areaOpacity:s=.3,styleRules:l,ruleContext:c}=e;return(e,u)=>{let d,h={strokeWidth:t},f=!0===a||Array.isArray(a)&&null!=u&&a.includes(u);return o?d=o(e,u):i?r&&(d=Li(e,i,r)):d=n||Ai,void 0!==d&&(h.stroke=d,f&&(h.fill=d,h.fillOpacity=s)),l?.length&&Object.assign(h,qi(e,l,c?c(e,u):{value:void 0,category:u})),h}}function Hi(e,t,i,r){if(!e.length)return[];let n=e.filter(e=>Number.isFinite(t(e))).sort((e,i)=>t(e)-t(i)),o=[],a=0,s=null,l=null,c=[],u=(e,t)=>e>t?"A":t>e?"B":null,d=e=>`seg-${a}-${e}`,h=e=>o.push(e),f=(e,t)=>{h({__x:e.x,__y:e.y,__y0:e.y,__diffSegment:d(t),__diffWinner:t,__valA:e.y,__valB:e.y,__sourceDatum:e.datum})};for(let e=0;e<n.length;e++){let o=n[e],p=t(o),g=i(o),m=r(o);if(!Number.isFinite(p)||!Number.isFinite(g)||!Number.isFinite(m))continue;let y=u(g,m);if(null!==y){if(null==s){s=y;for(let e of c)f(e,s);c=[],h({__x:p,__y:g>=m?g:m,__y0:g>=m?m:g,__diffSegment:d(s),__diffWinner:s,__valA:g,__valB:m,__sourceDatum:o}),l={x:p,a:g,b:m,w:y};continue}if(l&&l.w!==y){let e,t;if(c.length>0)e=c[0].x,t=c[0].y;else{let i=g-l.a-(m-l.b);if(0!==i){let r=(l.b-l.a)/i,n=Math.max(0,Math.min(1,r));e=l.x+n*(p-l.x),t=l.a+n*(g-l.a)}else e=l.x,t=l.a}h({__x:e,__y:t,__y0:t,__diffSegment:d(s),__diffWinner:s,__valA:t,__valB:t}),a++,s=y,h({__x:e,__y:t,__y0:t,__diffSegment:d(s),__diffWinner:s,__valA:t,__valB:t});for(let e=1;e<c.length;e++)f(c[e],s)}else for(let e of c)f(e,s);c=[],h({__x:p,__y:g>=m?g:m,__y0:g>=m?m:g,__diffSegment:d(s),__diffWinner:s,__valA:g,__valB:m,__sourceDatum:o}),l={x:p,a:g,b:m,w:y}}else c.push({x:p,y:g,datum:o})}for(let e of c)f(e,s??"A");return o}function Ui(e){if("A"===e.__diffWinner||"B"===e.__diffWinner)return e.__diffWinner;let t=String(e.__diffSegment??"");return"line-A"===t||t.endsWith("-A")?"A":"B"}function Ki(e,t){return Xi(e,t,e=>{let t=Number(e.__x),i=Number(e.__y);return{value:Number.isFinite(i)?i:void 0,x:Number.isFinite(t)?t:void 0,y:Number.isFinite(i)?i:void 0,category:Ui(e)}},e=>e.__sourceDatum?{...e.__sourceDatum,...e}:e)}function Zi(e){let{seriesAColor:t,seriesBColor:i,areaOpacity:r,styleRules:n}=e;return Ki(e=>({fill:"A"===Ui(e)?t:i,stroke:"none",fillOpacity:r}),n)}function Qi(e){let{seriesAColor:t,seriesBColor:i,lineWidth:r,styleRules:n}=e;return Ki(e=>({stroke:"A"===Ui(e)?t:i,strokeWidth:r,fill:"none"}),n)}var Ji={stops:[{offset:0,opacity:.8},{offset:1,opacity:.05}]};function er(e,t=Ji){if(e)return!0===e?t:"stops"in e?Array.isArray(e.stops)?e:void 0:"colorStops"in e?Array.isArray(e.colorStops)?{stops:e.colorStops.map(({offset:e,color:t})=>({offset:e,color:t}))}:void 0:{stops:[{offset:0,opacity:e.topOpacity??t.stops[0]?.opacity??.8},{offset:1,opacity:e.bottomOpacity??t.stops.at(-1)?.opacity??.05}]}}function tr(e){return e?er(e):void 0}function ir(e){if(e)return Array.isArray(e)?{stops:e.map(({at:e,color:t,opacity:i})=>({offset:e/100,color:t,...null!=i&&{opacity:i}}))}:Array.isArray(e.stops)?e:void 0}function rr(e){let t=e?.stops.filter(e=>"string"==typeof e.color&&Number.isFinite(e.offset)).map(({offset:e,color:t,opacity:i})=>({offset:Math.max(0,Math.min(1,e)),color:t,...Number.isFinite(i)&&{opacity:Math.max(0,Math.min(1,i))}})).sort((e,t)=>e.offset-t.offset);if(!t?.length)return;let i=t[0];return i.offset>0?[{...i,offset:0},...t]:t}function nr(e){return{...e.extent&&{extent:e.extent},stops:e.stops.map(e=>({...e,offset:1-e.offset})).sort((e,t)=>e.offset-t.offset)}}function or(e){return{...nr(e),extent:"domain"}}function ar(e){if(!e)return;let t="boolean"==typeof e?{}:"string"==typeof e?{method:e}:e;return{type:"trend",method:t.method??"linear",...null!=t.bandwidth&&{bandwidth:t.bandwidth},...null!=t.order&&{order:t.order},...null!=t.color&&{color:t.color},...null!=t.strokeWidth&&{strokeWidth:t.strokeWidth},...null!=t.strokeDasharray&&{strokeDasharray:t.strokeDasharray},...null!=t.label&&{label:t.label}}}function sr(e,t,i){return"function"==typeof e?e(i):i[e||t]}function lr(e){return e instanceof Date?e.getTime():Number(e)}function cr(e,t){return hi(1===t?.5:e/(t-1))}function ur(e){let t={};return void 0!==e.stroke&&(t.stroke=e.stroke),void 0!==e.strokeWidth&&(t.strokeWidth=e.strokeWidth),void 0!==e.opacity&&(t.opacity=e.opacity),t}function dr(e,t){let i=ar(t),r=Array.isArray(e)?e:void 0;return i?[i,...r??[]]:r}function hr(e,t){if(!Array.isArray(e))return{data:e,orderMap:/* @__PURE__ */new WeakMap};let i=t.xAccessor||"x",r=t.yAccessor||"y",n=t.orderAccessor?[...e].sort((e,i)=>null==e||"object"!=typeof e?1:null==i||"object"!=typeof i?-1:lr(sr(t.orderAccessor,"order",e))-lr(sr(t.orderAccessor,"order",i))):e,o=/* @__PURE__ */new WeakMap,a=0;for(let e of n){if(null==e||"object"!=typeof e)continue;let t=lr(sr(i,"x",e)),n=lr(sr(r,"y",e));Number.isFinite(t)&&Number.isFinite(n)&&a++}let s=0;for(let e of n){if(null==e||"object"!=typeof e)continue;let t=lr(sr(i,"x",e)),n=lr(sr(r,"y",e));Number.isFinite(t)&&Number.isFinite(n)&&o.set(e,{idx:s++,total:a})}return{data:n,orderMap:o}}function fr(e){if(!e.axes)return[{orient:"bottom",visible:!1!==e.showTimeAxis},{orient:"left",visible:!1!==e.showValueAxis}];let t=(...t)=>e.axes.some(e=>t.includes(e.orient)),i=!1===e.showTimeAxis&&!t("bottom","top"),r=!1===e.showValueAxis&&!t("left","right");return i||r?[...e.axes,...i?[{orient:"bottom",visible:!1}]:[],...r?[{orient:"left",visible:!1}]:[]]:e.axes}function pr(e,t,i,r=!1){let n=q({axes:t,showAxes:i});return{...Q(e,t,r),...!n.hasAxis&&{bottom:0},...!n.leftAxis?.hasAxis&&{left:0}}}function gr(e,t,i="x",r="y"){let n="function"==typeof i?i:e=>e[i],o="function"==typeof r?r:e=>e[r],a="function"==typeof t.colorBy?t.colorBy:e=>e[t.colorBy],s=/* @__PURE__ */new Map;for(let i of e){let e=a(i)??(i.parentLine&&a(i.parentLine));if(null==e||""===String(e))continue;let r=String(e),o=s.get(r);(!o||("end"===t.position?Number(n(i))>Number(n(o)):Number(n(i))<Number(n(o))))&&s.set(r,i)}return[...s].map(([e,a])=>({type:"text",label:e,["string"==typeof i?i:"x"]:n(a),["string"==typeof r?r:"y"]:o(a),x:n(a),y:o(a),_directLabel:{id:e,position:t.position},color:t.color(e),fontSize:t.fontSize}))}function mr(e=[]){let t=e.filter(e=>e._directLabel);return t.length?` Series endpoints: ${t.map(e=>`${e.label}: x ${String(e.x)}, y ${String(e.y)}`).join("; ")}.`:""}function yr(e){let t=1/0,i=-1/0;for(let r of e)r<t&&(t=r),r>i&&(i=r);return[t,i]}function xr(e,t=1/0){let i=t;for(let t of e)t<i&&(i=t);return i}function br(e,t=-1/0){let i=t;for(let t of e)t>i&&(i=t);return i}function vr(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)*(1-t)),n=Math.round(parseInt(i[2],16)*(1-t)),o=Math.round(parseInt(i[3],16)*(1-t));return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function wr(e,t=.5){let i=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(!i)return e;let r=Math.round(parseInt(i[1],16)+(255-parseInt(i[1],16))*t),n=Math.round(parseInt(i[2],16)+(255-parseInt(i[2],16))*t),o=Math.round(parseInt(i[3],16)+(255-parseInt(i[3],16))*t);return`#${r.toString(16).padStart(2,"0")}${n.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function kr(e){return e instanceof Date&&(e=e.getTime()),"string"==typeof e&&""!==e.trim()&&(e=Number(e)),"number"==typeof e&&Number.isFinite(e)?e:null}function Sr(e){let t=[];for(let[i,r]of e){let e=kr(i),n=kr(r);null!==e&&null!==n&&t.push([e,n])}return t.sort((e,t)=>e[0]-t[0])}function Ar(){return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN}}function Mr(e){let t=Sr(e);if(!t.length)return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN};let i=t[0][0],r=t.reduce((e,[r])=>e+(r-i)/t.length,0),n=t.reduce((e,[,i])=>e+i/t.length,0),o=0,a=0;for(let[e,s]of t){let t=e-i-r;o+=t*t,a+=t*(s-n)}let s=0===o?0:a/o,l=e=>n+s*(e-i-r);return{points:t.map(([e])=>[e,l(e)]),parameterCount:2,leverage:e=>1/t.length+(o>0?(e-i-r)**2/o:0),predict:l}}function $r(e,t=2){let i=Sr(e);if(!Number.isInteger(t)||t<0||t>=i.length)return{points:[],parameterCount:0,predict:()=>NaN,leverage:()=>NaN};let r=i[0][0]/2+i[i.length-1][0]/2,n=Math.max(Math.abs(i[0][0]-r),Math.abs(i[i.length-1][0]-r))||1,o=i.map(([e])=>(e-r)/n),a=[],s=Array.from({length:t+1},()=>Array(t+1).fill(0));for(let e=0;e<=t;e++){let t=o.map(t=>t**e);for(let i=0;i<2;i++)for(let i=0;i<e;i++){let r=t.reduce((e,t,r)=>e+t*a[i][r],0);s[i][e]+=r;for(let e=0;e<t.length;e++)t[e]-=r*a[i][e]}let r=Math.sqrt(t.reduce((e,t)=>e+t*t,0));if(!Number.isFinite(r)||r<=Number.EPSILON*i.length)return Ar();s[e][e]=r,a.push(t.map(e=>e/r))}let l=a.map(e=>e.reduce((e,t,r)=>e+t*i[r][1],0));for(let e=t;e>=0;e--){for(let i=e+1;i<=t;i++)l[e]-=s[e][i]*l[i];l[e]/=s[e][e]}let c=e=>{let i=(e-r)/n,o=0;for(let e=t;e>=0;e--)o=o*i+l[e];return o};return{points:i.map(([e])=>[e,c(e)]),parameterCount:t+1,predict:c,leverage:e=>{let i=(e-r)/n,o=[];for(let e=0;e<=t;e++){let t=i**e;for(let i=0;i<e;i++)t-=s[i][e]*o[i];o.push(t/s[e][e])}return o.reduce((e,t)=>e+t*t,0)}}}function _r(e,t,i=2){let r=e.length,n=e.reduce((e,[i,r])=>e+(r-t(i))**2,0);return{se:Math.sqrt(n/Math.max(r-i,1))}}function Ir(e){return e>=.99?2.576:e>=.95?1.96:e>=.9?1.645:1}import{scaleLinear as Pr}from"d3-scale";function Lr(e,t=.3){if(!Number.isFinite(t)||t<0||t>1)return[];let i=Sr(e),r=i.length;if(r<2)return i;let n=i.map(e=>e[0]),o=i.map(e=>e[1]),a=0,s=Math.min(r,Math.max(2,Math.ceil(t*r)))-1,l=[];for(let e=0;e<r;e++){let t=n[e],i=0,c=r-1;for(;s<r-1&&Math.abs(n[s+1]-t)<=Math.abs(n[a]-t);)a++,s++;let u=Math.max(Math.abs(n[a]-t),Math.abs(n[s]-t)),d=u||1;u>0&&(i=a,c=s);let h=0,f=0,p=0,g=0,m=0;for(let e=i;e<=c;e++){let i=Math.abs(n[e]-t)/d,r=i<1?Math.pow(1-Math.pow(i,3),3):0;if(0===r)continue;h+=r;let a=(n[e]-t)/d;f+=r*a,p+=r*o[e],g+=r*a*a,m+=r*a*o[e]}if(0===h){l.push([t,o[e]]);continue}let y=h*g-f*f;if(Math.abs(y)<1e-12)l.push([t,p/h]);else{let e=(p-(h*m-f*p)/y*f)/h;l.push([t,e])}}return l}function Rr(e,t=.3){let i=new Map(Lr(e,t));return i.size<2?null:Pr().domain([...i.keys()]).range([...i.values()])}function Cr(e,t){if(e.length<3||e[0][0]===e[e.length-1][0])return null;let i="polynomial"===t.method?$r(e,t.order??2):Mr(e);if(!i.points.length)return null;let r="loess"===t.method?Rr(e,t.bandwidth):i.predict;if(!r)return null;let{se:n}=_r(e,r,i.parameterCount),o=Ir(t.confidence??.95),a=e[e.length-1][0],s=(a-e[0][0])/(e.length-1);return{predict:r,forecast:(e,t=a)=>!Number.isInteger(e)||e<=0?[]:Array.from({length:e},(e,a)=>{let l=t+(a+1)*s,c=r(l),u=n*o*Math.sqrt(1+i.leverage(l));return{x:l,y:c,upper:c+u,lower:c-u}})}}var Tr="__forecastSegment",Nr="__forecastOpacity";function Fr(e,t,i,r){let n=t.uncertaintyOpacity,o=t.confidenceAccessor;if(!n&&!o)return;let a="object"==typeof n?n:{},s=a.min??.15,l=a.max??1;if(o){let t="function"==typeof o?o:e=>e[o];for(let i of e){let e=t(i);if(null!=e&&Number.isFinite(e)){let t=Math.max(0,Math.min(1,e));i[Nr]=s+t*(l-s)}}return}let c=e.map(e=>{let t=i(e),n=r(e);return null!=t&&null!=n&&Number.isFinite(t)&&Number.isFinite(n)?Math.abs(t-n):NaN}),u=c.filter(e=>Number.isFinite(e));if(0===u.length)return;let[d,h]=yr(u),f=h-d;e.forEach((e,t)=>{let i=c[t];if(!Number.isFinite(i))return;let r=f>0?(i-d)/f:0;e[Nr]=l-r*(l-s)})}function Er(e,t){return"function"==typeof t?t(e):!!e[t]}function Or(e){return[{type:"anomaly-band",threshold:e.threshold??2,showBand:!1!==e.showBand,fill:e.bandColor||"#6366f1",fillOpacity:e.bandOpacity??.1,anomalyColor:e.anomalyColor||"#ef4444",anomalyRadius:e.anomalyRadius??6,label:e.label}]}function zr(e,t,i,r,n){let{isTraining:o,isForecast:a,isAnomaly:s,upperBounds:l,lowerBounds:c,color:u="#6366f1",bandOpacity:d=.15,anomalyColor:h="#ef4444",anomalyRadius:f=6,label:p}=r,g=e.map(e=>{let t="observed";return a&&Er(e,a)?t="forecast":o&&Er(e,o)&&(t="training"),{...e,[Tr]:t}}),m=[];for(let e=0;e<g.length;e++)m.push(g[e]),e<g.length-1&&g[e][Tr]!==g[e+1][Tr]&&(m.push({...g[e+1],[Tr]:g[e][Tr]}),m.push({...g[e],[Tr]:g[e+1][Tr]}));if(r.trainUnderline){let e=[];for(let t of m)"training"===t[Tr]&&e.push({...t,[Tr]:"training-base"});m.unshift(...e)}let y=[];if(l&&c){let e="string"==typeof l?l:"__envUpper",t="string"==typeof c?c:"__envLower";if("function"==typeof l||"function"==typeof c)for(let i of m)"function"==typeof l&&(i[e]=l(i)),"function"==typeof c&&(i[t]=c(i));y.push({type:"envelope",upperAccessor:e,lowerAccessor:t,fill:u,fillOpacity:d,label:p})}if(r.uncertaintyOpacity||r.confidenceAccessor){let e=l?"function"==typeof l?l:e=>e[l]:()=>{},t=c?"function"==typeof c?c:e=>e[c]:()=>{};Fr(m.filter(e=>"forecast"===e[Tr]),r,e,t)}if(s){let e=r.anomalyStyle,t={type:"highlight",filter:e=>Er(e,s)};e?(t.style=e,t.r=f):"function"==typeof h?(t.style=e=>{let t=h(e);return{stroke:t,strokeWidth:1.5,fill:t,fillOpacity:.7}},t.r=f):(t.color=h,t.r=f,t.style={stroke:h,strokeWidth:1.5,fill:h,fillOpacity:.7}),y.push(t)}return n&&y.push(...Or(n)),{processedData:m,annotations:y}}function Dr(e,t,i,r,n){let{trainEnd:o,steps:a=10,color:s="#6366f1",bandOpacity:l=.15,label:c}=r;if(null===kr(o))return{processedData:e,annotations:[]};let u=[],d=[];for(let i of[...e].sort((e,i)=>(kr(e[t])??1/0)-(kr(i[t])??1/0))){let e=kr(i[t]);null!==e&&e<=o?u.push({...i,[Tr]:"training"}):d.push({...i,[Tr]:"observed"})}let h=Sr(u.map(e=>[e[t],e[i]])),f=[],p=[];if(h.length>=3&&Number.isInteger(a)&&a>0){let n=Cr(h,r);if(n){let o=br(e.map(e=>kr(e[t])).filter(e=>null!==e)),h=e.some(e=>e[t]instanceof Date);for(let{x:e,y:r,upper:s,lower:l}of n.forecast(a,o))p.push({...d[d.length-1]??u[u.length-1],[t]:h?new Date(e):e,[i]:r,[Tr]:"forecast",__forecastUpper:s,__forecastLower:l});Fr(p,r,e=>e.__forecastUpper,e=>e.__forecastLower),f.push({type:"envelope",upperAccessor:"__forecastUpper",lowerAccessor:"__forecastLower",fill:s,fillOpacity:l,label:c})}}f.push({type:"x-threshold",x:o,color:"#94a3b8",strokeWidth:1,strokeDasharray:"4,2",label:"Train / Forecast"}),n&&f.push(...Or(n));let g=[];if(g.push(...u),u.length>0&&d.length>0&&g.push({...u[u.length-1],[Tr]:"observed"}),g.push(...d),p.length>0){let e=d.length>0?d[d.length-1]:u[u.length-1];e&&g.push({...e,[Tr]:"forecast"}),g.push(...p)}return{processedData:g,annotations:f}}function Br(e){return!!(e.isTraining||e.isForecast||e.isAnomaly||e.upperBounds||e.lowerBounds)}function jr(e,t,i,r,n){let o=r._groupBy;if(o&&e.length){let a="function"==typeof o?o:e=>e[o],s=/* @__PURE__ */new Map;for(let t of e){let e=a(t),i=s.get(e);i?i.push(t):s.set(e,[t])}let l=[],c=[];for(let[e,o]of s){let s=jr(o,t,i,{...r,_groupBy:void 0},n);for(let e of s.processedData)l.push(e);for(let t of s.annotations)if("x-threshold"===t.type)c.some(e=>"x-threshold"===e.type)||c.push(t);else{let i=t.filter;c.push({...t,filter:t=>{let r=a(t);return(r===e||Object.is(r,e))&&(!i||i(t))}})}}return{processedData:l,annotations:c}}return Br(r)?zr(e,0,0,r,n):Dr(e,t,i,r,n)}function Wr(e,t){let i=t.trainDasharray??"8,4",r=t.forecastDasharray??"4,4",n=t.color||"#6366f1",o=t.trainOpacity,a=t.forecastOpacity,s=t.trainStroke,l=t.trainLinecap,c=t.trainUnderline;return t=>{let u=e(t),d=t[Tr];if("training"===d){let e=u.stroke;return"darken"===s?e=vr(u.stroke||"#666",.5):s&&(e=s),{...u,stroke:e,strokeDasharray:i,...l&&{strokeLinecap:l},...null!=o&&{strokeOpacity:o}}}if("training-base"===d){let e=u.stroke||"#666";return"lighten"===c&&(e=wr(e,.4)),{...u,stroke:e,strokeDasharray:void 0}}if("forecast"===d){let e=t[Nr]??a;return{...u,stroke:n,strokeDasharray:r,...null!=e&&{strokeOpacity:e}}}return u}}function Yr(e,t,i){if(!i)return;let r=[t,i.upperBounds??"__forecastUpper",i.lowerBounds??"__forecastLower"].map(e=>"function"==typeof e?e:t=>t[e]),n=!(!i.upperBounds&&!i.lowerBounds),o=1/0,a=-1/0;for(let t of e){let e=r[1](t),i=r[2](t);(null!=e||null!=i)&&(n=!0);for(let n of[Number(r[0](t)),e,i])"number"==typeof n&&Number.isFinite(n)&&(o=Math.min(o,n),a=Math.max(a,n))}return n&&o<=a?[o,a]:void 0}var qr="__semiotic_resolvedX",Xr="__semiotic_resolvedY",Gr="__compoundGroup";function Vr(e,t,i){let r="function"==typeof t,n="function"==typeof i,o=r?qr:t,a=n?Xr:i;return r||n?{xKey:o,yKey:a,rows:e.map(e=>{let o={...e};return r&&(o[qr]=t(e)),n&&(o[Xr]=i(e)),o})}:{rows:e,xKey:o,yKey:a}}function Hr(e,t,i){let r=e[t],n=e[i];return null==r||null==n||Number.isNaN(r)||Number.isNaN(n)}function Ur(e,t,i,r,n){let o=/* @__PURE__ */new Map;for(let t of e){let e=n?String(t[n]??""):"__single";o.has(e)||o.set(e,[]),o.get(e).push(t)}if("interpolate"===t){let e=[];for(let[,t]of o)for(let n of t)Hr(n,i,r)||e.push(n);return{rows:e,groupKey:n}}if("zero"===t){let e=[];for(let[,t]of o)for(let n of t)Hr(n,i,r)?e.push({...n,[r]:0}):e.push(n);return{rows:e,groupKey:n}}let a=[],s="_gapSegment";for(let[e,t]of o){let n=0,o=[],l=()=>{if(0===o.length)return;let t="__single"===e?`__seg${n}`:`${e}__seg${n}`;for(let e of o)a.push({...e,[s]:t});o=[],n++};for(let e of t)Hr(e,i,r)?l():o.push(e);l()}return{rows:a,groupKey:s}}function Kr(e,t,i,r,n,o,a,s){if(!t||!i)return{annotations:[]};let l="object"==typeof t?t:{},c=l.position||"end",u=l.fontSize||11,d="function"==typeof i?i:e=>e[i],h=Ci(e.map(e=>({__lbl:String(d(e)??"")})),"__lbl",o??a),f=gr(e,{position:c,fontSize:u,colorBy:i,color:e=>h?h(e):s||Ai},r,n),p=f.reduce((e,t)=>Math.max(e,Array.from(String(t.label)).length*(.65*u)),0)+10;return{annotations:f,marginExtra:"end"===c?{right:p}:{left:p}}}function Zr(e){let t=e.xAccessor||"x",i=e.yAccessor||"y",r=e.lineBy,n=e.colorBy||r,o=Array.isArray(e.data)?ei(e.data).filter(e=>!!e&&"object"==typeof e):[],a=Vr(o,t,i);o=a.rows;let s,l,c=a.xKey,u=a.yKey,d=Array.isArray(e.annotations)?[...e.annotations]:[],h="string"==typeof r||"function"==typeof r?r:void 0,f=e.baseLineStyle;if(e.forecast){let t=jr(o,c,u,!r||"string"!=typeof r&&"function"!=typeof r?e.forecast:{...e.forecast,_groupBy:r},e.anomaly);if(o=t.processedData,d.push(...t.annotations),s=Yr(o,u,e.forecast),!r||"string"!=typeof r&&"function"!=typeof r?h=Tr:(o=o.map(e=>({...e,[Gr]:`${"function"==typeof r?r(e):e[r]}__${e[Tr]||"observed"}`})),h=Gr),e.baseLineStyle){let t=Wr(t=>e.baseLineStyle(t),e.forecast);f=e=>t(e)}}else e.anomaly&&d.push(...Or(e.anomaly));if(e.gapStrategy){if("function"==typeof h){let e=h;o=o.map(t=>({...t,__semiotic_gapGroup:e(t)})),h="__semiotic_gapGroup"}let t="string"==typeof h?h:void 0,i=Ur(o,e.gapStrategy,c,u,t);o=i.rows,i.groupKey&&(h=i.groupKey)}if(e.directLabel){let t=Kr(o,e.directLabel,"string"==typeof n||"function"==typeof n?n:void 0,c,u,e.colorScheme,e.themeCategorical,e.color);d.push(...t.annotations),l=t.marginExtra}return{data:o,xAccessor:"function"==typeof t?c:t,yAccessor:"function"==typeof i?u:i,groupAccessor:h,colorAccessor:n,annotations:d,lineStyle:f,yExtent:s,marginExtra:l}}function Qr(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=M(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrScatterColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrScatterColorBy:t(e)})):o,u=t?Ci(c,l,s):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[3,15],f=d?o.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=f.length?yr(f):void 0,g=Di(n.xAccessor,n.yAccessor),m=n.styleRules;return e=>{let i={fill:t&&u?Li(e,t,u):"string"==typeof n.color?n.color:Ai,fillOpacity:"number"==typeof n.pointOpacity?n.pointOpacity:.8,r:d?Ni(e,d,h,p):"number"==typeof n.pointRadius?n.pointRadius:5};return m?.length&&Object.assign(i,qi(e,m,g(e))),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}var Jr={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Zr({data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:M(r.theme).colors.categorical}),a=dr(o.annotations,n.regression);return{chartType:"scatter",data:o.data,xAccessor:o.xAccessor,yAccessor:o.yAccessor,colorAccessor:t,sizeAccessor:n.sizeBy,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...r,...a&&a.length>0&&{annotations:a},...o.yExtent&&!r.yExtent&&{yExtent:o.yExtent},sizeRange:n.sizeRange||[3,15],pointStyle:r.pointStyle||Qr(e,t,i,r,n),showLegend:r.showLegend??!!t}}};function en(e,t){if(!t)return[];let i=/* @__PURE__ */new Set,r=[];for(let n of e){if(!n||"object"!=typeof n)continue;let e="function"==typeof t?t(n):n[t],o=String(e);i.has(o)||(i.add(o),r.push(o))}return r}function tn(e,t,i,r){if(!i.categoryAccessor)return;let n=en(e,i.categoryAccessor),o=i.colors,a="explicit-then-alpha"===r?[...Object.keys(o??{}).filter(e=>n.includes(e)),...n.filter(e=>!Object.hasOwn(o??{},e)).sort()]:n,s=M(t.theme).colors.categorical,l=s?.length?s:$i;return Object.fromEntries(a.map((e,t)=>[e,o&&Ri(o,e)||i.fill||l[t%l.length]]))}var rn={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=dr(r.annotations,n.regression);return{chartType:"scatter",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[5,40],colorScheme:i,...r,...o&&{annotations:o},pointStyle:r.pointStyle||nn(e,t,i,r,n),showLegend:r.showLegend??!!t}}};function nn(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=M(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrBubbleColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrBubbleColorBy:t(e)})):o,u=t?Ci(c,l,s):void 0,d=n.sizeBy,h=Array.isArray(n.sizeRange)?n.sizeRange:[5,40],f=d?o.map(e=>"function"==typeof d?d(e):Number(e[d])).filter(Number.isFinite):[],p=f.length?yr(f):void 0,g=Di(n.xAccessor,n.yAccessor),m=n.styleRules;return e=>{let i={fill:t&&u?Li(e,t,u):"string"==typeof n.color?n.color:Ai,fillOpacity:"number"==typeof n.bubbleOpacity?n.bubbleOpacity:.6,r:d?Ni(e,d,h,p):h[0],stroke:n.bubbleStrokeColor??"white",strokeWidth:n.bubbleStrokeWidth??1};return m?.length&&Object.assign(i,qi(e,m,g(e))),void 0!==n.stroke&&(i.stroke=n.stroke),void 0!==n.strokeWidth&&(i.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(i.opacity=n.opacity),i}}import{useMemo as on,useCallback as an,useState as sn,useId as ln,useEffect as cn,useRef as un}from"react";var dn="__semioticSelectionData";function hn(e,t){return t?.length&&Object.defineProperty(e,dn,{configurable:!0,enumerable:!1,value:t}),e}function fn(e){return e?.[dn]}function pn(e){return e.parentLine?hn({...e.parentLine,...e},fn(e)):e}function gn(e){return hn({...e[0]},e.map(pn))}function mn(e){return!!e&&fn(e)?.[0]===e}function yn(e){let t={"--semiotic-bg":e.colors.background,"--semiotic-text":e.colors.text,"--semiotic-text-secondary":e.colors.textSecondary,"--semiotic-grid":e.colors.grid,"--semiotic-border":e.colors.border,"--semiotic-cell-border":e.colors.cellBorder||e.colors.border,"--semiotic-primary":e.colors.primary,"--semiotic-font-family":e.typography.fontFamily,"--semiotic-secondary":e.colors.secondary||e.colors.primary,"--semiotic-surface":e.colors.surface||e.colors.background};e.colors.categorical.forEach((e,i)=>{t[`--semiotic-category-${i+1}`]=e}),e.colors.focus&&(t["--semiotic-focus"]=e.colors.focus),e.colors.selection&&(t["--semiotic-selection-color"]=e.colors.selection),null!=e.colors.selectionOpacity&&(t["--semiotic-selection-opacity"]=String(e.colors.selectionOpacity)),e.colors.diverging&&(t["--semiotic-diverging"]=e.colors.diverging),e.colors.annotation&&(t["--semiotic-annotation-color"]=e.colors.annotation),e.colors.success&&(t["--semiotic-success"]=e.colors.success),e.colors.danger&&(t["--semiotic-danger"]=e.colors.danger),e.colors.warning&&(t["--semiotic-warning"]=e.colors.warning),e.colors.error&&(t["--semiotic-error"]=e.colors.error),e.colors.info&&(t["--semiotic-info"]=e.colors.info),e.tooltip?.background&&(t["--semiotic-tooltip-bg"]=e.tooltip.background),e.tooltip?.text&&(t["--semiotic-tooltip-text"]=e.tooltip.text),e.tooltip?.borderRadius&&(t["--semiotic-tooltip-radius"]=e.tooltip.borderRadius),e.tooltip?.fontSize&&(t["--semiotic-tooltip-font-size"]=e.tooltip.fontSize),e.tooltip?.shadow&&(t["--semiotic-tooltip-shadow"]=e.tooltip.shadow),e.borderRadius&&(t["--semiotic-border-radius"]=e.borderRadius);let i=e.typography.legendSize??e.typography.labelSize;null!=i&&(t["--semiotic-legend-font-size"]=`${i}px`),null!=e.typography.legendFontFamily&&(t["--semiotic-legend-font-family"]=e.typography.legendFontFamily),null!=e.typography.legendFontWeight&&(t["--semiotic-legend-font-weight"]=String(e.typography.legendFontWeight));let r=e.typography.titleFontSize??e.typography.titleSize;return null!=r&&(t["--semiotic-title-font-size"]=`${r}px`),null!=e.typography.titleFontFamily&&(t["--semiotic-title-font-family"]=e.typography.titleFontFamily),null!=e.typography.titleFontWeight&&(t["--semiotic-title-font-weight"]=String(e.typography.titleFontWeight)),null!=e.typography.tickFontFamily&&(t["--semiotic-tick-font-family"]=e.typography.tickFontFamily),null!=e.typography.tickSize&&(t["--semiotic-tick-font-size"]=`${e.typography.tickSize}px`),null!=e.typography.labelSize&&(t["--semiotic-axis-label-font-size"]=`${e.typography.labelSize}px`),t}function xn(e,t=2166136261){let i=t;for(let t=0;t<e.length;t++)i^=e.charCodeAt(t),i=Math.imul(i,16777619);return i>>>0}var bn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function vn(e){let t=new Date(e instanceof Date?e.valueOf():e);return`${bn[t.getUTCMonth()]} ${t.getUTCDate()}`}function wn(e){let t=Math.abs(e[1]-e[0]);return t<864e5?e=>{let i=new Date(e instanceof Date?e.valueOf():e),r=`${String(i.getUTCHours()).padStart(2,"0")}:${String(i.getUTCMinutes()).padStart(2,"0")}`;return t<3e5&&(r+=`:${String(i.getUTCSeconds()).padStart(2,"0")}`),t<1e4&&(r+=`.${String(i.getUTCMilliseconds()).padStart(3,"0")}`),r}:t<3156e7?vn:t<1578e8?e=>{let t=new Date(e instanceof Date?e.valueOf():e);return`${bn[t.getUTCMonth()]} ${t.getUTCFullYear()}`}:e=>String(new Date(e instanceof Date?e.valueOf():e).getUTCFullYear())}function kn(e,t){let i=t=>e[Math.max(0,Math.min(e.length-1,Math.round(Number(t))))],r=e.every(e=>"number"==typeof e||e instanceof Date),n=t?void 0:Sn(e);return(o,a,s)=>{if(0===e.length)return"";let l=i(o);return t?t(l,a,s&&r?s.map(e=>Number(i(e).valueOf())):void 0):l instanceof Date&&n?n(l):String(l)}}function Sn(e){let t=e.filter(e=>e instanceof Date&&Number.isFinite(e.valueOf()));if(0===t.length)return;let i=t.every(e=>e.valueOf()%864e5==0),r=i&&t.every(e=>1===e.getUTCDate());if(r&&t.every(e=>0===e.getUTCMonth()))return e=>String(e.getUTCFullYear());if(r)return e=>`${vn(e).split(" ")[0]} ${e.getUTCFullYear()}`;let n=t.map(e=>e.valueOf()),o=[Math.min(...n),Math.max(...n)];if(i){let e=new Date(o[0]).getUTCFullYear()===new Date(o[1]).getUTCFullYear();return t=>e?vn(t):`${vn(t)}, ${t.getUTCFullYear()}`}return wn(o)}function An(e,t,i){return"function"==typeof e?e(t,i):t[e]}function Mn(e,t){if(!e?.length)return;let i=new Map(t.map((e,t)=>[Rt(e),t]));return e.map(e=>{let t={...e},r=r=>{if(!(r in e))return;let n=i.get(Rt(e[r]));void 0!==n&&(t[r]=n)};return r("x"),r("x0"),r("x1"),"string"==typeof e.type&&("x-threshold"===e.type||"x"===e.type)&&r("value"),t})}function $n(e){let t="number"==typeof e?e:"string"==typeof e&&""!==e.trim()?Number(e):NaN;return Number.isFinite(t)?Math.max(0,Math.floor(t)):void 0}function _n(e){return"string"==typeof e&&""!==e.trim()?e:void 0}function In(e){let{seriesOrder:t,overallOrder:i,highlightTop:r,color:n,colorScheme:o,neutralColor:a,themeCategorical:s,themeNeutral:l}=e;if(null==r&&null==n)return o;let c="string"==typeof o?[...Mi(o,s)]:o,u=null==r?i.length:Math.max(0,Math.floor(r)),d=new Set(i.slice(0,u)),h=/* @__PURE__ */new Map,f={};for(let e of t)Object.defineProperty(f,e,{configurable:!0,enumerable:!0,writable:!0,value:n??(d.has(e)?Fi(void 0,s,c,e,h):a??l??"#b8bec8")});return f}function Pn(e,t={}){let i=t.xAccessor??"x",r=t.yAccessor??"y",n=t.lineBy??"series",o=t.rankDirection??"descending",a=[],s=/* @__PURE__ */new Map,l=/* @__PURE__ */new Map,c=[],u=/* @__PURE__ */new Map,d=1/0,h=-1/0;e.forEach((e,t)=>{let o=An(i,e,t),f=Rt(o),p=s.get(f);null==p&&(p=a.length,s.set(f,p),a.push(o),l.set(p,[]));let g=String(An(n,e,t));u.has(g)||(u.set(g,c.length),c.push(g));let m=Number(An(r,e,t));Number.isFinite(m)&&(d=Math.min(d,m),h=Math.max(h,m),l.get(p)?.push({datum:e,inputIndex:t,series:g,value:m}))});let f=[],p=/* @__PURE__ */new Map,g=/* @__PURE__ */new Map;for(let e=0;e<a.length;e++){let t=l.get(e)??[];t.sort((e,t)=>("descending"===o?t.value-e.value:e.value-t.value)||(u.get(e.series)??0)-(u.get(t.series)??0)),t.forEach((t,i)=>{let r=i+1;f.push({datum:t.datum,xIndex:e,xValue:a[e],series:t.series,value:t.value,rank:r}),p.set(t.series,(p.get(t.series)??0)+r),g.set(t.series,(g.get(t.series)??0)+1)})}let m=c.length+1,y=[...c].sort((e,t)=>{let i=g.get(e)??0,r=g.get(t)??0;return((p.get(e)??0)+(a.length-i)*m)/Math.max(1,a.length)-((p.get(t)??0)+(a.length-r)*m)/Math.max(1,a.length)||(u.get(e)??0)-(u.get(t)??0)}),x=null==t.highlightTop?y.length:Math.max(0,Math.floor(t.highlightTop)),b=new Set(y.slice(0,x));return{data:f.map(e=>{let t=b.has(e.series);return{...e.datum,x:e.xIndex,y:e.rank,__bumpRaw:e.datum,__bumpSeries:e.series,__bumpColorGroup:t?e.series:"Other",__bumpValue:e.value,__bumpRank:e.rank,__bumpXValue:e.xValue,__bumpHighlighted:t}}),xValues:a,seriesOrder:c,overallOrder:y,valueExtent:d===1/0?[0,0]:[d,h]}}import*as Ln from"react";import{jsx as Rn}from"react/jsx-runtime";var Cn,Tn={isActive:!1,predicate:()=>!0};function Nn(){let e=(Cn??(Cn=Ln.createContext(null)),Cn);return Ln.useContext(e)??Tn}function Fn(e,t,i,r,n){let o=1-n;return o*o*o*e+3*o*o*n*t+3*o*n*n*i+n*n*n*r}function En(e,t,i,r,n){let o=1-n;return 3*o*o*(t-e)+6*o*n*(i-t)+3*n*n*(r-i)}function On(e,t,i,r,n){let o=[],a=(e.x+t.x)/2;for(let s=0;s<=n;s++){let l,c,u,d,h=s/n;"linear"===r?(l=e.x+(t.x-e.x)*h,c=e.y+(t.y-e.y)*h,u=t.x-e.x,d=t.y-e.y):(l=Fn(e.x,a,a,t.x,h),c=Fn(e.y,e.y,t.y,t.y,h),u=En(e.x,a,a,t.x,h),d=En(e.y,e.y,t.y,t.y,h)),o.push({x:l,y:c,dx:u,dy:d,radius:e.radius+(t.radius-e.radius)*h,datumIndex:h<.5?i:i+1})}return o}function zn(e,t){let i=e.length-1,r=Math.sign(e[i][0]-e[t][0])||1,n=r*e[i][0],o=r*e[t][0];for(let a=t+1;a<i;a++){let t=Math.max(o,Math.min(n,r*e[a][0]));e[a][0]=r*t,o=t}for(let r=t;r<i;r++){let t=r;for(;t<i&&e[t+1][0]===e[r][0];)t++;for(let i=r+1;i<t;i++)e[i][1]=e[r][1]+(e[t][1]-e[r][1])*(i-r)/(t-r);r=t}let a=1e-6*(n-r*e[t][0])/(i-t);o=r*e[t][0];for(let s=t+1;s<i;s++){let t=Math.max(o+a,Math.min(r*e[s][0],n-(i-s)*a));e[s][0]=r*t,o=t}}function Dn(e,t={}){let i=[],r=[],n=[];if(e.length<2)return{topPath:i,bottomPath:r,datumIndices:n};let o=t.curve??"smooth",a=Math.max(2,Math.floor(t.samplesPerSegment??12));for(let t=0;t<e.length-1;t++){let s=Math.max(0,i.length-1),l=On(e[t],e[t+1],t,o,a);for(let e=0===t?0:1;e<l.length;e++){let t=l[e],o=Math.hypot(t.dx,t.dy)||1,a=-t.dy/o,s=t.dx/o,c=Math.max(0,t.radius);i.push([t.x+a*c,t.y+s*c]),r.push([t.x-a*c,t.y-s*c]),n.push(t.datumIndex)}zn(i,s),zn(r,s)}return{topPath:i,bottomPath:r,datumIndices:n}}var Bn={top:20,bottom:48,left:48},jn=[[/[mwMW@%…]/,.95],[/[ijlI'.,|\s]/,.28],[/[frt():;/[\]{}*`!\\-]/,.39]];function Wn(e,t){let i=0;for(let t of e)i+=(t.codePointAt(0)??0)>=11904?1.1:jn.find(([e])=>e.test(t))?.[1]??(t.toLowerCase()!==t?.75:.62);return i*t*1.05}function Yn(e){let t=e.fontSize??12,i=!0===e.showLabels?"end":e.showLabels,r="end"===i||"both"===i||"auto"===i,n="start"===i||"both"===i,o=e.labels.reduce((e,i)=>Math.max(e,Wn(i,t)),0),a=Math.round(e.width*(e.maxSideFraction??.38)),s=Wn(String(Math.max(1,e.rankCount)),t),l=e.showAxes?8+s+6:8,c={start:l+4+(e.showAxes&&e.yLabel?24:0),end:12},u=e.legendSide?V({legendGroups:[{label:"",styleFn:()=>({}),items:e.labels.map(e=>({label:e}))}]},{sideGutter:0}):0,d=Wn("MMM",t),h=(t,i)=>Math.min(i+o,e.legendSide===t?Math.max(i+d,a-u):a),f={start:n?h("left",c.start):0,end:r?h("right",c.end):0},p=!1===e.showLabels?24:110;return{margin:{...Bn,right:Math.max(p,f.end),left:Math.max(Bn.left,f.start)},startLabelOffset:l,chrome:c,room:f,labelWidth:o,fontSize:t,hasStart:n,hasEnd:r}}function qn(e,t){let i={start:t.hasStart?Math.max(0,Math.min(e.left,t.room.start)-t.chrome.start):0,end:t.hasEnd?Math.max(0,Math.min(e.right,t.room.end)-t.chrome.end):0};return{budget:i,sideGutter:{...t.hasStart&&{left:t.chrome.start+Math.min(i.start,t.labelWidth)},...t.hasEnd&&{right:t.chrome.end+Math.min(i.end,t.labelWidth)}}}}function Xn(e,t,i){if(Wn(e,i)<=t)return{text:e,truncated:!1};let r=Array.from(e),n=r.length-1;for(;n>0&&Wn(`${r.slice(0,n).join("")}…`,i)>t;)n--;return{text:`${r.slice(0,n).join("").trimEnd()}…`,truncated:!0}}import{jsx as Gn,jsxs as Vn}from"react/jsx-runtime";function Hn(e,t,i,r){let n=Math.max(1,Math.floor(t/18)),o="auto"===i?Number.isFinite(r)&&(r??0)>=0?Math.min(n,Math.floor(r)):n:1/0,a=e.map((e,t)=>({candidate:e,index:t})).sort((e,t)=>{let i=e.candidate.priority??0;return(t.candidate.priority??0)-i||Number(t.candidate.highlighted)-Number(e.candidate.highlighted)||e.candidate.rank-t.candidate.rank||e.index-t.index}),s=[];for(let{candidate:e}of a){if(s.length>=o)break;s.some(t=>t.side===e.side&&Math.abs(t.y-e.y)<14)||s.push(e)}return new Set(s.map(e=>e.id))}function Un({datum:e,x:t,y:i,side:r,color:n,highlighted:o,labelStyle:a,offset:s,budget:l,fontSize:c}){let u=Nn(),d=u.isActive&&!u.predicate(e),h="function"==typeof a?a(e.__bumpRaw):a,f=null==l?{text:e.__bumpSeries,truncated:!1}:Xn(e.__bumpSeries,l,c);/* @__PURE__ */
2
- return Vn("text",{className:"semiotic-bump-label",x:t+("end"===r?s:-s),y:i,dy:"0.35em",textAnchor:"end"===r?"start":"end",fill:n,fillOpacity:d?.16:1,fontWeight:o?650:450,fontSize:12,style:{pointerEvents:"none",fontFamily:"var(--semiotic-font-family, sans-serif)",fontSize:"var(--semiotic-axis-label-font-size, 12px)",...h},children:[f.truncated&&/* @__PURE__ */Gn("title",{children:e.__bumpSeries}),f.text]})}function Kn(e){let t=Array.isArray(e.datum)?e.datum[0]:e.datum;return t&&"object"==typeof t&&"__bumpSeries"in t?t:void 0}function Zn(e,t,i){let[r,n]=t,[o,a]=i;return n===r?(o+a)/2:o+(a-o)*Math.max(0,Math.min(1,(e-r)/(n-r)))}function Qn(e){let t=e.__bumpXValue instanceof Date?e.__bumpXValue.getTime():Number(e.__bumpXValue);return{value:e.__bumpValue,x:Number.isFinite(t)?t:void 0,y:e.__bumpValue,category:e.__bumpSeries}}function Jn(e){let t=e.config,i=/* @__PURE__ */new Map;for(let t of e.data){let e=i.get(t.__bumpSeries)??[];e.push(t),i.set(t.__bumpSeries,e)}let r=t.seriesOrder.filter(e=>i.has(e)).sort((e,r)=>(i.get(e)?.[0]?.__bumpHighlighted?1:0)-(i.get(r)?.[0]?.__bumpHighlighted?1:0)||t.seriesOrder.indexOf(e)-t.seriesOrder.indexOf(r)),n=[],o=[],a=[];for(let o of r){let r=(i.get(o)??[]).sort((e,t)=>e.x-t.x);if(r.length<2)continue;let s=r[0].__bumpHighlighted,l=(t.colorMap&&Ri(t.colorMap,o))??e.resolveColor(r[0].__bumpSeries,r[0]),c=t.color??(s?l:t.neutralColor??e.theme.semantic.textSecondary??e.theme.semantic.border??l),u=r.map(i=>({x:e.scales.x(i.x),y:e.scales.y(i.y),radius:t.ribbon?Zn(i.__bumpValue,t.valueExtent,t.ribbonSizeRange)/2:Math.max(.5,t.lineWidth/2)})),d=Dn(u,{curve:t.curve,samplesPerSegment:t.samplesPerSegment}),h={fill:c,fillOpacity:1,opacity:s?t.ribbon?t.ribbonOpacity:t.lineOpacity:Math.min(t.ribbon?t.ribbonOpacity:t.lineOpacity,.58)};t.styleRules?.length&&Object.assign(h,qi(r[0].__bumpRaw,t.styleRules,Qn(r[0]))),t.areaStyle&&Object.assign(h,t.areaStyle(r[0].__bumpRaw)??{}),void 0!==t.stroke&&(h.stroke=t.stroke),void 0!==t.strokeWidth&&(h.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(h.opacity=t.opacity),n.push({type:"area",topPath:d.topPath,bottomPath:d.bottomPath,_hitArea:!0,style:h,datum:d.datumIndices.map(e=>r[e]),accessibleDatum:r.map(e=>e.__bumpRaw),accessibility:{label:`${o} ranking trajectory`,tableFields:r.map(e=>e.__bumpRaw)},group:o,interactive:!0}),t.showPoints&&r.forEach((e,i)=>{let r={fill:c,stroke:"none",opacity:s?1:.75};t.styleRules?.length&&Object.assign(r,qi(e.__bumpRaw,t.styleRules,Qn(e))),t.pointStyle&&Object.assign(r,t.pointStyle(e.__bumpRaw)??{}),void 0!==t.stroke&&(r.stroke=t.stroke),void 0!==t.strokeWidth&&(r.strokeWidth=t.strokeWidth),void 0!==t.opacity&&(r.opacity=t.opacity),n.push({type:"point",x:u[i].x,y:u[i].y,r:r.r??t.pointRadius,style:r,datum:e,accessibleDatum:e.__bumpRaw,accessibility:{label:`${o}, rank ${e.__bumpRank}, value ${e.__bumpValue}`},pointId:`${o}:${e.x}`})});let f=!0===t.showLabels?"end":t.showLabels,p=(e,i,r)=>{let n=null==t.labelPriorityAccessor?void 0:"function"==typeof t.labelPriorityAccessor?t.labelPriorityAccessor(e.__bumpRaw):Number(e.__bumpRaw[t.labelPriorityAccessor]);a.push({id:`${o}\0${r}`,datum:e,x:u[i].x,y:u[i].y,side:r,rank:e.__bumpRank,highlighted:s,priority:Number.isFinite(n)?n:void 0,color:"string"==typeof h.fill?h.fill:c})};("start"===f||"both"===f)&&p(r[0],0,"start"),("end"===f||"both"===f||"auto"===f)&&p(r.at(-1),r.length-1,"end")}let s=!0===t.showLabels?"end":t.showLabels,l=Hn(a,e.dimensions.plot.height,"auto"!==s||"auto",t.maxLabels);for(let e of a)l.has(e.id)&&o.push(
3
- /* @__PURE__ */Gn(Un,{datum:e.datum,x:e.x,y:e.y,side:e.side,color:e.color,highlighted:e.highlighted,labelStyle:t.labelStyle,offset:"end"===e.side?8:t.startLabelOffset??8,budget:t.labelBudget?.[e.side],fontSize:t.labelFontSize??12},e.id));return{nodes:n,overlays:o.length?/* @__PURE__ */Gn("g",{className:"semiotic-bump-labels",children:o}):void 0,restyle:(e,t)=>{let i=Kn(e);if(t?.isActive&&i&&!t.predicate(i))return{opacity:.14}}}}function eo(e){return Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[]}function to(e){return{xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineBy:e.lineBy,rankDirection:e.rankDirection,highlightTop:$n(e.highlightTop)}}function io(e,t,i,r,n,o){let a=t.labelStyle,s=o.position??"right";return{legendSide:!0!==o.show||"left"!==s&&"right"!==s?void 0:s,labels:e,showLabels:t.showLabels??!0,width:i,showAxes:r,rankCount:e.length,yLabel:"string"==typeof n?n:"Rank",fontSize:"object"==typeof a&&"number"==typeof a?.fontSize?a.fontSize:12}}var ro={frameType:"xy",layout:{modeDefaults:{showGrid:!0},margin:(e,t)=>{let{seriesOrder:i}=Pn(eo(e.data),to(e));return Yn(io(i,e,t.width,t.showAxes,e.yLabel,{show:e.showLegend,position:e.legendPosition})).margin}},buildProps:(e,t,i,r,n)=>{let o=Pn(eo(e),to(n)),[a]=r.size??[600,400],s=Yn(io(o.seriesOrder,n,a,!1!==r.showAxes,r.yLabel,{show:r.showLegend,position:r.legendPosition})),l=new Set(Array.isArray(r.__explicitMarginSides)?r.__explicitMarginSides:[]),c=r.margin,u={...c,...s.hasEnd&&!l.has("right")&&{right:Math.max(c.right,s.margin.right)},...s.hasStart&&!l.has("left")&&{left:Math.max(c.left,s.margin.left)}},d=qn(u,s),h=r.legendPosition??"right",f=r.legendLayout,p=!0!==r.showLegend||"left"!==h&&"right"!==h?void 0:d.sideGutter[h],g=Math.max(1,o.seriesOrder.length),m=M(r.theme),y=In({seriesOrder:o.seriesOrder,overallOrder:o.overallOrder,highlightTop:$n(n.highlightTop),color:_n(n.color),colorScheme:i,neutralColor:_n(n.neutralColor),themeCategorical:m.colors.categorical,themeNeutral:m.colors.textSecondary}),x={ribbon:!0===n.ribbon,curve:"linear"===n.curve?"linear":"smooth",samplesPerSegment:"number"==typeof n.samplesPerSegment?n.samplesPerSegment:12,ribbonSizeRange:Array.isArray(n.ribbonSizeRange)?n.ribbonSizeRange:[4,28],valueExtent:o.valueExtent,seriesOrder:o.seriesOrder,lineWidth:"number"==typeof n.lineWidth?n.lineWidth:3,ribbonOpacity:"number"==typeof n.ribbonOpacity?n.ribbonOpacity:.82,lineOpacity:"number"==typeof n.lineOpacity?n.lineOpacity:.9,neutralColor:_n(n.neutralColor),color:_n(n.color),colorMap:y&&"object"==typeof y&&!Array.isArray(y)?y:void 0,stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0,styleRules:n.styleRules,areaStyle:r.areaStyle,pointStyle:r.pointStyle,labelStyle:n.labelStyle,showPoints:!0===n.showPoints,pointRadius:"number"==typeof n.pointRadius?n.pointRadius:3,showLabels:n.showLabels??!0,labelPriorityAccessor:n.labelPriorityAccessor,maxLabels:"number"==typeof n.maxLabels?n.maxLabels:void 0,startLabelOffset:s.startLabelOffset,labelBudget:d.budget,labelFontSize:s.fontSize},b=kn(o.xValues,r.xFormat),v=o.xValues.map((e,t)=>t),w=Array.from({length:g},(e,t)=>t+1),k=r.axes??[{orient:"left",tickValues:w,tickFormat:e=>String(e),label:r.yLabel??"Rank",baseline:!1},{orient:"bottom",tickValues:v,tickFormat:b,label:r.xLabel,tickAnchor:"edges"}];return{...r,margin:u,...null!=p&&null==f?.sideGutter&&{legendLayout:{...f,sideGutter:p}},chartType:"custom",data:o.data,xAccessor:"x",yAccessor:"y",xExtent:[0,Math.max(1,o.xValues.length-1)],yExtent:[g+.5,.5],customLayout:Jn,layoutConfig:x,colorAccessor:"__bumpSeries",colorScheme:y,xFormat:b,axes:k,axisExtent:"exact",showAxes:r.showAxes??!0,showLegend:r.showLegend??!1,annotations:Mn(r.annotations,o.xValues)}}},no="__ma_unitized",oo="__ma_series";function ao(e,t,i){let r=Mi(t,i,Si),n=t&&"object"==typeof t&&!Array.isArray(t)?t:null;return e.map((e,t)=>{if("string"==typeof e.color&&e.color.length>0)return e.color;let i=e.label||`Series ${t+1}`,o=n?.[i];return"string"==typeof o&&o.length>0?o:r[t%r.length]})}function so(e,t){let i=zi(e),r=t.map((e,t)=>({label:e.label||`Series ${t+1}`,readY:zi(e.yAccessor)}));return(e,t)=>{let n=String(e[oo]??t??""),o=(r.find(e=>e.label===n)??r[0])?.readY(e);return{value:o,x:i(e),y:o,category:n||void 0}}}function lo(e,t){let i="function"==typeof t?t:e=>Number(e[t||"y"]),r=1/0,n=-1/0;for(let t of e){let e=i(t);"number"==typeof e&&Number.isFinite(e)&&(e<r&&(r=e),e>n&&(n=e))}if(!Number.isFinite(r)||!Number.isFinite(n))return[0,1];if(r===n){let e=0===r?1:.1*Math.abs(r);return[r-e,n+e]}return[r,n]}var co={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=Array.isArray(n.series)?n.series:[],s=ao(a,i,M(r.theme).colors.categorical),l=2===a.length,c=a.map(e=>e.extent||lo(o,e.yAccessor)),u=[];for(let e of o)a.forEach((t,i)=>{let r=("function"==typeof t.yAccessor?t.yAccessor:e=>e[t.yAccessor])(e);if(null==r||!Number.isFinite(Number(r)))return;let n=Number(r),o=c[i],a=o[1]-o[0]||1;u.push({...e,[no]:l?(n-o[0])/a:n,[oo]:t.label||`Series ${i+1}`})});let d=(e,t)=>i=>{let r=e[0]+i*(e[1]-e[0]);return"function"==typeof t?t(r):Number.isInteger(r)?String(r):r.toFixed(1)},h=l?[{orient:"left",label:a[0].label,tickFormat:d(c[0],a[0].format)},{orient:"right",label:a[1].label,tickFormat:d(c[1],a[1].format)},{orient:"bottom"}]:void 0,f=/* @__PURE__ */new Map;a.forEach((e,t)=>{f.set(e.label||`Series ${t+1}`,s[t])});let p=Oi(Vi({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,resolveStroke:e=>f.get(String(e[oo]??""))||s[0],styleRules:n.styleRules,ruleContext:so(n.xAccessor,a)}),{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0});return{chartType:"line",data:u,xAccessor:n.xAccessor||"x",yAccessor:no,groupAccessor:oo,colorAccessor:oo,...h&&{axes:h},...l&&{yExtent:[0,1]},...r,curve:n.curve||r.curve||"monotoneX",showLegend:r.showLegend??!0,colorScheme:s,lineStyle:p}}},uo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=n.xAccessor||"x",s="function"==typeof a?a:e=>e[a],l=o.some(e=>{let t=s(e);return!("number"==typeof t&&Number.isFinite(t)||t instanceof Date)}),c=l?o.map((e,t)=>({...e,__waterfallX:t,__waterfallTick:String(s(e)??t)})):o,u=n.styleRules?Xi(void 0,n.styleRules,Di(n.xAccessor,n.yAccessor)):void 0,d=u?e=>{let t=u(e),i="function"==typeof r.areaStyle?r.areaStyle(e):r.areaStyle;return i?{...t,...i}:t}:void 0;return{chartType:"waterfall",data:c,xAccessor:l?"__waterfallX":a,yAccessor:n.yAccessor||"y",waterfallStyle:{positiveColor:n.positiveColor,negativeColor:n.negativeColor,connectorStroke:n.connectorStroke,connectorWidth:n.connectorWidth,gap:n.gap,stroke:n.stroke,strokeWidth:n.strokeWidth,opacity:n.opacity},...r,...d&&{areaStyle:d},...l&&{axes:r.axes??[{orient:"bottom",tickValues:c.map((e,t)=>t)}],xFormat:e=>{let t=o[Number(e)]?s(o[Number(e)]):e,i=n.xFormat??r.xFormat;return"function"==typeof i?i(t):String(t??e)}}}}};function ho(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=M(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrLineColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrLineColorBy:t(e)})):o,u=t?Ci(c,l,s):void 0,d=Di(n.xAccessor,n.yAccessor);return Oi(Vi({lineWidth:"number"==typeof n.lineWidth?n.lineWidth:2,colorBy:t,colorScale:u,color:"string"==typeof n.color?n.color:void 0,fillArea:n.fillArea,areaOpacity:"number"==typeof n.areaOpacity?n.areaOpacity:.3,styleRules:n.styleRules,ruleContext:d}),{stroke:"string"==typeof n.stroke?n.stroke:void 0,strokeWidth:"number"==typeof n.strokeWidth?n.strokeWidth:void 0,opacity:"number"==typeof n.opacity?n.opacity:void 0})}function fo(e,t,i,r,n){let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=M(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrAreaColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrAreaColorBy:t(e)})):o,u=t?Ci(c,l,s):void 0,d=!1!==n.showLine,h="number"==typeof n.lineWidth?n.lineWidth:2,f="number"==typeof n.areaOpacity?n.areaOpacity:.7,p=zi(n.yAccessor),g=n.styleRules;return(e,i)=>{let r=t&&u?Li(e,t,u):"string"==typeof n.color?n.color:Ai,o={fill:r,fillOpacity:f,stroke:d?r:"none",...d&&{strokeWidth:h}};return g?.length&&Object.assign(o,qi(e,g,{value:p(e),category:i})),void 0!==n.stroke&&(o.stroke=n.stroke),void 0!==n.strokeWidth&&(o.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(o.opacity=n.opacity),o}}function po(e,t,i,r,n){if(!n.showPoints)return;let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=M(r.theme).colors.categorical,s=i??r.colorScheme??a,l="string"==typeof t?t:"__ssrPointColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrPointColorBy:t(e)})):o,u=t?Ci(c,l,s):void 0,d="number"==typeof n.pointRadius?n.pointRadius:3;return e=>{let i=t&&u?Li(e,t,u):"string"==typeof n.color?n.color:Ai;return{r:d,fill:i,stroke:"none"}}}var go={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.lineBy,a=n.fillArea,s=Array.isArray(a)?"mixed":a?"area":"line",l=M(r.theme).colors.categorical,c=ho(e,o,i,r,n),u=Zr({data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.lineBy,colorBy:o,colorScheme:i,color:"string"==typeof n.color?n.color:void 0,forecast:n.forecast,anomaly:n.anomaly,gapStrategy:n.gapStrategy,directLabel:n.directLabel,annotations:r.annotations,themeCategorical:l,baseLineStyle:c}),d=r.pointStyle||po(u.data,u.colorAccessor,i,r,n),h=r.margin,f=new Set(Array.isArray(r.__explicitMarginSides)?r.__explicitMarginSides:[]);u.marginExtra&&h&&"object"==typeof h?h={...h,...null!=u.marginExtra.right&&!f.has("right")&&{right:Math.max(Number(h.right)||0,u.marginExtra.right)},...null!=u.marginExtra.left&&!f.has("left")&&{left:Math.max(Number(h.left)||0,u.marginExtra.left)}}:u.marginExtra&&null==h&&(h={top:20,right:u.marginExtra.right??20,bottom:30,left:u.marginExtra.left??40});let p=(!n.directLabel||void 0!==r.showLegend)&&(r.showLegend??!!u.colorAccessor);return{chartType:s,data:u.data,xAccessor:u.xAccessor,yAccessor:u.yAccessor,groupAccessor:u.groupAccessor,colorAccessor:u.colorAccessor,colorScheme:i,lineStyle:u.lineStyle||c,...Array.isArray(a)&&{areaGroups:a},...a&&null!=n.areaOpacity&&{areaOpacity:n.areaOpacity},...null!=n.band&&{band:n.band},...r,...void 0!==h&&{margin:h},annotations:u.annotations,...u.yExtent&&!r.yExtent&&{yExtent:u.yExtent},...d&&{pointStyle:d},showLegend:p}}},mo={frameType:"xy",layout:{margin:(e,t)=>pr(t.marginDefaults,fr(e),t.showAxes,!!t.title)},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?ei(e):[],a=n.timeAccessor||"time",s=n.valueAccessor||"value",l=n.categoryAccessor,c=tn(o,r,n,"explicit-then-alpha"),u=n.valueExtent||r.yExtent,d={...ur(n),...void 0!==n.cursor&&{cursor:n.cursor}},h={...d,...void 0!==n.fill&&{fill:n.fill},...void 0!==n.gap&&{gap:n.gap},...Array.isArray(n.valueBands)&&{valueBands:n.valueBands}},f=Xi(void 0,n.styleRules,e=>{let t=e.categoryValue??e.total,i="number"==typeof t&&Number.isFinite(t)?t:void 0,r=Number(e.binStart),n=Number(e.binEnd);return{value:i,x:Number.isFinite(r)&&Number.isFinite(n)?(r+n)/2:void 0,y:i,category:null==e.category?void 0:String(e.category)}});return{chartType:"bar",data:o,...r,runtimeMode:"streaming",windowMode:"growing",windowSize:Math.max(1,o.length),arrowOfTime:n.arrowOfTime||"right",timeAccessor:e=>Kt(e,a,"time")??NaN,valueAccessor:e=>Ut(e,s,"value")??NaN,xExtent:n.timeExtent||r.xExtent,yExtent:u,invertY:"down"===n.direction,axes:fr({...n,axes:r.axes??n.axes}),extentPadding:n.extentPadding??r.extentPadding,binSize:n.binSize,categoryAccessor:l,barColors:c||r.barColors,colorScheme:c||r.colorScheme,barStyle:r.barStyle||h,areaStyle:r.areaStyle||(e=>({...f(e),...!l&&void 0!==n.fill&&{fill:n.fill},...d})),showLegend:r.showLegend??!!l}}},yo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.areaBy,a=Zr({data:Array.isArray(e)?ei(e):[],xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",lineBy:n.areaBy,forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:M(r.theme).colors.categorical}),s=Qt({data:e,safeData:a.data,areaBy:n.areaBy,lineDataAccessor:n.lineDataAccessor||"coordinates"}),l=ir(n.semanticGradient),c=l?.stops.length?or(l):er(r.gradientFill),u=!1!==n.semanticLine?rr(l):void 0,d=r.pointStyle||po(s,o,i,r,n);return{chartType:"area",data:s,xAccessor:a.xAccessor,yAccessor:a.yAccessor,y0Accessor:n.y0Accessor,groupAccessor:n.areaBy||void 0,colorAccessor:o,colorScheme:i,...r,...a.annotations.length>0&&{annotations:a.annotations},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},...void 0!==c&&{gradientFill:c},...u&&{semanticLineStops:u},lineStyle:r.lineStyle||fo(s,o,i,r,n),...d&&{pointStyle:d}}}},xo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.xAccessor||"x",a=n.seriesAAccessor||"a",s=n.seriesBAccessor||"b",l=e=>lr(sr(o,"x",e)),c=e=>lr(sr(a,"a",e)),u=e=>lr(sr(s,"b",e)),d=n.seriesAColor||"var(--semiotic-danger, #dc2626)",h=n.seriesBColor||"var(--semiotic-info, #2563eb)",f=n.areaOpacity??.6,p=n.lineWidth??1.5,g=!1!==n.showLines,m=!1!==r.showLegend,y=n.seriesALabel||"A",x=n.seriesBLabel||"B",b=r.legendPosition||"right",v=Hi(Array.isArray(e)?e:[],l,c,u),w=[];if(g&&Array.isArray(e)){let t=e.filter(e=>Number.isFinite(l(e))).sort((e,t)=>l(e)-l(t));for(let e of t){let t=l(e),i=c(e),r=u(e);Number.isFinite(i)&&w.push({__x:t,__y:i,__diffSegment:"line-A",__diffWinner:"A",__sourceDatum:e}),Number.isFinite(r)&&w.push({__x:t,__y:r,__diffSegment:"line-B",__diffWinner:"B",__sourceDatum:e})}}return{chartType:"mixed",data:[...v,...w],xAccessor:"__x",yAccessor:"__y",y0Accessor:"__y0",groupAccessor:"__diffSegment",areaGroups:Array.from(new Set(v.map(e=>e.__diffSegment))),areaStyle:Zi({seriesAColor:d,seriesBColor:h,areaOpacity:f,styleRules:n.styleRules}),lineStyle:Qi({seriesAColor:d,seriesBColor:h,lineWidth:p,styleRules:n.styleRules}),curve:n.curve||"linear",...r,...m&&{legend:{legendGroups:[{label:"",type:"fill",styleFn:e=>({fill:e.color||"currentColor"}),items:[{label:y,color:d},{label:x,color:h}]}]},legendPosition:b}}}},bo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=t||n.areaBy,a="string"==typeof o&&Array.isArray(e)?Ci(e,o,i):void 0,s="number"==typeof n.areaOpacity?n.areaOpacity:.7,l=r.lineStyle||(e=>{let t=null==o?void 0:Li(e,o,a),i=n.showLine??!0,r=n.stroke??t,l=n.strokeWidth??n.lineWidth??2,c={fill:n.color??t,stroke:i?r:"none",...i?{strokeWidth:l}:{},fillOpacity:s,...null==n.opacity?{}:{opacity:n.opacity}},u=n.styleRules;if(u?.length){let t=zi(n.yAccessor),i=o?String("function"==typeof o?o(e)??"":e[o]??""):void 0;Object.assign(c,qi(e,u,{value:t(e),category:i}))}return c}),c=n.normalize?"zero":n.baseline??"zero",u=r.pointStyle||po(e,o,i,r,n);return{chartType:"stackedarea",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.areaBy,colorAccessor:o,colorScheme:i,normalize:n.normalize,baseline:c,stackOrder:n.stackOrder,lineStyle:l,...r,...u&&{pointStyle:u},curve:r.curve??n.curve??"monotoneX",showLegend:r.showLegend??!!o}}},vo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let[o]=r.size??[600,400];return{chartType:"candlestick",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.highAccessor||"high",highAccessor:n.highAccessor||"high",lowAccessor:n.lowAccessor||"low",openAccessor:n.openAccessor,closeAccessor:n.closeAccessor,candlestickStyle:n.candlestickStyle,...r,...!r.pointStyle&&Array.isArray(n.styleRules)&&n.styleRules.length>0&&{pointStyle:Xi(void 0,n.styleRules,Di(n.xAccessor||"x",n.closeAccessor||n.highAccessor||"high"))},scalePadding:r.scalePadding??Math.max(2,Math.min(12,Math.round(o/40))),extentPadding:r.extentPadding??(o<=200?.02:.1)}}},wo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.xCenter,a=n.yCenter,s=n.quadrants,l=n.centerlineStyle||{},c=!1!==n.showQuadrantLabels,u=n.quadrantLabelSize??12,d=l.stroke||"#999",h=l.strokeWidth??1,f=Array.isArray(l.strokeDasharray)?l.strokeDasharray.join(","):l.strokeDasharray,p=Zt.createElement,g=s?[(e,t,i)=>{if(!t?.x||!t?.y)return null;let r=i.width,n=i.height,l=null!=o?t.x(o):r/2,g=null!=a?t.y(a):n/2;if(null!=o&&!Number.isFinite(l)||null!=a&&!Number.isFinite(g))return null;let m=Math.max(0,Math.min(r,l)),y=Math.max(0,Math.min(n,g)),x=[{c:s.topLeft,x:0,y:0,w:m,h:y},{c:s.topRight,x:m,y:0,w:r-m,h:y},{c:s.bottomLeft,x:0,y:y,w:m,h:n-y},{c:s.bottomRight,x:m,y:y,w:r-m,h:n-y}],b=c?[p("text",{key:"ltl",x:8,y:8+u,fill:s.topLeft.color,fontWeight:600,fontSize:u,opacity:.5},s.topLeft.label),p("text",{key:"ltr",x:r-8,y:8+u,fill:s.topRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},s.topRight.label),p("text",{key:"lbl",x:8,y:n-8,fill:s.bottomLeft.color,fontWeight:600,fontSize:u,opacity:.5},s.bottomLeft.label),p("text",{key:"lbr",x:r-8,y:n-8,fill:s.bottomRight.color,fontWeight:600,fontSize:u,opacity:.5,textAnchor:"end"},s.bottomRight.label)]:[];return p(Zt.Fragment,null,...x.map((e,t)=>e.w>0&&e.h>0?p("rect",{key:`qf-${t}`,x:e.x,y:e.y,width:e.w,height:e.h,fill:e.c.color,opacity:e.c.opacity??.08}):null),p("line",{key:"vc",x1:m,y1:0,x2:m,y2:n,stroke:d,strokeWidth:h,strokeDasharray:f}),p("line",{key:"hc",x1:0,y1:y,x2:r,y2:y,stroke:d,strokeWidth:h,strokeDasharray:f}),...b)}]:void 0;return{chartType:"scatter",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,sizeAccessor:n.sizeBy,sizeRange:n.sizeRange||[3,15],colorScheme:i,pointStyle:r.pointStyle||n.pointStyle||Qr(e,t,i,r,n),...r,showLegend:r.showLegend??!!t,...g&&{svgPreRenderers:g}}}},ko={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=hr(e,n),a=Zr({data:o.data,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",forecast:n.forecast,anomaly:n.anomaly,annotations:r.annotations,themeCategorical:M(r.theme).colors.categorical}),s=dr(a.annotations,n.regression),l=n.pointRadius??4,c=Di(n.xAccessor,n.yAccessor),u=n.styleRules,d=[e=>{let t=e.filter(e=>"point"===e.type&&"number"==typeof e.x&&"number"==typeof e.y);if(t.length<2)return null;let i=[];for(let e=0;e<t.length-1;e++){let r=t[e],n=t[e+1],o=cr(e,t.length);t.length<100&&i.push(Zt.createElement("line",{key:`halo-${e}`,x1:r.x,y1:r.y,x2:n.x,y2:n.y,stroke:"white",strokeWidth:l+2,strokeLinecap:"round",opacity:.5})),i.push(Zt.createElement("line",{key:`segment-${e}`,x1:r.x,y1:r.y,x2:n.x,y2:n.y,stroke:o,strokeWidth:l,strokeLinecap:"round"}))}return Zt.createElement(Zt.Fragment,null,...i)}];return{chartType:"scatter",data:a.data,xAccessor:a.xAccessor,yAccessor:a.yAccessor,colorAccessor:t,colorScheme:i,pointStyle:Oi(e=>{let t=o.orderMap.get(e),i=t?.idx??0,r=t?.total??1,n={fill:r>0?cr(i,r):"#6366f1",stroke:"white",strokeWidth:1,r:l,fillOpacity:1};return u?.length&&Object.assign(n,qi(e,u,c(e))),n},ur(n)),...r,...s&&s.length>0&&{annotations:s},...a.yExtent&&!r.yExtent&&{yExtent:a.yExtent},svgPreRenderers:d}}};function So(e,t,i){let r=zi(e),n=zi(t),o=zi(i);return e=>{let t="string"==typeof e.agg&&"number"==typeof e.count&&"number"==typeof e.xCenter&&"number"==typeof e.yCenter;return{value:t?Ao(e.value):o(e),x:t?Ao(e.xCenter):r(e),y:t?Ao(e.yCenter):n(e)}}}function Ao(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}var Mo={frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=n.frameProps&&"object"==typeof n.frameProps?n.frameProps:void 0,a=Number.isFinite(n.cellBorderWidth)?Math.max(0,n.cellBorderWidth):1,s=Xi(()=>({stroke:n.cellBorderColor??"#fff",strokeWidth:a}),n.styleRules,So(n.xAccessor,n.yAccessor,n.valueAccessor)),l=("string"==typeof o?.colorScheme?o.colorScheme:void 0)??i,c=null!=o&&Object.hasOwn(o,"heatmapColorScale"),u=o?.heatmapColorScale,d=c?"function"==typeof u?u:void 0:"custom"===l&&"function"==typeof n.customColorScale?n.customColorScale:void 0;return{chartType:"heatmap",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",valueAccessor:n.valueAccessor,showValues:n.showValues,heatmapValueFormat:n.valueFormat,...n.heatmapAggregation&&{heatmapAggregation:n.heatmapAggregation},...null!=n.heatmapXBins&&{heatmapXBins:n.heatmapXBins},...null!=n.heatmapYBins&&{heatmapYBins:n.heatmapYBins},areaStyle:s,...r,...void 0!==l&&{colorScheme:l},...d&&{heatmapColorScale:d}}}};import*as $o from"react-dom/server";function _o(e,t={}){let i=!0===t.showRetractedAnnotations,r=!0===t.showSupersededAnnotations,n=/* @__PURE__ */new Set;for(let t of e){let e=t?.lifecycle?.supersedes;e&&"retracted"!==t?.lifecycle?.status&&n.add(e)}return e.filter(e=>{if("retracted"===e?.lifecycle?.status&&!i)return!1;let t=e?.provenance?.stableId;return!(t&&n.has(t)&&!r)})}import*as Io from"react";import*as Po from"react-dom/server";var Lo=class{constructor(e){if(this._capacity=e,this.head=0,this._size=0,e<1)throw new Error("RingBuffer capacity must be at least 1");this.buffer=new Array(e)}push(e){let t;return this._size===this._capacity?t=this.buffer[this.head]:this._size++,this.buffer[this.head]=e,this.head=(this.head+1)%this._capacity,t}pushMany(e){let t=[];for(let i of e){let e=this.push(i);void 0!==e&&t.push(e)}return t}get(e){if(e<0||e>=this._size)return;let t=(this.head-this._size+e+this._capacity)%this._capacity;return this.buffer[t]}peek(){if(0!==this._size)return this.buffer[(this.head-1+this._capacity)%this._capacity]}peekOldest(){if(0!==this._size)return this.buffer[(this.head-this._size+this._capacity)%this._capacity]}[Symbol.iterator](){let e=0;return{next:()=>e>=this._size?{done:!0,value:void 0}:{done:!1,value:this.get(e++)}}}forEach(e){let t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;i<this._size;i++)e(this.buffer[(t+i)%this._capacity],i)}toArray(){let e=new Array(this._size),t=(this.head-this._size+this._capacity)%this._capacity;for(let i=0;i<this._size;i++)e[i]=this.buffer[(t+i)%this._capacity];return e}resize(e){if(e<1)throw new Error("RingBuffer capacity must be at least 1");let t=this.toArray(),i=0,r=[];t.length>e&&(i=t.length-e,r=t.slice(0,i)),this._capacity=e,this.buffer=new Array(e),this.head=0,this._size=0;for(let e=i;e<t.length;e++)this.push(t[e]);return r}update(e,t){let i=[],r=(this.head-this._size+this._capacity)%this._capacity;for(let n=0;n<this._size;n++){let o=(r+n)%this._capacity,a=this.buffer[o];if(e(a)){let e;e="object"!=typeof a||null===a?a:Array.isArray(a)?[...a]:{...a},i.push(e),this.buffer[o]=t(a)}}return i}remove(e){let t=[],i=[];if(this.forEach(r=>{e(r)?i.push(r):t.push(r)}),0===i.length)return i;this.buffer=new Array(this._capacity),this.head=0,this._size=0;for(let e of t)this.push(e);return i}clear(){this.buffer=new Array(this._capacity),this.head=0,this._size=0}get size(){return this._size}get capacity(){return this._capacity}get full(){return this._size===this._capacity}},Ro=class{constructor(){this._min=1/0,this._max=-1/0,this._dirty=!1}push(e){Number.isFinite(e)&&(e<this._min&&(this._min=e),e>this._max&&(this._max=e))}evict(e){(e===this._min||e===this._max)&&(this._dirty=!0)}recalculate(e,t){this._min=1/0,this._max=-1/0;for(let i of e){let e=t?t(i):i;Number.isFinite(e)&&(e<this._min&&(this._min=e),e>this._max&&(this._max=e))}this._dirty=!1}clear(){this._min=1/0,this._max=-1/0,this._dirty=!1}get extent(){return[this._min,this._max]}get min(){return this._min}get max(){return this._max}get dirty(){return this._dirty}};function Co(e,t){return e===t}function To(e,t){if("function"==typeof e)return t=>+e(t);let i=e||t;return e=>+e[i]}function No(e,t){if("function"==typeof e)return e;let i=e||t;return e=>e[i]}function Fo(e,t){return"function"==typeof e?t=>String(e(t)):e?t=>String(t[e]):t?e=>String(e[t]):void 0}function Eo(e){return e?"function"==typeof e?e:t=>t[e]||t.id:null}function Oo(e){return"string"==typeof e?e:e.id}function zo(e){return new Set(Array.isArray(e)?e:[e])}function Do(e,t,i){if(null!=e)return"function"==typeof e?e(t,i):"object"==typeof e&&null!==e&&"constant"in e?e.constant:t[e]}function Bo(e){let t=Math.max(0,Math.min(1,e.minOpacity??.1));if(Number.isNaN(e.age))return 1;if(e.age===1/0)return t;if(!Number.isFinite(e.extent)||e.extent<=0)return 1;let i=Math.max(0,e.age);if("step"===e.type)return i<(e.threshold??.5*e.extent)?1:t;if("exponential"===e.type){let r=e.halfLife??e.extent/2,n=r>0?r:e.extent/2;return t+Math.pow(.5,i/n)*(1-t)}return t+Math.max(0,Math.min(1,1-i/e.extent))*(1-t)}function jo(e,t,i){if(i<=1)return 1;let r=i-1;return Bo({age:r-t,extent:r,type:e.type,halfLife:e.halfLife??i/2,threshold:e.stepThreshold??.5*i,minOpacity:e.minOpacity??.1})}function Wo(e){let t=/* @__PURE__ */new Map;for(let i=0;i<e.length;i++)t.set(e[i],i);return t}function Yo(e,t,i,r=Wo(i)){let n=i.length;if(!(n<=1))for(let i of t){if("line"===i.type){let t=Array.isArray(i.datum)?i.datum:[];if(t.length<2)continue;let o=new Array(t.length),a=!1;for(let i=0;i<t.length;i++){let s=r.get(t[i]);null!=s?(o[i]=jo(e,s,n),o[i]<1&&(a=!0)):o[i]=1}a&&(i._decayOpacities=o);continue}if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[],o=i.topPath?i.topPath.length:t.length;if(o<2)continue;if(t.length===o){let a=new Array(o),s=!1;for(let i=0;i<t.length;i++){let o=r.get(t[i]);null!=o?(a[i]=jo(e,o,n),a[i]<1&&(s=!0)):a[i]=1}s&&(i._decayOpacities=a)}else{let a=1;for(let i of t){let t=r.get(i);if(null!=t){let i=jo(e,t,n);i<a&&(a=i)}}if(a<1){let e=new Array(o);e.fill(a),i._decayOpacities=e}}continue}let t=r.get(i.datum);if(null==t)continue;let o=jo(e,t,n);if("candlestick"===i.type)i._decayOpacity=o;else{let e=i.style?.opacity??1;i.style={...i.style,opacity:e*o}}}}function qo(e,t,i){let r=e.duration??500,n=i-t;return n>=r?0:1-n/r}function Xo(e,t,i,r,n,o=(typeof performance<"u"?performance.now():Date.now())){let a=e.color??"rgba(255,255,255,0.6)",s=e.glowRadius??4,l=!1,c=n??(()=>{let e=/* @__PURE__ */new Map;for(let t=0;t<i.length;t++)e.set(i[t],t);return e})();for(let i of t){if("line"===i.type)continue;if("area"===i.type){let t=Array.isArray(i.datum)?i.datum:[i.datum],n=0,s=!1;for(let i of t){let t=c.get(i);if(null==t)continue;s=!0;let a=r.get(t);if(null==a)continue;let l=qo(e,a,o);l>n&&(n=l)}s&&(l=Go(i,n,a)||l);continue}let t=c.get(i.datum);if(null==t)continue;let n=r.get(t);l=Go(i,null==n?0:qo(e,n,o),a,s)||l}return l}function Go(e,t,i,r){let n=!1;return t>0?(e._pulseIntensity!==t&&(e._pulseIntensity=t,n=!0),e._pulseColor!==i&&(e._pulseColor=i,n=!0),e._pulseGlowRadius!==r&&(e._pulseGlowRadius=r,n=!0),n):(0!==e._pulseIntensity&&(e._pulseIntensity=0,n=!0),void 0!==e._pulseColor&&(e._pulseColor=void 0,n=!0),void 0!==e._pulseGlowRadius&&(e._pulseGlowRadius=void 0,n=!0),n)}function Vo(e,t,i=(typeof performance<"u"?performance.now():Date.now())){if(!t||0===t.size)return!1;let r=e.duration??500,n=t.peek();return null!=n&&i-n<r}var Ho=null;function Uo(){return Ho}var Ko=/* @__PURE__ */Object.create(null);function Zo(e){Ko[e.chartType]=e}function Qo(e){return Ko[e]}function Jo(e){return Array.isArray(e)?{nodes:e,binBoundaries:[]}:{nodes:e.nodes,binBoundaries:e.binBoundaries}}var ea=typeof window>"u"||typeof document>"u",ta=/* @__PURE__ */new Set;function ia(e){Qo(e)||ea&&(ta.has(e)||(ta.add(e),console.warn(`[semiotic] StreamXYFrame: no XY plugin registered for "${e}" during SSR. Import a chart HOC, or call registerBuiltInXYPlugins() from "semiotic/xy" or "semiotic/realtime/core" before render.`)))}function ra(e){if("production"===process.env.NODE_ENV)return;let{label:t,nodes:i,overlays:r,warned:n}=e;na(r)&&0===i.length&&oa(n,"overlay-only",`[semiotic] ${t} returned overlays but no data-bearing scene nodes. Overlays do not participate in hover, selection, transitions, SSR evidence, or accessibility tables. Emit at least one scene node with a datum, or mark the overlay-only chart as intentionally decorative.`),i.length>0&&i.every(e=>null==e.datum)&&oa(n,"null-datums",`[semiotic] ${t} returned scene nodes, but every scene-node datum is null. Hover, callbacks, selection, and tooltip helpers need data-bearing nodes. Attach a user-facing datum to each interactive node, or set interactive overlays outside the chart.`)}function na(e){return null!=e&&!1!==e&&""!==e&&(!Array.isArray(e)||e.some(na))}function oa(e,t,i){e.has(t)||(e.add(t),console.warn(i))}function aa(e){if(e instanceof Error)return{name:e.name||"Error",message:e.message||"Custom layout threw."};if("string"==typeof e)return{name:"Error",message:e};if(null==e)return{name:"Error",message:"Custom layout threw a nullish value."};try{return{name:"Error",message:String(e)}}catch{return{name:"Error",message:"Custom layout threw a non-stringifiable value."}}}function sa(e,t,i,r){let n=aa(t),o="network"===e?"customNetworkLayout":"customLayout";return{code:"CUSTOM_LAYOUT_ERROR",severity:"error",phase:"layout",component:e,source:o,message:`Semiotic ${e} ${o} failed: ${n.message}`,error:n,recovery:i?"preserved-last-good-scene":"empty-scene",preservedLastGoodScene:i,affectedRevision:r}}function la(e){try{return{kind:"success",result:e.run()}}catch(t){let i=e.hasPreviousResult,r=sa(e.family,t,i,e.revision);"production"!==process.env.NODE_ENV&&console.error(`[semiotic] ${e.logLabel} threw:`,t);try{e.onLayoutError?.(r)}catch(e){"production"!==process.env.NODE_ENV&&console.error("[semiotic] onLayoutError threw:",e)}return{kind:"failure",diagnostic:r,preservedLastGoodScene:i}}}function ca(e,t){let i="function"==typeof e?e:i=>i[e||t];return e=>{let t=i(e);return null==t?Number.NaN:+t}}function ua(e){let t=[],i=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode,r=ca(i&&e.valueAccessor||e.yAccessor,i?"value":"y");if(e.boundsAccessor){let i=To(e.boundsAccessor,"bounds");t.push({kind:"bounds",getTop:e=>{let t=r(e);if(!Number.isFinite(t))return Number.NaN;let n=i(e);return Number.isFinite(n)&&0!==n?t+n:t},getBottom:e=>{let t=r(e);if(!Number.isFinite(t))return Number.NaN;let n=i(e);return Number.isFinite(n)&&0!==n?t-n:t},style:e.boundsStyle,perSeries:!0,interactive:!1})}if(e.band){let i=Array.isArray(e.band)?e.band:[e.band];for(let e of i)t.push({kind:"band",getTop:ca(e.y1Accessor,"y1"),getBottom:ca(e.y0Accessor,"y0"),style:e.style,perSeries:!1!==e.perSeries,interactive:!0===e.interactive})}return t}import{scaleLinear as da,scaleLog as ha,scaleSymlog as fa,scaleTime as pa,scaleUtc as ga}from"d3-scale";function ma(e,t,i,r,n,o=!1){let a=/* @__PURE__ */new Map;for(let s of e){let e=t(s),l=i(s);if(null==e||null==l||Number.isNaN(e)||Number.isNaN(l))continue;let c=Math.floor(e/r)*r,u=a.get(c);if(u||(u={start:c,end:c+r,total:0,categories:/* @__PURE__ */new Map,...o?{rows:[],categoryRows:/* @__PURE__ */new Map}:{}},a.set(c,u)),u.total+=l,u.rows?.push(s),n){let e=n(s);if(u.categories.set(e,(u.categories.get(e)||0)+l),u.categoryRows){let t=u.categoryRows.get(e);t||(t=[],u.categoryRows.set(e,t)),t.push(s)}}}return a}function ya(e,t,i,r,n){let o=ma(e,t,i,r,n);if(0===o.size)return[0,0];let a=0;for(let e of o.values())e.total>a&&(a=e.total);return[0,a]}function xa(e,t){let i=0,r=0,n=0;for(let o of e){let e=t(o);null==e||Number.isNaN(e)||(n+=e,n<i&&(i=n),n>r&&(r=n))}return[i,r]}function ba(e,t,i,r,n,o){let a=[];for(let o of e){let e=i(o),s=r(o),l=n?n(o):0;if(!Number.isFinite(e)||!Number.isFinite(s)||!Number.isFinite(l))continue;let c=t.x(e),u=t.y(s),d=n?t.y(l):0;!Number.isFinite(c)||!Number.isFinite(u)||!Number.isFinite(d)||a.push({x:c,y:u,bottom:d,raw:s,datum:o})}a.sort((e,t)=>e.x-t.x);let s=new Array(a.length),l=n?new Array(a.length):[],c=new Array(a.length),u=new Array(a.length),d=o?new Array(a.length):void 0;for(let e=0;e<a.length;e++){let t=a[e];s[e]=[t.x,t.y],n&&(l[e]=[t.x,t.bottom]),c[e]=t.raw,u[e]=t.datum,d&&o&&(d[e]=String(o(t.datum)))}return d?{topPath:s,bottomPath:l,rawValues:c,datum:u,pathIds:d}:{topPath:s,bottomPath:l,rawValues:c,datum:u}}function va(e,t,i,r,n,o,a){let{topPath:s,rawValues:l,datum:c,pathIds:u}=ba(e,t,i,r,void 0,a),d={type:"line",path:s,rawValues:l,style:n,datum:c,group:o};return u&&(d.pathIds=u),d}function wa(e,t,i,r,n,o,a,s,l){return{type:"area",...ba(e,t,i,r,s??(()=>n),l),style:o,group:a}}function ka(e,t,i,r){let n=/* @__PURE__ */new Map;if("silhouette"===r)for(let r of e){let e=0;for(let n of t)e+=i(n,r)||0;n.set(r,-e/2)}else if("wiggle"===r){e.length>0&&n.set(e[0],0);for(let r=1;r<e.length;r++){let o=e[r-1],a=e[r],s=0,l=0,c=0;for(let e of t){let t=i(e,a)||0;s+=(2*c+t)*(t-(i(e,o)||0)),l+=t,c+=t}let u=n.get(o)??0,d=l>0?s/(2*l):0;n.set(a,u-d)}if(e.length>0){let r=0;for(let o of e){let e=0;for(let r of t)e+=i(r,o)||0;r+=(n.get(o)??0)+e/2}let o=r/e.length;for(let t of e)n.set(t,(n.get(t)??0)-o)}}else for(let t of e)n.set(t,0);return n}function Sa(e,t,i){let r=0,n=0;for(let o of e){let e=0,a=0;for(let r of t){let t=i(r,o)||0;t>=0?e+=t:a+=t}a<r&&(r=a),e>n&&(n=e)}return[r,n]}function Aa(e,t,i,r,n,o,a,s="zero",l){let c=/* @__PURE__ */new Set,u=/* @__PURE__ */new Map;for(let t of e){let e=/* @__PURE__ */new Map;for(let n of t.data){let t=i(n),o=r(n);if(!Number.isFinite(t)||(c.add(t),!Number.isFinite(o)))continue;let a=e.get(t);a?(a.value+=o,a.sources?a.sources.push(n):a.sources=[a.datum,n]):e.set(t,{value:o,datum:n})}u.set(t.key,e)}let d,h=Array.from(c).sort((e,t)=>e-t);if(o){d=/* @__PURE__ */new Map;for(let t of h){let i=0;for(let r of e)i+=u.get(r.key)?.get(t)?.value||0;d.set(t,i||1)}}let f=ka(h,e.map(e=>e.key),(e,t)=>u.get(e)?.get(t)?.value||0,s),p="diverging"===s&&!o,g=[],m=/* @__PURE__ */new Map,y=/* @__PURE__ */new Map,x=/* @__PURE__ */new Map,b=/* @__PURE__ */new Map;for(let e of h)y.set(e,f.get(e)??0),x.set(e,0),b.set(e,0);for(let i of e){let e=u.get(i.key),r=/* @__PURE__ */new Map,s=[],c=[],f=[],v=[],w=[],k=l?[]:void 0,S=!1,A=()=>{if(0!==s.length){if(s.length>=2){let e=S?s.map((e,t)=>t).sort((e,t)=>s[e][0]-s[t][0]):void 0,t=e?e.map(e=>v[e]):v,r={type:"area",topPath:e?e.map(e=>s[e]):s,bottomPath:e?e.map(e=>c[e]):c,rawValues:e?e.map(e=>f[e]):f,style:n(i.key,gn(i.data)),datum:t,accessibleDatum:e?e.map(e=>w[e]):w,group:i.key};k&&(r.pathIds=e?e.map(e=>k[e]):k),a&&(r.curve=a),g.push(r)}s=[],c=[],f=[],v=[],w=[],k=l?[]:void 0,S=!1}};for(let n of h){let a,l,u=e.get(n),h=void 0!==u,g=u?.value??0;if(o&&h&&(g/=d.get(n)),!h||!Number.isFinite(g)||0===g){A();continue}p?g>0?(a=x.get(n),l=a+g,x.set(n,l)):(a=b.get(n),l=a+g,b.set(n,l)):(a=y.get(n),l=a+g,y.set(n,l));let m=t.x(n),M=t.y(a),$=t.y(l);if(!Number.isFinite(m)||!Number.isFinite(M)||!Number.isFinite($)){A();continue}let _=u.sources,I=u.value,P=_?{..._[0],__aggregateValue:I,__aggregateCount:_.length,__aggregateRows:_}:u.datum;s.length>0&&m<s[s.length-1][0]&&(S=!0),s.push([m,$]),c.push([m,M]),v.push(P),f.push(I),k&&k.push(`x:${n}`),w.push(_?{x:n,value:I,group:i.key,observations:_.length}:P),r.set(n,l)}A(),m.set(i.key,r)}return{nodes:g,stackedTops:m}}function Ma(e,t,i,r,n,o,a){let s=i(e),l=r(e);if(!Number.isFinite(s)||!Number.isFinite(l))return null;let c={type:"point",x:t.x(s),y:t.y(l),r:n,style:o,datum:e};return void 0!==a&&(c.pointId=a),c}function $a(e,t,i,r,n,o,a,s){let l=i(e),c=r(e);if(!Number.isFinite(l)||!Number.isFinite(c))return null;let u={type:"symbol",x:t.x(l),y:t.y(c),size:n,symbolType:o,style:a,datum:e};return void 0!==s&&(u.pointId=s),u}function _a(e,t,i,r,n,o,a){return{type:"rect",x:e,y:t,w:i,h:r,style:n,datum:o,group:a}}function Ia(e,t,i,r,n,o,a){let s={type:"heatcell",x:e,y:t,w:i,h:r,fill:n,datum:o};return void 0!==a?.value&&(s.value=a.value),a?.showValues&&(s.showValues=!0,a.valueFormat&&(s.valueFormat=a.valueFormat)),s}function Pa(e,t){return t?[t[0]??e[0],t[1]??e[1]]:e}function La(e){let{config:t,groups:i,getX:r,getY:n}=e,o="exact"===(t.yAxisExtent??t.axisExtent);if(t.normalize){let i=[0,o?1:1+t.extentPadding];return{yDomain:i,stackExtentCache:{key:`${e.bufferSize}:${e.ingestVersion}:norm`,yDomain:i}}}let a=`${e.bufferSize}:${e.ingestVersion}:${t.baseline??"zero"}:${t.stackOrder??"key"}`;if(e.stackExtentCache&&e.stackExtentCache.key===a)return{yDomain:e.stackExtentCache.yDomain,stackExtentCache:e.stackExtentCache};let s=/* @__PURE__ */new Map,l=/* @__PURE__ */new Set,c=0,u=/* @__PURE__ */new Map,d=/* @__PURE__ */new Map;for(let e of i){let t=/* @__PURE__ */new Map,i=0;for(let o of e.data){let e=r(o),a=n(o);if(!Number.isFinite(e)||!Number.isFinite(a))continue;t.set(e,(t.get(e)||0)+a),l.add(e),i+=a;let s=(u.get(e)||0)+a;u.set(e,s),s>c&&(c=s)}s.set(e.key,t),d.set(e.key,i)}let h,f,p=t.stackOrder??"key",g=(e,t)=>e<t?-1:e>t?1:0;if("input"===p)h=i.map(e=>e.key);else if("insideOut"===p){let e=[...i].map(e=>e.key).sort((e,t)=>{let i=(d.get(t)??0)-(d.get(e)??0);return 0!==i?i:g(e,t)}),t=[],r=[],n=0,o=0;for(let i of e)n<o?(t.push(i),n+=d.get(i)??0):(r.push(i),o+=d.get(i)??0);h=[...r.reverse(),...t]}else h="asc"===p?i.map(e=>e.key).sort((e,t)=>{let i=(d.get(e)??0)-(d.get(t)??0);return 0!==i?i:g(e,t)}):"desc"===p?i.map(e=>e.key).sort((e,t)=>{let i=(d.get(t)??0)-(d.get(e)??0);return 0!==i?i:g(e,t)}):i.map(e=>e.key).sort(g);if("wiggle"===t.baseline||"silhouette"===t.baseline){let e=Array.from(l).sort((e,t)=>e-t),i=ka(e,h,(e,t)=>s.get(e)?.get(t)||0,t.baseline),r=1/0,n=-1/0;for(let t of e){let e=i.get(t)??0,o=u.get(t)??0;e<r&&(r=e),e+o>n&&(n=e+o)}(!Number.isFinite(r)||!Number.isFinite(n))&&(r=0,n=0);let a=n-r,c=o?0:a>0?a*t.extentPadding:1;f=[r-c,n+c]}else if("diverging"===t.baseline){let e=Array.from(l).sort((e,t)=>e-t),[i,r]=Sa(e,h,(e,t)=>s.get(e)?.get(t)||0),n=r-i,a=o?0:n>0?n*t.extentPadding:1;f=[i-a,r+a]}else f=[0,c+(o?0:c>0?c*t.extentPadding:1)];return{yDomain:f,stackExtentCache:{key:a,yDomain:f}}}function Ra(e,t,i,r,n,o,a){let[,s]=ya(e,t,i,r,n);return[0,a?s:s+s*o]}function Ca(e,t,i,r){let[n,o]=xa(e,t),a=o-n,s=r?0:a>0?a*i:1;return[Math.min(0,n-Math.abs(s)),Math.max(0,o+Math.abs(s))]}function Ta(e,t,i,r,n){let o=Array.from(new Set(e.map(t).filter(e=>Number.isFinite(e)))).sort((e,t)=>e-t);if(o.length<2)return Pa(i,r);let a=o[0],s=o[1],l=o[o.length-1],c=o[o.length-2];return Pa("log"===n&&a>0?[a/Math.sqrt(s/a),l*Math.sqrt(l/c)]:[a-(s-a)/2,l+(l-c)/2],r)}function Na(e,t,i){if(!i.length)return e;let[r,n]=e;for(let e of t)for(let t of i){let i=t.getTop(e),o=t.getBottom(e);Number.isFinite(i)&&(i<r&&(r=i),i>n&&(n=i)),Number.isFinite(o)&&(o<r&&(r=o),o>n&&(n=o))}return[r,n]}function Fa(e,t){let i=e[1]-e[0],r=t.exactMode?0:i>0?i*t.extentPadding:1,n=[null!=t.userMin?e[0]:e[0]-r,null!=t.userMax?e[1]:e[1]+r];if("log"===t.yScaleType&&n[0]<=0&&t.dataYDomain[0]>0&&!t.exactMode){let e=1+t.extentPadding;null==t.userMin&&(n[0]=t.dataYDomain[0]/e)}return n}function Ea(e,t,i){if(!t||i)return e;let r=t[0],n=t[1];return null==r&&null==n?e:[r??e[0],n??e[1]]}function Oa(e,t,i){let r=e,n=t;return(r[0]===1/0||r[1]===-1/0)&&(r="time"===i?[0,864e5]:[0,1]),(n[0]===1/0||n[1]===-1/0)&&(n=[0,1]),{xDomain:r,yDomain:n}}function za(e,t,i){if("log"===e){let e=[Math.max(t[0],1e-6),Math.max(t[1],1e-6)];return ha().domain(e).range(i).clamp(!0)}return"symlog"===e?fa().domain(t).range(i):"time"===e||"utc"===e?("utc"===e?ga():pa()).domain([new Date(t[0]),new Date(t[1])]).range(i):da().domain(t).range(i)}function Da(e){let{config:t,layout:i,xDomain:r}=e,n=t.xScaleType??(e.xIsDate?"utc":void 0),o=t.invertY?[e.yDomain[1],e.yDomain[0]]:e.yDomain,a="streaming"===t.runtimeMode,s=t.scalePadding||0,l=Math.max(0,Math.min(s,Math.min(i.width,i.height)/2-1));return a?{x:za(n,r,"left"===t.arrowOfTime?[i.width-l,l]:[l,i.width-l]),y:za(t.yScaleType,o,[i.height-l,l])}:{x:za(n,r,[l,i.width-l]),y:za(t.yScaleType,o,[i.height-l,l])}}function Ba(e,t){return e&&"object"==typeof e&&!Array.isArray(e)?Ri(e,t):void 0}function ja(e,t,i,r){if(r&&r.version===i&&r.group===t&&r.data===e)return{result:r.result,cache:r};let n;if(t){let i=/* @__PURE__ */new Map;for(let r of e){let e=t(r);i.has(e)||i.set(e,[]),i.get(e).push(r)}n=Array.from(i.entries()).map(([e,t])=>({key:e,data:t}))}else n=[{key:"_default",data:e}];return{result:n,cache:{version:i,group:t,data:e,result:n}}}function Wa(e,t,i,r,n){if(n&&n.version===r)return{map:n.map,cache:n};let o=/* @__PURE__ */new Set;if(t)for(let i of e){let e=t(i);e&&o.add(e)}let a=Array.from(o).sort(),s=a.join("\0");if(n&&n.key===s){let e={...n,version:r};return{map:e.map,cache:e}}let l=Mi(i.colorScheme,i.themeCategorical,$i),c=/* @__PURE__ */new Map;for(let e=0;e<a.length;e++)c.set(a[e],Ba(i.colorScheme,a[e])??l[e%l.length]);return{map:c,cache:{key:s,map:c,version:r}}}function Ya(e){let{group:t,colorMapCache:i,groupColorMap:r,groupColorMapCap:n,config:o}=e,{groupColorCounter:a}=e,s=Ba(o.colorScheme,t);if(s)return{color:s,groupColorCounter:a};if(i){let e=i.map.get(t);if(e)return{color:e,groupColorCounter:a}}let l=r.get(t);if(l)return{color:l,groupColorCounter:a};let c=Mi(o.colorScheme,o.themeCategorical,$i);if(0===c.length)return{color:null,groupColorCounter:a};let u=c[a%c.length];if(a++,r.set(t,u),r.size>n){let e=r.keys().next().value;void 0!==e&&r.delete(e)}return{color:u,groupColorCounter:a}}function qa(e,t,i,r){let n=e.lineStyle;if("function"==typeof n){let e=n(i||{},t);if(e&&!e.stroke&&t){let i=r(t);if(i)return{...e,stroke:i}}return e}let o=e.themeSemantic?.primary;return n&&"object"==typeof n?{stroke:n.stroke||o||"#007bff",strokeWidth:n.strokeWidth??2,strokeDasharray:n.strokeDasharray,fill:n.fill,fillOpacity:n.fillOpacity,opacity:n.opacity,cursor:n.cursor}:{stroke:r(t)||o||"#007bff",strokeWidth:2}}function Xa(e,t,i,r){if(e.areaStyle){let n=e.areaStyle(i||{});if(n&&!n.fill&&t){let e=r(t);if(e)return{...n,fill:e,stroke:n.stroke||e}}return n}let n=e.lineStyle;if("function"==typeof n){let e=n(i||{},t);if(e&&!e.fill&&t){let i=r(t);if(i)return{...e,fill:i,stroke:e.stroke||i}}return e}let o=e.themeSemantic?.primary;if(n&&"object"==typeof n)return{fill:n.fill||n.stroke||o||"#4e79a7",fillOpacity:n.fillOpacity??.7,stroke:n.stroke||o||"#4e79a7",strokeWidth:n.strokeWidth??2,cursor:n.cursor};let a=r(t)||o||"#4e79a7";return{fill:a,fillOpacity:.7,stroke:a,strokeWidth:2}}function Ga(e,t,i,r){let n=e.boundsStyle;if("function"==typeof n)return n(i||{},t);if(n&&"object"==typeof n)return n;let o=r(t,i);return{fill:o.stroke||e.themeSemantic?.primary||"#4e79a7",fillOpacity:.2,...null!=o.opacity&&{opacity:o.opacity},stroke:"none",cursor:o.cursor}}function Va(e,t,i){t<=e.capacity||(e.resize(t),i&&t>i.capacity&&i.resize(t))}function Ha(e,t){let i=new Lo(e.capacity);return e.forEach(()=>i.push(t)),i}function Ua(e,t,i,r){let n=e.push(t);return i&&i.push(r),n}function Ka(e,t,i){if(!t||0===t.size)return;let r=/* @__PURE__ */new Set;if(e.forEach((e,t)=>{i(e)&&r.add(t)}),0===r.size)return;let n=t.toArray();t.clear();for(let e=0;e<n.length;e++)r.has(e)||t.push(n[e])}var Za=/* @__PURE__ */new WeakMap,Qa=class{getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}setLayoutSelection(e){this.config.layoutSelection=e}markStylePaintPending(){Za.set(this,!0)}consumeStylePaintPending(){let e=!0===Za.get(this);return Za.delete(this),e}},Ja={data:"data",domain:"domain",layout:"layout","scene-geometry":"sceneGeometry","scene-style":"sceneStyle","data-paint":"dataPaint","interaction-paint":"interactionPaint",overlay:"overlay",accessibility:"accessibility",evidence:"evidence"};function es(e,t){let i={...e};for(let e of t)i[Ja[e]]++;return i}function ts(e,t,i){let r=new Set(t);return{changeSet:{...e,...e.keys?{keys:[...e.keys]}:{}},changed:r,revisions:es(i,r)}}var is=class{constructor(){this.revisions={data:0,domain:0,layout:0,sceneGeometry:0,sceneStyle:0,dataPaint:0,interactionPaint:0,overlay:0,accessibility:0,evidence:0},this.latest=ts({kind:"initialize"},[],this.revisions),this.listeners=/* @__PURE__ */new Set}get last(){return this.latest}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}record(e,t){let i=ts(e,t,this.revisions);this.revisions=i.revisions,this.latest=i;for(let e of[...this.listeners])e();return i}},rs=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ns=["scene-style","data-paint","accessibility","evidence"],os=(e,t)=>({retainedData:e,invalidations:t}),as=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ss=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],ls=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],cs=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],us=["scene-geometry","data-paint","accessibility","evidence"],ds=["scene-style","data-paint","accessibility","evidence"],hs=["overlay","accessibility","evidence"],fs=[],ps={chartType:/* @__PURE__ */os("rebuild",as),runtimeMode:/* @__PURE__ */os("rebuild",as),xAccessor:/* @__PURE__ */os("rebuild",as),yAccessor:/* @__PURE__ */os("rebuild",as),timeAccessor:/* @__PURE__ */os("rebuild",as),valueAccessor:/* @__PURE__ */os("rebuild",as),y0Accessor:/* @__PURE__ */os("rebuild",as),boundsAccessor:/* @__PURE__ */os("rebuild",as),band:/* @__PURE__ */os("rebuild",as),openAccessor:/* @__PURE__ */os("rebuild",as),highAccessor:/* @__PURE__ */os("rebuild",as),lowAccessor:/* @__PURE__ */os("rebuild",as),closeAccessor:/* @__PURE__ */os("rebuild",as),candlestickRangeMode:/* @__PURE__ */os("rebuild",as),accessorRevision:/* @__PURE__ */os("rebuild",as),groupAccessor:/* @__PURE__ */os("rebuild",ss),categoryAccessor:/* @__PURE__ */os("rebuild",ss),lineDataAccessor:/* @__PURE__ */os("rebuild",ss),colorAccessor:/* @__PURE__ */os("rebuild",ds),sizeAccessor:/* @__PURE__ */os("rebuild",us),symbolAccessor:/* @__PURE__ */os("rebuild",us),pointIdAccessor:/* @__PURE__ */os("rebuild",us),xScaleType:/* @__PURE__ */os("preserve",ls),yScaleType:/* @__PURE__ */os("preserve",ls),xExtent:/* @__PURE__ */os("preserve",ls),invertY:/* @__PURE__ */os("preserve",ls),yExtent:/* @__PURE__ */os("preserve",ls),extentPadding:/* @__PURE__ */os("preserve",ls),scalePadding:/* @__PURE__ */os("preserve",ls),axisExtent:/* @__PURE__ */os("preserve",ls),yAxisExtent:/* @__PURE__ */os("preserve",ls),binSize:/* @__PURE__ */os("preserve",ls),normalize:/* @__PURE__ */os("preserve",ls),heatmapAggregation:/* @__PURE__ */os("preserve",ls),heatmapXBins:/* @__PURE__ */os("preserve",ls),heatmapYBins:/* @__PURE__ */os("preserve",ls),arrowOfTime:/* @__PURE__ */os("preserve",cs),baseline:/* @__PURE__ */os("preserve",cs),stackOrder:/* @__PURE__ */os("preserve",cs),sizeRange:/* @__PURE__ */os("preserve",cs),curve:/* @__PURE__ */os("preserve",cs),areaGroups:/* @__PURE__ */os("preserve",cs),customLayout:/* @__PURE__ */os("preserve",cs),layoutConfig:/* @__PURE__ */os("preserve",cs),layoutMargin:/* @__PURE__ */os("preserve",cs),symbolMap:/* @__PURE__ */os("preserve",us),showValues:/* @__PURE__ */os("preserve",us),heatmapValueFormat:/* @__PURE__ */os("preserve",us),trackHoverRows:/* @__PURE__ */os("preserve",us),lineStyle:/* @__PURE__ */os("preserve",ds),pointStyle:/* @__PURE__ */os("preserve",ds),areaStyle:/* @__PURE__ */os("preserve",ds),barStyle:/* @__PURE__ */os("preserve",ds),swarmStyle:/* @__PURE__ */os("preserve",ds),waterfallStyle:/* @__PURE__ */os("preserve",ds),candlestickStyle:/* @__PURE__ */os("preserve",ds),boundsStyle:/* @__PURE__ */os("preserve",ds),gradientFill:/* @__PURE__ */os("preserve",ds),lineGradient:/* @__PURE__ */os("preserve",ds),semanticLineStops:/* @__PURE__ */os("preserve",ds),colorScheme:/* @__PURE__ */os("preserve",ds),themeCategorical:/* @__PURE__ */os("preserve",ds),themeSemantic:/* @__PURE__ */os("preserve",ds),themeSequential:/* @__PURE__ */os("preserve",ds),themeDiverging:/* @__PURE__ */os("preserve",ds),barColors:/* @__PURE__ */os("preserve",ds),decay:/* @__PURE__ */os("preserve",ds),pulse:/* @__PURE__ */os("preserve",ds),staleness:/* @__PURE__ */os("preserve",ds),layoutSelection:/* @__PURE__ */os("preserve",ds),annotations:/* @__PURE__ */os("preserve",hs),windowSize:/* @__PURE__ */os("preserve",fs),windowMode:/* @__PURE__ */os("preserve",fs),maxCapacity:/* @__PURE__ */os("preserve",fs),clock:/* @__PURE__ */os("preserve",fs),transition:/* @__PURE__ */os("preserve",fs),introAnimation:/* @__PURE__ */os("preserve",fs),onLayoutError:/* @__PURE__ */os("preserve",fs)},gs=/* @__PURE__ */os("preserve",cs);function ms(e){let t="preserve",i=/* @__PURE__ */new Set;for(let r of e){let e=ps[r]??gs;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var ys=class{constructor(){this.tracker=new is}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},rs)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},ns):this.recordNoop("restyle")}recordConfig(e,t=!1){let i=ms(e);return this.tracker.record({kind:"config",keys:e},t?/* @__PURE__ */new Set([...i.invalidations,...us]):i.invalidations)}};import{quadtree as xs}from"d3-quadtree";var bs=class{constructor(){this.maxRadius=0,this.tree=null}get quadtree(){return this.tree}get maxPointRadius(){return this.maxRadius}clear(){this.tree=null,this.maxRadius=0}rebuild(e,t){if("scatter"!==e&&"bubble"!==e&&"custom"!==e)return void this.clear();let i=0,r=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(i++,e.r>r&&(r=e.r));if(this.maxRadius=r,i<=500)return void(this.tree=null);let n=new Array(i),o=0;for(let e of t)"point"===e.type&&!1!==e.interactive&&(n[o++]=e);this.tree=xs().x(e=>e.x).y(e=>e.y).addAll(n)}};function vs(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}if("point"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("glyph"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.size=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0);else if("rect"===t.type||"heatcell"===t.type)void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0);else if("candlestick"===t.type)void 0!==t._targetX&&(t.x=t._targetX,void 0!==t._targetOpenY&&(t.openY=t._targetOpenY),void 0!==t._targetCloseY&&(t.closeY=t._targetCloseY),void 0!==t._targetHighY&&(t.highY=t._targetHighY),void 0!==t._targetLowY&&(t.lowY=t._targetLowY),t._targetX=void 0,t._targetOpenY=void 0,t._targetCloseY=void 0,t._targetHighY=void 0,t._targetLowY=void 0);else if("line"===t.type||"area"===t.type){if(t._introClipFraction=void 0,"line"===t.type&&t._targetPath){for(let e=0;e<t.path.length;e++)t.path[e]=t._targetPath[e];t._prevPath=void 0,t._targetPath=void 0}if("area"===t.type){if(t._targetTopPath)for(let e=0;e<t.topPath.length;e++)t.topPath[e]=t._targetTopPath[e];if(t._targetBottomPath)for(let e=0;e<t.bottomPath.length;e++)t.bottomPath[e]=t._targetBottomPath[e];t._prevTopPath=void 0,t._prevBottomPath=void 0,t._targetTopPath=void 0,t._targetBottomPath=void 0}}}}function ws(e){for(let t of e){if(void 0!==t._targetOpacity){let e=t._targetOpacity;t.style={...t.style||{},opacity:0===e?0:e},t._targetOpacity=void 0}"point"===t.type?void 0!==t._targetX?(t.x=t._targetX,t.y=t._targetY,void 0!==t._targetR&&(t.r=t._targetR),t._targetX=void 0,t._targetY=void 0,t._targetR=void 0):void 0!==t._targetR&&(t.r=t._targetR,t._targetR=void 0):"rect"===t.type?void 0!==t._targetX&&(t.x=t._targetX,t.y=t._targetY,t.w=t._targetW,t.h=t._targetH,t._targetX=void 0,t._targetY=void 0,t._targetW=void 0,t._targetH=void 0):"wedge"===t.type&&void 0!==t._targetStartAngle&&(t.startAngle=t._targetStartAngle,t.endAngle=t._targetEndAngle,t._targetStartAngle=void 0,t._targetEndAngle=void 0)}}function ks(e,t,i,r){let n=r.width/i.width,o=r.height/i.height;for(let t of e)switch(t.type){case"line":for(let e of t.path)e[0]*=n,e[1]*=o;break;case"area":for(let e of t.topPath)e[0]*=n,e[1]*=o;for(let e of t.bottomPath)e[0]*=n,e[1]*=o;t.clipRect&&(t.clipRect={x:t.clipRect.x*n,y:t.clipRect.y*o,width:t.clipRect.width*n,height:t.clipRect.height*o}),t.strokeColorBands&&(t.strokeColorBands=t.strokeColorBands.map(e=>({...e,y:e.y*o,height:e.height*o})));break;case"point":case"symbol":case"glyph":t.x*=n,t.y*=o;break;case"rect":case"heatcell":t.x*=n,t.y*=o,t.w*=n,t.h*=o}return{x:t.x.copy().range(t.x.range().map(e=>e*n)),y:t.y.copy().range(t.y.range().map(e=>e*o))}}var Ss=class extends Qa{constructor(e){super(),this.xExtent=new Ro,this.yExtent=new Ro,this.growingCapacityWarned=!1,this.windowSizeWarned=!1,this.resolvedRibbons=[],this.timestampBuffer=null,this.activeTransition=null,this._hasRenderedOnce=!1,this.prevPositionMap=/* @__PURE__ */new Map,this.prevPathMap=/* @__PURE__ */new Map,this.exitNodes=[],this.lastIngestTime=0,this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=/* @__PURE__ */new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this._ingestVersion=0,this._datumIndexCache=null,this._bufferArrayCache=null,this._bufferDirty=!0,this.needsFullRebuild=!0,this.lastLayout=null,this.updateResults=new ys,this.scales=null,this.scene=[],this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=/* @__PURE__ */new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,this.xIsDate=!1,this.xTypeDetected=!1,this.spatialIndex=new bs,this._lastBoundedInsertsRef=null,this.applyPulse=(e,t,i)=>!(!this.config.pulse||!this.timestampBuffer)&&Xo(this.config.pulse,e,t,this.timestampBuffer,this.getDatumIndexMap(t),i),this.config=e,this.buffer=new Lo(e.windowSize),this.growingCap=e.windowSize;let t=["bar","swarm","waterfall"].includes(e.chartType)||"streaming"===e.runtimeMode;if(this.resolveXAccessor(),this.getY=t?To(e.valueAccessor||e.yAccessor,"value"):To(e.yAccessor,"y"),this.getGroup=Fo(e.groupAccessor),this.getCategory=Fo(e.categoryAccessor),this.getSize=e.sizeAccessor?To(e.sizeAccessor,"size"):void 0,this.getColor=Fo(e.colorAccessor),this.getSymbol=Fo(e.symbolAccessor),this.getY0=e.y0Accessor?To(e.y0Accessor,"y0"):void 0,this.resolvedRibbons=ua(e),this.getPointId=Fo(e.pointIdAccessor),"candlestick"===e.chartType){let t=null!=e.openAccessor,i=null!=e.closeAccessor;this.getOpen=t?To(e.openAccessor,"open"):void 0,this.getHigh=To(e.highAccessor,"high"),this.getLow=To(e.lowAccessor,"low"),this.getClose=i?To(e.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!t&&!i}e.pulse&&(this.timestampBuffer=new Lo(e.windowSize))}currentTime(){return this.config.clock?.()??r()}resolveXAccessor(e=this.buffer){let t=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=No(t&&this.config.timeAccessor||this.config.xAccessor,t?"time":"x");this.xIsDate=!1,this.xTypeDetected=!1;for(let t of e){let e=i(t);if(null==e||""===e)continue;let r=e instanceof Date&&Number.isFinite(e.getTime())||"string"==typeof e&&Number.isFinite(Gt(e));if(r||Number.isFinite(Number(e))){this.xIsDate=r,this.xTypeDetected=!0;break}}this.getX=this.xIsDate?e=>{return(t=i(e))instanceof Date?t.getTime():"string"==typeof t?Gt(t):+t;var t}:e=>+i(e)}syncPulseTimestampBuffer(){this.config.pulse?null!=this.timestampBuffer&&this.timestampBuffer.capacity===this.buffer.capacity&&this.timestampBuffer.size===this.buffer.size||(this.timestampBuffer=Ha(this.buffer,this.currentTime())):this.timestampBuffer=null}pushDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.push(this.getHigh(e)),void this.yExtent.push(this.getLow(e));this.yExtent.push(this.getY(e)),this.getY0&&this.yExtent.push(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.push(i),Number.isFinite(r)&&this.yExtent.push(r)}}evictDatumYExtent(e){if("candlestick"===this.config.chartType&&this.getHigh&&this.getLow)return this.yExtent.evict(this.getHigh(e)),void this.yExtent.evict(this.getLow(e));this.yExtent.evict(this.getY(e)),this.getY0&&this.yExtent.evict(this.getY0(e));for(let t of this.resolvedRibbons){let i=t.getTop(e),r=t.getBottom(e);Number.isFinite(i)&&this.yExtent.evict(i),Number.isFinite(r)&&this.yExtent.evict(r)}}rebuildYExtent(){this.yExtent.clear();for(let e of this.buffer)this.pushDatumYExtent(e)}rebuildExtents(){this.xExtent.clear(),this.yExtent.clear();for(let e of this.buffer)this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e)}ingest(e){if(e.bounded&&this._lastBoundedInsertsRef===e.inserts)return this.updateResults.recordNoop("replace"),!1;let t=this.currentTime();if(this.lastIngestTime=t,this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,e.bounded){this._lastBoundedInsertsRef=e.inserts,this.buffer.clear(),this.xExtent.clear(),this.yExtent.clear(),this.timestampBuffer&&this.timestampBuffer.clear(),this.resolveXAccessor(e.inserts);let i=e.totalSize||e.inserts.length;Va(this.buffer,i,this.timestampBuffer);for(let i of e.inserts)Ua(this.buffer,i,this.timestampBuffer,t),this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i)}else{this.xTypeDetected||this.resolveXAccessor(e.inserts);for(let i of e.inserts){if("growing"===this.config.windowMode&&this.buffer.full){let e=this.config.maxCapacity??1e5;this.growingCap<e&&(this.growingCap=Math.min(2*this.growingCap,e),this.buffer.resize(this.growingCap),this.timestampBuffer&&this.timestampBuffer.resize(this.growingCap),"production"!==process.env.NODE_ENV&&!this.growingCapacityWarned&&this.growingCap>=5e4&&(this.growingCapacityWarned=!0,console.warn(`[Semiotic] Growing window buffer reached ${this.growingCap} points (cap ${e}). Large canvas scenes are expensive — prefer a sliding window, aggregation, or an explicit maxCapacity if this is intentional.`)))}let e=Ua(this.buffer,i,this.timestampBuffer,t);this.xExtent.push(this.getX(i)),this.pushDatumYExtent(i),null!=e&&(this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e))}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,n=this.lastLayout;if(!(e.width>0&&e.height>0&&Number.isFinite(e.width)&&Number.isFinite(e.height)))return void(this.needsFullRebuild=!0);if(!this.needsFullRebuild&&!t.customLayout&&!this.activeTransition&&"bar"!==t.chartType&&"waterfall"!==t.chartType&&"candlestick"!==t.chartType&&this.lastLayout&&this.lastLayout.width>0&&this.lastLayout.height>0&&this.scene.length>0&&this.scales&&(this.config.scalePadding??0)<=0&&(this.lastLayout.width!==e.width||this.lastLayout.height!==e.height))return this.scales=ks(this.scene,this.scales,this.lastLayout,e),this.lastLayout={width:e.width,height:e.height},this.spatialIndex.rebuild(t.chartType,this.scene),void this.version++;this.xExtent.dirty&&this.xExtent.recalculate(i,this.getX),this.yExtent.dirty&&this.rebuildYExtent();let o=this.getBufferArray(),a=this.xExtent.extent,s=this.yExtent.extent,l="waterfall"===t.chartType&&i.size>0?Ta(o,this.getX,a,t.xExtent,t.xScaleType):Pa(a,t.xExtent),c=Pa(s,t.yExtent),u=!(!(h=t.yExtent)||null==h[0]||null==h[1]),d="exact"===(t.yAxisExtent??t.axisExtent);var h;if("stackedarea"===t.chartType&&!u&&i.size>0){let e=La({config:t,groups:this.groupData(o),getX:this.getX,getY:this.getY,bufferSize:i.size,ingestVersion:this._ingestVersion,stackExtentCache:this._stackExtentCache});c=e.yDomain,this._stackExtentCache=e.stackExtentCache}else"bar"===t.chartType&&t.binSize&&!u&&i.size>0?c=Ra(i,this.getX,this.getY,t.binSize,this.getCategory,t.extentPadding,d):"waterfall"===t.chartType&&!u&&i.size>0?c=Ca(i,this.getY,t.extentPadding,d):!u&&c[0]!==1/0&&(c=Na(c,o,this.resolvedRibbons),c=Fa(c,{exactMode:d,extentPadding:t.extentPadding,userMin:t.yExtent?.[0],userMax:t.yExtent?.[1],yScaleType:t.yScaleType,dataYDomain:s}));c=Ea(c,t.yExtent,!!u),({xDomain:l,yDomain:c}=Oa(l,c,t.xScaleType)),this.scales=Da({config:t,layout:e,xDomain:l,yDomain:c,xIsDate:this.xIsDate}),this._customLayoutFailedThisBuild=!1;let f=this.buildSceneNodes(e,o);if(this._customLayoutFailedThisBuild)return!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.lastLayout=n):(this.scene=[],this.spatialIndex.rebuild(this.config.chartType,this.scene)),void(this.needsFullRebuild=!0);let p=this.config.transition?Uo():null;p&&this.scene.length>0&&this.snapshotPositions(),this.scene=f,this.config.decay&&this.applyDecay(this.scene,o),this.config.pulse&&this.applyPulse(this.scene,o,this.currentTime()),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&p&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),p&&(this.prevPositionMap.size>0||this.prevPathMap.size>0)&&this.startTransition(),this.spatialIndex.rebuild(this.config.chartType,this.scene),this.needsFullRebuild=!1,this.lastLayout={width:e.width,height:e.height},this.version++}get quadtree(){return this.spatialIndex.quadtree}get maxPointRadius(){return this.spatialIndex.maxPointRadius}buildSceneNodes(e,t){let{config:i,scales:r}=this;if(!r)return[];if(i.customLayout){let n=i.layoutMargin??{top:0,right:0,bottom:0,left:0},o={data:t,scales:r,dimensions:{width:e.width,height:e.height,margin:n,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:i.themeSemantic??{},categorical:i.themeCategorical??$i},resolveColor:(e,t)=>{let r=this.resolveGroupColor(e);if(r)return r;let n=this.resolveLineStyle(e,t);return n.stroke?n.stroke:"string"==typeof n.fill?n.fill:i.themeSemantic?.primary??"#4e79a7"},config:i.layoutConfig??{},selection:i.layoutSelection??null},a=la({family:"xy",logLabel:"customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:i.onLayoutError,run:()=>i.customLayout(o)});if("failure"===a.kind)return this.lastCustomLayoutFailure=a.diagnostic,this._customLayoutFailedThisBuild=!0,a.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,[]);let s=a.result;this.customLayoutOverlays=s.overlays??null,this.lastCustomLayoutResult=s,this.lastCustomLayoutFailure=null;let l=s.nodes??[];if(this._customRestyle=s.restyle,this.hasCustomRestyle=!!s.restyle,this.hasCustomRestyle){this._baseStyles=/* @__PURE__ */new WeakMap;for(let e of l)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(l,i.layoutSelection??null)}return ra({label:"customLayout",nodes:l,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),l}if(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,0===t.length)return[];let n={scales:r,config:i,getX:this.getX,getY:this.getY,getY0:this.getY0,getSize:this.getSize,getColor:this.getColor,getSymbol:this.getSymbol,getGroup:this.getGroup,getCategory:this.getCategory,getPointId:this.getPointId,ribbons:this.resolvedRibbons,getOpen:this.getOpen,getHigh:this.getHigh,getLow:this.getLow,getClose:this.getClose,resolveLineStyle:(e,t)=>this.resolveLineStyle(e,t),resolveAreaStyle:(e,t)=>this.resolveAreaStyle(e,t),resolveBoundsStyle:(e,t)=>this.resolveBoundsStyle(e,t),resolveColorMap:e=>this.resolveColorMap(e),resolveGroupColor:e=>this.resolveGroupColor(e),groupData:e=>this.groupData(e),barCategoryCache:this._barCategoryCache},o=(a=i.chartType,Ko[a]?.buildScene);var a;if(!o)return ia(i.chartType),[];let s=Jo(o(n,t,e));return"bar"===i.chartType&&(this._barCategoryCache=n.barCategoryCache??null,this._binBoundaries=s.binBoundaries),s.nodes}resolveBoundsStyle(e,t){return Ga(this.config,e,t,(e,t)=>this.resolveLineStyle(e,t))}computeDecayOpacity(e,t){let i=this.config.decay;return!i||t<=1?1:jo(i,e,t)}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._ingestVersion)return this._datumIndexCache.map;let t=Wo(e);return this._datumIndexCache={version:this._ingestVersion,map:t},t}applyDecay(e,t){this.config.decay&&Yo(this.config.decay,e,t,this.getDatumIndexMap(t))}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&Vo(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}get transitionContext(){return{runtimeMode:this.config.runtimeMode,getX:this.getX,getY:this.getY,getCategory:this.getCategory,getPointId:this.getPointId}}get hasRenderedOnce(){return this._hasRenderedOnce}snapshotPositions(){Uo()?.snapshotPositions(this.transitionContext,this.scene,this.prevPositionMap,this.prevPathMap)}synthesizeIntroPositions(){this.prevPositionMap.clear(),this.prevPathMap.clear();let e=this.scales?.y(0)??0,t=Uo();if(t)for(let i=0;i<this.scene.length;i++){let r=this.scene[i],n=t.getNodeIdentity(this.transitionContext,r,i);n&&("point"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,r:0,opacity:0}):"rect"===r.type?this.prevPositionMap.set(n,{x:r.x,y:e,w:r.w,h:0,opacity:r.style.opacity??1}):"heatcell"===r.type?this.prevPositionMap.set(n,{x:r.x,y:r.y,w:r.w,h:r.h,opacity:0}):"line"===r.type?(r._introClipFraction=0,this.prevPathMap.set(n,{path:r.path.map(e=>[e[0],e[1]]),pathIds:r.pathIds?.slice(),opacity:r.style.opacity})):"area"===r.type&&(r._introClipFraction=0,this.prevPathMap.set(n,{topPath:r.topPath.map(e=>[e[0],e[1]]),bottomPath:r.bottomPath.map(e=>[e[0],e[1]]),pathIds:r.pathIds?.slice(),opacity:r.style.opacity})))}}startTransition(){let e=Uo();if(!this.config.transition||!e)return;let t=e.startTransition(this.transitionContext,this.config.transition,{scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},this.prevPositionMap,this.prevPathMap,this.currentTime());this.scene=t.scene,this.exitNodes=t.exitNodes,this.activeTransition=t.activeTransition}advanceTransition(e){let t=Uo();if(!this.activeTransition||!this.config.transition||!t)return!1;let i={scene:this.scene,exitNodes:this.exitNodes,activeTransition:this.activeTransition},r=t.advanceTransition(e,this.config.transition,i,this.prevPositionMap,this.prevPathMap);return this.scene=i.scene,this.exitNodes=i.exitNodes,this.activeTransition=i.activeTransition,r}cancelIntroAnimation(){this.prevPositionMap.clear(),this.prevPathMap.clear(),this.activeTransition=null,vs(this.scene),this.exitNodes=[]}groupData(e){let{result:t,cache:i}=ja(e,this.getGroup,this._ingestVersion,this._groupDataCache);return this._groupDataCache=i,t}resolveColorMap(e){let{map:t,cache:i}=Wa(e,this.getColor,this.config,this._ingestVersion,this._colorMapCache);return this._colorMapCache=i,t}resolveLineStyle(e,t){return qa(this.config,e,t,e=>this.resolveGroupColor(e))}resolveAreaStyle(e,t){return Xa(this.config,e,t,e=>this.resolveGroupColor(e))}resolveGroupColor(e){let{color:t,groupColorCounter:i}=Ya({group:e,colorMapCache:this._colorMapCache,groupColorMap:this._groupColorMap,groupColorCounter:this._groupColorCounter,groupColorMapCap:1e3,config:this.config});return this._groupColorCounter=i,t}getBufferArray(){return(this._bufferDirty||!this._bufferArrayCache)&&(this._bufferArrayCache=this.buffer.toArray(),this._bufferDirty=!1),this._bufferArrayCache}getData(){return this.getBufferArray()}remove(e){if(!this.getPointId)throw new Error("remove() requires pointIdAccessor to be configured");this.config.transition&&this.scene.length>0&&Uo()&&this.snapshotPositions();let t=zo(e),i=this.getPointId,r=e=>t.has(i(e));Ka(this.buffer,this.timestampBuffer,r);let n=this.buffer.remove(r);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(let e of n)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(e,t){if(!this.getPointId)throw new Error("update() requires pointIdAccessor to be configured");let i=zo(e),r=this.getPointId,n=/* @__PURE__ */new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&n.add(t)});let o=this.buffer.update(e=>i.has(r(e)),t);if(0===o.length)return this.updateResults.recordNoop("update"),o;for(let e of o)this.xExtent.evict(this.getX(e)),this.evictDatumYExtent(e);return this.buffer.forEach((e,t)=>{n.has(t)&&(this.xExtent.push(this.getX(e)),this.pushDatumYExtent(e))}),this.needsFullRebuild=!0,this._bufferDirty=!0,this._ingestVersion++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",o.length),o}getBinBoundaries(){return this._binBoundaries}getExtents(){return this.xExtent.min===1/0?null:{x:this.xExtent.extent,y:this.yExtent.extent}}clear(){this.buffer.clear(),this.resolveXAccessor(),this.xExtent.clear(),this.yExtent.clear(),this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.prevPathMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this._lastBoundedInsertsRef=null,this.needsFullRebuild=!0,this._bufferDirty=!0,this._bufferArrayCache=null,this._datumIndexCache=null,this.lastLayout=null,this.scales=null,this.scene=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,this.spatialIndex.clear(),this._colorMapCache=null,this._groupDataCache=null,this._groupColorMap=/* @__PURE__ */new Map,this._groupColorCounter=0,this._barCategoryCache=null,this._binBoundaries=[],this._stackExtentCache=null,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getBuffer(){return this.buffer}getXAccessor(){return this.getX}getYAccessor(){return this.getY}getCategoryAccessor(){return this.getCategory}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},n=i(r,t);r.style=n?{...e,...n}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e||"themeCategorical"in e||"colorAccessor"in e)&&(this._colorMapCache=null,this._groupColorMap=/* @__PURE__ */new Map,this._groupColorCounter=0),("barColors"in e||"colorScheme"in e)&&(this._barCategoryCache=null),("normalize"in e||"extentPadding"in e||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e||"boundsAccessor"in e||"band"in e||"y0Accessor"in e||"openAccessor"in e||"highAccessor"in e||"lowAccessor"in e||"closeAccessor"in e||"groupAccessor"in e||"categoryAccessor"in e||"chartType"in e||"runtimeMode"in e)&&(this._stackExtentCache=null);let r=!1,n=!1;Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let o="chartType"in e&&e.chartType!==t.chartType||"runtimeMode"in e&&e.runtimeMode!==t.runtimeMode;if(o||"xAccessor"in e||"yAccessor"in e||"timeAccessor"in e||"valueAccessor"in e){let e=["bar","swarm","waterfall"].includes(this.config.chartType)||"streaming"===this.config.runtimeMode,i=e&&this.config.timeAccessor||this.config.xAccessor,a=e&&t.timeAccessor||t.xAccessor,s=e&&this.config.valueAccessor||this.config.yAccessor,l=e&&t.valueAccessor||t.yAccessor,c=o||!Co(i,a),u=o||!Co(s,l);(c||u)&&(c&&this.resolveXAccessor(),this.getY=e?To(this.config.valueAccessor||this.config.yAccessor,"value"):To(this.config.yAccessor,"y"),u&&this.resolvedRibbons.some(e=>"bounds"===e.kind)&&(this.resolvedRibbons=ua(this.config)),r=!0,n=!0)}if("groupAccessor"in e&&!Co(e.groupAccessor,t.groupAccessor)&&(this.getGroup=null!=this.config.groupAccessor?Fo(this.config.groupAccessor):void 0,r=!0),"categoryAccessor"in e&&!Co(e.categoryAccessor,t.categoryAccessor)&&(this.getCategory=null!=this.config.categoryAccessor?Fo(this.config.categoryAccessor):void 0,r=!0),"sizeAccessor"in e&&!Co(e.sizeAccessor,t.sizeAccessor)&&(this.getSize=this.config.sizeAccessor?To(this.config.sizeAccessor,"size"):void 0,r=!0),"symbolAccessor"in e&&!Co(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Fo(this.config.symbolAccessor):void 0,r=!0),"colorAccessor"in e&&!Co(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Fo(this.config.colorAccessor):void 0,r=!0),"y0Accessor"in e&&!Co(e.y0Accessor,t.y0Accessor)&&(this.getY0=this.config.y0Accessor?To(this.config.y0Accessor,"y0"):void 0,r=!0,n=!0),("boundsAccessor"in e&&!Co(e.boundsAccessor,t.boundsAccessor)||"band"in e&&e.band!==t.band||"boundsStyle"in e&&e.boundsStyle!==t.boundsStyle)&&(this.resolvedRibbons=ua(this.config),r=!0,n=!0),"pointIdAccessor"in e&&!Co(e.pointIdAccessor,t.pointIdAccessor)&&(this.getPointId=null!=this.config.pointIdAccessor?Fo(this.config.pointIdAccessor):void 0,r=!0),"candlestick"===this.config.chartType&&(o||"openAccessor"in e&&!Co(e.openAccessor,t.openAccessor)||"closeAccessor"in e&&!Co(e.closeAccessor,t.closeAccessor)||"highAccessor"in e&&!Co(e.highAccessor,t.highAccessor)||"lowAccessor"in e&&!Co(e.lowAccessor,t.lowAccessor))){let e=null!=this.config.openAccessor,t=null!=this.config.closeAccessor;this.getOpen=e?To(this.config.openAccessor,"open"):void 0,this.getHigh=To(this.config.highAccessor,"high"),this.getLow=To(this.config.lowAccessor,"low"),this.getClose=t?To(this.config.closeAccessor,"close"):void 0,this.config.candlestickRangeMode=!e&&!t,r=!0,n=!0}if("accessorRevision"in e&&e.accessorRevision!==t.accessorRevision&&(this.resolveXAccessor(),r=!0,n=!0),!r){let i=Object.keys(e).filter(e=>!e.endsWith("Accessor")&&"timeAccessor"!==e&&"valueAccessor"!==e);for(let n of i)if(e[n]!==t[n]){r=!0;break}}r&&(n&&this.rebuildExtents(),this.needsFullRebuild=!0),this.updateResults.recordConfig(i,("bar"===this.config.chartType||"heatmap"===this.config.chartType)&&!this.config.trackHoverRows&&mn(t.areaStyle)!==mn(this.config.areaStyle))}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};function As(e,t,i,r){return"function"==typeof t.style?t.style(r||{},i):t.style&&"object"==typeof t.style?t.style:e.resolveBoundsStyle(i,r)}function Ms(e,t,i,r){if(!e.scales)return null;let{topPath:n,bottomPath:o,datum:a,pathIds:s}=ba(t,e.scales,e.getX,r.getTop,r.getBottom,e.getPointId);return n.length<2?null:{type:"area",topPath:n,bottomPath:o,...s&&{pathIds:s},...e.config.curve&&"linear"!==e.config.curve&&{curve:e.config.curve},style:As(e,r,i,gn(t)),datum:a,group:i,interactive:r.interactive}}function $s(e){let t=[],i=[];if(!e)return{perSeries:t,aggregate:i};for(let r of e)r.perSeries?t.push(r):i.push(r);return{perSeries:t,aggregate:i}}function _s(e,t,i){let r=[];for(let n of i){let i=Ms(e,t,"__ribbon_aggregate",n);i&&r.push(i)}return r}function Is(e,t,i,r){let n=[];for(let o of r){let r=Ms(e,t,i,o);r&&n.push(r)}return n}function Ps(e,t,i,r){if(!e.config.pointStyle)return;let n=r??e.getY;for(let r of t){let t=e.resolveGroupColor(r.key);for(let o of r.data){let r=e.config.pointStyle(o);!r.fill&&t&&(r={...r,fill:t});let a=r.r??3,s=e.getPointId?String(e.getPointId(o)):void 0,l=Ma(o,e.scales,e.getX,n,a,r,s);l&&i.push(l)}}}function Ls(e){return"threshold"===e.type&&"string"==typeof e.color&&"number"==typeof e.value}function Rs(e){return er(e)}function Cs(e,t){if("domain"!==e.extent)return;let[i,r]=t.domain(),n=t(r),o=t(i);return Number.isFinite(n)&&Number.isFinite(o)?[n,o]:void 0}function Ts(e,t){let i=[],r="bubble"===e.config.chartType?10:5,n=e.config.sizeRange||[3,15],o=null;if(e.getSize&&!e.config.pointStyle){let i=t.map(t=>e.getSize(t)).filter(e=>null!=e&&!Number.isNaN(e));if(i.length>0){let e=1/0,t=-1/0;for(let r of i)r<e&&(e=r),r>t&&(t=r);o=i=>e===t?(n[0]+n[1])/2:n[0]+(i-e)/(t-e)*(n[1]-n[0])}}let a=e.getColor?e.resolveColorMap(t):null,s=e.config.themeSemantic?.primary||"#4e79a7",l=e.getSymbol,u=l?c(l,e.config.symbolMap):null;for(let n of t){let t=e.config.pointStyle?e.config.pointStyle(n):{fill:s,opacity:.8},l=t.r||r;if(o&&e.getSize){let t=e.getSize(n);null!=t&&!Number.isNaN(t)&&(l=o(t))}if(a&&e.getColor&&!t.fill){let i=e.getColor(n);i&&a.has(i)&&(t={...t,fill:a.get(i)})}let c=e.getPointId?String(e.getPointId(n)):void 0;if(u){let r=u(n),o=$a(n,e.scales,e.getX,e.getY,Math.PI*l*l,r,t,c);o&&i.push(o)}else{let r=Ma(n,e.scales,e.getX,e.getY,l,t,c);r&&i.push(r)}}return i}var Ns=/* @__PURE__ */new Map;function Fs(e,t,i){return t===i?Math.floor(128):Math.min(Math.floor(255*(e-t)/(i-t)+.5),255)}function Es(e){let t=Object.prototype.hasOwnProperty.call(fi,e)?e:"blues",i=Ns.get(t);if(i)return i;i=new Array(256);let r=pi(t);for(let e=0;e<256;e++)i[e]=r(e/255);return Ns.set(t,i),i}function Os(e,t,i){let r=i.config.areaStyle?.(t);return r&&("string"==typeof r.fill&&(e.fill=r.fill),e.style=r),e}function zs(e,t,i){let r=Math.max(1,Math.floor(e.config.heatmapXBins??20)),n=Math.max(1,Math.floor(e.config.heatmapYBins??20)),o=e.config.heatmapAggregation??"count",a=To(e.config.valueAccessor,"value");if(!e.scales||0===t.length)return[];let[s,l]=e.scales.x.domain(),[c,u]=e.scales.y.domain(),d=(l-s||1)/r,h=(u-c||1)/n,f=r*n;if(f>1e6)return[];let p=new Int32Array(f),g=new Float64Array(f),m=e.config.trackHoverRows||mn(e.config.areaStyle)?/* @__PURE__ */new Map:void 0;for(let i=0;i<t.length;i++){let o=t[i],l=e.getX(o),u=e.getY(o);if(!isFinite(l)||!isFinite(u))continue;let f=Math.min(Math.floor((l-s)/d),r-1),y=Math.min(Math.floor((u-c)/h),n-1);if(f<0||y<0)continue;let x=y*r+f;p[x]++;let b=a(o);if(g[x]+=isFinite(b)?b:0,m){let e=m.get(x);e||(e=[],m.set(x,e)),e.push(o)}}let y=1/0,x=-1/0;for(let e=0;e<f;e++){if(0===p[e])continue;let t;switch(o){case"sum":t=g[e];break;case"mean":t=g[e]/p[e];break;default:t=p[e]}t<y&&(y=t),t>x&&(x=t)}if(!isFinite(y))return[];let b=e.config.heatmapColorScale,v="string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues",w=b?void 0:Es(v),k=i.width/r,S=i.height/n,A=e.config.showValues,M=e.config.heatmapValueFormat,$=[];for(let t=0;t<n;t++){let i=t*r;for(let a=0;a<r;a++){let r,l=i+a;if(0===p[l])continue;switch(o){case"sum":r=g[l];break;case"mean":r=g[l]/p[l];break;default:r=p[l]}let u=Fs(r,y,x),f=b?b(r):w[u],v=A?{value:r,showValues:!0,valueFormat:M}:{value:r},_=s+(a+.5)*d,I=c+(t+.5)*h,P=hn({xi:a,yi:t,value:r,count:p[l],sum:g[l],xCenter:_,yCenter:I,agg:o},m?.get(l));$.push(Os(Ia(a*k,(n-1-t)*S,k,S,f,P,v),P,e))}}return $}function Ds(e){if(!Array.isArray(e))return;let t=e.filter(e=>!!e&&("string"==typeof e.fill||"object"==typeof e.fill&&null!==e.fill)),i=t.filter(e=>"number"==typeof e.upTo&&Number.isFinite(e.upTo)).map(e=>({upTo:e.upTo,fill:e.fill})).sort((e,t)=>e.upTo-t.upTo),r=t.find(e=>"number"!=typeof e.upTo||!Number.isFinite(e.upTo)),n=r?[...i,{upTo:1/0,fill:r.fill}]:i;return n.length>0?n:void 0}function Bs(e,t,i,r){let n=Math.min(t,i),o=Math.max(t,i);if(!(o>n))return[];let a=[],s=-1/0;for(let t of e){let e=Math.max(s,n),i=Math.min(t.upTo,o);if(i>e&&a.push({from:e,to:i,fill:t.fill}),s=t.upTo,s>=o)break}return s<o&&a.push({from:Math.max(s,n),to:o,fill:r}),a}var js={line:function(e,t){let i=e.groupData(t),r=[],n=e.config.annotations?.filter(Ls).map(e=>({value:e.value,color:e.color,thresholdType:e.thresholdType||"greater"}));if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=$s(e.ribbons);if(o.length>0&&r.push(..._s(e,t,o)),n.length>0)for(let t of i)r.push(...Is(e,t.data,t.key,n))}for(let t of i){let i=e.resolveLineStyle(t.key,gn(t.data)),o=va(t.data,e.scales,e.getX,e.getY,i,t.key,e.getPointId);n&&n.length>0&&(o.colorThresholds=n),e.config.curve&&"linear"!==e.config.curve&&(o.curve=e.config.curve),e.config.lineGradient&&(o.strokeGradient=e.config.lineGradient),r.push(o)}return Ps(e,i,r),r},area:function(e,t){let i=e.groupData(t),r=[];if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=$s(e.ribbons);if(o.length>0&&r.push(..._s(e,t,o)),n.length>0)for(let t of i)r.push(...Is(e,t.data,t.key,n))}let n=e.scales.y.domain(),o=n[0],a=e.config.semanticLineStops?.filter(e=>Number.isFinite(e.offset)).map(e=>({value:n[0]+Math.max(0,Math.min(1,e.offset))*(n[1]-n[0]),color:e.color,opacity:e.opacity,thresholdType:"greater"})).sort((e,t)=>e.value-t.value),s=a&&a.length>0?(()=>{let t=a.reduce((e,t)=>(e.at(-1)?.value===t.value?e[e.length-1]=t:e.push(t),e),[]),i=[{from:n[0],to:t[0].value,color:t[0].color,opacity:t[0].opacity}];for(let e=0;e<t.length;e++)i.push({from:t[e].value,to:t[e+1]?.value??n[1],color:t[e].color,opacity:t[e].opacity});return i.map(({from:t,to:i,color:r,opacity:n})=>{let o=e.scales.y(t),a=e.scales.y(i);return{y:Math.min(o,a),height:Math.abs(a-o),color:r,...null!=n&&{opacity:n}}}).filter(e=>e.height>0)})():void 0,l=e.getY0?t=>e.getY0(t)??o:void 0;for(let t of i){let i=e.resolveAreaStyle(t.key,gn(t.data)),n=wa(t.data,e.scales,e.getX,e.getY,o,i,t.key,l,e.getPointId),c=Rs(e.config.gradientFill);if(c){n.fillGradient=c;let t=Cs(c,e.scales.y);t&&(n.fillGradientSpan=t)}e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),a&&a.length>0&&(n.colorThresholds=a,n.strokeColorBands=s),r.push(n)}return Ps(e,i,r),r},stackedarea:function(e,t){let i=e.groupData(t),r=e.config.stackOrder??"key",n=()=>i.sort((e,t)=>e.key<t.key?-1:e.key>t.key?1:0);if("input"!==r)if("key"===r)n();else if("asc"===r||"desc"===r||"insideOut"===r){let t=/* @__PURE__ */new Map;for(let r of i){let i=0;for(let t of r.data){let r=e.getX(t),n=e.getY(t);Number.isFinite(r)&&Number.isFinite(n)&&(i+=n)}t.set(r.key,i)}let n=(e,t)=>e<t?-1:e>t?1:0;if("asc"===r)i.sort((e,i)=>{let r=(t.get(e.key)??0)-(t.get(i.key)??0);return 0!==r?r:n(e.key,i.key)});else if("desc"===r)i.sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:n(e.key,i.key)});else{let e=[...i].sort((e,i)=>{let r=(t.get(i.key)??0)-(t.get(e.key)??0);return 0!==r?r:n(e.key,i.key)}),r=[],o=[],a=0,s=0;for(let i of e)a<s?(r.push(i),a+=t.get(i.key)??0):(o.push(i),s+=t.get(i.key)??0);i.length=0,i.push(...o.reverse(),...r)}}else n();let o=e.config.curve&&"linear"!==e.config.curve?e.config.curve:void 0,a=e.config.normalize?"zero":e.config.baseline??"zero",{nodes:s,stackedTops:l}=Aa(i,e.scales,e.getX,e.getY,(t,i)=>e.resolveAreaStyle(t,i),e.config.normalize,o,a,e.getPointId),c=s;if(e.config.pointStyle){let t=/* @__PURE__ */new WeakMap;for(let r of i){let i=l.get(r.key);if(i)for(let n of r.data){let r=e.getX(n),o=e.getY(n);null!=r&&!Number.isNaN(r)&&null!=o&&!Number.isNaN(o)&&i.has(r)&&t.set(n,i.get(r))}}Ps(e,i,c,i=>t.get(i)??e.getY(i))}return c},mixed:function(e,t){let i=e.groupData(t),r=[],n=e.config.areaGroups||/* @__PURE__ */new Set;if(e.ribbons&&e.ribbons.length>0){let{perSeries:n,aggregate:o}=$s(e.ribbons);if(o.length>0&&r.push(..._s(e,t,o)),n.length>0)for(let t of i)r.push(...Is(e,t.data,t.key,n))}let o=e.scales.y.domain()[0],a=e.getY0?t=>e.getY0(t)??o:void 0;for(let t of i)if(n.has(t.key)){let i=e.resolveAreaStyle(t.key,gn(t.data)),n=wa(t.data,e.scales,e.getX,e.getY,o,i,t.key,a,e.getPointId),s=Rs(e.config.gradientFill);if(s){n.fillGradient=s;let t=Cs(s,e.scales.y);t&&(n.fillGradientSpan=t)}e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),r.push(n)}else{let i=e.resolveLineStyle(t.key,gn(t.data)),n=va(t.data,e.scales,e.getX,e.getY,i,t.key,e.getPointId);e.config.curve&&"linear"!==e.config.curve&&(n.curve=e.config.curve),e.config.lineGradient&&(n.strokeGradient=e.config.lineGradient),r.push(n)}return Ps(e,i,r),r},scatter:Ts,bubble:Ts,heatmap:function(e,t,i){if(e.config.heatmapAggregation)return zs(e,t,i);if(0===t.length)return[];let r=To(e.config.valueAccessor,"value"),n=No(e.config.xAccessor,"x"),o=No(e.config.yAccessor,"y"),a=/* @__PURE__ */new Map,s=/* @__PURE__ */new Map,l=new Array(t.length),c=new Array(t.length);for(let e=0;e<t.length;e++){let i=t[e],r=n(i),u=o(i);l[e]=r,c[e]=u,a.has(r)||a.set(r,a.size),s.has(u)||s.set(u,s.size)}let u=a.size,d=s.size;if(0===u||0===d)return[];let h=Array.from(a.keys()),f=Array.from(s.keys()),p=h.every(e=>"number"==typeof e&&!isNaN(e)),g=f.every(e=>"number"==typeof e&&!isNaN(e)),m=4096;if(p&&g&&u*d>m&&t.length>m){let r=/* @__PURE__ */new Set;for(let n=0;n<t.length;n++){let o=a.get(l[n]),d=s.get(c[n]);if(void 0!==o&&void 0!==d&&(r.add(d*u+o),r.size>m))return zs({...e,config:{...e.config,heatmapAggregation:e.config.valueAccessor?"mean":"count"}},t,i)}}if(p){h.sort((e,t)=>Number(e)-Number(t)),a.clear();for(let e=0;e<h.length;e++)a.set(h[e],e)}if(g){f.sort((e,t)=>Number(e)-Number(t)),s.clear();for(let e=0;e<f.length;e++)s.set(f[e],e)}let y=new Float64Array(t.length),x=new Float64Array(t.length),b=new Array(t.length),v=/* @__PURE__ */new Map,w=0;for(let e=0;e<t.length;e++){let i=t[e],n=a.get(l[e]),o=s.get(c[e]);if(void 0===n||void 0===o)continue;let d,h=r(i),f=o*u+n,p=v.get(f);void 0!==p?d=p:(d=w++,v.set(f,d)),y[d]=f,x[d]=h,b[d]=i}let k=1/0,S=-1/0;for(let e=0;e<w;e++){let t=x[e];isFinite(t)&&(t<k&&(k=t),t>S&&(S=t))}if(!isFinite(k)||!isFinite(S))return[];let A="string"==typeof e.config.colorScheme?e.config.colorScheme:e.config.themeSequential||"blues",M=e.config.heatmapColorScale,$=M?void 0:Es(A),_=i.width/u,I=i.height/d,P=e.config.showValues,L=e.config.heatmapValueFormat,R=[];for(let t=0;t<w;t++){let i=x[t];if(!isFinite(i))continue;let r=y[t],n=r%u,o=(r-n)/u,a=Fs(i,k,S),s=M?M(i):$[a],l=P?{value:i,showValues:!0,valueFormat:L}:{value:i},c=b[t];R.push(Os(Ia(n*_,(d-1-o)*I,_,I,s,c,l),c,e))}return R},bar:function(e,t){if(!e.config.binSize)return{nodes:[],binBoundaries:[]};let i=ma(t,e.getX,e.getY,e.config.binSize,e.getCategory,!!e.config.trackHoverRows||mn(e.config.areaStyle));if(0===i.size)return{nodes:[],binBoundaries:[]};let r=null;if(e.getCategory){let t=/* @__PURE__ */new Set;for(let e of i.values())for(let i of e.categories.keys())t.add(i);let n=e.config.barColors?Object.keys(e.config.barColors):[],o=new Set(n),a=Array.from(t).filter(e=>!o.has(e)).sort(),s=n.filter(e=>t.has(e)),l=s.join("\0")+""+a.join("\0");e.barCategoryCache&&e.barCategoryCache.key===l?r=e.barCategoryCache.order:(r=[...s,...a],e.barCategoryCache={key:l,order:r})}let n=[],o=e.scales,[a,s]=o.x.domain(),l=e.config.barStyle,c=e.config.themeSemantic?.primary,u=l?.gap,d="number"==typeof u&&u>=0?u:1,h={};l?.stroke&&(h.stroke=l.stroke),"number"==typeof l?.strokeWidth&&(h.strokeWidth=l.strokeWidth),"number"==typeof l?.opacity&&(h.opacity=l.opacity),l?.cursor&&(h.cursor=l.cursor);let f=Ds(l?.valueBands);for(let t of i.values()){let i=Math.max(t.start,a),u=Math.min(t.end,s);if(i>=u)continue;let p=o.x(i),g=o.x(u),m=Math.abs(g-p),y=m>d+1?d:0,x=Math.min(p,g)+y/2,b=Math.max(m-y,1);if(!(b<=0))if(r&&t.categories.size>0){let i=hn(r.flatMap(e=>{let i=t.categories.get(e)||0;return 0===i?[]:[hn({category:e,value:i},t.categoryRows?.get(e))]}),t.rows),a=0;for(let{category:r,value:s}of i){let u=o.y(a),d=o.y(a+s),f=Math.min(u,d),p=Math.abs(u-d),g=(e.config.barColors?Ri(e.config.barColors,r):void 0)??l?.fill??c??"#4e79a7",m=hn({binStart:t.start,binEnd:t.end,total:t.total,category:r,categoryValue:s,categories:i},t.categoryRows?.get(r)),y=e.config.areaStyle?.(m)??{};n.push(_a(x,f,b,p,{fill:g,...h,...y},m,r)),a+=s}}else{let i=o.y(0),r=o.y(t.total),a=Math.min(i,r),s=Math.abs(i-r),u=l?.fill||c||"#007bff",d=hn({binStart:t.start,binEnd:t.end,total:t.total},t.rows),p=e.config.areaStyle?.(d)??{},g=_a(x,a,b,s,{fill:u,...h,...p},d);if(f){let e=g.style.fill,i="string"==typeof e||"object"==typeof e&&null!==e&&"hatch"===e.type?e:void 0,r=Bs(f,0,t.total,i);r.length>0&&(g.fillBands=r.map(e=>({y0:o.y(e.from),y1:o.y(e.to),fill:e.fill??u})))}n.push(g)}}let p=/* @__PURE__ */new Set;for(let e of i.values())p.add(e.start),p.add(e.end);return{nodes:n,binBoundaries:Array.from(p).sort((e,t)=>e-t)}},swarm:function(e,t){let i=[],r=e.config.swarmStyle||{},n=r.radius??3,o=r.fill??e.config.themeSemantic?.primary??"#007bff",a=r.opacity??.7,s=r.stroke,l=r.strokeWidth,c=r.cursor;for(let r of t){let t=e.getX(r),u=e.getY(r);if(null==u||Number.isNaN(u))continue;let d=e.scales.x(t),h=e.scales.y(u),f=o;if(e.getCategory){let t=String(e.getCategory(r));f=(e.config.barColors?Ri(e.config.barColors,t):void 0)??f}let{r:p,...g}=e.config.pointStyle?.(r)??{},m={type:"point",x:d,y:h,r:p??n,style:{fill:f,opacity:a,stroke:s,strokeWidth:l,cursor:c,...g},datum:r};e.getPointId&&(m.pointId=String(e.getPointId(r))),i.push(m)}return i},waterfall:function(e,t,i){let r=[],n=e.scales,o=e.config.waterfallStyle,a=t.filter(t=>{let i=e.getY(t),r=e.getX(t);return null!=i&&!Number.isNaN(i)&&null!=r&&isFinite(r)});if(0===a.length)return r;let s=o?.positiveColor??e.config.themeSemantic?.success??"#28a745",l=o?.negativeColor??e.config.themeSemantic?.danger??"#dc3545",c=o?.gap??1,u=o?.stroke,d=o?.strokeWidth,h=o?.opacity,f=0;for(let t=0;t<a.length;t++){let p=a[t],g=e.getX(p),m=e.getY(p),y=f+m,x=n.x(g),b=t>0?n.x(e.getX(a[t-1])):void 0,v=t<a.length-1?n.x(e.getX(a[t+1])):void 0,w=null!=b?(b+x)/2:null!=v?x-(v-x)/2:x-i.width/20,k=null!=v?(x+v)/2:null!=b?x+(x-b)/2:x+i.width/20,S=Math.min(w,k)+c/2,A=Math.max(w,k)-c/2-S;if(A<=0){f=y;continue}let M=n.y(f),$=n.y(y),_=Math.min(M,$),I=Math.abs(M-$),P=m>=0?s:l,L={...p,baseline:f,cumEnd:y,delta:m,_connectorStroke:o?.connectorStroke,_connectorWidth:o?.connectorWidth},R={fill:P,stroke:u,strokeWidth:d,opacity:h,cursor:o?.cursor,...e.config.areaStyle?.(L)};r.push(_a(S,_,A,I,R,L)),f=y}return r},candlestick:function(e,t,i){if(!e.getHigh||!e.getLow||!e.scales)return[];let r=e.config.candlestickRangeMode??!1;if(!(r||e.getOpen&&e.getClose))return[];let n=[],o=e.config.candlestickStyle||{},a=o.rangeColor||"#6366f1",s=r?a:o.upColor||"#28a745",l=r?a:o.downColor||"#dc3545",c=r?a:o.wickColor||"#333",u=o.wickWidth||(r?2:1),d=o.bodyWidth??0;if(null==o.bodyWidth){let i=t.map(t=>e.getX(t)).filter(e=>null!=e&&!Number.isNaN(e)).sort((e,t)=>e-t);if(i.length>1){let t=1/0,r=e.scales.x(i[0]);for(let n=1;n<i.length;n++){let o=e.scales.x(i[n]),a=Math.abs(o-r);a>0&&a<t&&(t=a),r=o}d=t!==1/0?Math.max(2,Math.min(.6*t,20)):6}else d=6}for(let a of t){let t=e.getX(a);if(null==t||Number.isNaN(t))continue;let h=e.getHigh(a),f=e.getLow(a);if(null==h||Number.isNaN(h)||null==f||Number.isNaN(f))continue;let p=r?h:e.getOpen(a),g=r?f:e.getClose(a);if(!r&&(null==p||Number.isNaN(p)||null==g||Number.isNaN(g)))continue;let m=g>=p,y=e.config.pointStyle?.(a)??{},x="string"==typeof y.fill?y.fill:void 0,b="string"==typeof y.stroke?y.stroke:void 0,v="number"==typeof y.strokeWidth?y.strokeWidth:void 0,w="number"==typeof y.opacity?y.opacity:"number"==typeof y.fillOpacity?y.fillOpacity:void 0,k={type:"candlestick",x:e.scales.x(t),openY:e.scales.y(p),closeY:e.scales.y(g),highY:e.scales.y(h),lowY:e.scales.y(f),bodyWidth:d,upColor:x&&m?x:s,downColor:x&&!m?x:l,wickColor:b??(r&&x?x:c),wickWidth:v??u,isUp:m,style:{cursor:o.cursor,...y,...void 0!==w&&{opacity:w}},datum:a};r&&(k.isRange=!0,k.dotRadius=Math.max(2,Math.min(d/2,.12*i.height))),n.push(k)}return n},custom:()=>[]};function Ws(){for(let e of Object.keys(js))Qo(e)||Zo({chartType:e,buildScene:js[e],canvasRenderers:[]})}function Ys(e){let t=e.parts.filter(e=>null!=e),i={};for(let e of t)for(let[t,r]of Object.entries(e.markCountByType))i[t]=(i[t]??0)+r;for(let[t,r]of Object.entries(e.additionalMarkCountByType??{}))r>0&&(i[t]=(i[t]??0)+r);let r=Object.values(i).reduce((e,t)=>e+t,0),n=0===r,o=Array.from(
4
- /* @__PURE__ */new Set([...t.flatMap(e=>e.warnings),...e.extraWarnings??[],...n?["EMPTY_SCENE"]:[]])),a="string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${r} marks`;return{component:"",frameType:e.frameType,status:n?"empty":"ok",empty:n,markCount:r,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:t.reduce((e,t)=>e+t.annotationCount,0),ariaLabel:a,warnings:o,semanticStatus:"not-assessed",semanticDiagnostics:[]}}function qs(e){let t={};for(let i of e){let e="string"==typeof i?.type&&i.type.length>0?i.type:"node";t[e]=(t[e]??0)+1}return{count:e.length,byType:t}}function Xs(e){let t=e instanceof Date?e.getTime():"number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Gs(e){if(!e||e.length<2)return;let t=Xs(e[0]),i=Xs(e[e.length-1]);return null!==t&&null!==i?[t,i]:void 0}function Vs(e){let{count:t,byType:i}=qs(e.marks),r=0===t,n=[...e.extraWarnings??[]];r&&!n.includes("EMPTY_SCENE")&&n.push("EMPTY_SCENE"),e.annotationRender&&e.annotationRender.unrenderedCount>0&&!n.includes("UNRENDERED_ANNOTATIONS")&&n.push("UNRENDERED_ANNOTATIONS");let o=Array.isArray(e.annotations)?e.annotations.length:0,a=e.annotationRender?.renderedCount??o,s="string"==typeof e.description&&e.description||"string"==typeof e.title&&e.title||`${e.frameType} chart, ${t} marks`,l=e.margin,c=l?{x:l.left,y:l.top,width:Math.max(1,e.width-l.left-l.right),height:Math.max(1,e.height-l.top-l.bottom)}:void 0;return{component:"",frameType:e.frameType,status:r?"empty":"ok",empty:r,markCount:t,markCountByType:i,width:e.width,height:e.height,...e.xDomain?{xDomain:e.xDomain}:{},...e.yDomain?{yDomain:e.yDomain}:{},...e.categories?{categories:e.categories}:{},...void 0!==e.nodeCount?{nodeCount:e.nodeCount}:{},...void 0!==e.edgeCount?{edgeCount:e.edgeCount}:{},...void 0!==e.legendItems?{legendItems:e.legendItems}:{},annotationCount:a,...e.annotationRender?.layout?{layout:e.annotationRender.layout}:{},...e.annotationRender?{annotationInputCount:e.annotationRender.inputCount,unrenderedAnnotationCount:e.annotationRender.unrenderedCount,...e.annotationRender.unrenderedTypes.length>0?{unrenderedAnnotationTypes:e.annotationRender.unrenderedTypes}:{}}:{},ariaLabel:s,warnings:n,semanticStatus:"not-assessed",semanticDiagnostics:[],...l?{margin:l}:{},...c?{plot:c}:{}}}import*as Hs from"react";import{area as Us,line as Ks}from"d3-shape";function Zs(e){let t=Number.isFinite(e)&&e>0?e:6;return{width:Math.max(8,t),height:t,lineY:t/2}}import{jsx as Qs,jsxs as Js}from"react/jsx-runtime";function el(e){return"object"==typeof e&&null!==e&&"hatch"===e.type}function tl(e){return["hatch",e.background??"transparent",e.stroke??"#000",e.lineWidth??1.5,e.spacing??6,e.angle??45,e.lineOpacity??1].join("|")}function il(e,t){return`${e}-hatch-${xn(tl(t)).toString(36)}`}function rl(e,t){let{background:i="transparent",stroke:r="#000",lineWidth:n=1.5,spacing:o=6,angle:a=45,lineOpacity:s=1}=e,l=Zs(o);/* @__PURE__ */
5
- return Js("pattern",{id:t,width:l.width,height:l.height,patternUnits:"userSpaceOnUse",patternTransform:0!==a?`rotate(${a})`:void 0,children:[i&&"transparent"!==i&&"none"!==i&&/* @__PURE__ */Qs("rect",{width:l.width,height:l.height,fill:i}),
6
- /* @__PURE__ */Qs("line",{x1:0,y1:l.lineY,x2:l.width,y2:l.lineY,stroke:r,strokeWidth:n,...1!==s?{strokeOpacity:s}:{}})]},t)}function nl(e,t,i="#4e79a7"){if(el(e)){let i=il(t,e);return{fill:`url(#${i})`,def:rl(e,i)}}return e&&"string"==typeof e?{fill:e}:{fill:i}}function ol(e,t,i){if(!e||"object"!=typeof e)return;let r=e;if(!Array.isArray(r.stops))return;let n=r.stops.flatMap(e=>{if(!e||"object"!=typeof e)return[];let{offset:t,color:r,opacity:n}=e;return"number"==typeof t&&Number.isFinite(t)?[{offset:Math.max(0,Math.min(1,t)),color:"string"==typeof r&&r?r:i,opacity:"number"==typeof n&&Number.isFinite(n)?Math.max(0,Math.min(1,n)):void 0}]:[]}).sort((e,t)=>e.offset-t.offset);return n.length?{direction:"horizontal"===r.direction?"horizontal":"vertical"===r.direction?"vertical":t,stops:n}:void 0}function al(e,t,i,r){let n=ol(e,i,r);if(!n)return;let{direction:o,stops:a}=n,s=`${t}-gradient`;return{fill:`url(#${s})`,def:/* @__PURE__ */Qs("linearGradient",{id:s,x1:0,y1:0,x2:"horizontal"===o?"100%":0,y2:"vertical"===o?"100%":0,children:a.map((e,t)=>/* @__PURE__ */Qs("stop",{offset:100*e.offset+"%",stopColor:e.color,stopOpacity:e.opacity},`${e.offset}-${t}`))},s)}}import{curveMonotoneX as sl,curveMonotoneY as ll,curveCardinal as cl,curveCatmullRom as ul,curveStep as dl,curveStepBefore as hl,curveStepAfter as fl,curveBasis as pl,curveNatural as gl}from"d3-shape";function ml(e){switch(e){case"monotoneX":return sl;case"monotoneY":return ll;case"cardinal":return cl;case"catmullRom":return ul;case"step":return dl;case"stepBefore":return hl;case"stepAfter":return fl;case"basis":return pl;case"natural":return gl;default:return null}}function yl(e,t,i){let r=i;for(let i of t)"lesser"===i.thresholdType?e<i.value&&(r=i.color):e>i.value&&(r=i.color);return r}function xl(e,t,i,r){if(e.length<2||t.length!==e.length||0===i.length)return[];let n=[],o=(e,t,i)=>{let r=n[n.length-1];r?.color===e?r.path.push(i):n.push({color:e,path:[t,i]})};for(let n=1;n<e.length;n++){let[a,s]=e[n-1],[l,c]=e[n],u=t[n-1],d=t[n]-u,h=[0,...0===d?[]:i.map(({value:e})=>(e-u)/d).filter(e=>e>0&&e<1&&Number.isFinite(e)).sort((e,t)=>e-t).filter((e,t,i)=>0===t||e!==i[t-1]),1];for(let e=1;e<h.length;e++){let t=h[e-1],n=h[e];o(yl(u+d*((t+n)/2),i,r),[a+(l-a)*t,s+(c-s)*t],[a+(l-a)*n,s+(c-s)*n])}}return n}import*as bl from"react";function vl(e){return(e.tl??0)>0||(e.tr??0)>0||(e.br??0)>0||(e.bl??0)>0}function wl(e){let t=e.cornerRadii;if(!t)return{tl:0,tr:0,br:0,bl:0};let i=Math.min(e.w,e.h)/2,r=e=>Math.max(0,Math.min(e??0,i));return{tl:r(t.tl),tr:r(t.tr),br:r(t.br),bl:r(t.bl)}}import{jsx as kl,jsxs as Sl}from"react/jsx-runtime";var Al={innerRadius:0,outerRadius:0,startAngle:0,endAngle:0};function Ml(e,t="#4e79a7"){return el(e)?e.background&&"transparent"!==e.background?e.background:t:e&&"string"==typeof e?e:t}function $l(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?`s_${t}`:t}function _l(e,t,i,r){let n=e.glyph;if(!n?.parts?.length||e.size<=0)return null;let o=u(n,e.size);if(o.scale<=0)return null;let a=`translate(${t},${i})${e.rotation?` rotate(${180*e.rotation/Math.PI})`:""} translate(${o.offsetX},${o.offsetY}) scale(${o.scale})`,s=e.color??("string"==typeof e.style.fill?e.style.fill:void 0),l=h(n,e.fraction??1,e.fractionStart??0,e.fractionDirection??"horizontal"),c=l?$l(`${r}-clip`):void 0,f=(e.style.opacity??1)*(e._decayOpacity??1)*(e.style.fillOpacity??1),p=t=>n.parts.map((i,r)=>{let n=t?"none"===i.fill?void 0:t:d(i.fill,s,e.accent),o=t?i.stroke&&"none"!==i.stroke?t:void 0:d(i.stroke??"none",s,e.accent);return n||o?/* @__PURE__ */kl("path",{d:i.d,fill:n??"none",stroke:o,strokeWidth:o?i.strokeWidth??1:void 0,strokeLinecap:i.strokeLinecap,strokeLinejoin:i.strokeLinejoin,opacity:i.opacity},r):null});/* @__PURE__ */
7
- return Sl("g",{transform:a,opacity:1===f?void 0:f,children:[l&&c&&/* @__PURE__ */kl("clipPath",{id:c,children:/* @__PURE__ */kl("rect",{x:l.x,y:l.y,width:l.width,height:l.height})}),l&&e.ghostColor?/* @__PURE__ */kl("g",{children:p(e.ghostColor)}):null,l&&c?/* @__PURE__ */kl("g",{clipPath:`url(#${c})`,children:p()}):p()]},r)}function Il(e,t){let i=e.filter(e=>Number.isFinite(e.offset)&&(null==e.opacity||Number.isFinite(e.opacity))).map(e=>({offset:Math.max(0,Math.min(1,e.offset)),color:e.color??t,opacity:null==e.opacity?void 0:Math.max(0,Math.min(1,e.opacity))}));return i.length<2?null:i.map((e,t)=>/* @__PURE__ */kl("stop",{offset:e.offset,stopColor:e.color,stopOpacity:e.opacity},t))}function Pl(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=e.x,n=e.y,o=e.x,a=e.y+e.h;"bottom"===e.roundedEdge?(n=e.y+e.h,a=e.y):"right"===e.roundedEdge?(r=e.x+e.w,n=e.y,o=e.x,a=e.y):"left"===e.roundedEdge&&(r=e.x,n=e.y,o=e.x+e.w,a=e.y);let s=Il(i.stops,Ml(e.style.fill));return s?/* @__PURE__ */kl("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:r,y1:n,x2:o,y2:a,children:s}):null}function Ll(e){let{x:t,y:i,w:r,h:n}=e,{tl:o,tr:a,br:s,bl:l}=wl(e),c=`M${t+o},${i}`;return c+=` L${t+r-a},${i}`,a>0&&(c+=` A${a},${a} 0 0 1 ${t+r},${i+a}`),c+=` L${t+r},${i+n-s}`,s>0&&(c+=` A${s},${s} 0 0 1 ${t+r-s},${i+n}`),c+=` L${t+l},${i+n}`,l>0&&(c+=` A${l},${l} 0 0 1 ${t},${i+n-l}`),c+=` L${t},${i+o}`,o>0&&(c+=` A${o},${o} 0 0 1 ${t+o},${i}`),c+=" Z",c}function Rl(e,t,i){let r=s(e.symbolType,e.size,e.path),n=e.rotation?`translate(${e.x},${e.y}) rotate(${180*e.rotation/Math.PI})`:`translate(${e.x},${e.y})`;/* @__PURE__ */
8
- return kl("path",{d:r,transform:n,fill:e.style.fill?Ml(e.style.fill):"none",fillOpacity:e.style.fillOpacity,opacity:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth},`${i??""}symbol-${t}`)}function Cl(e,t,i){let r=e.y,n=e.y+e.h,o=[],a=[];e.fillBands.forEach((t,s)=>{let l,c=Math.max(Math.min(t.y0,t.y1),r),u=Math.min(Math.max(t.y0,t.y1),n);if(u>c){if(el(t.fill)){let e=`${i}-band-${s}`;o.push(rl(t.fill,e)),l=`url(#${e})`}else l=Ml(t.fill);a.push(/* @__PURE__ */kl("rect",{x:e.x,y:c,width:e.w,height:u-c,fill:l},s))}});let s=e.style.stroke&&"none"!==e.style.stroke;/* @__PURE__ */
9
- return Sl("g",{opacity:e.style.opacity,children:[o.length>0&&/* @__PURE__ */kl("defs",{children:o}),a,s&&/* @__PURE__ */kl("rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:"none",stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},`rect-${t}`)}function Tl(e,t,i){let r="point"===e.type,n=r?"circle":"rect",o=r?{cx:e.x,cy:e.y,r:e.r}:{x:e.x,y:e.y,width:e.w,height:e.h},a=`${i?`${i}-`:""}${r?"point":"xyrect"}-${t}-hatch`;if(!r&&e.fillBands&&e.fillBands.length>0)return Cl(e,t,a);let s=el(e.style.fill)?rl(e.style.fill,a):void 0;/* @__PURE__ */
10
- return Sl(bl.Fragment,{children:[s&&/* @__PURE__ */kl("defs",{children:s}),bl.createElement(n,{...o,fill:s?`url(#${a})`:Ml(e.style.fill),opacity:r?e.style.opacity??e.style.fillOpacity??.8:e.style.opacity,stroke:e.style.stroke,strokeWidth:e.style.strokeWidth})]},`${e.type}-${t}`)}import*as Nl from"react";import{jsx as Fl}from"react/jsx-runtime";function El(e){if(!1!==e?.interactive)return e?.style?.cursor}function Ol(e,t,i){let r=El(t);return r&&null!=e&&!1!==e?/* @__PURE__ */Fl("g",{style:{cursor:r},"data-semiotic-mark-cursor":r,children:e},i):e}import{jsx as zl,jsxs as Dl}from"react/jsx-runtime";function Bl(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}function jl(e,t){let i=e.fillGradient;if(!i||"object"!=typeof i)return null;let r=1/0,n=-1/0;if(e.fillGradientSpan)[r,n]=e.fillGradientSpan;else{for(let[,t]of e.topPath)r=Math.min(r,t);for(let[,t]of e.bottomPath)n=Math.max(n,t)}if(!Number.isFinite(r)||!Number.isFinite(n))return null;let o=Il(i.stops,Ml(e.style.fill));return o?/* @__PURE__ */zl("linearGradient",{id:t,gradientUnits:"userSpaceOnUse",x1:0,y1:r,x2:0,y2:n,children:o}):null}function Wl(e,t,i,r){if(!e||t.length<2)return null;let n=Il(e.stops,r);return n?/* @__PURE__ */zl("linearGradient",{id:i,gradientUnits:"userSpaceOnUse",x1:t[0][0],y1:0,x2:t[t.length-1][0],y2:0,children:n}):null}function Yl(e,t,i,r=30){let n=ql(e,t,i,r);return"area"===e.type?n:Ol(n,e,`xy-cursor-${t}`)}function ql(e,t,i,r=30){switch(e.type){case"line":{let r=e;if(0===r.path.length)return null;let n=ml(r.curve),o=n?Ks().x(([e])=>e).y(([,e])=>e).curve(n)(r.path)??"":"M"+r.path.map(([e,t])=>`${e},${t}`).join("L"),a=$l(`${i?`${i}-`:""}line-${t}-stroke-gradient`),s=Wl(r.strokeGradient,r.path,a,r.style.stroke||"#4e79a7");/* @__PURE__ */
11
- return Dl(Hs.Fragment,{children:[s&&/* @__PURE__ */zl("defs",{children:s}),
12
- /* @__PURE__ */zl("path",{d:o,fill:"none",stroke:s?`url(#${a})`:r.style.stroke||"#4e79a7",strokeWidth:r.style.strokeWidth??2,strokeDasharray:r.style.strokeDasharray,opacity:r.style.opacity})]},`line-${t}`)}case"area":{let n=e;if(0===n.topPath.length)return null;let o=ml(n.curve),a=o&&n.topPath.length>=2&&n.bottomPath.length>=2?Us().x(([e])=>e).y0((e,t)=>n.bottomPath[t][1]).y1(([,e])=>e).curve(o)(n.topPath)??"":`M${n.topPath.map(([e,t])=>`${e},${t}`).join("L")}L${[...n.bottomPath].reverse().map(([e,t])=>`${e},${t}`).join("L")}Z`,s=`${i?`${i}-`:""}area-${t}-hatch`,l=el(n.style.fill)?rl(n.style.fill,s):void 0,c=$l(`${i?`${i}-`:""}area-${t}-gradient`),u=jl(n,c),d=u?`url(#${c})`:l?`url(#${s})`:Ml(n.style.fill),h=u?void 0:n.style.fillOpacity??.7,f=o?Ks().x(([e])=>e).y(([,e])=>e).curve(o)(n.topPath)??"":"M"+n.topPath.map(([e,t])=>`${e},${t}`).join("L"),p=El(n),g=p&&r>=0?/* @__PURE__ */zl("path",{d:f,fill:"none",stroke:"transparent",strokeWidth:Math.max(1,2*r),strokeLinecap:"round",pointerEvents:"stroke",style:{cursor:p},"data-semiotic-mark-cursor":p,"data-semiotic-cursor-hit-target":"area-top-path","aria-hidden":"true"},`area-${t}-cursor-target`):null,m=$l(`${i?`${i}-`:""}area-${t}-stroke-gradient`),y=!(!n.colorThresholds?.length||!n.rawValues||n.rawValues.length!==n.topPath.length),x=!!n.strokeColorBands?.length,b=y||x?null:Wl(n.strokeGradient,n.topPath,m,n.style.stroke||"#4e79a7"),v=n.style.strokeWidth??2,w=1/0,k=-1/0;for(let[e]of n.topPath)e<w&&(w=e),e>k&&(k=e);let S=x?n.strokeColorBands.map((e,r)=>$l(`${i?`${i}-`:""}area-${t}-stroke-band-${r}`)):[],A=x?n.strokeColorBands.map((e,t)=>/* @__PURE__ */zl("clipPath",{id:S[t],children:/* @__PURE__ */zl("rect",{x:w-v,y:e.y,width:k-w+2*v,height:e.height})},S[t])):null,M=n.style.stroke&&"none"!==n.style.stroke?x?n.strokeColorBands.map((e,i)=>/* @__PURE__ */zl("path",{d:f,fill:"none",stroke:e.color??Ml(n.style.stroke),strokeWidth:v,opacity:(n.style.opacity??1)*(e.opacity??1),clipPath:`url(#${S[i]})`},`area-${t}-stroke-band-${i}`)):y?xl(n.topPath,n.rawValues,n.colorThresholds,Ml(n.style.stroke)).map((e,i)=>/* @__PURE__ */zl("path",{d:"M"+e.path.map(([e,t])=>`${e},${t}`).join("L"),fill:"none",stroke:e.color,strokeWidth:v,opacity:n.style.opacity},`area-${t}-threshold-${i}`)):/* @__PURE__ */zl("path",{d:f,fill:"none",stroke:b?`url(#${m})`:Ml(n.style.stroke),strokeWidth:v,opacity:n.style.opacity}):null;if(n.clipRect){let e=`${i?`${i}-`:""}area-clip-${t}`;/* @__PURE__ */
13
- return Dl("g",{children:[
14
- /* @__PURE__ */Dl("defs",{children:[u,!u&&l,b,A,
15
- /* @__PURE__ */zl("clipPath",{id:e,children:/* @__PURE__ */zl("rect",{x:n.clipRect.x,y:n.clipRect.y,width:n.clipRect.width,height:n.clipRect.height})})]}),
16
- /* @__PURE__ */Dl("g",{clipPath:`url(#${e})`,children:[
17
- /* @__PURE__ */zl("path",{d:a,fill:d,fillOpacity:h,opacity:n.style.opacity,stroke:"none"}),M,g]})]},`area-${t}`)}/* @__PURE__ */
18
- return Dl(Hs.Fragment,{children:[(u||l||b||A)&&/* @__PURE__ */Dl("defs",{children:[u,!u&&l,b,A]}),
19
- /* @__PURE__ */zl("path",{d:a,fill:d,fillOpacity:h,opacity:n.style.opacity,stroke:"none"}),M,g]},`area-${t}`)}case"point":case"rect":return Tl(e,t,i);case"symbol":return Rl(e,t);case"glyph":{let r=e;return _l(r,r.x,r.y,`${i??""}glyph-${r.pointId??t}`)}case"heatcell":{let i=e,r={x:i.x,y:i.y,width:i.w,height:i.h,fill:i.fill,stroke:i.style?.stroke,strokeWidth:i.style?.strokeWidth,...null!=i.style?.opacity&&{opacity:i.style.opacity}};if(i.showValues&&null!=i.value&&i.w>=20&&i.h>=20){let e=i.valueFormat?i.valueFormat(i.value):Number.isInteger(i.value)?String(i.value):Math.abs(i.value)>=100?i.value.toFixed(0):Math.abs(i.value)>=1?i.value.toFixed(1):i.value.toPrecision(3),[n,o,a]=Bl(i.fill),s=.299*n+.587*o+.114*a>128?"#000":"#fff",l=Math.max(10,Math.min(16,.3*Math.min(i.w,i.h)));/* @__PURE__ */
20
- return Dl("g",{children:[
21
- /* @__PURE__ */zl("rect",{...r}),
22
- /* @__PURE__ */zl("text",{className:"semiotic-heatmap-value",x:i.x+i.w/2,y:i.y+i.h/2,textAnchor:"middle",dominantBaseline:"middle",fill:s,fontSize:`${l}px`,fontFamily:"var(--semiotic-font-family, sans-serif)",children:e})]},`heatcell-${t}`)}/* @__PURE__ */
23
- return zl("rect",{...r},`heatcell-${t}`)}case"candlestick":{let r=e,n=`${i?`${i}-`:""}candle-${t}-hatch`,o=el(r.style?.fill)?rl(r.style.fill,n):void 0,a=o?`url(#${n})`:void 0,{fill:s,...l}=r.style??{};if(r.isRange){let e=r.dotRadius??Math.max(2,r.bodyWidth/2),i=a??r.wickColor;/* @__PURE__ */
24
- return Dl(Hs.Fragment,{children:[o&&/* @__PURE__ */zl("defs",{children:o}),
25
- /* @__PURE__ */Dl("g",{style:l,children:[
26
- /* @__PURE__ */zl("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth,opacity:r.style?.opacity}),
27
- /* @__PURE__ */zl("circle",{cx:r.x,cy:r.highY,r:e,fill:i,opacity:r.style?.opacity}),
28
- /* @__PURE__ */zl("circle",{cx:r.x,cy:r.lowY,r:e,fill:i,opacity:r.style?.opacity})]})]},`candle-${t}`)}let c=Math.min(r.openY,r.closeY),u=Math.max(Math.abs(r.openY-r.closeY),1),d=r.isUp?r.upColor:r.downColor,h=a??d;/* @__PURE__ */
29
- return Dl(Hs.Fragment,{children:[o&&/* @__PURE__ */zl("defs",{children:o}),
30
- /* @__PURE__ */Dl("g",{style:l,children:[
31
- /* @__PURE__ */zl("line",{x1:r.x,y1:r.highY,x2:r.x,y2:r.lowY,stroke:r.wickColor,strokeWidth:r.wickWidth,opacity:r.style?.opacity}),
32
- /* @__PURE__ */zl("rect",{x:r.x-r.bodyWidth/2,y:c,width:r.bodyWidth,height:u,fill:h,stroke:a?r.wickColor:d,strokeWidth:1,opacity:r.style?.opacity})]})]},`candle-${t}`)}default:return null}}var Xl=/* @__PURE__ */new Set;function Gl(e){if(!e||"object"!=typeof e)return!1;let t=e;return"string"==typeof t.id&&"function"==typeof t.cacheKey&&"function"==typeof t.drawCanvas&&"function"==typeof t.renderStaticSVG}function Vl(e,t){let i="function"==typeof e?e(t.datum??null,t):e;return Gl(i)?i:void 0}function Hl(e,t){if("production"===process.env.NODE_ENV)return;let i=`${e}:${t}`;Xl.has(i)||(Xl.add(i),console.warn(`[Semiotic] Render backend "${e}" does not support scene node "${t}"; using the built-in renderer.`))}function Ul(e){let{node:t,index:i,renderMode:r,fallback:n}=e,o=Vl(r,t);if(!o)return{element:n(),renderedByBackend:!1};let a=o.renderStaticSVG({node:t,style:t.style??{},key:`${o.id}-${i}`});return null!=a?{element:Ol(a,t,`${o.id}-${i}-cursor`),renderedByBackend:!0}:(Hl(o.id,t.type??"unknown"),{element:n(),renderedByBackend:!1})}function Kl(e){return Ul(e).element}function Zl(e){let t=[];return e.nodes.forEach((i,r)=>{let n=Ul({node:i,index:r,renderMode:e.renderMode,fallback:()=>e.fallback(i,r)});null!==n.element&&void 0!==n.element&&!1!==n.element&&t.push({node:i,index:r,...n})}),t}import{scaleOrdinal as Ql}from"d3-scale";import{jsx as Jl,jsxs as ec}from"react/jsx-runtime";function tc(e,t,i){if(t&&"object"==typeof t&&!Array.isArray(t)){let e=t;return t=>Ri(e,t)??"#999"}let r=Array.isArray(t)?t:i.colors.categorical.length>0?i.colors.categorical:oi;return Ql().domain(e).range(r)}function ic(e,t,i){if(0===e.length)return;let r=tc(e,t,i);return{legendGroups:[{label:"",type:"fill",items:e.map(e=>({label:e})),styleFn:e=>({fill:r(e.label)})}]}}function rc(e){return"left"===e?"start":"right"===e?"end":e??"start"}function nc(e){return Number(e.typography.legendSize??e.typography.labelSize??e.typography.tickSize)||11}function oc(e){return e.typography.legendFontFamily??e.typography.fontFamily}function ac(e){return e.typography.legendFontWeight}function sc(e,t,i,r){let n=nc(r);return t+i+Math.ceil(e.length*n*.58)}function lc(e){let{categories:t,theme:i,position:r="right",totalWidth:n,margin:o,legendLayout:a}=e,{swatchSize:s,labelGap:l,itemGap:c,rowHeight:u}=K(a),d=s+l,h="top"===r||"bottom"===r,f=Math.max(s,n-o.left-o.right),p=t.map(e=>sc(e,s,l,i));if(h){let e=Math.max(s,a?.maxWidth??f),i=[],r=0,n=0;p.forEach((t,o)=>{let a=0===n?t:n+c+t;n>0&&a>e?(i.push({start:r,end:o,width:n}),r=o,n=t):n=a}),t.length>0&&i.push({start:r,end:t.length,width:n});let o=rc(a?.align),l=[];return i.forEach((i,r)=>{let n="center"===o?Math.max(0,(e-i.width)/2):"end"===o?Math.max(0,e-i.width):0;for(let e=i.start;e<i.end;e++)l.push({category:t[e],width:p[e],x:n,y:r*u}),n+=p[e]+c}),{items:l,width:i.reduce((e,t)=>Math.max(e,t.width),0),height:i.length*u,swatchSize:s,labelOffset:d,swatchRadius:0}}let g=p.reduce((e,t)=>Math.max(e,t),0);return{items:t.map((e,t)=>({category:e,width:p[t],x:0,y:t*u})),width:g,height:t.length*u,swatchSize:s,labelOffset:d,swatchRadius:0}}function cc(e){let{legendGroups:t,theme:i,position:r="right",totalWidth:n,margin:o,legendLayout:a}=e,{swatchSize:s,labelGap:l,rowHeight:c}=K(a),u=s+l,d=Math.max(12,nc(i)),h="top"===r||"bottom"===r,f=Math.max(s,n-o.left-o.right);if(h){let r=Math.max(s,a?.maxWidth??f),n=rc(a?.align),o=0,l=0,c=[];for(let n of t){let t=n.items.map(e=>e.label),u=lc({...e,categories:t,legendLayout:{...a,maxWidth:Math.max(s,r-d-8),align:"start"}}),h=n.label?d:0,f=n.label?sc(n.label,0,0,i):0,p=h>0?h+8:0,g=p+u.width,m=Math.max(u.height,f);c.push({group:n,x:o,y:0,itemOffsetX:p,itemOffsetY:0,width:g,height:m,items:u.items}),o+=g+12,l=Math.max(l,m)}let h=c.length>0?o-12:0,p=h>r?0:"center"===n?Math.max(0,(r-h)/2):"end"===n?Math.max(0,r-h):0;return{groups:c.map(e=>({...e,x:e.x+p})),width:h,height:l,swatchSize:s,labelOffset:u,swatchRadius:0}}let p=Z(t.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),c);return{groups:[],width:t.reduce((e,t)=>t.items.reduce((e,t)=>Math.max(e,sc(t.label,s,l,i)),Math.max(e,t.label?sc(t.label,0,0,i):0)),0),height:p.at(-1)?.endY??0,swatchSize:s,labelOffset:u,swatchRadius:0}}function uc(e){let t="top"===e.position||"bottom"===e.position,i=Math.max(1,e.totalWidth-e.margin.left-e.margin.right);return t?{width:Math.min(e.legendLayout?.maxWidth??i,200),height:e.gradient.label?46:26,swatchSize:12}:{width:e.gradient.label?86:72,height:e.gradient.label?126:108,swatchSize:14}}function dc(e){let{categories:t,colorScheme:i,theme:r,position:n="right",totalWidth:o,totalHeight:a,margin:s}=e;if(!t||0===t.length)return null;let l=tc(t,i,r),c="top"===n||"bottom"===n,u=lc(e),d={...ic(t,i,r),legendDistance:e.legendDistance},h=e.reservedWidth??O(d,e.legendLayout),{x:f,y:p}=U(d,{totalWidth:o,totalHeight:a,margin:s,position:n,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:h}),g=c?void 0:Z([{hasLabel:!1,itemCount:t.length}],Math.max(u.swatchSize,e.legendLayout?.rowHeight??22))[0],m=u.items.map((e,t)=>/* @__PURE__ */ec("g",{transform:`translate(${e.x},${e.y+(g?.itemsY??0)})`,children:[
33
- /* @__PURE__ */Jl("rect",{width:u.swatchSize,height:u.swatchSize,fill:l(e.category),rx:u.swatchRadius}),
34
- /* @__PURE__ */Jl("text",{x:u.labelOffset,y:u.swatchSize/2,dominantBaseline:"central",fontSize:nc(r),fill:r.colors.text,fontFamily:oc(r),children:e.category})]},`legend-${t}`));/* @__PURE__ */
35
- return ec("g",{className:"semiotic-legend",transform:`translate(${f},${p})`,fontWeight:ac(r),children:[g&&/* @__PURE__ */Jl("line",{x1:0,y1:g.lineY,x2:h,y2:g.lineY,stroke:"gray"}),m]})}function hc(e){if(!e.legendGroups.some(e=>e.items.some(()=>!0)))return null;let t=cc(e),i="top"===e.position||"bottom"===e.position,r={legendGroups:e.legendGroups,legendDistance:e.legendDistance},n=e.reservedWidth??O(r,e.legendLayout),o=e.theme.colors.grid||e.theme.colors.textSecondary,{x:a,y:s}=U(r,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:n});if(!i){let i=Z(e.legendGroups.map(e=>({hasLabel:!!e.label,itemCount:e.items.length})),Math.max(t.swatchSize,e.legendLayout?.rowHeight??22)),r=e.legendGroups.flatMap((r,o)=>{let a=i[o],s=r.type??"fill",l=[
36
- /* @__PURE__ */Jl("line",{x1:0,y1:a.lineY,x2:n,y2:a.lineY,stroke:"gray"},`legend-group-neatline-${o}`)];return r.label&&null!=a.labelY&&l.push(
37
- /* @__PURE__ */Jl("text",{y:a.labelY,fontSize:nc(e.theme),fill:e.theme.colors.text,fontFamily:oc(e.theme),children:r.label},`legend-group-label-${o}`)),l.push(
38
- /* @__PURE__ */Jl("g",{transform:`translate(0,${a.itemsY})`,children:r.items.map((i,n)=>{let a=r.styleFn(i,n),l="function"==typeof s?s(i):"line"===s?/* @__PURE__ */Jl("line",{x1:0,y1:0,x2:t.swatchSize,y2:t.swatchSize,style:a}):/* @__PURE__ */Jl("rect",{width:t.swatchSize,height:t.swatchSize,rx:t.swatchRadius,style:a});/* @__PURE__ */
39
- return ec("g",{transform:`translate(0,${n*Math.max(t.swatchSize,e.legendLayout?.rowHeight??22)})`,children:[l,
40
- /* @__PURE__ */Jl("text",{x:t.labelOffset,y:t.swatchSize/2,dominantBaseline:"central",fontSize:nc(e.theme),fill:e.theme.colors.text,fontFamily:oc(e.theme),children:i.label})]},`legend-${o}-${n}`)})},`legend-group-${o}`)),l});/* @__PURE__ */
41
- return Jl("g",{className:"semiotic-legend",transform:`translate(${a},${s})`,"data-orientation":"vertical",fontWeight:ac(e.theme),children:r})}let l=t.groups.flatMap((i,r)=>{let{group:n}=i,a=n.type??"fill",s=[];if(n.label&&s.push(
42
- /* @__PURE__ */Jl("text",{transform:`translate(${i.x},${i.y}) rotate(90)`,textAnchor:"start",fontSize:nc(e.theme),fill:e.theme.colors.text,fontFamily:oc(e.theme),children:n.label},`legend-group-label-${r}`)),s.push(...i.items.map((o,s)=>{let l=n.items[s],c=n.styleFn(l,s),u="function"==typeof a?a(l):"line"===a?/* @__PURE__ */Jl("line",{x1:0,y1:0,x2:t.swatchSize,y2:t.swatchSize,style:c}):/* @__PURE__ */Jl("rect",{width:t.swatchSize,height:t.swatchSize,rx:t.swatchRadius,style:c});/* @__PURE__ */
43
- return ec("g",{transform:`translate(${i.x+i.itemOffsetX+o.x},${i.y+i.itemOffsetY+o.y})`,children:[u,
44
- /* @__PURE__ */Jl("text",{x:t.labelOffset,y:t.swatchSize/2,dominantBaseline:"central",fontSize:nc(e.theme),fill:e.theme.colors.text,fontFamily:oc(e.theme),children:o.category})]},`legend-${r}-${s}`)})),r<t.groups.length-1){let e=i.x+i.width+6;s.push(
45
- /* @__PURE__ */Jl("line",{x1:e,y1:0,x2:e,y2:t.height,stroke:o},`legend-group-separator-${r}`))}return s});/* @__PURE__ */
46
- return Jl("g",{className:"semiotic-legend",transform:`translate(${a},${s})`,"data-orientation":"horizontal",fontWeight:ac(e.theme),children:l})}function fc(e){let t=uc(e),i="top"===e.position||"bottom"===e.position,r={gradient:e.gradient,legendDistance:e.legendDistance},n=O(r),o=(e.idPrefix?`${e.idPrefix}-`:"")+"semiotic-static-gradient-legend",a=e.gradient.format||I(e.gradient.domain),{x:s,y:l}=U(r,{totalWidth:e.totalWidth,totalHeight:e.totalHeight,margin:e.margin,position:e.position,legendLayout:e.legendLayout,axisChrome:e.axisChrome,reservedWidth:n}),c=Array.from({length:17},(t,r)=>{let n=r/16,o=i?e.gradient.domain[0]+n*(e.gradient.domain[1]-e.gradient.domain[0]):e.gradient.domain[1]-n*(e.gradient.domain[1]-e.gradient.domain[0]);/* @__PURE__ */
47
- return Jl("stop",{offset:n,stopColor:e.gradient.colorFn(o)},r)});if(i){let i=e.gradient.label?12:void 0,r=e.gradient.label?18:0;/* @__PURE__ */
48
- return ec("g",{className:"semiotic-legend",transform:`translate(${s},${l})`,fontWeight:ac(e.theme),children:[
49
- /* @__PURE__ */Jl("defs",{children:/* @__PURE__ */Jl("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:c})}),e.gradient.label&&/* @__PURE__ */Jl("text",{x:t.width/2,y:i,textAnchor:"middle",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:oc(e.theme),children:e.gradient.label}),
50
- /* @__PURE__ */Jl("rect",{x:0,y:r,width:t.width,height:12,fill:`url(#${o})`,rx:2}),
51
- /* @__PURE__ */Jl("text",{x:0,y:r+12+12,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:oc(e.theme),children:a(e.gradient.domain[0])}),
52
- /* @__PURE__ */Jl("text",{x:t.width,y:r+12+12,textAnchor:"end",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:oc(e.theme),children:a(e.gradient.domain[1])})]})}let u=e.gradient.label?12:void 0,d=e.gradient.label?18:0;/* @__PURE__ */
53
- return ec("g",{className:"semiotic-legend",transform:`translate(${s},${l})`,fontWeight:ac(e.theme),children:[
54
- /* @__PURE__ */Jl("defs",{children:/* @__PURE__ */Jl("linearGradient",{id:o,x1:"0%",y1:"0%",x2:"0%",y2:"100%",children:c})}),e.gradient.label&&/* @__PURE__ */Jl("text",{x:0,y:u,textAnchor:"start",fontSize:e.theme.typography.tickSize,fill:e.theme.colors.text,fontFamily:oc(e.theme),children:e.gradient.label}),
55
- /* @__PURE__ */Jl("rect",{x:0,y:d,width:14,height:100,fill:`url(#${o})`,rx:2}),
56
- /* @__PURE__ */Jl("text",{x:19,y:d+10,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:oc(e.theme),children:a(e.gradient.domain[1])}),
57
- /* @__PURE__ */Jl("text",{x:19,y:d+100,fontSize:e.theme.typography.tickSize,fill:e.theme.colors.textSecondary,fontFamily:oc(e.theme),children:a(e.gradient.domain[0])})]})}function pc(e,t){if(!t||!e||0===e.length)return[];let i="function"==typeof t?t:e=>e[t],r=/* @__PURE__ */new Set;for(let t of e){let e=i(t);null!=e&&r.add(String(e))}return Array.from(r)}import*as gc from"react";var mc=(e,t)=>({width:Array.from(e).length*t.size*.65,height:1.2*t.size,ascent:.9*t.size,source:"estimated"});function yc(e){let{desired:t,minGaps:i,weights:r}=e,n=t.length;if(0===n)return[];if(i.length!==Math.max(0,n-1))throw new Error("placeWithMinGap: minGaps must have desired.length - 1 entries");let o=new Array(n).fill(0);for(let e=1;e<n;e++)o[e]=o[e-1]+Math.max(0,Number.isFinite(i[e-1])?i[e-1]:0);let a=[];for(let e=0;e<n;e++){let i=Math.max(Number.EPSILON,Number.isFinite(r?.[e])?r[e]:1),n=(Number.isFinite(t[e])?t[e]:0)-o[e];for(a.push({start:e,end:e,weight:i,mean:n});a.length>1;){let e=a[a.length-1],t=a[a.length-2];if(t.mean<=e.mean)break;let i=t.weight+e.weight;a.splice(a.length-2,2,{start:t.start,end:e.end,weight:i,mean:(t.mean*t.weight+e.mean*e.weight)/i})}}let s=Number.isFinite(e.min)?e.min:-1/0,l=Number.isFinite(e.max)?e.max-o[n-1]:1/0,c=l<s?s:l,u=new Array(n);for(let e of a){let t=Math.max(s,Math.min(c,e.mean));for(let i=e.start;i<=e.end;i++)u[i]=t+o[i]}return u}var xc={INVALID_PROJECTION:"Check endpoint values and the scale domain, especially log-scale values.",INSUFFICIENT_SPACE:"Increase chart height or the label-side margin, or reduce the label font size.",TIED_ENDPOINTS:"Use connectors or a legend to distinguish series sharing an endpoint.",LABEL_OMITTED:"Consult the accessible series list; increase the label rail space to restore visible labels.",ESTIMATED_METRICS:"Load the intended font and remeasure before asserting collision-free text.",RENDER_FAILURE:"Inspect the annotation renderer; the placed label did not produce a node.",UNSUPPORTED_GEOMETRY:"Inspect custom-rendered text; its geometry has not been measured by the label solver.",LABEL_COLLISION:"Increase spacing or shorten the affected labels.",LABEL_OVERFLOW:"Increase the allocated bounds or shorten the affected labels."};function bc(e,t,i="end",r=2){let n,o=/* @__PURE__ */new Map,a=/* @__PURE__ */new Map,s=(e,t)=>{let i=a.get(e)??{count:0,labelIds:[]};i.count++,i.labelIds.length<20&&i.labelIds.push(t),a.set(e,i)},l=(e,t)=>{o.set(e,{id:e,status:"omitted",reason:t}),s(t,e),s("LABEL_OMITTED",e)},c=[...e].sort((e,t)=>(Number.isFinite(e.anchor.y)?e.anchor.y:1/0)-(Number.isFinite(t.anchor.y)?t.anchor.y:1/0)||(e.id<t.id?-1:e.id>t.id?1:0)),u=[],d=0;for(let e of c){let{id:i,anchor:o,measurement:a}=e;if("estimated"===a.source&&s("ESTIMATED_METRICS",i),![o.x,o.y,a.width,a.height,a.ascent].every(Number.isFinite)||a.width<0||a.height<=0){l(i,"INVALID_PROJECTION");continue}n===o.y&&s("TIED_ENDPOINTS",i),n=o.y;let c=a.height+(u.length?r:0);![t.x,t.y,t.width,t.height,r].every(Number.isFinite)||r<0||a.width>t.width||d+c>t.height?l(i,"INSUFFICIENT_SPACE"):(u.push(e),d+=c)}let h=yc({desired:u.map(e=>e.anchor.y-e.measurement.height/2),minGaps:u.slice(0,-1).map(e=>e.measurement.height+r),min:t.y,max:t.y+t.height-(u.at(-1)?.measurement.height??0)});u.forEach((e,r)=>{let n={x:"end"===i?t.x:t.x+t.width-e.measurement.width,y:h[r],width:e.measurement.width,height:e.measurement.height},a="end"===i?n.x:n.x+n.width,s=n.y+n.height/2,l={x:a-e.anchor.x,y:s-e.anchor.y};o.set(e.id,{id:e.id,status:"placed",box:n,offset:l,...Math.abs(l.y)>.01||Math.abs(l.x)>6.01?{connector:{x1:e.anchor.x,y1:e.anchor.y,x2:a,y2:s}}:{}})});let f=e.map(e=>o.get(e.id)),p=f.filter(e=>"placed"===e.status&&Math.abs(e.offset.y)>.01),g=f.filter(e=>"omitted"===e.status),m=e.filter(e=>"estimated"===e.measurement.source).length;return{dispositions:f,evidence:{status:m||g.length?"incomplete":"complete",requested:e.length,rendered:u.length,displaced:p.length,omitted:g.length,omittedIds:g.slice(0,20).map(e=>e.id),displacedIds:p.slice(0,20).map(e=>e.id),measurement:{measured:e.length-m,estimated:m},collisions:0,overflows:0,fallback:"accessible-series-list",findings:[...a].map(([e,t])=>({code:e,...t,remedy:xc[e]})),coverage:{directLabels:"assessed",axisLabels:"not-assessed"}}}}import{jsx as vc,jsxs as wc}from"react/jsx-runtime";function kc(e,t){let i=e.filter(e=>e._directLabel);if(!i.length)return{node:null};let r=i[0]._directLabel.position,n=t.measure??mc,o=i.map(e=>({family:t.fontFamily||"sans-serif",version:t.fontVersion??0,weight:400,size:e.fontSize||11})),a=i.map((e,i)=>{let r=(e,t)=>{if(null==e||!t)return NaN;try{return t(Number(e))}catch{return NaN}};return{id:String(e._directLabel.id),anchor:{x:r(e.x,t.scales?.x),y:r(e.y,t.scales?.y)},measurement:n(String(e.label),o[i])}}),s=Math.max(0,(t.margin?.["end"===r?"right":"left"]??0)-10),l=bc(a,{x:"end"===r?t.width+6:-s-6,y:0,width:s,height:t.height},r),c=l.dispositions.map((e,r)=>{if("omitted"===e.status)return null;let n=e.box,s=e.connector,c=i[r],u=/* @__PURE__ */wc("g",{"data-direct-label-id":e.id,children:[s&&/* @__PURE__ */vc("line",{...s,stroke:c.color,strokeWidth:.75}),
58
- /* @__PURE__ */vc("text",{x:n.x+(a[r].measurement.left??0),y:n.y+a[r].measurement.ascent,fontFamily:o[r].family,fontWeight:o[r].weight,fontSize:o[r].size,fill:c.color,textAnchor:"start",children:c.label})]},e.id),d=t.renderLabel?t.renderLabel({...c,dx:n.x+(a[r].measurement.left??0)-a[r].anchor.x,dy:n.y+a[r].measurement.ascent-a[r].anchor.y,fontFamily:o[r].family},r,u):u;if(!d){let t=l.evidence;t.rendered--,t.omitted++,t.omittedIds.length<20&&t.omittedIds.push(e.id),Math.abs(e.offset.y)>.01&&t.displaced--,t.displacedIds=t.displacedIds.filter(t=>t!==e.id);for(let i of["RENDER_FAILURE","LABEL_OMITTED"]){let r=t.findings.find(e=>e.code===i);r||(r={code:i,count:0,labelIds:[],remedy:xc[i]},t.findings.push(r)),r.count++,r.labelIds.length<20&&r.labelIds.push(e.id)}}if(d!==u&&(l.evidence.status="incomplete",d)){let t=l.evidence.findings.find(e=>"UNSUPPORTED_GEOMETRY"===e.code);t||(t={code:"UNSUPPORTED_GEOMETRY",count:0,labelIds:[],remedy:xc.UNSUPPORTED_GEOMETRY},l.evidence.findings.push(t)),t.count++,t.labelIds.length<20&&t.labelIds.push(e.id)}return d?/* @__PURE__ */vc(gc.Fragment,{children:d},e.id):null}),u=/* @__PURE__ */vc("g",{role:"list","aria-label":"Series endpoints","data-direct-label-fallback":"accessible-series-list",children:i.map((e,t)=>/* @__PURE__ */vc("g",{role:"listitem","aria-label":`${e.label}: x ${String(e.x)}, y ${String(e.y)}`,children:/* @__PURE__ */vc("title",{children:`${e.label}: x ${String(e.x)}, y ${String(e.y)}`})},a[t].id))});return{evidence:l.evidence,node:/* @__PURE__ */wc("g",{className:"semiotic-direct-labels","data-label-layout":JSON.stringify(l.evidence),children:[c,u]},"direct-labels")}}function Sc(e){return"string"==typeof e&&e.includes("var(")}var Ac=/^\s*var\(\s*--[^,)\s]+\s*(?:,\s*([\s\S]*))?\)\s*$/;function Mc(e){let t=Ac.exec(e);if(!t)return Sc(e)?void 0:e;let i=t[1]?.trim();return i?Mc(i):void 0}import{jsx as $c,jsxs as _c}from"react/jsx-runtime";var Ic="var(--semiotic-bg, #ffffff)";function Pc(e,t){return String(e).length*t*.6}function Lc(e){return void 0===e||!0===e||"halo"===e?{type:"halo"}:!1===e||"none"===e?null:"box"===e?{type:"box"}:{...e,type:e.type??"halo"}}function Rc(e){let{x:t,y:i,text:r,fill:n,fontSize:o=12,fontWeight:a,fontFamily:s,textAnchor:l="start",dominantBaseline:c,background:u,className:d}=e,h=Lc(u),f=e=>/* @__PURE__ */$c("text",{x:t,y:i,textAnchor:l,dominantBaseline:c,fill:n,fontSize:o,fontWeight:a,fontFamily:s,className:d,...e?{style:{stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:"stroke"}}:{},children:r});if(!h)return f();if("halo"===h.type)return f({stroke:h.fill??Ic,strokeWidth:h.haloWidth??3});let p,g,m=h.padding??{x:6,y:3},y="number"==typeof m?m:m.x,x="number"==typeof m?m:m.y,b=Pc(r,o),v=b+2*y,w=o+2*x;p="middle"===l?t-b/2-y:"end"===l?t-b-y:t-y,g="middle"===c||"central"===c?i-w/2:"hanging"===c||"text-before-edge"===c?i-x:i-.8*o-x;let k=h.fill??Ic,S={};return Sc(k)&&(S.fill=k),Sc(h.stroke)&&(S.stroke=h.stroke),/* @__PURE__ */_c("g",{className:d,children:[
59
- /* @__PURE__ */$c("rect",{x:p,y:g,width:v,height:w,rx:h.radius??3,ry:h.radius??3,fill:Sc(k)?Mc(k):k,fillOpacity:h.opacity??.85,stroke:Sc(h.stroke)?Mc(h.stroke):h.stroke,strokeWidth:h.strokeWidth,...S.fill||S.stroke?{style:S}:{}}),f()]})}import{jsx as Cc}from"react/jsx-runtime";function Tc(e,t,i){if(!e)return null;let r="object"==typeof e?e:{};/* @__PURE__ */
60
- return Cc("circle",{className:"semiotic-threshold-end-cap",cx:t[0],cy:t[1],r:Math.max(0,r.radius??4),fill:r.fill??i})}import{jsx as Nc,jsxs as Fc}from"react/jsx-runtime";function Ec({ann:e,position:t,vertical:i,width:r,height:n,color:o,fontSize:a=12,fontFamily:s,bold:l,background:c,dash:u="6,3",labelGap:d=4}){let h=e.labelPosition,f=t>.6*r,p=i?t+(f?-4:4):"left"===h?4:"center"===h?r/2:r-4,g=i?"bottom"===h?n-4:"center"===h?n/2:16:t<20?Math.min(n-4,t+16):t-d,m=i?f?"end":"start":"left"===h?"start":"center"===h?"middle":"end",y=i?[t,0]:[0,t],x=i?[t,n]:[r,t];/* @__PURE__ */
61
- return Fc("g",{opacity:e.opacity,children:[
62
- /* @__PURE__ */Nc("line",{x1:y[0],y1:y[1],x2:x[0],y2:x[1],stroke:o,strokeWidth:e.strokeWidth??1.5,strokeDasharray:e.strokeDasharray||u}),Tc(e.endCap,y,o),e.label&&/* @__PURE__ */Nc(Rc,{x:p,y:g,text:e.label,textAnchor:m,fill:e.labelColor??o,fontSize:a,fontFamily:s,fontWeight:l?"bold":void 0,background:c??e.labelBackground??"halo"})]})}function Oc(e){return{label:e.label,title:e.title,wrap:e.wrap||120,noWrap:"function"==typeof e._noteLayout?e.noWrap:void 0,_noteLayout:e._noteLayout}}function zc(e){return"function"==typeof e._noteLayout?e._noteLayout(e):void 0}function Dc(e,t,i){if(!e)return[];let r=Math.max(1,Math.floor(t/i)),n=[],o="";for(let t of e.split(/\s+/))t&&(o&&o.length+1+t.length>r?(n.push(o),o=t):o=o?`${o} ${t}`:t);return o&&n.push(o),n}import{jsx as Bc,jsxs as jc}from"react/jsx-runtime";function Wc(e,t,i,r){return"curly"===e?r?`M0,0 C${.6*i},0 ${.4*i},${t/2} ${i},${t/2} C${.4*i},${t/2} ${.6*i},${t} 0,${t}`:`M0,0 C0,${.6*i} ${t/2},${.4*i} ${t/2},${i} C${t/2},${.4*i} ${t},${.6*i} ${t},0`:r?`M0,0 L${i},0 L${i},${t} L0,${t}`:`M0,0 L0,${i} L${t},${i} L${t},0`}function Yc(e,t,i,r){if(!e)/* @__PURE__ */return Bc("g",{className:"annotation-note"});let{label:n,title:o,orientation:a,align:s,wrap:l=120,noWrap:c}=e;if(!n&&!o)/* @__PURE__ */return Bc("g",{className:"annotation-note"});let u=a;u||(u=Math.abs(t)>Math.abs(i)?"leftRight":"topBottom");let d="topBottom"===u,h="leftRight"===u,f=s;(!f||"dynamic"===f)&&(f=d?t>=0?"left":"right":i>=0?"top":"bottom");let p="start";d?"right"===f?p="end":"middle"===f&&(p="middle"):p=t>=0?"start":"end";let g=e.useHTML||e.html,m=g?void 0:zc(e),y=m?.lineHeight??16,x=m?.titleLines??(o?c?[o]:Dc(o,l,8):[]),b=m?.labelLines??(n?c?[n]:Dc(n,l,8):[]),v=x.length+b.length,w=h?"end"===p?-4:4:0,k=[],S=r||"var(--semiotic-annotation-color, var(--semiotic-text, #333))";if(g){let e=l,t=Math.max(y,v*y+(o&&n?2:0)),i="end"===p?w-e:"middle"===p?w-e/2:w,r="end"===p?"right":"middle"===p?"center":"left";k.push(
63
- /* @__PURE__ */Bc("foreignObject",{className:"annotation-note-html",x:i,y:-y,width:e,height:t+y,style:{overflow:"visible"},children:/* @__PURE__ */jc("div",{xmlns:"http://www.w3.org/1999/xhtml",style:{color:S,fontSize:"12px",lineHeight:`${y}px`,overflow:"visible",textAlign:r,whiteSpace:c?"nowrap":"normal",wordBreak:"break-word"},children:[o&&/* @__PURE__ */Bc("div",{className:"annotation-note-title",style:{fontWeight:"bold"},children:o}),n&&/* @__PURE__ */Bc("div",{className:"annotation-note-label",children:n})]})},"annotation-note-html"))}else for(let e of[!0,!1]){let t=e?x:b;if(0===t.length)continue;let i="annotation-note-"+(e?"title":"label");k.push(
64
- /* @__PURE__ */Bc("text",{className:i,fill:S,textAnchor:p,fontWeight:e?m?.titleFontWeight??"bold":void 0,y:e?void 0:x.length*y,children:t.map((e,t)=>/* @__PURE__ */Bc("tspan",{x:w,dy:0===t?0:y,children:e},t))},i))}let A=null;if((o||n)&&(0!==t||0!==i)){let e=d?m?m.width:Math.min(l,120):(x.length+b.length+(b.length>0?1:0))*y,t=d?p:f,i="end"===t||"bottom"===t?-e:"middle"===t?-e/2:0;A=/* @__PURE__ */Bc("line",{className:"note-line",x1:d?i:0,x2:d?i+e:0,y1:d?0:i,y2:d?0:i+e,stroke:r||"var(--semiotic-text-secondary, currentColor)"})}let M=Math.max(0,v-1)*y,$=b.length>0&&x.length>0?2:0,_=0;(d||h)&&(_=h&&"middle"===f?-(M+y+$)/2+y/2:i<0||h&&"bottom"===f?-(M+2):2+y);let I=0!==_?`translate(0,${_})`:void 0;/* @__PURE__ */
65
- return jc("g",{className:"annotation-note",transform:`translate(${t},${i})`,...m?.textProps,children:[
66
- /* @__PURE__ */Bc("g",{className:"annotation-note-content",transform:I,children:k}),A]})}function qc(e,t,i,r,n){let o=null,a=i||"var(--semiotic-text-secondary, currentColor)";switch(e){case"callout-circle":{let e=(t?.radius||0)+(t?.radiusPadding||0);e>0&&(o=/* @__PURE__ */Bc("circle",{r:e,fill:"none",stroke:a},"subject-circle"));break}case"callout-rect":{let e=t?.width||0,i=t?.height||0;(e>0||i>0)&&(o=/* @__PURE__ */Bc("rect",{width:e,height:i,fill:"none",stroke:a},"subject-rect"));break}case"callout-custom":o=t?.custom;break;case"xy-threshold":{let e=r||0,i=n||0,s=0,l=0,c=0,u=0;if(void 0!==t?.x)s=l=(t.x||0)-e,c=(t.y1||0)-i,u=(t.y2||0)-i;else if(void 0!==t?.y)c=u=(t.y||0)-i,s=(t.x1||0)-e,l=(t.x2||0)-e;else if(void 0!==t?.x1||void 0!==t?.x2)s=(t.x1||0)-e,l=(t.x2||0)-e;else{if(void 0===t?.y1&&void 0===t?.y2)break;c=(t.y1||0)-i,u=(t.y2||0)-i}o=/* @__PURE__ */Bc("line",{x1:s,y1:c,x2:l,y2:u,stroke:a,strokeDasharray:"5,5"},"threshold-line");break}case"bracket":{let e=t?.type||"curly",i=t?.width??t?.height;void 0!==i&&(o=/* @__PURE__ */Bc("path",{d:Wc(e,i,t?.depth||30,void 0===t?.width),fill:"none",stroke:a},"bracket-path"));break}}/* @__PURE__ */
67
- return Bc("g",{className:"annotation-subject",children:o})}function Xc(e,t,i,r,n,o){let a,s,l=0,c=0;if("callout-circle"!==n&&"label"!==n||!o?.radius){if("callout-rect"===n&&o){let i=o.width||0,r=o.height||0;if(i>0||r>0){let n=i/2,o=r/2,a=e-n,s=t-o;if(0!==a||0!==s){let e=Math.abs(a),t=Math.abs(s),u=i/2,d=r/2,h=e*d>t*u?u/e:d/t;l=n+a*h,c=o+s*h}}}else if("bracket"===n&&o){let e=o.width,t=o.height,i=o.depth||30;void 0!==e?(l=e/2,c=i):void 0!==t&&(l=i,c=t/2)}}else{let i=(o.radius||0)+(o.radiusPadding||0);if(i>0&&(0!==e||0!==t)){let r=Math.atan2(t,e);l=Math.cos(r)*i,c=Math.sin(r)*i}}let u=e-l,d=t-c,h=Math.hypot(u,d);if(h>.5){let n=r||"var(--semiotic-text-secondary, currentColor)",o="curve"===i?.type,f=Math.atan2(d,u);if(o){let r=(l+e)/2,o=(c+t)/2,s=-d/h,p=u/h,g=(i?.curve??.25)*h,m=r+s*g,y=o+p*g;a=/* @__PURE__ */Bc("path",{className:"connector-curve",d:`M${l},${c}Q${m},${y} ${e},${t}`,fill:"none",stroke:n},"connector-line"),f=Math.atan2(y-c,m-l)}else a=/* @__PURE__ */Bc("line",{x1:l,y1:c,x2:e,y2:t,stroke:n},"connector-line");if("arrow"===i?.end){let e=.08888888888888889*Math.PI,t=l+10*Math.cos(f+e),i=c+10*Math.sin(f+e),r=l+10*Math.cos(f-e),o=c+10*Math.sin(f-e);s=/* @__PURE__ */Bc("path",{d:`M${l},${c}L${t},${i}L${r},${o}Z`,fill:n,stroke:"none"},"connector-arrow")}}/* @__PURE__ */
68
- return jc("g",{className:"annotation-connector",children:[a,s]})}function Gc(e){let{x:t=0,y:i=0,dx:r,dy:n,nx:o,ny:a,note:s,connector:l,subject:c,type:u,color:d,className:h,disable:f,opacity:p,strokeDasharray:g,events:m={},"data-testid":y}=e,x=Array.isArray(t)?t[0]??0:t,b=Array.isArray(i)?i[0]??0:i,v=Array.isArray(f)?f:[],w=r||0,k=n||0;null!=o&&(w=o-x),null!=a&&(k=a-b);let S="string"==typeof u?u:"label";if("bracket"===S&&c&&0===w&&0===k)if(void 0!==c.width){w=c.width/2;let e=c.depth||30;k=e+(e>=0?5:-5)}else if(void 0!==c.height){let e=c.depth||30;w=e+(e>=0?5:-5),k=c.height/2}/* @__PURE__ */
69
- return jc("g",{className:`annotation ${h||""}`.trim(),transform:`translate(${x},${b})`,"data-testid":y,...null!=p&&{opacity:p},...g&&{strokeDasharray:g},...m,children:[!v.includes("connector")&&Xc(w,k,l,d,S,c),!v.includes("subject")&&qc(S,c,d,x,b),!v.includes("note")&&Yc(s,w,k,d)]})}function Vc(e){let{noteData:t}=e,{screenCoordinates:i}=t,r="string"==typeof t.type?t.type:"label",n=t.eventListeners||t.events||{};if(t.coordinates&&i){let e=t.nx||i[0][0]+(t.dx??0),n=t.ny||i[0][1]+(t.dy??0),o=i.map((i,o)=>{let a=Object.assign({},t,{note:0===o?t.note:{label:""},x:i[0],y:i[1],nx:e,ny:n});/* @__PURE__ */
70
- return Bc(Gc,{"data-testid":"semiotic-annotation",...a,type:r},`multi-annotation-${o}`)});/* @__PURE__ */
71
- return Bc("g",{children:o})}let o=t.note||{title:"none",label:t.label},a=`${o.label}-${o.title}-${t.i}`;/* @__PURE__ */
72
- return Bc(Gc,{"data-testid":"semiotic-annotation",events:n,...t,type:r},a)}import{jsx as Hc}from"react/jsx-runtime";var Uc={secondary:0,primary:3};function Kc(e){return!0===e?._annotationDeferred}function Zc(e){return"blended"===e?.cohesion||"layer"===e?.cohesion?e.cohesion:null}function Qc(e){return"primary"===e?.emphasis||"secondary"===e?.emphasis?e.emphasis:null}function Jc(e){let t=e?.provenance?.confidence;return"number"==typeof t&&Number.isFinite(t)?Math.max(0,Math.min(1,t)):null}function eu(e){return Math.max(.72,.95-.06*e)}function tu(e){let t=e.map((e,t)=>({p:e,i:t,emphasis:Qc(e.annotation),confidence:Jc(e.annotation),readingOrder:null,rank:1})),i=t.some(e=>null!=e.emphasis||null!=e.confidence),r=e.some(e=>Kc(e.annotation)),n=e.some(e=>null!=Zc(e.annotation)),o=e.some(e=>"layer"===Zc(e.annotation));if(!i&&!r&&!n)return e.map(e=>e.node);let a=t.filter(e=>null==e.emphasis&&null!=e.confidence).slice().sort((e,t)=>(t.confidence??0)-(e.confidence??0)||e.i-t.i);a.forEach((e,t)=>{e.readingOrder=t,e.rank=2-t/Math.max(1,a.length)});for(let e of t)e.emphasis&&(e.rank=Uc[e.emphasis]);let s=t.sort((e,t)=>e.rank-t.rank||e.i-t.i).map(e=>{let{p:t,i:i,emphasis:r,readingOrder:n}=e,o=Kc(t.annotation),a=t.node;if("primary"===r||"secondary"===r||null!=n){let e=null==r&&null!=n;a=/* @__PURE__ */Hc("g",{className:e?"annotation-emphasis annotation-emphasis--inferred":`annotation-emphasis annotation-emphasis--${r}`,..."secondary"===r?{opacity:.6,fontSize:"0.88em"}:{},...e?{opacity:eu(n),"data-annotation-reading-order":n}:{},children:t.node},`annotation-emphasis-${i}`)}let s=Zc(t.annotation);return s&&(a=/* @__PURE__ */Hc("g",{className:`annotation-cohesion--${s}`,children:a},`annotation-cohesion-${i}`)),o&&(a=/* @__PURE__ */Hc("g",{className:"annotation-deferred","data-annotation-disclosure":"deferred",children:a},`annotation-deferred-${i}`)),a});return r&&s.unshift(
73
- /* @__PURE__ */Hc("style",{children:".annotation-deferred{opacity:0;pointer-events:none;transition:opacity .12s ease}.stream-xy-frame:hover .annotation-deferred,.stream-ordinal-frame:hover .annotation-deferred,.stream-network-frame:hover .annotation-deferred,.stream-geo-frame:hover .annotation-deferred,.stream-xy-frame:focus-within .annotation-deferred,.stream-ordinal-frame:focus-within .annotation-deferred,.stream-network-frame:focus-within .annotation-deferred,.stream-geo-frame:focus-within .annotation-deferred{opacity:1;pointer-events:auto}@media (prefers-reduced-motion:reduce){.annotation-deferred{transition:none}}"},"annotation-disclosure-style")),o&&s.unshift(
74
- /* @__PURE__ */Hc("style",{children:".annotation-cohesion--layer text,.annotation-cohesion--layer tspan{fill:var(--semiotic-annotation-color,var(--semiotic-text-secondary,#666));font-style:italic}"},"annotation-cohesion-style")),s}function iu(e,t,i,r){let n=[];return e.forEach((e,o)=>{let a;a=i?i(e,o,r)??t(e,o,r):t(e,o,r),a&&n.push({node:a,annotation:e})}),{nodes:tu(n),renderedAnnotations:n.map(e=>e.annotation)}}function ru(e,t){let i=t.scales?.x??t.scales?.time;return i?null!=e.x?i(e.x):t.xAccessor&&null!=e[t.xAccessor]?i(e[t.xAccessor]):null:null}function nu(e,t){let i=t.scales?.y??t.scales?.value;return i?null!=e.y?i(e.y):t.yAccessor&&null!=e[t.yAccessor]?i(e[t.yAccessor]):null:null}function ou(e){let t=e.data;if(!t||0===t.length)return null;let i=t[t.length-1],r=e.scales?.x??e.scales?.time,n=e.scales?.y??e.scales?.value;if(!r||!n)return null;let o=e.xAccessor||"x",a=e.yAccessor||"y",s=i[o],l=i[a];return null==s||null==l?null:{x:r(s),y:n(l)}}function au(e){return null==e?null:String(e)}function su(e){return au(e.provenance?.stableId??e.stableId)}function lu(e){return au(e.stableId??e.id??e.provenance?.stableId)}function cu(e,t,i){return t.stickyPositionCache?.set(e,i),i}function uu(e,t,i){let r=su(e);if(!r)return null;let n=i.pointNodes?.find(e=>au(e.pointId)===r);if(n)return cu(t,i,{x:n.x,y:n.y});let o=i.data?.find(e=>lu(e)===r);if(!o)return null;let a=ru(o,i),s=nu(o,i);return null==a||null==s?null:cu(t,i,{x:a,y:s})}function du(e,t,i){let r=e.anchor||e.lifecycle?.anchor||"fixed";if("latest"===r){if(null!=e.pointId&&i.pointNodes&&i.pointNodes.length>0)for(let r=i.pointNodes.length-1;r>=0;r--){let n=i.pointNodes[r];if(n.pointId===e.pointId)return cu(t,i,{x:n.x,y:n.y})}let r=ou(i);return r?cu(t,i,r):null}if("semantic"===r){let r=uu(e,t,i);if(r)return r}let n=null,o=null;if(null!=e.pointId&&i.pointNodes){let t=i.pointNodes.find(t=>t.pointId===e.pointId);t&&(n=t.x,o=t.y)}if((null==n||null==o)&&(n=ru(e,i),o=nu(e,i)),null!=n&&null!=o)return cu(t,i,{x:n,y:o});if("sticky"===r){let e=i.stickyPositionCache?.get(t);if(e)return e}return null}function hu(e,t,i,r=50){let n=i.width||0,o=i.height||0;return e>=-r&&e<=n+r&&t>=-r&&t<=o+r}var fu=/* @__PURE__ */new Set(["label","callout","callout-circle","callout-rect","text","widget"]);function pu(e){return"string"==typeof e?.type?e.type:""}function gu(e){return!!e&&"object"==typeof e&&fu.has(pu(e))}function mu(e,t,i){return Math.max(t,Math.min(i,e))}function yu(e){return gu(e)}function xu(e){return"primary"===e?.emphasis||!0===e?.defensive}function bu(e,t,i={}){if("number"==typeof i.maxAnnotations&&Number.isFinite(i.maxAnnotations))return Math.max(0,Math.floor(i.maxAnnotations));if(!(e>0&&t>0))return 1/0;let r=i.areaPerAnnotation&&i.areaPerAnnotation>0?i.areaPerAnnotation:2e4;return Math.max(1,Math.round(e*t/r))}function vu(e){let t,i=e?.emphasis;t="primary"===i?100:"secondary"===i?10:50;let r=e?.provenance?.confidence;switch("number"==typeof r&&Number.isFinite(r)&&(t+=15*mu(r,0,1)),e?.lifecycle?.freshness){case"fresh":t+=8;break;case"aging":t+=4;break;case"stale":t+=1;break;case"expired":t-=200}return t}function wu(e){let{annotations:t,width:i,height:r}=e,n=Math.max(0,e.minVisible??1),o=bu(i,r,e),a=t.map((e,t)=>({annotation:e,index:t,note:yu(e)})),s=a.filter(e=>e.note);if(0===s.length||s.length<=o)return{visible:t.slice(),deferred:[],budget:o};let l=s.filter(e=>xu(e.annotation)),c=s.filter(e=>!xu(e.annotation)).sort((e,t)=>vu(t.annotation)-vu(e.annotation)||e.index-t.index),u=Math.max(0,o-l.length),d=Math.max(0,n-l.length),h=Math.min(c.length,Math.max(u,d)),f=/* @__PURE__ */new Set([...l.map(e=>e.index),...c.slice(0,h).map(e=>e.index)]),p=[],g=[];for(let{annotation:e,index:t,note:i}of a)!i||f.has(t)?p.push(e):g.push(e);return{visible:p,deferred:g,budget:o}}var ku=32,Su=6,Au=4,Mu=8,$u=72;function _u(e){return"number"==typeof e.dx||"number"==typeof e.dy}function Iu(e){return"text"===e.type||"widget"===e.type?{dx:0,dy:0}:{dx:30,dy:-30}}function Pu(e){let t=e?.familiarity;if(!t)return 3;let i=Object.values(t).filter(e=>"number"==typeof e&&Number.isFinite(e));return 0===i.length?3:i.reduce((e,t)=>e+t,0)/i.length}function Lu(e){if(!e)return 1;let t=Pu(e);return t<=2?1.5:t>=4?.6:1}var Ru={ai:"AI",agent:"agent",watcher:"watcher",system:"system",import:"imported",computed:"computed",user:"you"};function Cu(e){let t=e?.provenance;if(!t||"object"!=typeof t)return e;let i="string"==typeof t.source?Object.prototype.hasOwnProperty.call(Ru,t.source)?Ru[t.source]:t.source:null,r="number"==typeof t.confidence&&Number.isFinite(t.confidence)?`${Math.round(100*Math.max(0,Math.min(1,t.confidence)))}%`:null;if(!i&&!r||null!=e.label&&"string"!=typeof e.label)return e;let n=[i,r].filter(Boolean).join(" · "),o="string"==typeof e.label?e.label:"";return o.includes(`(${n})`)?e:{...e,label:o?`${o} (${n})`:`(${n})`}}function Tu(e,t){let i=!1,r=e.map(e=>Eu(e)&&"blended"!==e.cohesion&&"layer"!==e.cohesion?(i=!0,{...e,cohesion:t}):e);return i?r:e}function Nu(e){if(!Eu(e))return e;let t="string"==typeof e.mobileText?e.mobileText:void 0,i="string"==typeof e.shortText?e.shortText:void 0,r=t??i;return!r||"string"!=typeof e.label&&null!=e.label?e:{...e,label:r}}function Fu(e){if("text"!==e.type||"string"!=typeof e.color)return e;let t="number"==typeof e.dx?e.dx:0,i="number"==typeof e.dy?e.dy:0;return Math.hypot(t,i)<8?e:{...e,_redundantConnector:!0}}function Eu(e){return gu(e)}function Ou(e){if("widget"===e.type)return{width:"number"==typeof e.width?e.width:32,height:"number"==typeof e.height?e.height:32};let t=zc(e);if(t)return{width:Math.max(24,t.width+10),height:Math.max(18,t.height+6)};let i="number"==typeof e.wrap?e.wrap:120,r=[...Dc("string"==typeof e.title?e.title:void 0,i,7),...Dc("string"==typeof e.label?e.label:void 0,i,7)],n=r.reduce((e,t)=>Math.max(e,t.length),0);return{width:Math.max(24,Math.min(i,7*n)+10),height:Math.max(18,16*r.length+6)}}function zu(e,t,i,r,n){let o=e+i,a=t+r;return Math.abs(i)>Math.abs(r)?{x:i>=0?o+4:o-n.width-4,y:r<0?a-n.height:a,width:n.width,height:n.height}:{x:i>=0?o:o-n.width,y:r<0?a-n.height-4:a+4,width:n.width,height:n.height}}function Du(e,t){return{x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t}}function Bu(e,t){return Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function ju(e,t,i,r){let n=Math.max(0,r-e.x),o=Math.max(0,r-e.y),a=Math.max(0,e.x+e.width-(t-r)),s=Math.max(0,e.y+e.height-(i-r));return(n+a)*e.height+(o+s)*e.width}function Wu(e){let t=1.6*e;return[{dx:e,dy:-e},{dx:-e,dy:-e},{dx:e,dy:e},{dx:-e,dy:e},{dx:e,dy:0},{dx:-e,dy:0},{dx:0,dy:-e},{dx:0,dy:e},{dx:t,dy:-t},{dx:-t,dy:-t},{dx:t,dy:t},{dx:-t,dy:t}]}function Yu(e,t){return(e.pointNodes||[]).map(e=>{let i=Math.max(1,e.r||1)+t;return{x:e.x-i,y:e.y-i,width:2*i,height:2*i}})}function qu(e,t,i,r,n,o,a,s){let l=Du(e,a),c=.4*Math.hypot(t.dx,t.dy)+80*ju(l,n,o,s);for(let e of i)c+=12*Bu(l,e);for(let e of r)c+=4*Bu(l,e);return c}function Xu(e,t,i){if("widget"===e.type&&"number"==typeof e.px&&"number"==typeof e.py)return{x:e.px,y:e.py};let r=e.pointId??e.nodeId;if(null!=r&&i.pointNodes){let e=i.pointNodes.find(e=>e.pointId===r);if(e)return{x:e.x,y:e.y}}let n=e.coordinates,o=i.scales?.geoProjection;if(Array.isArray(n)&&n.length>=2&&o){let e=n[0],t=n[1];if("number"==typeof e&&"number"==typeof t){let i=o([e,t]);if(i&&"number"==typeof i[0]&&"number"==typeof i[1])return{x:i[0],y:i[1]}}}return i.scales||"number"!=typeof e.x||"number"!=typeof e.y?du(e,t,i):{x:e.x,y:e.y}}function Gu(e){let{annotations:t,context:i,defaultOffset:r=ku,notePadding:n=Su,markPadding:o=Au,edgePadding:a=Mu,preserveManualOffsets:s=!0,routeLongConnectors:l=!0,connectorThreshold:c=$u,density:u,progressiveDisclosure:d=!1,redundantCues:h=!1,responsive:f,mobile:p,cohesion:g,audience:m}=e,y=i.width||0,x=i.height||0,b="object"==typeof p?p:{},v=b.breakpoint??480,w=!!p&&y<=v,k=w&&!1!==b.preferShortText?t.map(Nu):t,S=w&&!u?{maxAnnotations:b.maxAnnotations??("callout-list"===b.strategy?1:2),minVisible:b.minVisible??1}:u,A=d||w&&(!1!==b.progressiveDisclosure||"callout-list"===b.strategy),M=w&&!f?b.responsive??{minWidth:v}:f,$=w&&!g?b.cohesion:g;if(0===k.length||y<=0||x<=0)return k.slice();let _=[],I=Yu(i,o),P=!1,L=k.map((e,t)=>{if(!Eu(e))return e;let o=Xu(e,t,i);if(!o)return e;let u=Ou(!0===e.defensive?Cu(e):e);if(s&&_u(e)){let t=Iu(e),i="number"==typeof e.dx?e.dx:t.dx,r="number"==typeof e.dy?e.dy:t.dy;return _.push(Du(zu(o.x,o.y,i,r,u),n)),e}let d=null,h=1/0;for(let e of Wu(r)){let t=qu(zu(o.x,o.y,e.dx,e.dy,u),e,_,I,y,x,n,a);t<h&&(d=e,h=t)}if(!d)return e;let f=Du(zu(o.x,o.y,d.dx,d.dy,u),n);_.push(f);let p=Math.hypot(d.dx,d.dy),g=l&&p>=c&&"text"!==e.type&&"widget"!==e.type?{...e.connector||{end:"arrow"},type:"curve"}:e.connector;return P=!0,{...e,dx:d.dx,dy:d.dy,...g?{connector:g}:{}}}),R=P?L:k.slice(),C=R;if(h){let e=!1,t=R.map(t=>{let i=Fu(t);return i!==t&&(e=!0),i});C=e?t:R}{let e=!1,t=C.map(t=>{if(!0!==t?.defensive)return t;let i=Cu(t);return i!==t&&(e=!0),i});C=e?t:C}let T,N=/* @__PURE__ */new Set;if(S){let e="object"==typeof S?S:{},t=Lu(m),i=1===t?e:{...e,maxAnnotations:Math.max(0,Math.round((e.maxAnnotations??bu(y,x,e))*t))},{deferred:r}=wu({annotations:C,width:y,height:x,...i});for(let e of r)N.add(e)}if(M){let e="object"==typeof M&&"number"==typeof M.minWidth?M.minWidth:480;if(y<=e)for(let e of C)Eu(e)&&"secondary"===e.emphasis&&N.add(e)}if(N.size>0)for(let e of C)!0===e?.defensive&&N.delete(e);return T=0===N.size?C:A?C.map(e=>N.has(e)?{...e,_annotationDeferred:!0}:e):C.filter(e=>!N.has(e)),$?Tu(T,$):T}function Vu(e,t,i,r){let n=nl(e.fill??e.color,t,r),o="string"==typeof e.fill&&e.fill?e.fill:"string"==typeof e.color&&e.color?e.color:r;return al(e.gradient,t,i,o)??n}var Hu=/* @__PURE__ */new Set(["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"]);function Uu(e,t,i){let r=e.position,n="string"==typeof r&&Hu.has(r)?r:"bottom-left",o=n.endsWith("left")?"left":n.endsWith("right")?"right":"center",a=n.startsWith("top")?"top":n.startsWith("bottom")?"bottom":"middle",s="top"===a?0:"bottom"===a?i:i/2;return{x:("left"===o?0:"right"===o?t:t/2)+("number"==typeof e.dx&&Number.isFinite(e.dx)?e.dx:0),y:s+("number"==typeof e.dy&&Number.isFinite(e.dy)?e.dy:0),textAnchor:"start"===e.textAnchor||"middle"===e.textAnchor||"end"===e.textAnchor?e.textAnchor:"left"===o?"start":"right"===o?"end":"middle",dominantBaseline:"auto"===e.dominantBaseline||"middle"===e.dominantBaseline||"hanging"===e.dominantBaseline?e.dominantBaseline:"top"===a?"hanging":"bottom"===a?"auto":"middle"}}function Ku(e,t,i,r){return{...Uu(e,t,i),fill:e.fill??e.color??r.fill,fontSize:e.fontSize??r.fontSize,fontFamily:e.fontFamily??r.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,letterSpacing:e.letterSpacing,opacity:e.opacity,className:e.className,style:{pointerEvents:"none"}}}import{jsx as Zu}from"react/jsx-runtime";var Qu={fill:"var(--semiotic-text, #333)",fontSize:11,fontFamily:"inherit"};function Ju({annotation:e,width:t,height:i,defaults:r=Qu}){let n=e.label??e.text;return null==n?null:/* @__PURE__ */Zu("text",{...Ku(e,t,i,r),children:n})}import{packEnclose as ed}from"d3-hierarchy";import{area as td,curveBasis as id,curveCardinal as rd,curveCatmullRom as nd,curveLinear as od,curveMonotoneX as ad,curveMonotoneY as sd,curveStep as ld,curveStepAfter as cd,curveStepBefore as ud}from"d3-shape";import*as dd from"react";function hd(e){let t=e.provenance,i=e.id??e.stableId??t?.stableId;return null==i||""===i?void 0:String(i)}function fd(e){let t=e.nativeEvent;return"touch"===t.pointerType?"touch":0===t.detail?"keyboard":"pointer"}function pd(e,t={}){let i=hd(e);return{"data-semiotic-annotation-widget":"",...i?{"data-semiotic-annotation-id":i}:{},onClickCapture(r){let n=fd(r);t.onAnnotationActivate?.({annotation:e,annotationId:i,chartId:t.chartId,inputType:n}),i&&t.onObservation&&t.onObservation({type:"annotation-activate",annotationId:i,inputType:n,timestamp:Date.now(),chartType:t.chartType??"unknown",chartId:t.chartId})}}}function gd(e,t){return Sc(e)?Mc(e)??t:e}function md(e,t,i){let r=e.labelBackground,n=t.colors.background,o=n&&"transparent"!==n?n:t.colors.surface||n;return void 0===r?"none"===i?"none":{type:"halo",fill:o}:!1===r||"none"===r?"none":!0===r||"halo"===r?{type:"halo",fill:o}:"box"===r?{type:"box",fill:o}:{...r,fill:gd(r.fill,o)??o,...void 0!==r.stroke?{stroke:gd(r.stroke,t.colors.border)}:{}}}function yd(e,t){let i=t.scales?.x??t.scales?.time,r=t.scales?.y??t.scales?.value;if(!i||!r)return[];let n=t.data||[],o=t.xAccessor||"x",a=t.yAccessor||"y",s="horizontal"===t.projection,l="ordinal"===t.frameType;l&&s&&([o,a]=[a,o]);let c=i,u=r,d=s?u:c,h=l?t.scales?.o?.domain().map(String)??[...new Set(n.filter(e=>null!=e[o]).map(e=>String(e[o])))].sort((e,t)=>d(e)-d(t)):[],f=new Map(h.map((e,t)=>[e,t])),p=Sr(n.map(e=>[l?null==e[o]?void 0:f.get(String(e[o])):e[o],e[a]]));return p.length<2?[]:("loess"===e.method?Lr(p,e.bandwidth??.3):("polynomial"===e.method?$r(p,e.order??2):Mr(p)).points).map(([e,t])=>{if(!l)return[c(e),u(t)];let i=d(h[e]);return s?[c(t),i]:[i,u(t)]}).filter(([e,t])=>Number.isFinite(e)&&Number.isFinite(t))}import{jsx as xd,jsxs as bd}from"react/jsx-runtime";var vd={linear:od,monotoneX:ad,monotoneY:sd,step:ld,stepAfter:cd,stepBefore:ud,basis:id,cardinal:rd,catmullRom:nd};function wd(e,t,i,r){let n=e.color||r?.colors.textSecondary||"#666",o=r?md(e,r,"none"):e.labelBackground??"none";switch(e.type){case"enclose":{let r=(e.coordinates||[]).map(e=>({x:ru({...e,type:"point"},i),y:nu({...e,type:"point"},i),r:1})).filter(e=>null!=e.x&&null!=e.y);if(r.length<2)return null;let a=ed(r),s=e.padding||10;/* @__PURE__ */
75
- return bd("g",{children:[
76
- /* @__PURE__ */xd("circle",{cx:a.x,cy:a.y,r:a.r+s,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:n,strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&/* @__PURE__ */xd(Rc,{x:a.x,y:a.y-a.r-s-4,textAnchor:"middle",fill:n,fontSize:12,text:e.label,background:o})]},`ann-${t}`)}case"rect-enclose":{let r=(e.coordinates||[]).map(e=>({x:ru({...e,type:"point"},i),y:nu({...e,type:"point"},i)})).filter(e=>null!=e.x&&null!=e.y);if(r.length<2)return null;let a=e.padding||10,[s,l]=yr(r.map(e=>e.x)),[c,u]=yr(r.map(e=>e.y)),d=s-a,h=l+a,f=c-a;/* @__PURE__ */
77
- return bd("g",{children:[
78
- /* @__PURE__ */xd("rect",{x:d,y:f,width:h-d,height:u+a-f,fill:e.fill||"none",fillOpacity:e.fillOpacity??.1,stroke:n,strokeWidth:1.5,strokeDasharray:"4,2"}),e.label&&/* @__PURE__ */xd(Rc,{x:(d+h)/2,y:f-4,textAnchor:"middle",fill:n,fontSize:12,text:e.label,background:o})]},`ann-${t}`)}case"highlight":{let r=i.data||[],n="function"==typeof e.filter?r.filter(e.filter):e.field&&null!=e.value?r.filter(t=>t[e.field]===e.value):[],o={stroke:e.color||"#f97316",strokeWidth:2,fill:"none"};/* @__PURE__ */
79
- return xd("g",{children:n.map((t,r)=>{let n=ru(t,i),a=nu(t,i);if(null==n||null==a)return null;let s="function"==typeof e.r?e.r(t):e.r||6,l="function"==typeof e.style?e.style(t):e.style||o;/* @__PURE__ */
80
- return xd("circle",{cx:n,cy:a,r:s,...l},`hl-${r}`)})},`ann-${t}`)}case"bracket":{let r=ru(e,i),n=nu(e,i);/* @__PURE__ */
81
- return xd(Vc,{noteData:{x:r??0,y:n??0,dx:e.dx||0,dy:e.dy||0,note:Oc(e),type:"bracket",subject:{type:e.bracketType||"curly",width:e.width,height:e.height,depth:e.depth||30},color:e.color}},`ann-${t}`)}case"trend":{let r=yd(e,i);if(r.length<2)return null;let n=r.map(([e,t])=>`${e},${t}`).join(" "),o=e.color||"#6366f1",[a,s]=r[r.length-1];/* @__PURE__ */
82
- return bd("g",{children:[
83
- /* @__PURE__ */xd("polyline",{points:n,fill:"none",stroke:o,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray||"6,3"}),e.label&&/* @__PURE__ */xd("text",{x:a+4,y:s-4,fill:o,fontSize:11,children:e.label})]},`ann-${t}`)}case"envelope":{let r=i.data||[];if(r.length<2)return null;let n=i.xAccessor||"x",o=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!o||!a)return null;let s=e.upperAccessor||"upperBounds",l=e.lowerAccessor||"lowerBounds",c=e.filter,u=r.filter(e=>null!=e[s]&&null!=e[l]&&(!c||c(e))).sort((e,t)=>e[n]-t[n]);if(u.length<2)return null;let d=vd[i.curve||"linear"]||od,h=td().x(e=>o(e[n])).y0(e=>a(e[l])).y1(e=>a(e[s])).curve(d)(u);if(!h)return null;let f=e.fill||"#6366f1",p=u[u.length-1];/* @__PURE__ */
84
- return bd("g",{children:[
85
- /* @__PURE__ */xd("path",{d:h,fill:f,fillOpacity:e.fillOpacity??.15,stroke:"none"}),e.label&&/* @__PURE__ */xd("text",{x:o(p[n])+4,y:a(p[s])-4,fill:f,fontSize:11,children:e.label})]},`ann-${t}`)}case"anomaly-band":{let r=(i.data||[]).filter(t=>!e.filter||e.filter(t));if(r.length<2)return null;let n=i.yAccessor||"y",o=i.scales?.x??i.scales?.time,a=i.scales?.y??i.scales?.value;if(!o||!a)return null;let s=r.map(e=>kr(e[n])).filter(e=>null!==e);if(s.length<2)return null;let l=s.reduce((e,t)=>e+t,0)/s.length,c=s.reduce((e,t)=>e+(t-l)**2,0)/s.length,u=Math.sqrt(c),d=e.threshold??2,h=l-d*u,f=a(l+d*u),p=a(h),g=e.fill||"#6366f1",m=e.anomalyColor||"#ef4444",y=e.anomalyRadius??6,x=r.filter(e=>{let t=kr(e[n]);return null!=t&&Math.abs(t-l)>d*u});/* @__PURE__ */
86
- return bd("g",{children:[!1!==e.showBand&&/* @__PURE__ */xd("rect",{x:0,y:Math.min(f,p),width:i.width||0,height:Math.abs(p-f),fill:g,fillOpacity:e.fillOpacity??.1}),x.map((e,t)=>{let r=ru(e,i),n=nu(e,i);return null==r||null==n?null:/* @__PURE__ */xd("circle",{cx:r,cy:n,r:y,fill:m,fillOpacity:.7,stroke:m,strokeWidth:1.5},`anomaly-${t}`)}),e.label&&/* @__PURE__ */xd("text",{x:(i.width||0)-4,y:Math.min(f,p)-4,textAnchor:"end",fill:g,fontSize:11,children:e.label})]},`ann-${t}`)}case"forecast":{let r=i.data||[],n=i.xAccessor||"x",o=i.yAccessor||"y",a=i.scales?.x??i.scales?.time,s=i.scales?.y??i.scales?.value;if(!a||!s)return null;let l=Sr(r.map(e=>[e[n],e[o]])),c=Cr(l,e);if(!c)return null;let{predict:u}=c,d=l[l.length-1][0],h=c.forecast(e.steps??5);if(!h.length)return null;let f=td().x(e=>a(e.x)).y0(e=>s(e.lower)).y1(e=>s(e.upper))(h);if(!f)return null;let p=h.map(e=>`${a(e.x)},${s(e.y)}`).join(" "),g=e.fill||"#6366f1",m=e.strokeColor||"#6366f1",y=h[h.length-1];/* @__PURE__ */
87
- return bd("g",{children:[
88
- /* @__PURE__ */xd("path",{d:f,fill:g,fillOpacity:e.fillOpacity??.15,stroke:"none"}),
89
- /* @__PURE__ */xd("polyline",{points:`${a(d)},${s(u(d))} ${p}`,fill:"none",stroke:m,strokeWidth:e.strokeWidth??2,strokeDasharray:e.strokeDasharray??"6,3"}),e.label&&y&&/* @__PURE__ */xd("text",{x:a(y.x)+4,y:s(y.y)-4,fill:m,fontSize:11,children:e.label})]},`ann-${t}`)}case"widget":{let r,n;if(null!=e.px&&null!=e.py)r=e.px,n=e.py;else{let o=du(e,t,i);if(!o)return null;r=o.x,n=o.y}if(!hu(r,n,i))return null;let o=e.width??32,a=e.height??32,s=e.content??/* @__PURE__ */xd("span",{style:{fontSize:18,cursor:"default"},title:e.label||"Info",children:"ℹ️"});/* @__PURE__ */
90
- return xd("foreignObject",{x:r+(e.dx??0)-o/2,y:n+(e.dy??0)-a/2,width:o,height:a,style:{overflow:"visible",pointerEvents:"auto"},children:/* @__PURE__ */xd("div",{...pd(e),style:{width:o,height:a,display:"flex",alignItems:"center",justifyContent:"center"},children:s})},`ann-${t}`)}default:return null}}import{jsx as kd,jsxs as Sd}from"react/jsx-runtime";function Ad(e,t){return e.color||t.colors.annotation||t.colors.text}function Md(e,t,i,r){if(Array.isArray(e.coordinates)&&e.coordinates.length>=2&&t.geoProjection){let i=t.geoProjection([e.coordinates[0],e.coordinates[1]]);if(i)return{x:i[0],y:i[1]}}return{x:$d(e,t,i),y:_d(e,t,r)}}function $d(e,t,i){return null!=e.x&&t.x?t.x(e.x):i&&null!=e[i]&&t.x?t.x(e[i]):"number"==typeof e.x?e.x:null}function _d(e,t,i){return null!=e.y&&t.y?t.y(e.y):i&&null!=e[i]&&t.y?t.y(e[i]):"number"==typeof e.y?e.y:null}function Id(e){let{annotations:t}=e;if(!t||0===t.length)return e.onRender?.({inputCount:0,eligibleCount:0,renderedCount:0,unrenderedCount:0,unrenderedTypes:[]}),null;let i=_o(t).filter(e=>!e._directLabel),r=e.scales.geoProjection,n=r?i.map(e=>{if(!Array.isArray(e.coordinates)||e.coordinates.length<2)return e;let t=r([Number(e.coordinates[0]),Number(e.coordinates[1])]);return t?{...e,x:t[0],y:t[1]}:e}):i,o=!!r&&!e.scales.x&&!e.scales.y,a=e=>Number(e),s=e.scales.x??(o?a:void 0),l=e.scales.y??(o?a:void 0),c=e.frameType??(e.projection?"ordinal":r||e.scales.x||e.scales.y?"xy":"network"),u="horizontal"===e.projection,d=e.projection?u?"horizontal":"vertical":void 0,h="vertical"===e.projection||u,f=e.scales.o,p=f?e=>(f(e)??0)+(f.bandwidth?.()??0)/2:void 0,g={scales:{x:(h?u?e.scales.r:p:void 0)??s,y:(h?u?p:e.scales.r:void 0)??l,time:h?e.scales.r:s,value:h?e.scales.r:l,o:f,...r?{geoProjection:r}:{}},width:e.layout.width,height:e.layout.height,xAccessor:e.xAccessor,yAccessor:e.yAccessor,data:e.annotationData,pointNodes:e.pointNodes,frameType:c,...d?{projection:d}:{}},m=kc(t,{...e.layout,scales:e.scales,margin:e.margin,fontFamily:e.theme.typography.fontFamily,measure:e.labelMeasurer,...e.svgAnnotationRules?{renderLabel:(t,i,r)=>e.svgAnnotationRules(t,i,g)??r}:{}}),y=e.autoPlaceAnnotations?Gu({annotations:n,context:g,..."object"==typeof e.autoPlaceAnnotations?e.autoPlaceAnnotations:{}}):n,x=iu(y,(t,i,r)=>Pd(t,i,e,r)??wd(t,i,r,e.theme),e.svgAnnotationRules,g),b=m.node?[...x.nodes,m.node]:x.nodes,v=/* @__PURE__ */new Map;for(let e of x.renderedAnnotations){let t="string"==typeof e.type?e.type:"unknown";v.set(t,(v.get(t)??0)+1)}m.evidence&&v.set("text",(v.get("text")??0)+m.evidence.rendered);let w=[];for(let e of t){let t="string"==typeof e.type?e.type:"unknown",i=v.get(t)??0;i>0?v.set(t,i-1):w.push(t)}e.onRender?.({inputCount:t.length,eligibleCount:y.length,renderedCount:x.renderedAnnotations.length+(m.evidence?.rendered??0),...m.evidence?{layout:m.evidence}:{},unrenderedCount:w.length,unrenderedTypes:w});let k=e.idPrefix?`${e.idPrefix}-`:"";return b.length>0?/* @__PURE__ */kd("g",{id:`${k}annotations`,className:"semiotic-annotations",children:b}):null}function Pd(e,t,i,r){let{scales:n,layout:o,theme:a,xAccessor:s,yAccessor:l}=i;switch(e.type){case"frame-text":/* @__PURE__ */
91
- return kd(Ju,{annotation:e,width:o.width,height:o.height,defaults:{fill:a.colors.text,fontSize:11,fontFamily:a.typography.fontFamily}},`ann-frame-text-${t}`);case"y-threshold":{let r=e.value??e.y;if(null==r)return null;let s=Ad(e,a),l=e.label,c=e.strokeDasharray||"6,4",u=e.strokeWidth??1.5;if("horizontal"===i.projection&&n.r){let i=n.r(r);return null==i?null:/* @__PURE__ */Sd("g",{opacity:e.opacity,children:[
92
- /* @__PURE__ */kd("line",{x1:i,y1:0,x2:i,y2:o.height,stroke:s,strokeWidth:u,strokeDasharray:c}),Tc(e.endCap,[i,0],s),l&&/* @__PURE__ */kd(Rc,{x:i+4,y:16,textAnchor:"start",fontSize:a.typography.tickSize,fill:e.labelColor??s,fontFamily:a.typography.fontFamily,text:l,background:md(e,a,"halo")})]},`ann-ythresh-${t}`)}let d=n.y?n.y(r):n.r?n.r(r):null;return null==d?null:/* @__PURE__ */kd(Ec,{ann:e,position:d,vertical:!1,width:o.width,height:o.height,color:s,fontSize:a.typography.tickSize,fontFamily:a.typography.fontFamily,background:md(e,a,"halo"),dash:"6,4",labelGap:6},`ann-ythresh-${t}`)}case"x-threshold":{let r=e.value??e.x;if(null==r)return null;let s="horizontal"===i.projection&&n.r?n.r(r):n.x?n.x(r):null;if(null==s)return null;let l=Ad(e,a);/* @__PURE__ */
93
- return kd(Ec,{ann:e,position:s,vertical:!0,width:o.width,height:o.height,color:l,fontSize:a.typography.tickSize,fontFamily:a.typography.fontFamily,background:md(e,a,"halo"),dash:"6,4"},`ann-xthresh-${t}`)}case"band":{let r=n.y?.domain?.(),s=e.y0??r?.[0],l=e.y1??r?.[1],c=null!=s&&n.y?n.y(s):null,u=null!=l&&n.y?n.y(l):null;if(null==c||null==u)return null;let d=Math.min(c,u),h=Math.abs(u-c),f=Vu(e,`ssr-band-${t}`,"vertical",a.colors.primary||Ad(e,a)),p=e.fillOpacity??.1,g=!0===i.underLayerBands&&"under"===e.layer;/* @__PURE__ */
94
- return Sd("g",{opacity:e.opacity,children:[!g&&f.def&&/* @__PURE__ */kd("defs",{children:f.def}),!g&&/* @__PURE__ */kd("rect",{x:0,y:d,width:o.width,height:h,fill:f.fill,fillOpacity:p}),e.label&&/* @__PURE__ */kd(Rc,{x:o.width-4,y:Math.max(d,0)+16,textAnchor:"end",fontSize:a.typography.tickSize,fill:e.labelColor??(e.color||a.colors.primary||Ad(e,a)),fontFamily:a.typography.fontFamily,fontWeight:"bold",text:e.label,background:md(e,a,"halo")})]},`ann-band-${t}`)}case"x-band":{let r=n.x?.domain?.(),s=e.x0??r?.[0],l=e.x1??r?.[1],c=null!=s&&n.x?n.x(s):null,u=null!=l&&n.x?n.x(l):null;if(null==c||null==u)return null;let d=Math.min(c,u),h=Math.abs(u-c),f=Vu(e,`ssr-xband-${t}`,"horizontal",a.colors.primary||Ad(e,a)),p=e.fillOpacity??.1,g=!0===i.underLayerBands&&"under"===e.layer;/* @__PURE__ */
95
- return Sd("g",{opacity:e.opacity,children:[!g&&f.def&&/* @__PURE__ */kd("defs",{children:f.def}),!g&&/* @__PURE__ */kd("rect",{x:d,y:0,width:h,height:o.height,fill:f.fill,fillOpacity:p}),e.label&&/* @__PURE__ */kd(Rc,{x:d+4,y:16,textAnchor:"start",fontSize:a.typography.tickSize,fill:e.labelColor??(e.color||a.colors.primary||Ad(e,a)),fontFamily:a.typography.fontFamily,fontWeight:"bold",text:e.label,background:md(e,a,"halo")})]},`ann-xband-${t}`)}case"category-highlight":{if(null==e.category||!n.o)return null;let r=n.o(String(e.category));if(null==r)return null;let s=n.o.bandwidth?n.o.bandwidth():40,l=Ad(e,a),c=e.opacity??.1,u=e.label;return"horizontal"===i.projection?/* @__PURE__ */Sd("g",{children:[
96
- /* @__PURE__ */kd("rect",{x:0,y:r,width:o.width,height:s,fill:l,opacity:c}),u&&/* @__PURE__ */kd(Rc,{x:12,y:r+s/2,dominantBaseline:"middle",fill:l,fontSize:a.typography.tickSize,fontWeight:"bold",fontFamily:a.typography.fontFamily,text:u,background:md(e,a,"none")})]},`ann-cathighlight-${t}`):/* @__PURE__ */Sd("g",{children:[
97
- /* @__PURE__ */kd("rect",{x:r,y:0,width:s,height:o.height,fill:l,opacity:c}),u&&/* @__PURE__ */kd(Rc,{x:r+s/2,y:16,textAnchor:"middle",fill:l,fontSize:a.typography.tickSize,fontWeight:"bold",fontFamily:a.typography.fontFamily,text:u,background:md(e,a,"none")})]},`ann-cathighlight-${t}`)}case"label":case"callout":case"callout-circle":case"callout-rect":case"text":{let i=Md(e,n,s,l),o=null==i.x||null==i.y?du(e,t,r):null,c=i.x??o?.x??null,u=i.y??o?.y??null;if(null==c||null==u)return null;let d="text"===e.type,h=e.dx??(d?0:30),f=e.dy??(d?0:-30),p=e.color||a.colors.text;if(!d){let i="callout"===e.type?"callout-circle":e.type,r="callout-circle"===i?{radius:e.radius??12,radiusPadding:e.radiusPadding}:"callout-rect"===i?{width:e.width,height:e.height}:void 0;/* @__PURE__ */
98
- return kd(Vc,{noteData:{x:c,y:u,dx:h,dy:f,note:Oc(e),type:i,...r?{subject:r}:{},connector:e.connector||{end:"arrow"},color:p,disable:e.disable,opacity:e.opacity,strokeDasharray:e.strokeDasharray,className:e.className}},`ann-label-${t}`)}/* @__PURE__ */
99
- return kd("g",{children:/* @__PURE__ */kd("text",{x:c+h,y:u+f,textAnchor:e.textAnchor||"start",fontSize:e.fontSize||a.typography.labelSize,fill:p,fontFamily:a.typography.fontFamily,fontWeight:e.fontWeight,opacity:e.opacity,strokeDasharray:e.strokeDasharray,children:e.label||e.title})},`ann-label-${t}`)}default:return null}}import{jsx as Ld}from"react/jsx-runtime";function Rd(e,t,i,r="right",n,o){if(null==e||!1===e)return null;let{x:a,y:s}=U(e,{totalWidth:t[0],totalHeight:t[1],margin:i,position:r,legendLayout:n,axisChrome:o});/* @__PURE__ */
100
- return Ld("g",{transform:`translate(${a}, ${s})`,children:e})}function Cd(e){let t=String(e).replace(/[^a-zA-Z0-9_-]/g,"_"),i=/^[A-Za-z_]/.test(t)?t:`c${t}`,r=`${i}-semiotic-title`,n=`${i}-semiotic-desc`;return{titleId:r,descId:n,labelledBy:`${r} ${n}`}}function Td(e,t){if(0===t.categories.length)return;let i=t.position||"right";H(e,{legend:ic(t.categories,t.colorScheme,t.theme),position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}function Nd(e,t){let i=t.position||"right";H(e,{legend:t.legend,position:i,size:t.size,hasTitle:t.hasTitle,legendLayout:t.legendLayout,minimumMargin:t.minimumMargin,axisChrome:t.axisChrome})}import*as Fd from"react";function Ed(e,t,i){if("edges"===e){if(t)return"start";if(i)return"end"}return"middle"}function Od(e,t,i){if("edges"===e){if(t)return"hanging";if(i)return"auto"}return"middle"}function zd(e){if(0===e.length)return{min:null,max:null};let t=1/0,i=-1/0;for(let r of e)r.pixel<t&&(t=r.pixel),r.pixel>i&&(i=r.pixel);return{min:t,max:i}}function Dd(e){if(e)return"object"==typeof e?e.strokeDasharray:"dashed"===e?"6,4":"dotted"===e?"2,4":e}function Bd(e,t){return e&&"string"!=typeof e?{stroke:e.stroke??t.stroke,strokeWidth:e.strokeWidth??t.strokeWidth,...null!=e.strokeOpacity&&{strokeOpacity:e.strokeOpacity},...e.strokeDasharray&&{strokeDasharray:e.strokeDasharray}}:{...t,..."string"==typeof e&&{strokeDasharray:Dd(e)}}}function jd(e,t,i){if("left"===e||"right"===e){let r="left"===e?i:0,n="left"===e?-1:1,o=Math.ceil(t/8),a=`M0,${r}`;for(let e=0;e<o;e++){let i=8*e+4,o=8*(e+1);a+=`L${Math.min(i,t)},${r+4*n}`,a+=`L${Math.min(o,t)},${r}`}return a}let r="bottom"===e?0:t,n="bottom"===e?1:-1,o=Math.ceil(i/8),a=`M${r},0`;for(let e=0;e<o;e++){let t=8*e+4,o=8*(e+1);a+=`L${r+4*n},${Math.min(t,i)}`,a+=`L${r},${Math.min(o,i)}`}return a}function Wd(e,t){let i=e.domain(),r=i[0],n=i[i.length-1],o=r instanceof Date,a=r instanceof Date?r.getTime():r,s=n instanceof Date?n.getTime():n;if(t<2||a===s)return o?[new Date(a),new Date(s)]:[a,s];let l=(s-a)/(t-1),c=new Array(t);for(let e=0;e<t;e++){let i=e===t-1?s:a+e*l;c[e]=o?new Date(i):i}return c}function Yd(e,t,i){return"exact"===i?Wd(e,t):e.ticks(t)}import{jsx as qd}from"react/jsx-runtime";function Xd(e){return"string"==typeof e||"number"==typeof e}function Gd(e){let{label:t,x:i,y:r,textAlign:n,fontSize:o,fontFamily:a,color:s}=e;/* @__PURE__ */
101
- return qd("foreignObject",{x:i,y:r,width:60,height:24,style:{overflow:"visible"},children:/* @__PURE__ */qd("div",{style:{color:s,fontFamily:a,fontSize:o,textAlign:n,userSelect:"none"},children:t})})}function Vd(e){return e instanceof Date?e:"number"==typeof e&&e>1e9?new Date(e):null}function Hd(e,t){let i=Vd(e);if(!i)return!1;let r=Vd(t);return!r||i.getFullYear()!==r.getFullYear()||i.getMonth()!==r.getMonth()}function Ud(e,t,i,r){return!!e&&("function"==typeof e?e(t.value,i):Hd(t.value,i>0?r[i-1].value:void 0))}function Kd(e,t){return e?.ticks??e?.tickCount??t}function Zd(e,t){return!("string"!=typeof e&&"number"!=typeof e||"string"!=typeof t&&"number"!=typeof t||String(e)!==String(t))}function Qd(e,t){if(e.length<=2)return e;let i=[e[0]];for(let r=1;r<e.length-1;r++)Math.abs(e[r].pixel-i[i.length-1].pixel)>=t&&i.push(e[r]);let r=e[e.length-1];return Math.abs(r.pixel-i[i.length-1].pixel)>=t?i.push(r):i[i.length-1]=r,i}function Jd(e){return"string"==typeof e||"number"==typeof e?6.5*String(e).length:60}function eh(e){for(let t=1;t<e.length;t++){let i=e[t-1],r=e[t];if(Math.abs(r.pixel-i.pixel)<(Jd(i.label)+Jd(r.label))/2+8)return!0}return!1}function th(e){let{scale:t,axis:i,size:r,horizontal:n=!1,axisExtent:o}=e,a=i?.extent??o,s=t.domain(),l=Kd(i,5),c=Math.max(2,Math.floor(r/(n?70:30))),u="exact"===a?Math.max(2,l):Math.min(l,c),d=i?.tickValues??Yd(t,u,a),h=d.map(e=>e.valueOf()),f=i?.tickFormat||e.format||(s[0]instanceof Date||d[0]instanceof Date?wn([s[0].valueOf(),s[s.length-1].valueOf()]):I(h)),p=(e,t)=>n?f(e,t,h):f(e),g=d.map((e,i)=>({value:e,pixel:t(e),label:p(e,i)})),m=22;if(n){let e=g.reduce((e,t)=>Math.max(e,Jd(t.label)),0);m=i?.autoRotate?Math.max(20,Math.min(e+8,55)):Math.max(55,e+8)}let y=n&&(i?.tickFormat||e.format)?e=>{let t=e.map(e=>e.value.valueOf());return e.map((e,i)=>({...e,label:f(e.value,i,t)}))}:void 0,x=Qd(g,m);if(y&&(x=y(x)),x.length>1&&(x=x.filter((e,t)=>0===t||!Zd(e.label,x[t-1].label))),i?.includeMax&&x.length>0&&"exact"!==a&&!i.tickValues){let e=s[s.length-1];if(null!=e){let i=t(e),r=Math.abs(i-x[x.length-1].pixel);if(r>1){let t=p(e,x.length);r<m&&x.length>1&&(x=x.slice(0,-1)),x=[...x,{value:e,pixel:i,label:t}]}}}return y?y(x):x}import{jsx as ih,jsxs as rh}from"react/jsx-runtime";function nh(e){let t=e._idPrefix||e.chartId;if(t){let e=String(t).replace(/[^a-zA-Z0-9_-]/g,"_");return/^[A-Za-z_]/.test(e)?e:`c${e}`}let i=`${e.chartType||""}:${e.title||""}:${Array.isArray(e.data)?e.data.length:0}`,r=0;for(let e=0;e<i.length;e++)r=31*r+i.charCodeAt(e)|0;return`c${(r>>>0).toString(36)}`}function oh(e,t,i){return P(e.showLegend&&!e.__legendIncludesAutomatic?ic(t,e.colorScheme,i):void 0,e.legend)}var ah={right:110,left:110,top:50,bottom:80};function sh(e,t){if(e.__autoLegendMargin)return ah[t]}function lh(e,t){let i={theme:t.theme,position:t.position||"right",totalWidth:t.size[0],totalHeight:t.size[1],margin:t.margin,hasTitle:t.hasTitle,legendLayout:t.legendLayout,idPrefix:t.idPrefix,reservedWidth:t.reservedWidth,axisChrome:t.axisChrome,legendDistance:L(e)||R(e)?e.legendDistance:void 0};return L(e)?hc({...i,legendGroups:e.legendGroups}):R(e)?fc({...i,gradient:e.gradient}):null}function ch(e,t){let{props:i,categories:r,theme:n,size:o,hasTitle:a}=t,s=i.legendPosition||"right",l={...e},c={theme:n,position:s,size:o,hasTitle:a,legendLayout:i.legendLayout,axisChrome:i.axisChrome,minimumMargin:sh(i,s)};if(void 0!==i.legend&&null!==i.legend){let t=oh(i,r,n);null!=t&&!1!==t&&Nd(e,{...c,legend:t})}else i.showLegend&&r.length>0&&Td(e,{...c,categories:r,colorScheme:i.colorScheme});return F(e,l,o,s),s}function uh(e){let{props:t,categories:i,theme:r,size:n,margin:o,hasTitle:a}=e,s=t.legendPosition||"right",l={theme:r,position:s,size:n,margin:o,hasTitle:a,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix};if(void 0!==t.legend&&null!==t.legend){let e=oh(t,i,r);return Fd.isValidElement(e)?Rd(e,n,o,s,t.legendLayout,t.axisChrome):lh(e,l)||(L(e)||R(e)?null:Rd(e??null,n,o,s,t.legendLayout,t.axisChrome))}return t.showLegend&&0!==i.length?dc({categories:i,colorScheme:t.colorScheme,theme:r,position:s,totalWidth:n[0],totalHeight:n[1],margin:o,hasTitle:a,legendLayout:t.legendLayout,axisChrome:t.axisChrome,idPrefix:t._idPrefix}):null}function dh(e,t,i,r,n,o){let a=e.scales;if(!a||"radial"===a.projection)return null;let{grid:s}=$(i),l=r?`${r}-`:"",c="vertical"===a.projection,u=o??Yd(a.r,5,n);/* @__PURE__ */
102
- return ih("g",c?{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=a.r(e);/* @__PURE__ */
103
- return ih("line",{x1:0,y1:r,x2:t.width,y2:r,stroke:s,strokeWidth:.5},`gr-${i}`)})}:{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:u.map((e,i)=>{let r=a.r(e);/* @__PURE__ */
104
- return ih("line",{x1:r,y1:0,x2:r,y2:t.height,stroke:s,strokeWidth:.5},`gr-${i}`)})})}function hh(e,t){let i=$(t.theme),r=t.background??i.background,n=t.idPrefix?`${t.idPrefix}-`:"",o="string"==typeof t.title?t.title:void 0,a=t.idPrefix?Cd(t.idPrefix):{titleId:"semiotic-title",descId:"semiotic-desc"},s=o?a.titleId:void 0,l=t.description?a.descId:void 0,c=[s,l].filter(Boolean).join(" ")||void 0;/* @__PURE__ */
105
- return rh("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className,width:t.width,height:t.height,role:"img","aria-labelledby":c,style:{fontFamily:i.fontFamily},children:[o&&/* @__PURE__ */ih("title",{id:s,children:o}),t.description&&/* @__PURE__ */ih("desc",{id:l,children:t.description}),t.defs&&/* @__PURE__ */ih("defs",{children:t.defs}),r&&"transparent"!==r&&/* @__PURE__ */ih("rect",{x:0,y:0,width:t.width,height:t.height,fill:r}),
106
- /* @__PURE__ */ih("g",{id:`${n}data-area`,transform:t.innerTransform,children:e}),o&&/* @__PURE__ */ih("text",{id:`${n}chart-title`,x:t.width/2,y:22,textAnchor:"middle",fontSize:i.titleFontSize,fontWeight:i.titleFontWeight,fill:i.text,fontFamily:i.titleFontFamily,children:o}),t.legend&&/* @__PURE__ */ih("g",{id:`${n}legend`,children:t.legend}),t.outerElements]})}function fh(e,t,i,r,n,o,a,s=!1){let l=$(r),c=i.legendPosition??"right",u=D(i.legendLayout,a?.leftAxis),d=D(i.legendLayout,a?.rightAxis),h=s&&"left"===c&&u>0?u:o?.left??i.margin?.left??40,f=s&&"right"===c&&d>0?d:o?.right??i.margin?.right??40,{xAxis:p,yAxis:g,xOrient:m,yOrient:y}=_(i.axes),x="top"===m?0:t.height,b="right"===y?t.width:0,v="top"===m?-1:1,w="right"===y?1:-1,k=th({scale:e.x,axis:p,size:t.width,horizontal:!0,format:i.xFormat||i.tickFormatTime,axisExtent:i.axisExtent}),S=th({scale:e.y,axis:g,size:t.height,format:i.yFormat||i.tickFormatValue,axisExtent:i.axisExtent}),A=!(!p?.autoRotate||!eh(k)),M=zd(k),I=zd(S),P=p?.label??i.xLabel,L=g?.label??("right"===y?i.yLabelRight??i.yLabel:i.yLabel),R=Bd(p?.axisStyle,{stroke:l.border,strokeWidth:1}),C=Bd(g?.axisStyle,{stroke:l.border,strokeWidth:1}),T="right"===y?t.width+f-15:15-h;/* @__PURE__ */
107
- return rh("g",{id:(n?`${n}-`:"")+"axes",className:"stream-axes",children:[!1!==p?.visible&&/* @__PURE__ */rh("g",{className:`semiotic-axis semiotic-axis-${m}`,"data-orient":m,children:[!1!==p?.baseline&&!p?.jaggedBase&&/* @__PURE__ */ih("line",{x1:0,y1:x,x2:t.width,y2:x,...R}),p?.jaggedBase&&/* @__PURE__ */ih("path",{d:jd(m,t.width,t.height),fill:"none",...R}),k.map((e,t)=>{let i=Ud(p?.landmarkTicks,e,t,k);/* @__PURE__ */
108
- return rh("g",{transform:`translate(${e.pixel},${x})`,children:[
109
- /* @__PURE__ */ih("line",{y2:5*v,...R}),Xd(e.label)?/* @__PURE__ */ih("text",{y:v*(A?12:18),textAnchor:A?"end":Ed(p?.tickAnchor,e.pixel===M.min,e.pixel===M.max),fontWeight:i?600:400,fontSize:i?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,transform:A?"top"===m?"rotate(45)":"rotate(-45)":void 0,children:e.label}):Gd({label:e.label,x:-30,y:"top"===m?-30:6,textAlign:"center",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},`xtick-${t}`)}),P&&/* @__PURE__ */ih("text",{x:t.width/2,y:"top"===m?-(A?58:40):t.height+(A?58:40),textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,children:P})]}),!1!==g?.visible&&/* @__PURE__ */rh("g",{className:`semiotic-axis semiotic-axis-${y}`,"data-orient":y,children:[!1!==g?.baseline&&!g?.jaggedBase&&/* @__PURE__ */ih("line",{x1:b,y1:0,x2:b,y2:t.height,...C}),g?.jaggedBase&&/* @__PURE__ */ih("path",{d:jd(y,t.width,t.height),fill:"none",...C}),S.map((e,t)=>{let i=Ud(g?.landmarkTicks,e,t,S);/* @__PURE__ */
110
- return rh("g",{transform:`translate(${b},${e.pixel})`,children:[
111
- /* @__PURE__ */ih("line",{x2:5*w,...C}),Xd(e.label)?/* @__PURE__ */ih("text",{x:8*w,textAnchor:"right"===y?"start":"end",dominantBaseline:Od(g?.tickAnchor,e.pixel===I.min,e.pixel===I.max),fontWeight:i?600:400,fontSize:i?l.tickSize+1:l.tickSize,fill:l.textSecondary,fontFamily:l.fontFamily,children:e.label}):Gd({label:e.label,x:"right"===y?8:-68,y:-12,textAlign:"right"===y?"left":"right",fontSize:l.tickSize,fontFamily:l.fontFamily,color:l.textSecondary})]},`ytick-${t}`)}),L&&/* @__PURE__ */ih("text",{x:T,y:t.height/2,textAnchor:"middle",fontSize:l.labelSize,fill:l.text,fontFamily:l.fontFamily,transform:`rotate(${"right"===y?90:-90}, ${T}, ${t.height/2})`,children:L})]})]})}import{jsx as ph,jsxs as gh}from"react/jsx-runtime";function mh(e,t,i,r,n,o,a){let{grid:s}=$(i),l=r?`${r}-`:"",c=o?.find(e=>"bottom"===e.orient),u=o?.find(e=>"top"===e.orient),d=o?.find(e=>"left"===e.orient),h=o?.find(e=>"right"===e.orient),f=c??u,p=d??h,g=th({scale:e.x,axis:f,size:t.width,horizontal:!0,format:a?.xFormat||a?.tickFormatTime,axisExtent:n}),m=th({scale:e.y,axis:p,size:t.height,format:a?.yFormat||a?.tickFormatValue,axisExtent:n}),y=!1!==f?.grid,x=!1!==p?.grid,b=Dd(f?.gridStyle),v=Dd(p?.gridStyle),w=Bd(f?.gridStyle,{stroke:s,strokeWidth:.5}),k=Bd(p?.gridStyle,{stroke:s,strokeWidth:.5});/* @__PURE__ */
112
- return gh("g",{id:`${l}grid`,className:"semiotic-grid",opacity:.8,children:[y&&g.map((e,i)=>/* @__PURE__ */ph("line",{x1:e.pixel,y1:0,x2:e.pixel,y2:t.height,...w,strokeDasharray:b??w.strokeDasharray},`gx-${i}`)),x&&m.map((e,i)=>/* @__PURE__ */ph("line",{x1:0,y1:e.pixel,x2:t.width,y2:e.pixel,...k,strokeDasharray:v??k.strokeDasharray},`gy-${i}`))]})}import*as yh from"react";import{jsx as xh,jsxs as bh}from"react/jsx-runtime";function vh(e){return"under"===e.layer&&("band"===e.type||"x-band"===e.type)}function wh(e,t,i,r){let n="band"===e.type,o=n?t.y:t.x;if("function"!=typeof o)return null;let a=o.domain?.(),s=o((n?e.y0:e.x0)??a?.[0]),l=o((n?e.y1:e.x1)??a?.[1]);if(!Number.isFinite(s)||!Number.isFinite(l))return null;let c=n?r:i,u=Math.min(c,Math.max(0,Math.min(s,l))),d=Math.max(0,Math.min(c,Math.max(s,l))-u);return n?{x:0,y:u,width:i,height:d}:{x:u,y:0,width:d,height:r}}function kh(e){return"band"===e.type?"vertical":"horizontal"}function Sh(e,t="under-band",i="var(--semiotic-primary, #6366f1)"){return(r,n,o)=>e.map((e,r)=>{let a=wh(e,n,o.width,o.height);if(!a)return null;let s=Vu(e,`${t}-${r}`,kh(e),i);/* @__PURE__ */
113
- return bh("g",{opacity:e.opacity,children:[s.def&&/* @__PURE__ */xh("defs",{children:s.def}),
114
- /* @__PURE__ */xh("rect",{...a,fill:s.fill,fillOpacity:e.fillOpacity??.1})]},`${t}-${r}`)})}function Ah(e,t){if(!t||0===e.length||!e.some(e=>null!=e&&"object"==typeof e&&Array.isArray(e[t])))return e;let i=[];for(let r of e){if(null==r||"object"!=typeof r)continue;let e=r[t];if(!Array.isArray(e))continue;let n=r.label??r.id??r.key;for(let t of e)null==t||"object"!=typeof t||i.push(null==n?t:{...t,_lineGroup:n})}return i}function Mh(e,t,i,r){return"function"==typeof e?e({size:t,margin:i,scales:r}):e}var $h={top:50,right:40,bottom:60,left:70},_h={top:20,right:80,bottom:20,left:80},Ih={top:40,right:40,bottom:40,left:40},Ph=/* @__PURE__ */new Set(["chord","force","circlepack","orbit"]);function Lh(e){return Ph.has(e)?Ih:_h}import{jsx as Rh,jsxs as Ch}from"react/jsx-runtime";function Th(e){let{scales:t,layout:i,props:r,theme:n,leftAxis:o,rightAxis:a,margin:s,axisChrome:l,hasRenderedLegend:c}=e;if(!o||!a||!1===a.visible)return null;let u=$(n),d=th({scale:t.y,axis:a,size:i.height,format:r.yFormat||r.tickFormatValue,axisExtent:r.axisExtent}),h=zd(d),f=a.label??r.yLabelRight,p=Bd(a.axisStyle,{stroke:u.border,strokeWidth:1}),g=r.legendPosition??"right",m=D(r.legendLayout,l?.rightAxis),y=c&&"right"===g&&m>0?m:s.right,x=i.width+y-15;/* @__PURE__ */
115
- return Ch("g",{className:"stream-axes semiotic-axis semiotic-axis-right","data-orient":"right",children:[!1!==a.baseline&&!a.jaggedBase&&/* @__PURE__ */Rh("line",{x1:i.width,y1:0,x2:i.width,y2:i.height,...p}),a.jaggedBase&&/* @__PURE__ */Rh("path",{d:jd("right",i.width,i.height),fill:"none",...p}),d.map((e,t)=>{let r=Ud(a.landmarkTicks,e,t,d);/* @__PURE__ */
116
- return Ch("g",{transform:`translate(${i.width},${e.pixel})`,children:[
117
- /* @__PURE__ */Rh("line",{x2:5,...p}),Xd(e.label)?/* @__PURE__ */Rh("text",{x:8,textAnchor:"start",dominantBaseline:Od(a.tickAnchor,e.pixel===h.min,e.pixel===h.max),fontWeight:r?600:400,fontSize:r?u.tickSize+1:u.tickSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:e.label}):Gd({label:e.label,x:8,y:-12,textAlign:"left",fontSize:u.tickSize,fontFamily:u.fontFamily,color:u.textSecondary})]},`ytick-r-${t}`)}),f&&/* @__PURE__ */Rh("text",{x:x,y:i.height/2,textAnchor:"middle",fontSize:u.labelSize,fill:u.text,fontFamily:u.fontFamily,transform:`rotate(90, ${x}, ${i.height/2})`,children:f})]})}import{Fragment as Nh,jsx as Fh,jsxs as Eh}from"react/jsx-runtime";function Oh(e,t){let i=M(e.theme),r=$h,n=e.size||[500,300],o=N({...r,...e.margin},e.title),a=C(e.title),s=Ah(ei(e.data),e.lineDataAccessor),l=e.showLegend?pc(s,e.colorAccessor||e.groupAccessor||e.categoryAccessor):[],c=q({showAxes:e.showAxes,xLabel:e.xLabel,yLabel:e.yLabel,yLabelRight:e.yLabelRight,axes:e.axes});ch(o,{props:{...e,axisChrome:c},categories:l,theme:i,size:n,hasTitle:a});let u=uh({props:{...e,axisChrome:c},categories:l,theme:i,size:n,margin:o,hasTitle:a}),d=Math.max(1,n[0]-o.left-o.right),h=Math.max(1,n[1]-o.top-o.bottom),f="streaming"===e.runtimeMode||["bar","swarm","waterfall"].includes(e.chartType),p=e.colorScheme||i.colors.categorical,g=(e.axes?.find(e=>"left"===e.orient)??e.axes?.find(e=>"right"===e.orient))?.extent??e.axisExtent,m={chartType:e.chartType,runtimeMode:f?"streaming":"bounded",windowSize:e.windowSize??e.capacity??200,windowMode:e.windowMode??e.capacityMode??"sliding",arrowOfTime:f?e.arrowOfTime??"right":"right",extentPadding:e.extentPadding??.1,xAccessor:e.xAccessor,yAccessor:e.yAccessor,timeAccessor:f?e.timeAccessor:void 0,valueAccessor:e.valueAccessor,colorAccessor:e.colorAccessor,sizeAccessor:e.sizeAccessor,symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,groupAccessor:e.groupAccessor||(e.lineDataAccessor?"_lineGroup":void 0),categoryAccessor:e.categoryAccessor,lineDataAccessor:e.lineDataAccessor,xExtent:e.xExtent,yExtent:e.yExtent,invertY:e.invertY,axisExtent:e.axisExtent,yAxisExtent:g,sizeRange:e.sizeRange,xScaleType:e.xScaleType,yScaleType:e.yScaleType,scalePadding:e.scalePadding,binSize:e.binSize,normalize:e.normalize,baseline:e.baseline,stackOrder:e.stackOrder,boundsAccessor:e.boundsAccessor,boundsStyle:e.boundsStyle,band:e.band,y0Accessor:e.y0Accessor,areaGroups:e.areaGroups?e.areaGroups instanceof Set?e.areaGroups:new Set(e.areaGroups):void 0,curve:e.curve,gradientFill:er(e.gradientFill),lineGradient:tr(e.lineGradient),semanticLineStops:e.semanticLineStops,openAccessor:e.openAccessor,highAccessor:e.highAccessor,lowAccessor:e.lowAccessor,closeAccessor:e.closeAccessor,candlestickStyle:e.candlestickStyle,lineStyle:e.lineStyle,pointStyle:e.pointStyle,areaStyle:e.areaStyle,barStyle:e.barStyle,waterfallStyle:e.waterfallStyle,swarmStyle:e.swarmStyle,colorScheme:p,themeCategorical:i.colors.categorical,themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging,themeSemantic:w(i),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,layoutSelection:e.layoutSelection,barColors:e.barColors,showValues:e.showValues,heatmapValueFormat:e.heatmapValueFormat,heatmapColorScale:e.heatmapColorScale,heatmapAggregation:e.heatmapAggregation,heatmapXBins:e.heatmapXBins,heatmapYBins:e.heatmapYBins,pointIdAccessor:e.pointIdAccessor,onLayoutError:e.onLayoutError},y=new Ss(m);e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:d,height:h});let x=Mh(e.backgroundGraphics,n,o,y.scales),b=Mh(e.foregroundGraphics,n,o,y.scales),v=mr(e.annotations),k=v?`${e.description||e.title||"Line chart."}${v}`:e.description;if(!y.scales){let r,a=e.annotations?Id({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{},layout:{width:d,height:h},theme:i,idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;t&&(t.evidence=Vs({frameType:"xy",width:n[0],height:n[1],marks:[],title:e.title,description:k,annotations:e.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:o}));let l=x||b||e.annotations?/* @__PURE__ */Eh(Nh,{children:[x,a,b]}):null;return Po.renderToStaticMarkup(hh(l,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?` ${e.className}`:""),title:e.title,description:k,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}let S,A=e._idPrefix,$=Zl({nodes:y.scene,renderMode:e.renderMode,fallback:(t,i)=>Yl(t,i,A,e.hoverRadius??30)}),_=!y.xIsDate||e.xFormat||e.tickFormatTime?e:{...e,xFormat:wn(y.scales.x.domain().map(e=>e.valueOf()))},I=e.showGrid?mh(y.scales,{width:d,height:h},i,A,e.axisExtent,e.axes,_):null,P=$.map(e=>e.element),L=`${nh(e)}-plot-clip`,R=!1!==e.showAxes,T=R?fh(y.scales,{width:d,height:h},_,i,A,o,c,!!u):null,F=R?Th({scales:y.scales,layout:{width:d,height:h},props:e,theme:i,leftAxis:e.axes?.find(e=>"left"===e.orient),rightAxis:e.axes?.find(e=>"right"===e.orient),margin:o,axisChrome:c,hasRenderedLegend:!!u}):null,E=e.annotations?Id({annotations:e.annotations,margin:o,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{x:y.scales.x,y:y.scales.y},layout:{width:d,height:h},theme:i,xAccessor:"string"==typeof e.xAccessor?e.xAccessor:void 0,yAccessor:"string"==typeof e.yAccessor?e.yAccessor:void 0,idPrefix:A,underLayerBands:!0,onRender:e=>{S=e}}):null;t&&(t.evidence=Vs({frameType:"xy",width:n[0],height:n[1],marks:$.map(e=>e.node),title:e.title,description:k,annotations:e.annotations,annotationRender:S,xDomain:Gs(y.scales.x?.domain?.()),yDomain:Gs(y.scales.y?.domain?.()),legendItems:l.length>0?l.length:void 0,margin:o}));let O=e.svgPreRenderers&&y.scales?e.svgPreRenderers.map((e,t)=>{try{/* @__PURE__ */
118
- return Fh(Io.Fragment,{children:e(y.scene,y.scales,{width:d,height:h})},`pre-${t}`)}catch{return null}}).filter(Boolean):null,z=_o(e.annotations??[]).filter(vh),D=z.length>0?Sh(z,`${nh(e)}-under-band`,i.colors.primary||i.colors.annotation||i.colors.text)(y.scene,y.scales,{width:d,height:h}):null,B=/* @__PURE__ */Eh(Nh,{children:[x,O,I,
119
- /* @__PURE__ */Fh("defs",{children:/* @__PURE__ */Fh("clipPath",{id:L,children:/* @__PURE__ */Fh("rect",{x:0,y:0,width:d,height:h})})}),
120
- /* @__PURE__ */Eh("g",{clipPath:`url(#${L})`,children:[D,P]}),T,F,E,b,y.customLayoutOverlays]});return Po.renderToStaticMarkup(hh(B,{width:n[0],height:n[1],className:"stream-xy-frame"+(e.className?` ${e.className}`:""),title:e.title,description:k,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}Ws();import*as zh from"react-dom/server";import{jsx as Dh,jsxs as Bh}from"react/jsx-runtime";function jh(e,t){return t.completed.has(e.id)?"var(--semiotic-success, #2b8a66)":t.blockers.has(e.id)?"var(--semiotic-error, #c64035)":"in-progress"===e.status?"var(--semiotic-warning, #d18a22)":t.armed.has(e.id)?"var(--semiotic-primary, #2474a6)":"var(--semiotic-text-secondary, #75818a)"}function Wh({machine:e,layout:t,runtime:i,downstreamSet:r,selectedSet:n,width:o,height:a,seed:s,reduced:l,onSelectTask:c}){let u=t.tasks.length?t.tasks.reduce((e,t)=>Math.min(e,t.y-t.height/2),1/0):60,d=Math.max(20,u-12),h=Math.max(26,u-6);/* @__PURE__ */
121
- return Bh("svg",{"aria-hidden":"true",width:o,height:a,viewBox:`0 0 ${o} ${a}`,style:{position:"absolute",inset:0,overflow:"visible",pointerEvents:"none"},children:[
122
- /* @__PURE__ */Dh("defs",{children:/* @__PURE__ */Dh("filter",{id:`chain-shadow-${s}`,x:"-20%",y:"-20%",width:"140%",height:"150%",children:/* @__PURE__ */Dh("feDropShadow",{dx:"0",dy:"2",stdDeviation:"2",floodOpacity:"0.2"})})}),e.lanes.map((e,i)=>{let r=t.tasks.filter(e=>e.laneIndex===i)[0]?.x??0;/* @__PURE__ */
123
- return Bh("g",{children:[
124
- /* @__PURE__ */Dh("line",{x1:r,x2:r,y1:h,y2:a-24,stroke:"var(--semiotic-grid, #d7dde0)",strokeWidth:1,strokeDasharray:"3 7"}),
125
- /* @__PURE__ */Dh("text",{x:r,y:d,textAnchor:"middle",fontSize:12,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e})]},e)}),t.routes.map(e=>{let t=i.delivered.has(e.edgeID),n=i.inFlight.has(e.edgeID),o=r.has(e.targetID)||r.has(e.sourceID),a=e.points.map(e=>`${e.x},${e.y}`).join(" ");/* @__PURE__ */
126
- return Dh("polyline",{points:a,fill:"none",stroke:o?"var(--semiotic-selection-color, #e08a1e)":t?"var(--semiotic-success, #2b8a66)":"var(--semiotic-grid, #aeb8bd)",strokeWidth:o?4:n?3:2,strokeOpacity:t||n||o?.95:.48,strokeLinecap:"round",strokeLinejoin:"round"},e.edgeID)}),t.sockets.map(e=>{let t=i.delivered.has(e.edgeID);/* @__PURE__ */
127
- return Bh("g",{children:[
128
- /* @__PURE__ */Dh("circle",{cx:e.x,cy:e.y,r:e.radius+2,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text, #243039)",strokeWidth:1.5}),t&&/* @__PURE__ */Dh("circle",{cx:e.x,cy:e.y,r:e.radius-.5,fill:"var(--semiotic-success, #2b8a66)"})]},e.id)}),e.nodes.map(e=>{let o=t.taskByID.get(e.id);if(!o)return null;let a=i.completed.has(e.id),u=i.blockers.has(e.id),d=i.previewTaskID===e.id,h=n.has(e.id)||d,f=r.has(e.id),p=jh(e,i),g=o.x-o.width/2,m=o.y-o.height/2,y=Math.max(2,o.height*e.progress);/* @__PURE__ */
129
- return Bh("g",{children:[
130
- /* @__PURE__ */Bh("g",{style:{transform:`rotate(${a?76:0}deg)`,transformBox:"fill-box",transformOrigin:"50% 100%",transition:l?"none":"transform 520ms cubic-bezier(.2,.8,.25,1)",filter:"url(#chain-shadow-"+s+")"},children:[
131
- /* @__PURE__ */Dh("rect",{x:g,y:m,width:o.width,height:o.height,rx:e.milestone?12:4,fill:"var(--semiotic-bg, #fff)",stroke:h||f?"var(--semiotic-selection-color, #e08a1e)":p,strokeWidth:h?4:f?3:2}),
132
- /* @__PURE__ */Dh("rect",{x:g+3,y:m+o.height-y+1,width:o.width-6,height:Math.max(0,y-4),rx:2,fill:p,opacity:a?.86:.46})]}),u&&/* @__PURE__ */Bh("g",{opacity:d?.28:1,children:[
133
- /* @__PURE__ */Dh("line",{x1:g-8,x2:g+14,y1:o.y+9,y2:o.y-9,stroke:"var(--semiotic-error, #c64035)",strokeWidth:7,strokeLinecap:"round"}),
134
- /* @__PURE__ */Dh("circle",{cx:g-8,cy:o.y+9,r:3,fill:"var(--semiotic-error, #c64035)"})]}),
135
- /* @__PURE__ */Bh("g",{onPointerDown:()=>c(e.id),style:{cursor:"pointer",pointerEvents:"auto"},children:[
136
- /* @__PURE__ */Dh("rect",{x:g,y:m,width:o.width,height:o.height,fill:"transparent"}),
137
- /* @__PURE__ */Dh("text",{x:o.x,y:o.y-4,textAnchor:"middle",fontSize:10.5,fontWeight:700,fill:"var(--semiotic-text, #243039)",children:e.label.length>24?`${e.label.slice(0,22)}…`:e.label}),
138
- /* @__PURE__ */Bh("text",{x:o.x,y:o.y+12,textAnchor:"middle",fontSize:9.5,fill:"var(--semiotic-text-secondary, #5f6b72)",children:[Math.round(100*e.progress),"% · ",a?"done":u?"blocked":i.armed.has(e.id)?"ready":"waiting"]})]})]},e.id)})]})}function Yh(e,t=0){if(e instanceof Date)return e.getTime();let i=Number(e);return Number.isFinite(i)?i:t}function qh(e){if(null==e.completionTime)return null;let t=Yh(e.completionTime,Number.NaN);return Number.isFinite(t)?t:null}function Xh(e,t,i,r){let n=/* @__PURE__ */new Set;for(let o of e.nodes){let a=e.incoming.get(o.id)??[];(r.has(o.id)||!i.has(o.id)&&a.every(e=>t.has(e.id)))&&n.add(o.id)}return n}function Gh(e,t,i,r){let n=e.nodes.map(qh).filter(e=>null!=e),o=n.length?n.reduce((e,t)=>Math.min(e,t),1/0)-1:0,a="replay"!==t||r?i:o,s=/* @__PURE__ */new Set,l=/* @__PURE__ */new Map;for(let i of e.nodes){let e=qh(i),r=null!=e&&e<=a,n="done"===i.status&&"replay"!==t;(r||n)&&s.add(i.id),i.blockerReason&&!s.has(i.id)&&l.set(i.id,i.blockerReason)}let c=/* @__PURE__ */new Set;if("replay"!==t||r)for(let t of e.edges)s.has(t.sourceID)&&c.add(t.id);return{currentTime:a,playing:!1,completed:s,delivered:c,inFlight:/* @__PURE__ */new Set,armed:Xh(e,c,l,s),blockers:l,previewTaskID:null}}function Vh(e,t){let i=/* @__PURE__ */new Map;for(let t of e)i.set(t.id,/* @__PURE__ */new Set);for(let e of t)i.has(e.source)||i.set(e.source,/* @__PURE__ */new Set),i.has(e.target)||i.set(e.target,/* @__PURE__ */new Set),i.get(e.source).add(e.target);return i}function Hh(e,t,i={}){let r=/* @__PURE__ */new Set,n=[...e.get(t)??[]];for(let t=0;t<n.length;t++){let i=n[t];r.has(i)||(r.add(i),n.push(...e.get(i)??[]))}return i.includeStart&&r.add(t),r}function Uh(e,t,i){return Do(i,e,t)}function Kh(e,t){return e<t?-1:e>t?1:0}function Zh(e,t){return`dependency:${encodeURIComponent(e)}:${encodeURIComponent(t)}`}function Qh(e,t){return`socket:${encodeURIComponent(e)}:${t}`}function Jh(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function ef(e){let t=[],i=/* @__PURE__ */new Map,r=[],n=/* @__PURE__ */new Set;e.data.forEach((o,a)=>{let s=String(Uh(o,a,e.taskIDAccessor)??"");if(!s)return void t.push({code:"duplicate-task-id",message:`Task row ${a} has an empty id.`,taskIDs:[]});if(i.has(s))return void t.push({code:"duplicate-task-id",message:`Task id "${s}" occurs more than once.`,taskIDs:[s]});let l=String(Uh(o,a,e.laneAccessor)??"Unassigned");n.has(l)||(n.add(l),r.push(l));let c=Uh(o,a,e.dependencyAccessor)??[],u=Array.from(new Set(Array.from(c,e=>String(e)))).sort(Kh),d=Uh(o,a,e.blockerAccessor),h=Uh(o,a,e.statusAccessor)??(d?"blocked":"waiting");i.set(s,{id:s,label:String(Uh(o,a,e.labelAccessor)??s),lane:l,laneIndex:0,level:0,index:a,datum:o,dependencyIDs:u,incomingEdgeIDs:[],outgoingEdgeIDs:[],socketIDs:[],start:Uh(o,a,e.startAccessor),end:Uh(o,a,e.endAccessor),progress:Jh(Uh(o,a,e.progressAccessor)),status:h,completionTime:Uh(o,a,e.completionTimeAccessor),blockerReason:d||void 0,milestone:!!Uh(o,a,e.milestoneAccessor)})});let o=e.laneOrder?[...e.laneOrder,...r.filter(t=>!e.laneOrder?.includes(t))]:r,a=new Map(o.map((e,t)=>[e,t]));for(let e of i.values())e.laneIndex=a.get(e.lane)??0;let s=/* @__PURE__ */new Map,l=/* @__PURE__ */new Map;for(let e of i.keys())s.set(e,[]),l.set(e,[]);let c=[],u=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of u)e.dependencyIDs.forEach((r,n)=>{let o=i.get(r);if(!o)return void t.push({code:"missing-dependency",message:`Task "${e.id}" depends on missing task "${r}".`,taskIDs:[e.id,r]});let a={id:Zh(r,e.id),sourceID:r,targetID:e.id,sourceIndex:o.index,targetIndex:e.index,socketID:Qh(e.id,n),socketIndex:n};c.push(a),s.get(e.id)?.push(a),l.get(r)?.push(a),e.incomingEdgeIDs.push(a.id),e.socketIDs.push(a.socketID),o.outgoingEdgeIDs.push(a.id)});for(let e of s.values())e.sort((e,t)=>Kh(e.sourceID,t.sourceID)),e.forEach((e,t)=>{e.socketIndex=t,e.socketID=Qh(e.targetID,t)});for(let e of l.values())e.sort((e,t)=>Kh(e.targetID,t.targetID));for(let e of i.values()){let t=s.get(e.id)??[];e.incomingEdgeIDs=t.map(e=>e.id),e.socketIDs=t.map(e=>e.socketID),e.outgoingEdgeIDs=(l.get(e.id)??[]).map(e=>e.id)}let d=/* @__PURE__ */new Map,h=/* @__PURE__ */new Map;for(let e of i.keys())d.set(e,s.get(e)?.length??0),h.set(e,0);let f=[...i.keys()].filter(e=>0===d.get(e)).sort(Kh),p=0;for(;f.length;){let e=f.shift();p+=1;for(let t of l.get(e)??[]){let i=Math.max(h.get(t.targetID)??0,(h.get(e)??0)+1);h.set(t.targetID,i);let r=(d.get(t.targetID)??0)-1;if(d.set(t.targetID,r),0===r){let e=f.findIndex(e=>e>t.targetID);e<0?f.push(t.targetID):f.splice(e,0,t.targetID)}}}if(p!==i.size){let e=[...i.keys()].filter(e=>(d.get(e)??0)>0).sort(Kh);t.push({code:"cycle",message:`Dependency graph contains a cycle involving: ${e.join(", ")}.`,taskIDs:e})}let g=0,m=[...i.values()].sort((e,t)=>e.index-t.index);for(let e of m)e.level=h.get(e.id)??0,g=Math.max(g,e.level);return{nodes:m,edges:c,byID:i,incoming:s,outgoing:l,lanes:o,maxLevel:g,diagnostics:t,valid:0===t.length}}function tf(e){return e.filter((t,i)=>{let r=e[i-1];return!r||r.x!==t.x||r.y!==t.y})}function rf(e,t,i={}){let r=Math.max(240,t.width),n=Math.max(220,t.height),o=t.paddingX??48,a=t.paddingTop??48,s=t.paddingBottom??44,l=Math.max(1,e.lanes.length),c=Math.max(70,(r-2*o)/l),u=Math.max(1,e.maxLevel+1),d=Math.max(76,(n-a-s)/u),h=Math.min(i.taskWidth??112,Math.max(58,.78*c)),f=Math.min(i.taskHeight??58,.64*d),p=i.socketRadius??5,g=Math.max(1,Math.round(i.gutterCount??3)),m=/* @__PURE__ */new Map;for(let t of e.nodes){let e=`${t.laneIndex}:${t.level}`,i=m.get(e)??[];i.push(t),m.set(e,i)}for(let e of m.values())e.sort((e,t)=>Kh(e.id,t.id));let y=.86*d,x=e=>e<=1?f:Math.max(22,Math.min(f,(y-4*(e-1))/e)),b=e.nodes.map(e=>{let t=m.get(`${e.laneIndex}:${e.level}`)??[e],i=Math.max(0,t.findIndex(t=>t.id===e.id))-(t.length-1)/2,r=x(t.length),n=i*(r+4);return{taskID:e.id,lane:e.lane,laneIndex:e.laneIndex,level:e.level,x:o+c*(e.laneIndex+.5),y:a+d*(e.level+.5)+n,width:h,height:r}}),v=new Map(b.map(e=>[e.taskID,e])),w=[],k=[];e.edges.forEach((t,i)=>{let r=v.get(t.sourceID),n=v.get(t.targetID);if(!r||!n)return;let o=e.incoming.get(t.targetID)??[],a=Math.min(.72*n.width,14*Math.max(1,o.length-1)),s=o.length<=1?n.x:n.x-a/2+a*t.socketIndex/(o.length-1),l=n.y-n.height/2-p-2,c={id:t.socketID,edgeID:t.id,taskID:n.taskID,index:t.socketIndex,x:s,y:l,radius:p};w.push(c);let u={x:r.x,y:r.y+r.height/2+3},d=Math.max(18,l-u.y),h=7*(i%g-(g-1)/2),f=Math.min(l-10,u.y+.48*d+h);k.push({edgeID:t.id,sourceID:t.sourceID,targetID:t.targetID,socketID:t.socketID,points:tf([u,{x:u.x,y:f},{x:s,y:f},{x:s,y:l}])})});let S=new Map(w.map(e=>[e.id,e])),A=new Map(k.map(e=>[e.edgeID,e]));return{tasks:b,sockets:w,routes:k,taskByID:v,socketByID:S,routeByEdgeID:A}}function nf(e,t,i={}){let r=new Set(i.completedTaskIDs??[]),n=[...Hh(Vh(e.nodes,e.edges.map(e=>({source:e.sourceID,target:e.targetID}))),t)].map(t=>e.byID.get(t)).filter(e=>null!=e).filter(e=>!(i.isComplete?i.isComplete(e):r.has(e.id)||"done"===e.status)).sort((e,t)=>e.index-t.index),o=Array.from(new Set(n.map(e=>e.lane)));return{blockerID:t,downstreamTaskCount:n.length,affectedLaneCount:o.length,downstreamTaskIDs:n.map(e=>e.id),affectedLanes:o}}import{jsx as of,jsxs as af}from"react/jsx-runtime";function sf(e){return e.__composite}function lf(e){return Array.isArray(e)?e.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[]}function cf(e,t){return"number"==typeof e&&Number.isFinite(e)?e:t}function uf(e,t,i){let r="string"==typeof i?i:"Tasks are arranged by workstream and dependency depth. Completed tasks deliver their authored prerequisites; task completion remains an explicit data event.",n=[...t.blockers.keys()].map(i=>{let r=nf(e,i,{completedTaskIDs:t.completed});return`${e.byID.get(i)?.label??i} affects ${r.downstreamTaskCount} unfinished tasks across ${r.affectedLaneCount} lanes.`}).join(" ");return n?`${r} ${n}`:`${r} No explicit blockers are active.`}import*as df from"react-dom/server";var hf=e=>Math.max(6,Math.round(2*e/3));function ff(e){let t=e.handles&&"object"==typeof e.handles?e.handles:e.handles?{}:null,i="number"==typeof t?.size&&Number.isFinite(t.size)?t.size:12;return{top:t?.move?Math.ceil(hf(i)/2)+2:0,bottom:e.showExtentLabels?34:20}}function pf(e,t){let i=e.colors.selection??e.colors.primary;return{fill:i,fillOpacity:t,stroke:i,strokeWidth:1}}var gf=(e,t,i)=>Math.min(i,Math.max(t,e)),mf=e=>Number(e.toPrecision(15));function yf({domain:e,scale:t,orientation:i,reverse:r=!1}){if(t){let e=t.range().map(Number),i=t.domain().map(Number),r=Math.min(e[0],e[e.length-1]),n=Math.max(e[0],e[e.length-1])-r,o=Math.min(i[0],i[i.length-1]),a=Math.max(i[0],i[i.length-1]);if(![r,n,o,a].every(Number.isFinite)||n<=0||a<=o)return null;let s=Math.abs(t(o)-r)<=Math.abs(t(a)-r);return{min:o,max:a,toFraction:e=>(t(e)-r)/n,fromFraction:e=>e<=0?s?o:a:e>=1?s?a:o:gf(mf(Number(t.invert(r+e*n))),o,a)}}if(!e)return null;let n=Math.min(Number(e[0]),Number(e[1])),o=Math.max(Number(e[0]),Number(e[1]));if(!Number.isFinite(n)||!Number.isFinite(o)||o<=n)return null;let a=o-n,s="x"===i?!r:r;return{min:n,max:o,toFraction:e=>{let t=(e-n)/a;return s?t:1-t},fromFraction:e=>e<=0?s?n:o:e>=1?s?o:n:mf(s?n+e*a:o-e*a)}}function xf(e,t){if(!e||e.length<2)return null;let i=Number(e[0]),r=Number(e[1]);return Number.isFinite(i)&&Number.isFinite(r)?[gf(Math.min(i,r),t.min,t.max),gf(Math.max(i,r),t.min,t.max)]:null}function bf(e){if(!Number.isFinite(e))return"";let t=Math.round(100*e)/100;return String(Object.is(t,-0)?0:t)}function vf(e,t,i,r=1.2*i,n){return"y"===t?e.length*r:n??Math.max(0,...e.map(e=>Array.from(e).length))*i*.6}function wf(e){let{value:t,track:i,length:r,orientation:n,format:o,fontSize:a,labelWidth:s,showDomainLabels:l}=e,c=e.lineHeight??1.2*a,u=e.gap??6,[d,h]=e.bounds??[0,r],f=(e,t,r=i.toFraction(t))=>{let l=o(t),u=l.split("\n");return{kind:e,value:t,text:l,lines:u,fraction:r,size:vf(u,n,a,c,s)}},p=(e,t)=>{let i=e.fraction*r,n=t;"before"===n&&i-e.size<d?n="after":"after"===n&&i+e.size>h&&(n="before");let o="before"===n?i-e.size:i;return{...e,placement:n,row:0,from:o,to:o+e.size}},g=f("start",t[0]),m=f("end",t[1]),[y,x]=g.fraction<=m.fraction?[g,m]:[m,g],b=p(y,"before"),v=p(x,"after");b.to+u>v.from&&(v.row=1);let w=[b,v];if(!l)return w;let k=w.filter(e=>0===e.row),S=e=>{let t=i.fromFraction(e),n=f(t===i.min?"domain-start":"domain-end",t,e),o=0===e?0:r-n.size;return{...n,placement:0===e?"after":"before",row:0,from:o,to:o+n.size}};return[...[S(0),S(1)].filter(e=>e.from>=d&&e.to<=h&&k.every(t=>e.to+u<=t.from||t.to+u<=e.from)),...w]}function kf(e){return e.__composite}function Sf(e,t){return"number"==typeof e&&Number.isFinite(e)?e:t}function Af(e,t,i,r){return e.replace(/^<svg\b/,`<svg x="${t}" y="${i}" data-semiotic-composite-part="${r}"`)}function Mf(e,t){for(let i of e){let e=i?.[t];if(Array.isArray(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1])return e}}import{jsx as $f,jsxs as _f}from"react/jsx-runtime";var If=e=>!0===e?{}:e&&"object"==typeof e?e:null,Pf=e=>"string"==typeof e?e:void 0;function Lf(e){return t=>{try{let i="function"==typeof e?e(t):void 0;return"string"==typeof i?i:bf(t)}catch{return bf(t)}}}function Rf(e,t,i,r,n,o,a){let s=[.35,.65].map(e=>"x"===a?{x1:t-r/2+r*e,x2:t-r/2+r*e,y1:i-.2*n,y2:i+.2*n}:{x1:t-.2*r,x2:t+.2*r,y1:i-n/2+n*e,y2:i-n/2+n*e});/* @__PURE__ */
139
- return _f("g",{className:"semiotic-brush-handle","data-semiotic-brush-part":e,children:[
140
- /* @__PURE__ */$f("rect",{x:t-r/2+.5,y:i-n/2+.5,width:r-1,height:n-1,rx:o.radius,fill:o.fill,stroke:o.stroke,strokeWidth:1}),s.map((e,t)=>/* @__PURE__ */$f("line",{...e,stroke:o.grip,strokeWidth:1},t))]},e)}function Cf(e){let{theme:t,config:i,direction:r,plot:n,margin:o}=e,a=yf({domain:e.domain,orientation:r});if(!a)return null;let s=If(i.handles),l=xf(e.extent,a)??(s?[a.min,a.max]:null);if(!l)return null;let c=If(i.brushStyle)??{},u=pf(t,.2),d=t.colors.surface??t.colors.background,h="x"===r?n.width:n.height,[f,p]=[a.toFraction(l[0]),a.toFraction(l[1])].sort((e,t)=>e-t),g=(e,t)=>"x"===r?{x:n.x+e*h,y:n.y,width:(t-e)*h,height:n.height}:{x:n.x,y:n.y+e*h,width:n.width,height:(t-e)*h},m=[],y=If(c.mask);if(y)for(let[e,t]of[[0,f],[p,1]])m.push(/* @__PURE__ */$f("rect",{className:"semiotic-brush-mask","data-semiotic-brush-part":"mask",...g(e,t),fill:Pf(y.fill)??d,opacity:Sf(y.opacity,.6)},`mask-${e}`));let x=Sf(c.strokeWidth,1),b=g(f,p);if(m.push(
141
- /* @__PURE__ */$f("rect",{className:"selection","data-semiotic-brush-part":"selection",x:b.x+x/2,y:b.y+x/2,width:Math.max(0,b.width-x),height:Math.max(0,b.height-x),fill:Pf(c.fill)??u.fill,fillOpacity:Sf(c.fillOpacity,.2),stroke:Pf(c.stroke)??u.stroke,strokeWidth:x},"selection")),s){let e=Sf(s.size,12),t=hf(e),i={fill:Pf(s.fill)??d,stroke:Pf(s.stroke)??u.stroke,grip:u.stroke,radius:Sf(s.radius,3)};for(let[o,a]of[["start",f],["end",p]])m.push("x"===r?Rf(o,n.x+a*h,n.y+n.height/2,t,2*e,i,"x"):Rf(o,n.x+n.width/2,n.y+a*h,2*e,t,i,"y"));if(s.move){let o=(f+p)/2;m.push("x"===r?Rf("move",n.x+o*h,n.y,2*e,t,i,"x"):Rf("move",n.x,n.y+o*h,t,2*e,i,"y"))}}if(i.showExtentLabels){let s=wf({value:l,track:a,length:h,orientation:r,format:Lf(i.extentLabelFormat??e.axisFormat),fontSize:11,bounds:"x"===r?[-o.left,n.width+o.right]:[-o.top,n.height+o.bottom]}),c=13.2*Math.max(1,...s.map(e=>e.lines.length));for(let e of s){let i="before"===e.placement,o="x"===r?n.x+e.fraction*h:n.x+n.width+4,a="x"===r?n.y+n.height+4+e.row*c:n.y+e.from;m.push(
142
- /* @__PURE__ */$f("text",{className:"semiotic-brush-label","data-semiotic-brush-label":e.kind,x:o,y:a+10.45,fill:t.colors.textSecondary,fontFamily:t.typography.fontFamily,fontSize:11,textAnchor:"x"===r&&i?"end":"start",children:e.lines.map((e,t)=>/* @__PURE__ */$f("tspan",{x:o,dy:0===t?0:13.2,children:e},t))},`label-${e.kind}`))}}/* @__PURE__ */
143
- return $f("g",{className:"semiotic-minimap-brush",children:m})}import{jsx as Tf,jsxs as Nf}from"react/jsx-runtime";import{jsx as Ff,jsxs as Ef}from"react/jsx-runtime";var Of={top:4,bottom:4,left:4,right:4};function zf(e,t,i,r,n){return{__composite:{data:e,colorBy:t,colorScheme:i,common:r,rest:n}}}function Df(e){return Array.isArray(e)?e.filter(e=>null!=e&&"object"==typeof e&&!Array.isArray(e)):[]}function Bf(e,t){return Math.max(1,Math.floor(Sf(e,t)))}var jf={frameType:"xy",buildProps:zf,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:n,common:o,rest:a}=kf(e),[s,l]=o.size??[600,400],c=a.minimap&&"object"==typeof a.minimap?a.minimap:{},u=Sf(c.height,60),d=o.margin,h=c.margin&&"object"==typeof c.margin?c.margin:{},f=ff(c),p={top:Sf(h.top,f.top),right:Sf(h.right,Sf(d?.right,20)),bottom:Sf(h.bottom,f.bottom),left:Sf(h.left,Sf(d?.left,40))},g=u+p.top+p.bottom,m=a.frameProps&&"object"==typeof a.frameProps?a.frameProps:{},y={...a,xAccessor:a.xAccessor||"x",yAccessor:a.yAccessor||"y"},x="y"===c.brushDirection?"y":"x",b={...o,size:[s,l],xExtent:m.xExtent??("x"===x?a.brushExtent:void 0)??o.xExtent,yExtent:m.yExtent??("y"===x?a.brushExtent:void 0)??a.yExtent??o.yExtent,_idPrefix:`${String(o._idPrefix??"minimap")}-detail`},v=go.buildProps(i,r,n,b,y);Object.assign(v,m);let w={...o,size:[s,g],margin:p,title:void 0,description:`${String(o.description??o.title??"Chart")} overview minimap`,showAxes:c.showAxes??!1,showLegend:!1,showGrid:!1,accessibleTable:!1,background:c.background,xExtent:void 0,yExtent:a.yExtent??o.yExtent,_idPrefix:`${String(o._idPrefix??"minimap")}-overview`};delete w.lineStyle,delete w.pointStyle;let k={...y,fillArea:!1,lineWidth:1,showPoints:!1,directLabel:!1,forecast:void 0,anomaly:void 0,band:void 0},S=go.buildProps(i,r,n,w,k);S.chartType=a.fillArea?"area":"line","function"==typeof c.lineStyle&&(S.lineStyle=c.lineStyle);let A={},_={},I=Oh(v,A),P=Oh(S,_),L=!0===a.renderBefore,R=L?0:l,C=[Af(I,0,L?g:0,"detail"),Af(P,0,R,"overview")].join(""),T=l+g,N=M(o.theme),F=$(N),E="string"==typeof o.title?o.title:void 0,O="string"==typeof o.description?o.description:E||"Chart with overview minimap",z=nh(o),D=E?`${z}-title`:void 0,B=`${z}-description`,j=Array.isArray(a.brushExtent)&&a.brushExtent.length>=2?[Number(a.brushExtent[0]),Number(a.brushExtent[1])]:null,W="x"===x?_.evidence?.xDomain:_.evidence?.yDomain,Y=W?Cf({theme:N,config:c,direction:x,domain:W,extent:j&&j.every(Number.isFinite)?j:null,plot:{x:p.left,y:R+p.top,width:Math.max(0,s-p.left-p.right),height:u},margin:p,axisFormat:"x"===x?o.xFormat:o.yFormat}):null,q=df.renderToStaticMarkup(
144
- /* @__PURE__ */Nf("svg",{xmlns:"http://www.w3.org/2000/svg",className:"minimap-chart",width:s,height:T,role:"img","aria-labelledby":[D,B].filter(Boolean).join(" "),style:{fontFamily:F.fontFamily},children:[E&&/* @__PURE__ */Tf("title",{id:D,children:E}),
145
- /* @__PURE__ */Tf("desc",{id:B,children:O}),
146
- /* @__PURE__ */Tf("g",{dangerouslySetInnerHTML:{__html:C}}),Y]}));if(t){let e=[A.evidence,_.evidence];t.evidence=Ys({frameType:"xy",width:s,height:T,parts:e,title:E,description:O,xDomain:Mf(e,"xDomain"),yDomain:Mf(e,"yDomain")})}return q}};function Wf(e,t){return String("function"==typeof t?t(e):e[t])}function Yf(e,t,i,r){if(!t)return{categories:[],color:()=>Ai};let n=Array.from(new Set(e.map(e=>Wf(e,t)))),o="string"==typeof t?t:"__semioticSplomColor",a=Ci("function"==typeof t?e.map(e=>({...e,[o]:Wf(e,t)})):e,o,i??r.colors.categorical);return{categories:n,color:e=>Li(e,t,a)}}function qf(e){let{data:t,field:i,label:r,cellSize:n,bins:o,diagonal:a,colorBy:s,color:l,x:c,y:u}=e;if("label"===a)return{visibleBars:0,svg:$o.renderToStaticMarkup(
147
- /* @__PURE__ */Ff("svg",{x:c,y:u,width:n,height:n,"data-semiotic-composite-part":`diagonal-${i}`,children:/* @__PURE__ */Ff("text",{x:n/2,y:n/2,textAnchor:"middle",dominantBaseline:"middle",fontSize:12,fontWeight:"bold",fill:"#333",children:r})}))};let d=t.map(e=>Number(e[i])).filter(Number.isFinite),h=d.length?Math.min(...d):0,f=((d.length?Math.max(...d):0)-h)/o||1,p=Array.from({length:o},()=>/* @__PURE__ */new Map);for(let e of t){let t=Number(e[i]);if(!Number.isFinite(t))continue;let r=Math.max(0,Math.min(o-1,Math.floor((t-h)/f))),n=s?Wf(e,s):"__all",a=p[r];a.set(n,[...a.get(n)??[],e])}let g=p.map(e=>Array.from(e.values()).reduce((e,t)=>e+t.length,0)),m=Math.max(1,...g),y=0,x=p.flatMap((e,t)=>{let i=0;return Array.from(e.entries()).flatMap(([e,r])=>{if(0===r.length)return[];y+=1;let a=r.length/m*(n-24),c=i;return i+=a,/* @__PURE__ */Ff("rect",{x:t/o*n,y:n-c-a,width:Math.max(n/o-1,1),height:a,fill:s?l(r[0]):Ai,opacity:.6},`${t}-${e}`)})});return{visibleBars:y,svg:$o.renderToStaticMarkup(
148
- /* @__PURE__ */Ef("svg",{x:c,y:u,width:n,height:n,"data-semiotic-composite-part":`diagonal-${i}`,children:[
149
- /* @__PURE__ */Ff("text",{x:n/2,y:14,textAnchor:"middle",fontSize:11,fontWeight:"bold",fill:"#333",children:r}),x]}))}}var Xf={frameType:"physics",layout:{primarySize:{width:920,height:620}},buildProps:zf,renderStatic:function(e,t){let{data:i,common:r,rest:n}=sf(e),o=lf(i),[a,s]=r.size??[920,620],l="string"==typeof r.title?r.title:"Dependency chain reaction",c=ef({data:o,taskIDAccessor:n.taskIDAccessor,labelAccessor:n.labelAccessor,laneAccessor:n.laneAccessor,dependencyAccessor:n.dependencyAccessor,startAccessor:n.startAccessor,endAccessor:n.endAccessor,progressAccessor:n.progressAccessor,statusAccessor:n.statusAccessor,completionTimeAccessor:n.completionTimeAccessor,blockerAccessor:n.blockerAccessor,milestoneAccessor:n.milestoneAccessor}),u=M(r.theme),d=$(u),h=nh(r),f=`${h}-title`,p=`${h}-description`;if(!c.valid){let e=c.diagnostics.map(e=>e.message).join(" "),i=zh.renderToStaticMarkup(
150
- /* @__PURE__ */af("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:s,role:"img","aria-labelledby":`${f} ${p}`,style:{fontFamily:d.fontFamily},children:[
151
- /* @__PURE__ */of("title",{id:f,children:l}),
152
- /* @__PURE__ */of("desc",{id:p,children:e}),
153
- /* @__PURE__ */of("rect",{width:a,height:s,fill:d.background}),
154
- /* @__PURE__ */of("text",{x:24,y:36,fontSize:16,fontWeight:700,fill:d.text,children:l}),c.diagnostics.map((e,t)=>/* @__PURE__ */of("text",{x:24,y:72+22*t,fontSize:12,fill:u.colors.error,children:e.message},`${e.code}-${t}`))]}));return t&&(t.evidence=Ys({frameType:"physics",width:a,height:s,parts:[],title:l,description:e,nodeCount:c.nodes.length,edgeCount:c.edges.length,extraWarnings:["INVALID_DEPENDENCY_GRAPH"]})),i}let g=rf(c,{width:a,height:s}),m=Gh(c,"snapshot",Yh(n.currentTime,1/0),!0),y=Array.isArray(n.selectedTaskIDs)?n.selectedTaskIDs.map(String):[],x=new Set(y),b=y[0]??null,v=b&&"none"!==n.insight?nf(c,b,{completedTaskIDs:m.completed}):null,w=new Set(v?.downstreamTaskIDs??[]),k=cf(n.seed,31),S=uf(c,m,r.description),A=zh.renderToStaticMarkup(
155
- /* @__PURE__ */of(Wh,{machine:c,layout:g,runtime:m,downstreamSet:w,selectedSet:x,width:a,height:s,seed:k,reduced:!0,onSelectTask:()=>{}})),_=void 0===r.theme?{}:yn(u),I=zh.renderToStaticMarkup(
156
- /* @__PURE__ */af("svg",{xmlns:"http://www.w3.org/2000/svg",className:"chain-reaction-chart",width:a,height:s,role:"img","aria-labelledby":`${f} ${p}`,style:{..._,fontFamily:d.fontFamily},children:[
157
- /* @__PURE__ */of("title",{id:f,children:l}),
158
- /* @__PURE__ */of("desc",{id:p,children:S}),
159
- /* @__PURE__ */of("rect",{width:a,height:s,fill:d.background}),
160
- /* @__PURE__ */of("text",{x:a/2,y:22,textAnchor:"middle",fontSize:d.titleFontSize,fontFamily:d.titleFontFamily,fontWeight:d.titleFontWeight,fill:d.text,children:l}),
161
- /* @__PURE__ */of("g",{dangerouslySetInnerHTML:{__html:A}})]}));return t&&(t.evidence=Ys({frameType:"physics",width:a,height:s,parts:[],additionalMarkCountByType:{task:c.nodes.length,dependency:c.edges.length},title:l,description:S,categories:c.lanes,nodeCount:c.nodes.length,edgeCount:c.edges.length})),I}},Gf={LineChart:go,BumpChart:ro,AreaChart:yo,DifferenceChart:xo,StackedAreaChart:bo,Scatterplot:Jr,BubbleChart:rn,Heatmap:Mo,QuadrantChart:wo,MultiAxisLineChart:co,WaterfallChart:uo,CandlestickChart:vo,ConnectedScatterplot:ko,ScatterplotMatrix:{frameType:"xy",buildProps:zf,renderStatic:function(e,t){let{data:i,colorBy:r,colorScheme:n,common:o,rest:a}=kf(e),s=Df(i),l=Array.isArray(a.fields)?a.fields.filter(e=>"string"==typeof e):[],c=a.fieldLabels&&"object"==typeof a.fieldLabels?a.fieldLabels:{},u=Bf(a.cellSize,150),d=Math.max(0,Sf(a.cellGap,4)),h=Math.max(0,Sf(a.pointRadius,2)),f=Math.max(0,Math.min(1,Sf(a.pointOpacity,.5))),p=Bf(a.histogramBins,20),g="string"==typeof a.diagonal?a.diagonal:"histogram",m=40+l.length*u+l.length*d,y=l.length*u+40+l.length*d,x=M(o.theme),b=$(x),v=Yf(s,r,n,x),w=a.showLegend??!!r,k="string"==typeof o.title?o.title:void 0,S="string"==typeof o.description?o.description:`Scatterplot matrix comparing ${l.length} fields`,A=k?28:0,_=w?v.categories:[],I=e=>Math.max(72,30+7*e.length),P=0,L=0,R=_.map(e=>{let t=I(e);P>0&&P+t>m&&(L+=1,P=0);let i={label:e,x:P,y:24*L};return P+=t,i}),C=_.length?24*(L+1)+4:0,T=A+C,N=T+y,F=[],E=[],O=0;l.forEach((e,t)=>{l.forEach((i,n)=>{let l=40+d+n*(u+d),m=T+t*(u+d);if(t===n){let t=qf({data:s,field:e,label:Ri(c,e)??e,cellSize:u,bins:p,diagonal:g,colorBy:r,color:v.color,x:l,y:m});return O+=t.visibleBars,void E.push(t.svg)}let y={},x=Oh({chartType:"scatter",data:s,size:[u,u],xAccessor:i,yAccessor:e,pointStyle:Xi(e=>({r:h,opacity:f,fill:v.color(e)}),a.styleRules,Di(i,e)),margin:Of,showAxes:!1,showGrid:!1,enableHover:!1,accessibleTable:!1,description:`${Ri(c,i)??i} versus ${Ri(c,e)??e} scatterplot`,theme:o.theme,_idPrefix:`${String(o._idPrefix??"splom")}-${t}-${n}`},y);F.push(y.evidence),E.push(Af(x,l,m,`cell-${e}-${i}`))})});let z=nh(o),D=k?`${z}-title`:void 0,B=`${z}-description`,j=$o.renderToStaticMarkup(
162
- /* @__PURE__ */Ef("svg",{xmlns:"http://www.w3.org/2000/svg",className:"scatterplot-matrix",width:m,height:N,role:"img","aria-labelledby":[D,B].filter(Boolean).join(" "),style:{fontFamily:b.fontFamily},children:[k&&/* @__PURE__ */Ff("title",{id:D,children:k}),
163
- /* @__PURE__ */Ff("desc",{id:B,children:S}),
164
- /* @__PURE__ */Ff("rect",{width:m,height:N,fill:b.background}),k&&/* @__PURE__ */Ff("text",{x:0,y:18,fontSize:14,fontWeight:600,fill:b.text,children:k}),R.map(e=>{let t=s.find(t=>r&&Wf(t,r)===e.label),i=t?v.color(t):Ai;/* @__PURE__ */
165
- return Ef("g",{transform:`translate(${e.x},${A+e.y})`,children:[
166
- /* @__PURE__ */Ff("circle",{cx:5,cy:8,r:5,fill:i}),
167
- /* @__PURE__ */Ff("text",{x:14,y:12,fontSize:11,fill:b.text,children:e.label})]},e.label)}),l.map((e,t)=>{let i=T+t*(u+d)+u/2;/* @__PURE__ */
168
- return Ff("text",{x:20,y:i,transform:`rotate(-90 20 ${i})`,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:Ri(c,e)??e},`row-${e}`)}),l.map((e,t)=>/* @__PURE__ */Ff("text",{x:40+d+t*(u+d)+u/2,y:T+l.length*(u+d)+20,textAnchor:"middle",dominantBaseline:"middle",fontSize:11,fontWeight:"bold",fill:b.text,children:Ri(c,e)??e},`column-${e}`)),
169
- /* @__PURE__ */Ff("g",{dangerouslySetInnerHTML:{__html:E.join("")}})]}));return t&&(t.evidence=Ys({frameType:"xy",width:m,height:N,parts:F,additionalMarkCountByType:O>0?{histogram:O}:void 0,title:k,description:S,categories:v.categories.length?v.categories:void 0,legendItems:_.length||void 0})),j}},MinimapChart:jf},Vf=class e{constructor(){this._count=0,this._mean=0,this._m2=0,this._min=1/0,this._max=-1/0}push(e){if(!Number.isFinite(e))return;this._count+=1;let t=e-this._mean;this._mean+=t/this._count;let i=e-this._mean;this._m2+=t*i,e<this._min&&(this._min=e),e>this._max&&(this._max=e)}merge(e){if(0===e._count)return;if(0===this._count)return this._count=e._count,this._mean=e._mean,this._m2=e._m2,this._min=e._min,void(this._max=e._max);let t=this._count+e._count,i=e._mean-this._mean;this._mean+=i*e._count/t,this._m2+=e._m2+i*i*this._count*e._count/t,this._count=t,e._min<this._min&&(this._min=e._min),e._max>this._max&&(this._max=e._max)}clear(){this._count=0,this._mean=0,this._m2=0,this._min=1/0,this._max=-1/0}clone(){let t=new e;return t.merge(this),t}get count(){return this._count}get mean(){return this._mean}get sum(){return this._mean*this._count}get variance(){return this._count<2?0:this._m2/this._count}get stddev(){return Math.sqrt(this.variance)}get sampleVariance(){return this._count<2?0:this._m2/(this._count-1)}get sampleStddev(){return Math.sqrt(this.sampleVariance)}get min(){return this._min}get max(){return this._max}};function Hf(e){let t=xn(e);return t^=t>>>16,t=Math.imul(t,2146121005),t^=t>>>15,t=Math.imul(t,2221713035),t^=t>>>16,t>>>0}var Uf=class e{constructor(e=10){let t=Math.max(4,Math.min(16,Math.floor(e)));this.p=t,this.m=1<<t,this.registers=new Uint8Array(this.m),this.alpha=.7213/(1+1.079/this.m),this.harmonicSum=this.m,this.zeros=this.m}add(e){let t=Hf(String(e)),i=t>>>32-this.p,r=Math.min(Math.clz32(t<<this.p),32-this.p)+1;this.updateRegister(i,r)}updateRegister(e,t){let i=this.registers[e];t<=i||(this.registers[e]=t,this.harmonicSum+=2**-t-2**-i,0===i&&this.zeros--)}merge(e){if(e.m===this.m)for(let t=0;t<this.m;t++)this.updateRegister(t,e.registers[t])}clone(){let t=new e(this.p);return t.registers.set(this.registers),t.harmonicSum=this.harmonicSum,t.zeros=this.zeros,t}count(){let e=this.alpha*this.m*this.m/this.harmonicSum;return e<=2.5*this.m&&this.zeros>0?Math.round(this.m*Math.log(this.m/this.zeros)):Math.round(e)}},Kf=class e{constructor(e=100){this.centroids=[],this.total=0,this.pending=0,this.compression=Math.max(20,e)}push(e){Number.isFinite(e)&&(this.centroids.push({mean:e,weight:1}),this.total+=1,this.pending++,this.pending>=2*this.compression&&this.compress())}merge(e){if(0===e.total)return;let t=0===this.total,i=e.centroids.length;for(let t=0;t<i;t++)this.centroids.push({...e.centroids[t]});this.total+=e.total,this.pending=t&&this.compression===e.compression?e.pending:this.pending+i,t||this.compress()}clone(){let t=new e(this.compression);return t.merge(this),t}quantile(e){if(0===this.total||Number.isNaN(e))return Number.NaN;let t=Math.min(1,Math.max(0,e));this.compress();let i=t*this.total,r=this.centroids[0].weight/2;if(i<=r)return this.centroids[0].mean;for(let e=1;e<this.centroids.length;e++){let t=this.centroids[e-1],n=this.centroids[e],o=(t.weight+n.weight)/2,a=r+o;if(i<=a){let e=(i-r)/o;return t.mean+(n.mean-t.mean)*e}r=a}return this.centroids[this.centroids.length-1].mean}get count(){return this.total}compress(){if(0===this.pending||(this.pending=0,this.centroids.length<=1))return;this.centroids.sort((e,t)=>e.mean-t.mean);let e=0,t=0,i=this.total,r=this.compression;for(let n=1;n<this.centroids.length;n++){let o=this.centroids[e],a=this.centroids[n],s=(t+o.weight/2)/i,l=4*i*s*(1-s)/r;if(o.weight+a.weight<=Math.max(1,l)){let e=o.weight+a.weight;o.mean=(o.mean*o.weight+a.mean*a.weight)/e,o.weight=e}else t+=o.weight,this.centroids[++e]=a}this.centroids.length=e+1}};function Zf(e){let t=Math.round(1e3*e)/10;return`p${String(t).replace(".","_")}`}function Qf(e,t,i){let r=e.length;for(e.push(t);r>0;){let n=r-1>>>1;if(i(e[n],t)<=0)break;e[r]=e[n],r=n}e[r]=t}function Jf(e,t){let i=e[0],r=e.pop();if(e.length>0){let i=0;for(;2*i+1<e.length;){let n=2*i+1;if(n+1<e.length&&t(e[n+1],e[n])<0&&n++,t(r,e[n])<=0)break;e[i]=e[n],i=n}e[i]=r}return i}var ep=(e,t)=>e-t,tp=class{constructor(e,t){this.stats=new Vf,this.digest=e?new Kf:null,this.hll=t?new Uf:null}push(e,t){this.stats.push(e),this.digest?.push(e),this.hll&&this.hll.add(t??e)}merge(e){this.stats.merge(e.stats),this.digest?.merge(e.digest),this.hll?.merge(e.hll)}},ip=class{constructor(e){this.windows=/* @__PURE__ */new Map,this.starts=[],this.sessions=[],this.latest=-1/0,this.type=e.window??"tumbling",this.size=e.size;let t=e.hop??e.size;this.hop=t>0&&t<=e.size?t:e.size,this.gap=e.gap??e.size,this.retain=null!=e.retain&&e.retain>0?e.retain:1/0,this.percentiles=e.percentiles??[],this.wantDistinct=!0===e.distinct}newBucket(){return new tp(this.percentiles.length>0,this.wantDistinct)}push(e,t,i){!Number.isFinite(e)||!Number.isFinite(t)||(e>this.latest&&(this.latest=e),"session"===this.type?this.pushSession(e,t,i):this.pushFixed(e,t,i),this.prune())}pushFixed(e,t,i){if("tumbling"===this.type||this.hop>=this.size){let r=Math.floor(e/this.size)*this.size;return void this.bump(r,t,i)}let r=this.hop,n=Math.floor(e/r);for(let o=Math.floor((e-this.size)/r)+1;o<=n;o++)this.bump(o*r,t,i)}bump(e,t,i){let r=this.windows.get(e);if(!r){if(this.windows.size>=this.retain&&e<this.starts[0])return;r=this.newBucket(),this.windows.set(e,r),this.retain!==1/0&&Qf(this.starts,e,ep)}r.push(t,i)}pushSession(e,t,i){let r=e-this.gap,n=e+this.gap,o=0,a=this.sessions.length,s=this.sessions[a-1];if(!s||e>=s.end)o=a,s&&s.end>=r&&s.start<=n&&o--;else for(;o<a;){let e=o+a>>>1;this.sessions[e].end<r?o=e+1:a=e}let l=this.sessions[o];if(!l||l.start>n){let r=this.newBucket();return r.push(t,i),void this.sessions.splice(o,0,{start:e,end:e,bucket:r})}l.bucket.push(t,i),l.start=Math.min(l.start,e),l.end=Math.max(l.end,e);let c=o+1;for(;c<this.sessions.length&&this.sessions[c].start<=n;){let e=this.sessions[c++];l.bucket.merge(e.bucket),l.end=Math.max(l.end,e.end)}c>o+1&&this.sessions.splice(o+1,c-o-1)}prune(){if(this.retain!==1/0){if("session"===this.type)return void(this.sessions.length>this.retain&&this.sessions.splice(0,this.sessions.length-this.retain));for(;this.windows.size>this.retain;)this.windows.delete(Jf(this.starts,ep))}}emit(){if("session"===this.type)return this.sessions.map(e=>{let t=this.latest-e.end<this.gap;return this.row(e.start,e.end,e.bucket,t)});let e=[];for(let[t,i]of this.windows){let r=t+this.size;e.push(this.row(t,r,i,this.latest<r))}return e.sort((e,t)=>e.start-t.start),e}row(e,t,i,r){let n=i.stats,o={start:e,end:t,count:n.count,mean:n.mean,sum:n.sum,min:n.min,max:n.max,stddev:n.stddev,partial:r};if(i.digest){let e={};for(let t of this.percentiles)e[Zf(t)]=i.digest.quantile(t);o.percentiles=e}return i.hll&&(o.distinct=i.hll.count()),o}get windowCount(){return"session"===this.type?this.sessions.length:this.windows.size}get watermark(){return this.latest}clear(){this.windows.clear(),this.starts=[],this.sessions=[],this.latest=-1/0}};function rp(e,t){switch(t){case"distinct":return e.distinct??0;case"p50":case"p95":case"p99":return e.percentiles?.[t]??Number.NaN;default:return e[t]??e.mean}}function np(e,t,i,r=1){if("none"===t)return null;if("minmax"===t)return[e.min,e.max];let n=rp(e,i),o=e.stddev*r;return[n-o,n+o]}var op={ms:1,s:1e3,m:6e4,h:36e5,d:864e5},ap=/(\d+(?:\.\d+)?)(ms|s|m|h|d)/g;function sp(e){if("number"==typeof e)return Number.isFinite(e)&&e>0?e:null;if("string"!=typeof e)return null;let t=e.trim();if(""===t)return null;ap.lastIndex=0;let i,r=0,n=0;for(;null!==(i=ap.exec(t));){let e=parseFloat(i[1]),t=op[i[2]];if(null==t||!Number.isFinite(e))return null;r+=e*t,n+=i[0].length}return n!==t.length?null:r>0?r:null}var lp="time",cp="value",up="__aggLower",dp="__aggUpper",hp="__aggPartial",fp="count",pp="__aggStart",gp="__aggEnd";function mp(e){let t=e.window??"tumbling",i=sp("session"===t?e.gap??e.size:e.size);if(null==i)return null;let r=null!=e.hop?sp(e.hop):void 0,n=null!=e.gap?sp(e.gap):void 0;return new ip({window:t,size:i,hop:r??void 0,gap:n??void 0,retain:e.retain,percentiles:e.percentiles,distinct:e.distinct})}function yp(e,t){let i=t.stat??"mean",r=t.band??"none",n=t.sigma??1;return e.emit().map(e=>{let t={[lp]:(e.start+e.end)/2,[cp]:rp(e,i),[fp]:e.count,[hp]:e.partial,[pp]:e.start,[gp]:e.end},o=np(e,r,i,n);return o&&(t[up]=o[0],t[dp]=o[1]),t})}function xp(e){return"none"!==(e.band??"none")}var bp="__aggSeries",vp=class{constructor(e,t){this.config=e,this.seriesAccessor=t,this.groups=/* @__PURE__ */new Map}push(e,t,i){let r=Kt(e,t,"time"),n=Ut(e,i,"value");if(null==r||null==n)return;let o=null==this.seriesAccessor?"":String("function"==typeof this.seriesAccessor?this.seriesAccessor(e):e[this.seriesAccessor]),a=this.groups.get(o);if(!a){if(a=mp(this.config),!a)return;this.groups.set(o,a)}a.push(+r,n)}emit(e){let t=[];for(let[i,r]of this.groups)for(let n of yp(r,e))t.push(null==this.seriesAccessor?n:{...n,[bp]:i});return t}clear(){this.groups.clear()}};function wp(e,t,i){return e??i??Math.max(t?.length??0,200)}function kp(e,t){let i=Array.isArray(e)?ei(e):[],r=t.aggregate;if(!r)return i;let n=new vp(r,t.seriesAccessor);for(let e of i)n.push(e,t.timeAccessor,t.valueAccessor);return n.emit(r)}function Sp(e){let t=e.timeAccessor||"time",i=e.valueAccessor||"value";return{timeAccessor:e=>Kt(e,t,"time")??NaN,valueAccessor:e=>Ut(e,i,"value")??NaN}}function Ap(e,t,i){return{runtimeMode:"streaming",windowMode:i.windowMode??i.capacityMode??"sliding",windowSize:wp(i.windowSize,e,i.capacity),arrowOfTime:i.arrowOfTime??"right",...Sp(i),xExtent:i.timeExtent??t.xExtent,yExtent:i.valueExtent??t.yExtent,extentPadding:i.extentPadding??t.extentPadding,tickFormatTime:i.tickFormatTime,tickFormatValue:i.tickFormatValue}}var Mp={RealtimeLineChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=kp(e,n),a=n.aggregate,s=n.aggregate?{timeAccessor:"time",valueAccessor:"value"}:Sp(n),l=Xi(()=>({stroke:"#007bff",strokeWidth:2}),n.styleRules,Di(s.timeAccessor,s.valueAccessor));return{chartType:"line",data:o,...r,...Ap(o,r,n),...s,groupAccessor:a&&null!=n.seriesAccessor?bp:n.seriesAccessor,...a&&{windowMode:"growing",windowSize:Math.max(1,a.retain??Math.max(o.length,600)),band:xp(a)?{y0Accessor:up,y1Accessor:dp,perSeries:null!=n.seriesAccessor}:void 0},lineStyle:r.lineStyle||(e=>({...l(e),...ur(n),...null!=n.strokeDasharray&&{strokeDasharray:n.strokeDasharray},...null!=n.cursor&&{cursor:n.cursor}}))}}},RealtimeHistogram:/* @__PURE__ */Object.assign({},mo,{buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?ei(e):[];return{...mo.buildProps(o,t,i,r,n),...Ap(o,r,n)}}}),TemporalHistogram:mo,RealtimeSwarmChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?ei(e):[],a=tn(o,r,n,"discovery"),s=Xi(void 0,n.styleRules,Di(n.timeAccessor??"time",n.valueAccessor??"value"));return{chartType:"swarm",data:o,...r,...Ap(o,r,n),categoryAccessor:n.categoryAccessor,colorScheme:a||i||r.colorScheme,barColors:a,yScaleType:n.yScaleType,swarmStyle:{...ur(n),fill:n.fill,radius:n.radius,cursor:n.cursor},pointStyle:e=>({...s(e),..."function"==typeof n.pointStyle?n.pointStyle(e):{},..."function"==typeof r.pointStyle?r.pointStyle(e):r.pointStyle})}}},RealtimeWaterfallChart:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?ei(e):[],a=uo.buildProps(o,t,i,r,{...n,xAccessor:n.timeAccessor||n.xAccessor||"time",yAccessor:n.valueAccessor||n.yAccessor||"value"});return{...a,...Ap(o,r,n),waterfallStyle:{...a.waterfallStyle,cursor:n.cursor}}}},RealtimeHeatmap:{frameType:"xy",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?ei(e):[];return{...Mo.buildProps(o,t,i,r,{...n,xAccessor:n.timeAccessor||n.xAccessor||"time",yAccessor:n.valueAccessor||n.yAccessor||"value",heatmapAggregation:n.aggregation??"count",cellBorderWidth:0}),...Ap(o,r,n),categoryAccessor:n.categoryAccessor}}}};import{useMemo as $p,useCallback as _p,useRef as Ip}from"react";var Pp={RdBu:gi,PiYG:mi,PRGn:yi,BrBG:xi,RdYlBu:bi,RdYlGn:vi,Spectral:wi},Lp="__likert_neutral_neg",Rp="__likert_neutral_pos";function Cp(e,t){if("function"==typeof e)return e;let i=e||t;return e=>e[i]}function Tp(e,t){if(e<=0)return[];if(t&&Object.prototype.hasOwnProperty.call(Pp,t)){let i=Pp[t];if(1===e)return[i(.5)];let r=[];for(let t=0;t<e;t++)r.push(i(t/(e-1)));return r}let i=["#da1e28","#ff8389","#ffb3b8"],r=["#a6c8ff","#4589ff","#0043ce"],n="#a8a8a8";if(1===e)return[n];let o=e%2!=0,a=Math.floor(e/2),s=[];for(let e=0;e<a;e++)s.push(i[Math.min(Math.floor(e*i.length/a),i.length-1)]);o&&s.push(n);for(let e=0;e<a;e++)s.push(r[Math.min(Math.floor(e*r.length/a),r.length-1)]);return s}function Np(e,t,i,r,n,o,a={}){let s=/* @__PURE__ */new Map,l=new Set(t);for(let a of e){let e=i(a);s.has(e)||s.set(e,/* @__PURE__ */new Map);let c=s.get(e);if(r){let e=r(a);if(null==e||!Number.isFinite(e))continue;if(!Number.isInteger(e)){"production"!==process.env.NODE_ENV&&console.warn("[LikertChart] Ignoring non-integer Likert score:",e);continue}let i=e-1;if(i<0||i>=t.length)continue;let n=t[i];c.set(n,(c.get(n)||0)+1)}else if(n&&o){let e=n(a),t=o(a);if(!l.has(e))continue;c.set(e,(c.get(e)||0)+(Number.isFinite(t)?t:0))}}let c=[];for(let[e,i]of s){let r=0;for(let e of t)r+=i.get(e)||0;if(0!==r)for(let n=0;n<t.length;n++){let o=t[n],s=i.get(o)||0,l={};a.category&&(l[a.category]=e),a.level&&(l[a.level]=o),a.count&&(l[a.count]=s),a.score&&(l[a.score]=n+1),c.push({...l,__likertCategory:e,__likertLevel:o,__likertLevelLabel:o,__likertCount:s,__likertPct:s/r*100,__likertLevelIndex:n})}}return c}function Fp(e,t){let i=t.length,r=i%2!=0,n=Math.floor(i/2),o=[];for(let t of e){let e=t.__likertLevelIndex;if(r&&e===n){let e=t.__likertPct/2;o.push({...t,__likertLevel:Lp,__likertPct:-e}),o.push({...t,__likertLevel:Rp,__likertPct:e})}else e<n?o.push({...t,__likertPct:-t.__likertPct}):o.push(t)}return o}function Ep(e,t){let i=t.length,r=i%2!=0,n=Math.floor(i/2),o=/* @__PURE__ */new Map;for(let t of e){let e=o.get(t.__likertCategory)||[];e.push(t),o.set(t.__likertCategory,e)}let a=[];for(let[,e]of o){let t,o,s=/* @__PURE__ */new Map;for(let i of e)i.__likertLevel===Lp?t=i:i.__likertLevel===Rp?o=i:s.set(i.__likertLevelIndex,i);r&&t&&a.push(t);for(let e=n-1;e>=0;e--){let t=s.get(e);t&&a.push(t)}r&&o&&a.push(o);for(let e=r?n+1:n;e<i;e++){let t=s.get(e);t&&a.push(t)}}return a}import{jsx as Op,jsxs as zp}from"react/jsx-runtime";function Dp(e,t,i){let r=Math.max(16,.3*t);if(null==i||i<=0)return r;let n=Pc(e,r),o=2*i*.8;return n<=o?r:r*o/n}function Bp({value:e,min:t,max:i,radius:r,innerRadius:n,showScaleLabels:o,label:a}){let s=Dp(e,r,n),l=.7*s+11;/* @__PURE__ */
170
- return zp("g",{textAnchor:"middle",children:[
171
- /* @__PURE__ */Op("text",{y:0,dominantBaseline:"central",fontSize:s,fontWeight:700,fill:"var(--semiotic-text, #333)",children:e}),o&&/* @__PURE__ */zp("text",{y:l,fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:[t," – ",i]}),null!=a&&""!==a&&/* @__PURE__ */Op("text",{y:l+(o?14:0),fontSize:11,fill:"var(--semiotic-text-secondary, #666)",children:a})]})}function jp({centerContent:e,centerLabel:t,value:i,min:r,max:n,radius:o,innerRadius:a,showScaleLabels:s,valueFormat:l,compact:c}){if(null!=e){let s="function"==typeof e?e(i,r,n):e;return"string"==typeof s||"number"==typeof s?Bp({value:String(s),min:r,max:n,radius:o,innerRadius:a,showScaleLabels:!1,label:t}):s}return c?null:Bp({value:l?l(i):String(Math.round(i)),min:r,max:n,radius:o,innerRadius:a,showScaleLabels:s,label:t})}function Wp(e){return Math.max(0,Math.min(1,e))}function Yp(e){let t=e.trim();if(t.startsWith("#")){let e=t.slice(1);if(3===e.length&&(e=e.split("").map(e=>e+e).join("")),6===e.length&&/^[0-9a-f]{6}$/i.test(e))return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}let i=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);if(i){let e=[Number(i[1]),Number(i[2]),Number(i[3])];if(e.every(Number.isFinite))return e}return null}function qp(e,t,i){let r=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(i)}`}function Xp(e,t,i){let r=e.filter(e=>Number.isFinite(e.offset)).map(e=>({offset:Wp(e.offset),color:e.color??i,opacity:null==e.opacity?1:Wp(e.opacity)})).sort((e,t)=>e.offset-t.offset);if(0===r.length)return"#999999";let n=e=>{if(1===e.opacity)return e.color;let t=Yp(e.color);return t?`rgba(${t[0]},${t[1]},${t[2]},${e.opacity})`:e.color};if(1===r.length)return n(r[0]);let o=Wp(t);if(o<=r[0].offset)return n(r[0]);if(o>=r[r.length-1].offset)return n(r[r.length-1]);for(let e=0;e<r.length-1;e++){let t=r[e],i=r[e+1];if(o<t.offset||o>i.offset)continue;let a=i.offset-t.offset,s=a<=0?0:(o-t.offset)/a,l=Yp(t.color),c=Yp(i.color);if(!l||!c)return n(s<.5?t:i);let[u,d,h]=l,[f,p,g]=c,m=u+(f-u)*s,y=d+(p-d)*s,x=h+(g-h)*s,b=t.opacity+(i.opacity-t.opacity)*s;return 1===b?qp(m,y,x):`rgba(${Math.round(m)},${Math.round(y)},${Math.round(x)},${b})`}return n(r[r.length-1])}function Gp(e,t,i){return null==i?`${e}-${t}`:`${e}-${t}-${i}`}function Vp(e){let{min:t,max:i,value:r,thresholds:n,fillColor:o,backgroundColor:a,fillZones:s,showScaleLabels:l,gradientFill:c,gradientSteps:u=240}=e,d=Math.max(t,Math.min(i,r)),h=i-t||1,f=(d-t)/h,p=n&&n.length>0?[...n].sort((e,t)=>e.value-t.value):[{value:i,color:o||"#007bff"}];p=p.map(e=>({...e,value:Math.max(t,Math.min(i,e.value))})),p[p.length-1].value<i&&p.push({value:i,color:p[p.length-1].color});let g=!!c&&c.stops.length>=2,m=[],y=/* @__PURE__ */new Map,x=[];if(g){let e=s?f:1,t=Gp("bg",0);if(m.push({category:t,value:1,_zone:"Track",_isFill:!1,_pctStart:0,_pct:1,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0}),y.set(t,{fill:a,opacity:.4}),e>0){let t=Math.max(1,Math.floor(u)),i=Math.max(1,Math.min(t,Math.round(e*t))),r=[];for(let t=0;t<i;t++){let n=e*(t+.5)/i;r.push(Xp(c.stops,n,o||p[0]?.color||"#007bff"))}let n=Gp("fill",0);m.push({category:n,value:e,_zone:"Gradient",_isFill:!0,_pctStart:0,_pct:e,_roundedEnds:{start:!0,end:!0},_nonInteractive:!0,_gradientBand:{colors:r}}),y.set(n,{fill:r[0]||a})}}else{let e=t;for(let n=0;n<p.length;n++){let o=p[n],l=(o.value-e)/h,c=(e-t)/h,u=(o.value-t)/h,g=s?Math.min(f,u):u,x=Math.max(0,g-c),b=s?Math.max(0,l-x):0;if(x>0){let a=Gp("fill",n);m.push({category:a,value:x,_zone:o.label||`Zone ${n+1}`,_isFill:!0,__gaugeAccessibleDatum:{category:o.label||`Zone ${n+1}`,value:r,min:t,max:i,segmentStart:e,segmentEnd:t+g*h,filled:!0}}),y.set(a,{fill:o.color})}if(b>0){let s=Gp("bg",n);m.push({category:s,value:b,_zone:o.label||`Zone ${n+1}`,_isFill:!1,__gaugeAccessibleDatum:{category:o.label||`Zone ${n+1}`,value:r,min:t,max:i,segmentStart:Math.max(e,d),segmentEnd:o.value,filled:!1}}),y.set(s,{fill:a,opacity:.4})}e=o.value}}if(l&&n&&n.length>0)for(let e of n)e.value>t&&e.value<i&&x.push({type:"gauge-label",value:e.value,label:e.label||String(e.value)});return{gaugeData:m,pieceStyle:(e,t)=>{let i=t||e.category;return y.get(i)||{fill:a}},gaugeAnnotations:x}}function Hp(e=240){let t=e*Math.PI/180,i=360-e,r=180+i/2,n=r*Math.PI/180;return{sweepRad:t,gapDeg:i,startAngleDeg:r,startAngleRad:n,offsetRad:-Math.PI/2+n}}function Up(e=240){let{sweepRad:t,offsetRad:i}=Hp(e),r=[[Math.cos(i),Math.sin(i)],[Math.cos(i+t),Math.sin(i+t)],[0,0]];for(let e=0;e<2*Math.PI;e+=Math.PI/2)((e-i)%(2*Math.PI)+2*Math.PI)%(2*Math.PI)<=t+.001&&r.push([Math.cos(e),Math.sin(e)]);let n=r.map(e=>e[0]),o=r.map(e=>e[1]),[a,s]=yr(n),[l,c]=yr(o);return{minX:a,maxX:s,minY:l,maxY:c,width:s-a,height:c-l,cx:(a+s)/2,cy:(l+c)/2}}import{Fragment as Kp,jsx as Zp,jsxs as Qp}from"react/jsx-runtime";function Jp(e){return er(e)}function eg(e,t,i,r,n,o){let a=M(r.theme).colors.categorical,s=i??r.colorScheme,l=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],c="string"==typeof t?t:"__ssrColorBy",u="function"==typeof t?l.map(e=>({...e,__ssrColorBy:t(e)})):l,d=t?Ci(u,c,s??a):void 0,h=Fi("string"==typeof n.color?n.color:void 0,a,s,void 0,
172
- /* @__PURE__ */new Map),f=o??zi(n.valueAccessor??"value"),p=n.styleRules,g=r.pieceStyle;return(e,i)=>{let r={fill:t&&d?Li(e,t,d):h};return p?.length&&Object.assign(r,qi(e,p,{value:f(e,i),category:i})),"function"==typeof g?Object.assign(r,g(e,i)||{}):g&&"object"==typeof g&&Object.assign(r,g),void 0!==n.stroke&&(r.stroke=n.stroke),void 0!==n.strokeWidth&&(r.strokeWidth=n.strokeWidth),void 0!==n.opacity&&(r.opacity=n.opacity),r}}function tg(e,t,i,r,n,o="median",a=.8){let s=zi(n.valueAccessor??"value"),l=eg(e,t,i,r,n,e=>"number"==typeof e[o]?e[o]:s(e));return(e,t)=>{let i=l(e,t);return void 0===i.fillOpacity&&(i.fillOpacity=a),void 0===i.stroke&&(i.stroke=i.fill),i}}function ig(e,t,i,r,n){return tg(e,t,i,r,n,"median",.6)}function rg(e,t,i,r,n){let o=eg(e,t,i,r,n),a="number"==typeof n.dotRadius?n.dotRadius:5;return(e,t)=>({r:a,fillOpacity:.8,...o(e,t)})}function ng(e,t,i,r,n){let o=eg(e,t,i,r,n),a=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],s=n.sizeBy,l=Array.isArray(n.sizeRange)?n.sizeRange:[3,8],c=s?a.map(e=>"function"==typeof s?s(e):Number(e[s])).filter(Number.isFinite):[],u=c.length?yr(c):void 0,d="number"==typeof n.pointRadius?n.pointRadius:4,h="number"==typeof n.pointOpacity?n.pointOpacity:.7;return(e,t)=>({r:s?Ni(e,s,l,u):d,fillOpacity:h,...o(e,t)})}var og={BarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=dr(r.annotations,n.regression);return{chartType:"bar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??!1,colorAccessor:t,colorScheme:i,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,...o&&{annotations:o},gradientFill:Jp(r.gradientFill),pieceStyle:eg(e,t,i,r,n)}}},StackedBarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.stackBy;return{chartType:"bar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.stackBy,colorAccessor:o,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},normalize:n.normalize,oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Jp(r.gradientFill),pieceStyle:eg(e,o,i,r,n),showLegend:r.showLegend??!!o}}},GroupedBarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.groupBy;return{chartType:"clusterbar",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",groupBy:n.groupBy,colorAccessor:o,colorScheme:i,projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??!1,barPadding:n.barPadding,...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Jp(r.gradientFill),pieceStyle:eg(e,o,i,r,n),showLegend:r.showLegend??!!o}}},SwarmPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"swarm",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},barPadding:n.categoryPadding??20,colorAccessor:t,...n.symbolBy&&{symbolAccessor:n.symbolBy},...n.symbolMap&&{symbolMap:n.symbolMap},colorScheme:i,...r,sizeRange:n.sizeRange||[3,8],pieceStyle:ng(e,t,i,r,n),showLegend:r.showLegend??!!t})},BoxPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"boxplot",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"horizontal"===n.orientation?"horizontal":"vertical",...n.valueExtent&&{rExtent:n.valueExtent},colorAccessor:t,colorScheme:i,...null!=n.showOutliers&&{showOutliers:n.showOutliers},...null!=n.outlierRadius&&{outlierRadius:n.outlierRadius},...r,summaryStyle:tg(e,t,i,r,n)})},Histogram:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],a=n.valueAccessor||"value",s=o.map(e=>Number("function"==typeof a?a(e):e[a])).filter(Number.isFinite),l=s.length?[Math.min(...s),Math.max(...s)]:void 0;return{chartType:"histogram",data:e,oAccessor:n.categoryAccessor||(e=>null==e.category?"All":String(e.category)),rAccessor:a,projection:"horizontal",bins:n.bins??25,normalize:n.relative??!1,colorAccessor:t,colorScheme:i,barPadding:n.categoryPadding??20,...n.valueExtent?{rExtent:n.valueExtent}:l?{rExtent:l}:{},...r,summaryStyle:tg(e,t,i,r,n,"count")}}},ViolinPlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"violin",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,projection:"horizontal"===n.orientation?"horizontal":"vertical",bins:n.bins??25,showIQR:n.showIQR??!0,barPadding:n.categoryPadding??20,colorScheme:i,...r,summaryStyle:ig(e,t,i,r,n),showLegend:r.showLegend??!!t,...n.valueExtent&&{rExtent:n.valueExtent}})},RidgelinePlot:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"ridgeline",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...n.valueExtent&&{rExtent:n.valueExtent},bins:n.bins??20,amplitude:n.amplitude??1.5,barPadding:n.categoryPadding??5,oSort:n.oSort??!1,...r,summaryStyle:tg(e,t,i,r,n,"median",.5),showLegend:r.showLegend??!!t})},DotPlot:{frameType:"ordinal",layout:{modeDefaults:{showGrid:!0}},buildProps:(e,t,i,r,n)=>{let o=dr(r.annotations,n.regression);return{chartType:"point",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",colorAccessor:t,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...n.valueExtent&&{rExtent:n.valueExtent},oSort:n.sort??"auto",barPadding:n.categoryPadding??10,...r,...o&&{annotations:o},pieceStyle:rg(e,t,i,r,n),showGrid:r.showGrid??!0,showLegend:r.showLegend??!!t}}},PieChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.categoryAccessor,a=zi(n.valueAccessor??"value");return{chartType:"pie",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",colorAccessor:o,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...r,pieceStyle:eg(e,o,i,r,n,e=>{let t=a(e);return null==t?void 0:Math.abs(t)}),showLegend:r.showLegend??!!o}}},DonutChart:{frameType:"ordinal",layout:{primarySize:{width:400,height:400}},buildProps:(e,t,i,r,n)=>{let o=t||n.categoryAccessor,a=zi(n.valueAccessor??"value");return{chartType:"donut",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",projection:"radial",margin:r.margin??{top:50,right:40,bottom:60,left:70},innerRadius:n.innerRadius??60,colorAccessor:o,colorScheme:i,...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...null!=n.startAngle&&{startAngle:n.startAngle},...r,pieceStyle:eg(e,o,i,r,n,e=>{let t=a(e);return null==t?void 0:Math.abs(t)})}}},GaugeChart:{frameType:"ordinal",layout:{primarySize:{width:300,height:250}},renderOverlay:function(e,{theme:t}){let i=e.__gauge;if(!i)return null;let r=Math.max(i.gMin,Math.min(i.gMax,i.value??i.gMin)),n=i.gMax===i.gMin?0:(r-i.gMin)/(i.gMax-i.gMin),o=(i.startAngleDeg+n*i.sweep-90)*Math.PI/180,a=i.needleColor||t.colors.text,s=i.showScaleLabels?(i.thresholds||[]).filter(e=>e.value>i.gMin&&e.value<i.gMax):[];/* @__PURE__ */
173
- return Qp(Kp,{children:[i.showNeedle&&/* @__PURE__ */Qp(Kp,{children:[
174
- /* @__PURE__ */Zp("line",{x1:i.centerX,y1:i.centerY,x2:i.centerX+i.needleLength*Math.cos(o),y2:i.centerY+i.needleLength*Math.sin(o),stroke:a,strokeWidth:2.5,strokeLinecap:"round"}),
175
- /* @__PURE__ */Zp("circle",{cx:i.centerX,cy:i.centerY,r:4,fill:a})]}),null!=i.contextValue&&/* @__PURE__ */Zp("text",{x:i.centerX,y:i.contextValueY,textAnchor:"middle",dominantBaseline:"middle",fontSize:i.valueFontSize,fontWeight:700,fill:a,children:i.contextValue}),s.map((e,r)=>{let n=i.gMax===i.gMin?0:(e.value-i.gMin)/(i.gMax-i.gMin),o=(i.startAngleDeg+n*i.sweep-90)*Math.PI/180,a=i.innerRadius-1,s=i.radius+1,l=i.radius+10,c=((o+Math.PI/2)/(2*Math.PI)*12+12)%12,u=c>=11||c<1?"middle":c<5?"start":c<7?"middle":"end",d=c>=11||c<1?"auto":c<5?"middle":c<7?"hanging":"middle";/* @__PURE__ */
176
- return Qp("g",{children:[
177
- /* @__PURE__ */Zp("line",{x1:i.centerX+Math.cos(o)*a,y1:i.centerY+Math.sin(o)*a,x2:i.centerX+Math.cos(o)*s,y2:i.centerY+Math.sin(o)*s,stroke:t.colors.border,strokeWidth:2,strokeLinecap:"round"}),
178
- /* @__PURE__ */Zp("text",{x:i.centerX+Math.cos(o)*l,y:i.centerY+Math.sin(o)*l,textAnchor:u,dominantBaseline:d,fill:t.colors.textSecondary,fontSize:10,children:e.label||String(e.value)})]},`gauge-label-${r}`)})]})},buildProps:(e,t,i,r,n)=>{let o=n.min??0,a=n.max??100,s=n.sweep??240,l=n.arcWidth??.3,c=!1!==n.showNeedle,u=!1!==n.fillZones,{startAngleDeg:d}=Hp(s),h=r.__resolvedMode??n.mode,f="context"===h||"sparkline"===h,p=n.showScaleLabels??!f,g=n.thresholds,m=tr(r.gradientFill),y=Vp({min:o,max:a,value:n.value,thresholds:g,fillColor:n.color,backgroundColor:n.backgroundColor||"#e0e0e0",fillZones:u,showScaleLabels:p,gradientFill:m}),x=n.styleRules,[b,v]=r.size||[300,250],w=Up(s),k=Math.min(10,Math.max(1,Math.min(b,v)/12)),S=Math.max(4,Math.min((b-2*k)/w.width,(v-2*k)/w.height)-2),A=Math.max(0,Math.min(S-1.5,S*(1-l))),M=b/2-w.cx*S,$=v/2-w.cy*S,_=2*(S+4),I=Math.max(o,Math.min(a,n.value??o)),P="function"==typeof n.valueFormat?n.valueFormat(I):String(Math.round(I)),L=n.centerContent??r.centerContent,R=jp({centerContent:L,centerLabel:"string"==typeof n.centerLabel?n.centerLabel:void 0,value:I,min:o,max:a,radius:S,innerRadius:A,showScaleLabels:p,valueFormat:"function"==typeof n.valueFormat?n.valueFormat:void 0,compact:f});return{chartType:"donut",data:y.gaugeData,oAccessor:"category",rAccessor:"value",projection:"radial",innerRadius:A,sweepAngle:s,startAngle:d,oSort:!1,pieceStyle:Oi((e,t)=>{let i={...y.pieceStyle(e,t)};return x?.length&&Object.assign(i,qi(e,x,{value:"number"==typeof e.value?e.value:void 0,category:t??(null==e.category?void 0:String(e.category))})),i},ur(n)),...null!=n.cornerRadius&&{cornerRadius:n.cornerRadius},...r,size:[b,v],margin:{top:$-_/2,bottom:v-$-_/2,left:M-_/2,right:b-M-_/2},...null!=R&&{centerContent:R},showAxes:!1,annotations:[...Array.isArray(r.annotations)?r.annotations:[],...y.gaugeAnnotations],__gauge:{gMin:o,gMax:a,sweep:s,arcWidth:l,value:I,startAngleDeg:d,thresholds:g,centerX:M,centerY:$,radius:S,innerRadius:A,showScaleLabels:p,needleLength:A>20?A-8:S-1,showNeedle:c,needleColor:n.needleColor,..."context"===h&&null==L&&{contextValue:P,contextValueY:$-.2*A,valueFontSize:Math.max(12,Math.min(22,.28*S))}}}}},FunnelChart:{frameType:"ordinal",layout:{margin:(e,t)=>"vertical"===e.orientation?{top:t.title?60:40,right:20,bottom:60,left:60}:{top:t.title?40:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o="vertical"===n.orientation,a=t||n.categoryAccessor;return{chartType:o?"bar-funnel":"funnel",data:e,oAccessor:n.stepAccessor||"step",rAccessor:n.valueAccessor||"value",colorAccessor:a,categoryAccessor:n.categoryAccessor,projection:o?"vertical":"horizontal",connectorAccessor:n.connectorAccessor,connectorStyle:n.connectorStyle,...!o&&null!=n.connectorOpacity&&{connectorOpacity:n.connectorOpacity},barPadding:o?40:0,colorScheme:i,...r,showAxes:o&&!1!==r.showAxes,showGrid:o,pieceStyle:eg(e,a,i,r,n),showLabels:n.showLabels??!0}}},RadarChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=n.seriesAccessor||t||"__radar",a=t||("__radar"===o?void 0:o),s=rg(e,a,i,r,{...n,dotRadius:n.pointRadius??4});return{chartType:"point",projection:"radial",data:e,oAccessor:n.categoryAccessor||"attribute",rAccessor:n.valueAccessor||"value",colorAccessor:a,colorScheme:i,connectorAccessor:o,connectorStyle:e=>{let t=s(e),i="string"==typeof t.fill?t.fill:void 0;return{fill:i,fillOpacity:.15,stroke:i,strokeWidth:2,opacity:.7}},pieceStyle:s,rExtent:n.valueExtent||[0],oLabel:"",...r,...n.categoryFormat&&{oFormat:n.categoryFormat},showLegend:r.showLegend??!!a}}},SwimlaneChart:{frameType:"ordinal",buildProps:(e,t,i,r,n)=>{let o=t||n.subcategoryAccessor;return{chartType:"swimlane",data:e,oAccessor:n.categoryAccessor||"category",rAccessor:n.valueAccessor||"value",stackBy:n.subcategoryAccessor,colorAccessor:o,categoryAccessor:n.categoryAccessor,subcategoryAccessor:n.subcategoryAccessor,colorScheme:i,projection:"vertical"===n.orientation?"vertical":"horizontal",...null!=n.trackFill&&{trackFill:n.trackFill},...n.valueExtent&&{rExtent:n.valueExtent},...null!=n.roundedTop&&{roundedTop:n.roundedTop},...r,gradientFill:Jp(r.gradientFill),pieceStyle:eg(e,o,i,r,n),showLegend:r.showLegend??!!o,barPadding:n.barPadding??40}}},LikertChart:{frameType:"ordinal",layout:{margin:(e,t)=>({...t.marginDefaults,left:"vertical"===e.orientation?t.marginDefaults.left:Math.max(100,t.marginDefaults.left)})},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.levels)&&n.levels.length>=2?n.levels:["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],a="vertical"!==n.orientation,s=Np(Array.isArray(e)?e.filter(e=>!!e&&"object"==typeof e):[],o,Cp(n.categoryAccessor,"question"),n.levelAccessor?null:Cp(n.valueAccessor,"score"),n.levelAccessor?Cp(n.levelAccessor,"level"):null,n.levelAccessor?Cp(n.countAccessor,"count"):null,{category:"string"==typeof n.categoryAccessor?n.categoryAccessor:void 0,level:"string"==typeof n.levelAccessor?n.levelAccessor:void 0,count:"string"==typeof n.countAccessor?n.countAccessor:void 0,score:n.levelAccessor||"string"!=typeof n.valueAccessor?void 0:n.valueAccessor});a&&(s=Ep(Fp(s,o),o));let l=M(r.theme).colors.diverging,c=Array.isArray(i)&&i.length>=o.length?i:Tp(o.length,l),u=new Map(o.map((e,t)=>[e,c[t]||"#888"])),d=o.length%2&&u.get(o[Math.floor(o.length/2)])||"#888",h="function"==typeof n.valueFormat?n.valueFormat:e=>`${Math.abs(Number(e)).toFixed(0)}%`,f=P(!1===r.showLegend?void 0:{legendGroups:[{label:"",items:o.map(e=>({label:e})),styleFn:e=>({fill:u.get(e.label)||"#888"})}]},r.legend),p=n.styleRules,g=r.pieceStyle;return{chartType:"bar",data:s,oAccessor:"__likertCategory",rAccessor:"__likertPct",stackBy:"__likertLevel",normalize:!1,projection:a?"horizontal":"vertical",barPadding:n.barPadding,showGrid:r.showGrid,oLabel:n.categoryLabel,rLabel:n.valueLabel||(a?void 0:"Percentage"),rFormat:h,...n.categoryFormat&&{oFormat:n.categoryFormat},...n.valueExtent&&{rExtent:n.valueExtent},...r,pieceStyle:Oi((e,t)=>{let i=e.__likertLevel||e.data?.__likertLevel,r=e.__likertLevelLabel||e.data?.__likertLevelLabel,n=e.__likertPct??e.data?.__likertPct,o={fill:i===Lp||i===Rp?d:u.get(String(r||i))||"#888"};return p?.length&&Object.assign(o,qi(e,p,{value:"number"==typeof n?n:void 0,category:t??(null==r?void 0:String(r))})),"function"==typeof g?Object.assign(o,g(e,t)||{}):g&&"object"==typeof g&&Object.assign(o,g),o},ur(n)),showLegend:r.showLegend??!0,legendPosition:r.legendPosition||"right",...f&&{legend:f},__legendIncludesAutomatic:!0}}}};import{interpolateRgb as ag}from"d3-interpolate";var sg=864e5,lg=e=>{let t=e.config,{plot:i}=e.dimensions;if(i.width<=0||i.height<=0)return{nodes:[]};let r=e=>{let i="function"==typeof t.dateAccessor?t.dateAccessor(e):e[t.dateAccessor];return i instanceof Date?i:new Date(i)},n=e=>{let i="function"==typeof t.valueAccessor?t.valueAccessor(e):e[t.valueAccessor];return Number(i)},o=/* @__PURE__ */new Map,a=null;for(let t of e.data){let e=r(t);if(!isFinite(e.getTime()))continue;null==a&&(a=e.getUTCFullYear());let i=cg(e),s=n(t);o.set(i,(o.get(i)??0)+(Number.isFinite(s)?s:0))}let s=t.year??a??/* @__PURE__ */(new Date).getUTCFullYear(),l=1/0,c=-1/0;for(let e of o.values())e<l&&(l=e),e>c&&(c=e);l===1/0&&(l=0,c=0);let[u,d]=t.colorRamp??[e.theme.semantic.surface??"#ebedf0",e.theme.semantic.primary??"#216e39"],h=e=>{if(c===l)return u;let t=(e-l)/(c-l);return ag(u,d)(t)},f=t.gutter??2,p=t.labelInset??0,g=i.width-p,m=i.height,y=Math.min((g-53*f)/54,(m-6*f)/7);if(y<=0)return{nodes:[]};let x=new Date(Date.UTC(s,0,1)),b=x.getUTCDay(),v=new Date(x.getTime()-b*sg),w=[];for(let e=0;e<54;e++)for(let t=0;t<7;t++){let r=new Date(v.getTime()+(7*e+t)*sg);if(r.getUTCFullYear()!==s)continue;let n=cg(r),a=o.get(n),l=null==a?u:h(a);w.push({type:"rect",x:i.x+p+e*(y+f),y:i.y+t*(y+f),w:y,h:y,style:{fill:l,stroke:"none"},datum:{date:r,value:a??0}})}return{nodes:w}};function cg(e){return`${e.getUTCFullYear()}-${ug(e.getUTCMonth()+1)}-${ug(e.getUTCDate())}`}function ug(e){return e<10?`0${e}`:String(e)}import*as dg from"react";import{scaleLinear as hg}from"d3-scale";import{interpolateLab as fg}from"d3-interpolate";function pg(e,t){if(!t)return!0;let i=Array.isArray(t)?t:[t],r=e;for(let e of i)if(null!=e.value&&String(r[e.field])!==String(e.value))return!1;return!0}function gg(e,t={}){let i=t.baseOpacity??1;return t.highlight||t.predicate?!pg(e,t.highlight)||t.predicate&&!t.predicate(e)?t.dimOpacity??.16:Math.min(1,i+(t.brighten??0)):i}function mg(e){if(0===e.length)return 0;let t=0;for(let i of e)t+=i;return t/e.length}import{jsx as yg,jsxs as xg}from"react/jsx-runtime";function bg(e){let t=e.fontSize??12;return null!=e.maxWidth&&e.text.length*t*.56>e.maxWidth?null:/* @__PURE__ */yg("text",{className:e.className,x:e.x,y:e.y,textAnchor:e.anchor??"middle",dominantBaseline:e.baseline??"middle",fontSize:t,fontWeight:e.fontWeight,fill:e.color,style:{pointerEvents:"none"},children:e.text},e.keyId)}var vg=e=>{let t=e.config,{plot:i}=e.dimensions,r=t.fields??[];if(r.length<2||i.width<=0||i.height<=0)return{nodes:[]};if(0===e.data.length)return{nodes:[]};let n=/* @__PURE__ */Object.create(null);for(let i of r){let r=t.domains&&Object.prototype.hasOwnProperty.call(t.domains,i)?t.domains[i]:void 0;if(Array.isArray(r)&&r.length>=2&&"number"==typeof r[0]&&Number.isFinite(r[0])&&"number"==typeof r[1]&&Number.isFinite(r[1])){n[i]=[r[0],r[1]];continue}let o=1/0,a=-1/0;for(let t of e.data){let e=Number(t[i]);Number.isFinite(e)&&(e<o&&(o=e),e>a&&(a=e))}if(Number.isFinite(o)&&Number.isFinite(a))if(o===a){let e=Math.max(.01*Math.abs(o),.5);n[i]=[o-e,a+e]}else n[i]=[o,a];else n[i]=[0,1]}let o=!1!==t.showAxes,a=o?t.axisLabelPadding??24:8,s=o?18:8,l=r.map(e=>hg().domain(n[e]).range([i.y+i.height-s,i.y+a])),c=r.map((e,t)=>1===r.length?i.x+i.width/2:i.x+t/(r.length-1)*i.width),u=t.colorBy?"function"==typeof t.colorBy?t.colorBy:e=>String(e[t.colorBy]??""):null,d=t.opacity??.45,h=t.strokeWidth??1.25,f=e.theme.semantic.primary??"#3b6cb1",p=t.dimmedOpacity??.08,g=t.highlightFn,m=[],y=[];for(let i of e.data){let n=u?e.resolveColor(String(u(i))):f,o=!g||g(i),a=gg(i,{predicate:g,baseOpacity:d,dimOpacity:p,brighten:.4}),s=o?y:m;for(let e=0;e<r.length-1;e++){let t=Number(i[r[e]]),u=Number(i[r[e+1]]);if(!Number.isFinite(t)||!Number.isFinite(u))continue;let d={type:"connector",x1:c[e],y1:l[e](t),x2:c[e+1],y2:l[e+1](u),style:{stroke:n,strokeWidth:g&&o?h+.75:h,opacity:a,fill:"none"},datum:i};s.push(d)}if(t.showPoints)for(let e=0;e<r.length;e++){let t=Number(i[r[e]]);if(!Number.isFinite(t))continue;let o={type:"point",x:c[e],y:l[e](t),r:2.5,style:{fill:n,stroke:"none",opacity:Math.min(1,a+.3)},datum:i};s.push(o)}}let x=null;if(o){let o=`var(--semiotic-border, ${e.theme.semantic.border??"#aaa"})`,u=`var(--semiotic-text, ${e.theme.semantic.text??"currentColor"})`,d=`var(--semiotic-text-secondary, ${e.theme.semantic.textSecondary??"#888"})`,h=i.y+a,f=i.y+i.height-s,p=[];for(let e=0;e<r.length;e++){let s=r[e],g=c[e],m=t.tickFormat&&Object.prototype.hasOwnProperty.call(t.tickFormat,s)?t.tickFormat[s]:void 0,y="function"==typeof m?m:e=>e.toLocaleString();p.push(dg.createElement("line",{key:`pc-axis-line-${e}`,x1:g,x2:g,y1:h,y2:f,stroke:o,strokeWidth:1})),p.push(bg({keyId:`pc-axis-label-${e}`,text:s,x:g,y:i.y+a-8,anchor:"middle",baseline:"auto",fontSize:12,fontWeight:600,color:u}));let[x,b]=n[s],v=5;for(let t=0;t<v;t++){let i=x+(b-x)*t/(v-1),r=l[e](i);p.push(dg.createElement("line",{key:`pc-tick-${e}-${t}`,x1:g-3,x2:g+3,y1:r,y2:r,stroke:o,strokeWidth:1}),bg({keyId:`pc-ticktext-${e}-${t}`,text:y(i),x:g+6,y:r+3,anchor:"start",baseline:"auto",fontSize:10,color:d}))}}x=dg.createElement(dg.Fragment,null,...p)}return{nodes:m.concat(y),overlays:x}},wg={frameType:"xy",buildProps:(e,t,i,r,n)=>({chartType:"custom",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",colorAccessor:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r,showAxes:n.frameProps?.showAxes??n.showAxes??!1,showLegend:r.showLegend??!!t})},kg={frameType:"ordinal",buildProps:(e,t,i,r,n)=>({chartType:"custom",data:e,oAccessor:n.categoryAccessor||n.oAccessor||"category",rAccessor:n.valueAccessor||n.rAccessor||"value",projection:n.projection||"vertical",colorAccessor:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r,showAxes:n.frameProps?.showAxes??n.showAxes??!1})},Sg={frameType:"network",layout:{margin:{top:40,right:40,bottom:40,left:40}},buildProps:(e,t,i,r,n)=>({chartType:"force",nodes:n.nodes||e||[],edges:n.edges||[],nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor||"id",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",valueAccessor:n.valueAccessor||"value",colorBy:t,colorScheme:i,customNetworkLayout:n.layout||n.customNetworkLayout,layoutConfig:n.layoutConfig,...r})},Ag={frameType:"ordinal",buildProps:(e,t,i,r,n)=>({...kg.buildProps(e,t,i,r,n),customLayout:vg,showAxes:!1})},Mg={frameType:"xy",buildProps:(e,t,i,r,n)=>({...wg.buildProps(e,t,i,r,n),customLayout:lg,showAxes:!1})};import*as $g from"react";function _g(e){let t=e>>>0;return function(){t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function Ig(e){let[t,i]=e,r=t<160||i<116,n=r?Math.min(12,Math.max(2,.08*t)):32,o=r?Math.min(8,Math.max(2,.12*i)):24,a=r?o:34;return{width:t,height:i,plot:{x:n,y:o,width:Math.max(1,t-2*n),height:Math.max(1,i-o-a)}}}function Pg(e){let t=String(e??"");if(!t)return"#4e79a7";let i=["#4e79a7","#59a14f","#e15759","#f28e2b","#76b7b2","#edc948","#b07aa1","#ff9da7"],r=0;for(let e=0;e<t.length;e+=1)r=31*r+t.charCodeAt(e)>>>0;return i[r%i.length]}function Lg(e,t="#4e79a7",i){let r=i?.styleRules,n=!!r&&r.length>0,o=n?zi(i?.valueAccessor):void 0;return i=>{let a=i.datum,s=a&&e?"function"==typeof e?e(a,0):a[e]:void 0,l={fill:null==s?t:Pg(s),stroke:"#111827",strokeWidth:1,opacity:.9};return n&&a&&Object.assign(l,qi(a,r,{value:o?o(a):void 0,category:null==s?void 0:String(s)})),l}}function Rg(e,t,i,r){return{fixedDt:1/120,maxSubsteps:8,colliders:t,observation:{chartType:i},kernel:{seed:e,gravity:{x:0,y:760},cellSize:36,collisionIterations:6,velocityDamping:.995,restitution:.08,friction:.4,sleepSpeed:8,sleepAfter:.6,...r}}}function Cg(e,t,i){return"function"==typeof i?i(e,t):e[i]}function Tg(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?t:null}let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:null}function Ng(e,t,i){return Math.max(t,Math.min(i,e))}function Fg(e,t){let i=Tg(e);return null!=i&&i>0?i:t}function Eg(e){if(!e)return;let t=Tg(e[0]),i=Tg(e[1]);return null!=t&&null!=i?t<=i?[t,i]:[i,t]:void 0}function Og(e){return String(e??"unknown").trim().replace(/[^A-Za-z0-9_-]+/g,"_")||"unknown"}function zg(e){let t=Math.max(2,Math.round(e.bins)),i=Math.max(1,Math.round(e.pegRows??t-1)),r=Math.max(1,Math.round(e.count??Math.max(64,4*t))),n=Ng(Number.isFinite(e.branchProbability)?e.branchProbability??.5:.5,0,1),o=_g(e.seed??1),a=e.idPrefix??"mechanical";return Array.from({length:r},(e,t)=>{let r=0;for(let e=0;e<i;e+=1)o()<n&&(r+=1);let s=i/2;return{id:`${a}-${t}`,value:r,mechanical:!0,pegRows:i,branchProbability:n,pathRights:r,side:r<s?"left":r>s?"right":"center"}})}function Dg(e,t,i=0){let r=new Set(e.filter(e=>null!=e.id).map(e=>String(e.id))),n=/* @__PURE__ */new Map;for(let o of e){let e=null==o.id?`${t}-${i++}`:String(o.id);for(;null==o.id&&r.has(e);)e=`${t}-${i++}`;r.add(e),n.set(e,null==o.id?{...o,id:e}:o)}return{seed:e,rows:Array.from(n.values()),nextId:i}}import{scaleLinear as Bg}from"d3-scale";function jg(e){let t=e.fixedPosition;Number.isFinite(t?.x)&&(e.x=e.prevX=t.x,e.vx=0),Number.isFinite(t?.y)&&(e.y=e.prevY=t.y,e.vy=0)}function Wg(e){if(!e)return;let t=Number.isFinite(e.x)?e.x:void 0,i=Number.isFinite(e.y)?e.y:void 0;return null==t&&null==i?void 0:{x:t,y:i}}function Yg(e,t,i){let r,n="x"===i?"y":"x",o=Math.abs(t[i]-e[i]),a=t[n]-e[n],s=(e,t)=>"circle"===e.shape.type?e.shape.radius:("x"===t?e.shape.width:e.shape.height)/2;if("circle"===e.shape.type&&"circle"===t.shape.type){let i=e.shape.radius+t.shape.radius;r=Math.sqrt(Math.max(0,i*i-o*o))}else if("aabb"===e.shape.type&&"aabb"===t.shape.type)r=s(e,n)+s(t,n);else{let a="circle"===e.shape.type?e:t,l="aabb"===e.shape.type?e:t,c=s(a,i),u=Math.max(0,o-s(l,i));r=s(l,n)+Math.sqrt(Math.max(0,c*c-u*u))}let l=a<0?-1:1;return{nx:"x"===n?l:0,ny:"y"===n?l:0,penetration:Math.max(0,r-Math.abs(a))}}function qg(e){return"circle"===e.type?{type:"circle",radius:e.radius}:{type:"aabb",width:e.width,height:e.height}}function Xg(e){return"aabb"===e.type?{type:"aabb",x:e.x,y:e.y,width:e.width,height:e.height}:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:e.thickness}}function Gg(e){return{id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,bodyCollisions:e.bodyCollisions,...e.fixedPosition?{fixedPosition:Wg(e.fixedPosition)}:{},shape:qg(e.shape),sleeping:e.sleeping,datum:e.datum,index:e.index,sleepTime:e.sleepTime,restitution:e.restitution,friction:e.friction}}function Vg(e){return e&&"function"!=typeof e?{property:e.property,equals:e.equals,notEquals:e.notEquals,oneOf:e.oneOf?.slice(),notOneOf:e.notOneOf?.slice()}:e}function Hg(e){return{id:e.id,shape:Xg(e.shape),sensor:e.sensor,restitution:e.restitution,friction:e.friction,bodyFilter:Vg(e.bodyFilter),index:e.index}}function Ug(e,t,i){if("aabb"!==t.type)return null;let r=e.x-e.prevX,n=e.y-e.prevY;if(0===r&&0===n)return null;let o="circle"===e.shape.type?e.shape.radius:e.shape.width/2,a="circle"===e.shape.type?e.shape.radius:e.shape.height/2,s=t.x-t.width/2,l=t.x+t.width/2,c=t.y-t.height/2,u=t.y+t.height/2;if(Math.max(e.x,e.prevX)+o<s||Math.min(e.x,e.prevX)-o>l||Math.max(e.y,e.prevY)+a<c||Math.min(e.y,e.prevY)-a>u)return null;let d="circle"===e.shape.type?0:o,h="circle"===e.shape.type?0:a,f=1/0,p=null,g=(e,t,r,n,o,a,s,l,c,u,d)=>{let h,g,m;if(r>0&&t+n<=o+i&&e+n>o)h=Math.max(0,(o-n-t)/r),g=e+n-o,m=-1;else{if(!(r<0&&t-n>=a-i&&e-n<a))return;h=Math.max(0,(a+n-t)/r),g=a-(e-n),m=1}let y=s+l*h;h<f&&y>=c&&y<=u&&(f=h,p={nx:d?m:0,ny:d?0:m,penetration:g})};return g(e.x,e.prevX,r,o,s,l,e.prevY,n,c-h,u+h,!0),g(e.y,e.prevY,n,a,c,u,e.prevX,r,s-d,l+d,!1),p}function Kg(e,t){return Math.abs(e.x-t.x)<=t.padding&&Math.abs(e.y-t.y)<=t.padding}function Zg(e,t){let i=Qg(e),r=[];for(let e=0;e<t.length;e++)tm(i,t[e].bounds)&&r.push(e);return{bounds:i,indexes:r}}function Qg(e,t=!0){let i="circle"===e.shape.type?e.shape.radius:e.shape.width/2,r="circle"===e.shape.type?e.shape.radius:e.shape.height/2,n=t?Math.max(.005,Math.min(i,r)):0;return{x:e.x,y:e.y,padding:n,minX:Math.min(e.x,e.prevX)-i-n,minY:Math.min(e.y,e.prevY)-r-n,maxX:Math.max(e.x,e.prevX)+i+n,maxY:Math.max(e.y,e.prevY)+r+n}}function Jg(e){let t="circle"===e.shape.type?e.shape.radius:e.shape.width/2,i="circle"===e.shape.type?e.shape.radius:e.shape.height/2;return{minX:e.x-t,minY:e.y-i,maxX:e.x+t,maxY:e.y+i}}function em(e){let t=e.shape;if("aabb"===t.type)return Jg({x:t.x,y:t.y,shape:t});let i=(t.thickness??0)/2;return{minX:Math.min(t.x1,t.x2)-i,minY:Math.min(t.y1,t.y2)-i,maxX:Math.max(t.x1,t.x2)+i,maxY:Math.max(t.y1,t.y2)+i}}function tm(e,t){return e.minX<=t.maxX&&e.maxX>=t.minX&&e.minY<=t.maxY&&e.maxY>=t.minY}function im(e,t,i={x:0,y:0}){let r=1,n=e.map(e=>{let t=Qg(e,!(e.sleeping&&e.x===e.prevX&&e.y===e.prevY));return!1!==e.bodyCollisions&&(r=Math.max(r,t.maxX-t.minX,t.maxY-t.minY)),t}),o=Math.max(1,Math.min(t,r)),a=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){if(!1===e[t].bodyCollisions)continue;let i=n[t];i.cellX=Math.floor(i.minX/o),i.cellY=Math.floor(i.minY/o);for(let e=i.cellX;e<=Math.floor(i.maxX/o);e+=1){let r=a.get(e);r||a.set(e,r=/* @__PURE__ */new Map);for(let e=i.cellY;e<=Math.floor(i.maxY/o);e+=1){let i=r.get(e);i?i.push(t):r.set(e,[t])}}}let s=[];for(let[e,t]of a)for(let[i,r]of t)for(let t=0;t<r.length;t+=1)for(let o=t+1;o<r.length;o+=1){let a=r[t],l=r[o],c=n[a],u=n[l];e!==Math.max(c.cellX,u.cellX)||i!==Math.max(c.cellY,u.cellY)||tm(c,u)&&s.push([a,l])}let l=e.map(e=>e.x*i.x+e.y*i.y);return s.sort(([e,t],[i,r])=>Math.max(l[i],l[r])-Math.max(l[e],l[t])||(e===i?t-r:e-i)),{pairs:s,coversPositions:()=>e.every((e,t)=>!1===e.bodyCollisions||Kg(e,n[t]))}}function rm(e,t){if("circle"!==e.shape.type||"circle"!==t.shape.type)return null;let i=e.shape.radius+t.shape.radius;if(i<=0)return null;let r=t.prevX-e.prevX,n=t.prevY-e.prevY,o=t.x-e.x-r,a=t.y-e.y-n,s=o*o+a*a,l=2*(r*o+n*a),c=r*r+n*n-i*i;if(c<-1e-5||s<=1e-12||l>=0)return null;let u=l*l-4*s*c;if(u<0)return null;let d=(-l-Math.sqrt(u))/(2*s);if(d<0||d>1)return null;let h=(r+d*o)/i,f=(n+d*a)/i,p=i-((t.x-e.x)*h+(t.y-e.y)*f);return p>0?{nx:h,ny:f,penetration:p}:null}var nm={seed:1,gravity:{x:0,y:980},fixedDt:1/120,cellSize:64,collisionIterations:6,velocityDamping:.995,sleepSpeed:8,sleepAfter:.35,restitution:.1,friction:.35,maxVelocity:1600,contactWakeSpeed:200},om=1e-9,am=.005;function sm(e,t,i){return Math.max(t,Math.min(i,e))}function lm(e,t,i){return Math.min(e??i,t??i)}function cm(e,t,i){return sm(Math.max(e??i,t??i),0,1)}function um(e){return e<0?-1:1}function dm(e){return e.sleeping&&e.x===e.prevX&&e.y===e.prevY}function hm(e,t,i,r,n,o){let a=r-e,s=n-t,l=i+o,c=a*a+s*s;if(c>=l*l)return null;if(c<=om)return{nx:1,ny:0,penetration:l};let u=Math.sqrt(c);return{nx:a/u,ny:s/u,penetration:l-u}}function fm(e,t,i,r,n,o,a,s){let l=n-e,c=(i+a)/2-Math.abs(l);if(c<=0)return null;let u=o-t,d=(r+s)/2-Math.abs(u);return d<=0?null:c<d?{nx:um(l),ny:0,penetration:c}:{nx:0,ny:um(u),penetration:d}}function pm(e,t,i,r,n,o,a){let s=o/2,l=a/2,c=e-sm(e,r-s,r+s),u=t-sm(t,n-l,n+l),d=c*c+u*u;if(d>i*i)return null;if(d<=om){let o=Math.abs(e-(r-s)),a=Math.abs(e-(r+s)),c=Math.abs(t-(n-l)),u=Math.abs(t-(n+l)),d=Math.min(o,a,c,u);return d===o?{nx:-1,ny:0,penetration:i+o}:d===a?{nx:1,ny:0,penetration:i+a}:d===c?{nx:0,ny:-1,penetration:i+c}:{nx:0,ny:1,penetration:i+u}}let h=Math.sqrt(d);return{nx:c/h,ny:u/h,penetration:i-h}}function gm(e,t,i,r,n,o,a,s=0){let l=o-r,c=a-n,u=l*l+c*c,d=u<=om?0:sm(((e-r)*l+(t-n)*c)/u,0,1),h=i+s/2,f=e-(r+l*d),p=t-(n+c*d),g=f*f+p*p;if(g>=h*h)return null;if(g<=om){let e=Math.sqrt(u);return e<=om?{nx:1,ny:0,penetration:h}:{nx:-c/e,ny:l/e,penetration:h}}let m=Math.sqrt(g);return{nx:f/m,ny:p/m,penetration:h-m}}function mm(e,t){if("circle"===e.shape.type&&"circle"===t.shape.type)return hm(e.x,e.y,e.shape.radius,t.x,t.y,t.shape.radius);if("aabb"===e.shape.type&&"aabb"===t.shape.type)return fm(e.x,e.y,e.shape.width,e.shape.height,t.x,t.y,t.shape.width,t.shape.height);let i="circle"===e.shape.type?e:t,r=i===e?t:e;if("circle"!==i.shape.type||"aabb"!==r.shape.type)return null;let n=pm(i.x,i.y,i.shape.radius,r.x,r.y,r.shape.width,r.shape.height);return n&&i===e&&(n.nx=-n.nx,n.ny=-n.ny),n}function ym(e,t){let i=t.shape;if("aabb"===i.type)return"circle"===e.shape.type?pm(e.x,e.y,e.shape.radius,i.x,i.y,i.width,i.height):fm(i.x,i.y,i.width,i.height,e.x,e.y,e.shape.width,e.shape.height);let r="circle"===e.shape.type?e.shape.radius:Math.sqrt(e.shape.width*e.shape.width+e.shape.height*e.shape.height)/2;return gm(e.x,e.y,r,i.x1,i.y1,i.x2,i.y2,i.thickness??0)}function xm(e,t){return`${e}\0${t}`}function bm(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function vm(e,t){if(!t)return;let i=e;for(let e of t.split(".")){if(null==i||"object"!=typeof i||!Object.prototype.hasOwnProperty.call(i,e))return;i=i[e]}return i}function wm(e,t){return!!t?.some(t=>Object.is(e,t))}function km(e,t){if(!t)return!0;if("function"==typeof t)return t(e);let i=vm(e,t.property);return!("equals"in t&&!Object.is(i,t.equals)||"notEquals"in t&&Object.is(i,t.notEquals)||t.oneOf&&!wm(i,t.oneOf)||t.notOneOf&&wm(i,t.notOneOf))}function Sm(e,t){return km(t,e.bodyFilter)}var Am=class{constructor(e={}){this.capabilities={determinism:"strict",sensors:!0,joints:!1,ccd:!1,maxBodiesHint:5e3,worker:!1},this.bodies=/* @__PURE__ */new Map,this.colliders=/* @__PURE__ */new Map,this.springs=/* @__PURE__ */new Map,this.activeSensors=/* @__PURE__ */new Set,this.supportedThisStep=/* @__PURE__ */new Set,this.supportDependents=/* @__PURE__ */new Map,this.supportContactsThisStep=/* @__PURE__ */new Set,this.reboundingThisStep=/* @__PURE__ */new Set,this.interpenetratingThisStep=/* @__PURE__ */new Set,this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0,this.options={...nm,...e},this.random=_g(this.options.seed)}init(e={}){this.options={...nm,...e},this.random=_g(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[],this.nextBodyIndex=0,this.nextColliderIndex=0,this.nextSpringIndex=0}spawn(e){let t={id:e.id,x:e.x,y:e.y,prevX:e.x,prevY:e.y,vx:e.vx??0,vy:e.vy??0,angle:e.angle??0,mass:Math.max(om,e.mass??1),bodyCollisions:e.bodyCollisions??!0,...e.fixedPosition?{fixedPosition:Wg(e.fixedPosition)}:{},shape:qg(e.shape),sleeping:!1,datum:e.datum,restitution:e.restitution,friction:e.friction,index:this.nextBodyIndex,sleepTime:0};jg(t),this.nextBodyIndex+=1,this.bodies.set(e.id,t)}remove(e){for(let t of e){this.bodies.delete(t);for(let e of Array.from(this.activeSensors))bm(e).bodyId===t&&this.activeSensors.delete(e)}}setColliders(e){this.colliders.clear(),this.activeSensors.clear(),this.nextColliderIndex=0;for(let t of e)this.colliders.set(t.id,{...t,shape:Xg(t.shape),bodyFilter:Vg(t.bodyFilter),index:this.nextColliderIndex}),this.nextColliderIndex+=1}setConstraint(e){let t=e.id??`spring-${this.nextSpringIndex}`;return this.springs.set(t,{id:t,bodyId:e.bodyId,target:e.target,restLength:e.restLength??0,stiffness:e.stiffness??40,damping:e.damping??3}),this.nextSpringIndex+=1,t}removeConstraint(e){this.springs.delete(e)}applyImpulse(e,t,i){let r=this.bodies.get(e);r&&(r.vx+=t/r.mass,r.vy+=i/r.mass,jg(r),this.wake(r))}step(e=this.options.fixedDt){let t=Math.max(0,e);if(this.lastEvents=[],0===t)return;this.reboundingThisStep.clear();let i=this.sortedBodies();for(let e of i)e.prevX=e.x,e.prevY=e.y;this.applySprings(t);let r=this.options.maxVelocity;for(let e of i)if(!e.sleeping){if(e.vx+=this.options.gravity.x*t,e.vy+=this.options.gravity.y*t,e.vx*=this.options.velocityDamping,e.vy*=this.options.velocityDamping,jg(e),r>0){let t=Math.sqrt(e.vx*e.vx+e.vy*e.vy);if(t>r){let i=r/t;e.vx*=i,e.vy*=i}}e.x+=e.vx*t,e.y+=e.vy*t}this.supportedThisStep.clear(),this.supportDependents.clear(),this.supportContactsThisStep.clear(),this.interpenetratingThisStep.clear();let n=this.sortedColliders().filter(e=>!e.sensor).map(e=>({collider:e,bounds:em(e)})),o=n.some(({collider:e})=>e.bodyFilter)?void 0:new Array(i.length);this.resolveColliders(i,n,!1,o);let a=o&&i.map(dm),s=im(i,this.options.cellSize,this.options.gravity);for(let e=0;e<this.options.collisionIterations;e+=1){e>0&&!s.coversPositions()&&(s=im(i,this.options.cellSize,this.options.gravity));let t=this.resolveBodyPairs(i,s.pairs,0===e,a),r=this.resolveColliders(i,n,0===e,o);if(o&&!t&&!r)break}s.coversPositions()||(s=im(i,this.options.cellSize,this.options.gravity));for(let[e,t]of s.pairs){let r=mm(i[e],i[t]);r&&r.penetration>.02&&(this.interpenetratingThisStep.add(i[e].id),this.interpenetratingThisStep.add(i[t].id))}let l=Array.from(this.supportedThisStep);for(let e=0;e<l.length;e+=1)for(let t of this.supportDependents.get(l[e])??[])this.supportedThisStep.has(t)||(this.supportedThisStep.add(t),l.push(t));this.reconcileSupportedVelocity(i,t),this.updateSensors(i),this.updateSleeping(i,t)}settle(e=1200,t=this.options.fixedDt){let i=0;for(;i<e&&!this.allSleeping();)this.step(t),i+=1;return i}readState(e=[]){e.length=0;for(let t of this.sortedBodies())e.push({id:t.id,x:t.x,y:t.y,prevX:t.prevX,prevY:t.prevY,vx:t.vx,vy:t.vy,angle:t.angle,mass:t.mass,...t.fixedPosition?{fixedPosition:Wg(t.fixedPosition)}:{},shape:qg(t.shape),sleeping:t.sleeping,datum:t.datum});return e}events(){return this.lastEvents.slice()}activeSensorPairs(){return Array.from(this.activeSensors).sort().map(bm)}allSleeping(){for(let e of this.bodies.values())if(!e.sleeping)return!1;return!0}snapshot(){return{options:{...this.options,gravity:{...this.options.gravity}},bodies:this.sortedBodies().map(Gg),colliders:this.sortedColliders().map(Hg),springs:Array.from(this.springs.values()).map(e=>({...e,target:{...e.target}})),activeSensors:Array.from(this.activeSensors).sort()}}restore(e){this.options={...e.options,gravity:{...e.options.gravity}},this.random=_g(this.options.seed),this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors=new Set(e.activeSensors),this.lastEvents=[],this.nextBodyIndex=0;for(let t of e.bodies){let e=Gg(t);jg(e),this.bodies.set(e.id,e),this.nextBodyIndex=Math.max(this.nextBodyIndex,e.index+1)}this.nextColliderIndex=0;for(let t of e.colliders){let e=Hg(t);this.colliders.set(e.id,e),this.nextColliderIndex=Math.max(this.nextColliderIndex,e.index+1)}this.nextSpringIndex=0;for(let t of e.springs){this.springs.set(t.id,{...t,target:{...t.target}});let e=/^spring-(\d+)$/.exec(t.id);e&&(this.nextSpringIndex=Math.max(this.nextSpringIndex,Number(e[1])+1))}}dispose(){this.bodies.clear(),this.colliders.clear(),this.springs.clear(),this.activeSensors.clear(),this.lastEvents=[]}sortedBodies(){return Array.from(this.bodies.values()).sort((e,t)=>e.index-t.index)}sortedColliders(){return Array.from(this.colliders.values()).sort((e,t)=>e.index-t.index)}applySprings(e){for(let t of Array.from(this.springs.values()).sort((e,t)=>e.id.localeCompare(t.id))){let i=this.bodies.get(t.bodyId);if(!i||i.sleeping)continue;let r="point"===t.target.type?t.target:this.bodies.get(t.target.bodyId);if(!r)continue;let n=r.x-i.x,o=r.y-i.y,a=n*n+o*o,s=Math.sqrt(a);if(s<=om)continue;let l=n/s,c=o/s,u="vx"in r?r.vx:0,d="vy"in r?r.vy:0,h=(u-i.vx)*l+(d-i.vy)*c,f=(s-t.restLength)*t.stiffness+h*t.damping;i.vx+=f*l*e/i.mass,i.vy+=f*c*e/i.mass}}resolveBodyPairs(e,t,i,r){let n=!1;for(let[o,a]of t){let t=e[o],s=e[a];if(!t||!s)continue;if(!i&&r?.[o]&&r[a]&&dm(t)&&dm(s)){n=!0;continue}let l=rm(t,s)??mm(t,s);l&&(n=!0,this.resolveDynamicCollision(t,s,l),i&&this.lastEvents.push({type:"contact",bodyId:t.id,otherId:s.id,sensor:!1}))}return n}resolveDynamicCollision(e,t,i){(e.fixedPosition||t.fixedPosition)&&(!e.sleeping&&null==e.fixedPosition?.x||!t.sleeping&&null==t.fixedPosition?.x?(e.sleeping||null!=e.fixedPosition?.y)&&(t.sleeping||null!=t.fixedPosition?.y)&&(i=Yg(e,t,"y")):i=Yg(e,t,"x"));let r=this.options.gravity,n=Math.hypot(r.x,r.y),o=this.contactOpposesGravity(i.nx,i.ny,n),a=this.contactOpposesGravity(-i.nx,-i.ny,n);o&&(e.sleeping&&this.supportedThisStep.add(t.id),this.addSupportContact(e.id,t.id)),a&&(t.sleeping&&this.supportedThisStep.add(e.id),this.addSupportContact(t.id,e.id));let s=e.sleeping?0:1/e.mass,l=t.sleeping?0:1/t.mass,c=null==e.fixedPosition?.x?s:0,u=null==e.fixedPosition?.y?s:0,d=null==t.fixedPosition?.x?l:0,h=null==t.fixedPosition?.y?l:0,f=e.fixedPosition||t.fixedPosition?i.nx**2*(c+d)+i.ny**2*(u+h):s+l;if(f<=om)return;let p=this.supportedThisStep.has(e.id)&&o&&!t.sleeping&&!t.fixedPosition,g=this.supportedThisStep.has(t.id)&&a&&!e.sleeping&&!e.fixedPosition,m=n>1,y=m&&p?0:c,x=m&&p?0:u,b=m&&!p&&g?0:d,v=m&&!p&&g?0:h,w=i.nx**2*(y+b)+i.ny**2*(x+v),k=Math.max(0,i.penetration-am)/Math.max(om,w);e.x-=i.nx*k*y,e.y-=i.ny*k*x,t.x+=i.nx*k*b,t.y+=i.ny*k*v,m&&p&&this.supportedThisStep.add(t.id),m&&g&&this.supportedThisStep.add(e.id);let S=t.vx-e.vx,A=t.vy-e.vy,M=S*i.nx+A*i.ny;if(M>0)return;let $=Math.abs(M),_=lm(e.restitution,t.restitution,this.options.restitution),I=e.vx*r.x+e.vy*r.y,P=t.vx*r.x+t.vy*r.y,L=-(1+_)*M/f,R=L*i.nx,C=L*i.ny;e.vx-=R*c,e.vy-=C*u,t.vx+=R*d,t.vy+=C*h,this.applyFriction(e,t,i,L,c,u,d,h),_>0&&(I>=0&&e.vx*r.x+e.vy*r.y<0&&this.reboundingThisStep.add(e.id),P>=0&&t.vx*r.x+t.vy*r.y<0&&this.reboundingThisStep.add(t.id)),$>this.options.contactWakeSpeed&&(this.wake(e),this.wake(t))}applyFriction(e,t,i,r,n,o,a,s){let l=-i.ny,c=i.nx,u=(t.vx-e.vx)*l+(t.vy-e.vy)*c,d=e.fixedPosition||t.fixedPosition?l**2*(n+a)+c**2*(o+s):n+a;if(Math.abs(u)<=om||d<=om)return;let h=cm(e.friction,t.friction,this.options.friction),f=sm(-u/d,-r*h,r*h),p=f*l,g=f*c;e.vx-=p*n,e.vy-=g*o,t.vx+=p*a,t.vy+=g*s}resolveColliders(e,t,i,r){if(0===t.length)return!1;let n=!1;for(let o=0;o<e.length;o++){let a=e[o],s=r?.[o];r&&(!s||!Kg(a,s.bounds))&&(r[o]=s=Zg(a,t));let l=0;for(;l<(s?s.indexes.length:t.length);){let e=s?s.indexes[l++]:l++,{collider:c,bounds:u}=t[e];if(!Sm(c,a))continue;let d=Ug(a,c.shape,am+om);if(!d&&!tm(Jg(a),u))continue;let h=d??ym(a,c);if(h&&(n=!0,this.resolveStaticCollision(a,c,h),this.contactOpposesGravity(h.nx,h.ny)&&this.supportedThisStep.add(a.id),i&&this.lastEvents.push({type:"contact",bodyId:a.id,otherId:c.id,sensor:!1}),s&&r&&!Kg(a,s.bounds)))for(r[o]=s=Zg(a,t),l=0;l<s.indexes.length&&s.indexes[l]<=e;)l++}}return n}resolveStaticCollision(e,t,i){e.x+=i.nx*Math.max(0,i.penetration-am),e.y+=i.ny*Math.max(0,i.penetration-am);let r=e.vx*i.nx+e.vy*i.ny;if(r<0){let n=lm(e.restitution,t.restitution,this.options.restitution),o=this.options.gravity,a=e.vx*o.x+e.vy*o.y;e.vx-=(1+n)*r*i.nx,e.vy-=(1+n)*r*i.ny;let s=-i.ny,l=i.nx,c=e.vx*s+e.vy*l,u=cm(e.friction,t.friction,this.options.friction);e.vx-=c*s*u,e.vy-=c*l*u,n>0&&a>=0&&e.vx*o.x+e.vy*o.y<0&&this.reboundingThisStep.add(e.id)}jg(e)}updateSensors(e){let t=this.sortedColliders().filter(e=>e.sensor);if(0===t.length&&0===this.activeSensors.size)return;let i=/* @__PURE__ */new Set;for(let r of e){let e=Jg(r);for(let n of t){if(!Sm(n,r)||!tm(e,em(n))||!ym(r,n))continue;let t=xm(n.id,r.id);i.add(t),this.activeSensors.has(t)||this.lastEvents.push({type:"sensor-enter",bodyId:r.id,sensorId:n.id})}}for(let e of Array.from(this.activeSensors).sort()){if(i.has(e))continue;let{sensorId:t,bodyId:r}=bm(e);this.lastEvents.push({type:"sensor-exit",bodyId:r,sensorId:t})}this.activeSensors=i}updateSleeping(e,t){let i=Math.hypot(this.options.gravity.x,this.options.gravity.y)>1;for(let r of e){let e=Math.sqrt(r.vx*r.vx+r.vy*r.vy),n=Math.sqrt((r.x-r.prevX)*(r.x-r.prevX)+(r.y-r.prevY)*(r.y-r.prevY));e<this.options.sleepSpeed&&n<this.options.sleepSpeed*t&&!this.interpenetratingThisStep.has(r.id)&&(!i||this.supportedThisStep.has(r.id))?(r.sleepTime+=t,!r.sleeping&&r.sleepTime>=this.options.sleepAfter&&(r.sleeping=!0,r.vx=0,r.vy=0,this.lastEvents.push({type:"sleep",bodyId:r.id}))):r.sleeping?this.wake(r):r.sleepTime=0}}addSupportContact(e,t){let i=this.supportDependents.get(e);i?.has(t)||(this.supportContactsThisStep.add(e),this.supportContactsThisStep.add(t),i||(i=/* @__PURE__ */new Set,this.supportDependents.set(e,i)),i.add(t))}reconcileSupportedVelocity(e,t){let i=this.options.gravity;if(!(Math.hypot(i.x,i.y)<=1))for(let r of e)r.sleeping||!this.supportedThisStep.has(r.id)||!this.supportContactsThisStep.has(r.id)||this.reboundingThisStep.has(r.id)&&r.vx*i.x+r.vy*i.y<0||(r.vx=(r.x-r.prevX)/t,r.vy=(r.y-r.prevY)/t,jg(r))}contactOpposesGravity(e,t,i){let{x:r,y:n}=this.options.gravity;return i??(i=Math.hypot(r,n)),i<=1e-9||(e*r+t*n)/i<-.2}wake(e){e.sleeping&&this.lastEvents.push({type:"wake",bodyId:e.id}),e.sleeping=!1,e.sleepTime=0}nextRandom(){return this.random()}},Mm=class{constructor(e={}){this.id="builtin",this.capabilities={...(new Am).capabilities,engine:"builtin"},this.world=new Am(e)}init(e={}){this.world.init(e)}spawn(e){this.world.spawn(e)}remove(e){this.world.remove(e)}setColliders(e){this.world.setColliders(e)}setConstraint(e){return this.world.setConstraint(e)}removeConstraint(e){this.world.removeConstraint(e)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i)}step(e){this.world.step(e)}settle(e,t){return this.world.settle(e,t)}readState(e){return this.world.readState(e)}events(){return this.world.events()}activeSensorPairs(){return this.world.activeSensorPairs()}allSleeping(){return this.world.allSleeping()}snapshot(){return this.world.snapshot()}restore(e){this.world.restore(e)}nextRandom(){return this.world.nextRandom()}dispose(){this.world.dispose()}};function $m(e={}){return new Mm(e)}function _m(e,t={}){return e?"function"==typeof e?e(t):(e.init(t),e):$m(t)}var Im=["binId","targetBin","category","windowIndex","lane","group"];function Pm(){return{count:0,total:0,mean:0,m2:0,min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY}}function Lm(e,t){if(!Number.isFinite(t))return;e.count+=1,e.total+=t,e.min=Math.min(e.min,t),e.max=Math.max(e.max,t);let i=t-e.mean;e.mean+=i/e.count;let r=t-e.mean;e.m2+=i*r}function Rm(e){return{count:e.count,total:e.total,mean:e.count>0?e.mean:0,min:e.count>0?e.min:0,max:e.count>0?e.max:0,variance:e.count>1?e.m2/(e.count-1):0}}function Cm(e){return{count:e.count,total:e.total,mean:e.mean,m2:e.variance*Math.max(0,e.count-1),min:e.count>0?e.min:Number.POSITIVE_INFINITY,max:e.count>0?e.max:Number.NEGATIVE_INFINITY}}function Tm(e,t){let i=e;if(null!=i[t])return i[t];let r=e.datum;return r&&"object"==typeof r?r[t]:void 0}function Nm(e,t,i){return"function"==typeof e?e(t,i):"string"==typeof e?Tm(t,e):void 0}function Fm(e,t,i){if("number"==typeof e)return e;let r="function"==typeof e?e(t,i):"string"==typeof e?Tm(t,e):1,n="number"==typeof r?r:Number(r);return Number.isFinite(n)?n:1}function Em(e){if(null==e)return;let t=String(e);return t.trim()?t:void 0}function Om(e){for(let t of Im){let i=Em(Tm(e,t));if(i)return i}return"sediment"}function zm(e){let t=Rm(e.value);return{id:e.id,label:e.label,count:t.count,total:t.total,bodyIds:e.bodyIds.slice(),lastBodyId:e.lastBodyId,lastDatum:e.lastDatum,x:Rm(e.x),y:Rm(e.y),value:t}}var Dm=class{constructor(e=!1){this.bins=/* @__PURE__ */new Map,this.nextIndex=0,this.config=e}updateConfig(e){void 0!==e&&(this.config=e,!1===e&&this.clear())}isEnabled(){return!1!==this.config}add(e){if(!1===this.config)return null;let t=this.nextIndex;this.nextIndex+=1;let i=Em(Nm(this.config.binAccessor,e,t))??Om(e),r=Em(Nm(this.config.labelAccessor,e,t))??i,n=Fm(this.config.valueAccessor,e,t),o=Math.max(0,Math.floor(this.config.retainBodyIds??12)),a=this.bins.get(i);return a||(a={id:i,label:r,bodyIds:[],x:Pm(),y:Pm(),value:Pm()},this.bins.set(i,a)),a.label=r,a.lastBodyId=e.id,a.lastDatum=e.datum,Lm(a.x,e.x),Lm(a.y,e.y),Lm(a.value,n),o>0&&(a.bodyIds.push(e.id),a.bodyIds.length>o&&(a.bodyIds=a.bodyIds.slice(a.bodyIds.length-o))),zm(a)}clear(){this.bins.clear(),this.nextIndex=0}snapshot(){return Array.from(this.bins.values()).map(zm)}restore(e=[]){this.bins.clear();for(let t of e)this.bins.set(t.id,{id:t.id,label:t.label,bodyIds:t.bodyIds.slice(),lastBodyId:t.lastBodyId,lastDatum:t.lastDatum,x:Cm(t.x),y:Cm(t.y),value:Cm(t.value)});this.nextIndex=e.reduce((e,t)=>e+t.count,0)}totals(){let e=this.snapshot();return{bins:e.length,count:e.reduce((e,t)=>e+t.count,0),total:e.reduce((e,t)=>e+t.total,0)}}};function Bm(e,t={}){let{baselineY:i=0,binWidth:r=24,gap:n=2,maxHeight:o=80,value:a="count",x:s}=t,l=e.reduce((e,t)=>Math.max(e,t[a]),1);return e.map((e,t)=>{let c=Math.max(0,e[a]/l*o),u=s?.(e,t)??t*(r+n);return{binId:e.id,label:e.label,index:t,count:e.count,total:e.total,x:u,y:i-c,width:r,height:c,meanX:e.x.mean,meanY:e.y.mean}})}function jm(e){let t=Number(e);if(Number.isFinite(t)&&!(t<=0))return Math.floor(t)}function Wm(e,t,i){if(!1===i)return;let r=jm(i?.warnAt);return null!=r?r:null!=e?Math.max(1,Math.floor(.8*e)):null!=t?Math.max(1,Math.floor(.8*t)):void 0}function Ym(e){let t=Math.max(0,Math.floor(e.liveBodies)),i=Math.max(0,Math.floor(e.queuedBodies??0)),r=t+i,n=jm(e.bodyLimit),o=jm(e.engineMaxBodiesHint),a=Wm(n,o,e.options),s=null==n?0:Math.max(0,t-n),l=s>0?"overflow":null!=a&&r>=a?"warning":"ok";return{action:"overflow"!==l?"continue":e.sedimentEnabled?"sediment":e.evictionEnabled?"evict":"retain",bodyLimit:n,engineMaxBodiesHint:o,liveBodies:t,overflow:s,projectedBodies:r,queuedBodies:i,state:l,warnAt:a}}var qm={bodyLimit:Number.POSITIVE_INFINITY,eviction:"oldest",fixedDt:1/120,maxDeltaSeconds:.1,maxSubsteps:8,settleStepLimit:1200,timeScale:1},Xm={chartId:"physics",chartType:"physics",sensors:{},onObservation:void 0,onSimulationStateChange:void 0};function Gm(e={},t=Xm){return{chartId:e.chartId??t.chartId,chartType:e.chartType??t.chartType,sensors:e.sensors??t.sensors,onObservation:e.onObservation??t.onObservation,onSimulationStateChange:e.onSimulationStateChange??t.onSimulationStateChange}}function Vm(e){return{...e,shape:{...e.shape},...e.fixedPosition?{fixedPosition:{...e.fixedPosition}}:{},datum:e.datum,springs:e.springs?.map(e=>({...e,target:{...e.target}}))}}function Hm(e){if(e instanceof Date){let t=e.getTime();return Number.isFinite(t)?t:void 0}let t="number"==typeof e?e:"string"==typeof e&&e.trim()?Number(e):NaN;return Number.isFinite(t)?t:void 0}function Um(e,t){let i=e;if(null!=i[t])return i[t];let r=e.datum;return r&&"object"==typeof r?r[t]:void 0}function Km(e,t,i){return"function"==typeof i?Hm(i(e,t)):"string"==typeof i?Hm(Um(e,i)):Hm(e.spawnAt)??Hm(Um(e,"arrivalTime"))??Hm(Um(e,"timestamp"))??Hm(Um(e,"time"))??Hm(Um(e,"eventTime"))}function Zm(e,t={}){let i=Hm(t.startAt)??0,r=t.pacing??"immediate";if("arrival"===r){let r=1/0,n=e.map((e,i)=>{let n=Km(e,i,t.timeAccessor);return null!=n&&(r=Math.min(r,n)),n}),o=Hm(t.timeScale)??1,a=o>0?o:1;return e.map((e,t)=>{let o=n[t],s=null==o?0:Math.max(0,o-r);return{...Vm(e),spawnAt:i+s/a}})}if("object"==typeof r){let t=Hm(r.ratePerSec);if(t&&t>0)return e.map((e,r)=>({...Vm(e),spawnAt:i+r/t}))}return e.map(e=>({...Vm(e),spawnAt:i}))}function Qm(e){return{...Vm(e),sequence:e.sequence,spawnAt:e.spawnAt}}function Jm(e){return e.map(e=>({...e,shape:{...e.shape},bodyFilter:e.bodyFilter&&"function"!=typeof e.bodyFilter?{...e.bodyFilter,oneOf:e.bodyFilter.oneOf?.slice(),notOneOf:e.bodyFilter.notOneOf?.slice()}:e.bodyFilter}))}function ey(e){return!1!==e&&{...e}}function ty(e,t){return e.spawnAt===t.spawnAt?e.sequence-t.sequence:e.spawnAt-t.spawnAt}function iy(e){return{...e,gravity:{...e.gravity}}}function ry(e,t,i,r){if("circle"===e.shape.type){let n=e.x-t,o=e.y-i,a=e.shape.radius+r,s=n*n+o*o;return s<=a*a?s:null}let n=Math.max(Math.abs(t-e.x)-e.shape.width/2,0),o=Math.max(Math.abs(i-e.y)-e.shape.height/2,0),a=n*n+o*o;return a<=r*r?a:null}function ny(e,t){return`${e}\0${t}`}function oy(e){let t=e.indexOf("\0");return{sensorId:e.slice(0,t),bodyId:e.slice(t+1)}}function ay(e,t={}){let{idPrefix:i="plot",includeFloor:r=!0,includeCeiling:n=!1,includeLeftWall:o=!0,includeRightWall:a=!0,wallThickness:s=20,floorThickness:l=s}=t,c=[],u=e.x+e.width/2,d=e.y+e.height/2,h=(e,t,r,n,o)=>{c.push({id:`${i}-${e}`,shape:{type:"aabb",x:t,y:r,width:n,height:o}})};return r&&h("floor",u,e.y+e.height+l/2,e.width+2*s,l),n&&h("ceiling",u,e.y-l/2,e.width+2*s,l),o&&h("left-wall",e.x-s/2,d,s,e.height+2*l),a&&h("right-wall",e.x+e.width+s/2,d,s,e.height+2*l),c}function sy(e){let{idPrefix:t="bin",count:i,domainStart:r,domainStep:n,xScale:o,yTop:a,yBottom:s,wallThickness:l=4,includeBoundaryWalls:c=!0,includeInteriorWalls:u=!0,closedBefore:d,lidY:h=a,lidThickness:f=Math.max(2,l)}=e,p=[],g=a+(s-a)/2,m=Math.abs(s-a),y=c?i:i-1;if(u||c)for(let e=c?0:1;e<=y;e+=1){if(!u&&e>0&&e<i)continue;let a=o(r+e*n);p.push({id:`${t}-wall-${e}`,shape:{type:"aabb",x:a,y:g,width:l,height:m}})}if(null!=d)for(let e=0;e<i;e+=1){let i=r+e*n,a=i+n;if(a>=d)continue;let s=o(i),c=o(a);p.push({id:`${t}-lid-${e}`,shape:{type:"segment",x1:Math.min(s,c)+l/2,y1:h,x2:Math.max(s,c)-l/2,y2:h,thickness:f}})}return p}import{quadtree as ly}from"d3-quadtree";var cy=class{constructor(){this.maxSearchRadius=0,this.revision=-1,this.tree=null}hitTest(e,t,i,r,n,o=0,a){let s=this.ensure(e,t);if(!s)return null;let l=null,c=Number.POSITIVE_INFINITY,u=Math.max(0,a?.searchRadius??Math.max(0,o)+this.maxSearchRadius),d=r-u,h=r+u,f=n-u,p=n+u;return s.visit((e,t,s,u,g)=>{if(u<d||t>h||g<f||s>p)return!0;if(e.length)return!1;let m=e;for(;m;){let e=m.data;if(e&&(!a?.include||a.include(e))){let t=a?.distanceSquared?a.distanceSquared(e,r,n):ry(e,r,n,Math.max(0,o));null!=t&&(t<c||t===c&&i.indexOf(e.id)>i.indexOf(l?.id??""))&&(l=e,c=t)}m=m.next}return!1}),l}ensure(e,t){if(this.tree&&this.revision===t)return this.tree;let i=e.readState();return 0===i.length?(this.tree=null,this.maxSearchRadius=0,this.revision=t,null):(this.maxSearchRadius=i.reduce((e,t)=>{return Math.max(e,"circle"===(i=t).shape.type?i.shape.radius:Math.hypot(i.shape.width,i.shape.height)/2);var i},0),this.tree=ly().x(e=>e.x).y(e=>e.y).addAll(i),this.revision=t,this.tree)}},uy=["data","scene-geometry","data-paint","accessibility","evidence"],dy=["scene-geometry","data-paint","accessibility","evidence"],hy=["overlay","accessibility","evidence"],fy=(e,t)=>({retainedData:e,invalidations:t}),py=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],gy=["scene-geometry","data-paint","accessibility","evidence"],my=[],yy={engine:/* @__PURE__ */fy("rebuild",["scene-geometry","data-paint","accessibility","evidence"]),kernel:/* @__PURE__ */fy("preserve",gy),colliders:/* @__PURE__ */fy("preserve",gy),sediment:/* @__PURE__ */fy("preserve",gy),bodyBudget:/* @__PURE__ */fy("preserve",py),bodyLimit:/* @__PURE__ */fy("preserve",py),eviction:/* @__PURE__ */fy("preserve",py),fixedDt:/* @__PURE__ */fy("preserve",my),maxDeltaSeconds:/* @__PURE__ */fy("preserve",my),maxSubsteps:/* @__PURE__ */fy("preserve",my),settleStepLimit:/* @__PURE__ */fy("preserve",my),timeScale:/* @__PURE__ */fy("preserve",my),observation:/* @__PURE__ */fy("preserve",my)},xy=/* @__PURE__ */fy("preserve",py);function by(e){let t="preserve",i=/* @__PURE__ */new Set;for(let r of e){let e=yy[r]??xy;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var vy=["seed","fixedDt","cellSize","collisionIterations","velocityDamping","sleepSpeed","sleepAfter","restitution","friction","maxVelocity","contactWakeSpeed"];function wy(e,t){return e===t||!(!e||!t||e.gravity?.x!==t.gravity?.x||e.gravity?.y!==t.gravity?.y)&&vy.every(i=>e[i]===t[i])}function ky(e,t){return Object.keys(e).filter(i=>"kernel"===i?!wy(e.kernel,t.kernel):e[i]!==t[i])}function Sy(e,t,i){if(!t.some(e=>"sleep"===e.type))return;let r=new Map(e.readState().map(e=>[e.id,e]));for(let e of t){if("sleep"!==e.type)continue;let t=r.get(e.bodyId);i.emit({type:"physics-settle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:e.bodyId,datum:t?.datum,x:t?.x,y:t?.y})}}function Ay(e,t,i){let r=new Set(e.activeSensorPairs().map(e=>ny(e.sensorId,e.bodyId))),n=r.size!==t.size;if(!n)for(let e of r)if(!t.has(e)){n=!0;break}if(!n)return r;let o=new Map(e.readState().map(e=>[e.id,e])),a=(e,t)=>{let{sensorId:r,bodyId:n}=oy(t),a=i.observation.sensors[r],s=o.get(n);i.emit({type:"enter"===e?a?.enterType??"physics-bin-enter":a?.exitType??"physics-bin-exit",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,bodyId:n,datum:s?.datum,x:s?.x,y:s?.y,sensorId:r,binId:a?.binId??r})};for(let e of Array.from(r).sort())t.has(e)||a("enter",e);for(let e of Array.from(t).sort())r.has(e)||a("exit",e);return r}function My(e,t){for(let i of e)t.has(oy(i).bodyId)&&e.delete(i)}function $y(e,t,i,r){return e||!t?"paused":i||!r?"running":"settled"}function _y(e,t,i){i.observation.onSimulationStateChange?.(t,e),("running"===t||"settled"===t)&&i.emit({type:"running"===t?"sim-active":"sim-idle",timestamp:i.elapsedSeconds,chartType:i.observation.chartType,chartId:i.observation.chartId,simulationState:t,previousSimulationState:e})}function Iy(e,t){t.emit({type:"overflow"===e.state?"physics-budget-overflow":"physics-budget-warning",timestamp:t.elapsedSeconds,chartType:t.observation.chartType,chartId:t.observation.chartId,budgetAction:e.action,bodyLimit:e.bodyLimit,engineMaxBodiesHint:e.engineMaxBodiesHint,liveBodies:e.liveBodies,overflow:e.overflow,projectedBodies:e.projectedBodies,queuedBodies:e.queuedBodies,warnAt:e.warnAt})}function Py(e,t,i){if("sleeping-first"!==t)return i.slice();let r=new Map(e.readState().map(e=>[e.id,e.sleeping])),n=[],o=[];for(let e of i)r.get(e)?n.push(e):o.push(e);return[...n,...o]}function Ly(e,t,i,r){let n=new Map(e.readState().map(e=>[e.id,e])),o=[];for(let e of i){let i=n.get(e);if(!i)continue;let a=t.add(i);a&&(o.push(e),r.emit({type:"physics-sediment",timestamp:r.elapsedSeconds,chartType:r.observation.chartType,chartId:r.observation.chartId,bodyId:e,datum:i.datum,x:i.x,y:i.y,binId:a.id,count:a.count,total:a.total}))}return o}function Ry(e,t,i,r,n,o){let a={evicted:[],sedimented:[],liveBodyOrder:n};if(!1===i)return a;let s=Math.max(0,Math.floor(r));if(!Number.isFinite(s))return a;let l=n.length-s;if(l<=0)return a;let c=Py(e,i,n).slice(0,l);if(0===c.length)return a;let u=Ly(e,t,c,o);e.remove(c);let d=new Set(c);return{evicted:c,sedimented:u,liveBodyOrder:n.filter(e=>!d.has(e))}}function Cy(e){let t=e?.sleepSpeed;return"number"==typeof t&&Number.isFinite(t)&&t>0?t:8}var Ty=class{constructor(){this.seconds=0,this.speed=8,this.scratch=[]}setKernelOptions(e){this.speed=Cy(e)}reset(){this.seconds=0}isAtRest(){return this.seconds>=.6}refresh(e,t,i){if(i>0)return void(this.seconds=0);if(e.allSleeping())return void(this.seconds+=Math.max(0,t));let r=e.readState(this.scratch),n=this.speed*this.speed,o=!0;for(let e of r){if(e.sleeping)continue;let i=e.x-e.prevX,r=e.y-e.prevY;if(e.vx*e.vx+e.vy*e.vy>=n||t>0&&i*i+r*r>=n*t*t){o=!1;break}}this.seconds=o?this.seconds+Math.max(0,t):0}};function Ny(e,t,i=!1){if(!e)return;let r=["spawned","evicted","sedimented","events","observations"],n={spawned:0,evicted:0,sedimented:0,events:0,observations:0},o=o=>{let a=t(o),s={...a};r.forEach(e=>{s[e]=a[e].slice(n[e]),n[e]=a[e].length}),(0!==o||i||!r.every(e=>0===s[e].length))&&e.onStep(s)};return o(0),()=>o(1)}function Fy(e,t,i,r={}){let n,o=0,a=0,s=t+(r.drainArrivals?Math.max(0,Math.ceil(((e.lastArrival()??e.elapsed())-e.elapsed())/e.fixedDt)):0);for(;o+a<s&&!r.shouldStop?.()&&(!1===r.stopAtRest||e.queueSize()>0||!e.atRest()||r.continueWhile?.());){let t=e.nextArrival(),l=r.skipIdle&&null!=t&&e.atRest()?Math.min(Math.max(0,Math.floor((t-e.elapsed())/e.fixedDt)-1),Math.max(0,s-o-a-1)):0;l>0&&(e.advanceTime(l*e.fixedDt),a+=l),e.step(e.fixedDt),e.advanceTime(e.fixedDt);let c=e.drainEvents();i.events&&(i.events.push(...c),e.observeKernelEvents(c,i.observations),e.observeSensorTransitions(i.observations));let u=[];if(e.spawnDue(u,i.observations),u.length>0){i.spawned.push(...u),n=e.observeBodyBudget(i.observations);let t=e.evictOverflow(i.observations);i.evicted?.push(...t.evicted),i.sedimented?.push(...t.sedimented)}o+=1,e.refreshQuiescence(e.fixedDt,u.length),r.afterStep?.()}return{steps:o,budget:n}}var Ey=class{constructor(e={}){this.activeSensorPairs=/* @__PURE__ */new Set,this.accumulator=0,this.bodyBudgetObservationKey="ok",this.bodySpatialIndex=new cy,this.elapsedSeconds=0,this.liveBodyOrder=[],this.nextSequence=0,this.paused=!1,this.queue=[],this.revision=0,this.observedInitialBoundary=!1,this.updateResults=new is,this.simulationState="settled",this.visible=!0,this.quiescence=new Ty;let{bodyBudget:t,colliders:i,engine:r,kernel:n,observation:o,sediment:a,...s}=e;this.config={...qm,...s},this.configInput={...e},this.bodyBudget=t??{},this.engineInput=r,this.observation=Gm(o),this.sediment=new Dm(a??!1),this.world=_m(r,{fixedDt:this.config.fixedDt,...n}),this.quiescence.setKernelOptions(n),i&&this.world.setColliders(Jm(i))}updateConfig(e){let t=ky(e,this.configInput),{colliders:i,bodyBudget:r,engine:n,kernel:o,observation:a,sediment:s,...l}=e;if(this.config={...this.config,...l},void 0!==r&&(this.bodyBudget=r,!1===r&&(this.bodyBudgetObservationKey="ok")),n&&n!==this.engineInput){let e=this.world.snapshot();this.world.dispose(),this.engineInput=n,this.world=_m(n,e.options),this.world.restore(e),this.revision+=1}if(o&&!wy(o,this.configInput.kernel)){let e=this.world.snapshot(),t={...e.options,...o,gravity:{...e.options.gravity,...o.gravity}};this.world.restore({...e,options:t}),this.quiescence.setKernelOptions(t),this.revision+=1}a&&(this.observation=Gm(a,this.observation)),this.sediment.updateConfig(s),i&&(this.world.setColliders(Jm(i)),this.revision+=1),this.configInput={...this.configInput,...e};let c=by(t);this.updateResults.record({kind:"config",keys:t},c.invalidations)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setColliders(e){this.world.setColliders(Jm(e)),this.revision+=1,this.updateResults.record({kind:"config",keys:["colliders"]},by(["colliders"]).invalidations)}enqueue(e,t){let i=Array.isArray(e)?e:[e],r=t?Zm(i,{...t,startAt:t.startAt??this.elapsedSeconds}):i;for(let e of r)this.queue.push({...Vm(e),sequence:this.nextSequence,spawnAt:e.spawnAt??this.elapsedSeconds}),this.nextSequence+=1;this.queue.sort(ty),r.length>0&&(this.revision+=1),this.updateResults.record({kind:"enqueue",count:r.length},r.length?uy:[])}enqueueWithResult(e,t){return this.enqueue(e,t),this.updateResults.last}spawnNow(e){this.spawnOne(Vm(e)),this.nextSequence+=1,this.observeBodyBudget(),this.evictOverflow(),this.revision+=1,this.updateResults.record({kind:"enqueue",count:1},uy)}materializeDueSpawns(){let e=this.revision,t=[],i=[];return this.spawnDue(t,i),0===t.length||(this.observeBodyBudget(i),this.evictOverflow(i),this.syncSimulationState(i),this.revision+=1,this.updateResults.record({kind:"enqueue",count:t.length},this.revision!==e?uy:[])),t}clear(){this.observedInitialBoundary=!1;let e=this.world.snapshot().options;this.world.init({...e,fixedDt:this.config.fixedDt}),this.activeSensorPairs.clear(),this.liveBodyOrder=[],this.queue=[],this.accumulator=0,this.elapsedSeconds=0,this.nextSequence=0,this.quiescence.reset(),this.sediment.clear(),this.bodyBudgetObservationKey="ok",this.revision+=1,this.syncSimulationState(),this.updateResults.record({kind:"clear"},uy)}tick(e,t){let i=this.revision,r=[],n=[],o=[],a=[],s=[];if(this.paused||!this.visible){let e=this.result(0,r,n,o,a,s,!1);return this.updateResults.record({kind:"tick",count:0},[]),e}let l=Math.max(0,Math.min(Number.isFinite(e)?e:0,this.config.maxDeltaSeconds))*this.config.timeScale;this.spawnDue(r,s);let c=this.observeBodyBudget(s),u=this.evictOverflow(s);n.push(...u.evicted),o.push(...u.sedimented),this.syncSimulationState(s),r.length>0&&this.quiescence.reset(),this.accumulator+=l;let d=this.stepObserver(t,{spawned:r,evicted:n,sedimented:o,events:a,observations:s}),h=l>0?Math.floor((this.accumulator+1e-9*this.config.fixedDt)/this.config.fixedDt):0,{steps:f,budget:p}=Fy(this.settleHost(),Math.min(h,this.config.maxSubsteps),{spawned:r,evicted:n,sedimented:o,events:a,observations:s},{stopAtRest:!1,shouldStop:()=>this.paused||!this.visible,afterStep:d});this.accumulator=Math.max(0,this.accumulator-f*this.config.fixedDt),f===this.config.maxSubsteps&&(this.accumulator=Math.min(this.accumulator,this.config.fixedDt)),(f>0||r.length>0||n.length>0||o.length>0||a.length>0)&&(this.revision+=1);let g=this.result(f,r,n,o,a,s,void 0,p??c);return this.updateResults.record({kind:"tick",count:f},this.revision!==i?r.length||n.length||o.length?uy:dy:[]),g}settle(e){return this.runSettle(e,!1).steps}settleWithObservations(e,t){return this.runSettle(e,!0,t)}stepObserver(e,t){let i=!this.observedInitialBoundary;return e&&(this.observedInitialBoundary=!0),Ny(e,e=>(e&&(this.revision+=1),this.result(e,t.spawned,t.evicted,t.sedimented,t.events,t.observations)),i)}settleHost(){return{fixedDt:this.config.fixedDt,queueSize:()=>this.queue.length,atRest:()=>this.atRest(),elapsed:()=>this.elapsedSeconds,nextArrival:()=>this.queue[0]?.spawnAt,lastArrival:()=>this.queue.at(-1)?.spawnAt,advanceTime:e=>{this.elapsedSeconds+=e},spawnDue:(e,t)=>this.spawnDue(e,t),observeBodyBudget:e=>this.observeBodyBudget(e),evictOverflow:e=>this.evictOverflow(e),step:e=>this.world.step(e),drainEvents:()=>this.world.events(),observeKernelEvents:(e,t)=>this.observeKernelEvents(e,t),observeSensorTransitions:e=>this.observeSensorTransitions(e),refreshQuiescence:(e,t)=>this.quiescence.refresh(this.world,e,t)}}runSettle(e,t,i){let r=this.revision,n=[],o=[],a=[],s=[],l=t?[]:void 0;if(t&&(this.paused||!this.visible)){let e=this.result(0,n,o,a,s,l??[],!1);return this.updateResults.record({kind:"settle",count:0},[]),e}this.spawnDue(n,l);let c=this.observeBodyBudget(l),u=this.evictOverflow(l);o.push(...u.evicted),a.push(...u.sedimented),this.syncSimulationState(l),n.length>0&&this.quiescence.reset();let d=t?{spawned:n,evicted:o,sedimented:a,events:s,observations:l}:{spawned:n},h=this.stepObserver(i,{spawned:n,evicted:o,sedimented:a,events:s,observations:l??[]}),{steps:f,budget:p}=Fy(this.settleHost(),e??this.config.settleStepLimit,d,{afterStep:h,continueWhile:i?.continueWhile,shouldStop:t?()=>this.paused||!this.visible:void 0,drainArrivals:void 0===e,skipIdle:void 0===e&&!i}),g=n.length+o.length+a.length>0;(f>0||g||s.length>0)&&(this.revision+=1);let m=this.result(f,n,o,a,s,l??[],void 0,p??c);return this.updateResults.record({kind:"settle",count:f},this.revision===r?[]:g?uy:dy),m}readBodies(e=[]){return this.world.readState(e)}readSediment(){return this.sediment.snapshot()}bodyBudgetStatus(){return this.evaluateBodyBudget()}sedimentTotals(){return this.sediment.totals()}sedimentHeightfield(e={}){return Bm(this.readSediment(),e)}hitTest(e,t,i=0,r){return this.bodySpatialIndex.hitTest(this.world,this.revision,this.liveBodyOrder,e,t,i,r)}events(){return this.world.events()}allSleeping(){return this.world.allSleeping()}atRest(){return this.world.allSleeping()||this.quiescence.isAtRest()}hasPendingWork(){return this.queue.length>0||!this.atRest()}queueSize(){return this.queue.length}liveBodyCount(){return this.liveBodyOrder.length}elapsed(){return this.elapsedSeconds}recordObservation(e){let{timestamp:t,chartType:i,chartId:r,...n}=e,o={...n,timestamp:t??this.elapsedSeconds,chartType:i??this.observation.chartType,chartId:r??this.observation.chartId};return this.emitObservation(o),this.updateResults.record({kind:"update",count:1},["evidence"]),o}getLastUpdateResult(){return this.updateResults.last}getUpdateSnapshot(){return this.updateResults.last}subscribeUpdateResult(e){return this.updateResults.subscribe(e)}version(){return this.revision}setPaused(e){let t=this.paused!==e;this.paused=e,this.syncSimulationState(),this.updateResults.record({kind:"pause"},t?hy:[])}setVisible(e){let t=this.visible!==e;this.visible=e,this.syncSimulationState(),this.updateResults.record({kind:"visibility"},t?hy:[])}remove(e){let t=new Set(e),i=new Set(this.liveBodyOrder),r=new Set(this.queue.map(e=>e.id));this.queue=this.queue.filter(e=>!t.has(e.id)),this.liveBodyOrder=this.liveBodyOrder.filter(e=>!t.has(e)),this.world.remove(e),this.removeActiveSensorPairsForBodies(t);let n=e.filter(e=>i.has(e)||r.has(e));return n.length>0&&(this.revision+=1,this.syncSimulationState()),this.updateResults.record({kind:"remove",keys:n,count:n.length},n.length?uy:[]),n}setConstraint(e){let t=this.world.setConstraint(e);return this.revision+=1,this.updateResults.record({kind:"constraint",keys:[t]},dy),t}removeConstraint(e){this.world.removeConstraint(e),this.revision+=1,this.updateResults.record({kind:"constraint",keys:[e]},dy)}applyImpulse(e,t,i){this.world.applyImpulse(e,t,i),this.revision+=1,this.updateResults.record({kind:"impulse",keys:[e]},dy)}nextRandom(){return this.world.nextRandom()}controls(){return e=this,{applyImpulse:(t,i,r)=>e.applyImpulse(t,i,r),clear:()=>e.clear(),hitTest:(t,i,r)=>e.hitTest(t,i,r),pause:()=>e.setPaused(!0),push:(t,i)=>e.enqueue(t,i),pushMany:(t,i)=>e.enqueue(t,i),bodyBudgetStatus:()=>e.bodyBudgetStatus(),readBodies:t=>e.readBodies(t),readSediment:()=>e.readSediment(),recordObservation:t=>e.recordObservation(t),remove:t=>e.remove(t),restore:t=>e.restore(t),resume:()=>e.setPaused(!1),settle:t=>e.settle(t),settleWithObservations:t=>e.settleWithObservations(t),snapshot:()=>e.snapshot(),sedimentHeightfield:t=>e.sedimentHeightfield(t),sedimentTotals:()=>e.sedimentTotals(),step:t=>e.tick(t)};var e}snapshot(){let e=this.world.snapshot();return{accumulator:this.accumulator,activeSensorPairs:Array.from(this.activeSensorPairs).sort(),bodyBudget:ey(this.bodyBudget),config:{...this.config,kernel:iy(e.options)},elapsedSeconds:this.elapsedSeconds,paused:this.paused,queue:this.queue.map(Qm),revision:this.revision,sediment:this.readSediment(),simulationState:this.simulationState,liveBodyOrder:this.liveBodyOrder.slice(),visible:this.visible,world:e}}restore(e){this.observedInitialBoundary=!1;let t=this.simulationState;this.config={bodyLimit:e.config.bodyLimit,eviction:e.config.eviction,fixedDt:e.config.fixedDt,maxDeltaSeconds:e.config.maxDeltaSeconds,maxSubsteps:e.config.maxSubsteps,settleStepLimit:e.config.settleStepLimit,timeScale:e.config.timeScale},this.configInput={...e.config,bodyBudget:ey(e.bodyBudget??{}),kernel:iy(e.world.options)},this.bodyBudget=ey(e.bodyBudget??{}),this.bodyBudgetObservationKey="ok",this.quiescence.setKernelOptions(e.world.options),this.quiescence.reset(),this.activeSensorPairs=new Set(e.activeSensorPairs),this.accumulator=e.accumulator,this.elapsedSeconds=e.elapsedSeconds,this.paused=e.paused,this.queue=e.queue.map(Qm).sort(ty),this.revision=e.revision,this.sediment.restore(e.sediment??[]),this.simulationState=e.simulationState??$y(e.paused,e.visible,e.queue.length>0,e.world.bodies.every(e=>e.sleeping)),this.liveBodyOrder=e.liveBodyOrder.slice(),this.visible=e.visible,this.nextSequence=this.queue.reduce((e,t)=>Math.max(e,t.sequence),-1)+1,this.world.restore(e.world),this.updateResults.record({kind:"restore"},uy),this.simulationState!==t&&this.observation.onSimulationStateChange?.(this.simulationState,t)}spawnDue(e,t){for(;this.queue.length>0&&this.queue[0].spawnAt<=this.elapsedSeconds+1e-9*this.config.fixedDt;){let i=this.queue.shift();if(!i)return;this.spawnOne(i,t),e.push(i.id)}}spawnOne(e,t){this.liveBodyOrder=this.liveBodyOrder.filter(t=>t!==e.id),this.removeActiveSensorPairsForBodies(/* @__PURE__ */new Set([e.id])),this.world.spawn(e),this.liveBodyOrder.push(e.id);for(let t of e.springs??[])this.world.setConstraint({...t,bodyId:e.id});if(!t&&!this.observation.onObservation)return;let i=this.world.readState().find(t=>t.id===e.id);this.emitObservation({type:"physics-spawn",timestamp:this.elapsedSeconds,chartType:this.observation.chartType,chartId:this.observation.chartId,bodyId:e.id,datum:i?.datum??e.datum,x:i?.x??e.x,y:i?.y??e.y},t)}result(e,t,i,r,n,o,a,s=this.evaluateBodyBudget()){this.syncSimulationState(o);let l=this.world.allSleeping();return{budget:s,elapsedSeconds:this.elapsedSeconds,evicted:i,events:n,observations:o,queueSize:this.queue.length,revision:this.revision,shouldContinue:a??(!this.paused&&this.visible&&(this.queue.length>0||!this.atRest())),sleeping:l,sedimented:r,spawned:t,steps:e}}observeKernelEvents(e,t){Sy(this.world,e,this.observationContext(t))}observeSensorTransitions(e){this.activeSensorPairs=Ay(this.world,this.activeSensorPairs,this.observationContext(e))}removeActiveSensorPairsForBodies(e){My(this.activeSensorPairs,e)}observationContext(e){return{elapsedSeconds:this.elapsedSeconds,observation:this.observation,emit:t=>this.emitObservation(t,e)}}emitObservation(e,t){t?.push(e),this.observation.onObservation?.(e)}evaluateBodyBudget(){return Ym({bodyLimit:this.config.bodyLimit,engineMaxBodiesHint:this.world.capabilities.maxBodiesHint,evictionEnabled:!1!==this.config.eviction,liveBodies:this.liveBodyOrder.length,queuedBodies:this.queue.length,sedimentEnabled:this.sediment.isEnabled(),options:this.bodyBudget})}observeBodyBudget(e){let t=this.evaluateBodyBudget();if("ok"===t.state||!1===this.bodyBudget)return this.bodyBudgetObservationKey="ok",t;let i=`${t.state}:${t.action}`;return i===this.bodyBudgetObservationKey||(this.bodyBudgetObservationKey=i,Iy(t,this.observationContext(e))),t}syncSimulationState(e){let t=$y(this.paused,this.visible,this.queue.length>0,this.atRest());if(t===this.simulationState)return;let i=this.simulationState;this.simulationState=t,_y(i,t,this.observationContext(e))}evictOverflow(e){let{evicted:t,sedimented:i,liveBodyOrder:r}=Ry(this.world,this.sediment,this.config.eviction,this.config.bodyLimit,this.liveBodyOrder,this.observationContext(e));return t.length>0&&(this.liveBodyOrder=r,this.removeActiveSensorPairsForBodies(new Set(t))),{evicted:t,sedimented:i}}};function Oy(e){let{data:t,valueAccessor:i,bins:r,ballRadius:n,seed:o,size:a,valueExtent:s}=e,{rows:l}=Dg(t,"galton"),c=Ig(a),u=l.map((e,t)=>Tg(Cg(e,t,i))).filter(e=>null!=e),d=Eg(s),[h,f]=d??(u.length?yr(u):[0,1]),p=f===h?1:f-h,g=Bg().domain([0,r]).range([c.plot.x,c.plot.x+c.plot.width]),m=Array.from({length:r},()=>0),y=[];l.forEach((e,t)=>{let o=Tg(Cg(e,t,i));if(null==o)return;let a=Math.max(0,Math.min(r-1,Math.floor((o-h)/p*r)));m[a]+=1,y.push({id:String(e.id??`galton-${t}`),x:g(a+.5),y:c.plot.y+n+2,vx:8*(t%5-2),vy:0,mass:1,shape:{type:"circle",radius:n},datum:{...e,value:o,bin:a}})});let x=c.plot.y+c.plot.height;return{config:Rg(o,[...ay({x:c.plot.x,y:c.plot.y,width:c.plot.width,height:c.plot.height},{idPrefix:"galton",wallThickness:20,floorThickness:20}),...sy({idPrefix:"galton-bin",count:r,domainStart:0,domainStep:1,xScale:g,yTop:c.plot.y-400,yBottom:x,wallThickness:6})],"GaltonBoardChart"),initialSpawns:y,initialSpawnPacing:{pacing:{ratePerSec:55}},projectionRows:m.map((e,t)=>({label:String(t+1),value:e})),metadata:{kind:"galton-board",bins:r,plot:c.plot,valueExtent:[h,f]}}}import{scaleLinear as zy}from"d3-scale";function Dy(e){let{windowSize:t,watermark:i,watermarkAtArrivalAccessor:r}=e;if(!(Number.isFinite(t)&&t>0))throw new RangeError("EventDrop windows.size must be a finite positive number");let{rows:n}=Dg(e.data,"event"),o=n.flatMap((t,i)=>{let r=Tg(Cg(t,i,e.timeAccessor));return null==r?[]:[{datum:t,index:i,eventTime:r,arrivalTime:Tg(Cg(t,i,e.arrivalAccessor))??r,watermarkAtArrival:0,late:!1}]}),a="function"==typeof i?null:Tg(i?.value),s="function"==typeof i?t:Tg(i?.delay)??t,l=-1/0,c=-1/0;for(let e of o.slice().sort((e,t)=>e.arrivalTime-t.arrivalTime||e.index-t.index)){l=Math.max(l,e.eventTime);let n="function"==typeof i?Tg(i(l)):l-s;c=a??Math.max(c,n??l-t);let o=r?Tg(Cg(e.datum,e.index,r)):null;e.watermarkAtArrival=o??c;let u=(Math.floor(e.eventTime/t)+1)*t;e.late=u<=e.watermarkAtArrival}return{events:o,watermarkValue:o.length?c:a??-s}}function By(e,t){let i=Math.max(5*t,Math.min(92,.13*e.plot.width));return{gutter:{x:e.plot.x,y:e.plot.y,width:i,height:e.plot.height},windowPlot:{x:e.plot.x+i,y:e.plot.y,width:Math.max(40,e.plot.width-i),height:e.plot.height},wallTop:e.plot.y+.48*e.plot.height}}function jy(e,t){let i=Math.max(0,Math.min(e.windowCount,e.closedWindowCount));if(!i)return[];let r=e.windowStart,n=e.windowStart+e.windowCount*e.windowSize,o=zy().domain([r,n]).range([e.windowPlot.x,e.windowPlot.x+e.windowPlot.width]),a=o(e.windowStart+i*e.windowSize),s=e.windowPlot.x,l=Math.max(18,Math.min(.3*e.windowPlot.height,a-s)),c=t+l,u=e=>a===s?t:c+(e-s)/(a-s)*(t-c),d=[];for(let t=0;t<i;t+=1){let i=e.windowStart+t*e.windowSize,r=i+e.windowSize,n=o(i),a=o(r);d.push({id:`eventdrop-lid-${t}`,windowIndex:t,x1:n,y1:u(n),x2:a,y2:u(a)})}return d}function Wy(e){let{count:t,idPrefix:i,wallThickness:r,xScale:n,yBottom:o,yTop:a,yTopForIndex:s}=e;return Array.from({length:t+1},(e,t)=>{let l=Math.min(o-1,s?.(t)??a),c=Math.max(1,o-l);return{id:`${i}-wall-${t}`,shape:{type:"aabb",x:n(t),y:l+c/2,width:r,height:c}}})}function Yy(e){let{data:t,timeAccessor:i,arrivalAccessor:r,windows:n,watermark:o,watermarkAtArrivalAccessor:a,ballRadius:s,seed:l,size:c,timeExtent:u,timeScale:d=1}=e,{events:h,watermarkValue:f}=Dy({data:t,timeAccessor:i,arrivalAccessor:r,watermark:o,watermarkAtArrivalAccessor:a,windowSize:n.size}),p=Ig(c),g=h.length?1/0:0,m=h.length?1/0:0,y=h.length?-1/0:n.size;for(let e of h)g=Math.min(g,e.arrivalTime),m=Math.min(m,e.eventTime),y=Math.max(y,e.eventTime);let x=Tg(u?.[0]),b=Tg(u?.[1]),v=Math.min(x??m,m),w=Math.max(b??y,y),k=Math.floor(v/n.size)*n.size,S=Math.max(1,Math.ceil((w-k+n.size)/n.size)),A=By(p,s),M=k+S*n.size,$=zy().domain([k,M]).range([A.windowPlot.x,A.windowPlot.x+A.windowPlot.width]),_=0,I=Array.from({length:S},(e,t)=>(k+(t+1)*n.size<=f&&_++,{value:0,secondary:0})),P=[];h.forEach(({datum:e,index:t,eventTime:i,arrivalTime:r,watermarkAtArrival:o,late:a})=>{let l=Math.max(0,Math.min(S-1,Math.floor((i-k)/n.size)));I[l].value+=a?0:1,I[l].secondary+=a?1:0,P.push({id:String(e.id??`event-${t}`),x:Xy(i,l,a,{windowStart:k,windowSize:n.size,gutter:A.gutter,closedWindowCount:_,windowPlot:A.windowPlot,windowCount:S},s),y:p.plot.y+s+2,vx:0,vy:0,mass:1,friction:.02,spawnAt:r,shape:{type:"circle",radius:s},datum:{...e,eventTime:i,arrivalTime:r,windowIndex:l,watermarkAtArrival:o,late:a}})});let L=p.plot.y+p.plot.height,R=p.plot.y+.28*p.plot.height,C={closedWindowCount:_,gutter:A.gutter,plot:p.plot,windowCount:S,windowPlot:A.windowPlot,windowSize:n.size,windowStart:k},T=jy(C,R);for(let e of P){let t=e.datum;e.y=qy({...C,lidSegments:T},t.windowIndex,t.late,s)}let N=e=>{if(e<0||e>_)return null;let t=0===e?T[0]?.y1:T[e-1]?.y2??T[e]?.y1;return"number"==typeof t&&Number.isFinite(t)?t:null},F=Wy({idPrefix:"eventdrop-window",count:S,xScale:e=>$(k+e*n.size),yTop:A.wallTop,yTopForIndex:e=>{let t=N(e);return null==t?A.wallTop:t+1.25*s},yBottom:L,wallThickness:6});return{config:Rg(l,[...ay({x:p.plot.x,y:p.plot.y,width:p.plot.width,height:p.plot.height},{idPrefix:"eventdrop",wallThickness:20,floorThickness:20}),...F,...T.map(e=>({id:e.id,shape:{type:"segment",x1:e.x1,y1:e.y1,x2:e.x2,y2:e.y2,thickness:Math.max(4,.42*s)},friction:.02,restitution:.01}))],"EventDropChart",{friction:.08}),initialSpawns:P,initialSpawnPacing:{pacing:"arrival",timeAccessor:e=>{let t=e.datum,i=t.windowIndex<_;return i&&!t.late||!i&&t.late?g:t.arrivalTime},timeScale:d},projectionRows:I.map((e,t)=>({label:`${k+t*n.size}-${k+(t+1)*n.size}`,value:e.value,secondary:e.secondary})),metadata:{kind:"event-drop",closedWindowCount:_,gutter:A.gutter,lidSegments:T,lateCount:I.reduce((e,t)=>e+t.secondary,0),plot:p.plot,windowPlot:A.windowPlot,windowWalls:F.map(({id:e,shape:t})=>({id:e,x:t.x-t.width/2,y:t.y-t.height/2,width:t.width,height:t.height})),watermarkValue:f,windowCount:S,windowSize:n.size,windowStart:k}}}function qy(e,t,i,r){let{windowPlot:n,lidSegments:o}=e,a=o[t];return i&&!a?Math.min(n.y+n.height-r,n.y+.48*n.height+2*r+4):!i&&a?Math.min(n.y+n.height-r,Math.max(a.y1,a.y2)+2*r+4):n.y+r+2}function Xy(e,t,i,r,n){let{windowPlot:o,windowCount:a,windowStart:s,windowSize:l}=r;if(i&&t>=r.closedWindowCount)return r.gutter.x+r.gutter.width/2;let c=o.width/a,u=i?o.x:o.x+t*c,d=i?o.x+o.width:u+c,h=Math.min((d-u)/2,n+(i?0:3)),f=o.x+(e-s)/l*c;return Math.max(u+h,Math.min(d-h,f))}function Gy(e={}){let t=(e.categories?.length?e.categories:["Intake","Review","Build","Ship"]).map(e=>String(e).trim()).filter(Boolean),i=t.length?t:["Intake"],r=Math.max(i.length,Math.round(e.count??Math.max(48,12*i.length))),n=Fg(e.unitValue,1),o=_g(e.seed??1),a=e.idPrefix??"mechanical-pile",s=i.map(()=>.65+.9*o()),l=s.reduce((e,t)=>e+t,0)||1,c=r-i.length,u=s.map(e=>e/l*c),d=u.map(e=>1+Math.floor(e)),h=r-d.reduce((e,t)=>e+t,0),f=u.map((e,t)=>({index:t,fraction:e-Math.floor(e)})).sort((e,t)=>t.fraction-e.fraction);for(let e=0;h>0;e=(e+1)%f.length)d[f[e].index]+=1,h-=1;return i.map((e,t)=>({id:`${a}-${t}`,category:e,value:d[t]*n,mechanical:!0,unitCount:d[t],unitValue:n,share:d[t]/r}))}function Vy(e,t){let i=e/t,r=Math.round(i);return Math.ceil(r>0&&Math.abs(i-r)<=Number.EPSILON*i*4?r:i)}function Hy(e,t,i){let r=Math.max(1,t),n=e.width/r,o=Math.max(2,2*i),a=Math.min(.7*n,Math.max(3.2*o,o+8)),s=Math.max(1,Math.floor(a/o));return{laneWidth:n,tubeWidth:a,ballDiameter:o,perRow:s,centerX:t=>e.x+(t+.5)*n,pileHeight:e=>Math.ceil(Math.max(0,e)/s)*o}}function Uy(e){let{data:t,categoryAccessor:i,valueAccessor:r,unitValue:n,ballRadius:o,seed:a,size:s}=e,l=Fg(n,1),{rows:c}=Dg(t,"pile"),u=Ig(s),d=[],h=/* @__PURE__ */new Map,f=/* @__PURE__ */new Map,p=[];function g(e){let t=h.get(e);return null==t&&(t=d.length,d.push(e),h.set(e,t)),t}c.forEach((e,t)=>{g(String(Cg(e,t,i)??"unknown"))});let m=Math.max(1,d.length),y=Hy(u.plot,m,o),x=Math.max(0,y.tubeWidth/2-o-1),b=d.map(()=>[]);c.forEach((e,t)=>{let n=String(Cg(e,t,i)??"unknown"),a=g(n),s=r?Tg(Cg(e,t,r)):1,c=Math.max(0,s??0);f.set(n,(f.get(n)??0)+c);let d=Vy(c,l),h=y.centerX(a);for(let i=0;i<d;i+=1){let r=b[a].length,s=i===d-1?c-i*l:l,f=Math.min(1,s/l),p=y.perRow>1?r%y.perRow:0,g=y.perRow>1?(p/(y.perRow-1)*2-1)*x:0;b[a].push({id:`${String(e.id??`pile-${t}`)}-${i}`,x:h+g,y:u.plot.y+o+2,vx:(i%3-1)*o/2,vy:0,mass:1,shape:{type:"circle",radius:o*Math.sqrt(f)},datum:{...e,category:n,unitIndex:i,unitValue:l,representedValue:s,unitFraction:f}})}});let v=b.reduce((e,t)=>Math.max(e,t.length),0);for(let e=0;e<v;e+=1)for(let t of b)e<t.length&&p.push(t[e]);let w=u.plot.y+u.plot.height,k=[...ay({x:u.plot.x,y:u.plot.y,width:u.plot.width,height:u.plot.height},{idPrefix:"pile",wallThickness:20,floorThickness:20})],S=u.plot.y-400;for(let e=0;e<m;e+=1){let t=y.centerX(e);for(let i of[-1,1])k.push({id:`pile-tube-${e}-${i<0?"l":"r"}`,shape:{type:"aabb",x:t+i*(y.tubeWidth+6)/2,y:(S+w)/2,width:6,height:w-S}})}return{config:Rg(a,k,"UnitPileChart"),initialSpawns:p,initialSpawnPacing:{pacing:{ratePerSec:20}},projectionRows:d.map(e=>({label:e,value:f.get(e)??0}))}}import{scaleLinear as Ky}from"d3-scale";function Zy(e,t,i,r){let n=(t+i)/2,o=[];for(let a of e){let s=o.filter(e=>Math.abs(a.x-e.x)<a.radius+e.radius+.5),l=[n];for(let e of s){let t=a.radius+e.radius+.5,i=Math.sqrt(t**2-(a.x-e.x)**2);l.push(e.y-i,e.y+i)}let c=r()<.5?-1:1;l.sort((e,t)=>Math.abs(e-n)-Math.abs(t-n)||c*(e-t));let u=l.find(e=>e-a.radius>=t&&e+a.radius<=i&&s.every(t=>(a.x-t.x)**2+(e-t.y)**2>=(a.radius+t.radius+.5)**2-1e-6));if(null==u){let r=e.reduce((e,t)=>Math.max(e,t.radius),-1/0),o=Math.max(0,i-t-2*r);return{positions:e.map((t,i)=>n+(1===e.length?0:i/(e.length-1)-.5)*o),overlapping:!0,entryOffset:0}}o.push({...a,y:u})}return{positions:o.map(e=>e.y),overlapping:!1,entryOffset:Math.max(0,o.reduce((e,i)=>Math.min(e,i.y-i.radius-t),36))}}function Qy(e){let{data:t,xAccessor:i,groupAccessor:r,radiusAccessor:n,pointRadius:o,seed:a,size:s,xExtent:l,collisionIterations:c,settle:u}=e,{rows:d}=Dg(t,"collision-swarm"),h=Ig(s),f=_g(a),p=[],g=[],m=/* @__PURE__ */new Map;function y(e){let t=m.get(e);return null==t&&(t=g.length,g.push(e),m.set(e,t)),t}d.forEach((e,t)=>{let a=Tg(Cg(e,t,i));if(null==a)return;let s=r?String(Cg(e,t,r)??"All"):"All",l=n?Tg(Cg(e,t,n)):null,c=Ng(null!=l&&l>0?l:o,2,18);y(s),p.push({datum:e,index:t,value:a,group:s,radius:c})});let x=l?Tg(l[0]):null,b=l?Tg(l[1]):null,v=p.reduce((e,t)=>Math.min(e,t.value),p.length?1/0:0),w=p.reduce((e,t)=>Math.max(e,t.value),p.length?-1/0:1),k=x??v,S=b??w;if(k===S&&(k-=.5,S+=.5),k>S){let e=S;S=k,k=e}let A=p.reduce((e,t)=>Math.max(e,t.radius),o),M=h.plot.x+A+8,$=h.plot.x+h.plot.width-A-8,_=Ky().domain([k,S]).range([M,$]),I=Math.max(1,g.length),P=h.plot.height/I,L=Math.min(6,.05*P),R=e=>h.plot.y+((m.get(e)??0)+.5)*P,C=/* @__PURE__ */new Map,T=/* @__PURE__ */new Set,N=/* @__PURE__ */new Map;for(let e of g){let t=p.filter(t=>t.group===e),i=R(e),r=t.map(e=>({x:_(e.value),radius:e.radius})),n=Zy(r,i-P/2+L,i+P/2-L,f);C.set(e,t.length),n.overlapping&&T.add(e),t.forEach((e,t)=>N.set(e.index,{x:r[t].x,y:n.positions[t],entryOffset:n.entryOffset}))}let F=p.map((e,t)=>{let i=N.get(e.index),r=i.x,n=i.y,o=T.has(e.group);return{id:String(e.datum.id??`collision-swarm-${t}`),x:r,y:n-(u?0:i.entryOffset),vx:0,vy:0,fixedPosition:{x:r},bodyCollisions:!o,mass:1,shape:{type:"circle",radius:e.radius},datum:{...e.datum,xValue:e.value,group:e.group,radius:e.radius,targetX:r,targetY:n,overlapping:o},springs:[{target:{type:"point",x:r,y:n},restLength:0,stiffness:34,damping:12}]}});return{config:Rg(a,ay({x:h.plot.x,y:h.plot.y,width:h.plot.width,height:h.plot.height},{idPrefix:"collision-swarm",includeCeiling:!1,wallThickness:20,floorThickness:20}),"CollisionSwarmChart",{gravity:{x:0,y:0},cellSize:Math.max(24,4*A),collisionIterations:Math.max(1,Math.round(c??6)),velocityDamping:.992,restitution:.02,friction:.18,sleepSpeed:3,sleepAfter:.5}),initialSpawns:F,projectionRows:g.map(e=>({label:e,value:C.get(e)??0})),metadata:{kind:"collision-swarm",xExtent:[k,S],xRange:[M,$],groups:g.map(e=>({label:e,y:R(e),count:C.get(e)??0,overlapping:T.has(e)})),plot:h.plot}}}function Jy(e){if(Array.isArray(e)&&e.length>=2){let t=Tg(e[0]),i=Tg(e[1]);return null!=t&&null!=i?{x:t,y:i}:null}if(e&&"object"==typeof e){let t=e,i=Tg(t.x),r=Tg(t.y);return null!=i&&null!=r?{x:i,y:r}:null}return null}function ex(e){return Array.isArray(e)?e.map(Jy).filter(e=>null!=e):[]}function tx(e,t){return"normalized"===e||"pixels"===e?e:t.length>0&&t.every(e=>e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1)?"normalized":"pixels"}function ix(e,t,i){return"normalized"===i?{x:t.plot.x+e.x*t.plot.width,y:t.plot.y+e.y*t.plot.height}:{x:Ng(e.x,t.plot.x,t.plot.x+t.plot.width),y:Ng(e.y,t.plot.y,t.plot.y+t.plot.height)}}function rx(e){let t=0;for(let i=1;i<e.length;i+=1){let r=e[i].x-e[i-1].x,n=e[i].y-e[i-1].y;t+=Math.hypot(r,n)}return t}function nx(e,t){if(0===e.length)return{x:0,y:0};if(1===e.length)return{...e[0]};let i=Ng(t,0,1)*rx(e),r=0;for(let t=1;t<e.length;t+=1){let n=e[t-1],o=e[t],a=Math.hypot(o.x-n.x,o.y-n.y);if(!(a<=0)){if(r+a>=i){let e=(i-r)/a;return{x:n.x+(o.x-n.x)*e,y:n.y+(o.y-n.y)*e}}r+=a}}return{...e[e.length-1]}}function ox(e,t){let i=nx(e,Math.max(0,t-.02)),r=nx(e,Math.min(1,t+.02)),n=r.x-i.x,o=r.y-i.y,a=Math.hypot(n,o)||1;return{x:n/a,y:o/a}}function ax(e){let{coordinateMode:t,flowSpeed:i,links:r,maxParticles:n,nodeIdAccessor:o,nodeXAccessor:a,nodeYAccessor:s,nodes:l,particleRadius:c,particleRate:u,pathAccessor:d,pathConstraint:h="path",reducedMotion:f,seed:p,size:g,sourceAccessor:m,targetAccessor:y,throughputAccessor:x}=e,b=Ig(g),v=_g(p),w=/* @__PURE__ */new Map,k=/* @__PURE__ */new Map,S=[];function A(e){if(e&&"object"==typeof e){let t=e;if("function"==typeof o){let e=o(t,0);if(null!=e)return String(e)}if("string"==typeof o&&null!=t[o])return String(t[o]);if(null!=t.id)return String(t.id)}return String(e??"unknown")}l.forEach((e,t)=>{let i=String(Cg(e,t,o)??e.id??t),r=Tg(Cg(e,t,a)),n=Tg(Cg(e,t,s));if(null!=r&&null!=n){let e={x:r,y:n};w.set(i,e),S.push(e)}k.set(i,String(e.label??e.name??i))});let M=[];r.forEach((e,t)=>{let i=A(Cg(e,t,m)),r=A(Cg(e,t,y)),n=Math.max(0,Tg(Cg(e,t,x))??0),o=ex(d?Cg(e,t,d):void 0),a=o.length?o:ex(e.path??e.points??e.route);a.forEach(e=>S.push(e)),M.push({id:String(e.id??`physical-flow-${i}-${r}-${t}`),link:e,index:t,source:i,target:r,throughput:n,rawPath:a})});let $=tx(t,S),_=/* @__PURE__ */new Map;for(let[e,t]of w)_.set(e,ix(t,b,$));let I=[];for(let e of M){let t=e.rawPath.map(e=>ix(e,b,$));if(t.length>=2)_.has(e.source)||_.set(e.source,t[0]),_.has(e.target)||_.set(e.target,t[t.length-1]);else{let i=_.get(e.source),r=_.get(e.target);i&&r&&(t=[i,r])}t.length<2||e.throughput<=0||(k.has(e.source)||k.set(e.source,e.source),k.has(e.target)||k.set(e.target,e.target),I.push({...e,path:t,packetCount:0}))}let P=Fg(u,.12),L=Math.max(1,Math.round(n)),R=I.map(e=>Math.max(1,Math.round(e.throughput*P))),C=R.reduce((e,t)=>e+t,0),T=C>L?L/C:1;I.forEach((e,t)=>{e.packetCount=Math.max(1,Math.floor(R[t]*T))});let N=I.reduce((e,t)=>e+t.packetCount,0);for(;N>L;){let e=I.reduce((e,t,i)=>t.packetCount<=1?e:-1===e||t.packetCount>I[e].packetCount?i:e,-1);if(-1===e)break;I[e].packetCount-=1,N-=1}let F=/* @__PURE__ */new Map,E=/* @__PURE__ */new Map,O=[],z=Fg(i,90),D=Fg(c,4);I.forEach((e,t)=>{F.set(e.target,(F.get(e.target)??0)+e.throughput),E.set(e.source,(E.get(e.source)??0)+e.throughput);let i=rx(e.path);for(let r=0;r<e.packetCount;r+=1){let n=(r+.5)/e.packetCount,o=f?n:Ng(.12+.84*n+.04*(v()-.5),.04,.98),a=f?o:Math.max(0,o-(.18+.12*v())),s=nx(e.path,a),l=nx(e.path,o),c=ox(e.path,a),u={x:-c.y,y:c.x},d=(v()-.5)*D*1.5,p=`${e.id}-packet-${r}`;O.push({id:p,x:s.x+u.x*d,y:s.y+u.y*d,vx:f?0:c.x*z+10*(v()-.5),vy:f?0:c.y*z+10*(v()-.5),mass:.8,spawnAt:f?0:.04*t+r/32,shape:{type:"circle",radius:D},datum:{...e.link,source:e.source,target:e.target,throughput:e.throughput,packetIndex:r,packetCount:e.packetCount,routeProgress:o,flowPath:e.path,flowPathLength:i,flowRouteId:e.id,flowSpeed:z,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target},springs:"none"!==h&&f?[{target:{type:"point",x:l.x,y:l.y},restLength:.7*D,stiffness:26,damping:4.25}]:void 0})}});let B=Math.max(18,5*D),j=Array.from(_,([e,t])=>({nodeId:e,label:k.get(e)??e,sensorId:`physical-flow-node-${Og(e)}`,point:t})),W=j.map(e=>({id:e.sensorId,sensor:!0,shape:{type:"aabb",x:e.point.x,y:e.point.y,width:B,height:B}})),Y=Object.fromEntries(j.map(e=>[e.sensorId,{binId:e.label,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),q=Rg(p,[...ay({x:b.plot.x,y:b.plot.y,width:b.plot.width,height:b.plot.height},{idPrefix:"physical-flow",wallThickness:18,floorThickness:18}),...W],"PacketFlowChart",{gravity:{x:0,y:0},cellSize:Math.max(24,7*D),collisionIterations:3,velocityDamping:.994,restitution:.01,friction:.16,sleepSpeed:2.5,sleepAfter:.7});q.bodyLimit=L,q.eviction="oldest",q.observation={...q.observation,sensors:Y};let X=Array.from(_,([e,t])=>({id:e,label:k.get(e)??e,x:t.x,y:t.y,sensorId:`physical-flow-node-${Og(e)}`,incoming:F.get(e)??0,outgoing:E.get(e)??0})),G=I.map(e=>({id:e.id,source:e.source,target:e.target,sourceLabel:k.get(e.source)??e.source,targetLabel:k.get(e.target)??e.target,throughput:e.throughput,packetCount:e.packetCount,path:e.path}));return{config:q,initialSpawns:O,projectionRows:X.filter(e=>e.incoming>0||e.outgoing>0).map(e=>({label:e.label,value:e.incoming,secondary:e.outgoing})),metadata:{kind:"physical-flow",coordinateMode:$,particleCount:O.length,totalThroughput:I.reduce((e,t)=>e+t.throughput,0),plot:b.plot,nodes:X,links:G}}}function sx(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function lx(e,t){let i=t instanceof Set?t:new Set(t);return e.map(e=>{let t=e.bodyIds??[],r=t.filter(e=>!i.has(e)),n=t.length-r.length,o=e.completion?.mode??"allMembersAbsorbed",a=e.completion?.valueByBodyId,s=e=>{let t=a?sx(a,e):void 0;return"number"==typeof t&&Number.isFinite(t)&&t>=0?t:1},l=t.reduce((e,t)=>e+s(t),0),c=t.reduce((e,t)=>e+(i.has(t)?s(t):0),0),u=e.completion?.threshold,d="threshold"===o?Number.isFinite(u)&&Number(u)>=0?Number(u):l:void 0,h=t.length>0&&("anyAbsorbed"===o?n>0:"threshold"===o?c>=(d??l):0===r.length);return{id:e.id,label:e.label??e.id,mode:o,complete:h,absorbed:n,total:t.length,absorbedValue:c,totalValue:l,threshold:d,missing:r}})}function cx(e){let t=e.reduce((e,t)=>e+(t.share??1),0);return t>0?t:e.length}function ux(e,t,i,r,n,o={}){return{id:e,friction:o.friction,restitution:o.restitution,bodyFilter:o.bodyFilter,shape:{type:"segment",x1:t,y1:i,x2:r,y2:n,thickness:o.thickness??8}}}function dx(e,t,i,r){return{type:"aabb",x:e,y:t,width:i,height:r}}function hx(e){let t=e.shape??"lane",i=Math.max(1,Math.round(e.width)),r=Math.max(1,Math.round(e.height)),n=e.padX??46,o=e.padY??72,a=n,s=i-n,l=o,c=r-Math.max(24,Math.round(.45*o)),u=(l+c)/2,d=Math.max(1,c-l),h=mu(e.pinchRatio??.18,.06,.5),f=Number(e.pinchHeightOffset??0),p=Number.isFinite(f)?f:0,g=mu(d*h+p,.06*d,.5*d),m=g/2,y=u-m,x=u+m,b=e.idPrefix??"process",v=e.friction??.58,w=e.restitution??.18,k=e.wallThickness??8,S=e.stages;if(!S.length)throw new Error("processStageLayout requires at least one stage");let A=mu(e.centerStageIndex??Math.floor(S.length/2),0,S.length-1),M=cx(S),$=s-a,_=a,I=S.map((e,t)=>{let i=(e.share??1)/M*$,r=_,n=t===S.length-1?s:_+i;return _=n,{id:e.id,label:e.label,description:e.description,kind:e.kind??"stage",index:t,x0:r,x1:n,x:(r+n)/2,width:n-r,y:u,height:d}}),P=I[A],L=P.x0,R=P.x1,C=(e,i)=>{if("lane"===t)return"top"===i?l:c;if("funnel"===t){let t=mu((e-a)/Math.max(1,s-a),0,1);return"top"===i?l+(y-l)*t:c+(x-c)*t}if(e<=L){let t=mu((e-a)/Math.max(1,L-a),0,1);return"top"===i?l+(y-l)*t:c+(x-c)*t}if(e<=R)return"top"===i?y:x;let r=mu((e-R)/Math.max(1,s-R),0,1);return"top"===i?y+(l-y)*r:x+(c-x)*r},T=I.map(e=>{let t=Math.min(C(e.x0,"top"),C(e.x1,"top")),i=Math.max(C(e.x0,"bottom"),C(e.x1,"bottom"));return{...e,y:(t+i)/2,height:Math.max(1,i-t)}}),N={thickness:k,friction:v,restitution:w},F=[];"lane"===t?F.push(ux(`${b}-top`,a,l,s,l,N),ux(`${b}-bottom`,a,c,s,c,N),ux(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,k-2)}),ux(`${b}-right`,s,l,s,c,{...N,thickness:Math.max(6,k)})):"funnel"===t?F.push(ux(`${b}-top`,a,l,s,y,N),ux(`${b}-bottom`,a,c,s,x,N),ux(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,k-2)}),ux(`${b}-right`,s,y,s,x,{...N,thickness:Math.max(6,k)})):F.push(ux(`${b}-left-top`,a,l,L,y,N),ux(`${b}-left-bottom`,a,c,L,x,N),ux(`${b}-center-top`,L,y,R,y,N),ux(`${b}-center-bottom`,L,x,R,x,N),ux(`${b}-right-top`,R,y,s,l,N),ux(`${b}-right-bottom`,R,x,s,c,N),ux(`${b}-left`,a,l,a,c,{...N,thickness:Math.max(6,k-2)}),ux(`${b}-right`,s,l,s,c,{...N,thickness:Math.max(6,k)}));let E=e.membraneDampingScale??.5,O=a,z=Math.max(1,("bowtie"===t?L:s)-O),D=(e.membranes??[]).map(e=>{let t=O+mu(e.offset,0,1)*z,i=e.width??18+18*e.cost,r=d-16,n=u+.25*(e.wobble??0);return{...e,x:t,y:n,width:i,height:r}}),B=!1===e.includeMembraneRegions?[]:D.map(e=>gx({id:e.id,label:e.label??e.id,description:e.description??`${e.label??e.id} is a permeable region. It taxes energy and damps velocity while bodies overlap it.`,x:e.x,y:e.y,width:e.width,height:e.height,cost:e.cost,dampingScale:e.dampingScale??E,bodyStyle:e.bodyStyle,metadata:e.metadata,semanticItem:e.semanticItem,color:e.color}));return{shape:t,width:i,height:r,padX:n,padY:o,left:a,right:s,topY:l,bottomY:c,midY:u,centerLeft:L,centerRight:R,pinchHeight:g,pinchTop:y,pinchBottom:x,stages:T,membranes:D,colliders:F,regionEffects:B,boundaryY:C}}function fx(e,t,i){return"function"==typeof t?r=>({...i,...t(r),primitive:e}):{...i,...t,primitive:e}}function px(e,t,i,r){return{id:e.id,label:e.label,description:e.description,kind:e.kind??t,shape:dx(e.x,e.y,e.width,e.height),bodyFilter:e.bodyFilter,collider:e.collider,colliderThickness:e.colliderThickness,friction:e.friction,restitution:e.restitution,semanticItem:e.semanticItem,metadata:e.metadata,bodyStyle:e.bodyStyle,attributes:i?fx(i,e.attributes,r):e.attributes,onEnter:e.onEnter,onExit:e.onExit}}function gx(e){let t=e.dampingScale??.5,i=e.energyScale??1,r=mu(e.cost,0,2);return{...px(e,"membrane","membrane",{membraneCost:r}),damping:r*t,energyDelta:-r*i}}function mx(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:12,y:0};return{...px(e,"force-field","routeSurface"),force:t,damping:e.damping??.015}}function yx(e){let t=e.pressure??e.occupancy??0,i=e.baseDamping??.08,r=e.dampingPerUnit??.12,n=e.energyPerUnit??0;return{...px(e,"membrane","pressureField",{pressure:t}),damping:i+t*r,energyDelta:n?-t*n:void 0,force:e.force}}function xx(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force;return{...px(e,"force-field","capacitatedSensor",{capacity:e.capacity,unitsPerSecond:e.unitsPerSecond??e.capacity}),force:t,damping:e.damping,charge:e.charge??e.capacity}}function bx(e){return{...px(e,"force-field","portal",{targetStage:e.targetStage}),force:e.force,impulseOnEnter:e.impulseOnEnter,damping:e.damping??.08}}function vx(e){let t="number"==typeof e.force?{x:e.force,y:0}:e.force??{x:24,y:0};return{...px(e,"sink","absorb"),force:t,damping:e.damping??.02,charge:e.charge??"absorbed"}}function wx(e){return{...px(e,"force-field","forceField"),force:e.force,damping:e.damping,energyDelta:e.energyDelta}}function kx(e){let t=e.x??e.anchor?.x??0,i=e.y??e.anchor?.y??0;return{id:e.id,label:e.label,description:e.description,group:e.group,bodyIds:e.bodyIds,datum:e.datum,state:e.state,x:t,y:i,width:e.width,height:e.height,anchor:e.anchor??{x:t,y:i},completion:e.completion,tether:e.tether,semanticItem:e.semanticItem}}function Sx(e){let t=e.idPrefix??"lane",i={thickness:e.thickness??8,friction:e.friction??.5,restitution:e.restitution??.16},r=[ux(`${t}-top`,e.left,e.top,e.right,e.top,i),ux(`${t}-bottom`,e.left,e.bottom,e.right,e.bottom,i)];return e.openEnds||r.push(ux(`${t}-left`,e.left,e.top,e.left,e.bottom,i),ux(`${t}-right`,e.right,e.top,e.right,e.bottom,i)),r}function Ax(e,t=12){return"number"==typeof e?{x:e,y:0}:e&&"object"==typeof e?{x:Number.isFinite(e.x)?Number(e.x):t,y:Number.isFinite(e.y)?Number(e.y):0}:{x:t,y:0}}function Mx(e,t){let i={id:`process-stage-${e.id}`,label:e.label??e.id,description:e.description,x:t.x,y:t.y,width:Math.max(12,.92*t.width),height:Math.max(40,.88*t.height),semanticItem:!1,attributes:{stageId:e.id}};if(e.absorb)return vx({...i,kind:e.kind??"sink",force:Ax(e.force,28),damping:e.damping??.04,charge:"absorbed",attributes:{...i.attributes,primitive:"absorb"}});if(e.portal){let t=e.portal.force??e.force??{x:-40,y:0};return bx({...i,kind:e.kind??"force-field",force:Ax(t,-40),damping:e.damping??.1,targetStage:e.portal.targetStageId,attributes:{...i.attributes,primitive:"portal",targetStage:e.portal.targetStageId}})}if(e.capacity){let t=Math.max(.1,e.capacity.unitsPerSecond);return xx({...i,kind:e.kind??"force-field",capacity:t,unitsPerSecond:t,force:Ax(e.force,10+.8*t),damping:e.damping??Math.max(.04,.32-.01*t),attributes:{...i.attributes,unitAccessor:e.capacity.unitAccessor,reviewerCapacity:t}})}if(e.pressure){let t="object"==typeof e.pressure&&e.pressure?e.pressure:{};return yx({...i,kind:e.kind??"membrane",pressure:t.pressure,occupancy:t.occupancy,baseDamping:t.baseDamping??e.damping??.1,dampingPerUnit:t.dampingPerUnit??.1,energyPerUnit:t.energyPerUnit??0,force:Ax(e.force,8),attributes:{...i.attributes,primitive:"pressureField"}})}return null!=e.force||null!=e.damping?mx({...i,kind:e.kind??"force-field",force:Ax(e.force,14),damping:e.damping??.02,attributes:{...i.attributes,primitive:"routeSurface"}}):wx({...i,kind:e.kind??"force-field",force:{x:10,y:0},damping:.02,attributes:{...i.attributes,primitive:"forceField"}})}function $x(e){let t=e.stages;if(!t.length)throw new Error("buildProcessFlowPhysics requires at least one stage");let i=e.size,r=Ig(i),n=Ng(e.ballRadius??6,2,18),o=e.seed??1,a=_g(o),s=e.idAccessor,l=e.stageAccessor??"stage",c=e.groupBy,u=e.groupLabelAccessor,d=e.workAccessor,h=e.radiusAccessor,f=e.groupCompletion??(c?"allAbsorbed":"none"),p=e.springStiffness??.28,g=e.springDamping??.72,m=!0===e.settle,y=t.map(e=>({id:e.id,label:e.label??e.id,description:e.description,share:e.share})),x=hx({width:i[0],height:i[1],shape:"lane",padX:Math.max(28,r.plot.x),padY:Math.max(36,r.plot.y+8),stages:y,idPrefix:"process-flow",includeMembraneRegions:!1,friction:.48,restitution:.14}),b=new Map(x.stages.map((e,t)=>[e.id,t])),v=new Map(x.stages.map(e=>[e.id,e])),w=x.stages[0].id,k=x.stages[0],S=new Set(t.filter(e=>e.absorb).map(e=>e.id)),A=t.map(e=>{let t=v.get(e.id)??k;return Mx(e,{x:t.x,y:x.midY,width:t.width,height:x.bottomY-x.topY})});A.unshift(mx({id:"process-flow-route",label:"process route",description:"Baseline conveyor along the process lane.",x:(x.left+x.right)/2,y:x.midY,width:x.right-x.left,height:x.bottomY-x.topY-12,force:8,damping:.012,semanticItem:!1}));let M=/* @__PURE__ */new Map;for(let e of x.stages)M.set(e.id,0);let $=[];e.data.forEach((e,t)=>{let i=String(s?Cg(e,t,s)??e.id??`process-flow-${t}`:e.id??`process-flow-${t}`),r=String(Cg(e,t,l)??w),o=b.has(r)?r:w;M.set(o,(M.get(o)??0)+1);let a=c?String(Cg(e,t,c)??""):void 0,f=a&&u?String(Cg(e,t,u)??a):a,p=d?Tg(Cg(e,t,d))??1:1,g=h?Tg(Cg(e,t,h)):null,m=Ng(null!=g&&g>0?g:n,2,18);$.push({datum:e,id:i,stageId:o,groupId:a||void 0,groupLabel:f||void 0,work:p,radius:m,index:t})});let _=/* @__PURE__ */new Map,I=/* @__PURE__ */new Map;for(let e of $){if(!e.groupId)continue;let t=_.get(e.groupId)??[];t.push(e.id),_.set(e.groupId,t),e.groupLabel&&I.set(e.groupId,e.groupLabel)}let P=Ng(e.groupAnchorAlong??.55,.15,.9),L=x.left+(x.right-x.left)*P,R=Array.from(_.keys()),C=R.map((e,i)=>{let r=_.get(e)??[],n=R.length<=1?x.midY:x.topY+28+i/Math.max(1,R.length-1)*(x.bottomY-x.topY-56);return kx({id:e,label:I.get(e)??e,bodyIds:r,anchor:{x:L,y:n},x:L,y:n,completion:"allAbsorbed"===f?{mode:"allMembersAbsorbed",targetZone:t.find(e=>e.absorb)?.id??"merged"}:void 0,tether:{stiffness:.06,visible:!0,restLength:18}})}),T=lx(C,$.filter(e=>S.has(e.stageId)).map(e=>e.id)),N=new Map(C.map(e=>[e.id,e])),F=$.map((e,t)=>{let i=v.get(e.stageId)??k,r=i.x+(a()-.5)*Math.min(24,.2*i.width),n=x.boundaryY(r,"top")+e.radius+10,o=x.boundaryY(r,"bottom")-e.radius-10,s=o<=n?x.midY:n+a()*Math.max(1,o-n),l=m?r:x.left+18+t%7*4,c=m?s:x.midY+(a()-.5)*(x.bottomY-x.topY)*.35,u=[{target:{type:"point",x:r,y:s},restLength:.45*e.radius,stiffness:p,damping:g}];if(e.groupId){let t=N.get(e.groupId);t?.anchor&&!S.has(e.stageId)&&u.push({target:{type:"point",x:t.anchor.x,y:t.anchor.y},restLength:t.tether?.restLength??22,stiffness:t.tether?.stiffness??.05,damping:.8})}return{id:e.id,x:l,y:c,vx:m?0:40+40*a(),vy:m?0:20*(a()-.5),mass:1,shape:{type:"circle",radius:e.radius},spawnAt:m?0:.03*t,springs:u,datum:{...e.datum,id:e.id,stage:e.stageId,groupId:e.groupId,groupLabel:e.groupLabel,work:e.work,__processFlow:!0}}}),E={kernel:{seed:o,gravity:{x:e.gravityX??22,y:e.gravityY??0},restitution:.14,friction:.48,velocityDamping:.988,maxVelocity:420,sleepSpeed:8,sleepAfter:.9,collisionIterations:4},colliders:x.colliders,fixedDt:1/60,maxSubsteps:8},O=x.stages.map(e=>({label:e.label??e.id,value:M.get(e.id)??0})),z=t.map(e=>{let t=v.get(e.id)??k;return{id:e.id,label:e.label??e.id,x:t.x,width:t.width,count:M.get(e.id)??0,capacity:e.capacity?.unitsPerSecond,absorb:!0===e.absorb,portalTarget:e.portal?.targetStageId}});return{config:E,initialSpawns:F,initialSpawnPacing:m?void 0:{pacing:"arrival",timeAccessor:"spawnAt",timeScale:1},projectionRows:O,metadata:{kind:"process-flow",plot:r.plot,volume:x,stages:z,groups:C,groupCompletion:T,regionEffects:A}}}import{scaleLinear as _x}from"d3-scale";function Ix(e,t,i){return Mi(e,t,i)}function Px(e,t){let i=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0;return 0===e.length?e=>i&&Ri(i,e)||"#4e79a7":t=>{if(i){let e=Ri(i,t);if(e)return e}let r=0;for(let e=0;e<t.length;e++)r=31*r+t.charCodeAt(e)|0;return e[Math.abs(r)%e.length]??"#4e79a7"}}function Lx(e,t,i){let r=e?.observation;return{...e,observation:{...r,chartId:t??r?.chartId??"physics-custom",chartType:r?.chartType??"PhysicsCustomChart",onObservation:i??r?.onObservation}}}function Rx(e,t){let i=t.config??{},r=(t.sensors??[]).map(e=>({...e,sensor:!0})),n=[...t.colliders??[],...r],o=[...e.colliders??[],...i.colliders??[],...n];return{...e,...i,observation:{...e.observation,...i.observation},...o.length>0&&{colliders:o}}}function Cx(e,t){if(!t?.length)return e;let i=/* @__PURE__ */new Map;for(let e of t){let{bodyId:t,...r}=e,n=i.get(t)??[];n.push(r),i.set(t,n)}return e.map(e=>{let t=i.get(e.id);return t?.length?{...e,springs:[...e.springs??[],...t]}:e})}function Tx(e){let t=Lx(e.config,e.chartId,e.onObservation),i=Ix(e.colorScheme,e.themeCategorical,oi),r=Ig(e.size),n={data:e.data,scales:{x:_x().domain(e.xExtent??[0,1]).range([r.plot.x,r.plot.x+r.plot.width]),y:_x().domain(e.yExtent??[0,1]).range([r.plot.y+r.plot.height,r.plot.y])},dimensions:r,theme:{semantic:e.semantic,categorical:[...i]},resolveColor:Px(i,e.colorScheme),config:e.layoutConfig??{},world:new Ey(t)},o=e.skipLayout?{}:e.layout(n)??{},a=Cx([...o.initialSpawns??o.bodies??[]],o.constraints);return{config:Rx(t,o),context:n,initialSpawnPacing:o.initialSpawnPacing,initialSpawns:a,result:o}}function Nx(e){let t=Bx(e);return[{id:"gauntlet-left",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:t.left,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-ceiling",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:t.top,x2:e.width-t.rightInset,y2:t.top,thickness:t.thickness}},{id:"gauntlet-floor",restitution:.12,friction:.42,shape:{type:"segment",x1:t.left,y1:e.floorY,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}},{id:"gauntlet-right",restitution:.12,friction:.42,shape:{type:"segment",x1:e.width-t.rightInset,y1:t.top,x2:e.width-t.rightInset,y2:e.floorY,thickness:t.thickness}}]}function Fx(e,t,i,r){return i?"function"==typeof i?i(e,t):e[i]??r:r}function Ex(e){return`gauntlet:${e}:core`}function Ox(e,t){return`gauntlet:${e}:positive:${t}`}function zx(e,t,i){return`gauntlet:${e}:negative:${t}:${i}`}var Dx={left:28,top:76,rightInset:30,thickness:8};function Bx(e){let t=e.height??e.floorY+36;if(!(e.width<220||t<160))return Dx;let i=Math.max(1,Math.min(e.width,t)),r=Math.max(2,.04*e.width);return{left:r,top:Math.max(2,.08*t),rightInset:r,thickness:Math.max(1,Math.min(4,.04*i))}}function jx(e){let t=e.height??e.floorY+36;return Math.max(.12,Math.min(1,e.width/500,t/260))}function Wx(e,t,i,r){let n=Bx(r),o=Math.max(2,i+2),a=n.left+n.thickness/2+o,s=r.width-n.rightInset-n.thickness/2-o,l=n.top+n.thickness/2+o,c=r.floorY-o,u=(e,t,i)=>t<=i?Math.max(t,Math.min(i,e)):(t+i)/2;return{x:u(e,a,s),y:u(t,l,c)}}function Yx(e,t,i){let[r,n]=e,o=r<220||n<160,a=Math.round(.48*n),s=o?n-Math.max(3,Math.min(12,.1*n)):n-36,l=(t??[]).filter(e=>!1!==e.enabled),c=Math.max(1,l.length),u=.22*r,d=c<=1?0:(.78*r-u)/(c-1),h=o?Math.max(Math.round(.12*r),.08*r+6):Math.max(Math.round(.14*r),110);return{crashY:s-(o?Math.min(i,Math.max(3,.22*n)):i),floorY:s,gates:l.map((e,t)=>({...e,id:e.id,x:e.x??Math.round(u+t*d),width:e.width??Math.max(o?8:54,Math.round(.07*r))})),graveyardX:Math.round(r*(o?.72:.84)),graveyardY:s-4,height:n,routeY:a,socketX:Math.round(r*(o?.82:.92)),startX:h,width:r}}function qx(e){return{graveyardX:e.graveyardX,graveyardY:e.graveyardY,routeY:e.routeY,socketX:e.socketX,socketY:e.routeY-4,startX:e.startX,startY:e.routeY}}function Xx(e,t,i,r){let n=qx(i),o=r?.(e,t,i)??{};return{...n,...o,startY:o.startY??o.routeY??n.startY,socketY:o.socketY??o.routeY??n.socketY,graveyardY:o.graveyardY??n.graveyardY}}function Gx(e,t,i=1){let r=[...e].sort((e,t)=>e.localeCompare(t)),n=Math.max(0,r.indexOf(t)),o=r.length>1?n/(r.length-1):.5;return{angle:.82*-Math.PI+o*Math.PI*.64,index:n,radius:(48+n%2*6)*i}}function Vx(e,t,i){let r=e.activePositiveIds.reduce((e,i)=>e+(t.get(i)?.value??1),0),n=e.missingPositiveIds.length+e.poppedPositiveIds.length,o=e.negativeIds.reduce((e,t)=>e+(i.get(t)?.load??1),0);return Math.max(0,Math.min(100,75+3*r-8*o-1.2*e.delay-5*n))}function Hx(e,t,i,r,n){let o=String(Fx(e,t,i.idAccessor,null!=e.id?String(e.id):`project-${t}`)),a=r.map(e=>e.id),s=[...Fx(e,t,i.positiveAccessor,a)],l=[...Fx(e,t,i.negativeAccessor,[])].filter(e=>n.has(e));return{id:o,activePositiveIds:s,datum:e,delay:0,eventsApplied:[],eventHistory:[],killed:!1,metrics:{...Fx(e,t,i.metricsAccessor,{})},missingPositiveIds:a.filter(e=>!s.includes(e)),negativeIds:l,outcome:"in_process",poppedPositiveIds:[],poppedNegativeIds:[],startedAt:Math.max(0,Number(Fx(e,t,i.startTimeAccessor,0))||0),stage:"project filed",viability:Fx(e,t,i.initialViability,100)}}function Ux(e,t,i,r,n,o,a){let s=jx(i),l=Math.max(3,28*s),c=r.startX,u=r.startY+(r.startY===i.routeY?38*t*s:0),d=a?.(e,t,i,r)??{},h=d.x??c,f=d.y??u,p={__gauntlet:!0,kind:"gauntlet-core",projectId:e.id,sourceDatum:e.datum},g=[{...d,id:Ex(e.id),x:h,y:f,vx:d.vx??42,vy:d.vy??0,mass:d.mass??7,bodyCollisions:d.bodyCollisions??!0,shape:d.shape??{type:"circle",radius:l},spawnAt:d.spawnAt??e.startedAt,datum:p}],m=Wx(h,f,d.shape&&"radius"in d.shape&&Number(d.shape.radius)||l,i);g[0].x=m.x,g[0].y=m.y;for(let t of e.activePositiveIds){let r=n.get(t);if(!r)continue;let o=Gx(e.activePositiveIds,t,s),a=r.radius??Math.max(2,10*s),l=Wx(m.x+Math.cos(o.angle)*o.radius,m.y+Math.sin(o.angle)*o.radius,a,i);g.push({id:Ox(e.id,t),x:l.x,y:l.y,vx:18*Math.cos(o.angle),vy:18*Math.sin(o.angle),mass:r.mass??.75,bodyCollisions:!1,shape:{type:"circle",radius:a},spawnAt:d.spawnAt??e.startedAt,datum:{__gauntlet:!0,kind:"gauntlet-positive",projectId:e.id,property:r,sourceDatum:e.datum},springs:!1===r.spring?[]:[{target:{type:"body",bodyId:Ex(e.id)},stiffness:.56,damping:.9,restLength:Math.max(6,(52+o.index%2*4)*s),...r.spring??{}}]})}return e.negativeIds.forEach((t,r)=>{let n=o.get(t);n&&g.push(Zx(e,n,r,m.x,m.y,i,d.spawnAt??e.startedAt))}),g}function Kx(e){let t=Yx(e.size??[900,520],e.gates,e.crashOffset??30),i=e.positiveProperties??[],r=new Map(i.map(e=>[e.id,e])),n=new Map((e.negativeProperties??[]).map(e=>[e.id,e])),o={idAccessor:e.idAccessor,initialViability:e.initialViability,metricsAccessor:e.metricsAccessor,negativeAccessor:e.negativeAccessor,positiveAccessor:e.positiveAccessor,startTimeAccessor:e.startTimeAccessor},a=(e.data??[]).map((t,a)=>{let s=Hx(t,a,o,i,n);return{...s,viability:e.viability?.(s,{negativeProperties:n,positiveProperties:r})??Vx(s,r,n)}}),s=a.flatMap((i,o)=>{let a=Xx(i,o,t,e.projectPlacement);return Ux(i,o,t,a,r,n,e.coreBody)});return{layout:t,states:a,initialSpawns:s,config:{fixedDt:1/60,maxSubsteps:8,kernel:{gravity:{x:0,y:0},restitution:.16,friction:.44,velocityDamping:.982,maxVelocity:520,sleepAfter:.8,sleepSpeed:7},colliders:Nx(t)}}}function Zx(e,t,i,r,n,o,a){let s=jx(o),l=t.radius??Math.max(2,7.2*s),c=Wx(r+(i%4*12-12)*s,n+(54+12*Math.floor(i/4))*s,l,o);return{id:zx(e.id,t.id,i),x:c.x,y:c.y,vx:10,vy:6,mass:t.mass??.72,bodyCollisions:!1,shape:{type:"circle",radius:l},spawnAt:a,datum:{__gauntlet:!0,kind:"gauntlet-negative",projectId:e.id,property:t,sourceDatum:e.datum},springs:!1===t.spring?[]:[{target:{type:"body",bodyId:Ex(e.id)},stiffness:.62,damping:.92,restLength:Math.max(6,(52+i%4*3)*s),...t.spring??{}}]}}function Qx(e=[]){let t=/* @__PURE__ */Object.create(null);for(let[i,r]of e)t[i]=r;return t}function Jx(...e){let t=Qx();for(let i of e)for(let[e,r]of Object.entries(i??{}))t[e]=r;return t}function eb(e){return Jx(e)}function tb(e){return e.map(e=>({...e,sourceIds:e.sourceIds?[...e.sourceIds]:void 0,productIds:e.productIds?[...e.productIds]:void 0,relationIds:e.relationIds?[...e.relationIds]:void 0,outletIds:e.outletIds?[...e.outletIds]:void 0}))}function ib(e){let t=Qx(Object.entries(e.components).map(([e,t])=>[e,{...t,initialMetrics:eb(t.initialMetrics),metrics:eb(t.metrics),productIds:[...t.productIds],history:tb(t.history)}])),i=Qx(Object.entries(e.products).map(([e,t])=>[e,{...t,metrics:eb(t.metrics),sourceIds:[...t.sourceIds],history:tb(t.history)}])),r=Qx(Object.entries(e.relations).map(([e,t])=>[e,{...t,sourceIds:[...t.sourceIds],metrics:t.metrics?eb(t.metrics):void 0}]));return{...e,eventsApplied:[...e.eventsApplied],components:t,products:i,relations:r,input:{amount:e.input.amount,metrics:eb(e.input.metrics)},metrics:eb(e.metrics),loss:{amount:e.loss.amount,metrics:eb(e.loss.metrics)},history:tb(e.history)}}var rb=1e-9;function nb(e,t){return e<t?-1:e>t?1:0}function ob(e,t,i,r,n){return{severity:e,code:t,message:i,path:r,ids:n?[...n]:void 0}}function ab(e){let t=/* @__PURE__ */new Set,i=/* @__PURE__ */new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(nb)}function sb(e,t){return e?Object.entries(e).flatMap(([e,i])=>Number.isFinite(i)?[]:[ob("error","invalid-metric",`Metric "${e}" must be a finite number.`,`${t}.${e}`)]):[]}function lb(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}function cb(e){let t=Qx();for(let i of e)lb(t,i.metrics);return t}function ub(e,t,i="selector"){let r=[],n=Object.values(e.components),o=new Set(n.map(e=>e.id)),a=(t.ids??[]).filter(e=>!o.has(e));if(a.length&&r.push(ob("error","unknown-component",`Selector references unknown component id${1===a.length?"":"s"}: ${a.join(", ")}.`,`${i}.ids`,a)),void 0!==t.count&&(!Number.isInteger(t.count)||t.count<0)&&r.push(ob("error","invalid-selector-count","Selector count must be a non-negative integer.",`${i}.count`)),r.some(e=>"error"===e.severity))return{ids:[],diagnostics:r};let s=t.ids?new Set(t.ids):null,l=t.categories?new Set(t.categories):null,c=t.statuses?new Set(t.statuses):null,u=t.outletIds?new Set(t.outletIds):null,d=n.filter(e=>!s||s.has(e.id)).filter(e=>!l||l.has(e.category)).filter(e=>!c||c.has(e.status)).filter(e=>!u||void 0!==e.outletId&&u.has(e.outletId)).map(e=>e.id).sort(nb);return void 0!==t.count&&(d=d.slice(0,t.count)),d.length||r.push(ob("warning","empty-selector","Selector matched no source components.",i)),{ids:d,diagnostics:r}}function db(e,t,i={}){return{eventId:e.event.id,effectType:t.type,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,label:e.event.label,summary:e.event.summary,...i}}function hb(e,t){let i={...t,eventId:e.event.id};e.materializations.push(i),e.observations.push({...i,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt})}function fb(e,t,i){return!(void 0!==t&&!e.outletIds.has(t)&&(e.diagnostics.push(ob("error","unknown-outlet",`Unknown outlet "${t}".`,i,[t])),1))}function pb(e,t,i){let r=ab(t);t.length||e.diagnostics.push(ob("error","empty-source-list","A product requires at least one source component.",i)),r.length&&e.diagnostics.push(ob("error","duplicate-source",`Source ids may appear only once: ${r.join(", ")}.`,i,r));let n=t.filter(t=>!e.state.components[t]);n.length&&e.diagnostics.push(ob("error","unknown-component",`Unknown source component id${1===n.length?"":"s"}: ${n.join(", ")}.`,i,n));let o=t.filter(t=>(e.state.components[t]?.productIds.length??0)>0);o.length&&e.diagnostics.push(ob("error","source-already-assigned",`Source component${1===o.length?" is":"s are"} already assigned: ${o.join(", ")}.`,i,o));let a=t.filter(t=>"consumed"===e.state.components[t]?.status&&!o.includes(t));return a.length&&e.diagnostics.push(ob("error","source-unavailable",`Consumed source component${1===a.length?" is":"s are"} unavailable: ${a.join(", ")}.`,i,a)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function gb(e,t,i){let r=ab(t),n=t.filter(t=>!e.state.components[t]);return t.length<2&&e.diagnostics.push(ob("error","insufficient-relation-sources","A relation requires at least two source components.",i)),r.length&&e.diagnostics.push(ob("error","duplicate-source",`Relation source ids must be unique: ${r.join(", ")}.`,i,r)),n.length&&e.diagnostics.push(ob("error","unknown-component",`Relation references unknown source component${1===n.length?"":"s"}: ${n.join(", ")}.`,i,n)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.components[t])}function mb(e,t,i,r,n){let o=r?.amount??0;(!Number.isFinite(o)||o<0||o>t+rb)&&e.diagnostics.push(ob("error","invalid-loss","Loss amount must be finite, non-negative, and no greater than its sources.",`${n}.amount`)),e.diagnostics.push(...sb(r?.metrics,`${n}.metrics`));for(let[t,o]of Object.entries(r?.metrics??{}))(o<0||o>Number(i[t]??0)+rb)&&e.diagnostics.push(ob("error","invalid-metric-loss",`Metric loss "${t}" must be non-negative and no greater than its sources.`,`${n}.metrics.${t}`));return!e.diagnostics.some(e=>"error"===e.severity)}function yb(e,t,i,r){if(!t?.length)return[];let n=ab(t),o=t.filter(t=>!e.state.relations[t]),a=t.filter(t=>"resolved"===e.state.relations[t]?.status),s=new Set(i),l=t.filter(t=>(e.state.relations[t]?.sourceIds??[]).some(e=>!s.has(e)));return n.length&&e.diagnostics.push(ob("error","duplicate-relation","Basis relations must be unique.",r,n)),o.length&&e.diagnostics.push(ob("error","unknown-relation",`Unknown basis relation: ${o.join(", ")}.`,r,o)),a.length&&e.diagnostics.push(ob("error","resolved-relation",`Basis relation is already resolved: ${a.join(", ")}.`,r,a)),l.length&&e.diagnostics.push(ob("error","relation-source-mismatch",`Basis relation includes a source outside this product: ${l.join(", ")}.`,r,l)),e.diagnostics.some(e=>"error"===e.severity)?null:t.map(t=>e.state.relations[t])}function xb(e,t){if(t.length){for(let i of t)i.status="resolved",i.resolution="combined",i.resolvedByEventId=e.event.id,i.resolvedAt=e.context.appliedAt;hb(e,{type:"resolve-relation",relationIds:t.map(e=>e.id)})}}function bb(e,t,i){e.state.loss.amount+=i?.amount??0;for(let[r,n]of Object.entries(i?.metrics??{}))t[r]=Number(t[r]??0)-n,e.state.loss.metrics[r]=Number(e.state.loss.metrics[r]??0)+n}function vb(e,t,i,r,n,o,a){let s=o&&void 0!==e.amount?e.amount:i;return{id:e.id,label:e.label??e.id,description:e.description,category:e.category??"product",color:e.color,order:e.order,declaredAmount:e.amount,amount:s,metrics:o&&e.metrics?Jx(r,e.metrics):eb(r),status:o?"complete":"forming",sourceIds:[...t],outletId:o?e.outletId??(n.outletIds.has("product")?"product":void 0):void 0,createdByEventId:n.event.id,createdAt:n.context.appliedAt,completedByEventId:o?n.event.id:void 0,completedAt:o?n.context.appliedAt:void 0,history:[a]}}function wb(e,t,i,r){void 0!==t.amount&&Math.abs(t.amount-i)>rb&&e.diagnostics.push(ob("warning","declared-product-amount-mismatch",`Product "${t.id}" declares ${t.amount}, while its sources yield ${i}.`,r,[t.id]))}function kb(e,t,i,r,n,o){let a=e.productDefinitions.get(t.id),s=i??a?.outletId??(e.outletIds.has("product")?"product":void 0);if(!fb(e,s,`${o}.outletId`))return;if("complete"===t.status)return void e.diagnostics.push(ob("error","product-already-complete",`Product "${t.id}" is already complete.`,o,[t.id]));a&&(wb(e,a,t.amount,`${o}.productId`),void 0!==a.amount&&(t.amount=a.amount),a.metrics&&(t.metrics=Jx(t.metrics,a.metrics))),t.status="complete",t.outletId=s,t.reason=r,t.completedByEventId=e.event.id,t.completedAt=e.context.appliedAt;let l=db(e,n,{sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:s?[s]:void 0});t.history.push(l),e.state.history.push(l),hb(e,{type:"complete-product",sourceIds:[...t.sourceIds],productIds:[t.id],outletIds:s?[s]:void 0})}function Sb(e,t,i){let r=`events.${e.event.id}.effects.${i}`,n=e.state;if("set-state"===t.type){["queued","active","transformed","retained","ejected","failed","recovered"].includes(t.state)||e.diagnostics.push(ob("error","invalid-component-state",`set-state cannot assign "${String(t.state)}".`,`${r}.state`)),e.diagnostics.push(...sb(t.metricsDelta,`${r}.metricsDelta`)),fb(e,t.outletId,`${r}.outletId`);let i=ub(n,t.select,`${r}.select`);e.diagnostics.push(...i.diagnostics);let o=i.ids.filter(e=>n.components[e].productIds.length);if(o.length&&e.diagnostics.push(ob("error","source-already-assigned",`Assigned source components cannot be retargeted: ${o.join(", ")}.`,`${r}.select`,o)),e.diagnostics.some(e=>"error"===e.severity))return;let a=db(e,t,{sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0});for(let e of i.ids){let i=n.components[e];i.status=t.state,i.outletId=t.outletId,i.reason=t.reason,t.metricsDelta&&lb(i.metrics,t.metricsDelta),i.history.push(a)}return n.history.push(a),void(i.ids.length&&hb(e,{type:"retarget-component",sourceIds:i.ids,outletIds:t.outletId?[t.outletId]:void 0}))}if("set-relation"===t.type){let{relation:i}=t;(!i.id||n.relations[i.id])&&e.diagnostics.push(ob("error","duplicate-relation",`Relation id "${i.id}" is missing or already active.`,`${r}.relation.id`,[i.id]));let o=gb(e,i.sourceIds,`${r}.relation.sourceIds`);if(e.diagnostics.push(...sb(i.metrics,`${r}.relation.metrics`)),!o||e.diagnostics.some(e=>"error"===e.severity))return;n.relations[i.id]={...i,sourceIds:[...i.sourceIds],metrics:i.metrics?eb(i.metrics):void 0,status:"active",createdByEventId:e.event.id,createdAt:e.context.appliedAt};let a=db(e,t,{sourceIds:[...i.sourceIds],relationIds:[i.id]});return n.history.push(a),void hb(e,{type:"activate-relation",sourceIds:[...i.sourceIds],relationIds:[i.id]})}if("resolve-relation"===t.type){let i=ab(t.relationIds),o=t.relationIds.filter(e=>!n.relations[e]),a=t.relationIds.filter(e=>"resolved"===n.relations[e]?.status);if(i.length&&e.diagnostics.push(ob("error","duplicate-relation","Relation ids must be unique.",`${r}.relationIds`,i)),o.length&&e.diagnostics.push(ob("error","unknown-relation",`Unknown relation: ${o.join(", ")}.`,`${r}.relationIds`,o)),a.length&&e.diagnostics.push(ob("error","resolved-relation",`Relation is already resolved: ${a.join(", ")}.`,`${r}.relationIds`,a)),e.diagnostics.some(e=>"error"===e.severity))return;for(let i of t.relationIds){let r=n.relations[i];r.status="resolved",r.resolution=t.resolution,r.resolvedByEventId=e.event.id,r.resolvedAt=e.context.appliedAt,r.reason=t.reason}let s=db(e,t,{relationIds:[...t.relationIds]});return n.history.push(s),void hb(e,{type:"resolve-relation",relationIds:[...t.relationIds]})}if("combine"===t.type||"contribute"===t.type){let i=e.productDefinitions.get(t.productId);i||e.diagnostics.push(ob("error","unknown-product",`Product "${t.productId}" has no declared mold.`,`${r}.productId`,[t.productId]));let o=n.products[t.productId];"combine"===t.type&&o&&e.diagnostics.push(ob("error","duplicate-product",`Product "${t.productId}" has already been formed.`,`${r}.productId`,[t.productId])),"contribute"===t.type&&(!o||"forming"!==o.status)&&e.diagnostics.push(ob("error","product-not-forming",`Contributions require an existing forming product "${t.productId}".`,`${r}.productId`,[t.productId]));let a=pb(e,t.sourceIds,`${r}.sourceIds`),s="contribute"===t.type&&o?[...o.sourceIds,...t.sourceIds]:t.sourceIds,l=yb(e,t.basisRelationIds,s,`${r}.basisRelationIds`);if(!a||!l||!i||e.diagnostics.some(e=>"error"===e.severity))return;let c=a.reduce((e,t)=>e+t.amount,0),u=cb(a);if(!mb(e,c,u,t.loss,`${r}.loss`))return;let d=c-(t.loss?.amount??0);bb(e,u,t.loss);let h,f="combine"===t.type&&!1!==t.complete,p=db(e,t,{sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0});if("combine"===t.type){if(f&&wb(e,i,d,`${r}.productId`),h=vb(i,t.sourceIds,d,u,e,f,p),f&&!fb(e,h.outletId,`${r}.productId`))return;n.products[t.productId]=h}else h=o,h.sourceIds.push(...t.sourceIds),h.amount+=d,lb(h.metrics,u),h.history.push(p);for(let e of a)e.productIds=[t.productId],e.status="consumed",e.outletId=void 0,e.history.push(p);return n.history.push(p),xb(e,l),hb(e,{type:"combine"===t.type?"form-product":"update-product",sourceIds:[...t.sourceIds],productIds:[t.productId],relationIds:t.basisRelationIds?[...t.basisRelationIds]:void 0,outletIds:h.outletId?[h.outletId]:void 0}),void(f&&hb(e,{type:"complete-product",sourceIds:[...h.sourceIds],productIds:[h.id],outletIds:h.outletId?[h.outletId]:void 0}))}if("complete-product"===t.type){let i=n.products[t.productId];return i?void kb(e,i,t.outletId,t.reason,t,r):void e.diagnostics.push(ob("error","unknown-product-state",`Product "${t.productId}" has not been formed.`,`${r}.productId`,[t.productId]))}if("split"===t.type){let i=pb(e,[t.sourceId],`${r}.sourceId`);t.products.length||e.diagnostics.push(ob("error","empty-split","A split requires at least one product allocation.",`${r}.products`));let o=t.products.map(e=>e.productId),a=ab(o);a.length&&e.diagnostics.push(ob("error","duplicate-product","Split product ids must be unique.",`${r}.products`,a));let s=o.map(t=>e.productDefinitions.get(t)),l=o.filter((e,t)=>!s[t]),c=o.filter(e=>n.products[e]);l.length&&e.diagnostics.push(ob("error","unknown-product",`Split references undeclared product molds: ${l.join(", ")}.`,`${r}.products`,l)),c.length&&e.diagnostics.push(ob("error","duplicate-product",`Split products already exist: ${c.join(", ")}.`,`${r}.products`,c));for(let[i,n]of t.products.entries())void 0!==n.amount&&(!Number.isFinite(n.amount)||n.amount<0)&&e.diagnostics.push(ob("error","invalid-product-amount","Split allocation amounts must be finite and non-negative.",`${r}.products.${i}.amount`)),e.diagnostics.push(...sb(n.metrics,`${r}.products.${i}.metrics`));if(!i?.length||e.diagnostics.some(e=>"error"===e.severity))return;let u=i[0];if(!mb(e,u.amount,u.metrics,t.loss,`${r}.loss`))return;let d=u.amount-(t.loss?.amount??0),h=t.products.map((e,t)=>e.amount??s[t]?.amount),f=h.filter(e=>void 0!==e).length;if(0!==f&&f!==h.length)return void e.diagnostics.push(ob("error","partial-split-allocation","Either every split product must declare an amount or none may do so.",`${r}.products`));let p=f?h:t.products.map(()=>d/t.products.length),g=p.reduce((e,t)=>e+t,0);if(Math.abs(g-d)>rb)return void e.diagnostics.push(ob("error","split-amount-mismatch",`Split allocations total ${g}, but ${d} remains after loss.`,`${r}.products`));let m=eb(u.metrics);for(let[e,i]of Object.entries(t.loss?.metrics??{}))m[e]=Number(m[e]??0)-i;let y=db(e,t,{sourceIds:[u.id],productIds:o});if(t.products.forEach((i,o)=>{let a=s[o],l=d>rb?p[o]/d:1/t.products.length,c=Qx(Object.entries(m).map(([e,t])=>[e,t*l])),h=i.metrics??a.metrics??c,f=vb({...a,amount:p[o],metrics:h},[u.id],p[o],eb(h),e,!0,y);fb(e,f.outletId,`${r}.products.${o}.productId`)&&(n.products[f.id]=f)}),e.diagnostics.some(e=>"error"===e.severity))return;u.productIds=o,u.status="consumed",u.outletId=void 0,u.history.push(y),n.loss.amount+=t.loss?.amount??0;for(let[e,i]of Object.entries(t.loss?.metrics??{}))n.loss.metrics[e]=Number(n.loss.metrics[e]??0)+i;n.history.push(y),hb(e,{type:"split-source",sourceIds:[u.id],productIds:o});for(let t of o)hb(e,{type:"complete-product",sourceIds:[u.id],productIds:[t],outletIds:n.products[t].outletId?[n.products[t].outletId]:void 0});return}if("eject"===t.type){fb(e,t.outletId,`${r}.outletId`);let i=ub(n,t.select,`${r}.select`);e.diagnostics.push(...i.diagnostics);let o=i.ids.filter(e=>n.components[e].productIds.length);if(o.length&&e.diagnostics.push(ob("error","source-already-assigned",`Assigned source components cannot be ejected: ${o.join(", ")}.`,`${r}.select`,o)),e.diagnostics.some(e=>"error"===e.severity))return;let a=db(e,t,{sourceIds:i.ids,outletIds:[t.outletId]});for(let e of i.ids){let i=n.components[e];i.status=t.state??"ejected",i.outletId=t.outletId,i.reason=t.reason,i.history.push(a)}return n.history.push(a),void(i.ids.length&&hb(e,{type:"retarget-component",sourceIds:i.ids,outletIds:[t.outletId]}))}if("set-metric"===t.type){if(e.diagnostics.push(...sb(t.metricsDelta,`${r}.metricsDelta`)),e.diagnostics.some(e=>"error"===e.severity))return;let i,o;if("run"===t.target)lb(n.metrics,t.metricsDelta);else if("components"in t.target){let o=ub(n,t.target.components,`${r}.target.components`);if(e.diagnostics.push(...o.diagnostics),e.diagnostics.some(e=>"error"===e.severity))return;i=o.ids;for(let e of o.ids)lb(n.components[e].metrics,t.metricsDelta)}else{o=[...t.target.productIds];let i=ab(o),a=o.filter(e=>!n.products[e]);if(i.length&&e.diagnostics.push(ob("error","duplicate-product","Metric target product ids must be unique.",`${r}.target.productIds`,i)),a.length&&e.diagnostics.push(ob("error","unknown-product-state",`Metric target product has not formed: ${a.join(", ")}.`,`${r}.target.productIds`,a)),e.diagnostics.some(e=>"error"===e.severity))return;for(let e of o)lb(n.products[e].metrics,t.metricsDelta)}return void n.history.push(db(e,t,{sourceIds:i,productIds:o}))}t.outcome.trim()?(n.outcome=t.outcome,n.summary=t.summary,n.history.push(db(e,t)),e.observations.push({type:"crucible-outcome",eventId:e.event.id,phaseId:e.context.phaseId,authoredAt:e.context.authoredAt,appliedAt:e.context.appliedAt,outcome:t.outcome})):e.diagnostics.push(ob("error","invalid-outcome","Outcome must be a non-empty string.",`${r}.outcome`))}function Ab(e,t,i){if(e.eventsApplied.includes(t.id))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:[ob("warning","duplicate-event-application",`Event "${t.id}" has already been applied.`,`events.${t.id}`,[t.id])]};let r=ib(e),n={state:r,event:t,context:i,productDefinitions:new Map(i.products.map(e=>[e.id,e])),outletIds:new Set(i.outlets.map(e=>e.id)),diagnostics:[],materializations:[],observations:[]};for(let[i,r]of t.effects.entries())if(Sb(n,r,i),n.diagnostics.some(e=>"error"===e.severity))return{applied:!1,state:e,materializations:[],observations:[],diagnostics:n.diagnostics};return r.elapsed=Math.max(r.elapsed,i.appliedAt),r.phaseId=i.phaseId,r.eventsApplied.push(t.id),n.observations.unshift({type:"crucible-event",eventId:t.id,phaseId:i.phaseId,authoredAt:i.authoredAt,appliedAt:i.appliedAt}),{applied:!0,state:r,materializations:n.materializations,observations:n.observations,diagnostics:n.diagnostics}}function Mb(e,t){return"product"===t?"product"===e.kind?e.id:"unassigned":"outlet"===t?e.outletId??"unassigned":"category"===t?e.category:e.status}function $b(e,t={}){let i=t.groupBy??"outlet",r=/* @__PURE__ */new Map,n=e=>{let t=Mb({...e,status:e.status??"active"},i),n=r.get(t);if(n)return n.count+=1,n.amount+=e.amount,void lb(n.metrics,e.metrics);r.set(t,{key:t,label:"product"===i&&"product"===e.kind?e.label:t,count:1,amount:e.amount,metrics:eb(e.metrics),status:"status"===i?e.status:void 0,outletId:"outlet"===i?e.outletId:void 0,category:"category"===i?e.category:void 0,productId:"product"===i&&"product"===e.kind?e.id:void 0})};for(let t of Object.values(e.components))t.productIds.length||"consumed"===t.status||n({kind:"component",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});for(let t of Object.values(e.products))n({kind:"product",id:t.id,label:t.label,status:t.status,outletId:t.outletId,category:t.category,amount:t.amount,metrics:t.metrics});let o=new Map((t.order??[]).map((e,t)=>[e,t]));return[...r.values()].sort((e,t)=>(o.get(e.key)??Number.MAX_SAFE_INTEGER)-(o.get(t.key)??Number.MAX_SAFE_INTEGER)||nb(e.key,t.key))}var _b=[900,520],Ib=[{id:"product",label:"Products",side:"bottom",order:0},{id:"retained",label:"Retained",side:"bottom",order:1},{id:"residue",label:"Residue",side:"left",order:2},{id:"failed",label:"Failed",side:"right",order:3},{id:"recovered",label:"Recovered",side:"right",order:4}],Pb=/* @__PURE__ */new Set(["queued","active","transformed","consumed","retained","ejected","failed","recovered"]),Lb=1e-9;function Rb(e,t){return e<t?-1:e>t?1:0}function Cb(e,t,i,r,n){return{severity:e,code:t,message:i,path:r,ids:n?[...n]:void 0}}function Tb(e){let t=/* @__PURE__ */new Set,i=/* @__PURE__ */new Set;for(let r of e)t.has(r)&&i.add(r),t.add(r);return[...i].sort(Rb)}function Nb(e){let t="number"==typeof e?e:Number(e);return Number.isFinite(t)?t:null}function Fb(e,t,i,r,n,o){if(!i)return r;try{return("function"==typeof i?i(e,t):e[i])??r}catch(e){return n.push(Cb("error","accessor-error",`Accessor threw: ${e instanceof Error?e.message:String(e)}.`,o)),r}}function Eb(e,t,i){if(!e||"object"!=typeof e||Array.isArray(e))return null!=e&&t.push(Cb("error","invalid-metrics","Metrics must be a numeric object.",i)),Qx();let r=Qx();for(let[n,o]of Object.entries(e)){let e=Nb(o);null!=e?r[n]=e:t.push(Cb("error","invalid-metric",`Metric "${n}" must be finite.`,`${i}.${n}`))}return r}function Ob(e,t){for(let[i,r]of Object.entries(t))e[i]=Number(e[i]??0)+r}function zb(e){let t=[],i=Qx(),r=[],n=0,o=Qx();e.data.forEach((a,s)=>{let l=String(a.id??`component-${s}`),c=Fb(a,s,e.idAccessor,l,t,`data.${s}.id`),u=String(c??l).trim();if(!u)return void t.push(Cb("error","invalid-component-id","Component ids may not be empty.",`data.${s}.id`));r.push(u);let d=Nb(Fb(a,s,e.amountAccessor,1,t,`data.${s}.amount`)),h=null!=d&&d>=0?d:0;(null==d||d<0)&&t.push(Cb("error","invalid-component-amount","Component amount must be finite and non-negative.",`data.${s}.amount`,[u]));let f=Eb(Fb(a,s,e.metricsAccessor,{},t,`data.${s}.metrics`),t,`data.${s}.metrics`),p=Fb(a,s,e.initialStateAccessor,"active",t,`data.${s}.status`),g=Pb.has(p)?p:"active";Pb.has(p)||t.push(Cb("error","invalid-component-status",`Unknown component status "${String(p)}".`,`data.${s}.status`,[u]));let m=String(Fb(a,s,e.labelAccessor,String(a.label??a.name??u),t,`data.${s}.label`)),y=String(Fb(a,s,e.categoryAccessor,"component",t,`data.${s}.category`));Object.hasOwn(i,u)||(i[u]={id:u,label:m,category:y,datum:a,status:g,initialAmount:h,amount:h,initialMetrics:Jx(f),metrics:Jx(f),productIds:[],history:[]},n+=h,Ob(o,f))});let a=Tb(r);a.length&&t.push(Cb("error","duplicate-component-id",`Component ids must be unique: ${a.join(", ")}.`,"data",a));let s=Eb(e.metrics??{},t,"metrics");return{state:{elapsed:0,phaseElapsed:0,phaseId:e.phases[0]?.id??"",phaseIndex:e.phases.length?0:-1,playing:!1,complete:0===e.phases.length,outcome:"in_process",eventsApplied:[],components:i,products:Qx(),relations:Qx(),input:{amount:n,metrics:o},metrics:s,loss:{amount:0,metrics:Qx()},history:[]},diagnostics:t}}function Db(e){let t=[];e.length||t.push(Cb("error","empty-phase-program","CrucibleChart requires at least one phase.","phases"));let i=Tb(e.map(e=>e.id));i.length&&t.push(Cb("error","duplicate-phase-id",`Phase ids must be unique: ${i.join(", ")}.`,"phases",i));let r=0;return{phases:e.map((e,i)=>{let n=Nb(e.duration),o=null!=n&&n>0?n:0;e.id.trim()||t.push(Cb("error","invalid-phase-id","Phase ids may not be empty.",`phases.${i}.id`)),(null==n||n<=0)&&t.push(Cb("error","invalid-phase-duration","Phase duration must be finite and greater than zero.",`phases.${i}.duration`,[e.id])),void 0!==e.intensity&&!Number.isFinite(e.intensity)&&t.push(Cb("error","invalid-phase-intensity","Phase intensity must be finite.",`phases.${i}.intensity`,[e.id]));let a={...e,duration:o,intensity:void 0===e.intensity?.5:Number.isFinite(e.intensity)?Math.max(0,Math.min(1,e.intensity)):.5,motion:e.motion??"hold",index:i,start:r,end:r+o};return r=a.end,a}),diagnostics:t}}function Bb(e,t,i){let r=e.find(e=>Math.abs(e.start-i)<=Lb);if(r)return{phase:r,boundaryRank:1};let n=e.find(e=>i>=e.start&&i<e.end);return n?{phase:n,boundaryRank:0}:Math.abs(i-t)<=Lb&&e.length?{phase:e[e.length-1],boundaryRank:0}:{phase:void 0,boundaryRank:1}}function jb(e,t,i){let r=[],n=Tb(e.map(e=>e.id));n.length&&r.push(Cb("error","duplicate-event-id",`Event ids must be unique: ${n.join(", ")}.`,"events",n));let o=[];return e.forEach((e,n)=>{let a,s,l;if(e.id.trim()||r.push(Cb("error","invalid-event-id","Event ids may not be empty.",`events.${n}.id`)),"time"in e.at&&void 0!==e.at.time){let o=Nb(e.at.time);if(null==o||o<0||o>i+Lb)return void r.push(Cb("error","event-time-out-of-range",`Event time must fall between 0 and ${i}.`,`events.${n}.at.time`,[e.id]));a=Math.max(0,Math.min(i,o));let c=Bb(t,i,a);s=c.phase,l=c.boundaryRank}else{if(s=t.find(t=>t.id===e.at.phaseId),!s)return void r.push(Cb("error","unknown-event-phase",`Event references unknown phase "${e.at.phaseId}".`,`events.${n}.at.phaseId`,[e.id,e.at.phaseId]));let i=e.at.progress??0;if(!Number.isFinite(i)||i<0||i>1)return void r.push(Cb("error","event-progress-out-of-range","Event phase progress must be between 0 and 1.",`events.${n}.at.progress`,[e.id]));a=s.start+s.duration*i,l=0===i?1:0}s?o.push({...e,index:n,authoredAt:a,phaseId:s.id,phaseIndex:s.index,boundaryRank:l}):r.push(Cb("error","event-without-phase","Event could not be assigned to a phase.",`events.${n}.at`,[e.id]))}),o.sort((e,t)=>e.authoredAt-t.authoredAt||e.boundaryRank-t.boundaryRank||e.index-t.index),{events:o,diagnostics:r}}function Wb(e,t){let i=[],r=new Set(t.map(e=>e.id)),n=Tb(t.map(e=>e.id)),o=Tb(e.map(e=>e.id));return n.length&&i.push(Cb("error","duplicate-outlet-id",`Outlet ids must be unique: ${n.join(", ")}.`,"outlets",n)),o.length&&i.push(Cb("error","duplicate-product-id",`Product ids must be unique: ${o.join(", ")}.`,"products",o)),t.forEach((e,t)=>{e.id.trim()||i.push(Cb("error","invalid-outlet-id","Outlet ids may not be empty.",`outlets.${t}.id`)),void 0!==e.order&&!Number.isFinite(e.order)&&i.push(Cb("error","invalid-outlet-order","Outlet order must be finite.",`outlets.${t}.order`,[e.id]))}),e.forEach((e,t)=>{e.id.trim()||i.push(Cb("error","invalid-product-id","Product ids may not be empty.",`products.${t}.id`)),void 0!==e.amount&&(!Number.isFinite(e.amount)||e.amount<0)&&i.push(Cb("error","invalid-product-amount","Declared product amount must be finite and non-negative.",`products.${t}.amount`,[e.id])),void 0!==e.outletId&&!r.has(e.outletId)&&i.push(Cb("error","unknown-outlet",`Product "${e.id}" references unknown outlet "${e.outletId}".`,`products.${t}.outletId`,[e.outletId])),Eb(e.metrics??{},i,`products.${t}.metrics`)}),i}function Yb(e){return e.map((e,t)=>({outlet:e,index:t})).sort((e,t)=>(e.outlet.order??e.index)-(t.outlet.order??t.index)||e.index-t.index).map(({outlet:e})=>({...e}))}function qb(e=_b,t=Ib){let i=Math.max(1,Nb(e[0])??900),r=Math.max(1,Nb(e[1])??520),n=i<360||r<260,o=n?Math.max(4,.035*Math.min(i,r)):20,a=n?Math.max(10,.075*r):34,s={x:o,y:o,width:Math.max(1,i-2*o),height:a},l=n?Math.max(16,.14*r):Math.min(78,.16*r),c={x:o,y:r-o-l,width:Math.max(1,i-2*o),height:l},u=n?Math.max(12,.08*i):Math.min(150,.17*i),d=s.y+s.height+(n?12:38),h=c.y-(n?10:34),f={x:u,y:d,width:Math.max(24,i-2*u),height:Math.max(24,h-d)},p=Math.max(18,Math.min(.32*f.width,n?84:180)),g={x:f.x+(f.width-p)/2,y:f.y-(n?10:24),width:p,height:n?12:28},m=Yb(t),y={left:m.filter(e=>"left"===(e.side??"bottom")),right:m.filter(e=>"right"===e.side),bottom:m.filter(e=>"bottom"===(e.side??"bottom"))},x=[],b=(e,t)=>{let r=Math.max(8,u-1.5*o),a=f.height/Math.max(1,t.length);t.forEach((t,s)=>{x.push({...t,side:e,x:"left"===e?o:i-o-r,y:f.y+s*a,width:r,height:Math.max(8,a-(n?2:8))})})};b("left",y.left),b("right",y.right);let v=f.width/Math.max(1,y.bottom.length);return y.bottom.forEach((e,t)=>{x.push({...e,side:"bottom",x:f.x+t*v,y:f.y+f.height+(n?2:7),width:Math.max(8,v-(n?2:8)),height:Math.max(8,c.y-f.y-f.height-(n?4:12))})}),x.sort((e,t)=>m.findIndex(t=>t.id===e.id)-m.findIndex(e=>e.id===t.id)),{width:i,height:r,phaseRail:s,chamber:f,mouth:g,projection:c,outlets:x}}function Xb(e,t,i){let r=i.map(([i,r])=>[Math.max(e,Math.min(i,r)),Math.min(t,Math.max(i,r))]).filter(([e,t])=>t>e+Lb).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),n=[],o=e;for(let[e,t]of r)e>o+Lb&&n.push([o,e]),o=Math.max(o,t);return t>o+Lb&&n.push([o,t]),n}function Gb(e){let{id:t,orientation:i,fixed:r,start:n,end:o,openings:a,thickness:s,friction:l,restitution:c}=e,u=Xb(n,o,a);return u.map(([e,n],o)=>({id:1===u.length?t:`${t}:${o}`,friction:l,restitution:c,shape:"horizontal"===i?{type:"segment",x1:e,y1:r,x2:n,y2:r,thickness:s}:{type:"segment",x1:r,y1:e,x2:r,y2:n,thickness:s}}))}function Vb(e){let{chamber:t,mouth:i}=e,r=Math.max(2,Math.min(10,.018*Math.min(e.width,e.height))),n=Math.max(t.x,i.x),o=Math.min(t.x+t.width,i.x+i.width),a={left:e.outlets.filter(e=>"left"===e.side),right:e.outlets.filter(e=>"right"===e.side),bottom:e.outlets.filter(e=>"bottom"===e.side)},s=[{id:"crucible:wall:top-left",friction:.42,restitution:.1,shape:{type:"segment",x1:t.x,y1:t.y,x2:n,y2:t.y,thickness:r}},{id:"crucible:wall:top-right",friction:.42,restitution:.1,shape:{type:"segment",x1:o,y1:t.y,x2:t.x+t.width,y2:t.y,thickness:r}}];s.push(...Gb({id:"crucible:wall:left",orientation:"vertical",fixed:t.x,start:t.y,end:t.y+t.height,openings:a.left.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...Gb({id:"crucible:wall:right",orientation:"vertical",fixed:t.x+t.width,start:t.y,end:t.y+t.height,openings:a.right.map(e=>[e.y,e.y+e.height]),thickness:r,friction:.46,restitution:.12}),...Gb({id:"crucible:wall:bottom",orientation:"horizontal",fixed:t.y+t.height,start:t.x,end:t.x+t.width,openings:a.bottom.map(e=>[e.x,e.x+e.width]),thickness:r,friction:.5,restitution:.08}));for(let t of e.outlets)s.push({id:`crucible:outlet:${encodeURIComponent(t.id)}`,sensor:!0,shape:{type:"aabb",x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height}});return s}function Hb(e){return"number"==typeof e&&Number.isFinite(e)?e>>>0:"string"==typeof e?xn(e):1}function Ub(e,t){return{fixedDt:1/120,maxSubsteps:8,settleStepLimit:7200,colliders:t.map(e=>({...e,shape:{...e.shape}})),observation:{chartType:"crucible"},kernel:{seed:Hb(e),gravity:{x:0,y:0},cellSize:42,collisionIterations:6,velocityDamping:.992,restitution:.12,friction:.42,sleepSpeed:4,sleepAfter:.5,maxVelocity:620}}}function Kb(e){return`crucible:component:${encodeURIComponent(e)}`}function Zb(e){return`crucible:product:${encodeURIComponent(e)}`}function Qb(e,t,i,r){if(void 0!==i&&Number.isFinite(i)&&i>0)return i;let[n,o]=t;if(o-n<=Lb)return(r[0]+r[1])/2;let a=Math.sqrt(Math.max(0,e-n)/(o-n));return r[0]+(r[1]-r[0])*a}function Jb(e,t){let i=Math.max(.25,Math.min(1,t.width/900,t.height/520)),r=e?.[0]??7*i,n=e?.[1]??18*i,o=Math.max(1,Math.min(r,n));return[o,Math.max(o,Math.max(r,n))]}function ev(e,t,i={}){let r=Object.values(e.components).sort((e,t)=>Rb(e.id,t.id)),n=yr(r.map(e=>e.amount)),o=Jb(i.radiusRange,t),a=_g(Hb(i.seed)),s=t.mouth.x+t.mouth.width/2,l=t.chamber.y+Math.max(18,.18*t.chamber.height),c=Math.max(4,.28*t.chamber.width),u=Math.max(4,.12*t.chamber.height);return r.map((e,t)=>{let d=t/Math.max(1,r.length)*Math.PI*2+.18*(a()-.5),h=Qb(e.amount,n,i.bodyRadius,o),f={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Kb(e.id),x:s+Math.cos(d)*c*(.45+.45*a()),y:l+Math.sin(d)*u*(.45+.45*a()),vx:24*(a()-.5),vy:18*(a()-.5),mass:Math.max(.25,h*h*.015),restitution:.12,friction:.4,shape:{type:"circle",radius:h},datum:f}})}function tv(e,t){if(!e)return[];let i=Math.min(e,Math.max(1,Math.ceil(Math.sqrt(e*Math.max(.5,t.width/Math.max(1,t.height)))))),r=Math.max(1,Math.ceil(e/i));return Array.from({length:e},(e,n)=>({x:t.x+(n%i+.5)*(t.width/i),y:t.y+(Math.floor(n/i)+.5)*(t.height/r)}))}function iv(e){return e.outletId?e.outletId:"failed"===e.status?"failed":"recovered"===e.status?"recovered":"retained"===e.status?"retained":"ejected"===e.status?"residue":void 0}function rv(e,t){return e.outlets.find(e=>e.id===t)||{x:e.chamber.x+.18*e.chamber.width,y:e.chamber.y+.2*e.chamber.height,width:.64*e.chamber.width,height:.6*e.chamber.height}}function nv(e,t){let i=/* @__PURE__ */new Map;for(let t of e){let e=t.outletId??"__chamber__",r=i.get(e)??[];r.push(t),i.set(e,r)}let r=/* @__PURE__ */new Map;for(let[e,n]of i){n.sort((e,t)=>(e.order??Number.MAX_SAFE_INTEGER)-(t.order??Number.MAX_SAFE_INTEGER)||Rb(e.id,t.id));let i=tv(n.length,rv(t,"__chamber__"===e?void 0:e));n.forEach((e,t)=>r.set(e.id,i[t]))}return r}function ov(e,t,i={}){let r=Object.values(e.products).sort((e,t)=>Rb(e.id,t.id)),n=Object.values(e.components).sort((e,t)=>Rb(e.id,t.id)),o=yr([...n.map(e=>e.amount),...r.map(e=>e.amount)]),a=Jb(i.radiusRange,t),s=nv(r,t),l=r.map(e=>{let r=s.get(e.id)??{x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2},n=1.28*Qb(e.amount,o,i.bodyRadius,a),l={__crucible:!0,kind:"product",semanticId:e.id,product:e};return{id:Zb(e.id),x:r.x,y:r.y,mass:Math.max(.25,n*n*.018),bodyCollisions:!1,shape:{type:"circle",radius:n},datum:l}}),c=/* @__PURE__ */new Map;for(let e of n.filter(e=>!e.productIds.length)){let t=iv(e)??"__chamber__",i=c.get(t)??[];i.push(e),c.set(t,i)}let u=/* @__PURE__ */new Map;for(let[e,i]of c){let r=tv(i.length,rv(t,"__chamber__"===e?void 0:e));i.forEach((e,t)=>u.set(e.id,r[t]))}return[...n.map(e=>{let r=u.get(e.id);if(e.productIds.length){let i=e.productIds.map(e=>s.get(e)).filter(e=>!!e);if(i.length){r={x:i.reduce((e,t)=>e+t.x,0)/i.length,y:i.reduce((e,t)=>e+t.y,0)/i.length};let n=xn(e.id)/4294967295*Math.PI*2,o=Math.min(20,Math.max(4,.012*t.width));r={x:r.x+Math.cos(n)*o,y:r.y+Math.sin(n)*o}}}r??(r={x:t.chamber.x+t.chamber.width/2,y:t.chamber.y+t.chamber.height/2});let n=Qb(e.amount,o,i.bodyRadius,a),l={__crucible:!0,kind:"component",semanticId:e.id,sourceDatum:e.datum};return{id:Kb(e.id),x:r.x,y:r.y,mass:Math.max(.25,n*n*.015),shape:{type:"circle",radius:n},datum:l}}),...l]}var av=ov;function sv(e){return Array.isArray(e)?e.map(sv):e&&"object"==typeof e?Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e&&"function"!=typeof e).sort(([e],[t])=>Rb(e,t)).map(([e,t])=>[e,sv(t)])):e}function lv(e){return JSON.stringify(sv(e))}function cv(e,t){let i=Nb(t)??0,r=Math.max(0,Math.min(e.duration,i));if(!e.phases.length)return{elapsed:r,phaseId:"",phaseIndex:-1,phaseElapsed:0,complete:!0};let n=r>=e.duration-Lb,o=n?e.phases[e.phases.length-1]:e.phases.find(e=>r>=e.start&&r<e.end)??e.phases[0];return{elapsed:r,phaseId:o.id,phaseIndex:o.index,phaseElapsed:n?o.duration:Math.max(0,r-o.start),complete:n}}function uv(e,t){if(void 0===t)return e.duration;if("number"==typeof t)return Math.max(0,Math.min(e.duration,Nb(t)??0));let i=e.phases.find(e=>e.id===t.phaseId);if(!i)return e.duration;let r=Math.max(0,Math.min(1,Nb(t.progress??0)??0));return i.start+i.duration*r}function dv(e,t=e.duration){let i=cv(e,t),r=ib(e.initialState),n=[],o=[],a=[];for(let t of e.events){if(t.authoredAt>i.elapsed+Lb)break;let s=Ab(r,t,{phaseId:t.phaseId,authoredAt:t.authoredAt,appliedAt:t.authoredAt,products:e.products,outlets:e.outlets});n.push(...s.diagnostics),o.push(...s.materializations),a.push(...s.observations),s.applied&&(r=s.state)}return r.elapsed=i.elapsed,r.phaseId=i.phaseId,r.phaseIndex=i.phaseIndex,r.phaseElapsed=i.phaseElapsed,r.complete=i.complete,i.complete&&"in_process"===r.outcome&&(r.outcome="complete"),r.playing=!1,{state:r,diagnostics:n,materializations:o,observations:a}}function hv(e){let t=Db(e.phases),i=t.phases.at(-1)?.end??0,r=Yb(e.outlets??Ib),n=(e.products??[]).map(e=>({...e,metrics:e.metrics?Jx(e.metrics):void 0})),o=jb(e.events??[],t.phases,i),a=zb(e),s=qb(e.size??_b,r),l=Vb(s),c=Wb(n,r),u=lv({seed:e.seed??1,components:Object.values(a.state.components).sort((e,t)=>Rb(e.id,t.id)).map(e=>({id:e.id,label:e.label,category:e.category,amount:e.amount,metrics:e.metrics,status:e.status})),phases:t.phases.map(({id:e,duration:t,label:i,description:r,intensity:n,motion:o,color:a,metrics:s})=>({id:e,duration:t,label:i,description:r,intensity:n,motion:o,color:a,metrics:s})),products:n,outlets:r,events:o.events.map(({id:e,label:t,description:i,summary:r,authoredAt:n,phaseId:o,boundaryRank:a,effects:s})=>({id:e,label:t,description:i,summary:r,authoredAt:n,phaseId:o,boundaryRank:a,effects:s}))}),d=ev(a.state,s,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),h=[...t.diagnostics,...o.diagnostics,...a.diagnostics,...c],f={phases:t.phases,events:o.events,products:n,outlets:r,duration:i,initialState:a.state,terminalState:a.state,layout:s,colliders:l,config:Ub(e.seed,l),initialSpawns:d,terminalSpawns:[],semanticKey:u,diagnostics:h},p=dv(f),g=Object.values(p.state.products).filter(e=>"forming"===e.status).map(e=>e.id),m=g.length?[Cb("warning","forming-product-at-end",`Products remain forming at the end of the tape: ${g.join(", ")}.`,"events",g)]:[];return f.terminalState=p.state,f.terminalSpawns=av(p.state,s,{seed:e.seed,bodyRadius:e.bodyRadius,radiusRange:e.radiusRange}),f.diagnostics=[...h,...p.diagnostics,...m],f}import*as fv from"react";import{jsx as pv,jsxs as gv}from"react/jsx-runtime";function mv(e){return Number.isFinite(e)?Math.abs(e)>=1e3?e.toLocaleString():Number.isInteger(e)?String(e):e.toFixed(2).replace(/\.00$/,"").replace(/(\.\d)0$/,"$1"):"0"}function yv(e,t,i,r){let n=e.datum;if(!n?.__crucible)return;let o="circle"===e.shape.type?e.shape.radius:8,a="string"==typeof t.fill?t.fill:"product"===n.kind?"#b8792d":"#356b63",s="string"==typeof t.stroke?t.stroke:"#26323a",l="number"==typeof t.strokeWidth?t.strokeWidth:1.25,c="number"==typeof t.opacity?t.opacity:.96,u=r?`${r}-crucible-body-${i}`:`crucible-body-${i}`;if("product"===n.kind){let t=Array.from({length:6},(t,i)=>{let r=-Math.PI/2+i/6*Math.PI*2;return`${e.x+Math.cos(r)*o},${e.y+Math.sin(r)*o}`}).join(" "),i=`${u}-glow`;/* @__PURE__ */
179
- return gv(fv.Fragment,{children:[
180
- /* @__PURE__ */pv("defs",{children:/* @__PURE__ */pv("filter",{id:i,x:"-60%",y:"-60%",width:"220%",height:"220%",children:/* @__PURE__ */pv("feDropShadow",{dx:"0",dy:"0",stdDeviation:"4",floodColor:a,floodOpacity:"0.8"})})}),
181
- /* @__PURE__ */pv("polygon",{points:t,fill:a,stroke:s,strokeWidth:l,opacity:c,filter:`url(#${i})`}),
182
- /* @__PURE__ */pv("circle",{cx:e.x,cy:e.y,r:Math.max(2,.36*o),fill:"none",stroke:"var(--semiotic-bg, #fffaf0)",strokeWidth:l,opacity:.72*c})]},u)}/* @__PURE__ */
183
- return gv(fv.Fragment,{children:[
184
- /* @__PURE__ */pv("circle",{cx:e.x,cy:e.y,r:o,fill:a,stroke:s,strokeWidth:l,opacity:c}),
185
- /* @__PURE__ */pv("circle",{cx:e.x-.25*o,cy:e.y-.28*o,r:Math.max(1,.18*o),fill:"rgba(255,255,255,0.34)"})]},u)}import{Fragment as xv,jsx as bv,jsxs as vv}from"react/jsx-runtime";var wv="var(--semiotic-text, #26323a)",kv="var(--semiotic-text-secondary, #6c7377)",Sv="var(--semiotic-primary, #b8792d)",Av="var(--semiotic-danger, #9f3d35)",Mv="var(--semiotic-success, #356b63)";function $v(e){let{x:t,y:i,width:r,height:n}=e.chamber,o=Math.min(.14*r,48),a=i+n;return[`M ${t} ${i}`,`L ${t+o} ${a-.16*n}`,`Q ${t+r/2} ${a+.1*n} ${t+r-o} ${a-.16*n}`,`L ${t+r} ${i}`].join(" ")}function _v({layout:e,phases:t,state:i,compact:r=!1}){let n=Math.max(1,t.reduce((e,t)=>e+Math.max(0,t.duration),0));/* @__PURE__ */
186
- return vv("svg",{"aria-hidden":"true","data-testid":"crucible-chrome",viewBox:`0 0 ${e.width} ${e.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:[
187
- /* @__PURE__ */vv("defs",{children:[
188
- /* @__PURE__ */vv("linearGradient",{id:"semiotic-crucible-heat",x1:"0",x2:"0",y1:"0",y2:"1",children:[
189
- /* @__PURE__ */bv("stop",{offset:"0",stopColor:Sv,stopOpacity:"0.03"}),
190
- /* @__PURE__ */bv("stop",{offset:"0.66",stopColor:Sv,stopOpacity:"0.1"}),
191
- /* @__PURE__ */bv("stop",{offset:"1",stopColor:Av,stopOpacity:"0.18"})]}),
192
- /* @__PURE__ */bv("pattern",{id:"semiotic-crucible-hatch",width:"7",height:"7",patternUnits:"userSpaceOnUse",patternTransform:"rotate(20)",children:/* @__PURE__ */bv("line",{x1:"0",x2:"0",y1:"0",y2:"7",stroke:wv,strokeOpacity:"0.08",strokeWidth:"1"})})]}),
193
- /* @__PURE__ */bv("rect",{x:e.chamber.x,y:e.chamber.y,width:e.chamber.width,height:e.chamber.height,rx:2,fill:"url(#semiotic-crucible-heat)",stroke:wv,strokeOpacity:"0.52",strokeWidth:r?1:2.2}),
194
- /* @__PURE__ */bv("path",{d:$v(e),fill:"url(#semiotic-crucible-hatch)",stroke:"none"}),
195
- /* @__PURE__ */bv("line",{x1:e.mouth.x,x2:e.mouth.x+e.mouth.width,y1:e.mouth.y,y2:e.mouth.y,stroke:wv,strokeLinecap:"round",strokeOpacity:"0.72",strokeWidth:r?2:5}),r?null:/* @__PURE__ */bv("g",{"data-testid":"crucible-phase-rail",children:t.map((r,o)=>{let a=t.slice(0,o).reduce((e,t)=>e+Math.max(0,t.duration),0),s=e.phaseRail.x+a/n*e.phaseRail.width,l=Math.max(0,r.duration)/n*e.phaseRail.width,c=r.id===i.phaseId,u=i.phaseIndex>o||i.complete;/* @__PURE__ */
196
- return vv("g",{children:[
197
- /* @__PURE__ */bv("rect",{x:s,y:e.phaseRail.y,width:Math.max(1,l-2),height:e.phaseRail.height,rx:2,fill:c?r.color??Sv:u?Mv:wv,fillOpacity:c?.68:u?.28:.09}),l>=46?/* @__PURE__ */bv("text",{x:s+l/2,y:e.phaseRail.y+e.phaseRail.height+13,fill:c?wv:kv,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8.5,fontWeight:c?800:650,letterSpacing:"0.04em",textAnchor:"middle",children:(r.label??r.id).toUpperCase()}):null]},r.id)})}),e.outlets.map(e=>/* @__PURE__ */vv("g",{children:[
198
- /* @__PURE__ */bv("rect",{x:e.x,y:e.y,width:e.width,height:e.height,rx:3,fill:e.color??("left"===e.side?Av:Mv),fillOpacity:"0.1",stroke:e.color??("left"===e.side?Av:Mv),strokeDasharray:"3 3",strokeOpacity:"0.62"}),r?null:/* @__PURE__ */bv("text",{x:e.x+e.width/2,y:e.y+Math.min(13,e.height/2+3),fill:kv,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:750,letterSpacing:"0.05em",textAnchor:"middle",children:(e.label??e.id).toUpperCase()})]},e.id))]})}function Iv(e,t){return"count"===t?e.count:"amount"===t?e.amount:Number(e.metrics[t]??0)}function Pv({rows:e,layout:t,projection:i,amountLabel:r}){if(!e.length)return null;let n=i.measure??"count",o=e.map(e=>Math.max(0,Iv(e,n))),a=o.reduce((e,t)=>Math.max(e,t),1),s=t.projection.width/Math.max(1,e.length),l=t.projection.height>48?21:4,c=Math.max(5,t.projection.height-l-5);/* @__PURE__ */
199
- return bv("svg",{"aria-hidden":"true","data-testid":"crucible-projection-overlay",viewBox:`0 0 ${t.width} ${t.height}`,style:{inset:0,pointerEvents:"none",position:"absolute"},children:e.map((e,i)=>{let u=o[i],d=Math.max(u>0?2:0,u/a*c),h=t.projection.x+i*s+.18*s,f=t.projection.y+c-d;/* @__PURE__ */
200
- return vv("g",{children:[
201
- /* @__PURE__ */bv("rect",{x:h,y:f,width:Math.max(3,.64*s),height:d,rx:2,fill:"failed"===e.status||"ejected"===e.status?Av:"complete"===e.status?Sv:Mv,fillOpacity:"0.68"}),l>4&&s>=34?/* @__PURE__ */vv(xv,{children:[
202
- /* @__PURE__ */bv("text",{x:h+.32*s,y:t.projection.y+c+10,fill:kv,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:7.5,fontWeight:700,textAnchor:"middle",children:e.label.length>13?`${e.label.slice(0,12)}…`:e.label}),
203
- /* @__PURE__ */vv("text",{x:h+.32*s,y:t.projection.y+c+19,fill:wv,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",fontSize:8,fontWeight:850,textAnchor:"middle",children:[mv(u),"amount"===n&&r?` ${r}`:""]})]}):null]},e.key)})})}function Lv(e){let t=e.datum;if(t&&"object"==typeof t){let e=t,i=e.label??e.name??e.id;if(null!=i&&""!==i)return String(i)}return e.id}function Rv(e,t={}){let i=t.bodies??[],r=Math.max(0,t.recentBodyLimit??6),n=/* @__PURE__ */new Map;for(let e of i){let i=t.getContainerId?.(e);if(!i)continue;let r=n.get(i);r?r.push(e):n.set(i,[e])}let o=e.map(e=>{let i=n.get(e.id)??[],o=Math.max(0,Math.floor(e.count??i.length)),a=i.slice(Math.max(0,i.length-r)).map(e=>({id:e.id,label:t.getBodyLabel?.(e)??Lv(e),datum:e.datum}));return{id:e.id,label:e.label,count:o,share:0,secondary:e.secondary,secondaryLabel:e.secondaryLabel,observed:e.observed,bodyIds:i.map(e=>e.id),recentBodies:a,metadata:e.metadata}}),a=o.reduce((e,t)=>e+t.count,0);return o.map(e=>({...e,share:a>0?e.count/a:0}))}import{Fragment as Cv,jsx as Tv,jsxs as Nv}from"react/jsx-runtime";function Fv(e,t,i,r,n){let o=Array.isArray(n)?n:n?[n]:[];if(!1!==i||0!==o.length)return({size:n})=>{let a=[Number(n[0])||700,Number(n[1])||420],s=Ig(a),l=Math.max(2,Math.round(t)),c=s.plot.width/l,u=s.plot.y+s.plot.height,d=e.reduce((e,t)=>Math.max(e,t.value),1),h=!1!==i,[f,p]=r?.valueExtent??[0,l],g=p===f?1:p-f,m=e.map((e,t)=>{let i=s.plot.x+(t+.5)*c,r=u-e.value/d*s.plot.height*.9;return`${0===t?"M":"L"} ${i.toFixed(1)} ${r.toFixed(1)}`}).join(" ");/* @__PURE__ */
204
- return Nv("svg",{"aria-hidden":"true","data-testid":"galton-board-structure-overlay",width:a[0],height:a[1],viewBox:`0 0 ${a[0]} ${a[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[h?/* @__PURE__ */Nv(Cv,{children:[Array.from({length:l+1},(e,t)=>{let i=s.plot.x+t*c;/* @__PURE__ */
205
- return Tv("line",{"data-testid":"galton-board-bin-wall",x1:i,x2:i,y1:s.plot.y,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.28,strokeWidth:1},`bin-wall-${t}`)}),
206
- /* @__PURE__ */Tv("line",{x1:s.plot.x,x2:s.plot.x+s.plot.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),
207
- /* @__PURE__ */Tv("path",{d:m,fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.7,strokeWidth:2,strokeLinejoin:"round"}),e.map((e,t)=>{if(e.value<=0)return null;let i=s.plot.x+(t+.5)*c,r=u-e.value/d*s.plot.height*.9;/* @__PURE__ */
208
- return Tv("text",{x:i,y:Math.max(s.plot.y+10,r-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.value},`${e.label}-${t}`)})]}):null,o.map((e,t)=>{let i=Number(e.value);if(!Number.isFinite(i))return null;let r=Math.max(0,Math.min(1,(i-f)/g)),n=s.plot.x+r*s.plot.width,o=e.color??"var(--semiotic-warning, #f28e2b)",l="bottom"===e.labelPosition?Math.min(a[1]-8,u+16):s.plot.y+16;/* @__PURE__ */
209
- return Nv("g",{className:e.className,"data-testid":"galton-board-reference-line",children:[
210
- /* @__PURE__ */Tv("line",{x1:n,x2:n,y1:s.plot.y+8,y2:u-4,stroke:o,strokeDasharray:e.strokeDasharray??"6 5",strokeWidth:e.strokeWidth??2}),null==e.label?null:/* @__PURE__ */Tv("text",{x:Math.min(s.plot.x+s.plot.width-4,n+6),y:l,fill:o,fontSize:10,fontWeight:700,children:e.label})]},`galton-reference-${t}-${i}`)})]})}}function Ev(e,t,i){if(!1!==i&&t)return({size:i})=>{let r=[Number(i[0])||760,Number(i[1])||360],n=Ig(r),o=Math.max(1,t.windowCount),a=t.plot??n.plot,s=t.gutter??{x:a.x,y:a.y,width:0,height:a.height},l=t.windowPlot??a,c=l.width/o,u=a.y+a.height,d=a.y+.48*a.height,h=t.lidSegments[0]?.y1??d,f=t.windowStart,p=t.windowStart+o*t.windowSize,g=p===f?0:(t.watermarkValue-f)/(p-f),m=l.x+Math.max(0,Math.min(1,g))*l.width;/* @__PURE__ */
211
- return Nv("svg",{"aria-hidden":"true","data-testid":"event-drop-window-overlay",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[
212
- /* @__PURE__ */Tv("rect",{x:a.x,y:a.y,width:a.width,height:a.height,fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeOpacity:.7,strokeWidth:1}),s.width>0?/* @__PURE__ */Nv("g",{children:[
213
- /* @__PURE__ */Tv("rect",{x:s.x,y:h,width:s.width,height:u-h,fill:"var(--semiotic-danger, #e15759)",fillOpacity:.07}),
214
- /* @__PURE__ */Nv("text",{x:s.x+s.width/2,y:h-8,textAnchor:"middle",fill:"var(--semiotic-danger, #e15759)",fontSize:10,fontWeight:700,children:[t.lateCount," late"]})]}):null,Array.from({length:o},(i,n)=>{let o=e[n],a=l.x+n*c,s=n<t.closedWindowCount;/* @__PURE__ */
215
- return Nv("g",{children:[
216
- /* @__PURE__ */Tv("rect",{x:a,y:d,width:c,height:u-d,fill:s?"var(--semiotic-danger, #e15759)":"var(--semiotic-primary, #4e79a7)",fillOpacity:s?.08:.06}),s?t.lidSegments.filter(e=>e.windowIndex===n).map(e=>/* @__PURE__ */Tv("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.78,strokeWidth:2,strokeLinecap:"round"},e.id)):null,
217
- /* @__PURE__ */Tv("text",{x:a+c/2,y:d-8,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:o?.value??0}),
218
- /* @__PURE__ */Tv("text",{x:a+c/2,y:Math.min(r[1]-8,u+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:o?.label??""})]},`window-${n}`)}),t.windowWalls?.map(({id:e,...t})=>/* @__PURE__ */Tv("rect",{...t,fill:"var(--semiotic-border, #d1d5db)",fillOpacity:.68},e)),t.lidSegments.filter(e=>null==e.windowIndex).map(e=>/* @__PURE__ */Tv("line",{x1:e.x1,x2:e.x2,y1:e.y1,y2:e.y2,stroke:"var(--semiotic-danger, #e15759)",strokeOpacity:.62,strokeWidth:2,strokeLinecap:"round"},e.id)),
219
- /* @__PURE__ */Tv("line",{x1:a.x,x2:a.x+a.width,y1:u,y2:u,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1.5}),
220
- /* @__PURE__ */Tv("line",{"data-testid":"event-drop-watermark",x1:m,x2:m,y1:a.y+8,y2:u,stroke:"var(--semiotic-warning, #f28e2b)",strokeDasharray:"5 4",strokeWidth:2}),
221
- /* @__PURE__ */Nv("text",{x:Math.min(a.x+a.width-4,m+6),y:a.y+16,fill:"var(--semiotic-warning, #f28e2b)",fontSize:10,fontWeight:700,children:["watermark ",Math.round(100*t.watermarkValue)/100]})]})}}function Ov(e,t,i,r=1){if(!1!==i&&0!==e.length)return({size:i})=>{let n=[Number(i[0])||700,Number(i[1])||380],o=Ig(n),a=Hy(o.plot,e.length,t),s=o.plot.y+o.plot.height;/* @__PURE__ */
222
- return Nv("svg",{"aria-hidden":"true","data-testid":"physics-pile-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[
223
- /* @__PURE__ */Tv("line",{x1:o.plot.x,x2:o.plot.x+o.plot.width,y1:s,y2:s,stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:1}),e.map((e,t)=>{let i=Math.min(o.plot.height,a.pileHeight(e.value/r)),l=a.tubeWidth,c=a.centerX(t),u=s-i;/* @__PURE__ */
224
- return Nv("g",{children:[
225
- /* @__PURE__ */Tv("rect",{x:c-l/2,y:u,width:l,height:i,rx:3,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.08,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.42,strokeWidth:1,strokeDasharray:"4 3"}),
226
- /* @__PURE__ */Tv("text",{x:c,y:Math.max(o.plot.y+12,u-6),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:11,fontWeight:700,children:e.value}),
227
- /* @__PURE__ */Tv("text",{x:c,y:Math.min(n[1]-8,s+16),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${t}`)}),
228
- /* @__PURE__ */Tv("text",{x:n[0]/2,y:n[1]-2,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:`Full circle = ${r}; partial circles scaled by area`})]})}}function zv(e){return Math.abs(e)>=1e3||Math.abs(e)<.01?e.toLocaleString(void 0,{maximumFractionDigits:0}):e.toLocaleString(void 0,{maximumFractionDigits:2})}function Dv(e,t){if(!1!==t&&e)return({size:t})=>{let i=[Number(t[0])||700,Number(t[1])||360],r=Ig(i),n=r.plot.y+r.plot.height,[o,a]=e.xExtent,s=o+(a-o)/2,l=[{label:zv(o),x:e.xRange[0]},{label:zv(s),x:e.xRange[0]+(e.xRange[1]-e.xRange[0])/2},{label:zv(a),x:e.xRange[1]}];/* @__PURE__ */
229
- return Nv("svg",{"aria-hidden":"true","data-testid":"collision-swarm-projection-overlay",width:i[0],height:i[1],viewBox:`0 0 ${i[0]} ${i[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.groups.some(e=>e.overlapping)?/* @__PURE__ */Tv("text",{"data-testid":"collision-swarm-overlap-warning",x:r.plot.x,y:Math.max(10,r.plot.y-9),fill:"var(--semiotic-warning, #b45309)",fontSize:10,children:i[0]<360?"Points overlap":"Points overlap. Reduce radius or increase height."}):null,e.groups.map(e=>/* @__PURE__ */Nv("g",{children:[
230
- /* @__PURE__ */Tv("line",{x1:r.plot.x,x2:r.plot.x+r.plot.width,y1:e.y,y2:e.y,stroke:"var(--semiotic-border, #d1d5db)",strokeDasharray:"3 5",strokeWidth:1}),
231
- /* @__PURE__ */Tv("text",{x:r.plot.x+4,y:e.y-7,fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:e.label}),
232
- /* @__PURE__ */Nv("text",{x:r.plot.x+r.plot.width-4,y:e.y-7,textAnchor:"end",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:["n=",e.count,e.overlapping?" · overlaps":""]})]},e.label)),
233
- /* @__PURE__ */Tv("line",{x1:e.xRange[0],x2:e.xRange[1],y1:n,y2:n,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),l.map(e=>/* @__PURE__ */Nv("g",{children:[
234
- /* @__PURE__ */Tv("line",{x1:e.x,x2:e.x,y1:n,y2:n+5,stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1}),
235
- /* @__PURE__ */Tv("text",{x:e.x,y:Math.min(i[1]-8,n+18),textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,children:e.label})]},`${e.label}-${e.x}`))]})}}import{Fragment as Bv,jsx as jv,jsxs as Wv}from"react/jsx-runtime";var Yv={flow:{fill:"rgba(59, 130, 246, 0.14)",stroke:"rgba(96, 165, 250, 0.7)",accent:"#60a5fa"},capacity:{fill:"rgba(251, 146, 60, 0.18)",stroke:"rgba(251, 146, 60, 0.85)",accent:"#fb923c"},portal:{fill:"rgba(244, 114, 182, 0.14)",stroke:"rgba(244, 114, 182, 0.7)",accent:"#f472b6"},absorb:{fill:"rgba(52, 211, 153, 0.18)",stroke:"rgba(52, 211, 153, 0.8)",accent:"#34d399"}};function qv(e){return 6.2*e.length}function Xv(e,t){let i=e.trim();if(i.length<=t)return i;if(t<=1)return i.slice(0,1);let r=i.split(/\s+/).filter(Boolean).map(e=>e[0]).join("").toUpperCase();return r.length>1&&r.length<=t?r:t<=3?i.slice(0,t).toUpperCase():`${i.slice(0,Math.max(1,t-2))}..`}function Gv(e,t,i="auto"){let r=Math.max(1,Math.floor(t/6.2)),n="compact"===i?Xv(e,r):"full"===i||qv(e)<=t?e:Xv(e,r);return{text:n,textLength:qv(n)>t?Math.max(4,t):void 0}}function Vv(e){return e.absorb?"absorb":e.portalTarget?"portal":null!=e.capacity?"capacity":"flow"}function Hv(e){if(null!=e.capacity){let t=null!=e.queueDepth?` · q ${e.queueDepth}`:"";return e.capacityLabel?`${e.capacityLabel}${t}`:`cap ${Number.isInteger(e.capacity)?String(e.capacity):e.capacity.toFixed(1)}${t}`}return e.absorb?"absorb":e.portalTarget?"portal":"flow"}function Uv(e,t={}){let{showFlowSpine:i=!0,showStageCounts:r=!0,showCapacityBadges:n=!0,showGroupSockets:o=!0,stageLabelMode:a="auto",outlineStages:s=!1,testId:l="process-flow-chrome"}=t,{width:c,height:u,left:d,right:h,topY:f,bottomY:p,midY:g,stages:m,groups:y=[]}=e,x=p-f;/* @__PURE__ */
236
- return Wv("svg",{"aria-hidden":"true","data-testid":l,"data-outline-stages":s?"true":void 0,width:c,height:u,viewBox:`0 0 ${c} ${u}`,style:{position:"absolute",inset:0,pointerEvents:"none"},className:["semiotic-process-chrome",s?"semiotic-process-chrome--outline-stages":null].filter(Boolean).join(" "),children:[
237
- /* @__PURE__ */jv("defs",{children:/* @__PURE__ */Wv("linearGradient",{id:"semiotic-process-floor",x1:"0",x2:"0",y1:"0",y2:"1",children:[
238
- /* @__PURE__ */jv("stop",{offset:"0%",stopColor:"var(--semiotic-process-floor, var(--semiotic-bg, #0f172a))",stopOpacity:"0.2"}),
239
- /* @__PURE__ */jv("stop",{offset:"100%",stopColor:"var(--semiotic-process-lane, var(--semiotic-surface, #1e293b))",stopOpacity:"0.55"})]})}),
240
- /* @__PURE__ */jv("rect",{x:0,y:0,width:c,height:u,fill:"url(#semiotic-process-floor)"}),
241
- /* @__PURE__ */jv("rect",{x:d-6,y:f-8,width:h-d+12,height:x+16,rx:14,fill:"var(--semiotic-process-lane, var(--semiotic-surface, #111827))",fillOpacity:.45,stroke:"var(--semiotic-process-border, var(--semiotic-border, #334155))",strokeOpacity:.95}),i?/* @__PURE__ */jv("line",{x1:d+8,x2:h-8,y1:g,y2:g,stroke:"var(--semiotic-process-border, var(--semiotic-border, #475569))",strokeWidth:2,strokeDasharray:"6 8",opacity:.55}):null,m.map((e,t)=>{let i=Vv(e),o=Yv[i],l=Math.max(12,e.width-8),c=mu(l-8,22,88),d=Math.max(8,c-10),h=Gv(e.label,d,a),y="none"!==a&&l-8>=22,b=Hv(e),v=Gv(b,Math.max(16,l-10),"auto"),w=n&&!1!==e.showBadge&&l>=32,k=null!=e.count?`n=${e.count}${null!=e.processed?` done ${e.processed}`:""}`:"",S=Gv(k,Math.max(16,l-8),"auto"),A=Math.max(30,f-15),M=A-13;/* @__PURE__ */
242
- return Wv("g",{"data-stage":e.id,"data-role":i,children:[
243
- /* @__PURE__ */jv("rect",{className:"semiotic-process-chrome__stage-bay",x:e.x0+4,y:f+6,width:l,height:x-12,rx:10,fill:s?"none":o.fill,stroke:o.stroke,strokeWidth:s?1.85:"flow"===i?1:1.6}),t<m.length-1?/* @__PURE__ */jv("polygon",{points:`${e.x1-2},${g-7} ${e.x1+8},${g} ${e.x1-2},${g+7}`,fill:o.accent,opacity:.85}):null,y?/* @__PURE__ */Wv(Bv,{children:[
244
- /* @__PURE__ */jv("rect",{className:"semiotic-process-chrome__stage-label-bg",x:e.x-c/2,y:M,width:c,height:18,rx:9,fill:"var(--semiotic-bg, #0f172a)",fillOpacity:.75,stroke:o.stroke}),
245
- /* @__PURE__ */Wv("text",{x:e.x,y:A,textAnchor:"middle",fill:o.accent,fontSize:10,fontWeight:800,className:"semiotic-process-chrome__stage-label",textLength:h.textLength,lengthAdjust:h.textLength?"spacingAndGlyphs":void 0,children:[
246
- /* @__PURE__ */jv("title",{children:e.label}),h.text]})]}):null,w?/* @__PURE__ */Wv("text",{x:e.x,y:f+22,textAnchor:"middle",fill:"var(--semiotic-process-muted, var(--semiotic-text-secondary, #94a3b8))",fontSize:9,fontWeight:700,textLength:v.textLength,lengthAdjust:v.textLength?"spacingAndGlyphs":void 0,children:[
247
- /* @__PURE__ */jv("title",{children:b}),v.text]}):null,r&&null!=e.count?/* @__PURE__ */Wv("text",{x:e.x,y:Math.min(u-8,p+16),textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #e2e8f0))",fontSize:11,fontWeight:800,textLength:S.textLength,lengthAdjust:S.textLength?"spacingAndGlyphs":void 0,children:[
248
- /* @__PURE__ */jv("title",{children:k}),S.text]}):null]},e.id)}),o?y.map((e,t)=>{let i=e.total??0,r=e.absorbed??0,n=e.complete??(i>0&&r>=i),o=!n&&i>0&&r/i>=.75,a=n?"rgba(52, 211, 153, 0.35)":o?"rgba(251, 191, 36, 0.28)":"rgba(15, 23, 42, 0.75)",s=n?"#34d399":o?"#fbbf24":"var(--semiotic-border, #64748b)",l=i>0?`${r}/${i}${n?" shipped":o?" almost":""}`:`feature ${t+1}`,c=mu(Math.max(54,qv(e.label)+18,qv(l)+16),54,104),u=Gv(e.label,c-12,"auto"),d=Gv(l,c-12,"auto");/* @__PURE__ */
249
- return Wv("g",{"data-group":e.id,children:[
250
- /* @__PURE__ */jv("rect",{x:e.x-c/2,y:e.y-22,width:c,height:44,rx:10,fill:a,stroke:s,strokeWidth:1.5}),
251
- /* @__PURE__ */Wv("text",{x:e.x,y:e.y-4,textAnchor:"middle",fill:"var(--semiotic-process-text, var(--semiotic-text, #f8fafc))",fontSize:10,fontWeight:800,textLength:u.textLength,lengthAdjust:u.textLength?"spacingAndGlyphs":void 0,children:[
252
- /* @__PURE__ */jv("title",{children:e.label}),u.text]}),
253
- /* @__PURE__ */Wv("text",{x:e.x,y:e.y+12,textAnchor:"middle",fill:s,fontSize:9,fontWeight:700,textLength:d.textLength,lengthAdjust:d.textLength?"spacingAndGlyphs":void 0,children:[
254
- /* @__PURE__ */jv("title",{children:l}),d.text]})]},e.id)}):null]})}import{jsx as Kv}from"react/jsx-runtime";function Zv(e,t,i={},r){if(!1===t||!e)return;let{volume:n,stages:o,groups:a,groupCompletion:s}=e,l=new Map(n.stages.map(e=>[e.id,e])),c=new Map(s.map(e=>[e.id,e]));return({size:e})=>{let t=Number(e[0])||n.width,s=Number(e[1])||n.height,u=o.map(e=>{let t=l.get(e.id),r=i[`process-stage-${e.id}`];return{id:e.id,label:e.label,x0:t?.x0??e.x-e.width/2,x1:(t?.x0??e.x-e.width/2)+(t?.width??e.width),x:e.x,width:t?.width??e.width,count:e.count,capacity:e.capacity,absorb:e.absorb,portalTarget:e.portalTarget,queueDepth:r?.queueDepth,processed:r?.processedCount}}),d=a.map(e=>{let t=c.get(e.id);return{id:e.id,label:e.label??e.id,x:e.anchor?.x??e.x??0,y:e.anchor?.y??e.y??0,absorbed:t?.absorbed,total:t?.total,complete:t?.complete}});return Uv({width:t,height:s,left:n.left,right:n.right,topY:n.topY,bottomY:n.bottomY,midY:n.midY,stages:u,groups:d},{showCapacityBadges:!0,showGroupSockets:!0,...r})}}function Qv(e,t,i){if(!1===i||!t||0===e.length)return;let r=new Map(t.volume.stages.map(e=>[e.id,e]));return({size:i})=>{let n=[Number(i[0])||t.volume.width,Number(i[1])||t.volume.height],o=Ig(n),a=e.reduce((e,t)=>Math.max(e,t.value),1),s=Math.min(48,.18*o.plot.height),l=o.plot.y+6;/* @__PURE__ */
255
- return Kv("svg",{"aria-hidden":"true","data-testid":"process-flow-projection-overlay",width:n[0],height:n[1],viewBox:`0 0 ${n[0]} ${n[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:t.stages.map((t,i)=>{let n=e[i];if(!n)return null;let o=r.get(t.id);if(!o)return null;let c=Math.max(2,n.value/a*s),u=Math.max(8,.35*o.width);/* @__PURE__ */
256
- return Kv("rect",{x:o.x-u/2,y:l,width:u,height:c,rx:2,fill:"var(--semiotic-primary, #4e79a7)",fillOpacity:.18,stroke:"var(--semiotic-primary, #4e79a7)",strokeOpacity:.45,strokeWidth:1},t.id)})})}}function Jv(e){return Math.abs(e)>=1e3?e.toLocaleString(void 0,{maximumFractionDigits:0}):e.toLocaleString(void 0,{maximumFractionDigits:1})}function ew(e){return e.map((e,t)=>`${0===t?"M":"L"} ${e.x} ${e.y}`).join(" ")}import{jsx as tw,jsxs as iw}from"react/jsx-runtime";function rw(e,t){let{showNodeLabels:i,showSensors:r,showStaticFlow:n}=t;if(e&&(n||r||i))return({size:t})=>{let o=[Number(t[0])||760,Number(t[1])||420],a=e.links.reduce((e,t)=>Math.max(e,t.throughput),1),s=new Set(e.nodes.map(e=>e.sensorId));/* @__PURE__ */
257
- return iw("svg",{"aria-hidden":"true","data-testid":"physical-flow-static-flow-overlay",width:o[0],height:o[1],viewBox:`0 0 ${o[0]} ${o[1]}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[n?e.links.map(e=>{let t=3+e.throughput/a*16,i=e.path[Math.floor(e.path.length/2)];/* @__PURE__ */
258
- return iw("g",{children:[
259
- /* @__PURE__ */tw("path",{d:ew(e.path),fill:"none",stroke:"var(--semiotic-border, #d1d5db)",strokeWidth:t+5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.26}),
260
- /* @__PURE__ */tw("path",{d:ew(e.path),fill:"none",stroke:"var(--semiotic-primary, #4e79a7)",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round",opacity:.16}),i?/* @__PURE__ */tw("text",{x:i.x,y:i.y-t/2-5,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #555)",fontSize:10,fontWeight:700,children:Jv(e.throughput)}):null]},e.id)}):null,e.nodes.map(e=>/* @__PURE__ */iw("g",{children:[r&&s.has(e.sensorId)?/* @__PURE__ */tw("rect",{"data-testid":"physical-flow-sensor-overlay",x:e.x-12,y:e.y-12,width:24,height:24,rx:4,fill:"none",stroke:"var(--semiotic-warning, #f59e0b)",strokeDasharray:"3 3",strokeWidth:1.5,opacity:.88}):null,n?/* @__PURE__ */tw("circle",{cx:e.x,cy:e.y,r:6,fill:"var(--semiotic-bg, #fff)",stroke:"var(--semiotic-text-secondary, #555)",strokeWidth:1.2}):null,i?/* @__PURE__ */tw("text",{x:e.x,y:e.y-14,textAnchor:"middle",fill:"var(--semiotic-text, #111827)",fontSize:11,fontWeight:800,children:e.label}):null]},e.id))]})}}import{Fragment as nw,jsx as ow,jsxs as aw}from"react/jsx-runtime";function sw({layout:e,compact:t,showLabels:i}){let r=t?Math.round(.14*e.height):Math.max(80,e.routeY-180),n=t?Math.max(6,Math.round(.72*e.height)):Math.min(360,e.height-170);/* @__PURE__ */
261
- return ow(nw,{children:e.gates.map(o=>/* @__PURE__ */aw("g",{children:[
262
- /* @__PURE__ */ow("rect",{x:o.x-o.width/2,y:r,width:o.width,height:n,rx:t?2:12,fill:o.color??"var(--semiotic-primary, #38bdf8)",fillOpacity:.1,stroke:o.color??"var(--semiotic-primary, #38bdf8)",strokeDasharray:"5 5",strokeOpacity:.7}),i?/* @__PURE__ */ow("text",{x:o.x,y:Math.max(64,e.routeY-196),fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:o.label??o.id}):null]},o.id))})}function lw({layout:e,states:t,compact:i=!1}){return i?/* @__PURE__ */ow("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:/* @__PURE__ */ow(sw,{layout:e,compact:!0,showLabels:!1})}):/* @__PURE__ */aw("svg",{"aria-hidden":"true",viewBox:`0 0 ${e.width} ${e.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[
263
- /* @__PURE__ */ow("path",{d:`M ${e.startX-42} ${e.routeY} C ${.24*e.width} ${e.routeY-70}, ${.42*e.width} ${e.routeY+78}, ${.58*e.width} ${e.routeY} S ${.78*e.width} ${e.routeY-82}, ${e.socketX+36} ${e.routeY}`,fill:"none",stroke:"var(--semiotic-primary, #38bdf8)",strokeDasharray:"18 12",strokeLinecap:"round",strokeOpacity:.45,strokeWidth:7}),
264
- /* @__PURE__ */ow("line",{x1:Math.round(.06*e.width),x2:Math.round(.94*e.width),y1:e.crashY,y2:e.crashY,stroke:"var(--semiotic-danger, #ef4444)",strokeDasharray:"3 7",strokeOpacity:.64}),
265
- /* @__PURE__ */ow("text",{x:Math.round(.07*e.width),y:e.crashY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:9,fontWeight:800,children:"CRASH LINE"}),
266
- /* @__PURE__ */ow(sw,{layout:e,compact:!1,showLabels:!0}),
267
- /* @__PURE__ */aw("g",{children:[
268
- /* @__PURE__ */ow("rect",{x:e.socketX-52,y:e.routeY-56,width:104,height:112,rx:13,fill:"var(--semiotic-success, #22c55e)",fillOpacity:.12,stroke:"var(--semiotic-success, #22c55e)",strokeWidth:1.5}),
269
- /* @__PURE__ */ow("text",{x:e.socketX,y:e.routeY-72,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"SOCKET"})]}),
270
- /* @__PURE__ */aw("g",{children:[
271
- /* @__PURE__ */ow("rect",{x:e.graveyardX-82,y:e.graveyardY-34,width:164,height:58,rx:11,fill:"var(--semiotic-danger, #ef4444)",fillOpacity:.16,stroke:"var(--semiotic-danger, #ef4444)",strokeOpacity:.7}),
272
- /* @__PURE__ */ow("text",{x:e.graveyardX,y:e.graveyardY-8,fill:"var(--semiotic-danger, #ef4444)",fontSize:10,fontWeight:800,textAnchor:"middle",children:"GRAVEYARD"}),
273
- /* @__PURE__ */ow("text",{x:e.graveyardX,y:e.graveyardY+12,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,textAnchor:"middle",children:t.some(e=>e.killed)?"lift shut off":"too heavy or too small"})]})]})}function cw(e){return e.map(e=>({label:e.id,value:Math.max(0,Number(e.viability)||0),outcome:e.outcome||e.stage||"in-process"}))}function uw({states:e,layout:t}){let i=cw(e);if(!i.length)return null;let r=i.reduce((e,t)=>Math.max(e,t.value),1),n=Math.max(40,(t.width-80)/i.length);/* @__PURE__ */
274
- return aw("svg",{"aria-hidden":"true","data-testid":"gauntlet-projection-overlay",width:t.width,height:t.height,viewBox:`0 0 ${t.width} ${t.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},children:[
275
- /* @__PURE__ */ow("text",{x:36,y:18,fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:800,children:"SETTLED · viability / outcome"}),i.map((e,t)=>{let i=40+t*n,o=Math.max(2,e.value/r*28),a=/kill|crash|block|grave/i.test(e.outcome);/* @__PURE__ */
276
- return aw("g",{children:[
277
- /* @__PURE__ */ow("rect",{x:i+.18*n,y:28-o+22,width:Math.max(10,.45*n),height:o,rx:2,fill:a?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",fillOpacity:.35,stroke:a?"var(--semiotic-danger, #ef4444)":"var(--semiotic-success, #16a34a)",strokeOpacity:.55,strokeWidth:1}),
278
- /* @__PURE__ */ow("text",{x:i+.4*n,y:62,textAnchor:"middle",fill:"var(--semiotic-text-secondary, #64748b)",fontSize:9,fontWeight:700,children:e.label})]},e.label)})]})}function dw(e,t){return e?"sparkline"===t?{top:2,right:2,bottom:2,left:2}:{top:8,right:8,bottom:8,left:8}:{top:0,right:0,bottom:0,left:0}}var hw={margin:(e,t)=>dw(t.compactMode,e.mode)};function fw(e,t){return e?t?i=>$g.createElement($g.Fragment,null,"function"==typeof e?e(i):e,"function"==typeof t?t(i):t):e:t}function pw(e,t,i){let r=t[i];return"boolean"==typeof r?r:!0!==e.__compactMode}var gw=["#356b63","#a34b43","#c08b38","#3e5f83","#785b7c","#6e7740","#8f5c3a","#41717b"];function mw(e){return gw[xn(e)%gw.length]}function yw(e,t,i,r){let n=e.datum,o={stroke:r.stroke??("product"===n?.kind?"#fffaf0":"#26323a"),strokeWidth:r.strokeWidth??("product"===n?.kind?1.8:1.1),opacity:r.opacity??.96};if(!n?.__crucible)return{...o,fill:r.color??"#b8792d"};if("product"===n.kind){let e=t.products[n.semanticId];return{...o,fill:r.color??e?.color??mw(e?.id??n.semanticId)}}let a,s=t.components[n.semanticId];return s?(a="status"===i?s.status:"outlet"===i?s.outletId??"in chamber":"product"===i?s.productIds[0]??"unalloyed":"category"===i||null==i?s.category:String("function"==typeof i?i(s.datum)??"unassigned":s.datum[String(i)]??"unassigned"),{...o,fill:r.color??mw(a)}):{...o,fill:r.color??"#356b63"}}function xw(e,t){let i=e.datum;if(i?.__crucible)return"product"===i.kind?t.products[i.semanticId]?.label:t.components[i.semanticId]?.label}var bw={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a=n.bins??21,s=n.seed??1,l=Math.max(1,Math.round(n.pegRows??a-1)),c="mechanical"===(n.simulationMode??n.mode),u=Oy({data:c?zg({bins:a,branchProbability:n.branchProbability,count:n.mechanicalCount,pegRows:l,seed:s}):Array.isArray(e)?e:[],valueAccessor:n.valueAccessor||"value",bins:a,ballRadius:n.ballRadius??("sparkline"===n.mode?1.5:"context"===n.mode?4:6),seed:s,size:o,valueExtent:c?[0,l]:n.valueExtent});return{...r,config:u.config,initialSpawns:u.initialSpawns,initialSpawnPacing:u.initialSpawnPacing,projectionRows:u.projectionRows,foregroundGraphics:fw(Fv(u.projectionRows,a,pw(r,n,"showProjection"),u.metadata,n.referenceLines),r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy||(c?"side":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},vw={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a=Yy({data:Array.isArray(e)?e:[],timeAccessor:n.timeAccessor||"time",arrivalAccessor:n.arrivalAccessor||"arrivalTime",watermarkAtArrivalAccessor:n.watermarkAtArrivalAccessor,windows:n.windows||{size:10},watermark:n.watermark,ballRadius:n.ballRadius??7,seed:n.seed??1,size:o,timeExtent:n.timeExtent,timeScale:n.timeScale??1});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:fw(Ev(a.projectionRows,a.metadata,pw(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||n.timeAccessor||"time"})}}},ww={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,400],a="mechanical"===(n.simulationMode??n.mode),s=Uy({data:a?Gy({categories:n.mechanicalCategories,count:n.mechanicalCount,seed:n.seed??1,unitValue:n.unitValue??1}):Array.isArray(e)?e:[],categoryAccessor:n.categoryAccessor||"category",valueAccessor:n.valueAccessor||(a?"value":void 0),unitValue:n.unitValue??1,ballRadius:n.ballRadius??8,seed:n.seed??1,size:o});return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:s.projectionRows,foregroundGraphics:fw(Ov(s.projectionRows,n.ballRadius??8,pw(r,n,"showProjection"),Number.isFinite(n.unitValue)&&n.unitValue>0?n.unitValue:1),r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy||(a?"category":void 0),"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.valueAccessor||"value"})}}},kw={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[600,360],a=Qy({data:Array.isArray(e)?e:[],xAccessor:n.xAccessor||"x",groupAccessor:n.groupAccessor,radiusAccessor:n.radiusAccessor,pointRadius:n.pointRadius??5,seed:n.seed??1,size:o,xExtent:n.xExtent,collisionIterations:n.collisionIterations,settle:n.settle});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:fw(Dv(a.metadata,pw(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy||n.groupAccessor,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.xAccessor||"x"})}}},Sw={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,420],a=Array.isArray(n.stages)?n.stages:[],s=$x({data:Array.isArray(e)?e:[],stages:a,size:o,idAccessor:n.idAccessor,stageAccessor:n.stageAccessor||"stage",groupBy:n.groupBy,groupLabelAccessor:n.groupLabelAccessor,workAccessor:n.workAccessor,radiusAccessor:n.radiusAccessor,ballRadius:n.ballRadius??6,seed:n.seed??1,groupCompletion:n.groupCompletion,groupAnchorAlong:n.groupAnchorAlong,settle:n.settle??!0,gravityX:n.gravityX,gravityY:n.gravityY}),l=s.metadata;return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:s.projectionRows,regionEffects:l?.regionEffects,backgroundGraphics:fw(Zv(s.metadata,pw(r,n,"showChrome"),{},n.chromeOptions),r.backgroundGraphics),foregroundGraphics:fw(Qv(s.projectionRows,s.metadata,pw(r,n,"showProjection")),r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy||n.groupBy,"#4e79a7",{styleRules:n.styleRules,valueAccessor:n.workAccessor||n.stageAccessor||"stage"})}}},Aw={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,520],a=Kx({data:Array.isArray(e)?e:[],size:o,gates:n.gates,positiveProperties:n.positiveProperties,negativeProperties:n.negativeProperties,crashOffset:n.crashOffset,idAccessor:n.idAccessor,positiveAccessor:n.positiveAccessor,negativeAccessor:n.negativeAccessor,metricsAccessor:n.metricsAccessor,initialViability:n.initialViability,projectPlacement:n.projectPlacement,coreBody:n.coreBody,viability:n.viability});return{...r,config:a.config,initialSpawns:a.initialSpawns,projectionRows:[],backgroundGraphics:fw(pw(r,n,"showChrome")?$g.createElement(lw,{layout:a.layout,states:a.states,compact:!0===r.__compactMode}):void 0,r.backgroundGraphics),foregroundGraphics:fw(pw(r,n,"showProjection")?$g.createElement(uw,{layout:a.layout,states:a.states}):void 0,r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy)}}},Mw={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[900,520],a=hv({data:Array.isArray(e)?e:[],phases:Array.isArray(n.phases)?n.phases:[],products:Array.isArray(n.products)?n.products:void 0,outlets:Array.isArray(n.outlets)?n.outlets:void 0,events:Array.isArray(n.events)?n.events:void 0,idAccessor:n.idAccessor,labelAccessor:n.labelAccessor,categoryAccessor:n.categoryAccessor,amountAccessor:n.amountAccessor,metricsAccessor:n.metricsAccessor,initialStateAccessor:n.initialStateAccessor,metrics:n.metrics,size:o,seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange}),s=dv(a,"snapshot"===n.playback?uv(a,n.snapshotAt):a.duration).state,l=n.projection&&"object"==typeof n.projection?n.projection:{groupBy:"outlet",measure:"count"},c=$b(s,l),u=l.measure??"count",d=Rv(c.map(e=>({id:e.key,label:e.label,count:e.count,secondary:"count"===u||"amount"===u?e.amount:Number(e.metrics[u]??0),secondaryLabel:"count"===u||"amount"===u?n.amountLabel??"amount":u,metadata:{amount:e.amount,metrics:e.metrics,status:e.status,outletId:e.outletId,category:e.category,productId:e.productId}}))),h={seed:n.seed,bodyRadius:"number"==typeof n.bodyRadius?n.bodyRadius:void 0,radiusRange:n.radiusRange},f=t??n.colorBy??"category",p=!1===n.showChrome?null:$g.createElement(_v,{layout:a.layout,phases:a.phases,state:s,compact:o[0]<520||o[1]<360}),g=!1===n.showProjection?null:$g.createElement(Pv,{rows:c,layout:a.layout,projection:l,amountLabel:n.amountLabel});return{...r,config:a.config,initialSpawns:ov(s,a.layout,h),projectionRows:d,bodyStyle:e=>yw(e,s,f,n),getBodyLabel:e=>xw(e,s),renderBodySVG:yv,backgroundGraphics:fw(p,r.backgroundGraphics),foregroundGraphics:fw(g,r.foregroundGraphics)}}},$w={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[760,420],a=ax({nodes:Array.isArray(n.nodes)?n.nodes:[],links:Array.isArray(n.links)?n.links:Array.isArray(n.edges)?n.edges:Array.isArray(e)?e:[],nodeIdAccessor:n.nodeIdAccessor||"id",nodeXAccessor:n.nodeXAccessor||"x",nodeYAccessor:n.nodeYAccessor||"y",sourceAccessor:n.sourceAccessor||"source",targetAccessor:n.targetAccessor||"target",throughputAccessor:n.throughputAccessor||"value",pathAccessor:n.pathAccessor||"path",coordinateMode:n.coordinateMode||"auto",particleRate:n.particleRate??.16,maxParticles:n.maxParticles??180,particleRadius:n.particleRadius??4,flowSpeed:n.flowSpeed??90,pathConstraint:n.pathConstraint||"path",reducedMotion:!0,seed:n.seed??1,size:o});return{...r,config:a.config,initialSpawns:a.initialSpawns,initialSpawnPacing:a.initialSpawnPacing,projectionRows:a.projectionRows,foregroundGraphics:fw(rw(a.metadata,{showNodeLabels:!1!==n.showNodeLabels,showSensors:!1!==n.showSensors,showStaticFlow:!1!==n.showStaticFlow}),r.foregroundGraphics),bodyStyle:Lg(t||n.colorBy||"source")}}},_w={frameType:"physics",layout:hw,buildProps:(e,t,i,r,n)=>{let o=r.size??[700,380],a=M(r.theme),s=Tx({chartId:n.chartId,colorScheme:i,config:n.config,data:Array.isArray(e)?e:[],layout:n.layout,layoutConfig:n.layoutConfig,semantic:w(a)??{},size:o,themeCategorical:a.colors.categorical,xExtent:n.xExtent,yExtent:n.yExtent});return{...r,config:s.config,initialSpawns:s.initialSpawns,initialSpawnPacing:s.initialSpawnPacing,projectionRows:[],bodyStyle:s.result.bodyStyle??Lg(t||n.colorBy),backgroundGraphics:fw(r.backgroundGraphics,s.result.backgroundOverlays),foregroundGraphics:fw(r.foregroundGraphics,s.result.overlays)}}};function Iw(e){return e&&{fields:["nodeId"],..."object"==typeof e?e:{name:"string"==typeof e?e:"hover"}}}function Pw(e){let t=e.roles.occurrence;return"string"==typeof t?[t]:e.entityIds}function Lw(e,t={}){let i=new Set(t.templates??["repeated-state-episode"]),r=e.filter(e=>i.has(e.template)).map(e=>{let t="string"==typeof e.roles.state?e.roles.state:e.nodePath[0],i=e.nodePath[e.nodePath.length-1];return{id:`capsule:${e.id}`,matchId:e.id,template:e.template,entryState:t,exitState:i,entityCount:e.entityCount,occurrenceIds:Pw(e),selected:!1}}).sort((e,t)=>t.entityCount!==e.entityCount?t.entityCount-e.entityCount:e.id.localeCompare(t.id)),n=/* @__PURE__ */new Set;for(let e of r)if(!e.occurrenceIds.some(e=>n.has(e))){e.selected=!0;for(let t of e.occurrenceIds)n.add(t)}return r}function Rw(e,t=[],i){let r=void 0===i?void 0:new Set("string"==typeof i?[i]:i),n=t.filter(e=>!e.missingPrehistory&&void 0!==e.partition&&r?.has(e.partition)),o=new Set(n.map(e=>e.id)),a=new Set(n.map(e=>e.entityId)),s=/* @__PURE__ */new Map,l=0;for(let t of e){if(void 0!==i&&"string"==typeof t.roles.occurrence&&!o.has(t.roles.occurrence))continue;let e=Object.entries(t.entityWeights);0===e.length&&void 0===i&&(l+=t.entityCount);for(let[t,r]of e)(void 0===i||a.has(t))&&s.set(t,r)}return[...s.values()].reduce((e,t)=>e+t,l)}function Cw(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Tw(e,t){return Cw(e,t)?e[t]:void 0}function Nw(e,t){return e.slice(0,t+1).map(e=>e.replaceAll("%","%25").replaceAll(">","%3E")).join(">")}function Fw(e,t,i){return e.entries.find(e=>e.measureId===t&&e.subjectId===i)}function Ew(e){let t=e.spec.comparison;if(!t)return;let i=t.partitions.map(i=>{let r=Fw(e.ledger,t.denominatorMeasureId,i)?.value??0,n={};return n["repeated-state-episode"]=Rw(e.motifs.matches.filter(e=>"repeated-state-episode"===e.template),e.source.occurrences,i),{partition:i,assigned:r,motifUsers:n,outcomes:{purchases:Fw(e.ledger,"purchases",i)?.value??0}}});return{partitions:[...t.partitions],denominatorMeasureId:t.denominatorMeasureId,referencePartition:t.referencePartition,rows:i}}function Ow(e,t){let i=e.spec.comparison?.denominatorMeasureId??e.spec.motifs.denominatorRef??"assigned";return Fw(e.ledger,i,t)?.value}function zw(e,t,i){return 0===i||1e4*e%i!=0?Math.round((t-e)/Math.max(i,1)*1e4):1e4*(t-e)/i}function Dw(e,t={}){let i=t.templates??["repeated-state-episode"],r="ordinal"===e.spec.coordinate.kind?e.spec.coordinate.sectionIds:[],n=void 0!==t.partition?Ow(e,t.partition)??0:e.spec.comparison?e.comparison?.rows.reduce((e,t)=>e+t.assigned,0)??0:e.ledger.entries.find(t=>"global"===t.subjectKind&&t.measureId===e.spec.motifs.denominatorRef)?.value??0,o=i=>Rw(i,e.source.occurrences,t.partition??e.spec.comparison?.partitions),a=[],s=e.motifs.incompleteCandidates.length>0;for(let l of i)for(let i of r){let r=e.motifs.matches.filter(e=>e.template===l),c=o(r.filter(e=>e.completionSectionId===i)),u=o(r.filter(e=>e.intersectSectionIds.includes(i)));a.push({template:l,sectionId:i,partition:t.partition,completionCount:c,intersectionCount:u,denominator:n,status:s?"incomplete":"exact"})}return{templates:i,sections:r,cells:a}}function Bw(e){return e.entityCount??1}function jw(e){if(!e.missingPrehistory)return{id:`group:${e.id}`,occurrenceId:e.id,partition:e.partition,nodePath:e.nodePath,entityCount:Bw(e),...e.stepEntityCounts&&{stepEntityCounts:[...e.stepEntityCounts]},signature:Nw(e.nodePath,e.nodePath.length-1)}}function Ww(e){let t=e.prefixForest;if(!t)return{atlas:e,groups:[],signatureOrder:[],ribbons:[],capsules:[],profile:Dw(e),differences:[],prefixForest:{kind:"observed-prefix",rootIds:[],nodes:[],order:[]},sceneSeeds:{nodes:[],edges:[]}};let i=(e.source.occurrences??[]).map(jw).filter(e=>!!e),r=/* @__PURE__ */new Map;for(let e of i){let i=t.order.indexOf(e.signature),n=r.get(e.signature),o=-1===i?t.order.length:i;(null==n||o<n)&&r.set(e.signature,o)}let n=[...new Set(i.map(e=>e.signature))].sort((e,t)=>{let i=(r.get(e)??0)-(r.get(t)??0);return 0!==i?i:e.localeCompare(t)}),o=[];for(let e of i)for(let t=0;t<e.nodePath.length-1;t++){let i=Nw(e.nodePath,t),r=Nw(e.nodePath,t+1);o.push({id:`ribbon:${e.id}:${t}`,groupId:e.id,partition:e.partition,fromPrefixId:i,toPrefixId:r,fromState:e.nodePath[t],toState:e.nodePath[t+1],entityCount:e.stepEntityCounts?.[t]??e.entityCount,...e.stepEntityCounts&&{toEntityCount:e.stepEntityCounts[t+1]}})}let a=Lw(e.motifs.matches),s=e.comparison??Ew(e),l=[];if(s&&s.partitions.length>=2){let e=s.rows[0],t=s.rows[1],i=Math.min(e.assigned,t.assigned)||e.assigned,r=e.motifUsers["repeated-state-episode"]??0,n=t.motifUsers["repeated-state-episode"]??0;l.push({motif:"repeated-state-episode",leftPartition:e.partition,rightPartition:t.partition,leftCount:r,rightCount:n,deltaCount:n-r,deltaBps:zw(r,n,i),denominator:i}),l.push({motif:"purchases",leftPartition:e.partition,rightPartition:t.partition,leftCount:e.outcomes.purchases??0,rightCount:t.outcomes.purchases??0,deltaCount:(t.outcomes.purchases??0)-(e.outcomes.purchases??0),deltaBps:zw(e.outcomes.purchases??0,t.outcomes.purchases??0,i),denominator:i})}let c={nodes:i.map(e=>({id:e.id,partition:e.partition,signature:e.signature})),edges:o.map(e=>({id:e.id,source:e.fromPrefixId,target:e.toPrefixId}))};return{atlas:e,groups:i,signatureOrder:n,ribbons:o,capsules:a,profile:Dw(e),differences:l,prefixForest:t,sceneSeeds:c}}function Yw(e,t){if(0===t||e.length<2)return e.map(e=>({...e}));let i=(e,t)=>{let i=t.x-e.x,r=t.y-e.y,n=Math.hypot(i,r)||1;return{x:-r/n,y:i/n}};return e.map((r,n)=>{let o=n>0?i(e[n-1],r):null,a=n<e.length-1?i(r,e[n+1]):null;if(!o||!a){let e=a??o??{x:0,y:0};return{x:r.x+e.x*t,y:r.y+e.y*t}}let s=o.x+a.x,l=o.y+a.y,c=Math.hypot(s,l);if(c<.001)return{x:r.x+a.x*t,y:r.y+a.y*t};s/=c,l/=c;let u=s*a.x+l*a.y;if(Math.abs(u)<.001)return{x:r.x+a.x*t,y:r.y+a.y*t};let d=4*Math.abs(t),h=t/u,f=Math.max(-d,Math.min(d,h));return{x:r.x+s*f,y:r.y+l*f}})}function qw(e,t){if(0===e.length)return"";if(1===e.length)return`M${e[0].x},${e[0].y}`;let i=Math.max(0,t),r=`M${e[0].x},${e[0].y}`;for(let t=1;t<e.length-1;t+=1){let n=e[t-1],o=e[t],a=e[t+1],s=Math.hypot(o.x-n.x,o.y-n.y),l=Math.hypot(a.x-o.x,a.y-o.y),c=Math.min(i,s/2,l/2);if(c<=.001){r+=` L${o.x},${o.y}`;continue}let u={x:o.x+(n.x-o.x)/s*c,y:o.y+(n.y-o.y)/s*c},d={x:o.x+(a.x-o.x)/l*c,y:o.y+(a.y-o.y)/l*c};r+=` L${u.x},${u.y} Q${o.x},${o.y} ${d.x},${d.y}`}let n=e[e.length-1];return`${r} L${n.x},${n.y}`}var Xw=(e,t,i)=>({x:e.x+(t.x-e.x)*i,y:e.y+(t.y-e.y)*i}),Gw=(e,t)=>Math.hypot(t.x-e.x,t.y-e.y);function Vw(e){let t=[e[0]];for(let i=1;i<e.length-1;i++){let r=e[i-1],n=e[i],o=e[i+1],a=Gw(r,n),s=Gw(n,o),l=Math.min(8,a/2,s/2);if(0===l)continue;let c=Xw(n,r,l/a),u=Xw(n,o,l/s);t.push(c);for(let e=1;e<=12;e++){let i=e/12;t.push(Xw(Xw(c,n,i),Xw(n,u,i),i))}}return t.push(e[e.length-1]),t.filter((e,i)=>0===i||Gw(t[i-1],e)>1e-8)}function Hw(e,t,i){if(e.length<2)return"";let r=Vw(e);if(r.length<2)return"";let n=[0];for(let e=1;e<r.length;e++)n.push(n[e-1]+Gw(r[e-1],r[e]));let o=n[n.length-1],a=Yw(r,1),s=[1,-1].map(e=>r.map((r,s)=>{let l=t+(i-t)*n[s]/o;return Xw(r,a[s],e*l/2)}));return[...s[0],...s[1].reverse()].map((e,t)=>`${0===t?"M":"L"}${e.x},${e.y}`).join(" ")+" Z"}function Uw(e){let t=-(e.reduce((e,t)=>e+t,0)+3*(e.length-1))/2;return e.map(e=>{let i=t+e/2;return t+=e+3,i})}var Kw={viewBox:[24,24],parts:[{d:"M5,0 H19 Q24,0 24,5 V19 Q24,24 19,24 H5 Q0,24 0,19 V5 Q0,0 5,0 Z",stroke:"accent"}]};function Zw(e){let t="";return e.split(">").map((e,i)=>t=i?`${t}>${e}`:e)}function Qw(e){let t=/* @__PURE__ */new Map;for(let i of e){let e=Zw(i.signature);i.nodePath.forEach((r,n)=>{let o=e[n],a=t.get(o);a||(a={id:o,state:r,depth:n+1,signatures:/* @__PURE__ */new Set},t.set(o,a)),a.signatures.add(i.signature)})}return[...t.values()]}var Jw=(e,t)=>e.stepEntityCounts?.[t]??e.entityCount,ek=({datum:e},t)=>({opacity:!t?.isActive||t.predicate(e)||null!=e?.fromNodeId&&t.predicate({...e,nodeId:e.fromNodeId})?1:.2}),tk=e=>{let t=e.config.braid,i=e.dimensions.plot,r=t.atlas.spec.comparison?.partitions??[...new Set(t.groups.map(e=>e.partition))],n=t.groups.filter(e=>r.includes(e.partition)&&e.nodePath.length>0),o=[],a=[],s=[];if(0===n.length)return{sceneNodes:a,sceneEdges:o,labels:s};let l=new Set(n.map(e=>e.signature)),c=[...t.signatureOrder.filter(e=>l.delete(e)),...l],u=new Map(c.map((e,t)=>[e,t])),d=[...n].sort((e,t)=>u.get(e.signature)-u.get(t.signature)),h=r.map(e=>d.filter(t=>t.partition===e)),f=Qw(d),p=br(f.map(e=>e.depth)),g=n.map(e=>br(e.stepEntityCounts??[e.entityCount])),m=br(g),y=e=>e<=0?0:Math.max(1,10*e/m),x=new Map(n.map((e,t)=>[e.id,y(g[t])])),b=i.height/r.length,{semantic:v}=e.theme,w=(e,t,i,r={})=>s.push({x:e,y:t,text:i,fill:v.text??"#333",fontSize:10,anchor:"middle",...r}),k={sourceRevision:t.atlas.provenance.sourceRevision,analysisRevision:t.atlas.analysisRevision,relationScopeId:"directed-admitted"},S=new Map(f.map(e=>{let t=h.map(t=>t.reduce((t,i)=>t+(e.signatures.has(i.signature)?x.get(i.id)+3:0),5));return[e.id,br(t,24)]})),A=br([...S.values()],24),M=Math.min(i.width/4,A/2+16),$=(i.width-2*M)/Math.max(p-1,1),_=e=>i.x+M+(e-1)*$,I=48+A/2,P=22+A/2,L=(e,t)=>e+I+(u.get(t)+.5)*Math.max(0,b-I-P)/c.length,R=(t,i,r,n,a)=>{let s=Jw(i,n),l=Jw(i,a),c=y(s),u=y(l);if(0===c&&0===u)return;let d=c!==u,h=e.resolveColor(i.signature);o.push({type:"curved",id:r,pathD:d?Hw(t,c,u):qw(t,8),style:{fill:d?h:"none",fillOpacity:1,stroke:d?"none":h,strokeWidth:d?0:c},datum:{...k,id:r,kind:"braid-track",nodeId:i.nodePath[a],fromNodeId:i.nodePath[n],groupId:i.id,signature:i.signature,partition:i.partition,entityCount:i.entityCount,fromStep:n,toStep:a,fromCount:s,toCount:l,falseRoot:!1},accessibleDatum:{journey:i.nodePath.join(" → "),partition:i.partition??"all",fromStep:n+1,toStep:a+1,fromCount:s,toCount:l}})};return r.forEach((e,t)=>{let r=i.y+t*b,n=h[t];if(e&&w(i.x+8,r+14,e,{fontSize:12,fontWeight:600,anchor:"start"}),0===n.length)return;for(let e=1;e<=p;e++)w(_(e),r+34,`Step ${e}`);let o=/* @__PURE__ */new Map;for(let t of f){let i=n.filter(e=>t.signatures.has(e.signature));if(0===i.length)continue;let s=_(t.depth),l=mg([...t.signatures].map(e=>L(r,e))),c=Uw(i.map(e=>x.get(e.id)));o.set(t.id,new Map(i.map((e,t)=>[e.id,{x:s,y:l+c[t],offset:c[t]}])));let u=S.get(t.id),d={state:t.state,step:t.depth,partition:e??"all"},h=`vertex:${e??"all"}:${t.id}`;a.push({type:"glyph",id:h,cx:s,cy:l,size:u,depth:t.depth,label:`${t.state} (step ${t.depth})`,glyph:Kw,accent:v.border??"#888",style:{fill:v.surface??"#fff"},datum:{...k,id:h,nodeId:t.state,kind:"braid-step",prefixId:t.id,...d},accessibleDatum:d}),w(s,l+u/2+12,t.state,{anchorPoint:[s,l]})}for(let t of n){let i=Zw(t.signature);for(let r=1;r<i.length;r++){let n=o.get(i[r-1]).get(t.id),a=o.get(i[r]).get(t.id),s=(n.x+a.x)/2-Math.sign(a.y-n.y)*a.offset,l=Math.abs(n.y-a.y)<1e-8?[n,a]:[n,{x:s,y:n.y},{x:s,y:a.y},a];R(l,t,`step:${e??"all"}:${i[r]}:${t.id}`,r-1,r)}}}),{sceneNodes:a,sceneEdges:o,labels:s,restyle:ek,restyleEdge:ek}};import*as ik from"react";import*as rk from"react";import{Fragment as nk,jsx as ok}from"react/jsx-runtime";var ak={type:"flat",matrix:[1,0,0,1,0,0],lift:0,scale:1,bounds:null,project:(e,t)=>[e,t],unproject:(e,t)=>[e,t],depth:(e,t)=>t,groundTransform:"matrix(1 0 0 1 0 0)",billboardTransform:(e,t)=>`translate(${e},${t})`},sk=/* @__PURE__ */Symbol.for("semiotic.networkPerspectiveContext");function lk(){let e=globalThis;return e[sk]??(e[sk]=rk.createContext(ak))}function ck(e,t,i){return t&&null!=e&&!1!==e?/* @__PURE__ */ok(uk,{frame:t,mode:i,children:e}):e}function uk({frame:e,mode:t,children:i}){if(!e)/* @__PURE__ */return ok(nk,{children:i});let r=lk();/* @__PURE__ */
279
- return ok(r.Provider,{value:e,children:"ground"===t?/* @__PURE__ */ok("g",{transform:e.groundTransform,children:i}):i})}import{Fragment as dk,jsx as hk}from"react/jsx-runtime";function fk(e,t){return"top"===t?e.thickness??0:Number.isFinite(t)?t:0}function pk(e){let[t,i,r,n,o,a]=e.matrix;return 1===t&&0===i&&0===r&&1===n&&0===o&&0===a}var gk=e=>Math.round(100*e)/100;function mk({z:e=0,children:t}){let i=rk.useContext(lk());if(pk(i))/* @__PURE__ */return hk(dk,{children:t});let[r,n,o,a,s,l]=i.matrix,c=l-i.lift*fk(i,e);/* @__PURE__ */
280
- return hk("g",{"data-perspective":"ground",transform:`matrix(${[r,n,o,a,s,c].map(gk).join(" ")})`,children:t})}function yk(e,t){let i=/* @__PURE__ */new Set,r=[t];for(;r.length;){let t=r.pop();if(i.has(t))continue;i.add(t);let n=Tw(e.children,t);Array.isArray(n)&&r.push(...n)}return i}function xk(e,t){let i=[],r=Tw(e.requiredChildren,t);if(void 0===r)return i;if(!Array.isArray(r))throw new Error("Invalid required-path dominator children");let n=[...r],o=/* @__PURE__ */new Set([t]);for(;n.length;){let t=n.pop(),r=Tw(e.requiredChildren,t);if("string"!=typeof t||o.has(t)||!Array.isArray(r))throw new Error("Invalid required-path dominator chain");o.add(t),i.push(t);for(let e of r)n.push(e)}return i.sort()}var bk=e=>{let{forest:t,selection:i,reading:r="organize"}=e.config,{atlas:n}=t,o=e.dimensions.plot,a=e.theme.semantic.text??"#273442",s=e.config.colors?.backbone??e.theme.semantic.textSecondary??"#8995a3",l=e.config.colors?.residual??e.theme.semantic.warning??"#b66631",c=e.config.colors?.required??e.theme.semantic.primary??"#3983a5",u=i?.analysisRevision===n.analysisRevision&&"directed-admitted"===i.relationScopeId&&n.source.nodes.some(e=>e.id===i.nodeId)?i.nodeId:void 0,d=/* @__PURE__ */new Map;for(let i of t.order)if(e.config.collapsedNodeIds?.includes(i)&&!d.has(i))for(let e of yk(t,i))e!==i&&d.set(e,i);let h=t.order.filter(e=>!d.has(e)),f=new Map(n.source.nodes.map(e=>[e.id,e])),p=/* @__PURE__ */new Map;for(let e of d.values())p.set(e,(p.get(e)??0)+1);let g=/* @__PURE__ */new Map;for(let e of n.source.edges){let t=d.get(e.source)??e.source;if(t===(d.get(e.target)??e.target)&&(e.source!==t||e.target!==t)){let i=g.get(t);i?i.push(e.id):g.set(t,[e.id])}}let m=[...n.sections.sectionIds];n.source.nodes.some(e=>!e.sectionId)&&m.push("Unsectioned");let y=new Map(n.source.nodes.map(e=>[e.id,e.sectionId??"Unsectioned"])),x=m.map(e=>h.filter(t=>y.get(t)===e)),b=/* @__PURE__ */new Map,v=[],w=[],k=[],S=[],A=(e,t,i,r=11,n)=>v.push({x:e,y:t,text:i,fill:a,anchor:"middle",fontSize:r,...n?{anchorPoint:n}:{}}),M=Math.max(16,Math.min(94,o.width/Math.max(1,m.length)-20));x.forEach((e,t)=>{let i=o.x+o.width*(t+.5)/m.length;A(i,o.y+18,m[t],12),e.forEach((t,r)=>{let n=o.y+58+(r+.5)*Math.max(40,o.height-110)/Math.max(1,e.length);b.set(t,{x:i,y:n})})});for(let t of h){let i=b.get(t),r=f.get(t),o=p.get(t)??0,a=g.get(t)??[],d=n.requiredPaths?.unreachableNodeIds.includes(t),h=r.completeness&&"known"!==r.completeness,m=h?"Unknown upstream":d?"Unreachable from roots":void 0;w.push({type:"glyph",id:t,cx:i.x,cy:i.y,size:34,glyph:{viewBox:[M,34],parts:[{d:`M6,0 H${M-6} Q${M},0 ${M},6 V28 Q${M},34 ${M-6},34 H6 Q0,34 0,28 V6 Q0,0 6,0 Z`,stroke:"accent"}]},accent:u===t?c:h?l:s,style:{fill:e.theme.semantic.surface??"#fff",strokeWidth:u===t?2.5:1},label:t,datum:{...r,nodeId:t,kind:"dependency-node",sourceRevision:n.provenance.sourceRevision,analysisRevision:n.analysisRevision,relationScopeId:"directed-admitted",hiddenCount:o,internalEdgeIds:a},accessibleDatum:{node:t,section:y.get(t),status:m??"Admitted",hiddenCount:o,internalEdges:a.join(", ")}});let x=[i.x,i.y];A(i.x,i.y+4,o?`${t} +${o}`:t,12,x),m?A(i.x,i.y+30,m,9,x):o&&A(i.x,i.y+30,`${a.length} internal links`,9,x)}let $,_=new Set(t.forest.backboneEdgeIds),I=new Set(e.config.highlightedEdgeIds),P=/* @__PURE__ */new Map;for(let e of n.source.edges){let t=d.get(e.source)??e.source,i=d.get(e.target)??e.target;if(t===i&&(e.source!==t||e.target!==i))continue;let r=b.get(t),a=b.get(i),u=JSON.stringify([t,i]),h=12*(P.get(u)??0);P.set(u,(P.get(u)??0)+1);let f,p,g=_.has(e.id),y=I.has(e.id)?c:g?s:l,x=a.x>r.x,v=r.x+(x?M/2:-M/2),w=a.x+(x?-M/2:M/2),A=[...b.values()].filter(e=>e.x>Math.min(r.x,a.x)&&e.x<Math.max(r.x,a.x));if(t===i)f=`M${r.x-14},${r.y-17} C${r.x-35-h},${r.y-64-h} ${r.x+35+h},${r.y-64-h} ${r.x+14},${r.y-17}`,p=1;else if(r.x===a.x){let e=a.y>r.y?1:-1,t=r.x+e*M/2,i=t+e*(32+h);f=`M${t},${r.y} C${i},${r.y} ${i},${a.y} ${t},${a.y}`,p=1===e?2:0}else if(A.length){let e=Math.min(r.y,a.y,...A.map(e=>e.y))-17-26-h,t=(o.width/m.length-M)/2*(x?1:-1);f=`M${v},${r.y} C${v+t},${r.y} ${v},${e} ${v+t},${e} H${w-t} C${w},${e} ${w-t},${a.y} ${w},${a.y}`,p=x?0:2}else if(x){let e=(v+w)/2;f=`M${v},${r.y} C${e},${r.y-h} ${e},${a.y-h} ${w},${a.y}`,p=0}else{let e=Math.min(r.y,a.y)-48-h;f=`M${v},${r.y} C${v-25},${e} ${w+25},${e} ${w},${a.y}`,p=2}k.push({type:"curved",id:e.id,pathD:f,style:{stroke:y,strokeWidth:I.has(e.id)?3:g?1.3:2,fill:"none"},datum:{...e,sourceRevision:n.provenance.sourceRevision,analysisRevision:n.analysisRevision,relationScopeId:"directed-admitted",kind:"dependency-edge",edgeClass:g?"backbone":"residual"},accessibleDatum:{edge:e.id,source:e.source,target:e.target,display:g?"backbone":"residual cross-link"}});let $=t===i?r.x+14:r.x===a.x?r.x+(a.y>r.y?M/2:-M/2):w,L=t===i?r.y-17:a.y;S.push(ik.createElement("path",{key:`arrow:${e.id}`,"data-dependency-edge":e.id,"data-source":e.source,"data-target":e.target,d:"M-6,-3 L0,0 L-6,3",fill:"none",stroke:y,transform:`translate(${$},${L}) rotate(${90*p})`}))}if("required-paths"===r&&u){let e=xk(t,u),i=[...new Set(e.map(e=>d.get(e)??e))].filter(e=>e!==u&&b.has(e));if(i.length){let e=i.map(e=>b.get(e)),t=Math.max(...e.map(e=>e.x))+M/2+8,r=Math.min(...e.map(e=>e.y))-23,n=Math.max(...e.map(e=>e.y))+23;$={x:t-7,y:r,width:7,height:n-r,z:"top"},S.push(ik.createElement("path",{key:"required-bracket",d:`M${t-7},${r} H${t} V${n} H${t-7}`,fill:"none",stroke:c,strokeWidth:2,"data-kind":"dominator-bracket"}))}A(o.x+o.width/2,o.y+o.height-16,e.length?`${u} lies on all admitted paths to ${e.join(", ")}${"incomplete"===n.requiredPaths?.status?" · incomplete scope":""}`:n.requiredPaths?`${u}: no other required targets in the admitted graph`:"Required paths have not been prepared")}let L=new Map(w.map(e=>[e.id,e.datum]));return{sceneNodes:w,sceneEdges:k,labels:v,restyle:(e,t)=>({opacity:t?.isActive&&!t.predicate(e.datum)?.2:1}),restyleEdge:(e,t)=>({opacity:t?.isActive&&![e.datum,L.get(String(e.datum?.source)),L.get(String(e.datum?.target))].some(e=>e&&t.predicate(e))?.2:1}),overlays:ik.createElement("g",{"aria-hidden":!0},ik.createElement(mk,{z:"top"},...S)),perspective:"manual",...e.perspective&&$?{perspectiveBounds:[$]}:{}}};import*as vk from"react";function wk(e,t,i){if(!Number.isFinite(t)||!Number.isFinite(i)||t<360||i<300)throw new Error("Circuit geometry needs at least 360 × 300 pixels");let r=[...e.atlas.sections.sectionIds];e.atlas.source.nodes.some(e=>!e.sectionId)&&r.push("Unsectioned");let n=hx({width:t,height:i-110,padX:22,padY:70,stages:r.map(e=>({id:e})),shape:"lane"}),o=new Map(e.atlas.source.nodes.map(e=>[e.id,e.sectionId??"Unsectioned"])),a=n.stages.flatMap(t=>{let r=e.order.filter(e=>o.get(e)===t.id),n=(i-235)/Math.max(1,r.length);if(r.length&&n<78)throw new Error("Increase circuit height to keep every module readable");return r.map((i,r)=>{let o=e.modules.find(e=>e.nodeId===i),a=Math.max(68,Math.min(142,t.width-56)),s=Math.min(68,n-10),l=t.x-a/2,c=95+(r+.5)*n-s/2;return{module:o,x:l,y:c,width:a,height:s,queue:{x:l+8,y:c+s-8,width:a-16,height:4},sensor:{x:l+a-5,y:c+s/2-4,width:8,height:8}}})}),s=new Map(a.map(e=>[e.module.nodeId,e])),l=new Set(e.residualEdgeIds),c=0,u=e.atlas.source.edges.map(e=>{let t,i=s.get(e.source),n=s.get(e.target),a=n.x>i.x,u=n.x===i.x,d=(t,i)=>{let r=t.module.ports.filter(e=>e.direction===i),n=r.findIndex(t=>t.edgeId===e.id);return t.y+10+(n+.5)*(t.height-20)/r.length},h={x:i.x+(a||u?i.width:0),y:d(i,"out")},f={x:n.x+(a?0:n.width),y:d(n,"in")};if(u){let r=h.x+18+5*c++;t=e.source===e.target?[h,{x:r,y:h.y},{x:r,y:i.y-15},{x:f.x-8,y:i.y-15},{x:f.x-8,y:i.y}]:[h,{x:r,y:h.y},{x:r,y:f.y},f]}else if(!a||Math.abs(r.indexOf(o.get(e.source))-r.indexOf(o.get(e.target)))>1){let e=a?1:-1,i=62+7*c++;t=[h,{x:h.x+16*e,y:h.y},{x:h.x+16*e,y:i},{x:f.x-16*e,y:i},{x:f.x-16*e,y:f.y},f]}else{let e=(h.x+f.x)/2;t=[h,{x:e,y:h.y},{x:e,y:f.y},f]}return{edgeId:e.id,source:e.source,target:e.target,residual:l.has(e.id),points:t,pathD:ew(t)}});return{width:t,height:i,modules:a,routes:u,sections:n.stages.map(e=>({id:e.id,x:e.x})),history:{x:42,y:i-88,width:t-84,height:46}}}function kk(e,t){let i=e.slice(1).map((t,i)=>Math.hypot(t.x-e[i].x,t.y-e[i].y)),r=i.reduce((e,t)=>e+t,0),n=Math.max(0,Math.min(1,t))*r;for(let t=0;t<i.length;t++){if(n<=i[t]){let r=i[t]?n/i[t]:0;return{x:e[t].x+(e[t+1].x-e[t].x)*r,y:e[t].y+(e[t+1].y-e[t].y)*r}}n-=i[t]}return e[e.length-1]}import*as Sk from"react";var Ak=Sk.createElement,Mk={observed:"#387e98",modeled:"#946344",residual:"#a56537",muted:"#778796",alarm:"#bb5149"};function $k(e,t={}){return{observed:t.observed??e.info??e.primary??Mk.observed,modeled:t.modeled??e.secondary??Mk.modeled,residual:t.residual??e.warning??Mk.residual,muted:t.muted??e.textSecondary??Mk.muted,alarm:t.alarm??e.danger??Mk.alarm}}var _k=e=>null===e?"unmeasured":e>=1e6?`${Number((e/1e6).toFixed(2))}m`:e>=1e3?`${Number((e/1e3).toFixed(1))}k`:String(e),Ik={stage:"M-5,0 H5",distributor:"M-5,0 H0 M0,0 L6,-5 M0,0 H6 M0,0 L6,5",queue:"M-6,-5 V5 H6 V-5 M-3,2 H3",retry:"M-5,2 A5,5 0 1,1 4,3 M4,-1 V4 H0","join-all":"M-6,-4 L0,0 L6,0 M-6,4 L0,0 M2,-5 V5",selector:"M-6,-4 L0,0 L6,0 M-6,4 L0,0 M1,-4 L5,0 L1,4",dependency:"M-5,-5 H5 V5 H-5 Z M-2,-2 L2,2 M-2,2 L2,-2",junction:"M0,-6 L6,0 L0,6 L-6,0 Z"},Pk={stage:"stage",distributor:"distributor",queue:"FIFO queue",retry:"retry episode","join-all":"all-member join",selector:"first success",dependency:"dependency gate",junction:"unclassified junction"};function Lk(e,t,i,r,n,o=Mk,a){let s=Object.values(t.entry.nodes).reduce((e,t)=>Math.max(e,t.queued??0),0)||1;return e.modules.map(e=>{let{module:l,x:c,y:u,width:d,height:h,queue:f}=e,p=t.entry.nodes[l.nodeId],g=n===l.nodeId?i:(p.queued??0)>0?o.alarm:o.muted,m=c+d/2,y="records"===l.semantics.unit?"rec":"attempts"===l.semantics.unit?"att":"roots",x=null!==p.capacity?`${_k(p.completions)} / ${_k(p.capacity)} ${y}/s`:null!==p.completions?`${_k(p.completions)} ${y}/s complete`:`${_k(p.arrivals)} ${y}/s offered`;return Ak("g",{key:l.id,"data-circuit-module":l.nodeId,"data-module-kind":l.kind,opacity:a?.(l.nodeId),"data-queued":p.queued??"unmeasured"},Ak("rect",{x:c,y:u,width:d,height:h,fill:"none",stroke:g,strokeWidth:n===l.nodeId?2.5:1}),Ak("path",{d:Ik[l.kind],transform:`translate(${c+10},${u+12})`,stroke:g,fill:"none",strokeWidth:1.4}),Ak("text",{x:m+5,y:u+16,textAnchor:"middle",fontSize:d<110?9:11,fontWeight:600,fill:r},l.semantics.label),Ak("text",{x:m,y:u+28,textAnchor:"middle",fontSize:8,fill:r},Pk[l.kind]),Ak("text",{x:m,y:u+41,textAnchor:"middle",fontSize:d<110?7:9,fill:r},x),Ak("text",{x:m,y:u+h-13,textAnchor:"middle",fontSize:8,fill:r},`Queue ${_k(p.queued)}`),null!==p.queued?Ak("rect",{...f,width:f.width*p.queued/s,fill:g,"data-circuit-gauge":"queue"}):null,Ak("rect",{...e.sensor,fill:i,"data-circuit-sensor":l.nodeId}),l.semantics.dependencyNodeIds?.length?Ak("text",{x:m,y:u-8,fontSize:8,textAnchor:"middle",fill:r,"data-circuit-dependency":l.nodeId},`Requires ${l.semantics.dependencyNodeIds.join(", ")}`):null)})}function Rk(e,t,i,r,n,o){let{history:a}=e,s=e.modules.find(e=>e.module.nodeId===o)?.module,l="records"===t.unit?"queued":"attempts",c=t.entries.map(e=>s?e.nodes[s.nodeId]["records"===t.unit?"queued":"arrivals"]:e.totals[l]),u=c.reduce((e,t)=>Math.max(e,t??0),0)||1,d=t.entries[0].at,h=t.entries[t.entries.length-1].at,f=h>d?h-d:1,p=e=>a.x+(e-d)/f*a.width,g="",m=!1;for(let[e,i]of t.entries.entries()){if(null===c[e]){m=!1;continue}let t=a.y+a.height-c[e]/u*a.height;g+=`${m?" H":"M"}${p(i.at)}${m?` V${t}`:`,${t}`}`,m=!0}return Ak("g",{"data-circuit-history":l,"data-history-module":s?.nodeId},Ak("text",{x:a.x,y:a.y-9,fill:n,fontSize:10},s?`${s.semantics.label} · ${"queued"===l?`queued ${s.semantics.unit}`:`offered ${s.semantics.unit}/s`} · aggregate observations`:"queued"===l?"Queued records · aggregate observations":"Offered attempts/s · aggregate observations"),Ak("path",{d:g,fill:"none",stroke:r,strokeWidth:2}),Ak("line",{x1:p(i.observedAt),x2:p(i.observedAt),y1:a.y,y2:a.y+a.height,stroke:n,strokeDasharray:"3 3","data-circuit-cursor":i.observedAt}),...t.entries.map(e=>Ak("text",{key:e.id,x:p(e.at),y:a.y+a.height+14,textAnchor:"middle",fontSize:9,fill:n},`${e.at}s`)))}function Ck(e,t,i,r){return{id:r.nodeId,nodeId:r.nodeId,kind:"circuit-module",moduleKind:r.kind,label:r.semantics.label,unit:r.semantics.unit,sourceRevision:t.sourceRevision,analysisRevision:e.atlas.analysisRevision,relationScopeId:"directed-admitted",editionId:t.id,editionKind:t.kind,synthetic:t.synthetic,mode:i.mode,observedAt:i.observedAt,...i.entry.nodes[r.nodeId]}}var Tk=e=>null===e?"unmeasured":String(e);function Nk(e,t,i,r){return[...t.modules.map(t=>{let n=Ck(e,i,r,t.module);return{id:n.id,bodyId:n.id,datum:n,x:t.x+t.width/2,y:t.y+t.height/2,width:t.width,height:t.height,shape:"rect",label:`${n.label}: ${n.moduleKind}`,description:`${n.label}. ${i.kind} at ${r.observedAt}s. Arrivals ${Tk(n.arrivals)} ${n.unit}/s; completions ${Tk(n.completions)} ${n.unit}/s; installed capacity ${Tk(n.capacity)} ${n.unit}/s; queue ${Tk(n.queued)} ${n.unit}. Measurement status: ${n.status}. Individual timings unavailable.`,group:"circuit modules"}}),...t.routes.map(t=>{let n=r.entry.flows.find(e=>e.edgeId===t.edgeId),o=t.points[Math.floor(t.points.length/2)];return{id:`pipe:${t.edgeId}`,x:o.x,y:o.y,shape:"path",pathData:t.pathD,label:`${t.source} → ${t.target}: ${Tk(n.perSecond)} ${n.unit}/s`,description:`Original edge ${t.edgeId}. ${t.residual?"Residual link":"Display backbone"}. ${i.kind} at ${r.observedAt}s; transferred volume ${Tk(n.perSecond)} ${n.unit}/s.`,group:"original pipes",datum:{id:t.edgeId,kind:"circuit-pipe",source:t.source,target:t.target,analysisRevision:e.atlas.analysisRevision,sourceRevision:i.sourceRevision,relationScopeId:"directed-admitted",editionId:i.id,editionKind:i.kind,observedAt:r.observedAt,...n}}})]}var Fk=vk.createElement,Ek=e=>{let{circuit:t,edition:i,reading:r,selection:n}=e.config;if(r.editionId!==i.id||i.analysisRevision!==t.atlas.analysisRevision)throw new Error("Circuit render inputs must share an edition and analysis revision");let o=wk(t,e.dimensions.width,e.dimensions.height),a=e.theme.semantic.text??"#273442",s=e.theme.semantic.surface??"#fff",l=$k(e.theme.semantic,e.config.colors),c="modeled"===i.kind?l.modeled:l.observed,u={width:o.width,height:o.height,viewBox:`0 0 ${o.width} ${o.height}`,style:{position:"absolute",inset:0,pointerEvents:"none"},"aria-hidden":!0},d=n?.analysisRevision===t.atlas.analysisRevision&&"directed-admitted"===n.relationScopeId?n.nodeId:void 0,h=r.entry.flows.reduce((e,t)=>Math.max(e,t.perSecond??0),0)||1,f=new Map(r.entry.flows.map(e=>[e.edgeId,e])),p=new Map(t.modules.map(e=>[e.nodeId,Ck(t,i,r,e)])),g=t=>e.config.layoutSelection?.isActive&&!e.config.layoutSelection.predicate(p.get(t))?.2:1,m=Math.max(0,Math.min(200,Math.floor(e.config.particleBudget??24))),y=_g(e.config.placementSeed??1),x=o.routes.filter(e=>(f.get(e.edgeId)?.perSecond??0)>0),b=e.config.reducedMotion?[]:Array.from({length:x.length?m:0},(e,t)=>{let i=x[t%x.length],n=kk(i.points,(y()+r.requestedTime/10)%1);return Fk("circle",{key:`cue:${t}`,cx:n.x,cy:n.y,r:2.3,fill:a,opacity:Math.max(g(i.source),g(i.target)),"data-circuit-particle":i.edgeId})}),v=o.modules.map(e=>({id:e.module.nodeId,x:e.x+e.width/2,y:e.y+e.height/2,fixedPosition:{x:e.x+e.width/2,y:e.y+e.height/2},shape:{type:"aabb",width:e.width,height:e.height},bodyCollisions:!1,datum:Ck(t,i,r,e.module)}));return{bodies:v,config:{kernel:{gravity:{x:0,y:0},seed:e.config.placementSeed??1,sleepAfter:.01},bodyBudget:!1,bodyLimit:v.length,eviction:!1,sediment:!1,settleStepLimit:4},bodyStyle:e=>({fill:s,stroke:l.muted,strokeWidth:1,opacity:g(e.id)}),colliders:o.modules.flatMap(e=>Sx({idPrefix:`queue:${e.module.nodeId}`,left:e.queue.x,right:e.queue.x+e.queue.width,top:e.queue.y,bottom:e.queue.y+e.queue.height,thickness:1,openEnds:!0})),sensors:o.modules.map(e=>({id:`sensor:${e.module.nodeId}`,shape:{type:"aabb",x:e.sensor.x+e.sensor.width/2,y:e.sensor.y+e.sensor.height/2,width:e.sensor.width,height:e.sensor.height}})),semanticItems:Nk(t,o,i,r),backgroundOverlays:Fk("svg",u,...o.routes.map(t=>{let i=f.get(t.edgeId),r=t.points[t.points.length-1],n=t.points[t.points.length-2],s=o.modules.find(e=>e.module.nodeId===t.source),u=o.modules.find(e=>e.module.nodeId===t.target),d=s.module.ports.filter(e=>"out"===e.direction).length<u.module.ports.filter(e=>"in"===e.direction).length,p=d?t.points[0]:r,m=d?p.x>=s.x+s.width:p.x>u.x,y=180*Math.atan2(r.y-n.y,r.x-n.x)/Math.PI,x=e.config.highlightedEdgeIds?.includes(t.edgeId),b=x?a:t.residual?l.residual:c,v="records"===i.unit?"rec":"attempts"===i.unit?"att":"roots";return Fk("g",{key:t.edgeId,"data-circuit-edge":t.edgeId,opacity:Math.max(g(t.source),g(t.target)),"data-source":t.source,"data-target":t.target,"data-flow":i.perSecond??"unmeasured","data-highlighted":x||void 0,"data-unit":`${i.unit}/s`},Fk("title",null,`${t.edgeId}: ${t.source} → ${t.target}; ${i.perSecond??"unmeasured"} ${i.unit}/s`),Fk("path",{d:t.pathD,stroke:b,strokeWidth:null===i.perSecond?1.5:1+i.perSecond/h*7,strokeDasharray:null===i.perSecond?"4 3":void 0,strokeLinejoin:"round",fill:"none",opacity:0===i.perSecond?.35:.75}),Fk("path",{d:"M-5,-3 L0,0 L-5,3",transform:`translate(${r.x},${r.y}) rotate(${y})`,fill:"none",stroke:b}),Fk("text",{x:p.x+(m?5:-5),y:p.y-7,textAnchor:m?"start":"end",fontSize:8,fill:a},`${null===i.perSecond?"?":_k(i.perSecond)} ${v}/s`))})),overlays:Fk("svg",{...u,"data-circuit-edition":i.kind,"data-circuit-time":r.observedAt},...o.sections.map(e=>Fk("text",{key:e.id,x:e.x,y:43,textAnchor:"middle",fontSize:11,fill:a},e.id)),...Lk(o,r,c,a,d,l,g),...b,Rk(o,i,r,c,a,d),Fk("text",{x:o.width/2,y:o.height-8,textAnchor:"middle",fontSize:9,fill:a},`${"modeled"===i.kind?"Modeled":"Observed"} · ${r.observedAt}s · pipe width = transferred volume/s · individual timings unavailable`))}},Ok=()=>null;function zk(e,t,i,r){return{frameType:e.frameType,layout:{...e.layout,primarySize:{width:i[0],height:i[1]},...r&&{margin:r}},buildProps:(i,r,n,o,a)=>{let[s,l]=o.size,c=t({...a,...o,width:s,height:l,colorScheme:n});return e.buildProps(c.data,r,n,{...o,title:c.title,description:c.description,summary:c.summary,accessibleTable:c.accessibleTable},{...a,...c})}}}var Dk=zk(Sg,function({atlas:e,linkedHover:t,...i},r=Ww(e)){return{...i,linkedHover:Iw(t),title:i.title??e.spec.dataRevision,description:i.description??"Motif Braid. Labeled squares show successive journey steps; parallel strands split at diverging prefixes and taper with per-step traffic.",summary:i.summary??`${r.groups.length} supported journey groups. Counts use ${e.spec.motifs.countUnit}; overlapping motifs do not partition the population. Source revision: ${e.provenance.sourceRevision}.`,accessibleTable:i.accessibleTable??!0,nodes:r.sceneSeeds.nodes,edges:r.sceneSeeds.edges,layout:tk,layoutConfig:{braid:r}}},[600,400]),Bk=zk(Sg,function({width:e=920,height:t=440,title:i="Dependency X-Ray",description:r,summary:n,accessibleTable:o=!0,chartId:a,className:s,onObservation:l,linkedHover:c,linkedSelection:u,annotations:d,frameProps:h,onSelectNode:f,...p}){return{nodes:p.forest.sceneSeeds.nodes,edges:p.forest.sceneSeeds.edges,layout:bk,layoutConfig:p,nodeIDAccessor:"id",sourceAccessor:"source",targetAccessor:"target",width:e,height:t,title:i,chartId:a,className:s,onObservation:l,linkedHover:Iw(c),selection:u,annotations:d,frameProps:h,animate:!1,margin:{top:12,right:24,bottom:12,left:12},description:r??`Sections organize the admitted directed graph. Backbone links organize the drawing; residual links retain other original edges. Brackets describe required paths, separately from transport. Roots: ${p.forest.atlas.requiredPaths?.roots.join(", ")??"not declared"}. Relation scope: directed-admitted. Completeness: ${p.forest.atlas.requiredPaths?.status??"not prepared"}.`,summary:n??`Roots: ${p.forest.atlas.requiredPaths?.roots.join(", ")??"not declared"}. Relation scope: directed-admitted. Required-path completeness: ${p.forest.atlas.requiredPaths?.status??"not prepared"}. ${p.forest.residual.originalEdgeIds.length} original edges retained.`,accessibleTable:o}},[920,440],{top:12,right:24,bottom:12,left:12}),jk=zk(_w,function({width:e=980,height:t=860,title:i,description:r,summary:n,accessibleTable:o=!0,chartId:a,className:s,onObservation:l,linkedHover:c,annotations:u,frameProps:d,linkedSelection:h,onSelectNode:f,...p}){return{key:JSON.stringify([p.circuit.atlas.analysisRevision,p.circuit.order,p.circuit.backboneEdgeIds,e,t]),data:p.circuit.modules.map(e=>Ck(p.circuit,p.edition,p.reading,e)),layout:Ek,layoutConfig:p,width:e,height:t,chartId:a,className:s,onObservation:l,linkedHover:Iw(c),annotations:u,frameProps:d,paused:!0,title:i??p.edition.label,description:r??`${p.edition.label}. ${p.edition.kind} aggregate interval tape at ${p.reading.observedAt} seconds. Pipe widths encode transferred volume per second in their labeled units; module readouts separate completions, capacity and queue stock. Individual timings are unavailable.`,summary:n??p.edition.assumptions.join(" "),accessibleTable:o,tooltip:!!(a||c||l)&&Ok}},[980,860]);import{scaleTime as Wk}from"d3-scale";var Yk={static:{duplicateIds:"fatal",invalidSystemTime:"warn"},mcp:{duplicateIds:"fatal",invalidSystemTime:"warn"},push:{duplicateIds:"warn",invalidSystemTime:"strip"}};function qk(e="static"){return Yk[e]??Yk.static}var Xk=/* @__PURE__ */new Set(["invalid-domain","missing-node","backward-edge","invalid-edge-time","invalid-value","invalid-node-time"]);function Gk(e){return"fatal"===e.severity||"warn"===e.severity?e.severity:Xk.has(e.kind)?"fatal":"warn"}function Vk(e){let t=[],i=[];for(let r of e)"fatal"===Gk(r)?t.push(r):i.push(r);return{fatal:t,warnings:i}}function Hk(e,t,i,r={}){let n=qk(r.usageMode??"static"),o=[],a=/* @__PURE__ */new Set;for(let t of e)a.has(t.id)&&o.push({kind:"duplicate-node",id:t.id,severity:n.duplicateIds}),a.add(t.id);let s=/* @__PURE__ */new Set,l=Array.isArray(i)&&2===i.length,c=l&&Number.isFinite(i[0])&&Number.isFinite(i[1]),u=c&&i[0]<=i[1];(!l||!c||!u)&&o.push({kind:"invalid-domain"});for(let t of e)null!=t.xExtent&&(Array.isArray(t.xExtent)&&2===t.xExtent.length&&Number.isFinite(t.xExtent[0])&&Number.isFinite(t.xExtent[1])&&t.xExtent[0]<=t.xExtent[1]||o.push({kind:"invalid-node-time",id:t.id}));for(let e of t)s.has(e.id)&&o.push({kind:"duplicate-edge",id:e.id,severity:n.duplicateIds}),s.add(e.id),a.has(e.source)||o.push({kind:"missing-node",id:e.id,endpoint:"source",nodeId:e.source}),a.has(e.target)||o.push({kind:"missing-node",id:e.id,endpoint:"target",nodeId:e.target}),Number.isFinite(e.startTime)&&Number.isFinite(e.endTime)?((null!=e.systemInTime&&!Number.isFinite(e.systemInTime)||null!=e.systemOutTime&&!Number.isFinite(e.systemOutTime))&&o.push({kind:"invalid-system-time",id:e.id,severity:"warn"}),(!Number.isFinite(e.value)||e.value<=0)&&o.push({kind:"invalid-value",id:e.id}),e.endTime<e.startTime&&o.push({kind:"backward-edge",severity:"fatal",id:e.id,source:e.source,target:e.target})):o.push({kind:"invalid-edge-time",id:e.id});return o}function Uk(e,t,i="static"){if("strip"!==qk(i).invalidSystemTime)return e;let r=new Set(t.filter(e=>"invalid-system-time"===e.kind).map(e=>e.id));return 0===r.size?e:e.map(e=>{if(!r.has(e.id))return e;let t={...e};return null!=t.systemInTime&&!Number.isFinite(t.systemInTime)&&delete t.systemInTime,null!=t.systemOutTime&&!Number.isFinite(t.systemOutTime)&&delete t.systemOutTime,t})}function Kk(e){return"invalid-node-time"===e.kind?`node ${e.id} has an invalid xExtent (must be [start, end] with start <= end)`:"invalid-edge-time"===e.kind?`edge ${e.id} has an invalid startTime or endTime`:"invalid-domain"===e.kind?"time domain must be a 2-tuple of finite times [start, end] with start <= end":"invalid-value"===e.kind?`edge ${e.id} must have a positive finite value`:"missing-node"===e.kind?`edge ${e.id} references missing ${e.endpoint} node "${e.nodeId}"`:"backward-edge"===e.kind?`edge ${e.id} (${e.source}->${e.target}) ends before it starts`:"duplicate-node"===e.kind?`node id "${e.id}" is duplicated`:"duplicate-edge"===e.kind?`edge id "${e.id}" is duplicated`:"invalid-system-time"===e.kind?`edge ${e.id} has an invalid systemInTime or systemOutTime`:e.kind}function Zk(e,t){let i=0,r=e.length-1,n=-1;for(;i<=r;){let o=i+r>>>1;e[o].at<=t?(n=o,i=o+1):r=o-1}return n<0?{at:t,before:0,after:0}:e[n]}function Qk(e,t=0){if(0===e.length)return{adjacentClearance:[],positions:[]};let i=[],r=[0];for(let n=0;n<e.length-1;n++){let o=e[n],a=e[n+1],s=[.../* @__PURE__ */new Set([...o.map(e=>e.at),...a.map(e=>e.at)])].sort((e,t)=>e-t),l=0;for(let e of s){let t=Zk(o,e),i=Zk(a,e);l=Math.max(l,t.after+i.before)}i.push(l),r.push(r[r.length-1]+l+t)}return{adjacentClearance:i,positions:r}}function Jk(e,t,i,r={}){let n=[...e];if(n.length<=1)return n;let o=[...n],a=i(n),s=1,l=Math.max(0,r.passes??6),c=Math.max(1,r.maxEvaluations??1/0);for(let e=0;e<l&&s<c;e++){let e=new Map(n.map((e,t)=>[e,t])),l=/* @__PURE__ */new Map,c=/* @__PURE__ */new Map;for(let i of t){let t=e.get(i.source),r=e.get(i.target);if(null==t||null==r)continue;let n=Number.isFinite(i.weight)&&i.weight>0?i.weight:1;l.set(i.source,(l.get(i.source)??0)+r*n),c.set(i.source,(c.get(i.source)??0)+n),l.set(i.target,(l.get(i.target)??0)+t*n),c.set(i.target,(c.get(i.target)??0)+n)}n=n.map((e,t)=>({item:e,index:t,barycenter:(l.get(e)??t)/(c.get(e)??1)})).sort((e,t)=>e.barycenter-t.barycenter||(r.compare?.(e.item,t.item)??e.index-t.index)).map(e=>e.item);let u=i(n);if(s++,u<a)a=u,o=[...n];else if(u===a)break}return o}function eS(e,t,i={}){let r=[...e];if(r.length<=1)return r;let n=t(r),o=1,a=Math.max(0,i.passes??6),s=Math.max(1,i.maxEvaluations??1/0);for(let e=0;e<a&&o<s;e++){let e=!1;for(let i=0;i<r.length-1&&o<s;i++){[r[i],r[i+1]]=[r[i+1],r[i]];let a=t(r);o++,a<n?(n=a,e=!0):[r[i],r[i+1]]=[r[i+1],r[i]]}if(!e)break}return r}function tS(e,t,i={}){let r=[...e],n=r.length;if(n<=1||n>(i.maxItems??8))return r;let o=Math.max(1,i.maxEvaluations??1/0),a=0,s=[...r],l=1/0,c=()=>{if(a>=o)return;let e=t(r);a++,e<l&&(l=e,s=[...r])};c();let u=new Array(n).fill(0),d=0;for(;d<n&&a<o;)if(u[d]<d){let e=d%2==0?0:u[d];[r[e],r[d]]=[r[d],r[e]],c(),u[d]++,d=0}else u[d]=0,d++;return s}function iS(){/* @__PURE__ */
281
- return Object.create(null)}function rS(e,t){return e<t?-1:e>t?1:0}function nS(e){return e.occupants.map(e=>e.id).sort(rS).join("\0")}function oS(e,t,i=0){return e.slice(0,-1).map((r,n)=>{let o=e[n+1];return null!=r.group&&r.group===o.group?i:t})}function aS(e,t){return e.map(e=>{let i=/* @__PURE__ */new Map;for(let r of e.occupants){let e=t[r.id];if(e)for(let t of e.samples){let e=i.get(t.t)??{before:0,after:0},r=t.boundaryOffset??0;i.set(t.t,{before:Math.max(e.before,t.topMass-r),after:Math.max(e.after,t.botMass+r)})}}return[...i].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({at:e,...t}))})}function sS(e,t,i){return Qk(aS([e,t],i)).adjacentClearance[0]??0}function lS(e,t,i){if(0===e.length)return[];let{padding:r,plotH:n,valueScale:o}=i,a=i.stackValueScale??o,s=oS(e,r,i.groupPadding??0),l=[r+e[0].peak.topPeak*a];for(let i=1;i<e.length;i++)l.push(l[i-1]+t[i-1]*a+s[i-1]);let c=l[l.length-1]+e[e.length-1].peak.botPeak*a+r;if(c>n&&c>0){let e=n/c;for(let t=0;t<l.length;t++)l[t]*=e}return l}function cS(e,t){let i=(e.boundaryOffset??0)*t,r=e.value*t;if("out"===e.kind){let n=e.sideMassBefore*t;return i+("top"===e.side?r/2-n:n-r/2)}let n=e.sideMassAfter*t;return i+("top"===e.side?r/2-n:n-r/2)}function uS(e,t,i,r,n,o,a){let s=e.length;if(0===s)return[];let{padding:l,plotH:c,valueScale:u}=a,d=oS(e,l,a.groupPadding??0),h=n.map((e,t)=>e*u+d[t]),f=l+e[0].peak.topPeak*u,p=c-l-e[s-1].peak.botPeak*u;if(p-f<=h.reduce((e,t)=>e+t,0)+1e-6)return lS(e,n,a);let g=1===s?[(f+p)/2]:[...o];for(let e=0;e<12;e++){let e=new Array(s).fill(0),n=new Array(s).fill(0);for(let o of i){let i=t[o.source],a=t[o.target];if(null==i||null==a||i===a)continue;let s=r[o.source]?.localAttachments.get(o.id),l=r[o.target]?.localAttachments.get(o.id);if(!s||!l)continue;let c=o.value>0&&Number.isFinite(o.value)?o.value:1,d=cS(s,u),h=cS(l,u);e[i]+=(g[a]+h-d)*c,n[i]+=c,e[a]+=(g[i]+d-h)*c,n[a]+=c}let o=yc({desired:g.map((t,i)=>0===n[i]?t:.45*t+e[i]/n[i]*.55),minGaps:h,weights:n.map(e=>Math.max(1,e)),min:f,max:p}),a=0;for(let e=0;e<s;e++)a=Math.max(a,Math.abs(o[e]-g[e]));if(g=o,a<.01)break}return g}function dS(e,t,i,r,n,o){let a=o.adjacentClearance?[...o.adjacentClearance]:Qk(aS(r,i)).adjacentClearance,s=lS(r,a,o),l="hug"===o.lanePlacement?uS(r,n,t,i,a,s,o):[...s];if("hug"===o.lanePlacement){let i=t=>{let i=iS();for(let r of e)i[r.id]=t[n[r.id]];return i};hS(i(l),t)>hS(i(s),t)+1e-6&&(l=[...s])}let c=iS();for(let t of e)c[t.id]=l[n[t.id]];let u=1/0,d=-1/0;for(let t of e){let e=c[t.id],r=i[t.id];!Number.isFinite(e)||!r||(u=Math.min(u,e-r.topPeak*o.valueScale),d=Math.max(d,e+r.botPeak*o.valueScale))}return{adjacentClearance:a,centerlines:c,slotCenter:l,stackCenter:s,verticalUtilization:Number.isFinite(u)&&Number.isFinite(d)&&o.plotH>0?Math.max(0,Math.min(1,(d-u)/o.plotH)):0}}function hS(e,t){let i=0;for(let r of t){let t=e[r.source],n=e[r.target];Number.isFinite(t)&&Number.isFinite(n)&&(i+=Math.abs(t-n)*(r.value>0?r.value:1))}return i}function fS(e,t){let i=e?.samples;if(!i||0===i.length||t<i[0].t)return{top:0,bot:0};let r=0,n=i.length-1,o=0;for(;r<=n;){let e=r+n>>>1;i[e].t<=t?(o=e,r=e+1):n=e-1}let a=i[o].boundaryOffset??0;return{top:i[o].topMass-a,bot:i[o].botMass+a}}function pS(e,t,i,r,n){let o=1-n;return o*o*o*e+3*o*o*n*t+3*o*n*n*i+n*n*n*r}function gS(e,t){let i=0,r=1;for(let n=0;n<28;n++){let n=(i+r)/2;pS(0,t,t,1,n)<e?i=n:r=n}return(i+r)/2}function mS(e,t,i){let r=t+cS(e,i),n=e.value*i/2;return[r-n,r+n]}function yS(e,t,i,r){return Math.max(0,Math.min(t,r)-Math.max(e,i))/Math.max(1e-9,t-e)}function xS(e,t,i,r,n,o,a){let{valueScale:s,domain:l,mode:c="quality"}=a,u="source"===a.ribbonLane?.85:"target"===a.ribbonLane?.15:.5,d=0;for(let a of e){let e=r[a.source],h=r[a.target];if(null==e||null==h||Math.abs(e-h)<2)continue;let f=t[a.source]?.localAttachments.get(a.id),p=t[a.target]?.localAttachments.get(a.id);if(!f||!p)continue;let g=Math.max(a.startTime,l?.[0]??-1/0),m=Math.min(a.endTime,l?.[1]??1/0);if(!(m>g))continue;let[y,x]=mS(f,n[a.source],s),[b,v]=mS(p,n[a.target],s),w=Math.min(e,h)+1,k=Math.max(e,h)-1;for(let e=w;e<=k;e++){let r=i[e];if(!r)continue;let l=[g,m];if("quality"===c)for(let e of r.occupants)for(let i of t[e.id]?.samples??[])i.t>g&&i.t<m&&l.push(i.t);let h=e=>{let i=gS((e-g)/(m-g),u),l=pS(y,y,b,b,i),c=pS(x,x,v,v,i),d=0;for(let i of r.occupants){if(i.id===a.source||i.id===a.target)continue;let r=o[i.id];if(null!=r?.start&&e<r.start||null!=r?.end&&e>r.end)continue;let u=fS(t[i.id],e),h=n[i.id];d=Math.max(d,yS(l,c,h-u.top*s,h+u.bot*s))}return d},f=[...new Set(l)].sort((e,t)=>e-t),p=0;for(let e=0;e<f.length-1;e++){let t=f[e],i=f[e+1]-t;p+=(h(t+.25*i)+h(t+.5*i)+h(t+.75*i))/3*i}d+=p/(m-g)*(a.value>0?a.value:1)}}return d}function bS(e,t,i,r,n,o,a,s,l,c,u="both",d){return{crossings:e,weightedLength:t,pixelLength:hS(a,i),transitOcclusion:xS(i,r,n,o,a,s,{valueScale:l,ribbonLane:u,domain:d,mode:"quality"}),verticalUtilization:c}}function vS(e,t){return t?Math.max(t[0],Math.min(t[1],e)):e}function wS(e,t){return e.map(e=>({t:vS(e.t,t),topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}}))}function kS(e,t,i){let r=t+(e.boundaryOffset??0)*i,n=e.value*i;if("out"===e.kind){let t=e.sideMassBefore*i;if("top"===e.side){let e=r-t;return[e,e+n]}let o=r+t;return[o-n,o]}let o=e.sideMassAfter*i;if("top"===e.side){let e=r-o;return[e,e+n]}let a=r+o;return[a-n,a]}function SS(e,t,i,r,n){if(0===e.length)return null;let o=wS(e,n),a=e=>t+(o[e].boundaryOffset??0)*i,s=e=>a(e)-o[e].topMass*i,l=e=>a(e)+o[e].botMass*i,c=`M${r(o[0].t)},${s(0)}`;for(let e=1;e<o.length;e++)c+=` L${r(o[e].t)},${s(e)}`;c+=` L${r(o[o.length-1].t)},${l(o.length-1)}`;for(let e=o.length-2;e>=0;e--)c+=` L${r(o[e].t)},${l(e)}`;return c+" Z"}function AS(e,t,i,r,n,o){let a=i.nodeData[e];if(!a||0===a.samples.length)return[];let s=i.valueScale,l=i.centerlines[e],c=wS(a.samples,n),u=c.find(e=>e.topMass+e.botMass>0)||c[0],d=[...c].reverse().find(e=>e.topMass+e.botMass>0)||c[c.length-1],h=r(u.t),f=r(d.t),p=e=>r(vS(e,n)),g=[],m=(e,t,i,r)=>`M${e},${t} L${i},${t} L${i},${r} L${e},${r} Z`;for(let i of t){if(i.source===e&&null!=i.systemInTime&&Number.isFinite(i.systemInTime)){let e=a.localAttachments.get(i.id),t=o?.get(i.id)??i.startTime;if(e&&"out"===e.kind&&i.systemInTime<t){let r=p(i.systemInTime),o=p(t),a=null!=n&&i.systemInTime<n[0],c=a?r:r-20,u=a?Math.min(o,r+20):r,d=Math.max(h,c);if(o>d){let[t,i]=kS(e,l,s);g.push({pathD:m(d,t,o,i),x0:c,x1:u,from:0,to:1})}}}if(i.target===e&&null!=i.systemOutTime&&Number.isFinite(i.systemOutTime)){let e=a.localAttachments.get(i.id);if(e&&"in"===e.kind&&i.systemOutTime>i.endTime){let t=p(i.systemOutTime),r=p(i.endTime),n=t+20,o=Math.min(f,n);if(o>r){let[i,a]=kS(e,l,s);g.push({pathD:m(r,i,o,a),x0:t,x1:n,from:1,to:0})}}}}return g}function MS(e,t){let i=iS(),r=iS();for(let t of e)i[t.id]=[],r[t.id]=[];for(let e of t)r[e.source]&&r[e.source].push(e),i[e.target]&&i[e.target].push(e);return{incoming:i,outgoing:r}}function $S(e,t,i,r="temporal"){let n="temporal"===r?(e,t)=>e.endTime-t.endTime||rS(e.id,t.id):(e,t)=>t.value-e.value||rS(e.id,t.id),o="temporal"===r?(e,t)=>e.startTime-t.startTime||rS(e.id,t.id):(e,t)=>t.value-e.value||rS(e.id,t.id),a=/* @__PURE__ */new Map;for(let e of t)a.set(e.id,{});let s=(e,t)=>{let i=/* @__PURE__ */new Map;for(let r of e){let e=r[t];i.has(e)||i.set(e,{partner:e,edges:[],total:0,earliestStart:1/0,latestEnd:-1/0});let n=i.get(e);n.edges.push(r),n.total+=r.value,n.earliestStart=Math.min(n.earliestStart,r.startTime),n.latestEnd=Math.max(n.latestEnd,r.endTime)}let a=[...i.values()];"temporal"===r?a.sort((e,i)=>"target"===t?e.earliestStart-i.earliestStart||rS(e.partner,i.partner):e.latestEnd-i.latestEnd||rS(e.partner,i.partner)):a.sort((e,t)=>t.total-e.total||rS(e.partner,t.partner));for(let e of a)e.edges.sort("target"===t?o:n);return a};for(let t of e){let e=i.outgoing[t.id],r=i.incoming[t.id];if(0===r.length)s(e,"target").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)a.get(t.id).sourceSide=i});else if(0===e.length)s(r,"source").forEach((e,t)=>{let i=t%2==0?"top":"bot";for(let t of e.edges)a.get(t.id).targetSide=i});else{let t=s(r,"source"),i=s(e,"target"),n=Math.max(t.length,i.length);for(let e=0;e<n;e++){let r=e%2==0?"top":"bot";if(t[e])for(let i of t[e].edges)a.get(i.id).targetSide=r;if(i[e])for(let t of i[e].edges)a.get(t.id).sourceSide=r}}}return a}function _S(e,t,i,r,n="temporal"){let o=t.incoming[e.id],a=t.outgoing[e.id],s=[];for(let e of o)s.push({time:e.endTime,delta:+e.value,edge:e,kind:"in",side:i.get(e.id).targetSide});for(let e of a)s.push({time:e.startTime,delta:-e.value,edge:e,kind:"out",side:i.get(e.id).sourceSide});let l={create:0,in:1,"transfer-out":2,"transfer-in":3,out:4},c=(e,t)=>{if(!r||!e.edge||!t.edge||e.kind!==t.kind||e.side!==t.side)return 0;if("out"===e.kind){if(e.edge.target===t.edge.target&&e.edge.endTime===t.edge.endTime)return 0;let i=r.get(e.edge.id)?.target,n=r.get(t.edge.id)?.target;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof n&&Number.isFinite(n)&&i!==n?"top"===e.side?i-n:n-i:0}if("in"===e.kind){if(e.edge.source===t.edge.source&&e.edge.startTime===t.edge.startTime)return 0;let i=r.get(e.edge.id)?.source,n=r.get(t.edge.id)?.source;return"number"==typeof i&&Number.isFinite(i)&&"number"==typeof n&&Number.isFinite(n)&&i!==n?"top"===e.side?n-i:i-n:0}return 0},u=()=>{s.sort((e,t)=>e.time-t.time||(e.phase??0)-(t.phase??0)||(e.sequence??0)-(t.sequence??0)||(l[e.kind]??99)-(l[t.kind]??99)||c(e,t)||rS(e.edge?.id??"",t.edge?.id??"")||rS(e.side,t.side)||e.delta-t.delta)},d=s.length?xr(s.map(e=>e.time)):null,h=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[0])?e.xExtent[0]:null,f=null!=h?h-1:null!=d&&Number.isFinite(d)?d-1:null;u();let p=null,g=0;for(let e of s)e.time!==p&&(p=e.time,g=0),e.sequence=g++;let m=e=>({time:e.time,phase:0,sequence:e.sequence??0}),y=[],x=0,b=0;for(let e of s)if("out"===e.kind){let t=Math.abs(e.delta),i=t-("top"===e.side?x:b);if(i>0){let t="top"===e.side?"bot":"top",r=Math.min(i,"top"===t?x:b);if(r>0){let n=m(e);y.push({...n,delta:-r,kind:"transfer-out",side:t}),y.push({...n,delta:+r,kind:"transfer-in",side:e.side}),"top"===t?x-=r:b-=r,"top"===e.side?x+=r:b+=r,i-=r}i>0&&null!==f&&(y.push({time:f,delta:+i,kind:"create",side:e.side}),"top"===e.side?x+=i:b+=i)}"top"===e.side?x-=t:b-=t}else if("in"===e.kind){let t=Math.abs(e.delta);"top"===e.side?x+=t:b+=t}s.push(...y),u();let v=0,w=0,k=0,S=0,A=0,M=0,$=[],_=/* @__PURE__ */new Map,I=e=>{$.push({t:e,topMass:v,botMass:w,...Math.abs(k)>1e-12&&{boundaryOffset:k}})},P=()=>{S=Math.max(S,v+w),A=Math.max(A,v-k),M=Math.max(M,w+k)};for(let e of s){if("transfer-out"!==e.kind&&"transfer-in"!==e.kind&&I(e.time),("in"===e.kind||"out"===e.kind)&&e.edge){let t="top"===e.side?v:w,i=t+e.delta;_.set(e.edge.id,{side:e.side,time:e.time,sideMassBefore:t,sideMassAfter:i,kind:e.kind,value:Math.abs(e.delta),...Math.abs(k)>1e-12&&{boundaryOffset:k}})}"top"===e.side?v+=e.delta:w+=e.delta,"transfer-in"===e.kind?(k+="top"===e.side?e.delta:-e.delta,P(),I(e.time)):"transfer-out"!==e.kind&&(P(),"out"===e.kind&&v+w<=1e-12&&(k=0),I(e.time))}let L=[],R=0;for(;R<$.length;){let e=R;for(;e+1<$.length&&$[e+1].t===$[R].t;)e++;L.push($[R]);for(let t=R+1;t<=e;t++){let e=L[L.length-1];($[t].topMass!==e.topMass||$[t].botMass!==e.botMass||($[t].boundaryOffset??0)!==(e.boundaryOffset??0))&&L.push($[t])}R=e+1}let C=Array.isArray(e.xExtent)&&Number.isFinite(e.xExtent[1])?e.xExtent[1]:null,T=null;for(let e of a)null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.systemInTime<e.startTime&&(null===T||e.systemInTime<T)&&(T=e.systemInTime);let N=null;for(let e of o)null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>e.endTime&&(null===N||e.systemOutTime>N)&&(N=e.systemOutTime);if(L.length>0){let e=L[L.length-1],t=Math.max(C??-1/0,N??-1/0);Number.isFinite(t)&&t>e.t&&e.topMass+e.botMass>0&&L.push({t:t,topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}});let i,r=L[0],n=L.find(e=>e.topMass+e.botMass>0),o=1/0;null!=h&&Number.isFinite(h)&&h<r.t&&r.topMass+r.botMass>0&&(o=h,i=r),n&&null!=T&&Number.isFinite(T)&&T<n.t&&T<o&&(o=T,i=n),i&&Number.isFinite(o)&&L.unshift({t:o,topMass:i.topMass,botMass:i.botMass,...null!=i.boundaryOffset&&{boundaryOffset:i.boundaryOffset}})}let F=L;if("max"===n&&null!=h&&null!=C&&C>h){let e,t=0;for(let i of L){let r=i.topMass+i.botMass;r>t&&(t=r,e=i)}if(e){let t={topMass:e.topMass,botMass:e.botMass,...null!=e.boundaryOffset&&{boundaryOffset:e.boundaryOffset}};F=[...L.filter(e=>e.t<h),{t:h,...t},{t:C,...t},...L.filter(e=>e.t>C)]}}return{samples:F,peak:S,topPeak:A,botPeak:M,localAttachments:_}}function IS(e,t,i,r){let n=/* @__PURE__ */new Map;for(let o of e){let e=t[o.source]?.localAttachments.get(o.id),a=t[o.target]?.localAttachments.get(o.id),s=i[o.source],l=i[o.target];if(!(e&&a&&Number.isFinite(s)&&Number.isFinite(l)))continue;let c=kS(e,s,r),u=kS(a,l,r);n.set(o.id,{source:(c[0]+c[1])/2,target:(u[0]+u[1])/2})}return n}function PS(e,t){let i=(e,i)=>{for(let r of e){let e=/* @__PURE__ */new Map;for(let n of r){let r=`${("out"===i?t.get(n.id)?.sourceSide:t.get(n.id)?.targetSide)??""}\0${"out"===i?n.startTime:n.endTime}`,o="out"===i?`${n.target}\0${n.endTime}`:`${n.source}\0${n.startTime}`,a=e.get(r);if(null!=a&&a!==o)return!0;e.set(r,o)}}return!1};return i(Object.values(e.outgoing),"out")||i(Object.values(e.incoming),"in")}function LS(e,t,i){let r=/* @__PURE__ */new Map,n=[];for(let t of e)n.push({time:t.startTime,kind:"out",edge:t}),n.push({time:t.endTime,kind:"in",edge:t});n.sort((e,t)=>e.time-t.time||(e.kind===t.kind?0:"in"===e.kind?-1:1)||("out"===e.kind?t.edge.value-e.edge.value:0)||rS(e.edge.id,t.edge.id));let o=e=>{let t=r.get(e);return t||(t={top:0,bot:0},r.set(e,t)),t},a=(e,t,i)=>{let r="top"===t?"bot":"top",n=Math.min(i,e[t]);e[t]-=n;let o=i-n;o>0&&(e[r]=Math.max(0,e[r]-o))};for(let e of n){let{edge:r}=e;if("in"===e.kind){let e=t.get(r.id)?.targetSide??"bot";o(r.target)[e]+=r.value;continue}let n=o(r.source),s=t.get(r.id),l=s.sourceSide??"bot";if(i[r.source]===i[r.target]){let e=n.top>=r.value,t=n.bot>=r.value;e!==t?l=e?"top":"bot":!e&&!t&&n.top!==n.bot&&(l=n.top>n.bot?"top":"bot"),s.sourceSide=l,s.targetSide=l}a(n,l,r.value)}}function RS(e,t,i,r){for(let n of e){let e=t.incoming[n.id],o=t.outgoing[n.id];if(0===e.length||0===o.length)continue;let a=()=>{let t={inTop:0,inBot:0,outTop:0,outBot:0};for(let r of e)"top"===i.get(r.id).targetSide?t.inTop+=r.value:t.inBot+=r.value;for(let e of o)"top"===i.get(e.id).sourceSide?t.outTop+=e.value:t.outBot+=e.value;return t},s=(e,t)=>{let n=a(),s="top"===e?n.outTop-n.inTop:n.outBot-n.inBot,l="top"===t?n.inTop-n.outTop:n.inBot-n.outBot;if(s<=0||l<=0)return!1;let c=Math.min(s,l),u=o.filter(t=>!r.has(t.id)&&i.get(t.id).sourceSide===e&&t.value<=c).sort((e,t)=>t.value-e.value||rS(e.id,t.id));return 0!==u.length&&(i.get(u[0].id).sourceSide=t,!0)},l=o.length+1;for(;l-- >0&&(s("top","bot")||s("bot","top")););}}var CS=(e,t)=>{let i=0,r=e.length;for(;i<r;){let n=i+r>>>1;e[n]<t?i=n+1:r=n}return i},TS=class{constructor(e){this.coordinates=[...new Set(e)].sort((e,t)=>e-t),this.tree=new Int32Array(this.coordinates.length+1)}add(e,t){for(let i=CS(this.coordinates,e)+1;i<this.tree.length;i+=i&-i)this.tree[i]+=t}below(e){let t=0;for(let i=CS(this.coordinates,e);i>0;i-=i&-i)t+=this.tree[i];return t}};function NS(e,t){return e.source!==t.source&&e.target!==t.target&&e.source!==t.target&&e.target!==t.source&&Math.max(e.startTime,t.startTime)<Math.min(e.endTime,t.endTime)}var FS=class{constructor(e,t,i){this.size=i,this.routes=[],this.outgoing=Array.from({length:i},()=>[]),this.incoming=Array.from({length:i},()=>[]);let r=/* @__PURE__ */new Map,n=/* @__PURE__ */new Map;for(let e of t.keys())n.set(e,n.size);this.nodeCount=n.size;for(let i of e){let e=t.get(i.source),o=t.get(i.target);if(void 0===e||void 0===o||!(i.startTime<i.endTime))continue;let a=n.get(i.source),s=n.get(i.target),l=`${a}:${s}`;r.has(l)||r.set(l,r.size);let c=this.routes.length;this.routes.push({edge:i,source:e,target:o,sourceNode:a,targetNode:s,pair:r.get(l),reverse:-1}),this.outgoing[e].push(c),this.incoming[o].push(c)}for(let e of this.routes)e.reverse=r.get(`${e.targetNode}:${e.sourceNode}`)??-1;if(this.events=this.routes.flatMap((e,t)=>[{time:e.edge.startTime,route:t,delta:1},{time:e.edge.endTime,route:t,delta:-1}]).sort((e,t)=>e.time-t.time||e.delta-t.delta||e.route-t.route),this.smallPairs=this.routes.length<=80?[]:null,this.smallPairs)for(let e=0;e<this.routes.length;e++)for(let t=e+1;t<this.routes.length;t++)NS(this.routes[e].edge,this.routes[t].edge)&&this.smallPairs.push([e,t]);this.work=this.smallPairs?.length??1/0}crossing(e,t,i){return(i[e.source]-i[t.source])*(i[e.target]-i[t.target])<0?1:0}count(e){if(this.smallPairs){let t=0;for(let[i,r]of this.smallPairs)t+=this.crossing(this.routes[i],this.routes[r],e);return t}let t=Array.from({length:this.size+1},()=>[]);for(let i of this.routes){let r=e[i.source],n=e[i.target];for(let e=r+1;e<=this.size;e+=e&-e)t[e].push(n)}let i=t.map(e=>new TS(e)),r=new Int32Array(4*this.nodeCount),n=new Int32Array(this.routes.length),o=(e,t)=>{let r=0;for(let n=e;n>0;n-=n&-n)r+=i[n].below(t);return r},a=0;for(let t of this.events){let s=this.routes[t.route],l=e[s.source],c=e[s.target];1===t.delta&&(a+=o(l,this.size)-o(l,c+1)+o(this.size,c)-o(l+1,c),l!==c&&(a-=r[4*s.sourceNode+(l<c?1:0)],a-=r[4*s.targetNode+(l<c?2:3)],s.reverse>=0&&(a+=n[s.reverse])));for(let e=l+1;e<=this.size;e+=e&-e)i[e].add(c,t.delta);l!==c&&(r[4*s.sourceNode+(l<c?3:2)]+=t.delta,r[4*s.targetNode+(l<c?0:1)]+=t.delta),n[s.pair]+=t.delta}return a}swapDelta(e,t,i){let r=0,n=0,o=r=>i[r===e?t:r===t?e:r],a=(e,t)=>{let a=this.routes[e],s=this.routes[t];if(!NS(a.edge,s.edge))return;n++;let l=(o(a.source)-o(s.source))*(o(a.target)-o(s.target))<0?1:0;r+=l-this.crossing(a,s,i)};for(let i of this.outgoing[e])for(let e of this.outgoing[t])a(i,e);for(let i of this.incoming[e])for(let r of this.incoming[t]){let n=this.routes[i],o=this.routes[r];n.source===e&&o.source===t||n.source===t&&o.source===e||a(i,r)}return{delta:r,evaluations:n}}};function ES(e){let t=iS();return e.forEach((e,i)=>{for(let r of e.occupants)t[r.id]=i}),t}function OS(e,t,i){e.splice(0,e.length,...i);let r=ES(i);for(let e of Object.keys(t))delete t[e];Object.assign(t,r)}function zS(e){let t=/* @__PURE__ */new Map,i=[];e.forEach((e,r)=>{if(!e.group)return void i.push({anchor:r,stableId:nS(e),slots:[e]});let n=t.get(e.group)??{indexes:[],slots:[]};n.indexes.push(r),n.slots.push(e),t.set(e.group,n)});for(let[e,r]of t)i.push({anchor:r.indexes.reduce((e,t)=>e+t,0)/r.indexes.length,stableId:`${e}\0${r.slots.map(nS).join("\0")}`,slots:r.slots});return i.sort((e,t)=>e.anchor-t.anchor||rS(e.stableId,t.stableId))}function DS(e){return e.some(e=>e.group)?zS(e).flatMap(e=>e.slots):[...e]}function BS(e){let t=/* @__PURE__ */new Set;for(let i of e)if(i.group){if(t.has(i.group))return!0;t.add(i.group)}return!1}function jS(e){return e.flatMap(e=>e.slots)}function WS(e,t){let i=/* @__PURE__ */new Map;for(let t of e)for(let e of t.slots)i.set(e,t);let r=/* @__PURE__ */new Map;for(let e of t){let t=i.get(e.source),n=i.get(e.target);if(!t||!n||t===n)continue;let o=Number.isFinite(e.weight)&&e.weight>0?e.weight:1,a=t.stableId<n.stableId?`${t.stableId}\0${n.stableId}`:`${n.stableId}\0${t.stableId}`,s=r.get(a);s?s.weight=(s.weight??0)+o:r.set(a,{source:t,target:n,weight:o})}return[...r.values()]}function YS(e,t,i){let r=/* @__PURE__ */new Map;return e.forEach((e,t)=>{for(let i of e.slots)r.set(i,t)}),e.map((e,n)=>{if(e.slots.length<=1)return e;let o=/* @__PURE__ */new Map;for(let t of e.slots)o.set(t,0);for(let e of t){let t=r.get(e.source),i=r.get(e.target);if(null==t||null==i)continue;let a=Number.isFinite(e.weight)&&e.weight>0?e.weight:1;if(t===n&&i!==n){let t=i>n?1:-1;o.set(e.source,(o.get(e.source)??0)+a*t)}else if(i===n&&t!==n){let i=t>n?1:-1;o.set(e.target,(o.get(e.target)??0)+a*i)}}let a=[...e.slots].sort((e,t)=>(o.get(e)??0)-(o.get(t)??0)||i(e,t));return{...e,slots:a}})}function qS(e,t){e.some(e=>e.group)&&OS(e,t,DS(e))}function XS(e,t,i=0){return e.crossings<t.crossings||e.crossings===t.crossings&&e.cost<=t.cost+i}function GS({order:e,after:t,nodes:i,edges:r,outgoingPartners:n,incomingPartners:o,slotForNode:a,averageGap:s,evaluate:l}){let c=(i,n)=>{let o=[...new Set(n.map(t=>e.indexOf(t)))].sort((e,t)=>e-t),a=e.indexOf(i),c=o[0],u=o[o.length-1];if(o.length<3||!o.includes(a)||u-c+1!==o.length||Math.abs(2*a-c-u)<=1)return;let d=[...e];d.splice(a,1),d.splice(c+u>>1,0,i);let h=DS(d),f=l(h),p=new Set(i.occupants.map(e=>e.id)),g=new Set(n.flatMap(e=>e.occupants.map(e=>e.id))),m=r.reduce((e,t)=>p.has(t.source)&&g.has(t.target)||p.has(t.target)&&g.has(t.source)?e+(t.value>0?t.value:1):e,0),y=Math.abs(2*a-c-u)*s*Math.max(1,m);XS(f,t,y)&&(e=h,t=f)};for(let[e,t]of n)!o.has(e)&&t.size>=3&&c(a.get(e),[...t].map(e=>a.get(e)));for(let e of i){let t=a.get(e.id);!e.group&&t.group&&(o.get(e.id)?.size??0)>=3&&c(t,[...o.get(e.id)??[]].map(e=>a.get(e)).filter(e=>e===t||e.group===t.group).filter((e,t,i)=>i.indexOf(e)===t))}return{order:e,after:t}}function VS(e,t){let i=[...new Set(Object.values(e))].sort((e,t)=>e-t),r=new Map(i.map((e,t)=>[e,t])),n=new Map(Object.entries(e).map(([e,t])=>[e,r.get(t)]));return new FS(t,n,i.length).count(i.map((e,t)=>t))}function HS(e,t){let i=0;for(let r of t){let t=e[r.source],n=e[r.target];null==t||null==n||(i+=Math.abs(t-n)*(r.value>0?r.value:1))}return i}var US=e=>{let t=1;for(let i=2;i<=e;i++)t*=i;return t},KS=/* @__PURE__ */828*US(8),ZS=3e3;function QS(e){let t=new Array(e.length),i=Math.floor((e.length-1)/2),r=i-1,n=i+1;e.length>0&&(t[i]=e[0]);for(let i=1;i<e.length;i++)i%2==1&&n<e.length?t[n++]=e[i]:r>=0?t[r--]=e[i]:t[n++]=e[i];return t}function JS(e,t,i){let r=i(e),n=r,o=[...e],a=Math.floor((e.length-1)/2);for(let s of t){let t=e.indexOf(s);if(t===a)continue;e.splice(t,1),e.splice(a,0,s);let l=i(e);l<=r?(r=l,l<n&&(o=[...e],n=l)):(e.splice(a,1),e.splice(t,0,s))}return o}function eA(e,t,i,r,n,o,a){let s=[...n],l=new Map(n.map(e=>[e,nS(e)])),c=/* @__PURE__ */new Map;for(let e of n)for(let t of e.occupants)c.set(t.id,e);let u=/* @__PURE__ */new Map,d=[];for(let e of t){let t=c.get(e.source),i=c.get(e.target);!t||!i||(u.set(e,[t,i]),t!==i&&d.push({source:t,target:i,weight:e.value}))}let h=t.reduce((e,t)=>e+(t.value>0?t.value:1),0),f=a.plotH/Math.max(1,n.length),p=n.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),g=Math.max(1,h)*(Math.max(1,a.plotH)+f*Math.max(p,n.length)+1e-6*Math.max(1,n.length-1))+1,m=4*f,y={fullCrossing:0,localCrossing:0},x=/* @__PURE__ */new Map,b=(e,t)=>{let r=x.get(e);r||(r=/* @__PURE__ */new Map,x.set(e,r));let n=r.get(t);if(null!=n)return n;let o=sS(e,t,i);return r.set(t,o),o},v=new Map(n.map((e,t)=>[e,t])),w=new FS(t,new Map([...c].map(([e,t])=>[e,v.get(t)])),n.length),k=e=>{let t=new Int32Array(n.length);for(let i=0;i<e.length;i++)t[v.get(e[i])]=i;return t},S=new Map([...u].map(([e,[t,i]])=>[e,{source:v.get(t),target:v.get(i),weight:e.value>0?e.value:1}])),A=[...S.values()],M=/* @__PURE__ */new Map,$=/* @__PURE__ */new Map,_=/* @__PURE__ */new Map,I=(e,t,i)=>{e.has(t)||e.set(t,/* @__PURE__ */new Set),e.get(t).add(i)};for(let e of t)I(M,e.source,e.target),I($,e.target,e.source),I(_,e.source,e.target),I(_,e.target,e.source);let P=e=>1===M.get(e.source)?.size&&M.get(e.source).has(e.target)||1===_.get(e.source)?.size||1===_.get(e.target)?.size,L=t.flatMap(e=>{if(!P(e))return[];let t=S.get(e);return t&&t.source!==t.target?[t]:[]}),R=e=>{let t=0;for(let i of L)t+=Math.max(0,Math.abs(e[i.source]-e[i.target])-1)*i.weight;return t*m},C=e=>R(k(e)),T=new Int32Array(n.length),N=new Float64Array(n.length),F=new Float64Array(n.length+1),E=e=>{for(let t=0;t<e.length;t++)T[v.get(e[t])]=t;let t=w.count(T);if(e.length>0){let t=v.get(e[0]);N[t]=a.padding+e[0].peak.topPeak*a.valueScale;for(let t=1;t<e.length;t++){let i=v.get(e[t-1]),r=v.get(e[t]);N[r]=N[i]+b(e[t-1],e[t])*a.valueScale+a.padding}let i=v.get(e[e.length-1]),r=N[i]+e[e.length-1].peak.botPeak*a.valueScale+a.padding;if(r>a.plotH&&r>0){let e=a.plotH/r;for(let t=0;t<N.length;t++)N[t]*=e}}F[0]=0;for(let t=0;t<e.length;t++)F[t+1]=F[t]+e[t].peak.topPeak+e[t].peak.botPeak;let i=0,r=0,n=0;for(let e of A){let t=T[e.source],o=T[e.target];if(i+=Math.abs(t-o)*e.weight,r+=Math.abs(N[e.source]-N[e.target])*e.weight,Math.abs(t-o)>=2){let i=Math.min(t,o)+1,r=Math.max(t,o);n+=(F[r]-F[i])*e.weight}}return t*g+r+n*f+R(T)+1e-6*i},O=(e,i)=>{let r=new Array(e.length+1).fill(0);for(let t=0;t<e.length;t++)r[t+1]=r[t]+e[t].peak.topPeak+e[t].peak.botPeak;let n=0;for(let e of t){let t=i[e.source],o=i[e.target];if(null==t||null==o||Math.abs(t-o)<2)continue;let a=Math.min(t,o)+1;n+=(r[Math.max(t,o)]-r[a])*(e.value>0?e.value:1)}return n},z=r=>{let n=ES(r),o=r.slice(0,-1).map((e,t)=>b(e,r[t+1])),s=dS(e,t,i,r,n,{plotH:a.plotH,padding:a.padding,valueScale:a.valueScale,lanePlacement:a.lanePlacement??"stack",groupPadding:a.groupPadding,adjacentClearance:o});return{map:n,geometry:s,weightedLength:HS(n,t),pixelLength:hS(s.centerlines,t)}},D=(e,n,o)=>{let s=n;null==s&&(s=w.count(k(e)),y.fullCrossing++);let{map:l,geometry:c,weightedLength:u,pixelLength:d}=z(e),h=o?xS(t,i,e,l,c.centerlines,r,{valueScale:a.valueScale,ribbonLane:a.ribbonLane,domain:a.domain,mode:o}):O(e,l);return{crossings:s,weightedLength:u,pixelLength:d,transitOcclusion:h,cost:s*g+d+h*f+C(e)+1e-6*u}},B=(e,t,i="quality")=>D(e,t,i),j=[...s],W=(e,t)=>rS(l.get(e),l.get(t)),Y=BS(j),q=(e,t,i,r=ZS)=>{let n=t(e);for(let o=0;o<i&&r>0;o++){let i=!1,a=Array.from({length:e.length-1},(e,t)=>t);o%2==1&&a.reverse();for(let o of a){if(r--<=0)break;let a=e[o],s=e[o+1],l=w.swapDelta(v.get(a),v.get(s),k(e));[e[o],e[o+1]]=[s,a],y.localCrossing+=l.evaluations;let c=t(e,n.crossings+l.delta);c.cost<n.cost?(n=c,i=!0):[e[o],e[o+1]]=[a,s]}if(!i)break}return e},X=e=>{let t=Jk(e,d,e=>D(e).cost,{passes:6,compare:W,maxEvaluations:ZS});return q(t,D,6)},G=e=>{let t=X(e);if((e.length<=8?US(e.length)*(e.length+A.length+w.work):1/0)>KS)return t;let i=tS(e,E,{maxItems:8,maxEvaluations:5e4}),r=B(i),n=B(t);return r.crossings!==n.crossings&&r.crossings<n.crossings?i:t},V=e=>e.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),H=(e,t)=>V(t)-V(e)||rS(e.stableId,t.stableId),U=(e,t)=>t.peak.topPeak+t.peak.botPeak-(e.peak.topPeak+e.peak.botPeak)||W(e,t),K="geometry-refine"===a.mode;if(K||"crossing-min"!==a.laneOrder&&"crossing-min+inside-out"!==a.laneOrder?K||"inside-out"!==a.laneOrder||(j=Y?jS(QS([...zS(j)].sort(H))):QS([...j].sort(U))):j=Y?(e=>{let t=zS(e);if(t.length<=1)return jS(t);let i=e=>D(jS(e)).cost;if(t=zS(G(e)),t=YS(t,d,W),t=Jk(t,WS(t,d),i,{passes:6,compare:(e,t)=>rS(e.stableId,t.stableId),maxEvaluations:ZS}),t=eS(t,i,{passes:8,maxEvaluations:ZS}),(t.length<=8?US(t.length)*(t.length+A.length+w.work):1/0)<=KS){let e=tS(t,e=>E(jS(e)),{maxItems:8,maxEvaluations:5e4}),i=jS(e),r=jS(t),n=B(i),o=B(r);n.crossings!==o.crossings?t=n.crossings<o.crossings?e:t:n.cost<o.cost&&(t=e)}return t=YS(t,d,W),jS(t)})(j):G(j),!K&&"crossing-min+inside-out"===a.laneOrder&&j.length>1)if(Y){let e=zS(j);j=jS(JS(e,[...e].sort(H),e=>D(jS(e)).cost))}else j=JS(j,[...j].sort(U),e=>D(e).cost);if((K||"crossing-min"===a.laneOrder||"crossing-min+inside-out"===a.laneOrder)&&j.length>1)if(Y){let e=eS(zS(j),e=>B(jS(e),void 0,"score").cost,{passes:6});e=YS(e,d,W),j=jS(e)}else q(j,(e,t)=>B(e,t,"score"),1,1/0);let Z=DS(s);j=DS(j);let Q=B(j),J=B(Z);if(K){let e=C(Z),t=C(j);(Q.crossings>J.crossings||Q.crossings===J.crossings&&t>e+1e-9||Q.cost>J.cost)&&(j=Z,Q=J)}else Q.cost>J.cost&&(j=Z,Q=J);let ee=GS({order:j,after:Q,nodes:e,edges:t,outgoingPartners:M,incomingPartners:$,slotForNode:c,averageGap:f,evaluate:B});return j=ee.order,Q=ee.after,OS(n,o,j),{before:J,after:Q,initialOrder:s.map(e=>l.get(e)),evaluations:y}}function tA(e,t,i){let r=new Map(i.map((e,t)=>[e,t]));OS(e,t,[...e].sort((e,t)=>(r.get(nS(e))??1/0)-(r.get(nS(t))??1/0)||rS(nS(e),nS(t))))}function iA(e,t,i){let r=e.map(e=>{let r=e.occupants.map(e=>({id:e.id,end:i[e.id]?.end??e.end})),n=0,o=0;for(let e of r){let i=t[e.id];n=Math.max(n,i?.topPeak||0),o=Math.max(o,i?.botPeak||0)}return{occupants:r,peak:{topPeak:n,botPeak:o},...null!=e.group?{group:e.group}:{}}}),n=iS();return r.forEach((e,t)=>{for(let i of e.occupants)n[i.id]=t}),{slots:r,slotByNode:n}}function rA(e,t,i,r){return`${e.map(e=>{let t=i[e.id],n=r[e.id];return[e.id,e.group??"",e.xExtent?.[0]??"",e.xExtent?.[1]??"",t?.topPeak??0,t?.botPeak??0,n?.start??"",n?.end??""].join(":")}).join("|")}#${t.map(e=>[e.id,e.source,e.target,e.value,e.startTime,e.endTime].join(":")).join("|")}`}var nA=/* @__PURE__ */new Map;function oA(e){return nA.get(e)}function aA(e,t){for(nA.has(e)&&nA.delete(e),nA.set(e,{slots:t.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),slotByNode:Object.assign(iS(),t.slotByNode)});nA.size>12;){let e=nA.keys().next().value;if(null==e)break;nA.delete(e)}}var sA=1e5,lA=1e-9;function cA(e,t){return null!=e.start&&null!=e.end&&null!=t.start&&null!=t.end&&!(e.end<=t.start||t.end<=e.start)}function uA(e,t){return rS(e,t)<=0?`${e}\0${t}`:`${t}\0${e}`}function dA(e){let t=/* @__PURE__ */new Map,i=/* @__PURE__ */new Map;for(let r of e)i.has(r.source)||i.set(r.source,/* @__PURE__ */new Set),t.has(r.target)||t.set(r.target,/* @__PURE__ */new Set),i.get(r.source).add(r.target),t.get(r.target).add(r.source);return{incoming:new Map([...t].map(([e,t])=>[e,t.size])),outgoing:new Map([...i].map(([e,t])=>[e,t.size]))}}function hA(e){let t=/* @__PURE__ */new Map,i=/* @__PURE__ */new Map,r=(e,t,i,r)=>{let n=e.get(t);n||(n=/* @__PURE__ */new Map,e.set(t,n)),n.set(i,(n.get(i)??0)+r)};for(let n of e){let e=n.value>0&&Number.isFinite(n.value)?n.value:1;r(t,n.source,n.target,e),r(i,n.target,n.source,e)}let n=/* @__PURE__ */new Map,o=e=>{if(n.has(e))return;let r=t.get(e),o=i.get(e),a=/* @__PURE__ */new Map;for(let[e,t]of r??[])a.set(e,(a.get(e)??0)+t);for(let[e,t]of o??[])a.set(e,(a.get(e)??0)+t);if(1===a.size){let[t,i]=[...a][0];n.set(e,{partner:t,weight:i})}};for(let t of e)o(t.source),o(t.target);return n}function fA(e,t,i){let r=i.get(e),n=i.get(t);return!r||!n||r.partner===n.partner||r.partner===t||n.partner===e}function pA(e,t,i){return!!i.has(e)&&t.some(t=>!fA(e,t,i))}function gA(e,t){return(e.value>0&&Number.isFinite(e.value)?e.value:1)*(1+(1===t.outgoing.get(e.source)?1:0)+(1===t.incoming.get(e.target)?1:0))}function mA(e,t,i,r,n,o){let a=/* @__PURE__ */new Set,s=new Map(e.map(e=>[e,/* @__PURE__ */new Set])),l=new Map(e.map(e=>[e,/* @__PURE__ */new Set]));for(let e of r)a.add(uA(e.source,e.target)),s.get(e.target)?.add(e.source),l.get(e.source)?.add(e.target);let c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Set,d=(e,t)=>{for(let i=0;i<e.length;i++)for(let r=i+1;r<e.length;r++){let n=uA(e[i],e[r]);t instanceof Map?t.set(n,[e[i],e[r]]):t.add(n)}};for(let e of l.values())d([...e],c);for(let e of s.values())d([...e],u);let h=/* @__PURE__ */new Set;for(let[e,[r,n]]of c)u.has(e)&&(cA(t[r],t[n])||cA(i[r],i[n])&&(h.add(r),h.add(n)));return{conflicts:(e,i)=>{let r=n.get(e),s=n.get(i);return!((null==r||null==s||r===s)&&(null!=r==(null!=s)||a.has(uA(e,i))||o.has(e)&&o.has(i)&&fA(e,i,o))&&!cA(t[e],t[i])&&(!h.has(e)&&!h.has(i)||a.has(uA(e,i))))}}}function yA(e,t){return e.filter(e=>null!=t[e.id].start).sort((e,i)=>t[e.id].start-t[i.id].start||t[e.id].end-t[i.id].end||rS(e.id,i.id)).map(e=>e.id)}function xA(e,t,i=/* @__PURE__ */new Map){let r=[],n=[];for(let o of e){let e=r.findIndex(e=>e.every(e=>!t.conflicts(o,e))&&!pA(o,e,i));-1===e&&!i.has(o)&&(e=r.findIndex(e=>e.every(e=>!t.conflicts(o,e)))),-1===e&&(e=r.length,r.push([])),r[e].push(o),n.push(e)}return{assignment:n,slotCount:r.length}}function bA(e,t,i,r){if(e.length<=12||r.slotCount<=1)return r.assignment;let n=new Map(e.map((e,t)=>[e,t])),o=Array.from({length:e.length},()=>/* @__PURE__ */new Map),a=dA(i);for(let e of i){let t=n.get(e.source),i=n.get(e.target);if(null==t||null==i||t===i)continue;let r=gA(e,a);o[t].set(i,(o[t].get(i)??0)+r),o[i].set(t,(o[i].get(t)??0)+r)}let s=hA(i),l=e.map(e=>s.get(e)?.weight??0),c=Array.from({length:e.length},()=>/* @__PURE__ */new Map),u=0;for(let i=0;i<e.length-1&&u<5e4;i++)if(s.has(e[i]))for(let r=i+1;r<e.length;r++){if(!s.has(e[r])||t.conflicts(e[i],e[r]))continue;u++;let n=Math.min(l[i],l[r])||Math.max(l[i],l[r]),o=fA(e[i],e[r],s)?n:-n;if(!(Math.abs(o)<=lA)&&(c[i].set(r,o),c[r].set(i,o),u>=5e4))break}let d=[...r.assignment],h=Array.from({length:r.slotCount},()=>[]);d.forEach((e,t)=>h[e].push(t));let f=(e,t,i)=>{let r=d[t],n=d[i],o=0,a=/* @__PURE__ */new Set;for(let s of[t,i])for(let[l,c]of e[s]){let e=s<l?`${s}:${l}`:`${l}:${s}`;if(a.has(e))continue;a.add(e);let u=d[s]===d[l],h=(s===t?n:r)===(l===t?n:l===i?r:d[l]);u!==h&&(o+=h?c:-c)}return o},p=(e,t,i)=>{let r=0;for(let[n,o]of e[t]){let e=d[t]===d[n],a=i===d[n];e!==a&&(r+=a?o:-o)}return r},g=(e,t)=>e>lA||Math.abs(e)<=lA&&t>lA,m=(e,t,i,r)=>e>i+lA||Math.abs(e-i)<=lA&&t>r+lA,y=0;for(let i=0;i<32&&y<sA;i++){let i=null,r=-1,n=-1,a=-1,s=-1/0,l=-1/0;for(let u=0;u<e.length;u++){for(let f=0;f<h.length&&!(y++>=sA);f++){if(f===d[u]||!h[f].every(i=>!t.conflicts(e[u],e[i])))continue;let y=p(o,u,f),x=p(c,u,f);g(y,x)&&m(y,x,s,l)&&(i="move",r=u,n=-1,a=f,s=y,l=x)}if(y>=sA)break}for(let u=0;u<e.length-1;u++){for(let p=u+1;p<e.length&&!(y++>=sA);p++){let y=d[u],x=d[p];if(y===x||!h[x].every(i=>i===p||!t.conflicts(e[u],e[i]))||!h[y].every(i=>i===u||!t.conflicts(e[p],e[i])))continue;let b=f(o,u,p),v=f(c,u,p);g(b,v)&&m(b,v,s,l)&&(i="swap",r=u,n=p,a=-1,s=b,l=v)}if(y>=sA)break}if(null==i||-1===r)break;if("move"===i){let e=d[r];h[e].splice(h[e].indexOf(r),1),h[a].push(r),d[r]=a;continue}let u=d[r],x=d[n];h[u].splice(h[u].indexOf(r),1,n),h[x].splice(h[x].indexOf(n),1,r),d[r]=x,d[n]=u}return d}function vA(e,t){for(let i=0;i<Math.min(e.length,t.length);i++)if(e[i]!==t[i])return e[i]<t[i];return e.length<t.length}function wA(e,t,i,r){if(0===e.length||e.length>12||r.slotCount<=1)return r.assignment;let n=new Map(e.map((e,t)=>[e,t])),o=Array.from({length:e.length},()=>new Float64Array(e.length)),a=Array.from({length:e.length},()=>/* @__PURE__ */new Map),s=Array.from({length:e.length},()=>/* @__PURE__ */new Map),l=dA(i);for(let e of i){let t=n.get(e.source),i=n.get(e.target);if(null==t||null==i||t===i)continue;let r=gA(e,l);o[t][i]+=r,o[i][t]+=r,s[t].set(i,(s[t].get(i)??0)+r),a[i].set(t,(a[i].get(t)??0)+r)}let c=hA(i),u=e.map(e=>c.get(e)?.weight??0),d=Array.from({length:e.length},()=>new Float64Array(e.length));for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++){for(let[e,r]of a[t])d[t][i]+=Math.min(r,a[i].get(e)??0);for(let[e,r]of s[t])d[t][i]+=Math.min(r,s[i].get(e)??0);if(c.has(e[t])&&c.has(e[i])){let r=Math.min(u[t],u[i])||Math.max(u[t],u[i]);d[t][i]+=fA(e[t],e[i],c)?r:-r}d[i][t]=d[t][i]}let h=[...r.assignment],f=(t=>{let i=0,r=0;for(let n=0;n<e.length;n++)for(let a=n+1;a<e.length;a++)t[n]===t[a]&&(i+=o[n][a],r+=d[n][a]);return{flow:i,affinity:r}})(h),p=0,g=new Array(e.length).fill(-1),m=Array.from({length:r.slotCount},()=>[]),y=(i,n,a,s)=>{if(p>=75e3)return;if(i===e.length)return p++,void((a>f.flow||a===f.flow&&s>f.affinity||a===f.flow&&s===f.affinity&&vA(g,h))&&(h=[...g],f={flow:a,affinity:s}));let l=Math.min(n+1,r.slotCount-1);for(let r=0;r<=l;r++){if(m[r].some(r=>t.conflicts(e[i],e[r])))continue;let l=0,c=0;for(let e of m[r])l+=o[i][e],c+=d[i][e];if(g[i]=r,m[r].push(i),y(i+1,Math.max(n,r),a+l,s+c),m[r].pop(),g[i]=-1,p>=75e3)return}};return g[0]=0,m[0].push(0),y(1,0,0,0),h}function kA(e,t){let i=1/0,r=-1/0;for(let t of e?.samples??[])t.topMass+t.botMass<=1e-9||(i=Math.min(i,t.t),r=Math.max(r,t.t));return Number.isFinite(i)&&Number.isFinite(r)?(null!=t.start&&(i=Math.max(i,t.start)),null!=t.end&&(r=Math.min(r,t.end)),r>=i?{start:i,end:r}:{start:null,end:null}):{start:null,end:null}}function SA(e,t,i,r){let n=rA(e,t,i,r),o=oA(n);if(o)return iA(o.slots,i,r);let a=iS();for(let t of e)a[t.id]=kA(i[t.id],r[t.id]);let s=yA(e,a),l=new Map(e.map(e=>[e.id,e])),c=new Map(e.map(e=>[e.id,e.group||void 0])),u=hA(t),d=mA(s,a,r,t,c,u),h=xA(s,d,u),f=wA(s,d,t,{...h,assignment:bA(s,d,t,h)}),p=/* @__PURE__ */new Map,g=f.map(e=>(p.has(e)||p.set(e,p.size),p.get(e))),m=Array.from({length:p.size||(e.length>0?1:0)},()=>({occupants:[],peak:{topPeak:0,botPeak:0}})),y=iS();s.forEach((e,t)=>{let i=g[t],r=m[i];r.occupants.push({id:e,end:a[e].end??-1/0});let n=l.get(e)?.group;n&&(r.group=n),y[e]=i});for(let t of[...e].sort((e,t)=>rS(e.id,t.id)))null==y[t.id]&&(m[0].occupants.push({id:t.id,end:-1/0}),y[t.id]=0);for(let e of m){e.occupants.sort((e,t)=>(a[e.id].start??1/0)-(a[t.id].start??1/0)||rS(e.id,t.id));for(let t of e.occupants){let r=i[t.id];e.peak.topPeak=Math.max(e.peak.topPeak,r?.topPeak||0),e.peak.botPeak=Math.max(e.peak.botPeak,r?.botPeak||0)}}let x={slots:m,slotByNode:y};return aA(n,x),x}function AA(e){return e.topMass+e.botMass}function MA(e){let t=/* @__PURE__ */new Map;for(let i of e.samples){if(Number.isNaN(i.t))continue;let e=t.get(i.t);e||(e=[],t.set(i.t,e)),e.push(i)}let i=0,r=-1/0;return n=>{n>=r||(i=0),r=n;let o=t.get(n);if(o){let e=o.reduce((e,t)=>AA(t)>=AA(e)?t:e,o[0]);return{exact:o,sample:e}}for(;i<e.samples.length&&!(e.samples[i].t>n);)i++;return{exact:o,sample:e.samples[i-1]??null}}}function $A(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t,samples:t.samples.map(e=>({...e})),localAttachments:new Map([...t.localAttachments].map(([e,t])=>[e,{...t}]))}]))}function _A(e,t,i,r,n,o,a=0){let s=/* @__PURE__ */new Map;for(let i of e){if(!i.group||!t[i.id])continue;let e=s.get(i.group)??[];e.push(i),s.set(i.group,e)}if(0===s.size||!(o>0))return t;let l=$A(t);for(let[e,c]of s){let s=i.map((e,t)=>({slot:e,index:t})).filter(({slot:t})=>t.group===e);if(0===s.length)continue;let u=s[0].slot,d=s.at(-1).slot,h=n[u.occupants[0]?.id],f=n[d.occupants[0]?.id];if(!Number.isFinite(h)||!Number.isFinite(f))continue;let p=(h-u.peak.topPeak*o+(f+d.peak.botPeak*o))/2,g=[...new Set(c.flatMap(e=>t[e.id].samples.map(e=>e.t)))].sort((e,t)=>e-t),m=/* @__PURE__ */new Map;for(let e of c)m.set(e.id,/* @__PURE__ */new Map);let y=new Map(c.map(e=>[e.id,MA(t[e.id])]));for(let e of g){let t=/* @__PURE__ */new Map;for(let i of c){let{sample:n}=y.get(i.id)(e);if(!n||AA(n)<=1e-9)continue;let o=r[i.id];if(null==o)continue;let a=t.get(o)??[];a.push({node:i,sample:n}),t.set(o,a)}let i=[...t].sort((e,t)=>e[0]-t[0]).map(([e,t])=>({slot:e,active:t,mass:Math.max(...t.map(({sample:e})=>AA(e)))}));if(0===i.length)continue;let s=p-(i.reduce((e,t)=>e+t.mass,0)*o+Math.max(0,a)*Math.max(0,i.length-1))/2;for(let t of i){for(let{node:i,sample:r}of t.active){let t=(s-n[i.id])/o+r.topMass-(r.boundaryOffset??0);m.get(i.id).set(e,t)}s+=t.mass*o+Math.max(0,a)}}for(let e of c){let i=t[e.id],r=l[e.id],n=m.get(e.id),o=y.get(e.id),a=[];for(let e of g){let t=n.get(e),{exact:i,sample:r}=o(e);i?a.push(...i.map(e=>({...e,...null!=t?{boundaryOffset:(e.boundaryOffset??0)+t}:{}}))):null==t||!r||AA(r)<=1e-9||a.push({...r,t:e,boundaryOffset:(r.boundaryOffset??0)+t})}r.samples=a,r.localAttachments=new Map([...i.localAttachments].map(([e,t])=>{let i=n.get(t.time);return[e,{...t,...null!=i?{boundaryOffset:(t.boundaryOffset??0)+i}:{}}]}))}}return l}function IA(e,t,i,r,n){let{plotH:o,padding:a,valueScale:s,packing:l,laneOrder:c,lifetimeMode:u="half",lanePlacement:d="stack",groupPadding:h=0,ribbonLane:f="both",domain:p}=n,g=iS(),m=iS();for(let t of e)g[t.id]=i[t.id].topPeak||0,m[t.id]=i[t.id].botPeak||0;let y="half"===u,x=iS();for(let t of e){let e=Array.isArray(t.xExtent)?t.xExtent[0]:null,i=Array.isArray(t.xExtent)?t.xExtent[1]:null,n=null!=e&&Number.isFinite(e)?e:1/0,o=null!=i&&Number.isFinite(i)?i:-1/0;for(let e of r.outgoing[t.id]){e.startTime<n&&(n=e.startTime),null!=e.systemInTime&&Number.isFinite(e.systemInTime)&&e.systemInTime<n&&(n=e.systemInTime);let t=y?(e.startTime+e.endTime)/2:e.endTime;t>o&&(o=t)}for(let e of r.incoming[t.id]){let t=y?(e.startTime+e.endTime)/2:e.startTime;t<n&&(n=t),e.endTime>o&&(o=e.endTime),null!=e.systemOutTime&&Number.isFinite(e.systemOutTime)&&e.systemOutTime>o&&(o=e.systemOutTime)}x[t.id]={start:Number.isFinite(n)?n:null,end:Number.isFinite(o)?o:null}}let b=iS(),v=[],w=[];if(n.frozenSlots){let e=iA(n.frozenSlots,i,x);v=e.slots,b=e.slotByNode,w=v.map(nS)}else if("reuse"===l){let r=SA(e,t,i,x);v=r.slots,b=r.slotByNode}else e.forEach((e,t)=>{v.push({occupants:[{id:e.id,end:x[e.id]?.end??-1/0}],peak:{topPeak:g[e.id],botPeak:m[e.id]},...e.group?{group:e.group}:{}}),b[e.id]=t});qS(v,b),0===w.length&&(w=v.map(nS));let k=null;n.frozenSlots||(n.fixedSlotOrder?tA(v,b,n.fixedSlotOrder):n.runOrdering&&c&&"insertion"!==c&&(k=eA(e,t,i,x,v,b,{plotH:o,padding:a,valueScale:s,groupPadding:h,laneOrder:c,ribbonLane:f,domain:p}))),qS(v,b);let S=dS(e,t,i,v,b,{plotH:o,padding:a,valueScale:s,stackValueScale:n.stackValueScale,lanePlacement:d,groupPadding:h}),A=0===v.length?0:v[0].peak.topPeak+S.adjacentClearance.reduce((e,t)=>e+t,0)+v[v.length-1].peak.botPeak,M=k?.before.crossings??null,$=k?.after.crossings??null,_=k?.before.weightedLength??null,I=k?.after.weightedLength??null;return{effectiveSlotsHeight:A,centerlines:S.centerlines,laneLifetime:x,slots:v,slotByNode:b,slotCenter:S.slotCenter,stackCenter:S.stackCenter,verticalUtilization:S.verticalUtilization,selectedSlotOrder:v.map(nS),initialSlotOrder:w,ordering:k,crossingsBefore:M,crossingsAfter:$,lengthBefore:_,lengthAfter:I}}function PA(e,t,i){let{plotH:r,pairing:n="temporal",packing:o="reuse",laneOrder:a="crossing-min",lifetimeMode:s="half",maxValueScale:l,lanePlacement:c="stack",nodeSizing:u="temporal",groupPadding:d=0,ribbonLane:h="both",domain:f}=i,p=Number.isFinite(d)?Math.max(0,d):0,g=MS(e,t),m=$S(e,t,g,n),y=iS();for(let t of e)y[t.id]=_S(t,g,m,void 0,u);let x=IA(e,t,y,g,{plotH:r,padding:12,valueScale:1,packing:o,laneOrder:a,lifetimeMode:s,runOrdering:!0,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),b=x.slots.map(e=>({occupants:e.occupants.map(e=>({...e})),peak:{...e.peak},...null!=e.group?{group:e.group}:{}})),v=/* @__PURE__ */new Set;for(let e of t){let t=x.slotByNode[e.source],i=x.slotByNode[e.target];if(void 0===t||void 0===i)continue;let r=m.get(e.id);t!==i?i<t?(r.sourceSide="top",r.targetSide="bot"):(r.sourceSide="bot",r.targetSide="top"):(v.add(e.id),r.sourceSide="bot",r.targetSide="bot")}for(let t of e){let e=g.outgoing[t.id],i=g.incoming[t.id],r=new Set(e.map(e=>m.get(e.id).sourceSide)),n=new Set(i.map(e=>m.get(e.id).targetSide));if(1===r.size&&i.length>0){let e=[...r][0];for(let t of i)x.slotByNode[t.source]===x.slotByNode[t.target]&&(m.get(t.id).targetSide=e)}if(1===n.size&&e.length>0){let t=[...n][0];for(let i of e)x.slotByNode[i.source]===x.slotByNode[i.target]&&(m.get(i.id).sourceSide=t)}}LS(t,m,x.slotByNode),RS(e,g,m,v),y=iS();for(let t of e)y[t.id]=_S(t,g,m,void 0,u);let w=IA(e,t,y,g,{plotH:r,padding:12,valueScale:1,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:b,lanePlacement:"stack",groupPadding:p,ribbonLane:h,domain:f}),k=w.effectiveSlotsHeight??w.slots.reduce((e,t)=>e+t.peak.topPeak+t.peak.botPeak,0),S=w.slots.slice(0,-1).reduce((e,t,i)=>e+(null!=t.group&&t.group===w.slots[i+1].group?1:0),0),A=Math.max(1,w.slots.length+1-S),M=Math.min(12,Math.max(0,.35*r-S*p)/A),$=2*M+oS(w.slots,M,p).reduce((e,t)=>e+t,0),_=k>0?Math.max(0,(r-$)/k):1,I=Number.isFinite(l)&&l>0?Math.min(_,l):_,P=IA(e,t,y,g,{plotH:r,padding:M,valueScale:I,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:b,lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:_}),L=Number.isFinite(l)&&l>0&&l+1e-12<_;if("insertion"!==a&&("hug"===c||L)&&P.slots.length>1&&(eA(e,t,y,P.laneLifetime,P.slots,P.slotByNode,{plotH:r,padding:M,valueScale:I,groupPadding:p,laneOrder:a,ribbonLane:h,domain:f,lanePlacement:c,mode:"geometry-refine"}),P=IA(e,t,y,g,{plotH:r,padding:M,valueScale:I,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:P.slots,fixedSlotOrder:P.slots.map(nS),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:_})),PS(g,m)){let i=IS(t,y,P.centerlines,I);y=iS();for(let t of e)y[t.id]=_S(t,g,m,i,u);P=IA(e,t,y,g,{plotH:r,padding:M,valueScale:I,packing:o,laneOrder:a,lifetimeMode:s,frozenSlots:P.slots,fixedSlotOrder:P.slots.map(nS),lanePlacement:c,groupPadding:p,ribbonLane:h,domain:f,stackValueScale:_})}let R=new Map(x.initialSlotOrder.map((e,t)=>[e,t])),C=[...P.slots].sort((e,t)=>(R.get(nS(e))??1/0)-(R.get(nS(t))??1/0)||rS(nS(e),nS(t))),T=iS();C.forEach((e,t)=>{for(let i of e.occupants)T[i.id]=t});let N=dS(e,t,y,C,T,{plotH:r,padding:M,valueScale:I,stackValueScale:_,lanePlacement:"stack",groupPadding:p}),F=_A(e,y,C,T,N.centerlines,I,p),E=bS(VS(T,t),HS(T,t),t,F,C,T,N.centerlines,P.laneLifetime,I,N.verticalUtilization,h,f);y=_A(e,y,P.slots,P.slotByNode,P.centerlines,I,p);let O=bS(VS(P.slotByNode,t),HS(P.slotByNode,t),t,y,P.slots,P.slotByNode,P.centerlines,P.laneLifetime,I,P.verticalUtilization,h,f);return{nodeData:y,sides:m,valueScale:I,padding:M,compressedPadding:M<12,centerlines:P.centerlines,laneLifetime:P.laneLifetime,slots:P.slots,slotByNode:P.slotByNode,crossingsBefore:"insertion"===a?null:E.crossings,crossingsAfter:"insertion"===a?null:O.crossings,lengthBefore:"insertion"===a?null:E.weightedLength,lengthAfter:"insertion"===a?null:O.weightedLength,layoutQualityBefore:E,layoutQuality:O}}function LA(e){return Vt(e)}function RA(e){return Ht(e)}function CA(e){let{sx:t,sTop:i,sBot:r,tx:n,tTop:o,tBot:a,cp1X:s,cp2X:l}=e,c=(i+r)/2,u=(o+a)/2;return{pathD:[`M${t},${i}`,`C${s},${i} ${l},${o} ${n},${o}`,`L${n},${a}`,`C${l},${a} ${s},${r} ${t},${r}`,"Z"].join(" "),bezier:{circular:!1,points:[{x:t,y:c},{x:s,y:c},{x:l,y:u},{x:n,y:u}],halfWidth:(r-i)/2}}}function TA(e,t,i,r,n,o,a,s,l={}){let c,u,d,h,f=n,p=e=>s?Math.max(s[0],Math.min(s[1],e)):e,g=o(p(e.time)),m=o(p(i.time)),y=e.value*f,x=i.value*f,b=t+(e.boundaryOffset??0)*f,v=r+(i.boundaryOffset??0)*f,w=e.sideMassBefore*f,k=i.sideMassAfter*f;"top"===e.side?(c=b-w,u=c+y):(u=b+w,c=u-y),"top"===i.side?(d=v-k,h=d+x):(h=v+k,d=h-x);let S=l.sourceRunwayStart,A=l.minRun,M=(c+u)/2,$=(d+h)/2,_=Math.abs($-M),I=m-g,P="number"==typeof S&&Number.isFinite(S),L="number"==typeof A&&Number.isFinite(A)&&A>0;if(P&&_>1e-9&&I>0&&("auto"===A||L)){let t="source"===a?.85:"target"===a?.15:.5,i=1.5*Math.min(t*t,(1-t)*(1-t)),r="auto"===A?Math.min(144,Math.sqrt(8*_/i)):A;if(r>I){let t=o(p(Math.min(S,e.time)));if(Number.isFinite(t)){let e=Math.min(g,t);g=Math.min(g,Math.max(e,m-r))}}}let R="source"===a?g+.85*(m-g):"target"===a?g+.15*(m-g):(g+m)/2;return{sx:g,sTop:c,sBot:u,tx:m,tTop:d,tBot:h,cp1X:R,cp2X:R}}function NA(e,t,i,r,n,o){let a=new Map(t),s=/* @__PURE__ */new Map;for(let t of e){let e=o?.get(t.source),i=null==e?`node:${t.source}`:`group:${e}`,r=s.get(i)??/* @__PURE__ */new Map,n=r.get(t.startTime)??[];n.push(t),r.set(t.startTime,n),s.set(i,r)}for(let e of s.values())for(let[o,s]of e){if(!s.some(e=>i.has(e.id)))continue;let e=s.map(e=>t.get(e.id));if(e.some(e=>null==e))continue;let l=r(o),c=Math.min(...e.map(e=>e.sx));if(!(c<l-1e-9))continue;let u=Math.max(...s.map(e=>{let t=i.get(e.id);return null==t?l:Math.min(l,r(t))})),d=Math.min(l,Math.max(c,u));for(let e of s){let i=t.get(e.id),r="source"===n?.85:"target"===n?.15:.5,o=d+(i.tx-d)*r;a.set(e.id,{...i,sx:d,cp1X:o,cp2X:o})}}return a}function FA(e,t,i){let r=new Set(t.map(e=>e.target)),n=new Map(e.map(e=>[e.id,e])),o=/* @__PURE__ */new Map;for(let e of t){if(r.has(e.source))continue;let t=o.get(e.source)??[];t.push(e),o.set(e.source,t)}let a=/* @__PURE__ */new Map;for(let t of e){if(!t.group)continue;let e=a.get(t.group)??[];e.push(t),a.set(t.group,e)}let s=/* @__PURE__ */new Set;for(let[e,t]of a){let i=t.flatMap(e=>o.get(e.id)??[]),n=new Set(i.map(e=>e.startTime));i.length>0&&1===n.size&&t.every(e=>{let t=e.xExtent?.[0],n=i[0].startTime;return!r.has(e.id)&&(o.get(e.id)?.length??0)>0&&Number.isFinite(t)&&t<n})&&s.add(e)}let l=/* @__PURE__ */new Map;for(let[e,t]of o){let r=n.get(e);if(r?.group&&!s.has(r.group))continue;let o=r?.xExtent?.[0],a=[...t].sort((e,t)=>e.startTime-t.startTime||e.id.localeCompare(t.id)),c=a[0]?.startTime-1,u=null;for(let e=0;e<a.length;){let t=a[e].startTime,r=e+1;for(;r<a.length&&a[r].startTime===t;)r++;for(let t=e;t<r;t++){let e=a[t],r=Number.isFinite(o)&&o<e.startTime,n=Number.isFinite(e.systemInTime)&&e.systemInTime<e.startTime;if(!r&&!n)continue;let s=i[0];r&&(s=Math.max(s,o)),n&&(s=Math.max(s,e.systemInTime)),!r&&n&&Number.isFinite(c)&&(s=Math.max(s,c)),null!=u&&(s=Math.max(s,u)),s<e.startTime&&l.set(e.id,s)}u=t,e=r}}for(let[e,t]of a){if(!s.has(e))continue;let i=t.flatMap(e=>o.get(e.id)??[]);if(!i.every(e=>l.has(e.id))){for(let e of i)l.delete(e.id);continue}let r=Math.max(...i.map(e=>l.get(e.id)));for(let e of i)l.set(e.id,r)}return l}function EA(e,t,i,r,n){let o=/* @__PURE__ */new Map;for(let a of e){if(!i.has(a.id))continue;let e=t.get(a.id);if(!(e&&e.sx<r(a.startTime)-1e-9))continue;let s=n(e.sx);Number.isFinite(s)&&s<a.startTime&&o.set(a.id,s)}return o}function OA(e,t,i){let r=/* @__PURE__ */new Map,n=/* @__PURE__ */new Map;for(let[e,t]of i??[]){let i=n.get(t)??[];i.push(e),n.set(t,i)}for(let o of e){let e=t.get(o.id);if(!(null!=e&&Number.isFinite(e)&&e<o.startTime))continue;let a=i?.get(o.source),s=null==a?[o.source]:n.get(a)??[o.source];for(let t of s){let i=r.get(t)??/* @__PURE__ */new Map,n=i.get(o.startTime);i.set(o.startTime,null==n?e:Math.min(n,e)),r.set(t,i)}}return r}function zA(e,t){return t&&0!==t.size?e.map(e=>{let i=t.get(e.t);return null==i?e:{...e,t:i}}):e}function DA(e){return Math.max(18,11*e.length*.58)}function BA(e){let t=1.22*DA(e.labelText)+4;return"start"===e.labelAnchor?[e.labelX,e.labelX+t]:"middle"===e.labelAnchor?[e.labelX-t/2,e.labelX+t/2]:[e.labelX-t,e.labelX]}function jA(e,t){let i=e.labelX-DA(e.labelText),r=t.labelX-DA(t.labelText);return i<=t.labelX+3&&r<=e.labelX+3}function WA(e,t){let i=[...e].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX||e.id.localeCompare(t.id));for(let e=0;e<3;e+=1){for(let e=0;e<i.length;e+=1){let t=8;for(let r=0;r<e;r+=1)jA(i[e],i[r])&&(t=Math.max(t,i[r].labelY+16));i[e].labelY=Math.max(i[e].labelY,t)}for(let e=i.length-1;e>=0;e-=1){let r=t-8;for(let t=e+1;t<i.length;t+=1)jA(i[e],i[t])&&(r=Math.min(r,i[t].labelY-16));i[e].labelY=Math.min(i[e].labelY,r)}}}function YA(e,t,i){let r=e.map(e=>({...e})),n=/* @__PURE__ */new Map;for(let e of r){let i=t[e.id];if(null==i)continue;let r=n.get(i)??[];r.push(e),n.set(i,r)}let o=e=>{if(e.length<2)return;let t=e.reduce((e,t)=>e+t.labelY,0)/e.length,r=(e.length-1)/2;e.forEach((e,n)=>{e.labelY=Math.max(8,Math.min(i-8,t+16*(n-r)))})};for(let e of n.values()){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],i=-1/0;for(let r of e){let e=r.labelX-DA(r.labelText);t.length>0&&e>i+3&&(o(t),t=[],i=-1/0),t.push(r),i=Math.max(i,r.labelX)}o(t)}return WA(r,i),r}function qA(e,t,i){let r=e.map(e=>({...e}));for(let e of r){let i=1.22*DA(e.labelText)+4;e.labelX=i>=t-4?t/2:Math.max(i/2+2,Math.min(t-i/2-2,e.labelX))}let n=[],o=[...r].sort((e,t)=>e.labelY-t.labelY||e.labelX-t.labelX);for(let e of o){let t=n[n.length-1];!t||Math.abs(t[0].labelY-e.labelY)>14?n.push([e]):t.push(e)}for(let e of n){e.sort((e,t)=>e.labelX-t.labelX||e.id.localeCompare(t.id));let t=[],r=/* @__PURE__ */new Map;for(let i of e){let[e,n]=BA(i),o=t.findIndex(t=>e>t+8);-1===o&&(o=t.length),t[o]=n,r.set(i,o)}let n=e.reduce((e,t)=>e+t.labelY,0)/e.length,o=n<14*t.length+8;for(let t of e){let e=r.get(t)??0;t.labelY=o?Math.min(i-8,12+14*e):Math.max(8,n-14*e)}}return r}function XA(e,t,i,r,n={}){if(!1===r)return e.map(e=>({...e,labelText:"",labelDeferred:!1,labelFullText:void 0}));if(!0===r)return e.map(e=>({...e,labelDeferred:!1,labelFullText:void 0}));let o=Math.max(1,t*i),a=Math.max(4,Math.min(e.length,Math.floor(o/14e3)));Number.isFinite(n.maxLabels)&&n.maxLabels>=0&&(a=Math.min(a,Math.floor(n.maxLabels)));let s=e.map((e,t)=>{let i=n.priorityById?.get(e.id),r=Math.abs(e.labelY);return{band:e,index:t,score:null!=i&&Number.isFinite(i)?1e6*i+DA(e.labelText):DA(e.labelText)+.01*r}}).filter(e=>e.band.labelText.trim().length>0).sort((e,t)=>t.score-e.score||e.index-t.index||e.band.id.localeCompare(t.band.id)),l=new Set(s.slice(0,a).map(e=>e.band.id));return e.map(e=>l.has(e.id)||0===e.labelText.trim().length?{...e,labelDeferred:!1,labelFullText:void 0}:{...e,labelFullText:e.labelText,labelText:"",labelDeferred:!0})}var GA=/(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?),(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)/gi;function VA(e){return e.replace(GA,(e,t,i)=>`${i},${t}`)}function HA(e){if(!e)return;let t=e=>({x:e.y,y:e.x});return{...e,...e.points&&{points:e.points.map(t)},...e.segments&&{segments:e.segments.map(e=>e.map(t))}}}function UA(e){return{...e,pathD:VA(e.pathD),y0:e.x0,y1:e.x1,x0:0,x1:0}}function KA(e,t){return"horizontal"===t?e:{...e,pathD:VA(e.pathD),gradientStubs:e.gradientStubs?.map(UA),labelX:e.labelY,labelY:e.labelX,labelAnchor:"middle",labelBaseline:"auto"}}function ZA(e,t){return"horizontal"===t?e:{...e,pathD:VA(e.pathD),bezier:HA(e.bezier)}}function QA(e){let{nodes:t,edges:i,domain:r,usageMode:n="static"}=e,o=Hk(t,i,r,{usageMode:n}),{fatal:a,warnings:s}=Vk(o),l=Uk(i,o,n);return{layout:a.length?null:PA(t,l,{plotH:"vertical"===e.orientation?e.plotW:e.plotH,...e.layoutOpts,ribbonLane:e.ribbonLane,domain:r}),issues:a,warnings:s}}function JA(e,t=QA(e)){let{nodes:i,edges:r,domain:n,plotW:o,plotH:a,ribbonLane:s,ribbonMinRun:l=0,edgeOpacity:c,colorOf:u,orientation:d="horizontal",showLabels:h=!0,labelPriorityAccessor:f,maxLabels:p,selectionDatum:g="raw",styleRules:m,colorBy:y,valueAccessor:x,usageMode:b="static"}=e,v="vertical"===d?a:o,w="vertical"===d?o:a,{layout:k,issues:S,warnings:A}=t,M=Uk(r,[...S,...A],b),$=Wk().domain(n).range([0,v]);if(!k)return{layout:null,layoutConfig:{bands:[],ribbons:[],showLabels:!1!==h},issues:S,warnings:A,xScale:$};let{centerlines:_,nodeData:I,valueScale:P}=k,L=Bi(y,x),R=[],C=[],T=0===l?/* @__PURE__ */new Map:FA(i,M,n),N=new Map(i.filter(e=>e.group).map(e=>[e.id,e.group])),F=/* @__PURE__ */new Map;for(let e of M){let t=I[e.source]?.localAttachments.get(e.id),i=I[e.target]?.localAttachments.get(e.id);!t||!i||F.set(e.id,TA(t,_[e.source],i,_[e.target],P,$,s,n,{minRun:l,sourceRunwayStart:T.get(e.id)}))}let E=NA(M,F,T,$,s,N),O=EA(M,E,T,$,e=>n[0]+e/v*(n[1]-n[0])),z=OA(M,O,N);i.forEach((e,t)=>{let i=I[e.id];if(!i||0===i.samples.length)return;let r=zA(i.samples,z.get(e.id)),o=SS(r,_[e.id],P,$,n);if(!o)return;let a,s,l=wS(r,n),c=l.find(e=>e.topMass+e.botMass>0)||l[0],h=(c.botMass-c.topMass+2*(c.boundaryOffset??0))*P/2,f=_[e.id]+h,p=u(e.id,t),g=p,y=.5,x=e.__raw??e;if(m&&m.length>0){let e=qi(x,m,L(x));"string"==typeof e.fill?p=e.fill:null!=e.fill&&el(e.fill)&&(s=e.fill,p=e.fill.background&&"transparent"!==e.fill.background?e.fill.background:p),"string"==typeof e.stroke&&(g=e.stroke),"number"==typeof e.strokeWidth&&(y=e.strokeWidth),"number"==typeof e.fillOpacity&&(a=e.fillOpacity),"number"==typeof e.opacity&&null==a&&(a=e.opacity)}let b=AS(e.id,M,k,$,n,O);R.push({id:e.id,pathD:o,fill:p,stroke:g,strokeWidth:y,...null!=a&&{fillOpacity:a},...s&&{hatchFill:s},...b.length>0&&{gradientStubs:b},rawDatum:x,labelX:$("vertical"===d&&e.xExtent?e.xExtent[0]:c.t)-4,labelY:f,labelText:e.label??e.id})});let D=/* @__PURE__ */new Map;i.forEach((e,t)=>D.set(e.id,t)),M.forEach(e=>{let t=E.get(e.id);if(!t)return;let i=D.get(e.source)??0,r=u(e.source,i),{pathD:n,bezier:o}=CA(t),a=e.__raw??e,s="function"==typeof c?Number(c(a)):c,l=Number.isFinite(s)?Math.max(0,Math.min(1,s)):.35;C.push({id:e.id,pathD:n,fill:r,opacity:l,rawDatum:a,bezier:o})});let B=YA(R,k.slotByNode,w).map(e=>KA(e,d)),j="vertical"===d?qA(B,o,a):B,W=/* @__PURE__ */new Map;if(null!=f)for(let e of i){let t=e.__raw??e,i="function"==typeof f?f(t):Number(t[f]);Number.isFinite(i)&&W.set(e.id,i)}let Y=XA(j,o,a,h,{...W.size>0&&{priorityById:W},...null!=p&&{maxLabels:p}});return{layout:k,layoutConfig:{bands:Y,ribbons:C.map(e=>ZA(e,d)),showLabels:!1!==h,selectionDatum:g},issues:[],warnings:A,xScale:$}}function eM(e,t,i,r="horizontal"){return"vertical"===r?{top:e?38:t?28:16,right:24,bottom:24,left:i?72:24}:{top:e?30:t?24:8,right:80,bottom:i?28:8,left:80}}import{scaleLinear as tM,scaleUtc as iM}from"d3-scale";import{Fragment as rM,jsx as nM,jsxs as oM}from"react/jsx-runtime";var aM="var(--semiotic-grid, #94a3b8)",sM="var(--semiotic-text-secondary, #475569)",lM="var(--semiotic-text-secondary, #94a3b8)";function cM(e){let t=e.layout,i=e.nodes,r=e.orientation,n=e.plotW,o=e.plotH,a=e.timelineExtent,s=e.showQualityReadout??!1,l=e.showLaneRails??!1,c=(e.warnings??[]).slice(0,3),u=e.timeFormat,d=e.colorOf,h=e.toTime,f=e.xScale,p=RA(e.domain),{centerlines:g,laneLifetime:m,nodeData:y,valueScale:x,compressedPadding:b,crossingsBefore:v,crossingsAfter:w,layoutQualityBefore:k,layoutQuality:S}=t,A=null,M=null,$=1/0,_=-1/0;for(let e of i){let t=m[e.id];if(!t||null===t.start||null===t.end)continue;let i=f(t.start),r=f(t.end);$=Math.min($,t.start),_=Math.max(_,t.end),(null===A||i<A)&&(A=i),(null===M||r>M)&&(M=r)}let I=e=>Math.max(0,Math.min(a,e)),P=I(A??0),L=Math.max(P,I(M??a)),R=[Math.max(h(e.domain[0]),$),Math.min(h(e.domain[1]),_)],C=Math.max(2,Math.min(8,Math.floor(a/90))),T=iM().domain(R),N=e.axisTicks??(Number.isFinite(R[0])&&Number.isFinite(R[1])?(p?T.ticks(C):tM().domain(R).ticks(C)).map(e=>({date:e})):[]),F=e=>{if(null!=e.label)return e.label;let t=h(e.date),i=p?new Date(t):t;return u?u(i):p?T.tickFormat()(i):String(t)},E=N.map((e,t)=>({tick:e,index:t,coordinate:f(h(e.date))})).filter(({coordinate:e})=>e>=P-.5&&e<=L+.5),O=null!==(w??null)&&null!=k&&null!=S,z=s&&(O||c.length>0)?/* @__PURE__ */oM("g",{fill:lM,fontSize:10,textAnchor:"end",children:[O&&/* @__PURE__ */oM(rM,{children:[
282
- /* @__PURE__ */oM("text",{x:n,y:-14,children:["crossings: ",v," → ",w," ","pixel length: ",Math.round(k.pixelLength)," → ",Math.round(S.pixelLength)]}),
283
- /* @__PURE__ */oM("text",{x:n,y:-3,children:["transit: ",k.transitOcclusion.toFixed(1)," → ",S.transitOcclusion.toFixed(1)," ","lane use: ",Math.round(100*S.verticalUtilization),"%"]})]}),c.map((e,t)=>/* @__PURE__ */oM("text",{x:n,y:O?10+11*t:11*t-3,fill:"var(--semiotic-warning, #b45309)",children:["warn: ",e]},`warn-${t}`))]}):null,D=b?/* @__PURE__ */nM("text",{x:n,y:"vertical"===r?-3:2,fontSize:10,fill:lM,textAnchor:"end",children:"dense layout: lane gaps compressed"}):null,B=(e,t)=>d?d(e,t):aM;/* @__PURE__ */
284
- return oM("g","vertical"===r?{children:[z,D,E.map(({index:e,coordinate:t})=>/* @__PURE__ */nM("line",{x1:0,y1:t,x2:n,y2:t,stroke:aM,strokeOpacity:.15,strokeDasharray:"2 4"},`grid-${e}`)),l&&i.map((e,t)=>{let i=m[e.id];if(!i||null===i.start)return null;let r=g[e.id],n=y[e.id],o=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},a=r+(o.botPeak-o.topPeak)*x/2,s=f(i.start),l=f(i.end),c=B(e.id,t);/* @__PURE__ */
285
- return oM("g",{children:[
286
- /* @__PURE__ */nM("line",{x1:a,y1:s,x2:a,y2:l,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),
287
- /* @__PURE__ */nM("line",{x1:a-4,y1:s,x2:a+4,y2:s,stroke:c,strokeOpacity:.5}),
288
- /* @__PURE__ */nM("line",{x1:a-4,y1:l,x2:a+4,y2:l,stroke:c,strokeOpacity:.5})]},`lane-${e.id}`)}),
289
- /* @__PURE__ */nM("line",{x1:-4,y1:P,x2:-4,y2:L,stroke:aM}),E.map(({tick:e,index:t,coordinate:i})=>{let r=F(e);/* @__PURE__ */
290
- return oM("g",{transform:`translate(-4,${i})`,children:[
291
- /* @__PURE__ */nM("line",{x2:-6,stroke:aM}),
292
- /* @__PURE__ */nM("text",{x:-10,y:4,textAnchor:"end",fontSize:11,fill:sM,children:r})]},t)})]}:{children:[z,D,E.map(({index:e,coordinate:t})=>/* @__PURE__ */nM("line",{x1:t,y1:0,x2:t,y2:o,stroke:aM,strokeOpacity:.15,strokeDasharray:"2 4"},`grid-${e}`)),l&&i.map((e,t)=>{let i=m[e.id];if(!i||null===i.start)return null;let r=g[e.id],n=y[e.id],o=n?{topPeak:n.topPeak,botPeak:n.botPeak}:{topPeak:0,botPeak:0},a=r+(o.botPeak-o.topPeak)*x/2,s=f(i.start),l=f(i.end),c=B(e.id,t);/* @__PURE__ */
293
- return oM("g",{children:[
294
- /* @__PURE__ */nM("line",{x1:s,y1:a,x2:l,y2:a,stroke:c,strokeOpacity:.35,strokeWidth:1,strokeDasharray:"3 3"}),
295
- /* @__PURE__ */nM("line",{x1:s,y1:a-4,x2:s,y2:a+4,stroke:c,strokeOpacity:.5}),
296
- /* @__PURE__ */nM("line",{x1:l,y1:a-4,x2:l,y2:a+4,stroke:c,strokeOpacity:.5})]},`lane-${e.id}`)}),
297
- /* @__PURE__ */nM("line",{x1:P,y1:o+4,x2:L,y2:o+4,stroke:aM}),E.map(({tick:e,index:t,coordinate:i})=>{let r=F(e);/* @__PURE__ */
298
- return oM("g",{transform:`translate(${i},${o+4})`,children:[
299
- /* @__PURE__ */nM("line",{y2:6,stroke:aM}),
300
- /* @__PURE__ */nM("text",{y:20,textAnchor:"middle",fontSize:11,fill:sM,children:r})]},t)})]})}function uM(e,t){return"scene"===t?e:e.data}function dM(e,t,i){return!t?.isActive||t.predicate(uM(e,i))}var hM=e=>{let{bands:t=[],ribbons:i=[],showLabels:r=!0,selectionDatum:n="raw"}=e.config,o=e.selection??null,a=[];for(let e of i){let t={__kind:"ribbon",data:e.rawDatum,id:e.id},i=!dM(t,o,n);a.push({type:"bezier",pathD:e.pathD,...e.bezier&&{bezierCache:e.bezier},style:{fill:e.fill,opacity:i?Math.min(e.opacity,.22):e.opacity,stroke:"none"},datum:t})}for(let e of t){if(!e.gradientStubs)continue;let t=!dM({__kind:"band",data:e.rawDatum,id:e.id},o,n);for(let i=0;i<e.gradientStubs.length;i++){let r=e.gradientStubs[i];a.push({type:"bezier",pathD:r.pathD,interactive:!1,style:{fill:e.fill,fillOpacity:t?.22:e.fillOpacity??.86,stroke:"none"},_gradient:{x0:r.x0,x1:r.x1,...null!=r.y0&&{y0:r.y0},...null!=r.y1&&{y1:r.y1},from:r.from,to:r.to},datum:{__kind:"band",data:e.rawDatum,id:`${e.id}__stub${i}`}})}}for(let e of t){let t=!!(e.gradientStubs&&e.gradientStubs.length>0),i={__kind:"band",data:e.rawDatum,id:e.id},r=!dM(i,o,n),s=e.fillOpacity??.86,l=e.hatchFill??e.fill;a.push({type:"bezier",pathD:e.pathD,style:{...t?{fill:"none"}:{fill:l,fillOpacity:r?.22:s},stroke:e.stroke??("string"==typeof e.fill?e.fill:"#666"),strokeWidth:e.strokeWidth??.5,...r&&t?{opacity:.22}:{}},datum:i})}let s=r?t.flatMap(e=>{let t=e.labelDeferred&&e.labelFullText?.trim(),i=e.labelText.trim().length>0,r=t&&o?.isActive&&dM({__kind:"band",data:e.rawDatum,id:e.id},o,n),a=i?e.labelText:r?e.labelFullText:"";return a.trim()?[{x:e.labelX,y:e.labelY,text:a,anchor:e.labelAnchor??"end",baseline:e.labelBaseline??"middle",fontSize:11,fontWeight:600}]:[]}):[];return{sceneNodes:t.map(e=>({type:"circle",id:e.id,cx:-1e4,cy:-1e4,r:0,style:{fill:e.fill},datum:{__kind:"band",data:e.rawDatum,id:e.id}})),sceneEdges:a,labels:s}};function fM(e,t){if(!e)return[];let i=[],r=e=>{i.push(e);let n="function"==typeof t?t(e):e[t];n&&Array.isArray(n)&&n.forEach(r)};return r(e),i}function pM(e,t,i,r){if(e&&e.length>0)return e;let n=/* @__PURE__ */new Set;return t.forEach(e=>{let t="function"==typeof i?i(e):e[i],o="function"==typeof r?r(e):e[r];n.add(t),n.add(o)}),Array.from(n).map(e=>({id:e}))}function gM({edgeColorBy:e,colorBy:t,colorScale:i,nodeStyleFn:r,edgeOpacity:n,baseStyle:o={}}){return a=>{let s={fillOpacity:n,...o};if("function"==typeof e)s.fill=e(a);else if("source"===e){let e="object"==typeof a.source?a.source:null;t&&e?s.fill=Li(e.data||e,t,i):e&&(s.fill=r(e,e.index).fill)}else if("target"===e){let e="object"==typeof a.target?a.target:null;t&&e?s.fill=Li(e.data||e,t,i):e&&(s.fill=r(e,e.index).fill)}else"gradient"===e&&(s.fill="#999",s.fillOpacity=.7*n);return s}}var mM=(e,t,i,r,n)=>({data:e,nodeIDAccessor:n.nodeIdAccessor??n.nodeIDAccessor??"name",childrenAccessor:n.childrenAccessor,hierarchySum:n.valueAccessor,colorBy:t,colorByDepth:n.colorByDepth,showLabels:n.showLabels,colorScheme:i,...r,showLegend:(r.showLegend??!(!t||n.colorByDepth))&&!(!t||n.colorByDepth)}),yM=(e,t,i,r,n)=>{let o=M(r.theme).colors.categorical,a=/* @__PURE__ */new Map,s=fM(e??null,n.childrenAccessor??"children"),l="function"==typeof t?t:null,c=l?"__hierarchyColor":"string"==typeof t?t:void 0,u=l?s.map(e=>({__hierarchyColor:l(e)})):s,d=t&&c?Ci(u,c,i??r.colorScheme??o):void 0;return e=>{if(n.colorByDepth)return _i[Number(e?.depth||0)%_i.length];let r=e?.data||e;return t?Li(l?{__hierarchyColor:l(r)}:r,c,d??void 0):Fi(void 0,o,i,void 0,a)}};function xM(e,t,i,r){let n=Xi(e,r.styleRules,Bi(t,r.valueAccessor),e=>e?.data||e),o=i.nodeStyle||r.nodeStyle;return Oi(o?"function"==typeof o?e=>({...n(e),...o(e)??{}}):e=>({...n(e),...o}):n,ur(r))}function bM(e){if(void 0!==e.edgeStyle)return e.edgeStyle;let{edgeWidth:t,edgeColor:i,edgeOpacity:r}=e,n=e.strokeWidth??1;return void 0!==t||void 0!==i||void 0!==r||void 0!==e.stroke||void 0!==e.strokeWidth||void 0!==e.opacity?o=>{let a=o?.data||o,s=n;if("number"==typeof t)s=t;else if("function"==typeof t)s=t(a);else if("string"==typeof t){let e=a?.[t],i="number"==typeof e?e:Number(e);s=Number.isFinite(i)&&i>0?i:n}return{stroke:i??e.stroke??"#999",strokeWidth:s,opacity:r??e.opacity??.6}}:void 0}var vM={MotifBraidChart:Dk,DependencyForestChart:Bk,ForceDirectedGraph:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,n)=>{let o=bM(n),a=M(r.theme).colors.categorical,s=/* @__PURE__ */new Map,l=Array.isArray(n.nodes)?n.nodes:[],c="string"==typeof t?t:"__ssrForceColorBy",u=t?Ci("function"==typeof t?l.map(e=>({...e,__ssrForceColorBy:t(e)})):l,c,i??r.colorScheme??a):void 0,d=n.nodeStyle??(e=>({fill:t?Li(e?.data||e,t,u):Fi(void 0,a,i,void 0,s),..."number"==typeof n.nodeSize&&{r:n.nodeSize}})),h=Gi(n.styleRules,t,"number"==typeof n.nodeSize?void 0:n.nodeSize),f=Oi(h?(e,t)=>({...d(e),...h(e,t)}):d,{stroke:n.nodeStroke??n.stroke,strokeWidth:n.nodeStrokeWidth??n.strokeWidth,opacity:n.opacity});return{chartType:"force",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,colorBy:t,colorScheme:i,iterations:n.iterations,forceStrength:n.forceStrength,nodeLabel:n.nodeLabel,nodeSize:n.nodeSize??8,nodeSizeRange:n.nodeSizeRange,nodeStyle:f,edgeStyle:o,...r,showLabels:r.showLabels??n.showLabels??!1,showLegend:(r.showLegend??!!t)&&!!t}}},SankeyDiagram:{frameType:"network",layout:{primarySize:{width:800,height:600}},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.nodes)?n.nodes:pM([],Array.isArray(n.edges)?n.edges:[],n.sourceAccessor||"source",n.targetAccessor||"target"),a=M(r.theme).colors.categorical,s=/* @__PURE__ */new Map,l="string"==typeof t?t:"__ssrSankeyColorBy",c="function"==typeof t?o.map(e=>({...e,__ssrSankeyColorBy:t(e)})):o,u=t?Ci(c,l,i??r.colorScheme??a):void 0,d=e=>({fill:t?Li(e?.data||e,t,u):Fi(void 0,a,i,void 0,s),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),h=Gi(n.styleRules,t,n.valueAccessor),f=h?(e,t)=>({...d(e),...h(e,t)}):d,p=gM({edgeColorBy:n.edgeColorBy??"source",colorBy:t,colorScale:u,nodeStyleFn:f,edgeOpacity:n.edgeOpacity??.5,baseStyle:{stroke:"none",strokeWidth:0}});return{chartType:"sankey",nodes:n.nodes,edges:n.edges,nodeIDAccessor:n.nodeIdAccessor||n.nodeIDAccessor,sourceAccessor:n.sourceAccessor,targetAccessor:n.targetAccessor,valueAccessor:n.valueAccessor,orientation:n.orientation,nodeAlign:n.nodeAlign,nodeWidth:n.nodeWidth,nodePaddingRatio:n.nodePaddingRatio,showLabels:n.showLabels,nodeLabel:n.nodeLabel,colorBy:t,edgeColorBy:n.edgeColorBy,edgeOpacity:n.edgeOpacity,nodeStyle:Oi(n.nodeStyle||f,ur(n)),edgeStyle:Oi(n.edgeStyle||p,ur(n)),colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t}}},ProcessSankey:{frameType:"network",layout:{margin:e=>eM(!!e.title,!!e.showQualityReadout,!Array.isArray(e.axisTicks)||e.axisTicks.length>0,"vertical"===e.orientation?"vertical":"horizontal")},buildProps:(e,t,i,r,n)=>{let o=n.sourceAccessor||"source",a=n.targetAccessor||"target",s=n.valueAccessor||"value",l=n.nodeIdAccessor||"id",c=n.startTimeAccessor||"startTime",u=n.endTimeAccessor||"endTime",d=n.systemInTimeAccessor,h=n.systemOutTimeAccessor,f=n.xExtentAccessor||"xExtent",p=n.groupBy,g=n.edgeIdAccessor||"id",m=(e,t)=>"function"==typeof e?e(t):t[e],y=Array.isArray(n.edges)?n.edges:[],x=Array.isArray(n.nodes)?n.nodes:[],b=x.length>0?x:pM([],y,o,a),v=[LA(n.domain?.[0]),LA(n.domain?.[1])],w=b.map(e=>{let t=String(m(l,e)),i=m(f,e),r=n.nodeLabel?m(n.nodeLabel,e):t,o={id:t,label:null==r?t:String(r),__raw:e},a=p?m(p,e):null;if(null!=a&&""!==String(a)&&(o.group=String(a)),Array.isArray(i)&&2===i.length){let e=LA(i[0]),t=LA(i[1]);Number.isFinite(e)&&Number.isFinite(t)&&(o.xExtent=[e,t])}return o}),k=y.map((e,t)=>{let i=m(g,e),r={id:null!=i?String(i):`${m(o,e)}-${m(a,e)}-${t}`,source:String(m(o,e)),target:String(m(a,e)),value:Number(m(s,e)),startTime:LA(m(c,e)),endTime:LA(m(u,e)),__raw:e};if(d){let t=LA(m(d,e));Number.isFinite(t)&&(r.systemInTime=t)}if(h){let t=LA(m(h,e));Number.isFinite(t)&&(r.systemOutTime=t)}return r}),[S,A]=r.size??[600,400],$=r.margin,_="vertical"===n.orientation?"vertical":"horizontal",I=!Array.isArray(n.axisTicks)||n.axisTicks.length>0,L={...eM(!!r.title,!!n.showQualityReadout,I,_),...$},R=(r.showLegend??!!t)&&!!t,C=r.legendPosition??"right";if(R){let e="left"===C||"top"===C||"bottom"===C?C:"right",t={...L};"right"===e?L.right=Math.max(L.right,140):"left"===e?L.left=Math.max(L.left,140):"top"===e?L.top=Math.max(L.top,50):L.bottom=Math.max(L.bottom,80),F(L,t,[S,A],e)}let T=L,N=Math.max(1,S-T.left-T.right),E=Math.max(1,A-T.top-T.bottom),O=Mi(i,M(r.theme).colors.categorical,oi),z="function"==typeof t?t:null,D=z?b.map(e=>({_cat:z(e)})):b,B=z?"_cat":"string"==typeof t?t:void 0,j=i??[...O],W=B?Ci(D,B,j):null,Y=/* @__PURE__ */new Map;for(let e of w)Y.set(e.id,e.__raw);let q=(e,i)=>{if(t&&Y.has(e)){let i=Y.get(e);return z?Li({_cat:z(i)},"_cat",W??void 0):Li(i,"string"==typeof t?t:"id",W??void 0)}return O[i%O.length]},X=P(R&&t?(()=>{let e=/* @__PURE__ */new Map;b.forEach((i,r)=>{let n=m(t,i),o=null==n?"":String(n);!o||e.has(o)||e.set(o,{label:o,color:q(String(m(l,i)),r)})});let i=Array.from(e.values());return i.length>0?{legendGroups:[{type:"fill",label:"",items:i,styleFn:e=>{let t=e.color||"#333";return{fill:t,stroke:t}}}]}:void 0})():void 0,r.legend),G=!1!==n.showLabels&&("auto"!==n.showLabels||"auto"),{layout:V,layoutConfig:H,issues:U,xScale:K}=JA({nodes:w,edges:k,domain:v,plotW:N,plotH:E,orientation:_,ribbonLane:n.ribbonLane||"both",ribbonMinRun:"auto"===n.ribbonMinRun||"number"==typeof n.ribbonMinRun?n.ribbonMinRun:0,edgeOpacity:"number"==typeof n.edgeOpacity?n.edgeOpacity:.35,colorOf:q,showLabels:G,styleRules:n.styleRules,colorBy:t,valueAccessor:s,layoutOpts:{pairing:n.pairing||"temporal",packing:n.packing||"reuse",laneOrder:n.laneOrder||"crossing-min",lifetimeMode:n.lifetimeMode||"half",maxValueScale:"number"==typeof n.maxValueScale?n.maxValueScale:void 0,lanePlacement:n.lanePlacement||"stack",nodeSizing:n.nodeSizing||"temporal",groupPadding:"number"==typeof n.groupPadding?n.groupPadding:0}});if(U.length>0){let e=U.map(Kk).join("; ");throw new Error(`ProcessSankey: data invalid — ${e}`)}let Z=V?cM({layout:V,nodes:w,orientation:_,plotW:N,plotH:E,timelineExtent:"vertical"===_?E:N,domain:n.domain,axisTicks:Array.isArray(n.axisTicks)?n.axisTicks.map(e=>({date:e.date,label:e.label})):void 0,showQualityReadout:!!n.showQualityReadout,showLaneRails:!!n.showLaneRails,timeFormat:"function"==typeof n.timeFormat?e=>n.timeFormat(e):void 0,colorOf:q,toTime:e=>LA(e),xScale:e=>Number(K(e))}):void 0;return{chartType:"force",nodes:b,edges:y,customNetworkLayout:hM,layoutConfig:H,sourceAccessor:o,targetAccessor:a,valueAccessor:s,nodeIDAccessor:l,colorBy:t,colorScheme:i,...Z&&{backgroundGraphics:Z},...r,showLegend:R,...X&&{legend:X,legendPosition:C},__legendIncludesAutomatic:!0,margin:T}}},ChordDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,n)=>{let o=Array.isArray(n.styleRules)&&n.styleRules.length>0;if(!(t||o||r.nodeStyle||n.nodeStyle||Ei(ur(n))))return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,edgeOpacity:n.edgeOpacity,showLabels:n.showLabels,colorBy:t,edgeColorBy:n.edgeColorBy,colorScheme:i,...r,showLegend:(r.showLegend??!!t)&&!!t};let a=Array.isArray(n.edges)?n.edges:[],s=Array.isArray(n.nodes)&&n.nodes.length>0?n.nodes:pM([],a,n.sourceAccessor||"source",n.targetAccessor||"target"),l=M(r.theme).colors.categorical,c=Mi(i,l),u="string"==typeof t?t:"__ssrChordColorBy",d="function"==typeof t?s.map(e=>({...e,__ssrChordColorBy:t(e)})):s,h=t?Ci(d,u,i??r.colorScheme??l):void 0,f=/* @__PURE__ */new Map,p=n.nodeIdAccessor||n.nodeIDAccessor||"id",g=(e,i)=>{let r,o=e?.data||e;if(t)r=Li(o,t,h);else{let t=String(e.id??o?.[p]??"");f.has(t)||f.set(t,f.size);let n=e.index??i??f.get(t);r=c[n%c.length]}return{fill:r,stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}},m=Gi(n.styleRules,t,n.valueAccessor),y=m?(e,t)=>({...g(e,t),...m(e,t)}):g;return{chartType:"chord",nodes:n.nodes,edges:n.edges,valueAccessor:n.valueAccessor,padAngle:n.padAngle,groupWidth:n.groupWidth,edgeOpacity:n.edgeOpacity,showLabels:n.showLabels,colorBy:t,edgeColorBy:n.edgeColorBy,colorScheme:i,nodeStyle:Oi(n.nodeStyle||y,ur(n)),...r,showLegend:(r.showLegend??!!t)&&!!t}}},TreeDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,n)=>{let o=yM(e,t,i,r,n),a=!1!==n.showLabels;return{chartType:n.layout??"tree",orientation:n.orientation,nodeLabel:a?n.nodeLabel||n.nodeIdAccessor:void 0,...mM(e,t,i,r,n),nodeStyle:xM(e=>({fill:o(e),stroke:n.stroke??"black",strokeWidth:n.strokeWidth??1,...void 0!==n.opacity&&{opacity:n.opacity}}),t,r,n)}}},Treemap:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,n)=>{let o=yM(e,t,i,r,n),a=n.showLabels??r.showLabels,s=n.labelMode,l=void 0!==n.paddingTop?n.paddingTop:r.paddingTop,c=void 0!==l?l:!a||"parent"!==s&&"all"!==s?void 0:18;return{chartType:"treemap",labelMode:s,nodeLabel:a?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...null!=c&&{paddingTop:c},...mM(e,t,i,r,n),nodeStyle:xM(e=>({fill:o(e),stroke:"var(--semiotic-cell-border, var(--semiotic-border, #fff))",strokeWidth:1,strokeOpacity:.8}),t,r,n)}}},CirclePack:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,n)=>{let o=yM(e,t,i,r,n);return{chartType:"circlepack",nodeLabel:n.showLabels??r.showLabels?n.nodeLabel||n.nodeIdAccessor:void 0,...null!=n.padding&&{padding:n.padding},...mM(e,t,i,r,n),nodeStyle:xM(e=>({fill:o(e),fillOpacity:n.circleOpacity??.7,stroke:"currentColor",strokeWidth:1,strokeOpacity:.3}),t,r,n)}}},OrbitDiagram:{frameType:"network",layout:{primarySize:{width:600,height:600}},buildProps:(e,t,i,r,n)=>{let o=e??n.data,a=n.childrenAccessor||"children",s=n.nodeIdAccessor||n.nodeIDAccessor||"name",l=M(r.theme).colors.categorical,c=i??r.colorScheme??l,u=Mi(c,l),d=fM(o,a),h="__ssrOrbitColorBy",f="function"==typeof t?t:null,p=t?Ci(f?d.map(e=>({[h]:f(e)})):d,f?h:t,c):void 0,g=Xi(e=>{let i=e.data||e,r=Number(e.depth??0);return{fill:n.colorByDepth?0===r?u[0]:_i[r%_i.length]:t?f?Li({[h]:f(i)},h,p):Li(i,t,p):u[0],stroke:"#fff",strokeWidth:1,opacity:0===r?1:.85}},n.styleRules,Bi(t,"value"),e=>e?.data||e);return{chartType:"orbit",data:o,childrenAccessor:a,nodeIDAccessor:s,colorBy:t,colorScheme:c,colorByDepth:n.colorByDepth??!1,nodeSize:n.nodeRadius??6,nodeLabel:n.showLabels?s:void 0,showLabels:n.showLabels??!1,orbitMode:n.orbitMode??"flat",orbitSize:n.orbitSize??2.95,orbitSpeed:n.speed??.25,orbitRevolution:n.revolution,orbitRevolutionStyle:n.revolutionStyle,orbitEccentricity:n.eccentricity??1,orbitShowRings:n.showRings??!0,orbitAnimated:!1,nodeStyle:Oi(g,ur(n)),edgeStyle:()=>({stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1}),...r,showLegend:(r.showLegend??!(!t||n.colorByDepth))&&!(!t||n.colorByDepth)}}}},wM={fill:"#f0f0f0",stroke:"#ccc",strokeWidth:.5};function kM(e,t,i){let[r,n]=i;if(!t)return r;let[o,a]=t,s=a>o?a-o:0,l=Number(e),c=Number.isFinite(l)?l:o,u=s>0?(c-o)/s:0;return r+Math.max(0,Math.min(1,u))*(n-r)}function SM(e){let{valueAccessor:t,valueDomain:i,edgeWidthRange:r,resolveStroke:n,edgeOpacity:o,edgeLinecap:a,styleRules:s}=e,l=zi(t);return Xi(e=>({stroke:n(e),strokeWidth:kM(e[t],i,r),strokeLinecap:a,opacity:o,fillOpacity:0}),s,e=>({value:l(e)}))}import{scaleSequential as AM}from"d3-scale";function MM(e,t,i,r){let n,o,a=Array.isArray(e)?e:[];if(t){let e="string"==typeof t?t:"__geoColorBy",r="string"==typeof t?a:a.map(e=>({...e,__geoColorBy:t(e)}));n=Ci(r,e,i)}if(r.sizeBy){let e="function"==typeof r.sizeBy?r.sizeBy:e=>e?.[r.sizeBy],t=a.map(e).filter(e=>null!=e&&isFinite(e));t.length>0&&(o=yr(t))}return e=>({fill:t&&n?Li(e,t,n):Ai,fillOpacity:r.fillOpacity,stroke:"#fff",strokeWidth:r.strokeWidth,r:r.sizeBy?Ni(e,r.sizeBy,r.sizeRange,o):r.pointRadius??6})}function $M(e){return e&&"object"==typeof e&&e.properties?{...e.properties,...e}:e}function _M(e,t,i){if(!Array.isArray(e))return;let r=e=>"function"==typeof t?t(e):null!=t?e?.properties?.[t]??e?.[t]:void 0,n=1/0,o=-1/0;for(let t of e){let e=r(t);null==e||!isFinite(e)||(e<n&&(n=e),e>o&&(o=e))}let a=[Number.isFinite(n)?n:0,Number.isFinite(o)?o:1],s=AM(pi(i)).domain(a);return{domain:a,colorScale:e=>s(e),valueAccessor:r}}function IM(e,t){if(e)return i=>{let r=e.valueAccessor(i);return{fill:null!=r&&isFinite(r)?e.colorScale(r):"#ccc",stroke:"#999",strokeWidth:.5,fillOpacity:t}}}var PM={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o="string"==typeof i?i:"blues",a=_M(n.areas,n.valueAccessor,o),s=n.areaStyle??IM(a,n.areaOpacity??1),l=e=>"function"==typeof n.valueAccessor?n.valueAccessor(e):null!=n.valueAccessor?e?.properties?.[n.valueAccessor]??e?.[n.valueAccessor]:void 0,c=n.styleRules?Xi(s,n.styleRules,e=>({value:l(e)}),$M):s,u=!1!==r.showLegend&&a?{gradient:{colorFn:a.colorScale,domain:a.domain,label:"string"==typeof n.valueAccessor?n.valueAccessor:"value"}}:void 0;return{areas:n.areas,projection:n.projection||"equalEarth",areaStyle:c,valueAccessor:n.valueAccessor,colorScheme:o,graticule:n.graticule,fitPadding:n.fitPadding,...r,...void 0===r.legend&&u?{legend:u}:{}}}},LM={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=e||n.points,a=n.pointStyle??MM(o,t,i,{sizeBy:n.sizeBy,sizeRange:n.sizeRange||[3,30],fillOpacity:.7,strokeWidth:.5}),s=n.styleRules?Xi(a,n.styleRules,Bi(t,n.sizeBy)):a;return{points:o,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",areas:n.areas,areaStyle:n.areaStyle||wM,pointStyle:s,sizeBy:n.sizeBy,colorBy:t,colorScheme:i,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,...r}}},RM={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=e||n.points,a=r.__resolvedMode??n.mode,s="sparkline"===a,l=n.pointStyle??MM(o,t,i,{pointRadius:"number"==typeof n.pointRadius?n.pointRadius:s?1.5:5,fillOpacity:.85,strokeWidth:1}),c=n.nodeIdAccessor||"id",u=n.cartogramLayout||(s?"strip":"radial"),d="strip"===u,h=n.styleRules?Xi(l,n.styleRules,Bi(t)):l;return{points:o,lines:n.lines,xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",pointStyle:e=>{let t="function"==typeof h?h(e):h,i="function"==typeof c?c(e):e[c],r=null!=i&&String(i)===String(n.center),o="number"==typeof t.r?t.r:5;return{...t,fillOpacity:r?1:t.fillOpacity??.8,stroke:r?"var(--semiotic-text, #222)":t.stroke??"#fff",strokeWidth:r?1.25:t.strokeWidth??1,r:r?1.35*o:o}},colorBy:t,colorScheme:i,projection:n.projection||"mercator",graticule:n.graticule,fitPadding:n.fitPadding,projectionTransform:{center:n.center,centerAccessor:c,costAccessor:n.costAccessor,strength:n.strength??1,lineMode:n.lineMode||"straight",layout:u},...r,cartogramChrome:{showRings:n.showRings??!0,showNorth:n.showNorth??(!d&&!s),showRingLabels:n.showRingLabels??(!d&&"context"!==a&&!s),costLabel:n.costLabel}}}},CM={frameType:"geo",layout:{margin:{top:10,right:10,bottom:10,left:10}},buildProps:(e,t,i,r,n)=>{let o=(Array.isArray(e)?e:null)||n.flows||[],a=n.nodes||[],s=n.nodeIdAccessor||"id",l=n.valueAccessor||"value",c=n.xAccessor||"lon",u=n.yAccessor||"lat",d="function"==typeof c?c:e=>e[c],h="function"==typeof u?u:e=>e[u],f=a.map(e=>({...e,x:d(e),y:h(e)})),p=/* @__PURE__ */new Map;for(let e of f)p.set(String(e[s]),e);let g=n.edgeColorBy??t,m="function"==typeof g,y=o.map(e=>{if(!e||null==e.source||null==e.target)return null;let t=p.get(String(e.source)),i=p.get(String(e.target));return t&&i?{...e,coordinates:[{x:t.x,y:t.y},{x:i.x,y:i.y}]}:null}).filter(Boolean),x="__flowMapEdgeColor",b=g?m?Ci(y.map(e=>({[x]:g(e)})),x,i||"category10"):Ci(y,g,i||"category10"):null,v=y.map(e=>Number(e[l]??0)).filter(e=>Number.isFinite(e)),w=v.length>0?yr(v):void 0,[k,S]=n.edgeWidthRange??[1,8],A=n.edgeOpacity??.6,M=n.edgeLinecap??"round";return{lines:y,points:f,xAccessor:"x",yAccessor:"y",lineDataAccessor:"coordinates",lineType:n.lineType||"geo",flowStyle:n.flowStyle||"basic",areas:n.areas,areaStyle:n.areaStyle||wM,projection:n.projection||"equalEarth",graticule:n.graticule,fitPadding:n.fitPadding,colorScheme:i,lineStyle:SM({valueAccessor:l,valueDomain:w,edgeWidthRange:[k,S],resolveStroke:e=>g&&b?Li(e,g,b):"#007bff",edgeOpacity:A,edgeLinecap:M,styleRules:n.styleRules}),pointStyle:()=>({fill:"#333",r:4,fillOpacity:.8}),...r}}},TM={FlowCircuitChart:jk,GaltonBoardChart:bw,EventDropChart:vw,UnitPileChart:ww,CollisionSwarmChart:kw,PacketFlowChart:$w,ProcessFlowChart:Sw,GauntletChart:Aw,CrucibleChart:Mw,ChainReactionChart:Xf},NM=/* @__PURE__ */Object.assign({Sparkline:{frameType:"xy",layout:{mode:"sparkline"},buildProps:(e,t,i,r,n)=>({chartType:"line",data:e,xAccessor:n.xAccessor||"x",yAccessor:n.yAccessor||"y",groupAccessor:n.lineBy||t,colorAccessor:t,...r,showAxes:!1,margin:r.margin,showLegend:!1,showGrid:!1,title:void 0})},XYCustomChart:wg,OrdinalCustomChart:kg,ParallelCoordinatesRecipe:Ag,CalendarHeatmapRecipe:Mg,NetworkCustomChart:Sg,ChoroplethMap:PM,ProportionalSymbolMap:LM,FlowMap:CM,DistanceCartogram:RM,GeoCustomChart:{frameType:"geo",buildProps:(e,t,i,r,n)=>({points:n.points||e||[],areas:n.areas||[],lines:n.lines||[],projection:n.projection||"equirectangular",xAccessor:n.xAccessor||"lon",yAccessor:n.yAccessor||"lat",lineDataAccessor:n.lineDataAccessor,colorBy:t,colorScheme:i,customLayout:n.layout||n.customLayout,layoutConfig:n.layoutConfig,...r})},PhysicsCustomChart:_w},
301
- /* @__PURE__ */Object.assign({},Gf,Mp,og),
302
- /* @__PURE__ */Object.assign({},vM,TM));import*as FM from"react";import{jsx as EM}from"react/jsx-runtime";var OM=/* @__PURE__ */new Set(["svg","g","text","tspan","path","circle","ellipse","rect","line","polyline","polygon","use","image","defs","symbol"]);function zM(e){if(Array.isArray(e))return e.length>0&&e.every(zM);if(!FM.isValidElement(e))return!1;if(e.type===FM.Fragment){let t=FM.Children.toArray(e.props.children);return t.length>0&&t.every(zM)}return"string"==typeof e.type&&OM.has(e.type)}function DM(e,t,i){if(!zM(e))return null;if(!FM.isValidElement(e)||e.type===FM.Fragment)/* @__PURE__ */
303
- return EM("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:e});let r=e,n="text"===r.type?FM.cloneElement(r,{x:r.props.x??0,y:r.props.y??0,textAnchor:r.props.textAnchor??"middle",dominantBaseline:r.props.dominantBaseline??"middle"}):r;/* @__PURE__ */
304
- return EM("g",{className:"semiotic-radial-center-content",transform:`translate(${t},${i})`,pointerEvents:"none",children:n})}import*as BM from"react-dom/server";import{scaleBand as jM,scaleLinear as WM}from"d3-scale";function YM(e,t,i,r,n,o){let a=e.color??"rgba(255,255,255,0.6)",s=e.glowRadius??4,l=!1;for(let c of t){if("connector"===c.type||"violin"===c.type||"boxplot"===c.type)continue;if("wedge"===c.type){let t=c.category;if(!t)continue;let r=0;for(let a of n(t)??[]){let t=i.get(a);null!=t&&(r=Math.max(r,qo(e,t,o)))}l=Go(c,r,a)||l;continue}if(null==c.datum)continue;let t=r.get(c.datum);if(null==t)continue;let u=i.get(t);l=Go(c,null==u?0:qo(e,u,o),a,s)||l}return l}var qM=class{constructor(){this.colorSchemeMap=/* @__PURE__ */new Map,this.colorSchemeIndex=0}resetColors(){this.colorSchemeMap.clear(),this.colorSchemeIndex=0}resolvePieceStyle(e,t,i){if(t&&"function"==typeof e.pieceStyle){let r=e.pieceStyle(t,i);return r&&!r.fill&&i?{...r,fill:this.getColorFromScheme(e,i)}:r}return e.pieceStyle&&"object"==typeof e.pieceStyle?e.pieceStyle:e.barColors&&i?{fill:Ri(e.barColors,i)??"#007bff"}:{fill:i?this.getColorFromScheme(e,i):"#007bff"}}resolveSummaryStyle(e,t,i){return t&&"function"==typeof e.summaryStyle?e.summaryStyle(t,i):e.summaryStyle&&"object"==typeof e.summaryStyle?e.summaryStyle:{fill:"#007bff",fillOpacity:.6,stroke:"#007bff",strokeWidth:1}}getColorFromScheme(e,t){let i=this.colorSchemeMap.get(t);if(i)return i;let r=Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical||$i,n=r[this.colorSchemeIndex%r.length];return this.colorSchemeIndex++,this.colorSchemeMap.set(t,n),n}};function XM(e,t,i){let{scales:r,config:n,getConnector:o,getO:a}=e;if(!o||!r)return[];let s=[],{projection:l}=r,c=/* @__PURE__ */new Map;for(let e of t){if("point"!==e.type&&"rect"!==e.type)continue;let t=e.datum;if(!t)continue;let i,r,n=o(t);n&&("point"===e.type?(i=e.x,r=e.y):(i=e.x+e.w/2,r=e.y+("vertical"===l?0:e.h/2)),c.has(n)||c.set(n,[]),c.get(n).push({x:i,y:r,datum:t,category:a(t)}))}let u=new Map(r.o.domain().map((e,t)=>[e,t])),d=n.connectorStyle,h={stroke:e.config.themeSemantic?.border||e.config.themeSemantic?.secondary||"#999",strokeWidth:1,opacity:.5},f=e=>"function"==typeof d?d(e):d||h,p=(e,t,i)=>{s.push({type:"connector",x1:e.x,y1:e.y,x2:t.x,y2:t.y,style:f(e.datum),datum:e.datum,group:i})};for(let[e,t]of c)if(!(t.length<2)){t.sort((e,t)=>(u.get(e.category)??-1)-(u.get(t.category)??-1));for(let i=0;i<t.length-1;i++)p(t[i],t[i+1],e);"radial"===l&&t.length>=3&&p(t[t.length-1],t[0],e)}return s}function GM(e,t,i,r=!1){let n=/* @__PURE__ */new Map;for(let r of e){let e=t(r);if(!Number.isFinite(e))continue;let o=i?i(r):"_default",a=n.get(o);a||(a={total:0,value:0,pieces:[]},n.set(o,a)),a.total+=e,a.pieces.push(r)}let o=0;for(let e of n.values())o+=Math.abs(e.total);for(let e of n.values())e.value=r&&o>0?e.total/o:e.total;return n}function VM(e,t,i,r=!1){let n=/* @__PURE__ */new Set;return{steps:e.map(e=>{let o=GM(e.pieceData,t,i,r),a=0;for(let[e,t]of o)n.add(e),a+=t.total;return{col:e,groups:o,stepTotal:a}}),keys:[...n]}}function HM(e,t,i){let r="function"==typeof e?e(i?t.w:t.h):e;return"number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0}function UM(e){let t=e.getSymbol;return t?c(t,e.config.symbolMap):null}function KM(e,t,i,r,n,o,a){t?e.push({type:"symbol",x:r,y:n,size:Math.PI*o*o,symbolType:t(i),style:a,datum:i}):e.push({type:"point",x:r,y:n,r:o,style:a,datum:i})}function ZM(e,t){let{scales:i,columns:r,config:n,resolvePieceStyle:o,getR:a}=e,s=[],l=Math.min(t.width,t.height)/2-4,c="donut"===n.chartType?n.innerRadius||60:0,u=-Math.PI/2+(n.startAngle||0)*Math.PI/180,d=null!=n.sweepAngle?n.sweepAngle*Math.PI/180:2*Math.PI,h=null!=n.sweepAngle&&n.sweepAngle<360,f=Object.values(r),p=f.some(e=>{let t=e.pieceData[0];return t&&("number"==typeof t._pct||"number"==typeof t._pctStart||null!=t._roundedEnds)}),g=f.length,m=h&&!p&&g>1&&(n.cornerRadius??0)>0;for(let e=0;e<f.length;e++){let t=f[e],i=t.pieceData[0],r="number"==typeof i?._pctStart?i._pctStart:t.pctStart,h="number"==typeof i?._pct?i._pct:t.pct,p=u+r*d,g=u+(r+h)*d,y=o(t.pieceData[0],t.name),x=0===e,b=e===f.length-1,v={type:"wedge",cx:0,cy:0,innerRadius:c,outerRadius:l,startAngle:p,endAngle:g,...n.cornerRadius&&{cornerRadius:n.cornerRadius},style:y,datum:i?._nonInteractive?null:t.pieceData,accessibleDatum:{...1===t.pieceData.length?t.pieceData[0]:{},category:t.name,value:t.pieceData.reduce((e,t)=>e+a(t),0),percent:100*h,count:t.pieceData.length,...t.pieceData[0]?.__gaugeAccessibleDatum},category:t.name};i?._roundedEnds?v.roundedEnds=i._roundedEnds:m&&(v.roundedEnds={start:x,end:b}),i?._gradientBand&&(v._gradientBand=i._gradientBand),s.push(v)}return s}import{quantileSorted as QM}from"d3-array";function JM(e,t,i){return{...e[0],...i,category:t,data:e}}function e$(e){let t=e.length,i=e[0],r=e[t-1];return{n:t,min:i,q1:QM(e,.25)??i,median:QM(e,.5)??(i+r)/2,q3:QM(e,.75)??r,max:r,mean:e.reduce((e,t)=>e+t,0)/t}}function t$(e,t,i,r,n){let o=new Array(n).fill(0);for(let a of e)a<t||a>i||o[Math.min(Math.floor((a-t)/r),n-1)]++;return o}import{scaleLinear as i$}from"d3-scale";var r$={bar:function(e,t){let{scales:i,columns:r,config:n,getR:o,getStack:a,resolvePieceStyle:s}=e,{r:l,projection:c}=i,u=[],d="vertical"===c,h="horizontal"===c,f=n.normalize,{steps:p,keys:g}=VM(Object.values(r),o,a,f);for(let{col:e,groups:t}of p){let i=0,r=0;for(let n of g){let o=t.get(n);if(!o)continue;let c=o.value,f=s(o.pieces[0],a?n:e.name),p={...o.pieces[0],__aggregateValue:o.total,__pieceCount:o.pieces.length,category:e.name};if(d){let t=l(c>=0?i+c:r),o=c>=0?l(i)-l(i+c):l(r+c)-l(r);u.push(_a(e.x,t,e.width,Math.abs(o),f,p,n)),c>=0?i+=c:r+=c}else if(h){let t=l(c>=0?i:r+c),o=c>=0?l(i+c)-l(i):l(r)-l(r+c);u.push(_a(t,e.x,Math.abs(o),e.width,f,p,n)),c>=0?i+=c:r+=c}}}let m="vertical"===c;for(let e of u){if("rect"!==e.type)continue;let t=e.datum?.__aggregateValue??0;e.roundedEdge=m?t>=0?"top":"bottom":t>=0?"right":"left",n.gradientFill&&(e.fillGradient=n.gradientFill)}if(void 0!==n.roundedTop){let e=/* @__PURE__ */new Map;for(let t of u){if("rect"!==t.type)continue;let i=t.datum?.category||"";e.has(i)||e.set(i,[]),e.get(i).push(t)}for(let t of e.values()){if(0===t.length)continue;let e=t.filter(e=>(e.datum?.__aggregateValue??0)>=0),i=t.filter(e=>(e.datum?.__aggregateValue??0)<0);if(e.length>0){let t=m?e.reduce((e,t)=>e.y<t.y?e:t):e.reduce((e,t)=>e.x+e.w>t.x+t.w?e:t),i=HM(n.roundedTop,t,m);i>0&&(t.roundedTop=i)}if(i.length>0){let e=m?i.reduce((e,t)=>e.y+e.h>t.y+t.h?e:t):i.reduce((e,t)=>e.x<t.x?e:t),t=HM(n.roundedTop,e,m);t>0&&(e.roundedTop=t)}}}return u},clusterbar:function(e,t){let{scales:i,columns:r,config:n,getR:o,getGroup:a,resolvePieceStyle:s}=e,{r:l,projection:c}=i,u=[],d="vertical"===c,{steps:h,keys:f}=VM(Object.values(r),o,a),p=f.length||1;for(let{col:e,groups:t}of h){let i=e.width/p,r=.2*i,n=i-r;for(let a=0;a<f.length;a++){let c=t.get(f[a])?.pieces||[];for(let t of c){let c=o(t),h=s(t,f[a]);if(d){let o=e.x+a*i+r/2,s=l(0),d=l(c);u.push(_a(o,Math.min(s,d),n,Math.abs(s-d),h,t,f[a]))}else{let o=e.x+a*i+r/2,s=l(0),d=l(c);u.push(_a(Math.min(s,d),o,Math.abs(d-s),n,h,t,f[a]))}}}}for(let e of u){if("rect"!==e.type||null==e.datum)continue;let t=o(e.datum),i=HM(n.roundedTop,e,d);i>0&&(e.roundedTop=i),e.roundedEdge=d?t>=0?"top":"bottom":t>=0?"right":"left",n.gradientFill&&(e.fillGradient=n.gradientFill)}return u},point:function(e,t){let{scales:i,columns:r,getR:n,multiScales:o,resolvePieceStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d="radial"===l,h=o.length>0,f=UM(e),p=2*Math.PI,g=-Math.PI/2;for(let e of Object.values(r))for(let t of e.pieceData){let i,r,l=t.__rIndex??0,m=t.__rValue??n(t),y=h&&o[l]||s,x=a(t,e.name),b=x.r||5;if(d){let t=g+(e.pctStart+e.pct/2)*p,n=y(m);i=Math.cos(t)*n,r=Math.sin(t)*n}else u?(i=e.middle,r=y(m)):(i=y(m),r=e.middle);KM(c,f,t,i,r,b,x)}return c},swarm:function(e,t){let{scales:i,columns:r,getR:n,resolvePieceStyle:o}=e,{r:a,projection:s}=i,l=[],c="vertical"===s,u=UM(e);for(let e of Object.values(r)){let t=e.width/2;for(let i=0;i<e.pieceData.length;i++){let r=e.pieceData[i],s=n(r),d=o(r,e.name),h=d.r||4,f=(7919*i%100/100-.5)*t*.8;KM(l,u,r,c?e.middle+f:a(s),c?a(s):e.middle+f,h,d)}}return l},pie:ZM,donut:ZM,boxplot:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d=!1!==n.showOutliers;for(let t of Object.values(r)){let i=t.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(0===i.length)continue;let r=e$(i),{min:n,max:l,q1:h,median:f,q3:p}=r,g=p-h,m=h-1.5*g,y=p+1.5*g,x=i.find(e=>e>=m)??n,b=l;for(let e=i.length-1;e>=0;e--)if(i[e]<=y){b=i[e];break}r.min=x,r.max=b;let v=a(JM(t.pieceData,t.name,r),t.name),w=[];if(d)for(let e of t.pieceData){let i=o(e);if(i<m||i>y){let r=u?t.middle:s(i),n=u?s(i):t.middle;w.push({px:r,py:n,value:i,datum:e})}}if(c.push({type:"boxplot",x:u?t.middle:0,y:u?0:t.middle,projection:u?"vertical":"horizontal",columnWidth:.6*t.width,minPos:s(x),q1Pos:s(h),medianPos:s(f),q3Pos:s(p),maxPos:s(b),stats:r,style:v,datum:t.pieceData,category:t.name,outliers:w}),d)for(let t of w)c.push({type:"point",x:t.px,y:t.py,r:3,style:{fill:v.fill||e.config.themeSemantic?.secondary||"#999",opacity:.6,cursor:v.cursor},datum:t.datum})}return c},violin:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u="vertical"===l,d=n.bins||20,h=!1!==n.showIQR;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(t.length<2)continue;let i,r=t[0],n=t[t.length-1],l=(n-r)/d||1,f=t$(t,r,n,l,d),p=br(f,1),g=e.width/2*.9;if(u){i=`M ${e.middle} ${s(r)}`;for(let t=0;t<d;t++){let n=s(r+(t+.5)*l),o=f[t]/p*g;i+=` L ${e.middle+o} ${n}`}i+=` L ${e.middle} ${s(n)}`;for(let t=d-1;t>=0;t--){let n=s(r+(t+.5)*l),o=f[t]/p*g;i+=` L ${e.middle-o} ${n}`}i+=" Z"}else{i=`M ${s(r)} ${e.middle}`;for(let t=0;t<d;t++){let n=s(r+(t+.5)*l),o=f[t]/p*g;i+=` L ${n} ${e.middle-o}`}i+=` L ${s(n)} ${e.middle}`;for(let t=d-1;t>=0;t--){let n=s(r+(t+.5)*l),o=f[t]/p*g;i+=` L ${n} ${e.middle+o}`}i+=" Z"}let m,y=e$(t),x=a(JM(e.pieceData,e.name,y),e.name);h&&t.length>=4&&(m={q1Pos:s(y.q1),medianPos:s(y.median),q3Pos:s(y.q3),centerPos:e.middle,isVertical:u});let b=u?{x:e.x,y:Math.min(s(n),s(r)),width:e.width,height:Math.abs(s(n)-s(r))}:{x:Math.min(s(r),s(n)),y:e.x,width:Math.abs(s(n)-s(r)),height:e.width};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:b,iqrLine:m,stats:y,style:x,datum:e.pieceData,category:e.name})}return c},histogram:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s}=i,l=[],c=n.bins||25,u=n.normalize,d=s.domain?.(),h=d?+d[0]:void 0,f=d?+d[1]:void 0;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e));if(0===t.length)continue;let[i,r]=yr(t),n=null!=h&&isFinite(h)?h:i,d=null!=f&&isFinite(f)?f:r,p=(d-n)/c||1,g=t$(t,n,d,p,c),m=t.length,y=br(g,1);for(let t=0;t<c;t++){if(0===g[t])continue;let i=(u?g[t]/m:g[t]/y)*e.width*.9,r=s(n+t*p),o=s(n+(t+1)*p),c=Math.min(r,o),d=Math.abs(o-r),h=e.x+e.width-i,f={...e.pieceData[0],bin:t,count:g[t],range:[n+t*p,n+(t+1)*p],category:e.name,data:e.pieceData},x=a(f,e.name);l.push(_a(c,h,d,i,x,f,e.name))}}return l},ridgeline:function(e,t){let{scales:i,columns:r,config:n,getR:o,resolveSummaryStyle:a}=e,{r:s,projection:l}=i,c=[],u=n.bins||20,d="horizontal"===l,h=n.amplitude||1.5;for(let e of Object.values(r)){let t=e.pieceData.map(e=>o(e)).filter(e=>null!=e&&!isNaN(e)).sort((e,t)=>e-t);if(t.length<2)continue;let i,r=t[0],n=t[t.length-1],l=(n-r)/u||1,f=t$(t,r,n,l,u),p=br(f,1),g=e$(t),m=a(JM(e.pieceData,e.name,g),e.name),y=e.width*h;if(d){let t=e.x+e.width;i=`M ${s(r)} ${t}`;for(let e=0;e<u;e++)i+=` L ${s(r+(e+.5)*l)} ${t-f[e]/p*y}`;i+=` L ${s(n)} ${t} Z`}else{let t=e.x;i=`M ${t} ${s(r)}`;for(let e=0;e<u;e++){let n=s(r+(e+.5)*l);i+=` L ${t+f[e]/p*y} ${n}`}i+=` L ${t} ${s(n)} Z`}let x=d?{x:Math.min(s(r),s(n)),y:e.x,width:Math.abs(s(n)-s(r)),height:e.width}:{x:e.x,y:Math.min(s(n),s(r)),width:e.width,height:Math.abs(s(n)-s(r))};c.push({type:"violin",pathString:i,translateX:0,translateY:0,bounds:x,stats:g,style:{...m,fillOpacity:m.fillOpacity??.5},datum:e.pieceData,category:e.name})}return c},timeline:function(e,t){let{scales:i,columns:r,getRawRange:n,resolvePieceStyle:o}=e,{r:a,projection:s}=i,l=[],c="horizontal"===s;for(let e of Object.values(r))for(let t of e.pieceData){let i=n(t);if(!i)continue;let[r,s]=i,u=o(t,e.name);if(c){let i=a(Math.min(r,s)),n=a(Math.max(r,s));l.push(_a(i,e.x,n-i,e.width,u,t,e.name))}else{let i=a(Math.max(r,s)),n=a(Math.min(r,s));l.push(_a(e.x,i,e.width,n-i,u,t,e.name))}}return l},funnel:function(e,t){let{columns:i,getR:r,getStack:n,resolvePieceStyle:o}=e,a=[],s=t.width/2,l=!1!==e.config.showLabels,c=e.scales.o.domain().map(e=>i[e]).filter(Boolean);if(0===c.length)return a;let{steps:u,keys:d}=VM(c,r,n),h=d.length>1&&"_default"!==d[0],f=0;if(!h)for(let{stepTotal:e}of u)e>f&&(f=e);if(h)for(let e of u){let t=0,i=0;for(let r=0;r<d.length;r++){let n=e.groups.get(d[r]);n&&(r%2==0?t+=n.total:i+=n.total)}let r=Math.max(t,i);r>f&&(f=r)}if(0===f)return a;let p=u[0].stepTotal,g=h?.95*s:.9*t.width,m=i$().domain([0,f]).range([0,g]),y=e.config.connectorOpacity??.3,x=/* @__PURE__ */new Map;for(let t=0;t<u.length;t++){let i=u[t],r=i.col,n=0===t,c=r.x,f=r.width,g=.55*f,b=c+(f-g)/2,v=/* @__PURE__ */new Map;if(h){let e=0;for(let t of d){let r=i.groups.get(t);r&&(e+=m(r.total))}let t=s,c=s;for(let h=0;h<d.length;h++){let f=d[h],p=i.groups.get(f);if(!p)continue;let y=m(p.total),x=h%2==0,w=x?t:c-y;x?t+=y:c-=y;let k=o(p.pieces[0],f),S=u[0].groups.get(f)?.total??0,A=S>0?p.total/S*100:0,M={...p.pieces[0],__funnelValue:p.total,__funnelPercent:A,__funnelStep:r.name,__funnelIsFirstStep:n,__aggregateValue:p.total,__pieceCount:p.pieces.length,category:f};l&&(0===h&&(M.__funnelStepLabel=r.name,M.__funnelStepLabelX=s,M.__funnelStepLabelY=b,M.__funnelRowWidth=e),M.__funnelValueLabelX=w+y/2,M.__funnelValueLabelY=b,M.__funnelBarW=y),a.push(_a(w,b,y,g,k,M,f)),v.set(f,{x:w,y:b,w:y,h:g})}}else{let e=i.stepTotal,t=m(e),c=s-t/2,u=d[0],h="_default"!==u,f=i.groups.get(u)?.pieces[0]??r.pieceData[0],y=h?u:r.name,x=o(f,y),w=p>0?e/p*100:0,k={...f,__funnelValue:e,__funnelPercent:w,__funnelStep:r.name,__funnelIsFirstStep:n,category:h?u:r.name};l&&(k.__funnelStepLabel=r.name,k.__funnelStepLabelX=s,k.__funnelStepLabelY=b,k.__funnelRowWidth=t,k.__funnelValueLabelX=s,k.__funnelValueLabelY=b,k.__funnelBarW=t),a.push(_a(c,b,t,g,x,k,y)),v.set(u,{x:c,y:b,w:t,h:g})}if(t>0&&x.size>0){let t=h?d:[d[0]];for(let n of t){let t=x.get(n),s=v.get(n);if(!t||!s)continue;let l=(()=>{let e=i.groups.get(n),t="_default"===n?r.name:n;return o(e?e.pieces[0]:r.pieceData[0],t)})(),c={type:"trapezoid",points:[[t.x,t.y+t.h],[t.x+t.w,t.y+t.h],[s.x+s.w,s.y],[s.x,s.y]],style:{fill:l.fill||e.config.themeSemantic?.secondary||"#999",opacity:y,cursor:l.cursor},datum:i.groups.get(n)?.pieces[0]??r.pieceData[0],category:"_default"===n?r.name:n};a.push(c)}}x=v}return a},"bar-funnel":function(e,t){let{columns:i,getR:r,getStack:n,resolvePieceStyle:o,scales:a}=e,s=[],l=a.o.domain().map(e=>i[e]).filter(Boolean);if(0===l.length)return s;let{steps:c,keys:u}=VM(l,r,n),d=u.length>1&&"_default"!==u[0],h=a.r,f=d?u.length:1,p=d?.15:0;for(let e=0;e<c.length;e++){let t=c[e],i=t.col,r=0===e,n=e>0?c[e-1]:null,a=i.width/f,l=a*p,g=a-l;for(let e=0;e<u.length;e++){let f=u[e],p=t.groups.get(f);if(!p)continue;let m=p.total,y=c[0].groups.get(f)?.total??0,x=y>0?m/y*100:0,b=n?.groups.get(f)?.total??m,v=r?0:Math.max(0,b-m),w=i.x+e*a+l/2,k=h(m),S=h(0),A=S-k,M=o(p.pieces[0],d?f:i.name),$={...p.pieces[0],__barFunnelValue:m,__barFunnelPercent:x,__barFunnelIsFirstStep:r,__barFunnelIsDropoff:!1,__barFunnelStep:i.name,__barFunnelDropoffValue:v,__barFunnelCategory:"_default"===f?void 0:f,category:d?f:i.name,__barFunnelLabelX:w+g/2,__barFunnelLabelY:h(m+v)};if(s.push(_a(w,Math.min(k,S),g,Math.abs(A),M,$,d?f:i.name)),v>0){let e=h(m+v),t=k-e,r={...M},n={...p.pieces[0],__barFunnelValue:v,__barFunnelPercent:y>0?v/y*100:0,__barFunnelIsFirstStep:!1,__barFunnelIsDropoff:!0,__barFunnelStep:i.name,__barFunnelCategory:"_default"===f?void 0:f,category:d?f:i.name};s.push(_a(w,e,g,t,r,n,d?f:i.name))}}}return s},swimlane:function(e,t){let{scales:i,columns:r,getR:n,getStack:o,resolvePieceStyle:a}=e,{r:s,projection:l}=i,c=[],u="horizontal"===l,d=e.config.gradientFill,h=u?"left":"bottom",f=/* @__PURE__ */new Map,p=t=>{let i=f.get(t);if(void 0!==i)return i;let r="function"==typeof e.config.roundedTop?e.config.roundedTop(t.width):e.config.roundedTop,n="number"==typeof r&&Number.isFinite(r)?Math.max(0,r):0;return f.set(t,n),n},g=e.config.trackFill;if(g){let e="string"==typeof g?g:g.color,t="string"==typeof g?1:g.opacity??1,[i,n]=s.range(),o=Math.min(i,n),a=Math.abs(n-i);for(let i of Object.values(r)){let r={fill:e,opacity:t},n=u?_a(o,i.x,a,i.width,r,null,"__track__"):_a(i.x,o,i.width,a,r,null,"__track__"),s=p(i);s>0&&(n.cornerRadii={tl:s,tr:s,br:s,bl:s}),c.push(n)}}for(let e of Object.values(r)){let t=0,i=c.length,r=p(e);for(let i of e.pieceData){let r=Math.abs(n(i));if(0===r)continue;let l,f=o?o(i):e.name,p=a(i,f);if(u){let n=s(t),o=s(t+r);l=_a(n,e.x,o-n,e.width,p,i,f)}else{let n=s(t+r),o=s(t);l=_a(e.x,n,e.width,o-n,p,i,f)}d&&(l.fillGradient=d,l.roundedEdge=h),c.push(l),t+=r}if(r>0&&c.length>i){let e=c.slice(i),t=e[0],n=e[e.length-1];1===e.length?t.cornerRadii={tl:r,tr:r,br:r,bl:r}:u?(t.cornerRadii={tl:r,bl:r},n.cornerRadii={tr:r,br:r}):(t.cornerRadii={bl:r,br:r},n.cornerRadii={tl:r,tr:r})}}return c}};function n$(e){let{data:t,chartType:i,projection:r,normalize:n,rExtent:o,extentPadding:a=.05,baselinePadding:s,axisExtent:l,getO:c,getR:u,getStack:d,rawRExtent:h}=e,f=a;if("radial"===r&&("pie"===i||"donut"===i))return[0,1];let p=0,g=0;if("bar"===i||"bar-funnel"===i){let e=/* @__PURE__ */new Map;for(let i of t){let t=c(i);e.has(t)||e.set(t,[]),e.get(t).push(i)}for(let t of e.values()){let e=GM(t,u,d,"bar"===i&&n),r=0,o=0;for(let{value:t}of e.values())"bar-funnel"===i?(r=Math.max(r,t),o=Math.min(o,t)):t>=0?r+=t:o+=t;g=Math.max(g,r),p=Math.min(p,o)}}else if("swimlane"===i){let e=/* @__PURE__ */new Map;for(let i of t){let t=c(i),r=Math.abs(u(i));e.set(t,(e.get(t)||0)+r)}for(let t of e.values())t>g&&(g=t)}else if("clusterbar"===i)for(let e of t){let t=u(e);Number.isFinite(t)&&(t>g&&(g=t),t<p&&(p=t))}else{let e=h[0],t=h[1];e!==1/0&&(p=e),t!==-1/0&&(g=t)}o&&(null!=o[0]&&(p=o[0]),null!=o[1]&&(g=o[1]));let m="bar"===i||"clusterbar"===i||"bar-funnel"===i||"swimlane"===i;if(m&&(null!=o?.[0]||null!=o?.[1]||(p>0&&(p=0),g<0&&(g=0))),"bar-funnel"!==i&&"exact"!==l){let e=g-p,t=e>0?e*f:1,r=m&&!s&&0===p,n=m&&!s&&0===g||"swimlane"===i;null==o?.[0]&&!r&&(p-=t),null==o?.[1]&&!n&&(g+=t)}return[p,g]}function o$(e){let{data:t,oExtent:i,oScale:r,projection:n,layout:o,dynamicColumnWidth:a,getO:s,getR:l}=e,c=/* @__PURE__ */Object.create(null),u=/* @__PURE__ */new Map;for(let e of t){let t=s(e);u.has(t)||u.set(t,[]),u.get(t).push(e)}let d=0;if("radial"===n)for(let e of t)d+=Math.abs(l(e));let h=null;if(a&&"radial"!==n){h=/* @__PURE__ */new Map;let e=0;for(let t of i){let i,r=u.get(t)||[];i="string"==typeof a?r.reduce((e,t)=>{let i=Number(t[a]);return e+(Number.isFinite(i)?i:0)},0):a(r);let n=Number.isFinite(i)?Math.max(0,i):0;h.set(t,n),e=Math.max(e,n)}let t="horizontal"===n?o.height:o.width,s=r.padding()*r.step()*Math.max(0,i.length-1),l=Math.max(0,t-s);if(e>0){let t=0;for(let i of h.values())t+=i/e;for(let[i,r]of h)h.set(i,r/e/t*l)}}let f=0,p=0;for(let e of i){let t,i,n=u.get(e)||[],o=n.reduce((e,t)=>e+Math.abs(l(t)),0),a=d>0?o/d:0;h?(t=p,i=h.get(e)??r.bandwidth(),p+=i+r.padding()*r.step()):(t=r(e)??0,i=r.bandwidth()),c[e]={name:e,x:t,y:0,width:i,middle:t+i/2,padding:r.padding()*r.step(),pieceData:n,pct:a,pctStart:f},f+=a}return c}function a$(e,t){let i="function"==typeof t,r=i?null:t||"category",n=/* @__PURE__ */new Map;for(let o=0;o<e.length;o++){let a=e[o],s=i?t(a):a[r],l=n.get(s);l?l.push(o):n.set(s,[o])}return n}var s$=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],l$=["scene-style","data-paint","accessibility","evidence"],c$=(e,t)=>({retainedData:e,invalidations:t}),u$=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],d$=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],h$=["layout","scene-geometry","data-paint","overlay","accessibility","evidence"],f$=["scene-geometry","data-paint","accessibility","evidence"],p$=["scene-style","data-paint","accessibility","evidence"],g$=[],m$={chartType:/* @__PURE__ */c$("rebuild",u$),runtimeMode:/* @__PURE__ */c$("rebuild",u$),categoryAccessor:/* @__PURE__ */c$("rebuild",u$),valueAccessor:/* @__PURE__ */c$("rebuild",u$),oAccessor:/* @__PURE__ */c$("rebuild",u$),rAccessor:/* @__PURE__ */c$("rebuild",u$),stackBy:/* @__PURE__ */c$("rebuild",u$),groupBy:/* @__PURE__ */c$("rebuild",u$),timeAccessor:/* @__PURE__ */c$("rebuild",u$),accessorRevision:/* @__PURE__ */c$("rebuild",u$),colorAccessor:/* @__PURE__ */c$("rebuild",p$),symbolAccessor:/* @__PURE__ */c$("rebuild",f$),connectorAccessor:/* @__PURE__ */c$("rebuild",f$),dataIdAccessor:/* @__PURE__ */c$("rebuild",f$),projection:/* @__PURE__ */c$("preserve",d$),extentPadding:/* @__PURE__ */c$("preserve",d$),axisExtent:/* @__PURE__ */c$("preserve",d$),rExtent:/* @__PURE__ */c$("preserve",d$),oExtent:/* @__PURE__ */c$("preserve",d$),multiAxis:/* @__PURE__ */c$("preserve",d$),normalize:/* @__PURE__ */c$("preserve",d$),bins:/* @__PURE__ */c$("preserve",d$),oSort:/* @__PURE__ */c$("preserve",h$),barPadding:/* @__PURE__ */c$("preserve",h$),roundedTop:/* @__PURE__ */c$("preserve",h$),baselinePadding:/* @__PURE__ */c$("preserve",h$),innerRadius:/* @__PURE__ */c$("preserve",h$),cornerRadius:/* @__PURE__ */c$("preserve",h$),startAngle:/* @__PURE__ */c$("preserve",h$),sweepAngle:/* @__PURE__ */c$("preserve",h$),trackFill:/* @__PURE__ */c$("preserve",h$),showOutliers:/* @__PURE__ */c$("preserve",h$),showIQR:/* @__PURE__ */c$("preserve",h$),amplitude:/* @__PURE__ */c$("preserve",h$),connectorOpacity:/* @__PURE__ */c$("preserve",h$),showLabels:/* @__PURE__ */c$("preserve",h$),dynamicColumnWidth:/* @__PURE__ */c$("rebuild",h$),customLayout:/* @__PURE__ */c$("preserve",h$),layoutConfig:/* @__PURE__ */c$("preserve",h$),layoutMargin:/* @__PURE__ */c$("preserve",h$),symbolMap:/* @__PURE__ */c$("preserve",f$),pieceStyle:/* @__PURE__ */c$("preserve",p$),summaryStyle:/* @__PURE__ */c$("preserve",p$),connectorStyle:/* @__PURE__ */c$("preserve",p$),gradientFill:/* @__PURE__ */c$("preserve",p$),colorScheme:/* @__PURE__ */c$("preserve",p$),themeCategorical:/* @__PURE__ */c$("preserve",p$),themeSemantic:/* @__PURE__ */c$("preserve",p$),themeSequential:/* @__PURE__ */c$("preserve",p$),themeDiverging:/* @__PURE__ */c$("preserve",p$),barColors:/* @__PURE__ */c$("preserve",p$),decay:/* @__PURE__ */c$("preserve",p$),pulse:/* @__PURE__ */c$("preserve",p$),staleness:/* @__PURE__ */c$("preserve",p$),layoutSelection:/* @__PURE__ */c$("preserve",p$),windowSize:/* @__PURE__ */c$("preserve",g$),windowMode:/* @__PURE__ */c$("preserve",g$),clock:/* @__PURE__ */c$("preserve",g$),transition:/* @__PURE__ */c$("preserve",g$),introAnimation:/* @__PURE__ */c$("preserve",g$),onLayoutError:/* @__PURE__ */c$("preserve",g$)},y$=/* @__PURE__ */c$("preserve",h$);function x$(e){let t="preserve",i=/* @__PURE__ */new Set;for(let r of e){let e=m$[r]??y$;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var b$=class{constructor(){this.tracker=new is}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},s$)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},l$):this.recordNoop("restyle")}recordConfig(e){let t=x$(e);return this.tracker.record({kind:"config",keys:e},t.invalidations)}};import{quadtree as v$}from"d3-quadtree";function w$(e){let t=0,i=0;for(let r of e)"point"===r.type&&!1!==r.interactive&&(t++,r.r>i&&(i=r.r));if(t<=500)return{quadtree:null,maxRadius:i};let r=new Array(t),n=0;for(let t of e)"point"===t.type&&!1!==t.interactive&&(r[n++]=t);return{maxRadius:i,quadtree:v$().x(e=>e.x).y(e=>e.y).addAll(r)}}var k$=class extends Qa{constructor(e){super(),this.rExtent=new Ro,this.rExtents=[],this.windowSizeWarned=!1,this.updateResults=new b$,this.rAccessors=[],this.categories=/* @__PURE__ */new Set,this._hasStreamingData=!1,this.styleResolver=new qM,this.timestampBuffer=null,this.activeTransition=null,this.prevPositionMap=/* @__PURE__ */new Map,this.exitNodes=[],this.lastIngestTime=0,this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutFailedThisBuild=!1,this._customLayoutDiagnosticsWarned=/* @__PURE__ */new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,this.version=0,this._dataVersion=0,this._bufferArrayCache=null,this._pointQuadtree=null,this._maxPointRadius=0,this._datumIndexCache=null,this._categoryIndexCache=null,this._hasRenderedOnce=!1,this.config=e,this.buffer=new Lo(e.windowSize),this.getO=Fo(e.categoryAccessor||e.oAccessor,"category");let t="streaming"===e.runtimeMode,i=e.valueAccessor||e.rAccessor;Array.isArray(i)?(this.rAccessors=i.map(e=>To(e,"value")),this.getR=this.rAccessors[0],this.rExtents=i.map(()=>new Ro)):(t&&e.timeAccessor,this.getR=To(i,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent]),this.getStack=Fo(e.stackBy),this.getGroup=Fo(e.groupBy),this.getColor=Fo(e.colorAccessor),this.getSymbol=Fo(e.symbolAccessor),this.getConnector=Fo(e.connectorAccessor),this.getDataId=Fo(e.dataIdAccessor),e.pulse&&(this.timestampBuffer=new Lo(e.windowSize))}syncPulseTimestampBuffer(){var e,t,i,r;this.timestampBuffer=(e=!!this.config.pulse,t=this.buffer,i=this.timestampBuffer,r=this.currentTime(),e?null!=i&&i.capacity===t.capacity&&i.size===t.size?i:Ha(t,r):null)}currentTime(){return this.config.clock?.()??r()}ingest(e){let t=this.currentTime();if(this.lastIngestTime=t,this._dataVersion++,e.bounded){this.buffer.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();e.preserveCategoryOrder?this._hasStreamingData=!0:this.categories.clear(),this.timestampBuffer&&this.timestampBuffer.clear();let i=e.totalSize||e.inserts.length;Va(this.buffer,i,this.timestampBuffer);for(let i of e.inserts)Ua(this.buffer,i,this.timestampBuffer,t),this.categories.add(this.getO(i)),this.pushValueExtent(i)}else{this._hasStreamingData=!0;for(let i of e.inserts){let e=Ua(this.buffer,i,this.timestampBuffer,t);this.categories.add(this.getO(i)),this.pushValueExtent(i),null!=e&&this.evictValueExtent(e)}}return this.updateResults.recordData(e.bounded?"replace":"ingest",e.inserts.length),!0}ingestWithResult(e){return this.ingest(e),this.updateResults.last}pushValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.push(t[0]),this.rExtent.push(t[1]))}else if(this.rAccessors.length>1){for(let t=0;t<this.rAccessors.length;t++)this.rExtents[t].push(this.rAccessors[t](e));this.rExtent.push(this.getR(e))}else this.rExtent.push(this.getR(e))}evictValueExtent(e){if("timeline"===this.config.chartType){let t=this.getRawRange(e);t&&(this.rExtent.evict(t[0]),this.rExtent.evict(t[1]))}else if(this.rAccessors.length>1){for(let t=0;t<this.rAccessors.length;t++)this.rExtents[t].evict(this.rAccessors[t](e));this.rExtent.evict(this.getR(e))}else this.rExtent.evict(this.getR(e))}getRawRange(e){let t=this.config.valueAccessor||this.config.rAccessor;if(!t)return null;let i="function"==typeof t?t(e):e[t];return Array.isArray(i)&&i.length>=2?[+i[0],+i[1]]:null}computeScene(e){let{config:t,buffer:i}=this,r=this.scales,n=this.multiScales,o=this.columns;if(0===i.size)return this.scales=null,this.multiScales=[],this.scene=[],this.columns={},this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,void this.version++;this.rExtent.dirty&&("timeline"===t.chartType?(this.rExtent.clear(),i.forEach(e=>this.pushValueExtent(e))):this.rExtent.recalculate(i,this.getR));let a,s,l=this.getBufferArray(),c=t.projection||"vertical",u=t.oExtent||this.resolveCategories(l),d=this.computeValueDomain(l,u),h="vertical"===c,f="horizontal"===c,p="radial"===c,g=null!=t.barPadding?t.barPadding/(h?e.width:e.height):.1,m=Math.min(.9,Math.max(0,g));if(p){a=jM().domain(u).range([0,1]).padding(0);let i=Math.min(e.width,e.height)/2,r=t.innerRadius||0;s=WM().domain(d).range([r,i])}else f?(a=jM().domain(u).range([0,e.height]).padding(m),s=WM().domain(d).range([0,e.width])):(a=jM().domain(u).range([0,e.width]).padding(m),s=WM().domain(d).range([e.height,0]));this.scales={o:a,r:s,projection:c},this.rAccessors.length>1&&t.multiAxis?this.multiScales=this.rAccessors.map((r,n)=>{let o=this.rExtents[n];o.dirty&&o.recalculate(i,r);let[a,s]=o.extent;a===1/0&&(a=0,s=1);let l=t.extentPadding??.05,c=s-a,u=c>0?c*l:1;return a-=u,s+=u,a>0&&(a=0),f?WM().domain([a,s]).range([0,e.width]):WM().domain([a,s]).range([e.height,0])}):this.multiScales=[];let y=l;this.rAccessors.length>1&&(y=l.flatMap(e=>this.rAccessors.map((t,i)=>({...e,__rIndex:i,__rValue:t(e),__rName:this.resolveRAccessorName(i)})))),this.columns=this.buildColumns(y,u,a,c,e),this._customLayoutFailedThisBuild=!1;let x=this.buildSceneNodes(y,e);this._customLayoutFailedThisBuild?!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.scales=r,this.multiScales=n,this.columns=o):(this.scene=[],this.rebuildPointQuadtree()):(this.config.transition&&this.scene.length>0&&this.snapshotPositions(),this.scene=x,this.rebuildPointQuadtree(),this.config.decay&&this.applyDecay(this.scene,l),this.config.pulse&&this.applyPulse(this.scene,l),this.config.transition&&!this._hasRenderedOnce&&this.scene.length>0&&(this.config.introAnimation&&this.synthesizeIntroPositions(),this._hasRenderedOnce=!0),this.config.transition&&this.prevPositionMap.size>0&&this.startTransition(),this.version++)}resolveRAccessorName(e){let t=this.config.valueAccessor||this.config.rAccessor,i=Array.isArray(t)?t[e]:t;return"string"==typeof i?i:`value${e}`}resolveCategories(e){let t=this.config.oSort,i="streaming"===this.config.runtimeMode||this._hasStreamingData,r="auto"===t?void 0:t,n=null;if(i){n=/* @__PURE__ */new Set;for(let t of e)n.add(this.getO(t))}let o=n?Array.from(this.categories).filter(e=>n.has(e)):Array.from(this.categories);if(i&&void 0===r){let e=Math.max(50,3*n.size);if(this.categories.size>e){let t=this.categories.size-e;for(let e of this.categories){if(t<=0)break;n.has(e)||(this.categories.delete(e),t--)}}return o}if(!1===r)return o;if("function"==typeof r)return o.sort(r);let a=/* @__PURE__ */new Map;for(let t of e){let e=this.getO(t);a.set(e,(a.get(e)||0)+Math.abs(this.getR(t)))}return"asc"===r?o.sort((e,t)=>(a.get(e)||0)-(a.get(t)||0)):o.sort((e,t)=>(a.get(t)||0)-(a.get(e)||0))}computeValueDomain(e,t){return n$({data:e,chartType:this.config.chartType,projection:this.config.projection,normalize:this.config.normalize,rExtent:this.config.rExtent,extentPadding:this.config.extentPadding,baselinePadding:this.config.baselinePadding,axisExtent:this.config.axisExtent,getO:this.getO,getR:this.getR,getStack:this.getStack,rawRExtent:this.rExtent.extent})}buildColumns(e,t,i,r,n){return o$({data:e,oExtent:t,oScale:i,projection:r,layout:n,dynamicColumnWidth:this.config.dynamicColumnWidth,getO:this.getO,getR:this.getR})}getSceneContext(){return{scales:this.scales,columns:this.columns,config:this.config,getR:this.getR,getStack:this.getStack,getGroup:this.getGroup,getColor:this.getColor,getSymbol:this.getSymbol,getConnector:this.getConnector,getO:this.getO,multiScales:this.multiScales,rAccessors:this.rAccessors,resolvePieceStyle:(e,t)=>this.styleResolver.resolvePieceStyle(this.config,e,t),resolveSummaryStyle:(e,t)=>this.styleResolver.resolveSummaryStyle(this.config,e,t),getRawRange:e=>this.getRawRange(e)}}buildSceneNodes(e,t){if(!this.scales)return[];if(this.config.customLayout){let i=this.buildLayoutContext(e,t),r=la({family:"ordinal",logLabel:"ordinal customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:this.config.onLayoutError,run:()=>this.config.customLayout(i)});if("failure"===r.kind)return this.lastCustomLayoutFailure=r.diagnostic,this._customLayoutFailedThisBuild=!0,r.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,[]);let n=r.result;this.customLayoutOverlays=n.overlays??null,this.lastCustomLayoutResult=n,this.lastCustomLayoutFailure=null;let o=n.nodes??[];if(this._customRestyle=n.restyle,this.hasCustomRestyle=!!n.restyle,this.hasCustomRestyle){this._baseStyles=/* @__PURE__ */new WeakMap;for(let e of o)e.style&&this._baseStyles.set(e,e.style);this.applyCustomRestyle(o,this.config.layoutSelection??null)}return ra({label:"ordinal customLayout",nodes:o,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),o}this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1;let i=this.getSceneContext(),r=r$[this.config.chartType],n=r?r(i,t):[];return this.getConnector&&this.scales&&(n=[...XM(i,n),...n]),n}buildLayoutContext(e,t){let i=this.config,r=i.layoutMargin??{top:0,right:0,bottom:0,left:0},n=Ix(i.colorScheme,i.themeCategorical,$i),o=this.scales,a="radial"===o.projection?{x:-t.width/2,y:-t.height/2,width:t.width,height:t.height}:{x:0,y:0,width:t.width,height:t.height};return{data:e,scales:{o:o.o,r:o.r,projection:o.projection},dimensions:{width:t.width,height:t.height,margin:r,plot:a},theme:{semantic:i.themeSemantic??{},categorical:[...n]},resolveColor:Px(n,i.colorScheme),config:i.layoutConfig??{},selection:i.layoutSelection??null}}computeDecayOpacity(e,t){let i=this.config.decay;return!i||t<=1?1:jo(i,e,t)}getDatumIndexMap(e){if(this._datumIndexCache&&this._datumIndexCache.version===this._dataVersion)return this._datumIndexCache.map;let t=Wo(e);return this._datumIndexCache={version:this._dataVersion,map:t},t}getCategoryIndexMap(e){if(this._categoryIndexCache&&this._categoryIndexCache.version===this._dataVersion)return this._categoryIndexCache.map;let t=a$(e,this.config.categoryAccessor||this.config.oAccessor);return this._categoryIndexCache={version:this._dataVersion,map:t},t}rebuildPointQuadtree(){let e=w$(this.scene);this._pointQuadtree=e.quadtree,this._maxPointRadius=e.maxRadius}get pointQuadtree(){return this._pointQuadtree}get maxPointRadius(){return this._maxPointRadius}applyDecay(e,t){if(!this.config.decay)return;let i=t.length;if(i<=1)return;let r=this.getDatumIndexMap(t);for(let t of e){if("connector"===t.type||"violin"===t.type||"boxplot"===t.type||"wedge"===t.type||!t.datum)continue;let e=r.get(t.datum);if(null==e)continue;let n=this.computeDecayOpacity(e,i),o=t.style?.opacity??1;t.style={...t.style,opacity:o*n}}}applyPulse(e,t,i=this.currentTime()){return!(!this.config.pulse||!this.timestampBuffer)&&YM(this.config.pulse,e,this.timestampBuffer,this.getDatumIndexMap(t),e=>this.getCategoryIndexMap(t).get(e),i)}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(this.scene,this.getBufferArray(),e)}hasActivePulsesAt(e){return!!this.config.pulse&&Vo(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}synthesizeIntroPositions(){this.prevPositionMap.clear();let e,t=/* @__PURE__ */new Map,i=this.scales?.r(0)??0,r="horizontal"!==this.scales?.projection;for(let n=0;n<this.scene.length;n++){let o=this.scene[n],a=this.getNodeKey(o,t);a&&("rect"===o.type?r?this.prevPositionMap.set(a,{x:o.x,y:i,w:o.w,h:0,opacity:o.style.opacity??1}):this.prevPositionMap.set(a,{x:i,y:o.y,w:0,h:o.h,opacity:o.style.opacity??1}):"point"===o.type?this.prevPositionMap.set(a,{x:o.x,y:o.y,r:0,opacity:0}):"wedge"===o.type&&(void 0===e&&(e=o.startAngle),this.prevPositionMap.set(a,{x:o.cx,y:o.cy,startAngle:e,endAngle:e,innerRadius:o.innerRadius,outerRadius:o.outerRadius,opacity:0})))}}getNodeKey(e,t){if("point"===e.type){let i=`p:${e.datum?this.getO(e.datum):""}:${e.datum?this.getR(e.datum):0}`,r=t.get(i)||0;return t.set(i,r+1),`${i}:${r}`}if("rect"===e.type){let i=e.datum?null!=e.datum.category&&""!==e.datum.category?String(e.datum.category):String(this.getO(e.datum)??""):"",r=`r:${e.group||""}:${i}`,n=t.get(r)||0;return t.set(r,n+1),0===n?r:`${r}:${n}`}return"wedge"===e.type?`w:${e.category??""}`:null}snapshotPositions(){this.prevPositionMap.clear();let e=/* @__PURE__ */new Map;for(let t=0;t<this.scene.length;t++){let i=this.scene[t],r=this.getNodeKey(i,e);r&&("point"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,r:i.r,opacity:i.style.opacity??i.style.fillOpacity}):"rect"===i.type?this.prevPositionMap.set(r,{x:i.x,y:i.y,w:i.w,h:i.h,opacity:i.style.opacity??i.style.fillOpacity}):"wedge"===i.type&&this.prevPositionMap.set(r,{x:i.cx,y:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius,opacity:i.style.opacity??1}))}}startTransition(){if(!this.config.transition||0===this.prevPositionMap.size)return;let e=this.config.transition.duration??300;if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}let t=!1,i=/* @__PURE__ */new Set,r=/* @__PURE__ */new Map;for(let e=0;e<this.scene.length;e++){let n=this.scene[e],o=this.getNodeKey(n,r);if(!o)continue;n._transitionKey=o;let a=this.prevPositionMap.get(o);if("point"===n.type)a?(i.add(o),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(a.x!==n.x||a.y!==n.y||void 0!==a.r&&a.r!==n.r)&&(n._targetX=n.x,n._targetY=n.y,n._targetR=n.r,n.x=a.x,n.y=a.y,void 0!==a.r&&(n.r=a.r),t=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetR=n.r,n.r=0,n.style={...n.style,opacity:0},t=!0);else if("rect"===n.type)a?(i.add(o),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(a.x!==n.x||a.y!==n.y||a.w!==n.w||a.h!==n.h)&&(n._targetX=n.x,n._targetY=n.y,n._targetW=n.w,n._targetH=n.h,n.x=a.x,n.y=a.y,n.w=a.w??n.w,n.h=a.h??n.h,t=!0)):(n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n.style={...n.style,opacity:0},t=!0);else if("wedge"===n.type)if(a)i.add(o),n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,(a.startAngle!==n.startAngle||a.endAngle!==n.endAngle)&&(n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle,n.startAngle=a.startAngle,n.endAngle=a.endAngle,t=!0);else{n._targetOpacity=n.style.opacity??n.style.fillOpacity??1,n._targetStartAngle=n.startAngle,n._targetEndAngle=n.endAngle;let e=n.startAngle;n.startAngle=e,n.endAngle=e,n.style={...n.style,opacity:0},this.prevPositionMap.set(o,{x:n.cx,y:n.cy,startAngle:e,endAngle:e,innerRadius:n.innerRadius,outerRadius:n.outerRadius,opacity:0}),t=!0}}this.exitNodes=[];for(let[e,r]of this.prevPositionMap)if(!i.has(e)){if(e.startsWith("p:"))this.exitNodes.push({type:"point",x:r.x,y:r.y,r:r.r??3,style:{opacity:r.opacity??1},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("r:"))this.exitNodes.push({type:"rect",x:r.x,y:r.y,w:r.w??0,h:r.h??0,style:{opacity:r.opacity??1,fill:"#999"},datum:null,_targetOpacity:0,_transitionKey:e});else if(e.startsWith("w:")){let t=((r.startAngle??0)+(r.endAngle??0))/2,i={type:"wedge",cx:r.x,cy:r.y,innerRadius:r.innerRadius??0,outerRadius:r.outerRadius??100,startAngle:r.startAngle??0,endAngle:r.endAngle??0,style:{opacity:r.opacity??1},datum:null,category:e.slice(2),_targetStartAngle:t,_targetEndAngle:t,_targetOpacity:0,_transitionKey:e};this.exitNodes.push(i)}t=!0}this.exitNodes.length>0&&(this.scene=[...this.scene,...this.exitNodes]),t&&(this.activeTransition={startTime:this.currentTime(),duration:e})}advanceTransition(r){if(!this.activeTransition)return!1;let n=t(r,this.activeTransition),o="linear"===this.config.transition?.easing?"linear":"ease-out-cubic",a=e(n,o);for(let e of this.scene){let t=e._transitionKey;if(t)if("point"===e.type){if(void 0!==e._targetOpacity){let r=this.prevPositionMap.get(t),n=r?r.opacity??1:0;e.style.opacity=i(n,e._targetOpacity,a)}let r=this.prevPositionMap.get(t);void 0!==e._targetX&&r&&(e.x=i(r.x,e._targetX,a),e.y=i(r.y,e._targetY,a)),void 0!==e._targetR&&void 0!==r?.r&&(e.r=i(r.r,e._targetR,a))}else if("rect"===e.type){if(void 0!==e._targetOpacity){let r=this.prevPositionMap.get(t),n=r?r.opacity??1:0;e.style.opacity=i(n,e._targetOpacity,a)}if(void 0===e._targetX)continue;let r=this.prevPositionMap.get(t);if(!r)continue;e.x=i(r.x,e._targetX,a),e.y=i(r.y,e._targetY,a),void 0!==r.w&&(e.w=i(r.w,e._targetW,a),e.h=i(r.h,e._targetH,a))}else if("wedge"===e.type){if(void 0!==e._targetOpacity){let r=this.prevPositionMap.get(t),n=r?r.opacity??1:0;e.style={...e.style,opacity:i(n,e._targetOpacity,a)}}if(void 0!==e._targetStartAngle&&void 0!==e._targetEndAngle){let r=this.prevPositionMap.get(t);r&&void 0!==r.startAngle&&(e.startAngle=i(r.startAngle,e._targetStartAngle,a),e.endAngle=i(r.endAngle,e._targetEndAngle,a))}}}if(n>=1){for(let e of this.scene)if(void 0!==e._targetOpacity&&(e.style={...e.style||{},opacity:0===e._targetOpacity?0:e._targetOpacity},e._targetOpacity=void 0),"point"===e.type){if(void 0===e._targetX&&void 0===e._targetR)continue;void 0!==e._targetX&&(e.x=e._targetX,e.y=e._targetY),void 0!==e._targetR&&(e.r=e._targetR),e._targetX=void 0,e._targetY=void 0,e._targetR=void 0}else if("rect"===e.type){if(void 0===e._targetX)continue;e.x=e._targetX,e.y=e._targetY,e.w=e._targetW,e.h=e._targetH,e._targetX=void 0,e._targetY=void 0,e._targetW=void 0,e._targetH=void 0}else"wedge"===e.type&&void 0!==e._targetStartAngle&&(e.startAngle=e._targetStartAngle,e.endAngle=e._targetEndAngle,e._targetStartAngle=void 0,e._targetEndAngle=void 0);if(this.exitNodes.length>0){let e=new Set(this.exitNodes);this.scene=this.scene.filter(t=>!e.has(t)),this.exitNodes=[]}return this.activeTransition=null,!1}return!0}cancelIntroAnimation(){this.prevPositionMap.clear(),this.activeTransition=null,ws(this.scene),this.exitNodes=[]}getBufferArray(){return this._bufferArrayCache?.version!==this._dataVersion&&(this._bufferArrayCache={version:this._dataVersion,data:this.buffer.toArray()}),this._bufferArrayCache.data}getData(){return this.buffer.toArray()}remove(e){if(!this.getDataId)throw new Error("remove() requires dataIdAccessor to be configured");this.config.transition&&this.scene.length>0&&this.snapshotPositions();let t=zo(e),i=this.getDataId,r=e=>t.has(i(e));Ka(this.buffer,this.timestampBuffer,r);let n=this.buffer.remove(r);if(0===n.length)return this.updateResults.recordNoop("remove"),n;for(let e of n)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach(e=>this.categories.add(this.getO(e))),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("remove",n.length),n}update(e,t){if(!this.getDataId)throw new Error("update() requires dataIdAccessor to be configured");let i=zo(e),r=this.getDataId,n=/* @__PURE__ */new Set;this.buffer.forEach((e,t)=>{i.has(r(e))&&n.add(t)});let o=this.buffer.update(e=>i.has(r(e)),t);if(0===o.length)return this.updateResults.recordNoop("update"),o;for(let e of o)this.evictValueExtent(e);return this.categories.clear(),this.buffer.forEach((e,t)=>{this.categories.add(this.getO(e)),n.has(t)&&this.pushValueExtent(e)}),this._dataVersion++,this.version++,this.lastIngestTime=this.currentTime(),this.updateResults.recordData("update",o.length),o}clear(){this.buffer.clear(),this.rExtent.clear(),this.categories.clear(),this._hasStreamingData=!1,this._hasRenderedOnce=!1,this.timestampBuffer&&this.timestampBuffer.clear(),this.prevPositionMap.clear(),this.exitNodes=[],this.activeTransition=null,this.lastIngestTime=0,this.scales=null,this.scene=[],this.columns={},this.multiScales=[],this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,this._pointQuadtree=null,this._maxPointRadius=0,this.styleResolver.resetColors(),this._dataVersion++,this.version++,this.updateResults.recordData("clear")}get size(){return this.buffer.size}getOAccessor(){return this.getO}getRAccessor(){return this.getR}applyCustomRestyle(e,t){let i=this._customRestyle;if(i)for(let r of e){let e=this._baseStyles.get(r)??r.style??{},n=i(r,t);r.style=n?{...e,...n}:e}}restyleScene(e){this._customRestyle?(this.applyCustomRestyle(this.scene,e),this.markStylePaintPending(),this.updateResults.recordRestyle(!0)):this.updateResults.recordRestyle(!1)}rebuildAccessorDerivedState(){this.categories.clear(),this.rExtent.clear();for(let e of this.rExtents)e.clear();this._categoryIndexCache=null,this.buffer.forEach(e=>{this.categories.add(this.getO(e)),this.pushValueExtent(e)})}updateConfig(e){let t={...this.config},i=Object.keys(e).filter(i=>e[i]!==t[i]);"production"!==process.env.NODE_ENV&&!this.windowSizeWarned&&"windowSize"in e&&e.windowSize!==t.windowSize&&(this.windowSizeWarned=!0,console.warn(`[Semiotic] windowSize changed after mount (${t.windowSize} → ${e.windowSize}) but it is a mount-only setting — the ring buffer keeps its original capacity. Remount the chart (e.g. via a React key) to apply a new windowSize.`)),("colorScheme"in e&&e.colorScheme!==t.colorScheme||"themeCategorical"in e&&e.themeCategorical!==t.themeCategorical||"colorAccessor"in e&&!Co(e.colorAccessor,t.colorAccessor))&&this.styleResolver.resetColors(),("categoryAccessor"in e&&!Co(e.categoryAccessor,t.categoryAccessor)||"oAccessor"in e&&!Co(e.oAccessor,t.oAccessor))&&(this._categoryIndexCache=null),Object.assign(this.config,e),"pulse"in e&&this.syncPulseTimestampBuffer();let r=!1;("categoryAccessor"in e||"oAccessor"in e)&&(Co(this.config.categoryAccessor||this.config.oAccessor,t.categoryAccessor||t.oAccessor)||(this.getO=Fo(this.config.categoryAccessor||this.config.oAccessor,"category"),r=!0));let n=!1;if("valueAccessor"in e||"rAccessor"in e){let e=this.config.valueAccessor||this.config.rAccessor,i=t.valueAccessor||t.rAccessor,r=Array.isArray(e)?e:[e],o=Array.isArray(i)?i:[i];if(n=r.length!==o.length||r.some((e,t)=>!Co(e,o[t])),n){let e=this.config.valueAccessor||this.config.rAccessor;Array.isArray(e)?(this.rAccessors=e.map(e=>To(e,"value")),this.getR=this.rAccessors[0],this.rExtents=e.map(()=>new Ro)):(this.getR=To(e,"value"),this.rAccessors=[this.getR],this.rExtents=[this.rExtent])}}"stackBy"in e&&!Co(e.stackBy,t.stackBy)&&(this.getStack=null!=this.config.stackBy?Fo(this.config.stackBy):void 0),"groupBy"in e&&!Co(e.groupBy,t.groupBy)&&(this.getGroup=null!=this.config.groupBy?Fo(this.config.groupBy):void 0),"colorAccessor"in e&&!Co(e.colorAccessor,t.colorAccessor)&&(this.getColor=null!=this.config.colorAccessor?Fo(this.config.colorAccessor):void 0),"symbolAccessor"in e&&!Co(e.symbolAccessor,t.symbolAccessor)&&(this.getSymbol=null!=this.config.symbolAccessor?Fo(this.config.symbolAccessor):void 0),"connectorAccessor"in e&&!Co(e.connectorAccessor,t.connectorAccessor)&&(this.getConnector=null!=this.config.connectorAccessor?Fo(this.config.connectorAccessor):void 0);let o="accessorRevision"in e&&e.accessorRevision!==t.accessorRevision;(r||n||o)&&this.rebuildAccessorDerivedState(),this.updateResults.recordConfig(i)}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}};function S$(e,t,i,r){return"string"==typeof e?{key:e,fn:null}:"function"==typeof e?{key:i,fn:e}:"string"==typeof t?{key:t,fn:null}:"function"==typeof t?{key:r,fn:t}:{key:void 0,fn:null}}function A$(e,t,i){return r=>{if(!r||!i||!e.fn&&!t.fn)return r;let n=!1,o=r.map(i=>{let r=e.fn&&e.key&&!(e.key in i),o=t.fn&&t.key&&!(t.key in i);if(!r&&!o)return i;n=!0;let a={...i};return r&&(a[e.key]=e.fn(i)),o&&(a[t.key]=t.fn(i)),a});return n?o:r}}import*as M$ from"react";import*as $$ from"react";import{arc as _$}from"d3-shape";var I$=(e,t)=>({x:e*Math.cos(t),y:e*Math.sin(t)});function P$(e){let{innerRadius:t,outerRadius:i,startAngle:r,endAngle:n}=e,o=t<=0;if(!((e.cornerRadius??0)>0&&(e.roundStart||e.roundEnd))){if(o){let e=I$(i,r),t=I$(i,n),o=n-r>Math.PI?1:0;return`M0,0 L${e.x},${e.y} A${i},${i} 0 ${o} 1 ${t.x},${t.y} Z`}let e=I$(i,r),a=I$(i,n),s=I$(t,n),l=I$(t,r),c=n-r>Math.PI?1:0;return`M${e.x},${e.y} A${i},${i} 0 ${c} 1 ${a.x},${a.y} L${s.x},${s.y} A${t},${t} 0 ${c} 0 ${l.x},${l.y} Z`}let a=i-t,s=Math.max(0,Math.min(e.cornerRadius??0,a/2));if(0===s)return P$({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let l=Math.asin(Math.min(1,s/Math.max(1e-9,i-s))),c=o?0:Math.asin(Math.min(1,s/Math.max(1e-9,t+s))),u=n-r,d=e.roundStart&&e.roundEnd?u/2:u,h=!!e.roundStart&&l<d,f=!!e.roundEnd&&l<d;if(!h&&!f)return P$({...e,cornerRadius:0,roundStart:!1,roundEnd:!1});let p=r+(h?l:0),g=n-(f?l:0),m=r+(h?c:0),y=n-(f?c:0),x=I$(i,p),b=I$(i,g),v=(i-s)*Math.cos(l),w=I$(v,r),k=I$(v,n),S=o?null:I$(t,y),A=o?null:I$(t,m),M=o?0:(t+s)*Math.cos(c),$=o?null:I$(M,r),_=o?null:I$(M,n),I=g-p>Math.PI?1:0,P=o?0:y-m>Math.PI?1:0,L="";if(h)L+=`M${w.x},${w.y}`,L+=` A${s},${s} 0 0 1 ${x.x},${x.y}`;else{let e=I$(i,r);L+=`M${e.x},${e.y}`}if(f)L+=` A${i},${i} 0 ${I} 1 ${b.x},${b.y}`,L+=` A${s},${s} 0 0 1 ${k.x},${k.y}`;else{let e=I$(i,n);L+=` A${i},${i} 0 ${I} 1 ${e.x},${e.y}`}if(o)L+=" L0,0";else{if(f)L+=` L${_.x},${_.y}`,L+=` A${s},${s} 0 0 1 ${S.x},${S.y}`;else{let e=I$(t,n);L+=` L${e.x},${e.y}`}if(h)L+=` A${t},${t} 0 ${P} 0 ${A.x},${A.y}`,L+=` A${s},${s} 0 0 1 ${$.x},${$.y}`;else{let e=I$(t,r);L+=` A${t},${t} 0 ${P} 0 ${e.x},${e.y}`}}return L+=" Z",L}function L$(e){let t=P$({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:e.startAngle,endAngle:e.endAngle,cornerRadius:e.cornerRadius,roundStart:e.roundStart,roundEnd:e.roundEnd}),i=[],r=e.colors;if(r.length>0){let t=(e.endAngle-e.startAngle)/r.length;for(let n=0;n<r.length;n++){let o=e.startAngle+n*t;i.push({d:P$({innerRadius:e.innerRadius,outerRadius:e.outerRadius,startAngle:o,endAngle:e.endAngle}),color:r[n]})}}return{clipPath:t,slices:i}}import{jsx as R$,jsxs as C$}from"react/jsx-runtime";function T$(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e4?`${(e/1e3).toFixed(0)}K`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function N$(e,t){let i=e.datum;if(!i)return null;let r=[],n=i.__funnelStepLabel,o=Number(i.__funnelStepLabelX),a=Number(i.__funnelStepLabelY),s=Number(i.__funnelRowWidth);"string"==typeof n&&Number.isFinite(o)&&Number.isFinite(a)&&(!Number.isFinite(s)||8.4*n.length+16<=s)&&r.push(
305
- /* @__PURE__ */R$("text",{x:o,y:a+3,textAnchor:"middle",dominantBaseline:"hanging",fontSize:14,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.6)",strokeWidth:3,paintOrder:"stroke",children:n},`${t}-funnel-step`));let l=Number(i.__funnelValue),c=Number(i.__funnelValueLabelX),u=Number(i.__funnelValueLabelY),d=Number(i.__funnelBarW);if(Number.isFinite(l)&&0!==l&&Number.isFinite(c)&&Number.isFinite(u)&&d>=60){let e=Number(i.__funnelPercent),n=!0!==i.__funnelIsFirstStep&&Number.isFinite(e)?`${T$(l)} (${Math.abs(e-Math.round(e))<.05?Math.round(e):e.toFixed(1)}%)`:T$(l);7.8*n.length+16>d&&(n=T$(l)),7.8*n.length+16<=d&&r.push(
306
- /* @__PURE__ */R$("text",{x:c,y:u+22,textAnchor:"middle",dominantBaseline:"hanging",fontSize:13,fontWeight:"bold",fill:"#fff",fontFamily:"var(--semiotic-font-family, sans-serif)",stroke:"rgba(0,0,0,0.5)",strokeWidth:3,paintOrder:"stroke",children:n},`${t}-funnel-value`))}return r.length?/* @__PURE__ */R$("g",{children:r},`${t}-funnel-labels`):null}function F$(e,t,i){return Ol(E$(e,t,i),e,`ordinal-cursor-${t}`)}function E$(e,t,i){let r=("category"in e?e.category:void 0)||("group"in e?e.group:void 0)||"",n=i=>`ord-${e.type}-${r}-${t}-${i}`,o=`ord-${e.type}-${r}-${t}`;switch(e.type){case"rect":{let t,i,r=e,n=`${$l(o)}-grad`,a=Pl(r,n);if(a)i=`url(#${n})`;else if(el(r.style.fill)){let e=`${$l(o)}-hatch`;t=rl(r.style.fill,e),i=`url(#${e})`}else i=Ml(r.style.fill);let s=a||t?/* @__PURE__ */C$("defs",{children:[a,t]}):null;if(r.cornerRadii&&vl(r.cornerRadii)){let e=Ll(r);/* @__PURE__ */
307
- return C$($$.Fragment,{children:[s,
308
- /* @__PURE__ */R$("path",{d:e,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth})]},o)}if(r.roundedTop&&r.roundedTop>0){let e,t=Math.min(r.roundedTop,r.w/2,r.h/2),{x:n,y:a,w:l,h:c}=r;switch(r.roundedEdge){case"right":e=`M${n},${a} L${n+l-t},${a} A${t},${t} 0 0 1 ${n+l},${a+t} L${n+l},${a+c-t} A${t},${t} 0 0 1 ${n+l-t},${a+c} L${n},${a+c} Z`;break;case"left":e=`M${n+l},${a} L${n+t},${a} A${t},${t} 0 0 0 ${n},${a+t} L${n},${a+c-t} A${t},${t} 0 0 0 ${n+t},${a+c} L${n+l},${a+c} Z`;break;case"bottom":e=`M${n},${a} L${n+l},${a} L${n+l},${a+c-t} A${t},${t} 0 0 1 ${n+l-t},${a+c} L${n+t},${a+c} A${t},${t} 0 0 1 ${n},${a+c-t} Z`;break;default:e=`M${n},${a+c} L${n},${a+t} A${t},${t} 0 0 1 ${n+t},${a} L${n+l-t},${a} A${t},${t} 0 0 1 ${n+l},${a+t} L${n+l},${a+c} Z`}/* @__PURE__ */
309
- return C$($$.Fragment,{children:[s,
310
- /* @__PURE__ */R$("path",{d:e,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth})]},o)}/* @__PURE__ */
311
- return C$($$.Fragment,{children:[s,
312
- /* @__PURE__ */R$("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:i,opacity:r.style.opacity,stroke:r.style.stroke,strokeWidth:r.style.strokeWidth}),N$(r,o)]},o)}case"point":{let t=e;/* @__PURE__ */
313
- return R$("circle",{cx:t.x,cy:t.y,r:t.r,fill:Ml(t.style.fill),opacity:t.style.opacity??t.style.fillOpacity??.8,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},o)}case"symbol":return Rl(e,t,i);case"glyph":{let r=e;return _l(r,r.x,r.y,`${i??""}ord-glyph-${r.pointId??t}`)}case"wedge":{let r,n=e;if(n._gradientBand&&n._gradientBand.colors.length>0){let e=$l(`${i?`${i}-`:""}gauge-grad-${n.category||o}-${t}`),{clipPath:r,slices:a}=L$({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds?.start??!0,roundEnd:n.roundedEnds?.end??!0,colors:n._gradientBand.colors});/* @__PURE__ */
314
- return C$("g",{transform:`translate(${n.cx},${n.cy})`,opacity:n.style.opacity,fillOpacity:n.style.fillOpacity,children:[
315
- /* @__PURE__ */R$("defs",{children:/* @__PURE__ */R$("clipPath",{id:e,children:/* @__PURE__ */R$("path",{d:r})})}),
316
- /* @__PURE__ */R$("g",{clipPath:`url(#${e})`,children:a.map((e,t)=>/* @__PURE__ */R$("path",{d:e.d,fill:Ml(e.color)},t))}),n.style.stroke&&"none"!==n.style.stroke&&
317
- /* @__PURE__ */R$("path",{d:r,fill:"none",stroke:n.style.stroke,strokeWidth:n.style.strokeWidth})]},o)}if(n.roundedEnds)r=P$({innerRadius:n.innerRadius,outerRadius:n.outerRadius,startAngle:n.startAngle,endAngle:n.endAngle,cornerRadius:n.cornerRadius,roundStart:n.roundedEnds.start,roundEnd:n.roundedEnds.end});else{let e=_$().innerRadius(n.innerRadius).outerRadius(n.outerRadius).startAngle(n.startAngle+Math.PI/2).endAngle(n.endAngle+Math.PI/2);n.cornerRadius&&e.cornerRadius(n.cornerRadius),r=e(Al)||""}/* @__PURE__ */
318
- return R$("path",{d:r,transform:`translate(${n.cx},${n.cy})`,fill:Ml(n.style.fill),stroke:n.style.stroke,strokeWidth:n.style.strokeWidth,opacity:n.style.opacity},o)}case"boxplot":{let t=e,i=t.columnWidth/2,r=t.style.strokeWidth??1;return"vertical"===t.projection?/* @__PURE__ */C$("g",{children:[
319
- /* @__PURE__ */R$("line",{x1:t.x,y1:t.minPos,x2:t.x,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r}),
320
- /* @__PURE__ */R$("rect",{x:t.x-i,y:Math.min(t.q1Pos,t.q3Pos),width:t.columnWidth,height:Math.abs(t.q3Pos-t.q1Pos),fill:Ml(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),
321
- /* @__PURE__ */R$("line",{x1:t.x-i,y1:t.medianPos,x2:t.x+i,y2:t.medianPos,stroke:t.style.stroke||"#333",strokeWidth:2*r}),
322
- /* @__PURE__ */R$("line",{x1:t.x-.5*i,y1:t.minPos,x2:t.x+.5*i,y2:t.minPos,stroke:t.style.stroke||"#333",strokeWidth:r}),
323
- /* @__PURE__ */R$("line",{x1:t.x-.5*i,y1:t.maxPos,x2:t.x+.5*i,y2:t.maxPos,stroke:t.style.stroke||"#333",strokeWidth:r})]},o):/* @__PURE__ */C$("g",{children:[
324
- /* @__PURE__ */R$("line",{x1:t.minPos,y1:t.y,x2:t.maxPos,y2:t.y,stroke:t.style.stroke||"#333",strokeWidth:r}),
325
- /* @__PURE__ */R$("rect",{x:Math.min(t.q1Pos,t.q3Pos),y:t.y-i,width:Math.abs(t.q3Pos-t.q1Pos),height:t.columnWidth,fill:Ml(t.style.fill),fillOpacity:t.style.fillOpacity??.6,stroke:t.style.stroke||"#333",strokeWidth:r}),
326
- /* @__PURE__ */R$("line",{x1:t.medianPos,y1:t.y-i,x2:t.medianPos,y2:t.y+i,stroke:t.style.stroke||"#333",strokeWidth:2*r}),
327
- /* @__PURE__ */R$("line",{x1:t.minPos,y1:t.y-.5*i,x2:t.minPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r}),
328
- /* @__PURE__ */R$("line",{x1:t.maxPos,y1:t.y-.5*i,x2:t.maxPos,y2:t.y+.5*i,stroke:t.style.stroke||"#333",strokeWidth:r})]},o)}case"violin":{let t=e,i=[
329
- /* @__PURE__ */R$("path",{d:t.pathString,transform:t.translateX||t.translateY?`translate(${t.translateX},${t.translateY})`:void 0,fill:Ml(t.style.fill),fillOpacity:t.style.fillOpacity??t.style.opacity??.6,stroke:t.style.stroke||"#333",strokeWidth:t.style.strokeWidth??1},n("path"))];if(t.iqrLine&&t.bounds){let e=t.bounds,r=e.x+e.width/2,o=e.y+e.height/2;t.iqrLine.isVertical?i.push(
330
- /* @__PURE__ */R$("line",{x1:r,y1:t.iqrLine.q1Pos,x2:r,y2:t.iqrLine.q3Pos,stroke:t.style.stroke||"#333",strokeWidth:2},n("iqr")),
331
- /* @__PURE__ */R$("circle",{cx:r,cy:t.iqrLine.medianPos,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},n("med"))):i.push(
332
- /* @__PURE__ */R$("line",{x1:t.iqrLine.q1Pos,y1:o,x2:t.iqrLine.q3Pos,y2:o,stroke:t.style.stroke||"#333",strokeWidth:2},n("iqr")),
333
- /* @__PURE__ */R$("circle",{cx:t.iqrLine.medianPos,cy:o,r:3,fill:"white",stroke:t.style.stroke||"#333",strokeWidth:1},n("med")))}/* @__PURE__ */
334
- return R$("g",{children:i},o)}case"connector":{let t=e,i=t.style.fill&&"none"!==t.style.fill?Ml(t.style.fill,"var(--semiotic-border, #999)"):"var(--semiotic-border, #999)";/* @__PURE__ */
335
- return R$("line",{x1:t.x1,y1:t.y1,x2:t.x2,y2:t.y2,stroke:t.style.stroke||i,strokeWidth:t.style.strokeWidth??1,opacity:t.style.opacity??.5},o)}case"trapezoid":{let t=e,i=t.points.map(e=>`${e[0]},${e[1]}`).join(" ");/* @__PURE__ */
336
- return R$("polygon",{points:i,fill:Ml(t.style.fill,"#999"),opacity:t.style.opacity,stroke:t.style.stroke,strokeWidth:t.style.strokeWidth},o)}default:return null}}import{jsx as O$,jsxs as z$}from"react/jsx-runtime";function D$(e){return"connector"===e.node.type}function B$(e,t,i,r){if(e.length<2)return null;let n=e[0].node,o=n.style.fill;if(!o||"none"===o)return null;let a=$l(`${t?`${t}-`:""}connector-${i}-${r}-hatch`),s=el(o)?rl(o,a):null,l=[`${n.x1},${n.y1}`,...e.map(({node:e})=>`${e.x2},${e.y2}`)].join(" ");return Ol(/* @__PURE__ */z$(M$.Fragment,{children:[s&&/* @__PURE__ */O$("defs",{children:s}),
337
- /* @__PURE__ */O$("polygon",{points:l,fill:s?`url(#${a})`:Ml(o,"#999"),opacity:n.style.fillOpacity??n.style.opacity??.3,"data-semiotic-connector-fill":n.group||"_default"})]}),n,`ordinal-connector-fill-${i}-${r}`)}function j$(e,t,i){let r=/* @__PURE__ */new Map;for(let t of e){if(!D$(t))continue;let e=t.node.group||"_default",i=r.get(e);i?i.push(t):r.set(e,[t])}if(0===r.size)return;let n=Array.from(r.values()).map((e,r)=>/* @__PURE__ */z$("g",{children:[B$(e,t,i,r),e.map(e=>e.element)]},`ordinal-connectors-${i}-${r}`)),o=e[0],a=D$(o)?null:o.element;for(let e of r.values())for(let t of e)t.element=null;o.element=/* @__PURE__ */z$(M$.Fragment,{children:[n,a]},`ordinal-connector-run-${i}`)}function W$(e){let t=Zl({nodes:e.nodes,renderMode:e.renderMode,fallback:(t,i)=>F$(t,i,e.idPrefix)}),i=0;for(let r=0;r<t.length;){if(t[r].renderedByBackend){r++;continue}let n=r+1;for(;n<t.length&&!t[n].renderedByBackend;)n++;j$(t.slice(r,n),e.idPrefix,i++),r=n}return t}function Y$(e){let{id:t,...i}=e;return rl({type:"hatch",...i},t)}var q$={stroke:"rgba(255,255,255,0.5)",lineWidth:1.5,spacing:6,angle:45,lineOpacity:1};import{Fragment as X$,jsx as G$,jsxs as V$}from"react/jsx-runtime";function H$(e,t,i,r,n,o,a,s=!1){let l=e.scales;if(!l||"radial"===l.projection)return null;let c=$(r),u="vertical"===l.projection,d=e.columns,h=i.categoryFormat||i.oFormat,f=i.valueFormat||i.rFormat,p=i.categoryLabel||i.oLabel,g=i.valueLabel||i.rLabel,m=i.legendPosition??"right",y=D(i.legendLayout,a?.leftAxis),x=s&&"left"===m&&y>0?y:o?.left??i.margin?.left??40,b=Object.values(d).map((e,t)=>({pixel:e.middle,label:h?h(e.name,t):e.name})),v=i.rTickValues??Yd(l.r,5,i.axisExtent),w=f||I(v),k=v.map(e=>({pixel:l.r(e),label:w(e)}));/* @__PURE__ */
338
- return V$("g",u?{id:(n?`${n}-`:"")+"axes",className:"ordinal-axes",children:[
339
- /* @__PURE__ */G$("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:c.border,strokeWidth:1}),b.map((e,i)=>/* @__PURE__ */V$("g",{transform:`translate(${e.pixel},${t.height})`,children:[
340
- /* @__PURE__ */G$("line",{y2:5,stroke:c.border,strokeWidth:1}),Xd(e.label)?/* @__PURE__ */G$("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):Gd({label:e.label,x:-30,y:6,textAlign:"center",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},`oxtick-${i}`)),p&&/* @__PURE__ */G$("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:p}),
341
- /* @__PURE__ */G$("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:c.border,strokeWidth:1}),k.map((e,t)=>/* @__PURE__ */V$("g",{transform:`translate(0,${e.pixel})`,children:[
342
- /* @__PURE__ */G$("line",{x2:-5,stroke:c.border,strokeWidth:1}),
343
- /* @__PURE__ */G$("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label})]},`oytick-${t}`)),g&&/* @__PURE__ */G$("text",{x:15-x,y:t.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${t.height/2})`,children:g})]}:{id:(n?`${n}-`:"")+"axes",className:"ordinal-axes",children:[
344
- /* @__PURE__ */G$("line",{x1:0,y1:t.height,x2:t.width,y2:t.height,stroke:c.border,strokeWidth:1}),k.map((e,i)=>/* @__PURE__ */V$("g",{transform:`translate(${e.pixel},${t.height})`,children:[
345
- /* @__PURE__ */G$("line",{y2:5,stroke:c.border,strokeWidth:1}),
346
- /* @__PURE__ */G$("text",{y:18,textAnchor:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label})]},`oxtick-${i}`)),g&&/* @__PURE__ */G$("text",{x:t.width/2,y:t.height+40,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,children:g}),
347
- /* @__PURE__ */G$("line",{x1:0,y1:0,x2:0,y2:t.height,stroke:c.border,strokeWidth:1}),b.map((e,t)=>/* @__PURE__ */V$("g",{transform:`translate(0,${e.pixel})`,children:[
348
- /* @__PURE__ */G$("line",{x2:-5,stroke:c.border,strokeWidth:1}),Xd(e.label)?/* @__PURE__ */G$("text",{x:-8,textAnchor:"end",dominantBaseline:"middle",fontSize:c.tickSize,fill:c.textSecondary,fontFamily:c.fontFamily,children:e.label}):Gd({label:e.label,x:-68,y:-12,textAlign:"right",fontSize:c.tickSize,fontFamily:c.fontFamily,color:c.textSecondary})]},`oytick-${t}`)),p&&/* @__PURE__ */G$("text",{x:15-x,y:t.height/2,textAnchor:"middle",fontSize:c.labelSize,fill:c.text,fontFamily:c.fontFamily,transform:`rotate(-90, ${15-x}, ${t.height/2})`,children:p})]})}function U$(e,t){let i=M(e.theme),r=$h,n=e.size||[500,400],o=N({...r,...e.margin},e.title),a=C(e.title),s=ei(e.data),l=e.showLegend?pc(s,e.colorAccessor||e.stackBy||e.groupBy):[],c=X({showAxes:e.showAxes,projection:e.projection,hasCategoryLabel:!(!e.categoryLabel&&!e.oLabel),hasValueLabel:!(!e.valueLabel&&!e.rLabel)});ch(o,{props:{...e,axisChrome:c},categories:l,theme:i,size:n,hasTitle:a});let u=uh({props:{...e,axisChrome:c},categories:l,theme:i,size:n,margin:o,hasTitle:a}),d=Math.max(1,n[0]-o.left-o.right),h=Math.max(1,n[1]-o.top-o.bottom),f=e.projection||"vertical",p="radial"===f,g=e.colorScheme||i.colors.categorical,m={chartType:e.chartType,windowSize:e.windowSize??1e4,windowMode:e.windowMode??"sliding",extentPadding:e.extentPadding??.05,projection:f,oAccessor:e.oAccessor,rAccessor:e.rAccessor,colorAccessor:e.colorAccessor,stackBy:e.stackBy,groupBy:e.groupBy,categoryAccessor:e.categoryAccessor,valueAccessor:e.valueAccessor,timeAccessor:e.timeAccessor,rExtent:e.rExtent,oExtent:e.oExtent,axisExtent:e.axisExtent,barPadding:e.barPadding,roundedTop:e.roundedTop,innerRadius:e.innerRadius,cornerRadius:e.cornerRadius,normalize:e.normalize,startAngle:e.startAngle,sweepAngle:e.sweepAngle,bins:e.bins,showOutliers:e.showOutliers,showIQR:e.showIQR,amplitude:e.amplitude,oSort:e.oSort,connectorAccessor:e.connectorAccessor,connectorStyle:e.connectorStyle,dynamicColumnWidth:e.dynamicColumnWidth,pieceStyle:e.pieceStyle,summaryStyle:e.summaryStyle,gradientFill:er(e.gradientFill),symbolAccessor:e.symbolAccessor,symbolMap:e.symbolMap,multiAxis:e.multiAxis,baselinePadding:e.baselinePadding,trackFill:e.trackFill,connectorOpacity:e.connectorOpacity,showLabels:e.showLabels,colorScheme:g,themeCategorical:i.colors.categorical,themeSemantic:w(i),customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutMargin:o,layoutSelection:e.layoutSelection,barColors:e.barColors},y=new k$(m);e.data&&y.ingest({inserts:s,bounded:!0}),y.computeScene({width:d,height:h});let x=Mh(e.backgroundGraphics,n,o,y.scales),b=Mh(e.foregroundGraphics,n,o,y.scales);if(!y.scales){let r,a=e.annotations?Id({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:s,scales:{},layout:{width:d,height:h},theme:i,projection:f,idPrefix:e._idPrefix,onRender:e=>{r=e}}):null;t&&(t.evidence=Vs({frameType:"ordinal",width:n[0],height:n[1],marks:[],title:e.title,description:e.description,annotations:e.annotations,annotationRender:r,extraWarnings:y.scales?[]:["NO_SCALES"],margin:o}));let l=x||b||e.annotations?/* @__PURE__ */V$(X$,{children:[x,a,b,y.customLayoutOverlays]}):null;return BM.renderToStaticMarkup(hh(l,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}let v=e._idPrefix,k=e.showGrid?dh(y,{width:d,height:h},i,v,e.axisExtent,e.rTickValues):null,S=null;if(y.scene.some(e=>"rect"===e.type&&e.datum?.__barFunnelIsDropoff)){let t=nh(e),i=/* @__PURE__ */new Set;for(let e of y.scene)if("rect"===e.type&&e.datum?.__barFunnelIsDropoff){let t="string"==typeof e.style.fill?e.style.fill:"#666";i.add(t)}S=Array.from(i).map((e,i)=>Y$({...q$,id:`funnel-hatch-${t}-${i}`,background:e}));let r=/* @__PURE__ */new Map;Array.from(i).forEach((e,i)=>r.set(e,`funnel-hatch-${t}-${i}`));for(let e of y.scene)if("rect"===e.type&&e.datum?.__barFunnelIsDropoff){let t="string"==typeof e.style.fill?e.style.fill:"#666";e.style={...e.style,fill:`url(#${r.get(t)})`}}}let A,$=W$({nodes:y.scene,renderMode:e.renderMode,idPrefix:v}),_=$.map(e=>e.element),I=!1!==e.showAxes?H$(y,{width:d,height:h},e,i,v,o,c,!!u):null,P=e.categoryAccessor??e.oAccessor??"category",L=e.valueAccessor??e.rAccessor??"value",R="horizontal"===f,T=S$(R?L:P,void 0,"__semiotic_resolvedO",""),F=S$(R?P:L,void 0,"__semiotic_resolvedR",""),E=e.annotations?Id({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,annotationData:A$(T,F,e.annotations.length>0)(s),scales:{o:y.scales.o,r:y.scales.r,y:"vertical"===y.scales.projection?y.scales.r:void 0},layout:{width:d,height:h},theme:i,projection:f,xAccessor:T.key,yAccessor:F.key,idPrefix:v,onRender:e=>{A=e}}):null;if(t){let i=y.scales.o?.domain?.();t.evidence=Vs({frameType:"ordinal",width:n[0],height:n[1],marks:$.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:A,yDomain:Gs(y.scales.r?.domain?.()),categories:Array.isArray(i)?i.map(String):void 0,margin:o})}let O=p&&e.centerContent?DM(e.centerContent,o.left+d/2,o.top+h/2):null,z=p&&e.centerContent?O??/* @__PURE__ */G$("foreignObject",{x:o.left,y:o.top,width:d,height:h,pointerEvents:"none",children:/* @__PURE__ */G$("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",textAlign:"center"},children:e.centerContent})}):null,D=/* @__PURE__ */V$(X$,{children:[k,_,I,E,b,y.customLayoutOverlays]}),B=/* @__PURE__ */V$(X$,p?{children:[x?/* @__PURE__ */G$("g",{transform:`translate(${-d/2},${-h/2})`,children:x}):null,D]}:{children:[x,D]});return BM.renderToStaticMarkup(hh(B,{width:n[0],height:n[1],className:"stream-ordinal-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:p?`translate(${o.left+d/2},${o.top+h/2})`:`translate(${o.left},${o.top})`,innerWidth:d,innerHeight:h,legend:u,defs:S,outerElements:z,idPrefix:e._idPrefix}))}function K$({nodes:e,edges:t,restyle:i,restyleEdge:r,baseStyles:n,selection:o}){let a=!(!i&&!r);if(i)for(let t of e){let e=n.get(t)??t.style,r=i(t,o);t.style=r?{...e,...r}:e}if(r)for(let e of t){let t=n.get(e)??e.style,i=r(e,o);e.style=i?{...t,...i}:t}return a}import*as Z$ from"react-dom/server";var Q$=/* @__PURE__ */Object.create(null);function J$(e,t){Q$[e]=t}function e_(e){return Q$[e]}function t_(e,t){var i=e.get(t);if(!i)throw new Error("missing: "+t);return i}function i_(e,t,i){let r=e.length,n=Array.from({length:r},()=>[]),o=Array.from({length:r},()=>[]),a=new Int32Array(r),s=new Int32Array(r),l=new Float64Array(r),c=new Float64Array(t.length),u=new Int32Array(r),d=e.map(e=>{let t=i(e);return`${typeof t}:${String(t)}`}),h=0;for(let e of t)e.source.index!==e.target.index&&Number.isFinite(e.value)&&(h=Math.max(h,e.value));let f=(e,t)=>d[e]<d[t]?-1:d[e]>d[t]?1:0;t.map((e,t)=>t).sort((e,i)=>f(t[e].source.index,t[i].source.index)||f(t[e].target.index,t[i].target.index)||t[e].value-t[i].value).forEach(e=>{let i=t[e],r=i.source.index,u=i.target.index;if(r===u)return;let d=Number.isFinite(i.value)&&h>0?Math.max(0,i.value)/h:0;c[e]=d,o[r].push(e),n[u].push(e),s[r]++,a[u]++,l[r]+=d,l[u]-=d});let p=e.map(e=>e.index),g=Int32Array.from(p),m=e=>0===s[e]?2:0===a[e]?1:0,y=(e,t)=>{let i=m(e),r=m(t);return i!==r?i>r:0===i&&l[e]!==l[t]?l[e]>l[t]:d[e]<d[t]||d[e]===d[t]&&e<t},x=(e,t)=>{let i=p[e];p[e]=p[t],p[t]=i,g[p[e]]=e,g[i]=t},b=(e,t=!1)=>{let i=g[e];for(;!t&&i>0;){let t=i-1>>>1;if(!y(e,p[t]))break;x(i,t),i=t}for(;2*i+1<p.length;){let t=2*i+1;if(t+1<p.length&&y(p[t+1],p[t])&&t++,!y(p[t],e))break;x(i,t),i=t}};for(let e=(p.length>>>1)-1;e>=0;e--)b(p[e],!0);let v=0,w=r-1;for(;p.length;){let e=p[0];u[e]=0===s[e]?w--:v++;let i=p.pop();g[e]=-1,p.length&&(p[0]=i,g[i]=0,b(i));for(let i of o[e]){let e=t[i].target.index;g[e]<0||(a[e]--,l[e]+=c[i],b(e))}for(let i of n[e]){let e=t[i].source.index;g[e]<0||(s[e]--,l[e]-=c[i],b(e))}}return u}function r_(e){return e.y0-e.y1>0?"up":"down"}function n_(e,t){return t(e.source)==t(e.target)}function o_(e){return e.target.x0-e.source.x1}function a_(e,t){var i=l_(e),r=o_(t)/Math.tan(i);return"up"==r_(e)?e.y1-r:e.y1+r}function s_(e,t){var i=l_(e),r=o_(t)/Math.tan(i);return"up"==r_(e)?e.y1+r:e.y1-r}function l_(e){var t=Math.abs(e.y1-e.y0),i=Math.abs(e.target.x0-e.source.x1);return Math.atan(i/t)}function c_(e){return d_(e.source)}function u_(e){return d_(e.target)}function d_(e){return(e.y0+e.y1)/2}function h_(e){return e.virtual?0:e.value}function f_(e,t){var i=0;e.sourceLinks.forEach(function(e){i=e.circular&&!n_(e,t)?i+1:i});var r=0;return e.targetLinks.forEach(function(e){r=e.circular&&!n_(e,t)?r+1:r}),i+r}function p_(e){return e.target.depth}function g_(e,t){return e.sourceLinks.length?e.depth:t-1}function m_(e,t){return e.y0-t.y0}function y_(e,t){return t.y0-e.y0}function x_(e,t){return e.y1-t.y1}function b_(e,t){return t.y1-e.y1}function v_(e,t){return k_(e.source,t.source)||e.index-t.index}function w_(e,t){return k_(e.target,t.target)||e.index-t.index}function k_(e,t){return e.partOfCycle===t.partOfCycle?e.y0-t.y0:"top"===e.circularLinkType||"bottom"===t.circularLinkType?-1:1}function S_(e,t){return A_(e)==A_(t)?"bottom"==e.circularLinkType?y_(e,t):m_(e,t):A_(t)-A_(e)}function A_(e){return e.target.column-e.source.column}function M_(e,t){let i=e;return i.nodes.forEach(function(e){e.y+(e.y1-e.y0)>i.y1&&(e.y=e.y-(e.y+(e.y1-e.y0)-i.y1));var t=e.sourceLinks.slice().sort(function(e,t){return e.index-t.index});t.length>1&&t.sort(function(e,t){if(!e.circular&&!t.circular){if(e.target.column==t.target.column)return e.y1-t.y1;if(!__(e,t))return e.y1-t.y1;if(e.target.column>t.target.column){var i=a_(t,e);return e.y1-i}if(t.target.column>e.target.column)return a_(e,t)-t.y1}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.target.column===t.target.column?e.target.y1-t.target.y1:t.target.column-e.target.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.target.column===t.target.column?t.target.y1-e.target.y1:e.target.column-t.target.column:"top"==e.circularLinkType?-1:1:void 0});var r=e.y0;t.forEach(function(e){e.y0=r+e.width/2,r+=e.width});for(var n=0,o=t.length-1;o>=0;o--){var a=t[o];"bottom"==a.circularLinkType&&(a.y0=e.y1-n-a.width/2),n+=a.width}}),i}function $_(e,t){let i=e;return i.nodes.forEach(function(e){var t=e.targetLinks.slice().sort(function(e,t){return e.index-t.index});t.length>1&&t.sort(function(e,t){if(!e.circular&&!t.circular){if(e.source.column==t.source.column)return e.y0-t.y0;if(!__(e,t))return e.y0-t.y0;if(t.source.column<e.source.column){var i=s_(t,e);return e.y0-i}if(e.source.column<t.source.column)return s_(e,t)-t.y0}return e.circular&&!t.circular?"top"==e.circularLinkType?-1:1:t.circular&&!e.circular?"top"==t.circularLinkType?1:-1:e.circular&&t.circular?e.circularLinkType===t.circularLinkType&&"top"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:e.source.column-t.source.column:e.circularLinkType===t.circularLinkType&&"bottom"==e.circularLinkType?e.source.column===t.source.column?e.source.y1-t.source.y1:t.source.column-e.source.column:"top"==e.circularLinkType?-1:1:void 0});var i=e.y0;t.forEach(function(e){e.y1=i+e.width/2,i+=e.width});for(var r=0,n=t.length-1;n>=0;n--){var o=t[n];"bottom"==o.circularLinkType&&(o.y1=e.y1-r-o.width/2),r+=o.width}}),i}function __(e,t){return I_(e)==I_(t)}function I_(e){return e.y0-e.y1>0?"up":"down"}import{min as P_}from"d3-array";var L_=class{constructor(e){this.size=e,this.maximum=new Float64Array(4*e),this.floor=new Float64Array(4*e)}query(e,t){let i=(r,n,o)=>{if(e<=n&&o<=t)return this.maximum[r];let a=n+o>>>1;return Math.max(this.floor[r],e<=a?i(2*r,n,a):0,t>a?i(2*r+1,a+1,o):0)};return i(1,0,this.size-1)}reserve(e,t,i){let r=(n,o,a)=>{if(this.maximum[n]=Math.max(this.maximum[n],i),e<=o&&a<=t)return void(this.floor[n]=Math.max(this.floor[n],i));let s=o+a>>>1;e<=s&&r(2*n,o,s),t>s&&r(2*n+1,s+1,a)};r(1,0,this.size-1)}};function R_(e){var t=e.source.x1,i=e.y0,r=e.target.x0,n=e.y1,o=(t+r)/2;return"M"+t+","+i+"C"+o+","+i+" "+o+","+n+" "+r+","+n}function C_(e,t,i,r,n){let o=e;o.links.forEach(function(e){e.circular&&(e._circularWidth=e.width,e._circularStub=!1)});var a=P_(o.links,function(e){return e.source.y0});o.links.forEach(function(e){e.circular&&(e.circularPathData={})});var s=o.links.filter(function(e){return e.circular}),l=/* @__PURE__ */new Map,c=/* @__PURE__ */new Map;s.forEach(function(e){l.set(e.source,(l.get(e.source)||0)+1),c.set(e.target,(c.get(e.target)||0)+1)});var u=new Set(s.filter(function(e){return n_(e,t)&&1===l.get(e.source)&&1===c.get(e.target)}));return["top","bottom"].forEach(function(e){var t=s.filter(function(t){return t.circularLinkType===e});T_(t.slice(),u,i),["source","target"].forEach(function(n){var o=/* @__PURE__ */new Map;t.forEach(function(e){var t=e[n].column;o.has(t)||o.set(t,[]),o.get(t).push(e)}),o.forEach(function(t){t.sort("source"===n?"bottom"===e?y_:m_:"bottom"===e?b_:x_);var o=0,a="source"===n?"right":"left";t.forEach(function(e,t){e.circularPathData[a+"SmallArcRadius"]=r+e._circularWidth/2+o,e.circularPathData[a+"LargeArcRadius"]=r+e._circularWidth/2+t*i+o,o+=e._circularWidth})})})}),o.links.forEach(function(e){e.circular&&(e.circularPathData.arcRadius=e._circularWidth+r,e.circularPathData.rightNodeBuffer=5,e.circularPathData.leftNodeBuffer=5,e.circularPathData.sourceWidth=e.source.x1-e.source.x0,e.circularPathData.sourceX=e.source.x0+e.circularPathData.sourceWidth,e.circularPathData.targetX=e.target.x0,e.circularPathData.sourceY=e.y0,e.circularPathData.targetY=e.y1,u.has(e)?(e.circularPathData.rightSmallArcRadius=r+e._circularWidth/2,e.circularPathData.rightLargeArcRadius=r+e._circularWidth/2,e.circularPathData.leftSmallArcRadius=r+e._circularWidth/2,e.circularPathData.leftLargeArcRadius=r+e._circularWidth/2,"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=e.source.y1+n+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=e.source.y0-n-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius)):"bottom"==e.circularLinkType?(e.circularPathData.verticalFullExtent=Math.max(o.y1,e.source.y1,e.target.y1)+n+e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent-e.circularPathData.leftLargeArcRadius):(e.circularPathData.verticalFullExtent=a-n-e.circularPathData.verticalBuffer,e.circularPathData.verticalRightInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.rightLargeArcRadius,e.circularPathData.verticalLeftInnerExtent=e.circularPathData.verticalFullExtent+e.circularPathData.leftLargeArcRadius),e.circularPathData.rightInnerExtent=e.circularPathData.sourceX+e.circularPathData.rightNodeBuffer,e.circularPathData.leftInnerExtent=e.circularPathData.targetX-e.circularPathData.leftNodeBuffer,e.circularPathData.rightFullExtent=e.circularPathData.sourceX+e.circularPathData.rightLargeArcRadius+e.circularPathData.rightNodeBuffer,e.circularPathData.leftFullExtent=e.circularPathData.targetX-e.circularPathData.leftLargeArcRadius-e.circularPathData.leftNodeBuffer),e.circular?e.path=N_(e):e.path=R_(e)}),o}function T_(e,t,i){if(0!==e.length){e.sort(S_);var r=Array.from(new Set(e.flatMap(function(e){return[e.source.column,e.target.column]}))).sort(function(e,t){return e-t}),n=new Map(r.map(function(e,t){return[e,t]})),o=new L_(r.length);e.forEach(function(e){var r=n.get(e.source.column),a=n.get(e.target.column),s=Math.min(r,a),l=Math.max(r,a),c=t.has(e)?0:o.query(s,l);e.circularPathData.verticalBuffer=c+e._circularWidth/2,o.reserve(s,l,c+e._circularWidth+i)})}}function N_(e){return"top"==e.circularLinkType?"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 0 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY-e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 0 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 0 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY-e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 0 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY:"M"+e.circularPathData.sourceX+" "+e.circularPathData.sourceY+" L"+e.circularPathData.rightInnerExtent+" "+e.circularPathData.sourceY+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightSmallArcRadius+" 0 0 1 "+e.circularPathData.rightFullExtent+" "+(e.circularPathData.sourceY+e.circularPathData.rightSmallArcRadius)+" L"+e.circularPathData.rightFullExtent+" "+e.circularPathData.verticalRightInnerExtent+" A"+e.circularPathData.rightLargeArcRadius+" "+e.circularPathData.rightLargeArcRadius+" 0 0 1 "+e.circularPathData.rightInnerExtent+" "+e.circularPathData.verticalFullExtent+" L"+e.circularPathData.leftInnerExtent+" "+e.circularPathData.verticalFullExtent+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftLargeArcRadius+" 0 0 1 "+e.circularPathData.leftFullExtent+" "+e.circularPathData.verticalLeftInnerExtent+" L"+e.circularPathData.leftFullExtent+" "+(e.circularPathData.targetY+e.circularPathData.leftSmallArcRadius)+" A"+e.circularPathData.leftLargeArcRadius+" "+e.circularPathData.leftSmallArcRadius+" 0 0 1 "+e.circularPathData.leftInnerExtent+" "+e.circularPathData.targetY+" L"+e.circularPathData.targetX+" "+e.circularPathData.targetY}import{min as F_,max as E_,sum as O_,mean as z_,group as D_,groups as B_}from"d3-array";function j_(e){return function(){return e}}function W_(e){return e.index}function Y_(e){return e.nodes}function q_(e){return e.links}function X_(e,t){var i=/* @__PURE__ */new Map;return D_(e,t).forEach(function(e,t){i.set(t,e[0])}),i}function G_(e,t){e.nodes.forEach(function(e,t){e.index=t,e.sourceLinks=[],e.targetLinks=[]});var i=X_(e.nodes,t);e.links.forEach(function(e,t){e.index=t;var r=e.source,n=e.target;"object"!=typeof r&&(r=e.source=t_(i,r)),"object"!=typeof n&&(n=e.target=t_(i,n)),r.sourceLinks.push(e),n.targetLinks.push(e)})}function V_(e,t,i){var r=0,n=null==t?i_(e.nodes,e.links,i):null;e.nodes.forEach(function(e){delete e.circularLinkType}),e.links.forEach(function(e){delete e.circularLinkID,delete e.circularLinkType,delete e.circularPathData,delete e._circularWidth,delete e._circularStub,e.circular=n?n[e.source.index]>=n[e.target.index]:!(t(e.source)<t(e.target)),e.circular&&(e.circularLinkID=r++)})}function H_(e,t){var i=0,r=0;e.links.forEach(function(e){e.circular&&(e.source.circularLinkType||e.target.circularLinkType?e.circularLinkType=e.source.circularLinkType?e.source.circularLinkType:e.target.circularLinkType:e.circularLinkType=i<r?"top":"bottom","top"==e.circularLinkType?i++:r++,e.source.circularLinkType=e.circularLinkType,e.target.circularLinkType=e.circularLinkType)}),e.links.forEach(function(e){e.circular&&(e.source.circularLinkType==e.target.circularLinkType&&(e.circularLinkType=e.source.circularLinkType),n_(e,t)&&(e.circularLinkType=e.source.circularLinkType))})}function U_(e){e.nodes.forEach(function(e){e.partOfCycle=!1,e.value=Math.max(O_(e.sourceLinks,h_),O_(e.targetLinks,h_)),e.sourceLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)}),e.targetLinks.forEach(function(t){t.circular&&(e.partOfCycle=!0,e.circularLinkType=t.circularLinkType)})})}function K_(e,t,i){if(null!=t&&e.nodes.length){e.nodes.sort(function(e,i){return t(e)<t(i)?-1:1});var r=0,n=t(e.nodes[0]);e.nodes.forEach(function(e){r=t(e)==n?r:r+1,n=t(e)==n?n:t(e),e.column=r})}var o=new Int32Array(e.nodes.length),a=[],s=1;e.nodes.forEach(function(e){e.depth=e.height=0,e.targetLinks.forEach(function(t){t.circular||o[e.index]++}),0===o[e.index]&&a.push(e)});for(var l=0;l<a.length;l++){var c=a[l];s=Math.max(s,c.depth+1),c.sourceLinks.forEach(function(e){e.circular||(e.target.depth=Math.max(e.target.depth,c.depth+1),0===--o[e.target.index]&&a.push(e.target))})}for(l=a.length-1;l>=0;l--)(c=a[l]).sourceLinks.forEach(function(e){e.circular||(c.height=Math.max(c.height,e.target.height+1))});e.nodes.forEach(function(e){e.column=null==t?i(e,s):e.column})}function Z_(e,t,i){var r=B_(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});e.py=t;var n=F_(r,function(t){return(e.y1-e.y0-(t.length-1)*e.py)/O_(t,function(e){return e.value})});e.ky=n,e.links.forEach(function(t){t.width=t.value*e.ky});var o=E_(e.nodes,function(e){return e.column});o>0?e.nodes.forEach(function(t){t.x0=e.x0+t.column*((e.x1-e.x0-i)/o),t.x1=t.x0+i}):e.nodes.forEach(function(t){t.x0=e.x0,t.x1=t.x0+i})}function Q_(e){var t=0,i=0;return e.targetLinks.forEach(function(e){if(!e.circular){var r=e.value||1;i+=d_(e.source)*r,t+=r}}),e.sourceLinks.forEach(function(e){if(!e.circular){var r=e.value||1;i+=d_(e.target)*r,t+=r}}),t>0?i/t:NaN}function J_(e,t,i){var r=B_(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});r.forEach(function(n,o){var a=n.length;if(t)n.sort(t);else if(o>0){var s=/* @__PURE__ */new Map;n.forEach(function(e,t){var i=Q_(e);s.set(e,{bc:i,idx:t})}),n.sort(function(e,t){var i=s.get(e),r=s.get(t),n=i.bc,o=r.bc;if(e.circularLinkType!==t.circularLinkType){if("top"==e.circularLinkType&&"bottom"==t.circularLinkType)return-1;if("bottom"==e.circularLinkType&&"top"==t.circularLinkType)return 1;if("top"==e.circularLinkType)return-1;if("top"==t.circularLinkType||"bottom"==e.circularLinkType)return 1;if("bottom"==t.circularLinkType)return-1}return isNaN(n)||isNaN(o)?isNaN(n)?isNaN(o)?i.idx-r.idx:1:-1:n-o})}else n.sort(function(e,t){return e.circularLinkType==t.circularLinkType?f_(t,i)-f_(e,i):"top"==e.circularLinkType&&"bottom"==t.circularLinkType||"top"==e.circularLinkType&&0==t.partOfCycle||0==e.partOfCycle&&"bottom"==t.circularLinkType?-1:0});n.forEach(function(t,n){t.depth==r.length-1&&1==a||0==t.depth&&1==a?(t.y0=e.y1/2-t.value*e.ky,t.y1=t.y0+t.value*e.ky):t.partOfCycle?0==f_(t,i)?(t.y0=e.y1/2+n,t.y1=t.y0+t.value*e.ky):"top"==t.circularLinkType?(t.y0=e.y0+n,t.y1=t.y0+t.value*e.ky):(t.y0=e.y1-t.value*e.ky-n,t.y1=t.y0+t.value*e.ky):0==e.y0||0==e.y1?(t.y0=(e.y1-e.y0)/a*n,t.y1=t.y0+t.value*e.ky):(t.y0=(e.y1-e.y0)/2-a/2+n,t.y1=t.y0+t.value*e.ky)})})}function eI(e,t,i,r,n,o){var a=B_(e.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]});u();for(var s=1,l=o;l>0;--l)c(s*=.99,i),u();function c(t,i){var r=a.length;a.forEach(function(n){var o=n.length,a=n[0].depth;n.forEach(function(n){var s;if(n.sourceLinks.length||n.targetLinks.length)if(n.partOfCycle&&f_(n,i)>0){var l=z_(n.sourceLinks,u_),c=z_(n.targetLinks,c_),u=l&&c?(l+c)/2:l||c;if(u){var d=(u-d_(n))*t*.3;n.y0+=d,n.y1+=d}}else if(0==a&&1==o)s=n.y1-n.y0,n.y0=e.y1/2-s/2,n.y1=e.y1/2+s/2;else if(a==r-1&&1==o)s=n.y1-n.y0,n.y0=e.y1/2-s/2,n.y1=e.y1/2+s/2;else if(1==n.targetLinks.length&&1==n.targetLinks[0].source.sourceLinks.length)s=n.y1-n.y0,n.y0=n.targetLinks[0].source.y0,n.y1=n.y0+s;else{var h=z_(n.sourceLinks,u_),f=z_(n.targetLinks,c_),p=((h&&f?(h+f)/2:h||f)-d_(n))*t;n.y0+=p,n.y1+=p}})})}function u(){a.forEach(function(i){var o,a,s,l=e.y0,c=i.length;for(t?i.sort(t):i.sort(k_),s=0;s<c;++s)(a=l-(o=i[s]).y0)>0&&(o.y0+=a,o.y1+=a),l=o.y1+r;if((a=l-r-e.y1)>0)for(l=o.y0-=a,o.y1-=a,s=c-2;s>=0;--s)(a=(o=i[s]).y1+n-l)>0&&(o.y0-=a,o.y1-=a),l=o.y0})}}function tI(e){e.nodes.forEach(function(e){e.sourceLinks.sort(w_),e.targetLinks.sort(v_)}),e.nodes.forEach(function(e){var t=e.y0,i=t,r=e.y1,n=r;e.sourceLinks.forEach(function(e){e.circular?(e.y0=r-e.width/2,r-=e.width):(e.y0=t+e.width/2,t+=e.width)}),e.targetLinks.forEach(function(e){e.circular?(e.y1=n-e.width/2,n-=e.width):(e.y1=i+e.width/2,i+=e.width)})})}function iI(e){var t=e.nodes,i=e.links,r=!1,n=!1;if(i.forEach(function(e){"top"==e.circularLinkType?r=!0:"bottom"==e.circularLinkType&&(n=!0)}),0==r||0==n){let r=function(t){return(t-o)/(a-o)*(e.y1-e.y0)+e.y0};var o=F_(t,function(e){return e.y0}),a=E_(t,function(e){return e.y1}),s=a-o,l=(e.y1-e.y0)/s;l<1?(t.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1)}),i.forEach(function(e){e.y0=r(e.y0),e.y1=r(e.y1),e.width=e.width*l})):t.forEach(function(e){var t=e.y1-e.y0,i=r(e.y0)-e.y0;e.y0=r(e.y0),e.y1=e.y0+t,e.sourceLinks.forEach(function(e){e.y0=e.y0+i}),e.targetLinks.forEach(function(e){e.y1=e.y1+i})})}}function rI(){var e=0,t=0,i=1,r=1,n=24,o=8,a=null,s=W_,l=g_,c=void 0,u=32,d=2,h=Y_,f=q_;function p(){var e={nodes:h.apply(null,arguments),links:f.apply(null,arguments)};return g(e),e}function g(h){h.x0=e,h.y0=t,h.x1=i,h.y1=r,h.py=0,G_(h,s),V_(h,c,s),H_(h,s),U_(h),K_(h,c,l);var f=o;if(null!==a){var p=B_(h.nodes,function(e){return e.column}).sort(function(e,t){return e[0]-t[0]}).map(function(e){return e[1]}),g=E_(p,function(e){return e.length});g>1&&(f=Math.max(1,(r-t)*a/(g-1)))}Z_(h,f,n),J_(h,c,s),eI(h,c,s,f,f,u),tI(h),J_(h,c,s),eI(h,c,s,f,f,u),tI(h),M_(h),$_(h),iI(h),C_(h,s,d,10,8)}return p.update=function(e){return tI(e),C_(e,s,d,10,8),e},p.nodeWidth=function(e){return arguments.length?(n=+e,p):n},p.nodePadding=function(e){return arguments.length?(o=+e,p):o},p.nodePaddingRatio=function(e){return arguments.length?(a=+e,p):a},p.nodes=function(e){return arguments.length?(h="function"==typeof e?e:j_(e),p):h},p.links=function(e){return arguments.length?(f="function"==typeof e?e:j_(e),p):f},p.nodeId=function(e){return arguments.length?(s="function"==typeof e?e:j_(e),p):s},p.nodeAlign=function(e){return arguments.length?(l="function"==typeof e?e:j_(e),p):l},p.nodeSort=function(e){return arguments.length?(c=e,p):c},p.iterations=function(e){return arguments.length?(u=+e,p):u},p.circularLinkGap=function(e){return arguments.length?(d=+e,p):d},p.extent=function(n){return arguments.length?(e=+n[0][0],t=+n[0][1],i=+n[1][0],r=+n[1][1],p):[[e,t],[i,r]]},p.size=function(n){return arguments.length?(e=t=0,i=+n[0],r=+n[1],p):[i-e,r-t]},p}import{interpolateNumber as nI}from"d3-interpolate";var oI=e=>{let{source:t,target:i}=e;if("string"==typeof t||"string"==typeof i)return null;if("down"===e.direction){let r=e.y0-e.sankeyWidth/2,n=e.y1-e.sankeyWidth/2,o=e.y1+e.sankeyWidth/2,a=e.y0+e.sankeyWidth/2,s=t.x1,l=i.x0,c=nI(s,l),u=c(.5),d=c(.5);return`M${r},${s}C${r},${u} ${n},${d} ${n},${l}L${o},${l}C${o},${d} ${a},${u} ${a},${s}Z`}let r=e.sankeyWidth/2,n=nI(t.x1,i.x0),{pathD:o}=CA({sx:t.x1,sTop:e.y0-r,sBot:e.y0+r,tx:i.x0,tTop:e.y1-r,tBot:e.y1+r,cp1X:n(.5),cp2X:n(.5)});return o};function aI(e){let t=e.circularPathData;if(!t)return null;let i=e.sankeyWidth/2,r="bottom"===e.circularLinkType?1:-1,n=1===r?1:0,o="down"===e.direction,a=(e,t)=>o?`${t},${e}`:`${e},${t}`,s=(e,t,i,r,n)=>`A${o?t:e},${o?e:t} 0 0 ${o?1-i:i} ${a(r,n)}`,{sourceX:l,sourceY:c,targetX:u,targetY:d,rightInnerExtent:h,leftInnerExtent:f,rightFullExtent:p,leftFullExtent:g,verticalFullExtent:m,verticalRightInnerExtent:y,verticalLeftInnerExtent:x,rightLargeArcRadius:b,rightSmallArcRadius:v,leftLargeArcRadius:w,leftSmallArcRadius:k}=t;return`M${a(l,c-r*i)}L${a(h,c-r*i)}`+s(b+i,v+i,n,p+i,c+r*v)+`L${a(p+i,y)}`+s(b+i,b+i,n,h,m+r*i)+`L${a(f,m+r*i)}`+s(w+i,w+i,n,g-i,x)+`L${a(g-i,d+r*k)}`+s(w+i,k+i,n,f,d-r*i)+`L${a(u,d-r*i)}L${a(u,d+r*i)}L${a(f,d+r*i)}`+s(w-i,k-i,1-n,g+i,d+r*k)+`L${a(g+i,x)}`+s(w-i,w-i,1-n,f,m-r*i)+`L${a(h,m-r*i)}`+s(b-i,b-i,1-n,p-i,y)+`L${a(p-i,c+r*v)}`+s(b-i,v-i,1-n,h,c+r*i)+`L${a(l,c+r*i)}Z`}var sI=/* @__PURE__ */new Set,lI=/* @__PURE__ */new WeakMap;function cI(e,t){if("production"===process.env.NODE_ENV||!e||!e.data||"object"!=typeof e.data)return e;let i=lI.get(e);if(i){let e=i.get(t);if(e)return e}else i=/* @__PURE__ */new Map,lI.set(e,i);let r=new Proxy(e,{get(e,i,r){if("string"==typeof i&&!(i in e)&&e.data&&i in e.data){let e=`${t}:${i}`;sI.has(e)||(sI.add(e),console.warn(`[Semiotic] "${t}" callback accessed "${i}" on the wrapper object, but it only exists on ".data". Use d.data.${i} (or d.data?.${i}) instead. Frame callbacks receive RealtimeNode/RealtimeEdge wrappers, not your raw data.`))}return Reflect.get(e,i,r)}});return i.set(t,r),r}var uI={left:function(e){return e.depth},right:function(e,t){return t-1-e.height},center:function(e){return e.targetLinks.length?e.depth:e.sourceLinks.length?Math.min.apply(Math,e.sourceLinks.map(p_))-1:0},justify:g_},dI={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){let n="vertical"===i.orientation?"down":"right",o=i.nodeAlign||"justify",a=i.nodeWidth??15,s=i.nodePaddingRatio??.05,l=i.iterations??300;for(let e of t)e.sankeyWidth=0,e.circular=!1,delete e.circularPathData,delete e._circularWidth,delete e._circularStub;for(let t of e)t.value=0,t.width=t.height=0,t.x0=t.x1=t.y0=t.y1=0,t.sourceLinks=[],t.targetLinks=[];let c=new Set(e.map(e=>e.id)),u=/* @__PURE__ */new Set,d=t.filter(e=>{let t=Oo(e.source),i=Oo(e.target);return!(!Number.isFinite(e.value)||e.value<=0||!c.has(t)||!c.has(i)||(u.add(t),u.add(i),0))}).map(e=>({...e,source:Oo(e.source),target:Oo(e.target)}));if(0===d.length)return;let h,f=e.filter(e=>u.has(e.id)).map(e=>({...e}));h="down"===n?[[0,0],[r[1],r[0]]]:[[0,0],[r[0],r[1]]];let p=rI().extent(h).links(d).nodes(f).nodeAlign(uI[o]||g_).nodeId(e=>e.id).nodeWidth(a).iterations(l);p.nodePaddingRatio&&p.nodePaddingRatio(s),p();{let e=1/0,t=-1/0,i=1/0,r=-1/0;for(let n of f)n.x0<e&&(e=n.x0),n.x1>t&&(t=n.x1),n.y0<i&&(i=n.y0),n.y1>r&&(r=n.y1);for(let n of d){if(!n.circular||!n.circularPathData)continue;let o=n.circularPathData,a=(n._circularWidth??n.width??0)/2;o.leftFullExtent-a<e&&(e=o.leftFullExtent-a),o.rightFullExtent+a>t&&(t=o.rightFullExtent+a),o.verticalFullExtent-a<i&&(i=o.verticalFullExtent-a),o.verticalFullExtent+a>r&&(r=o.verticalFullExtent+a)}let n=t-e,o=r-i,a=h[1][0],s=h[1][1];if(n>0&&o>0&&(e<0||i<0||t>a||r>s)){let t=a/n,r=s/o,l=Math.min(t,r),c=-e*l+(a-n*l)/2,u=-i*l+(s-o*l)/2;for(let e of f)e.x0=e.x0*l+c,e.x1=e.x1*l+c,e.y0=e.y0*l+u,e.y1=e.y1*l+u;for(let e of d)if(e.y0=e.y0*l+u,e.y1=e.y1*l+u,e.width=(e.width??0)*l,e._circularWidth&&(e._circularWidth*=l),e.circular&&e.circularPathData){let t=e.circularPathData;t.sourceX=t.sourceX*l+c,t.targetX=t.targetX*l+c,t.sourceY=t.sourceY*l+u,t.targetY=t.targetY*l+u,t.rightFullExtent=t.rightFullExtent*l+c,t.leftFullExtent=t.leftFullExtent*l+c,t.verticalFullExtent=t.verticalFullExtent*l+u,t.rightInnerExtent=t.rightInnerExtent*l+c,t.leftInnerExtent=t.leftInnerExtent*l+c,t.verticalRightInnerExtent=t.verticalRightInnerExtent*l+u,t.verticalLeftInnerExtent=t.verticalLeftInnerExtent*l+u,t.rightSmallArcRadius*=l,t.rightLargeArcRadius*=l,t.leftSmallArcRadius*=l,t.leftLargeArcRadius*=l,t.sourceWidth*=l,t.rightNodeBuffer*=l,t.leftNodeBuffer*=l,t.arcRadius*=l}}}let g=/* @__PURE__ */new Map;for(let t of e)g.set(t.id,t);for(let e of f){let t=g.get(e.id);t&&(t.x0=e.x0,t.x1=e.x1,t.y0=e.y0,t.y1=e.y1,t.value=e.value,t.depth=e.depth,t.sourceLinks=e.sourceLinks,t.targetLinks=e.targetLinks,t.width=e.x1-e.x0,t.height=e.y1-e.y0,t.x=e.x0+(e.x1-e.x0)/2,t.y=e.y0+(e.y1-e.y0)/2)}let m=/* @__PURE__ */new Map;for(let e of t)if(e._edgeKey)m.set(e._edgeKey,e);else{let t=Oo(e.source),i=Oo(e.target);m.set(`${t}\0${i}`,e)}for(let e of d){let t=Oo(e.source),i=Oo(e.target),r=e._edgeKey?m.get(e._edgeKey):m.get(`${t}\0${i}`);if(r){r.y0=e.y0,r.y1=e.y1,r.sankeyWidth=e.width??0,r.circular=!!e.circular,r.circularPathData=e.circularPathData,r._circularWidth=e._circularWidth,r._circularStub=e._circularStub,r.path=e.path,r.circularLinkType=e.circularLinkType,r.direction=n;let o=g.get(t),a=g.get(i);o&&(r.source=o),a&&(r.target=a)}}},buildScene(e,t,i,r){let n="vertical"===i.orientation?"down":"right",o=i.nodeStyle,a=i.edgeStyle,s=i.edgeOpacity??.5,l=i.edgeColorBy||"source",c=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:oi,u=/* @__PURE__ */new Map;e.forEach((e,t)=>{u.set(e.id,c[t%c.length])});let d=[],h=[],f=[],p=/* @__PURE__ */new Map;for(let t of e){let e=t.x1-t.x0,i=t.y1-t.y0;if(t.value<=0||e<=0||i<=0)continue;let r=o?o(cI(t,"nodeStyle")):{},a={fill:r.fill||u.get(t.id)||"#4d430c",stroke:r.stroke,strokeWidth:r.strokeWidth,opacity:r.opacity,cursor:r.cursor};p.set(t.id,("string"==typeof a.fill?a.fill:null)||u.get(t.id)||"#4d430c"),"down"===n?d.push({type:"rect",x:t.y0,y:t.x0,w:i,h:e,style:a,datum:t,id:t.id,label:t.id}):d.push({type:"rect",x:t.x0,y:t.y0,w:e,h:i,style:a,datum:t,id:t.id,label:t.id})}let g=[...t].sort((e,t)=>(t.sankeyWidth||0)-(e.sankeyWidth||0));for(let e of g){if(!(e.value>0)||!e.sankeyWidth||e.sankeyWidth<=0)continue;let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999";n="function"==typeof l?l(e)||n:"target"===l?p.get(r.id)||u.get(r.id)||n:p.get(t.id)||u.get(t.id)||n;let o,c=a?a(cI(e,"edgeStyle")):{};if(o=e.circular&&e.circularPathData?aI(e):oI(e),!o)continue;let d={fill:c.fill||n,fillOpacity:c.fillOpacity??s,stroke:c.stroke||"none",strokeWidth:c.strokeWidth,strokeOpacity:c.strokeOpacity,opacity:c.opacity,cursor:c.cursor};h.push({type:"bezier",pathD:o,bezierCache:e.bezier,style:d,datum:e})}if(!1!==i.showLabels){let t=Eo(i.nodeLabel);for(let i of e){let e=i.x1-i.x0,o=i.y1-i.y0;if(i.value<=0||e<=0||o<=0)continue;let a,s,l,c=t?t(i):i.id;if(c){if("down"===n)a=i.y0+(i.y1-i.y0)/2,s=i.x1+14,l="start";else{let t=r[0]/2;i.x0+e/2<t?(a=i.x0-6,l="end"):(a=i.x1+6,l="start"),s=i.y0+o/2}f.push({x:a,y:s,text:String(c),anchor:"down"===n?"middle":l,baseline:"middle",fontSize:11})}}}return{sceneNodes:d,sceneEdges:h,labels:f}}};import{forceSimulation as hI,forceCenter as fI,forceX as pI,forceY as gI,forceLink as mI,forceManyBody as yI,forceCollide as xI}from"d3-force";import{scaleLinear as bI}from"d3-scale";function vI(e,t,i){if(i.some(e=>null!=e.__forceRadius))return e=>e.__forceRadius??8;if(null==e)return()=>8;if("number"==typeof e)return()=>e;if("function"==typeof e)return t=>e(t)||8;let r=t||[5,20],n=[];for(let t of i){let i=t.data?.[e];"number"==typeof i&&n.push(i)}if(0===n.length)return()=>r[0];let[o,a]=yr(n);if(o===a)return()=>(r[0]+r[1])/2;let s=bI().domain([o,a]).range(r).clamp(!0);return t=>{let i=t.data?.[e];return null==i||"number"!=typeof i?r[0]:s(i)}}function wI(e){let t=e.data?.weight??e.weight;return"number"==typeof t&&Number.isFinite(t)?t:Number.isFinite(e.value)?e.value:1}function kI(e){let t=e>>>0;return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}var SI={supportsStreaming:!0,hierarchical:!1,computeLayout(e,t,i,r){if(0===e.length)return;let n=i.forceStrength??.1,o=r[0]/2,a=r[1]/2,s=Math.max(.1,Math.min(1,Math.min(r[0],r[1])/200)),l=Math.min(.5,.06+1.8*(1-s)),c=i.__previousPositions,u=0,d=[];for(let t of e){let e=null!=t.x&&null!=t.y&&(0!==t.x||0!==t.y),i=c?.get(t.id);e?u++:i?(t.x=i.x,t.y=i.y,u++):d.push(t)}let h=e.length>0?d.length/e.length:1,f=u>0&&h<=.3;if(f){let i=/* @__PURE__ */new Map;for(let t of e)i.set(t.id,t);for(let e of d){let r=AI(e.id,t,i);if(r.length>0){let t=0,i=0;for(let e of r)t+=e.x,i+=e.y;let n=$I(e.id),o=n%360*(Math.PI/180),a=(10+n%20)*s;e.x=t/r.length+a*Math.cos(o),e.y=i/r.length+a*Math.sin(o)}else{let t=$I(e.id),i=t%360*(Math.PI/180),r=(15+t%30)*s;e.x=o+r*Math.cos(i),e.y=a+r*Math.sin(i)}}}else{let t=Math.PI*(3-Math.sqrt(5));for(let i=0;i<e.length;i++){let r=e[i];if(null==r.x||null==r.y||0===r.x&&0===r.y){let e=10*Math.sqrt(i+.5)*s,n=i*t;r.x=o+e*Math.cos(n),r.y=a+e*Math.sin(n)}}}let p=e.length,g=i.iterations??Math.max(50,Math.min(300,Math.floor(300-2*(p-30)))),m=i.__skipForceSimulation||0===i.iterations?0:f?40:g,y=vI(i.nodeSize,i.nodeSizeRange,e),x=e=>y(e);if(m>0){let c=/* @__PURE__ */new Map,u=/* @__PURE__ */new Map;for(let t of e)c.set(t.id,0),u.set(t.id,t);for(let e of t){let t=Oo(e.source),i=Oo(e.target);c.set(t,(c.get(t)??0)+1),c.set(i,(c.get(i)??0)+1)}let d=mI().strength(e=>{let t=wI(e),i=Oo(e.source),r=Oo(e.target),o=Math.max(1,Math.min(c.get(i)??1,c.get(r)??1)),a=t&&t>0?Math.sqrt(t):1;return Math.min(2.5,a*n/(.1*o))}).distance(e=>{let t="string"==typeof e.source?u.get(e.source):e.source,i="string"==typeof e.target?u.get(e.target):e.target,r=(t?x(t):0)+(i?x(i):0)+Math.max(6,12*s);return Math.max(16,40*s,r)}).id(e=>e.id),h=hI();if((void 0!==i.random||void 0!==i.seed)&&h.randomSource(i.random??kI(i.seed)),h.force("charge",yI().strength(e=>{let t=c.get(e.id)??0;return-15*s*x(e)*Math.sqrt(t+1)})).force("collide",xI(e=>x(e)+3*s).strength(.9).iterations(2)).force("center",fI(o,a).strength(.8)).force("x",pI(o).strength(l)).force("y",gI(a).strength(l)).force("bounds",MI(r,x)),h.nodes(e),t.length>0){let e=t.map(e=>({...e,source:Oo(e.source),target:Oo(e.target)}));d.links(e),h.force("link",d)}f?h.alpha(.3):h.alpha()<.1&&h.alpha(1),h.stop();for(let e=0;e<m;++e)h.tick()}for(let t of e){if(null==t.x||null==t.y)continue;let e=x(t),i=m>0?2:0,n=Math.min(r[0]/2,e+i),o=Math.min(r[1]/2,e+i);t.x=Math.max(n,Math.min(r[0]-n,t.x)),t.y=Math.max(o,Math.min(r[1]-o,t.y)),t.x0=0,t.x1=0,t.y0=0,t.y1=0}let b=/* @__PURE__ */new Map;for(let t of e)b.set(t.id,t);for(let e of t){if("string"==typeof e.source){let t=b.get(e.source);t&&(e.source=t)}if("string"==typeof e.target){let t=b.get(e.target);t&&(e.target=t)}}},buildScene(e,t,i,r){let n=i.nodeStyle,o=i.edgeStyle,a=vI(i.nodeSize,i.nodeSizeRange,e),s=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:oi,l=/* @__PURE__ */new Map;e.forEach((e,t)=>{l.set(e.id,s[t%s.length])});let c=[],u=[],d=[];for(let t of e){if(null==t.x||null==t.y)continue;let e=a(cI(t,"nodeSize")),r=n?n(cI(t,"nodeStyle")):{},o={fill:r.fill||l.get(t.id)||i.themeSemantic?.primary||"#007bff",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??2,opacity:r.opacity,cursor:r.cursor};c.push({type:"circle",cx:t.x,cy:t.y,r:e,style:o,datum:t,id:t.id,label:t.id})}let h=/* @__PURE__ */new Map;for(let t of e)h.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:h.get(e.source),r="object"==typeof e.target?e.target:h.get(e.target);if(!t||!r||null==t.x||null==t.y||null==r.x||null==r.y)continue;let n=o?o(cI(e,"edgeStyle")):{},a={stroke:n.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:n.strokeWidth??1,opacity:n.opacity??.6,cursor:n.cursor};u.push({type:"line",x1:t.x,y1:t.y,x2:r.x,y2:r.y,style:a,datum:e})}if(!1!==i.showLabels){let t=Eo(i.nodeLabel);for(let i of e){if(null==i.x||null==i.y)continue;let e=t?t(i):i.id;if(!e)continue;let r=a(cI(i,"nodeSize"));d.push({x:i.x,y:i.y-r-4,text:String(e),anchor:"middle",baseline:"auto",fontSize:11,anchorPoint:[i.x,i.y]})}}return{sceneNodes:c,sceneEdges:u,labels:d}}};function AI(e,t,i){let r=[];for(let n of t){let t=Oo(n.source),o=Oo(n.target),a=null;if(t===e?a=o:o===e&&(a=t),a){let e=i.get(a);e&&(0!==e.x||0!==e.y)&&r.push({x:e.x,y:e.y})}}return r}function MI(e,t,i=2,r=.6){let n=[],o=o=>{let a=r*Math.max(o,.2);for(let r of n){let n=r.x??e[0]/2,o=r.y??e[1]/2,s=r.vx??0,l=r.vy??0,c=t(r)+i,u=Math.min(e[0]/2,c),d=Math.max(e[0]/2,e[0]-c),h=Math.min(e[1]/2,c),f=Math.max(e[1]/2,e[1]-c),p=n+s,g=o+l;p<u?r.vx=s+(u-p)*a:p>d&&(r.vx=s+(d-p)*a),g<h?r.vy=l+(h-g)*a:g>f&&(r.vy=l+(f-g)*a)}};return o.initialize=e=>{n=e},o}function $I(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i)|0;return Math.abs(t)}import{chord as _I,ribbon as II}from"d3-chord";import{arc as PI}from"d3-shape";var LI=oi,RI={supportsStreaming:!1,hierarchical:!1,computeLayout(e,t,i,r){for(let t of e)delete t.__arcData;for(let e of t)delete e.__chordData,delete e.__chordEdges;if(0===e.length)return;let{padAngle:n=.01,groupWidth:o=20,sortGroups:a}=i,s=Math.min(r[0],r[1])/2,l=s-o,c=r[0]/2,u=r[1]/2,d=new Map(e.map(e=>[e.id,e])),h=/* @__PURE__ */new Set,f=t.filter(e=>{let t=Oo(e.source),i=Oo(e.target);return!(!Number.isFinite(e.value)||e.value<=0||!d.has(t)||!d.has(i)||(h.add(t),h.add(i),0))}),p=e.filter(e=>h.has(e.id)),g=p.length;if(0===g)return;let m=new Map(p.map((e,t)=>[e.id,t])),y=Array.from({length:g},()=>new Array(g).fill(0)),x=/* @__PURE__ */new Map;for(let e of f){let t=Oo(e.source),i=Oo(e.target),r=m.get(t),n=m.get(i);y[r][n]+=e.value;let o=r<=n?`${r}\0${n}`:`${n}\0${r}`,a=x.get(o);a?a.push(e):x.set(o,[e])}let b=Math.min(Number.isFinite(n)?Math.max(0,n):.01,Math.PI/g),v=_I().padAngle(b);a&&v.sortGroups(a);let w=v(y),k=w.groups,S=PI().innerRadius(l).outerRadius(s);for(let e of k){let t=p[e.index],i={innerRadius:l,outerRadius:s,startAngle:e.startAngle,endAngle:e.endAngle},r=S.centroid(i);t.x=r[0]+c,t.y=r[1]+u,t.__arcData={startAngle:e.startAngle,endAngle:e.endAngle}}for(let e of t){let t=Oo(e.source),i=Oo(e.target),r=d.get(t),n=d.get(i);r&&(e.source=r),n&&(e.target=n)}for(let e of w){let t=e.source.index,i=e.target.index,r=t<=i?`${t}\0${i}`:`${i}\0${t}`,n=x.get(r);for(let t of n)t.__chordData=e,t.__chordEdges=n}},buildScene(e,t,i,r){let{groupWidth:n=20,edgeOpacity:o=.5}=i,a=Math.min(r[0],r[1])/2,s=a-n,l=r[0]/2,c=r[1]/2,u=i.nodeStyle,d=i.edgeStyle,h=i.edgeColorBy||"source",f=Array.isArray(i.colorScheme)?i.colorScheme:i.themeCategorical&&i.themeCategorical.length>0?i.themeCategorical:LI,p=/* @__PURE__ */new Map;e.forEach((e,t)=>{p.set(e.id,f[t%f.length])});let g=II().radius(s),m=[],y=[],x=[];for(let t=0;t<e.length;t++){let i=e[t],r=i.__arcData;if(!r)continue;let n=u?u(cI(i,"nodeStyle")):{},o={fill:("string"==typeof n.fill?n.fill:void 0)||p.get(i.id)||f[t%f.length],stroke:n.stroke||"black",strokeWidth:n.strokeWidth??1,opacity:n.opacity,cursor:n.cursor};m.push({type:"arc",cx:l,cy:c,innerR:s,outerR:a,startAngle:r.startAngle-Math.PI/2,endAngle:r.endAngle-Math.PI/2,style:o,datum:i,id:i.id,label:i.id})}let b=/* @__PURE__ */new Set,v=e.filter(e=>e.__arcData);for(let e of t){let t=e.__chordData;if(!t||b.has(t))continue;b.add(t);let r=v[t.source.index].id;for(let t of e.__chordEdges||[])Oo(t.source)===r&&(e=t);let n=g(t);if(!n)continue;let a=CI(n,l,c),s=i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",u=d?d(cI(e,"edgeStyle")):{};if(d)s=("string"==typeof u.fill?u.fill:void 0)||s;else{let t="object"==typeof e.source?e.source:null,i="object"==typeof e.target?e.target:null;"target"===h&&i?s=p.get(i.id)||s:t&&(s=p.get(t.id)||s)}let f={fill:s,fillOpacity:u.fillOpacity??o,stroke:u.stroke||"none",strokeWidth:u.strokeWidth,strokeOpacity:u.strokeOpacity,opacity:u.opacity,cursor:u.cursor};y.push({type:"ribbon",pathD:a,style:f,datum:e})}if(!1!==i.showLabels){let t=Eo(i.nodeLabel),r=a+12;for(let i of e){let e=i.__arcData;if(!e)continue;let n=t?t(i):i.id;if(!n)continue;let o=(e.startAngle+e.endAngle)/2,a=o-Math.PI/2,s=l+Math.cos(a)*r,u=c+Math.sin(a)*r,d=o>Math.PI?"end":"start";x.push({x:s,y:u,text:String(n),anchor:d,baseline:"middle",fontSize:11})}}return{sceneNodes:m,sceneEdges:y,labels:x}}};function CI(e,t,i){let r=e.match(/[a-zA-Z]|[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?/g);if(!r)return e;let n=[],o=0;for(;o<r.length;){let e=r[o];if("M"===e||"L"===e||"C"===e||"Q"===e)for(n.push(e),o++;o<r.length&&!isNaN(Number(r[o]));)n.push(String(Number(r[o])+t)),o++,o<r.length&&!isNaN(Number(r[o]))&&(n.push(String(Number(r[o])+i)),o++);else if("A"===e)for(n.push(e),o++;o<r.length&&!isNaN(Number(r[o]));)n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&n.push(r[o++]),o<r.length&&(n.push(String(Number(r[o])+t)),o++),o<r.length&&(n.push(String(Number(r[o])+i)),o++);else"Z"===e||"z"===e?(n.push(e),o++):(n.push(r[o]),o++)}return n.join(" ")}import{hierarchy as TI,tree as NI,cluster as FI,treemap as EI,pack as OI,partition as zI,treemapBinary as DI}from"d3-hierarchy";var BI=["#e8d5b7","#b8d4e3","#d4e3b8","#e3c4d4","#d4d4e3","#e3d4b8","#b8e3d4","#e3b8b8"];function jI(e){if(e.startsWith("#")){let t=e.slice(1);if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6===t.length)return[0,2,4].map(e=>parseInt(t.slice(e,e+2),16))}let t=e.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return t?[+t[1],+t[2],+t[3]]:[128,128,128]}function WI(e){let[t,i,r]=jI(e);return.299*t+.587*i+.114*r>150?"#222":"#fff"}function YI(e){if(e)return"function"==typeof e?e:t=>t[e]}function qI(e,t,i){let r=t.nodeIDAccessor,n=e.data;return String("function"==typeof r?r(n):"string"==typeof r&&void 0!==n[r]?n[r]:void 0!==n.name?n.name:void 0!==n.id?n.id:`node-${i}`)}function XI(e){if(!e)return null;if("function"==typeof e){let t=e;return e=>t(e.data??e)}return t=>t.data?.[e]||t[e]||t.id}function GI(e="value"){let t="function"==typeof e?e:t=>t[e];return e=>{let i=t(e),r="string"==typeof i?Number(i):i;return Number.isFinite(r)&&r>0?r:0}}function VI(e){let t=new Map(e.map(e=>[e,0]));return e.map(e=>{let i=t.get(e),r=e;for(;i>0&&t.has(r);)r=`${e}__${i++}`;return t.set(e,i||1),t.set(r,1),r})}function HI(e){return Array.isArray(e.colorScheme)?e.colorScheme:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical:BI}function UI(e){return Array.isArray(e.colorScheme)&&e.colorScheme.length>0?e.colorScheme[0]:e.themeSemantic?.primary?e.themeSemantic.primary:e.themeCategorical&&e.themeCategorical.length>0?e.themeCategorical[0]:"#4d430c"}function KI(e,t,i){if(t.colorByDepth&&void 0!==e.depth){let i=HI(t);return i[e.depth%i.length]}return i||UI(t)}function ZI(e,t,i){return{fill:KI(e,t,i.fill),stroke:i.stroke||t.themeSemantic?.surface||"#fff",strokeWidth:i.strokeWidth??1,opacity:i.opacity,cursor:i.cursor}}function QI(e){return!e.__hierarchyNode?.children?.length}function JI(e,t,i,r,n,o){let a=[],s=[],l=[],c=i.treeOrientation||"vertical",u="radial"===c,d=r[0]/2,h=r[1]/2,{nodeSize:f}=i,p="number"==typeof f?f:5;for(let t of e){let e=t.x,r=t.y;u&&(e+=d,r+=h);let o=ZI(t,i,n(cI(t,"nodeStyle")));a.push({type:"circle",cx:e,cy:r,r:p,style:o,datum:t,id:t.id,label:t.id,depth:t.depth})}let g=i.edgeOpacity??.5;for(let e of t){let t="object"==typeof e.source?e.source:null,r="object"==typeof e.target?e.target:null;if(!t||!r)continue;let n=t.x,a=t.y,l=r.x,f=r.y;u&&(n+=d,a+=h,l+=d,f+=h);let p=iP(n,a,l,f,c),m=o(cI(e,"edgeStyle")),y={fill:"none",stroke:m.stroke||i.themeSemantic?.border||i.themeSemantic?.secondary||"#999",strokeWidth:m.strokeWidth??1.5,opacity:m.opacity??g,cursor:m.cursor};s.push({type:"curved",pathD:p,style:y,datum:e})}if(!1!==i.showLabels){let t=XI(i.nodeLabel);for(let i of e){let e=t?t(i):i.id;if(!e)continue;let r,n,o,a=i.x,s=i.y;if(u&&(a+=d,s+=h),u){let e=a-d,t=s-h,i=Math.sqrt(e*e+t*t);i>0?(r=a+e/i*10,n=s+t/i*10,o=e>=0?"start":"end"):(r=a,n=s-12,o="middle")}else"horizontal"===c?(QI(i)?(r=a+p+6,o="start"):(r=a-p-6,o="end"),n=s):(r=a,n=s+p+14,o="middle");l.push({x:r,y:n,text:String(e),anchor:o,baseline:"middle",fontSize:11,anchorPoint:[a,s]})}}return{sceneNodes:a,sceneEdges:s,labels:l}}function eP(e,t,i){let r=[],n=[];for(let n of e){let e=n.x1-n.x0,o=n.y1-n.y0;if(e<=0||o<=0)continue;let a=i(cI(n,"nodeStyle")),s=ZI(n,t,a);s.fillOpacity=a.fillOpacity,s.strokeOpacity=a.strokeOpacity,r.push({type:"rect",x:n.x0,y:n.y0,w:e,h:o,style:s,datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){let r=XI(t.nodeLabel),o=t.labelMode||"leaf",a="partition"===t.chartType;for(let s of e){let e=s.x1-s.x0,l=s.y1-s.y0;if(e<=0||l<=0)continue;let c=QI(s);if(!a&&("leaf"===o&&!c||"parent"===o&&c))continue;let u=r?r(s):s.id;if(!u)continue;if(e<(c?30:40)||l<(c?16:14))continue;let d=KI(s,t,i(cI(s,"nodeStyle")).fill),h="string"==typeof d?WI(d):t.themeSemantic?.text??"#000";c?n.push({x:s.x0+e/2,y:s.y0+l/2,text:String(u),anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,Math.min(e,l)/6)),fill:h}):n.push({x:s.x0+4,y:s.y0+12,text:String(u),anchor:"start",baseline:"auto",fontSize:11,fontWeight:600,fill:h})}}return{sceneNodes:r,sceneEdges:[],labels:n}}function tP(e,t,i){let r=[],n=[];for(let n of e){let e=n.__radius??5;if(e<=0)continue;let o=ZI(n,t,i(cI(n,"nodeStyle")));o.opacity??(o.opacity=.7),r.push({type:"circle",cx:n.x,cy:n.y,r:e,style:o,datum:n,id:n.id,label:n.id,depth:n.depth})}if(!1!==t.showLabels){let r=XI(t.nodeLabel);for(let o of e){let e=o.__radius??5,a=r?r(o):o.id;if(!a||e<15)continue;let s=QI(o),l=KI(o,t,i(cI(o,"nodeStyle")).fill);if(s){let i="string"==typeof l?WI(l):t.themeSemantic?.text??"#000";n.push({x:o.x,y:o.y,text:String(a),anchor:"middle",baseline:"middle",fontSize:Math.min(11,Math.max(8,e/3)),fill:i})}else n.push({x:o.x,y:o.y-e+14,text:String(a),anchor:"middle",baseline:"hanging",fontSize:Math.min(11,Math.max(8,e/3)),fill:t.themeSemantic?.text||"#000",stroke:t.themeSemantic?.surface||"#fff",strokeWidth:3,paintOrder:"stroke"})}}return{sceneNodes:r,sceneEdges:[],labels:n}}function iP(e,t,i,r,n){let o=(e+i)/2,a=(t+r)/2;return"horizontal"===n?`M ${e},${t} C ${o},${t} ${o},${r} ${i},${r}`:"radial"===n?`M ${e},${t} Q ${o},${t} ${o},${a} T ${i},${r}`:`M ${e},${t} C ${e},${a} ${i},${a} ${i},${r}`}var rP={supportsStreaming:!1,hierarchical:!0,computeLayout(e,t,i,r){let n=i.__hierarchyRoot;if(!n)return;let o=i.chartType,a=YI(i.childrenAccessor),s=TI(n,a),l=[];s.eachBefore(e=>l.push(e));let c=VI(l.map((e,t)=>qI(e,i,t)));s.sum(GI(i.hierarchySum)).sort((e,t)=>t.value-e.value);let[u,d]=r;switch(o){case"tree":case"cluster":nP(s,i,u,d);break;case"treemap":case"partition":oP(s,i,u,d);break;case"circlepack":aP(s,i,u,d)}let h=s.descendants();e.length=0,t.length=0;let f=new Map(l.map((e,t)=>[e,{id:c[t],x:0,y:0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:e.value,depth:e.depth,data:e.data,createdByFrame:!0}]));for(let t of h){let r=f.get(t);"tree"===o||"cluster"===o?sP(r,t,i):"treemap"===o||"partition"===o?lP(r,t):"circlepack"===o&&cP(r,t),r.__hierarchyNode=t,e.push(r)}if("tree"===o||"cluster"===o)for(let e of h)if(e.parent){let i=f.get(e.parent),r=f.get(e);t.push({source:i,target:r,value:1,y0:0,y1:0,sankeyWidth:0,data:{depth:e.depth}})}},buildScene(e,t,i,r){let n=i.chartType,o=i.nodeStyle||(()=>({})),a=i.edgeStyle||(()=>({}));switch(n){case"tree":case"cluster":return JI(e,t,i,r,o,a);case"treemap":case"partition":return eP(e,i,o);case"circlepack":return tP(e,i,o);default:return{sceneNodes:[],sceneEdges:[],labels:[]}}}};function nP(e,t,i,r){let n=t.treeOrientation||"vertical",o="cluster"===t.chartType?FI():NI();if("horizontal"===n)o.size([r,i]);else if("radial"===n){let e=Math.min(i,r)/2;o.size([2*Math.PI,.8*e])}else o.size([i,r]);o(e)}function oP(e,t,i,r){let n="treemap"===t.chartType,o=n?EI().tile(DI):zI();o.size([i,r]).padding(t.padding??(n?4:1)),"paddingTop"in o&&t.paddingTop>0&&o.paddingTop(t.paddingTop),o(e)}function aP(e,t,i,r){let n=t.padding??4,o=OI().size([i,r]).padding(n);e.leaves().some(e=>e.value)||o.radius(()=>0).padding(0),o(e)}function sP(e,t,i){let r=i.treeOrientation||"vertical";if("radial"===r){let i=t.x,r=t.y;e.x=r*Math.cos(i-Math.PI/2),e.y=r*Math.sin(i-Math.PI/2)}else"horizontal"===r?(e.x=t.y,e.y=t.x):(e.x=t.x,e.y=t.y);uP(e,5)}function lP(e,t){e.x0=t.x0,e.y0=t.y0,e.x1=e.value?t.x1:t.x0,e.y1=e.value?t.y1:t.y0,e.x=(e.x0+e.x1)/2,e.y=(e.y0+e.y1)/2,e.width=e.x1-e.x0,e.height=e.y1-e.y0}function cP(e,t){let i=t.r??0;e.x=t.x,e.y=t.y,uP(e,i),e.__radius=i}function uP(e,t){e.x0=e.x-t,e.x1=e.x+t,e.y0=e.y-t,e.y1=e.y+t,e.width=2*t,e.height=2*t}import{pie as dP}from"d3-shape";function hP(e){let t=e.__orbitState;return t||(t={metaMap:/* @__PURE__ */new Map,startTime:typeof performance<"u"?performance.now():Date.now()},e.__orbitState=t),t}function fP(e){if(Array.isArray(e))return e;switch(e){case"solar":return[1];case"atomic":return[2,8];default:return[9999]}}function pP(e){if("function"==typeof e)return e;let t=e||"name";return e=>String(e[t]??"")}function gP(e){switch(e){case"decay":return e=>Math.pow(.6,e.depth??0);case"alternate":return e=>{let t=e.depth??0;return(t%2==0?1:-1)/(t+1)};default:return e=>1/((e.depth??0)+1)}}function mP(e,t,i,r,n){let o=YI(i.childrenAccessor||"children"),a=pP(i.nodeIDAccessor),s=fP(i.orbitMode),l=i.orbitSize??2.95,c=i.orbitEccentricity??1,u="number"==typeof l?()=>l:l,d="number"==typeof c?()=>c:c,h=hP(i);h.metaMap.clear(),r.length=0,n.length=0;let f=VI(fM(e,o).map(e=>String(a(e)))),p=0,g=t[0]/2,m=t[1]/2,y=Math.min(t[0],t[1])/2*.85,x=f[p++],b={id:x,x:g,y:m,x0:g,x1:g,y0:m,y1:m,width:0,height:0,value:0,depth:0,data:e};r.push(b),h.metaMap.set(x,{ring:y,angle:0,depth:0,parentId:null,eccentricity:1}),function e(t,i,a,l,c,g,m){let y=o(t);if(!y?.length)return;let x=y.length,b=0,v=0,w=0;for(;v<x;)v+=s[Math.min(w,s.length-1)],w++,b++;let k=0;for(let x=0;x<b;x++){let v=s[Math.min(x,s.length-1)],w=y.slice(k,k+v);if(!w.length)break;let S=(x+1)/b,A={id:i,depth:g,data:t,parentId:i},M=m?c/u(A)*S:c*S,$=dP().value(e=>o(e)?.length?4:1).sort(null)(w),_=d(A);for(let t=0;t<w.length;t++){let o=($[t].startAngle+$[t].endAngle)/2,s=w[t],c=f[p++],u=a+M*Math.sin(o),d=l+M*Math.cos(o)*_,m={id:c,x:u,y:d,x0:u,x1:u,y0:d,y1:d,width:0,height:0,value:0,depth:g,data:s};r.push(m),h.metaMap.set(c,{ring:M,angle:o,depth:g,parentId:i,eccentricity:_}),n.push({source:i,target:c,value:1,y0:0,y1:0,sankeyWidth:0,data:{source:i,target:c}}),e(s,c,u,d,M,g+1,!0)}k+=v}}(e,x,g,m,y,1,!1)}function yP(e,t,i,r){let n=hP(t),o=t.orbitSpeed??.25,a=t.orbitRevolution??gP(t.orbitRevolutionStyle),s=((typeof performance<"u"?performance.now():Date.now())-n.startTime)/1e3,l=o*(Math.PI/6),c=/* @__PURE__ */new Map;for(let t of e)c.set(t.id,t);for(let t of e){let e=n.metaMap.get(t.id);if(!e||!e.parentId)continue;let i=c.get(e.parentId);if(!i)continue;let r={id:t.id,depth:e.depth,data:t.data,parentId:e.parentId},o=e.angle+s*l*a(r);t.x=i.x+e.ring*Math.sin(o),t.y=i.y+e.ring*Math.cos(o)*e.eccentricity,t.x0=t.x,t.x1=t.x,t.y0=t.y,t.y1=t.y}}var xP={supportsStreaming:!1,hierarchical:!0,supportsAnimation:!0,computeLayout(e,t,i,r){let n=i.__hierarchyRoot;n&&mP(n,r,i,e,t)},buildScene(e,t,i,r){let n=i.nodeStyle,o=i.edgeStyle,a=i.nodeSize,s="number"==typeof a?()=>a:"function"==typeof a?a:()=>6,l=[],c=[],u=[];if(!1!==i.orbitShowRings){let t=hP(i),r=/* @__PURE__ */new Map;for(let t of e)r.set(t.id,t);let n=/* @__PURE__ */new Map;for(let[,e]of t.metaMap){if(!e.parentId)continue;let t=r.get(e.parentId);if(!t)continue;let i=`${e.parentId}:${e.ring}`;n.has(i)||n.set(i,{parentX:t.x,parentY:t.y,ring:e.ring,ecc:e.eccentricity})}let o=48,a={stroke:"rgba(128,128,128,0.35)",strokeWidth:.5,opacity:1};for(let[,{parentX:e,parentY:t,ring:i,ecc:r}]of n)for(let n=0;n<o;n++){let s=n/o*Math.PI*2,l=(n+1)/o*Math.PI*2;c.push({type:"line",x1:e+i*Math.sin(s),y1:t+i*Math.cos(s)*r,x2:e+i*Math.sin(l),y2:t+i*Math.cos(l)*r,style:a,datum:null})}}for(let t of e){if(null==t.x||null==t.y)continue;let e=s(cI(t,"nodeSize")),r=n?n(cI(t,"nodeStyle")):{},o={fill:r.fill||i.themeSemantic?.primary||"#6366f1",stroke:r.stroke||i.themeSemantic?.surface||"#fff",strokeWidth:r.strokeWidth??1,opacity:r.opacity??(0===(t.depth??0)?1:.85),cursor:r.cursor};l.push({type:"circle",cx:t.x,cy:t.y,r:e,style:o,datum:t,id:t.id,label:t.id,depth:t.depth})}let d=/* @__PURE__ */new Map;for(let t of e)d.set(t.id,t);for(let e of t){let t="object"==typeof e.source?e.source:d.get(e.source),i="object"==typeof e.target?e.target:d.get(e.target);if(!t||!i||null==t.x||null==i.x)continue;let r=o?o(cI(e,"edgeStyle")):{},n={stroke:r.stroke||"rgba(128,128,128,0.35)",strokeWidth:r.strokeWidth??.5,opacity:r.opacity??1,cursor:r.cursor};c.push({type:"line",x1:t.x,y1:t.y,x2:i.x,y2:i.y,style:n,datum:e})}if(i.showLabels){let t=i.nodeLabel;for(let i of e){let e=s(cI(i,"nodeSize"));if(e<=4)continue;let r="function"==typeof t?t(i):t?i.data?.[t]??i.id:i.id;u.push({x:i.x,y:i.y+e+12,text:String(r),anchor:"middle",fontSize:10,fill:"currentColor",anchorPoint:[i.x,i.y]})}}return{sceneNodes:l,sceneEdges:c,labels:u}},tick:(e,t,i,r,n)=>!1!==i.orbitAnimated&&(yP(e,i),!0)};import*as bP from"react";import{arc as vP}from"d3-shape";import{jsx as wP,jsxs as kP}from"react/jsx-runtime";function SP(e,t){let i=e.style.fill;return(e.style.opacity??1)<=0||(e.style.fillOpacity??1)<=0||"string"==typeof i&&/^\s*(none|transparent)\s*$|^rgba\(.*,\s*0(\.0+)?\s*\)$|^#[\da-f]{3}0$|^#[\da-f]{6}00$/i.test(i)?null:e.faces?.map((i,r)=>/* @__PURE__ */wP("path",{d:i.pathD,fill:"string"==typeof e.style.fill?o(e.style.fill,i.shade):t,fillOpacity:e.style.fillOpacity,opacity:e.style.opacity},`face-${r}`))}function AP(e,t){return Ol(MP(e,t),e,`network-node-cursor-${t}`)}function MP(e,t){switch(e.type){case"circle":{let i=e,r=el(i.style.fill)?rl(i.style.fill,`net-circle-${t}-hatch`):void 0,n={fill:r?`url(#net-circle-${t}-hatch)`:Ml(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity};/* @__PURE__ */
349
- return kP(bP.Fragment,{children:[r&&/* @__PURE__ */wP("defs",{children:r}),i.pathD&&SP(i,n.fill),i.pathD?/* @__PURE__ */wP("path",{d:i.pathD,...n}):/* @__PURE__ */wP("circle",{cx:i.cx,cy:i.cy,r:i.r,...n})]},`net-circle-${t}`)}case"rect":{let i=e,r=el(i.style.fill)?rl(i.style.fill,`net-rect-${t}-hatch`):void 0,n={fill:r?`url(#net-rect-${t}-hatch)`:Ml(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity};/* @__PURE__ */
350
- return kP(bP.Fragment,{children:[r&&/* @__PURE__ */wP("defs",{children:r}),i.pathD&&SP(i,n.fill),i.pathD?/* @__PURE__ */wP("path",{d:i.pathD,...n}):/* @__PURE__ */wP("rect",{x:i.x,y:i.y,width:i.w,height:i.h,...n})]},`net-rect-${t}`)}case"arc":{let i=e,r=i.pathD?"":vP().innerRadius(i.innerR).outerRadius(i.outerR).startAngle(i.startAngle+Math.PI/2).endAngle(i.endAngle+Math.PI/2)(Al)||"",n=el(i.style.fill)?rl(i.style.fill,`net-arc-${t}-hatch`):void 0;/* @__PURE__ */
351
- return kP(bP.Fragment,{children:[n&&/* @__PURE__ */wP("defs",{children:n}),i.pathD&&SP(i,n?`url(#net-arc-${t}-hatch)`:Ml(i.style.fill)),
352
- /* @__PURE__ */wP("path",{d:i.pathD??r,transform:i.pathD?void 0:`translate(${i.cx},${i.cy})`,fill:n?`url(#net-arc-${t}-hatch)`:Ml(i.style.fill),stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity})]},`net-arc-${t}`)}case"symbol":{let i=e,r=s(i.symbolType,i.size,i.path),n=i.rotation?`translate(${i.cx},${i.cy}) rotate(${180*i.rotation/Math.PI})`:`translate(${i.cx},${i.cy})`,o=/* @__PURE__ */wP("path",{d:r,transform:n,fill:i.style.fill?Ml(i.style.fill):"none",stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,fillOpacity:i.style.fillOpacity,strokeOpacity:i.style.strokeOpacity,opacity:i.style.opacity},`net-symbol-${t}`);return i.faces?.length?/* @__PURE__ */kP(bP.Fragment,{children:[SP(i,i.style.fill?Ml(i.style.fill):void 0),o]},`net-symbol-${t}`):o}case"glyph":{let i=e;return _l(i,i.cx,i.cy,`net-glyph-${i.id??t}`)}default:return null}}function $P(e,t){return Ol(_P(e,t),e,`network-edge-cursor-${t}`)}function _P(e,t){switch(e.type){case"line":{let i=e;/* @__PURE__ */
353
- return wP("line",{x1:i.x1,y1:i.y1,x2:i.x2,y2:i.y2,stroke:i.style.stroke||"#999",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity},`net-edge-${t}`)}case"bezier":{let i=e,r=`net-bezier-${t}-hatch`,n=el(i.style.fill)?rl(i.style.fill,r):void 0;/* @__PURE__ */
354
- return kP(bP.Fragment,{children:[n&&/* @__PURE__ */wP("defs",{children:n}),
355
- /* @__PURE__ */wP("path",{d:i.pathD,fill:n?`url(#${r})`:Ml(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity})]},`net-edge-${t}`)}case"ribbon":{let i=e,r=`net-ribbon-${t}-hatch`,n=el(i.style.fill)?rl(i.style.fill,r):void 0;/* @__PURE__ */
356
- return kP(bP.Fragment,{children:[n&&/* @__PURE__ */wP("defs",{children:n}),
357
- /* @__PURE__ */wP("path",{d:i.pathD,fill:n?`url(#${r})`:Ml(i.style.fill,"#999"),fillOpacity:i.style.fillOpacity,stroke:i.style.stroke||"none",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity})]},`net-edge-${t}`)}case"curved":{let i=e;/* @__PURE__ */
358
- return wP("path",{d:i.pathD,fill:Ml(i.style.fill,"none"),fillOpacity:i.style.fill&&"none"!==i.style.fill?i.style.fillOpacity??.1:void 0,stroke:i.style.stroke||"#999",strokeOpacity:i.style.strokeOpacity,strokeWidth:i.style.strokeWidth??1,strokeDasharray:i.style.strokeDasharray,strokeLinecap:i.style.strokeLinecap,opacity:i.style.opacity},`net-edge-${t}`)}default:return null}}function IP(e,t,i="middle",r="auto"){/* @__PURE__ */
359
- return wP("text",{x:e.x,y:e.y,textAnchor:e.anchor||i,dominantBaseline:e.baseline||r,fontSize:e.fontSize||11,fontWeight:e.fontWeight,fill:e.fill||"var(--semiotic-text, #333)",stroke:e.stroke,strokeWidth:e.strokeWidth,paintOrder:e.paintOrder,transform:e.rotate?`rotate(${Math.round(180*e.rotate/Math.PI*100)/100} ${e.x} ${e.y})`:void 0,style:{pointerEvents:"none"},children:e.text},`net-label-${t}`)}function PP(e){let t=e.id??e.datum?.id??e.datum?.data?.id??e.datum?.data?.name;return null==t?void 0:String(t)}function LP(e){if("glyph"===e.type&&e.glyph&&"number"==typeof e.size){let t=e.cx??e.x,i=e.cy??e.y;if("number"!=typeof t||"number"!=typeof i)return null;let r=f(e.glyph,e.size);return{x:t+r.centerDx,y:i+r.centerDy,r:Math.max(1,r.radius)}}let t=e.cx??(null!=e.x&&null!=e.w?e.x+e.w/2:e.x),i=e.cy??(null!=e.y&&null!=e.h?e.y+e.h/2:e.y);return"number"!=typeof t||"number"!=typeof i?null:{x:t,y:i,r:"number"==typeof e.r?Math.max(1,e.r):"number"==typeof e.outerR?Math.max(1,e.outerR):"number"==typeof e.size?Math.max(1,l(e.size)):Math.max(1,e.w??0,e.h??0)/2}}function RP(e){if(!e)return;let t=[];for(let i of e){let e=LP(i);e&&t.push({pointId:PP(i),...e})}return t}import{Fragment as CP,jsx as TP}from"react/jsx-runtime";var NP={x:0,y:0,k:1};function FP(e){return e&&Number.isFinite(e.k)&&e.k>0&&Number.isFinite(e.x)&&Number.isFinite(e.y)?e:NP}function EP({view:e,width:t,height:i,children:r}){if(!e)/* @__PURE__ */return TP(CP,{children:r});let{x:n,y:o,k:a}=FP(e);/* @__PURE__ */
360
- return TP("svg",{width:t,height:i,overflow:"hidden","data-network-view":"",children:/* @__PURE__ */TP("g",{transform:`translate(${n},${o}) scale(${a})`,children:r})})}function OP(e,t,i){return"function"==typeof t?t(e):e[t??i]}function zP(e){let t=null==e?NaN:Number(e);return Number.isFinite(t)?t:1}function DP(e,t){return null!=e?String(e):("production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Missing network ${t} ID; skipping this datum.`),null)}function BP(e,t){let i=DP(OP(e,t.sourceAccessor,"source"),"source"),r=DP(OP(e,t.targetAccessor,"target"),"target");return null===i||null===r?null:{source:i,target:r,value:zP(OP(e,t.valueAccessor,"value")),data:e}}function jP(e,t,i){let r=/* @__PURE__ */new Map;for(let t of e){let e=DP(OP(t,i.nodeIDAccessor,"id"),"node");null!==e&&(r.has(e)&&"production"!==process.env.NODE_ENV&&console.warn(`[Semiotic] Duplicate network node ID "${e}"; using the last datum.`),r.set(e,t))}let n=[];return t.forEach((e,t)=>{let o=BP(e,i);if(o){for(let e of[o.source,o.target])r.has(e)||r.set(e,{id:e});n.push({...o,_edgeKey:`${o.source}\0${o.target}\0${t}`})}}),{nodes:r,edges:n}}import{Fragment as WP,jsx as YP,jsxs as qP}from"react/jsx-runtime";function XP(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function GP([e,t]){return{id:e,x:t.x??0,y:t.y??0,x0:0,x1:0,y0:0,y1:0,width:0,height:0,value:0,data:t,createdByFrame:!0}}function VP(e){return{...e,y0:0,y1:0,sankeyWidth:0}}m(a),J$("sankey",dI),J$("force",SI),J$("chord",RI),J$("tree",rP),J$("cluster",rP),J$("treemap",rP),J$("circlepack",rP),J$("partition",rP),J$("orbit",xP);var HP=/* @__PURE__ */new Set(["tree","cluster","treemap","circlepack","partition","orbit"]);function UP(e){return e.map(e=>{let t=e.datum&&"object"==typeof e.datum?e.datum:{},i=t.data&&"object"==typeof t.data?t.data:t,r="cx"in e?e.cx:e.x+e.w/2,n="cy"in e?e.cy:e.y+e.h/2;return{...i,...null==i.id&&null!=e.id?{id:e.id}:{},x:r,y:n}})}function KP(e,t){let i=M(e.theme),r=e.chartType||"force",n=e.size||[500,500],o=N({...Lh(r),...e.margin},e.title),a=C(e.title),s=e.showLegend?(()=>{let t="string"==typeof(i=e.colorBy)||"function"==typeof i?e.colorBy:void 0;var i;if(!t)return[];let n=ei(e.nodes||[]);if(n.length>0)return pc(n,t);if(HP.has(r)&&e.data)return pc(fM(e.data,e.childrenAccessor||"children"),t);let o=Array.isArray(e.edges)?ei(e.edges):[];if(0===o.length)return[];let a=XP(e.sourceAccessor,"source"),s=XP(e.targetAccessor,"target"),l=Array.from(new Set(o.flatMap(e=>[a(e),s(e)]).filter(e=>null!=e).map(String)));return pc(l.map(e=>({id:e})),t)})():[];ch(o,{props:e,categories:s,theme:i,size:n,hasTitle:a});let l,c=uh({props:e,categories:s,theme:i,size:n,margin:o,hasTitle:a}),u=Math.max(1,n[0]-o.left-o.right),d=Math.max(1,n[1]-o.top-o.bottom),h=Mh(e.backgroundGraphics,n,o,null),f=Mh(e.foregroundGraphics,n,o,null),m=(r,a=[],s=[])=>(t&&(t.evidence=Vs({frameType:"network",width:n[0],height:n[1],marks:[...a.map(({node:e})=>({type:`node:${e.type??"node"}`})),...s.map(({node:e})=>({type:`edge:${e.type??"edge"}`}))],title:e.title,description:e.description,annotations:e.annotations,annotationRender:l,nodeCount:a.length,edgeCount:s.length,margin:o})),Z$.renderToStaticMarkup(hh(/* @__PURE__ */YP(EP,{view:e.viewTransform,width:u,height:d,children:r}),{width:n[0],height:n[1],className:"stream-network-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${o.left},${o.top})`,innerWidth:u,innerHeight:d,legend:c,idPrefix:e._idPrefix}))),y=t=>{let r=e=>Number(e);return e.annotations?Id({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{x:r,y:r},layout:{width:u,height:d},theme:i,frameType:"network",annotationData:t&&UP(t),pointNodes:t&&RP(t),idPrefix:e._idPrefix,onRender:e=>{l=e}}):null},x=()=>{let t=y(),i=h||f||e.annotations?/* @__PURE__ */qP(WP,{children:[h,t,f]}):null;return m(i)},b=e_(r);if(!b&&!e.customNetworkLayout)throw new Error(`No layout plugin found for chart type: "${r}". Supported types: force, sankey, chord, tree, cluster, treemap, circlepack, partition, orbit.`);let v,k,S={chartType:r,nodeIDAccessor:e.nodeIDAccessor,sourceAccessor:e.sourceAccessor,targetAccessor:e.targetAccessor,valueAccessor:e.valueAccessor,childrenAccessor:e.childrenAccessor,hierarchySum:e.hierarchySum,orientation:e.orientation,nodeAlign:e.nodeAlign,nodePaddingRatio:e.nodePaddingRatio,nodeWidth:e.nodeWidth,iterations:e.iterations,forceStrength:e.forceStrength,padAngle:e.padAngle,groupWidth:e.groupWidth,sortGroups:e.sortGroups,edgeSort:e.edgeSort,treeOrientation:e.treeOrientation,edgeType:e.edgeType,padding:e.padding,paddingTop:e.paddingTop,nodeStyle:e.nodeStyle,edgeStyle:e.edgeStyle,nodeLabel:e.nodeLabel,showLabels:e.showLabels,labelMode:e.labelMode,colorBy:e.colorBy,colorScheme:e.colorScheme||i.colors.categorical,edgeColorBy:e.edgeColorBy,edgeOpacity:e.edgeOpacity,colorByDepth:e.colorByDepth,nodeSize:e.nodeSize,nodeSizeRange:e.nodeSizeRange,orbitMode:e.orbitMode,orbitSize:e.orbitSize,orbitSpeed:e.orbitSpeed,orbitRevolution:e.orbitRevolution,orbitRevolutionStyle:e.orbitRevolutionStyle,orbitEccentricity:e.orbitEccentricity,orbitShowRings:e.orbitShowRings,orbitAnimated:!1,customNetworkLayout:e.customNetworkLayout,layoutConfig:e.layoutConfig,perspective:e.perspective},A=p(e.perspective);if(HP.has(r)){let t=e.data||e.edges;if(!t||Array.isArray(t))return x();S.__hierarchyRoot=t,v=[],k=[]}else{let t=ei(e.nodes||[]),i=Array.isArray(e.edges)?ei(e.edges):[];if(0===t.length&&0===i.length)return x();let r=jP(t,i,S);v=Array.from(r.nodes,GP),k=r.edges.map(VP)}let _,I,P=[],L=[],R=[],T=null,F=null;if(S.customNetworkLayout){let t=S.colorScheme,r=Ix(t,i.colors.categorical,oi),n=Px(r,t),o={nodes:v,edges:k,dimensions:{width:u,height:d,plot:{x:0,y:0,width:u,height:d}},theme:{semantic:i.colors,categorical:[...r]},resolveColor:n,config:S.layoutConfig??{},selection:e.layoutSelection??null,perspective:A?.config??null},a=S.customNetworkLayout(o);_=a.perspective,P=a.sceneNodes??[],L=a.sceneEdges??[],K$({nodes:P,edges:L,restyle:a.restyle,restyleEdge:a.restyleEdge,selection:e.layoutSelection??null,baseStyles:/* @__PURE__ */new WeakMap}),R=a.labels??[],T=a.backgrounds??null,F=a.overlays??null,I=a.perspectiveBounds}else if(b){b.computeLayout(v,k,S,[u,d]);let e=b.buildScene(v,k,S,[u,d]);P=e.sceneNodes,L=e.sceneEdges,R=e.labels}let E=[],O=A?(()=>{let e=g({sceneNodes:P,sceneEdges:L,labels:R,bounds:I,size:[u,d],perspective:A,chartType:r,theme:w(i)});return P=e.sceneNodes,L=e.sceneEdges,R=e.labels,E=e.underlay,e.frame})():null,z=$(i);for(let e of R)e.fill||(e.fill=z.text);let D=Zl({nodes:L,renderMode:e.renderMode,fallback:(e,t)=>$P(e,t)}),B=Zl({nodes:P,renderMode:e.renderMode,fallback:(e,t)=>AP(e,t)}),j=D.map(e=>e.element),W=B.map(e=>e.element),Y=R.map((e,t)=>IP(e,t)).filter(Boolean),q=y(P),X=/* @__PURE__ */qP(WP,{children:[h,ck(T,O,_),E.map((e,t)=>$P(e,t)),j,W,Y,q,ck(f,O),ck(F,O,_)]});return m(X,B,D)}import*as ZP from"react-dom/server";import{geoPath as QP}from"d3-geo";import{quadtree as JP}from"d3-quadtree";import{geoMercator as eL,geoEqualEarth as tL,geoAlbersUsa as iL,geoOrthographic as rL,geoNaturalEarth1 as nL,geoEquirectangular as oL}from"d3-geo";var aL={mercator:eL,equalEarth:tL,albersUsa:iL,orthographic:rL,naturalEarth:nL,equirectangular:oL};function sL(e){if(!e)return tL();if("string"==typeof e){let t=aL[e];return t?t():("production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Unknown projection "${e}", falling back to equalEarth`),tL())}if("object"==typeof e&&"type"in e){let t=aL[e.type],i=t?t():tL();return e.rotate&&"rotate"in i&&i.rotate(e.rotate),e.center&&"center"in i&&i.center(e.center),i}return e}function lL(e,t){return e?"function"==typeof e?e:t=>t[e]:e=>e[t]}function cL(e){return e?"function"==typeof e?e:t=>t[e]:e=>e.coordinates||e.data||[]}function uL(e,t,i){return e?"function"==typeof e?{...i,...e(t)}:{...i,...e}:{...i}}function dL(e){return{fill:e.themeSemantic?.surface||"#e0e0e0",stroke:e.themeSemantic?.border||"#999",strokeWidth:.5,fillOpacity:1}}function hL(e){return{fill:e.themeSemantic?.primary||"#4e79a7",r:4,fillOpacity:.8}}function fL(e){return{stroke:e.themeSemantic?.primary||"#4e79a7",strokeWidth:1.5,fill:"none"}}function pL(e,t){if(e.length<2)return[e];let i=.4*t,r=[],n=[e[0]];for(let t=1;t<e.length;t++){let o=e[t-1],a=e[t];Math.abs(a[0]-o[0])>i?(n.length>=2&&r.push(n),n=[a]):n.push(a)}return n.length>=2&&r.push(n),r}function gL(e,t,i=24){let r=t[0]-e[0],n=t[1]-e[1],o=Math.sqrt(r*r+n*n);if(0===o)return[e,t];let a=-n/o,s=r/o,l=Math.min(.3*o,80),c=(e[0]+t[0])/2+a*l,u=(e[1]+t[1])/2+s*l,d=[];for(let r=0;r<=i;r++){let n=r/i,o=1-n,a=o*o*e[0]+2*o*n*c+n*n*t[0],s=o*o*e[1]+2*o*n*u+n*n*t[1];d.push([a,s])}return d}function mL(e,t){if(e.length<2)return e;let i=t/2+1,r=[];for(let t=0;t<e.length;t++){let n,o,a=e[t];0===t?(n=e[1][0]-a[0],o=e[1][1]-a[1]):t===e.length-1?(n=a[0]-e[t-1][0],o=a[1]-e[t-1][1]):(n=e[t+1][0]-e[t-1][0],o=e[t+1][1]-e[t-1][1]);let s=Math.sqrt(n*n+o*o)||1,l=o/s,c=-n/s;r.push([a[0]+l*i,a[1]+c*i])}return r}function yL(e,t,i,r,n){let o=t[0]-e[0],a=t[1]-e[1],s=Math.sqrt(o*o+a*a);if(0===s)return[e,t];let l=a/s,c=-o/s,u=n/2+1;return[[e[0]+l*u,e[1]+c*u],[t[0]+l*u,t[1]+c*u]]}import{scaleLinear as xL}from"d3-scale";function bL(e,t,i,r){let n=e.filter(e=>"point"===e.type);if(n.length<2)return null;let o=t.strength??1,a=Number.isFinite(o)?Math.max(0,Math.min(1,o)):1,s="strip"===t.layout?"strip":"radial";if("radial"===s&&0===a)return null;let l=t.centerAccessor?"function"==typeof t.centerAccessor?t.centerAccessor:e=>e[t.centerAccessor]:e=>e.id,c="function"==typeof t.costAccessor?t.costAccessor:e=>e[t.costAccessor],u=n.find(e=>e.datum&&String(l(e.datum))===String(t.center));if(!u)return"production"!==process.env.NODE_ENV&&console.warn(`GeoFrame: Distance cartogram center "${t.center}" not found in point data`),null;let d=br(n.map(e=>e.datum?Number(c(e.datum)):NaN).filter(e=>isFinite(e)&&e>=0),1);r>0&&"production"!==process.env.NODE_ENV&&console.warn("GeoFrame: Distance cartogram does not support area rendering. Areas will be ignored. Remove areas or set projectionTransform to null to render them.");for(let t=e.length-1;t>=0;t--){let i=e[t];"geoarea"===i.type&&i.interactive&&e.splice(t,1)}let h="strip"===s?wL(n,u,c,d,i):vL(n,u,c,d,a,i),f=e.filter(e=>"line"===e.type);if(f.length>0){let e=/* @__PURE__ */new Map;for(let t of n)null!=t.pointId&&e.set(String(t.pointId),[t.x,t.y]);for(let i of f){let r=i.datum?.source,n=i.datum?.target;if(null!=r&&null!=n){let o=e.get(String(r)),a=e.get(String(n));if(o&&a)if("fractional"===t.lineMode&&i.path.length>2){let e=i.path[0],t=i.path[i.path.length-1],r=[o[0]-e[0],o[1]-e[1]],n=[a[0]-t[0],a[1]-t[1]],s=[0];for(let e=1;e<i.path.length;e++)s.push(s[e-1]+Math.hypot(i.path[e][0]-i.path[e-1][0],i.path[e][1]-i.path[e-1][1]));let l=s[s.length-1];i.path=i.path.map((e,t)=>{let o=l>0?s[t]/l:t/(i.path.length-1);return[e[0]+r[0]*(1-o)+n[0]*o,e[1]+r[1]*(1-o)+n[1]*o]})}else i.path=[o,a]}}}return h}function vL(e,t,i,r,n,o){let a=t.x,s=t.y,l=o.width/2,c=o.height/2,u=Math.min(o.width,o.height)/2,d=xL().domain([0,r]).range([0,u]);for(let o of e){if(o===t||!o.datum)continue;let e=o.x,u=o.y,h=Math.atan2(u-s,e-a),f=Math.hypot(e-a,u-s),p=Number(i(o.datum)),g=isFinite(p)&&p>=0?r>0?d(p):0:f,m=l+Math.cos(h)*g,y=c+Math.sin(h)*g;o.x=e+(m-e)*n,o.y=u+(y-u)*n}return t.x=a+(l-a)*n,t.y=s+(c-s)*n,{cx:t.x,cy:t.y,maxCost:r,availableRadius:u,layout:"radial"}}function wL(e,t,i,r,n){let o=Math.max(3,Math.min(8,.35*n.height)),a=Math.max(1,n.width-2*o),s=n.height/2,l=xL().domain([0,r]).range([0,a]);t.x=o,t.y=s;let c=[];for(let n of e){if(n===t)continue;if(!n.datum){n.x=o,n.y=s;continue}let e=Number(i(n.datum)),a=o+(isFinite(e)&&e>=0&&r>0?l(e):0);n.x=a,n.y=s,c.push({node:n,x:a})}c.sort((e,t)=>e.x-t.x);let u=Math.max(0,Math.min(n.height/2-1,6)),d=0;for(;d<c.length;){let e=d+1;for(;e<c.length&&Math.abs(c[e].x-c[d].x)<3;)e++;let t=e-d;if(t>1&&u>0)for(let e=0;e<t;e++){let i=e-(t-1)/2,r=Math.min(2.5,2*u/Math.max(1,t-1));c[d+e].node.y=s+i*r}d=e}return{cx:o,cy:s,maxCost:r,availableRadius:a,layout:"strip"}}var kL=["data","domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],SL=["scene-style","data-paint","accessibility","evidence"],AL=(e,t)=>({retainedData:e,invalidations:t}),ML=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],$L=["domain","layout","scene-geometry","data-paint","overlay","accessibility","evidence"],_L=["scene-geometry","data-paint","accessibility","evidence"],IL=["scene-style","data-paint","accessibility","evidence"],PL=["scene-geometry","scene-style","data-paint","accessibility","evidence"],LL=["overlay","accessibility","evidence"],RL=[],CL={xAccessor:/* @__PURE__ */AL("rebuild",ML),yAccessor:/* @__PURE__ */AL("rebuild",ML),lineDataAccessor:/* @__PURE__ */AL("rebuild",ML),pointIdAccessor:/* @__PURE__ */AL("rebuild",_L),lineIdAccessor:/* @__PURE__ */AL("rebuild",_L),windowSize:/* @__PURE__ */AL("rebuild",ML),projection:/* @__PURE__ */AL("preserve",$L),projectionExtent:/* @__PURE__ */AL("preserve",$L),fitPadding:/* @__PURE__ */AL("preserve",$L),lineType:/* @__PURE__ */AL("preserve",$L),flowStyle:/* @__PURE__ */AL("preserve",$L),graticule:/* @__PURE__ */AL("preserve",$L),projectionTransform:/* @__PURE__ */AL("preserve",$L),customLayout:/* @__PURE__ */AL("preserve",$L),layoutConfig:/* @__PURE__ */AL("preserve",$L),layoutMargin:/* @__PURE__ */AL("preserve",$L),areaStyle:/* @__PURE__ */AL("preserve",IL),pointStyle:/* @__PURE__ */AL("preserve",PL),lineStyle:/* @__PURE__ */AL("preserve",IL),colorScheme:/* @__PURE__ */AL("preserve",IL),themeCategorical:/* @__PURE__ */AL("preserve",IL),themeDiverging:/* @__PURE__ */AL("preserve",IL),themeSemantic:/* @__PURE__ */AL("preserve",IL),themeSequential:/* @__PURE__ */AL("preserve",IL),decay:/* @__PURE__ */AL("preserve",IL),pulse:/* @__PURE__ */AL("preserve",IL),layoutSelection:/* @__PURE__ */AL("preserve",IL),annotations:/* @__PURE__ */AL("preserve",LL),autoPlaceAnnotations:/* @__PURE__ */AL("preserve",LL),clock:/* @__PURE__ */AL("preserve",RL),transition:/* @__PURE__ */AL("preserve",RL),introAnimation:/* @__PURE__ */AL("preserve",RL),onLayoutError:/* @__PURE__ */AL("preserve",RL)},TL=/* @__PURE__ */AL("preserve",$L);function NL(e){let t="preserve",i=/* @__PURE__ */new Set;for(let r of e){let e=CL[r]??TL;"rebuild"===e.retainedData&&(t="rebuild");for(let t of e.invalidations)i.add(t)}return{retainedData:t,invalidations:i}}var FL=class{constructor(){this.tracker=new is}get last(){return this.tracker.last}subscribe(e){return this.tracker.subscribe(e)}recordData(e,t){return this.tracker.record({kind:e,...void 0===t?{}:{count:t}},kL)}recordNoop(e){return this.tracker.record({kind:e,..."restyle"===e?{}:{count:0}},[])}recordRestyle(e){return e?this.tracker.record({kind:"restyle"},SL):this.recordNoop("restyle")}recordConfig(e,t={}){let i=NL(e),r=new Set(i.invalidations);return t.retainedDataChanged&&r.add("data"),this.tracker.record({kind:"config",keys:e},r)}};import{geoDistance as EL,geoGraticule as OL,geoInterpolate as zL}from"d3-geo";function DL({config:e,projection:t,path:i,areas:r,points:n,lines:o,layout:a}){let s=lL(e.xAccessor,"lon"),l=lL(e.yAccessor,"lat"),c=[],u=dL(e),d=fL(e),h=hL(e);if(e.graticule){let t=!0===e.graticule?{}:e.graticule,r=OL();t.step&&r.step(t.step);let n=i(r())||"";n&&c.push({type:"geoarea",pathData:n,centroid:[a.width/2,a.height/2],bounds:[[0,0],[a.width,a.height]],screenArea:0,style:{fill:"none",stroke:t.stroke||"#e0e0e0",strokeWidth:t.strokeWidth??.5,strokeDasharray:t.strokeDasharray||"2,2"},datum:null,interactive:!1})}for(let t of r){let r=i(t);if(!r)continue;let n=i.centroid(t),o=i.bounds(t),a=i.area(t);c.push({type:"geoarea",pathData:r,centroid:n,bounds:o,screenArea:a,style:uL(e.areaStyle,t,u),datum:t,interactive:!0})}let f=cL(e.lineDataAccessor);for(let i of o){let r=f(i);if(!r||r.length<2)continue;let n=[];if("geo"===e.lineType){let e=new Array(r.length);for(let t=0;t<r.length;t++)e[t]=[s(r[t]),l(r[t])];for(let i=0;i<e.length-1;i++){let r=e[i],o=e[i+1],a=EL(r,o)||0,s=Math.max(2,Math.ceil(a/(Math.PI/180))),l=zL(r,o);for(let e=0;e<=s;e++){if(i>0&&0===e)continue;let r=t(l(e/s));null!=r&&n.push(r)}}}else for(let e=0;e<r.length;e++){let i=r[e],o=t([s(i),l(i)]);null!=o&&n.push(o)}if(n.length<2)continue;let o=uL(e.lineStyle,i,d),u="number"==typeof o.strokeWidth?o.strokeWidth:1;2===r.length&&n.length>=2&&"arc"===e.flowStyle?n=gL(n[0],n[n.length-1]):2===r.length&&n.length>=2&&"offset"===e.flowStyle&&(n="geo"===e.lineType?mL(n,u):yL(n[0],n[n.length-1],0,0,u));let h=pL(n,a.width);if(h.length<=1)c.push({type:"line",path:n.length>=2?n:h[0]||n,style:o,datum:i});else for(let e of h)e.length<2||c.push({type:"line",path:e,style:{...o,_edgeFade:!0},datum:i})}let p=e.pointIdAccessor?"function"==typeof e.pointIdAccessor?e.pointIdAccessor:t=>t[e.pointIdAccessor]:null,g=t.clipAngle?t.clipAngle()??0:0,m=g>0?g*Math.PI/180:null,y=t.rotate?t.rotate():[0,0,0],x="function"==typeof t.center?t.center():[0,0],b=[(x[0]??0)-y[0],(x[1]??0)-y[1]];for(let i of n){let r=s(i),n=l(i);if(null!=m&&EL([r,n],b)>m)continue;let o=t([r,n]);if(!o)continue;let a=e.pointStyle?e.pointStyle(i):{...h},u={type:"point",x:o[0],y:o[1],r:a.r||4,style:a,datum:i,pointId:p?String(p(i)):void 0};c.push(u)}return c}function BL(e){if(null==e)return 0;if("number"==typeof e&&Number.isFinite(e)&&e>=0&&e<.5)return e;throw new RangeError(`[semiotic] fitPadding must be a finite fraction in [0, 0.5); received ${String(e)}.`)}var jL=class extends Qa{constructor(e){var t;super(),this.updateResults=new FL,this.scene=[],this.scales=null,this.version=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customLayoutDiagnosticsWarned=/* @__PURE__ */new Set,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,this._customLayoutFailedThisBuild=!1,this._quadtree=null,this._maxPointRadius=0,this.projection=null,this.geoPath=null,this.baseScale=0,this.baseTranslate=[0,0],this.baseRotation=[0,0,0],this.currentZoom=1,this.cartogramLayout=null,this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.streaming=!1,this.lastIngestTime=0,this.timestampBuffer=null,this.activeTransition=null,this.prevPositions=null,this._hasRenderedOnce=!1,this.config=(t=e,{...t,fitPadding:BL(t.fitPadding)})}currentTime(){return this.config.clock?.()??r()}getConfiguredWindowSize(){let e=this.config.windowSize??500;if(!Number.isInteger(e)||e<1)throw new Error("GeoPipelineStore windowSize must be a positive integer");return e}retainNewestLines(e=this.getConfiguredWindowSize()){this.lineData.length>e&&(this.lineData=this.lineData.slice(-e))}resizeStreamingWindow(e){if(this.pointBuffer){let t=this.pointBuffer.toArray(),i=this.timestampBuffer?.toArray()??[],r=t.slice(-e),n=i.slice(-r.length),o=this.currentTime();this.pointBuffer=new Lo(e),this.timestampBuffer=new Lo(e),r.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(n[t]??o)})}this.retainNewestLines(e)}updateConfig(e){let t="fitPadding"in(o=e)?{...o,fitPadding:BL(o.fitPadding)}:o,i=this.config,r=this.getConfiguredWindowSize(),n=Object.keys(t).filter(e=>t[e]!==i[e]);var o;this.config={...this.config,...t};let a=this.getConfiguredWindowSize(),s=this.streaming&&a!==r;s&&(this.resizeStreamingWindow(a),this.version++),"customLayout"in t&&!t.customLayout&&(this.lastCustomLayoutFailure=null),this.updateResults.recordConfig(n,{retainedDataChanged:s})}updateConfigWithResult(e){return this.updateConfig(e),this.updateResults.last}setAreas(e){this.areas=e,this.updateResults.recordData("replace",e.length)}setAreasWithResult(e){return this.setAreas(e),this.updateResults.last}setPoints(e){this.pointData=e.slice(),this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.updateResults.recordData("replace",e.length)}setPointsWithResult(e){return this.setPoints(e),this.updateResults.last}setLines(e){this.lineData=e.slice(),this.streaming&&this.retainNewestLines(),this.updateResults.recordData("replace",e.length)}setLinesWithResult(e){return this.setLines(e),this.updateResults.last}initStreaming(e){void 0!==e&&e!==this.config.windowSize&&(this.config={...this.config,windowSize:e});let t=this.getConfiguredWindowSize(),i=this.pointBuffer?this.pointBuffer.toArray():this.pointData,r=this.timestampBuffer?.toArray()??[],n=i.slice(-t),o=r.slice(-n.length),a=this.currentTime();this.pointBuffer=new Lo(t),this.timestampBuffer=new Lo(t),n.forEach((e,t)=>{this.pointBuffer.push(e),this.timestampBuffer.push(o[t]??a)}),this.pointData=[],this.retainNewestLines(t),this.streaming=!0}pushPoint(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();Ua(this.pointBuffer,e,this.timestampBuffer,t),this.lastIngestTime=t,this.updateResults.recordData("ingest",1)}pushPointWithResult(e){return this.pushPoint(e),this.updateResults.last}pushMany(e){this.pointBuffer||this.initStreaming();let t=this.currentTime();for(let i of e)Ua(this.pointBuffer,i,this.timestampBuffer,t);this.lastIngestTime=t,this.updateResults.recordData("ingest",e.length)}pushManyWithResult(e){return this.pushMany(e),this.updateResults.last}pushLine(e){null!=e&&"object"==typeof e?(this.streaming||this.initStreaming(),this.lineData.push(e),this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",1)):this.updateResults.recordNoop("ingest")}pushManyLines(e){if(!Array.isArray(e)||0===e.length)return void this.updateResults.recordNoop("ingest");let t=e.filter(e=>null!=e&&"object"==typeof e);if(0!==t.length){this.streaming||this.initStreaming();for(let e of t)this.lineData.push(e);this.retainNewestLines(),this.version++,this.updateResults.recordData("ingest",t.length)}else this.updateResults.recordNoop("ingest")}removeLine(e){let{lineIdAccessor:t}=this.config;if(!t)throw new Error("removeLine() requires lineIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]),n=[];return this.lineData=this.lineData.filter(e=>!r.has(String(i(e)))||(n.push(e),!1)),n.length>0?(this.version++,this.updateResults.recordData("remove",n.length)):this.updateResults.recordNoop("remove"),n}getLines(){return this.lineData.slice()}removePoint(e){let{pointIdAccessor:t}=this.config;if(!t)throw new Error("removePoint() requires pointIdAccessor to be configured");let i="function"==typeof t?t:e=>e[t],r=new Set(Array.isArray(e)?e:[e]);if(this.streaming&&this.pointBuffer){let e=e=>r.has(String(i(e)));Ka(this.pointBuffer,this.timestampBuffer,e);let t=this.pointBuffer.remove(e);return t.length>0?(this.version++,this.updateResults.recordData("remove",t.length)):this.updateResults.recordNoop("remove"),t}{let e=[];return this.pointData=this.pointData.filter(t=>!r.has(String(i(t)))||(e.push(t),!1)),e.length>0?(this.version++,this.updateResults.recordData("remove",e.length)):this.updateResults.recordNoop("remove"),e}}clear(){this.areas=[],this.pointData=[],this.lineData=[],this.pointBuffer=null,this.timestampBuffer=null,this.streaming=!1,this.scene=[],this.scales=null,this._hasRenderedOnce=!1,this.activeTransition=null,this.prevPositions=null,this._quadtree=null,this._maxPointRadius=0,this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,this._customLayoutFailedThisBuild=!1,this.version++,this.updateResults.recordData("clear")}restyleScene(e){let t=this._customRestyle;if(t){for(let i of this.scene){let r=this._baseStyles.get(i)??i.style,n=t(i,e);i.style=n?{...r,...n}:r}this.markStylePaintPending(),this.updateResults.recordRestyle(!0)}else this.updateResults.recordRestyle(!1)}computeScene(e){let{config:t}=this,i=this.projection,r=this.geoPath,n=this.scales,o=this.baseScale,a=[...this.baseTranslate],s=[...this.baseRotation],l=this.scene;this.projection=sL(t.projection),this.geoPath=QP(this.projection),this.fitProjection(e),this.geoPath=QP(this.projection);let c=this.projection;this.scales={projection:c,geoPath:this.geoPath,projectedPoint:(e,t)=>c([e,t]),invertedPoint:(e,t)=>c.invert?c.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let u=this.buildSceneNodes(e);if(this._customLayoutFailedThisBuild)!0===this.lastCustomLayoutFailure?.preservedLastGoodScene?(this.projection=i,this.geoPath=r,this.scales=n,this.baseScale=o,this.baseTranslate=a,this.baseRotation=s):(this.scene=[],this.rebuildQuadtree());else{if(this.scene=u,this.rebuildQuadtree(),t.projectionTransform&&this.applyCartogramTransform(t.projectionTransform,e),t.decay&&this.streaming&&this.applyDecay(),t.pulse&&this.streaming&&this.applyPulse(),t.transition&&!this._hasRenderedOnce&&this.scene.length>0&&t.introAnimation){let t=e.width/2,i=e.height/2,r=this.scene.filter(e=>"point"===e.type).map(e=>({...e,x:t,y:i}));r.length>0&&this.startTransition(r)}this._hasRenderedOnce=!0,t.transition&&l.length>0&&this.startTransition(l),this.version++}}fitProjection(e){let t=this.projection,i=this.config,r=[...this.areas],n=lL(i.xAccessor,"lon"),o=lL(i.yAccessor,"lat"),a=this.getPoints();if(a.length>0){let e=a.map(e=>[n(e),o(e)]);r.push({type:"Feature",properties:{},geometry:{type:"MultiPoint",coordinates:e}})}let s=cL(i.lineDataAccessor);for(let e of this.lineData){let t=s(e);if(t&&t.length>0){let e=t.map(e=>[n(e),o(e)]);r.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}})}}if(0!==r.length){if(i.projectionExtent){let[[r,n],[o,a]]=i.projectionExtent,s={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[[r,n],[r,a],[o,a],[o,n],[r,n]]]}};t.fitExtent([[0,0],[e.width,e.height]],s)}else if(t.clipAngle&&(t.clipAngle()??0)>0){let r=i.fitPadding??0,n=Math.min(e.width,e.height),o=n/2-n*r;t.scale(o),t.translate([e.width/2,e.height/2])}else{let n={type:"FeatureCollection",features:r},o=i.fitPadding??0,a=e.width*o,s=e.height*o;t.fitExtent([[a,s],[e.width-a,e.height-s]],n)}this.baseScale=t.scale(),this.baseTranslate=t.translate(),this.baseRotation=t.rotate?.()??[0,0,0]}}applyZoomTransform(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,n=this.scales,o=i.scale(),a=[...i.translate()],s=this.currentZoom;i.scale(this.baseScale*e.k),i.translate([this.baseTranslate[0]*e.k+e.x,this.baseTranslate[1]*e.k+e.y]),this.currentZoom=e.k,this.geoPath=QP(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(e,t)=>i([e,t]),invertedPoint:(e,t)=>i.invert?i.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let l=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.scale(o),i.translate(a),this.currentZoom=s,this.geoPath=r,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyZoomScale(e,t){let i=this.projection;if(!i)return;let r=this.geoPath,n=this.scales,o=i.scale(),a=[...i.translate()],s=this.currentZoom;i.scale(this.baseScale*e),i.translate(this.baseTranslate),this.currentZoom=e,this.geoPath=QP(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(e,t)=>i([e,t]),invertedPoint:(e,t)=>i.invert?i.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let l=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.scale(o),i.translate(a),this.currentZoom=s,this.geoPath=r,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=l,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}applyRotation(e,t){let i=this.projection;if(!i||!i.rotate)return;let r=this.geoPath,n=this.scales,o=[...i.rotate()];i.rotate(e),this.geoPath=QP(i),this.scales={projection:i,geoPath:this.geoPath,projectedPoint:(e,t)=>i([e,t]),invertedPoint:(e,t)=>i.invert?i.invert([e,t]):null},this._customLayoutFailedThisBuild=!1;let a=this.buildSceneNodes(t);this._customLayoutFailedThisBuild?this.lastCustomLayoutFailure?.preservedLastGoodScene?(i.rotate(o),this.geoPath=r,this.scales=n):(this.scene=[],this.rebuildQuadtree()):(this.scene=a,this.rebuildQuadtree(),this.config.projectionTransform&&this.applyCartogramTransform(this.config.projectionTransform,t),this.version++)}setRotation(e){let t=this.projection;!t||!t.rotate||t.rotate(e)}hasProjection(){return null!=this.projection}getRotation(){return this.projection?.rotate?.()??this.baseRotation}getBaseProjectionState(){return{scale:this.baseScale,translate:[...this.baseTranslate]}}getPoints(){return this.streaming&&this.pointBuffer?this.pointBuffer.toArray():this.pointData}rebuildQuadtree(){let e=0,t=0;for(let i of this.scene)"point"===i.type&&!1!==i.interactive&&(t++,i.r>e&&(e=i.r));if(this._maxPointRadius=e,t<=500)return void(this._quadtree=null);let i=new Array(t),r=0;for(let e of this.scene)"point"===e.type&&!1!==e.interactive&&(i[r++]=e);this._quadtree=JP().x(e=>e.x).y(e=>e.y).addAll(i)}get quadtree(){return this._quadtree}get maxPointRadius(){return this._maxPointRadius}buildSceneNodes(e){this._customLayoutFailedThisBuild=!1;let{config:t}=this,i=this.projection,r=this.geoPath;if(t.customLayout&&this.scales){let i=t.layoutMargin??{top:0,right:0,bottom:0,left:0},r=Ix(t.colorScheme,t.themeCategorical,$i),n={areas:this.areas.slice(),points:this.getPoints().slice(),lines:this.lineData.slice(),scales:this.scales,dimensions:{width:e.width,height:e.height,margin:i,plot:{x:0,y:0,width:e.width,height:e.height}},theme:{semantic:t.themeSemantic??{},categorical:[...r]},resolveColor:Px(r,t.colorScheme),config:t.layoutConfig??{},selection:t.layoutSelection??null},o=la({family:"geo",logLabel:"geo customLayout",revision:this.version,hasPreviousResult:null!==this.lastCustomLayoutResult,onLayoutError:t.onLayoutError,run:()=>t.customLayout(n)});if("failure"===o.kind)return this.lastCustomLayoutFailure=o.diagnostic,this._customLayoutFailedThisBuild=!0,o.preservedLastGoodScene?this.scene:(this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,[]);let a=o.result,s=a.nodes??[];if(this.customLayoutOverlays=a.overlays??null,this.lastCustomLayoutResult=a,this.lastCustomLayoutFailure=null,this._customRestyle=a.restyle,this.hasCustomRestyle=!!a.restyle,this._baseStyles=/* @__PURE__ */new WeakMap,this.hasCustomRestyle)for(let e of s){this._baseStyles.set(e,e.style);let i=a.restyle?.(e,t.layoutSelection??null);i&&(e.style={...e.style,...i})}return ra({label:"geo customLayout",nodes:s,overlays:this.customLayoutOverlays,warned:this._customLayoutDiagnosticsWarned}),s}return this.customLayoutOverlays=null,this.lastCustomLayoutResult=null,this.lastCustomLayoutFailure=null,this._customRestyle=void 0,this.hasCustomRestyle=!1,this._baseStyles=/* @__PURE__ */new WeakMap,DL({config:t,projection:i,path:r,areas:this.areas,points:this.getPoints(),lines:this.lineData,layout:e})}applyCartogramTransform(e,t){let i=bL(this.scene,e,t,this.areas.length);i&&(this.cartogramLayout=i)}applyDecay(){let e=this.config.decay;if(!e||!this.pointBuffer)return;let t=this.pointBuffer.size;if(0===t)return;let i=this.scene.filter(e=>"point"===e.type);for(let r=0;r<i.length;r++){let n=jo(e,r,t);i[r]._decayOpacity=n,i[r].style={...i[r].style,opacity:n}}}applyPulse(e=this.currentTime()){let t=this.config.pulse;if(!t||!this.timestampBuffer)return!1;let i=this.scene.filter(e=>"point"===e.type),r=this.timestampBuffer.toArray(),n=t.color||"rgba(255,255,255,0.6)",o=t.glowRadius??4,a=!1;for(let s=0;s<i.length&&s<r.length;s++){let l=qo(t,r[s],e);a=Go(i[s],l,n,o)||a}return a}refreshPulse(e){return!0!==this.lastCustomLayoutFailure?.preservedLastGoodScene&&this.applyPulse(e)}hasActivePulsesAt(e){return!!this.config.pulse&&Vo(this.config.pulse,this.timestampBuffer,e)}get hasActivePulses(){return this.hasActivePulsesAt(this.currentTime())}startTransition(e){let t=this.config.transition?.duration??300;if(t<=0)return;let i=/* @__PURE__ */new Map;for(let t of e)"point"===t.type&&t.pointId&&i.set(t.pointId,[t.x,t.y]);let r=this.scene.filter(e=>"point"===e.type),n=!1;for(let e of r)if(e.pointId){let t=i.get(e.pointId);t&&(e._targetX=e.x,e._targetY=e.y,e.x=t[0],e.y=t[1],(Math.abs(t[0]-e._targetX)>.5||Math.abs(t[1]-e._targetY)>.5)&&(n=!0))}for(let e of r)e.pointId&&!i.has(e.pointId)&&(e._targetOpacity=e.style?.opacity??e.style?.fillOpacity??1,e.style={...e.style,opacity:0},n=!0);n&&(this.activeTransition={startTime:this.currentTime(),duration:t})}cancelIntroAnimation(){this.activeTransition=null;for(let e of this.scene)"point"===e.type&&(null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0),null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0))}advanceTransition(r){if(!this.activeTransition)return!1;let n=t(r,this.activeTransition),o=e(n),a=this.scene.filter(e=>"point"===e.type);for(let e of a){if(null!=e._targetX&&null!=e._targetY){let t=e.x,r=e.y;e.x=i(t,e._targetX,o),e.y=i(r,e._targetY,o)}null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity*o})}if(n>=1){for(let e of a)null!=e._targetX&&(e.x=e._targetX,e.y=e._targetY,e._targetX=void 0,e._targetY=void 0),null!=e._targetOpacity&&(e.style={...e.style,opacity:e._targetOpacity},e._targetOpacity=void 0);return this.activeTransition=null,!1}return!0}};import*as WL from"react";import{jsx as YL,jsxs as qL}from"react/jsx-runtime";function XL(e,t){return Ol(GL(e,t),e,`geo-cursor-${t}`)}function GL(e,t){switch(e.type){case"geoarea":{let i=e;if(!i.pathData)return null;let r=el(i.style.fill)?rl(i.style.fill,`geoarea-${t}-hatch`):void 0;/* @__PURE__ */
361
- return qL(WL.Fragment,{children:[r&&/* @__PURE__ */YL("defs",{children:r}),
362
- /* @__PURE__ */YL("path",{d:i.pathData,fill:r?`url(#geoarea-${t}-hatch)`:Ml(i.style.fill,"#e0e0e0"),fillOpacity:i.style.fillOpacity??1,stroke:i.style.stroke||"none",strokeWidth:i.style.strokeWidth??.5,strokeDasharray:i.style.strokeDasharray,opacity:(i.style.opacity??1)*(i._decayOpacity??1)})]},`geoarea-${t}`)}case"point":{let i=e,r=el(i.style.fill)?rl(i.style.fill,`geopoint-${t}-hatch`):void 0;/* @__PURE__ */
363
- return qL(WL.Fragment,{children:[r&&/* @__PURE__ */YL("defs",{children:r}),
364
- /* @__PURE__ */YL("circle",{cx:i.x,cy:i.y,r:i.r,fill:r?`url(#geopoint-${t}-hatch)`:Ml(i.style.fill),fillOpacity:i.style.fillOpacity??.8,stroke:i.style.stroke,strokeWidth:i.style.strokeWidth,opacity:i._decayOpacity??i.style.opacity??1})]},`point-${t}`)}case"line":{let i=e;if(i.path.length<2)return null;let r="M"+i.path.map(e=>`${e[0]},${e[1]}`).join("L");/* @__PURE__ */
365
- return YL("path",{d:r,fill:"none",stroke:i.style.stroke||"#4e79a7",strokeWidth:i.style.strokeWidth??1.5,strokeDasharray:i.style.strokeDasharray,opacity:i.style.opacity??1},`line-${t}`)}case"glyph":{let i=e;return _l(i,i.x,i.y,`geo-glyph-${i.pointId??t}`)}default:return null}}function VL(e){if(!e)return;let t=[];for(let i of e)if("point"===i.type)t.push(i);else if("glyph"===i.type){let e=i,r=f(e.glyph,e.size);t.push({pointId:e.pointId,x:e.x+r.centerDx,y:e.y+r.centerDy,r:r.radius})}return t}import{jsx as HL,jsxs as UL}from"react/jsx-runtime";function KL({bottomMargin:e,costLabel:t,layout:{cx:i,cy:r,maxCost:n,availableRadius:o,layout:a},ringStyle:s,ringValues:l,showNorth:c,showRingLabels:u,showRings:d}){let h="strip"===a,f={stroke:h?"var(--semiotic-border, #999)":"#999",strokeWidth:h?1:.8,strokeDasharray:h?"none":"4,3",labelColor:"var(--semiotic-text-secondary, #777)",labelSize:h?8:10,...s};/* @__PURE__ */
366
- return UL("g",h?{children:[
367
- /* @__PURE__ */HL("line",{x1:i,y1:r,x2:i+o,y2:r,stroke:f.stroke,strokeWidth:f.strokeWidth,strokeLinecap:"round",opacity:.85}),
368
- /* @__PURE__ */HL("line",{x1:i,y1:r-3.5,x2:i,y2:r+3.5,stroke:f.stroke,strokeWidth:f.strokeWidth,opacity:.9}),d&&l.map(a=>{let s=i+(n>0?a/n*o:0);/* @__PURE__ */
369
- return UL("g",{children:[
370
- /* @__PURE__ */HL("line",{x1:s,y1:r-2.5,x2:s,y2:r+2.5,stroke:f.stroke,strokeWidth:.9,opacity:.65}),u&&/* @__PURE__ */UL("text",{x:s,y:r+Math.min(10,(e??2)+8),textAnchor:"middle",fontSize:f.labelSize,fill:f.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[a,t?` ${t}`:""]})]},a)})]}:{children:[l.map(e=>{let a=e/n*o;/* @__PURE__ */
371
- return UL("g",{children:[
372
- /* @__PURE__ */HL("circle",{cx:i,cy:r,r:a,fill:"none",stroke:f.stroke,strokeWidth:f.strokeWidth,strokeDasharray:f.strokeDasharray,opacity:.5}),u&&/* @__PURE__ */UL("text",{x:i+a+3,y:r-2,fontSize:f.labelSize,fill:f.labelColor,fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:[e,t?` ${t}`:""]})]},e)}),c&&/* @__PURE__ */UL("g",{transform:"translate(24, 24)",children:[
373
- /* @__PURE__ */HL("circle",{r:16,fill:"white",fillOpacity:.85,stroke:"#bbb",strokeWidth:.8}),
374
- /* @__PURE__ */HL("path",{d:"M0,-11 L3,-3 L1,-4 L1,7 L-1,7 L-1,-4 L-3,-3 Z",fill:"#555",stroke:"none"}),
375
- /* @__PURE__ */HL("text",{y:-12,textAnchor:"middle",fontSize:7,fontWeight:700,fill:"#555",fontFamily:"var(--semiotic-font-family, system-ui, sans-serif)",children:"N"}),
376
- /* @__PURE__ */HL("line",{x1:11,y1:0,x2:13,y2:0,stroke:"#bbb",strokeWidth:.8}),
377
- /* @__PURE__ */HL("line",{x1:-11,y1:0,x2:-13,y2:0,stroke:"#bbb",strokeWidth:.8}),
378
- /* @__PURE__ */HL("line",{x1:0,y1:11,x2:0,y2:13,stroke:"#bbb",strokeWidth:.8})]})]})}import{Fragment as ZL,jsx as QL,jsxs as JL}from"react/jsx-runtime";function eR(e,t){let i=M(e.theme),r=e.size||[e.width||600,e.height||400],n=N({top:10,right:10,bottom:10,left:10,...e.margin},e.title),o=C(e.title),a=Array.isArray(e.areas)?ei(e.areas):e.areas,s=ei(e.points),l=ei(e.lines),c=e.showLegend?(()=>{let t="string"==typeof(r=e.colorBy)||"function"==typeof r?e.colorBy:void 0,i=s.length>0?s:Array.isArray(a)&&a.length>0?"string"==typeof t?a.map(e=>({...e.properties||{},...e})):a:[];var r;return pc(i,t)})():[];ch(n,{props:e,categories:c,theme:i,size:r,hasTitle:o});let u=uh({props:e,categories:c,theme:i,size:r,margin:n,hasTitle:o}),d=Math.max(1,r[0]-n.left-n.right),h=Math.max(1,r[1]-n.top-n.bottom),f={projection:e.projection||"equalEarth",projectionExtent:e.projectionExtent,xAccessor:e.xAccessor,yAccessor:e.yAccessor,lineDataAccessor:e.lineDataAccessor,pointIdAccessor:e.pointIdAccessor,lineIdAccessor:e.lineIdAccessor,lineType:e.lineType,flowStyle:e.flowStyle,areaStyle:e.areaStyle,pointStyle:e.pointStyle,lineStyle:e.lineStyle,colorScheme:e.colorScheme,graticule:e.graticule,fitPadding:e.fitPadding,projectionTransform:e.projectionTransform,customLayout:e.customLayout,layoutConfig:e.layoutConfig,layoutSelection:e.layoutSelection,layoutMargin:n,onLayoutError:e.onLayoutError,themeCategorical:i.colors.categorical,themeSemantic:w(i),themeSequential:i.colors.sequential,themeDiverging:i.colors.diverging},p=new jL(f);if(a){if("string"==typeof a)throw new Error(`Geo SSR requires pre-resolved GeoJSON features. Reference string "${a}" cannot be resolved synchronously. Use \`const features = await resolveReferenceGeography('${a}')\` before calling renderGeoToStaticSVG.`);p.setAreas(a)}e.points&&p.setPoints(s),e.lines&&p.setLines(l),p.computeScene({width:d,height:h});let g,m=Mh(e.backgroundGraphics,r,n,p.scales),y=Mh(e.foregroundGraphics,r,n,p.scales),x=Zl({nodes:p.scene,renderMode:e.renderMode,fallback:(e,t)=>XL(e,t)}),b=x.map(e=>e.element),v=x.length>0&&e.cartogramChrome,k=p.cartogramLayout&&v?/* @__PURE__ */QL(KL,{layout:{...p.cartogramLayout,layout:p.cartogramLayout.layout??"radial"},ringValues:tR(p.cartogramLayout.maxCost,v.showRings),showRings:v.showRings??!0,showNorth:v.showNorth??!0,showRingLabels:v.showRingLabels??!0,costLabel:"string"==typeof v.costLabel?v.costLabel:void 0}):null,S=e.annotations?Id({annotations:e.annotations,autoPlaceAnnotations:e.autoPlaceAnnotations,svgAnnotationRules:e.svgAnnotationRules,scales:{geoProjection:p.scales?.projectedPoint?([e,t])=>p.scales.projectedPoint(e,t):void 0},layout:{width:d,height:h},theme:i,pointNodes:VL(p.scene),idPrefix:e._idPrefix,onRender:e=>{g=e}}):null;t&&(t.evidence=Vs({frameType:"geo",width:r[0],height:r[1],marks:x.map(e=>e.node),title:e.title,description:e.description,annotations:e.annotations,annotationRender:g,legendItems:c.length>0?c.length:null!=e.legend?1:void 0,margin:n}));let A=/* @__PURE__ */JL(ZL,{children:[m,b,S,k,y,p.customLayoutOverlays]});return ZP.renderToStaticMarkup(hh(A,{width:r[0],height:r[1],className:"stream-geo-frame"+(e.className?` ${e.className}`:""),title:e.title,description:e.description,background:e.background,theme:i,innerTransform:`translate(${n.left??0},${n.top??0})`,innerWidth:d,innerHeight:h,legend:u,idPrefix:e._idPrefix}))}function tR(e,t){if(!1===t||e<=0)return[];if(Array.isArray(t))return t.filter(t=>t>0&&t<=e);let i="number"==typeof t?t:Math.min(5,Math.max(2,Math.ceil(e/5))),r=e/i,n=[];for(let e=1;e<=i;e++)n.push(Math.round(r*e*10)/10);return n}import*as iR from"react-dom/server";function rR(e){return e.world.bodies.map(e=>({id:e.id,x:e.x,y:e.y,prevX:e.prevX,prevY:e.prevY,vx:e.vx,vy:e.vy,angle:e.angle,mass:e.mass,shape:{...e.shape},sleeping:e.sleeping,datum:e.datum}))}function nR(e=[]){return e.map(e=>({id:e.id,label:e.label,count:e.count,...null!=e.secondary?{secondary:e.secondary}:{},...e.secondaryLabel?{secondaryLabel:e.secondaryLabel}:{},...null!=e.observed?{observed:e.observed}:{}}))}function oR(e,t,i,r){let n=e-(t+i+r);return{charge:e,live:t,queued:i,sedimented:r,unaccounted:n,balanced:0===n}}function aR(e,t={}){let i=t.bodies??rR(e),r=i.filter(e=>e.sleeping).length,n=e.queue.length,o=e.sediment.reduce((e,t)=>e+t.count,0),a="settled"===e.simulationState&&0===n&&r===i.length,s=[];a||s.push("PHYSICS_NOT_SETTLED"),n>0&&s.push("PHYSICS_QUEUE_UNDRAINED");let l=null!=t.charge&&Number.isFinite(t.charge)?oR(t.charge,i.length,n,o):void 0;return l&&!l.balanced&&s.push("PHYSICS_LEDGER_MISMATCH"),{bodyCount:i.length,sleepingCount:r,settled:a,stepsRun:Math.max(0,Math.floor(t.stepsRun??0)),seed:e.world.options.seed,binCounts:nR(t.projectionRows),queuedCount:n,sedimentedCount:o,...l?{ledger:l}:{},warnings:s}}var sR={fill:"#4e79a7",stroke:"#172033",strokeWidth:1,opacity:.85};function lR(e){return e.datum&&"object"==typeof e.datum?e.datum:null}function cR(e){let t=e.datum;if(t&&"object"==typeof t){let e=t,i=e.label??e.name??e.id;if(null!=i&&""!==i)return String(i)}return e.id}function uR(e,t,i){let r="function"==typeof t?t(e,i):t;return{...sR,...r??{}}}function dR(e,t={},i={index:0,simulationState:"settled"}){let r=lR(e),n={label:t.getBodyLabel?.(e)??cR(e)},o={style:uR(e,t.bodyStyle,i),datum:r,accessibleDatum:r,accessibility:n,_transitionKey:e.id};return"aabb"===e.shape.type?{type:"rect",x:e.x-e.shape.width/2,y:e.y-e.shape.height/2,w:e.shape.width,h:e.shape.height,...o}:{type:"point",x:e.x,y:e.y,r:e.shape.radius,pointId:e.id,...o}}function hR(e,t={},i="settled"){return e.map((e,r)=>dR(e,t,{index:r,simulationState:i}))}function fR(e,t={}){let i=e.settle(t.maxSteps),r=e.readBodies(),n=e.snapshot();return{snapshot:n,bodies:r,sceneNodes:hR(r,t,n.simulationState),evidence:aR(n,{bodies:r,projectionRows:t.projectionRows,stepsRun:i,charge:t.charge}),stepsRun:i}}import{jsx as pR,jsxs as gR}from"react/jsx-runtime";function mR(e){let t=e.replace(/[^A-Za-z0-9_-]/g,"_");return!t||/^\d/.test(t)?`physics-${t}`:t}var yR={top:0,right:0,bottom:0,left:0};function xR(e,t,i){return"function"==typeof e?e({size:t,margin:i}):e}function bR(e,t={}){let{width:i=640,height:r=360,title:n,description:o,background:a,backgroundGraphics:s,backgroundGraphicsBackdrop:l,className:c,foregroundGraphics:u,idPrefix:d="physics",margin:h,style:f,renderBodySVG:p,renderChrome:g,...m}=t,y=fR(e,m),x={...yR,...h},b=[i,r],v=xR(s,b,x),w=xR(u,b,x),k=mR(d),S=n?`${k}-title`:void 0,A=o?`${k}-desc`:void 0,M=[S,A].filter(Boolean).join(" ")||void 0,$=x.left||x.top?`translate(${x.left},${x.top})`:void 0,_=Math.max(1,i-x.left-x.right),I=Math.max(1,r-x.top-x.bottom),P=`${k}-plot-clip`,L=$&&null!=v?/* @__PURE__ */pR("g",{transform:$,children:v}):v;return{element:/* @__PURE__ */gR("svg",{xmlns:"http://www.w3.org/2000/svg",className:c??"stream-physics-frame",width:i,height:r,viewBox:`0 0 ${i} ${r}`,role:"img","aria-labelledby":M,style:f,children:[n&&/* @__PURE__ */pR("title",{id:S,children:n}),o&&/* @__PURE__ */pR("desc",{id:A,children:o}),
379
- /* @__PURE__ */pR("defs",{children:/* @__PURE__ */pR("clipPath",{id:P,children:/* @__PURE__ */pR("rect",{width:_,height:I})})}),l&&"transparent"!==l?/* @__PURE__ */pR("rect",{className:"stream-frame-background__backdrop",x:0,y:0,width:i,height:r,fill:l}):null,!s&&a&&"transparent"!==a?/* @__PURE__ */pR("rect",{x:0,y:0,width:i,height:r,fill:a}):null,L,
380
- /* @__PURE__ */pR("g",{id:`${k}-data-area`,transform:$,clipPath:`url(#${P})`,children:y.sceneNodes.map((e,t)=>{let i=y.bodies[t],r=i&&p?p(i,e.style??{},t,k):void 0;return null!=r?Ol(r,e,t):Ol("point"===e.type||"rect"===e.type?Tl(e,t,k):null,e,`xy-cursor-${t}`)})}),w,g?.(y)]}),scene:y,evidence:y.evidence}}function vR(e,t={}){let{element:i,scene:r,evidence:n}=bR(e,t);return{svg:iR.renderToStaticMarkup(i),scene:r,evidence:n}}function wR(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function kR(e,t){let i="sensor"===e.physics?t.sensorThickness:t.barrierThickness;return Math.max(0,wR(e.thickness)??wR(i)??wR(t.thickness)??4)}function SR(e=[],t={}){let i=t.idPrefix?`${t.idPrefix}-`:"",r=[];for(let n of e){if("barrier"!==n.physics&&"sensor"!==n.physics)continue;let e,o=n.axis??t.defaultAxis??"x",a=kR(n,t),s=n.colliderId??`${i}${n.id}`;if("x"===o){let i=wR(n.x),r=wR(n.y1)??wR(t.plotBounds?.y)??wR(n.y),o=wR(n.y2)??(t.plotBounds?t.plotBounds.y+t.plotBounds.height:void 0)??wR(n.y);if(null==i||null==r||null==o)continue;e={type:"segment",x1:i,y1:r,x2:i,y2:o,thickness:a}}else{let i=wR(n.y),r=wR(n.x1)??wR(t.plotBounds?.x)??wR(n.x),o=wR(n.x2)??(t.plotBounds?t.plotBounds.x+t.plotBounds.width:void 0)??wR(n.x);if(null==i||null==r||null==o)continue;e={type:"segment",x1:r,y1:i,x2:o,y2:i,thickness:a}}r.push({id:s,shape:e,sensor:"sensor"===n.physics,..."barrier"!==n.physics||null==n.restitution&&null==t.barrierRestitution?{}:{restitution:wR(n.restitution)??wR(t.barrierRestitution)},..."barrier"!==n.physics||null==n.friction&&null==t.barrierFriction?{}:{friction:wR(n.friction)??wR(t.barrierFriction)}})}return r}function AR(e){return e.sensorId??`stream-region-${e.id}`}function MR(e){let t=AR(e),i={bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution};if("boundary"===e.collider&&"aabb"===e.shape.type){let r=e.colliderThickness??8,n=e.shape.x-e.shape.width/2,o=e.shape.x+e.shape.width/2,a=e.shape.y-e.shape.height/2,s=e.shape.y+e.shape.height/2;return[{...i,id:`${t}-top`,shape:{type:"segment",x1:n,y1:a,x2:o,y2:a,thickness:r}},{...i,id:`${t}-right`,shape:{type:"segment",x1:o,y1:a,x2:o,y2:s,thickness:r}},{...i,id:`${t}-bottom`,shape:{type:"segment",x1:o,y1:s,x2:n,y2:s,thickness:r}},{...i,id:`${t}-left`,shape:{type:"segment",x1:n,y1:s,x2:n,y2:a,thickness:r}}]}return e.collider?[{...i,id:`${t}-collider`,shape:e.shape}]:[]}function $R({annotations:e,chartId:t,chartType:i,config:r,onRegionObservation:n,regionEffects:o,seed:a,size:s}){let l=SR((e??[]).filter(e=>"barrier"===e.physics||"sensor"===e.physics),{idPrefix:t?`${t}-ann`:"physics-ann",plotBounds:{x:0,y:0,width:s[0],height:s[1]}}),c=void 0===a||void 0!==r?.kernel?.seed?r:{...r,kernel:{...r?.kernel,seed:a}},u=o.flatMap(e=>[{id:AR(e),sensor:!0,shape:e.shape,bodyFilter:e.bodyFilter,friction:e.friction,restitution:e.restitution},...MR(e)]),d=Object.fromEntries(o.map(e=>[AR(e),{binId:e.binId??e.id,enterType:"physics-proximity-enter",exitType:"physics-proximity-exit"}])),h=c?.observation,f=o.length>0,p=u.length>0||l.length>0;return f||p||null!=t||h?{...c,colliders:[...c?.colliders??[],...u,...l],observation:{...h,chartId:t??h?.chartId,chartType:h?.chartType??i,sensors:{...h?.sensors??{},...d},onObservation:e=>{f&&n(e),h?.onObservation?.(e)}}}:c}import{jsx as _R}from"react/jsx-runtime";function IR({title:e,totalWidth:t,marginTop:i}){return e?"string"!=typeof e?/* @__PURE__ */_R("foreignObject",{x:0,y:0,width:t,height:i,children:e}):/* @__PURE__ */_R("text",{x:t/2,y:22,textAnchor:"middle",fontWeight:"bold",fill:"var(--semiotic-text, #333)",fontSize:14,className:"semiotic-chart-title",style:{userSelect:"none",fontSize:"var(--semiotic-title-font-size, 14px)",fontFamily:"var(--semiotic-title-font-family, var(--semiotic-font-family, sans-serif))",fontWeight:"var(--semiotic-title-font-weight, bold)"},children:e}):null}import{scaleLinear as PR}from"d3-scale";function LR(e){return"circle"===e.shape.type?e.shape.radius:Math.max(e.shape.width,e.shape.height)/2}function RR(e){return e.map(e=>({pointId:e.id,x:e.x,y:e.y,r:Math.max(1,LR(e))}))}function CR(e){let{width:t,height:i,pointNodes:r=[],data:n}=e;return{scales:{x:PR().domain([0,Math.max(1,t)]).range([0,Math.max(1,t)]),y:PR().domain([0,Math.max(1,i)]).range([0,Math.max(1,i)])},width:t,height:i,frameType:"network",pointNodes:r,data:n,xAccessor:"x",yAccessor:"y"}}function TR(e){return e?.length?e.map(e=>null!=e.pointId||null==e.bodyId?e:{...e,pointId:String(e.bodyId)}):e}import{jsx as NR,jsxs as FR}from"react/jsx-runtime";function ER(e,t,i,r,n){let o=Math.max(1,i[0]-r.left-r.right),a=Math.max(1,i[1]-r.top-r.bottom),s=TR(t.annotations),l=CR({width:o,height:a,pointNodes:RR(e.bodies)}),c=l.scales?.x,u=l.scales?.y;if(!c||!u)throw new Error("Physics annotation context requires pixel scales");let d,h=Id({annotations:s,autoPlaceAnnotations:t.autoPlaceAnnotations,scales:{x:c,y:u},layout:{width:o,height:a},theme:n,frameType:"network",xAccessor:l.xAccessor,yAccessor:l.yAccessor,pointNodes:l.pointNodes,svgAnnotationRules:t.svgAnnotationRules,onRender:e=>{d=e}}),f=t.legend?lh(t.legend,{theme:n,position:t.legendPosition,size:[i[0],i[1]],margin:r,hasTitle:!!t.title,legendLayout:t.legendLayout})??Rd(t.legend,i,r,t.legendPosition,t.legendLayout):null;return{annotationRender:d,node:/* @__PURE__ */FR("svg",{className:"stream-physics-frame__overlay","data-testid":"stream-physics-overlay",role:"presentation",width:i[0],height:i[1],style:{position:"absolute",top:0,left:0,pointerEvents:"none",overflow:"visible"},children:[
381
- /* @__PURE__ */NR("g",{transform:`translate(${r.left},${r.top})`,children:h}),
382
- /* @__PURE__ */NR(IR,{title:t.title,totalWidth:i[0],marginTop:Math.max(r.top,28)}),f]})}}var OR={top:0,right:0,bottom:0,left:0};function zR(e,t){let i=e.size??[e.width??600,e.height??400],r=M(e.theme),n=void 0===e.theme?{}:yn(r),o=e.bodyStyle,a=!1,s=e.legendPosition??"right",l=T({...OR,...e.margin},a);if(e.legend){let t={...l};H(l,{legend:e.legend,position:s,size:i,hasTitle:a,legendLayout:e.legendLayout}),F(l,t,i,s)}let c,u=[Math.max(1,i[0]-l.left-l.right),Math.max(1,i[1]-l.top-l.bottom)],d=$R({annotations:e.annotations,chartId:e.chartId,chartType:"StreamPhysicsFrame",config:e.config,onRegionObservation:()=>{},regionEffects:e.regionEffects??[],seed:e.seed,size:u}),h=new Ey(d);Array.isArray(e.initialSpawns)&&e.initialSpawns.length>0&&h.enqueue(e.initialSpawns,e.initialSpawnPacing);let f=vR(h,{...e,width:i[0],height:i[1],background:e.background??r.colors.background,bodyStyle:(e,t)=>({fill:r.colors.primary,stroke:r.colors.text,strokeWidth:1,opacity:.9,..."function"==typeof o?o(e,t):o}),style:{...n,fontFamily:r.typography.fontFamily,...e.style},charge:e.charge,idPrefix:e.idPrefix??e._idPrefix??"physics",margin:l,renderChrome:t=>{let n=ER(t,e,i,l,r);return c=n.annotationRender,n.node}});return t&&(t.evidence=Vs({frameType:"physics",width:i[0],height:i[1],marks:f.scene.sceneNodes,title:e.title,description:e.description,annotations:e.annotations,annotationRender:c,extraWarnings:[...0===f.scene.sceneNodes.length?["PHYSICS_EMPTY_SCENE"]:[],...f.scene.evidence.warnings]})),f.svg}import*as DR from"react-dom/server";function BR(e,t={}){if("function"==typeof e)return e;let i=t.locale??"en-US",r=t.currency??"USD";if("currency"===e){let e=t.precision??2,n=new Intl.NumberFormat(i,{style:"currency",currency:r,maximumFractionDigits:e,minimumFractionDigits:e});return e=>n.format(e)}if("percent"===e){let e=t.precision??1,r=new Intl.NumberFormat(i,{style:"percent",maximumFractionDigits:e,minimumFractionDigits:0});return e=>r.format(e)}if("compact"===e){let e=t.precision??1,r=new Intl.NumberFormat(i,{notation:"compact",maximumFractionDigits:e,minimumFractionDigits:0});return e=>r.format(e)}if("duration"===e)return e=>jR(e);let n=t.precision??0,o=new Intl.NumberFormat(i,{notation:t.notation??"standard",maximumFractionDigits:n,minimumFractionDigits:0});return e=>o.format(e)}function jR(e){if(!Number.isFinite(e))return String(e);let t=e<0?"-":"",i=Math.abs(e),r=Math.round(i);if(r<1e3)return`${t}${r}ms`;let n=Math.round(i/10)/100;if(n<60)return`${t}${YR(n)}s`;let o=Math.round(i/1e3);if(o<3600)return`${t}${WR(Math.floor(o/60),"m",o%60,"s")}`;let a=Math.round(i/6e4);if(a<1440)return`${t}${WR(Math.floor(a/60),"h",a%60,"m")}`;let s=Math.round(i/36e5);return`${t}${WR(Math.floor(s/24),"d",s%24,"h")}`}function WR(e,t,i,r){return 0===i?`${e}${t}`:`${e}${t} ${i}${r}`}function YR(e){return String(Math.round(100*e)/100)}function qR(e,t,i){return`${t??""}${e}${i??""}`}function XR(e,t){return 0===e||t(Math.abs(e))===t(0)}function GR(e,t){return Number.isFinite(e)?XR(e,t)?t(0):`${e>0?"+":"−"}${t(Math.abs(e))}`:""}function VR(e,t){if(!t||0===t.length||!Number.isFinite(e))return null;let i=t.filter(e=>Number.isFinite(e.at)||e.at===-1/0).slice().sort((e,t)=>e.at-t.at),r=null;for(let t of i){if(!(e>=t.at))break;r=t}return r}import{jsx as HR,jsxs as UR}from"react/jsx-runtime";var KR={tile:{width:280,height:184,padding:16,labelSize:13,captionSize:11,valueSize:40,detailSize:13,align:"start",border:!0,showHeader:!0,showDetail:!0},presentation:{width:540,height:320,padding:32,labelSize:18,captionSize:14,valueSize:96,detailSize:18,align:"center",border:!0,showHeader:!0,showDetail:!0},inline:{width:240,height:64,padding:8,labelSize:0,captionSize:0,valueSize:28,detailSize:13,align:"start",border:!1,showHeader:!1,showDetail:!0},thumbnail:{width:96,height:56,padding:6,labelSize:0,captionSize:0,valueSize:22,detailSize:0,align:"center",border:!1,showHeader:!1,showDetail:!1}};function ZR(e,t){return"number"==typeof e&&Number.isFinite(e)&&e>0?e:t}function QR(e,t,i){return t||("success"===e?i.colors.success??"#2ca02c":"warning"===e?i.colors.warning??"#b26a00":"danger"===e?i.colors.danger??"#d62728":"info"===e?i.colors.info??i.colors.primary:i.colors.text)}function JR(e,t,i){let r=e.comparison&&"object"==typeof e.comparison?e.comparison:void 0,n=r&&"number"==typeof r.value&&Number.isFinite(r.value)?r.value:void 0,o=("number"==typeof e.delta&&Number.isFinite(e.delta)?e.delta:void 0)??(void 0===n?void 0:t-n);if(void 0!==o)return`${GR(o,i)}${r&&"string"==typeof r.label?` ${r.label}`:""}`}function eC(e,t,i){let r=e.target&&"object"==typeof e.target?e.target:void 0;if(!r||"number"!=typeof r.value||!Number.isFinite(r.value))return;let n="string"==typeof r.label?` ${r.label}`:"";return 0===r.value?`target ${i(r.value)}${n}`:`${new Intl.NumberFormat("string"==typeof e.locale?e.locale:"en-US",{style:"percent",maximumFractionDigits:0}).format(t/r.value)} of ${i(r.value)}${n}`}var tC={BigNumber:function(e,t){let i="presentation"===e.mode||"inline"===e.mode||"thumbnail"===e.mode?e.mode:"tile",r=KR[i],n=ZR(e.width,r.width),o=ZR(e.height,r.height),a="number"==typeof e.padding&&Number.isFinite(e.padding)?Math.max(0,e.padding):r.padding,s="center"===e.align||"end"===e.align||"start"===e.align?e.align:r.align,l="center"===s?"middle":"end"===s?"end":"start",c="center"===s?n/2:"end"===s?n-a:a,u=M(e.theme),d="number"==typeof e.value&&Number.isFinite(e.value)?e.value:void 0,h=BR("string"==typeof e.format||"function"==typeof e.format?e.format:"number",{locale:"string"==typeof e.locale?e.locale:void 0,currency:"string"==typeof e.currency?e.currency:void 0,precision:"number"==typeof e.precision?e.precision:void 0}),f=void 0===d?"No value":qR(h(d),"string"==typeof e.prefix?e.prefix:void 0,"string"==typeof e.suffix?e.suffix:void 0),p=void 0===d?void 0:VR(d,e.thresholds),g=p?.level??"neutral",m="string"==typeof e.color?e.color:QR(g,p?.color,u),y="string"==typeof e.label?e.label:void 0,x="string"==typeof e.caption?e.caption:void 0,b="string"==typeof e.unit?e.unit:void 0,v=[void 0===d?void 0:JR(e,d,h),void 0===d?void 0:eC(e,d,h),p?.label].filter(Boolean).join(" · "),w="string"==typeof e.description&&e.description||[y,f,b,v].filter(Boolean).join(", "),k="string"==typeof e.background?e.background:u.colors.surface??u.colors.background,S="string"==typeof e.borderColor?e.borderColor:u.colors.border,A=a+r.labelSize,$=A+r.captionSize+4,_=r.showHeader&&(y||x)?x?$+10:A+14:a,I="presentation"===i?o/2+.32*r.valueSize:"thumbnail"===i?o/2+.34*r.valueSize:Math.min(o-a-(v?26:4),_+r.valueSize),P=c+("start"===l?Math.max(r.valueSize,f.length*r.valueSize*.55):0),L=DR.renderToStaticMarkup(
383
- /* @__PURE__ */UR("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:o,viewBox:`0 0 ${n} ${o}`,role:"img","aria-label":w,"data-semiotic-component":"BigNumber",children:[
384
- /* @__PURE__ */HR("title",{children:y??f}),"string"==typeof e.description&&/* @__PURE__ */HR("desc",{children:e.description}),
385
- /* @__PURE__ */HR("rect",{x:r.border?.5:0,y:r.border?.5:0,width:r.border?n-1:n,height:r.border?o-1:o,rx:r.border?8:0,fill:k,stroke:r.border?S:"none"}),r.showHeader&&y&&/* @__PURE__ */HR("text",{x:c,y:A,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.labelSize,fontWeight:600,fill:u.colors.text,children:y}),r.showHeader&&x&&/* @__PURE__ */HR("text",{x:c,y:$,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.captionSize,fill:u.colors.textSecondary,children:x}),
386
- /* @__PURE__ */HR("text",{x:c,y:I,textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.valueSize,fontWeight:600,fontVariant:"tabular-nums",fill:void 0===d?u.colors.textSecondary:m,"data-mark-type":"value",children:f}),b&&void 0!==d&&"start"===l&&/* @__PURE__ */HR("text",{x:P+6,y:I,textAnchor:"start",fontFamily:u.typography.fontFamily,fontSize:Math.max(11,Math.round(.32*r.valueSize)),fontWeight:500,fill:u.colors.textSecondary,children:b}),r.showDetail&&v&&/* @__PURE__ */HR("text",{x:c,y:Math.min(o-a,I+r.detailSize+10),textAnchor:l,fontFamily:u.typography.fontFamily,fontSize:r.detailSize,fill:u.colors.textSecondary,children:v})]}));return t&&(t.evidence=Vs({frameType:"value",width:n,height:o,marks:void 0===d?[]:[{type:"value"}],title:y,description:w})),L}};function iC(e,t,i){return tC[e](t,i)}import*as rC from"react-dom/server";import{jsx as nC,jsxs as oC}from"react/jsx-runtime";function aC(e,t,i){let{title:r,subtitle:n,theme:o,width:a=1200,height:s,layout:l={},background:c}=t,u=$(M(o)),d=l.columns||2,h=l.gap??16,f=0;r&&(f+=30),n&&(f+=20),f>0&&(f+=10);let p=a-h,g=Math.floor((p-h*(d-1))/d),m=[],y=0,x=f+h,b=0;for(let t of e){let e=Math.min(t.colSpan||1,d),r=g*e+h*(e-1),n=t.props.height||300;y+e>d&&(x+=b+h,y=0,b=0);let a=h/2+y*(g+h),s={...t.props,width:r,height:n,theme:o,_idPrefix:`chart-${m.length}`},l=t.component?i.chart(t.component,s):t.frameType?i.frame(t.frameType,s):`<svg xmlns="http://www.w3.org/2000/svg" width="${r}" height="${n}"></svg>`,c=ae(l,{width:r,height:n}),u=Math.max(n,c.height);m.push({x:a,y:x,width:r,height:u,svg:l,svgDimensions:c}),b=Math.max(b,u),y+=e}let v=s||x+b+h,w=m.map((e,t)=>/* @__PURE__ */nC("g",{transform:`translate(${e.x},${e.y})`,children:/* @__PURE__ */nC("foreignObject",{width:e.width,height:e.height,children:/* @__PURE__ */nC("div",{xmlns:"http://www.w3.org/1999/xhtml",dangerouslySetInnerHTML:{__html:se(e.svg,e.svgDimensions)}})})},`dashboard-chart-${t}`));return rC.renderToStaticMarkup(
387
- /* @__PURE__ */oC("svg",{xmlns:"http://www.w3.org/2000/svg",width:a,height:v,role:"img","aria-label":r||"Dashboard",style:{fontFamily:u.fontFamily},children:[r&&/* @__PURE__ */nC("title",{children:r}),c&&/* @__PURE__ */nC("rect",{x:0,y:0,width:a,height:v,fill:c}),r&&/* @__PURE__ */nC("text",{x:a/2,y:24,textAnchor:"middle",fontSize:u.titleFontSize+4,fontWeight:u.titleFontWeight,fill:u.text,fontFamily:u.titleFontFamily,children:r}),n&&/* @__PURE__ */nC("text",{x:a/2,y:r?46:20,textAnchor:"middle",fontSize:u.labelSize,fill:u.textSecondary,fontFamily:u.fontFamily,children:n}),w]}))}import{Fragment as sC,jsx as lC}from"react/jsx-runtime";function cC(e,t){switch(e){case"xy":return Oh(t);case"ordinal":return U$(t);case"network":return KP(t);case"geo":return eR(t);case"physics":return zR(t);default:throw new Error(`Unknown frame type: ${e}. Must be "xy", "ordinal", "network", "geo", or "physics".`)}}function uC(e){return Oh(e)}function dC(e){return U$(e)}function hC(e){return KP(e)}function fC(e){return eR(e)}var pC=/* @__PURE__ */new Set(["d","transform","points","viewBox","x","y","x1","x2","y1","y2","cx","cy","r","rx","ry","width","height","dx","dy","offset","startOffset","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","fill-opacity","opacity","font-size","letter-spacing"]),gC=/-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?/gi;function mC(e){if(Number.isFinite(e))return Math.max(0,Math.min(8,Math.floor(e)))}function yC(e,t){let i=Number(e);if(!Number.isFinite(i))return e;let r=10**t,n=Math.round((i+Number.EPSILON)*r)/r;return Object.is(n,-0)?"0":String(n)}function xC(e,t){let i,r=new RegExp(gC.source,gC.flags),n="",o=0,a=!1;for(;i=r.exec(e);){let r=e.slice(o,i.index);a&&0===r.length?n+=" ":n+=r,n+=yC(i[0],t),o=i.index+i[0].length,a=!0}return n+e.slice(o)}function bC(e,t){let i=mC(t);return void 0===i?e:ne(e,(e,t)=>{if(pC.has(e)&&!/\b(?:var|calc|url)\(/i.test(t))return xC(t,i)})}var vC=["showAxes","axes","axisExtent","xLabel","yLabel","yLabelRight","categoryLabel","valueLabel","xFormat","yFormat","categoryFormat","valueFormat","tickFormatTime","tickFormatValue","xScaleType","yScaleType","xExtent","yExtent","rExtent","oExtent","extentPadding","hoverRadius","scalePadding","sizeRange","innerRadius","centerContent","curve","gradientFill","lineGradient","lineStyle","pointStyle","areaStyle","barStyle","waterfallStyle","swarmStyle","pieceStyle","summaryStyle","nodeStyle","edgeStyle","connectorStyle","backgroundGraphics","foregroundGraphics","svgPreRenderers","svgAnnotationRules","barColors","legend","legendLayout","autoPlaceAnnotations","perspective"],wC=["width","height","showAxes","showGrid","enableHover","showLegend","showLabels","showCategoryTicks","orientation","title","description","summary","accessibleTable","xLabel","yLabel","categoryLabel","valueLabel","linkedHover","mobileInteraction","mobileSemantics","responsiveRules"];function kC(e,t){let i={};for(let r of t)void 0!==e[r]&&(i[r]=e[r]);return i}function SC(e,t,i){return MC(e,t,i).svg}function AC(e,t,i){let r={},{svg:n,frameType:o}=MC(e,t,i,r),a=r.evidence??Vs({frameType:o,width:"number"==typeof t.width?t.width:600,height:"number"==typeof t.height?t.height:400,marks:[],title:"string"==typeof t.title?t.title:void 0,description:"string"==typeof t.description?t.description:void 0,annotations:t.annotations,extraWarnings:["NO_EVIDENCE"]});if(a.component=e,a.sceneHashVersion=2,a.sceneHash=xt(n,a),Wt(a,e,t),i?.artifactContract){let r=ut(i.artifactContract,{excludeEvidenceSamples:!0});r.contract&&(a.artifactContract=r.contract),a.artifactTransfer=r.transfer,a.artifactBinding="0.1"===r.contract?.contractVersion&&"invalid"!==r.transfer.status?yt(r.contract,t,e):{status:"unknown",mismatchPaths:[],unknownPaths:["artifactContract"]}}return{svg:n,evidence:a}}function MC(e,t,i,r){if(Object.prototype.hasOwnProperty.call(tC,e))return{svg:bC(iC(e,t,r),i?.precision),frameType:"value"};if(!Object.prototype.hasOwnProperty.call(NM,e))throw new Error(`Unknown chart component: "${e}". Run \`npx semiotic-ai --list\` for supported chart types.`);let n,o=NM[e],a=Pt(o.layout?.mode??(It(t.mode)?t.mode:void 0),{...o.layout?.modeDefaults,...kC(t,wC)},o.layout?.primarySize),{data:s,theme:l,background:c,className:u,annotations:d,margin:h,colorScheme:f,colorBy:p,legendPosition:g,...m}=t,{width:y,height:x}=a,b=[y,x],v=m.frameProps||{},w=o.layout?.margin,k="function"==typeof w?w(t,a):w??a.marginDefaults,S="xy"===o.frameType?Q(k,m.axes??v.axes,!!a.title):k,A=void 0!==h?h:v.margin,$=Yt(A),_="number"==typeof A?{top:A,right:A,bottom:A,left:A}:{...S,...$},I=kC(m,vC),P=e=>v[e]??a[e],L={...v,...I,theme:l,title:a.title,description:a.description,showAxes:P("showAxes"),showLegend:P("showLegend"),showLabels:P("showLabels"),showGrid:P("showGrid"),xLabel:P("xLabel"),yLabel:P("yLabel"),categoryLabel:P("categoryLabel"),valueLabel:P("valueLabel"),background:c??v.background,className:u,annotations:d,size:b,margin:_,__resolvedMode:a.mode,__compactMode:a.compactMode,__explicitMarginSides:"number"==typeof A?["top","right","bottom","left"]:Object.keys($??{}),__autoLegendMargin:!0,...void 0!==f&&{colorScheme:f},...void 0!==g&&{legendPosition:g},_idPrefix:m._idPrefix},R=o.buildProps(s,p,f,L,m);if(o.renderStatic)n=o.renderStatic(R,r);else switch(o.frameType){case"xy":n=Oh(R,r);break;case"ordinal":n=U$(R,r);break;case"network":n=KP(R,r);break;case"geo":n=eR(R,r);break;case"physics":n=zR(R,r)}let C=o.renderOverlay?.(R,{theme:M(l)});if(null!=C){let e=qt.renderToStaticMarkup(/* @__PURE__ */lC(sC,{children:C})),t=n.lastIndexOf("</svg>");n=t<0?`${n}${e}`:`${n.slice(0,t)}${e}${n.slice(t)}`}return{svg:bC(n,i?.precision),frameType:o.frameType}}async function $C(e,t,i={}){let r,{background:n}=i;if(r=["xy","ordinal","network","geo","physics"].includes(e)?cC(e,t):SC(e,t),n){let e=ee(r),t=e?re(e,"style"):void 0;r=oe(r,{style:`${t?`${t};`:""}background:${n}`})}let o={width:t.width||t.size?.[0]||600,height:t.height||t.size?.[1]||400},{width:a,height:s}=ae(r,o),{rasterizeSVG:l}=await(import("./c-3YEW2PK6.min.js"));return l(r,a,s,i)}function _C(e,t={}){return aC(e,t,{chart:SC,frame:cC})}import*as IC from"react-dom/server";import{Fragment as PC,jsx as LC,jsxs as RC}from"react/jsx-runtime";function CC(e,t,i,r={}){let{stepSize:n,windowSize:o,frameCount:a,xExtent:s,yExtent:l,transitionFrames:c=4,fps:u=12,easing:d="ease-out",decay:h}=r,f=i.width||600,p=i.height||400,g=M(i.theme),m={...i,...s&&{xExtent:s},...l&&{yExtent:l}};if(!t||0===t.length)return[];let y=a||Math.min(60,Math.max(10,t.length)),x=n||Math.max(1,Math.ceil(t.length/y)),b=[];for(let e=x;e<=t.length;e+=x)b.push(e);b[b.length-1]!==t.length&&b.push(t.length);let v=/* @__PURE__ */new Set(["bar","pie","donut","clusterbar","swarm","point","boxplot","violin","histogram","timeline","swimlane","ridgeline","funnel","bar-funnel"]).has(e),w=N({top:20,right:20,bottom:30,left:40,...i.margin},i.title),k=Math.max(1,f-w.left-w.right),S=Math.max(1,p-w.top-w.bottom),A=[];if(v)for(let r=0;r<b.length;r++){let n=b[r],a=o?Math.max(0,n-o):0,s=t.slice(a,n),l={chartType:e,windowSize:1e4,windowMode:"sliding",extentPadding:.05,projection:i.projection||"vertical",oAccessor:i.oAccessor||i.categoryAccessor||"category",rAccessor:i.rAccessor||i.valueAccessor||"value",colorAccessor:i.colorAccessor||i.colorBy,stackBy:i.stackBy,groupBy:i.groupBy,connectorAccessor:i.connectorAccessor,connectorStyle:i.connectorStyle,barPadding:i.barPadding,innerRadius:i.innerRadius,normalize:i.normalize,bins:i.bins,colorScheme:i.colorScheme||g.colors.categorical,...h&&{decay:h}},c=new k$(l);c.ingest({inserts:s,bounded:!0}),c.computeScene({width:k,height:S}),c.scene.length>0&&A.push(jC(c.scene,f,p,g,m,A.length))}else for(let r=0;r<b.length;r++){let n=b[r],a=o?Math.max(0,n-o):0,y=t.slice(a,n),x={chartType:e,windowSize:y.length+10,windowMode:"sliding",arrowOfTime:"right",extentPadding:.1,xAccessor:i.xAccessor||"x",yAccessor:i.yAccessor||"y",colorAccessor:i.colorAccessor||i.colorBy,groupAccessor:i.groupAccessor||i.lineBy,lineDataAccessor:i.lineDataAccessor,xExtent:s,yExtent:l,colorScheme:i.colorScheme||g.colors.categorical,lineStyle:i.lineStyle,pointStyle:i.pointStyle,areaStyle:i.areaStyle,sizeAccessor:i.sizeAccessor||i.sizeBy,sizeRange:i.sizeRange,...h&&{decay:h},...c>0&&{transition:{duration:c*(1e3/u),easing:d}}},v=new Ss(x);if(v.ingest({inserts:y,bounded:!0}),v.computeScene({width:k,height:S}),0===v.scene.length)continue;let w=v.scales?{y:v.scales.y}:void 0;if(A.push(BC(v.scene,f,p,g,m,w,A.length)),c>0&&r>0&&v.activeTransition){let e=c*(1e3/u);for(let t=1;t<=c;t++){let i=t/c,r=v.activeTransition.startTime+i*e;v.advanceTransition(r),A.push(BC(v.scene,f,p,g,m,w,A.length))}}}return A}function TC(e,t,i={}){return t.map(t=>{try{return SC(e,{...i,...t})}catch{return`<svg xmlns="http://www.w3.org/2000/svg" width="${i.width||t.width||600}" height="${i.height||t.height||400}"></svg>`}})}function NC(e,t,i,r){let n=Cd(`${e}-${t}`),o="string"==typeof i&&i.length>0?i:void 0,a="string"==typeof r&&r.length>0?r:void 0,s=o?n.titleId:void 0,l=a?n.descId:void 0;return{titleText:o,descText:a,titleId:s,descId:l,labelledBy:[s,l].filter(Boolean).join(" ")||void 0}}function FC(e,t){return"string"==typeof e.idPrefix&&e.idPrefix.length>0?e.idPrefix:nh(e)||t}function EC(e,t,i){let r=t.size??[t.width??600,t.height??400],n=M(t.theme),o=$(n),a=t.background||n.colors.background,s=t.idPrefix??"physics-gif",l=NC(s,i,t.title,t.description),{titleId:c,descId:u,labelledBy:d}=l,h=hR(e.readBodies(),{bodyStyle:t.bodyStyle,getBodyLabel:t.getBodyLabel}),f=/* @__PURE__ */RC("svg",{xmlns:"http://www.w3.org/2000/svg",className:t.className??"stream-physics-frame",width:r[0],height:r[1],viewBox:`0 0 ${r[0]} ${r[1]}`,role:"img","aria-labelledby":d,style:{fontFamily:o.fontFamily},children:[t.title&&/* @__PURE__ */LC("title",{id:c,children:t.title}),t.description&&/* @__PURE__ */LC("desc",{id:u,children:t.description}),a&&"transparent"!==a?/* @__PURE__ */LC("rect",{x:0,y:0,width:r[0],height:r[1],fill:a}):null,
388
- /* @__PURE__ */LC("g",{id:`${s}-frame-${i}`,children:h.map((e,t)=>Yl(e,t,`${s}-${i}`))})]});return IC.renderToStaticMarkup(f)}function OC(e,t={}){let{fps:i=12,frameCount:r,durationSeconds:n=2,includeInitialFrame:o=!0,stepDt:a,stepsPerFrame:s,background:l}=t,c=Math.max(.001,a??e.config?.fixedDt??1/120),u=s??Math.max(1,Math.round(1/Math.max(1,i)/c)),d=r??Math.max(1,Math.ceil(n*Math.max(1,i))),h=l?{...e,background:l}:e,f=new Ey(e.config);e.initialSpawns?.length&&f.enqueue(e.initialSpawns,e.initialSpawnPacing);let p=[];for(o&&(f.tick(0),p.push(EC(f,h,0)));p.length<d;){for(let e=0;e<u;e+=1)f.tick(c);p.push(EC(f,h,p.length))}return p}function zC(e,t){let i=e.background||t.colors.background;return i&&"transparent"!==i?i:null}function DC(e,t,i,r,n,o){if(!e||0===e.length)return null;let a=$(r),s=[];for(let r=0;r<e.length;r++){let l=e[r];if("y-threshold"===l.type&&null!=l.value){let e=null;if(o)e=o(l.value);else if(n){let[t,r]=n,o=r-t;if(0===o)continue;e=i-(l.value-t)/o*i}if(null==e)continue;let c=l.color||a.primary,u=l.strokeDasharray||"6,4",d=l.strokeWidth??1.5,h=l.labelPosition||"right";s.push(
389
- /* @__PURE__ */RC("g",{children:[
390
- /* @__PURE__ */LC("line",{x1:0,y1:e,x2:t,y2:e,stroke:c,strokeWidth:d,strokeDasharray:u}),l.label&&/* @__PURE__ */LC("text",{x:"left"===h?4:"center"===h?t/2:t-4,y:e<20?Math.min(i-4,e+16):e-5,textAnchor:"left"===h?"start":"center"===h?"middle":"end",fontSize:a.tickSize,fill:l.labelColor??c,fontFamily:a.fontFamily,children:l.label})]},`ann-${r}`))}}return s.length>0?/* @__PURE__ */LC(PC,{children:s}):null}function BC(e,t,i,r,n,o,a=0){let s=$(r),l=N({top:20,right:20,bottom:30,left:40,...n.margin},n.title),c=Math.max(1,t-l.left-l.right),u=Math.max(1,i-l.top-l.bottom),d=zC(n,r),h=n.renderMode,f=e.map((e,t)=>Kl({node:e,index:t,renderMode:h,fallback:()=>Yl(e,t)})).filter(Boolean),p=DC(n.annotations,c,u,r,n.yExtent,o?.y),{titleText:g,descText:m,titleId:y,descId:x,labelledBy:b}=NC(FC(n,"xy-gif"),a,n.title,n.description),v=/* @__PURE__ */RC("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:i,role:"img","aria-labelledby":b,style:{fontFamily:s.fontFamily},children:[g&&/* @__PURE__ */LC("title",{id:y,children:g}),m&&/* @__PURE__ */LC("desc",{id:x,children:m}),d&&/* @__PURE__ */LC("rect",{x:0,y:0,width:t,height:i,fill:d}),
391
- /* @__PURE__ */RC("g",{transform:`translate(${l.left},${l.top})`,children:[p,f]}),g&&/* @__PURE__ */LC("text",{x:t/2,y:22,textAnchor:"middle",fontSize:s.titleFontSize,fontWeight:s.titleFontWeight,fill:s.text,fontFamily:s.titleFontFamily,children:g})]});return IC.renderToStaticMarkup(v)}function jC(e,t,i,r,n,o=0){let a=$(r),s=N({top:20,right:20,bottom:30,left:40,...n.margin},n.title),l="radial"===n.projection,c=l?s.left+(t-s.left-s.right)/2:s.left,u=l?s.top+(i-s.top-s.bottom)/2:s.top,d=zC(n,r),h=W$({nodes:e,renderMode:n.renderMode,idPrefix:n.idPrefix}).map(e=>e.element),{titleText:f,descText:p,titleId:g,descId:m,labelledBy:y}=NC(FC(n,"ordinal-gif"),o,n.title,n.description),x=/* @__PURE__ */RC("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:i,role:"img","aria-labelledby":y,style:{fontFamily:a.fontFamily},children:[f&&/* @__PURE__ */LC("title",{id:g,children:f}),p&&/* @__PURE__ */LC("desc",{id:m,children:p}),d&&/* @__PURE__ */LC("rect",{x:0,y:0,width:t,height:i,fill:d}),
392
- /* @__PURE__ */LC("g",{transform:`translate(${c},${u})`,children:h}),f&&/* @__PURE__ */LC("text",{x:t/2,y:22,textAnchor:"middle",fontSize:a.titleFontSize,fontWeight:a.titleFontWeight,fill:a.text,fontFamily:a.titleFontFamily,children:f})]});return IC.renderToStaticMarkup(x)}async function WC(e,t,i,r={}){let{fps:n=12,loop:o=!0,scale:a=1,background:s}=r,l=i.width||600,c=i.height||400,u=CC(e,t,s?{...i,background:s}:i,r);if(0===u.length)throw new Error("No frames generated — check that data is not empty");return qC(u,l,c,{fps:n,loop:o,scale:a})}async function YC(e,t={}){let{fps:i=12,loop:r=!0,scale:n=1}=t,o=e.size??[e.width??600,e.height??400],a=OC(e,t);if(0===a.length)throw new Error("No physics frames generated");return qC(a,o[0],o[1],{fps:i,loop:r,scale:n})}async function qC(...e){return(await(import("./c-YM6CT4LJ.min.js"))).encodeSvgFramesToGif(...e)}Ws(),Ho=n;export{M as a,$ as b,cC as c,uC as d,dC as e,hC as f,fC as g,bC as h,SC as i,AC as j,$C as k,_C as l,CC as m,TC as n,OC as o,WC as p,YC as q};